// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rax
movq 0x10(%rdi), %rcx
cmpq %rcx, %rax
sete %dl
je 0x2cf1
xorl %edi, %edi
testq %rdi, %rdi
je 0x2cdd
movq (%rax,%rdi), %r8
cmpq -0x8(%rax,%rdi), %r8
jne 0x2cf1
leaq (%rax,%rdi), %rdx
addq $0x8, %rdx
addq $0x8, %rdi
cmpq %rcx, %rdx
sete %dl
jne 0x2ccd
testb $0x1, %dl
je 0x2f71
movq 0x8(%rsi), %rdx
movq 0x10(%rsi), %r14
cmpq %r14, %rdx
sete %dil
je 0x2d33
xorl %r8d, %r8d
testq %r8, %r8
je 0x2d1e
movq (%rdx,%r8), %r9
cmpq -0x8(%rdx,%r8), %r9
jne 0x2d33
leaq (%rdx,%r8), %rdi
addq $0x8, %rdi
addq $0x8, %r8
cmpq %r14, %rdi
sete %dil
jne 0x2d0e
testb $0x1, %dil
je 0x2f71
leaq 0x8(%rbx), %rdi
movq 0x20(%rbx), %r9
subq %rax, %rcx
movq %rcx, %r8
shrq $0x3, %r8
testq %r9, %r9
je 0x2dfe
movl %r9d, %r10d
imull %r8d, %r10d
cmpl $0x2, %r10d
jl 0x2dfe
movq 0x20(%rsi), %r10
testq %r10, %r10
je 0x2dfe
movq %r14, %r15
subq %rdx, %r15
shrq $0x3, %r15
movl %r10d, %r11d
imull %r15d, %r11d
cmpl $0x2, %r11d
jl 0x2dfe
movq (%rax), %r14
movq (%rdx), %r11
cmpq %r11, %r14
jne 0x2f71
imulq %r9, %rcx
shrq $0x3, %rcx
testq %r9, %r9
movslq %ecx, %r12
movl $0x1, %ecx
cmoveq %rcx, %r12
imulq %r12, %r14
addq 0x28(%rbx), %r14
cmpq 0x28(%rsi), %r14
jne 0x2f71
imulq %r9, %r8
testq %r9, %r9
cmoveq %rcx, %r8
imulq %r10, %r15
testq %r10, %r10
cmoveq %rcx, %r15
cmpq %rax, 0x10(%rbx)
je 0x2de5
movq %rax, 0x10(%rbx)
addq %r8, %r15
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x2fcb
movq %r11, (%rsi)
jmp 0x2f67
testq %r9, %r9
je 0x2e10
movl %r9d, %r10d
imull %r8d, %r10d
cmpl $0x1, %r10d
jne 0x2e35
movq 0x20(%rsi), %r10
testq %r10, %r10
je 0x2f7f
movq %r14, %r11
subq %rdx, %r11
shrq $0x3, %r11
imull %r11d, %r10d
cmpl $0x1, %r10d
je 0x2f7f
testq %r9, %r9
je 0x2efa
movl %r9d, %r10d
imull %r8d, %r10d
cmpl $0x1, %r10d
je 0x2efa
testq %r9, %r9
je 0x2fdb
movl %r9d, %r10d
imull %r8d, %r10d
cmpl $0x2, %r10d
jl 0x2fdb
movq 0x20(%rsi), %r10
subq %rdx, %r14
shrq $0x3, %r14
testq %r10, %r10
je 0x2e89
movl %r10d, %edx
imull %r14d, %edx
cmpl $0x1, %edx
jne 0x2fdb
imulq %r9, %rcx
shrq $0x3, %rcx
testq %r9, %r9
movslq %ecx, %rdx
movl $0x1, %ecx
cmoveq %rcx, %rdx
imulq (%rax), %rdx
addq 0x28(%rbx), %rdx
cmpq 0x28(%rsi), %rdx
jne 0x2f71
imulq %r9, %r8
testq %r9, %r9
cmoveq %rcx, %r8
imulq %r10, %r14
testq %r10, %r10
cmoveq %rcx, %r14
movq (%rax), %rcx
movq %rcx, (%rsp)
cmpq %rax, 0x10(%rbx)
je 0x2ed9
movq %rax, 0x10(%rbx)
addq %r8, %r14
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x2fac
movq %rcx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x10(%rbx)
jmp 0x2fb4
movq 0x20(%rsi), %r10
testq %r10, %r10
je 0x2e4f
movq %r14, %r15
subq %rdx, %r15
shrq $0x3, %r15
movl %r10d, %r11d
imull %r15d, %r11d
cmpl $0x2, %r11d
jl 0x2e4f
movq 0x28(%rsi), %rsi
subq 0x28(%rbx), %rsi
movq (%rdx), %rcx
cmpq %rcx, %rsi
jne 0x2f71
imulq %r9, %r8
testq %r9, %r9
movl $0x1, %esi
cmoveq %rsi, %r8
imulq %r10, %r15
testq %r10, %r10
cmoveq %rsi, %r15
cmpq %rax, 0x10(%rbx)
je 0x2f57
movq %rax, 0x10(%rbx)
addq %r8, %r15
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x2fcb
movq %rcx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x10(%rbx)
jmp 0x2fd0
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
cmpq %rax, 0x10(%rbx)
je 0x2f89
movq %rax, 0x10(%rbx)
movq 0x28(%rsi), %rax
subq 0x28(%rbx), %rax
movq %rax, (%rsp)
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x2fb9
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x10(%rbx)
jmp 0x2fc1
movq %rsp, %rdx
callq 0x4eba
movslq %r14d, %rax
jmp 0x2fd3
movq %rsp, %rdx
callq 0x4d9a
movq $0x2, 0x20(%rbx)
jmp 0x2fd7
callq 0x4eba
movslq %r15d, %rax
movq %rax, 0x20(%rbx)
movb $0x1, %al
jmp 0x2f73
leaq 0x33a1(%rip), %rdi      # 0x6383
leaq 0x319e(%rip), %rsi      # 0x6187
leaq 0x31a3(%rip), %rcx      # 0x6193
movl $0xc1, %edx
callq 0x20c0