Being detained in an Egyptian police station is high on the list of risks facing journalists working in Egypt. Being attacked by armed men is another. On Sunday, I experienced both.
Journalism has become more difficult in Egypt since a popular coup removed the President and led to the appointment of an interim government in July.
Mirroring wider divisions in Egyptian society, local media have become polarised. Journalists seen as supportive of the former Government - which frequently includes Western journalists - are increasingly targeted by the regime and its supporters.
The authorities want to portray an image of national unity in the face of "terrorists", those Egyptians who until three months ago were supporters of the country's first democratically elected president. Anyone who challenges this narrative is at risk.
Sunday was the 40th anniversary of an Egyptian attack on Israel. Jingoistic fervour rises on Armed Forces Day, a national holiday when state television shows endless clips of Egyptian soldiers crossing the Suez Canal and rockets being launched against the enemy.
Tahrir Square was filled with thousands of Egyptians celebrating. Flyovers of jets received huge applause and people waved posters of armed forces commander-in-chief General Abdel Fattah el-Sisi.
While many Egyptians welcomed el-Sisi as a national saviour when the army stepped in following widespread protests on July 3 to remove President Mohamed Morsi, an increasingly isolated group of mostly Islamists continue to demand Morsi's reinstatement.
Several kilometres west of Tahrir Square, I followed a pro-Morsi march of thousands.
"Rabaa! Rabaa!" The repeated chant rippled the length of the march, punctuated by clapping, horns and drums. The marchers wore yellow shirts and held four fingers aloft to represent Rabaa, which means fourth in Arabic. Rabaa al-Adawiya was the largest of two pro-Morsi sit-ins which formed following what Morsi's supporters describe as "the coup".
The police dispersed the sit-ins mid-August, killing nearly 600 protesters.
Since then, Rabaa has become a symbol of an increasingly bitter segment of the population, who feel their country has turned on them.
"I came today because they killed our brothers in Rabaa," said protester Ayman Mahmoud El-Gazar as he walked towards the square.
Conflict seemed inevitable, despite the insistence of the marchers on their peaceful intentions.
Within minutes of the marchers approaching a line of security forces, black smoke from burning tyres and clouds of tear gas blurred the street. The marchers faced security forces and mobs of men, one of whom, in underwear and sunglasses, stood on a car.
Both sides hurled chunks of torn-up paving stones, and the explosion of fireworks and crackle of gunfire tore through the air.
A wounded man was carried past, a gunshot in his stomach leaking gore on to the footpath. I followed the blood trail up the street.
"Up there, a man was shot in the head," a man said, pushing me down a side-street with bloodstained hands.
One street over, a mob armed with sticks were beating someone. A gun was pointed in my direction. I ran but the mob intercepted me, interpreting my flight as proof of guilt.
I told them I was a journalist and not American as the crowd around me grew. A young man in a singlet ripped at my pocket trying to take my phone, while someone behind me tried to rip my bag from my back.
A man hit me over the head with the flat of a long blade. More flailing punches followed as a middle-aged man threw his arms around me to protect me.
Pushed against a fence, I let go of my phone and showed my passport. A man with a moustache and handgun ordered me to go with him.
"Ante zabit?" Are you an officer, I asked. He nodded.
A howling crowd followed us up the street, men still throwing punches. Finally I was pushed into a police truck as the crowd cursed me.
An officer escorted me into the police station down bloodstained stairs. Battered detainees filled a cage and rows more crouched facing the walls. The officer sat me on a bench in a room filled with policemen and left me to contemplate the violent sounds coming from the hall.
As the minutes became hours, I thought of other journalists detained in Egypt recently.
New Zealand Al Jazeera correspondent Wayne Hay, his cameraman Adil Bradlow and producer Russ Fin were detained on August 27 and held for five days before being released without charge.
Canadian filmmaker John Greyson and emergency-room doctor Tarek Loubani were detained on August 16 and held for nearly seven weeks.
Metin Turan, a journalist for Turkish state broadcaster TRT, was arrested on August 17 and remains imprisoned.
No one told me why I was being held or when I would be released.
According to NGOs, media that challenge the narrative that the Government is combating terrorism are coming under attack.
A recent statement by Reporters Without Borders said it was alarmed by "a wave of official statements displaying clear hostility towards media that fail to sing the army's praises".
The arbitrary detention of foreign journalists is part of a deliberate government campaign, according to the Committee to Protect Journalists (CPJ). "They want to control the information that people inside and outside the country hear," said CPJ Middle East and North Africa representative Shaimaa Abulkhair.
In the three months following July 3, Reporters Without Borders recorded over 80 arbitrary detentions and 40 attacks on journalists. Ten media outlets were raided by police during this time and five of those remain closed. Five journalists were killed.
At least 10 journalists are in custody, according to the CPJ, many facing charges of publishing false information.
Egyptian criminal law includes nearly 70 imprisonable offences that affect the press, according to the Arabic Network for Human Rights Information.
These include blasphemy, insulting public officials and disrupting national peace. In practice these broad offences make it easy for the authorities to prosecute journalists.
In June last year, state television aired an advertisement warning Egyptians against talking to foreigners as they could be foreign spies.
Xenophobic attacks are often thought to be carried out by thugs on the police payroll. "They educate them to believe that any foreigners they find at clashes will be against them and they should attack them," Abulkhair said.
The Government insists journalists carry official state-issued press cards to work in Egypt. If not, "they say they will detain and charge them," said Abulkhair.
After being kept in the police station for several hours, the officers finally processed me.
"You were beaten by the Muslim Brotherhood," one told me. "We protected you."
"Why are you interfering in this matter?" another asked. "Why do you want to show Egypt in a bad way?"
They asked repeatedly for my camera's memory card, which I had hidden.
Eventually they returned my bag, camera and passport, but kept my gas mask.
When a taxi drove me home down Tahrir St the clashes were over and the streets were swept clean. It was almost as if the protests had never happened. Which is just how the Egyptian Government would have it.
• Campbell MacDiarmid has lived in Egypt since January last year. He is currently the deputy managing editor of Business Today magazine.