// File: /workspace/github_c_makefile_star2_O3/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 0x2e29(%rip), %xmm0     # 0x5cfc
movups %xmm0, 0x3c(%rsp)
movaps 0x2e11(%rip), %xmm0     # 0x5cf0
movaps %xmm0, 0x30(%rsp)
movaps 0x2df5(%rip), %xmm0     # 0x5ce0
movaps %xmm0, 0x20(%rsp)
movaps 0x2dd9(%rip), %xmm0     # 0x5cd0
movaps %xmm0, 0x10(%rsp)
movl $0x3055, %esi           # imm = 0x3055
callq 0x21f0
movq %rax, %r14
leaq 0x2516(%rip), %rsi      # 0x5426
movq %rax, %rdi
callq 0x2a1c
testl %eax, %eax
jne 0x2f2a
leaq 0x2517(%rip), %rdi      # 0x543a
xorl %eax, %eax
callq 0x4184
leaq 0x2529(%rip), %rsi      # 0x545a
movq %r14, %rdi
callq 0x2a1c
testl %eax, %eax
jne 0x2f4b
leaq 0x2529(%rip), %rdi      # 0x546d
xorl %eax, %eax
callq 0x4184
leaq 0x253a(%rip), %rsi      # 0x548c
movq %r14, %rdi
callq 0x2a1c
testl %eax, %eax
jne 0x2f6c
leaq 0x2536(%rip), %rdi      # 0x549b
xorl %eax, %eax
callq 0x4184
leaq 0x2543(%rip), %rsi      # 0x54b6
movq %r14, %rdi
callq 0x2a1c
testl %eax, %eax
jne 0x2f8d
leaq 0x2552(%rip), %rdi      # 0x54d8
xorl %eax, %eax
callq 0x4184
leaq 0x2572(%rip), %rsi      # 0x5506
movq %r14, %rdi
callq 0x2a1c
testl %eax, %eax
jne 0x2fae
leaq 0x2582(%rip), %rdi      # 0x5529
xorl %eax, %eax
callq 0x4184
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 0x2fe6
cmpl $0x0, 0x4(%rsp)
jne 0x2ff4
leaq 0x256b(%rip), %rdi      # 0x5558
xorl %eax, %eax
callq 0x4184
movq 0x8(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r14
retq