#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*/ sprintf(char *, char *, int);
char const **sys_errlist;
int sys_nerr;
const char *strerror(int e) {
  static char buffer[30];
  if (!e) {
    buffer[0] = 0;
  } else if (e > 0 && e < sys_nerr) {
    return (sys_errlist[e]);
  } else {
    sprintf(buffer, "Unknown error %d", e);
  }
  return (buffer);
}


x86 assembly (clang, -O0):
<strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1131 <strerror+0x21>
movb   $0x0,0x2f14(%rip)
jmp    1183 <strerror+0x73>
cmpl   $0x0,-0xc(%rbp)
jle    1168 <strerror+0x58>
mov    -0xc(%rbp),%eax
mov    0x2ea3(%rip),%rcx
cmp    (%rcx),%eax
jge    1168 <strerror+0x58>
mov    0x2ea4(%rip),%rax
mov    (%rax),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    118e <strerror+0x7e>
mov    -0xc(%rbp),%edx
lea    0x2ece(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1183 <strerror+0x73>
lea    0x2eb6(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strerror>:
push   %rbx
test   %edi,%edi
je     1136 <strerror+0x26>
mov    %edi,%edx
jle    1146 <strerror+0x36>
mov    0x2ec8(%rip),%rax
cmp    %edx,(%rax)
jle    1146 <strerror+0x36>
mov    0x2ecd(%rip),%rax
mov    (%rax),%rax
mov    %edx,%ecx
mov    (%rax,%rcx,8),%rbx
jmp    115c <strerror+0x4c>
movb   $0x0,0x2f03(%rip)
lea    0x2efc(%rip),%rbx
jmp    115c <strerror+0x4c>
lea    0x2ef3(%rip),%rbx
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@strerror.buffer = internal global [30 x i8] zeroinitializer
@sys_nerr = global i32 0
@sys_errlist = global i8** null
@.str = [17 x i8] c"Unknown error %d\00"
define i8* @strerror(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp ne i32 %4, 0
br i1 %5, label %7, label %6
6: ; preds = %1
store i8 0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @strerror.buffer, i64 0, i64 0)
br label %24
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = load i32, i32* %3
%12 = load i32, i32* @sys_nerr
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i8**, i8*** @sys_errlist
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
store i8* %19, i8** %2
br label %25
20: ; preds = %10, %7
%21 = load i32, i32* %3
%22 = call i32 @sprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @strerror.buffer, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20
br label %24
24: ; preds = %23, %6
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @strerror.buffer, i64 0, i64 0), i8** %2
br label %25
25: ; preds = %24, %14
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@strerror.buffer = internal global [30 x i8] zeroinitializer
@sys_nerr = global i32 0
@sys_errlist = global i8** null
@.str = [17 x i8] c"Unknown error %d\00"
define i8* @strerror(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %3, label %4
3: ; preds = %1
store i8 0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @strerror.buffer, i64 0, i64 0)
br label %16
4: ; preds = %1
%5 = icmp sgt i32 %0, 0
%6 = load i32, i32* @sys_nerr
%7 = icmp sgt i32 %6, %0
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = load i8**, i8*** @sys_errlist
%11 = zext i32 %0 to i64
%12 = getelementptr inbounds i8*, i8** %10, i64 %11
%13 = load i8*, i8** %12
br label %16
14: ; preds = %4
%15 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @strerror.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %16
16: ; preds = %3, %14, %9
%17 = phi i8* [ %13, %9 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @strerror.buffer, i64 0, i64 0), %14 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @strerror.buffer, i64 0, i64 0), %3 ]
ret i8* %17
}