#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 errnum) {
  extern int sys_nerr;
  extern char *sys_errlist[];
  static char null[1] = {0};
  if (errnum <= 0)
    return null;
  else if (errnum >= sys_nerr) {
    static char errmsg[50];
    sprintf(errmsg, "error %d", errnum);
    return errmsg;
  } else
    return sys_errlist[errnum];
}


x86 assembly (clang, -O0):
<strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     1135 <strerror+0x25>
lea    0x2f14(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1180 <strerror+0x70>
mov    -0xc(%rbp),%eax
mov    0x2ea9(%rip),%rcx
cmp    (%rcx),%eax
jl     116d <strerror+0x5d>
mov    -0xc(%rbp),%edx
lea    0x2eff(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2eec(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1180 <strerror+0x70>
movslq -0xc(%rbp),%rcx
mov    0x2e80(%rip),%rax
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
test   %edi,%edi
jle    1131 <strerror+0x21>
mov    %edi,%edx
mov    0x2eca(%rip),%rax
cmp    %edi,(%rax)
jle    113a <strerror+0x2a>
mov    %edx,%eax
mov    0x2ecd(%rip),%rcx
mov    (%rcx,%rax,8),%rbx
jmp    1150 <strerror+0x40>
lea    0x2f08(%rip),%rbx
jmp    1150 <strerror+0x40>
lea    0x2f0f(%rip),%rbx
lea    0xeb8(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

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

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