// File: 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:
subq $0x50b8, %rsp           # imm = 0x50B8
movq %rdi, 0x50a8(%rsp)
movq %rsi, 0x50a0(%rsp)
movq 0x50a8(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x40a0(%rsp), %rcx
movq %rcx, 0x30(%rsp)
movq 0x8(%rax), %rdi
callq 0x47cf0
movq 0x28(%rsp), %rdi
movq %rax, 0x38(%rsp)
callq 0x44310
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rdx
movq %rax, %rcx
leaq 0x22092b(%rip), %rsi    # 0x266e78
movb $0x0, %al
callq 0x2a280
leaq 0x40a0(%rsp), %rdi
leaq 0x23ce90(%rip), %rsi    # 0x2833f3
callq 0x2a520
movq %rax, 0x4098(%rsp)
cmpq $0x0, 0x4098(%rsp)
jne 0x465a1
leaq 0x40a0(%rsp), %rsi
leaq 0x220902(%rip), %rdi    # 0x266e8c
movb $0x0, %al
callq 0x1cbff0
movl $0x0, 0x50b4(%rsp)
jmp 0x46833
movl $0x4000, 0x4094(%rsp) # imm = 0x4000
leaq 0x90(%rsp), %rdi
movq 0x4098(%rsp), %rdx
movl $0x4000, %esi           # imm = 0x4000
callq 0x29bd0
cmpq $0x0, %rax
je 0x4681b
movsbl 0x90(%rsp), %eax
cmpl $0x0, %eax
jne 0x465df
jmp 0x465ac
movsbl 0x90(%rsp), %eax
cmpl $0x23, %eax
jne 0x465ee
jmp 0x465ac
leaq 0x90(%rsp), %rdi
leaq 0x22155d(%rip), %rsi    # 0x267b5a
leaq 0x8c(%rsp), %rdx
leaq 0x88(%rsp), %rcx
leaq 0x84(%rsp), %r8
movb $0x0, %al
callq 0x29150
cmpl $0x3, %eax
jne 0x46816
jmp 0x46627
movq 0x28(%rsp), %rdi
callq 0x39fe0
cmpl 0x8c(%rsp), %eax
jg 0x4674f
movl $0x98, %edi
callq 0x292e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x20(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x47df0
jmp 0x4665e
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rsi
callq 0x457b0
movl $0x0, 0x68(%rsp)
movq 0x28(%rsp), %rdi
movl 0x68(%rsp), %eax
movl %eax, 0x1c(%rsp)
callq 0x44320
movl %eax, %ecx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
jge 0x4674a
movq 0x28(%rsp), %rdi
movl 0x68(%rsp), %esi
callq 0x447e0
movq %rax, 0x60(%rsp)
movl $0x78, %edi
callq 0x292e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x10(%rsp)
callq 0x519f0
jmp 0x466ce
movq 0x10(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x78(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x49040
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x4c980
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x4667f
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
movl $0x98, %esi
callq 0x291f0
jmp 0x46842
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
movl $0x78, %esi
callq 0x291f0
jmp 0x46842
jmp 0x46627
movq 0x28(%rsp), %rdi
movl 0x8c(%rsp), %esi
callq 0x3a000
movq %rax, 0x50(%rsp)
movl 0x88(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x84(%rsp), %eax
jg 0x46814
jmp 0x46783
movq 0x50a0(%rsp), %rdi
callq 0x38730
cmpl 0x4c(%rsp), %eax
jg 0x46802
movl $0x88, %edi
callq 0x292e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x8(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x4e450
jmp 0x467b6
movq 0x8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x49150
movq 0x50a0(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x47d00
jmp 0x46783
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
movl $0x88, %esi
callq 0x291f0
jmp 0x46842
jmp 0x46804
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x46770
jmp 0x46816
jmp 0x465ac
movq 0x4098(%rsp), %rdi
callq 0x297e0
movl $0x1, 0x50b4(%rsp)
movl 0x50b4(%rsp), %eax
addq $0x50b8, %rsp           # imm = 0x50B8
retq
movq 0x70(%rsp), %rdi
callq 0x29c10
nopl (%rax)