// File: /workspace/github_c_makefile_star2_O2/baskerville[P]bspwm/src/tree.c
// Function: transfer_node
bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desktop_t *dd, node_t *nd, bool follow)
{
	if (ns == NULL || ns == nd || is_child(ns, nd) || is_descendant(nd, ns)) {
		return false;
	}

	unsigned int sc = (ms->sticky_count > 0 && ds == ms->desk) ? sticky_count(ns) : 0;
	if (sticky_still && sc > 0 && dd != md->desk) {
		return false;
	}

	put_status(SBSC_MASK_NODE_TRANSFER, "node_transfer 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n", ms->id, ds->id, ns->id, md->id, dd->id, nd!=NULL?nd->id:0);

	bool held_focus = is_descendant(ds->focus, ns);
	/* avoid ending up with a dangling pointer (because of unlink_node) */
	node_t *last_ds_focus = is_child(ns, ds->focus) ? NULL : ds->focus;
	bool ds_was_focused = (ds == mon->desk);

	if (held_focus && ds_was_focused) {
		clear_input_focus();
	}

	unlink_node(ms, ds, ns);
	insert_node(md, dd, ns, nd);

	if (md != ms) {
		if (ns->client == NULL || monitor_from_client(ns->client) != md) {
			adapt_geometry(&ms->rectangle, &md->rectangle, ns);
		}
		ms->sticky_count -= sc;
		md->sticky_count += sc;
	}

	if (ds != dd) {
		ewmh_set_wm_desktop(ns, dd);
		if (sticky_still) {
			if (ds == ms->desk && dd != md->desk) {
				hide_node(ds, ns);
			} else if (ds != ms->desk && dd == md->desk) {
				show_node(dd, ns);
			}
		}
	}

	history_remove(ds, ns, true);
	stack(dd, ns, false);

	if (ds == dd) {
		if (held_focus) {
			if (ds_was_focused) {
				focus_node(ms, ds, last_ds_focus);
			} else {
				activate_node(ms, ds, last_ds_focus);
			}
		} else {
			draw_border(ns, is_descendant(ns, ds->focus), (ms == mon));
		}
	} else {
		if (single_monocle) {
			if (ds->layout != LAYOUT_MONOCLE && tiled_count(ds->root, true) <= 1) {
				set_layout(ms, ds, LAYOUT_MONOCLE, false);
			}
			if (dd->layout == LAYOUT_MONOCLE && tiled_count(dd->root, true) > 1) {
				set_layout(md, dd, dd->user_layout, false);
			}
		}
		if (held_focus) {
			if (follow) {
				if (ds_was_focused) {
					focus_node(md, dd, last_ds_focus);
				}
				activate_node(ms, ds, ds->focus);
			} else {
				if (ds_was_focused) {
					focus_node(ms, ds, ds->focus);
				} else {
					activate_node(ms, ds, ds->focus);
				}
			}
		}
		if (!held_focus || !follow || !ds_was_focused) {
			if (dd->focus == ns) {
				if (dd == mon->desk) {
					focus_node(md, dd, held_focus ? last_ds_focus : ns);
				} else {
					activate_node(md, dd, held_focus ? last_ds_focus : ns);
				}
			} else {
				draw_border(ns, is_descendant(ns, dd->focus), (md == mon));
			}
		}
	}

	arrange(ms, ds);

	if (ds != dd) {
		arrange(md, dd);
	}

	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x28(%rsp)
testq %rdx, %rdx
sete %al
cmpq %r9, %rdx
sete %cl
orb %al, %cl
je 0x9961
xorl %ebp, %ebp
jmp 0x9ce5
movq %r9, %r14
movq %r8, %rbx
movq %rdx, %r13
movq %rsi, %r15
testq %r9, %r9
je 0x9978
cmpq %r14, 0x40(%r13)
je 0x995a
movq %rdi, 0x10(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x9892
xorl %ebp, %ebp
testb %al, %al
jne 0x9ce5
movq 0x10(%rsp), %rax
cmpl $0x0, 0x40(%rax)
je 0x99cb
cmpq %r15, 0x58(%rax)
jne 0x99cb
movq %r13, %rdi
callq 0xb262
movl %eax, %ebp
leaq 0x1edb6(%rip), %rax     # 0x2876a
testl %ebp, %ebp
setne %cl
andb (%rax), %cl
cmpb $0x1, %cl
jne 0x99cb
movq 0x28(%rsp), %rax
cmpq %rbx, 0x58(%rax)
jne 0x995a
movq 0x10(%rsp), %rax
movl 0x20(%rax), %edx
movl 0x20(%r15), %ecx
movl (%r13), %r8d
movq 0x28(%rsp), %rax
movl 0x20(%rax), %r9d
movl 0x20(%rbx), %r10d
testq %r14, %r14
je 0x99f2
movl (%r14), %r11d
jmp 0x99f5
xorl %r11d, %r11d
leaq 0x14dc8(%rip), %rsi     # 0x1e7c4
movl $0x40000, %edi          # imm = 0x40000
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x1d07d
popq %rax
popq %rcx
movq 0x38(%r15), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x9892
movb %al, 0xf(%rsp)
testq %r12, %r12
je 0x9a2c
cmpq %r12, 0x40(%r13)
je 0x9a33
movq %r12, 0x18(%rsp)
jmp 0x9a3c
movq $0x0, 0x18(%rsp)
movq %rbx, 0x30(%rsp)
leaq 0x1ecc8(%rip), %rax     # 0x28710
movq (%rax), %rax
movq 0x58(%rax), %rax
movq %rax, 0x20(%rsp)
cmpq %r15, %rax
sete %al
andb 0xf(%rsp), %al
cmpb $0x1, %al
jne 0x9a67
callq 0x105cd
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xaee2
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rdi, %r14
callq 0x8f01
cmpq %rbx, %r14
je 0x9acb
movq 0x48(%r13), %rdi
testq %rdi, %rdi
je 0x9aaa
callq 0x7330
cmpq %r14, %rax
je 0x9abf
movq 0x10(%rsp), %rax
leaq 0x4c(%rax), %rdi
leaq 0x4c(%r14), %rsi
movq %r13, %rdx
callq 0x6bfe
movq 0x10(%rsp), %rax
subl %ebp, 0x40(%rax)
addl %ebp, 0x40(%r14)
movq 0x30(%rsp), %rbx
cmpq %rbx, %r15
je 0x9b12
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1c625
leaq 0x1ec83(%rip), %rax     # 0x2876a
cmpb $0x1, (%rax)
movq 0x10(%rsp), %r12
jne 0x9b81
movq 0x58(%r14), %rax
cmpq %r15, 0x58(%r12)
je 0x9b71
cmpq %rbx, %rax
jne 0x9b81
movq %rbx, %rdi
movq %r13, %rsi
callq 0xa18e
jmp 0x9b81
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0xcb44
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0xc7ea
cmpb $0x0, 0xf(%rsp)
movq 0x10(%rsp), %r12
je 0x9b54
cmpq %r15, 0x20(%rsp)
je 0x9c2a
movq %r12, %rdi
movq %r15, %rsi
movq 0x18(%rsp), %rdx
jmp 0x9cb2
movq 0x38(%r15), %rsi
movq %r13, %rdi
callq 0x9892
xorl %edx, %edx
leaq 0x1eba7(%rip), %rcx     # 0x28710
cmpq %r12, (%rcx)
jmp 0x9c7e
cmpq %rbx, %rax
je 0x9b81
movq %r15, %rdi
movq %r13, %rsi
callq 0xa117
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0xcb44
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0xc7ea
leaq 0x1f255(%rip), %rax     # 0x28df8
cmpb $0x1, (%rax)
jne 0x9bf7
cmpl $0x1, 0x24(%r15)
je 0x9bd0
movq 0x30(%r15), %rdi
pushq $0x1
popq %rsi
callq 0x93c6
cmpl $0x1, %eax
jg 0x9bd0
pushq $0x1
popq %rdx
movq %r12, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x7b4b
cmpl $0x1, 0x24(%rbx)
jne 0x9bf7
movq 0x30(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x93c6
cmpl $0x2, %eax
jl 0x9bf7
movl 0x28(%rbx), %edx
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x7b4b
cmpb $0x0, 0xf(%rsp)
je 0x9c61
cmpb $0x0, 0x70(%rsp)
je 0x9c12
cmpq %r15, 0x20(%rsp)
je 0x9c3a
movq 0x38(%r15), %rdx
jmp 0x9c1d
movq 0x38(%r15), %rdx
cmpq %r15, 0x20(%rsp)
je 0x9c56
movq %r12, %rdi
movq %r15, %rsi
callq 0x95e4
jmp 0x9c61
movq %r12, %rdi
movq %r15, %rsi
movq 0x18(%rsp), %rdx
jmp 0x9cc2
movq %r14, %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
callq 0x9cf6
movq 0x38(%r15), %rdx
movq %r12, %rdi
movq %r15, %rsi
jmp 0x9cb2
movq %r12, %rdi
movq %r15, %rsi
callq 0x9cf6
movq 0x38(%rbx), %rsi
cmpq %r13, %rsi
je 0x9c8e
movq %r13, %rdi
callq 0x9892
xorl %edx, %edx
leaq 0x1ea95(%rip), %rcx     # 0x28710
cmpq %r14, (%rcx)
sete %dl
movzbl %al, %esi
movq %r13, %rdi
callq 0xf25d
jmp 0x9cc7
leaq 0x1ea7b(%rip), %rax     # 0x28710
movq (%rax), %rax
cmpb $0x0, 0xf(%rsp)
cmovneq 0x18(%rsp), %r13
cmpq %rbx, 0x58(%rax)
je 0x9cb9
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x95e4
jmp 0x9cc7
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x9cf6
movq %r12, %rdi
movq %r15, %rsi
callq 0x8670
movb $0x1, %bpl
cmpq %rbx, %r15
je 0x9ce5
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8670
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq