The former Islamic State group commander walked into the visitors' room of his Baghdad prison, without the usual yellow jumpsuit and shackles his fellow inmates wear. In slippers and a track suit, he greeted guards with a big smile, kissing them on the cheeks.

The scene testifies to the strange path of Abu Shakr, a 36-year-old who joined al-Qaida out of anger over treatment of Iraq's Sunnis and rose in the group as it transformed into the extremist juggernaut now called the Islamic State. Finally, he became an informant against the group after his capture.

Arrested in late 2013, he was presented a choice by Iraqi security officials: Help them against the extremists and in return he would get jailhouse perks. Now with relatively free rein inside the confines of a maximum security prison complex, Abu Shakr can play with his five children, enjoy supervised visits and buddy up with the guards.

Security officials say he has given them guidance on the extremists' tactics and helped them find, capture and interrogate suspected militants. In Salahuddin province, a key front line north of Baghdad, he helped the military win back key areas this week, including the town of Beiji, where troops secured Iraq's largest oil refinery.

He clearly has been willing to act against his former group in return for access to his family — and perhaps, implicitly, to prevent any government action against them. But his personal sentiment toward the militants is hard to gauge. Speaking to The Associated Press, he didn't express any remorse for his involvement in the group or directly denounce its actions or talk of any ideological conversion. He only said he never liked the group's ferocious targeting of Shiites and Christians. "It was not supposed to be this way," he said.

"We can't stop this thing, but we can limit it," he said of the Sunni militant group. "Daesh has nothing to lose," he added, using its Arabic acronym.

He spoke to the AP with various prison guards coming in and out of the room and with an intelligence official — with whom he works closely — present for part of the time. He spoke on condition he be identified only by his nom de guerre to protect his family. IS militants have issued numerous death threats against him.

Abu Shakr's drive to wage jihad was twofold: He said he was enraged by the U.S.-led occupation in Iraq that overthrew Saddam Hussein in 2003 and bitter toward the new Shiite-led government that Sunnis feel discriminates against them.

A graduate of Baghdad University, he joined al-Qaida's branch in Iraq in 2007. His reasoning, he said: "If we invaded America, what would be the reaction? The American people ... would resist, of course."

He said he climbed al-Qaida's ranks, starting as a foot soldier, moving from his native Diyala province to Baghdad, then to Salahuddin and finally stationed in the western city of Fallujah.

"When you get a new assignment with your company, sometimes you have to move," he said. "This was no different."

During that time, al-Qaida in Iraq's leaders — Abu Ayyub al-Masri and Abu Omar al-Baghdadi — were killed by a 2010 U.S. airstrike. They were replaced by the ambitious Abu Bakr al-Baghdadi, who would transform the group. In 2012, he began sending fighters into Syria, barging into that country's civil war. There, the group garnered battlefield prowess, resources and more fighters.

Abu Shakr was assigned to Fallujah in 2012. His task was to oversee security for al-Qaida's operations there. That meant in part organizing safehouses and movement between Iraq and Syria, but security officials said he was also responsible for Iraqi deaths from ordering militants in fighting with troops.

Fallujah fell completely to the militants in January this year, two months after Abu Shakr's arrest. But even at the time he deployed there, he said, much of the city was under the group's sway.

Their weapons were primitive at that time, he said. They could easily build explosives, he said, "but we had very few weapons. We had to rely on primitive car bombs, IEDs, as well as street fights with the army."

But they gradually drew support from Sunni tribes across Anbar province, resentful of the government. "The tribes feel the issue of oppression. For example, they didn't get a percentage of contracts ... or someone to represent them in the government," he said.

With resources from Syria, the group could provide fighters with a comfortable salary. Abu Shakr said he was getting the equivalent of $65 a month, plus an extra $45 for his wife and $20 per child.

Al-Baghdadi accelerated the group's transformation. In early 2013, the group renamed itself the Islamic State of Iraq and the Levant. It began seizing territory in Syria, leading to bloody frictions with Syrian rebels. Al-Qaida's central leader Ayman al-Zawahri began to criticize the network's Iraqi branch.

Under al-Baghdadi, "the operation changed," Abu Shakr said. Policies became "random," he said. Frictions with al-Qaida Central deepened. For example, "al-Zawahri objected to the policy of beheading. He told them, 'Don't get carried away with this publicity, it is not acceptable'," Abu Shakr said.

By the end of 2013, al-Qaida formally ejected al-Baghdadi's group. Al-Baghdadi burst forth only more powerful, first overrunning Fallujah and parts of Anbar. Then his fighters captured Iraq's second-largest city Mosul in the north in June. The group now controls around a third of Iraq and Syria.

By that point, however, Abu Shakr had been caught.

Iraqi intelligence forces had learned of his high-level role and began inquiring about him through informants around town. Haitham, an intelligence officer, said an intelligence team staked out his Fallujah home for 11 days, watching him and his family come and go. Haitham said he would even sneak into the house to listen to Abu Shakr's conversations. He spoke on condition he be identified only by his first name because he still works undercover.

Finally in late 2013, they arrested Abu Shakr. Intelligence officials worked to flip him. "Everyone has a weakness," Haitham said. "His biggest weakness is his family. ... We knew that if we were going to get him to cooperate with us, we needed to get his family too."

An Interior Ministry spokesman said Abu Shakr has not yet been sentenced for his collaboration with the radical group and the case is ongoing.

During the interview, Abu Shakr's 2-year-old daughter entered the visitor's room, her hair styled in a short bob. She greeted the guards with a bashful kiss on the cheek.

Abu Shakr says he considers the government his family's protector now. "I may be in prison for the rest of my life, and I'm sorry for that," he continued. "But I see now that it was my arrest that saved my family."