// File: /workspace/github_cpp_makefile_star2_O1/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 0x116464(%rip), %rsi    # 0x14ed78
xorl %ebp, %ebp
leaq 0x20(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x27140
leaq 0x137ab7(%rip), %rsi    # 0x1703e3
movq %r15, %rdi
callq 0x27b30
testq %rax, %rax
je 0x38ada
movq %rax, %r12
leaq 0x1020(%rsp), %rdi
movl $0x4000, %esi           # imm = 0x4000
movq %rax, %rdx
callq 0x27fd0
testq %rax, %rax
je 0x38acb
leaq 0x18(%r14), %rax
movq %rax, 0x18(%rsp)
leaq 0x1020(%rsp), %r15
movq %r12, 0x10(%rsp)
movzbl 0x1020(%rsp), %eax
testl %eax, %eax
je 0x38ab2
cmpl $0x23, %eax
je 0x38ab2
movq %r15, %rdi
leaq 0x117013(%rip), %rsi    # 0x14f9aa
leaq 0x8(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x4(%rsp), %r8
xorl %eax, %eax
callq 0x27900
cmpl $0x3, %eax
jne 0x38aaa
movl 0x8(%rsp), %eax
cmpl %eax, 0x24(%r14)
jg 0x38a49
movl $0x98, %edi
callq 0x27930
movq %rax, %rbp
movq %rax, %rdi
xorl %esi, %esi
callq 0x39944
movq %r14, 0x10(%rbp)
movl 0x24(%r14), %edx
movl %edx, 0x18(%rbp)
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0xfa862
movq %r14, %rdi
callq 0x38086
cmpl $0x0, 0x34(%r14)
jle 0x389b6
xorl %r12d, %r12d
movq 0x28(%r14), %rax
movq (%rax,%r12,8), %r15
movl $0x78, %edi
callq 0x27930
movq %rax, %r13
movq %rax, %rdi
callq 0x3e708
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3a39a
movq %r15, %rdi
movq %r13, %rsi
callq 0x3bc94
incq %r12
movslq 0x34(%r14), %rax
cmpq %rax, %r12
jl 0x38a05
jmp 0x389b6
movl 0xc(%rsp), %r15d
cmpl 0x4(%rsp), %r15d
movq 0x10(%rsp), %r12
jg 0x38aaa
movq 0x18(%r14), %rcx
cltq
movq (%rcx,%rax,8), %rbp
cmpl %r15d, 0xc(%rbx)
jg 0x38a9c
movl $0x88, %edi
callq 0x27930
movq %rax, %r13
movq %rax, %rdi
xorl %esi, %esi
callq 0x3cb38
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3a406
movl 0xc(%rbx), %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0xfa862
jmp 0x38a64
leal 0x1(%r15), %eax
cmpl 0x4(%rsp), %r15d
movl %eax, %r15d
jl 0x38a64
leaq 0x1020(%rsp), %r15
movq %r15, %rdi
movl $0x4000, %esi           # imm = 0x4000
movq %r12, %rdx
callq 0x27fd0
testq %rax, %rax
jne 0x38974
movq %r12, %rdi
callq 0x27920
movl $0x1, %ebp
jmp 0x38aed
leaq 0x1162ab(%rip), %rdi    # 0x14ed8c
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0xfd64a
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 0x38b23
movq %rax, %rbx
movl $0x88, %esi
jmp 0x38b20
movq %rax, %rbx
movl $0x78, %esi
movq %r13, %rdi
callq 0x27950
movq %rbx, %rdi
callq 0x28160