// File: /workspace/github_c_makefile_star2_O1/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 %r14
pushq %rbx
movq %rdi, %rbx
movw $0x0, 0x25(%rdi)
testq %rdi, %rdi
je 0x4c1b
movq 0x40(%rbx), %rcx
testq %rcx, %rcx
je 0x4c1b
movzwl 0x10(%rcx), %edx
movzwl 0x12(%rcx), %eax
jmp 0x4c26
movq 0x7bb6(%rip), %rcx      # 0xc7d8
xorl %edx, %edx
xorl %eax, %eax
movzwl 0x16(%rcx), %r8d
movzwl 0x14(%rcx), %ecx
cmpb $0x1, 0x24(%rbx)
jne 0x4c3b
movb $0x0, 0x24(%rbx)
jmp 0x4c81
movzwl 0x8(%rbx), %esi
cmpw %cx, %si
jne 0x4c81
movzwl 0xa(%rbx), %edi
cmpw %r8w, %di
jne 0x4c81
movw %dx, 0x4(%rbx)
movw %ax, 0x6(%rbx)
movsbl 0x7b42(%rip), %r9d      # 0xc7a0
addl %r9d, %r9d
subl %r9d, %esi
movw %si, 0x8(%rbx)
subl %r9d, %edi
movw %di, 0xa(%rbx)
movswl %dx, %esi
movswl %ax, %edx
movq %rbx, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x4ec8
movswl 0x4(%rbx), %edi
movswl %dx, %esi
addl %ecx, %esi
cmpl %edi, %esi
jge 0x4ccb
movsbl 0x7b0b(%rip), %edi      # 0xc7a0
addl %edi, %edi
addl 0x8(%rbx), %edi
movl %esi, %r9d
subl %edi, %r9d
movw %r9w, 0x4(%rbx)
movswl 0x6(%rbx), %r10d
movswl %ax, %r9d
addl %r8d, %r9d
cmpl %r10d, %r9d
jge 0x4cf7
movzwl 0xa(%rbx), %edi
movsbl 0x7ade(%rip), %r10d     # 0xc7a0
leal (%rdi,%r10,2), %edi
subl %edi, %r9d
jmp 0x4d03
movswl 0x6(%rbx), %r9d
cmpw %ax, %r9w
jl 0x4df8
cmpw %dx, %di
jl 0x4df8
movswl %ax, %r10d
addl %r8d, %r10d
cmpl %r9d, %r10d
jl 0x4df8
xorl %edi, %edi
jmp 0x4d0b
movb $0x1, %dil
movl %eax, %r9d
cmpw %ax, %r10w
jge 0x4d0b
movw %r9w, 0x6(%rbx)
movb $0x1, %dil
movzwl 0x48(%rbx), %r9d
testw %r9w, %r9w
je 0x4d27
cmpw %r9w, 0x8(%rbx)
jae 0x4d27
movw %r9w, 0x8(%rbx)
movb $0x1, %bpl
jmp 0x4d29
xorl %ebp, %ebp
movzwl 0x4a(%rbx), %r9d
testw %r9w, %r9w
je 0x4d43
cmpw %r9w, 0xa(%rbx)
jae 0x4d43
movw %r9w, 0xa(%rbx)
movb $0x1, %bpl
movzwl 0x8(%rbx), %r11d
movsbl 0x7a50(%rip), %r9d      # 0xc7a0
leal (%r11,%r9,2), %r14d
movswl %r9w, %r10d
addl %r9d, %r9d
cmpl %ecx, %r14d
jle 0x4d73
movw %dx, 0x4(%rbx)
subl %r10d, %ecx
subl %r10d, %ecx
movw %cx, 0x8(%rbx)
movb $0x1, %bpl
jmp 0x4d89
movswl 0x4(%rbx), %ecx
addl %r9d, %r11d
addl %ecx, %r11d
cmpl %esi, %r11d
jle 0x4d8c
subl %r14d, %esi
movw %si, 0x4(%rbx)
movb $0x1, %dil
movzwl 0xa(%rbx), %ecx
addl %ecx, %r9d
cmpl %r8d, %r9d
jle 0x4dac
movw %ax, 0x6(%rbx)
addl %r10d, %r10d
subl %r10d, %r8d
movw %r8w, 0xa(%rbx)
movb $0x1, %bpl
jmp 0x4dc4
movswl 0x6(%rbx), %ecx
addl %r9d, %ecx
cwtl
addl %eax, %r8d
cmpl %r8d, %ecx
jle 0x4dc7
subl %r9d, %r8d
movw %r8w, 0x6(%rbx)
movb $0x1, %dil
testb %dil, %dil
je 0x4ddb
movl (%rbx), %edi
movswl 0x4(%rbx), %esi
movswl 0x6(%rbx), %edx
callq 0x4e11
testb %bpl, %bpl
je 0x4df3
movl (%rbx), %edi
movzwl 0x8(%rbx), %esi
movzwl 0xa(%rbx), %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x4e79
popq %rbx
popq %r14
popq %rbp
retq
cmpl %edi, %esi
jl 0x4c8e
movl %edx, %r9d
cmpw %dx, %di
jl 0x4ca0
jmp 0x4ca5