// File: /workspace/github_c_makefile_star2_O2/michaelforney[P]wld/wayland-drm.c
// Function: wayland_create_context
struct wayland_context *
wayland_create_context(struct wl_display *display,
                       struct wl_event_queue *queue)
{
	struct drm_context *context;

	if (!(context = malloc(sizeof *context)))
		goto error0;

	context_initialize(&context->base.base, &wld_context_impl);
	context->wl = NULL;
	context->fd = -1;
	context->capabilities = 0;
	wl_array_init(&context->formats);

	if (!(context->registry = wl_display_get_registry(display)))
		goto error1;

	wl_registry_add_listener(context->registry, &registry_listener, context);
	wl_proxy_set_queue((struct wl_proxy *)context->registry, queue);

	/* Wait for wl_drm global. */
	wl_display_roundtrip_queue(display, queue);

	if (!context->wl) {
		DEBUG("No wl_drm global\n");
		goto error2;
	}

	wl_drm_add_listener(context->wl, &drm_listener, context);

	/* Wait for DRM capabilities and device. */
	wl_display_roundtrip_queue(display, queue);

	if (!(context->capabilities & WL_DRM_CAPABILITY_PRIME)) {
		DEBUG("No PRIME support\n");
		goto error3;
	}

	if (context->fd == -1) {
		DEBUG("No DRM device\n");
		goto error3;
	}

	if (!(context->driver_context = wld_drm_create_context(context->fd))) {
		DEBUG("Couldn't initialize context for DRM device\n");
		goto error4;
	}

	return &context->base;

error4:
	close(context->fd);
error3:
	wl_drm_destroy(context->wl);
error2:
	wl_registry_destroy(context->registry);
error1:
	wl_array_release(&context->formats);
	free(context);
error0:
	return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %r12
pushq $0x58
popq %rdi
callq 0x9570
testq %rax, %rax
je 0xde1a
movq %rax, %rbx
leaq 0xaf6b(%rip), %rsi      # 0x18c20
movq %rax, %rdi
callq 0x9eb8
andq $0x0, 0x28(%rbx)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x50(%rbx)
movq %rbx, %r14
addq $0x38, %r14
movq %r14, %rdi
callq 0x91c0
movq %r12, %rdi
callq 0x9170
movq 0xb2da(%rip), %rdx      # 0x18fc8
pushq $0x1
popq %rsi
movq %r12, %rdi
movl %eax, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x9400
movq %rax, 0x30(%rbx)
testq %rax, %rax
je 0xde0a
leaq 0xaf31(%rip), %rsi      # 0x18c48
movq %rax, %rdi
movq %rbx, %rdx
callq 0x92b0
movq 0x30(%rbx), %rdi
movq %r15, %rsi
callq 0x97c0
movq %r12, %rdi
movq %r15, %rsi
callq 0x97b0
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0xdda5
leaq 0xaf0f(%rip), %rsi      # 0x18c58
movq %rbx, %rdx
callq 0x92b0
movq %r12, %rdi
movq %r15, %rsi
callq 0x97b0
testb $0x1, 0x50(%rbx)
je 0xddc6
movl 0x54(%rbx), %edi
cmpl $-0x1, %edi
je 0xddd9
callq 0x9160
movq %rax, 0x20(%rbx)
testq %rax, %rax
jne 0xde1c
movq 0xb26d(%rip), %rax      # 0x18ff0
movq (%rax), %rdi
leaq 0x3a28(%rip), %rsi      # 0x117b5
leaq 0x3888(%rip), %rdx      # 0x1161c
xorl %eax, %eax
callq 0x9480
movl 0x54(%rbx), %edi
callq 0x93c0
jmp 0xddf8
movq 0xb244(%rip), %rax      # 0x18ff0
movq (%rax), %rdi
leaq 0x39ba(%rip), %rsi      # 0x11770
leaq 0x385f(%rip), %rdx      # 0x1161c
xorl %eax, %eax
callq 0x9480
jmp 0xde01
movq 0xb223(%rip), %rax      # 0x18ff0
movq (%rax), %rdi
leaq 0x39b1(%rip), %rsi      # 0x11788
jmp 0xddea
movq 0xb210(%rip), %rax      # 0x18ff0
movq (%rax), %rdi
leaq 0x39b6(%rip), %rsi      # 0x117a0
leaq 0x382b(%rip), %rdx      # 0x1161c
xorl %eax, %eax
callq 0x9480
movq 0x28(%rbx), %rdi
callq 0x9830
movq 0x30(%rbx), %rdi
callq 0x9830
movq %r14, %rdi
callq 0x95a0
movq %rbx, %rdi
callq 0x9060
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq