// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq %rcx, -0x58(%rbp)
movl %edx, -0x2c(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdi, -0x38(%rbp)
movq (%r8), %r15
movq %r8, -0x60(%rbp)
movq 0x8(%r8), %rax
subq %r15, %rax
movq %rax, %r14
shrq $0x3, %r14
movq (%r9), %rbx
movq %r9, -0x48(%rbp)
movq 0x8(%r9), %rcx
subq %rbx, %rcx
shrq $0x3, %rcx
movq %rcx, -0x50(%rbp)
shrq $0x2, %rax
orl $0x1, %eax
movq %rsp, %rcx
addq $0xf, %rax
andq $-0x10, %rax
movq %rcx, %r12
subq %rax, %r12
movq %r12, %rsp
negq %rax
movb $0x0, (%rcx,%rax)
xorl %r13d, %r13d
testl %r14d, %r14d
cmovlel %r13d, %r14d
cmpq %r13, %r14
je 0x4524
movq (%r15,%r13,8), %rax
andl $0x0, 0x8(%rax)
andq $0x0, 0x18(%rax)
movq (%r15,%r13,8), %rax
movq (%rax), %rsi
movq %r12, %rdi
callq 0x34d0
incq %r13
jmp 0x44fe
xorl %eax, %eax
movq -0x50(%rbp), %rdx
testl %edx, %edx
movl $0x0, %ecx
cmovgl %edx, %ecx
movq -0x60(%rbp), %r15
movq -0x58(%rbp), %r13
cmpq %rax, %rcx
je 0x454f
movq (%rbx,%rax,8), %rdx
andq $0x0, 0x8(%rdx)
incq %rax
jmp 0x453c
movq 0x7a7a(%rip), %rax      # 0xbfd0
andl $0x0, (%rax)
movl -0x2c(%rbp), %edi
movq %r13, %rsi
movq %r12, %rdx
callq 0x30c0
cmpl $-0x1, %eax
je 0x4651
movl %eax, %ebx
movq %r12, %rdi
callq 0x3160
xorl %ecx, %ecx
xorl %edx, %edx
movl %edx, %edx
cmpq %rdx, %rax
jbe 0x45bc
movsbl (%r12,%rdx), %esi
cmpl %esi, %ebx
je 0x459e
xorl %edi, %edi
cmpb $0x3a, %sil
setne %dil
addl %edi, %ecx
incl %edx
jmp 0x457e
movl %ecx, %eax
movq (%r15), %rcx
movq (%rcx,%rax,8), %rax
movl $0x1, 0x8(%rax)
movq 0x79eb(%rip), %rcx      # 0xbfa0
movq (%rcx), %rcx
movq %rcx, 0x18(%rax)
cmpl $0x3f, %ebx
jne 0x4559
movq %r12, %rdi
callq 0x3160
movq 0x79e0(%rip), %rbx      # 0xbfb0
movl (%rbx), %ecx
xorl %edx, %edx
movl %edx, %r14d
cmpq %r14, %rax
jbe 0x4619
movsbl (%r12,%r14), %esi
leal 0x1(%r14), %edx
cmpl %esi, %ecx
jne 0x45d4
leaq 0x3bd8(%rip), %rdi      # 0x81c8
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
xorl %eax, %eax
callq 0x3070
movq 0x79ba(%rip), %rax      # 0xbfc0
movq (%rax), %rdi
movl (%rbx), %edx
leaq 0x3bbf(%rip), %rsi      # 0x81d1
xorl %eax, %eax
callq 0x33c0
movq %r12, %rdi
callq 0x3160
cmpq %r14, %rax
movq -0x48(%rbp), %r14
je 0x46ef
movq -0x38(%rbp), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x4288
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %rax
xorl %ecx, %ecx
movl -0x2c(%rbp), %edi
cmpq %rcx, %r14
je 0x467a
movq (%rax,%rcx,8), %rdx
cmpl $0x0, 0x8(%rdx)
jne 0x4675
movq 0x10(%rdx), %rsi
testq %rsi, %rsi
je 0x4675
movq %rsi, 0x18(%rdx)
incq %rcx
jmp 0x4659
movq 0x7947(%rip), %rax      # 0xbfc8
movslq (%rax), %rcx
movl %edi, %eax
subl %ecx, %eax
cmpl -0x50(%rbp), %eax
jne 0x46b4
movq -0x48(%rbp), %rax
movq (%rax), %rdx
movslq %edi, %rsi
pushq $0x1
popq %rax
cmpq %rsi, %rcx
jge 0x4642
movq (%r13,%rcx,8), %rdi
movq (%rdx), %r8
movq %rdi, 0x8(%r8)
incq %rcx
addq $0x8, %rdx
jmp 0x469a
leaq 0x3b0d(%rip), %rdi      # 0x81c8
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
xorl %eax, %eax
callq 0x3070
movq 0x78ef(%rip), %rax      # 0xbfc0
movq (%rax), %rcx
leaq 0x3b3f(%rip), %rdi      # 0x821a
pushq $0x27
popq %rsi
pushq $0x1
popq %rdx
callq 0x3520
movq -0x48(%rbp), %r14
jmp 0x462e
leaq 0x3ad2(%rip), %rdi      # 0x81c8
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
xorl %eax, %eax
callq 0x3070
movq 0x78b4(%rip), %rax      # 0xbfc0
movq (%rax), %rdi
movl (%rbx), %edx
leaq 0x3ae3(%rip), %rsi      # 0x81fb
xorl %eax, %eax
callq 0x33c0
jmp 0x462e