// File: /workspace/github_cpp_makefile_star2_O3/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 $0x1d8, %rsp            # imm = 0x1D8
movq %rsi, -0x50(%rbp)
movq 0x60(%rdi), %rax
movq %rdi, -0x48(%rbp)
movq 0x68(%rdi), %rcx
cmpq %rax, %rcx
je 0x3de3
xorl %ebx, %ebx
movq (%rax,%rbx,8), %r13
movq %r13, %rdi
movq -0x50(%rbp), %rsi
callq 0x538e
testb %al, %al
jne 0x4001
incq %rbx
movq -0x48(%rbp), %rcx
movq 0x60(%rcx), %rax
movq 0x68(%rcx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
ja 0x3dad
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
xorl %ebx, %ebx
cmpq %rax, %rcx
je 0x3ff5
xorl %r14d, %r14d
xorl %r13d, %r13d
movq (%rax,%r14,8), %r15
movq %r15, %rdi
movq -0x50(%rbp), %rsi
callq 0x544c
movl %eax, %r12d
cmpl %ebx, %eax
jle 0x3e63
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %r13
cmpq %rax, %r13
je 0x3e5b
movq %rax, -0x78(%rbp)
leaq 0x10(%rax), %rbx
movq -0x10(%rbx), %rdi
cmpq %rdi, %rbx
je 0x3e43
movq (%rbx), %rsi
incq %rsi
callq 0x31d0
leaq 0x20(%rbx), %rax
addq $0x10, %rbx
cmpq %r13, %rbx
movq %rax, %rbx
jne 0x3e2f
movq -0x78(%rbp), %rax
movq %rax, -0x38(%rbp)
movl %r12d, %ebx
movq %r15, %r13
jmp 0x3ec6
testl %ebx, %ebx
jle 0x3ec4
cmpl %ebx, %r12d
jne 0x3ec6
leaq -0x1f0(%rbp), %rax
movq %rax, -0x200(%rbp)
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
addq %rsi, %rdx
leaq -0x200(%rbp), %r15
movq %r15, %rdi
callq 0x630c
leaq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x65d0
movq -0x200(%rbp), %rdi
leaq -0x1f0(%rbp), %rax
cmpq %rax, %rdi
je 0x3ec6
movq -0x1f0(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3ec6
xorl %ebx, %ebx
incq %r14
movq -0x48(%rbp), %rcx
movq 0x60(%rcx), %rax
movq 0x68(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
ja 0x3e03
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x3ff8
leaq -0x200(%rbp), %rdi
callq 0x3120
leaq -0x1f0(%rbp), %r12
leaq 0x3142(%rip), %rsi      # 0x704f
movl $0x8, %edx
movq %r12, %rdi
callq 0x3210
movq -0x50(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r12, %rdi
callq 0x3210
leaq 0x3190(%rip), %rsi      # 0x70c4
movl $0x10, %edx
movq %rax, %rdi
callq 0x3210
leaq -0x60(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %rdi
callq 0x630c
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq %r12, %rdi
callq 0x3210
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0x3f82
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x31d0
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x3fd8
movl $0x8, %ebx
xorl %r13d, %r13d
leaq 0x30dc(%rip), %r14      # 0x7077
movl $0x2, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x3210
movq -0x40(%rbp), %rax
movq -0x8(%rax,%rbx), %rsi
movq (%rax,%rbx), %rdx
movq %r12, %rdi
callq 0x3210
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
incq %r13
sarq $0x5, %rax
addq $0x20, %rbx
cmpq %r13, %rax
ja 0x3f9b
leaq -0x1e8(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x32b0
movq -0x70(%rbp), %rsi
movq -0x48(%rbp), %rdi
callq 0x409a
xorl %r13d, %r13d
leaq -0x40(%rbp), %rdi
callq 0x5320
movq %r13, %rax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x401c
jmp 0x4038
jmp 0x4038
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0x403b
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x403b
jmp 0x4038
movq %rax, %rbx
movq 0x5f76(%rip), %rsi      # 0x9fb8
leaq -0x200(%rbp), %rdi
callq 0x3140
leaq -0x180(%rbp), %rdi
callq 0x3080
jmp 0x4088
jmp 0x4085
movq %rax, %rbx
movq -0x200(%rbp), %rdi
leaq -0x1f0(%rbp), %rax
cmpq %rax, %rdi
je 0x4088
movq -0x1f0(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x4088
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x5320
movq %rbx, %rdi
callq 0x3320
nop