// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelTree.cpp
// Function: gaps::R3SurfelTree::SplitNode(gaps::R3SurfelNode*, int, int, double, double, double, double, int)
int R3SurfelTree::
SplitNode(R3SurfelNode *node,  
    int max_parts_per_node, int max_blocks_per_node, 
    RNScalar max_leaf_complexity, RNScalar max_block_complexity,
    RNLength max_leaf_extent, RNLength max_block_extent,
    int max_levels)
{
  // Initialize return value
  int status = 0;

  // Just checking
  if (max_block_complexity > max_leaf_complexity) {
    max_block_complexity = max_leaf_complexity;
  }

  // Check if node is leaf
  if (node->NParts() == 0) {
    // Split blocks
    if (((max_block_complexity > 0) && (node->Complexity() > max_block_complexity)) ||
        ((max_block_extent > 0) && (node->BBox().LongestAxisLength() > max_block_extent))) {
      status |= SplitBlocks(node, max_block_complexity, max_block_extent);
    }

    // Check if node should be split 
    if (node->TreeLevel() < max_levels) {
      // Determine number of parts
      int nparts = 1;
      if (max_blocks_per_node > 0) {
        int n = node->NBlocks() / max_blocks_per_node + 1;
        if (n > nparts) nparts = n;
      }
      if (max_leaf_complexity > 0) {
        int n = (int) (node->Complexity() / max_leaf_complexity) + 1;
        if (n > nparts) nparts = n;
      }
      if (max_leaf_extent > 0) {
        int n = (int) (node->BBox().LongestAxisLength() / max_leaf_extent) + 1;
        if (n > nparts) nparts = n;
      }
      if (max_parts_per_node > 0) {
        if (nparts > max_parts_per_node) nparts = max_parts_per_node;
      }
      if (nparts > node->NBlocks()) {
        nparts = node->NBlocks();
      }

      // Split node into parts with K means clustering of blocks
      if (nparts > 1) {
        status |= SplitLeafNodeWithKMeansClusteringOfBlocks(this, node, nparts);
      }
    }
  }
  else {
    // Check if node should be split
    if (node->TreeLevel() < max_levels) {
      // Determine number of parts
      int nparts = node->NParts() / max_parts_per_node + 1;
      if (nparts > max_parts_per_node) nparts = max_parts_per_node;

      // Split node into parts with K means clustering of parts
      if (nparts > 1) {
        status |= SplitInteriorNodeWithKMeansClusteringOfParts(this, node, nparts);
      }
    }
  }

  // Return whether anything was split
  return status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %r8d, %ebp
movl %edx, %ebx
movq %rdi, 0x68(%rsp)
cmpl $0x0, 0x3c(%rsi)
movq %rsi, 0x8(%rsp)
je 0x39c0e
movq %rsi, %r14
movq %rsi, %rdi
callq 0x376e2
xorl %esi, %esi
cmpl %ebp, %eax
jge 0x3a14f
movl 0x3c(%r14), %ecx
movl %ecx, %eax
cltd
idivl %ebx
leal 0x1(%rax), %edx
cmpl %ebx, %eax
cmovgel %ebx, %edx
cmpl $0x2, %edx
setl %al
cmpl %edx, %ecx
setle %cl
orb %al, %cl
jne 0x3a14f
movq %r14, %rbp
movq %rdx, 0x18(%rsp)
leaq (,%rdx,8), %rax
leaq (%rax,%rax,2), %rbx
movq %rbx, %rdi
callq 0x13030
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
movq 0x28(%rsp), %rax
leaq (%rax,%r14), %rdi
callq 0x83dc0
addq $0x18, %r14
cmpq %r14, %rbx
jne 0x3983b
movslq 0x3c(%rbp), %rax
leaq (,%rax,4), %rcx
testq %rax, %rax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x13030
movq %rax, %r12
xorl %r14d, %r14d
leaq 0x48(%rsp), %rbx
movq 0x28(%rsp), %r13
movq 0x18(%rsp), %r15
movl 0x3c(%rbp), %eax
imull %r14d, %eax
cltd
idivl %r15d
movq 0x30(%rbp), %rcx
cltq
movq (%rcx,%rax,8), %rdi
callq 0x3755c
movq (%rax), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x68(%rcx)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x8412a
incq %r14
addq $0x18, %r13
cmpq %r14, %r15
jne 0x39886
movslq 0x3c(%rbp), %rdx
testq %rdx, %rdx
jle 0x398dd
shlq $0x2, %rdx
movq %r12, %rdi
movl $0xff, %esi
callq 0x132a0
leaq 0x48(%rsp), %r13
movl $0x0, 0x24(%rsp)
movq %r12, 0x30(%rsp)
cmpl $0x0, 0x3c(%rbp)
jle 0x39aaa
movl $0x1, %ebx
xorl %r15d, %r15d
movq 0x30(%rbp), %rax
movq (%rax,%r15,8), %rdi
callq 0x3755c
movq (%rax), %rcx
movq %r13, %rdi
movq %rax, %rsi
callq *0x68(%rcx)
movq 0x28(%rsp), %rbp
xorl %r14d, %r14d
movsd 0xa383e(%rip), %xmm0    # 0xdd168
movsd %xmm0, 0x10(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4feeb
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x39960
movl (%r12,%r15,4), %eax
cmpq %rax, %r14
movl $0x0, %eax
cmovnel %eax, %ebx
movl %r14d, (%r12,%r15,4)
movsd %xmm0, 0x10(%rsp)
incq %r14
addq $0x18, %rbp
cmpq %r14, 0x18(%rsp)
jne 0x39930
incq %r15
movq 0x8(%rsp), %rbp
movslq 0x3c(%rbp), %rax
cmpq %rax, %r15
jl 0x39901
testl %ebx, %ebx
jne 0x39aaa
xorl %ebp, %ebp
movq 0x18(%rsp), %r14
leaq (,%rbp,2), %rax
addq %rbp, %rax
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
movq %rdi, 0x38(%rsp)
leaq 0x4fbcc2(%rip), %rsi    # 0x535670
callq 0x8412a
movq 0x8(%rsp), %rax
movl 0x3c(%rax), %eax
testl %eax, %eax
jle 0x39a86
xorpd %xmm0, %xmm0
xorl %r14d, %r14d
movl (%r12,%r14,4), %ecx
cmpq %rcx, %rbp
jne 0x39a5e
movq 0x8(%rsp), %r12
movq 0x30(%r12), %rax
movq (%rax,%r14,8), %r15
movq %r15, %rdi
movsd %xmm0, 0x10(%rsp)
callq 0x3742e
movsd %xmm0, 0x40(%rsp)
movq %r15, %rdi
callq 0x3755c
movq (%rax), %rcx
movq %r13, %rbx
leaq 0x70(%rsp), %r13
movq %r13, %rdi
movq %rax, %rsi
callq *0x68(%rcx)
movq %rbx, %rdi
movq %r13, %rsi
movq %rbx, %r13
movsd 0x40(%rsp), %xmm0
callq 0x84806
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x846fc
movq %r15, %rdi
callq 0x3742e
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
movl 0x3c(%r12), %eax
movq 0x30(%rsp), %r12
incq %r14
movslq %eax, %rcx
cmpq %rcx, %r14
jl 0x399ca
ucomisd 0xa3913(%rip), %xmm0    # 0xdd388
movq 0x18(%rsp), %r14
jbe 0x39a86
movq 0x38(%rsp), %rdi
callq 0x8477a
incq %rbp
cmpq %r14, %rbp
jne 0x3998e
movl 0x24(%rsp), %eax
incl %eax
movl %eax, 0x24(%rsp)
cmpl $0x10, %eax
movq 0x8(%rsp), %rbp
jne 0x398ef
leaq 0x48(%rsp), %rdi
callq 0xa9ca8
cmpl $0x0, 0x3c(%rbp)
movq %rbp, %r15
movq 0x68(%rsp), %rbp
jle 0x39aea
xorl %r14d, %r14d
leaq 0x48(%rsp), %rbx
movq 0x30(%r15), %rax
movq (%rax,%r14,8), %rsi
movl 0x54(%rsp), %edx
movq %rbx, %rdi
callq 0xa9d3e
incq %r14
movslq 0x3c(%r15), %rax
cmpq %rax, %r14
jl 0x39aca
xorl %r15d, %r15d
movl $0xd0, %edi
callq 0x134e0
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x3715c
movq %rbp, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %rdx
callq 0x38f02
movl 0x54(%rsp), %eax
testl %eax, %eax
jle 0x39b56
xorl %r14d, %r14d
cmpl %r15d, (%r12,%r14,4)
jne 0x39b4b
movq 0x48(%rsp), %rax
movq (%rax,%r14,8), %r13
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3905c
movq %rbp, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x38f02
movl 0x54(%rsp), %eax
incq %r14
movslq %eax, %rcx
cmpq %rcx, %r14
jl 0x39b1f
cmpl $0x0, 0x3c(%rbx)
movq 0x18(%rsp), %r14
jne 0x39b75
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x3905c
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
incl %r15d
cmpl %r14d, %r15d
jne 0x39aed
movl $0x1, %ecx
movq 0x8(%rsp), %rax
cmpl $0x1, 0x3c(%rax)
jne 0x39be9
movq 0x30(%rax), %rax
movq (%rax), %rbx
cmpl $0x0, 0x54(%rsp)
jle 0x39bd3
xorl %r14d, %r14d
movq 0x48(%rsp), %rax
movq (%rax,%r14,8), %r13
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3905c
movq %rbp, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
callq 0x38f02
incq %r14
movslq 0x54(%rsp), %rax
cmpq %rax, %r14
jl 0x39ba2
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x3905c
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
xorl %ecx, %ecx
movq %r12, %rdi
movl %ecx, %ebx
callq 0x13680
movq 0x28(%rsp), %rdi
callq 0x13680
leaq 0x48(%rsp), %rdi
callq 0xa9d12
movl %ebx, %esi
jmp 0x3a14f
movl %ecx, %r15d
movsd %xmm2, 0x18(%rsp)
movsd %xmm0, 0x40(%rsp)
minsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x39c59
movq 0x8(%rsp), %rdi
movsd %xmm3, 0x38(%rsp)
movsd %xmm0, 0x10(%rsp)
callq 0x3742e
xorpd %xmm1, %xmm1
movsd 0x38(%rsp), %xmm3
ucomisd 0x10(%rsp), %xmm0
movsd 0x10(%rsp), %xmm0
ja 0x39c97
movl $0x0, 0x20(%rsp)
ucomisd %xmm1, %xmm3
jbe 0x39caf
movq 0x8(%rsp), %rdi
movsd %xmm3, 0x38(%rsp)
movsd %xmm0, 0x10(%rsp)
callq 0x3755c
movq %rax, %rdi
callq 0x6d97e
movsd 0x38(%rsp), %xmm3
ucomisd %xmm3, %xmm0
movsd 0x10(%rsp), %xmm0
jbe 0x39caf
movq 0x68(%rsp), %rdi
movq (%rdi), %rax
movq 0x8(%rsp), %rsi
movapd %xmm3, %xmm1
callq *0x40(%rax)
movl %eax, 0x20(%rsp)
movq 0x8(%rsp), %rdi
callq 0x376e2
cmpl %ebp, %eax
jge 0x39cdd
testl %r15d, %r15d
jle 0x39ce6
movq 0x8(%rsp), %rax
movl 0x4c(%rax), %eax
cltd
idivl %r15d
leal 0x1(%rax), %ecx
testl %eax, %eax
movl $0x1, %ebp
cmovgl %ecx, %ebp
jmp 0x39ceb
movl 0x20(%rsp), %esi
jmp 0x3a14f
movl $0x1, %ebp
movsd 0x40(%rsp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x39d1b
movq 0x8(%rsp), %rdi
callq 0x3742e
xorpd %xmm1, %xmm1
divsd 0x40(%rsp), %xmm0
cvttsd2si %xmm0, %eax
leal 0x1(%rax), %ecx
cmpl %eax, %ebp
cmovlel %ecx, %ebp
movsd 0x18(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x39d50
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x3755c
movq %rax, %rdi
callq 0x6d97e
divsd 0x18(%rsp), %xmm0
cvttsd2si %xmm0, %eax
leal 0x1(%rax), %ecx
cmpl %eax, %ebp
cmovlel %ecx, %ebp
jmp 0x39d55
movq 0x8(%rsp), %r14
movl 0x20(%rsp), %esi
cmpl %ebx, %ebp
movl %ebx, %eax
cmovll %ebp, %eax
testl %ebx, %ebx
cmovlel %ebp, %eax
movl %eax, %ebp
movl 0x4c(%r14), %eax
cmpl %eax, %ebp
cmovgel %eax, %ebp
cmpl $0x2, %ebp
jl 0x3a14f
movq %r14, %r15
movl %ebp, %r12d
leaq (,%r12,8), %rax
leaq (%rax,%rax,2), %rbx
movq %rbx, %rdi
callq 0x13030
movq %rax, 0x30(%rsp)
xorl %r14d, %r14d
movq 0x30(%rsp), %rax
leaq (%rax,%r14), %rdi
callq 0x83dc0
addq $0x18, %r14
cmpq %r14, %rbx
jne 0x39d9b
movslq 0x4c(%r15), %rax
leaq (,%rax,4), %rcx
testq %rax, %rax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x13030
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
leaq 0x48(%rsp), %rbx
movq 0x30(%rsp), %r13
movl 0x4c(%r15), %eax
imull %r14d, %eax
cltd
idivl %ebp
movq 0x40(%r15), %rcx
cltq
movq (%rcx,%rax,8), %rdi
callq 0x2cb9e
movq (%rax), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x68(%rcx)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x8412a
incq %r14
addq $0x18, %r13
cmpq %r14, %r12
jne 0x39de3
movl %ebp, 0x24(%rsp)
movslq 0x4c(%r15), %rdx
testq %rdx, %rdx
jle 0x39e40
shlq $0x2, %rdx
movq 0x18(%rsp), %rdi
movl $0xff, %esi
callq 0x132a0
leaq 0x48(%rsp), %rbx
movl $0x0, 0x64(%rsp)
movq %r12, 0x28(%rsp)
movq 0x8(%rsp), %rax
cmpl $0x0, 0x4c(%rax)
jle 0x39ff1
movl $0x1, %ebp
xorl %r15d, %r15d
movq 0x8(%rsp), %rcx
movq 0x40(%rcx), %rax
movq (%rax,%r15,8), %rdi
callq 0x2cb9e
movq (%rax), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x68(%rcx)
movq 0x30(%rsp), %r13
xorl %r14d, %r14d
movsd 0xa32d1(%rip), %xmm0    # 0xdd168
movsd %xmm0, 0x10(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4feeb
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x39ed2
movq 0x18(%rsp), %rcx
movl (%rcx,%r15,4), %eax
cmpq %rax, %r14
movl $0x0, %eax
cmovnel %eax, %ebp
movl %r14d, (%rcx,%r15,4)
movsd %xmm0, 0x10(%rsp)
incq %r14
addq $0x18, %r13
cmpq %r14, %r12
jne 0x39e9d
incq %r15
movq 0x8(%rsp), %rcx
movslq 0x4c(%rcx), %rax
cmpq %rax, %r15
jl 0x39e6e
testl %ebp, %ebp
jne 0x39ff1
xorl %r15d, %r15d
leaq (%r15,%r15,2), %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
movq %rdi, 0x40(%rsp)
leaq 0x4fb759(%rip), %rsi    # 0x535670
callq 0x8412a
movq 0x8(%rsp), %rax
movl 0x4c(%rax), %eax
testl %eax, %eax
jle 0x39fd2
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %r15, 0x38(%rsp)
movq 0x18(%rsp), %rcx
movl (%rcx,%r12,4), %ecx
cmpq %rcx, %r15
jne 0x39fab
movq 0x8(%rsp), %r13
movq 0x40(%r13), %rax
movq (%rax,%r12,8), %r15
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%r15), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
callq 0x2cb9e
movq (%rax), %rcx
movq %rbx, %rbp
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x68(%rcx)
movq %rbp, %rdi
movq %rbx, %rsi
movq %rbp, %rbx
movsd 0x10(%rsp), %xmm0
callq 0x84806
movq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x846fc
addl 0x8(%r15), %r14d
movq 0x38(%rsp), %r15
movl 0x4c(%r13), %eax
incq %r12
movslq %eax, %rcx
cmpq %rcx, %r12
jl 0x39f37
testl %r14d, %r14d
movq 0x28(%rsp), %r12
jle 0x39fd2
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movq 0x40(%rsp), %rdi
callq 0x8477a
incq %r15
cmpq %r12, %r15
jne 0x39efe
movl 0x64(%rsp), %eax
incl %eax
movl %eax, 0x64(%rsp)
cmpl $0x10, %eax
jne 0x39e52
leaq 0x48(%rsp), %rdi
callq 0xa9ca8
movq 0x8(%rsp), %rbp
cmpl $0x0, 0x4c(%rbp)
movq 0x68(%rsp), %r12
jle 0x3a033
xorl %r14d, %r14d
leaq 0x48(%rsp), %rbx
movq 0x40(%rbp), %rax
movq (%rax,%r14,8), %rsi
movl 0x54(%rsp), %edx
movq %rbx, %rdi
callq 0xa9d3e
incq %r14
movslq 0x4c(%rbp), %rax
cmpq %rax, %r14
jl 0x3a013
xorl %r14d, %r14d
movl $0xd0, %edi
callq 0x134e0
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x3715c
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x38f02
movl 0x54(%rsp), %eax
testl %eax, %eax
jle 0x3a0a2
xorl %r15d, %r15d
movq 0x18(%rsp), %rcx
cmpl %r14d, (%rcx,%r15,4)
jne 0x3a097
movq 0x48(%rsp), %rax
movq (%rax,%r15,8), %r13
movq (%rbp), %rax
movq %rbp, %rdi
movq %r13, %rsi
callq *0x30(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
callq *0x28(%rax)
movl 0x54(%rsp), %eax
incq %r15
movslq %eax, %rcx
cmpq %rcx, %r15
jl 0x3a066
cmpl $0x0, 0x4c(%rbx)
jne 0x3a0bc
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3905c
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
incl %r14d
cmpl 0x24(%rsp), %r14d
jne 0x3a036
movl $0x1, %ebx
cmpl $0x1, 0x3c(%rbp)
jne 0x3a12b
movq 0x30(%rbp), %rax
movq (%rax), %rbx
cmpl $0x0, 0x54(%rsp)
jle 0x3a115
xorl %r14d, %r14d
movq 0x48(%rsp), %rax
movq (%rax,%r14,8), %r13
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
callq *0x30(%rax)
movq (%rbp), %rax
movq %rbp, %rdi
movq %r13, %rsi
callq *0x28(%rax)
incq %r14
movslq 0x54(%rsp), %rax
cmpq %rax, %r14
jl 0x3a0e6
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3905c
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
xorl %ebx, %ebx
movq 0x18(%rsp), %rdi
callq 0x13680
movq 0x30(%rsp), %rdi
callq 0x13680
leaq 0x48(%rsp), %rdi
callq 0xa9d12
movl 0x20(%rsp), %esi
orl %ebx, %esi
movl %esi, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3a1a5
jmp 0x3a1a5
jmp 0x3a1a5
jmp 0x3a1a5
jmp 0x3a17b
movq %rax, %r14
movq 0x30(%rsp), %rdi
jmp 0x3a195
jmp 0x3a1a5
jmp 0x3a1a5
movq %rax, %r14
movl $0xd0, %esi
movq %rbx, %rdi
callq 0x134f0
jmp 0x3a1a8
movq %rax, %r14
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x139b0
jmp 0x3a1b2
jmp 0x3a1a5
jmp 0x3a1a5
jmp 0x3a1a5
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0xa9d12
movq %r14, %rdi
callq 0x138b0