// File: /workspace/github_c_makefile_star2_O2/fukunagatsu[P]RIblast/raccess.cpp
// Function: Raccess::CalcHairpinProbability(std::vector<double, std::allocator<double>>&, std::vector<double, std::allocator<double>>&)
void Raccess::CalcHairpinProbability(vector<double> &hairpin_probability, vector<double> &conditional_hairpin_probability){
  int w = _min_accessible_length;
  for(int x = 1; x+w-1 <=_seq_length;x++){
    double temp = 0.0;
    double c_temp = 0.0;
    int type = 0;
    bool flag = 0;
    bool c_flag = 0;
    double h_energy = 0.0;
    
    for(int i = max(1,x-_maximal_span);i<x ;i++){
      for(int j = x+w; j<=min(i+_maximal_span,_seq_length);j++){
	type = BP_pair[_int_sequence[i]][_int_sequence[j]];
	if(_Beta_stemend[i][j-i-1] != -INF){
	  h_energy = _Beta_stemend[i][j-i-1] + HairpinEnergy(type, i,j);
	  if(j == x+w){
	    temp = flag == 1 ? logsumexp(temp, h_energy) : h_energy;
	    flag = 1;
	  }else{
	    c_temp = c_flag == 1 ? logsumexp(c_temp, h_energy) :  h_energy;
	    c_flag = 1;
	  }
	}
      }
    }

    if(flag == 1 && c_flag == 1){
      temp = logsumexp(temp, c_temp);
    }
    if(flag == 0 && c_flag == 1){
      temp = c_temp;
      flag = 1;
    }
    if(flag == 1){
      hairpin_probability[x-1] = fmath::expd(temp-_Alpha_outer[_seq_length]);
    }
    if(c_flag == 1){
      conditional_hairpin_probability[x-1] = fmath::expd(c_temp-_Alpha_outer[_seq_length]);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movslq 0x62118(%rdi), %rcx
movq %rcx, %rax
shlq $0x20, %rax
movq %rax, 0x28(%rsp)
leal 0x1(%rcx), %eax
movl %eax, 0x24(%rsp)
pushq $0x1
popq %rbx
movq %rcx, 0x48(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdi, 0x10(%rsp)
movq 0x48(%rsp), %rax
leaq (%rbx,%rax), %rcx
decq %rcx
movslq 0x62110(%rdi), %rax
cmpq %rax, %rcx
jg 0xa55c
incq 0x30(%rsp)
movl 0x62114(%rdi), %ecx
movl %ebx, %r12d
subl %ecx, %r12d
cmpl $0x2, %r12d
pushq $0x1
popq %rsi
cmovll %esi, %r12d
movl %ebx, %edx
subl %ecx, %edx
cmpl $0x2, %edx
cmovll %esi, %edx
shlq $0x20, %rdx
movq 0x28(%rsp), %rsi
subq %rdx, %rsi
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %r15d, %r15d
movsd %xmm0, 0x18(%rsp)
movl $0x0, 0x4(%rsp)
movq %rbx, 0x50(%rsp)
cmpq %rbx, %r12
jae 0xa487
movl 0x24(%rsp), %ebp
xorl %r13d, %r13d
movq %rsi, 0x58(%rsp)
movq %rsi, %rbx
movq 0x30(%rsp), %r14
leal (%rcx,%r12), %edx
cmpl %edx, %eax
cmovll %eax, %edx
movslq %edx, %rdx
cmpq %rdx, %r14
jg 0xa468
movq 0x62218(%rdi), %rax
imulq $0x18, %r12, %rcx
movq (%rax,%rcx), %rax
movq %rbx, %rcx
sarq $0x1d, %rcx
movsd (%rax,%rcx), %xmm0
ucomisd 0x3d583(%rip), %xmm0    # 0x47930
jne 0xa3b1
jnp 0xa40a
movq 0x620f8(%rdi), %rax
movslq (%rax,%r12,4), %rcx
movslq (%rax,%r14,4), %rax
imulq $0x14, %rcx, %rcx
leaq 0x3d615(%rip), %rdx     # 0x479e0
addq %rdx, %rcx
movl (%rcx,%rax,4), %esi
movl %r12d, %edx
movl %ebp, %ecx
movsd %xmm0, 0x60(%rsp)
callq 0x9570
movsd 0x60(%rsp), %xmm1
addsd %xmm0, %xmm1
testq %r13, %r13
je 0xa40c
testb $0x1, 0x4(%rsp)
je 0xa429
movsd 0x18(%rsp), %xmm0
callq 0x94a2
movsd %xmm0, 0x18(%rsp)
jmp 0xa42f
jmp 0xa442
movl %r15d, %eax
movb $0x1, %r15b
testb $0x1, %al
je 0xa437
movsd 0x8(%rsp), %xmm0
callq 0x94a2
movsd %xmm0, 0x8(%rsp)
jmp 0xa43d
movsd %xmm1, 0x18(%rsp)
movb $0x1, %al
movl %eax, 0x4(%rsp)
jmp 0xa43d
movsd %xmm1, 0x8(%rsp)
movq 0x10(%rsp), %rdi
incq %r14
movl 0x62110(%rdi), %eax
movl 0x62114(%rdi), %ecx
movabsq $0x100000000, %rdx      # imm = 0x100000000
addq %rdx, %rbx
decq %r13
incl %ebp
jmp 0xa375
incq %r12
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
movq 0x58(%rsp), %rsi
addq %rdx, %rsi
movq 0x50(%rsp), %rbx
jmp 0xa358
testb $0x1, %r15b
je 0xa4b5
movl 0x4(%rsp), %ebp
testb $0x1, %bpl
je 0xa4b9
movsd 0x8(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
callq 0x94a2
movq 0x10(%rsp), %rdi
movsd %xmm0, 0x8(%rsp)
jmp 0xa4b9
movl 0x4(%rsp), %ebp
testb $0x1, %r15b
jne 0xa4d7
movsd 0x18(%rsp), %xmm0
testb $0x1, %bpl
jne 0xa4d1
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
je 0xa50a
movslq 0x62110(%rdi), %rax
movq 0x62140(%rdi), %rcx
movsd 0x8(%rsp), %xmm0
subsd (%rcx,%rax,8), %xmm0
callq 0xa856
movq 0x10(%rsp), %rdi
movq 0x38(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, -0x8(%rax,%rbx,8)
testb $0x1, %bpl
je 0xa541
movslq 0x62110(%rdi), %rax
movq 0x62140(%rdi), %rcx
movsd 0x18(%rsp), %xmm0
subsd (%rcx,%rax,8), %xmm0
callq 0xa856
movq 0x10(%rsp), %rdi
movq 0x40(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, -0x8(%rax,%rbx,8)
incq %rbx
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, 0x28(%rsp)
incl 0x24(%rsp)
jmp 0xa2ea
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop