// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/apps/sflprocess/sflprocess.cpp
// Function: LoadScene(gaps::R3SurfelScene*, char const*, char const*, char const*, char const*, char const*)
static int
LoadScene(R3SurfelScene *scene1, 
  const char *scene_filename, const char *database_filename, 
  const char *parent_object_name, const char *parent_label_name, const char *parent_node_name)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Find parent surfel tree node in scene1
  R3SurfelNode *parent_node = scene1->Tree()->FindNodeByName(parent_node_name);
  if (!parent_node) {
    RNFail("Unable to find parent node with name %s\n", parent_node_name);
    return 0;
  }

  // Find parent object in scene1
  R3SurfelObject *parent_object = scene1->FindObjectByName(parent_object_name);
  if (!parent_object) {
    RNFail("Unable to find parent object with name %s\n", parent_object_name);
    return 0;
  }

  // Find parent label in scene1
  R3SurfelLabel *parent_label = scene1->FindLabelByName(parent_label_name);
  if (!parent_label) {
    RNFail("Unable to find parent label with name %s\n", parent_label_name);
    return 0;
  }

  // Allocate scene2
  R3SurfelScene *scene2 = new R3SurfelScene();
  if (!scene2) {
    RNFail("Unable to allocate scene\n");
    return 0;
  }

  // Open scene2
  if (!scene2->OpenFile(scene_filename, database_filename, "r", "r")) {
    delete scene2;
    return 0;
  }

  // Insert scene2 into scene1
  scene1->InsertScene(*scene2, parent_object, parent_label, parent_node);

  // Print statistics
  if (print_verbose) {
    printf("Loaded scene from %s and %s ...\n", scene_filename, database_filename);
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Objects = %d\n", scene2->NObjects());
    printf("  # Labels = %d\n", scene2->NLabels());
    printf("  # Assignments = %d\n", scene2->NLabelAssignments());
    printf("  # Nodes = %d\n", scene2->Tree()->NNodes());
    printf("  # Blocks = %d\n", scene2->Tree()->Database()->NBlocks());
    printf("  # Surfels = %lld\n", scene2->Tree()->Database()->NSurfels());
    fflush(stdout);
  }

  // Close scene
  if (!scene2->CloseFile()) return 0;

  // Delete scene
  delete scene2;

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r15
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, %r12
leaq 0x18(%rsp), %r13
movq %r13, %rdi
callq 0xc0cf4
xorl %ebp, %ebp
movq %r13, %rdi
xorl %esi, %esi
callq 0x15a10
movq 0x8(%r12), %rdi
movq %r15, %rsi
callq 0x3a6a0
testq %rax, %rax
je 0x1c53a
movq %rax, %r13
movq %r12, %rdi
movq %r14, %rsi
callq 0x428ca
testq %rax, %rax
je 0x1c546
movq %rax, %rbp
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4296e
testq %rax, %rax
je 0x1c554
movq %rax, %r14
movl $0x1f0, %edi            # imm = 0x1F0
callq 0x15610
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x421dc
movq (%rbx), %rax
leaq 0xf8e5c(%rip), %rcx     # 0x115273
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %r15
movq %r15, %rdx
movq %rcx, %r8
callq *0xe8(%rax)
testl %eax, %eax
je 0x1c578
movq (%r12), %rax
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r14, %rcx
movq %r13, %r8
callq *0xd0(%rax)
cmpl $0x0, 0x150964(%rip)    # 0x16cdbc
je 0x1c516
leaq 0xeb635(%rip), %rdi     # 0x107a9a
movq 0x8(%rsp), %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x15080
leaq 0x18(%rsp), %rdi
callq 0xc0d56
leaq 0xeb12d(%rip), %rdi     # 0x1075b2
movb $0x1, %al
callq 0x15080
movl 0x1c(%rbx), %esi
leaq 0xeb1c1(%rip), %rdi     # 0x107657
xorl %eax, %eax
callq 0x15080
movl 0x2c(%rbx), %esi
leaq 0xeb1c2(%rip), %rdi     # 0x107669
xorl %eax, %eax
callq 0x15080
movl 0x7c(%rbx), %esi
leaq 0xeb1c2(%rip), %rdi     # 0x10767a
xorl %eax, %eax
callq 0x15080
movq 0x8(%rbx), %rax
movl 0x24(%rax), %esi
leaq 0xeb1f7(%rip), %rdi     # 0x1076c4
xorl %eax, %eax
callq 0x15080
movq 0x8(%rbx), %rax
movq 0x10(%rax), %rax
movl 0x4c(%rax), %esi
leaq 0xeb1ee(%rip), %rdi     # 0x1076d4
xorl %eax, %eax
callq 0x15080
movq 0x8(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x50(%rax), %rsi
leaq 0xeb1e5(%rip), %rdi     # 0x1076e5
xorl %eax, %eax
callq 0x15080
movq 0x14fa52(%rip), %rax    # 0x16bf60
movq (%rax), %rdi
callq 0x15750
movq (%rbx), %rax
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq *0xf8(%rax)
testl %eax, %eax
je 0x1c567
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movl $0x1, %ebp
jmp 0x1c567
leaq 0xeb1cb(%rip), %rdi     # 0x10770c
movq %r15, %rsi
jmp 0x1c560
leaq 0xeb1e8(%rip), %rdi     # 0x107735
xorl %ebp, %ebp
movq %r14, %rsi
jmp 0x1c560
leaq 0xeb214(%rip), %rdi     # 0x10776f
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0xc3e02
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
xorl %ebp, %ebp
jmp 0x1c567
movq %rax, %r14
movl $0x1f0, %esi            # imm = 0x1F0
movq %rbx, %rdi
callq 0x15620
movq %r14, %rdi
callq 0x15ad0