#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 char *flagstr(int flags) {
  const char *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    $0x90,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x80(%rbp),%rdi
lea    0x2c57(%rip),%rsi
mov    $0x78,%edx
call   1040 <memcpy@plt>
lea    0x2ef6(%rip),%rax
mov    %rax,-0x88(%rbp)
movl   $0x0,-0x8c(%rbp)
movslq -0x8c(%rbp),%rax
cmp    $0xf,%rax
jae    1213 <flagstr+0xe3>
mov    -0x4(%rbp),%eax
mov    -0x8c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11fa <flagstr+0xca>
mov    -0x8c(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
lea    0x2e9a(%rip),%rax
cmp    %rax,-0x88(%rbp)
je     11db <flagstr+0xab>
mov    -0x88(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x88(%rbp)
movb   $0x7c,(%rax)
mov    -0x88(%rbp),%rdi
movslq -0x8c(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rsi
call   1030 <stpcpy@plt>
mov    %rax,-0x88(%rbp)
jmp    11ff <flagstr+0xcf>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    116b <flagstr+0x3b>
cmpl   $0x0,-0x4(%rbp)
je     125f <flagstr+0x12f>
lea    0x2e2c(%rip),%rax
cmp    %rax,-0x88(%rbp)
je     1249 <flagstr+0x119>
mov    -0x88(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x88(%rbp)
movb   $0x7c,(%rax)
mov    -0x88(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe61(%rip),%rsi
call   1050 <sprintf@plt>
lea    0x2dea(%rip),%rax
add    $0x90,%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    0xf87(%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    0xf07(%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):
@.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"
@__const.flagstr.strs = [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)]
@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 [15 x i8*]
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
%6 = bitcast [15 x i8*]* %3 to i8*
store i8* getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0), i8** %4
store i32 0, i32* %5
br label %7
7: ; preds = %36, %1
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
%10 = icmp ult i64 %9, 15
br i1 %10, label %11, label %39
11: ; preds = %7
%12 = load i32, i32* %2
%13 = load i32, i32* %5
%14 = shl i32 1, %13
%15 = and i32 %12, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %35
17: ; preds = %11
%18 = load i32, i32* %5
%19 = shl i32 1, %18
%20 = xor i32 %19, -1
%21 = load i32, i32* %2
%22 = and i32 %21, %20
store i32 %22, i32* %2
%23 = load i8*, i8** %4
%24 = icmp ne i8* %23, getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0)
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
store i8 124, i8* %26
br label %28
28: ; preds = %25, %17
%29 = load i8*, i8** %4
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [15 x i8*], [15 x i8*]* %3, i64 0, i64 %31
%33 = load i8*, i8** %32
%34 = call i8* @stpcpy(i8* %29, i8* %33)
store i8* %34, i8** %4
br label %35
35: ; preds = %28, %11
br label %36
36: ; preds = %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %7
39: ; preds = %7
%40 = load i32, i32* %2
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %52
42: ; preds = %39
%43 = load i8*, i8** %4
%44 = icmp ne i8* %43, getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0)
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %4
store i8 124, i8* %46
br label %48
48: ; preds = %45, %42
%49 = load i8*, i8** %4
%50 = load i32, i32* %2
%51 = call i32 @sprintf(i8* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %48, %39
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @flagstr.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@.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"
@reltable.flagstr = [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)]
@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)
}