// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
movq %r15, %rdi
callq 0x6630a
xorl %r13d, %r13d
movslq 0x14(%rbx), %rax
cmpq %rax, %r13
jge 0x1bc49
movq 0x8(%rbx), %rax
movq (%rax,%r13,8), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x21234
leaq 0x18(%r12), %rsi
leaq 0x58(%r12), %rcx
addq $0x48, %r12
movq (%r14), %r10
movq %r14, %rdi
movq %rax, %rdx
movq %r12, %r8
xorl %r9d, %r9d
callq *0x38(%r10)
testq %rax, %rax
je 0x1bc8c
movq %r15, %rdi
movq %rax, %rsi
callq 0x22bfc
incq %r13
jmp 0x1bbf7
xorl %r15d, %r15d
movslq 0x24(%rbx), %rax
cmpq %rax, %r15
jge 0x1bca2
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)
incq %r15
testq %rax, %rax
jne 0x1bc4c
movq %rsp, %rdi
callq 0x66378
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
xorl %r15d, %r15d
movslq 0x34(%rbx), %rax
cmpq %rax, %r15
jge 0x1bc8c
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 0x1bc8c
movq 0x98(%r12), %rcx
movq %rcx, 0x98(%rax)
movl 0xa0(%r12), %ecx
movl %ecx, 0xa0(%rax)
incq %r15
jmp 0x1bca5
jmp 0x1bd1a
jmp 0x1bd1a
jmp 0x1bd1a
movq %rax, %rbx
movq %rsp, %rdi
callq 0x66378
movq %rbx, %rdi
callq 0xe810
nop