“Unfounded, baseless and untrue,” said Pakistan’s foreign secretary Aizaz Ahmad Chaudhry earlier this month, when asked whether his nation was considering the sale of nuclear arms to Saudi Arabia. Earlier this spring, Defense Minister Khawaja Mohammad Asif reiterated Pakistan’s “pledge to protect Saudi Arabia’s territorial integrity” in response to a request for military assistance against the House of Saud’s Houthi foes next door. But within days, Pakistan’s parliament voted unanimously not only against sending troops to Yemen, but also against even taking sides in the conflict. Despite decades of lavish funding to Pakistan, the Saudis might wonder what they are getting for their riyals. And Pakistanis, with all the problems they face in their own neighborhood, might be amazed that anyone would expect them to plunge into the treacherous miasma of the Middle East. What to make of the warm-but-not-too-warm friendship between the wealthiest state in the Sunni Muslim world, and its most heavily armed one?

This question is an important one for a simple reason: Pakistan and Saudi Arabia are each other’s wild cards. Each is the other’s out-of-region game-changer, a factor that must play into the calculations of all other players in the Middle East and South Asia alike. Think you’ve got the complex equation sorted out of Arabs vs. Persians, Sunnis vs. Shi’a, Ba’athists vs. Islamists? Well, if Pakistan decides to throw its weight around the Middle East, you’ll have to re-tabulate your odds. Think you understand the delicate balance between New Delhi, Islamabad, Kabul, and Beijing? Well, Riyadh has long been staking one particular player at this table, and whether it chooses to double down or fold on its investment will affect everyone else’s bets. To understand the strategies of both Saudi Arabia and Pakistan, one must understand what underlies their durable but lopsided relationship.

A protester holds a flag during a rally in support of Saudi Arabia over its intervention in Yemen, after Friday Prayers in Karachi, Pakistan, April 24, 2015. Akhtar Soomro / Reuters WHAT SAUDI ARABIA WANTS

Maintaining a deep relationship with Pakistan advances Saudi Arabia’s ambition of expanding its ideological reach beyond the Arab world. Riyadh tries to achieve this goal globally, both through highly visible investments and by more covert means. With great fanfare, the Saudi government builds grand mosques and endows humanitarian charities; more quietly, it spreads its Salafist doctrine by funding ideologically focused madrassas, and by paying for clerics and opinion-shapers to visit, study, or conduct pilgrimages to the Kingdom. For the Saudi royal family, Pakistan is the ultimate prize: It has the world’s second largest population of Muslims, and, unlike first-ranked Indonesia, is constitutionally an “Islamic Republic.” Pakistan was founded explicitly to provide a homeland for South Asian Muslims. Unlike Muslim-majority countries such as Bangladesh, the Central Asian Republics, and Turkey; near-majority ones like Nigeria; or massive-minority ones such as India, Pakistan has a Muslim identity as part of its national identity and mission. How that mission is translated into practice, however, is very much up for grabs. And the Saudis would very much like to grab it.

Saudi Arabia sees Pakistan as a crucial component of its plan to constrain Iran. Additionally, Saudi Arabia sees Pakistan as a crucial component of its plan to constrain Iran. Every Saudi ruler has, as part of his official title, the designation “Custodian of the Two Holy Mosques:” that is, guardian of Mecca and Medina, the two most sacred sites in the Muslim world. The regime’s identity is not merely that of an oil-rich Arab nation, but also as the standard-bearer for Islam. The most potent challenger to this identity, in both spiritual and political terms, is Iran—a nation that is also oil-rich and theocratic, but is Persian rather than Arab and Shi’a rather than Sunni. From the Saudi perspective, one of the best ways to keep Iran off-balance is to bolster a powerful Sunni rival on its eastern border. How intense is the rivalry? In 2008, Saudi King Abdullah was quoted in a cable published via Wikileaks urging the U.S. to attack Iran and “cut the head off the snake.”

Pakistan says it won’t provide nuclear technology to the Saudis, and Saudi Arabia says it has no interest in asking for it. Of course they do. But the father of Pakistan’s nuclear program, A.Q. Khan, ran the most extensive proliferation ring the world has ever seen, and remains a national hero. In 2004, after intense U.S. pressure on Pakistan’s military ruler General Pervez Musharraf, Khan admitted to selling nuclear information and technology to Iran, Libya, and North Korea; he received an immediate pardon, was confined to his luxurious home, and has lived freely ever since his release in 2009. The Saudis might well feel that an operation, which was once termed a “Nuclear Walmart,” will not keep its doors shut for long. And with an $80 billion military budget, the Saudis might see any tab as “Always Low Prices.”

WHAT PAKISTAN WANTS

A supporter of the Jamiat Ahle Hadith organization holds a picture of Saudia Arabia's King Salman bin Abdulaziz during a rally in support of Saudi Arabia over its intervention in Yemen, in Lahore April 19, 2015. Mohsin Raza / Reuters The best things in life are free, but Pakistan feels these are best left to the birds and bees. What it wants is money, and the Saudis have provided a lot of it: No comprehensive tally is available publicly, but over the past four decades the Kingdom has supplied Pakistan with many billions of dollars in aid through cash, credit, and cut-rate oil. During the 1980s, Saudi Arabia delivered perhaps half of the multi-billion-dollar stream channeled through Pakistan to the anti-Soviet mujahideen. In 1998, when Pakistan’s Prime Minister Nawaz Sharif was deliberating about whether to answer India’s nuclear test with one of his own, Saudi Crown Prince Abdullah reportedly promised 50,000 barrels of oil per day to help Islamabad weather any potential sanctions.

