// File: /workspace/github_cpp_makefile_star2_O2/jaudoux[P]countTags/src/optionparser.h
// Function: option::Parser::workhorse(bool, option::Descriptor const*, int, char const**, option::Parser::Action&, bool, bool, int)
inline bool Parser::workhorse(bool gnu, const Descriptor usage[], int numargs, const char** args, Action& action,
                              bool single_minus_longopt, bool print_errors, int min_abbr_len)
{
  // protect against NULL pointer
  if (args == 0)
    numargs = 0;

  int nonops = 0;

  while (numargs != 0 && *args != 0)
  {
    const char* param = *args; // param can be --long-option, -srto or non-option argument

    // in POSIX mode the first non-option argument terminates the option list
    // a lone minus character is a non-option argument
    if (param[0] != '-' || param[1] == 0)
    {
      if (gnu)
      {
        ++nonops;
        ++args;
        if (numargs > 0)
          --numargs;
        continue;
      }
      else
        break;
    }

    // -- terminates the option list. The -- itself is skipped.
    if (param[1] == '-' && param[2] == 0)
    {
      shift(args, nonops);
      ++args;
      if (numargs > 0)
        --numargs;
      break;
    }

    bool handle_short_options;
    const char* longopt_name;
    if (param[1] == '-') // if --long-option
    {
      handle_short_options = false;
      longopt_name = param + 2;
    }
    else
    {
      handle_short_options = true;
      longopt_name = param + 1; //for testing a potential -long-option
    }

    bool try_single_minus_longopt = single_minus_longopt;
    bool have_more_args = (numargs > 1 || numargs < 0); // is referencing argv[1] valid?

    do // loop over short options in group, for long options the body is executed only once
    {
      int idx;

      const char* optarg;

      /******************** long option **********************/
      if (handle_short_options == false || try_single_minus_longopt)
      {
        idx = 0;
        while (usage[idx].longopt != 0 && !streq(usage[idx].longopt, longopt_name))
          ++idx;

        if (usage[idx].longopt == 0 && min_abbr_len > 0) // if we should try to match abbreviated long options
        {
          int i1 = 0;
          while (usage[i1].longopt != 0 && !streqabbr(usage[i1].longopt, longopt_name, min_abbr_len))
            ++i1;
          if (usage[i1].longopt != 0)
          { // now test if the match is unambiguous by checking for another match
            int i2 = i1 + 1;
            while (usage[i2].longopt != 0 && !streqabbr(usage[i2].longopt, longopt_name, min_abbr_len))
              ++i2;

            if (usage[i2].longopt == 0) // if there was no second match it's unambiguous, so accept i1 as idx
              idx = i1;
          }
        }

        // if we found something, disable handle_short_options (only relevant if single_minus_longopt)
        if (usage[idx].longopt != 0)
          handle_short_options = false;

        try_single_minus_longopt = false; // prevent looking for longopt in the middle of shortopt group

        optarg = longopt_name;
        while (*optarg != 0 && *optarg != '=')
          ++optarg;
        if (*optarg == '=') // attached argument
          ++optarg;
        else
          // possibly detached argument
          optarg = (have_more_args ? args[1] : 0);
      }

      /************************ short option ***********************************/
      if (handle_short_options)
      {
        if (*++param == 0) // point at the 1st/next option character
          break; // end of short option group

        idx = 0;
        while (usage[idx].shortopt != 0 && !instr(*param, usage[idx].shortopt))
          ++idx;

        if (param[1] == 0) // if the potential argument is separate
          optarg = (have_more_args ? args[1] : 0);
        else
          // if the potential argument is attached
          optarg = param + 1;
      }

      const Descriptor* descriptor = &usage[idx];

      if (descriptor->shortopt == 0) /**************  unknown option ********************/
      {
        // look for dummy entry (shortopt == "" and longopt == "") to use as Descriptor for unknown options
        idx = 0;
        while (usage[idx].shortopt != 0 && (usage[idx].shortopt[0] != 0 || usage[idx].longopt[0] != 0))
          ++idx;
        descriptor = (usage[idx].shortopt == 0 ? 0 : &usage[idx]);
      }

      if (descriptor != 0)
      {
        Option option(descriptor, param, optarg);
        switch (descriptor->check_arg(option, print_errors))
        {
          case ARG_ILLEGAL:
            return false; // fatal
          case ARG_OK:
            // skip one element of the argument vector, if it's a separated argument
            if (optarg != 0 && have_more_args && optarg == args[1])
            {
              shift(args, nonops);
              if (numargs > 0)
                --numargs;
              ++args;
            }

            // No further short options are possible after an argument
            handle_short_options = false;

            break;
          case ARG_IGNORE:
          case ARG_NONE:
            option.arg = 0;
            break;
        }

        if (!action.perform(option))
          return false;
      }

    } while (handle_short_options);

    shift(args, nonops);
    ++args;
    if (numargs > 0)
      --numargs;

  } // while

  if (numargs > 0 && *args == 0) // It's a bug in the caller if numargs is greater than the actual number
    numargs = 0; // of arguments, but as a service to the user we fix this if we spot it.

  if (numargs < 0) // if we don't know the number of remaining non-option arguments
  { // we need to count them
    numargs = 0;
    while (args[numargs] != 0)
      ++numargs;
  }

  return action.finished(numargs + nonops, args - nonops);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %r9d, 0x2c(%rsp)
movq %r8, 0x30(%rsp)
movq %rcx, %r15
movl %edx, %r14d
xorl %eax, %eax
testq %rcx, %rcx
cmovel %eax, %r14d
leaq 0x10(%rsi), %rax
movq %rax, 0x38(%rsp)
leaq 0x38(%rsi), %rax
movq %rax, 0x40(%rsp)
leaq 0x8(%rsi), %rax
movq %rax, 0x48(%rsp)
xorl %ebp, %ebp
movq %rsi, (%rsp)
movl %edi, 0x28(%rsp)
testl %r14d, %r14d
je 0x364b
movq (%r15), %rax
testq %rax, %rax
je 0x3668
cmpb $0x2d, (%rax)
jne 0x3348
movq %rax, 0x8(%rsp)
movzbl 0x1(%rax), %eax
cmpl $0x2d, %eax
je 0x3358
testl %eax, %eax
movq 0x8(%rsp), %r8
jne 0x3368
testb %dil, %dil
je 0x3668
incl %ebp
jmp 0x3633
movq 0x8(%rsp), %r8
cmpb $0x0, 0x2(%r8)
je 0x364f
movl %ebp, 0x24(%rsp)
leaq 0x1(%r8), %rcx
movl %r14d, %edx
leaq 0x2(%r8), %r14
cmpb $0x2d, %al
cmovneq %rcx, %r14
setne %bpl
leaq 0x1(%r14), %rax
movq %rax, 0x50(%rsp)
movl %edx, 0x14(%rsp)
movl %edx, 0x10(%rsp)
movl 0x2c(%rsp), %eax
movq %r15, 0x18(%rsp)
notb %al
andb %bpl, %al
testb $0x1, %al
jne 0x34a1
xorl %r12d, %r12d
movq 0x38(%rsp), %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x33cd
movq %r14, %rsi
callq 0x3702
testb %al, %al
jne 0x33d1
incl %r12d
addq $0x28, %rbx
jmp 0x33b0
movb $0x1, %al
jmp 0x33d8
cmpq $0x0, (%rbx)
sete %al
movl 0xc8(%rsp), %ecx
testl %ecx, %ecx
movq (%rsp), %rsi
jle 0x3462
testb %al, %al
je 0x3462
movq 0x40(%rsp), %r13
movq 0x38(%rsp), %r15
xorl %ebx, %ebx
movq (%r15), %rdi
testq %rdi, %rdi
je 0x3459
movq %r14, %rsi
movl 0xc8(%rsp), %edx
callq 0x372a
testb %al, %al
jne 0x341f
incq %rbx
addq $0x28, %r15
addq $0x28, %r13
jmp 0x33f7
cmpq $0x0, (%r15)
je 0x3459
movq 0x18(%rsp), %r15
movq (%r13), %rdi
testq %rdi, %rdi
je 0x3561
movq %r14, %rsi
movl 0xc8(%rsp), %edx
callq 0x372a
addq $0x28, %r13
testb %al, %al
je 0x342a
cmpq $0x0, -0x28(%r13)
cmovel %ebx, %r12d
jmp 0x345e
movq 0x18(%rsp), %r15
movq (%rsp), %rsi
movslq %r12d, %rax
imulq $0x28, %rax, %rax
cmpq $0x0, 0x10(%rsi,%rax)
movzbl %bpl, %ebp
movl $0x0, %eax
cmovnel %eax, %ebp
movq 0x50(%rsp), %rbx
movzbl -0x1(%rbx), %eax
testl %eax, %eax
je 0x3492
cmpl $0x3d, %eax
je 0x34a1
incq %rbx
jmp 0x3480
cmpl $0x1, 0x14(%rsp)
jne 0x349d
xorl %ebx, %ebx
jmp 0x34a1
movq 0x8(%r15), %rbx
testb $0x1, %bpl
je 0x351b
movq 0x8(%rsp), %rax
cmpb $0x0, 0x1(%rax)
je 0x3618
leaq 0x1(%rax), %r13
xorl %r12d, %r12d
movq 0x48(%rsp), %rbx
movq (%rbx), %rsi
testq %rsi, %rsi
je 0x34e1
movsbl (%r13), %edi
callq 0x3766
testb %al, %al
jne 0x34e1
incl %r12d
addq $0x28, %rbx
jmp 0x34c2
movq 0x8(%rsp), %rbx
movb 0x2(%rbx), %al
addq $0x2, %rbx
testb %al, %al
movl $0x0, %ecx
cmoveq %rcx, %rbx
cmpl $0x1, 0x14(%rsp)
je 0x3512
testb %al, %al
movq (%rsp), %rsi
jne 0x350b
movq 0x8(%r15), %rbx
movq %r13, 0x8(%rsp)
jmp 0x351b
movq %r13, 0x8(%rsp)
movq (%rsp), %rsi
movslq %r12d, %rax
imulq $0x28, %rax, %r13
cmpq $0x0, 0x8(%rsi,%r13)
jne 0x3569
xorl %r12d, %r12d
movq %rsi, %r13
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x3550
cmpb $0x0, (%rax)
jne 0x3547
movq 0x10(%r13), %rax
cmpb $0x0, (%rax)
je 0x356c
incl %r12d
addq $0x28, %r13
jmp 0x3530
xorl %eax, %eax
testb $0x1, %bpl
jne 0x339b
jmp 0x3618
movl %ebx, %r12d
jmp 0x345e
addq %rsi, %r13
leaq 0x58(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
movq %rbx, %rcx
callq 0x377c
movzbl 0xc0(%rsp), %esi
movq %r15, %rdi
callq *0x18(%r13)
cmpl $0x3, %eax
ja 0x35f0
movl %eax, %eax
leaq 0x2b0f(%rip), %rcx      # 0x60b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq 0x18(%rsp), %r15
jmpq *%rax
andq $0x0, 0x78(%rsp)
jmp 0x35f5
xorl %ebp, %ebp
cmpl $0x1, 0x14(%rsp)
je 0x35f5
testq %rbx, %rbx
je 0x35f5
cmpq 0x8(%r15), %rbx
jne 0x35ec
movq %r15, %rdi
addq $0x8, %r15
movl 0x24(%rsp), %esi
callq 0x36de
xorl %eax, %eax
movl 0x10(%rsp), %ecx
testl %ecx, %ecx
setg %al
subl %eax, %ecx
movl %ecx, 0x10(%rsp)
xorl %ebp, %ebp
jmp 0x35f5
movq 0x18(%rsp), %r15
movq 0x30(%rsp), %rdi
movq (%rdi), %rax
leaq 0x58(%rsp), %rsi
callq *(%rax)
testb %al, %al
je 0x3647
xorl %eax, %eax
testb $0x1, %bpl
movq (%rsp), %rsi
jne 0x3396
movq %r15, %rdi
movl 0x24(%rsp), %ebp
movl %ebp, %esi
callq 0x36de
movq (%rsp), %rsi
movl 0x10(%rsp), %r14d
movl 0x28(%rsp), %edi
xorl %eax, %eax
testl %r14d, %r14d
setg %al
subl %eax, %r14d
addq $0x8, %r15
jmp 0x3317
xorl %eax, %eax
jmp 0x36ac
xorl %esi, %esi
jmp 0x3692
movq %r15, %rdi
movl %ebp, %esi
callq 0x36de
addq $0x8, %r15
xorl %eax, %eax
testl %r14d, %r14d
setg %al
subl %eax, %r14d
testl %r14d, %r14d
movl $0x0, %esi
jle 0x3681
xorl %eax, %eax
cmpq $0x0, (%r15)
cmovel %eax, %r14d
movl %r14d, %esi
jmp 0x3692
jns 0x3692
xorl %esi, %esi
cmpq $0x0, (%r15,%rsi,8)
leaq 0x1(%rsi), %rsi
jne 0x3685
decl %esi
addl %ebp, %esi
movslq %ebp, %rax
shlq $0x3, %rax
subq %rax, %r15
movq 0x30(%rsp), %rdi
movq (%rdi), %rax
movq %r15, %rdx
callq *0x8(%rax)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq