Everyone may come to Rick’s Café Américain, but 75 years ago, no one was happy to be there. And they certainly didn’t think “Casablanca” was a hit, much less an iconic piece of cinema.

Humphrey Bogart — a heavy drinker whose third marriage was falling apart — got so grouchy while staging the climactic scene that the producer had to be called in to break up a fight between him and the director.

Ingrid Bergman — hungry for Hollywood stardom after a shaky start — fretted she didn’t know which of her leading men she would go off with at the end of the picture. She also worried that delays would cost her a plum part in “For Whom the Bells Tolls.’’

Paul Henreid — strong-armed into accepting what he called a “lousy, lousy script’’ — was convinced he would be laughed off the screen when his character showed up wearing a perfectly tailored, double-breasted, cream-colored suit after escaping from a concentration camp.

Getty Images

No fewer than seven writers struggled to balance the film’s intoxicatingly irresistible blend of suspense, romance, politics and cynical humor — delivering new pages to the set daily even as the topical World War II romantic thriller was being rushed through at an unusually fast pace for a production that ended up costing just over $1 million.

Oh, and the film’s composer hated “As Time Goes By’’ so much that he wanted to replace it.

Shooting with an unfinished script on a tight deadline with much behind-the-scenes rancor has sunk countless movies. But “Casablanca’’ — which premiered on Nov. 26, 1942 in New York and went into national release on Jan. 23, 1943 — somehow became a masterwork that not only went on to the box office and Oscar glory in its era, but over the decades achieved a rare status as one of the most beloved and most quoted films ever.

“Casablanca’’ was based on an unproduced play called “Everybody Comes to Rick’s’’ by Murray Burnett, a New York City high school teacher, and a divorced mother named Joan Allison. It fortuitously landed on the desk of a story analyst at Warner Brothers on Dec. 8, 1941 — the day after the Japanese attack on Pearl Harbor.

The timely story was snapped up by Hal Wallis, who had just signed a new producing contract that gave him unusual autonomy. It was in theaters less than a year later, a mind-boggling accomplishment even in an era when movie studios were factories with platoons of actors, director and writers under contract. “Casablanca’’ went before the cameras with a far-from-completed script on May 25, 1942 — after a mad five-month scramble to assemble what turned out to be a perfect cast.

After first-choice William Wyler (“The Letter’’) didn’t respond to a feeler, Wallis went with Warner’s top director. Curtiz had a reputation for ruthlessness and artistry, as well as the clout that came from a long string of hits. It was Curtiz who personally recruited real-life refugee extras, who shed genuine tears while singing “La Marseilles’’ to drown out the Nazis’ German anthem in the most rousing of the film’s many unforgettable scenes.

Paul Henreid and Humphrey BogartEverette Collection

Studio chief Jack Warner suggested George Raft to play the romantically disillusioned Rick. Instead, Wallis, exercising his contractual prerogative to cast anyone he wanted, had the script tailored specifically for Bogart, who, after a long run of cookie-cutter tough guy roles, had emerged as a leading man thanks to “The Maltese Falcon.’’

The female lead in the play was an American divorcee of dubious morals until Casey Robinson, one of the script writers, made the inspired suggestion she be turned into a more virtuous European refugee. When MGM refused to loan Hedy Lamarr out for the part that became Ilsa Lund, Wallis approached independent producer David O. Selznick for Bergman, a Swede he had under contract. Selznick agreed because he felt “Casablanca’’ might finally put her over with American audiences after several false starts — and it certainly didn’t hurt for Bergman, who was not an American citizen, to play in an overtly patriotic movie.

When he was unable to secure the services of Philip Dorn — the Dutch actor who was Curtiz’ first choice to play the underground leader Victor Laszlo — Wallis leaned on Henreid, an Austrian Jew who had recently scored a huge hit in the romantic weepie “Now, Voyager’’ opposite Bette Davis. In addition to disdaining the script, Henreid scorned the idea of playing a secondary character, no matter how noble. The actor’s ego was massaged with the offer of co-star billing with Bogart and Bergman.

Paul Henreid and Ingrid BergmanGetty Images

As difficult as the casting was, it was a piece of cake compared to the script-writing process, which continued by fits and stars until the final scene was shot on Aug. 3 — and even after.

The script was first assigned to Julius and Philip Epstein, twin wits credited with most of the movie’s memorable lines, including “I’m shocked, shocked that gambling is going on’’ and “round up the usual suspects.’’ When they were called to Washington to work on war documentaries, the project was taken over by Howard Koch, an avowed liberal who beefed up the film’s political elements. The Epsteins returned and tweaked some — but hardly all — of Koch’s work.

