// File: /workspace/github_cpp_makefile_star2_O1/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 0x6f73f(%rip), %rsi     # 0xa77bd
movq %r15, %rdi
callq 0xe530
testq %rax, %rax
je 0x382b8
movq %rax, %r14
leaq 0x58(%rsp), %r15
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r15, %rdi
callq 0x3ca26
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 0x3ca26
movsd (%r15), %xmm0
movsd 0x8(%r15), %xmm1
movsd 0x10(%r15), %xmm2
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x3ca26
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3d342
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd 0x10(%r12), %xmm2
leaq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x3ca26
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3d342
leaq 0x70(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x27542
movsd 0x228(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
movl 0x238(%rbx), %edx
movl 0x23c(%rbx), %ecx
movl 0x240(%rbx), %r8d
leaq 0x70262(%rip), %rsi     # 0xa83d4
xorl %ebp, %ebp
movq %r14, %rdi
xorl %eax, %eax
callq 0xe670
movsd 0x8(%r13), %xmm0
movsd 0x10(%r13), %xmm1
movsd 0x18(%r13), %xmm2
leaq 0x7026b(%rip), %rsi     # 0xa8402
movq %r14, %rdi
movb $0x3, %al
callq 0xe670
leaq 0x7026e(%rip), %rsi     # 0xa8416
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 0x70269(%rip), %rsi     # 0xa8441
movq %r14, %rdi
xorl %eax, %eax
callq 0xe670
movl 0x23c(%rbx), %edx
imull 0x238(%rbx), %edx
imull 0x240(%rbx), %edx
leaq 0x70275(%rip), %rsi     # 0xa8472
movq %r14, %rdi
xorl %eax, %eax
callq 0xe670
cmpl $0x0, 0x238(%rbx)
jle 0x38285
leaq 0x70225(%rip), %r15     # 0xa843c
cmpl $0x0, 0x23c(%rbx)
jle 0x3827b
xorl %r12d, %r12d
cmpl $0x0, 0x240(%rbx)
jle 0x3826f
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
cmpl 0x240(%rbx), %r13d
jl 0x3822f
incl %r12d
cmpl 0x23c(%rbx), %r12d
jl 0x38223
incl %ebp
cmpl 0x238(%rbx), %ebp
jl 0x38217
leaq 0x70226(%rip), %rdi     # 0xa84b2
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 0x28348
jmp 0x382cb
leaq 0x6a0fe(%rip), %rdi     # 0xa23bd
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0x72a1e
movl %ebx, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop