// File: tomfunkhouser[P]gaps/pkgs/fglut/freeglut_geometry.c
// Function: glutSolidCylinder
void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
{
    int i,j;

    /* Step in z and radius as stacks are drawn. */

    double z0,z1;
    const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );

    /* Pre-computed circle */

    double *sint,*cost;

    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );

    fghCircleTable(&sint,&cost,-slices);

    /* Cover the base and top */

    glBegin(GL_TRIANGLE_FAN);
        glNormal3d(0.0, 0.0, -1.0 );
        glVertex3d(0.0, 0.0,  0.0 );
        for (j=0; j<=slices; j++)
          glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
    glEnd();

    glBegin(GL_TRIANGLE_FAN);
        glNormal3d(0.0, 0.0, 1.0   );
        glVertex3d(0.0, 0.0, height);
        for (j=slices; j>=0; j--)
          glVertex3d(cost[j]*radius, sint[j]*radius, height);
    glEnd();

    /* Do the stacks */

    z0 = 0.0;
    z1 = zStep;

    for (i=1; i<=stacks; i++)
    {
        if (i==stacks)
            z1 = height;

        glBegin(GL_QUAD_STRIP);
            for (j=0; j<=slices; j++ )
            {
                glNormal3d(cost[j],        sint[j],        0.0 );
                glVertex3d(cost[j]*radius, sint[j]*radius, z0  );
                glVertex3d(cost[j]*radius, sint[j]*radius, z1  );
            }
        glEnd();

        z0 = z1; z1 += zStep;
    }

    /* Release sin and cos tables */

    free(sint);
    free(cost);
}

// Assembly:
subq $0x58, %rsp
movsd %xmm0, 0x50(%rsp)
movsd %xmm1, 0x48(%rsp)
movl %edi, 0x44(%rsp)
movl %esi, 0x40(%rsp)
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
cmpl $0x0, 0x40(%rsp)
jle 0x188f55
movl 0x40(%rsp), %eax
movl %eax, 0x4(%rsp)
jmp 0x188f60
movl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x188f60
movsd 0x8(%rsp), %xmm0
movl 0x4(%rsp), %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x71411(%rip), %rax     # 0x1fa390
cmpb $0x0, 0x1c(%rax)
jne 0x188f9a
leaq 0x14946(%rip), %rdi     # 0x19d8d2
leaq 0x264a9(%rip), %rsi     # 0x1af43c
movb $0x0, %al
callq 0x17de70
xorl %edx, %edx
subl 0x44(%rsp), %edx
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x188210
movl $0x6, %edi
callq 0x221b0
xorps %xmm1, %xmm1
movsd 0x55ec(%rip), %xmm2     # 0x18e5b0
movaps %xmm1, %xmm0
callq 0x22330
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x23020
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x44(%rsp), %eax
jg 0x18902b
movq 0x10(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
mulsd 0x50(%rsp), %xmm0
movq 0x18(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd 0x50(%rsp), %xmm1
xorps %xmm2, %xmm2
callq 0x23020
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x188fe2
callq 0x22de0
movl $0x6, %edi
callq 0x221b0
xorps %xmm1, %xmm1
movsd 0x4fcb(%rip), %xmm2     # 0x18e010
movaps %xmm1, %xmm0
callq 0x22330
movsd 0x48(%rsp), %xmm2
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0x23020
movl 0x44(%rsp), %eax
movl %eax, 0x38(%rsp)
cmpl $0x0, 0x38(%rsp)
jl 0x1890af
movq 0x10(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
mulsd 0x50(%rsp), %xmm0
movq 0x18(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd 0x50(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
callq 0x23020
movl 0x38(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x189066
callq 0x22de0
xorps %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movl $0x1, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x40(%rsp), %eax
jg 0x1891e8
movl 0x3c(%rsp), %eax
cmpl 0x40(%rsp), %eax
jne 0x1890f5
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movl $0x8, %edi
callq 0x221b0
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x44(%rsp), %eax
jg 0x1891b5
movq 0x10(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x18(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
xorps %xmm2, %xmm2
callq 0x22330
movq 0x10(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
mulsd 0x50(%rsp), %xmm0
movq 0x18(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd 0x50(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
callq 0x23020
movq 0x10(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
mulsd 0x50(%rsp), %xmm0
movq 0x18(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd 0x50(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
callq 0x23020
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x189107
callq 0x22de0
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x20(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x1890d1
movq 0x18(%rsp), %rdi
callq 0x22c30
movq 0x10(%rsp), %rdi
callq 0x22c30
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)