// File: /workspace/github_c_makefile_star2_O2/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, 0xd8(%rsp)
movq %r8, 0xd0(%rsp)
movq %rcx, 0x88(%rsp)
movq %rdx, %r8
movq %rdi, 0xc8(%rsp)
movq (%rsi), %rcx
movq 0x8(%rsi), %rax
movq %rcx, 0xc0(%rsp)
subq %rcx, %rax
pushq $0x50
popq %rcx
cqto
idivq %rcx
movq %rax, 0xe0(%rsp)
movq %r8, 0x80(%rsp)
movq (%r8), %rax
movq %rax, 0x110(%rsp)
incq %rax
movq %rax, 0xb8(%rsp)
xorl %eax, %eax
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x69101(%rip), %r11     # 0x78e00
cmpq %rax, 0xe0(%rsp)
jbe 0x1037e
movq %rax, 0xf8(%rsp)
imulq $0x50, %rax, %rax
movq 0xc0(%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, 0x38(%rsp)
movslq %esi, %rbp
movzwl 0x14(%rdx,%rax), %eax
leal -0x1(%rbp,%rax), %eax
movq 0x80(%rsp), %rdx
movq (%rdx), %r14
movq 0xc8(%rsp), %rsi
movslq (%rsi), %r8
movq 0xd8(%rsp), %rdx
movq (%rdx), %rbx
imulq $0x18, %rcx, %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 0xd0(%rsp), %rcx
addq (%rcx), %r15
movq %r15, 0x50(%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, 0x48(%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, 0x30(%rsp)
movl 0x4(%rsi), %eax
movl %eax, 0x1c(%rsp)
leal -0x1(%rdx), %eax
movq %rax, 0x108(%rsp)
movq %r14, 0x20(%rsp)
movq %rdx, 0x60(%rsp)
leaq -0x1(%r14,%rdx), %rax
movq %rax, 0x58(%rsp)
leal -0x1(%r9), %eax
movq %rax, 0x100(%rsp)
xorl %r13d, %r13d
movl %r9d, 0x18(%rsp)
movl %edi, %eax
movq %rax, 0x70(%rsp)
movl %r9d, %eax
movq %rdi, 0x40(%rsp)
movl %edi, %ecx
movq %r9, 0x10(%rsp)
movq 0x60(%rsp), %rdx
addq %r13, %rdx
testq %rdx, %rdx
jle 0x1008b
leaq (%r9,%r13), %rdx
testl %edx, %edx
jle 0x1008b
movq 0x58(%rsp), %rdx
movzbl (%rdx,%r13), %edx
cmpq $0x2, %rdx
jb 0x1008b
leaq (%r9,%r13), %rsi
decq %rsi
movl %esi, %esi
movq 0x30(%rsp), %rdi
movzbl (%rdi,%rsi), %esi
cmpq $0x2, %rsi
jb 0x1008b
movq 0x50(%rsp), %rdi
movss -0x4(%rdi,%r13,4), %xmm0
subss (%rdi,%r13,4), %xmm0
movq 0x48(%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
imulq $0x14, %rdi, %rsi
addq %r11, %rsi
movl (%rsi,%rdx,4), %esi
testl %esi, %esi
je 0x10069
movsd %xmm5, 0x8(%rsp)
movsd %xmm2, 0x28(%rsp)
movsd %xmm1, 0x98(%rsp)
movq 0x108(%rsp), %rdx
leaq (%rdx,%r13), %rbx
movq 0x100(%rsp), %rdx
leaq (%rdx,%r13), %r14
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 0x30(%rsp), %rcx
movzbl (%rcx,%rax), %ecx
cmpq $0x6, %rcx
movl $0x0, %edi
sbbq %rdi, %rdi
orq %r10, %rdi
addq %rcx, %rdi
imulq $0x14, %rdx, %rcx
addq %r11, %rcx
movslq (%rcx,%rdi,4), %rcx
leaq 0x68eda(%rip), %rdx     # 0x78e70
movl (%rdx,%rcx,4), %edx
subq $0x8, %rsp
movl %ebx, %ecx
movl %r14d, %r8d
pushq 0x90(%rsp)
pushq 0x90(%rsp)
pushq %rax
movsd %xmm3, 0xc0(%rsp)
movsd %xmm4, 0x98(%rsp)
movsd %xmm6, 0x88(%rsp)
callq 0x10390
movsd 0x88(%rsp), %xmm6
movsd 0x98(%rsp), %xmm4
movsd 0xc0(%rsp), %xmm3
addq $0x20, %rsp
addsd %xmm0, %xmm4
addsd %xmm0, %xmm6
ucomisd %xmm4, %xmm3
jbe 0x10039
movl %r14d, 0x18(%rsp)
movl %ebx, %eax
movq %rax, 0x70(%rsp)
movl %r14d, %eax
movl %ebx, %ecx
movapd %xmm6, %xmm1
movsd 0x8(%rsp), %xmm5
movapd %xmm5, %xmm2
movapd %xmm4, %xmm3
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x68dce(%rip), %r11     # 0x78e00
movq 0x10(%rsp), %r9
jmp 0x10069
movl %r14d, %eax
movl %ebx, %ecx
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x68db1(%rip), %r11     # 0x78e00
movq 0x10(%rsp), %r9
movsd 0x98(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
movsd 0x8(%rsp), %xmm5
decq %r13
movq 0x70(%rsp), %rdx
addl %r15d, %edx
incl %edx
movl %r15d, %esi
incl %esi
incq %r12
movl %esi, %r15d
cmpl 0x1c(%rsp), %edx
jl 0xfe5f
movq 0xa8(%rsp), %rax
movzwl 0x10(%rax), %eax
movq 0x40(%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 0x30(%rsp), %rdi
addq %rdi, %rdx
incq %rdx
movq %rdx, 0x68(%rsp)
addl %eax, %esi
movq %rsi, 0x40(%rsp)
movq 0xb8(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x78(%rsp)
movq 0xe8(%rsp), %rax
leaq 0x4(%rax,%rcx,4), %rax
movq %rax, 0x58(%rsp)
movq 0xf0(%rsp), %rax
leaq -0x4(,%rax,4), %rax
movq %rax, 0x50(%rsp)
movq 0x38(%rsp), %rax
leal -0x1(%rax), %r13d
xorl %r14d, %r14d
movsd %xmm1, 0x10(%rsp)
movl %r8d, %eax
movq %r8, 0x60(%rsp)
movl %r8d, %edi
movsd %xmm2, 0x20(%rsp)
movsd %xmm3, 0x8(%rsp)
movq 0x78(%rsp), %rcx
movzbl (%rcx,%r14), %edx
cmpq $0x2, %rdx
jb 0x10324
movq 0x68(%rsp), %rcx
movzbl (%rcx,%r14), %ecx
cmpq $0x2, %rcx
jb 0x10324
movq 0x58(%rsp), %rsi
movss (%rsi,%r14,4), %xmm0
movq 0x90(%rsp), %rsi
movq (%rsi), %rsi
addss -0x4(%rsi,%rbp,4), %xmm0
subss (%rsi,%rbp,4), %xmm0
movq 0xb0(%rsp), %rsi
movq (%rsi), %rsi
addq 0x50(%rsp), %rsi
addss (%rsi,%rbp,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
imulq $0x14, %rsi, %rcx
addq %r11, %rcx
movslq (%rcx,%rdx,4), %rcx
testq %rcx, %rcx
je 0x10307
movl %edi, 0x48(%rsp)
movsd %xmm2, 0x28(%rsp)
movq 0x40(%rsp), %rdx
leaq (%rdx,%r14), %rbx
leaq 0x68c71(%rip), %rdx     # 0x78e70
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 0x30(%rsp), %rax
movzbl (%rax,%r8), %eax
cmpq $0x6, %rax
movl $0x0, %edi
sbbq %rdi, %rdi
orq %r10, %rdi
addq %rax, %rdi
imulq $0x14, %rsi, %rax
addq %r11, %rax
movl (%rax,%rdi,4), %esi
movq %r9, %r15
leaq (%r9,%r14), %rax
subq $0x8, %rsp
movl %ebx, %r9d
pushq 0x90(%rsp)
pushq 0x90(%rsp)
movq %rax, %r12
pushq %rax
movsd %xmm1, 0xb8(%rsp)
movsd %xmm3, 0xc0(%rsp)
callq 0x10390
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 0x102e7
movl %r13d, %eax
movq %rax, 0x38(%rsp)
movsd %xmm1, 0x10(%rsp)
movl %ebx, %eax
movl %ebx, %edi
movsd 0x28(%rsp), %xmm2
movsd %xmm2, 0x20(%rsp)
movsd %xmm3, 0x8(%rsp)
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x68b1e(%rip), %r11     # 0x78e00
movq %r15, %r9
jmp 0x10307
movl %ebx, %eax
movabsq $0x3ffffffffffffffb, %r10 # imm = 0x3FFFFFFFFFFFFFFB
leaq 0x68b06(%rip), %r11     # 0x78e00
movq %r15, %r9
movsd 0x28(%rsp), %xmm2
movl 0x48(%rsp), %edi
incq %r14
movq 0x60(%rsp), %rcx
subl %edi, %ecx
addl %r14d, %ecx
decl %r13d
decq %rbp
cmpl 0x1c(%rsp), %ecx
jl 0x10145
movq 0xa8(%rsp), %rax
movq 0x38(%rsp), %rcx
movl %ecx, 0x4(%rax)
movq 0x70(%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
jmp 0xfcff
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq