#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_B8(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 & 0X0001020408100000ULL;
  opp_discs = (discs_opponent & 0X0000020408102000ULL) | 0X0000FDFBF7EFC000ULL;
  r = (opp_discs + 0X0000000000002000ULL) & my_discs;
  if (r != 0) {
    flipped |= (r - 1) & 0X0000020408102000ULL;
  }
  my_discs = discs_player & 0X4040404040400000ULL;
  opp_discs = (discs_opponent & 0X0040404040404000ULL) | 0X3FBFBFBFBFBF8000ULL;
  r = (opp_discs + 0X0000000000004000ULL) & my_discs;
  if (r != 0) {
    flipped |= (r - 1) & 0X0040404040404000ULL;
  }
  my_discs = discs_player & 0X000000000000001FULL;
  r = ((my_discs << 1) + discs_opponent) & 0X0000000000000040ULL;
  if (r != 0) {
    flipped |= 0X0000000000000040ULL - (0X2ULL << last_bit(my_discs));
  }
  return flipped;
}


x86 assembly (clang, -O0):
<flip_B8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movabs $0x1020408100000,%rax
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x20408102000,%rax
and    -0x10(%rbp),%rax
movabs $0xfdfbf7efc000,%rcx
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x2000,%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1193 <flip_B8+0x83>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
movabs $0x20408102000,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movabs $0x4040404040400000,%rax
40 40 40
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x40404040404000,%rax
and    -0x10(%rbp),%rax
movabs $0x3fbfbfbfbfbf8000,%rcx
bf bf 3f
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     11fe <flip_B8+0xee>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
movabs $0x40404040404000,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
and    $0x1f,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
add    -0x10(%rbp),%rax
and    $0x40,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1251 <flip_B8+0x141>
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    $0x40,%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_B8>:
push   %rbx
movabs $0x20408102000,%rax
mov    %rsi,%rcx
and    %rax,%rcx
movabs $0xfdfbf7efe000,%rdx
add    %rcx,%rdx
movabs $0x1020408100000,%rcx
and    %rdi,%rcx
and    %rdx,%rcx
lea    -0x1(%rcx),%rdx
and    %rax,%rdx
test   %rcx,%rcx
cmove  %rcx,%rdx
movabs $0x40404040404000,%rax
mov    %rsi,%rcx
and    %rax,%rcx
movabs $0x3fbfbfbfbfbfc000,%rbx
bf bf 3f
add    %rcx,%rbx
movabs $0x4040404040400000,%rcx
40 40 40
and    %rdi,%rcx
and    %rbx,%rcx
lea    -0x1(%rcx),%rbx
and    %rax,%rbx
test   %rcx,%rcx
cmove  %rcx,%rbx
or     %rdx,%rbx
and    $0x1f,%edi
lea    (%rsi,%rdi,2),%eax
test   $0x40,%al
je     11ac <flip_B8+0x9c>
call   1030 <last_bit@plt>
mov    $0xfffffffffffffffe,%rdx
mov    %eax,%ecx
shl    %cl,%rdx
add    $0x40,%rdx
or     %rdx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @flip_B8(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, 283691315101696
store i64 %10, i64* %5
%11 = load i64, i64* %4
%12 = and i64 %11, 2216338399232
%13 = or i64 %12, 279258638303232
store i64 %13, i64* %6
%14 = load i64, i64* %6
%15 = add i64 %14, 8192
%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, 2216338399232
%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, 4629771061636890624
store i64 %28, i64* %5
%29 = load i64, i64* %4
%30 = and i64 %29, 18085043209519104
%31 = or i64 %30, 4593600975217852416
store i64 %31, i64* %6
%32 = load i64, i64* %6
%33 = add i64 %32, 16384
%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, 18085043209519104
%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, 31
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, 64
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 64, %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_B8(i64 %0, i64 %1) {
%3 = and i64 %0, 283691315101696
%4 = and i64 %1, 2216338399232
%5 = add nuw nsw i64 %4, 279258638311424
%6 = and i64 %3, %5
%7 = icmp eq i64 %6, 0
%8 = add nuw nsw i64 %6, 4398046511103
%9 = and i64 %8, 2216338399232
%10 = select i1 %7, i64 0, i64 %9
%11 = and i64 %0, 4629771061636890624
%12 = and i64 %1, 18085043209519104
%13 = add nuw nsw i64 %12, 4593600975217868800
%14 = and i64 %11, %13
%15 = icmp eq i64 %14, 0
%16 = add nuw nsw i64 %14, 36028797018963967
%17 = and i64 %16, 18085043209519104
%18 = select i1 %15, i64 0, i64 %17
%19 = or i64 %10, %18
%20 = and i64 %0, 31
%21 = shl nuw nsw i64 %20, 1
%22 = add i64 %21, %1
%23 = and i64 %22, 64
%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, 64
%30 = or i64 %29, %19
br label %31
31: ; preds = %25, %2
%32 = phi i64 [ %30, %25 ], [ %19, %2 ]
ret i64 %32
}