#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_A6(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 & 0X0000000000004000ULL) & (discs_player << 9);
  flipped |= (discs_opponent & 0X0000000000008000ULL) & (discs_player << 8);
  my_discs = discs_player & 0X00000000003F0000ULL;
  r = ((my_discs << 1) + discs_opponent) & 0X0000000000800000ULL;
  if (r != 0) {
    flipped |= 0X0000000000800000ULL - (0X2ULL << last_bit(my_discs));
  }
  my_discs = discs_player & 0X0408102000000000ULL;
  opp_discs = (discs_opponent & 0X0008102040000000ULL) | 0X03F7EFDF80000000ULL;
  r = (opp_discs + 0X0000000040000000ULL) & my_discs;
  if (r != 0) {
    flipped |= (r - 1) & 0X0008102040000000ULL;
  }
  my_discs = discs_player & 0X8080808000000000ULL;
  opp_discs = (discs_opponent & 0X0080808080000000ULL) | 0X7F7F7F7F00000000ULL;
  r = (opp_discs + 0X0000000080000000ULL) & my_discs;
  if (r != 0) {
    flipped |= (r - 1) & 0X0080808080000000ULL;
  }
  return flipped;
}


x86 assembly (clang, -O0):
<flip_A6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
and    $0x4000,%rax
mov    -0x8(%rbp),%rcx
shl    $0x9,%rcx
and    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
and    $0x8000,%rax
mov    -0x8(%rbp),%rcx
shl    $0x8,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
and    $0x3f0000,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
add    -0x10(%rbp),%rax
and    $0x800000,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ad <flip_A6+0x9d>
mov    -0x18(%rbp),%rdi
call   1030 <last_bit@plt>
mov    %eax,%eax
mov    %eax,%ecx
mov    $0x2,%eax
shl    %cl,%rax
mov    %rax,%rcx
mov    $0x800000,%eax
sub    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movabs $0x408102000000000,%rax
10 08 04
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x8102040000000,%rax
and    -0x10(%rbp),%rax
movabs $0x3f7efdf80000000,%rcx
ef f7 03
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x40000000,%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1218 <flip_A6+0x108>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
movabs $0x8102040000000,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movabs $0x8080808000000000,%rax
80 80 80
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x80808080000000,%rax
and    -0x10(%rbp),%rax
movabs $0x7f7f7f7f00000000,%rcx
7f 7f 7f
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
movabs $0x80000000,%rax
add    -0x20(%rbp),%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1287 <flip_A6+0x177>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
movabs $0x80808080000000,%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_A6>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %r14d,%eax
shl    $0x9,%eax
and    %r15d,%eax
and    $0x4000,%eax
mov    %r14d,%ebx
shl    $0x8,%ebx
and    %r15d,%ebx
and    $0x8000,%ebx
or     %rax,%rbx
and    $0x3f0000,%edi
lea    (%rsi,%rdi,2),%eax
test   $0x800000,%eax
je     1166 <flip_A6+0x56>
call   1030 <last_bit@plt>
mov    $0xfffffffffffffffe,%rdx
mov    %eax,%ecx
shl    %cl,%rdx
add    $0x800000,%rdx
or     %rdx,%rbx
movabs $0x8102040000000,%rax
mov    %r15,%rcx
and    %rax,%rcx
movabs $0x3f7efdfc0000000,%rdx
ef f7 03
add    %rcx,%rdx
and    %r14,%rdx
movabs $0x408102000000000,%rcx
10 08 04
and    %rdx,%rcx
lea    -0x1(%rcx),%rdx
and    %rax,%rdx
test   %rcx,%rcx
cmove  %rcx,%rdx
movabs $0x80808080000000,%rcx
and    %rcx,%r15
movabs $0x7f7f7f7f80000000,%rax
7f 7f 7f
add    %r15,%rax
and    %r14,%rax
movabs $0x8080808000000000,%rsi
80 80 80
and    %rax,%rsi
lea    -0x1(%rsi),%rax
and    %rcx,%rax
test   %rsi,%rsi
cmove  %rsi,%rax
or     %rdx,%rax
or     %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @flip_A6(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, 16384
%11 = load i64, i64* %3
%12 = shl i64 %11, 9
%13 = and i64 %10, %12
store i64 %13, i64* %8
%14 = load i64, i64* %4
%15 = and i64 %14, 32768
%16 = load i64, i64* %3
%17 = shl 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, 4128768
store i64 %22, i64* %5
%23 = load i64, i64* %5
%24 = shl i64 %23, 1
%25 = load i64, i64* %4
%26 = add i64 %24, %25
%27 = and i64 %26, 8388608
store i64 %27, i64* %7
%28 = load i64, i64* %7
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %2
%31 = load i64, i64* %5
%32 = call i32 @last_bit(i64 %31)
%33 = zext i32 %32 to i64
%34 = shl i64 2, %33
%35 = sub i64 8388608, %34
%36 = load i64, i64* %8
%37 = or i64 %36, %35
store i64 %37, i64* %8
br label %38
38: ; preds = %30, %2
%39 = load i64, i64* %3
%40 = and i64 %39, 290499905590394880
store i64 %40, i64* %5
%41 = load i64, i64* %4
%42 = and i64 %41, 2269530512424960
%43 = or i64 %42, 285960844565544960
store i64 %43, i64* %6
%44 = load i64, i64* %6
%45 = add i64 %44, 1073741824
%46 = load i64, i64* %5
%47 = and i64 %45, %46
store i64 %47, i64* %7
%48 = load i64, i64* %7
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %38
%51 = load i64, i64* %7
%52 = sub i64 %51, 1
%53 = and i64 %52, 2269530512424960
%54 = load i64, i64* %8
%55 = or i64 %54, %53
store i64 %55, i64* %8
br label %56
56: ; preds = %50, %38
%57 = load i64, i64* %3
%58 = and i64 %57, -9187201952591642624
store i64 %58, i64* %5
%59 = load i64, i64* %4
%60 = and i64 %59, 36170086410616832
%61 = or i64 %60, 9187201948296675328
store i64 %61, i64* %6
%62 = load i64, i64* %6
%63 = add i64 %62, 2147483648
%64 = load i64, i64* %5
%65 = and i64 %63, %64
store i64 %65, i64* %7
%66 = load i64, i64* %7
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %74
68: ; preds = %56
%69 = load i64, i64* %7
%70 = sub i64 %69, 1
%71 = and i64 %70, 36170086410616832
%72 = load i64, i64* %8
%73 = or i64 %72, %71
store i64 %73, i64* %8
br label %74
74: ; preds = %68, %56
%75 = load i64, i64* %8
ret i64 %75
}

