#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 total = 0;
  int next, curr, prev;
  prev = curr = 1;
  while (curr <= 4000000) {
    next = prev + curr;
    if (curr % 2 == 0)
      total += curr;
    prev = curr;
    curr = next;
  }
  printf("%d\n", total);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x3d0900,-0x10(%rbp)
jg     1178 <main+0x68>
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1167 <main+0x57>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1134 <main+0x24>
mov    -0x8(%rbp),%esi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

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