The obvious answer in both cases is to not torture.
The deontological argument requires accordance with what you would have made into universal law. This means that the general principle must be obeyed without regard to consequence. Obviously torture is forbidden.
The utilitarian argument is the only possible way of justifying torture from an ethical standpoint. Still, even then, it fails to do so.
Torture is neither reliable nor effective at gathering information. The person being tortured simply wants to make the torture stop. There is a neurological explanation for this fact.
This makes it so the information gathered from torture lacks utility, and therefore cannot ethically justify torture.
Ticking time bomb or the beating do not provide ethical arguments for torture. They provide emotional arguments for torture.
Lastly, of the 595 people imprisoned at Guantanamo:
"In interviews, dozens of high-level military, intelligence and law-enforcement officials in the United States, Europe and the Middle East said that contrary to the repeated assertions of senior administration officials, none of the detainees at the United States Naval Base at Guantánamo Bay ranked as leaders or senior operatives of Al Qaeda.
They said only a relative handful -- some put the number at about a dozen, others more than two dozen -- were sworn Qaeda members or other militants able to elucidate the organization's inner workings."
https://mobile.nytimes.com/2004/06/...e-value-of-guantanamo-detainees.html?referer=
Do you really think we should torture some, what, 571 potentially innocent people?