#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 main() {
  int i;
  int arr1[42];
  int arr2[42];
  for (i = 0; i < 42; i++) {
    arr1[i] = foo(i) + 29;
  }
  for (i = 0; i < 42; i++) {
    arr2[i] = arr1[i];
  }
  return arr2[22];
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x2a,-0x8(%rbp)
jge    1159 <main+0x49>
mov    -0x8(%rbp),%edi
call   1030 <foo@plt>
mov    %eax,%ecx
add    $0x1d,%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,-0xb0(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <main+0x19>
movl   $0x0,-0x8(%rbp)
cmpl   $0x2a,-0x8(%rbp)
jge    118e <main+0x7e>
movslq -0x8(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,-0x160(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1160 <main+0x50>
mov    -0x108(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xb0,%rsp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1030 <foo@plt>
add    $0x1d,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x2a,%rbx
jne    1120 <main+0x10>
mov    0x58(%rsp),%eax
add    $0xb0,%rsp
pop    %rbx
ret

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

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