// File: /workspace/github_c_makefile_star2_O3/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
movw $0x0, 0x25(%rdi)
movq 0x40(%rdi), %rdx
testq %rdx, %rdx
je 0x4b58
movzwl 0x10(%rdx), %eax
movzwl 0x12(%rdx), %r9d
jmp 0x4b64
movq 0x7c79(%rip), %rdx      # 0xc7d8
xorl %r9d, %r9d
xorl %eax, %eax
movzwl 0x14(%rdx), %ecx
movzwl 0x16(%rdx), %r8d
cmpb $0x1, 0x24(%rbx)
jne 0x4b79
movb $0x0, 0x24(%rbx)
jmp 0x4bc0
cmpw %cx, 0x8(%rbx)
jne 0x4bc0
cmpw %r8w, 0xa(%rbx)
jne 0x4bc0
movw %ax, 0x4(%rbx)
movw %r9w, 0x6(%rbx)
movsbl 0x7c0a(%rip), %edx      # 0xc7a0
addl %edx, %edx
movl %ecx, %esi
subl %edx, %esi
movw %si, 0x8(%rbx)
movl %r8d, %esi
subl %edx, %esi
movw %si, 0xa(%rbx)
movswl %ax, %esi
movswl %r9w, %edx
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x4e27
movswl 0x4(%rbx), %edi
movswl %ax, %edx
addl %ecx, %edx
cmpl %edi, %edx
jge 0x4c0a
movsbl 0x7bcc(%rip), %esi      # 0xc7a0
addl %esi, %esi
addl 0x8(%rbx), %esi
movl %edx, %edi
subl %esi, %edi
movw %di, 0x4(%rbx)
movzwl 0x6(%rbx), %esi
movswl %si, %r10d
movswl %r9w, %r11d
addl %r8d, %r11d
cmpl %r10d, %r11d
jge 0x4c3a
movzwl 0xa(%rbx), %esi
movsbl 0x7b9f(%rip), %r10d     # 0xc7a0
leal (%rsi,%r10,2), %esi
subl %esi, %r11d
jmp 0x4c46
movzwl 0x6(%rbx), %esi
movswl %si, %r10d
movswl %r9w, %r11d
addl %r8d, %r11d
cmpl %r10d, %r11d
jl 0x4cd7
cmpw %r9w, %si
jl 0x4cd7
cmpw %ax, %di
jl 0x4cd7
xorl %r10d, %r10d
jmp 0x4c51
movb $0x1, %r10b
movl %r9d, %r11d
cmpw %r9w, %si
jge 0x4c51
movw %r11w, 0x6(%rbx)
movb $0x1, %r10b
movl %r11d, %esi
movzwl 0x48(%rbx), %r11d
testw %r11w, %r11w
je 0x4c6d
cmpw %r11w, 0x8(%rbx)
jae 0x4c6d
movw %r11w, 0x8(%rbx)
movb $0x1, %bpl
jmp 0x4c6f
xorl %ebp, %ebp
movzwl 0x4a(%rbx), %r11d
testw %r11w, %r11w
je 0x4c89
cmpw %r11w, 0xa(%rbx)
jae 0x4c89
movw %r11w, 0xa(%rbx)
movb $0x1, %bpl
movzwl 0x8(%rbx), %r11d
movsbl 0x7b0a(%rip), %r12d     # 0xc7a0
leal (%r11,%r12,2), %r15d
movswl %r12w, %r14d
movl %r12d, %r11d
addl %r11d, %r11d
cmpl %ecx, %r15d
jle 0x4cbf
movw %ax, 0x4(%rbx)
subl %r14d, %ecx
subl %r14d, %ecx
movw %cx, 0x8(%rbx)
movb $0x1, %bpl
movb $0x1, %r10b
jmp 0x4ced
movswl %di, %eax
addl %r15d, %eax
cmpl %edx, %eax
jle 0x4ceb
subl %r15d, %edx
movw %dx, 0x4(%rbx)
movb $0x1, %r10b
movl %edx, %eax
jmp 0x4ced
cmpw %ax, %di
jge 0x4bf0
movw %ax, 0x4(%rbx)
movl %eax, %edi
jmp 0x4bf0
movl %edi, %eax
movzwl 0xa(%rbx), %ecx
addl %ecx, %r11d
cmpl %r8d, %r11d
jle 0x4d19
movw %r9w, 0x6(%rbx)
addl %r14d, %r14d
subl %r14d, %r8d
movw %r8w, 0xa(%rbx)
movl (%rbx), %edi
movswl %ax, %esi
movswl %r9w, %edx
callq 0x4d70
jmp 0x4d53
movswl %si, %edx
leal (%r11,%rdx), %ecx
movswl %r9w, %esi
addl %esi, %r8d
cmpl %r8d, %ecx
jle 0x4d3f
subl %r11d, %r8d
movw %r8w, 0x6(%rbx)
movl (%rbx), %edi
movswl %r8w, %edx
movswl %ax, %esi
jmp 0x4d49
testb %r10b, %r10b
je 0x4d4e
movl (%rbx), %edi
movswl %ax, %esi
callq 0x4d70
testb %bpl, %bpl
je 0x4d67
movl (%rbx), %edi
movzwl 0x8(%rbx), %esi
movzwl 0xa(%rbx), %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x4dd8
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq