// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1028, %rsp           # imm = 0x1028
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x20(%rsp), %r14
movl $0x7ff, %edx            # imm = 0x7FF
movq %r14, %rdi
callq 0xe240
movq %r14, %rdi
movl $0x2e, %esi
callq 0xe4c0
testq %rax, %rax
je 0x38321
movb $0x0, (%rax)
leaq 0x20(%rsp), %rdi
callq 0xe1e0
movl $0x7a69732e, 0x20(%rsp,%rax) # imm = 0x7A69732E
movw $0x65, 0x24(%rsp,%rax)
leaq 0x820(%rsp), %r14
movl $0x7ff, %edx            # imm = 0x7FF
movq %r14, %rdi
movq %r12, %rsi
callq 0xe240
movq %r14, %rdi
movl $0x2e, %esi
callq 0xe4c0
testq %rax, %rax
je 0x38367
movb $0x0, (%rax)
leaq 0x820(%rsp), %rdi
callq 0xe1e0
movl $0x66782e, 0x820(%rsp,%rax) # imm = 0x66782E
movl 0x238(%rbx), %r14d
movl 0x23c(%rbx), %r15d
movl 0x240(%rbx), %ebp
leaq 0x702d6(%rip), %rsi     # 0xa8670
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
movq %r13, 0x8(%rsp)
je 0x383f4
leaq 0x6f40b(%rip), %rsi     # 0xa77bd
leaq 0x20(%rsp), %rdi
callq 0xe530
movq %rax, %r13
testq %rax, %rax
je 0x38492
leaq 0x702a5(%rip), %rsi     # 0xa8674
movq %r13, %rdi
movq 0x8(%rsp), %rdx
movl %r14d, %ecx
movl %r15d, %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0xe670
movq %r13, %rdi
callq 0xe430
jmp 0x384a5
movl %r14d, 0x4(%rsp)
movl %r15d, 0x18(%rsp)
movl %ebp, 0x14(%rsp)
leaq 0x6a67b(%rip), %rsi     # 0xa2a84
leaq 0x20(%rsp), %rdi
callq 0xe530
movq %rax, %r15
testq %rax, %rax
je 0x38817
leaq 0x1c(%rsp), %r14
movl $0x1, (%r14)
leaq 0x4(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0xe8b0
leaq 0x18(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0xe8b0
leaq 0x14(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0xe8b0
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rcx
callq 0xe8b0
movq %r15, %rdi
callq 0xe430
jmp 0x3882a
leaq 0x700b2(%rip), %rdi     # 0xa854b
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x72a1e
testq %r13, %r13
movq 0x8(%rsp), %r13
je 0x38833
leaq 0x6f303(%rip), %rsi     # 0xa77bd
leaq 0x820(%rsp), %rdi
callq 0xe530
movq %rax, %r15
testq %rax, %rax
je 0x3859d
movsd 0x118(%rbx), %xmm0
movsd 0x120(%rbx), %xmm1
movsd 0x128(%rbx), %xmm2
movsd 0x130(%rbx), %xmm3
leaq 0x701b0(%rip), %r13     # 0xa86aa
movq %r15, %rdi
movq %r13, %rsi
movb $0x4, %al
callq 0xe670
movsd 0x138(%rbx), %xmm0
movsd 0x140(%rbx), %xmm1
movsd 0x148(%rbx), %xmm2
movsd 0x150(%rbx), %xmm3
movq %r15, %rdi
movq %r13, %rsi
movb $0x4, %al
callq 0xe670
movsd 0x158(%rbx), %xmm0
movsd 0x160(%rbx), %xmm1
movsd 0x168(%rbx), %xmm2
movsd 0x170(%rbx), %xmm3
movq %r15, %rdi
movq %r13, %rsi
movb $0x4, %al
callq 0xe670
movsd 0x178(%rbx), %xmm0
movsd 0x180(%rbx), %xmm1
movsd 0x188(%rbx), %xmm2
movsd 0x190(%rbx), %xmm3
movq %r15, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %r13
movb $0x4, %al
callq 0xe670
movq %r15, %rdi
callq 0xe430
jmp 0x385b3
leaq 0x700e0(%rip), %rdi     # 0xa8684
leaq 0x820(%rsp), %rsi
xorl %eax, %eax
callq 0x72a1e
xorl %ebp, %ebp
testq %r15, %r15
je 0x38835
leaq 0x6a4bf(%rip), %rsi     # 0xa2a84
movq %r12, %rdi
callq 0xe530
testq %rax, %rax
je 0x38802
movq %rax, %r15
leaq 0x6f39d(%rip), %rsi     # 0xa797d
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x387da
leaq 0x6f38f(%rip), %rsi     # 0xa7986
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x387da
leaq 0x6f381(%rip), %rsi     # 0xa798f
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x387da
leaq 0x6f372(%rip), %rsi     # 0xa7997
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x387da
leaq 0x6f183(%rip), %rsi     # 0xa77bf
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x38849
leaq 0x6f34c(%rip), %rsi     # 0xa799f
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x38849
leaq 0x6f33d(%rip), %rsi     # 0xa79a7
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x388f3
leaq 0x6f32d(%rip), %rsi     # 0xa79ae
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x388d9
leaq 0x6f310(%rip), %rsi     # 0xa79a8
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x388d9
leaq 0x6f305(%rip), %rsi     # 0xa79b4
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x3890d
leaq 0x6f2f5(%rip), %rsi     # 0xa79bb
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x3890d
leaq 0x6f2e5(%rip), %rsi     # 0xa79c2
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x38927
leaq 0x6f2c1(%rip), %rsi     # 0xa79b5
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x38927
leaq 0x6f2bd(%rip), %rsi     # 0xa79c8
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x38941
leaq 0x6f2ad(%rip), %rsi     # 0xa79cf
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x38941
leaq 0x6f29d(%rip), %rsi     # 0xa79d6
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x3895b
leaq 0x6f279(%rip), %rsi     # 0xa79c9
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x3895b
leaq 0x6f275(%rip), %rsi     # 0xa79dc
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x38975
leaq 0x6f265(%rip), %rsi     # 0xa79e3
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x38975
leaq 0x6f255(%rip), %rsi     # 0xa79ea
movq %r13, %rdi
callq 0xe640
testl %eax, %eax
je 0x3898f
leaq 0x6f231(%rip), %rsi     # 0xa79dd
movq 0x8(%rsp), %rdi
callq 0xe640
testl %eax, %eax
je 0x3898f
leaq 0x6f22b(%rip), %rdi     # 0xa79f0
xorl %ebp, %ebp
leaq 0x20(%rsp), %rdx
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x72a1e
jmp 0x38835
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x39594
testl %eax, %eax
je 0x38835
movq %r15, %rdi
callq 0xe430
movl $0x1, %ebp
jmp 0x38835
leaq 0x6f159(%rip), %rdi     # 0xa7962
xorl %ebp, %ebp
movq %r12, %rsi
xorl %eax, %eax
callq 0x72a1e
jmp 0x38835
leaq 0x6fd2d(%rip), %rdi     # 0xa854b
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x72a1e
testq %r15, %r15
jne 0x384b3
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0x24c(%rbx), %r14
testq %r14, %r14
setle %al
jle 0x388cc
movq 0x230(%rbx), %r12
xorps %xmm0, %xmm0
cvtsd2ss (%r12), %xmm0
leaq 0x4(%rsp), %rdi
movss %xmm0, (%rdi)
movl $0x1, %ebx
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0xe8b0
cmpq $0x1, %rax
jne 0x38835
movq %rbx, %r13
cmpq %rbx, %r14
je 0x388c6
xorps %xmm0, %xmm0
cvtsd2ss (%r12,%r13,8), %xmm0
movss %xmm0, 0x4(%rsp)
movl $0x4, %esi
movl $0x1, %edx
leaq 0x4(%rsp), %rdi
movq %r15, %rcx
callq 0xe8b0
leaq 0x1(%r13), %rbx
cmpq $0x1, %rax
je 0x3888e
cmpq %r14, %r13
setae %al
testb %al, %al
jne 0x387f3
jmp 0x38835
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x396ff
jmp 0x387ef
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x39629
jmp 0x387ef
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x39794
jmp 0x387ef
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x3982c
jmp 0x387ef
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x398c2
jmp 0x387ef
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x3995a
jmp 0x387ef
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x399f2
jmp 0x387ef
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x39a88
jmp 0x387ef
nop