// File: /workspace/github_c_makefile_star2_O3/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 *0x5445(%rip)           # 0x8238
movq %rax, %r14
movl $0x333c, 0xc(%rsp)      # imm = 0x333C
movl %ebp, 0x10(%rsp)
movl $0x3038, 0x14(%rsp)     # imm = 0x3038
leaq 0x2538(%rip), %rsi      # 0x5349
movq %r15, %rdi
callq 0x2a1c
testl %eax, %eax
jne 0x2e2b
leaq 0x253b(%rip), %rdi      # 0x535f
xorl %eax, %eax
callq 0x4184
leaq 0x254f(%rip), %rsi      # 0x5381
movq %r15, %rdi
callq 0x2a1c
testl %eax, %eax
jne 0x2e4c
leaq 0x2554(%rip), %rdi      # 0x5399
xorl %eax, %eax
callq 0x4184
leaq 0x242d(%rip), %rsi      # 0x5280
movq %r14, %rdi
callq 0x2a1c
testl %eax, %eax
jne 0x2e6d
leaq 0x2557(%rip), %rdi      # 0x53bd
xorl %eax, %eax
callq 0x4184
leaq 0xc(%rsp), %rdx
movl $0x313f, %edi           # imm = 0x313F
movq %rbx, %rsi
callq *0x53c0(%rip)           # 0x8240
movq %rax, %rbx
testq %rax, %rax
jne 0x2e96
leaq 0x254d(%rip), %rdi      # 0x53dc
xorl %eax, %eax
callq 0x4184
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2160
testl %eax, %eax
jne 0x2eb4
leaq 0x2558(%rip), %rdi      # 0x5405
xorl %eax, %eax
callq 0x4184
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq