// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3PlanarGrid.cpp
// Function: gaps::R3PlanarGrid::WriteGrid(_IO_FILE*) const
int R3PlanarGrid::
WriteGrid(FILE *fp) const
{
  // Write grid 
  if (!grid.WriteGrid(fp)) return 0;

  // Write plane to file
  for (int i = 0; i < 4; i++) {
    RNScalar a = plane[i];
    if (fwrite(&a, sizeof(RNScalar), 1, fp) != 1) {
      RNFail("Unable to write plane to file");
      return 0;
    }
  }

  // Write bounding box to file
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 3; j++) {
      RNScalar a = bbox[i][j];
      if (fwrite(&a, sizeof(RNScalar), 1, fp) != 1) {
        RNFail("Unable to write plane to file");
        return 0;
      }
    }
  }

  // Write transformation to file
  const R4Matrix& matrix = transformation.Matrix();
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      RNScalar a = matrix[i][j];
      if (fwrite(&a, sizeof(RNScalar), 1, fp) != 1) {
        RNFail("Unable to write plane to file");
        return 0;
      }
    }
  }

  // Return success
  return 1;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq 0x48(%rsp), %rdi
movq %rdi, (%rsp)
addq $0x130, %rdi            # imm = 0x130
movq 0x40(%rsp), %rsi
callq 0xdec60
cmpl $0x0, %eax
jne 0xde33a
movl $0x0, 0x54(%rsp)
jmp 0xde4fa
movl $0x0, 0x3c(%rsp)
cmpl $0x4, 0x3c(%rsp)
jge 0xde3a5
movq (%rsp), %rdi
movl 0x3c(%rsp), %esi
callq 0x899f0
movsd %xmm0, 0x30(%rsp)
movq 0x40(%rsp), %rcx
leaq 0x30(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x13a80
cmpq $0x1, %rax
je 0xde396
leaq 0xc8700(%rip), %rdi     # 0x1a6a82
movb $0x0, %al
callq 0x1464b0
movl $0x0, 0x54(%rsp)
jmp 0xde4fa
jmp 0xde398
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0xde342
movl $0x0, 0x2c(%rsp)
cmpl $0x2, 0x2c(%rsp)
jge 0xde448
movl $0x0, 0x28(%rsp)
cmpl $0x3, 0x28(%rsp)
jge 0xde436
movq (%rsp), %rdi
addq $0x200, %rdi            # imm = 0x200
movl 0x2c(%rsp), %esi
callq 0x1bb60
movq %rax, %rdi
movl 0x28(%rsp), %esi
callq 0x1bba0
movsd %xmm0, 0x20(%rsp)
movq 0x40(%rsp), %rcx
leaq 0x20(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x13a80
cmpq $0x1, %rax
je 0xde427
leaq 0xc866f(%rip), %rdi     # 0x1a6a82
movb $0x0, %al
callq 0x1464b0
movl $0x0, 0x54(%rsp)
jmp 0xde4fa
jmp 0xde429
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0xde3c0
jmp 0xde438
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0xde3ad
movq (%rsp), %rdi
addq $0x20, %rdi
callq 0x31ae0
movq %rax, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
cmpl $0x4, 0x14(%rsp)
jge 0xde4f2
movl $0x0, 0x10(%rsp)
cmpl $0x4, 0x10(%rsp)
jge 0xde4e0
movq 0x18(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x31af0
movslq 0x10(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x40(%rsp), %rcx
leaq 0x8(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x13a80
cmpq $0x1, %rax
je 0xde4d1
leaq 0xc85c2(%rip), %rdi     # 0x1a6a82
movb $0x0, %al
callq 0x1464b0
movl $0x0, 0x54(%rsp)
jmp 0xde4fa
jmp 0xde4d3
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0xde475
jmp 0xde4e2
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0xde462
movl $0x1, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)