// File: /workspace/github_c_makefile_star2_O3/fukunagatsu[P]RIblast/ungapped_extension.cpp
// Function: UngappedExtension::Run(std::vector<Hit, std::allocator<Hit>>&, std::vector<unsigned char, std::allocator<unsigned char>>&, std::vector<unsigned char, std::allocator<unsigned char>>&, 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>>>>&)
void UngappedExtension::Run(vector<Hit> &candidate, vector<unsigned char> &query_seq, vector<unsigned char> &db_seq, vector<float> &query_accessibility, vector<float> &query_conditional_accessibility, vector<vector<float> > &db_accessibility,vector<vector<float> > &db_conditional_accessibility){
  for(int x = 0; x < candidate.size(); x++){
    double min_energy = candidate[x].GetEnergy();
    double energy = candidate[x].GetEnergy();
    double min_a_energy = candidate[x].GetAccessibilityEnergy();
    double a_energy = candidate[x].GetAccessibilityEnergy();
    double min_h_energy = candidate[x].GetHybridizationEnergy();
    double h_energy = candidate[x].GetHybridizationEnergy();
    
    int i = candidate[x].GetQSp(); int p = candidate[x].GetQSp();
    int j = candidate[x].GetDbSp(); int q = candidate[x].GetDbSp();
    int min_p = p; int min_q = q;
    int db_seq_id = candidate[x].GetDbSeqId();
    int db_seq_id_start = candidate[x].GetDbSeqIdStart(); int db_seq_id_end = db_seq_id_start + candidate[x].GetDbLength()-1;
    int min_db_seq_id_start = db_seq_id_start;
    while(true){
      i--; j--;
      db_seq_id_end++;
      if(i < 0 || j < 0 || query_seq[i] < 2 || db_seq[j] < 2){
	break;
      }
      double temp_accessibility = query_accessibility[i] - query_accessibility[i+1]
					  + query_conditional_accessibility[i+_min_accessible_length]
					  + db_conditional_accessibility[db_seq_id][db_seq_id_end];
      energy += temp_accessibility;
      a_energy += temp_accessibility;
      
      int q_char = query_seq[i] <=5 ? query_seq[i]-1 : query_seq[i]-5;
      int db_char = db_seq[j] <=5 ? db_seq[j]-1 : db_seq[j]-5;
      int type = BP_pair[q_char][db_char];
      if(type!=0){
	int q_char2 = query_seq[p] <=5 ? query_seq[p]-1 : query_seq[p]-5;
	int db_char2 = db_seq[q] <=5 ? db_seq[q]-1 : db_seq[q]-5;
	int type2 = BP_pair[q_char2][db_char2];
	type2 = rtype[type2];
	energy += LoopEnergy(type, type2, i, j, p, q, query_seq, db_seq);
	h_energy += LoopEnergy(type, type2, i, j, p, q, query_seq, db_seq);
	if(energy < min_energy){
	  min_energy = energy;
	  min_a_energy = a_energy;
	  min_h_energy = h_energy;
	  min_p = i;
	  min_q = j;
	}
	
	p = i;
	q = j;
      }
      
      if(min_p-i >= _drop_out_score){
	break;
      }
    }

    energy = min_energy;
    a_energy = min_a_energy;
    h_energy = min_h_energy;
    int k = candidate[x].GetQSp() + candidate[x].GetQLength()-1; int r = candidate[x].GetQSp() + candidate[x].GetQLength()-1;
    int l = candidate[x].GetDbSp() + candidate[x].GetQLength()-1; int s = candidate[x].GetDbSp() + candidate[x].GetQLength()-1;
    int min_r = r; int min_s = s;
    
    while(true){
      k++; l++;
      db_seq_id_start--;
      if(query_seq[k] < 2 || db_seq[l] < 2){
	break;
      }
      double temp_accessibility = query_conditional_accessibility[k] + db_accessibility[db_seq_id][db_seq_id_start]
			- db_accessibility[db_seq_id][db_seq_id_start+1]
			+ db_conditional_accessibility[db_seq_id][db_seq_id_start+_min_accessible_length];
      energy += temp_accessibility;
      a_energy += temp_accessibility;
      
      int q_char2 = query_seq[k] <=5 ? query_seq[k]-1 : query_seq[k]-5;
      int db_char2 = db_seq[l] <=5 ? db_seq[l]-1 : db_seq[l]-5;
      int type2 = BP_pair[q_char2][db_char2];
      type2 = rtype[type2];
      if(type2!=0){
	int q_char = query_seq[r] <=5 ? query_seq[r]-1 : query_seq[r]-5;
	int db_char = db_seq[s] <=5 ? db_seq[s]-1 : db_seq[s]-5;
	int type = BP_pair[q_char][db_char];
	energy += LoopEnergy(type, type2, r, s, k, l, query_seq, db_seq);
	h_energy += LoopEnergy(type, type2, r, s, k, l, query_seq, db_seq);
	
	if(energy < min_energy){
	  min_energy = energy;
	  min_a_energy = a_energy;
	  min_h_energy = h_energy;
	  min_r = k;
	  min_s = l;
	  min_db_seq_id_start = db_seq_id_start;
	}
	r = k;
	s = l;
      }
      if(k-min_r >= _drop_out_score){
	break;
      }
    }
    candidate[x].SetDbSeqIdStart(min_db_seq_id_start);
    candidate[x].SetQSp(min_p);
    candidate[x].SetDbSp(min_q);
    candidate[x].SetQLength(min_r-min_p+1);
    candidate[x].SetDbLength(min_r-min_p+1);
    candidate[x].SetEnergy(min_energy);
    candidate[x].SetAccessibilityEnergy(min_a_energy);
    candidate[x].SetHybridizationEnergy(min_h_energy);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %r9, 0xe0(%rsp)
movq %r8, 0xd8(%rsp)
movq %rcx, 0x88(%rsp)
movq %rdx, 0x28(%rsp)
movq %rdi, 0xd0(%rsp)
movq (%rsi), %rcx
movq 0x8(%rsi), %rax
movq %rcx, 0xc8(%rsp)
subq %rcx, %rax
je 0x15d41
sarq $0x4, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rcx
movq 0x28(%rsp), %rax
movq (%rax), %rax
cmpq $0x1, %rcx
adcq $0x0, %rcx
movq %rcx, 0xc0(%rsp)
movq %rax, 0x110(%rsp)
incq %rax
movq %rax, 0xb8(%rsp)
xorl %eax, %eax
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x698fe(%rip), %r11     # 0x7efc0
movq %rax, 0xf8(%rsp)
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
movq 0xc8(%rsp), %rdx
leaq (%rdx,%rax), %rcx
movq %rcx, 0xa8(%rsp)
movsd 0x28(%rdx,%rax), %xmm4
movsd 0x18(%rdx,%rax), %xmm5
movsd 0x20(%rdx,%rax), %xmm6
movl 0x4(%rdx,%rax), %esi
movl 0x8(%rdx,%rax), %edi
movl 0xc(%rdx,%rax), %r9d
movslq (%rdx,%rax), %rcx
movq %rsi, 0x40(%rsp)
movslq %esi, %r14
movzwl 0x14(%rdx,%rax), %eax
leal -0x1(%r14,%rax), %eax
movq 0x28(%rsp), %rdx
movq (%rdx), %r13
movq 0xd0(%rsp), %rsi
movslq (%rsi), %r8
movq 0xe0(%rsp), %rdx
movq (%rdx), %rbx
leaq (%rcx,%rcx,2), %rdx
shlq $0x3, %rdx
movq 0x158(%rsp), %rcx
movq (%rcx), %rcx
movq %rdx, 0x90(%rsp)
addq %rdx, %rcx
movq %rcx, 0xb0(%rsp)
movslq %edi, %rdx
leaq (,%rdx,4), %r15
movq 0xd8(%rsp), %rcx
addq (%rcx), %r15
movq %r15, 0x58(%rsp)
movslq %eax, %r12
movq %r8, 0xf0(%rsp)
leaq (,%r8,4), %rax
leaq (%rax,%rdx,4), %rax
movq %rbx, 0xe8(%rsp)
addq %rbx, %rax
addq $-0x4, %rax
movq %rax, 0x50(%rsp)
movl %edx, %r15d
negl %r15d
incq %r12
movapd %xmm6, %xmm1
movapd %xmm5, %xmm2
movapd %xmm4, %xmm3
movq 0x88(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movl 0x4(%rsi), %eax
movl %eax, 0x1c(%rsp)
leal -0x1(%rdx), %eax
movq %rax, 0x108(%rsp)
movq %r13, 0x20(%rsp)
movq %rdx, 0x68(%rsp)
leaq -0x1(%r13,%rdx), %rax
movq %rax, 0x60(%rsp)
leal -0x1(%r9), %eax
movq %rax, 0x100(%rsp)
xorl %r13d, %r13d
movl %r9d, 0x18(%rsp)
movl %edi, %eax
movq %rax, 0x78(%rsp)
movl %r9d, %eax
movq %rdi, 0x48(%rsp)
movl %edi, %ecx
movq %r9, 0x10(%rsp)
movq 0x68(%rsp), %rdx
addq %r13, %rdx
testq %rdx, %rdx
jle 0x15a42
leaq (%r9,%r13), %rdx
testl %edx, %edx
jle 0x15a42
movq 0x60(%rsp), %rdx
movzbl (%rdx,%r13), %edx
cmpq $0x2, %rdx
jb 0x15a42
leaq (%r9,%r13), %rsi
decq %rsi
movl %esi, %esi
movq 0x38(%rsp), %rdi
movzbl (%rdi,%rsi), %esi
cmpq $0x2, %rsi
jb 0x15a42
movq 0x58(%rsp), %rdi
movss -0x4(%rdi,%r13,4), %xmm0
subss (%rdi,%r13,4), %xmm0
movq 0x50(%rsp), %rdi
addss (%rdi,%r13,4), %xmm0
movq 0xb0(%rsp), %rdi
movq (%rdi), %rdi
addss (%rdi,%r12,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm0, %xmm4
addsd %xmm0, %xmm5
cmpb $0x6, %dl
movl $0x0, %edi
sbbq %rdi, %rdi
orq %r10, %rdi
addq %rdx, %rdi
cmpb $0x6, %sil
movl $0x0, %edx
sbbq %rdx, %rdx
orq %r10, %rdx
addq %rsi, %rdx
leaq (%rdi,%rdi,4), %rsi
leaq (%r11,%rsi,4), %rsi
movl (%rsi,%rdx,4), %esi
testl %esi, %esi
je 0x15a20
movsd %xmm5, 0x8(%rsp)
movsd %xmm2, 0x30(%rsp)
movsd %xmm1, 0x98(%rsp)
movq 0x108(%rsp), %rdx
leaq (%rdx,%r13), %rbp
movq 0x100(%rsp), %rdx
leaq (%rdx,%r13), %rbx
movslq %ecx, %r9
movq 0x20(%rsp), %rcx
movzbl (%rcx,%r9), %ecx
cmpq $0x6, %rcx
movl $0x0, %edx
sbbq %rdx, %rdx
orq %r10, %rdx
addq %rcx, %rdx
cltq
movq 0x38(%rsp), %rcx
movzbl (%rcx,%rax), %ecx
cmpq $0x6, %rcx
movl $0x0, %edi
sbbq %rdi, %rdi
orq %r10, %rdi
addq %rcx, %rdi
leaq (%rdx,%rdx,4), %rcx
leaq (%r11,%rcx,4), %rcx
movslq (%rcx,%rdi,4), %rcx
leaq 0x696dd(%rip), %rdx     # 0x7f030
movl (%rdx,%rcx,4), %edx
subq $0x8, %rsp
movl %ebp, %ecx
movl %ebx, %r8d
pushq 0x90(%rsp)
pushq 0x38(%rsp)
pushq %rax
movsd %xmm3, 0xc0(%rsp)
movsd %xmm4, 0xa0(%rsp)
movsd %xmm6, 0x90(%rsp)
callq 0x15d54
movsd 0x90(%rsp), %xmm6
movsd 0xa0(%rsp), %xmm4
movsd 0xc0(%rsp), %xmm3
addq $0x20, %rsp
addsd %xmm0, %xmm4
addsd %xmm0, %xmm6
ucomisd %xmm4, %xmm3
jbe 0x159f1
movl %ebx, 0x18(%rsp)
movl %ebp, %eax
movq %rax, 0x78(%rsp)
movl %ebx, %eax
movl %ebp, %ecx
movapd %xmm6, %xmm1
movsd 0x8(%rsp), %xmm5
movapd %xmm5, %xmm2
movapd %xmm4, %xmm3
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x695d6(%rip), %r11     # 0x7efc0
movq 0x10(%rsp), %r9
jmp 0x15a20
movl %ebx, %eax
movl %ebp, %ecx
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x695ba(%rip), %r11     # 0x7efc0
movq 0x10(%rsp), %r9
movsd 0x98(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movsd 0x8(%rsp), %xmm5
decq %r13
movq 0x78(%rsp), %rdx
addl %r15d, %edx
incl %edx
movl %r15d, %esi
incl %esi
incq %r12
movl %esi, %r15d
cmpl 0x1c(%rsp), %edx
jl 0x1581a
movq 0xa8(%rsp), %rax
movzwl 0x10(%rax), %eax
movq 0x48(%rsp), %rsi
leal (%rsi,%rax), %r8d
decl %r8d
movq 0x150(%rsp), %rcx
movq 0x90(%rsp), %rdx
addq (%rcx), %rdx
movq %rdx, 0x90(%rsp)
leal (%r9,%rax), %r12d
decl %r12d
movslq %r8d, %rcx
movslq %r12d, %rdx
addl %eax, %r9d
movq 0x38(%rsp), %rdi
addq %rdi, %rdx
incq %rdx
movq %rdx, 0x70(%rsp)
addl %eax, %esi
movq %rsi, 0x48(%rsp)
movq 0xb8(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x80(%rsp)
movq 0xe8(%rsp), %rax
leaq 0x4(%rax,%rcx,4), %rax
movq %rax, 0x60(%rsp)
movq 0xf0(%rsp), %rax
leaq -0x4(,%rax,4), %rax
movq %rax, 0x58(%rsp)
movq 0x40(%rsp), %rax
leal -0x1(%rax), %r13d
xorl %ebx, %ebx
movsd %xmm1, 0x10(%rsp)
movl %r8d, %eax
movq %r8, 0x68(%rsp)
movl %r8d, %edi
movsd %xmm2, 0x20(%rsp)
movsd %xmm3, 0x8(%rsp)
movq 0x80(%rsp), %rcx
movzbl (%rcx,%rbx), %edx
cmpq $0x2, %rdx
jb 0x15cde
movq 0x70(%rsp), %rcx
movzbl (%rcx,%rbx), %ecx
cmpq $0x2, %rcx
jb 0x15cde
movq 0x60(%rsp), %rsi
movss (%rsi,%rbx,4), %xmm0
movq 0x90(%rsp), %rsi
movq (%rsi), %rsi
addss -0x4(%rsi,%r14,4), %xmm0
subss (%rsi,%r14,4), %xmm0
movq 0xb0(%rsp), %rsi
movq (%rsi), %rsi
addq 0x58(%rsp), %rsi
addss (%rsi,%r14,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm0, %xmm3
addsd %xmm0, %xmm2
cmpb $0x6, %dl
movl $0x0, %esi
sbbq %rsi, %rsi
orq %r10, %rsi
addq %rdx, %rsi
cmpb $0x6, %cl
movl $0x0, %edx
sbbq %rdx, %rdx
orq %r10, %rdx
addq %rcx, %rdx
leaq (%rsi,%rsi,4), %rcx
leaq (%r11,%rcx,4), %rcx
movslq (%rcx,%rdx,4), %rcx
testq %rcx, %rcx
je 0x15cc2
movl %edi, 0x50(%rsp)
movsd %xmm2, 0x30(%rsp)
movq 0x48(%rsp), %rdx
leaq (%rdx,%rbx), %rbp
leaq 0x69474(%rip), %rdx     # 0x7f030
movl (%rdx,%rcx,4), %edx
movslq %eax, %rcx
movq 0x110(%rsp), %rax
movzbl (%rax,%rcx), %eax
cmpq $0x6, %rax
movl $0x0, %esi
sbbq %rsi, %rsi
orq %r10, %rsi
addq %rax, %rsi
movslq %r12d, %r8
movq 0x38(%rsp), %rax
movzbl (%rax,%r8), %eax
cmpq $0x6, %rax
movl $0x0, %edi
sbbq %rdi, %rdi
orq %r10, %rdi
addq %rax, %rdi
leaq (%rsi,%rsi,4), %rax
leaq (%r11,%rax,4), %rax
movl (%rax,%rdi,4), %esi
movq %r9, %r15
leaq (%r9,%rbx), %rax
subq $0x8, %rsp
movl %ebp, %r9d
pushq 0x90(%rsp)
pushq 0x38(%rsp)
movq %rax, %r12
pushq %rax
movsd %xmm1, 0xb8(%rsp)
movsd %xmm3, 0xc0(%rsp)
callq 0x15d54
movsd 0xc0(%rsp), %xmm3
movsd 0xb8(%rsp), %xmm1
addq $0x20, %rsp
addsd %xmm0, %xmm3
addsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
ucomisd %xmm3, %xmm0
jbe 0x15ca2
movl %r13d, %eax
movq %rax, 0x40(%rsp)
movsd %xmm1, 0x10(%rsp)
movl %ebp, %eax
movl %ebp, %edi
movsd 0x30(%rsp), %xmm2
movsd %xmm2, 0x20(%rsp)
movsd %xmm3, 0x8(%rsp)
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x69323(%rip), %r11     # 0x7efc0
movq %r15, %r9
jmp 0x15cc2
movl %ebp, %eax
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x6930b(%rip), %r11     # 0x7efc0
movq %r15, %r9
movsd 0x30(%rsp), %xmm2
movl 0x50(%rsp), %edi
incq %rbx
movq 0x68(%rsp), %rcx
subl %edi, %ecx
addl %ebx, %ecx
decl %r13d
decq %r14
cmpl 0x1c(%rsp), %ecx
jl 0x15afe
movq 0xa8(%rsp), %rax
movq 0x40(%rsp), %rcx
movl %ecx, 0x4(%rax)
movq 0x78(%rsp), %rdx
movl %edx, 0x8(%rax)
movl 0x18(%rsp), %ecx
movl %ecx, 0xc(%rax)
subl %edx, %edi
incl %edi
movl %edi, 0x10(%rax)
movl %edi, 0x14(%rax)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x28(%rax)
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x18(%rax)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x20(%rax)
movq 0xf8(%rsp), %rax
incq %rax
cmpq 0xc0(%rsp), %rax
jne 0x156c2
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop