If Hollywood wanted a script about the inexorable decline of a corporate icon, it might look to Hewlett-Packard for inspiration. Once one of Silicon Valley's most respected companies, HP officially split itself in two on Sunday, betting that the smaller parts will be nimbler and more able to reverse four years of declining sales.

HP fell victim to huge shifts in the computer industry that also forced Dell to go private and have knocked IBM on its heels. Pressure from investors compelled it to act. But there are dramatic twists in HP's story, including scandals, a revolving door for CEOs and one of the most ill-fated mergers in tech history, that make HP more than a victim of changing times.

HP isn't down and out: It could still confound skeptics and return some of its former glory. But the breakup is an inauspicious moment for a company that was once one of the tech industry's finest. Here are some of the events that got HP to where it is today.

Comdex Carly Fiorina, who engineered HP's Compaq acquisition, at the Comdex trade show in 1999

The Compaq acquisition: Much has been said about HP’s 2001 buyout of its larger PC rival, and the story is back in the news thanks to then-CEO Carly Fiorina’s U.S. presidential campaign. Without getting bogged down in whether Carly made a huge error, it’s safe to say that the deal did not set HP up for the future. Dell’s direct sales model was about to turn the industry on its head, and tablets and smartphones would deal a blow from which PCs have never recovered. HP bet big on a losing horse.

The pretexting scandal: You want a movie script? In 2006, HP admitted it had hired private investigators who spied on its own board members to figure out who was leaking company information to journalists. Criminal charges against HP executives were eventually dropped, but it cost the jobs of board chair Patricia Dunn and several other top staff. It was an embarrassing distraction at a time when HP needed to get down to business.

The EDS purchase: Buying a big IT services company in 2008 looked like a smart way for HP to diversify into more profitable areas, but HP “never unlocked the value from the deal they were looking for,” says IDC analyst Crawford Del Prete. Soon after, the market turned from large outsourcing deals to smaller contracts, and HP was riding the wrong horse again. Its services business continues to struggle.

Mark Hurd scandal: Like Fiorina, Hurd is a divisive figure for HP watchers. What's undeniable is that his relationship with R-rated movie actress Jodie Fisher cost him his job and kicked off a disastrous string of events for HP. More contentious is whether Hurd’s rampant cost-cutting stunted innovation and set HP up to fail. Del Prete doesn’t see it that way: Hurd slashed expenses, was adored by Wall Street, and probably would have reinvested some of those savings in the long term, he says. Regardless, his ouster kicked off the most damaging period in HP’s history. Hurd was forced to resign, ostensibly over an inaccurate expense report. If only his successor's missteps had been so trivial.

Hewlett-Packard Leo Apotheker had a short tenure as HP CEO

Leo Apotheker. Oh Leo, what were you thinking? Or maybe that’s a question for HP’s board. The former SAP chief took over from Hurd in September 2010 and managed to do a lot of damage before his ouster 11 months later. "He was really a software sales and marketing executive," says Del Prete. "He had a hammer and everything became a nail." Among the highlights of his tenure:

The Autonomy debacle: The New York Times has called it “the worst corporate deal ever,” and it’s hard to argue it didn’t contribute mightily to HP’s woes. HP shelled out $11.1 billion for the U.K. software maker and took a write-down of $8.8 billion the following year, effectively admitting that it had drastically overpaid. HP claims it was hoodwinked by Autonomy's management, and lawsuits are ongoing, but there’s evidence that HP rushed the deal without knowing what it was getting into. It was another big distraction for HP and gave more ammunition to investors who wanted change at the company.

The PC blunder: At the same time it bought Autonomy, Apotheker announced that HP was considering a sale of its PC division. It wasn’t a terrible idea — IBM did the same and hasn’t looked back — but dithering about it in public for many months caused uncertainty that hurt HP’s business and helped its rivals.Apotheker also killed off HP's webOS smartphones and tablets, which HP gained when it bought Palm for $1 billion a year earlier. At a time when smartphones were the hottest item in tech, it was a curious decision, to say the least.

Revolving doors: Before a year was up, HP’s board had had enough and Apotheker was replaced by Meg Whitman, the company's third CEO in 13 months. Her first move: announcing that HP would keep its PC division after all. Whitman seemed an unlikely choice after her 10 years running Ebay, but she's won praise for making the best of a tough assignment.

Cloud confusion: It's an open question whether an enterprise IT company needs its own public cloud, but it's now clear that HP won't have one. It said a few weeks ago it will shut down its Helion cloud services in January, and focus instead on "hybrid" infrastructure and partnering with other cloud providers. HP's public cloud was another initiative started by Apotheker, though one wonders if HP couldn't have done a bit more with it after four years of effort.

None of these events alone landed HP where it is today. The move to cloud computing and collapsing PC market played a role, along with the ongoing decline in proprietary high-end Unix systems. The failure of Intel’s Itanium processor, on which HP bet the farm in systems, was also a major setback.

Despite all the missteps, the two HPs remain formidable entities, each with some $50 billion in revenue. HP Inc., which will sell PCs and printers, is unlikely to produce much growth, but the PC business can generate a good amount of cash, as Michael Dell has proved. And the core infrastructure business of Hewlett-Packard Enterprise has "never been executing better," according to IDC's Del Prete, who pointed to its 3Par storage gear and industry-standard servers.

"We don't see customers being at risk from the split," he said, meaning IDC isn't advising HP customers to shop around.

What matters, he says, is whether Hewlett-Packard Enterprise can make the right acquisitions and partnerships over the next 24 months to bring back some growth.