Khamenei will not commit political suicide by staying with Assad until the last moment. Doing so would be very damaging for the regime’s interests. Iran is becoming more isolated every day. It does not need a new enemy in Damascus in the event of Assad’s fall, especially when this could impact on its ability to supply weapons to Hezbollah through Syrian territory (not to mention relations with Hamas and Islamic Jihad, which it conducts through its offices in Damascus). It could also lose access to its economic interests in Syria.
These interests are all important to Khamenei, and he will want to protect them. Therefore Assad should not be surprised if one day he finds that, while Iran supports him publicly, behind the scenes its leaders are anticipating his demise by cavorting with members of the Syrian opposition.