#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);
double distancecost(int A, int B) {
  double cost = 0;
  int C = abs(B - A);
  switch (C) {
  case 0:
    cost = 400000000.0;
    break;
  case 1:
    cost = 16.0;
    break;
  case 2:
    cost = 8.0;
    break;
  case 3:
    cost = 4.0;
    break;
  case 4:
    cost = 2.0;
    break;
  case 5:
    cost = 1.0;
    break;
  default:
    cost = 0.0;
    break;
  }
  return cost;
}


x86 assembly (clang, -O0):
<distancecost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%eax
sub    %eax,%edi
call   1030 <abs@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x5,%rax
ja     11c7 <distancecost+0xb7>
mov    -0x20(%rbp),%rax
lea    0xede(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  0xec5(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11cf <distancecost+0xbf>
movsd  0xeab(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11cf <distancecost+0xbf>
movsd  0xe91(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11cf <distancecost+0xbf>
movsd  0xe77(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11cf <distancecost+0xbf>
movsd  0xe5d(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11cf <distancecost+0xbf>
movsd  0xe43(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11cf <distancecost+0xbf>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distancecost>:
sub    %edi,%esi
mov    %esi,%eax
neg    %eax
cmovs  %esi,%eax
xorps  %xmm0,%xmm0
cmp    $0x5,%eax
ja     111f <distancecost+0x1f>
mov    %eax,%eax
lea    0xee6(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
ret

LLVM IR (-O0):
define double @distancecost(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %5
%7 = load i32, i32* %4
%8 = load i32, i32* %3
%9 = sub nsw i32 %7, %8
%10 = call i32 @abs(i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
switch i32 %11, label %18 [
i32 0, label %12
i32 1, label %13
i32 2, label %14
i32 3, label %15
i32 4, label %16
i32 5, label %17
]
12: ; preds = %2
store double 4.000000e+08, double* %5
br label %19
13: ; preds = %2
store double 1.600000e+01, double* %5
br label %19
14: ; preds = %2
store double 8.000000e+00, double* %5
br label %19
15: ; preds = %2
store double 4.000000e+00, double* %5
br label %19
16: ; preds = %2
store double 2.000000e+00, double* %5
br label %19
17: ; preds = %2
store double 1.000000e+00, double* %5
br label %19
18: ; preds = %2
store double 0.000000e+00, double* %5
br label %19
19: ; preds = %18, %17, %16, %15, %14, %13, %12
%20 = load double, double* %5
ret double %20
}

LLVM IR (-O2):
@switch.table.distancecost = [6 x double] [double 4.000000e+08, double 1.600000e+01, double 8.000000e+00, double 4.000000e+00, double 2.000000e+00, double 1.000000e+00]
define double @distancecost(i32 %0, i32 %1) {
%3 = sub nsw i32 %1, %0
%4 = tail call i32 @llvm.abs.i32(i32 %3, i1 true)
%5 = icmp ult i32 %4, 6
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = zext i32 %4 to i64
%8 = getelementptr inbounds [6 x double], [6 x double]* @switch.table.distancecost, i64 0, i64 %7
%9 = load double, double* %8
br label %10
10: ; preds = %2, %6
%11 = phi double [ %9, %6 ], [ 0.000000e+00, %2 ]
ret double %11
}