// File: tomfunkhouser[P]gaps/pkgs/GSV/GSVScene.cpp
// Function: gaps::GSVScene::ReadLaserFile(char const*, int)
int GSVScene::
ReadLaserFile(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;
    char run_name[4096];
    if (sscanf(buffer, "%s", run_name) != (unsigned int) 1) {
      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 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:
subq $0x5098, %rsp           # imm = 0x5098
movq %rdi, 0x5088(%rsp)
movq %rsi, 0x5080(%rsp)
movl %edx, 0x507c(%rsp)
movq 0x5088(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x5080(%rsp), %rdi
leaq 0x246b19(%rip), %rsi    # 0x2833f3
callq 0x2a520
movq %rax, 0x5070(%rsp)
cmpq $0x0, 0x5070(%rsp)
jne 0x3c918
movq 0x5080(%rsp), %rsi
leaq 0x22a305(%rip), %rdi    # 0x266c06
movb $0x0, %al
callq 0x1cbff0
movl $0x0, 0x5094(%rsp)
jmp 0x3cb6c
movl $0x0, 0x506c(%rsp)
movl $0x4000, 0x5068(%rsp) # imm = 0x4000
leaq 0x1060(%rsp), %rdi
movq 0x5070(%rsp), %rdx
movl $0x4000, %esi           # imm = 0x4000
callq 0x29bd0
cmpq $0x0, %rax
je 0x3cb54
movl 0x506c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x506c(%rsp)
movsbl 0x1060(%rsp), %eax
cmpl $0x0, %eax
jne 0x3c972
jmp 0x3c92e
movsbl 0x1060(%rsp), %eax
cmpl $0x23, %eax
jne 0x3c981
jmp 0x3c92e
leaq 0x1060(%rsp), %rdi
leaq 0x60(%rsp), %rdx
leaq 0x243892(%rip), %rsi    # 0x280227
movb $0x0, %al
callq 0x29150
cmpl $0x1, %eax
je 0x3c9ce
movl 0x506c(%rsp), %esi
movq 0x5080(%rsp), %rdx
leaq 0x22a272(%rip), %rdi    # 0x266c29
movb $0x0, %al
callq 0x1cbff0
movl $0x0, 0x5094(%rsp)
jmp 0x3cb6c
movl $0x90, %edi
callq 0x292e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x8(%rsp)
leaq 0x60(%rsp), %rsi
callq 0x45090
jmp 0x3c9ef
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rsi
callq 0x3b700
movl $0x2, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
cmpl $0x2, 0x44(%rsp)
jg 0x3cb4f
leaq 0x30(%rsp), %rdi
callq 0x444a0
leaq 0x20(%rsp), %rdi
callq 0x444b0
jmp 0x3ca39
movq 0x58(%rsp), %rdi
movl 0x44(%rsp), %esi
movl 0x507c(%rsp), %r8d
leaq 0x30(%rsp), %rdx
leaq 0x20(%rsp), %rcx
callq 0x46e80
movl %eax, 0x4(%rsp)
jmp 0x3ca5f
movl 0x4(%rsp), %eax
cmpl $0x0, %eax
jne 0x3cacf
movl $0x0, 0x5094(%rsp)
movl $0x1, 0x1c(%rsp)
jmp 0x3cb11
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
movl $0x90, %esi
callq 0x291f0
jmp 0x3cb7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
jmp 0x3cb43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x444c0
jmp 0x3cb43
movq 0x58(%rsp), %rdi
movl 0x44(%rsp), %esi
leaq 0x30(%rsp), %rdx
leaq 0x20(%rsp), %rcx
callq 0x477e0
movl %eax, (%rsp)
jmp 0x3caec
movl (%rsp), %eax
cmpl $0x0, %eax
jne 0x3cb09
movl $0x0, 0x5094(%rsp)
movl $0x1, 0x1c(%rsp)
jmp 0x3cb11
movl $0x0, 0x1c(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x444c0
leaq 0x30(%rsp), %rdi
callq 0x444d0
movl 0x1c(%rsp), %eax
testl %eax, %eax
je 0x3cb31
jmp 0x3cb2f
jmp 0x3cb6c
jmp 0x3cb33
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x3ca18
leaq 0x30(%rsp), %rdi
callq 0x444d0
jmp 0x3cb7b
jmp 0x3c92e
movq 0x5070(%rsp), %rdi
callq 0x297e0
movl $0x1, 0x5094(%rsp)
movl 0x5094(%rsp), %eax
addq $0x5098, %rsp           # imm = 0x5098
retq
movq 0x50(%rsp), %rdi
callq 0x29c10
nopw %cs:(%rax,%rax)