// File: /workspace/github_cpp_makefile_star2_O1/jstaursky[P]hutch/src/Sleigh/slghsymbol.cc
// Function: SymbolTable::purge()
void SymbolTable::purge(void)

{				// Get rid of unsavable symbols and scopes
  SleighSymbol *sym;
  for(int4 i=0;i<symbollist.size();++i) {
    sym = symbollist[i];
    if (sym == (SleighSymbol *)0) continue;
    if (sym->scopeid != 0) { // Not in global scope
      if (sym->getType() == SleighSymbol::operand_symbol) continue;
    }
    else {
      switch(sym->getType()) {
      case SleighSymbol::space_symbol:
      case SleighSymbol::token_symbol:
      case SleighSymbol::epsilon_symbol:
      case SleighSymbol::section_symbol:
	break;
      case SleighSymbol::macro_symbol:
	{			// Delete macro's local symbols
	  MacroSymbol *macro = (MacroSymbol *)sym;
	  for(int4 i=0;i<macro->getNumOperands();++i) {
	    SleighSymbol *opersym = macro->getOperand(i);
	    table[opersym->scopeid]->removeSymbol(opersym);
	    symbollist[opersym->id] = (SleighSymbol *)0;
	    delete opersym;
	  }
	  break;
	}
      case SleighSymbol::subtable_symbol:
	{			// Delete unused subtables
	  SubtableSymbol *subsym = (SubtableSymbol *)sym;
	  if (subsym->getPattern() != (TokenPattern *)0) continue;
	  for(int4 i=0;i<subsym->getNumConstructors();++i) { // Go thru each constructor
	    Constructor *con = subsym->getConstructor(i);
	    for(int4 j=0;j<con->getNumOperands();++j) { // Go thru each operand
	      OperandSymbol *oper = con->getOperand(j);
	      table[oper->scopeid]->removeSymbol(oper);
	      symbollist[oper->id] = (SleighSymbol *)0;
	      delete oper;
	    }
	  }
	  break;		// Remove the subtable symbol itself
	}
      default:
	continue;
      }
    }
    table[sym->scopeid]->removeSymbol(sym); // Remove the symbol
    symbollist[i] = (SleighSymbol *)0;
    delete sym;
  }
  for(int4 i=1;i<table.size();++i) { // Remove any empty scopes
    if (table[i]->tree.empty()) {
      delete table[i];
      table[i] = (SymbolScope *)0;
    }
  }
  renumber();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq (%rdi), %rax
cmpq %rax, 0x8(%rdi)
je 0x65db0
xorl %ebp, %ebp
leaq 0x1b371(%rip), %r15     # 0x80ef4
movq (%rax,%rbp,8), %r13
testq %r13, %r13
je 0x65d96
movl 0x2c(%r13), %r14d
movq (%r13), %rax
movq %r13, %rdi
callq *0x10(%rax)
testl %r14d, %r14d
je 0x65bb1
cmpl $0x8, %eax
jne 0x65d54
jmp 0x65d96
leal -0xb(%rax), %ecx
cmpl $0x5, %ecx
ja 0x65cc0
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
movq %r13, 0x10(%rsp)
jmpq *%rax
movq 0x30(%r13), %rax
testq %rax, %rax
jne 0x65d96
movq %rax, 0x18(%rsp)
movq 0x40(%r13), %rax
movq 0x48(%r13), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
testl %ecx, %ecx
jle 0x65ca8
xorl %edx, %edx
movq %rdx, 0x20(%rsp)
movq (%rax,%rdx,8), %r14
movq 0x18(%r14), %rax
movq 0x20(%r14), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
testl %ecx, %ecx
jle 0x65c80
xorl %r15d, %r15d
movq (%rax,%r15,8), %r12
movl 0x2c(%r12), %eax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %r13
movq %r12, 0x8(%rsp)
addq $0x8, %r13
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3f970
movq %r13, %rdi
movq %rax, %rsi
callq 0x3fb50
movl 0x28(%r12), %eax
movq (%rbx), %rcx
movq $0x0, (%rcx,%rax,8)
testq %r12, %r12
je 0x65c66
movq (%r12), %rax
movq %r12, %rdi
callq *0x8(%rax)
incq %r15
movq 0x18(%r14), %rax
movq 0x20(%r14), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r15
jl 0x65c15
movq 0x20(%rsp), %rdx
incq %rdx
movq 0x10(%rsp), %r13
movq 0x40(%r13), %rax
movq 0x48(%r13), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rdx
jl 0x65bf6
cmpq $0x0, 0x18(%rsp)
leaq 0x1b23f(%rip), %r15     # 0x80ef4
jne 0x65d96
jmp 0x65d54
cmpl $0x2, %eax
jb 0x65d54
jmp 0x65d96
movq 0x40(%r13), %rax
movq 0x48(%r13), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
testl %ecx, %ecx
jle 0x65d54
xorl %r14d, %r14d
movq (%rax,%r14,8), %r12
movl 0x2c(%r12), %eax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %r13
movq %r12, 0x8(%rsp)
addq $0x8, %r13
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3f970
movq %r13, %rdi
movq %rax, %rsi
callq 0x3fb50
movl 0x28(%r12), %eax
movq (%rbx), %rcx
movq $0x0, (%rcx,%rax,8)
testq %r12, %r12
je 0x65d35
movq (%r12), %rax
movq %r12, %rdi
callq *0x8(%rax)
incq %r14
movq 0x10(%rsp), %r13
movq 0x40(%r13), %rax
movq 0x48(%r13), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r14
jl 0x65ce4
movl 0x2c(%r13), %eax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %r12
movq %r13, 0x8(%rsp)
addq $0x8, %r12
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3f970
movq %r12, %rdi
movq %rax, %rsi
callq 0x3fb50
movq (%rbx), %rax
movq $0x0, (%rax,%rbp,8)
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
incq %rbp
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbp, %rcx
ja 0x65b83
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
cmpq $0x9, %rcx
jb 0x65e10
movl $0x1, %r15d
movq (%rax,%r15,8), %r14
cmpq $0x0, 0x30(%r14)
jne 0x65df9
testq %r14, %r14
je 0x65ded
leaq 0x8(%r14), %rdi
callq 0x40780
movl $0x40, %esi
movq %r14, %rdi
callq 0x40870
movq 0x18(%rbx), %rax
movq $0x0, (%rax,%r15,8)
incq %r15
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x65dc7
movq %rbx, %rdi
callq 0x41240
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop