"We realized early on how important Ant-Man and the Wasp was going to be for us," says Markus of the 2018 film, which didn't have a script when they were writing Infinity War and Endgame. Paul Rudd's Ant-Man ends his sequel stuck in the Quantum Realm, which becomes key in Endgame for the heroes to defeat Thanos. "That was a big aha moment," says McFeely.

The duo also had to provide closure to an 11-year storyline for Robert Downey Jr.'s Iron Man. They used a time travel element to allow Tony Stark to finally reconcile with his father. "That was the last piece of unfinished emotional business in Tony's life," says Markus.

Long after Markus and McFeely finished their work, composer Alan Silvestri, who worked on 2011's Captain America: The First Avenger as well as 2012's Avengers, came on to score the films. For that first Avengers movie, Silvestri had opted to give the villain Loki his own theme as well as keep individual themes for Captain America and Black Widow. But Infinity War and Endgame were a different animal because of the number of characters and storylines. While Markus and McFeely had to tie together multiple storylines, Silvestri felt that starting fresh was in many ways his best bet.

"Thanos needed to have his own sensibility because he was driving both of these films," he says. "But if every time a character walks on, they have to have their own music, we knew it would be crippling."

In many ways, the one moment that 11 years of storytelling built to was the return of all the heroes who died in Infinity War, a segment Silvestri and the filmmakers refer to as "the portals," which saw Doctor Strange (Benedict Cumberbatch) and his wizard allies bringing the heroes to the battle against Thanos. "These were moments that we really didn't have any thematic material to draw from, so we had to face them anew," says Silvestri.

Though the composer and screenwriters constantly had to refer to other people's work, there was one exception. In a strange twist, Endgame was written and shot before Captain Marvel, even though that film came out a month before Endgame. Markus and McFeely worked with director-screenwriters Anna Boden and Ryan Fleck, who were on the set for the Captain Marvel scenes. "In a weird way," says Markus, "we were playing with their baby before they had their baby."

This story first appeared in a January stand-alone issue of The Hollywood Reporter magazine. To receive the magazine, click here to subscribe.