// File: /workspace/github_c_makefile_star2_O1/baskerville[P]bspwm/src/messages.c
// Function: cmd_query
void cmd_query(char **args, int num, FILE *rsp)
{
	coordinates_t monitor_ref = {mon, NULL, NULL};
	coordinates_t desktop_ref = {mon, mon->desk, NULL};
	coordinates_t node_ref = {mon, mon->desk, mon->desk->focus};
	coordinates_t trg = {NULL, NULL, NULL};
	monitor_select_t *monitor_sel = NULL;
	desktop_select_t *desktop_sel = NULL;
	node_select_t *node_sel = NULL;
	domain_t dom = DOMAIN_TREE;
	bool print_ids = true;
	uint8_t d = 0;

	if (num < 1) {
		fail(rsp, "query: Missing arguments.\n");
		return;
	}

	while (num > 0) {
		if (streq("-T", *args) || streq("--tree", *args)) {
			dom = DOMAIN_TREE, d++;
		} else if (streq("-M", *args) || streq("--monitors", *args)) {
			dom = DOMAIN_MONITOR, d++;
			if (num > 1 && *(args + 1)[0] != OPT_CHR) {
				num--, args++;
				int ret;
				coordinates_t tmp = monitor_ref;
				monitor_ref.desktop = NULL;
				monitor_ref.node = NULL;
				if ((ret = monitor_from_desc(*args, &tmp, &monitor_ref)) != SELECTOR_OK) {
					handle_failure(ret, "query -M", *args, rsp);
					goto end;
				}
			}
		} else if (streq("-D", *args) || streq("--desktops", *args)) {
			dom = DOMAIN_DESKTOP, d++;
			if (num > 1 && *(args + 1)[0] != OPT_CHR) {
				num--, args++;
				int ret;
				coordinates_t tmp = desktop_ref;
				desktop_ref.node = NULL;
				if ((ret = desktop_from_desc(*args, &tmp, &desktop_ref)) != SELECTOR_OK) {
					handle_failure(ret, "query -D", *args, rsp);
					goto end;
				}
			}
		} else if (streq("-N", *args) || streq("--nodes", *args)) {
			dom = DOMAIN_NODE, d++;
			if (num > 1 && *(args + 1)[0] != OPT_CHR) {
				num--, args++;
				int ret;
				coordinates_t tmp = node_ref;
				if ((ret = node_from_desc(*args, &tmp, &node_ref)) != SELECTOR_OK) {
					handle_failure(ret, "query -N", *args, rsp);
					goto end;
				}
			}
		} else if (streq("-m", *args) || streq("--monitor", *args)) {
			if (num > 1 && *(args + 1)[0] != OPT_CHR) {
				num--, args++;
				int ret;
				if ((*args)[0] == '.') {
					free(monitor_sel);
					monitor_sel = malloc(sizeof(monitor_select_t));
					*monitor_sel = make_monitor_select();
					char *desc = copy_string(*args, strlen(*args));
					if (!parse_monitor_modifiers(desc, monitor_sel)) {
						handle_failure(SELECTOR_BAD_MODIFIERS, "query -m", *args, rsp);
						free(desc);
						goto end;
					}
					free(desc);
				} else if ((ret = monitor_from_desc(*args, &monitor_ref, &trg)) != SELECTOR_OK) {
					handle_failure(ret, "query -m", *args, rsp);
					goto end;
				}
			} else {
				trg = monitor_ref;
			}
		} else if (streq("-d", *args) || streq("--desktop", *args)) {
			if (num > 1 && *(args + 1)[0] != OPT_CHR) {
				num--, args++;
				int ret;
				if ((*args)[0] == '.') {
					free(desktop_sel);
					desktop_sel = malloc(sizeof(desktop_select_t));
					*desktop_sel = make_desktop_select();
					char *desc = copy_string(*args, strlen(*args));
					if (!parse_desktop_modifiers(desc, desktop_sel)) {
						handle_failure(SELECTOR_BAD_MODIFIERS, "query -d", *args, rsp);
						free(desc);
						goto end;
					}
					free(desc);
				} else if ((ret = desktop_from_desc(*args, &desktop_ref, &trg)) != SELECTOR_OK) {
					handle_failure(ret, "query -d", *args, rsp);
					goto end;
				}
			} else {
				trg = desktop_ref;
			}
		} else if (streq("-n", *args) || streq("--node", *args)) {
			if (num > 1 && *(args + 1)[0] != OPT_CHR) {
				num--, args++;
				int ret;
				if ((*args)[0] == '.') {
					free(node_sel);
					node_sel = malloc(sizeof(node_select_t));
					*node_sel = make_node_select();
					char *desc = copy_string(*args, strlen(*args));
					if (!parse_node_modifiers(desc, node_sel)) {
						handle_failure(SELECTOR_BAD_MODIFIERS, "query -n", *args, rsp);
						free(desc);
						goto end;
					}
					free(desc);
				} else if ((ret = node_from_desc(*args, &node_ref, &trg)) != SELECTOR_OK) {
					handle_failure(ret, "query -n", *args, rsp);
					goto end;
				}
			} else {
				trg = node_ref;
				if (trg.node == NULL) {
					fail(rsp, "");
					goto end;
				}
			}
		} else if (streq("--names", *args)) {
			print_ids = false;
		} else {
			fail(rsp, "query: Unknown option: '%s'.\n", *args);
			goto end;
		}
		num--, args++;
	}

	if (d < 1) {
		fail(rsp, "query: No commands given.\n");
		goto end;
	}

	if (d > 1) {
		fail(rsp, "query: Multiple commands given.\n");
		goto end;
	}

	if (dom == DOMAIN_TREE && trg.monitor == NULL) {
		fail(rsp, "query -T: No options given.\n");
		goto end;
	}

	if (!print_ids && (dom == DOMAIN_NODE || dom == DOMAIN_TREE)) {
		fail(rsp, "query -%c: --names only applies to -M and -D.\n", dom == DOMAIN_NODE ? 'N' : 'T');
		goto end;
	}

	if ((dom == DOMAIN_MONITOR && (desktop_sel != NULL || node_sel != NULL)) ||
	    (dom == DOMAIN_DESKTOP && node_sel != NULL)) {
		fail(rsp, "query -%c: Incompatible descriptor-free constraints.\n", dom == DOMAIN_MONITOR ? 'M' : 'D');
		goto end;
	}

	if (dom == DOMAIN_NODE) {
		if (query_node_ids(&monitor_ref, &desktop_ref, &node_ref, &trg, monitor_sel, desktop_sel, node_sel, rsp) < 1) {
			fail(rsp, "");
		}
	} else if (dom == DOMAIN_DESKTOP) {
		if (query_desktop_ids(&monitor_ref, &desktop_ref, &trg, monitor_sel, desktop_sel, print_ids ? fprint_desktop_id : fprint_desktop_name, rsp) < 1) {
			fail(rsp, "");
		}
	} else if (dom == DOMAIN_MONITOR) {
		if (query_monitor_ids(&monitor_ref, &trg, monitor_sel, print_ids ? fprint_monitor_id : fprint_monitor_name, rsp) < 1) {
			fail(rsp, "");
		}
	} else {
		if (trg.node != NULL) {
			query_node(trg.node, rsp);
		} else if (trg.desktop != NULL) {
			query_desktop(trg.desktop, rsp);
		} else  {
			query_monitor(trg.monitor, rsp);
		}
		fprintf(rsp, "\n");
	}

end:
	free(monitor_sel);
	free(desktop_sel);
	free(node_sel);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
leaq 0x15a23(%rip), %rax     # 0x29710
movq (%rax), %rax
movq %rax, 0x60(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x68(%rsp)
movq %rax, 0x48(%rsp)
movq 0x58(%rax), %rcx
movq %rcx, 0x50(%rsp)
xorl %r15d, %r15d
movq %r15, 0x58(%rsp)
movq %rax, 0x78(%rsp)
movq %rcx, 0x80(%rsp)
movq 0x38(%rcx), %rax
movq %rax, 0x88(%rsp)
movq %r15, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
testl %esi, %esi
jle 0x14342
movl %esi, %ebp
movq %rdi, %r13
movq %rdx, (%rsp)
movb $0x1, %al
movl %eax, 0x2c(%rsp)
leaq 0xc483(%rip), %rbx      # 0x201d7
movq $0x0, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r14d, %r14d
movq (%r13), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x13ed8
leaq 0xc44a(%rip), %rdi      # 0x201da
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x13ed8
leaq 0xc44b(%rip), %rdi      # 0x201f2
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x13ee3
leaq 0xc423(%rip), %rdi      # 0x201e1
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x13ee3
leaq 0xc431(%rip), %rdi      # 0x20206
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x13f4e
leaq 0xc409(%rip), %rdi      # 0x201f5
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x13f4e
leaq 0xc414(%rip), %rdi      # 0x20217
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x13fb3
leaq 0xc3ef(%rip), %rdi      # 0x20209
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x13fb3
leaq 0xbf15(%rip), %rdi      # 0x1fd46
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x1401c
leaq 0xc3d2(%rip), %rdi      # 0x2021a
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x1401c
leaq 0xbed2(%rip), %rdi      # 0x1fd31
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x1403c
leaq 0xc3b7(%rip), %rdi      # 0x2022d
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x1403c
leaq 0xbecb(%rip), %rdi      # 0x1fd58
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x140d0
leaq 0xc39c(%rip), %rdi      # 0x20240
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x140d0
leaq 0xc395(%rip), %rdi      # 0x20250
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
jne 0x145c3
movl $0x0, 0x2c(%rsp)
jmp 0x14314
incb %r14b
xorl %r15d, %r15d
jmp 0x14314
incb %r14b
movl $0x1, %r15d
cmpl $0x1, %ebp
je 0x13fc1
movq 0x8(%r13), %rax
cmpb $0x2d, (%rax)
je 0x14314
addq $0x8, %r13
movq 0x70(%rsp), %rax
movq %rax, 0xa0(%rsp)
movups 0x60(%rsp), %xmm0
movaps %xmm0, 0x90(%rsp)
xorps %xmm0, %xmm0
leaq 0x68(%rsp), %rax
movups %xmm0, (%rax)
movq (%r13), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x19c02
testl %eax, %eax
je 0x14312
jmp 0x14434
incb %r14b
movl $0x2, %r15d
cmpl $0x1, %ebp
je 0x13fc1
movq 0x8(%r13), %rax
cmpb $0x2d, (%rax)
je 0x14314
addq $0x8, %r13
movq 0x58(%rsp), %rax
movq %rax, 0xa0(%rsp)
movups 0x48(%rsp), %xmm0
movaps %xmm0, 0x90(%rsp)
movq $0x0, 0x58(%rsp)
movq (%r13), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x19fc7
testl %eax, %eax
je 0x14312
jmp 0x1447a
incb %r14b
movl $0x3, %r15d
cmpl $0x1, %ebp
jne 0x13fcb
movl $0x1, %ebp
jmp 0x14314
movq 0x8(%r13), %rax
cmpb $0x2d, (%rax)
je 0x14314
addq $0x8, %r13
movq 0x88(%rsp), %rax
movq %rax, 0xa0(%rsp)
movups 0x78(%rsp), %xmm0
movaps %xmm0, 0x90(%rsp)
movq (%r13), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0x1a436
testl %eax, %eax
je 0x14312
jmp 0x144bf
cmpl $0x1, %ebp
je 0x1402b
movq 0x8(%r13), %rdi
movb (%rdi), %al
cmpb $0x2d, %al
jne 0x14068
movq 0x70(%rsp), %rax
movq %rax, 0x40(%rsp)
movups 0x60(%rsp), %xmm0
jmp 0x1405e
cmpl $0x1, %ebp
je 0x1404f
movq 0x8(%r13), %rdi
movb (%rdi), %al
cmpb $0x2d, %al
jne 0x14131
movq 0x58(%rsp), %rax
movq %rax, 0x40(%rsp)
movups 0x48(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
jmp 0x14314
addq $0x8, %r13
cmpb $0x2e, %al
jne 0x14108
movq 0x8(%rsp), %rdi
callq 0x4460
movl $0x8, %edi
callq 0x4290
movq %rax, %r12
movq %rax, 0x8(%rsp)
callq 0x1ad68
movq %rax, (%r12)
movq (%r13), %r12
movq %r12, %rdi
callq 0x4470
movq %r12, %rdi
movq %rax, %rsi
callq 0x5e6e
movq %rax, %r12
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x1786e
testb %al, %al
je 0x141d2
movq %r12, %rdi
jmp 0x141c5
cmpl $0x1, %ebp
je 0x140e3
movq 0x8(%r13), %rdi
movb (%rdi), %al
cmpb $0x2d, %al
jne 0x1421a
movq 0x88(%rsp), %rax
movq %rax, 0x40(%rsp)
movups 0x78(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
testq %rax, %rax
jne 0x14314
jmp 0x145b7
leaq 0x60(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x19c02
testl %eax, %eax
je 0x141ca
movq (%r13), %rdx
movl %eax, %edi
leaq 0xc0f8(%rip), %rsi      # 0x20224
jmp 0x142fd
addq $0x8, %r13
cmpb $0x2e, %al
jne 0x141f5
movq 0x18(%rsp), %rdi
callq 0x4460
movl $0x24, %edi
callq 0x4290
movq %rax, %r12
leaq 0x90(%rsp), %rdi
callq 0x1ad53
movl 0xb0(%rsp), %eax
movl %eax, 0x20(%r12)
movups 0x90(%rsp), %xmm0
movups 0xa0(%rsp), %xmm1
movups %xmm1, 0x10(%r12)
movups %xmm0, (%r12)
movq (%r13), %rdi
movq %rdi, 0x18(%rsp)
callq 0x4470
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x5e6e
movq %rax, 0x20(%rsp)
movq %rax, %rdi
movq %r12, 0x18(%rsp)
movq %r12, %rsi
callq 0x17945
testb %al, %al
je 0x142ad
movq 0x20(%rsp), %rdi
callq 0x4460
movb $0x1, %r12b
jmp 0x14309
movq (%r13), %rcx
movq %r12, 0x20(%rsp)
xorl %r12d, %r12d
movq (%rsp), %rdi
leaq 0xc821(%rip), %rsi      # 0x20a0a
leaq 0xc034(%rip), %rdx      # 0x20224
jmp 0x142c6
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x19fc7
testl %eax, %eax
je 0x141ca
movq (%r13), %rdx
movl %eax, %edi
leaq 0xc022(%rip), %rsi      # 0x20237
jmp 0x142fd
addq $0x8, %r13
cmpb $0x2e, %al
jne 0x142d9
movq 0x10(%rsp), %rdi
callq 0x4460
movl $0x60, %edi
callq 0x4290
movq %rax, 0x10(%rsp)
leaq 0x90(%rsp), %r12
movq %r12, %rdi
callq 0x1ad35
movl $0x18, %ecx
movq 0x10(%rsp), %rdi
movq %r12, %rsi
rep  movsl (%rsi), %es:(%rdi)
movq (%r13), %r12
movq %r12, %rdi
callq 0x4470
movq %r12, %rdi
movq %rax, %rsi
callq 0x5e6e
movq %rax, %r12
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x17bf5
testb %al, %al
jne 0x140c8
movq (%r13), %rcx
movq %r12, 0x20(%rsp)
xorl %r12d, %r12d
movq (%rsp), %rdi
leaq 0xc766(%rip), %rsi      # 0x20a0a
leaq 0xbf9c(%rip), %rdx      # 0x20247
jmp 0x142c6
movq (%r13), %rcx
xorl %r12d, %r12d
movq (%rsp), %rdi
leaq 0xc74b(%rip), %rsi      # 0x20a0a
leaq 0xbf71(%rip), %rdx      # 0x20237
xorl %eax, %eax
callq 0x11852
movq 0x20(%rsp), %rdi
callq 0x4460
jmp 0x14309
leaq 0x78(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x1a436
testl %eax, %eax
je 0x141ca
movq (%r13), %rdx
movl %eax, %edi
leaq 0xbf4a(%rip), %rsi      # 0x20247
movq (%rsp), %rcx
callq 0x1528e
xorl %r12d, %r12d
testb %r12b, %r12b
je 0x144d5
decl %ebp
leal -0x1(%rbp), %eax
addq $0x8, %r13
cmpl $0x1, %ebp
movl %eax, %ebp
jg 0x13d72
cmpb $0x1, %r14b
je 0x14364
movzbl %r14b, %eax
testl %eax, %eax
movq 0x8(%rsp), %r15
jne 0x14393
leaq 0xbf36(%rip), %rsi      # 0x20276
jmp 0x1439a
leaq 0xbe73(%rip), %rsi      # 0x201bc
movq %rdx, %rdi
xorl %eax, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11852
testl %r15d, %r15d
sete %al
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x143b4
leaq 0xbf2f(%rip), %rsi      # 0x202b2
movq (%rsp), %rdi
xorl %eax, %eax
callq 0x11852
jmp 0x144d5
leaq 0xbef7(%rip), %rsi      # 0x20291
movq (%rsp), %rdi
xorl %eax, %eax
callq 0x11852
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
jmp 0x144e4
movl 0x2c(%rsp), %edx
testb $0x1, %dl
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
jne 0x143ec
cmpl $0x3, %r15d
je 0x143d2
testl %r15d, %r15d
jne 0x143ec
cmpl $0x3, %r15d
movl $0x4e, %eax
movl $0x54, %edx
cmovel %eax, %edx
leaq 0xbee5(%rip), %rsi      # 0x202cf
jmp 0x14424
cmpl $0x1, %r15d
jne 0x143fa
movq %r14, %rax
orq %rbx, %rax
jne 0x1440e
cmpl $0x2, %r15d
sete %al
testq %rbx, %rbx
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x14444
xorl %eax, %eax
cmpl $0x1, %r15d
sete %al
leal (%rax,%rax,8), %edx
addl $0x44, %edx
leaq 0xbeda(%rip), %rsi      # 0x202fe
movq (%rsp), %rdi
xorl %eax, %eax
callq 0x11852
jmp 0x144df
movq (%r13), %rdx
leaq 0xbdad(%rip), %rsi      # 0x201ec
jmp 0x144ca
cmpl $0x3, %r15d
jne 0x14487
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x78(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movq 0x8(%rsp), %r15
movq %r15, %r8
movq %r14, %r9
movq (%rsp), %r12
pushq %r12
pushq %rbx
callq 0x18f4d
jmp 0x1453f
movq (%r13), %rdx
leaq 0xbd7b(%rip), %rsi      # 0x20200
jmp 0x144ca
cmpl $0x2, %r15d
jne 0x1449b
testb $0x1, %dl
je 0x1450e
leaq 0x5412(%rip), %r9       # 0x198ab
jmp 0x14515
cmpl $0x1, %r15d
jne 0x1455a
testb $0x1, %dl
movq 0x8(%rsp), %r15
je 0x1457a
leaq 0x53c3(%rip), %rcx      # 0x1987d
jmp 0x14581
movq (%r13), %rdx
leaq 0xbd47(%rip), %rsi      # 0x20211
movl %eax, %edi
movq (%rsp), %rcx
callq 0x1528e
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
movq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x4460
movq %r14, %rdi
callq 0x4460
movq %rbx, %rdi
callq 0x4460
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x53ad(%rip), %r9       # 0x198c2
movq 0x8(%rsp), %r15
subq $0x8, %rsp
leaq 0x68(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq %r15, %rcx
movq %r14, %r8
movq 0x8(%rsp), %r12
pushq %r12
callq 0x196f9
addq $0x10, %rsp
testl %eax, %eax
jg 0x144e4
leaq 0xd056(%rip), %rsi      # 0x215a4
movq %r12, %rdi
xorl %eax, %eax
callq 0x11852
jmp 0x144e4
movq 0x40(%rsp), %rax
testq %rax, %rax
movq 0x8(%rsp), %r15
je 0x1459c
movq %rax, %rdi
movq (%rsp), %r12
movq %r12, %rsi
callq 0x18954
jmp 0x145e9
leaq 0x5313(%rip), %rcx      # 0x19894
leaq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq %r15, %rdx
movq (%rsp), %r12
movq %r12, %r8
callq 0x197e8
jmp 0x14543
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x145dd
movq %rax, %rdi
movq (%rsp), %r12
movq %r12, %rsi
callq 0x187fa
jmp 0x145e9
leaq 0xcfe6(%rip), %rsi      # 0x215a4
jmp 0x14383
leaq 0xbc8e(%rip), %rsi      # 0x20258
movq (%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x11852
jmp 0x144d5
movq (%rsp), %r12
movq %r12, %rsi
callq 0x18440
movl $0xa, %edi
movq %r12, %rsi
callq 0x4420
jmp 0x144e4