#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 */
typedef int int32_t;

/* Variables and functions */
int const abs(int const);
int32_t kingMovesBetweenSquares(int32_t sq1, int32_t sq2) {
  const int32_t r1 = (((sq1) / 12) - 2);
  const int32_t f1 = (((sq1) % 12) - 2);
  const int32_t r2 = (((sq2) / 12) - 2);
  const int32_t f2 = (((sq2) % 12) - 2);
  const int32_t dr = abs(r1 - r2);
  const int32_t df = abs(f1 - f2);
  const int32_t min = dr < df ? dr : df;
  return min + abs(dr - df);
}


x86 assembly (clang, -O0):
<kingMovesBetweenSquares>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
sub    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
sub    $0x2,%edx
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
sub    $0x2,%edx
mov    %edx,-0x18(%rbp)
mov    -0xc(%rbp),%edi
sub    -0x14(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
sub    -0x18(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1195 <kingMovesBetweenSquares+0x85>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    119b <kingMovesBetweenSquares+0x8b>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
sub    -0x20(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kingMovesBetweenSquares>:
movslq %edi,%r8
imul   $0x2aaaaaab,%r8,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    0x0(,%rcx,4),%edx
lea    (%rdx,%rdx,2),%edx
sub    %edx,%r8d
movslq %esi,%rdx
imul   $0xffffffffd5555555,%rdx,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
sar    $0x21,%rsi
add    %edi,%esi
imul   $0x2aaaaaab,%rdx,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
shr    $0x21,%rdi
add    %eax,%edi
shl    $0x2,%edi
lea    (%rdi,%rdi,2),%eax
add    %ecx,%esi
mov    %esi,%ecx
neg    %ecx
cmovs  %esi,%ecx
sub    %edx,%eax
add    %r8d,%eax
mov    %eax,%edx
neg    %edx
cmovs  %eax,%edx
mov    %ecx,%esi
sub    %edx,%esi
cmovb  %ecx,%edx
mov    %esi,%eax
neg    %eax
cmovs  %esi,%eax
add    %edx,%eax
ret

LLVM IR (-O0):
define i32 @kingMovesBetweenSquares(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%12 = load i32, i32* %3
%13 = sdiv i32 %12, 12
%14 = sub nsw i32 %13, 2
store i32 %14, i32* %5
%15 = load i32, i32* %3
%16 = srem i32 %15, 12
%17 = sub nsw i32 %16, 2
store i32 %17, i32* %6
%18 = load i32, i32* %4
%19 = sdiv i32 %18, 12
%20 = sub nsw i32 %19, 2
store i32 %20, i32* %7
%21 = load i32, i32* %4
%22 = srem i32 %21, 12
%23 = sub nsw i32 %22, 2
store i32 %23, i32* %8
%24 = load i32, i32* %5
%25 = load i32, i32* %7
%26 = sub nsw i32 %24, %25
%27 = call i32 @abs(i32 %26)
store i32 %27, i32* %9
%28 = load i32, i32* %6
%29 = load i32, i32* %8
%30 = sub nsw i32 %28, %29
%31 = call i32 @abs(i32 %30)
store i32 %31, i32* %10
%32 = load i32, i32* %9
%33 = load i32, i32* %10
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %2
%36 = load i32, i32* %9
br label %39
37: ; preds = %2
%38 = load i32, i32* %10
br label %39
39: ; preds = %37, %35
%40 = phi i32 [ %36, %35 ], [ %38, %37 ]
store i32 %40, i32* %11
%41 = load i32, i32* %11
%42 = load i32, i32* %9
%43 = load i32, i32* %10
%44 = sub nsw i32 %42, %43
%45 = call i32 @abs(i32 %44)
%46 = add nsw i32 %41, %45
ret i32 %46
}

LLVM IR (-O2):
define i32 @kingMovesBetweenSquares(i32 %0, i32 %1) {
%3 = sdiv i32 %0, 12
%4 = srem i32 %0, 12
%5 = sdiv i32 %1, -12
%6 = srem i32 %1, 12
%7 = add nsw i32 %5, %3
%8 = tail call i32 @llvm.abs.i32(i32 %7, i1 true)
%9 = sub nsw i32 %4, %6
%10 = tail call i32 @llvm.abs.i32(i32 %9, i1 true)
%11 = icmp ult i32 %8, %10
%12 = select i1 %11, i32 %8, i32 %10
%13 = sub nsw i32 %8, %10
%14 = tail call i32 @llvm.abs.i32(i32 %13, i1 true)
%15 = add nuw nsw i32 %12, %14
ret i32 %15
}