// File: /workspace/github_cpp_makefile_star2_O1/mgo1977[P]c---parsing-argument-options/./Parser.h
// Function: Parser::parse[abi:cxx11](int, char**)
std::vector<std::string>
Parser::parse(int argc, char** argv) {

    std::vector<std::string> otherArguments;

    // first argument is the program name
    if ( argc >= 1 )
        programName = argv[0];

    // now, start iterating over each argument
    for(int argNumber=1; argNumber < argc; ++argNumber) {

        std::string argument = argv[argNumber];

        // arguments start with "-"
        // if not, push it into "other inputs"
        if ( argument.empty() )
            continue;

        if ( argument[0] != '-' ) {
            // add it as other argument and continue with the next arg
            otherArguments.push_back( argument );
            continue;        
        }

        // this is a malformed argument:
        // "-"
        if ( argument.length() < 2 ) {
            std::stringstream error;
            error << "Malformed argument! (see arg number " << argNumber << ")";
            usage(error.str());
        }

        BaseOption* option = NULL;

        std::string possibleValue;

        // now, if the next char is a '-' it's a long option,
        // if not, it's a short one
        if ( argument[1] != '-' ) {

            option = findOption(argument[1]);

            // this looks like a short option, so let's check if there
            // are no more chars here, then we pick the value from here
            if ( argument.length() > 2 ) {
                possibleValue = argument.substr(2);
            }


        }
        else {
            
            // this looks like a long option, so let's check if there
            // are no more chars here, if not, that's malformed
            if ( argument.length() < 3 ) {
                std::stringstream error;
                error << "Malformed argument! (see arg number " << argNumber << ")";
                usage(error.str());
            }

            // let's allow the separation between key and value by '='
            // on long options
            std::string optionAndValueStr = argument.substr(2);

            // initially we suppose there is no value
            std::string optionStr = optionAndValueStr;

            int separator = optionStr.find('=');

            if ( separator != std::string::npos ) {
                optionStr     = optionAndValueStr.substr(0, separator);
                possibleValue = optionAndValueStr.substr(separator+1);
            }

            option = findOption( optionStr );

        }

        if ( option == NULL ) {
            std::stringstream error;
            error << "Unknown option '" << argument << "' (see arg number " << argNumber << ")";
            usage(error.str());
        }

        // let's see if this needs an argument
        if ( option->needArgument() ) {

            if ( possibleValue.empty() ) {

                // try to get the next one or fail
                if ( argNumber+1 < argc ) {

                    // let's move to the next argument
                    argNumber++;

                    option->setValue( argv[argNumber] );

                }
                else {
                    std::stringstream error;
                    error << "Option '" << argument << "' needs an additional argument";
                    usage(error.str());
                }

            }
            else {
                // the value we got directly from the option:
                //   --key=value or -kvalue
                option->setValue( possibleValue.c_str() );
            }

        }
        else {
            // set as read
            option->markAsFound();
        }

    }

    // now, let's do some basic checking

    // was the help option requested?
    if ( helpOption.isSet() ) {
        usage();
    }

    // let's go thru all the options to get all the
    // ones that are mandatories and that weren't
    // set
   
    std::string mandatoriesError; 

    for(std::vector<BaseOption*>::iterator iter = options.begin();
        iter != options.end();
        ++iter
    ) {

        BaseOption* option = *iter;

        if ( option->isMandatory() && !option->isSet() ) {

            if ( ! mandatoriesError.empty() )
                mandatoriesError += ", ";

            mandatoriesError += getSummaryOptionText(option);
        }

    }

    if ( ! mandatoriesError.empty() ) {
        usage("The following arguments are mandatory: " + mandatoriesError);
    }

    return otherArguments;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %rcx, %r12
movl %edx, %r13d
movq %rsi, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, -0x98(%rbp)
movq $0x0, 0x10(%rdi)
testl %edx, %edx
jle 0x3541
movq (%r12), %rbx
leaq 0x78(%r14), %r15
movq 0x80(%r14), %rax
movq %rax, -0x30(%rbp)
movq %rbx, %rdi
callq 0x30b0
movq %r15, %rdi
xorl %esi, %esi
movq -0x30(%rbp), %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x3290
movq %r14, -0x30(%rbp)
cmpl $0x2, %r13d
jl 0x387d
movl $0x1, %r15d
leaq -0x70(%rbp), %rbx
movslq %r15d, %rax
movq (%r12,%rax,8), %rsi
movq %rbx, %rdi
leaq -0x260(%rbp), %rdx
callq 0x51e8
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x3858
movq -0x70(%rbp), %rcx
cmpb $0x2d, (%rcx)
jne 0x374c
cmpq $0x1, %rax
je 0x3a06
leaq -0x80(%rbp), %rdx
movq %rdx, -0x90(%rbp)
movq $0x0, -0x88(%rbp)
movb $0x0, -0x80(%rbp)
movb 0x1(%rcx), %cl
cmpb $0x2d, %cl
jne 0x3760
cmpq $0x2, %rax
jbe 0x3a6f
movl $0x2, %edx
leaq -0x260(%rbp), %rdi
movq %rbx, %rsi
movq $-0x1, %rcx
callq 0x31f0
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x260(%rbp), %rsi
movq -0x258(%rbp), %rdx
addq %rsi, %rdx
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x6370
movq %rbx, %rdi
movl $0x3d, %esi
xorl %edx, %edx
callq 0x3250
movq %rax, %rbx
shlq $0x20, %rbx
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
cmpq %rax, %rbx
je 0x36d4
movq %rbx, %rcx
sarq $0x20, %rcx
leaq -0xd8(%rbp), %r14
movq %r14, %rdi
leaq -0x260(%rbp), %rsi
xorl %edx, %edx
callq 0x31f0
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0x3230
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x3679
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x31d0
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rbx
sarq $0x20, %rbx
movq %r14, %rdi
leaq -0x260(%rbp), %rsi
movq %rbx, %rdx
movq $-0x1, %rcx
callq 0x31f0
leaq -0x90(%rbp), %rdi
movq %r14, %rsi
callq 0x3230
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x36d4
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x31d0
leaq -0xa8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
callq 0x6370
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x3d8c
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x372d
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x31d0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x37cb
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x37cb
movq -0x98(%rbp), %rdi
movq %rbx, %rsi
callq 0x5226
jmp 0x3858
movq -0x30(%rbp), %rsi
movq 0x60(%rsi), %rdx
movq 0x68(%rsi), %rsi
subq %rdx, %rsi
je 0x3795
sarq $0x3, %rsi
cmpq $0x1, %rsi
adcq $0x0, %rsi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
cmpb %cl, 0x8(%r8)
cmoveq %r8, %rbx
je 0x3797
incq %rdi
cmpq %rdi, %rsi
jne 0x377f
xorl %ebx, %ebx
cmpq $0x3, %rax
jb 0x37ed
movl $0x2, %edx
leaq -0x260(%rbp), %r14
movq %r14, %rdi
leaq -0x70(%rbp), %rsi
movq $-0x1, %rcx
callq 0x31f0
leaq -0x90(%rbp), %rdi
movq %r14, %rsi
callq 0x3230
movq -0x260(%rbp), %rdi
leaq -0x250(%rbp), %rax
cmpq %rax, %rdi
je 0x37ed
movq -0x250(%rbp), %rsi
incq %rsi
callq 0x31d0
testq %rbx, %rbx
je 0x397c
cmpb $0x1, 0x31(%rbx)
jne 0x3817
cmpq $0x0, -0x88(%rbp)
je 0x381d
movq -0x90(%rbp), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
jmp 0x3838
movb $0x1, 0x58(%rbx)
jmp 0x3838
incl %r15d
cmpl %r13d, %r15d
jge 0x3b02
movslq %r15d, %rax
movq (%r12,%rax,8), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
leaq -0x70(%rbp), %rbx
je 0x3858
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x31d0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x3871
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x31d0
incl %r15d
cmpl %r13d, %r15d
jl 0x3559
movq -0x30(%rbp), %rdi
cmpb $0x0, 0x58(%rdi)
jne 0x3ad2
leaq -0x250(%rbp), %rax
movq %rax, -0x260(%rbp)
movq $0x0, -0x258(%rbp)
movb $0x0, -0x250(%rbp)
movq 0x60(%rdi), %rbx
cmpq 0x68(%rdi), %rbx
je 0x3933
leaq -0x60(%rbp), %r14
leaq -0x70(%rbp), %r15
leaq -0x260(%rbp), %r12
movq (%rbx), %r13
cmpb $0x1, 0x30(%r13)
jne 0x3925
cmpb $0x0, 0x58(%r13)
jne 0x3925
cmpq $0x0, -0x258(%rbp)
je 0x38ee
movq %r12, %rdi
leaq 0x378e(%rip), %rsi      # 0x7077
callq 0x3340
movq %r15, %rdi
movq %r13, %rdx
leaq 0x391f(%rip), %rcx      # 0x721a
callq 0x44fe
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq %r12, %rdi
callq 0x3070
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x3925
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x31d0
addq $0x8, %rbx
movq -0x30(%rbp), %rax
cmpq 0x68(%rax), %rbx
jne 0x38c4
cmpq $0x0, -0x258(%rbp)
jne 0x3ade
movq -0x260(%rbp), %rdi
leaq -0x250(%rbp), %rax
cmpq %rax, %rdi
je 0x3963
movq -0x250(%rbp), %rsi
incq %rsi
callq 0x31d0
movq -0x98(%rbp), %rax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x260(%rbp), %rdi
callq 0x3120
leaq -0x250(%rbp), %rbx
leaq 0x3695(%rip), %rsi      # 0x702b
movl $0x10, %edx
movq %rbx, %rdi
callq 0x3210
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq %rbx, %rdi
callq 0x3210
movq %rax, %rbx
leaq 0x367f(%rip), %rsi      # 0x703c
movl $0x12, %edx
movq %rax, %rdi
callq 0x3210
movq %rbx, %rdi
movl %r15d, %esi
callq 0x3300
leaq 0x364d(%rip), %rsi      # 0x7029
movl $0x1, %edx
movq %rax, %rdi
callq 0x3210
leaq -0x248(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x32b0
movq -0x50(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x40d2
leaq -0x260(%rbp), %rdi
callq 0x3120
leaq -0x250(%rbp), %rbx
leaq 0x35e4(%rip), %rsi      # 0x7004
movl $0x24, %edx
movq %rbx, %rdi
callq 0x3210
movq %rbx, %rdi
movl %r15d, %esi
callq 0x3300
leaq 0x35ea(%rip), %rsi      # 0x7029
movl $0x1, %edx
movq %rax, %rdi
callq 0x3210
leaq -0x248(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x32b0
movq -0x90(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x40d2
leaq -0x260(%rbp), %rdi
callq 0x3120
leaq -0x250(%rbp), %rbx
leaq 0x357b(%rip), %rsi      # 0x7004
movl $0x24, %edx
movq %rbx, %rdi
callq 0x3210
movq %rbx, %rdi
movl %r15d, %esi
callq 0x3300
leaq 0x3581(%rip), %rsi      # 0x7029
movl $0x1, %edx
movq %rax, %rdi
callq 0x3210
leaq -0x248(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x32b0
movq -0x50(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x40d2
leaq 0x35de(%rip), %rsi      # 0x70b7
callq 0x40d2
leaq 0x3595(%rip), %rsi      # 0x707a
leaq -0x70(%rbp), %rdi
leaq -0x260(%rbp), %rdx
callq 0x5272
movq -0x70(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x40d2
leaq -0x260(%rbp), %rdi
callq 0x3120
leaq -0x250(%rbp), %rbx
leaq 0x3533(%rip), %rsi      # 0x704f
movl $0x8, %edx
movq %rbx, %rdi
callq 0x3210
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq %rbx, %rdi
callq 0x3210
leaq 0x3518(%rip), %rsi      # 0x7058
movl $0x1e, %edx
movq %rax, %rdi
callq 0x3210
leaq -0x248(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x32b0
movq -0x50(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x40d2
jmp 0x3b78
jmp 0x3c26
jmp 0x3b78
jmp 0x3c26
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3c29
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3c29
jmp 0x3c26
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3c02
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3c02
jmp 0x3bff
jmp 0x3c26
jmp 0x3c53
movq %rax, %rbx
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x3d04
jmp 0x3d15
jmp 0x3d12
jmp 0x3c26
jmp 0x3c53
jmp 0x3c7f
jmp 0x3c7f
jmp 0x3c53
jmp 0x3d39
movq %rax, %rbx
movq 0x63af(%rip), %rsi      # 0x9fb8
leaq -0x260(%rbp), %rdi
callq 0x3140
leaq -0x1e0(%rbp), %rdi
callq 0x3080
jmp 0x3ce5
movq %rax, %rbx
movq 0x6388(%rip), %rsi      # 0x9fb8
leaq -0x260(%rbp), %rdi
callq 0x3140
leaq -0x1e0(%rbp), %rdi
callq 0x3080
jmp 0x3cc2
jmp 0x3c53
jmp 0x3ce2
jmp 0x3c53
movq %rax, %rbx
jmp 0x3cc2
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x3c82
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3c82
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3ca0
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3ca0
movq %rax, %rbx
movq -0x260(%rbp), %rdi
leaq -0x250(%rbp), %rax
cmpq %rax, %rdi
je 0x3cc2
movq -0x250(%rbp), %rsi
incq %rsi
callq 0x31d0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3ce5
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3ce5
jmp 0x3d12
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x3d3c
movq -0x60(%rbp), %rsi
jmp 0x3d2f
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x3d15
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3d15
movq %rax, %rbx
movq -0x260(%rbp), %rdi
leaq -0x250(%rbp), %rax
cmpq %rax, %rdi
je 0x3d3c
movq -0x250(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3d3c
movq %rax, %rbx
movq -0x98(%rbp), %rdi
callq 0x5304
movq %rbx, %rdi
callq 0x3320