// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::WriteRawFile(char const*, char const*) const
int R3Grid::
WriteRawFile(const char *filename, const char *format) const
{
  // Get size file name
  char size_name[2048];
  strncpy(size_name, filename, 2047);
  char *ext = strrchr(size_name, '.');
  if (ext) *ext = '\0';
  strncat(size_name, ".size", 2047);

  // Get transformation file name
  char transformation_name[2048];
  strncpy(transformation_name, filename, 2047);
  ext = strrchr(transformation_name, '.');
  if (ext) *ext = '\0';
  strncat(transformation_name, ".xf", 2047);

  // Write size file
  if (!WriteRawSizeFile(size_name, grid_resolution[0], grid_resolution[1], grid_resolution[2], format)) return 0;

  // Write transformation file
  if (!WriteRawTransformationFile(transformation_name, world_to_grid_transform)) return 0;

  // Open raw file
  FILE *fp = fopen(filename, "wb");
  if (!fp) {
    RNFail("Unable to open raw file %s", filename);
    return 0;
  }

  // Write raw grid values
  if (!strcmp(format, "Double64") || !strcmp(format, "double64")) {
    if (!WriteRawValues<RNScalar64>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Float64") || !strcmp(format, "float64")) {
    if (!WriteRawValues<RNScalar64>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Float32") || !strcmp(format, "float32")) {
    if (!WriteRawValues<RNScalar32>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Uint64") || !strcmp(format, "Uint64")) {
    if (!WriteRawValues<RNUInt64>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Int64") || !strcmp(format, "int64")) {
    if (!WriteRawValues<RNInt64>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Uint32") || !strcmp(format, "uint32")) {
    if (!WriteRawValues<RNUInt32>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Int32") || !strcmp(format, "int32")) {
    if (!WriteRawValues<RNInt32>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Uint16") || !strcmp(format, "uint16")) {
    if (!WriteRawValues<RNUInt16>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Int16") || !strcmp(format, "int16")) {
    if (!WriteRawValues<RNInt16>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Uchar8") || !strcmp(format, "uchar8")) {
    if (!WriteRawValues<RNUChar8>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Char8") || !strcmp(format, "char8")) {
    if (!WriteRawValues<RNChar8>(fp, grid_values, grid_size)) return 0;
  } else {
    RNFail("Unrecognized format %s in %s\n", format, size_name);
    return 0;
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1038, %rsp           # imm = 0x1038
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
leaq 0x30(%rsp), %rbx
movl $0x7ff, %edx            # imm = 0x7FF
movq %rbx, %rdi
callq 0xe250
pushq $0x2e
popq %rsi
movq %rbx, %rdi
callq 0xe4e0
testq %rax, %rax
je 0x33ebd
movb $0x0, (%rax)
leaq 0x30(%rsp), %rdi
callq 0xe1e0
movl $0x7a69732e, 0x30(%rsp,%rax) # imm = 0x7A69732E
movw $0x65, 0x34(%rsp,%rax)
leaq 0x830(%rsp), %rbx
movl $0x7ff, %edx            # imm = 0x7FF
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe250
pushq $0x2e
popq %rsi
movq %rbx, %rdi
callq 0xe4e0
testq %rax, %rax
je 0x33f01
movb $0x0, (%rax)
leaq 0x830(%rsp), %rdi
callq 0xe1e0
movl $0x66782e, 0x830(%rsp,%rax) # imm = 0x66782E
movl 0x238(%r14), %r13d
movl 0x23c(%r14), %ebp
movl 0x240(%r14), %ebx
leaq 0x656e7(%rip), %rsi     # 0x9961c
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x33f8a
movq %r15, 0x8(%rsp)
leaq 0x6481c(%rip), %rsi     # 0x98769
leaq 0x30(%rsp), %rdi
callq 0xe550
testq %rax, %rax
je 0x34334
movq %rax, %r15
leaq 0x656b6(%rip), %rsi     # 0x99620
movq %rax, %rdi
movq 0x8(%rsp), %rdx
movl %r13d, %ecx
movl %ebp, %r8d
movl %ebx, %r9d
xorl %eax, %eax
callq 0xe6a0
movq %r15, %rdi
jmp 0x34019
movl %r13d, 0x10(%rsp)
movl %ebp, 0x28(%rsp)
movl %ebx, 0x24(%rsp)
leaq 0x5fa93(%rip), %rsi     # 0x93a31
leaq 0x30(%rsp), %rdi
callq 0xe550
testq %rax, %rax
je 0x34334
movq %rax, %rbx
movq %r15, 0x8(%rsp)
leaq 0x2c(%rsp), %r15
movl $0x1, (%r15)
leaq 0x10(%rsp), %rdi
pushq $0x4
popq %r13
pushq $0x1
popq %rbp
movq %r13, %rsi
movq %rbp, %rdx
movq %rax, %rcx
callq 0xe8e0
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0xe8e0
leaq 0x24(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0xe8e0
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0xe8e0
movq %rbx, %rdi
callq 0xe440
leaq 0x64744(%rip), %rsi     # 0x98769
leaq 0x830(%rsp), %rdi
callq 0xe550
testq %rax, %rax
je 0x34344
movq %rax, %rbx
movsd 0x118(%r14), %xmm0
movsd 0x120(%r14), %xmm1
movsd 0x128(%r14), %xmm2
movsd 0x130(%r14), %xmm3
leaq 0x655ed(%rip), %r13     # 0x99656
movq %rax, %rdi
movq %r13, %rsi
movb $0x4, %al
callq 0xe6a0
movsd 0x138(%r14), %xmm0
movsd 0x140(%r14), %xmm1
movsd 0x148(%r14), %xmm2
movsd 0x150(%r14), %xmm3
movq %rbx, %rdi
movq %r13, %rsi
movb $0x4, %al
callq 0xe6a0
movsd 0x158(%r14), %xmm0
movsd 0x160(%r14), %xmm1
movsd 0x168(%r14), %xmm2
movsd 0x170(%r14), %xmm3
movq %rbx, %rdi
movq %r13, %rsi
movb $0x4, %al
callq 0xe6a0
movsd 0x178(%r14), %xmm0
movsd 0x180(%r14), %xmm1
movsd 0x188(%r14), %xmm2
movsd 0x190(%r14), %xmm3
movq %rbx, %rdi
movq %r13, %rsi
movb $0x4, %al
callq 0xe6a0
movq %rbx, %rdi
callq 0xe440
leaq 0x5f919(%rip), %rsi     # 0x93a31
movq %r12, %rdi
callq 0xe550
testq %rax, %rax
je 0x34382
movq %rax, %rbx
leaq 0x647f6(%rip), %rsi     # 0x98929
movq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x34357
leaq 0x647e3(%rip), %rsi     # 0x98932
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x34357
leaq 0x647d5(%rip), %rsi     # 0x9893b
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x34357
leaq 0x647c6(%rip), %rsi     # 0x98943
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x34357
leaq 0x645d7(%rip), %rsi     # 0x9876b
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x343a9
leaq 0x647a0(%rip), %rsi     # 0x9894b
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x343a9
leaq 0x64791(%rip), %rsi     # 0x98953
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x34482
leaq 0x64781(%rip), %rsi     # 0x9895a
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x34416
leaq 0x64764(%rip), %rsi     # 0x98954
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x34416
leaq 0x64759(%rip), %rsi     # 0x98960
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x3451a
leaq 0x64749(%rip), %rsi     # 0x98967
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x3451a
leaq 0x64739(%rip), %rsi     # 0x9896e
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x34584
leaq 0x64715(%rip), %rsi     # 0x98961
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x34584
leaq 0x64711(%rip), %rsi     # 0x98974
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x34602
leaq 0x64701(%rip), %rsi     # 0x9897b
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x34602
leaq 0x646f1(%rip), %rsi     # 0x98982
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x3466a
leaq 0x646cd(%rip), %rsi     # 0x98975
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x3466a
movq %rbx, %r12
leaq 0x646c6(%rip), %rsi     # 0x98988
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x346e3
leaq 0x646b6(%rip), %rsi     # 0x9898f
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x346e3
leaq 0x646a6(%rip), %rsi     # 0x98996
movq %r15, %r13
movq %r15, %rdi
callq 0xe670
testl %eax, %eax
je 0x34746
leaq 0x6467f(%rip), %rsi     # 0x98989
movq %r13, %rdi
callq 0xe670
testl %eax, %eax
je 0x34746
leaq 0x6467b(%rip), %rdi     # 0x9899c
xorl %ebx, %ebx
leaq 0x30(%rsp), %rdx
movq %r13, %rsi
xorl %eax, %eax
callq 0x681ca
jmp 0x34395
leaq 0x651bc(%rip), %rdi     # 0x994f7
xorl %ebx, %ebx
leaq 0x30(%rsp), %rsi
jmp 0x3438e
leaq 0x652e5(%rip), %rdi     # 0x99630
xorl %ebx, %ebx
leaq 0x830(%rsp), %rsi
jmp 0x3438e
movq 0x230(%r14), %rsi
movl 0x24c(%r14), %edx
movq %rbx, %rdi
callq 0x34d0f
testl %eax, %eax
je 0x345fb
movq %rbx, %rdi
callq 0xe440
pushq $0x1
popq %rbx
jmp 0x34395
leaq 0x64585(%rip), %rdi     # 0x9890e
xorl %ebx, %ebx
movq %r12, %rsi
xorl %eax, %eax
callq 0x681ca
movl %ebx, %eax
addq $0x1038, %rsp           # imm = 0x1038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %r15
movq 0x230(%r14), %rbp
movslq 0x24c(%r14), %rax
xorl %ebx, %ebx
testl %eax, %eax
movq %rax, 0x8(%rsp)
cmovgl %eax, %ebx
movq %rbx, 0x18(%rsp)
negq %rbx
pushq $-0x1
popq %r13
pushq $0x4
popq %r14
pushq $0x1
popq %r12
leaq (%rbx,%r13), %rax
cmpq $-0x1, %rax
je 0x345e8
cvtsd2ss 0x8(%rbp,%r13,8), %xmm0
movss %xmm0, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0xe8e0
incq %r13
cmpq $0x1, %rax
je 0x343da
jmp 0x345ed
movq %rbx, %r15
movq 0x230(%r14), %rbp
movslq 0x24c(%r14), %rax
xorl %ebx, %ebx
testl %eax, %eax
movq %rax, 0x8(%rsp)
cmovgl %eax, %ebx
movq %rbx, 0x18(%rsp)
negq %rbx
pushq $-0x1
popq %r13
pushq $0x8
popq %r14
pushq $0x1
popq %r12
leaq (%rbx,%r13), %rax
cmpq $-0x1, %rax
je 0x345e8
cvttsd2si 0x8(%rbp,%r13,8), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0xe8e0
incq %r13
cmpq $0x1, %rax
je 0x34447
jmp 0x345ed
movslq 0x24c(%r14), %rax
xorl %ecx, %ecx
testl %eax, %eax
movq %rax, 0x8(%rsp)
cmovgl %eax, %ecx
movq 0x230(%r14), %r13
movq %rcx, 0x18(%rsp)
movq %rcx, %r14
negq %r14
pushq $-0x1
popq %rbp
pushq $0x8
popq %r15
pushq $0x1
popq %r12
leaq (%r14,%rbp), %rax
cmpq $-0x1, %rax
je 0x34505
movsd 0x8(%r13,%rbp,8), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
subsd 0x5fa9d(%rip), %xmm0    # 0x93f70
cvttsd2si %xmm0, %rdx
sarq $0x3f, %rcx
andq %rcx, %rdx
orq %rax, %rdx
movq %rdx, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0xe8e0
incq %rbp
cmpq $0x1, %rax
je 0x344b2
jmp 0x3450a
movq 0x18(%rsp), %rbp
cmpq 0x8(%rsp), %rbp
jge 0x34375
jmp 0x345fb
movq 0x230(%r14), %rbp
movslq 0x24c(%r14), %rax
xorl %r14d, %r14d
testl %eax, %eax
movq %rax, 0x8(%rsp)
cmovgl %eax, %r14d
movq %r14, 0x18(%rsp)
negq %r14
pushq $-0x1
popq %r13
pushq $0x4
popq %r15
pushq $0x1
popq %r12
leaq (%r14,%r13), %rax
cmpq $-0x1, %rax
je 0x346ce
cvttsd2si 0x8(%rbp,%r13,8), %rax
movl %eax, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0xe8e0
incq %r13
cmpq $0x1, %rax
je 0x3454a
jmp 0x346d3
movq %rbx, %r15
movq 0x230(%r14), %rbp
movslq 0x24c(%r14), %rax
xorl %ebx, %ebx
testl %eax, %eax
movq %rax, 0x8(%rsp)
cmovgl %eax, %ebx
movq %rbx, 0x18(%rsp)
negq %rbx
pushq $-0x1
popq %r13
pushq $0x4
popq %r14
pushq $0x1
popq %r12
leaq (%rbx,%r13), %rax
cmpq $-0x1, %rax
je 0x345e8
cvttsd2si 0x8(%rbp,%r13,8), %eax
movl %eax, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0xe8e0
incq %r13
cmpq $0x1, %rax
je 0x345b5
jmp 0x345ed
movq 0x18(%rsp), %r13
cmpq 0x8(%rsp), %r13
movq %r15, %rbx
jge 0x34375
xorl %ebx, %ebx
jmp 0x34395
movq 0x230(%r14), %rbp
movslq 0x24c(%r14), %rax
xorl %r14d, %r14d
testl %eax, %eax
movq %rax, 0x8(%rsp)
cmovgl %eax, %r14d
movq %r14, 0x18(%rsp)
negq %r14
pushq $-0x1
popq %r13
pushq $0x2
popq %r15
pushq $0x1
popq %r12
leaq (%r14,%r13), %rax
cmpq $-0x1, %rax
je 0x346ce
cvttsd2si 0x8(%rbp,%r13,8), %eax
movw %ax, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0xe8e0
incq %r13
cmpq $0x1, %rax
je 0x34632
jmp 0x346d3
movq 0x230(%r14), %rbp
movslq 0x24c(%r14), %rax
xorl %r14d, %r14d
testl %eax, %eax
movq %rax, 0x8(%rsp)
cmovgl %eax, %r14d
movq %r14, 0x18(%rsp)
negq %r14
pushq $-0x1
popq %r13
pushq $0x2
popq %r15
pushq $0x1
popq %r12
leaq (%r14,%r13), %rax
cmpq $-0x1, %rax
je 0x346ce
cvttsd2si 0x8(%rbp,%r13,8), %eax
movw %ax, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0xe8e0
incq %r13
cmpq $0x1, %rax
je 0x3469a
jmp 0x346d3
movq 0x18(%rsp), %r13
cmpq 0x8(%rsp), %r13
jge 0x34375
jmp 0x345fb
movq 0x230(%r14), %r13
movslq 0x24c(%r14), %rax
xorl %ebx, %ebx
testl %eax, %eax
movq %rax, 0x8(%rsp)
cmovgl %eax, %ebx
movq %rbx, 0x18(%rsp)
negq %rbx
pushq $-0x1
popq %rbp
leaq 0x10(%rsp), %r14
pushq $0x1
popq %r15
leaq (%rbx,%rbp), %rax
cmpq $-0x1, %rax
je 0x347a5
cvttsd2si 0x8(%r13,%rbp,8), %eax
movb %al, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0xe8e0
incq %rbp
cmpq $0x1, %rax
je 0x34711
jmp 0x347aa
movq 0x230(%r14), %r13
movslq 0x24c(%r14), %rax
xorl %ebx, %ebx
testl %eax, %eax
movq %rax, 0x8(%rsp)
cmovgl %eax, %ebx
movq %rbx, 0x18(%rsp)
negq %rbx
pushq $-0x1
popq %rbp
leaq 0x10(%rsp), %r14
pushq $0x1
popq %r15
leaq (%rbx,%rbp), %rax
cmpq $-0x1, %rax
je 0x347a5
cvttsd2si 0x8(%r13,%rbp,8), %eax
movb %al, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0xe8e0
incq %rbp
cmpq $0x1, %rax
je 0x34774
jmp 0x347aa
movq 0x18(%rsp), %rbp
cmpq 0x8(%rsp), %rbp
movq %r12, %rbx
jge 0x34375
jmp 0x345fb
nop