#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int errnum) {
  char sn[1 + 10 + 1], *p = sn + sizeof sn;
  static char s[64];
  unsigned e = (errnum < 0) ? -(unsigned)errnum : errnum;
  *--p = '\0';
  do {
    *--p = '0' + e % 10;
    e /= 10;
  } while (e);
  if (errnum < 0)
    *--p = '-';
  strcpy(s, "Unknown error ");
  strcat(s, p);
  return s;
}


x86 assembly (clang, -O0):
<strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x10(%rbp),%rax
add    $0xc,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    114e <strerror+0x2e>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1154 <strerror+0x34>
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,-0x1(%rax)
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    116d <strerror+0x4d>
cmpl   $0x0,-0x4(%rbp)
jge    11c6 <strerror+0xa6>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,-0x1(%rax)
lea    0x2e73(%rip),%rdi
lea    0xe2c(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rsi
lea    0x2e5c(%rip),%rdi
call   1040 <strcat@plt>
lea    0x2e50(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strerror>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ecx
neg    %ecx
cmovs  %edi,%ecx
movb   $0x0,0x17(%rsp)
lea    0x16(%rsp),%rbx
mov    $0xcccccccd,%r8d
xchg   %ax,%ax
mov    %ecx,%edx
imul   %r8,%rdx
shr    $0x23,%rdx
lea    (%rdx,%rdx,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %ecx,%eax
sub    %esi,%eax
or     $0x30,%al
mov    %al,(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    $0x9,%ecx
mov    %edx,%ecx
ja     1140 <strerror+0x20>
test   %edi,%edi
js     116d <strerror+0x4d>
add    $0x1,%rbx
jmp    1170 <strerror+0x50>
movb   $0x2d,(%rbx)
lea    0x2ec9(%rip),%r14
lea    0xe82(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcat@plt>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@strerror.s = internal global [64 x i8] zeroinitializer
@.str = [15 x i8] c"Unknown error \00"
define i8* @strerror(i32 %0) {
%2 = alloca i32
%3 = alloca [12 x i8]
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds i8, i8* %6, i64 12
store i8* %7, i8** %4
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* %2
%12 = sub i32 0, %11
br label %15
13: ; preds = %1
%14 = load i32, i32* %2
br label %15
15: ; preds = %13, %10
%16 = phi i32 [ %12, %10 ], [ %14, %13 ]
store i32 %16, i32* %5
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 -1
store i8* %18, i8** %4
store i8 0, i8* %18
br label %19
19: ; preds = %28, %15
%20 = load i32, i32* %5
%21 = urem i32 %20, 10
%22 = add i32 48, %21
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %4
store i8 %23, i8* %25
%26 = load i32, i32* %5
%27 = udiv i32 %26, 10
store i32 %27, i32* %5
br label %28
28: ; preds = %19
%29 = load i32, i32* %5
%30 = icmp ne i32 %29, 0
br i1 %30, label %19, label %31
31: ; preds = %28
%32 = load i32, i32* %2
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i32 -1
store i8* %36, i8** %4
store i8 45, i8* %36
br label %37
37: ; preds = %34, %31
%38 = call i32 @strcpy(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @strerror.s, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%39 = load i8*, i8** %4
%40 = call i32 @strcat(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @strerror.s, i64 0, i64 0), i8* %39)
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @strerror.s, i64 0, i64 0)
}

LLVM IR (-O2):
@strerror.s = internal global [64 x i8] zeroinitializer
@.str = [15 x i8] c"Unknown error \00"
define i8* @strerror(i32 %0) {
%2 = alloca [12 x i8]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%4 = icmp slt i32 %0, 0
%5 = sub i32 0, %0
%6 = select i1 %4, i32 %5, i32 %0
%7 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 11
store i8 0, i8* %7
br label %8
8: ; preds = %8, %1
%9 = phi i8* [ %7, %1 ], [ %14, %8 ]
%10 = phi i32 [ %6, %1 ], [ %15, %8 ]
%11 = urem i32 %10, 10
%12 = trunc i32 %11 to i8
%13 = or i8 %12, 48
%14 = getelementptr inbounds i8, i8* %9, i64 -1
store i8 %13, i8* %14
%15 = udiv i32 %10, 10
%16 = icmp ult i32 %10, 10
br i1 %16, label %17, label %8
17: ; preds = %8
br i1 %4, label %18, label %20
18: ; preds = %17
%19 = getelementptr inbounds i8, i8* %9, i64 -2
store i8 45, i8* %19
br label %20
20: ; preds = %18, %17
%21 = phi i8* [ %19, %18 ], [ %14, %17 ]
%22 = tail call i32 @strcpy(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @strerror.s, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @strcat(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @strerror.s, i64 0, i64 0), i8* %21)
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @strerror.s, i64 0, i64 0)
}