int icost(int dd) {
  static int t[256] = {
      1024,  1023,  1022,  1021,  1019,  1016,  1012,  1008,  1004,  999,
      993,   986,   979,   972,   964,   955,   946,   936,   925,   914,
      903,   890,   878,   865,   851,   837,   822,   807,   791,   775,
      758,   741,   724,   706,   687,   668,   649,   629,   609,   589,
      568,   547,   526,   504,   482,   460,   437,   414,   391,   368,
      344,   321,   297,   273,   248,   224,   199,   175,   150,   125,
      100,   75,    50,    25,    0,     -25,   -50,   -75,   -100,  -125,
      -150,  -175,  -199,  -224,  -248,  -273,  -297,  -321,  -344,  -368,
      -391,  -414,  -437,  -460,  -482,  -504,  -526,  -547,  -568,  -589,
      -609,  -629,  -649,  -668,  -687,  -706,  -724,  -741,  -758,  -775,
      -791,  -807,  -822,  -837,  -851,  -865,  -878,  -890,  -903,  -914,
      -925,  -936,  -946,  -955,  -964,  -972,  -979,  -986,  -993,  -999,
      -1004, -1008, -1012, -1016, -1019, -1021, -1022, -1023, -1024, -1023,
      -1022, -1021, -1019, -1016, -1012, -1008, -1004, -999,  -993,  -986,
      -979,  -972,  -964,  -955,  -946,  -936,  -925,  -914,  -903,  -890,
      -878,  -865,  -851,  -837,  -822,  -807,  -791,  -775,  -758,  -741,
      -724,  -706,  -687,  -668,  -649,  -629,  -609,  -589,  -568,  -547,
      -526,  -504,  -482,  -460,  -437,  -414,  -391,  -368,  -344,  -321,
      -297,  -273,  -248,  -224,  -199,  -175,  -150,  -125,  -100,  -75,
      -50,   -25,   0,     25,    50,    75,    100,   125,   150,   175,
      199,   224,   248,   273,   297,   321,   344,   368,   391,   414,
      437,   460,   482,   504,   526,   547,   568,   589,   609,   629,
      649,   668,   687,   706,   724,   741,   758,   775,   791,   807,
      822,   837,   851,   865,   878,   890,   903,   914,   925,   936,
      946,   955,   964,   972,   979,   986,   993,   999,   1004,  1008,
      1012,  1016,  1019,  1021,  1022,  1023,
  };
  if (dd < 0) {
    dd = 256 - (-dd % 256);
  } else {
    dd %= 256;
  }
  return t[dd];
}


