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

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

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

	/* Adjust or discard hashes inside a DESKTOP_SEL, e.g. `newest#@prev#older:/1/2` */
	if (hash != NULL && colon != NULL && path != NULL &&
	    path < hash && hash < colon) {
		if (path > desc && *(path - 1) == '#') {
			hash = path - 1;
		} else {
			hash = NULL;
		}
	}

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

	/* Discard colons within references, e.g. `@next.occupied:/#any.descendant_of.window` */
	if (colon != NULL && hash != NULL && colon < hash) {
		colon = NULL;
	}

	node_select_t sel = make_node_select();

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

	direction_t dir;
	cycle_dir_t cyc;
	history_dir_t hdi;
	if (parse_direction(desc, &dir)) {
		find_nearest_neighbor(ref, dst, dir, &sel);
	} else if (parse_cycle_direction(desc, &cyc)) {
		find_closest_node(ref, dst, cyc, &sel);
	} else if (parse_history_direction(desc, &hdi)) {
		history_find_node(hdi, ref, dst, &sel);
	} else if (streq("any", desc)) {
		find_any_node(ref, dst, &sel);
	} else if (streq("first_ancestor", desc)) {
		find_first_ancestor(ref, dst, &sel);
	} else if (streq("last", desc)) {
		history_find_node(HISTORY_OLDER, ref, dst, &sel);
	} else if (streq("newest", desc)) {
		history_find_newest_node(ref, dst, &sel);
	} else if (streq("biggest", desc)) {
		find_by_area(AREA_BIGGEST, ref, dst, &sel);
	} else if (streq("smallest", desc)) {
		find_by_area(AREA_SMALLEST, ref, dst, &sel);
	} else if (streq("pointed", desc)) {
		xcb_window_t win = XCB_NONE;
		query_pointer(&win, NULL);
		if (locate_leaf(win, dst) && node_matches(dst, ref, &sel)) {
			return SELECTOR_OK;
		} else {
			return SELECTOR_INVALID;
		}
	} else if (streq("focused", desc)) {
		coordinates_t loc = {mon, mon->desk, mon->desk->focus};
		if (node_matches(&loc, ref, &sel)) {
			*dst = loc;
		}
	} else if (*desc == '@') {
		desc++;
		*dst = *ref;
		if (colon != NULL) {
			*colon = '\0';
			int ret;
			if ((ret = desktop_from_desc(desc, ref, dst)) == SELECTOR_OK) {
				dst->node = dst->desktop->focus;
				desc = colon + 1;
			} else {
				free(desc_copy);
				return ret;
			}
		}
		if (*desc == '/') {
			dst->node = dst->desktop->root;
		}
		char *move = strtok(desc, PTH_TOK);
		while (move != NULL && dst->node != NULL) {
			if (streq("first", move) || streq("1", move)) {
				dst->node = dst->node->first_child;
			} else if (streq("second", move) || streq("2", move)) {
				dst->node = dst->node->second_child;
			} else if (streq("parent", move)) {
				dst->node = dst->node->parent;
			} else if (streq("brother", move)) {
				dst->node = brother_tree(dst->node);
			} else {
				direction_t dir;
				if (parse_direction(move, &dir)) {
					dst->node = find_fence(dst->node, dir);
				} else {
					free(desc_copy);
					return SELECTOR_BAD_DESCRIPTOR;
				}
			}
			move = strtok(NULL, PTH_TOK);
		}
		free(desc_copy);
		if (dst->node != NULL) {
			if (node_matches(dst, ref, &sel)) {
				return SELECTOR_OK;
			} else {
				return SELECTOR_INVALID;
			}
		} else if (dst->desktop->root != NULL) {
			return SELECTOR_INVALID;
		}
		return SELECTOR_OK;
	} else {
		uint32_t id;
		if (parse_id(desc, &id)) {
			free(desc_copy);
			if (find_by_id(id, dst) && node_matches(dst, ref, &sel)) {
				return SELECTOR_OK;
			} else {
				return SELECTOR_INVALID;
			}
		} else {
			free(desc_copy);
			return SELECTOR_BAD_DESCRIPTOR;
		}
	}

	free(desc_copy);

	if (dst->node == NULL) {
		return SELECTOR_INVALID;
	}

	return SELECTOR_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, %rbx
