// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelScene.cpp
// Function: gaps::R3SurfelScene::RemoveLabel(gaps::R3SurfelLabel*)
void R3SurfelScene::
RemoveLabel(R3SurfelLabel *label)
{
  // Just checking
  assert(label);
  assert(label->scene == this);
  assert(label->scene_index >= 0);
  assert(labels.Kth(label->scene_index) == label);

  // Remove label properties from scene
  while (label->NLabelProperties() > 0) {
    R3SurfelLabelProperty *property = label->LabelProperty(label->NLabelProperties()-1);
    RemoveLabelProperty(property);
  }

  // Remove label relationships from scene
  while (label->NLabelRelationships() > 0) {
    R3SurfelLabelRelationship *relationship = label->LabelRelationship(label->NLabelRelationships()-1);
    RemoveLabelRelationship(relationship);
  }

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

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

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

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

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

  // Remove label from scene
  RNArrayEntry *entry = labels.KthEntry(label->scene_index);
  R3SurfelLabel *tail = labels.Tail();
  tail->scene_index = label->scene_index;
  labels.EntryContents(entry) = tail;
  labels.RemoveTail();
  label->scene_index = -1;
  label->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 0x1966b
movq 0x30(%r14), %rcx
movl %eax, %eax
movq -0x8(%rcx,%rax,8), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x58(%rax)
movl 0x3c(%r14), %eax
jmp 0x19639
movq 0x40(%r14), %rcx
movl %eax, %eax
movq -0x8(%rcx,%rax,8), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x78(%rax)
movl 0x4c(%r14), %eax
testl %eax, %eax
jg 0x19657
jmp 0x1968c
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 0x19675
movq 0x18(%r14), %r12
testq %r12, %r12
je 0x196c8
leaq 0x20(%r12), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xaafac
subq 0x20(%r12), %rax
shrq $0x3, %rax
movq %r15, %rdi
movl %eax, %esi
callq 0xab13e
movq $0x0, 0x18(%r14)
movslq 0x2c(%r14), %rax
testq %rax, %rax
jle 0x196eb
movq 0x20(%r14), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
movq $0x0, 0x18(%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x196d7
leaq 0x20(%r14), %rdi
xorl %esi, %esi
callq 0xab174
leaq 0x20(%rbx), %rdi
movslq 0x10(%r14), %rax
movq 0x20(%rbx), %rcx
movslq 0x2c(%rbx), %rdx
movq -0x8(%rcx,%rdx,8), %rsi
movl %eax, 0x10(%rsi)
movq %rsi, (%rcx,%rax,8)
leal -0x1(%rdx), %esi
callq 0xab13e
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
nop