// File: tomfunkhouser[P]gaps/pkgs/fglut/freeglut_display.c
// Function: glutSwapBuffers
void FGAPIENTRY glutSwapBuffers( void )
{
    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSwapBuffers" );
    FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSwapBuffers" );

    /*
     * "glXSwapBuffers" already performs an implicit call to "glFlush". What
     * about "SwapBuffers"?
     */
    glFlush( );
    if( ! fgStructure.CurrentWindow->Window.DoubleBuffered )
        return;

#if TARGET_HOST_POSIX_X11
    glXSwapBuffers( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
#elif TARGET_HOST_MS_WINDOWS
    SwapBuffers( fgStructure.CurrentWindow->Window.Device );
#endif

    /* GLUT_FPS env var support */
    if( fgState.FPSInterval )
    {
        GLint t = glutGet( GLUT_ELAPSED_TIME );
        fgState.SwapCount++;
        if( fgState.SwapTime == 0 )
            fgState.SwapTime = t;
        else if( t - fgState.SwapTime > fgState.FPSInterval )
        {
            float time = 0.001f * ( t - fgState.SwapTime );
            float fps = ( float )fgState.SwapCount / time;
            fprintf( stderr,
                     "freeglut: %d frames in %.2f seconds = %.2f FPS\n",
                     fgState.SwapCount, time, fps );
            fgState.SwapTime = t;
            fgState.SwapCount = 0;
        }
    }
}

// Assembly:
subq $0x18, %rsp
leaq 0x803a5(%rip), %rax     # 0x1fa390
cmpb $0x0, 0x1c(%rax)
jne 0x17a006
leaq 0x238da(%rip), %rdi     # 0x19d8d2
leaq 0x23c69(%rip), %rsi     # 0x19dc68
movb $0x0, %al
callq 0x17de70
leaq 0x85ed3(%rip), %rax     # 0x1ffee0
cmpq $0x0, 0x30(%rax)
jne 0x17a029
leaq 0x23c0f(%rip), %rdi     # 0x19dc2a
leaq 0x23c46(%rip), %rsi     # 0x19dc68
movb $0x0, %al
callq 0x17de70
callq 0x22f50
leaq 0x85eab(%rip), %rax     # 0x1ffee0
movq 0x30(%rax), %rax
cmpl $0x0, 0x30(%rax)
jne 0x17a044
jmp 0x17a167
leaq 0x85de5(%rip), %rax     # 0x1ffe30
movq (%rax), %rdi
leaq 0x85e8b(%rip), %rax     # 0x1ffee0
movq 0x30(%rax), %rax
movq 0x18(%rax), %rsi
callq 0x23350
leaq 0x80327(%rip), %rax     # 0x1fa390
cmpl $0x0, 0x30(%rax)
je 0x17a167
movl $0x2bc, %edi            # imm = 0x2BC
callq 0x181410
movl %eax, 0x14(%rsp)
leaq 0x80308(%rip), %rax     # 0x1fa390
movl 0x34(%rax), %ecx
addl $0x1, %ecx
leaq 0x802fb(%rip), %rax     # 0x1fa390
movl %ecx, 0x34(%rax)
leaq 0x802f1(%rip), %rax     # 0x1fa390
cmpl $0x0, 0x38(%rax)
jne 0x17a0b8
movl 0x14(%rsp), %ecx
leaq 0x802e0(%rip), %rax     # 0x1fa390
movl %ecx, 0x38(%rax)
jmp 0x17a165
movl 0x14(%rsp), %eax
leaq 0x802cd(%rip), %rcx     # 0x1fa390
subl 0x38(%rcx), %eax
leaq 0x802c3(%rip), %rcx     # 0x1fa390
cmpl 0x30(%rcx), %eax
jbe 0x17a163
movl 0x14(%rsp), %ecx
leaq 0x802af(%rip), %rax     # 0x1fa390
movl 0x38(%rax), %edx
subl %edx, %ecx
cvtsi2ss %rcx, %xmm0
movss 0x23b21(%rip), %xmm1    # 0x19dc14
mulss %xmm1, %xmm0
movss %xmm0, 0x10(%rsp)
movl 0x34(%rax), %eax
cvtsi2ss %rax, %xmm0
divss 0x10(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
movq 0x7aeb0(%rip), %rax     # 0x1f4fc8
movq (%rax), %rdi
leaq 0x8026e(%rip), %rax     # 0x1fa390
movl 0x34(%rax), %edx
movss 0x10(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0xc(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x23b38(%rip), %rsi     # 0x19dc78
movb $0x2, %al
callq 0x22f30
movl 0x14(%rsp), %ecx
leaq 0x8023e(%rip), %rax     # 0x1fa390
movl %ecx, 0x38(%rax)
leaq 0x80234(%rip), %rax     # 0x1fa390
movl $0x0, 0x34(%rax)
jmp 0x17a165
jmp 0x17a167
addq $0x18, %rsp
retq
nopl (%rax)