#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 *, long, long, long, long);
long computeFibonacciEven(long max) {
  long currentFibonacciValue = 1;
  long nextFibonacciValue = 2;
  long sumOfEvens = 2;
  long computedValue = 0;
  while (1) {
    computedValue = currentFibonacciValue + nextFibonacciValue;
    printf("CurrentFib=%lu : NextFib=%lu : EvenSum=%lu : ComputedValue=%lu\n",
           currentFibonacciValue, nextFibonacciValue, sumOfEvens,
           computedValue);
    if (computedValue > max)
      return sumOfEvens;
    else if (computedValue % 2 == 0) {
      sumOfEvens += computedValue;
    }
    currentFibonacciValue = nextFibonacciValue;
    nextFibonacciValue = computedValue;
  }
}


x86 assembly (clang, -O0):
<computeFibonacciEven>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1,-0x10(%rbp)
movq   $0x2,-0x18(%rbp)
movq   $0x2,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
jle    117c <computeFibonacciEven+0x6c>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret
mov    -0x28(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11a0 <computeFibonacciEven+0x90>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11a5 <computeFibonacciEven+0x95>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    113c <computeFibonacciEven+0x2c>

x86 assembly (clang, -O2):
<computeFibonacciEven>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
lea    0xedd(%rip),%rdi
mov    $0x2,%r13d
mov    $0x3,%r15d
mov    $0x1,%esi
mov    $0x2,%edx
mov    $0x2,%ecx
mov    $0x3,%r8d
call   1030 <printf@plt>
cmp    $0x3,%r14
jl     119e <computeFibonacciEven+0x8e>
mov    $0x2,%r13d
lea    0xea4(%rip),%r12
mov    $0x2,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rbx
test   $0x1,%bl
mov    $0x0,%eax
cmove  %r15,%rax
add    %rax,%r13
add    %rsi,%r15
mov    %r12,%rdi
mov    %rbx,%rdx
mov    %r13,%rcx
mov    %r15,%r8
call   1030 <printf@plt>
mov    %rbx,%rsi
cmp    %r14,%r15
jle    1170 <computeFibonacciEven+0x60>
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [64 x i8] c"CurrentFib=%lu : NextFib=%lu : EvenSum=%lu : ComputedValue=%lu\0A\00"
define i64 @computeFibonacciEven(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %2
store i64 1, i64* %3
store i64 2, i64* %4
store i64 2, i64* %5
store i64 0, i64* %6
br label %7
7: ; preds = %1, %30
%8 = load i64, i64* %3
%9 = load i64, i64* %4
%10 = add nsw i64 %8, %9
store i64 %10, i64* %6
%11 = load i64, i64* %3
%12 = load i64, i64* %4
%13 = load i64, i64* %5
%14 = load i64, i64* %6
%15 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i64 %11, i64 %12, i64 %13, i64 %14)
%16 = load i64, i64* %6
%17 = load i64, i64* %2
%18 = icmp sgt i64 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %7
%20 = load i64, i64* %5
ret i64 %20
21: ; preds = %7
%22 = load i64, i64* %6
%23 = srem i64 %22, 2
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i64, i64* %6
%27 = load i64, i64* %5
%28 = add nsw i64 %27, %26
store i64 %28, i64* %5
br label %29
29: ; preds = %25, %21
br label %30
30: ; preds = %29
%31 = load i64, i64* %4
store i64 %31, i64* %3
%32 = load i64, i64* %6
store i64 %32, i64* %4
br label %7
}

LLVM IR (-O2):
@.str = [64 x i8] c"CurrentFib=%lu : NextFib=%lu : EvenSum=%lu : ComputedValue=%lu\0A\00"
define i64 @computeFibonacciEven(i64 %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i64 1, i64 2, i64 2, i64 3)
%3 = icmp slt i64 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %6, %1
%5 = phi i64 [ 2, %1 ], [ %13, %6 ]
ret i64 %5
6: ; preds = %1, %6
%7 = phi i64 [ %14, %6 ], [ 3, %1 ]
%8 = phi i64 [ %13, %6 ], [ 2, %1 ]
%9 = phi i64 [ %7, %6 ], [ 2, %1 ]
%10 = and i64 %7, 1
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i64 %7, i64 0
%13 = add nsw i64 %12, %8
%14 = add nsw i64 %7, %9
%15 = tail call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i64 %9, i64 %7, i64 %13, i64 %14)
%16 = icmp sgt i64 %14, %0
br i1 %16, label %4, label %6
}