// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x20, %rsp
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, (%rsp)
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0xaf4d6
movq %r14, %rdi
callq 0x1d806
movq 0x8(%rbx), %r14
testq %r14, %r14
je 0x1d755
leaq 0xcf3e9(%rip), %rsi     # 0xecae1
movq %r15, %rdi
callq 0x158e0
testl %eax, %eax
je 0x1d76a
movq %r14, %rdi
movq %r15, %rsi
callq 0x36436
testq %rax, %rax
je 0x1d7e6
movq (%r14), %rcx
xorps %xmm2, %xmm2
movq %r14, %rdi
movq %rax, %rsi
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq *0x60(%rcx)
pushq $0x1
popq %rbx
cmpl $0x0, 0x13c6a0(%rip)    # 0x159ddc
je 0x1d7f9
leaq 0xcf5e2(%rip), %rdi     # 0xecd2b
movq %r15, %rsi
xorl %eax, %eax
callq 0x15080
jmp 0x1d796
leaq 0xcf34e(%rip), %rdi     # 0xecaaa
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xb2096
jmp 0x1d7f9
movq (%r14), %rax
movq %r14, %rdi
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq *0x68(%rax)
pushq $0x1
popq %rbx
cmpl $0x0, 0x13c654(%rip)    # 0x159ddc
je 0x1d7f9
leaq 0xcf74d(%rip), %rdi     # 0xecede
callq 0x15990
leaq 0x10(%rsp), %rdi
callq 0xaf510
leaq 0xcedfa(%rip), %rdi     # 0xec5a1
movb $0x1, %al
callq 0x15080
movl 0x24(%r14), %esi
leaq 0xceefa(%rip), %rdi     # 0xec6b3
xorl %eax, %eax
callq 0x15080
movq 0x10(%r14), %rax
movl 0x4c(%rax), %esi
leaq 0xceef5(%rip), %rdi     # 0xec6c3
xorl %eax, %eax
callq 0x15080
movq 0x13b7a4(%rip), %rax    # 0x158f80
movq (%rax), %rdi
callq 0x15750
jmp 0x1d7f9
leaq 0xcf2f8(%rip), %rdi     # 0xecae5
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0xb2096
movl %ebx, %eax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop