// File: /workspace/github_c_makefile_star2_O1/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 0x10ec7
cmpl $0x2, %eax
je 0x10ed9
cmpl $0x1, %eax
jne 0x1112c
cmpl $0x3, 0x308(%rdi)
jne 0x10eea
cmpl $0x2, %eax
je 0x10ed9
cmpl $0x3, %eax
jne 0x1112c
cmpl $0x0, 0x308(%rdi)
je 0x10eea
cmpl $0x2, %eax
jne 0x1112c
movl 0x308(%rdi), %eax
decl %eax
cmpl $0x1, %eax
ja 0x1112c
movl 0x32c(%rdi), %eax
btl $0x8, %eax
jb 0x10f07
xorl %r9d, %r9d
testb $0x10, %al
jne 0x10f1c
xorl %edx, %edx
xorl %r10d, %r10d
xorl %r8d, %r8d
jmp 0x10f2c
movl 0x368(%rdi), %r9d
movl 0x36c(%rdi), %edx
movl %edx, %r10d
movl %r9d, %r8d
jmp 0x10f2c
movl 0x340(%rdi), %r8d
movl 0x344(%rdi), %edx
xorl %r10d, %r10d
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testl $0x110, %eax            # imm = 0x110
je 0x10f69
leaq 0x340(%rdi), %r11
leaq 0x368(%rdi), %rbx
leaq 0x344(%rdi), %r14
leaq 0x36c(%rdi), %r15
testb $0x10, %al
cmoveq %rbx, %r11
movl (%r11), %ebx
cmovneq %r14, %r15
movl (%r15), %r11d
jmp 0x10f6e
xorl %r11d, %r11d
xorl %ebx, %ebx
testb %al, %al
jns 0x1106e
movl 0x35c(%rdi), %ebp
testl %ebp, %ebp
jle 0x1106e
movl 0x364(%rdi), %r12d
testl %r12d, %r12d
jle 0x1106e
movzwl (%rcx), %r14d
subl %r10d, %r14d
jle 0x1106e
movzwl (%rsi), %r15d
subl %r9d, %r15d
jle 0x1106e
cvtsi2sdl 0x360(%rdi), %xmm0
cvtsi2sd %r12d, %xmm1
divsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1106e
cvtsi2sdl 0x358(%rdi), %xmm2
cvtsi2sd %ebp, %xmm3
divsd %xmm3, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x1106e
xorps %xmm3, %xmm3
cvtsi2sd %r15d, %xmm3
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movapd %xmm3, %xmm4
divsd %xmm1, %xmm4
xorpd %xmm5, %xmm5
ucomisd %xmm5, %xmm4
jbe 0x1106e
ucomisd %xmm4, %xmm2
jbe 0x11032
movapd %xmm3, %xmm1
divsd %xmm2, %xmm1
addsd 0xeb91(%rip), %xmm1     # 0x1fbb0
xorps %xmm0, %xmm0
cvtsi2sd %r9d, %xmm0
addsd %xmm3, %xmm0
cvttsd2si %xmm0, %r9d
jmp 0x11055
ucomisd %xmm0, %xmm4
jbe 0x1106e
mulsd %xmm1, %xmm0
addsd 0xeb6c(%rip), %xmm0     # 0x1fbb0
xorps %xmm2, %xmm2
cvtsi2sd %r9d, %xmm2
addsd %xmm0, %xmm2
cvttsd2si %xmm2, %r9d
movw %r9w, (%rsi)
xorps %xmm0, %xmm0
cvtsi2sd %r10d, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r9d
movw %r9w, (%rcx)
movzwl (%rsi), %r9d
cmpl %r9d, %ebx
cmovll %r9d, %ebx
movw %bx, (%rsi)
movzwl (%rcx), %r9d
cmpl %r9d, %r11d
cmovll %r9d, %r11d
movw %r11w, (%rcx)
testb $0x20, %al
je 0x110c5
movl 0x348(%rdi), %r9d
testl %r9d, %r9d
jle 0x110aa
movzwl (%rsi), %r10d
cmpl %r10d, %r9d
cmovgl %r10d, %r9d
movw %r9w, (%rsi)
movl 0x34c(%rdi), %r9d
testl %r9d, %r9d
jle 0x110c5
movzwl (%rcx), %r10d
cmpl %r10d, %r9d
cmovgl %r10d, %r9d
movw %r9w, (%rcx)
testl $0x140, %eax            # imm = 0x140
je 0x11124
movl 0x350(%rdi), %r10d
testl %r10d, %r10d
jle 0x11124
movl 0x354(%rdi), %r9d
testl %r9d, %r9d
jle 0x11124
movzwl (%rsi), %r11d
movl %r11d, %eax
subl %r8d, %eax
movl $0xffff, %ebx           # imm = 0xFFFF
andl %ebx, %eax
xorl %ebp, %ebp
cmpl %r11d, %r8d
cmovgl %ebp, %eax
movzwl (%rcx), %r8d
movl %r8d, %edi
subl %edx, %edi
andl %ebx, %edi
cmpl %r8d, %edx
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