// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::CreateCylinder(gaps::R3Cylinder const&, double)
void R3Mesh::
CreateCylinder(const R3Cylinder& cylinder, RNLength vertex_spacing)
{
  // Determine number of vertices per circle
  int n = 32;
  if (vertex_spacing > 0) {
    n = (int) (2.0 * RN_PI * cylinder.Radius() / vertex_spacing);
    if (n < 8) n = 8;
  }

  // Allocate vertex pointers
  R3MeshVertex ***vertices = new R3MeshVertex **[2];
  vertices[0] = new R3MeshVertex * [ n ];
  vertices[1] = new R3MeshVertex * [ n ];

  // Create vertices
  for (int i = 0; i < n; i++) {
    RNAngle a = i*RN_TWO_PI/n;
    RNScalar x = cylinder.Radius()*cos(a);
    RNScalar y = cylinder.Radius()*sin(a);
    vertices[0][i] = CreateVertex(R3Point(x, y, -0.5*cylinder.Height()));
    vertices[1][i] = CreateVertex(R3Point(x, y,  0.5*cylinder.Height()));
  }

  // Create bottom faces
  R3MeshVertex *v0c = CreateVertex(R3Point(0, 0, -0.5*cylinder.Height()));
  for (int i = 0; i < n; i++) {
    R3MeshVertex *v00 = vertices[0][i];
    R3MeshVertex *v01 = vertices[0][(i+1)%n];
    CreateFace(v0c, v01, v00);
  }
  
  // Create top faces
  R3MeshVertex *v1c = CreateVertex(R3Point(0, 0, 0.5*cylinder.Height()));
  for (int i = 0; i < n; i++) {
    R3MeshVertex *v10 = vertices[1][i];
    R3MeshVertex *v11 = vertices[1][(i+1)%n];
    CreateFace(v1c, v10, v11);
  }
  
  // Create side faces
  for (int i = 0; i < n; i++) {
    R3MeshVertex *v00 = vertices[0][i];
    R3MeshVertex *v01 = vertices[0][(i+1)%n];
    R3MeshVertex *v10 = vertices[1][i];
    R3MeshVertex *v11 = vertices[1][(i+1)%n];
    CreateFace(v00, v01, v11);
    CreateFace(v00, v11, v10);
  }

  // Delete vertex pointers
  delete [] vertices[0];
  delete [] vertices[1];
  delete [] vertices;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movl $0x20, %r13d
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1e280
leaq 0x8bd4b(%rip), %rax     # 0xa9fa8
movsd (%rax), %xmm1
addsd %xmm1, %xmm1
mulsd 0x78(%r15), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
cmpl $0x9, %eax
movl $0x8, %r13d
cmovgel %eax, %r13d
movl $0x10, %edi
callq 0xe030
movq %rax, %r14
movl %r13d, %ebp
leaq (,%rbp,8), %r12
movq %r12, %rdi
callq 0xe030
movq %rax, (%r14)
movq %r12, %rdi
callq 0xe030
movq %rax, 0x8(%r14)
leaq 0x8bd12(%rip), %rax     # 0xa9fc8
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %r13d, %r13d
leaq 0x30(%rsp), %r12
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
mulsd 0x20(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x78(%r15), %xmm1
movsd %xmm1, 0x8(%rsp)
callq 0xe860
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x78(%r15), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x28(%rsp), %xmm0
callq 0xe0f0
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x50(%r15), %xmm2
mulsd 0x83f1e(%rip), %xmm2    # 0xa2260
movq %r12, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x3ca26
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq (%r14), %rcx
movq %rax, (%rcx,%r13,8)
movsd 0x50(%r15), %xmm2
mulsd 0x83cbd(%rip), %xmm2    # 0xa2030
movq %r12, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x3ca26
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq 0x8(%r14), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
cmpq %r13, %rbp
jne 0x1e2d6
movsd 0x50(%r15), %xmm2
mulsd 0x83ea9(%rip), %xmm2    # 0xa2260
leaq 0x30(%rsp), %r12
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq %r12, %rdi
callq 0x3ca26
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq %rax, %r12
negq %rbp
movl $0x1, %r13d
movq (%r14), %rax
movq -0x8(%rax,%r13,8), %rcx
movq %rbp, %rdx
addq %r13, %rdx
movq %r13, %rdx
movl $0x0, %esi
cmoveq %rsi, %rdx
movq (%rax,%rdx,8), %rdx
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq *0x48(%rax)
leaq 0x1(,%r13), %rax
addq %rbp, %rax
incq %r13
cmpq $0x1, %rax
jne 0x1e3e6
movsd 0x50(%r15), %xmm2
mulsd 0x83bfb(%rip), %xmm2    # 0xa2030
leaq 0x30(%rsp), %r15
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq %r15, %rdi
callq 0x3ca26
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq %rax, %r15
movl $0x1, %r12d
movq %r14, %r13
xorl %r14d, %r14d
movq 0x8(%r13), %rax
movq -0x8(%rax,%r12,8), %rdx
movq %rbp, %rcx
addq %r12, %rcx
movq %r12, %rcx
cmoveq %r14, %rcx
movq (%rax,%rcx,8), %rcx
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
xorl %r8d, %r8d
callq *0x48(%rax)
leaq (%r12,%rbp), %rax
incq %rax
incq %r12
cmpq $0x1, %rax
jne 0x1e467
movl $0x1, %r14d
movq (%r13), %rax
movq 0x8(%r13), %rcx
movq -0x8(%rax,%r14,8), %r15
movq %rbp, %rdx
addq %r14, %rdx
movq %r14, %rsi
movl $0x0, %edx
cmoveq %rdx, %rsi
movq (%rax,%rsi,8), %rdx
movq -0x8(%rcx,%r14,8), %rax
movq %rax, 0x8(%rsp)
movq %rbp, %r12
movq %r13, %rbp
movq (%rcx,%rsi,8), %r13
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rcx
xorl %r8d, %r8d
callq *0x48(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbp, %r13
movq %r12, %rbp
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq *0x48(%rax)
leaq (%r12,%r14), %rax
incq %rax
incq %r14
cmpq $0x1, %rax
jne 0x1e4a6
movq (%r13), %rdi
testq %rdi, %rdi
je 0x1e52a
callq 0xe5b0
movq 0x8(%r13), %rdi
testq %rdi, %rdi
je 0x1e538
callq 0xe5b0
movq %r13, %rdi
callq 0xe5b0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop