// File: /workspace/github_c_makefile_star2_O1/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 *0x5470(%rip)           # 0x8238
movq %rax, %r14
movl $0x333c, 0xc(%rsp)      # imm = 0x333C
movl %ebp, 0x10(%rsp)
movl $0x3038, 0x14(%rsp)     # imm = 0x3038
leaq 0x2563(%rip), %rsi      # 0x5349
movq %r15, %rdi
callq 0x29fc
testl %eax, %eax
jne 0x2e00
leaq 0x2566(%rip), %rdi      # 0x535f
xorl %eax, %eax
callq 0x41e8
leaq 0x257a(%rip), %rsi      # 0x5381
movq %r15, %rdi
callq 0x29fc
testl %eax, %eax
jne 0x2e21
leaq 0x257f(%rip), %rdi      # 0x5399
xorl %eax, %eax
callq 0x41e8
leaq 0x2458(%rip), %rsi      # 0x5280
movq %r14, %rdi
callq 0x29fc
testl %eax, %eax
jne 0x2e42
leaq 0x2582(%rip), %rdi      # 0x53bd
xorl %eax, %eax
callq 0x41e8
leaq 0xc(%rsp), %rdx
movl $0x313f, %edi           # imm = 0x313F
movq %rbx, %rsi
callq *0x53eb(%rip)           # 0x8240
movq %rax, %rbx
testq %rax, %rax
jne 0x2e6b
leaq 0x2578(%rip), %rdi      # 0x53dc
xorl %eax, %eax
callq 0x41e8
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2160
testl %eax, %eax
jne 0x2e89
leaq 0x2583(%rip), %rdi      # 0x5405
xorl %eax, %eax
callq 0x41e8
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq