// File: /workspace/github_cpp_makefile_star2_O2/junhe[P]libpatterndetector/pattern.cpp
// Function: PatternUtil::getReqPatList(std::vector<Request, std::allocator<Request>> const&, RequestPatternList&)
int
PatternUtil::getReqPatList( const vector<Request> &reqs,
                            RequestPatternList &patlist )
{
    vector<off_t> offsets; 
    vector<off_t> lengths;

    vector<Request>::const_iterator it;

    for ( it = reqs.begin() ; 
          it != reqs.end();
          it++ )
    {
        offsets.push_back(it->offset);
        lengths.push_back(it->length);
    }

    // Get the patterns of logical offsets first
    PatChain<PatternUnit>
        offset_pat = getPatChainFromSeq(offsets);
    
    //cout << "before show. offset.size()=" <<
    //     offsets.size() << endl;
    //cout << offset_pat.show() << endl;

    vector<PatternUnit>::const_iterator chain_iter;
    int range_start = 0, range_end; //the range currently processing
    for (chain_iter = offset_pat.begin();
            chain_iter != offset_pat.end();
            chain_iter++ ) 
    {
        RequestPattern reqpat;
        range_end = range_start
                  + max( int(chain_iter->cnt 
                             * chain_iter->seq.size()), 1 );  
        assert( ((ssize_t) range_end) <= offsets.size() );
        
        reqpat.offset = *chain_iter;
        vector<off_t> length_seq(lengths.begin()+range_start,
                                 lengths.begin()+range_end);
        reqpat.length = getPatChainFromSeq(length_seq);

        patlist.list.push_back( reqpat );
        
        range_start = range_end;
    }
    
    //cout << patlist.show();
    
    return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
movq %rsp, %r14
andq $0x0, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
leaq 0x20(%rsp), %r15
movaps %xmm0, (%r15)
andq $0x0, 0x10(%r15)
movq (%rdi), %r12
cmpq 0x8(%rbx), %r12
je 0x2eb5
movq %r14, %rdi
movq %r12, %rsi
callq 0x3b42
addq $0x8, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x3b42
addq $0x8, %r12
jmp 0x2e8f
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x3b94
leaq 0x58(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x30ca
leaq 0x40(%rsp), %rdi
callq 0x2666
movq 0x60(%rsp), %r14
xorl %r13d, %r13d
leaq 0xe0(%rsp), %rbp
leaq 0xf8(%rsp), %r12
leaq 0xc8(%rsp), %rbx
cmpq 0x68(%rsp), %r14
je 0x300b
leaq 0x80(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x4e48(%rip), %rax      # 0x7d68
movq %rax, 0x78(%rsp)
leaq 0xb0(%rsp), %rax
movups %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x4e5c(%rip), %rax      # 0x7d98
movq %rax, 0xa8(%rsp)
movq 0x10(%r14), %r15
subq 0x8(%r14), %r15
shrq $0x3, %r15
imull 0x20(%r14), %r15d
cmpl $0x2, %r15d
jge 0x2f61
pushq $0x1
popq %rax
movl %eax, %r15d
addl %r13d, %r15d
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x3, %rax
cmpq %r15, %rax
jb 0x303b
leaq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0x3be2
movq 0x20(%rsp), %rax
movl %r13d, %ecx
leaq (%rax,%rcx,8), %rsi
leaq (%rax,%r15,8), %rdx
movq %rbp, %rdi
movq %r12, %rcx
callq 0x3c04
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3b94
leaq 0x78(%rsp), %r13
movq %r12, %rdi
movq %rbx, %rsi
callq 0x30ca
leaq 0xb0(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x3f32
movq %r12, %rdi
callq 0x250e
movq %rbx, %rdi
callq 0x2666
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x3c36
movq %rbp, %rdi
callq 0x2666
movq %r13, %rdi
callq 0x24f8
addq $0x30, %r14
movl %r15d, %r13d
jmp 0x2efb
leaq 0x58(%rsp), %rdi
callq 0x250e
leaq 0x20(%rsp), %rdi
callq 0x2666
movq %rsp, %rdi
callq 0x2666
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x210f(%rip), %rdi      # 0x5151
leaq 0x20ce(%rip), %rsi      # 0x5117
leaq 0x2129(%rip), %rcx      # 0x5179
movl $0x137, %edx            # imm = 0x137
callq 0x20b0
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x2666
jmp 0x30af
jmp 0x30ac
jmp 0x307f
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x2666
jmp 0x3082
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x2666
jmp 0x3096
jmp 0x3093
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x24f8
leaq 0x58(%rsp), %rdi
callq 0x250e
jmp 0x30af
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2666
movq %rsp, %rdi
callq 0x2666
movq %rbx, %rdi
callq 0x21a0
nop