// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/GSV/GSVRun.cpp
// Function: gaps::GSVRun::ReadImageSegmentFile(gaps::RNArray<gaps::GSVPanorama*>&)
int GSVRun::
ReadImageSegmentFile(RNArray<GSVPanorama *>& panoramas)
{
  // Create filename
  char filename[4096];
  sprintf(filename, "%s/%s/image_seg.txt", scene->RawDataDirectoryName(), Name());

  // Open file
  FILE *fp = fopen(filename, "r");
  if (!fp) {
    RNFail("Unable to open segment info file: %s\n", filename);
    return 0;
  }

  // Read range of panorama indices for each segment
  const int buffer_size = 16*1024;
  char buffer[buffer_size];
  while (fgets(buffer, buffer_size, fp)) {
    // Parse line
    if (buffer[0] == '\0') continue;
    if (buffer[0] == '#') continue;
    int segment_index;
    int start_panorama_index;
    int end_panorama_index;
    if (sscanf(buffer, "%d%d%d", &segment_index, &start_panorama_index, &end_panorama_index) == 3) {
      // Create segment
      while (NSegments() <= segment_index) {
        GSVSegment *segment = new GSVSegment();
        InsertSegment(segment);
        for (int ic = 0; ic < NCameras(); ic++) {
          GSVCamera *camera = Camera(ic);
          GSVTapestry *tapestry = new GSVTapestry();
          segment->InsertTapestry(tapestry);
          camera->InsertTapestry(tapestry);
        }
      }

      // Get segment
      GSVSegment *segment = Segment(segment_index);

      // Create panoramas
      for (int panorama_index = start_panorama_index; panorama_index <= end_panorama_index; panorama_index++) {
        while (panoramas.NEntries() <= panorama_index) {
          GSVPanorama *panorama = new GSVPanorama();
          segment->InsertPanorama(panorama);
          panoramas.Insert(panorama);
        }
      }
    }
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5028, %rsp           # imm = 0x5028
movq %rsi, %rbx
movq %rdi, %r14
movq 0x8(%rdi), %rax
movq 0x48(%rdi), %rcx
movq 0x20(%rax), %rdx
leaq 0xf5385(%rip), %rsi     # 0x12bd79
xorl %ebp, %ebp
leaq 0x20(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x27140
leaq 0x116697(%rip), %rsi    # 0x14d0a3
movq %r15, %rdi
callq 0x27b20
testq %rax, %rax
je 0x36b5c
movq %rax, %r13
leaq 0x1020(%rsp), %r15
movq %rax, 0x18(%rsp)
movq %r15, %rdi
movl $0x4000, %esi           # imm = 0x4000
movq %r13, %rdx
callq 0x27fe0
testq %rax, %rax
je 0x36b4f
movzbl 0x1020(%rsp), %eax
testl %eax, %eax
je 0x36a2d
cmpl $0x23, %eax
je 0x36a2d
movq %r15, %rdi
leaq 0xf5f39(%rip), %rsi     # 0x12c99a
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0xc(%rsp), %r8
xorl %eax, %eax
callq 0x27900
cmpl $0x3, %eax
jne 0x36b42
movslq 0x14(%rsp), %rax
cmpl %eax, 0x24(%r14)
jg 0x36aef
movl $0x98, %edi
callq 0x27940
movq %rax, %rbp
movq %rax, %rdi
xorl %esi, %esi
callq 0x37710
movq %r14, %rdi
movq %rbp, %rsi
callq 0x36272
xorl %r13d, %r13d
movslq 0x34(%r14), %rax
cmpq %rax, %r13
jge 0x36a80
movq 0x28(%r14), %rax
movq (%rax,%r13,8), %r15
pushq $0x78
popq %rdi
callq 0x27940
movq %rax, %r12
movq %rax, %rdi
callq 0x3bb24
movq %rbp, %rdi
movq %r12, %rsi
callq 0x37f68
movq %r15, %rdi
movq %r12, %rsi
callq 0x396fe
incq %r13
jmp 0x36ab0
movq 0x18(%r14), %rcx
movq (%rcx,%rax,8), %rbp
movl 0x10(%rsp), %r15d
movq 0x18(%rsp), %r13
cmpl 0xc(%rsp), %r15d
jg 0x36b42
cmpl %r15d, 0xc(%rbx)
jg 0x36b3d
movl $0x88, %edi
callq 0x27940
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
callq 0x3a2f4
movq %rbp, %rdi
movq %r12, %rsi
callq 0x37fcc
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3110a
jmp 0x36b08
incl %r15d
jmp 0x36b01
leaq 0x1020(%rsp), %r15
jmp 0x36a2d
movq %r13, %rdi
callq 0x27930
pushq $0x1
popq %rbp
jmp 0x36b6f
leaq 0xf522a(%rip), %rdi     # 0x12bd8d
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0xe434a
movl %ebp, %eax
addq $0x5028, %rsp           # imm = 0x5028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x98, %esi
movq %rbp, %rdi
jmp 0x36ba3
movq %rax, %rbx
movl $0x88, %esi
jmp 0x36ba0
movq %rax, %rbx
pushq $0x78
popq %rsi
movq %r12, %rdi
callq 0x27960
movq %rbx, %rdi
callq 0x28170