char *rnc_error(long errcode) {
  static char *const errors[] = {"No error",
                                 "File is not RNC-1 format",
                                 "Huffman decode error",
                                 "File size mismatch",
                                 "CRC error in packed data",
                                 "CRC error in unpacked data",
                                 "Unknown error"};
  errcode = -errcode;
  if (errcode < 0)
    errcode = 0;
  if (errcode > sizeof(errors) / sizeof(*errors) - 1)
    errcode = sizeof(errors) / sizeof(*errors) - 1;
  return errors[errcode];
}


x86 assembly (clang, -O0):
<rnc_error>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
sub    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    1125 <rnc_error+0x25>
movq   $0x0,-0x8(%rbp)
cmpq   $0x6,-0x8(%rbp)
jbe    1138 <rnc_error+0x38>
movq   $0x6,-0x8(%rbp)
mov    -0x8(%rbp),%rcx
lea    0x2ccd(%rip),%rax
mov    (%rax,%rcx,8),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<rnc_error>:
xor    %eax,%eax
neg    %rdi
cmovns %rdi,%rax
cmp    $0x6,%rax
mov    $0x6,%ecx
cmovb  %rax,%rcx
lea    0xee3(%rip),%rdx
movslq (%rdx,%rcx,4),%rax
add    %rdx,%rax
ret

LLVM IR (-O0):
@rnc_error.errors = internal constant [7 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([25 x i8], [25 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 ([19 x i8], [19 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i32 0, i32 0)]
@.str = [9 x i8] c"No error\00"
@.str.1 = [25 x i8] c"File is not RNC-1 format\00"
@.str.2 = [21 x i8] c"Huffman decode error\00"
@.str.3 = [19 x i8] c"File size mismatch\00"
@.str.4 = [25 x i8] c"CRC error in packed data\00"
@.str.5 = [27 x i8] c"CRC error in unpacked data\00"
@.str.6 = [14 x i8] c"Unknown error\00"
define i8* @rnc_error(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = sub nsw i64 0, %3
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i64 0, i64* %2
br label %8
8: ; preds = %7, %1
%9 = load i64, i64* %2
%10 = icmp ugt i64 %9, 6
br i1 %10, label %11, label %12
11: ; preds = %8
store i64 6, i64* %2
br label %12
12: ; preds = %11, %8
%13 = load i64, i64* %2
%14 = getelementptr inbounds [7 x i8*], [7 x i8*]* @rnc_error.errors, i64 0, i64 %13
%15 = load i8*, i8** %14
ret i8* %15
}

LLVM IR (-O2):
@reltable.rnc_error = internal unnamed_addr constant [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str to i64), i64 ptrtoint ([7 x i32]* @reltable.rnc_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([25 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.rnc_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.rnc_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.rnc_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([25 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.rnc_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.rnc_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.6 to i64), i64 ptrtoint ([7 x i32]* @reltable.rnc_error to i64)) to i32)]
@.str = [9 x i8] c"No error\00"
@.str.1 = [25 x i8] c"File is not RNC-1 format\00"
@.str.2 = [21 x i8] c"Huffman decode error\00"
@.str.3 = [19 x i8] c"File size mismatch\00"
@.str.4 = [25 x i8] c"CRC error in packed data\00"
@.str.5 = [27 x i8] c"CRC error in unpacked data\00"
@.str.6 = [14 x i8] c"Unknown error\00"
define i8* @rnc_error(i64 %0) {
%2 = sub nsw i64 0, %0
%3 = icmp sgt i64 %2, 0
%4 = select i1 %3, i64 %2, i64 0
%5 = icmp ult i64 %4, 6
%6 = select i1 %5, i64 %4, i64 6
%7 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.rnc_error to i8*), i64 %7)
ret i8* %8
}