#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 sum, fibo[2] = {1, 1}, i, next = fibo[0] + fibo[1];
  for (sum = 0, i = 0; next <= 4000000; i++) {
    if (!(next % 2)) {
      sum += next;
    }
    fibo[i % 2] = next;
    next = fibo[0] + fibo[1];
  }
  printf("The sum of the even fibonacci sequence terms whose value is below 4M "
         "is %i\n",
         sum);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3d0900,-0x18(%rbp)
jg     1197 <main+0x87>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    116b <main+0x5b>
mov    -0x18(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %ecx,-0x10(%rbp,%rax,4)
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <main+0x31>
mov    -0x8(%rbp),%esi
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movabs $0x100000001,%rax
mov    %rax,(%rsp)
xor    %eax,%eax
mov    $0x2,%ecx
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
test   $0x1,%cl
mov    $0x0,%edx
cmove  %ecx,%edx
add    %edx,%esi
mov    %eax,%edx
and    $0x1,%edx
mov    %ecx,(%rsp,%rdx,4)
mov    0x4(%rsp),%ecx
add    (%rsp),%ecx
add    $0x1,%eax
cmp    $0x3d0901,%ecx
jl     1130 <main+0x20>
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@__const.main.fibo = [2 x i32] [i32 1, i32 1]
@.str = [76 x i8] c"The sum of the even fibonacci sequence terms whose value is below 4M is %i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [2 x i32]* %3 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%10 = load i32, i32* %9
%11 = add nsw i32 %8, %10
store i32 %11, i32* %5
store i32 0, i32* %2
store i32 0, i32* %4
br label %12
12: ; preds = %34, %0
%13 = load i32, i32* %5
%14 = icmp sle i32 %13, 4000000
br i1 %14, label %15, label %37
15: ; preds = %12
%16 = load i32, i32* %5
%17 = srem i32 %16, 2
%18 = icmp ne i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i32, i32* %5
%21 = load i32, i32* %2
%22 = add nsw i32 %21, %20
store i32 %22, i32* %2
br label %23
23: ; preds = %19, %15
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = srem i32 %25, 2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 %27
store i32 %24, i32* %28
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%32 = load i32, i32* %31
%33 = add nsw i32 %30, %32
store i32 %33, i32* %5
br label %34
34: ; preds = %23
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %12
37: ; preds = %12
%38 = load i32, i32* %2
%39 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [76 x i8] c"The sum of the even fibonacci sequence terms whose value is below 4M is %i\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to [2 x i32]*
%3 = bitcast i64* %1 to i8*
store i64 4294967297, i64* %1
%4 = bitcast i64* %1 to i32*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
br label %6
6: ; preds = %0, %6
%7 = phi i32 [ %19, %6 ], [ 2, %0 ]
%8 = phi i32 [ %20, %6 ], [ 0, %0 ]
%9 = phi i32 [ %13, %6 ], [ 0, %0 ]
%10 = and i32 %7, 1
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i32 %7, i32 0
%13 = add nsw i32 %12, %9
%14 = and i32 %8, 1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 %15
store i32 %7, i32* %16
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = add nsw i32 %18, %17
%20 = add nuw nsw i32 %8, 1
%21 = icmp slt i32 %19, 4000001
br i1 %21, label %6, label %22
22: ; preds = %6
%23 = tail call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i32 %13)
ret i32 0
}