// File: /workspace/github_cpp_makefile_star2_O2/ridiculousfish[P]docopt_fish/docopt_matching.cpp
// Function: docopt_fish::match_options(std::vector<docopt_fish::option_t, std::allocator<docopt_fish::option_t>> const&, docopt_fish::match_state_t*, docopt_fish::match_context_t const&)
static bool match_options(const option_list_t &options_in_doc, match_state_t *state,
                          const match_context_t &ctx) {
    bool successful_match = false;
    bool made_suggestion = false;

    // Collect potential suggestions in here. We squelch them if we find that a
    // later matched option
    // has the same corresponding long name; we need to remove those from the
    // suggestions
    option_list_t potential_suggestions;

    for (const option_t &opt_in_doc : options_in_doc) {
        // Find the matching option from the resolved option list (i.e. argv)
        size_t resolved_opt_idx = npos;
        for (size_t i = 0; i < ctx.aclass.resolved_options.size(); i++) {
            // Skip ones that have already been consumed
            if (! state->consumed_options->at(i)) {
                // See if the option from argv has the same key range as the option in
                // the document
                if (ctx.aclass.resolved_options.at(i).option.has_same_name(opt_in_doc)) {
                    resolved_opt_idx = i;
                    break;
                }
            }
        }

        if (resolved_opt_idx != npos) {
            // We found a matching option in argv. Set it in the argument_values for
            // this state and mark its index as used
            // We have two things to set:
            //  - The option name, like -foo
            //  - The option's argument value (if any)
            const resolved_option_t &resolved_opt = ctx.aclass.resolved_options.at(resolved_opt_idx);
            const rstring_t &name = opt_in_doc.best_name();

            // Update the option value, creating it if necessary
            state->argument_values.mut()[name].count += 1;

            // Update the option argument vlaue
            if (opt_in_doc.has_value() && resolved_opt.value_idx_in_argv != npos) {
                const rstring_t &variable_name = opt_in_doc.value;

                const rstring_t &value = resolved_opt.value_in_arg;
                state->argument_values.mut()[variable_name].values.push_back(value.std_string());
            }

            successful_match = true;
            state->consumed_options.mut()[resolved_opt_idx] = true;
        } else {
            // This was an option that was not specified in argv
            // It can be a suggestion
            if (ctx.flags & flag_generate_suggestions) {
                potential_suggestions.push_back(opt_in_doc);
            }
        }
    }

    // Now go through and handle potential suggestions
    if (ctx.flags & flag_generate_suggestions) {
        for (const option_t &suggestion : potential_suggestions) {
            size_t type_idx = option_t::NAME_TYPE_COUNT;
            while (type_idx--) {
                option_t::name_type_t type = static_cast<option_t::name_type_t>(type_idx);
                if (suggestion.has_type(type)) {
                    state->suggested_next_arguments.insert(suggestion.names[type]);
                }
            }
            made_suggestion = true;
        }
    }

    bool matched_something = successful_match || made_suggestion;
    if (matched_something) {
        ctx.try_mark_fully_consumed(state);
    }
    return matched_something;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r14
leaq 0x20(%rsp), %rax
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq (%rdi), %r12
movq 0x8(%rdi), %rax
movq %rax, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
leaq 0x10(%rsi), %r13
xorl %ebx, %ebx
movl $0xa8, %r15d
cmpq 0x10(%rsp), %r12
je 0x12f31
xorl %ebp, %ebp
movq 0x10(%r14), %rcx
movq 0x20(%rcx), %rax
subq 0x18(%rcx), %rax
cqto
idivq %r15
cmpq %rax, %rbp
jae 0x12e5c
movq (%r13), %rdi
movq %rbp, %rsi
callq 0x140b0
testb %al, %al
jne 0x12e57
movq 0x10(%r14), %rdi
addq $0x18, %rdi
movq %rbp, %rsi
callq 0x140d2
movq %rax, %rdi
movq %r12, %rsi
callq 0xdfba
testb %al, %al
jne 0x12e79
incq %rbp
jmp 0x12e12
testb $0x1, 0x2(%r14)
je 0x12f28
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x9370
jmp 0x12f28
movq 0x10(%r14), %rdi
addq $0x18, %rdi
movq %rbp, %rsi
callq 0x140d2
movq %rax, 0x18(%rsp)
movq %r12, %rdi
callq 0xdffe
movq %rax, %rbx
movq 0x8(%rsp), %rdi
callq 0x1338e
movq %rax, %rdi
movq %rbx, %rsi
callq 0x13870
incl 0x18(%rax)
cmpq $0x0, 0x50(%r12)
je 0x12f10
movq 0x18(%rsp), %rax
cmpq $-0x1, 0x88(%rax)
je 0x12f10
movq 0x8(%rsp), %rdi
callq 0x1338e
leaq 0x48(%r12), %rsi
movq %rax, %rdi
callq 0x13870
movq %rax, %rbx
movq 0x18(%rsp), %rsi
addq $0x90, %rsi
leaq 0x38(%rsp), %rdi
callq 0xac82
movq %rbx, %rdi
leaq 0x38(%rsp), %rbx
movq %rbx, %rsi
callq 0xc8d0
movq %rbx, %rdi
callq 0x7050
movq %r13, %rdi
callq 0x140f4
movq %rax, %rdi
movq %rbp, %rsi
callq 0x14140
orq %rdx, (%rax)
movb $0x1, %bl
subq $-0x80, %r12
jmp 0x12e05
movq %rbx, 0x10(%rsp)
testb $0x1, 0x2(%r14)
jne 0x12f76
xorl %eax, %eax
movq 0x10(%rsp), %rbx
orb %al, %bl
testb $0x1, %bl
je 0x12f58
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x138d6
leaq 0x20(%rsp), %rdi
callq 0xef34
andb $0x1, %bl
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %r15
movq 0x8(%rsp), %rax
leaq 0x28(%rax), %r13
xorl %eax, %eax
pushq $0x2
popq %rbx
cmpq %r15, %r12
je 0x12f3f
movq %rbx, %rbp
cmpq $-0x1, %rbp
je 0x12fc0
movq %r12, %rdi
movl %ebp, %esi
callq 0x1415e
testb %al, %al
je 0x12fbb
movl %ebp, %eax
imulq $0x18, %rax, %rsi
addq %r12, %rsi
movq %r13, %rdi
callq 0xc73c
decq %rbp
jmp 0x12f96
subq $-0x80, %r12
movb $0x1, %al
jmp 0x12f8e
jmp 0x12fe7
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x7050
jmp 0x12fea
jmp 0x12fe7
jmp 0x12fe7
jmp 0x12fe7
jmp 0x12fe7
jmp 0x12fe7
jmp 0x12fe7
jmp 0x12fe7
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xef34
movq %rbx, %rdi
callq 0x7390