// File: /workspace/github_c_makefile_star2_O3/fukunagatsu[P]RIblast/gapped_extension.cpp
// Function: GappedExtension::LoopEnergy(int, int, int, int, int, int, std::vector<unsigned char, std::allocator<unsigned char>>&, std::vector<unsigned char, std::allocator<unsigned char>>&)
double GappedExtension::LoopEnergy(int type, int type2,int i,int j,int p,int q, vector<unsigned char> &query_seq, vector<unsigned char> &db_seq){
  double z = 0;
  int u1 = p-i-1;
  int u2 = q-j-1;
  if ((u1==0) && (u2==0)){
    z = stack37[type][type2];
  }else{
    if ((u1==0)||(u2==0)) {
      int u;
      u = u1 == 0 ? u2 : u1;
      z = u <=30 ? bulge37[u] : bulge37[30] + lxc37*log( u/30.);
      
      if (u == 1){
	z += stack37[type][type2];
      }else {
	if (type>2){ z += TerminalAU;}
	if (type2>2){ z += TerminalAU;}
      }
    }else{     
      int a = query_seq[i+1] <=5 ? query_seq[i+1]-1 : query_seq[i+1]-5;
      int b = db_seq[j+1] <=5 ? db_seq[j+1]-1 : db_seq[j+1]-5;
      int c = query_seq[p-1] <=5 ? query_seq[p-1]-1 : query_seq[p-1]-5;
      int d = db_seq[q-1] <=5 ? db_seq[q-1]-1 : db_seq[q-1]-5;
      if (u1+u2==2) {
	z = int11_37[type][type2][a][b];
      }else if ((u1==1) && (u2==2)){
	z = int21_37[type][type2][a][d][b];
      }else if ((u1==2) && (u2==1)){
	z = int21_37[type2][type][d][a][c];
      }else if ((u1==2) && (u2==2)){
	z = int22_37[type][type2][a][c][d][b];
      }else{
	z = internal_loop37[u1+u2]+mismatchI37[type][a][b]+mismatchI37[type2][d][c];
      }
    }
  }
  return double(z)/100;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %edx, %ebx
movl %esi, %ebp
movl 0x20(%rsp), %r10d
movl %ecx, %edx
notl %edx
addl %r9d, %edx
movl %r8d, %esi
notl %esi
addl %r10d, %esi
movl %esi, %eax
orl %edx, %eax
je 0x18b2b
testl %edx, %edx
setne %al
testl %esi, %esi
setne %dil
testb %dil, %al
jne 0x18b50
testl %edx, %edx
cmovnel %edx, %esi
cmpl $0x1f, %esi
jge 0x18bf9
movslq %esi, %rax
leaq 0x974cc(%rip), %rcx     # 0xaffc0
cvtsi2sdl (%rcx,%rax,4), %xmm0
cmpl $0x1, %esi
jne 0x18c1a
movslq %ebp, %rax
movslq %ebx, %rcx
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
leaq 0x973d9(%rip), %rsi     # 0xafef0
addq %rax, %rsi
addq %rdx, %rsi
cvtsi2sdl (%rsi,%rcx,4), %xmm1
addsd %xmm1, %xmm0
jmp 0x18cdf
movslq %ebp, %rax
movslq %ebx, %rcx
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
leaq 0x973b0(%rip), %rsi     # 0xafef0
addq %rax, %rsi
addq %rdx, %rsi
cvtsi2sdl (%rsi,%rcx,4), %xmm0
jmp 0x18cdf
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq (%rax), %r11
movslq %ecx, %rax
movzbl 0x1(%r11,%rax), %r14d
xorl %eax, %eax
cmpl $0x6, %r14d
movl $0x0, %ecx
sbbl %ecx, %ecx
orl $-0x5, %ecx
addl %r14d, %ecx
movq (%rdi), %r14
movslq %r8d, %rdi
movzbl 0x1(%r14,%rdi), %edi
cmpl $0x6, %edi
movl $0x0, %r8d
sbbl %r8d, %r8d
orl $-0x5, %r8d
addl %edi, %r8d
movslq %r9d, %rdi
movzbl -0x1(%r11,%rdi), %r11d
cmpl $0x6, %r11d
movl $0x0, %edi
sbbl %edi, %edi
movslq %r10d, %r9
movzbl -0x1(%r14,%r9), %r10d
cmpl $0x6, %r10d
sbbl %eax, %eax
leal (%rsi,%rdx), %r9d
cmpl $0x2, %r9d
jne 0x18c3d
movslq %ebp, %rax
movslq %ebx, %rdx
movslq %ecx, %rcx
movslq %r8d, %rsi
imulq $0x320, %rax, %rax      # imm = 0x320
leaq 0x97461(%rip), %rdi     # 0xb0040
addq %rax, %rdi
imulq $0x64, %rdx, %rax
addq %rdi, %rax
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,4), %rax
movl (%rax,%rsi,4), %ecx
jmp 0x18cdb
cvtsi2sd %esi, %xmm0
divsd 0x34e2b(%rip), %xmm0    # 0x4da30
callq 0x31b0
mulsd 0x970f6(%rip), %xmm0    # 0xafd08
addsd 0x970f6(%rip), %xmm0    # 0xafd10
cmpl $0x3, %ebp
jl 0x18c27
addsd 0x970d9(%rip), %xmm0    # 0xafd00
cmpl $0x3, %ebx
jl 0x18cdf
addsd 0x970c8(%rip), %xmm0    # 0xafd00
jmp 0x18cdf
orl $-0x5, %eax
addl %r10d, %eax
movl %edx, %r14d
xorl $0x1, %r14d
movl %esi, %r10d
xorl $0x2, %r10d
orl %r10d, %r14d
jne 0x18c90
movslq %ebp, %rdx
movslq %ebx, %rsi
movslq %ecx, %rcx
cltq
movslq %r8d, %rdi
imulq $0xfa0, %rdx, %rdx      # imm = 0xFA0
leaq 0x98cce(%rip), %r8      # 0xb1940
addq %rdx, %r8
imulq $0x1f4, %rsi, %rdx      # imm = 0x1F4
addq %r8, %rdx
imulq $0x64, %rcx, %rcx
addq %rdx, %rcx
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,4), %rax
jmp 0x18cd8
orl $-0x5, %edi
addl %r11d, %edi
xorl $0x2, %edx
xorl $0x1, %esi
orl %edx, %esi
jne 0x18cec
movslq %ebx, %rdx
movslq %ebp, %rsi
cltq
movslq %ecx, %rcx
movslq %edi, %rdi
imulq $0xfa0, %rdx, %rdx      # imm = 0xFA0
leaq 0x98c84(%rip), %r8      # 0xb1940
addq %rdx, %r8
imulq $0x1f4, %rsi, %rdx      # imm = 0x1F4
addq %r8, %rdx
imulq $0x64, %rax, %rax
addq %rdx, %rax
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,4), %rax
movl (%rax,%rdi,4), %ecx
cvtsi2sd %ecx, %xmm0
divsd 0x662c9(%rip), %xmm0    # 0x7efb0
popq %rbx
popq %r14
popq %rbp
retq
movslq %r8d, %rsi
orl %r10d, %edx
jne 0x18d3b
movslq %ebp, %rdx
movslq %ebx, %r8
movslq %ecx, %rcx
movslq %edi, %rdi
cltq
imulq $0x4e20, %rdx, %rdx     # imm = 0x4E20
leaq 0xa0930(%rip), %r9      # 0xb9640
addq %rdx, %r9
imulq $0x9c4, %r8, %rdx       # imm = 0x9C4
addq %r9, %rdx
imulq $0x1f4, %rcx, %rcx      # imm = 0x1F4
addq %rdx, %rcx
imulq $0x64, %rdi, %rdx
addq %rcx, %rdx
leaq (%rax,%rax,4), %rax
leaq (%rdx,%rax,4), %rax
jmp 0x18bf1
movslq %r9d, %rdx
leaq 0xc79fb(%rip), %r8      # 0xe0740
movslq %ebp, %r9
movslq %ecx, %rcx
imulq $0x64, %r9, %r9
leaq 0xc7a6a(%rip), %r10     # 0xe07c0
addq %r10, %r9
leaq (%rcx,%rcx,4), %rcx
leaq (%r9,%rcx,4), %rcx
movl (%rcx,%rsi,4), %ecx
addl (%r8,%rdx,4), %ecx
movslq %ebx, %rdx
cltq
movslq %edi, %rsi
imulq $0x64, %rdx, %rdx
addq %r10, %rdx
leaq (%rax,%rax,4), %rax
leaq (%rdx,%rax,4), %rax
addl (%rax,%rsi,4), %ecx
jmp 0x18cdb
nop