// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelScene.cpp
// Function: gaps::R3SurfelScene::MergeObject(gaps::R3SurfelObject*, gaps::R3SurfelObject*)
void R3SurfelScene::
MergeObject(R3SurfelObject *dst_object, R3SurfelObject *src_object)
{
  // Just checking
  assert(dst_object && src_object);
  assert(dst_object->scene == this);
  assert(dst_object->scene_index >= 0);
  assert(src_object->scene == this);
  assert(src_object->scene_index >= 0);

  // Move all nodes from src_object into dst_object
  while (src_object->NNodes() > 0) {
    R3SurfelNode *node = src_object->Node(src_object->NNodes()-1);
    src_object->RemoveNode(node);
    dst_object->InsertNode(node);
  }

  // Move all parts from src_object into dst_object
  while (src_object->NParts() > 0) {
    R3SurfelObject *part = src_object->Part(src_object->NParts()-1);
    RemoveObject(part);
    InsertObject(part, dst_object);
  }

  // Move all object properties from src_object into dst_object
  while (src_object->NObjectProperties() > 0) {
    R3SurfelObjectProperty *property = src_object->ObjectProperty(src_object->NObjectProperties()-1);
    src_object->UpdateBeforeRemoveObjectProperty(property);
    property->object = dst_object;
    dst_object->UpdateAfterInsertObjectProperty(property);
  }

  // Move all object relationships from src_object into dst_object
  while (src_object->NObjectRelationships() > 0) {
    R3SurfelObjectRelationship *relationship = src_object->ObjectRelationship(src_object->NObjectRelationships()-1);
    src_object->UpdateBeforeRemoveObjectRelationship(relationship);
    for (int i = 0; i < relationship->objects.NEntries(); i++) {
      if (relationship->objects.Kth(i) == src_object) {
        RNArrayEntry *entry = relationship->objects.KthEntry(i);
        relationship->objects.EntryContents(entry) = dst_object;
        break;
      }
    }
    dst_object->UpdateAfterInsertObjectRelationship(relationship);
  }

  // Move all label assignments from src_object into dst_object
  while (src_object->NLabelAssignments() > 0) {
    R3SurfelLabelAssignment *assignment = src_object->LabelAssignment(src_object->NLabelAssignments()-1);
    src_object->UpdateBeforeRemoveLabelAssignment(assignment);
    assignment->object = dst_object;
    dst_object->UpdateAfterInsertLabelAssignment(assignment);
  }

  // Remove src_object
  RemoveObject(src_object);

  // Delete src_object
  delete src_object;

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

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movl 0x6c(%rdx), %eax
testl %eax, %eax
jle 0x193dd
movq 0x60(%r14), %rcx
movl %eax, %eax
movq -0x8(%rcx,%rax,8), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x16fc4
movq %r15, %rdi
movq %r12, %rsi
callq 0x17e86
movl 0x6c(%r14), %eax
jmp 0x1938c
movq 0x20(%r14), %rcx
movl %eax, %eax
movq -0x8(%rcx,%rax,8), %r12
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x20(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq *0x18(%rax)
movl 0x2c(%r14), %eax
testl %eax, %eax
jg 0x193b7
jmp 0x1940d
movq 0x30(%r14), %rcx
movl %eax, %eax
movq -0x8(%rcx,%rax,8), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x18234
movq %r15, 0x18(%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0x18228
movl 0x3c(%r14), %eax
testl %eax, %eax
jg 0x193e7
jmp 0x1945d
movq 0x40(%r14), %rcx
movl %eax, %eax
movq -0x8(%rcx,%rax,8), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x1826c
movslq 0x24(%r12), %rax
testq %rax, %rax
jle 0x19452
movq 0x18(%r12), %rcx
xorl %edx, %edx
cmpq %r14, (%rcx,%rdx,8)
je 0x1944e
incq %rdx
cmpq %rdx, %rax
jne 0x1943e
jmp 0x19452
movq %r15, (%rcx,%rdx,8)
movq %r15, %rdi
movq %r12, %rsi
callq 0x18260
movl 0x4c(%r14), %eax
testl %eax, %eax
jg 0x19417
jmp 0x1948d
movq 0x50(%r14), %rcx
movl %eax, %eax
movq -0x8(%rcx,%rax,8), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x182a8
movq %r15, 0x18(%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0x18298
movl 0x5c(%r14), %eax
testl %eax, %eax
jg 0x19467
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x20(%rax)
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
orb $0x1, 0x1e8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop