// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/apps/sflprocess/sflprocess.cpp
// Function: SplitSurfelTreeNodes(gaps::R3SurfelScene*, char const*, int, int, double, double, double, double, int)
static int
SplitSurfelTreeNodes(R3SurfelScene *scene, const char *node_name,
  int max_parts_per_node, int max_blocks_per_node, 
  RNScalar max_node_complexity, RNScalar max_block_complexity,
  RNLength max_leaf_extent, RNLength max_block_extent, 
  int max_levels)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Get surfel tree
  R3SurfelTree *tree = scene->Tree();
  if (!tree) {
    RNFail("Scene has no surfel tree\n");
    return 0;
  }    

  // Find node
  R3SurfelNode *node = NULL;
  if (strcmp(node_name, "All")) {
    node = tree->FindNodeByName(node_name);
    if (!node) {
      RNFail("Unable to find node with name %s\n", node_name);
      return 0;
    }
  }

  // Check node
  if (node) {
    // Split nodes
    tree->SplitNodes(node,
      max_parts_per_node, max_blocks_per_node, 
      max_node_complexity, max_block_complexity, 
      max_leaf_extent, max_block_extent, 
      max_levels);

    // Print statistics
    if (print_verbose) {
      printf("Split nodes starting at %s ...\n", node_name);
      printf("  Time = %.2f seconds\n", start_time.Elapsed());
      printf("  # Nodes = %d\n", tree->NNodes());
      printf("  # Blocks = %d\n", tree->Database()->NBlocks());
      fflush(stdout);
    }
  }
  else {
    // Split nodes
    tree->SplitNodes(
      max_parts_per_node, max_blocks_per_node, 
      max_node_complexity, max_block_complexity, 
      max_leaf_extent, max_block_extent, 
      max_levels);

    // Print statistics
    if (print_verbose) {
      printf("Split all nodes  ...\n");
      printf("  Time = %.2f seconds\n", start_time.Elapsed());
      printf("  # Nodes = %d\n", tree->NNodes());
      printf("  # Blocks = %d\n", tree->Database()->NBlocks());
      fflush(stdout);
    }
  }

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, 0x4(%rsp)
movsd %xmm3, 0x20(%rsp)
movsd %xmm2, 0x18(%rsp)
movsd %xmm1, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movl %ecx, %r12d
movl %edx, %r13d
movq %rsi, %r15
movq %rdi, %r14
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
callq 0xc0cf4
xorl %ebx, %ebx
movq %rbp, %rdi
xorl %esi, %esi
callq 0x15a10
movq 0x8(%r14), %r14
testq %r14, %r14
je 0x1e5f7
leaq 0xe9570(%rip), %rsi     # 0x107af2
movq %r15, %rdi
callq 0x158b0
testl %eax, %eax
je 0x1e60a
movq %r14, %rdi
movq %r15, %rsi
callq 0x3a6a0
testq %rax, %rax
je 0x1e69f
movq (%r14), %r9
movq %r14, %rdi
movq %rax, %rsi
movl %r13d, %edx
movl %r12d, %ecx
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movsd 0x20(%rsp), %xmm3
movl 0x4(%rsp), %r8d
callq *0x18(%r9)
movl $0x1, %ebx
cmpl $0x0, 0x14e7de(%rip)    # 0x16cdbc
je 0x1e6b2
leaq 0xe9731(%rip), %rdi     # 0x107d1c
movq %r15, %rsi
xorl %eax, %eax
callq 0x15080
jmp 0x1e64f
leaq 0xe94bd(%rip), %rdi     # 0x107abb
xorl %eax, %eax
callq 0xc3e02
jmp 0x1e6b2
movq (%r14), %rax
movq %r14, %rdi
movl %r13d, %esi
movl %r12d, %edx
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movsd 0x20(%rsp), %xmm3
movl 0x4(%rsp), %ecx
callq *0x20(%rax)
movl $0x1, %ebx
cmpl $0x0, 0x14e77b(%rip)    # 0x16cdbc
je 0x1e6b2
leaq 0xe9890(%rip), %rdi     # 0x107eda
callq 0x15970
leaq 0x28(%rsp), %rdi
callq 0xc0d56
leaq 0xe8f52(%rip), %rdi     # 0x1075b2
movb $0x1, %al
callq 0x15080
movl 0x24(%r14), %esi
leaq 0xe9052(%rip), %rdi     # 0x1076c4
xorl %eax, %eax
callq 0x15080
movq 0x10(%r14), %rax
movl 0x4c(%rax), %esi
leaq 0xe904d(%rip), %rdi     # 0x1076d4
xorl %eax, %eax
callq 0x15080
movq 0x14d8cb(%rip), %rax    # 0x16bf60
movq (%rax), %rdi
callq 0x15750
jmp 0x1e6b2
leaq 0xe9450(%rip), %rdi     # 0x107af6
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0xc3e02
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq