#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, int);
int main(void) {
  uint32_t sum = 2;
  uint32_t terms[2];
  uint32_t temp = 0;
  terms[0] = 1;
  terms[1] = 2;
  while (terms[1] <= 4000000) {
    temp = terms[1] + terms[2];
    terms[1] = terms[2];
    terms[2] = temp;
    if (!(terms[2] % 2))
      sum += terms[2];
  }
  printf("The sum of the even-valued terms in the Fibonacci sequence where "
         "the terms do not exceed %d is: %d\n",
         4000000, sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x2,-0xc(%rbp)
cmpl   $0x3d0900,-0xc(%rbp)
jg     117f <main+0x6f>
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117a <main+0x6a>
mov    -0x8(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    113b <main+0x2b>
mov    -0x8(%rbp),%edx
lea    0xe77(%rip),%rdi
mov    $0x3d0900,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
LLVM IR (-O0):
@.str = [100 x i8] c"The sum of the even-valued terms in the Fibonacci sequence where the terms do not exceed %d is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i32]
%4 = alloca i32
store i32 0, i32* %1
store i32 2, i32* %2
store i32 0, i32* %4
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
store i32 1, i32* %5
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i32 2, i32* %6
br label %7
7: ; preds = %31, %0
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%9 = load i32, i32* %8
%10 = icmp sle i32 %9, 4000000
br i1 %10, label %11, label %32
11: ; preds = %7
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%13 = load i32, i32* %12
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 2
%15 = load i32, i32* %14
%16 = add nsw i32 %13, %15
store i32 %16, i32* %4
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 2
%18 = load i32, i32* %17
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i32 %18, i32* %19
%20 = load i32, i32* %4
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 2
store i32 %20, i32* %21
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 2
%23 = load i32, i32* %22
%24 = srem i32 %23, 2
%25 = icmp ne i32 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %11
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 2
%28 = load i32, i32* %27
%29 = load i32, i32* %2
%30 = add nsw i32 %29, %28
store i32 %30, i32* %2
br label %31
31: ; preds = %26, %11
br label %7
32: ; preds = %7
%33 = load i32, i32* %2
%34 = call i32 @printf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str, i64 0, i64 0), i32 4000000, i32 %33)
ret i32 0
}

LLVM IR (-O2):