#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 132
#define ELOOP 131
#define ENAMETOOLONG 130
#define ENOENT 129
#define ENOTDIR 128
int errno;
char *getChdirErrMsg() {
  static char *out;
  switch (errno) {
  case EACCES:
    out = "can't open %s: access denied\n";
    break;
  case ENOENT:
    out = "can't open %s: a component doesn't name an existing directory\n";
    break;
  case ENOTDIR:
    out = "can't open %s: it's not a directory\n";
    break;
  case ELOOP:
    out = "can't correctly find %s: there are loops in the path\n";
    break;
  case ENAMETOOLONG:
    out = "can't open %s:a component in the path is too long\n";
    break;
  default:
    out = "unknown error while opening %s : errno(%d)\n";
  }
  return out;
}


x86 assembly (clang, -O0):
<getChdirErrMsg>:
push   %rbp
mov    %rsp,%rbp
mov    0x2ed5(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x8(%rbp)
sub    $0x4,%eax
ja     1192 <getChdirErrMsg+0x92>
mov    -0x8(%rbp),%rax
lea    0xed6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeda(%rip),%rax
mov    %rax,0x2ee7(%rip)
jmp    11a0 <getChdirErrMsg+0xa0>
lea    0xee5(%rip),%rax
mov    %rax,0x2ed4(%rip)
jmp    11a0 <getChdirErrMsg+0xa0>
lea    0xf11(%rip),%rax
mov    %rax,0x2ec1(%rip)
jmp    11a0 <getChdirErrMsg+0xa0>
lea    0xf23(%rip),%rax
mov    %rax,0x2eae(%rip)
jmp    11a0 <getChdirErrMsg+0xa0>
lea    0xf46(%rip),%rax
mov    %rax,0x2e9b(%rip)
jmp    11a0 <getChdirErrMsg+0xa0>
lea    0xf66(%rip),%rax
mov    %rax,0x2e88(%rip)
mov    0x2e81(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getChdirErrMsg>:
mov    0x2ed9(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
cmp    $0x4,%eax
ja     1122 <getChdirErrMsg+0x22>
cltq
lea    0xffe(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xfc2(%rip),%rax
ret

LLVM IR (-O0):
@getChdirErrMsg.out = internal global i8* null
@errno = global i32 0
@.str = [30 x i8] c"can't open %s: access denied\0A\00"
@.str.1 = [63 x i8] c"can't open %s: a component doesn't name an existing directory\0A\00"
@.str.2 = [37 x i8] c"can't open %s: it's not a directory\0A\00"
@.str.3 = [54 x i8] c"can't correctly find %s: there are loops in the path\0A\00"
@.str.4 = [51 x i8] c"can't open %s:a component in the path is too long\0A\00"
@.str.5 = [44 x i8] c"unknown error while opening %s : errno(%d)\0A\00"
define i8* @getChdirErrMsg() {
%1 = load i32, i32* @errno
switch i32 %1, label %7 [
i32 132, label %2
i32 129, label %3
i32 128, label %4
i32 131, label %5
i32 130, label %6
]
2: ; preds = %0
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8** @getChdirErrMsg.out
br label %8
3: ; preds = %0
store i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8** @getChdirErrMsg.out
br label %8
4: ; preds = %0
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8** @getChdirErrMsg.out
br label %8
5: ; preds = %0
store i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i8** @getChdirErrMsg.out
br label %8
6: ; preds = %0
store i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8** @getChdirErrMsg.out
br label %8
7: ; preds = %0
store i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i8** @getChdirErrMsg.out
br label %8
8: ; preds = %7, %6, %5, %4, %3, %2
%9 = load i8*, i8** @getChdirErrMsg.out
ret i8* %9
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [30 x i8] c"can't open %s: access denied\0A\00"
@.str.1 = [63 x i8] c"can't open %s: a component doesn't name an existing directory\0A\00"
@.str.2 = [37 x i8] c"can't open %s: it's not a directory\0A\00"
@.str.3 = [54 x i8] c"can't correctly find %s: there are loops in the path\0A\00"
@.str.4 = [51 x i8] c"can't open %s:a component in the path is too long\0A\00"
@.str.5 = [44 x i8] c"unknown error while opening %s : errno(%d)\0A\00"
@reltable.getChdirErrMsg = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([37 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.getChdirErrMsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([63 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.getChdirErrMsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([51 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.getChdirErrMsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([54 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.getChdirErrMsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([30 x i8]* @.str to i64), i64 ptrtoint ([5 x i32]* @reltable.getChdirErrMsg to i64)) to i32)]
define i8* @getChdirErrMsg() {
%1 = load i32, i32* @errno
%2 = add i32 %1, -128
%3 = icmp ult i32 %2, 5
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 ([5 x i32]* @reltable.getChdirErrMsg to i8*), i64 %6)
br label %8
8: ; preds = %0, %4
%9 = phi i8* [ %7, %4 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), %0 ]
ret i8* %9
}