A resident shaves using a car window as a mirror amongst cars parked by World Cup tourists for a fee. Tourists were parking in an area where homes once stood. (Mario Tama/Getty Images)

No, Steve Jobs declared. Apple wouldn’t put a store in Brazil, with its “crazy” and “super-high” taxation. This was 2010, and Jobs was writing, bluntly, to an official in Rio de Janeiro.

Four years later, Jobs’s successor had a different message for Brazilians.

“ ‘Obrigado’ to everyone who visited our new store,” CEO Tim Cook tweeted in February, after 1,700 people packed into a Rio mall for the opening of the first Apple store in Latin America. “We are Brazilians, with lots of pride and lots of love,” his blue-shirted employees sang, adapting a tune heard in stadiums and bars when the national soccer team plays.

Apple is one of many foreign brands feeling the love for Brazil — even if Brazilians, mired in an economic slump, aren’t. As the country hosts this year’s World Cup and prepares for the Olympic Games in 2016, the optimism that led it to bid for the planet’s two most famous sporting events has all but evaporated.

Inflation and flagging growth are squeezing Brazil’s new middle class, whose anger is so intense and encompassing that its targets include the World Cup itself — an amazing thing in a country that is the definition of soccer mad. Protesters have jeered the national team, the World Cup trophy and the country’s president, Dilma Rousseff, whom Brazilians blame for spending extravagantly on stadiums while neglecting basic public services.

In May, Sao Paulo bus drivers snarled 162 miles of traffic when they threw away their keys in a strike, a fitting image for a country that is stalled after years of rapid economic growth.

The foreign investors still come, drawn by something even high taxes can’t take away: young, increasingly educated and affluent consumers. Companies as diverse as Forever 21, known for trendy fashions, and luxury automaker Bayerische Motoren Werke are putting down stakes this year.

“Brazil has changed,” says Arturo Pineiro, head of BMW Brasil Group, which is investing $276 million in a plant scheduled to open later this year in Araquari, in the country’s south. “It has some problems, but, with the right focus, they can be solved.”

It can be hard to find ordinary Brazilians who agree with him, amid reports of protesters pelting police with rocks — or, at one clash in May, shooting them with arrows — and widespread griping about public corruption.

When the country was awarded the two sporting events last decade, then-President Luiz Inacio Lula da Silva — just Lula to Brazilians — was hailed as a miracle worker. The former union leader guided an epic boom during eight years in office, from 2003 to 2010, with the benchmark Ibovespa stock index growing sixfold and annual economic growth reaching as much as 7.5 percent. This allowed Lula to plow cash into his ambitious Bolsa Familia, a program that gives low-income Brazilians a monthly stipend in exchange for sending their children to school and has helped cut the poverty rate in half.

Brazilians long for those days now. Economic growth has slowed to just over 2 percent annually, and the stock market has declined by more than 20 percent in three years under Rousseff, Lula’s former chief of staff.

Much of this can be attributed to the shrinking of China’s once-enormous appetite for Brazilian commodities. Last year, Brazil, a huge producer of beef, chicken, soybeans and other agricultural goods, came close to a trade deficit for the first time since 2000.

Far from showcasing Brazil’s strengths, the World Cup is shining a light on a key weakness. Lula pledged that projects for the games would jump-start investment in transportation upgrades, and Rousseff promoted a Growth Acceleration Program, known as PAC, that would reinvigorate the economy.

Instead, the $3.6 billion spent on new stadiums was almost four times initial estimates. Other projects floundered: Contas Abertas, an organization that works for government transparency, said in April that only 12 percent of the planned public works projects were completed. A promised bullet train from Rio to Sao Paulo was shelved.

A YouTube video shot in the city of Porto Alegre captured the public’s mood: In it, young people dance to the Pharrell Williams hit “Happy,” past piles of dirt, rutted roads and angry graffiti, as extravagant official predictions for Cup riches scroll past.

“We’re ashamed to receive foreigners into this chaos here,” says Ana Trindade, 40, who organized a protest in Porto Alegre, a World Cup host city and once Rousseff’s home. “The World Cup will leave behind no legacy whatsoever, just more debt and less investment in health, education and transport.”

A one-time World Cup hero who’s now an opposition politician puts it even more starkly: “I’m rooting for Brazil to win on the field,” says Romario, a striker on the team that won the 1994 World Cup. “Off the field, we’ve already lost.”

