char *errstr(int errnum) {
  char *errlist[] = {"Duplicate label `%s'",
                     "No file name specified",
                     "Can't open file `%s'",
                     "Unknown command `%s'",
                     "Out of memory!",
                     "Duplicate variable `%s'",
                     "Unknown variable `%s'",
                     "Expected math symbol, not `%s'",
                     "Missing relational operator",
                     "Missing colon in statement",
                     "Unknown label: `%s'",
                     "Unknown relational operator: `%s'",
                     "No equal sign in assignment",
                     "Missing right parentheses in conditional expression",
                     "Cannot assign value to constant `%s'",
                     "Missing command line argument after `%s'"};
  if (errnum >= 0) {
    return errlist[errnum];
  } else {
    return "";
  }
}


x86 assembly (clang, -O0):
<errstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0xc(%rbp)
lea    -0x90(%rbp),%rdi
lea    0x2c74(%rip),%rsi
mov    $0x80,%edx
call   1030 <memcpy@plt>
cmpl   $0x0,-0xc(%rbp)
jl     1155 <errstr+0x45>
movslq -0xc(%rbp),%rax
mov    -0x90(%rbp,%rax,8),%rax
ff
mov    %rax,-0x8(%rbp)
jmp    1160 <errstr+0x50>
lea    0xf08(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<errstr>:
test   %edi,%edi
js     1115 <errstr+0x15>
mov    %edi,%eax
lea    0x10b3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xf48(%rip),%rax
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Duplicate label `%s'\00"
@.str.1 = [23 x i8] c"No file name specified\00"
@.str.2 = [21 x i8] c"Can't open file `%s'\00"
@.str.3 = [21 x i8] c"Unknown command `%s'\00"
@.str.4 = [15 x i8] c"Out of memory!\00"
@.str.5 = [24 x i8] c"Duplicate variable `%s'\00"
@.str.6 = [22 x i8] c"Unknown variable `%s'\00"
@.str.7 = [31 x i8] c"Expected math symbol, not `%s'\00"
@.str.8 = [28 x i8] c"Missing relational operator\00"
@.str.9 = [27 x i8] c"Missing colon in statement\00"
@.str.10 = [20 x i8] c"Unknown label: `%s'\00"
@.str.11 = [34 x i8] c"Unknown relational operator: `%s'\00"
@.str.12 = [28 x i8] c"No equal sign in assignment\00"
@.str.13 = [52 x i8] c"Missing right parentheses in conditional expression\00"
@.str.14 = [37 x i8] c"Cannot assign value to constant `%s'\00"
@.str.15 = [41 x i8] c"Missing command line argument after `%s'\00"
@__const.errstr.errlist = [16 x i8*] [i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 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 ([24 x i8], [24 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.15, i32 0, i32 0)]
@.str.16 = [1 x i8] zeroinitializer
define i8* @errstr(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [16 x i8*]
store i32 %0, i32* %3
%5 = bitcast [16 x i8*]* %4 to i8*
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [16 x i8*], [16 x i8*]* %4, i64 0, i64 %10
%12 = load i8*, i8** %11
store i8* %12, i8** %2
br label %14
13: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.16, i64 0, i64 0), i8** %2
br label %14
14: ; preds = %13, %8
%15 = load i8*, i8** %2
ret i8* %15
}

LLVM IR (-O2):
@.str = [21 x i8] c"Duplicate label `%s'\00"
@.str.1 = [23 x i8] c"No file name specified\00"
@.str.2 = [21 x i8] c"Can't open file `%s'\00"
@.str.3 = [21 x i8] c"Unknown command `%s'\00"
@.str.4 = [15 x i8] c"Out of memory!\00"
@.str.5 = [24 x i8] c"Duplicate variable `%s'\00"
@.str.6 = [22 x i8] c"Unknown variable `%s'\00"
@.str.7 = [31 x i8] c"Expected math symbol, not `%s'\00"
@.str.8 = [28 x i8] c"Missing relational operator\00"
@.str.9 = [27 x i8] c"Missing colon in statement\00"
@.str.10 = [20 x i8] c"Unknown label: `%s'\00"
@.str.11 = [34 x i8] c"Unknown relational operator: `%s'\00"
@.str.12 = [28 x i8] c"No equal sign in assignment\00"
@.str.13 = [52 x i8] c"Missing right parentheses in conditional expression\00"
@.str.14 = [37 x i8] c"Cannot assign value to constant `%s'\00"
@.str.15 = [41 x i8] c"Missing command line argument after `%s'\00"
@reltable.errstr = [16 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.1 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.2 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.3 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.4 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.5 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.6 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([31 x i8]* @.str.7 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([28 x i8]* @.str.8 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @.str.9 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.10 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([34 x i8]* @.str.11 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([28 x i8]* @.str.12 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([52 x i8]* @.str.13 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([37 x i8]* @.str.14 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([41 x i8]* @.str.15 to i64), i64 ptrtoint ([16 x i32]* @reltable.errstr to i64)) to i32)]
@.str.16 = [1 x i8] zeroinitializer
define i8* @errstr(i32 %0) {
%2 = icmp sgt i32 %0, -1
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 ([16 x i32]* @reltable.errstr to i8*), i64 %5)
br label %7
7: ; preds = %1, %3
%8 = phi i8* [ %6, %3 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.16, i64 0, i64 0), %1 ]
ret i8* %8
}