// File: /workspace/github_cpp_makefile_star2_O1/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 0x47ae
cmpq $0x0, 0x20(%rax)
jle 0x47ae
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 0x4536
sarq $0x3, %rcx
imulq 0x20(%r14), %rcx
cmpq $0x1, %rcx
ja 0x4574
movq 0x28(%rax), %rax
movq 0x28(%r14), %rcx
addq %rax, %rcx
movslq 0x4(%rsp), %rdx
imulq %rax, %rdx
movq %rcx, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x46e1
movups 0x20(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rbx)
jmp 0x4799
leaq 0x8(%r14), %rsi
leaq 0x70(%rsp), %rdi
movq %rsi, 0x50(%rsp)
movq %rbx, 0x8(%rsp)
callq 0x485e
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rax
xorl %r15d, %r15d
cmpq %rax, %rdi
je 0x45ad
movq %rdi, %rcx
addq (%rcx), %r15
addq $0x8, %rcx
cmpq %rax, %rcx
jne 0x45a1
testq %rdi, %rdi
je 0x45c2
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
movq 0x38(%r14), %rbx
leaq 0x476b(%rip), %rax      # 0x8d38
leaq 0x28(%rsp), %r13
movq %rax, -0x8(%r13)
leaq 0x8(%rbx), %rsi
movq %r13, %rdi
callq 0x485e
movq 0x20(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x476e(%rip), %rax      # 0x8d60
movq %rax, 0x20(%rsp)
movq 0x28(%rbx), %rax
movq %rax, 0x48(%rsp)
leaq 0x58(%rsp), %rdi
movq %r13, %rsi
callq 0x485e
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rax
xorl %ebx, %ebx
cmpq %rax, %rdi
je 0x462d
movq %rdi, %rcx
addq (%rcx), %rbx
addq $0x8, %rcx
cmpq %rax, %rcx
jne 0x4621
testq %rdi, %rdi
je 0x463f
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 0x469f
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 0x4685
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 0x46f3
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rbx)
jmp 0x4700
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
callq 0x2848
jmp 0x4799
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x2848
testl %r14d, %r14d
sete %al
cmpl $0x2, 0x4(%rsp)
setl %cl
orb %al, %cl
jne 0x4776
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 0x475f
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rbx)
jmp 0x476c
movq %rbx, %rdi
leaq 0x10(%rsp), %rdx
callq 0x2848
incl %r15d
cmpl %r15d, 0x4(%rsp)
jne 0x4719
leaq 0x45bb(%rip), %rax      # 0x8d38
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x4799
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 0x1aa7(%rip), %rdi      # 0x625c
leaq 0x19cb(%rip), %rsi      # 0x6187
leaq 0x1acd(%rip), %rcx      # 0x6290
movl $0x2c8, %edx            # imm = 0x2C8
callq 0x20c0
jmp 0x47df
movq %rbx, 0x8(%rsp)
jmp 0x47da
jmp 0x47df
jmp 0x47da
movq %rax, %r14
jmp 0x4805
movq %rax, %r14
leaq 0x454f(%rip), %rax      # 0x8d38
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x4805
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4823
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x2140
movq %r14, %rdi
callq 0x21c0
nop