// File: /workspace/github_cpp_makefile_star2_O2/jstaursky[P]hutch/src/Sleigh/slghpatexpress.cc
// Function: TokenPattern::resolveTokens(TokenPattern const&, TokenPattern const&)
int4 TokenPattern::resolveTokens(const TokenPattern &tok1,const TokenPattern &tok2)

{				// Use the token lists to decide how the two patterns
				// should be aligned relative to each other
				// return how much -tok2- needs to be shifted
				// and set the resulting tokenlist and ellipses
  bool reversedirection = false;
  leftellipsis = false;
  rightellipsis = false;
  int4 ressa = 0;
  int4 minsize = tok1.toklist.size() < tok2.toklist.size() ? tok1.toklist.size() : tok2.toklist.size();
  if (minsize == 0) {
				// Check if pattern doesn't care about tokens
    if ((tok1.toklist.size()==0)&&(tok1.leftellipsis==false)&&(tok1.rightellipsis==false)) {
      toklist = tok2.toklist;
      leftellipsis = tok2.leftellipsis;
      rightellipsis = tok2.rightellipsis;
      return 0;
    }
    else if ((tok2.toklist.size()==0)&&(tok2.leftellipsis==false)&&(tok2.rightellipsis==false)) {
      toklist = tok1.toklist;
      leftellipsis = tok1.leftellipsis;
      rightellipsis = tok1.rightellipsis;
      return 0;
    }
				// If one of the ellipses is true then the pattern
				// still cares about tokens even though none are
				// specified
  }
  
  if (tok1.leftellipsis) {
    reversedirection = true;
    if (tok2.rightellipsis)
      throw SleighError("Right/left ellipsis");
    else if (tok2.leftellipsis)
      leftellipsis = true;
    else if (tok1.toklist.size() != minsize)
      throw SleighError("Mismatched pattern sizes");
    else if (tok1.toklist.size()==tok2.toklist.size())
      throw SleighError("Pattern size cannot vary (missing ... ?)");
  }
  else if (tok1.rightellipsis) {
    if (tok2.leftellipsis)
      throw SleighError("Left/right ellipsis");
    else if (tok2.rightellipsis)
      rightellipsis = true;
    else if (tok1.toklist.size() != minsize)
      throw SleighError("Mismatched pattern sizes");
    else if (tok1.toklist.size()==tok2.toklist.size())
      throw SleighError("Pattern size cannot vary (missing ... ?)");
  }
  else {
    if (tok2.leftellipsis) {
      reversedirection = true;
      if (tok2.toklist.size() != minsize)
	throw SleighError("Mismatched pattern sizes");
      else if (tok1.toklist.size()==tok2.toklist.size())
	throw SleighError("Pattern size cannot vary (missing ... ?)");
    }
    else if (tok2.rightellipsis) {
      if (tok2.toklist.size() != minsize)
	throw SleighError("Mismatched pattern sizes");
      else if (tok1.toklist.size()==tok2.toklist.size())
	throw SleighError("Pattern size cannot vary (missing ... ?)");
    }
    else {
      if (tok2.toklist.size() != tok1.toklist.size())
	throw SleighError("Mismatched pattern sizes");
    }
  }
  if (reversedirection) {
    for(int4 i=0;i<minsize;++i)
      if (tok1.toklist[tok1.toklist.size()-1-i] != tok2.toklist[tok2.toklist.size()-1-i])
	throw SleighError("Mismatched tokens when combining patterns");
    if (tok1.toklist.size() <= tok2.toklist.size())
      for(int4 i=minsize;i<tok2.toklist.size();++i)
	ressa += tok2.toklist[tok2.toklist.size()-1-i]->getSize();
    else
      for(int4 i=minsize;i<tok1.toklist.size();++i)
	ressa += tok1.toklist[tok1.toklist.size()-1-i]->getSize();
    if (tok1.toklist.size() < tok2.toklist.size())
      ressa = -ressa;
  }
  else {
    for(int4 i=0;i<minsize;++i)
      if (tok1.toklist[i] != tok2.toklist[i])
	throw SleighError("Mismatched tokens when combining patterns");
  }
				// Save the results into -this-
  if (tok1.toklist.size() <= tok2.toklist.size())
    toklist = tok2.toklist;
  else
    toklist = tok1.toklist;
  return ressa;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rdi, %rbx
andw $0x0, 0x20(%rdi)
movq %rsi, %r15
addq $0x8, %rsi
movq 0x8(%r15), %rdi
movq 0x10(%r15), %r9
movq %r9, %r12
subq %rdi, %r12
movq %r12, %rcx
sarq $0x3, %rcx
leaq 0x8(%rdx), %rax
movq 0x8(%rdx), %r8
movq 0x10(%rdx), %r11
movq %r11, %r13
subq %r8, %r13
movq %r13, %rdx
sarq $0x3, %rdx
cmpq %rdx, %rcx
movq %rdx, %r10
cmovbq %rcx, %r10
testl %r10d, %r10d
je 0x669ba
movb 0x20(%r15), %bpl
testb $0x1, %bpl
je 0x669e8
cmpb $0x1, 0x21(%r14)
je 0x66d21
cmpb $0x1, 0x20(%r14)
jne 0x66ab2
movb $0x1, 0x20(%rbx)
jmp 0x66ac7
movb 0x20(%r15), %bpl
cmpq %rdi, %r9
jne 0x66a10
testb %bpl, %bpl
jne 0x66a10
cmpb $0x0, 0x21(%r15)
jne 0x66a10
leaq 0x8(%rbx), %rdi
movq %rax, %rsi
callq 0x50190
movb 0x20(%r14), %al
movb %al, 0x20(%rbx)
movb 0x21(%r14), %al
jmp 0x66a3f
movb 0x20(%r14), %bpl
cmpb $0x1, 0x21(%r15)
jne 0x66a4a
testb %bpl, %bpl
jne 0x66d6f
cmpb $0x1, 0x21(%r14)
jne 0x66c3e
movb $0x1, 0x21(%rbx)
jmp 0x66ca6
cmpq %r8, %r11
jne 0x66995
cmpb $0x0, 0x20(%r14)
jne 0x66995
cmpb $0x0, 0x21(%r14)
jne 0x66995
leaq 0x8(%rbx), %rdi
callq 0x50190
movb 0x20(%r15), %al
movb %al, 0x20(%rbx)
movb 0x21(%r15), %al
movb %al, 0x21(%rbx)
xorl %r14d, %r14d
jmp 0x66bbe
testb %bpl, %bpl
je 0x66bd0
movslq %r10d, %r14
cmpq %r14, %rdx
jne 0x66e59
cmpq %rdx, %rcx
jne 0x66ac7
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x20bec(%rip), %rsi     # 0x87662
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x483ea(%rip), %rsi     # 0xaee88
movq 0x48193(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
jmp 0x66f89
movslq %r10d, %r14
cmpq %r14, %rcx
jne 0x66dbd
cmpq %rdx, %rcx
je 0x66e0b
movabsq $-0x100000000, %r14     # imm = 0xFFFFFFFF00000000
addq %r12, %rdi
addq %r13, %r8
xorl %r15d, %r15d
testl %r10d, %r10d
cmovgl %r10d, %r15d
incq %r15
movq %r14, %r12
decq %r15
je 0x66b4f
leaq (%r12,%r14), %r13
sarq $0x1d, %r12
movq (%rdi,%r12), %rbp
cmpq (%r8,%r12), %rbp
movq %r13, %r12
je 0x66ae7
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x20b8c(%rip), %rsi     # 0x8769f
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x4834d(%rip), %rsi     # 0xaee88
movq 0x480f6(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
jmp 0x66f89
movslq %r10d, %rdi
leaq (,%rdi,8), %r8
cmpq %rdx, %rcx
jbe 0x66b7e
subq %r8, %r9
addq $-0x8, %r9
xorl %r8d, %r8d
cmpq %rdi, %rcx
jbe 0x66b9d
movq (%r9), %r10
addl 0x20(%r10), %r8d
incq %rdi
addq $-0x8, %r9
jmp 0x66b69
subq %r8, %r11
addq $-0x8, %r11
xorl %r8d, %r8d
cmpq %rdi, %rdx
jbe 0x66b9d
movq (%r11), %r9
addl 0x20(%r9), %r8d
incq %rdi
addq $-0x8, %r11
jmp 0x66b88
movl %r8d, %r14d
negl %r14d
cmpq %rdx, %rcx
cmovael %r8d, %r14d
addq $0x8, %rbx
movq %rbx, %rdi
cmpq %rdx, %rcx
ja 0x66bb9
movq %rax, %rsi
callq 0x50190
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x1, 0x21(%r14)
jne 0x66c9d
movslq %r10d, %r9
cmpq %r9, %rdx
jne 0x66ef5
cmpq %rdx, %rcx
jne 0x66ca6
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x20a60(%rip), %rsi     # 0x87662
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x4825e(%rip), %rsi     # 0xaee88
movq 0x48007(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
jmp 0x66f89
movslq %r10d, %r9
cmpq %r9, %rcx
jne 0x66ea7
cmpq %rdx, %rcx
jne 0x66ca6
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x20a01(%rip), %rsi     # 0x87662
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x481ff(%rip), %rsi     # 0xaee88
movq 0x47fa8(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
jmp 0x66f89
cmpq %rcx, %rdx
jne 0x66f40
xorl %r14d, %r14d
testl %r10d, %r10d
movl $0x0, %r9d
cmovgl %r10d, %r9d
xorl %r10d, %r10d
cmpq %r10, %r9
je 0x66baa
movq (%rdi,%r10,8), %r11
leaq 0x1(%r10), %r15
cmpq (%r8,%r10,8), %r11
movq %r15, %r10
je 0x66cb9
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x209ba(%rip), %rsi     # 0x8769f
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x4817b(%rip), %rsi     # 0xaee88
movq 0x47f24(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
jmp 0x66f89
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x20902(%rip), %rsi     # 0x87635
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x4812d(%rip), %rsi     # 0xaee88
movq 0x47ed6(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
jmp 0x66f89
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x2090a(%rip), %rsi     # 0x8768b
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x480df(%rip), %rsi     # 0xaee88
movq 0x47e88(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
jmp 0x66f89
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x2087a(%rip), %rsi     # 0x87649
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x48091(%rip), %rsi     # 0xaee88
movq 0x47e3a(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
jmp 0x66f89
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x20845(%rip), %rsi     # 0x87662
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x48043(%rip), %rsi     # 0xaee88
movq 0x47dec(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
jmp 0x66f89
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x207de(%rip), %rsi     # 0x87649
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x47ff5(%rip), %rsi     # 0xaee88
movq 0x47d9e(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
jmp 0x66f89
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x20790(%rip), %rsi     # 0x87649
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x47fa7(%rip), %rsi     # 0xaee88
movq 0x47d50(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
jmp 0x66f89
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x20742(%rip), %rsi     # 0x87649
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x47f59(%rip), %rsi     # 0xaee88
movq 0x47d02(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
jmp 0x66f89
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x206f7(%rip), %rsi     # 0x87649
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x47f0e(%rip), %rsi     # 0xaee88
movq 0x47cb7(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
jmp 0x66fb9
jmp 0x66fcd
jmp 0x66fb9
jmp 0x66fcd
jmp 0x66fb9
jmp 0x66fcd
jmp 0x66fb9
jmp 0x66fcd
jmp 0x66fb9
jmp 0x66fcd
jmp 0x66fb9
jmp 0x66fcd
jmp 0x66fb9
jmp 0x66fcd
jmp 0x66fb9
jmp 0x66fcd
jmp 0x66fb9
jmp 0x66fcd
jmp 0x66fb9
jmp 0x66fcd
jmp 0x66fb9
jmp 0x66fcd
jmp 0x66fb9
jmp 0x66fcd
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x4e020
testb %bpl, %bpl
jne 0x66fd0
jmp 0x66fd8
movq %rax, %r14
movq %rbx, %rdi
callq 0x4ea60
movq %r14, %rdi
callq 0x518c0