// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::ReadRawFile(char const*)
int R3Grid::
ReadRawFile(const char *filename)
{
  // 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);

  // Read size file
  char format[2048];
  int xres, yres, zres;
  if (!ReadRawSizeFile(size_name, xres, yres, zres, format)) return 0;
  int new_size = xres * yres * zres;
  if (new_size == 0) {
    RNFail("Zero dimensions in size file %s", size_name);
    return 0;
  }

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

  // Re-allocate grid values
  if (!grid_values || (new_size > grid_size)) { 
    if (grid_values) delete [] grid_values;
    grid_values = new RNScalar [ new_size ];
    assert(grid_values);
  }

  // Update grid resolution variables
  grid_resolution[0] = xres;
  grid_resolution[1] = yres;
  grid_resolution[2] = zres;
  grid_row_size = grid_resolution[0];
  grid_sheet_size = grid_row_size * grid_resolution[1];
  grid_size = grid_sheet_size * grid_resolution[2];
  if (grid_size <= 0) {
    RNFail("Invalid grid size (%d) in file", grid_size);
    return 0;
  }

  // Read raw grid values
  if (!strcmp(format, "Double64") || !strcmp(format, "double64")) {
    if (!ReadRawValues<RNScalar64>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Float64") || !strcmp(format, "float64")) {
    if (!ReadRawValues<RNScalar64>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Float32") || !strcmp(format, "float32")) {
    if (!ReadRawValues<RNScalar32>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Uint64") || !strcmp(format, "Uint64")) {
    if (!ReadRawValues<RNUInt64>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Int64") || !strcmp(format, "int64")) {
    if (!ReadRawValues<RNInt64>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Uint32") || !strcmp(format, "uint32")) {
    if (!ReadRawValues<RNUInt32>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Int32") || !strcmp(format, "int32")) {
    if (!ReadRawValues<RNInt32>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Uint16") || !strcmp(format, "uint16")) {
    if (!ReadRawValues<RNUInt16>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Int16") || !strcmp(format, "int16")) {
    if (!ReadRawValues<RNInt16>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Uchar8") || !strcmp(format, "uchar8")) {
    if (!ReadRawValues<RNUChar8>(fp, grid_values, grid_size)) return 0;
  } else if (!strcmp(format, "Char8") || !strcmp(format, "char8")) {
    if (!ReadRawValues<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);

  // Read transformation file
  R3Affine transformation;
  if (ReadRawTransformationFile(transformation_name, transformation)) {
    SetWorldToGridTransformation(transformation);
  }

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2128, %rsp           # imm = 0x2128
movq %rsi, %r15
movq %rdi, 0x10(%rsp)
leaq 0x1120(%rsp), %rbx
movl $0x7ff, %edx            # imm = 0x7FF
movq %rbx, %rdi
callq 0xe240
movq %rbx, %rdi
movl $0x2e, %esi
callq 0xe4c0
testq %rax, %rax
je 0x37661
movb $0x0, (%rax)
leaq 0x1120(%rsp), %rdi
callq 0xe1e0
movl $0x7a69732e, 0x1120(%rsp,%rax) # imm = 0x7A69732E
movw $0x65, 0x1124(%rsp,%rax)
leaq 0x1920(%rsp), %rbx
movl $0x7ff, %edx            # imm = 0x7FF
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe240
movq %rbx, %rdi
movl $0x2e, %esi
callq 0xe4c0
testq %rax, %rax
je 0x376b0
movb $0x0, (%rax)
leaq 0x1920(%rsp), %rdi
callq 0xe1e0
movl $0x66782e, 0x1920(%rsp,%rax) # imm = 0x66782E
leaq 0x746c4(%rip), %rsi     # 0xabd93
leaq 0x1120(%rsp), %rdi
callq 0xe530
testq %rax, %rax
je 0x377e6
movq %rax, %rbx
leaq 0x920(%rsp), %rdi
movl $0x800, %esi            # imm = 0x800
movq %rax, %rdx
callq 0xe730
testq %rax, %rax
je 0x377fe
movq %rbx, %rdi
callq 0xe430
leaq 0x920(%rsp), %rdi
movl $0x28, %esi
callq 0xe1a0
testq %rax, %rax
je 0x377fc
leaq 0x920(%rsp), %rdi
movl $0x29, %esi
callq 0xe1a0
testq %rax, %rax
je 0x377fc
leaq 0x70e38(%rip), %rsi     # 0xa8583
leaq 0x920(%rsp), %rdi
callq 0xe710
testq %rax, %rax
je 0x37a64
leaq 0xa0(%rsp), %rdi
movl $0x7ff, %edx            # imm = 0x7FF
movq %rax, %rsi
callq 0xe240
leaq 0x70e30(%rip), %rsi     # 0xa85ad
xorl %edi, %edi
callq 0xe710
testq %rax, %rax
je 0x37a70
movq %rax, %rdi
callq 0xe700
movl %eax, %ebx
leaq 0x70e0f(%rip), %rsi     # 0xa85ad
xorl %edi, %edi
callq 0xe710
testq %rax, %rax
movl %ebx, 0xc(%rsp)
je 0x37c17
movq %rax, %rdi
callq 0xe700
movl %eax, %r14d
leaq 0x70de9(%rip), %rsi     # 0xa85ad
xorl %edi, %edi
callq 0xe710
testq %rax, %rax
je 0x37c23
movq %rax, %rdi
callq 0xe700
movl %eax, %ebx
xorl %r12d, %r12d
jmp 0x378c2
leaq 0x70d5e(%rip), %rdi     # 0xa854b
leaq 0x1120(%rsp), %rsi
xorl %eax, %eax
callq 0x72a1e
jmp 0x37814
leaq 0x70d62(%rip), %rdi     # 0xa8567
leaq 0x1120(%rsp), %rsi
xorl %eax, %eax
callq 0x72a1e
leaq 0x6ad93(%rip), %rsi     # 0xa25ae
leaq 0x1120(%rsp), %rdi
callq 0xe530
testq %rax, %rax
je 0x3786c
movq %rax, %rbx
leaq 0x920(%rsp), %rdi
movl $0x4, %esi
movl $0x3, %edx
movq %rax, %rcx
callq 0xe6c0
cmpq $0x3, %rax
setne %r12b
je 0x37887
leaq 0x70d0c(%rip), %rdi     # 0xa8567
leaq 0x1120(%rsp), %rsi
xorl %eax, %eax
callq 0x72a1e
jmp 0x37885
leaq 0x70cd8(%rip), %rdi     # 0xa854b
leaq 0x1120(%rsp), %rsi
xorl %eax, %eax
callq 0x72a1e
movb $0x1, %r12b
jmp 0x378c2
movq %rbx, %rdi
callq 0xe430
movl 0x920(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0x924(%rsp), %r14d
movl 0x928(%rsp), %ebx
leaq 0x700cd(%rip), %rsi     # 0xa797d
leaq 0xa0(%rsp), %rdi
movl $0x7ff, %edx            # imm = 0x7FF
callq 0xe240
xorl %ebp, %ebp
testb %r12b, %r12b
jne 0x37c03
movl %r14d, %r13d
imull 0xc(%rsp), %r14d
movl %r14d, %r12d
imull %ebx, %r12d
testl %r12d, %r12d
je 0x37a21
leaq 0x6acc1(%rip), %rsi     # 0xa25ae
movq %r15, %rdi
callq 0xe530
testq %rax, %rax
je 0x37a34
movq %rax, %r8
movq 0x10(%rsp), %r15
movq 0x230(%r15), %rdi
testq %rdi, %rdi
je 0x3791b
cmpl 0x24c(%r15), %r12d
jle 0x37950
movq %r8, 0x18(%rsp)
testq %rdi, %rdi
je 0x3792a
callq 0xe5b0
movslq %r12d, %rax
shlq $0x3, %rax
testl %r12d, %r12d
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0xe030
movq %rax, 0x230(%r15)
movq 0x18(%rsp), %r8
movl 0xc(%rsp), %eax
movl %eax, 0x238(%r15)
movl %r13d, 0x23c(%r15)
movl %ebx, 0x240(%r15)
movl %eax, 0x244(%r15)
movl %r14d, 0x248(%r15)
movl %r12d, 0x24c(%r15)
testl %r12d, %r12d
jle 0x37a4c
movabsq $0x3436656c62756f44, %rax # imm = 0x3436656C62756F44
movq 0xa0(%rsp), %rcx
xorq %rax, %rcx
movzbl 0xa8(%rsp), %edx
orq %rcx, %rdx
je 0x37a9e
addq $0x20, %rax
xorq 0xa0(%rsp), %rax
movzbl 0xa8(%rsp), %ecx
orq %rax, %rcx
je 0x37a9e
movq 0xa0(%rsp), %rax
movabsq $0x343674616f6c45, %rcx # imm = 0x343674616F6C45
cmpq %rcx, %rax
jg 0x37a7c
movabsq $0x323374616f6c46, %rcx # imm = 0x323374616F6C46
cmpq %rcx, %rax
je 0x37a07
movabsq $0x323374616f6c66, %rcx # imm = 0x323374616F6C66
cmpq %rcx, %rax
jne 0x37c2f
movq 0x230(%r15), %rsi
movq %r8, %rdi
movl %r12d, %edx
movq %r8, %rbx
callq 0x39011
jmp 0x37ab3
leaq 0x6ff1a(%rip), %rdi     # 0xa7942
xorl %ebp, %ebp
leaq 0x1120(%rsp), %rsi
jmp 0x37a40
leaq 0x6ff27(%rip), %rdi     # 0xa7962
xorl %ebp, %ebp
movq %r15, %rsi
xorl %eax, %eax
callq 0x72a1e
jmp 0x37c03
leaq 0x6fdf0(%rip), %rdi     # 0xa7843
xorl %ebp, %ebp
movl %r12d, %esi
xorl %eax, %eax
callq 0x72a1e
jmp 0x37c03
leaq 0x70b1a(%rip), %rdi     # 0xa8585
jmp 0x37805
leaq 0x70b39(%rip), %rdi     # 0xa85b0
jmp 0x37805
movabsq $0x343674616f6c66, %rcx # imm = 0x343674616F6C66
cmpq %rcx, %rax
je 0x37a9e
movabsq $0x343674616f6c46, %rcx # imm = 0x343674616F6C46
cmpq %rcx, %rax
jne 0x37c2f
movq 0x230(%r15), %rsi
movq %r8, %rdi
movl %r12d, %edx
movq %r8, %rbx
callq 0x38f80
testl %eax, %eax
je 0x37c03
movq %rbx, %rdi
callq 0xe430
leaq 0x920(%rsp), %rdi
callq 0x2a1e0
leaq 0x742bc(%rip), %rsi     # 0xabd93
leaq 0x1920(%rsp), %rdi
callq 0xe530
testq %rax, %rax
je 0x37bf1
movq %rax, %rbx
leaq 0x28(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x38(%rsp), %r9
leaq 0x68(%rsp), %r13
leaq 0x70(%rsp), %rbp
leaq 0x78(%rsp), %r10
leaq 0x80(%rsp), %r11
leaq 0x88(%rsp), %r14
leaq 0x90(%rsp), %r15
leaq 0x98(%rsp), %r12
leaq 0x70ae4(%rip), %rsi     # 0xa8619
leaq 0x20(%rsp), %rdx
movq %rax, %rdi
xorl %eax, %eax
pushq %r12
pushq %r15
movq 0x20(%rsp), %r15
pushq %r14
pushq %r11
pushq %r10
pushq %rbp
pushq %r13
leaq 0x98(%rsp), %r10
pushq %r10
leaq 0x98(%rsp), %r10
pushq %r10
leaq 0x98(%rsp), %r10
pushq %r10
leaq 0x98(%rsp), %r10
pushq %r10
leaq 0x98(%rsp), %r10
pushq %r10
callq 0xe840
addq $0x60, %rsp
movl %eax, %ebp
cmpl $0x10, %eax
jne 0x37bc6
movq %rbx, %rdi
callq 0xe430
leaq 0x8a0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x2c6ae
leaq 0x920(%rsp), %rdi
leaq 0x8a0(%rsp), %rsi
xorl %edx, %edx
callq 0x2a8d2
jmp 0x37bdc
leaq 0x70a7d(%rip), %rdi     # 0xa864a
leaq 0x1920(%rsp), %rsi
xorl %eax, %eax
callq 0x72a1e
cmpl $0x10, %ebp
jne 0x37bf1
leaq 0x920(%rsp), %rsi
movq %r15, %rdi
callq 0x3336c
leaq 0x920(%rsp), %rdi
callq 0x2a27c
movl $0x1, %ebp
movl %ebp, %eax
addq $0x2128, %rsp           # imm = 0x2128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x709b5(%rip), %rdi     # 0xa85d3
jmp 0x37805
leaq 0x709cc(%rip), %rdi     # 0xa85f6
jmp 0x37805
movl $0x746e6955, %eax       # imm = 0x746E6955
xorl 0xa0(%rsp), %eax
movl $0x343674, %ecx         # imm = 0x343674
xorl 0xa3(%rsp), %ecx
orl %eax, %ecx
je 0x37e3d
movl $0x36746e49, %eax       # imm = 0x36746E49
xorl 0xa0(%rsp), %eax
movzwl 0xa4(%rsp), %ecx
xorl $0x34, %ecx
orl %eax, %ecx
je 0x37e23
movl $0x36746e69, %eax       # imm = 0x36746E69
xorl 0xa0(%rsp), %eax
movzwl 0xa4(%rsp), %ecx
xorl $0x34, %ecx
orl %eax, %ecx
je 0x37e23
movl $0x746e6955, %ecx       # imm = 0x746E6955
xorl 0xa0(%rsp), %ecx
movl $0x323374, %eax         # imm = 0x323374
movl 0xa3(%rsp), %edx
xorl %eax, %edx
orl %ecx, %edx
je 0x37e57
movl $0x746e6975, %ecx       # imm = 0x746E6975
xorl 0xa0(%rsp), %ecx
xorl 0xa3(%rsp), %eax
orl %ecx, %eax
je 0x37e57
movl $0x33746e49, %eax       # imm = 0x33746E49
xorl 0xa0(%rsp), %eax
movzwl 0xa4(%rsp), %ecx
xorl $0x32, %ecx
orl %eax, %ecx
je 0x37e71
movl $0x33746e69, %eax       # imm = 0x33746E69
xorl 0xa0(%rsp), %eax
movzwl 0xa4(%rsp), %ecx
xorl $0x32, %ecx
orl %eax, %ecx
je 0x37e71
movl $0x746e6955, %ecx       # imm = 0x746E6955
xorl 0xa0(%rsp), %ecx
movl $0x363174, %eax         # imm = 0x363174
movl 0xa3(%rsp), %edx
xorl %eax, %edx
orl %ecx, %edx
je 0x37e8b
movl $0x746e6975, %ecx       # imm = 0x746E6975
xorl 0xa0(%rsp), %ecx
xorl 0xa3(%rsp), %eax
orl %ecx, %eax
je 0x37e8b
movl $0x31746e49, %eax       # imm = 0x31746E49
xorl 0xa0(%rsp), %eax
movzwl 0xa4(%rsp), %ecx
xorl $0x36, %ecx
orl %eax, %ecx
je 0x37ea5
movl $0x31746e69, %eax       # imm = 0x31746E69
xorl 0xa0(%rsp), %eax
movzwl 0xa4(%rsp), %ecx
xorl $0x36, %ecx
orl %eax, %ecx
je 0x37ea5
movl $0x61686355, %ecx       # imm = 0x61686355
xorl 0xa0(%rsp), %ecx
movl $0x387261, %eax         # imm = 0x387261
movl 0xa3(%rsp), %edx
xorl %eax, %edx
orl %ecx, %edx
je 0x37ebf
movl $0x61686375, %ecx       # imm = 0x61686375
xorl 0xa0(%rsp), %ecx
xorl 0xa3(%rsp), %eax
orl %ecx, %eax
je 0x37ebf
movl $0x72616843, %eax       # imm = 0x72616843
xorl 0xa0(%rsp), %eax
movzwl 0xa4(%rsp), %ecx
xorl $0x38, %ecx
orl %eax, %ecx
je 0x37ede
movl $0x72616863, %eax       # imm = 0x72616863
xorl 0xa0(%rsp), %eax
movzwl 0xa4(%rsp), %ecx
xorl $0x38, %ecx
orl %eax, %ecx
je 0x37ede
leaq 0x6fbeb(%rip), %rdi     # 0xa79f0
xorl %ebp, %ebp
leaq 0xa0(%rsp), %rsi
leaq 0x1120(%rsp), %rdx
xorl %eax, %eax
callq 0x72a1e
jmp 0x37c03
movq 0x230(%r15), %rsi
movq %r8, %rdi
movl %r12d, %edx
movq %r8, %rbx
callq 0x3915a
jmp 0x37ab3
movq 0x230(%r15), %rsi
movq %r8, %rdi
movl %r12d, %edx
movq %r8, %rbx
callq 0x390aa
jmp 0x37ab3
movq 0x230(%r15), %rsi
movq %r8, %rdi
movl %r12d, %edx
movq %r8, %rbx
callq 0x391ef
jmp 0x37ab3
movq 0x230(%r15), %rsi
movq %r8, %rdi
movl %r12d, %edx
movq %r8, %rbx
callq 0x3928b
jmp 0x37ab3
movq 0x230(%r15), %rsi
movq %r8, %rdi
movl %r12d, %edx
movq %r8, %rbx
callq 0x39324
jmp 0x37ab3
movq 0x230(%r15), %rsi
movq %r8, %rdi
movl %r12d, %edx
movq %r8, %rbx
callq 0x393c0
jmp 0x37ab3
movq 0x10(%rsp), %rax
movq 0x230(%rax), %rsi
movq %r8, %rbx
movq %r8, %rdi
movl %r12d, %edx
callq 0x3945c
jmp 0x37ab3
movq 0x10(%rsp), %rax
movq 0x230(%rax), %rsi
movq %r8, %rbx
movq %r8, %rdi
movl %r12d, %edx
callq 0x394f8
jmp 0x37ab3
movq %rax, %rbx
leaq 0x920(%rsp), %rdi
callq 0x2a27c
movq %rbx, %rdi
callq 0xe7e0
nop