// File: tomfunkhouser[P]gaps/pkgs/fglut/freeglut_structure.c
// Function: fgDestroyMenu
void fgDestroyMenu( SFG_Menu* menu )
{
    SFG_Window *window;
    SFG_Menu *from;

    FREEGLUT_INTERNAL_ERROR_EXIT ( menu, "Menu destroy function called with null menu",
                                   "fgDestroyMenu" );

    /* First of all, have all references to this menu removed from all windows: */
    for( window = (SFG_Window *)fgStructure.Windows.First;
         window;
         window = (SFG_Window *)window->Node.Next )
        fghRemoveMenuFromWindow( window, menu );

    /* Now proceed with removing menu entries that lead to this menu */
    for( from = ( SFG_Menu * )fgStructure.Menus.First;
         from;
         from = ( SFG_Menu * )from->Node.Next )
        fghRemoveMenuFromMenu( from, menu );

    /*
     * If the programmer defined a destroy callback, call it
     * A. Donev: But first make this the active menu
     */
    if( menu->Destroy )
    {
        SFG_Menu *activeMenu=fgStructure.CurrentMenu;
        fgStructure.CurrentMenu = menu;
        menu->Destroy( );
        fgStructure.CurrentMenu = activeMenu;
    }

    /*
     * Now we are pretty sure the menu is not used anywhere
     * and that we can remove all of its entries
     */
    while( menu->Entries.First )
    {
        SFG_MenuEntry *entry = ( SFG_MenuEntry * ) menu->Entries.First;

        fgListRemove( &menu->Entries, &entry->Node );

        if( entry->Text )
            free( entry->Text );
        entry->Text = NULL;

        free( entry );
    }

    if( fgStructure.CurrentWindow == menu->Window )
        fgSetWindow( NULL );
    fgDestroyWindow( menu->Window );
    fgListRemove( &fgStructure.Menus, &menu->Node );
    if( fgStructure.CurrentMenu == menu )
        fgStructure.CurrentMenu = NULL;

    free( menu );
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x182b9d
leaq 0x2b6c2(%rip), %rdi     # 0x1ae24a
leaq 0x2c140(%rip), %rsi     # 0x1aeccf
leaq 0x2c165(%rip), %rdx     # 0x1aecfb
movb $0x0, %al
callq 0x17de70
movq 0x7d33c(%rip), %rax     # 0x1ffee0
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x182bcf
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x182d00
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x182ba9
movq 0x7d31a(%rip), %rax     # 0x1ffef0
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x182c01
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x182dc0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x182bdb
movq 0x20(%rsp), %rax
cmpq $0x0, 0x38(%rax)
je 0x182c39
movq 0x7d304(%rip), %rax     # 0x1fff18
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x7d2f3(%rip)     # 0x1fff18
movq 0x20(%rsp), %rax
callq *0x38(%rax)
movq 0x8(%rsp), %rax
movq %rax, 0x7d2df(%rip)     # 0x1fff18
jmp 0x182c3b
movq 0x20(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x182c95
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
addq $0x20, %rdi
movq (%rsp), %rsi
callq 0x182ae0
movq (%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x182c7e
movq (%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x22c30
movq (%rsp), %rax
movq $0x0, 0x18(%rax)
movq (%rsp), %rdi
callq 0x22c30
jmp 0x182c3b
movq 0x7d274(%rip), %rax     # 0x1fff10
movq 0x20(%rsp), %rcx
cmpq 0x60(%rcx), %rax
jne 0x182cb0
xorl %eax, %eax
movl %eax, %edi
callq 0x1838e0
movq 0x20(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0x1829b0
movq 0x20(%rsp), %rsi
leaq 0x7d216(%rip), %rdi     # 0x1ffee0
addq $0x10, %rdi
callq 0x182ae0
movq 0x7d23e(%rip), %rax     # 0x1fff18
cmpq 0x20(%rsp), %rax
jne 0x182cec
movq $0x0, 0x7d22c(%rip) # 0x1fff18
movq 0x20(%rsp), %rdi
callq 0x22c30
addq $0x28, %rsp
retq
nopl (%rax,%rax)