// File: /workspace/github_cpp_makefile_star2_O1/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 0x39fb7
movq %rsi, %r14
movq %rsi, %rdi
callq 0x37a04
xorl %esi, %esi
cmpl %ebp, %eax
jge 0x3a503
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 0x3a503
movq %r14, %rbp
movq %rdx, 0x58(%rsp)
leaq (,%rdx,8), %rax
leaq (%rax,%rax,2), %r12
movq %r12, %rdi
callq 0x13030
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
leaq (%rax,%rbx), %rdi
callq 0x84d7c
addq $0x18, %rbx
cmpq %rbx, %r12
jne 0x39bea
movslq 0x3c(%rbp), %rax
leaq (,%rax,4), %rcx
testq %rax, %rax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x13030
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
leaq 0x30(%rsp), %rbx
movq 0x20(%rsp), %r13
movq 0x58(%rsp), %r12
movl 0x3c(%rbp), %eax
imull %r14d, %eax
cltd
idivl %r12d
movq 0x30(%rbp), %rcx
cltq
movq (%rcx,%rax,8), %rdi
callq 0x37838
movq (%rax), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x68(%rcx)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x850ec
incq %r14
addq $0x18, %r13
cmpq %r14, %r12
jne 0x39c37
movslq 0x3c(%rbp), %rdx
testq %rdx, %rdx
jle 0x39c90
shlq $0x2, %rdx
movq 0x18(%rsp), %rdi
movl $0xff, %esi
callq 0x132a0
leaq 0x30(%rsp), %r13
movl $0x0, 0x2c(%rsp)
cmpl $0x0, 0x3c(%rbp)
jle 0x39e52
movl $0x1, %ebx
xorl %r15d, %r15d
movq 0x30(%rbp), %rax
movq (%rax,%r15,8), %rdi
callq 0x37838
movq (%rax), %rcx
movq %r13, %rdi
movq %rax, %rsi
callq *0x68(%rcx)
movq 0x20(%rsp), %rbp
xorl %r14d, %r14d
movsd 0xa4498(%rip), %xmm0    # 0xde170
movsd %xmm0, 0x10(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x50893
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x39d13
movq 0x18(%rsp), %rcx
movl (%rcx,%r15,4), %eax
cmpq %rax, %r14
movl $0x0, %eax
cmovnel %eax, %ebx
movl %r14d, (%rcx,%r15,4)
movsd %xmm0, 0x10(%rsp)
incq %r14
addq $0x18, %rbp
cmpq %r14, %r12
jne 0x39cde
incq %r15
movq 0x8(%rsp), %rbp
movslq 0x3c(%rbp), %rax
cmpq %rax, %r15
jl 0x39caf
testl %ebx, %ebx
jne 0x39e52
xorl %ebx, %ebx
leaq (%rbx,%rbx,2), %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
movq %rdi, 0x48(%rsp)
leaq 0x4fc919(%rip), %rsi    # 0x536670
callq 0x850ec
movq 0x8(%rsp), %rax
cmpl $0x0, 0x3c(%rax)
jle 0x39e11
xorpd %xmm0, %xmm0
xorl %r14d, %r14d
movq 0x18(%rsp), %rax
movl (%rax,%r14,4), %eax
cmpq %rax, %rbx
jne 0x39df9
movq 0x8(%rsp), %r12
movq 0x30(%r12), %rax
movq (%rax,%r14,8), %r15
movq %r15, %rdi
movsd %xmm0, 0x10(%rsp)
callq 0x3770e
movsd %xmm0, 0x50(%rsp)
movq %r15, %rdi
callq 0x37838
movq (%rax), %rcx
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
movq %rax, %rsi
callq *0x68(%rcx)
movq %r13, %rdi
movq %rbp, %rsi
movsd 0x50(%rsp), %xmm0
callq 0x857c8
movq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x856be
movq %r15, %rdi
callq 0x3770e
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
jmp 0x39dfe
movq 0x8(%rsp), %r12
incq %r14
movslq 0x3c(%r12), %rax
cmpq %rax, %r14
jl 0x39d72
jmp 0x39e15
xorpd %xmm0, %xmm0
ucomisd 0xa456b(%rip), %xmm0    # 0xde388
jbe 0x39e29
movq 0x48(%rsp), %rdi
callq 0x8573c
incq %rbx
movq 0x58(%rsp), %r12
cmpq %r12, %rbx
jne 0x39d3e
movl 0x2c(%rsp), %eax
incl %eax
movl %eax, 0x2c(%rsp)
cmpl $0x10, %eax
movq 0x8(%rsp), %rbp
jne 0x39c9d
leaq 0x30(%rsp), %rdi
callq 0xaaf34
cmpl $0x0, 0x3c(%rbp)
movq %rbp, %r15
movq 0x68(%rsp), %rbp
jle 0x39e92
xorl %r14d, %r14d
leaq 0x30(%rsp), %rbx
movq 0x30(%r15), %rax
movq (%rax,%r14,8), %rsi
movl 0x3c(%rsp), %edx
movq %rbx, %rdi
callq 0xaafca
incq %r14
movslq 0x3c(%r15), %rax
cmpq %rax, %r14
jl 0x39e72
xorl %r15d, %r15d
movl $0xd0, %edi
callq 0x134e0
movq %rax, %r13
movq %rax, %rdi
xorl %esi, %esi
callq 0x37448
movq %rbp, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
callq 0x39272
cmpl $0x0, 0x3c(%rsp)
jle 0x39f00
xorl %r14d, %r14d
movq 0x18(%rsp), %rax
cmpl %r15d, (%rax,%r14,4)
jne 0x39ef3
movq 0x30(%rsp), %rax
movq (%rax,%r14,8), %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x393e0
movq %rbp, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x39272
incq %r14
movslq 0x3c(%rsp), %rax
cmpq %rax, %r14
jl 0x39ec6
cmpl $0x0, 0x3c(%r13)
jne 0x39f1c
movq %rbp, %rdi
movq %r13, %rsi
callq 0x393e0
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
incl %r15d
cmpl %r12d, %r15d
jne 0x39e95
movl $0x1, %ecx
movq 0x8(%rsp), %rax
cmpl $0x1, 0x3c(%rax)
jne 0x39f90
movq 0x30(%rax), %rax
movq (%rax), %rbx
cmpl $0x0, 0x3c(%rsp)
jle 0x39f7a
xorl %r14d, %r14d
movq 0x30(%rsp), %rax
movq (%rax,%r14,8), %r13
movq %rbp, %rdi
movq %r13, %rsi
callq 0x393e0
movq %rbp, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
callq 0x39272
incq %r14
movslq 0x3c(%rsp), %rax
cmpq %rax, %r14
jl 0x39f49
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x393e0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
xorl %ecx, %ecx
movq 0x18(%rsp), %rdi
movl %ecx, %ebx
callq 0x13680
movq 0x20(%rsp), %rdi
callq 0x13680
leaq 0x30(%rsp), %rdi
callq 0xaaf9e
movl %ebx, %esi
jmp 0x3a503
movl %ecx, %r15d
movsd %xmm2, 0x18(%rsp)
movsd %xmm0, 0x50(%rsp)
minsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3a002
movq 0x8(%rsp), %rdi
movsd %xmm3, 0x48(%rsp)
movsd %xmm0, 0x10(%rsp)
callq 0x3770e
xorpd %xmm1, %xmm1
movsd 0x48(%rsp), %xmm3
ucomisd 0x10(%rsp), %xmm0
movsd 0x10(%rsp), %xmm0
ja 0x3a040
movl $0x0, 0x28(%rsp)
ucomisd %xmm1, %xmm3
jbe 0x3a058
movq 0x8(%rsp), %rdi
movsd %xmm3, 0x48(%rsp)
movsd %xmm0, 0x10(%rsp)
callq 0x37838
movq %rax, %rdi
callq 0x6e5de
movsd 0x48(%rsp), %xmm3
ucomisd %xmm3, %xmm0
movsd 0x10(%rsp), %xmm0
jbe 0x3a058
movq 0x68(%rsp), %rdi
movq (%rdi), %rax
movq 0x8(%rsp), %rsi
movapd %xmm3, %xmm1
callq *0x40(%rax)
movl %eax, 0x28(%rsp)
movq 0x8(%rsp), %rdi
callq 0x37a04
cmpl %ebp, %eax
jge 0x3a086
testl %r15d, %r15d
jle 0x3a08f
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 0x3a094
movl 0x28(%rsp), %esi
jmp 0x3a503
movl $0x1, %ebp
movsd 0x50(%rsp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3a0c4
movq 0x8(%rsp), %rdi
callq 0x3770e
xorpd %xmm1, %xmm1
divsd 0x50(%rsp), %xmm0
cvttsd2si %xmm0, %eax
leal 0x1(%rax), %ecx
cmpl %eax, %ebp
cmovlel %ecx, %ebp
movsd 0x18(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3a0f9
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x37838
movq %rax, %rdi
callq 0x6e5de
divsd 0x18(%rsp), %xmm0
cvttsd2si %xmm0, %eax
leal 0x1(%rax), %ecx
cmpl %eax, %ebp
cmovlel %ecx, %ebp
jmp 0x3a0fe
movq 0x8(%rsp), %r14
movl 0x28(%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 0x3a503
movq %r14, %r15
movl %ebp, %eax
movq %rax, 0x58(%rsp)
leaq (,%rax,8), %rax
leaq (%rax,%rax,2), %r12
movq %r12, %rdi
callq 0x13030
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
leaq (%rax,%rbx), %rdi
callq 0x84d7c
addq $0x18, %rbx
cmpq %rbx, %r12
jne 0x3a147
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 0x30(%rsp), %rbx
movq 0x20(%rsp), %r13
movq 0x58(%rsp), %r12
movl 0x4c(%r15), %eax
imull %r14d, %eax
cltd
idivl %ebp
movq 0x40(%r15), %rcx
cltq
movq (%rcx,%rax,8), %rdi
callq 0x2cfc6
movq (%rax), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x68(%rcx)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x850ec
incq %r14
addq $0x18, %r13
cmpq %r14, %r12
jne 0x3a194
movl %ebp, 0x2c(%rsp)
movslq 0x4c(%r15), %rdx
testq %rdx, %rdx
jle 0x3a1f1
shlq $0x2, %rdx
movq 0x18(%rsp), %rdi
movl $0xff, %esi
callq 0x132a0
xorl %ebx, %ebx
movl $0x0, 0x64(%rsp)
movq 0x8(%rsp), %rax
cmpl $0x0, 0x4c(%rax)
jle 0x3a3a5
movl $0x1, %ebp
xorl %r15d, %r15d
movq 0x8(%rsp), %rcx
movq 0x40(%rcx), %rax
movq (%rax,%r15,8), %rdi
callq 0x2cfc6
movq (%rax), %rcx
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
callq *0x68(%rcx)
movq 0x20(%rsp), %r13
xorl %r14d, %r14d
movsd 0xa3f2e(%rip), %xmm0    # 0xde170
movsd %xmm0, 0x10(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
callq 0x50893
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x3a27a
movq 0x18(%rsp), %rcx
movl (%rcx,%r15,4), %eax
cmpq %rax, %r14
cmovnel %ebx, %ebp
movl %r14d, (%rcx,%r15,4)
movsd %xmm0, 0x10(%rsp)
incq %r14
addq $0x18, %r13
cmpq %r14, %r12
jne 0x3a248
incq %r15
movq 0x8(%rsp), %rcx
movslq 0x4c(%rcx), %rax
cmpq %rax, %r15
jl 0x3a217
testl %ebp, %ebp
jne 0x3a3a5
xorl %r15d, %r15d
leaq (%r15,%r15,2), %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
movq %rdi, 0x50(%rsp)
leaq 0x4fc3b5(%rip), %rsi    # 0x536670
callq 0x850ec
movq 0x8(%rsp), %rax
cmpl $0x0, 0x4c(%rax)
jle 0x3a362
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %r15, 0x48(%rsp)
movq 0x18(%rsp), %rax
movl (%rax,%r12,4), %eax
cmpq %rax, %r15
jne 0x3a34b
movq 0x8(%rsp), %rbx
movq 0x40(%rbx), %rax
movq (%rax,%r12,8), %r15
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%r15), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
callq 0x2cfc6
movq (%rax), %rcx
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
movq %rax, %rsi
callq *0x68(%rcx)
leaq 0x30(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
movsd 0x10(%rsp), %xmm0
callq 0x857c8
movq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x856be
addl 0x8(%r15), %r14d
movq 0x48(%rsp), %r15
jmp 0x3a350
movq 0x8(%rsp), %rbx
incq %r12
movslq 0x4c(%rbx), %rax
cmpq %rax, %r12
jl 0x3a2da
jmp 0x3a365
xorl %r14d, %r14d
testl %r14d, %r14d
jle 0x3a37c
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movq 0x50(%rsp), %rdi
callq 0x8573c
incq %r15
movq 0x58(%rsp), %r12
cmpq %r12, %r15
movl $0x0, %ebx
jne 0x3a2a2
movl 0x64(%rsp), %eax
incl %eax
movl %eax, 0x64(%rsp)
cmpl $0x10, %eax
jne 0x3a1fb
leaq 0x30(%rsp), %rdi
callq 0xaaf34
movq 0x8(%rsp), %rbp
cmpl $0x0, 0x4c(%rbp)
movq 0x68(%rsp), %r12
jle 0x3a3e7
xorl %r14d, %r14d
leaq 0x30(%rsp), %rbx
movq 0x40(%rbp), %rax
movq (%rax,%r14,8), %rsi
movl 0x3c(%rsp), %edx
movq %rbx, %rdi
callq 0xaafca
incq %r14
movslq 0x4c(%rbp), %rax
cmpq %rax, %r14
jl 0x3a3c7
xorl %r14d, %r14d
movl $0xd0, %edi
callq 0x134e0
movq %rax, %r13
movq %rax, %rdi
xorl %esi, %esi
callq 0x37448
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x39272
cmpl $0x0, 0x3c(%rsp)
jle 0x3a454
xorl %r15d, %r15d
movq 0x18(%rsp), %rax
cmpl %r14d, (%rax,%r15,4)
jne 0x3a447
movq 0x30(%rsp), %rax
movq (%rax,%r15,8), %rbx
movq (%rbp), %rax
movq %rbp, %rdi
movq %rbx, %rsi
callq *0x30(%rax)
movq (%r13), %rax
movq %r13, %rdi
movq %rbx, %rsi
callq *0x28(%rax)
incq %r15
movslq 0x3c(%rsp), %rax
cmpq %rax, %r15
jl 0x3a419
cmpl $0x0, 0x4c(%r13)
jne 0x3a470
movq %r12, %rdi
movq %r13, %rsi
callq 0x393e0
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
incl %r14d
cmpl 0x2c(%rsp), %r14d
jne 0x3a3ea
movl $0x1, %ebx
cmpl $0x1, 0x3c(%rbp)
jne 0x3a4df
movq 0x30(%rbp), %rax
movq (%rax), %rbx
cmpl $0x0, 0x3c(%rsp)
jle 0x3a4c9
xorl %r14d, %r14d
movq 0x30(%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 0x3c(%rsp), %rax
cmpq %rax, %r14
jl 0x3a49a
movq %r12, %rdi
movq %rbx, %rsi
callq 0x393e0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
xorl %ebx, %ebx
movq 0x18(%rsp), %rdi
callq 0x13680
movq 0x20(%rsp), %rdi
callq 0x13680
leaq 0x30(%rsp), %rdi
callq 0xaaf9e
movl 0x28(%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 0x3a551
jmp 0x3a551
jmp 0x3a551
jmp 0x3a551
jmp 0x3a527
jmp 0x3a539
jmp 0x3a551
jmp 0x3a551
movq %rax, %rbx
movl $0xd0, %esi
movq %r13, %rdi
callq 0x134f0
jmp 0x3a554
movq %rax, %rbx
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x139b0
jmp 0x3a55e
jmp 0x3a551
jmp 0x3a551
jmp 0x3a551
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xaaf9e
movq %rbx, %rdi
callq 0x138b0