// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::WriteFile(char const*) const
int R2Image::
WriteFile(const char *filename) const
{
  // Parse input filename extension
  const char *input_extension;
  if (!(input_extension = strrchr(filename, '.'))) {
    RNFail("Output file has no extension (e.g., .jpg).\n");
    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';

  // Write file of appropriate type
  if (!strncmp(extension, ".bmp", 4)) return WriteBMPFile(filename);
  else if (!strncmp(extension, ".pgm", 4)) return WritePPMFile(filename, 0);
  else if (!strncmp(extension, ".ppm", 4)) return WritePPMFile(filename, 0);
  else if (!strncmp(extension, ".jpg", 4)) return WriteJPEGFile(filename);
  else if (!strncmp(extension, ".jpeg", 5)) return WriteJPEGFile(filename);
  else if (!strncmp(extension, ".tif", 4)) return WriteTIFFFile(filename);
  else if (!strncmp(extension, ".tiff", 5)) return WriteTIFFFile(filename);
  else if (!strncmp(extension, ".png", 4)) return WritePNGFile(filename);
  else if (!strncmp(extension, ".raw", 4)) return WriteRAWFile(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 $0x408, %rsp            # imm = 0x408
movq %rsi, %rbx
movq %rdi, %r14
pushq $0x2e
popq %rsi
movq %rbx, %rdi
callq 0xe4e0
testq %rax, %rax
je 0x61df4
movq %rax, %r15
movq %rax, %rdi
callq 0xe1e0
movl $0x3ff, %ebp            # imm = 0x3FF
cmpl %ebp, %eax
cmovll %eax, %ebp
xorl %r12d, %r12d
testl %ebp, %ebp
movl $0x0, %r13d
cmovgl %ebp, %r13d
cmpq %r12, %r13
je 0x61db9
movsbl (%r15,%r12), %edi
callq 0xe6c0
movb %al, (%rsp,%r12)
incq %r12
jmp 0x61da1
movslq %ebp, %rax
movb $0x0, (%rsp,%rax)
movl (%rsp), %ebp
cmpl $0x67706a2e, %ebp       # imm = 0x67706A2E
je 0x61e66
cmpl $0x6d67702e, %ebp       # imm = 0x6D67702E
je 0x61e06
cmpl $0x6d70702e, %ebp       # imm = 0x6D70702E
je 0x61e06
cmpl $0x706d622e, %ebp       # imm = 0x706D622E
jne 0x61e15
movq %r14, %rdi
movq %rbx, %rsi
callq 0x61eac
jmp 0x61e71
leaq 0x38d7e(%rip), %rdi     # 0x9ab79
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x681ca
jmp 0x61e73
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x62070
jmp 0x61e71
leaq 0x38d2f(%rip), %rsi     # 0x9ab4b
movq %rsp, %rdi
pushq $0x5
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x61e66
cmpl $0x6669742e, %ebp       # imm = 0x6669742E
je 0x61e87
leaq 0x38d17(%rip), %rsi     # 0x9ab51
movq %rsp, %rdi
pushq $0x5
popq %rdx
callq 0xe480
testl %eax, %eax
je 0x61e87
cmpl $0x7761722e, %ebp       # imm = 0x7761722E
je 0x61e93
cmpl $0x676e702e, %ebp       # imm = 0x676E702E
jne 0x61ea0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x62392
jmp 0x61e71
movq %r14, %rdi
movq %rbx, %rsi
callq 0x62322
movl %eax, %ebx
movl %ebx, %eax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x38ed6(%rip), %rdi     # 0x9ad64
jmp 0x61dfb
movq %r14, %rdi
movq %rbx, %rsi
callq 0x623e6
jmp 0x61e71
leaq 0x38cb0(%rip), %rdi     # 0x9ab57
jmp 0x61dfb