// File: tomfunkhouser[P]gaps/apps/mshsegment/mshsegment.cpp
// Function: ReadMesh(char const*)
static R3Mesh *
ReadMesh(const char *filename)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Allocate mesh
  R3Mesh *mesh = new R3Mesh();
  assert(mesh);

  // Read mesh from file
  if (!mesh->ReadFile(filename)) {
    delete mesh;
    return NULL;
  }

  // Initialize (remember segments in face materials)
  if (set_face_materials) {
    for (int i = 0; i < mesh->NFaces(); i++) {
      R3MeshFace *face = mesh->Face(i);
      int segment = mesh->FaceSegment(face);
      mesh->SetFaceMaterial(face, segment);
      mesh->SetFaceSegment(face, -1);
    }
  }

  // Print statistics
  if (print_verbose) {
    printf("Read mesh from %s ...\n", filename);
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Faces = %d\n", mesh->NFaces());
    printf("  # Edges = %d\n", mesh->NEdges());
    printf("  # Vertices = %d\n", mesh->NVertices());
    fflush(stdout);
  }

  // Return mesh
  return mesh;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
leaq 0x48(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xa5c50
movq 0x10(%rsp), %rdi
callq 0x12040
movl $0x138, %edi            # imm = 0x138
callq 0xd3d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
callq 0x3a860
jmp 0x1087e
movq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq (%rdi), %rax
callq *0x180(%rax)
cmpl $0x0, %eax
jne 0x108eb
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x108bb
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x60(%rsp)
jmp 0x10a17
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x38(%rsp)
movl %eax, 0x34(%rsp)
movl $0x138, %esi            # imm = 0x138
callq 0xd3e0
jmp 0x10a21
cmpl $0x0, 0xc13da(%rip)     # 0xd1ccc
je 0x10978
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0x4(%rsp)
movq 0x40(%rsp), %rdi
callq 0x12060
movl %eax, %ecx
movl 0x4(%rsp), %eax
cmpl %ecx, %eax
jge 0x10976
movq 0x40(%rsp), %rdi
movl 0x30(%rsp), %esi
callq 0x12080
movq %rax, 0x28(%rsp)
movq 0x40(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x120b0
movl %eax, 0x24(%rsp)
movq 0x40(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x24(%rsp), %edx
callq 0x120d0
movq 0x40(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x120f0
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x10900
jmp 0x10978
cmpl $0x0, 0xc1349(%rip)     # 0xd1cc8
je 0x10a0d
movq 0x58(%rsp), %rsi
leaq 0x9a877(%rip), %rdi     # 0xab208
movb $0x0, %al
callq 0xd070
leaq 0x48(%rsp), %rdi
callq 0xa5d10
leaq 0x9a876(%rip), %rdi     # 0xab21f
movb $0x1, %al
callq 0xd070
movq 0x40(%rsp), %rdi
callq 0x12060
movl %eax, %esi
leaq 0x9a873(%rip), %rdi     # 0xab236
movb $0x0, %al
callq 0xd070
movq 0x40(%rsp), %rdi
callq 0x12110
movl %eax, %esi
leaq 0x9a869(%rip), %rdi     # 0xab246
movb $0x0, %al
callq 0xd070
movq 0x40(%rsp), %rdi
callq 0x12130
movl %eax, %esi
leaq 0x9a85f(%rip), %rdi     # 0xab256
movb $0x0, %al
callq 0xd070
movq 0xc059b(%rip), %rax     # 0xd0fa0
movq (%rax), %rdi
callq 0xd4b0
movq 0x40(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
addq $0x68, %rsp
retq
movq 0x38(%rsp), %rdi
callq 0xd690
nopl (%rax,%rax)