// File: /workspace/github_c_makefile_star2_O3/fukunagatsu[P]RIblast/seed_search.cpp
// Function: SeedSearch::CalcInteractionEnergy(std::vector<Hit, std::allocator<Hit>>&, std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&, std::vector<float, std::allocator<float>>&, std::vector<float, std::allocator<float>>&, std::vector<std::vector<float, std::allocator<float>>, std::allocator<std::vector<float, std::allocator<float>>>>&, std::vector<std::vector<float, std::allocator<float>>, std::allocator<std::vector<float, std::allocator<float>>>>&, std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&)
void SeedSearch::CalcInteractionEnergy(vector<Hit> &hit_result, vector<int> &query_suffix_array, vector<int> &db_suffix_array, vector<float> &query_accessibility, vector<float> &query_conditional_accessibility, vector<vector<float> > &db_accessibility,vector<vector<float> > &db_conditional_accessibility, vector<int> &db_seq_length, vector<int> &db_seq_start_position){
  for(int i = 0;i < _hit_candidate_result.size(); i++){
    int sp_q_sa = _hit_candidate_result[i].GetSpQSa();
    int ep_q_sa = _hit_candidate_result[i].GetEpQSa();
    int sp_db_sa = _hit_candidate_result[i].GetSpDbSa();
    int ep_db_sa = _hit_candidate_result[i].GetEpDbSa();
    int length = _hit_candidate_result[i].GetLength();
    double temp_score = _hit_candidate_result[i].GetEnergy();

    vector<int> q_sp_vector; q_sp_vector.reserve(10000);
    vector<double> qa_vector; qa_vector.reserve(10000);
    for(int j = sp_q_sa; j <=ep_q_sa ; j++){
      q_sp_vector.push_back(query_suffix_array[j]);
      qa_vector.push_back(CalcAccessibility(query_accessibility, query_conditional_accessibility, query_suffix_array[j], length));
    }

    for(int k = sp_db_sa; k <=ep_db_sa ; k++){
      int db_sp = db_suffix_array[k];
      int dbseq_start = 0; int dbseq_id = 0;
      GetSeqIdAndStart(db_seq_length, db_seq_start_position, &dbseq_id, &dbseq_start, db_sp, length);
      double dba = CalcAccessibility(db_accessibility[dbseq_id], db_conditional_accessibility[dbseq_id], dbseq_start, length);
      
      for(int j = sp_q_sa; j <= ep_q_sa; j++){
	double interaction_energy = qa_vector[j-sp_q_sa] + dba + temp_score;
	
	if(interaction_energy < 0){
	  Hit temp_hit( q_sp_vector[j-sp_q_sa], db_sp, length, qa_vector[j-sp_q_sa] + dba, temp_score);
	  temp_hit.SetDbSeqId(dbseq_id);
	  temp_hit.SetDbSeqIdStart(dbseq_start);
	  try{
	    hit_result.push_back(temp_hit);
	  }catch(bad_alloc){
	    cerr << "The memory capacity is too small to run RIblast for this dataset" << endl;  
	    exit(1);
	  }
	}
      }
    } 
  }
  return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rcx, 0xa8(%rsp)
movq %rsi, 0xb0(%rsp)
movq 0x30(%rdi), %rax
movq %rdi, 0x68(%rsp)
cmpq %rax, 0x38(%rdi)
je 0x16b23
movq %r9, %r12
movq %r8, %r13
movq %rdx, %rbp
xorl %ebx, %ebx
movq %r9, 0x98(%rsp)
movq %r8, 0x90(%rsp)
movq %rdx, 0x88(%rsp)
movq %rbx, %rcx
shlq $0x5, %rcx
movslq (%rax,%rcx), %rdx
movq %rdx, 0x28(%rsp)
movl 0x4(%rax,%rcx), %edx
movq %rdx, 0x20(%rsp)
movl 0xc(%rax,%rcx), %edx
movl %edx, 0x14(%rsp)
movslq 0x8(%rax,%rcx), %rdx
movq %rdx, 0x70(%rsp)
movslq 0x10(%rax,%rcx), %r14
movsd 0x18(%rax,%rcx), %xmm0
movsd %xmm0, 0x80(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
movl $0x2710, %esi           # imm = 0x2710
leaq 0x50(%rsp), %rdi
callq 0x8732
movq %rbx, 0xa0(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movl $0x2710, %esi           # imm = 0x2710
leaq 0x30(%rsp), %rdi
callq 0x16e36
movq 0x20(%rsp), %rax
cmpl %eax, 0x28(%rsp)
jg 0x16925
movq 0x20(%rsp), %rax
leal 0x1(%rax), %ebx
movq 0x28(%rsp), %r15
leaq (,%r15,4), %rdx
addq (%rbp), %rdx
movq 0x58(%rsp), %rsi
cmpq 0x60(%rsp), %rsi
je 0x16899
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x58(%rsp)
jmp 0x168ab
leaq 0x50(%rsp), %rdi
callq 0x8e4c
movq (%rbp), %rax
movl (%rax,%r15,4), %eax
cltq
movq (%r13), %rcx
xorps %xmm0, %xmm0
cvtss2sd (%rcx,%rax,4), %xmm0
movq 0x68(%rsp), %rcx
movslq 0x24(%rcx), %rcx
cmpl %r14d, %ecx
jge 0x168e3
shlq $0x2, %rax
addq (%r12), %rax
xorps %xmm1, %xmm1
cvtss2sd (%rax,%rcx,4), %xmm1
addsd %xmm1, %xmm0
incq %rcx
cmpq %rcx, %r14
jne 0x168cf
movsd %xmm0, 0xc8(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x16907
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x16919
leaq 0x30(%rsp), %rdi
leaq 0xc8(%rsp), %rdx
callq 0x1703e
incq %r15
cmpl %r15d, %ebx
jne 0x16872
movq 0x70(%rsp), %rcx
cmpl 0x14(%rsp), %ecx
jg 0x16ab5
incl 0x14(%rsp)
movq 0x20(%rsp), %rbp
subl 0x28(%rsp), %ebp
incl %ebp
movq 0xa8(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x70(%rsp)
movl (%rax,%rcx,4), %r9d
xorl %eax, %eax
movl %eax, 0x1c(%rsp)
movl %eax, 0x18(%rsp)
movl %r14d, (%rsp)
movq 0x160(%rsp), %rsi
movq 0x168(%rsp), %rdx
leaq 0x18(%rsp), %rcx
leaq 0x1c(%rsp), %r8
movl %r9d, 0x7c(%rsp)
callq 0x16c48
movl 0x18(%rsp), %r13d
movslq %r13d, %rax
movq 0x150(%rsp), %rcx
movq (%rcx), %rcx
leaq (%rax,%rax,2), %rdx
movl 0x1c(%rsp), %ebx
movslq %ebx, %rax
movq (%rcx,%rdx,8), %rcx
xorps %xmm3, %xmm3
cvtss2sd (%rcx,%rax,4), %xmm3
movq 0x68(%rsp), %rcx
movslq 0x24(%rcx), %rcx
cmpl %r14d, %ecx
jge 0x169e8
movq 0x158(%rsp), %rsi
movq (%rsi), %rsi
shlq $0x2, %rax
addq (%rsi,%rdx,8), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%rcx,4), %xmm0
addsd %xmm0, %xmm3
incq %rcx
cmpq %rcx, %r14
jne 0x169d4
movq 0x20(%rsp), %rax
cmpl %eax, 0x28(%rsp)
jg 0x16aa3
xorl %r12d, %r12d
movsd %xmm3, 0xb8(%rsp)
movq 0x30(%rsp), %rax
movsd (%rax,%r12,8), %xmm0
addsd %xmm3, %xmm0
movsd 0x80(%rsp), %xmm1
addsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x16a97
movq 0x50(%rsp), %rax
movl (%rax,%r12,4), %esi
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
movl 0x7c(%rsp), %edx
movl %r14d, %ecx
movsd 0x80(%rsp), %xmm1
callq 0x16ed2
movl %r13d, 0xc8(%rsp)
movl %ebx, 0xcc(%rsp)
movq 0xb0(%rsp), %rdi
movq %r15, %rsi
callq 0x16f4a
movq 0x100(%rsp), %rdi
testq %rdi, %rdi
je 0x16a8e
movq 0x110(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
movsd 0xb8(%rsp), %xmm3
incq %r12
cmpl %r12d, %ebp
jne 0x16a03
movq 0x70(%rsp), %rcx
incq %rcx
cmpl %ecx, 0x14(%rsp)
jne 0x16943
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x16acc
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
movq 0x98(%rsp), %r12
movq 0x90(%rsp), %r13
movq 0x88(%rsp), %rbp
movq 0xa0(%rsp), %rbx
je 0x16b03
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
incq %rbx
movq 0x68(%rsp), %rcx
movq 0x30(%rcx), %rax
movq 0x38(%rcx), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
cmpq %rbx, %rcx
ja 0x167cb
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x16bed
jmp 0x16b43
jmp 0x16b43
jmp 0x16b43
movq %rax, %rbx
jmp 0x16bd6
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x16bb9
movq %rbx, %rdi
callq 0x32d0
movq 0xd0466(%rip), %rax     # 0xe6fc8
addq $0x10, %rax
movq %rax, 0xc0(%rsp)
movq %rbx, %rdi
callq 0x30f0
movq 0xd0473(%rip), %rdi     # 0xe6ff0
leaq 0x98fd8(%rip), %rsi     # 0xafb5c
movl $0x40, %edx
callq 0x3280
movq 0xd045b(%rip), %rdi     # 0xe6ff0
callq 0x3120
movl $0x1, %edi
callq 0x32a0
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x3150
callq 0x33b0
movq 0x100(%rsp), %rdi
testq %rdi, %rdi
je 0x16bd6
movq 0x110(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x16bed
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x16c04
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
movq %rbx, %rdi
callq 0x33e0
movq %rax, %rdi
callq 0x4793