// File: /workspace/github_cpp_makefile_star2_O1/wx-csy[P]librmq/main.cpp
// Function: std::pair<double, double> performance_test_instance<librmq::rmq_st<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 $0x15a8, %rsp           # imm = 0x15A8
movq %rsi, 0x10(%rsp)
movq %rdi, %rbp
movl %edx, %eax
movq %rax, 0x220(%rsp)
movl $0x1, %ecx
movq %rax, %rdx
shrq $0x1e, %rdx
xorl %eax, %edx
imull $0x6c078965, %edx, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, 0x220(%rsp,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0x3793
movq $0x270, 0x15a0(%rsp) # imm = 0x270
movq %rbp, %rax
shrq $0x3e, %rax
leaq (,%rbp,4), %rcx
xorl %r12d, %r12d
negq %rax
movl $0x0, %edi
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0x1030
movq %rax, %rbx
movq 0x10(%rsp), %rcx
movq %rcx, %rax
shrq $0x3d, %rax
leaq (,%rcx,8), %rcx
negq %rax
sbbq %r12, %r12
orq %rcx, %r12
movq %r12, %rdi
callq 0x1030
movq %rax, %r15
movq %r12, %rdi
callq 0x1030
movq %rax, %r13
testq %rbp, %rbp
je 0x3843
xorl %r14d, %r14d
leaq 0x220(%rsp), %r12
movq %r12, %rdi
callq 0x2204
movl %eax, (%rbx,%r14,4)
incq %r14
cmpq %r14, %rbp
jne 0x382f
callq 0x1050
movq %rax, 0x20(%rsp)
leaq 0x38(%rsp), %rdi
movl $0x1e8, %edx            # imm = 0x1E8
xorl %esi, %esi
callq 0x1080
leaq 0x30(%rsp), %rdi
movq %rbp, %rsi
movq %rbx, 0x28(%rsp)
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x2454
callq 0x1050
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
je 0x38d6
xorl %r14d, %r14d
leaq 0x220(%rsp), %r12
movq %r12, %rdi
callq 0x2204
xorl %edx, %edx
divq %rbp
movq %rdx, (%r15,%r14,8)
movq %r12, %rdi
callq 0x2204
xorl %edx, %edx
divq %rbp
incq %rdx
movq %rdx, (%r13,%r14,8)
movq (%r15,%r14,8), %rax
cmpq %rdx, %rax
je 0x3894
jbe 0x38ce
movq %rdx, (%r15,%r14,8)
movq %rax, (%r13,%r14,8)
incq %r14
cmpq %rbx, %r14
jne 0x3894
movl $0x0, 0xc(%rsp)
callq 0x1050
movq %rax, %rbp
testq %rbx, %rbx
movq 0x28(%rsp), %r14
je 0x3942
movq 0x218(%rsp), %rax
xorl %edx, %edx
movq (%r15,%rdx,8), %rsi
movq (%r13,%rdx,8), %rdi
movq %rdi, %rcx
subq %rsi, %rcx
bsrq %rcx, %rcx
movl %ecx, %r8d
movl $0x1, %r9d
shll %cl, %r9d
movq 0x38(%rsp,%r8,8), %r8
movq (%r8,%rsi,8), %rcx
movslq %r9d, %rsi
subq %rsi, %rdi
movq (%r8,%rdi,8), %rsi
movl (%rax,%rcx,4), %edi
cmpl (%rax,%rsi,4), %edi
jl 0x3936
movl %esi, %ecx
addl %ecx, 0xc(%rsp)
incq %rdx
cmpq %rdx, %rbx
jne 0x38fa
callq 0x1050
movq %rax, %rbx
movq %r14, %rdi
callq 0x10e0
movq %r15, %rdi
callq 0x10e0
movq %r13, %rdi
callq 0x10e0
movl $0x8, %r14d
movq 0x30(%rsp,%r14), %rdi
testq %rdi, %rdi
je 0x3977
callq 0x10e0
addq $0x8, %r14
cmpq $0x1e8, %r14            # imm = 0x1E8
jne 0x3968
subq %rbp, %rbx
cvtsi2sd %rbx, %xmm1
movsd 0xedd1c(%rip), %xmm2    # 0xf16b0
movq 0x18(%rsp), %rax
subq 0x20(%rsp), %rax
cvtsi2sd %rax, %xmm0
divsd %xmm2, %xmm1
divsd %xmm2, %xmm0
addq $0x15a8, %rsp           # imm = 0x15A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x1141
movq %rbx, %rdi
callq 0x1110