That one store is clearly identified as going into p, not into q.
Therefore, it's quite reasonable to conclude that q has not been changed.
If we weren't allowed to conclude that, we would almost never be able to put stack variables into registers, and that would make even simple programs run a lot slower.
(The other point, which is another argument that it's the second optimization that should be considered incorrect, is that the program before the final optimization has a store to p[1], which is an out-of-bounds access into an array, which should be considered an error in all reasonable programming languages.)