#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 */
long atol(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
long next_fibonacci_num();
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "usage: %s <N>\n", argv[0]);
    return 1;
  }
  long N = atol(argv[1]);
  long sum = 0;
  long fib = 0;
  while ((fib = next_fibonacci_num()) <= N)
    if (fib % 2 == 0)
      sum += fib;
  printf("%ld\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)
cmpl   $0x2,-0x8(%rbp)
je     1188 <main+0x48>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fe <main+0xbe>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atol@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1050 <next_fibonacci_num@plt>
mov    %rax,-0x28(%rbp)
cmp    -0x18(%rbp),%rax
jg     11e7 <main+0xa7>
mov    -0x28(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11e2 <main+0xa2>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11a9 <main+0x69>
mov    -0x20(%rbp),%rsi
lea    0xe1d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    116c <main+0x2c>
mov    0x8(%rsi),%rdi
call   1060 <atol@plt>
mov    %rax,%r15
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <next_fibonacci_num@plt>
cmp    %r15,%rax
jle    118c <main+0x4c>
xor    %ebx,%ebx
jmp    11b5 <main+0x75>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe81(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%r14d
jmp    11c4 <main+0x84>
xor    %r12d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   $0x1,%al
cmovne %r12,%rax
add    %rax,%rbx
xor    %eax,%eax
call   1050 <next_fibonacci_num@plt>
cmp    %r15,%rax
jle    11a0 <main+0x60>
lea    0xe53(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"usage: %s <N>\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %26
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @atol(i8* %10)
%12 = tail call i64 (...) @next_fibonacci_num()
%13 = icmp sgt i64 %12, %11
br i1 %13, label %23, label %14
14: ; preds = %8, %14
%15 = phi i64 [ %21, %14 ], [ %12, %8 ]
%16 = phi i64 [ %20, %14 ], [ 0, %8 ]
%17 = and i64 %15, 1
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i64 %15, i64 0
%20 = add nsw i64 %19, %16
%21 = tail call i64 (...) @next_fibonacci_num()
%22 = icmp sgt i64 %21, %11
br i1 %22, label %23, label %14
23: ; preds = %14, %8
%24 = phi i64 [ 0, %8 ], [ %20, %14 ]
%25 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %24)
br label %26
26: ; preds = %23, %4
%27 = phi i32 [ 1, %4 ], [ 0, %23 ]
ret i32 %27
}