// File: /workspace/github_cpp_makefile_star2_O1/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 0x5b1ac
cmpb $0x1, 0x20(%r15)
jne 0x5b1d8
cmpb $0x1, 0x21(%r14)
je 0x5b568
cmpb $0x1, 0x20(%r14)
jne 0x5b2ae
movb $0x1, 0x20(%rbx)
jmp 0x5b2c3
cmpq %rdi, %r10
jne 0x5b200
cmpb $0x0, 0x20(%r15)
jne 0x5b200
cmpb $0x0, 0x21(%r15)
jne 0x5b200
leaq 0x8(%rbx), %rdi
movq %rax, %rsi
callq 0x40f10
movb 0x20(%r14), %al
movb %al, 0x20(%rbx)
movb 0x21(%r14), %al
jmp 0x5b22f
movb 0x20(%r14), %bpl
cmpb $0x1, 0x21(%r15)
jne 0x5b239
testb %bpl, %bpl
jne 0x5b5c3
cmpb $0x1, 0x21(%r14)
jne 0x5b3f1
movb $0x1, 0x21(%rbx)
jmp 0x5b466
cmpq %r8, %r11
jne 0x5b186
cmpb $0x0, 0x20(%r14)
jne 0x5b186
cmpb $0x0, 0x21(%r14)
jne 0x5b186
leaq 0x8(%rbx), %rdi
callq 0x40f10
movb 0x20(%r15), %al
movb %al, 0x20(%rbx)
movb 0x21(%r15), %al
movb %al, 0x21(%rbx)
xorl %ebp, %ebp
jmp 0x5b4a1
testb %bpl, %bpl
je 0x5b376
movslq %r9d, %r14
cmpq %r14, %rdx
jne 0x5b6d4
cmpq %rdx, %rcx
jne 0x5b2c3
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x25412(%rip), %rsi     # 0x80682
leaq 0x25433(%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 0x47bf6(%rip), %rsi     # 0xa2e90
movq 0x47997(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
jmp 0x5b838
movslq %r9d, %r14
cmpq %r14, %rcx
jne 0x5b61e
cmpq %rdx, %rcx
je 0x5b679
testl %r9d, %r9d
jle 0x5b302
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 0x5b4b2
addq %r14, %r12
decq %r15
jne 0x5b2e5
movslq %r9d, %rdi
cmpq %rdx, %rcx
jbe 0x5b336
cmpq %rdi, %rcx
jbe 0x5b362
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 0x5b321
jmp 0x5b365
cmpq %rdi, %rdx
jbe 0x5b362
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 0x5b34d
jmp 0x5b365
xorl %r8d, %r8d
movl %r8d, %ebp
negl %ebp
cmpq %rdx, %rcx
cmovael %r8d, %ebp
jmp 0x5b48d
cmpb $0x1, 0x21(%r14)
jne 0x5b45d
movslq %r9d, %r10
cmpq %r10, %rdx
jne 0x5b78a
cmpq %rdx, %rcx
jne 0x5b466
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x252cf(%rip), %rsi     # 0x80682
leaq 0x252f0(%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 0x47ab3(%rip), %rsi     # 0xa2e90
movq 0x47854(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
jmp 0x5b838
movslq %r9d, %r10
cmpq %r10, %rcx
jne 0x5b72f
cmpq %rdx, %rcx
jne 0x5b466
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 0x41d60
jmp 0x5b838
cmpq %rcx, %rdx
jne 0x5b7e2
testl %r9d, %r9d
jle 0x5b48b
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
xorl %r10d, %r10d
movq (%rdi,%r10,8), %r11
cmpq (%r8,%r10,8), %r11
jne 0x5b50d
incq %r10
cmpq %r10, %r9
jne 0x5b475
xorl %ebp, %ebp
addq $0x8, %rbx
movq %rbx, %rdi
cmpq %rdx, %rcx
ja 0x5b49c
movq %rax, %rsi
callq 0x40f10
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 0x251f0(%rip), %rsi     # 0x806bf
leaq 0x25212(%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 0x47997(%rip), %rsi     # 0xa2e90
movq 0x47738(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
jmp 0x5b838
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x25195(%rip), %rsi     # 0x806bf
leaq 0x251b7(%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 0x4793c(%rip), %rsi     # 0xa2e90
movq 0x476dd(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
jmp 0x5b838
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x250d0(%rip), %rsi     # 0x80655
leaq 0x250dc(%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 0x478e1(%rip), %rsi     # 0xa2e90
movq 0x47682(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
jmp 0x5b838
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x250cb(%rip), %rsi     # 0x806ab
leaq 0x250d7(%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 0x47886(%rip), %rsi     # 0xa2e90
movq 0x47627(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
jmp 0x5b838
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2502e(%rip), %rsi     # 0x80669
leaq 0x2503f(%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 0x4782b(%rip), %rsi     # 0xa2e90
movq 0x475cc(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
jmp 0x5b838
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x24fec(%rip), %rsi     # 0x80682
leaq 0x2500d(%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 0x477d0(%rip), %rsi     # 0xa2e90
movq 0x47571(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
jmp 0x5b838
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x24f78(%rip), %rsi     # 0x80669
leaq 0x24f89(%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 0x47775(%rip), %rsi     # 0xa2e90
movq 0x47516(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
jmp 0x5b838
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x24f1d(%rip), %rsi     # 0x80669
leaq 0x24f2e(%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 0x4771a(%rip), %rsi     # 0xa2e90
movq 0x474bb(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
jmp 0x5b838
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x24ec2(%rip), %rsi     # 0x80669
leaq 0x24ed3(%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 0x476bf(%rip), %rsi     # 0xa2e90
movq 0x47460(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
jmp 0x5b838
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x24e6a(%rip), %rsi     # 0x80669
leaq 0x24e7b(%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 0x47667(%rip), %rsi     # 0xa2e90
movq 0x47408(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
jmp 0x5b868
jmp 0x5b884
jmp 0x5b868
jmp 0x5b884
jmp 0x5b868
jmp 0x5b884
jmp 0x5b868
jmp 0x5b884
jmp 0x5b868
jmp 0x5b884
jmp 0x5b868
jmp 0x5b884
jmp 0x5b868
jmp 0x5b884
jmp 0x5b868
jmp 0x5b884
jmp 0x5b868
jmp 0x5b884
jmp 0x5b868
jmp 0x5b884
jmp 0x5b868
jmp 0x5b884
jmp 0x5b868
jmp 0x5b884
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x5b88a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x40870
jmp 0x5b88a
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x5b897
movq %rbx, %rdi
callq 0x40080
movq %r14, %rdi
callq 0x41f00
nop