// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movq 0x60(%rdi), %rax
movq %rdi, -0x58(%rbp)
cmpq %rax, 0x68(%rdi)
setne %bl
je 0x3e03
movq (%rax), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x536e
testb %al, %al
jne 0x3e03
movl $0x1, %r14d
movq -0x58(%rbp), %rcx
movq 0x60(%rcx), %rax
movq 0x68(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
seta %bl
jbe 0x3e03
movq (%rax,%r14,8), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x536e
incq %r14
testb %al, %al
cmovneq %r15, %r13
je 0x3dcc
jmp 0x3e03
testb %bl, %bl
jne 0x3f39
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x58(%rbp), %rcx
movq 0x60(%rcx), %rax
xorl %ebx, %ebx
cmpq %rax, 0x68(%rcx)
je 0x3f23
xorl %r14d, %r14d
xorl %r13d, %r13d
movq %r12, -0x30(%rbp)
movq (%rax,%r14,8), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x5422
movl %eax, %r12d
cmpl %ebx, %eax
jle 0x3e97
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %r13
cmpq %rax, %r13
je 0x3e8f
movq %rax, -0x80(%rbp)
leaq 0x10(%rax), %rbx
movq -0x10(%rbx), %rdi
cmpq %rdi, %rbx
je 0x3e77
movq (%rbx), %rsi
incq %rsi
callq 0x31d0
leaq 0x20(%rbx), %rax
addq $0x10, %rbx
cmpq %r13, %rbx
movq %rax, %rbx
jne 0x3e63
movq -0x80(%rbp), %rax
movq %rax, -0x48(%rbp)
movl %r12d, %ebx
movq %r15, %r13
jmp 0x3efe
testl %ebx, %ebx
jle 0x3efc
cmpl %ebx, %r12d
jne 0x3efe
leaq -0x1f8(%rbp), %rax
movq %rax, -0x208(%rbp)
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
addq %rsi, %rdx
leaq -0x208(%rbp), %r15
movq %r15, %rdi
callq 0x6370
movq -0x30(%rbp), %r12
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0x6658
movq -0x208(%rbp), %rdi
leaq -0x1f8(%rbp), %rax
cmpq %rax, %rdi
je 0x3f02
movq -0x1f8(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3f02
xorl %ebx, %ebx
movq -0x30(%rbp), %r12
incq %r14
movq -0x58(%rbp), %rcx
movq 0x60(%rcx), %rax
movq 0x68(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
ja 0x3e38
jmp 0x3f26
xorl %r13d, %r13d
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0x3f4e
leaq -0x50(%rbp), %rdi
callq 0x5304
movq %r13, %rax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rbx
leaq -0x208(%rbp), %rdi
callq 0x3120
leaq -0x1f8(%rbp), %r12
leaq 0x30e4(%rip), %rsi      # 0x704f
movl $0x8, %edx
movq %r12, %rdi
callq 0x3210
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r12, %rdi
callq 0x3210
leaq 0x3136(%rip), %rsi      # 0x70c4
movl $0x10, %edx
movq %rax, %rdi
callq 0x3210
leaq -0x68(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
addq %rsi, %rdx
leaq -0x78(%rbp), %rdi
callq 0x6370
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq %r12, %rdi
callq 0x3210
movq -0x78(%rbp), %rdi
cmpq %r15, %rdi
je 0x3fdc
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x31d0
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
je 0x4032
movl $0x8, %ebx
xorl %r13d, %r13d
leaq 0x3082(%rip), %r14      # 0x7077
movl $0x2, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x3210
movq -0x50(%rbp), %rax
movq -0x8(%rax,%rbx), %rsi
movq (%rax,%rbx), %rdx
movq %r12, %rdi
callq 0x3210
movq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
incq %r13
sarq $0x5, %rax
addq $0x20, %rbx
cmpq %r13, %rax
ja 0x3ff5
leaq -0x1f0(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x32b0
movq -0x78(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x40d2
jmp 0x4055
jmp 0x4071
jmp 0x4071
movq %rax, %rbx
movq -0x78(%rbp), %rdi
cmpq %r15, %rdi
je 0x4074
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x4074
jmp 0x4071
movq %rax, %rbx
movq 0x5f3d(%rip), %rsi      # 0x9fb8
leaq -0x208(%rbp), %rdi
callq 0x3140
leaq -0x188(%rbp), %rdi
callq 0x3080
jmp 0x40c1
jmp 0x40be
movq %rax, %rbx
movq -0x208(%rbp), %rdi
leaq -0x1f8(%rbp), %rax
cmpq %rax, %rdi
je 0x40c1
movq -0x1f8(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x40c1
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x5304
movq %rbx, %rdi
callq 0x3320