// File: /workspace/github_cpp_makefile_star2_O2/junhe[P]libpatterndetector/pattern.cpp
// Function: RequestPattern::futureRequests(int, int)
vector<Request>
RequestPattern::futureRequests( int n , int startStride )
{
    // let me handle the simple case first
    // one offset pattern and one length pattern
    assert( length.chain.size() == 1 && length.chain[0].cnt > 0 );

    vector<Request> freq; // future requests put here

    // handle the case of only one request in the pattern
    if ( offset.seq.size() == 0
            || ( offset.seq.size() * offset.cnt <= 1 ) )
    {
        assert(length.chain.size() > 0);
        freq.push_back( Request(offset.init + length.chain[0].init,
                                length.chain[0].init * n) );
        return freq;
    }

    off_t off_stride_sum = sumVector(offset.seq);
    PatternUnit mylen = length.chain[0]; // for short
    off_t len_stride_sum = sumVector(mylen.seq);
    int i;
    int offseqsize = offset.seq.size();
    int lenseqsize = mylen.seq.size();


    int round = ((startStride-1) * n) / offseqsize;
    int remain = ((startStride-1) * n) % offseqsize;

    off_t off_add = off_stride_sum * round;
    off_t len_add = len_stride_sum * round;
    for ( i = 0 ; i < remain ; i++ ) {
        off_add += offset.seq[ i % offseqsize ];
        len_add += mylen.seq[ i% lenseqsize ];
    }

    off_t base_off = offset.init + off_stride_sum * offset.cnt + off_add;
    off_t base_len = mylen.init + len_stride_sum * mylen.cnt + len_add;
    
    freq.push_back( Request(base_off, base_len) );


    if ( offseqsize == 0 || lenseqsize == 0 )
        return freq;

    off_t curoff = base_off;
    off_t curlen = base_len;
    for ( i = 0 ; i < n-1 ; i++ ) {
        curoff = curoff + offset.seq[ i % offseqsize ];
        curlen = curlen + mylen.seq[ i % lenseqsize ];
        freq.push_back( Request(curoff, curlen) );
    }
    return freq;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %ecx, %ebp
movq %rdi, (%rsp)
movq 0x38(%rsi), %rax
movq 0x40(%rsi), %rcx
subq %rax, %rcx
cmpq $0x30, %rcx
jne 0x3af7
cmpq $0x0, 0x20(%rax)
jle 0x3af7
movl %edx, %ebx
movq %rsi, %r15
xorps %xmm0, %xmm0
movq (%rsp), %rcx
andq $0x0, 0x10(%rcx)
movups %xmm0, (%rcx)
movq 0x10(%rsi), %rcx
subq 0x8(%rsi), %rcx
je 0x3954
sarq $0x3, %rcx
imulq 0x20(%r15), %rcx
cmpq $0x1, %rcx
ja 0x3980
movq 0x28(%rax), %rax
movq 0x28(%r15), %rcx
addq %rax, %rcx
movslq %ebx, %rdx
imulq %rax, %rdx
leaq 0x28(%rsp), %rsi
movq %rcx, (%rsi)
movq %rdx, 0x8(%rsi)
movq (%rsp), %rdi
callq 0x26e4
jmp 0x3ae1
leaq 0x8(%r15), %rsi
leaq 0x70(%rsp), %rdi
movq %rsi, 0x10(%rsp)
callq 0x3b94
leaq 0x70(%rsp), %r12
movq %r12, %rdi
callq 0x3db8
movq %rax, %r14
movq %r12, %rdi
callq 0x2666
movq 0x38(%r15), %rsi
leaq 0x28(%rsp), %rdi
callq 0x3c62
leaq 0x30(%rsp), %rsi
leaq 0x58(%rsp), %rdi
callq 0x3b94
leaq 0x58(%rsp), %r12
movq %r12, %rdi
callq 0x3db8
movq %rax, %r13
movq %r12, %rdi
callq 0x2666
movq %r13, %r10
movq 0x8(%r15), %rdi
movq 0x10(%r15), %r12
subq %rdi, %r12
shrq $0x3, %r12
movq 0x30(%rsp), %r8
movq 0x38(%rsp), %r13
decl %ebp
movl %ebx, 0xc(%rsp)
imull %ebx, %ebp
movl %ebp, %eax
cltd
idivl %r12d
movl %edx, %ecx
subq %r8, %r13
shrq $0x3, %r13
cltq
movq %r14, %r9
imulq %rax, %r14
movq %r10, %rbx
imulq %rax, %rbx
xorl %esi, %esi
testl %edx, %edx
cmovlel %esi, %ecx
cmpl %esi, %ecx
je 0x3a47
movl %esi, %eax
cltd
idivl %r12d
addq (%rdi,%rdx,8), %r14
movl %esi, %eax
cltd
idivl %r13d
addq (%r8,%rdx,8), %rbx
incl %esi
jmp 0x3a2b
movq 0x20(%r15), %rax
imulq %r9, %rax
addq 0x28(%r15), %r14
addq %rax, %r14
movq 0x48(%rsp), %rax
imulq %r10, %rax
addq 0x50(%rsp), %rbx
addq %rax, %rbx
leaq 0x18(%rsp), %rsi
movq %r14, (%rsi)
movq %rbx, 0x8(%rsi)
movq (%rsp), %rdi
callq 0x26e4
testl %r13d, %r13d
je 0x3ad7
movl 0xc(%rsp), %eax
cmpl $0x2, %eax
pushq $0x1
popq %r15
cmovgel %eax, %r15d
decl %r15d
xorl %ebp, %ebp
cmpl %ebp, %r15d
je 0x3ad7
movl %ebp, %eax
cltd
idivl %r12d
movq 0x10(%rsp), %rax
movq (%rax), %rax
addq (%rax,%rdx,8), %r14
movl %ebp, %eax
cltd
idivl %r13d
movq 0x30(%rsp), %rax
addq (%rax,%rdx,8), %rbx
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq (%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x26e4
incl %ebp
jmp 0x3a95
leaq 0x28(%rsp), %rdi
callq 0x2522
movq (%rsp), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16ee(%rip), %rdi      # 0x51ec
leaq 0x1612(%rip), %rsi      # 0x5117
leaq 0x1714(%rip), %rcx      # 0x5220
movl $0x2c8, %edx            # imm = 0x2C8
callq 0x20b0
jmp 0x3b23
jmp 0x3b23
jmp 0x3b1e
jmp 0x3b1e
movq %rax, %r14
jmp 0x3b30
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x2522
movq (%rsp), %rdi
callq 0x26b0
movq %r14, %rdi
callq 0x21a0
nop