// File: /workspace/github_c_makefile_star2_O1/baskerville[P]bspwm/src/monitor.c
// Function: adapt_geometry
void adapt_geometry(xcb_rectangle_t *rs, xcb_rectangle_t *rd, node_t *n)
{
	for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
		if (f->client == NULL) {
			continue;
		}
		client_t *c = f->client;
		/* Clip the rectangle to fit into the monitor.	Without this, the fitting
		 * algorithm doesn't work as expected. This also conserves the
		 * out-of-bounds regions */
		int left_adjust = MAX((rs->x - c->floating_rectangle.x), 0);
		int top_adjust = MAX((rs->y - c->floating_rectangle.y), 0);
		int right_adjust = MAX((c->floating_rectangle.x + c->floating_rectangle.width) - (rs->x + rs->width), 0);
		int bottom_adjust = MAX((c->floating_rectangle.y + c->floating_rectangle.height) - (rs->y + rs->height), 0);
		c->floating_rectangle.x += left_adjust;
		c->floating_rectangle.y += top_adjust;
		c->floating_rectangle.width -= (left_adjust + right_adjust);
		c->floating_rectangle.height -= (top_adjust + bottom_adjust);

		int dx_s = c->floating_rectangle.x - rs->x;
		int dy_s = c->floating_rectangle.y - rs->y;

		int nume_x = dx_s * (rd->width - c->floating_rectangle.width);
		int nume_y = dy_s * (rd->height - c->floating_rectangle.height);

		int deno_x = rs->width - c->floating_rectangle.width;
		int deno_y = rs->height - c->floating_rectangle.height;

		int dx_d = (deno_x == 0 ? 0 : nume_x / deno_x);
		int dy_d = (deno_y == 0 ? 0 : nume_y / deno_y);

		/* Translate and undo clipping */
		c->floating_rectangle.width += left_adjust + right_adjust;
		c->floating_rectangle.height += top_adjust + bottom_adjust;
		c->floating_rectangle.x = rd->x + dx_d - left_adjust;
		c->floating_rectangle.y = rd->y + dy_d - top_adjust;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, (%rsp)
movq %rdi, %r15
movq %rdx, 0x10(%rsp)
movq %rdx, %rdi
callq 0x92fd
testq %rax, %rax
je 0x6f9a
movq %rax, %rdi
movq 0x48(%rdi), %r9
testq %r9, %r9
je 0x6f84
movswl (%r15), %esi
movswl 0x318(%r9), %eax
movl %esi, %r10d
subl %eax, %r10d
xorl %ecx, %ecx
testl %r10d, %r10d
cmovlel %ecx, %r10d
movswl 0x2(%r15), %r8d
movswl 0x31a(%r9), %ebp
movl %r8d, %r11d
subl %ebp, %r11d
testl %r11d, %r11d
cmovlel %ecx, %r11d
movzwl 0x31c(%r9), %r14d
movzwl 0x4(%r15), %ebx
leal (%rax,%r14), %edx
addl %esi, %ebx
subl %ebx, %edx
testl %edx, %edx
cmovlel %ecx, %edx
movzwl 0x31e(%r9), %r12d
movzwl 0x6(%r15), %esi
leal (%r12,%rbp), %ebx
addl %r8d, %esi
subl %esi, %ebx
testl %ebx, %ebx
cmovlel %ecx, %ebx
addl %r10d, %eax
movw %ax, 0x318(%r9)
addl %r11d, %ebp
movw %bp, 0x31a(%r9)
addl %r10d, %edx
movq %r14, 0x20(%rsp)
movl %r14d, %r13d
subl %edx, %r13d
movw %r13w, 0x31c(%r9)
addl %r11d, %ebx
movq %r12, 0x18(%rsp)
movl %r12d, %r14d
subl %ebx, %r14d
movw %r14w, 0x31e(%r9)
movswl 0x2(%r15), %edx
movl %edx, 0xc(%rsp)
movq (%rsp), %rdx
movzwl 0x6(%rdx), %esi
movzwl 0x4(%r15), %r12d
movzwl 0x6(%r15), %ebx
movl $0x0, %r8d
cmpw %r13w, %r12w
je 0x6f29
movzwl %r13w, %edx
subl %edx, %r12d
movswl %ax, %r8d
movswl (%r15), %eax
subl %eax, %r8d
movq (%rsp), %rax
movzwl 0x4(%rax), %eax
subl %edx, %eax
imull %r8d, %eax
cltd
idivl %r12d
movl %eax, %r8d
cmpw %r14w, %bx
je 0x6f48
movswl %bp, %eax
subl 0xc(%rsp), %eax
movzwl %r14w, %ecx
subl %ecx, %esi
imull %eax, %esi
subl %ecx, %ebx
movl %esi, %eax
cltd
idivl %ebx
movl %eax, %ecx
movq 0x20(%rsp), %rax
movw %ax, 0x31c(%r9)
movq 0x18(%rsp), %rax
movw %ax, 0x31e(%r9)
subl %r10d, %r8d
movq (%rsp), %rax
addw (%rax), %r8w
movw %r8w, 0x318(%r9)
subl %r11d, %ecx
addw 0x2(%rax), %cx
movw %cx, 0x31a(%r9)
movq 0x10(%rsp), %rsi
callq 0x9363
movq %rax, %rdi
testq %rax, %rax
jne 0x6e22
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq