// File: 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
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x6b00
leaq -0x40(%rbp), %rdi
callq 0x6b00
leaq -0x48(%rbp), %rdi
callq 0x6e70
movq -0x8(%rbp), %rdi
callq 0x6e90
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6f00
movq %rax, -0x58(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x6ec0
testb $0x1, %al
jne 0x4dd3
jmp 0x4e29
leaq -0x48(%rbp), %rdi
callq 0x6f30
movq %rax, %rsi
leaq -0x28(%rbp), %rdi
callq 0x6d70
jmp 0x4dea
leaq -0x48(%rbp), %rdi
callq 0x6f30
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x40(%rbp), %rdi
callq 0x6d70
jmp 0x4e05
jmp 0x4e07
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x6f50
movq %rax, -0x70(%rbp)
jmp 0x4db3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x51fb
leaq -0xa8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x6f90
jmp 0x4e3b
leaq -0x90(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x5220
jmp 0x4e50
leaq -0xa8(%rbp), %rdi
callq 0x3220
leaq -0xb0(%rbp), %rdi
callq 0x3030
movl $0x0, -0xb4(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x7080
movq %rax, -0x1a8(%rbp)
jmp 0x4e87
movq -0x1a8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x70f0
movq %rax, -0x1b0(%rbp)
jmp 0x4eb8
movq -0x1b0(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x70b0
testb $0x1, %al
jne 0x4ee2
jmp 0x51c6
leaq -0x118(%rbp), %rdi
callq 0x7120
jmp 0x4ef0
movl -0xb4(%rbp), %eax
movl %eax, -0x1cc(%rbp)
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x3130
movq -0x1c8(%rbp), %rdi
movl 0x20(%rax), %eax
movl %eax, -0x1bc(%rbp)
callq 0x3130
movq %rax, %rdi
addq $0x8, %rdi
callq 0x6c70
movq %rax, %rcx
movl -0x1bc(%rbp), %eax
imull %ecx, %eax
movl %eax, -0x11c(%rbp)
movl $0x1, -0x120(%rbp)
leaq -0x11c(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x7170
movq %rax, -0x1b8(%rbp)
jmp 0x4f68
movq -0x1b8(%rbp), %rcx
movl -0x1cc(%rbp), %eax
addl (%rcx), %eax
movl %eax, -0xb8(%rbp)
movslq -0xb8(%rbp), %rax
movq %rax, -0x1d8(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x6c70
movq %rax, %rcx
movq -0x1d8(%rbp), %rax
cmpq %rcx, %rax
ja 0x4fa5
jmp 0x5003
leaq 0x81fb(%rip), %rdi      # 0xd1a7
leaq 0x81ba(%rip), %rsi      # 0xd16d
movl $0x137, %edx            # imm = 0x137
leaq 0x8210(%rip), %rcx      # 0xd1cf
callq 0x20a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3220
jmp 0x51fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x51ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x51b8
leaq -0xb0(%rbp), %rdi
callq 0x71b0
movq %rax, %rsi
leaq -0x118(%rbp), %rdi
callq 0x71d0
jmp 0x5020
leaq -0x40(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x69a0
movq %rax, -0x148(%rbp)
movslq -0xb4(%rbp), %rsi
leaq -0x148(%rbp), %rdi
callq 0x7210
movq -0x1e8(%rbp), %rdi
movq %rax, -0x140(%rbp)
callq 0x69a0
movq %rax, -0x158(%rbp)
movslq -0xb8(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0x7210
movq %rax, -0x150(%rbp)
leaq -0x159(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x7250
movq -0x1e0(%rbp), %rcx
movq -0x140(%rbp), %rsi
movq -0x150(%rbp), %rdx
leaq -0x138(%rbp), %rdi
callq 0x7270
jmp 0x50b4
leaq -0x159(%rbp), %rdi
callq 0x3400
leaq -0x198(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x6f90
jmp 0x50d5
leaq -0x180(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x5220
jmp 0x50ea
leaq -0xe8(%rbp), %rdi
leaq -0x180(%rbp), %rsi
movq %rsi, -0x1f0(%rbp)
callq 0x72f0
movq -0x1f0(%rbp), %rdi
callq 0x2bd0
leaq -0x198(%rbp), %rdi
callq 0x3220
movq -0x10(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x7320
jmp 0x512e
movl -0xb8(%rbp), %eax
movl %eax, -0xb4(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x3220
leaq -0x118(%rbp), %rdi
callq 0x2ba0
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
callq 0x3150
movq %rax, -0x1a0(%rbp)
jmp 0x4ea3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x159(%rbp), %rdi
callq 0x3400
jmp 0x51b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x51ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x3220
leaq -0x138(%rbp), %rdi
callq 0x3220
leaq -0x118(%rbp), %rdi
callq 0x2ba0
jmp 0x51ef
leaq -0x90(%rbp), %rdi
callq 0x2bd0
leaq -0x40(%rbp), %rdi
callq 0x3220
leaq -0x28(%rbp), %rdi
callq 0x3220
xorl %eax, %eax
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
leaq -0x90(%rbp), %rdi
callq 0x2bd0
leaq -0x40(%rbp), %rdi
callq 0x3220
leaq -0x28(%rbp), %rdi
callq 0x3220
movq -0x60(%rbp), %rdi
callq 0x21a0
nopw %cs:(%rax,%rax)