// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x48(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x20(%rbp), %rsi
movl -0xc(%rbp), %edx
callq 0x2e270
movq -0x48(%rbp), %rdi
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rsi
movl -0x10(%rbp), %edx
callq 0x2e270
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x2e009
movslq -0x34(%rbp), %rcx
leaq 0xb115a(%rip), %rax     # 0xdf150
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rbp)
jmp 0x2e025
movslq -0x38(%rbp), %rcx
leaq 0xb113c(%rip), %rax     # 0xdf150
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rdi
callq 0xba80
subq $0x1, %rax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x2e255
cmpl $0x0, -0x14(%rbp)
jne 0x2e134
cmpl $0x0, -0xc(%rbp)
jle 0x2e096
movq -0x48(%rbp), %rdi
movslq -0x3c(%rbp), %rcx
leaq 0xb117c(%rip), %rax     # 0xdf1e0
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rsi
movl -0xc(%rbp), %edx
subl $0x1, %edx
callq 0x2e270
movl %eax, %ecx
movq -0x58(%rbp), %rax
movslq %ecx, %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
cmpl $0x0, -0x10(%rbp)
jle 0x2e0f7
movq -0x28(%rbp), %rdi
movl -0x10(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xbaa0
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0x2e0f7
movq -0x48(%rbp), %rdi
movslq -0x3c(%rbp), %rcx
leaq 0xb11bb(%rip), %rax     # 0xdf280
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rsi
movl -0x10(%rbp), %edx
subl $0x1, %edx
callq 0x2e270
movl %eax, %ecx
movq -0x60(%rbp), %rax
movslq %ecx, %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0x2e117
movq -0x28(%rbp), %rdi
movl -0x10(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xbaa0
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x2e12f
cmpl $0x2, -0x3c(%rbp)
jle 0x2e12f
cvtsi2sdl 0xb11fb(%rip), %xmm0 # 0xdf320
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x2e253
movslq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rdi
callq 0xba80
movq %rax, %rcx
movq -0x68(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x2e1b0
movq -0x28(%rbp), %rdi
movl -0x10(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0xbaa0
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0x2e1b0
movq -0x48(%rbp), %rdi
movslq -0x3c(%rbp), %rcx
leaq 0xb1062(%rip), %rax     # 0xdf1e0
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rsi
movl -0x10(%rbp), %edx
addl $0x1, %edx
callq 0x2e270
movl %eax, %ecx
movq -0x70(%rbp), %rax
movslq %ecx, %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0xc(%rbp), %eax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x2e1fe
movq -0x48(%rbp), %rdi
movslq -0x3c(%rbp), %rcx
leaq 0xb10b4(%rip), %rax     # 0xdf280
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rsi
movl -0xc(%rbp), %edx
addl $0x1, %edx
callq 0x2e270
movl %eax, %ecx
movq -0x78(%rbp), %rax
movslq %ecx, %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movslq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x28(%rbp), %rdi
callq 0xba80
movq %rax, %rcx
movq -0x80(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x2e239
movq -0x28(%rbp), %rdi
movl -0x10(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0xbaa0
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x2e251
cmpl $0x2, -0x3c(%rbp)
jle 0x2e251
cvtsi2sdl 0xb10d9(%rip), %xmm0 # 0xdf320
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x2e253
jmp 0x2e255
movsd -0x30(%rbp), %xmm0
movsd 0xaa96(%rip), %xmm1     # 0x38cf8
divsd %xmm1, %xmm0
addq $0x80, %rsp
popq %rbp
retq
nop