// File: /workspace/github_cpp_makefile_star2_O3/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 $0x2118, %rsp           # imm = 0x2118
movq %rsi, %r15
movq %rdi, %rbp
leaq 0x1110(%rsp), %r14
movl $0x7ff, %edx            # imm = 0x7FF
movq %r14, %rdi
callq 0xe240
movq %r14, %rdi
movl $0x2e, %esi
callq 0xe4c0
testq %rax, %rax
je 0x3731b
movb $0x0, (%rax)
leaq 0x1110(%rsp), %rdi
callq 0xe1e0
movl $0x7a69732e, 0x1110(%rsp,%rax) # imm = 0x7A69732E
movw $0x65, 0x1114(%rsp,%rax)
leaq 0x1910(%rsp), %r14
movl $0x7ff, %edx            # imm = 0x7FF
movq %r14, %rdi
movq %r15, %rsi
callq 0xe240
movq %r14, %rdi
movl $0x2e, %esi
callq 0xe4c0
testq %rax, %rax
je 0x3736a
movb $0x0, (%rax)
leaq 0x1910(%rsp), %rdi
callq 0xe1e0
movl $0x66782e, 0x1910(%rsp,%rax) # imm = 0x66782E
leaq 0x74a4a(%rip), %rsi     # 0xabdd3
leaq 0x1110(%rsp), %rdi
callq 0xe530
testq %rax, %rax
je 0x3749a
movq %rax, %r14
leaq 0x910(%rsp), %rdi
movl $0x800, %esi            # imm = 0x800
movq %rax, %rdx
callq 0xe730
testq %rax, %rax
je 0x374a3
movq %r14, %rdi
callq 0xe430
leaq 0x910(%rsp), %rdi
movl $0x28, %esi
callq 0xe1a0
testq %rax, %rax
je 0x374b9
leaq 0x910(%rsp), %rdi
movl $0x29, %esi
callq 0xe1a0
testq %rax, %rax
je 0x374b9
leaq 0x7117a(%rip), %rsi     # 0xa857f
leaq 0x910(%rsp), %rdi
callq 0xe710
testq %rax, %rax
je 0x376d3
leaq 0x90(%rsp), %rdi
movl $0x7ff, %edx            # imm = 0x7FF
movq %rax, %rsi
callq 0xe240
leaq 0x71172(%rip), %rsi     # 0xa85a9
xorl %edi, %edi
callq 0xe710
testq %rax, %rax
je 0x376f5
movq %rax, %rdi
callq 0xe700
movl %eax, %r12d
leaq 0x71150(%rip), %rsi     # 0xa85a9
xorl %edi, %edi
callq 0xe710
testq %rax, %rax
je 0x37701
movq %rax, %rdi
callq 0xe700
movl %eax, %ebx
leaq 0x7112f(%rip), %rsi     # 0xa85a9
xorl %edi, %edi
callq 0xe710
testq %rax, %rax
je 0x37882
movq %rax, %rdi
callq 0xe700
movl %eax, %r14d
jmp 0x37535
leaq 0x710a6(%rip), %rdi     # 0xa8547
jmp 0x374aa
leaq 0x710b9(%rip), %rdi     # 0xa8563
leaq 0x1110(%rsp), %rsi
xorl %eax, %eax
callq 0x719d2
leaq 0x6b0eb(%rip), %rsi     # 0xa25ab
leaq 0x1110(%rsp), %rdi
callq 0xe530
testq %rax, %rax
je 0x37687
movq %rax, %r14
leaq 0x910(%rsp), %rdi
movl $0x4, %esi
movl $0x3, %edx
movq %rax, %rcx
callq 0xe6c0
cmpq $0x3, %rax
jne 0x37690
movq %r14, %rdi
callq 0xe430
movl 0x910(%rsp), %r12d
movl 0x914(%rsp), %ebx
movl 0x918(%rsp), %r14d
leaq 0x70456(%rip), %rsi     # 0xa7979
leaq 0x90(%rsp), %rdi
movl $0x7ff, %edx            # imm = 0x7FF
callq 0xe240
movl %ebx, %r13d
imull %r12d, %r13d
movl %r13d, %eax
imull %r14d, %eax
testl %eax, %eax
je 0x37699
movl %eax, 0x4(%rsp)
leaq 0x6b055(%rip), %rsi     # 0xa25ab
movq %r15, %rdi
callq 0xe530
testq %rax, %rax
je 0x376c5
movq %rax, %rdi
movq 0x230(%rbp), %rsi
testq %rsi, %rsi
movl 0x4(%rsp), %edx
je 0x37582
cmpl 0x24c(%rbp), %edx
jle 0x375c4
movq %rdi, 0x8(%rsp)
testq %rsi, %rsi
je 0x37598
movq %rsi, %rdi
callq 0xe5b0
movl 0x4(%rsp), %edx
movslq %edx, %rax
shlq $0x3, %rax
testl %edx, %edx
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0xe030
movl 0x4(%rsp), %edx
movq %rax, %rsi
movq %rax, 0x230(%rbp)
movq 0x8(%rsp), %rdi
movl %r12d, 0x238(%rbp)
movl %ebx, 0x23c(%rbp)
movl %r14d, 0x240(%rbp)
movl %r12d, 0x244(%rbp)
movl %r13d, 0x248(%rbp)
movq %rbp, 0x8(%rsp)
movl %edx, 0x24c(%rbp)
testl %edx, %edx
jle 0x376e1
movabsq $0x3436656c62756f44, %rax # imm = 0x3436656C62756F44
movq 0x90(%rsp), %rcx
xorq %rax, %rcx
movzbl 0x98(%rsp), %r8d
orq %rcx, %r8
je 0x376df
addq $0x20, %rax
xorq 0x90(%rsp), %rax
movzbl 0x98(%rsp), %ecx
orq %rax, %rcx
je 0x376df
movq 0x90(%rsp), %rax
movabsq $0x343674616f6c45, %rcx # imm = 0x343674616F6C45
cmpq %rcx, %rax
jg 0x3770d
movabsq $0x323374616f6c46, %rcx # imm = 0x323374616F6C46
cmpq %rcx, %rax
je 0x3767a
movabsq $0x323374616f6c66, %rcx # imm = 0x323374616F6C66
cmpq %rcx, %rax
jne 0x3788e
movq %rdi, %rbx
callq 0x38b6f
jmp 0x37737
leaq 0x70eb9(%rip), %rdi     # 0xa8547
jmp 0x376a0
leaq 0x70ecc(%rip), %rdi     # 0xa8563
jmp 0x376a0
leaq 0x7029e(%rip), %rdi     # 0xa793e
xorl %ebx, %ebx
leaq 0x1110(%rsp), %rsi
xorl %eax, %eax
callq 0x719d2
movl %ebx, %eax
addq $0x2118, %rsp           # imm = 0x2118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x70292(%rip), %rdi     # 0xa795e
xorl %ebx, %ebx
movq %r15, %rsi
jmp 0x376aa
leaq 0x70ea7(%rip), %rdi     # 0xa8581
jmp 0x374aa
jmp 0x3772f
leaq 0x70157(%rip), %rdi     # 0xa783f
xorl %ebx, %ebx
movl %edx, %esi
xorl %eax, %eax
callq 0x719d2
jmp 0x376b1
leaq 0x70eb0(%rip), %rdi     # 0xa85ac
jmp 0x374aa
leaq 0x70ec7(%rip), %rdi     # 0xa85cf
jmp 0x374aa
movabsq $0x343674616f6c66, %rcx # imm = 0x343674616F6C66
cmpq %rcx, %rax
je 0x3772f
movabsq $0x343674616f6c46, %rcx # imm = 0x343674616F6C46
cmpq %rcx, %rax
jne 0x3788e
movq %rdi, %rbx
callq 0x38ad3
testl %eax, %eax
je 0x3784e
movq %rbx, %rdi
callq 0xe430
leaq 0x910(%rsp), %rdi
callq 0x29f8c
leaq 0x74678(%rip), %rsi     # 0xabdd3
leaq 0x1910(%rsp), %rdi
callq 0xe530
testq %rax, %rax
je 0x3786b
movq %rax, %r14
leaq 0x18(%rsp), %rcx
leaq 0x20(%rsp), %r8
leaq 0x28(%rsp), %r9
leaq 0x58(%rsp), %r13
leaq 0x60(%rsp), %rbp
leaq 0x68(%rsp), %r10
leaq 0x70(%rsp), %r11
leaq 0x78(%rsp), %rbx
leaq 0x80(%rsp), %r15
leaq 0x88(%rsp), %r12
leaq 0x70e62(%rip), %rsi     # 0xa8615
leaq 0x10(%rsp), %rdx
movq %rax, %rdi
xorl %eax, %eax
pushq %r12
pushq %r15
pushq %rbx
pushq %r11
pushq %r10
pushq %rbp
pushq %r13
leaq 0x88(%rsp), %r10
pushq %r10
leaq 0x88(%rsp), %r10
pushq %r10
leaq 0x88(%rsp), %r10
pushq %r10
leaq 0x88(%rsp), %r10
pushq %r10
leaq 0x88(%rsp), %r10
pushq %r10
callq 0xe840
addq $0x60, %rsp
cmpl $0x10, %eax
jne 0x37855
movq %r14, %rdi
callq 0xe430
leaq 0x890(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2c3b2
leaq 0x910(%rsp), %rdi
leaq 0x890(%rsp), %rsi
xorl %edx, %edx
callq 0x2a68c
leaq 0x910(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x331b6
jmp 0x3786b
xorl %ebx, %ebx
jmp 0x376b1
leaq 0x70dea(%rip), %rdi     # 0xa8646
leaq 0x1910(%rsp), %rsi
xorl %eax, %eax
callq 0x719d2
leaq 0x910(%rsp), %rdi
callq 0x2a028
movl $0x1, %ebx
jmp 0x376b1
leaq 0x70d69(%rip), %rdi     # 0xa85f2
jmp 0x374aa
movl $0x746e6955, %eax       # imm = 0x746E6955
xorl 0x90(%rsp), %eax
movl $0x343674, %ecx         # imm = 0x343674
xorl 0x93(%rsp), %ecx
orl %eax, %ecx
je 0x37a95
movl $0x36746e49, %eax       # imm = 0x36746E49
xorl 0x90(%rsp), %eax
movzwl 0x94(%rsp), %ecx
xorl $0x34, %ecx
orl %eax, %ecx
je 0x37a88
movl $0x36746e69, %eax       # imm = 0x36746E69
xorl 0x90(%rsp), %eax
movzwl 0x94(%rsp), %ecx
xorl $0x34, %ecx
orl %eax, %ecx
je 0x37a88
movl $0x746e6955, %ecx       # imm = 0x746E6955
xorl 0x90(%rsp), %ecx
movl $0x323374, %eax         # imm = 0x323374
movl 0x93(%rsp), %r8d
xorl %eax, %r8d
orl %ecx, %r8d
je 0x37aa2
movl $0x746e6975, %ecx       # imm = 0x746E6975
xorl 0x90(%rsp), %ecx
xorl 0x93(%rsp), %eax
orl %ecx, %eax
je 0x37aa2
movl $0x33746e49, %eax       # imm = 0x33746E49
xorl 0x90(%rsp), %eax
movzwl 0x94(%rsp), %ecx
xorl $0x32, %ecx
orl %eax, %ecx
je 0x37aaf
movl $0x33746e69, %eax       # imm = 0x33746E69
xorl 0x90(%rsp), %eax
movzwl 0x94(%rsp), %ecx
xorl $0x32, %ecx
orl %eax, %ecx
je 0x37aaf
movl $0x746e6955, %ecx       # imm = 0x746E6955
xorl 0x90(%rsp), %ecx
movl $0x363174, %eax         # imm = 0x363174
movl 0x93(%rsp), %r8d
xorl %eax, %r8d
orl %ecx, %r8d
je 0x37abc
movl $0x746e6975, %ecx       # imm = 0x746E6975
xorl 0x90(%rsp), %ecx
xorl 0x93(%rsp), %eax
orl %ecx, %eax
je 0x37abc
movl $0x31746e49, %eax       # imm = 0x31746E49
xorl 0x90(%rsp), %eax
movzwl 0x94(%rsp), %ecx
xorl $0x36, %ecx
orl %eax, %ecx
je 0x37ac9
movl $0x31746e69, %eax       # imm = 0x31746E69
xorl 0x90(%rsp), %eax
movzwl 0x94(%rsp), %ecx
xorl $0x36, %ecx
orl %eax, %ecx
je 0x37ac9
movl $0x61686355, %ecx       # imm = 0x61686355
xorl 0x90(%rsp), %ecx
movl $0x387261, %eax         # imm = 0x387261
movl 0x93(%rsp), %edx
xorl %eax, %edx
orl %ecx, %edx
je 0x37ad6
movl $0x61686375, %ecx       # imm = 0x61686375
xorl 0x90(%rsp), %ecx
xorl 0x93(%rsp), %eax
orl %ecx, %eax
je 0x37ad6
movl $0x72616843, %eax       # imm = 0x72616843
xorl 0x90(%rsp), %eax
movzwl 0x94(%rsp), %ecx
xorl $0x38, %ecx
orl %eax, %ecx
je 0x37ae7
movl $0x72616863, %eax       # imm = 0x72616863
xorl 0x90(%rsp), %eax
movzwl 0x94(%rsp), %ecx
xorl $0x38, %ecx
orl %eax, %ecx
je 0x37ae7
leaq 0x6ff82(%rip), %rdi     # 0xa79ec
xorl %ebx, %ebx
leaq 0x90(%rsp), %rsi
leaq 0x1110(%rsp), %rdx
xorl %eax, %eax
callq 0x719d2
jmp 0x376b1
movq %rdi, %rbx
callq 0x38cc9
jmp 0x37737
movq %rdi, %rbx
callq 0x38c0e
jmp 0x37737
movq %rdi, %rbx
callq 0x38d69
jmp 0x37737
movq %rdi, %rbx
callq 0x38e0b
jmp 0x37737
movq %rdi, %rbx
callq 0x38eaa
jmp 0x37737
movq %rdi, %rbx
callq 0x38f4c
jmp 0x37737
movq %rdi, %rbx
movl 0x4(%rsp), %edx
callq 0x38fee
jmp 0x37737
movq %rdi, %rbx
movl 0x4(%rsp), %edx
callq 0x39090
jmp 0x37737
movq %rax, %rbx
leaq 0x910(%rsp), %rdi
callq 0x2a028
movq %rbx, %rdi
callq 0xe7e0