#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
#define EACCES 138
#define ECONNREFUSED 137
#define EINTR 136
#define EINVAL 135
#define EIO 134
#define ELOOP 133
#define ENFILE 132
#define ENOENT 131
#define ENOMEM 130
#define EPERM 129
#define EPIPE 128
char *strerror(int err) {
  static char buf[10];
  switch (err) {
  case ENOENT:
    return "ENOENT";
  case ELOOP:
    return "ELOOP";
  case ENFILE:
    return "ENFILE";
  case EPIPE:
    return "EPIPE";
  case ENOMEM:
    return "ENOMEM";
  case ECONNREFUSED:
    return "ECONNREFUSED";
  case EINTR:
    return "EINTR";
  case EINVAL:
    return "EINVAL";
  case EACCES:
    return "EACCES";
  case EPERM:
    return "EPERM";
  case EIO:
    return "EIO";
  }
  int i = sizeof(buf) - 1;
  buf[i--] = '\0';
  while (err && i >= 0) {
    buf[i--] = '0' + (err % 10);
    err /= 10;
  };
  return buf + i + 1;
}


x86 assembly (clang, -O0):
<strerror>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0xa,%eax
ja     11e0 <strerror+0xe0>
mov    -0x18(%rbp),%rax
lea    0xed9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xef5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1278 <strerror+0x178>
lea    0xeec(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1278 <strerror+0x178>
lea    0xee2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1278 <strerror+0x178>
lea    0xed9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1278 <strerror+0x178>
lea    0xecf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1278 <strerror+0x178>
lea    0xec6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1278 <strerror+0x178>
lea    0xec3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1278 <strerror+0x178>
lea    0xeb9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1278 <strerror+0x178>
lea    0xeb0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1278 <strerror+0x178>
lea    0xea7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1278 <strerror+0x178>
lea    0xe9d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1278 <strerror+0x178>
movl   $0x9,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2e25(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x19(%rbp)
je     1219 <strerror+0x119>
cmpl   $0x0,-0x10(%rbp)
setge  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1229 <strerror+0x129>
jmp    1262 <strerror+0x162>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2dd5(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    1200 <strerror+0x100>
movslq -0x10(%rbp),%rcx
lea    0x2db4(%rip),%rax
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<strerror>:
lea    -0x80(%rdi),%eax
cmp    $0xb,%eax
jae    1119 <strerror+0x19>
cltq
lea    0xf3b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
movb   $0x0,0x2f0a(%rip)
mov    $0x8,%eax
test   %edi,%edi
je     116f <strerror+0x6f>
lea    0x2ef1(%rip),%r8
mov    %rax,%r9
movslq %edi,%rcx
imul   $0x66666667,%rcx,%rdi
mov    %rdi,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rdi
add    %edx,%edi
lea    (%rdi,%rdi,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
add    $0x30,%sil
add    $0xffffffffffffffff,%rax
setb   %dl
mov    %sil,(%r9,%r8,1)
add    $0xfffffff6,%ecx
cmp    $0xffffffec,%ecx
ja     116f <strerror+0x6f>
test   %dl,%dl
jne    1130 <strerror+0x30>
lea    0x2eab(%rip),%rcx
add    %rcx,%rax
add    $0x1,%rax
ret

LLVM IR (-O0):
@strerror.buf = internal global [10 x i8] zeroinitializer
@.str = [7 x i8] c"ENOENT\00"
@.str.1 = [6 x i8] c"ELOOP\00"
@.str.2 = [7 x i8] c"ENFILE\00"
@.str.3 = [6 x i8] c"EPIPE\00"
@.str.4 = [7 x i8] c"ENOMEM\00"
@.str.5 = [13 x i8] c"ECONNREFUSED\00"
@.str.6 = [6 x i8] c"EINTR\00"
@.str.7 = [7 x i8] c"EINVAL\00"
@.str.8 = [7 x i8] c"EACCES\00"
@.str.9 = [6 x i8] c"EPERM\00"
@.str.10 = [4 x i8] c"EIO\00"
define i8* @strerror(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
switch i32 %5, label %17 [
i32 131, label %6
i32 133, label %7
i32 132, label %8
i32 128, label %9
i32 130, label %10
i32 137, label %11
i32 136, label %12
i32 135, label %13
i32 138, label %14
i32 129, label %15
i32 134, label %16
]
6: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %2
br label %46
7: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %46
8: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %46
9: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %46
10: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %46
11: ; preds = %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %46
12: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %46
13: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %46
14: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8** %2
br label %46
15: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8** %2
br label %46
16: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8** %2
br label %46
17: ; preds = %1
store i32 9, i32* %4
%18 = load i32, i32* %4
%19 = add nsw i32 %18, -1
store i32 %19, i32* %4
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds [10 x i8], [10 x i8]* @strerror.buf, i64 0, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %30, %17
%23 = load i32, i32* %3
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* %4
%27 = icmp sge i32 %26, 0
br label %28
28: ; preds = %25, %22
%29 = phi i1 [ false, %22 ], [ %27, %25 ]
br i1 %29, label %30, label %41
30: ; preds = %28
%31 = load i32, i32* %3
%32 = srem i32 %31, 10
%33 = add nsw i32 48, %32
%34 = trunc i32 %33 to i8
%35 = load i32, i32* %4
%36 = add nsw i32 %35, -1
store i32 %36, i32* %4
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds [10 x i8], [10 x i8]* @strerror.buf, i64 0, i64 %37
store i8 %34, i8* %38
%39 = load i32, i32* %3
%40 = sdiv i32 %39, 10
store i32 %40, i32* %3
br label %22
41: ; preds = %28
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @strerror.buf, i64 0, i64 0), i64 %43
%45 = getelementptr inbounds i8, i8* %44, i64 1
store i8* %45, i8** %2
br label %46
46: ; preds = %41, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6
%47 = load i8*, i8** %2
ret i8* %47
}

LLVM IR (-O2):
@strerror.buf = internal global [10 x i8] zeroinitializer
@.str = [7 x i8] c"ENOENT\00"
@.str.1 = [6 x i8] c"ELOOP\00"
@.str.2 = [7 x i8] c"ENFILE\00"
@.str.3 = [6 x i8] c"EPIPE\00"
@.str.4 = [7 x i8] c"ENOMEM\00"
@.str.5 = [13 x i8] c"ECONNREFUSED\00"
@.str.6 = [6 x i8] c"EINTR\00"
@.str.7 = [7 x i8] c"EINVAL\00"
@.str.8 = [7 x i8] c"EACCES\00"
@.str.9 = [6 x i8] c"EPERM\00"
@.str.10 = [4 x i8] c"EIO\00"
@reltable.strerror = [11 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([11 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.9 to i64), i64 ptrtoint ([11 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.4 to i64), i64 ptrtoint ([11 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str to i64), i64 ptrtoint ([11 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.2 to i64), i64 ptrtoint ([11 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([11 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.10 to i64), i64 ptrtoint ([11 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.7 to i64), i64 ptrtoint ([11 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.6 to i64), i64 ptrtoint ([11 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.5 to i64), i64 ptrtoint ([11 x i32]* @reltable.strerror to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.8 to i64), i64 ptrtoint ([11 x i32]* @reltable.strerror to i64)) to i32)]
define i8* @strerror(i32 %0) {
%2 = add i32 %0, -128
%3 = icmp ult i32 %2, 11
br i1 %3, label %26, label %4
4: ; preds = %1
store i8 0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @strerror.buf, i64 0, i64 9)
%5 = icmp eq i32 %0, 0
br i1 %5, label %22, label %6
6: ; preds = %4, %6
%7 = phi i64 [ %12, %6 ], [ 8, %4 ]
%8 = phi i32 [ %14, %6 ], [ %0, %4 ]
%9 = srem i32 %8, 10
%10 = trunc i32 %9 to i8
%11 = add nsw i8 %10, 48
%12 = add nsw i64 %7, -1
%13 = getelementptr inbounds [10 x i8], [10 x i8]* @strerror.buf, i64 0, i64 %7
store i8 %11, i8* %13
%14 = sdiv i32 %8, 10
%15 = add i32 %8, -10
%16 = icmp ult i32 %15, -19
%17 = icmp ne i64 %7, 0
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %6, label %19
19: ; preds = %6
%20 = shl i64 %12, 32
%21 = ashr exact i64 %20, 32
br label %22
22: ; preds = %19, %4
%23 = phi i64 [ 8, %4 ], [ %21, %19 ]
%24 = getelementptr inbounds [10 x i8], [10 x i8]* @strerror.buf, i64 0, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 1
br label %30
26: ; preds = %1
%27 = sext i32 %2 to i64
%28 = shl i64 %27, 2
%29 = call i8* @llvm.load.relative.i64(i8* bitcast ([11 x i32]* @reltable.strerror to i8*), i64 %28)
br label %30
30: ; preds = %26, %22
%31 = phi i8* [ %25, %22 ], [ %29, %26 ]
ret i8* %31
}