// File: /workspace/github_c_makefile_star2_O3/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
movq %rdi, %r14
movq $0x0, (%rdx)
cmpb $0x25, (%rdi)
jne 0x19b74
leaq 0xfbc9(%rip), %rax      # 0x29708
movq (%rax), %r15
movl $0x1, %ebp
testq %r15, %r15
je 0x19c7f
incq %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x4820
testl %eax, %eax
je 0x19bef
movq 0x78(%r15), %r15
testq %r15, %r15
jne 0x19b53
jmp 0x19c7f
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 0x5e2f
movq %rax, %r14
movq %rax, %rdi
movl $0x23, %esi
callq 0x4560
movq %r14, %r15
testq %rax, %rax
je 0x19bff
movq %rax, %r12
movb $0x0, (%rax)
leaq 0xfb53(%rip), %rax      # 0x29710
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 0x19b1a
testl %eax, %eax
je 0x19bf9
movl %eax, %ebp
movq %r14, %rdi
callq 0x4460
jmp 0x19c7f
movq %r15, (%rbx)
xorl %ebp, %ebp
jmp 0x19c7f
incq %r12
movq %r12, %r15
movq %rsp, %rsi
movq $0x0, (%rsi)
movq %r15, %rdi
callq 0x1773f
testb %al, %al
je 0x19c39
leaq 0x1c(%rsp), %rsi
movq %r15, %rdi
callq 0x16ab6
testb %al, %al
je 0x19c48
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %esi
movq %rsp, %rdx
callq 0x7560
jmp 0x19c6a
movq %r14, %rdi
callq 0x4460
movl $0x2, %ebp
jmp 0x19c7f
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x16b33
testb %al, %al
je 0x19c8e
movq 0x20(%rsp), %rdi
movl 0x18(%rsp), %esi
movq %rsp, %rdx
callq 0x7392
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 0x16bc5
testb %al, %al
je 0x19cb5
movl 0x14(%rsp), %edi
leaq 0x20(%rsp), %rsi
movq %rsp, %rcx
movq %rbx, %rdx
callq 0xdb98
jmp 0x19c6d
leaq 0x6dad(%rip), %rdi      # 0x20a69
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19dd4
leaq 0x7567(%rip), %rdi      # 0x2123a
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19de9
leaq 0x7555(%rip), %rdi      # 0x2123f
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19df8
leaq 0x757c(%rip), %rdi      # 0x2127d
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19e0d
leaq 0x6f1d(%rip), %rdi      # 0x20c35
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19e21
leaq 0x7528(%rip), %rdi      # 0x21257
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19e52
leaq 0xe(%rsp), %rsi
movq %r15, %rdi
callq 0x172c5
testb %al, %al
je 0x19d75
leaq 0xf9b1(%rip), %rax      # 0x29708
movq (%rax), %rax
testq %rax, %rax
je 0x19d75
movzwl 0xe(%rsp), %ecx
decl %ecx
je 0x19e88
movq 0x78(%rax), %rax
testq %rax, %rax
jne 0x19d64
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x17217
testb %al, %al
je 0x19dab
leaq 0xf97b(%rip), %rax      # 0x29708
movq (%rax), %rax
testq %rax, %rax
je 0x19dab
movl 0x10(%rsp), %ecx
cmpl %ecx, 0x20(%rax)
je 0x19e88
movq 0x78(%rax), %rax
testq %rax, %rax
jne 0x19d99
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1adaa
movl %eax, %r15d
movq %r14, %rdi
callq 0x4460
movl $0x3, %ebp
testb %r15b, %r15b
je 0x19c7f
jmp 0x19e9a
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
movq %rbx, %rsi
callq 0x7657
jmp 0x19c6d
leaq 0x20(%rsp), %rsi
movq %rsp, %rcx
xorl %edi, %edi
jmp 0x19cab
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
movq %rbx, %rsi
callq 0xdb3c
jmp 0x19c6d
leaq 0xf8e4(%rip), %rax      # 0x296f8
movq (%rax), %r15
testq %r15, %r15
jne 0x19e2b
jmp 0x19c6d
leaq 0xf8e8(%rip), %rax      # 0x29710
movq (%rax), %r15
leaq 0x38(%rsp), %rdi
movq %r15, (%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rdi)
movq %rsp, %rdx
callq 0x18f6e
testb %al, %al
je 0x19c6d
movq %r15, (%rbx)
jmp 0x19c6d
leaq 0x38(%rsp), %rsi
xorl %edi, %edi
callq 0x1095f
leaq 0xf8a3(%rip), %rax      # 0x29708
movq (%rax), %r15
testq %r15, %r15
je 0x19c6d
movl 0x38(%rsp), %edi
movq 0x4c(%r15), %rsi
callq 0x60d4
testb %al, %al
jne 0x19e4a
movq 0x78(%r15), %r15
jmp 0x19e68
movq %rax, (%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rbx)
movq %r14, %rdi
callq 0x4460
movq %rsp, %rdx
movq %rbx, %rdi
callq 0x18f6e
xorb $0x1, %al
movzbl %al, %ebp
jmp 0x19c7f