// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %ebx
movl %esi, %ebp
movl 0x30(%rsp), %esi
movl %ecx, %eax
notl %eax
addl %r9d, %eax
movl %r8d, %r14d
notl %r14d
addl %esi, %r14d
movl %r14d, %edx
orl %eax, %edx
je 0x16d39
testl %eax, %eax
setne %dl
testl %r14d, %r14d
setne %dil
testb %dil, %dl
jne 0x16d5e
testl %eax, %eax
cmovnel %eax, %r14d
cmpl $0x1e, %r14d
jg 0x16e07
movslq %r14d, %rax
leaq 0x980c1(%rip), %rcx     # 0xaedf0
cvtsi2sdl (%rcx,%rax,4), %xmm0
jmp 0x16e29
movslq %ebp, %rax
movslq %ebx, %rcx
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
leaq 0x97fd2(%rip), %rsi     # 0xaed20
addq %rax, %rsi
addq %rdx, %rsi
cvtsi2sdl (%rsi,%rcx,4), %xmm0
jmp 0x16fca
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rdi
movq (%rdi), %r11
movslq %ecx, %rcx
movzbl 0x1(%r11,%rcx), %edi
xorl %r10d, %r10d
cmpl $0x6, %edi
movl $0x0, %ecx
sbbl %ecx, %ecx
orl $-0x5, %ecx
addl %edi, %ecx
movq (%rdx), %r15
movslq %r8d, %rdx
movzbl 0x1(%r15,%rdx), %edx
cmpl $0x6, %edx
movl $0x0, %edi
sbbl %edi, %edi
orl $-0x5, %edi
addl %edx, %edi
movslq %r9d, %rdx
movzbl -0x1(%r11,%rdx), %edx
cmpl $0x6, %edx
movl $0x0, %r9d
sbbl %r9d, %r9d
movslq %esi, %rsi
movzbl -0x1(%r15,%rsi), %esi
cmpl $0x6, %esi
sbbl %r10d, %r10d
leal (%r14,%rax), %r8d
cmpl $0x2, %r8d
jne 0x16e5c
movslq %ebp, %rax
movslq %ebx, %rdx
movslq %ecx, %rcx
movslq %edi, %rsi
imulq $0x320, %rax, %rax      # imm = 0x320
leaq 0x98083(%rip), %rdi     # 0xaee70
addq %rax, %rdi
imulq $0x64, %rdx, %rax
addq %rdi, %rax
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,4), %rax
movl (%rax,%rsi,4), %eax
jmp 0x16fc6
cvtsi2sd %r14d, %xmm0
divsd 0x35b3c(%rip), %xmm0    # 0x4c950
callq 0x31b0
mulsd 0x97d17(%rip), %xmm0    # 0xaeb38
addsd 0x97d17(%rip), %xmm0    # 0xaeb40
cmpl $0x1, %r14d
jne 0x16eb7
movslq %ebp, %rax
movslq %ebx, %rcx
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
leaq 0x97ed8(%rip), %rsi     # 0xaed20
addq %rax, %rsi
addq %rdx, %rsi
cvtsi2sdl (%rsi,%rcx,4), %xmm1
addsd %xmm1, %xmm0
jmp 0x16fca
orl $-0x5, %r10d
addl %r10d, %esi
movl %eax, %r11d
xorl $0x1, %r11d
movl %r14d, %r10d
xorl $0x2, %r10d
orl %r10d, %r11d
jne 0x16eda
movslq %ebp, %rax
movslq %ebx, %rdx
movslq %ecx, %rcx
movslq %esi, %rsi
movslq %edi, %rdi
imulq $0xfa0, %rax, %rax      # imm = 0xFA0
leaq 0x998dd(%rip), %r8      # 0xb0770
addq %rax, %r8
imulq $0x1f4, %rdx, %rax      # imm = 0x1F4
addq %r8, %rax
imulq $0x64, %rcx, %rcx
addq %rax, %rcx
leaq (%rsi,%rsi,4), %rax
leaq (%rcx,%rax,4), %rax
movl (%rax,%rdi,4), %eax
jmp 0x16fc6
cmpl $0x3, %ebp
jl 0x16ec4
addsd 0x97c6c(%rip), %xmm0    # 0xaeb30
cmpl $0x3, %ebx
jl 0x16fca
addsd 0x97c5b(%rip), %xmm0    # 0xaeb30
jmp 0x16fca
orl $-0x5, %r9d
addl %r9d, %edx
xorl $0x2, %eax
xorl $0x1, %r14d
orl %eax, %r14d
jne 0x16f2e
movslq %ebx, %rax
movslq %ebp, %rdi
movslq %esi, %rsi
movslq %ecx, %rcx
movslq %edx, %rdx
imulq $0xfa0, %rax, %rax      # imm = 0xFA0
leaq 0x99866(%rip), %r8      # 0xb0770
addq %rax, %r8
imulq $0x1f4, %rdi, %rax      # imm = 0x1F4
addq %r8, %rax
imulq $0x64, %rsi, %rsi
addq %rax, %rsi
leaq (%rcx,%rcx,4), %rax
leaq (%rsi,%rax,4), %rax
movl (%rax,%rdx,4), %eax
jmp 0x16fc6
movslq %edi, %rdi
orl %r10d, %eax
jne 0x16f7e
movslq %ebp, %rax
movslq %ebx, %r8
movslq %ecx, %rcx
movslq %edx, %rdx
movslq %esi, %rsi
imulq $0x4e20, %rax, %rax     # imm = 0x4E20
leaq 0xa151d(%rip), %r9      # 0xb8470
addq %rax, %r9
imulq $0x9c4, %r8, %rax       # imm = 0x9C4
addq %r9, %rax
imulq $0x1f4, %rcx, %rcx      # imm = 0x1F4
addq %rax, %rcx
imulq $0x64, %rdx, %rax
addq %rcx, %rax
leaq (%rsi,%rsi,4), %rcx
leaq (%rax,%rcx,4), %rax
jmp 0x16eaf
movslq %r8d, %r8
leaq 0xc85e8(%rip), %r9      # 0xdf570
movslq %ebp, %rax
movslq %ecx, %rcx
imulq $0x64, %rax, %rax
leaq 0xc8657(%rip), %r10     # 0xdf5f0
addq %r10, %rax
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,4), %rax
movl (%rax,%rdi,4), %eax
addl (%r9,%r8,4), %eax
movslq %ebx, %rcx
movslq %esi, %rsi
movslq %edx, %rdx
imulq $0x64, %rcx, %rcx
addq %r10, %rcx
leaq (%rsi,%rsi,4), %rsi
leaq (%rcx,%rsi,4), %rcx
addl (%rcx,%rdx,4), %eax
cvtsi2sd %eax, %xmm0
divsd 0x66e0e(%rip), %xmm0    # 0x7dde0
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop