// File: mgo1977[P]c---parsing-argument-options/./Parser.h
// Function: Parser::findOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
BaseOption*
Parser::findOption(std::string longOption) {

    // iterate over the array and search for the exact match option
    for(int index=0; index < options.size(); ++index) {
        BaseOption* option = options.at(index);
        if ( option->matches( longOption ) )
            return option;
    }

    // now, let's search for better matching ones...
    int bestMatchSize   = 0;
    BaseOption* bestMatchOption = NULL;
    std::vector<std::string> ambiguousOptions;

    for(int index=0; index < options.size(); ++index) {
        BaseOption* option = options.at(index);

        int matchSize = option->bestMatch(longOption);

        // we have a new winner
        if ( matchSize > bestMatchSize ) {
            bestMatchSize   = matchSize;
            bestMatchOption = option;

            // clear the list
            ambiguousOptions.clear();
        }
        else if (bestMatchSize>0 && matchSize==bestMatchSize ) {
            // this is conflicting with other option
            ambiguousOptions.push_back(option->getLongOption());
        }

    }

    if ( ambiguousOptions.size() > 0 ) {
        // if we're in an ambiguous case, it's better to report it
        std::stringstream error;
        error << "Option '" << longOption << "' is ambiguous: ";

        error << bestMatchOption->getLongOption();

        for(int index=0; index < ambiguousOptions.size(); ++index) {
            error << ", " << ambiguousOptions[index];
        }

        usage(error.str());
    }



    return bestMatchOption;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
movq %rsi, -0x270(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x268(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x268(%rbp), %rdi
movslq -0x1c(%rbp), %rax
movq %rax, -0x278(%rbp)
addq $0x60, %rdi
callq 0x5cb0
movq %rax, %rcx
movq -0x278(%rbp), %rax
cmpq %rcx, %rax
jae 0x4261
movq -0x268(%rbp), %rdi
addq $0x60, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x5cd0
movq -0x270(%rbp), %rsi
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x5d40
testb $0x1, %al
jne 0x4247
jmp 0x4254
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x457a
jmp 0x4256
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x41ec
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x5670
movl $0x0, -0x54(%rbp)
movq -0x268(%rbp), %rdi
movslq -0x54(%rbp), %rax
movq %rax, -0x280(%rbp)
addq $0x60, %rdi
callq 0x5cb0
movq %rax, %rcx
movq -0x280(%rbp), %rax
cmpq %rcx, %rax
jae 0x439b
movq -0x268(%rbp), %rdi
addq $0x60, %rdi
movslq -0x54(%rbp), %rsi
callq 0x5cd0
movq %rax, -0x288(%rbp)
jmp 0x42cb
movq -0x270(%rbp), %rsi
movq -0x288(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0x5dd0
movl %eax, -0x28c(%rbp)
jmp 0x42f1
movl -0x28c(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jle 0x432c
movl -0x70(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x5eb0
jmp 0x438b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x456f
cmpl $0x0, -0x2c(%rbp)
jle 0x4389
movl -0x70(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x4389
movq -0x60(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x5c80
jmp 0x434c
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x5ed0
jmp 0x435e
leaq -0x90(%rbp), %rdi
callq 0x3160
jmp 0x4389
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x3160
jmp 0x456f
jmp 0x438b
jmp 0x438d
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x4280
leaq -0x50(%rbp), %rdi
callq 0x5f00
cmpq $0x0, %rax
jbe 0x455c
leaq -0x218(%rbp), %rdi
callq 0x31a0
jmp 0x43bc
leaq -0x208(%rbp), %rdi
leaq 0x7c83(%rip), %rsi      # 0xc04d
callq 0x3260
movq %rax, -0x298(%rbp)
jmp 0x43d8
movq -0x270(%rbp), %rsi
movq -0x298(%rbp), %rdi
callq 0x3230
movq %rax, -0x2a0(%rbp)
jmp 0x43f4
movq -0x2a0(%rbp), %rdi
leaq 0x7cc0(%rip), %rsi      # 0xc0c2
callq 0x3260
jmp 0x4409
leaq -0x208(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movq -0x38(%rbp), %rsi
leaq -0x238(%rbp), %rdi
callq 0x5c80
jmp 0x4429
movq -0x2a8(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x3230
jmp 0x443e
leaq -0x238(%rbp), %rdi
callq 0x3160
movl $0x0, -0x23c(%rbp)
movslq -0x23c(%rbp), %rax
movq %rax, -0x2b0(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x5f00
movq %rax, %rcx
movq -0x2b0(%rbp), %rax
cmpq %rcx, %rax
jae 0x44f2
leaq -0x208(%rbp), %rdi
leaq 0x7bed(%rip), %rsi      # 0xc075
callq 0x3260
movq %rax, -0x2b8(%rbp)
jmp 0x4496
movslq -0x23c(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x5f20
movq -0x2b8(%rbp), %rdi
movq %rax, %rsi
callq 0x3230
jmp 0x44b7
jmp 0x44b9
movl -0x23c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x23c(%rbp)
jmp 0x4454
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x454e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x3160
jmp 0x454e
leaq -0x260(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x3250
jmp 0x4507
movq -0x268(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x57b0
jmp 0x451c
leaq -0x260(%rbp), %rdi
callq 0x3160
leaq -0x218(%rbp), %rdi
callq 0x31d0
jmp 0x455c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x3160
leaq -0x218(%rbp), %rdi
callq 0x31d0
jmp 0x456f
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x5aa0
jmp 0x457a
leaq -0x50(%rbp), %rdi
callq 0x5aa0
jmp 0x4587
movq -0x8(%rbp), %rax
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x3480