// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::ReadAsciiRawSizeFile(char const*, int&, int&, int&, char*)
static int 
ReadAsciiRawSizeFile(const char *filename, int& xres, int& yres, int& zres, char *format)
{
  // Open file
  FILE *fp = fopen(filename, "r");
  if (!fp) {
    RNFail("Unable to open size file %s", filename);
    return 0;
  }

  // Read line from file
  char buffer[2048];
  if (!fgets(buffer, 2048, fp)) {
    RNFail("Unable to read size file %s", filename);
    return 0;
  }

  // Close file
  fclose(fp);

  // Check line (may be binary file)
  if (!strstr(buffer, "(")) return 0;
  if (!strstr(buffer, ")")) return 0;

  // Parse format
  char *token = strtok(buffer, "(");
  if (!token) { RNFail("Error parsing type name in size file %s", filename); return 0; }
  strncpy(format, token, 2047);

  // Parse xres
  token = strtok(NULL, ",)");
  if (!token) { RNFail("Error parsing xres in size file %s", filename); return 0; }
  xres = atoi(token);

  // Parse yres
  token = strtok(NULL, ",)");
  if (!token) { RNFail("Error parsing yres in size file %s", filename); return 0; }
  yres = atoi(token);

  // Parse zres
  token = strtok(NULL, ",)");
  if (!token) { RNFail("Error parsing zres in size file %s", filename); return 0; }
  zres = atoi(token);

  // Return success
  return 1;
}

// Assembly:
subq $0x848, %rsp            # imm = 0x848
movq %rdi, 0x838(%rsp)
movq %rsi, 0x830(%rsp)
movq %rdx, 0x828(%rsp)
movq %rcx, 0x820(%rsp)
movq %r8, 0x818(%rsp)
movq 0x838(%rsp), %rdi
leaq 0xcd0c5(%rip), %rsi     # 0x138673
callq 0xf5e0
movq %rax, 0x810(%rsp)
cmpq $0x0, 0x810(%rsp)
jne 0x6b5ec
movq 0x838(%rsp), %rsi
leaq 0xc9ab0(%rip), %rdi     # 0x135085
movb $0x0, %al
callq 0xd4f30
movl $0x0, 0x844(%rsp)
jmp 0x6b7f5
leaq 0x10(%rsp), %rdi
movq 0x810(%rsp), %rdx
movl $0x800, %esi            # imm = 0x800
callq 0xf7e0
cmpq $0x0, %rax
jne 0x6b62f
movq 0x838(%rsp), %rsi
leaq 0xc9a89(%rip), %rdi     # 0x1350a1
movb $0x0, %al
callq 0xd4f30
movl $0x0, 0x844(%rsp)
jmp 0x6b7f5
movq 0x810(%rsp), %rdi
callq 0xf4b0
leaq 0x10(%rsp), %rdi
leaq 0xc9a75(%rip), %rsi     # 0x1350bd
callq 0xf110
cmpq $0x0, %rax
jne 0x6b663
movl $0x0, 0x844(%rsp)
jmp 0x6b7f5
leaq 0x10(%rsp), %rdi
leaq 0xcd273(%rip), %rsi     # 0x1388e2
callq 0xf110
cmpq $0x0, %rax
jne 0x6b68a
movl $0x0, 0x844(%rsp)
jmp 0x6b7f5
leaq 0x10(%rsp), %rdi
leaq 0xc9a27(%rip), %rsi     # 0x1350bd
callq 0xf7c0
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jne 0x6b6ce
movq 0x838(%rsp), %rsi
leaq 0xc9a08(%rip), %rdi     # 0x1350bf
movb $0x0, %al
callq 0xd4f30
movl $0x0, 0x844(%rsp)
jmp 0x6b7f5
movq 0x818(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl $0x7ff, %edx            # imm = 0x7FF
callq 0xf260
xorl %eax, %eax
movl %eax, %edi
leaq 0xc99f7(%rip), %rsi     # 0x1350e7
callq 0xf7c0
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jne 0x6b728
movq 0x838(%rsp), %rsi
leaq 0xc99d9(%rip), %rdi     # 0x1350ea
movb $0x0, %al
callq 0xd4f30
movl $0x0, 0x844(%rsp)
jmp 0x6b7f5
movq 0x8(%rsp), %rdi
callq 0xf7b0
movl %eax, %ecx
movq 0x830(%rsp), %rax
movl %ecx, (%rax)
xorl %eax, %eax
movl %eax, %edi
leaq 0xc999e(%rip), %rsi     # 0x1350e7
callq 0xf7c0
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jne 0x6b77e
movq 0x838(%rsp), %rsi
leaq 0xc99a3(%rip), %rdi     # 0x13510d
movb $0x0, %al
callq 0xd4f30
movl $0x0, 0x844(%rsp)
jmp 0x6b7f5
movq 0x8(%rsp), %rdi
callq 0xf7b0
movl %eax, %ecx
movq 0x828(%rsp), %rax
movl %ecx, (%rax)
xorl %eax, %eax
movl %eax, %edi
leaq 0xc9948(%rip), %rsi     # 0x1350e7
callq 0xf7c0
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jne 0x6b7d4
movq 0x838(%rsp), %rsi
leaq 0xc9970(%rip), %rdi     # 0x135130
movb $0x0, %al
callq 0xd4f30
movl $0x0, 0x844(%rsp)
jmp 0x6b7f5
movq 0x8(%rsp), %rdi
callq 0xf7b0
movl %eax, %ecx
movq 0x820(%rsp), %rax
movl %ecx, (%rax)
movl $0x1, 0x844(%rsp)
movl 0x844(%rsp), %eax
addq $0x848, %rsp            # imm = 0x848
retq
nopw %cs:(%rax,%rax)