// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movb $0x0, -0x12(%rbp)
movb $0x0, -0x11(%rbp)
movq -0x8(%rbp), %rax
movb $0x0, 0x26(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x25(%rax)
movq -0x8(%rbp), %rdi
leaq -0xa(%rbp), %rsi
leaq -0xc(%rbp), %rdx
leaq -0xe(%rbp), %rcx
leaq -0x10(%rbp), %r8
callq 0x5550
movq -0x8(%rbp), %rax
testb $0x1, 0x24(%rax)
je 0x50b4
movq -0x8(%rbp), %rax
movb $0x0, 0x24(%rax)
jmp 0x5144
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %eax
movzwl -0xe(%rbp), %ecx
cmpl %ecx, %eax
jne 0x5142
movq -0x8(%rbp), %rax
movzwl 0xa(%rax), %eax
movzwl -0x10(%rbp), %ecx
cmpl %ecx, %eax
jne 0x5142
movw -0xa(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x4(%rax)
movw -0xc(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x6(%rax)
movsbl 0xa6cd(%rip), %edx      # 0xf7c0
shll %edx
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %ecx
subl %edx, %ecx
movw %cx, 0x8(%rax)
movsbl 0xa6b6(%rip), %edx      # 0xf7c0
shll %edx
movq -0x8(%rbp), %rax
movzwl 0xa(%rax), %ecx
subl %edx, %ecx
movw %cx, 0xa(%rax)
movq -0x8(%rbp), %rdi
movw -0xa(%rbp), %dx
movw -0xc(%rbp), %cx
movw -0xe(%rbp), %ax
movswl %dx, %esi
movswl %cx, %edx
movzwl %ax, %ecx
movzwl -0x10(%rbp), %r8d
callq 0x5640
jmp 0x5458
jmp 0x5144
movq -0x8(%rbp), %rax
movswl 0x4(%rax), %eax
movswl -0xa(%rbp), %ecx
movzwl -0xe(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jg 0x5194
movq -0x8(%rbp), %rax
movswl 0x6(%rax), %eax
movswl -0xc(%rbp), %ecx
movzwl -0x10(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jg 0x5194
movq -0x8(%rbp), %rax
movswl 0x4(%rax), %eax
movswl -0xa(%rbp), %ecx
cmpl %ecx, %eax
jl 0x5194
movq -0x8(%rbp), %rax
movswl 0x6(%rax), %eax
movswl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jge 0x525a
movb $0x1, -0x12(%rbp)
movq -0x8(%rbp), %rax
movswl 0x4(%rax), %eax
movswl -0xa(%rbp), %ecx
movzwl -0xe(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x51da
movswl -0xa(%rbp), %eax
movzwl -0xe(%rbp), %ecx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
subl %ecx, %eax
movsbl 0xa5f7(%rip), %ecx      # 0xf7c0
shll %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x4(%rax)
jmp 0x51f8
movq -0x8(%rbp), %rax
movswl 0x4(%rax), %eax
movswl -0xa(%rbp), %ecx
cmpl %ecx, %eax
jge 0x51f6
movw -0xa(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x4(%rax)
jmp 0x51f8
movq -0x8(%rbp), %rax
movswl 0x6(%rax), %eax
movswl -0xc(%rbp), %ecx
movzwl -0x10(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x523a
movswl -0xc(%rbp), %eax
movzwl -0x10(%rbp), %ecx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
subl %ecx, %eax
movsbl 0xa597(%rip), %ecx      # 0xf7c0
shll %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x6(%rax)
jmp 0x5258
movq -0x8(%rbp), %rax
movswl 0x6(%rax), %eax
movswl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jge 0x5256
movw -0xc(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x6(%rax)
jmp 0x5258
jmp 0x525a
movq -0x8(%rbp), %rax
movzwl 0x48(%rax), %eax
cmpl $0x0, %eax
je 0x528f
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0x48(%rcx), %ecx
cmpl %ecx, %eax
jge 0x528f
movq -0x8(%rbp), %rax
movw 0x48(%rax), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8(%rax)
movb $0x1, -0x11(%rbp)
movq -0x8(%rbp), %rax
movzwl 0x4a(%rax), %eax
cmpl $0x0, %eax
je 0x52c4
movq -0x8(%rbp), %rax
movzwl 0xa(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0x4a(%rcx), %ecx
cmpl %ecx, %eax
jge 0x52c4
movq -0x8(%rbp), %rax
movw 0x4a(%rax), %cx
movq -0x8(%rbp), %rax
movw %cx, 0xa(%rax)
movb $0x1, -0x11(%rbp)
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %eax
movsbl 0xa4ed(%rip), %ecx      # 0xf7c0
shll %ecx
addl %ecx, %eax
movzwl -0xe(%rbp), %ecx
cmpl %ecx, %eax
jle 0x530f
movw -0xa(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x4(%rax)
movzwl -0xe(%rbp), %eax
movsbl 0xa4ca(%rip), %ecx      # 0xf7c0
shll %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8(%rax)
movb $0x1, -0x11(%rbp)
movb $0x1, -0x12(%rbp)
jmp 0x536a
movq -0x8(%rbp), %rax
movswl 0x4(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
addl %ecx, %eax
movsbl 0xa498(%rip), %ecx      # 0xf7c0
shll %ecx
addl %ecx, %eax
movswl -0xa(%rbp), %ecx
movzwl -0xe(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x5368
movswl -0xa(%rbp), %eax
movzwl -0xe(%rbp), %ecx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
subl %ecx, %eax
movsbl 0xa46b(%rip), %ecx      # 0xf7c0
shll %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x4(%rax)
movb $0x1, -0x12(%rbp)
jmp 0x536a
movq -0x8(%rbp), %rax
movzwl 0xa(%rax), %eax
movsbl 0xa447(%rip), %ecx      # 0xf7c0
shll %ecx
addl %ecx, %eax
movzwl -0x10(%rbp), %ecx
cmpl %ecx, %eax
jle 0x53b5
movw -0xc(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x6(%rax)
movzwl -0x10(%rbp), %eax
movsbl 0xa424(%rip), %ecx      # 0xf7c0
shll %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0xa(%rax)
movb $0x1, -0x11(%rbp)
movb $0x1, -0x12(%rbp)
jmp 0x5410
movq -0x8(%rbp), %rax
movswl 0x6(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
addl %ecx, %eax
movsbl 0xa3f2(%rip), %ecx      # 0xf7c0
shll %ecx
addl %ecx, %eax
movswl -0xc(%rbp), %ecx
movzwl -0x10(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x540e
movswl -0xc(%rbp), %eax
movzwl -0x10(%rbp), %ecx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
subl %ecx, %eax
movsbl 0xa3c5(%rip), %ecx      # 0xf7c0
shll %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x6(%rax)
movb $0x1, -0x12(%rbp)
jmp 0x5410
testb $0x1, -0x12(%rbp)
je 0x5434
movq -0x8(%rbp), %rax
movl (%rax), %edi
movq -0x8(%rbp), %rax
movw 0x4(%rax), %cx
movq -0x8(%rbp), %rax
movswl %cx, %esi
movswl 0x6(%rax), %edx
callq 0x5460
testb $0x1, -0x11(%rbp)
je 0x5458
movq -0x8(%rbp), %rax
movl (%rax), %edi
movq -0x8(%rbp), %rax
movw 0x8(%rax), %cx
movq -0x8(%rbp), %rax
movzwl %cx, %esi
movzwl 0xa(%rax), %edx
callq 0x54e0
addq $0x20, %rsp
popq %rbp
retq
nop