// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/fglut/freeglut_geometry.c
// Function: glutSolidTorus
void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
{
  double  iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
  double *vertex, *normal;
  int    i, j;
  double spsi, cpsi, sphi, cphi ;

  FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );

  if ( nSides < 1 ) nSides = 1;
  if ( nRings < 1 ) nRings = 1;

  /* Increment the number of sides and rings to allow for one more point than surface */
  nSides ++ ;
  nRings ++ ;

  /* Allocate the vertices array */
  vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
  normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );

  glPushMatrix();

  dpsi =  2.0 * M_PI / (double)(nRings - 1) ;
  dphi = -2.0 * M_PI / (double)(nSides - 1) ;
  psi  = 0.0;

  for( j=0; j<nRings; j++ )
  {
    cpsi = cos ( psi ) ;
    spsi = sin ( psi ) ;
    phi = 0.0;

    for( i=0; i<nSides; i++ )
    {
      int offset = 3 * ( j * nSides + i ) ;
      cphi = cos ( phi ) ;
      sphi = sin ( phi ) ;
      *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
      *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
      *(vertex + offset + 2) =                    sphi * iradius  ;
      *(normal + offset + 0) = cpsi * cphi ;
      *(normal + offset + 1) = spsi * cphi ;
      *(normal + offset + 2) =        sphi ;
      phi += dphi;
    }

    psi += dpsi;
  }

    glBegin( GL_QUADS );
  for( i=0; i<nSides-1; i++ )
  {
    for( j=0; j<nRings-1; j++ )
    {
      int offset = 3 * ( j * nSides + i ) ;
      glNormal3dv( normal + offset );
      glVertex3dv( vertex + offset );
      glNormal3dv( normal + offset + 3 );
      glVertex3dv( vertex + offset + 3 );
      glNormal3dv( normal + offset + 3 * nSides + 3 );
      glVertex3dv( vertex + offset + 3 * nSides + 3 );
      glNormal3dv( normal + offset + 3 * nSides );
      glVertex3dv( vertex + offset + 3 * nSides );
    }
  }

  glEnd();

  free ( vertex ) ;
  free ( normal ) ;
  glPopMatrix();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %esi, %ebx
movl %edi, %r15d
movsd %xmm1, 0x18(%rsp)
movsd %xmm0, 0x10(%rsp)
leaq 0x6aea7(%rip), %rax     # 0x1421c0
cmpb $0x0, 0x1c(%rax)
jne 0xd7334
leaq 0x12290(%rip), %rdi     # 0xe95b6
leaq 0x23cbc(%rip), %rsi     # 0xfafe9
xorl %eax, %eax
callq 0xcfe73
cmpl $0x2, %r15d
movl $0x1, %r12d
cmovll %r12d, %r15d
cmpl $0x2, %ebx
cmovgel %ebx, %r12d
leal 0x1(%r12), %ecx
leal (%r15,%r15,2), %eax
addl $0x3, %eax
movl %eax, 0x2c(%rsp)
movl %eax, %r13d
movq %rcx, %r14
imull %ecx, %r13d
movl $0x8, %edi
movq %r13, %rsi
callq 0x21600
movq %rax, %rbx
movl $0x8, %edi
movq %r13, %rsi
callq 0x21600
movq %rax, %r13
callq 0x21f50
movq %r12, 0x68(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movsd 0x6a13(%rip), %xmm2     # 0xdddb0
movapd %xmm2, %xmm3
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
divsd %xmm0, %xmm3
movsd %xmm3, 0x78(%rsp)
divsd %xmm1, %xmm2
movsd %xmm2, 0x80(%rsp)
movq %r13, 0x20(%rsp)
leaq 0x10(%r13), %rbp
movq %r15, 0x70(%rsp)
leaq (%r15,%r15,2), %rax
leaq 0x18(,%rax,8), %r12
movq %rbx, 0x48(%rsp)
leaq 0x10(%rbx), %r15
xorpd %xmm0, %xmm0
xorl %r13d, %r13d
movsd %xmm0, 0x40(%rsp)
callq 0x221d0
movapd %xmm0, 0x30(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0x21170
movaps 0x30(%rsp), %xmm1
movlhps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movaps %xmm1, 0x30(%rsp)
xorl %ebx, %ebx
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x221d0
movaps %xmm0, 0x50(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x21170
movapd 0x50(%rsp), %xmm4
movapd %xmm4, %xmm1
movsd 0x10(%rsp), %xmm3
mulsd %xmm3, %xmm1
addsd 0x18(%rsp), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movapd 0x30(%rsp), %xmm2
mulpd %xmm2, %xmm1
movupd %xmm1, -0x10(%r15,%rbx)
movapd %xmm4, %xmm1
unpcklpd %xmm4, %xmm1            # xmm1 = xmm1[0],xmm4[0]
mulpd %xmm2, %xmm1
movupd %xmm1, -0x10(%rbp,%rbx)
movsd %xmm0, (%rbp,%rbx)
mulsd %xmm3, %xmm0
movsd %xmm0, (%r15,%rbx)
movsd 0x8(%rsp), %xmm0
subsd 0x80(%rsp), %xmm0
addq $0x18, %rbx
cmpq %rbx, %r12
jne 0xd7418
movsd 0x40(%rsp), %xmm0
addsd 0x78(%rsp), %xmm0
incq %r13
addq %r12, %rbp
addq %r12, %r15
cmpq %r14, %r13
jne 0xd73ea
movl $0x7, %edi
callq 0x21190
movl 0x2c(%rsp), %eax
movl 0x70(%rsp), %ecx
movl 0x68(%rsp), %edx
movq %rdx, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
leaq (%rcx,%rcx,2), %rcx
leaq 0x18(,%rcx,8), %rdx
movq 0x48(%rsp), %r15
leaq (%r15,%rax,8), %r12
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,8), %r13
xorl %ebp, %ebp
xorl %eax, %eax
movq %rdx, 0x8(%rsp)
movq %rax, 0x30(%rsp)
movq 0x10(%rsp), %r14
movq %rbp, 0x50(%rsp)
movq 0x20(%rsp), %rbx
leaq (%rbx,%rbp), %rdi
callq 0x21e00
leaq (%r15,%rbp), %rdi
callq 0x211b0
leaq (%rbx,%rbp), %rdi
addq $0x18, %rdi
callq 0x21e00
leaq (%r15,%rbp), %rdi
addq $0x18, %rdi
callq 0x211b0
movq %r13, %r15
addq %rbp, %r15
leaq 0x18(,%rbp), %rdi
addq %r13, %rdi
callq 0x21e00
movq %r13, %rbx
leaq (%r12,%rbp), %r13
leaq (%r12,%rbp), %rdi
addq $0x18, %rdi
callq 0x211b0
movq %r15, %rdi
movq 0x48(%rsp), %r15
callq 0x21e00
movq %r13, %rdi
movq %rbx, %r13
callq 0x211b0
movq 0x8(%rsp), %rdx
addq %rdx, %rbp
decq %r14
jne 0xd751a
movq 0x30(%rsp), %rax
incq %rax
movq 0x50(%rsp), %rbp
addq $0x18, %rbp
cmpq 0x18(%rsp), %rax
jne 0xd750b
callq 0x21c50
movq %r15, %rdi
callq 0x21ad0
movq 0x20(%rsp), %rdi
callq 0x21ad0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x221c0