// File: /workspace/github_cpp_makefile_star2_O2/junhe[P]libpatterndetector/pattern.cpp
// Function: PatternUnit::append(PatternUnit&)
bool
PatternUnit::append( PatternUnit &other )
{

//    mlog(IDX_WARN, "in %s", __FUNCTION__);

    if ( this->isSeqRepeating() 
        && other.isSeqRepeating() )
    {
        if ( this->size() > 1 && other.size() > 1 ) {
            //case 1. both has size > 1
            if ( this->seq[0] == other.seq[0] 
                 && this->init + this->seq[0]*this->size() == other.init ) {
                int newsize = this->size() + other.size();
                this->seq.clear();
                this->seq.push_back(other.seq[0]);
                this->cnt = newsize;
                return true;
            } else {
                return false;
            }               
        } else if ( this->size() == 1 && other.size() == 1 ) {
            //case 2. both has size == 1
            //definitely follows
            this->seq.clear();
            this->seq.push_back(other.init - this->init);
            this->cnt = 2; //has two now
            return true;
        } else if ( this->size() == 1 && other.size() > 1 ) {
            if ( other.init - this->init == other.seq[0] ) {
                int newsize = this->size() + other.size();
                this->seq.clear();
                this->seq.push_back(other.seq[0]);
                this->cnt = newsize;
                return true;
            } else {
                return false;
            }
        } else if ( this->size() > 1 && other.size() == 1) {
            if ( this->init + this->seq[0]*this->size() == other.init ) {
                int newsize = this->size() + other.size();
                off_t tmp = this->seq[0];
                this->seq.clear();
                this->seq.push_back(tmp);
                this->cnt = newsize;
                return true;
            } else {
                return false;
            }
        }
    } else {
        return false;  //TODO:should handle this case
    }
    // Never should reach here
    assert(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
callq 0x2c30
testb %al, %al
je 0x2c04
movq %r14, %rdi
callq 0x2c30
testb %al, %al
je 0x2c04
movq %rbx, %rdi
callq 0x29c6
movl %eax, %ebp
cmpl $0x2, %eax
jl 0x2b51
movq %r14, %rdi
callq 0x29c6
movl %eax, %r15d
cmpl $0x2, %eax
jl 0x2b96
movq 0x8(%rbx), %rax
movq (%rax), %rcx
movq 0x8(%r14), %rsi
cmpq (%rsi), %rcx
jne 0x2c04
movl %ebp, %edx
imulq %rdx, %rcx
addq 0x28(%rbx), %rcx
cmpq 0x28(%r14), %rcx
jne 0x2c04
leaq 0x8(%rbx), %rdi
addl %ebp, %r15d
cmpq %rax, 0x10(%rbx)
je 0x2b44
movq %rax, 0x10(%rbx)
callq 0x3b42
movl %r15d, %eax
jmp 0x2bfc
cmpl $0x1, %ebp
jne 0x2c11
movq %r14, %rdi
callq 0x29c6
cmpl $0x1, %eax
jne 0x2bcc
leaq 0x8(%rbx), %rdi
movq 0x8(%rbx), %rax
cmpq %rax, 0x10(%rbx)
je 0x2b79
movq %rax, 0x10(%rbx)
movq 0x28(%r14), %rax
subq 0x28(%rbx), %rax
movq %rsp, %rsi
movq %rax, (%rsi)
callq 0x40cc
movq $0x2, 0x20(%rbx)
jmp 0x2c00
cmpl $0x1, %r15d
jne 0x2c11
movq 0x8(%rbx), %rax
movq (%rax), %rcx
movl %ebp, %edx
imulq %rcx, %rdx
addq 0x28(%rbx), %rdx
cmpq 0x28(%r14), %rdx
jne 0x2c04
leaq 0x8(%rbx), %rdi
incl %ebp
movq %rcx, (%rsp)
cmpq %rax, 0x10(%rbx)
je 0x2bc7
movq %rax, 0x10(%rbx)
movq %rsp, %rsi
jmp 0x2bf5
jle 0x2c11
movl %eax, %ebp
movq 0x8(%r14), %rsi
movq 0x28(%r14), %rax
subq 0x28(%rbx), %rax
cmpq (%rsi), %rax
jne 0x2c04
incl %ebp
leaq 0x8(%rbx), %rdi
movq 0x8(%rbx), %rax
cmpq %rax, 0x10(%rbx)
je 0x2bf5
movq %rax, 0x10(%rbx)
callq 0x3b42
movl %ebp, %eax
movq %rax, 0x20(%rbx)
movb $0x1, %al
jmp 0x2c06
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x26fb(%rip), %rdi      # 0x5313
leaq 0x24f8(%rip), %rsi      # 0x5117
leaq 0x24fd(%rip), %rcx      # 0x5123
movl $0xc1, %edx
callq 0x20b0