#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 *, int);
int Fibonacci() {
  int soma = 2, fibaux = 2, fib = 2;
  int fibmenos = 1;
  do {
    fibaux = fib;
    fib += fibmenos;
    fibmenos = fibaux;
    if (fib % 2 == 0) {
      soma = soma + fib;
    }
  } while (fib < 4000000);
  printf("%d\n\n", soma);
  return soma;
}


x86 assembly (clang, -O0):
<Fibonacci>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x2,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1166 <Fibonacci+0x56>
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    116b <Fibonacci+0x5b>
cmpl   $0x3d0900,-0xc(%rbp)
jl     1134 <Fibonacci+0x24>
mov    -0x4(%rbp),%esi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Fibonacci>:
push   %rbx
mov    $0x1,%eax
mov    $0x2,%ebx
mov    $0x2,%ecx
mov    %ecx,%edx
add    %ecx,%eax
test   $0x1,%al
mov    $0x0,%ecx
cmove  %eax,%ecx
add    %ecx,%ebx
mov    %eax,%ecx
cmp    $0x3d0900,%eax
mov    %edx,%eax
jl     1120 <Fibonacci+0x10>
lea    0xebe(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

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

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