#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 *, long);
int main() {
  long int sum = 2;
  long int fib_a = 2;
  long int fib_b = 1;
  long int fib_aux;
  do {
    if (fib_a % 2 == 1)
      sum += fib_a;
    fib_aux = fib_a;
    fib_a += fib_b;
    fib_b = fib_aux;
  } while (fib_a < 4000000);
  printf("Sum is: %ld\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x2,-0x10(%rbp)
movq   $0x2,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x1,%rdx
jne    115b <main+0x4b>
mov    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x3d0900,-0x18(%rbp)
jl     1137 <main+0x27>
mov    -0x10(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x1,%eax
mov    $0x2,%ecx
mov    $0x2,%esi
nop
mov    %rcx,%rdx
shr    $0x3f,%rcx
add    %rdx,%rcx
and    $0xfffffffffffffffe,%rcx
mov    %rdx,%rdi
sub    %rcx,%rdi
cmp    $0x1,%rdi
mov    $0x0,%ecx
cmove  %rdx,%rcx
add    %rcx,%rsi
add    %rdx,%rax
mov    %rax,%rcx
cmp    $0x3d0900,%rax
mov    %rdx,%rax
jl     1120 <main+0x10>
push   %rax
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Sum is: %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
store i64 2, i64* %2
store i64 2, i64* %3
store i64 1, i64* %4
br label %6
6: ; preds = %20, %0
%7 = load i64, i64* %3
%8 = srem i64 %7, 2
%9 = icmp eq i64 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i64, i64* %3
%12 = load i64, i64* %2
%13 = add nsw i64 %12, %11
store i64 %13, i64* %2
br label %14
14: ; preds = %10, %6
%15 = load i64, i64* %3
store i64 %15, i64* %5
%16 = load i64, i64* %4
%17 = load i64, i64* %3
%18 = add nsw i64 %17, %16
store i64 %18, i64* %3
%19 = load i64, i64* %5
store i64 %19, i64* %4
br label %20
20: ; preds = %14
%21 = load i64, i64* %3
%22 = icmp slt i64 %21, 4000000
br i1 %22, label %6, label %23
23: ; preds = %20
%24 = load i64, i64* %2
%25 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %24)
ret i32 0
}

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