// File: /workspace/github_c_makefile_star2_O2/baskerville[P]bspwm/src/tree.c
// Function: unlink_node
void unlink_node(monitor_t *m, desktop_t *d, node_t *n)
{
	if (d == NULL || n == NULL) {
		return;
	}

	node_t *p = n->parent;

	if (p == NULL) {
		d->root = NULL;
		d->focus = NULL;
		put_status(SBSC_MASK_REPORT);
	} else {
		if (d->focus == p || is_descendant(d->focus, n)) {
			d->focus = NULL;
		}

		history_remove(d, p, false);
		cancel_presel(m, d, p);

		if (p->sticky) {
			m->sticky_count--;
		}

		node_t *b = brother_tree(n);
		node_t *g = p->parent;

		b->parent = g;

		if (g != NULL) {
			if (is_first_child(p)) {
				g->first_child = b;
			} else {
				g->second_child = b;
			}
		} else {
			d->root = b;
		}

		if (!n->vacant && removal_adjustment) {
			if (automatic_scheme == SCHEME_SPIRAL) {
				if (is_first_child(n)) {
					rotate_tree(b, 270);
				} else {
					rotate_tree(b, 90);
				}
			} else if (automatic_scheme == SCHEME_LONGEST_SIDE || g == NULL) {
				if (p != NULL) {
					if (p->rectangle.width > p->rectangle.height) {
						b->split_type = TYPE_VERTICAL;
					} else {
						b->split_type = TYPE_HORIZONTAL;
					}
				}
			} else if (automatic_scheme == SCHEME_ALTERNATE) {
				if (g->split_type == TYPE_HORIZONTAL) {
					b->split_type = TYPE_VERTICAL;
				} else {
					b->split_type = TYPE_HORIZONTAL;
				}
			}
		}

		free(p);
		n->parent = NULL;

		propagate_flags_upward(m, d, b);
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
testq %rsi, %rsi
sete %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
je 0xaf05
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rdx, %r14
movq %rsi, %rbx
movq 0x40(%rdx), %r12
testq %r12, %r12
je 0xaf83
movq %rdi, %r15
movq 0x38(%rbx), %rdi
cmpq %r12, %rdi
je 0xaf2c
movq %r14, %rsi
callq 0x9892
testb %al, %al
je 0xaf31
andq $0x0, 0x38(%rbx)
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0xcb44
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x8d19
cmpb $0x1, 0x26(%r12)
jne 0xaf58
decl 0x40(%r15)
movq %r14, %rdi
callq 0xa4b2
movq %rax, %r13
movq 0x40(%r12), %rax
movq %rax, 0x40(%r13)
testq %rax, %rax
je 0xaf9d
leaq 0x30(%rax), %rdx
leaq 0x38(%rax), %rcx
cmpq %r12, 0x30(%rax)
cmoveq %rdx, %rcx
jmp 0xafa1
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbx)
pushq $0x1
popq %rdi
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x1d07d
leaq 0x30(%rbx), %rcx
movq %r13, (%rcx)
cmpb $0x0, 0x24(%r14)
jne 0xb024
leaq 0x1de26(%rip), %rcx     # 0x28dd8
cmpb $0x1, (%rcx)
jne 0xb024
leaq 0x1de16(%rip), %rcx     # 0x28dd4
movl (%rcx), %ecx
cmpl $0x2, %ecx
jne 0xafdc
movq 0x40(%r14), %rax
testq %rax, %rax
je 0xafd4
cmpq %r14, 0x30(%rax)
je 0xb017
pushq $0x5a
popq %rsi
movq %r13, %rdi
jmp 0xb01f
testq %rax, %rax
setne %dl
testl %ecx, %ecx
setne %sil
testb %sil, %dl
jne 0xb005
movzwl 0x1c(%r12), %eax
cmpw 0x1e(%r12), %ax
jbe 0xb010
movl $0x1, 0x4(%r13)
jmp 0xb024
cmpl $0x1, %ecx
jne 0xb024
cmpl $0x0, 0x4(%rax)
je 0xaffb
andl $0x0, 0x4(%r13)
jmp 0xb024
movq %r13, %rdi
movl $0x10e, %esi            # imm = 0x10E
callq 0x941b
movq %r12, %rdi
callq 0x4460
andq $0x0, 0x40(%r14)
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x94a1