const char *FungELF_strerror(int rc) {
  switch (rc) {
  case -1:
    return "File too short";
  case -2:
    return "Wrong file layout";
  case -3:
    return "Error reading ELF headers";
  case -4:
    return "Error reading text section";
  }
  if (rc >= 0)
    return "No error";
  if (rc < 0)
    return "Unknown error";
}


x86 assembly (clang, -O0):
<FungELF_strerror>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x4,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     1170 <FungELF_strerror+0x70>
mov    -0x18(%rbp),%rax
lea    0xed9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xed9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <FungELF_strerror+0x9f>
lea    0xed8(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <FungELF_strerror+0x9f>
lea    0xeda(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <FungELF_strerror+0x9f>
lea    0xee4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <FungELF_strerror+0x9f>
cmpl   $0x0,-0xc(%rbp)
jl     118a <FungELF_strerror+0x8a>
lea    0xee5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <FungELF_strerror+0x9f>
cmpl   $0x0,-0xc(%rbp)
jge    119f <FungELF_strerror+0x9f>
lea    0xed4(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<FungELF_strerror>:
cmp    $0xfffffffb,%edi
jbe    111a <FungELF_strerror+0x1a>
add    $0x4,%edi
movslq %edi,%rax
lea    0xf5e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
test   %edi,%edi
lea    0xf33(%rip),%rcx
lea    0xf35(%rip),%rax
cmovns %rcx,%rax
ret

LLVM IR (-O0):
@.str = [15 x i8] c"File too short\00"
@.str.1 = [18 x i8] c"Wrong file layout\00"
@.str.2 = [26 x i8] c"Error reading ELF headers\00"
@.str.3 = [27 x i8] c"Error reading text section\00"
@.str.4 = [9 x i8] c"No error\00"
@.str.5 = [14 x i8] c"Unknown error\00"
define i8* @FungELF_strerror(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %9 [
i32 -1, label %5
i32 -2, label %6
i32 -3, label %7
i32 -4, label %8
]
5: ; preds = %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %2
br label %17
6: ; preds = %1
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %17
7: ; preds = %1
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %17
8: ; preds = %1
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %17
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %17
13: ; preds = %9
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %17
17: ; preds = %5, %6, %7, %8, %12, %16, %13
%18 = load i8*, i8** %2
ret i8* %18
}

LLVM IR (-O2):
@.str = [15 x i8] c"File too short\00"
@.str.1 = [18 x i8] c"Wrong file layout\00"
@.str.2 = [26 x i8] c"Error reading ELF headers\00"
@.str.3 = [27 x i8] c"Error reading text section\00"
@.str.4 = [9 x i8] c"No error\00"
@.str.5 = [14 x i8] c"Unknown error\00"
@reltable.FungELF_strerror = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.FungELF_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([26 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.FungELF_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.FungELF_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.FungELF_strerror to i64)) to i32)]
define i8* @FungELF_strerror(i32 %0) {
%2 = icmp ugt i32 %0, -5
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = icmp sgt i32 %0, -1
%5 = select i1 %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0)
br label %11
6: ; preds = %1
%7 = add i32 %0, 4
%8 = sext i32 %7 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.FungELF_strerror to i8*), i64 %9)
br label %11
11: ; preds = %6, %3
%12 = phi i8* [ %5, %3 ], [ %10, %6 ]
ret i8* %12
}