#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 evenfib() {
  int sum = 0;
  int fibArr[4000000] = {0};
  for (int n = 0;; n++) {
    int temp = fib(n);
    if (temp > 4000000) {
      break;
    }
    if (temp % 2 == 0) {
      sum += temp;
    }
  }
  return sum;
}


x86 assembly (clang, -O0):
<evenfib>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf42420,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xf42410(%rbp),%rdi
xor    %esi,%esi
mov    $0xf42400,%edx
call   1030 <memset@plt>
movl   $0x0,-0xf42414(%rbp)
mov    -0xf42414(%rbp),%edi
call   1040 <fib@plt>
mov    %eax,-0xf42418(%rbp)
cmpl   $0x3d0900,-0xf42418(%rbp)
jle    1175 <evenfib+0x55>
jmp    11b1 <evenfib+0x91>
mov    -0xf42418(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1198 <evenfib+0x78>
mov    -0xf42418(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119d <evenfib+0x7d>
mov    -0xf42414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf42414(%rbp)
jmp    114f <evenfib+0x2f>
mov    -0x4(%rbp),%eax
add    $0xf42420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evenfib>:
push   %rbp
push   %r14
push   %rbx
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <fib@plt>
cmp    $0x3d0900,%eax
jg     1149 <evenfib+0x39>
xor    %r14d,%r14d
mov    $0x1,%ebp
xor    %ebx,%ebx
xchg   %ax,%ax
test   $0x1,%al
cmovne %r14d,%eax
add    %eax,%ebx
mov    %ebp,%edi
call   1030 <fib@plt>
add    $0x1,%ebp
cmp    $0x3d0901,%eax
jl     1130 <evenfib+0x20>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @evenfib() {
%1 = alloca i32
%2 = alloca [4000000 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [4000000 x i32]* %2 to i8*
store i32 0, i32* %3
br label %6
6: ; preds = %21, %0
%7 = load i32, i32* %3
%8 = call i32 @fib(i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 4000000
br i1 %10, label %11, label %12
11: ; preds = %6
br label %24
12: ; preds = %6
%13 = load i32, i32* %4
%14 = srem i32 %13, 2
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* %4
%18 = load i32, i32* %1
%19 = add nsw i32 %18, %17
store i32 %19, i32* %1
br label %20
20: ; preds = %16, %12
br label %21
21: ; preds = %20
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %6
24: ; preds = %11
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
define i32 @evenfib() {
%1 = tail call i32 @fib(i32 0)
%2 = icmp sgt i32 %1, 4000000
br i1 %2, label %14, label %3
3: ; preds = %0, %3
%4 = phi i32 [ %12, %3 ], [ %1, %0 ]
%5 = phi i32 [ %10, %3 ], [ 0, %0 ]
%6 = phi i32 [ %11, %3 ], [ 0, %0 ]
%7 = and i32 %4, 1
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i32 %4, i32 0
%10 = add nsw i32 %9, %5
%11 = add nuw nsw i32 %6, 1
%12 = tail call i32 @fib(i32 %11)
%13 = icmp sgt i32 %12, 4000000
br i1 %13, label %14, label %3
14: ; preds = %3, %0
%15 = phi i32 [ 0, %0 ], [ %10, %3 ]
ret i32 %15
}