// File: /workspace/github_cpp_makefile_star2_O1/snaury[P]t-digest-simple/main.cpp
// Function: main
int main() {
    std::random_device seed;
    std::default_random_engine rng(seed());
    std::uniform_real_distribution<double> dist(0.0, 1.0);

    std::vector<double> data;
    std::cout << "Generating random data..." << std::endl;
    for (size_t i = 0; i < num_values; ++i) {
        data.push_back(dist(rng));
    }

    std::cout << "Computing the digest..." << std::endl;
    auto t0 = std::chrono::high_resolution_clock::now();
    MergingTDigest digest(100);
    for (auto value : data) {
        digest.add(value);
    }
    digest.compress();
    auto t1 = std::chrono::high_resolution_clock::now();
    auto dt = std::chrono::duration_cast<std::chrono::nanoseconds>(t1 - t0);
    auto nsperop = dt / (double)num_values;
    std::cout << nsperop.count() << "ns per value" << std::endl;
    std::cout << digest.size() << " centroids" << std::endl;
    std::cout << "p50 = " << digest.quantile(0.5) << std::endl;
    std::cout << "p95 = " << digest.quantile(0.95) << std::endl;
    std::cout << "p99 = " << digest.quantile(0.99) << std::endl;
    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1400, %rsp           # imm = 0x1400
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x277a
movq %rbx, %rdi
callq 0x2160
movl %eax, %ecx
leaq (%rcx,%rcx,2), %rcx
shrq $0x20, %rcx
movl %eax, %edx
subl %ecx, %edx
shrl %edx
addl %ecx, %edx
shrl $0x1e, %edx
movl %edx, %ecx
shll $0x1f, %ecx
orl %edx, %ecx
leal (%rax,%rcx), %edx
cmpl $0x1, %edx
adcl %eax, %ecx
movq %rcx, 0x60(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x3c45(%rip), %rbx      # 0x5fd8
leaq 0x1cde(%rip), %rsi      # 0x4078
movl $0x19, %edx
movq %rbx, %rdi
callq 0x2150
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq 0x3c13(%rip), %rdi      # 0x5fd8
callq 0x2030
movq %rax, %rdi
callq 0x20b0
movl $0x989680, %r12d        # imm = 0x989680
leaq 0x60(%rsp), %rbx
movq %rsp, %r14
leaq 0x20(%rsp), %r15
movq %rbx, %rdi
callq 0x3a63
addsd 0x1c33(%rip), %xmm0     # 0x4028
movsd %xmm0, 0x20(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x2416
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x2421
movq %r14, %rdi
movq %r15, %rdx
callq 0x3bac
decq %r12
jne 0x23e5
movq 0x3bab(%rip), %rbx      # 0x5fd8
leaq 0x1c5e(%rip), %rsi      # 0x4092
movl $0x17, %edx
movq %rbx, %rdi
callq 0x2150
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq 0x3b79(%rip), %rdi      # 0x5fd8
callq 0x2030
movq %rax, %rdi
callq 0x20b0
callq 0x2040
movq %rax, %rbx
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movabsq $0x3f847ae147ae147b, %rax # imm = 0x3F847AE147AE147B
movq %rax, 0x38(%rsp)
movq $0x800, 0x40(%rsp)      # imm = 0x800
movupd %xmm0, 0x48(%rsp)
movq (%rsp), %r12
movq 0x8(%rsp), %r13
cmpq %r13, %r12
je 0x24e6
leaq 0x20(%rsp), %r14
leaq 0x68(%rsp), %r15
movsd (%r12), %xmm0
movsd %xmm0, 0x68(%rsp)
movq $0x1, 0x70(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x2c3e
addq $0x8, %r12
cmpq %r13, %r12
jne 0x24bd
leaq 0x20(%rsp), %rdi
callq 0x27f4
callq 0x2040
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x1b00(%rip), %xmm0     # 0x4008
movq 0x3ac9(%rip), %rdi      # 0x5fd8
callq 0x2180
movq %rax, %rbx
leaq 0x1b8c(%rip), %rsi      # 0x40aa
movl $0xc, %edx
movq %rax, %rdi
callq 0x2150
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20b0
leaq 0x20(%rsp), %rdi
callq 0x27f4
movq 0x28(%rsp), %rsi
subq 0x20(%rsp), %rsi
sarq $0x4, %rsi
movq 0x3a67(%rip), %rdi      # 0x5fd8
callq 0x20a0
movq %rax, %rbx
leaq 0x1b37(%rip), %rsi      # 0x40b7
movl $0xa, %edx
movq %rax, %rdi
callq 0x2150
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20b0
movq 0x3a1d(%rip), %rdi      # 0x5fd8
leaq 0x1b00(%rip), %rsi      # 0x40c2
movl $0x6, %edx
callq 0x2150
leaq 0x20(%rsp), %rdi
movsd 0x1a37(%rip), %xmm0     # 0x4010
callq 0x2a20
movq 0x39f3(%rip), %rdi      # 0x5fd8
callq 0x2180
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20b0
movq 0x39bd(%rip), %rdi      # 0x5fd8
leaq 0x1aa7(%rip), %rsi      # 0x40c9
movl $0x6, %edx
callq 0x2150
leaq 0x20(%rsp), %rdi
movsd 0x19df(%rip), %xmm0     # 0x4018
callq 0x2a20
movq 0x3993(%rip), %rdi      # 0x5fd8
callq 0x2180
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20b0
movq 0x395d(%rip), %rdi      # 0x5fd8
leaq 0x1a4e(%rip), %rsi      # 0x40d0
movl $0x6, %edx
callq 0x2150
leaq 0x20(%rsp), %rdi
movsd 0x1987(%rip), %xmm0     # 0x4020
callq 0x2a20
movq 0x3933(%rip), %rdi      # 0x5fd8
callq 0x2180
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20b0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x26eb
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2701
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
leaq 0x78(%rsp), %rdi
callq 0x2110
xorl %eax, %eax
addq $0x1400, %rsp           # imm = 0x1400
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x2772
jmp 0x272b
movq %rax, %rbx
jmp 0x2760
jmp 0x2747
jmp 0x272b
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x274a
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
jmp 0x274a
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2760
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
leaq 0x78(%rsp), %rdi
callq 0x2110
movq %rbx, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x2c32