// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/fglut/freeglut_menu.c
// Function: fgCheckActiveMenu
GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed,
                              int mouse_x, int mouse_y )
{
    /*
     * Near as I can tell, this is the menu behaviour:
     *  - Down-click the menu button, menu not active:  activate
     *    the menu with its upper left-hand corner at the mouse
     *    location.
     *  - Down-click any button outside the menu, menu active:
     *    deactivate the menu
     *  - Down-click any button inside the menu, menu active:
     *    select the menu entry and deactivate the menu
     *  - Up-click the menu button, menu not active:  nothing happens
     *  - Up-click the menu button outside the menu, menu active:
     *    nothing happens
     *  - Up-click the menu button inside the menu, menu active:
     *    select the menu entry and deactivate the menu
     * Since menus can have submenus, we need to check this recursively.
     */
    if( window->ActiveMenu )
    {
        if( window == window->ActiveMenu->ParentWindow )
        {
            window->ActiveMenu->Window->State.MouseX =
                                       mouse_x - window->ActiveMenu->X;
            window->ActiveMenu->Window->State.MouseY =
                                       mouse_y - window->ActiveMenu->Y;
        }

        /* In the menu, invoke the callback and deactivate the menu */
        if( fghCheckMenuStatus( window->ActiveMenu ) )
        {
            /*
             * Save the current window and menu and set the current
             * window to the window whose menu this is
             */
            SFG_Window *save_window = fgStructure.CurrentWindow;
            SFG_Menu *save_menu = fgStructure.CurrentMenu;
            SFG_Window *parent_window = window->ActiveMenu->ParentWindow;
            fgSetWindow( parent_window );
            fgStructure.CurrentMenu = window->ActiveMenu;

            /* Execute the menu callback */
            fghExecuteMenuCallback( window->ActiveMenu );
            fgDeactivateMenu( parent_window );

            /* Restore the current window and menu */
            fgSetWindow( save_window );
            fgStructure.CurrentMenu = save_menu;
        }
        else if( pressed )
            /*
             * Outside the menu, deactivate if it's a downclick
             *
             * XXX This isn't enough.  A downclick outside of
             * XXX the interior of our freeglut windows should also
             * XXX deactivate the menu.  This is more complicated.
             */
            fgDeactivateMenu( window->ActiveMenu->ParentWindow );

        /*
         * XXX Why does an active menu require a redisplay at
         * XXX this point?  If this can come out cleanly, then
         * XXX it probably should do so; if not, a comment should
         * XXX explain it.
         */
        if( ! window->IsMenu )
            window->State.Redisplay = GL_TRUE;

        return GL_TRUE;
    }

    /* No active menu, let's check whether we need to activate one. */
    if( ( 0 <= button ) &&
        ( FREEGLUT_MAX_MENUS > button ) &&
        ( window->Menu[ button ] ) &&
        pressed )
    {
        /* XXX Posting a requisite Redisplay seems bogus. */
        window->State.Redisplay = GL_TRUE;
        fghActivateMenu( window, button );
        return GL_TRUE;
    }

    return GL_FALSE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rdi, %rbx
movq 0x150(%rdi), %rdi
testq %rdi, %rdi
je 0xd3298
cmpq %rbx, 0x68(%rdi)
jne 0xd323c
subl 0x4c(%rdi), %ecx
movq 0x60(%rdi), %rax
movl %ecx, 0x60(%rax)
subl 0x50(%rdi), %r8d
movl %r8d, 0x64(%rax)
callq 0xd2f2d
testb %al, %al
je 0xd33f5
leaq 0x75620(%rip), %r12     # 0x148870
movq 0x30(%r12), %r14
movq 0x38(%r12), %r13
movq 0x150(%rbx), %rax
movq 0x68(%rax), %r15
movq %r15, %rdi
callq 0xd5037
movq 0x150(%rbx), %rdi
movq %rdi, 0x38(%r12)
callq 0xd3428
movq %r15, %rdi
callq 0xd3473
movq %r14, %rdi
callq 0xd5037
movq %r13, 0x38(%r12)
jmp 0xd340a
cmpl $0x2, %esi
ja 0xd33f1
movl %esi, %eax
movq 0x138(%rbx,%rax,8), %r14
testq %r14, %r14
sete %al
testb %bpl, %bpl
sete %cl
orb %al, %cl
jne 0xd33f1
movb $0x1, 0x48(%rbx)
leaq 0x755a6(%rip), %rax     # 0x148870
movq 0x68(%r14), %rcx
testq %rcx, %rcx
je 0xd32de
movq $0x0, 0x150(%rcx)
movq 0x30(%rax), %r15
movq %r14, 0x150(%rbx)
movb $0x1, 0x40(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd3501
leaq 0x70ec0(%rip), %rax     # 0x1441c0
incl 0x70(%rax)
movq 0x68(%r14), %rdi
leaq 0x4(%rsp), %r12
movq %rsp, %rdx
movq %r12, %rsi
callq 0xd3b4c
movq %rbx, %rdi
callq 0xd5037
movl 0x60(%rbx), %ebp
movl $0x64, %edi
callq 0xd3cc4
addl %ebp, %eax
movl %eax, 0x4c(%r14)
movl 0x64(%rbx), %ebp
movl $0x65, %edi
callq 0xd3cc4
addl %ebp, %eax
movl %eax, 0x50(%r14)
movl 0x44(%r14), %edx
movl 0x4c(%r14), %ecx
leal (%rdx,%rcx), %esi
cmpl (%r12), %esi
jle 0xd335c
subl %edx, %ecx
movl %ecx, 0x4c(%r14)
movl 0x48(%r14), %ecx
leal (%rcx,%rax), %edx
cmpl (%rsp), %edx
jle 0xd3375
subl %ecx, %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovgl %eax, %ecx
movl %ecx, 0x50(%r14)
movl 0x60(%rbx), %ebp
movl $0x64, %edi
callq 0xd3cc4
addl %ebp, %eax
subl 0x4c(%r14), %eax
movq 0x60(%r14), %rcx
movl %eax, 0x60(%rcx)
movl 0x64(%rbx), %ebx
movl $0x65, %edi
callq 0xd3cc4
addl %ebx, %eax
subl 0x50(%r14), %eax
movq 0x60(%r14), %rdi
movl %eax, 0x64(%rdi)
callq 0xd5037
movl 0x4c(%r14), %edi
movl 0x50(%r14), %esi
callq 0xd5c18
movl 0x44(%r14), %edi
movl 0x48(%r14), %esi
callq 0xd5b4c
callq 0xd5d06
callq 0xd5876
movq 0x60(%r14), %rax
movq %r14, 0x150(%rax)
movq %r14, %rdi
callq 0xd2f2d
movq %r15, %rdi
callq 0xd5037
movb $0x1, %al
jmp 0xd3419
xorl %eax, %eax
jmp 0xd3419
testb %bpl, %bpl
je 0xd340a
movq 0x150(%rbx), %rax
movq 0x68(%rax), %rdi
callq 0xd3473
movb $0x1, %al
cmpb $0x0, 0x170(%rbx)
jne 0xd3419
movb $0x1, 0x48(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq