Cognitive foundations of prosocial behavior