#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) {
  int limit = 4000000;
  int fib1 = 1;
  int fib2 = 2;
  int nextFib = 0;
  double evenFibs = 0;
  while (fib1 < limit && fib2 < limit) {
    nextFib = fib1 + fib2;
    if (nextFib % 2 == 0) {
      evenFibs += nextFib;
    }
    fib1 = fib2;
    fib2 = nextFib;
  }
  printf("result: %f", evenFibs);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3d0900,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8(%rbp),%ecx
mov    %al,-0x21(%rbp)
jge    1160 <main+0x50>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1170 <main+0x60>
jmp    11ad <main+0x9d>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    119c <main+0x8c>
cvtsi2sdl -0x14(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1143 <main+0x33>
movsd  -0x20(%rbp),%xmm0
lea    0xe47(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x1,%eax
mov    $0x2,%ecx
xorpd  %xmm0,%xmm0
movsd  0xed9(%rip),%xmm1
jmp    1140 <main+0x30>
nopl   0x0(%rax)
movapd %xmm1,%xmm2
addsd  %xmm2,%xmm0
cmp    $0x3d0900,%ecx
jge    1156 <main+0x46>
mov    %eax,%edx
mov    %ecx,%eax
mov    %edx,%ecx
add    %eax,%ecx
test   $0x1,%cl
jne    1130 <main+0x20>
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
jmp    1134 <main+0x24>
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"result: %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store i32 0, i32* %1
store i32 4000000, i32* %2
store i32 1, i32* %3
store i32 2, i32* %4
store i32 0, i32* %5
store double 0.000000e+00, double* %6
br label %7
7: ; preds = %29, %0
%8 = load i32, i32* %3
%9 = load i32, i32* %2
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i32, i32* %4
%13 = load i32, i32* %2
%14 = icmp slt i32 %12, %13
br label %15
15: ; preds = %11, %7
%16 = phi i1 [ false, %7 ], [ %14, %11 ]
br i1 %16, label %17, label %32
17: ; preds = %15
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = add nsw i32 %18, %19
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = srem i32 %21, 2
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = load i32, i32* %5
%26 = sitofp i32 %25 to double
%27 = load double, double* %6
%28 = fadd double %27, %26
store double %28, double* %6
br label %29
29: ; preds = %24, %17
%30 = load i32, i32* %4
store i32 %30, i32* %3
%31 = load i32, i32* %5
store i32 %31, i32* %4
br label %7
32: ; preds = %15
%33 = load double, double* %6
%34 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"result: %f\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi double [ 0.000000e+00, %0 ], [ %10, %1 ]
%3 = phi i32 [ 2, %0 ], [ %5, %1 ]
%4 = phi i32 [ 1, %0 ], [ %3, %1 ]
%5 = add nsw i32 %3, %4
%6 = and i32 %5, 1
%7 = icmp eq i32 %6, 0
%8 = sitofp i32 %5 to double
%9 = select i1 %7, double %8, double -0.000000e+00
%10 = fadd double %2, %9
%11 = icmp slt i32 %5, 4000000
br i1 %11, label %1, label %12
12: ; preds = %1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double %10)
ret i32 0
}