#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 */
float log2(float);
int round(float);
int calc_mv_cost(int dx, int dy) {
  return round((log2((float)(dx + 1)) * 2.0f + 0.718f + !!dx)) +
         round((log2((float)(dy + 1)) * 2.0f + 0.718f + !!dy));
}


x86 assembly (clang, -O0):
<calc_mv_cost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm0
call   1030 <log2@plt>
addss  %xmm0,%xmm0
movss  0xeb7(%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
call   1040 <round@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm0
call   1030 <log2@plt>
addss  %xmm0,%xmm0
movss  0xe78(%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
call   1040 <round@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
add    %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_mv_cost>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x1(%rbp),%eax
cvtsi2ss %eax,%xmm0
call   1030 <log2@plt>
addss  %xmm0,%xmm0
addss  0xec1(%rip),%xmm0
movss  0xebd(%rip),%xmm1
test   %ebp,%ebp
jne    114e <calc_mv_cost+0x2e>
xorps  %xmm1,%xmm1
addss  %xmm1,%xmm0
call   1040 <round@plt>
mov    %eax,%ebp
lea    0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
call   1030 <log2@plt>
addss  %xmm0,%xmm0
addss  0xe8c(%rip),%xmm0
test   %ebx,%ebx
movss  0xe86(%rip),%xmm1
jne    1183 <calc_mv_cost+0x63>
xorps  %xmm1,%xmm1
addss  %xmm1,%xmm0
call   1040 <round@plt>
add    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @calc_mv_cost(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = add nsw i32 %5, 1
%7 = sitofp i32 %6 to float
%8 = call float @log2(float %7)
%9 = call float @llvm.fmuladd.f32(float %8, float 2.000000e+00, float 0x3FE6F9DB20000000)
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
%13 = xor i1 %12, true
%14 = zext i1 %13 to i32
%15 = sitofp i32 %14 to float
%16 = fadd float %9, %15
%17 = call i32 @round(float %16)
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
%20 = sitofp i32 %19 to float
%21 = call float @log2(float %20)
%22 = call float @llvm.fmuladd.f32(float %21, float 2.000000e+00, float 0x3FE6F9DB20000000)
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
%26 = xor i1 %25, true
%27 = zext i1 %26 to i32
%28 = sitofp i32 %27 to float
%29 = fadd float %22, %28
%30 = call i32 @round(float %29)
%31 = add nsw i32 %17, %30
ret i32 %31
}

LLVM IR (-O2):
define i32 @calc_mv_cost(i32 %0, i32 %1) {
%3 = add nsw i32 %0, 1
%4 = sitofp i32 %3 to float
%5 = tail call float @log2(float %4)
%6 = tail call float @llvm.fmuladd.f32(float %5, float 2.000000e+00, float 0x3FE6F9DB20000000)
%7 = icmp ne i32 %0, 0
%8 = uitofp i1 %7 to float
%9 = fadd float %6, %8
%10 = tail call i32 @round(float %9)
%11 = add nsw i32 %1, 1
%12 = sitofp i32 %11 to float
%13 = tail call float @log2(float %12)
%14 = tail call float @llvm.fmuladd.f32(float %13, float 2.000000e+00, float 0x3FE6F9DB20000000)
%15 = icmp ne i32 %1, 0
%16 = uitofp i1 %15 to float
%17 = fadd float %14, %16
%18 = tail call i32 @round(float %17)
%19 = add nsw i32 %18, %10
ret i32 %19
}