The entire movie is a narration told from an unreliable narrator. You think you can trust the narrator, although it might be a little wonky, but then it's revealed that actually he's been hallucinating since Bob is on the drugs. Bob has to be our narrator because we only ever see his side of the story. But when he gets told that he himself is Bob and he is surprised by this, the audience becomes omnipotent since we see Bob as Fred. I remember being angry that Fred is shocked when he gets told and shouting "but you're Bob! You were just watching yourself!". I think here, with the help of Substance D, Fred would take the drug and the hallucinations were so strong that he became another person. Or it might have been the other way around. Maybe Bob became addicted and then created Fred as an alter ego, including all the memories of having an old family. However, since the government Bob works for knows he doesn't have a family, maybe they just picked Bob off the street, gave him some drugs and some memories so that they could control him. Bob goes through testing to make sure he's not on drugs, but looking it back on it, those might have been to ensure he was now addicted. He would have been useless otherwise.
This makes me think about whose story we're actually getting. We see Bob the most, see everything he does, but since he was not the one being targeted in the end and was actually being pushed away, perhaps the story wasn't supposed to be for him. Maybe this was Donna's story. Donna is revealed to be Frank, both seemingly inconsequential characters in Bob and Fred's life, but when they turn out to be one and the same, they cause Bob's downfall. Same thing applies to Barris. Barris was just his annoying friend, and since Bob didn't know he was Fred and vice versa, he didn't know that Barris was actually trying to turn against him. Yet both of these characters were just pawns in Donna's plan. She used Bob to get to Barris, and Barris to try to get to Bob. Although watching Bob had no affect on her plan, she told Fred that he was watching Bob, maybe to try to get him off Barris' back and not raise suspicion since Barris was the one that was feeding them information. At the end, someone talks to Dona about what happened and she tells them that it had to be for the greater good. The movie feels like it ends there. But then we get the scene with Bob (now Bruce) spraying pesticide and finding the blue flowers, Bruce doesn't get the closer he needs, the audience just gets confirmation that Donna's intuition about New Path being the proprietor of Substance D is correct.