char *convert_policy(const unsigned int policy) {
  static char *policy_names[] = {"normal", "fifo", "rr",
                                 "batch",  "iso",  "idle"};
  if (policy < 6)
    return policy_names[policy];
  return "unknown";
}


x86 assembly (clang, -O0):
<convert_policy>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
cmpl   $0x6,-0xc(%rbp)
jae    112a <convert_policy+0x2a>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
lea    0x2f13(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    1135 <convert_policy+0x35>
lea    0xeed(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_policy>:
cmp    $0x5,%edi
ja     1116 <convert_policy+0x16>
mov    %edi,%eax
lea    0xef2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xf19(%rip),%rax
ret

LLVM IR (-O0):
@convert_policy.policy_names = internal global [6 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0)]
@.str = [7 x i8] c"normal\00"
@.str.1 = [5 x i8] c"fifo\00"
@.str.2 = [3 x i8] c"rr\00"
@.str.3 = [6 x i8] c"batch\00"
@.str.4 = [4 x i8] c"iso\00"
@.str.5 = [5 x i8] c"idle\00"
@.str.6 = [8 x i8] c"unknown\00"
define i8* @convert_policy(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp ult i32 %4, 6
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* %3
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds [6 x i8*], [6 x i8*]* @convert_policy.policy_names, i64 0, i64 %8
%10 = load i8*, i8** %9
store i8* %10, i8** %2
br label %12
11: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %12
12: ; preds = %11, %6
%13 = load i8*, i8** %2
ret i8* %13
}

LLVM IR (-O2):
@reltable.convert_policy = internal unnamed_addr constant [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str to i64), i64 ptrtoint ([6 x i32]* @reltable.convert_policy to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([6 x i32]* @reltable.convert_policy to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.2 to i64), i64 ptrtoint ([6 x i32]* @reltable.convert_policy to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.convert_policy to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.convert_policy to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.convert_policy to i64)) to i32)]
@.str = [7 x i8] c"normal\00"
@.str.1 = [5 x i8] c"fifo\00"
@.str.2 = [3 x i8] c"rr\00"
@.str.3 = [6 x i8] c"batch\00"
@.str.4 = [4 x i8] c"iso\00"
@.str.5 = [5 x i8] c"idle\00"
@.str.6 = [8 x i8] c"unknown\00"
define i8* @convert_policy(i32 %0) {
%2 = icmp ult i32 %0, 6
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = zext i32 %0 to i64
%5 = shl i64 %4, 2
%6 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.convert_policy to i8*), i64 %5)
br label %7
7: ; preds = %1, %3
%8 = phi i8* [ %6, %3 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %1 ]
ret i8* %8
}