// File: ridiculousfish[P]docopt_fish/docopt_fish_parse_tree.cpp
// Function: docopt_fish::parse_context_t::parse(docopt_fish::option_clause_t*)
bool parse(option_clause_t *result) {
        rstring_t word;
        if (!this->scan_word(&word)) {
            return false;
        }

        // TODO: handle -- ?
        // What should happen if options are specified after the -- in the usage spec?

        /* Hack to support specifying parameter names inline.

         Consider usage like this:
           "usage: prog [-m <msg>]"

        There's two ways we can interpret this:
         1. An optional -m flag, followed by a positional parameter
         2. An -m option whose value is <msg>

        The Python reference docopt resolves this ambiguity by looking at the Options: section. If
        it finds a declaration of -m with a variable, then <msg> is assumed to be the value
        (interpretation #2); otherwise it's a positional (interpretation #1).

        But requiring a required positional after a flag seems very unlikely, so in this version we
        always use interpretation #2. We do this by treating it as one token '-m <msg>'. Note this
        token contains a space.

        One exception is if a delimeter is found, e.g.:

        "usage: prog [-m=<foo> <msg>]"

        Now <foo> is the value of the option m, and <msg> is positional.

        The second exception is if the option is also found in the Options: section without a
        variable:

            usage: prog -m <msg>
            options: -m

        Then we ignore the option.

        Also, if you really want interpretation #1, you can use parens:

           "usage: prog [-m (<msg>)]"
        */
        rstring_t remaining = word;
        if (remaining.length() > 1 && remaining[0] == '-' && !remaining.is_double_dash()) {
            // It's an option
            option_t opt_from_usage_section;
            if (!option_t::parse_from_string(&remaining, &opt_from_usage_section, &this->errors)) {
                // must have an error in this case
                assert(!this->errors.empty());
                return false;
            }
            assert(!opt_from_usage_section.best_name().empty());

            // See if we have a corresponding option in the options section
            const option_t *opt_from_options_section = nullptr;
            for (const option_t &test_op : *this->shortcut_options) {
                if (opt_from_usage_section.has_same_name(test_op)) {
                    opt_from_options_section = &test_op;
                    break;
                }
            }

            // Looks like an option without a separator. See if the next token is a
            // variable
            rstring_t next = this->peek_word();
            if (next.length() > 2 && next.front() == '<' && next.back() == '>') {
                // It's a variable. See if we have a presence in options.
                bool options_section_implies_no_value =
                    (opt_from_options_section && opt_from_options_section->value.empty());
                if (!options_section_implies_no_value) {
                    rstring_t variable;
                    bool scanned = this->scan_word(&variable);
                    assert(scanned);  // Should always succeed, since we peeked at the word
                    word = word.merge(variable);
                    opt_from_usage_section.value = variable;
                }
            }

            // Use the option from the Options section in preference to the one from
            // the Usage
            // section, since the options one has more information like the
            // corresponding long name
            // and description
            result->word = word;
            result->option =
                opt_from_options_section ? *opt_from_options_section : opt_from_usage_section;
        }
        return true;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xbe70
movq -0x150(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x27a60
testb $0x1, %al
jne 0x29414
movb $0x0, -0x1(%rbp)
jmp 0x2975c
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x48(%rbp), %rdi
callq 0xbf20
cmpq $0x1, %rax
jbe 0x29758
leaq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x110a0
cmpl $0x2d, %eax
jne 0x29758
leaq -0x48(%rbp), %rdi
callq 0x297c0
testb $0x1, %al
jne 0x29758
leaq -0xc8(%rbp), %rdi
callq 0x1d030
movq -0x150(%rbp), %rdx
addq $0x20, %rdx
leaq -0x48(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x8950
testb $0x1, %al
jne 0x294d3
movq -0x150(%rbp), %rdi
addq $0x20, %rdi
callq 0xbfd0
xorb $-0x1, %al
testb $0x1, %al
jne 0x294a9
jmp 0x294ab
jmp 0x294ca
leaq 0x22b5c(%rip), %rdi     # 0x4c00e
leaq 0x22a6f(%rip), %rsi     # 0x4bf28
movl $0xfb, %edx
leaq 0x22b5f(%rip), %rcx     # 0x4c024
callq 0x81e0
movb $0x0, -0x1(%rbp)
jmp 0x2975c
leaq -0xc8(%rbp), %rdi
callq 0x1f390
movq %rax, %rdi
callq 0xbe30
xorb $-0x1, %al
testb $0x1, %al
jne 0x294ef
jmp 0x294f1
jmp 0x29510
leaq 0x22b68(%rip), %rdi     # 0x4c060
leaq 0x22a29(%rip), %rsi     # 0x4bf28
movl $0xfe, %edx
leaq 0x22b19(%rip), %rcx     # 0x4c024
callq 0x81e0
movq -0x150(%rbp), %rax
movq $0x0, -0xd0(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rdi
callq 0x14c00
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rdi
callq 0x14c30
movq %rax, -0xe8(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x14c60
testb $0x1, %al
jne 0x2956c
jmp 0x295b8
leaq -0xe0(%rbp), %rdi
callq 0xc8c0
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x1f300
testb $0x1, %al
jne 0x29598
jmp 0x295a8
movq -0xf0(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x295b8
jmp 0x295aa
leaq -0xe0(%rbp), %rdi
callq 0x14d30
jmp 0x29553
movq -0x150(%rbp), %rsi
leaq -0x108(%rbp), %rdi
callq 0x290d0
leaq -0x108(%rbp), %rdi
callq 0xbf20
cmpq $0x2, %rax
jbe 0x296fa
leaq -0x108(%rbp), %rdi
callq 0xfa90
cmpl $0x3c, %eax
jne 0x296fa
leaq -0x108(%rbp), %rdi
callq 0x29830
cmpl $0x3e, %eax
jne 0x296fa
xorl %eax, %eax
cmpq $0x0, -0xd0(%rbp)
movb %al, -0x151(%rbp)
je 0x29633
movq -0xd0(%rbp), %rdi
addq $0x48, %rdi
callq 0xbe30
movb %al, -0x151(%rbp)
movb -0x151(%rbp), %al
andb $0x1, %al
movb %al, -0x109(%rbp)
testb $0x1, -0x109(%rbp)
jne 0x296f8
leaq -0x128(%rbp), %rdi
callq 0xbe70
movq -0x150(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x27a60
andb $0x1, %al
movb %al, -0x129(%rbp)
testb $0x1, -0x129(%rbp)
je 0x29680
jmp 0x2969f
leaq 0x22899(%rip), %rdi     # 0x4bf20
leaq 0x2289a(%rip), %rsi     # 0x4bf28
movl $0x113, %edx            # imm = 0x113
leaq 0x2298a(%rip), %rcx     # 0x4c024
callq 0x81e0
leaq -0x148(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x128(%rbp), %rdx
callq 0xc010
movq -0x148(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x140(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x138(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x128(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x120(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x296fa
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x10(%rax)
cmpq $0x0, -0xd0(%rbp)
je 0x2972f
movq -0xd0(%rbp), %rax
movq %rax, -0x160(%rbp)
jmp 0x2973f
leaq -0xc8(%rbp), %rax
movq %rax, -0x160(%rbp)
jmp 0x2973f
movq -0x160(%rbp), %rsi
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
movl $0x7c, %edx
callq 0x8270
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopw (%rax,%rax)