// File: /workspace/github_cpp_makefile_star2_O3/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 %rbx
subq $0x10, %rsp
movq %rsi, %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rcx
movq 0x10(%rdi), %rsi
cmpq %rsi, %rcx
je 0x2cf5
xorl %edx, %edx
testq %rdx, %rdx
je 0x2ce4
movq (%rcx,%rdx), %rdi
cmpq -0x8(%rcx,%rdx), %rdi
jne 0x2f4f
leaq (%rcx,%rdx), %rdi
addq $0x8, %rdi
addq $0x8, %rdx
cmpq %rsi, %rdi
jne 0x2cd0
movq 0x8(%rax), %rdx
movq 0x10(%rax), %r8
cmpq %r8, %rdx
je 0x2d29
xorl %edi, %edi
testq %rdi, %rdi
je 0x2d18
movq (%rdx,%rdi), %r9
cmpq -0x8(%rdx,%rdi), %r9
jne 0x2f4f
leaq (%rdx,%rdi), %r9
addq $0x8, %r9
addq $0x8, %rdi
cmpq %r8, %r9
jne 0x2d04
leaq 0x8(%rbx), %rdi
movq 0x20(%rbx), %r9
testq %r9, %r9
je 0x2dc2
movq %rsi, %r11
subq %rcx, %r11
movq %r11, %r10
shrq $0x3, %r10
imulq %r9, %r10
cmpl $0x2, %r10d
jl 0x2db8
movq 0x20(%rax), %r14
testq %r14, %r14
je 0x2db8
movq %r8, %r15
subq %rdx, %r15
shrq $0x3, %r15
imulq %r15, %r14
cmpl $0x2, %r14d
jl 0x2db8
movq (%rcx), %r8
cmpq (%rdx), %r8
jne 0x2f4f
imulq %r9, %r11
shrq $0x3, %r11
movslq %r11d, %r9
imulq %r8, %r9
addq 0x28(%rbx), %r9
cmpq 0x28(%rax), %r9
jne 0x2f4f
cmpq %rsi, %rcx
je 0x2da3
movq %rcx, 0x10(%rbx)
movq %rcx, %rsi
addq %r10, %r14
cmpq 0x18(%rbx), %rsi
je 0x2f62
movq %r8, (%rsi)
jmp 0x2f45
cmpl $0x1, %r10d
jne 0x2e5d
movq 0x20(%rax), %r14
testq %r14, %r14
je 0x2de2
movq %r8, %r15
subq %rdx, %r15
shrq $0x3, %r15
movl %r14d, %r10d
imull %r15d, %r10d
cmpl $0x1, %r10d
jne 0x2e15
cmpq %rsi, %rcx
je 0x2dee
movq %rcx, 0x10(%rbx)
movq %rcx, %rsi
movq 0x28(%rax), %rax
subq 0x28(%rbx), %rax
movq %rax, 0x8(%rsp)
cmpq 0x18(%rbx), %rsi
je 0x2ee7
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x10(%rbx)
jmp 0x2ef1
testq %r9, %r9
je 0x2efb
movq %rsi, %r11
subq %rcx, %r11
movq %r11, %r10
shrq $0x3, %r10
imulq %r9, %r10
cmpl $0x1, %r10d
jne 0x2e5d
movq 0x20(%rax), %r14
testq %r14, %r14
je 0x2e4c
imulq %r15, %r14
cmpl $0x2, %r14d
jge 0x2f05
movq %rsi, %r11
subq %rcx, %r11
movq %r11, %r10
shrq $0x3, %r10
imulq %r9, %r10
cmpl $0x2, %r10d
jl 0x2f7a
movq 0x20(%rax), %r15
testq %r15, %r15
je 0x2e88
movq %r8, %r14
subq %rdx, %r14
shrq $0x3, %r14
imull %r15d, %r14d
cmpl $0x1, %r14d
jne 0x2f7a
movq (%rcx), %r14
imulq %r9, %r11
shrq $0x3, %r11
movslq %r11d, %r9
imulq %r14, %r9
addq 0x28(%rbx), %r9
cmpq 0x28(%rax), %r9
jne 0x2f4f
subq %rdx, %r8
shrq $0x3, %r8
imulq %r15, %r8
testq %r15, %r15
movl $0x1, %r15d
cmovneq %r8, %r15
movq %r14, 0x8(%rsp)
cmpq %rsi, %rcx
je 0x2ed1
movq %rcx, 0x10(%rbx)
movq %rcx, %rsi
addq %r10, %r15
cmpq 0x18(%rbx), %rsi
je 0x2f53
movq %r14, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x10(%rbx)
jmp 0x2f5d
leaq 0x8(%rsp), %rdx
callq 0x4ca0
movq $0x2, 0x20(%rbx)
jmp 0x2f6e
imulq %r15, %r14
cmpl $0x1, %r14d
jle 0x2f7a
movq 0x28(%rax), %rax
subq 0x28(%rbx), %rax
cmpq (%rdx), %rax
jne 0x2f4f
movq %rsi, %r10
subq %rcx, %r10
shrq $0x3, %r10
imulq %r9, %r10
testq %r9, %r9
movl $0x1, %r8d
cmovneq %r10, %r8
cmpq %rcx, %rsi
je 0x2f39
movq %rcx, 0x10(%rbx)
movq %rcx, %rsi
addq %r8, %r14
cmpq 0x18(%rbx), %rsi
je 0x2f62
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x10(%rbx)
jmp 0x2f67
xorl %eax, %eax
jmp 0x2f70
leaq 0x8(%rsp), %rdx
callq 0x4dc0
movslq %r15d, %rax
jmp 0x2f6a
callq 0x4dc0
movslq %r14d, %rax
movq %rax, 0x20(%rbx)
movb $0x1, %al
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
leaq 0x3392(%rip), %rdi      # 0x6313
leaq 0x318f(%rip), %rsi      # 0x6117
leaq 0x3194(%rip), %rcx      # 0x6123
movl $0xc1, %edx
callq 0x20c0
nop