// File: /workspace/github_c_makefile_star2_O2/tudurom[P]windowchef/wm.c
// Function: fit_on_screen
static void
fit_on_screen(struct client *client)
{
	int16_t mon_x, mon_y;
	uint16_t mon_width, mon_height;
	bool will_resize, will_move;

	will_resize = will_move = false;
	client->hmaxed = client->vmaxed = false;
	get_monitor_size(client, &mon_x, &mon_y, &mon_width, &mon_height);
	if (client->maxed) {
		client->maxed = false;
	} else if (client->geom.width == mon_width && client->geom.height == mon_height) {
		client->geom.x = mon_x;
		client->geom.y = mon_y;
		client->geom.width -= 2 * conf.border_width;
		client->geom.height -= 2 * conf.border_width;
		maximize_window(client, mon_x, mon_y, mon_width, mon_height);
		return;
	}

	/* Is it outside the display? */
	if (client->geom.x > mon_x + mon_width || client->geom.y > mon_y + mon_height
			|| client->geom.x < mon_x || client->geom.y < mon_y) {
		will_move = true;
		if (client->geom.x > mon_x + mon_width)
			client->geom.x = mon_x + mon_width - client->geom.width - 2 * conf.border_width;
		else if (client->geom.x < mon_x)
			client->geom.x = mon_x;
		if (client->geom.y > mon_y + mon_height)
			client->geom.y = mon_y + mon_height - client->geom.height - 2 * conf.border_width;
		else if (client->geom.y < mon_y)
			client->geom.y = mon_y;
	}

	/* Is it smaller than it wants to be? */
	if (client->min_width != 0 && client->geom.width < client->min_width) {
		client->geom.width = client->min_width;
		will_resize = true;
	}
	if (client->min_height != 0 && client->geom.height < client->min_height) {
		client->geom.height = client->min_height;

		will_resize = true;
	}

	/* If the window is larger than the screen or is a bit in the outside,
	 * move it to the corner and resize it accordingly. */
	if (client->geom.width + 2 * conf.border_width > mon_width) {
		client->geom.x = mon_x;
		client->geom.width = mon_width - 2 * conf.border_width;
		will_move = will_resize = true;
	} else if (client->geom.x + client->geom.width + 2 * conf.border_width
			> mon_x + mon_width) {
		client->geom.x = mon_x + mon_width - client->geom.width - 2 * conf.border_width;
		will_move = true;
	}

	if (client->geom.height + 2 * conf.border_width > mon_height) {
		client->geom.y = mon_y;
		client->geom.height = mon_height - 2 * conf.border_width;
		will_move = will_resize = true;
	} else if (client->geom.y + client->geom.height + 2 * conf.border_width
			> mon_y + mon_height) {
		client->geom.y = mon_y + mon_height - client->geom.height - 2 * conf.border_width;
		will_move = true;
	}

	if (will_move)
		teleport_window(client->window, client->geom.x, client->geom.y);
	if (will_resize)
		resize_window_absolute(client->window, client->geom.width, client->geom.height);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
andw $0x0, 0x25(%rdi)
movq 0x40(%rdi), %rsi
testq %rsi, %rsi
je 0x4a2d
movzwl 0x10(%rsi), %eax
movzwl 0x12(%rsi), %edx
jmp 0x4a38
movq 0x7da4(%rip), %rsi      # 0xc7d8
xorl %edx, %edx
xorl %eax, %eax
movzwl 0x14(%rsi), %ecx
movzwl 0x16(%rsi), %r8d
cmpb $0x1, 0x24(%rbx)
jne 0x4a4d
movb $0x0, 0x24(%rbx)
jmp 0x4a92
cmpw %cx, 0x8(%rbx)
jne 0x4a92
cmpw %r8w, 0xa(%rbx)
jne 0x4a92
movw %ax, 0x4(%rbx)
movw %dx, 0x6(%rbx)
movsbl 0x7d37(%rip), %esi      # 0xc7a0
addl %esi, %esi
movl %ecx, %edi
subl %esi, %edi
movw %di, 0x8(%rbx)
movl %r8d, %edi
subl %esi, %edi
movw %di, 0xa(%rbx)
movswl %ax, %esi
movswl %dx, %edx
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x4ce2
movswl 0x4(%rbx), %edi
movswl %ax, %esi
addl %ecx, %esi
cmpl %edi, %esi
jge 0x4ae2
movsbl 0x7cf9(%rip), %r9d      # 0xc7a0
addl %r9d, %r9d
addl 0x8(%rbx), %r9d
movl %esi, %edi
subl %r9d, %edi
movw %di, 0x4(%rbx)
movzwl 0x6(%rbx), %r9d
movswl %r9w, %r10d
movswl %dx, %r11d
addl %r8d, %r11d
cmpl %r10d, %r11d
jge 0x4b13
movzwl 0xa(%rbx), %r9d
movsbl 0x7cc7(%rip), %r10d     # 0xc7a0
leal (%r9,%r10,2), %r9d
subl %r9d, %r11d
jmp 0x4b1f
movzwl 0x6(%rbx), %r9d
movswl %r9w, %r10d
movswl %dx, %r11d
addl %r8d, %r11d
cmpl %r10d, %r11d
jl 0x4bb0
cmpw %dx, %r9w
jl 0x4bb0
cmpw %ax, %di
jl 0x4bb0
xorl %r10d, %r10d
jmp 0x4b2a
movb $0x1, %r10b
movl %edx, %r11d
cmpw %dx, %r9w
jge 0x4b2a
movw %r11w, 0x6(%rbx)
movb $0x1, %r10b
movl %r11d, %r9d
movzwl 0x48(%rbx), %r11d
testw %r11w, %r11w
je 0x4b46
cmpw %r11w, 0x8(%rbx)
jae 0x4b46
movw %r11w, 0x8(%rbx)
movb $0x1, %bpl
jmp 0x4b48
xorl %ebp, %ebp
movzwl 0x4a(%rbx), %r11d
testw %r11w, %r11w
je 0x4b62
cmpw %r11w, 0xa(%rbx)
jae 0x4b62
movw %r11w, 0xa(%rbx)
movb $0x1, %bpl
movzwl 0x8(%rbx), %r11d
movsbl 0x7c31(%rip), %r12d     # 0xc7a0
leal (%r11,%r12,2), %r15d
movswl %r12w, %r14d
movl %r12d, %r11d
addl %r12d, %r11d
cmpl %ecx, %r15d
jle 0x4b98
movw %ax, 0x4(%rbx)
subl %r14d, %ecx
subl %r14d, %ecx
movw %cx, 0x8(%rbx)
movb $0x1, %bpl
movb $0x1, %r10b
jmp 0x4bc6
movswl %di, %eax
addl %r15d, %eax
cmpl %esi, %eax
jle 0x4bc4
subl %r15d, %esi
movw %si, 0x4(%rbx)
movb $0x1, %r10b
movl %esi, %eax
jmp 0x4bc6
cmpw %ax, %di
jge 0x4ac7
movw %ax, 0x4(%rbx)
movl %eax, %edi
jmp 0x4ac7
movl %edi, %eax
movzwl 0xa(%rbx), %ecx
addl %ecx, %r11d
cmpl %r8d, %r11d
jle 0x4bf0
movw %dx, 0x6(%rbx)
addl %r14d, %r14d
subl %r14d, %r8d
movw %r8w, 0xa(%rbx)
movl (%rbx), %edi
movswl %ax, %esi
movswl %dx, %edx
callq 0x4c44
jmp 0x4c27
movswl %r9w, %ecx
addl %r11d, %ecx
movswl %dx, %edx
addl %edx, %r8d
cmpl %r8d, %ecx
jle 0x4c0f
subl %r11d, %r8d
movw %r8w, 0x6(%rbx)
movl %r8d, %r9d
jmp 0x4c14
testb %r10b, %r10b
je 0x4c22
movl (%rbx), %edi
movswl %ax, %esi
movswl %r9w, %edx
callq 0x4c44
testb %bpl, %bpl
je 0x4c3b
movl (%rbx), %edi
movzwl 0x8(%rbx), %esi
movzwl 0xa(%rbx), %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x4c9e
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq