#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 *strerror(int errno) {
  static char buf[100];
  extern int sys_nerr;
  extern char *sys_errlist[];
  if (errno < sys_nerr && errno >= 0)
    return sys_errlist[errno];
  sprintf(buf, "unknown error %d", errno);
  return buf;
}


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    114f <strerror+0x3f>
cmpl   $0x0,-0xc(%rbp)
jl     114f <strerror+0x3f>
movslq -0xc(%rbp),%rcx
mov    0x2eb6(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    1170 <strerror+0x60>
mov    -0xc(%rbp),%edx
lea    0x2ee7(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2ed4(%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
test   %edi,%edi
js     1131 <strerror+0x21>
mov    0x2eca(%rip),%rax
cmp    %edx,(%rax)
jle    1131 <strerror+0x21>
mov    %edx,%eax
mov    0x2ecd(%rip),%rcx
mov    (%rcx,%rax,8),%rbx
jmp    1147 <strerror+0x37>
lea    0x2f08(%rip),%rbx
lea    0xec1(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

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

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