// File: jstaursky[P]hutch/src/Sleigh/slghpatexpress.cc
// Function: TokenPattern::commonSubPattern(TokenPattern const&) const
TokenPattern TokenPattern::commonSubPattern(const TokenPattern &tokpat) const

{				// Construct pattern that matches anything
				// that matches either -this- or -tokpat-
  TokenPattern patres((Pattern *)0); // Empty shell
  int4 i;
  bool reversedirection = false;

  if (leftellipsis||tokpat.leftellipsis) {
    if (rightellipsis||tokpat.rightellipsis)
      throw SleighError("Right/left ellipsis in commonSubPattern");
    reversedirection = true;
  }

				// Find common subset of tokens and ellipses
  patres.leftellipsis = leftellipsis || tokpat.leftellipsis;
  patres.rightellipsis = rightellipsis || tokpat.rightellipsis;
  int4 minnum = toklist.size();
  int4 maxnum = tokpat.toklist.size();
  if (maxnum < minnum) {
    int4 tmp = minnum;
    minnum = maxnum;
    maxnum = tmp;
  }
  if (reversedirection) {
    for(i=0;i<minnum;++i) {
      Token *tok = toklist[toklist.size()-1-i];
      if (tok == tokpat.toklist[tokpat.toklist.size()-1-i])
	patres.toklist.insert(patres.toklist.begin(),tok);
      else
	break;
    }
    if (i<maxnum)
      patres.leftellipsis = true;
  }
  else {
    for(i=0;i<minnum;++i) {
      Token *tok = toklist[i];
      if (tok == tokpat.toklist[i])
	patres.toklist.push_back(tok);
      else
	break;
    }
    if (i<maxnum)
      patres.rightellipsis = true;
  }
  
  patres.pattern = pattern->commonSubPattern(tokpat.pattern,0);
  return patres;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0x58(%rsp)
movq %rdi, %rax
movq %rax, 0x60(%rsp)
movq %rdi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
movq %rdx, 0xf0(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x68(%rsp)
movb $0x0, 0xef(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0xd13e0
movq 0x68(%rsp), %rax
movb $0x0, 0xe7(%rsp)
testb $0x1, 0x20(%rax)
jne 0x127d2f
movq 0xf0(%rsp), %rax
testb $0x1, 0x20(%rax)
je 0x127e30
movq 0x68(%rsp), %rax
testb $0x1, 0x21(%rax)
jne 0x127d4c
movq 0xf0(%rsp), %rax
testb $0x1, 0x21(%rax)
je 0x127e28
movb $0x1, 0xab(%rsp)
movl $0x20, %edi
callq 0xd2b40
movq %rax, 0x48(%rsp)
leaq 0xbf(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0xe0c80
movq 0x50(%rsp), %rdx
leaq 0x609a8(%rip), %rsi     # 0x188729
leaq 0xc0(%rsp), %rdi
callq 0xe00a0
jmp 0x127d90
movq 0x48(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0xd06e0
jmp 0x127da4
movq 0x48(%rsp), %rdi
movb $0x0, 0xab(%rsp)
movq 0xa00b0(%rip), %rsi     # 0x1c7e68
movq 0x9fc61(%rip), %rdx     # 0x1c7a20
callq 0xe01f0
jmp 0x128190
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
jmp 0x127e00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0xd4550
leaq 0xbf(%rsp), %rdi
callq 0xd8ec0
testb $0x1, 0xab(%rsp)
jne 0x127e19
jmp 0x127e23
movq 0x48(%rsp), %rdi
callq 0xd5400
jmp 0x128179
movb $0x1, 0xe7(%rsp)
movq 0x68(%rsp), %rcx
movb $0x1, %al
testb $0x1, 0x20(%rcx)
movb %al, 0x47(%rsp)
jne 0x127e50
movq 0xf0(%rsp), %rax
movb 0x20(%rax), %al
movb %al, 0x47(%rsp)
movq 0x68(%rsp), %rcx
movq 0x58(%rsp), %rax
movb 0x47(%rsp), %dl
andb $0x1, %dl
movb %dl, 0x20(%rax)
movb $0x1, %al
testb $0x1, 0x21(%rcx)
movb %al, 0x46(%rsp)
jne 0x127e7f
movq 0xf0(%rsp), %rax
movb 0x21(%rax), %al
movb %al, 0x46(%rsp)
movq 0x68(%rsp), %rdi
movq 0x58(%rsp), %rax
movb 0x46(%rsp), %cl
andb $0x1, %cl
movb %cl, 0x21(%rax)
addq $0x8, %rdi
callq 0xd41b0
movl %eax, 0xa4(%rsp)
movq 0xf0(%rsp), %rdi
addq $0x8, %rdi
callq 0xd41b0
movl %eax, 0xa0(%rsp)
movl 0xa0(%rsp), %eax
cmpl 0xa4(%rsp), %eax
jge 0x127ef5
movl 0xa4(%rsp), %eax
movl %eax, 0x9c(%rsp)
movl 0xa0(%rsp), %eax
movl %eax, 0xa4(%rsp)
movl 0x9c(%rsp), %eax
movl %eax, 0xa0(%rsp)
testb $0x1, 0xe7(%rsp)
je 0x128069
movl $0x0, 0xe8(%rsp)
movl 0xe8(%rsp), %eax
cmpl 0xa4(%rsp), %eax
jge 0x12804b
movq 0x68(%rsp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, 0x28(%rsp)
addq $0x8, %rdi
callq 0xd41b0
movq 0x28(%rsp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
movslq 0xe8(%rsp), %rax
subq %rax, %rsi
callq 0xdc980
movq (%rax), %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xf0(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x30(%rsp)
movq 0xf0(%rsp), %rdi
addq $0x8, %rdi
callq 0xd41b0
movq 0x30(%rsp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
movslq 0xe8(%rsp), %rax
subq %rax, %rsi
callq 0xdc980
movq %rax, %rcx
movq 0x38(%rsp), %rax
cmpq (%rcx), %rax
jne 0x128031
movq 0x58(%rsp), %rdi
addq $0x8, %rdi
movq %rdi, 0x18(%rsp)
callq 0xd9760
movq %rax, 0x80(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xd9e60
movq 0x18(%rsp), %rdi
movq 0x88(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0xdf450
movq %rax, 0x20(%rsp)
jmp 0x12800c
movq 0x20(%rsp), %rax
movq %rax, 0x78(%rsp)
jmp 0x128033
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
jmp 0x128179
jmp 0x12804b
jmp 0x128035
movl 0xe8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe8(%rsp)
jmp 0x127f0e
movl 0xe8(%rsp), %eax
cmpl 0xa0(%rsp), %eax
jge 0x128064
movq 0x58(%rsp), %rax
movb $0x1, 0x20(%rax)
jmp 0x12811e
movl $0x0, 0xe8(%rsp)
movl 0xe8(%rsp), %eax
cmpl 0xa4(%rsp), %eax
jge 0x128103
movq 0x68(%rsp), %rdi
addq $0x8, %rdi
movslq 0xe8(%rsp), %rsi
callq 0xdc980
movq (%rax), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xf0(%rsp), %rdi
addq $0x8, %rdi
movslq 0xe8(%rsp), %rsi
callq 0xdc980
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq (%rcx), %rax
jne 0x1280e9
movq 0x58(%rsp), %rdi
addq $0x8, %rdi
leaq 0x70(%rsp), %rsi
callq 0xdd590
jmp 0x1280e7
jmp 0x1280eb
jmp 0x128103
jmp 0x1280ed
movl 0xe8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe8(%rsp)
jmp 0x128074
movl 0xe8(%rsp), %eax
cmpl 0xa0(%rsp), %eax
jge 0x12811c
movq 0x58(%rsp), %rax
movb $0x1, 0x21(%rax)
jmp 0x12811e
movq 0x68(%rsp), %rax
movq (%rax), %rdi
movq 0xf0(%rsp), %rax
movq (%rax), %rsi
movq (%rdi), %rax
movq 0x30(%rax), %rax
xorl %edx, %edx
callq *%rax
movq %rax, 0x8(%rsp)
jmp 0x128143
movq 0x58(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movb $0x1, 0xef(%rsp)
testb $0x1, 0xef(%rsp)
jne 0x12816c
movq 0x58(%rsp), %rdi
callq 0xd2580
movq 0x60(%rsp), %rax
addq $0x108, %rsp            # imm = 0x108
retq
movq 0x58(%rsp), %rdi
callq 0xd2580
movq 0xb0(%rsp), %rdi
callq 0xe0be0