// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/flags.cpp
// Function: flag::Flag::parse(int*, char***, bool)
int Flag::parse(int * p_argc, char *** p_argv, const bool remove_flags) {
  int argc = *p_argc;
  char ** argv = *p_argv;

  // Grab the program name from argv[0] for --help output later.
  prog_name = argv[0];

  // Put the options into an array, as getopt expects them.
  struct option * options = new struct option[Flag::options().size() + 1];
  int x = 0;
  typedef list<struct option>::iterator iter;
  for (iter i = Flag::options().begin(), e = Flag::options().end(); i != e; ++i) {
    options[x++] = *i;
  }
  // This sentinel is needed to prevent the getopt library from segfaulting
  // when an unknown long option is seen first on the list of flags.
  struct option sentinel = {0, 0, 0, 0};
  options[x] = sentinel;

  // Parse the arguments.
  for (int c = 0, index = 0; c != -1; index = 0) {
    c = getopt_long(argc, argv, Flag::codes().c_str(), options, &index);
    switch (c) {
      case -1: break;

      case 0: {  // longopt with no short name.
        const string long_name = options[index].name;
        Flag * flag = Flag::long_names()[long_name];
        if (flag) flag -> set(optarg);
        if (flag == &FLAGS_OPT_help) {
          Flag::show_help(cout);
          delete [] options;
          exit(0);
        }
        break;
      }

      case '?': {  // unknown option.
        Flag::show_help(cerr);
        delete [] options;
        exit(1);
      }

      default: {  // short option
        if (Flag::short_names().find(c) == Flag::short_names().end()) {
          // This should never happen.
          cerr << "ERROR: failed to find a flag matching '" << c << "'" << endl;
        } else {
          Flag * flag = Flag::short_names()[c];
          if (flag) flag -> set(optarg);
        }
        break;
      }
    }
  }

  // Trim the non-argument params from argv.
  if (remove_flags) {
    for (*p_argc = 0; optind < argc; ++optind, ++(*p_argc)) {
      argv[*p_argc] = argv[optind];
    }
  }

  delete [] options;
  return 0;
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
movb %dl, %al
movq %rdi, 0x110(%rsp)
movq %rsi, 0x108(%rsp)
andb $0x1, %al
movb %al, 0x107(%rsp)
movq 0x110(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x100(%rsp)
movq 0x108(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xf8(%rsp)
movq 0xf8(%rsp), %rax
movq (%rax), %rsi
leaq 0x3b8c0(%rip), %rdi     # 0xd24f8
callq 0x85a0
callq 0x98020
movq %rax, %rdi
callq 0x980b0
addq $0x1, %rax
movl $0x20, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x8030
movq %rax, 0xf0(%rsp)
movl $0x0, 0xec(%rsp)
callq 0x98020
movq %rax, %rdi
callq 0x980c0
movq %rax, 0xe0(%rsp)
callq 0x98020
movq %rax, %rdi
callq 0x980f0
movq %rax, 0xd8(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x98120
testb $0x1, %al
jne 0x96cc7
jmp 0x96d29
leaq 0xe0(%rsp), %rdi
callq 0x98140
movq %rax, %rcx
movq 0xf0(%rsp), %rax
movl 0xec(%rsp), %edx
movl %edx, %esi
addl $0x1, %esi
movl %esi, 0xec(%rsp)
movslq %edx, %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rax)
leaq 0xe0(%rsp), %rdi
callq 0x98160
jmp 0x96cac
leaq 0xb8(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x8200
movq 0xf0(%rsp), %rax
movslq 0xec(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0xb8(%rsp), %rcx
movq %rcx, (%rax)
movq 0xc0(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0xc8(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0xd0(%rsp), %rcx
movq %rcx, 0x18(%rax)
movl $0x0, 0xb4(%rsp)
movl $0x0, 0xb0(%rsp)
cmpl $-0x1, 0xb4(%rsp)
je 0x97082
movl 0x100(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x40(%rsp)
callq 0x98180
movq %rax, %rdi
callq 0x8190
movl 0x3c(%rsp), %edi
movq 0x40(%rsp), %rsi
movq %rax, %rdx
movq 0xf0(%rsp), %rcx
leaq 0xb0(%rsp), %r8
callq 0x8720
movl %eax, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
movl %eax, 0x48(%rsp)
subl $-0x1, %eax
je 0x96e22
jmp 0x96e06
movl 0x48(%rsp), %eax
testl %eax, %eax
je 0x96e27
jmp 0x96e10
movl 0x48(%rsp), %eax
subl $0x3f, %eax
je 0x96f6c
jmp 0x96f9f
jmp 0x97070
movq 0xf0(%rsp), %rax
movslq 0xb0(%rsp), %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rax
movq %rax, 0x28(%rsp)
leaq 0x8f(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x87f0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x90(%rsp), %rdi
callq 0x85b0
jmp 0x96e6f
leaq 0x8f(%rsp), %rdi
callq 0x84a0
callq 0x98210
movq %rax, 0x20(%rsp)
jmp 0x96e88
movq 0x20(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x982a0
movq %rax, 0x18(%rsp)
jmp 0x96ea1
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x70(%rsp)
je 0x96f15
movq 0x70(%rsp), %rdi
movq 0x390ce(%rip), %rax     # 0xcff90
movq (%rax), %rsi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
jmp 0x96ed0
jmp 0x96f15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0x8f(%rsp), %rdi
callq 0x84a0
jmp 0x97126
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x88f8
jmp 0x96f67
leaq 0x3b5fc(%rip), %rax     # 0xd2518
cmpq %rax, 0x70(%rsp)
jne 0x96f55
movq 0x3908e(%rip), %rdi     # 0xcffb8
callq 0x96aa0
jmp 0x96f31
movq 0xf0(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x96f4e
movq 0x10(%rsp), %rdi
callq 0x8560
xorl %edi, %edi
callq 0x8530
leaq 0x90(%rsp), %rdi
callq 0x88f8
jmp 0x97070
jmp 0x97126
movq 0x3907d(%rip), %rdi     # 0xcfff0
callq 0x96aa0
movq 0xf0(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x96f95
movq 0x8(%rsp), %rdi
callq 0x8560
movl $0x1, %edi
callq 0x8530
callq 0x98430
movq %rax, %rdi
movl 0xb4(%rsp), %eax
movb %al, 0x67(%rsp)
leaq 0x67(%rsp), %rsi
callq 0x984c0
movq %rax, 0x68(%rsp)
callq 0x98430
movq %rax, %rdi
callq 0x984f0
movq %rax, 0x58(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x98410
testb $0x1, %al
jne 0x96fe8
jmp 0x9702a
movq 0x39001(%rip), %rdi     # 0xcfff0
leaq 0x1b9fa(%rip), %rsi     # 0xb29f0
callq 0x8400
movq %rax, %rdi
movl 0xb4(%rsp), %esi
callq 0x8780
movq %rax, %rdi
leaq 0x1bdd2(%rip), %rsi     # 0xb2de6
callq 0x8400
movq %rax, %rdi
movq 0x38f65(%rip), %rsi     # 0xcff88
callq 0x8470
jmp 0x9706e
callq 0x98430
movq %rax, %rdi
movl 0xb4(%rsp), %eax
movb %al, 0x4f(%rsp)
leaq 0x4f(%rsp), %rsi
callq 0x98520
movq (%rax), %rax
movq %rax, 0x50(%rsp)
cmpq $0x0, 0x50(%rsp)
je 0x9706c
movq 0x50(%rsp), %rdi
movq 0x38f2d(%rip), %rax     # 0xcff90
movq (%rax), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
jmp 0x9706e
jmp 0x97070
jmp 0x97072
movl $0x0, 0xb0(%rsp)
jmp 0x96d99
testb $0x1, 0x107(%rsp)
je 0x97101
movq 0x110(%rsp), %rax
movl $0x0, (%rax)
movq 0x38f27(%rip), %rax     # 0xcffc8
movl (%rax), %eax
cmpl 0x100(%rsp), %eax
jge 0x970ff
movq 0xf8(%rsp), %rax
movq 0x38f0d(%rip), %rcx     # 0xcffc8
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdx
movq 0xf8(%rsp), %rax
movq 0x110(%rsp), %rcx
movslq (%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x38ee8(%rip), %rax     # 0xcffc8
movl (%rax), %ecx
addl $0x1, %ecx
movq 0x38edc(%rip), %rax     # 0xcffc8
movl %ecx, (%rax)
movq 0x110(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x9709a
jmp 0x97101
movq 0xf0(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x9711c
movq (%rsp), %rdi
callq 0x8560
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
retq
movq 0x80(%rsp), %rdi
callq 0x87d0
movq %rax, %rdi
callq 0x8cf60
nopl (%rax,%rax)