#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_H3(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 & 0X0002000000000000ULL) & (discs_player >> 9);
  flipped |= (discs_opponent & 0X0001000000000000ULL) & (discs_player >> 8);
  my_discs = discs_player & 0X0000FC0000000000ULL;
  r = (discs_opponent + 0X0000020000000000ULL) & my_discs;
  if (r != 0) {
    flipped |= (r - 1) & 0X0000FE0000000000ULL;
  }
  my_discs = discs_player & 0X0000000004081020ULL;
  opp_discs = (discs_opponent & 0X0000000204081000ULL) | 0X000000FDFBF7E000ULL;
  r = ((my_discs << 7) + opp_discs) & 0X0000010000000000ULL;
  if (r != 0) {
    flipped |= (0X0000010000000000ULL - (0X2ULL << last_bit(my_discs))) &
               0X0000000204081000ULL;
  }
  my_discs = discs_player & 0X0000000001010101ULL;
  opp_discs = (discs_opponent & 0X0000000101010100ULL) | 0X000000FEFEFEFE00ULL;
  r = ((my_discs << 8) + opp_discs) & 0X0000010000000000ULL;
  if (r != 0) {
    flipped |= (0X0000010000000000ULL - (0X2ULL << last_bit(my_discs))) &
               0X0000000101010100ULL;
  }
  return flipped;
}


x86 assembly (clang, -O0):
<flip_H3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x2000000000000,%rax
and    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
shr    $0x9,%rcx
and    %rcx,%rax
mov    %rax,-0x30(%rbp)
movabs $0x1000000000000,%rax
and    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
shr    $0x8,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movabs $0xfc0000000000,%rax
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x20000000000,%rax
add    -0x10(%rbp),%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ae <flip_H3+0x9e>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
movabs $0xfe0000000000,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
and    $0x4081020,%rax
mov    %rax,-0x18(%rbp)
movabs $0x204081000,%rax
and    -0x10(%rbp),%rax
movabs $0xfdfbf7e000,%rcx
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x7,%rax
add    -0x20(%rbp),%rax
movabs $0x10000000000,%rcx
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     123d <flip_H3+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 $0x10000000000,%rax
sub    %rcx,%rax
movabs $0x204081000,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
and    $0x1010101,%rax
mov    %rax,-0x18(%rbp)
movabs $0x101010100,%rax
and    -0x10(%rbp),%rax
movabs $0xfefefefe00,%rcx
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x8,%rax
add    -0x20(%rbp),%rax
movabs $0x10000000000,%rcx
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12cc <flip_H3+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 $0x10000000000,%rax
sub    %rcx,%rax
movabs $0x101010100,%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_H3>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
movabs $0x10000000000,%r12
movabs $0x204081000,%r13
mov    %rdi,%rax
shr    $0x9,%rax
and    %rsi,%rax
movabs $0x2000000000000,%rcx
and    %rax,%rcx
movabs $0xffffffffffff,%rax
add    $0x1,%rax
mov    %rdi,%rdx
shr    $0x8,%rdx
and    %rsi,%rdx
and    %rax,%rdx
or     %rcx,%rdx
movabs $0x20000000000,%rax
add    %rsi,%rax
movabs $0xfc0000000000,%rcx
and    %rdi,%rcx
and    %rax,%rcx
lea    -0x1(%rcx),%rax
movabs $0xfe0000000000,%rbx
and    %rax,%rbx
test   %rcx,%rcx
cmove  %rcx,%rbx
or     %rdx,%rbx
and    $0x4081020,%edi
mov    %rsi,%rax
and    %r13,%rax
mov    %rdi,%rcx
shl    $0x7,%rcx
add    %rax,%rcx
movabs $0xfdfbf7e000,%rax
add    %rcx,%rax
bt     $0x28,%rax
jae    11e1 <flip_H3+0xd1>
call   1030 <last_bit@plt>
mov    $0xfffffffffffffffe,%rdx
mov    %eax,%ecx
shl    %cl,%rdx
and    %r13,%rdx
or     %rdx,%rbx
movabs $0x101010100,%r13
and    $0x1010101,%r14d
and    %r13,%r15
mov    %r14,%rax
shl    $0x8,%rax
add    %r15,%rax
movabs $0xfefefefe00,%rcx
add    %rax,%rcx
test   %r12,%rcx
je     122b <flip_H3+0x11b>
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_H3(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, 562949953421312
%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, 281474976710656
%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, 277076930199552
store i64 %22, i64* %5
%23 = load i64, i64* %4
%24 = add i64 %23, 2199023255552
%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, 279275953455104
%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, 67637280
store i64 %37, i64* %5
%38 = load i64, i64* %4
%39 = and i64 %38, 8657571840
%40 = or i64 %39, 1090854051840
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, 1099511627776
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 1099511627776, %52
%54 = and i64 %53, 8657571840
%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, 16843009
store i64 %59, i64* %5
%60 = load i64, i64* %4
%61 = and i64 %60, 4311810304
%62 = or i64 %61, 1095199817216
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, 1099511627776
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 1099511627776, %74
%76 = and i64 %75, 4311810304
%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_H3(i64 %0, i64 %1) {
%3 = and i64 %1, 562949953421312
%4 = lshr i64 %0, 9
%5 = and i64 %3, %4
%6 = and i64 %1, 281474976710656
%7 = lshr i64 %0, 8
%8 = and i64 %6, %7
%9 = or i64 %5, %8
%10 = and i64 %0, 277076930199552
%11 = add i64 %1, 2199023255552
%12 = and i64 %10, %11
%13 = icmp eq i64 %12, 0
%14 = add nuw nsw i64 %12, 281474976710655
%15 = and i64 %14, 279275953455104
%16 = select i1 %13, i64 0, i64 %15
%17 = or i64 %9, %16
%18 = and i64 %0, 67637280
%19 = and i64 %1, 8657571840
%20 = or i64 %19, 1090854051840
%21 = shl nuw nsw i64 %18, 7
%22 = add nuw nsw i64 %20, %21
%23 = and i64 %22, 1099511627776
%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, 8657571840
%30 = or i64 %29, %17
br label %31
31: ; preds = %25, %2
%32 = phi i64 [ %30, %25 ], [ %17, %2 ]
%33 = and i64 %0, 16843009
%34 = and i64 %1, 4311810304
%35 = or i64 %34, 1095199817216
%36 = shl nuw nsw i64 %33, 8
%37 = add nuw nsw i64 %35, %36
%38 = and i64 %37, 1099511627776
%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, 4311810304
%45 = or i64 %44, %32
br label %46
46: ; preds = %40, %31
%47 = phi i64 [ %45, %40 ], [ %32, %31 ]
ret i64 %47
}