// File: /workspace/github_cpp_makefile_star2_O3/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 $0x248, %rsp            # imm = 0x248
movq %rcx, -0xa0(%rbp)
movq %rsi, -0x30(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, -0x98(%rbp)
movq $0x0, 0x10(%rdi)
testl %edx, %edx
jle 0x3893
movl %edx, %r13d
movq -0xa0(%rbp), %rax
movq (%rax), %rbx
movq -0x30(%rbp), %rax
leaq 0x78(%rax), %r14
movq 0x80(%rax), %r15
movq %rbx, %rdi
callq 0x30b0
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x3290
cmpl $0x1, %r13d
je 0x3893
movl $0x1, %r15d
leaq -0x40(%rbp), %r14
leaq -0x50(%rbp), %rbx
movslq %r15d, %rax
movq -0xa0(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
movq %rbx, %rdi
leaq -0x268(%rbp), %rdx
callq 0x5204
movq -0x48(%rbp), %rax
testq %rax, %rax
je 0x3872
movq -0x50(%rbp), %rcx
cmpb $0x2d, (%rcx)
jne 0x3761
cmpq $0x1, %rax
je 0x3a20
leaq -0x80(%rbp), %rdx
movq %rdx, -0x90(%rbp)
movq $0x0, -0x88(%rbp)
movb $0x0, -0x80(%rbp)
movb 0x1(%rcx), %cl
cmpb $0x2d, %cl
jne 0x3775
cmpq $0x2, %rax
jbe 0x3a89
movl $0x2, %edx
leaq -0x268(%rbp), %rdi
movq %rbx, %rsi
movq $-0x1, %rcx
callq 0x31f0
leaq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x268(%rbp), %rsi
movq -0x260(%rbp), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %r14
movq %r14, %rdi
callq 0x630c
movq %r14, %rdi
movl $0x3d, %esi
xorl %edx, %edx
callq 0x3250
movq %rax, %r14
shlq $0x20, %r14
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
cmpq %rax, %r14
je 0x36e9
movq %r14, %rcx
sarq $0x20, %rcx
leaq -0xe0(%rbp), %r12
movq %r12, %rdi
leaq -0x268(%rbp), %rsi
xorl %edx, %edx
callq 0x31f0
leaq -0x70(%rbp), %rdi
movq %r12, %rsi
callq 0x3230
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x368e
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x31d0
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r14
sarq $0x20, %r14
movq %r12, %rdi
leaq -0x268(%rbp), %rsi
movq %r14, %rdx
movq $-0x1, %rcx
callq 0x31f0
leaq -0x90(%rbp), %rdi
movq %r12, %rsi
callq 0x3230
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x36e9
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x31d0
leaq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %r14
movq %r14, %rdi
callq 0x630c
movq -0x30(%rbp), %rdi
movq %r14, %rsi
callq 0x3d82
movq %rax, %r14
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x3742
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x31d0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x37dc
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x37dc
movq -0x98(%rbp), %rdi
movq %rbx, %rsi
callq 0x5242
jmp 0x3872
movq -0x30(%rbp), %rsi
movq 0x60(%rsi), %rdx
movq 0x68(%rsi), %rsi
subq %rdx, %rsi
je 0x37a6
sarq $0x3, %rsi
cmpq $0x1, %rsi
adcq $0x0, %rsi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r14
cmpb %cl, 0x8(%r14)
je 0x37a9
incq %rdi
cmpq %rdi, %rsi
jne 0x3794
xorl %r14d, %r14d
cmpq $0x3, %rax
jb 0x37fe
movl $0x2, %edx
movq %rbx, %rsi
leaq -0x268(%rbp), %r12
movq %r12, %rdi
movq $-0x1, %rcx
callq 0x31f0
leaq -0x90(%rbp), %rdi
movq %r12, %rsi
callq 0x3230
movq -0x268(%rbp), %rdi
leaq -0x258(%rbp), %rax
cmpq %rax, %rdi
je 0x37fe
movq -0x258(%rbp), %rsi
incq %rsi
callq 0x31d0
testq %r14, %r14
je 0x3996
cmpb $0x1, 0x31(%r14)
jne 0x3829
cmpq $0x0, -0x88(%rbp)
je 0x3830
movq -0x90(%rbp), %rsi
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
jmp 0x3852
movb $0x1, 0x58(%r14)
jmp 0x3852
incl %r15d
cmpl %r13d, %r15d
jge 0x3b1c
movslq %r15d, %rax
movq -0xa0(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
leaq -0x40(%rbp), %r14
je 0x3872
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x31d0
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x3887
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x31d0
incl %r15d
cmpl %r13d, %r15d
jl 0x3567
movq -0x30(%rbp), %rdi
cmpb $0x0, 0x58(%rdi)
jne 0x3aec
leaq -0x258(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
movq 0x60(%rdi), %r12
movq 0x68(%rdi), %rax
cmpq %rax, %r12
je 0x3962
leaq 0x394b(%rip), %rbx      # 0x721a
leaq -0x50(%rbp), %r14
leaq -0x268(%rbp), %r15
movq (%r12), %r13
cmpb $0x1, 0x30(%r13)
jne 0x3944
cmpb $0x0, 0x58(%r13)
jne 0x3944
cmpq $0x0, -0x260(%rbp)
je 0x3905
movq %r15, %rdi
leaq 0x3777(%rip), %rsi      # 0x7077
callq 0x3340
movq %r14, %rdi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x44c6
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %r15, %rdi
callq 0x3070
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x393c
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x31d0
movq -0x30(%rbp), %rax
movq 0x68(%rax), %rax
addq $0x8, %r12
cmpq %rax, %r12
jne 0x38da
cmpq $0x0, -0x260(%rbp)
leaq -0x258(%rbp), %rcx
jne 0x3af8
movq -0x268(%rbp), %rdi
cmpq %rcx, %rdi
je 0x397d
movq -0x258(%rbp), %rsi
incq %rsi
callq 0x31d0
movq -0x98(%rbp), %rax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x268(%rbp), %rdi
callq 0x3120
leaq -0x258(%rbp), %rbx
leaq 0x367b(%rip), %rsi      # 0x702b
movl $0x10, %edx
movq %rbx, %rdi
callq 0x3210
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %rbx, %rdi
callq 0x3210
movq %rax, %rbx
leaq 0x3665(%rip), %rsi      # 0x703c
movl $0x12, %edx
movq %rax, %rdi
callq 0x3210
movq %rbx, %rdi
movl %r15d, %esi
callq 0x3300
leaq 0x3633(%rip), %rsi      # 0x7029
movl $0x1, %edx
movq %rax, %rdi
callq 0x3210
leaq -0x250(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x32b0
movq -0x70(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x409a
leaq -0x268(%rbp), %rdi
callq 0x3120
leaq -0x258(%rbp), %rbx
leaq 0x35ca(%rip), %rsi      # 0x7004
movl $0x24, %edx
movq %rbx, %rdi
callq 0x3210
movq %rbx, %rdi
movl %r15d, %esi
callq 0x3300
leaq 0x35d0(%rip), %rsi      # 0x7029
movl $0x1, %edx
movq %rax, %rdi
callq 0x3210
leaq -0x250(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x32b0
movq -0x90(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x409a
leaq -0x268(%rbp), %rdi
callq 0x3120
leaq -0x258(%rbp), %rbx
leaq 0x3561(%rip), %rsi      # 0x7004
movl $0x24, %edx
movq %rbx, %rdi
callq 0x3210
movq %rbx, %rdi
movl %r15d, %esi
callq 0x3300
leaq 0x3567(%rip), %rsi      # 0x7029
movl $0x1, %edx
movq %rax, %rdi
callq 0x3210
leaq -0x250(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x32b0
movq -0x70(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x409a
leaq 0x35c4(%rip), %rsi      # 0x70b7
callq 0x409a
leaq 0x357b(%rip), %rsi      # 0x707a
leaq -0x50(%rbp), %rdi
leaq -0x268(%rbp), %rdx
callq 0x528e
movq -0x50(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x409a
leaq -0x268(%rbp), %rdi
callq 0x3120
leaq -0x258(%rbp), %rbx
leaq 0x3519(%rip), %rsi      # 0x704f
movl $0x8, %edx
movq %rbx, %rdi
callq 0x3210
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %rbx, %rdi
callq 0x3210
leaq 0x34fe(%rip), %rsi      # 0x7058
movl $0x1e, %edx
movq %rax, %rdi
callq 0x3210
leaq -0x250(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x32b0
movq -0x70(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x409a
jmp 0x3b92
jmp 0x3c1a
jmp 0x3b92
jmp 0x3c1a
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x3c1d
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3c1d
jmp 0x3c1a
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3bf6
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3bf6
jmp 0x3bf3
jmp 0x3c1a
jmp 0x3c47
jmp 0x3cee
jmp 0x3d0c
jmp 0x3c1a
jmp 0x3c47
jmp 0x3c73
jmp 0x3c73
jmp 0x3c47
movq %rax, %rbx
movq 0x63bb(%rip), %rsi      # 0x9fb8
leaq -0x268(%rbp), %rdi
callq 0x3140
leaq -0x1e8(%rbp), %rdi
callq 0x3080
jmp 0x3cd9
movq %rax, %rbx
movq 0x6394(%rip), %rsi      # 0x9fb8
leaq -0x268(%rbp), %rdi
callq 0x3140
leaq -0x1e8(%rbp), %rdi
callq 0x3080
jmp 0x3cb6
jmp 0x3c47
jmp 0x3cd6
jmp 0x3c47
movq %rax, %rbx
jmp 0x3cb6
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x3c76
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3c76
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x3c94
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3c94
movq %rax, %rbx
movq -0x268(%rbp), %rdi
leaq -0x258(%rbp), %rax
cmpq %rax, %rdi
je 0x3cb6
movq -0x258(%rbp), %rsi
incq %rsi
callq 0x31d0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3cd9
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3cd9
jmp 0x3d33
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3d36
movq -0x40(%rbp), %rsi
jmp 0x3d29
jmp 0x3d0c
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3d0f
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3d0f
movq %rax, %rbx
movq -0x268(%rbp), %rdi
leaq -0x258(%rbp), %rax
cmpq %rax, %rdi
je 0x3d36
movq -0x258(%rbp), %rsi
incq %rsi
callq 0x31d0
jmp 0x3d36
movq %rax, %rbx
movq -0x98(%rbp), %rdi
callq 0x5320
movq %rbx, %rdi
callq 0x3320