// File: jstaursky[P]hutch/src/Sleigh/slghsymbol.cc
// Function: Constructor::orderOperands()
void Constructor::orderOperands(void)

{
  OperandSymbol *sym;
  vector<OperandSymbol *> patternorder;
  vector<OperandSymbol *> newops; // New order of the operands
  int4 lastsize;

  pateq->operandOrder(this,patternorder);
  for(int4 i=0;i<operands.size();++i) { // Make sure patternorder contains all operands
    sym = operands[i];
    if (!sym->isMarked()) {
      patternorder.push_back(sym);
      sym->setMark();		// Make sure all operands are marked
    }
  }
  do {
    lastsize = newops.size();
    for(int4 i=0;i<patternorder.size();++i) {
      sym = patternorder[i];
      if (!sym->isMarked()) continue; // "unmarked" means it is already in newops
      if (sym->isOffsetIrrelevant()) continue; // expression Operands come last
      if ((sym->offsetbase == -1)||(!operands[sym->offsetbase]->isMarked())) {
	newops.push_back(sym);
	sym->clearMark();
      }
    }
  } while(newops.size() != lastsize);
  for(int4 i=0;i<patternorder.size();++i) { // Tack on expression Operands
    sym = patternorder[i];
    if (sym->isOffsetIrrelevant()) {
      newops.push_back(sym);
      sym->clearMark();
    }
  }

  if (newops.size() != operands.size())
    throw SleighError("Circular offset dependency between operands");


  for(int4 i=0;i<newops.size();++i) { // Fix up operand indices
    newops[i]->hand = i;
    newops[i]->localexp->changeIndex(i);
  }
  vector<int4> handmap;		// Create index translation map
  for(int4 i=0;i<operands.size();++i)
    handmap.push_back(operands[i]->hand);

				// Fix up offsetbase
  for(int4 i=0;i<newops.size();++i) {
    sym = newops[i];
    if (sym->offsetbase == -1) continue;
    sym->offsetbase = handmap[sym->offsetbase];
  }

  if (templ != (ConstructTpl *)0) // Fix up templates
    templ->changeHandleIndex(handmap);
  for(int4 i=0;i<namedtempl.size();++i) {
    ConstructTpl *ntempl = namedtempl[i];
    if (ntempl != (ConstructTpl *)0)
      ntempl->changeHandleIndex(handmap);
  }

				// Fix up printpiece operand refs
  for(int4 i=0;i<printpiece.size();++i) {
    if (printpiece[i][0] == '\n') {
      int4 index = printpiece[i][1]-'A';
      index = handmap[index];
      printpiece[i][1] = 'A'+index;
    }
  }
  operands = newops;
}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movq %rdi, 0x170(%rsp)
movq 0x170(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0x150(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0xdc5e0
leaq 0x138(%rsp), %rdi
callq 0xdc5e0
movq 0xa8(%rsp), %rsi
movq 0xb0(%rsp), %rdx
movq 0x10(%rsi), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
jmp 0x147800
movl $0x0, 0x120(%rsp)
movq 0xa8(%rsp), %rdi
movslq 0x120(%rsp), %rax
movq %rax, 0xa0(%rsp)
addq $0x18, %rdi
callq 0xd98e0
movq %rax, %rcx
movq 0xa0(%rsp), %rax
cmpq %rcx, %rax
jae 0x1478e0
movq 0xa8(%rsp), %rdi
addq $0x18, %rdi
movslq 0x120(%rsp), %rsi
callq 0xdc620
movq (%rax), %rax
movq %rax, 0x168(%rsp)
movq 0x168(%rsp), %rdi
callq 0xdfb00
movb %al, 0x9f(%rsp)
jmp 0x14787a
movb 0x9f(%rsp), %al
testb $0x1, %al
jne 0x1478c8
jmp 0x147887
leaq 0x150(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0xdd2e0
jmp 0x14789e
movq 0x168(%rsp), %rdi
callq 0xd2620
jmp 0x1478ad
jmp 0x1478c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0x148030
jmp 0x1478ca
movl 0x120(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x120(%rsp)
jmp 0x14780b
jmp 0x1478e2
leaq 0x138(%rsp), %rdi
callq 0xd98e0
movl %eax, 0x134(%rsp)
movl $0x0, 0x11c(%rsp)
movslq 0x11c(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x150(%rsp), %rdi
callq 0xd98e0
movq %rax, %rcx
movq 0x90(%rsp), %rax
cmpq %rcx, %rax
jae 0x147a28
movslq 0x11c(%rsp), %rsi
leaq 0x150(%rsp), %rdi
callq 0xdc620
movq (%rax), %rax
movq %rax, 0x168(%rsp)
movq 0x168(%rsp), %rdi
callq 0xdfb00
movb %al, 0x8f(%rsp)
jmp 0x147968
movb 0x8f(%rsp), %al
testb $0x1, %al
jne 0x14797a
jmp 0x147975
jmp 0x147a12
movq 0x168(%rsp), %rdi
callq 0xd8370
movb %al, 0x8e(%rsp)
jmp 0x147990
movb 0x8e(%rsp), %al
testb $0x1, %al
jne 0x14799d
jmp 0x14799f
jmp 0x147a12
movq 0x168(%rsp), %rax
cmpl $-0x1, 0x34(%rax)
je 0x1479e8
movq 0xa8(%rsp), %rdi
addq $0x18, %rdi
movq 0x168(%rsp), %rax
movslq 0x34(%rax), %rsi
callq 0xdc620
movq (%rax), %rdi
callq 0xdfb00
movb %al, 0x8d(%rsp)
jmp 0x1479db
movb 0x8d(%rsp), %al
testb $0x1, %al
jne 0x147a10
jmp 0x1479e8
leaq 0x138(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0xdd2e0
jmp 0x1479ff
movq 0x168(%rsp), %rdi
callq 0xd50e0
jmp 0x147a0e
jmp 0x147a10
jmp 0x147a12
movl 0x11c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x11c(%rsp)
jmp 0x147901
jmp 0x147a2a
leaq 0x138(%rsp), %rdi
callq 0xd98e0
movslq 0x134(%rsp), %rcx
cmpq %rcx, %rax
jne 0x1478e2
movl $0x0, 0x118(%rsp)
movslq 0x118(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x150(%rsp), %rdi
callq 0xd98e0
movq %rax, %rcx
movq 0x80(%rsp), %rax
cmpq %rcx, %rax
jae 0x147afd
movslq 0x118(%rsp), %rsi
leaq 0x150(%rsp), %rdi
callq 0xdc620
movq (%rax), %rax
movq %rax, 0x168(%rsp)
movq 0x168(%rsp), %rdi
callq 0xd8370
movb %al, 0x7f(%rsp)
jmp 0x147ab3
movb 0x7f(%rsp), %al
testb $0x1, %al
jne 0x147abd
jmp 0x147ae5
leaq 0x138(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0xdd2e0
jmp 0x147ad4
movq 0x168(%rsp), %rdi
callq 0xd50e0
jmp 0x147ae3
jmp 0x147ae5
jmp 0x147ae7
movl 0x118(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x118(%rsp)
jmp 0x147a53
leaq 0x138(%rsp), %rdi
callq 0xd98e0
movq 0xa8(%rsp), %rdi
movq %rax, 0x70(%rsp)
addq $0x18, %rdi
callq 0xd98e0
movq %rax, %rcx
movq 0x70(%rsp), %rax
cmpq %rcx, %rax
je 0x147c0d
movb $0x1, 0xf6(%rsp)
movl $0x20, %edi
callq 0xd2b40
movq %rax, 0x60(%rsp)
leaq 0xf7(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0xe0c80
movq 0x68(%rsp), %rdx
leaq 0x41885(%rip), %rsi     # 0x1893eb
leaq 0xf8(%rsp), %rdi
callq 0xe00a0
jmp 0x147b75
movq 0x60(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0xd06e0
jmp 0x147b89
movq 0x60(%rsp), %rdi
movb $0x0, 0xf6(%rsp)
movq 0x802cb(%rip), %rsi     # 0x1c7e68
movq 0x7fe7c(%rip), %rdx     # 0x1c7a20
callq 0xe01f0
jmp 0x148057
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0x147be5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0xd4550
leaq 0xf7(%rsp), %rdi
callq 0xd8ec0
testb $0x1, 0xf6(%rsp)
jne 0x147bfe
jmp 0x147c08
movq 0x60(%rsp), %rdi
callq 0xd5400
jmp 0x148030
movl $0x0, 0xf0(%rsp)
movslq 0xf0(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x138(%rsp), %rdi
callq 0xd98e0
movq %rax, %rcx
movq 0x58(%rsp), %rax
cmpq %rcx, %rax
jae 0x147ca8
movslq 0xf0(%rsp), %rsi
movl %esi, %eax
movl %eax, 0x4c(%rsp)
leaq 0x138(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0xdc620
movl 0x4c(%rsp), %ecx
movq 0x50(%rsp), %rdi
movq (%rax), %rax
movl %ecx, 0x3c(%rax)
movslq 0xf0(%rsp), %rsi
callq 0xdc620
movq (%rax), %rax
movq 0x40(%rax), %rdi
movl 0xf0(%rsp), %esi
callq 0xd4ba0
jmp 0x147c90
jmp 0x147c92
movl 0xf0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf0(%rsp)
jmp 0x147c18
leaq 0xd8(%rsp), %rdi
callq 0xdd980
movl $0x0, 0xd4(%rsp)
movq 0xa8(%rsp), %rdi
movslq 0xd4(%rsp), %rax
movq %rax, 0x40(%rsp)
addq $0x18, %rdi
callq 0xd98e0
movq %rax, %rcx
movq 0x40(%rsp), %rax
cmpq %rcx, %rax
jae 0x147d55
movq 0xa8(%rsp), %rdi
addq $0x18, %rdi
movslq 0xd4(%rsp), %rsi
callq 0xdc620
movq (%rax), %rsi
addq $0x3c, %rsi
leaq 0xd8(%rsp), %rdi
callq 0xcf4c0
jmp 0x147d1a
jmp 0x147d1c
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x147cc0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0xd5e90
jmp 0x148030
movl $0x0, 0xd0(%rsp)
movslq 0xd0(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x138(%rsp), %rdi
callq 0xd98e0
movq %rax, %rcx
movq 0x38(%rsp), %rax
cmpq %rcx, %rax
jae 0x147df3
movslq 0xd0(%rsp), %rsi
leaq 0x138(%rsp), %rdi
callq 0xdc620
movq (%rax), %rax
movq %rax, 0x168(%rsp)
movq 0x168(%rsp), %rax
cmpl $-0x1, 0x34(%rax)
jne 0x147db7
jmp 0x147ddd
movq 0x168(%rsp), %rax
movslq 0x34(%rax), %rsi
leaq 0xd8(%rsp), %rdi
callq 0xd2680
movl (%rax), %ecx
movq 0x168(%rsp), %rax
movl %ecx, 0x34(%rax)
movl 0xd0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd0(%rsp)
jmp 0x147d60
movq 0xa8(%rsp), %rax
cmpq $0x0, 0x60(%rax)
je 0x147e1f
movq 0xa8(%rsp), %rax
movq 0x60(%rax), %rdi
leaq 0xd8(%rsp), %rsi
callq 0xdbe40
jmp 0x147e1d
jmp 0x147e1f
movl $0x0, 0xcc(%rsp)
movq 0xa8(%rsp), %rdi
movslq 0xcc(%rsp), %rax
movq %rax, 0x30(%rsp)
addq $0x68, %rdi
callq 0xd33b0
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0x147eb5
movq 0xa8(%rsp), %rdi
addq $0x68, %rdi
movslq 0xcc(%rsp), %rsi
callq 0xd9460
movq (%rax), %rax
movq %rax, 0xc0(%rsp)
cmpq $0x0, 0xc0(%rsp)
je 0x147e9d
movq 0xc0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0xdbe40
jmp 0x147e9b
jmp 0x147e9d
jmp 0x147e9f
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x147e2a
movl $0x0, 0xbc(%rsp)
movq 0xa8(%rsp), %rdi
movslq 0xbc(%rsp), %rax
movq %rax, 0x28(%rsp)
addq $0x30, %rdi
callq 0xe1670
movq %rax, %rcx
movq 0x28(%rsp), %rax
cmpq %rcx, %rax
jae 0x147fe6
movq 0xa8(%rsp), %rdi
addq $0x30, %rdi
movslq 0xbc(%rsp), %rsi
callq 0xe1770
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xe2f50
movq %rax, 0x20(%rsp)
jmp 0x147f1b
movq 0x20(%rsp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x147fce
movq 0xa8(%rsp), %rdi
addq $0x30, %rdi
movslq 0xbc(%rsp), %rsi
callq 0xe1770
movq %rax, %rdi
movl $0x1, %esi
callq 0xe2f50
movq %rax, 0x18(%rsp)
jmp 0x147f59
movq 0x18(%rsp), %rax
movsbl (%rax), %eax
addl $-0x41, %eax
movl %eax, 0xb8(%rsp)
movslq 0xb8(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
callq 0xd2680
movq 0xa8(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0xb8(%rsp)
movb 0xb8(%rsp), %al
addb $0x41, %al
movb %al, 0xf(%rsp)
addq $0x30, %rdi
movslq 0xbc(%rsp), %rsi
callq 0xe1770
movq %rax, %rdi
movl $0x1, %esi
callq 0xe2f50
movq %rax, 0x10(%rsp)
jmp 0x147fc3
movq 0x10(%rsp), %rax
movb 0xf(%rsp), %cl
movb %cl, (%rax)
jmp 0x147fd0
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x147ec0
movq 0xa8(%rsp), %rdi
addq $0x18, %rdi
leaq 0x138(%rsp), %rsi
callq 0xd6830
jmp 0x148001
leaq 0xd8(%rsp), %rdi
callq 0xd5e90
leaq 0x138(%rsp), %rdi
callq 0xcf440
leaq 0x150(%rsp), %rdi
callq 0xcf440
addq $0x178, %rsp            # imm = 0x178
retq
leaq 0x138(%rsp), %rdi
callq 0xcf440
leaq 0x150(%rsp), %rdi
callq 0xcf440
movq 0x128(%rsp), %rdi
callq 0xe0be0
nopw (%rax,%rax)