// File: /workspace/github_c_makefile_star2_O0/bobrippling[P]tim/window.c
// Function: window_calc_rects
void window_calc_rects(
		window *topleft,
		const unsigned screentop,
		const unsigned screenwidth,
		const unsigned screenheight)
{
	unsigned nwins_h = 0;
	window *win_h;
	for(win_h = topleft; win_h; win_h = win_h->neighbours.right, nwins_h++);

	const unsigned nvlines = nwins_h + 1;
	const unsigned winspace_v = screenwidth - nvlines;
	unsigned winwidth = winspace_v / nwins_h;

	unsigned i_h;
	for(i_h = 0, win_h = topleft; win_h; win_h = win_h->neighbours.right, i_h++){
		unsigned nwins_v = 0;
		window *win_v;
		for(win_v = win_h; win_v; win_v = win_v->neighbours.below)
			nwins_v++;

		/* final win gets any left over cols */
		if(!win_h->neighbours.right)
			winwidth += winspace_v % nwins_h;

		const unsigned nhlines = nwins_v - 1;
		const unsigned winspace_h = screenheight - nhlines;
		const unsigned winheight = winspace_h / nwins_v;

		unsigned i_v;
		for(i_v = 0, win_v = win_h; win_v; win_v = win_v->neighbours.below, i_v++){
			rect_t r = {
				.x = i_h * (winwidth + 1),
				.y = i_v * (winheight + 1) + screentop,
				.w = winwidth,
				.h = winheight,
			};

			/* final win gets any left over lines */
			if(!win_v->neighbours.below)
				r.h += winspace_h % nwins_v;

			win_v->screen_coord = r;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x12e50
jmp 0x12e39
movq -0x20(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x20(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x12e30
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x10(%rbp), %eax
subl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
xorl %edx, %edx
divl -0x18(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x12f8d
movl $0x0, -0x34(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x12eb4
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x40(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x12e96
movq -0x20(%rbp), %rax
cmpq $0x0, 0x50(%rax)
jne 0x12ecd
movl -0x28(%rbp), %eax
xorl %edx, %edx
divl -0x18(%rbp)
addl -0x2c(%rbp), %edx
movl %edx, -0x2c(%rbp)
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x14(%rbp), %eax
subl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
xorl %edx, %edx
divl -0x34(%rbp)
movl %eax, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x12f71
movl -0x30(%rbp), %eax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
imull %ecx, %eax
movl %eax, -0x60(%rbp)
movl -0x50(%rbp), %eax
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
imull %ecx, %eax
addl -0xc(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x40(%rbp), %rax
cmpq $0x0, 0x58(%rax)
jne 0x12f46
movl -0x48(%rbp), %eax
xorl %edx, %edx
divl -0x34(%rbp)
addl -0x54(%rbp), %edx
movl %edx, -0x54(%rbp)
movq -0x40(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x40(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x12ef9
jmp 0x12f73
movq -0x20(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x20(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x12e7c
popq %rbp
retq
nop