// File: /workspace/github_cpp_makefile_star2_O3/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
movl %edx, 0x4(%rsp)
movq 0x38(%rsi), %rax
movq 0x40(%rsi), %rcx
subq %rax, %rcx
cmpq $0x30, %rcx
jne 0x46ae
cmpq $0x0, 0x20(%rax)
jle 0x46ae
movq %rsi, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x10(%rsi), %rcx
subq 0x8(%rsi), %rcx
je 0x4460
sarq $0x3, %rcx
imulq 0x20(%r14), %rcx
cmpq $0x1, %rcx
ja 0x448f
movq 0x28(%rax), %rax
movq 0x28(%r14), %rcx
addq %rax, %rcx
movslq 0x4(%rsp), %rsi
imulq %rax, %rsi
leaq 0x20(%rsp), %rdx
movq %rcx, (%rdx)
movq %rsi, 0x8(%rdx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2842
jmp 0x4699
leaq 0x8(%r14), %rsi
leaq 0x70(%rsp), %rdi
movq %rsi, 0x50(%rsp)
movq %rbx, 0x8(%rsp)
callq 0x475e
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rax
xorl %r15d, %r15d
cmpq %rax, %rdi
je 0x44c8
movq %rdi, %rcx
addq (%rcx), %r15
addq $0x8, %rcx
cmpq %rax, %rcx
jne 0x44bc
testq %rdi, %rdi
je 0x44dd
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
movq 0x38(%r14), %rbx
leaq 0x4850(%rip), %rax      # 0x8d38
leaq 0x28(%rsp), %r13
movq %rax, -0x8(%r13)
leaq 0x8(%rbx), %rsi
movq %r13, %rdi
callq 0x475e
leaq 0x485c(%rip), %rax      # 0x8d60
movq %rax, 0x20(%rsp)
movups 0x20(%rbx), %xmm0
movups %xmm0, 0x40(%rsp)
leaq 0x58(%rsp), %rdi
movq %r13, %rsi
callq 0x475e
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rax
xorl %ebx, %ebx
cmpq %rax, %rdi
je 0x453f
movq %rdi, %rcx
addq (%rcx), %rbx
addq $0x8, %rcx
cmpq %rax, %rcx
jne 0x4533
testq %rdi, %rdi
je 0x4551
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
movq 0x8(%r14), %rdi
movq %r14, %r9
movq 0x10(%r14), %r13
subq %rdi, %r13
shrq $0x3, %r13
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r14
decl %ebp
imull 0x4(%rsp), %ebp
movl %ebp, %eax
cltd
idivl %r13d
subq %r8, %r14
shrq $0x3, %r14
movslq %eax, %rbp
movq %r15, %r12
imulq %rbp, %r12
imulq %rbx, %rbp
testl %edx, %edx
jle 0x45b1
movl %edx, %ecx
xorl %esi, %esi
movl %esi, %eax
cltd
idivl %r13d
addq (%rdi,%rdx,8), %r12
movl %esi, %eax
cltd
idivl %r14d
addq (%r8,%rdx,8), %rbp
incl %esi
cmpl %esi, %ecx
jne 0x4597
imulq 0x20(%r9), %r15
addq 0x28(%r9), %r12
addq %r15, %r12
imulq 0x40(%rsp), %rbx
addq 0x48(%rsp), %rbp
addq %rbx, %rbp
movq %r12, 0x10(%rsp)
movq %rbp, 0x18(%rsp)
movq 0x8(%rsp), %rbx
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x45f3
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rbx)
jmp 0x4600
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x2842
testl %r14d, %r14d
sete %al
cmpl $0x2, 0x4(%rsp)
setl %cl
orb %al, %cl
jne 0x4676
decl 0x4(%rsp)
xorl %r15d, %r15d
movl %r15d, %eax
cltd
idivl %r13d
movq 0x50(%rsp), %rax
movq (%rax), %rax
addq (%rax,%rdx,8), %r12
movl %r15d, %eax
cltd
idivl %r14d
movq 0x28(%rsp), %rax
addq (%rax,%rdx,8), %rbp
movq %r12, 0x10(%rsp)
movq %rbp, 0x18(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x465f
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rbx)
jmp 0x466c
movq %rbx, %rdi
leaq 0x10(%rsp), %rdx
callq 0x2842
incl %r15d
cmpl %r15d, 0x4(%rsp)
jne 0x4619
leaq 0x46bb(%rip), %rax      # 0x8d38
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x4699
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b37(%rip), %rdi      # 0x61ec
leaq 0x1a5b(%rip), %rsi      # 0x6117
leaq 0x1b5d(%rip), %rcx      # 0x6220
movl $0x2c8, %edx            # imm = 0x2C8
callq 0x20c0
jmp 0x46df
jmp 0x46df
jmp 0x46da
jmp 0x46da
movq %rbx, 0x8(%rsp)
movq %rax, %r14
jmp 0x4705
movq %rax, %r14
leaq 0x464f(%rip), %rax      # 0x8d38
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x4705
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4723
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x2140
movq %r14, %rdi
callq 0x21c0
nop