const char *get_err_str(int type) {
  static const char *name[] = {
      [0] = "begin-array", [1] = "end-array",      [2] = "begin-object",
      [3] = "end-object",  [4] = "name-separator", [5] = "value-separator",
      [6] = "string",      [7] = "number",         [8] = "boolean",
      [9] = "null",
  };
  return name[type];
}


x86 assembly (clang, -O0):
<get_err_str>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rcx
lea    0x2f1e(%rip),%rax
mov    (%rax,%rcx,8),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_err_str>:
movslq %edi,%rax
lea    0xef6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret

LLVM IR (-O0):
@get_err_str.name = internal global [10 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i32 0, i32 0)]
@.str = [12 x i8] c"begin-array\00"
@.str.1 = [10 x i8] c"end-array\00"
@.str.2 = [13 x i8] c"begin-object\00"
@.str.3 = [11 x i8] c"end-object\00"
@.str.4 = [15 x i8] c"name-separator\00"
@.str.5 = [16 x i8] c"value-separator\00"
@.str.6 = [7 x i8] c"string\00"
@.str.7 = [7 x i8] c"number\00"
@.str.8 = [8 x i8] c"boolean\00"
@.str.9 = [5 x i8] c"null\00"
define i8* @get_err_str(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds [10 x i8*], [10 x i8*]* @get_err_str.name, i64 0, i64 %4
%6 = load i8*, i8** %5
ret i8* %6
}

LLVM IR (-O2):
@reltable.get_err_str = internal unnamed_addr constant [10 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str to i64), i64 ptrtoint ([10 x i32]* @reltable.get_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.1 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.2 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.3 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.4 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.5 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.6 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.7 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.8 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_err_str to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.9 to i64), i64 ptrtoint ([10 x i32]* @reltable.get_err_str to i64)) to i32)]
@.str = [12 x i8] c"begin-array\00"
@.str.1 = [10 x i8] c"end-array\00"
@.str.2 = [13 x i8] c"begin-object\00"
@.str.3 = [11 x i8] c"end-object\00"
@.str.4 = [15 x i8] c"name-separator\00"
@.str.5 = [16 x i8] c"value-separator\00"
@.str.6 = [7 x i8] c"string\00"
@.str.7 = [7 x i8] c"number\00"
@.str.8 = [8 x i8] c"boolean\00"
@.str.9 = [5 x i8] c"null\00"
define i8* @get_err_str(i32 %0) {
%2 = sext i32 %0 to i64
%3 = shl i64 %2, 2
%4 = call i8* @llvm.load.relative.i64(i8* bitcast ([10 x i32]* @reltable.get_err_str to i8*), i64 %3)
ret i8* %4
}