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

	if (*desc == '%') {
		locate_monitor(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, '#');

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

	monitor_select_t sel = make_monitor_select();

	if (!parse_monitor_modifiers(desc, &sel)) {
		free(desc_copy);
		return SELECTOR_BAD_MODIFIERS;
	}

	direction_t dir;
	cycle_dir_t cyc;
	history_dir_t hdi;
	uint16_t idx;
	uint32_t id;
	if (parse_direction(desc, &dir)) {
		dst->monitor = nearest_monitor(ref->monitor, dir, &sel);
	} else if (parse_cycle_direction(desc, &cyc)) {
		dst->monitor = closest_monitor(ref->monitor, cyc, &sel);
	} else if (parse_history_direction(desc, &hdi)) {
		history_find_monitor(hdi, ref, dst, &sel);
	} else if (streq("any", desc)) {
		find_any_monitor(ref, dst, &sel);
	} else if (streq("last", desc)) {
		history_find_monitor(HISTORY_OLDER, ref, dst, &sel);
	} else if (streq("newest", desc)) {
		history_find_newest_monitor(ref, dst, &sel);
	} else if (streq("primary", desc)) {
		if (pri_mon != NULL) {
			coordinates_t loc = {pri_mon, NULL, NULL};
			if (monitor_matches(&loc, ref, &sel)) {
				dst->monitor = pri_mon;
			}
		}
	} else if (streq("focused", desc)) {
		coordinates_t loc = {mon, NULL, NULL};
		if (monitor_matches(&loc, ref, &sel)) {
			dst->monitor = mon;
		}
	} else if (streq("pointed", desc)) {
		xcb_point_t pointer;
		query_pointer(NULL, &pointer);
		for (monitor_t *m = mon_head; m != NULL; m = m->next) {
			if (is_inside(pointer, m->rectangle)) {
				dst->monitor = m;
				break;
			}
		}
	} else if (parse_index(desc, &idx) && monitor_from_index(idx, dst)) {
		free(desc_copy);
		if (monitor_matches(dst, ref, &sel)) {
			return SELECTOR_OK;
		} else {
			return SELECTOR_INVALID;
		}
	} else if (parse_id(desc, &id) && monitor_from_id(id, dst)) {
		free(desc_copy);
		if (monitor_matches(dst, ref, &sel)) {
			return SELECTOR_OK;
		} else {
			return SELECTOR_INVALID;
		}
	} else {
		if (locate_monitor(desc, dst)) {
			free(desc_copy);
			if (monitor_matches(dst, ref, &sel)) {
				return SELECTOR_OK;
			} else {
				return SELECTOR_INVALID;
			}
		} else {
			free(desc_copy);
			return SELECTOR_BAD_DESCRIPTOR;
		}
	}

	free(desc_copy);

end:
	if (dst->monitor == NULL) {
		return SELECTOR_INVALID;
	}

	return SELECTOR_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdx, %rbx
andq $0x0, (%rdx)
movq %rdi, %r14
cmpb $0x25, (%rdi)
jne 0x18799
incq %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x19936
jmp 0x18889
movq 0x10(%rsi), %rax
movq %rax, 0x30(%rsp)
movups (%rsi), %xmm0
movaps %xmm0, 0x20(%rsp)
movq %r14, %rdi
callq 0x4470
movq %r14, %rdi
movq %rax, %rsi
callq 0x5d82
movq %rax, %r14
pushq $0x23
popq %rsi
movq %rax, %rdi
callq 0x4560
movq %r14, %r15
testq %rax, %rax
je 0x18818
movq %rax, %r12
movb $0x0, (%rax)
leaq 0xff30(%rip), %rax      # 0x28710
movq (%rax), %rax
leaq 0x38(%rsp), %rsi
movq %rax, (%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsi)
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x1876b
testl %eax, %eax
je 0x18812
movl %eax, %ebp
movq %r14, %rdi
callq 0x4460
jmp 0x18893
incq %r12
movq %r12, %r15
movq %rsp, %rsi
andq $0x0, (%rsi)
movq %r15, %rdi
callq 0x16554
testb %al, %al
je 0x1884f
leaq 0x1c(%rsp), %rsi
movq %r15, %rdi
callq 0x15947
testb %al, %al
je 0x1885c
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %esi
movq %rsp, %rdx
callq 0x73e6
jmp 0x1887e
movq %r14, %rdi
callq 0x4460
pushq $0x2
popq %rbp
jmp 0x18893
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x159bc
testb %al, %al
je 0x188a2
movq 0x20(%rsp), %rdi
movl 0x18(%rsp), %esi
movq %rsp, %rdx
callq 0x724d
movq %rax, (%rbx)
movq %r14, %rdi
callq 0x4460
xorl %ebp, %ebp
cmpq $0x0, (%rbx)
sete %bpl
movl %ebp, %eax
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14(%rsp), %rsi
movq %r15, %rdi
callq 0x15a4a
testb %al, %al
je 0x188c9
movl 0x14(%rsp), %edi
leaq 0x20(%rsp), %rsi
movq %rsp, %rcx
movq %rbx, %rdx
callq 0xcff8
jmp 0x18881
leaq 0x7199(%rip), %rdi      # 0x1fa69
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x189ab
leaq 0x7953(%rip), %rdi      # 0x2023a
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x189c0
leaq 0x7941(%rip), %rdi      # 0x2023f
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x189cf
leaq 0x7968(%rip), %rdi      # 0x2027d
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x189e4
leaq 0x7309(%rip), %rdi      # 0x1fc35
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x189f8
leaq 0x7914(%rip), %rdi      # 0x20257
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x18a29
leaq 0xe(%rsp), %rsi
movq %r15, %rdi
callq 0x160f1
testb %al, %al
je 0x18975
movzwl 0xe(%rsp), %edi
movq %rbx, %rsi
callq 0x19974
testb %al, %al
jne 0x1899e
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x16048
testb %al, %al
je 0x18a5f
movl 0x10(%rsp), %edi
movq %rbx, %rsi
callq 0x199a1
testb %al, %al
je 0x18a5f
movq %r14, %rdi
callq 0x4460
jmp 0x18a79
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
movq %rbx, %rsi
callq 0x74aa
jmp 0x18881
leaq 0x20(%rsp), %rsi
movq %rsp, %rcx
xorl %edi, %edi
jmp 0x188bf
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
movq %rbx, %rsi
callq 0xcf9f
jmp 0x18881
leaq 0xfd0d(%rip), %rax      # 0x286f8
movq (%rax), %r15
testq %r15, %r15
jne 0x18a02
jmp 0x18881
leaq 0xfd11(%rip), %rax      # 0x28710
movq (%rax), %r15
leaq 0x38(%rsp), %rdi
movq %r15, (%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rdi)
movq %rsp, %rdx
callq 0x17c07
testb %al, %al
je 0x18881
movq %r15, (%rbx)
jmp 0x18881
leaq 0x38(%rsp), %rsi
xorl %edi, %edi
callq 0xfb66
leaq 0xfccc(%rip), %r15      # 0x28708
movq (%r15), %r15
testq %r15, %r15
je 0x18881
movl 0x38(%rsp), %edi
movq 0x4c(%r15), %rsi
callq 0x6020
testb %al, %al
jne 0x18a21
addq $0x78, %r15
jmp 0x18a3c
movq %r15, %rdi
movq %rbx, %rsi
callq 0x19936
movl %eax, %ebp
movq %r14, %rdi
callq 0x4460
testb %bpl, %bpl
je 0x18a8e
movq %rsp, %rdx
movq %rbx, %rdi
callq 0x17c07
xorb $0x1, %al
movzbl %al, %ebp
jmp 0x18893
pushq $0x3
jmp 0x18859