// File: tomfunkhouser[P]gaps/apps/mshinfo/mshinfo.cpp
// Function: main
int main(int argc, char **argv)
{
  // Check number of arguments
  if (argc != 2) {
    printf("Usage: meshinfo inputfile\n");
    exit(1);
  }

  // Create mesh
  R3Mesh *mesh = new R3Mesh();
  if (!mesh) {
    RNFail("Unable to allocate mesh data structure.\n");
    exit(1);
  }

  // Read mesh
  if (!mesh->ReadFile(argv[1])) {
    RNFail("Unable to read file: %s\n", argv[1]);
    exit(1);
  }

  // Compute stats
  int num_boundaries = NumBoundaryEdges(mesh);
  int num_components = mesh->ConnectedComponents();
  RNScalar avg_vertex_valence = mesh->AverageVertexValence();
  RNScalar avg_edge_length = mesh->AverageEdgeLength();
  RNArea total_face_area = mesh->Area();
  RNAngle avg_edge_interior_angle = mesh->AverageEdgeInteriorAngle();
  const R3Point& centroid = mesh->Centroid();
  const R3Box& bbox = mesh->BBox();

  // Print stats
  printf("Total faces = %d\n", mesh->NFaces());
  printf("Total edges = %d\n", mesh->NEdges());
  printf("Total vertices = %d\n", mesh->NVertices());
  printf("Boundary edges = %d ( %g%% )\n", num_boundaries, 100.0 * num_boundaries/ mesh->NEdges());
  printf("Connected components = %d\n", num_components);
  printf("Surface area = %g\n", total_face_area);
  printf("Average vertex valence = %g\n", avg_vertex_valence);
  printf("Average edge length = %g\n", avg_edge_length);
  printf("Average edge interior angle = %g\n", avg_edge_interior_angle);
  printf("Centroid = ( %g %g %g )\n", centroid[0], centroid[1], centroid[2]);
  printf("Bounding box = ( %g %g %g ) ( %g %g %g )\n", bbox[0][0], bbox[0][1], bbox[0][2], bbox[1][0], bbox[1][1], bbox[1][2]);
  printf("Axial lengths = ( %g %g %g )\n", bbox.XLength(), bbox.YLength(), bbox.ZLength());

  // Return success 
  return 0;
}

// Assembly:
subq $0xd8, %rsp
movl $0x0, 0xd4(%rsp)
movl %edi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
cmpl $0x2, 0xd0(%rsp)
je 0x100c3
leaq 0x89f5e(%rip), %rdi     # 0x9a010
movb $0x0, %al
callq 0xd070
movl $0x1, %edi
callq 0xd4e0
movl $0x138, %edi            # imm = 0x138
callq 0xd3d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x58(%rsp)
callq 0x10720
jmp 0x100df
movq 0x58(%rsp), %rax
movq %rax, 0xc0(%rsp)
cmpq $0x0, 0xc0(%rsp)
jne 0x10137
leaq 0x89f2d(%rip), %rdi     # 0x9a02b
movb $0x0, %al
callq 0x98fa0
movl $0x1, %edi
callq 0xd4e0
movq 0x58(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
movl $0x138, %esi            # imm = 0x138
callq 0xd3e0
jmp 0x104da
movq 0xc0(%rsp), %rdi
movq 0xc8(%rsp), %rax
movq 0x8(%rax), %rsi
movq (%rdi), %rax
callq *0x180(%rax)
cmpl $0x0, %eax
jne 0x1017d
movq 0xc8(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x89ee8(%rip), %rdi     # 0x9a054
movb $0x0, %al
callq 0x98fa0
movl $0x1, %edi
callq 0xd4e0
movq 0xc0(%rsp), %rdi
callq 0xffd0
movl %eax, 0xb0(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x13240
movl %eax, 0xac(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x11c50
movsd %xmm0, 0xa0(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x11d20
movsd %xmm0, 0x98(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x11940
movsd %xmm0, 0x90(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x11df0
movsd %xmm0, 0x88(%rsp)
movq 0xc0(%rsp), %rsi
leaq 0x68(%rsp), %rdi
callq 0x116c0
leaq 0x68(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x10560
movq %rax, 0x60(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x10580
movl %eax, %esi
leaq 0x89e29(%rip), %rdi     # 0x9a06d
movb $0x0, %al
callq 0xd070
movq 0xc0(%rsp), %rdi
callq 0x104f0
movl %eax, %esi
leaq 0x89e1e(%rip), %rdi     # 0x9a07f
movb $0x0, %al
callq 0xd070
movq 0xc0(%rsp), %rdi
callq 0x105a0
movl %eax, %esi
leaq 0x89e13(%rip), %rdi     # 0x9a091
movb $0x0, %al
callq 0xd070
movl 0xb0(%rsp), %eax
movl %eax, 0xc(%rsp)
cvtsi2sdl 0xb0(%rsp), %xmm1
movsd 0x89d67(%rip), %xmm0    # 0x9a008
mulsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movq 0xc0(%rsp), %rdi
callq 0x104f0
movsd (%rsp), %xmm0
movl 0xc(%rsp), %esi
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
leaq 0x89dd7(%rip), %rdi     # 0x9a0a6
movb $0x1, %al
callq 0xd070
movl 0xac(%rsp), %esi
leaq 0x89de0(%rip), %rdi     # 0x9a0c4
movb $0x0, %al
callq 0xd070
movsd 0x90(%rsp), %xmm0
leaq 0x89de4(%rip), %rdi     # 0x9a0df
movb $0x1, %al
callq 0xd070
movsd 0xa0(%rsp), %xmm0
leaq 0x89de0(%rip), %rdi     # 0x9a0f2
movb $0x1, %al
callq 0xd070
movsd 0x98(%rsp), %xmm0
leaq 0x89de6(%rip), %rdi     # 0x9a10f
movb $0x1, %al
callq 0xd070
movsd 0x88(%rsp), %xmm0
leaq 0x89de9(%rip), %rdi     # 0x9a129
movb $0x1, %al
callq 0xd070
movq 0x80(%rsp), %rdi
xorl %esi, %esi
callq 0x105c0
movsd %xmm0, 0x18(%rsp)
movq 0x80(%rsp), %rdi
movl $0x1, %esi
callq 0x105c0
movsd %xmm0, 0x10(%rsp)
movq 0x80(%rsp), %rdi
movl $0x2, %esi
callq 0x105c0
movsd 0x10(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x18(%rsp), %xmm0
leaq 0x89daf(%rip), %rdi     # 0x9a14b
movb $0x3, %al
callq 0xd070
movq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x105e0
movq %rax, %rdi
xorl %esi, %esi
callq 0x105c0
movsd %xmm0, 0x40(%rsp)
movq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x105e0
movq %rax, %rdi
movl $0x1, %esi
callq 0x105c0
movsd %xmm0, 0x20(%rsp)
movq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x105e0
movq %rax, %rdi
movl $0x2, %esi
callq 0x105c0
movsd %xmm0, 0x28(%rsp)
movq 0x60(%rsp), %rdi
movl $0x1, %esi
callq 0x105e0
movq %rax, %rdi
xorl %esi, %esi
callq 0x105c0
movsd %xmm0, 0x30(%rsp)
movq 0x60(%rsp), %rdi
movl $0x1, %esi
callq 0x105e0
movq %rax, %rdi
movl $0x1, %esi
callq 0x105c0
movsd %xmm0, 0x38(%rsp)
movq 0x60(%rsp), %rdi
movl $0x1, %esi
callq 0x105e0
movq %rax, %rdi
movl $0x2, %esi
callq 0x105c0
movsd 0x20(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
movsd 0x30(%rsp), %xmm3
movsd 0x38(%rsp), %xmm4
movaps %xmm0, %xmm5
movsd 0x40(%rsp), %xmm0
leaq 0x89ce2(%rip), %rdi     # 0x9a164
movb $0x6, %al
callq 0xd070
movq 0x60(%rsp), %rdi
callq 0x10620
movsd %xmm0, 0x50(%rsp)
movq 0x60(%rsp), %rdi
callq 0x10640
movsd %xmm0, 0x48(%rsp)
movq 0x60(%rsp), %rdi
callq 0x10660
movsd 0x48(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x50(%rsp), %xmm0
leaq 0x89cc5(%rip), %rdi     # 0x9a18e
movb $0x3, %al
callq 0xd070
xorl %eax, %eax
addq $0xd8, %rsp
retq
movq 0xb8(%rsp), %rdi
callq 0xd680
nopw (%rax,%rax)