x86 assembly (clang, -O0):
<icost>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    112d <icost+0x2d>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    $0x100,%eax
sub    %edx,%eax
mov    %eax,-0x4(%rbp)
jmp    113b <icost+0x3b>
mov    -0x4(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
movslq -0x4(%rbp),%rcx
lea    0x2eea(%rip),%rax
mov    (%rax,%rcx,4),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<icost>:
mov    %edi,%eax
neg    %eax
movzbl %al,%eax
mov    $0x100,%ecx
sub    %eax,%ecx
test   %edi,%edi
movzbl %dil,%eax
cmovs  %ecx,%eax
lea    0xee2(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret

LLVM IR (-O0):
@icost.t = internal global [256 x i32] [i32 1024, i32 1023, i32 1022, i32 1021, i32 1019, i32 1016, i32 1012, i32 1008, i32 1004, i32 999, i32 993, i32 986, i32 979, i32 972, i32 964, i32 955, i32 946, i32 936, i32 925, i32 914, i32 903, i32 890, i32 878, i32 865, i32 851, i32 837, i32 822, i32 807, i32 791, i32 775, i32 758, i32 741, i32 724, i32 706, i32 687, i32 668, i32 649, i32 629, i32 609, i32 589, i32 568, i32 547, i32 526, i32 504, i32 482, i32 460, i32 437, i32 414, i32 391, i32 368, i32 344, i32 321, i32 297, i32 273, i32 248, i32 224, i32 199, i32 175, i32 150, i32 125, i32 100, i32 75, i32 50, i32 25, i32 0, i32 -25, i32 -50, i32 -75, i32 -100, i32 -125, i32 -150, i32 -175, i32 -199, i32 -224, i32 -248, i32 -273, i32 -297, i32 -321, i32 -344, i32 -368, i32 -391, i32 -414, i32 -437, i32 -460, i32 -482, i32 -504, i32 -526, i32 -547, i32 -568, i32 -589, i32 -609, i32 -629, i32 -649, i32 -668, i32 -687, i32 -706, i32 -724, i32 -741, i32 -758, i32 -775, i32 -791, i32 -807, i32 -822, i32 -837, i32 -851, i32 -865, i32 -878, i32 -890, i32 -903, i32 -914, i32 -925, i32 -936, i32 -946, i32 -955, i32 -964, i32 -972, i32 -979, i32 -986, i32 -993, i32 -999, i32 -1004, i32 -1008, i32 -1012, i32 -1016, i32 -1019, i32 -1021, i32 -1022, i32 -1023, i32 -1024, i32 -1023, i32 -1022, i32 -1021, i32 -1019, i32 -1016, i32 -1012, i32 -1008, i32 -1004, i32 -999, i32 -993, i32 -986, i32 -979, i32 -972, i32 -964, i32 -955, i32 -946, i32 -936, i32 -925, i32 -914, i32 -903, i32 -890, i32 -878, i32 -865, i32 -851, i32 -837, i32 -822, i32 -807, i32 -791, i32 -775, i32 -758, i32 -741, i32 -724, i32 -706, i32 -687, i32 -668, i32 -649, i32 -629, i32 -609, i32 -589, i32 -568, i32 -547, i32 -526, i32 -504, i32 -482, i32 -460, i32 -437, i32 -414, i32 -391, i32 -368, i32 -344, i32 -321, i32 -297, i32 -273, i32 -248, i32 -224, i32 -199, i32 -175, i32 -150, i32 -125, i32 -100, i32 -75, i32 -50, i32 -25, i32 0, i32 25, i32 50, i32 75, i32 100, i32 125, i32 150, i32 175, i32 199, i32 224, i32 248, i32 273, i32 297, i32 321, i32 344, i32 368, i32 391, i32 414, i32 437, i32 460, i32 482, i32 504, i32 526, i32 547, i32 568, i32 589, i32 609, i32 629, i32 649, i32 668, i32 687, i32 706, i32 724, i32 741, i32 758, i32 775, i32 791, i32 807, i32 822, i32 837, i32 851, i32 865, i32 878, i32 890, i32 903, i32 914, i32 925, i32 936, i32 946, i32 955, i32 964, i32 972, i32 979, i32 986, i32 993, i32 999, i32 1004, i32 1008, i32 1012, i32 1016, i32 1019, i32 1021, i32 1022, i32 1023]
define i32 @icost(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = load i32, i32* %2
%7 = sub nsw i32 0, %6
%8 = srem i32 %7, 256
%9 = sub nsw i32 256, %8
store i32 %9, i32* %2
br label %13
10: ; preds = %1
%11 = load i32, i32* %2
%12 = srem i32 %11, 256
store i32 %12, i32* %2
br label %13
13: ; preds = %10, %5
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [256 x i32], [256 x i32]* @icost.t, i64 0, i64 %15
%17 = load i32, i32* %16
ret i32 %17
}

LLVM IR (-O2):
@icost.t = internal unnamed_addr constant [256 x i32] [i32 1024, i32 1023, i32 1022, i32 1021, i32 1019, i32 1016, i32 1012, i32 1008, i32 1004, i32 999, i32 993, i32 986, i32 979, i32 972, i32 964, i32 955, i32 946, i32 936, i32 925, i32 914, i32 903, i32 890, i32 878, i32 865, i32 851, i32 837, i32 822, i32 807, i32 791, i32 775, i32 758, i32 741, i32 724, i32 706, i32 687, i32 668, i32 649, i32 629, i32 609, i32 589, i32 568, i32 547, i32 526, i32 504, i32 482, i32 460, i32 437, i32 414, i32 391, i32 368, i32 344, i32 321, i32 297, i32 273, i32 248, i32 224, i32 199, i32 175, i32 150, i32 125, i32 100, i32 75, i32 50, i32 25, i32 0, i32 -25, i32 -50, i32 -75, i32 -100, i32 -125, i32 -150, i32 -175, i32 -199, i32 -224, i32 -248, i32 -273, i32 -297, i32 -321, i32 -344, i32 -368, i32 -391, i32 -414, i32 -437, i32 -460, i32 -482, i32 -504, i32 -526, i32 -547, i32 -568, i32 -589, i32 -609, i32 -629, i32 -649, i32 -668, i32 -687, i32 -706, i32 -724, i32 -741, i32 -758, i32 -775, i32 -791, i32 -807, i32 -822, i32 -837, i32 -851, i32 -865, i32 -878, i32 -890, i32 -903, i32 -914, i32 -925, i32 -936, i32 -946, i32 -955, i32 -964, i32 -972, i32 -979, i32 -986, i32 -993, i32 -999, i32 -1004, i32 -1008, i32 -1012, i32 -1016, i32 -1019, i32 -1021, i32 -1022, i32 -1023, i32 -1024, i32 -1023, i32 -1022, i32 -1021, i32 -1019, i32 -1016, i32 -1012, i32 -1008, i32 -1004, i32 -999, i32 -993, i32 -986, i32 -979, i32 -972, i32 -964, i32 -955, i32 -946, i32 -936, i32 -925, i32 -914, i32 -903, i32 -890, i32 -878, i32 -865, i32 -851, i32 -837, i32 -822, i32 -807, i32 -791, i32 -775, i32 -758, i32 -741, i32 -724, i32 -706, i32 -687, i32 -668, i32 -649, i32 -629, i32 -609, i32 -589, i32 -568, i32 -547, i32 -526, i32 -504, i32 -482, i32 -460, i32 -437, i32 -414, i32 -391, i32 -368, i32 -344, i32 -321, i32 -297, i32 -273, i32 -248, i32 -224, i32 -199, i32 -175, i32 -150, i32 -125, i32 -100, i32 -75, i32 -50, i32 -25, i32 0, i32 25, i32 50, i32 75, i32 100, i32 125, i32 150, i32 175, i32 199, i32 224, i32 248, i32 273, i32 297, i32 321, i32 344, i32 368, i32 391, i32 414, i32 437, i32 460, i32 482, i32 504, i32 526, i32 547, i32 568, i32 589, i32 609, i32 629, i32 649, i32 668, i32 687, i32 706, i32 724, i32 741, i32 758, i32 775, i32 791, i32 807, i32 822, i32 837, i32 851, i32 865, i32 878, i32 890, i32 903, i32 914, i32 925, i32 936, i32 946, i32 955, i32 964, i32 972, i32 979, i32 986, i32 993, i32 999, i32 1004, i32 1008, i32 1012, i32 1016, i32 1019, i32 1021, i32 1022, i32 1023]
define i32 @icost(i32 %0) {
%2 = icmp slt i32 %0, 0
%3 = sub i32 0, %0
%4 = and i32 %3, 255
%5 = sub nuw nsw i32 256, %4
%6 = and i32 %0, 255
%7 = select i1 %2, i32 %5, i32 %6
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds [256 x i32], [256 x i32]* @icost.t, i64 0, i64 %8
%10 = load i32, i32* %9
ret i32 %10
}