// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
testq %rdi, %rdi
jne 0xbd82f
leaq 0x27444(%rip), %rdi     # 0xe4c5e
leaq 0x27ece(%rip), %rsi     # 0xe56ef
leaq 0x27ef3(%rip), %rdx     # 0xe571b
xorl %eax, %eax
callq 0xbad73
leaq 0x7a05a(%rip), %r14     # 0x137890
movq (%r14), %r14
testq %r14, %r14
je 0xbd84b
movq %r14, %rdi
movq %rbx, %rsi
callq 0xbd907
jmp 0xbd836
leaq 0x7a04e(%rip), %rax     # 0x1378a0
movq (%rax), %rax
testq %rax, %rax
je 0xbd873
leaq 0x20(%rax), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
je 0xbd852
cmpq %rbx, 0x20(%rcx)
jne 0xbd85e
andq $0x0, 0x20(%rcx)
jmp 0xbd85e
movq 0x38(%rbx), %rax
testq %rax, %rax
je 0xbd893
movq 0x7a045(%rip), %r14     # 0x1378c8
movq %rbx, 0x7a03e(%rip)     # 0x1378c8
callq *%rax
movq %r14, 0x7a035(%rip)     # 0x1378c8
leaq 0x20(%rbx), %r14
movq (%r14), %r15
testq %r15, %r15
je 0xbd8bd
movq %r14, %rdi
movq %r15, %rsi
callq 0xbd7d7
movq 0x18(%r15), %rdi
callq 0x21ad0
movq %r15, %rdi
callq 0x21ad0
jmp 0xbd897
movq 0x60(%rbx), %rdi
cmpq %rdi, 0x79ff8(%rip)     # 0x1378c0
jne 0xbd8d5
xorl %edi, %edi
callq 0xbde17
movq 0x60(%rbx), %rdi
callq 0xbd70e
leaq 0x79fbf(%rip), %rdi     # 0x1378a0
movq %rbx, %rsi
callq 0xbd7d7
cmpq %rbx, 0x79fd8(%rip)     # 0x1378c8
jne 0xbd8fa
andq $0x0, 0x79fce(%rip)     # 0x1378c8
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x21ad0