// File: /workspace/github_cpp_makefile_star2_O2/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, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
leaq 0x7139b(%rip), %rax     # 0x1331e0
cmpb $0x0, 0x1c(%rax)
jne 0xc1e60
leaq 0x12414(%rip), %rdi     # 0xd4266
leaq 0x23e00(%rip), %rsi     # 0xe5c59
xorl %eax, %eax
callq 0xbad73
cmpl $0x2, %r15d
pushq $0x1
popq %r13
cmovll %r13d, %r15d
cmpl $0x2, %ebx
cmovgel %ebx, %r13d
leal 0x1(%r13), %ebp
leal (%r15,%r15,2), %eax
addl $0x3, %eax
movl %eax, 0x2c(%rsp)
movl %eax, %r14d
imull %ebp, %r14d
pushq $0x8
popq %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x21600
movq %rax, %rbx
movq %r12, %rdi
movq %r14, %rsi
callq 0x21600
movq %rax, %r14
callq 0x21f70
movq %r13, 0x68(%rsp)
cvtsi2sd %r13d, %xmm0
movsd 0x6e78(%rip), %xmm2     # 0xc8d38
movapd %xmm2, %xmm3
cvtsi2sd %r15d, %xmm1
divsd %xmm0, %xmm3
movsd %xmm3, 0x78(%rsp)
divsd %xmm1, %xmm2
movsd %xmm2, 0x80(%rsp)
movq %r15, 0x70(%rsp)
imulq $0x18, %r15, %r12
addq $0x18, %r12
movq %r14, 0x18(%rsp)
leaq 0x10(%r14), %r13
movq %rbp, %r14
movq %rbx, 0x20(%rsp)
leaq 0x10(%rbx), %r15
xorpd %xmm0, %xmm0
xorl %ebp, %ebp
cmpq %r14, %rbp
je 0xc1fee
movsd %xmm0, 0x48(%rsp)
callq 0x221f0
movapd %xmm0, 0x30(%rsp)
movsd 0x48(%rsp), %xmm0
callq 0x21170
movapd 0x30(%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movapd %xmm1, 0x30(%rsp)
xorpd %xmm0, %xmm0
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0xc1fd4
movsd %xmm0, (%rsp)
movsd (%rsp), %xmm0
callq 0x221f0
movaps %xmm0, 0x50(%rsp)
movsd (%rsp), %xmm0
callq 0x21170
movapd 0x50(%rsp), %xmm4
movapd %xmm4, %xmm1
movsd 0x8(%rsp), %xmm2
mulsd %xmm2, %xmm1
addsd 0x10(%rsp), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movapd 0x30(%rsp), %xmm3
mulpd %xmm3, %xmm1
movupd %xmm1, -0x10(%r15,%rbx)
movapd %xmm4, %xmm1
unpcklpd %xmm4, %xmm1            # xmm1 = xmm1[0],xmm4[0]
mulpd %xmm3, %xmm1
movupd %xmm1, -0x10(%r13,%rbx)
movsd %xmm0, (%r13,%rbx)
mulsd %xmm2, %xmm0
movsd %xmm0, (%r15,%rbx)
movsd (%rsp), %xmm0
subsd 0x80(%rsp), %xmm0
addq $0x18, %rbx
jmp 0xc1f43
movsd 0x48(%rsp), %xmm0
addsd 0x78(%rsp), %xmm0
incq %rbp
addq %r12, %r13
addq %r12, %r15
jmp 0xc1f08
pushq $0x7
popq %rdi
callq 0x21190
movl 0x2c(%rsp), %eax
movl 0x70(%rsp), %ecx
movl 0x68(%rsp), %edx
movq %rdx, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
imulq $0x18, %rcx, %rcx
addq $0x18, %rcx
movq %rcx, (%rsp)
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,8), %r13
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,8), %rbx
xorl %r14d, %r14d
xorl %eax, %eax
cmpq 0x10(%rsp), %rax
je 0xc20d3
movq %rax, 0x30(%rsp)
movq %r14, 0x50(%rsp)
movq 0x8(%rsp), %rbp
subq $0x1, %rbp
jb 0xc20bd
movq 0x18(%rsp), %r12
leaq (%r12,%r14), %rdi
callq 0x21e20
movq 0x20(%rsp), %r15
leaq (%r15,%r14), %rdi
callq 0x211b0
leaq (%r12,%r14), %rdi
addq $0x18, %rdi
callq 0x21e20
leaq (%r15,%r14), %rdi
addq $0x18, %rdi
callq 0x211b0
leaq (%rbx,%r14), %r15
leaq (%rbx,%r14), %rdi
addq $0x18, %rdi
callq 0x21e20
leaq (%r14,%r13), %r12
leaq (%r14,%r13), %rdi
addq $0x18, %rdi
callq 0x211b0
movq %r15, %rdi
callq 0x21e20
movq %r12, %rdi
callq 0x211b0
addq (%rsp), %r14
jmp 0xc2049
movq 0x30(%rsp), %rax
incq %rax
movq 0x50(%rsp), %r14
addq $0x18, %r14
jmp 0xc202f
callq 0x21c60
movq 0x20(%rsp), %rdi
callq 0x21ad0
movq 0x18(%rsp), %rdi
callq 0x21ad0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x221e0