// File: /workspace/github_c_makefile_star2_O1/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 $0x108, %rsp            # imm = 0x108
movq %r9, 0xc0(%rsp)
movq %r8, 0xe8(%rsp)
movq %rcx, 0x50(%rsp)
movq %rdx, 0x38(%rsp)
movq %rdi, 0xb8(%rsp)
movq (%rsi), %rcx
movq 0x8(%rsi), %rax
movq %rcx, 0xe0(%rsp)
subq %rcx, %rax
je 0x13eab
sarq $0x4, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rcx
movq 0x38(%rsp), %rax
movq (%rax), %rax
cmpq $0x1, %rcx
adcq $0x0, %rcx
movq %rcx, 0xd8(%rsp)
movq %rax, 0x100(%rsp)
incq %rax
movq %rax, 0xd0(%rsp)
xorl %eax, %eax
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x6a5ed(%rip), %r11     # 0x7ddf0
movq %rax, 0xf8(%rsp)
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
movq 0xe0(%rsp), %rcx
leaq (%rcx,%rax), %rdx
movq %rdx, 0xc8(%rsp)
movsd 0x28(%rcx,%rax), %xmm4
movsd 0x18(%rcx,%rax), %xmm5
movsd 0x20(%rcx,%rax), %xmm6
movl 0x4(%rcx,%rax), %edx
movl 0x8(%rcx,%rax), %r8d
movl 0xc(%rcx,%rax), %r9d
movslq (%rcx,%rax), %rdi
movq %rdx, 0x68(%rsp)
movslq %edx, %rbx
movzwl 0x14(%rcx,%rax), %eax
leal -0x1(%rbx,%rax), %eax
movq 0x38(%rsp), %rcx
movq (%rcx), %r14
movq 0x50(%rsp), %rcx
movq (%rcx), %rdx
movq 0xb8(%rsp), %rsi
movslq (%rsi), %rcx
movq %rdi, 0xf0(%rsp)
leaq (%rdi,%rdi,2), %r15
movq %rdx, %rdi
shlq $0x3, %r15
movq 0x148(%rsp), %rdx
addq (%rdx), %r15
movq %r15, 0x88(%rsp)
movq 0xc0(%rsp), %rdx
movq (%rdx), %rdx
movl 0x4(%rsi), %esi
movl %esi, 0x4(%rsp)
movslq %eax, %r13
movslq %r8d, %rsi
leaq (,%rsi,4), %r15
movq 0xe8(%rsp), %rax
addq (%rax), %r15
movq %r15, 0x80(%rsp)
shlq $0x2, %rcx
leaq (%rcx,%rsi,4), %rax
addq %rdx, %rax
addq $-0x4, %rax
movq %rax, 0x78(%rsp)
movl %esi, %r12d
negl %r12d
incq %r13
movapd %xmm6, %xmm1
movapd %xmm5, %xmm2
movapd %xmm4, %xmm3
leal -0x1(%rsi), %ebp
movq %r14, 0x70(%rsp)
movq %rsi, 0x98(%rsp)
leaq -0x1(%r14,%rsi), %rax
movq %rax, 0x90(%rsp)
leal -0x1(%r9), %eax
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
movl %r9d, 0x1c(%rsp)
movl %r8d, %eax
movq %rax, 0xa0(%rsp)
movl %r9d, %eax
movl %r8d, %r14d
movq %r9, 0x40(%rsp)
movq %r8, 0x48(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x98(%rsp), %rcx
addq %r15, %rcx
testq %rcx, %rcx
jle 0x13b71
leaq (%r9,%r15), %rcx
testl %ecx, %ecx
jle 0x13b71
movq 0x90(%rsp), %rcx
movzbl (%rcx,%r15), %ecx
cmpq $0x2, %rcx
jb 0x13b71
leaq (%r9,%r15), %rdx
decq %rdx
movl %edx, %edx
movzbl (%rdi,%rdx), %edx
cmpq $0x2, %rdx
jb 0x13b71
movq 0x80(%rsp), %rsi
movss -0x4(%rsi,%r15,4), %xmm0
subss (%rsi,%r15,4), %xmm0
movq 0x78(%rsp), %rsi
addss (%rsi,%r15,4), %xmm0
movq 0x88(%rsp), %rsi
movq (%rsi), %rsi
addss (%rsi,%r13,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm0, %xmm4
addsd %xmm0, %xmm5
cmpb $0x6, %cl
movl $0x0, %esi
sbbq %rsi, %rsi
orq %r10, %rsi
addq %rcx, %rsi
cmpb $0x6, %dl
movl $0x0, %ecx
sbbq %rcx, %rcx
orq %r10, %rcx
addq %rdx, %rcx
leaq (%rsi,%rsi,4), %rdx
leaq (%r11,%rdx,4), %rdx
movl (%rdx,%rcx,4), %esi
testl %esi, %esi
je 0x13b4c
movsd %xmm5, 0x30(%rsp)
movsd %xmm2, 0x60(%rsp)
movsd %xmm1, 0xa8(%rsp)
movslq %r14d, %r9
movq 0x70(%rsp), %rcx
movzbl (%rcx,%r9), %ecx
cmpq $0x6, %rcx
movl $0x0, %edx
sbbq %rdx, %rdx
orq %r10, %rdx
addq %rcx, %rdx
cltq
movzbl (%rdi,%rax), %ecx
cmpq $0x6, %rcx
movl $0x0, %edi
sbbq %rdi, %rdi
movq 0x20(%rsp), %r8
leaq (%r8,%r15), %r14
orq %r10, %rdi
addq %rcx, %rdi
leaq (%rdx,%rdx,4), %rcx
leaq (%r11,%rcx,4), %rcx
movslq (%rcx,%rdi,4), %rcx
leaq 0x6a3f1(%rip), %rdx     # 0x7de60
movl (%rdx,%rcx,4), %edx
leaq (%r15,%rbp), %rcx
subq $0x8, %rsp
movq %rcx, 0x30(%rsp)
movl %r14d, %r8d
pushq 0x58(%rsp)
pushq 0x48(%rsp)
pushq %rax
movsd %xmm3, 0xd0(%rsp)
movsd %xmm4, 0x78(%rsp)
movsd %xmm6, 0x30(%rsp)
callq 0x13ebe
movsd 0x30(%rsp), %xmm6
movsd 0x78(%rsp), %xmm4
movsd 0xd0(%rsp), %xmm3
addq $0x20, %rsp
addsd %xmm0, %xmm4
addsd %xmm0, %xmm6
ucomisd %xmm4, %xmm3
jbe 0x13b0f
leal (%r15,%rbp), %eax
movq %rax, 0xa0(%rsp)
movl %r14d, %eax
movl %r14d, 0x1c(%rsp)
movapd %xmm6, %xmm1
movsd 0x30(%rsp), %xmm5
movapd %xmm5, %xmm2
movapd %xmm4, %xmm3
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x6a2ed(%rip), %r11     # 0x7ddf0
movq 0x48(%rsp), %r8
movq 0x40(%rsp), %r9
jmp 0x13b42
movl %r14d, %eax
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x6a2cd(%rip), %r11     # 0x7ddf0
movq 0x48(%rsp), %r8
movq 0x40(%rsp), %r9
movsd 0xa8(%rsp), %xmm1
movsd 0x60(%rsp), %xmm2
movsd 0x30(%rsp), %xmm5
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %r14
decq %r15
movq 0xa0(%rsp), %rcx
addl %r12d, %ecx
incl %ecx
movl %r12d, %edx
incl %edx
incq %r13
movl %edx, %r12d
cmpl 0x4(%rsp), %ecx
jl 0x13947
movq 0xc8(%rsp), %rax
movzwl 0x10(%rax), %eax
leal (%r8,%rax), %r15d
decl %r15d
leal -0x1(%r9,%rax), %edi
movq 0x50(%rsp), %rcx
movq (%rcx), %r14
movq 0xc0(%rsp), %rcx
movq (%rcx), %rcx
movq 0xf0(%rsp), %rdx
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rsi
movq 0x140(%rsp), %rdx
movq (%rdx), %rdx
addq %rsi, %rdx
movq %rdx, 0x88(%rsp)
movq 0x148(%rsp), %rdx
addq (%rdx), %rsi
movq %rsi, 0x90(%rsp)
movq 0xb8(%rsp), %rsi
movslq (%rsi), %rdx
movl 0x4(%rsi), %esi
movl %esi, 0x4(%rsp)
movslq %r15d, %rsi
movq %rdi, 0x58(%rsp)
movslq %edi, %rdi
addl %eax, %r9d
movq %r9, 0x40(%rsp)
movq %r14, 0x70(%rsp)
addq %r14, %rdi
incq %rdi
movq %rdi, 0x28(%rsp)
addl %eax, %r8d
movq %r8, 0x48(%rsp)
movq 0xd0(%rsp), %rax
addq %rsi, %rax
movq %rax, 0x30(%rsp)
leaq 0x4(%rcx,%rsi,4), %rax
movq %rax, 0x80(%rsp)
leaq -0x4(,%rdx,4), %rax
movq %rax, 0x78(%rsp)
movq 0x68(%rsp), %rax
leal -0x1(%rax), %r14d
xorl %r12d, %r12d
movsd %xmm1, 0x8(%rsp)
movl %r15d, %ebp
movq %r15, 0x98(%rsp)
movl %r15d, %r13d
movsd %xmm2, 0x20(%rsp)
movsd %xmm3, 0x10(%rsp)
movq 0x30(%rsp), %rax
movzbl (%rax,%r12), %ecx
cmpq $0x2, %rcx
jb 0x13e41
movq 0x28(%rsp), %rax
movzbl (%rax,%r12), %eax
cmpq $0x2, %rax
jb 0x13e41
movq 0x80(%rsp), %rdx
movss (%rdx,%r12,4), %xmm0
movq 0x88(%rsp), %rdx
movq (%rdx), %rdx
addss -0x4(%rdx,%rbx,4), %xmm0
subss (%rdx,%rbx,4), %xmm0
movq 0x90(%rsp), %rdx
movq (%rdx), %rdx
addq 0x78(%rsp), %rdx
addss (%rdx,%rbx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm0, %xmm3
addsd %xmm0, %xmm2
cmpb $0x6, %cl
movl $0x0, %edx
sbbq %rdx, %rdx
orq %r10, %rdx
addq %rcx, %rdx
cmpb $0x6, %al
movl $0x0, %ecx
sbbq %rcx, %rcx
orq %r10, %rcx
addq %rax, %rcx
leaq (%rdx,%rdx,4), %rax
leaq (%r11,%rax,4), %rax
movslq (%rax,%rcx,4), %rax
testq %rax, %rax
je 0x13e20
movsd %xmm2, 0x60(%rsp)
movslq %ebp, %rcx
movq 0x100(%rsp), %rdx
movzbl (%rdx,%rcx), %edx
cmpq $0x6, %rdx
movl $0x0, %esi
sbbq %rsi, %rsi
orq %r10, %rsi
addq %rdx, %rsi
movslq 0x58(%rsp), %r8
movq 0x70(%rsp), %rdx
movzbl (%rdx,%r8), %edi
cmpq $0x6, %rdi
movl $0x0, %r9d
sbbq %r9, %r9
leaq 0x6a10b(%rip), %rdx     # 0x7de60
movl (%rdx,%rax,4), %edx
orq %r10, %r9
addq %rdi, %r9
leaq (%rsi,%rsi,4), %rax
leaq (%r11,%rax,4), %rax
movl (%rax,%r9,4), %esi
movq 0x48(%rsp), %r15
leaq (%r15,%r12), %rbp
movq 0x40(%rsp), %rax
leaq (%rax,%r12), %rdi
subq $0x8, %rsp
movl %ebp, %r9d
pushq 0x58(%rsp)
pushq 0x48(%rsp)
movq %rdi, 0x70(%rsp)
pushq %rdi
movsd %xmm1, 0xc8(%rsp)
movsd %xmm3, 0xd0(%rsp)
callq 0x13ebe
movsd 0xd0(%rsp), %xmm3
movsd 0xc8(%rsp), %xmm1
addq $0x20, %rsp
addsd %xmm0, %xmm3
addsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
ucomisd %xmm3, %xmm0
jbe 0x13e09
leal (%r15,%r12), %r13d
movl %r14d, %eax
movq %rax, 0x68(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd 0x60(%rsp), %xmm2
movsd %xmm2, 0x20(%rsp)
movsd %xmm3, 0x10(%rsp)
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x69fe9(%rip), %r11     # 0x7ddf0
jmp 0x13e20
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x69fd6(%rip), %r11     # 0x7ddf0
movsd 0x60(%rsp), %xmm2
incq %r12
movq 0x98(%rsp), %rax
subl %r13d, %eax
addl %r12d, %eax
decl %r14d
decq %rbx
cmpl 0x4(%rsp), %eax
jl 0x13c68
movq 0xc8(%rsp), %rax
movq 0x68(%rsp), %rcx
movl %ecx, 0x4(%rax)
movq 0xa0(%rsp), %rcx
movl %ecx, 0x8(%rax)
movl 0x1c(%rsp), %edx
movl %edx, 0xc(%rax)
subl %ecx, %r13d
incl %r13d
movl %r13d, 0x10(%rax)
movl %r13d, 0x14(%rax)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x28(%rax)
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x18(%rax)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%rax)
movq 0xf8(%rsp), %rax
incq %rax
cmpq 0xd8(%rsp), %rax
jne 0x13803
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop