// File: ashlall[P]StreamStats/ChiSquareExperiments/./../SourceCode/ChiSquare/../Quantiles/Q-Digest.cpp
// Function: QDigest::compressDownward(long)
void QDigest::compressDownward(long seedNode)
{
  double threshold = std :: floor(size/compression_factor); 
	
  std::queue<long, std::list<long> > queue;
  queue.push(seedNode);
  while(!queue.empty())
  {
    long node = queue.front();
    queue.pop();
    long atNode = get(node);
    long atSibling = get(sibling(node));
    if (atNode == 0 && atSibling == 0)
      continue;
    long parent_ = parent(node);
    long atParent = get(parent_);
    if (atParent + atNode + atSibling > threshold)
       continue;
    if (node2count.find(parent_) == node2count.end())
      node2count.insert(std::make_pair (parent_, atParent + atNode + atSibling));
    else
      node2count[parent_] += 1;
    node2count.erase(node);
    node2count.erase(sibling(node));

    // Ensures that P2 holds for node and sibling subtrees
    if (!isLeaf(node))
    {
      queue.push(leftChild(node));
      queue.push(leftChild(sibling(node)));
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
cvtsi2sdq 0x40(%rax), %xmm0
movsd 0x60(%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x22d0
movsd %xmm0, -0x18(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x92b0
movq -0xc0(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x92e0
jmp 0x4759
jmp 0x475b
leaq -0x30(%rbp), %rdi
callq 0x9310
movb %al, -0xc9(%rbp)
jmp 0x476c
movb -0xc9(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x477d
jmp 0x4add
leaq -0x30(%rbp), %rdi
callq 0x9330
movq %rax, -0xd8(%rbp)
jmp 0x478f
movq -0xd8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x9350
jmp 0x47a8
movq -0xc8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x42e0
movq %rax, -0xe0(%rbp)
jmp 0x47c1
movq -0xc8(%rbp), %rdi
movq -0xe0(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rsi
callq 0x9220
movq %rax, -0xe8(%rbp)
jmp 0x47e5
movq -0xe8(%rbp), %rsi
movq -0xc8(%rbp), %rdi
callq 0x42e0
movq %rax, -0xf0(%rbp)
jmp 0x4801
movq -0xf0(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x4839
cmpq $0x0, -0x58(%rbp)
jne 0x4839
jmp 0x475b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x93e0
jmp 0x4aef
movq -0xc8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x9260
movq %rax, -0xf8(%rbp)
jmp 0x4852
movq -0xc8(%rbp), %rdi
movq -0xf8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rsi
callq 0x42e0
movq %rax, -0x100(%rbp)
jmp 0x4876
movq -0x100(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
addq -0x50(%rbp), %rax
addq -0x58(%rbp), %rax
cvtsi2sd %rax, %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x489e
jmp 0x475b
movq -0xc8(%rbp), %rdi
addq $0x8, %rdi
leaq -0x60(%rbp), %rsi
callq 0x8c20
movq %rax, -0x108(%rbp)
jmp 0x48bb
movq -0xc8(%rbp), %rdi
movq -0x108(%rbp), %rax
movq %rax, -0x70(%rbp)
addq $0x8, %rdi
callq 0x8c50
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x8bf0
testb $0x1, %al
jne 0x48f0
jmp 0x4992
movq -0xc8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x120(%rbp)
movq -0x68(%rbp), %rax
movq -0x50(%rbp), %rcx
addq %rcx, %rax
movq -0x58(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x8cc0
movq %rdx, -0x118(%rbp)
movq %rax, -0x110(%rbp)
jmp 0x493b
movq -0x120(%rbp), %rdi
movq -0x118(%rbp), %rax
movq -0x110(%rbp), %rcx
movq %rcx, -0x88(%rbp)
movq %rax, -0x80(%rbp)
leaq -0x88(%rbp), %rsi
callq 0x8c80
movb %dl, -0x129(%rbp)
movq %rax, -0x128(%rbp)
jmp 0x4976
movb -0x129(%rbp), %al
movq -0x128(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
movb %al, -0x98(%rbp)
jmp 0x49c0
movq -0xc8(%rbp), %rdi
addq $0x8, %rdi
leaq -0x60(%rbp), %rsi
callq 0x8cf0
movq %rax, -0x138(%rbp)
jmp 0x49af
movq -0x138(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0xc8(%rbp), %rdi
addq $0x8, %rdi
leaq -0x48(%rbp), %rsi
callq 0x9280
jmp 0x49d6
movq -0xc8(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x148(%rbp)
movq -0x48(%rbp), %rsi
callq 0x9220
movq %rax, -0x140(%rbp)
jmp 0x49fd
movq -0x148(%rbp), %rdi
movq -0x140(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0xa8(%rbp), %rsi
callq 0x9280
jmp 0x4a20
movq -0xc8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x9370
movb %al, -0x149(%rbp)
jmp 0x4a38
movb -0x149(%rbp), %al
testb $0x1, %al
jne 0x4ad8
jmp 0x4a48
movq -0xc8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x93c0
movq %rax, -0x158(%rbp)
jmp 0x4a61
movq -0x158(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x9390
jmp 0x4a81
movq -0xc8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x9220
movq %rax, -0x160(%rbp)
jmp 0x4a9a
movq -0x160(%rbp), %rsi
movq -0xc8(%rbp), %rdi
callq 0x93c0
movq %rax, -0x168(%rbp)
jmp 0x4ab6
movq -0x168(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x9390
jmp 0x4ad6
jmp 0x4ad8
jmp 0x475b
leaq -0x30(%rbp), %rdi
callq 0x93e0
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x2320
nopl (%rax,%rax)