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

  // Print header lines
  const R3Box bbox = WorldBox();
  const RNScalar delta = GridToWorldScaleFactor();
  fprintf(fp, "object 1 class gridpositions counts %d %d %d\n", XResolution(), YResolution(), ZResolution());
  fprintf(fp, "origin %lf %lf %lf\n", bbox[0][0], bbox[0][1], bbox[0][2]);
  fprintf(fp, "delta %lf 0 0\ndelta 0 %lf 0\ndelta 0 0 %lf\n", delta, delta, delta);
  fprintf(fp, "\nobject 2 class gridconnections counts %d %d %d\n", XResolution(), YResolution(), ZResolution());
  fprintf(fp, "\nobject 3 class array type double rank 0 items %d data follows\n", (XResolution() * YResolution() * ZResolution()));

  // Print values
  for (int i = 0; i < XResolution(); i++) {
    for (int j = 0; j < YResolution(); j++) {
      for (int k = 0; k < ZResolution(); k++) {
	fprintf(fp, "%lf\n", GridValue(i, j, k));
      }
    }
  }

  // Print trailer lines
  fprintf(fp, "\nend\n");

  // Close file
  fclose(fp);

  // Return OK status
  return grid_size;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x6fb41(%rip), %rsi     # 0xa77b9
movq %r15, %rdi
callq 0xe530
testq %rax, %rax
je 0x37ebb
movq %rax, %r14
leaq 0x58(%rsp), %r15
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r15, %rdi
callq 0x3c532
movl 0x238(%rbx), %eax
decl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movl 0x23c(%rbx), %eax
decl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movl 0x240(%rbx), %eax
decl %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x3c532
movsd (%r15), %xmm0
movsd 0x8(%r15), %xmm1
movsd 0x10(%r15), %xmm2
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x3c532
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3ce48
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd 0x10(%r12), %xmm2
leaq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x3c532
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3ce48
leaq 0x70(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x27326
movsd 0x228(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
movl 0x238(%rbx), %edx
movl 0x23c(%rbx), %ecx
movl 0x240(%rbx), %r8d
leaq 0x70664(%rip), %rsi     # 0xa83d0
xorl %ebp, %ebp
movq %r14, %rdi
xorl %eax, %eax
callq 0xe670
movsd 0x8(%r13), %xmm0
movsd 0x10(%r13), %xmm1
movsd 0x18(%r13), %xmm2
leaq 0x7066d(%rip), %rsi     # 0xa83fe
movq %r14, %rdi
movb $0x3, %al
callq 0xe670
leaq 0x70670(%rip), %rsi     # 0xa8412
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
movb $0x3, %al
callq 0xe670
movl 0x238(%rbx), %edx
movl 0x23c(%rbx), %ecx
movl 0x240(%rbx), %r8d
leaq 0x7066b(%rip), %rsi     # 0xa843d
movq %r14, %rdi
xorl %eax, %eax
callq 0xe670
movl 0x23c(%rbx), %edx
imull 0x238(%rbx), %edx
imull 0x240(%rbx), %edx
leaq 0x70677(%rip), %rsi     # 0xa846e
movq %r14, %rdi
xorl %eax, %eax
callq 0xe670
movl 0x238(%rbx), %ecx
testl %ecx, %ecx
jle 0x37e88
movl 0x23c(%rbx), %eax
leaq 0x70620(%rip), %r15     # 0xa8438
testl %eax, %eax
jle 0x37e82
movl 0x240(%rbx), %ecx
xorl %r12d, %r12d
testl %ecx, %ecx
jle 0x37e74
xorl %r13d, %r13d
movq 0x230(%rbx), %rax
movl 0x248(%rbx), %ecx
imull %r13d, %ecx
movl 0x244(%rbx), %edx
imull %r12d, %edx
addl %ebp, %ecx
addl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq %r14, %rdi
movq %r15, %rsi
movb $0x1, %al
callq 0xe670
incl %r13d
movl 0x240(%rbx), %ecx
cmpl %ecx, %r13d
jl 0x37e2c
movl 0x23c(%rbx), %eax
incl %r12d
cmpl %eax, %r12d
jl 0x37e25
movl 0x238(%rbx), %ecx
incl %ebp
cmpl %ecx, %ebp
jl 0x37e18
leaq 0x7061f(%rip), %rdi     # 0xa84ae
movl $0x5, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0xe8b0
movq %r14, %rdi
callq 0xe430
movl 0x24c(%rbx), %ebx
leaq 0x70(%rsp), %rdi
callq 0x280f4
jmp 0x37ece
leaq 0x6a4f8(%rip), %rdi     # 0xa23ba
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0x719d2
movl %ebx, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq