// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq %rdi, %rbx
movq 0x28(%rsi), %rcx
movslq 0x4(%rdi), %rax
cmpq %rax, %rcx
jg 0x315b
movl %ecx, 0x4(%rsp)
movslq 0x30(%r14), %rax
movl %eax, 0x8(%rsp)
movw $0x0, 0xc(%rsp)
movl 0x158(%rbx), %edx
movl 0x15c(%rbx), %esi
cmpl $0x1, %edx
je 0x2f86
movslq %esi, %rdi
cmpq %rdi, %rcx
jle 0x2f7d
movl %ecx, 0x15c(%rbx)
movq %rcx, %rdi
movl %ecx, %esi
cmpq %rdi, %rcx
jne 0x30cb
movb $0x1, 0xd(%rsp)
addl %edx, %esi
movl %esi, 0x15c(%rbx)
movq 0x50(%rbx), %rdx
movq 0x58(%rbx), %rsi
movq %rsi, %rcx
subq %rdx, %rcx
shrq $0x6, %rcx
cmpl %ecx, %eax
jge 0x2fb5
shlq $0x6, %rax
incl (%rdx,%rax)
jmp 0x309e
leaq 0x50(%rbx), %r15
movl $0x0, 0x10(%rsp)
fld1
fchs
fld %st(0)
fstpt 0x30(%rsp)
fstpt 0x20(%rsp)
movl $0xffffffff, 0x40(%rsp) # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jle 0x303d
leaq 0x10(%rsp), %r12
cmpq 0x60(%rbx), %rsi
je 0x3017
movaps 0x10(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
movaps 0x30(%rsp), %xmm2
movaps 0x40(%rsp), %xmm3
movaps %xmm3, 0x30(%rsi)
movaps %xmm2, 0x20(%rsi)
movaps %xmm1, 0x10(%rsi)
movaps %xmm0, (%rsi)
movq 0x58(%rbx), %rsi
addq $0x40, %rsi
movq %rsi, 0x58(%rbx)
jmp 0x3026
movq %r15, %rdi
movq %r12, %rdx
callq 0x7e82
movq 0x58(%rbx), %rsi
incl 0x160(%rbx)
movq %rsi, %rax
subq 0x50(%rbx), %rax
shrq $0x6, %rax
cmpl %eax, 0x30(%r14)
jg 0x2fe0
movl $0x1, 0x10(%rsp)
cmpq 0x60(%rbx), %rsi
je 0x307c
movaps 0x10(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
movaps 0x30(%rsp), %xmm2
movaps 0x40(%rsp), %xmm3
movaps %xmm3, 0x30(%rsi)
movaps %xmm2, 0x20(%rsi)
movaps %xmm1, 0x10(%rsi)
movaps %xmm0, (%rsi)
movq 0x58(%rbx), %rcx
addq $0x40, %rcx
movq %rcx, 0x58(%rbx)
jmp 0x308d
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
callq 0x7e82
movq 0x58(%rbx), %rcx
incl 0x160(%rbx)
movq 0x50(%rbx), %rdx
subq %rdx, %rcx
shrq $0x6, %rcx
cmpl %ecx, 0x3c(%rbx)
jg 0x30cb
movslq 0x30(%r14), %rax
movq %rax, %rcx
shlq $0x6, %rcx
movl 0x30(%rdx,%rcx), %ecx
cmpl $-0x1, %ecx
je 0x30cb
cmpl 0x10c(%rbx), %ecx
jl 0x30cb
movl %eax, 0x108(%rbx)
movl %ecx, 0x10c(%rbx)
movslq 0x8(%rbx), %rax
cmpq %rax, 0x28(%r14)
jge 0x3105
movq 0x98(%rbx), %rax
movq 0xa8(%rbx), %rcx
addq $-0xc, %rcx
cmpq %rcx, %rax
je 0x3135
movl 0xc(%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x4(%rsp), %rcx
movq %rcx, (%rax)
addq $0xc, 0x98(%rbx)
jmp 0x314f
movq 0xe8(%rbx), %rax
movq 0xf8(%rbx), %rcx
addq $-0xc, %rcx
cmpq %rcx, %rax
je 0x313b
movl 0xc(%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x4(%rsp), %rcx
movq %rcx, (%rax)
addq $0xc, 0xe8(%rbx)
jmp 0x314f
addq $0x68, %rbx
jmp 0x3142
addq $0xb8, %rbx
leaq 0x4(%rsp), %rsi
movq %rbx, %rdi
callq 0x7fec
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x9e8e(%rip), %rdi      # 0xcff0
leaq 0x62e0(%rip), %rsi      # 0x9449
callq 0x2210
movq 0x188(%rbx), %rsi
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
movl $0x3a, %esi
callq 0x22a0
movl (%rbx), %esi
movq %rax, %rdi
callq 0x2390
movq %rax, %rdi
movl $0x2d, %esi
callq 0x22a0
movl 0x4(%rbx), %esi
movq %rax, %rdi
callq 0x2390
leaq 0x62b9(%rip), %rsi      # 0x946c
movq %rax, %rdi
callq 0x2210
movq 0x28(%r14), %rsi
movq %rax, %rdi
callq 0x23d0
leaq 0x62c0(%rip), %rsi      # 0x948e
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
movl $0x163, %esi            # imm = 0x163
callq 0x2390
leaq 0x62ac(%rip), %rsi      # 0x9496
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20e0
movl $0x1, %edi
callq 0x22c0