In addition to cash, Pakistan is hoping to boost its credibility in the Islamic world. Pakistan was founded with a Muslim identity—but not necessarily an Islamic one. What is the distinction? It’s the difference between culture and faith. When arguing for a nation separate from India, Pakistan’s founding father Muhammad Ali Jinnah said that Islam and Hinduism “are not religions in the strict sense of the word, but are, in fact, different and distinct social orders.” Jinnah was himself hardly a rigorous observer of Islamic practices, and his nation’s transition from homeland for Muslims to Islamic Republic occurred only after his death. By far the most significant period of Islamization was the 1977–88 tenure of General Zia-ul Haq—a period that corresponded, whether by intent or coincidence, with the blossoming of the relationship between Pakistan and Saudi Arabia. Indeed, Sharif was reported to have “become a member of the Saudi royal family” when, according to a diplomatic cable, his daughter married a grandson of King Fahd.

Unlike the assistance provided by Washington, Saudi Arabia’s infusion came with no strings attached. And unlike the offer made by Beijing, all of Saudi Arabia’s promised funding actually materialized.

Beyond boosting the nation’s Islamic credentials, Pakistan is looking to diversify its stock of superpower supporters. Although China is said to be Pakistan’s “all-weather friend,” the precise meaning of this friendship is elusive. Has China stood beside Pakistan in tough diplomatic struggles? Not really. For example, it stood on the sidelines during the 1999 Kargil crisis. Does China bail Pakistan out of economic hardship? Perhaps it will in the future ( if President Xi makes good on recent promises ), but it has not often done so in the past. Did China actively support Pakistan during its three wars with India in 1948, 1965, and 1971? No, no, and no. United States, meanwhile, is Pakistan’s—well, nobody is quite sure what. Friend? Enemy? Both? Neither? Even if Pakistan is not going to walk away from either of its two traditional patrons, it is pleased to have Saudi Arabia as a third. Just last year, for example, Riyadh helped Islamabad stave off a financial crisis with a $1.5 billion soft loan . Unlike the assistance provided by Washington, Saudi Arabia’s infusion came with no strings attached. And unlike the offer made by Beijing, all of Saudi Arabia’s promised funding actually materialized.

WHAT HAPPENS NEXT

The relationship between Pakistan and Saudi Arabia has had its ups and downs. Ties tend to be closer when Pakistan is governed either by the military (under Generals Zia and Musharraf) or the Pakistan Muslim League (led by Sharif—a Zia protégé who tried to grant himself the power to enforce sharia). After Musharraf ousted Sharif in 1999, the once-and-future prime minister and his family spent seven years in exile, living comfortably in the seaside city of Jeddah.

Games of chance are officially banned in both Saudi Arabia and Pakistan—but the governments of both nations know the importance of keeping a wild card in the hole.

The Pakistan Peoples Party (PPP), rival of both the Muslim League and the military, has historically been less close to the Saudis. The PPP has produced three national leaders of note: Zulfikar Ali Bhutto (from 1971 until his execution by Zia in 1977), his daughter Benazir Bhutto (who served two terms as prime minister in the 1990s and was killed in a 2007 terrorist bombing), and her widower, Asif Ali Zardari (who led the first, and so far only, democratically-elected government in Pakistan to complete a full term). One of the bases of support for the PPP has traditionally been the country’s Shi’a minority, which represents about one-fifth of the population . The Bhuttos have traditionally been more favorably disposed toward Iran than the Saudis might like, and their periods in power have seen a slight cooling between Islamabad and Riyadh.

Cooperation against terrorism has also ebbed and flowed. Pakistan and Saudi Arabia have both been the victims of terrorism, and have also served as its incubators. Both governments have launched tough campaigns against Al Qaeda, but extremely well-connected individuals in both nations have supported the group, too: Osama bin Laden was the scion of one of Saudi Arabia’s most powerful families, and for the last half-decade of his life, he found sanctuary right outside Pakistan’s military academy in Abbottabad. Private Saudi funds fuel some of the most bloodthirsty terrorist groups based in Pakistan, including Lashkar-e Jhangvi (a Sunni sectarian force, which directs most of its violence at Shi’a) and Lashkar-e Taiba (whose primary target is India and was responsible for the 2008 Mumbai attack). While the Pakistani government is usually upset by Saudi support for sectarian militias on its soil, Lashkar-e Taiba is another matter. In the past, the group has been supported by Pakistani intelligence for reasons of political expediency (it served as a de facto proxy in Kashmir throughout the 1990s, and arguably even after its 2002 banning by Musharraf), and by Saudi patrons for reasons of ideology (the Ahl-e Hadith school, which it follows, is part of the Salafi pathway rather than any ideology indigenous to South Asia).

Whatever overlapping interests they may have in dangerous groups like Lashkar-e Taiba, the Saudis and Pakistanis have much bigger reasons for seeking each other’s friendship. These reasons may be largely transactional, but the transaction has been a mutually beneficial one for nearly 40 years. There is little reason to believe that relations will get markedly better in the near future—or, for that matter, markedly worse.

A supporter of Pakistan Muslim League-Nawaz (PML-N) party, his body painted in national flag colors, chants slogans with others as they participate in a pro-government rally in support of Prime Minister Nawaz Sharif in Lahore, August 25, 2014. Mohsin Raza / Reuters What, then, to make of Pakistan’s reluctance to join the Saudi campaign against Shi’a rebels in Yemen? Or to open the door to nuclear cooperation in the event that Iran manages to join the world’s most exclusive club? What, exactly, did the Saudis buy for their $1.5 billion bailout—and how much more will they be willing to pay?

For the answers to these questions, perhaps the best place to look would be a poker-table: Games of chance are officially banned in both Saudi Arabia and Pakistan—but the governments of both nations know the importance of keeping a wild card in the hole.