// File: /workspace/github_cpp_makefile_star2_O1/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 0xd49f3
leaq 0x27580(%rip), %rdi     # 0xfbf5e
leaq 0x2804a(%rip), %rsi     # 0xfca2f
leaq 0x2806f(%rip), %rdx     # 0xfca5b
xorl %eax, %eax
callq 0xd1cf7
movq 0x73e76(%rip), %r14     # 0x148870
testq %r14, %r14
je 0xd4a0f
movq %r14, %rdi
movq %rbx, %rsi
callq 0xd4ae7
movq (%r14), %r14
jmp 0xd49fa
movq 0x73e6a(%rip), %rax     # 0x148880
testq %rax, %rax
je 0xd4a3c
movq 0x20(%rax), %rcx
testq %rcx, %rcx
je 0xd4a37
cmpq %rbx, 0x20(%rcx)
jne 0xd4a32
movq $0x0, 0x20(%rcx)
movq (%rcx), %rcx
jmp 0xd4a1f
movq (%rax), %rax
jmp 0xd4a16
movq 0x38(%rbx), %rax
testq %rax, %rax
je 0xd4a5c
movq 0x73e5c(%rip), %r14     # 0x1488a8
movq %rbx, 0x73e55(%rip)     # 0x1488a8
callq *%rax
movq %r14, 0x73e4c(%rip)     # 0x1488a8
movq 0x20(%rbx), %r14
testq %r14, %r14
je 0xd4a9a
leaq 0x20(%rbx), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xd4997
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0xd4a82
callq 0x21ae0
movq $0x0, 0x18(%r14)
movq %r14, %rdi
callq 0x21ae0
movq (%r15), %r14
testq %r14, %r14
jne 0xd4a69
movq 0x73dff(%rip), %rax     # 0x1488a0
cmpq 0x60(%rbx), %rax
jne 0xd4aae
xorl %edi, %edi
callq 0xd5037
movq 0x60(%rbx), %rdi
callq 0xd48be
leaq 0x73dc2(%rip), %rdi     # 0x148880
movq %rbx, %rsi
callq 0xd4997
cmpq %rbx, 0x73ddb(%rip)     # 0x1488a8
jne 0xd4ada
movq $0x0, 0x73dce(%rip) # 0x1488a8
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x21ae0