// File: /workspace/github_c_makefile_star2_O1/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 0x19c57
leaq 0xfae1(%rip), %rax      # 0x29708
movq (%rax), %r15
testq %r15, %r15
je 0x19d5e
incq %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x4820
testl %eax, %eax
je 0x19cd2
movq 0x78(%r15), %r15
testq %r15, %r15
jne 0x19c36
jmp 0x19d5e
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 0x5e6e
movq %rax, %r14
movq %rax, %rdi
movl $0x23, %esi
callq 0x4560
movq %r14, %r15
testq %rax, %rax
je 0x19ce8
movq %rax, %r12
movb $0x0, (%rax)
leaq 0xfa70(%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 0x19c02
movl %eax, %ebp
testl %eax, %eax
je 0x19cda
movq %r14, %rdi
callq 0x4460
movq %r14, %r15
jmp 0x19ce0
movq %r15, (%rbx)
jmp 0x19d5e
incq %r12
movq %r12, %r15
testl %ebp, %ebp
jne 0x19d68
movq %rsp, %rsi
movq $0x0, (%rsi)
movq %r15, %rdi
callq 0x1786e
testb %al, %al
je 0x19d22
leaq 0x1c(%rsp), %rsi
movq %r15, %rdi
callq 0x16be3
testb %al, %al
je 0x19d31
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %esi
movq %rsp, %rdx
callq 0x7642
jmp 0x19d53
movq %r14, %rdi
callq 0x4460
movl $0x2, %ebp
jmp 0x19d68
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x16c60
testb %al, %al
je 0x19d77
movq 0x20(%rsp), %rdi
movl 0x18(%rsp), %esi
movq %rsp, %rdx
callq 0x746d
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 0x16cf2
testb %al, %al
je 0x19d9e
movl 0x14(%rsp), %edi
leaq 0x20(%rsp), %rsi
movq %rsp, %rcx
movq %rbx, %rdx
callq 0xdb24
jmp 0x19d56
leaq 0x6d10(%rip), %rdi      # 0x20ab5
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19ec2
leaq 0x74ca(%rip), %rdi      # 0x21286
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19ed7
leaq 0x74b8(%rip), %rdi      # 0x2128b
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19ee6
leaq 0x74df(%rip), %rdi      # 0x212c9
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19efb
leaq 0x6e80(%rip), %rdi      # 0x20c81
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19f0f
leaq 0x748b(%rip), %rdi      # 0x212a3
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x19f40
leaq 0xe(%rsp), %rsi
movq %r15, %rdi
callq 0x173f4
testb %al, %al
je 0x19e79
leaq 0xf8c8(%rip), %rax      # 0x29708
movq (%rax), %rax
testq %rax, %rax
setne %cl
je 0x19e71
movzwl 0xe(%rsp), %edx
cmpl $0x1, %edx
je 0x19e67
decl %edx
movq 0x78(%rax), %rax
testq %rax, %rax
setne %cl
je 0x19e71
decl %edx
jne 0x19e57
movq %rax, (%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rbx)
testb %cl, %cl
jne 0x19f84
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x17346
testb %al, %al
je 0x19f8e
leaq 0xf873(%rip), %rax      # 0x29708
movq (%rax), %rcx
testq %rcx, %rcx
setne %al
je 0x19f80
movl 0x10(%rsp), %edx
cmpl %edx, 0x20(%rcx)
je 0x19f76
movq 0x78(%rcx), %rcx
testq %rcx, %rcx
setne %al
jne 0x19ea8
jmp 0x19f80
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
movq %rbx, %rsi
callq 0x7739
jmp 0x19d56
leaq 0x20(%rsp), %rsi
movq %rsp, %rcx
xorl %edi, %edi
jmp 0x19d94
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
movq %rbx, %rsi
callq 0xdac5
jmp 0x19d56
leaq 0xf7f6(%rip), %rax      # 0x296f8
movq (%rax), %r15
testq %r15, %r15
jne 0x19f19
jmp 0x19d56
leaq 0xf7fa(%rip), %rax      # 0x29710
movq (%rax), %r15
leaq 0x38(%rsp), %rdi
movq %r15, (%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rdi)
movq %rsp, %rdx
callq 0x1905e
testb %al, %al
je 0x19d56
movq %r15, (%rbx)
jmp 0x19d56
leaq 0x38(%rsp), %rsi
xorl %edi, %edi
callq 0x10928
leaq 0xf7b5(%rip), %rax      # 0x29708
movq (%rax), %r15
testq %r15, %r15
je 0x19d56
movl 0x38(%rsp), %edi
movq 0x4c(%r15), %rsi
callq 0x6134
testb %al, %al
jne 0x19f38
movq 0x78(%r15), %r15
jmp 0x19f56
movq %rcx, (%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rbx)
testb %al, %al
je 0x19f8e
movq %r14, %rdi
callq 0x4460
jmp 0x19fb2
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1aff9
movl %eax, %r15d
movq %r14, %rdi
callq 0x4460
movl $0x3, %ebp
testb %r15b, %r15b
je 0x19d68
movq %rsp, %rdx
movq %rbx, %rdi
callq 0x1905e
xorb $0x1, %al
movzbl %al, %ebp
jmp 0x19d68