// File: /workspace/github_c_makefile_star2_O2/lukexi[P]eglstreams-mini/src/egl.c
// Function: GetEglConfig
EGLConfig GetEglConfig(EGLDisplay eglDpy) {
    EGLint configAttribs[] = {
        EGL_SURFACE_TYPE, EGL_STREAM_BIT_KHR,
        EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
        EGL_RED_SIZE, 1,
        EGL_GREEN_SIZE, 1,
        EGL_BLUE_SIZE, 1,
        EGL_ALPHA_SIZE, 0,
        EGL_DEPTH_SIZE, 1,
        EGL_NONE,
    };

    const char *extensionString = eglQueryString(eglDpy, EGL_EXTENSIONS);

    /*
     * EGL_EXT_output_base and EGL_EXT_output_drm are needed to find
     * the EGLOutputLayer for the DRM KMS plane.
     */

    if (!ExtensionIsSupported(extensionString, "EGL_EXT_output_base")) {
        Fatal("EGL_EXT_output_base not found.\n");
    }

    if (!ExtensionIsSupported(extensionString, "EGL_EXT_output_drm")) {
        Fatal("EGL_EXT_output_drm not found.\n");
    }

    /*
     * EGL_KHR_stream, EGL_EXT_stream_consumer_egloutput, and
     * EGL_KHR_stream_producer_eglsurface are needed to create an
     * EGLStream connecting an EGLSurface and an EGLOutputLayer.
     */

    if (!ExtensionIsSupported(extensionString, "EGL_KHR_stream")) {
        Fatal("EGL_KHR_stream not found.\n");
    }

    if (!ExtensionIsSupported(extensionString,
                              "EGL_EXT_stream_consumer_egloutput")) {
        Fatal("EGL_EXT_stream_consumer_egloutput not found.\n");
    }

    if (!ExtensionIsSupported(extensionString,
                              "EGL_KHR_stream_producer_eglsurface")) {
        Fatal("EGL_KHR_stream_producer_eglsurface not found.\n");
    }

    /* Bind full OpenGL as EGL's client API. */

    eglBindAPI(EGL_OPENGL_API);

    /* Find a suitable EGL config. */
    EGLint n = 0;
    EGLConfig eglConfig;
    EGLBoolean ret = eglChooseConfig(eglDpy, configAttribs, &eglConfig, 1, &n);

    if (!ret || !n) {
        Fatal("eglChooseConfig() failed.\n");
    }

    return eglConfig;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
movups 0x2e80(%rip), %xmm0     # 0x5cfc
movups %xmm0, 0x3c(%rsp)
movaps 0x2e68(%rip), %xmm0     # 0x5cf0
movaps %xmm0, 0x30(%rsp)
movaps 0x2e4c(%rip), %xmm0     # 0x5ce0
movaps %xmm0, 0x20(%rsp)
movaps 0x2e30(%rip), %xmm0     # 0x5cd0
movaps %xmm0, 0x10(%rsp)
movl $0x3055, %esi           # imm = 0x3055
callq 0x21f0
movq %rax, %r14
leaq 0x256d(%rip), %rsi      # 0x5426
movq %rax, %rdi
callq 0x29e0
testl %eax, %eax
jne 0x2ed3
leaq 0x256e(%rip), %rdi      # 0x543a
xorl %eax, %eax
callq 0x40d8
leaq 0x2580(%rip), %rsi      # 0x545a
movq %r14, %rdi
callq 0x29e0
testl %eax, %eax
jne 0x2ef4
leaq 0x2580(%rip), %rdi      # 0x546d
xorl %eax, %eax
callq 0x40d8
leaq 0x2591(%rip), %rsi      # 0x548c
movq %r14, %rdi
callq 0x29e0
testl %eax, %eax
jne 0x2f15
leaq 0x258d(%rip), %rdi      # 0x549b
xorl %eax, %eax
callq 0x40d8
leaq 0x259a(%rip), %rsi      # 0x54b6
movq %r14, %rdi
callq 0x29e0
testl %eax, %eax
jne 0x2f36
leaq 0x25a9(%rip), %rdi      # 0x54d8
xorl %eax, %eax
callq 0x40d8
leaq 0x25c9(%rip), %rsi      # 0x5506
movq %r14, %rdi
callq 0x29e0
testl %eax, %eax
jne 0x2f57
leaq 0x25d9(%rip), %rdi      # 0x5529
xorl %eax, %eax
callq 0x40d8
movl $0x30a2, %edi           # imm = 0x30A2
callq 0x23a0
leaq 0x4(%rsp), %r8
andl $0x0, (%r8)
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
pushq $0x1
popq %rcx
movq %rbx, %rdi
callq 0x2420
testl %eax, %eax
je 0x2f8a
cmpl $0x0, 0x4(%rsp)
jne 0x2f98
leaq 0x25c7(%rip), %rdi      # 0x5558
xorl %eax, %eax
callq 0x40d8
movq 0x8(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r14
retq