// File: 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:
subq $0x88, %rsp
movsd %xmm0, 0x80(%rsp)
movsd %xmm1, 0x78(%rsp)
movl %edi, 0x74(%rsp)
movl %esi, 0x70(%rsp)
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0x70ad0(%rip), %rax     # 0x1fa390
cmpb $0x0, 0x1c(%rax)
jne 0x1898db
leaq 0x14005(%rip), %rdi     # 0x19d8d2
leaq 0x25929(%rip), %rsi     # 0x1af1fd
movb $0x0, %al
callq 0x17de70
cmpl $0x1, 0x74(%rsp)
jge 0x1898ea
movl $0x1, 0x74(%rsp)
cmpl $0x1, 0x70(%rsp)
jge 0x1898f9
movl $0x1, 0x70(%rsp)
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
movl 0x70(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x70(%rsp)
imull $0x3, 0x74(%rsp), %eax
imull 0x70(%rsp), %eax
movslq %eax, %rsi
movl $0x8, %edi
callq 0x226a0
movq %rax, 0x38(%rsp)
imull $0x3, 0x74(%rsp), %eax
imull 0x70(%rsp), %eax
movslq %eax, %rsi
movl $0x8, %edi
callq 0x226a0
movq %rax, 0x30(%rsp)
callq 0x23110
movl 0x70(%rsp), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
movsd 0x8229(%rip), %xmm0     # 0x191b88
divsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movl 0x74(%rsp), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
movsd 0x25bc4(%rip), %xmm0    # 0x1af540
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x70(%rsp), %eax
jge 0x189b30
movsd 0x50(%rsp), %xmm0
callq 0x233b0
movsd %xmm0, 0x18(%rsp)
movsd 0x50(%rsp), %xmm0
callq 0x22190
movsd %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x74(%rsp), %eax
jge 0x189b0e
movl 0x28(%rsp), %eax
imull 0x74(%rsp), %eax
addl 0x2c(%rsp), %eax
imull $0x3, %eax, %eax
movl %eax, 0x4(%rsp)
movsd 0x58(%rsp), %xmm0
callq 0x233b0
movsd %xmm0, 0x8(%rsp)
movsd 0x58(%rsp), %xmm0
callq 0x22190
movsd %xmm0, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
movsd 0x60(%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
movsd 0x68(%rsp), %xmm3
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movq 0x38(%rsp), %rax
movslq 0x4(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x20(%rsp), %xmm0
movsd 0x60(%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
movsd 0x68(%rsp), %xmm3
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movq 0x38(%rsp), %rax
movslq 0x4(%rsp), %rcx
movsd %xmm0, 0x8(%rax,%rcx,8)
movsd 0x10(%rsp), %xmm0
mulsd 0x68(%rsp), %xmm0
movq 0x38(%rsp), %rax
movslq 0x4(%rsp), %rcx
movsd %xmm0, 0x10(%rax,%rcx,8)
movsd 0x18(%rsp), %xmm0
mulsd 0x8(%rsp), %xmm0
movq 0x30(%rsp), %rax
movslq 0x4(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x20(%rsp), %xmm0
mulsd 0x8(%rsp), %xmm0
movq 0x30(%rsp), %rax
movslq 0x4(%rsp), %rcx
movsd %xmm0, 0x8(%rax,%rcx,8)
movsd 0x10(%rsp), %xmm0
movq 0x30(%rsp), %rax
movslq 0x4(%rsp), %rcx
movsd %xmm0, 0x10(%rax,%rcx,8)
movsd 0x40(%rsp), %xmm0
addsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x1899d8
movsd 0x48(%rsp), %xmm0
addsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x189997
movl $0x7, %edi
callq 0x221b0
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movl 0x74(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x189c95
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
movl 0x70(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x189c83
movl 0x28(%rsp), %eax
imull 0x74(%rsp), %eax
addl 0x2c(%rsp), %eax
imull $0x3, %eax, %eax
movl %eax, (%rsp)
movq 0x30(%rsp), %rdi
movslq (%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0x22fb0
movq 0x38(%rsp), %rdi
movslq (%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0x221d0
movq 0x30(%rsp), %rdi
movslq (%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
addq $0x18, %rdi
callq 0x22fb0
movq 0x38(%rsp), %rdi
movslq (%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
addq $0x18, %rdi
callq 0x221d0
movq 0x30(%rsp), %rdi
movslq (%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
imull $0x3, 0x74(%rsp), %eax
cltq
shlq $0x3, %rax
addq %rax, %rdi
addq $0x18, %rdi
callq 0x22fb0
movq 0x38(%rsp), %rdi
movslq (%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
imull $0x3, 0x74(%rsp), %eax
cltq
shlq $0x3, %rax
addq %rax, %rdi
addq $0x18, %rdi
callq 0x221d0
movq 0x30(%rsp), %rdi
movslq (%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
imull $0x3, 0x74(%rsp), %eax
cltq
shlq $0x3, %rax
addq %rax, %rdi
callq 0x22fb0
movq 0x38(%rsp), %rdi
movslq (%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
imull $0x3, 0x74(%rsp), %eax
cltq
shlq $0x3, %rax
addq %rax, %rdi
callq 0x221d0
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x189b5d
jmp 0x189c85
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x189b42
callq 0x22de0
movq 0x38(%rsp), %rdi
callq 0x22c30
movq 0x30(%rsp), %rdi
callq 0x22c30
callq 0x233a0
addq $0x88, %rsp
retq
nopl (%rax,%rax)