// File: /workspace/github_cpp_makefile_star2_O1/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 0x3176
movl %ecx, 0x4(%rsp)
movslq 0x30(%r14), %rax
movl %eax, 0x8(%rsp)
movw $0x0, 0xc(%rsp)
movl 0x158(%rbx), %edx
cmpl $0x1, %edx
jne 0x2fa4
movb $0x1, 0xd(%rsp)
addl %edx, 0x15c(%rbx)
movq 0x50(%rbx), %rcx
movq 0x58(%rbx), %rdx
subq %rcx, %rdx
shrq $0x6, %rdx
cmpl %edx, %eax
jge 0x2fcd
shlq $0x6, %rax
incl (%rcx,%rax)
jmp 0x30aa
movslq 0x15c(%rbx), %rsi
cmpq %rsi, %rcx
jle 0x2fb6
movl %ecx, 0x15c(%rbx)
cmpl $0x1, %edx
je 0x2f7a
movslq 0x15c(%rbx), %rsi
cmpq %rsi, %rcx
jne 0x30e6
jmp 0x2f7a
movl $0x0, 0x10(%rsp)
fld1
fchs
fld %st(0)
fstpt 0x30(%rsp)
fstpt 0x20(%rsp)
movl $0xffffffff, 0x40(%rsp) # imm = 0xFFFFFFFF
movq 0x58(%rbx), %rsi
movq %rsi, %rax
subq 0x50(%rbx), %rax
leaq 0x50(%rbx), %r15
shrq $0x6, %rax
cmpl %eax, 0x30(%r14)
jle 0x305f
leaq 0x10(%rsp), %r12
cmpq 0x60(%rbx), %rsi
je 0x3039
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)
addq $0x40, 0x58(%rbx)
jmp 0x3044
movq %r15, %rdi
movq %r12, %rdx
callq 0x7b3e
incl 0x160(%rbx)
movq 0x58(%rbx), %rsi
movq %rsi, %rax
subq 0x50(%rbx), %rax
shrq $0x6, %rax
cmpl %eax, 0x30(%r14)
jg 0x3009
movl $0x1, 0x10(%rsp)
cmpq 0x60(%rbx), %rsi
je 0x3097
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)
addq $0x40, 0x58(%rbx)
jmp 0x30a4
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
callq 0x7b3e
incl 0x160(%rbx)
movq 0x58(%rbx), %rcx
movq 0x50(%rbx), %rax
subq %rax, %rcx
shrq $0x6, %rcx
cmpl %ecx, 0x3c(%rbx)
jg 0x30e6
movslq 0x30(%r14), %rcx
movq %rcx, %rdx
shlq $0x6, %rdx
movl 0x30(%rax,%rdx), %eax
cmpl $-0x1, %eax
je 0x30e6
cmpl 0x10c(%rbx), %eax
jl 0x30e6
movl %ecx, 0x108(%rbx)
movl %eax, 0x10c(%rbx)
movslq 0x8(%rbx), %rax
cmpq %rax, 0x28(%r14)
jge 0x3120
movq 0x98(%rbx), %rax
movq 0xa8(%rbx), %rcx
addq $-0xc, %rcx
cmpq %rcx, %rax
je 0x3150
movl 0xc(%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x4(%rsp), %rcx
movq %rcx, (%rax)
addq $0xc, 0x98(%rbx)
jmp 0x316a
movq 0xe8(%rbx), %rax
movq 0xf8(%rbx), %rcx
addq $-0xc, %rcx
cmpq %rcx, %rax
je 0x3156
movl 0xc(%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x4(%rsp), %rcx
movq %rcx, (%rax)
addq $0xc, 0xe8(%rbx)
jmp 0x316a
addq $0x68, %rbx
jmp 0x315d
addq $0xb8, %rbx
leaq 0x4(%rsp), %rsi
movq %rbx, %rdi
callq 0x7ca8
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x9e73(%rip), %rdi      # 0xcff0
leaq 0x6295(%rip), %rsi      # 0x9419
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 0x626e(%rip), %rsi      # 0x943c
movq %rax, %rdi
callq 0x2210
movq 0x28(%r14), %rsi
movq %rax, %rdi
callq 0x23d0
leaq 0x6275(%rip), %rsi      # 0x945e
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
movl $0x163, %esi            # imm = 0x163
callq 0x2390
leaq 0x6261(%rip), %rsi      # 0x9466
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20e0
movl $0x1, %edi
callq 0x22c0
nop