#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 **sys_errlist;
int sys_nerr;
char *strerror(int err) {
  if (err < sys_nerr)
    return sys_errlist[err];
  else {
    static char errbuf[50];
    sprintf(errbuf, "Unknown system error %d", err);
    return errbuf;
  }
}


x86 assembly (clang, -O0):
<strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2ec3(%rip),%rcx
cmp    (%rcx),%eax
jge    1148 <strerror+0x38>
mov    0x2ec4(%rip),%rax
mov    (%rax),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    1169 <strerror+0x59>
mov    -0xc(%rbp),%edx
lea    0x2efe(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2eeb(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strerror>:
push   %rbx
mov    %edi,%edx
mov    0x2ece(%rip),%rax
cmp    %edi,(%rax)
jle    1131 <strerror+0x21>
mov    0x2ed3(%rip),%rax
mov    (%rax),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,8),%rbx
jmp    1147 <strerror+0x37>
lea    0x2f18(%rip),%rbx
lea    0xec1(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@sys_nerr = global i32 0
@sys_errlist = global i8** null
@strerror.errbuf = internal global [50 x i8] zeroinitializer
@.str = [24 x i8] c"Unknown system 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 = load i32, i32* @sys_nerr
%6 = icmp slt i32 %4, %5
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i8**, i8*** @sys_errlist
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %8, i64 %10
%12 = load i8*, i8** %11
store i8* %12, i8** %2
br label %16
13: ; preds = %1
%14 = load i32, i32* %3
%15 = call i32 @sprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @strerror.errbuf, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %14)
store i8* getelementptr inbounds ([50 x i8], [50 x i8]* @strerror.errbuf, i64 0, i64 0), i8** %2
br label %16
16: ; preds = %13, %7
%17 = load i8*, i8** %2
ret i8* %17
}

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