// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3PointSet.cpp
// Function: gaps::R3PointSet::ReadBinaryFile(char const*)
int R3PointSet::
ReadBinaryFile(const char *filename)
{
  // Open file
  FILE *fp = fopen(filename, "rb");
  if (!fp) {
    RNFail("Unable to open %s\n", filename);
    return 0;
  }

  // Read points
  float buf[16];
  while (fread(buf, sizeof(float), 16, fp) == (unsigned int) 16) {
    R3Point position(buf[0], buf[1], buf[2]);
    R3Vector normal(buf[3], buf[4], buf[5]);
    RNRgb color(buf[6], buf[7], buf[8]);
    double timestamp = buf[9];
    int category_identifier = buf[10] + 0.5;
    int instance_identifier = buf[11] + 0.5;
    double value = buf[12];
    normal.Normalize();
    int index = InsertPoint(position);
    SetPointNormal(index, normal);
    SetPointColor(index, color);
    SetPointTimestamp(index, timestamp);
    SetPointCategoryIdentifier(index, category_identifier);
    SetPointInstanceIdentifier(index, instance_identifier);
    SetPointValue(index, value);
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xc8(%rsp)
movq %rsi, 0xc0(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, (%rsp)
movq 0xc0(%rsp), %rdi
leaq 0xdde91(%rip), %rsi     # 0x1bc643
callq 0x23bd0
movq %rax, 0xb8(%rsp)
cmpq $0x0, 0xb8(%rsp)
jne 0xde7f0
movq 0xc0(%rsp), %rsi
leaq 0xdf8e1(%rip), %rdi     # 0x1be0ba
movb $0x0, %al
callq 0x120a50
movl $0x0, 0xd4(%rsp)
jmp 0xde9ac
jmp 0xde7f2
leaq 0x70(%rsp), %rdi
movq 0xb8(%rsp), %rcx
movl $0x4, %esi
movl $0x10, %edx
callq 0x23fc0
cmpq $0x10, %rax
jne 0xde994
movss 0x70(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x74(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movss 0x78(%rsp), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x58(%rsp), %rdi
callq 0xd9f40
movss 0x7c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x80(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movss 0x84(%rsp), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x40(%rsp), %rdi
callq 0xdb0a0
movss 0x88(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x8c(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movss 0x90(%rsp), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x28(%rsp), %rdi
callq 0x11c290
movss 0x94(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movss 0x98(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0xdc769(%rip), %xmm1    # 0x1bb030
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x1c(%rsp)
movss 0x9c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0xdc748(%rip), %xmm1    # 0x1bb030
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x18(%rsp)
movss 0xa0(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x40(%rsp), %rdi
callq 0xdb800
movq (%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xdd260
movq (%rsp), %rdi
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %esi
leaq 0x40(%rsp), %rdx
callq 0xdd330
movq (%rsp), %rdi
movl 0xc(%rsp), %esi
leaq 0x28(%rsp), %rdx
callq 0xdd500
movq (%rsp), %rdi
movl 0xc(%rsp), %esi
movsd 0x20(%rsp), %xmm0
callq 0xdd590
movq (%rsp), %rdi
movl 0xc(%rsp), %esi
movl 0x1c(%rsp), %edx
callq 0xdd630
movq (%rsp), %rdi
movl 0xc(%rsp), %esi
movl 0x18(%rsp), %edx
callq 0xdd6c0
movq (%rsp), %rdi
movl 0xc(%rsp), %esi
movsd 0x10(%rsp), %xmm0
callq 0xdd7f0
jmp 0xde7f2
movq 0xb8(%rsp), %rdi
callq 0x239a0
movl $0x1, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
addq $0xd8, %rsp
retq
nopl (%rax,%rax)