@nicolas-grekas could you use longer variable names for all these local variables, based on their meaning ? This will make the code much more readable.
We are not in minified JS code where each byte saved in the file size is a win. Readability is key (especially for such tricky logic)