// File: /workspace/github_c_makefile_star2_O2/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 $0x108, %rsp            # imm = 0x108
movq %r9, 0x88(%rsp)
movq %r8, 0x80(%rsp)
movq %rcx, 0x78(%rsp)
movq %rdx, %r12
movq %rsi, 0xa0(%rsp)
movq %rdi, 0x18(%rsp)
xorl %r14d, %r14d
xorpd %xmm0, %xmm0
leaq 0xb8(%rsp), %rbx
movq %rdx, 0x70(%rsp)
movq 0x18(%rsp), %rcx
movq 0x30(%rcx), %rax
movq 0x38(%rcx), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
cmpq %r14, %rcx
jbe 0x10e6b
movq %r14, %rcx
shlq $0x5, %rcx
movslq (%rax,%rcx), %rdx
movq %rdx, 0x28(%rsp)
movslq 0x4(%rax,%rcx), %rbp
movslq 0x8(%rax,%rcx), %r13
movslq 0xc(%rax,%rcx), %rdx
movq %rdx, 0x90(%rsp)
movl 0x10(%rax,%rcx), %edx
movl %edx, 0xc(%rsp)
movsd 0x18(%rax,%rcx), %xmm1
movsd %xmm1, 0x20(%rsp)
movapd %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
movl $0x2710, %esi           # imm = 0x2710
leaq 0x50(%rsp), %rdi
callq 0x6488
movq %r14, 0x68(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
movl $0x2710, %esi           # imm = 0x2710
leaq 0x30(%rsp), %rdi
callq 0x110f6
movq 0x28(%rsp), %r15
leaq (,%r15,4), %r14
cmpq %rbp, %r15
jg 0x10e38
movq (%r12), %rsi
addq %r14, %rsi
leaq 0x50(%rsp), %rdi
callq 0x651e
movq (%r12), %rax
movl (%rax,%r14), %ecx
movq 0x18(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movl 0xc(%rsp), %r8d
callq 0x10f24
movsd %xmm0, 0xb8(%rsp)
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x112de
incq %r15
addq $0x4, %r14
jmp 0x10c96
movq 0x78(%rsp), %rax
movq (%rax), %rax
movq %r13, 0x98(%rsp)
movl (%rax,%r13,4), %r13d
andl $0x0, 0x14(%rsp)
andl $0x0, 0x10(%rsp)
movl 0xc(%rsp), %ebx
movl %ebx, (%rsp)
movq 0x150(%rsp), %rsi
movq 0x158(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x14(%rsp), %r8
movl %r13d, %r9d
callq 0x10f54
movslq 0x10(%rsp), %r15
imulq $0x18, %r15, %rdx
movq 0x140(%rsp), %rax
movq (%rax), %rsi
addq %rdx, %rsi
movq 0x148(%rsp), %rax
addq (%rax), %rdx
movl 0x14(%rsp), %r14d
movq 0x18(%rsp), %rdi
movl %r14d, %ecx
movl %ebx, %r8d
callq 0x10f24
movsd 0x20(%rsp), %xmm1
movapd %xmm0, %xmm4
xorl %r12d, %r12d
movsd %xmm0, 0xa8(%rsp)
movq 0x28(%rsp), %rax
addq %r12, %rax
cmpq %rbp, %rax
jg 0x10e20
movq 0x30(%rsp), %rax
movsd (%rax,%r12,8), %xmm0
addsd %xmm4, %xmm0
movapd %xmm1, %xmm3
addsd %xmm0, %xmm3
xorpd %xmm2, %xmm2
ucomisd %xmm3, %xmm2
jbe 0x10e18
movq 0x50(%rsp), %rax
movl (%rax,%r12,4), %esi
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
movl %r13d, %edx
movl 0xc(%rsp), %ecx
callq 0x1118c
movl %r15d, 0xb8(%rsp)
movl %r14d, 0xbc(%rsp)
movq 0xa0(%rsp), %rdi
movq %rbx, %rsi
callq 0x111ee
leaq 0xf0(%rsp), %rdi
callq 0xe77e
movsd 0x20(%rsp), %xmm1
movsd 0xa8(%rsp), %xmm4
incq %r12
jmp 0x10d8a
movq 0x98(%rsp), %r13
incq %r13
movq 0x70(%rsp), %r12
leaq 0xb8(%rsp), %rbx
cmpq 0x90(%rsp), %r13
jle 0x10cf6
leaq 0x30(%rsp), %rdi
callq 0x6a68
leaq 0x50(%rsp), %rdi
callq 0x4632
movq 0x68(%rsp), %r14
incq %r14
xorpd %xmm0, %xmm0
jmp 0x10bf2
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x10f0a
jmp 0x10e8b
jmp 0x10e8b
jmp 0x10e8b
movq %rax, %r14
jmp 0x10f00
movq %rax, %r14
cmpl $0x1, %edx
jne 0x10ef3
movq %r14, %rdi
callq 0x3280
movq 0xd2121(%rip), %rax     # 0xe2fc8
addq $0x10, %rax
movq %rax, 0xb0(%rsp)
movq %r14, %rdi
callq 0x30e0
movq 0xd212e(%rip), %rdi     # 0xe2ff0
leaq 0x98ad3(%rip), %rsi     # 0xa999c
callq 0x31e0
movq %rax, %rdi
callq 0x3110
pushq $0x1
popq %rdi
callq 0x3250
movq %rax, %r14
leaq 0xb0(%rsp), %rdi
callq 0x3140
callq 0x3370
leaq 0xf0(%rsp), %rdi
callq 0xe77e
leaq 0x30(%rsp), %rdi
callq 0x6a68
leaq 0x50(%rsp), %rdi
callq 0x4632
movq %r14, %rdi
callq 0x33a0
movq %rax, %rdi
callq 0x4014