I don’t think Iran will let ISIS take Baghdad. This is the best chance Iran will ever have to annex the parts of the-country-formerly-known-as-Iraq where there is Shiite majority population. They would not want Baghdad just a few miles away as capital of some Sunni caliphate.
It will be a helluva fight.