// File: /workspace/github_cpp_makefile_star2_O3/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 0x114627(%rip), %rsi    # 0x14cd79
xorl %ebp, %ebp
leaq 0x20(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x27140
leaq 0x135cd9(%rip), %rsi    # 0x16e443
movq %r15, %rdi
callq 0x27b20
testq %rax, %rax
je 0x38929
movq %rax, %r12
leaq 0x1020(%rsp), %rdi
movl $0x4000, %esi           # imm = 0x4000
movq %rax, %rdx
callq 0x27fc0
testq %rax, %rax
je 0x3891a
leaq 0x18(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0x1020(%rsp), %r15
movq %r12, 0x18(%rsp)
movzbl 0x1020(%rsp), %eax
testl %eax, %eax
je 0x38901
cmpl $0x23, %eax
je 0x38901
movq %r15, %rdi
leaq 0x115205(%rip), %rsi    # 0x14d9da
leaq 0x8(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x4(%rsp), %r8
xorl %eax, %eax
callq 0x27900
cmpl $0x3, %eax
jne 0x388f9
movl 0x8(%rsp), %ecx
cmpl %ecx, 0x24(%r14)
jg 0x38887
movl $0x98, %edi
callq 0x27930
movq %rax, %rbp
movq %rax, %rdi
xorl %esi, %esi
callq 0x39658
movq %r14, 0x10(%rbp)
movl 0x24(%r14), %edx
movl %edx, 0x18(%rbp)
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0xf8c16
movq %r14, %rdi
callq 0x37ec6
cmpl $0x0, 0x34(%r14)
jle 0x387f4
xorl %r12d, %r12d
movq 0x28(%r14), %rax
movq (%rax,%r12,8), %r15
movl $0x78, %edi
callq 0x27930
movq %rax, %r13
movq %rax, %rdi
callq 0x3e2c8
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3a07a
movq %r15, %rdi
movq %r13, %rsi
callq 0x3b95c
incq %r12
movslq 0x34(%r14), %rax
cmpq %rax, %r12
jl 0x38843
jmp 0x387f4
movl 0xc(%rsp), %r15d
movl 0x4(%rsp), %eax
cmpl %eax, %r15d
movq 0x18(%rsp), %r12
jg 0x388f9
movq 0x10(%rsp), %rdx
movq (%rdx), %rdx
movslq %ecx, %rcx
movq (%rdx,%rcx,8), %rbp
movl 0xc(%rbx), %ecx
cmpl %r15d, %ecx
jg 0x388ed
movl $0x88, %edi
callq 0x27930
movq %rax, %r13
movq %rax, %rdi
xorl %esi, %esi
callq 0x3c800
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3a0e6
movl 0xc(%rbx), %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf8c16
movl 0xc(%rbx), %ecx
cmpl %r15d, %ecx
jle 0x388b1
movl 0x4(%rsp), %eax
leal 0x1(%r15), %edx
cmpl %eax, %r15d
movl %edx, %r15d
jl 0x388ac
leaq 0x1020(%rsp), %r15
movq %r15, %rdi
movl $0x4000, %esi           # imm = 0x4000
movq %r12, %rdx
callq 0x27fc0
testq %rax, %rax
jne 0x387b2
movq %r12, %rdi
callq 0x27920
movl $0x1, %ebp
jmp 0x3893c
leaq 0x11445d(%rip), %rdi    # 0x14cd8d
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0xfb6f2
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 0x38972
movq %rax, %rbx
movl $0x88, %esi
jmp 0x3896f
movq %rax, %rbx
movl $0x78, %esi
movq %r13, %rdi
callq 0x27950
movq %rbx, %rdi
callq 0x28150
nop