#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 */
long fibonacci(long);
int /*<<< orphan*/ printf(char *, long);
int main(int argc, char *argv[]) {
  long int i;
  long int sum = 0;
  for (i = 0; fibonacci(i) < 4000000; i++) {
    printf("fibonacci(i) is: %lu\n", fibonacci(i));
    if ((fibonacci(i) % 2) == 0)
      sum += fibonacci(i);
  }
  printf("The sum of the even fibonacci numbers below 4000000 is: %lu\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fibonacci@plt>
cmp    $0x3d0900,%rax
jge    11b7 <main+0x97>
mov    -0x18(%rbp),%rdi
call   1040 <fibonacci@plt>
mov    %rax,%rsi
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fibonacci@plt>
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11a1 <main+0x81>
mov    -0x18(%rbp),%rdi
call   1040 <fibonacci@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11a6 <main+0x86>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1146 <main+0x26>
mov    -0x20(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %r15d,%r15d
xor    %edi,%edi
call   1040 <fibonacci@plt>
cmp    $0x3d08ff,%rax
jg     1190 <main+0x70>
xor    %r15d,%r15d
lea    0xebf(%rip),%r14
xor    %ebx,%ebx
jmp    1164 <main+0x44>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <fibonacci@plt>
cmp    $0x3d0900,%rax
jge    1190 <main+0x70>
mov    %rbx,%rdi
call   1040 <fibonacci@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <fibonacci@plt>
test   $0x1,%al
jne    1150 <main+0x30>
mov    %rbx,%rdi
call   1040 <fibonacci@plt>
add    %rax,%r15
jmp    1150 <main+0x30>
lea    0xe7f(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [22 x i8] c"fibonacci(i) is: %lu\0A\00"
@.str.1 = [61 x i8] c"The sum of the even fibonacci numbers below 4000000 is: %lu\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @fibonacci(i64 0)
%4 = icmp slt i64 %3, 4000000
br i1 %4, label %5, label %21
5: ; preds = %2, %16
%6 = phi i64 [ %17, %16 ], [ 0, %2 ]
%7 = phi i64 [ %18, %16 ], [ 0, %2 ]
%8 = tail call i64 @fibonacci(i64 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %8)
%10 = tail call i64 @fibonacci(i64 %7)
%11 = and i64 %10, 1
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %5
%14 = tail call i64 @fibonacci(i64 %7)
%15 = add nsw i64 %14, %6
br label %16
16: ; preds = %5, %13
%17 = phi i64 [ %15, %13 ], [ %6, %5 ]
%18 = add nuw nsw i64 %7, 1
%19 = tail call i64 @fibonacci(i64 %18)
%20 = icmp slt i64 %19, 4000000
br i1 %20, label %5, label %21
21: ; preds = %16, %2
%22 = phi i64 [ 0, %2 ], [ %17, %16 ]
%23 = tail call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i64 %22)
ret i32 0
}