// File: /workspace/github_cpp_makefile_star2_O2/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 $0x258, %rsp            # imm = 0x258
movq %rcx, %r14
movq %rsi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, -0x40(%rbp)
andq $0x0, 0x10(%rdi)
movl %edx, -0x34(%rbp)
testl %edx, %edx
jle 0x24c8
movq (%r14), %rsi
leaq 0x78(%rbx), %rdi
callq 0x2310
movq %r14, -0xb0(%rbp)
movq %rbx, -0x30(%rbp)
pushq $0x1
popq %r15
leaq -0x258(%rbp), %r13
leaq -0x278(%rbp), %rbx
cmpl -0x34(%rbp), %r15d
jge 0x2730
movslq %r15d, %rax
movq -0xb0(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
leaq -0x60(%rbp), %rdi
leaq -0x238(%rbp), %rdx
callq 0x36b6
movq -0x58(%rbp), %rax
testq %rax, %rax
je 0x271f
movq -0x60(%rbp), %rcx
cmpb $0x2d, (%rcx)
jne 0x2666
cmpq $0x1, %rax
je 0x27f2
leaq -0x98(%rbp), %rdx
movq %rdx, -0xa8(%rbp)
andq $0x0, -0xa0(%rbp)
movb $0x0, -0x98(%rbp)
movb 0x1(%rcx), %cl
cmpb $0x2d, %cl
jne 0x2678
cmpq $0x2, %rax
jbe 0x28c9
leaq -0x238(%rbp), %r14
movq %r14, %rdi
leaq -0x60(%rbp), %rsi
pushq $0x2
popq %rdx
pushq $-0x1
popq %rcx
callq 0x21d0
leaq -0x88(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x2230
movq %r12, %rdi
pushq $0x3d
popq %rsi
xorl %edx, %edx
callq 0x2220
movq %rax, %r14
shlq $0x20, %r14
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
cmpq %rax, %r14
je 0x2628
movl %r15d, -0x64(%rbp)
movq %r14, %rcx
sarq $0x20, %rcx
movq %rbx, %r15
movq %rbx, %rdi
leaq -0x238(%rbp), %r12
movq %r12, %rsi
xorl %edx, %edx
callq 0x21d0
leaq -0x88(%rbp), %rdi
movq %r15, %rsi
callq 0x21f0
movq %r15, %rdi
callq 0x20b0
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r14
sarq $0x20, %r14
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
pushq $-0x1
popq %rcx
callq 0x21d0
leaq -0xa8(%rbp), %rdi
movq %r15, %rsi
callq 0x21f0
movq %r15, %rdi
callq 0x20b0
movl -0x64(%rbp), %r15d
movq %r13, %r12
movq %r13, %rdi
leaq -0x88(%rbp), %rsi
callq 0x2230
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq 0x2af8
movq %rax, %r14
movq %r12, %rdi
callq 0x20b0
leaq -0x88(%rbp), %rdi
callq 0x20b0
leaq -0x238(%rbp), %rdi
jmp 0x26b9
movq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x36f2
jmp 0x271f
movsbl %cl, %esi
movq -0x30(%rbp), %rdi
callq 0x2aac
movq %rax, %r14
cmpq $0x3, -0x58(%rbp)
jb 0x26be
leaq -0x238(%rbp), %r12
movq %r12, %rdi
leaq -0x60(%rbp), %rsi
pushq $0x2
popq %rdx
pushq $-0x1
popq %rcx
callq 0x21d0
leaq -0xa8(%rbp), %rdi
movq %r12, %rsi
callq 0x21f0
movq %r12, %rdi
callq 0x20b0
testq %r14, %r14
je 0x2850
cmpb $0x1, 0x31(%r14)
jne 0x26e9
cmpq $0x0, -0xa0(%rbp)
je 0x26f0
movq -0xa8(%rbp), %rsi
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
jmp 0x2713
movb $0x1, 0x58(%r14)
jmp 0x2713
incl %r15d
cmpl -0x34(%rbp), %r15d
jge 0x2927
movslq %r15d, %rax
movq -0xb0(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
leaq -0xa8(%rbp), %rdi
callq 0x20b0
leaq -0x60(%rbp), %rdi
callq 0x20b0
incl %r15d
jmp 0x24e5
movq -0x30(%rbp), %rdi
cmpb $0x0, 0x58(%rdi)
jne 0x2984
leaq -0x228(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x60(%rdi), %r13
leaq -0x60(%rbp), %rbx
leaq -0x238(%rbp), %r14
leaq 0x390e(%rip), %r15      # 0x6075
cmpq 0x68(%rdi), %r13
je 0x27c2
movq (%r13), %r12
cmpb $0x1, 0x30(%r12)
jne 0x27b8
cmpb $0x0, 0x58(%r12)
jne 0x27b8
cmpq $0x0, -0x230(%rbp)
je 0x2796
movq %r14, %rdi
movq %r15, %rsi
callq 0x2300
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
movq %r12, %rdx
callq 0x372e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2320
movq %rbx, %rdi
callq 0x20b0
addq $0x8, %r13
movq -0x30(%rbp), %rdi
jmp 0x2767
cmpq $0x0, -0x230(%rbp)
jne 0x2990
leaq -0x238(%rbp), %rdi
callq 0x20b0
movq -0x40(%rbp), %rax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r15d, %ebx
leaq -0x238(%rbp), %rdi
callq 0x2100
leaq -0x228(%rbp), %rdi
leaq 0x37f5(%rip), %rsi      # 0x6004
callq 0x21a0
movq %rax, %rdi
movl %ebx, %esi
callq 0x22d0
leaq 0x3a91(%rip), %rsi      # 0x62b6
movq %rax, %rdi
callq 0x21a0
leaq -0x220(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x2290
movq -0xa8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x2d68
movl %r15d, %ebx
leaq -0x238(%rbp), %rdi
callq 0x2100
leaq -0x228(%rbp), %rdi
leaq 0x37bc(%rip), %rsi      # 0x6029
callq 0x21a0
leaq -0x60(%rbp), %rsi
movq %rax, %rdi
callq 0x2190
leaq 0x37b5(%rip), %rsi      # 0x603a
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
movl %ebx, %esi
callq 0x22d0
leaq 0x3a18(%rip), %rsi      # 0x62b6
movq %rax, %rdi
callq 0x21a0
leaq -0x220(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x2290
movq -0x88(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x2d68
movl %r15d, %ebx
leaq -0x238(%rbp), %rdi
callq 0x2100
leaq -0x228(%rbp), %rdi
leaq 0x371e(%rip), %rsi      # 0x6004
callq 0x21a0
movq %rax, %rdi
movl %ebx, %esi
callq 0x22d0
leaq 0x39ba(%rip), %rsi      # 0x62b6
movq %rax, %rdi
callq 0x21a0
leaq -0x220(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x2290
movq -0x88(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x2d68
leaq -0x238(%rbp), %rdi
callq 0x2100
leaq -0x228(%rbp), %rdi
leaq 0x370c(%rip), %rsi      # 0x604d
callq 0x21a0
leaq -0x60(%rbp), %rsi
movq %rax, %rdi
callq 0x2190
leaq 0x36fd(%rip), %rsi      # 0x6056
movq %rax, %rdi
callq 0x21a0
leaq -0x220(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x2290
movq -0x88(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x2d68
leaq 0x372a(%rip), %rsi      # 0x60b5
callq 0x2d68
leaq 0x36e1(%rip), %rsi      # 0x6078
leaq -0x60(%rbp), %rdi
leaq -0x238(%rbp), %rdx
callq 0x374d
movq -0x60(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x2d68
jmp 0x29bc
jmp 0x2a13
jmp 0x29bc
jmp 0x2a13
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x20b0
jmp 0x2a16
jmp 0x2a13
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x20b0
jmp 0x2a05
jmp 0x2a02
jmp 0x2a5f
jmp 0x2a6d
jmp 0x2a13
jmp 0x2a7e
jmp 0x2a98
jmp 0x2a13
jmp 0x2a7e
jmp 0x2a24
jmp 0x2a7e
jmp 0x2a24
movq %rax, %rbx
leaq -0x238(%rbp), %rdi
callq 0x2130
jmp 0x2a8d
movq %rax, %rbx
leaq -0x238(%rbp), %rdi
callq 0x2130
jmp 0x2a81
movq %rax, %rbx
jmp 0x2a43
movq %rax, %rbx
jmp 0x2a4f
jmp 0x2a7e
jmp 0x2a7e
jmp 0x2a79
movq %rax, %rbx
leaq -0x258(%rbp), %rdi
callq 0x20b0
leaq -0x88(%rbp), %rdi
callq 0x20b0
leaq -0x238(%rbp), %rdi
callq 0x20b0
jmp 0x2a81
jmp 0x2a6d
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x20b0
jmp 0x2a70
movq %rax, %rbx
leaq -0x238(%rbp), %rdi
jmp 0x2a91
movq %rax, %rbx
jmp 0x2a8d
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x20b0
leaq -0x60(%rbp), %rdi
callq 0x20b0
jmp 0x2a9b
movq %rax, %rbx
movq -0x40(%rbp), %rdi
callq 0x37c4
movq %rbx, %rdi
callq 0x22e0