When Haley Anderson competes at the Rio Olympics on Aug. 15, she'll be racing for about two hours in open water off Copacabana Beach. The marathon swim is not for the faint of heart. It's 10 kilometers, or 6.2 miles.

What does it take? "A certain kind of crazy," Anderson said with a grin. "You have to be a little weird to wanna put yourself through two hours or more of pain."

The marathon swim became an Olympic event in 2008, and four years later, at the London games, Anderson became the first U.S. medalist in the event. She took silver in a photo finish after a final sprint, missing gold by a mere four-tenths of a second behind Hungarian Éva Risztov after one hour, 57 minutes and 38 seconds of swimming.

I caught up with Anderson at early morning pool swim practice in late June, as she trained in Los Angeles at her alma mater, USC.

She is lean and sculpted, with vivid blue eyes that match the water she was slicing through. Anderson, 24, holds three individual USC records (in the 500-yard, 1,000-yard, and 1,650-yard freestyle). She was an eight-time All-American, and a five-time conference champion.

Anderson grew up in a swimming family in Granite Bay, Calif. Her mother, Colette, swam for the University of Hawaii. Her older sister Alyssa won gold at the London Olympics in the 4 x 200-meter freestyle. Younger sister Jordan swims for the University of Utah.

"I like that she's like the middle child," U.S. open water head coach Catherine Vogt said, as she watched from the pool deck as Anderson swam laps. Vogt also coached Anderson at USC and at the 2012 Olympics.

"She's really tough and she's really competitive, and she's very observant," Vogt added. "She notices everything around her, which I think helps make her be really good."

Those keen powers of observation are crucial in marathon swim. Racers are swimming through murky, often choppy water. They're frequently bunched tight together, fighting for position and trying to keep marker buoys in sight.

In that scrum, Anderson has to be prepared for lots of physical contact in the water.

"I've been grabbed by my ankles and pulled back," she said, "and that takes a lot of effort, you know. You don't just happen to close your hand around someone's ankle and pull back. That takes conscious effort!"

Vogt compares the marathon swim to a chess match: you need to think strategically and plan your moves in advance. You have to anticipate what the racers around you are going to do, as well as map out your feeding schedule in the water.

Feeding is key in such a long, exhausting event. Vogt and the other coaches stand on a platform mid-course, and hold feeding sticks with cups on the end for their respective swimmers to grab as they race by.

Vogt will be holding a stick similar to a fishing pole with an American flag on the end, so Anderson will know which cup to grab. Hers contains a mix of Gatorade and energy goos to keep her sugar level up in the grueling race. She may also stash some packets of energy goos in her suit in case she needs an extra boost.

Even at her elite level, Anderson constantly fights self-doubt during her races.

"You have to push yourself past what you think you can do, push past the barriers in your mind, 'cause in every race you don't think you can do it," she said.

So what's her mantra to eliminate those doubts?

"Nothing earth-shattering or eloquent," Anderson said. "Just positive sayings to mask all the negative stuff going through your head - 'You can do this. You've trained for this.'"

Sometimes a song enters her brain, unbidden, and gets stuck there. It's never the song she wants.

"There were a few races where I had Justin Bieber's 'Baby' stuck in my head," she recalled, unhappily. "For two hours!"

So that's one hazard. Far more troubling is that invariably in open water swimming, with wind and waves, she will end up swallowing quite a bit of water, which, given Rio's notoriously polluted water, is a scary thought.

"I do take in a lot of water as I'm swimming," Anderson told me. "A couple mouthfuls over two hours. If there's a wave that comes by, sometimes you happen to breathe in."

Anderson's race and other open-water swimming events will take place in the Atlantic Ocean off iconic Copacabana Beach. The water there is heavily polluted, though Brazilians and tourists swim there every day in large numbers. She swam there in January, and got stung by a jellyfish.

(Even more polluted is nearby Guanabara Bay, where the sailing and rowing events will be held.)

Anderson will take probiotics and antibiotics before the race, and will try not to think about what she's ingesting. She tells herself, "don't worry about things you can't control."

Instead, as she swims, she may draw inspiration by keeping an eye on her left wrist. There she sports a tattoo of the five Olympic rings. She got it after she won silver in London four years ago.

"My mom says it's the only tattoo I can get," Anderson said, laughing.

When she sees that tattoo, "I just think about how much time, how much effort I've dedicated to this sport, and also how much it's given back to me. All the places I've been able to go, the people I've met. It's a constant reminder of the sport I love and everything I've gotten from it."

Copyright 2016 NPR. To see more, visit http://www.npr.org/.