// File: jstaursky[P]hutch/src/Sleigh/slgh_compile.cc
// Function: ConsistencyChecker::setPostOrder(SubtableSymbol*)
void ConsistencyChecker::setPostOrder(SubtableSymbol *root)

{
  postorder.clear();
  sizemap.clear();

  // Establish post-order of SubtableSymbols so that we can
  // recursively fill in sizes of varnodes which are exported
  // from constructors

  vector<SubtableSymbol *> path;
  vector<int4> state;
  vector<int4> ctstate;

  sizemap[root] = -1;		// Mark root as traversed
  path.push_back(root);
  state.push_back(0);
  ctstate.push_back(0);

  while(!path.empty()) {
    SubtableSymbol *cur = path.back();
    int4 ctind = state.back();
    if (ctind >= cur->getNumConstructors()) {
      path.pop_back(); 		// Table is fully traversed
      state.pop_back();
      ctstate.pop_back();
      postorder.push_back(cur);	// Post the traversed table
    }
    else {
      Constructor *ct = cur->getConstructor(ctind);
      int4 oper = ctstate.back();
      if (oper >= ct->getNumOperands()) {
	state.back() = ctind + 1; // Constructor fully traversed
	ctstate.back() = 0;
      }
      else {
	ctstate.back() = oper + 1;
	OperandSymbol *opsym = ct->getOperand(oper);
	SubtableSymbol *subsym = dynamic_cast<SubtableSymbol *>(opsym->getDefiningSymbol());
	if (subsym != (SubtableSymbol *)0) {
	  map<SubtableSymbol *,int4>::const_iterator iter;
	  iter = sizemap.find(subsym);
	  if (iter == sizemap.end()) { // Not traversed yet
	    sizemap[subsym] = -1; // Mark table as traversed
	    path.push_back(subsym); // Recurse
	    state.push_back(0);
	    ctstate.push_back(0);
	  }
	}
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
addq $0x18, %rdi
callq 0x6a7b0
movq -0xe8(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0xe0(%rbp)
callq 0x6a7d0
leaq -0x28(%rbp), %rdi
callq 0x6a4d0
leaq -0x40(%rbp), %rdi
callq 0x6a7f0
leaq -0x58(%rbp), %rdi
callq 0x6a7f0
movq -0xe0(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x6a6d0
movq %rax, -0xd8(%rbp)
jmp 0x5ea72
movq -0xd8(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq -0x28(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x6a810
jmp 0x5ea8e
movl $0x0, -0x68(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x6a880
jmp 0x5eaa4
movl $0x0, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x6c(%rbp), %rsi
callq 0x6a880
jmp 0x5eaba
jmp 0x5eabc
leaq -0x28(%rbp), %rdi
callq 0x6a8b0
xorb $-0x1, %al
testb $0x1, %al
jne 0x5ead0
jmp 0x5ede9
leaq -0x28(%rbp), %rdi
callq 0x6a8f0
movq (%rax), %rax
movq %rax, -0x78(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x6a930
movl (%rax), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0xf0(%rbp)
movq -0x78(%rbp), %rdi
callq 0x6a660
movl %eax, -0xec(%rbp)
jmp 0x5eb08
movl -0xf0(%rbp), %eax
movl -0xec(%rbp), %ecx
cmpl %ecx, %eax
jl 0x5eb7a
leaq -0x28(%rbp), %rdi
callq 0x6a970
leaq -0x40(%rbp), %rdi
callq 0x6a9a0
leaq -0x58(%rbp), %rdi
callq 0x6a9a0
movq -0xe8(%rbp), %rdi
addq $0x18, %rdi
leaq -0x78(%rbp), %rsi
callq 0x6a810
jmp 0x5eb49
jmp 0x5ede4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x6a9d0
leaq -0x40(%rbp), %rdi
callq 0x6a9d0
leaq -0x28(%rbp), %rdi
callq 0x6aa30
jmp 0x5ee0d
movq -0x78(%rbp), %rdi
movl -0x7c(%rbp), %esi
callq 0x6a680
movq %rax, -0xf8(%rbp)
jmp 0x5eb8f
movq -0xf8(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x6a930
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x100(%rbp)
movq -0x88(%rbp), %rdi
callq 0x52760
movl %eax, -0xfc(%rbp)
jmp 0x5ebce
movl -0x100(%rbp), %eax
movl -0xfc(%rbp), %ecx
cmpl %ecx, %eax
jl 0x5ec0f
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x6a930
movl -0x104(%rbp), %ecx
movl %ecx, (%rax)
leaq -0x58(%rbp), %rdi
callq 0x6a930
movl $0x0, (%rax)
jmp 0x5ede2
movl -0x8c(%rbp), %eax
incl %eax
movl %eax, -0x114(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x6a930
movl -0x114(%rbp), %ecx
movl %ecx, (%rax)
movq -0x88(%rbp), %rdi
movl -0x8c(%rbp), %esi
callq 0x179c0
movq %rax, -0x110(%rbp)
jmp 0x5ec49
movq -0x110(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
callq 0x52780
movq %rax, -0x120(%rbp)
jmp 0x5ec6c
movq -0x120(%rbp), %rax
cmpq $0x0, %rax
je 0x5eca0
movq -0x120(%rbp), %rdi
leaq 0xd0ba1(%rip), %rsi     # 0x12f828
leaq 0xd29fa(%rip), %rdx     # 0x131688
xorl %eax, %eax
movl %eax, %ecx
callq 0x11530
movq %rax, -0x128(%rbp)
jmp 0x5ecab
xorl %eax, %eax
movq %rax, -0x128(%rbp)
jmp 0x5ecab
movq -0x128(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
je 0x5ede0
leaq -0xa8(%rbp), %rdi
callq 0x6a510
movq -0xe8(%rbp), %rdi
addq $0x30, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x6a530
movq %rax, -0x130(%rbp)
jmp 0x5ecf3
movq -0x130(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x6a560
movq -0xe8(%rbp), %rdi
movq -0xb0(%rbp), %rax
movq %rax, -0xa8(%rbp)
addq $0x30, %rdi
callq 0x6a5b0
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x6a560
leaq -0xa8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x6a580
testb $0x1, %al
jne 0x5ed65
jmp 0x5edde
movq -0xe8(%rbp), %rdi
addq $0x30, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x6a6d0
movq %rax, -0x138(%rbp)
jmp 0x5ed85
movq -0x138(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq -0x28(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x6a810
jmp 0x5eda4
movl $0x0, -0xcc(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0xcc(%rbp), %rsi
callq 0x6a880
jmp 0x5edc0
movl $0x0, -0xd0(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x6a880
jmp 0x5eddc
jmp 0x5edde
jmp 0x5ede0
jmp 0x5ede2
jmp 0x5ede4
jmp 0x5eabc
leaq -0x58(%rbp), %rdi
callq 0x6a9d0
leaq -0x40(%rbp), %rdi
callq 0x6a9d0
leaq -0x28(%rbp), %rdi
callq 0x6aa30
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x118b0
nopw %cs:(%rax,%rax)