// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
xorl %eax, %eax
movl %eax, %edi
movl $0x3055, %esi           # imm = 0x3055
callq 0x21d0
movq %rax, -0x20(%rbp)
movq 0x60b8(%rip), %rax      # 0x9230
movq -0x8(%rbp), %rdi
movl $0x3055, %esi           # imm = 0x3055
callq *%rax
movq %rax, -0x28(%rbp)
movl $0x333c, -0x34(%rbp)    # imm = 0x333C
movl -0xc(%rbp), %eax
movl %eax, -0x30(%rbp)
movl $0x3038, -0x2c(%rbp)    # imm = 0x3038
movq -0x20(%rbp), %rdi
leaq 0x323e(%rip), %rsi      # 0x63e4
callq 0x2cf0
cmpl $0x0, %eax
jne 0x31be
leaq 0x3243(%rip), %rdi      # 0x63fa
movb $0x0, %al
callq 0x4cf0
movq -0x20(%rbp), %rdi
leaq 0x3253(%rip), %rsi      # 0x641c
callq 0x2cf0
cmpl $0x0, %eax
jne 0x31e1
leaq 0x325a(%rip), %rdi      # 0x6434
movb $0x0, %al
callq 0x4cf0
movq -0x28(%rbp), %rdi
leaq 0x312f(%rip), %rsi      # 0x631b
callq 0x2cf0
cmpl $0x0, %eax
jne 0x3204
leaq 0x325b(%rip), %rdi      # 0x6458
movb $0x0, %al
callq 0x4cf0
movq 0x602d(%rip), %rax      # 0x9238
movq -0x8(%rbp), %rsi
leaq -0x34(%rbp), %rdx
movl $0x313f, %edi           # imm = 0x313F
callq *%rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3233
leaq 0x324b(%rip), %rdi      # 0x6477
movb $0x0, %al
callq 0x4cf0
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x2140
cmpl $0x0, %eax
jne 0x3256
leaq 0x3251(%rip), %rdi      # 0x64a0
movb $0x0, %al
callq 0x4cf0
movq -0x18(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq