unsigned long long flip_A6(const unsigned long long P,
                           const unsigned long long O) {
  unsigned long long flipped, outflank_v, outflank_h, outflank_d7;
  outflank_v =
      (0x8000000000000000ULL >>
       __builtin_clzll((O & 0x0000000101010100ULL) ^ 0x0000000101010101ULL)) &
      P;
  flipped = (-outflank_v * 2) & 0x0000000101010100ULL;
  outflank_h = ((O & 0x00007e0000000000ULL) + 0x0000020000000000ULL) & P;
  flipped |= (outflank_h - (outflank_h >> 8)) & 0x00007e0000000000ULL;
  outflank_d7 =
      (0x8000000000000000ULL >>
       __builtin_clzll((O & 0x0000000204081000ULL) ^ 0x0000000204081020ULL)) &
      P;
  flipped |= (-outflank_d7 * 2) & 0x0000000204081000ULL;
  flipped |= (((P >> 8) & 0x0001000000000000ULL) |
              ((P >> 9) & 0x0002000000000000ULL)) &
             O;
  return flipped;
}


x86 assembly (clang, -O0):
<flip_A6>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x101010100,%rax
and    -0x10(%rbp),%rax
movabs $0x101010101,%rcx
xor    %rcx,%rax
bsr    %rax,%rax
xor    $0x3f,%rax
mov    %eax,%eax
mov    %eax,%ecx
movabs $0x8000000000000000,%rax
shr    %cl,%rax
and    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
sub    -0x20(%rbp),%rax
shl    $0x1,%rax
movabs $0x101010100,%rcx
and    %rcx,%rax
mov    %rax,-0x18(%rbp)
movabs $0x7e0000000000,%rax
and    -0x10(%rbp),%rax
movabs $0x20000000000,%rcx
add    %rcx,%rax
and    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x28(%rbp),%rcx
shr    $0x8,%rcx
sub    %rcx,%rax
movabs $0x7e0000000000,%rcx
and    %rcx,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x204081000,%rax
and    -0x10(%rbp),%rax
movabs $0x204081020,%rcx
xor    %rcx,%rax
bsr    %rax,%rax
xor    $0x3f,%rax
mov    %eax,%eax
mov    %eax,%ecx
movabs $0x8000000000000000,%rax
shr    %cl,%rax
and    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
sub    -0x30(%rbp),%rax
shl    $0x1,%rax
movabs $0x204081000,%rcx
and    %rcx,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x8,%rax
movabs $0x1000000000000,%rcx
and    %rcx,%rax
mov    -0x8(%rbp),%rcx
shr    $0x9,%rcx
movabs $0x2000000000000,%rdx
and    %rdx,%rcx
or     %rcx,%rax
and    -0x10(%rbp),%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<flip_A6>:
movabs $0x101010100,%rax
mov    %rsi,%rcx
and    %rax,%rcx
lea    0x1(%rax),%rdx
xor    %rcx,%rdx
bsr    %rdx,%rcx
xor    $0x3f,%ecx
movabs $0x8000000000000000,%r9
mov    %r9,%rdx
shr    %cl,%rdx
mov    %edi,%r8d
and    %edx,%r8d
add    %r8,%r8
neg    %r8
and    %rax,%r8
movabs $0x7e0000000000,%r10
mov    %rsi,%rcx
and    %r10,%rcx
movabs $0x20000000000,%rdx
add    %rcx,%rdx
and    %rdi,%rdx
mov    %rdx,%rcx
shr    $0x8,%rcx
sub    %rcx,%rdx
movabs $0x204081000,%r11
mov    %rsi,%rcx
and    %r11,%rcx
lea    0x20(%r11),%rax
xor    %rcx,%rax
bsr    %rax,%rcx
xor    $0x3f,%ecx
shr    %cl,%r9
and    %r10,%rdx
and    %rdi,%r9
add    %r9,%r9
neg    %r9
and    %r11,%r9
mov    %rdi,%rax
shr    $0x8,%rax
movabs $0x1000000000000,%rcx
and    %rax,%rcx
shr    $0x9,%rdi
movabs $0x2000000000000,%rax
and    %rdi,%rax
or     %rcx,%rax
and    %rsi,%rax
or     %rdx,%rax
or     %r8,%rax
or     %r9,%rax
ret

