// File: /workspace/github_c_makefile_star2_O1/baskerville[P]bspwm/src/tree.c
// Function: adjust_ratios
void adjust_ratios(node_t *n, xcb_rectangle_t rect)
{
#define NULL_OR_VACANT(n) ((n) == NULL || (n)->vacant)
	if (NULL_OR_VACANT(n)) {
		return;
	}

	double ratio;

	if (n->split_type == TYPE_VERTICAL) {
		double position = (double) n->rectangle.x + n->split_ratio * (double) n->rectangle.width;
		ratio = (position - (double) rect.x) / (double) rect.width;
	} else {
		double position = (double) n->rectangle.y + n->split_ratio * (double) n->rectangle.height;
		ratio = (position - (double) rect.y) / (double) rect.height;
	}

	ratio = MAX(0.0, ratio);
	ratio = MIN(1.0, ratio);
	n->split_ratio = ratio;

	xcb_rectangle_t first_rect;
	xcb_rectangle_t second_rect;
	unsigned int fence;

	if (NULL_OR_VACANT(n->first_child)) {
		adjust_ratios(n->second_child, rect);
		return;
	}
	if (NULL_OR_VACANT(n->second_child)) {
		adjust_ratios(n->first_child, rect);
		return;
	}
#undef NULL_OR_VACANT

	if (n->split_type == TYPE_VERTICAL) {
		fence = rect.width * n->split_ratio;
		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;
		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};
	}

	adjust_ratios(n->first_child, first_rect);
	adjust_ratios(n->second_child, second_rect);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movsd 0x14150(%rip), %xmm3    # 0x1f618
movl $0xffff, %ebx           # imm = 0xFFFF
movl $0xffff, %r9d           # imm = 0xFFFF
movq %rsi, %r14
shrq $0x10, %r14
movq %rsi, %r15
shrq $0x20, %r15
movq %rsi, %r12
shrq $0x30, %r12
testq %rdi, %rdi
je 0xb636
movq %rdi, %r13
cmpb $0x0, 0x24(%rdi)
jne 0xb636
movl 0x4(%r13), %eax
cmpl $0x1, %eax
jne 0xb517
leaq 0x18(%r13), %r8
leaq 0x1c(%r13), %rdi
movq %rsi, %rdx
movq %r15, %rcx
jmp 0xb525
leaq 0x1a(%r13), %r8
leaq 0x1e(%r13), %rdi
movq %r14, %rdx
movq %r12, %rcx
movswl (%r8), %r8d
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
movzwl (%rdi), %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
mulsd 0x8(%r13), %xmm1
addsd %xmm0, %xmm1
movswl %dx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
subsd %xmm0, %xmm1
movzwl %cx, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
divsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
maxsd %xmm1, %xmm2
movapd %xmm3, %xmm0
minsd %xmm2, %xmm0
movsd %xmm0, 0x8(%r13)
movq 0x30(%r13), %rdi
testq %rdi, %rdi
je 0xb586
cmpb $0x1, 0x24(%rdi)
jne 0xb58f
movq 0x38(%r13), %rdi
jmp 0xb4e8
movq 0x38(%r13), %rcx
testq %rcx, %rcx
je 0xb4e8
cmpb $0x0, 0x24(%rcx)
jne 0xb4e8
cmpl $0x1, %eax
jne 0xb5cc
movzwl %r15w, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
movl %ecx, %eax
leal (%rsi,%rcx), %ebp
subl %ecx, %r15d
movq %r12, %rcx
jmp 0xb5ef
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
addl %ecx, %r14d
subl %ecx, %r12d
andl %r9d, %ecx
andl %r9d, %r12d
movq %rsi, %rbp
movq %r15, %rax
shlq $0x30, %rcx
andq %rbx, %rax
shlq $0x20, %rax
orq %rcx, %rax
movl %esi, %esi
orq %rax, %rsi
callq 0xb4b5
movq 0x38(%r13), %rdi
shlq $0x30, %r12
andq %rbx, %r15
shlq $0x20, %r15
orq %r12, %r15
shll $0x10, %r14d
orq %r15, %r14
andq %rbx, %rbp
orq %r14, %rbp
movq %rbp, %rsi
movsd 0x13fe7(%rip), %xmm3    # 0x1f618
jmp 0xb4cd
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq