// File: /workspace/github_c_makefile_star2_O3/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:
testq %rdi, %rdi
je 0xb66c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movsd 0x1410e(%rip), %xmm4    # 0x1f608
movl $0xffff, %r14d          # imm = 0xFFFF
movl $0xffff, %r8d           # imm = 0xFFFF
movq %rsi, %r15
shrq $0x10, %r15
movq %rsi, %r12
shrq $0x20, %r12
movq %rsi, %r13
shrq $0x30, %r13
cmpb $0x0, 0x24(%rbx)
jne 0xb65e
movl 0x4(%rbx), %eax
xorl %ecx, %ecx
cmpl $0x1, %eax
movl %r13d, %edx
cmovel %r12d, %edx
movzwl %dx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movl %r15d, %edx
cmovel %esi, %edx
movswl %dx, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
setne %cl
movswl 0x18(%rbx,%rcx,2), %edx
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
movzwl 0x1c(%rbx,%rcx,2), %ecx
xorps %xmm3, %xmm3
cvtsi2sd %ecx, %xmm3
mulsd 0x8(%rbx), %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(%rbx)
movq 0x30(%rbx), %rdi
testq %rdi, %rdi
je 0xb59e
cmpb $0x1, 0x24(%rdi)
jne 0xb5a4
movq 0x38(%rbx), %rdi
jmp 0xb5b3
movq 0x38(%rbx), %rcx
testq %rcx, %rcx
je 0xb5b3
cmpb $0x0, 0x24(%rcx)
je 0xb5c4
movq %rdi, %rbx
testq %rdi, %rdi
jne 0xb51b
jmp 0xb65e
cmpl $0x1, %eax
jne 0xb5ea
movzwl %r12w, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
movl %ecx, %eax
leal (%rsi,%rcx), %ebp
subl %ecx, %r12d
movq %r13, %rcx
jmp 0xb60d
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
addl %ecx, %r15d
subl %ecx, %r13d
andl %r8d, %ecx
andl %r8d, %r13d
movq %rsi, %rbp
movq %r12, %rax
shlq $0x30, %rcx
andq %r14, %rax
shlq $0x20, %rax
orq %rcx, %rax
movl %esi, %esi
orq %rax, %rsi
callq 0xb4db
movq 0x38(%rbx), %rbx
shlq $0x30, %r13
andq %r14, %r12
shlq $0x20, %r12
orq %r13, %r12
shll $0x10, %r15d
orq %r12, %r15
andq %r14, %rbp
orq %r15, %rbp
movq %rbp, %rsi
testq %rbx, %rbx
movsd 0x13fb6(%rip), %xmm4    # 0x1f608
movl $0xffff, %r8d           # imm = 0xFFFF
jne 0xb506
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq