// File: readmapping[P]alfalfa/src/fasta.cpp
// Function: load_fasta(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, std::vector<long, std::allocator<long>>&)
void load_fasta(string filename, string &S, vector<string> &descr, vector<long> &startpos) {
  string meta, line;
  long length = 0;

  // Everything starts at zero.
  startpos.push_back(0);

  ifstream data(filename.c_str());

  if(!data.is_open()) { cerr << "unable to open " << filename << endl; exit(1); }

  while(!data.eof()) {
    getline(data, line, '\n'); // Load one line at a time.
    if(line.length() == 0) continue;
    if(line[line.length()-1]=='\r')
        line.erase(--line.end());

    long start = 0, end = line.length() - 1;

    // Meta tag line and start of a new sequence.
    if(line[0] == '>') {
      // Save previous sequence and meta data.
      if(length > 0) {
	descr.push_back(meta);
	S += '`'; // ` character used to separate strings
	startpos.push_back(S.length());
	//lengths.push_back(length+1);
      }
      // Reset parser state.
      start = 1; meta = ""; length = 0;
    }
    trim(line, start, end);
    // Collect meta data.
    if(line[0] == '>') {
      for(long i = start; i <= end; i++) { if(line[i] == ' ') break; meta += line[i]; }
    }
    else { // Collect sequence data.
      length += end - start + 1;
      for(long i = start; i <= end; i++) {
	S += std::tolower(line[i]);
      }
    }
  }
  if(length > 0) {
    descr.push_back(meta);
  }
  cerr << "# full reference length = " << S.length() << endl;
  for(long i = 0; i < (long)descr.size(); i++) {
    cerr << "# " << descr[i] << " " << startpos[i] << endl;
  }
}

