// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
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 0x3791
movq $0x270, 0x15a0(%rsp) # imm = 0x270
movq %rbp, %rax
shrq $0x3e, %rax
leaq (,%rbp,4), %rcx
xorl %r14d, %r14d
negq %rax
movl $0x0, %edi
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0x1030
movq %rax, %r12
movq %rbx, %rax
shrq $0x3d, %rax
movq %rbx, 0x10(%rsp)
leaq (,%rbx,8), %rcx
negq %rax
sbbq %r14, %r14
orq %rcx, %r14
movq %r14, %rdi
callq 0x1030
movq %rax, %r15
movq %r14, %rdi
callq 0x1030
movq %rax, %r13
testq %rbp, %rbp
je 0x3840
xorl %ebx, %ebx
leaq 0x220(%rsp), %r14
movq %r14, %rdi
callq 0x2204
movl %eax, (%r12,%rbx,4)
incq %rbx
cmpq %rbx, %rbp
jne 0x382c
callq 0x1050
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
movl $0x1e8, %edx            # imm = 0x1E8
xorl %esi, %esi
callq 0x1080
leaq 0x30(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x2456
callq 0x1050
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
testq %rax, %rax
movq %rbx, 0x28(%rsp)
je 0x3948
movq %r12, 0x18(%rsp)
xorl %ebx, %ebx
leaq 0x220(%rsp), %r12
movq %r12, %rdi
callq 0x2204
xorl %edx, %edx
divq %rbp
movq %rdx, %r14
movq %rdx, (%r15,%rbx,8)
movq %r12, %rdi
callq 0x2204
xorl %edx, %edx
divq %rbp
incq %rdx
movq %rdx, (%r13,%rbx,8)
cmpq %rdx, %r14
je 0x3897
jbe 0x38d0
movq %rdx, (%r15,%rbx,8)
movq %r14, (%r13,%rbx,8)
incq %rbx
cmpq 0x10(%rsp), %rbx
jne 0x3897
movl $0x0, 0xc(%rsp)
callq 0x1050
movq %rax, %rbp
xorl %eax, %eax
movq 0x218(%rsp), %rdx
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %r12
movq (%r15,%rax,8), %rsi
movq (%r13,%rax,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 (%rdx,%rcx,4), %edi
cmpl (%rdx,%rsi,4), %edi
jl 0x393a
movl %esi, %ecx
addl %ecx, 0xc(%rsp)
incq %rax
cmpq %rax, %r10
jne 0x38fe
jmp 0x3958
movl $0x0, 0xc(%rsp)
callq 0x1050
movq %rax, %rbp
callq 0x1050
movq %rax, %rbx
movq %r12, %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 0x398d
callq 0x10e0
addq $0x8, %r14
cmpq $0x1e8, %r14            # imm = 0x1E8
jne 0x397e
subq %rbp, %rbx
cvtsi2sd %rbx, %xmm1
movsd 0xedd06(%rip), %xmm2    # 0xf16b0
movq 0x20(%rsp), %rax
subq 0x28(%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