#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*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char const *);
char *strdup(char *);
size_t strlen(char *);
char *reverse_parse_known_options(int option_code, const int *atflags,
                                  const char **atstrings, const int arr_size) {
  if (option_code == 0) {
    return NULL;
  }
  size_t idx, bufsiz = 2048;
  char options[bufsiz];
  memset(options, 0, bufsiz);
  for (idx = 0; idx < arr_size; idx++) {
    if (0 != (atflags[idx] & option_code)) {
      char *cur = &(options[strlen(options)]);
      snprintf(cur, bufsiz - strlen(cur), "%s ", atstrings[idx]);
    }
  }
  if (strlen(options) > 0) {
    return strdup(options);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<reverse_parse_known_options>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    116d <reverse_parse_known_options+0x2d>
movq   $0x0,-0x8(%rbp)
jmp    1283 <reverse_parse_known_options+0x143>
movq   $0x800,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x60(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmp    %rcx,%rax
jae    1241 <reverse_parse_known_options+0x101>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
and    -0xc(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     122b <reverse_parse_known_options+0xeb>
mov    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x70(%rbp),%rsi
mov    -0x68(%rbp),%rdi
sub    %rax,%rsi
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xdda(%rip),%rdx
call   1040 <snprintf@plt>
jmp    1230 <reverse_parse_known_options+0xf0>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11af <reverse_parse_known_options+0x6f>
mov    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jbe    126d <reverse_parse_known_options+0x12d>
mov    -0x60(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    127c <reverse_parse_known_options+0x13c>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_parse_known_options>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,-0x38(%rbp)
mov    %rsi,-0x40(%rbp)
test   %edi,%edi
je     11f7 <reverse_parse_known_options+0xb7>
mov    %ecx,%r13d
mov    %edi,%r12d
mov    %rsp,-0x30(%rbp)
mov    %rsp,%rbx
add    $0xfffffffffffff800,%rbx
mov    %rbx,%rsp
mov    $0x800,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
test   %r13d,%r13d
je     11e8 <reverse_parse_known_options+0xa8>
movslq %r13d,%r14
xor    %r15d,%r15d
jmp    11a9 <reverse_parse_known_options+0x69>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r15
cmp    %r15,%r14
je     11e8 <reverse_parse_known_options+0xa8>
mov    -0x40(%rbp),%rax
test   %r12d,(%rax,%r15,4)
je     11a0 <reverse_parse_known_options+0x60>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbx,1),%r13
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    $0x800,%esi
sub    %rax,%rsi
mov    -0x38(%rbp),%rax
mov    (%rax,%r15,8),%rcx
mov    %r13,%rdi
lea    0xe1f(%rip),%rdx
call   1040 <snprintf@plt>
jmp    11a0 <reverse_parse_known_options+0x60>
cmpb   $0x0,(%rbx)
je     11fb <reverse_parse_known_options+0xbb>
mov    %rbx,%rdi
call   1060 <strdup@plt>
jmp    11fd <reverse_parse_known_options+0xbd>
xor    %eax,%eax
jmp    1201 <reverse_parse_known_options+0xc1>
xor    %eax,%eax
mov    -0x30(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s \00"
define i8* @reverse_parse_known_options(i32 %0, i32* %1, i8** %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i8*
%15 = alloca i32
store i32 %0, i32* %6
store i32* %1, i32** %7
store i8** %2, i8*** %8
store i32 %3, i32* %9
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %4
store i8* null, i8** %5
br label %63
19: ; preds = %4
store i64 2048, i64* %11
%20 = load i64, i64* %11
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %12
%22 = alloca i8, i64 %20
store i64 %20, i64* %13
%23 = load i64, i64* %11
%24 = call i32 @memset(i8* %22, i32 0, i64 %23)
store i64 0, i64* %10
br label %25
25: ; preds = %52, %19
%26 = load i64, i64* %10
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = icmp ult i64 %26, %28
br i1 %29, label %30, label %55
30: ; preds = %25
%31 = load i32*, i32** %7
%32 = load i64, i64* %10
%33 = getelementptr inbounds i32, i32* %31, i64 %32
%34 = load i32, i32* %33
%35 = load i32, i32* %6
%36 = and i32 %34, %35
%37 = icmp ne i32 0, %36
br i1 %37, label %38, label %51
38: ; preds = %30
%39 = call i64 @strlen(i8* %22)
%40 = getelementptr inbounds i8, i8* %22, i64 %39
store i8* %40, i8** %14
%41 = load i8*, i8** %14
%42 = load i64, i64* %11
%43 = load i8*, i8** %14
%44 = call i64 @strlen(i8* %43)
%45 = sub i64 %42, %44
%46 = load i8**, i8*** %8
%47 = load i64, i64* %10
%48 = getelementptr inbounds i8*, i8** %46, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 @snprintf(i8* %41, i64 %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %38, %30
br label %52
52: ; preds = %51
%53 = load i64, i64* %10
%54 = add i64 %53, 1
store i64 %54, i64* %10
br label %25
55: ; preds = %25
%56 = call i64 @strlen(i8* %22)
%57 = icmp ugt i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i8* @strdup(i8* %22)
store i8* %59, i8** %5
store i32 1, i32* %15
br label %61
60: ; preds = %55
store i8* null, i8** %5
store i32 1, i32* %15
br label %61
61: ; preds = %60, %58
%62 = load i8*, i8** %12
br label %63
63: ; preds = %61, %18
%64 = load i8*, i8** %5
ret i8* %64
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s \00"
define noalias i8* @reverse_parse_known_options(i32 %0, i32* nocapture %1, i8** nocapture %2, i32 %3) {
%5 = icmp eq i32 %0, 0
br i1 %5, label %38, label %6
6: ; preds = %4
%7 = tail call i8* @llvm.stacksave()
%8 = alloca [2048 x i8]
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i64 2048)
%11 = icmp eq i32 %3, 0
br i1 %11, label %31, label %12
12: ; preds = %6
%13 = sext i32 %3 to i64
br label %14
14: ; preds = %12, %28
%15 = phi i64 [ %29, %28 ], [ 0, %12 ]
%16 = getelementptr inbounds i32, i32* %1, i64 %15
%17 = load i32, i32* %16
%18 = and i32 %17, %0
%19 = icmp eq i32 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %14
%21 = call i64 @strlen(i8* %9)
%22 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 %21
%23 = call i64 @strlen(i8* %22)
%24 = sub i64 2048, %23
%25 = getelementptr inbounds i8*, i8** %2, i64 %15
%26 = load i8*, i8** %25
%27 = call i32 @snprintf(i8* %22, i64 %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %14, %20
%29 = add nuw i64 %15, 1
%30 = icmp eq i64 %29, %13
br i1 %30, label %31, label %14
31: ; preds = %28, %6
%32 = load i8, i8* %9
%33 = icmp eq i8 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = call i8* @strdup(i8* %9)
br label %36
36: ; preds = %31, %34
%37 = phi i8* [ %35, %34 ], [ null, %31 ]
br label %38
38: ; preds = %4, %36
%39 = phi i8* [ %37, %36 ], [ null, %4 ]
ret i8* %39
}