The counter is an optimization over calling ret.empty(). It was
suggested that the compiler would realize cnt is only 0 on the first
iteration, and not actually emit the check and conditional.
This optimization was actually not triggered at all, since we
incremented cnt at the beginning of the first iteration. Fix it by
incrementing at the end instead.
This was reported by Github user "Janus".
Fixes #25682. Note this does not change semantics. It only allows the optimization of moving instead of copying on first CScript element to actually be reachable.