#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 last_bit(unsigned long long);
unsigned long long flip_G1(const unsigned long long discs_player,
                           const unsigned long long discs_opponent) {
  unsigned long long my_discs, opp_discs, r, flipped = 0ULL;
  my_discs = discs_player & 0X0000081020408000ULL;
  opp_discs = (discs_opponent & 0X0004081020400000ULL) | 0X01FBF7EFDF800000ULL;
  r = ((my_discs << 7) + opp_discs) & 0X0200000000000000ULL;
  if (r != 0) {
    flipped |= (0X0200000000000000ULL - (0X2ULL << last_bit(my_discs))) &
               0X0004081020400000ULL;
  }
  my_discs = discs_player & 0XF800000000000000ULL;
  r = (discs_opponent + 0X0400000000000000ULL) & my_discs;
  if (r != 0) {
    flipped |= (r - 1) & 0XFC00000000000000ULL;
  }
  my_discs = discs_player & 0X0000020202020202ULL;
  opp_discs = (discs_opponent & 0X0002020202020200ULL) | 0X01FDFDFDFDFDFC00ULL;
  r = ((my_discs << 8) + opp_discs) & 0X0200000000000000ULL;
  if (r != 0) {
    flipped |= (0X0200000000000000ULL - (0X2ULL << last_bit(my_discs))) &
               0X0002020202020200ULL;
  }
  return flipped;
}


x86 assembly (clang, -O0):
<flip_G1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movabs $0x81020408000,%rax
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x4081020400000,%rax
and    -0x10(%rbp),%rax
movabs $0x1fbf7efdf800000,%rcx
f7 fb 01
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x7,%rax
add    -0x20(%rbp),%rax
movabs $0x200000000000000,%rcx
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11bb <flip_G1+0xab>
mov    -0x18(%rbp),%rdi
call   1030 <last_bit@plt>
mov    %eax,%eax
mov    %eax,%ecx
mov    $0x2,%eax
shl    %cl,%rax
mov    %rax,%rcx
movabs $0x200000000000000,%rax
sub    %rcx,%rax
movabs $0x4081020400000,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movabs $0xf800000000000000,%rax
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x400000000000000,%rax
add    -0x10(%rbp),%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     120b <flip_G1+0xfb>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
movabs $0xfc00000000000000,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movabs $0x20202020202,%rax
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x2020202020200,%rax
and    -0x10(%rbp),%rax
movabs $0x1fdfdfdfdfdfc00,%rcx
fd fd 01
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x8,%rax
add    -0x20(%rbp),%rax
movabs $0x200000000000000,%rcx
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     129e <flip_G1+0x18e>
mov    -0x18(%rbp),%rdi
call   1030 <last_bit@plt>
mov    %eax,%eax
mov    %eax,%ecx
mov    $0x2,%eax
shl    %cl,%rax
mov    %rax,%rcx
movabs $0x200000000000000,%rax
sub    %rcx,%rax
movabs $0x2020202020200,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flip_G1>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
movabs $0x200000000000000,%r12
movabs $0x4081020400000,%rbx
movabs $0x81020408000,%rdi
and    %r14,%rdi
mov    %rsi,%rax
and    %rbx,%rax
mov    %rdi,%rcx
shl    $0x7,%rcx
add    %rax,%rcx
movabs $0x1fbf7efdf800000,%rax
f7 fb 01
add    %rcx,%rax
bt     $0x39,%rax
jb     1168 <flip_G1+0x58>
xor    %edx,%edx
jmp    117c <flip_G1+0x6c>
call   1030 <last_bit@plt>
mov    $0xfffffffffffffffe,%rdx
mov    %eax,%ecx
shl    %cl,%rdx
and    %rbx,%rdx
movabs $0x400000000000000,%rax
add    %r15,%rax
and    %r14,%rax
movabs $0xf800000000000000,%rcx
and    %rax,%rcx
lea    -0x1(%rcx),%rax
movabs $0xfc00000000000000,%rsi
and    %rax,%rsi
xor    %ebx,%ebx
cmp    $0x1,%rcx
movabs $0x2020202020200,%r13
cmovae %rsi,%rbx
or     %rdx,%rbx
movabs $0x20202020202,%rdi
and    %r14,%rdi
and    %r13,%r15
mov    %rdi,%rax
shl    $0x8,%rax
add    %r15,%rax
movabs $0x1fdfdfdfdfdfc00,%rcx
fd fd 01
add    %rax,%rcx
test   %r12,%rcx
je     1204 <flip_G1+0xf4>
call   1030 <last_bit@plt>
mov    $0xfffffffffffffffe,%rdx
mov    %eax,%ecx
shl    %cl,%rdx
and    %r13,%rdx
or     %rdx,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @flip_G1(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
store i64 0, i64* %8
%9 = load i64, i64* %3
%10 = and i64 %9, 8865353596928
store i64 %10, i64* %5
%11 = load i64, i64* %4
%12 = and i64 %11, 1134765260406784
%13 = or i64 %12, 142980422811254784
store i64 %13, i64* %6
%14 = load i64, i64* %5
%15 = shl i64 %14, 7
%16 = load i64, i64* %6
%17 = add i64 %15, %16
%18 = and i64 %17, 144115188075855872
store i64 %18, i64* %7
%19 = load i64, i64* %7
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %2
%22 = load i64, i64* %5
%23 = call i32 @last_bit(i64 %22)
%24 = zext i32 %23 to i64
%25 = shl i64 2, %24
%26 = sub i64 144115188075855872, %25
%27 = and i64 %26, 1134765260406784
%28 = load i64, i64* %8
%29 = or i64 %28, %27
store i64 %29, i64* %8
br label %30
30: ; preds = %21, %2
%31 = load i64, i64* %3
%32 = and i64 %31, -576460752303423488
store i64 %32, i64* %5
%33 = load i64, i64* %4
%34 = add i64 %33, 288230376151711744
%35 = load i64, i64* %5
%36 = and i64 %34, %35
store i64 %36, i64* %7
%37 = load i64, i64* %7
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %30
%40 = load i64, i64* %7
%41 = sub i64 %40, 1
%42 = and i64 %41, -288230376151711744
%43 = load i64, i64* %8
%44 = or i64 %43, %42
store i64 %44, i64* %8
br label %45
45: ; preds = %39, %30
%46 = load i64, i64* %3
%47 = and i64 %46, 2207646876162
store i64 %47, i64* %5
%48 = load i64, i64* %4
%49 = and i64 %48, 565157600297472
%50 = or i64 %49, 143550030475557888
store i64 %50, i64* %6
%51 = load i64, i64* %5
%52 = shl i64 %51, 8
%53 = load i64, i64* %6
%54 = add i64 %52, %53
%55 = and i64 %54, 144115188075855872
store i64 %55, i64* %7
%56 = load i64, i64* %7
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %67
58: ; preds = %45
%59 = load i64, i64* %5
%60 = call i32 @last_bit(i64 %59)
%61 = zext i32 %60 to i64
%62 = shl i64 2, %61
%63 = sub i64 144115188075855872, %62
%64 = and i64 %63, 565157600297472
%65 = load i64, i64* %8
%66 = or i64 %65, %64
store i64 %66, i64* %8
br label %67
67: ; preds = %58, %45
%68 = load i64, i64* %8
ret i64 %68
}

