// File: 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:
subq $0x14c8, %rsp           # imm = 0x14C8
movq %rdi, 0x14b0(%rsp)
movq %rsi, 0x14a8(%rsp)
movl %edx, 0x14a4(%rsp)
movslq 0x14a4(%rsp), %rsi
leaq 0x118(%rsp), %rdi
callq 0x12d0
movq 0x14b0(%rsp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, 0x110(%rsp)
movq 0x14a8(%rsp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, 0x108(%rsp)
movq 0x14a8(%rsp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, 0x100(%rsp)
movl $0x0, 0xfc(%rsp)
movslq 0xfc(%rsp), %rax
cmpq 0x14b0(%rsp), %rax
jae 0x4bb8
leaq 0x118(%rsp), %rdi
callq 0x28e0
movl %eax, %edx
movq 0x110(%rsp), %rax
movslq 0xfc(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x4b71
callq 0x1050
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0x14b0(%rsp), %rsi
movq 0x110(%rsp), %rdx
leaq 0xb8(%rsp), %rdi
callq 0x2a30
callq 0x1050
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0xd8(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x52b0
movq %rax, 0x50(%rsp)
jmp 0x4c2b
movq 0x50(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x5280
movsd %xmm0, 0x48(%rsp)
jmp 0x4c4d
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x5300
movsd %xmm0, 0x40(%rsp)
jmp 0x4c71
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0xf0(%rsp)
movq $0x0, 0x88(%rsp)
movq 0x88(%rsp), %rax
cmpq 0x14a8(%rsp), %rax
jae 0x4de9
jmp 0x4ca4
leaq 0x118(%rsp), %rdi
callq 0x28e0
movq %rax, 0x38(%rsp)
jmp 0x4cb8
movq 0x38(%rsp), %rax
movq 0x14b0(%rsp), %rcx
xorl %edx, %edx
divq %rcx
movq 0x108(%rsp), %rax
movq 0x88(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
leaq 0x118(%rsp), %rdi
callq 0x28e0
movq %rax, 0x30(%rsp)
jmp 0x4cf2
movq 0x30(%rsp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0x14b0(%rsp)
addq $0x1, %rdx
movq 0x100(%rsp), %rax
movq 0x88(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x108(%rsp), %rax
movq 0x88(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x100(%rsp), %rcx
movq 0x88(%rsp), %rdx
cmpq (%rcx,%rdx,8), %rax
je 0x4ca4
movq 0x108(%rsp), %rax
movq 0x88(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x100(%rsp), %rcx
movq 0x88(%rsp), %rdx
cmpq (%rcx,%rdx,8), %rax
jbe 0x4dce
movq 0x108(%rsp), %rdi
movq 0x88(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq 0x100(%rsp), %rsi
movq 0x88(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x5310
jmp 0x4dce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x2e40
jmp 0x4f8f
jmp 0x4dd0
movq 0x88(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x88(%rsp)
jmp 0x4c8c
movl $0x0, 0x84(%rsp)
callq 0x1050
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpq 0x14a8(%rsp), %rax
jae 0x4e78
movq 0x108(%rsp), %rax
movq 0x70(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x100(%rsp), %rax
movq 0x70(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0xb8(%rsp), %rdi
callq 0x2d10
movq %rax, %rcx
movl 0x84(%rsp), %eax
movl %eax, %eax
addq %rcx, %rax
movl %eax, 0x84(%rsp)
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x4e14
callq 0x1050
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0xd8(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x52b0
movq %rax, 0x28(%rsp)
jmp 0x4eab
movq 0x28(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x5280
movsd %xmm0, 0x20(%rsp)
jmp 0x4ec7
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x5300
movsd %xmm0, 0x18(%rsp)
jmp 0x4ee5
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0xe8(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x4f11
movq 0x10(%rsp), %rdi
callq 0x10f0
movq 0x108(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x4f2e
movq 0x8(%rsp), %rdi
callq 0x10f0
movq 0x100(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x4f49
movq (%rsp), %rdi
callq 0x10f0
leaq 0x14b8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0xe8(%rsp), %rdx
callq 0x5350
jmp 0x4f68
leaq 0xb8(%rsp), %rdi
callq 0x2e40
movsd 0x14b8(%rsp), %xmm0
movsd 0x14c0(%rsp), %xmm1
addq $0x14c8, %rsp           # imm = 0x14C8
retq
movq 0x98(%rsp), %rdi
callq 0x1120
nopl (%rax)