// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, 0x10(%rax)
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, -0x120(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4460
movq -0x120(%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 $0x40, %esi
callq 0x4550
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movl $0x3a, %esi
callq 0x4550
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x25873
cmpq $0x0, -0x58(%rbp)
je 0x25873
cmpq $0x0, -0x50(%rbp)
je 0x25873
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x25873
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
jae 0x25873
movq -0x50(%rbp), %rax
cmpq -0x10(%rbp), %rax
jbe 0x25869
movq -0x50(%rbp), %rax
movsbl -0x1(%rax), %eax
cmpl $0x23, %eax
jne 0x25869
movq -0x50(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x25871
movq $0x0, -0x48(%rbp)
jmp 0x25873
cmpq $0x0, -0x48(%rbp)
je 0x258f4
movq -0x48(%rbp), %rax
movb $0x0, (%rax)
leaq 0xfe78(%rip), %rax      # 0x35700
movq (%rax), %rax
movq %rax, -0x78(%rbp)
leaq 0xfe6a(%rip), %rax      # 0x35700
movq (%rax), %rax
movq 0x58(%rax), %rax
movq %rax, -0x70(%rbp)
leaq 0xfe58(%rip), %rax      # 0x35700
movq (%rax), %rax
movq 0x58(%rax), %rax
movq 0x38(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x78(%rbp), %rsi
callq 0x25770
movl %eax, -0x5c(%rbp)
cmpl $0x0, %eax
jne 0x258de
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x258f2
movq -0x40(%rbp), %rdi
callq 0x4450
movl -0x5c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x25fc4
jmp 0x258f4
cmpq $0x0, -0x58(%rbp)
je 0x25914
cmpq $0x0, -0x48(%rbp)
je 0x25914
movq -0x58(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x25914
movq $0x0, -0x58(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x26540
cmpq $0x0, -0x58(%rbp)
je 0x25934
movq -0x58(%rbp), %rax
movq %rax, -0x128(%rbp)
jmp 0x2593f
movq -0x10(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x22190
testb $0x1, %al
jne 0x2596b
movq -0x40(%rbp), %rdi
callq 0x4450
movl $0x2, -0x4(%rbp)
jmp 0x25fc4
movq -0x10(%rbp), %rdi
leaq -0xdc(%rbp), %rsi
callq 0x20bf0
testb $0x1, %al
jne 0x25981
jmp 0x259a0
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0xdc(%rbp), %edx
leaq -0xd8(%rbp), %rcx
callq 0xee80
jmp 0x25fa0
movq -0x10(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x20cb0
testb $0x1, %al
jne 0x259b6
jmp 0x259d5
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0xe0(%rbp), %edx
leaq -0xd8(%rbp), %rcx
callq 0x10420
jmp 0x25f9e
movq -0x10(%rbp), %rdi
leaq -0xe4(%rbp), %rsi
callq 0x20d90
testb $0x1, %al
jne 0x259eb
jmp 0x25a0a
movl -0xe4(%rbp), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0xd8(%rbp), %rcx
callq 0x12bb0
jmp 0x25f9c
movq -0x10(%rbp), %rsi
leaq 0x9232(%rip), %rdi      # 0x2ec47
callq 0x4800
cmpl $0x0, %eax
jne 0x25a38
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0xec70
jmp 0x25f9a
movq -0x10(%rbp), %rsi
leaq 0x99a2(%rip), %rdi      # 0x2f3e5
callq 0x4800
cmpl $0x0, %eax
jne 0x25a66
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0xede0
jmp 0x25f98
movq -0x10(%rbp), %rsi
leaq 0x9983(%rip), %rdi      # 0x2f3f4
callq 0x4800
cmpl $0x0, %eax
jne 0x25a96
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
xorl %edi, %edi
leaq -0xd8(%rbp), %rcx
callq 0x12bb0
jmp 0x25f96
movq -0x10(%rbp), %rsi
leaq 0x9958(%rip), %rdi      # 0x2f3f9
callq 0x4800
cmpl $0x0, %eax
jne 0x25ac4
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0x12b10
jmp 0x25f94
movq -0x10(%rbp), %rsi
leaq 0x9931(%rip), %rdi      # 0x2f400
callq 0x4800
cmpl $0x0, %eax
jne 0x25af4
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
xorl %edi, %edi
leaq -0xd8(%rbp), %rcx
callq 0xf030
jmp 0x25f92
movq -0x10(%rbp), %rsi
leaq 0x9909(%rip), %rdi      # 0x2f408
callq 0x4800
cmpl $0x0, %eax
jne 0x25b27
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl $0x1, %edi
leaq -0xd8(%rbp), %rcx
callq 0xf030
jmp 0x25f90
movq -0x10(%rbp), %rsi
leaq 0x98df(%rip), %rdi      # 0x2f411
callq 0x4800
cmpl $0x0, %eax
jne 0x25b9d
movl $0x0, -0xe8(%rbp)
leaq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x176a0
movl -0xe8(%rbp), %edi
movq -0x20(%rbp), %rsi
callq 0x265d0
testb $0x1, %al
jne 0x25b6b
jmp 0x25b91
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0x23df0
testb $0x1, %al
jne 0x25b85
jmp 0x25b91
movl $0x0, -0x4(%rbp)
jmp 0x25fc4
movl $0x1, -0x4(%rbp)
jmp 0x25fc4
movq -0x10(%rbp), %rsi
leaq 0x926b(%rip), %rdi      # 0x2ee13
callq 0x4800
cmpl $0x0, %eax
jne 0x25c3b
leaq 0xfb43(%rip), %rax      # 0x35700
movq (%rax), %rax
movq %rax, -0x100(%rbp)
leaq 0xfb32(%rip), %rax      # 0x35700
movq (%rax), %rax
movq 0x58(%rax), %rax
movq %rax, -0xf8(%rbp)
leaq 0xfb1d(%rip), %rax      # 0x35700
movq (%rax), %rax
movq 0x58(%rax), %rax
movq 0x38(%rax), %rax
movq %rax, -0xf0(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x100(%rbp), %rdi
leaq -0xd8(%rbp), %rdx
callq 0x23df0
testb $0x1, %al
jne 0x25c12
jmp 0x25c36
movq -0x20(%rbp), %rax
movq -0x100(%rbp), %rcx
movq %rcx, (%rax)
movq -0xf8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0xf0(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x25f8c
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x40, %eax
jne 0x25f1a
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
cmpq $0x0, -0x58(%rbp)
je 0x25cda
movq -0x58(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x25140
movl %eax, -0x104(%rbp)
cmpl $0x0, %eax
jne 0x25cc1
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x38(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x25cd8
movq -0x40(%rbp), %rdi
callq 0x4450
movl -0x104(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x25fc4
jmp 0x25cda
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x25cfa
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x30(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rdi
leaq 0x9714(%rip), %rsi      # 0x2f419
callq 0x4830
movq %rax, -0x110(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x110(%rbp)
movb %al, -0x129(%rbp)
je 0x25d35
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
setne %al
movb %al, -0x129(%rbp)
movb -0x129(%rbp), %al
testb $0x1, %al
jne 0x25d44
jmp 0x25eab
movq -0x110(%rbp), %rsi
leaq 0x96c9(%rip), %rdi      # 0x2f41b
callq 0x4800
cmpl $0x0, %eax
je 0x25d74
movq -0x110(%rbp), %rsi
leaq 0x8ec7(%rip), %rdi      # 0x2ec31
callq 0x4800
cmpl $0x0, %eax
jne 0x25d8d
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x25e8f
movq -0x110(%rbp), %rsi
leaq 0x9686(%rip), %rdi      # 0x2f421
callq 0x4800
cmpl $0x0, %eax
je 0x25dbd
movq -0x110(%rbp), %rsi
leaq 0x8e83(%rip), %rdi      # 0x2ec36
callq 0x4800
cmpl $0x0, %eax
jne 0x25dd6
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x38(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x25e8d
movq -0x110(%rbp), %rsi
leaq 0x9644(%rip), %rdi      # 0x2f428
callq 0x4800
cmpl $0x0, %eax
jne 0x25e07
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x40(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x25e8b
movq -0x110(%rbp), %rsi
leaq 0x961a(%rip), %rdi      # 0x2f42f
callq 0x4800
cmpl $0x0, %eax
jne 0x25e39
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xe580
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x25e89
movq -0x110(%rbp), %rdi
leaq -0x114(%rbp), %rsi
callq 0x20bf0
testb $0x1, %al
jne 0x25e52
jmp 0x25e72
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x114(%rbp), %esi
callq 0xe9c0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x25e87
movq -0x40(%rbp), %rdi
callq 0x4450
movl $0x3, -0x4(%rbp)
jmp 0x25fc4
jmp 0x25e89
jmp 0x25e8b
jmp 0x25e8d
jmp 0x25e8f
xorl %eax, %eax
movl %eax, %edi
leaq 0x957f(%rip), %rsi      # 0x2f419
callq 0x4830
movq %rax, -0x110(%rbp)
jmp 0x25d11
movq -0x40(%rbp), %rdi
callq 0x4450
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x25ef1
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0x23df0
testb $0x1, %al
jne 0x25ed9
jmp 0x25ee5
movl $0x0, -0x4(%rbp)
jmp 0x25fc4
movl $0x1, -0x4(%rbp)
jmp 0x25fc4
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x30(%rax)
je 0x25f0c
movl $0x1, -0x4(%rbp)
jmp 0x25fc4
jmp 0x25f0e
movl $0x0, -0x4(%rbp)
jmp 0x25fc4
movq -0x10(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x216f0
testb $0x1, %al
jne 0x25f30
jmp 0x25f7a
movq -0x40(%rbp), %rdi
callq 0x4450
movl -0x118(%rbp), %edi
movq -0x20(%rbp), %rsi
callq 0xeb40
testb $0x1, %al
jne 0x25f4e
jmp 0x25f71
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0x23df0
testb $0x1, %al
jne 0x25f68
jmp 0x25f71
movl $0x0, -0x4(%rbp)
jmp 0x25fc4
movl $0x1, -0x4(%rbp)
jmp 0x25fc4
movq -0x40(%rbp), %rdi
callq 0x4450
movl $0x3, -0x4(%rbp)
jmp 0x25fc4
jmp 0x25f8e
jmp 0x25f90
jmp 0x25f92
jmp 0x25f94
jmp 0x25f96
jmp 0x25f98
jmp 0x25f9a
jmp 0x25f9c
jmp 0x25f9e
jmp 0x25fa0
movq -0x40(%rbp), %rdi
callq 0x4450
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x25fbd
movl $0x1, -0x4(%rbp)
jmp 0x25fc4
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq