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

  // Read file of appropriate type
  if (!strncmp(extension, ".obj", 4)) {
    if (!ReadObjFile(filename)) return 0;
  }
  else if (!strncmp(extension, ".off", 4)) {
    if (!ReadOffFile(filename)) return 0;
  }
  else if (!strncmp(extension, ".ray", 4))  {
    if (!ReadRayFile(filename)) return 0;
  }
  else if (!strncmp(extension, ".ply", 4)) { 
    if (!ReadPlyFile(filename)) return 0;
  }
  else if (!strncmp(extension, ".cat", 4)) { 
    if (!ReadCattFile(filename)) return 0;
  }
  else if (!strncmp(extension, ".m", 4)) { 
    if (!ReadHoppeFile(filename)) return 0;
  }  
  else if (!strncmp(extension, ".ifs", 4)) { 
    if (!ReadIfsFile(filename)) return 0;
  }
  else if (!strncmp(extension, ".stl", 4))  {
    if (!ReadSTLFile(filename)) return 0;
  }
  else if (!strncmp(extension, ".wrl", 4))  {
    if (!ReadVRMLFile(filename)) return 0;
  }
  else {
    RNFail("Unable to read file %s (unrecognized extension: %s)\n", filename, extension);
    return 0;
  }

  // Set mesh name, if it doesn't already have one
  if (strlen(Name()) == 0) SetName(filename);

  // Return success
  return 1;
}

// 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 0x2bf21
movq 0x10(%rsp), %rsi
leaq 0x107448(%rip), %rdi    # 0x133355
movb $0x0, %al
callq 0xf070
movl $0x0, 0x24(%rsp)
jmp 0x2c1db
movq 0x8(%rsp), %rdi
leaq 0x107453(%rip), %rsi    # 0x133380
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x2bf65
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x188(%rax)
cmpl $0x0, %eax
jne 0x2bf60
movl $0x0, 0x24(%rsp)
jmp 0x2c1db
jmp 0x2c1ae
movq 0x8(%rsp), %rdi
leaq 0x107414(%rip), %rsi    # 0x133385
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x2bfa9
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x190(%rax)
cmpl $0x0, %eax
jne 0x2bfa4
movl $0x0, 0x24(%rsp)
jmp 0x2c1db
jmp 0x2c1ac
movq 0x8(%rsp), %rdi
leaq 0x1073d5(%rip), %rsi    # 0x13338a
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x2bfed
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x198(%rax)
cmpl $0x0, %eax
jne 0x2bfe8
movl $0x0, 0x24(%rsp)
jmp 0x2c1db
jmp 0x2c1aa
movq 0x8(%rsp), %rdi
leaq 0x107396(%rip), %rsi    # 0x13338f
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x2c031
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x1a0(%rax)
cmpl $0x0, %eax
jne 0x2c02c
movl $0x0, 0x24(%rsp)
jmp 0x2c1db
jmp 0x2c1a8
movq 0x8(%rsp), %rdi
leaq 0x107357(%rip), %rsi    # 0x133394
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x2c075
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x1a8(%rax)
cmpl $0x0, %eax
jne 0x2c070
movl $0x0, 0x24(%rsp)
jmp 0x2c1db
jmp 0x2c1a6
movq 0x8(%rsp), %rdi
leaq 0x107318(%rip), %rsi    # 0x133399
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x2c0b9
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x1b0(%rax)
cmpl $0x0, %eax
jne 0x2c0b4
movl $0x0, 0x24(%rsp)
jmp 0x2c1db
jmp 0x2c1a4
movq 0x8(%rsp), %rdi
leaq 0x1072d7(%rip), %rsi    # 0x13339c
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x2c0fd
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x1b8(%rax)
cmpl $0x0, %eax
jne 0x2c0f8
movl $0x0, 0x24(%rsp)
jmp 0x2c1db
jmp 0x2c1a2
movq 0x8(%rsp), %rdi
leaq 0x107298(%rip), %rsi    # 0x1333a1
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x2c13e
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x1c0(%rax)
cmpl $0x0, %eax
jne 0x2c13c
movl $0x0, 0x24(%rsp)
jmp 0x2c1db
jmp 0x2c1a0
movq 0x8(%rsp), %rdi
leaq 0x10725c(%rip), %rsi    # 0x1333a6
movl $0x4, %edx
callq 0xf230
cmpl $0x0, %eax
jne 0x2c17c
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0x1c8(%rax)
cmpl $0x0, %eax
jne 0x2c17a
movl $0x0, 0x24(%rsp)
jmp 0x2c1db
jmp 0x2c19e
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0x10721e(%rip), %rdi    # 0x1333ab
movb $0x0, %al
callq 0xd4f30
movl $0x0, 0x24(%rsp)
jmp 0x2c1db
jmp 0x2c1a0
jmp 0x2c1a2
jmp 0x2c1a4
jmp 0x2c1a6
jmp 0x2c1a8
jmp 0x2c1aa
jmp 0x2c1ac
jmp 0x2c1ae
movq (%rsp), %rdi
callq 0x3a010
movq %rax, %rdi
callq 0xf200
cmpq $0x0, %rax
jne 0x2c1d3
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3a020
movl $0x1, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)