The following code executes incorrectly, stoppin after about 800'000 iterations and performing the last `System.out.printf`. The exact number of iterations changes from run to run, probably depending on compilation timing.
But there is more: commenting out the lines after the loop and executing throws a "/ by zero" ArithmeticException on L.12.
In both cases, it should instead report `n=-2147483647, q=0, q1=1` and exit with code 22, as when executed in interpreter mode with -Xint.
Tried on macOS 14.5/AArch64 and Ubuntu 22.04.4/x64 with JDK 21 and 22. Executes correctly on JDK 17.
```
import static java.lang.Integer.*;
public class Buggy {
public static void main(String[] args) {
int N = -1;
int d = MIN_VALUE + 1;
long i = 0;
int n = 0;
for (; compareUnsigned(n, N) < 0; ++n, ++i) {
int q = divideUnsigned(n, d + 1);
int q1 = divideUnsigned(n, d);
if (q1 != q) {
System.out.printf("n=%d, q=%d, q1=%d%n", n, q, q1);
System.exit(22);
}
};
int q = divideUnsigned(n, d + 1);
int q1 = divideUnsigned(n, d);
if (q1 != q) {
System.out.printf("n=%d, q=%d, q1=%d", n, q, q1);
System.exit(22);
}
System.out.printf("counted=%d, expected=%d%n", i, (N & 0xFFFF_FFFFL) + 1);
}
}
```