// File: /workspace/github_cpp_makefile_star2_O2/wx-csy[P]librmq/main.cpp
// Function: std::pair<double, double> performance_test_instance<librmq::rmq_zkw<int>>(unsigned long, unsigned long, int)
std::pair<double, double> performance_test_instance(size_t size, size_t nq, int seed = 123456) {
    std::mt19937 gen(seed);
    int *data = new int[size];
    size_t *ql = new size_t[nq], *qr = new size_t[nq];
    for (int i = 0; i < size; i++) data[i] = gen();
    
    using namespace std::chrono;
    double tprep, tq;
    
    auto tstart = high_resolution_clock::now(), tend = tstart;
    TSolver solver(size, data);
    tend = high_resolution_clock::now();
    tprep = duration_cast<duration<double>>(tend - tstart).count();
    
    for (size_t i = 0; i < nq; i++) {
        do {
            ql[i] = gen() % size; qr[i] = gen() % size + 1;
        } while (ql[i] == qr[i]);
        if (ql[i] > qr[i]) std::swap(ql[i], qr[i]);
    }
    
    volatile unsigned checksum = 0;
    tstart = high_resolution_clock::now();
    for (size_t i = 0; i < nq; i++) checksum += solver.query(ql[i], qr[i]); 
    tend = high_resolution_clock::now();
    tq = duration_cast<duration<double>>(tend - tstart).count();

    delete[] data;
    delete[] ql; delete[] qr;

    return {tprep, tq};
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x13d8, %rsp           # imm = 0x13D8
movq %rsi, %r14
movq %rdi, %r13
movslq %edx, %rsi
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
callq 0x1c2e
movq %r13, %rax
shrq $0x3e, %rax
leaq (,%r13,4), %rcx
xorl %ebx, %ebx
negq %rax
movl $0x0, %edi
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0x1030
movq %rax, %r12
movq %r14, %rax
shrq $0x3d, %rax
movq %r14, 0x8(%rsp)
leaq (,%r14,8), %rcx
negq %rax
movl $0x0, %r14d
sbbq %r14, %r14
orq %rcx, %r14
movq %r14, %rdi
callq 0x1030
movq %rax, %r15
movq %r14, %rdi
movq %r12, %r14
callq 0x1030
movq %rax, %r12
cmpq %rbx, %r13
je 0x2dd8
movq %rbp, %rdi
callq 0x1e60
movl %eax, (%r14,%rbx,4)
incq %rbx
jmp 0x2dc2
callq 0x1050
movq %rax, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %r14, 0x28(%rsp)
movq %r14, %rdx
callq 0x1ef8
xorl %ebx, %ebx
callq 0x1050
movq %rax, 0x20(%rsp)
leaq 0x50(%rsp), %rbp
cmpq 0x8(%rsp), %rbx
je 0x2e4b
movq %rbp, %rdi
callq 0x1e60
xorl %edx, %edx
divq %r13
movq %rdx, %r14
movq %rdx, (%r15,%rbx,8)
movq %rbp, %rdi
callq 0x1e60
xorl %edx, %edx
divq %r13
incq %rdx
movq %rdx, (%r12,%rbx,8)
cmpq %rdx, %r14
je 0x2e0f
jbe 0x2e46
movq %rdx, (%r15,%rbx,8)
movq %r14, (%r12,%rbx,8)
incq %rbx
jmp 0x2e08
movl $0x0, 0x1c(%rsp)
xorl %ebx, %ebx
callq 0x1050
movq %rax, %r13
leaq 0x30(%rsp), %r14
cmpq %rbx, 0x8(%rsp)
je 0x2e82
movq (%r15,%rbx,8), %rsi
movq (%r12,%rbx,8), %rdx
movq %r14, %rdi
callq 0x2012
addl %eax, 0x1c(%rsp)
incq %rbx
jmp 0x2e62
movq 0x20(%rsp), %rax
subq 0x10(%rsp), %rax
cvtsi2sd %rax, %xmm0
divsd 0xee7b7(%rip), %xmm0    # 0xf1650
movsd %xmm0, 0x8(%rsp)
callq 0x1050
subq %r13, %rax
cvtsi2sd %rax, %xmm0
divsd 0xee79c(%rip), %xmm0    # 0xf1650
movsd %xmm0, 0x10(%rsp)
movq 0x28(%rsp), %rdi
callq 0x10f0
movq %r15, %rdi
callq 0x10f0
movq %r12, %rdi
callq 0x10f0
leaq 0x30(%rsp), %rdi
callq 0x2084
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
addq $0x13d8, %rsp           # imm = 0x13D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2084
movq %rbx, %rdi
callq 0x1120
nop