// File: /workspace/github_cpp_makefile_star2_O3/jpbalarini[P]otsus/./framework/libparser.cpp
// Function: parsecmdline(char const*, char const*, int, char**, std::vector<optstruct*, std::allocator<optstruct*>>&, std::vector<parstruct*, std::allocator<parstruct*>>&)
int parsecmdline(const char *pname,
		 const char *function,
		 const int argc, char **argv,
		 vector <OptStruct*> & opt,
		 vector <ParStruct*> & par) {
	int nopt = opt.size();
	int npar = par.size();
	
	
	char gp[2*nopt+1];
	gp[0]='\0';
	
	
	for(int i=0; i < nopt; i++) { opt[i]->flag = 0; opt[i]->value=NULL; strcat(gp, opt[i]->gp);}
	for(int i=0; i < npar; i++) { par[i]->value = NULL;}
	
	opterr = 0;	// No messages by getopt
	
	int c;
	while ((c = getopt (argc, argv, gp)) != -1)
	{
		
		int j=0;
		for(unsigned int i=0; i < strlen(gp); i++)
			if (c == gp[i])
			{
				
				opt[j]->flag = 1;
				/*				if (optarg != NULL && optarg[0] == '-')
				 {	 
				 printf("\n%s: %s\n", pname, function);
				 fprintf (stderr, "\nerror: option -%c requires an argument.\n", c);
				 printusage(pname,function, gp, argc, argv, opt, nopt, par, npar);
				 return 0;
				 
				 }*/
				
				opt[j]->value = optarg;
				break;
				
			} else if (gp[i] != ':') j++;
		
		
		
		if (c == '?')
		{	
			
			unsigned int i = 0;
			for(i=0; i < strlen(gp); i++)
				if (optopt == gp[i])
				{
					printf("\n%s: %s\n", pname, function);
					fprintf (stderr, "\nerror: option -%c requires an argument.\n", optopt);
					break;	
				}
			
			if (i == strlen(gp)) { 	printf("\n%s: %s\n", pname, function);
				fprintf (stderr, "\nerror: unknown option `-%c'.\n", optopt);
			}
			
			printusage(pname, gp,  opt,  par);
			return 0;
			
		}
		
	}
	
	
	//// Setting default values for non selected options
	for(int j=0; j < nopt; j++)
		if (opt[j]->flag == 0 && opt[j]->defvalue != NULL) opt[j]->value =  opt[j]->defvalue;
	
	
	if (argc - optind != npar) {
		printf("\n%s: %s\n", pname, function);
		fprintf (stderr, "\nerror: incorrect number of parameters\n");
		printusage(pname, gp,  opt,par);
		return 0;
	}
	
	int i=0;
	for (int index = optind; index < argc ; index++, i++){
		par[i]->value = argv[index];
	}
	
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, -0x60(%rbp)
movl %edx, -0x44(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdi, -0x30(%rbp)
movq (%r8), %r12
movq %r8, -0x68(%rbp)
movq 0x8(%r8), %rax
subq %r12, %rax
movq %rax, %rdx
shrq $0x3, %rdx
movq (%r9), %rbx
movq %r9, -0x50(%rbp)
movq 0x8(%r9), %rcx
subq %rbx, %rcx
shrq $0x3, %rcx
movq %rcx, -0x38(%rbp)
shrq $0x2, %rax
orl $0x1, %eax
movq %rsp, %rcx
addq $0xf, %rax
andq $-0x10, %rax
movq %rcx, %r13
subq %rax, %r13
movq %r13, %rsp
negq %rax
movb $0x0, (%rcx,%rax)
movq %rdx, -0x58(%rbp)
testl %edx, %edx
jle 0x4ba5
movq -0x58(%rbp), %r14
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
xorl %r15d, %r15d
movq (%r12,%r15,8), %rax
movl $0x0, 0x8(%rax)
movq $0x0, 0x18(%rax)
movq (%r12,%r15,8), %rax
movq (%rax), %rsi
movq %r13, %rdi
callq 0x34c0
incq %r15
cmpq %r15, %r14
jne 0x4b7b
cmpl $0x0, -0x38(%rbp)
jle 0x4bca
movq -0x38(%rbp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movq (%rbx,%rcx,8), %rdx
movq $0x0, 0x8(%rdx)
incq %rcx
cmpq %rcx, %rax
jne 0x4bb6
movq 0x73ff(%rip), %rax      # 0xbfd0
movl $0x0, (%rax)
movl -0x44(%rbp), %r12d
movl %r12d, %edi
movq -0x60(%rbp), %r15
movq %r15, %rsi
movq %r13, %rdx
callq 0x30c0
cmpl $-0x1, %eax
movq -0x68(%rbp), %r14
je 0x4c6b
movl %eax, %ebx
movq %r13, %rdi
callq 0x3160
testq %rax, %rax
je 0x4c4d
xorl %esi, %esi
movl $0x1, %ecx
xorl %edx, %edx
movsbl (%r13,%rsi), %esi
cmpl %esi, %ebx
je 0x4c2f
xorl %edi, %edi
cmpb $0x3a, %sil
setne %dil
addl %edi, %edx
movl %ecx, %esi
incl %ecx
cmpq %rsi, %rax
ja 0x4c0e
jmp 0x4c4d
movl %edx, %eax
movq (%r14), %rcx
movq (%rcx,%rax,8), %rax
movl $0x1, 0x8(%rax)
movq 0x7352(%rip), %rcx      # 0xbf98
movq (%rcx), %rcx
movq %rcx, 0x18(%rax)
cmpl $0x3f, %ebx
je 0x4ce5
movl %r12d, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x30c0
movl %eax, %ebx
cmpl $-0x1, %eax
jne 0x4bf8
movq -0x58(%rbp), %rdi
testl %edi, %edi
jle 0x4c9d
movq (%r14), %rax
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
cmpl $0x0, 0x8(%rdx)
jne 0x4c95
movq 0x10(%rdx), %rsi
testq %rsi, %rsi
je 0x4c95
movq %rsi, 0x18(%rdx)
incq %rcx
cmpq %rcx, %rdi
jne 0x4c7e
movq 0x7324(%rip), %rax      # 0xbfc8
movslq (%rax), %rdx
movl %r12d, %eax
subl %edx, %eax
cmpl -0x38(%rbp), %eax
jne 0x4d4a
movl $0x1, %eax
cmpl %edx, %r12d
jle 0x4d3b
movq -0x50(%rbp), %rcx
movq (%rcx), %rcx
movl -0x38(%rbp), %esi
leaq (%r15,%rdx,8), %rdx
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
movq (%rcx,%rdi,8), %r9
movq %r8, 0x8(%r9)
incq %rdi
cmpq %rdi, %rsi
jne 0x4ccf
jmp 0x4d3b
movq %r13, %rdi
callq 0x3160
testq %rax, %rax
je 0x4d17
movq 0x72b7(%rip), %rcx      # 0xbfb0
movl (%rcx), %ecx
movl $0x1, %edx
xorl %ebx, %ebx
movsbl (%r13,%rbx), %esi
cmpl %esi, %ecx
je 0x4d68
movl %edx, %ebx
incl %edx
cmpq %rbx, %rax
ja 0x4d02
jmp 0x4d19
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x3160
cmpq %rbx, %rax
je 0x4d59
movq -0x30(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
movq -0x50(%rbp), %rcx
callq 0x48bc
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x363a
jmp 0x4d26
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x35ff
jmp 0x4d26
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x35c4
jmp 0x4d19
nop