// File: /workspace/github_c_makefile_star2_O1/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 0x2e54(%rip), %xmm0     # 0x5cfc
movups %xmm0, 0x3c(%rsp)
movaps 0x2e3c(%rip), %xmm0     # 0x5cf0
movaps %xmm0, 0x30(%rsp)
movaps 0x2e20(%rip), %xmm0     # 0x5ce0
movaps %xmm0, 0x20(%rsp)
movaps 0x2e04(%rip), %xmm0     # 0x5cd0
movaps %xmm0, 0x10(%rsp)
movl $0x3055, %esi           # imm = 0x3055
callq 0x21f0
movq %rax, %r14
leaq 0x2541(%rip), %rsi      # 0x5426
movq %rax, %rdi
callq 0x29fc
testl %eax, %eax
jne 0x2eff
leaq 0x2542(%rip), %rdi      # 0x543a
xorl %eax, %eax
callq 0x41e8
leaq 0x2554(%rip), %rsi      # 0x545a
movq %r14, %rdi
callq 0x29fc
testl %eax, %eax
jne 0x2f20
leaq 0x2554(%rip), %rdi      # 0x546d
xorl %eax, %eax
callq 0x41e8
leaq 0x2565(%rip), %rsi      # 0x548c
movq %r14, %rdi
callq 0x29fc
testl %eax, %eax
jne 0x2f41
leaq 0x2561(%rip), %rdi      # 0x549b
xorl %eax, %eax
callq 0x41e8
leaq 0x256e(%rip), %rsi      # 0x54b6
movq %r14, %rdi
callq 0x29fc
testl %eax, %eax
jne 0x2f62
leaq 0x257d(%rip), %rdi      # 0x54d8
xorl %eax, %eax
callq 0x41e8
leaq 0x259d(%rip), %rsi      # 0x5506
movq %r14, %rdi
callq 0x29fc
testl %eax, %eax
jne 0x2f83
leaq 0x25ad(%rip), %rdi      # 0x5529
xorl %eax, %eax
callq 0x41e8
movl $0x30a2, %edi           # imm = 0x30A2
callq 0x23a0
leaq 0x4(%rsp), %r8
movl $0x0, (%r8)
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movl $0x1, %ecx
callq 0x2420
testl %eax, %eax
je 0x2fbb
cmpl $0x0, 0x4(%rsp)
jne 0x2fc9
leaq 0x2596(%rip), %rdi      # 0x5558
xorl %eax, %eax
callq 0x41e8
movq 0x8(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r14
retq