// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/apps/sflprocess/sflprocess.cpp
// Function: CreateMultiresolutionBlocks(gaps::R3SurfelScene*, char const*, double, double)
static int
CreateMultiresolutionBlocks(R3SurfelScene *scene, const char *node_name,
  RNScalar multiresolution_factor, RNScalar max_node_complexity)
{
  // 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) {
    // Create multiresolution starting at node
    tree->CreateMultiresolutionBlocks(node, multiresolution_factor, max_node_complexity);

    // Print statistics
    if (print_verbose) {
      printf("Created multiresolution blocks for 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 {
    // Create multiresolution starting at all root nodes
    tree->CreateMultiresolutionBlocks(multiresolution_factor, max_node_complexity);

    // Print statistics
    if (print_verbose) {
      printf("Created multiresolution blocks for 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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
movsd %xmm1, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movq %rsi, %r15
movq %rdi, %r14
leaq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0xc2368
xorl %ebx, %ebx
movq %r12, %rdi
xorl %esi, %esi
callq 0x15a20
movq 0x8(%r14), %r14
testq %r14, %r14
je 0x1e9cc
leaq 0xeb163(%rip), %rsi     # 0x109afb
movq %r15, %rdi
callq 0x158c0
testl %eax, %eax
je 0x1e9df
movq %r14, %rdi
movq %r15, %rsi
callq 0x3aaf0
testq %rax, %rax
jne 0x1e9e1
leaq 0xeb144(%rip), %rdi     # 0x109aff
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0xc5782
jmp 0x1eaa0
leaq 0xeb0f1(%rip), %rdi     # 0x109ac4
xorl %eax, %eax
callq 0xc5782
jmp 0x1eaa0
xorl %eax, %eax
movq (%r14), %rcx
testq %rax, %rax
je 0x1ea26
xorps %xmm2, %xmm2
movq %r14, %rdi
movq %rax, %rsi
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq *0x60(%rcx)
movl $0x1, %ebx
cmpl $0x0, 0x1503bf(%rip)    # 0x16edcc
je 0x1eaa0
leaq 0xeb32b(%rip), %rdi     # 0x109d45
movq %r15, %rsi
xorl %eax, %eax
callq 0x15080
jmp 0x1ea52
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq *0x68(%rcx)
movl $0x1, %ebx
cmpl $0x0, 0x150388(%rip)    # 0x16edcc
je 0x1eaa0
leaq 0xeb4ab(%rip), %rdi     # 0x109ef8
callq 0x15980
leaq 0x18(%rsp), %rdi
callq 0xc23ca
leaq 0xeab56(%rip), %rdi     # 0x1095b9
movb $0x1, %al
callq 0x15080
movl 0x24(%r14), %esi
leaq 0xeac56(%rip), %rdi     # 0x1096cb
xorl %eax, %eax
callq 0x15080
movq 0x10(%r14), %rax
movl 0x4c(%rax), %esi
leaq 0xeac51(%rip), %rdi     # 0x1096db
xorl %eax, %eax
callq 0x15080
movq 0x14f4c8(%rip), %rax    # 0x16df60
movq (%rax), %rdi
callq 0x15760
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq