// File: /workspace/github_cpp_makefile_star2_O1/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 0xc2368
xorl %ebx, %ebx
movq %rbp, %rdi
xorl %esi, %esi
callq 0x15a20
movq 0x8(%r14), %r14
testq %r14, %r14
je 0x1e844
leaq 0xeb2eb(%rip), %rsi     # 0x109afb
movq %r15, %rdi
callq 0x158c0
testl %eax, %eax
je 0x1e857
movq %r14, %rdi
movq %r15, %rsi
callq 0x3aaf0
testq %rax, %rax
jne 0x1e859
leaq 0xeb2cc(%rip), %rdi     # 0x109aff
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0xc5782
jmp 0x1e941
leaq 0xeb279(%rip), %rdi     # 0x109ac4
xorl %eax, %eax
callq 0xc5782
jmp 0x1e941
xorl %eax, %eax
movq (%r14), %r9
movq %r14, %rdi
testq %rax, %rax
je 0x1e8b3
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, 0x150532(%rip)    # 0x16edcc
je 0x1e941
leaq 0xeb47e(%rip), %rdi     # 0x109d25
movq %r15, %rsi
xorl %eax, %eax
callq 0x15080
jmp 0x1e8f3
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(%r9)
movl $0x1, %ebx
cmpl $0x0, 0x1504e7(%rip)    # 0x16edcc
je 0x1e941
leaq 0xeb5f5(%rip), %rdi     # 0x109ee3
callq 0x15980
leaq 0x28(%rsp), %rdi
callq 0xc23ca
leaq 0xeacb5(%rip), %rdi     # 0x1095b9
movb $0x1, %al
callq 0x15080
movl 0x24(%r14), %esi
leaq 0xeadb5(%rip), %rdi     # 0x1096cb
xorl %eax, %eax
callq 0x15080
movq 0x10(%r14), %rax
movl 0x4c(%rax), %esi
leaq 0xeadb0(%rip), %rdi     # 0x1096db
xorl %eax, %eax
callq 0x15080
movq 0x14f627(%rip), %rax    # 0x16df60
movq (%rax), %rdi
callq 0x15760
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq