// File: 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:
subq $0x208, %rsp            # imm = 0x208
movq %rdi, 0x200(%rsp)
movq %rsi, 0x1f8(%rsp)
movq 0x200(%rsp), %rax
movq %rax, 0x100(%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0x36800
movl $0x0, 0x1e4(%rsp)
movl 0x1e4(%rsp), %eax
movl %eax, 0xf8(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x135e0
movl %eax, 0xfc(%rsp)
jmp 0x2abc3
movl 0xf8(%rsp), %eax
movl 0xfc(%rsp), %ecx
cmpl %ecx, %eax
jge 0x2ad81
movq 0x1f8(%rsp), %rdi
movl 0x1e4(%rsp), %esi
callq 0x13630
movq %rax, 0xf0(%rsp)
jmp 0x2abf7
movq 0xf0(%rsp), %rax
movq %rax, 0x1c8(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x1c8(%rsp), %rsi
callq 0x13660
movq %rax, 0xe8(%rsp)
jmp 0x2ac26
movq 0xe8(%rsp), %rax
movq %rax, 0x1c0(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x1c8(%rsp), %rsi
callq 0x36860
movq %rax, 0xe0(%rsp)
jmp 0x2ac55
movq 0xe0(%rsp), %rax
movq %rax, 0x1b8(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x1c8(%rsp), %rsi
callq 0x368d0
movq %rax, 0xd8(%rsp)
jmp 0x2ac84
movq 0xd8(%rsp), %rax
movq %rax, 0x1b0(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x1c8(%rsp), %rsi
callq 0x368f0
movq %rax, 0xd0(%rsp)
jmp 0x2acb3
movq 0x100(%rsp), %rdi
movq 0xd0(%rsp), %rax
movq %rax, 0x1a8(%rsp)
movq 0x1c0(%rsp), %rsi
movq 0x1b8(%rsp), %rdx
movq 0x1b0(%rsp), %rcx
movq 0x1a8(%rsp), %r8
movq (%rdi), %rax
movq 0x38(%rax), %rax
xorl %r9d, %r9d
callq *%rax
movq %rax, 0xc8(%rsp)
jmp 0x2ad01
movq 0xc8(%rsp), %rax
movq %rax, 0x1a0(%rsp)
cmpq $0x0, 0x1a0(%rsp)
jne 0x2ad52
movl $0x1, 0x19c(%rsp)
jmp 0x2b297
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d8(%rsp)
movl %eax, 0x1d4(%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0x36850
jmp 0x2b2ac
movq 0x1a0(%rsp), %rsi
leaq 0x1e8(%rsp), %rdi
callq 0x37410
jmp 0x2ad69
jmp 0x2ad6b
movl 0x1e4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1e4(%rsp)
jmp 0x2ab9f
movl $0x0, 0x198(%rsp)
movl 0x198(%rsp), %eax
movl %eax, 0xc0(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x135c0
movl %eax, 0xc4(%rsp)
jmp 0x2adb0
movl 0xc0(%rsp), %eax
movl 0xc4(%rsp), %ecx
cmpl %ecx, %eax
jge 0x2af7d
movq 0x1f8(%rsp), %rdi
movl 0x198(%rsp), %esi
callq 0x36930
movq %rax, 0xb8(%rsp)
jmp 0x2ade4
movq 0xb8(%rsp), %rax
movq %rax, 0x190(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x190(%rsp), %rsi
xorl %edx, %edx
callq 0x36960
movq %rax, 0xb0(%rsp)
jmp 0x2ae15
movq 0xb0(%rsp), %rax
movq %rax, 0x188(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x190(%rsp), %rsi
movl $0x1, %edx
callq 0x36960
movq %rax, 0xa8(%rsp)
jmp 0x2ae49
movq 0xa8(%rsp), %rax
movq %rax, 0x180(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x188(%rsp), %rsi
callq 0x36910
movl %eax, 0xa4(%rsp)
jmp 0x2ae77
movl 0xa4(%rsp), %eax
movl %eax, 0x17c(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x180(%rsp), %rsi
callq 0x36910
movl %eax, 0xa0(%rsp)
jmp 0x2aea3
movl 0xa0(%rsp), %eax
movl %eax, 0x178(%rsp)
movl 0x17c(%rsp), %esi
leaq 0x1e8(%rsp), %rdi
callq 0x377e0
movq %rax, 0x98(%rsp)
jmp 0x2aecf
movq 0x98(%rsp), %rax
movq %rax, 0x170(%rsp)
movl 0x178(%rsp), %esi
leaq 0x1e8(%rsp), %rdi
callq 0x377e0
movq %rax, 0x90(%rsp)
jmp 0x2aefd
movq 0x100(%rsp), %rdi
movq 0x90(%rsp), %rax
movq %rax, 0x168(%rsp)
movq 0x170(%rsp), %rsi
movq 0x168(%rsp), %rdx
movq (%rdi), %rax
movq 0x40(%rax), %rax
xorl %ecx, %ecx
callq *%rax
movq %rax, 0x88(%rsp)
jmp 0x2af3a
movq 0x88(%rsp), %rax
movq %rax, 0x160(%rsp)
cmpq $0x0, 0x160(%rsp)
jne 0x2af65
movl $0x1, 0x19c(%rsp)
jmp 0x2b297
jmp 0x2af67
movl 0x198(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x198(%rsp)
jmp 0x2ad8c
movl $0x0, 0x15c(%rsp)
movl 0x15c(%rsp), %eax
movl %eax, 0x80(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x135a0
movl %eax, 0x84(%rsp)
jmp 0x2afac
movl 0x80(%rsp), %eax
movl 0x84(%rsp), %ecx
cmpl %ecx, %eax
jge 0x2b28c
movq 0x1f8(%rsp), %rdi
movl 0x15c(%rsp), %esi
callq 0x136d0
movq %rax, 0x78(%rsp)
jmp 0x2afdd
movq 0x78(%rsp), %rax
movq %rax, 0x150(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x150(%rsp), %rsi
xorl %edx, %edx
callq 0x13700
movq %rax, 0x70(%rsp)
jmp 0x2b008
movq 0x70(%rsp), %rax
movq %rax, 0x148(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x150(%rsp), %rsi
movl $0x1, %edx
callq 0x13700
movq %rax, 0x68(%rsp)
jmp 0x2b036
movq 0x68(%rsp), %rax
movq %rax, 0x140(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x150(%rsp), %rsi
movl $0x2, %edx
callq 0x13700
movq %rax, 0x60(%rsp)
jmp 0x2b064
movq 0x60(%rsp), %rax
movq %rax, 0x138(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x148(%rsp), %rsi
callq 0x36910
movl %eax, 0x5c(%rsp)
jmp 0x2b08c
movl 0x5c(%rsp), %eax
movl %eax, 0x134(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x140(%rsp), %rsi
callq 0x36910
movl %eax, 0x58(%rsp)
jmp 0x2b0b2
movl 0x58(%rsp), %eax
movl %eax, 0x130(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x138(%rsp), %rsi
callq 0x36910
movl %eax, 0x54(%rsp)
jmp 0x2b0d8
movl 0x54(%rsp), %eax
movl %eax, 0x12c(%rsp)
movl 0x134(%rsp), %esi
leaq 0x1e8(%rsp), %rdi
callq 0x377e0
movq %rax, 0x48(%rsp)
jmp 0x2b0fe
movq 0x48(%rsp), %rax
movq %rax, 0x120(%rsp)
movl 0x130(%rsp), %esi
leaq 0x1e8(%rsp), %rdi
callq 0x377e0
movq %rax, 0x40(%rsp)
jmp 0x2b126
movq 0x40(%rsp), %rax
movq %rax, 0x118(%rsp)
movl 0x12c(%rsp), %esi
leaq 0x1e8(%rsp), %rdi
callq 0x377e0
movq %rax, 0x38(%rsp)
jmp 0x2b14e
movq 0x100(%rsp), %rdi
movq 0x38(%rsp), %rax
movq %rax, 0x110(%rsp)
movq 0x120(%rsp), %rsi
movq 0x118(%rsp), %rdx
movq 0x110(%rsp), %rcx
movq (%rdi), %rax
movq 0x48(%rax), %rax
xorl %r8d, %r8d
callq *%rax
movq %rax, 0x30(%rsp)
jmp 0x2b18e
movq 0x30(%rsp), %rax
movq %rax, 0x108(%rsp)
cmpq $0x0, 0x108(%rsp)
jne 0x2b1b6
movl $0x1, 0x19c(%rsp)
jmp 0x2b297
movq 0x108(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x150(%rsp), %rsi
callq 0x369e0
movl %eax, 0x2c(%rsp)
jmp 0x2b1de
movl 0x2c(%rsp), %edx
movq 0x20(%rsp), %rsi
movq 0x100(%rsp), %rdi
callq 0x369c0
jmp 0x2b1f6
movq 0x108(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x150(%rsp), %rsi
callq 0x36a20
movl %eax, 0x1c(%rsp)
jmp 0x2b21e
movl 0x1c(%rsp), %edx
movq 0x10(%rsp), %rsi
movq 0x100(%rsp), %rdi
callq 0x36a00
jmp 0x2b236
movq 0x108(%rsp), %rax
movq %rax, (%rsp)
movq 0x1f8(%rsp), %rdi
movq 0x150(%rsp), %rsi
callq 0x36a60
movl %eax, 0xc(%rsp)
jmp 0x2b25d
movl 0xc(%rsp), %edx
movq (%rsp), %rsi
movq 0x100(%rsp), %rdi
callq 0x36a40
jmp 0x2b274
jmp 0x2b276
movl 0x15c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x15c(%rsp)
jmp 0x2af88
movl $0x0, 0x19c(%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0x36850
addq $0x208, %rsp            # imm = 0x208
retq
movq 0x1d8(%rsp), %rdi
callq 0xf890
nopl (%rax)