Shares of IBM (IBM -0.84%) and Microsoft (MSFT 0.92%) have both seen better days. IBM has slumped 14.3% over the past 12 months. Microsoft stock fared better with a 13.6% gain, but slid 9% after its mixed second-quarter earnings report.

IBM Chart

Source: YCharts.

Both tech titans are transitioning their older business models toward the cloud, and both have been posting declines in their core businesses. However, contrarian investors should take a second look at these two "bad news" stocks to see if either is worth buying as others sell.

Top-line comparison
Last quarter, IBM's revenue fell 12% year over year to $24.1 billion, dropping across all business segments. Software revenue declined 7% to $7.6 billion. global technology services revenue fell 8% to $9.2 billion, global business services slid 8% to $4.3 billion, and system and technology revenue plunged 39% to $2.4 billion.

IBM attributed those declines to weak client spending, sluggish demand in the software sector, and the divestitures of several lower-margin businesses, including its x86 server, microelectronics, and customer care divisions. Those divestitures were intended to improve the company's earnings per share, but they also took a bite out of its top line.

By comparison, Microsoft's revenue rose 9% year over year to $26.5 billion last quarter. Device and consumer revenue rose 8% to $12.9 billion, while commercial revenue grew 5% to $13.3 billion. However, Windows Pro and non-Pro revenue both fell 13%, prompting fears that Microsoft was slowly killing its cash cow with free and cheap licenses for OEMs. Nonetheless, Surface, Windows Phones, and Xbox sales remained solid, while the number of Office 365 personal and home subscribers rose 30% sequentially to 9.2 million.

This disparity between these two companies' revenue growth isn't new. Over the past five years, IBM's revenue has steadily slipped as Microsoft posted double-digit gains.

IBM Revenue (TTM) Chart

Source: YCharts.

Bottom-line battle
In 2007, then-IBM CEO Sam Palmisano promised to double the company's EPS to $20 by 2015. But to fulfill that lofty promise, IBM divested its lower-margin businesses and financed share buybacks with debt. Over the past 12 months, IBM had free cash flow of $13 billion, but repurchased $18.55 billion in stock.

That strategy resulted in lower revenue growth and the artificial inflation of earnings per share. Even with that support, IBM's diluted EPS from continuing operations fell 4% year over year last quarter, as net income fell 11% to $5.5 billion, due to top-line declines in its remaining businesses. On the bright side, CEO Ginni Rometty replaced Palmisano's $20 promise with more realistic EPS guidance of $15.75 to $16.50 for 2015, which would represent just 1% to 6% growth from 2014.

Microsoft's bottom line has been under pressure from restructuring charges related to integrating Nokia's (NOK 0.55%) handset division and the discounts on Windows licenses. Last quarter, its diluted EPS fell 9% to $0.71 per share as net income fell 10.6% to $5.86 billion. Looking ahead, Microsoft's earnings growth will likely remain lumpy as it keeps some Windows licenses free, gives away Windows 10 as a free upgrade, and offers more free trials for Office 365. Wall Street expects Microsoft to finish fiscal 2015 with earnings of $2.44 per share -- a 7% decline from 2014.

The cloud awaits
IBM and Microsoft are both transitioning toward higher-margin cloud-based businesses. IBM is doing this via inorganic growth through acquisitions, while Microsoft is mostly upgrading its existing products and services.

For the full year, IBM's total revenue from cloud-based revenue rose 60% year over year to $7 billion. Within that total, cloud delivered as a service revenue rose 75% to $3 billion, with a year-end annual run rate of $3.5 billion. While $3.5 billion is admittedly a small percentage of IBM's 2014 revenue of $92.8 billion, the company recently inked major cloud deals across multiple sectors that could eventually offset its drastic declines in software.

Last quarter, Microsoft's commercial cloud revenue -- which comes from Office 365, Azure, and Dynamics CRM -- rose 114% year over year, and it is now on track to hit an annual run rate of $5.5 billion. That would also represent a small percentage of Microsoft's expected revenue of $98 billion for fiscal 2015, but it could eventually offset short-term declines in Windows revenue.

The verdict
Here are the three key takeaways from comparing IBM to Microsoft: Microsoft tops IBM in revenue growth, both companies are struggling with bottom-line growth, and both are pivoting their businesses toward higher-margin cloud services.

Despite these similarities, I would buy Microsoft before IBM, since its plans to consolidate the PC market with Windows 10, spread that influence to mobile devices, then tie it all together with universal apps offers more long-term promise than IBM's ongoing problems in the middleware market.