// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %rax
movl %r8d, 0x4(%rsp)
movq %rcx, %r14
movq %rdi, %r15
movl $0x0, (%rdi)
movq $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
movslq %eax, %rbx
movq %r14, %rbp
movq %rbp, %rax
subq %r14, %rax
cmpq %rbx, %rax
jge 0x820c
movq %rbp, %rdi
leaq 0x6255(%rip), %rsi      # 0xe21e
callq 0x2060
movq %rax, %r13
movslq %r13d, %r12
movzbl (%rbp,%r12), %eax
movslq (%r15), %rsi
movq 0x8(%r15), %rdi
cmpl $0x3a, %eax
je 0x8009
testl %eax, %eax
jne 0x8028
addl %r13d, %esi
je 0x8046
movslq %esi, %rsi
shlq $0x4, %rsi
testq %rdi, %rdi
je 0x8088
callq 0x23d0
jmp 0x8090
addl %r13d, %esi
je 0x805a
movslq %esi, %rsi
shlq $0x4, %rsi
testq %rdi, %rdi
je 0x8104
callq 0x23d0
jmp 0x810c
incq %rsi
testl %esi, %esi
je 0x8071
shlq $0x4, %rsi
testq %rdi, %rdi
je 0x818c
callq 0x23d0
jmp 0x8194
testq %rdi, %rdi
je 0x8050
callq 0x22e0
movq $0x0, 0x8(%r15)
jmp 0x80b0
testq %rdi, %rdi
je 0x8064
callq 0x22e0
movq $0x0, 0x8(%r15)
jmp 0x812c
testq %rdi, %rdi
je 0x807b
callq 0x22e0
movq $0x0, 0x8(%r15)
jmp 0x81b4
movq %rsi, %rdi
callq 0x2330
testq %rax, %rax
setne %cl
je 0x809e
movq %rax, 0x8(%r15)
jmp 0x80b0
testb %cl, %cl
jne 0x80b0
leaq 0x5f77(%rip), %rdi      # 0xe020
xorl %eax, %eax
callq 0x289c
testl %r13d, %r13d
jle 0x80fa
movq 0x8(%r15), %rdx
movslq (%r15), %rsi
movl %r13d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leal 0x1(%rsi), %ecx
shlq $0x4, %rsi
addq %rsi, %rdx
addq $0xc, %rdx
xorl %esi, %esi
movq $0x0, -0xc(%rdx)
movb (%rbp,%rsi), %dil
movb %dil, -0x4(%rdx)
movb $0x0, -0x3(%rdx)
leal (%rcx,%rsi), %edi
movl %edi, (%rdx)
incq %rsi
addq $0x10, %rdx
cmpq %rsi, %rax
jne 0x80d4
addl %r13d, (%r15)
xorl %eax, %eax
jmp 0x8204
movq %rsi, %rdi
callq 0x2330
testq %rax, %rax
setne %cl
je 0x811a
movq %rax, 0x8(%r15)
jmp 0x812c
testb %cl, %cl
jne 0x812c
leaq 0x5efb(%rip), %rdi      # 0xe020
xorl %eax, %eax
callq 0x289c
testl %r13d, %r13d
jle 0x8184
movq 0x8(%r15), %rsi
movslq (%r15), %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addl %r13d, %eax
movl %r13d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leal 0x1(%rdi), %edx
shlq $0x4, %rdi
addq %rdi, %rsi
addq $0xc, %rsi
xorl %edi, %edi
movq $0x0, -0xc(%rsi)
movb (%rbp,%rdi), %r8b
movb %r8b, -0x4(%rsi)
cmpq %rdi, %rax
sete -0x3(%rsi)
leal (%rdx,%rdi), %r8d
movl %r8d, (%rsi)
incq %rdi
addq $0x10, %rsi
cmpq %rdi, %rcx
jne 0x8159
movl (%r15), %ecx
addl %r13d, %ecx
jmp 0x81e9
movq %rsi, %rdi
callq 0x2330
testq %rax, %rax
setne %cl
je 0x81a2
movq %rax, 0x8(%r15)
jmp 0x81b4
testb %cl, %cl
jne 0x81b4
leaq 0x5e73(%rip), %rdi      # 0xe020
xorl %eax, %eax
callq 0x289c
addq %rbp, %r12
leaq -0x1(%r12), %rsi
movq %rbp, %rdi
callq 0x29ac
movq 0x8(%r15), %rdx
movslq (%r15), %rsi
leal 0x1(%rsi), %ecx
shlq $0x4, %rsi
movq %rax, (%rdx,%rsi)
movb $0x0, 0x8(%rdx,%rsi)
cmpb $0x3d, (%r12)
sete 0x9(%rdx,%rsi)
movl %ecx, 0xc(%rdx,%rsi)
shlq $0x20, %r13
movl %ecx, (%r15)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq %r13, %rax
incq %rax
sarq $0x20, %rax
addq %rax, %rbp
movb $0x1, %al
testb %al, %al
jne 0x7fb0
movzbl 0x4(%rsp), %esi
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8228
nop