LLVM IR (-O0):
define i64 @flip_A6(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, 4311810304
%11 = xor i64 %10, 4311810305
%12 = call i64 @llvm.ctlz.i64(i64 %11, i1 true)
%13 = trunc i64 %12 to i32
%14 = zext i32 %13 to i64
%15 = lshr i64 -9223372036854775808, %14
%16 = load i64, i64* %3
%17 = and i64 %15, %16
store i64 %17, i64* %6
%18 = load i64, i64* %6
%19 = sub i64 0, %18
%20 = mul i64 %19, 2
%21 = and i64 %20, 4311810304
store i64 %21, i64* %5
%22 = load i64, i64* %4
%23 = and i64 %22, 138538465099776
%24 = add i64 %23, 2199023255552
%25 = load i64, i64* %3
%26 = and i64 %24, %25
store i64 %26, i64* %7
%27 = load i64, i64* %7
%28 = load i64, i64* %7
%29 = lshr i64 %28, 8
%30 = sub i64 %27, %29
%31 = and i64 %30, 138538465099776
%32 = load i64, i64* %5
%33 = or i64 %32, %31
store i64 %33, i64* %5
%34 = load i64, i64* %4
%35 = and i64 %34, 8657571840
%36 = xor i64 %35, 8657571872
%37 = call i64 @llvm.ctlz.i64(i64 %36, i1 true)
%38 = trunc i64 %37 to i32
%39 = zext i32 %38 to i64
%40 = lshr i64 -9223372036854775808, %39
%41 = load i64, i64* %3
%42 = and i64 %40, %41
store i64 %42, i64* %8
%43 = load i64, i64* %8
%44 = sub i64 0, %43
%45 = mul i64 %44, 2
%46 = and i64 %45, 8657571840
%47 = load i64, i64* %5
%48 = or i64 %47, %46
store i64 %48, i64* %5
%49 = load i64, i64* %3
%50 = lshr i64 %49, 8
%51 = and i64 %50, 281474976710656
%52 = load i64, i64* %3
%53 = lshr i64 %52, 9
%54 = and i64 %53, 562949953421312
%55 = or i64 %51, %54
%56 = load i64, i64* %4
%57 = and i64 %55, %56
%58 = load i64, i64* %5
%59 = or i64 %58, %57
store i64 %59, i64* %5
%60 = load i64, i64* %5
ret i64 %60
}

LLVM IR (-O2):
define i64 @flip_A6(i64 %0, i64 %1) {
%3 = and i64 %1, 4311810304
%4 = xor i64 %3, 4311810305
%5 = tail call i64 @llvm.ctlz.i64(i64 %4, i1 true)
%6 = lshr i64 -9223372036854775808, %5
%7 = and i64 %6, %0
%8 = mul nsw i64 %7, -2
%9 = and i64 %8, 4311810304
%10 = and i64 %1, 138538465099776
%11 = add nuw nsw i64 %10, 2199023255552
%12 = and i64 %11, %0
%13 = lshr exact i64 %12, 8
%14 = sub nsw i64 %12, %13
%15 = and i64 %14, 138538465099776
%16 = and i64 %1, 8657571840
%17 = xor i64 %16, 8657571872
%18 = tail call i64 @llvm.ctlz.i64(i64 %17, i1 true)
%19 = lshr i64 -9223372036854775808, %18
%20 = and i64 %19, %0
%21 = mul nsw i64 %20, -2
%22 = and i64 %21, 8657571840
%23 = lshr i64 %0, 8
%24 = and i64 %23, 281474976710656
%25 = lshr i64 %0, 9
%26 = and i64 %25, 562949953421312
%27 = or i64 %24, %26
%28 = and i64 %27, %1
%29 = or i64 %15, %28
%30 = or i64 %29, %9
%31 = or i64 %30, %22
ret i64 %31
}