// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movq %rdx, %rbx
testl %esi, %esi
jle 0x13073
movl %esi, %r15d
movq %rdi, %r14
leaq 0x166fe(%rip), %rax     # 0x29710
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x58(%rax), %rax
movq %rax, 0x40(%rsp)
xorl %eax, %eax
movq %rax, 0x48(%rsp)
movq %rax, 0x10(%rsp)
movq 0x38(%rsp), %rax
movq %rax, (%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
movq (%rdi), %rdi
cmpb $0x2d, (%rdi)
je 0x130a1
leaq 0x38(%rsp), %rsi
movq %rsp, %rdx
callq 0x19fc7
movl %eax, %ebp
testl %eax, %eax
je 0x13092
movq (%r14), %rdx
leaq 0xd1c8(%rip), %rsi      # 0x2022f
movl %ebp, %edi
movq %rbx, %rcx
callq 0x1528e
jmp 0x13099
leaq 0xcf16(%rip), %rsi      # 0x1ff90
movq %rbx, %rdi
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11852
decl %r15d
addq $0x8, %r14
testl %ebp, %ebp
jne 0x13635
testl %r15d, %r15d
jle 0x13624
movq (%r14), %r13
leaq 0xcc2c(%rip), %rdi      # 0x1fce0
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x13219
leaq 0xcc08(%rip), %rdi      # 0x1fcd3
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x13219
leaq 0xcc11(%rip), %rdi      # 0x1fcf3
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x13287
leaq 0xcbea(%rip), %rdi      # 0x1fce3
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x13287
leaq 0xcc36(%rip), %rdi      # 0x1fd46
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x132f5
leaq 0xcc0d(%rip), %rdi      # 0x1fd34
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x132f5
leaq 0xcc29(%rip), %rdi      # 0x1fd67
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x13388
leaq 0xcc06(%rip), %rdi      # 0x1fd5b
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x13388
leaq 0xceac(%rip), %rdi      # 0x20018
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x13474
leaq 0xce98(%rip), %rdi      # 0x2001b
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x13474
leaq 0xcbd0(%rip), %rdi      # 0x1fd6a
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x13576
leaq 0xce98(%rip), %rdi      # 0x20049
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x13576
leaq 0xcb90(%rip), %rdi      # 0x1fd58
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x131eb
leaq 0xce77(%rip), %rdi      # 0x20052
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
jne 0x13674
cmpl $0x1, %r15d
je 0x13644
decl %r15d
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x8(%r14), %rdx
addq $0x8, %r14
callq 0x832f
movl %r15d, %r13d
movq %r14, %r12
jmp 0x1336e
movq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
movaps (%rsp), %xmm0
movaps %xmm0, 0x20(%rsp)
cmpl $0x1, %r15d
jne 0x1323d
movl $0x1, %r15d
jmp 0x1334d
movq 0x8(%r14), %rdi
cmpb $0x2d, (%rdi)
je 0x1334d
addq $0x8, %r14
leaq 0x38(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x19fc7
movl %eax, %r13d
testl %eax, %eax
je 0x13343
movq (%r14), %rdx
movl %r13d, %edi
leaq 0xcd54(%rip), %rsi      # 0x1ffc9
movq %rbx, %rcx
callq 0x1528e
movl $0x3, %ebp
jmp 0x13345
movq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
movaps (%rsp), %xmm0
movaps %xmm0, 0x20(%rsp)
cmpl $0x1, %r15d
jne 0x132ab
movl $0x1, %r15d
jmp 0x1340b
movq 0x8(%r14), %rdi
cmpb $0x2d, (%rdi)
je 0x1340b
addq $0x8, %r14
leaq 0x38(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x19fc7
movl %eax, %r13d
testl %eax, %eax
je 0x133fd
movq (%r14), %rdx
movl %r13d, %edi
leaq 0xccf1(%rip), %rsi      # 0x1ffd4
movq %rbx, %rcx
callq 0x1528e
movl $0x3, %ebp
jmp 0x133ff
cmpl $0x1, %r15d
je 0x13644
movq (%rsp), %rax
movq 0x60(%rax), %rcx
cmpq 0x68(%rax), %rcx
je 0x136e4
leal -0x1(%r15), %r13d
leaq 0x8(%r14), %r12
movq (%r12), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x19c02
testl %eax, %eax
je 0x133d1
movq (%r12), %rdx
movl %eax, %edi
leaq 0xccc1(%rip), %rsi      # 0x20002
jmp 0x133c2
xorl %ebp, %ebp
decl %r15d
testl %r13d, %r13d
jne 0x13360
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0xa2cd
movl %r15d, %r13d
movq %r14, %r12
testl %ebp, %ebp
jne 0x13635
leal -0x1(%r13), %r15d
addq $0x8, %r12
movq %r12, %r14
cmpl $0x1, %r13d
jg 0x130aa
jmp 0x13635
cmpl $0x1, %r15d
je 0x13644
leal -0x1(%r15), %r13d
leaq 0x8(%r14), %r12
movq (%r12), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x19fc7
testl %eax, %eax
je 0x134d6
movq (%r12), %rdx
movl %eax, %edi
leaq 0xcc4b(%rip), %rsi      # 0x2000d
movq %rbx, %rcx
callq 0x1528e
xorl %ebp, %ebp
jmp 0x13568
cmpl $0x3, %r15d
jl 0x13451
movq 0x10(%r14), %rsi
leaq 0xc941(%rip), %rdi      # 0x1fd23
callq 0x4820
testl %eax, %eax
jne 0x13457
addq $0x10, %r14
addl $-0x2, %r15d
movb $0x1, %al
movl %r15d, %r13d
movq %r14, %r12
jmp 0x13459
xorl %ebp, %ebp
decl %r15d
testl %r13d, %r13d
jne 0x13360
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x7be8
testb %al, %al
je 0x13436
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x9af5
jmp 0x13360
movq %rbx, %rdi
leaq 0xe164(%rip), %rsi      # 0x215a4
xorl %eax, %eax
callq 0x11852
movl $0x3, %ebp
jmp 0x13360
movl $0x1, %r13d
xorl %eax, %eax
movq 0x20(%rsp), %rsi
movq (%rsp), %rdi
movq 0x8(%rsp), %rdx
movzbl %al, %ecx
callq 0x7fb3
jmp 0x13543
cmpl $0x1, %r15d
je 0x13644
leaq 0x8(%r14), %r12
movq (%r12), %rdi
leaq 0x20(%rsp), %rsi
callq 0x16c60
movl %eax, %r13d
testb %al, %al
je 0x13502
movq 0x8(%rsp), %r14
cmpl $0x1, 0x20(%rsp)
jne 0x135a9
movq 0x40(%r14), %rcx
testq %rcx, %rcx
jne 0x135b2
jmp 0x134c8
movq (%rsp), %rdi
movq %r14, %rsi
movq %rdi, %rdx
xorl %r8d, %r8d
callq 0x851b
movq 0x48(%r14), %rcx
testq %rcx, %rcx
jne 0x134b6
jmp 0x135e1
cmpl $0x3, %r15d
jl 0x1351f
movq 0x10(%r14), %rsi
leaq 0xc83c(%rip), %rdi      # 0x1fd23
callq 0x4820
testl %eax, %eax
jne 0x13525
addq $0x10, %r14
addl $-0x2, %r15d
movb $0x1, %al
movl %r15d, %r13d
movq %r14, %r12
jmp 0x13527
movq (%r14), %rdx
movq 0x8(%r14), %rcx
movq %rbx, %rdi
leaq 0xcb11(%rip), %rsi      # 0x20024
xorl %eax, %eax
callq 0x11852
jmp 0x135e1
movl $0x1, %r13d
xorl %eax, %eax
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
movzbl %al, %r8d
callq 0x851b
testb %al, %al
je 0x13555
movq 0x20(%rsp), %rax
movq %rax, (%rsp)
movb $0x1, %bpl
jmp 0x13568
xorl %ebp, %ebp
movq %rbx, %rdi
leaq 0xe043(%rip), %rsi      # 0x215a4
xorl %eax, %eax
callq 0x11852
testb %bpl, %bpl
jne 0x1336e
jmp 0x13635
cmpl $0x1, %r15d
je 0x13644
leaq 0x8(%r14), %r12
movq (%r12), %rdi
leaq 0x54(%rsp), %rsi
callq 0x16c60
testb %al, %al
je 0x135e8
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x28(%rsi), %edx
notl %edx
andl $0x1, %edx
jmp 0x13607
movq 0x48(%r14), %rcx
testq %rcx, %rcx
je 0x135d8
movq (%rsp), %rdi
movq %r14, %rsi
movq %rdi, %rdx
xorl %r8d, %r8d
callq 0x851b
jmp 0x135e1
movq (%rsp), %rdi
movq %r14, %rsi
movq %rdi, %rdx
xorl %r8d, %r8d
callq 0x851b
movq 0x40(%r14), %rcx
testq %rcx, %rcx
jne 0x135c6
testb %r13b, %r13b
jne 0x13619
jmp 0x13635
movq (%r12), %rdi
leaq 0x20(%rsp), %rsi
callq 0x16abc
testb %al, %al
je 0x1365a
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x20(%rsp), %edx
movl $0x1, %ecx
callq 0x7ec3
testb %al, %al
je 0x136e4
decl %r15d
movl %r15d, %r13d
jmp 0x1336e
leaq 0xc982(%rip), %rsi      # 0x1ffad
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11852
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc994(%rip), %rsi      # 0x1ffdf
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x11852
jmp 0x13635
movq (%r14), %rdx
movq 0x8(%r14), %rcx
leaq 0xc9bc(%rip), %rsi      # 0x20024
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11852
jmp 0x13635
leaq 0xc860(%rip), %rdi      # 0x1fedb
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x136a3
leaq 0xc9cd(%rip), %rdi      # 0x2005b
movq %r13, %rsi
callq 0x4820
testl %eax, %eax
je 0x136a3
leaq 0xc9e3(%rip), %rsi      # 0x20084
jmp 0x1364b
cmpl $0x1, %r15d
jne 0x136f0
movq (%rsp), %rdi
movq 0x60(%rdi), %rax
cmpq 0x68(%rdi), %rax
je 0x136e4
movq 0x8(%rsp), %rsi
movq 0x40(%rsi), %rcx
testq %rcx, %rcx
jne 0x136c9
movq 0x48(%rsi), %rcx
movq %rdi, %rdx
callq 0x84ef
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x842d
jmp 0x13635
leaq 0xdeb9(%rip), %rsi      # 0x215a4
jmp 0x1362b
leaq 0xc96d(%rip), %rsi      # 0x20064
jmp 0x1364b