I can tell you what's going on here, and it's not a good fix.
It is this issue: https://torstencurdt.com/tech/posts/modulo-of-negative-numbers/
In the first line, either the left or the right side must be negative, for the result, extra
to be negative.
If the right side were negative, the fix wouldn't work, as it would make the result more negative. So extra
must start off as negative, when it wasn't expected to be.
A real fix would be figuring out why extra
is negative before this code even starts and fixing that.
One-line if statements are bad, for the reason you state, and also because it's harder or sometimes impossible to set a break on the target of the if statement.
And that subexpression is computed twice. Likely the compiler will optimize that out, but assigning that subexpression to a variable will not just guarantee it's computed once, but document what's going on.
Shoddy work by the AI! Big surprise NOT.