// File: /workspace/github_c_makefile_star2_O3/fukunagatsu[P]RIblast/ungapped_extension.cpp
// Function: UngappedExtension::LoopEnergy(int, int, int, int, int, int, std::vector<unsigned char, std::allocator<unsigned char>>&, std::vector<unsigned char, std::allocator<unsigned char>>&)
double UngappedExtension::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{
    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
movl 0x28(%rsp), %ebx
movl %ecx, %edi
notl %edi
addl %r9d, %edi
movl %r8d, %r10d
notl %r10d
addl %ebx, %r10d
movl %r10d, %eax
orl %edi, %eax
je 0x15e21
movq 0x38(%rsp), %r11
movq 0x30(%rsp), %rax
movq (%rax), %r14
movslq %ecx, %rax
movzbl 0x1(%r14,%rax), %ebp
xorl %eax, %eax
cmpl $0x6, %ebp
movl $0x0, %ecx
sbbl %ecx, %ecx
orl $-0x5, %ecx
addl %ebp, %ecx
movq (%r11), %r15
movslq %r8d, %r8
movzbl 0x1(%r15,%r8), %r8d
cmpl $0x6, %r8d
movl $0x0, %r11d
sbbl %r11d, %r11d
orl $-0x5, %r11d
addl %r8d, %r11d
movslq %r9d, %r8
movzbl -0x1(%r14,%r8), %r9d
cmpl $0x6, %r9d
movl $0x0, %r8d
sbbl %r8d, %r8d
movslq %ebx, %rbx
movzbl -0x1(%r15,%rbx), %ebp
cmpl $0x6, %ebp
sbbl %eax, %eax
leal (%r10,%rdi), %ebx
cmpl $0x2, %ebx
jne 0x15e44
movslq %esi, %rax
movslq %edx, %rdx
movslq %ecx, %rcx
movslq %r11d, %rsi
imulq $0x320, %rax, %rax      # imm = 0x320
leaq 0x69319(%rip), %rdi     # 0x7f120
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 0x15ee3
movslq %esi, %rax
movslq %edx, %rcx
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
leaq 0x6921a(%rip), %rsi     # 0x7f050
addq %rax, %rsi
addq %rdx, %rsi
movl (%rsi,%rcx,4), %ecx
jmp 0x15ee3
orl $-0x5, %eax
addl %ebp, %eax
movl %edi, %r14d
xorl $0x1, %r14d
movl %r10d, %ebp
xorl $0x2, %ebp
orl %ebp, %r14d
jne 0x15e95
movslq %esi, %rsi
movslq %edx, %rdx
movslq %ecx, %rcx
cltq
movslq %r11d, %rdi
imulq $0xfa0, %rsi, %rsi      # imm = 0xFA0
leaq 0x6aba9(%rip), %r8      # 0x80a20
addq %rsi, %r8
imulq $0x1f4, %rdx, %rdx      # imm = 0x1F4
addq %r8, %rdx
imulq $0x64, %rcx, %rcx
addq %rdx, %rcx
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,4), %rax
jmp 0x15ee0
orl $-0x5, %r8d
addl %r9d, %r8d
xorl $0x2, %edi
xorl $0x1, %r10d
orl %edi, %r10d
jne 0x15ef6
movslq %edx, %rdx
movslq %esi, %rsi
cltq
movslq %ecx, %rcx
movslq %r8d, %rdi
imulq $0xfa0, %rdx, %rdx      # imm = 0xFA0
leaq 0x6ab5c(%rip), %r8      # 0x80a20
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 0x690c1(%rip), %xmm0    # 0x7efb0
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movslq %r11d, %r9
orl %ebp, %edi
jne 0x15f45
movslq %esi, %rsi
movslq %edx, %rdx
movslq %ecx, %rcx
movslq %r8d, %rdi
cltq
imulq $0x4e20, %rsi, %rsi     # imm = 0x4E20
leaq 0x72807(%rip), %r8      # 0x88720
addq %rsi, %r8
imulq $0x9c4, %rdx, %rdx      # imm = 0x9C4
addq %r8, %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
movl (%rax,%r9,4), %ecx
jmp 0x15ee3
movslq %ebx, %rdi
leaq 0x998d1(%rip), %r10     # 0xaf820
movslq %esi, %rsi
movslq %ecx, %rcx
imulq $0x64, %rsi, %rsi
leaq 0x99940(%rip), %r11     # 0xaf8a0
addq %r11, %rsi
leaq (%rcx,%rcx,4), %rcx
leaq (%rsi,%rcx,4), %rcx
movl (%rcx,%r9,4), %ecx
addl (%r10,%rdi,4), %ecx
movslq %edx, %rdx
cltq
movslq %r8d, %rsi
imulq $0x64, %rdx, %rdx
addq %r11, %rdx
leaq (%rax,%rax,4), %rax
leaq (%rdx,%rax,4), %rax
addl (%rax,%rsi,4), %ecx
jmp 0x15ee3
nop