#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_A3(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 & 0X0080000000000000ULL) & (discs_player >> 8);
  flipped |= (discs_opponent & 0X0040000000000000ULL) & (discs_player >> 7);
  my_discs = discs_player & 0X00003F0000000000ULL;
  r = ((my_discs << 1) + discs_opponent) & 0X0000800000000000ULL;
  if (r != 0) {
    flipped |= 0X0000800000000000ULL - (0X2ULL << last_bit(my_discs));
  }
  my_discs = discs_player & 0X0000000020100804ULL;
  opp_discs = (discs_opponent & 0X0000004020100800ULL) | 0X00007FBFDFEFF000ULL;
  r = ((my_discs << 9) + opp_discs) & 0X0000800000000000ULL;
  if (r != 0) {
    flipped |= (0X0000800000000000ULL - (0X2ULL << last_bit(my_discs))) &
               0X0000004020100800ULL;
  }
  my_discs = discs_player & 0X0000000080808080ULL;
  opp_discs = (discs_opponent & 0X0000008080808000ULL) | 0X00007F7F7F7F0000ULL;
  r = ((my_discs << 8) + opp_discs) & 0X0000800000000000ULL;
  if (r != 0) {
    flipped |= (0X0000800000000000ULL - (0X2ULL << last_bit(my_discs))) &
               0X0000008080808000ULL;
  }
  return flipped;
}


x86 assembly (clang, -O0):
<flip_A3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x80000000000000,%rax
and    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
shr    $0x8,%rcx
and    %rcx,%rax
mov    %rax,-0x30(%rbp)
movabs $0x40000000000000,%rax
and    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
shr    $0x7,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movabs $0x3f0000000000,%rax
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
add    -0x10(%rbp),%rax
movabs $0x800000000000,%rcx
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c5 <flip_A3+0xb5>
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 $0x800000000000,%rax
sub    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
and    $0x20100804,%rax
mov    %rax,-0x18(%rbp)
movabs $0x4020100800,%rax
and    -0x10(%rbp),%rax
movabs $0x7fbfdfeff000,%rcx
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x9,%rax
add    -0x20(%rbp),%rax
movabs $0x800000000000,%rcx
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1254 <flip_A3+0x144>
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 $0x800000000000,%rax
sub    %rcx,%rax
movabs $0x4020100800,%rcx
and    %rcx,%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movabs $0x80808080,%rax
and    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x8080808000,%rax
and    -0x10(%rbp),%rax
movabs $0x7f7f7f7f0000,%rcx
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x8,%rax
add    -0x20(%rbp),%rax
movabs $0x800000000000,%rcx
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12e7 <flip_A3+0x1d7>
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 $0x800000000000,%rax
sub    %rcx,%rax
movabs $0x8080808000,%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_A3>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
movabs $0x800000000000,%r12
mov    %rdi,%rax
shr    $0x8,%rax
and    %rsi,%rax
movabs $0x80000000000000,%rcx
and    %rax,%rcx
mov    %rdi,%rax
shr    $0x7,%rax
and    %rsi,%rax
movabs $0x40000000000000,%rbx
and    %rax,%rbx
or     %rcx,%rbx
movabs $0x3f0000000000,%rdi
and    %r14,%rdi
lea    (%rsi,%rdi,2),%rax
bt     $0x2f,%rax
jae    1189 <flip_A3+0x79>
call   1030 <last_bit@plt>
mov    $0xfffffffffffffffe,%rdx
mov    %eax,%ecx
shl    %cl,%rdx
add    %r12,%rdx
or     %rdx,%rbx
movabs $0x4020100800,%r13
mov    %r14d,%edi
and    $0x20100804,%edi
mov    %r15,%rax
and    %r13,%rax
mov    %rdi,%rcx
shl    $0x9,%rcx
add    %rax,%rcx
movabs $0x7fbfdfeff000,%rax
add    %rcx,%rax
test   %r12,%rax
je     11d5 <flip_A3+0xc5>
call   1030 <last_bit@plt>
mov    $0xfffffffffffffffe,%rdx
mov    %eax,%ecx
shl    %cl,%rdx
and    %r13,%rdx
or     %rdx,%rbx
movabs $0x8080808000,%r13
and    $0x80808080,%r14d
and    %r13,%r15
mov    %r14,%rax
shl    $0x8,%rax
add    %r15,%rax
movabs $0x7f7f7f7f0000,%rcx
add    %rax,%rcx
test   %r12,%rcx
je     121f <flip_A3+0x10f>
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_A3(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, 36028797018963968
%11 = load i64, i64* %3
%12 = lshr i64 %11, 8
%13 = and i64 %10, %12
store i64 %13, i64* %8
%14 = load i64, i64* %4
%15 = and i64 %14, 18014398509481984
%16 = load i64, i64* %3
%17 = lshr i64 %16, 7
%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, 69269232549888
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, 140737488355328
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 140737488355328, %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, 537921540
store i64 %40, i64* %5
%41 = load i64, i64* %4
%42 = and i64 %41, 275415828480
%43 = or i64 %42, 140462072524800
store i64 %43, i64* %6
%44 = load i64, i64* %5
%45 = shl i64 %44, 9
%46 = load i64, i64* %6
%47 = add i64 %45, %46
%48 = and i64 %47, 140737488355328
store i64 %48, i64* %7
%49 = load i64, i64* %7
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %60
51: ; preds = %38
%52 = load i64, i64* %5
%53 = call i32 @last_bit(i64 %52)
%54 = zext i32 %53 to i64
%55 = shl i64 2, %54
%56 = sub i64 140737488355328, %55
%57 = and i64 %56, 275415828480
%58 = load i64, i64* %8
%59 = or i64 %58, %57
store i64 %59, i64* %8
br label %60
60: ; preds = %51, %38
%61 = load i64, i64* %3
%62 = and i64 %61, 2155905152
store i64 %62, i64* %5
%63 = load i64, i64* %4
%64 = and i64 %63, 551911718912
%65 = or i64 %64, 140185576603648
store i64 %65, i64* %6
%66 = load i64, i64* %5
%67 = shl i64 %66, 8
%68 = load i64, i64* %6
%69 = add i64 %67, %68
%70 = and i64 %69, 140737488355328
store i64 %70, i64* %7
%71 = load i64, i64* %7
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %82
73: ; preds = %60
%74 = load i64, i64* %5
%75 = call i32 @last_bit(i64 %74)
%76 = zext i32 %75 to i64
%77 = shl i64 2, %76
%78 = sub i64 140737488355328, %77
%79 = and i64 %78, 551911718912
%80 = load i64, i64* %8
%81 = or i64 %80, %79
store i64 %81, i64* %8
br label %82
82: ; preds = %73, %60
%83 = load i64, i64* %8
ret i64 %83
}

