everything after his visit to Rekall Inc is a fake memory; he was never a spy and never went to Mars. One clue is that as they prepare to give him his (official) fake memories, the technician looks at the cassette and says something like, "Hmm, Blue Sky on Mars, that's a new one", and the film enRAB with a blue sky on Mars. Another clue is how the girl exactly matches the specifications Arnie gave (despite him contradicting himself).
The scene in which Arnie is offered a "wake-up" pill has several interpretations. It could be a trap by the bad guys. It might have been real, with Arnie truly having a psychotic mental excursion in the real world and needing to be woken up. Or it could be just another part of the fake memory implanted by Rekall.