#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
float CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, int, float);
int main() {
  clock_t start = clock();
  register int fibMinus2 = 1;
  register int fibMinus1 = 1;
  register int fib = 2;
  register int i = 2;
  register int sum = 0;
  const int limit = 4000000;
  while (fib < limit) {
    if (i++ % 2 == 0)
      sum += fib;
    fibMinus2 = fibMinus1;
    fibMinus1 = fib;
    fib += fibMinus2;
  }
  clock_t dur = clock() - start;
  printf("Sum %d in %fms", sum, ((float)dur) / CLOCKS_PER_SEC);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
movl   $0x2,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x3d0900,-0x28(%rbp)
cmpl   $0x3d0900,-0x1c(%rbp)
jge    11b0 <main+0x90>
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x20(%rbp)
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1196 <main+0x76>
mov    -0x1c(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1164 <main+0x44>
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%esi
cvtsi2ssq -0x30(%rbp),%xmm0
mov    0x2e19(%rip),%rax
divss  (%rax),%xmm0
lea    0xe26(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
mov    $0x2,%ecx
mov    $0x1,%eax
mov    $0x2,%edx
nop
test   $0x1,%cl
mov    $0x0,%esi
cmove  %edx,%esi
add    $0x1,%ecx
add    %esi,%ebx
mov    %eax,%esi
add    %edx,%esi
mov    %edx,%eax
mov    %esi,%edx
cmp    $0x3d0900,%esi
jl     1140 <main+0x20>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r14,%rax
cvtsi2ss %rax,%xmm0
mov    0x2e72(%rip),%rax
divss  (%rax),%xmm0
lea    0xe7f(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"Sum %d in %fms\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
define i32 @main() {
%1 = tail call i64 (...) @clock()
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 1, %0 ], [ %6, %2 ]
%4 = phi i32 [ 0, %0 ], [ %11, %2 ]
%5 = phi i32 [ 2, %0 ], [ %7, %2 ]
%6 = phi i32 [ 2, %0 ], [ %12, %2 ]
%7 = add nuw nsw i32 %5, 1
%8 = and i32 %5, 1
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i32 %6, i32 0
%11 = add nsw i32 %10, %4
%12 = add nsw i32 %3, %6
%13 = icmp slt i32 %12, 4000000
br i1 %13, label %2, label %14
14: ; preds = %2
%15 = tail call i64 (...) @clock()
%16 = sub nsw i64 %15, %1
%17 = sitofp i64 %16 to float
%18 = load float, float* @CLOCKS_PER_SEC
%19 = fdiv float %17, %18
%20 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %11, float %19)
ret i32 0
}