// File: /workspace/github_c_makefile_star2_O3/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 0xb690
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 0xb70f
movq %rdi, %r15
movq 0x38(%rbx), %rax
cmpq %r12, %rax
je 0xb6c8
testq %rax, %rax
je 0xb6d0
cmpq %r14, %rax
je 0xb6c8
movq 0x40(%rax), %rax
cmpq %r14, %rax
je 0xb6c3
testq %rax, %rax
jne 0xb6b5
cmpq %r14, %rax
jne 0xb6d0
movq $0x0, 0x38(%rbx)
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0xd6b9
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x906b
cmpb $0x1, 0x26(%r12)
jne 0xb6f7
decl 0x40(%r15)
movq 0x40(%r14), %rax
testq %rax, %rax
je 0xb72b
movq 0x30(%rax), %r13
cmpq %r14, %r13
jne 0xb72e
movq 0x38(%rax), %r13
jmp 0xb72e
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbx)
movl $0x1, %edi
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x1e6b8
xorl %r13d, %r13d
movq 0x40(%r12), %rax
movq %rax, 0x40(%r13)
testq %rax, %rax
je 0xb74e
leaq 0x30(%rax), %rdx
leaq 0x38(%rax), %rcx
cmpq %r12, 0x30(%rax)
cmoveq %rdx, %rcx
jmp 0xb752
leaq 0x30(%rbx), %rcx
movq %r13, (%rcx)
cmpb $0x0, 0x24(%r14)
jne 0xb7da
leaq 0x1e675(%rip), %rcx     # 0x29dd8
cmpb $0x1, (%rcx)
jne 0xb7da
leaq 0x1e665(%rip), %rcx     # 0x29dd4
movl (%rcx), %ecx
cmpl $0x2, %ecx
jne 0xb78f
movq 0x40(%r14), %rax
testq %rax, %rax
je 0xb785
cmpq %r14, 0x30(%rax)
je 0xb7cd
movq %r13, %rdi
movl $0x5a, %esi
jmp 0xb7d5
testq %rax, %rax
setne %dl
testl %ecx, %ecx
setne %sil
testb %sil, %dl
jne 0xb7b8
movzwl 0x1c(%r12), %eax
cmpw 0x1e(%r12), %ax
jbe 0xb7c3
movl $0x1, 0x4(%r13)
jmp 0xb7da
cmpl $0x1, %ecx
jne 0xb7da
cmpl $0x0, 0x4(%rax)
je 0xb7ae
movl $0x0, 0x4(%r13)
jmp 0xb7da
movq %r13, %rdi
movl $0x10e, %esi            # imm = 0x10E
callq 0x9815
movq %r12, %rdi
callq 0x4460
movq $0x0, 0x40(%r14)
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x98ae