// File: 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:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movq 0x68(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0xd3a00
testb $0x1, %al
jne 0x136421
movq 0x60(%rsp), %rdi
callq 0xd3a00
testb $0x1, %al
jne 0x136421
jmp 0x136470
movl $0x38, %edi
callq 0xd8380
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x10(%rsp)
xorl %esi, %esi
callq 0xe26d0
jmp 0x13643f
movq 0x10(%rsp), %rax
movq %rax, 0x70(%rsp)
jmp 0x13664a
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
movl $0x38, %esi
callq 0xd8620
jmp 0x136654
movl $0x38, %edi
callq 0xd8380
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x8(%rsp)
movl $0x1, %esi
callq 0xe26d0
jmp 0x136491
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rax
movq %rax, 0x48(%rsp)
callq 0xdd3c0
movl %eax, 0x4(%rsp)
movq 0x60(%rsp), %rdi
callq 0xdd3c0
movl %eax, %ecx
movl 0x4(%rsp), %eax
cmpl %ecx, %eax
jle 0x1364cc
movq 0x18(%rsp), %rdi
callq 0xdd3c0
movl %eax, (%rsp)
jmp 0x1364d9
movq 0x60(%rsp), %rdi
callq 0xdd3c0
movl %eax, (%rsp)
movl (%rsp), %eax
movl %eax, 0x44(%rsp)
movq 0x48(%rsp), %rax
movl $0x0, (%rax)
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x13662a
movq 0x18(%rsp), %rdi
movl 0x40(%rsp), %esi
shll $0x3, %esi
movl $0x20, %edx
callq 0xdf280
movq 0x18(%rsp), %rdi
movl %eax, 0x3c(%rsp)
movl 0x40(%rsp), %esi
shll $0x3, %esi
movl $0x20, %edx
callq 0xd7dc0
movl %eax, 0x38(%rsp)
movq 0x60(%rsp), %rdi
movl 0x40(%rsp), %esi
shll $0x3, %esi
movl $0x20, %edx
callq 0xdf280
movl %eax, 0x34(%rsp)
movq 0x60(%rsp), %rdi
movl 0x40(%rsp), %esi
shll $0x3, %esi
movl $0x20, %edx
callq 0xd7dc0
movl %eax, 0x30(%rsp)
movl 0x3c(%rsp), %eax
andl 0x34(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
andl 0x38(%rsp), %eax
movl 0x2c(%rsp), %ecx
andl 0x30(%rsp), %ecx
cmpl %ecx, %eax
je 0x1365d0
movq 0x48(%rsp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq 0x48(%rsp), %rdi
callq 0xda700
movq 0x48(%rsp), %rax
movq %rax, 0x70(%rsp)
jmp 0x13664a
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
movl $0x38, %esi
callq 0xd8620
jmp 0x136654
movl 0x3c(%rsp), %eax
orl 0x34(%rsp), %eax
movl %eax, 0x28(%rsp)
movl 0x3c(%rsp), %eax
andl 0x38(%rsp), %eax
movl 0x34(%rsp), %ecx
andl 0x30(%rsp), %ecx
orl %ecx, %eax
movl %eax, 0x24(%rsp)
movq 0x48(%rsp), %rdi
addq $0x8, %rdi
leaq 0x28(%rsp), %rsi
callq 0xd2df0
movq 0x48(%rsp), %rdi
addq $0x20, %rdi
leaq 0x24(%rsp), %rsi
callq 0xd2df0
movslq 0x40(%rsp), %rax
addq $0x4, %rax
movl %eax, 0x40(%rsp)
jmp 0x1364f3
movl 0x44(%rsp), %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x4(%rax)
movq 0x48(%rsp), %rdi
callq 0xda700
movq 0x48(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
addq $0x78, %rsp
retq
movq 0x58(%rsp), %rdi
callq 0xe0be0
nop