Not long after his schemes led to the deaths of more than 160 people in Mumbai in 2008, David Headley had a dream.
It was early 2009 and he envisioned the Prophet Mohammed's tomb, with his own final resting place "not next to the prophet's grave itself, but a little distance away."
Mr. Headley, now 50, concluded that his vision meant great heavenly rewards awaited him - if he were successful in a new attack. The plan?
Get gunmen to shoot up the Denmark offices of Jyllands Posten, so that he could avenge Islam against the newspaper that affronted God's messenger with a cartoon.
So testified Mr. Headley in a Chicago court Thursday, where the 50-year-old convicted terrorist is giving evidence against a peripheral player, Tahawwur Rana, to save himself from the death penalty.
Mr. Headley, who has pleaded guilty to several terrorist offences but has not yet been sentenced, has now concluded a week's worth of testimony in the trial of his lifelong best friend. An understated government witness who often gives the impression that he believes his actions to be unfailingly logical, he revealed himself as a man stitched together from irreconcilable contradictions.
The product of a broken bicultural home, Mr. Headley was raised in Pakistan by his father, came to the United States to live with his mother in his teens, and floated back and forth between the two countries ever since.
After he became a white-skinned member of several Pakistani terrorist groups, Mr. Headley's plots killed scores of people during the Mumbai massacre, including several of his fellow American citizens.
He acknowledges that his greatest assets are that he is trained to be a liar and a manipulator. Yet his testimony is being closely watched by observers everywhere, in the hope that he'll definitively settle some truths about Pakistan's clandestine support for global terrorism networks.
Though the fundamental facts are not in dispute, Mr. Headley's testimony will raise more questions than answers when it concludes next week.
In June, 12 jurors will have to decide how much of Mr. Headley's twisty narrative they want to believe, but for them, the matter is relatively simple.
During his endless travels to scout out targets for terrorist attacks, Mr. Headley frequently presented himself as an immigration consultant.
The court must ultimately decide whether the accused, Mr. Rana, a Pakistani-Canadian proprietor of a Chicago company called First World Migration, was Mr. Headley's willing co-conspirator or unwitting dupe.
Mr. Rana may have supplied some papers but it was Mr. Headley who did all the legwork.
From 2000 onward, he spent years training as a terrorist with Pakistan's Lashkar-e-Taiba jihadist organization. More intriguing than that are his claims he had a Pakistani government handler from 2006 to 2009 - a "Major Iqbal," reputedly a serving member of the Inter-Services Intelligence Directorate (ISI).
Mr. Headley testified that Major Iqbal's group ran him through more than 50 intensive courses in surveillance, countersurveillance and general spy craft - all before he sneaked into India to videotape the Mumbai landmarks that were eventually attacked by Lashkar gunmen in 2008.
Pressed by defence lawyers on Thursday for details about his ISI links, Mr. Headley seemed evasive at times. He said he never learned Major Iqbal's full name nor did he ever figure out who his master's bosses were. Asked where they met, Mr. Headley said it was in a white house in a busy Lahore neighbourhood - but he didn't have an address and nor could he give directions verbally.
Defence lawyers were left to ask: If Mr. Headley truly was a man trained to operate in the shadows by the ISI, why was he so often so indiscrete?
The Headley testimony is that he told at least one of his wives (there were two) and Mr. Rana about the Mumbai plot long before it was executed. Afterward, he all but telegraphed his never-executed attack against Denmark.
In the Chicago court, Mr. Headley said that after his initial surveillance trip to Denmark in 2009, he brought four or five souvenir baseball hats marked with "Copenhagen" across the brim back to Pakistan for his intimates - as a kind of macabre inside joke they all immediately understood.
Frequently, Mr. Headley referred to the terrorist scheme in written communications as the "Mickey Mouse Project" - which defence lawyers pointed out was a pretty clear allusion to the fact he planned to kill a cartoonist. "I guess I didn't do a very good job making a code," Mr. Headley deadpanned, to chuckles in the courtroom.
Defence lawyers questioned Mr. Headley's claims that he filled in Mr. Rana on the gory details of the Denmark plot. It was ever in flux, but in its most ambitious incarnation, gunmen would storm the newspaper, decapitate staff members and throw the heads out of windows.
How did Mr. Rana, never himself a violent man, react to that? "He just said 'Okay' ... He wasn't jumping with joy ... He didn't object," Mr. Headley replied.
The two men had met in military school nearly 40 years ago, with trouble being as much a constant in Mr. Headley's adult life as diligence was in Mr. Rana's.
Dressed in a windbreaker and Adidas track pants, Mr. Headley stood ramrod straight when the judge and jury entered the room.
He testified that he had fancied himself a soldier, of sorts, and at times he seemed an almost visible counterpoint to the slouched, suited and slight figure of his confidant Mr. Rana, whose hair has turned snow white.
When defence lawyers suggested to Mr. Headley that he often made small talk with Mr. Rana just to advance his schemes, the self-styled Islamic warrior furrowed his brow.
"When you care about somebody you ask what they are doing," Mr. Headly replied, sounding almost hurt by the suggestion he was always working some angle or another.