When encountering a single-dash argument, parse arguments will read in the next argument (l. 308), if it exists. This overwrites the len_arg variable that used to hold the length of the single-dash argument (which can contain multiple letters). However, the next loop (l. 314ff) is over len_arg. Dependent on whether the following argument is shorter or longer than the single-dash argument, this will either miss out on single-letter arguments or parse beyond the end off key_arg, leading to unpredictable behaviour.
The obvious fix is to introduce a second length variable, and that indeed resolves the issue.