// File: /workspace/github_c_makefile_star2_O1/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 0x42d5
xorl %eax, %eax
callq 0x343f
movq %rax, %rbx
xorl %eax, %eax
callq 0x4420
leaq 0x2a7f(%rip), %rdi      # 0x5049
callq 0x4337
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 0x2648
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       # 0x252c
callq 0x21e0
movq (%r14,%r13), %rax
movq (%rax), %rdi
callq 0x4337
movq %rax, -0x8(%r12)
movq %rdx, (%r12)
incq %rbp
movslq 0x8(%rbx), %rax
addq $0x10, %r12
addq $0x58, %r13
cmpq %rax, %rbp
jl 0x2607
movq %rbx, %rdi
callq 0x3049
cmpl $0x0, 0x8(%rbx)
jle 0x27e0
xorl %ebp, %ebp
movq 0x8(%rsp), %r14
xorl %r15d, %r15d
movq (%rbx), %r12
cmpb $0x0, 0x50(%r12,%rbp)
jne 0x27c8
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 0x300c
movl 0x8(%r12,%rbp), %edx
movl 0xc(%r12,%rbp), %ecx
xorl %edi, %edi
xorl %esi, %esi
callq 0x23b0
xorl %eax, %eax
callq 0x42d5
mulss 0x294e(%rip), %xmm0     # 0x5008
cvtss2sd %xmm0, %xmm0
callq 0x2400
movsd 0x294d(%rip), %xmm1     # 0x5018
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
movsd 0x2945(%rip), %xmm1     # 0x5020
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rsp)
xorl %eax, %eax
callq 0x42d5
mulss 0x2915(%rip), %xmm0     # 0x500c
cvtss2sd %xmm0, %xmm0
callq 0x2400
movsd 0x2910(%rip), %xmm1     # 0x5018
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
mulsd 0x2908(%rip), %xmm0     # 0x5020
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x4(%rsp)
xorl %eax, %eax
callq 0x42d5
mulss 0x28df(%rip), %xmm0     # 0x5010
cvtss2sd %xmm0, %xmm0
callq 0x2400
movsd 0x28d6(%rip), %xmm1     # 0x5018
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
mulsd 0x28ce(%rip), %xmm0     # 0x5020
cvtsd2ss %xmm0, %xmm2
movss (%rsp), %xmm0
movss 0x4(%rsp), %xmm1
movss 0x28ab(%rip), %xmm3     # 0x5014
callq 0x2180
movl $0x4000, %edi           # imm = 0x4000
callq 0x20c0
xorl %eax, %eax
callq 0x42d5
movss %xmm0, (%rsp)
movq 0x20(%r12,%rbp), %rsi
movq 0x30(%r12,%rbp), %rdi
callq 0x2270
xorl %eax, %eax
callq 0x42d5
subss (%rsp), %xmm0
mulss 0x285d(%rip), %xmm0     # 0x5004
cvtss2sd %xmm0, %xmm0
leaq 0x2876(%rip), %rdi      # 0x5028
leaq 0x289a(%rip), %rsi      # 0x5053
movb $0x1, %al
callq 0x2050
movq %r14, %rdi
callq 0x4362
incq %r15
movslq 0x8(%rbx), %rax
addq $0x10, %r14
addq $0x58, %rbp
cmpq %rax, %r15
jl 0x2664
leaq 0x287b(%rip), %rdi      # 0x5062
callq 0x43ae
leaq 0x10(%rsp), %rdi
callq 0x4362
jmp 0x2648
nop