#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 /*<<< orphan*/ printf(char *, int);
int main() {
  int x = 1;
  int y = 0;
  int z;
  int counter = 0;
  int xarray[33];
  int sum = 0;
  while (x < 4000000) {
    xarray[counter] = x;
    z = x;
    x += y;
    y = z;
    counter++;
  }
  printf("value of x is: %d\n", x);
  printf("counter = %d\n", counter);
  int curvar = 0;
  int xvar;
  for (int i = 0; i < counter; i++) {
    xvar = xarray[i];
    if (xvar % 2 == 0) {
      sum += xvar;
      printf("Even number found: %d\n", xvar);
    }
  }
  printf("Sum of even numbers = %d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xa4(%rbp)
cmpl   $0x3d0900,-0x8(%rbp)
jge    117f <main+0x6f>
mov    -0x8(%rbp),%ecx
movslq -0x14(%rbp),%rax
mov    %ecx,-0xa0(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <main+0x31>
mov    -0x8(%rbp),%esi
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0xa8(%rbp)
movl   $0x0,-0xb0(%rbp)
mov    -0xb0(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1228 <main+0x118>
movslq -0xb0(%rbp),%rax
mov    -0xa0(%rbp,%rax,4),%eax
mov    %eax,-0xac(%rbp)
mov    -0xac(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    120f <main+0xff>
mov    -0xac(%rbp),%eax
add    -0xa4(%rbp),%eax
mov    %eax,-0xa4(%rbp)
mov    -0xac(%rbp),%esi
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
jmp    1214 <main+0x104>
mov    -0xb0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb0(%rbp)
jmp    11b1 <main+0xa1>
mov    -0xa4(%rbp),%esi
lea    0xe03(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
xor    %ebx,%ebx
mov    $0x1,%esi
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
mov    %esi,%ecx
mov    %esi,(%rsp,%rbx,4)
mov    %eax,%esi
add    %ecx,%esi
add    $0x1,%rbx
mov    %ecx,%eax
cmp    $0x3d0900,%esi
jl     1130 <main+0x20>
lea    0xeb2(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebx,%r15d
xor    %ebx,%ebx
lea    0xeb4(%rip),%r14
xor    %ebp,%ebp
jmp    1189 <main+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r15
je     119e <main+0x8e>
mov    (%rsp,%rbx,4),%esi
test   $0x1,%sil
jne    1180 <main+0x70>
add    %esi,%ebp
mov    %r14,%rdi
call   1030 <printf@plt>
jmp    1180 <main+0x70>
lea    0xe93(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"value of x is: %d\0A\00"
@.str.1 = [14 x i8] c"counter = %d\0A\00"
@.str.2 = [23 x i8] c"Even number found: %d\0A\00"
@.str.3 = [26 x i8] c"Sum of even numbers = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [33 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
store i32 0, i32* %3
store i32 0, i32* %5
store i32 0, i32* %7
br label %11
11: ; preds = %14, %0
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 4000000
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = load i32, i32* %2
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [33 x i32], [33 x i32]* %6, i64 0, i64 %17
store i32 %15, i32* %18
%19 = load i32, i32* %2
store i32 %19, i32* %4
%20 = load i32, i32* %3
%21 = load i32, i32* %2
%22 = add nsw i32 %21, %20
store i32 %22, i32* %2
%23 = load i32, i32* %4
store i32 %23, i32* %3
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %11
26: ; preds = %11
%27 = load i32, i32* %2
%28 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %5
%30 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %29)
store i32 0, i32* %8
store i32 0, i32* %10
br label %31
31: ; preds = %50, %26
%32 = load i32, i32* %10
%33 = load i32, i32* %5
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %53
35: ; preds = %31
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [33 x i32], [33 x i32]* %6, i64 0, i64 %37
%39 = load i32, i32* %38
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = srem i32 %40, 2
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %35
%44 = load i32, i32* %9
%45 = load i32, i32* %7
%46 = add nsw i32 %45, %44
store i32 %46, i32* %7
%47 = load i32, i32* %9
%48 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %43, %35
br label %50
50: ; preds = %49
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %31
53: ; preds = %31
%54 = load i32, i32* %7
%55 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %54)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"value of x is: %d\0A\00"
@.str.1 = [14 x i8] c"counter = %d\0A\00"
@.str.2 = [23 x i8] c"Even number found: %d\0A\00"
@.str.3 = [26 x i8] c"Sum of even numbers = %d\0A\00"
define i32 @main() {
%1 = alloca [33 x i32]
%2 = bitcast [33 x i32]* %1 to i8*
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %9, %3 ]
%5 = phi i32 [ 1, %0 ], [ %8, %3 ]
%6 = phi i32 [ 0, %0 ], [ %5, %3 ]
%7 = getelementptr inbounds [33 x i32], [33 x i32]* %1, i64 0, i64 %4
store i32 %5, i32* %7
%8 = add nsw i32 %5, %6
%9 = add nuw i64 %4, 1
%10 = icmp slt i32 %8, 4000000
br i1 %10, label %3, label %11
11: ; preds = %3
%12 = trunc i64 %9 to i32
%13 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %8)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%15 = add i64 %4, 1
%16 = and i64 %15, 4294967295
br label %19
17: ; preds = %29
%18 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %30)
ret i32 0
19: ; preds = %11, %29
%20 = phi i64 [ 0, %11 ], [ %31, %29 ]
%21 = phi i32 [ 0, %11 ], [ %30, %29 ]
%22 = getelementptr inbounds [33 x i32], [33 x i32]* %1, i64 0, i64 %20
%23 = load i32, i32* %22
%24 = and i32 %23, 1
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = add nsw i32 %23, %21
%28 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %29
29: ; preds = %19, %26
%30 = phi i32 [ %27, %26 ], [ %21, %19 ]
%31 = add nuw nsw i64 %20, 1
%32 = icmp eq i64 %31, %16
br i1 %32, label %17, label %19
}