#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char **sys_errlist;
int sys_nerr;
char *strerror(int e) {
  static char buf[100];
  if (e < 0 || e >= sys_nerr) {
    snprintf(buf, sizeof(buf), "Unknown error %d", e);
    return buf;
  } else
    return sys_errlist[e];
}


x86 assembly (clang, -O0):
<strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1137 <strerror+0x27>
mov    -0xc(%rbp),%eax
mov    0x2eb9(%rip),%rcx
cmp    (%rcx),%eax
jl     1162 <strerror+0x52>
mov    -0xc(%rbp),%ecx
lea    0x2eff(%rip),%rdi
mov    $0x64,%esi
lea    0xeb3(%rip),%rdx
call   1030 <snprintf@plt>
lea    0x2ee7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1178 <strerror+0x68>
mov    0x2e8f(%rip),%rax
mov    (%rax),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strerror>:
push   %rbx
mov    %edi,%ecx
test   %edi,%edi
js     1134 <strerror+0x24>
mov    0x2eca(%rip),%rax
cmp    %ecx,(%rax)
jle    1134 <strerror+0x24>
mov    0x2ecf(%rip),%rax
mov    (%rax),%rax
mov    %ecx,%ecx
mov    (%rax,%rcx,8),%rbx
jmp    114f <strerror+0x3f>
lea    0x2f05(%rip),%rbx
lea    0xebe(%rip),%rdx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

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

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