// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1bf43
leaq 0x7f027(%rip), %rax     # 0x9af48
movsd (%rax), %xmm1
addsd %xmm1, %xmm1
mulsd 0x78(%r12), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
cmpl $0x9, %eax
pushq $0x8
popq %rbp
cmovgel %eax, %ebp
jmp 0x1bf46
pushq $0x20
popq %rbp
movl %ebp, %eax
movq %rax, 0x18(%rsp)
leaq (,%rax,8), %r15
movq %r15, %rdi
callq 0xe030
movq %rax, 0x20(%rsp)
movq %r15, %rdi
callq 0xe030
leaq 0x7eff7(%rip), %rcx     # 0x9af68
movsd (%rcx), %xmm0
movsd %xmm0, 0x30(%rsp)
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x28(%rsp)
movq %rax, %r15
xorl %r14d, %r14d
leaq 0x40(%rsp), %r13
cmpq %r14, 0x18(%rsp)
je 0x1c069
cvtsi2sd %r14d, %xmm0
mulsd 0x30(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x78(%r12), %xmm1
movsd %xmm1, 0x8(%rsp)
callq 0xe890
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x10(%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 0x77259(%rip), %xmm2    # 0x93260
movq %r13, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x37b4c
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq 0x20(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
movsd 0x50(%r12), %xmm2
mulsd 0x76fd5(%rip), %xmm2    # 0x93010
movq %r13, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x37b4c
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq %rax, (%r15,%r14,8)
incq %r14
jmp 0x1bf90
movq %r15, 0x10(%rsp)
movabsq $0x100000000, %rbp      # imm = 0x100000000
movsd 0x50(%r12), %xmm2
mulsd 0x771d9(%rip), %xmm2    # 0x93260
leaq 0x40(%rsp), %r13
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq %r13, %rdi
callq 0x37b4c
movq (%rbx), %rax
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq %rax, %r13
movq 0x18(%rsp), %rax
decq %rax
movq %rax, 0x8(%rsp)
xorl %eax, %eax
cmpq %rax, 0x18(%rsp)
je 0x1c108
movq 0x20(%rsp), %rsi
movq (%rsi,%rax,8), %rcx
leaq 0x1(%rax), %r14
movq %rbp, %rdx
sarq $0x20, %rdx
cmpq %rax, 0x8(%rsp)
cmoveq %r15, %rdx
movq (%rsi,%rdx,8), %rdx
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
xorl %r8d, %r8d
callq *0x48(%rax)
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rbp
movq %r14, %rax
jmp 0x1c0bf
movsd 0x50(%r12), %xmm2
mulsd 0x76ef9(%rip), %xmm2    # 0x93010
leaq 0x40(%rsp), %r12
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq %r12, %rdi
callq 0x37b4c
movq (%rbx), %rax
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq %rax, %r12
movabsq $0x100000000, %r13      # imm = 0x100000000
xorl %eax, %eax
movq 0x10(%rsp), %rbp
cmpq %rax, 0x18(%rsp)
je 0x1c197
movq (%rbp,%rax,8), %rdx
leaq 0x1(%rax), %r14
movq %r13, %rcx
sarq $0x20, %rcx
cmpq %rax, 0x8(%rsp)
cmoveq %r15, %rcx
movq (%rbp,%rcx,8), %rcx
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq *0x48(%rax)
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r13
movq %r14, %rax
jmp 0x1c151
movabsq $0x100000000, %r15      # imm = 0x100000000
xorl %eax, %eax
cmpq %rax, 0x18(%rsp)
je 0x1c21c
movq 0x20(%rsp), %rdx
movq (%rdx,%rax,8), %r12
leaq 0x1(%rax), %r14
movq %r15, %rcx
sarq $0x20, %rcx
cmpq %rax, 0x8(%rsp)
movl $0x0, %esi
cmoveq %rsi, %rcx
movq (%rdx,%rcx,8), %rdx
movq (%rbp,%rax,8), %r13
movq 0x10(%rsp), %rax
movq (%rax,%rcx,8), %rbp
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rcx
xorl %r8d, %r8d
callq *0x48(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq 0x10(%rsp), %rbp
movq %r13, %rcx
xorl %r8d, %r8d
callq *0x48(%rax)
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r15
movq %r14, %rax
jmp 0x1c1a3
movq 0x20(%rsp), %rdi
callq 0xe5d0
movq %rbp, %rdi
callq 0xe5d0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop