int sector_size_code(int sector_size) {
  switch (sector_size) {
  case 128:
    return 0;
  case 256:
    return 1;
  default:
  case 512:
    return 2;
  case 1024:
    return 3;
  case 2048:
    return 4;
  case 4096:
    return 5;
  case 8192:
    return 6;
  case 16384:
    return 7;
  }
}


x86 assembly (clang, -O0):
<sector_size_code>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0x80,%eax
je     11a2 <sector_size_code+0xa2>
jmp    111d <sector_size_code+0x1d>
mov    -0xc(%rbp),%eax
sub    $0x100,%eax
je     11ae <sector_size_code+0xae>
jmp    1130 <sector_size_code+0x30>
mov    -0xc(%rbp),%eax
sub    $0x200,%eax
je     11bf <sector_size_code+0xbf>
jmp    1143 <sector_size_code+0x43>
mov    -0xc(%rbp),%eax
sub    $0x400,%eax
je     11cb <sector_size_code+0xcb>
jmp    1156 <sector_size_code+0x56>
mov    -0xc(%rbp),%eax
sub    $0x800,%eax
je     11d7 <sector_size_code+0xd7>
jmp    1169 <sector_size_code+0x69>
mov    -0xc(%rbp),%eax
sub    $0x1000,%eax
je     11e3 <sector_size_code+0xe3>
jmp    117c <sector_size_code+0x7c>
mov    -0xc(%rbp),%eax
sub    $0x2000,%eax
je     11ef <sector_size_code+0xef>
jmp    118f <sector_size_code+0x8f>
mov    -0xc(%rbp),%eax
sub    $0x4000,%eax
je     11fb <sector_size_code+0xfb>
jmp    11ba <sector_size_code+0xba>
movl   $0x0,-0x4(%rbp)
jmp    1202 <sector_size_code+0x102>
movl   $0x1,-0x4(%rbp)
jmp    1202 <sector_size_code+0x102>
jmp    11bf <sector_size_code+0xbf>
movl   $0x2,-0x4(%rbp)
jmp    1202 <sector_size_code+0x102>
movl   $0x3,-0x4(%rbp)
jmp    1202 <sector_size_code+0x102>
movl   $0x4,-0x4(%rbp)
jmp    1202 <sector_size_code+0x102>
movl   $0x5,-0x4(%rbp)
jmp    1202 <sector_size_code+0x102>
movl   $0x6,-0x4(%rbp)
jmp    1202 <sector_size_code+0x102>
movl   $0x7,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<sector_size_code>:
cmp    $0x7ff,%edi
jle    1126 <sector_size_code+0x26>
cmp    $0x1fff,%edi
jg     1144 <sector_size_code+0x44>
cmp    $0x800,%edi
je     115a <sector_size_code+0x5a>
cmp    $0x1000,%edi
jne    1169 <sector_size_code+0x69>
mov    $0x5,%eax
ret
cmp    $0x80,%edi
je     1160 <sector_size_code+0x60>
cmp    $0x100,%edi
je     116f <sector_size_code+0x6f>
cmp    $0x400,%edi
jne    1169 <sector_size_code+0x69>
mov    $0x3,%eax
ret
cmp    $0x2000,%edi
je     1163 <sector_size_code+0x63>
cmp    $0x4000,%edi
jne    1169 <sector_size_code+0x69>
mov    $0x7,%eax
ret
mov    $0x4,%eax
ret
xor    %eax,%eax
ret
mov    $0x6,%eax
ret
mov    $0x2,%eax
ret
mov    $0x1,%eax
ret

LLVM IR (-O0):
define i32 @sector_size_code(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %7 [
i32 128, label %5
i32 256, label %6
i32 512, label %8
i32 1024, label %9
i32 2048, label %10
i32 4096, label %11
i32 8192, label %12
i32 16384, label %13
]
5: ; preds = %1
store i32 0, i32* %2
br label %14
6: ; preds = %1
store i32 1, i32* %2
br label %14
7: ; preds = %1
br label %8
8: ; preds = %1, %7
store i32 2, i32* %2
br label %14
9: ; preds = %1
store i32 3, i32* %2
br label %14
10: ; preds = %1
store i32 4, i32* %2
br label %14
11: ; preds = %1
store i32 5, i32* %2
br label %14
12: ; preds = %1
store i32 6, i32* %2
br label %14
13: ; preds = %1
store i32 7, i32* %2
br label %14
14: ; preds = %13, %12, %11, %10, %9, %8, %6, %5
%15 = load i32, i32* %2
ret i32 %15
}

LLVM IR (-O2):
define i32 @sector_size_code(i32 %0) {
switch i32 %0, label %3 [
i32 128, label %9
i32 256, label %2
i32 16384, label %8
i32 1024, label %4
i32 2048, label %5
i32 4096, label %6
i32 8192, label %7
]
2: ; preds = %1
br label %9
3: ; preds = %1
br label %9
4: ; preds = %1
br label %9
5: ; preds = %1
br label %9
6: ; preds = %1
br label %9
7: ; preds = %1
br label %9
8: ; preds = %1
br label %9
9: ; preds = %1, %8, %7, %6, %5, %4, %3, %2
%10 = phi i32 [ 2, %3 ], [ 6, %7 ], [ 5, %6 ], [ 4, %5 ], [ 3, %4 ], [ 7, %8 ], [ 1, %2 ], [ 0, %1 ]
ret i32 %10
}