const char *ctf_get_error_string(int error) {
  static const char *strings[] = {
      "OK.",
      "File not found.",
      "ELF header is corrupted.",
      "ELF version is wrong.",
      "Unable to open the ELF file.",
      "The '.SUNW_ctf' section was not found.",
      "The string table was not found.",
      "The symbol table was not found.",
      "Unable to decompress the data.",
      "Decompressed data is corrupted.",
      "Unable to find required label in the parent file.",
      "Wrong CTF magic number.",
      "Wrong CTF version.",
      "Label section is corrupted.",
      "Not found.",
      "End of the list.",
      "Null pointer.",
      "Sections offsets corrupted.",
      "Kind invalid.",
      "Type ID not found.",
      "Conversion fault."};
  if (error < 0 || error > 21)
    return "Unknown error.";
  else
    return strings[error];
}


x86 assembly (clang, -O0):
<ctf_get_error_string>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     111b <ctf_get_error_string+0x1b>
cmpl   $0x15,-0xc(%rbp)
jle    112b <ctf_get_error_string+0x2b>
lea    0x10d6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    113e <ctf_get_error_string+0x3e>
movslq -0xc(%rbp),%rcx
lea    0x2efa(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ctf_get_error_string>:
cmp    $0x15,%edi
jbe    110d <ctf_get_error_string+0xd>
lea    0x1140(%rip),%rax
ret
mov    %edi,%eax
lea    0xeea(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret

LLVM IR (-O0):
@ctf_get_error_string.strings = internal global [21 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.18, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.19, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.20, i32 0, i32 0)]
@.str = [4 x i8] c"OK.\00"
@.str.1 = [16 x i8] c"File not found.\00"
@.str.2 = [25 x i8] c"ELF header is corrupted.\00"
@.str.3 = [22 x i8] c"ELF version is wrong.\00"
@.str.4 = [29 x i8] c"Unable to open the ELF file.\00"
@.str.5 = [39 x i8] c"The '.SUNW_ctf' section was not found.\00"
@.str.6 = [32 x i8] c"The string table was not found.\00"
@.str.7 = [32 x i8] c"The symbol table was not found.\00"
@.str.8 = [31 x i8] c"Unable to decompress the data.\00"
@.str.9 = [32 x i8] c"Decompressed data is corrupted.\00"
@.str.10 = [50 x i8] c"Unable to find required label in the parent file.\00"
@.str.11 = [24 x i8] c"Wrong CTF magic number.\00"
@.str.12 = [19 x i8] c"Wrong CTF version.\00"
@.str.13 = [28 x i8] c"Label section is corrupted.\00"
@.str.14 = [11 x i8] c"Not found.\00"
@.str.15 = [17 x i8] c"End of the list.\00"
@.str.16 = [14 x i8] c"Null pointer.\00"
@.str.17 = [28 x i8] c"Sections offsets corrupted.\00"
@.str.18 = [14 x i8] c"Kind invalid.\00"
@.str.19 = [19 x i8] c"Type ID not found.\00"
@.str.20 = [18 x i8] c"Conversion fault.\00"
@.str.21 = [15 x i8] c"Unknown error.\00"
define i8* @ctf_get_error_string(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 21
br i1 %8, label %9, label %10
9: ; preds = %6, %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.21, i64 0, i64 0), i8** %2
br label %15
10: ; preds = %6
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [21 x i8*], [21 x i8*]* @ctf_get_error_string.strings, i64 0, i64 %12
%14 = load i8*, i8** %13
store i8* %14, i8** %2
br label %15
15: ; preds = %10, %9
%16 = load i8*, i8** %2
ret i8* %16
}

LLVM IR (-O2):
@reltable.ctf_get_error_string = internal unnamed_addr constant [21 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.1 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([25 x i8]* @.str.2 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.3 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([29 x i8]* @.str.4 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([39 x i8]* @.str.5 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @.str.6 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @.str.7 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([31 x i8]* @.str.8 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @.str.9 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([50 x i8]* @.str.10 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.11 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.12 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([28 x i8]* @.str.13 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.14 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.15 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.16 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([28 x i8]* @.str.17 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.18 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.19 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.20 to i64), i64 ptrtoint ([21 x i32]* @reltable.ctf_get_error_string to i64)) to i32)]
@.str = [4 x i8] c"OK.\00"
@.str.1 = [16 x i8] c"File not found.\00"
@.str.2 = [25 x i8] c"ELF header is corrupted.\00"
@.str.3 = [22 x i8] c"ELF version is wrong.\00"
@.str.4 = [29 x i8] c"Unable to open the ELF file.\00"
@.str.5 = [39 x i8] c"The '.SUNW_ctf' section was not found.\00"
@.str.6 = [32 x i8] c"The string table was not found.\00"
@.str.7 = [32 x i8] c"The symbol table was not found.\00"
@.str.8 = [31 x i8] c"Unable to decompress the data.\00"
@.str.9 = [32 x i8] c"Decompressed data is corrupted.\00"
@.str.10 = [50 x i8] c"Unable to find required label in the parent file.\00"
@.str.11 = [24 x i8] c"Wrong CTF magic number.\00"
@.str.12 = [19 x i8] c"Wrong CTF version.\00"
@.str.13 = [28 x i8] c"Label section is corrupted.\00"
@.str.14 = [11 x i8] c"Not found.\00"
@.str.15 = [17 x i8] c"End of the list.\00"
@.str.16 = [14 x i8] c"Null pointer.\00"
@.str.17 = [28 x i8] c"Sections offsets corrupted.\00"
@.str.18 = [14 x i8] c"Kind invalid.\00"
@.str.19 = [19 x i8] c"Type ID not found.\00"
@.str.20 = [18 x i8] c"Conversion fault.\00"
@.str.21 = [15 x i8] c"Unknown error.\00"
define i8* @ctf_get_error_string(i32 %0) {
%2 = icmp ugt i32 %0, 21
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 ([21 x i32]* @reltable.ctf_get_error_string to i8*), i64 %5)
br label %7
7: ; preds = %1, %3
%8 = phi i8* [ %6, %3 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.21, i64 0, i64 0), %1 ]
ret i8* %8
}