const char *celt_strerror(int error) {
  static const char *error_strings[8] = {
      "success",        "invalid argument",        "invalid mode",
      "internal error", "corrupted stream",        "request not implemented",
      "invalid state",  "memory allocation failed"};
  if (error > 0 || error < -7)
    return "unknown error";
  else
    return error_strings[-error];
}


x86 assembly (clang, -O0):
<celt_strerror>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     111b <celt_strerror+0x1b>
cmpl   $0xfffffff9,-0xc(%rbp)
jge    112b <celt_strerror+0x2b>
lea    0xf63(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1142 <celt_strerror+0x42>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
movslq %eax,%rcx
lea    0x2ef6(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<celt_strerror>:
lea    -0x1(%rdi),%eax
cmp    $0xfffffff8,%eax
jae    1110 <celt_strerror+0x10>
lea    0xf96(%rip),%rax
ret
neg    %edi
lea    0xee7(%rip),%rcx
movslq (%rcx,%rdi,4),%rax
add    %rcx,%rax
ret

LLVM IR (-O0):
@celt_strerror.error_strings = internal global [8 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 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 ([15 x i8], [15 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 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 ([14 x i8], [14 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i32 0, i32 0)]
@.str = [8 x i8] c"success\00"
@.str.1 = [17 x i8] c"invalid argument\00"
@.str.2 = [13 x i8] c"invalid mode\00"
@.str.3 = [15 x i8] c"internal error\00"
@.str.4 = [17 x i8] c"corrupted stream\00"
@.str.5 = [24 x i8] c"request not implemented\00"
@.str.6 = [14 x i8] c"invalid state\00"
@.str.7 = [25 x i8] c"memory allocation failed\00"
@.str.8 = [14 x i8] c"unknown error\00"
define i8* @celt_strerror(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sgt i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, -7
br i1 %8, label %9, label %10
9: ; preds = %6, %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8** %2
br label %16
10: ; preds = %6
%11 = load i32, i32* %3
%12 = sub nsw i32 0, %11
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [8 x i8*], [8 x i8*]* @celt_strerror.error_strings, i64 0, i64 %13
%15 = load i8*, i8** %14
store i8* %15, i8** %2
br label %16
16: ; preds = %10, %9
%17 = load i8*, i8** %2
ret i8* %17
}

LLVM IR (-O2):
@reltable.celt_strerror = internal unnamed_addr constant [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([8 x i32]* @reltable.celt_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.celt_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.celt_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.celt_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.celt_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.celt_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.6 to i64), i64 ptrtoint ([8 x i32]* @reltable.celt_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([25 x i8]* @.str.7 to i64), i64 ptrtoint ([8 x i32]* @reltable.celt_strerror to i64)) to i32)]
@.str = [8 x i8] c"success\00"
@.str.1 = [17 x i8] c"invalid argument\00"
@.str.2 = [13 x i8] c"invalid mode\00"
@.str.3 = [15 x i8] c"internal error\00"
@.str.4 = [17 x i8] c"corrupted stream\00"
@.str.5 = [24 x i8] c"request not implemented\00"
@.str.6 = [14 x i8] c"invalid state\00"
@.str.7 = [25 x i8] c"memory allocation failed\00"
@.str.8 = [14 x i8] c"unknown error\00"
define i8* @celt_strerror(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp ult i32 %2, -8
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = sub nsw i32 0, %0
%6 = zext i32 %5 to i64
%7 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.celt_strerror to i8*), i64 %7)
br label %9
9: ; preds = %1, %4
%10 = phi i8* [ %8, %4 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), %1 ]
ret i8* %10
}