// File: /workspace/github_cpp_makefile_star2_O3/ridiculousfish[P]docopt_fish/docopt_matching.cpp
// Function: docopt_fish::match_usages(std::vector<docopt_fish::usage_t, std::allocator<docopt_fish::usage_t>> const&, unsigned int, std::vector<docopt_fish::option_t, std::allocator<docopt_fish::option_t>> const&, docopt_fish::arg_classification_t const&, std::vector<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>, std::allocator<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>>> const&)
match_results_t match_usages(const std::vector<usage_t> &usages,
                             parse_flags_t flags,
                             const option_list_t &shortcut_options,
                             const arg_classification_t &aclass,
                             const string_list_t &argv) {
    
    match_context_t ctx(flags, shortcut_options, aclass, argv);
    size_t opt_count = ctx.aclass.resolved_options.size();
    match_state_list_t states;
    match(usages, match_state_t(opt_count), ctx, &states);
    
    // Illustration of some logging to help debug matching
    const bool log_stuff = false;
    if (log_stuff) {
        errstream() << "Matched " << states.size() << " way(s)\n";
        for (size_t i = 0; i < states.size(); i++) {
            const match_state_t &state = states.at(i);
            bool is_incomplete = !ctx.unused_arguments(&state).empty();
            errstream() << "Result " << i << (is_incomplete ? " (INCOMPLETE)" : "") << ":\n";
            for (const auto &kv : *state.argument_values) {
                const rstring_t &name = kv.first;
                const argument_t &arg = kv.second;
                errstream() << "\t" << name.std_string() << ": ";
                for (size_t j = 0; j < arg.values.size(); j++) {
                    if (j > 0) {
                        errstream() << ", ";
                    }
                    errstream() << arg.values.at(j);
                }
                errstream() << '\n';
            }
        }
    }
    
    match_results_t r;
    if (states.empty()) {
        // We had no states
        // Every arg is unused
        for (size_t i = 0; i < argv.size(); i++) {
            r.unused_args.push_back(i);
        }
    } else {
        // We got at least one state
        // Find the ones with the fewest unused arguments
        size_t fewest_unused_args = SIZE_MAX;
        for (match_state_t &st: states) {
            index_list_t unused_args = ctx.unused_arguments(&st);
            if (unused_args.size() < fewest_unused_args) {
                // Fewer unused args
                // Replace the suggestions
                fewest_unused_args = unused_args.size();
                r.option_map = std::move(st.argument_values.mut());
                r.unused_args = std::move(unused_args);
                r.suggestions = std::move(st.suggested_next_arguments);
            } else if (unused_args.size() == fewest_unused_args) {
                // Same number of unused args
                // Incorporate these suggestions too
                r.suggestions.insert(st.suggested_next_arguments.cbegin(),
                                     st.suggested_next_arguments.cend());
            }
        }
    }
    
    return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, %r14
movq %rdi, %rbx
movl %edx, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x40(%rsp)
movq %r9, 0x28(%rsp)
movq %r9, 0x48(%rsp)
movq 0x20(%r8), %rax
subq 0x18(%r8), %rax
sarq $0x3, %rax
movabsq $-0x30c30c30c30c30c3, %rsi # imm = 0xCF3CF3CF3CF3CF3D
imulq %rax, %rsi
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x14648
movq (%r14), %r13
movq %r14, (%rsp)
movq 0x8(%r14), %r14
subq %r13, %r14
je 0x12c92
sarq $0x4, %r14
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %r14
movq %r14, %rdx
cmpq $0x2, %r14
jae 0x12e75
decq %r14
cmpq %r14, %rdx
jbe 0x12f75
leaq (%r14,%r14,2), %rax
shlq $0x4, %rax
addq %rax, %r13
leaq 0x118(%rsp), %r14
leaq 0xb8(%rsp), %rsi
movq %r14, %rdi
callq 0x14c48
leaq 0x30(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r13, %rdi
movq %r14, %rsi
callq 0x12fec
leaq 0x140(%rsp), %r15
movq %r15, %rdi
callq 0xb254
movq -0x10(%r15), %rdi
testq %rdi, %rdi
je 0x12c80
callq 0x1563c
movq 0x120(%rsp), %rdi
testq %rdi, %rdi
je 0x12c92
callq 0x1563c
leaq 0xe0(%rsp), %r15
movq %r15, %rdi
callq 0xb254
movq -0x10(%r15), %rdi
testq %rdi, %rdi
je 0x12cb0
callq 0x1563c
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x12cc2
callq 0x1563c
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rbx)
leaq 0x20(%rbx), %rcx
movl %eax, 0x20(%rbx)
movq %rax, 0x28(%rbx)
movq %rcx, 0x30(%rbx)
movq %rcx, 0x38(%rbx)
movq %rax, 0x40(%rbx)
leaq 0x50(%rbx), %rcx
movl %eax, 0x50(%rbx)
movq %rax, 0x58(%rbx)
movq %rcx, 0x60(%rbx)
movq %rcx, 0x68(%rbx)
movq %rax, 0x70(%rbx)
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
cmpq %r12, %r15
je 0x12df0
leaq 0x48(%rbx), %rax
movq %rax, (%rsp)
leaq 0x18(%rbx), %rax
movq %rax, 0x8(%rsp)
addq $0x28, %r15
movq $-0x1, %r14
leaq -0x28(%r15), %r13
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq %r13, %rdx
callq 0x14786
movq 0x58(%rsp), %rbp
subq 0x50(%rsp), %rbp
sarq $0x3, %rbp
cmpq %r14, %rbp
jae 0x12db0
movq %r13, %rdi
callq 0x14ae8
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x14b5c
movq (%rbx), %rdi
movq 0x10(%rbx), %rsi
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rbx)
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
testq %rdi, %rdi
je 0x12d9f
subq %rdi, %rsi
callq 0x6200
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x14bba
movq %rbp, %r14
jmp 0x12dc3
jne 0x12dc3
movq 0x18(%r15), %rsi
leaq 0x8(%r15), %rdx
movq (%rsp), %rdi
callq 0x16256
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x12dda
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x6200
leaq 0x60(%r15), %rax
addq $0x38, %r15
cmpq %r12, %r15
movq %rax, %r15
jne 0x12d2b
jmp 0x12e56
movq $0x0, 0x50(%rsp)
movq 0x28(%rsp), %r14
movq (%r14), %rax
movq 0x8(%r14), %rcx
cmpq %rax, %rcx
je 0x12e56
xorl %edx, %edx
leaq 0x50(%rsp), %r15
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x12e28
movq %rdx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x12e3a
movq %rbx, %rdi
movq %r15, %rdx
callq 0x160f0
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq 0x50(%rsp), %rdx
incq %rdx
movq %rdx, 0x50(%rsp)
movq %rcx, %rsi
subq %rax, %rsi
sarq $0x5, %rsi
cmpq %rsi, %rdx
jb 0x12e11
leaq 0x10(%rsp), %rdi
callq 0x14c18
movq %rbx, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %r12d
xorl %r13d, %r13d
leaq 0x50(%rsp), %r15
movq %r14, 0x8(%rsp)
movq (%rsp), %rax
movq (%rax), %rbp
movq 0x8(%rax), %rdx
subq %rbp, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rdx
cmpq %r13, %rdx
jbe 0x12f78
movq %r15, %r14
movq %r14, %rdi
leaq 0xb8(%rsp), %rsi
callq 0x15a4c
leaq (,%r13,2), %rax
addq %r13, %rax
shlq $0x4, %rax
addq %rax, %rbp
movq %rbp, %rdi
movq %r15, %rsi
leaq 0x30(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x12fec
leaq 0x78(%rsp), %rdi
callq 0xb254
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
movq %r12, %r13
je 0x12f07
callq 0x1563c
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %r14
je 0x12f1b
callq 0x1563c
testb $0x2, 0x32(%rsp)
jne 0x12f31
leaq 0x1(%r13), %r12
cmpq %r14, %r12
jne 0x12e88
jmp 0x12f50
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
cmpq %rcx, %rax
je 0x12f22
cmpb $0x0, 0x58(%rax)
jne 0x12c92
addq $0x60, %rax
jmp 0x12f3b
movq (%rsp), %rax
movq (%rax), %r13
movq 0x8(%rax), %rdx
subq %r13, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rdx
jmp 0x12c1e
movq %r14, %r13
leaq 0xde4f(%rip), %rdi      # 0x20dce
movq %r13, %rsi
xorl %eax, %eax
callq 0x6300
jmp 0x12f90
movq %rax, %r15
jmp 0x12fda
movq %rax, %r15
movq %r14, %rdi
callq 0x1475a
jmp 0x12fa2
jmp 0x12f9f
movq %rax, %r15
leaq 0xb8(%rsp), %rdi
callq 0x1475a
jmp 0x12fda
jmp 0x12fcf
movq %rax, %r15
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x12fd2
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x6200
jmp 0x12fd2
movq %rax, %r15
movq %rbx, %rdi
callq 0xb140
leaq 0x10(%rsp), %rdi
callq 0x14c18
movq %r15, %rdi
callq 0x6360