#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 first = 1;
  int second = 1;
  int term;
  int sum = 0;
  while (1) {
    term = first + second;
    if (term > 4000000) {
      break;
    }
    sum += (term % 2 == 0) ? term : 0;
    first = second;
    second = term;
  }
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x3d0900,-0x10(%rbp)
jle    114f <main+0x3f>
jmp    1192 <main+0x82>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    116e <main+0x5e>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1178 <main+0x68>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    1178 <main+0x68>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1134 <main+0x24>
mov    -0x14(%rbp),%esi
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x1,%eax
xor    %esi,%esi
mov    $0x2,%ecx
nopl   0x0(%rax)
mov    %ecx,%edx
test   $0x1,%dl
mov    $0x0,%ecx
cmove  %edx,%ecx
add    %ecx,%esi
add    %edx,%eax
mov    %eax,%ecx
cmp    $0x3d0901,%eax
mov    %edx,%eax
jl     1120 <main+0x10>
push   %rax
lea    0xebc(%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() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
store i32 1, i32* %3
store i32 0, i32* %5
br label %6
6: ; preds = %0, %20
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = add nsw i32 %7, %8
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 4000000
br i1 %11, label %12, label %13
12: ; preds = %6
br label %26
13: ; preds = %6
%14 = load i32, i32* %4
%15 = srem i32 %14, 2
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = load i32, i32* %4
br label %20
19: ; preds = %13
br label %20
20: ; preds = %19, %17
%21 = phi i32 [ %18, %17 ], [ 0, %19 ]
%22 = load i32, i32* %5
%23 = add nsw i32 %22, %21
store i32 %23, i32* %5
%24 = load i32, i32* %3
store i32 %24, i32* %2
%25 = load i32, i32* %4
store i32 %25, i32* %3
br label %6
26: ; preds = %12
%27 = load i32, i32* %5
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %27)
ret i32 0
}

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