// File: /workspace/github_cpp_makefile_star2_O1/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 %rdx, %r14
movq %rsi, %rbx
movq 0x9773(%rip), %rax      # 0xefa0
movq (%rax), %rax
movq %rax, 0x10(%rdx)
xorl %r13d, %r13d
movq %r13, 0x18(%rdx)
movq %r13, (%rdx)
movl $0x1, 0x20(%rdx)
movb $0x1, 0x27(%rdx)
movq %r13, 0x28(%rdx)
movw $0x0, 0x8(%rdx)
movw $0x1, 0x25(%rdx)
movb $0x0, 0xa(%rdx)
cmpl $0x2, %edi
jl 0x5f57
leal -0x1(%rdi), %eax
movl %eax, 0x14(%rsp)
movl $0x1, %r12d
xorl %r13d, %r13d
leaq 0x57e3(%rip), %r8       # 0xb060
movq %rdi, 0x8(%rsp)
movslq %r12d, %r15
movq (%rbx,%r15,8), %rax
cmpb $0x2d, (%rax)
jne 0x5f5e
movzbl 0x1(%rax), %eax
leal -0x61(%rax), %ecx
cmpl $0x15, %ecx
ja 0x5b7b
movslq (%r8,%rcx,4), %rax
addq %r8, %rax
jmpq *%rax
cmpl 0x14(%rsp), %r12d
jne 0x5c03
movq 0x9733(%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 0x60f5(%rip), %rsi      # 0xb9eb
jmp 0x5d96
movb $0x1, 0x5(%r14)
jmp 0x5dfc
incl %r12d
movq 0x8(%rbx,%r15,8), %rax
movq %rax, 0x28(%r14)
testq %rax, %rax
jne 0x5dfc
movl $0x1e, %edx
movq 0x96ca(%rip), %r15      # 0xeff0
movq %r15, %rdi
leaq 0x5f96(%rip), %rsi      # 0xb8c6
callq 0x3310
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
jmp 0x5de0
movb $0x1, 0x4(%r14)
jmp 0x5dfc
cmpl 0x14(%rsp), %r12d
jne 0x5bf2
movq 0x9680(%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 0x6265(%rip), %rsi      # 0xbc0e
jmp 0x5d96
movb $0x1, 0x7(%r14)
jmp 0x5dfc
cmpl 0x14(%rsp), %r12d
jne 0x5c6f
movq 0x9626(%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 0x61a8(%rip), %rsi      # 0xbbab
jmp 0x5d96
cmpl 0x14(%rsp), %r12d
jne 0x5cfe
movq 0x95d6(%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 0x5ec6(%rip), %rsi      # 0xb919
jmp 0x5d96
movb $0x1, 0x9(%r14)
jmp 0x5dfc
movb $0x2, 0xa(%r14)
leal 0x1(%r12), %ebp
movq 0x8(%rbx,%r15,8), %rax
testq %rax, %rax
je 0x5f61
cmpb $0x0, 0x1(%rax)
jne 0x5dfc
movzbl (%rax), %eax
cmpl $0x64, %eax
jg 0x5f35
cmpl $0x45, %eax
je 0x5f4d
cmpl $0x58, %eax
je 0x5f43
jmp 0x5dfc
cmpl 0x14(%rsp), %r12d
jne 0x5e11
movq 0x9537(%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 0x5ff4(%rip), %rsi      # 0xbae6
jmp 0x5d96
movb $0x1, 0x6(%r14)
jmp 0x5dfc
cmpl 0x14(%rsp), %r12d
jne 0x5e98
movq 0x94dd(%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 $0x31, %edx
movq %rax, %rdi
leaq 0x5d99(%rip), %rsi      # 0xb8e5
callq 0x3310
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r13, %rdi
jmp 0x5ee7
movb $0x1, 0x8(%r14)
jmp 0x5dfc
cmpl $0x2d, %eax
je 0x5f5e
movq 0x9465(%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 0x6078(%rip), %rsi      # 0xbc3d
callq 0x3310
movq (%rbx,%r15,8), %r13
testq %r13, %r13
je 0x5eb2
movq %r13, %rdi
callq 0x3130
movq %rbp, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x3310
jmp 0x5ecc
incl %r12d
movq 0x8(%rbx,%r15,8), %rax
movq %rax, 0x18(%r14)
jmp 0x5dfc
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 0x5dfc
movq 0x93bf(%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 0x5dfa(%rip), %rsi      # 0xba64
jmp 0x5e74
movq 0x8(%rbx,%r15,8), %rax
movl $0x0, 0x20(%r14)
movb (%rax), %cl
leal -0x30(%rcx), %edx
movq %rax, %rbp
cmpb $0x9, %dl
ja 0x5cad
xorl %edx, %edx
movq %rax, %rbp
leal (%rdx,%rdx,4), %edx
addb $-0x30, %cl
movzbl %cl, %ecx
leal (%rcx,%rdx,2), %edx
movl %edx, 0x20(%r14)
movb 0x1(%rbp), %cl
incq %rbp
leal -0x30(%rcx), %esi
cmpb $0xa, %sil
jb 0x5c8e
incl %r12d
cmpq %rax, %rbp
jne 0x5dfc
movq 0x9330(%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 0x5ef1(%rip), %rsi      # 0xbbea
jmp 0x5d80
movq 0x8(%rbx,%r15,8), %rax
movb (%rax), %cl
leal -0x30(%rcx), %edx
movq %rax, %rbp
cmpb $0x9, %dl
ja 0x5d34
movl (%r14), %edx
movq %rax, %rbp
leal (%rdx,%rdx,4), %edx
addb $-0x30, %cl
movzbl %cl, %ecx
leal (%rcx,%rdx,2), %edx
movl %edx, (%r14)
movb 0x1(%rbp), %cl
incq %rbp
leal -0x30(%rcx), %esi
cmpb $0xa, %sil
jb 0x5d16
incl %r12d
cmpq %rax, %rbp
jne 0x5dfc
movq 0x92a9(%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 0x5bff(%rip), %rsi      # 0xb97f
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 0x526c(%rip), %r8       # 0xb060
movq 0x8(%rsp), %rdi
movb $0x1, %r13b
movl %r12d, %ebp
incl %ebp
movl %ebp, %r12d
cmpl %edi, %ebp
jl 0x5882
jmp 0x5f61
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 0x5dfc
movq 0x91b5(%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 0x5ccb(%rip), %rsi      # 0xbb3f
callq 0x3310
movq %rbp, %rdi
callq 0x3130
movq %r13, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x3310
movq (%r13), %rax
jmp 0x5dc9
incl %r12d
movq 0x8(%rbx,%r15,8), %rdi
leaq 0x5a70(%rip), %rsi      # 0xb917
callq 0x3330
movq %rax, 0x10(%r14)
jmp 0x5f21
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, %ebp
movq 0x8(%rsp), %rdi
leaq 0x5130(%rip), %r8       # 0xb060
jmp 0x5dff
cmpl $0x65, %eax
je 0x5f4d
cmpl $0x78, %eax
jne 0x5dfc
movb $0x2, 0xa(%r14)
jmp 0x5dff
movb $0x1, 0xa(%r14)
jmp 0x5dff
movl $0x1, %ebp
jmp 0x5f61
movl %r12d, %ebp
cmpq $0x0, 0x18(%r14)
jne 0x6005
movq 0x907d(%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, %r15
leaq 0x5caa(%rip), %rsi      # 0xbc4e
movl $0x24, %edx
movq %rax, %rdi
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
movq %rax, %r15
movq (%rax), %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
movb $0x1, %r13b
testb $0x1, %r13b
jne 0x6023
cmpb $0x1, 0x6(%r14)
je 0x6023
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rdi
callq 0x55f7