// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, 0x8(%rdx)
movq %rdi, %r14
cmpb $0x25, (%rdi)
jne 0x18ac9
incq %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1978f
jmp 0x18cce
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 0x5d82
movq %rax, %r12
pushq $0x23
popq %rsi
movq %rax, %rdi
callq 0x4560
movq %rax, %r15
pushq $0x3a
popq %rsi
movq %r12, %rdi
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 0x18b6c
movb $0x0, (%r14)
leaq 0xfbe0(%rip), %rax      # 0x28710
movq (%rax), %rax
leaq 0x70(%rsp), %rsi
movq %rax, (%rsi)
movq 0x58(%rax), %rax
movq %rax, 0x8(%rsi)
andq $0x0, 0x10(%rsi)
leaq 0x10(%rsp), %rdx
movq %r12, %rdi
callq 0x18a95
testl %eax, %eax
je 0x18b68
movl %eax, %ebp
movq %r12, %rdi
callq 0x4460
jmp 0x18cd9
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)
andl $0x0, 0x20(%rsi)
testq %r12, %r12
movq %r12, %rdi
cmoveq %r15, %rdi
callq 0x1660c
testb %al, %al
je 0x18bcd
leaq 0x3c(%rsp), %rsi
movq %r15, %rdi
callq 0x159bc
testb %al, %al
je 0x18bdf
movl 0x3c(%rsp), %edx
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rcx
movq %rbx, %rsi
callq 0x7996
jmp 0x18cc4
movq 0x8(%rsp), %rdi
callq 0x4460
pushq $0x2
popq %rbp
jmp 0x18cd9
leaq 0x38(%rsp), %rsi
movq %r15, %rdi
callq 0x15a4a
testb %al, %al
je 0x18c0b
movl 0x38(%rsp), %edi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rcx
movq %rbx, %rdx
callq 0xceef
jmp 0x18cc4
leaq 0x6e57(%rip), %rdi      # 0x1fa69
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x18c8d
leaq 0x7615(%rip), %rdi      # 0x2023a
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x18ca1
leaq 0x7607(%rip), %rdi      # 0x2023f
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x18cb2
leaq 0x6fea(%rip), %rdi      # 0x1fc35
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x18ced
testq %r12, %r12
je 0x18d3a
movb $0x0, (%r12)
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x1876b
testl %eax, %eax
je 0x18daf
movl %eax, %ebp
movq 0x8(%rsp), %rdi
jmp 0x18b5e
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %rbx, %rsi
callq 0x7ac2
jmp 0x18cc4
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rcx
xorl %edi, %edi
jmp 0x18bfe
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %rbx, %rsi
callq 0xce96
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 0xfa1c(%rip), %rax      # 0x28710
movq (%rax), %rax
leaq 0x70(%rsp), %rdi
movq %rax, (%rdi)
movq 0x58(%rax), %rax
movq %rax, 0x8(%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x17c4d
testb %al, %al
movq 0x8(%rsp), %rdi
je 0x18cc9
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rbx)
movups 0x70(%rsp), %xmm0
movups %xmm0, (%rbx)
jmp 0x18cc9
leaq 0x6(%rsp), %rsi
movq %r15, %rdi
callq 0x160f1
testb %al, %al
je 0x18d5e
movzwl 0x6(%rsp), %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x197ee
testb %al, %al
jne 0x18d89
leaq 0x34(%rsp), %rsi
movq %r15, %rdi
callq 0x16048
testb %al, %al
je 0x18e22
movl 0x34(%rsp), %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x19842
testb %al, %al
je 0x18e22
movq 0x8(%rsp), %rdi
callq 0x4460
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x17c4d
xorb $0x1, %al
movzbl %al, %ebp
jmp 0x18cd9
incq %r12
leaq 0x6e7c(%rip), %rdi      # 0x1fc35
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x18e6c
leaq 0x6(%rsp), %rsi
movq %r12, %rdi
callq 0x160f1
movl %eax, %ebp
movq 0x8(%rsp), %rdi
callq 0x4460
testb %bpl, %bpl
je 0x18eb4
movzwl 0x6(%rsp), %edi
movq (%rbx), %rdx
movq %rbx, %rsi
callq 0x197ee
testb %al, %al
je 0x18e1b
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x17c4d
xorl %ebp, %ebp
testb %al, %al
jne 0x18cd9
pushq $0x1
jmp 0x18bd9
leaq 0x70(%rsp), %r12
andl $0x0, (%r12)
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rcx
movq %r15, %rdi
movq %rbx, %rdx
movq %r12, %r8
callq 0x19893
movl %eax, %ebx
movq 0x8(%rsp), %rdi
callq 0x4460
xorl %eax, %eax
xorl %ecx, %ecx
cmpl %eax, (%r12)
setle %cl
leal 0x1(,%rcx,2), %ebp
testb %bl, %bl
cmovnel %eax, %ebp
jmp 0x18cd9
movq (%rbx), %rax
leaq 0x70(%rsp), %rdi
movq %rax, (%rdi)
movq 0x58(%rax), %rax
movq %rax, 0x8(%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x17c4d
testb %al, %al
je 0x18cc4
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rbx)
movups 0x70(%rsp), %xmm0
movups %xmm0, (%rbx)
jmp 0x18cc4
pushq $0x3
jmp 0x18bd9