// File: 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
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0x6720
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rdi
callq 0x66c0
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
addl %eax, %eax
movl %eax, %edx
movq %rdx, %rcx
incq %rcx
movq %rsp, %rax
movq %rax, -0x48(%rbp)
addq $0x10, %rdx
andq $-0x10, %rdx
movq %rsp, %rax
subq %rdx, %rax
movq %rax, -0x80(%rbp)
movq %rax, %rsp
movq %rcx, -0x50(%rbp)
movb $0x0, (%rax)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x632f
movq -0x30(%rbp), %rdi
movslq -0x54(%rbp), %rsi
callq 0x6700
movq (%rax), %rax
movl $0x0, 0x8(%rax)
movq -0x30(%rbp), %rdi
movslq -0x54(%rbp), %rsi
callq 0x6700
movq (%rax), %rax
movq $0x0, 0x18(%rax)
movq -0x30(%rbp), %rdi
movslq -0x54(%rbp), %rsi
callq 0x6700
movq -0x80(%rbp), %rdi
movq (%rax), %rax
movq (%rax), %rsi
callq 0x3580
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x62d1
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x6361
movq -0x38(%rbp), %rdi
movslq -0x58(%rbp), %rsi
callq 0x66e0
movq (%rax), %rax
movq $0x0, 0x8(%rax)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x6336
movq 0xcc60(%rip), %rax      # 0x12fc8
movl $0x0, (%rax)
movq -0x80(%rbp), %rdx
movl -0x1c(%rbp), %edi
movq -0x28(%rbp), %rsi
callq 0x30d0
movl %eax, -0x5c(%rbp)
cmpl $-0x1, %eax
je 0x655e
movl $0x0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movq -0x80(%rbp), %rdi
movl -0x64(%rbp), %eax
movq %rax, -0x88(%rbp)
callq 0x3190
movq %rax, %rcx
movq -0x88(%rbp), %rax
cmpq %rcx, %rax
jae 0x6440
movq -0x80(%rbp), %rcx
movl -0x5c(%rbp), %eax
movl -0x64(%rbp), %edx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x6415
movq -0x30(%rbp), %rdi
movslq -0x60(%rbp), %rsi
callq 0x6700
movq (%rax), %rax
movl $0x1, 0x8(%rax)
movq 0xcbaa(%rip), %rax      # 0x12f98
movq (%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x30(%rbp), %rdi
movslq -0x60(%rbp), %rsi
callq 0x6700
movq -0x90(%rbp), %rcx
movq (%rax), %rax
movq %rcx, 0x18(%rax)
jmp 0x6440
movq -0x80(%rbp), %rax
movl -0x64(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
je 0x642e
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x6430
jmp 0x6432
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x6398
cmpl $0x3f, -0x5c(%rbp)
jne 0x6559
movl $0x0, -0x68(%rbp)
movl $0x0, -0x68(%rbp)
movq -0x80(%rbp), %rdi
movl -0x68(%rbp), %eax
movq %rax, -0x98(%rbp)
callq 0x3190
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jae 0x64d8
movq -0x80(%rbp), %rcx
movq 0xcb23(%rip), %rax      # 0x12fa8
movl (%rax), %eax
movl -0x68(%rbp), %edx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x64cb
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x6d29(%rip), %rdi      # 0xd1ca
movb $0x0, %al
callq 0x3070
movq 0xcb09(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movq 0xcaef(%rip), %rax      # 0x12fa8
movl (%rax), %edx
leaq 0x6d11(%rip), %rsi      # 0xd1d3
movb $0x0, %al
callq 0x3470
jmp 0x64d8
jmp 0x64cd
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x6458
movq -0x80(%rbp), %rdi
movl -0x68(%rbp), %eax
movq %rax, -0xa0(%rbp)
callq 0x3190
movq %rax, %rcx
movq -0xa0(%rbp), %rax
cmpq %rcx, %rax
jne 0x6531
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x6cc1(%rip), %rdi      # 0xd1ca
movb $0x0, %al
callq 0x3070
movq 0xcaa1(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movq 0xca87(%rip), %rax      # 0x12fa8
movl (%rax), %edx
leaq 0x6cd3(%rip), %rsi      # 0xd1fd
movb $0x0, %al
callq 0x3470
movq -0x80(%rbp), %rsi
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x5f70
movl $0x0, -0x4(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x66ac
jmp 0x636e
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x65dd
movq -0x30(%rbp), %rdi
movslq -0x70(%rbp), %rsi
callq 0x6700
movq (%rax), %rax
cmpl $0x0, 0x8(%rax)
jne 0x65d0
movq -0x30(%rbp), %rdi
movslq -0x70(%rbp), %rsi
callq 0x6700
movq (%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x65d0
movq -0x30(%rbp), %rdi
movslq -0x70(%rbp), %rsi
callq 0x6700
movq (%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x30(%rbp), %rdi
movslq -0x70(%rbp), %rsi
callq 0x6700
movq -0xa8(%rbp), %rcx
movq (%rax), %rax
movq %rcx, 0x18(%rax)
jmp 0x65d2
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x6565
movl -0x1c(%rbp), %eax
movq 0xc9d9(%rip), %rcx      # 0x12fc0
subl (%rcx), %eax
cmpl -0x40(%rbp), %eax
je 0x6641
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x6bcd(%rip), %rdi      # 0xd1ca
movb $0x0, %al
callq 0x3070
movq 0xc9ad(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
leaq 0x6c07(%rip), %rsi      # 0xd21c
movb $0x0, %al
callq 0x3470
movq -0x80(%rbp), %rsi
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x5f70
movl $0x0, -0x4(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x66ac
movl $0x0, -0x74(%rbp)
movq 0xc971(%rip), %rax      # 0x12fc0
movl (%rax), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x669e
movq -0x28(%rbp), %rax
movslq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xb0(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x74(%rbp), %rsi
callq 0x66e0
movq -0xb0(%rbp), %rcx
movq (%rax), %rax
movq %rcx, 0x8(%rax)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x6654
movl $0x1, -0x4(%rbp)
movl $0x1, -0x6c(%rbp)
movq -0x48(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax,%rax)