// File: /workspace/github_c_makefile_star2_O2/fukunagatsu[P]RIblast/rna_interaction_search.cpp
// Function: RnaInteractionSearch::LoadDatabase(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
void RnaInteractionSearch::LoadDatabase(string db_file_name, int hash_size){
  //load seq file
  ifstream ifs((db_file_name+".seq").c_str(), ios::in | ios::binary);
  if (!ifs){
    cout << "Error: can't open " << db_file_name << ".seq." <<endl;
    exit(1);
  }
  int temp_i = 0;
  ifs.read(reinterpret_cast<char*>(&temp_i), sizeof(int));
  _number_of_db_seq = temp_i;
  vector<int> temp_iv;
  vector<int>::iterator i_it;
  temp_iv.assign(temp_i, 0.0);
  for(i_it=temp_iv.begin();i_it!=temp_iv.end();i_it++){
    ifs.read(reinterpret_cast<char*>(&*i_it),sizeof(int));
  }
  int temp = 0;
  for(int i = 0; i <temp_iv.size(); i++){
    _db_seq_start_position.push_back(temp);
    temp += temp_iv[i]+1;
    _db_seq_length.push_back(temp_iv[i]);
  }
  
  int count = 0;
  vector<unsigned char>::iterator c_it;
  ifs.read(reinterpret_cast<char*>(&count), sizeof(int));
  
  _db_seq.resize(count);
  for(c_it=_db_seq.begin();c_it!=_db_seq.end();c_it++){
    ifs.read(reinterpret_cast<char*>(&*c_it),sizeof(unsigned char));
  }
  ifs.close();
  double length_count = 0;
  for(int i= 0; i<_db_seq.size();i++){
    if(_db_seq[i] == 0){
      _db_seq_length_without_repeat.push_back(length_count);
      length_count = 0;
    }else if(_db_seq[i]>=2 && _db_seq[i]<=5){
      length_count++;
    }
  }
  _db_seq_length_without_repeat.push_back(length_count);
  //load acc file
  ifs.open((db_file_name+".acc").c_str(), ios::in | ios::binary);
  if (!ifs){
    cout << "Error: can't open " << db_file_name << ".acc." <<endl;
    exit(1);
  }
  for(int i = 0; i < _number_of_db_seq; i++){
    int a_count = 0;
    vector<float>::iterator it;
    vector <float> temp;
    vector <float> c_temp;
    ifs.read(reinterpret_cast<char*>(&a_count), sizeof(int));
    temp.assign(a_count, 0.0);
    for(it=temp.begin();it!=temp.end();it++){
      ifs.read(reinterpret_cast<char*>(&*it),sizeof(float));
    }
    ifs.read(reinterpret_cast<char*>(&a_count), sizeof(int));
    c_temp.assign(a_count, 0.0);
    for(it=c_temp.begin();it!=c_temp.end();it++){
      ifs.read(reinterpret_cast<char*>(&*it),sizeof(float));
    }
    _db_accessibility.push_back(temp);
    _db_conditional_accessibility.push_back(c_temp);
  }
  ifs.close();

  //load nam file
  ifs.open((db_file_name+".nam").c_str(), ios::in);
  if (!ifs){
    cout << "Error: can't open " << db_file_name << ".nam." <<endl;
    exit(1);
  }
  string str;
  while(getline(ifs, str)){
    _db_seq_name.push_back(str);
  }
  ifs.close();

  //load ind file
  ifs.open((db_file_name+".ind").c_str(), ios::in | ios::binary);
  if (!ifs){
    cout << "Error: can't open " << db_file_name << ".ind." <<endl;
    exit(1);
  }
  count = 0;
  vector<int>::iterator it;
  ifs.read(reinterpret_cast<char*>(&count), sizeof(int));
  
  _db_suffix_array.resize(count);
  for(it=_db_suffix_array.begin();it!=_db_suffix_array.end();it++){
    ifs.read(reinterpret_cast<char*>(&*it),sizeof(int));
  }
  for(int i = 0; i < hash_size; i++){
    for(it=_start_hash[i].begin();it!=_start_hash[i].end();it++){
      ifs.read(reinterpret_cast<char*>(&*it),sizeof(int));
    }
  }
  
  for(int i = 0; i < hash_size; i++){
    for(it=_end_hash[i].begin();it!=_end_hash[i].end();it++){
      ifs.read(reinterpret_cast<char*>(&*it),sizeof(int));
    }
  }
  ifs.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2a8, %rsp            # imm = 0x2A8
movq %rdx, 0x40(%rsp)
movq %rdi, %r14
leaq 0xa480(%rip), %rdx      # 0x16868
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %rsi, 0x8(%rsp)
callq 0x653c
movq (%rbx), %rsi
leaq 0xa0(%rsp), %rdi
pushq $0xc
popq %rdx
callq 0x33c0
leaq 0x20(%rsp), %rdi
callq 0x3100
movq 0xa0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xc0(%rsp,%rax)
jne 0xc967
leaq 0x4c(%rsp), %rsi
andl $0x0, (%rsi)
leaq 0xa0(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x3290
movslq 0x4c(%rsp), %rsi
movl %esi, 0xf0(%r14)
xorpd %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x20(%rsp), %rdx
andl $0x0, (%rdx)
callq 0xf40e
movq 0x50(%rsp), %r13
leaq 0xa0(%rsp), %rbx
pushq $0x4
popq %r15
cmpq 0x58(%rsp), %r13
je 0xc4a0
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3290
addq $0x4, %r13
jmp 0xc485
leaq 0x1c(%rsp), %rax
andl $0x0, (%rax)
leaq 0xa8(%r14), %r15
leaq 0xc0(%r14), %r12
xorl %ebp, %ebp
xorl %ebx, %ebx
subq 0x50(%rsp), %r13
sarq $0x2, %r13
cmpq %rbx, %r13
jbe 0xc502
movq %r15, %rdi
leaq 0x1c(%rsp), %rsi
callq 0x651e
movq 0x50(%rsp), %rsi
movl (%rsi,%rbp), %eax
addq %rbp, %rsi
movl 0x1c(%rsp), %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x1c(%rsp)
movq %r12, %rdi
callq 0x651e
incq %rbx
movq 0x58(%rsp), %r13
addq $0x4, %rbp
jmp 0xc4ba
leaq 0x18(%rsp), %rsi
andl $0x0, (%rsi)
leaq 0xa0(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x3290
leaq 0x60(%r14), %rdi
movslq 0x18(%rsp), %rsi
callq 0xdbdc
movq 0x60(%r14), %rbx
leaq 0xa0(%rsp), %r15
pushq $0x1
popq %r12
cmpq 0x68(%r14), %rbx
je 0xc551
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x3290
incq %rbx
jmp 0xc538
leaq 0xa0(%rsp), %rdi
callq 0x3060
leaq 0xd8(%r14), %rbx
xorpd %xmm0, %xmm0
xorl %r12d, %r12d
leaq 0x20(%rsp), %r15
movq 0x60(%r14), %rax
movq 0x68(%r14), %rcx
subq %rax, %rcx
cmpq %r12, %rcx
jbe 0xc5bd
movb (%rax,%r12), %al
testb %al, %al
je 0xc5a1
cmpb $0x1, %al
sete %cl
cmpb $0x6, %al
setae %al
orb %cl, %al
jne 0xc5b8
addsd 0x3b3c1(%rip), %xmm0    # 0x47960
jmp 0xc5b8
cvttsd2si %xmm0, %eax
movl %eax, 0x20(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe63c
xorpd %xmm0, %xmm0
incq %r12
jmp 0xc571
cvttsd2si %xmm0, %eax
leaq 0x20(%rsp), %rsi
movl %eax, (%rsi)
movq %rbx, %rdi
callq 0xe63c
leaq 0xa2c3(%rip), %rdx      # 0x1689a
leaq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x653c
movq 0x20(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
pushq $0xc
popq %rdx
callq 0x3150
leaq 0x20(%rsp), %rdi
callq 0x3100
movq 0xa0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xc0(%rsp,%rax)
jne 0xc9a3
leaq 0x18(%r14), %rax
movq %rax, 0x98(%rsp)
xorl %ebx, %ebx
leaq 0xa0(%rsp), %r13
pushq $0x4
popq %r15
leaq 0x70(%rsp), %rbp
cmpl 0xf0(%r14), %ebx
jge 0xc735
andl $0x0, 0x4(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movapd %xmm0, 0x70(%rsp)
andq $0x0, 0x80(%rsp)
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
movq %r15, %rdx
callq 0x3290
movslq 0x4(%rsp), %rsi
andl $0x0, 0x14(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x14(%rsp), %rdx
callq 0xf604
movq 0x20(%rsp), %r12
cmpq 0x28(%rsp), %r12
je 0xc6b8
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3290
addq $0x4, %r12
jmp 0xc69d
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
movq %r15, %rdx
callq 0x3290
movslq 0x4(%rsp), %rsi
andl $0x0, 0x14(%rsp)
movq %rbp, %rdi
leaq 0x14(%rsp), %rdx
callq 0xf604
movq 0x70(%rsp), %r12
cmpq 0x78(%rsp), %r12
je 0xc6ff
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3290
addq $0x4, %r12
jmp 0xc6e4
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
callq 0xdc08
movq 0x98(%rsp), %rdi
movq %rbp, %rsi
callq 0xdc08
movq %rbp, %rdi
callq 0x47e2
leaq 0x20(%rsp), %rdi
callq 0x47e2
incl %ebx
jmp 0xc63e
leaq 0xa0(%rsp), %rdi
callq 0x3060
leaq 0xa12e(%rip), %rdx      # 0x16877
leaq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x653c
movq 0x20(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x3150
leaq 0x20(%rsp), %rdi
callq 0x3100
movq 0xa0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xc0(%rsp,%rax)
jne 0xc9dc
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x30(%r14), %rbx
leaq 0xa0(%rsp), %r15
leaq 0x20(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x3050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0xc7d9
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4f44
jmp 0xc7b3
leaq 0xa0(%rsp), %rdi
callq 0x3060
leaq 0xa080(%rip), %rdx      # 0x1686d
leaq 0x70(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x653c
movq 0x70(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
pushq $0xc
popq %rdx
callq 0x3150
leaq 0x70(%rsp), %rdi
callq 0x3100
movq 0xa0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xc0(%rsp,%rax)
jne 0xca15
leaq 0x18(%rsp), %rsi
andl $0x0, (%rsi)
leaq 0xa0(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x3290
leaq 0x48(%r14), %rdi
movslq 0x18(%rsp), %rsi
callq 0x6456
movq 0x48(%r14), %rbx
leaq 0xa0(%rsp), %r15
pushq $0x4
popq %r12
cmpq 0x50(%r14), %rbx
je 0xc885
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x3290
addq $0x4, %rbx
jmp 0xc86b
xorl %r13d, %r13d
movq 0x40(%rsp), %rax
testl %eax, %eax
cmovlel %r13d, %eax
movq %rax, 0x40(%rsp)
leaq 0xa0(%rsp), %rbx
pushq $0x4
popq %r15
cmpq 0x40(%rsp), %r13
je 0xc8db
movq 0x78(%r14), %rax
imulq $0x18, %r13, %rbp
movq (%rax,%rbp), %r12
cmpq 0x8(%rax,%rbp), %r12
je 0xc8d6
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3290
addq $0x4, %r12
movq 0x78(%r14), %rax
jmp 0xc8b7
incq %r13
jmp 0xc8a4
xorl %r13d, %r13d
leaq 0xa0(%rsp), %rbx
pushq $0x4
popq %r15
cmpq 0x40(%rsp), %r13
je 0xc927
movq 0x90(%r14), %rax
imulq $0x18, %r13, %rbp
movq (%rax,%rbp), %r12
cmpq 0x8(%rax,%rbp), %r12
je 0xc922
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3290
addq $0x4, %r12
movq 0x90(%r14), %rax
jmp 0xc900
incq %r13
jmp 0xc8ea
leaq 0xa0(%rsp), %rdi
callq 0x3060
leaq 0x20(%rsp), %rdi
callq 0x3100
leaq 0x50(%rsp), %rdi
callq 0x4632
leaq 0xa0(%rsp), %rdi
callq 0x30a0
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xd6662(%rip), %rdi     # 0xe2fd0
leaq 0x3b322(%rip), %rsi     # 0x47c97
callq 0x31e0
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x31c0
leaq 0x3b31c(%rip), %rsi     # 0x47caa
movq %rax, %rdi
callq 0x31e0
movq %rax, %rdi
callq 0x3110
jmp 0xca4c
movq 0xd6626(%rip), %rdi     # 0xe2fd0
leaq 0x3b2e6(%rip), %rsi     # 0x47c97
callq 0x31e0
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x31c0
leaq 0x3b2e6(%rip), %rsi     # 0x47cb0
movq %rax, %rdi
callq 0x31e0
movq %rax, %rdi
callq 0x3110
jmp 0xca4c
movq 0xd65ed(%rip), %rdi     # 0xe2fd0
leaq 0x3b2ad(%rip), %rsi     # 0x47c97
callq 0x31e0
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x31c0
leaq 0x3b2b3(%rip), %rsi     # 0x47cb6
movq %rax, %rdi
callq 0x31e0
movq %rax, %rdi
callq 0x3110
jmp 0xca4c
movq 0xd65b4(%rip), %rdi     # 0xe2fd0
leaq 0x3b274(%rip), %rsi     # 0x47c97
callq 0x31e0
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x31c0
leaq 0x3b280(%rip), %rsi     # 0x47cbc
movq %rax, %rdi
callq 0x31e0
movq %rax, %rdi
callq 0x3110
pushq $0x1
popq %rdi
callq 0x3250
jmp 0xca73
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x3100
jmp 0xcaa9
jmp 0xcaa6
jmp 0xcaa6
jmp 0xca9b
jmp 0xcaa6
jmp 0xca9b
jmp 0xca9b
jmp 0xca9b
movq %rax, %rbx
jmp 0xcad8
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x3100
jmp 0xcae5
jmp 0xcaa6
jmp 0xca9b
jmp 0xcaa6
jmp 0xca9b
jmp 0xca9b
jmp 0xcaa6
jmp 0xcab7
jmp 0xcab7
jmp 0xca9b
jmp 0xca9b
movq %rax, %rbx
jmp 0xcace
jmp 0xcaa6
jmp 0xcab7
jmp 0xcaa6
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x3100
jmp 0xcace
jmp 0xcab7
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x47e2
leaq 0x20(%rsp), %rdi
callq 0x47e2
leaq 0x50(%rsp), %rdi
callq 0x4632
leaq 0xa0(%rsp), %rdi
callq 0x30a0
movq %rbx, %rdi
callq 0x33a0
nop