// File: /workspace/github_cpp_makefile_star2_O2/Altius[P]hotspot2/src/hotspot2_part1.cpp
// Function: BackgroundRegionManager::add(SiteRange const&)
void BackgroundRegionManager::add(const SiteRange& s)
{
  if (s.endPos > m_posR)
    {
      cerr << "Coding error:  BRM::add(), region " << *m_pCurChrom << ':' << m_posL << '-' << m_posR
           << " received out-of-bounds position " << s.endPos
           << " (line " << __LINE__ << " of the code)." << endl
           << endl;
      exit(1);
    }
  SiteData sd;
  sd.pos = s.endPos;
  sd.count = s.count;
  sd.hasPval = false;
  sd.sampled = false;

  if (1 != m_samplingInterval && s.endPos > m_nextPosToSample)
    m_nextPosToSample = s.endPos;

  // Alternatively, "sampling" could be performed strictly at multiples of m_samplingInterval.
  // If we intend to sample at, say, positions 200, 400, 600, 800, 1000, etc.,
  // and regions 390-402 and 598-620 are excluded (unmappable),
  // then the current code will sample at 200, 403, 621, 821, etc.
  // Sampling strictly at multiples of m_samplingInterval would in this case
  // sample at 200, 800, 1000, etc.
  // Use the following code if strict multiples of m_samplingInterval are desired.
  //
  // m_nextPosToSample += static_cast<int>(ceil(static_cast<double>(s.endPos - m_nextPosToSample)/static_cast<double>(m_samplingInterval))) * m_samplingInterval;
  //
  // The above is a one-step version of "while(s.endPos > m_nextPosToSample){m_nextPosToSample += m_samplingInterval;}."
  // Typically, m_nextPosToSample will only need to increase by m_samplingInterval;
  // it will need to increase by a greater multiple of m_samplingInterval when a large gap is present in the data
  // (an unmappable region or otherwise restricted/withheld region).

  if (1 == m_samplingInterval || s.endPos == m_nextPosToSample)
    {
      sd.sampled = true;
      m_nextPosToSample += m_samplingInterval;
      // Add the incoming site's count to the distribution of counts observed in this region.
      if (s.count < static_cast<int>(m_distn.size()))
        m_distn[s.count].numOccs++;
      else
        {
          StatsForCount sc;
          sc.numOccs = 0;
          sc.pmf = sc.pval = -1.;
          sc.MAxN = -1; // don't compute moving averages until/unless we're sliding, for efficiency's sake
          while (static_cast<int>(m_distn.size()) < s.count)
            {
              m_distn.push_back(sc); // create bins for unobserved interior values, e.g., count = 5 but only 0,1,2 have been observed so far
              m_sampledDataDistnSize++;
            }
          sc.numOccs = 1;
          m_distn.push_back(sc);
          m_sampledDataDistnSize++;
        }
      if ( static_cast<int>(m_distn.size()) >= m_MAlength && m_distn[s.count].MAxN != -1 && m_distn[s.count].MAxN >= m_modeYval)
        {
          m_modeXval = s.count;
          m_modeYval = m_distn[s.count].MAxN;
        }
    }

  // Add the incoming site to the appropriate deque of observed positions.
  if (s.endPos < m_posC)
    m_sitesInRegion_leftHalf.push_back(sd);
  else
    m_sitesInRegion_rightHalf.push_back(sd);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x28(%rsi), %rcx
movslq 0x4(%rdi), %rax
cmpq %rax, %rcx
jg 0x2da4
movl %ecx, 0x4(%rsp)
movl 0x30(%rbx), %eax
movl %eax, 0x8(%rsp)
andw $0x0, 0xc(%rsp)
movl 0x158(%r14), %edx
movl 0x15c(%r14), %esi
cmpl $0x1, %edx
je 0x2c9f
movslq %esi, %rdi
cmpq %rdi, %rcx
jle 0x2c96
movl %ecx, 0x15c(%r14)
movq %rcx, %rdi
movl %ecx, %esi
cmpq %rdi, %rcx
jne 0x2d74
movb $0x1, 0xd(%rsp)
addl %edx, %esi
movl %esi, 0x15c(%r14)
movq 0x50(%r14), %rcx
movq 0x58(%r14), %rdx
movq %rdx, %rsi
subq %rcx, %rsi
shrq $0x6, %rsi
cmpl %esi, %eax
jge 0x2cce
cltq
shlq $0x6, %rax
incl (%rcx,%rax)
jmp 0x2d43
leaq 0x10(%rsp), %r12
andl $0x0, (%r12)
leaq 0x50(%r14), %r15
fld1
fchs
fld %st(0)
fstpt 0x30(%rsp)
fstpt 0x20(%rsp)
orl $-0x1, 0x30(%r12)
subq %rcx, %rdx
shrq $0x6, %rdx
cmpl %edx, %eax
jle 0x2d1a
movq %r15, %rdi
movq %r12, %rsi
callq 0x5dc4
incl 0x160(%r14)
movq 0x50(%r14), %rcx
movq 0x58(%r14), %rdx
movl 0x30(%rbx), %eax
jmp 0x2cf0
leaq 0x10(%rsp), %rsi
movl $0x1, (%rsi)
movq %r15, %rdi
callq 0x5dc4
incl 0x160(%r14)
movq 0x50(%r14), %rcx
movq 0x58(%r14), %rsi
subq %rcx, %rsi
shrq $0x6, %rsi
cmpl %esi, 0x3c(%r14)
jg 0x2d74
movslq 0x30(%rbx), %rax
movq %rax, %rdx
shlq $0x6, %rdx
movl 0x30(%rcx,%rdx), %ecx
cmpl $-0x1, %ecx
je 0x2d74
cmpl 0x10c(%r14), %ecx
jl 0x2d74
movl %eax, 0x108(%r14)
movl %ecx, 0x10c(%r14)
movslq 0x8(%r14), %rax
leaq 0xb8(%r14), %rcx
addq $0x68, %r14
cmpq %rax, 0x28(%rbx)
cmovgeq %rcx, %r14
leaq 0x4(%rsp), %rsi
movq %r14, %rdi
callq 0x5dfa
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x9245(%rip), %rdi      # 0xbff0
leaq 0x5677(%rip), %rsi      # 0x8429
callq 0x21e0
movq 0x188(%r14), %rsi
movq %rax, %rdi
callq 0x21c0
pushq $0x3a
popq %rsi
movq %rax, %rdi
callq 0x2260
movl (%r14), %esi
movq %rax, %rdi
callq 0x2340
pushq $0x2d
popq %rsi
movq %rax, %rdi
callq 0x2260
movl 0x4(%r14), %esi
movq %rax, %rdi
callq 0x2340
leaq 0x5652(%rip), %rsi      # 0x844c
movq %rax, %rdi
callq 0x21e0
movq 0x28(%rbx), %rsi
movq %rax, %rdi
callq 0x2380
leaq 0x5659(%rip), %rsi      # 0x846e
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
movl $0x163, %esi            # imm = 0x163
callq 0x2340
leaq 0x5645(%rip), %rsi      # 0x8476
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20e0
pushq $0x1
popq %rdi
callq 0x2280
nop