unsigned index_bytes_per_pixel(unsigned index) {
  switch (index) {
  case 0x0100:
    return 1;
  case 0x0200:
    return 1;
  case 0x0300:
    return 2;
  case 0x0400:
    return 2;
  case 0x0500:
    return 3;
  case 0x0600:
    return 4;
  case 0x0700:
    return 4;
  case 0x0800:
    return 2;
  default:
    return 0;
  }
}


x86 assembly (clang, -O0):
<index_bytes_per_pixel>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0x100,%eax
je     11a2 <index_bytes_per_pixel+0xa2>
jmp    111d <index_bytes_per_pixel+0x1d>
mov    -0xc(%rbp),%eax
sub    $0x200,%eax
je     11ae <index_bytes_per_pixel+0xae>
jmp    1130 <index_bytes_per_pixel+0x30>
mov    -0xc(%rbp),%eax
sub    $0x300,%eax
je     11ba <index_bytes_per_pixel+0xba>
jmp    1143 <index_bytes_per_pixel+0x43>
mov    -0xc(%rbp),%eax
sub    $0x400,%eax
je     11c6 <index_bytes_per_pixel+0xc6>
jmp    1156 <index_bytes_per_pixel+0x56>
mov    -0xc(%rbp),%eax
sub    $0x500,%eax
je     11d2 <index_bytes_per_pixel+0xd2>
jmp    1169 <index_bytes_per_pixel+0x69>
mov    -0xc(%rbp),%eax
sub    $0x600,%eax
je     11de <index_bytes_per_pixel+0xde>
jmp    117c <index_bytes_per_pixel+0x7c>
mov    -0xc(%rbp),%eax
sub    $0x700,%eax
je     11ea <index_bytes_per_pixel+0xea>
jmp    118f <index_bytes_per_pixel+0x8f>
mov    -0xc(%rbp),%eax
sub    $0x800,%eax
je     11f6 <index_bytes_per_pixel+0xf6>
jmp    1202 <index_bytes_per_pixel+0x102>
movl   $0x1,-0x4(%rbp)
jmp    1209 <index_bytes_per_pixel+0x109>
movl   $0x1,-0x4(%rbp)
jmp    1209 <index_bytes_per_pixel+0x109>
movl   $0x2,-0x4(%rbp)
jmp    1209 <index_bytes_per_pixel+0x109>
movl   $0x2,-0x4(%rbp)
jmp    1209 <index_bytes_per_pixel+0x109>
movl   $0x3,-0x4(%rbp)
jmp    1209 <index_bytes_per_pixel+0x109>
movl   $0x4,-0x4(%rbp)
jmp    1209 <index_bytes_per_pixel+0x109>
movl   $0x4,-0x4(%rbp)
jmp    1209 <index_bytes_per_pixel+0x109>
movl   $0x2,-0x4(%rbp)
jmp    1209 <index_bytes_per_pixel+0x109>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<index_bytes_per_pixel>:
add    $0xffffff00,%edi
rol    $0x18,%edi
xor    %eax,%eax
cmp    $0x7,%edi
ja     111d <index_bytes_per_pixel+0x1d>
movslq %edi,%rax
lea    0xee6(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret

LLVM IR (-O0):
define i32 @index_bytes_per_pixel(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %13 [
i32 256, label %5
i32 512, label %6
i32 768, label %7
i32 1024, label %8
i32 1280, label %9
i32 1536, label %10
i32 1792, label %11
i32 2048, label %12
]
5: ; preds = %1
store i32 1, i32* %2
br label %14
6: ; preds = %1
store i32 1, i32* %2
br label %14
7: ; preds = %1
store i32 2, i32* %2
br label %14
8: ; preds = %1
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 4, i32* %2
br label %14
12: ; preds = %1
store i32 2, i32* %2
br label %14
13: ; preds = %1
store i32 0, i32* %2
br label %14
14: ; preds = %13, %12, %11, %10, %9, %8, %7, %6, %5
%15 = load i32, i32* %2
ret i32 %15
}

LLVM IR (-O2):
@switch.table.index_bytes_per_pixel = [8 x i32] [i32 1, i32 1, i32 2, i32 2, i32 3, i32 4, i32 4, i32 2]
define i32 @index_bytes_per_pixel(i32 %0) {
%2 = add i32 %0, -256
%3 = tail call i32 @llvm.fshl.i32(i32 %2, i32 %2, i32 24)
%4 = icmp ult i32 %3, 8
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds [8 x i32], [8 x i32]* @switch.table.index_bytes_per_pixel, i64 0, i64 %6
%8 = load i32, i32* %7
br label %9
9: ; preds = %1, %5
%10 = phi i32 [ %8, %5 ], [ 0, %1 ]
ret i32 %10
}