#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 */
scalar_t__ isPowerOfTwo(unsigned long long);
scalar_t__ lsb(unsigned long long);
int whoIsWinner(unsigned long long int n) {
  int i = 0;
  while (n != 1) {
    if (isPowerOfTwo(n)) {
      n /= 2;
    } else {
      n -= lsb(n);
    }
    i++;
  }
  return (i & 1);
}


x86 assembly (clang, -O0):
<whoIsWinner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpq   $0x1,-0x8(%rbp)
je     1187 <whoIsWinner+0x67>
mov    -0x8(%rbp),%rdi
call   1030 <isPowerOfTwo@plt>
cmp    $0x0,%rax
je     1162 <whoIsWinner+0x42>
mov    -0x8(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1179 <whoIsWinner+0x59>
mov    -0x8(%rbp),%rdi
call   1040 <lsb@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <whoIsWinner+0x13>
mov    -0xc(%rbp),%eax
and    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<whoIsWinner>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
cmp    $0x1,%rdi
je     1169 <whoIsWinner+0x49>
mov    %rdi,%r14
xor    %ebx,%ebx
jmp    1154 <whoIsWinner+0x34>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1040 <lsb@plt>
sub    %rax,%r14
add    $0x1,%ebx
cmp    $0x1,%r14
je     1166 <whoIsWinner+0x46>
mov    %r14,%rdi
call   1030 <isPowerOfTwo@plt>
test   %rax,%rax
je     1140 <whoIsWinner+0x20>
shr    %r14
jmp    114b <whoIsWinner+0x2b>
and    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @whoIsWinner(i64 %0) {
%2 = alloca i64
%3 = alloca i32
store i64 %0, i64* %2
store i32 0, i32* %3
br label %4
4: ; preds = %19, %1
%5 = load i64, i64* %2
%6 = icmp ne i64 %5, 1
br i1 %6, label %7, label %22
7: ; preds = %4
%8 = load i64, i64* %2
%9 = call i64 @isPowerOfTwo(i64 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i64, i64* %2
%13 = udiv i64 %12, 2
store i64 %13, i64* %2
br label %19
14: ; preds = %7
%15 = load i64, i64* %2
%16 = call i64 @lsb(i64 %15)
%17 = load i64, i64* %2
%18 = sub i64 %17, %16
store i64 %18, i64* %2
br label %19
19: ; preds = %14, %11
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %4
22: ; preds = %4
%23 = load i32, i32* %3
%24 = and i32 %23, 1
ret i32 %24
}

LLVM IR (-O2):
define i32 @whoIsWinner(i64 %0) {
%2 = icmp eq i64 %0, 1
br i1 %2, label %19, label %3
3: ; preds = %1, %13
%4 = phi i32 [ %15, %13 ], [ 0, %1 ]
%5 = phi i64 [ %14, %13 ], [ %0, %1 ]
%6 = tail call i64 @isPowerOfTwo(i64 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = lshr i64 %5, 1
br label %13
10: ; preds = %3
%11 = tail call i64 @lsb(i64 %5)
%12 = sub i64 %5, %11
br label %13
13: ; preds = %10, %8
%14 = phi i64 [ %9, %8 ], [ %12, %10 ]
%15 = add nuw nsw i32 %4, 1
%16 = icmp eq i64 %14, 1
br i1 %16, label %17, label %3
17: ; preds = %13
%18 = and i32 %15, 1
br label %19
19: ; preds = %17, %1
%20 = phi i32 [ 0, %1 ], [ %18, %17 ]
ret i32 %20
}