// File: /workspace/github_cpp_makefile_star2_O3/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 0x68989
callq 0xe5b0
movq $0x0, 0x10(%r14)
movq $0x0, (%r14)
leaq 0x39c14(%rip), %rsi     # 0xa25ab
movq %rbx, %rdi
callq 0xe530
testq %rax, %rax
je 0x68aa6
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 0x68aa6
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 0x68a9c
movd 0x12(%rsp), %xmm0
movd %xmm0, %esi
cmpl $0xa0d474e, %esi        # imm = 0xA0D474E
jne 0x68a38
cmpb $-0x77, %cl
jne 0x68a38
cmpb $0x50, %dl
jne 0x68a38
cmpb $0x1a, 0x16(%rsp)
jne 0x68a38
cmpl $0x8, %eax
jl 0x68a38
movl $0x2, %r12d
cmpb $0xa, 0x17(%rsp)
je 0x68a9c
cmpl $0x4, %eax
jl 0x68a5b
cmpb $0x49, %cl
jne 0x68a5b
cmpb $0x49, %dl
jne 0x68a5b
cmpb $0x2a, %sil
jne 0x68a5b
shrl $0x8, %esi
movl $0x4, %r12d
testb %sil, %sil
je 0x68a9c
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 0x68a9c
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 0x68aa9
xorl %r12d, %r12d
movq %rbx, %rdi
movl $0x2e, %esi
callq 0xe4c0
testq %rax, %rax
je 0x68b34
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 0x68b01
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 0x68aeb
movslq %ebp, %rax
movb $0x0, 0x10(%rsp,%rax)
decl %r12d
cmpl $0x4, %r12d
ja 0x68b76
leaq 0x40f87(%rip), %rax     # 0xa9aa0
movslq (%rax,%r12,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x698b4
jmp 0x68bc6
leaq 0x4105d(%rip), %rdi     # 0xa9b98
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x719d2
jmp 0x68bc8
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x69c36
jmp 0x68bc6
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x69912
jmp 0x68bc6
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x6997a
jmp 0x68bc6
movl 0x10(%rsp), %eax
cmpl $0x6d67702d, %eax       # imm = 0x6D67702D
jle 0x68b9d
cmpl $0x6d67702e, %eax       # imm = 0x6D67702E
movq 0x8(%rsp), %rdi
je 0x68bbe
cmpl $0x6d70702e, %eax       # imm = 0x6D70702E
je 0x68bbe
cmpl $0x706d622e, %eax       # imm = 0x706D622E
je 0x68b6c
jmp 0x68bdc
cmpl $0x67706a2e, %eax       # imm = 0x67706A2E
movq 0x8(%rsp), %rdi
je 0x68b27
cmpl $0x6d66702e, %eax       # imm = 0x6D66702E
jne 0x68bdc
movq %r14, %rsi
callq 0x6a28c
jmp 0x68bc6
movq %r14, %rsi
callq 0x69e46
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 0x68b27
cmpl $0x6669742e, %eax       # imm = 0x6669742E
je 0x68c37
movl $0x6669742e, %ecx       # imm = 0x6669742E
xorl 0x10(%rsp), %ecx
movzbl 0x14(%rsp), %edx
xorl $0x66, %edx
orl %ecx, %edx
je 0x68c37
cmpl $0x6472672e, %eax       # imm = 0x6472672E
je 0x68c4c
cmpl $0x7761722e, %eax       # imm = 0x7761722E
je 0x68b4e
cmpl $0x676e702e, %eax       # imm = 0x676E702E
je 0x68b5d
leaq 0x40fa2(%rip), %rdi     # 0xa9bd7
jmp 0x68c3e
leaq 0x411a6(%rip), %rdi     # 0xa9de4
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x719d2
jmp 0x68bc8
movq %r14, %rsi
callq 0x6a798
jmp 0x68bc6
nop