Depends. Single ticket on Iberia or American your first flight will be domestic and you would arrive in T4. You would not have to go through security again but when you ended your subway train line out to T4S you would pass immigrations where your passport would be stamped.
Two tickets different story.
Single ticket to Delta or United you might have to change terminals and pass security again. Immigration will be when you enter the concourse to your stateside flight.