int BSP_GetSizeFromSeg(int seg_size) {
  switch (seg_size) {
  case 0:
  case 1:
  case 2:
  case 3:
  case 4:
  case 5:
  case 6:
  case 7:
  case 8:
  case 9:
  case 10:
    return 0;
  case 11:
    return 4;
  case 12:
    return 8;
  case 13:
    return 16;
  case 14:
    return 32;
  case 15:
    return 64;
  case 16:
    return 128;
  case 17:
    return 256;
  case 18:
    return 512;
  case 19:
    return 1024;
  case 20:
    return 2048;
  case 21:
    return 4096;
  case 22:
    return 8 * 1024;
  case 23:
    return 16 * 1024;
  case 24:
    return 32 * 1024;
  case 25:
    return 64 * 1024;
  case 26:
    return 128 * 1024;
  case 27:
    return 256 * 1024;
  case 28:
    return 512 * 1024;
  case 29:
    return 1024 * 1024;
  case 30:
    return 2048 * 1024;
  case 31:
    return 4096 * 1024;
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<BSP_GetSizeFromSeg>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x10(%rbp)
sub    $0x1f,%rax
ja     1234 <BSP_GetSizeFromSeg+0x134>
mov    -0x10(%rbp),%rax
lea    0xedd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x4,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x8,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x10,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x20,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x40,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x80,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x100,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x200,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x400,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x800,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x1000,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x2000,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x4000,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x8000,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x10000,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x20000,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x40000,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x80000,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x100000,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x200000,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0x400000,-0x4(%rbp)
jmp    123b <BSP_GetSizeFromSeg+0x13b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<BSP_GetSizeFromSeg>:
mov    $0xffffffff,%eax
cmp    $0x1f,%edi
ja     1117 <BSP_GetSizeFromSeg+0x17>
movslq %edi,%rax
lea    0xeec(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret

LLVM IR (-O0):
define i32 @BSP_GetSizeFromSeg(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %27 [
i32 0, label %5
i32 1, label %5
i32 2, label %5
i32 3, label %5
i32 4, label %5
i32 5, label %5
i32 6, label %5
i32 7, label %5
i32 8, label %5
i32 9, label %5
i32 10, label %5
i32 11, label %6
i32 12, label %7
i32 13, label %8
i32 14, label %9
i32 15, label %10
i32 16, label %11
i32 17, label %12
i32 18, label %13
i32 19, label %14
i32 20, label %15
i32 21, label %16
i32 22, label %17
i32 23, label %18
i32 24, label %19
i32 25, label %20
i32 26, label %21
i32 27, label %22
i32 28, label %23
i32 29, label %24
i32 30, label %25
i32 31, label %26
]
5: ; preds = %1, %1, %1, %1, %1, %1, %1, %1, %1, %1, %1
store i32 0, i32* %2
br label %28
6: ; preds = %1
store i32 4, i32* %2
br label %28
7: ; preds = %1
store i32 8, i32* %2
br label %28
8: ; preds = %1
store i32 16, i32* %2
br label %28
9: ; preds = %1
store i32 32, i32* %2
br label %28
10: ; preds = %1
store i32 64, i32* %2
br label %28
11: ; preds = %1
store i32 128, i32* %2
br label %28
12: ; preds = %1
store i32 256, i32* %2
br label %28
13: ; preds = %1
store i32 512, i32* %2
br label %28
14: ; preds = %1
store i32 1024, i32* %2
br label %28
15: ; preds = %1
store i32 2048, i32* %2
br label %28
16: ; preds = %1
store i32 4096, i32* %2
br label %28
17: ; preds = %1
store i32 8192, i32* %2
br label %28
18: ; preds = %1
store i32 16384, i32* %2
br label %28
19: ; preds = %1
store i32 32768, i32* %2
br label %28
20: ; preds = %1
store i32 65536, i32* %2
br label %28
21: ; preds = %1
store i32 131072, i32* %2
br label %28
22: ; preds = %1
store i32 262144, i32* %2
br label %28
23: ; preds = %1
store i32 524288, i32* %2
br label %28
24: ; preds = %1
store i32 1048576, i32* %2
br label %28
25: ; preds = %1
store i32 2097152, i32* %2
br label %28
26: ; preds = %1
store i32 4194304, i32* %2
br label %28
27: ; preds = %1
store i32 -1, i32* %2
br label %28
28: ; preds = %27, %26, %25, %24, %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@switch.table.BSP_GetSizeFromSeg = [32 x i32] [i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512, i32 1024, i32 2048, i32 4096, i32 8192, i32 16384, i32 32768, i32 65536, i32 131072, i32 262144, i32 524288, i32 1048576, i32 2097152, i32 4194304]
define i32 @BSP_GetSizeFromSeg(i32 %0) {
%2 = icmp ult i32 %0, 32
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = sext i32 %0 to i64
%5 = getelementptr inbounds [32 x i32], [32 x i32]* @switch.table.BSP_GetSizeFromSeg, i64 0, i64 %4
%6 = load i32, i32* %5
br label %7
7: ; preds = %1, %3
%8 = phi i32 [ %6, %3 ], [ -1, %1 ]
ret i32 %8
}