I just did this over a week ago with an AA flight (PHL-MAD) to an IB flight (MAD-SVQ). We had 2.5 hours scheduled although our first flight arrived early, so it was more like 3 hours. We made it with plenty of time to spare. To be fair, there was virtually no line at passport control and bags care pretty quickly (the times on the monitors were great and accurate). You will come out at T4, so you will be right where you need to be to check back in.