LLVM IR (-O2):
define i64 @flip_G1(i64 %0, i64 %1) {
%3 = and i64 %0, 8865353596928
%4 = and i64 %1, 1134765260406784
%5 = or i64 %4, 142980422811254784
%6 = shl nuw nsw i64 %3, 7
%7 = add nuw nsw i64 %5, %6
%8 = and i64 %7, 144115188075855872
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = tail call i32 @last_bit(i64 %3)
%12 = zext i32 %11 to i64
%13 = shl i64 -2, %12
%14 = and i64 %13, 1134765260406784
br label %15
15: ; preds = %10, %2
%16 = phi i64 [ %14, %10 ], [ 0, %2 ]
%17 = and i64 %0, -576460752303423488
%18 = add i64 %1, 288230376151711744
%19 = and i64 %17, %18
%20 = icmp eq i64 %19, 0
%21 = add i64 %19, -1
%22 = and i64 %21, -288230376151711744
%23 = select i1 %20, i64 0, i64 %22
%24 = or i64 %16, %23
%25 = and i64 %0, 2207646876162
%26 = and i64 %1, 565157600297472
%27 = or i64 %26, 143550030475557888
%28 = shl nuw nsw i64 %25, 8
%29 = add nuw nsw i64 %27, %28
%30 = and i64 %29, 144115188075855872
%31 = icmp eq i64 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %15
%33 = tail call i32 @last_bit(i64 %25)
%34 = zext i32 %33 to i64
%35 = shl i64 -2, %34
%36 = and i64 %35, 565157600297472
%37 = or i64 %36, %24
br label %38
38: ; preds = %32, %15
%39 = phi i64 [ %37, %32 ], [ %24, %15 ]
ret i64 %39
}