const char *level_to_str(int level) {
  const char *map[] = {"Debug", "Info", "Warning", "Error"};
  if (level < 0 || level >= 4)
    return "Unknown";
  return map[level];
}


x86 assembly (clang, -O0):
<level_to_str>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    0x2d22(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d1f(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d1c(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2d19(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1147 <level_to_str+0x47>
cmpl   $0x4,-0xc(%rbp)
jl     1157 <level_to_str+0x57>
lea    0xecb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1164 <level_to_str+0x64>
movslq -0xc(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<level_to_str>:
cmp    $0x3,%edi
jbe    110d <level_to_str+0xd>
lea    0xf0d(%rip),%rax
ret
mov    %edi,%eax
lea    0xf0e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Debug\00"
@.str.1 = [5 x i8] c"Info\00"
@.str.2 = [8 x i8] c"Warning\00"
@.str.3 = [6 x i8] c"Error\00"
@__const.level_to_str.map = [4 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 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 ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0)]
@.str.4 = [8 x i8] c"Unknown\00"
define i8* @level_to_str(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [4 x i8*]
store i32 %0, i32* %3
%5 = bitcast [4 x i8*]* %4 to i8*
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i32, i32* %3
%10 = icmp sge i32 %9, 4
br i1 %10, label %11, label %12
11: ; preds = %8, %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %17
12: ; preds = %8
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 %14
%16 = load i8*, i8** %15
store i8* %16, i8** %2
br label %17
17: ; preds = %12, %11
%18 = load i8*, i8** %2
ret i8* %18
}

LLVM IR (-O2):
@.str = [6 x i8] c"Debug\00"
@.str.1 = [5 x i8] c"Info\00"
@.str.2 = [8 x i8] c"Warning\00"
@.str.3 = [6 x i8] c"Error\00"
@reltable.level_to_str = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.level_to_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.level_to_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.level_to_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.level_to_str to i64)) to i32)]
@.str.4 = [8 x i8] c"Unknown\00"
define i8* @level_to_str(i32 %0) {
%2 = icmp ugt i32 %0, 3
br i1 %2, label %7, label %3
3: ; preds = %1
%4 = zext i32 %0 to i64
%5 = shl i64 %4, 2
%6 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.level_to_str 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.4, i64 0, i64 0), %1 ]
ret i8* %8
}