// File: /workspace/github_c_makefile_star2_O2/fukunagatsu[P]RIblast/raccess.cpp
// Function: Raccess::CalcBulgeAndInternalProbability(std::vector<double, std::allocator<double>>&, std::vector<double, std::allocator<double>>&)
void Raccess::CalcBulgeAndInternalProbability(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 = fmath::expd(_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] += temp;		   
		  }else{
		    conditional_biloop_probability[k-1] += temp;		  
		  }
		}
		
		for(int k = q+1; k <= j-w;k++){
		  if(k == j-w){
		    biloop_probability[k-1] += temp;
		  }else{
		    conditional_biloop_probability[k-1] += temp;
		  }
		}
	      } 
	    }
	  }
	}
      }
    }
  }
  
  for(int i=0;i<_seq_length;i++){
    if(biloop_probability[i] != 0){
      biloop_probability[i] = fmath::log((float)(biloop_probability[i] + conditional_biloop_probability[i]));
      biloop_probability[i] = fmath::expd(biloop_probability[i]-_Alpha_outer[_seq_length]);
    }
    if(conditional_biloop_probability[i] != 0){
      conditional_biloop_probability[i] = fmath::log((float)(conditional_biloop_probability[i]));
      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, 0x18(%rsp)
andl $0x0, 0x8(%rax)
movq %rsi, 0x20(%rsp)
andq $0x0, 0x10(%rax)
movq %rdi, %rbx
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(%rbx), %rsi
xorl %edx, %edx
callq 0xa94a
movslq 0x62118(%rbx), %rcx
movl 0x62110(%rbx), %eax
pushq $0x2
popq %rdx
subl %ecx, %edx
movl %edx, 0x34(%rsp)
movq %rcx, 0x68(%rsp)
notq %rcx
movq %rcx, 0x78(%rsp)
pushq $0x2
popq %rcx
movq %rcx, 0x38(%rsp)
pushq $0x6
popq %rcx
movl %ecx, 0x30(%rsp)
pushq $-0x18
popq %rcx
movl %ecx, 0x2c(%rsp)
pushq $0x7
popq %rdx
pushq $0x1
popq %r9
pushq $0x8
popq %rcx
movq %rcx, 0x70(%rsp)
leaq 0x3e2f2(%rip), %r11     # 0x479e0
movsd 0x3e23a(%rip), %xmm2    # 0x47930
movq %rbx, %rdi
movq %rbx, 0x10(%rsp)
leal -0x5(%rax), %ecx
movslq %ecx, %rcx
cmpq %rcx, %r9
jge 0x9a37
movl %edx, 0x4c(%rsp)
movslq %edx, %r8
movq 0x78(%rsp), %rcx
leaq (%rcx,%r8), %r14
leaq 0x1(%r9), %r10
movq %r9, %rcx
notq %rcx
movq %rcx, 0xc0(%rsp)
leal 0x1f(%r9), %ecx
movl %ecx, 0x50(%rsp)
movl 0x2c(%rsp), %esi
movq %r9, 0x90(%rsp)
movq %r10, 0x88(%rsp)
movl 0x62114(%rdi), %ecx
addl %r9d, %ecx
cmpl %ecx, %eax
cmovll %eax, %ecx
movslq %ecx, %rcx
cmpq %rcx, %r8
jg 0x9a12
movq 0x620f8(%rdi), %rcx
movslq (%rcx,%r9,4), %rdx
movslq (%rcx,%r8,4), %rcx
imulq $0x14, %rdx, %rdx
addq %r11, %rdx
movl (%rdx,%rcx,4), %ecx
movl %ecx, 0x60(%rsp)
testl %ecx, %ecx
je 0x9a05
leal -0x5(%r8), %eax
movl 0x50(%rsp), %ecx
cmpl %ecx, %eax
cmovgel %ecx, %eax
movq %r8, %r13
subq 0x68(%rsp), %r13
cltq
movq %rax, 0x80(%rsp)
leal -0x1(%r8), %eax
movl %eax, 0x64(%rsp)
movl 0x34(%rsp), %eax
movl %eax, %r15d
movq 0x38(%rsp), %rdx
movl %esi, 0x54(%rsp)
movl %esi, %eax
movl 0x30(%rsp), %ecx
movq %r8, 0x98(%rsp)
cmpq 0x80(%rsp), %rdx
jg 0x99fb
movl %r15d, %r15d
cmpl %eax, %ecx
movl %eax, 0x5c(%rsp)
movl %ecx, 0x58(%rsp)
cmovgl %ecx, %eax
movslq %eax, %rbp
leaq -0x1(%rdx), %rax
movq %rax, 0xa8(%rsp)
movq %rdx, %rbx
subq 0x68(%rsp), %rbx
movl %ebx, %eax
movq %rax, 0xa0(%rsp)
movq %rdx, 0x40(%rsp)
cmpq %r8, %rbp
jae 0x99e4
cmpq %r10, %rdx
sete %cl
movq 0x620f8(%rdi), %rax
movslq (%rax,%rdx,4), %rdx
movslq (%rax,%rbp,4), %rax
imulq $0x14, %rdx, %rdx
addq %r11, %rdx
movslq (%rdx,%rax,4), %rax
cmpl %ebp, 0x64(%rsp)
sete %dl
testq %rax, %rax
je 0x99d7
andb %dl, %cl
jne 0x99d7
movq 0x62218(%rdi), %rcx
imulq $0x18, %r9, %rdx
leaq (,%r8,8), %rsi
addq (%rcx,%rdx), %rsi
movq 0xc0(%rsp), %rcx
movsd (%rsi,%rcx,8), %xmm1
ucomisd %xmm2, %xmm1
jne 0x9884
jnp 0x99d7
movq 0x62158(%rdi), %rcx
imulq $0x18, 0xa8(%rsp), %rsi
movl %ebp, %r12d
subl 0x40(%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 %xmm2, %xmm0
jne 0x98c9
jnp 0x99d7
leaq 0x3e180(%rip), %rcx     # 0x47a50
movl (%rcx,%rax,4), %edx
sarq $0x20, %r12
movl %ebp, (%rsp)
movq %rsi, 0xb8(%rsp)
movl 0x60(%rsp), %esi
movl %r9d, %ecx
movq 0x40(%rsp), %r9
movsd %xmm1, 0xb0(%rsp)
callq 0x918e
addsd 0xb0(%rsp), %xmm0
movq 0x10(%rsp), %rax
movq 0x62158(%rax), %rax
movq 0xb8(%rsp), %rcx
movq (%rax,%rcx), %rax
addsd (%rax,%r12,8), %xmm0
callq 0xa856
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0xa0(%rsp), %rcx
leaq (%rax,%rcx,8), %rax
addq $-0x8, %rax
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
addq 0x70(%rsp), %rcx
movq 0x38(%rsp), %rdx
movq 0x10(%rsp), %rdi
leaq 0x3e082(%rip), %r11     # 0x479e0
movsd 0x3dfca(%rip), %xmm2    # 0x47930
movq 0x90(%rsp), %r9
movq 0x88(%rsp), %r10
movq 0x98(%rsp), %r8
cmpq %rbx, %rdx
jg 0x99a2
cmpq %rdx, %r15
movq %rcx, %rsi
cmoveq %rax, %rsi
movsd (%rsi), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsi)
incq %rdx
addq $0x8, %rcx
jmp 0x997e
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
movq %rbp, %rdx
cmpq %r13, %rdx
jge 0x99d7
cmpq %rdx, %r14
movq %rax, %rsi
cmoveq %rcx, %rsi
movsd (%rsi,%rdx,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsi,%rdx,8)
incq %rdx
jmp 0x99b5
incq %rbp
movq 0x40(%rsp), %rdx
jmp 0x9813
incq %rdx
movl 0x58(%rsp), %ecx
incl %ecx
movl 0x5c(%rsp), %eax
incl %eax
incl %r15d
jmp 0x97cf
movl 0x62110(%rdi), %eax
movl 0x54(%rsp), %esi
incq %r8
incl %esi
incq %r14
jmp 0x974b
incq 0x38(%rsp)
incl 0x30(%rsp)
incl 0x2c(%rsp)
movl 0x4c(%rsp), %edx
incl %edx
addq $0x8, 0x70(%rsp)
incl 0x34(%rsp)
movq %r10, %r9
jmp 0x96fe
xorl %ebx, %ebx
cltq
cmpq %rax, %rbx
jge 0x9b23
movq 0x20(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%rbx,8), %xmm0
ucomisd 0x3deef(%rip), %xmm0    # 0x47948
movq 0x18(%rsp), %rax
movq (%rax), %rax
jne 0x9a65
jnp 0x9abb
addsd (%rax,%rbx,8), %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0xa80c
cvtss2sd %xmm0, %xmm0
movq 0x20(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, (%rax,%rbx,8)
movq 0x10(%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,%rbx,8)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rdi
movsd (%rax,%rbx,8), %xmm0
ucomisd 0x3de80(%rip), %xmm0    # 0x47948
jne 0x9acc
jnp 0x9b15
cvtsd2ss %xmm0, %xmm0
callq 0xa80c
cvtss2sd %xmm0, %xmm0
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, (%rax,%rbx,8)
movq 0x10(%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,%rbx,8)
movq 0x10(%rsp), %rdi
incq %rbx
movl 0x62110(%rdi), %eax
jmp 0x9a39
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 0x9b58
movq %rax, %rbx
jmp 0x9b68
jmp 0x9b58
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0xa9b8
leaq 0xf0(%rsp), %rdi
callq 0xa9b8
movq %rbx, %rdi
callq 0x33a0
nop