// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rsi, %rbx
movq %rdi, %r12
leaq 0x60(%rdi), %r13
xorl %r15d, %r15d
movq 0x60(%r12), %rcx
movq 0x68(%r12), %rax
movq %rax, %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %r15, %rdx
jbe 0x2b57
movq %r13, %rdi
movq %r15, %rsi
callq 0x383e
movq (%rax), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3860
incq %r15
testb %al, %al
je 0x2b19
jmp 0x2c42
movq %r13, -0x60(%rbp)
movq %rbx, -0x58(%rbp)
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
xorl %esi, %esi
movl $0x0, -0x2c(%rbp)
xorl %r13d, %r13d
subq %rcx, %rax
sarq $0x3, %rax
cmpq %rsi, %rax
jbe 0x2c2c
movq %r12, %rbx
movq -0x60(%rbp), %rdi
movq %rsi, %r14
callq 0x383e
movq (%rax), %r15
movq %r15, %rdi
movq -0x58(%rbp), %rsi
callq 0x38d8
movl %eax, %r12d
movl -0x2c(%rbp), %eax
cmpl %eax, %r12d
jle 0x2bc5
leaq -0x50(%rbp), %rdi
callq 0x3936
movl %r12d, -0x2c(%rbp)
movq %rbx, %r12
jmp 0x2c05
testl %eax, %eax
movq %r14, %rsi
jle 0x2c0a
cmpl %eax, %r12d
jne 0x2c11
addq $0x10, %r15
leaq -0x208(%rbp), %rdi
movq %r15, %rsi
callq 0x2230
movq %rbx, %r12
leaq -0x50(%rbp), %rdi
leaq -0x208(%rbp), %rbx
movq %rbx, %rsi
callq 0x49c4
movq %rbx, %rdi
callq 0x20b0
movq %r13, %r15
movq %r14, %rsi
jmp 0x2c17
movl $0x0, -0x2c(%rbp)
movq %r13, %r15
movq %rbx, %r12
incq %rsi
movq 0x60(%r12), %rcx
movq 0x68(%r12), %rax
movq %r15, %r13
jmp 0x2b7a
movq %r13, %r14
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0x2c57
leaq -0x50(%rbp), %rdi
callq 0x37c4
movq %r14, %rax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %r13
leaq -0x208(%rbp), %rdi
callq 0x2100
leaq -0x1f8(%rbp), %r12
leaq 0x33d9(%rip), %rsi      # 0x604d
movq %r12, %rdi
callq 0x21a0
movq %rax, %rdi
movq -0x58(%rbp), %rsi
callq 0x2190
leaq 0x3433(%rip), %rsi      # 0x60c2
movq %rax, %rdi
callq 0x21a0
addq $0x10, %r14
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
callq 0x2230
leaq -0x80(%rbp), %rsi
movq %r12, %rdi
callq 0x2190
leaq -0x80(%rbp), %rdi
callq 0x20b0
xorl %ebx, %ebx
leaq 0x33b0(%rip), %r14      # 0x6075
xorl %r15d, %r15d
movq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
sarq $0x5, %rax
cmpq %r15, %rax
jbe 0x2cfc
movq %r12, %rdi
movq %r14, %rsi
callq 0x21a0
movq -0x50(%rbp), %rsi
addq %rbx, %rsi
movq %rax, %rdi
callq 0x2190
incq %r15
addq $0x20, %rbx
jmp 0x2cc8
leaq -0x1f0(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x2290
movq -0x80(%rbp), %rsi
movq %r13, %rdi
callq 0x2d68
jmp 0x2d1e
jmp 0x2d2e
jmp 0x2d2e
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x20b0
jmp 0x2d31
jmp 0x2d2e
movq %rax, %rbx
leaq -0x208(%rbp), %rdi
callq 0x2130
jmp 0x2d57
jmp 0x2d54
movq %rax, %rbx
leaq -0x208(%rbp), %rdi
callq 0x20b0
jmp 0x2d57
jmp 0x2d54
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x37c4
movq %rbx, %rdi
callq 0x22e0