// File: ashlall[P]StreamStats/ChiSquareExperiments/./../SourceCode/ChiSquare/../Quantiles/Q-Digest.cpp
// Function: QDigest::compressUpward(long)
void QDigest::compressUpward(long node)
{
  double threshold = std::floor(size / compression_factor);
  long atNode = get(node);
  while (!isRoot(node))
  {
    if (atNode > threshold)
      break;
    long atSibling = get(sibling(node));
    if (atNode + atSibling > threshold)
      break;
    long parent_ = parent(node);
    long atParent = get(parent_);
    if (atNode + atSibling + atParent > threshold)
      break;

    // restores property 2
    if (node2count.find(parent_) == node2count.end())
	node2count.insert(std::make_pair (parent_, atParent + atNode + atSibling));
    else
      {
	long hold = node2count[parent_];
	node2count[parent_] += 1;
      }
    node2count.erase(node);
    if (atSibling > 0)
      node2count.erase(sibling(node));
    node = parent_;
    atNode = atParent + atNode + atSibling;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
cvtsi2sdq 0x40(%rax), %xmm0
divsd 0x60(%rax), %xmm0
callq 0x22d0
movq -0x88(%rbp), %rdi
movsd %xmm0, -0x18(%rbp)
movq -0x10(%rbp), %rsi
callq 0x42e0
movq %rax, -0x20(%rbp)
movq -0x88(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x9200
xorb $-0x1, %al
testb $0x1, %al
jne 0x43c2
jmp 0x4587
cvtsi2sdq -0x20(%rbp), %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x43d4
jmp 0x4587
movq -0x88(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x9220
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x42e0
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
addq -0x28(%rbp), %rax
cvtsi2sd %rax, %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x4410
jmp 0x4587
movq -0x88(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x9260
movq -0x88(%rbp), %rdi
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rsi
callq 0x42e0
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
addq -0x28(%rbp), %rax
addq -0x38(%rbp), %rax
cvtsi2sd %rax, %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x4455
jmp 0x4587
movq -0x88(%rbp), %rdi
addq $0x8, %rdi
leaq -0x30(%rbp), %rsi
callq 0x8c20
movq -0x88(%rbp), %rdi
movq %rax, -0x40(%rbp)
addq $0x8, %rdi
callq 0x8c50
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x8bf0
testb $0x1, %al
jne 0x4494
jmp 0x44e4
movq -0x88(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x90(%rbp)
movq -0x38(%rbp), %rax
addq -0x20(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x8cc0
movq -0x90(%rbp), %rdi
movq %rax, -0x58(%rbp)
movq %rdx, -0x50(%rbp)
leaq -0x58(%rbp), %rsi
callq 0x8c80
movq %rax, -0x70(%rbp)
movb %dl, -0x68(%rbp)
jmp 0x451d
movq -0x88(%rbp), %rdi
addq $0x8, %rdi
leaq -0x30(%rbp), %rsi
callq 0x8cf0
movq -0x88(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x78(%rbp)
addq $0x8, %rdi
leaq -0x30(%rbp), %rsi
callq 0x8cf0
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x88(%rbp), %rdi
addq $0x8, %rdi
leaq -0x10(%rbp), %rsi
callq 0x9280
cmpq $0x0, -0x28(%rbp)
jle 0x456a
movq -0x88(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rsi
callq 0x9220
movq -0x98(%rbp), %rdi
movq %rax, -0x80(%rbp)
leaq -0x80(%rbp), %rsi
callq 0x9280
movq -0x30(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x38(%rbp), %rax
addq -0x20(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x43a7
addq $0xa0, %rsp
popq %rbp
retq