With such conflicting dynamics distorting its policies, achieving its aims in Syria will depend to a significant extent on how Turkey manages its already tense ties with Washington and its highly sensitive ties with Tehran. Rushing to Iran’s support against the United States might have been Ankara's knee-jerk reaction prior to the Arab Spring out of to a sense of Islamic solidarity, but the situation has changed.

Turkey’s continuing staunch opposition to the Russian- and Iranian-backed regime, on the other hand, led to its enthusiastic support of the US-led strikes against the regime forces in April. Ankara welcomed these strikes even knowing it would anger Moscow and Tehran, with which it must tread cautiously because of its reliance on them in Syria.

Iran had expressed disapproval of Ankara’s Olive Branch operation in Afrin. President Hassan Rouhani has openly called for it to end and for Turkish troops to be withdrawn.

Turkey, determined to stand against the American-supported YPG, launched an operation against the group in January in Afrin, disregarding not just US but international disapproval.

US President Donald Trump’s decision to pull out of the Iran nuclear deal has added new complications for Turkey’s two overriding quests in Syria: to see the Kurdish People's Protection Units (YPG) defeated and President Bashar al-Assad and his regime ousted. These two aims were already headed toward incompatibility in the crosscurrents that have shaped this crisis.

Instead, and despite their cooperation under the Astana process, the two countries act more like regional rivals than friends today.

With the deepening divide between Sunnis and Shiites following the Arab Spring and Tehran’s involvement in Syria, Turkish Islamists and the pro-government media have cultivated a deep dislike of Iran. Islamic solidarity, in short, has been overtaken by deep suspicions about Tehran’s regional aims.

President Recep Tayyip Erdogan set the tone last year when he lashed out at Iran on a visit to the Gulf region. "There is Persian nationalism here, we have to prevent this. We cannot just watch this oppression," Erdogan said in a speech in Bahrain on Feb. 14, 2017.

Mehmet Acet, a columnist for the pro-government Yeni Safak, believes that anti-Iranian sentiment still prevails in circles close to Erdogan and his ruling Justice and Development Party. He wrote, “There is hardly anyone left in the region that is prepared to look on Iran with a sense of mercy anymore, because it has contributed in the first degree, with its Persian nationalism and sectarian solidarity, to returning Syria to the Stone Age.”

Fahrettin Altun, a coordinator from the government-funded Political, Economic and Social Research Foundation, is concerned that instead of weakening Iran, Trump’s move will empower radical Iranian elements. He believes the move will entrench Iran even more in Syria. “Iran is spreading out in the region and growing uncontrollably,” Altun wrote.

It is evident that if Iran were forced to pull out of Syria by the United States, or failing that, if the wings of its proxies there were clipped — even by Israel, which is oft-despised in Turkey — it would be welcomed by Ankara, though no government officials would admit it openly.

And yet the two countries continue to stress their cooperation in Syria despite their differences. The reason is clear to Sedat Ergin, a leading foreign policy commentator for daily Hurriyet. Ergin wrote in a recent article, “There is no doubt that Iran’s increasing its regional influence by establishing an arc from Iraq in the south of Turkey to Syria is not something that Ankara looks on warmly." He went on, “Notwithstanding that, the reasons that keep Turkey and Iran close can’t be overlooked. To start with, the interests of the two countries regarding the YPG overlap to a great extent.”

Tehran’s criticism of Turkey’s Operation Olive Branch and Rouhani’s call on Ankara to pull out of Syria appear to contradict this statement.

Many analysts believe that Iran’s position regarding Turkey’s operation has little to do with the Kurds and a lot to do with a desire to prevent Turkey from gaining a foothold in Syria, from where it cannot only protect but also arm anti-Assad elements that aim to undermine Iran’s position in Syria.

However, as Ergin pointed out, Tehran may have expressed disapproval of this operation, but its objection did not turn into a campaign against Ankara. “The reason is simple,” according to Ergin. Tehran would not shed many tears over the fact that Turkey has thrown the YPG out of Afrin, he argued. “To the contrary, it sees this as something to be applauded, because it represents the defeat of an organization that is seen as an extension of the US,” Ergin wrote.

The US determination to increase the pressure on Iran, pleasing as it may be for Ankara with regard to Syria, also comes with undesirable possibilities for Turkey in Syria.

Maintaining its foothold in Syria with the help of its YPG allies has become more vital than ever for Washington, despite Trump’s promise to pull out of the country as soon as possible.

US longevity in Syria is not a welcome prospect for Ankara as long as Washington refuses to dump the YPG and list it as a terrorist organization. Despite official statements about ongoing talks between Ankara and Washington on this matter, there is little evidence to suggest progress is being made.

By supporting the YPG, the United States has ensured that Turkey no longer considers it a partner or ally in Syria, undoubtedly a pleasing outcome for Tehran.

Put briefly, the need to defeat the YPG and the desire to see the back of Assad are divergent currents for Ankara. They will require careful diplomatic juggling to manage if developments in Syria are to be prevented from working to Turkey’s disadvantage.

Retired Turkish Ambassador Oguz Demiralp is not too optimistic on this score. He lamented the abandonment of Ankara’s former policy of neutrality in Middle East disputes and nostalgically recalled how that policy had enabled Turkey to represent Iraq’s interests in Tehran and Iran’s interests in Baghdad during the Iran-Iraq War in the 1980s.

“That is the kind of Turkey we had in the Middle East back then,” Demiralp wrote in a recent article for the independent news portal T24. “If we stood equidistantly to all sides in the region, they might have listened to us,” Demiralp maintained.

Demiralp sees no way out for Turkey except to return to its old policy of working to maintain good ties with every regional country. That course, however, appears to be a long shot under the current administration.

Attention in Turkey is currently focused on the snap elections set for June 24. Once election frenzy is over, Syria will re-emerge as a major headache for whoever emerges from the ballot box. How Ankara will extricate itself from this increasingly complicated situation, while its Syria policy is getting more difficult to manage with every adverse development, is anything but clear.