#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 argc, char *argv[]) {
  int sum = 2;
  int i = 3;
  int a = 1;
  int b = 2;
  while (i < 4000000) {
    i = a + b;
    a = b;
    b = i;
    if (i % 2 == 0) {
      sum = sum + i;
    }
  }
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
movl   $0x3,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x2,-0x20(%rbp)
cmpl   $0x3d0900,-0x18(%rbp)
jge    1186 <main+0x76>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1181 <main+0x71>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1142 <main+0x32>
mov    -0x14(%rbp),%esi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x1,%eax
mov    $0x2,%ecx
mov    $0x2,%esi
nop
mov    %ecx,%edx
add    %ecx,%eax
test   $0x1,%al
mov    $0x0,%ecx
cmove  %eax,%ecx
add    %ecx,%esi
mov    %eax,%ecx
cmp    $0x3d0900,%eax
mov    %edx,%eax
jl     1120 <main+0x10>
push   %rax
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2, i32* %6
store i32 3, i32* %7
store i32 1, i32* %8
store i32 2, i32* %9
br label %10
10: ; preds = %26, %2
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 4000000
br i1 %12, label %13, label %27
13: ; preds = %10
%14 = load i32, i32* %8
%15 = load i32, i32* %9
%16 = add nsw i32 %14, %15
store i32 %16, i32* %7
%17 = load i32, i32* %9
store i32 %17, i32* %8
%18 = load i32, i32* %7
store i32 %18, i32* %9
%19 = load i32, i32* %7
%20 = srem i32 %19, 2
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %13
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = add nsw i32 %23, %24
store i32 %25, i32* %6
br label %26
26: ; preds = %22, %13
br label %10
27: ; preds = %10
%28 = load i32, i32* %6
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %3
%4 = phi i32 [ 2, %2 ], [ %7, %3 ]
%5 = phi i32 [ 1, %2 ], [ %4, %3 ]
%6 = phi i32 [ 2, %2 ], [ %11, %3 ]
%7 = add nsw i32 %4, %5
%8 = and i32 %7, 1
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i32 %7, i32 0
%11 = add nsw i32 %10, %6
%12 = icmp slt i32 %7, 4000000
br i1 %12, label %3, label %13
13: ; preds = %3
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
ret i32 0
}