#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 main() {
  int sum = 0, val_prev = 1, val_cur = 2;
  while (val_cur < 4000000) {
    if (val_cur % 2 == 0) {
      sum += val_cur;
      printf("%d -> %d\n", val_cur, sum);
    } else {
      printf("%d -> skip\n", val_cur);
    }
    int val_next = val_prev + val_cur;
    val_prev = val_cur;
    val_cur = val_next;
  }
  printf("sum: %d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
cmpl   $0x3d0900,-0x10(%rbp)
jge    11a2 <main+0x92>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1177 <main+0x67>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1188 <main+0x78>
mov    -0x10(%rbp),%esi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1134 <main+0x24>
mov    -0x8(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x1,%ebp
mov    $0x2,%eax
lea    0xed7(%rip),%r14
lea    0xeda(%rip),%r15
xor    %r12d,%r12d
jmp    115a <main+0x4a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    %ebx,%ebp
mov    %ebp,%eax
cmp    $0x3d0900,%ebp
mov    %ebx,%ebp
jge    1175 <main+0x65>
mov    %eax,%ebx
test   $0x1,%bl
jne    1140 <main+0x30>
add    %ebx,%r12d
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    114c <main+0x3c>
lea    0xe9a(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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