// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0x25185
movq -0x10(%rbp), %rdi
addq $0x1, %rdi
movq -0x20(%rbp), %rsi
callq 0x266b0
jmp 0x2573d
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x38(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x30(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
leaq -0x38(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4460
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
callq 0x6750
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movl $0x23, %esi
callq 0x4550
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movl $0x3a, %esi
callq 0x4550
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x2521b
cmpq $0x0, -0x50(%rbp)
je 0x2521b
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x2521b
movq $0x0, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x2528e
movq -0x48(%rbp), %rax
movb $0x0, (%rax)
leaq 0x104d0(%rip), %rax     # 0x35700
movq (%rax), %rax
movq %rax, -0x70(%rbp)
leaq 0x104c2(%rip), %rax     # 0x35700
movq (%rax), %rax
movq 0x58(%rax), %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x70(%rbp), %rsi
callq 0x25140
movl %eax, -0x54(%rbp)
cmpl $0x0, %eax
jne 0x25278
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x2528c
movq -0x40(%rbp), %rdi
callq 0x4450
movl -0x54(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x25758
jmp 0x2528e
cmpq $0x0, -0x50(%rbp)
je 0x252ae
cmpq $0x0, -0x48(%rbp)
je 0x252ae
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x252ae
movq $0x0, -0x50(%rbp)
leaq -0x94(%rbp), %rdi
callq 0x26570
cmpq $0x0, -0x50(%rbp)
je 0x252ce
movq -0x50(%rbp), %rax
movq %rax, -0xf8(%rbp)
jmp 0x252d9
movq -0x10(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rdi
leaq -0x94(%rbp), %rsi
callq 0x21e80
testb $0x1, %al
jne 0x25305
movq -0x40(%rbp), %rdi
callq 0x4450
movl $0x2, -0x4(%rbp)
jmp 0x25758
movq -0x10(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x20cb0
testb $0x1, %al
jne 0x2531b
jmp 0x2533a
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x98(%rbp), %edx
leaq -0x94(%rbp), %rcx
callq 0x9b80
jmp 0x25734
movq -0x10(%rbp), %rdi
leaq -0x9c(%rbp), %rsi
callq 0x20d90
testb $0x1, %al
jne 0x25350
jmp 0x2536f
movl -0x9c(%rbp), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x94(%rbp), %rcx
callq 0x12d70
jmp 0x25732
movq -0x10(%rbp), %rsi
leaq 0x98cd(%rip), %rdi      # 0x2ec47
callq 0x4800
cmpl $0x0, %eax
jne 0x2539d
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x94(%rbp), %rdx
callq 0x9db0
jmp 0x25730
movq -0x10(%rbp), %rsi
leaq 0xa04c(%rip), %rdi      # 0x2f3f4
callq 0x4800
cmpl $0x0, %eax
jne 0x253cd
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
xorl %edi, %edi
leaq -0x94(%rbp), %rcx
callq 0x12d70
jmp 0x2572e
movq -0x10(%rbp), %rsi
leaq 0xa021(%rip), %rdi      # 0x2f3f9
callq 0x4800
cmpl $0x0, %eax
jne 0x253fb
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x94(%rbp), %rdx
callq 0x12ce0
jmp 0x2572c
movq -0x10(%rbp), %rsi
leaq 0x9a0d(%rip), %rdi      # 0x2ee13
callq 0x4800
cmpl $0x0, %eax
jne 0x25487
leaq 0x102e9(%rip), %rax     # 0x35700
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
leaq 0x102d8(%rip), %rax     # 0x35700
movq (%rax), %rax
movq 0x58(%rax), %rax
movq %rax, -0xb8(%rbp)
movq $0x0, -0xb0(%rbp)
movq -0x18(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
leaq -0x94(%rbp), %rdx
callq 0x23ab0
testb $0x1, %al
jne 0x2545e
jmp 0x25482
movq -0x20(%rbp), %rax
movq -0xc0(%rbp), %rcx
movq %rcx, (%rax)
movq -0xb8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0xb0(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x2572a
cmpq $0x0, -0x50(%rbp)
je 0x255eb
movq -0x50(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x24c20
movl %eax, -0xc4(%rbp)
cmpl $0x0, %eax
jne 0x255cf
movq -0x50(%rbp), %rsi
addq $0x1, %rsi
leaq 0x994b(%rip), %rdi      # 0x2ee13
callq 0x4800
cmpl $0x0, %eax
jne 0x25543
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x58(%rax), %rax
movq %rax, -0xd8(%rbp)
movq $0x0, -0xd0(%rbp)
movq -0x18(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
leaq -0x94(%rbp), %rdx
callq 0x23ab0
testb $0x1, %al
jne 0x2551a
jmp 0x2553e
movq -0x20(%rbp), %rax
movq -0xe0(%rbp), %rcx
movq %rcx, (%rax)
movq -0xd8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0xd0(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x255cd
movq -0x50(%rbp), %rdi
addq $0x1, %rdi
leaq -0x9e(%rbp), %rsi
callq 0x217f0
testb $0x1, %al
jne 0x2555d
jmp 0x255b8
movq -0x40(%rbp), %rdi
callq 0x4450
movw -0x9e(%rbp), %ax
movq -0x20(%rbp), %rsi
movq -0x20(%rbp), %rcx
movq (%rcx), %rdx
movzwl %ax, %edi
callq 0x26750
testb $0x1, %al
jne 0x25586
jmp 0x255ac
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x94(%rbp), %rdx
callq 0x23ab0
testb $0x1, %al
jne 0x255a0
jmp 0x255ac
movl $0x0, -0x4(%rbp)
jmp 0x25758
movl $0x1, -0x4(%rbp)
jmp 0x25758
movq -0x40(%rbp), %rdi
callq 0x4450
movl $0x3, -0x4(%rbp)
jmp 0x25758
jmp 0x255e6
movq -0x40(%rbp), %rdi
callq 0x4450
movl -0xc4(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x25758
jmp 0x25728
movq -0x10(%rbp), %rdi
leaq -0x9e(%rbp), %rsi
callq 0x217f0
testb $0x1, %al
jne 0x25601
jmp 0x25659
movw -0x9e(%rbp), %ax
movq -0x20(%rbp), %rsi
xorl %ecx, %ecx
movl %ecx, %edx
movzwl %ax, %edi
callq 0x26750
testb $0x1, %al
jne 0x2561e
jmp 0x25659
movq -0x40(%rbp), %rdi
callq 0x4450
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x94(%rbp), %rdx
callq 0x23ab0
testb $0x1, %al
jne 0x25641
jmp 0x2564d
movl $0x0, -0x4(%rbp)
jmp 0x25758
movl $0x1, -0x4(%rbp)
jmp 0x25758
movq -0x10(%rbp), %rdi
leaq -0xa4(%rbp), %rsi
callq 0x216f0
testb $0x1, %al
jne 0x2566f
jmp 0x256c3
movl -0xa4(%rbp), %edi
movq -0x20(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x26810
testb $0x1, %al
jne 0x25688
jmp 0x256c3
movq -0x40(%rbp), %rdi
callq 0x4450
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x94(%rbp), %rdx
callq 0x23ab0
testb $0x1, %al
jne 0x256ab
jmp 0x256b7
movl $0x0, -0x4(%rbp)
jmp 0x25758
movl $0x1, -0x4(%rbp)
jmp 0x25758
movl $0x0, -0xe4(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x94(%rbp), %rcx
leaq -0xe4(%rbp), %r8
callq 0x268c0
testb $0x1, %al
jne 0x256f2
jmp 0x25704
movq -0x40(%rbp), %rdi
callq 0x4450
movl $0x0, -0x4(%rbp)
jmp 0x25758
movq -0x40(%rbp), %rdi
callq 0x4450
cmpl $0x0, -0xe4(%rbp)
jle 0x2571f
movl $0x1, -0x4(%rbp)
jmp 0x25758
movl $0x3, -0x4(%rbp)
jmp 0x25758
jmp 0x2572a
jmp 0x2572c
jmp 0x2572e
jmp 0x25730
jmp 0x25732
jmp 0x25734
movq -0x40(%rbp), %rdi
callq 0x4450
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x25751
movl $0x1, -0x4(%rbp)
jmp 0x25758
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw %cs:(%rax,%rax)