// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x618, %rsp            # imm = 0x618
movq %rsi, 0x8(%rsp)
testq %rdi, %rdi
je 0x7fae
movq %rdx, %rbx
movq %rdi, %r14
leaq 0x108(%rsp), %rdi
pushq $0x8
popq %rdx
movq %r14, %rsi
callq 0x3470
leaq 0x180(%rsp), %rdi
callq 0x30a0
testb %al, %al
je 0x7fd1
pushq $0x18
popq %rdi
callq 0x3260
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rax, (%rsp)
andq $0x0, 0x10(%rax)
leaq 0xf8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x8(%rsp), %rax
andl $0x0, (%rax)
xorl %r14d, %r14d
leaq 0x490(%rsp), %r12
pushq $0x9
popq %rbp
leaq 0xc8(%rsp), %r13
leaq 0x310(%rsp), %r15
leaq 0x108(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x3080
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x7e3b
movq 0xe8(%rsp), %rax
cmpb $0x23, (%rax)
je 0x7b22
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
andq $0x0, 0x18(%rsp)
movb %r14b, 0x20(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
andq $0x0, 0x38(%rsp)
movb %r14b, 0x40(%rsp)
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
andq $0x0, 0x58(%rsp)
movb %r14b, 0x60(%rsp)
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
andq $0x0, 0x78(%rsp)
movb %r14b, 0x80(%rsp)
leaq 0xa0(%rsp), %rax
movq %rax, 0x90(%rsp)
andq $0x0, 0x98(%rsp)
movb %r14b, 0xa0(%rsp)
movl $0x10001, 0xc0(%rsp) # imm = 0x10001
movq %r12, %rdi
leaq 0xe8(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x33c0
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
movl %ebp, %edx
callq 0x3480
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
movl %ebp, %edx
callq 0x3480
movq %r12, %rdi
leaq 0x50(%rsp), %rsi
movl %ebp, %edx
callq 0x3480
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
movl %ebp, %edx
callq 0x3480
movq %r12, %rdi
leaq 0x90(%rsp), %rsi
movl %ebp, %edx
callq 0x3480
testq %rbx, %rbx
je 0x7c67
movq 0x30(%rsp), %rax
xorl %ecx, %ecx
movb (%rbx,%rcx), %dl
testb %dl, %dl
je 0x7c67
movb (%rax,%rcx), %sil
cmpb %sil, %dl
jne 0x7c5e
incq %rcx
jmp 0x7c49
testb %sil, %sil
jne 0x7e24
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rsi
movzbl -0x1(%rax,%rsi), %eax
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
ja 0x7c9a
movzwl %ax, %eax
addl $-0x30, %eax
movw %ax, 0xc0(%rsp)
addq $-0x2, %rsi
leaq 0x50(%rsp), %rdi
callq 0x3330
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rsi
movzbl -0x1(%rax,%rsi), %eax
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
ja 0x7cd2
movzwl %ax, %eax
addl $-0x30, %eax
movw %ax, 0xc2(%rsp)
addq $-0x2, %rsi
leaq 0x70(%rsp), %rdi
callq 0x3330
movq 0x78(%rsp), %rsi
movl 0x98(%rsp), %eax
movl %eax, 0xb8(%rsp)
movq 0x58(%rsp), %rcx
movl %ecx, 0xb0(%rsp)
movl %esi, 0xb4(%rsp)
testl %eax, %eax
setne %al
testl %ecx, %ecx
setne %cl
andb %al, %cl
testl %esi, %esi
setne %al
testb %al, %cl
jne 0x7d38
movq 0x72e1(%rip), %rdi      # 0xeff0
leaq 0x30c0(%rip), %rsi      # 0xadd6
callq 0x3240
movq %rax, %rdi
callq 0x3130
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3220
movq %rax, %rdi
callq 0x3130
movq 0x50(%rsp), %rdi
callq 0x7a3c
testb %al, %al
je 0x7f1f
movq 0x70(%rsp), %rdi
callq 0x7a3c
testb %al, %al
je 0x7e6b
movq 0x90(%rsp), %rdi
callq 0x7a60
testb %al, %al
je 0x7f65
leaq 0xd8(%rsp), %rax
movq %rax, 0xc8(%rsp)
andq $0x0, 0xd0(%rsp)
movb $0x0, 0xd8(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x3480
movq %r15, %rdi
movq %r13, %rsi
pushq $0x8
popq %rdx
callq 0x3400
movq %r15, %rdi
leaq 0xbc(%rsp), %rsi
callq 0x3370
movq %r15, %rdi
callq 0x3120
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x3480
movq %r15, %rdi
movq %r13, %rsi
pushq $0x8
popq %rdx
callq 0x3400
movq %r15, %rdi
leaq 0xbe(%rsp), %rsi
callq 0x3370
movq %r15, %rdi
callq 0x3120
cmpw $0x0, 0xbc(%rsp)
je 0x7eb4
movq (%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x8086
movq 0x8(%rsp), %rax
incl (%rax)
movq %r13, %rdi
callq 0x3110
movq %r12, %rdi
callq 0x31c0
leaq 0x10(%rsp), %rdi
callq 0x80b6
jmp 0x7b22
leaq 0xe8(%rsp), %rdi
callq 0x3110
leaq 0x108(%rsp), %rdi
callq 0x30b0
movq (%rsp), %rax
addq $0x618, %rsp            # imm = 0x618
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x717e(%rip), %rdi      # 0xeff0
leaq 0x2f81(%rip), %rsi      # 0xadfa
callq 0x3240
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x3220
leaq 0x2f6f(%rip), %rsi      # 0xae01
movq %rax, %rdi
callq 0x3240
movq %rax, %rdi
leaq 0x70(%rsp), %rsi
callq 0x3220
movq %rax, %rdi
callq 0x3130
jmp 0x7fc9
movq 0x7135(%rip), %rdi      # 0xeff0
leaq 0x2f38(%rip), %rsi      # 0xadfa
callq 0x3240
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x3220
leaq 0x2f64(%rip), %rsi      # 0xae3f
movq %rax, %rdi
callq 0x3240
movzwl 0xbc(%rsp), %esi
movq %rax, %rdi
callq 0x33f0
leaq 0x2319(%rip), %rsi      # 0xa213
movq %rax, %rdi
callq 0x3240
movzwl 0xbe(%rsp), %esi
movq %rax, %rdi
callq 0x33f0
movq %rax, %rdi
callq 0x3130
jmp 0x7fc9
movq 0x70ca(%rip), %rdi      # 0xeff0
leaq 0x2ecd(%rip), %rsi      # 0xadfa
callq 0x3240
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x3220
leaq 0x2ebb(%rip), %rsi      # 0xae01
movq %rax, %rdi
callq 0x3240
movq %rax, %rdi
leaq 0x50(%rsp), %rsi
callq 0x3220
movq %rax, %rdi
callq 0x3130
jmp 0x7fc9
movq 0x7084(%rip), %rdi      # 0xeff0
leaq 0x2e87(%rip), %rsi      # 0xadfa
callq 0x3240
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x3220
leaq 0x2e91(%rip), %rsi      # 0xae1d
movq %rax, %rdi
callq 0x3240
movq %rax, %rdi
leaq 0x90(%rsp), %rsi
callq 0x3220
movq %rax, %rdi
callq 0x3130
jmp 0x7fc9
movq 0x703b(%rip), %rdi      # 0xeff0
leaq 0x2dde(%rip), %rsi      # 0xad9a
callq 0x3240
movq %rax, %rdi
callq 0x3130
pushq $0x1
popq %rdi
callq 0x32e0
movq 0x7018(%rip), %rdi      # 0xeff0
leaq 0x2d15(%rip), %rsi      # 0xacf4
callq 0x3240
movq %rax, %rdi
movq %r14, %rsi
callq 0x3240
leaq 0x2dd3(%rip), %rsi      # 0xadc9
movq %rax, %rdi
callq 0x3240
movq %rax, %rdi
callq 0x3130
jmp 0x7fc9
jmp 0x800a
movq %rax, %rbx
jmp 0x8070
jmp 0x8037
jmp 0x8037
jmp 0x8017
jmp 0x8037
movq %rax, %rbx
leaq 0x310(%rsp), %rdi
callq 0x3120
jmp 0x803a
movq %rax, %rbx
jmp 0x8059
movq %rax, %rbx
jmp 0x8063
jmp 0x8049
jmp 0x8049
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x3110
jmp 0x804c
movq %rax, %rbx
leaq 0x490(%rsp), %rdi
callq 0x31c0
leaq 0x10(%rsp), %rdi
callq 0x80b6
leaq 0xe8(%rsp), %rdi
callq 0x3110
leaq 0x108(%rsp), %rdi
callq 0x30b0
movq %rbx, %rdi
callq 0x3440
nop