// File: /workspace/github_c_makefile_star2_O3/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, 0x18(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, 0x10(%rsp)
testq %rdx, %rdx
je 0x8e2e
movq %rcx, %r12
movq %rdx, %rbx
movabsq $0xffff00000000, %rbp   # imm = 0xFFFF00000000
movq %r12, 0x18(%rbx)
cmpq $0x0, 0x10(%rbx)
je 0x8a64
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x10242
movq %r12, %r14
shrq $0x10, %r14
movq %r12, %r13
shrq $0x20, %r13
movq %r12, %r15
shrq $0x30, %r15
movq 0x30(%rbx), %rdx
testq %rdx, %rdx
jne 0x8a8d
cmpq $0x0, 0x38(%rbx)
je 0x8bf7
movq 0x8(%rsp), %rax
cmpl $0x1, 0x24(%rax)
movq %r14, 0x20(%rsp)
je 0x8aad
cmpb $0x0, 0x24(%rdx)
jne 0x8aad
movq 0x38(%rbx), %rdi
cmpb $0x0, 0x24(%rdi)
je 0x8b10
movq %r12, %r14
movq %r13, %rsi
movq %r15, %rax
shlq $0x30, %rax
shlq $0x20, %rsi
andq %rbp, %rsi
orq %rax, %rsi
movl %r12d, %ecx
orq %rsi, %rcx
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x18(%rsp), %r8
callq 0x8a11
movq 0x38(%rbx), %rbx
shlq $0x30, %r15
shlq $0x20, %r13
andq %rbp, %r13
orq %r15, %r13
movq 0x20(%rsp), %rax
shll $0x10, %eax
orq %r13, %rax
movzwl %r14w, %r12d
orq %rax, %r12
testq %rbx, %rbx
jne 0x8a47
jmp 0x8e2e
cmpl $0x1, 0x4(%rbx)
jne 0x8b49
movzwl %r13w, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd 0x8(%rbx), %xmm0
cvttsd2si %xmm0, %rax
movzwl 0x20(%rdx), %esi
movzwl 0x20(%rdi), %edi
leal (%rdi,%rsi), %r8d
cmpl %ecx, %r8d
ja 0x8ba0
cmpl %esi, %eax
jae 0x8b78
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
jmp 0x8b8d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
mulsd 0x8(%rbx), %xmm0
cvttsd2si %xmm0, %rax
movzwl 0x22(%rdx), %ecx
movzwl 0x22(%rdi), %esi
leal (%rsi,%rcx), %edi
cmpl %r15d, %edi
ja 0x8bd7
cmpl %ecx, %eax
jae 0x8bae
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
jmp 0x8bc4
subl %edi, %ecx
movzwl %cx, %esi
cmpl %eax, %esi
jae 0x8ba0
movl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movl %ecx, %esi
movzwl %r13w, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rbx)
movl %esi, %eax
movl %eax, %esi
leal (%r12,%rax), %r14d
subl %eax, %r13d
jmp 0x8ab3
movl %r15d, %ecx
subl %esi, %ecx
movzwl %cx, %esi
cmpl %eax, %esi
jae 0x8bd7
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, %r14d
movq %r14, 0x20(%rsp)
subl %eax, %r15d
movl $0xffff, %ecx           # imm = 0xFFFF
andl %ecx, %eax
andl %ecx, %r15d
movq %r12, %r14
movq %r13, %rsi
jmp 0x8ab6
movq 0x48(%rbx), %rax
testq %rax, %rax
je 0x8e2e
movb $0x1, %cl
movq 0x10(%rsp), %rdx
cmpq $0x0, 0x70(%rdx)
jne 0x8c2a
cmpq $0x0, 0x78(%rdx)
jne 0x8c2a
movq 0x8(%rsp), %rcx
movq 0x30(%rcx), %rcx
cmpq $0x0, 0x48(%rcx)
sete %cl
leaq 0x211c5(%rip), %rdx     # 0x29df6
cmpb $0x1, (%rdx)
jne 0x8c4c
movq 0x8(%rsp), %rdx
cmpl $0x1, 0x24(%rdx)
jne 0x8c4c
xorl %ebp, %ebp
cmpl $0x2, 0x308(%rax)
jb 0x8c6f
leaq 0x211a6(%rip), %rdx     # 0x29df9
movb (%rdx), %dl
notb %dl
orb %cl, %dl
xorl %ebp, %ebp
testb $0x1, %dl
je 0x8c6f
cmpl $0x3, 0x308(%rax)
je 0x8c6f
movl 0x300(%rax), %ebp
movq %rbx, %rdi
callq 0x106f3
movq %rax, 0x18(%rsp)
movq 0x48(%rbx), %rax
movl 0x308(%rax), %edi
cmpl $0x1, %edi
ja 0x8d64
leaq 0x21161(%rip), %rcx     # 0x29df7
cmpb $0x1, (%rcx)
jne 0x8ca8
xorl %ecx, %ecx
movq 0x8(%rsp), %rdx
cmpl $0x1, 0x24(%rdx)
je 0x8cb0
movq 0x8(%rsp), %rcx
movl 0x60(%rcx), %ecx
leal (%rcx,%rbp,2), %r8d
movzwl %r13w, %esi
subl %r8d, %r13d
cmpl %esi, %r8d
movl $0x1, %r9d
cmovgel %r9d, %r13d
movl %r15d, %edx
subl %r8d, %edx
cmpl %r15d, %r8d
cmovgel %r9d, %edx
movw %r12w, (%rsp)
movw %r14w, 0x2(%rsp)
movw %r13w, 0x4(%rsp)
movw %dx, 0x6(%rsp)
cmpl %r9d, %edi
jne 0x8d5e
movl 0x31c(%rax), %edi
movzwl 0x31e(%rax), %r8d
cmpw %di, %r13w
cmovael %edi, %r13d
movw %r13w, 0x4(%rsp)
cmpw %r8w, %dx
cmovael %r8d, %edx
movw %dx, 0x6(%rsp)
leaq 0x210e5(%rip), %rdi     # 0x29e05
cmpb $0x1, (%rdi)
jne 0x8d5e
subl %ebp, %r12d
movzwl %r13w, %edi
addl %ecx, %edi
subl %edi, %esi
movl %esi, %edi
shrl $0x1f, %edi
addl %esi, %edi
shrl %edi
addl %r12d, %edi
movw %di, (%rsp)
subl %ebp, %r14d
movzwl %dx, %edx
addl %ecx, %edx
subl %edx, %r15d
movl %r15d, %ecx
shrl $0x1f, %ecx
addl %r15d, %ecx
shrl %ecx
addl %r14d, %ecx
movw %cx, 0x2(%rsp)
movq (%rsp), %rcx
jmp 0x8d83
cmpl $0x2, %edi
jne 0x8d76
movq 0x318(%rax), %rax
movq %rax, (%rsp)
jmp 0x8d8a
movq 0x10(%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 0x10ebf
movq -0x6(%r12), %rdi
movq 0x18(%rsp), %rsi
callq 0x630e
testb %al, %al
jne 0x8e25
movl (%rbx), %edi
movswl (%rsp), %esi
movswl 0x2(%rsp), %edx
movzwl 0x4(%rsp), %ecx
movzwl 0x6(%rsp), %r8d
callq 0x103c4
leaq 0x21051(%rip), %rax     # 0x29e26
cmpb $0x0, (%rax)
jne 0x8e25
movq 0x10(%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
movswl 0x2(%rsp), %r14d
subq $0x8, %rsp
leaq 0x16801(%rip), %rsi     # 0x1f610
movl $0x800000, %edi         # imm = 0x800000
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
callq 0x1e6b8
addq $0x20, %rsp
movl (%rbx), %edi
movl %ebp, %esi
callq 0x112d7
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq