Image copyright EPA Image caption President Trump (right) spent two days in Saudi Arabia

As Donald Trump has ended the Saudi leg of his first foreign visit, here's a look back at some of the contentious moments in the Gulf kingdom.

1. Thumbs down for a thumbs up?

It's one of the president's favourite gestures, and Bloomberg journalist Jennifer Jacobs tweeted a picture of him doing just that in Riyadh.

Image copyright Twitter - @JenniferJJacobs

Then came the question: could it have been offensive?

Well, yes, if you read this document distributed by the US embassy in Riyadh to journalists covering Mr Trump's trip, according to Politico's Annie Karni.

Image copyright Twitter - @anniekarni

But is it? Not really, said the BBC's Kim Ghattas. "I'm Arab, lived in the Arab world, travelled across [the] region [and] never heard of it".

Faisal bin Farhan, adviser to the Saudi foreign ministry, also did not see any wrong behaviour from Mr Trump. He tweeted:

Image copyright Twitter

So where did it all come from? It seems that, some time ago, it was indeed seen as an offensive gesture.

Here is what the US Defense Language Institute said in 2003, according to the National Review: "After the Gulf conflict [in 1991], however, Middle Easterners of the Arabian Peninsula adopted this hand movement, along with the OK sign, as a symbol of co-operation toward freedom."

And here is proof of how inoffensive the gesture seems to be: an aide signals that Saudi King Salman bin Abdul Aziz al-Saud is ready to welcome Mr Trump at Riyadh's airport.

Image copyright Reuters

2. Trump's 'Islamic terrorism' phrase

The president's highly anticipated address did not include the phrase "radical Islamic terrorism", which he had used before, and which is considered offensive by many Muslims.

A transcript of the text published on his Facebook page included a mention of "Islamist extremism" and "Islamist terror groups".

But in his speech Mr Trump actually said: "That means honestly confronting the crisis of Islamic extremism and the Islamists and Islamic terror of all kinds."

Did he stumble over the word or did he decide to change the script?

A White House official later blamed Mr Trump's fatigue for the switch, saying he was "just an exhausted guy".

The word "Islamist" refers to those who aim to reorder government and society in accordance with Islamic law, or Sharia.

Meanwhile, "Islamic" relates to Islam as a religion.

That is why a number of Middle East experts prefer the use of "Islamist extremism" to avoid tarring the entire religion.

Anyway, Mr Trump's veering off the script appears to not have caused major controversy.

3. No headscarf for Melania

Foreign visitors are not forced to wear it while visiting the kingdom, and the list of Western women who have done just that includes the UK Prime Minister Theresa May, German Chancellor Angela Merkel, former US First Lady Michelle Obama and former US Secretary of State Condoleezza Rice.

Media playback is unsupported on your device Media caption Melania Trump didn't wear a headscarf, but does it matter?

So what's the issue here? Well, here's what Mr Trump said in January 2015, when then-President Barack Obama visited the country.

Image copyright Twitter - @realDonaldTrump

Mr Trump's daughter, Ivanka, didn't wear a headscarf either.

When asked why they both went without headscarves, the White House responded that they were not required to wear them, CNN reports.

Image copyright Reuters Image caption Ivanka Trump (left) and Melania Trump (2nd left) at a reception ceremony in Riyadh

Experts also point out that both women were dressed conservatively in long trousers and dresses.

4. Did Trump bow or not?

The controversy here stems from this encounter between President Obama and King Abdullah of Saudi Arabia during a summit in London in 2009, which caused a furore.

Image copyright Getty Images Image caption Barack Obama bows to Saudi Arabia King Abdullah bin Abdul Aziz Al Saud in 2009

It didn't go unnoticed by Mr Trump, who tweeted about it in July 2012 - and several other times (here and here).

Image copyright Twitter - @realDonaldTrump

So many were left wondering what happened here as Mr Trump received an honorary medal from the Saudi king:

Image copyright AFP Image caption Trump receives the Order of Abdulaziz Al Saud medal from the Saudi king

Did he bow or not?

Or was it simply that he had to bend his knees and bow his head to receive the medal as the president is much taller than the Saudi king?

Some hawk-eyed observers even suggested that there was a "clumsy curtsey" at the end.

The White House has so far not commented on the issue.