How does any of this square with the sanguineness of a core of investors? Remember that 30 years ago, Brazil was a country that had been ruled for 20 years by an authoritarian military regime. Forty years ago, Rousseff was a Marxist guerrilla who had been jailed and tortured.

Now, Brazilians express their dissatisfaction with their government peacefully, for the most part, and look for answers at the polls. When Rousseff’s Workers’ Party faces voters in October, the election will turn on basic pocketbook issues, as in most other Western democracies.

Pimco’s shift

The shift at the giant bond shop Pacific Investment Management Co. reflects this stability. As recently as January, Pimco despaired over Brazil. Founder Bill Gross said the country was no longer a preferred emerging market. A few months later, a team of Pimco credit analysts visited the country and came back with a different point of view. The deep pessimism of Brazilians, they said, was great for investors.

Pessimism was going to drive change, Mark Kiesel, Pimco’s deputy chief investment officer, wrote in an April report. And if that was the case, investors were undervaluing Brazil’s strengths: a huge resource base, a democratic government and favorable demographics, including a median age of 30.7, compared with 46.1 in Germany and Japan and 37.6 in the United States.

“Simply put, there comes a point to take the road less traveled, when a lot of bad news is priced in,” Kiesel wrote.

Long known for fabulous wealth mingling with dire poverty, Brazil now has a middle class that numbers 109 million, according to research firm Data Popular. The Brazilian government’s Secretariat of Strategic Affairs defines middle class as average monthly per capita income of 291 reais ($124) to 1,019 reais, based on data from mid-2012.

Although that isn’t rich by the standards of developed countries, 29 million Brazilians are in the nation’s wealthiest income classes, up from 13 million in 2002, according to Finance Minister Guido Mantega. They have a monthly average family income of 5,329 reais or more.

BMW is targeting those wealthier consumers with the plant it’s building in Araquari. BMW Brasil Group President Pineiro, 49, is a Sao Paulo native and a returnee. In the 1990s and early 2000s, Pineiro worked for BMW in Spain and the United States.

“The country was broken when I left,” he says.

He remembers the havoc caused by 500 percent annual inflation in the 1980s; in 2014, economists are wringing their hands over inflation approaching the government’s declared upper limit of 6.5 percent.

Slowing wage growth and rising debt have dented consumer spending, but an jobless rate below 5 percent has kept the middle class from shrinking.

“They are learning about consumption for the first time,” Pineiro says. “As they start to consume, it’s very unlikely they’ll go back.”

Those consumers are a boon for both Brazilian businesses and international companies. After average monthly incomes almost doubled from 2006 to 2012, Brazilian households could afford more than just staples. Packaged food sales have risen 9 percent a year in the country for the past five years, and the industry may add another $75 billion in sales by 2018, estimates Sean Walker, president of Latin America for General Mills, the Minneapolis-based maker of Cheerios.

“We have no reason to fear anything,” says Abilio Diniz, who built a supermarket chain into the country’s largest retailer and is now the billionaire chairman of BRF, Brazil’s biggest food producer. “This country has solid fundamentals.”

Byzantine bureaucracy

It also has fundamental weaknesses, in the estimation of the World Bank, and is not addressing them with urgency. In ease of doing business, the bank ranks Brazil No. 116 of 189 countries. In 2006, it was No. 119. That reflects a byzantine bureaucracy in a famously protectionist country. As one Portuguese phrase goes, para ingles ver — “for the English to see.”

The phrase originally referred to abolition laws that Brazil passed in the 1800s under British pressure; it’s meant to convey a sense that some policies are only for show. Because of the taxes and tariffs Jobs complained about, the iPhone 5s Apple sells in Rio — plastered on billboards in Brazil’s green and yellow colors, with the slogan que bonito e, “How beautiful it is” — is the world’s most expensive, at $1,257. That compares with $649 in the U.S.

In March, Mantega spoke to economics students at a Sao Paulo university. He made the case for his government’s policies and for the pro-investment camp. Brazil weathered the 2008 financial crisis better than most major economies while boosting foreign reserves to more than $370 billion, he said. He pointed to the 20 million jobs created since 2003. He said infrastructure spending could help growth reach 4 percent annually during the next eight years.

That last contention is conspicuously optimistic: Economists surveyed by Bloomberg see 1.8 percent growth in 2014, 2 percent in 2015 and 2.7 percent in 2016.

If Mantega is correct, then que bonito e indeed for Apple and Tim Cook. If the pessimists, and the Brazilian people, are being more realistic, it could turn out that Steve Jobs was right again.

The full version of this Bloomberg Markets article appears in the magazine’s July/August issue.