One goal of the ad-hoc command line argument parsing in clang-scan-deps is to get the last output path value.
Currently, the algorithm walks the arguments in reverse and identifies potention output path arguments.
Interestingly, in clang-cl mode, the output path can be specified in multiple ways. For example /o /opt/build and /o/opt/build are equivalent. The parser currently fails to correctly parse the former. It considers the value (/opt/build/) to be a shorthand for /o pt/build. It doesn't look at the preceding /o.
This patch simplifies the algorithm by doing forward iteration and fixes the bug by correctly handling separate /o argument.
A test for boundary (I+1 != FlagsEnd) will be needed here, to avoid an infinite loop in the case -Xclang is the last arg.
I think it would be worth doing continue here, both because Arg's value is -Xclang, which won't be used in this iteration, and also it is a bit confusing as Arg has now represents *(I-1) instead of *I