// File: Altius[P]hotspot2/src/hotspot2_part1.cpp
// Function: BackgroundRegionManager::computePandFlush(SiteManager&)
void BackgroundRegionManager::computePandFlush(SiteManager& sm)
{
 if (m_distn.empty())
    return;

  if (!m_sliding || m_needToUpdate_kcutoff)
    {
      // Moving averages need to be computed, m_kcutoff needs to be determined,
      // mean and variance need to be computed, and all pmfs need to be computed.
      findCutoff();
    }

  computeStats(-1); // -1 means "for all observed values of k"

  while (!m_sitesInRegion_leftHalf.empty())
    {
      if (!m_sitesInRegion_leftHalf.front().hasPval)
        {
          long double pval;
          if (m_pmf != NULL)
            pval = getPvalue(m_sitesInRegion_leftHalf.front().count);
          else
            pval = 999.;
	  sm.processPvalue(pval // pass this P-value along to the corresponding site
#ifdef DEBUG
			   , m_sitesInRegion_leftHalf.front().sampled
#endif
			   );
	}
      m_sitesInRegion_leftHalf.pop_front();
    }
  while (!m_sitesInRegion_rightHalf.empty())
    {
      if (!m_sitesInRegion_rightHalf.front().hasPval)
        {
          long double pval;
          if (m_pmf != NULL)
            pval = getPvalue(m_sitesInRegion_rightHalf.front().count);
          else
            pval = 999.;
	  sm.processPvalue(pval // pass this P-value along to the corresponding site
#ifdef DEBUG
			   , m_sitesInRegion_rightHalf.front().sampled
#endif
			   );
        }
      m_sitesInRegion_rightHalf.pop_front();
    }

  m_distn.clear();
  m_posL = m_posC = m_posR = -1;
  m_pCurChrom = NULL;
  m_runningSum_count = m_runningSum_countSquared = 
    m_runningSum_count_duringPrevComputation = m_runningSum_countSquared_duringPrevComputation = 0;
  m_numPtsInNullRegion = m_numPtsInNullRegion_duringPrevComputation = 0;
  m_modeYval = m_modeXval = m_kcutoff = m_kTrendReversal = -1;
  m_sliding = false;
  m_needToUpdate_kcutoff = true;

  m_kvalsWithMinMAxN.clear();
  m_minMAxN = -1;

  m_prev_k = -1;
  m_pmf = NULL;
  m_pmfParams.clear();
  m_nextPosToSample = -1;
  m_sampledDataDistnSize = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x60(%rbp)
addq $0x50, %rdi
callq 0xac80
testb $0x1, %al
jne 0x5d27
jmp 0x5d2c
jmp 0x5f5b
movq -0x60(%rbp), %rax
testb $0x1, 0x118(%rax)
je 0x5d46
movq -0x60(%rbp), %rax
testb $0x1, 0x119(%rax)
je 0x5d4f
movq -0x60(%rbp), %rdi
callq 0x4660
movq -0x60(%rbp), %rdi
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
leaq -0x14(%rbp), %rsi
callq 0x4f10
movq -0x60(%rbp), %rdi
addq $0x68, %rdi
callq 0xacc0
xorb $-0x1, %al
testb $0x1, %al
jne 0x5d78
jmp 0x5de3
movq -0x60(%rbp), %rdi
addq $0x68, %rdi
callq 0xacf0
testb $0x1, 0x8(%rax)
jne 0x5dd4
movq -0x60(%rbp), %rax
cmpq $0x0, 0x168(%rax)
je 0x5dbe
movq -0x60(%rbp), %rdi
addq $0x68, %rdi
callq 0xacf0
movq -0x60(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, -0x34(%rbp)
leaq -0x34(%rbp), %rsi
callq 0x5870
fstpt -0x30(%rbp)
jmp 0x5dc7
flds 0xd248(%rip)            # 0x1300c
fstpt -0x30(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3ca0
movq -0x60(%rbp), %rdi
addq $0x68, %rdi
callq 0xad20
jmp 0x5d63
jmp 0x5de5
movq -0x60(%rbp), %rdi
addq $0xb8, %rdi
callq 0xacc0
xorb $-0x1, %al
testb $0x1, %al
jne 0x5dfd
jmp 0x5e74
movq -0x60(%rbp), %rdi
addq $0xb8, %rdi
callq 0xacf0
testb $0x1, 0x8(%rax)
jne 0x5e5f
movq -0x60(%rbp), %rax
cmpq $0x0, 0x168(%rax)
je 0x5e49
movq -0x60(%rbp), %rdi
addq $0xb8, %rdi
callq 0xacf0
movq -0x60(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, -0x54(%rbp)
leaq -0x54(%rbp), %rsi
callq 0x5870
fstpt -0x50(%rbp)
jmp 0x5e52
flds 0xd1bd(%rip)            # 0x1300c
fstpt -0x50(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3ca0
movq -0x60(%rbp), %rdi
addq $0xb8, %rdi
callq 0xad20
jmp 0x5de5
movq -0x60(%rbp), %rdi
addq $0x50, %rdi
callq 0xad90
movq -0x60(%rbp), %rdi
movl $0xffffffff, 0x4(%rdi)  # imm = 0xFFFFFFFF
movl $0xffffffff, 0x8(%rdi)  # imm = 0xFFFFFFFF
movl $0xffffffff, (%rdi)     # imm = 0xFFFFFFFF
movq $0x0, 0x188(%rdi)
movq $0x0, 0x30(%rdi)
movq $0x0, 0x28(%rdi)
movq $0x0, 0x18(%rdi)
movq $0x0, 0x10(%rdi)
movl $0x0, 0x38(%rdi)
movl $0x0, 0x20(%rdi)
movl $0xffffffff, 0x114(%rdi) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x110(%rdi) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x108(%rdi) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x10c(%rdi) # imm = 0xFFFFFFFF
movb $0x0, 0x118(%rdi)
movb $0x1, 0x119(%rdi)
addq $0x120, %rdi            # imm = 0x120
callq 0xaa40
movq -0x60(%rbp), %rdi
movl $0xffffffff, 0x150(%rdi) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x154(%rdi) # imm = 0xFFFFFFFF
movq $0x0, 0x168(%rdi)
addq $0x170, %rdi            # imm = 0x170
callq 0xab50
movq -0x60(%rbp), %rax
movl $0xffffffff, 0x15c(%rax) # imm = 0xFFFFFFFF
movl $0x0, 0x160(%rax)
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)