The Valero oil refinery looms over the small streets of this blighted port city. A vast maze of pipes and vats and boilers, the refinery traces its rootsback 111 years, to just months after the historic Spindletop gusher that triggered the Texas oil rush.

Today the Spindletop well is marked by a modest flagpole in a wet field just north of here. And oil isn’t bubbling up in large enough quantities to feed the refineries in this area.

So pipelines and tankers have become critical lifelines for an industry that has shaped not only the Texas Gulf Coast but America’s entire oil-based economy.

Enter the Keystone XL pipeline. TransCanada, a Calgary-based pipeline giant, hopes that its Keystone XL project will take Canadian tar sands oil on a 1,700-mile journey from a tank farm in Alberta, across the Great Plains and down the spine of America, and deliver it here.

The refineries are eagerly waiting. The modernized Valero refinery can turn 310,000 barrels a day of some of the world’s worst-quality crude oil — such as the bitumen-laden mixture from Canadian oil sands — into gasoline and diesel fuel for cars and trucks. Valero, the largest U.S. oil refining company, would be one of the biggest customers of oil from the Keystone XL pipeline, buying about 150,000 barrels a day.

Map: Keystone XL pipeline

Explore the controversies surrounding the pipeline. View the full graphic

What happens to the Canadian oil once it arrives in this port is central to the debate over the need to build the Keystone XL. Foes of the pipeline worry that the oil will be exported, either as crude or as refined petroleum products such as diesel or gasoline. As a result, they argue, the United States would get little benefit in return for accepting the risk of a pipeline leak. Rep. Edward J. Markey (D-Mass.) has proposed barring exports of petroleum products made from Keystone XL oil.

Pipeline proponents say it would add to U.S. supplies and reduce dependence on unfriendly governments such as Venezuela’s or unstable regions such as the Persian Gulf. They say bringing additional crude oil onto world markets will also damp prices, which surged again this summer. Even if a portion of the oil products made from Canadian crude is exported, proponents say, that would still ease world prices while sustaining U.S. refining industry jobs.

“Valero has no intention of exporting the crude oil that comes down the Keystone XL pipeline,” said Bill Day, a Valero spokesman. “As for exporting refined products, that is an increasingly important part of Valero’s business, but that’s already happening without Keystone XL and will continue regardless.”

Exports are also a long-standing part of the global trade in refined oil products. American motorists tend to use a lot of gasoline, and not so much diesel. In Europe, it’s the reverse. So American refiners ship diesel to Europe and import gasoline from there. In addition, Mexico and many countries in Latin America lack advanced refineries, and they, too, turn to the U.S. Gulf for supplies.

“Some products get exported, but most stay in the U.S. for domestic use,” Day said. “In the first quarter of 2012, Valero exported less than 18.7 percent of the distillates it produced and less than 6.7 percent of the gasoline it produced.”

Even if Congress decided to stop the export of oil from Keystone XL, the logistics of doing that would be complicated. “Even after Keystone XL is completed and bringing crude oil to Port Arthur, the refinery will still need other sources of crude,” Day said. “We will still bring in some crude by ship, for example. That oil would all get intermingled, and the products made from it would also get intermingled.”

Refineries vie for an edge

The Valero refinery was built in 1901, five months after the discovery of oil at the small mound called Spindletop. A well drilled there erupted and in nine days produced as much oil as the entire United States had pumped in seven months. The gush of oil formed a small lake, where it sat until storage tanks were built.

In the era of plentiful U.S. oil, refiners often made more money than oil exploration firms, essentially dictating crude oil prices while luring motorists with low prices and gimmicks. But since the 1970s, oil markets have lurched back and forth, sometimes rewarding exploration with high prices and at other times favoring refiners.

The Valero refinery, sprawled across 4,000 acres here, is now one of the most advanced. In 2001, its previous owner invested $850 million in pieces of equipment known as a coker and a hydrocracker, which enabled the refinery to process heavy, sour crude — grades that are full of sulfur and harder to turn into high-quality products such as gasoline, diesel and jet fuel. After Valero bought the refinery in 2005, the company invested hundreds of millions more in similar equipment that can break large petroleum molecules into smaller, more valuable ones.

The ability to use low-quality oil gives a refinery a big competitive advantage.

“Their refineries are well suited to take discounted oil whether it’s heavy or sour and make a profit on it,” said Brian Youngberg, an oil analyst at the investment firm Edward Jones. “I would assume they’re very anxious to get this pipeline down there.”

GOP presidential hopeful Mitt Romney, echoing other pipeline supporters, has trumpeted the notion of “North American energy independence,” with Canadian supplies freeing the United States from Middle East supplies.

But the oil market pays little attention to the origin of tankers, and oil industry executives say that the countries most likely to be edged out of the U.S. market would be Venezuela and Mexico.

Motiva, a joint venture of Royal Dutch Shell and Saudi Aramco, recently doubled the capacity of a giant refinery next door to the Valero refinery. Corrosion problems forced the company to close down much of the plant just weeks after a ribbon-cutting ceremony. Fixing it could take months.

But once repaired, the refinery will be the nation’s biggest, and it will most likely import even more oil from Saudi Arabia than it does now, regardless of supplies from Canada. It has not yet signed a contract for oil from the Keystone XL, but if it does, the Canadian oil would probably displace Latin America supplies.

