By Noah Barkin

OBERNDORF, Germany (Reuters) - In the lush forests of southern Germany sits a fenced-in compound of drab white buildings that house a company under siege.

Heckler and Koch is one of the most successful gun makers in the world. Its HK416 assault rifle is said to have been used to kill Osama bin Laden and the G36 is standard issue for militaries across the globe.

In years past, the company profited from Germany's aggressive export policies. In 2008, Chancellor Angela Merkel's government approved a controversial but lucrative licensing deal for HK that allows Saudi Arabia to produce the G36 itself.

But lately, the mood in Berlin has shifted. And HK's most important client has become its fiercest critic.

Last year, Berlin reversed course on arms exports following a storm of media criticism. Tighter restrictions ground HK's Middle East business to a halt, hammering revenues.

Even worse, for a company that prides itself on engineering it likens to "fine watchmaking", the government is now questioning the quality of its signature product.

The G36, Berlin says, does not shoot straight in hot weather or when it heats up through constant firing.

"This weapon, the way it is now constructed, has no future in the German armed forces," Defence Minister Ursula von der Leyen declared last month.

HK, a private company with 700 employees, has always avoided the spotlight. Now it is front-page news and in a fight for survival, its reputation damaged and its business practices and finances under scrutiny.

Last week it invited a small group of reporters to its headquarters in Oberndorf south of Stuttgart.

The message was clear: there is nothing wrong with the G36, a gun HK began delivering to the Bundeswehr nearly two decades ago and has sold to over 30 other countries.

"We are convinced that there is some sort of campaign against us," said Andreas Heeschen, a 54-year-old German investor who bought the firm from British Aerospace - now BAE Systems - in 2002 and recently relocated from London to Oberndorf to take a more active management role.

Story continues

HK is vowing to fight back. Executives said it is considering legal action against the government for what it sees as politically motivated slander.

The conflict is more than a battle between a defense firm and a disgruntled client. It also reflects Germany's struggle to define its role in a world of heightened security risks.

Seventy years after the end of World War Two, Germany is still reluctant to send its troops to crisis zones. Yet until recently it encouraged companies like Heckler and Koch to ship arms around the world.

Berlin is now tacitly acknowledging the hypocrisy of this stance. But reversing course is proving messy - for the government and the gunmaker.

HIDDEN IN HAYSTACKS

Heckler and Koch traces its roots back to 1811, when Friedrich I of Wuerttemberg ordered an armaments factory built in Oberndorf. Sixty years later, two brothers - Paul and Wilhelm Mauser - who worked in the armory set up shop for themselves.

The company thrived. At its peak in World War Two, it produced 70,000 rifles a month for the Nazis with the help of thousands of forced laborers. After the German defeat, French troops swooped in to dismantle Mauser's machines and put them on trains for Alsace.

One night, three Mauser engineers - Edmund Heckler, Theodor Koch and Alex Seidel - crept into the railyard, unloaded a set of machines and hid them under haystacks on the hill above Oberndorf.

In 1955, when a ban on German arms-making was lifted, those machines were dusted off and began producing guns under the name Heckler and Koch.

By the end of the 1950s, the company was supplying the Bundeswehr with the G3, now the second most widely used assault rifle of all time after the Russian Kalashnikov.

The G36 followed in 1997. Since then, HK has delivered nearly 180,000 to the German armed forces.

The first suggestions that the gun might be faulty date back to April 2010, when 32 Bundeswehr paratroopers were ambushed by Taliban fighters in northern Afghanistan. Three German soldiers were killed in a nine-hour firefight. The G36 was said to have overheated, forcing the Germans to retreat.

For years no action was taken. Then defense minister von der Leyen commissioned a new study of the weapon. It was completed last month and the results were damning.

"In demanding battle situations, precise engagement of the enemy is not reliable," the confidential report, seen by Reuters, reads.

In Oberndorf, the report was greeted with fury and incredulity.

Why, Heckler and Koch asks, does Germany suddenly have a problem with a weapon its military has used for nearly 20 years? Why haven't other G36 countries complained? And why are politicians rather than troops who use the rifle criticizing it?

"It looks to me like von der Leyen has jumped at the chance to send a tough message to a company that cannot fight back because it's relatively small and has an image problem," said Thomas Wiegold, a Berlin journalist who blogs on defense issues.

A German officer with experience in Afghanistan, who spoke to Reuters on condition of anonymity, said: "Any weapon gets hot if you shoot it long enough. The G36 is not a machine gun and it's not made to be one."

MEXICO DEAL

Some suspect HK has become a target because of other misdeeds that embarrassed the government. The G36 has turned up repeatedly where it wasn't supposed to be sold - including Libya and Georgia - prompting withering exposes in the German media.

The most high-profile example is Mexico, where thousands of HK guns went to four states that were under an export ban because of corrupt police forces.

Some of the guns were discovered in Iguala, a town in one of the banned states where 43 students were abducted last year by police and allegedly assassinated by gang members.

HK has dismissed two executives it said had acted alone in facilitating the illegal Mexican exports. But prosecutors in Stuttgart are investigating whether more may have known.

During the visit, the company tried to emphasize the quality of its work, with Martin Lemperle, a 35-year HK veteran with a thick Swabian accent, proudly showing off wares in the factory.

Around him, workers smoothed the edges of rifle and pistol parts with tiny devices that whirred like a dentist's drill.

"We make a product," Lemperle said. "Others decide whether it is used to kill."

Owner Heeschen is scrambling to repair HK's reputation and finances.

He told Reuters that to offset the stalled Middle East business, which hit revenues by 50 million euros in 2014, he wants to expand in the U.S. civilian market.

In a nod to sensitivities about school shootings, he says the focus will be on selling pistols rather than assault rifles. His goal is to boost U.S. civilian revenues to $100 million in 2015, more than double the 2013 level.

"This will more than compensate for the decline on the military side," Heeschen said.

But concerns about the firm's finances linger. HK is paying a whopping 9.5 percent interest rate on a 295 million euro bond that falls due in 2018. It recently secured a new 30 million euro credit facility, but on even more onerous terms.

Rating agency Moody's said this month that the firm's capital structure was "unsustainable" without new capital.

But Heeschen says he is not considering selling up. "Who would want to buy the company now?" he said.

(Additional reporting by Sabine Siebold; Writing by Noah Barkin; Editing by Giles Elgood)