// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/fglut/freeglut_main.c
// Function: glutMainLoop
void FGAPIENTRY glutMainLoop( void )
{
    int action;

#if TARGET_HOST_MS_WINDOWS
    SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
#endif

    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoop" );

#if TARGET_HOST_MS_WINDOWS
    /*
     * Processing before the main loop:  If there is a window which is open and
     * which has a visibility callback, call it.  I know this is an ugly hack,
     * but I'm not sure what else to do about it.  Ideally we should leave
     * something uninitialized in the create window code and initialize it in
     * the main loop, and have that initialization create a "WM_ACTIVATE"
     * message.  Then we would put the visibility callback code in the
     * "case WM_ACTIVATE" block below.         - John Fay -- 10/24/02
     */
    while( window )
    {
        if ( FETCH_WCB( *window, Visibility ) )
        {
            SFG_Window *current_window = fgStructure.CurrentWindow ;

            INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
            fgSetWindow( current_window );
        }

        window = (SFG_Window *)window->Node.Next ;
    }
#endif

    fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
    while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
    {
        SFG_Window *window;

        glutMainLoopEvent( );
        /*
         * Step through the list of windows, seeing if there are any
         * that are not menus
         */
        for( window = ( SFG_Window * )fgStructure.Windows.First;
             window;
             window = ( SFG_Window * )window->Node.Next )
            if ( ! ( window->IsMenu ) )
                break;

        if( ! window )
            fgState.ExecState = GLUT_EXEC_STATE_STOP;
        else
        {
            if( fgState.IdleCallback )
            {
                if( fgStructure.CurrentWindow &&
                    fgStructure.CurrentWindow->IsMenu )
                    /* fail safe */
                    fgSetWindow( window );
                fgState.IdleCallback( );
            }

            fghSleepForEvents( );
        }
    }

    /*
     * When this loop terminates, destroy the display, state and structure
     * of a freeglut session, so that another glutInit() call can happen
     *
     * Save the "ActionOnWindowClose" because "fgDeinitialize" resets it.
     */
    action = fgState.ActionOnWindowClose;
    fgDeinitialize( );
    if( action == GLUT_ACTION_EXIT )
        exit( 0 );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x71960(%rip), %r12     # 0x1421c0
cmpb $0x0, 0x1c(%r12)
je 0xd0978
movl $0x1, 0xa0(%r12)
leaq 0x75ff1(%rip), %r13     # 0x146870
leaq 0x2c3(%rip), %rbx       # 0xd0b49
leaq 0x8(%rsp), %r14
leaq 0x2d9(%rip), %r15       # 0xd0b6b
leaq 0x75f37(%rip), %rbp     # 0x1467d0
callq 0xcff6b
movq %r13, %rdi
movq (%rdi), %rdi
testq %rdi, %rdi
je 0xd094c
cmpb $0x0, 0x170(%rdi)
jne 0xd08a1
movq 0x68(%r12), %rax
testq %rax, %rax
je 0xd08e6
movq 0x30(%r13), %rcx
testq %rcx, %rcx
je 0xd08dc
cmpb $0x0, 0x170(%rcx)
je 0xd08dc
callq 0xd314d
movq 0x68(%r12), %rax
callq *%rax
cmpq $0x0, 0x68(%r12)
jne 0xd093b
movb $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd2cb3
cmpq $0x0, 0x10(%rsp)
jne 0xd093b
cmpq $0x0, 0x48(%r12)
je 0xd0919
movq %r14, %rdi
xorl %esi, %esi
callq 0x21fb0
movb $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0xd2cb3
movq (%rbp), %rdi
callq 0x217e0
cmpl $0x1, 0xa0(%r12)
je 0xd0899
jmp 0xd0958
movl $0x2, 0xa0(%r12)
movl 0x9c(%r12), %ebx
callq 0xce031
testl %ebx, %ebx
je 0xd098d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18c37(%rip), %rdi     # 0xe95b6
leaq 0x29cd2(%rip), %rsi     # 0xfa658
xorl %eax, %eax
callq 0xcfe73
xorl %edi, %edi
callq 0x21b00