// File: /workspace/github_cpp_makefile_star2_O3/jstaursky[P]hutch/src/Sleigh/slghpattern.cc
// Function: PatternBlock::intersect(PatternBlock const*) const
PatternBlock *PatternBlock::intersect(const PatternBlock *b) const

{ // Construct the intersecting pattern
  if (alwaysFalse() || b->alwaysFalse())
    return new PatternBlock(false);
  PatternBlock *res = new PatternBlock(true);
  int4 maxlength = (getLength() > b->getLength()) ? getLength() : b->getLength();

  res->offset = 0;
  int4 offset = 0;
  uintm mask1,val1,mask2,val2,commonmask;
  uintm resmask,resval;
  while(offset < maxlength) {
    mask1 = getMask(offset*8,sizeof(uintm)*8);
    val1 = getValue(offset*8,sizeof(uintm)*8);
    mask2 = b->getMask(offset*8,sizeof(uintm)*8);
    val2 = b->getValue(offset*8,sizeof(uintm)*8);
    commonmask = mask1 & mask2;	// Bits in mask shared by both patterns
    if ((commonmask & val1) != (commonmask & val2)) {
      res->nonzerosize = -1;	// Impossible pattern
      res->normalize();
      return res;
    }
    resmask = mask1 | mask2;
    resval = (mask1 & val1) | (mask2 & val2);
    res->maskvec.push_back(resmask);
    res->valvec.push_back(resval);
    offset += sizeof(uintm);
  }
  res->nonzerosize = maxlength;
  res->normalize();
  return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, 0x18(%rsp)
cmpl $-0x1, 0x4(%rdi)
je 0x61fe7
movq %rsi, %r14
cmpl $-0x1, 0x4(%rsi)
je 0x61fe7
movl $0x38, %edi
callq 0x40810
movq %rax, %rbx
movq %rax, %rdi
movl $0x1, %esi
movq %rax, 0x8(%rsp)
callq 0x42350
movq 0x18(%rsp), %rcx
movl 0x4(%rcx), %eax
addl (%rcx), %eax
movl 0x4(%r14), %ecx
addl (%r14), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl $0x0, (%rbx)
movl %ecx, (%rsp)
testl %ecx, %ecx
jle 0x6200c
movq %r14, 0x30(%rsp)
leaq 0x8(%rbx), %rax
movq %rax, 0x28(%rsp)
addq $0x20, %rbx
movq %rbx, 0x20(%rsp)
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %esi
movl $0x20, %edx
callq 0x41a80
movl %eax, %r12d
movq %rbx, %rdi
movl %ebp, %esi
movl $0x20, %edx
callq 0x40760
movl %eax, %r13d
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %esi
movl $0x20, %edx
callq 0x41a80
movl %eax, %r14d
movq %rbx, %rdi
movl %ebp, %esi
movl $0x20, %edx
callq 0x40760
movl %eax, %ecx
xorl %r13d, %ecx
andl %r12d, %ecx
testl %r14d, %ecx
jne 0x62000
andl %r14d, %eax
orl %r12d, %r14d
movl %r14d, 0x14(%rsp)
andl %r12d, %r13d
orl %eax, %r13d
movl %r13d, 0x4(%rsp)
movq 0x8(%rsp), %rbx
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x61f9c
movl %r14d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x10(%rbx)
jmp 0x61fab
movq 0x28(%rsp), %rdi
leaq 0x14(%rsp), %rdx
callq 0x40780
movq 0x28(%rbx), %rsi
cmpq 0x30(%rbx), %rsi
je 0x61fc5
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rbx)
jmp 0x61fd4
movq 0x20(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0x40780
addl $0x4, %r15d
addl $0x20, %ebp
cmpl (%rsp), %r15d
jl 0x61f0a
jmp 0x6200c
movl $0x38, %edi
callq 0x40810
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x42350
jmp 0x6201a
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rbx
movl (%rsp), %eax
movl %eax, 0x4(%rbx)
movq %rbx, %rdi
callq 0x40d70
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x62033
movq %rbx, 0x8(%rsp)
movq %rax, %r14
movl $0x38, %esi
movq 0x8(%rsp), %rdi
callq 0x40880
movq %r14, %rdi
callq 0x41f10
nop