LLVM IR (-O2):
define i64 @flip_A3(i64 %0, i64 %1) {
%3 = and i64 %1, 36028797018963968
%4 = lshr i64 %0, 8
%5 = and i64 %3, %4
%6 = and i64 %1, 18014398509481984
%7 = lshr i64 %0, 7
%8 = and i64 %6, %7
%9 = or i64 %5, %8
%10 = and i64 %0, 69269232549888
%11 = shl nuw nsw i64 %10, 1
%12 = add i64 %11, %1
%13 = and i64 %12, 140737488355328
%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, 140737488355328
%20 = or i64 %19, %9
br label %21
21: ; preds = %15, %2
%22 = phi i64 [ %20, %15 ], [ %9, %2 ]
%23 = and i64 %0, 537921540
%24 = and i64 %1, 275415828480
%25 = or i64 %24, 140462072524800
%26 = shl nuw nsw i64 %23, 9
%27 = add nuw nsw i64 %25, %26
%28 = and i64 %27, 140737488355328
%29 = icmp eq i64 %28, 0
br i1 %29, label %36, label %30
30: ; preds = %21
%31 = tail call i32 @last_bit(i64 %23)
%32 = zext i32 %31 to i64
%33 = shl i64 -2, %32
%34 = and i64 %33, 275415828480
%35 = or i64 %34, %22
br label %36
36: ; preds = %30, %21
%37 = phi i64 [ %35, %30 ], [ %22, %21 ]
%38 = and i64 %0, 2155905152
%39 = and i64 %1, 551911718912
%40 = or i64 %39, 140185576603648
%41 = shl nuw nsw i64 %38, 8
%42 = add nuw nsw i64 %40, %41
%43 = and i64 %42, 140737488355328
%44 = icmp eq i64 %43, 0
br i1 %44, label %51, label %45
45: ; preds = %36
%46 = tail call i32 @last_bit(i64 %38)
%47 = zext i32 %46 to i64
%48 = shl i64 -2, %47
%49 = and i64 %48, 551911718912
%50 = or i64 %49, %37
br label %51
51: ; preds = %45, %36
%52 = phi i64 [ %50, %45 ], [ %37, %36 ]
ret i64 %52
}