// File: tomfunkhouser[P]gaps/apps/gapsview/gapsview.cpp
// Function: OpenSFLFiles(char const*, char const*)
static R3SurfelScene *
OpenSFLFiles(const char *scene_filename, const char *database_filename)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

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

  // Open scene files
  if (!scene->OpenFile(scene_filename, database_filename, "r", "r")) {
    delete scene;
    return NULL;
  }

  // Read all surfels into memory
  scene->ReadBlocks();
  
  // Print statistics
  if (print_verbose) {
    printf("Opened sfl scene from %s ...\n", scene_filename);
    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("  # Images = %d\n", scene->NImages());
    printf("  # Nodes = %d\n", scene->Tree()->NNodes());
    printf("  # Surfels = %lld\n", scene->Tree()->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 0x1c7070
movq 0x8(%rsp), %rdi
callq 0x38bc0
movl $0x1f0, %edi            # imm = 0x1F0
callq 0x292e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x6f690
jmp 0x37357
movq 0x10(%rsp), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x373a7
leaq 0x22f478(%rip), %rdi    # 0x2667e8
movb $0x0, %al
callq 0x1cbff0
movq $0x0, 0x50(%rsp)
jmp 0x37503
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x20(%rsp)
movl %eax, 0x1c(%rsp)
movl $0x1f0, %esi            # imm = 0x1F0
callq 0x291f0
jmp 0x3750d
movq 0x28(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq (%rdi), %rax
leaq 0x24c033(%rip), %r8     # 0x2833f3
movq %r8, %rcx
callq *0xe8(%rax)
cmpl $0x0, %eax
jne 0x373f5
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x373e7
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x50(%rsp)
jmp 0x37503
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x160(%rax)
cmpl $0x0, 0x2c78b2(%rip)    # 0x2fecbc
je 0x374f9
movq 0x48(%rsp), %rsi
leaq 0x22f3ea(%rip), %rdi    # 0x266806
movb $0x0, %al
callq 0x290f0
leaq 0x30(%rsp), %rdi
callq 0x1c7130
leaq 0x22ef94(%rip), %rdi    # 0x2663c8
movb $0x1, %al
callq 0x290f0
movq 0x28(%rsp), %rdi
callq 0x3a8c0
movl %eax, %esi
leaq 0x22f3d6(%rip), %rdi    # 0x266824
movb $0x0, %al
callq 0x290f0
movq 0x28(%rsp), %rdi
callq 0x3a8e0
movl %eax, %esi
leaq 0x22f3ce(%rip), %rdi    # 0x266836
movb $0x0, %al
callq 0x290f0
movq 0x28(%rsp), %rdi
callq 0x3a900
movl %eax, %esi
leaq 0x22f3c5(%rip), %rdi    # 0x266847
movb $0x0, %al
callq 0x290f0
movq 0x28(%rsp), %rdi
callq 0x39850
movl %eax, %esi
leaq 0x22f3c1(%rip), %rdi    # 0x26685d
movb $0x0, %al
callq 0x290f0
movq 0x28(%rsp), %rdi
callq 0x394e0
movq %rax, %rdi
callq 0x394f0
movl %eax, %esi
leaq 0x22f1c6(%rip), %rdi    # 0x266684
movb $0x0, %al
callq 0x290f0
movq 0x28(%rsp), %rdi
callq 0x394e0
movq %rax, %rdi
xorl %esi, %esi
callq 0x3a920
movq %rax, %rsi
leaq 0x22f38b(%rip), %rdi    # 0x26686e
movb $0x0, %al
callq 0x290f0
movq 0x2b7ad7(%rip), %rax    # 0x2eefc8
movq (%rax), %rdi
callq 0x29910
movq 0x28(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
movq 0x20(%rsp), %rdi
callq 0x29c10
nopw (%rax,%rax)