First of all, I'd contact the airline and explain that the connection is too short and that they need to change you (no charge) to a later flight. It looks like Iberia has 5 lights a day, at 3-4 hour intervals, so any later flight would be okay. That way, you aren't risking a much longer wait if the next flight is fully booked. The computer parameters never seem to take into account the actual logistics. Even if your ORD-MAD flight lands on time, you don't get off the plane immediately (even if the crew make arrangments for you to be the first off the plane), and you will need to board the next flight at least 15 minutes before takeoff. That leaves you down to about 1/2 hour. Ridiculous.
If the agent doesn't understand, be patient and explain that you have to go through immigration and change terminals, etc, etc. It's very likely that s/he has never been on a similar route - maybe never been to Europe. If all else fails, ask for a supervisor. Don't give up easily and don't wait til you get to Madrid.