#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 abs(int);
int log2f(int);
int round(int);
unsigned mvCost(int dx, int dy) {
  dx = (abs(dx)) << 2;
  dy = (abs(dy)) << 2;
  int xCost = round((log2f(dx + 1) * 2 + 0.718f + !!dx) + .5f);
  int yCost = round((log2f(dy + 1) * 2 + 0.718f + !!dy) + .5f);
  return (4 * (xCost + yCost));
}


x86 assembly (clang, -O0):
<mvCost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <abs@plt>
shl    $0x2,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <abs@plt>
shl    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
call   1040 <log2f@plt>
shl    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  0xe90(%rip),%xmm1
addss  %xmm1,%xmm0
cmpl   $0x0,-0x4(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cvtsi2ss %eax,%xmm1
addss  %xmm1,%xmm0
movss  0xe68(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%edi
call   1050 <round@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1040 <log2f@plt>
shl    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  0xe42(%rip),%xmm1
addss  %xmm1,%xmm0
cmpl   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cvtsi2ss %eax,%xmm1
addss  %xmm1,%xmm0
movss  0xe1a(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%edi
call   1050 <round@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
shl    $0x2,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mvCost>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%eax
neg    %eax
cmovs  %edi,%eax
lea    0x0(,%rax,4),%ebx
mov    %esi,%ebp
neg    %ebp
cmovs  %esi,%ebp
lea    0x0(,%rbp,4),%r14d
lea    0x1(,%rax,4),%edi
call   1030 <log2f@plt>
add    %eax,%eax
cvtsi2ss %eax,%xmm0
addss  0xea5(%rip),%xmm0
movss  0xea1(%rip),%xmm1
test   %ebx,%ebx
jne    116a <mvCost+0x4a>
xorps  %xmm1,%xmm1
addss  %xmm1,%xmm0
addss  0xe92(%rip),%xmm0
cvttss2si %xmm0,%edi
call   1040 <round@plt>
mov    %eax,%ebx
lea    0x1(,%rbp,4),%edi
call   1030 <log2f@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
addss  0xe62(%rip),%xmm0
test   %r14d,%r14d
movss  0xe5b(%rip),%xmm1
jne    11ae <mvCost+0x8e>
xorps  %xmm1,%xmm1
addss  %xmm1,%xmm0
addss  0xe4e(%rip),%xmm0
cvttss2si %xmm0,%edi
call   1040 <round@plt>
add    %ebx,%eax
shl    $0x2,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mvCost(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = call i32 @abs(i32 %7)
%9 = shl i32 %8, 2
store i32 %9, i32* %3
%10 = load i32, i32* %4
%11 = call i32 @abs(i32 %10)
%12 = shl i32 %11, 2
store i32 %12, i32* %4
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
%15 = call i32 @log2f(i32 %14)
%16 = mul nsw i32 %15, 2
%17 = sitofp i32 %16 to float
%18 = fadd float %17, 0x3FE6F9DB20000000
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
%22 = xor i1 %21, true
%23 = zext i1 %22 to i32
%24 = sitofp i32 %23 to float
%25 = fadd float %18, %24
%26 = fadd float %25, 5.000000e-01
%27 = fptosi float %26 to i32
%28 = call i32 @round(i32 %27)
store i32 %28, i32* %5
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
%31 = call i32 @log2f(i32 %30)
%32 = mul nsw i32 %31, 2
%33 = sitofp i32 %32 to float
%34 = fadd float %33, 0x3FE6F9DB20000000
%35 = load i32, i32* %4
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
%38 = xor i1 %37, true
%39 = zext i1 %38 to i32
%40 = sitofp i32 %39 to float
%41 = fadd float %34, %40
%42 = fadd float %41, 5.000000e-01
%43 = fptosi float %42 to i32
%44 = call i32 @round(i32 %43)
store i32 %44, i32* %6
%45 = load i32, i32* %5
%46 = load i32, i32* %6
%47 = add nsw i32 %45, %46
%48 = mul nsw i32 4, %47
ret i32 %48
}

LLVM IR (-O2):
define i32 @mvCost(i32 %0, i32 %1) {
%3 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%4 = shl i32 %3, 2
%5 = tail call i32 @llvm.abs.i32(i32 %1, i1 true)
%6 = shl i32 %5, 2
%7 = or i32 %4, 1
%8 = tail call i32 @log2f(i32 %7)
%9 = shl nsw i32 %8, 1
%10 = sitofp i32 %9 to float
%11 = fadd float %10, 0x3FE6F9DB20000000
%12 = icmp ne i32 %4, 0
%13 = uitofp i1 %12 to float
%14 = fadd float %11, %13
%15 = fadd float %14, 5.000000e-01
%16 = fptosi float %15 to i32
%17 = tail call i32 @round(i32 %16)
%18 = or i32 %6, 1
%19 = tail call i32 @log2f(i32 %18)
%20 = shl nsw i32 %19, 1
%21 = sitofp i32 %20 to float
%22 = fadd float %21, 0x3FE6F9DB20000000
%23 = icmp ne i32 %6, 0
%24 = uitofp i1 %23 to float
%25 = fadd float %22, %24
%26 = fadd float %25, 5.000000e-01
%27 = fptosi float %26 to i32
%28 = tail call i32 @round(i32 %27)
%29 = add nsw i32 %28, %17
%30 = shl nsw i32 %29, 2
ret i32 %30
}