#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 */
scalar_t__ isEven(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int current = 1, fibonacci = 0, previous = 0, sum = 0;
  printf("\n\nThe sum of the even numbers of the Fibonacci sequence, from 0-%d "
         "is: ",
         4000000);
  while (fibonacci <= 4000000) {
    fibonacci = previous + current;
    previous = current;
    current = fibonacci;
    if (isEven(fibonacci) && fibonacci <= 4000000)
      sum += fibonacci;
  }
  printf("%d\n\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   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x3d0900,%esi
call   1030 <printf@plt>
cmpl   $0x3d0900,-0xc(%rbp)
jg     11ab <main+0x8b>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <isEven@plt>
cmp    $0x0,%rax
je     11a6 <main+0x86>
cmpl   $0x3d0900,-0xc(%rbp)
jg     11a6 <main+0x86>
mov    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    115c <main+0x3c>
mov    -0x14(%rbp),%esi
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%rdi
mov    $0x3d0900,%esi
call   1030 <printf@plt>
mov    $0x1,%r15d
xor    %r14d,%r14d
xor    %ebx,%ebx
xor    %eax,%eax
jmp    116a <main+0x4a>
nopw   0x0(%rax,%rax,1)
cmp    $0x3d0901,%ebp
cmovge %r14d,%ecx
add    %ecx,%ebx
mov    %r15d,%eax
mov    %ebp,%r15d
cmp    $0x3d0901,%ebp
jge    1181 <main+0x61>
mov    %eax,%ebp
add    %r15d,%ebp
mov    %ebp,%edi
call   1040 <isEven@plt>
mov    %ebp,%ecx
test   %rax,%rax
jne    1150 <main+0x30>
xor    %ecx,%ecx
jmp    1150 <main+0x30>
lea    0xec0(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [72 x i8] c"\0A\0AThe sum of the even numbers of the Fibonacci sequence, from 0-%d is: \00"
@.str.1 = [5 x i8] c"%d\0A\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 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i32 4000000)
br label %7
7: ; preds = %26, %0
%8 = load i32, i32* %3
%9 = icmp sle i32 %8, 4000000
br i1 %9, label %10, label %27
10: ; preds = %7
%11 = load i32, i32* %4
%12 = load i32, i32* %2
%13 = add nsw i32 %11, %12
store i32 %13, i32* %3
%14 = load i32, i32* %2
store i32 %14, i32* %4
%15 = load i32, i32* %3
store i32 %15, i32* %2
%16 = load i32, i32* %3
%17 = call i64 @isEven(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %10
%20 = load i32, i32* %3
%21 = icmp sle i32 %20, 4000000
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %3
%24 = load i32, i32* %5
%25 = add nsw i32 %24, %23
store i32 %25, i32* %5
br label %26
26: ; preds = %22, %19, %10
br label %7
27: ; preds = %7
%28 = load i32, i32* %5
%29 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [72 x i8] c"\0A\0AThe sum of the even numbers of the Fibonacci sequence, from 0-%d is: \00"
@.str.1 = [5 x i8] c"%d\0A\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i32 4000000)
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %12, %2 ]
%4 = phi i32 [ 0, %0 ], [ %5, %2 ]
%5 = phi i32 [ 1, %0 ], [ %6, %2 ]
%6 = add nsw i32 %4, %5
%7 = tail call i64 @isEven(i32 %6)
%8 = icmp ne i64 %7, 0
%9 = icmp slt i32 %6, 4000001
%10 = and i1 %9, %8
%11 = select i1 %10, i32 %6, i32 0
%12 = add nsw i32 %11, %3
br i1 %9, label %2, label %13
13: ; preds = %2
%14 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %12)
ret i32 0
}