// File: /workspace/github_c_makefile_star2_O3/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:
testq %rdi, %rdi
je 0x812d
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %r14d
movl %esi, %r12d
cmpw %r12w, %r14w
jae 0x811f
movl %r8d, %ebp
movl %edx, %r15d
cmpw %r15w, %bp
jae 0x811f
movl %r9d, %r13d
movq %rdi, %rbx
cmpb $0x0, 0x24(%rdi)
jne 0x7f7e
cmpb $0x0, 0x26(%rbx)
jne 0x7f7e
cmpb $0x0, 0x25(%rbx)
jne 0x7f7e
cmpb $0x0, 0x27(%rbx)
jne 0x7f7e
cmpb $0x1, 0x28(%rbx)
jne 0x7fac
movq %rbx, %rdi
callq 0x4f0a
movq %rbx, %rdi
callq 0x4f9e
movl (%rbx), %esi
leaq 0x14(%rsp), %rcx
movl $0x0, (%rcx)
movq 0x4416(%rip), %rdi      # 0xc3b8
movl $0x40, %edx
callq 0x3200
movzwl %r14w, %eax
movl %eax, 0xc(%rsp)
movzwl %r12w, %ecx
movzwl %bp, %eax
movl %eax, 0x10(%rsp)
movzwl %r15w, %edi
movq 0x40(%rbx), %rdx
testq %rdx, %rdx
je 0x7fdb
movzwl 0x10(%rdx), %r10d
movzwl 0x12(%rdx), %eax
movl %eax, 0x4(%rsp)
jmp 0x7fed
movl $0x0, 0x4(%rsp)
movq 0x47ee(%rip), %rdx      # 0xc7d8
xorl %r10d, %r10d
movsbl 0x47af(%rip), %eax      # 0xc7a3
movl %eax, 0x8(%rsp)
movsbl 0x47a7(%rip), %esi      # 0xc7a6
addl %eax, %esi
movzwl 0x14(%rdx), %eax
subl %esi, %eax
movl $0x1, %esi
subl %ecx, %esi
movsbl 0x478c(%rip), %r8d      # 0xc7a2
imull %r8d, %esi
addl %esi, %eax
movsbl 0x477c(%rip), %r9d      # 0xc7a0
movl %ecx, %esi
imull %r9d, %esi
addl %esi, %esi
subl %esi, %eax
movzwl 0x16(%rdx), %edx
movl $0x1, %esi
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 0x474f(%rip), %r11d     # 0xc7a5
movsbl 0x4747(%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 0x50(%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 0x8(%rsp), %r10d
imull 0xc(%rsp), %ecx
addl %r10d, %ecx
movl 0x4(%rsp), %eax
addl %r11d, %eax
imull 0x10(%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 0x4d70
movl (%rbx), %edi
movzwl 0x8(%rbx), %esi
movzwl 0xa(%rbx), %edx
callq 0x4dd8
movq 0x429e(%rip), %rdi      # 0xc3b8
callq 0x3400
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq