// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, 0xc(%rsp)
movq %rcx, %r15
movq %rdi, %r14
andl $0x0, (%rdi)
leaq 0x8(%rdi), %rax
movq %rax, (%rsp)
andq $0x0, 0x8(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x2d(%rdi)
movl %esi, 0x10(%rdi)
movq %rdx, 0x18(%rdi)
movq %rcx, %rdi
callq 0x2140
cltq
movq %rax, 0x10(%rsp)
xorl %r13d, %r13d
movq %r15, %rbx
movq %r15, %rax
subq %rbx, %rax
cmpq 0x10(%rsp), %rax
jge 0x785d
movq %r15, %rdi
leaq 0x4b69(%rip), %rsi      # 0xc240
callq 0x2060
movq %rax, %r12
movslq %r12d, %rbp
movzbl (%r15,%rbp), %eax
cmpl $0x3a, %eax
je 0x7751
testl %eax, %eax
je 0x77ee
movslq %r13d, %rsi
shlq $0x4, %rsi
addq $0x10, %rsi
movq (%rsp), %rdi
callq 0x43e9
testb %al, %al
jne 0x771a
leaq 0x490d(%rip), %rdi      # 0xc020
xorl %eax, %eax
callq 0x25ca
addq %r15, %rbp
leaq -0x1(%rbp), %rsi
movq %r15, %rdi
callq 0x2788
movq 0x8(%r14), %rcx
movslq (%r14), %rdx
leal 0x1(%rdx), %r13d
shlq $0x4, %rdx
movq %rax, (%rcx,%rdx)
movb $0x0, 0x8(%rcx,%rdx)
cmpb $0x3d, (%rbp)
sete 0x9(%rcx,%rdx)
movl %r13d, 0xc(%rcx,%rdx)
jmp 0x77d0
addl %r12d, %r13d
movslq %r13d, %rsi
shlq $0x4, %rsi
movq (%rsp), %rdi
callq 0x43e9
testb %al, %al
jne 0x7776
leaq 0x48b1(%rip), %rdi      # 0xc020
xorl %eax, %eax
callq 0x25ca
movq 0x8(%r14), %rsi
movslq (%r14), %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addl %r12d, %eax
testl %r12d, %r12d
movl $0x0, %ecx
cmovgl %r12d, %ecx
leal 0x1(%rdi), %edx
shlq $0x4, %rdi
addq %rdi, %rsi
addq $0xc, %rsi
xorl %edi, %edi
cmpq %rdi, %rcx
je 0x77ca
andq $0x0, -0xc(%rsi)
movb (%r15,%rdi), %r8b
movb %r8b, -0x4(%rsi)
cmpq %rdi, %rax
sete -0x3(%rsi)
leal (%rdx,%rdi), %r8d
movl %r8d, (%rsi)
incq %rdi
addq $0x10, %rsi
jmp 0x77a1
movl (%r14), %r13d
addl %r12d, %r13d
shlq $0x20, %r12
movl %r13d, (%r14)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq %r12, %rax
incq %rax
sarq $0x20, %rax
addq %rax, %r15
jmp 0x76bc
addl %r12d, %r13d
movslq %r13d, %rsi
shlq $0x4, %rsi
movq (%rsp), %rdi
callq 0x43e9
testb %al, %al
jne 0x7813
leaq 0x4814(%rip), %rdi      # 0xc020
xorl %eax, %eax
callq 0x25ca
movq 0x8(%r14), %rsi
xorl %eax, %eax
testl %r12d, %r12d
movl $0x0, %ecx
cmovgl %r12d, %ecx
movslq (%r14), %rdi
leal 0x1(%rdi), %edx
shlq $0x4, %rdi
addq %rdi, %rsi
addq $0xc, %rsi
cmpq %rax, %rcx
je 0x785a
andq $0x0, -0xc(%rsi)
movb (%r15,%rax), %dil
movb %dil, -0x4(%rsi)
movb $0x0, -0x3(%rsi)
leal (%rdx,%rax), %edi
movl %edi, (%rsi)
incq %rax
addq $0x10, %rsi
jmp 0x7836
addl %r12d, (%r14)
movzbl 0xc(%rsp), %esi
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7878