// File: /workspace/github_c_makefile_star2_O1/michaelforney[P]wld/wayland.c
// Function: wld_wayland_create_context
wld_context *
wld_wayland_create_context(struct wl_display *display, enum wld_wayland_interface_id id, ...)
{
	struct wayland_context *context = NULL;
	struct wl_event_queue *queue;
	va_list requested_impls;
	bool impls_tried[ARRAY_LENGTH(impls)] = { 0 };
	const char *interface_string;

	if (!(queue = wl_display_create_queue(display)))
		return NULL;

	if ((interface_string = getenv("WLD_WAYLAND_INTERFACE"))) {
		id = interface_id(interface_string);

		if ((context = impls[id]->create_context(display, queue)))
			return &context->base;

		fprintf(stderr, "Could not create context for Wayland interface '%s'\n",
		        interface_string);

		return NULL;
	}

	va_start(requested_impls, id);

	while (id >= 0) {
		if (impls_tried[id] || !impls[id])
			continue;

		if ((context = impls[id]->create_context(display, queue)))
			goto done;

		impls_tried[id] = true;
		id = va_arg(requested_impls, enum wld_wayland_interface_id);
	}

	va_end(requested_impls);

	/* If the user specified WLD_ANY, try any remaining implementations. */
	if (!context && id == WLD_ANY) {
		for (id = 0; id < ARRAY_LENGTH(impls); ++id) {
			if (impls_tried[id] || !impls[id])
				continue;

			if ((context = impls[id]->create_context(display, queue)))
				break;
		}
	}

	if (!context) {
		DEBUG("Could not initialize any of the specified implementations\n");
		return NULL;
	}

done:
	context->impl = impls[id];
	context->display = display;
	context->queue = queue;

	return &context->base;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %esi, %r15d
movq %rdi, %rbx
movq %rdx, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
movq %r8, 0x50(%rsp)
movq %r9, 0x58(%rsp)
testb %al, %al
je 0xdd49
movaps %xmm0, 0x60(%rsp)
movaps %xmm1, 0x70(%rsp)
movaps %xmm2, 0x80(%rsp)
movaps %xmm3, 0x90(%rsp)
movaps %xmm4, 0xa0(%rsp)
movaps %xmm5, 0xb0(%rsp)
movaps %xmm6, 0xc0(%rsp)
movaps %xmm7, 0xd0(%rsp)
movw $0x0, 0xe(%rsp)
callq 0x9750
testq %rax, %rax
je 0xdebe
movq %rax, %r14
leaq 0x3808(%rip), %rdi      # 0x11570
callq 0x9030
testq %rax, %rax
je 0xddc1
movq %rax, %r13
movq %rax, %rdi
callq 0xdc8c
cltq
leaq 0x9dfa(%rip), %rcx      # 0x17b80
movq (%rcx,%rax,8), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *(%rax)
movq %rax, %r12
testq %rax, %rax
jne 0xdec1
movq 0xa24b(%rip), %rax      # 0x17ff0
movq (%rax), %rdi
leaq 0x37d7(%rip), %rsi      # 0x11586
xorl %r12d, %r12d
movq %r13, %rdx
xorl %eax, %eax
callq 0x9480
jmp 0xdec1
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x120(%rsp), %rax
movq %rax, 0x18(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, 0x10(%rsp)
testl %r15d, %r15d
js 0xde45
leaq 0x9d8d(%rip), %r13      # 0x17b80
movl %r15d, %ebp
cmpb $0x1, 0xe(%rsp,%rbp)
je 0xde50
movq (%r13,%rbp,8), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *(%rax)
testq %rax, %rax
jne 0xde8d
movb $0x1, 0xe(%rsp,%rbp)
movl 0x10(%rsp), %ecx
cmpq $0x28, %rcx
ja 0xde2f
movq %rcx, %rax
addq 0x20(%rsp), %rax
addl $0x8, %ecx
movl %ecx, 0x10(%rsp)
jmp 0xde3d
movq 0x18(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x18(%rsp)
movl (%rax), %r15d
testl %r15d, %r15d
jns 0xddf3
cmpl $-0x1, %r15d
je 0xde52
xorl %r12d, %r12d
jmp 0xde95
jmp 0xde50
leaq 0x9d27(%rip), %r13      # 0x17b80
xorl %r12d, %r12d
xorl %r15d, %r15d
cmpb $0x0, 0xe(%rsp,%r15)
jne 0xde78
movq (%r13), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *(%rax)
testq %rax, %rax
jne 0xde92
incq %r15
addq $0x8, %r13
cmpq $0x1, %r15
je 0xde5f
movl $0x2, %r15d
jmp 0xde95
movq %rax, %r12
jmp 0xde9a
movq %rax, %r12
testq %r12, %r12
je 0xdeb9
movslq %r15d, %rax
leaq 0x9cdc(%rip), %rcx      # 0x17b80
movq (%rcx,%rax,8), %rax
movq %rax, 0x8(%r12)
movq %rbx, 0x10(%r12)
movq %r14, 0x18(%r12)
jmp 0xdec1
callq 0x99fe
xorl %r12d, %r12d
movq %r12, %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq