unsigned long long flip_A2(const unsigned long long P,
                           const unsigned long long O) {
  unsigned int outflank_h;
  unsigned long long flipped, outflank_v, outflank_d9;
  outflank_v = ((O | ~0x0101010101010000ULL) + 0x0000000000010000ULL) & P &
               0x0101010101000000ULL;
  flipped =
      (outflank_v - (unsigned int)(outflank_v != 0)) & 0x0001010101010000ULL;
  outflank_h = ((O & 0x00007e00u) + 0x00000200u) & P;
  flipped |= (outflank_h - (outflank_h >> 8)) & 0x00007e00u;
  outflank_d9 = ((O | ~0x4020100804020000ULL) + 0x0000000000020000ULL) & P &
                0x4020100804000000ULL;
  flipped |=
      (outflank_d9 - (unsigned int)(outflank_d9 != 0)) & 0x0020100804020000ULL;
  return flipped;
}


x86 assembly (clang, -O0):
<flip_A2>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0xfefefefefefeffff,%rax
fe fe fe
or     -0x10(%rbp),%rax
add    $0x10000,%rax
and    -0x8(%rbp),%rax
movabs $0x101010101000000,%rcx
01 01 01
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpq   $0x0,-0x28(%rbp)
setne  %cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,%ecx
sub    %rcx,%rax
movabs $0x1010101010000,%rcx
and    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
and    $0x7e00,%rax
add    $0x200,%rax
and    -0x8(%rbp),%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x14(%rbp),%ecx
shr    $0x8,%ecx
sub    %ecx,%eax
and    $0x7e00,%eax
mov    %eax,%eax
or     -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
movabs $0xbfdfeff7fbfdffff,%rax
ef df bf
or     -0x10(%rbp),%rax
add    $0x20000,%rax
and    -0x8(%rbp),%rax
movabs $0x4020100804000000,%rcx
10 20 40
and    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,-0x30(%rbp)
setne  %cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,%ecx
sub    %rcx,%rax
movabs $0x20100804020000,%rcx
and    %rcx,%rax
or     -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<flip_A2>:
movabs $0xfefefefefeffff,%rax
or     %rsi,%rax
add    $0x10000,%rax
movabs $0x101010101000000,%rdx
01 01 01
and    %rdi,%rdx
and    %rax,%rdx
cmp    $0x1,%rdx
adc    $0xffffffffffffffff,%rdx
movabs $0x1010101010000,%rcx
and    %rdx,%rcx
movabs $0x3fdfeff7fbfdffff,%rax
ef df 3f
or     %rsi,%rax
mov    %esi,%edx
and    $0x7e00,%edx
add    $0x200,%edx
movabs $0x4020100804000000,%rsi
10 20 40
and    %rdi,%rsi
and    %edx,%edi
mov    %edi,%edx
shr    $0x8,%edx
sub    %edx,%edi
and    $0x7e00,%edi
add    $0x20000,%rax
and    %rax,%rsi
cmp    $0x1,%rsi
adc    $0xffffffffffffffff,%rsi
movabs $0x20100804020000,%rax
and    %rsi,%rax
or     %rcx,%rax
or     %rdi,%rax
ret

LLVM IR (-O0):
define i64 @flip_A2(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%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 = or i64 %9, -72340172838076417
%11 = add i64 %10, 65536
%12 = load i64, i64* %3
%13 = and i64 %11, %12
%14 = and i64 %13, 72340172838010880
store i64 %14, i64* %7
%15 = load i64, i64* %7
%16 = load i64, i64* %7
%17 = icmp ne i64 %16, 0
%18 = zext i1 %17 to i32
%19 = zext i32 %18 to i64
%20 = sub i64 %15, %19
%21 = and i64 %20, 282578800148480
store i64 %21, i64* %6
%22 = load i64, i64* %4
%23 = and i64 %22, 32256
%24 = add i64 %23, 512
%25 = load i64, i64* %3
%26 = and i64 %24, %25
%27 = trunc i64 %26 to i32
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = load i32, i32* %5
%30 = lshr i32 %29, 8
%31 = sub i32 %28, %30
%32 = and i32 %31, 32256
%33 = zext i32 %32 to i64
%34 = load i64, i64* %6
%35 = or i64 %34, %33
store i64 %35, i64* %6
%36 = load i64, i64* %4
%37 = or i64 %36, -4620710844295151617
%38 = add i64 %37, 131072
%39 = load i64, i64* %3
%40 = and i64 %38, %39
%41 = and i64 %40, 4620710844295020544
store i64 %41, i64* %8
%42 = load i64, i64* %8
%43 = load i64, i64* %8
%44 = icmp ne i64 %43, 0
%45 = zext i1 %44 to i32
%46 = zext i32 %45 to i64
%47 = sub i64 %42, %46
%48 = and i64 %47, 9024825867763712
%49 = load i64, i64* %6
%50 = or i64 %49, %48
store i64 %50, i64* %6
%51 = load i64, i64* %6
ret i64 %51
}

LLVM IR (-O2):
define i64 @flip_A2(i64 %0, i64 %1) {
%3 = or i64 %1, 71775015237779455
%4 = add i64 %3, 65536
%5 = and i64 %0, 72340172838010880
%6 = and i64 %5, %4
%7 = icmp ne i64 %6, 0
%8 = sext i1 %7 to i64
%9 = add nsw i64 %6, %8
%10 = and i64 %9, 282578800148480
%11 = and i64 %1, 32256
%12 = add nuw nsw i64 %11, 512
%13 = and i64 %12, %0
%14 = trunc i64 %13 to i32
%15 = lshr exact i32 %14, 8
%16 = sub nsw i32 %14, %15
%17 = and i32 %16, 32256
%18 = zext i32 %17 to i64
%19 = or i64 %1, 4602661192559624191
%20 = add i64 %19, 131072
%21 = and i64 %0, 4620710844295020544
%22 = and i64 %21, %20
%23 = icmp ne i64 %22, 0
%24 = sext i1 %23 to i64
%25 = add nsw i64 %22, %24
%26 = and i64 %25, 9024825867763712
%27 = or i64 %26, %10
%28 = or i64 %27, %18
ret i64 %28
}