#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_A7(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 & 0X0204081020000000ULL;
  opp_discs = (discs_opponent & 0X0004081020400000ULL) | 0X01FBF7EFDF800000ULL;
  r = (opp_discs + 0X0000000000400000ULL) & my_discs;
  if (r != 0) {
    flipped |= (r - 1) & 0X0004081020400000ULL;
  }
  my_discs = discs_player & 0X8080808080000000ULL;
  opp_discs = (discs_opponent & 0X0080808080800000ULL) | 0X7F7F7F7F7F000000ULL;
  r = (opp_discs + 0X0000000000800000ULL) & my_discs;
  if (r != 0) {
    flipped |= (r - 1) & 0X0080808080800000ULL;
  }
  my_discs = discs_player & 0X0000000000003F00ULL;
  r = ((my_discs << 1) + discs_opponent) & 0X0000000000008000ULL;
  if (r != 0) {
    flipped |= 0X0000000000008000ULL - (0X2ULL << last_bit(my_discs));
  }
  return flipped;
}


x86 assembly (clang, -O0):
<flip_A7>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movabs $0x204081020000000,%rax
08 04 02
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    -0x20(%rbp),%rax
add    $0x400000,%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1193 <flip_A7+0x83>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
movabs $0x4081020400000,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movabs $0x8080808080000000,%rax
80 80 80
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x80808080800000,%rax
and    -0x10(%rbp),%rax
movabs $0x7f7f7f7f7f000000,%rcx
7f 7f 7f
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x800000,%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11fe <flip_A7+0xee>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
movabs $0x80808080800000,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
and    $0x3f00,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
add    -0x10(%rbp),%rax
and    $0x8000,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1255 <flip_A7+0x145>
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    $0x8000,%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_A7>:
push   %rbx
movabs $0x4081020400000,%rax
mov    %rsi,%rcx
and    %rax,%rcx
movabs $0x1fbf7efdfc00000,%rdx
f7 fb 01
add    %rcx,%rdx
movabs $0x204081020000000,%rcx
08 04 02
and    %rdi,%rcx
and    %rdx,%rcx
lea    -0x1(%rcx),%rdx
and    %rax,%rdx
test   %rcx,%rcx
cmove  %rcx,%rdx
movabs $0x80808080800000,%rax
mov    %rsi,%rcx
and    %rax,%rcx
movabs $0x7f7f7f7f7f800000,%rbx
7f 7f 7f
add    %rcx,%rbx
movabs $0x8080808080000000,%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    $0x3f00,%edi
lea    (%rsi,%rdi,2),%eax
test   $0x8000,%eax
je     11b5 <flip_A7+0xa5>
call   1030 <last_bit@plt>
mov    $0xfffffffffffffffe,%rdx
mov    %eax,%ecx
shl    %cl,%rdx
add    $0x8000,%rdx
or     %rdx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @flip_A7(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, 145249953332068352
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* %6
%15 = add i64 %14, 4194304
%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, 1134765260406784
%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, -9187201950444158976
store i64 %28, i64* %5
%29 = load i64, i64* %4
%30 = and i64 %29, 36170086419005440
%31 = or i64 %30, 9187201950427381760
store i64 %31, i64* %6
%32 = load i64, i64* %6
%33 = add i64 %32, 8388608
%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, 36170086419005440
%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, 16128
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, 32768
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 32768, %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_A7(i64 %0, i64 %1) {
%3 = and i64 %0, 145249953332068352
%4 = and i64 %1, 1134765260406784
%5 = add nuw nsw i64 %4, 142980422815449088
%6 = and i64 %3, %5
%7 = icmp eq i64 %6, 0
%8 = add nuw nsw i64 %6, 2251799813685247
%9 = and i64 %8, 1134765260406784
%10 = select i1 %7, i64 0, i64 %9
%11 = and i64 %0, -9187201950444158976
%12 = and i64 %1, 36170086419005440
%13 = add nuw i64 %12, 9187201950435770368
%14 = and i64 %11, %13
%15 = icmp eq i64 %14, 0
%16 = add nuw nsw i64 %14, 72057594037927935
%17 = and i64 %16, 36170086419005440
%18 = select i1 %15, i64 0, i64 %17
%19 = or i64 %10, %18
%20 = and i64 %0, 16128
%21 = shl nuw nsw i64 %20, 1
%22 = add i64 %21, %1
%23 = and i64 %22, 32768
%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, 32768
%30 = or i64 %29, %19
br label %31
31: ; preds = %25, %2
%32 = phi i64 [ %30, %25 ], [ %19, %2 ]
ret i64 %32
}