// File: /workspace/github_c_makefile_star2_O3/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 0x18776
movl %esi, %edi
movq (%r8), %r10
movzbl (%r10,%rdi), %r10d
movl $0x0, %edi
cmpl $0x2, %r10d
jb 0x18776
cmpb $0x5, %r10b
ja 0x1876f
decl %r10d
jmp 0x18773
addl $-0x5, %r10d
movl %r10d, %edi
testl %edx, %edx
js 0x1879d
movl %edx, %r10d
movq (%r9), %r11
movzbl (%r11,%r10), %r10d
cmpl $0x2, %r10d
jb 0x1879d
cmpb $0x5, %r10b
ja 0x18796
decl %r10d
jmp 0x1879a
addl $-0x5, %r10d
movl %r10d, %eax
pushq %rbx
testl %ecx, %ecx
je 0x18828
cltq
movslq %edi, %rcx
leaq (%rax,%rax,4), %rax
leaq 0x9756a(%rip), %rdi     # 0xafd20
leaq (%rdi,%rax,4), %rax
movslq (%rax,%rcx,4), %rax
testq %rax, %rax
je 0x18863
movl 0x8(%r8), %r11d
movq (%r8), %r10
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 0x18919
cmpb $0x0, 0x1(%rdi,%rcx)
je 0x18919
xorl %r9d, %r9d
cmpl $-0x1, %edx
jl 0x188fe
leaq 0x1(%rcx), %rdx
movl %edx, %edx
movzbl (%rdi,%rdx), %edx
cmpl $0x2, %edx
jb 0x188fe
cmpb $0x5, %dl
ja 0x188f8
decl %edx
jmp 0x188fb
movslq %edi, %rcx
cltq
leaq (%rcx,%rcx,4), %rcx
leaq 0x974e8(%rip), %rdi     # 0xafd20
leaq (%rdi,%rcx,4), %rcx
movslq (%rcx,%rax,4), %rax
testq %rax, %rax
je 0x18863
testl %esi, %esi
jle 0x1886c
movq (%r8), %rcx
movl %esi, %esi
movzbl -0x1(%rcx,%rsi), %ecx
xorl %esi, %esi
cmpl $0x2, %ecx
jb 0x18877
cmpb $0x5, %cl
ja 0x18872
decl %ecx
jmp 0x18875
xorpd %xmm0, %xmm0
jmp 0x18981
xorpd %xmm0, %xmm0
jmp 0x1888e
addl $-0x5, %ecx
movl %ecx, %esi
movslq %esi, %rcx
leaq (%rax,%rax,4), %rsi
leaq 0x9752b(%rip), %rdi     # 0xafdb0
leaq (%rdi,%rsi,4), %rsi
cvtsi2sdl (%rsi,%rcx,4), %xmm0
testl %edx, %edx
jle 0x188b1
movq (%r9), %rcx
movl %edx, %esi
movzbl -0x1(%rcx,%rsi), %esi
testl %esi, %esi
je 0x188dc
xorl %edi, %edi
cmpl $0x1, %esi
je 0x188c1
cmpb $0x5, %sil
ja 0x188bc
decl %esi
jmp 0x188bf
je 0x18966
movq (%r9), %rcx
jmp 0x188dc
addl $-0x5, %esi
movl %esi, %edi
movslq %edi, %rsi
leaq (%rax,%rax,4), %rdi
leaq 0x97581(%rip), %r8      # 0xafe50
leaq (%r8,%rdi,4), %rdi
cvtsi2sdl (%rdi,%rsi,4), %xmm1
addsd %xmm1, %xmm0
cmpl $0x3, %eax
jl 0x18981
movslq %edx, %rax
cmpb $0x0, -0x1(%rcx,%rax)
je 0x18979
jmp 0x18981
addl $-0x5, %edx
movl %edx, %r9d
movslq %r9d, %rdx
leaq (%rax,%rax,4), %r9
leaq 0x974a4(%rip), %rbx     # 0xafdb0
leaq (%rbx,%r9,4), %r9
xorps %xmm0, %xmm0
cvtsi2sdl (%r9,%rdx,4), %xmm0
addl $-0x2, %r11d
cmpl %esi, %r11d
jle 0x18961
xorl %edx, %edx
cmpl $-0x1, %esi
jl 0x18946
movslq %esi, %rsi
movzbl 0x1(%r10,%rsi), %esi
cmpl $0x2, %esi
jb 0x18946
cmpb $0x5, %sil
ja 0x18941
decl %esi
jmp 0x18944
addl $-0x5, %esi
movl %esi, %edx
movslq %edx, %rdx
leaq (%rax,%rax,4), %rsi
leaq 0x974fc(%rip), %r9      # 0xafe50
leaq (%r9,%rsi,4), %rsi
cvtsi2sdl (%rsi,%rdx,4), %xmm1
addsd %xmm1, %xmm0
cmpq %rcx, %r8
jne 0x1896d
cmpl $0x3, %eax
jge 0x18979
jmp 0x18981
cmpl $0x3, %eax
jl 0x18981
cmpb $0x0, 0x1(%rdi,%rcx)
jne 0x18981
addsd 0x9737f(%rip), %xmm0    # 0xafd00
divsd 0x66627(%rip), %xmm0    # 0x7efb0
popq %rbx
retq
nop