// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::ReadFile(char const*)
int R2Image::
ReadFile(const char *filename)
{
  // Initialize everything
  if (pixels) { delete [] pixels; pixels = NULL; }
  width = height = 0;

  // Parse image format
  int format = R2ImageFileFormat(filename);
  
  // Parse input filename extension
  const char *input_extension;
  if (!(input_extension = strrchr(filename, '.'))) {
    RNFail("Input file %s has no extension (e.g., .jpg).\n", filename);
    return 0;
  }

  // Make lower-case copy of extension
  char extension[1024];
  int len = strlen(input_extension);
  if (len > 1023) len = 1023;
  for (int i = 0; i < len; i++) 
    extension[i] = tolower(input_extension[i]);
  extension[len] = '\0';

  // Read file of appropriate type
  if (format == R2_IMAGE_JPEG_FORMAT) return ReadJPEGFile(filename);
  else if (format == R2_IMAGE_PNG_FORMAT) return ReadPNGFile(filename);
  else if (format == R2_IMAGE_TIFF_FORMAT) return ReadTIFFFile(filename);
  else if (format == R2_IMAGE_BMP_FORMAT) return ReadBMPFile(filename);
  else if (format == R2_IMAGE_RAW_FORMAT) return ReadRAWFile(filename);
  else if (!strncmp(extension, ".bmp", 4)) return ReadBMPFile(filename);
  else if (!strncmp(extension, ".ppm", 4)) return ReadPPMFile(filename);
  else if (!strncmp(extension, ".pgm", 4)) return ReadPPMFile(filename);
  else if (!strncmp(extension, ".pfm", 4)) return ReadPFMFile(filename);
  else if (!strncmp(extension, ".jpg", 4)) return ReadJPEGFile(filename);
  else if (!strncmp(extension, ".jpeg", 5)) return ReadJPEGFile(filename);
  else if (!strncmp(extension, ".tif", 4)) return ReadTIFFFile(filename);
  else if (!strncmp(extension, ".tiff", 5)) return ReadTIFFFile(filename);
  else if (!strncmp(extension, ".png", 4)) return ReadPNGFile(filename);
  else if (!strncmp(extension, ".raw", 4)) return ReadRAWFile(filename);
  else if (!strncmp(extension, ".grd", 4)) return ReadGRDFile(filename);
  
  // Should never get here
  RNFail("Unrecognized image file extension");
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rsi, %rbx
movq %rdi, %r14
movq 0x10(%rdi), %rdi
testq %rdi, %rdi
je 0x69775
callq 0xe5b0
movq $0x0, 0x10(%r14)
movq $0x0, (%r14)
leaq 0x38e2b(%rip), %rsi     # 0xa25ae
movq %rbx, %rdi
callq 0xe530
testq %rax, %rax
je 0x69892
movq %rax, %r15
pxor %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movdqa %xmm0, (%rdi)
movl $0x1, %esi
movl $0x8, %edx
movq %rax, %rcx
callq 0xe6c0
testl %eax, %eax
je 0x69892
cmpl $0x2, %eax
setge %sil
movb 0x10(%rsp), %cl
movb 0x11(%rsp), %dl
movl %ecx, %edi
notb %dil
movl %edx, %r8d
xorb $-0x28, %r8b
orb %dil, %r8b
sete %dil
movl $0x1, %r12d
testb %sil, %dil
jne 0x69888
movd 0x12(%rsp), %xmm0
movd %xmm0, %esi
cmpl $0xa0d474e, %esi        # imm = 0xA0D474E
jne 0x69824
cmpb $-0x77, %cl
jne 0x69824
cmpb $0x50, %dl
jne 0x69824
cmpb $0x1a, 0x16(%rsp)
jne 0x69824
cmpl $0x8, %eax
jl 0x69824
movl $0x2, %r12d
cmpb $0xa, 0x17(%rsp)
je 0x69888
cmpl $0x4, %eax
jl 0x69847
cmpb $0x49, %cl
jne 0x69847
cmpb $0x49, %dl
jne 0x69847
cmpb $0x2a, %sil
jne 0x69847
shrl $0x8, %esi
movl $0x4, %r12d
testb %sil, %sil
je 0x69888
cmpl $0x2, %eax
setge %sil
movl %ecx, %edi
xorb $0x42, %dil
movl %edx, %r8d
xorb $0x4d, %r8b
orb %dil, %r8b
sete %dil
movl $0x3, %r12d
testb %sil, %dil
jne 0x69888
xorl %esi, %esi
cmpl $0x2, %eax
setge %sil
xorb $-0x2c, %cl
xorb $0x31, %dl
leal (%rsi,%rsi,4), %eax
xorl %r12d, %r12d
orb %cl, %dl
cmovel %eax, %r12d
movq %r15, %rdi
callq 0xe430
jmp 0x69895
xorl %r12d, %r12d
movq %rbx, %rdi
movl $0x2e, %esi
callq 0xe4c0
testq %rax, %rax
je 0x69920
movq %rax, %r15
movq %r14, 0x8(%rsp)
movq %rbx, %r14
movq %rax, %rdi
callq 0xe1e0
movl $0x3ff, %ebp            # imm = 0x3FF
cmpl %ebp, %eax
cmovll %eax, %ebp
testl %eax, %eax
jle 0x698ed
cmpl $0x2, %ebp
movl $0x1, %r13d
cmovgel %ebp, %r13d
xorl %ebx, %ebx
movsbl (%r15,%rbx), %edi
callq 0xe690
movb %al, 0x10(%rsp,%rbx)
incq %rbx
cmpq %rbx, %r13
jne 0x698d7
movslq %ebp, %rax
movb $0x0, 0x10(%rsp,%rax)
decl %r12d
cmpl $0x4, %r12d
ja 0x69962
leaq 0x40183(%rip), %rax     # 0xa9a88
movslq (%rax,%r12,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x6a63c
jmp 0x699b2
leaq 0x40251(%rip), %rdi     # 0xa9b78
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x72a1e
jmp 0x699b4
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x6a9d0
jmp 0x699b2
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x6a69a
jmp 0x699b2
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x6a702
jmp 0x699b2
movl 0x10(%rsp), %eax
cmpl $0x6d67702d, %eax       # imm = 0x6D67702D
jle 0x69989
cmpl $0x6d67702e, %eax       # imm = 0x6D67702E
movq 0x8(%rsp), %rdi
je 0x699aa
cmpl $0x6d70702e, %eax       # imm = 0x6D70702E
je 0x699aa
cmpl $0x706d622e, %eax       # imm = 0x706D622E
je 0x69958
jmp 0x699c8
cmpl $0x67706a2e, %eax       # imm = 0x67706A2E
movq 0x8(%rsp), %rdi
je 0x69913
cmpl $0x6d66702e, %eax       # imm = 0x6D66702E
jne 0x699c8
movq %r14, %rsi
callq 0x6b062
jmp 0x699b2
movq %r14, %rsi
callq 0x6abe0
movl %eax, %ebp
movl %ebp, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x65706a2e, %ecx       # imm = 0x65706A2E
xorl 0x10(%rsp), %ecx
movzbl 0x14(%rsp), %edx
xorl $0x67, %edx
orl %ecx, %edx
je 0x69913
cmpl $0x6669742e, %eax       # imm = 0x6669742E
je 0x69a23
movl $0x6669742e, %ecx       # imm = 0x6669742E
xorl 0x10(%rsp), %ecx
movzbl 0x14(%rsp), %edx
xorl $0x66, %edx
orl %ecx, %edx
je 0x69a23
cmpl $0x6472672e, %eax       # imm = 0x6472672E
je 0x69a38
cmpl $0x7761722e, %eax       # imm = 0x7761722E
je 0x6993a
cmpl $0x676e702e, %eax       # imm = 0x676E702E
je 0x69949
leaq 0x40196(%rip), %rdi     # 0xa9bb7
jmp 0x69a2a
leaq 0x4039a(%rip), %rdi     # 0xa9dc4
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x72a1e
jmp 0x699b4
movq %r14, %rsi
callq 0x6b554
jmp 0x699b2
nop