// File: /workspace/github_c_makefile_star2_O3/baskerville[P]bspwm/src/window.c
// Function: apply_size_hints
void apply_size_hints(client_t *c, uint16_t *width, uint16_t *height)
{
	if (!SHOULD_HONOR_SIZE_HINTS(c->honor_size_hints, c->state)) {
		return;
	}

	int32_t minw = 0, minh = 0;
	int32_t basew = 0, baseh = 0, real_basew = 0, real_baseh = 0;

	if (c->size_hints.flags & XCB_ICCCM_SIZE_HINT_BASE_SIZE) {
		basew = c->size_hints.base_width;
		baseh = c->size_hints.base_height;
		real_basew = basew;
		real_baseh = baseh;
	} else if (c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE) {
		/* base size is substituted with min size if not specified */
		basew = c->size_hints.min_width;
		baseh = c->size_hints.min_height;
	}

	if (c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE) {
		minw = c->size_hints.min_width;
		minh = c->size_hints.min_height;
	} else if (c->size_hints.flags & XCB_ICCCM_SIZE_HINT_BASE_SIZE) {
		/* min size is substituted with base size if not specified */
		minw = c->size_hints.base_width;
		minh = c->size_hints.base_height;
	}

	/* Handle the size aspect ratio */
	if (c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_ASPECT &&
	    c->size_hints.min_aspect_den > 0 &&
	    c->size_hints.max_aspect_den > 0 &&
	    *height > real_baseh &&
	    *width > real_basew) {
		/* ICCCM mandates:
		 * If a base size is provided along with the aspect ratio fields, the base size should be subtracted from the
		 * window size prior to checking that the aspect ratio falls in range. If a base size is not provided, nothing
		 * should be subtracted from the window size. (The minimum size is not to be used in place of the base size for
		 * this purpose.)
		 */
		double dx = *width - real_basew;
		double dy = *height - real_baseh;
		double ratio = dx / dy;
		double min = c->size_hints.min_aspect_num / (double) c->size_hints.min_aspect_den;
		double max = c->size_hints.max_aspect_num / (double) c->size_hints.max_aspect_den;

		if (max > 0 && min > 0 && ratio > 0) {
			if (ratio < min) {
				/* dx is lower than allowed, make dy lower to compensate this (+ 0.5 to force proper rounding). */
				dy = dx / min + 0.5;
				*width  = dx + real_basew;
				*height = dy + real_baseh;
			} else if (ratio > max) {
				/* dx is too high, lower it (+0.5 for proper rounding) */
				dx = dy * max + 0.5;
				*width  = dx + real_basew;
				*height = dy + real_baseh;
			}
		}
	}

	/* Handle the minimum size */
	*width = MAX(*width, minw);
	*height = MAX(*height, minh);

	/* Handle the maximum size */
	if (c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE)
	{
		if (c->size_hints.max_width > 0) {
			*width = MIN(*width, c->size_hints.max_width);
		}
		if (c->size_hints.max_height > 0) {
			*height = MIN(*height, c->size_hints.max_height);
		}
	}

	/* Handle the size increment */
	if (c->size_hints.flags & (XCB_ICCCM_SIZE_HINT_P_RESIZE_INC | XCB_ICCCM_SIZE_HINT_BASE_SIZE) &&
	    c->size_hints.width_inc > 0 && c->size_hints.height_inc > 0) {
		uint16_t t1 = *width, t2 = *height;
		unsigned_subtract(t1, basew);
		unsigned_subtract(t2, baseh);
		*width -= t1 % c->size_hints.width_inc;
		*height -= t2 % c->size_hints.height_inc;
	}
}

