// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3MeshSearchTree.cpp
// Function: gaps::R3MeshSearchTree::Empty(gaps::R3MeshSearchTreeNode*)
void R3MeshSearchTree::
Empty(R3MeshSearchTreeNode *node)
{
  // Delete children
  if (node->children[0]) {
    Empty(node->children[0]);
    delete node->children[0];
    node->children[0] = NULL;
  }
  if (node->children[1]) {
    Empty(node->children[1]);
    delete node->children[1];
    node->children[1] = NULL;
  }

  // Delete small face containers
  for (int i = 0; i < node->small_faces.NEntries(); i++) {
    R3MeshSearchTreeFace *face = node->small_faces[i];
    assert(face->reference_count > 0);
    if (--(face->reference_count) == 0) delete face;
  }

  // Delete big face containers
  for (int i = 0; i < node->big_faces.NEntries(); i++) {
    R3MeshSearchTreeFace *face = node->big_faces[i];
    assert(face->reference_count > 0);
    if (--(face->reference_count) == 0) delete face;
  }

  // Empty face containers
  node->small_faces.Empty();
  node->big_faces.Empty();
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x58(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1c0c1
movq 0x30(%rsp), %rdi
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0x1c050
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
je 0x1c0b4
movq 0x28(%rsp), %rdi
callq 0x21880
movq 0x28(%rsp), %rdi
movl $0x48, %esi
callq 0xf4d0
movq 0x58(%rsp), %rax
movq $0x0, 0x8(%rax)
movq 0x58(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x1c11a
movq 0x30(%rsp), %rdi
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x1c050
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, %rax
je 0x1c10d
movq 0x20(%rsp), %rdi
callq 0x21880
movq 0x20(%rsp), %rdi
movl $0x48, %esi
callq 0xf4d0
movq 0x58(%rsp), %rax
movq $0x0, 0x10(%rax)
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x58(%rsp), %rdi
addq $0x38, %rdi
callq 0x178e0
movl %eax, %ecx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
jge 0x1c19f
movq 0x58(%rsp), %rdi
addq $0x38, %rdi
movl 0x54(%rsp), %esi
callq 0x21860
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rcx
movl 0x10(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x10(%rcx)
cmpl $0x0, %eax
jne 0x1c190
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x1c18e
movq 0x10(%rsp), %rdi
movl $0x18, %esi
callq 0xf4d0
jmp 0x1c190
jmp 0x1c192
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x1c122
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x58(%rsp), %rdi
addq $0x28, %rdi
callq 0x178e0
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jge 0x1c222
movq 0x58(%rsp), %rdi
addq $0x28, %rdi
movl 0x44(%rsp), %esi
callq 0x21860
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rcx
movl 0x10(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x10(%rcx)
cmpl $0x0, %eax
jne 0x1c213
movq 0x38(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x1c211
movq (%rsp), %rdi
movl $0x18, %esi
callq 0xf4d0
jmp 0x1c213
jmp 0x1c215
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x1c1a7
movq 0x58(%rsp), %rdi
addq $0x38, %rdi
xorl %esi, %esi
callq 0xdef50
movq 0x58(%rsp), %rdi
addq $0x28, %rdi
xorl %esi, %esi
callq 0xdef50
addq $0x68, %rsp
retq
nopw (%rax,%rax)