#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 *, long);
int main() {
  long int sum = 0;
  int i, first = 1, second = 2, next = 0;
  for (i = 1; next <= 4000000; i++) {
    next = first + second;
    if (next % 2 == 0) {
      sum += next;
    }
    first = second;
    second = next;
  }
  sum += 2;
  printf("%ld\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x3d0900,-0x20(%rbp)
jg     1193 <main+0x83>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1179 <main+0x69>
movslq -0x20(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <main+0x33>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe56(%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
xor    %esi,%esi
nopl   0x0(%rax)
mov    %ecx,%edx
add    %ecx,%eax
test   $0x1,%al
mov    $0x0,%ecx
cmove  %eax,%ecx
movslq %ecx,%rcx
add    %rcx,%rsi
mov    %eax,%ecx
cmp    $0x3d0901,%eax
mov    %edx,%eax
jl     1120 <main+0x10>
push   %rax
add    $0x2,%rsi
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

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