I once watched a movie on AMC that had a plot like this: A man is viewing a trial, and he and his friend get into a conversation about how the prosecuting attorney was so good at his job that he could successfully prosecute an innocent defendant. The friend has an idea: this man is to be framed for a crime he did not commit. They agree that the friend will later reveal that the man is entirely innocent of the crime. An opportunity arises: a prostitute is found murdered. The man is framed. Then, a plot twist: the friend dies, and so the man distresses about being acquitted. After that, it does (somehow) come to light that the whole thing was a setup. Then, at the very end, there is the mother of all plot twists: it is revealed that the man did kill the woman after all, and this is found out by the fact that he knew the name of the woman, which was not mentioned during the trial.
I have tried googling this before, but I cannot find it. I will send a five dollar amazon gift card to anyone who can tell me the name of this movie.