// File: ridiculousfish[P]docopt_fish/docopt_matching.cpp
// Function: docopt_fish::match(std::vector<docopt_fish::usage_t, std::allocator<docopt_fish::usage_t>> const&, docopt_fish::match_state_t, docopt_fish::match_context_t const&, std::vector<docopt_fish::match_state_t, std::allocator<docopt_fish::match_state_t>>*)
static void match(const vector<usage_t> &usages, match_state_t state, const match_context_t &ctx,
                  match_state_list_t *resulting_states) {
    // Elide the copy in the last one
    size_t count = usages.size();
    if (count == 0) {
        return;
    }

    bool fully_consumed = false;
    for (size_t i = 0; i + 1 < count && !fully_consumed; i++) {
        match(usages.at(i), state.copy(), ctx, resulting_states);

        if (ctx.flags & flag_stop_after_consuming_everything) {
            for (const match_state_t &ms : *resulting_states) {
                if (ms.fully_consumed) {
                    fully_consumed = true;
                    break;
                }
            }
        }
    }
    if (!fully_consumed) {
        match(usages.at(count - 1), state.move(), ctx, resulting_states);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rsi, -0x130(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1f4a0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2feeb
jmp 0x300d8
movb $0x0, -0x29(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rcx
addq $0x1, %rcx
xorl %eax, %eax
cmpq -0x28(%rbp), %rcx
movb %al, -0x131(%rbp)
jae 0x2ff18
movb -0x29(%rbp), %al
xorb $-0x1, %al
movb %al, -0x131(%rbp)
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0x2ff27
jmp 0x3004a
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x32a70
movq -0x130(%rbp), %rsi
movq %rax, -0x148(%rbp)
leaq -0x98(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x32ab0
movq -0x148(%rbp), %rdi
movq -0x140(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x300f0
jmp 0x2ff72
leaq -0x98(%rbp), %rdi
callq 0x321f0
movq -0x18(%rbp), %rax
movl (%rax), %eax
andl $0x20000, %eax          # imm = 0x20000
cmpl $0x0, %eax
je 0x30037
movq -0x20(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x32320
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x32350
movq %rax, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x32380
testb $0x1, %al
jne 0x2ffdc
jmp 0x30035
leaq -0xb8(%rbp), %rdi
callq 0x323c0
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
testb $0x1, 0x58(%rax)
je 0x30025
movb $0x1, -0x29(%rbp)
jmp 0x30035
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x321f0
jmp 0x300e1
jmp 0x30027
leaq -0xb8(%rbp), %rdi
callq 0x32970
jmp 0x2ffc3
jmp 0x30037
jmp 0x30039
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2fef7
testb $0x1, -0x29(%rbp)
jne 0x300d8
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
decq %rsi
callq 0x32a70
movq -0x130(%rbp), %rdi
movq %rax, -0x158(%rbp)
callq 0x32ae0
movq %rax, %rsi
leaq -0x128(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x32af0
movq -0x158(%rbp), %rdi
movq -0x150(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x300f0
jmp 0x300aa
leaq -0x128(%rbp), %rdi
callq 0x321f0
jmp 0x300d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x321f0
jmp 0x300e1
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0xa0(%rbp), %rdi
callq 0x85d0
nopl (%rax)