// File: gpertea[P]gclib/GArgs.cpp
// Function: GArgs::GArgs(int, char**, char const*, bool)
GArgs::GArgs(int argc, char* argv[], const char* format, bool nodigitopts) {
   /* format can be:
      <string>{;|=} e.g. disable-test;PID=S= for --disable-test PID=50 (or --PID 50) S=3.5 etc.
      <letter>[:]  e.g. p:hT  for -p testing (or -ptesting) -h -T
   */
const char* fstr=format;
fmtcount=0;
count=0;
nonOptCount=0;
nonOptPos=0;
optPos=0;
errarg=0;
err_valmissing=false;
args=NULL;
fmt=NULL;
_argc=argc;
_argv=argv;
int fmtlen=strlen(format);
//---- first parse the format string
while (fstr-format < fmtlen ) {
  int l=strcspn(fstr, ";=:");
  if (fstr[l]==0) { //end of string reached
      //all previous chars are just switches:
       GREALLOC(fmt, (fmtcount+l)*sizeof(fmtdef));
       //store each switch
       for (int i=0; i<l;i++) { 
         fmt[fmtcount+i].longopt=NULL;
         fmt[fmtcount+i].opt=fstr[i];
         fmt[fmtcount+i].req_value = false;
         fmt[fmtcount+i].code=fmtcount+i+1;
         }
       fmtcount+=l;
       break;
     }
   else {
     if (fstr[l]==':') {
         //fstr[l-1] is an argument, but all the previous are just switches
         GREALLOC(fmt, (fmtcount+l)*sizeof(fmtdef));
         //store each switch AND the option
         for (int i=0; i<l;i++) { 
           fmt[fmtcount+i].longopt=NULL; //one char length
           fmt[fmtcount+i].opt=fstr[i];
           fmt[fmtcount+i].req_value = (i==l-1);
           fmt[fmtcount+i].code=fmtcount+i+1;
           }
         fmtcount+=l;
         }
      else { // fstr[l]=='=' or ';' 
         GREALLOC(fmt, (fmtcount+1)*sizeof(fmtdef));
         fmt[fmtcount].longopt=Gstrdup(fstr, fstr+l-1);
         fmt[fmtcount].opt=0;
         fmt[fmtcount].req_value=(fstr[l]=='=');
         fmt[fmtcount].code=fmtcount+1;
         fmtcount++;
         }
     fstr+=l+1;
     }
  }
 //-- now parse the arguments based on the given format specification
 parseArgs(nodigitopts);
 }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rcx
movq %rcx, -0x30(%rbp)
movl $0x0, (%rax)
movl $0x0, 0x28(%rax)
movl $0x0, 0x2c(%rax)
movl $0x0, 0x30(%rax)
movl $0x0, 0x34(%rax)
movl $0x0, 0x38(%rax)
movb $0x0, 0x3c(%rax)
movq $0x0, 0x20(%rax)
movq $0x0, 0x8(%rax)
movl -0xc(%rbp), %ecx
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rdi
callq 0x2140
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movslq -0x34(%rbp), %rcx
cmpq %rcx, %rax
jge 0xb9fd
movq -0x30(%rbp), %rdi
leaq 0x8b00(%rip), %rsi      # 0x14249
callq 0x2060
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0xb839
movq -0x48(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
movl (%rax), %eax
addl -0x38(%rbp), %eax
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x5f10
testb $0x1, %al
jne 0xb794
leaq 0x8896(%rip), %rdi      # 0x14023
movb $0x0, %al
callq 0x2640
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0xb829
movq -0x48(%rbp), %rdx
movq 0x8(%rdx), %rax
movl (%rdx), %ecx
addl -0x3c(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb (%rax,%rcx), %cl
movq 0x8(%rdx), %rax
movl (%rdx), %esi
addl -0x3c(%rbp), %esi
movslq %esi, %rsi
shlq $0x4, %rsi
addq %rsi, %rax
movb %cl, 0x8(%rax)
movq 0x8(%rdx), %rax
movl (%rdx), %ecx
addl -0x3c(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movb $0x0, 0x9(%rax)
movl (%rdx), %ecx
addl -0x3c(%rbp), %ecx
addl $0x1, %ecx
movq 0x8(%rdx), %rax
movl (%rdx), %edx
addl -0x3c(%rbp), %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xb79b
movq -0x48(%rbp), %rax
movl -0x38(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0xb9fd
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
jne 0xb931
movq -0x48(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
movl (%rax), %eax
addl -0x38(%rbp), %eax
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x5f10
testb $0x1, %al
jne 0xb87c
leaq 0x87ae(%rip), %rdi      # 0x14023
movb $0x0, %al
callq 0x2640
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0xb921
movq -0x48(%rbp), %rdx
movq 0x8(%rdx), %rax
movl (%rdx), %ecx
addl -0x40(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movb (%rax,%rcx), %cl
movq 0x8(%rdx), %rax
movl (%rdx), %esi
addl -0x40(%rbp), %esi
movslq %esi, %rsi
shlq $0x4, %rsi
addq %rsi, %rax
movb %cl, 0x8(%rax)
movl -0x40(%rbp), %eax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
sete %cl
movq 0x8(%rdx), %rax
movl (%rdx), %esi
addl -0x40(%rbp), %esi
movslq %esi, %rsi
shlq $0x4, %rsi
addq %rsi, %rax
andb $0x1, %cl
movb %cl, 0x9(%rax)
movl (%rdx), %ecx
addl -0x40(%rbp), %ecx
addl $0x1, %ecx
movq 0x8(%rdx), %rax
movl (%rdx), %edx
addl -0x40(%rbp), %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xb883
movq -0x48(%rbp), %rax
movl -0x38(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0xb9e4
movq -0x48(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
movl (%rax), %eax
addl $0x1, %eax
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x5f10
testb $0x1, %al
jne 0xb95f
leaq 0x86cb(%rip), %rdi      # 0x14023
movb $0x0, %al
callq 0x2640
movq -0x30(%rbp), %rdi
movq -0x30(%rbp), %rsi
movslq -0x38(%rbp), %rax
addq %rax, %rsi
addq $-0x1, %rsi
callq 0x2880
movq %rax, %rdx
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rcx
movslq (%rax), %rsi
shlq $0x4, %rsi
addq %rsi, %rcx
movq %rdx, (%rcx)
movq 0x8(%rax), %rcx
movslq (%rax), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movb $0x0, 0x8(%rcx)
movq -0x30(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl $0x3d, %ecx
sete %dl
movq 0x8(%rax), %rcx
movslq (%rax), %rsi
shlq $0x4, %rsi
addq %rsi, %rcx
andb $0x1, %dl
movb %dl, 0x9(%rcx)
movl (%rax), %edx
addl $0x1, %edx
movq 0x8(%rax), %rcx
movslq (%rax), %rsi
shlq $0x4, %rsi
addq %rsi, %rcx
movl %edx, 0xc(%rcx)
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0xb726
movq -0x48(%rbp), %rdi
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0xba20
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)