// File: /workspace/github_c_makefile_star2_O3/baskerville[P]bspwm/src/messages.c
// Function: cmd_monitor
void cmd_monitor(char **args, int num, FILE *rsp)
{
	if (num < 1) {
		fail(rsp, "monitor: Missing arguments.\n");
		return;
	}

	coordinates_t ref = {mon, NULL, NULL};
	coordinates_t trg = ref;

	if ((*args)[0] != OPT_CHR) {
		int ret;
		if ((ret = monitor_from_desc(*args, &ref, &trg)) == SELECTOR_OK) {
			num--, args++;
		} else {
			handle_failure(ret, "monitor", *args, rsp);
			return;
		}
	}

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

	while (num > 0) {
		if (streq("-f", *args) || streq("--focus", *args)) {
			coordinates_t dst = trg;
			if (num > 1 && *(args + 1)[0] != OPT_CHR) {
				num--, args++;
				int ret;
				if ((ret = monitor_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
					handle_failure(ret, "monitor -f", *args, rsp);
					fail(rsp, "");
					return;
				}
			}
			focus_node(dst.monitor, NULL, NULL);
		} else if (streq("-s", *args) || streq("--swap", *args)) {
			num--, args++;
			if (num < 1) {
				fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
				return;
			}
			coordinates_t dst;
			int ret;
			if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
				if (!swap_monitors(trg.monitor, dst.monitor)) {
					fail(rsp, "");
					return;
				}
			} else {
				handle_failure(ret, "monitor -s", *args, rsp);
				return;
			}
		} else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
			num--, args++;
			if (num < 1) {
				fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
				return;
			}
			desktop_t *d = trg.monitor->desk_head;
			while (num > 0 && d != NULL) {
				rename_desktop(trg.monitor, d, *args);
				d = d->next;
				num--, args++;
			}
			put_status(SBSC_MASK_REPORT);
			while (num > 0) {
				add_desktop(trg.monitor, make_desktop(*args, XCB_NONE));
				num--, args++;
			}
			while (d != NULL) {
				desktop_t *next = d->next;
				if (d == mon->desk) {
					focus_node(trg.monitor, d->prev, d->prev->focus);
				}
				merge_desktops(trg.monitor, d, mon, mon->desk);
				remove_desktop(trg.monitor, d);
				d = next;
			}
		} else if (streq("-a", *args) || streq("--add-desktops", *args)) {
			num--, args++;
			if (num < 1) {
				fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
				return;
			}
			while (num > 0) {
				add_desktop(trg.monitor, make_desktop(*args, XCB_NONE));
				num--, args++;
			}
		} else if (streq("-r", *args) || streq("--remove", *args)) {
			if (num > 1) {
				fail(rsp, "monitor %s: Trailing commands.\n", *args);
				return;
			}
			if (mon_head == mon_tail) {
				fail(rsp, "");
				return;
			}
			remove_monitor(trg.monitor);
			return;
		} else if (streq("-o", *args) || streq("--reorder-desktops", *args)) {
			num--, args++;
			if (num < 1) {
				fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
				return;
			}
			desktop_t *d = trg.monitor->desk_head;
			while (d != NULL && num > 0) {
				desktop_t *next = d->next;
				coordinates_t dst;
				if (locate_desktop(*args, &dst) && dst.monitor == trg.monitor) {
					swap_desktops(trg.monitor, d, dst.monitor, dst.desktop, false);
					if (next == dst.desktop) {
						next = d;
					}
				}
				d = next;
				num--, args++;
			}
		} else if (streq("-g", *args) || streq("--rectangle", *args)) {
			num--, args++;
			if (num < 1) {
				fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
				return;
			}
			xcb_rectangle_t r;
			if (parse_rectangle(*args, &r)) {
				update_root(trg.monitor, &r);
			} else {
				fail(rsp, "monitor %s: Invalid argument: '%s'.\n", *(args - 1), *args);
				return;
			}
		} else if (streq("-n", *args) || streq("--rename", *args)) {
			num--, args++;
			if (num < 1) {
				fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
				return;
			}
			rename_monitor(trg.monitor, *args);
		} else {
			fail(rsp, "monitor: Unknown command: '%s'.\n", *args);
			return;
		}
		num--, args++;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %r14
testl %esi, %esi
jle 0x13915
movl %esi, %r15d
movq %rdi, %rbx
leaq 0x161a8(%rip), %rax     # 0x29710
movq (%rax), %rax
movq %rax, 0x50(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x58(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x18(%rsp)
movq (%rdi), %rdi
cmpb $0x2d, (%rdi)
jne 0x13934
movq %r14, 0x8(%rsp)
leaq 0x30(%rsp), %r13
movq (%rbx), %r12
movzbl (%r12), %ebp
leal -0x2d(%rbp), %r14d
negl %r14d
movl %r14d, %eax
cmpl $0x2d, %ebp
jne 0x135d6
movzbl 0x1(%r12), %eax
subl $0x66, %eax
jne 0x135d4
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x137b2
leaq 0xc6de(%rip), %rdi      # 0x1fcc3
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x137b2
movl %r14d, %eax
cmpb $0x2d, %bpl
jne 0x13611
movzbl 0x1(%r12), %eax
subl $0x73, %eax
jne 0x1360f
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x13809
leaq 0xc72b(%rip), %rdi      # 0x1fd4b
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x13809
movl %r14d, %eax
cmpb $0x2d, %bpl
jne 0x1364c
movzbl 0x1(%r12), %eax
subl $0x64, %eax
jne 0x1364a
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x13982
leaq 0xca79(%rip), %rdi      # 0x200d4
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x13982
movl %r14d, %eax
cmpb $0x2d, %bpl
jne 0x13687
movzbl 0x1(%r12), %eax
subl $0x61, %eax
jne 0x13685
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x139d5
leaq 0xca4f(%rip), %rdi      # 0x200e5
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x139d5
movl %r14d, %eax
cmpb $0x2d, %bpl
jne 0x136c2
movzbl 0x1(%r12), %eax
subl $0x72, %eax
jne 0x136c0
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x139f7
leaq 0xc947(%rip), %rdi      # 0x20018
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x139f7
movl %r14d, %eax
cmpb $0x2d, %bpl
jne 0x136fd
movzbl 0x1(%r12), %eax
subl $0x6f, %eax
jne 0x136fb
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x13862
leaq 0xca08(%rip), %rdi      # 0x20114
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x13862
movl %r14d, %eax
cmpb $0x2d, %bpl
jne 0x13738
movzbl 0x1(%r12), %eax
subl $0x67, %eax
jne 0x13736
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x138d9
leaq 0xc9e0(%rip), %rdi      # 0x20127
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x138d9
cmpb $0x2d, %bpl
jne 0x13772
movzbl 0x1(%r12), %r14d
subl $0x6e, %r14d
jne 0x1376f
movzbl 0x2(%r12), %r14d
negl %r14d
testl %r14d, %r14d
je 0x1378e
leaq 0xc891(%rip), %rdi      # 0x2000f
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
jne 0x13b81
cmpl $0x1, %r15d
je 0x139df
decl %r15d
movq 0x10(%rsp), %rdi
movq 0x8(%rbx), %rsi
addq $0x8, %rbx
callq 0x7067
jmp 0x13849
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
cmpl $0x1, %r15d
jne 0x137d4
movl $0x1, %r15d
jmp 0x137f9
movq 0x8(%rbx), %rdi
cmpb $0x2d, (%rdi)
je 0x137f9
addq $0x8, %rbx
leaq 0x50(%rsp), %rsi
movq %r13, %rdx
callq 0x19b1a
testl %eax, %eax
jne 0x13a47
decl %r15d
movq 0x30(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xa308
jmp 0x13849
cmpl $0x1, %r15d
je 0x139df
addq $0x8, %rbx
movq (%rbx), %rdi
leaq 0x50(%rsp), %rsi
movq %r13, %rdx
callq 0x19b1a
testl %eax, %eax
jne 0x13a31
movq 0x10(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x6f2a
testb %al, %al
je 0x13a23
decl %r15d
movl %r15d, %eax
leal -0x1(%rax), %r15d
addq $0x8, %rbx
cmpl $0x1, %eax
jg 0x135ac
jmp 0x13a71
cmpl $0x1, %r15d
je 0x139df
movq 0x10(%rsp), %rax
movq 0x60(%rax), %r12
addq $0x8, %rbx
decl %r15d
testq %r12, %r12
je 0x13849
movq 0x48(%r12), %r14
movq (%rbx), %rdi
movq %r13, %rsi
callq 0x1ac03
testb %al, %al
je 0x138bb
movq 0x30(%rsp), %rdx
movq 0x10(%rsp), %rdi
cmpq %rdi, %rdx
jne 0x138bb
movq 0x38(%rsp), %rcx
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x83ba
cmpq 0x38(%rsp), %r14
je 0x138be
movq %r14, %r12
addq $0x8, %rbx
leal -0x1(%r15), %eax
testq %r12, %r12
je 0x1384c
cmpl $0x1, %r15d
movl %eax, %r15d
ja 0x13881
jmp 0x1384c
cmpl $0x1, %r15d
je 0x139df
leaq 0x8(%rbx), %r14
movq (%r14), %rdi
movq %r13, %rsi
callq 0x172df
testb %al, %al
je 0x13b62
decl %r15d
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x6b6f
movl %r15d, %eax
movq %r14, %rbx
jmp 0x1384c
leaq 0xc746(%rip), %rsi      # 0x20062
movq %r14, %rdi
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x117fd
leaq 0x50(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x19b1a
testl %eax, %eax
je 0x13960
movq (%rbx), %rdx
leaq 0xc885(%rip), %rsi      # 0x201d6
movl %eax, %edi
movq %r14, %rcx
callq 0x151d0
jmp 0x13a71
decl %r15d
je 0x13973
movq %r14, 0x8(%rsp)
addq $0x8, %rbx
jmp 0x135a7
leaq 0xc705(%rip), %rsi      # 0x2007f
movq %r14, %rdi
jmp 0x13a6a
cmpl $0x1, %r15d
je 0x139df
movq 0x10(%rsp), %rax
addq $0x8, %rbx
movq 0x60(%rax), %r14
decl %r15d
testq %r14, %r14
je 0x13abe
movl %r15d, %r12d
movq 0x10(%rsp), %rdi
movq (%rbx), %rdx
movq %r14, %rsi
callq 0x81d4
addq $0x8, %rbx
movq 0x48(%r14), %r14
leal -0x1(%r12), %r15d
cmpl $0x2, %r12d
jb 0x13ac1
testq %r14, %r14
jne 0x139a1
jmp 0x13ac1
cmpl $0x1, %r15d
jne 0x13a80
leaq 0xc6c0(%rip), %rsi      # 0x200a6
movq 0x8(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x117fd
jmp 0x13a71
cmpl $0x1, %r15d
jne 0x13ab2
leaq 0x15d00(%rip), %rax     # 0x29708
movq (%rax), %rax
leaq 0x15cee(%rip), %rcx     # 0x29700
cmpq (%rcx), %rax
je 0x13a23
movq 0x10(%rsp), %rdi
callq 0x72d2
jmp 0x13a71
leaq 0xdb2e(%rip), %rsi      # 0x21558
movq 0x8(%rsp), %rdi
jmp 0x13a6a
movq (%rbx), %rdx
leaq 0xc68e(%rip), %rsi      # 0x200c9
movl %eax, %edi
movq 0x8(%rsp), %rcx
jmp 0x13956
movq (%rbx), %rdx
leaq 0xc64a(%rip), %rsi      # 0x2009b
movl %eax, %edi
movq 0x8(%rsp), %rbx
movq %rbx, %rcx
callq 0x151d0
leaq 0xdaf1(%rip), %rsi      # 0x21558
movq %rbx, %rdi
xorl %eax, %eax
callq 0x117fd
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jle 0x13a71
addq $0x8, %rbx
incl %r15d
movq 0x10(%rsp), %r14
movq (%rbx), %rdi
xorl %esi, %esi
callq 0x813c
movq %r14, %rdi
movq %rax, %rsi
callq 0x822e
addq $0x8, %rbx
decl %r15d
cmpl $0x2, %r15d
ja 0x13a89
jmp 0x13a71
leaq 0xc63b(%rip), %rsi      # 0x200f4
jmp 0x139e6
xorl %r14d, %r14d
movl $0x1, %edi
xorl %eax, %eax
callq 0x1e6b8
testl %r15d, %r15d
je 0x13afb
movl %r15d, %r12d
xorl %r13d, %r13d
movq 0x10(%rsp), %r15
movq (%rbx,%r13,8), %rdi
xorl %esi, %esi
callq 0x813c
movq %r15, %rdi
movq %rax, %rsi
callq 0x822e
incq %r13
cmpl %r13d, %r12d
jne 0x13ad8
testq %r14, %r14
je 0x13a71
movq 0x48(%r14), %rbx
leaq 0x15c01(%rip), %rax     # 0x29710
movq (%rax), %rdx
movq 0x58(%rdx), %rcx
cmpq %rcx, %r14
jne 0x13b3b
movq 0x10(%rsp), %rdi
movq 0x40(%r14), %rsi
movq 0x38(%rsi), %rdx
callq 0xa308
leaq 0x15bdc(%rip), %rax     # 0x29710
movq (%rax), %rdx
movq 0x58(%rdx), %rcx
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x838e
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x82cc
movq %rbx, %r14
testq %rbx, %rbx
jne 0x13b04
jmp 0x13a71
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
leaq 0xc5c3(%rip), %rsi      # 0x20133
movq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x117fd
jmp 0x13a71
leaq 0xc5d0(%rip), %rsi      # 0x20158
jmp 0x139e6