#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 is_even(int);
int sum_of_even_fibs_under(int upperbound) {
  int sum = 0;
  int currentFib = 1;
  int previousFib = 1;
  while (currentFib < upperbound) {
    bool isEven = is_even(currentFib);
    if (isEven) {
      sum += currentFib;
    }
    int oldCurrentFib = currentFib;
    currentFib += previousFib;
    previousFib = oldCurrentFib;
  }
  return sum;
}


x86 assembly (clang, -O0):
<sum_of_even_fibs_under>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1174 <sum_of_even_fibs_under+0x64>
mov    -0xc(%rbp),%edi
call   1030 <is_even@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     115a <sum_of_even_fibs_under+0x4a>
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1130 <sum_of_even_fibs_under+0x20>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_of_even_fibs_under>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r15d,%r15d
cmp    $0x2,%edi
jl     114c <sum_of_even_fibs_under+0x3c>
mov    %edi,%r14d
mov    $0x1,%eax
xor    %r15d,%r15d
mov    $0x1,%ebx
nop
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <is_even@plt>
test   %eax,%eax
cmovne %ebp,%eax
add    %eax,%r15d
add    %ebp,%ebx
mov    %ebx,%eax
cmp    %r14d,%ebx
mov    %ebp,%ebx
jl     1130 <sum_of_even_fibs_under+0x20>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sum_of_even_fibs_under(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 1, i32* %4
store i32 1, i32* %5
br label %8
8: ; preds = %21, %1
%9 = load i32, i32* %4
%10 = load i32, i32* %2
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %27
12: ; preds = %8
%13 = load i32, i32* %4
%14 = call i32 @is_even(i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* %4
%19 = load i32, i32* %3
%20 = add nsw i32 %19, %18
store i32 %20, i32* %3
br label %21
21: ; preds = %17, %12
%22 = load i32, i32* %4
store i32 %22, i32* %7
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = add nsw i32 %24, %23
store i32 %25, i32* %4
%26 = load i32, i32* %7
store i32 %26, i32* %5
br label %8
27: ; preds = %8
%28 = load i32, i32* %3
ret i32 %28
}

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