(Paul J. Richards/AFP/Getty Images)

Presidents give hundreds of speeches every year on topics from the mundane to the consequential, but there are only a handful of times when they have to be funny - on purpose.

Saturday's White House Correspondents' Association dinner will be one of them when President Obama takes the podium at the annual event for the sixth time in his presidency.

His task: stepping out of his role as commander-in-chief, and adopting a new one: comedian in chief.

ABC News spoke to former White House Deputy Chief Speechwriter Jeff Shesol, who offered an inside look at what it was like to build a comedy routine for President Bill Clinton in the years when his relationship with the press was at its most contentious.

Clinton had returned to the United States and was set to deliver remarks at the correspondents' dinner in 1998, following an almost-suspiciously lengthy time overseas at the height of the Monica Lewinsky sex scandal.

"The press was starting to say he's just avoiding the United States," Shesol said. "So we did this riff that opened it where Clinton stands up and he acts like thinks he's in a foreign country."

"As you know I've been traveling to other lands quite a lot lately. And I just want to say what a pleasure it is for Hillary and me to be here in your country," Clinton said. "I've even tasted some of your… hamburgers. Quite tasty, sort of a meat sandwich."

Shesol had drawn up a speech with fellow writer Mark Katz that - at least for a few minutes in a room jam-packed with a bloodthirsty press - swapped contention with laughter.

"It was a way of acknowledging what was going on without getting yourself into deeper trouble," Shesol said. "Finding that line was always the challenge."

Step 1: The First Draft

For Shesol, the process of building a correspondents' dinner speech usually started inside of a Starbucks about 10 days before the event.

"Whereas for a big speech of any other time you might go in there and have a thorough conversation with the president beforehand," Shesol said. "This was a speech where he wasn't going to see it until you had a draft that was ready to go."

Recently released documents from the Clinton Administration have given an inside look at the process behind constructing the 1999 WHCD speech.

Formerly withheld Clinton Documents

In one section, the writers had Clinton take a jab at former dean of the White House press corps Helen Thomas when rumors were circulating that the press briefing room was set to be moved.

"She's still miffed about the last time the White House briefing room was moved - when the capital relocated to Washington from Philadelphia," Clinton joked.

On one of the drafts, a scribble from Shesol says "That's funny. That'll piss her off."

Step 2: Finding The Right Jokes

"The challenge was not simply writing a funny joke," Shesol told ABC News. "The challenge was finding jokes that were of the moment that were edgy enough to get a laugh, but not dangerous enough to get you into trouble."

According to Shesol, there was one cardinal rule that never really needed explanation.

"We were very clear that we were never going to make a joke that involved her [Lewinsky] at all," Shesol said. "But you also can't go and do one of these speeches and just pretend that none of this is happening."

The angle Shesol and Katz wound up choosing was a play on Clinton's impeachment by the U.S. House earlier that year. The Newseum had designated the story as #53 on its Top 100 news stories of the century.

"What's a guy have to do to make the top 50?" Clinton cracked. "I came in six places after the invention of plastic, for crying out loud. I don't recall 12 months of around-the-clock coverage of 'the miracle of plastic.'"

After the draft had been written up, Katz and Shesol would confer with several other aides and outside talent including Philip Rosenthal, the creator of Everybody Loves Raymond.

Step 3: Presidential Approval

Then it was on to the Oval Office.

"You would go sit with him, he would go through it and say some of them out loud, which ones he thought were working, which ones he didn't get," Shesol said. "Sometimes he would have an idea for a joke."

Shesol said one of the toughest parts of building the speech would be when people who outranked the speechwriters wanted to include jokes that - well, just weren't funny.

"We had a strategy we used to describe it as, you wouldn't kill the joke, you would sort of ease it out into the middle of the highway and slowly back away," Shesol said. "You could drop a joke in a speech and not try desperately to fix it."

More often than not, Shesol said, Clinton would be able to root out the good from the bad and utilize the pen to make the necessary corrections.

But most of Clinton's real preparation came just before he was set to go onstage.

Step 4: Practice Makes Perfect

"Having finalized it, we would go back and when we were literally dressed for the dinner we would go down to the bathroom and he would stand at a podium and run through it once or twice to hone his delivery," Shesol said. "He had a great sense of comic timing so there wasn't much that we'd need to tweak past that."

One of the most important elements for speechwriters, Shesol said, is the ending of the speech, which the president commonly utilizes to remind people of the office.

"I know at least it goes back as far as Franklin Roosevelt where he would do the routine of jokes and then at the end have some kind of grace note," Shesol said. "It was kind of returning everything to its normal place. You were no longer just delivering a series of gags, you were a president and we all had our prescribed roles that we were going to settle back in."

Step 5: Make It Through Dinner

But according to Shesol, the toughest part for Clinton wasn't the speech itself.

"I'll be honest, he hated going to these things," Shesol said. "These were the people who spent their professional lives kicking him around and being, in his view, extremely unfair. He did not relish going to these dinners and he had to sit through these comedians making jokes at his expense."

While the President is likely to get roasted on everything from the Affordable Care Act to his interactions with Russian President Vladimir Putin in the 100th annual dinner this Saturday, Obama's team might do well to look back at history as it puts the final touches on his routine.

"The question is what kind of jokes could the president conceivably make that wouldn't add fuel to the fire," Shesol said. "It's a huge challenge as a joke writer finding ways to address the elephant in the room, without calling it an elephant."