// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::WriteFile(char const*) const
int R3Mesh::
WriteFile(const char *filename) const
{
  // Parse input filename extension
  const char *extension;
  if (!(extension = strrchr(filename, '.'))) {
    printf("Filename %s has no extension (e.g., .ply)", filename);
    return 0;
  }

  // Write file of appropriate type
  if (!strncmp(extension, ".ray", 4)) 
    return WriteRayFile(filename);
  else if (!strncmp(extension, ".ply", 4)) 
    return WritePlyFile(filename);
  else if (!strncmp(extension, ".obj", 4)) 
    return WriteObjFile(filename);
  else if (!strncmp(extension, ".off", 4)) 
    return WriteOffFile(filename);
  else if (!strncmp(extension, ".cat", 4)) 
    return WriteCattFile(filename);
  else if (!strncmp(extension, ".ifs", 4)) 
    return WriteIfsFile(filename);
  else if (!strncmp(extension, ".stl", 4)) 
    return WriteSTLFile(filename);
  else {
    RNFail("Unable to write file %s (unrecognized extension: %s)", filename, extension);
    return 0;
  }
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq 0x18(%rsp), %rax
movq %rax, (%rsp)
movq 0x10(%rsp), %rdi
movl $0x2e, %esi
callq 0xf580
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
jne 0x33ba1
movq 0x10(%rsp), %rsi
leaq 0xffe07(%rip), %rdi     # 0x133994
movb $0x0, %al
callq 0xf070
movl $0x0, 0x24(%rsp)
jmp 0x33d3a
movq 0x8(%rsp), %rdi
leaq 0xff7dd(%rip), %rsi     # 0x13338a
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x33bd7
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x1d8(%rax)
movl %eax, 0x24(%rsp)
jmp 0x33d3a
movq 0x8(%rsp), %rdi
leaq 0xff7ac(%rip), %rsi     # 0x13338f
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x33c12
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
movl $0x1, %edx
callq *0x1e0(%rax)
movl %eax, 0x24(%rsp)
jmp 0x33d3a
movq 0x8(%rsp), %rdi
leaq 0xff762(%rip), %rsi     # 0x133380
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x33c48
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x1e8(%rax)
movl %eax, 0x24(%rsp)
jmp 0x33d3a
movq 0x8(%rsp), %rdi
leaq 0xff731(%rip), %rsi     # 0x133385
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x33c7e
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x1f0(%rax)
movl %eax, 0x24(%rsp)
jmp 0x33d3a
movq 0x8(%rsp), %rdi
leaq 0xff70a(%rip), %rsi     # 0x133394
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x33cb4
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x1f8(%rax)
movl %eax, 0x24(%rsp)
jmp 0x33d3a
movq 0x8(%rsp), %rdi
leaq 0xff6dc(%rip), %rsi     # 0x13339c
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x33ce7
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x200(%rax)
movl %eax, 0x24(%rsp)
jmp 0x33d3a
movq 0x8(%rsp), %rdi
leaq 0xff6ae(%rip), %rsi     # 0x1333a1
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x33d1a
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x208(%rax)
movl %eax, 0x24(%rsp)
jmp 0x33d3a
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0xffc93(%rip), %rdi     # 0x1339be
movb $0x0, %al
callq 0xd4f30
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)