// File: /workspace/github_c_makefile_star2_O2/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 0x123c9
movl %esi, %ebp
movq %rdi, %r15
leaq 0x16857(%rip), %rax     # 0x28710
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x58(%rax), %rax
movq %rax, 0x50(%rsp)
andq $0x0, 0x58(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %rax
andq $0x0, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq (%rdi), %rdi
cmpb $0x2d, (%rdi)
jne 0x123e8
movq %rbx, 0x8(%rsp)
leaq 0xcdc1(%rip), %r13      # 0x1ecc3
testl %ebp, %ebp
jle 0x12496
movq (%r15), %r12
movzbl (%r12), %r14d
leal -0x2d(%r14), %ebx
negl %ebx
movl %ebx, %eax
cmpl $0x2d, %r14d
jne 0x11f33
movzbl 0x1(%r12), %eax
subl $0x66, %eax
jne 0x11f31
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x120cd
movq %r13, %rdi
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x120cd
movl %ebx, %eax
cmpb $0x2d, %r14b
jne 0x11f69
movzbl 0x1(%r12), %eax
subl $0x61, %eax
jne 0x11f67
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x12124
leaq 0xcd5b(%rip), %rdi      # 0x1ecd3
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x12124
movl %ebx, %eax
cmpb $0x2d, %r14b
jne 0x11fa3
movzbl 0x1(%r12), %eax
subl $0x6d, %eax
jne 0x11fa1
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x121a1
leaq 0xcd72(%rip), %rdi      # 0x1ed24
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x121a1
movl %ebx, %eax
cmpb $0x2d, %r14b
jne 0x11fdd
movzbl 0x1(%r12), %eax
subl $0x73, %eax
jne 0x11fdb
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x12202
leaq 0xcd5f(%rip), %rdi      # 0x1ed4b
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x12202
movl %ebx, %eax
cmpb $0x2d, %r14b
jne 0x12017
movzbl 0x1(%r12), %eax
subl $0x62, %eax
jne 0x12015
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x12282
leaq 0xcfb2(%rip), %rdi      # 0x1efd8
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x12282
movl %ebx, %eax
cmpb $0x2d, %r14b
jne 0x12051
movzbl 0x1(%r12), %eax
subl $0x6c, %eax
jne 0x1204f
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x1235f
leaq 0xcfa6(%rip), %rdi      # 0x1f006
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x1235f
movl %ebx, %eax
cmpb $0x2d, %r14b
jne 0x1208b
movzbl 0x1(%r12), %eax
subl $0x6e, %eax
jne 0x12089
movzbl 0x2(%r12), %eax
negl %eax
testl %eax, %eax
je 0x120a6
leaq 0xcf79(%rip), %rdi      # 0x1f00f
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
jne 0x124c1
cmpl $0x1, %ebp
je 0x12442
decl %ebp
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x8(%r15), %rdx
addq $0x8, %r15
callq 0x7f8c
jmp 0x12190
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
cmpl $0x1, %ebp
jne 0x120eb
pushq $0x1
popq %rbp
jmp 0x12111
movq 0x8(%r15), %rdi
cmpb $0x2d, (%rdi)
je 0x12111
addq $0x8, %r15
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x18a95
testl %eax, %eax
jne 0x1245a
decl %ebp
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
xorl %edx, %edx
callq 0x9cf6
jmp 0x12190
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
cmpl $0x1, %ebp
jne 0x12142
pushq $0x1
popq %rbp
jmp 0x12168
movq 0x8(%r15), %rdi
cmpb $0x2d, (%rdi)
je 0x12168
addq $0x8, %r15
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x18a95
testl %eax, %eax
jne 0x12473
decl %ebp
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x78b4
testb %al, %al
je 0x12421
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
xorl %edx, %edx
callq 0x95e4
movq %r15, %r12
decl %ebp
addq $0x8, %r12
movq %r12, %r15
jmp 0x11f02
cmpl $0x1, %ebp
je 0x12442
movq 0x10(%rsp), %rax
movq 0x60(%rax), %rcx
cmpq 0x68(%rax), %rcx
je 0x12421
leaq 0x8(%r15), %r12
movq (%r12), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x1876b
testl %eax, %eax
jne 0x12466
cmpl $0x3, %ebp
jb 0x121fb
movq 0x10(%r15), %rsi
leaq 0xcb27(%rip), %rdi      # 0x1ed13
callq 0x4820
testl %eax, %eax
je 0x1225a
decl %ebp
xorl %eax, %eax
jmp 0x12266
xorl %eax, %eax
pushq $0x1
popq %rbp
jmp 0x12266
cmpl $0x1, %ebp
je 0x12442
leaq 0x8(%r15), %r12
movq (%r12), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x18a95
testl %eax, %eax
jne 0x1247f
cmpl $0x3, %ebp
jb 0x12250
movq 0x10(%r15), %rsi
leaq 0xcad9(%rip), %rdi      # 0x1ed13
callq 0x4820
testl %eax, %eax
je 0x1231f
decl %ebp
xorl %eax, %eax
jmp 0x1232b
xorl %eax, %eax
pushq $0x1
popq %rbp
jmp 0x1232b
addq $0x10, %r15
addl $-0x2, %ebp
movb $0x1, %al
movq %r15, %r12
movq 0x30(%rsp), %rsi
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
movzbl %al, %ecx
callq 0x7c36
jmp 0x12348
cmpl $0x1, %ebp
je 0x12442
leaq 0x8(%r15), %r12
movq (%r12), %rdi
leaq 0x30(%rsp), %rsi
callq 0x159bc
testb %al, %al
je 0x124a5
movq 0x18(%rsp), %r15
cmpl $0x1, 0x30(%rsp)
jne 0x122dd
movq 0x40(%r15), %rcx
testq %rcx, %rcx
jne 0x122e6
jmp 0x122cf
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %rdi, %rdx
xorl %r8d, %r8d
callq 0x8150
movq 0x48(%r15), %rcx
testq %rcx, %rcx
jne 0x122bc
jmp 0x123c2
movq 0x48(%r15), %rcx
testq %rcx, %rcx
je 0x12311
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %rdi, %rdx
xorl %r8d, %r8d
callq 0x8150
jmp 0x123c2
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %rdi, %rdx
xorl %r8d, %r8d
callq 0x8150
movq 0x40(%r15), %rcx
testq %rcx, %rcx
jne 0x122fe
jmp 0x123c2
addq $0x10, %r15
addl $-0x2, %ebp
movb $0x1, %al
movq %r15, %r12
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
movzbl %al, %r8d
callq 0x8150
testb %al, %al
je 0x12421
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x12193
cmpl $0x1, %ebp
je 0x12442
leaq 0x8(%r15), %r12
movq (%r12), %rdi
leaq 0x64(%rsp), %rsi
callq 0x159bc
testb %al, %al
je 0x12392
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x28(%rsi), %edx
notl %edx
andl $0x1, %edx
jmp 0x123b6
movq (%r12), %rdi
leaq 0x30(%rsp), %rsi
callq 0x1582f
testb %al, %al
je 0x124a5
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x30(%rsp), %edx
pushq $0x1
popq %rcx
callq 0x7b4b
testb %al, %al
je 0x12421
decl %ebp
jmp 0x12193
leaq 0xcb80(%rip), %rsi      # 0x1ef50
movq %rbx, %rdi
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10897
leaq 0x48(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x18a95
testl %eax, %eax
je 0x1240f
movq (%r15), %rdx
leaq 0xcde4(%rip), %rsi      # 0x1f1e9
movl %eax, %edi
movq %rbx, %rcx
jmp 0x12491
decl %ebp
je 0x1242f
movq %rbx, 0x8(%rsp)
addq $0x8, %r15
jmp 0x11efb
leaq 0xe130(%rip), %rsi      # 0x20558
movq 0x8(%rsp), %rdi
jmp 0x12439
leaq 0xcb37(%rip), %rsi      # 0x1ef6d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10897
jmp 0x12496
leaq 0xcb56(%rip), %rsi      # 0x1ef9f
movq 0x8(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x10897
jmp 0x12496
movq (%r15), %rdx
leaq 0xcb25(%rip), %rsi      # 0x1ef89
jmp 0x1248a
movq (%r12), %rdx
leaq 0xcb51(%rip), %rsi      # 0x1efc2
jmp 0x1248a
movq (%r15), %rdx
leaq 0xcb17(%rip), %rsi      # 0x1ef94
jmp 0x1248a
movq (%r12), %rdx
leaq 0xcb43(%rip), %rsi      # 0x1efcd
movl %eax, %edi
movq 0x8(%rsp), %rcx
callq 0x14064
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %rdx
movq 0x8(%r15), %rcx
leaq 0xcb2e(%rip), %rsi      # 0x1efe1
movq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x10897
jmp 0x12496
cmpb $0x2d, %r14b
movq 0x8(%rsp), %r14
jne 0x124df
movzbl 0x1(%r12), %ebx
subl $0x72, %ebx
jne 0x124dd
movzbl 0x2(%r12), %ebx
negl %ebx
testl %ebx, %ebx
je 0x124ff
leaq 0xcb2e(%rip), %rdi      # 0x1f018
movq %r12, %rsi
callq 0x4820
testl %eax, %eax
je 0x124ff
leaq 0xcb44(%rip), %rsi      # 0x1f041
jmp 0x12548
cmpl $0x1, %ebp
jne 0x12541
movq 0x10(%rsp), %rdi
movq 0x60(%rdi), %rax
cmpq 0x68(%rdi), %rax
je 0x12550
movq 0x18(%rsp), %rsi
movq 0x40(%rsi), %rcx
testq %rcx, %rcx
jne 0x12525
movq 0x48(%rsi), %rcx
movq %rdi, %rdx
callq 0x8127
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x8067
jmp 0x12496
leaq 0xcad9(%rip), %rsi      # 0x1f021
movq %r14, %rdi
jmp 0x1244e
leaq 0xe001(%rip), %rsi      # 0x20558
movq %r14, %rdi
jmp 0x12439