// File: snaury[P]t-digest-simple/./merging_tdigest.hpp
// Function: MergingTDigest::compress()
void compress() {
        if (buffer_size_ > 0) {
            std::stable_sort(summary_.begin(), summary_.end());
            buffer_size_ = 0;
            if (summary_.size() > 3) {
                auto l = summary_.begin();
                auto r = std::next(l);
                int64_t sum = 0;
                while (r != summary_.end()) {
                    // use quantile with the smallest error
                    double ql = (sum + l->count * 0.5) / count_;
                    double err = ql * (1.0 - ql);
                    double qr = (sum + l->count + r->count * 0.5) / count_;
                    double err2 = qr * (1.0 - qr);
                    if (err > err2) {
                        err = err2;
                    }
                    double k = 4 * count_ * err * epsilon_;
                    if (l->count + r->count <= k) {
                        // it is possible to merge left and right
                        *l += *r;
                    } else {
                        // skip to the next pair
                        sum += l->count;
                        if (++l != r) {
                            *l = *r;
                        }
                    }
                    ++r;
                }
                // remove all leftover centroids
                summary_.erase(++l, summary_.end());
            }
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, 0x28(%rax)
jbe 0x300b
movq -0x90(%rbp), %rdi
callq 0x3d70
movq -0x90(%rbp), %rdi
movq %rax, -0x10(%rbp)
callq 0x3bf0
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4320
movq -0x90(%rbp), %rdi
movq $0x0, 0x28(%rdi)
callq 0x3ec0
cmpq $0x3, %rax
jbe 0x3009
movq -0x90(%rbp), %rdi
callq 0x3d70
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0x4360
movq %rax, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x90(%rbp), %rdi
callq 0x3bf0
movq %rax, -0x40(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x4390
testb $0x1, %al
jne 0x2d38
jmp 0x2fbc
cvtsi2sdq -0x38(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
leaq -0x20(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x43d0
movsd -0xd8(%rbp), %xmm1
movq -0xd0(%rbp), %rdi
movq %rax, %rcx
movq -0x90(%rbp), %rax
cvtsi2sdq 0x8(%rcx), %xmm0
movsd 0x629b(%rip), %xmm2     # 0x9018
movsd %xmm2, -0xc0(%rbp)
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x30(%rax), %xmm1
movaps 0x62a7(%rip), %xmm2     # 0x9040
movaps %xmm2, -0xb0(%rbp)
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x62a4(%rip), %xmm2     # 0x9050
movaps %xmm2, -0xa0(%rbp)
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
movsd 0x6230(%rip), %xmm1     # 0x9008
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xc8(%rbp)
callq 0x43d0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movq 0x8(%rcx), %rcx
addq %rcx, %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0xb8(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x43d0
movsd -0xc0(%rbp), %xmm4
movsd -0xb8(%rbp), %xmm1
movaps -0xb0(%rbp), %xmm3
movaps -0xa0(%rbp), %xmm2
movq %rax, %rcx
movq -0x90(%rbp), %rax
cvtsi2sdq 0x8(%rcx), %xmm0
mulsd %xmm4, %xmm0
addsd %xmm1, %xmm0
movq 0x30(%rax), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd 0x6188(%rip), %xmm1     # 0x9008
subsd -0x58(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x50(%rbp), %xmm0
ucomisd -0x60(%rbp), %xmm0
jbe 0x2ea4
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movq -0x90(%rbp), %rax
movq 0x30(%rax), %rcx
shlq $0x2, %rcx
movq %rcx, %xmm0
movaps 0x6181(%rip), %xmm1     # 0x9040
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x6185(%rip), %xmm1     # 0x9050
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
mulsd -0x50(%rbp), %xmm0
mulsd 0x18(%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x43d0
movq 0x8(%rax), %rax
movq %rax, -0xe0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x43d0
movq %rax, %rcx
movq -0xe0(%rbp), %rax
addq 0x8(%rcx), %rax
cvtsi2sd %rax, %xmm1
movsd -0x68(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x2f4e
leaq -0x28(%rbp), %rdi
callq 0x43f0
movq %rax, -0xe8(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x43f0
movq -0xe8(%rbp), %rsi
movq %rax, %rdi
callq 0x4410
jmp 0x2fae
leaq -0x20(%rbp), %rdi
callq 0x43d0
movq 0x8(%rax), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x4460
movq %rax, %rdi
leaq -0x28(%rbp), %rsi
callq 0x4390
testb $0x1, %al
jne 0x2f7e
jmp 0x2fac
leaq -0x28(%rbp), %rdi
callq 0x43f0
movq %rax, -0xf0(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x43f0
movq -0xf0(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x2fae
leaq -0x28(%rbp), %rdi
callq 0x4460
jmp 0x2d12
leaq -0x20(%rbp), %rdi
callq 0x4460
movq %rax, %rsi
leaq -0x70(%rbp), %rdi
callq 0x4510
movq -0x90(%rbp), %rdi
callq 0x3bf0
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x4510
movq -0x90(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x78(%rbp), %rdx
callq 0x4480
movq %rax, -0x88(%rbp)
jmp 0x300b
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop