// File: /workspace/github_c_makefile_star2_O1/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 0x19ffe
incq %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1adff
jmp 0x1a22a
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 0x5e6e
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
testq %r14, %r14
je 0x1a0a1
movb $0x0, (%r14)
leaq 0xf6aa(%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 0x19fc7
movl %eax, %ebp
testl %eax, %eax
je 0x1a0a6
movq %r12, %rdi
callq 0x4460
movq %r12, %r15
jmp 0x1a0aa
movq %r12, %r15
jmp 0x1a0b2
leaq 0x1(%r14), %r15
testl %ebp, %ebp
jne 0x1a235
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 0x17945
testb %al, %al
je 0x1a116
leaq 0x3c(%rsp), %rsi
movq %r15, %rdi
callq 0x16c60
testb %al, %al
je 0x1a12a
movl 0x3c(%rsp), %edx
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rcx
movq %rbx, %rsi
callq 0x7cdd
jmp 0x1a21d
movq 0x8(%rsp), %rdi
callq 0x4460
movl $0x2, %ebp
jmp 0x1a235
leaq 0x38(%rsp), %rsi
movq %r15, %rdi
callq 0x16cf2
testb %al, %al
je 0x1a156
movl 0x38(%rsp), %edi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rcx
movq %rbx, %rdx
callq 0xd9fe
jmp 0x1a21d
leaq 0x6958(%rip), %rdi      # 0x20ab5
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x1a1e6
leaq 0x7116(%rip), %rdi      # 0x21286
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x1a1fa
leaq 0x7108(%rip), %rdi      # 0x2128b
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x1a20b
leaq 0x6aeb(%rip), %rdi      # 0x20c81
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x1a249
testq %r12, %r12
je 0x1a299
movb $0x0, (%r12)
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x19c02
testl %eax, %eax
je 0x1a30e
movl %eax, %r15d
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x4460
xorl %ecx, %ecx
movl %r15d, %ebp
jmp 0x1a429
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %rbx, %rsi
callq 0x7e1f
jmp 0x1a21d
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rcx
xorl %edi, %edi
jmp 0x1a149
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movq %rbx, %rsi
callq 0xd99f
movq 0x8(%rsp), %r14
movq %r14, %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 0xf4c0(%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 0x190a4
testb %al, %al
movq 0x8(%rsp), %r14
je 0x1a222
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rbx)
movups 0x70(%rsp), %xmm0
movups %xmm0, (%rbx)
jmp 0x1a222
leaq 0x6(%rsp), %rsi
movq %r15, %rdi
callq 0x173f4
testb %al, %al
je 0x1a2bd
movzwl 0x6(%rsp), %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1ae75
testb %al, %al
jne 0x1a2e8
leaq 0x34(%rsp), %rsi
movq %r15, %rdi
callq 0x17346
testb %al, %al
je 0x1a38c
movl 0x34(%rsp), %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1aee2
testb %al, %al
je 0x1a38c
movq 0x8(%rsp), %rdi
callq 0x4460
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x190a4
xorb $0x1, %al
movzbl %al, %ebp
jmp 0x1a235
incq %r12
leaq 0x6969(%rip), %rdi      # 0x20c81
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x1a3d7
leaq 0x6(%rsp), %rsi
movq %r12, %rdi
callq 0x173f4
movl %eax, %ebp
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x4460
testb %bpl, %bpl
je 0x1a422
movzwl 0x6(%rsp), %edi
movq (%rbx), %rdx
movq %rbx, %rsi
callq 0x1ae75
testb %al, %al
je 0x1a382
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x190a4
xorl %ecx, %ecx
movl $0x0, %ebp
testb %al, %al
jne 0x1a429
movl $0x1, %ebp
jmp 0x1a427
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 0x1af3d
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 0x1a235
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 0x190a4
testb %al, %al
je 0x1a419
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rbx)
movups 0x70(%rsp), %xmm0
movups %xmm0, (%rbx)
movb $0x1, %cl
movq 0x8(%rsp), %r14
jmp 0x1a429
movl $0x3, %ebp
xorl %ecx, %ecx
testb %cl, %cl
jne 0x1a222
jmp 0x1a235