// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rsi, %rdi
movl $0x2e, %esi
callq 0xe4c0
testq %rax, %rax
je 0x6b90d
movq %rax, %r15
movq %rax, %rdi
callq 0xe1e0
movl $0x3ff, %ebp            # imm = 0x3FF
cmpl %ebp, %eax
cmovll %eax, %ebp
testl %eax, %eax
jle 0x6b8e8
cmpl $0x2, %ebp
movl $0x1, %r12d
cmovgel %ebp, %r12d
xorl %r13d, %r13d
movsbl (%r15,%r13), %edi
callq 0xe690
movb %al, (%rsp,%r13)
incq %r13
cmpq %r13, %r12
jne 0x6b8d2
movslq %ebp, %rax
movb $0x0, (%rsp,%rax)
movl (%rsp), %eax
cmpl $0x6d70702d, %eax       # imm = 0x6D70702D
jg 0x6b922
cmpl $0x67706a2e, %eax       # imm = 0x67706A2E
je 0x6b996
cmpl $0x6d67702e, %eax       # imm = 0x6D67702E
je 0x6b93d
jmp 0x6b94c
leaq 0x3e2c5(%rip), %rdi     # 0xa9bd9
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x72a1e
jmp 0x6b9a3
cmpl $0x6d70702e, %eax       # imm = 0x6D70702E
je 0x6b93d
cmpl $0x706d622e, %eax       # imm = 0x706D622E
jne 0x6b94c
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6b9dc
jmp 0x6b9a1
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x6bbf6
jmp 0x6b9a1
movl $0x65706a2e, %ecx       # imm = 0x65706A2E
xorl (%rsp), %ecx
movzbl 0x4(%rsp), %edx
xorl $0x67, %edx
orl %ecx, %edx
je 0x6b996
cmpl $0x6669742e, %eax       # imm = 0x6669742E
je 0x6b9b7
movl $0x6669742e, %ecx       # imm = 0x6669742E
xorl (%rsp), %ecx
movzbl 0x4(%rsp), %edx
xorl $0x66, %edx
orl %ecx, %edx
je 0x6b9b7
cmpl $0x7761722e, %eax       # imm = 0x7761722E
je 0x6b9c3
cmpl $0x676e702e, %eax       # imm = 0x676E702E
jne 0x6b9d0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6bf66
jmp 0x6b9a1
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6bef4
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 0x3e406(%rip), %rdi     # 0xa9dc4
jmp 0x6b914
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6bfba
jmp 0x6b9a1
leaq 0x3e1e0(%rip), %rdi     # 0xa9bb7
jmp 0x6b914