// File: 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
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x118(%rbp)
cmpb $0x0, 0x1761b(%rip)     # 0x1b2e0
jne 0x3d68
leaq 0x1760e(%rip), %rdi     # 0x1b2e0
callq 0x3460
cmpl $0x0, %eax
je 0x3d68
callq 0xa470
movq %rsp, %rax
fstpt (%rax)
callq 0xa440
fstpt -0x124(%rbp)
jmp 0x3cf7
fldt -0x124(%rbp)
flds 0xf305(%rip)            # 0x13008
fmulp %st, %st(1)
flds 0xf2f9(%rip)            # 0x13004
faddp %st, %st(1)
movq %rsp, %rax
fstpt (%rax)
callq 0xa410
fstpt -0x130(%rbp)
jmp 0x3d1f
fldt -0x130(%rbp)
fnstcw -0x10a(%rbp)
movzwl -0x10a(%rbp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, -0x10c(%rbp)
fldcw -0x10c(%rbp)
fistpl -0x104(%rbp)
fldcw -0x10a(%rbp)
movl -0x104(%rbp), %eax
movl %eax, 0x1757c(%rip)     # 0x1b2d8
leaq 0x1757d(%rip), %rdi     # 0x1b2e0
callq 0x3170
movq -0x10(%rbp), %rax
fldt (%rax)
fldz
fucompi %st(1), %st
fstp %st(0)
ja 0x3d8a
jmp 0x3d78
movq -0x10(%rbp), %rax
fldt (%rax)
fld1
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jbe 0x3db3
jmp 0x3d8a
movl $0x0, -0x20(%rbp)
jmp 0x3e47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq 0x17537(%rip), %rdi     # 0x1b2e0
callq 0x3160
jmp 0x40ab
movq -0x10(%rbp), %rax
fldt (%rax)
fstpt -0x13c(%rbp)
callq 0xa470
fldt -0x13c(%rbp)
fld %st(1)
fstp %st(0)
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jbe 0x3de3
jmp 0x3dd8
movl 0x174fa(%rip), %eax     # 0x1b2d8
movl %eax, -0x20(%rbp)
jmp 0x3e45
movq -0x10(%rbp), %rax
fldt (%rax)
movq %rsp, %rax
fstpt (%rax)
callq 0xa440
flds 0xf20f(%rip)            # 0x13008
fmulp %st, %st(1)
flds 0xf203(%rip)            # 0x13004
faddp %st, %st(1)
movq %rsp, %rax
fstpt (%rax)
callq 0xa410
fld %st(0)
fstp %st(0)
fnstcw -0x10e(%rbp)
movzwl -0x10e(%rbp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, -0x110(%rbp)
fldcw -0x110(%rbp)
fistpl -0x108(%rbp)
fldcw -0x10e(%rbp)
movl -0x108(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x3e47
movq -0x118(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0xa480
movq -0x118(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0xa4e0
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xa4b0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x13d(%rbp)
jne 0x3e85
jmp 0x3e97
leaq -0x40(%rbp), %rdi
callq 0xa510
movb 0x38(%rax), %al
movb %al, -0x13d(%rbp)
movb -0x13d(%rbp), %al
testb $0x1, %al
jne 0x3ea3
jmp 0x3eb4
leaq -0x80(%rbp), %rdi
leaq -0x40(%rbp), %rsi
xorl %edx, %edx
callq 0xa530
jmp 0x3e57
movq -0x118(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0xa4e0
leaq -0xa0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xa570
testb $0x1, %al
jne 0x3edd
jmp 0x3f34
movq 0x1710c(%rip), %rdi     # 0x1aff0
leaq 0xf434(%rip), %rsi      # 0x1331f
callq 0x3240
movq %rax, %rdi
movl $0xda, %esi
callq 0x3420
movq %rax, %rdi
leaq 0xf426(%rip), %rsi      # 0x1332d
callq 0x3240
movq %rax, %rdi
movq 0x17092(%rip), %rsi     # 0x1afa8
callq 0x3280
movq %rax, %rdi
movq 0x17083(%rip), %rsi     # 0x1afa8
callq 0x3280
movl $0x2, %edi
callq 0x3330
movq -0x10(%rbp), %rax
fldt (%rax)
fstpt -0x150(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xa510
fldt -0x150(%rbp)
fstpt 0x10(%rax)
movl -0x20(%rbp), %eax
movl %eax, -0x144(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xa510
movl -0x144(%rbp), %ecx
movl %ecx, 0x34(%rax)
leaq -0x40(%rbp), %rdi
callq 0xa510
movq -0x118(%rbp), %rsi
movb $0x1, 0x38(%rax)
leaq -0xc0(%rbp), %rdi
callq 0xa480
leaq -0x40(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xa4b0
testb $0x1, %al
jne 0x3fa6
jmp 0x40a2
leaq -0xe0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xa5a0
leaq -0x100(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
xorl %edx, %edx
callq 0xa5e0
leaq -0xe0(%rbp), %rdi
callq 0xa510
movq (%rax), %rax
movq %rax, -0x158(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xa510
movq %rax, %rcx
movq -0x158(%rbp), %rax
cmpq (%rcx), %rax
jne 0x408a
leaq -0xe0(%rbp), %rdi
callq 0xa510
movq 0x28(%rax), %rax
addq $0x1, %rax
movq %rax, -0x160(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xa510
movq %rax, %rcx
movq -0x160(%rbp), %rax
cmpq 0x28(%rcx), %rax
jne 0x408a
leaq -0xe0(%rbp), %rdi
callq 0xa510
movl 0x34(%rax), %eax
movl %eax, -0x164(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xa510
movq %rax, %rcx
movl -0x164(%rbp), %eax
cmpl 0x34(%rcx), %eax
jne 0x408a
leaq -0xe0(%rbp), %rdi
callq 0xa510
movq 0x20(%rax), %rax
movq %rax, -0x170(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xa510
movq -0x170(%rbp), %rcx
movq %rcx, 0x20(%rax)
jmp 0x4096
movq -0x118(%rbp), %rdi
callq 0xa620
movq -0x118(%rbp), %rdi
callq 0xa770
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x3430
nopw %cs:(%rax,%rax)