// File: /workspace/github_c_makefile_star2_O2/lukexi[P]eglstreams-mini/src/egl.c
// Function: GetEglDisplay
EGLDisplay GetEglDisplay(EGLDeviceEXT device, int drmFd)
{
    EGLDisplay eglDpy;

    const char *clientExtensionString =
        eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);

    const char *deviceExtensionString =
        pEglQueryDeviceStringEXT(device, EGL_EXTENSIONS);

    /*
     * Provide the DRM fd when creating the EGLDisplay, so that the
     * EGL implementation can make any necessary DRM calls using the
     * same fd as the application.
     */
    EGLint attribs[] = {
        EGL_DRM_MASTER_FD_EXT,
        drmFd,
        EGL_NONE
    };

    /*
     * eglGetPlatformDisplayEXT requires EGL client extension
     * EGL_EXT_platform_base.
     */
    if (!ExtensionIsSupported(clientExtensionString, "EGL_EXT_platform_base")) {
        Fatal("EGL_EXT_platform_base not found.\n");
    }

    /*
     * EGL_EXT_platform_device is required to pass
     * EGL_PLATFORM_DEVICE_EXT to eglGetPlatformDisplayEXT().
     */

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

    /*
     * Providing a DRM fd during EGLDisplay creation requires
     * EGL_EXT_device_drm.
     */
    if (!ExtensionIsSupported(deviceExtensionString, "EGL_EXT_device_drm")) {
        Fatal("EGL_EXT_device_drm not found.\n");
    }

    /* Get an EGLDisplay from the EGLDeviceEXT. */
    eglDpy = pEglGetPlatformDisplayEXT(EGL_PLATFORM_DEVICE_EXT,
                                       (void*)device, attribs);

    if (eglDpy == EGL_NO_DISPLAY) {
        Fatal("Failed to get EGLDisplay from EGLDevice.");
    }

    if (!eglInitialize(eglDpy, NULL, NULL)) {
        Fatal("Failed to initialize EGLDisplay.");
    }

    return eglDpy;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebp
movq %rdi, %rbx
xorl %edi, %edi
movl $0x3055, %esi           # imm = 0x3055
callq 0x21f0
movq %rax, %r15
movq %rbx, %rdi
movl $0x3055, %esi           # imm = 0x3055
callq *0x549c(%rip)           # 0x8238
movq %rax, %r14
movl $0x333c, 0xc(%rsp)      # imm = 0x333C
movl %ebp, 0x10(%rsp)
movl $0x3038, 0x14(%rsp)     # imm = 0x3038
leaq 0x258f(%rip), %rsi      # 0x5349
movq %r15, %rdi
callq 0x29e0
testl %eax, %eax
jne 0x2dd4
leaq 0x2592(%rip), %rdi      # 0x535f
xorl %eax, %eax
callq 0x40d8
leaq 0x25a6(%rip), %rsi      # 0x5381
movq %r15, %rdi
callq 0x29e0
testl %eax, %eax
jne 0x2df5
leaq 0x25ab(%rip), %rdi      # 0x5399
xorl %eax, %eax
callq 0x40d8
leaq 0x2484(%rip), %rsi      # 0x5280
movq %r14, %rdi
callq 0x29e0
testl %eax, %eax
jne 0x2e16
leaq 0x25ae(%rip), %rdi      # 0x53bd
xorl %eax, %eax
callq 0x40d8
leaq 0xc(%rsp), %rdx
movl $0x313f, %edi           # imm = 0x313F
movq %rbx, %rsi
callq *0x5417(%rip)           # 0x8240
movq %rax, %rbx
testq %rax, %rax
jne 0x2e3f
leaq 0x25a4(%rip), %rdi      # 0x53dc
xorl %eax, %eax
callq 0x40d8
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2160
testl %eax, %eax
jne 0x2e5d
leaq 0x25af(%rip), %rdi      # 0x5405
xorl %eax, %eax
callq 0x40d8
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq