Like a bulldozer that has unexpectedly hit granite in a sandpile, Caterpillar Tractor Co. has run into hard times.

After posting its best profit ever last year, Caterpillar has just reported its poorest per-share results in a nonstrike quarter since the Depression, as its primary markets--construction and energy equipment--have slumped with the economy.

The company, which until two years ago had not laid off a single employe in two decades, now has 17,000 workers on indefinite layoff, roughly one-quarter of its total workforce. Most of the layoffs have come in the past couple of months, and almost half have been in the Peoria area, where Caterpillar is by far the largest employer.

Not just jobs have been cut. The company has embarked on an aggressive program to reduce costs and inventories. Capital spending plans have been slashed. Earlier this month, Cat cut the pay of white-collar workers 3 to 9 percent and reduced the salaries of 22 top executives by 10 percent.

"We've bitten a lot of bullets around here," says Caterpillar Chairman Lee L. Morgan.

But while a recent cartoon in the Chicago Tribune showed Caterpillar and International Harvester Co. tractors laboring fruitlessly to drag a Braniff airliner out of a chasm, Caterpillar's predicament is not as dire as that of bankrupt Braniff or nearly bankrupt Harvester--as Morgan pointed out in an angry rebuke to the newspaper. Caterpillar remains cash-rich and in a good position to borrow money if it needs it, analysts say, and the company's cost reductions will aid its bottom line even if its markets don't bounce back soon.

But Caterpillar, which had prided itself on the diversity of its business, both by product line and geographically, now finds itself with problems almost everywhere. The troubles come at a time when it already has its hands full with competition from Japanese and European tractor makers, particularly Japan's Komatsu.

In addition, Cat is negotiating with the United Auto Workers union over a contract to replace the one that expires Sept. 30. While neither side expects a strike, labor troubles would add to Caterpillar's woes--although hedge buying by customers and dealers worried about a strike is expected, ironically, to help the company's third-quarter results.

What has happened to Caterpillar is that its international and energy equipment businesses, which had been offsetting declines in its domestic construction equipment lines, have now turned sour as the recession has hit the rest of the world and declining prices have slowed oil exploration and production.

"Things just really went to pot," says Morgan. "The economy has gone to hell, really."

Despite its reputation on Wall Street for conservative, sharp management, Caterpillar didn't anticipate the downturn. Its projections were for rebounds in its primary markets in the second and third quarters this year.

"I think our enthusiasm . . . was based more on the condition that business was going to turn up," Morgan says. "This year is turning out to be quite a different year than we had expected it to be."

That Caterpillar avoided disaster as long as it did is a tribute to its diversity. Although the company is best known for its ubiquitous yellow bulldozers, it makes a variety of other products that in the past have protected it when the domestic construction business slumped. It has been particularly active in energy equipment, with products used in oilfield construction and development and diesel engines that power remote drilling and production facilities.

More important, the company does more than half its business overseas, where its construction equipment is a basic need of developing countries. Caterpillar equipment is sold in just about every nation--one reason Morgan has long championed the cause of free trade. Last year, 56.6 percent of Caterpillar's record $9.15 billion sales came from overseas.

John McGinty, an analyst at First Boston Corp., estimates that demand for Caterpillar products overseas has dropped as much as 25 percent in the first half of this year. "Demand is very, very soft," he says.

Similarly, demand for Cat equipment in oilfields has slumped as sagging oil and gas prices have led oil companies to shrink their development budgets. And many developing countries that happen to be oil-rich have scaled back their modernization plans, cutting demand for Caterpillar earthmovers.

"We don't have some offsetting geographical areas or product application areas that have sort of propped up our business as they have in the past," Morgan says. "All major geographical areas and all product application sectors are down in varying amounts. Virtually all of them are depressed."

Caterpillar officials have been working hard to tailor costs to the lower sales levels. Capital expenditures for 1982, originally pegged at $750 million, have been reduced to $600 million. The company has also moved to reduce inventories, which are expensive to carry at high interest rates. Analysts, however, say this process has been difficult because of the reluctance of dealers to take equipment they might have trouble selling, particularly when they can get it quickly from the company's stocks.

But Caterpillar's most visible cuts have come in its employment rolls. "I guess we have to clearly declare the performance of the world's economy as the winner in the contest, over our corporate practices and best intentions of trying to stabilize employment," Morgan says.

Caterpillar began laying off workers two years ago, but started making cuts in earnest earlier this year. As recently as February, the company only had about 3,000 employes on indefinite layoff. Eight thousand workers were furloughed on June 7; the next round of layoffs this fall will put the total at 18,500 workers, most of them in Illinois, where Cat is the largest private employer.

And as Caterpillar goes, so goes Peoria. The company dominates many areas of the city's life, and, at peak, employs about 36,000 persons, a bit more than 20 percent of the area's total employment. Caterpillar is not the only company in town cutting its workforce; within the past year, a Hiram Walker distillery and a Pabst brewery have closed, taking several hundred jobs with them. (The Hiram Walker plant, purchased by Archer-Daniels-Midland, will soon reopen, however, to make industrial alcohol and as a grain terminal.) Unemployment in Peoria is running about 11.5 percent, and city officials expect it to rise to 14.5 percent at the peak of Caterpillar's layoffs this fall.

At a time when the city is trying to revitalize its downtown area and has just finished building a gleaming $65 million civic center, the lost jobs and wages are hurting local businesses, reducing Peoria's sales-tax revenues and increasing the number of people on welfare.

"The impact on the private economy, of course, is considerable, particularly when you have a private economy that has never known a peak unemployment rate of more than 6 or 7 percent," says Mayor Richard E. Carver.

But Carver says that while Caterpillar cuts have caused hardship, they have not brought much resentment. Peorians seem to understand the company's problems, and believe they are temporary, he says. "There is absolutely nothing in the current downturn in the Peoria economy that suggests it will be anything but temporary," Carver says.

"This is a company that has taken the necessary steps right down the line in a very considered fashion to ensure the long-term viability of the company," he adds.

The measures taken by Caterpillar also play well in places other than Peoria. Industry analysts give the company high marks for moving quickly to deal with its problems.

"They reacted very, very quickly and they've reacted monthly," McGinty says. "They've done a magnificent job of cutting back on their costs, fixed and variable, and done an extremely good job of avoiding losses. Most companies with that kind of drop in demand would be losing money."

Analysts believe that Caterpillar's lackluster $9.7 million, 11-cent-a-share profit in the second quarter--a 94 percent drop from the year-ago quarter--is not indicative of future earnings, even though per-share earnings this year will drop to about $1.50 from last year's record $6.44. They say the effects of the cost-cutting will begin to improve earnings in the second half and into next year even if the economy doesn't improve.

"Cost-cutting and other things will make things look better in the second half," said Eli Lustgarten, an analyst at Paine Webber, who is predicting 1983 profits of $4.50 a share for the company. McGinty says, "They could recover to $3 or $4 in 1983 without a big change in demand."

And Caterpillar remains financially strong from a cash and borrowing standpoint, an advantage International Harvester did not enjoy when it ran into trouble.

When Duff & Phelps, the Chicago-based financial-rating service, lowered Caterpillar's debt rating a notch in late June, it nevertheless commended the company for doing "an excellent job in scaling back operations to present business levels."

Morgan is confident that Caterpillar will come back stongly once interest rates subside and the world economy improves. "I remain optimistic about the fundamental needs which our company's products serve: energy, transportation, food and water, industrial development and things of that kind," he says.

Even if the markets don't come back for years, Morgan says, Caterpillar could keep operating profitably, although it eventually might have to make some permanent cuts in its size.

Although Morgan is looking for economic improvement next year, the sudden shock felt by the company this year has caused him to be conservative in his projections. "We are quite convinced that the early part of 1983, at the best, won't be a whole lot better than slightly improved over the current level of activity," he says, then adds: "I'd like to be surprised on that score."