// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movl %r9d, 0x2c(%rsp)
movq %r8, 0x38(%rsp)
movq %rcx, %r8
testq %rcx, %rcx
sete %al
testl %edx, %edx
sete %cl
orb %al, %cl
je 0x388f
xorl %r10d, %r10d
xorl %r9d, %r9d
addl %r10d, %r9d
movslq %r10d, %rax
shlq $0x3, %rax
subq %rax, %r8
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
movl %r9d, %esi
movq %r8, %rdx
callq *0x8(%rax)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edx, %r9d
movq %rsi, %r14
xorl %r11d, %r11d
xorl %r10d, %r10d
movl %edi, 0x10(%rsp)
movq (%r8), %rbp
testq %rbp, %rbp
je 0x3ceb
cmpb $0x2d, (%rbp)
jne 0x38be
movzbl 0x1(%rbp), %eax
cmpl $0x2d, %eax
je 0x38cf
testl %eax, %eax
jne 0x38d9
testb %dil, %dil
je 0x3ceb
incl %r10d
jmp 0x3c94
cmpb $0x0, 0x2(%rbp)
je 0x3cb5
leaq 0x1(%rbp), %rcx
leaq 0x2(%rbp), %rbx
cmpb $0x2d, %al
setne %sil
cmovneq %rcx, %rbx
movl %r10d, 0x14(%rsp)
movl %r10d, %eax
negl %eax
cltq
movq %rax, 0x30(%rsp)
leaq 0x1(%rbx), %r10
movl %r9d, 0x4(%rsp)
movl 0x2c(%rsp), %eax
movq %r9, 0x40(%rsp)
movq %r10, 0x8(%rsp)
movq %r8, 0x20(%rsp)
notb %al
andb %sil, %al
testb $0x1, %al
jne 0x3a8e
movq 0x10(%r14), %rdx
testq %rdx, %rdx
je 0x39ef
movl %esi, %r12d
xorl %r15d, %r15d
movq %rdx, %rax
xorl %ecx, %ecx
movb (%rax,%rcx), %sil
testb %sil, %sil
je 0x3955
leaq 0x1(%rcx), %rdi
cmpb (%rbx,%rcx), %sil
movq %rdi, %rcx
je 0x393d
jmp 0x396a
movzbl (%rbx,%rcx), %eax
testl %eax, %eax
je 0x3a51
cmpl $0x3d, %eax
je 0x3a51
leaq (%r15,%r15,4), %rax
incq %r15
movq 0x38(%r14,%rax,8), %rax
testq %rax, %rax
jne 0x393b
testq %rdx, %rdx
sete %al
cmpl $0x0, 0xb8(%rsp)
setle %cl
orb %al, %cl
jne 0x3a51
movl $0x1, %eax
xorl %ecx, %ecx
movl 0xb8(%rsp), %r10d
movb (%rdx), %dil
movq %rbx, %rsi
testb %dil, %dil
je 0x39cd
xorl %esi, %esi
cmpb (%rbx,%rsi), %dil
jne 0x39c5
movb 0x1(%rdx,%rsi), %dil
incq %rsi
testb %dil, %dil
jne 0x39b0
jmp 0x39ca
cmpq %r10, %rsi
jl 0x39d9
addq %rbx, %rsi
movzbl (%rsi), %edx
testl %edx, %edx
je 0x39f4
cmpl $0x3d, %edx
je 0x39f4
leaq (%rcx,%rcx,4), %rdx
incq %rcx
movq 0x38(%r14,%rdx,8), %rdx
incq %rax
testq %rdx, %rdx
jne 0x39a3
jmp 0x3a4c
xorl %r15d, %r15d
jmp 0x3a54
leal 0x1(%rcx), %edx
leaq (%rdx,%rdx,4), %rdx
movq 0x10(%r14,%rdx,8), %rdx
testq %rdx, %rdx
je 0x3a49
movb (%rdx), %dil
movq %rbx, %rsi
testb %dil, %dil
je 0x3a2f
xorl %esi, %esi
cmpb (%rbx,%rsi), %dil
jne 0x3a27
movb 0x1(%rdx,%rsi), %dil
incq %rsi
testb %dil, %dil
jne 0x3a12
jmp 0x3a2c
cmpq %r10, %rsi
jl 0x3a3b
addq %rbx, %rsi
movzbl (%rsi), %edx
testl %edx, %edx
je 0x3a4c
cmpl $0x3d, %edx
je 0x3a4c
leaq (%rax,%rax,4), %rdx
incq %rax
movq 0x38(%r14,%rdx,8), %rdx
jmp 0x3a00
movl %ecx, %r15d
movq 0x8(%rsp), %r10
movl %r12d, %esi
movslq %r15d, %rax
leaq (%rax,%rax,4), %rax
cmpq $0x0, 0x10(%r14,%rax,8)
movzbl %sil, %esi
cmovnel %r11d, %esi
movq %r10, %r13
movzbl -0x1(%r13), %eax
testl %eax, %eax
je 0x3a7f
cmpl $0x3d, %eax
je 0x3a8e
incq %r13
jmp 0x3a6c
cmpl $0x1, %r9d
jne 0x3a8a
xorl %r13d, %r13d
jmp 0x3a8e
movq 0x8(%r8), %r13
testb $0x1, %sil
je 0x3aef
movb 0x1(%rbp), %al
testb %al, %al
je 0x3c5f
movq 0x8(%r14), %rcx
xorl %r15d, %r15d
testq %rcx, %rcx
je 0x3aca
movb (%rcx), %dl
testb %dl, %dl
je 0x3ab8
incq %rcx
cmpb %al, %dl
jne 0x3aab
cmpb %al, %dl
je 0x3aca
leaq (%r15,%r15,4), %rcx
incq %r15
movq 0x30(%r14,%rcx,8), %rcx
jmp 0x3aa6
leaq 0x1(%rbp), %rax
movb 0x2(%rbp), %cl
addq $0x2, %rbp
testb %cl, %cl
movq %rbp, %r13
cmoveq %r11, %r13
cmpl $0x1, %r9d
je 0x3aec
testb %cl, %cl
jne 0x3aec
movq 0x8(%r8), %r13
movq %rax, %rbp
movslq %r15d, %rax
leaq (%rax,%rax,4), %rax
cmpq $0x0, 0x8(%r14,%rax,8)
jne 0x3c4e
movq 0x8(%r14), %rax
xorl %r15d, %r15d
testq %rax, %rax
je 0x3b35
movq %r14, %r12
cmpb $0x0, (%rax)
jne 0x3b20
movq 0x10(%r12), %rax
cmpb $0x0, (%rax)
je 0x3b49
movq 0x30(%r12), %rax
incl %r15d
addq $0x28, %r12
testq %rax, %rax
jne 0x3b11
xorl %eax, %eax
jmp 0x3b3a
movl $0x0, %eax
testb $0x1, %sil
jne 0x3918
jmp 0x3c5f
movl %esi, (%rsp)
movq %rbp, 0x18(%rsp)
leaq 0x48(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movq 0x18(%rsp), %rdx
movq %r13, %rcx
callq 0x3d3c
movzbl 0xb0(%rsp), %esi
movq %rbp, %rdi
callq *0x18(%r12)
cmpl $0x3, %eax
ja 0x3c0c
movl %eax, %eax
leaq 0x3525(%rip), %rcx      # 0x70b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq 0x20(%rsp), %rsi
movq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rbp
jmpq *%rax
movq $0x0, 0x68(%rsp)
jmp 0x3c11
movl $0x0, (%rsp)
cmpl $0x1, 0x40(%rsp)
je 0x3c11
testq %r13, %r13
je 0x3c11
cmpq 0x8(%rsi), %r13
jne 0x3c03
cmpl $0x0, 0x14(%rsp)
jle 0x3be9
movq (%rsi), %rax
xorl %ecx, %ecx
movq -0x8(%rsi,%rcx,8), %rdx
movq %rdx, (%rsi,%rcx,8)
movq %rax, -0x8(%rsi,%rcx,8)
decq %rcx
cmpq %rdi, %rcx
jg 0x3bd3
addq $0x8, %rsi
movq %rsi, 0x20(%rsp)
xorl %eax, %eax
movl 0x4(%rsp), %ecx
testl %ecx, %ecx
setg %al
subl %eax, %ecx
movl %ecx, 0x4(%rsp)
movl $0x0, (%rsp)
jmp 0x3c11
movq 0x18(%rsp), %rbp
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
leaq 0x48(%rsp), %rsi
callq *(%rax)
testb %al, %al
je 0x3cae
xorl %eax, %eax
movl (%rsp), %esi
testb $0x1, %sil
movq 0x20(%rsp), %r8
movq 0x40(%rsp), %r9
movl $0x0, %r11d
movq 0x8(%rsp), %r10
jne 0x3913
jmp 0x3c5f
movl %esi, (%rsp)
movq %rbp, 0x18(%rsp)
leaq (%r14,%rax,8), %r12
jmp 0x3b51
movl 0x14(%rsp), %r10d
testl %r10d, %r10d
jle 0x3c89
movq (%r8), %rax
xorl %ecx, %ecx
movq 0x30(%rsp), %rsi
movq -0x8(%r8,%rcx,8), %rdx
movq %rdx, (%r8,%rcx,8)
movq %rax, -0x8(%r8,%rcx,8)
decq %rcx
cmpq %rsi, %rcx
jg 0x3c73
movl 0x4(%rsp), %eax
movl %eax, %r9d
movl 0x10(%rsp), %edi
xorl %eax, %eax
testl %r9d, %r9d
setg %al
addq $0x8, %r8
subl %eax, %r9d
jne 0x389f
jmp 0x385f
xorl %eax, %eax
jmp 0x3880
testl %r10d, %r10d
jle 0x3cdc
movl %r10d, %eax
negl %eax
cltq
movq (%r8), %rcx
xorl %edx, %edx
movq -0x8(%r8,%rdx,8), %rsi
movq %rsi, (%r8,%rdx,8)
movq %rcx, -0x8(%r8,%rdx,8)
decq %rdx
cmpq %rax, %rdx
jg 0x3cc6
addq $0x8, %r8
xorl %eax, %eax
testl %r9d, %r9d
setg %al
subl %eax, %r9d
testl %r9d, %r9d
jle 0x3cff
xorl %eax, %eax
cmpq $0x0, (%r8)
cmovel %eax, %r9d
jmp 0x3862
jns 0x385f
xorl %r9d, %r9d
cmpq $0x0, (%r8,%r9,8)
leaq 0x1(%r9), %r9
jne 0x3d08
decl %r9d
jmp 0x3862
nop