// File: /workspace/github_cpp_makefile_star2_O1/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, 0x74104(%rip)     # 0x1441dc
je 0xd00e8
leaq 0x2bce0(%rip), %rdi     # 0xfbdc1
xorl %eax, %eax
callq 0xd1cf7
testq %r14, %r14
je 0xd011f
cmpl $0x0, (%r15)
je 0xd011f
movq (%r14), %rdi
testq %rdi, %rdi
je 0xd011f
cmpb $0x0, (%rdi)
je 0xd011f
callq 0x22170
movq %rax, 0x7415c(%rip)     # 0x144268
testq %rax, %rax
jne 0xd011f
leaq 0x2bcd5(%rip), %rdi     # 0xfbded
xorl %eax, %eax
callq 0xd1cf7
callq 0xd4b47
callq 0xd1c70
movq %rax, 0x740d0(%rip)     # 0x144200
leaq 0x2bce7(%rip), %rdi     # 0xfbe1e
callq 0x21b20
testq %rax, %rax
je 0xd016c
leaq 0x12b72(%rip), %rsi     # 0xe2cba
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, 0x74084(%rip)     # 0x1441f0
leaq 0x2bcb4(%rip), %rdi     # 0xfbe27
callq 0x21b20
movq %rax, 0x10(%rsp)
cmpl $0x2, %ebp
jl 0xd031f
movl $0x1, %r12d
movq $0x0, 0x8(%rsp)
movslq %r12d, %rax
leaq (%r14,%rax,8), %r13
movq (%r13), %rbx
movq %rbx, %rdi
leaq 0x2bc85(%rip), %rsi     # 0xfbe2f
callq 0x21d10
testl %eax, %eax
je 0xd024d
movq %rbx, %rdi
leaq 0x2bcab(%rip), %rsi     # 0xfbe6c
callq 0x21d10
testl %eax, %eax
je 0xd0274
movq %rbx, %rdi
leaq 0x2bcdf(%rip), %rsi     # 0xfbeb7
callq 0x21d10
testl %eax, %eax
je 0xd02ab
movq %rbx, %rdi
leaq 0x2bd15(%rip), %rsi     # 0xfbf04
callq 0x21d10
testl %eax, %eax
je 0xd02ce
movq %rbx, %rdi
leaq 0x2bd08(%rip), %rsi     # 0xfbf0e
callq 0x21d10
testl %eax, %eax
je 0xd02f1
movq %rbx, %rdi
leaq 0x2bcf9(%rip), %rsi     # 0xfbf16
callq 0x21d10
testl %eax, %eax
je 0xd02fa
movq %rbx, %rdi
leaq 0x2bceb(%rip), %rsi     # 0xfbf1f
callq 0x21d10
testl %eax, %eax
jne 0xd0311
movb $0x1, 0x73f9f(%rip)     # 0x1441e7
jmp 0xd0301
incl %r12d
cmpl %ebp, %r12d
jl 0xd0263
leaq 0x2bbdc(%rip), %rdi     # 0xfbe38
xorl %eax, %eax
callq 0xd1cf7
movslq %r12d, %rax
leaq (%r14,%rax,8), %rcx
movq (%rcx), %rax
movq %rax, 0x10(%rsp)
jmp 0xd0299
incl %r12d
cmpl %ebp, %r12d
jl 0xd028a
leaq 0x2bbf3(%rip), %rdi     # 0xfbe76
xorl %eax, %eax
callq 0xd1cf7
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 0xd0306
cmpl $0x0, 0x73f2e(%rip)     # 0x1441e0
jne 0xd02c2
leaq 0x2bc04(%rip), %rdi     # 0xfbebf
xorl %eax, %eax
callq 0xd1cf7
movl $0x3, 0x73f14(%rip)     # 0x1441e0
jmp 0xd0301
cmpl $0x3, 0x73f0b(%rip)     # 0x1441e0
jne 0xd02e5
leaq 0x2bbe1(%rip), %rdi     # 0xfbebf
xorl %eax, %eax
callq 0xd1cf7
movl $0x0, 0x73ef1(%rip)     # 0x1441e0
jmp 0xd0301
movb $0x1, 0x73eec(%rip)     # 0x1441e4
jmp 0xd0301
movb $0x1, 0x73ee5(%rip)     # 0x1441e6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq $0x0, (%r13)
addl %eax, (%r15)
incl %r12d
cmpl %ebp, %r12d
jl 0xd0195
jmp 0xd0328
movq $0x0, 0x8(%rsp)
movslq (%r15), %rax
cmpq $0x2, %rax
jl 0xd035e
movl $0x1, %ecx
movl $0x1, %edx
movslq %edx, %rdx
movq (%r14,%rdx,8), %rsi
incq %rdx
testq %rsi, %rsi
je 0xd033e
leal -0x1(%rdx), %edi
cmpq %rdi, %rcx
je 0xd0356
movq %rsi, (%r14,%rcx,8)
incq %rcx
cmpq %rax, %rcx
jne 0xd033b
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x21ce0
movq %rax, 0x7845e(%rip)     # 0x1487d0
testq %rax, %rax
jne 0xd0390
movq %rbx, %rdi
callq 0x21f30
leaq 0x2bc34(%rip), %rdi     # 0xfbfba
movq %rax, %rsi
xorl %eax, %eax
callq 0xd1cf7
movq 0x78439(%rip), %rdi     # 0x1487d0
xorl %esi, %esi
xorl %edx, %edx
callq 0x21f50
testl %eax, %eax
jne 0xd03bd
movq %rbx, %rdi
callq 0x21f30
leaq 0x2bc23(%rip), %rdi     # 0xfbfd6
movq %rax, %rsi
xorl %eax, %eax
callq 0xd1cf7
movq 0x7840c(%rip), %rdi     # 0x1487d0
movslq 0xe0(%rdi), %rax
movl %eax, 0x78407(%rip)     # 0x1487d8
movq 0xe8(%rdi), %rcx
shlq $0x7, %rax
movq 0x10(%rcx,%rax), %rdx
movq %rdx, 0x783f8(%rip)     # 0x1487e0
movups 0x18(%rcx,%rax), %xmm0
movups %xmm0, 0x78414(%rip)    # 0x148808
movl 0x10(%rdi), %eax
movl %eax, 0x783eb(%rip)     # 0x1487e8
leaq 0x2bc05(%rip), %rsi     # 0xfc009
xorl %edx, %edx
callq 0x21680
movq %rax, 0x783de(%rip)     # 0x1487f0
xorps %xmm0, %xmm0
movups %xmm0, 0x783dc(%rip)    # 0x1487f8
movq 0x783ad(%rip), %rdi     # 0x1487d0
leaq 0x2bc26(%rip), %rsi     # 0xfc050
xorl %edx, %edx
callq 0x21680
movq %rax, %r14
movl $0x8, %edi
callq 0x21c70
movq %rax, %rbx
movq 0x78398(%rip), %rdi     # 0x1487e0
movl $0x21, %edx
movq %r14, %rsi
movq %rax, %rcx
callq 0xcfe5b
cmpl $0x1, %eax
jne 0xd0553
movl $0x8, %edi
callq 0x21c70
movq %rax, %r15
movq (%rbx), %rax
movq (%rax), %rdi
movl $0x21, %edx
movq %r14, %rsi
movq %r15, %rcx
callq 0xcfe5b
cmpl $0x1, %eax
jne 0xd0543
movq (%rbx), %rax
movq (%rax), %r14
movq (%r15), %rdi
movq (%rdi), %r12
callq 0x21c00
movq %r15, %rdi
callq 0x21ae0
movq (%rbx), %rdi
callq 0x21c00
movq %rbx, %rdi
callq 0x21ae0
cmpq %r12, %r14
jne 0xd0563
movq 0x7830a(%rip), %rdi     # 0x1487d0
leaq 0x2bb4d(%rip), %rsi     # 0xfc01a
xorl %edx, %edx
callq 0x21680
movq %rax, %rbx
movq 0x782f2(%rip), %rdi     # 0x1487d0
leaq 0x2bb44(%rip), %rsi     # 0xfc029
xorl %edx, %edx
callq 0x21680
movq %rax, %r14
movq 0x782ea(%rip), %rdi     # 0x1487e0
movq %rbx, %rsi
movq %rax, %rdx
callq 0xcfdfc
testl %eax, %eax
je 0xd0563
movq 0x782c4(%rip), %rdi     # 0x1487d0
leaq 0x2bb24(%rip), %rsi     # 0xfc037
xorl %edx, %edx
callq 0x21680
movq %rax, %r15
movq %r14, 0x782d4(%rip)     # 0x1487f8
movq 0x782b5(%rip), %rdi     # 0x1487e0
movq %rbx, %rsi
movq %rax, %rdx
callq 0xcfdfc
testl %eax, %eax
je 0xd0563
movq %r15, 0x782bf(%rip)     # 0x148800
jmp 0xd0563
movq (%r15), %rdi
callq 0x21c00
movq %r15, %rdi
callq 0x21ae0
movq (%rbx), %rdi
callq 0x21c00
movq %rbx, %rdi
callq 0x21ae0
movb $0x1, 0x73c72(%rip)     # 0x1441dc
callq 0xd07e5
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xd05f4
xorl %eax, %eax
leaq 0x20(%rsp), %rbx
movl %eax, (%rbx)
leaq 0x1c(%rsp), %r14
movl %eax, (%r14)
leaq 0x73c2f(%rip), %rsi     # 0x1441c0
leaq 0x73c2c(%rip), %rdx     # 0x1441c4
movq %rbx, %rcx
movq %r14, %r8
callq 0x218f0
movl (%rbx), %esi
movl %esi, 0x73c21(%rip)     # 0x1441cc
movl (%r14), %edx
movl %edx, 0x73c1c(%rip)     # 0x1441d0
movl %eax, %ecx
notl %ecx
testb $0xc, %cl
jne 0xd05c4
movb $0x1, 0x73c10(%rip)     # 0x1441d4
testb $0x10, %al
je 0xd05d6
movl 0x7823a(%rip), %edi     # 0x148808
subl %esi, %edi
addl %edi, 0x73bea(%rip)     # 0x1441c0
testb $0x20, %al
je 0xd05e8
movl 0x7822c(%rip), %eax     # 0x14880c
subl %edx, %eax
addl %eax, 0x73bdc(%rip)     # 0x1441c4
testb $0x3, %cl
jne 0xd05f4
movb $0x1, 0x73bd4(%rip)     # 0x1441c8
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq