// File: /workspace/github_c_makefile_star2_O3/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 %rdx, %r13
testq %rdx, %rdx
sete %al
cmpq %r9, %rdx
sete %dl
orb %al, %dl
je 0x9e93
xorl %eax, %eax
jmp 0xa2f9
movq %r9, %rbp
movq %rsi, %rbx
testq %r9, %r9
je 0x9eba
cmpq %rbp, 0x40(%r13)
je 0x9e8c
movq %rbp, %rax
movq 0x40(%rax), %rax
cmpq %r13, %rax
je 0x9eb5
testq %rax, %rax
jne 0x9ea7
cmpq %r13, %rax
je 0x9e8c
movq %r8, 0x20(%rsp)
movq %rcx, %r14
xorl %r12d, %r12d
cmpl $0x0, 0x40(%rdi)
movl $0x0, %r15d
movq %rdi, 0x18(%rsp)
je 0x9f12
cmpq %rbx, 0x58(%rdi)
jne 0x9f12
movq %r13, %rdi
callq 0xba68
movl %eax, %r15d
leaq 0x1f87c(%rip), %rax     # 0x2976a
testl %r15d, %r15d
setne %cl
andb (%rax), %cl
cmpb $0x1, %cl
jne 0x9f0d
movq 0x20(%rsp), %rax
cmpq %rax, 0x58(%r14)
movq 0x18(%rsp), %rdi
jne 0x9e8c
jmp 0x9f12
movq 0x18(%rsp), %rdi
movl 0x20(%rdi), %edx
movl 0x20(%rbx), %ecx
movl (%r13), %r8d
movl 0x20(%r14), %r9d
movq 0x20(%rsp), %rax
movl 0x20(%rax), %r10d
testq %rbp, %rbp
je 0x9f32
movl (%rbp), %r12d
leaq 0x1588b(%rip), %rsi     # 0x1f7c4
movl $0x40000, %edi          # imm = 0x40000
xorl %eax, %eax
pushq %r12
pushq %r10
callq 0x1e6b8
addq $0x10, %rsp
movq 0x38(%rbx), %rax
testq %rax, %rax
movq %rbx, 0x28(%rsp)
movl %r15d, 0x34(%rsp)
je 0x9f86
cmpq %r13, %rax
movq %r14, %r12
je 0x9fc3
movq %rax, %rcx
movq 0x18(%rsp), %r15
movq 0x40(%rcx), %rcx
cmpq %r13, %rcx
je 0x9f7e
testq %rcx, %rcx
jne 0x9f70
cmpq %r13, %rcx
sete %dl
jmp 0x9fca
leaq 0x1f783(%rip), %rax     # 0x29710
movq (%rax), %rax
cmpq %rbx, 0x58(%rax)
sete 0x7(%rsp)
setne %al
movl %eax, 0xc(%rsp)
movb $0x1, %al
movl %eax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %rbx, %rsi
xorl %ebx, %ebx
movq %r14, %r12
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %r14
jmp 0xa026
movb $0x1, %dl
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %r14
xorl %ecx, %ecx
cmpq %rax, 0x40(%r13)
cmovneq %rax, %rcx
movq %rcx, 0x10(%rsp)
leaq 0x1f72b(%rip), %rax     # 0x29710
movq (%rax), %rax
cmpq %rbx, 0x58(%rax)
sete 0x7(%rsp)
setne %cl
movq %rdx, %rbx
xorb $0x1, %dl
movl %edx, %eax
orb %cl, %al
testb $0x1, %al
je 0xa00c
movl %edx, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
jmp 0xa021
callq 0x11510
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movq 0x28(%rsp), %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0xb66d
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x92a8
cmpq %r15, %r12
movq %rbx, %rbp
je 0xa07b
movq 0x48(%r13), %rdi
testq %rdi, %rdi
je 0xa05d
callq 0x747e
cmpq %r12, %rax
je 0xa06e
leaq 0x4c(%r15), %rdi
leaq 0x4c(%r12), %rsi
movq %r13, %rdx
callq 0x6d15
movl 0x34(%rsp), %eax
subl %eax, 0x40(%r15)
addl %eax, 0x40(%r12)
movq 0x28(%rsp), %rbx
cmpq %r14, %rbx
je 0xa0c8
movq %r13, %rdi
movq %r14, %rsi
callq 0x1dbc2
leaq 0x1f6d3(%rip), %rax     # 0x2976a
cmpb $0x1, (%rax)
jne 0xa14b
movq 0x58(%r12), %rax
cmpq %rbx, 0x58(%r15)
je 0xa13b
cmpq %r14, %rax
jne 0xa14b
movq %r14, %rdi
movq %r13, %rsi
callq 0xa7fb
jmp 0xa14b
movq %rbx, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0xd6b9
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0xd303
testb %bpl, %bpl
je 0xa10a
cmpb $0x0, 0x7(%rsp)
je 0xa225
movq %r15, %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
callq 0xa308
jmp 0xa235
movq 0x38(%rbx), %rax
testq %rax, %rax
je 0xa2bd
movq %r13, %rcx
cmpq %r13, %rax
je 0xa130
movq %r13, %rcx
movq 0x40(%rcx), %rcx
cmpq %rax, %rcx
je 0xa130
testq %rcx, %rcx
jne 0xa122
cmpq %rax, %rcx
sete %al
jmp 0xa2bf
cmpq %r14, %rax
je 0xa14b
movq %rbx, %rdi
movq %r13, %rsi
callq 0xa781
movq %rbx, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0xd6b9
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0xd303
leaq 0x1fc89(%rip), %rax     # 0x29df8
cmpb $0x1, (%rax)
jne 0xa1ca
cmpl $0x1, 0x24(%rbx)
je 0xa19f
movq 0x30(%rbx), %rdi
movl $0x1, %esi
callq 0x97a3
cmpl $0x1, %eax
jg 0xa19f
movq %r15, %rdi
movq %rbx, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x7d6e
cmpl $0x1, 0x24(%r14)
jne 0xa1ca
movq 0x30(%r14), %rdi
movl $0x1, %esi
callq 0x97a3
cmpl $0x2, %eax
jl 0xa1ca
movl 0x28(%r14), %edx
movq %r12, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x7d6e
testb %bpl, %bpl
je 0xa24b
cmpb $0x0, 0x70(%rsp)
je 0xa20d
cmpb $0x0, 0x7(%rsp)
je 0xa1ed
movq %r12, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
callq 0xa308
movq 0x38(%rbx), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x9a3d
movl 0x8(%rsp), %eax
orb 0xc(%rsp), %al
testb $0x1, %al
jne 0xa24b
jmp 0xa2b0
movq 0x38(%rbx), %rdx
cmpb $0x0, 0x7(%rsp)
je 0xa240
movq %r15, %rdi
movq %rbx, %rsi
callq 0xa308
jmp 0xa24b
movq %r15, %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
callq 0x9a3d
movq %r15, %rdi
movq %rbx, %rsi
jmp 0xa2f2
movq %r15, %rdi
movq %rbx, %rsi
callq 0x9a3d
movq 0x38(%r14), %rax
cmpq %r13, %rax
je 0xa272
testq %rax, %rax
je 0xa29b
movq %r13, %rcx
movq 0x40(%rcx), %rcx
cmpq %rax, %rcx
je 0xa26a
testq %rcx, %rcx
jne 0xa25c
cmpq %rax, %rcx
sete %al
jmp 0xa29d
leaq 0x1f497(%rip), %rax     # 0x29710
movq (%rax), %rax
testb %bpl, %bpl
cmovneq 0x10(%rsp), %r13
cmpq %r14, 0x58(%rax)
je 0xa2a2
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x9a3d
jmp 0xa2b0
xorl %eax, %eax
movq %r12, %rcx
jmp 0xa2c2
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0xa308
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8958
jmp 0xa2ec
xorl %eax, %eax
movq %r15, %rcx
leaq 0x1f447(%rip), %rsi     # 0x29710
xorl %edx, %edx
cmpq %rcx, (%rsi)
sete %dl
movzbl %al, %esi
movq %r13, %rdi
callq 0xff61
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8958
cmpq %r14, %rbx
je 0xa2f7
movq %r12, %rdi
movq %r14, %rsi
callq 0x8958
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq