// File: /workspace/github_c_makefile_star2_O2/fukunagatsu[P]RIblast/gapped_extension.cpp
// Function: GappedExtension::CalcDangleEnergy(int, int, int, std::vector<unsigned char, std::allocator<unsigned char>>&, std::vector<unsigned char, std::allocator<unsigned char>>&, int)
double GappedExtension::CalcDangleEnergy(int q_pos, int db_pos, int flag, vector<unsigned char> &query_seq, vector<unsigned char> &db_seq, int dbseq_length){
  double x = 0;
  int q_char = GetChar(query_seq,q_pos);
  int db_char = GetChar(db_seq,db_pos);
  int type =  flag == 0 ? BP_pair[q_char][db_char] : BP_pair[db_char][q_char];
  int q_length = query_seq.size()-1;
  
  if (type != 0) {
    if(flag == 0){
      if (q_pos>0)x += dangle5_37[type][GetChar(query_seq,q_pos-1)];
      if (db_pos>0 && db_seq[db_pos-1]!=0) x += dangle3_37[type][GetChar(db_seq,db_pos-1)];
      if( (db_pos == 0 || db_seq[db_pos-1]==0) && type>2){
	x += TerminalAU;
      }
    }else{
      if (db_pos < db_seq.size()-1 && db_seq[db_pos+1] != 0) x += dangle5_37[type][GetChar(db_seq,db_pos+1)];
      if (q_pos< q_length-1) x += dangle3_37[type][GetChar(query_seq,q_pos+1)];
      if((db_pos == db_seq.size()-1 || db_seq[db_pos+1]==0) && type>2){
	x += TerminalAU;
      }
    }
  }
  return(double(x)/100);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r14
movq %r8, %r15
movl %ecx, %r12d
movl %edx, %ebx
movl %esi, %ebp
movq %r8, %rsi
movl %ebp, %edx
callq 0x1288a
movl %eax, %r13d
movq %r14, %rsi
movl %ebx, %edx
callq 0x1288a
testl %r12d, %r12d
movl %eax, %ecx
cmovel %r13d, %ecx
cmovel %eax, %r13d
movslq %ecx, %rax
movslq %r13d, %rcx
imulq $0x14, %rax, %rax
leaq 0x97474(%rip), %rdx     # 0xa9b60
addq %rax, %rdx
movslq (%rdx,%rcx,4), %r13
testq %r13, %r13
je 0x127ad
testl %r12d, %r12d
je 0x127b6
movq %r13, 0x10(%rsp)
movl 0x8(%r15), %r13d
subl (%r15), %r13d
movslq %ebx, %rbx
movq (%r14), %rax
movq %rax, %r12
notq %r12
addq 0x8(%r14), %r12
xorpd %xmm0, %xmm0
cmpq %rbx, %r12
jbe 0x1275a
cmpb $0x0, 0x1(%rax,%rbx)
je 0x1275a
leaq 0x1(%rbx), %rdx
movq %r14, %rsi
movq %rax, %r14
callq 0x1288a
cltq
imulq $0x14, 0x10(%rsp), %rcx
leaq 0x974a1(%rip), %rdx     # 0xa9bf0
addq %rcx, %rdx
cvtsi2sdl (%rdx,%rax,4), %xmm0
movq %r14, %rax
addl $-0x2, %r13d
cmpl %ebp, %r13d
jle 0x127dd
incl %ebp
movq %r15, %rsi
movl %ebp, %edx
movsd %xmm0, 0x8(%rsp)
movq %rax, %r14
callq 0x1288a
cltq
movq 0x10(%rsp), %rsi
imulq $0x14, %rsi, %rcx
leaq 0x97506(%rip), %rdx     # 0xa9c90
addq %rcx, %rdx
cvtsi2sdl (%rdx,%rax,4), %xmm0
movq %r14, %rax
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
jmp 0x127e2
xorpd %xmm0, %xmm0
jmp 0x1286a
testl %ebp, %ebp
jle 0x127fc
decl %ebp
movq %r15, %rsi
movl %ebp, %edx
callq 0x1288a
cltq
imulq $0x14, %r13, %rcx
leaq 0x9741d(%rip), %rdx     # 0xa9bf0
addq %rcx, %rdx
cvtsi2sdl (%rdx,%rax,4), %xmm0
jmp 0x12800
movq 0x10(%rsp), %rsi
cmpq %rbx, %r12
jne 0x127ee
cmpl $0x3, %esi
jge 0x12862
jmp 0x1286a
cmpl $0x3, %esi
jl 0x1286a
cmpb $0x0, 0x1(%rax,%rbx)
je 0x12862
jmp 0x1286a
xorpd %xmm0, %xmm0
testl %ebx, %ebx
jle 0x1284c
leal -0x1(%rbx), %edx
movq (%r14), %r15
cmpb $0x0, (%r15,%rdx)
je 0x12851
movq %r14, %rsi
movsd %xmm0, 0x8(%rsp)
callq 0x1288a
cltq
imulq $0x14, %r13, %rcx
leaq 0x97464(%rip), %rdx     # 0xa9c90
addq %rcx, %rdx
cvtsi2sdl (%rdx,%rax,4), %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
jmp 0x12851
je 0x12881
movq (%r14), %r15
cmpl $0x3, %r13d
jl 0x1286a
movslq %ebx, %rax
cmpb $0x0, -0x1(%r15,%rax)
jne 0x1286a
addsd 0x972d6(%rip), %xmm0    # 0xa9b40
divsd 0x6657e(%rip), %xmm0    # 0x78df0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, %r13d
jge 0x12862
jmp 0x1286a
nop