#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 E2BIG 139
#define EACCES 138
#define EFAULT 137
#define EIO 136
#define EISDIR 135
#define ELIBBAD 134
#define ELOOP 133
#define EMFILE 132
#define ENAMETOOLONG 131
#define ENFILE 130
#define ENOENT 129
#define ENOTDIR 128
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
void handleerr() {
  switch (errno) {
  case E2BIG:
    fprintf(stderr, "list of arguments too large\n");
    break;
  case EACCES:
    fprintf(stderr, "permission denied\n");
    break;
  case EFAULT:
    fprintf(stderr, "segmentation fault\n");
    break;
  case EIO:
    fprintf(stderr, "I/O error\n");
    break;
  case EISDIR:
    fprintf(stderr, "is a directory\n");
    break;
  case ENOTDIR:
    fprintf(stderr, "not a directory\n");
    break;
  case ELIBBAD:
    fprintf(stderr, "not a valid executable\n");
    break;
  case ELOOP:
    fprintf(stderr, "too many redirections\n");
    break;
  case EMFILE:
    fprintf(stderr, "file limit for this shell exceeded\n");
    break;
  case ENAMETOOLONG:
    fprintf(stderr, "file name too long\n");
    break;
  case ENFILE:
    fprintf(stderr, "file limit for this system exceeded\n");
    break;
  case ENOENT:
    fprintf(stderr, "file or directory does not exist\n");
    break;
  default:
    fprintf(stderr, "unknown error\n");
    break;
  }
}


x86 assembly (clang, -O0):
<handleerr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb9(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x8(%rbp)
sub    $0xb,%eax
ja     127f <handleerr+0x16f>
mov    -0x8(%rbp),%rax
lea    0xec2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
lea    0xed9(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1294 <handleerr+0x184>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xedc(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1294 <handleerr+0x184>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xed5(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1294 <handleerr+0x184>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xecf(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1294 <handleerr+0x184>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xec0(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1294 <handleerr+0x184>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xeb6(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1294 <handleerr+0x184>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xead(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1294 <handleerr+0x184>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1294 <handleerr+0x184>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1294 <handleerr+0x184>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xeb2(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1294 <handleerr+0x184>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xeac(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1294 <handleerr+0x184>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xeb7(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1294 <handleerr+0x184>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xebf(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handleerr>:
mov    0x2ec1(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
cmp    $0xb,%eax
ja     1133 <handleerr+0x23>
cltq
lea    0x1006(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
jmp    113a <handleerr+0x2a>
lea    0xfe4(%rip),%rsi
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
@errno = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"list of arguments too large\0A\00"
@.str.1 = [19 x i8] c"permission denied\0A\00"
@.str.2 = [20 x i8] c"segmentation fault\0A\00"
@.str.3 = [11 x i8] c"I/O error\0A\00"
@.str.4 = [16 x i8] c"is a directory\0A\00"
@.str.5 = [17 x i8] c"not a directory\0A\00"
@.str.6 = [24 x i8] c"not a valid executable\0A\00"
@.str.7 = [23 x i8] c"too many redirections\0A\00"
@.str.8 = [36 x i8] c"file limit for this shell exceeded\0A\00"
@.str.9 = [20 x i8] c"file name too long\0A\00"
@.str.10 = [37 x i8] c"file limit for this system exceeded\0A\00"
@.str.11 = [34 x i8] c"file or directory does not exist\0A\00"
@.str.12 = [15 x i8] c"unknown error\0A\00"
define void @handleerr() {
%1 = load i32, i32* @errno
switch i32 %1, label %38 [
i32 139, label %2
i32 138, label %5
i32 137, label %8
i32 136, label %11
i32 135, label %14
i32 128, label %17
i32 134, label %20
i32 133, label %23
i32 132, label %26
i32 131, label %29
i32 130, label %32
i32 129, label %35
]
2: ; preds = %0
%3 = load i32, i32* @stderr
%4 = call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %41
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %41
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %41
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %41
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %41
17: ; preds = %0
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %41
20: ; preds = %0
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %41
23: ; preds = %0
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %41
26: ; preds = %0
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
br label %41
29: ; preds = %0
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
br label %41
32: ; preds = %0
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0))
br label %41
35: ; preds = %0
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0))
br label %41
38: ; preds = %0
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0))
br label %41
41: ; preds = %38, %35, %32, %29, %26, %23, %20, %17, %14, %11, %8, %5, %2
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"list of arguments too large\0A\00"
@.str.1 = [19 x i8] c"permission denied\0A\00"
@.str.2 = [20 x i8] c"segmentation fault\0A\00"
@.str.3 = [11 x i8] c"I/O error\0A\00"
@.str.4 = [16 x i8] c"is a directory\0A\00"
@.str.5 = [17 x i8] c"not a directory\0A\00"
@.str.6 = [24 x i8] c"not a valid executable\0A\00"
@.str.7 = [23 x i8] c"too many redirections\0A\00"
@.str.8 = [36 x i8] c"file limit for this shell exceeded\0A\00"
@.str.9 = [20 x i8] c"file name too long\0A\00"
@.str.10 = [37 x i8] c"file limit for this system exceeded\0A\00"
@.str.11 = [34 x i8] c"file or directory does not exist\0A\00"
@.str.12 = [15 x i8] c"unknown error\0A\00"
@reltable.handleerr = [12 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.5 to i64), i64 ptrtoint ([12 x i32]* @reltable.handleerr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([34 x i8]* @.str.11 to i64), i64 ptrtoint ([12 x i32]* @reltable.handleerr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([37 x i8]* @.str.10 to i64), i64 ptrtoint ([12 x i32]* @reltable.handleerr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.9 to i64), i64 ptrtoint ([12 x i32]* @reltable.handleerr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([36 x i8]* @.str.8 to i64), i64 ptrtoint ([12 x i32]* @reltable.handleerr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.7 to i64), i64 ptrtoint ([12 x i32]* @reltable.handleerr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.6 to i64), i64 ptrtoint ([12 x i32]* @reltable.handleerr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.4 to i64), i64 ptrtoint ([12 x i32]* @reltable.handleerr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.3 to i64), i64 ptrtoint ([12 x i32]* @reltable.handleerr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.2 to i64), i64 ptrtoint ([12 x i32]* @reltable.handleerr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.1 to i64), i64 ptrtoint ([12 x i32]* @reltable.handleerr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([29 x i8]* @.str to i64), i64 ptrtoint ([12 x i32]* @reltable.handleerr to i64)) to i32)]
define void @handleerr() {
%1 = load i32, i32* @errno
%2 = add i32 %1, -128
%3 = icmp ult i32 %2, 12
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = sext i32 %2 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([12 x i32]* @reltable.handleerr to i8*), i64 %6)
br label %8
8: ; preds = %0, %4
%9 = phi i8* [ %7, %4 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), %0 ]
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* %9)
ret void
}