// File: tomfunkhouser[P]gaps/pkgs/fglut/freeglut_menu.c
// Function: fghDisplayMenuBox
static void fghDisplayMenuBox( SFG_Menu* menu )
{
    SFG_MenuEntry *menuEntry;
    int i;
    int border = FREEGLUT_MENU_BORDER;

    /*
     * Have the menu box drawn first. The +- values are
     * here just to make it more nice-looking...
     */
    /* a non-black dark version of the below. */
    glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
    glBegin( GL_QUAD_STRIP );
        glVertex2i( menu->Width         , 0                    );
        glVertex2i( menu->Width - border,                border);
        glVertex2i( 0                   , 0                    );
        glVertex2i(               border,                border);
        glVertex2i( 0                   , menu->Height         );
        glVertex2i(               border, menu->Height - border);
    glEnd( );

    /* a non-black dark version of the below. */
    glColor4f( 0.5f, 0.5f, 0.5f, 1.0f );
    glBegin( GL_QUAD_STRIP );
        glVertex2i( 0                   , menu->Height         );
        glVertex2i(               border, menu->Height - border);
        glVertex2i( menu->Width         , menu->Height         );
        glVertex2i( menu->Width - border, menu->Height - border);
        glVertex2i( menu->Width         , 0                    );
        glVertex2i( menu->Width - border,                border);
    glEnd( );

    glColor4fv( menu_pen_back );
    glBegin( GL_QUADS );
        glVertex2i(               border,                border);
        glVertex2i( menu->Width - border,                border);
        glVertex2i( menu->Width - border, menu->Height - border);
        glVertex2i(               border, menu->Height - border);
    glEnd( );

    /* Check if any of the submenus is currently active... */
    for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
         menuEntry;
         menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
    {
        /* Has the menu been marked as active, maybe? */
        if( menuEntry->IsActive )
        {
            /*
             * That's truly right, and we need to have it highlighted.
             * There is an assumption that mouse cursor didn't move
             * since the last check of menu activity state:
             */
            int menuID = menuEntry->Ordinal;

            /* So have the highlight drawn... */
            glColor4fv( menu_pen_hback );
            glBegin( GL_QUADS );
                glVertex2i( border,
                            (menuID + 0)*FREEGLUT_MENU_HEIGHT + border );
                glVertex2i( menu->Width - border,
                            (menuID + 0)*FREEGLUT_MENU_HEIGHT + border );
                glVertex2i( menu->Width - border,
                            (menuID + 1)*FREEGLUT_MENU_HEIGHT + border );
                glVertex2i( border,
                            (menuID + 1)*FREEGLUT_MENU_HEIGHT + border );
            glEnd( );
        }
    }

    /* Print the menu entries now... */

    glColor4fv( menu_pen_fore );

    for( menuEntry = (SFG_MenuEntry *)menu->Entries.First, i = 0;
         menuEntry;
         menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next, ++i )
    {
        /* If the menu entry is active, set the color to white */
        if( menuEntry->IsActive )
            glColor4fv( menu_pen_hfore );

        /* Move the raster into position... */
        /* Try to center the text - JCJ 31 July 2003*/
        glRasterPos2i(
            2 * border,
            ( i + 1 )*FREEGLUT_MENU_HEIGHT -
            ( int )( FREEGLUT_MENU_HEIGHT*0.3 - border )
        );

        /* Have the label drawn, character after character: */
        glutBitmapString( FREEGLUT_MENU_FONT,
                          (unsigned char *)menuEntry->Text);

        /* If it's a submenu, draw a right arrow */
        if( menuEntry->SubMenu )
        {
            int width = glutBitmapWidth( FREEGLUT_MENU_FONT, '_' );
            int x_base = menu->Width - 2 - width;
            int y_base = i*FREEGLUT_MENU_HEIGHT + border;
            glBegin( GL_TRIANGLES );
                glVertex2i( x_base, y_base + 2*border);
                glVertex2i( menu->Width - 2, y_base +
                            ( FREEGLUT_MENU_HEIGHT + border) / 2 );
                glVertex2i( x_base, y_base + FREEGLUT_MENU_HEIGHT - border );
            glEnd( );
        }

        /* If the menu entry is active, reset the color */
        if( menuEntry->IsActive )
            glColor4fv( menu_pen_fore );
    }
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movl $0x2, 0x50(%rsp)
movss 0xe86f(%rip), %xmm3     # 0x18e088
movaps %xmm3, %xmm0
movaps %xmm3, %xmm1
movaps %xmm3, %xmm2
callq 0x22820
movl $0x8, %edi
callq 0x221b0
movq 0x60(%rsp), %rax
movl 0x44(%rax), %edi
xorl %esi, %esi
callq 0x22d40
movq 0x60(%rsp), %rax
movl 0x44(%rax), %edi
subl 0x50(%rsp), %edi
movl 0x50(%rsp), %esi
callq 0x22d40
xorl %esi, %esi
movl %esi, %edi
callq 0x22d40
movl 0x50(%rsp), %edi
movl 0x50(%rsp), %esi
callq 0x22d40
movq 0x60(%rsp), %rax
movl 0x48(%rax), %esi
xorl %edi, %edi
callq 0x22d40
movl 0x50(%rsp), %edi
movq 0x60(%rsp), %rax
movl 0x48(%rax), %esi
subl 0x50(%rsp), %esi
callq 0x22d40
callq 0x22de0
movss 0x11030(%rip), %xmm2    # 0x1908cc
movss 0xe7e4(%rip), %xmm3     # 0x18e088
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x22820
movl $0x8, %edi
callq 0x221b0
movq 0x60(%rsp), %rax
movl 0x48(%rax), %esi
xorl %edi, %edi
callq 0x22d40
movl 0x50(%rsp), %edi
movq 0x60(%rsp), %rax
movl 0x48(%rax), %esi
subl 0x50(%rsp), %esi
callq 0x22d40
movq 0x60(%rsp), %rax
movl 0x44(%rax), %edi
movq 0x60(%rsp), %rax
movl 0x48(%rax), %esi
callq 0x22d40
movq 0x60(%rsp), %rax
movl 0x44(%rax), %edi
subl 0x50(%rsp), %edi
movq 0x60(%rsp), %rax
movl 0x48(%rax), %esi
subl 0x50(%rsp), %esi
callq 0x22d40
movq 0x60(%rsp), %rax
movl 0x44(%rax), %edi
xorl %esi, %esi
callq 0x22d40
movq 0x60(%rsp), %rax
movl 0x44(%rax), %edi
subl 0x50(%rsp), %edi
movl 0x50(%rsp), %esi
callq 0x22d40
callq 0x22de0
leaq 0x7ac51(%rip), %rdi     # 0x1fa590
callq 0x22380
movl $0x7, %edi
callq 0x221b0
movl 0x50(%rsp), %edi
movl 0x50(%rsp), %esi
callq 0x22d40
movq 0x60(%rsp), %rax
movl 0x44(%rax), %edi
subl 0x50(%rsp), %edi
movl 0x50(%rsp), %esi
callq 0x22d40
movq 0x60(%rsp), %rax
movl 0x44(%rax), %edi
subl 0x50(%rsp), %edi
movq 0x60(%rsp), %rax
movl 0x48(%rax), %esi
subl 0x50(%rsp), %esi
callq 0x22d40
movl 0x50(%rsp), %edi
movq 0x60(%rsp), %rax
movl 0x48(%rax), %esi
subl 0x50(%rsp), %esi
callq 0x22d40
callq 0x22de0
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0x17faf3
movq 0x58(%rsp), %rax
cmpb $0x0, 0x28(%rax)
je 0x17fadf
movq 0x58(%rsp), %rax
movl 0x14(%rax), %eax
movl %eax, 0x4c(%rsp)
leaq 0x7abbd(%rip), %rdi     # 0x1fa5a0
callq 0x22380
movl $0x7, %edi
callq 0x221b0
movl 0x50(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x4c(%rsp), %eax
addl $0x0, %eax
movl %eax, 0x20(%rsp)
leaq 0x8040c(%rip), %rdi     # 0x1ffe18
callq 0x17a700
movl 0x20(%rsp), %esi
movl 0x24(%rsp), %edi
addl $0x2, %eax
imull %eax, %esi
addl 0x50(%rsp), %esi
callq 0x22d40
movq 0x60(%rsp), %rax
movl 0x44(%rax), %eax
subl 0x50(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x4c(%rsp), %eax
addl $0x0, %eax
movl %eax, 0x28(%rsp)
leaq 0x803ce(%rip), %rdi     # 0x1ffe18
callq 0x17a700
movl 0x28(%rsp), %esi
movl 0x2c(%rsp), %edi
addl $0x2, %eax
imull %eax, %esi
addl 0x50(%rsp), %esi
callq 0x22d40
movq 0x60(%rsp), %rax
movl 0x44(%rax), %eax
subl 0x50(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
leaq 0x80390(%rip), %rdi     # 0x1ffe18
callq 0x17a700
movl 0x30(%rsp), %esi
movl 0x34(%rsp), %edi
addl $0x2, %eax
imull %eax, %esi
addl 0x50(%rsp), %esi
callq 0x22d40
movl 0x50(%rsp), %eax
movl %eax, 0x3c(%rsp)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
leaq 0x8035a(%rip), %rdi     # 0x1ffe18
callq 0x17a700
movl 0x38(%rsp), %esi
movl 0x3c(%rsp), %edi
addl $0x2, %eax
imull %eax, %esi
addl 0x50(%rsp), %esi
callq 0x22d40
callq 0x22de0
jmp 0x17fae1
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x58(%rsp)
jmp 0x17f9b5
leaq 0x7aab6(%rip), %rdi     # 0x1fa5b0
callq 0x22380
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0x17fcfc
movq 0x58(%rsp), %rax
cmpb $0x0, 0x28(%rax)
je 0x17fb38
leaq 0x7aa8d(%rip), %rdi     # 0x1fa5c0
callq 0x22380
movl 0x50(%rsp), %eax
shll %eax
movl %eax, 0x1c(%rsp)
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
leaq 0x802c4(%rip), %rdi     # 0x1ffe18
callq 0x17a700
movl %eax, %ecx
movl 0x14(%rsp), %eax
addl $0x2, %ecx
imull %ecx, %eax
movl %eax, 0x18(%rsp)
leaq 0x802a8(%rip), %rdi     # 0x1ffe18
callq 0x17a700
movl 0x18(%rsp), %esi
movl 0x1c(%rsp), %edi
addl $0x2, %eax
cvtsi2sd %eax, %xmm0
cvtsi2sdl 0x50(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
movsd 0xea4f(%rip), %xmm2     # 0x18e5f8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
subl %eax, %esi
callq 0x222e0
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rsi
leaq 0x8024c(%rip), %rdi     # 0x1ffe18
callq 0x17a3d0
movq 0x58(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x17fcc6
leaq 0x80230(%rip), %rdi     # 0x1ffe18
movl $0x5f, %esi
callq 0x17a560
movl %eax, 0x48(%rsp)
movq 0x60(%rsp), %rax
movl 0x44(%rax), %eax
subl $0x2, %eax
subl 0x48(%rsp), %eax
movl %eax, 0x44(%rsp)
movl 0x54(%rsp), %eax
movl %eax, (%rsp)
leaq 0x80201(%rip), %rdi     # 0x1ffe18
callq 0x17a700
movl %eax, %ecx
movl (%rsp), %eax
addl $0x2, %ecx
imull %ecx, %eax
addl 0x50(%rsp), %eax
movl %eax, 0x40(%rsp)
movl $0x4, %edi
callq 0x221b0
movl 0x44(%rsp), %edi
movl 0x40(%rsp), %esi
movl 0x50(%rsp), %eax
shll %eax
addl %eax, %esi
callq 0x22d40
movq 0x60(%rsp), %rax
movl 0x44(%rax), %eax
subl $0x2, %eax
movl %eax, 0x8(%rsp)
movl 0x40(%rsp), %eax
movl %eax, 0x4(%rsp)
leaq 0x801ac(%rip), %rdi     # 0x1ffe18
callq 0x17a700
movl 0x4(%rsp), %esi
movl 0x8(%rsp), %edi
addl $0x2, %eax
addl 0x50(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl %eax, %esi
callq 0x22d40
movl 0x44(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x40(%rsp), %eax
movl %eax, 0xc(%rsp)
leaq 0x80172(%rip), %rdi     # 0x1ffe18
callq 0x17a700
movl 0xc(%rsp), %esi
movl 0x10(%rsp), %edi
addl $0x2, %eax
addl %eax, %esi
subl 0x50(%rsp), %esi
callq 0x22d40
callq 0x22de0
movq 0x58(%rsp), %rax
cmpb $0x0, 0x28(%rax)
je 0x17fcdd
leaq 0x7a8d8(%rip), %rdi     # 0x1fa5b0
callq 0x22380
jmp 0x17fcdf
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x58(%rsp)
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x17fb15
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)