#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 EBADF 131
#define EEXIST 130
#define EINVAL 129
#define ENOENT 128
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
const char *custom_strerror(int errnum) {
  switch (errnum) {
  case 0:
    return "Success";
  case EINVAL:
    return "Invalid argument";
  case EBADF:
    return "Bad file descriptor";
  case ENOENT:
    return "No such file or directory";
  case EEXIST:
    return "File exists";
  default:
    printf("oops unknown errno %d\n", errnum);
    assert(0);
  }
  return "xxx";
}


x86 assembly (clang, -O0):
<custom_strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
test   %eax,%eax
je     118a <custom_strerror+0x6a>
jmp    113e <custom_strerror+0x1e>
mov    -0x10(%rbp),%eax
sub    $0x80,%eax
je     11ba <custom_strerror+0x9a>
jmp    1151 <custom_strerror+0x31>
mov    -0x10(%rbp),%eax
sub    $0x81,%eax
je     119a <custom_strerror+0x7a>
jmp    1164 <custom_strerror+0x44>
mov    -0x10(%rbp),%eax
sub    $0x82,%eax
je     11ca <custom_strerror+0xaa>
jmp    1177 <custom_strerror+0x57>
mov    -0x10(%rbp),%eax
sub    $0x83,%eax
je     11aa <custom_strerror+0x8a>
jmp    11da <custom_strerror+0xba>
lea    0xe6f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <custom_strerror+0xdb>
lea    0xe67(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <custom_strerror+0xdb>
lea    0xe68(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <custom_strerror+0xdb>
lea    0xe6c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <custom_strerror+0xdb>
lea    0xe76(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <custom_strerror+0xdb>
mov    -0xc(%rbp),%esi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <assert@plt>
lea    0xe73(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<custom_strerror>:
push   %rax
mov    %edi,%esi
lea    -0x80(%rsi),%eax
cmp    $0x3,%eax
ja     1144 <custom_strerror+0x24>
lea    0xece(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xefb(%rip),%rax
pop    %rcx
ret
test   %esi,%esi
jne    116c <custom_strerror+0x4c>
lea    0xec1(%rip),%rax
pop    %rcx
ret
lea    0xec0(%rip),%rax
pop    %rcx
ret
lea    0xef6(%rip),%rax
pop    %rcx
ret
lea    0xebf(%rip),%rax
pop    %rcx
ret
lea    0xef0(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <assert@plt>
lea    0xef4(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"Success\00"
@.str.1 = [17 x i8] c"Invalid argument\00"
@.str.2 = [20 x i8] c"Bad file descriptor\00"
@.str.3 = [26 x i8] c"No such file or directory\00"
@.str.4 = [12 x i8] c"File exists\00"
@.str.5 = [23 x i8] c"oops unknown errno %d\0A\00"
@.str.6 = [4 x i8] c"xxx\00"
define i8* @custom_strerror(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %10 [
i32 0, label %5
i32 129, label %6
i32 131, label %7
i32 128, label %8
i32 130, label %9
]
5: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %2
br label %15
6: ; preds = %1
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %15
7: ; preds = %1
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %15
8: ; preds = %1
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %15
9: ; preds = %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %15
10: ; preds = %1
%11 = load i32, i32* %3
%12 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %11)
%13 = call i32 @assert(i32 0)
br label %14
14: ; preds = %10
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %15
15: ; preds = %14, %9, %8, %7, %6, %5
%16 = load i8*, i8** %2
ret i8* %16
}

LLVM IR (-O2):
@.str = [8 x i8] c"Success\00"
@.str.1 = [17 x i8] c"Invalid argument\00"
@.str.2 = [20 x i8] c"Bad file descriptor\00"
@.str.3 = [26 x i8] c"No such file or directory\00"
@.str.4 = [12 x i8] c"File exists\00"
@.str.5 = [23 x i8] c"oops unknown errno %d\0A\00"
@.str.6 = [4 x i8] c"xxx\00"
define i8* @custom_strerror(i32 %0) {
switch i32 %0, label %6 [
i32 0, label %9
i32 129, label %2
i32 131, label %3
i32 128, label %4
i32 130, label %5
]
2: ; preds = %1
br label %9
3: ; preds = %1
br label %9
4: ; preds = %1
br label %9
5: ; preds = %1
br label %9
6: ; preds = %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %0)
%8 = tail call i32 @assert(i32 0)
br label %9
9: ; preds = %1, %6, %5, %4, %3, %2
%10 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), %6 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), %5 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), %4 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %10
}