// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelNode.cpp
// Function: gaps::R3SurfelNode::SetParent(gaps::R3SurfelNode*)
void R3SurfelNode::
SetParent(R3SurfelNode *parent)
{
  // Just checking
  assert(parent);
  assert(this->parent);
  assert(tree);
  assert(tree == this->parent->tree);
  assert(tree == parent->tree);
  if (parent == this->parent) return;

  // Find least common ancestor
  R3SurfelNode *least_common_ancestor = NULL;

  // Invalidate properties starting at current parent
  R3SurfelNode *ancestor = this->parent;
  while (ancestor && (ancestor != least_common_ancestor)) {
    if (ancestor->complexity == -1) break;
    ancestor->complexity = -1;
    ancestor->bbox[0][0] = FLT_MAX;
    ancestor->timestamp_range[0] = FLT_MAX;
    ancestor = ancestor->parent;
  }

  // Invalidate properties starting at new parent
  ancestor = parent;
  while (ancestor && (ancestor != least_common_ancestor)) {
    if (ancestor->complexity == -1) break;
    ancestor->complexity = -1;
    ancestor->bbox[0][0] = FLT_MAX;
    ancestor->timestamp_range[0] = FLT_MAX;
    ancestor = ancestor->parent;
  }

  // Update hierarchy
  this->parent->parts.Remove(this);
  parent->parts.Insert(this);
  this->parent = parent;

  // Mark scene as dirty
  if (Tree() && Tree()->Scene()) Tree()->Scene()->SetDirty();
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq 0x30(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x28(%rcx), %rax
jne 0x5f778
jmp 0x5f96d
movq 0x10(%rsp), %rax
movq $0x0, 0x20(%rsp)
movq 0x28(%rax), %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
cmpq $0x0, 0x18(%rsp)
movb %al, 0xf(%rsp)
je 0x5f7ae
movq 0x18(%rsp), %rax
cmpq 0x20(%rsp), %rax
setne %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x5f7bb
jmp 0x5f841
movq 0x18(%rsp), %rax
movsd 0x50(%rax), %xmm0
movsd 0x1449b3(%rip), %xmm1   # 0x1a4180
ucomisd %xmm1, %xmm0
jne 0x5f7d7
jp 0x5f7d7
jmp 0x5f841
movq 0x18(%rsp), %rax
movsd 0x14499c(%rip), %xmm0   # 0x1a4180
movsd %xmm0, 0x50(%rax)
movq 0x18(%rsp), %rdi
addq $0x60, %rdi
xorl %esi, %esi
callq 0x1bda0
movq %rax, %rdi
xorl %esi, %esi
callq 0x1bde0
movsd 0x144985(%rip), %xmm0   # 0x1a4190
movsd %xmm0, (%rax)
movq 0x18(%rsp), %rdi
addq $0xa8, %rdi
xorl %esi, %esi
callq 0x1be00
movsd 0x144966(%rip), %xmm0   # 0x1a4190
movsd %xmm0, (%rax)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x5f78f
movq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
cmpq $0x0, 0x18(%rsp)
movb %al, 0xe(%rsp)
je 0x5f86a
movq 0x18(%rsp), %rax
cmpq 0x20(%rsp), %rax
setne %al
movb %al, 0xe(%rsp)
movb 0xe(%rsp), %al
testb $0x1, %al
jne 0x5f877
jmp 0x5f8fd
movq 0x18(%rsp), %rax
movsd 0x50(%rax), %xmm0
movsd 0x1448f7(%rip), %xmm1   # 0x1a4180
ucomisd %xmm1, %xmm0
jne 0x5f893
jp 0x5f893
jmp 0x5f8fd
movq 0x18(%rsp), %rax
movsd 0x1448e0(%rip), %xmm0   # 0x1a4180
movsd %xmm0, 0x50(%rax)
movq 0x18(%rsp), %rdi
addq $0x60, %rdi
xorl %esi, %esi
callq 0x1bda0
movq %rax, %rdi
xorl %esi, %esi
callq 0x1bde0
movsd 0x1448c9(%rip), %xmm0   # 0x1a4190
movsd %xmm0, (%rax)
movq 0x18(%rsp), %rdi
addq $0xa8, %rdi
xorl %esi, %esi
callq 0x1be00
movsd 0x1448aa(%rip), %xmm0   # 0x1a4190
movsd %xmm0, (%rax)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x5f84b
movq 0x10(%rsp), %rsi
movq 0x28(%rsi), %rdi
addq $0x30, %rdi
callq 0x1bf30
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdi
addq $0x30, %rdi
callq 0x1bee0
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %rax
movq %rax, 0x28(%rdi)
callq 0x61030
cmpq $0x0, %rax
je 0x5f96d
movq 0x10(%rsp), %rdi
callq 0x61030
movq %rax, %rdi
callq 0x61040
cmpq $0x0, %rax
je 0x5f96d
movq 0x10(%rsp), %rdi
callq 0x61030
movq %rax, %rdi
callq 0x61040
movq %rax, %rdi
callq 0x1bea0
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)