// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0x24c64
movq -0x10(%rbp), %rdi
addq $0x1, %rdi
movq -0x20(%rbp), %rsi
callq 0x269c0
jmp 0x25118
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, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4460
movq -0xd0(%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)
cmpq $0x0, -0x48(%rbp)
je 0x24d31
movq -0x48(%rbp), %rax
movb $0x0, (%rax)
leaq 0x10a23(%rip), %rax     # 0x35700
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x68(%rbp), %rsi
callq 0x24c20
movl %eax, -0x4c(%rbp)
cmpl $0x0, %eax
jne 0x24d1b
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x24d2f
movq -0x40(%rbp), %rdi
callq 0x4450
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x25132
jmp 0x24d31
callq 0x265a0
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x21d90
testb $0x1, %al
jne 0x24d60
movq -0x40(%rbp), %rdi
callq 0x4450
movl $0x2, -0x4(%rbp)
jmp 0x25132
movq -0x10(%rbp), %rdi
leaq -0x74(%rbp), %rsi
callq 0x20bf0
testb $0x1, %al
jne 0x24d73
jmp 0x24d95
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl -0x74(%rbp), %esi
leaq -0x70(%rbp), %rdx
callq 0x9220
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2510f
movq -0x10(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x20cb0
testb $0x1, %al
jne 0x24da8
jmp 0x24dca
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl -0x78(%rbp), %esi
leaq -0x70(%rbp), %rdx
callq 0x8f20
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2510d
movq -0x10(%rbp), %rdi
leaq -0x7c(%rbp), %rsi
callq 0x20d90
testb $0x1, %al
jne 0x24ddd
jmp 0x24df6
movl -0x7c(%rbp), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x12f10
jmp 0x2510b
movq -0x10(%rbp), %rsi
leaq 0x9e46(%rip), %rdi      # 0x2ec47
callq 0x4800
cmpl $0x0, %eax
jne 0x24e21
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x9310
jmp 0x25109
movq -0x10(%rbp), %rsi
leaq 0xa5c8(%rip), %rdi      # 0x2f3f4
callq 0x4800
cmpl $0x0, %eax
jne 0x24e4e
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
xorl %edi, %edi
leaq -0x70(%rbp), %rcx
callq 0x12f10
jmp 0x25107
movq -0x10(%rbp), %rsi
leaq 0xa5a0(%rip), %rdi      # 0x2f3f9
callq 0x4800
cmpl $0x0, %eax
jne 0x24e79
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x12e80
jmp 0x25105
movq -0x10(%rbp), %rsi
leaq 0xa5b3(%rip), %rdi      # 0x2f437
callq 0x4800
cmpl $0x0, %eax
jne 0x24ef4
leaq 0x10853(%rip), %rax     # 0x356e8
cmpq $0x0, (%rax)
je 0x24eef
leaq 0x10846(%rip), %rax     # 0x356e8
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
movq $0x0, -0x98(%rbp)
movq $0x0, -0x90(%rbp)
movq -0x18(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x23a20
testb $0x1, %al
jne 0x24edc
jmp 0x24eed
leaq 0x10805(%rip), %rax     # 0x356e8
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x24eef
jmp 0x25103
movq -0x10(%rbp), %rsi
leaq 0x9f14(%rip), %rdi      # 0x2ee13
callq 0x4800
cmpl $0x0, %eax
jne 0x24f60
leaq 0x107f0(%rip), %rax     # 0x35700
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
movq $0x0, -0xb0(%rbp)
movq $0x0, -0xa8(%rbp)
movq -0x18(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x23a20
testb $0x1, %al
jne 0x24f4a
jmp 0x24f5b
leaq 0x107af(%rip), %rax     # 0x35700
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x25101
movq -0x10(%rbp), %rsi
leaq 0xa4a6(%rip), %rdi      # 0x2f411
callq 0x4800
cmpl $0x0, %eax
jne 0x24fe7
xorl %eax, %eax
movl %eax, %edi
leaq -0xbc(%rbp), %rsi
callq 0x176a0
leaq 0x1076c(%rip), %rax     # 0x356f8
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
cmpq $0x0, -0xc8(%rbp)
je 0x24fe2
movq -0xc8(%rbp), %rax
movl -0xbc(%rbp), %edi
movq 0x4c(%rax), %rsi
callq 0x6bf0
testb $0x1, %al
jne 0x24fbc
jmp 0x24fcc
movq -0xc8(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x24fe2
jmp 0x24fce
movq -0xc8(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0xc8(%rbp)
jmp 0x24f96
jmp 0x250ff
movq -0x10(%rbp), %rdi
leaq -0x7e(%rbp), %rsi
callq 0x217f0
testb $0x1, %al
jne 0x24ffa
jmp 0x25045
movzwl -0x7e(%rbp), %edi
movq -0x20(%rbp), %rsi
callq 0x26a30
testb $0x1, %al
jne 0x2500d
jmp 0x25045
movq -0x40(%rbp), %rdi
callq 0x4450
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x23a20
testb $0x1, %al
jne 0x2502d
jmp 0x25039
movl $0x0, -0x4(%rbp)
jmp 0x25132
movl $0x1, -0x4(%rbp)
jmp 0x25132
movq -0x10(%rbp), %rdi
leaq -0x84(%rbp), %rsi
callq 0x216f0
testb $0x1, %al
jne 0x2505b
jmp 0x250a8
movl -0x84(%rbp), %edi
movq -0x20(%rbp), %rsi
callq 0x26ab0
testb $0x1, %al
jne 0x25070
jmp 0x250a8
movq -0x40(%rbp), %rdi
callq 0x4450
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x23a20
testb $0x1, %al
jne 0x25090
jmp 0x2509c
movl $0x0, -0x4(%rbp)
jmp 0x25132
movl $0x1, -0x4(%rbp)
jmp 0x25132
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x269c0
testb $0x1, %al
jne 0x250bb
jmp 0x250ed
movq -0x40(%rbp), %rdi
callq 0x4450
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x23a20
testb $0x1, %al
jne 0x250db
jmp 0x250e4
movl $0x0, -0x4(%rbp)
jmp 0x25132
movl $0x1, -0x4(%rbp)
jmp 0x25132
movq -0x40(%rbp), %rdi
callq 0x4450
movl $0x3, -0x4(%rbp)
jmp 0x25132
jmp 0x25101
jmp 0x25103
jmp 0x25105
jmp 0x25107
jmp 0x25109
jmp 0x2510b
jmp 0x2510d
jmp 0x2510f
movq -0x40(%rbp), %rdi
callq 0x4450
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x2512b
movl $0x1, -0x4(%rbp)
jmp 0x25132
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nop