// File: 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:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movq %rsi, 0x80(%rsp)
movq %rdx, 0x78(%rsp)
movq %rcx, 0x70(%rsp)
movq %r8, 0x68(%rsp)
movq %r9, 0x60(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x16dd30
leaq 0x50(%rsp), %rdi
callq 0x263f0
movq 0x88(%rsp), %rdi
callq 0x26780
movq %rax, %rdi
movq 0x60(%rsp), %rsi
callq 0x60280
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
jne 0x21af9
movq 0x60(%rsp), %rsi
leaq 0x1d6c23(%rip), %rdi    # 0x1f8705
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0x94(%rsp)
jmp 0x21dc7
movq 0x88(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x70d50
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x21b3b
movq 0x70(%rsp), %rsi
leaq 0x1d6c23(%rip), %rdi    # 0x1f8747
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0x94(%rsp)
jmp 0x21dc7
movq 0x88(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x70ea0
movq %rax, 0x38(%rsp)
cmpq $0x0, 0x38(%rsp)
jne 0x21b7d
movq 0x68(%rsp), %rsi
leaq 0x1d6c36(%rip), %rdi    # 0x1f879c
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0x94(%rsp)
jmp 0x21dc7
movl $0x1f0, %edi            # imm = 0x1F0
callq 0x16740
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x6fe50
jmp 0x21b9d
movq 0x18(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x21bef
leaq 0x1d6a58(%rip), %rdi    # 0x1f860e
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0x94(%rsp)
jmp 0x21dc7
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x28(%rsp)
movl %eax, 0x24(%rsp)
movl $0x1f0, %esi            # imm = 0x1F0
callq 0x16750
jmp 0x21dd6
movq 0x30(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq (%rdi), %rax
leaq 0x1e05c8(%rip), %r8     # 0x2021d3
movq %r8, %rcx
callq *0xe8(%rax)
cmpl $0x0, %eax
jne 0x21c44
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x21c34
movq 0x10(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x0, 0x94(%rsp)
jmp 0x21dc7
movq 0x88(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq 0x48(%rsp), %r8
movq (%rdi), %rax
callq *0xd0(%rax)
cmpl $0x0, 0x242b50(%rip)    # 0x2647c0
je 0x21d7d
movq 0x80(%rsp), %rsi
movq 0x78(%rsp), %rdx
leaq 0x1d6eb3(%rip), %rdi    # 0x1f8b3d
movb $0x0, %al
callq 0x16090
leaq 0x50(%rsp), %rdi
callq 0x16ddf0
leaq 0x1d68dd(%rip), %rdi    # 0x1f857f
movb $0x1, %al
callq 0x16090
movq 0x30(%rsp), %rdi
callq 0x266c0
movl %eax, %esi
leaq 0x1d6994(%rip), %rdi    # 0x1f8650
movb $0x0, %al
callq 0x16090
movq 0x30(%rsp), %rdi
callq 0x266e0
movl %eax, %esi
leaq 0x1d698c(%rip), %rdi    # 0x1f8662
movb $0x0, %al
callq 0x16090
movq 0x30(%rsp), %rdi
callq 0x26700
movl %eax, %esi
leaq 0x1d6983(%rip), %rdi    # 0x1f8673
movb $0x0, %al
callq 0x16090
movq 0x30(%rsp), %rdi
callq 0x26780
movq %rax, %rdi
callq 0x26330
movl %eax, %esi
leaq 0x1d69ab(%rip), %rdi    # 0x1f86bd
movb $0x0, %al
callq 0x16090
movq 0x30(%rsp), %rdi
callq 0x26780
movq %rax, %rdi
callq 0x26790
movq %rax, %rdi
callq 0x267a0
movl %eax, %esi
leaq 0x1d6991(%rip), %rdi    # 0x1f86cd
movb $0x0, %al
callq 0x16090
movq 0x30(%rsp), %rdi
callq 0x26780
movq %rax, %rdi
callq 0x26790
movq %rax, %rdi
callq 0x267c0
movq %rax, %rsi
leaq 0x1d6977(%rip), %rdi    # 0x1f86de
movb $0x0, %al
callq 0x16090
movq 0x23921b(%rip), %rax    # 0x25af90
movq (%rax), %rdi
callq 0x168c0
movq 0x30(%rsp), %rdi
movq (%rdi), %rax
xorl %ecx, %ecx
movl %ecx, %esi
callq *0xf8(%rax)
cmpl $0x0, %eax
jne 0x21da1
movl $0x0, 0x94(%rsp)
jmp 0x21dc7
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x21dbc
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x1, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq
movq 0x28(%rsp), %rdi
callq 0x16ca0