// Assembly:
subq $0x388, %rsp            # imm = 0x388
movq %rdi, 0xb0(%rsp)
movq %rdi, 0x380(%rsp)
movq %rsi, 0x378(%rsp)
movq %rdx, 0x370(%rsp)
movq %rcx, 0x368(%rsp)
leaq 0x348(%rsp), %rdi
callq 0x8590
leaq 0x328(%rsp), %rdi
callq 0x8590
movq $0x0, 0x320(%rsp)
movq 0x368(%rsp), %rdi
movq $0x0, 0x318(%rsp)
leaq 0x318(%rsp), %rsi
callq 0x1eaf0
jmp 0x2fd98
movq 0xb0(%rsp), %rdi
callq 0x8170
movq %rax, %rsi
leaq 0x100(%rsp), %rdi
movl $0x8, %edx
callq 0x87a0
jmp 0x2fdbc
leaq 0x100(%rsp), %rdi
callq 0x86a0
movb %al, 0xaf(%rsp)
jmp 0x2fdd2
movb 0xaf(%rsp), %al
testb $0x1, %al
jne 0x2fe7e
jmp 0x2fde3
movq 0x67206(%rip), %rdi     # 0x96ff0
leaq 0x4d522(%rip), %rsi     # 0x7d313
callq 0x8360
movq %rax, 0xa0(%rsp)
jmp 0x2fe00
movq 0xb0(%rsp), %rsi
movq 0xa0(%rsp), %rdi
callq 0x8330
movq %rax, 0x98(%rsp)
jmp 0x2fe1f
movq 0x98(%rsp), %rdi
movq 0x67182(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x2fe35
movl $0x1, %edi
callq 0x84a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x310(%rsp)
movl %eax, 0x30c(%rsp)
jmp 0x3037f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x310(%rsp)
movl %eax, 0x30c(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x8110
jmp 0x3037f
jmp 0x2fe80
movq 0x100(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x100(%rsp,%rax), %rdi
callq 0x87b0
movb %al, 0x97(%rsp)
jmp 0x2fea2
movb 0x97(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2feb4
jmp 0x301f7
leaq 0x100(%rsp), %rdi
leaq 0x328(%rsp), %rsi
movl $0xa, %edx
callq 0x87c0
jmp 0x2fed0
leaq 0x328(%rsp), %rdi
callq 0x8630
cmpq $0x0, %rax
jne 0x2fee5
jmp 0x2fe80
leaq 0x328(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x8630
movq 0x80(%rsp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x8830
movq %rax, 0x88(%rsp)
jmp 0x2ff17
movq 0x88(%rsp), %rax
movsbl (%rax), %eax
cmpl $0xd, %eax
jne 0x2ff84
leaq 0x328(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x81e0
movq %rax, 0xf0(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0xe220
movq %rax, %rsi
leaq 0xf8(%rsp), %rdi
callq 0x31320
movq 0x70(%rsp), %rdi
movq 0xf8(%rsp), %rsi
callq 0x84c0
movq %rax, 0x78(%rsp)
jmp 0x2ff77
movq 0x78(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq $0x0, 0xe0(%rsp)
leaq 0x328(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x8630
movq 0x60(%rsp), %rdi
decq %rax
movq %rax, 0xd8(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x8830
movq %rax, 0x68(%rsp)
jmp 0x2ffc2
movq 0x68(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x3e, %eax
jne 0x3006f
cmpq $0x0, 0x320(%rsp)
jle 0x30041
movq 0x370(%rsp), %rdi
leaq 0x348(%rsp), %rsi
callq 0x1eb20
jmp 0x2fff5
movq 0x378(%rsp), %rdi
movl $0x60, %esi
callq 0x8210
jmp 0x30009
movq 0x368(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x378(%rsp), %rdi
callq 0x8630
movq 0x58(%rsp), %rdi
movq %rax, 0xd0(%rsp)
leaq 0xd0(%rsp), %rsi
callq 0x1eaf0
jmp 0x3003f
jmp 0x30041
movq $0x1, 0xe0(%rsp)
leaq 0x49a0a(%rip), %rsi     # 0x79a5e
leaq 0x348(%rsp), %rdi
callq 0x8570
jmp 0x30063
movq $0x0, 0x320(%rsp)
leaq 0x328(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
callq 0x2fc40
jmp 0x3008e
xorl %eax, %eax
movl %eax, %esi
leaq 0x328(%rsp), %rdi
callq 0x8830
movq %rax, 0x50(%rsp)
jmp 0x300a6
movq 0x50(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x3e, %eax
jne 0x30157
movq 0xe0(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0xc8(%rsp), %rax
cmpq 0xd8(%rsp), %rax
jg 0x30152
movq 0xc8(%rsp), %rsi
leaq 0x328(%rsp), %rdi
callq 0x8830
movq %rax, 0x48(%rsp)
jmp 0x300f5
movq 0x48(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x30104
jmp 0x30152
movq 0xc8(%rsp), %rsi
leaq 0x328(%rsp), %rdi
callq 0x8830
movq %rax, 0x40(%rsp)
jmp 0x30120
movq 0x40(%rsp), %rax
movsbl (%rax), %esi
leaq 0x348(%rsp), %rdi
callq 0x8210
jmp 0x30137
jmp 0x30139
movq 0xc8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xc8(%rsp)
jmp 0x300c7
jmp 0x301f2
movq 0xd8(%rsp), %rax
subq 0xe0(%rsp), %rax
addq $0x1, %rax
addq 0x320(%rsp), %rax
movq %rax, 0x320(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
cmpq 0xd8(%rsp), %rax
jg 0x301f0
movq 0xc0(%rsp), %rsi
leaq 0x328(%rsp), %rdi
callq 0x8830
movq %rax, 0x38(%rsp)
jmp 0x301b9
movq 0x38(%rsp), %rax
movsbl (%rax), %edi
callq 0x85d0
movq 0x378(%rsp), %rdi
movsbl %al, %esi
callq 0x8210
jmp 0x301d8
jmp 0x301da
movq 0xc0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xc0(%rsp)
jmp 0x3018b
jmp 0x301f2
jmp 0x2fe80
cmpq $0x0, 0x320(%rsp)
jle 0x3021b
movq 0x370(%rsp), %rdi
leaq 0x348(%rsp), %rsi
callq 0x1eb20
jmp 0x30219
jmp 0x3021b
movq 0x66dce(%rip), %rdi     # 0x96ff0
leaq 0x4d607(%rip), %rsi     # 0x7d830
callq 0x8360
movq %rax, 0x30(%rsp)
jmp 0x30235
movq 0x378(%rsp), %rdi
callq 0x8630
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x8100
movq %rax, 0x28(%rsp)
jmp 0x30256
movq 0x28(%rsp), %rdi
movq 0x66d4e(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x30269
movq $0x0, 0xb8(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x370(%rsp), %rdi
callq 0xccb0
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jge 0x30350
movq 0x66d49(%rip), %rdi     # 0x96ff0
leaq 0x4d59d(%rip), %rsi     # 0x7d84b
callq 0x8360
movq %rax, 0x18(%rsp)
jmp 0x302ba
movq 0x370(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0xccf0
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x8330
movq %rax, 0x10(%rsp)
jmp 0x302e3
movq 0x10(%rsp), %rdi
leaq 0x4f123(%rip), %rsi     # 0x7f412
callq 0x8360
movq %rax, 0x8(%rsp)
jmp 0x302fb
movq 0x368(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0xccd0
movq 0x8(%rsp), %rdi
movq (%rax), %rsi
callq 0x8790
movq %rax, (%rsp)
jmp 0x30323
movq (%rsp), %rdi
movq 0x66c82(%rip), %rsi     # 0x96fb0
callq 0x83b0
jmp 0x30335
jmp 0x30337
movq 0xb8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb8(%rsp)
jmp 0x30275
leaq 0x100(%rsp), %rdi
callq 0x8110
leaq 0x328(%rsp), %rdi
callq 0x8858
leaq 0x348(%rsp), %rdi
callq 0x8858
addq $0x388, %rsp            # imm = 0x388
retq
leaq 0x328(%rsp), %rdi
callq 0x8858
leaq 0x348(%rsp), %rdi
callq 0x8858
movq 0x310(%rsp), %rdi
callq 0x8730
nopw %cs:(%rax,%rax)