// File: /workspace/github_c_makefile_star2_O2/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 0x12a18
testl %edx, %edx
setne %al
testl %esi, %esi
setne %dil
testb %dil, %al
jne 0x12a36
testl %edx, %edx
cmovnel %edx, %esi
cmpl $0x1f, %esi
jge 0x12ade
movslq %esi, %rax
leaq 0x97418(%rip), %rcx     # 0xa9e00
cvtsi2sdl (%rcx,%rax,4), %xmm0
cmpl $0x1, %esi
jne 0x12aff
movslq %ebp, %rax
movslq %ebx, %rcx
imulq $0x1c, %rax, %rax
leaq 0x97329(%rip), %rdx     # 0xa9d30
addq %rax, %rdx
cvtsi2sdl (%rdx,%rcx,4), %xmm1
addsd %xmm1, %xmm0
jmp 0x12c60
movslq %ebp, %rax
movslq %ebx, %rcx
imulq $0x1c, %rax, %rax
leaq 0x97307(%rip), %rdx     # 0xa9d30
addq %rax, %rdx
cvtsi2sdl (%rdx,%rcx,4), %xmm0
jmp 0x12c60
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 0x12b22
movslq %ebp, %rax
movslq %ebx, %rdx
movslq %ecx, %rcx
movslq %r8d, %rsi
imulq $0x320, %rax, %rax      # imm = 0x320
leaq 0x973bb(%rip), %rdi     # 0xa9e80
addq %rax, %rdi
imulq $0x64, %rdx, %rax
addq %rdi, %rax
imulq $0x14, %rcx, %rcx
addq %rax, %rcx
movl (%rcx,%rsi,4), %ecx
jmp 0x12c5c
cvtsi2sd %esi, %xmm0
divsd 0x34e66(%rip), %xmm0    # 0x47950
callq 0x3190
mulsd 0x97051(%rip), %xmm0    # 0xa9b48
addsd 0x97051(%rip), %xmm0    # 0xa9b50
cmpl $0x3, %ebp
jl 0x12b0c
addsd 0x97034(%rip), %xmm0    # 0xa9b40
cmpl $0x3, %ebx
jl 0x12c60
addsd 0x97023(%rip), %xmm0    # 0xa9b40
jmp 0x12c60
orl $-0x5, %eax
addl %r10d, %eax
movl %edx, %r14d
xorl $0x1, %r14d
movl %esi, %r10d
xorl $0x2, %r10d
orl %r10d, %r14d
jne 0x12b7a
movslq %ebp, %rdx
movslq %ebx, %rsi
movslq %ecx, %rcx
cltq
movslq %r8d, %rdi
imulq $0xfa0, %rdx, %rdx      # imm = 0xFA0
leaq 0x98c29(%rip), %r8      # 0xab780
addq %rdx, %r8
imulq $0x1f4, %rsi, %rdx      # imm = 0x1F4
addq %r8, %rdx
imulq $0x64, %rcx, %rcx
addq %rdx, %rcx
imulq $0x14, %rax, %rax
addq %rcx, %rax
movl (%rax,%rdi,4), %ecx
jmp 0x12c5c
orl $-0x5, %edi
addl %r11d, %edi
xorl $0x2, %edx
xorl $0x1, %esi
orl %edx, %esi
jne 0x12bc9
movslq %ebx, %rdx
movslq %ebp, %rsi
cltq
movslq %ecx, %rcx
movslq %edi, %rdi
imulq $0xfa0, %rdx, %rdx      # imm = 0xFA0
leaq 0x98bda(%rip), %r8      # 0xab780
addq %rdx, %r8
imulq $0x1f4, %rsi, %rdx      # imm = 0x1F4
addq %r8, %rdx
imulq $0x64, %rax, %rax
addq %rdx, %rax
imulq $0x14, %rcx, %rcx
addq %rax, %rcx
movl (%rcx,%rdi,4), %ecx
jmp 0x12c5c
movslq %r8d, %rsi
orl %r10d, %edx
jne 0x12c17
movslq %ebp, %rdx
movslq %ebx, %r8
movslq %ecx, %rcx
movslq %edi, %rdi
cltq
imulq $0x4e20, %rdx, %rdx     # imm = 0x4E20
leaq 0xa0893(%rip), %r9      # 0xb3480
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
imulq $0x14, %rax, %rax
addq %rdx, %rax
addq %rcx, %rax
movl (%rax,%rsi,4), %ecx
jmp 0x12c5c
movslq %r9d, %rdx
leaq 0xc795f(%rip), %r8      # 0xda580
movslq %ebp, %r9
movslq %ecx, %rcx
imulq $0x64, %r9, %r9
leaq 0xc79ce(%rip), %r10     # 0xda600
addq %r10, %r9
imulq $0x14, %rcx, %rcx
addq %r9, %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
imulq $0x14, %rax, %rax
addq %rdx, %rax
addl (%rax,%rsi,4), %ecx
cvtsi2sd %ecx, %xmm0
divsd 0x66188(%rip), %xmm0    # 0x78df0
popq %rbx
popq %r14
popq %rbp
retq
nop