#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);
void p002() {
  int limit = 4000000;
  int sum = 2;
  int a = 1;
  int b = 2;
  int temp = a + b;
  while (temp < limit) {
    if (temp % 2 == 0) {
      sum += temp;
    }
    a = b;
    b = temp;
    temp = a + b;
  }
  printf("Sum is: %d", sum);
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x3d0900,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1180 <p002+0x70>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1166 <p002+0x56>
mov    -0x14(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    113d <p002+0x2d>
mov    -0x8(%rbp),%esi
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
mov    $0x2,%eax
mov    $0x3,%ecx
mov    $0x2,%esi
nop
mov    %ecx,%edx
test   $0x1,%dl
mov    $0x0,%ecx
cmove  %edx,%ecx
add    %ecx,%esi
add    %edx,%eax
mov    %eax,%ecx
cmp    $0x3d0900,%eax
mov    %edx,%eax
jl     1120 <p002+0x10>
lea    0xebd(%rip),%rdi
jmp    1030 <printf@plt>

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

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