#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 EBUSY 133
#define EFAULT 132
#define EINVAL 131
#define EIO 130
#define EPERM 129
#define ESRCH 128
int errno;
int /*<<< orphan*/ memcpy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
void getErrmsg(char *errmsg) {
  if (errmsg == NULL) {
    return;
  }
  char *msg;
  switch (errno) {
  case EBUSY:
    msg = "EBUSY: error with allocating or freeing a debug register.";
    break;
  case EFAULT:
    msg = "EFAULT: attempt to read from or write to an invalid area.";
    break;
  case EINVAL:
    msg = "EINVAL: attemp to set an invalid option.";
    break;
  case EIO:
    msg = "EIO: request is invalid.";
    break;
  case EPERM:
    msg = "EPERM: the specified process cannot be tarced, maybe you need more "
          "privileges.";
    break;
  case ESRCH:
    msg = "ESRCH: the specified process does not exist.";
    break;
  default:
    msg = "Unknown error";
    break;
  }
  memcpy(errmsg, msg, strlen(msg));
}


x86 assembly (clang, -O0):
<getErrmsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    113c <getErrmsg+0x1c>
jmp    11fe <getErrmsg+0xde>
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     11cb <getErrmsg+0xab>
mov    -0x18(%rbp),%rax
lea    0xe9e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea6(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11d6 <getErrmsg+0xb6>
lea    0xed0(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11d6 <getErrmsg+0xb6>
lea    0xefa(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11d6 <getErrmsg+0xb6>
lea    0xf13(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11d6 <getErrmsg+0xb6>
lea    0xf1c(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11d6 <getErrmsg+0xb6>
lea    0xf5b(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11d6 <getErrmsg+0xb6>
lea    0xf78(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1040 <memcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getErrmsg>:
test   %rdi,%rdi
je     114f <getErrmsg+0x2f>
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
cmp    $0x5,%eax
ja     1150 <getErrmsg+0x30>
cltq
lea    0xffa(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
jmp    1157 <getErrmsg+0x37>
ret
lea    0xfdb(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <memcpy@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [58 x i8] c"EBUSY: error with allocating or freeing a debug register.\00"
@.str.1 = [58 x i8] c"EFAULT: attempt to read from or write to an invalid area.\00"
@.str.2 = [41 x i8] c"EINVAL: attemp to set an invalid option.\00"
@.str.3 = [25 x i8] c"EIO: request is invalid.\00"
@.str.4 = [79 x i8] c"EPERM: the specified process cannot be tarced, maybe you need more privileges.\00"
@.str.5 = [45 x i8] c"ESRCH: the specified process does not exist.\00"
@.str.6 = [14 x i8] c"Unknown error\00"
define void @getErrmsg(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %1
br label %22
7: ; preds = %1
%8 = load i32, i32* @errno
switch i32 %8, label %15 [
i32 133, label %9
i32 132, label %10
i32 131, label %11
i32 130, label %12
i32 129, label %13
i32 128, label %14
]
9: ; preds = %7
store i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8** %3
br label %16
10: ; preds = %7
store i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %16
11: ; preds = %7
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %16
12: ; preds = %7
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %16
13: ; preds = %7
store i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.4, i64 0, i64 0), i8** %3
br label %16
14: ; preds = %7
store i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i8** %3
br label %16
15: ; preds = %7
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8** %3
br label %16
16: ; preds = %15, %14, %13, %12, %11, %10, %9
%17 = load i8*, i8** %2
%18 = load i8*, i8** %3
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @memcpy(i8* %17, i8* %18, i32 %20)
br label %22
22: ; preds = %16, %6
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [58 x i8] c"EBUSY: error with allocating or freeing a debug register.\00"
@.str.1 = [58 x i8] c"EFAULT: attempt to read from or write to an invalid area.\00"
@.str.2 = [41 x i8] c"EINVAL: attemp to set an invalid option.\00"
@.str.3 = [25 x i8] c"EIO: request is invalid.\00"
@.str.4 = [79 x i8] c"EPERM: the specified process cannot be tarced, maybe you need more privileges.\00"
@.str.5 = [45 x i8] c"ESRCH: the specified process does not exist.\00"
@.str.6 = [14 x i8] c"Unknown error\00"
@reltable.getErrmsg = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([45 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.getErrmsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([79 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.getErrmsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([25 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.getErrmsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([41 x i8]* @.str.2 to i64), i64 ptrtoint ([6 x i32]* @reltable.getErrmsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([58 x i8]* @.str.1 to i64), i64 ptrtoint ([6 x i32]* @reltable.getErrmsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([58 x i8]* @.str to i64), i64 ptrtoint ([6 x i32]* @reltable.getErrmsg to i64)) to i32)]
define void @getErrmsg(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = load i32, i32* @errno
%5 = add i32 %4, -128
%6 = icmp ult i32 %5, 6
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = sext i32 %5 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.getErrmsg to i8*), i64 %9)
br label %11
11: ; preds = %3, %7
%12 = phi i8* [ %10, %7 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), %3 ]
%13 = tail call i32 @strlen(i8* %12)
%14 = tail call i32 @memcpy(i8* %0, i8* %12, i32 %13)
br label %15
15: ; preds = %1, %11
ret void
}