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

  // Write points
  float buf[16];
  for (int i = 0; i < NPoints(); i++) {
    const R3Point& p = PointPosition(i);
    const R3Vector& n = PointNormal(i);
    const RNRgb& c = PointColor(i);
    buf[0] = p[0]; buf[1] = p[1]; buf[2] = p[2];
    buf[3] = n[0]; buf[4] = n[1]; buf[5] = n[2];
    buf[6] = c[0]; buf[7] = c[1]; buf[8] = c[2];
    buf[9] = PointTimestamp(i);
    buf[10] = PointCategoryIdentifier(i);
    buf[11] = PointInstanceIdentifier(i);
    buf[12] = PointValue(i);
    buf[13] = buf[14] = buf[15] = 0;
    if (fwrite(buf, sizeof(float), 16, fp) != (unsigned int) 16) {
      RNFail("Unable to write point %d to %s\n", i, filename);
      return 0;
    }
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movq %rsi, 0x80(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x80(%rsp), %rdi
leaq 0xde8c5(%rip), %rsi     # 0x1bdb68
callq 0x23bd0
movq %rax, 0x78(%rsp)
cmpq $0x0, 0x78(%rsp)
jne 0xdf2db
movq 0x80(%rsp), %rsi
leaq 0xdedf6(%rip), %rdi     # 0x1be0ba
movb $0x0, %al
callq 0x120a50
movl $0x0, 0x94(%rsp)
jmp 0xdf4fc
movl $0x0, 0x2c(%rsp)
movq 0x8(%rsp), %rdi
movl 0x2c(%rsp), %eax
movl %eax, 0x4(%rsp)
callq 0x32400
movl %eax, %ecx
movl 0x4(%rsp), %eax
cmpl %ecx, %eax
jge 0xdf4e7
movq 0x8(%rsp), %rdi
movl 0x2c(%rsp), %esi
callq 0x359b0
movq 0x8(%rsp), %rdi
movq %rax, 0x20(%rsp)
movl 0x2c(%rsp), %esi
callq 0xe01e0
movq 0x8(%rsp), %rdi
movq %rax, 0x18(%rsp)
movl 0x2c(%rsp), %esi
callq 0xe0250
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x33470
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x30(%rsp)
movq 0x20(%rsp), %rdi
movl $0x1, %esi
callq 0x33470
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x34(%rsp)
movq 0x20(%rsp), %rdi
movl $0x2, %esi
callq 0x33470
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x38(%rsp)
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x7c4f0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x3c(%rsp)
movq 0x18(%rsp), %rdi
movl $0x1, %esi
callq 0x7c4f0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x40(%rsp)
movq 0x18(%rsp), %rdi
movl $0x2, %esi
callq 0x7c4f0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x44(%rsp)
movq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0xe02c0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x48(%rsp)
movq 0x10(%rsp), %rdi
movl $0x1, %esi
callq 0xe02c0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x4c(%rsp)
movq 0x10(%rsp), %rdi
movl $0x2, %esi
callq 0xe02c0
movq 0x8(%rsp), %rdi
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x50(%rsp)
movl 0x2c(%rsp), %esi
callq 0xe02e0
movq 0x8(%rsp), %rdi
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x54(%rsp)
movl 0x2c(%rsp), %esi
callq 0xe0360
movq 0x8(%rsp), %rdi
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x58(%rsp)
movl 0x2c(%rsp), %esi
callq 0xe03d0
movq 0x8(%rsp), %rdi
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x5c(%rsp)
movl 0x2c(%rsp), %esi
callq 0xe0440
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x60(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x6c(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x68(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x64(%rsp)
leaq 0x30(%rsp), %rdi
movq 0x78(%rsp), %rcx
movl $0x4, %esi
movl $0x10, %edx
callq 0x24420
cmpq $0x10, %rax
je 0xdf4d5
movl 0x2c(%rsp), %esi
movq 0x80(%rsp), %rdx
leaq 0xdec1f(%rip), %rdi     # 0x1be0e0
movb $0x0, %al
callq 0x120a50
movl $0x0, 0x94(%rsp)
jmp 0xdf4fc
jmp 0xdf4d7
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0xdf2e3
movq 0x78(%rsp), %rdi
callq 0x239a0
movl $0x1, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq
nopl (%rax,%rax)