// File: /workspace/github_cpp_makefile_star2_O3/Ahhgust[P]STRaitRazor/str8.cpp
// Function: parseArgs(int, char**, Options&)
int
parseArgs(int argc, char **argv, Options &opt) {
  
  int i;

  // defaults
  opt.out = stdout;
  opt.verbose=0;
  opt.help=0;
  opt.shortCircuit=0;
  opt.minPrint=0;
  opt.noReverseComplement=0; 
  opt.config=NULL;
  opt.numThreads=1;
  opt.useTrie=1;
  opt.type=NULL;
  opt.includeAnchors=false;
  opt.printHeader=false;
  opt.motifDistance=0;
  opt.distance=1;
  opt.useQuality=NO_QUALITY;

  bool errors=0;
  
  for (i=1; i < argc; ++i) {
    if (argv[i][0] == '-') {
      if (argv[i][1] == 'h') {
        opt.help=1;
      } else if (argv[i][1] == 'd') {
        opt.printHeader=1;
      } else if (argv[i][1] == 's') {
        opt.shortCircuit=1;
      } else if (argv[i][1] == 'v') {
        opt.verbose=1;
      } else if (argv[i][1] == 'i') {
        opt.includeAnchors=true;
      } else if (argv[i][1] == 'q') {
        opt.useQuality=EXPECT_QUALITY;

        // my attempt at an optional argument
        ++i;
        if (argv[i] == NULL)
          break;
        else if (argv[i][1] == '\0') {
          if (argv[i][0] == 'x' || argv[i][0] == 'X') {
            opt.useQuality = EXPECT_QUALITY;
          } else if (argv[i][0] == 'e' || argv[i][0] == 'E') {
            opt.useQuality = EDGAR_QUALITY;
          } else {
            --i;
          }
        } else {
          --i;
        }

        
      } else if (argv[i][1] == 't') {
        // filters the config file by type
        ++i;
        opt.type = argv[i];
        if (opt.type==NULL) {
          cerr << "Oops. -t flag requires a type!" << endl;
          errors=1;
        }
      } else if (argv[i][1] == 'n') {
        opt.noReverseComplement=1; 
      } else if (argv[i][1] == 'o') { // setting output file
        if (i == argc-1) {
          cerr << endl<< "Option -o requires an argument\nEG, -o outFile.txt" << endl << endl;
          errors=1;
        } else {
          ++i;
          opt.out = fopen(argv[i], "w");
        }
      } else if (argv[i][1] == 'f') { // setting min records to print
        if (i == argc-1) {
          cerr << endl << "Option -f requires an integer; the smallest number of haplotype-counts that are allowed to be printed" << endl << endl;
          errors=1;
        } else {
          ++i;
          char *s = argv[i];
          while (*s >= '0' && *s <= '9') {
            opt.minPrint = (opt.minPrint*10)+(*s - '0');
            ++s;
          }
          if (s == argv[i]) {
            cerr << endl << "Option -f requires an integer; the smallest number of haplotype-counts that are allowed to be printed, not " << s  << endl << endl;
            errors=1;
          }
        }
      } else if (argv[i][1] == 'a') { // setting the degeneracy/distance with anchors when constructing the trie
        if (i == argc-1) {
          cerr << endl << "Option -a requires an integer in the range [0,2] (inclusive); the (max) hamming distance used when searching for anchors" << endl << endl;
          errors=1;
        } else {
          ++i;
          char *s = argv[i];
          opt.distance = (*s - '0');
          if (s[1] != 0 || opt.distance > 2) {
            cerr << endl << "Option -a requires a an integer in the range [0,2] (inclusive); the (max) hamming distance used when searching for anchors, not: " << s << endl;
            errors=1;
          }
          //	  cerr << "Distance is " << ((unsigned)opt.distance) << endl;
        }
      } else if (argv[i][1] == 'm') { // setting the degeneracy/distance with motifs when constructing the trie
        if (i == argc-1) {
          cerr << endl << "Option -m requires a 0 or a 1; the (max) hamming distance used when searching for motifs" << endl << endl;
	  errors=1;
        } else {
          ++i;
          char *s = argv[i];
          opt.motifDistance = (*s - '0');
          if (s[1] != 0 || opt.motifDistance > 1) {
            cerr << endl << "Option -m requires a 0 or a 1 (inclusive); the (max) hamming distance used when searching for motifs, not: " << s << endl;
            errors=1;
          }
        }
      } else if (argv[i][1] == 'p') { // setting the number of threads/processors
        if (i == argc-1) {
          cerr << endl << "Option -p requires an integer; the number of processors needed" << endl << endl;
          errors=1;
        } else {
          ++i;
          char *s = argv[i];
          opt.numThreads=0;
          while (*s >= '0' && *s <= '9') {
            opt.numThreads = (opt.numThreads*10)+(*s - '0');
            ++s;
          }
          if (s == argv[i]) {
            cerr << endl << "Option -p requires an integer; not " << s  << endl << endl;
            errors=1;
          }
          
#ifdef NOTHREADS
          
          if (opt.numThreads > 1) {
            cerr << "This program was compiled w/o threads, yet you are trying to use multithreading. You can't do both!" << endl <<
              "Please either recompile this program with threads, or set the number of threads to 1!!" << endl;
            exit(EXIT_FAILURE);
          } 
#endif
          
        }
      } else if (argv[i][1] == 'c') { // this config file
        if (i == argc-1) {
          cerr << endl<< "Option -c requires a file; ie, the config file" << endl << endl;
          errors=1;
        } else {
          ++i;
          opt.config = argv[i];
        }
      } else if (argv[i][1] == '-') { // unix convention; force the end of flags
        break;
      } else {
        cerr << endl <<  "Unknown option: " << argv[i]  << endl << endl;
        errors=1;
      }

    } else
      break;
    
  }
  
  if (opt.config==NULL) {
    cerr << endl <<  "Missing required flag: -c configfile"  << endl << endl;
    errors=1;
  }

  if (errors || opt.help) 
    usage(argv[0]);

  return i;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq 0x97e3(%rip), %rax      # 0xefa0
movq (%rax), %rax
movq %rax, 0x10(%rdx)
xorl %eax, %eax
movq %rax, 0x18(%rdx)
movq %rax, (%rdx)
movl $0x1, 0x20(%rdx)
movb $0x1, 0x27(%rdx)
movq %rax, 0x28(%rdx)
movw $0x0, 0x8(%rdx)
movw $0x1, 0x25(%rdx)
movb $0x0, 0xa(%rdx)
cmpl $0x2, %edi
jl 0x5fe0
movq %rdx, %r14
movl %edi, %ebp
leal -0x1(%rbp), %esi
movl $0x1, %r12d
xorl %r13d, %r13d
leaq 0x5893(%rip), %rdi      # 0xb0a0
movq %rbp, 0x8(%rsp)
movl %esi, 0x4(%rsp)
movslq %r12d, %r15
movq (%rbx,%r15,8), %rax
cmpb $0x2d, (%rax)
jne 0x5fb2
movzbl 0x1(%rax), %eax
leal -0x61(%rax), %ecx
cmpl $0x15, %ecx
ja 0x5bcf
movslq (%rdi,%rcx,4), %rax
addq %rdi, %rax
jmpq *%rax
cmpl %esi, %r12d
jne 0x5c67
movq 0x97a1(%rip), %r15      # 0xeff0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movl $0x78, %edx
movq %rax, %rdi
leaq 0x61a3(%rip), %rsi      # 0xba2b
jmp 0x5a97
movb $0x1, 0x5(%r14)
jmp 0x5c52
incl %r12d
movq 0x8(%rbx,%r15,8), %rax
movq %rax, 0x28(%r14)
testq %rax, %rax
jne 0x5c52
movl $0x1e, %edx
movq 0x9738(%rip), %r15      # 0xeff0
movq %r15, %rdi
leaq 0x6044(%rip), %rsi      # 0xb906
callq 0x3310
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
leaq 0x57ab(%rip), %rdi      # 0xb0a0
movl 0x4(%rsp), %esi
movb $0x1, %r13b
jmp 0x5c52
movb $0x1, 0x4(%r14)
jmp 0x5c52
cmpl %esi, %r12d
jne 0x5c46
movq 0x96d5(%rip), %r15      # 0xeff0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movl $0x2e, %edx
movq %rax, %rdi
leaq 0x62fa(%rip), %rsi      # 0xbc4e
jmp 0x5a97
movb $0x1, 0x7(%r14)
jmp 0x5c52
cmpl %esi, %r12d
jne 0x5cd3
movq 0x967d(%rip), %r15      # 0xeff0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movl $0x3e, %edx
movq %rax, %rdi
leaq 0x623f(%rip), %rsi      # 0xbbeb
jmp 0x5a97
cmpl %esi, %r12d
jne 0x5d19
movq 0x962f(%rip), %r15      # 0xeff0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movl $0x65, %edx
movq %rax, %rdi
leaq 0x5f5f(%rip), %rsi      # 0xb959
jmp 0x5a97
movb $0x1, 0x9(%r14)
jmp 0x5c52
movb $0x2, 0xa(%r14)
leal 0x1(%r12), %eax
movq 0x8(%rbx,%r15,8), %rcx
testq %rcx, %rcx
je 0x5fb5
cmpb $0x0, 0x1(%rcx)
jne 0x5c52
movzbl (%rcx), %ecx
cmpl $0x64, %ecx
jg 0x5f95
cmpl $0x45, %ecx
je 0x5fa8
cmpl $0x58, %ecx
je 0x5c55
jmp 0x5c52
cmpl %esi, %r12d
jne 0x5d57
movq 0x9592(%rip), %r15      # 0xeff0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movl $0x58, %edx
movq %rax, %rdi
leaq 0x608f(%rip), %rsi      # 0xbb26
callq 0x3310
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
leaq 0x55ab(%rip), %rdi      # 0xb0a0
movl 0x4(%rsp), %esi
movb $0x1, %r13b
movl %esi, %eax
jmp 0x5c55
movb $0x1, 0x6(%r14)
jmp 0x5c52
movq %rbx, 0x10(%rsp)
cmpl %esi, %r12d
jne 0x5de2
movq 0x94ce(%rip), %rbx      # 0xeff0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movl $0x31, %edx
movq %rax, %rdi
leaq 0x5dca(%rip), %rsi      # 0xb925
callq 0x3310
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movb $0x1, %r13b
movl 0x4(%rsp), %esi
movl %esi, %eax
movq 0x10(%rsp), %rbx
jmp 0x5e7f
movb $0x1, 0x8(%r14)
jmp 0x5c52
cmpl $0x2d, %eax
je 0x5fb2
movq 0x9411(%rip), %r13      # 0xeff0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %rbp
movl $0x10, %edx
movq %rax, %rdi
leaq 0x6064(%rip), %rsi      # 0xbc7d
callq 0x3310
movq (%rbx,%r15,8), %r13
testq %r13, %r13
je 0x5e04
movq %r13, %rdi
callq 0x3130
movq %rbp, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x3310
jmp 0x5e1e
incl %r12d
movq 0x8(%rbx,%r15,8), %rax
movq %rax, 0x18(%r14)
movl %r12d, %eax
incl %eax
movl %eax, %r12d
cmpl %ebp, %eax
jl 0x5816
jmp 0x5fb5
incl %r12d
movq 0x8(%rbx,%r15,8), %rbp
movb (%rbp), %al
addb $-0x30, %al
movb %al, 0x25(%r14)
cmpb $0x0, 0x1(%rbp)
setne %cl
cmpb $0x3, %al
setae %al
orb %cl, %al
cmpb $0x1, %al
jne 0x5f88
movq 0x935b(%rip), %r15      # 0xeff0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movl $0x81, %edx
movq %rax, %rdi
leaq 0x5dd6(%rip), %rsi      # 0xbaa4
jmp 0x5dbe
incl %r12d
movq 0x8(%rbx,%r15,8), %rbp
movl $0x0, 0x20(%r14)
movb (%rbp), %al
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
ja 0x5e8b
incq %rbp
xorl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
addb $-0x30, %al
movzbl %al, %eax
leal (%rax,%rcx,2), %ecx
movl %ecx, 0x20(%r14)
movb (%rbp), %al
leal -0x30(%rax), %edx
incq %rbp
cmpb $0xa, %dl
jb 0x5cf7
jmp 0x5f88
incl %r12d
movq 0x8(%rbx,%r15,8), %rbp
movb (%rbp), %al
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
ja 0x5ecd
movl (%r14), %ecx
incq %rbp
leal (%rcx,%rcx,4), %ecx
addb $-0x30, %al
movzbl %al, %eax
leal (%rax,%rcx,2), %ecx
movl %ecx, (%r14)
movb (%rbp), %al
leal -0x30(%rax), %edx
incq %rbp
cmpb $0xa, %dl
jb 0x5d36
jmp 0x5f88
incl %r12d
movq 0x8(%rbx,%r15,8), %rbp
movb (%rbp), %al
addb $-0x30, %al
movb %al, 0x26(%r14)
cmpb $0x0, 0x1(%rbp)
setne %cl
cmpb $0x2, %al
setae %al
orb %cl, %al
cmpb $0x1, %al
jne 0x5f88
movq 0x926b(%rip), %r15      # 0xeff0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movl $0x6b, %edx
movq %rax, %rdi
leaq 0x5dc1(%rip), %rsi      # 0xbb7f
callq 0x3310
movq %rbp, %rdi
callq 0x3130
movq %r13, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x3310
movq (%r13), %rax
jmp 0x5f56
incl %r12d
movq 0x10(%rsp), %rbx
movq 0x8(%rbx,%r15,8), %rdi
leaq 0x5b61(%rip), %rsi      # 0xb957
callq 0x3330
movq %rax, 0x10(%r14)
movl %r12d, %eax
jmp 0x5e7b
movq (%rbp), %rax
movq -0x18(%rax), %rax
movq %rbp, %rdi
addq %rax, %rdi
movl 0x20(%rbp,%rax), %esi
orl $0x1, %esi
callq 0x3450
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movb $0x1, %r13b
movl %r12d, %eax
movq 0x8(%rsp), %rbp
movl 0x4(%rsp), %esi
leaq 0x521a(%rip), %rdi      # 0xb0a0
jmp 0x5c55
movq 0x915e(%rip), %r15      # 0xeff0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movl $0x23, %edx
movq %rax, %rdi
leaq 0x5d5f(%rip), %rsi      # 0xbc2a
jmp 0x5f0d
movq 0x911c(%rip), %r15      # 0xeff0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movl $0x6b, %edx
movq %rax, %rdi
leaq 0x5ab2(%rip), %rsi      # 0xb9bf
callq 0x3310
movq %rbp, %rdi
callq 0x3130
movq %r13, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x3310
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
leaq 0x511f(%rip), %rdi      # 0xb0a0
movl 0x4(%rsp), %esi
movb $0x1, %r13b
movl %r12d, %eax
movq 0x8(%rsp), %rbp
jmp 0x5c55
cmpl $0x65, %ecx
je 0x5fa8
cmpl $0x78, %ecx
je 0x5c55
jmp 0x5c52
movb $0x1, 0xa(%r14)
jmp 0x5c55
movl %r12d, %eax
cmpq $0x0, 0x18(%r14)
je 0x5fe0
testb $0x1, %r13b
jne 0x6076
cmpb $0x1, 0x6(%r14)
je 0x6076
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9009(%rip), %r14      # 0xeff0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r14
leaq 0x5c76(%rip), %rsi      # 0xbc8e
movl $0x24, %edx
movq %rax, %rdi
callq 0x3310
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq (%rbx), %rdi
callq 0x558a