When the market gets rough, it can pay to buy shares of companies that everyone knows aren't about to go anywhere, even if things get worse. And when it comes to those types of businesses, it's especially hard to imagine a world where pharmacies like Walgreens Boots Alliance (WBA 0.44%) become irrelevant or unsustainable.

But Walgreens is far from the perfect investment, and its shares have fallen over 40% over the past five years, badly underperforming the market's gain of nearly 76%. Let's examine two arguments in favor of buying it now and one for selling it, so you'll get a stronger sense of how effective of an investment it could be for your goals and needs.

1. It'll likely recover from inflation and supply disruptions

Between inflation and supply chain issues, most retailers have seen their margins compress over the last year, and Walgreens is no exception. Its earnings per share (EPS) from continuing operations crashed by 73% in its fiscal third quarter, hitting $0.33. Still, management's guidance for the 2022 fiscal year hasn't changed despite problems in the economy, even after a weak quarter. In other words, its operating conditions are expected to stabilize or improve enough to make up for the bump in the road.

Its profit margin will likely remain narrow, but it has one big benefit -- consumers need its consumer healthcare products and pharmacy services no matter what. Even if people economize on groceries or discretionary items, medicines and healthcare goods will be a higher priority for almost everyone.

That's why Walgreens' retail sales rose by 2.4%, excluding tobacco, in its fiscal third quarter. And it's also why hiking prices to keep up with rising supply costs won't destroy much in the way of demand. Assuming inflation continues, the business will continue to be better positioned than others when it comes to preserving its top line.

2. It's valued somewhat cheaply

At the moment, Walgreens' trailing price-to-earnings (P/E) multiple is about 6.1 whereas the P/E of major competitors like CVS Health is above 15.8. Furthermore, Walgreens compares favorably to the market's average P/E of just over 19. Both of these comparisons show it's valued on the cheaper side. Conservative investors could have a wider margin of safety if they buy its shares since the risk of a collapse brought on by an inflated valuation is significantly lower than it might be with other stocks.

Furthermore, a low valuation also implies a special opportunity for contrarian investors to bet against the grain at a lower risk than normal. Stocks get sky-high valuations when the market expects the underlying companies to grow rapidly, and the reverse is also true. Walgreens' cheapness makes sense as it's improbable for a national pharmacy retailer chain to expand its earnings at a pace that'd justify a high valuation.

And of the 21 Wall Street analysts who cover the company, a whopping 18 say to hold its stock rather than buy or sell it. If it ends up bucking expectations and topping the estimates for its growth, the people willing to bet on it when its shares were cheap will get an outsized reward, though it probably isn't the right move for everyone.

Now, let's look at the argument in favor of selling.

1. It isn't growing quickly, and it probably won't anytime soon

As you may have guessed, Walgreens' slow growth is precisely why someone might want to sell their shares. Over the last five years, its trailing 12-month (TTM) net income only grew by 31.9%, and revenue over that period rose only by around 13.8%. Likewise, its free cash flow (FCF) fell by more than 41.7% in the same period. Furthermore, servicing its debt load in excess of $38.2 billion means that management's ability to invest for faster growth is quite limited, so there isn't much of a chance for the situation to improve without significant changes.

Right now, management plans to save $3.5 billion annually by the 2024 fiscal year. Still, it's important to recognize that its total operating expenses in 2021 were above $24.5 billion. Finding a few billion in savings will doubtlessly be better than if management didn't look, but it won't fundamentally change the company's prospects until it can pay down some of its debt, which will take more time.