// File: Ahhgust[P]STRaitRazor/parseConfig.cpp
// Function: parseConfig(char*, unsigned int*, char*)
vector<Config>*
parseConfig(char *file, unsigned *numStrs, char *filt) {


  if (file==NULL) {
    cerr << "Empty filename for the config file detected..." << endl;
    exit(EXIT_FAILURE);
  }


  ifstream myfile(file);
  
  if (! myfile.is_open() ) {
    cerr << "Failed to open " << file << " for reading" << endl;
    exit(EXIT_FAILURE);
  }
  
  vector<Config> *c = new vector<Config>;

  string line;
  *numStrs=0;
  
  while (getline(myfile, line)) {
    if (line[0] == COMMENT)
      continue;

    Config conf;
    conf.forwardCount=1; // defaults
    conf.reverseCount=1;

    stringstream ss(line);

    getline(ss, conf.locusName, SEP);
    getline(ss, conf.markerType, SEP);
    getline(ss, conf.forwardFlank, SEP);
    getline(ss, conf.reverseFlank, SEP);
    getline(ss, conf.strMotif, SEP);

    if (filt != NULL) {
      const char *type = conf.markerType.c_str();
      const char *f = filt;
      while (*f && *type) {
	if (*f != *type)
	  break;

	++f;
	++type;
      }
      if (*f && *type)
	continue; // grab the next record from the configuration file
    }

    // quantifier is tacked to the end
    // assume it's, EG:
    // GGATTTCCCCC,2   
    char lastChar = conf.forwardFlank[ conf.forwardFlank.length() -1];
    if (lastChar >= '0' && lastChar <= '9') {
      conf.forwardCount = lastChar - '0';
      conf.forwardFlank.resize( conf.forwardFlank.length() - 2);
    }

    lastChar = conf.reverseFlank[ conf.reverseFlank.length() -1];

    if (lastChar >= '0' && lastChar <= '9') {
      conf.reverseCount = lastChar - '0';
      conf.reverseFlank.resize( conf.reverseFlank.length() - 2);
    }

    conf.motifLength = conf.strMotif.length();
    conf.forwardLength = conf.forwardFlank.length();
    conf.reverseLength = conf.reverseFlank.length();

    if (conf.motifLength < 1 || conf.forwardLength < 1 || conf.reverseLength < 1) {
      cerr << "Problem with the lengths for locus:" << endl <<
	conf.locusName << endl;
    }
    
    if (! validDNAWithAmbiguities( conf.forwardFlank.c_str() ) ) {
	cerr << "Locus " << conf.locusName << " has illegal characters in " <<
	  conf.forwardFlank << endl;
	exit(EXIT_FAILURE);
    }


    if (! validDNAWithAmbiguities( conf.reverseFlank.c_str() ) ) {
	cerr << "Locus " << conf.locusName << " has illegal characters in " <<
	  conf.reverseFlank << endl;
	exit(EXIT_FAILURE);
    }
      
    if (! validDNA( conf.strMotif.c_str() ) ) {
	cerr << "Locus " << conf.locusName << " has illegal characters in motif " <<
	  conf.strMotif << endl;
	exit(EXIT_FAILURE);
    }

    // parsing integers (period and offset)
    string s;
    getline(ss, s, SEP);
    istringstream(s)  >>   conf.motifPeriod;

    getline(ss, s, SEP);
    istringstream(s)  >>   conf.motifOffset;

    if (conf.motifPeriod < 1) {
      cerr << "Locus " << conf.locusName << " has illegal spacing characteristics " <<
	conf.motifPeriod << "\t" << conf.motifOffset  << endl;
	exit(EXIT_FAILURE);
    }

    c->push_back(conf);

    ++(*numStrs);
  }

  
  return c;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x910, %rsp            # imm = 0x910
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0xf5ea
movq 0xca2b(%rip), %rdi      # 0x1bff0
leaq 0x5769(%rip), %rsi      # 0x14d35
callq 0x3290
movq %rax, %rdi
movq 0xc9dd(%rip), %rsi      # 0x1bfb8
callq 0x32e0
movl $0x1, %edi
callq 0x3330
movq -0x8(%rbp), %rsi
leaq -0x220(%rbp), %rdi
movq %rdi, -0x7e0(%rbp)
movl $0x8, %edx
callq 0x34d0
movq -0x7e0(%rbp), %rdi
callq 0x3420
movb %al, -0x7d1(%rbp)
jmp 0xf61a
movb -0x7d1(%rbp), %al
testb $0x1, %al
jne 0xf6b1
jmp 0xf62a
movq 0xc9bf(%rip), %rdi      # 0x1bff0
leaq 0x5657(%rip), %rsi      # 0x14c8f
callq 0x3290
movq %rax, -0x7e8(%rbp)
jmp 0xf646
movq -0x7e8(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x3290
movq %rax, -0x7f0(%rbp)
jmp 0xf65f
movq -0x7f0(%rbp), %rdi
leaq 0x56f7(%rip), %rsi      # 0x14d64
callq 0x3290
movq %rax, -0x7f8(%rbp)
jmp 0xf67b
movq -0x7f8(%rbp), %rdi
movq 0xc92f(%rip), %rsi      # 0x1bfb8
callq 0x32e0
jmp 0xf690
movl $0x1, %edi
callq 0x3330
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x10009
movl $0x18, %edi
callq 0x32b0
movq %rax, -0x800(%rbp)
jmp 0xf6c4
movq -0x800(%rbp), %rdi
callq 0x10030
movq -0x800(%rbp), %rax
movq %rax, -0x238(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x3380
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
leaq -0x220(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x3090
movq %rax, -0x808(%rbp)
jmp 0xf710
movq -0x808(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3340
movb %al, -0x809(%rbp)
jmp 0xf72e
movb -0x809(%rbp), %al
testb $0x1, %al
jne 0xf73d
jmp 0xffbd
xorl %eax, %eax
movl %eax, %esi
leaq -0x258(%rbp), %rdi
callq 0x3520
movq %rax, -0x818(%rbp)
jmp 0xf756
movq -0x818(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0xf77e
jmp 0xf6f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0xfffd
leaq -0x310(%rbp), %rdi
callq 0x10050
movw $0x1, -0x260(%rbp)
movw $0x1, -0x25e(%rbp)
movl $0x10, %edi
movl $0x8, %esi
callq 0x100b0
movl %eax, -0x81c(%rbp)
jmp 0xf7b3
movl -0x81c(%rbp), %edx
leaq -0x498(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x3410
jmp 0xf7ce
leaq -0x498(%rbp), %rdi
leaq -0x310(%rbp), %rsi
movl $0x9, %edx
callq 0x34e0
jmp 0xf7e8
leaq -0x2f0(%rbp), %rsi
leaq -0x498(%rbp), %rdi
movl $0x9, %edx
callq 0x34e0
jmp 0xf802
leaq -0x2d0(%rbp), %rsi
leaq -0x498(%rbp), %rdi
movl $0x9, %edx
callq 0x34e0
jmp 0xf81c
leaq -0x2b0(%rbp), %rsi
leaq -0x498(%rbp), %rdi
movl $0x9, %edx
callq 0x34e0
jmp 0xf836
leaq -0x290(%rbp), %rsi
leaq -0x498(%rbp), %rdi
movl $0x9, %edx
callq 0x34e0
jmp 0xf850
cmpq $0x0, -0x18(%rbp)
je 0xf94a
leaq -0x310(%rbp), %rdi
addq $0x20, %rdi
callq 0x3100
movq %rax, -0x4a0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x4a8(%rbp)
movq -0x4a8(%rbp), %rcx
xorl %eax, %eax
cmpb $0x0, (%rcx)
movb %al, -0x81d(%rbp)
je 0xf8a4
movq -0x4a0(%rbp), %rax
cmpb $0x0, (%rax)
setne %al
movb %al, -0x81d(%rbp)
movb -0x81d(%rbp), %al
testb $0x1, %al
jne 0xf8b0
jmp 0xf921
movq -0x4a8(%rbp), %rax
movsbl (%rax), %eax
movq -0x4a0(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0xf8f8
jmp 0xf921
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0xffaf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0xffa3
movq -0x4a8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4a8(%rbp)
movq -0x4a0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4a0(%rbp)
jmp 0xf87d
movq -0x4a8(%rbp), %rax
cmpb $0x0, (%rax)
je 0xf948
movq -0x4a0(%rbp), %rax
cmpb $0x0, (%rax)
je 0xf948
movl $0x2, -0x4ac(%rbp)
jmp 0xff69
jmp 0xf94a
leaq -0x2d0(%rbp), %rdi
movq %rdi, -0x830(%rbp)
callq 0x33d0
movq -0x830(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x3520
movq %rax, -0x828(%rbp)
jmp 0xf978
movq -0x828(%rbp), %rax
movb (%rax), %al
movb %al, -0x4ad(%rbp)
movsbl -0x4ad(%rbp), %eax
cmpl $0x30, %eax
jl 0xf9da
movsbl -0x4ad(%rbp), %eax
cmpl $0x39, %eax
jg 0xf9da
movsbl -0x4ad(%rbp), %eax
addl $-0x30, %eax
movw %ax, -0x260(%rbp)
leaq -0x2d0(%rbp), %rdi
movq %rdi, -0x838(%rbp)
callq 0x33d0
movq -0x838(%rbp), %rdi
movq %rax, %rsi
addq $-0x2, %rsi
callq 0x3370
jmp 0xf9d8
jmp 0xf9da
leaq -0x2b0(%rbp), %rdi
movq %rdi, -0x848(%rbp)
callq 0x33d0
movq -0x848(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x3520
movq %rax, -0x840(%rbp)
jmp 0xfa08
movq -0x840(%rbp), %rax
movb (%rax), %al
movb %al, -0x4ad(%rbp)
movsbl -0x4ad(%rbp), %eax
cmpl $0x30, %eax
jl 0xfa6a
movsbl -0x4ad(%rbp), %eax
cmpl $0x39, %eax
jg 0xfa6a
movsbl -0x4ad(%rbp), %eax
addl $-0x30, %eax
movw %ax, -0x25e(%rbp)
leaq -0x2b0(%rbp), %rdi
movq %rdi, -0x850(%rbp)
callq 0x33d0
movq -0x850(%rbp), %rdi
movq %rax, %rsi
addq $-0x2, %rsi
callq 0x3370
jmp 0xfa68
jmp 0xfa6a
leaq -0x310(%rbp), %rdi
addq $0x80, %rdi
callq 0x33d0
movl %eax, -0x268(%rbp)
leaq -0x310(%rbp), %rdi
addq $0x40, %rdi
callq 0x33d0
movl %eax, -0x270(%rbp)
leaq -0x310(%rbp), %rdi
addq $0x60, %rdi
callq 0x33d0
movl %eax, -0x26c(%rbp)
cmpl $0x1, -0x268(%rbp)
jb 0xfaca
cmpl $0x1, -0x270(%rbp)
jb 0xfaca
cmpl $0x1, -0x26c(%rbp)
jae 0xfb35
movq 0xc51f(%rip), %rdi      # 0x1bff0
leaq 0x5299(%rip), %rsi      # 0x14d71
callq 0x3290
movq %rax, -0x858(%rbp)
jmp 0xfae6
movq -0x858(%rbp), %rdi
movq 0xc4c4(%rip), %rsi      # 0x1bfb8
callq 0x32e0
movq %rax, -0x860(%rbp)
jmp 0xfb02
movq -0x860(%rbp), %rdi
leaq -0x310(%rbp), %rsi
callq 0x3270
movq %rax, -0x868(%rbp)
jmp 0xfb1e
movq -0x868(%rbp), %rdi
movq 0xc48c(%rip), %rsi      # 0x1bfb8
callq 0x32e0
jmp 0xfb33
jmp 0xfb35
leaq -0x310(%rbp), %rdi
addq $0x40, %rdi
callq 0x3100
movq %rax, %rdi
callq 0xf490
testb $0x1, %al
jne 0xfbe4
movq 0xc494(%rip), %rdi      # 0x1bff0
leaq 0x5232(%rip), %rsi      # 0x14d95
callq 0x3290
movq %rax, -0x870(%rbp)
jmp 0xfb71
movq -0x870(%rbp), %rdi
leaq -0x310(%rbp), %rsi
callq 0x3270
movq %rax, -0x878(%rbp)
jmp 0xfb8d
movq -0x878(%rbp), %rdi
leaq 0x5201(%rip), %rsi      # 0x14d9c
callq 0x3290
movq %rax, -0x880(%rbp)
jmp 0xfba9
movq -0x880(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x3270
movq %rax, -0x888(%rbp)
jmp 0xfbc5
movq -0x888(%rbp), %rdi
movq 0xc3e5(%rip), %rsi      # 0x1bfb8
callq 0x32e0
jmp 0xfbda
movl $0x1, %edi
callq 0x3330
leaq -0x310(%rbp), %rdi
addq $0x60, %rdi
callq 0x3100
movq %rax, %rdi
callq 0xf490
testb $0x1, %al
jne 0xfc93
movq 0xc3e5(%rip), %rdi      # 0x1bff0
leaq 0x5183(%rip), %rsi      # 0x14d95
callq 0x3290
movq %rax, -0x890(%rbp)
jmp 0xfc20
movq -0x890(%rbp), %rdi
leaq -0x310(%rbp), %rsi
callq 0x3270
movq %rax, -0x898(%rbp)
jmp 0xfc3c
movq -0x898(%rbp), %rdi
leaq 0x5152(%rip), %rsi      # 0x14d9c
callq 0x3290
movq %rax, -0x8a0(%rbp)
jmp 0xfc58
movq -0x8a0(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0x3270
movq %rax, -0x8a8(%rbp)
jmp 0xfc74
movq -0x8a8(%rbp), %rdi
movq 0xc336(%rip), %rsi      # 0x1bfb8
callq 0x32e0
jmp 0xfc89
movl $0x1, %edi
callq 0x3330
leaq -0x310(%rbp), %rdi
addq $0x80, %rdi
callq 0x3100
movq %rax, %rdi
callq 0xf540
testb $0x1, %al
jne 0xfd45
movq 0xc333(%rip), %rdi      # 0x1bff0
leaq 0x50d1(%rip), %rsi      # 0x14d95
callq 0x3290
movq %rax, -0x8b0(%rbp)
jmp 0xfcd2
movq -0x8b0(%rbp), %rdi
leaq -0x310(%rbp), %rsi
callq 0x3270
movq %rax, -0x8b8(%rbp)
jmp 0xfcee
movq -0x8b8(%rbp), %rdi
leaq 0x50bc(%rip), %rsi      # 0x14db8
callq 0x3290
movq %rax, -0x8c0(%rbp)
jmp 0xfd0a
movq -0x8c0(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x3270
movq %rax, -0x8c8(%rbp)
jmp 0xfd26
movq -0x8c8(%rbp), %rdi
movq 0xc284(%rip), %rsi      # 0x1bfb8
callq 0x32e0
jmp 0xfd3b
movl $0x1, %edi
callq 0x3330
leaq -0x4d0(%rbp), %rdi
movq %rdi, -0x8d0(%rbp)
callq 0x3380
movq -0x8d0(%rbp), %rsi
leaq -0x498(%rbp), %rdi
movl $0x9, %edx
callq 0x34e0
jmp 0xfd72
leaq -0x650(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
movl $0x8, %edx
callq 0x3460
jmp 0xfd8c
leaq -0x264(%rbp), %rsi
leaq -0x650(%rbp), %rdi
callq 0x100d0
jmp 0xfda1
leaq -0x650(%rbp), %rdi
callq 0x3130
leaq -0x498(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
movl $0x9, %edx
callq 0x34e0
jmp 0xfdc7
leaq -0x7d0(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
movl $0x8, %edx
callq 0x3460
jmp 0xfde1
leaq -0x262(%rbp), %rsi
leaq -0x7d0(%rbp), %rdi
callq 0x100d0
jmp 0xfdf6
leaq -0x7d0(%rbp), %rdi
callq 0x3130
movzwl -0x264(%rbp), %eax
cmpl $0x1, %eax
jge 0xff33
movq 0xc1d7(%rip), %rdi      # 0x1bff0
leaq 0x4f75(%rip), %rsi      # 0x14d95
callq 0x3290
movq %rax, -0x8d8(%rbp)
jmp 0xfe2e
movq -0x8d8(%rbp), %rdi
leaq -0x310(%rbp), %rsi
callq 0x3270
movq %rax, -0x8e0(%rbp)
jmp 0xfe4a
movq -0x8e0(%rbp), %rdi
leaq 0x4f82(%rip), %rsi      # 0x14dda
callq 0x3290
movq %rax, -0x8e8(%rbp)
jmp 0xfe66
movq -0x8e8(%rbp), %rdi
movzwl -0x264(%rbp), %esi
callq 0x3450
movq %rax, -0x8f0(%rbp)
jmp 0xfe82
movq -0x8f0(%rbp), %rdi
leaq 0x431e(%rip), %rsi      # 0x141ae
callq 0x3290
movq %rax, -0x8f8(%rbp)
jmp 0xfe9e
movq -0x8f8(%rbp), %rdi
movzwl -0x262(%rbp), %esi
callq 0x3450
movq %rax, -0x900(%rbp)
jmp 0xfeba
movq -0x900(%rbp), %rdi
movq 0xc0f0(%rip), %rsi      # 0x1bfb8
callq 0x32e0
jmp 0xfecf
movl $0x1, %edi
callq 0x3330
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0xff97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x650(%rbp), %rdi
callq 0x3130
jmp 0xff97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x7d0(%rbp), %rdi
callq 0x3130
jmp 0xff97
movq -0x238(%rbp), %rdi
leaq -0x310(%rbp), %rsi
callq 0x10100
jmp 0xff48
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
leaq -0x4d0(%rbp), %rdi
callq 0x31b0
movl $0x0, -0x4ac(%rbp)
leaq -0x498(%rbp), %rdi
callq 0x31f0
leaq -0x310(%rbp), %rdi
callq 0x10170
movl -0x4ac(%rbp), %eax
testl %eax, %eax
je 0xff92
jmp 0xff8d
jmp 0xf6f4
jmp 0xf6f4
leaq -0x4d0(%rbp), %rdi
callq 0x31b0
leaq -0x498(%rbp), %rdi
callq 0x31f0
leaq -0x310(%rbp), %rdi
callq 0x10170
jmp 0xfffd
movq -0x238(%rbp), %rax
movq %rax, -0x908(%rbp)
movl $0x1, -0x4ac(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x31b0
leaq -0x220(%rbp), %rdi
callq 0x30b0
movq -0x908(%rbp), %rax
addq $0x910, %rsp            # imm = 0x910
popq %rbp
retq
leaq -0x258(%rbp), %rdi
callq 0x31b0
leaq -0x220(%rbp), %rdi
callq 0x30b0
movq -0x228(%rbp), %rdi
callq 0x34a0
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)