// File: /workspace/github_c_makefile_star2_O2/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 $0x118, %rsp            # imm = 0x118
leaq 0xf0(%rsp), %rax
andq $0x0, (%rax)
movq %rdx, 0x20(%rsp)
andl $0x0, 0x8(%rax)
movq %rsi, 0x18(%rsp)
andq $0x0, 0x10(%rax)
movq %rdi, %r15
andl $0x0, 0x18(%rax)
andq $0x0, 0x20(%rax)
movslq 0x62110(%rdi), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0xa94a
leaq 0xc8(%rsp), %rdi
andq $0x0, (%rdi)
andl $0x0, 0x8(%rdi)
andq $0x0, 0x10(%rdi)
andl $0x0, 0x18(%rdi)
andq $0x0, 0x20(%rdi)
movslq 0x62110(%r15), %rsi
xorl %edx, %edx
callq 0xa94a
movslq 0x62118(%r15), %rcx
movl 0x62110(%r15), %eax
pushq $0x2
popq %rdx
subl %ecx, %edx
movl %edx, 0x44(%rsp)
movq %rcx, 0x80(%rsp)
notq %rcx
movq %rcx, 0xa0(%rsp)
pushq $0x2
popq %rcx
movq %rcx, 0x48(%rsp)
pushq $0x6
popq %rcx
movl %ecx, 0x40(%rsp)
pushq $-0x18
popq %rcx
movl %ecx, 0x3c(%rsp)
pushq $0x7
popq %rcx
movl %ecx, 0x38(%rsp)
pushq $0x1
popq %rdi
movq %r15, 0x28(%rsp)
leal -0x5(%rax), %ecx
movslq %ecx, %rcx
cmpq %rcx, %rdi
jge 0xa0e4
movslq 0x38(%rsp), %r8
movq 0xa0(%rsp), %rcx
addq %r8, %rcx
movq %rcx, 0x98(%rsp)
leaq 0x1(%rdi), %rcx
movq %rcx, 0x88(%rsp)
movq %rdi, %rcx
notq %rcx
movq %rcx, 0xc0(%rsp)
leal 0x1f(%rdi), %ecx
movl %ecx, 0x68(%rsp)
movl 0x3c(%rsp), %r9d
movq %rdi, 0x50(%rsp)
movl 0x62114(%r15), %ecx
addl %edi, %ecx
cmpl %ecx, %eax
cmovll %eax, %ecx
movslq %ecx, %rcx
cmpq %rcx, %r8
jg 0xa0c2
movq 0x620f8(%r15), %rcx
movslq (%rcx,%rdi,4), %rdx
movslq (%rcx,%r8,4), %rcx
imulq $0x14, %rdx, %rdx
leaq 0x3dd14(%rip), %rsi     # 0x479e0
addq %rsi, %rdx
movl (%rdx,%rcx,4), %ecx
movl %ecx, 0x78(%rsp)
testl %ecx, %ecx
je 0xa0af
leal -0x5(%r8), %eax
movl 0x68(%rsp), %ecx
cmpl %ecx, %eax
cmovgel %ecx, %eax
movq %r8, %r13
subq 0x80(%rsp), %r13
cltq
movq %rax, 0xa8(%rsp)
leal -0x1(%r8), %eax
movl %eax, 0x7c(%rsp)
movl 0x44(%rsp), %eax
movq %rax, 0x30(%rsp)
movq 0x48(%rsp), %rdx
movl %r9d, 0x6c(%rsp)
movl 0x40(%rsp), %ecx
movq %r8, 0x60(%rsp)
cmpq 0xa8(%rsp), %rdx
jg 0xa09e
movq 0x30(%rsp), %rax
movl %eax, %eax
movq %rax, 0x30(%rsp)
cmpl %r9d, %ecx
movl %r9d, 0x74(%rsp)
movl %r9d, %eax
movl %ecx, 0x70(%rsp)
cmovgl %ecx, %eax
movslq %eax, %rbx
leaq -0x1(%rdx), %rax
movq %rax, 0xb0(%rsp)
movq %rdx, %r14
subq 0x80(%rsp), %r14
movl %r14d, %ecx
movq %rcx, 0x90(%rsp)
leaq -0x1(%rcx), %rbp
movq %rdx, 0x58(%rsp)
cmpq %r8, %rbx
jae 0xa07c
cmpq 0x88(%rsp), %rdx
sete %cl
movq 0x620f8(%r15), %rax
movslq (%rax,%rdx,4), %rdx
movslq (%rax,%rbx,4), %rax
imulq $0x14, %rdx, %rdx
leaq 0x3dc34(%rip), %rsi     # 0x479e0
addq %rsi, %rdx
movslq (%rdx,%rax,4), %rax
cmpl %ebx, 0x7c(%rsp)
sete %dl
testq %rax, %rax
je 0xa065
andb %dl, %cl
jne 0xa065
movq 0x28(%rsp), %rcx
movq 0x62218(%rcx), %rcx
imulq $0x18, 0x50(%rsp), %rdx
movq 0x60(%rsp), %rsi
leaq (,%rsi,8), %rsi
addq (%rcx,%rdx), %rsi
movq 0xc0(%rsp), %rcx
movsd (%rsi,%rcx,8), %xmm0
movsd %xmm0, 0x10(%rsp)
ucomisd 0x3db27(%rip), %xmm0    # 0x47930
jne 0x9e11
jnp 0xa065
movq 0x28(%rsp), %rcx
movq 0x62158(%rcx), %rcx
imulq $0x18, 0xb0(%rsp), %rsi
movl %ebx, %r12d
subl 0x58(%rsp), %r12d
shlq $0x20, %r12
movabsq $0x100000000, %rdx      # imm = 0x100000000
addq %rdx, %r12
movq (%rcx,%rsi), %rcx
movq %r12, %rdx
sarq $0x1d, %rdx
movsd (%rcx,%rdx), %xmm0
ucomisd 0x3dad9(%rip), %xmm0    # 0x47930
jne 0x9e5f
jnp 0xa065
leaq 0x3dbea(%rip), %rcx     # 0x47a50
movl (%rcx,%rax,4), %edx
sarq $0x20, %r12
movl %ebx, (%rsp)
movq 0x28(%rsp), %r15
movq %r15, %rdi
movq %rsi, 0xb8(%rsp)
movl 0x78(%rsp), %esi
movq 0x50(%rsp), %rcx
movq 0x60(%rsp), %r8
movq 0x58(%rsp), %r9
callq 0x918e
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movq 0x62158(%r15), %rax
movq 0xb8(%rsp), %rcx
movq (%rax,%rcx), %rax
addsd (%rax,%r12,8), %xmm1
movsd %xmm1, 0x10(%rsp)
movq 0x48(%rsp), %r12
cmpq %r14, %r12
jg 0x9f9e
cmpq %r12, 0x30(%rsp)
jne 0x9f3a
leaq 0xf0(%rsp), %rdi
movq %rbp, %rsi
callq 0xa9c8
movsd 0x10(%rsp), %xmm0
testq %rdx, (%rax)
je 0x9f12
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x90(%rsp), %rcx
movsd -0x8(%rax,%rcx,8), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x94a2
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x90(%rsp), %rcx
movsd %xmm0, -0x8(%rax,%rcx,8)
leaq 0xf0(%rsp), %rdi
movq %rbp, %rsi
callq 0xa9c8
jmp 0x9f93
leaq -0x1(%r12), %r15
leaq 0xc8(%rsp), %rdi
movq %r15, %rsi
callq 0xa9c8
movsd 0x10(%rsp), %xmm0
testq %rdx, (%rax)
je 0x9f74
movq 0x20(%rsp), %rax
movq (%rax), %rax
movsd -0x8(%rax,%r12,8), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x94a2
movq 0x20(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, -0x8(%rax,%r12,8)
leaq 0xc8(%rsp), %rdi
movq %r15, %rsi
callq 0xa9c8
orq %rdx, (%rax)
incq %r12
jmp 0x9ec6
movq %rbx, %r15
cmpq %r13, %r15
jge 0xa065
cmpq %r15, 0x98(%rsp)
jne 0xa008
leaq 0xf0(%rsp), %rdi
movq %r15, %rsi
callq 0xa9c8
movsd 0x10(%rsp), %xmm0
testq %rdx, (%rax)
je 0x9fe8
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r15,8), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x94a2
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, (%rax,%r15,8)
leaq 0xf0(%rsp), %rdi
movq %r15, %rsi
callq 0xa9c8
jmp 0xa05a
leaq 0xc8(%rsp), %rdi
movq %r15, %rsi
callq 0xa9c8
movsd 0x10(%rsp), %xmm0
testq %rdx, (%rax)
je 0xa03c
movq 0x20(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r15,8), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x94a2
movq 0x20(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, (%rax,%r15,8)
leaq 0xc8(%rsp), %rdi
movq %r15, %rsi
callq 0xa9c8
orq %rdx, (%rax)
incq %r15
jmp 0x9fa1
incq %rbx
movq 0x28(%rsp), %r15
movq 0x60(%rsp), %r8
movq 0x58(%rsp), %rdx
jmp 0x9d7e
incq %rdx
movl 0x70(%rsp), %ecx
incl %ecx
movl 0x74(%rsp), %r9d
incl %r9d
movq 0x30(%rsp), %rax
incl %eax
movq %rax, 0x30(%rsp)
jmp 0x9d24
movl 0x62110(%r15), %eax
movq 0x50(%rsp), %rdi
movl 0x6c(%rsp), %r9d
incq %r8
incl %r9d
incq 0x98(%rsp)
jmp 0x9c98
incq 0x48(%rsp)
incl 0x40(%rsp)
incl 0x3c(%rsp)
incl 0x38(%rsp)
incl 0x44(%rsp)
movq 0x88(%rsp), %rdi
jmp 0x9c46
xorl %r15d, %r15d
leaq 0xf0(%rsp), %r12
leaq 0xc8(%rsp), %r13
cltq
cmpq %rax, %r15
jge 0xa232
movq %r12, %rdi
movq %r15, %rsi
callq 0xa9c8
testq %rdx, (%rax)
je 0xa151
movq %r13, %rdi
movq %r15, %rsi
callq 0xa9c8
testq %rdx, (%rax)
je 0xa151
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r15,8), %xmm0
movq 0x20(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r15,8), %xmm1
callq 0x94a2
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, (%rax,%r15,8)
movq %r12, %rdi
movq %r15, %rsi
callq 0xa9c8
testq %rdx, (%rax)
jne 0xa18d
movq %r13, %rdi
movq %r15, %rsi
callq 0xa9c8
testq %rdx, (%rax)
je 0xa18d
movq 0x20(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r15,8), %xmm0
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, (%rax,%r15,8)
movq %r12, %rdi
movq %r15, %rsi
callq 0xa9c8
testq %rdx, (%rax)
je 0xa1d6
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r15,8), %xmm0
movq 0x28(%rsp), %rcx
movslq 0x62110(%rcx), %rax
movq 0x62140(%rcx), %rcx
subsd (%rcx,%rax,8), %xmm0
callq 0xa856
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, (%rax,%r15,8)
movq %r13, %rdi
movq %r15, %rsi
callq 0xa9c8
testq %rdx, (%rax)
je 0xa21f
movq 0x20(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r15,8), %xmm0
movq 0x28(%rsp), %rcx
movslq 0x62110(%rcx), %rax
movq 0x62140(%rcx), %rcx
subsd (%rcx,%rax,8), %xmm0
callq 0xa856
movq 0x20(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
movq 0x28(%rsp), %rax
movl 0x62110(%rax), %eax
jmp 0xa0f7
leaq 0xc8(%rsp), %rdi
callq 0xa9b8
leaq 0xf0(%rsp), %rdi
callq 0xa9b8
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa281
jmp 0xa281
movq %rax, %rbx
jmp 0xa291
jmp 0xa281
jmp 0xa281
jmp 0xa281
jmp 0xa281
jmp 0xa281
jmp 0xa281
jmp 0xa281
jmp 0xa281
jmp 0xa281
jmp 0xa281
jmp 0xa281
jmp 0xa281
jmp 0xa281
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0xa9b8
leaq 0xf0(%rsp), %rdi
callq 0xa9b8
movq %rbx, %rdi
callq 0x33a0