// File: /workspace/github_cpp_makefile_star2_O2/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 0x25d6
movq %rbx, %rdi
callq 0x2160
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
divl %ecx
cmpl $0x1, %edx
adcl $0x0, %edx
movq %rdx, 0x18(%rsp)
xorpd %xmm0, %xmm0
xorps %xmm1, %xmm1
movhps 0x1c95(%rip), %xmm1     # xmm1 = xmm1[0,1],mem[0,1]
movaps %xmm1, 0x60(%rsp)
movapd %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
movq 0x4c4e(%rip), %rdi      # 0x6fd8
leaq 0x1cf7(%rip), %rsi      # 0x4088
callq 0x2130
movq %rax, %rdi
callq 0x2090
movl $0x989680, %r13d        # imm = 0x989680
leaq 0x60(%rsp), %rbx
leaq 0x18(%rsp), %r14
movq %rsp, %r15
leaq 0x20(%rsp), %r12
subq $0x1, %r13
jb 0x23da
movq %rbx, %rdi
movq %r14, %rsi
callq 0x262c
movsd %xmm0, 0x20(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x3aec
jmp 0x23b6
movq 0x4bf7(%rip), %rdi      # 0x6fd8
leaq 0x1cba(%rip), %rsi      # 0x40a2
callq 0x2130
movq %rax, %rdi
callq 0x2090
callq 0x2030
movq %rax, %rbx
xorpd %xmm0, %xmm0
leaq 0x20(%rsp), %r14
andq $0x0, 0x10(%r14)
movapd %xmm0, (%r14)
movabsq $0x3f847ae147ae147b, %rax # imm = 0x3F847AE147AE147B
movq %rax, 0x18(%r14)
movq $0x800, 0x20(%r14)      # imm = 0x800
movupd %xmm0, 0x28(%r14)
movq (%rsp), %r12
movq 0x8(%rsp), %r13
pushq $0x1
popq %r15
cmpq %r13, %r12
je 0x2455
movsd (%r12), %xmm0
movq %r14, %rdi
movq %r15, %rsi
callq 0x2634
addq $0x8, %r12
jmp 0x2439
leaq 0x20(%rsp), %rdi
callq 0x2652
callq 0x2030
subq %rbx, %rax
cvtsi2sd %rax, %xmm0
divsd 0x1b9c(%rip), %xmm0     # 0x4010
movq 0x4b5d(%rip), %rdi      # 0x6fd8
callq 0x2190
leaq 0x1c33(%rip), %rsi      # 0x40ba
movq %rax, %rdi
callq 0x2130
movq %rax, %rdi
callq 0x2090
leaq 0x20(%rsp), %rdi
callq 0x27de
movq 0x4b30(%rip), %rdi      # 0x6fd8
movq %rax, %rsi
callq 0x20c0
leaq 0x1c10(%rip), %rsi      # 0x40c7
movq %rax, %rdi
callq 0x2130
movq %rax, %rdi
callq 0x2090
movq 0x4b0a(%rip), %rdi      # 0x6fd8
leaq 0x1bfd(%rip), %rsi      # 0x40d2
callq 0x2130
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
movsd 0x1b2e(%rip), %xmm0     # 0x4018
callq 0x27f4
movq %rbx, %rdi
callq 0x2190
movq %rax, %rdi
callq 0x2090
movq 0x4ad2(%rip), %rdi      # 0x6fd8
leaq 0x1bcc(%rip), %rsi      # 0x40d9
callq 0x2130
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
movsd 0x1afe(%rip), %xmm0     # 0x4020
callq 0x27f4
movq %rbx, %rdi
callq 0x2190
movq %rax, %rdi
callq 0x2090
movq 0x4a9a(%rip), %rdi      # 0x6fd8
leaq 0x1b9b(%rip), %rsi      # 0x40e0
callq 0x2130
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
movsd 0x1ace(%rip), %xmm0     # 0x4028
callq 0x27f4
movq %rbx, %rdi
callq 0x2190
movq %rax, %rdi
callq 0x2090
leaq 0x20(%rsp), %rdi
callq 0x3950
movq %rsp, %rdi
callq 0x396e
leaq 0x78(%rsp), %rdi
callq 0x2908
xorl %eax, %eax
addq $0x1400, %rsp           # imm = 0x1400
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x25a9
movq %rax, %rbx
jmp 0x25c3
jmp 0x25b8
jmp 0x25a9
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x3950
jmp 0x25bb
movq %rax, %rbx
movq %rsp, %rdi
callq 0x396e
leaq 0x78(%rsp), %rdi
callq 0x2908
movq %rbx, %rdi
callq 0x21d0
nop