// File: /workspace/github_c_makefile_star2_O2/fukunagatsu[P]RIblast/raccess.cpp
// Function: Raccess::CalcAccessibility(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void Raccess::CalcAccessibility(string &sequence){
  double prob = 0.0;
  float accessibility = 0.0;
  vector<float> accessibility_array; accessibility_array.resize(_seq_length, 0.0);

  vector<double> biloop_probability; biloop_probability.resize(_seq_length, 0.0);
  vector<double> conditional_biloop_probability; conditional_biloop_probability.resize(_seq_length, 0.0);
  vector<double> hairpin_probability; hairpin_probability.resize(_seq_length, 0.0);
  vector<double> conditional_hairpin_probability; conditional_hairpin_probability.resize(_seq_length, 0.0);

  double pf = _Alpha_outer[_seq_length];
  if(pf >= -690 && pf <= 690){
    CalcBulgeAndInternalProbability(biloop_probability, conditional_biloop_probability);
  }else{
    CalcLogSumBulgeAndInternalProbability(biloop_probability, conditional_biloop_probability);
  }
  
  CalcHairpinProbability(hairpin_probability, conditional_hairpin_probability);
  
  ofstream of(_db_name.c_str(), ios::out | ios::binary | ios::app);
  int count = _seq_length - _min_accessible_length + 1;
  of.write(reinterpret_cast<const char*>(&count), sizeof(int));
  for(int i = 1; i <=count;i++){
    prob += CalcExteriorProbability(i,_min_accessible_length);
    prob += hairpin_probability[i-1];
    prob += biloop_probability[i-1];
    prob += CalcMultiProbability(i,_min_accessible_length);
    accessibility = (-fmath::log((float)prob)*kT)/1000;
    accessibility_array[i-1] = accessibility;
    of.write(reinterpret_cast<const char*>(&accessibility), sizeof(float));
    prob = 0.0;
  }
 
  count = _seq_length;
  of.write(reinterpret_cast<const char*>(&count), sizeof(int));
  float conditional_accessibility = 0.0;
  for(int i = 0; i < _min_accessible_length; i++){
    of.write(reinterpret_cast<const char*>(&conditional_accessibility), sizeof(float));
  }
  
  for(int i = 1; i+_min_accessible_length <=_seq_length;i++){
    prob += CalcExteriorProbability(i,_min_accessible_length+1);
    prob += conditional_hairpin_probability[i-1];
    prob += conditional_biloop_probability[i-1];
    prob += CalcMultiProbability(i,_min_accessible_length+1);
    conditional_accessibility = (-fmath::log((float)prob)*kT)/1000 - accessibility_array[i-1];
    of.write(reinterpret_cast<const char*>(&conditional_accessibility), sizeof(float));
    prob = 0.0;
  }
  of.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2c8, %rsp            # imm = 0x2C8
