// File: /workspace/github_c_makefile_star2_O1/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:
xorl %eax, %eax
movl $0x0, %edi
testl %esi, %esi
js 0x169ae
movl %esi, %edi
movq (%r8), %r10
movzbl (%r10,%rdi), %r10d
movl $0x0, %edi
cmpl $0x2, %r10d
jb 0x169ae
cmpb $0x5, %r10b
ja 0x169a7
decl %r10d
jmp 0x169ab
addl $-0x5, %r10d
movl %r10d, %edi
testl %edx, %edx
js 0x169d5
movl %edx, %r10d
movq (%r9), %r11
movzbl (%r11,%r10), %r10d
cmpl $0x2, %r10d
jb 0x169d5
cmpb $0x5, %r10b
ja 0x169ce
decl %r10d
jmp 0x169d2
addl $-0x5, %r10d
movl %r10d, %eax
pushq %rbx
testl %ecx, %ecx
movl %eax, %r10d
cmovel %edi, %r10d
cmovel %eax, %edi
movslq %r10d, %rax
movslq %edi, %rdi
leaq (%rax,%rax,4), %rax
leaq 0x9815d(%rip), %r10     # 0xaeb50
leaq (%r10,%rax,4), %rax
movslq (%rax,%rdi,4), %rax
testq %rax, %rax
je 0x16ac2
movq (%r8), %r10
testl %ecx, %ecx
je 0x16acb
movl 0x8(%r8), %r11d
subl %r10d, %r11d
movslq %edx, %rcx
movq (%r9), %rdi
movq %rdi, %r8
notq %r8
addq 0x8(%r9), %r8
xorpd %xmm0, %xmm0
cmpq %rcx, %r8
jbe 0x16a69
cmpb $0x0, 0x1(%rdi,%rcx)
je 0x16a69
cmpl $-0x1, %edx
jl 0x16a4f
leaq 0x1(%rcx), %rdx
movl %edx, %edx
movzbl (%rdi,%rdx), %edx
cmpq $0x2, %rdx
jae 0x16b39
xorl %edx, %edx
leaq (%rax,%rax,4), %r9
leaq 0x98184(%rip), %rbx     # 0xaebe0
leaq (%rbx,%r9,4), %r9
xorps %xmm0, %xmm0
cvtsi2sdl (%r9,%rdx,4), %xmm0
addl $-0x2, %r11d
cmpl %esi, %r11d
jle 0x16aa0
cmpl $-0x1, %esi
jl 0x16a86
movslq %esi, %rdx
movzbl 0x1(%r10,%rdx), %edx
cmpq $0x2, %rdx
jae 0x16af1
xorl %edx, %edx
leaq (%rax,%rax,4), %rsi
leaq 0x981ed(%rip), %r9      # 0xaec80
leaq (%r9,%rsi,4), %rsi
cvtsi2sdl (%rsi,%rdx,4), %xmm1
addsd %xmm1, %xmm0
cmpq %rcx, %r8
je 0x16b83
cmpl $0x3, %eax
jl 0x16b90
cmpb $0x0, 0x1(%rdi,%rcx)
je 0x16b88
jmp 0x16b90
xorpd %xmm0, %xmm0
jmp 0x16b90
testl %esi, %esi
jle 0x16ae1
movl %esi, %ecx
movzbl -0x1(%r10,%rcx), %ecx
cmpq $0x2, %rcx
jae 0x16ae7
xorl %ecx, %ecx
jmp 0x16aff
xorpd %xmm0, %xmm0
jmp 0x16b13
cmpb $0x5, %cl
ja 0x16afb
decq %rcx
jmp 0x16aff
cmpb $0x5, %dl
ja 0x16b46
decq %rdx
jmp 0x16a88
addq $-0x5, %rcx
leaq (%rax,%rax,4), %rsi
leaq 0x980d6(%rip), %rdi     # 0xaebe0
leaq (%rdi,%rsi,4), %rsi
cvtsi2sdl (%rsi,%rcx,4), %xmm0
testl %edx, %edx
jle 0x16b6b
movq (%r9), %rcx
movl %edx, %esi
movzbl -0x1(%rcx,%rsi), %ecx
testq %rcx, %rcx
je 0x16b6b
cmpl $0x1, %ecx
jne 0x16b2f
xorl %ecx, %ecx
jmp 0x16b53
cmpb $0x5, %cl
ja 0x16b4f
decq %rcx
jmp 0x16b53
cmpb $0x5, %dl
ja 0x16b9a
decq %rdx
jmp 0x16a51
addq $-0x5, %rdx
jmp 0x16a88
addq $-0x5, %rcx
leaq (%rax,%rax,4), %rsi
leaq 0x98122(%rip), %rdi     # 0xaec80
leaq (%rdi,%rsi,4), %rsi
cvtsi2sdl (%rsi,%rcx,4), %xmm1
addsd %xmm1, %xmm0
testl %edx, %edx
je 0x16b83
cmpl $0x3, %eax
jl 0x16b90
movq (%r9), %rax
movslq %edx, %rcx
cmpb $0x0, -0x1(%rax,%rcx)
je 0x16b88
jmp 0x16b90
cmpl $0x3, %eax
jl 0x16b90
addsd 0x97fa0(%rip), %xmm0    # 0xaeb30
divsd 0x67248(%rip), %xmm0    # 0x7dde0
popq %rbx
retq
addq $-0x5, %rdx
jmp 0x16a51
nop