// File: tomfunkhouser[P]gaps/apps/sflinit/sflinit.cpp
// Function: OpenScene(char const*, char const*)
static R3SurfelScene *
OpenScene(const char *scene_name, const char *database_name)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

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

  // Open surfel scene files
  if (!scene->OpenFile(scene_name, database_name, "w", "w")) {
    delete scene;
    return NULL;
  }

  // Print statistics
  if (print_verbose) {
    printf("Opened scene ...\n");
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Objects = %d\n", scene->NObjects());
    printf("  # Labels = %d\n", scene->NLabels());
    printf("  # Assignments = %d\n", scene->NLabelAssignments());
    printf("  # Features = %d\n", scene->NFeatures());
    printf("  # Scans = %d\n", scene->NScans());
    printf("  # Images = %d\n", scene->NImages());
    printf("  # Nodes = %d\n", scene->Tree()->NNodes());
    printf("  # Blocks = %d\n", scene->Tree()->Database()->NBlocks());
    printf("  # Surfels = %lld\n", scene->Tree()->Database()->NSurfels());
    fflush(stdout);
  }

  // Return scene
  return scene;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
leaq 0x30(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x141530
movq 0x8(%rsp), %rdi
callq 0x16c00
movl $0x1f0, %edi            # imm = 0x1F0
callq 0x13570
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x1c460
jmp 0x16857
movq 0x10(%rsp), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x168a7
leaq 0x18d7e5(%rip), %rdi    # 0x1a4055
movb $0x0, %al
callq 0x1464b0
movq $0x0, 0x50(%rsp)
jmp 0x16a54
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x20(%rsp)
movl %eax, 0x1c(%rsp)
movl $0x1f0, %esi            # imm = 0x1F0
callq 0x13580
jmp 0x16a5e
movq 0x28(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq (%rdi), %rax
leaq 0x19063e(%rip), %r8     # 0x1a6efe
movq %r8, %rcx
callq *0xe8(%rax)
cmpl $0x0, %eax
jne 0x168f5
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x168e7
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x50(%rsp)
jmp 0x16a54
cmpl $0x0, 0x1e5cdc(%rip)    # 0x1fc5d8
je 0x16a4a
leaq 0x18d766(%rip), %rdi    # 0x1a406f
movb $0x0, %al
callq 0x13070
leaq 0x30(%rsp), %rdi
callq 0x1415f0
leaq 0x18d760(%rip), %rdi    # 0x1a4081
movb $0x1, %al
callq 0x13070
movq 0x28(%rsp), %rdi
callq 0x16c20
movl %eax, %esi
leaq 0x18d75d(%rip), %rdi    # 0x1a4098
movb $0x0, %al
callq 0x13070
movq 0x28(%rsp), %rdi
callq 0x16c40
movl %eax, %esi
leaq 0x18d755(%rip), %rdi    # 0x1a40aa
movb $0x0, %al
callq 0x13070
movq 0x28(%rsp), %rdi
callq 0x16c60
movl %eax, %esi
leaq 0x18d74c(%rip), %rdi    # 0x1a40bb
movb $0x0, %al
callq 0x13070
movq 0x28(%rsp), %rdi
callq 0x16c80
movl %eax, %esi
leaq 0x18d748(%rip), %rdi    # 0x1a40d1
movb $0x0, %al
callq 0x13070
movq 0x28(%rsp), %rdi
callq 0x16ca0
movl %eax, %esi
leaq 0x18d741(%rip), %rdi    # 0x1a40e4
movb $0x0, %al
callq 0x13070
movq 0x28(%rsp), %rdi
callq 0x16cc0
movl %eax, %esi
leaq 0x18d737(%rip), %rdi    # 0x1a40f4
movb $0x0, %al
callq 0x13070
movq 0x28(%rsp), %rdi
callq 0x16ce0
movq %rax, %rdi
callq 0x16cf0
movl %eax, %esi
leaq 0x18d726(%rip), %rdi    # 0x1a4105
movb $0x0, %al
callq 0x13070
movq 0x28(%rsp), %rdi
callq 0x16ce0
movq %rax, %rdi
callq 0x16d10
movq %rax, %rdi
callq 0x16d20
movl %eax, %esi
leaq 0x18d70c(%rip), %rdi    # 0x1a4115
movb $0x0, %al
callq 0x13070
movq 0x28(%rsp), %rdi
callq 0x16ce0
movq %rax, %rdi
callq 0x16d10
movq %rax, %rdi
callq 0x16d40
movq %rax, %rsi
leaq 0x18d6f2(%rip), %rdi    # 0x1a4126
movb $0x0, %al
callq 0x13070
movq 0x1dc54e(%rip), %rax    # 0x1f2f90
movq (%rax), %rdi
callq 0x13680
movq 0x28(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
movq 0x20(%rsp), %rdi
callq 0x13970
nopl (%rax,%rax)