#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int foo(int, int *, int);
int main() {
  int i, b[100];
  for (i = 0; i < 100; i++) {
    b[i] = foo(i, b, i);
  }
  for (i = 0; i < 100; i) {
    if (b[i] != i) {
    ERROR:
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jge    1160 <main+0x50>
mov    -0x8(%rbp),%edi
lea    -0x1a0(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <foo@plt>
mov    %eax,%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <main+0x19>
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jge    11a0 <main+0x90>
movslq -0x8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
cmp    -0x8(%rbp),%eax
je     1196 <main+0x86>
jmp    118a <main+0x7a>
movl   $0x1,-0x4(%rbp)
jmp    11a7 <main+0x97>
jmp    119b <main+0x8b>
jmp    1167 <main+0x57>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x198,%rsp
xor    %ebx,%ebx
mov    %rsp,%r14
nop
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <foo@plt>
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1120 <main+0x10>
cmpl   $0x0,(%rsp)
je     1150 <main+0x40>
mov    $0x1,%eax
add    $0x198,%rsp
pop    %rbx
pop    %r14
ret
nop
jmp    1150 <main+0x40>

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i32]
store i32 0, i32* %1
store i32 0, i32* %2
br label %4
4: ; preds = %15, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 100
br i1 %6, label %7, label %18
7: ; preds = %4
%8 = load i32, i32* %2
%9 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%10 = load i32, i32* %2
%11 = call i32 @foo(i32 %8, i32* %9, i32 %10)
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %13
store i32 %11, i32* %14
br label %15
15: ; preds = %7
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %4
18: ; preds = %4
store i32 0, i32* %2
br label %19
19: ; preds = %32, %18
%20 = load i32, i32* %2
%21 = icmp slt i32 %20, 100
br i1 %21, label %22, label %34
22: ; preds = %19
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = load i32, i32* %2
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %22
br label %30
30: ; preds = %29
store i32 1, i32* %1
br label %35
31: ; preds = %22
br label %32
32: ; preds = %31
%33 = load i32, i32* %2
br label %19
34: ; preds = %19
store i32 0, i32* %1
br label %35
35: ; preds = %34, %30
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [100 x i32]
%2 = bitcast [100 x i32]* %1 to i8*
%3 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
br label %7
4: ; preds = %7
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 0
br i1 %6, label %14, label %15
7: ; preds = %0, %7
%8 = phi i64 [ 0, %0 ], [ %12, %7 ]
%9 = trunc i64 %8 to i32
%10 = call i32 @foo(i32 %9, i32* %3, i32 %9)
%11 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %8
store i32 %10, i32* %11
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, 100
br i1 %13, label %4, label %7
14: ; preds = %4, %14
br label %14
15: ; preds = %4
ret i32 1
}