movq %rdi, %r14
andq $0x0, 0x10(%rdx)
movq 0x10(%rsi), %rax
movq %rax, 0x10(%rsp)
movups (%rsi), %xmm0
movaps %xmm0, (%rsp)
callq 0x4470
movq %r14, %rdi
movq %rax, %rsi
callq 0x5d82
movq %rax, %r14
pushq $0x23
popq %rsi
movq %rax, %rdi
callq 0x4560
movq %rax, %r13
pushq $0x40
popq %rsi
movq %r14, %rdi
callq 0x4560
movq %rax, %r15
pushq $0x3a
popq %rsi
movq %r14, %rdi
callq 0x4560
movq %rax, %r12
testq %r13, %r13
setne %al
testq %r12, %r12
setne %cl
andb %al, %cl
testq %r15, %r15
setne %al
cmpq %r13, %r15
setb %dl
andb %al, %dl
andb %cl, %dl
cmpq %r12, %r13
setb %al
andb %dl, %al
cmpb $0x1, %al
jne 0x18f62
cmpq %r14, %r15
jbe 0x18fad
cmpb $0x23, -0x1(%r15)
jne 0x18fad
decq %r15
movq %r15, %r13
jmp 0x18f67
testq %r13, %r13
je 0x18fad
movb $0x0, (%r13)
leaq 0xf79d(%rip), %rax      # 0x28710
movq (%rax), %rax
leaq 0x40(%rsp), %rsi
movq %rax, (%rsi)
movq 0x58(%rax), %rax
movq %rax, 0x8(%rsi)
movq 0x38(%rax), %rax
movq %rax, 0x10(%rsi)
movq %rsp, %rdx
movq %r14, %rdi
callq 0x18ebb
testl %eax, %eax
je 0x18fb7
movl %eax, %r15d
movq %r14, %rdi
callq 0x4460
jmp 0x1930b
xorl %eax, %eax
xorl %r13d, %r13d
movq %r14, %r15
jmp 0x18fbd
leaq 0x1(%r13), %r15
movb $0x1, %al
xorl %ebp, %ebp
cmpq %r13, %r12
cmovaeq %r12, %rbp
testb %al, %al
cmoveq %r12, %rbp
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, 0x50(%rsi)
movaps %xmm0, 0x40(%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
testq %rbp, %rbp
movq %rbp, %rdi
cmoveq %r15, %rdi
callq 0x168cb
testb %al, %al
je 0x19028
leaq 0x24(%rsp), %rsi
movq %r15, %rdi
callq 0x15947
testb %al, %al
je 0x19039
movl 0x24(%rsp), %edx
movq %rsp, %rdi
leaq 0x40(%rsp), %rcx
movq %rbx, %rsi
callq 0xa8f6
jmp 0x192f7
movq %r14, %rdi
callq 0x4460
pushq $0x2
popq %r15
jmp 0x1930b
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0x159bc
testb %al, %al
je 0x19063
movl 0x20(%rsp), %edx
movq %rsp, %rdi
leaq 0x40(%rsp), %rcx
movq %rbx, %rsi
callq 0xb7b6
jmp 0x192f7
leaq 0x1c(%rsp), %rsi
movq %r15, %rdi
callq 0x15a4a
testb %al, %al
je 0x1908d
movl 0x1c(%rsp), %edi
movq %rsp, %rsi
leaq 0x40(%rsp), %rcx
movq %rbx, %rdx
callq 0xcddb
jmp 0x192f7
leaq 0x69d5(%rip), %rdi      # 0x1fa69
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19293
leaq 0x7180(%rip), %rdi      # 0x2022b
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x192a5
leaq 0x7178(%rip), %rdi      # 0x2023a
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x192b7
leaq 0x7166(%rip), %rdi      # 0x2023f
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x192c6
leaq 0x7156(%rip), %rdi      # 0x20246
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x192d8
leaq 0x7147(%rip), %rdi      # 0x2024e
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x192e4
leaq 0x7139(%rip), %rdi      # 0x20257
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19320
leaq 0x6b00(%rip), %rdi      # 0x1fc35
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x1935e
cmpb $0x40, (%r15)
jne 0x193ab
incq %r15
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rbx)
movaps (%rsp), %xmm0
movups %xmm0, (%rbx)
testq %rbp, %rbp
je 0x19193
movb $0x0, (%rbp)
movq %rsp, %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x18a95
testl %eax, %eax
jne 0x18f9d
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rax
movq %rax, 0x10(%rbx)
incq %rbp
movq %rbp, %r15
cmpb $0x2f, (%r15)
jne 0x191a5
movq 0x8(%rbx), %rax
movq 0x30(%rax), %rax
movq %rax, 0x10(%rbx)
leaq 0x70b3(%rip), %r12      # 0x2025f
movq %r15, %rdi
movq %r12, %rsi
callq 0x4850
movq %rax, %rbp
testq %rax, %rax
je 0x193f9
movq 0x10(%rbx), %r13
testq %r13, %r13
je 0x193f9
leaq 0x708a(%rip), %rdi      # 0x20261
movq %rbp, %rsi
callq 0x4820
testl %eax, %eax
je 0x1926e
movzbl (%rbp), %r15d
movl %r15d, %eax
subl $0x31, %eax
jne 0x191f8
movzbl 0x1(%rbp), %eax
negl %eax
testl %eax, %eax
je 0x1926e
leaq 0x7062(%rip), %rdi      # 0x20267
movq %rbp, %rsi
callq 0x4820
testl %eax, %eax
je 0x19274
subl $0x32, %r15d
jne 0x1921c
movzbl 0x1(%rbp), %r15d
negl %r15d
testl %r15d, %r15d
je 0x19274
leaq 0x7043(%rip), %rdi      # 0x2026e
movq %rbp, %rsi
callq 0x4820
testl %eax, %eax
je 0x19283
leaq 0x7037(%rip), %rdi      # 0x20275
movq %rbp, %rsi
callq 0x4820
testl %eax, %eax
je 0x19289
movq %rbp, %rdi
leaq 0x28(%rsp), %rsi
callq 0x15947
testb %al, %al
je 0x19438
movq 0x10(%rbx), %rdi
movl 0x28(%rsp), %esi
callq 0xa62f
jmp 0x19278
movq 0x30(%r13), %rax
jmp 0x19278
movq 0x38(%r13), %rax
movq %rax, 0x10(%rbx)
xorl %edi, %edi
jmp 0x191af
movq 0x40(%r13), %rax
jmp 0x19278
movq %r13, %rdi
callq 0xa4b2
jmp 0x19278
movq %rsp, %rdi
leaq 0x40(%rsp), %rdx
movq %rbx, %rsi
callq 0xa786
jmp 0x192f7
movq %rsp, %rdi
leaq 0x40(%rsp), %rdx
movq %rbx, %rsi
callq 0xa888
jmp 0x192f7
movq %rsp, %rsi
leaq 0x40(%rsp), %rcx
xorl %edi, %edi
jmp 0x19080
movq %rsp, %rdi
leaq 0x40(%rsp), %rdx
movq %rbx, %rsi
callq 0xcd73
jmp 0x192f7
movq %rsp, %rsi
leaq 0x40(%rsp), %rcx
xorl %edi, %edi
jmp 0x192ef
pushq $0x1
popq %rdi
movq %rsp, %rsi
leaq 0x40(%rsp), %rcx
movq %rbx, %rdx
callq 0xaa5d
movq %r14, %rdi
callq 0x4460
xorl %r15d, %r15d
cmpq $0x0, 0x10(%rbx)
sete %r15b
movl %r15d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28(%rsp), %r14
andl $0x0, (%r14)
xorl %r15d, %r15d
movq %r14, %rdi
xorl %esi, %esi
callq 0xfb66
movl (%r14), %edi
movq %rbx, %rsi
callq 0x19720
testb %al, %al
je 0x193f2
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x17e76
jmp 0x193ea
leaq 0xf3ab(%rip), %rax      # 0x28710
movq (%rax), %rax
leaq 0x28(%rsp), %rdi
movq %rax, (%rdi)
movq 0x58(%rax), %rax
movq %rax, 0x8(%rdi)
movq 0x38(%rax), %rax
movq %rax, 0x10(%rdi)
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
callq 0x17e76
testb %al, %al
je 0x192f7
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rbx)
movups 0x28(%rsp), %xmm0
movups %xmm0, (%rbx)
jmp 0x192f7
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x16048
movl %eax, %ebp
movq %r14, %rdi
callq 0x4460
testb %bpl, %bpl
je 0x19440
movl 0x28(%rsp), %edi
movq %rbx, %rsi
callq 0xa6ef
testb %al, %al
je 0x193f2
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x17e76
xorl %r15d, %r15d
testb %al, %al
jne 0x1930b
pushq $0x1
jmp 0x19032
movq %r14, %rdi
callq 0x4460
cmpq $0x0, 0x10(%rbx)
je 0x19423
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x17e76
xorb $0x1, %al
movzbl %al, %r15d
jmp 0x1930b
movq 0x8(%rbx), %rax
xorl %r15d, %r15d
cmpq $0x0, 0x30(%rax)
setne %r15b
jmp 0x1930b
movq %r14, %rdi
callq 0x4460
pushq $0x3
jmp 0x19032