// File: /workspace/github_cpp_makefile_star2_O1/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 0xc2368
xorl %ebp, %ebp
movq %r13, %rdi
xorl %esi, %esi
callq 0x15a20
movq 0x8(%r12), %rdi
movq %r15, %rsi
callq 0x3aaf0
testq %rax, %rax
je 0x1c7e0
movq %rax, %r13
movq %r12, %rdi
movq %r14, %rsi
callq 0x42dac
testq %rax, %rax
je 0x1c7ec
movq %rax, %rbp
movq %r12, %rdi
movq %rbx, %rsi
callq 0x42e6e
testq %rax, %rax
je 0x1c7fa
movq %rax, %r14
movl $0x1f0, %edi            # imm = 0x1F0
callq 0x15610
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x426c0
movq (%rbx), %rax
leaq 0xfabb6(%rip), %rcx     # 0x117273
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %r15
movq %r15, %rdx
movq %rcx, %r8
callq *0xe8(%rax)
testl %eax, %eax
je 0x1c81e
movq (%r12), %rax
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r14, %rcx
movq %r13, %r8
callq *0xd0(%rax)
cmpl $0x0, 0x1526ce(%rip)    # 0x16edcc
je 0x1c7bc
leaq 0xed398(%rip), %rdi     # 0x109aa3
movq 0x8(%rsp), %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x15080
leaq 0x18(%rsp), %rdi
callq 0xc23ca
leaq 0xece8e(%rip), %rdi     # 0x1095b9
movb $0x1, %al
callq 0x15080
movl 0x1c(%rbx), %esi
leaq 0xecf22(%rip), %rdi     # 0x10965e
xorl %eax, %eax
callq 0x15080
movl 0x2c(%rbx), %esi
leaq 0xecf23(%rip), %rdi     # 0x109670
xorl %eax, %eax
callq 0x15080
movl 0x7c(%rbx), %esi
leaq 0xecf23(%rip), %rdi     # 0x109681
xorl %eax, %eax
callq 0x15080
movq 0x8(%rbx), %rax
movl 0x24(%rax), %esi
leaq 0xecf58(%rip), %rdi     # 0x1096cb
xorl %eax, %eax
callq 0x15080
movq 0x8(%rbx), %rax
movq 0x10(%rax), %rax
movl 0x4c(%rax), %esi
leaq 0xecf4f(%rip), %rdi     # 0x1096db
xorl %eax, %eax
callq 0x15080
movq 0x8(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x50(%rax), %rsi
leaq 0xecf46(%rip), %rdi     # 0x1096ec
xorl %eax, %eax
callq 0x15080
movq 0x1517ac(%rip), %rax    # 0x16df60
movq (%rax), %rdi
callq 0x15760
movq (%rbx), %rax
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq *0xf8(%rax)
testl %eax, %eax
je 0x1c80d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movl $0x1, %ebp
jmp 0x1c80d
leaq 0xecf2c(%rip), %rdi     # 0x109713
movq %r15, %rsi
jmp 0x1c806
leaq 0xecf49(%rip), %rdi     # 0x10973c
xorl %ebp, %ebp
movq %r14, %rsi
jmp 0x1c806
leaq 0xecf75(%rip), %rdi     # 0x109776
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0xc5782
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 0x1c80d
movq %rax, %r14
movl $0x1f0, %esi            # imm = 0x1F0
movq %rbx, %rdi
callq 0x15620
movq %r14, %rdi
callq 0x15ae0