// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::CreateCopy(gaps::R3Mesh const&)
void R3Mesh::
CreateCopy(const R3Mesh& mesh)
{
  // Copy vertices
  RNArray<R3MeshVertex *> verts;
  for (int i = 0; i < mesh.NVertices(); i++) {
    R3MeshVertex *vertex = mesh.Vertex(i);
    const R3Point& position = mesh.VertexPosition(vertex);
    const R3Vector& normal = mesh.VertexNormal(vertex);
    const RNRgb& color = mesh.VertexColor(vertex);
    const R2Point& texcoords = mesh.VertexTextureCoords(vertex);
    R3MeshVertex *copy_vertex = this->CreateVertex(position, normal, color, texcoords);
    if (!copy_vertex) return;
    verts.Insert(copy_vertex);
  }

  // Copy edges
  for (int i = 0; i < mesh.NEdges(); i++) {
    R3MeshEdge *edge = mesh.Edge(i);
    R3MeshVertex *v0 = mesh.VertexOnEdge(edge, 0);
    R3MeshVertex *v1 = mesh.VertexOnEdge(edge, 1);
    int i0 = mesh.VertexID(v0);
    int i1 = mesh.VertexID(v1);
    R3MeshVertex *copy_v0 = verts.Kth(i0);
    R3MeshVertex *copy_v1 = verts.Kth(i1);
    R3MeshEdge *copy_edge = this->CreateEdge(copy_v0, copy_v1);
    if (!copy_edge) return;
  }

  // Copy faces
  for (int i = 0; i < mesh.NFaces(); i++) {
    R3MeshFace *face = mesh.Face(i);
    R3MeshVertex *v0 = mesh.VertexOnFace(face, 0);
    R3MeshVertex *v1 = mesh.VertexOnFace(face, 1);
    R3MeshVertex *v2 = mesh.VertexOnFace(face, 2);
    int i0 = mesh.VertexID(v0);
    int i1 = mesh.VertexID(v1);
    int i2 = mesh.VertexID(v2);
    R3MeshVertex *copy_v0 = verts.Kth(i0);
    R3MeshVertex *copy_v1 = verts.Kth(i1);
    R3MeshVertex *copy_v2 = verts.Kth(i2);
    R3MeshFace *copy_face = this->CreateFace(copy_v0, copy_v1, copy_v2);
    if (!copy_face) return;
    this->SetFaceMaterial(copy_face, mesh.FaceMaterial(face));
    this->SetFaceSegment(copy_face, mesh.FaceSegment(face));
    this->SetFaceCategory(copy_face, mesh.FaceCategory(face));
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsp, %rdi
callq 0x6f80c
cmpl $0x0, 0x14(%rbx)
jle 0x1defa
xorl %r13d, %r13d
movq %rsp, %r15
movq 0x8(%rbx), %rax
movq (%rax,%r13,8), %r12
testb $0x2, 0x78(%r12)
jne 0x1deb4
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x2b0(%rax)
leaq 0x18(%r12), %rsi
leaq 0x30(%r12), %rdx
leaq 0x58(%r12), %rcx
addq $0x48, %r12
movq (%r14), %rax
movq %r14, %rdi
movq %r12, %r8
xorl %r9d, %r9d
callq *0x38(%rax)
testq %rax, %rax
je 0x1dfbd
movl 0xc(%rsp), %edx
movq %r15, %rdi
movq %rax, %rsi
callq 0x6f8a2
incq %r13
movslq 0x14(%rbx), %rax
cmpq %rax, %r13
jl 0x1de95
cmpl $0x0, 0x24(%rbx)
jle 0x1df47
xorl %r15d, %r15d
movq 0x18(%rbx), %rax
movq (%rax,%r15,8), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rax
movslq 0x70(%rcx), %rcx
movslq 0x70(%rax), %rax
movq (%rsp), %rdx
movq (%rdx,%rcx,8), %rsi
movq (%rdx,%rax,8), %rdx
movq (%r14), %rax
movq %r14, %rdi
xorl %ecx, %ecx
callq *0x40(%rax)
testq %rax, %rax
je 0x1dfbd
incq %r15
movslq 0x24(%rbx), %rax
cmpq %rax, %r15
jl 0x1df03
cmpl $0x0, 0x34(%rbx)
jle 0x1dfbd
xorl %r15d, %r15d
movq 0x28(%rbx), %rax
movq (%rax,%r15,8), %r12
movq 0x8(%r12), %rax
movq 0x10(%r12), %rcx
movq 0x18(%r12), %rdx
movslq 0x70(%rax), %rax
movslq 0x70(%rcx), %rcx
movslq 0x70(%rdx), %rdi
movq (%rsp), %r8
movq (%r8,%rax,8), %rsi
movq (%r8,%rcx,8), %rdx
movq (%r8,%rdi,8), %rcx
movq (%r14), %rax
movq %r14, %rdi
xorl %r8d, %r8d
callq *0x48(%rax)
testq %rax, %rax
je 0x1dfbd
movq 0x98(%r12), %rcx
movq %rcx, 0x98(%rax)
movl 0xa0(%r12), %ecx
movl %ecx, 0xa0(%rax)
incq %r15
movslq 0x34(%rbx), %rax
cmpq %rax, %r15
jl 0x1df50
movq %rsp, %rdi
callq 0x6f876
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x1dfd9
jmp 0x1dfd9
jmp 0x1dfd9
movq %rax, %rbx
movq %rsp, %rdi
callq 0x6f876
movq %rbx, %rdi
callq 0xe7e0