#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 */
#define EACCES 144
#define EAGAIN 143
#define EBADF 142
#define EFAULT 141
#define EINTR 140
#define EINVAL 139
#define EIO 138
#define EISDIR 137
#define ELOOP 136
#define EMFILE 135
#define ENAMETOOLONG 134
#define ENFILE 133
#define ENODEV 132
#define ENOENT 131
#define ENOMEM 130
#define EOVERFLOW 129
#define EPERM 128
char *ltoa(int);
char *strerror(int err) {
  switch (err) {
  case EAGAIN:
    return "EAGAIN";
  case EPERM:
    return "EPERM";
  case EFAULT:
    return "EFAULT";
  case EINVAL:
    return "EINVAL";
  case ELOOP:
    return "ELOOP";
  case EACCES:
    return "EACCES";
  case EISDIR:
    return "EISDIR";
  case EMFILE:
    return "EMFILE";
  case ENFILE:
    return "ENFILE";
  case ENOENT:
    return "ENOENT";
  case ENOMEM:
    return "ENOMEM";
  case ENAMETOOLONG:
    return "ENAMETOOLONG";
  case ENODEV:
    return "ENODEV";
  case EOVERFLOW:
    return "EOVERFLOW";
  case EINTR:
    return "EINTR";
  case EIO:
    return "EIO";
  case EBADF:
    return "EBADF";
  default:
    return ltoa(err);
  }
}


x86 assembly (clang, -O0):
<strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x10,%eax
ja     1254 <strerror+0x144>
mov    -0x18(%rbp),%rax
lea    0xec5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xef9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xef0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xee6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xedd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xed4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xeca(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xec1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xeb8(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xeaf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xea6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xe9d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xe94(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xe91(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xe88(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xe82(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xe78(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
lea    0xe6c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <strerror+0x150>
mov    -0xc(%rbp),%edi
call   1030 <ltoa@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strerror>:
lea    -0x80(%rdi),%eax
cmp    $0x11,%eax
jae    1129 <strerror+0x19>
cltq
lea    0xf5b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
jmp    1030 <ltoa@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"EAGAIN\00"
@.str.1 = [6 x i8] c"EPERM\00"
@.str.2 = [7 x i8] c"EFAULT\00"
@.str.3 = [7 x i8] c"EINVAL\00"
@.str.4 = [6 x i8] c"ELOOP\00"
@.str.5 = [7 x i8] c"EACCES\00"
@.str.6 = [7 x i8] c"EISDIR\00"
@.str.7 = [7 x i8] c"EMFILE\00"
@.str.8 = [7 x i8] c"ENFILE\00"
@.str.9 = [7 x i8] c"ENOENT\00"
@.str.10 = [7 x i8] c"ENOMEM\00"
@.str.11 = [13 x i8] c"ENAMETOOLONG\00"
@.str.12 = [7 x i8] c"ENODEV\00"
@.str.13 = [10 x i8] c"EOVERFLOW\00"
@.str.14 = [6 x i8] c"EINTR\00"
@.str.15 = [4 x i8] c"EIO\00"
@.str.16 = [6 x i8] c"EBADF\00"
define i8* @strerror(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %22 [
i32 143, label %5
i32 128, label %6
i32 141, label %7
i32 139, label %8
i32 136, label %9
i32 144, label %10
i32 137, label %11
i32 135, label %12
i32 133, label %13
i32 131, label %14
i32 130, label %15
i32 134, label %16
i32 132, label %17
i32 129, label %18
i32 140, label %19
i32 138, label %20
i32 142, label %21
]
5: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %2
br label %25
6: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %25
7: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %25
8: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %25
9: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %25
10: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %25
11: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %25
12: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %25
13: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8** %2
br label %25
14: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8** %2
br label %25
15: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i8** %2
br label %25
16: ; preds = %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8** %2
br label %25
17: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i8** %2
br label %25
18: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i8** %2
br label %25
19: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.14, i64 0, i64 0), i8** %2
br label %25
20: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i8** %2
br label %25
21: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0), i8** %2
br label %25
22: ; preds = %1
%23 = load i32, i32* %3
%24 = call i8* @ltoa(i32 %23)
store i8* %24, i8** %2
br label %25
25: ; preds = %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@.str = [7 x i8] c"EAGAIN\00"
@.str.1 = [6 x i8] c"EPERM\00"
@.str.2 = [7 x i8] c"EFAULT\00"
@.str.3 = [7 x i8] c"EINVAL\00"
@.str.4 = [6 x i8] c"ELOOP\00"
@.str.5 = [7 x i8] c"EACCES\00"
@.str.6 = [7 x i8] c"EISDIR\00"
@.str.7 = [7 x i8] c"EMFILE\00"
@.str.8 = [7 x i8] c"ENFILE\00"
@.str.9 = [7 x i8] c"ENOENT\00"
@.str.10 = [7 x i8] c"ENOMEM\00"
@.str.11 = [13 x i8] c"ENAMETOOLONG\00"
@.str.12 = [7 x i8] c"ENODEV\00"
@.str.13 = [10 x i8] c"EOVERFLOW\00"
@.str.14 = [6 x i8] c"EINTR\00"
@.str.15 = [4 x i8] c"EIO\00"
@.str.16 = [6 x i8] c"EBADF\00"
@reltable.strerror = [17 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.13 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.10 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.9 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.12 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.8 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.11 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.7 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.4 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.6 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.15 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.3 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.14 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.2 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.16 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.5 to i64), i64 ptrtoint ([17 x i32]* @reltable.strerror to i64)) to i32)]
define i8* @strerror(i32 %0) {
%2 = add i32 %0, -128
%3 = icmp ult i32 %2, 17
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i8* @ltoa(i32 %0)
br label %10
6: ; preds = %1
%7 = sext i32 %2 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([17 x i32]* @reltable.strerror to i8*), i64 %8)
br label %10
10: ; preds = %6, %4
%11 = phi i8* [ %5, %4 ], [ %9, %6 ]
ret i8* %11
}