#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
char const *strerror(int);
const char *elf_strerror(int err) {
  if (err >= 0)
    return strerror(err);
  switch (err) {
  case (-1):
    return "Not an ELF object";
  case (-2):
    return "Invalid ELF class";
  case (-3):
    return "Invalid ELF encoding";
  case (-4):
    return "Invalid ELF version";
  case (-5):
    return "Invalid ELF OS ABI";
  case (-6):
    return "Invalid ELF object type";
  case (-7):
    return "Not expected ELF object type";
  case (-8):
    return "ELF object is of unknown machine type";
  case (-9):
    return "Unexpected ELF section header size";
  }
  return "Not an ELF error";
}


x86 assembly (clang, -O0):
<elf_strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1136 <elf_strerror+0x26>
mov    -0xc(%rbp),%edi
call   1030 <strerror@plt>
mov    %rax,-0x8(%rbp)
jmp    11fa <elf_strerror+0xea>
mov    -0xc(%rbp),%eax
add    $0x9,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x8,%eax
ja     11ef <elf_strerror+0xdf>
mov    -0x18(%rbp),%rax
lea    0xeaa(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xebe(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fa <elf_strerror+0xea>
lea    0xec0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fa <elf_strerror+0xea>
lea    0xec2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fa <elf_strerror+0xea>
lea    0xec7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fa <elf_strerror+0xea>
lea    0xecb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fa <elf_strerror+0xea>
lea    0xece(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fa <elf_strerror+0xea>
lea    0xed6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fa <elf_strerror+0xea>
lea    0xee3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fa <elf_strerror+0xea>
lea    0xef9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fa <elf_strerror+0xea>
lea    0xf0c(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elf_strerror>:
test   %edi,%edi
js     1119 <elf_strerror+0x9>
jmp    1030 <strerror@plt>
cmp    $0xfffffff7,%edi
jb     1133 <elf_strerror+0x23>
add    $0x9,%edi
movslq %edi,%rax
lea    0xfc5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xfa4(%rip),%rax
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Not an ELF object\00"
@.str.1 = [18 x i8] c"Invalid ELF class\00"
@.str.2 = [21 x i8] c"Invalid ELF encoding\00"
@.str.3 = [20 x i8] c"Invalid ELF version\00"
@.str.4 = [19 x i8] c"Invalid ELF OS ABI\00"
@.str.5 = [24 x i8] c"Invalid ELF object type\00"
@.str.6 = [29 x i8] c"Not expected ELF object type\00"
@.str.7 = [38 x i8] c"ELF object is of unknown machine type\00"
@.str.8 = [35 x i8] c"Unexpected ELF section header size\00"
@.str.9 = [17 x i8] c"Not an ELF error\00"
define i8* @elf_strerror(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sge i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* %3
%8 = call i8* @strerror(i32 %7)
store i8* %8, i8** %2
br label %21
9: ; preds = %1
%10 = load i32, i32* %3
switch i32 %10, label %20 [
i32 -1, label %11
i32 -2, label %12
i32 -3, label %13
i32 -4, label %14
i32 -5, label %15
i32 -6, label %16
i32 -7, label %17
i32 -8, label %18
i32 -9, label %19
]
11: ; preds = %9
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %2
br label %21
12: ; preds = %9
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %21
13: ; preds = %9
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %21
14: ; preds = %9
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %21
15: ; preds = %9
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %21
16: ; preds = %9
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %21
17: ; preds = %9
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %21
18: ; preds = %9
store i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %21
19: ; preds = %9
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8** %2
br label %21
20: ; preds = %9
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i8** %2
br label %21
21: ; preds = %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %6
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@.str = [18 x i8] c"Not an ELF object\00"
@.str.1 = [18 x i8] c"Invalid ELF class\00"
@.str.2 = [21 x i8] c"Invalid ELF encoding\00"
@.str.3 = [20 x i8] c"Invalid ELF version\00"
@.str.4 = [19 x i8] c"Invalid ELF OS ABI\00"
@.str.5 = [24 x i8] c"Invalid ELF object type\00"
@.str.6 = [29 x i8] c"Not expected ELF object type\00"
@.str.7 = [38 x i8] c"ELF object is of unknown machine type\00"
@.str.8 = [35 x i8] c"Unexpected ELF section header size\00"
@.str.9 = [17 x i8] c"Not an ELF error\00"
@reltable.elf_strerror = [9 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([35 x i8]* @.str.8 to i64), i64 ptrtoint ([9 x i32]* @reltable.elf_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([38 x i8]* @.str.7 to i64), i64 ptrtoint ([9 x i32]* @reltable.elf_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([29 x i8]* @.str.6 to i64), i64 ptrtoint ([9 x i32]* @reltable.elf_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.5 to i64), i64 ptrtoint ([9 x i32]* @reltable.elf_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.4 to i64), i64 ptrtoint ([9 x i32]* @reltable.elf_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.3 to i64), i64 ptrtoint ([9 x i32]* @reltable.elf_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.2 to i64), i64 ptrtoint ([9 x i32]* @reltable.elf_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.1 to i64), i64 ptrtoint ([9 x i32]* @reltable.elf_strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str to i64), i64 ptrtoint ([9 x i32]* @reltable.elf_strerror to i64)) to i32)]
define i8* @elf_strerror(i32 %0) {
%2 = icmp sgt i32 %0, -1
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i8* @strerror(i32 %0)
br label %12
5: ; preds = %1
%6 = icmp ugt i32 %0, -10
br i1 %6, label %7, label %12
7: ; preds = %5
%8 = add i32 %0, 9
%9 = sext i32 %8 to i64
%10 = shl i64 %9, 2
%11 = call i8* @llvm.load.relative.i64(i8* bitcast ([9 x i32]* @reltable.elf_strerror to i8*), i64 %10)
br label %12
12: ; preds = %5, %7, %3
%13 = phi i8* [ %4, %3 ], [ %11, %7 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), %5 ]
ret i8* %13
}