// File: /workspace/github_cpp_makefile_star2_O3/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, 0x73fba(%rip)     # 0x1421dc
movl %ebp, %eax
je 0xce237
leaq 0x2bbe4(%rip), %rdi     # 0xf9e11
xorl %eax, %eax
callq 0xcfe73
movl (%r15), %eax
testq %r14, %r14
je 0xce26c
testl %eax, %eax
je 0xce26c
movq (%r14), %rdi
testq %rdi, %rdi
je 0xce26c
cmpb $0x0, (%rdi)
je 0xce26c
callq 0x22160
movq %rax, 0x7400f(%rip)     # 0x142268
testq %rax, %rax
jne 0xce26c
leaq 0x2bbd8(%rip), %rdi     # 0xf9e3d
xorl %eax, %eax
callq 0xcfe73
callq 0xd2c55
callq 0xcfdec
movq %rax, 0x73f83(%rip)     # 0x142200
leaq 0x2bbea(%rip), %rdi     # 0xf9e6e
callq 0x21b10
testq %rax, %rax
je 0xce2b9
leaq 0x12a65(%rip), %rsi     # 0xe0cfa
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, 0x73f37(%rip)     # 0x1421f0
leaq 0x2bbb7(%rip), %rdi     # 0xf9e77
callq 0x21b10
movq %rax, 0x10(%rsp)
cmpl $0x2, %ebp
jl 0xce46c
movl $0x1, %r12d
movq $0x0, 0x8(%rsp)
movslq %r12d, %rax
leaq (%r14,%rax,8), %r13
movq (%r13), %rbx
movq %rbx, %rdi
leaq 0x2bb88(%rip), %rsi     # 0xf9e7f
callq 0x21d00
testl %eax, %eax
je 0xce39a
movq %rbx, %rdi
leaq 0x2bbae(%rip), %rsi     # 0xf9ebc
callq 0x21d00
testl %eax, %eax
je 0xce3c1
movq %rbx, %rdi
leaq 0x2bbe2(%rip), %rsi     # 0xf9f07
callq 0x21d00
testl %eax, %eax
je 0xce3f8
movq %rbx, %rdi
leaq 0x2bc18(%rip), %rsi     # 0xf9f54
callq 0x21d00
testl %eax, %eax
je 0xce41b
movq %rbx, %rdi
leaq 0x2bc0b(%rip), %rsi     # 0xf9f5e
callq 0x21d00
testl %eax, %eax
je 0xce43e
movq %rbx, %rdi
leaq 0x2bbfc(%rip), %rsi     # 0xf9f66
callq 0x21d00
testl %eax, %eax
je 0xce447
movq %rbx, %rdi
leaq 0x2bbee(%rip), %rsi     # 0xf9f6f
callq 0x21d00
testl %eax, %eax
jne 0xce45e
movb $0x1, 0x73e52(%rip)     # 0x1421e7
jmp 0xce44e
incl %r12d
cmpl %ebp, %r12d
jl 0xce3b0
leaq 0x2badf(%rip), %rdi     # 0xf9e88
xorl %eax, %eax
callq 0xcfe73
movslq %r12d, %rax
leaq (%r14,%rax,8), %rcx
movq (%rcx), %rax
movq %rax, 0x10(%rsp)
jmp 0xce3e6
incl %r12d
cmpl %ebp, %r12d
jl 0xce3d7
leaq 0x2baf6(%rip), %rdi     # 0xf9ec6
xorl %eax, %eax
callq 0xcfe73
movslq %r12d, %rax
leaq (%r14,%rax,8), %rcx
movq (%rcx), %rax
movq %rax, 0x8(%rsp)
movq $0x0, (%r13)
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
movq %rcx, %r13
jmp 0xce453
cmpl $0x0, 0x73de1(%rip)     # 0x1421e0
jne 0xce40f
leaq 0x2bb07(%rip), %rdi     # 0xf9f0f
xorl %eax, %eax
callq 0xcfe73
movl $0x3, 0x73dc7(%rip)     # 0x1421e0
jmp 0xce44e
cmpl $0x3, 0x73dbe(%rip)     # 0x1421e0
jne 0xce432
leaq 0x2bae4(%rip), %rdi     # 0xf9f0f
xorl %eax, %eax
callq 0xcfe73
movl $0x0, 0x73da4(%rip)     # 0x1421e0
jmp 0xce44e
movb $0x1, 0x73d9f(%rip)     # 0x1421e4
jmp 0xce44e
movb $0x1, 0x73d98(%rip)     # 0x1421e6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq $0x0, (%r13)
addl %eax, (%r15)
incl %r12d
cmpl %ebp, %r12d
jl 0xce2e2
jmp 0xce475
movq $0x0, 0x8(%rsp)
movslq (%r15), %rax
cmpq $0x2, %rax
jl 0xce4ab
movl $0x1, %ecx
movl $0x1, %edx
movslq %edx, %rdx
movq (%r14,%rdx,8), %rsi
incq %rdx
testq %rsi, %rsi
je 0xce48b
leal -0x1(%rdx), %edi
cmpq %rdi, %rcx
je 0xce4a3
movq %rsi, (%r14,%rcx,8)
incq %rcx
cmpq %rax, %rcx
jne 0xce488
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x21cd0
movq %rax, 0x78311(%rip)     # 0x1467d0
testq %rax, %rax
jne 0xce4e4
movq %rbx, %rdi
callq 0x21f20
leaq 0x2bb37(%rip), %rdi     # 0xfa00a
movq %rax, %rsi
xorl %eax, %eax
callq 0xcfe73
movq 0x782ec(%rip), %rax     # 0x1467d0
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21f40
testl %eax, %eax
jne 0xce50d
movq %rbx, %rdi
callq 0x21f20
leaq 0x2bb23(%rip), %rdi     # 0xfa026
movq %rax, %rsi
xorl %eax, %eax
callq 0xcfe73
movq 0x782bc(%rip), %rdi     # 0x1467d0
movslq 0xe0(%rdi), %rax
movl %eax, 0x782b7(%rip)     # 0x1467d8
movq 0xe8(%rdi), %rcx
shlq $0x7, %rax
movq 0x10(%rcx,%rax), %rdx
movq %rdx, 0x782a8(%rip)     # 0x1467e0
movups 0x18(%rcx,%rax), %xmm0
movups %xmm0, 0x782c4(%rip)    # 0x146808
movl 0x10(%rdi), %eax
movl %eax, 0x7829b(%rip)     # 0x1467e8
leaq 0x2bb05(%rip), %rsi     # 0xfa059
xorl %edx, %edx
callq 0x21680
movq %rax, 0x7828e(%rip)     # 0x1467f0
xorps %xmm0, %xmm0
movups %xmm0, 0x7828c(%rip)    # 0x1467f8
movq 0x7825d(%rip), %rdi     # 0x1467d0
leaq 0x2bb26(%rip), %rsi     # 0xfa0a0
xorl %edx, %edx
callq 0x21680
movq %rax, %r14
movl $0x8, %edi
callq 0x21c60
movq %rax, %rbx
movq 0x78248(%rip), %rdi     # 0x1467e0
movl $0x21, %edx
movq %r14, %rsi
movq %rax, %rcx
callq 0xcdf9f
cmpl $0x1, %eax
jne 0xce6a0
movl $0x8, %edi
callq 0x21c60
movq %rax, %r15
movq (%rbx), %rax
movq (%rax), %rdi
movl $0x21, %edx
movq %r14, %rsi
movq %r15, %rcx
callq 0xcdf9f
movq (%r15), %rdi
cmpl $0x1, %eax
jne 0xce693
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 0xce6b0
movq 0x781ba(%rip), %rdi     # 0x1467d0
leaq 0x2ba4d(%rip), %rsi     # 0xfa06a
xorl %edx, %edx
callq 0x21680
movq %rax, %rbx
movq 0x781a2(%rip), %rdi     # 0x1467d0
leaq 0x2ba44(%rip), %rsi     # 0xfa079
xorl %edx, %edx
callq 0x21680
movq %rax, %r14
movq 0x7819a(%rip), %rdi     # 0x1467e0
movq %rbx, %rsi
movq %rax, %rdx
callq 0xcdf40
testl %eax, %eax
je 0xce6b0
movq 0x78174(%rip), %rdi     # 0x1467d0
leaq 0x2ba24(%rip), %rsi     # 0xfa087
xorl %edx, %edx
callq 0x21680
movq %rax, %r15
movq %r14, 0x78184(%rip)     # 0x1467f8
movq 0x78165(%rip), %rdi     # 0x1467e0
movq %rbx, %rsi
movq %rax, %rdx
callq 0xcdf40
testl %eax, %eax
je 0xce6b0
movq %r15, 0x7816f(%rip)     # 0x146800
jmp 0xce6b0
callq 0x21bf0
movq %r15, %rdi
callq 0x21ad0
movq (%rbx), %rdi
callq 0x21bf0
movq %rbx, %rdi
callq 0x21ad0
movb $0x1, 0x73b25(%rip)     # 0x1421dc
callq 0xce91d
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xce741
xorl %eax, %eax
leaq 0x20(%rsp), %rbx
movl %eax, (%rbx)
leaq 0x1c(%rsp), %r14
movl %eax, (%r14)
leaq 0x73ae2(%rip), %rsi     # 0x1421c0
leaq 0x73adf(%rip), %rdx     # 0x1421c4
movq %rbx, %rcx
movq %r14, %r8
callq 0x218f0
movl (%rbx), %esi
movl %esi, 0x73ad4(%rip)     # 0x1421cc
movl (%r14), %edx
movl %edx, 0x73acf(%rip)     # 0x1421d0
movl %eax, %ecx
notl %ecx
testb $0xc, %cl
jne 0xce711
movb $0x1, 0x73ac3(%rip)     # 0x1421d4
testb $0x10, %al
je 0xce723
movl 0x780ed(%rip), %edi     # 0x146808
subl %esi, %edi
addl %edi, 0x73a9d(%rip)     # 0x1421c0
testb $0x20, %al
je 0xce735
movl 0x780df(%rip), %eax     # 0x14680c
subl %edx, %eax
addl %eax, 0x73a8f(%rip)     # 0x1421c4
testb $0x3, %cl
jne 0xce741
movb $0x1, 0x73a87(%rip)     # 0x1421c8
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq