#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 atoi(char *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  int lim = atoi(argv[1]), sum = 0, previous = 1, current = 2, next;
  while (current <= lim) {
    if (current % 2 == 0)
      sum += current;
    next = current + previous;
    previous = current;
    current = next;
  }
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x2,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     119e <main+0x7e>
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1184 <main+0x64>
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    115b <main+0x3b>
mov    -0x18(%rbp),%esi
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x8(%rsi),%rdi
call   1040 <atoi@plt>
xor    %esi,%esi
cmp    $0x2,%eax
jl     115a <main+0x3a>
mov    $0x1,%ecx
mov    $0x2,%edx
xor    %esi,%esi
nopl   (%rax)
mov    %edx,%edi
test   $0x1,%dil
mov    $0x0,%edx
cmove  %edi,%edx
add    %edx,%esi
add    %edi,%ecx
mov    %ecx,%edx
cmp    %eax,%ecx
mov    %edi,%ecx
jle    1140 <main+0x20>
lea    0xe9f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = icmp slt i32 %5, 2
br i1 %6, label %17, label %7
7: ; preds = %2, %7
%8 = phi i32 [ %14, %7 ], [ 0, %2 ]
%9 = phi i32 [ %15, %7 ], [ 2, %2 ]
%10 = phi i32 [ %9, %7 ], [ 1, %2 ]
%11 = and i32 %9, 1
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 %9, i32 0
%14 = add nsw i32 %13, %8
%15 = add nsw i32 %9, %10
%16 = icmp sgt i32 %15, %5
br i1 %16, label %17, label %7
17: ; preds = %7, %2
%18 = phi i32 [ 0, %2 ], [ %14, %7 ]
%19 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %18)
ret i32 0
}