// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x58, %edi
callq 0x9590
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x12169
jmp 0x1232a
movq -0x20(%rbp), %rdi
leaq 0x9aac(%rip), %rsi      # 0x1bc20
callq 0xa3f0
movq -0x20(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x20(%rbp), %rax
movl $0xffffffff, 0x54(%rax) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movl $0x0, 0x50(%rax)
movq -0x20(%rbp), %rdi
addq $0x38, %rdi
callq 0x91d0
movq -0x10(%rbp), %rdi
callq 0x12440
movq -0x20(%rbp), %rcx
movq %rax, 0x30(%rcx)
cmpq $0x0, %rax
jne 0x121c4
jmp 0x12314
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0x9a71(%rip), %rsi      # 0x1bc48
callq 0x12490
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x97e0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x97d0
movq -0x20(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x12229
movq 0x9de4(%rip), %rax      # 0x1bff0
movq (%rax), %rdi
leaq 0x306a(%rip), %rsi      # 0x15280
leaq 0x2f0b(%rip), %rdx      # 0x15128
movb $0x0, %al
callq 0x94a0
jmp 0x12307
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0x9a1c(%rip), %rsi      # 0x1bc58
callq 0x124c0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x97d0
movq -0x20(%rbp), %rax
movl 0x50(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1227e
movq 0x9d8c(%rip), %rax      # 0x1bff0
movq (%rax), %rdi
leaq 0x302a(%rip), %rsi      # 0x15298
leaq 0x2eb3(%rip), %rdx      # 0x15128
movb $0x0, %al
callq 0x94a0
jmp 0x122fa
movq -0x20(%rbp), %rax
cmpl $-0x1, 0x54(%rax)
jne 0x122a9
movq 0x9d61(%rip), %rax      # 0x1bff0
movq (%rax), %rdi
leaq 0x3017(%rip), %rsi      # 0x152b0
leaq 0x2e88(%rip), %rdx      # 0x15128
movb $0x0, %al
callq 0x94a0
jmp 0x122fa
movq -0x20(%rbp), %rax
movl 0x54(%rax), %edi
callq 0x9170
movq -0x20(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0x122e4
movq 0x9d26(%rip), %rax      # 0x1bff0
movq (%rax), %rdi
leaq 0x2ff1(%rip), %rsi      # 0x152c5
leaq 0x2e4d(%rip), %rdx      # 0x15128
movb $0x0, %al
callq 0x94a0
jmp 0x122ee
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x12332
movq -0x20(%rbp), %rax
movl 0x54(%rax), %edi
callq 0x93e0
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x124f0
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x12510
movq -0x20(%rbp), %rdi
addq $0x38, %rdi
callq 0x95c0
movq -0x20(%rbp), %rdi
callq 0x9060
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)