// File: /workspace/github_cpp_makefile_star2_O2/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, 0x24(%rsp)
movq %rsi, %r14
movq %rdi, 0x18(%rsp)
leaq 0x11ae83(%rip), %rsi    # 0x14d0a3
movq %r14, %rdi
callq 0x27b20
testq %rax, %rax
je 0x32481
movq %rax, %r12
movq %r14, 0x10(%rsp)
leaq 0x2060(%rsp), %r14
xorl %ebx, %ebx
movq %r14, %rdi
movl $0x4000, %esi           # imm = 0x4000
movq %r12, %rdx
callq 0x27fe0
testq %rax, %rax
je 0x32496
incl %ebx
movzbl 0x2060(%rsp), %eax
testl %eax, %eax
je 0x32243
cmpl $0x23, %eax
je 0x32243
movl %ebx, 0xc(%rsp)
movq %r14, %rdi
leaq 0x116dae(%rip), %rsi    # 0x14902b
leaq 0x1060(%rsp), %rbx
movq %rbx, %rdx
xorl %eax, %eax
callq 0x27900
cmpl $0x1, %eax
jne 0x324c3
movq %rbx, %rdi
leaq 0xf9819(%rip), %rsi     # 0x12babb
pushq $0x9
popq %rdx
callq 0x27990
testl %eax, %eax
je 0x3240a
movq %rbx, %rdi
leaq 0xf98f4(%rip), %rsi     # 0x12bbb0
pushq $0xb
popq %rdx
callq 0x27990
testl %eax, %eax
je 0x3243e
cmpl $0x6e7572, 0x1060(%rsp) # imm = 0x6E7572
jne 0x32478
movq %r14, %rdi
leaq 0xfd7b3(%rip), %rsi     # 0x12fa9a
leaq 0x1060(%rsp), %rdx
leaq 0x60(%rsp), %rbx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x27900
cmpl $0x2, %eax
jne 0x324d5
movl $0x90, %edi
callq 0x27940
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x35f68
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x31726
movq %r15, %rdi
callq 0x36644
testl %eax, %eax
je 0x324ec
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0xe1cd2
movq %r15, %rdi
movq %rbx, %rsi
callq 0x369ca
testl %eax, %eax
je 0x324b7
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x36bb0
testl %eax, %eax
je 0x324b7
xorl %r13d, %r13d
movq %r12, 0x48(%rsp)
cmpl $0x3, %r13d
je 0x3246e
leaq 0x38(%rsp), %rdi
callq 0xe1cd2
movq %r14, %rbx
leaq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0xe1cd2
movq %r15, %rbp
movq %r15, %rdi
movl %r13d, %esi
leaq 0x38(%rsp), %rdx
movq %r14, %rcx
movl 0x24(%rsp), %r8d
callq 0x36f6a
testl %eax, %eax
je 0x324a3
movq %rbp, %rdi
movl %r13d, %esi
leaq 0x38(%rsp), %r12
movq %r12, %rdx
leaq 0x50(%rsp), %r15
movq %r15, %rcx
callq 0x37446
movl %eax, %r14d
movq %r15, %rdi
callq 0xe1d40
movq %r12, %rdi
callq 0xe1d40
incl %r13d
testl %r14d, %r14d
movq %rbx, %r14
movq 0x48(%rsp), %r12
movq %rbp, %r15
jne 0x32379
jmp 0x324b7
movq %r14, %rdi
leaq 0xfd686(%rip), %rsi     # 0x12fa9a
movq %rbx, %rdx
leaq 0x60(%rsp), %rbx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x27900
cmpl $0x2, %eax
jne 0x324cc
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x31858
jmp 0x32478
movq %r14, %rdi
leaq 0xfd652(%rip), %rsi     # 0x12fa9a
movq %rbx, %rdx
leaq 0x60(%rsp), %rbx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x27900
cmpl $0x2, %eax
jne 0x324cc
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x31888
jmp 0x32478
leaq 0x28(%rsp), %rdi
callq 0xe1d40
movl 0xc(%rsp), %ebx
jmp 0x32243
leaq 0xf967c(%rip), %rdi     # 0x12bb04
xorl %ebx, %ebx
movq %r14, %rsi
xorl %eax, %eax
callq 0xe434a
jmp 0x324ee
movq %r12, %rdi
callq 0x27930
pushq $0x1
popq %rbx
jmp 0x324ee
leaq 0x50(%rsp), %rdi
callq 0xe1d40
leaq 0x38(%rsp), %rdi
callq 0xe1d40
leaq 0x28(%rsp), %rdi
callq 0xe1d40
jmp 0x324ec
leaq 0xf9689(%rip), %rdi     # 0x12bb53
jmp 0x324dc
leaq 0xf96ab(%rip), %rdi     # 0x12bb7e
jmp 0x324dc
leaq 0xf964b(%rip), %rdi     # 0x12bb27
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0xe434a
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 %r15, %rdi
callq 0x27960
jmp 0x32541
jmp 0x32516
movq %rax, %rbx
jmp 0x32537
movq %rax, %rbx
jmp 0x3252d
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0xe1d40
leaq 0x38(%rsp), %rdi
callq 0xe1d40
leaq 0x28(%rsp), %rdi
callq 0xe1d40
movq %rbx, %rdi
callq 0x28170
nop