// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/fglut/freeglut_init.c
// Function: glutInit
void FGAPIENTRY glutInit( int* pargc, char** argv )
{
    char* displayName = NULL;
    char* geometry = NULL;
    int i, j, argc = *pargc;

    /* will return true for VC8 (VC2005) and higher */
#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 )
    size_t sLen;
#if HAVE_ERRNO
    errno_t err;
#endif
#endif

    if( fgState.Initialised )
        fgError( "illegal glutInit() reinitialization attempt" );

    if (pargc && *pargc && argv && *argv && **argv)
    {
        fgState.ProgramName = strdup (*argv);

        if( !fgState.ProgramName )
            fgError ("Could not allocate space for the program's name.");
    }

    fgCreateStructure( );

    /* Get start time */
    fgState.Time = fgSystemTime();

    /* check if GLUT_FPS env var is set */
#ifndef _WIN32_WCE
    {
    /* will return true for VC8 (VC2005) and higher */
#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) && HAVE_ERRNO
        char* fps = NULL;
        err = _dupenv_s( &fps, &sLen, "GLUT_FPS" );
        if (err)
            fgError("Error getting GLUT_FPS environment variable"); 
#else
        const char *fps = getenv( "GLUT_FPS" );
#endif
        if( fps )
        {
            int interval;
            sscanf( fps, "%d", &interval );

            if( interval <= 0 )
                fgState.FPSInterval = 5000;  /* 5000 millisecond default */
            else
                fgState.FPSInterval = interval;
        }
    /* will return true for VC8 (VC2005) and higher */
#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) && HAVE_ERRNO
        free ( fps );  fps = NULL;  /* dupenv_s allocates a string that we must free */
#endif
    }

    /* will return true for VC8 (VC2005) and higher */
#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) && HAVE_ERRNO
    err = _dupenv_s( &displayName, &sLen, "DISPLAY" );
    if (err)
        fgError("Error getting DISPLAY environment variable");
#else
    displayName = getenv( "DISPLAY" );
#endif

    for( i = 1; i < argc; i++ )
    {
        if( strcmp( argv[ i ], "-display" ) == 0 )
        {
            if( ++i >= argc )
                fgError( "-display parameter must be followed by display name" );

            displayName = argv[ i ];

            argv[ i - 1 ] = NULL;
            argv[ i     ] = NULL;
            ( *pargc ) -= 2;
        }
        else if( strcmp( argv[ i ], "-geometry" ) == 0 )
        {
            if( ++i >= argc )
                fgError( "-geometry parameter must be followed by window "
                         "geometry settings" );

            geometry = argv[ i ];

            argv[ i - 1 ] = NULL;
            argv[ i     ] = NULL;
            ( *pargc ) -= 2;
        }
        else if( strcmp( argv[ i ], "-direct" ) == 0)
        {
            if( fgState.DirectContext == GLUT_FORCE_INDIRECT_CONTEXT )
                fgError( "parameters ambiguity, -direct and -indirect "
                    "cannot be both specified" );

            fgState.DirectContext = GLUT_FORCE_DIRECT_CONTEXT;
            argv[ i ] = NULL;
            ( *pargc )--;
        }
        else if( strcmp( argv[ i ], "-indirect" ) == 0 )
        {
            if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
                fgError( "parameters ambiguity, -direct and -indirect "
                    "cannot be both specified" );

            fgState.DirectContext = GLUT_FORCE_INDIRECT_CONTEXT;
            argv[ i ] = NULL;
            (*pargc)--;
        }
        else if( strcmp( argv[ i ], "-iconic" ) == 0 )
        {
            fgState.ForceIconic = GL_TRUE;
            argv[ i ] = NULL;
            ( *pargc )--;
        }
        else if( strcmp( argv[ i ], "-gldebug" ) == 0 )
        {
            fgState.GLDebugSwitch = GL_TRUE;
            argv[ i ] = NULL;
            ( *pargc )--;
        }
        else if( strcmp( argv[ i ], "-sync" ) == 0 )
        {
            fgState.XSyncSwitch = GL_TRUE;
            argv[ i ] = NULL;
            ( *pargc )--;
        }
    }

    /* Compact {argv}. */
    for( i = j = 1; i < *pargc; i++, j++ )
    {
        /* Guaranteed to end because there are "*pargc" arguments left */
        while ( argv[ j ] == NULL )
            j++;
        if ( i != j )
            argv[ i ] = argv[ j ];
    }

#endif /* _WIN32_WCE */

    /*
     * Have the display created now. If there wasn't a "-display"
     * in the program arguments, we will use the DISPLAY environment
     * variable for opening the X display (see code above):
     */
    fghInitialize( displayName );
    /* will return true for VC8 (VC2005) and higher */
#if TARGET_HOST_MS_WINDOWS && ( _MSC_VER >= 1400 ) && HAVE_ERRNO
    free ( displayName );  displayName = NULL;  /* dupenv_s allocates a string that we must free */
#endif

    /*
     * Geometry parsing deffered until here because we may need the screen
     * size.
     */

    if (geometry )
    {
        unsigned int parsedWidth = 0, parsedHeight = 0;
        int mask = XParseGeometry( geometry,
                                   &fgState.Position.X, &fgState.Position.Y,
                                   &parsedWidth, &parsedHeight );
        /* TODO: Check for overflow? */
        fgState.Size.X = parsedWidth;
        fgState.Size.Y = parsedHeight;

        if( (mask & (WidthValue|HeightValue)) == (WidthValue|HeightValue) )
            fgState.Size.Use = GL_TRUE;

        if( mask & XNegative )
            fgState.Position.X += fgDisplay.ScreenWidth - fgState.Size.X;

        if( mask & YNegative )
            fgState.Position.Y += fgDisplay.ScreenHeight - fgState.Size.Y;

        if( (mask & (XValue|YValue)) == (XValue|YValue) )
            fgState.Position.Use = GL_TRUE;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %r15
movl (%rdi), %ebp
cmpb $0x0, 0x79e72(%rip)     # 0x1331fc
movl %ebp, %eax
je 0xb939f
leaq 0x2b72c(%rip), %rdi     # 0xe4ac1
xorl %eax, %eax
callq 0xbad73
movl (%r15), %eax
testq %r14, %r14
je 0xb93d4
testl %eax, %eax
je 0xb93d4
movq (%r14), %rdi
testq %rdi, %rdi
je 0xb93d4
cmpb $0x0, (%rdi)
je 0xb93d4
callq 0x22180
movq %rax, 0x79ec7(%rip)     # 0x133288
testq %rax, %rax
jne 0xb93d4
leaq 0x2b720(%rip), %rdi     # 0xe4aed
xorl %eax, %eax
callq 0xbad73
callq 0xbd966
callq 0xbad30
movq %rax, 0x79e3b(%rip)     # 0x133220
leaq 0x2b732(%rip), %rdi     # 0xe4b1e
callq 0x21b10
testq %rax, %rax
je 0xb9421
leaq 0x1261d(%rip), %rsi     # 0xcba1a
leaq 0x24(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x21890
movl (%rbx), %eax
testl %eax, %eax
movl $0x1388, %ecx           # imm = 0x1388
cmovgl %eax, %ecx
movl %ecx, 0x79def(%rip)     # 0x133210
leaq 0x2b6ff(%rip), %rdi     # 0xe4b27
callq 0x21b10
movq %rax, 0x10(%rsp)
pushq $0x1
popq %r12
movq $0x0, 0x8(%rsp)
cmpl %ebp, %r12d
jge 0xb95be
movslq %r12d, %rax
leaq (%r14,%rax,8), %r13
movq (%r13), %rbx
movq %rbx, %rdi
leaq 0x2b6d2(%rip), %rsi     # 0xe4b2f
callq 0x21d30
testl %eax, %eax
je 0xb9500
movq %rbx, %rdi
leaq 0x2b6f8(%rip), %rsi     # 0xe4b6c
callq 0x21d30
testl %eax, %eax
je 0xb9527
movq %rbx, %rdi
leaq 0x2b72c(%rip), %rsi     # 0xe4bb7
callq 0x21d30
testl %eax, %eax
je 0xb9558
movq %rbx, %rdi
leaq 0x2b762(%rip), %rsi     # 0xe4c04
callq 0x21d30
testl %eax, %eax
je 0xb957b
movq %rbx, %rdi
leaq 0x2b755(%rip), %rsi     # 0xe4c0e
callq 0x21d30
testl %eax, %eax
je 0xb959b
movq %rbx, %rdi
leaq 0x2b746(%rip), %rsi     # 0xe4c16
callq 0x21d30
testl %eax, %eax
je 0xb95a4
movq %rbx, %rdi
leaq 0x2b738(%rip), %rsi     # 0xe4c1f
callq 0x21d30
testl %eax, %eax
jne 0xb95b6
movb $0x1, 0x79d0c(%rip)     # 0x133207
jmp 0xb95ab
incl %r12d
cmpl %ebp, %r12d
jl 0xb9516
leaq 0x2b629(%rip), %rdi     # 0xe4b38
xorl %eax, %eax
callq 0xbad73
movslq %r12d, %rax
leaq (%r14,%rax,8), %rax
movq (%rax), %rcx
movq %rcx, 0x10(%rsp)
jmp 0xb954c
incl %r12d
cmpl %ebp, %r12d
jl 0xb953d
leaq 0x2b640(%rip), %rdi     # 0xe4b76
xorl %eax, %eax
callq 0xbad73
movslq %r12d, %rax
leaq (%r14,%rax,8), %rax
movq (%rax), %rcx
movq %rcx, 0x8(%rsp)
andq $0x0, (%r13)
movq %rax, %r13
pushq $-0x2
jmp 0xb95ad
cmpl $0x0, 0x79ca1(%rip)     # 0x133200
jne 0xb956f
leaq 0x2b657(%rip), %rdi     # 0xe4bbf
xorl %eax, %eax
callq 0xbad73
movl $0x3, 0x79c87(%rip)     # 0x133200
jmp 0xb95ab
cmpl $0x3, 0x79c7e(%rip)     # 0x133200
jne 0xb9592
leaq 0x2b634(%rip), %rdi     # 0xe4bbf
xorl %eax, %eax
callq 0xbad73
andl $0x0, 0x79c67(%rip)     # 0x133200
jmp 0xb95ab
movb $0x1, 0x79c62(%rip)     # 0x133204
jmp 0xb95ab
movb $0x1, 0x79c5b(%rip)     # 0x133206
pushq $-0x1
popq %rax
andq $0x0, (%r13)
addl %eax, (%r15)
incl %r12d
jmp 0xb943f
movslq (%r15), %rax
pushq $0x1
popq %rcx
movq %rcx, %rdx
cmpq %rax, %rcx
jge 0xb95ec
movslq %edx, %rdx
movq (%r14,%rdx,8), %rsi
incq %rdx
testq %rsi, %rsi
je 0xb95cf
leal -0x1(%rdx), %edi
cmpq %rdi, %rcx
je 0xb95e7
movq %rsi, (%r14,%rcx,8)
incq %rcx
jmp 0xb95c7
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x21ce0
movq %rax, 0x7e1f0(%rip)     # 0x1377f0
testq %rax, %rax
jne 0xb9625
movq %rbx, %rdi
callq 0x21f30
leaq 0x2b6a6(%rip), %rdi     # 0xe4cba
movq %rax, %rsi
xorl %eax, %eax
callq 0xbad73
movq 0x7e1cb(%rip), %rax     # 0x1377f0
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21f60
testl %eax, %eax
jne 0xb964e
movq %rbx, %rdi
callq 0x21f30
leaq 0x2b692(%rip), %rdi     # 0xe4cd6
movq %rax, %rsi
xorl %eax, %eax
callq 0xbad73
movq 0x7e19b(%rip), %rax     # 0x1377f0
movslq 0xe0(%rax), %rcx
movl %ecx, 0x7e196(%rip)     # 0x1377f8
movq 0xe8(%rax), %rdx
shlq $0x7, %rcx
movq 0x10(%rdx,%rcx), %rsi
movq %rsi, 0x7e187(%rip)     # 0x137800
movups 0x18(%rdx,%rcx), %xmm0
movups %xmm0, 0x7e1a3(%rip)    # 0x137828
movl 0x10(%rax), %eax
movl %eax, 0x7e17a(%rip)     # 0x137808
leaq 0x2b674(%rip), %rdi     # 0xe4d09
callq 0xb9a27
movq %rax, 0x7e16f(%rip)     # 0x137810
xorps %xmm0, %xmm0
movups %xmm0, 0x7e16d(%rip)    # 0x137818
leaq 0x2b69e(%rip), %rdi     # 0xe4d50
callq 0xb9a27
movq %rax, %r14
pushq $0x8
popq %rdi
callq 0x21c70
movq %rax, %rbx
movq 0x7e134(%rip), %rdi     # 0x137800
pushq $0x21
popq %rdx
movq %r14, %rsi
movq %rax, %rcx
callq 0xb9126
cmpl $0x1, %eax
jne 0xb97b3
pushq $0x8
popq %rdi
callq 0x21c70
movq %rax, %r15
movq (%rbx), %rax
movq (%rax), %rdi
pushq $0x21
popq %rdx
movq %r14, %rsi
movq %r15, %rcx
callq 0xb9126
movq (%r15), %rdi
cmpl $0x1, %eax
jne 0xb97a6
movq (%rbx), %rax
movq (%rax), %r14
movq (%rdi), %r12
callq 0x21bf0
movq %r15, %rdi
callq 0x21ad0
movq (%rbx), %rdi
callq 0x21bf0
movq %rbx, %rdi
callq 0x21ad0
cmpq %r12, %r14
jne 0xb97c3
leaq 0x2b5d6(%rip), %rdi     # 0xe4d1a
callq 0xb9a27
movq %rax, %rbx
leaq 0x2b5d6(%rip), %rdi     # 0xe4d29
callq 0xb9a27
movq %rax, %r14
movq 0x7e09e(%rip), %rdi     # 0x137800
movq %rbx, %rsi
movq %rax, %rdx
callq 0xb90c8
testl %eax, %eax
je 0xb97c3
leaq 0x2b5bf(%rip), %rdi     # 0xe4d37
callq 0xb9a27
movq %rax, %r15
movq %r14, 0x7e091(%rip)     # 0x137818
movq 0x7e072(%rip), %rdi     # 0x137800
movq %rbx, %rsi
movq %rax, %rdx
callq 0xb90c8
testl %eax, %eax
je 0xb97c3
movq %r15, 0x7e07c(%rip)     # 0x137820
jmp 0xb97c3
callq 0x21bf0
movq %r15, %rdi
callq 0x21ad0
movq (%rbx), %rdi
callq 0x21bf0
movq %rbx, %rdi
callq 0x21ad0
movb $0x1, 0x79a32(%rip)     # 0x1331fc
callq 0xb9a61
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xb9854
leaq 0x20(%rsp), %rbx
andl $0x0, (%rbx)
leaq 0x1c(%rsp), %r14
andl $0x0, (%r14)
leaq 0x799ef(%rip), %rsi     # 0x1331e0
leaq 0x799ec(%rip), %rdx     # 0x1331e4
movq %rbx, %rcx
movq %r14, %r8
callq 0x21900
movl (%rbx), %esi
movl %esi, 0x799e1(%rip)     # 0x1331ec
movl (%r14), %edx
movl %edx, 0x799dc(%rip)     # 0x1331f0
movl %eax, %ecx
notl %ecx
testb $0xc, %cl
jne 0xb9824
movb $0x1, 0x799d0(%rip)     # 0x1331f4
testb $0x10, %al
je 0xb9836
movl 0x7dffa(%rip), %edi     # 0x137828
subl %esi, %edi
addl %edi, 0x799aa(%rip)     # 0x1331e0
testb $0x20, %al
je 0xb9848
movl 0x7dfec(%rip), %eax     # 0x13782c
subl %edx, %eax
addl %eax, 0x7999c(%rip)     # 0x1331e4
testb $0x3, %cl
jne 0xb9854
movb $0x1, 0x79994(%rip)     # 0x1331e8
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq