// File: /workspace/github_c_makefile_star2_O2/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, %r15
movq %rdx, %rbx
movq %rsi, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
movabsq $0xffff00000000, %r14   # imm = 0xFFFF00000000
testq %rbx, %rbx
je 0x8b36
movq %r15, %rbp
shrq $0x10, %rbp
movq %r15, %r13
shrq $0x20, %r13
movq %r15, %r12
shrq $0x30, %r12
movw %r15w, 0x18(%rbx)
movw %bp, 0x1a(%rbx)
movw %r13w, 0x1c(%rbx)
movw %r12w, 0x1e(%rbx)
cmpq $0x0, 0x10(%rbx)
je 0x87a0
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0xf4ac
movq 0x30(%rbx), %rdx
testq %rdx, %rdx
jne 0x87b4
cmpq $0x0, 0x38(%rbx)
je 0x88fe
movq 0x8(%rsp), %rax
cmpl $0x1, 0x24(%rax)
je 0x87cf
cmpb $0x0, 0x24(%rdx)
jne 0x87cf
movq 0x38(%rbx), %rsi
cmpb $0x0, 0x24(%rsi)
je 0x8828
movq %r15, 0x10(%rsp)
movq %r13, %rsi
movq %r12, %rax
shlq $0x30, %rax
shlq $0x20, %rsi
andq %r14, %rsi
orq %rax, %rsi
movl %r15d, %ecx
orq %rsi, %rcx
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x20(%rsp), %r8
callq 0x8729
movq 0x38(%rbx), %rbx
shlq $0x30, %r12
shlq $0x20, %r13
andq %r14, %r13
orq %r12, %r13
shll $0x10, %ebp
orq %r13, %rbp
movzwl 0x10(%rsp), %r15d
orq %rbp, %r15
jmp 0x8756
cmpl $0x1, 0x4(%rbx)
jne 0x885b
movzwl %r13w, %ecx
cvtsi2sd %ecx, %xmm0
mulsd 0x8(%rbx), %xmm0
cvttsd2si %xmm0, %rax
movzwl 0x20(%rdx), %edi
movzwl 0x20(%rsi), %esi
leal (%rsi,%rdi), %r8d
cmpl %ecx, %r8d
ja 0x88a9
cmpl %edi, %eax
jae 0x8884
cvtsi2sd %edi, %xmm0
jmp 0x8896
cvtsi2sd %r12d, %xmm0
mulsd 0x8(%rbx), %xmm0
cvttsd2si %xmm0, %rax
movzwl 0x22(%rdx), %ecx
movzwl 0x22(%rsi), %esi
leal (%rsi,%rcx), %edi
cmpl %r12d, %edi
ja 0x88e2
cmpl %ecx, %eax
jae 0x88bc
cvtsi2sd %ecx, %xmm0
jmp 0x88cf
subl %esi, %ecx
movzwl %cx, %esi
cmpl %eax, %esi
jae 0x88a9
movl %ecx, %eax
cvtsi2sd %rax, %xmm0
movl %ecx, %edi
movzwl %r13w, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rbx)
movl %edi, %eax
movl %eax, %esi
leal (%r15,%rax), %ecx
movq %rcx, 0x10(%rsp)
subl %eax, %r13d
jmp 0x87d7
movl %r12d, %ecx
subl %esi, %ecx
movzwl %cx, %esi
cmpl %eax, %esi
jae 0x88e2
movl %ecx, %eax
cvtsi2sd %rax, %xmm0
movzwl %r12w, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rbx)
movl %ecx, %eax
addl %eax, %ebp
subl %eax, %r12d
movl $0xffff, %ecx           # imm = 0xFFFF
andl %ecx, %eax
andl %ecx, %r12d
movq %r15, 0x10(%rsp)
movq %r13, %rsi
jmp 0x87da
movq 0x48(%rbx), %rax
testq %rax, %rax
je 0x8b36
movb $0x1, %cl
movq 0x18(%rsp), %rdx
cmpq $0x0, 0x70(%rdx)
jne 0x8931
cmpq $0x0, 0x78(%rdx)
jne 0x8931
movq 0x8(%rsp), %rcx
movq 0x30(%rcx), %rcx
cmpq $0x0, 0x48(%rcx)
sete %cl
leaq 0x204be(%rip), %rdx     # 0x28df6
cmpb $0x1, (%rdx)
jne 0x8954
movq 0x8(%rsp), %rdx
cmpl $0x1, 0x24(%rdx)
jne 0x8954
xorl %r14d, %r14d
cmpl $0x2, 0x308(%rax)
jb 0x8979
leaq 0x2049e(%rip), %rdx     # 0x28df9
movb (%rdx), %dl
notb %dl
orb %cl, %dl
xorl %r14d, %r14d
testb $0x1, %dl
je 0x8979
cmpl $0x3, 0x308(%rax)
je 0x8979
movl 0x300(%rax), %r14d
movq %rbx, %rdi
callq 0xf918
movq %rax, 0x10(%rsp)
movq 0x48(%rbx), %rcx
movl 0x308(%rcx), %edx
cmpl $0x1, %edx
ja 0x8a65
leaq 0x20457(%rip), %rax     # 0x28df7
cmpb $0x1, (%rax)
jne 0x89b2
xorl %esi, %esi
movq 0x8(%rsp), %rax
cmpl $0x1, 0x24(%rax)
je 0x89ba
movq 0x8(%rsp), %rax
movl 0x60(%rax), %esi
leal (%rsi,%r14,2), %r8d
movzwl %r13w, %eax
subl %r8d, %r13d
cmpl %eax, %r8d
pushq $0x1
popq %r9
cmovgel %r9d, %r13d
movl %r12d, %edi
subl %r8d, %edi
cmpl %r12d, %r8d
cmovgel %r9d, %edi
movw %r15w, (%rsp)
movw %bp, 0x2(%rsp)
movw %r13w, 0x4(%rsp)
movw %di, 0x6(%rsp)
cmpl %r9d, %edx
jne 0x8a5f
movl 0x31c(%rcx), %edx
movzwl 0x31e(%rcx), %r8d
cmpw %dx, %r13w
cmovael %edx, %r13d
movw %r13w, 0x4(%rsp)
cmpw %r8w, %di
cmovael %r8d, %edi
movw %di, 0x6(%rsp)
leaq 0x203de(%rip), %rdx     # 0x28e05
cmpb $0x1, (%rdx)
jne 0x8a5f
subl %r14d, %r15d
movzwl %r13w, %edx
addl %esi, %edx
subl %edx, %eax
pushq $0x2
popq %r8
cltd
idivl %r8d
addl %r15d, %eax
movw %ax, (%rsp)
subl %r14d, %ebp
movzwl %di, %eax
addl %esi, %eax
subl %eax, %r12d
movl %r12d, %eax
cltd
idivl %r8d
addl %ebp, %eax
movw %ax, 0x2(%rsp)
movq (%rsp), %rax
jmp 0x8a84
cmpl $0x2, %edx
jne 0x8a77
movq 0x318(%rcx), %rax
movq %rax, (%rsp)
jmp 0x8a8b
movq 0x18(%rsp), %rax
movq 0x4c(%rax), %rax
movq %rax, (%rsp)
movq %rax, 0x320(%rcx)
movq 0x48(%rbx), %rdi
leaq 0x4(%rsp), %rsi
leaq 0x6(%rsp), %r12
movq %r12, %rdx
callq 0x1008b
movq -0x6(%r12), %rdi
movq 0x10(%rsp), %rsi
callq 0x6258
testb %al, %al
jne 0x8b2c
movl (%rbx), %edi
movswl (%rsp), %esi
movswl 0x2(%rsp), %edx
movzwl 0x4(%rsp), %ecx
movzwl 0x6(%rsp), %r8d
callq 0xf602
leaq 0x20350(%rip), %rax     # 0x28e26
cmpb $0x0, (%rax)
jne 0x8b2c
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 0x15afd(%rip), %rsi     # 0x1e610
movl $0x800000, %edi         # imm = 0x800000
xorl %eax, %eax
pushq %r14
movq %r15, %r14
pushq %r11
pushq %r10
callq 0x1d07d
addq $0x20, %rsp
movl (%rbx), %edi
movl %r14d, %esi
callq 0x1043a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq