// File: /workspace/github_c_makefile_star2_O2/tudurom[P]windowchef/wm.c
// Function: grid_window
static void
grid_window(struct client *client, uint16_t grid_width, uint16_t grid_height, uint16_t grid_x, uint16_t grid_y, uint16_t occ_w, uint16_t occ_h)
{
	int16_t mon_x, mon_y;
	uint16_t base_w, base_h;
	uint16_t new_w, new_h;
	uint16_t mon_w, mon_h;

	if (client == NULL || grid_x >= grid_width || grid_y >= grid_height)
		return;

	DMSG("Gridding window in grid of size (%d, %d) pos (%d, %d) window size (%d, %d)\n", grid_width, grid_height, grid_x, grid_y, occ_w, occ_h);
	if (is_special(client)) {
		reset_window(client);
		set_focused(client);
	}

	get_monitor_size(client, &mon_x, &mon_y, &mon_w, &mon_h);

	base_w = (mon_w - conf.gap_left - conf.gap_right - (grid_width - 1) * conf.grid_gap
			- grid_width * 2 * conf.border_width) / grid_width;
	base_h = (mon_h - conf.gap_up - conf.gap_down - (grid_height - 1) * conf.grid_gap
			- grid_height * 2 * conf.border_width) / grid_height;
	/* calculate new window size */
	new_w = base_w * occ_w + (occ_w - 1) * (conf.grid_gap + 2 * conf.border_width);

	new_h = base_h * occ_h + (occ_h - 1) * (conf.grid_gap + 2 * conf.border_width);

	client->orig_geom = client->geom;

	client->geom.width = new_w;
	client->geom.height = new_h;

	client->geom.x = mon_x + conf.gap_left + grid_x
		* (conf.border_width + base_w + conf.border_width + conf.grid_gap);
	client->geom.y = mon_y + conf.gap_up + grid_y
		* (conf.border_width + base_h + conf.border_width + conf.grid_gap);

	client->gridded = true;
	client->grid.gx = grid_width;
	client->grid.gy = grid_height;
	client->grid.px = grid_x;
	client->grid.py = grid_y;
	client->grid.sx = occ_w;
	client->grid.sy = occ_h;

	DMSG("w: %d\th: %d\n", new_w, new_h);

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

	xcb_flush(conn);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdi, %rdi
je 0x796b
movl %ecx, %r14d
movl %esi, %r12d
cmpw %r12w, %r14w
jae 0x796b
movl %r8d, %ebp
movl %edx, %r15d
cmpw %r15w, %bp
jae 0x796b
movl %r9d, %r13d
movq %rdi, %rbx
movzwl 0x50(%rsp), %eax
movw %ax, 0x6(%rsp)
callq 0x4dab
testb %al, %al
je 0x793c
movq %rbx, %rdi
callq 0x4dc9
movq %rbx, %rdi
callq 0x5936
movzwl %r14w, %eax
movl %eax, 0x10(%rsp)
movzwl %r12w, %ecx
movzwl %bp, %eax
movl %eax, 0x14(%rsp)
movzwl %r15w, %edi
movq 0x40(%rbx), %rdx
testq %rdx, %rdx
je 0x797a
movzwl 0x10(%rdx), %r10d
movzwl 0x12(%rdx), %eax
movl %eax, 0x8(%rsp)
jmp 0x798c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x0, 0x8(%rsp)
movq 0x4e4f(%rip), %rdx      # 0xc7d8
xorl %r10d, %r10d
movsbl 0x4e10(%rip), %eax      # 0xc7a3
movl %eax, 0xc(%rsp)
movsbl 0x4e08(%rip), %esi      # 0xc7a6
addl %eax, %esi
movzwl 0x14(%rdx), %eax
subl %esi, %eax
pushq $0x1
popq %rsi
movl %esi, %r9d
subl %ecx, %r9d
movsbl 0x4deb(%rip), %r8d      # 0xc7a2
imull %r8d, %r9d
addl %r9d, %eax
movsbl 0x4dda(%rip), %r9d      # 0xc7a0
movl %ecx, %r11d
imull %r9d, %r11d
addl %r11d, %r11d
subl %r11d, %eax
movzwl 0x16(%rdx), %edx
subl %edi, %esi
imull %r8d, %esi
addl %edx, %esi
movl %edi, %edx
imull %r9d, %edx
addl %edx, %edx
subl %edx, %esi
cltd
idivl %ecx
movl %eax, %ecx
movsbl 0x4daf(%rip), %r11d     # 0xc7a5
movsbl 0x4da7(%rip), %eax      # 0xc7a4
addl %r11d, %eax
subl %eax, %esi
leal (%r8,%r9,2), %r8d
movzwl %r13w, %r13d
movl %ecx, %eax
imull %r13d, %eax
leal -0x1(%r13), %r9d
imull %r8d, %r9d
addl %eax, %r9d
movl %esi, %eax
cltd
idivl %edi
movzwl 0x6(%rsp), %edx
leal -0x1(%rdx), %esi
imull %r8d, %esi
addl %r8d, %ecx
addl %eax, %r8d
imull %edx, %eax
addl %eax, %esi
movzwl 0xc(%rbx), %eax
movw %ax, 0x16(%rbx)
movq 0x4(%rbx), %rax
movq %rax, 0xe(%rbx)
movw %r9w, 0x8(%rbx)
movw %si, 0xa(%rbx)
addl 0xc(%rsp), %r10d
imull 0x10(%rsp), %ecx
addl %r10d, %ecx
movl 0x8(%rsp), %eax
addl %r11d, %eax
imull 0x14(%rsp), %r8d
addl %eax, %r8d
movw %cx, 0x4(%rbx)
movw %r8w, 0x6(%rbx)
movb $0x1, 0x28(%rbx)
movw %r12w, 0x18(%rbx)
movw %r15w, 0x1a(%rbx)
movw %r14w, 0x1c(%rbx)
movw %bp, 0x1e(%rbx)
movw %r13w, 0x20(%rbx)
movw %dx, 0x22(%rbx)
movl (%rbx), %edi
movswl %cx, %esi
movswl %r8w, %edx
callq 0x4c44
movl (%rbx), %edi
movzwl 0x8(%rbx), %esi
movzwl 0xa(%rbx), %edx
callq 0x4c9e
movq 0x48fe(%rip), %rdi      # 0xc3b8
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x33f0