#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 sum_even(int);
int main(void) {
  int f1 = 1;
  int f2 = 2;
  int f3 = f1 + f2;
  int sum = 2;
  int lc = 0;
  while (f3 < 4000000) {
    lc++;
    if ((f3 & 0x01) == 0) {
      sum += f3;
    }
    f1 = f2;
    f2 = f3;
    f3 = f1 + f2;
  }
  printf("  sum is %d, lc is %d\n", sum, lc);
  printf(" another way is %d\n", sum_even(4000000));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3d0900,-0x10(%rbp)
jge    119c <main+0x7c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1182 <main+0x62>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1154 <main+0x34>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x3d0900,%edi
call   1040 <sum_even@plt>
mov    %eax,%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x3,%ecx
mov    $0x2,%esi
xor    %edx,%edx
mov    $0x2,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ecx,%edi
add    $0x1,%edx
test   $0x1,%dil
mov    $0x0,%ecx
cmove  %edi,%ecx
add    %ecx,%esi
add    %edi,%eax
mov    %eax,%ecx
cmp    $0x3d0900,%eax
mov    %edi,%eax
jl     1140 <main+0x20>
push   %rax
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x3d0900,%edi
call   1040 <sum_even@plt>
lea    0xe97(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [23 x i8] c" sum is %d, lc is %d\0A\00"
@.str.1 = [20 x i8] c" another way 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 2, i32* %3
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = add nsw i32 %7, %8
store i32 %9, i32* %4
store i32 2, i32* %5
store i32 0, i32* %6
br label %10
10: ; preds = %23, %0
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 4000000
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 1
store i32 %15, i32* %6
%16 = load i32, i32* %4
%17 = and i32 %16, 1
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = add nsw i32 %21, %20
store i32 %22, i32* %5
br label %23
23: ; preds = %19, %13
%24 = load i32, i32* %3
store i32 %24, i32* %2
%25 = load i32, i32* %4
store i32 %25, i32* %3
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = add nsw i32 %26, %27
store i32 %28, i32* %4
br label %10
29: ; preds = %10
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %31)
%33 = call i32 @sum_even(i32 4000000)
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c" sum is %d, lc is %d\0A\00"
@.str.1 = [20 x i8] c" another way is %d\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 0, %0 ], [ %6, %1 ]
%3 = phi i32 [ 2, %0 ], [ %10, %1 ]
%4 = phi i32 [ 3, %0 ], [ %11, %1 ]
%5 = phi i32 [ 2, %0 ], [ %4, %1 ]
%6 = add nuw nsw i32 %2, 1
%7 = and i32 %4, 1
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i32 %4, i32 0
%10 = add nsw i32 %9, %3
%11 = add nsw i32 %4, %5
%12 = icmp slt i32 %11, 4000000
br i1 %12, label %1, label %13
13: ; preds = %1
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %6)
%15 = tail call i32 @sum_even(i32 4000000)
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %15)
ret i32 0
}