// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
movb $0x0, %al
callq 0x4e00
movb $0x0, %al
callq 0x3ae0
movq %rax, -0x10(%rbp)
movb $0x0, %al
callq 0x5030
leaq 0x3a6f(%rip), %rdi      # 0x6051
callq 0x4e80
movq %rax, -0x20(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movslq 0x8(%rax), %rdi
movl $0x10, %esi
callq 0x2350
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x2694
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
leaq -0x40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x121(%rip), %rdx      # 0x2520
callq 0x21c0
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdi
callq 0x4e80
movq %rax, %rcx
movq -0x70(%rbp), %rax
movq %rcx, -0x50(%rbp)
movq %rdx, -0x48(%rbp)
movq -0x50(%rbp), %rcx
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x260c
jmp 0x2696
movq -0x10(%rbp), %rdi
callq 0x3450
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x2890
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
testb $0x1, 0x50(%rax)
je 0x26db
jmp 0x2882
movq -0x60(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x60(%rbp), %rax
movq 0x28(%rax), %rcx
callq 0x2190
movq -0x60(%rbp), %rdi
movb $0x0, %al
callq 0x3400
movq -0x60(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x60(%rbp), %rax
movl 0xc(%rax), %ecx
xorl %esi, %esi
movl %esi, %edi
callq 0x2390
movb $0x0, %al
callq 0x4e00
movss 0x38e3(%rip), %xmm1     # 0x6014
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x23f0
movsd 0x38e2(%rip), %xmm1     # 0x6028
divsd %xmm1, %xmm0
movsd 0x38ce(%rip), %xmm1     # 0x6020
addsd %xmm1, %xmm0
movsd 0x38ba(%rip), %xmm1     # 0x6018
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x74(%rbp)
movb $0x0, %al
callq 0x4e00
movss 0x3896(%rip), %xmm1     # 0x6010
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x23f0
movsd 0x3899(%rip), %xmm1     # 0x6028
divsd %xmm1, %xmm0
movsd 0x3885(%rip), %xmm1     # 0x6020
addsd %xmm1, %xmm0
movsd 0x3871(%rip), %xmm1     # 0x6018
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x78(%rbp)
movb $0x0, %al
callq 0x4e00
movss 0x3849(%rip), %xmm1     # 0x600c
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x23f0
movss -0x78(%rbp), %xmm1
movaps %xmm0, %xmm2
movss -0x74(%rbp), %xmm0
movsd 0x3843(%rip), %xmm3     # 0x6028
divsd %xmm3, %xmm2
movsd 0x382f(%rip), %xmm3     # 0x6020
addsd %xmm3, %xmm2
movsd 0x381b(%rip), %xmm3     # 0x6018
mulsd %xmm3, %xmm2
cvtsd2ss %xmm2, %xmm2
movss 0x37fb(%rip), %xmm3     # 0x6008
callq 0x2160
movl $0x4000, %edi           # imm = 0x4000
callq 0x20b0
movb $0x0, %al
callq 0x4e00
movss %xmm0, -0x64(%rbp)
movq -0x60(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x2250
movb $0x0, %al
callq 0x4e00
subss -0x64(%rbp), %xmm0
movss 0x37b3(%rip), %xmm1     # 0x6004
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x37d0(%rip), %rdi      # 0x6030
leaq 0x37f4(%rip), %rsi      # 0x605b
movb $0x1, %al
callq 0x2050
movq -0x28(%rbp), %rdi
movslq -0x54(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
callq 0x4ec0
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x26a6
leaq 0x37d3(%rip), %rdi      # 0x606a
callq 0x4f30
leaq -0x20(%rbp), %rdi
callq 0x4ec0
jmp 0x2696
nopw (%rax,%rax)