// File: /workspace/github_cpp_makefile_star2_O3/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 %rsi, %r15
movq %rdi, %rbx
movw $0x0, 0x20(%rdi)
addq $0x8, %rsi
movq 0x8(%r15), %rdi
movq 0x10(%r15), %r10
movq %r10, %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, %r9
cmovbq %rcx, %r9
testl %r9d, %r9d
je 0x5af33
movb 0x20(%r15), %bpl
testb $0x1, %bpl
je 0x5af61
cmpb $0x1, 0x21(%r14)
je 0x5b2f1
cmpb $0x1, 0x20(%r14)
jne 0x5b037
movb $0x1, 0x20(%rbx)
jmp 0x5b04c
movb 0x20(%r15), %bpl
cmpq %rdi, %r10
jne 0x5af89
testb %bpl, %bpl
jne 0x5af89
cmpb $0x0, 0x21(%r15)
jne 0x5af89
leaq 0x8(%rbx), %rdi
movq %rax, %rsi
callq 0x40f20
movb 0x20(%r14), %al
movb %al, 0x20(%rbx)
movb 0x21(%r14), %al
jmp 0x5afb8
movb 0x20(%r14), %bpl
cmpb $0x1, 0x21(%r15)
jne 0x5afc2
testb %bpl, %bpl
jne 0x5b34c
cmpb $0x1, 0x21(%r14)
jne 0x5b17a
movb $0x1, 0x21(%rbx)
jmp 0x5b1ef
cmpq %r8, %r11
jne 0x5af0e
cmpb $0x0, 0x20(%r14)
jne 0x5af0e
cmpb $0x0, 0x21(%r14)
jne 0x5af0e
leaq 0x8(%rbx), %rdi
callq 0x40f20
movb 0x20(%r15), %al
movb %al, 0x20(%rbx)
movb 0x21(%r15), %al
movb %al, 0x21(%rbx)
xorl %ebp, %ebp
jmp 0x5b22a
testb %bpl, %bpl
je 0x5b0ff
movslq %r9d, %r14
cmpq %r14, %rdx
jne 0x5b45d
cmpq %rdx, %rcx
jne 0x5b04c
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x25689(%rip), %rsi     # 0x80682
leaq 0x256aa(%rip), %rdx     # 0x806aa
leaq 0x8(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x47e6d(%rip), %rsi     # 0xa2e90
movq 0x47c0e(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x5b5c1
movslq %r9d, %r14
cmpq %r14, %rcx
jne 0x5b3a7
cmpq %rdx, %rcx
je 0x5b402
testl %r9d, %r9d
jle 0x5b08b
movabsq $-0x100000000, %r14     # imm = 0xFFFFFFFF00000000
addq %r12, %rdi
addq %r13, %r8
movl %r9d, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movq %r14, %r12
movq %r12, %r13
sarq $0x1d, %r13
movq (%rdi,%r13), %rbp
cmpq (%r8,%r13), %rbp
jne 0x5b23b
addq %r14, %r12
decq %r15
jne 0x5b06e
movslq %r9d, %rdi
cmpq %rdx, %rcx
jbe 0x5b0bf
cmpq %rdi, %rcx
jbe 0x5b0eb
leaq (,%rdi,8), %r8
subq %r8, %r10
addq $-0x8, %r10
xorl %r8d, %r8d
movq (%r10), %r9
addl 0x20(%r9), %r8d
incq %rdi
addq $-0x8, %r10
cmpq %rdi, %rcx
ja 0x5b0aa
jmp 0x5b0ee
cmpq %rdi, %rdx
jbe 0x5b0eb
leaq (,%rdi,8), %r8
subq %r8, %r11
addq $-0x8, %r11
xorl %r8d, %r8d
movq (%r11), %r9
addl 0x20(%r9), %r8d
incq %rdi
addq $-0x8, %r11
cmpq %rdi, %rdx
ja 0x5b0d6
jmp 0x5b0ee
xorl %r8d, %r8d
movl %r8d, %ebp
negl %ebp
cmpq %rdx, %rcx
cmovael %r8d, %ebp
jmp 0x5b216
cmpb $0x1, 0x21(%r14)
jne 0x5b1e6
movslq %r9d, %r10
cmpq %r10, %rdx
jne 0x5b513
cmpq %rdx, %rcx
jne 0x5b1ef
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x25546(%rip), %rsi     # 0x80682
leaq 0x25567(%rip), %rdx     # 0x806aa
leaq 0x8(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x47d2a(%rip), %rsi     # 0xa2e90
movq 0x47acb(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x5b5c1
movslq %r9d, %r10
cmpq %r10, %rcx
jne 0x5b4b8
cmpq %rdx, %rcx
jne 0x5b1ef
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x254da(%rip), %rsi     # 0x80682
leaq 0x254fb(%rip), %rdx     # 0x806aa
leaq 0x8(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x47cbe(%rip), %rsi     # 0xa2e90
movq 0x47a5f(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x5b5c1
cmpq %rcx, %rdx
jne 0x5b56b
testl %r9d, %r9d
jle 0x5b214
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
xorl %r10d, %r10d
movq (%rdi,%r10,8), %r11
cmpq (%r8,%r10,8), %r11
jne 0x5b296
incq %r10
cmpq %r10, %r9
jne 0x5b1fe
xorl %ebp, %ebp
addq $0x8, %rbx
movq %rbx, %rdi
cmpq %rdx, %rcx
ja 0x5b225
movq %rax, %rsi
callq 0x40f20
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x25467(%rip), %rsi     # 0x806bf
leaq 0x25489(%rip), %rdx     # 0x806e8
leaq 0x8(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x47c0e(%rip), %rsi     # 0xa2e90
movq 0x479af(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x5b5c1
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2540c(%rip), %rsi     # 0x806bf
leaq 0x2542e(%rip), %rdx     # 0x806e8
leaq 0x8(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x47bb3(%rip), %rsi     # 0xa2e90
movq 0x47954(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x5b5c1
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x25347(%rip), %rsi     # 0x80655
leaq 0x25353(%rip), %rdx     # 0x80668
leaq 0x8(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x47b58(%rip), %rsi     # 0xa2e90
movq 0x478f9(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x5b5c1
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x25342(%rip), %rsi     # 0x806ab
leaq 0x2534e(%rip), %rdx     # 0x806be
leaq 0x8(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x47afd(%rip), %rsi     # 0xa2e90
movq 0x4789e(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x5b5c1
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x252a5(%rip), %rsi     # 0x80669
leaq 0x252b6(%rip), %rdx     # 0x80681
leaq 0x8(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x47aa2(%rip), %rsi     # 0xa2e90
movq 0x47843(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x5b5c1
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x25263(%rip), %rsi     # 0x80682
leaq 0x25284(%rip), %rdx     # 0x806aa
leaq 0x8(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x47a47(%rip), %rsi     # 0xa2e90
movq 0x477e8(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x5b5c1
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x251ef(%rip), %rsi     # 0x80669
leaq 0x25200(%rip), %rdx     # 0x80681
leaq 0x8(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x479ec(%rip), %rsi     # 0xa2e90
movq 0x4778d(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x5b5c1
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x25194(%rip), %rsi     # 0x80669
leaq 0x251a5(%rip), %rdx     # 0x80681
leaq 0x8(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x47991(%rip), %rsi     # 0xa2e90
movq 0x47732(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x5b5c1
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x25139(%rip), %rsi     # 0x80669
leaq 0x2514a(%rip), %rdx     # 0x80681
leaq 0x8(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x47936(%rip), %rsi     # 0xa2e90
movq 0x476d7(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x5b5c1
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x250e1(%rip), %rsi     # 0x80669
leaq 0x250f2(%rip), %rdx     # 0x80681
leaq 0x8(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x478de(%rip), %rsi     # 0xa2e90
movq 0x4767f(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x5b5f1
jmp 0x5b612
jmp 0x5b5f1
jmp 0x5b612
jmp 0x5b5f1
jmp 0x5b612
jmp 0x5b5f1
jmp 0x5b612
jmp 0x5b5f1
jmp 0x5b612
jmp 0x5b5f1
jmp 0x5b612
jmp 0x5b5f1
jmp 0x5b612
jmp 0x5b5f1
jmp 0x5b612
jmp 0x5b5f1
jmp 0x5b612
jmp 0x5b5f1
jmp 0x5b612
jmp 0x5b5f1
jmp 0x5b612
jmp 0x5b5f1
jmp 0x5b612
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x5b60b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x40880
testb %bpl, %bpl
jne 0x5b615
jmp 0x5b61d
movq %rax, %r14
movq %rbx, %rdi
callq 0x40090
movq %r14, %rdi
callq 0x41f10
nop