#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 *, unsigned int);
unsigned int sum_parity(unsigned int, unsigned int);
int main() {
  unsigned a = 1, b = 2, a_parity = 1, b_parity = 2, sum = 0;
  while (a <= 4000000) {
    if (a_parity == 2)
      sum += a;
    b_parity = a_parity ^ b_parity;
    a_parity = a_parity ^ b_parity;
    b_parity = a_parity ^ b_parity;
    b_parity = sum_parity(a_parity, b_parity);
    b = a ^ b;
    a = a ^ b;
    b = a ^ b;
    b += a;
  }
  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   $0x1,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3d0900,-0x8(%rbp)
ja     11c4 <main+0xa4>
cmpl   $0x2,-0x10(%rbp)
jne    1172 <main+0x52>
mov    -0x8(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
xor    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
xor    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
xor    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <sum_parity@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
xor    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
xor    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
xor    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1152 <main+0x32>
mov    -0x18(%rbp),%esi
lea    0xe32(%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
mov    $0x1,%esi
mov    $0x2,%eax
xor    %ebx,%ebx
mov    $0x2,%ecx
mov    $0x1,%ebp
nopl   (%rax)
mov    %ecx,%r15d
mov    %eax,%r14d
cmp    $0x2,%esi
mov    $0x0,%eax
cmove  %ebp,%eax
add    %eax,%ebx
mov    %r14d,%edi
call   1040 <sum_parity@plt>
add    %r15d,%ebp
mov    %r14d,%esi
mov    %ebp,%ecx
mov    %r15d,%ebp
cmp    $0x3d0901,%r15d
jb     1140 <main+0x20>
lea    0xe8a(%rip),%rdi
mov    %ebx,%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"sum = %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
store i32 1, i32* %4
store i32 2, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %17, %0
%8 = load i32, i32* %2
%9 = icmp ule i32 %8, 4000000
br i1 %9, label %10, label %42
10: ; preds = %7
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* %2
%15 = load i32, i32* %6
%16 = add i32 %15, %14
store i32 %16, i32* %6
br label %17
17: ; preds = %13, %10
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = xor i32 %18, %19
store i32 %20, i32* %5
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = xor i32 %21, %22
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = xor i32 %24, %25
store i32 %26, i32* %5
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = call i32 @sum_parity(i32 %27, i32 %28)
store i32 %29, i32* %5
%30 = load i32, i32* %2
%31 = load i32, i32* %3
%32 = xor i32 %30, %31
store i32 %32, i32* %3
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = xor i32 %33, %34
store i32 %35, i32* %2
%36 = load i32, i32* %2
%37 = load i32, i32* %3
%38 = xor i32 %36, %37
store i32 %38, i32* %3
%39 = load i32, i32* %2
%40 = load i32, i32* %3
%41 = add i32 %40, %39
store i32 %41, i32* %3
br label %7
42: ; preds = %7
%43 = load i32, i32* %6
%44 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %43)
ret i32 0
}

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