// File: /workspace/github_c_makefile_star2_O2/baskerville[P]bspwm/src/desktop.c
// Function: transfer_desktop
bool transfer_desktop(monitor_t *ms, monitor_t *md, desktop_t *d, bool follow)
{
	if (ms == NULL || md == NULL || d == NULL || ms == md) {
		return false;
	}

	bool d_was_active = (d == ms->desk);
	bool ms_was_focused = (ms == mon);
	unsigned int sc = (ms->sticky_count > 0 && d_was_active) ? sticky_count(d->root) : 0;

	unlink_desktop(ms, d);
	ms->sticky_count -= sc;

	if ((!follow || !d_was_active || !ms_was_focused) && md->desk != NULL) {
		hide_sticky = false;
		hide_desktop(d);
		hide_sticky = true;
	}

	insert_desktop(md, d);
	md->sticky_count += sc;
	history_remove(d, NULL, false);

	if (d_was_active) {
		if (follow) {
			if (activate_desktop(ms, NULL)) {
				activate_node(ms, ms->desk, NULL);
			}
			if (ms_was_focused) {
				focus_node(md, d, d->focus);
			}
		} else {
			if (ms_was_focused) {
				focus_node(ms, ms->desk, NULL);
			} else if (activate_desktop(ms, NULL)) {
				activate_node(ms, ms->desk, NULL);
			}
		}
	}

	if (sc > 0) {
		if (ms->desk != NULL) {
			transfer_sticky_nodes(md, d, ms, ms->desk, d->root);
		} else if (d != md->desk) {
			transfer_sticky_nodes(md, d, md, md->desk, d->root);
		}
	}

	adapt_geometry(&ms->rectangle, &md->rectangle, d->root);
	arrange(md, d);

	if ((!follow || !d_was_active || !ms_was_focused) && md->desk == d) {
		if (md == mon) {
			focus_node(md, d, d->focus);
		} else {
			activate_node(md, d, d->focus);
		}
	}

	ewmh_update_wm_desktops();
	ewmh_update_desktop_names();
	ewmh_update_desktop_viewport();
	ewmh_update_current_desktop();

	put_status(SBSC_MASK_DESKTOP_TRANSFER, "desktop_transfer 0x%08X 0x%08X 0x%08X\n", ms->id, d->id, md->id);
	put_status(SBSC_MASK_REPORT);

	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, 0x8(%rsp)
testq %rdi, %rdi
setne %al
testq %rsi, %rsi
setne %cl
andb %al, %cl
testq %rdx, %rdx
setne %al
cmpq %rsi, %rdi
setne %bl
andb %al, %bl
andb %cl, %bl
cmpb $0x1, %bl
jne 0x7e6b
movq %rdx, %r15
movq %rdi, %r12
movq %rsi, 0x20(%rsp)
movq 0x58(%rdi), %r13
cmpq %rdx, %r13
setne %dl
leaq 0x20a85(%rip), %rcx     # 0x28710
cmpl $0x0, 0x40(%rdi)
movq (%rcx), %r14
sete %cl
xorl %eax, %eax
orb %dl, %cl
jne 0x7ca4
movq 0x30(%r15), %rdi
callq 0xb262
movq %r14, 0x10(%rsp)
cmpq %r12, %r14
setne %bpl
movq %r13, 0x18(%rsp)
cmpq %r15, %r13
movl %eax, %r13d
setne %r14b
movq %r12, %rdi
movq %r15, %rsi
callq 0x7e90
movl %r13d, 0xc(%rsp)
subl %r13d, 0x40(%r12)
movl 0x8(%rsp), %eax
movl %eax, %r13d
xorb $0x1, %r13b
orb %r14b, %r13b
orb %bpl, %r13b
cmpb $0x1, %r13b
movq 0x20(%rsp), %rbp
jne 0x7d0e
cmpq $0x0, 0x58(%rbp)
je 0x7d0e
leaq 0x20a6b(%rip), %r14     # 0x28769
movb $0x0, (%r14)
movq %r15, %rdi
callq 0x7987
movb $0x1, (%r14)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x7ed4
movl 0xc(%rsp), %r14d
addl %r14d, 0x40(%rbp)
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xcb44
cmpq %r15, 0x18(%rsp)
je 0x7d53
testl %r14d, %r14d
je 0x7dac
movq 0x58(%r12), %rcx
testq %rcx, %rcx
je 0x7d91
movq 0x30(%r15), %r8
movq %rbp, %rdi
movq %r15, %rsi
movq %r12, %rdx
jmp 0x7da7
cmpb $0x0, 0x8(%rsp)
je 0x7df1
movq %r12, %rdi
xorl %esi, %esi
callq 0x78b4
testb %al, %al
je 0x7d7b
movq 0x58(%r12), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x95e4
cmpq %r12, 0x10(%rsp)
jne 0x7d35
movq 0x38(%r15), %rdx
movq %rbp, %rdi
movq %r15, %rsi
jmp 0x7e86
movq 0x58(%rbp), %rcx
cmpq %r15, %rcx
je 0x7dac
movq 0x30(%r15), %r8
movq %rbp, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x98bc
leaq 0x4c(%r12), %rdi
leaq 0x4c(%rbp), %rsi
movq 0x30(%r15), %rdx
callq 0x6bfe
movq %rbp, %rdi
movq %r15, %rsi
callq 0x8670
testb %r13b, %r13b
je 0x7e2d
cmpq %r15, 0x58(%rbp)
jne 0x7e2d
movq 0x38(%r15), %rdx
leaq 0x20931(%rip), %rax     # 0x28710
cmpq %rbp, (%rax)
je 0x7e22
movq %rbp, %rdi
movq %r15, %rsi
callq 0x95e4
jmp 0x7e2d
cmpq %r12, 0x10(%rsp)
je 0x7e7c
movq %r12, %rdi
xorl %esi, %esi
callq 0x78b4
testb %al, %al
je 0x7d35
movq 0x58(%r12), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x95e4
jmp 0x7d35
movq %rbp, %rdi
movq %r15, %rsi
callq 0x9cf6
callq 0x1c670
callq 0x1c6ea
callq 0x1c78f
callq 0x1c5f3
movl 0x20(%r12), %edx
movl 0x20(%r15), %ecx
movl 0x20(%rbp), %r8d
leaq 0x166d7(%rip), %rsi     # 0x1e52c
movl $0x800, %edi            # imm = 0x800
xorl %eax, %eax
callq 0x1d07d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x1d07d
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x58(%r12), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x9cf6
jmp 0x7d35