// File: ridiculousfish[P]docopt_fish/docopt_fish.cpp
// Function: docopt_fish::argv_classifier_t::parse_separated_option(docopt_fish::option_t::name_type_t, std::vector<docopt_fish::error_t, std::allocator<docopt_fish::error_t>>*)
bool argv_classifier_t::parse_separated_option(option_t::name_type_t type, error_list_t *out_errors) {
    const string_t &arg = this->arg();
    assert(this->arg_has_prefix(type == option_t::double_long ? "--" : "-"));

    // Parse the argument into an 'option'. Note that this option does not appear
    // in the options list because its range reflects the string in the argument.
    // TODO: Need to distinguish between equivalent ways of specifying parameters
    // (--foo=bar and --foo bar)
    option_t arg_as_option = option_t::parse_from_argument(arg, type);
    const rstring_t arg_name = arg_as_option.names[type];
    assert(!arg_name.empty());

    // Get list of matching options.
    // Short options must have a value to match, else we handle them in parse_unseparated_short_options
    auto match_iter = std::find_if(this->options.cbegin(), this->options.cend(), [&](const option_t &opt) {
        bool does_match = opt.names[type] == arg_name &&
            (type != option_t::single_short || opt.has_value());
        return does_match;
    });
    
    bool errored = false;
    // Our option de-duplication ensures we should never have more than one match
    if (match_iter == this->options.cend()) {
        this->error(out_errors, error_unknown_option, "Unknown option");
        errored = true;
    } else {
        const option_t &match = *match_iter;
        // Ensure the option and argument agree on having a value
        rstring_t value;
        const size_t name_idx = this->idx;
        size_t arg_index = npos;
        if (match.has_value()) {
            if (arg_as_option.has_value()) {
                // The arg was specified as --foo=bar (long) or -DNDEBUG (short)
                // The range is the value portion; the index is the same as our
                // argument.
                value = arg_as_option.value;
                arg_index = this->idx;
            } else if (! (match.flags & value_is_optional)) {
                if (this->idx + 1 < this->argv.size()) {
                    this->idx += 1;
                    arg_index = this->idx;
                    value = rstring_t(this->argv.at(arg_index));
                } else {
                    // We are at the last argument, and we expect a value. Return the
                    // value as a suggestion.
                    this->suggest(match.value);
                    this->error(out_errors, error_option_has_missing_argument,
                                      "Option expects an argument");
                    errored = true;
                }
            } else {
                // There was no value match, but it was optional
                assert(match.flags & value_is_optional);
            }
        } else if (arg_as_option.has_value()) {
            // A value was specified as --foo=bar, but none was expected
            this->error(out_errors, error_option_unexpected_argument,
                              "Option does not expect an argument");
            errored = true;
        }
        
        // Apply our SEPARATOR-NOTE
        // Be strict about = separators
        // Note that we use the single_long_strict_eqsep flag in arg_as_option
        // to indicate that we got an = separator
        if (! errored && type == option_t::single_long) {
            bool requires_eq = match.flags & single_long_strict_eqsep;
            bool has_eq = arg_as_option.flags & single_long_strict_eqsep;
            if (requires_eq != has_eq) {
                const char *msg = has_eq ?
                                   "Option requires a space to separate its argument" :
                                   "Option requires '=' to separate its argument";
                this->error(out_errors, error_wrong_separator, msg);
                errored = true;
            }
        }

        if (!errored) {
            this->classification.resolved_options.emplace_back(match, name_idx, arg_index, value);
            this->idx += 1;
        }
    }
    return ! errored;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0xc6f0
movq -0x150(%rbp), %rdi
movq %rax, -0x20(%rbp)
movl -0xc(%rbp), %ecx
leaq 0x45309(%rip), %rsi     # 0x4e734
leaq 0x45301(%rip), %rax     # 0x4e733
cmpl $0x2, %ecx
cmoveq %rax, %rsi
callq 0xc720
testb $0x1, %al
jne 0x9444
jmp 0x9446
jmp 0x9465
leaq 0x41dca(%rip), %rdi     # 0x4b217
leaq 0x41c34(%rip), %rsi     # 0x4b088
movl $0x1fd, %edx            # imm = 0x1FD
leaq 0x41df8(%rip), %rcx     # 0x4b258
callq 0x81e0
movq -0x20(%rbp), %rsi
movl -0xc(%rbp), %edx
leaq -0xa0(%rbp), %rdi
callq 0x9150
leaq -0xa0(%rbp), %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xc7b0
movq (%rax), %rcx
movq %rcx, -0xb8(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0xb0(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0xa8(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0xbe30
xorb $-0x1, %al
testb $0x1, %al
jne 0x94bd
jmp 0x94bf
jmp 0x94de
leaq 0x41df5(%rip), %rdi     # 0x4b2bb
leaq 0x41bbb(%rip), %rsi     # 0x4b088
movl $0x205, %edx            # imm = 0x205
leaq 0x41d7f(%rip), %rcx     # 0x4b258
callq 0x81e0
movq -0x150(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xc7e0
movq %rax, %rcx
movq -0x150(%rbp), %rax
movq %rcx, -0xc8(%rbp)
movq 0x8(%rax), %rdi
callq 0xc810
movq %rax, -0xd0(%rbp)
leaq -0xc(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0xb8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xc8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movq -0xe0(%rbp), %rdx
movq -0xd8(%rbp), %rcx
callq 0x98d0
movq %rax, %rcx
movq -0x150(%rbp), %rax
movq %rcx, -0xc0(%rbp)
movb $0x0, -0xe1(%rbp)
movq 0x8(%rax), %rdi
callq 0xc810
movq %rax, -0xf0(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0xc840
testb $0x1, %al
jne 0x958a
jmp 0x95b7
movq -0x150(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x67, %edx
leaq 0x41d2c(%rip), %rcx     # 0x4b2cd
xorl %eax, %eax
movl %eax, %r8d
callq 0xc880
movb $0x1, -0xe1(%rbp)
jmp 0x98b9
leaq -0xc0(%rbp), %rdi
callq 0xc8c0
movq %rax, -0xf8(%rbp)
leaq -0x110(%rbp), %rdi
callq 0xbe70
movq -0x150(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x118(%rbp)
movq $-0x1, -0x120(%rbp)
movq -0xf8(%rbp), %rdi
callq 0xc8e0
testb $0x1, %al
jne 0x9608
jmp 0x9782
leaq -0xa0(%rbp), %rdi
callq 0xc8e0
testb $0x1, %al
jne 0x961a
jmp 0x9652
movq -0x150(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, -0x110(%rbp)
movq -0x50(%rbp), %rcx
movq %rcx, -0x108(%rbp)
movq -0x48(%rbp), %rcx
movq %rcx, -0x100(%rbp)
movq 0x20(%rax), %rax
movq %rax, -0x120(%rbp)
jmp 0x9780
movq -0xf8(%rbp), %rax
movl 0x78(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x9749
movq -0x150(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, -0x158(%rbp)
movq (%rax), %rdi
callq 0xc910
movq %rax, %rcx
movq -0x158(%rbp), %rax
cmpq %rcx, %rax
jae 0x9708
movq -0x150(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
movq 0x20(%rax), %rcx
movq %rcx, -0x120(%rbp)
movq (%rax), %rdi
movq -0x120(%rbp), %rsi
callq 0xc930
movq %rax, %rsi
leaq -0x138(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq $-0x1, %rcx
callq 0xc430
movq -0x138(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x128(%rbp), %rax
movq %rax, -0x100(%rbp)
jmp 0x9747
movq -0x150(%rbp), %rdi
movq -0xf8(%rbp), %rsi
addq $0x48, %rsi
callq 0xc970
movq -0x150(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x64, %edx
leaq 0x41ba6(%rip), %rcx     # 0x4b2dc
xorl %eax, %eax
movl %eax, %r8d
callq 0xc880
movb $0x1, -0xe1(%rbp)
jmp 0x977e
movq -0xf8(%rbp), %rax
movl 0x78(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x975d
jmp 0x977c
leaq 0x41b93(%rip), %rdi     # 0x4b2f7
leaq 0x4191d(%rip), %rsi     # 0x4b088
movl $0x230, %edx            # imm = 0x230
leaq 0x41ae1(%rip), %rcx     # 0x4b258
callq 0x81e0
jmp 0x977e
jmp 0x9780
jmp 0x97be
leaq -0xa0(%rbp), %rdi
callq 0xc8e0
testb $0x1, %al
jne 0x9794
jmp 0x97bc
movq -0x150(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x65, %edx
leaq 0x41b6c(%rip), %rcx     # 0x4b317
xorl %eax, %eax
movl %eax, %r8d
callq 0xc880
movb $0x1, -0xe1(%rbp)
jmp 0x97be
testb $0x1, -0xe1(%rbp)
jne 0x986b
cmpl $0x1, -0xc(%rbp)
jne 0x986b
movq -0xf8(%rbp), %rax
movl 0x78(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x139(%rbp)
movl -0x28(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x13a(%rbp)
movb -0x139(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb -0x13a(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x9869
movq -0x150(%rbp), %rdi
movb -0x13a(%rbp), %dl
leaq 0x41b38(%rip), %rax     # 0x4b36b
leaq 0x41b00(%rip), %rcx     # 0x4b33a
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, -0x148(%rbp)
movq -0x18(%rbp), %rsi
movq -0x148(%rbp), %rcx
movl $0x68, %edx
xorl %eax, %eax
movl %eax, %r8d
callq 0xc880
movb $0x1, -0xe1(%rbp)
jmp 0x986b
testb $0x1, -0xe1(%rbp)
jne 0x98b7
movq -0x150(%rbp), %rdi
addq $0x28, %rdi
addq $0x18, %rdi
movq -0xf8(%rbp), %rsi
leaq -0x118(%rbp), %rdx
leaq -0x120(%rbp), %rcx
leaq -0x110(%rbp), %r8
callq 0xc9f0
movq -0x150(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
jmp 0x98b9
movb -0xe1(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopl (%rax)