unsigned long long flip_B8(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 & 0x0002020202020200ULL) ^ 0x0002020202020202ULL)) &
      P;
  flipped = (0x8000000000000000ULL - outflank_v * 2) & 0x0002020202020200ULL;
  outflank_h = ((O & 0x7c00000000000000ULL) + 0x0400000000000000ULL) & P;
  flipped |= (outflank_h - (outflank_h >> 8)) & 0x7c00000000000000ULL;
  outflank_d7 =
      (0x8000000000000000ULL >>
       __builtin_clzll((O & 0x0004081020400000ULL) ^ 0x0004081020408000ULL)) &
      P;
  flipped |= (0x8000000000000000ULL - outflank_d7 * 2) & 0x0004081020400000ULL;
  return flipped;
}


x86 assembly (clang, -O0):
<flip_B8>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x2020202020200,%rax
and    -0x10(%rbp),%rax
movabs $0x2020202020202,%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)
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
movabs $0x8000000000000000,%rax
sub    %rcx,%rax
movabs $0x2020202020200,%rcx
and    %rcx,%rax
mov    %rax,-0x18(%rbp)
movabs $0x7c00000000000000,%rax
and    -0x10(%rbp),%rax
movabs $0x400000000000000,%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 $0x7c00000000000000,%rcx
and    %rcx,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
movabs $0x4081020400000,%rax
and    -0x10(%rbp),%rax
movabs $0x4081020408000,%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)
mov    -0x30(%rbp),%rcx
shl    $0x1,%rcx
movabs $0x8000000000000000,%rax
sub    %rcx,%rax
movabs $0x4081020400000,%rcx
and    %rcx,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<flip_B8>:
movabs $0x2020202020200,%r8
mov    %rsi,%rax
and    %r8,%rax
lea    0x2(%r8),%rcx
xor    %rax,%rcx
bsr    %rcx,%rcx
xor    $0x3f,%ecx
movabs $0x8000000000000000,%rax
mov    %rax,%rdx
shr    %cl,%rdx
and    %rdi,%rdx
add    %rdx,%rdx
neg    %rdx
and    %r8,%rdx
movabs $0x7c00000000000000,%r9
mov    %rsi,%rcx
and    %r9,%rcx
movabs $0x400000000000000,%r8
add    %rcx,%r8
and    %rdi,%r8
mov    %r8,%rcx
shr    $0x8,%rcx
sub    %rcx,%r8
and    %r9,%r8
or     %rdx,%r8
movabs $0x4081020400000,%rdx
and    %rdx,%rsi
lea    0x8000(%rdx),%rcx
xor    %rsi,%rcx
bsr    %rcx,%rcx
xor    $0x3f,%ecx
shr    %cl,%rax
and    %rdi,%rax
add    %rax,%rax
neg    %rax
and    %rdx,%rax
or     %r8,%rax
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
%9 = load i64, i64* %4
%10 = and i64 %9, 565157600297472
%11 = xor i64 %10, 565157600297474
%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 = mul i64 %18, 2
%20 = sub i64 -9223372036854775808, %19
%21 = and i64 %20, 565157600297472
store i64 %21, i64* %5
%22 = load i64, i64* %4
%23 = and i64 %22, 8935141660703064064
%24 = add i64 %23, 288230376151711744
%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, 8935141660703064064
%32 = load i64, i64* %5
%33 = or i64 %32, %31
store i64 %33, i64* %5
%34 = load i64, i64* %4
%35 = and i64 %34, 1134765260406784
%36 = xor i64 %35, 1134765260439552
%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 = mul i64 %43, 2
%45 = sub i64 -9223372036854775808, %44
%46 = and i64 %45, 1134765260406784
%47 = load i64, i64* %5
%48 = or i64 %47, %46
store i64 %48, i64* %5
%49 = load i64, i64* %5
ret i64 %49
}

LLVM IR (-O2):
define i64 @flip_B8(i64 %0, i64 %1) {
%3 = and i64 %1, 565157600297472
%4 = xor i64 %3, 565157600297474
%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, 565157600297472
%10 = and i64 %1, 8935141660703064064
%11 = add nuw i64 %10, 288230376151711744
%12 = and i64 %11, %0
%13 = lshr exact i64 %12, 8
%14 = sub i64 %12, %13
%15 = and i64 %14, 8935141660703064064
%16 = or i64 %9, %15
%17 = and i64 %1, 1134765260406784
%18 = xor i64 %17, 1134765260439552
%19 = tail call i64 @llvm.ctlz.i64(i64 %18, i1 true)
%20 = lshr i64 -9223372036854775808, %19
%21 = and i64 %20, %0
%22 = mul nsw i64 %21, -2
%23 = and i64 %22, 1134765260406784
%24 = or i64 %16, %23
ret i64 %24
}