// File: /workspace/github_cpp_makefile_star2_O3/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, 0x8(%rsp)
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 0x37f25
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 0x37f6b
movb $0x0, (%rax)
leaq 0x820(%rsp), %rdi
callq 0xe1e0
movl $0x66782e, 0x820(%rsp,%rax) # imm = 0x66782E
movl 0x238(%rbx), %r13d
movl 0x23c(%rbx), %r15d
movl 0x240(%rbx), %ebp
leaq 0x706ce(%rip), %rsi     # 0xa866c
movq 0x8(%rsp), %rdi
callq 0xe640
testl %eax, %eax
je 0x37ff0
leaq 0x6f806(%rip), %rsi     # 0xa77b9
leaq 0x20(%rsp), %rdi
callq 0xe530
testq %rax, %rax
je 0x3838e
movq %rax, %r14
leaq 0x706a0(%rip), %rsi     # 0xa8670
movq %rax, %rdi
movq 0x8(%rsp), %rdx
movl %r13d, %ecx
movl %r15d, %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0xe670
movq %r14, %rdi
jmp 0x38085
movl %r13d, 0x4(%rsp)
movl %r15d, 0x18(%rsp)
movl %ebp, 0x14(%rsp)
leaq 0x6aa7c(%rip), %rsi     # 0xa2a81
leaq 0x20(%rsp), %rdi
callq 0xe530
testq %rax, %rax
je 0x3838e
movq %rax, %r15
leaq 0x1c(%rsp), %r13
movl $0x1, (%r13)
leaq 0x4(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rax, %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 %r13, %rdi
movq %r15, %rcx
callq 0xe8b0
movq %r15, %rdi
callq 0xe430
leaq 0x6f728(%rip), %rsi     # 0xa77b9
leaq 0x820(%rsp), %rdi
callq 0xe530
testq %rax, %rax
je 0x3839e
movq %rax, %r15
movsd 0x118(%rbx), %xmm0
movsd 0x120(%rbx), %xmm1
movsd 0x128(%rbx), %xmm2
movsd 0x130(%rbx), %xmm3
leaq 0x705d5(%rip), %r13     # 0xa86a6
movq %rax, %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
movb $0x4, %al
callq 0xe670
movq %r15, %rdi
callq 0xe430
leaq 0x6a90d(%rip), %rsi     # 0xa2a81
movq %r12, %rdi
callq 0xe530
testq %rax, %rax
je 0x383d9
movq %rax, %r15
leaq 0x6f7ea(%rip), %rsi     # 0xa7979
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x383b1
leaq 0x6f7d7(%rip), %rsi     # 0xa7982
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x383b1
leaq 0x6f7c9(%rip), %rsi     # 0xa798b
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x383b1
leaq 0x6f7ba(%rip), %rsi     # 0xa7993
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x383b1
leaq 0x6f5cb(%rip), %rsi     # 0xa77bb
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x38404
leaq 0x6f794(%rip), %rsi     # 0xa799b
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x38404
leaq 0x6f785(%rip), %rsi     # 0xa79a3
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x384aa
leaq 0x6f775(%rip), %rsi     # 0xa79aa
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x38490
leaq 0x6f758(%rip), %rsi     # 0xa79a4
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x38490
leaq 0x6f74d(%rip), %rsi     # 0xa79b0
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x384c4
leaq 0x6f73d(%rip), %rsi     # 0xa79b7
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x384c4
leaq 0x6f72d(%rip), %rsi     # 0xa79be
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x384de
leaq 0x6f709(%rip), %rsi     # 0xa79b1
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x384de
leaq 0x6f705(%rip), %rsi     # 0xa79c4
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x384f8
leaq 0x6f6f5(%rip), %rsi     # 0xa79cb
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x384f8
leaq 0x6f6e5(%rip), %rsi     # 0xa79d2
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x38512
leaq 0x6f6c1(%rip), %rsi     # 0xa79c5
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x38512
leaq 0x6f6bd(%rip), %rsi     # 0xa79d8
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x3852c
leaq 0x6f6ad(%rip), %rsi     # 0xa79df
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x3852c
leaq 0x6f69d(%rip), %rsi     # 0xa79e6
movq %r14, %rdi
callq 0xe640
testl %eax, %eax
je 0x38546
leaq 0x6f679(%rip), %rsi     # 0xa79d9
movq 0x8(%rsp), %rdi
callq 0xe640
testl %eax, %eax
je 0x38546
leaq 0x6f673(%rip), %rdi     # 0xa79ec
xorl %ebx, %ebx
leaq 0x20(%rsp), %rdx
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x719d2
jmp 0x383ec
leaq 0x701b2(%rip), %rdi     # 0xa8547
xorl %ebx, %ebx
leaq 0x20(%rsp), %rsi
jmp 0x383e5
leaq 0x702db(%rip), %rdi     # 0xa8680
xorl %ebx, %ebx
leaq 0x820(%rsp), %rsi
jmp 0x383e5
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x39132
testl %eax, %eax
je 0x38400
movq %r15, %rdi
callq 0xe430
movl $0x1, %ebx
jmp 0x383ec
leaq 0x6f57e(%rip), %rdi     # 0xa795e
xorl %ebx, %ebx
movq %r12, %rsi
xorl %eax, %eax
callq 0x719d2
movl %ebx, %eax
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
jmp 0x383ec
movslq 0x24c(%rbx), %r12
testq %r12, %r12
jle 0x383ca
movq 0x230(%rbx), %r13
xorps %xmm0, %xmm0
cvtsd2ss (%r13), %xmm0
leaq 0x4(%rsp), %rdi
movss %xmm0, (%rdi)
movl $0x1, %r14d
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0xe8b0
xorl %ebx, %ebx
cmpq $0x1, %rax
jne 0x383ec
movq %r14, %rbp
cmpq %r14, %r12
je 0x38482
xorps %xmm0, %xmm0
cvtsd2ss (%r13,%rbp,8), %xmm0
movss %xmm0, 0x4(%rsp)
movl $0x4, %esi
movl $0x1, %edx
leaq 0x4(%rsp), %rdi
movq %r15, %rcx
callq 0xe8b0
leaq 0x1(%rbp), %r14
cmpq $0x1, %rax
je 0x38449
cmpq %r12, %rbp
jae 0x383ca
jmp 0x383ec
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x392a9
jmp 0x383c6
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x391cf
jmp 0x383c6
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x39346
jmp 0x383c6
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x393e6
jmp 0x383c6
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x39484
jmp 0x383c6
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x39524
jmp 0x383c6
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x395c4
jmp 0x383c6
movq 0x230(%rbx), %rsi
movl 0x24c(%rbx), %edx
movq %r15, %rdi
callq 0x39662
jmp 0x383c6