// File: /workspace/github_c_makefile_star2_O3/baskerville[P]bspwm/src/query.c
// Function: desktop_from_desc
int desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
{
	dst->desktop = NULL;

	if (*desc == '%') {
		locate_desktop(desc + 1, dst);
		goto end;
	}

	coordinates_t ref_copy = *ref;
	ref = &ref_copy;
	char *desc_copy = copy_string(desc, strlen(desc));
	desc = desc_copy;

	char *hash = strrchr(desc, '#');
	char *colon = strrchr(desc, ':');

	/* Discard hashes inside a MONITOR_SEL, e.g. `primary#next:focused` */
	if (hash != NULL && colon != NULL && hash < colon) {
		hash = NULL;
	}

	if (hash != NULL) {
		*hash = '\0';
		int ret;
		coordinates_t tmp = {mon, mon->desk, NULL};
		if ((ret = desktop_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
			desc = hash + 1;
		} else {
			free(desc_copy);
			return ret;
		}
	}

	/* Discard colons within references, e.g. `DisplayPort-1:focused#next.local` */
	if (colon != NULL && hash != NULL && colon < hash) {
		colon = NULL;
	}

	desktop_select_t sel = make_desktop_select();

	if (!parse_desktop_modifiers(colon != NULL ? colon : desc, &sel)) {
		free(desc_copy);
		return SELECTOR_BAD_MODIFIERS;
	}

	cycle_dir_t cyc;
	history_dir_t hdi;
	uint16_t idx;
	uint32_t id;
	if (parse_cycle_direction(desc, &cyc)) {
		find_closest_desktop(ref, dst, cyc, &sel);
	} else if (parse_history_direction(desc, &hdi)) {
		history_find_desktop(hdi, ref, dst, &sel);
	} else if (streq("any", desc)) {
		find_any_desktop(ref, dst, &sel);
	} else if (streq("last", desc)) {
		history_find_desktop(HISTORY_OLDER, ref, dst, &sel);
	} else if (streq("newest", desc)) {
		history_find_newest_desktop(ref, dst, &sel);
	} else if (streq("focused", desc)) {
		coordinates_t loc = {mon, mon->desk, NULL};
		if (desktop_matches(&loc, ref, &sel)) {
			*dst = loc;
		}
	} else if (colon != NULL) {
		*colon = '\0';
		int ret;
		if ((ret = monitor_from_desc(desc, ref, dst)) == SELECTOR_OK) {
			if (streq("focused", colon + 1)) {
				coordinates_t loc = {dst->monitor, dst->monitor->desk, NULL};
				if (desktop_matches(&loc, ref, &sel)) {
					*dst = loc;
				}
			} else if (parse_index(colon + 1, &idx)) {
				free(desc_copy);
				if (desktop_from_index(idx, dst, dst->monitor) && desktop_matches(dst, ref, &sel)) {
					return SELECTOR_OK;
				} else {
					return SELECTOR_INVALID;
				}
			} else {
				free(desc_copy);
				return SELECTOR_BAD_DESCRIPTOR;
			}
		} else {
			free(desc_copy);
			return ret;
		}
	} else if (parse_index(desc, &idx) && desktop_from_index(idx, dst, NULL)) {
		free(desc_copy);
		if (desktop_matches(dst, ref, &sel)) {
			return SELECTOR_OK;
		} else {
			return SELECTOR_INVALID;
		}
	} else if (parse_id(desc, &id) && desktop_from_id(id, dst, NULL)) {
		free(desc_copy);
		if (desktop_matches(dst, ref, &sel)) {
			return SELECTOR_OK;
		} else {
			return SELECTOR_INVALID;
		}
	} else {
		int hits = 0;
		if (desktop_from_name(desc, ref, dst, &sel, &hits)) {
			free(desc_copy);
			return SELECTOR_OK;
		} else {
			free(desc_copy);
			if (hits > 0) {
				return SELECTOR_INVALID;
			} else {
				return SELECTOR_BAD_DESCRIPTOR;
			}
		}
	}

	free(desc_copy);

end:
	if (dst->desktop == NULL) {
		return SELECTOR_INVALID;
	}

	return SELECTOR_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, %rbx
movq %rdi, %r14
movq $0x0, 0x8(%rdx)
cmpb $0x25, (%rdi)
jne 0x19ee6
incq %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1ac03
jmp 0x1a0f7
movq 0x10(%rsi), %rax
movq %rax, 0x20(%rsp)
movups (%rsi), %xmm0
movaps %xmm0, 0x10(%rsp)
movq %r14, %rdi
callq 0x4470
movq %r14, %rdi
movq %rax, %rsi
callq 0x5e2f
movq %rax, %r12
movq %rax, %rdi
movl $0x23, %esi
callq 0x4560
movq %rax, %r15
movq %r12, %rdi
movl $0x3a, %esi
callq 0x4560
movq %rax, %r13
xorl %r14d, %r14d
cmpq %rax, %r15
cmovaeq %r15, %r14
testq %r15, %r15
cmoveq %r15, %r14
movq %r12, %r15
testq %r14, %r14
je 0x19f90
movb $0x0, (%r14)
leaq 0xf7bf(%rip), %rax      # 0x29710
movq (%rax), %rax
leaq 0x70(%rsp), %rsi
movq %rax, (%rsi)
movq 0x58(%rax), %rax
movq %rax, 0x8(%rsi)
movq $0x0, 0x10(%rsi)
leaq 0x10(%rsp), %rdx
movq %r12, %rdi
callq 0x19eaf
testl %eax, %eax
je 0x19f8c
movl %eax, %ebp
movq %r12, %rdi
callq 0x4460
jmp 0x1a102
leaq 0x1(%r14), %r15
movq %r12, 0x8(%rsp)
xorl %r12d, %r12d
cmpq %r14, %r13
cmovaeq %r13, %r12
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
movl $0x0, 0x20(%rsi)
testq %r12, %r12
movq %r12, %rdi
cmoveq %r15, %rdi
callq 0x17811
testb %al, %al
je 0x19ff4
leaq 0x3c(%rsp), %rsi
movq %r15, %rdi
callq 0x16b33
testb %al, %al
je 0x1a008
movl 0x3c(%rsp), %edx
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rcx
movq %rbx, %rsi
callq 0x7ba9
jmp 0x1a0ed
movq 0x8(%rsp), %rdi
callq 0x4460
movl $0x2, %ebp
jmp 0x1a102
leaq 0x38(%rsp), %rsi
movq %r15, %rdi
callq 0x16bc5
testb %al, %al
je 0x1a034
movl 0x38(%rsp), %edi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rcx
movq %rbx, %rdx
callq 0xda89
jmp 0x1a0ed
leaq 0x6a2e(%rip), %rdi      # 0x20a69
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x1a0b6
leaq 0x71ec(%rip), %rdi      # 0x2123a
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x1a0ca
leaq 0x71de(%rip), %rdi      # 0x2123f
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x1a0db
leaq 0x6bc1(%rip), %rdi      # 0x20c35
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x1a116
testq %r12, %r12
je 0x1a166
movb $0x0, (%r12)
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x19b1a
testl %eax, %eax
je 0x1a1db
movl %eax, %ebp
movq 0x8(%rsp), %rdi
jmp 0x19f82
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %rbx, %rsi
callq 0x7ce4
jmp 0x1a0ed
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rcx
xorl %edi, %edi
jmp 0x1a027
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %rbx, %rsi
callq 0xda2d
movq 0x8(%rsp), %rdi
callq 0x4460
xorl %ebp, %ebp
cmpq $0x0, 0x8(%rbx)
sete %bpl
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf5f3(%rip), %rax      # 0x29710
movq (%rax), %rax
leaq 0x70(%rsp), %rdi
movq %rax, (%rdi)
movq 0x58(%rax), %rax
movq %rax, 0x8(%rdi)
movq $0x0, 0x10(%rdi)
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x18fb4
testb %al, %al
movq 0x8(%rsp), %rdi
je 0x1a0f2
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rbx)
movups 0x70(%rsp), %xmm0
movups %xmm0, (%rbx)
jmp 0x1a0f2
leaq 0x6(%rsp), %rsi
movq %r15, %rdi
callq 0x172c5
testb %al, %al
je 0x1a18a
movzwl 0x6(%rsp), %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1ac62
testb %al, %al
jne 0x1a1b5
leaq 0x34(%rsp), %rsi
movq %r15, %rdi
callq 0x17217
testb %al, %al
je 0x1a257
movl 0x34(%rsp), %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1acb5
testb %al, %al
je 0x1a257
movq 0x8(%rsp), %rdi
callq 0x4460
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x18fb4
xorb $0x1, %al
movzbl %al, %ebp
jmp 0x1a102
incq %r12
leaq 0x6a50(%rip), %rdi      # 0x20c35
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x1a2a2
leaq 0x6(%rsp), %rsi
movq %r12, %rdi
callq 0x172c5
movl %eax, %r15d
movq 0x8(%rsp), %rdi
callq 0x4460
movl $0x3, %ebp
testb %r15b, %r15b
je 0x1a102
movzwl 0x6(%rsp), %edi
movq (%rbx), %rdx
movq %rbx, %rsi
callq 0x1ac62
testb %al, %al
je 0x1a24d
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x18fb4
xorl %ebp, %ebp
testb %al, %al
jne 0x1a102
movl $0x1, %ebp
jmp 0x1a102
xorl %r14d, %r14d
leaq 0x70(%rsp), %r12
movl %r14d, (%r12)
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rcx
movq %r15, %rdi
movq %rbx, %rdx
movq %r12, %r8
callq 0x1ad05
movl %eax, %ebx
movq 0x8(%rsp), %rdi
callq 0x4460
xorl %eax, %eax
cmpl %r14d, (%r12)
setle %al
leal 0x1(,%rax,2), %ebp
testb %bl, %bl
cmovnel %r14d, %ebp
jmp 0x1a102
movq (%rbx), %rax
leaq 0x70(%rsp), %rdi
movq %rax, (%rdi)
movq 0x58(%rax), %rax
movq %rax, 0x8(%rdi)
movq $0x0, 0x10(%rdi)
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x18fb4
testb %al, %al
je 0x1a0ed
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rbx)
movups 0x70(%rsp), %xmm0
movups %xmm0, (%rbx)
jmp 0x1a0ed