// File: /workspace/github_cpp_makefile_star2_O2/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, %ebx
movsd %xmm3, 0x20(%rsp)
movsd %xmm2, 0x18(%rsp)
movsd %xmm1, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movl %ecx, %ebp
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %r14
leaq 0x28(%rsp), %r13
movq %r13, %rdi
callq 0xaf4d6
movq %r13, %rdi
callq 0x1d806
movq 0x8(%r14), %r14
testq %r14, %r14
je 0x1d5f0
leaq 0xcf561(%rip), %rsi     # 0xecae1
movq %r15, %rdi
callq 0x158e0
testl %eax, %eax
je 0x1d605
movq %r14, %rdi
movq %r15, %rsi
callq 0x36436
testq %rax, %rax
je 0x1d695
movq (%r14), %r9
movq %r14, %rdi
movq %rax, %rsi
movl %r12d, %edx
movl %ebp, %ecx
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movsd 0x20(%rsp), %xmm3
movl %ebx, %r8d
callq *0x18(%r9)
pushq $0x1
popq %rbx
cmpl $0x0, 0x13c805(%rip)    # 0x159ddc
je 0x1d6a8
leaq 0xcf727(%rip), %rdi     # 0xecd0b
movq %r15, %rsi
xorl %eax, %eax
callq 0x15080
jmp 0x1d645
leaq 0xcf4b3(%rip), %rdi     # 0xecaaa
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xb2096
jmp 0x1d6a8
movq (%r14), %rax
movq %r14, %rdi
movl %r12d, %esi
movl %ebp, %edx
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movsd 0x20(%rsp), %xmm3
movl %ebx, %ecx
callq *0x20(%rax)
pushq $0x1
popq %rbx
cmpl $0x0, 0x13c7a5(%rip)    # 0x159ddc
je 0x1d6a8
leaq 0xcf889(%rip), %rdi     # 0xecec9
callq 0x15990
leaq 0x28(%rsp), %rdi
callq 0xaf510
leaq 0xcef4b(%rip), %rdi     # 0xec5a1
movb $0x1, %al
callq 0x15080
movl 0x24(%r14), %esi
leaq 0xcf04b(%rip), %rdi     # 0xec6b3
xorl %eax, %eax
callq 0x15080
movq 0x10(%r14), %rax
movl 0x4c(%rax), %esi
leaq 0xcf046(%rip), %rdi     # 0xec6c3
xorl %eax, %eax
callq 0x15080
movq 0x13b8f5(%rip), %rax    # 0x158f80
movq (%rax), %rdi
callq 0x15750
jmp 0x1d6a8
leaq 0xcf449(%rip), %rdi     # 0xecae5
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0xb2096
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq