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

	n->rectangle = rect;

	if (n->presel != NULL) {
		draw_presel_feedback(m, d, n);
	}

	if (is_leaf(n)) {

		if (n->client == NULL) {
			return;
		}

		unsigned int bw;
		bool the_only_window = !m->prev && !m->next && d->root->client;
		if ((borderless_monocle && d->layout == LAYOUT_MONOCLE && IS_TILED(n->client))
		    || (borderless_singleton && the_only_window)
		    || n->client->state == STATE_FULLSCREEN) {
			bw = 0;
		} else {
			bw = n->client->border_width;
		}

		xcb_rectangle_t r;
		xcb_rectangle_t cr = get_window_rectangle(n);
		client_state_t s = n->client->state;
		/* tiled and pseudo-tiled clients */
		if (s == STATE_TILED || s == STATE_PSEUDO_TILED) {
			int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
			r = rect;
			int bleed = wg + 2 * bw;
			r.width = (bleed < r.width ? r.width - bleed : 1);
			r.height = (bleed < r.height ? r.height - bleed : 1);
			/* pseudo-tiled clients */
			if (s == STATE_PSEUDO_TILED) {
				xcb_rectangle_t f = n->client->floating_rectangle;
				r.width = MIN(r.width, f.width);
				r.height = MIN(r.height, f.height);
				if (center_pseudo_tiled) {
					r.x = rect.x - bw + (rect.width - wg - r.width) / 2;
					r.y = rect.y - bw + (rect.height - wg - r.height) / 2;
				}
			}
			n->client->tiled_rectangle = r;
		/* floating clients */
		} else if (s == STATE_FLOATING) {
			r = n->client->floating_rectangle;
		/* fullscreen clients */
		} else {
			r = m->rectangle;
			n->client->tiled_rectangle = r;
		}

		apply_size_hints(n->client, &r.width, &r.height);

		if (!rect_eq(r, cr)) {
			window_move_resize(n->id, r.x, r.y, r.width, r.height);
			if (!grabbing) {
				put_status(SBSC_MASK_NODE_GEOMETRY, "node_geometry 0x%08X 0x%08X 0x%08X %ux%u+%i+%i\n", m->id, d->id, n->id, r.width, r.height, r.x, r.y);
			}
		}

		window_border_width(n->id, bw);

	} else {
		xcb_rectangle_t first_rect;
		xcb_rectangle_t second_rect;

		if (d->layout == LAYOUT_MONOCLE || n->first_child->vacant || n->second_child->vacant) {
			first_rect = second_rect = rect;
		} else {
			unsigned int fence;
			if (n->split_type == TYPE_VERTICAL) {
				fence = rect.width * n->split_ratio;
				if ((n->first_child->constraints.min_width + n->second_child->constraints.min_width) <= rect.width) {
					if (fence < n->first_child->constraints.min_width) {
						fence = n->first_child->constraints.min_width;
						n->split_ratio = (double) fence / (double) rect.width;
					} else if (fence > (uint16_t) (rect.width - n->second_child->constraints.min_width)) {
						fence = (rect.width - n->second_child->constraints.min_width);
						n->split_ratio = (double) fence / (double) rect.width;
					}
				}
				first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
				second_rect = (xcb_rectangle_t) {rect.x + fence, rect.y, rect.width - fence, rect.height};
			} else {
				fence = rect.height * n->split_ratio;
				if ((n->first_child->constraints.min_height + n->second_child->constraints.min_height) <= rect.height) {
					if (fence < n->first_child->constraints.min_height) {
						fence = n->first_child->constraints.min_height;
						n->split_ratio = (double) fence / (double) rect.height;
					} else if (fence > (uint16_t) (rect.height - n->second_child->constraints.min_height)) {
						fence = (rect.height - n->second_child->constraints.min_height);
						n->split_ratio = (double) fence / (double) rect.height;
					}
				}
				first_rect = (xcb_rectangle_t) {rect.x, rect.y, rect.width, fence};
				second_rect = (xcb_rectangle_t) {rect.x, rect.y + fence, rect.width, rect.height - fence};
			}
		}

		apply_layout(m, d, n->first_child, first_rect, root_rect);
		apply_layout(m, d, n->second_child, second_rect, root_rect);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x20(%rsp)
movq %rcx, %rbp
movq %rdx, %rbx
movq %rsi, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
movabsq $0xffff00000000, %r14   # imm = 0xFFFF00000000
testq %rbx, %rbx
je 0x8f46
movq %rbp, %r13
shrq $0x10, %r13
movq %rbp, %r12
shrq $0x20, %r12
movq %rbp, %r15
shrq $0x30, %r15
movw %bp, 0x18(%rbx)
movw %r13w, 0x1a(%rbx)
movw %r12w, 0x1c(%rbx)
movw %r15w, 0x1e(%rbx)
cmpq $0x0, 0x10(%rbx)
je 0x8b94
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x101d0
cmpq $0x0, 0x30(%rbx)
jne 0x8ba6
cmpq $0x0, 0x38(%rbx)
je 0x8d07
movq 0x8(%rsp), %rax
cmpl $0x1, 0x24(%rax)
je 0x8bc5
movq 0x30(%rbx), %rdx
cmpb $0x0, 0x24(%rdx)
jne 0x8bc5
movq 0x38(%rbx), %rsi
cmpb $0x0, 0x24(%rsi)
je 0x8c21
movq %rbp, 0x10(%rsp)
movq %r12, %rsi
movq %r15, %rax
movq 0x30(%rbx), %rdx
shlq $0x30, %rax
shlq $0x20, %rsi
andq %r14, %rsi
orq %rax, %rsi
movl %ebp, %ecx
orq %rsi, %rcx
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x20(%rsp), %r8
callq 0x8b1d
movq 0x38(%rbx), %rbx
shlq $0x30, %r15
shlq $0x20, %r12
andq %r14, %r12
orq %r15, %r12
shll $0x10, %r13d
orq %r12, %r13
movzwl 0x10(%rsp), %ebp
orq %r13, %rbp
jmp 0x8b4a
cmpl $0x1, 0x4(%rbx)
jne 0x8c58
movzwl %r12w, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd 0x8(%rbx), %xmm0
cvttsd2si %xmm0, %rax
movzwl 0x20(%rdx), %edx
movzwl 0x20(%rsi), %esi
leal (%rsi,%rdx), %edi
cmpl %ecx, %edi
ja 0x8caf
cmpl %edx, %eax
jae 0x8c87
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
jmp 0x8c9c
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
mulsd 0x8(%rbx), %xmm0
cvttsd2si %xmm0, %rax
movzwl 0x22(%rdx), %ecx
movzwl 0x22(%rsi), %edx
leal (%rdx,%rcx), %esi
cmpl %r15d, %esi
ja 0x8cea
cmpl %ecx, %eax
jae 0x8cc1
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
jmp 0x8cd7
subl %esi, %ecx
movzwl %cx, %edx
cmpl %eax, %edx
jae 0x8caf
movl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movl %ecx, %edx
movzwl %r12w, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rbx)
movl %edx, %eax
movl %eax, %esi
leal (%rax,%rbp), %ecx
movq %rcx, 0x10(%rsp)
subl %eax, %r12d
jmp 0x8bcd
movl %r15d, %ecx
subl %edx, %ecx
movzwl %cx, %edx
cmpl %eax, %edx
jae 0x8cea
movl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movzwl %r15w, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rbx)
movl %ecx, %eax
addl %eax, %r13d
subl %eax, %r15d
movl $0xffff, %ecx           # imm = 0xFFFF
andl %ecx, %eax
andl %ecx, %r15d
movq %rbp, 0x10(%rsp)
movq %r12, %rsi
jmp 0x8bd0
movq 0x48(%rbx), %rax
testq %rax, %rax
je 0x8f46
movb $0x1, %cl
movq 0x18(%rsp), %rdx
cmpq $0x0, 0x70(%rdx)
jne 0x8d3a
cmpq $0x0, 0x78(%rdx)
jne 0x8d3a
movq 0x8(%rsp), %rcx
movq 0x30(%rcx), %rcx
cmpq $0x0, 0x48(%rcx)
sete %cl
leaq 0x210b5(%rip), %rdx     # 0x29df6
cmpb $0x1, (%rdx)
jne 0x8d5d
movq 0x8(%rsp), %rdx
cmpl $0x1, 0x24(%rdx)
jne 0x8d5d
xorl %r14d, %r14d
cmpl $0x2, 0x308(%rax)
jb 0x8d82
leaq 0x21095(%rip), %rdx     # 0x29df9
movb (%rdx), %dl
notb %dl
orb %cl, %dl
xorl %r14d, %r14d
testb $0x1, %dl
je 0x8d82
cmpl $0x3, 0x308(%rax)
je 0x8d82
movl 0x300(%rax), %r14d
movq %rbx, %rdi
callq 0x1066f
movq %rax, 0x10(%rsp)
movq 0x48(%rbx), %rax
movl 0x308(%rax), %edi
cmpl $0x1, %edi
ja 0x8e75
leaq 0x2104e(%rip), %rcx     # 0x29df7
cmpb $0x1, (%rcx)
jne 0x8dbb
xorl %ecx, %ecx
movq 0x8(%rsp), %rdx
cmpl $0x1, 0x24(%rdx)
je 0x8dc3
movq 0x8(%rsp), %rcx
movl 0x60(%rcx), %ecx
leal (%rcx,%r14,2), %r8d
movzwl %r12w, %esi
subl %r8d, %r12d
cmpl %esi, %r8d
movl $0x1, %r9d
cmovgel %r9d, %r12d
movl %r15d, %edx
subl %r8d, %edx
cmpl %r15d, %r8d
cmovgel %r9d, %edx
movw %bp, (%rsp)
movw %r13w, 0x2(%rsp)
movw %r12w, 0x4(%rsp)
movw %dx, 0x6(%rsp)
cmpl %r9d, %edi
jne 0x8e6f
movl 0x31c(%rax), %edi
movzwl 0x31e(%rax), %r8d
cmpw %di, %r12w
cmovael %edi, %r12d
movw %r12w, 0x4(%rsp)
cmpw %r8w, %dx
cmovael %r8d, %edx
movw %dx, 0x6(%rsp)
leaq 0x20fd3(%rip), %rdi     # 0x29e05
cmpb $0x1, (%rdi)
jne 0x8e6f
subl %r14d, %ebp
movzwl %r12w, %edi
addl %ecx, %edi
subl %edi, %esi
movl %esi, %edi
shrl $0x1f, %edi
addl %esi, %edi
shrl %edi
addl %ebp, %edi
movw %di, (%rsp)
subl %r14d, %r13d
movzwl %dx, %edx
addl %ecx, %edx
subl %edx, %r15d
movl %r15d, %ecx
shrl $0x1f, %ecx
addl %r15d, %ecx
shrl %ecx
addl %r13d, %ecx
movw %cx, 0x2(%rsp)
movq (%rsp), %rcx
jmp 0x8e94
cmpl $0x2, %edi
jne 0x8e87
movq 0x318(%rax), %rax
movq %rax, (%rsp)
jmp 0x8e9b
movq 0x18(%rsp), %rcx
movq 0x4c(%rcx), %rcx
movq %rcx, (%rsp)
movq %rcx, 0x320(%rax)
movq 0x48(%rbx), %rdi
leaq 0x4(%rsp), %rsi
leaq 0x6(%rsp), %r12
movq %r12, %rdx
callq 0x10e94
movq -0x6(%r12), %rdi
movq 0x10(%rsp), %rsi
callq 0x6398
testb %al, %al
jne 0x8f3c
movl (%rbx), %edi
movswl (%rsp), %esi
movswl 0x2(%rsp), %edx
movzwl 0x4(%rsp), %ecx
movzwl 0x6(%rsp), %r8d
callq 0x10349
leaq 0x20f40(%rip), %rax     # 0x29e26
cmpb $0x0, (%rax)
jne 0x8f3c
movq 0x18(%rsp), %rax
movl 0x20(%rax), %edx
movq 0x8(%rsp), %rax
movl 0x20(%rax), %ecx
movl (%rbx), %r8d
movzwl 0x4(%rsp), %r9d
movzwl 0x6(%rsp), %r10d
movswl (%rsp), %r11d
movq %r14, %r15
movswl 0x2(%rsp), %r14d
subq $0x8, %rsp
leaq 0x166fd(%rip), %rsi     # 0x1f620
movl $0x800000, %edi         # imm = 0x800000
xorl %eax, %eax
pushq %r14
movq %r15, %r14
pushq %r11
pushq %r10
callq 0x1eb0b
addq $0x20, %rsp
movl (%rbx), %edi
movl %r14d, %esi
callq 0x112cb
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq