// File: /workspace/github_cpp_makefile_star2_O3/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 0x6ab65
movq %rax, %r15
movq %rax, %rdi
callq 0xe1e0
movl $0x3ff, %ebp            # imm = 0x3FF
cmpl %ebp, %eax
cmovll %eax, %ebp
testl %eax, %eax
jle 0x6ab40
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 0x6ab2a
movslq %ebp, %rax
movb $0x0, (%rsp,%rax)
movl (%rsp), %eax
cmpl $0x6d70702d, %eax       # imm = 0x6D70702D
jg 0x6ab7a
cmpl $0x67706a2e, %eax       # imm = 0x67706A2E
je 0x6abee
cmpl $0x6d67702e, %eax       # imm = 0x6D67702E
je 0x6ab95
jmp 0x6aba4
leaq 0x3f08d(%rip), %rdi     # 0xa9bf9
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x719d2
jmp 0x6abfb
cmpl $0x6d70702e, %eax       # imm = 0x6D70702E
je 0x6ab95
cmpl $0x706d622e, %eax       # imm = 0x706D622E
jne 0x6aba4
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6ac34
jmp 0x6abf9
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x6ae4e
jmp 0x6abf9
movl $0x65706a2e, %ecx       # imm = 0x65706A2E
xorl (%rsp), %ecx
movzbl 0x4(%rsp), %edx
xorl $0x67, %edx
orl %ecx, %edx
je 0x6abee
cmpl $0x6669742e, %eax       # imm = 0x6669742E
je 0x6ac0f
movl $0x6669742e, %ecx       # imm = 0x6669742E
xorl (%rsp), %ecx
movzbl 0x4(%rsp), %edx
xorl $0x66, %edx
orl %ecx, %edx
je 0x6ac0f
cmpl $0x7761722e, %eax       # imm = 0x7761722E
je 0x6ac1b
cmpl $0x676e702e, %eax       # imm = 0x676E702E
jne 0x6ac28
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6b1bc
jmp 0x6abf9
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6b14a
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 0x3f1ce(%rip), %rdi     # 0xa9de4
jmp 0x6ab6c
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6b210
jmp 0x6abf9
leaq 0x3efa8(%rip), %rdi     # 0xa9bd7
jmp 0x6ab6c