// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/GSV/GSVScene.cpp
// Function: gaps::GSVScene::ReadGSFFile(char const*, int)
int GSVScene::
ReadGSFFile(const char *filename, RNBoolean read_points)
{
  // Open file
  FILE *fp = fopen(filename, "r");
  if (!fp) {
    RNFail("Unable to open GSV scene file: %s\n", filename);
    return 0;
  }

  // Read run names from file
  int line_count = 0;
  const int buffer_size = 16*1024;
  char buffer[buffer_size];
  while (fgets(buffer, buffer_size, fp)) {
    line_count++;
    if (buffer[0] == '\0') continue;
    if (buffer[0] == '#') continue;

    // Parse command keyword
    char cmd[4096];
    if (sscanf(buffer, "%s", cmd) != (unsigned int) 1) {
      RNFail("Unable to read command from line %d of %s\n", line_count, filename);
      return 0;
    }

    // Parse rest of command
    if (!strcmp(cmd, "raw_data")) {
      // Parse directory name
      char directory_name[1024];
      if (sscanf(buffer, "%s%s", cmd, directory_name) != (unsigned int) 2) {
        RNFail("Unable to read scan_directory from line %d of %s\n", line_count, filename);
        return 0;
      }

      // Set directory name
      SetRawDataDirectoryName(directory_name);
    }
    else if (!strcmp(cmd, "cache_data")) {
      // Parse directory name
      char directory_name[1024];
      if (sscanf(buffer, "%s%s", cmd, directory_name) != (unsigned int) 2) {
        RNFail("Unable to read scan_directory from line %d of %s\n", line_count, filename);
        return 0;
      }

      // Set directory name
      SetCacheDataDirectoryName(directory_name);
    }
    else if (!strcmp(cmd, "run")) {
      // Parse run name
      char run_name[4096];
      if (sscanf(buffer, "%s%s", cmd, run_name) != (unsigned int) 2) {
        RNFail("Unable to read run name from line %d of %s\n", line_count, filename);
        return 0;
      }

      // Create run
      GSVRun *run = new GSVRun(run_name);
      InsertRun(run);
      
      // Read camera info
      if (!run->ReadCameraInfoFile()) return 0;
      
      // Read image info
      RNArray<GSVPanorama *> panoramas;
      if (!run->ReadImageSegmentFile(panoramas)) return 0;
      if (!run->ReadImagePoseFile(panoramas)) return 0;

      // Read laser stuff
      const int max_laser_index = 2;
      for (int laser_index = 0; laser_index <= max_laser_index; laser_index++) {
        RNArray<GSVScanline *> scanlines;
        RNArray<GSVScan *> scanline_scans;
        if (!run->ReadLaserObjFile(laser_index, scanlines, scanline_scans, read_points)) return 0;
        if (!run->ReadLaserPoseFile(laser_index, scanlines, scanline_scans)) return 0;
      }
    }
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x6068, %rsp           # imm = 0x6068
movl %edx, 0x1c(%rsp)
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
leaq 0x13aa51(%rip), %rsi    # 0x16e443
movq %r14, %rdi
callq 0x27b20
testq %rax, %rax
je 0x33cc5
movq %rax, %r15
movq %r14, 0x8(%rsp)
leaq 0x2060(%rsp), %rdi
movl $0x4000, %esi           # imm = 0x4000
movq %rax, %rdx
callq 0x27fc0
testq %rax, %rax
je 0x33cb6
movq 0x10(%rsp), %rax
leaq 0x8(%rax), %rbx
leaq 0x50(%rsp), %r14
xorl %eax, %eax
incl %eax
movl %eax, 0x4(%rsp)
movzbl 0x2060(%rsp), %eax
cmpl $0x23, %eax
je 0x33c94
testl %eax, %eax
je 0x33c94
leaq 0x2060(%rsp), %rdi
leaq 0x1366c4(%rip), %rsi    # 0x16a12b
leaq 0x60(%rsp), %rdx
xorl %eax, %eax
callq 0x27900
cmpl $0x1, %eax
jne 0x33cfa
movq 0x60(%rsp), %rax
movabsq $0x617461645f776172, %rcx # imm = 0x617461645F776172
xorq %rcx, %rax
movzbl 0x68(%rsp), %ecx
orq %rax, %rcx
je 0x33c1e
movq 0x60(%rsp), %rax
movabsq $0x61645f6568636163, %rcx # imm = 0x61645F6568636163
xorq %rcx, %rax
movq 0x63(%rsp), %rcx
movabsq $0x617461645f6568, %rdx # imm = 0x617461645F6568
xorq %rdx, %rcx
orq %rax, %rcx
je 0x33c5c
cmpl $0x6e7572, 0x60(%rsp)   # imm = 0x6E7572
jne 0x33c94
leaq 0x2060(%rsp), %rdi
leaq 0x11d084(%rip), %rsi    # 0x150b6a
leaq 0x60(%rsp), %rdx
leaq 0x1060(%rsp), %r13
movq %r13, %rcx
xorl %eax, %eax
callq 0x27900
cmpl $0x2, %eax
jne 0x33d0c
movl $0x90, %edi
callq 0x27930
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
callq 0x37b7c
movq 0x10(%rsp), %rax
movq %rax, 0x8(%r12)
movl 0x14(%rax), %edx
movl %edx, 0x10(%r12)
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf8c16
movq %r12, %rdi
callq 0x38328
testl %eax, %eax
je 0x33d23
leaq 0x20(%rsp), %r13
movq %r13, %rdi
callq 0xf8b80
movq %r12, %rdi
movq %r13, %rsi
callq 0x38728
testl %eax, %eax
je 0x33cee
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0x38980
testl %eax, %eax
je 0x33cee
movq %rbx, 0x30(%rsp)
xorl %r13d, %r13d
movq %r15, 0x38(%rsp)
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0xf8b80
movq %r14, %rdi
callq 0xf8b80
movq %r12, %rbp
movq %r12, %rdi
movl %r13d, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl 0x1c(%rsp), %r8d
callq 0x38d98
testl %eax, %eax
je 0x33cda
movq %r14, %r12
movq %rbp, %rdi
movl %r13d, %esi
leaq 0x40(%rsp), %r14
movq %r14, %rdx
movq %r12, %r15
movq %r12, %rcx
callq 0x393a4
movl %eax, %ebx
movq %r15, %rdi
callq 0xf8bea
movq %r14, %rdi
callq 0xf8bea
testl %ebx, %ebx
je 0x33cee
incl %r13d
cmpl $0x3, %r13d
movq %r12, %r14
movq 0x38(%rsp), %r15
movq %rbp, %r12
jne 0x33b8d
leaq 0x20(%rsp), %rdi
callq 0xf8bea
movq 0x30(%rsp), %rbx
jmp 0x33c94
leaq 0x2060(%rsp), %rdi
leaq 0x11cf3d(%rip), %rsi    # 0x150b6a
leaq 0x60(%rsp), %rdx
leaq 0x1060(%rsp), %r13
movq %r13, %rcx
xorl %eax, %eax
callq 0x27900
cmpl $0x2, %eax
jne 0x33d03
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x32f02
jmp 0x33c94
leaq 0x2060(%rsp), %rdi
leaq 0x11ceff(%rip), %rsi    # 0x150b6a
leaq 0x60(%rsp), %rdx
leaq 0x1060(%rsp), %r13
movq %r13, %rcx
xorl %eax, %eax
callq 0x27900
cmpl $0x2, %eax
jne 0x33d03
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x32f38
leaq 0x2060(%rsp), %rdi
movl $0x4000, %esi           # imm = 0x4000
movq %r15, %rdx
callq 0x27fc0
testq %rax, %rax
movl 0x4(%rsp), %eax
jne 0x33a39
movq %r15, %rdi
callq 0x27920
movl $0x1, %ebx
jmp 0x33d25
leaq 0x118e38(%rip), %rdi    # 0x14cb04
xorl %ebx, %ebx
movq %r14, %rsi
xorl %eax, %eax
callq 0xfb6f2
jmp 0x33d25
leaq 0x50(%rsp), %rdi
callq 0xf8bea
leaq 0x40(%rsp), %rdi
callq 0xf8bea
leaq 0x20(%rsp), %rdi
callq 0xf8bea
jmp 0x33d23
leaq 0x118e52(%rip), %rdi    # 0x14cb53
jmp 0x33d13
leaq 0x118e74(%rip), %rdi    # 0x14cb7e
jmp 0x33d13
leaq 0x118e14(%rip), %rdi    # 0x14cb27
movl 0x4(%rsp), %esi
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0xfb6f2
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x6068, %rsp           # imm = 0x6068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x90, %esi
movq %r12, %rdi
callq 0x27950
jmp 0x33d78
jmp 0x33d4d
movq %rax, %rbx
jmp 0x33d6e
movq %rax, %rbx
jmp 0x33d64
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0xf8bea
leaq 0x40(%rsp), %rdi
callq 0xf8bea
leaq 0x20(%rsp), %rdi
callq 0xf8bea
movq %rbx, %rdi
callq 0x28150