int segment_to_int(int segment_bitfield) {
  switch (segment_bitfield) {
  case 0:
  case 0x1717:
    return 0;
  case 0x1400:
    return 1;
  case 0x0d92:
    return 2;
  case 0x1d90:
    return 3;
  case 0x1c81:
    return 4;
  case 0x1991:
    return 5;
  case 0x1993:
    return 6;
  case 0x1500:
    return 7;
  case 0x1d93:
    return 8;
  case 0x1d91:
    return 9;
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<segment_to_int>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
test   %eax,%eax
je     11d8 <segment_to_int+0xd8>
jmp    111a <segment_to_int+0x1a>
mov    -0xc(%rbp),%eax
sub    $0xd92,%eax
je     11f0 <segment_to_int+0xf0>
jmp    112d <segment_to_int+0x2d>
mov    -0xc(%rbp),%eax
sub    $0x1400,%eax
je     11e4 <segment_to_int+0xe4>
jmp    1140 <segment_to_int+0x40>
mov    -0xc(%rbp),%eax
sub    $0x1500,%eax
je     122c <segment_to_int+0x12c>
jmp    1153 <segment_to_int+0x53>
mov    -0xc(%rbp),%eax
sub    $0x1717,%eax
je     11d8 <segment_to_int+0xd8>
jmp    1166 <segment_to_int+0x66>
mov    -0xc(%rbp),%eax
sub    $0x1991,%eax
je     1214 <segment_to_int+0x114>
jmp    1179 <segment_to_int+0x79>
mov    -0xc(%rbp),%eax
sub    $0x1993,%eax
je     1220 <segment_to_int+0x120>
jmp    118c <segment_to_int+0x8c>
mov    -0xc(%rbp),%eax
sub    $0x1c81,%eax
je     1208 <segment_to_int+0x108>
jmp    119f <segment_to_int+0x9f>
mov    -0xc(%rbp),%eax
sub    $0x1d90,%eax
je     11fc <segment_to_int+0xfc>
jmp    11b2 <segment_to_int+0xb2>
mov    -0xc(%rbp),%eax
sub    $0x1d91,%eax
je     1244 <segment_to_int+0x144>
jmp    11c5 <segment_to_int+0xc5>
mov    -0xc(%rbp),%eax
sub    $0x1d93,%eax
je     1238 <segment_to_int+0x138>
jmp    1250 <segment_to_int+0x150>
movl   $0x0,-0x4(%rbp)
jmp    1257 <segment_to_int+0x157>
movl   $0x1,-0x4(%rbp)
jmp    1257 <segment_to_int+0x157>
movl   $0x2,-0x4(%rbp)
jmp    1257 <segment_to_int+0x157>
movl   $0x3,-0x4(%rbp)
jmp    1257 <segment_to_int+0x157>
movl   $0x4,-0x4(%rbp)
jmp    1257 <segment_to_int+0x157>
movl   $0x5,-0x4(%rbp)
jmp    1257 <segment_to_int+0x157>
movl   $0x6,-0x4(%rbp)
jmp    1257 <segment_to_int+0x157>
movl   $0x7,-0x4(%rbp)
jmp    1257 <segment_to_int+0x157>
movl   $0x8,-0x4(%rbp)
jmp    1257 <segment_to_int+0x157>
movl   $0x9,-0x4(%rbp)
jmp    1257 <segment_to_int+0x157>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<segment_to_int>:
cmp    $0x1990,%edi
jle    112e <segment_to_int+0x2e>
cmp    $0x1d8f,%edi
jg     1151 <segment_to_int+0x51>
cmp    $0x1991,%edi
je     1181 <segment_to_int+0x81>
cmp    $0x1993,%edi
je     1187 <segment_to_int+0x87>
cmp    $0x1c81,%edi
jne    11a5 <segment_to_int+0xa5>
mov    $0x4,%eax
ret
xor    %eax,%eax
cmp    $0x13ff,%edi
jle    116f <segment_to_int+0x6f>
cmp    $0x1400,%edi
je     118d <segment_to_int+0x8d>
cmp    $0x1500,%edi
je     1193 <segment_to_int+0x93>
cmp    $0x1717,%edi
jne    11a5 <segment_to_int+0xa5>
ret
cmp    $0x1d90,%edi
je     1199 <segment_to_int+0x99>
cmp    $0x1d91,%edi
je     119f <segment_to_int+0x9f>
cmp    $0x1d93,%edi
jne    11a5 <segment_to_int+0xa5>
mov    $0x8,%eax
ret
test   %edi,%edi
je     1150 <segment_to_int+0x50>
cmp    $0xd92,%edi
jne    11a5 <segment_to_int+0xa5>
mov    $0x2,%eax
ret
mov    $0x5,%eax
ret
mov    $0x6,%eax
ret
mov    $0x1,%eax
ret
mov    $0x7,%eax
ret
mov    $0x3,%eax
ret
mov    $0x9,%eax
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
define i32 @segment_to_int(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %15 [
i32 0, label %5
i32 5911, label %5
i32 5120, label %6
i32 3474, label %7
i32 7568, label %8
i32 7297, label %9
i32 6545, label %10
i32 6547, label %11
i32 5376, label %12
i32 7571, label %13
i32 7569, label %14
]
5: ; preds = %1, %1
store i32 0, i32* %2
br label %16
6: ; preds = %1
store i32 1, i32* %2
br label %16
7: ; preds = %1
store i32 2, i32* %2
br label %16
8: ; preds = %1
store i32 3, i32* %2
br label %16
9: ; preds = %1
store i32 4, i32* %2
br label %16
10: ; preds = %1
store i32 5, i32* %2
br label %16
11: ; preds = %1
store i32 6, i32* %2
br label %16
12: ; preds = %1
store i32 7, i32* %2
br label %16
13: ; preds = %1
store i32 8, i32* %2
br label %16
14: ; preds = %1
store i32 9, i32* %2
br label %16
15: ; preds = %1
store i32 -1, i32* %2
br label %16
16: ; preds = %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
define i32 @segment_to_int(i32 %0) {
switch i32 %0, label %11 [
i32 0, label %12
i32 5911, label %12
i32 5120, label %2
i32 3474, label %3
i32 7568, label %4
i32 7297, label %5
i32 6545, label %6
i32 6547, label %7
i32 5376, label %8
i32 7571, label %9
i32 7569, label %10
]
2: ; preds = %1
br label %12
3: ; preds = %1
br label %12
4: ; preds = %1
br label %12
5: ; preds = %1
br label %12
6: ; preds = %1
br label %12
7: ; preds = %1
br label %12
8: ; preds = %1
br label %12
9: ; preds = %1
br label %12
10: ; preds = %1
br label %12
11: ; preds = %1
br label %12
12: ; preds = %1, %1, %11, %10, %9, %8, %7, %6, %5, %4, %3, %2
%13 = phi i32 [ -1, %11 ], [ 9, %10 ], [ 8, %9 ], [ 7, %8 ], [ 6, %7 ], [ 5, %6 ], [ 4, %5 ], [ 3, %4 ], [ 2, %3 ], [ 1, %2 ], [ 0, %1 ], [ 0, %1 ]
ret i32 %13
}