// File: /workspace/github_c_makefile_star2_O2/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 0x13887(%rip), %xmm4    # 0x1e608
movl $0xffff, %ebx           # imm = 0xFFFF
movl $0xffff, %r8d           # imm = 0xFFFF
movq %rsi, %r14
shrq $0x10, %r14
movq %rsi, %r15
shrq $0x20, %r15
movq %rsi, %r12
shrq $0x30, %r12
testq %rdi, %rdi
je 0xaed3
movq %rdi, %r13
cmpb $0x0, 0x24(%rdi)
jne 0xaed3
movl 0x4(%r13), %eax
xorl %ecx, %ecx
cmpl $0x1, %eax
movl %r12d, %edx
cmovel %r15d, %edx
movzwl %dx, %edx
cvtsi2sd %edx, %xmm0
movl %r14d, %edx
cmovel %esi, %edx
movswl %dx, %edx
cvtsi2sd %edx, %xmm1
setne %cl
movswl 0x18(%r13,%rcx,2), %edx
cvtsi2sd %edx, %xmm2
movzwl 0x1c(%r13,%rcx,2), %ecx
cvtsi2sd %ecx, %xmm3
mulsd 0x8(%r13), %xmm3
addsd %xmm2, %xmm3
subsd %xmm1, %xmm3
divsd %xmm0, %xmm3
xorpd %xmm1, %xmm1
maxsd %xmm3, %xmm1
movapd %xmm4, %xmm0
minsd %xmm1, %xmm0
movsd %xmm0, 0x8(%r13)
movq 0x30(%r13), %rdi
testq %rdi, %rdi
je 0xae29
cmpb $0x1, 0x24(%rdi)
jne 0xae32
movq 0x38(%r13), %rdi
jmp 0xada1
movq 0x38(%r13), %rcx
testq %rcx, %rcx
je 0xada1
cmpb $0x0, 0x24(%rcx)
jne 0xada1
cmpl $0x1, %eax
jne 0xae6c
movzwl %r15w, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
movl %ecx, %eax
leal (%rsi,%rcx), %ebp
subl %ecx, %r15d
movq %r12, %rcx
jmp 0xae8c
cvtsi2sd %r12d, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
addl %ecx, %r14d
subl %ecx, %r12d
andl %r8d, %ecx
andl %r8d, %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 0xad6e
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 0x1373a(%rip), %xmm4    # 0x1e608
jmp 0xad86
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq