// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3TriangleArray.cpp
// Function: gaps::R3TriangleArray::LoadMesh(gaps::R3Mesh const&)
void R3TriangleArray::
LoadMesh(const R3Mesh& mesh)
{
  // Create vertices
  RNArray<R3TriangleVertex *> triangle_vertices;
  for (int i = 0; i < mesh.NVertices(); i++) {
    R3MeshVertex *mesh_vertex = mesh.Vertex(i);
    const R3Point& position = mesh.VertexPosition(mesh_vertex);
    R3TriangleVertex *triangle_vertex = new R3TriangleVertex(position);
    triangle_vertices.Insert(triangle_vertex);
    vertices.Insert(triangle_vertex);

    // Check if should assign vertex normal
    RNBoolean smooth = TRUE;
    const RNAngle max_smooth_angle = RN_PI/5.0;
    for (int j = 0; j < mesh.VertexValence(mesh_vertex); j++) {
      R3MeshEdge *mesh_edge = mesh.EdgeOnVertex(mesh_vertex, j);
      RNAngle angle = mesh.EdgeInteriorAngle(mesh_edge);
      if (fabs(angle - RN_PI) > max_smooth_angle) { smooth = FALSE; break; }
    }

    // Assign vertex normal
    if (smooth) {
      const R3Vector& normal = mesh.VertexNormal(mesh_vertex);
      triangle_vertex->SetNormal(normal);
    }
    
    // Assign vertex color
    if (!mesh.VertexColor(mesh_vertex).IsBlack()) {
      triangle_vertex->SetColor(mesh.VertexColor(mesh_vertex));
    }

    // Assign vertex texture coordinates
    triangle_vertex->SetTextureCoords(mesh.VertexTextureCoords(mesh_vertex));
  }

  // Create triangles
  for (int i = 0; i < mesh.NFaces(); i++) {
    R3MeshFace *mesh_face = mesh.Face(i);
    int i0 = mesh.VertexID(mesh.VertexOnFace(mesh_face, 0));
    int i1 = mesh.VertexID(mesh.VertexOnFace(mesh_face, 1));
    int i2 = mesh.VertexID(mesh.VertexOnFace(mesh_face, 2));
    R3TriangleVertex *v0 = triangle_vertices.Kth(i0);
    R3TriangleVertex *v1 = triangle_vertices.Kth(i1);
    R3TriangleVertex *v2 = triangle_vertices.Kth(i2);
    R3Triangle *triangle = new R3Triangle(v0, v1, v2);
    triangles.Insert(triangle);
  }

  // Update everything
  Update();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x705ec
cmpl $0x0, 0x14(%r14)
jle 0x5399d
movq 0x8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x28(%rsp)
leaq 0x56774(%rip), %rax     # 0xa9fa8
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
divsd 0x4ea12(%rip), %xmm0    # 0xa2258
movsd %xmm0, 0x30(%rsp)
xorl %ebx, %ebx
movq 0x8(%r14), %rax
movq (%rax,%rbx,8), %rbp
movl $0x68, %edi
callq 0xe440
movq %rax, %r13
leaq 0x18(%rbp), %rsi
movq %rax, %rdi
callq 0x54110
movl 0x24(%rsp), %edx
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x70682
movq 0x8(%rsp), %rax
movl 0x14(%rax), %edx
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x70682
cmpl $0x0, 0x14(%rbp)
jle 0x538e7
movl $0x1, %r12d
xorl %r15d, %r15d
movq 0x8(%rbp), %rax
movq (%rax,%r15,8), %rsi
movq %r14, %rdi
callq 0x11fe4
subsd 0x10(%rsp), %xmm0
andpd 0x4e9ae(%rip), %xmm0    # 0xa2270
ucomisd 0x30(%rsp), %xmm0
jbe 0x538d0
movl $0x0, %r12d
ja 0x538de
incq %r15
movslq 0x14(%rbp), %rax
cmpq %rax, %r15
jl 0x538a4
testl %r12d, %r12d
xorpd %xmm1, %xmm1
je 0x5393c
testb $0x2, 0x78(%rbp)
jne 0x538fc
movq (%r14), %rax
movq %r14, %rdi
movq %rbp, %rsi
callq *0x2b0(%rax)
leaq 0x30(%rbp), %rsi
leaq 0x18(%r13), %rdi
callq 0x3dc6a
movsd 0x18(%r13), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x53937
jp 0x53937
movsd 0x20(%r13), %xmm0
ucomisd %xmm1, %xmm0
jne 0x53937
jp 0x53937
movsd 0x28(%r13), %xmm0
ucomisd %xmm1, %xmm0
jne 0x53937
jnp 0x5393c
orb $0x1, 0x59(%r13)
movsd 0x58(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jne 0x53963
jp 0x53963
movsd 0x60(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jne 0x53963
jp 0x53963
movsd 0x68(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jne 0x53963
jnp 0x53975
leaq 0x58(%rbp), %rsi
leaq 0x30(%r13), %rdi
callq 0x704f2
orb $0x4, 0x59(%r13)
addq $0x48, %rbp
movq %r13, %rdi
addq $0x48, %rdi
movq %rbp, %rsi
callq 0x68f66
orb $0x2, 0x59(%r13)
incq %rbx
movslq 0x14(%r14), %rax
cmpq %rax, %rbx
jl 0x5384e
cmpl $0x0, 0x34(%r14)
jle 0x53a29
movq 0x8(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
movq 0x28(%r14), %rax
movq (%rax,%r15,8), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rdx
movslq 0x70(%rcx), %rcx
movslq 0x70(%rdx), %rdx
movq 0x18(%rax), %rax
movslq 0x70(%rax), %rax
movq 0x18(%rsp), %rsi
movq (%rsi,%rcx,8), %r13
movq (%rsi,%rdx,8), %rbp
movq (%rsi,%rax,8), %rbx
movl $0x88, %edi
callq 0xe440
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x54628
movq 0x8(%rsp), %rax
movl 0x24(%rax), %edx
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x70682
incq %r15
movslq 0x34(%r14), %rax
cmpq %rax, %r15
jl 0x539b9
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x248(%rax)
leaq 0x18(%rsp), %rdi
callq 0x70656
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x53a79
movq %rax, %rbx
movl $0x68, %esi
movq %r13, %rdi
jmp 0x53a6a
movq %rax, %rbx
movl $0x88, %esi
movq %r12, %rdi
callq 0xe450
jmp 0x53a7c
jmp 0x53a79
jmp 0x53a79
jmp 0x53a79
jmp 0x53a79
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x70656
movq %rbx, %rdi
callq 0xe7e0