// File: /workspace/github_cpp_makefile_star2_O3/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 %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
testq %rdi, %rdi
jne 0xd2ac7
leaq 0x274fc(%rip), %rdi     # 0xf9fae
leaq 0x27fc6(%rip), %rsi     # 0xfaa7f
leaq 0x27feb(%rip), %rdx     # 0xfaaab
xorl %eax, %eax
callq 0xcfe73
movq 0x73da2(%rip), %r14     # 0x146870
testq %r14, %r14
je 0xd2ae3
movq %r14, %rdi
movq %rbx, %rsi
callq 0xd2bf5
movq (%r14), %r14
jmp 0xd2ace
movq 0x73d96(%rip), %rax     # 0x146880
testq %rax, %rax
je 0xd2b10
movq 0x20(%rax), %rcx
testq %rcx, %rcx
je 0xd2b0b
cmpq %rbx, 0x20(%rcx)
jne 0xd2b06
movq $0x0, 0x20(%rcx)
movq (%rcx), %rcx
jmp 0xd2af3
movq (%rax), %rax
jmp 0xd2aea
movq 0x38(%rbx), %rax
testq %rax, %rax
je 0xd2b71
movq 0x73d88(%rip), %r14     # 0x1468a8
movq %rbx, 0x73d81(%rip)     # 0x1468a8
callq *%rax
movq %r14, 0x73d78(%rip)     # 0x1468a8
jmp 0xd2b71
movq (%r14), %rcx
movq 0x8(%r14), %rax
testq %rcx, %rcx
je 0xd2b42
movq %rax, 0x8(%rcx)
testq %rax, %rax
je 0xd2b4d
movq %rcx, (%rax)
movq (%r14), %rcx
movq %rcx, 0x20(%rbx)
cmpq %r14, 0x28(%rbx)
jne 0xd2b5b
movq %rax, 0x28(%rbx)
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0xd2b69
callq 0x21ad0
movq %r14, %rdi
callq 0x21ad0
movq 0x20(%rbx), %r14
testq %r14, %r14
jne 0xd2b32
movq 0x60(%rbx), %rdi
cmpq %rdi, 0x73d1b(%rip)     # 0x1468a0
jne 0xd2b92
xorl %edi, %edi
callq 0xd314d
movq 0x60(%rbx), %rdi
callq 0xd293c
movq (%rbx), %rcx
movq 0x8(%rbx), %rax
testq %rcx, %rcx
je 0xd2ba7
movq %rax, 0x8(%rcx)
testq %rax, %rax
je 0xd2baf
movq %rcx, (%rax)
cmpq %rbx, 0x73cca(%rip)     # 0x146880
jne 0xd2bc2
movq (%rbx), %rcx
movq %rcx, 0x73cbe(%rip)     # 0x146880
cmpq %rbx, 0x73cbf(%rip)     # 0x146888
jne 0xd2bd2
movq %rax, 0x73cb6(%rip)     # 0x146888
cmpq %rbx, 0x73ccf(%rip)     # 0x1468a8
jne 0xd2be6
movq $0x0, 0x73cc2(%rip) # 0x1468a8
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x21ad0