#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 */
unsigned long long fib_recur(unsigned long long);
unsigned long long recursive(unsigned long long max) {
  unsigned long long i = 0;
  unsigned long long n = 0;
  unsigned long long sum = 0;
  for (i = 0; n < max; i++) {
    n = fib_recur(i);
    if (n % 2 == 0) {
      sum += n;
    }
  }
  return sum;
}


x86 assembly (clang, -O0):
<recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    118b <recursive+0x7b>
mov    -0x10(%rbp),%rdi
call   1030 <fib_recur@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    1175 <recursive+0x65>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    117a <recursive+0x6a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113c <recursive+0x2c>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursive>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1151 <recursive+0x41>
mov    %rdi,%r14
xor    %r15d,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <fib_recur@plt>
test   $0x1,%al
mov    $0x0,%ecx
cmove  %rax,%rcx
add    %rcx,%r15
add    $0x1,%rbx
cmp    %r14,%rax
jb     1130 <recursive+0x20>
jmp    1154 <recursive+0x44>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @recursive(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %2
store i64 0, i64* %3
store i64 0, i64* %4
store i64 0, i64* %5
store i64 0, i64* %3
br label %6
6: ; preds = %21, %1
%7 = load i64, i64* %4
%8 = load i64, i64* %2
%9 = icmp ult i64 %7, %8
br i1 %9, label %10, label %24
10: ; preds = %6
%11 = load i64, i64* %3
%12 = call i64 @fib_recur(i64 %11)
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = urem i64 %13, 2
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i64, i64* %4
%18 = load i64, i64* %5
%19 = add i64 %18, %17
store i64 %19, i64* %5
br label %20
20: ; preds = %16, %10
br label %21
21: ; preds = %20
%22 = load i64, i64* %3
%23 = add i64 %22, 1
store i64 %23, i64* %3
br label %6
24: ; preds = %6
%25 = load i64, i64* %5
ret i64 %25
}

LLVM IR (-O2):
define i64 @recursive(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %13, label %3
3: ; preds = %1, %3
%4 = phi i64 [ %10, %3 ], [ 0, %1 ]
%5 = phi i64 [ %11, %3 ], [ 0, %1 ]
%6 = tail call i64 @fib_recur(i64 %5)
%7 = and i64 %6, 1
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i64 %6, i64 0
%10 = add i64 %9, %4
%11 = add i64 %5, 1
%12 = icmp ult i64 %6, %0
br i1 %12, label %3, label %13
13: ; preds = %3, %1
%14 = phi i64 [ 0, %1 ], [ %10, %3 ]
ret i64 %14
}