// File: /workspace/github_cpp_makefile_star2_O2/Altius[P]hotspot2/src/hotspot2_part1.cpp
// Function: SiteManager::processPvalue(long double const&)
void SiteManager::processPvalue(const long double& pval
#ifdef DEBUG
				, const bool& sampled
#endif
				)
{
  static const int MAX_VALUE = static_cast<int>(floor(-log10(numeric_limits<long double>::min()) * CHANGE_OF_SCALE + 0.5));
  int negLog10P_scaled;
  if (pval < 0 || pval > 1)
    negLog10P_scaled = 0;
  else
    {
      if (pval < numeric_limits<long double>::min())
      	negLog10P_scaled = MAX_VALUE;
      else
	negLog10P_scaled = static_cast<int>(floor(-log10(pval) * CHANGE_OF_SCALE + 0.5));
    }
  deque<SiteRange>::iterator itCurSiteNeedingPval(m_sites.begin());
  while (itCurSiteNeedingPval != m_sites.end() && itCurSiteNeedingPval->hasPval)
    itCurSiteNeedingPval++;
  if (m_sites.end() == itCurSiteNeedingPval)
    {
      cerr << "Error:  line " << __LINE__ << ", m_sites is empty or already filled with P-values"
	   << endl << endl;
      exit(2);
    }

  itCurSiteNeedingPval->pval = pval;
  itCurSiteNeedingPval->negLog10P_scaled = negLog10P_scaled;
  itCurSiteNeedingPval->hasPval = true;
#ifdef DEBUG
  itCurSiteNeedingPval->sampled = sampled;
#endif

  if (itCurSiteNeedingPval != m_sites.begin())
    {
      deque<SiteRange>::iterator it_prev = itCurSiteNeedingPval;
      it_prev--;
      if (it_prev->chrom == itCurSiteNeedingPval->chrom && it_prev->endPos + 1 == itCurSiteNeedingPval->endPos &&
#ifdef DEBUG
	  it_prev->sampled == itCurSiteNeedingPval->sampled &&
#endif
	  it_prev->negLog10P_scaled == itCurSiteNeedingPval->negLog10P_scaled)
	itCurSiteNeedingPval->begPos = it_prev->begPos;
      else
	writeLastUnreportedSite();
      m_sites.pop_front();
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x80, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movb 0x99db(%rip), %al       # 0xc270
testb %al, %al
je 0x2a28
fldt (%r14)
fldz
fucompi %st(1), %st
seta %al
fld1
fxch %st(1)
fucomi %st(1), %st
fstp %st(1)
seta %cl
xorl %ebp, %ebp
orb %al, %cl
jne 0x290d
fldt 0x5772(%rip)            # 0x8030
fucompi %st(1), %st
jbe 0x28cc
fstp %st(0)
movl 0x999e(%rip), %ebp      # 0xc268
jmp 0x290b
fstpt (%rsp)
callq 0x2150
fmuls 0x572e(%rip)            # 0x8008
fadds 0x5724(%rip)            # 0x8004
fstpt (%rsp)
callq 0x20f0
fnstcw 0x10(%rsp)
movzwl 0x10(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x14(%rsp)
fldcw 0x14(%rsp)
fistpl 0x18(%rsp)
fldcw 0x10(%rsp)
movl 0x18(%rsp), %ebp
fldz
fstp %st(0)
movq 0x10(%rbx), %rax
leaq 0x20(%rsp), %r15
movq %rax, (%r15)
movups 0x18(%rbx), %xmm0
movups %xmm0, 0x8(%r15)
movq 0x28(%rbx), %rcx
movq %rcx, 0x18(%r15)
leaq 0x40(%rsp), %r12
cmpq 0x30(%rbx), %rax
je 0x29e1
cmpb $0x1, 0x38(%rax)
jne 0x2955
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x5c8e
movq 0x20(%rsp), %rax
jmp 0x2931
fldt (%r14)
fstpt 0x10(%rax)
movl %ebp, 0x34(%rax)
movb $0x1, 0x38(%rax)
cmpq 0x10(%rbx), %rax
je 0x29d1
leaq 0x40(%rsp), %r14
movq %rax, (%r14)
movups 0x28(%rsp), %xmm0
movups %xmm0, 0x8(%r14)
movq 0x38(%rsp), %rax
movq %rax, 0x18(%r14)
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x5cae
movq (%r14), %rax
movq (%rax), %rdx
movq 0x20(%rsp), %rcx
cmpq (%rcx), %rdx
jne 0x29c1
movq 0x28(%rax), %rdx
incq %rdx
cmpq 0x28(%rcx), %rdx
jne 0x29c1
movl 0x34(%rax), %edx
cmpl 0x34(%rcx), %edx
jne 0x29c1
movq 0x20(%rax), %rax
movq %rax, 0x20(%rcx)
jmp 0x29c9
movq %rbx, %rdi
callq 0x5cce
movq %rbx, %rdi
callq 0x5da6
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x9608(%rip), %rdi      # 0xbff0
leaq 0x5994(%rip), %rsi      # 0x8383
callq 0x21e0
movq %rax, %rdi
movl $0xda, %esi
callq 0x2340
leaq 0x5989(%rip), %rsi      # 0x8391
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20e0
pushq $0x2
popq %rdi
callq 0x2280
leaq 0x9841(%rip), %rdi      # 0xc270
callq 0x2370
testl %eax, %eax
je 0x289d
fldt 0x55ee(%rip)            # 0x8030
fstpt (%rsp)
callq 0x2150
fmuls 0x55b8(%rip)            # 0x8008
fadds 0x55ae(%rip)            # 0x8004
fstpt (%rsp)
callq 0x20f0
fnstcw 0x12(%rsp)
movzwl 0x12(%rsp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, 0x16(%rsp)
fldcw 0x16(%rsp)
fistpl 0x1c(%rsp)
fldcw 0x12(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x97e1(%rip)      # 0xc268
leaq 0x97e2(%rip), %rdi      # 0xc270
callq 0x2120
jmp 0x289d