#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 argc, char *argv[]) {
  int sum = 0;
  int val1 = 0;
  int val2 = 1;
  for (; val2 <= 4000000;) {
    if (val2 & 1) {
      sum += val2;
    }
    val1 ^= val2;
    val2 ^= val1;
    val1 ^= val2;
    val2 += val1;
    printf("val2: %d\n", val2);
  }
  printf("Sum: %d", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x3d0900,-0x1c(%rbp)
jg     1198 <main+0x88>
mov    -0x1c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1160 <main+0x50>
mov    -0x1c(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
xor    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
xor    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
xor    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
jmp    113b <main+0x2b>
mov    -0x14(%rbp),%esi
lea    0xe68(%rip),%rdi
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   %rbx
push   %rax
xor    %ebx,%ebx
mov    $0x1,%eax
lea    0xedb(%rip),%r14
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    %eax,%ebp
and    $0x1,%eax
neg    %eax
and    %ebp,%eax
add    %eax,%r15d
add    %ebp,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
cmp    $0x3d0901,%ebx
mov    %ebp,%ebx
jl     1130 <main+0x20>
lea    0xeaf(%rip),%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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