#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 */
char const *hash_error_string(int);
char *strerror(int);
const char *error_string(int error) {
  const char *str;
  if ((((error) >= -2000) && ((error) < (-2000 + 20))))
    return hash_error_string(error);
  if (error < 0) {
    return "Negative error codes are not supported.";
  }
  str = strerror(error);
  if (str == NULL) {
    return "strerror() returned NULL.";
  }
  return str;
}


x86 assembly (clang, -O0):
<error_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0xfffff830,-0xc(%rbp)
jl     1156 <error_string+0x36>
cmpl   $0xfffff844,-0xc(%rbp)
jge    1156 <error_string+0x36>
mov    -0xc(%rbp),%edi
call   1030 <hash_error_string@plt>
mov    %rax,-0x8(%rbp)
jmp    119f <error_string+0x7f>
cmpl   $0x0,-0xc(%rbp)
jge    1170 <error_string+0x50>
lea    0xe99(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <error_string+0x7f>
mov    -0xc(%rbp),%edi
call   1040 <strerror@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1197 <error_string+0x77>
lea    0xe9a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <error_string+0x7f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<error_string>:
lea    0x7d0(%rdi),%eax
cmp    $0x13,%eax
ja     1130 <error_string+0x10>
jmp    1030 <hash_error_string@plt>
test   %edi,%edi
js     1150 <error_string+0x30>
push   %rax
call   1040 <strerror@plt>
mov    %rax,%rcx
test   %rax,%rax
lea    0xee1(%rip),%rax
cmovne %rcx,%rax
add    $0x8,%rsp
ret
lea    0xea9(%rip),%rax
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Negative error codes are not supported.\00"
@.str.1 = [26 x i8] c"strerror() returned NULL.\00"
define i8* @error_string(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, -2000
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, -1980
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* %3
%12 = call i8* @hash_error_string(i32 %11)
store i8* %12, i8** %2
br label %25
13: ; preds = %7, %1
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
store i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8** %2
br label %25
17: ; preds = %13
%18 = load i32, i32* %3
%19 = call i8* @strerror(i32 %18)
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %25
23: ; preds = %17
%24 = load i8*, i8** %4
store i8* %24, i8** %2
br label %25
25: ; preds = %23, %22, %16, %10
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@.str = [40 x i8] c"Negative error codes are not supported.\00"
@.str.1 = [26 x i8] c"strerror() returned NULL.\00"
define i8* @error_string(i32 %0) {
%2 = add i32 %0, 2000
%3 = icmp ult i32 %2, 20
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i8* @hash_error_string(i32 %0)
br label %12
6: ; preds = %1
%7 = icmp slt i32 %0, 0
br i1 %7, label %12, label %8
8: ; preds = %6
%9 = tail call i8* @strerror(i32 %0)
%10 = icmp eq i8* %9, null
%11 = select i1 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %9
br label %12
12: ; preds = %8, %6, %4
%13 = phi i8* [ %5, %4 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), %6 ], [ %11, %8 ]
ret i8* %13
}