// File: ridiculousfish[P]docopt_fish/docopt_fish.cpp
// Function: docopt_fish::option_t::parse_from_string(docopt_fish::rstring_t*, docopt_fish::option_t*, std::vector<docopt_fish::error_t, std::allocator<docopt_fish::error_t>>*)
bool option_t::parse_from_string(rstring_t *remaining, option_t *result, error_list_t *out_errors) {
    assert(!remaining->empty());
    error_list_t errors;
    
    // An option is one or more dashes, the option name, maybe space and/or equals
    rstring_t leading_dashes, name, space_separator, equals;
    std::tie(leading_dashes, name, space_separator, equals, std::ignore) =
        remaining->scan_multiple<it_equals<'-'>, char_is_valid_in_option_name, char_is_space,
                                 it_equals<'='>, char_is_space>();

    // Validate our fields
    const size_t dash_count = leading_dashes.length();
    assert(dash_count > 0);
    if (dash_count > 2) {
        append_token_error(&errors, leading_dashes, error_excessive_dashes, "Too many dashes");
    }
    
    if (name.empty()) {
        append_token_error(&errors, name, error_invalid_option_name, "Missing option name");
    }
    
    if (equals.length() > 1) {
        append_token_error(&errors, equals, error_excessive_equal_signs, "Too many equal signs");
    }
    
    // Maybe parse a variable name
    rstring_t var_name;
    if (remaining->has_prefix("<")) {
        var_name = parse_variable_name(remaining, out_errors);
    }
    
    // Report an error for cases like '--foo='
    if (var_name.empty() && !equals.empty()) {
        append_token_error(&errors, equals, error_invalid_variable_name,
                           "Missing variable for this assignment");
    }
    
    // Determine the type
    name_type_t type;
    if (dash_count > 1) {
        type = double_long;
    } else if (name.length() > 1) {
        type = single_long;
    } else {
        type = single_short;
    }

    // Generate an error on long options with no separators (--foo<bar>). Only
    // short options support these.
    if (type != single_short && ! var_name.empty() &&
        space_separator.empty() && equals.empty()) {
        append_token_error(&errors, name, error_bad_option_separator,
                           "Long options must use a space or equals separator");
    }
    
    bool success = errors.empty();
    if (success) {
        // Build flags
        option_flags_t flags = 0;
        if (type == single_long && ! equals.empty()) {
            // see SEPARATOR-NOTE
            flags |= single_long_strict_eqsep;
        }
        
        *result = option_t(type, leading_dashes.merge(name), var_name, flags);
    }
    if (out_errors) {
        std::move(errors.begin(), errors.end(), std::back_inserter(*out_errors));
    }
    return success;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2a0, %rsp            # imm = 0x2A0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0xbe30
xorb $-0x1, %al
testb $0x1, %al
jne 0x8978
jmp 0x897a
jmp 0x8999
leaq 0x426f3(%rip), %rdi     # 0x4b074
leaq 0x42700(%rip), %rsi     # 0x4b088
movl $0x7b, %edx
leaq 0x42704(%rip), %rcx     # 0x4b098
callq 0x81e0
leaq -0x30(%rbp), %rdi
callq 0xbe50
leaq -0x48(%rbp), %rdi
callq 0xbe70
jmp 0x89ad
leaq -0x70(%rbp), %rdi
callq 0xbe70
jmp 0x89b8
leaq -0x88(%rbp), %rdi
callq 0xbe70
jmp 0x89c6
leaq -0xa0(%rbp), %rdi
callq 0xbe70
jmp 0x89d4
movq -0x8(%rbp), %rsi
leaq -0x118(%rbp), %rdi
callq 0x8e50
jmp 0x89e6
leaq 0x434c6(%rip), %r9      # 0x4beb3
leaq -0x140(%rbp), %rdi
movq %rdi, -0x248(%rbp)
leaq -0x48(%rbp), %rsi
leaq -0x70(%rbp), %rdx
leaq -0x88(%rbp), %rcx
leaq -0xa0(%rbp), %r8
callq 0xbea0
movq -0x248(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0xbef0
jmp 0x8a2b
leaq -0x48(%rbp), %rdi
callq 0xbf20
movq %rax, -0x250(%rbp)
jmp 0x8a3d
movq -0x250(%rbp), %rax
movq %rax, -0x148(%rbp)
cmpq $0x0, -0x148(%rbp)
jbe 0x8a57
jmp 0x8a90
leaq 0x42698(%rip), %rdi     # 0x4b0f6
leaq 0x42623(%rip), %rsi     # 0x4b088
movl $0x86, %edx
leaq 0x42627(%rip), %rcx     # 0x4b098
callq 0x81e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xc3d0
jmp 0x8e40
cmpq $0x2, -0x148(%rbp)
jbe 0x8ab7
leaq 0x42664(%rip), %rcx     # 0x4b105
leaq -0x30(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movl $0x1, %edx
callq 0x8e80
jmp 0x8ab5
jmp 0x8ab7
leaq -0x70(%rbp), %rdi
callq 0xbe30
movb %al, -0x251(%rbp)
jmp 0x8ac8
movb -0x251(%rbp), %al
testb $0x1, %al
jne 0x8ad4
jmp 0x8af1
leaq 0x4263a(%rip), %rcx     # 0x4b115
leaq -0x30(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x5, %edx
callq 0x8e80
jmp 0x8aef
jmp 0x8af1
leaq -0xa0(%rbp), %rdi
callq 0xbf20
movq %rax, -0x260(%rbp)
jmp 0x8b06
movq -0x260(%rbp), %rax
cmpq $0x1, %rax
jbe 0x8b33
leaq 0x4260f(%rip), %rcx     # 0x4b129
leaq -0x30(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
movl $0x3, %edx
callq 0x8e80
jmp 0x8b31
jmp 0x8b33
leaq -0x160(%rbp), %rdi
callq 0xbe70
jmp 0x8b41
movq -0x8(%rbp), %rdi
leaq 0x42a46(%rip), %rsi     # 0x4b592
callq 0xbf40
movb %al, -0x261(%rbp)
jmp 0x8b59
movb -0x261(%rbp), %al
testb $0x1, %al
jne 0x8b65
jmp 0x8ba5
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x178(%rbp), %rdi
callq 0x8ed0
jmp 0x8b7b
movq -0x178(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x168(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0x160(%rbp), %rdi
callq 0xbe30
movb %al, -0x262(%rbp)
jmp 0x8bb9
movb -0x262(%rbp), %al
testb $0x1, %al
jne 0x8bc5
jmp 0x8c05
leaq -0xa0(%rbp), %rdi
callq 0xbe30
movb %al, -0x263(%rbp)
jmp 0x8bd9
movb -0x263(%rbp), %al
testb $0x1, %al
jne 0x8c05
jmp 0x8be5
leaq 0x42552(%rip), %rcx     # 0x4b13e
leaq -0x30(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
movl $0x6, %edx
callq 0x8e80
jmp 0x8c03
jmp 0x8c05
cmpq $0x1, -0x148(%rbp)
jbe 0x8c1b
movl $0x2, -0x17c(%rbp)
jmp 0x8c52
leaq -0x70(%rbp), %rdi
callq 0xbf20
movq %rax, -0x270(%rbp)
jmp 0x8c2d
movq -0x270(%rbp), %rax
cmpq $0x1, %rax
jbe 0x8c46
movl $0x1, -0x17c(%rbp)
jmp 0x8c50
movl $0x0, -0x17c(%rbp)
jmp 0x8c52
cmpl $0x0, -0x17c(%rbp)
je 0x8cd8
leaq -0x160(%rbp), %rdi
callq 0xbe30
movb %al, -0x271(%rbp)
jmp 0x8c6f
movb -0x271(%rbp), %al
testb $0x1, %al
jne 0x8cd8
jmp 0x8c7b
leaq -0x88(%rbp), %rdi
callq 0xbe30
movb %al, -0x272(%rbp)
jmp 0x8c8f
movb -0x272(%rbp), %al
testb $0x1, %al
jne 0x8c9b
jmp 0x8cd8
leaq -0xa0(%rbp), %rdi
callq 0xbe30
movb %al, -0x273(%rbp)
jmp 0x8caf
movb -0x273(%rbp), %al
testb $0x1, %al
jne 0x8cbb
jmp 0x8cd8
leaq 0x424a1(%rip), %rcx     # 0x4b163
leaq -0x30(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x4, %edx
callq 0x8e80
jmp 0x8cd6
jmp 0x8cd8
leaq -0x30(%rbp), %rdi
callq 0xbfd0
andb $0x1, %al
movb %al, -0x17d(%rbp)
testb $0x1, -0x17d(%rbp)
je 0x8d98
movl $0x0, -0x184(%rbp)
cmpl $0x1, -0x17c(%rbp)
jne 0x8d38
leaq -0xa0(%rbp), %rdi
callq 0xbe30
movb %al, -0x274(%rbp)
jmp 0x8d1d
movb -0x274(%rbp), %al
testb $0x1, %al
jne 0x8d38
jmp 0x8d29
movl -0x184(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x184(%rbp)
movl -0x17c(%rbp), %eax
movl %eax, -0x278(%rbp)
leaq -0x220(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0xc010
jmp 0x8d5a
movl -0x278(%rbp), %esi
movl -0x184(%rbp), %r8d
leaq -0x208(%rbp), %rdi
leaq -0x220(%rbp), %rdx
leaq -0x160(%rbp), %rcx
callq 0xc140
jmp 0x8d83
movq -0x10(%rbp), %rdi
leaq -0x208(%rbp), %rsi
movl $0x7c, %edx
callq 0x8270
cmpq $0x0, -0x18(%rbp)
je 0x8e1a
leaq -0x30(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0xc340
movq -0x288(%rbp), %rdi
movq %rax, -0x228(%rbp)
callq 0xc370
movq %rax, -0x230(%rbp)
movq -0x18(%rbp), %rdi
callq 0xc3a0
movq %rax, -0x280(%rbp)
jmp 0x8ddb
movq -0x280(%rbp), %rax
movq %rax, -0x238(%rbp)
movq -0x228(%rbp), %rdi
movq -0x230(%rbp), %rsi
movq -0x238(%rbp), %rdx
callq 0xc2d0
movq %rax, -0x290(%rbp)
jmp 0x8e0c
movq -0x290(%rbp), %rax
movq %rax, -0x240(%rbp)
movb -0x17d(%rbp), %al
movb %al, -0x291(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xc3d0
movb -0x291(%rbp), %al
andb $0x1, %al
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x85d0
nopl (%rax)