// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelScene.cpp
// Function: gaps::R3SurfelScene::RemoveObject(gaps::R3SurfelObject*)
void R3SurfelScene::
RemoveObject(R3SurfelObject *object)
{
  // Just checking
  assert(object);
  assert(object->scene == this);
  assert(object->scene_index >= 0);
  assert(objects.Kth(object->scene_index) == object);

  // Remove object propertys from scene
  while (object->NObjectProperties() > 0) {
    R3SurfelObjectProperty *property = object->ObjectProperty(object->NObjectProperties()-1);
    RemoveObjectProperty(property);
  }

  // Remove object relationships from scene
  while (object->NObjectRelationships() > 0) {
    R3SurfelObjectRelationship *relationship = object->ObjectRelationship(object->NObjectRelationships()-1);
    RemoveObjectRelationship(relationship);
  }

  // Remove label assignments
  while (object->NLabelAssignments() > 0) {
    R3SurfelLabelAssignment *assignment = object->LabelAssignment(object->NLabelAssignments()-1);
    RemoveLabelAssignment(assignment);
  }

  // Update object
  object->UpdateBeforeRemove(this);

  // Remove object from parent
  if (object->parent) {
    object->parent->parts.Remove(object);
    object->parent = NULL;
  }

  // Remove object from parts
  for (int i = 0; i < object->NParts(); i++) {
    R3SurfelObject *part = object->Part(i);
    part->parent = NULL;
  }

  // Remove parts from object
  object->parts.Empty();

  // Remove object from scene
  RNArrayEntry *entry = objects.KthEntry(object->scene_index);
  R3SurfelObject *tail = objects.Tail();
  tail->scene_index = object->scene_index;
  objects.EntryContents(entry) = tail;
  objects.RemoveTail();
  object->scene_index = -1;
  object->scene = NULL;

  // Mark scene as dirty
  flags.Add(R3_SURFEL_SCENE_DIRTY_FLAG);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movl 0x3c(%rsi), %eax
testl %eax, %eax
jle 0x193bb
movq 0x30(%r14), %rcx
movl %eax, %eax
movq -0x8(%rcx,%rax,8), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
movl 0x3c(%r14), %eax
jmp 0x19389
movq 0x40(%r14), %rcx
movl %eax, %eax
movq -0x8(%rcx,%rax,8), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x68(%rax)
movl 0x4c(%r14), %eax
testl %eax, %eax
jg 0x193a7
jmp 0x193dc
movq 0x50(%r14), %rcx
movl %eax, %eax
movq -0x8(%rcx,%rax,8), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x88(%rax)
movl 0x5c(%r14), %eax
testl %eax, %eax
jg 0x193c5
movq %r14, %rdi
movq %rbx, %rsi
callq 0x180f2
movq 0x18(%r14), %r12
testq %r12, %r12
je 0x19423
leaq 0x20(%r12), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xa9d20
subq 0x20(%r12), %rax
shrq $0x3, %rax
movq %r15, %rdi
movl %eax, %esi
callq 0xa9ec8
movq $0x0, 0x18(%r14)
movslq 0x2c(%r14), %rax
testq %rax, %rax
jle 0x19446
movq 0x20(%r14), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
movq $0x0, 0x18(%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x19432
leaq 0x20(%r14), %rdi
xorl %esi, %esi
callq 0xa9f08
leaq 0x10(%rbx), %rdi
movslq 0x10(%r14), %rax
movq 0x10(%rbx), %rcx
movslq 0x1c(%rbx), %rdx
movq -0x8(%rcx,%rdx,8), %rsi
movl %eax, 0x10(%rsi)
movq %rsi, (%rcx,%rax,8)
leal -0x1(%rdx), %esi
callq 0xa9ec8
movl $0xffffffff, 0x10(%r14) # imm = 0xFFFFFFFF
movq $0x0, 0x8(%r14)
orb $0x1, 0x1e8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq