// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r14
movq %rsi, %r15
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rdi)
andw $0x0, 0x20(%rdi)
movups %xmm0, (%rdi)
movb 0x20(%rsi), %al
pushq $0x1
popq %rcx
testb %al, %al
movq %rdi, 0x10(%rsp)
jne 0x6783d
movb 0x20(%r14), %r8b
testb %r8b, %r8b
je 0x6785d
cmpb $0x0, 0x21(%r15)
jne 0x679a6
movb 0x21(%r14), %sil
testb %sil, %sil
jne 0x679a6
movb 0x20(%r14), %r8b
movb $0x1, %dl
jmp 0x6786c
testb $0x1, 0x21(%r15)
movzbl 0x21(%r14), %esi
cmovnel %ecx, %esi
xorl %edx, %edx
leaq 0x8(%rdi), %r12
movzbl %r8b, %r8d
testb %al, %al
cmovnel %ecx, %r8d
movb %r8b, 0x20(%rdi)
movb %sil, 0x21(%rdi)
movq 0x10(%r15), %rbp
subq 0x8(%r15), %rbp
shrq $0x3, %rbp
movq 0x10(%r14), %rax
subq 0x8(%r14), %rax
shrq $0x3, %rax
cmpl %ebp, %eax
movl %ebp, %ecx
cmovgl %eax, %ecx
movl %ecx, 0xc(%rsp)
movl %eax, %ecx
cmovgl %ebp, %ecx
xorl %ebx, %ebx
testl %ecx, %ecx
cmovlel %ebx, %ecx
movl %ecx, 0x8(%rsp)
testb %dl, %dl
je 0x67916
cmpl %ebp, %eax
cmovll %eax, %ebp
testl %ebp, %ebp
cmovlel %ebx, %ebp
movabsq $-0x100000000, %r13     # imm = 0xFFFFFFFF00000000
negq %rbp
cmpq %rbx, %rbp
je 0x67951
movq 0x10(%r15), %rax
movq %r13, %rcx
sarq $0x1d, %rcx
movq (%rax,%rcx), %rax
movq %rax, 0x18(%rsp)
movq 0x10(%r14), %rdx
cmpq (%rdx,%rcx), %rax
jne 0x6795d
movq (%r12), %rsi
movq %r12, %rdi
leaq 0x18(%rsp), %rdx
callq 0x51280
decq %rbx
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq %rax, %r13
jmp 0x678d0
cmpl %ebp, %eax
cmovll %eax, %ebp
testl %ebp, %ebp
cmovlel %ebx, %ebp
leaq 0x18(%rsp), %r13
cmpq %rbx, %rbp
je 0x67957
movq 0x8(%r15), %rax
movq (%rax,%rbx,8), %rax
movq %rax, 0x18(%rsp)
movq 0x8(%r14), %rcx
cmpq (%rcx,%rbx,8), %rax
jne 0x67972
movq %r12, %rdi
movq %r13, %rsi
callq 0x50ab0
incq %rbx
jmp 0x67925
movl 0x8(%rsp), %eax
jmp 0x67961
movl 0x8(%rsp), %eax
jmp 0x67974
negl %ebx
movl %ebx, %eax
cmpl 0xc(%rsp), %eax
movq 0x10(%rsp), %rbx
jge 0x67983
movb $0x1, 0x20(%rbx)
jmp 0x67983
movl %ebx, %eax
cmpl 0xc(%rsp), %eax
movq 0x10(%rsp), %rbx
jge 0x67983
movb $0x1, 0x21(%rbx)
movq (%r15), %rdi
movq (%r14), %rsi
movq (%rdi), %rax
xorl %edx, %edx
callq *0x30(%rax)
movq %rax, (%rbx)
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %r14
leaq 0x1fd49(%rip), %rsi     # 0x87701
leaq 0x18(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bl
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x4ddf0
xorl %ebx, %ebx
movq 0x474a9(%rip), %rsi     # 0xaee88
movq 0x47252(%rip), %rdx     # 0xaec38
movq %r14, %rdi
callq 0x51630
movq %rax, %r15
leaq 0x18(%rsp), %rdi
callq 0x4e020
testb %bl, %bl
jne 0x67a04
jmp 0x67a15
movq %rax, %r15
movq %r14, %rdi
callq 0x4ea60
jmp 0x67a15
jmp 0x67a12
jmp 0x67a12
movq %rax, %r15
movq 0x10(%rsp), %rdi
callq 0x4e060
movq %r15, %rdi
callq 0x518c0
nop