const char *index_name(unsigned index) {
  switch (index) {
  case 0x0100:
    return "palette8";
  case 0x0200:
    return "bgr8";
  case 0x0300:
    return "bgr15";
  case 0x0400:
    return "bgr16";
  case 0x0500:
    return "bgr24";
  case 0x0600:
    return "bgr32";
  case 0x0700:
    return "yuy2";
  case 0x0800:
    return "text";
  default:
    return "unknown";
  }
}


x86 assembly (clang, -O0):
<index_name>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x100,%eax
je     11a2 <index_name+0xa2>
jmp    111d <index_name+0x1d>
mov    -0x10(%rbp),%eax
sub    $0x200,%eax
je     11b2 <index_name+0xb2>
jmp    1130 <index_name+0x30>
mov    -0x10(%rbp),%eax
sub    $0x300,%eax
je     11c2 <index_name+0xc2>
jmp    1143 <index_name+0x43>
mov    -0x10(%rbp),%eax
sub    $0x400,%eax
je     11d2 <index_name+0xd2>
jmp    1156 <index_name+0x56>
mov    -0x10(%rbp),%eax
sub    $0x500,%eax
je     11e2 <index_name+0xe2>
jmp    1169 <index_name+0x69>
mov    -0x10(%rbp),%eax
sub    $0x600,%eax
je     11f2 <index_name+0xf2>
jmp    117c <index_name+0x7c>
mov    -0x10(%rbp),%eax
sub    $0x700,%eax
je     1202 <index_name+0x102>
jmp    118f <index_name+0x8f>
mov    -0x10(%rbp),%eax
sub    $0x800,%eax
je     1212 <index_name+0x112>
jmp    1222 <index_name+0x122>
lea    0xe57(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    122d <index_name+0x12d>
lea    0xe50(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    122d <index_name+0x12d>
lea    0xe45(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    122d <index_name+0x12d>
lea    0xe3b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    122d <index_name+0x12d>
lea    0xe31(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    122d <index_name+0x12d>
lea    0xe27(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    122d <index_name+0x12d>
lea    0xe1d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    122d <index_name+0x12d>
lea    0xe12(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    122d <index_name+0x12d>
lea    0xe07(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<index_name>:
add    $0xffffff00,%edi
rol    $0x18,%edi
cmp    $0x7,%edi
ja     1120 <index_name+0x20>
movslq %edi,%rax
lea    0xf20(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xf09(%rip),%rax
ret

LLVM IR (-O0):
@.str = [9 x i8] c"palette8\00"
@.str.1 = [5 x i8] c"bgr8\00"
@.str.2 = [6 x i8] c"bgr15\00"
@.str.3 = [6 x i8] c"bgr16\00"
@.str.4 = [6 x i8] c"bgr24\00"
@.str.5 = [6 x i8] c"bgr32\00"
@.str.6 = [5 x i8] c"yuy2\00"
@.str.7 = [5 x i8] c"text\00"
@.str.8 = [8 x i8] c"unknown\00"
define i8* @index_name(i32 %0) {
%2 = alloca i8*
%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 i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2
br label %14
6: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %14
7: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %14
8: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %14
9: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %14
10: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %14
11: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %14
12: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %14
13: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8** %2
br label %14
14: ; preds = %13, %12, %11, %10, %9, %8, %7, %6, %5
%15 = load i8*, i8** %2
ret i8* %15
}

LLVM IR (-O2):
@.str = [9 x i8] c"palette8\00"
@.str.1 = [5 x i8] c"bgr8\00"
@.str.2 = [6 x i8] c"bgr15\00"
@.str.3 = [6 x i8] c"bgr16\00"
@.str.4 = [6 x i8] c"bgr24\00"
@.str.5 = [6 x i8] c"bgr32\00"
@.str.6 = [5 x i8] c"yuy2\00"
@.str.7 = [5 x i8] c"text\00"
@.str.8 = [8 x i8] c"unknown\00"
@reltable.index_name = [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str to i64), i64 ptrtoint ([8 x i32]* @reltable.index_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.index_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.index_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.index_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.index_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.index_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.6 to i64), i64 ptrtoint ([8 x i32]* @reltable.index_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.7 to i64), i64 ptrtoint ([8 x i32]* @reltable.index_name to i64)) to i32)]
define i8* @index_name(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 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.index_name to i8*), i64 %7)
br label %9
9: ; preds = %1, %5
%10 = phi i8* [ %8, %5 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), %1 ]
ret i8* %10
}