// File: /workspace/github_cpp_makefile_star2_O1/jstaursky[P]hutch/src/Sleigh/slghsymbol.cc
// Function: DecisionNode::orderPatterns(DecisionProperties&)
void DecisionNode::orderPatterns(DecisionProperties &props)

{
  // This is a tricky routine.  When this routine is called, the patterns remaining in the
  // the decision node can no longer be distinguished by examining additional bits. The basic
  // idea here is that the patterns should be ordered so that the most specialized should come
  // first in the list. Pattern 1 is a specialization of pattern 2, if the set of instructions
  // matching 1 is contained in the set matching 2.  So in the simplest case, the pattern order
  // should represent a strict nesting.  Unfortunately, there are many potential situations where
  // patterns don't necessarily nest.
  //   1) An "or" of two patterns.  This can be an explicit '|' operator in the Constructor, in
  //      which case this can be detected because the two patterns point to the same constructor
  //      But the "or" can be implied across two constructors that do the same thing.  This should
  //      probably be flagged as an error except in the following case.
  //   2) Two patterns aren't properly nested, but they are "resolved" by a third pattern which
  //      covers the intersection of the first two patterns.  Sometimes its easier to specify
  //      three cases that need to be distinguished in this way.
  //   3) Recursive constructors that use a "guard" context bit.  The guard bit is used to prevent
  //      the recursive constructor from matching repeatedly, but it's too much work to put a
  //      constraint an the bit for every other pattern.
  //   4) Other situations where the ability to distinguish between constructors is hidden in
  //      the subconstructors.
  // This routine can determine if an intersection results from case 1) or case 2)
  int4 i,j,k;
  vector<pair<DisjointPattern *,Constructor *> > newlist;
  vector<pair<DisjointPattern *,Constructor *> > conflictlist;

  // Check for identical patterns
  for(i=0;i<list.size();++i) {
    for(j=0;j<i;++j) {
      DisjointPattern *ipat = list[i].first;
      DisjointPattern *jpat = list[j].first;
      if (ipat->identical(jpat))
	props.identicalPattern(list[i].second,list[j].second);
    }
  }

  newlist = list;
  for(i=0;i<list.size();++i) {
    for(j=0;j<i;++j) {
      DisjointPattern *ipat = newlist[i].first;
      DisjointPattern *jpat = list[j].first;
      if (ipat->specializes(jpat))
	break;
      if (!jpat->specializes(ipat)) { // We have a potential conflict
	Constructor *iconst = newlist[i].second;
	Constructor *jconst = list[j].second;
	if (iconst == jconst) { // This is an OR in the pattern for ONE constructor
	  // So there is no conflict
	}
	else {			// A true conflict that needs to be resolved
	  conflictlist.push_back(pair<DisjointPattern *,Constructor *>(ipat,iconst));
	  conflictlist.push_back(pair<DisjointPattern *,Constructor *>(jpat,jconst));
	}
      }
    }
    for(k=i-1;k>=j;--k)
      list[k+1] = list[k];
    list[j] = newlist[i];
  }
  
  // Check if intersection patterns are present, which resolve conflicts
  for(i=0;i<conflictlist.size();i+=2) {
    DisjointPattern *pat1,*pat2;
    Constructor *const1,*const2;
    pat1 = conflictlist[i].first;
    const1 = conflictlist[i].second;
    pat2 = conflictlist[i+1].first;
    const2 = conflictlist[i+1].second;
    bool resolved = false;
    for(j=0;j<list.size();++j) {
      DisjointPattern *tpat = list[j].first;
      Constructor *tconst = list[j].second;
      if ((tpat == pat1)&&(tconst==const1)) break; // Ran out of possible specializations
      if ((tpat == pat2)&&(tconst==const2)) break;
      if (tpat->resolvesIntersect(pat1,pat2)) {
	resolved = true;
	break;
      }
    }
    if (!resolved)
      props.conflictingPattern(const1,const2);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, 0x60(%rsp)
movq %rdi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
xorl %eax, %eax
movq %rax, 0x50(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x8(%rdi), %rax
cmpq (%rdi), %rax
je 0x6ceff
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x6ceec
movq %rbx, %r15
shlq $0x4, %r15
movq %rbx, %r12
xorl %r13d, %r13d
movq (%r14), %rax
movq (%rax,%r15), %rdi
movq (%rax,%r13), %rsi
callq 0x3f9a0
testb %al, %al
je 0x6cee3
movq (%r14), %rax
movq 0x8(%rax,%r15), %rsi
movq 0x8(%rax,%r13), %rdx
movq 0x60(%rsp), %rdi
callq 0x42290
addq $0x10, %r13
decq %r12
jne 0x6ceb8
incq %rbx
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x4, %rax
cmpq %rbx, %rax
ja 0x6cea6
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x40360
movq 0x8(%r14), %rax
cmpq (%r14), %rax
je 0x6d095
movq $0x0, 0x58(%rsp)
xorl %edi, %edi
movq %rdi, %rcx
movl $0x0, %ebx
testq %rdi, %rdi
je 0x6d032
movq %rcx, (%rsp)
shlq $0x4, %rcx
movq %rcx, 0x8(%rsp)
xorl %r12d, %r12d
xorl %ebx, %ebx
movq 0x40(%rsp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx), %r15
movq (%r14), %rax
movq (%rax,%r12), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x40fa0
movl %eax, %ebp
testb %al, %al
jne 0x6d02e
movq %r13, %rdi
movq %r15, %rsi
callq 0x40fa0
testb %al, %al
jne 0x6d014
movq 0x40(%rsp), %rax
movq 0x8(%rsp), %rcx
movq 0x8(%rax,%rcx), %rax
movq (%r14), %rcx
movq 0x8(%rcx,%r12), %rcx
movq %rcx, 0x28(%rsp)
cmpq %rcx, %rax
je 0x6d014
movq %r15, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x6cfcb
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x18(%rsp)
jmp 0x6cfda
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x41650
movq %r13, 0x30(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x6d005
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x18(%rsp)
jmp 0x6d014
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x41650
testb %bpl, %bpl
jne 0x6d02e
incq %rbx
addq $0x10, %r12
cmpq %rbx, (%rsp)
jne 0x6cf47
movq (%rsp), %rbx
movq (%rsp), %rcx
movl %ebx, %eax
movq %rcx, %rdi
cmpq %rax, %rcx
jbe 0x6d05d
movslq %ebx, %rcx
movq (%r14), %rdx
addq 0x58(%rsp), %rdx
movq %rdi, %rsi
decq %rsi
movups -0x10(%rdx), %xmm0
movups %xmm0, (%rdx)
addq $-0x10, %rdx
cmpq %rcx, %rsi
jg 0x6d04a
movq 0x40(%rsp), %rcx
movq %rdi, %rdx
shlq $0x4, %rdx
movq (%r14), %rsi
shlq $0x4, %rax
movups (%rcx,%rdx), %xmm0
movups %xmm0, (%rsi,%rax)
movq 0x8(%r14), %rax
subq (%r14), %rax
incq %rdi
sarq $0x4, %rax
addq $0x10, 0x58(%rsp)
cmpq %rdi, %rax
ja 0x6cf24
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x6d181
xorl %ebx, %ebx
movq %rbx, %rcx
shlq $0x4, %rcx
movq 0x8(%rdi,%rcx), %rax
movq %rax, 0x8(%rsp)
movq 0x18(%rdi,%rcx), %rax
movq %rax, (%rsp)
movq (%r14), %rax
cmpq %rax, 0x8(%r14)
je 0x6d150
movq %rbx, 0x28(%rsp)
movq (%rdi,%rcx), %r13
movq 0x10(%rdi,%rcx), %rbp
movl $0x8, %r12d
xorl %ebx, %ebx
xorl %r15d, %r15d
movq -0x8(%rax,%r12), %rdi
movq (%rax,%r12), %rax
cmpq %r13, %rdi
jne 0x6d0fc
cmpq 0x8(%rsp), %rax
je 0x6d107
cmpq %rbp, %rdi
jne 0x6d10b
cmpq (%rsp), %rax
jne 0x6d10b
xorl %eax, %eax
jmp 0x6d127
movq %r13, %rsi
movq %rbp, %rdx
callq 0x3f920
movzbl %r15b, %r15d
testb %al, %al
movl $0x1, %ecx
cmovnel %ecx, %r15d
xorb $0x1, %al
testb %al, %al
je 0x6d145
incq %rbx
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
addq $0x10, %r12
cmpq %rbx, %rcx
ja 0x6d0e7
testb $0x1, %r15b
movq 0x28(%rsp), %rbx
jne 0x6d163
movq 0x60(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq (%rsp), %rdx
callq 0x41cb0
addq $0x2, %rbx
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
subq %rdi, %rax
sarq $0x4, %rax
cmpq %rbx, %rax
ja 0x6d0a7
testq %rdi, %rdi
je 0x6d193
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x40870
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x6d1aa
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x40870
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6d1c5
jmp 0x6d1c5
jmp 0x6d1c5
jmp 0x6d1c5
jmp 0x6d1c5
jmp 0x6d1c5
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x6d1df
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x40870
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x6d1f6
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x40870
movq %rbx, %rdi
callq 0x41f00