The old courthouse in central Benghazi, Libya's second-largest city and the birthplace of the uprising against Moammar Gadhafi, is a shelled-out ruin — a testimony to the destruction and chaos that permeate this North African country four years after the civil war that ousted the longtime dictator.

The building is steeped in symbolism. It was here that the rallying cry first came against Gadhafi's 42-year rule. It was here that pro-democracy protesters and rebels first raised the tri-colored Libyan flag, replacing Gadhafi's green banner.

Now, the courthouse is ruin and rubble, like much of the rest of Benghazi.

Today, Libya is bitterly divided between an elected parliament and government that are cornered in the country's east, with little power on the ground, and an Islamist militia-backed government in the west. Hundreds of militias are aligned with either side or on their own, battling for power and turf.

The U.N.-backed talks between rival factions have not yet managed to strike a power-sharing deal. Meanwhile, Libya's Islamic State affiliate is fighting on different fronts, losing ground in its eastern stronghold of Darna while expanding along the country's central northern coastline.

For Benghazi, the past year was the worst. Near-daily street fighting has pitted militias made up of a myriad of al-Qaida-linked militants, Islamic State extremists and former anti-Gadhafi rebels against soldiers loyal to the internationally recognized government and their militia allies.

Once known for its mix of architectural styles left behind by Arab, Ottoman and Italian rule, this city — shaped like a crescent moon, hugging the Mediterranean Sea on one side and sheltered by the Green Mountain on the other — has lost the flair of times past.

Many landmarks have been destroyed, including much of the Old City, with its Moorish arches and Italian facades. The Benghazi University, its archives and department buildings have been hollowed-out, occupied in turn by militiamen who put snipers on rooftops and turned the campus into a warzone.

The last destruction — albeit not on this scale — that city elders remember was during World War II, when Benghazi was captured by the British. But the city was quickly rebuilt after the war, in part thanks to the country's new-found oil wealth.

Now charred and wrecked cars, piles of twisted metal and debris act as front-line demarcations between warring factions. In many neighborhoods, Libyan soldiers have blown up entire buildings to clear snipers' nests or in search of underground tunnels used for smuggling weapons.

Schools have closed, few hospitals remain open, and wheat and fuel shortages force residents to line up for hours every day outside bakeries and gas stations. Many neighborhoods have been emptied out by fleeing residents, only to be looted and torched by marauding militias.

More than a fifth of Benghazi's 630,000-strong population has been forced out of their homes. Those with money fled abroad. The rest sought refuge in other Libyan towns and cities, or crowded into Benghazi's makeshift camps and schools turned into shelters.

The overall number of displaced within Libya has almost doubled from an estimated 230,000 last September to more than 434,000 amid escalating fighting this year, according to the latest U.N. report.

Benghazi resident Hamid al-Idrissi says he and his family fled their war-torn Gawarsha neighborhood under heavy shelling. His extended family had a total of 45 houses there, built on a vast swath of land owned by his late grandfather, he said.

"Houses were first looted, then burned down. We lost everything," al-Idrissi told The Associated Press as he and his relatives huddled inside a school turned into a shelter.

Civilians still in the city live against the backdrop of gunshots and ambulance sirens that fill the night. In May, more than 27 civilians were killed, including 12 members of one family who were preparing for a wedding party when a rocket hit their house. The groom and five children were among the dead.

The city's residents also fear abductions at the hands of militiamen from the Shura Council of Benghazi Revolutionaries, an umbrella group of hard-line militias that includes Ansar al-Shariah, which the U.S. blames for the September 2012 attack on the U.S. Consulate in Benghazi that killed Ambassador Chris Stevens and three other Americans.

Benghazi's descent into all-out war started in May 2014, when Libyan renegade Gen. Khalifa Hifter, once Gadhafi's army chief who later joined the opposition, launched an offensive against the militias blamed for a series of assassinations of the city's army officers, policemen, judges, and journalists. He soon formally joined ranks with Libya's elected government and since then, Hifter's forces have taken back parts of Benghazi.

The fighting has split many Benghazi families, with relatives, even brothers, often joining opposite camps.

One of Saed Abdel-Hadi's sons joined Libya's Islamic State affiliate after returning from Syria and was killed in clashes. Another son joined the army, which is battling IS militants.

"When my other son joined the army, the extremists threatened to kill me," he said, adding that he fled with rest of the family and now lives in a friend's garage.

Even those with only a distant connection to Islamic militias or the army are targeted in retaliatory attacks.

One of Muftah al-Shagaubi's cousins joined an extremist group a while ago. Months later, al-Shagaubi lost his home as did 20 of his relatives when Hifter's forces looted, burned and blew up the buildings so they could never come back, he said.

"I have lived all my life here and now we have to leave ... because nothing is left for me in Libya," he said, adding that he was preparing to head to Turkey in the coming weeks.

Essam al-Hamali, a member of the Benghazi Crisis Committee, said there are 140,000 displaced individuals in the city alone.

"Most of these families left their homes in a hurry, taking whatever they could grab," he said. "Some only had the clothes they were wearing when the fighting began."

Over the past five months, his committee received a one-time voucher of under $100 per person for 481 families living in one Benghazi school.

In March, it got about 7,000 food parcels from international donors through the Libyan Aid Agency — less than 1 percent of what is needed. It was promised $20 million to $40 million in aid but the government only delivered $5 million.

"We have declared Benghazi a disaster zone," al-Hamali said. "But it seems that no one cares."