#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_G3(const unsigned long long discs_player,
                           const unsigned long long discs_opponent) {
  unsigned long long my_discs, opp_discs, r;
  unsigned long long flipped =
      (discs_opponent & 0X0004000000000000ULL) & (discs_player >> 9);
  flipped |= (discs_opponent & 0X0002000000000000ULL) & (discs_player >> 8);
  my_discs = discs_player & 0X0000F80000000000ULL;
  r = (discs_opponent + 0X0000040000000000ULL) & my_discs;
  if (r != 0) {
    flipped |= (r - 1) & 0X0000FC0000000000ULL;
  }
  my_discs = discs_player & 0X0000000008102040ULL;
  opp_discs = (discs_opponent & 0X0000000408102000ULL) | 0X000001FBF7EFC000ULL;
  r = ((my_discs << 7) + opp_discs) & 0X0000020000000000ULL;
  if (r != 0) {
    flipped |= (0X0000020000000000ULL - (0X2ULL << last_bit(my_discs))) &
               0X0000000408102000ULL;
  }
  my_discs = discs_player & 0X0000000002020202ULL;
  opp_discs = (discs_opponent & 0X0000000202020200ULL) | 0X000001FDFDFDFC00ULL;
  r = ((my_discs << 8) + opp_discs) & 0X0000020000000000ULL;
  if (r != 0) {
    flipped |= (0X0000020000000000ULL - (0X2ULL << last_bit(my_discs))) &
               0X0000000202020200ULL;
  }
  return flipped;
}


x86 assembly (clang, -O0):
<flip_G3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x4000000000000,%rax
and    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
shr    $0x9,%rcx
and    %rcx,%rax
mov    %rax,-0x30(%rbp)
movabs $0x2000000000000,%rax
and    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
shr    $0x8,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movabs $0xf80000000000,%rax
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x40000000000,%rax
add    -0x10(%rbp),%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ae <flip_G3+0x9e>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
movabs $0xfc0000000000,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
and    $0x8102040,%rax
mov    %rax,-0x18(%rbp)
movabs $0x408102000,%rax
and    -0x10(%rbp),%rax
movabs $0x1fbf7efc000,%rcx
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x7,%rax
add    -0x20(%rbp),%rax
movabs $0x20000000000,%rcx
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     123d <flip_G3+0x12d>
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 $0x20000000000,%rax
sub    %rcx,%rax
movabs $0x408102000,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
and    $0x2020202,%rax
mov    %rax,-0x18(%rbp)
movabs $0x202020200,%rax
and    -0x10(%rbp),%rax
movabs $0x1fdfdfdfc00,%rcx
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x8,%rax
add    -0x20(%rbp),%rax
movabs $0x20000000000,%rcx
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12cc <flip_G3+0x1bc>
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 $0x20000000000,%rax
sub    %rcx,%rax
movabs $0x202020200,%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_G3>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
movabs $0x20000000000,%r12
movabs $0x408102000,%r13
mov    %rdi,%rax
shr    $0x9,%rax
and    %rsi,%rax
movabs $0x4000000000000,%rcx
and    %rax,%rcx
mov    %rdi,%rax
shr    $0x8,%rax
and    %rsi,%rax
movabs $0x2000000000000,%rdx
and    %rax,%rdx
or     %rcx,%rdx
movabs $0x40000000000,%rax
add    %rsi,%rax
movabs $0xf80000000000,%rcx
and    %rdi,%rcx
and    %rax,%rcx
lea    -0x1(%rcx),%rax
movabs $0xfc0000000000,%rbx
and    %rax,%rbx
test   %rcx,%rcx
cmove  %rcx,%rbx
or     %rdx,%rbx
and    $0x8102040,%edi
mov    %rsi,%rax
and    %r13,%rax
mov    %rdi,%rcx
shl    $0x7,%rcx
add    %rax,%rcx
movabs $0x1fbf7efc000,%rax
add    %rcx,%rax
bt     $0x29,%rax
jae    11dd <flip_G3+0xcd>
call   1030 <last_bit@plt>
mov    $0xfffffffffffffffe,%rdx
mov    %eax,%ecx
shl    %cl,%rdx
and    %r13,%rdx
or     %rdx,%rbx
movabs $0x202020200,%r13
and    $0x2020202,%r14d
and    %r13,%r15
mov    %r14,%rax
shl    $0x8,%rax
add    %r15,%rax
movabs $0x1fdfdfdfc00,%rcx
add    %rax,%rcx
test   %r12,%rcx
je     1227 <flip_G3+0x117>
mov    %r14,%rdi
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_G3(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
%9 = load i64, i64* %4
%10 = and i64 %9, 1125899906842624
%11 = load i64, i64* %3
%12 = lshr i64 %11, 9
%13 = and i64 %10, %12
store i64 %13, i64* %8
%14 = load i64, i64* %4
%15 = and i64 %14, 562949953421312
%16 = load i64, i64* %3
%17 = lshr i64 %16, 8
%18 = and i64 %15, %17
%19 = load i64, i64* %8
%20 = or i64 %19, %18
store i64 %20, i64* %8
%21 = load i64, i64* %3
%22 = and i64 %21, 272678883688448
store i64 %22, i64* %5
%23 = load i64, i64* %4
%24 = add i64 %23, 4398046511104
%25 = load i64, i64* %5
%26 = and i64 %24, %25
store i64 %26, i64* %7
%27 = load i64, i64* %7
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %2
%30 = load i64, i64* %7
%31 = sub i64 %30, 1
%32 = and i64 %31, 277076930199552
%33 = load i64, i64* %8
%34 = or i64 %33, %32
store i64 %34, i64* %8
br label %35
35: ; preds = %29, %2
%36 = load i64, i64* %3
%37 = and i64 %36, 135274560
store i64 %37, i64* %5
%38 = load i64, i64* %4
%39 = and i64 %38, 17315143680
%40 = or i64 %39, 2181708103680
store i64 %40, i64* %6
%41 = load i64, i64* %5
%42 = shl i64 %41, 7
%43 = load i64, i64* %6
%44 = add i64 %42, %43
%45 = and i64 %44, 2199023255552
store i64 %45, i64* %7
%46 = load i64, i64* %7
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %57
48: ; preds = %35
%49 = load i64, i64* %5
%50 = call i32 @last_bit(i64 %49)
%51 = zext i32 %50 to i64
%52 = shl i64 2, %51
%53 = sub i64 2199023255552, %52
%54 = and i64 %53, 17315143680
%55 = load i64, i64* %8
%56 = or i64 %55, %54
store i64 %56, i64* %8
br label %57
57: ; preds = %48, %35
%58 = load i64, i64* %3
%59 = and i64 %58, 33686018
store i64 %59, i64* %5
%60 = load i64, i64* %4
%61 = and i64 %60, 8623620608
%62 = or i64 %61, 2190399634432
store i64 %62, i64* %6
%63 = load i64, i64* %5
%64 = shl i64 %63, 8
%65 = load i64, i64* %6
%66 = add i64 %64, %65
%67 = and i64 %66, 2199023255552
store i64 %67, i64* %7
%68 = load i64, i64* %7
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %79
70: ; preds = %57
%71 = load i64, i64* %5
%72 = call i32 @last_bit(i64 %71)
%73 = zext i32 %72 to i64
%74 = shl i64 2, %73
%75 = sub i64 2199023255552, %74
%76 = and i64 %75, 8623620608
%77 = load i64, i64* %8
%78 = or i64 %77, %76
store i64 %78, i64* %8
br label %79
79: ; preds = %70, %57
%80 = load i64, i64* %8
ret i64 %80
}

LLVM IR (-O2):
define i64 @flip_G3(i64 %0, i64 %1) {
%3 = and i64 %1, 1125899906842624
%4 = lshr i64 %0, 9
%5 = and i64 %3, %4
%6 = and i64 %1, 562949953421312
%7 = lshr i64 %0, 8
%8 = and i64 %6, %7
%9 = or i64 %5, %8
%10 = and i64 %0, 272678883688448
%11 = add i64 %1, 4398046511104
%12 = and i64 %10, %11
%13 = icmp eq i64 %12, 0
%14 = add nuw nsw i64 %12, 281474976710655
%15 = and i64 %14, 277076930199552
%16 = select i1 %13, i64 0, i64 %15
%17 = or i64 %9, %16
%18 = and i64 %0, 135274560
%19 = and i64 %1, 17315143680
%20 = or i64 %19, 2181708103680
%21 = shl nuw nsw i64 %18, 7
%22 = add nuw nsw i64 %20, %21
%23 = and i64 %22, 2199023255552
%24 = icmp eq i64 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %2
%26 = tail call i32 @last_bit(i64 %18)
%27 = zext i32 %26 to i64
%28 = shl i64 -2, %27
%29 = and i64 %28, 17315143680
%30 = or i64 %29, %17
br label %31
31: ; preds = %25, %2
%32 = phi i64 [ %30, %25 ], [ %17, %2 ]
%33 = and i64 %0, 33686018
%34 = and i64 %1, 8623620608
%35 = or i64 %34, 2190399634432
%36 = shl nuw nsw i64 %33, 8
%37 = add nuw nsw i64 %35, %36
%38 = and i64 %37, 2199023255552
%39 = icmp eq i64 %38, 0
br i1 %39, label %46, label %40
40: ; preds = %31
%41 = tail call i32 @last_bit(i64 %33)
%42 = zext i32 %41 to i64
%43 = shl i64 -2, %42
%44 = and i64 %43, 8623620608
%45 = or i64 %44, %32
br label %46
46: ; preds = %40, %31
%47 = phi i64 [ %45, %40 ], [ %32, %31 ]
ret i64 %47
}