#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 fib(int);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  int sum = 0;
  int n = 1;
  while (fib(n) <= 4000000) {
    if (fib(n) % 2 == 0) {
      sum += fib(n);
    }
    n += 1;
  }
  printf("Total: %d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <fib@plt>
cmp    $0x3d0900,%eax
jg     1185 <main+0x65>
mov    -0xc(%rbp),%edi
call   1040 <fib@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1177 <main+0x57>
mov    -0xc(%rbp),%edi
call   1040 <fib@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113d <main+0x1d>
mov    -0x8(%rbp),%esi
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebx
mov    $0x1,%edi
call   1040 <fib@plt>
xor    %ebp,%ebp
cmp    $0x3d0900,%eax
jg     1167 <main+0x47>
xor    %ebp,%ebp
jmp    1151 <main+0x31>
nop
add    $0x1,%ebx
mov    %ebx,%edi
call   1040 <fib@plt>
cmp    $0x3d0901,%eax
jge    1167 <main+0x47>
mov    %ebx,%edi
call   1040 <fib@plt>
test   $0x1,%al
jne    1140 <main+0x20>
mov    %ebx,%edi
call   1040 <fib@plt>
add    %eax,%ebp
jmp    1140 <main+0x20>
lea    0xe92(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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