It’s the song forever being butchered in the bedrooms of novice guitarists. Famed for its iconic riff, Deep Purple’s “Smoke on the Water” is among the most instantly recognisable songs in rock, a fact that has led to its outlawing in scores of guitar shops lest it send the staff into a fit of rage.

“Smoke on the Water” was written on a whim, a reaction to an incident that very nearly ended in tragedy, though it would provide Deep Purple with their biggest hit.

It was December 1971 and the band had arrived in Montreux, Switzerland, to make an album in the Rolling Stones’ mobile studio. The studio was stationed next door to the Casino, an entertainment complex on the edge of Lake Geneva. While they were there a concert by Frank Zappa and The Mothers of Invention was held in the casino’s theatre.

Midway through the show a fan fired a flare gun into the wooden rafters, which swiftly caught fire. Zappa stopped the music and directed fans to the exits. Within hours, the building had burnt to the ground. Miraculously, no one was killed.

The members of Deep Purple watched the fire from their hotel across the lake and quickly set about writing a song. It was bassist Roger Glover who came up with the name “Smoke on the Water” — the working title had been “Durh Durh Durh” on account of guitarist Ritchie Blackmore’s riff. Singer Ian Gillan took charge of the lyrics, writing a scene-by-scene account of what had taken place, from “some stupid” shooting the flare gun into the air to “Funky Claude”, aka Claude Nobs, the Casino’s owner (and founder of the Montreux Jazz Festival), “running in and out pulling kids out of the ground”.

It’s thanks to “Funky Claude” that the song saw the light of day. Initially, the band had no plans to include “Smoke on the Water” on their as-yet-unrecorded album, not least because Gillan was worried the title made it sound like a drug song. But when Nobs heard it he said: “You’re crazy. It’s going to be a huge hit.”

He wasn’t wrong. Appearing on their sixth album, 1972’s Machine Head, “Smoke on the Water” was released as a single a year later and, thanks in part to the infectious simplicity of Blackmore’s riff, is now held up as a classic rock anthem. The guitarist would have to defend the riff against sniffy interviewers who suggested his use of just four notes made it too basic to be any good. His response was that they should listen to the opening of Beethoven’s Fifth Symphony.

Over the years “Smoke on the Water” has yielded cover versions ranging from the decent to the inexplicable. In the former category was a charity recording to help victims of the 1988 Armenian earthquake that featured an all-male roll-call of top rockers including Bruce Dickinson, Bryan Adams, Tony Iommi, Brian May and Keith Emerson, and dialled up the rock histrionics to seismic effect. In the latter was Pat Boone’s deeply peculiar samba/big band treatment for 1997’s In a Metal Mood, an album of rock covers that seemed to have been made with the sole intention of showing that this white-bread singer had a sense of humour.

Similarly baffling was the finger-clicking swing-jazz version by the now-disgraced Australian entertainer Rolf Harris for his LP “Rolf Rules OK”, on which he employed his usual jaunty singing style, even while uttering the words, “Watch it burn”.

It’s a measure of “Smoke on the Water”’s enduring regard among guitar obsessives that it’s repeatedly used in attempts break the world record for the number of guitarists playing at once. In 2014 Ian Gillan joined scores of amateur rockers in playing the song on the beach in Lyme Regis in the UK, though they failed to beat the record achieved at a festival in Wroclaw, Poland, in 2009 when 6,346 guitarists performed it together, led by current Deep Purple guitarist Steve Morse.

After their early ambivalence, the members of Deep Purple have evidently developed an affection for their most famous song, safe in the knowledge that, as long as people play guitar, it will never go out of favour.