// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
addq $0x130, %rdi            # imm = 0x130
callq 0x9b980
testl %eax, %eax
je 0x7669a
movsd (%r14), %xmm0
movq %rsp, %rdi
movsd %xmm0, (%rdi)
movl $0x8, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x139a0
cmpq $0x1, %rax
jne 0x76611
leaq 0x18(%r14), %r13
movq %r14, 0x8(%rsp)
leaq 0x8(%r14), %rbp
movq $-0x1, %r12
movq %rsp, %r15
cmpq $0x2, %r12
je 0x76553
cmpq $0x1, %r12
movq %rbp, %rax
cmoveq %r13, %rax
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x139a0
incq %r12
addq $0x8, %rbp
cmpq $0x1, %rax
je 0x764fd
leaq 0x6a55a(%rip), %rdi     # 0xe0a9a
xorl %ebp, %ebp
xorl %eax, %eax
callq 0xaddb2
cmpq $0x2, %r12
jbe 0x766b3
movq 0x8(%rsp), %rax
addq $0x208, %rax            # imm = 0x208
movq %rax, 0x10(%rsp)
xorl %r13d, %r13d
movq %rsp, %r15
xorl %r12d, %r12d
testl %r12d, %r12d
movl $0x20, %ebp
movl $0x8, %eax
cmoveq %rax, %rbp
movq 0x8(%rsp), %rax
movsd 0x200(%rax,%rbp), %xmm0
movsd %xmm0, (%rsp)
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x139a0
cmpq $0x1, %rax
jne 0x76626
addq 0x10(%rsp), %rbp
xorl %r14d, %r14d
cmpq $0x2, %r14
je 0x765fa
movsd (%rbp,%r14,8), %xmm0
movsd %xmm0, (%rsp)
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x139a0
incq %r14
cmpq $0x1, %rax
je 0x765b3
decq %r14
leaq 0x6a4ad(%rip), %rdi     # 0xe0a9a
xorl %eax, %eax
callq 0xaddb2
cmpq $0x1, %r14
jbe 0x76634
leal 0x1(%r12), %eax
testl %r12d, %r12d
setne %r13b
movl %eax, %r12d
je 0x7656c
jmp 0x7663a
leaq 0x6a482(%rip), %rdi     # 0xe0a9a
xorl %ebp, %ebp
xorl %eax, %eax
callq 0xaddb2
jmp 0x766b3
leaq 0x6a46d(%rip), %rdi     # 0xe0a9a
xorl %eax, %eax
callq 0xaddb2
testb $0x1, %r13b
je 0x7669a
movq 0x8(%rsp), %rbp
addq $0x28, %rbp
xorl %r13d, %r13d
movq %rsp, %r15
xorl %r12d, %r12d
xorl %r14d, %r14d
movsd (%rbp,%r14,8), %xmm0
movsd %xmm0, (%rsp)
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x139a0
cmpq $0x1, %rax
jne 0x7669e
incq %r14
cmpq $0x4, %r14
jne 0x7664f
cmpq $0x3, %r13
leaq 0x1(%r13), %rax
setae %r12b
addq $0x20, %rbp
movq %rax, %r13
cmpq $0x4, %rax
jne 0x7664c
jmp 0x766ac
xorl %ebp, %ebp
jmp 0x766b3
leaq 0x6a3f5(%rip), %rdi     # 0xe0a9a
xorl %eax, %eax
callq 0xaddb2
movzbl %r12b, %ebp
andl $0x1, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq