// File: /workspace/github_cpp_makefile_star2_O2/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 0x77a4c(%rip), %r12     # 0x1331e0
cmpb $0x0, 0x1c(%r12)
je 0xbb8ab
movl $0x1, 0xa0(%r12)
pushq $0x1
popq %rax
leaq 0x7c0da(%rip), %r13     # 0x137890
leaq 0x281(%rip), %rbx       # 0xbba3e
leaq 0x8(%rsp), %r14
leaq 0x297(%rip), %r15       # 0xbba60
leaq 0x7c020(%rip), %rbp     # 0x1377f0
cmpl $0x1, %eax
jne 0xbb88b
callq 0xbaf48
movq %r13, %rdi
movq (%rdi), %rdi
testq %rdi, %rdi
je 0xbb872
cmpb $0x0, 0x170(%rdi)
jne 0xbb7e1
movq 0x68(%r12), %rax
testq %rax, %rax
je 0xbb826
movq 0x30(%r13), %rcx
testq %rcx, %rcx
je 0xbb81c
cmpb $0x0, 0x170(%rcx)
je 0xbb81c
callq 0xbde17
movq 0x68(%r12), %rax
callq *%rax
cmpq $0x0, 0x68(%r12)
jne 0xbb87e
movb $0x0, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xbd9c1
cmpq $0x0, 0x10(%rsp)
jne 0xbb87e
cmpq $0x0, 0x48(%r12)
je 0xbb851
callq 0xbad60
movb $0x0, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0xbd9c1
movq (%rbp), %rdi
callq 0x217f0
jmp 0xbb87e
movl $0x2, 0xa0(%r12)
movl 0xa0(%r12), %eax
jmp 0xbb7d0
movl 0x9c(%r12), %ebx
callq 0xb91b8
testl %ebx, %ebx
je 0xbb8c0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x189b4(%rip), %rdi     # 0xd4266
leaq 0x29a17(%rip), %rsi     # 0xe52d0
xorl %eax, %eax
callq 0xbad73
xorl %edi, %edi
callq 0x21b00