// File: tomfunkhouser[P]gaps/apps/conf2conf/conf2conf.cpp
// Function: ReadMeshFile(gaps::RGBDConfiguration*, char const*)
static R3Mesh *
ReadMeshFile(RGBDConfiguration *configuration, const char *filename)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Allocate mesh
  R3Mesh *mesh = new R3Mesh();
  if (!mesh) {
    RNFail("Unable to allocate mesh for %s\n", filename);
    return NULL;
  }

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

  // Create surface      
  RGBDSurface *surface = new RGBDSurface("-", mesh, texel_spacing);
  if (!surface) {
    RNFail("Unable to allocate surface for %s\n", filename);
    delete mesh;
    return NULL;
  }

  // Remember mesh filename
  surface->SetMeshFilename(input_mesh_filename);

  // Insert surface into configuration
  configuration->InsertSurface(surface);

  // 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 $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
leaq 0x50(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0xdaa10
movq 0x20(%rsp), %rdi
callq 0x19c20
movl $0x138, %edi            # imm = 0x138
callq 0x126d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x28(%rsp)
callq 0x442e0
jmp 0x17343
movq 0x28(%rsp), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
jne 0x17398
movq 0x60(%rsp), %rsi
leaq 0x14efcc(%rip), %rdi    # 0x16632d
movb $0x0, %al
callq 0xdf990
movq $0x0, 0x70(%rsp)
jmp 0x1753d
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
movl $0x138, %esi            # imm = 0x138
callq 0x126e0
jmp 0x17547
movq 0x48(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq (%rdi), %rax
callq *0x180(%rax)
cmpl $0x0, %eax
jne 0x173d9
movq 0x48(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x173cb
movq 0x18(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x70(%rsp)
jmp 0x1753d
movl $0xa0, %edi
callq 0x126d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x10(%rsp)
movq 0x48(%rsp), %rdx
movsd 0x19ac2d(%rip), %xmm0   # 0x1b2028
leaq 0x14ef4b(%rip), %rsi    # 0x16634d
callq 0x23f50
jmp 0x17409
movq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x17479
movq 0x60(%rsp), %rsi
leaq 0x14ef28(%rip), %rdi    # 0x16634f
movb $0x0, %al
callq 0xdf990
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x17449
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x70(%rsp)
jmp 0x1753d
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
movl $0xa0, %esi
callq 0x126e0
jmp 0x17547
movq 0x30(%rsp), %rdi
movq 0x19ab3b(%rip), %rsi    # 0x1b1fc0
movq (%rdi), %rax
callq *0xc8(%rax)
movq 0x68(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
cmpl $0x0, 0x19ab43(%rip)    # 0x1b1fe8
je 0x17533
movq 0x60(%rsp), %rsi
leaq 0x14eebb(%rip), %rdi    # 0x166372
movb $0x0, %al
callq 0x12090
leaq 0x50(%rsp), %rdi
callq 0xdaad0
leaq 0x14ee23(%rip), %rdi    # 0x1662f2
movb $0x1, %al
callq 0x12090
movq 0x48(%rsp), %rdi
callq 0x19f00
movl %eax, %esi
leaq 0x14eea0(%rip), %rdi    # 0x166389
movb $0x0, %al
callq 0x12090
movq 0x48(%rsp), %rdi
callq 0x19f20
movl %eax, %esi
leaq 0x14ee96(%rip), %rdi    # 0x166399
movb $0x0, %al
callq 0x12090
movq 0x48(%rsp), %rdi
callq 0x19f40
movl %eax, %esi
leaq 0x14ee8c(%rip), %rdi    # 0x1663a9
movb $0x0, %al
callq 0x12090
movq 0x199a65(%rip), %rax    # 0x1b0f90
movq (%rax), %rdi
callq 0x12850
movq 0x48(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
addq $0x78, %rsp
retq
movq 0x40(%rsp), %rdi
callq 0x12c20
nopw %cs:(%rax,%rax)