// Assembly:
movq %rdx, %rcx
movl 0x328(%rdi), %eax
cmpl $0x3, %eax
je 0x10f3a
cmpl $0x2, %eax
je 0x10ee2
cmpl $0x1, %eax
jne 0x10f43
cmpl $0x3, 0x308(%rdi)
jne 0x10eef
jmp 0x10f43
movl 0x308(%rdi), %eax
decl %eax
cmpl $0x1, %eax
ja 0x10f43
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl 0x32c(%rdi), %eax
btl $0x8, %eax
jb 0x10f44
xorl %edx, %edx
movl $0x0, %r9d
movl $0x0, %ebx
movl $0x0, %r8d
movl $0x0, %r10d
movl $0x0, %r11d
testb $0x10, %al
je 0x10f6e
movl 0x340(%rdi), %edx
movl 0x344(%rdi), %r8d
xorl %r9d, %r9d
xorl %ebx, %ebx
jmp 0x10f60
cmpl $0x0, 0x308(%rdi)
je 0x10eef
retq
movl 0x368(%rdi), %edx
movl 0x36c(%rdi), %r9d
movl %edx, %ebx
movl %r9d, %r8d
movl %r9d, %r10d
movl %edx, %r11d
testb $0x10, %al
je 0x10f6e
movl 0x340(%rdi), %r11d
movl 0x344(%rdi), %r10d
testb %al, %al
jns 0x11081
movl 0x35c(%rdi), %ebp
testl %ebp, %ebp
jle 0x11081
movl 0x364(%rdi), %r15d
testl %r15d, %r15d
jle 0x11081
movzwl (%rcx), %r14d
subl %r9d, %r14d
jle 0x11081
movzwl (%rsi), %r12d
subl %ebx, %r12d
jle 0x11081
cvtsi2sdl 0x360(%rdi), %xmm0
cvtsi2sd %r15d, %xmm1
divsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x11081
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
cvtsi2sd %ebp, %xmm3
movd %r12d, %xmm2
movd 0x358(%rdi), %xmm4
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
cvtdq2pd %xmm2, %xmm2
movapd %xmm1, %xmm4
unpcklpd %xmm3, %xmm4            # xmm4 = xmm4[0],xmm3[0]
movapd %xmm2, %xmm3
divpd %xmm4, %xmm3
xorpd %xmm4, %xmm4
cmpltpd %xmm3, %xmm4
movmskpd %xmm4, %ebp
movl %ebp, %r14d
shrb %r14b
je 0x11081
testb $0x1, %bpl
je 0x11081
movapd %xmm3, %xmm4
unpckhpd %xmm3, %xmm4            # xmm4 = xmm4[1],xmm3[1]
ucomisd %xmm3, %xmm4
jbe 0x11048
movapd %xmm2, %xmm1
divsd %xmm4, %xmm1
addsd 0xeb71(%rip), %xmm1     # 0x1fba8
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %ebx
jmp 0x11069
ucomisd %xmm0, %xmm3
jbe 0x11081
mulsd %xmm1, %xmm0
addsd 0xeb4e(%rip), %xmm0     # 0x1fba8
xorps %xmm2, %xmm2
cvtsi2sd %ebx, %xmm2
addsd %xmm0, %xmm2
cvttsd2si %xmm2, %ebx
movw %bx, (%rsi)
xorps %xmm0, %xmm0
cvtsi2sd %r9d, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r9d
movw %r9w, (%rcx)
movzwl (%rsi), %r9d
cmpl %r9d, %r11d
cmovll %r9d, %r11d
movw %r11w, (%rsi)
movzwl (%rcx), %r9d
cmpl %r9d, %r10d
cmovll %r9d, %r10d
movw %r10w, (%rcx)
testb $0x20, %al
je 0x110d9
movl 0x348(%rdi), %r9d
testl %r9d, %r9d
jle 0x110be
movzwl (%rsi), %r10d
cmpl %r10d, %r9d
cmoval %r10d, %r9d
movw %r9w, (%rsi)
movl 0x34c(%rdi), %r9d
testl %r9d, %r9d
jle 0x110d9
movzwl (%rcx), %r10d
cmpl %r10d, %r9d
cmoval %r10d, %r9d
movw %r9w, (%rcx)
testl $0x140, %eax            # imm = 0x140
je 0x11136
movl 0x350(%rdi), %r10d
testl %r10d, %r10d
jle 0x11136
movl 0x354(%rdi), %r9d
testl %r9d, %r9d
jle 0x11136
movzwl (%rsi), %r11d
movl %r11d, %eax
subl %edx, %eax
movl $0xffff, %ebx           # imm = 0xFFFF
andl %ebx, %eax
xorl %ebp, %ebp
cmpl %r11d, %edx
cmovgl %ebp, %eax
movzwl (%rcx), %edx
movl %edx, %edi
subl %r8d, %edi
andl %ebx, %edi
cmpl %edx, %r8d
cmovgl %ebp, %edi
xorl %edx, %edx
divl %r10d
subl %edx, %r11d
movw %r11w, (%rsi)
movl %edi, %eax
xorl %edx, %edx
divl %r9d
subw %dx, (%rcx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq