// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x38, %rsp
cmpl $0x2, %edi
jne 0xe276
movq %rsi, %r14
movl $0x138, %edi            # imm = 0x138
callq 0xc380
movq %rax, %rbx
movq %rax, %rdi
callq 0xe2b8
movq 0x8(%r14), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x180(%rax)
testl %eax, %eax
je 0xe284
movq %rbx, %rdi
callq 0xe03c
movl %eax, %r15d
movq %rbx, %rdi
callq 0xf67c
movl %eax, %ebp
movq %rbx, %rdi
callq 0xeb22
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
callq 0xeb62
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
callq 0xe9aa
movsd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0xebc0
movsd %xmm0, 0x8(%rsp)
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xe7fe
movl 0x34(%rbx), %esi
leaq 0x3bf0a(%rip), %rdi     # 0x4a029
xorl %eax, %eax
callq 0xc070
movl 0x24(%rbx), %esi
leaq 0x3bf0b(%rip), %rdi     # 0x4a03b
xorl %eax, %eax
callq 0xc070
movl 0x14(%rbx), %esi
leaq 0x3bf0c(%rip), %rdi     # 0x4a04d
xorl %eax, %eax
callq 0xc070
cvtsi2sd %r15d, %xmm0
mulsd 0x3beb3(%rip), %xmm0    # 0x4a008
cvtsi2sdl 0x24(%rbx), %xmm1
divsd %xmm1, %xmm0
leaq 0x3befd(%rip), %rdi     # 0x4a062
movl %r15d, %esi
movb $0x1, %al
callq 0xc070
leaq 0x3bf0a(%rip), %rdi     # 0x4a080
movl %ebp, %esi
xorl %eax, %eax
callq 0xc070
leaq 0x3bf15(%rip), %rdi     # 0x4a09b
movsd (%rsp), %xmm0
movb $0x1, %al
callq 0xc070
leaq 0x3bf15(%rip), %rdi     # 0x4a0ae
movsd 0x10(%rsp), %xmm0
movb $0x1, %al
callq 0xc070
leaq 0x3bf1e(%rip), %rdi     # 0x4a0cb
movsd 0x18(%rsp), %xmm0
movb $0x1, %al
callq 0xc070
leaq 0x3bf24(%rip), %rdi     # 0x4a0e5
movsd 0x8(%rsp), %xmm0
movb $0x1, %al
callq 0xc070
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
movsd 0x10(%r14), %xmm2
leaq 0x3bf21(%rip), %rdi     # 0x4a107
movb $0x3, %al
callq 0xc070
movsd 0x100(%rbx), %xmm0
movsd 0x108(%rbx), %xmm1
movsd 0x110(%rbx), %xmm2
movsd 0x118(%rbx), %xmm3
movsd 0x120(%rbx), %xmm4
movsd 0x128(%rbx), %xmm5
leaq 0x3befc(%rip), %rdi     # 0x4a120
movb $0x6, %al
callq 0xc070
movsd 0x118(%rbx), %xmm0
movsd 0x120(%rbx), %xmm1
subsd 0x100(%rbx), %xmm0
subsd 0x108(%rbx), %xmm1
movsd 0x128(%rbx), %xmm2
subsd 0x110(%rbx), %xmm2
leaq 0x3bee8(%rip), %rdi     # 0x4a14a
movb $0x3, %al
callq 0xc070
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3beeb(%rip), %rdi     # 0x4a168
callq 0xc570
jmp 0xe296
movq 0x8(%r14), %rsi
leaq 0x3bd81(%rip), %rdi     # 0x4a010
xorl %eax, %eax
callq 0x4965e
pushq $0x1
popq %rdi
callq 0xc470
movq %rax, %r14
movl $0x138, %esi            # imm = 0x138
movq %rbx, %rdi
callq 0xc390
movq %r14, %rdi
callq 0xc630
nop