#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 main(void) {
  printf("==========\nBy considering the terms in the Fibonacci sequence "
         "whose\nvalues do not exceed four million, find the sum of the "
         "even-valued terms.\n==========\n\n");
  unsigned long int intFib = 0;
  unsigned long int intPrev = 0;
  unsigned long int intCur = 1;
  unsigned long int intSumEvenNumbers = 0;
  unsigned long int intMax = 0x3D0900;
  while (intSumEvenNumbers < intMax) {
    intFib = intPrev + intCur;
    if (intFib % 2 == 0)
      intSumEvenNumbers += intFib;
    intPrev = intCur;
    intCur = intFib;
  }
  printf("The sum of all even numbers in the Fibonacci sequence is: %i\n",
         intSumEvenNumbers);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x3d0900,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    11a2 <main+0x92>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    118d <main+0x7d>
mov    -0x10(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1155 <main+0x45>
mov    -0x28(%rbp),%rsi
lea    0xeee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xf16(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ecx
xor    %esi,%esi
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
mov    %rcx,%rdx
add    %rcx,%rax
test   $0x1,%al
mov    $0x0,%ecx
cmove  %rax,%rcx
add    %rcx,%rsi
mov    %rax,%rcx
mov    %rdx,%rax
cmp    $0x3d0900,%rsi
jb     1140 <main+0x20>
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [155 x i8] c"==========\0ABy considering the terms in the Fibonacci sequence whose\0Avalues do not exceed four million, find the sum of the even-valued terms.\0A==========\0A\0A\00"
@.str.1 = [62 x i8] c"The sum of all even numbers in the Fibonacci sequence is: %i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %2
store i64 0, i64* %3
store i64 1, i64* %4
store i64 0, i64* %5
store i64 4000000, i64* %6
br label %8
8: ; preds = %23, %0
%9 = load i64, i64* %5
%10 = load i64, i64* %6
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %26
12: ; preds = %8
%13 = load i64, i64* %3
%14 = load i64, i64* %4
%15 = add i64 %13, %14
store i64 %15, i64* %2
%16 = load i64, i64* %2
%17 = urem i64 %16, 2
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %12
%20 = load i64, i64* %2
%21 = load i64, i64* %5
%22 = add i64 %21, %20
store i64 %22, i64* %5
br label %23
23: ; preds = %19, %12
%24 = load i64, i64* %4
store i64 %24, i64* %3
%25 = load i64, i64* %2
store i64 %25, i64* %4
br label %8
26: ; preds = %8
%27 = load i64, i64* %5
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i64 %27)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [62 x i8] c"The sum of all even numbers in the Fibonacci sequence is: %i\0A\00"
@str = [154 x i8] c"==========\0ABy considering the terms in the Fibonacci sequence whose\0Avalues do not exceed four million, find the sum of the even-valued terms.\0A==========\0A\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([154 x i8], [154 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi i64 [ 0, %0 ], [ %10, %2 ]
%4 = phi i64 [ 1, %0 ], [ %6, %2 ]
%5 = phi i64 [ 0, %0 ], [ %4, %2 ]
%6 = add i64 %4, %5
%7 = and i64 %6, 1
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i64 %6, i64 0
%10 = add i64 %9, %3
%11 = icmp ult i64 %10, 4000000
br i1 %11, label %2, label %12
12: ; preds = %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i64 %10)
ret i32 0
}