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

/* Variables and functions */
#define GLOB_ABORTED 131
#define GLOB_NOMATCH 130
#define GLOB_NOSPACE 129
#define GLOB_NOSYS 128
int /*<<< orphan*/ snprintf(char *, int, char *, int);
const char *errstr(int val) {
  static const char *const strs[] = {[GLOB_NOSPACE] = "GLOB_NOSPACE",
                                     [GLOB_ABORTED] = "GLOB_ABORTED",
                                     [GLOB_NOMATCH] = "GLOB_NOMATCH",
                                     [GLOB_NOSYS] = "GLOB_NOSYS"};
  static char buf[100];
  if (val < 0 || val >= (sizeof(strs) / sizeof(strs[0])) || strs[val] == NULL) {
    snprintf(buf, sizeof(buf), "GLOB_??? (%d)", val);
    return buf;
  }
  return strs[val];
}


x86 assembly (clang, -O0):
<errstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     114b <errstr+0x3b>
movslq -0xc(%rbp),%rax
cmp    $0x84,%rax
jae    114b <errstr+0x3b>
movslq -0xc(%rbp),%rcx
lea    0x28c0(%rip),%rax
cmpq   $0x0,(%rax,%rcx,8)
jne    1176 <errstr+0x66>
mov    -0xc(%rbp),%ecx
lea    0x2eeb(%rip),%rdi
mov    $0x64,%esi
lea    0xed1(%rip),%rdx
call   1030 <snprintf@plt>
lea    0x2ed3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1189 <errstr+0x79>
movslq -0xc(%rbp),%rcx
lea    0x287f(%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):
<errstr>:
push   %rbx
mov    %edi,%ecx
lea    -0x84(%rcx),%eax
cmp    $0xfffffffb,%eax
ja     113b <errstr+0x2b>
lea    0x2f1b(%rip),%rbx
lea    0xf06(%rip),%rdx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1030 <snprintf@plt>
jmp    1148 <errstr+0x38>
mov    %ecx,%eax
lea    0x28bc(%rip),%rcx
mov    (%rcx,%rax,8),%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@errstr.strs = internal constant [132 x i8*] [i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i32 0, i32 0)]
@.str = [11 x i8] c"GLOB_NOSYS\00"
@.str.1 = [13 x i8] c"GLOB_NOSPACE\00"
@.str.2 = [13 x i8] c"GLOB_NOMATCH\00"
@.str.3 = [13 x i8] c"GLOB_ABORTED\00"
@errstr.buf = internal global [100 x i8] zeroinitializer
@.str.4 = [14 x i8] c"GLOB_??? (%d)\00"
define i8* @errstr(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 %16, label %6
6: ; preds = %1
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = icmp uge i64 %8, 132
br i1 %9, label %16, label %10
10: ; preds = %6
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [132 x i8*], [132 x i8*]* @errstr.strs, i64 0, i64 %12
%14 = load i8*, i8** %13
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %10, %6, %1
%17 = load i32, i32* %3
%18 = call i32 @snprintf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @errstr.buf, i64 0, i64 0), i32 100, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %17)
store i8* getelementptr inbounds ([100 x i8], [100 x i8]* @errstr.buf, i64 0, i64 0), i8** %2
br label %24
19: ; preds = %10
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [132 x i8*], [132 x i8*]* @errstr.strs, i64 0, i64 %21
%23 = load i8*, i8** %22
store i8* %23, i8** %2
br label %24
24: ; preds = %19, %16
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@errstr.strs = internal unnamed_addr constant [132 x i8*] [i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* null, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i32 0, i32 0)]
@.str = [11 x i8] c"GLOB_NOSYS\00"
@.str.1 = [13 x i8] c"GLOB_NOSPACE\00"
@.str.2 = [13 x i8] c"GLOB_NOMATCH\00"
@.str.3 = [13 x i8] c"GLOB_ABORTED\00"
@errstr.buf = internal global [100 x i8] zeroinitializer
@.str.4 = [14 x i8] c"GLOB_??? (%d)\00"
define i8* @errstr(i32 %0) {
%2 = add i32 %0, -132
%3 = icmp ult i32 %2, -4
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @snprintf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @errstr.buf, i64 0, i64 0), i32 100, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %0)
br label %10
6: ; preds = %1
%7 = zext i32 %0 to i64
%8 = getelementptr inbounds [132 x i8*], [132 x i8*]* @errstr.strs, i64 0, i64 %7
%9 = load i8*, i8** %8
br label %10
10: ; preds = %6, %4
%11 = phi i8* [ getelementptr inbounds ([100 x i8], [100 x i8]* @errstr.buf, i64 0, i64 0), %4 ], [ %9, %6 ]
ret i8* %11
}