#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_A8(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 & 0X0102040810200000ULL;
  opp_discs = (discs_opponent & 0X0002040810204000ULL) | 0X00FDFBF7EFDF8000ULL;
  r = (opp_discs + 0X0000000000004000ULL) & my_discs;
  if (r != 0) {
    flipped |= (r - 1) & 0X0002040810204000ULL;
  }
  my_discs = discs_player & 0X8080808080800000ULL;
  opp_discs = (discs_opponent & 0X0080808080808000ULL) | 0X7F7F7F7F7F7F0000ULL;
  r = (opp_discs + 0X0000000000008000ULL) & my_discs;
  if (r != 0) {
    flipped |= (r - 1) & 0X0080808080808000ULL;
  }
  my_discs = discs_player & 0X000000000000003FULL;
  r = ((my_discs << 1) + discs_opponent) & 0X0000000000000080ULL;
  if (r != 0) {
    flipped |= 0X0000000000000080ULL - (0X2ULL << last_bit(my_discs));
  }
  return flipped;
}


x86 assembly (clang, -O0):
<flip_A8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movabs $0x102040810200000,%rax
04 02 01
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x2040810204000,%rax
and    -0x10(%rbp),%rax
movabs $0xfdfbf7efdf8000,%rcx
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x4000,%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1193 <flip_A8+0x83>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
movabs $0x2040810204000,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movabs $0x8080808080800000,%rax
80 80 80
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x80808080808000,%rax
and    -0x10(%rbp),%rax
movabs $0x7f7f7f7f7f7f0000,%rcx
7f 7f 7f
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8000,%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11fe <flip_A8+0xee>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
movabs $0x80808080808000,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
and    $0x3f,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
add    -0x10(%rbp),%rax
and    $0x80,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1253 <flip_A8+0x143>
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    $0x80,%eax
sub    %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_A8>:
push   %rbx
movabs $0x2040810204000,%rax
mov    %rsi,%rcx
and    %rax,%rcx
movabs $0xfdfbf7efdfc000,%rdx
add    %rcx,%rdx
movabs $0x102040810200000,%rcx
04 02 01
and    %rdi,%rcx
and    %rdx,%rcx
lea    -0x1(%rcx),%rdx
and    %rax,%rdx
test   %rcx,%rcx
cmove  %rcx,%rdx
movabs $0x80808080808000,%rax
mov    %rsi,%rcx
and    %rax,%rcx
movabs $0x7f7f7f7f7f7f8000,%rbx
7f 7f 7f
add    %rcx,%rbx
movabs $0x8080808080800000,%rcx
80 80 80
and    %rdi,%rcx
and    %rbx,%rcx
lea    -0x1(%rcx),%rbx
and    %rax,%rbx
test   %rcx,%rcx
cmove  %rcx,%rbx
or     %rdx,%rbx
and    $0x3f,%edi
lea    (%rsi,%rdi,2),%eax
test   $0x80,%al
je     11ac <flip_A8+0x9c>
call   1030 <last_bit@plt>
mov    $0xfffffffffffffffe,%rdx
mov    %eax,%ecx
shl    %cl,%rdx
sub    $0xffffffffffffff80,%rdx
or     %rdx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @flip_A8(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, 72624976668131328
store i64 %10, i64* %5
%11 = load i64, i64* %4
%12 = and i64 %11, 567382630219776
%13 = or i64 %12, 71490211407691776
store i64 %13, i64* %6
%14 = load i64, i64* %6
%15 = add i64 %14, 16384
%16 = load i64, i64* %5
%17 = and i64 %15, %16
store i64 %17, i64* %7
%18 = load i64, i64* %7
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %2
%21 = load i64, i64* %7
%22 = sub i64 %21, 1
%23 = and i64 %22, 567382630219776
%24 = load i64, i64* %8
%25 = or i64 %24, %23
store i64 %25, i64* %8
br label %26
26: ; preds = %20, %2
%27 = load i64, i64* %3
%28 = and i64 %27, -9187201950435770368
store i64 %28, i64* %5
%29 = load i64, i64* %4
%30 = and i64 %29, 36170086419038208
%31 = or i64 %30, 9187201950435704832
store i64 %31, i64* %6
%32 = load i64, i64* %6
%33 = add i64 %32, 32768
%34 = load i64, i64* %5
%35 = and i64 %33, %34
store i64 %35, i64* %7
%36 = load i64, i64* %7
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %26
%39 = load i64, i64* %7
%40 = sub i64 %39, 1
%41 = and i64 %40, 36170086419038208
%42 = load i64, i64* %8
%43 = or i64 %42, %41
store i64 %43, i64* %8
br label %44
44: ; preds = %38, %26
%45 = load i64, i64* %3
%46 = and i64 %45, 63
store i64 %46, i64* %5
%47 = load i64, i64* %5
%48 = shl i64 %47, 1
%49 = load i64, i64* %4
%50 = add i64 %48, %49
%51 = and i64 %50, 128
store i64 %51, i64* %7
%52 = load i64, i64* %7
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %62
54: ; preds = %44
%55 = load i64, i64* %5
%56 = call i32 @last_bit(i64 %55)
%57 = zext i32 %56 to i64
%58 = shl i64 2, %57
%59 = sub i64 128, %58
%60 = load i64, i64* %8
%61 = or i64 %60, %59
store i64 %61, i64* %8
br label %62
62: ; preds = %54, %44
%63 = load i64, i64* %8
ret i64 %63
}

LLVM IR (-O2):
define i64 @flip_A8(i64 %0, i64 %1) {
%3 = and i64 %0, 72624976668131328
%4 = and i64 %1, 567382630219776
%5 = add nuw nsw i64 %4, 71490211407708160
%6 = and i64 %3, %5
%7 = icmp eq i64 %6, 0
%8 = add nuw nsw i64 %6, 1125899906842623
%9 = and i64 %8, 567382630219776
%10 = select i1 %7, i64 0, i64 %9
%11 = and i64 %0, -9187201950435770368
%12 = and i64 %1, 36170086419038208
%13 = add nuw i64 %12, 9187201950435737600
%14 = and i64 %11, %13
%15 = icmp eq i64 %14, 0
%16 = add nuw nsw i64 %14, 72057594037927935
%17 = and i64 %16, 36170086419038208
%18 = select i1 %15, i64 0, i64 %17
%19 = or i64 %10, %18
%20 = and i64 %0, 63
%21 = shl nuw nsw i64 %20, 1
%22 = add i64 %21, %1
%23 = and i64 %22, 128
%24 = icmp eq i64 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %2
%26 = tail call i32 @last_bit(i64 %20)
%27 = zext i32 %26 to i64
%28 = shl i64 -2, %27
%29 = add i64 %28, 128
%30 = or i64 %29, %19
br label %31
31: ; preds = %25, %2
%32 = phi i64 [ %30, %25 ], [ %19, %2 ]
ret i64 %32
}