A damper on oil prices?

How would the Keystone XL pipeline affect domestic oil and gasoline prices?

U.S. prices are set in Cushing, Okla. The rundown town of abandoned buildings is surrounded by giant tank farms. The New York Mercantile Exchange uses the price of West Texas Intermediate crude oil as its benchmark, and most U.S. oil prices are based on that price — one set by a mixture of supply and demand, geopolitical anxiety and capital flows from investors or “speculators.”

For decades, oil flowed to Cushing from Texas on its way to big refineries and gasoline markets in the Midwest. But in recent years, more and more oil has been flowing into Cushing, not only from Texas but also from North Dakota and Canada. There isn’t enough pipeline capacity to take that oil south to the Gulf of Mexico refineries, so a bottleneck has developed in Cushing, where firms are scrambling to build new storage tanks.

That’s depressed the price of crude oil in Cushing, opening up a gap of $10 to $20 a barrel between West Texas Intermediate and the similar Brent crude in London. For U.S. refiners, especially in the Midwest, that’s been a bonanza. They buy oil more cheaply than other parts of the world market. For American motorists, especially those in the Midwest, the Cushing glut has moderated sharp increases in gasoline prices. Gulf Coast refiners are able to buy cheap crude and sell diesel at big profit margins to customers in Europe.

Pipeline companies see a niche and are rushing to fill it. Enbridge, another Canadian pipeline company, bought a 50 percent stake in the Seaway pipeline, which used to run from Texas to Cushing, and reversed course beginning in May. Many analysts say that solving the bottleneck in Cushing could increase crude oil prices there and thus throughout the United States.

In March, President Obama made a rare visit to Cushing, where he stood in front of stacks of pipes and endorsed the southern leg of the Keystone XL as a way to ease the bottleneck — without committing himself to the northern leg. TransCanada has secured the permits it needs for the southern leg and has begun construction.

If the northern leg is approved, however, the Keystone XL would have little effect on the bottleneck at Cushing. The pipeline would carry as much oil into Cushing as it would carry out. In its first application to the Canadian National Energy Board, TransCanada estimated that leapfrogging Cushing could boost oil sands prices by $3 a barrel, providing an extra $2 billion to $3.9 billion a year to oil sands producers.

Instead, some oil experts say that Keystone XL’s new oil supplies from Canada, combined with other new pipelines from Cushing to the Gulf Coast, would effectively just move the crude oil glut from Cushing to Texas.

Texas refiners would then have greater bargaining power and could play off Canadian oil sands against Venezuela’s Orinoco crude or Mexico’s Maya crude or even higher quality “sweet” U.S. domestic crude from the Bakken or a similar formation called the Eagle Ford in Texas. Both Valero and Marathon have been operating their cokers at less than full capacity because the price of higher-quality domestic crudes was more attractive, according to Robert Johnston, director of energy and natural resources at the Eurasia Group. Those U.S. supplies will grow, Johnston notes, adding that the U.S. domestic “production boom is now driving further risks for Canadian oil exports.”

The volume of oil processed by the refineries wouldn’t change. But as U.S. gasoline consumption declines, a result of improved automobile fuel efficiency and additional biofuels, refiners would continue to export a substantial amount of products from Canadian and other petroleum supplies.

Harold Hamm, chief executive of Continental Resources and a major oil producer in North Dakota’s Bakken formation, supports the Keystone XL pipeline but worries that the new supplies will drive down prices. That might be good for the country, said Hamm, an adviser and major financial backer to presidential candidate Mitt Romney. But he added, “from a selfish standpoint I [would] just as soon it not get built. We’ll be competing against it for U.S. supplies.”

In Port Arthur, ‘the real world’

For the oil industry, Port Arthur is a good location. Tankers slide up the Sabine Pass, and networks of pipelines crisscross the region. The Gulf of Mexico offers relatively easy access to Latin America, the eastern United States, the Panama Canal, Europe and Africa. Moreover, 23 percent of U.S. domestic oil is produced in the Gulf of Mexico.

As a result, more than 40 percent of U.S. refining capacity is situated along the gulf coast.

Although investment is pouring into Port Arthur’s refineries, the city itself has reaped little benefit. The old downtown’s Proctor Street, once lined with stately hotels, office buildings and fancy cars, is virtually abandoned. (One exception: A bar called Club Sistahs, which has some live bands.) The blocks near the refineries have small, rundown homes. People living below the poverty line make up a quarter of the population, according to the U.S. Census. Per capita income is just two-thirds of the Texas average. Fewer than one in 10 people over age 25 have a college degree.

The town’s most famous sons have included painter Robert Rauschenberg, football coach Jimmy Johnson and singer Janis Joplin, who said of her hometown: “What’s happening never happens there.”

Luther Fields, with flecks of gray in his goatee, was a city trash collector for seven years. He hurt his back on the job and then “had some trouble with the law” — minor thefts, he said. Now he has little chance of getting a job.

“They got plenty of money from the oil, but I don’t know what they do with it,” Fields said outside the Jesse Jackson Educational Center, where a Baptist revival meeting was being held. “The oil flows in and the money flows out. But it doesn’t seem to stick around here.”

Looking up at the refinery stacks just 200 yards away, he said: “See that? That’s the dream world over there. I’m in the real world. I just want to get my life back together. I want a piece of the action.”