#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 Fibonacci(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i = 0;
  int fibonacci = 0;
  int sum = 0;
  int max;
  printf("To which number do you want your sequence to arrive? ");
  scanf("%d", &max);
  while (fibonacci < max) {
    fibonacci = Fibonacci(i);
    printf("Fibonacci(%d): %d\n", i, fibonacci);
    if (fibonacci % 2 == 0) {
      sum = sum + fibonacci;
      printf("Sum: %d\n", sum);
    }
    i++;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xecd(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d9 <main+0xa9>
mov    -0x8(%rbp),%edi
call   1030 <Fibonacci@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11cb <main+0x9b>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1172 <main+0x42>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11b8 <main+0x88>
lea    0xed0(%rip),%r15
lea    0xedc(%rip),%r14
xor    %r12d,%r12d
xor    %ebx,%ebx
jmp    1189 <main+0x59>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    0xc(%rsp),%ebp
jge    11b8 <main+0x88>
mov    %ebx,%edi
call   1030 <Fibonacci@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x1,%bpl
jne    1180 <main+0x50>
add    %ebp,%r12d
mov    %r14,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1180 <main+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [54 x i8] c"To which number do you want your sequence to arrive? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Fibonacci(%d): %d\0A\00"
@.str.3 = [9 x i8] c"Sum: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
br label %8
8: ; preds = %27, %0
%9 = load i32, i32* %3
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %30
12: ; preds = %8
%13 = load i32, i32* %2
%14 = call i32 @Fibonacci(i32 %13)
store i32 %14, i32* %3
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %15, i32 %16)
%18 = load i32, i32* %3
%19 = srem i32 %18, 2
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %12
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = add nsw i32 %22, %23
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %21, %12
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %8
30: ; preds = %8
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [54 x i8] c"To which number do you want your sequence to arrive? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Fibonacci(%d): %d\0A\00"
@.str.3 = [9 x i8] c"Sum: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %0, %17
%8 = phi i32 [ %18, %17 ], [ 0, %0 ]
%9 = phi i32 [ %19, %17 ], [ 0, %0 ]
%10 = call i32 @Fibonacci(i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %10)
%12 = and i32 %10, 1
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %7
%15 = add nsw i32 %10, %8
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %7
%18 = phi i32 [ %15, %14 ], [ %8, %7 ]
%19 = add nuw nsw i32 %9, 1
%20 = load i32, i32* %1
%21 = icmp slt i32 %10, %20
br i1 %21, label %7, label %22
22: ; preds = %17, %0
ret i32 0
}