// File: /workspace/github_c_makefile_star2_O3/lukexi[P]eglstreams-mini/acquire-thread-per-display.c
// Function: main
int main() {
    GetTime();

    egl_state* EGL = SetupEGL();
    EnableGLDebug();



    fps MainLoopFPS = MakeFPS("Main Loop");
    fps* DisplayFPS = calloc(EGL->DisplaysCount, sizeof(fps));
    for (int DisplayIndex = 0; DisplayIndex < EGL->DisplaysCount; DisplayIndex++) {
        egl_display* Display = &EGL->Displays[DisplayIndex];

        pthread_t AcquireThread;
        pthread_create(&AcquireThread, NULL, AcquireThreadMain, Display);

        DisplayFPS[DisplayIndex] = MakeFPS(Display->EDID->MonitorName);
    }

    while (1) {

        EGLUpdateVSync(EGL);

        for (int DisplayIndex = 0; DisplayIndex < EGL->DisplaysCount; DisplayIndex++) {
            egl_display* Display = &EGL->Displays[DisplayIndex];

            if (Display->PageFlipPending) {
                continue;
            }

            eglMakeCurrent(Display->DisplayDevice,
                Display->Surface, Display->Surface,
                Display->Context);

            PrintDisplayLayerSwapInterval(Display);

            glViewport(0, 0,
                (GLint)Display->Width,
                (GLint)Display->Height);

            glClearColor(
                        (sin(GetTime()*3)/2+0.5) * 0.8,
                        (sin(GetTime()*5)/2+0.5) * 0.8,
                        (sin(GetTime()*7)/2+0.5) * 0.8,
                        1);
            glClear(GL_COLOR_BUFFER_BIT);

            NEWTIME(eglSwapBuffers);
            eglSwapBuffers(Display->DisplayDevice, Display->Surface);
            ENDTIME(eglSwapBuffers);

            TickFPS(&DisplayFPS[DisplayIndex]);
        }



        GLCheck("Display Thread");

        TickFPS(&MainLoopFPS);
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
xorl %eax, %eax
callq 0x4271
xorl %eax, %eax
callq 0x3482
movq %rax, %rbx
xorl %eax, %eax
callq 0x43bc
leaq 0x2a5f(%rip), %rdi      # 0x5049
callq 0x42d3
movq %rax, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movslq 0x8(%rbx), %r14
movl $0x10, %esi
movq %r14, %rdi
callq 0x2370
movq %rax, 0x8(%rsp)
testq %r14, %r14
jle 0x2668
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %r12
xorl %r13d, %r13d
leaq 0x20(%rsp), %r15
xorl %ebp, %ebp
movq (%rbx), %r14
leaq (%r14,%r13), %rcx
movq %r15, %rdi
xorl %esi, %esi
leaq -0xee(%rip), %rdx       # 0x254c
callq 0x21e0
movq (%r14,%r13), %rax
movq (%rax), %rdi
callq 0x42d3
movq %rax, -0x8(%r12)
movq %rdx, (%r12)
incq %rbp
movslq 0x8(%rbx), %rax
addq $0x10, %r12
addq $0x58, %r13
cmpq %rax, %rbp
jl 0x2627
movq %rbx, %rdi
callq 0x3074
movl 0x8(%rbx), %eax
testl %eax, %eax
jle 0x2803
xorl %ebp, %ebp
movq 0x8(%rsp), %r14
xorl %r15d, %r15d
movq (%rbx), %r12
cmpb $0x0, 0x50(%r12,%rbp)
jne 0x27ec
leaq (%r12,%rbp), %r13
movq 0x30(%r12,%rbp), %rdi
movq 0x20(%r12,%rbp), %rdx
movq 0x28(%r12,%rbp), %rcx
movq %rdx, %rsi
callq 0x21b0
movq %r13, %rdi
xorl %eax, %eax
callq 0x3037
movl 0x8(%r12,%rbp), %edx
movl 0xc(%r12,%rbp), %ecx
xorl %edi, %edi
xorl %esi, %esi
callq 0x23b0
xorl %eax, %eax
callq 0x4271
mulss 0x292d(%rip), %xmm0     # 0x5008
cvtss2sd %xmm0, %xmm0
callq 0x2400
movsd 0x292c(%rip), %xmm1     # 0x5018
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
movsd 0x2924(%rip), %xmm1     # 0x5020
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rsp)
xorl %eax, %eax
callq 0x4271
mulss 0x28f4(%rip), %xmm0     # 0x500c
cvtss2sd %xmm0, %xmm0
callq 0x2400
movsd 0x28ef(%rip), %xmm1     # 0x5018
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
mulsd 0x28e7(%rip), %xmm0     # 0x5020
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x4(%rsp)
xorl %eax, %eax
callq 0x4271
mulss 0x28be(%rip), %xmm0     # 0x5010
cvtss2sd %xmm0, %xmm0
callq 0x2400
movsd 0x28b5(%rip), %xmm1     # 0x5018
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
mulsd 0x28ad(%rip), %xmm0     # 0x5020
cvtsd2ss %xmm0, %xmm2
movss (%rsp), %xmm0
movss 0x4(%rsp), %xmm1
movss 0x288a(%rip), %xmm3     # 0x5014
callq 0x2180
movl $0x4000, %edi           # imm = 0x4000
callq 0x20c0
xorl %eax, %eax
callq 0x4271
movss %xmm0, (%rsp)
movq 0x20(%r12,%rbp), %rsi
movq 0x30(%r12,%rbp), %rdi
callq 0x2270
xorl %eax, %eax
callq 0x4271
subss (%rsp), %xmm0
mulss 0x283c(%rip), %xmm0     # 0x5004
cvtss2sd %xmm0, %xmm0
leaq 0x2855(%rip), %rdi      # 0x5028
leaq 0x2879(%rip), %rsi      # 0x5053
movb $0x1, %al
callq 0x2050
movq %r14, %rdi
callq 0x42fe
movl 0x8(%rbx), %eax
incq %r15
movslq %eax, %rcx
addq $0x10, %r14
addq $0x58, %rbp
cmpq %rcx, %r15
jl 0x2685
leaq 0x2858(%rip), %rdi      # 0x5062
callq 0x434a
leaq 0x10(%rsp), %rdi
callq 0x42fe
jmp 0x2668
nop