// File: /workspace/github_c_makefile_star2_O1/baskerville[P]bspwm/src/tree.c
// Function: swap_nodes
bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop_t *d2, node_t *n2, bool follow)
{
	if (n1 == NULL || n2 == NULL || n1 == n2 || is_descendant(n1, n2) || is_descendant(n2, n1) ||
	    (d1 != d2 && ((m1->sticky_count > 0 && sticky_count(n1) > 0) ||
	                  (m2->sticky_count > 0 && sticky_count(n2) > 0)))) {
		return false;
	}

	put_status(SBSC_MASK_NODE_SWAP, "node_swap 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n", m1->id, d1->id, n1->id, m2->id, d2->id, n2->id);

	node_t *pn1 = n1->parent;
	node_t *pn2 = n2->parent;
	bool n1_first_child = is_first_child(n1);
	bool n2_first_child = is_first_child(n2);
	bool n1_held_focus = is_descendant(d1->focus, n1);
	bool n2_held_focus = is_descendant(d2->focus, n2);
	node_t *last_d1_focus = d1->focus;
	node_t *last_d2_focus = d2->focus;

	if (pn1 != NULL) {
		if (n1_first_child) {
			pn1->first_child = n2;
		} else {
			pn1->second_child = n2;
		}
	}

	if (pn2 != NULL) {
		if (n2_first_child) {
			pn2->first_child = n1;
		} else {
			pn2->second_child = n1;
		}
	}

	n1->parent = pn2;
	n2->parent = pn1;

	propagate_flags_upward(m2, d2, n1);
	propagate_flags_upward(m1, d1, n2);

	if (d1 != d2) {
		if (d1->root == n1) {
			d1->root = n2;
		}

		if (d2->root == n2) {
			d2->root = n1;
		}

		if (n1_held_focus) {
			d1->focus = n2_held_focus ? last_d2_focus : n2;
		}

		if (n2_held_focus) {
			d2->focus = n1_held_focus ? last_d1_focus : n1;
		}

		if (m1 != m2) {
			adapt_geometry(&m2->rectangle, &m1->rectangle, n2);
			adapt_geometry(&m1->rectangle, &m2->rectangle, n1);
		}

		ewmh_set_wm_desktop(n1, d2);
		ewmh_set_wm_desktop(n2, d1);

		history_remove(d1, n1, true);
		history_remove(d2, n2, true);

		bool d1_was_focused = (d1 == mon->desk);
		bool d2_was_focused = (d2 == mon->desk);

		if (m1->desk != d1 && m2->desk == d2) {
			show_node(d2, n1);
			if (!follow || !d2_was_focused || !n2_held_focus) {
				hide_node(d2, n2);
			}
		} else if (m1->desk == d1 && m2->desk != d2) {
			if (!follow || !d1_was_focused || !n1_held_focus) {
				hide_node(d1, n1);
			}
			show_node(d1, n2);
		}

		if (single_monocle) {
			layout_t l1 = tiled_count(d1->root, true) <= 1 ? LAYOUT_MONOCLE : d1->user_layout;
			layout_t l2 = tiled_count(d2->root, true) <= 1 ? LAYOUT_MONOCLE : d2->user_layout;
			set_layout(m1, d1, l1, false);
			set_layout(m2, d2, l2, false);
		}

		if (n1_held_focus) {
			if (d1_was_focused) {
				if (follow) {
					focus_node(m2, d2, last_d1_focus);
				} else {
					focus_node(m1, d1, d1->focus);
				}
			} else {
				activate_node(m1, d1, d1->focus);
			}
		} else {
			draw_border(n2, is_descendant(n2, d1->focus), (m1 == mon));
		}

		if (n2_held_focus) {
			if (d2_was_focused) {
				if (follow) {
					focus_node(m1, d1, last_d2_focus);
				} else {
					focus_node(m2, d2, d2->focus);
				}
			} else {
				activate_node(m2, d2, d2->focus);
			}
		} else {
			draw_border(n1, is_descendant(n1, d2->focus), (m2 == mon));
		}
	} else {
		if (!n1_held_focus) {
			draw_border(n1, is_descendant(n1, d2->focus), (m2 == mon));
		}
		if (!n2_held_focus) {
			draw_border(n2, is_descendant(n2, d1->focus), (m1 == mon));
		}
	}

	arrange(m1, d1);

	if (d1 != d2) {
		arrange(m2, d2);
	} else {
		if (pointer_follows_focus && (n1_held_focus || n2_held_focus)) {
			center_pointer(get_rectangle(m1, d1, d1->focus));
		}
	}

	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %rbp
xorl %r12d, %r12d
cmpq %r9, %rdx
je 0xbb29
movq %rdx, %r13
testq %rdx, %rdx
je 0xbb29
testq %rbp, %rbp
je 0xbb29
movq %r8, %r15
movq %rcx, %r9
movq %rsi, %rbx
movq %rdi, %r14
movq %r13, %rax
movq 0x40(%rax), %rax
cmpq %rbp, %rax
je 0xbad1
testq %rax, %rax
jne 0xbac3
cmpq %rbp, %rax
je 0xbb26
movq %rbp, %rax
movq 0x40(%rax), %rax
cmpq %r13, %rax
je 0xbae7
testq %rax, %rax
jne 0xbad9
cmpq %r13, %rax
je 0xbb26
cmpq %r15, %rbx
movq %r9, 0x8(%rsp)
je 0xbb3b
cmpl $0x0, 0x40(%r14)
je 0xbb0e
movq %r13, %rdi
callq 0xba1f
movq 0x8(%rsp), %r9
testl %eax, %eax
jne 0xbb26
cmpl $0x0, 0x40(%r9)
je 0xbb3b
movq %rbp, %rdi
callq 0xba1f
movq 0x8(%rsp), %r9
testl %eax, %eax
je 0xbb3b
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x20(%r14), %edx
movl 0x20(%rbx), %ecx
movl (%r13), %r8d
movl 0x20(%r9), %r9d
movl 0x20(%r15), %r10d
movl (%rbp), %r11d
leaq 0x13c46(%rip), %rsi     # 0x1f79f
movl $0x20000, %edi          # imm = 0x20000
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x1eb0b
addq $0x10, %rsp
movq 0x40(%r13), %rax
movq 0x40(%rbp), %rcx
movl $0x38, %edx
movl $0x38, %esi
testq %rax, %rax
je 0xbb96
xorl %esi, %esi
cmpq %r13, 0x30(%rax)
setne %sil
leaq 0x30(,%rsi,8), %rsi
testq %rcx, %rcx
je 0xbbac
xorl %edx, %edx
cmpq %rbp, 0x30(%rcx)
setne %dl
leaq 0x30(,%rdx,8), %rdx
movq 0x38(%rbx), %r9
testq %r9, %r9
movq 0x8(%rsp), %rdi
movq %r9, 0x20(%rsp)
je 0xbbe1
movq %r9, %r8
cmpq %r13, %r9
je 0xbbd8
movq %r9, %r8
movq 0x40(%r8), %r8
cmpq %r13, %r8
je 0xbbd8
testq %r8, %r8
jne 0xbbca
cmpq %r13, %r8
sete %r12b
jmp 0xbbe4
xorl %r12d, %r12d
movq 0x38(%r15), %r9
testq %r9, %r9
je 0xbc14
movq %r9, %r8
cmpq %rbp, %r9
je 0xbc06
movq %r9, %r8
movq 0x40(%r8), %r8
cmpq %rbp, %r8
je 0xbc06
testq %r8, %r8
jne 0xbbf8
cmpq %rbp, %r8
sete %r8b
movl %r8d, 0x4(%rsp)
jmp 0xbc1c
movl $0x0, 0x4(%rsp)
testq %rax, %rax
je 0xbc25
movq %rbp, (%rax,%rsi)
movq %r9, 0x28(%rsp)
testq %rcx, %rcx
je 0xbc33
movq %r13, (%rcx,%rdx)
movq %rcx, 0x40(%r13)
movq %rax, 0x40(%rbp)
movq %r15, %rsi
movq %r13, %rdx
callq 0x99a5
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x99a5
cmpq %r15, %rbx
je 0xbd8f
cmpq %r13, 0x30(%rbx)
jne 0xbc67
movq %rbp, 0x30(%rbx)
cmpq %rbp, 0x30(%r15)
movq 0x8(%rsp), %rcx
movq 0x28(%rsp), %rdx
jne 0xbc7b
movq %r13, 0x30(%r15)
testb %r12b, %r12b
je 0xbc90
cmpb $0x0, 0x4(%rsp)
movq %rbp, %rax
cmovneq %rdx, %rax
movq %rax, 0x38(%rbx)
cmpb $0x0, 0x4(%rsp)
je 0xbca7
testb %r12b, %r12b
movq %r13, %rax
cmovneq 0x20(%rsp), %rax
movq %rax, 0x38(%r15)
movl %r12d, 0x14(%rsp)
movq %r15, 0x30(%rsp)
cmpq %rcx, %r14
movq %r14, %r15
je 0xbce2
movq 0x8(%rsp), %rax
leaq 0x4c(%rax), %r12
leaq 0x4c(%r15), %r14
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x6df4
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x6df4
movq %r13, %rdi
movq 0x30(%rsp), %r12
movq %r12, %rsi
callq 0x1df7b
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1df7b
movq %rbx, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0xd60c
movq %r12, %rdi
movq %rbp, %rsi
movl $0x1, %edx
callq 0xd60c
leaq 0x1d9ec(%rip), %rax     # 0x29710
movq (%rax), %rax
movq 0x58(%rax), %rax
movq %rax, 0x18(%rsp)
movq %r15, %r14
movq 0x58(%r15), %rax
movq %r12, %r15
cmpq %rbx, %rax
movq 0x8(%rsp), %rcx
movl 0x14(%rsp), %r12d
je 0xbd58
cmpq %r15, 0x58(%rcx)
je 0xbdce
cmpq %rbx, %rax
jne 0xbdfa
cmpq %r15, 0x58(%rcx)
je 0xbdfa
cmpb $0x0, 0x70(%rsp)
je 0xbd77
cmpq %rbx, 0x18(%rsp)
jne 0xbd77
movl %r12d, %eax
xorb $0x1, %al
je 0xbd82
movq %rbx, %rdi
movq %r13, %rsi
callq 0xa721
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xa798
jmp 0xbdfa
testb %r12b, %r12b
jne 0xbf0f
movq 0x38(%r15), %rax
testq %rax, %rax
movq 0x8(%rsp), %rsi
je 0xbef3
movq %r13, %rcx
cmpq %r13, %rax
je 0xbdc3
movq %r13, %rcx
movq 0x40(%rcx), %rcx
cmpq %rax, %rcx
je 0xbdc3
testq %rcx, %rcx
jne 0xbdb5
cmpq %rax, %rcx
sete %al
jmp 0xbef5
movq %r15, %rdi
movq %r13, %rsi
callq 0xa798
cmpb $0x0, 0x70(%rsp)
je 0xbdef
cmpq %r15, 0x18(%rsp)
jne 0xbdef
movl 0x4(%rsp), %eax
xorb $0x1, %al
je 0xbdfa
movq %r15, %rdi
movq %rbp, %rsi
callq 0xa721
leaq 0x1dff7(%rip), %rax     # 0x29df8
cmpb $0x1, (%rax)
jne 0xbe6e
movq 0x30(%rbx), %rdi
movl $0x1, 0x10(%rsp)
movl $0x1, %esi
callq 0x98c5
movl $0x1, %r12d
cmpl $0x2, %eax
jl 0xbe2b
movl 0x28(%rbx), %r12d
movq 0x30(%r15), %rdi
movl $0x1, %esi
callq 0x98c5
cmpl $0x2, %eax
jl 0xbe46
movl 0x28(%r15), %eax
movl %eax, 0x10(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movl %r12d, %edx
xorl %ecx, %ecx
callq 0x7ec3
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movl 0x10(%rsp), %edx
xorl %ecx, %ecx
callq 0x7ec3
movl 0x14(%rsp), %r12d
testb %r12b, %r12b
je 0xbe8e
cmpq %rbx, 0x18(%rsp)
je 0xbeb8
movq 0x38(%rbx), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x9af5
jmp 0xbf6f
movq 0x38(%rbx), %rax
testq %rax, %rax
je 0xbed5
movq %rbp, %rcx
cmpq %rbp, %rax
je 0xbeb0
movq %rbp, %rcx
movq 0x40(%rcx), %rcx
cmpq %rax, %rcx
je 0xbeb0
testq %rcx, %rcx
jne 0xbea2
cmpq %rax, %rcx
sete %al
jmp 0xbed7
cmpb $0x0, 0x70(%rsp)
je 0xbf60
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
jmp 0xbf6a
xorl %eax, %eax
xorl %edx, %edx
leaq 0x1d830(%rip), %rcx     # 0x29710
cmpq %r14, (%rcx)
sete %dl
movzbl %al, %esi
movq %rbp, %rdi
callq 0xff0c
jmp 0xbf6f
xorl %eax, %eax
leaq 0x1d814(%rip), %rcx     # 0x29710
xorl %edx, %edx
cmpq %rsi, (%rcx)
sete %dl
movzbl %al, %esi
movq %r13, %rdi
callq 0xff0c
cmpb $0x0, 0x4(%rsp)
jne 0xbff1
movq 0x38(%rbx), %rax
testq %rax, %rax
je 0xbf44
movq %rbp, %rcx
cmpq %rbp, %rax
je 0xbf3c
movq %rbp, %rcx
movq 0x40(%rcx), %rcx
cmpq %rax, %rcx
je 0xbf3c
testq %rcx, %rcx
jne 0xbf2e
cmpq %rax, %rcx
sete %al
jmp 0xbf46
xorl %eax, %eax
leaq 0x1d7c3(%rip), %rcx     # 0x29710
xorl %edx, %edx
cmpq %r14, (%rcx)
sete %dl
movzbl %al, %esi
movq %rbp, %rdi
jmp 0xbfec
movq 0x38(%rbx), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa2cd
cmpb $0x0, 0x4(%rsp)
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rdx
je 0xbf95
cmpq %r15, 0x18(%rsp)
je 0xbfbf
movq 0x38(%r15), %rdx
movq %r15, %rsi
callq 0x9af5
jmp 0xbff1
movq 0x38(%r15), %rax
testq %rax, %rax
je 0xbfd5
movq %r13, %rcx
cmpq %r13, %rax
je 0xbfb7
movq %r13, %rcx
movq 0x40(%rcx), %rcx
cmpq %rax, %rcx
je 0xbfb7
testq %rcx, %rcx
jne 0xbfa9
cmpq %rax, %rcx
sete %al
jmp 0xbfd7
cmpb $0x0, 0x70(%rsp)
je 0xc055
movq %r14, %rdi
movq %rbx, %rsi
jmp 0xc05c
xorl %eax, %eax
xorl %edx, %edx
leaq 0x1d730(%rip), %rcx     # 0x29710
cmpq %rdi, (%rcx)
sete %dl
movzbl %al, %esi
movq %r13, %rdi
callq 0xff0c
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8a5c
cmpq %r15, %rbx
je 0xc016
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x8a5c
movb $0x1, %r12b
jmp 0xbb29
orb 0x4(%rsp), %r12b
movl %r12d, %eax
movb $0x1, %r12b
cmpb $0x1, %al
jne 0xbb29
leaq 0x1ddcb(%rip), %rax     # 0x29dfb
cmpb $0x0, (%rax)
je 0xbb29
movq 0x38(%rbx), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x982d
movq %rax, %rdi
callq 0x1158c
jmp 0xbb29
movq 0x38(%r15), %rdx
movq %r15, %rsi
callq 0xa2cd
jmp 0xbff1