// File: /workspace/github_cpp_makefile_star2_O1/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 %r9, %r13
movq %rsi, %rbx
movq %rdi, %r14
movl %edx, 0x38(%rsp)
movq %rcx, 0x40(%rsp)
movq %r8, 0x48(%rsp)
movq %r9, 0x50(%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, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x15772
movq 0x8(%rbx), %rbp
movq (%rbx), %rax
subq %rax, %rbp
movq %r14, 0x10(%rsp)
je 0x13e79
sarq $0x4, %rbp
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rbp
cmpq $0x2, %rbp
jb 0x13de2
movq %rbx, 0x8(%rsp)
movq %r13, 0x18(%rsp)
movl $0x1, %eax
xorl %r13d, %r13d
leaq 0x58(%rsp), %r14
xorl %r12d, %r12d
movq %rbp, %r15
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq (%rax), %rbp
movq 0x8(%rax), %rdx
subq %rbp, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rdx
cmpq %r12, %rdx
jbe 0x14035
movq %r14, %rdi
leaq 0xb8(%rsp), %rsi
callq 0x16bc0
leaq (%r12,%r12,2), %rax
shlq $0x4, %rax
addq %rax, %rbp
movq %rbp, %rdi
movq %r14, %r12
movq %r14, %rsi
leaq 0x38(%rsp), %rdx
leaq 0x20(%rsp), %rcx
callq 0x140b8
leaq 0x80(%rsp), %rdi
callq 0xc244
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
movq %r15, %rbp
je 0x13d62
callq 0x167a2
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
movl $0x1, %r15d
je 0x13d77
callq 0x167a2
testb $0x2, 0x3a(%rsp)
jne 0x13d83
movq %r12, %r14
jmp 0x13db3
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
cmpq %rax, %rcx
movq %r12, %r14
je 0x13db3
addq $0x60, %rcx
movzbl %r13b, %r13d
cmpb $0x0, -0x8(%rcx)
cmovnel %r15d, %r13d
jne 0x13db3
leaq 0x60(%rcx), %rdx
cmpq %rax, %rcx
movq %rdx, %rcx
jne 0x13d99
leaq 0x1(%rbx), %rax
cmpq %rbp, %rax
jae 0x13dc9
movq %rbx, %r12
testb $0x1, %r13b
je 0x13ce0
testb $0x1, %r13b
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r13
movq 0x8(%rsp), %rbx
jne 0x13e79
decq %rbp
movq (%rbx), %r12
movq 0x8(%rbx), %rdx
subq %r12, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rdx
cmpq %rbp, %rdx
jbe 0x14032
leaq (,%rbp,2), %rax
addq %rbp, %rax
shlq $0x4, %rax
addq %rax, %r12
leaq 0x118(%rsp), %r15
leaq 0xb8(%rsp), %rsi
movq %r15, %rdi
callq 0x15dda
leaq 0x38(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movq %r12, %rdi
movq %r15, %rsi
callq 0x140b8
leaq 0x140(%rsp), %r15
movq %r15, %rdi
callq 0xc244
movq -0x10(%r15), %rdi
testq %rdi, %rdi
je 0x13e67
callq 0x167a2
movq 0x120(%rsp), %rdi
testq %rdi, %rdi
je 0x13e79
callq 0x167a2
leaq 0xe0(%rsp), %r15
movq %r15, %rdi
callq 0xc244
movq -0x10(%r15), %rdi
testq %rdi, %rdi
je 0x13e97
callq 0x167a2
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x13ea9
callq 0x167a2
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
xorl %eax, %eax
movq %rax, 0x10(%r14)
leaq 0x20(%r14), %rcx
movl %eax, 0x20(%r14)
movq %rax, 0x28(%r14)
movq %rcx, 0x30(%r14)
movq %rcx, 0x38(%r14)
movq %rax, 0x40(%r14)
leaq 0x50(%r14), %rcx
movl %eax, 0x50(%r14)
movq %rax, 0x58(%r14)
movq %rcx, 0x60(%r14)
movq %rcx, 0x68(%r14)
movq %rax, 0x70(%r14)
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rbx
cmpq %rbx, %r15
je 0x13fb7
leaq 0x48(%r14), %rax
movq %rax, 0x8(%rsp)
leaq 0x18(%r14), %rax
movq %rax, 0x18(%rsp)
addq $0x28, %r15
movq $-0x1, %r14
leaq 0x58(%rsp), %r13
leaq -0x28(%r15), %r12
movq %r13, %rdi
leaq 0x38(%rsp), %rsi
movq %r12, %rdx
callq 0x158ce
movq 0x60(%rsp), %rbp
subq 0x58(%rsp), %rbp
sarq $0x3, %rbp
cmpq %r14, %rbp
jae 0x13f76
movq %r12, %rdi
callq 0x15c6e
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x15ce2
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xc11e
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x15d46
movq %rbp, %r14
jmp 0x13f8a
jne 0x13f8a
movq 0x18(%r15), %rsi
leaq 0x8(%r15), %rdx
movq 0x8(%rsp), %rdi
callq 0x173de
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x13fa1
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x7200
leaq 0x60(%r15), %rax
addq $0x38, %r15
cmpq %rbx, %r15
movq %rax, %r15
jne 0x13f1b
jmp 0x14011
movq $0x0, 0x58(%rsp)
movq 0x8(%r13), %rax
cmpq (%r13), %rax
je 0x14011
xorl %eax, %eax
leaq 0x58(%rsp), %r15
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x13fe8
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%r14)
jmp 0x13ff3
movq %r14, %rdi
movq %r15, %rdx
callq 0x17278
movq 0x58(%rsp), %rax
incq %rax
movq %rax, 0x58(%rsp)
movq 0x8(%r13), %rcx
subq (%r13), %rcx
sarq $0x5, %rcx
cmpq %rcx, %rax
jb 0x13fd1
leaq 0x20(%rsp), %rdi
callq 0x15daa
movq 0x10(%rsp), %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %r12
leaq 0xede3(%rip), %rdi      # 0x22e1f
movq %r12, %rsi
xorl %eax, %eax
callq 0x7300
movq %rax, %r14
leaq 0x118(%rsp), %rdi
jmp 0x14064
movq %rax, %r14
jmp 0x140a6
jmp 0x14099
jmp 0x1406b
movq %rax, %r14
leaq 0x58(%rsp), %rdi
callq 0x158a2
jmp 0x1406e
movq %rax, %r14
leaq 0xb8(%rsp), %rdi
callq 0x158a2
jmp 0x140a6
movq %rax, %r14
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x1409c
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x7200
jmp 0x1409c
movq %rax, %r14
movq 0x10(%rsp), %rdi
callq 0xc0f0
leaq 0x20(%rsp), %rdi
callq 0x15daa
movq %r14, %rdi
callq 0x7360