// File: tomfunkhouser[P]gaps/pkgs/fglut/freeglut_geometry.c
// Function: glutWireTorus
void FGAPIENTRY glutWireTorus( 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 ( "glutWireTorus" );

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

  /* 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 ;
  dphi = -2.0 * M_PI / (double)nSides ;
  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;
  }

  for( i=0; i<nSides; i++ )
  {
    glBegin( GL_LINE_LOOP );

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

    glEnd();
  }

  for( j=0; j<nRings; j++ )
  {
    glBegin(GL_LINE_LOOP);

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

    glEnd();
  }

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

// Assembly:
subq $0x98, %rsp
movsd %xmm0, 0x90(%rsp)
movsd %xmm1, 0x88(%rsp)
movl %edi, 0x84(%rsp)
movl %esi, 0x80(%rsp)
movsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x88(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
leaq 0x70ee4(%rip), %rax     # 0x1fa390
cmpb $0x0, 0x1c(%rax)
jne 0x1894c7
leaq 0x14419(%rip), %rdi     # 0x19d8d2
leaq 0x25d2f(%rip), %rsi     # 0x1af1ef
movb $0x0, %al
callq 0x17de70
cmpl $0x1, 0x84(%rsp)
jge 0x1894dc
movl $0x1, 0x84(%rsp)
cmpl $0x1, 0x80(%rsp)
jge 0x1894f1
movl $0x1, 0x80(%rsp)
imull $0x3, 0x84(%rsp), %eax
imull 0x80(%rsp), %eax
movslq %eax, %rsi
movl $0x8, %edi
callq 0x226a0
movq %rax, 0x48(%rsp)
imull $0x3, 0x84(%rsp), %eax
imull 0x80(%rsp), %eax
movslq %eax, %rsi
movl $0x8, %edi
callq 0x226a0
movq %rax, 0x40(%rsp)
callq 0x23110
cvtsi2sdl 0x80(%rsp), %xmm1
movsd 0x863d(%rip), %xmm0     # 0x191b88
divsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
cvtsi2sdl 0x84(%rsp), %xmm1
movsd 0x25fda(%rip), %xmm0    # 0x1af540
divsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x80(%rsp), %eax
jge 0x189723
movsd 0x60(%rsp), %xmm0
callq 0x233b0
movsd %xmm0, 0x28(%rsp)
movsd 0x60(%rsp), %xmm0
callq 0x22190
movsd %xmm0, 0x30(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x68(%rsp)
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x84(%rsp), %eax
jge 0x189701
movl 0x38(%rsp), %eax
imull 0x84(%rsp), %eax
addl 0x3c(%rsp), %eax
imull $0x3, %eax, %eax
movl %eax, 0x14(%rsp)
movsd 0x68(%rsp), %xmm0
callq 0x233b0
movsd %xmm0, 0x18(%rsp)
movsd 0x68(%rsp), %xmm0
callq 0x22190
movsd %xmm0, 0x20(%rsp)
movsd 0x28(%rsp), %xmm0
movsd 0x70(%rsp), %xmm2
movsd 0x18(%rsp), %xmm1
movsd 0x78(%rsp), %xmm3
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movq 0x48(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x30(%rsp), %xmm0
movsd 0x70(%rsp), %xmm2
movsd 0x18(%rsp), %xmm1
movsd 0x78(%rsp), %xmm3
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movq 0x48(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd %xmm0, 0x8(%rax,%rcx,8)
movsd 0x20(%rsp), %xmm0
mulsd 0x78(%rsp), %xmm0
movq 0x48(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd %xmm0, 0x10(%rax,%rcx,8)
movsd 0x28(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
movq 0x40(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x30(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
movq 0x40(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd %xmm0, 0x8(%rax,%rcx,8)
movsd 0x20(%rsp), %xmm0
movq 0x40(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd %xmm0, 0x10(%rax,%rcx,8)
movsd 0x50(%rsp), %xmm0
addsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x1895c5
movsd 0x58(%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x189581
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x84(%rsp), %eax
jge 0x1897c0
movl $0x2, %edi
callq 0x221b0
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x80(%rsp), %eax
jge 0x1897ab
movl 0x38(%rsp), %eax
imull 0x84(%rsp), %eax
addl 0x3c(%rsp), %eax
imull $0x3, %eax, %eax
movl %eax, 0x10(%rsp)
movq 0x40(%rsp), %rdi
movslq 0x10(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0x22fb0
movq 0x48(%rsp), %rdi
movslq 0x10(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0x221d0
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x18974e
callq 0x22de0
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x18972b
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x80(%rsp), %eax
jge 0x18985d
movl $0x2, %edi
callq 0x221b0
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x84(%rsp), %eax
jge 0x189848
movl 0x38(%rsp), %eax
imull 0x84(%rsp), %eax
addl 0x3c(%rsp), %eax
imull $0x3, %eax, %eax
movl %eax, 0xc(%rsp)
movq 0x40(%rsp), %rdi
movslq 0xc(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0x22fb0
movq 0x48(%rsp), %rdi
movslq 0xc(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0x221d0
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x1897eb
callq 0x22de0
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x1897c8
movq 0x48(%rsp), %rdi
callq 0x22c30
movq 0x40(%rsp), %rdi
callq 0x22c30
callq 0x233a0
addq $0x98, %rsp
retq
nop