#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 */
int /*<<< orphan*/ errno;
char const *strerror(int /*<<< orphan*/);
const char *dsk_strerror(int err) {
  switch (err) {
  case (-2):
    return "Out of memory.";
  case (-1):
    return "Bad pointer.";
  case (-6):
    return strerror(errno);
  case (0):
    return "No error.";
  }
  return "Unknown error.";
}


x86 assembly (clang, -O0):
<dsk_strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x6,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x6,%eax
ja     118b <dsk_strerror+0x7b>
mov    -0x18(%rbp),%rax
lea    0xec5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1196 <dsk_strerror+0x86>
lea    0xed0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1196 <dsk_strerror+0x86>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
call   1030 <strerror@plt>
mov    %rax,-0x8(%rbp)
jmp    1196 <dsk_strerror+0x86>
lea    0xeb6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1196 <dsk_strerror+0x86>
lea    0xeb0(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dsk_strerror>:
add    $0x6,%edi
cmp    $0x6,%edi
ja     113d <dsk_strerror+0x2d>
lea    0xefd(%rip),%rax
lea    0xeda(%rip),%rcx
movslq (%rcx,%rdi,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
jmp    1030 <strerror@plt>
lea    0xefe(%rip),%rax
ret
lea    0xedf(%rip),%rax
ret
lea    0xee4(%rip),%rax
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Out of memory.\00"
@.str.1 = [13 x i8] c"Bad pointer.\00"
@errno = global i32 0
@.str.2 = [10 x i8] c"No error.\00"
@.str.3 = [15 x i8] c"Unknown error.\00"
define i8* @dsk_strerror(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %11 [
i32 -2, label %5
i32 -1, label %6
i32 -6, label %7
i32 0, label %10
]
5: ; preds = %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %2
br label %12
6: ; preds = %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %12
7: ; preds = %1
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
store i8* %9, i8** %2
br label %12
10: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %12
11: ; preds = %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %12
12: ; preds = %11, %10, %7, %6, %5
%13 = load i8*, i8** %2
ret i8* %13
}

LLVM IR (-O2):
@.str = [15 x i8] c"Out of memory.\00"
@.str.1 = [13 x i8] c"Bad pointer.\00"
@errno = global i32 0
@.str.2 = [10 x i8] c"No error.\00"
@.str.3 = [15 x i8] c"Unknown error.\00"
define i8* @dsk_strerror(i32 %0) {
switch i32 %0, label %7 [
i32 -2, label %8
i32 -1, label %2
i32 -6, label %3
i32 0, label %6
]
2: ; preds = %1
br label %8
3: ; preds = %1
%4 = load i32, i32* @errno
%5 = tail call i8* @strerror(i32 %4)
br label %8
6: ; preds = %1
br label %8
7: ; preds = %1
br label %8
8: ; preds = %1, %7, %6, %3, %2
%9 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %7 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %6 ], [ %5, %3 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %9
}