#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;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
char *stpcpy(char *, char const *const);
const char *flagstr(int flags) {
  static const char *const strs[] = {
      "GLOB_ERR",     "GLOB_MARK",       "GLOB_NOSORT",    "GLOB_DOOFSS",
      "GLOB_NOCHECK", "GLOB_APPEND",     "GLOB_NOESCAPE",  "GLOB_PERIOD",
      "GLOB_MAGCHAR", "GLOB_ALTDIRFUNC", "GLOB_BRACE",     "GLOB_NOMAGIC",
      "GLOB_TILDE",   "GLOB_ONLYDIR",    "GLOB_TILDECHECK"};
  static char buf[100];
  char *cp = buf;
  int cnt;
  for (cnt = 0; cnt < (sizeof(strs) / sizeof(strs[0])); ++cnt)
    if (flags & (1 << cnt)) {
      flags &= ~(1 << cnt);
      if (cp != buf)
        *cp++ = '|';
      cp = stpcpy(cp, strs[cnt]);
    }
  if (flags != 0) {
    if (cp != buf)
      *cp++ = '|';
    sprintf(cp, "%#x", flags);
  }
  return buf;
}


x86 assembly (clang, -O0):
<flagstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0x2f0e(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0xf,%rax
jae    11ca <flagstr+0xaa>
mov    -0x4(%rbp),%eax
mov    -0x14(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11b7 <flagstr+0x97>
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
lea    0x2ec1(%rip),%rax
cmp    %rax,-0x10(%rbp)
je     119b <flagstr+0x7b>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x7c,(%rax)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rcx
lea    0x2bf6(%rip),%rax
mov    (%rax,%rcx,8),%rsi
call   1030 <stpcpy@plt>
mov    %rax,-0x10(%rbp)
jmp    11bc <flagstr+0x9c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <flagstr+0x1d>
cmpl   $0x0,-0x4(%rbp)
je     120a <flagstr+0xea>
lea    0x2e65(%rip),%rax
cmp    %rax,-0x10(%rbp)
je     11f7 <flagstr+0xd7>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x7c,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xeb6(%rip),%rsi
call   1040 <sprintf@plt>
lea    0x2e2f(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flagstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r12d
lea    0x2f0e(%rip),%r14
lea    0xec7(%rip),%r15
xor    %ebx,%ebx
mov    %r15,%rbp
mov    %r14,%rax
jmp    116f <flagstr+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
not    %edx
and    %edx,%r12d
movslq 0x0(%rbp),%rsi
add    %r15,%rsi
call   1030 <stpcpy@plt>
add    $0x1,%rbx
add    $0x4,%rbp
cmp    $0xf,%rbx
je     1192 <flagstr+0x72>
mov    $0x1,%edx
mov    %ebx,%ecx
shl    %cl,%edx
bt     %ebx,%r12d
jae    1161 <flagstr+0x41>
mov    %r14,%rdi
cmp    %r14,%rax
je     1150 <flagstr+0x30>
movb   $0x7c,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
jmp    1150 <flagstr+0x30>
test   %r12d,%r12d
je     11bc <flagstr+0x9c>
lea    0x2ea2(%rip),%rdi
cmp    %rdi,%rax
je     11ad <flagstr+0x8d>
movb   $0x7c,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
lea    0xf43(%rip),%rsi
mov    %r12d,%edx
call   1040 <sprintf@plt>
lea    0x2e7d(%rip),%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@flagstr.strs = internal constant [15 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.14, i32 0, i32 0)]
@.str = [9 x i8] c"GLOB_ERR\00"
@.str.1 = [10 x i8] c"GLOB_MARK\00"
@.str.2 = [12 x i8] c"GLOB_NOSORT\00"
@.str.3 = [12 x i8] c"GLOB_DOOFSS\00"
@.str.4 = [13 x i8] c"GLOB_NOCHECK\00"
@.str.5 = [12 x i8] c"GLOB_APPEND\00"
@.str.6 = [14 x i8] c"GLOB_NOESCAPE\00"
@.str.7 = [12 x i8] c"GLOB_PERIOD\00"
@.str.8 = [13 x i8] c"GLOB_MAGCHAR\00"
@.str.9 = [16 x i8] c"GLOB_ALTDIRFUNC\00"
@.str.10 = [11 x i8] c"GLOB_BRACE\00"
@.str.11 = [13 x i8] c"GLOB_NOMAGIC\00"
@.str.12 = [11 x i8] c"GLOB_TILDE\00"
@.str.13 = [13 x i8] c"GLOB_ONLYDIR\00"
@.str.14 = [16 x i8] c"GLOB_TILDECHECK\00"
@flagstr.buf = internal global [100 x i8] zeroinitializer
@.str.15 = [4 x i8] c"%#x\00"
define i8* @flagstr(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
store i8* getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0), i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %34, %1
%6 = load i32, i32* %4
%7 = sext i32 %6 to i64
%8 = icmp ult i64 %7, 15
br i1 %8, label %9, label %37
9: ; preds = %5
%10 = load i32, i32* %2
%11 = load i32, i32* %4
%12 = shl i32 1, %11
%13 = and i32 %10, %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %9
%16 = load i32, i32* %4
%17 = shl i32 1, %16
%18 = xor i32 %17, -1
%19 = load i32, i32* %2
%20 = and i32 %19, %18
store i32 %20, i32* %2
%21 = load i8*, i8** %3
%22 = icmp ne i8* %21, getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0)
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %3
store i8 124, i8* %24
br label %26
26: ; preds = %23, %15
%27 = load i8*, i8** %3
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [15 x i8*], [15 x i8*]* @flagstr.strs, i64 0, i64 %29
%31 = load i8*, i8** %30
%32 = call i8* @stpcpy(i8* %27, i8* %31)
store i8* %32, i8** %3
br label %33
33: ; preds = %26, %9
br label %34
34: ; preds = %33
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %5
37: ; preds = %5
%38 = load i32, i32* %2
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %50
40: ; preds = %37
%41 = load i8*, i8** %3
%42 = icmp ne i8* %41, getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0)
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i8*, i8** %3
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %3
store i8 124, i8* %44
br label %46
46: ; preds = %43, %40
%47 = load i8*, i8** %3
%48 = load i32, i32* %2
%49 = call i32 @sprintf(i8* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %46, %37
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@reltable.flagstr = internal unnamed_addr constant [15 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.1 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.2 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.3 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.4 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.5 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.6 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.7 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.8 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.9 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.10 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.11 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.12 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.13 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.14 to i64), i64 ptrtoint ([15 x i32]* @reltable.flagstr to i64)) to i32)]
@.str = [9 x i8] c"GLOB_ERR\00"
@.str.1 = [10 x i8] c"GLOB_MARK\00"
@.str.2 = [12 x i8] c"GLOB_NOSORT\00"
@.str.3 = [12 x i8] c"GLOB_DOOFSS\00"
@.str.4 = [13 x i8] c"GLOB_NOCHECK\00"
@.str.5 = [12 x i8] c"GLOB_APPEND\00"
@.str.6 = [14 x i8] c"GLOB_NOESCAPE\00"
@.str.7 = [12 x i8] c"GLOB_PERIOD\00"
@.str.8 = [13 x i8] c"GLOB_MAGCHAR\00"
@.str.9 = [16 x i8] c"GLOB_ALTDIRFUNC\00"
@.str.10 = [11 x i8] c"GLOB_BRACE\00"
@.str.11 = [13 x i8] c"GLOB_NOMAGIC\00"
@.str.12 = [11 x i8] c"GLOB_TILDE\00"
@.str.13 = [13 x i8] c"GLOB_ONLYDIR\00"
@.str.14 = [16 x i8] c"GLOB_TILDECHECK\00"
@flagstr.buf = internal global [100 x i8] zeroinitializer
@.str.15 = [4 x i8] c"%#x\00"
define i8* @flagstr(i32 %0) {
br label %2
2: ; preds = %1, %21
%3 = phi i64 [ 0, %1 ], [ %24, %21 ]
%4 = phi i8* [ getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0), %1 ], [ %23, %21 ]
%5 = phi i32 [ %0, %1 ], [ %22, %21 ]
%6 = trunc i64 %3 to i32
%7 = shl nuw nsw i32 1, %6
%8 = and i32 %7, %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %2
%11 = xor i32 %7, -1
%12 = and i32 %5, %11
%13 = icmp eq i8* %4, getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0)
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %4, i64 1
store i8 124, i8* %4
br label %16
16: ; preds = %14, %10
%17 = phi i8* [ %15, %14 ], [ getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0), %10 ]
%18 = shl i64 %3, 2
%19 = call i8* @llvm.load.relative.i64(i8* bitcast ([15 x i32]* @reltable.flagstr to i8*), i64 %18)
%20 = tail call i8* @stpcpy(i8* %17, i8* %19)
br label %21
21: ; preds = %2, %16
%22 = phi i32 [ %12, %16 ], [ %5, %2 ]
%23 = phi i8* [ %20, %16 ], [ %4, %2 ]
%24 = add nuw nsw i64 %3, 1
%25 = icmp eq i64 %24, 15
br i1 %25, label %26, label %2
26: ; preds = %21
%27 = icmp eq i32 %22, 0
br i1 %27, label %35, label %28
28: ; preds = %26
%29 = icmp eq i8* %23, getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0)
br i1 %29, label %32, label %30
30: ; preds = %28
%31 = getelementptr inbounds i8, i8* %23, i64 1
store i8 124, i8* %23
br label %32
32: ; preds = %30, %28
%33 = phi i8* [ %31, %30 ], [ getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0), %28 ]
%34 = tail call i32 @sprintf(i8* dereferenceable(1) %33, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i32 %22)
br label %35
35: ; preds = %32, %26
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0)
}