// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Utils/R3Segmentation.cpp
// Function: gaps::R3SegmentationCluster::InsertChild(gaps::R3SegmentationCluster*)
void R3SegmentationCluster::
InsertChild(R3SegmentationCluster *child)
{
  // Check
  assert(child != this);

  // Update area
  area += child->area;

  // Update color
  int n = points.NEntries() + child->points.NEntries();
  color *= points.NEntries();
  color += child->points.NEntries() * child->color;
  color = (n > 0) ? color / n : RNblack_rgb;

  // Update timestamp
  timestamp *= points.NEntries();
  timestamp += child->points.NEntries() * child->timestamp;
  timestamp = (n > 0) ? timestamp / n : 0;

  // Update primitive
  primitive.Update(this->primitive, child->primitive, this->points.NEntries(), child->points.NEntries());

  // Update category info
  if (points.NEntries() + child->points.NEntries() > 0) {
    if (category_identifier == child->category_identifier) {
      // Categories match -- average confidences
      category_confidence = (points.NEntries() * category_confidence + child->points.NEntries() * child->category_confidence);
      category_confidence /= points.NEntries() + child->points.NEntries();
    }
    else {
      // Categories don't match -- trust larger cluster
      if ((child->category_identifier < 0) || (points.NEntries() > child->points.NEntries())) {
        category_confidence = points.NEntries() * category_confidence;
        category_confidence /= points.NEntries() + child->points.NEntries();
      }
      else {
        category_identifier = child->category_identifier;
        category_confidence += child->points.NEntries() * child->category_confidence;
        category_confidence /= points.NEntries() + child->points.NEntries();
      }
    }
  }

  // Update affinities for current points
  if (points.NEntries() < 4 * child->points.NEntries()) {
    for (int i = 0; i < points.NEntries(); i++) {
      R3SegmentationPoint *point = points.Kth(i);
      RNScalar affinity = Affinity(point);
      if (affinity < 0) affinity = 0;
      possible_affinity += affinity - point->cluster_affinity;
      total_affinity += affinity - point->cluster_affinity;
      point->cluster_affinity = affinity;
    }
  }

  // Insert points from child
  while (!child->points.IsEmpty()) {
    R3SegmentationPoint *point = child->points.Tail();
    child->RemovePoint(point);
    RNScalar affinity = Affinity(point);
    if (affinity < 0) affinity = 0;
    possible_affinity += affinity;
    InsertPoint(point, affinity);
  }

  // Update child
  child->area = 0;
  child->color = RNblack_rgb;
  child->timestamp = 0;

  // Update hierarchy
  child->parent = this;
  children.Insert(child);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, %rbx
movq %rdi, %r14
movsd 0xe8(%rsi), %xmm0
addsd 0xe8(%rdi), %xmm0
movsd %xmm0, 0xe8(%rdi)
movl 0x14(%rdi), %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movl $0xf0, %eax
leaq (%rdi,%rax), %r12
movl 0x14(%rsi), %ebp
movq %r12, %rdi
callq 0xc4b00
cvtsi2sdl 0x14(%rbx), %xmm2
movsd 0xf0(%rbx), %xmm0
mulsd %xmm2, %xmm0
movsd 0xf8(%rbx), %xmm1
mulsd %xmm2, %xmm1
mulsd 0x100(%rbx), %xmm2
leaq 0x10(%rsp), %r13
movq %r13, %rdi
callq 0xc49c4
movq %r12, %rdi
movq %r13, %rsi
callq 0xc4a76
addl %r15d, %ebp
cvtsi2sd %ebp, %xmm3
movsd %xmm3, 0x8(%rsp)
jle 0x2b0c8
movsd 0xf0(%r14), %xmm0
movsd 0xf8(%r14), %xmm1
divsd %xmm3, %xmm0
divsd %xmm3, %xmm1
movsd 0x100(%r14), %xmm2
divsd %xmm3, %xmm2
leaq 0x10(%rsp), %rdi
callq 0xc49c4
jmp 0x2b0d9
leaq 0x548891(%rip), %rsi    # 0x573960
leaq 0x10(%rsp), %rdi
callq 0xc49a6
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0xc4a56
xorps %xmm1, %xmm1
cvtsi2sdl 0x14(%r14), %xmm1
mulsd 0x108(%r14), %xmm1
movsd %xmm1, 0x108(%r14)
testl %ebp, %ebp
jg 0x2b10b
xorpd %xmm0, %xmm0
jmp 0x2b125
xorps %xmm0, %xmm0
cvtsi2sdl 0x14(%rbx), %xmm0
mulsd 0x108(%rbx), %xmm0
addsd %xmm1, %xmm0
divsd 0x8(%rsp), %xmm0
movl $0xf0, %r13d
movsd %xmm0, 0x108(%r14)
leaq 0x40(%r14), %r12
leaq 0xd0(%rsp), %rdi
movq %r12, %rsi
callq 0x2923e
leaq 0x40(%rbx), %rsi
leaq 0x28(%rsp), %rdi
callq 0x2923e
xorps %xmm0, %xmm0
cvtsi2sdl 0x14(%r14), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x14(%rbx), %xmm1
leaq 0xd0(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %r12, %rdi
callq 0x29a5e
leaq 0x30(%rsp), %rdi
callq 0x89530
leaq 0xd8(%rsp), %rdi
callq 0x89530
movl 0x14(%r14), %eax
movl 0x14(%rbx), %ecx
movl %ecx, %edx
addl %eax, %edx
jle 0x2b23e
movl 0x110(%rbx), %esi
cmpl %esi, 0x110(%r14)
jne 0x2b1df
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd 0x118(%rbx), %xmm1
leaq 0x118(%r14), %rsi
mulsd 0x118(%r14), %xmm0
addsd %xmm1, %xmm0
jmp 0x2b22f
testl %esi, %esi
setns %dil
cmpl %ecx, %eax
setle %r8b
testb %dil, %r8b
jne 0x2b209
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
leaq 0x118(%r14), %rsi
mulsd 0x118(%r14), %xmm0
jmp 0x2b22f
movl %esi, 0x110(%r14)
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
leaq 0x118(%r14), %rsi
mulsd 0x118(%rbx), %xmm0
addsd 0x118(%r14), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%rsi)
shll $0x2, %ecx
cmpl %ecx, %eax
jge 0x2b2a8
cmpl $0x0, 0x14(%r14)
jle 0x2b2a8
xorl %r15d, %r15d
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x2a6b4
xorpd %xmm1, %xmm1
maxsd %xmm0, %xmm1
movapd %xmm1, %xmm0
subsd 0xc8(%r12), %xmm0
movupd 0x120(%r14), %xmm2
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
addpd %xmm2, %xmm0
movupd %xmm0, 0x120(%r14)
movsd %xmm1, 0xc8(%r12)
incq %r15
movslq 0x14(%r14), %rax
cmpq %rax, %r15
jl 0x2b24f
addq %rbx, %r13
movl 0x14(%rbx), %eax
testl %eax, %eax
je 0x2b302
movq 0x8(%rbx), %rcx
cltq
movq -0x8(%rcx,%rax,8), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2a52e
movq %r14, %rdi
movq %r12, %rsi
callq 0x2a6b4
xorpd %xmm1, %xmm1
maxsd %xmm0, %xmm1
movsd 0x120(%r14), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x120(%r14)
movq %r14, %rdi
movq %r12, %rsi
movapd %xmm1, %xmm0
callq 0x2aa70
jmp 0x2b2ab
xorl %r15d, %r15d
movq %r15, 0xe8(%rbx)
leaq 0x54864d(%rip), %rsi    # 0x573960
movq %r13, %rdi
callq 0xc4a56
movq %r15, 0x108(%rbx)
movq %r14, 0x18(%rbx)
movl 0x2c(%r14), %edx
addq $0x20, %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xc4be6
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x89530
jmp 0x2b35d
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x89530
movq %rbx, %rdi
callq 0x15ae0