// File: /workspace/github_cpp_makefile_star2_O2/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, %rbp
leaq 0x1120(%rsp), %r14
movl $0x7ff, %edx            # imm = 0x7FF
movq %r14, %rdi
callq 0xe250
pushq $0x2e
popq %rsi
movq %r14, %rdi
callq 0xe4e0
testq %rax, %rax
je 0x33133
movb $0x0, (%rax)
leaq 0x1120(%rsp), %rdi
callq 0xe1e0
movl $0x7a69732e, 0x1120(%rsp,%rax) # imm = 0x7A69732E
movw $0x65, 0x1124(%rsp,%rax)
leaq 0x1920(%rsp), %r14
movl $0x7ff, %edx            # imm = 0x7FF
movq %r14, %rdi
movq %r15, %rsi
callq 0xe250
pushq $0x2e
popq %rsi
movq %r14, %rdi
callq 0xe4e0
testq %rax, %rax
je 0x33180
movb $0x0, (%rax)
leaq 0x1920(%rsp), %rdi
callq 0xe1e0
movl $0x66782e, 0x1920(%rsp,%rax) # imm = 0x66782E
leaq 0x69954(%rip), %rsi     # 0x9caf3
leaq 0x1120(%rsp), %rdi
callq 0xe550
testq %rax, %rax
je 0x332ac
movq %rax, %r14
leaq 0x120(%rsp), %rdi
movl $0x800, %esi            # imm = 0x800
movq %rax, %rdx
callq 0xe760
testq %rax, %rax
je 0x332b5
movq %r14, %rdi
callq 0xe440
leaq 0x120(%rsp), %rdi
pushq $0x28
popq %rsi
callq 0xe1a0
testq %rax, %rax
je 0x332cb
leaq 0x120(%rsp), %rdi
pushq $0x29
popq %rsi
callq 0xe1a0
testq %rax, %rax
je 0x332cb
leaq 0x66318(%rip), %rsi     # 0x9952f
leaq 0x120(%rsp), %rdi
callq 0xe740
testq %rax, %rax
je 0x334d7
leaq 0x920(%rsp), %rdi
movl $0x7ff, %edx            # imm = 0x7FF
movq %rax, %rsi
callq 0xe250
leaq 0x66310(%rip), %rsi     # 0x99559
xorl %edi, %edi
callq 0xe740
testq %rax, %rax
je 0x33628
movq %rax, %rdi
callq 0xe730
movl %eax, %r12d
leaq 0x662ee(%rip), %rsi     # 0x99559
xorl %edi, %edi
callq 0xe740
testq %rax, %rax
je 0x33634
movq %rax, %rdi
callq 0xe730
movl %eax, %ebx
leaq 0x662cd(%rip), %rsi     # 0x99559
xorl %edi, %edi
callq 0xe740
testq %rax, %rax
je 0x3366b
movq %rax, %rdi
callq 0xe730
movl %eax, %r14d
jmp 0x33343
leaq 0x66244(%rip), %rdi     # 0x994f7
jmp 0x332bc
leaq 0x66257(%rip), %rdi     # 0x99513
leaq 0x1120(%rsp), %rsi
xorl %eax, %eax
callq 0x681ca
leaq 0x60289(%rip), %rsi     # 0x9355b
leaq 0x1120(%rsp), %rdi
callq 0xe550
testq %rax, %rax
je 0x3348b
movq %rax, %r14
leaq 0x120(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x3
popq %rdx
movq %rax, %rcx
callq 0xe6f0
cmpq $0x3, %rax
jne 0x33494
movq %r14, %rdi
callq 0xe440
movl 0x120(%rsp), %r12d
movl 0x124(%rsp), %ebx
movl 0x128(%rsp), %r14d
leaq 0x655f8(%rip), %rsi     # 0x98929
leaq 0x920(%rsp), %rdi
movl $0x7ff, %edx            # imm = 0x7FF
callq 0xe250
movl %ebx, %r13d
imull %r12d, %r13d
movl %r13d, %eax
imull %r14d, %eax
testl %eax, %eax
je 0x3349d
movl %eax, 0xc(%rsp)
leaq 0x601f7(%rip), %rsi     # 0x9355b
movq %r15, %rdi
callq 0xe550
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x334c9
movq 0x230(%rbp), %r15
testq %r15, %r15
movl 0xc(%rsp), %esi
je 0x33392
cmpl 0x24c(%rbp), %esi
jle 0x333c6
testq %r15, %r15
je 0x333a3
movq %r15, %rdi
callq 0xe5d0
movl 0xc(%rsp), %esi
movslq %esi, %rax
shlq $0x3, %rax
testl %esi, %esi
pushq $-0x1
popq %rdi
cmovnsq %rax, %rdi
callq 0xe030
movl 0xc(%rsp), %esi
movq %rax, %r15
movq %rax, 0x230(%rbp)
movl %r12d, 0x238(%rbp)
movl %ebx, 0x23c(%rbp)
movl %r14d, 0x240(%rbp)
movl %r12d, 0x244(%rbp)
movl %r13d, 0x248(%rbp)
movq %rbp, 0x18(%rsp)
movl %esi, 0x24c(%rbp)
testl %esi, %esi
jle 0x33613
leaq 0x65527(%rip), %rsi     # 0x98929
leaq 0x920(%rsp), %rdi
pushq $0x9
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x334e3
leaq 0x65511(%rip), %rsi     # 0x98932
leaq 0x920(%rsp), %rdi
pushq $0x9
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x334e3
movq 0x920(%rsp), %rax
movabsq $0x323374616f6c46, %rcx # imm = 0x323374616F6C46
cmpq %rcx, %rax
je 0x33677
movabsq $0x323374616f6c66, %rcx # imm = 0x323374616F6C66
cmpq %rcx, %rax
je 0x33677
movabsq $0x343674616f6c66, %rcx # imm = 0x343674616F6C66
cmpq %rcx, %rax
je 0x33489
movabsq $0x343674616f6c46, %rcx # imm = 0x343674616F6C46
cmpq %rcx, %rax
jne 0x336c7
jmp 0x334e3
leaq 0x66065(%rip), %rdi     # 0x994f7
jmp 0x334a4
leaq 0x66078(%rip), %rdi     # 0x99513
jmp 0x334a4
leaq 0x6544a(%rip), %rdi     # 0x988ee
xorl %ebx, %ebx
leaq 0x1120(%rsp), %rsi
xorl %eax, %eax
callq 0x681ca
movl %ebx, %eax
addq $0x2128, %rsp           # imm = 0x2128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6543e(%rip), %rdi     # 0x9890e
xorl %ebx, %ebx
movq %r15, %rsi
jmp 0x334ae
leaq 0x66053(%rip), %rdi     # 0x99531
jmp 0x332bc
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movl 0xc(%rsp), %edx
callq 0x34c97
testl %eax, %eax
je 0x33ac3
movq 0x10(%rsp), %rdi
callq 0xe440
leaq 0x120(%rsp), %rdi
callq 0x27652
leaq 0x695d9(%rip), %rsi     # 0x9caf3
leaq 0x1920(%rsp), %rdi
callq 0xe550
testq %rax, %rax
je 0x33656
movq %rax, %r14
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), %rbx
leaq 0x90(%rsp), %r15
leaq 0x98(%rsp), %r12
leaq 0x6604d(%rip), %rsi     # 0x995c5
leaq 0x20(%rsp), %rdx
movq %rax, %rdi
xorl %eax, %eax
pushq %r12
pushq %r15
pushq %rbx
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 0xe870
addq $0x60, %rsp
cmpl $0x10, %eax
jne 0x33640
movq %r14, %rdi
callq 0xe440
leaq 0xa0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x29770
leaq 0x120(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
xorl %edx, %edx
callq 0x27cea
leaq 0x120(%rsp), %rsi
movq 0x18(%rsp), %rdi
callq 0x2f570
jmp 0x33656
leaq 0x651d5(%rip), %rdi     # 0x987ef
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x681ca
jmp 0x334b5
leaq 0x65f2d(%rip), %rdi     # 0x9955c
jmp 0x332bc
leaq 0x65f44(%rip), %rdi     # 0x9957f
jmp 0x332bc
leaq 0x65faf(%rip), %rdi     # 0x995f6
leaq 0x1920(%rsp), %rsi
xorl %eax, %eax
callq 0x681ca
leaq 0x120(%rsp), %rdi
callq 0x276ee
pushq $0x1
popq %rbx
jmp 0x334b5
leaq 0x65f30(%rip), %rdi     # 0x995a2
jmp 0x332bc
movl 0xc(%rsp), %ebx
xorl %ebp, %ebp
leaq 0x120(%rsp), %r14
pushq $0x4
popq %r12
pushq $0x1
popq %r13
cmpq %rbp, %rbx
je 0x334fc
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq 0x10(%rsp), %rcx
callq 0xe6f0
cmpq $0x1, %rax
jne 0x33aba
cvtss2sd 0x120(%rsp), %xmm0
movsd %xmm0, (%r15,%rbp,8)
incq %rbp
jmp 0x3368d
leaq 0x65285(%rip), %rsi     # 0x98953
leaq 0x920(%rsp), %rdi
pushq $0x7
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x3390e
leaq 0x6526d(%rip), %rsi     # 0x9895a
leaq 0x920(%rsp), %rdi
pushq $0x6
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x338bd
leaq 0x65248(%rip), %rsi     # 0x98954
leaq 0x920(%rsp), %rdi
pushq $0x6
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x338bd
leaq 0x65235(%rip), %rsi     # 0x98960
leaq 0x920(%rsp), %rdi
pushq $0x7
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x33979
leaq 0x6521d(%rip), %rsi     # 0x98967
leaq 0x920(%rsp), %rdi
pushq $0x7
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x33979
leaq 0x65205(%rip), %rsi     # 0x9896e
leaq 0x920(%rsp), %rdi
pushq $0x6
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x339cc
leaq 0x651d9(%rip), %rsi     # 0x98961
leaq 0x920(%rsp), %rdi
pushq $0x6
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x339cc
leaq 0x651cd(%rip), %rsi     # 0x98974
leaq 0x920(%rsp), %rdi
pushq $0x7
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x33a1c
leaq 0x651b5(%rip), %rsi     # 0x9897b
leaq 0x920(%rsp), %rdi
pushq $0x7
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x33a1c
leaq 0x6519d(%rip), %rsi     # 0x98982
leaq 0x920(%rsp), %rdi
pushq $0x6
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x33a6b
leaq 0x65171(%rip), %rsi     # 0x98975
leaq 0x920(%rsp), %rdi
pushq $0x6
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x33a6b
leaq 0x65165(%rip), %rsi     # 0x98988
leaq 0x920(%rsp), %rdi
pushq $0x7
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x33aca
leaq 0x6514d(%rip), %rsi     # 0x9898f
leaq 0x920(%rsp), %rdi
pushq $0x7
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x33aca
leaq 0x65135(%rip), %rsi     # 0x98996
leaq 0x920(%rsp), %rdi
pushq $0x6
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x33b16
leaq 0x65109(%rip), %rsi     # 0x98989
leaq 0x920(%rsp), %rdi
pushq $0x6
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x33b16
leaq 0x650fd(%rip), %rdi     # 0x9899c
xorl %ebx, %ebx
leaq 0x920(%rsp), %rsi
leaq 0x1120(%rsp), %rdx
xorl %eax, %eax
callq 0x681ca
jmp 0x334b5
movl 0xc(%rsp), %ebx
xorl %ebp, %ebp
leaq 0x120(%rsp), %r14
pushq $0x8
popq %r12
pushq $0x1
popq %r13
cmpq %rbp, %rbx
je 0x334fc
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq 0x10(%rsp), %rcx
callq 0xe6f0
cmpq $0x1, %rax
jne 0x33aba
cvtsi2sdq 0x120(%rsp), %xmm0
movsd %xmm0, (%r15,%rbp,8)
incq %rbp
jmp 0x338d3
movl 0xc(%rsp), %ebx
xorl %ebp, %ebp
leaq 0x120(%rsp), %r14
pushq $0x8
popq %r12
pushq $0x1
popq %r13
cmpq %rbp, %rbx
je 0x334fc
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq 0x10(%rsp), %rcx
callq 0xe6f0
cmpq $0x1, %rax
jne 0x33aba
movsd 0x120(%rsp), %xmm0
unpcklps 0x605d6(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x605de(%rip), %xmm0    # 0x93f40
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd %xmm1, (%r15,%rbp,8)
incq %rbp
jmp 0x33924
movl 0xc(%rsp), %ebx
xorl %ebp, %ebp
leaq 0x120(%rsp), %r14
pushq $0x4
popq %r12
pushq $0x1
popq %r13
cmpq %rbp, %rbx
je 0x334fc
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq 0x10(%rsp), %rcx
callq 0xe6f0
cmpq $0x1, %rax
jne 0x33aba
movl 0x120(%rsp), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, (%r15,%rbp,8)
incq %rbp
jmp 0x3398f
movl 0xc(%rsp), %ebx
xorl %ebp, %ebp
leaq 0x120(%rsp), %r14
pushq $0x4
popq %r12
pushq $0x1
popq %r13
cmpq %rbp, %rbx
je 0x334fc
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq 0x10(%rsp), %rcx
callq 0xe6f0
cmpq $0x1, %rax
jne 0x33aba
cvtsi2sdl 0x120(%rsp), %xmm0
movsd %xmm0, (%r15,%rbp,8)
incq %rbp
jmp 0x339e2
movl 0xc(%rsp), %ebx
xorl %ebp, %ebp
leaq 0x120(%rsp), %r14
pushq $0x2
popq %r12
pushq $0x1
popq %r13
cmpq %rbp, %rbx
je 0x334fc
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq 0x10(%rsp), %rcx
callq 0xe6f0
cmpq $0x1, %rax
jne 0x33aba
movzwl 0x120(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, (%r15,%rbp,8)
incq %rbp
jmp 0x33a32
movl 0xc(%rsp), %ebx
xorl %ebp, %ebp
leaq 0x120(%rsp), %r14
pushq $0x2
popq %r12
pushq $0x1
popq %r13
cmpq %rbp, %rbx
je 0x334fc
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq 0x10(%rsp), %rcx
callq 0xe6f0
cmpq $0x1, %rax
jne 0x33aba
movswl 0x120(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, (%r15,%rbp,8)
incq %rbp
jmp 0x33a81
cmpq %rbx, %rbp
jae 0x334fc
xorl %ebx, %ebx
jmp 0x334b5
movl 0xc(%rsp), %ebx
xorl %r13d, %r13d
leaq 0x120(%rsp), %r14
pushq $0x1
popq %r12
cmpq %r13, %rbx
je 0x334fc
movq %r14, %rdi
movq %r12, %rsi
movq %r12, %rdx
movq 0x10(%rsp), %rcx
callq 0xe6f0
cmpq $0x1, %rax
jne 0x33b62
movzbl 0x120(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, (%r15,%r13,8)
incq %r13
jmp 0x33add
movl 0xc(%rsp), %ebx
xorl %r13d, %r13d
leaq 0x120(%rsp), %r14
pushq $0x1
popq %r12
cmpq %r13, %rbx
je 0x334fc
movq %r14, %rdi
movq %r12, %rsi
movq %r12, %rdx
movq 0x10(%rsp), %rcx
callq 0xe6f0
cmpq $0x1, %rax
jne 0x33b62
movsbl 0x120(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, (%r15,%r13,8)
incq %r13
jmp 0x33b29
cmpq %rbx, %r13
jae 0x334fc
jmp 0x33ac3
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x276ee
movq %rbx, %rdi
callq 0xe810