// File: /workspace/github_c_makefile_star2_O1/fukunagatsu[P]RIblast/raccess.cpp
// Function: Raccess::CalcLogSumBulgeAndInternalProbability(std::vector<double, std::allocator<double>>&, std::vector<double, std::allocator<double>>&)
void Raccess::CalcLogSumBulgeAndInternalProbability(vector<double> &biloop_probability, vector<double> &conditional_biloop_probability){
  double probability = 0;
  double temp = 0;
  int type = 0;
  int type2 = 0;
  vector<bool> b_flag_array; b_flag_array.resize(_seq_length,0);
  vector<bool> c_flag_array; c_flag_array.resize(_seq_length,0);
  int w = _min_accessible_length;
  
  for(int i = 1; i<_seq_length-TURN-2;i++){
    for(int j = i+TURN+3; j<=min(i+_maximal_span,_seq_length);j++){
      type = BP_pair[_int_sequence[i]][_int_sequence[j]];
      if (type!=0) {
	for (int p =i+1; p <= min(i+MAXLOOP+1,j-TURN-2); p++) {
	  int u1 = p-i-1;
	  for (int q=max(p+TURN+1,j-MAXLOOP+u1-1); q<j; q++) {
	    type2 = BP_pair[_int_sequence[p]][_int_sequence[q]];
	    if (type2 != 0 && !(p == i+1 && q == j-1)) {
	      type2 = rtype[type2];
	      if(_Beta_stemend[i][j-i-1] != -INF && _Alpha_stem[p-1][q-p+1] != -INF){
		temp = _Beta_stemend[i][j-i-1] + LoopEnergy(type, type2,i,j,p,q)+_Alpha_stem[p-1][q-p+1];
		
		for(int k = i+1; k <= p-w;k++){
		  if(k == p-w){
		    biloop_probability[k-1] = b_flag_array[k-1] == 1 ? logsumexp(biloop_probability[k-1], temp) : temp;
		    b_flag_array[k-1] = 1;		   
		  }else{
		    conditional_biloop_probability[k-1] = c_flag_array[k-1] == 1 ? logsumexp(conditional_biloop_probability[k-1], temp) : temp;
		    c_flag_array[k-1] = 1;		  
		  }
		}
		
		for(int k = q+1; k <= j-w;k++){
		  if(k == j-w){
		    biloop_probability[k-1] = b_flag_array[k-1] == 1 ? logsumexp(biloop_probability[k-1], temp) : temp;
		    b_flag_array[k-1] = 1;
		  }else{
		    conditional_biloop_probability[k-1] = c_flag_array[k-1] == 1 ? logsumexp(conditional_biloop_probability[k-1], temp) : temp;
		    c_flag_array[k-1] = 1;
		  }
		}
	      } 
	    }
	  }
	}
      }
    }
  }
  
  for(int i=0;i<_seq_length;i++){
    if(b_flag_array[i]==1 && c_flag_array[i]==1){
      biloop_probability[i] = logsumexp(biloop_probability[i], conditional_biloop_probability[i]);
    }
    if(b_flag_array[i]==0 && c_flag_array[i]==1){
      biloop_probability[i] = conditional_biloop_probability[i];
    }
    if(b_flag_array[i]==1){
      biloop_probability[i] = fmath::expd(biloop_probability[i]-_Alpha_outer[_seq_length]);
    }
    if(c_flag_array[i]==1){
      conditional_biloop_probability[i] = fmath::expd(conditional_biloop_probability[i]-_Alpha_outer[_seq_length]);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rdx, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdi, %r14
xorl %ebx, %ebx
leaq 0xe0(%rsp), %rdi
movq %rbx, (%rdi)
movl %ebx, 0x8(%rdi)
movq %rbx, 0x10(%rdi)
movl %ebx, 0x18(%rdi)
movq %rbx, 0x20(%rdi)
movslq 0x62110(%r14), %rsi
xorl %edx, %edx
callq 0xcb68
leaq 0xb8(%rsp), %rdi
movq %rbx, (%rdi)
movl %ebx, 0x8(%rdi)
movq %rbx, 0x10(%rdi)
movl %ebx, 0x18(%rdi)
movq %rbx, 0x20(%rdi)
movslq 0x62110(%r14), %rsi
xorl %edx, %edx
callq 0xcb68
movl 0x62110(%r14), %eax
cmpl $0x7, %eax
jl 0xbe77
movslq 0x62118(%r14), %rax
movl $0x3, %ecx
subl %eax, %ecx
movl %ecx, 0x34(%rsp)
movl $0x2, %ecx
subl %eax, %ecx
movl %ecx, 0x30(%rsp)
movl $0x7, %ecx
movq %rax, 0x110(%rsp)
subl %eax, %ecx
movl %ecx, 0x28(%rsp)
movl $0x2, %eax
movq %rax, 0x60(%rsp)
movl $0x6, 0x2c(%rsp)
movl $0xffffffe8, 0x24(%rsp) # imm = 0xFFFFFFE8
movl $0x7, %eax
movq %rax, 0x108(%rsp)
movl $0x1, %esi
movq %r14, 0x50(%rsp)
leaq 0x6(%rsi), %rax
movl 0x62114(%r14), %ecx
addl %esi, %ecx
movl 0x62110(%r14), %edx
cmpl %ecx, %edx
cmovll %edx, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jg 0xbe3f
leaq 0x1(%rsi), %rax
movq %rax, 0x118(%rsp)
movq %rsi, %rax
notq %rax
movq %rax, 0x140(%rsp)
leal 0x1f(%rsi), %eax
movl %eax, 0xb0(%rsp)
movl 0x28(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0x108(%rsp), %rdi
movl 0x24(%rsp), %eax
movl %eax, 0x38(%rsp)
movq %rsi, 0x10(%rsp)
movq 0x620f8(%r14), %rax
movslq (%rax,%rsi,4), %rcx
movslq (%rax,%rdi,4), %rax
leaq (%rcx,%rcx,4), %rcx
leaq 0x41067(%rip), %rdx     # 0x4c9d0
leaq (%rdx,%rcx,4), %rcx
movl (%rcx,%rax,4), %eax
movl %eax, 0xb4(%rsp)
testl %eax, %eax
je 0xbe0a
leaq -0x5(%rdi), %rax
cmpq 0x10(%rsp), %rax
jbe 0xbe0a
movl 0x3c(%rsp), %ecx
decq %rcx
movq %rcx, 0x160(%rsp)
movl 0xb0(%rsp), %ecx
cmpl %ecx, %eax
cmovgel %ecx, %eax
movl %edi, %ecx
subl 0x10(%rsp), %ecx
leaq -0x1(%rdi), %rdx
movq %rdx, 0x148(%rsp)
movq %rdi, %rdx
subq 0x110(%rsp), %rdx
movq %rdx, 0x58(%rsp)
cltq
movq %rax, 0x120(%rsp)
addl $-0x20, %ecx
movq %rcx, 0x128(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0x60(%rsp), %rdx
movl 0x38(%rsp), %eax
movl %eax, 0x48(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, 0x44(%rsp)
movl 0x34(%rsp), %eax
movl %eax, 0x40(%rsp)
movq %rdi, 0x98(%rsp)
movq 0x128(%rsp), %rax
addl %edx, %eax
leal 0x4(%rdx), %ecx
cmpl %eax, %ecx
cmovgl %ecx, %eax
cmpq %rax, %rdi
jbe 0xbde5
movl 0x4c(%rsp), %eax
movl $0x2, %ecx
subq %rax, %rcx
movq %rcx, 0xa8(%rsp)
movl 0x48(%rsp), %eax
movl 0x44(%rsp), %ecx
cmpl %eax, %ecx
movl %eax, %esi
cmovgl %ecx, %esi
leaq -0x1(%rdx), %rax
movq %rax, 0x138(%rsp)
movq %rdx, %rax
subq 0x110(%rsp), %rax
movq %rax, 0x130(%rsp)
movl 0x40(%rsp), %eax
movq %rax, 0xa0(%rsp)
movq %rdx, %rax
xorq 0x118(%rsp), %rax
movq %rax, 0x150(%rsp)
movq %rdx, 0x78(%rsp)
movq 0x620f8(%r14), %rax
movslq (%rax,%rdx,4), %rcx
movslq (%rax,%rsi,4), %rax
leaq (%rcx,%rcx,4), %rcx
leaq 0x40f28(%rip), %rdx     # 0x4c9d0
leaq (%rdx,%rcx,4), %rcx
movslq (%rcx,%rax,4), %rax
movq %rsi, 0x18(%rsp)
movq %rsi, %rcx
xorq 0x148(%rsp), %rcx
orq 0x150(%rsp), %rcx
sete %cl
testq %rax, %rax
je 0xbdc2
testb %cl, %cl
jne 0xbdc2
movq 0x50(%rsp), %rcx
movq 0x62218(%rcx), %rcx
movq 0x10(%rsp), %rdx
leaq (%rdx,%rdx,2), %rdx
movq 0x98(%rsp), %rsi
leaq (,%rsi,8), %rsi
addq (%rcx,%rdx,8), %rsi
movq 0x140(%rsp), %rcx
movsd (%rsi,%rcx,8), %xmm1
ucomisd 0x40e16(%rip), %xmm1    # 0x4c930
jne 0xbb22
jnp 0xbdc2
movq 0x50(%rsp), %rcx
movq 0x62158(%rcx), %rcx
movq 0x138(%rsp), %rdx
leaq (%rdx,%rdx,2), %rbx
movq 0x18(%rsp), %r14
subl 0x78(%rsp), %r14d
shlq $0x20, %r14
movabsq $0x100000000, %rdx      # imm = 0x100000000
addq %rdx, %r14
movq (%rcx,%rbx,8), %rcx
movq %r14, %rdx
sarq $0x1d, %rdx
movsd (%rcx,%rdx), %xmm0
ucomisd 0x40dc3(%rip), %xmm0    # 0x4c930
jne 0xbb75
jnp 0xbdc2
leaq 0x40ec4(%rip), %rcx     # 0x4ca40
movl (%rcx,%rax,4), %edx
sarq $0x20, %r14
movq 0x18(%rsp), %rax
movl %eax, (%rsp)
movq 0x50(%rsp), %r15
movq %r15, %rdi
movl 0xb4(%rsp), %esi
movq 0x10(%rsp), %r12
movl %r12d, %ecx
movq 0x98(%rsp), %r8
movq 0x78(%rsp), %r9
movsd %xmm1, 0x8(%rsp)
callq 0xa8b6
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movq 0x62158(%r15), %rax
movq (%rax,%rbx,8), %rax
addsd (%rax,%r14,8), %xmm1
cmpq 0x130(%rsp), %r12
movsd %xmm1, 0x8(%rsp)
jge 0xbcf8
movq 0xb8(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x88(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x68(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x158(%rsp)
movq 0x10(%rsp), %r12
movq 0x60(%rsp), %r15
leaq -0x1(%r15), %rcx
movq %r12, %rax
shrq $0x6, %rax
movabsq $-0x8000000000000000, %rdi # imm = 0x8000000000000000
leaq 0x3f(%rdi), %rdx
andq %rcx, %rdx
xorl %esi, %esi
cmpq %rdi, %rdx
setbe %sil
movl $0x1, %ebx
movl %r12d, %ecx
shlq %cl, %rbx
movq 0xa8(%rsp), %rcx
leaq (%rcx,%r12), %rdx
leaq -0x8(,%rsi,8), %rcx
cmpq $0x1, %rdx
jne 0xbc9b
movq 0x80(%rsp), %rdx
leaq (%rdx,%rax,8), %rax
leaq (%rax,%rcx), %r13
movq (%rcx,%rax), %rbp
movq 0x158(%rsp), %r14
jmp 0xbcb7
movq 0x90(%rsp), %rdx
leaq (%rdx,%rax,8), %rax
leaq (%rax,%rcx), %r13
movq (%rcx,%rax), %rbp
movq 0x88(%rsp), %r14
movapd %xmm1, %xmm0
testq %rbx, %rbp
je 0xbcd7
movsd (%r14,%r12,8), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xabc8
movsd 0x8(%rsp), %xmm1
movsd %xmm0, (%r14,%r12,8)
orq %rbx, %rbp
movq %rbp, (%r13)
incq %r15
incq %r12
cmpq 0xa0(%rsp), %r15
jne 0xbc33
movq 0x18(%rsp), %rax
cmpq 0x58(%rsp), %rax
jge 0xbdc2
movq 0xb8(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x88(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x68(%rsp), %rax
movq (%rax), %rbp
movq 0x18(%rsp), %r12
movq %r12, %rax
shrq $0x6, %rax
movl $0x1, %ebx
movl %r12d, %ecx
shlq %cl, %rbx
cmpq %r12, 0x160(%rsp)
jne 0xbd75
movq 0x80(%rsp), %rcx
leaq (%rcx,%rax,8), %r15
movq (%r15), %r13
movq %rbp, %r14
jmp 0xbd8c
movq 0x90(%rsp), %rcx
leaq (%rcx,%rax,8), %r15
movq (%r15), %r13
movq 0x88(%rsp), %r14
movapd %xmm1, %xmm0
testq %rbx, %r13
je 0xbdac
movsd (%r14,%r12,8), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xabc8
movsd 0x8(%rsp), %xmm1
movsd %xmm0, (%r14,%r12,8)
incq %r12
orq %rbx, %r13
movq %r13, (%r15)
cmpq 0x58(%rsp), %r12
jl 0xbd45
movq 0x18(%rsp), %rsi
incq %rsi
movq 0x98(%rsp), %rdi
cmpq %rdi, %rsi
movq 0x50(%rsp), %r14
movq 0x78(%rsp), %rdx
jb 0xba8e
leaq 0x1(%rdx), %rax
incl 0x40(%rsp)
incl 0x44(%rsp)
incl 0x48(%rsp)
incl 0x4c(%rsp)
cmpq 0x120(%rsp), %rdx
movq %rax, %rdx
jl 0xba0d
leaq 0x1(%rdi), %rax
movl 0x62114(%r14), %ecx
movq 0x10(%rsp), %rsi
addl %esi, %ecx
movl 0x62110(%r14), %edx
cmpl %ecx, %edx
cmovll %edx, %ecx
movslq %ecx, %rcx
incl 0x38(%rsp)
incl 0x3c(%rsp)
cmpq %rcx, %rdi
movq %rax, %rdi
jl 0xb94f
incq %rsi
movslq 0x62110(%r14), %rax
leaq -0x5(%rax), %rcx
incq 0x60(%rsp)
incl 0x34(%rsp)
incl 0x2c(%rsp)
incl 0x24(%rsp)
incq 0x108(%rsp)
incl 0x30(%rsp)
incl 0x28(%rsp)
cmpq %rcx, %rsi
jl 0xb8e9
testl %eax, %eax
jle 0xc0f5
movq 0xe0(%rsp), %rsi
movq 0xb8(%rsp), %rbp
movq 0x68(%rsp), %rcx
movq (%rcx), %r8
movq 0x70(%rsp), %rcx
movq (%rcx), %r15
movl %eax, %r10d
movq 0x62140(%r14), %r11
xorl %ebx, %ebx
movsd 0x40aad(%rip), %xmm3    # 0x4c960
movq %r8, 0x8(%rsp)
movq %rsi, 0x58(%rsp)
movq %r10, 0xa8(%rsp)
movq %r11, 0xa0(%rsp)
movl $0x1, %r12d
movl %ebx, %ecx
shlq %cl, %r12
movq %rbx, %r14
shrq $0x6, %r14
movq (%rsi,%r14,8), %r13
btq %rbx, %r13
jae 0xbf2e
testq %r12, (%rbp,%r14,8)
je 0xbf29
movsd (%r8,%rbx,8), %xmm0
movsd (%r15,%rbx,8), %xmm1
callq 0xabc8
movsd 0x40a57(%rip), %xmm3    # 0x4c960
movq 0xa0(%rsp), %r11
movq 0xa8(%rsp), %r10
movq 0x8(%rsp), %r8
movq 0x58(%rsp), %rsi
movsd %xmm0, (%r8,%rbx,8)
testq %r12, %r13
jne 0xbf4a
testq %r12, (%rbp,%r14,8)
je 0xbf41
movsd (%r15,%rbx,8), %xmm0
movsd %xmm0, (%r8,%rbx,8)
testq %r12, %r13
je 0xc014
movsd (%r8,%rbx,8), %xmm1
subsd (%r11,%r10,8), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm3
jae 0xc00e
ucomisd 0x409fc(%rip), %xmm1    # 0x4c968
movsd 0x40a14(%rip), %xmm0    # 0x4c988
jae 0xc00e
movsd 0xdf44e(%rip), %xmm0    # 0xeb3d0
mulsd %xmm1, %xmm0
addsd 0x409e2(%rip), %xmm0    # 0x4c970
movq %xmm0, %rax
movl %eax, %ecx
andl $0x7ff, %ecx            # imm = 0x7FF
addsd 0x409d5(%rip), %xmm0    # 0x4c978
mulsd 0xdf42d(%rip), %xmm0    # 0xeb3d8
subsd %xmm1, %xmm0
shlq $0x29, %rax
movabsq $-0x10000000000000, %rdx # imm = 0xFFF0000000000000
andq %rdx, %rax
movsd 0xdb3f8(%rip), %xmm1    # 0xe73c0
subsd %xmm0, %xmm1
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
mulsd 0xdb3d0(%rip), %xmm2    # 0xe73b0
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
addq %rdx, %rax
subsd %xmm0, %xmm2
addsd 0xdb3a7(%rip), %xmm2    # 0xe73a0
leaq 0xdb3a0(%rip), %rdx     # 0xe73a0
orq 0x30(%rdx,%rcx,8), %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, (%r8,%rbx,8)
testq %r12, (%rbp,%r14,8)
je 0xc0e9
movsd (%r15,%rbx,8), %xmm1
subsd (%r11,%r10,8), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm3
jae 0xc0e3
ucomisd 0x40927(%rip), %xmm1    # 0x4c968
movsd 0x4093f(%rip), %xmm0    # 0x4c988
jae 0xc0e3
movsd 0xdf379(%rip), %xmm0    # 0xeb3d0
mulsd %xmm1, %xmm0
addsd 0x4090d(%rip), %xmm0    # 0x4c970
movq %xmm0, %rax
movl %eax, %ecx
andl $0x7ff, %ecx            # imm = 0x7FF
addsd 0x40900(%rip), %xmm0    # 0x4c978
mulsd 0xdf358(%rip), %xmm0    # 0xeb3d8
subsd %xmm1, %xmm0
shlq $0x29, %rax
movabsq $-0x10000000000000, %rdx # imm = 0xFFF0000000000000
andq %rdx, %rax
movsd 0xdb323(%rip), %xmm1    # 0xe73c0
subsd %xmm0, %xmm1
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
mulsd 0xdb2fb(%rip), %xmm2    # 0xe73b0
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
addq %rdx, %rax
subsd %xmm0, %xmm2
addsd 0xdb2d2(%rip), %xmm2    # 0xe73a0
leaq 0xdb2cb(%rip), %rdx     # 0xe73a0
orq 0x30(%rdx,%rcx,8), %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, (%r15,%rbx,8)
incq %rbx
cmpq %rbx, %r10
jne 0xbecd
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0xc13a
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
xorl %eax, %eax
movq %rax, 0xb8(%rsp)
movl %eax, 0xc0(%rsp)
movq %rax, 0xc8(%rsp)
movl %eax, 0xd0(%rsp)
movq %rax, 0xd8(%rsp)
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0xc17f
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
xorl %eax, %eax
movq %rax, 0xe0(%rsp)
movl %eax, 0xe8(%rsp)
movq %rax, 0xf0(%rsp)
movl %eax, 0xf8(%rsp)
movq %rax, 0x100(%rsp)
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0xc1de
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
xorl %eax, %eax
movq %rax, 0xb8(%rsp)
movl %eax, 0xc0(%rsp)
movq %rax, 0xc8(%rsp)
movl %eax, 0xd0(%rsp)
movq %rax, 0xd8(%rsp)
jmp 0xc1de
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0xc223
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
xorl %eax, %eax
movq %rax, 0xe0(%rsp)
movl %eax, 0xe8(%rsp)
movq %rax, 0xf0(%rsp)
movl %eax, 0xf8(%rsp)
movq %rax, 0x100(%rsp)
movq %rbx, %rdi
callq 0x33e0
nop