Image copyright AFP PHOTO / PAKISTAN PRESS INFORMATION DEPARTMENT Image caption This is the Saudi crown prince's first visit to Pakistan since assuming that role

For a country running out of foreign reserves, facing a yawning current account deficit and fighting to secure its financial future, Pakistan is putting on quite a show for Saudi Arabia's de facto ruler - Crown Prince Mohammed bin Salman.

And it's easy to see why: Prime Minister Imran Khan needs money, and he needs it fast.

MBS, as he's known, has come to town promising billions.

But money is just one dimension of a relationship that goes much deeper. The two countries have a nexus of interests.

Pakistan was meant to be the first stop on an Asian tour taking in five countries but the crown prince's trips to Indonesia and Malaysia have been postponed. He is still scheduled to visit China and India in what is being seen as a charm offensive by the controversial prince.

How lavish is the visit?

The last time a Saudi royal visit was marked with this much fanfare was in 2006, when then Saudi ruler King Abdullah bin Abdulaziz toured the nuclear-armed nation.

And security is being taken seriously - with Imran Khan making a point of saying that he is personally taking care of the arrangements. The 33-year-old Saudi's tour comes amid heightened tensions in the region, after India blamed Pakistan for the deadliest attack on its security forces in Kashmir in decades.

JF-17 Thunder fighter jets escorted MBS's fleet on Sunday evening as it entered Pakistani airspace - with all other flights grounded. The crown prince was greeted by Mr Khan and Pakistan's powerful army chief on a red carpet at a military airport and given a 21-gun salute.

Imran Khan then personally drove Mohammed bin Salman to the official residence of the prime minister, where Mr Khan doesn't actually stay but where MBS will for his two-day visit, in a first for a state guest.

Hundreds of five-star rooms in Islamabad are believed have been booked out for the 1,000-strong delegation. There are even reports that thousands of pigeons have been caught for a welcome ceremony.

Pakistan's higher civilian honour will be conferred on the prince, who Mr Khan has praised for his "reformist ideas".

Image caption Pakistan needs Saudi money to stave off a huge IMF bail-out - but this is not a one-way relationship

Why is Pakistan desperate for cash?

The central bank has only $8bn (£6.2bn) left in foreign reserves and faces a balance of payments crisis.

Since he was sworn in last August, former star cricketer Imran Khan has been aggressively pursuing help from friendly countries in order to reduce the size of the bailout package that Pakistan is likely to need from the International Monetary Fund, under very strict conditions.

The country is seeking its 13th bailout since the late 1980s and Saudi Arabia has already provided a $6bn loan.

Media playback is unsupported on your device Media caption What has become of India's and Pakistan's economies, 70 years after partition?

The visit of MBS comes soon after Abu Dhabi's Crown Prince Mohammed bin Zayed al-Nahyan was in town and the United Arab Emirates has pledged to provide $6bn to support Pakistan's battered economy.

But Saudi Arabia is taking things up a notch - with its media reporting provisional agreements worth $20bn are being signed.

The crown jewel is a new $10bn oil refinery in southern port city of Gwadar.

Gwadar is the nerve centre of China's $60bn China-Pakistan Economic Corridor. Chinese money is much valued by Pakistan's government but analysts say it comes with strings attached - Chinese workers normally build Chinese projects. There are also concerns about Beijing having too much influence.

Funds from the Gulf countries are hence very welcome.

What's in it for the Saudis?

While it is easy to see Pakistan as a country which is benefiting from the largesse of its allies at the cost of its sovereignty, the story is not so simple.

Saudi Arabia needs Pakistan too.

The crown prince's tour comes at a peculiar time for the kingdom, which is currently facing a global reputational crisis of its own due to the humanitarian catastrophe of its war in Yemen and the killing of journalist Jamal Khashoggi in its Istanbul consulate.

Against this backdrop, the current tour can be seen as a charm offensive by MBS, who is seeking to bolster relationships with dependable allies while doling out cash.

And it's important not to forget that Pakistan is very important to the Saudis.

Image copyright Getty Images Image caption MBS visited Pakistan in 2016 before he was elevated to crown prince

The two countries have a military relationship which goes back decades. When Islam's holiest site in Mecca was attacked by militants four decades ago, it was Pakistani troops who were deployed to eliminate them.

"There has always been the assumption that Pakistan would be able to provide manpower if Saudi Arabia faced a major security crisis or a major attack," says Shashank Joshi, a South Asia expert and defence editor of The Economist magazine.

"Saudi Arabia, like some of the other gulf countries, has lots of cash but not necessarily a particularly strong army. Pakistan has not very much cash but a very strong and powerful army."

He adds that it has long been suspected - but never proven - that the two sides have a longstanding nuclear relationship that Saudi Arabia could draw upon if it one day needed access to the technology - for example if regional rival Iran became a nuclear-armed power.

The Saudis have a strong religious influence in mostly Sunni Muslim Pakistan and after the Soviet-Afghan war in the 1980s, they were able to set up a large network of religious seminaries, in part to counter Iran's influence.

In fact, a week before MBS's visit to Pakistan, the main avenues of Islamabad were dotted with posters and banners commemorating the 40th anniversary of the Iranian revolution. Since then, those have been replaced with pictures of MBS.

The presence of Iran as Pakistan's next door neighbour is another reason why the Saudis want to keep up the relationship.

"Saudi Arabia would like to ensure Pakistan remains closer to Riyadh than it does to Tehran," says Mr Joshi.

Image caption Signs of Iranian leaders were taken down - and replaced with these

It's true that Pakistan's decision not to heed Saudi Arabia's call to join its war in Yemen four years ago damaged the relationship. But this visit - coming amid a generational shift in the Saudi leadership - "represents a turning of the page", says Pakistani newspaper columnist Mosharraf Zaidi.

The Taliban question

What makes the timing of this tour even more significant is that it comes at a time when geopolitics in the region are shifting.

Unprecedented talks are taking place to bring an end to the war in Afghanistan - where Pakistan, Saudi Arabia, Iran, India and the US all have a stake.

The high-level talks have been held in Qatar - the Gulf country with which Saudi Arabia has an ongoing rift - and Saudi officials will want to find out exactly what has been going on from Pakistan's army chiefs, says Shashank Joshi.

"Saudi Arabia will be keen that as the peace process continues that it is factions [of the Taliban that they are close to] who are empowered, rather than those who are close to Iran."

Additional reporting by the BBC's Kevin Ponniah