// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movq %rsi, %r12
movq %rdi, %r14
movl $0x20, %ebp
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1e218
leaq 0x8bdd2(%rip), %rax     # 0xa9fc8
movsd (%rax), %xmm1
addsd %xmm1, %xmm1
mulsd 0x78(%r12), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
cmpl $0x9, %eax
movl $0x8, %ebp
cmovgel %eax, %ebp
movl %ebp, %ebx
leaq (,%rbx,8), %r15
movq %r15, %rdi
callq 0xe030
movq %rax, 0x10(%rsp)
movq %r15, %rdi
movq %rbx, %r15
callq 0xe030
movq %rax, %rbx
leaq 0x8bda4(%rip), %rax     # 0xa9fe8
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %ebp, %ebp
leaq 0x40(%rsp), %r13
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0x30(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x78(%r12), %xmm1
movsd %xmm1, 0x8(%rsp)
callq 0xe860
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x78(%r12), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x38(%rsp), %xmm0
callq 0xe0f0
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x50(%r12), %xmm2
mulsd 0x83f90(%rip), %xmm2    # 0xa2260
movq %r13, %rdi
movsd 0x20(%rsp), %xmm0
callq 0x3c532
movq (%r14), %rax
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
movsd 0x50(%r12), %xmm2
mulsd 0x83d2c(%rip), %xmm2    # 0xa2030
movq %r13, %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x3c532
movq (%r14), %rax
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq %rax, (%rbx,%rbp,8)
incq %rbp
cmpq %rbp, %r15
jne 0x1e262
movq %rbx, 0x18(%rsp)
movsd 0x50(%r12), %xmm2
mulsd 0x83f16(%rip), %xmm2    # 0xa2260
leaq 0x40(%rsp), %r13
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq %r13, %rdi
callq 0x3c532
movq (%r14), %rax
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq %rax, %r13
negq %r15
movq 0x10(%rsp), %rbp
movq %r15, %rsi
movl $0x1, %r15d
movq -0x8(%rbp,%r15,8), %rcx
movq %rsi, %rax
addq %r15, %rax
movq %r15, %rax
movl $0x0, %edx
cmoveq %rdx, %rax
movq (%rbp,%rax,8), %rdx
movq (%r14), %rax
movq %r14, %rdi
movq %rsi, %rbx
movq %r13, %rsi
xorl %r8d, %r8d
callq *0x48(%rax)
movq %rbx, %rsi
leaq (%rbx,%r15), %rax
incq %rax
incq %r15
cmpq $0x1, %rax
jne 0x1e381
movsd 0x50(%r12), %xmm2
mulsd 0x83c5f(%rip), %xmm2    # 0xa2030
leaq 0x40(%rsp), %r12
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq %r12, %rdi
callq 0x3c532
movq (%r14), %rax
xorl %ebp, %ebp
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq %rbx, %rcx
movq %rax, %r12
movl $0x1, %r13d
movq 0x18(%rsp), %rsi
movq -0x8(%rsi,%r13,8), %rdx
movq %rcx, %rax
addq %r13, %rax
movq %r13, %rax
cmoveq %rbp, %rax
movq (%rsi,%rax,8), %rcx
movq (%r14), %rax
movq %rsi, %r15
movq %r14, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq *0x48(%rax)
movq %r15, %rsi
movq %rbx, %rcx
leaq (%rbx,%r13), %rax
incq %rax
incq %r13
cmpq $0x1, %rax
jne 0x1e407
movl $0x1, %r15d
movq 0x10(%rsp), %rdx
movq -0x8(%rdx,%r15,8), %r12
movq %rcx, %rax
addq %r15, %rax
movq %r15, %rax
movl $0x0, %ecx
cmoveq %rcx, %rax
movq (%rdx,%rax,8), %rdx
movq 0x18(%rsp), %rcx
movq -0x8(%rcx,%r15,8), %r13
movq (%rcx,%rax,8), %rbp
movq (%r14), %rax
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rcx
xorl %r8d, %r8d
callq *0x48(%rax)
movq (%r14), %rax
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq *0x48(%rax)
movq %rbx, %rcx
leaq (%rbx,%r15), %rax
incq %rax
incq %r15
cmpq $0x1, %rax
jne 0x1e44b
movq 0x10(%rsp), %rdi
callq 0xe5b0
movq 0x18(%rsp), %rdi
callq 0xe5b0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq