int main(void) {
  int n = 0;
  int first = 1;
  int *p[101];
  if (0) {
  lab:;
  }
  int x[n % 100 + 1];
  if (first == 0) {
    if (&x[0] != p[n % 100 + 1]) {
      printf("ERROR: %d %p $p\n", &x[0], p[n % 100 + 1]);
      return (1);
    }
  } else {
    p[n % 100 + 1] = &x[0];
    first = n < 100;
  }
  x[0] = 1;
  x[n % 100] = 2;
  n++;
  if (n < 100000)
    goto lab;
  printf("OK\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x360,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
xor    %eax,%eax
test   $0x1,%al
jne    113f <main+0x2f>
jmp    1149 <main+0x39>
jmp    1144 <main+0x34>
jmp    1149 <main+0x39>
movslq -0x8(%rbp),%rcx
mov    %ecx,%eax
imul   $0x51eb851f,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x348(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x360(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x350(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1211 <main+0x101>
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    -0x360(%rbp),%rax
add    $0x1,%edx
movslq %edx,%rcx
cmp    -0x340(%rbp,%rcx,8),%rax
ff
je     120c <main+0xfc>
mov    -0x360(%rbp),%rsi
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq %edx,%rax
mov    -0x340(%rbp,%rax,8),%rdx
ff
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x354(%rbp)
jmp    12ad <main+0x19d>
jmp    1240 <main+0x130>
mov    -0x360(%rbp),%rcx
mov    -0x8(%rbp),%eax
mov    $0x64,%esi
cltd
idiv   %esi
add    $0x1,%edx
movslq %edx,%rax
mov    %rcx,-0x340(%rbp,%rax,8)
ff
cmpl   $0x64,-0x8(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
mov    -0x360(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    -0x360(%rbp),%rax
movslq %edx,%rcx
movl   $0x2,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x186a0,-0x8(%rbp)
jge    128e <main+0x17e>
movl   $0x2,-0x354(%rbp)
jmp    12ad <main+0x19d>
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x354(%rbp)
mov    -0x348(%rbp),%rax
mov    %rax,%rsp
mov    -0x354(%rbp),%eax
sub    $0x1,%eax
je     12d0 <main+0x1c0>
jmp    12cb <main+0x1bb>
jmp    1144 <main+0x34>
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x330,%rsp
mov    $0x1,%edi
xor    %ecx,%ecx
movabs $0x28f5c28f5c28f5c3,%r8
c2 f5 28
xor    %r9d,%r9d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rsp,%r14
mov    %rcx,%rax
shr    $0x2,%rax
mul    %r8
mov    %ecx,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x25,%rax
imul   $0x64,%eax,%eax
neg    %eax
add    %ecx,%eax
add    $0x1,%eax
lea    0xf(,%rax,4),%rbx
and    $0xfffffffffffffff0,%rbx
mov    %rsp,%rsi
sub    %rbx,%rsi
mov    %rsi,%rsp
test   %edi,%edi
je     11a0 <main+0x80>
mov    %rsi,-0x340(%rbp,%rax,8)
ff
xor    %edi,%edi
cmp    $0x64,%ecx
setb   %dil
jmp    11af <main+0x8f>
mov    -0x340(%rbp,%rax,8),%rax
ff
xor    %edi,%edi
cmp    %rax,%rsi
jne    11f5 <main+0xd5>
shr    $0x2,%rdx
imul   $0x190,%rdx,%rax
mov    %r9,%rdx
sub    %rax,%rdx
movl   $0x1,(%rsi)
movl   $0x2,(%rsi,%rdx,1)
cmp    $0x1869f,%ecx
je     11e5 <main+0xc5>
add    $0x1,%rcx
mov    %r14,%rsp
add    $0x4,%r9
jmp    1150 <main+0x30>
lea    0xe25(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    120b <main+0xeb>
lea    0xe04(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
mov    %r14,%rsp
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"ERROR: %d %p $p\0A\00"
@.str.1 = [4 x i8] c"OK\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [101 x i32*]
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 1, i32* %3
br i1 false, label %8, label %10
8: ; preds = %0
br label %9
9: ; preds = %61, %8
br label %10
10: ; preds = %9, %0
%11 = load i32, i32* %2
%12 = srem i32 %11, 100
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %5
%16 = alloca i32, i64 %14
store i64 %14, i64* %6
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %38
19: ; preds = %10
%20 = getelementptr inbounds i32, i32* %16, i64 0
%21 = load i32, i32* %2
%22 = srem i32 %21, 100
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [101 x i32*], [101 x i32*]* %4, i64 0, i64 %24
%26 = load i32*, i32** %25
%27 = icmp ne i32* %20, %26
br i1 %27, label %28, label %37
28: ; preds = %19
%29 = getelementptr inbounds i32, i32* %16, i64 0
%30 = load i32, i32* %2
%31 = srem i32 %30, 100
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [101 x i32*], [101 x i32*]* %4, i64 0, i64 %33
%35 = load i32*, i32** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %29, i32* %35)
store i32 1, i32* %1
store i32 1, i32* %7
br label %61
37: ; preds = %19
br label %48
38: ; preds = %10
%39 = getelementptr inbounds i32, i32* %16, i64 0
%40 = load i32, i32* %2
%41 = srem i32 %40, 100
%42 = add nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [101 x i32*], [101 x i32*]* %4, i64 0, i64 %43
store i32* %39, i32** %44
%45 = load i32, i32* %2
%46 = icmp slt i32 %45, 100
%47 = zext i1 %46 to i32
store i32 %47, i32* %3
br label %48
48: ; preds = %38, %37
%49 = getelementptr inbounds i32, i32* %16, i64 0
store i32 1, i32* %49
%50 = load i32, i32* %2
%51 = srem i32 %50, 100
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %16, i64 %52
store i32 2, i32* %53
%54 = load i32, i32* %2
%55 = add nsw i32 %54, 1
store i32 %55, i32* %2
%56 = load i32, i32* %2
%57 = icmp slt i32 %56, 100000
br i1 %57, label %58, label %59
58: ; preds = %48
store i32 2, i32* %7
br label %61
59: ; preds = %48
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
store i32 1, i32* %7
br label %61
61: ; preds = %59, %58, %28
%62 = load i8*, i8** %5
%63 = load i32, i32* %7
switch i32 %63, label %66 [
i32 1, label %64
i32 2, label %9
]
64: ; preds = %61
%65 = load i32, i32* %1
ret i32 %65
66: ; preds = %61
unreachable
}

LLVM IR (-O2):
@.str = [17 x i8] c"ERROR: %d %p $p\0A\00"
@str = [3 x i8] c"OK\00"
define i32 @main() {
%1 = alloca [101 x i32*]
%2 = bitcast [101 x i32*]* %1 to i8*
br label %3
3: ; preds = %28, %0
%4 = phi i32 [ 1, %0 ], [ %22, %28 ]
%5 = phi i32 [ 0, %0 ], [ %29, %28 ]
%6 = urem i32 %5, 100
%7 = add nuw nsw i32 %6, 1
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
%10 = alloca i32, i64 %8
%11 = icmp eq i32 %4, 0
%12 = getelementptr inbounds [101 x i32*], [101 x i32*]* %1, i64 0, i64 %8
br i1 %11, label %13, label %18
13: ; preds = %3
%14 = load i32*, i32** %12
%15 = icmp eq i32* %10, %14
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %10, i32* %14)
br label %30
18: ; preds = %3
store i32* %10, i32** %12
%19 = icmp ult i32 %5, 100
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %13, %18
%22 = phi i32 [ 0, %13 ], [ %20, %18 ]
store i32 1, i32* %10
%23 = zext i32 %6 to i64
%24 = getelementptr inbounds i32, i32* %10, i64 %23
store i32 2, i32* %24
%25 = icmp eq i32 %5, 99999
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %30
28: ; preds = %21
%29 = add nuw nsw i32 %5, 1
br label %3
30: ; preds = %16, %26
%31 = phi i32 [ 0, %26 ], [ 1, %16 ]
ret i32 %31
}