#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);
int Problem002(void) {
  int a = 1, b = 2, c;
  int sum = 2;
  do {
    c = a + b;
    if (c % 2 == 1) {
      sum = sum + c;
    }
    a = b;
    b = c;
  } while ((a + b) < 4000000);
  printf("%30d", sum);
  return 0;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1153 <Problem002+0x43>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
cmp    $0x3d0900,%eax
jl     112d <Problem002+0x1d>
mov    -0x10(%rbp),%esi
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
mov    $0x1,%eax
mov    $0x2,%ecx
mov    $0x2,%esi
nop
mov    %ecx,%edx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
mov    %eax,%edi
sub    %ecx,%edi
cmp    $0x1,%edi
mov    $0x0,%ecx
cmove  %eax,%ecx
add    %ecx,%esi
lea    (%rax,%rdx,1),%edi
mov    %eax,%ecx
mov    %edx,%eax
cmp    $0x3d0900,%edi
jl     1120 <Problem002+0x10>
push   %rax
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

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