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

	coordinates_t ref = {mon, mon->desk, NULL};
	coordinates_t trg = ref;

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

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

	bool changed = false;

	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 = desktop_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
					handle_failure(ret, "desktop -f", *args, rsp);
					break;
				}
			}
			focus_node(dst.monitor, dst.desktop, NULL);
		} else if (streq("-a", *args) || streq("--activate", *args)) {
			coordinates_t dst = trg;
			if (num > 1 && *(args + 1)[0] != OPT_CHR) {
				num--, args++;
				int ret;
				if ((ret = desktop_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
					handle_failure(ret, "desktop -a", *args, rsp);
					break;
				}
			}
			if (activate_desktop(dst.monitor, dst.desktop)) {
				activate_node(dst.monitor, dst.desktop, NULL);
			} else {
				fail(rsp, "");
				break;
			}
		} else if (streq("-m", *args) || streq("--to-monitor", *args)) {
			num--, args++;
			if (num < 1) {
				fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
				break;
			}
			if (trg.monitor->desk_head == trg.monitor->desk_tail) {
				fail(rsp, "");
				break;
			}
			coordinates_t dst;
			int ret;
			if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
				bool follow = false;
				if (num > 1 && streq("--follow", *(args+1))) {
					follow = true;
					num--, args++;
				}
				if (transfer_desktop(trg.monitor, dst.monitor, trg.desktop, follow)) {
					trg.monitor = dst.monitor;
				} else {
					fail(rsp, "");
					break;
				}
			} else {
				handle_failure(ret, "desktop -m", *args, rsp);
				break;
			}
		} else if (streq("-s", *args) || streq("--swap", *args)) {
			num--, args++;
			if (num < 1) {
				fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
				break;
			}
			coordinates_t dst;
			int ret;
			if ((ret = desktop_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
				bool follow = false;
				if (num > 1 && streq("--follow", *(args+1))) {
					follow = true;
					num--, args++;
				}
				if (swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop, follow)) {
					trg.monitor = dst.monitor;
				} else {
					fail(rsp, "");
					break;
				}
			} else {
				handle_failure(ret, "desktop -s", *args, rsp);
				break;
			}
		} else if (streq("-b", *args) || streq("--bubble", *args)) {
			num--, args++;
			if (num < 1) {
				fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
				break;
			}
			cycle_dir_t cyc;
			if (parse_cycle_direction(*args, &cyc)) {
				desktop_t *d = trg.desktop;
				if (cyc == CYCLE_PREV) {
					if (d->prev == NULL) {
						while (d->next != NULL) {
							swap_desktops(trg.monitor, d, trg.monitor, d->next, false);
						}
					} else {
						swap_desktops(trg.monitor, d, trg.monitor, d->prev, false);
					}
				} else {
					if (d->next == NULL) {
						while (d->prev != NULL) {
							swap_desktops(trg.monitor, d, trg.monitor, d->prev, false);
						}
					} else {
						swap_desktops(trg.monitor, d, trg.monitor, d->next, false);
					}
				}
			} else {
				fail(rsp, "desktop %s: Invalid argument: '%s'.\n", *(args - 1), *args);
				break;
			}
		} else if (streq("-l", *args) || streq("--layout", *args)) {
			num--, args++;
			if (num < 1) {
				fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
				break;
			}
			bool ret;
			layout_t lyt;
			cycle_dir_t cyc;
			if (parse_cycle_direction(*args, &cyc)) {
				ret = set_layout(trg.monitor, trg.desktop, (trg.desktop->user_layout + 1) % 2, true);
			} else if (parse_layout(*args, &lyt)) {
				ret = set_layout(trg.monitor, trg.desktop, lyt, true);
			} else {
				fail(rsp, "desktop %s: Invalid argument: '%s'.\n", *(args - 1), *args);
				break;
			}
			if (!ret) {
				fail(rsp, "");
				break;
			}
		} else if (streq("-n", *args) || streq("--rename", *args)) {
			num--, args++;
			if (num < 1) {
				fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
				break;
			}
			rename_desktop(trg.monitor, trg.desktop, *args);
		} else if (streq("-r", *args) || streq("--remove", *args)) {
			if (num > 1) {
				fail(rsp, "desktop %s: Trailing commands.\n", *args);
				break;
			}
			if (trg.monitor->desk_head != trg.monitor->desk_tail) {
				desktop_t *fallback = trg.desktop->prev == NULL ?
				                      trg.desktop->next :
				                      trg.desktop->prev;
				merge_desktops(trg.monitor, trg.desktop, trg.monitor, fallback);
				remove_desktop(trg.monitor, trg.desktop);
				return;
			} else {
				fail(rsp, "");
				break;
			}
		} else {
			fail(rsp, "desktop: Unknown command: '%s'.\n", *args);
			break;
		}
		num--, args++;
	}

	if (changed) {
		arrange(trg.monitor, trg.desktop);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %rbx
testl %esi, %esi
jle 0x133ab
movl %esi, %r14d
movq %rdi, %r12
leaq 0x16888(%rip), %rax     # 0x29710
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x58(%rax), %rax
movq %rax, 0x50(%rsp)
xorl %eax, %eax
movq %rax, 0x58(%rsp)
movq %rax, 0x20(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x18(%rsp)
movq (%rdi), %rdi
cmpb $0x2d, (%rdi)
jne 0x133ca
movq %rbx, 0x8(%rsp)
leaq 0xcdf2(%rip), %r13      # 0x1fcc3
movq (%r12), %r15
movzbl (%r15), %ebx
leal -0x2d(%rbx), %ebp
negl %ebp
movl %ebp, %eax
cmpl $0x2d, %ebx
jne 0x12ef6
movzbl 0x1(%r15), %eax
subl $0x66, %eax
jne 0x12ef4
movzbl 0x2(%r15), %eax
negl %eax
testl %eax, %eax
je 0x13081
movq %r13, %rdi
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x13081
movl %ebp, %eax
cmpb $0x2d, %bl
jne 0x12f29
movzbl 0x1(%r15), %eax
subl $0x61, %eax
jne 0x12f27
movzbl 0x2(%r15), %eax
negl %eax
testl %eax, %eax
je 0x130de
leaq 0xcd9b(%rip), %rdi      # 0x1fcd3
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x130de
movl %ebp, %eax
cmpb $0x2d, %bl
jne 0x12f60
movzbl 0x1(%r15), %eax
subl $0x6d, %eax
jne 0x12f5e
movzbl 0x2(%r15), %eax
negl %eax
testl %eax, %eax
je 0x13170
leaq 0xcdb5(%rip), %rdi      # 0x1fd24
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x13170
movl %ebp, %eax
cmpb $0x2d, %bl
jne 0x12f97
movzbl 0x1(%r15), %eax
subl $0x73, %eax
jne 0x12f95
movzbl 0x2(%r15), %eax
negl %eax
testl %eax, %eax
je 0x131f2
leaq 0xcda5(%rip), %rdi      # 0x1fd4b
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x131f2
movl %ebp, %eax
cmpb $0x2d, %bl
jne 0x12fce
movzbl 0x1(%r15), %eax
subl $0x62, %eax
jne 0x12fcc
movzbl 0x2(%r15), %eax
negl %eax
testl %eax, %eax
je 0x1328e
leaq 0xcffb(%rip), %rdi      # 0x1ffd8
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x1328e
movl %ebp, %eax
cmpb $0x2d, %bl
jne 0x13005
movzbl 0x1(%r15), %eax
subl $0x6c, %eax
jne 0x13003
movzbl 0x2(%r15), %eax
negl %eax
testl %eax, %eax
je 0x1333c
leaq 0xcff2(%rip), %rdi      # 0x20006
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x1333c
movl %ebp, %eax
cmpb $0x2d, %bl
jne 0x1303c
movzbl 0x1(%r15), %eax
subl $0x6e, %eax
jne 0x1303a
movzbl 0x2(%r15), %eax
negl %eax
testl %eax, %eax
je 0x13057
leaq 0xcfc8(%rip), %rdi      # 0x2000f
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
jne 0x134a9
cmpl $0x1, %r14d
je 0x13426
decl %r14d
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x8(%r12), %rdx
addq $0x8, %r12
callq 0x81d4
jmp 0x13150
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
cmpl $0x1, %r14d
jne 0x130a3
movl $0x1, %r14d
jmp 0x130cb
movq 0x8(%r12), %rdi
cmpb $0x2d, (%rdi)
je 0x130cb
addq $0x8, %r12
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x19eaf
testl %eax, %eax
jne 0x1343e
decl %r14d
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
xorl %edx, %edx
callq 0xa308
jmp 0x13150
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
cmpl $0x1, %r14d
jne 0x13100
movl $0x1, %r14d
jmp 0x13128
movq 0x8(%r12), %rdi
cmpb $0x2d, (%rdi)
je 0x13128
addq $0x8, %r12
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x19eaf
testl %eax, %eax
jne 0x13458
decl %r14d
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x7ab4
testb %al, %al
je 0x13405
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
xorl %edx, %edx
callq 0x9a3d
movq %r12, %rbp
leal -0x1(%r14), %eax
addq $0x8, %rbp
movq %rbp, %r12
cmpl $0x1, %r14d
movl %eax, %r14d
jg 0x12ed1
jmp 0x1347c
cmpl $0x1, %r14d
je 0x13426
movq 0x10(%rsp), %rax
movq 0x60(%rax), %rcx
cmpq 0x68(%rax), %rcx
je 0x13405
leaq 0x8(%r12), %rbp
movq (%rbp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x19b1a
testl %eax, %eax
jne 0x1344b
cmpl $0x3, %r14d
jb 0x131d1
movq 0x10(%r12), %rsi
leaq 0xcb54(%rip), %rdi      # 0x1fd13
callq 0x4820
testl %eax, %eax
je 0x1327c
decl %r14d
jmp 0x131d7
movl $0x1, %r14d
xorl %eax, %eax
movq 0x30(%rsp), %rsi
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
movzbl %al, %ecx
callq 0x7e58
jmp 0x13265
cmpl $0x1, %r14d
je 0x13426
leaq 0x8(%r12), %rbp
movq (%rbp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x19eaf
testl %eax, %eax
jne 0x13465
cmpl $0x3, %r14d
jb 0x13240
movq 0x10(%r12), %rsi
leaq 0xcae5(%rip), %rdi      # 0x1fd13
callq 0x4820
testl %eax, %eax
je 0x1332a
decl %r14d
jmp 0x13246
movl $0x1, %r14d
xorl %eax, %eax
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
movzbl %al, %r8d
callq 0x83ba
testb %al, %al
je 0x13405
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x13153
addq $0x10, %r12
addl $-0x2, %r14d
movb $0x1, %al
movq %r12, %rbp
jmp 0x131d9
cmpl $0x1, %r14d
je 0x13426
leaq 0x8(%r12), %rbp
movq (%rbp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x16b33
testb %al, %al
je 0x1348b
movq 0x18(%rsp), %r15
cmpl $0x1, 0x30(%rsp)
jne 0x132eb
movq 0x40(%r15), %rcx
testq %rcx, %rcx
jne 0x132f4
jmp 0x132dd
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %rdi, %rdx
xorl %r8d, %r8d
callq 0x83ba
movq 0x48(%r15), %rcx
testq %rcx, %rcx
jne 0x132ca
jmp 0x133a3
movq 0x48(%r15), %rcx
testq %rcx, %rcx
je 0x1331f
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %rdi, %rdx
xorl %r8d, %r8d
callq 0x83ba
jmp 0x133a3
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %rdi, %rdx
xorl %r8d, %r8d
callq 0x83ba
movq 0x40(%r15), %rcx
testq %rcx, %rcx
jne 0x1330c
jmp 0x133a3
addq $0x10, %r12
addl $-0x2, %r14d
movb $0x1, %al
movq %r12, %rbp
jmp 0x13248
cmpl $0x1, %r14d
je 0x13426
leaq 0x8(%r12), %rbp
movq (%rbp), %rdi
leaq 0x64(%rsp), %rsi
callq 0x16b33
testb %al, %al
je 0x13371
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x28(%rsi), %edx
notl %edx
andl $0x1, %edx
jmp 0x13395
movq (%rbp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x1698f
testb %al, %al
je 0x1348b
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x30(%rsp), %edx
movl $0x1, %ecx
callq 0x7d6e
testb %al, %al
je 0x13405
decl %r14d
jmp 0x13153
leaq 0xcb9e(%rip), %rsi      # 0x1ff50
movq %rbx, %rdi
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x117fd
leaq 0x48(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x19eaf
testl %eax, %eax
je 0x133f2
movq (%r12), %rdx
leaq 0xce01(%rip), %rsi      # 0x201e9
movl %eax, %edi
movq %rbx, %rcx
jmp 0x13477
decl %r14d
je 0x13413
movq %rbx, 0x8(%rsp)
addq $0x8, %r12
jmp 0x12eca
leaq 0xe14c(%rip), %rsi      # 0x21558
movq 0x8(%rsp), %rdi
jmp 0x1341d
leaq 0xcb53(%rip), %rsi      # 0x1ff6d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x117fd
jmp 0x1347c
leaq 0xcb72(%rip), %rsi      # 0x1ff9f
movq 0x8(%rsp), %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x117fd
jmp 0x1347c
movq (%r12), %rdx
leaq 0xcb40(%rip), %rsi      # 0x1ff89
jmp 0x13470
movq (%rbp), %rdx
leaq 0xcb6c(%rip), %rsi      # 0x1ffc2
jmp 0x13470
movq (%r12), %rdx
leaq 0xcb31(%rip), %rsi      # 0x1ff94
jmp 0x13470
movq (%rbp), %rdx
leaq 0xcb5d(%rip), %rsi      # 0x1ffcd
movl %eax, %edi
movq 0x8(%rsp), %rcx
callq 0x151d0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r12), %rdx
movq 0x8(%r12), %rcx
leaq 0xcb46(%rip), %rsi      # 0x1ffe1
movq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x117fd
jmp 0x1347c
cmpb $0x2d, %bl
movq 0x8(%rsp), %rbx
jne 0x134c4
movzbl 0x1(%r15), %ebp
subl $0x72, %ebp
jne 0x134c2
movzbl 0x2(%r15), %ebp
negl %ebp
testl %ebp, %ebp
je 0x134e4
leaq 0xcb49(%rip), %rdi      # 0x20018
movq %r15, %rsi
callq 0x4820
testl %eax, %eax
je 0x134e4
leaq 0xcb5f(%rip), %rsi      # 0x20041
jmp 0x1352e
cmpl $0x1, %r14d
jne 0x13527
movq 0x10(%rsp), %rdi
movq 0x60(%rdi), %rax
cmpq 0x68(%rdi), %rax
je 0x13536
movq 0x18(%rsp), %rsi
movq 0x40(%rsi), %rcx
testq %rcx, %rcx
jne 0x1350b
movq 0x48(%rsi), %rcx
movq %rdi, %rdx
callq 0x838e
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x82cc
jmp 0x1347c
leaq 0xcaf3(%rip), %rsi      # 0x20021
movq %rbx, %rdi
jmp 0x13432
leaq 0xe01b(%rip), %rsi      # 0x21558
jmp 0x1341a