// File: /workspace/github_cpp_makefile_star2_O2/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, 0x48(%rsp)
cmpl $0x0, 0x3c(%rsi)
pushq $-0x1
popq %r13
movq %rsi, 0x8(%rsp)
je 0x356d0
movq %rsi, %r14
movq %rsi, %rdi
callq 0x338a4
xorl %esi, %esi
cmpl %ebp, %eax
jge 0x35eae
movl 0x3c(%r14), %ecx
movl %ecx, %eax
cltd
idivl %ebx
leal 0x1(%rax), %r15d
cmpl %ebx, %eax
cmovgel %ebx, %r15d
cmpl $0x2, %r15d
setl %al
cmpl %r15d, %ecx
setle %cl
orb %al, %cl
jne 0x35eae
imulq $0x18, %r15, %r12
movq %r12, %rdi
callq 0x13030
movq %rax, 0x30(%rsp)
xorl %ebx, %ebx
movq 0x30(%rsp), %rax
leaq (%rax,%rbx), %rdi
callq 0x781ba
addq $0x18, %rbx
cmpq %rbx, %r12
jne 0x35650
movslq 0x3c(%r14), %rbx
leaq (,%rbx,4), %rdi
testq %rbx, %rbx
cmovsq %r13, %rdi
callq 0x13030
movq %rax, %r12
xorl %r14d, %r14d
leaq 0x50(%rsp), %r13
movq 0x30(%rsp), %rbp
cmpq %r14, %r15
je 0x357ad
imull %r14d, %ebx
movl %ebx, %eax
cltd
idivl %r15d
movq 0x8(%rsp), %rbx
movq 0x30(%rbx), %rcx
cltq
movq (%rcx,%rax,8), %rsi
movq %r13, %rdi
callq 0x36c84
movq %rbp, %rdi
movq %r13, %rsi
callq 0x784a6
incq %r14
movl 0x3c(%rbx), %ebx
addq $0x18, %rbp
jmp 0x3568f
movl %ecx, %r15d
movsd %xmm2, 0x20(%rsp)
movsd %xmm0, 0x40(%rsp)
minsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3571b
movq 0x8(%rsp), %rdi
movsd %xmm3, 0x18(%rsp)
movsd %xmm0, 0x10(%rsp)
callq 0x3365c
xorpd %xmm1, %xmm1
movsd 0x18(%rsp), %xmm3
ucomisd 0x10(%rsp), %xmm0
movsd 0x10(%rsp), %xmm0
ja 0x35759
movl $0x0, 0x2c(%rsp)
ucomisd %xmm1, %xmm3
jbe 0x35771
movq 0x8(%rsp), %rdi
movsd %xmm3, 0x18(%rsp)
movsd %xmm0, 0x10(%rsp)
callq 0x33720
movq %rax, %rdi
callq 0x642d6
movsd 0x18(%rsp), %xmm3
ucomisd %xmm3, %xmm0
movsd 0x10(%rsp), %xmm0
jbe 0x35771
movq 0x48(%rsp), %rdi
movq (%rdi), %rax
movq 0x8(%rsp), %rsi
movapd %xmm3, %xmm1
callq *0x40(%rax)
movl %eax, 0x2c(%rsp)
movq 0x8(%rsp), %rdi
callq 0x338a4
cmpl %ebp, %eax
jge 0x357a4
testl %r15d, %r15d
jle 0x35aab
movq 0x8(%rsp), %rax
movl 0x4c(%rax), %eax
cltd
idivl %r15d
leal 0x1(%rax), %ecx
testl %eax, %eax
pushq $0x1
popq %rbp
cmovgl %ecx, %ebp
jmp 0x35aae
movl 0x2c(%rsp), %esi
jmp 0x35eae
movq %r15, 0x20(%rsp)
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
movq 0x48(%rsp), %rbp
cmpq %rax, %rbx
je 0x357cd
orl $-0x1, (%r12,%rax,4)
incq %rax
jmp 0x357be
leaq 0x50(%rsp), %r13
xorl %eax, %eax
movl %eax, 0x3c(%rsp)
cmpl $0x10, %eax
je 0x3595f
xorl %r15d, %r15d
pushq $0x1
popq %r14
movq 0x8(%rsp), %rcx
movslq 0x3c(%rcx), %rax
cmpq %rax, %r15
jge 0x35866
movq 0x30(%rcx), %rax
movq (%rax,%r15,8), %rsi
movq %r13, %rdi
callq 0x36c84
movq 0x30(%rsp), %rbp
xorl %ebx, %ebx
movsd 0x92953(%rip), %xmm0    # 0xc8168
movsd %xmm0, 0x10(%rsp)
cmpq %rbx, 0x20(%rsp)
je 0x3585c
movq %rbp, %rdi
movq %r13, %rsi
callq 0x495a1
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x35853
movl (%r12,%r15,4), %eax
cmpq %rax, %rbx
movl $0x0, %eax
cmovnel %eax, %r14d
movl %ebx, (%r12,%r15,4)
movsd %xmm0, 0x10(%rsp)
incq %rbx
addq $0x18, %rbp
jmp 0x3581b
incq %r15
movq 0x48(%rsp), %rbp
jmp 0x357e8
testl %r14d, %r14d
jne 0x3595f
xorl %r14d, %r14d
cmpq 0x20(%rsp), %r14
je 0x35954
imulq $0x18, %r14, %rdi
addq 0x30(%rsp), %rdi
movq %rdi, 0x18(%rsp)
leaq 0x4f0dfe(%rip), %rsi    # 0x526690
callq 0x784a6
xorpd %xmm0, %xmm0
xorl %ebx, %ebx
movq 0x8(%rsp), %rax
movslq 0x3c(%rax), %rax
cmpq %rax, %rbx
jge 0x35933
movl (%r12,%rbx,4), %eax
cmpq %rax, %r14
jne 0x3592b
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rax
movq (%rax,%rbx,8), %r15
movq %r15, %rdi
movsd %xmm0, 0x10(%rsp)
callq 0x3365c
movsd %xmm0, 0x40(%rsp)
movq %r12, %rbp
leaq 0x70(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x36c84
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %r12
movsd 0x40(%rsp), %xmm0
callq 0x78930
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x78826
movq %r15, %rdi
callq 0x3365c
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
incq %rbx
jmp 0x3589d
ucomisd 0x92a45(%rip), %xmm0    # 0xc8380
jbe 0x35947
movq 0x18(%rsp), %rdi
callq 0x788a4
incq %r14
movq 0x48(%rsp), %rbp
jmp 0x35872
movl 0x3c(%rsp), %eax
incl %eax
jmp 0x357d4
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
callq 0x9a7ae
xorl %r14d, %r14d
movq 0x8(%rsp), %rcx
movslq 0x3c(%rcx), %rax
cmpq %rax, %r14
jge 0x35992
movq 0x30(%rcx), %rax
movq (%rax,%r14,8), %rsi
movq %rbx, %rdi
callq 0x1784c
incq %r14
jmp 0x3596f
xorl %r15d, %r15d
cmpl 0x20(%rsp), %r15d
je 0x35a25
movl $0xd0, %edi
callq 0x134f0
movq %rax, %r13
movq %rax, %rdi
xorl %esi, %esi
callq 0x33394
movq %rbp, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
callq 0x34e72
xorl %r14d, %r14d
movslq 0x5c(%rsp), %rax
cmpq %rax, %r14
jge 0x35a01
cmpl %r15d, (%r12,%r14,4)
jne 0x359fc
movq 0x50(%rsp), %rax
movq (%rax,%r14,8), %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x34fc0
movq %rbp, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x34e72
incq %r14
jmp 0x359ca
cmpl $0x0, 0x3c(%r13)
jne 0x35a1d
movq %rbp, %rdi
movq %r13, %rsi
callq 0x34fc0
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
incl %r15d
jmp 0x35995
movq 0x8(%rsp), %rax
cmpl $0x1, 0x3c(%rax)
jne 0x35a6d
movq 0x30(%rax), %rax
movq (%rax), %rbx
xorl %r14d, %r14d
movslq 0x5c(%rsp), %rax
cmpq %rax, %r14
jge 0x35a72
movq 0x50(%rsp), %rax
movq (%rax,%r14,8), %r13
movq %rbp, %rdi
movq %r13, %rsi
callq 0x34fc0
movq %rbp, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
callq 0x34e72
incq %r14
jmp 0x35a3a
pushq $0x1
popq %rbx
jmp 0x35a88
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x34fc0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
xorl %ebx, %ebx
movq %r12, %rdi
callq 0x136a0
movq 0x30(%rsp), %rdi
callq 0x136a0
leaq 0x50(%rsp), %rdi
callq 0x9a81c
movl %ebx, %esi
jmp 0x35eae
pushq $0x1
popq %rbp
movsd 0x40(%rsp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x35ade
movq 0x8(%rsp), %rdi
callq 0x3365c
xorpd %xmm1, %xmm1
divsd 0x40(%rsp), %xmm0
cvttsd2si %xmm0, %eax
leal 0x1(%rax), %ecx
cmpl %eax, %ebp
cmovlel %ecx, %ebp
movsd 0x20(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x35b13
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x33720
movq %rax, %rdi
callq 0x642d6
divsd 0x20(%rsp), %xmm0
cvttsd2si %xmm0, %eax
leal 0x1(%rax), %ecx
cmpl %eax, %ebp
cmovlel %ecx, %ebp
jmp 0x35b18
movq 0x8(%rsp), %r14
movl 0x2c(%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 0x35eae
movl %ebp, %eax
movq %rax, 0x30(%rsp)
imulq $0x18, %rax, %r12
movq %r12, %rdi
callq 0x13030
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
movq 0x18(%rsp), %rax
leaq (%rax,%rbx), %rdi
callq 0x781ba
addq $0x18, %rbx
cmpq %rbx, %r12
jne 0x35b56
movl %ebp, 0x3c(%rsp)
movslq 0x4c(%r14), %rbx
leaq (,%rbx,4), %rdi
testq %rbx, %rbx
cmovsq %r13, %rdi
callq 0x13030
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0x50(%rsp), %r13
movq 0x18(%rsp), %rbp
movq 0x30(%rsp), %r12
cmpq %r14, %r12
je 0x35bde
imull %r14d, %ebx
movl %ebx, %eax
cltd
idivl 0x3c(%rsp)
movq 0x8(%rsp), %rbx
movq 0x40(%rbx), %rcx
cltq
movq (%rcx,%rax,8), %rsi
movq %r13, %rdi
callq 0x36c66
movq %rbp, %rdi
movq %r13, %rsi
callq 0x784a6
incq %r14
movl 0x4c(%rbx), %ebx
addq $0x18, %rbp
jmp 0x35ba0
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
movq 0x10(%rsp), %rcx
cmpq %rax, %rbx
je 0x35bf8
orl $-0x1, (%rcx,%rax,4)
incq %rax
jmp 0x35bea
leaq 0x50(%rsp), %rbx
xorl %eax, %eax
movl %eax, 0x6c(%rsp)
cmpl $0x10, %eax
je 0x35d5f
xorl %r15d, %r15d
pushq $0x1
popq %rbp
movq 0x8(%rsp), %rcx
movslq 0x4c(%rcx), %rax
cmpq %rax, %r15
jge 0x35c8e
movq 0x40(%rcx), %rax
movq (%rax,%r15,8), %rsi
movq %rbx, %rdi
callq 0x36c66
movq 0x18(%rsp), %r13
xorl %r14d, %r14d
movsd 0x92528(%rip), %xmm0    # 0xc8168
movsd %xmm0, 0x20(%rsp)
cmpq %r14, %r12
je 0x35c89
movq %r13, %rdi
movq %rbx, %rsi
callq 0x495a1
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x35c80
movq 0x10(%rsp), %rcx
movl (%rcx,%r15,4), %eax
cmpq %rax, %r14
movl $0x0, %eax
cmovnel %eax, %ebp
movl %r14d, (%rcx,%r15,4)
movsd %xmm0, 0x20(%rsp)
incq %r14
addq $0x18, %r13
jmp 0x35c46
incq %r15
jmp 0x35c12
testl %ebp, %ebp
jne 0x35d5f
xorl %ebp, %ebp
cmpq %r12, %rbp
je 0x35d54
imulq $0x18, %rbp, %rdi
addq 0x18(%rsp), %rdi
movq %rdi, 0x40(%rsp)
leaq 0x4f09da(%rip), %rsi    # 0x526690
callq 0x784a6
xorl %r12d, %r12d
xorl %r14d, %r14d
movq 0x8(%rsp), %rax
movslq 0x4c(%rax), %rax
cmpq %rax, %r12
jge 0x35d33
movq 0x10(%rsp), %rax
movl (%rax,%r12,4), %eax
cmpq %rax, %rbp
jne 0x35d2e
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rax
movq (%rax,%r12,8), %r15
cvtsi2sdl 0x8(%r15), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbx, %r13
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x36c66
movq %r13, %rdi
movq %rbx, %rsi
movq %r13, %rbx
movsd 0x20(%rsp), %xmm0
callq 0x78930
movq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x78826
addl 0x8(%r15), %r14d
incq %r12
jmp 0x35cc1
testl %r14d, %r14d
jle 0x35d47
cvtsi2sd %r14d, %xmm0
movq 0x40(%rsp), %rdi
callq 0x788a4
incq %rbp
movq 0x30(%rsp), %r12
jmp 0x35c98
movl 0x6c(%rsp), %eax
incl %eax
jmp 0x35bff
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
callq 0x9a7ae
xorl %r14d, %r14d
movq 0x48(%rsp), %r12
movq 0x8(%rsp), %rbp
movslq 0x4c(%rbp), %rax
cmpq %rax, %r14
jge 0x35d97
movq 0x40(%rbp), %rax
movq (%rax,%r14,8), %rsi
movq %rbx, %rdi
callq 0x1784c
incq %r14
jmp 0x35d79
xorl %r14d, %r14d
cmpl 0x3c(%rsp), %r14d
je 0x35e2e
movl $0xd0, %edi
callq 0x134f0
movq %rax, %r13
movq %rax, %rdi
xorl %esi, %esi
callq 0x33394
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x34e72
xorl %r15d, %r15d
movslq 0x5c(%rsp), %rax
cmpq %rax, %r15
jge 0x35e0a
movq 0x10(%rsp), %rax
cmpl %r14d, (%rax,%r15,4)
jne 0x35e05
movq 0x50(%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
jmp 0x35dcd
cmpl $0x0, 0x4c(%r13)
jne 0x35e26
movq %r12, %rdi
movq %r13, %rsi
callq 0x34fc0
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
incl %r14d
jmp 0x35d9a
cmpl $0x1, 0x3c(%rbp)
jne 0x35e6f
movq 0x30(%rbp), %rax
movq (%rax), %rbx
xorl %r14d, %r14d
movslq 0x5c(%rsp), %rax
cmpq %rax, %r14
jge 0x35e74
movq 0x50(%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
jmp 0x35e3e
pushq $0x1
popq %rbx
jmp 0x35e8a
movq %r12, %rdi
movq %rbx, %rsi
callq 0x34fc0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
callq 0x136a0
movq 0x18(%rsp), %rdi
callq 0x136a0
leaq 0x50(%rsp), %rdi
callq 0x9a81c
movl 0x2c(%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 0x35f04
jmp 0x35f04
jmp 0x35f04
jmp 0x35ed8
jmp 0x35f04
movq %rax, %rbx
movq 0x18(%rsp), %rdi
jmp 0x35ef4
jmp 0x35f04
movq %rax, %rbx
movl $0xd0, %esi
movq %r13, %rdi
callq 0x13500
jmp 0x35f07
jmp 0x35f04
movq %rax, %rbx
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x139f0
jmp 0x35f11
jmp 0x35f04
jmp 0x35f04
jmp 0x35f04
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x9a81c
movq %rbx, %rdi
callq 0x138f0
nop