andl $0x0, 0x14(%rsp)
movq %rdi, %rbx
xorpd %xmm0, %xmm0
leaq 0xb0(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movslq 0x62110(%rbx), %rsi
leaq 0xc8(%rsp), %rdx
andl $0x0, (%rdx)
callq 0xa916
leaq 0x50(%rsp), %rdi
xorpd %xmm0, %xmm0
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movslq 0x62110(%rbx), %rsi
leaq 0xc8(%rsp), %rdx
andq $0x0, (%rdx)
callq 0xa746
xorpd %xmm0, %xmm0
leaq 0x30(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movslq 0x62110(%rbx), %rsi
leaq 0xc8(%rsp), %rdx
andq $0x0, (%rdx)
callq 0xa746
leaq 0x90(%rsp), %rdi
xorpd %xmm0, %xmm0
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movslq 0x62110(%rbx), %rsi
leaq 0xc8(%rsp), %rdx
andq $0x0, (%rdx)
callq 0xa746
xorpd %xmm0, %xmm0
leaq 0x70(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movslq 0x62110(%rbx), %rsi
leaq 0xc8(%rsp), %rdx
andq $0x0, (%rdx)
callq 0xa746
movslq 0x62110(%rbx), %rax
movq 0x62140(%rbx), %rcx
movsd (%rcx,%rax,8), %xmm0
andpd 0x3f1f5(%rip), %xmm0    # 0x479b0
movsd 0x3f175(%rip), %xmm1    # 0x47938
ucomisd %xmm0, %xmm1
jae 0x87dd
leaq 0x50(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
callq 0x9b7e
jmp 0x87ef
leaq 0x50(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
callq 0x9626
leaq 0x90(%rsp), %rsi
leaq 0x70(%rsp), %rdx
movq %rbx, %rdi
callq 0xa2a6
movq 0x62120(%rbx), %rsi
leaq 0xc8(%rsp), %rdi
pushq $0x15
popq %rdx
callq 0x3220
movl 0x62110(%rbx), %eax
subl 0x62118(%rbx), %eax
incl %eax
leaq 0x10(%rsp), %rsi
movl %eax, (%rsi)
leaq 0xc8(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x32b0
pushq $0x1
popq %r14
leaq 0xc8(%rsp), %r15
leaq 0x14(%rsp), %r12
pushq $0x4
popq %r13
movslq 0x10(%rsp), %rax
cmpq %rax, %r14
jg 0x891c
movl 0x62118(%rbx), %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0xa56c
movsd %xmm0, 0x28(%rsp)
movq 0x90(%rsp), %rax
movsd -0x8(%rax,%r14,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x50(%rsp), %rax
movsd -0x8(%rax,%r14,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movl 0x62118(%rbx), %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0xa59e
movsd 0x28(%rsp), %xmm1
addsd 0x3f088(%rip), %xmm1    # 0x47948
addsd 0x20(%rsp), %xmm1
addsd 0x18(%rsp), %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
callq 0xa80c
cvtss2sd %xmm0, %xmm0
mulsd 0xda983(%rip), %xmm0    # 0xe3268
divsd 0x3f053(%rip), %xmm0    # 0x47940
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x14(%rsp)
movq 0xb0(%rsp), %rax
movss %xmm0, -0x4(%rax,%r14,4)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x32b0
incq %r14
jmp 0x8855
movl 0x62110(%rbx), %eax
leaq 0x10(%rsp), %rsi
movl %eax, (%rsi)
leaq 0xc8(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x32b0
leaq 0xc(%rsp), %r14
andl $0x0, (%r14)
xorl %ebp, %ebp
leaq 0xc8(%rsp), %r15
pushq $0x4
popq %r12
movl 0x62118(%rbx), %edx
cmpl %edx, %ebp
jge 0x896c
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x32b0
incl %ebp
jmp 0x8950
pushq $0x1
popq %r14
xorl %ebp, %ebp
leaq 0xc8(%rsp), %r15
leaq 0xc(%rsp), %r12
pushq $0x4
popq %r13
leal (%rdx,%r14), %eax
cmpl 0x62110(%rbx), %eax
jg 0x8a4e
incl %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0xa56c
movsd %xmm0, 0x28(%rsp)
movq 0x70(%rsp), %rax
movsd (%rax,%rbp,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x30(%rsp), %rax
movsd (%rax,%rbp,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movl 0x62118(%rbx), %edx
incl %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0xa59e
movsd 0x28(%rsp), %xmm1
addsd 0x3ef61(%rip), %xmm1    # 0x47948
addsd 0x20(%rsp), %xmm1
addsd 0x18(%rsp), %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
callq 0xa80c
cvtss2sd %xmm0, %xmm0
mulsd 0xda85c(%rip), %xmm0    # 0xe3268
divsd 0x3ef2c(%rip), %xmm0    # 0x47940
movq 0xb0(%rsp), %rax
cvtss2sd (%rax,%rbp,4), %xmm1
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x32b0
movl 0x62118(%rbx), %edx
incl %r14d
incq %rbp
jmp 0x8983
leaq 0xc8(%rsp), %rdi
callq 0x32f0
leaq 0xc8(%rsp), %rdi
callq 0x3310
leaq 0x70(%rsp), %rdi
callq 0x6a68
leaq 0x90(%rsp), %rdi
callq 0x6a68
leaq 0x30(%rsp), %rdi
callq 0x6a68
leaq 0x50(%rsp), %rdi
callq 0x6a68
leaq 0xb0(%rsp), %rdi
callq 0x47e2
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8ad7
jmp 0x8ace
jmp 0x8ace
movq %rax, %rbx
jmp 0x8af1
movq %rax, %rbx
jmp 0x8afe
movq %rax, %rbx
jmp 0x8b08
movq %rax, %rbx
jmp 0x8b12
jmp 0x8ad7
movq %rax, %rbx
jmp 0x8ae7
jmp 0x8ad7
jmp 0x8ad7
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x3310
leaq 0x70(%rsp), %rdi
callq 0x6a68
leaq 0x90(%rsp), %rdi
callq 0x6a68
leaq 0x30(%rsp), %rdi
callq 0x6a68
leaq 0x50(%rsp), %rdi
callq 0x6a68
leaq 0xb0(%rsp), %rdi
callq 0x47e2
movq %rbx, %rdi
callq 0x33a0
nop