But Wallis and Curtiz still felt the crucial love story needed more heart, and turned to Robinson, the studio’s top paid writer, who had earlier written a story analysis. Robinson joined the team — beginning just five days before cameras started rolling — but thought so little of the story he turned down a shared screen credit, which would have eventually provided his only Oscar.

Somehow, the seemingly chaotic efforts of a disparate group of writers — who, with the exception of Epstein, who died in 1952, argued publicly for decades over who deserved credit — managed to produce what’s still taught as a model of cohesive storytelling in screenwriting classes.

“The Epsteins needed Koch to bring in the moral background, and Koch needed the Epsteins to keep things from getting too preachy,’’ says Noah Isenberg, author of the 2016 book “We’ll Always Have Casablanca: The Life, Legend and Afterlife of Hollywood’s Most Beloved Movie.’’ “And the three of them needed Casey Robinson to crucially shape the romance, especially in the Paris flashbacks. And Curtiz had to keep things moving through many dialogue-heavy scenes.’’

Dooley Wilson, Humphrey Bogart and Ingrid BergmanEverett Collection

Conflicts continued to dog “Casablanca’’ straight through the shoot, and even after the cameras stopped rolling. There are so many legends surrounding the film’s chaotic genesis that not all of them may be entirely true.

Take the famous story that “As Time Goes By’’ only remained in the picture because Ingrid Bergman’s hair was cut short for her role in “For Whom the Bell Tolls’’ by the time composer Max Steiner wrote his own love theme to replace it. Rode and Isenberg point to the absence of memos corroborating this.

“It’s true that Steiner told his wife he hated ‘As Time Goes By,’ but there’s probably no way they could have gotten Bergman back from location for retakes,’’ Isenberg says. “Steiner ended up using no less than 14 different arrangements of the song in his score, which is one of his best remembered.’’

Bergman insisted in her memoirs that Curtiz told her to “play it in between’’ when she asked the director which man Ilsa would leave Casablanca with. Yet Isenberg and Rode both point to evidence that it was clear from the outset that no matter what her feelings for Rick, Victor would have to be the ultimate romantic victor. That’s the way the play ends, and Robinson had pointed out in a memo before he officially joined the screenwriting team that the film just wouldn’t soar without Rick sacrificing the love of his life for the common good.

“The Production Code Authority would never have allowed a married woman like Ilsa to go off with Rick,’’ says Rode, referring to the studio’s self-censoring system.

The PCA was unusually lenient in other areas, though, notably overlooking the sexual implications of Rick and Ilsa’s late-night encounter where she threatens to shoot him to obtain exit visas and they fall into an embrace. Curtiz cut to a shot of a phallic airport tower and Rick smoking what looks suspiciously like a post-coital cigarette. Nobody, then or now, doesn’t think that they had a steamy reunion between shots.

Even if it was a foregone conclusion that Ilsa would dutifully leave for Lisbon with her husband, the screenwriters were still struggling about the exact plot machinations necessary to get there.

Bogart — who may have ad-libbed the “here’s looking at you kid’’ and “of all the gin joints’’ lines — was especially tense while shooting the climactic sequence at the airport, nearly coming to blows with Curtiz over how his lines should be delivered.

After Wallis calmed them down, there were more last-minute rewrites on the set — one of which introduced the entirely new concept that Rick would go off with Renault and join the Free French after Ilsa leaves with Victor and Rick shoots Major Strasser. “And that should just about cover our expenses’’ was the final line penciled into the much-revised final shooting script.

But Wallis still wasn’t totally happy, and a couple of weeks later he personally came up with Rick’s immortal rejoinder after that: “Louis, I think this is the beginning of a beautiful friendship.’’

Dooley Wilson and Humphrey BogartEverett Collection

Rains was 3,000 miles away from Burbank by this point. Fortunately, he and Bogart had turned their backs to the camera after the “expenses’’ line, so they merely had to call back Bogart to dub the new line over the existing footage.

The producer was tempted to further tinker after some audience members at a sneak preview suggested a coda. He was all set to shoot a brief new scene with Rick and Renault fighting with a garrison of Free French when Selznick — the mastermind behind “Gone With the Wind’’ — persuasively argued that “Casablanca’’ was an already perfect movie.

Jack Warner agreed. Though planned for a summer 1943 release, he was eager to rush it out after Allied forces invaded the real-life Casablanca in early November 1942. The film opened on Thanksgiving Day in New York, and fueled by the headlines and rave reviews, was a smash hit. There was more good luck: a summit by Allied leaders in Casablanca further bolstered the film’s national opening two months later. A year after that, it was nominated for eight Oscars, winning for picture, director and screenplay.

But it took Bogart’s death on Jan. 14, 1957 at the age of 57 — prompting “Casablanca’’ to arrive on TV the following year — to fully launch a never-ending love affair with moviegoers that is still going strong after three-quarters of century.