#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 /*<<< orphan*/ scanf(char *, int *);
int main() {
  int a = 1;
  int b = 1;
  int sum = 0;
  int c = 0;
  int input;
  printf("Please insert an integer value: ");
  scanf("%d", &input);
  while (c < input) {
    c = a + b;
    a = b;
    b = c;
    if (c % 2 == 0) {
      sum = sum + c;
    }
  }
  printf("The sum of even fibonacci numbers up to 1M is: %d\n", sum);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11ac <main+0x8c>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a7 <main+0x87>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1169 <main+0x49>
mov    -0x10(%rbp),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xed4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    1179 <main+0x59>
mov    $0x1,%edx
xor    %ebx,%ebx
mov    $0x1,%ecx
nopw   0x0(%rax,%rax,1)
mov    %edx,%esi
add    %edx,%ecx
test   $0x1,%cl
mov    $0x0,%edx
cmove  %ecx,%edx
add    %edx,%ebx
mov    %ecx,%edx
cmp    %eax,%ecx
mov    %esi,%ecx
jl     1160 <main+0x40>
lea    0xea4(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Please insert an integer value: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [51 x i8] c"The sum of even fibonacci numbers up to 1M is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
store i32 1, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
br label %9
9: ; preds = %26, %0
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = add nsw i32 %14, %15
store i32 %16, i32* %5
%17 = load i32, i32* %3
store i32 %17, i32* %2
%18 = load i32, i32* %5
store i32 %18, i32* %3
%19 = load i32, i32* %5
%20 = srem i32 %19, 2
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %13
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = add nsw i32 %23, %24
store i32 %25, i32* %4
br label %26
26: ; preds = %22, %13
br label %9
27: ; preds = %9
%28 = load i32, i32* %4
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [33 x i8] c"Please insert an integer value: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [51 x i8] c"The sum of even fibonacci numbers up to 1M is: %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 ([33 x i8], [33 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 %17
7: ; preds = %0, %7
%8 = phi i32 [ %15, %7 ], [ 0, %0 ]
%9 = phi i32 [ %11, %7 ], [ 1, %0 ]
%10 = phi i32 [ %9, %7 ], [ 1, %0 ]
%11 = add nsw i32 %9, %10
%12 = and i32 %11, 1
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 %11, i32 0
%15 = add nsw i32 %14, %8
%16 = icmp slt i32 %11, %5
br i1 %16, label %7, label %17
17: ; preds = %7, %0
%18 = phi i32 [ 0, %0 ], [ %15, %7 ]
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %18)
ret i32 0
}