// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
leaq 0x71ad5(%rip), %r12     # 0x1441c0
cmpb $0x0, 0x1c(%r12)
je 0xd285b
movl $0x1, 0xa0(%r12)
leaq 0x76166(%rip), %r13     # 0x148870
leaq 0x329(%rip), %rbx       # 0xd2a3a
movq %rsp, %r14
leaq 0x341(%rip), %r15       # 0xd2a5c
leaq 0x760ae(%rip), %rbp     # 0x1487d0
callq 0xd1def
movq %r13, %rdi
movq (%rdi), %rdi
testq %rdi, %rdi
je 0xd281d
cmpb $0x0, 0x170(%rdi)
jne 0xd272a
cmpq $0x0, 0x68(%r12)
je 0xd2763
movq 0x30(%r13), %rax
testq %rax, %rax
je 0xd275e
cmpb $0x0, 0x170(%rax)
je 0xd275e
callq 0xd5037
callq *0x68(%r12)
cmpq $0x0, 0x68(%r12)
jne 0xd2829
movb $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd4ba5
cmpq $0x0, 0x8(%rsp)
jne 0xd2829
cmpq $0x0, 0x48(%r12)
je 0xd27a5
movq %r14, %rdi
xorl %esi, %esi
callq 0x21fc0
movb $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0xd4ba5
movq (%rbp), %rdi
callq 0x217e0
testl %eax, %eax
jne 0xd2829
movq (%rbp), %rax
movl 0x10(%rax), %ecx
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
leal 0x3f(%rcx), %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
movl %eax, %edx
andl $-0x40, %edx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, (%rsp,%rax,8)
jmp 0xd2829
movl $0x2, 0xa0(%r12)
cmpl $0x1, 0xa0(%r12)
je 0xd2722
movl 0x9c(%r12), %ebx
callq 0xcfee7
testl %ebx, %ebx
je 0xd2870
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18d04(%rip), %rdi     # 0xeb566
leaq 0x29d9f(%rip), %rsi     # 0xfc608
xorl %eax, %eax
callq 0xd1cf7
xorl %edi, %edi
callq 0x21b10