LLVM IR (-O2):
define i64 @flip_A6(i64 %0, i64 %1) {
%3 = and i64 %1, 16384
%4 = shl i64 %0, 9
%5 = and i64 %3, %4
%6 = and i64 %1, 32768
%7 = shl i64 %0, 8
%8 = and i64 %6, %7
%9 = or i64 %5, %8
%10 = and i64 %0, 4128768
%11 = shl nuw nsw i64 %10, 1
%12 = add i64 %11, %1
%13 = and i64 %12, 8388608
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %2
%16 = tail call i32 @last_bit(i64 %10)
%17 = zext i32 %16 to i64
%18 = shl i64 -2, %17
%19 = add i64 %18, 8388608
%20 = or i64 %19, %9
br label %21
21: ; preds = %15, %2
%22 = phi i64 [ %20, %15 ], [ %9, %2 ]
%23 = and i64 %0, 290499905590394880
%24 = and i64 %1, 2269530512424960
%25 = add nuw nsw i64 %24, 285960845639286784
%26 = and i64 %23, %25
%27 = icmp eq i64 %26, 0
%28 = add nuw nsw i64 %26, 4503599627370495
%29 = and i64 %28, 2269530512424960
%30 = select i1 %27, i64 0, i64 %29
%31 = and i64 %0, -9187201952591642624
%32 = and i64 %1, 36170086410616832
%33 = add nuw i64 %32, 9187201950444158976
%34 = and i64 %31, %33
%35 = icmp eq i64 %34, 0
%36 = add nuw nsw i64 %34, 72057594037927935
%37 = and i64 %36, 36170086410616832
%38 = select i1 %35, i64 0, i64 %37
%39 = or i64 %38, %30
%40 = or i64 %39, %22
ret i64 %40
}