// File: tomfunkhouser[P]gaps/pkgs/GSV/GSVScanline.cpp
// Function: gaps::GSVScanline::ReadPoints(_IO_FILE*, int)
int GSVScanline::
ReadPoints(FILE *fp, RNBoolean seek) 
{
  // Check read counter
  if (++read_count > 1) return 1;
  assert(!points);

  // Seek within file
  if (seek && (file_offset > 0)) {
    if (!RNFileSeek(fp, file_offset, RN_FILE_SEEK_SET)) {
      RNFail("Unable to seek to scanline points\n");
      return 0;
    }
  }
  else {
    // Update file offset
    file_offset = RNFileTell(fp);
  }

  // Read number of points 
  if (fread(&npoints, sizeof(int), 1, fp) != (unsigned int) 1) {
    RNFail("Unable to read number of scanline points\n");
    return 0;
  }

  // Check number of points
  if (npoints > 0) {
    // Allocate points 
    points = new GSVPoint [ npoints ];
    if (!points) {
      RNFail("Unable to allocate scanline points\n");
      return 0;
    }
    
    // Read points
    if (fread(points, sizeof(GSVPoint), npoints, fp) != (unsigned int) npoints) {
      RNFail("Unable to read scanline points\n");
      return 0;
    }
    
    // Update bounding box
    bbox = R3null_box;
    for (int i = 0; i < npoints; i++) {
      bbox.Union(points[i].Position());
    }
  }
  else {
    // No points
    points = NULL;
    bbox = R3null_box;
  }

  // Return success
  return 1;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq %rsi, 0x70(%rsp)
movl %edx, 0x6c(%rsp)
movq 0x78(%rsp), %rcx
movq %rcx, 0x38(%rsp)
movl 0x20(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x20(%rcx)
cmpl $0x1, %eax
jbe 0x5950d
movl $0x1, 0x84(%rsp)
jmp 0x5978d
cmpl $0x0, 0x6c(%rsp)
je 0x5955a
movq 0x38(%rsp), %rax
cmpq $0x0, 0x18(%rax)
jbe 0x5955a
movq 0x38(%rsp), %rax
movq 0x70(%rsp), %rdi
movq 0x18(%rax), %rsi
xorl %edx, %edx
callq 0x1caea0
cmpl $0x0, %eax
jne 0x59558
leaq 0x20debc(%rip), %rdi    # 0x2673fd
movb $0x0, %al
callq 0x1cbff0
movl $0x0, 0x84(%rsp)
jmp 0x5978d
jmp 0x59570
movq 0x70(%rsp), %rdi
callq 0x1caef0
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x38(%rsp), %rdi
addq $0x30, %rdi
movq 0x70(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x299d0
cmpq $0x1, %rax
je 0x595b1
leaq 0x20de86(%rip), %rdi    # 0x267420
movb $0x0, %al
callq 0x1cbff0
movl $0x0, 0x84(%rsp)
jmp 0x5978d
movq 0x38(%rsp), %rax
cmpl $0x0, 0x30(%rax)
jle 0x59762
movq 0x38(%rsp), %rax
movslq 0x30(%rax), %rax
movq %rax, 0x28(%rsp)
movl $0x50, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, 0x20(%rsp)
callq 0x29820
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x30(%rsp)
cmpq $0x0, %rax
je 0x5964e
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
imulq $0x50, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x5ee80
jmp 0x59636
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rax
addq $0x50, %rax
cmpq %rcx, %rax
movq %rax, 0x18(%rsp)
jne 0x59625
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x28(%rax)
cmpq $0x0, 0x28(%rax)
jne 0x596a3
leaq 0x20dde0(%rip), %rdi    # 0x26744a
movb $0x0, %al
callq 0x1cbff0
movl $0x0, 0x84(%rsp)
jmp 0x5978d
movq 0x20(%rsp), %rsi
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
callq 0x29030
jmp 0x5979c
movq 0x38(%rsp), %rax
movq 0x28(%rax), %rdi
movslq 0x30(%rax), %rdx
movq 0x70(%rsp), %rcx
movl $0x50, %esi
callq 0x299d0
movq 0x38(%rsp), %rcx
movl 0x30(%rcx), %ecx
cmpq %rcx, %rax
je 0x596ea
leaq 0x20dd9b(%rip), %rdi    # 0x26746e
movb $0x0, %al
callq 0x1cbff0
movl $0x0, 0x84(%rsp)
jmp 0x5978d
movq 0x38(%rsp), %rdi
addq $0x88, %rdi
leaq 0x2a8dfb(%rip), %rsi    # 0x3024f8
callq 0x386d0
movl $0x0, 0x58(%rsp)
movq 0x38(%rsp), %rcx
movl 0x58(%rsp), %eax
cmpl 0x30(%rcx), %eax
jge 0x59760
movq 0x38(%rsp), %rax
movq %rax, %rcx
addq $0x88, %rcx
movq %rcx, (%rsp)
movq 0x28(%rax), %rsi
movslq 0x58(%rsp), %rax
imulq $0x50, %rax, %rax
addq %rax, %rsi
leaq 0x40(%rsp), %rdi
callq 0x3a200
movq (%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x153680
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x5970a
jmp 0x59782
movq 0x38(%rsp), %rdi
movq $0x0, 0x28(%rdi)
addq $0x88, %rdi
leaq 0x2a8d7b(%rip), %rsi    # 0x3024f8
callq 0x386d0
movl $0x1, 0x84(%rsp)
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq
movq 0x60(%rsp), %rdi
callq 0x29c10
nopw %cs:(%rax,%rax)