#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 *, double);
int main(void) {
  long n, nminus1, current;
  double total;
  n = 1;
  nminus1 = 0;
  current = 1;
  total = 0;
  while (current <= 10000) {
    current = n + nminus1;
    printf("CURRENT FIBONACCI NUMBER IS %ld\n", current);
    if ((current % 2) == 0) {
      printf("Adding %ld to the total\n", current);
      total += current;
    }
    nminus1 = n;
    n = current;
  }
  printf("Total of even fibonacci numbers = %ld\n", total);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x1,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpq   $0x2710,-0x20(%rbp)
jg     11ba <main+0xaa>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm0
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11a5 <main+0x95>
cvtsi2sdq -0x20(%rbp),%xmm0
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
cvtsi2sdq -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    113f <main+0x2f>
movsd  -0x28(%rbp),%xmm0
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%ebx
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %r12d,%r12d
lea    0xecc(%rip),%r15
lea    0xee6(%rip),%r14
jmp    1149 <main+0x39>
nopl   (%rax)
cmp    $0x2711,%rbx
jge    1192 <main+0x82>
mov    %r12,%rax
mov    %rbx,%r12
mov    %rax,%rbx
add    %r12,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
mov    %r15,%rdi
movsd  %xmm0,0x10(%rsp)
call   1030 <printf@plt>
test   $0x1,%bl
jne    1140 <main+0x30>
mov    %r14,%rdi
movsd  0x10(%rsp),%xmm0
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    1140 <main+0x30>
lea    0xea1(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"CURRENT FIBONACCI NUMBER IS %ld\0A\00"
@.str.1 = [25 x i8] c"Adding %ld to the total\0A\00"
@.str.2 = [39 x i8] c"Total of even fibonacci numbers = %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca double
store i32 0, i32* %1
store i64 1, i64* %2
store i64 0, i64* %3
store i64 1, i64* %4
store double 0.000000e+00, double* %5
br label %6
6: ; preds = %27, %0
%7 = load i64, i64* %4
%8 = icmp sle i64 %7, 10000
br i1 %8, label %9, label %30
9: ; preds = %6
%10 = load i64, i64* %2
%11 = load i64, i64* %3
%12 = add nsw i64 %10, %11
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = sitofp i64 %13 to double
%15 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), double %14)
%16 = load i64, i64* %4
%17 = srem i64 %16, 2
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %9
%20 = load i64, i64* %4
%21 = sitofp i64 %20 to double
%22 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), double %21)
%23 = load i64, i64* %4
%24 = sitofp i64 %23 to double
%25 = load double, double* %5
%26 = fadd double %25, %24
store double %26, double* %5
br label %27
27: ; preds = %19, %9
%28 = load i64, i64* %2
store i64 %28, i64* %3
%29 = load i64, i64* %4
store i64 %29, i64* %2
br label %6
30: ; preds = %6
%31 = load double, double* %5
%32 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), double %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"CURRENT FIBONACCI NUMBER IS %ld\0A\00"
@.str.1 = [25 x i8] c"Adding %ld to the total\0A\00"
@.str.2 = [39 x i8] c"Total of even fibonacci numbers = %ld\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %13
%2 = phi double [ 0.000000e+00, %0 ], [ %14, %13 ]
%3 = phi i64 [ 1, %0 ], [ %5, %13 ]
%4 = phi i64 [ 0, %0 ], [ %3, %13 ]
%5 = add nsw i64 %3, %4
%6 = sitofp i64 %5 to double
%7 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), double %6)
%8 = and i64 %5, 1
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), double %6)
%12 = fadd double %2, %6
br label %13
13: ; preds = %10, %1
%14 = phi double [ %12, %10 ], [ %2, %1 ]
%15 = icmp slt i64 %5, 10001
br i1 %15, label %1, label %16
16: ; preds = %13
%17 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), double %14)
ret i32 0
}