This article was produced in partnership with the Pulitzer Center on Crisis Reporting.

GUANTÁNAMO BAY, Cuba — When the C.I.A. strapped down Khalid Shaikh Mohammed at a secret site in Poland in 2003, those inside the cell included a three-man waterboarding team, black-masked guards — and a doctor.

The doctor’s stated role was to monitor the health of the detainee. He also kept count of each near drowning.

“Literally, the physician had a little silver thing,” James E. Mitchell, one of the architects of the interrogation program, testified last week to the military tribunal at Guantánamo Bay. The doctor, he said, “would click how many times the water was poured” as a guard kept time with a stopwatch.

But the C.I.A. doctors did more than count waterboarding sessions. Government investigations and evidence in the pretrial hearings of the men, including Mr. Mohammed, accused of conspiring in the Sept. 11, 2001, attacks, show doctors conducted “rectal rehydration,” carried out rectal cavity searches and examined swollen feet and legs of captives who were sleep deprived for days by being shackled in painful positions.