// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/mbk.c
// Function: render_stos_med4plane
static void render_stos_med4plane(deark *c, struct pictbank_params *pb)
{
	i64 planesize;
	i64 lump;
	UI num_planes = 4;
	UI bits_per_pixel = 2;
	u8 xbuf[4];

	//width_in_bytes = pb->width_in_words*2;
	planesize = pb->width_in_bytes * pb->pseudoheight;

	for(lump=0; lump<pb->height_in_lumps; lump++) {
		i64 col_idx;
		i64 lump_start_srcpos_in_plane;
		i64 lump_start_ypos;

		lump_start_srcpos_in_plane = pb->width_in_bytes * pb->lines_per_lump * lump;
		lump_start_ypos = pb->lines_per_lump * lump;

		for(col_idx=0; col_idx<pb->width_in_bytes; col_idx++) {
			i64 col_start_srcpos_in_plane;
			i64 ypos_in_lump;

			// Each column that we process sets 16 pixels:
			// 8 pixels are set, then 8 pixels skipped, then 8 pixels set.

			col_start_srcpos_in_plane = lump_start_srcpos_in_plane +
				pb->lines_per_lump*col_idx;

			for(ypos_in_lump=0; ypos_in_lump<pb->lines_per_lump; ypos_in_lump++) {
				UI i;
				UI pn;
				i64 xpos1, ypos;

				ypos = lump_start_ypos + ypos_in_lump;

				// xbuf[0..1] are for the first set of 8 pixels.
				// xbuf[2..3] are for the second set.
				for(pn=0; pn<num_planes; pn++) {
					xbuf[pn] = dbuf_getbyte(pb->unc_pixels, planesize*pn +
						col_start_srcpos_in_plane + ypos_in_lump);
				}

				xpos1 = col_idx*16;
				if(col_idx%2) xpos1 -= 8;

				for(i=0; i<8; i++) {
					i64 xpos;
					UI palent;
					UI pixset;

					for(pixset=0; pixset<2; pixset++) {
						palent = 0;
						for(pn=0; pn<bits_per_pixel; pn++) {
							if(xbuf[pixset*2+pn] & (1<<(7-i))) {
								palent |= (1<<pn);
							}
						}
						xpos = xpos1 + pixset*16 + i;
						de_bitmap_setpixel_rgb(pb->img, xpos, ypos, pb->pal[palent]);
					}
				}
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x4, -0x24(%rbp)
movl $0x2, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
imulq 0x28(%rcx), %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0xdda81
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
imulq 0x20(%rcx), %rax
imulq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
imulq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0xdda6e
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
imulq -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jge 0xdda5b
movq -0x48(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0xdd946
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x60(%rbp), %eax
imulq %rax, %rsi
addq -0x50(%rbp), %rsi
addq -0x58(%rbp), %rsi
callq 0x165060
movb %al, %cl
movl -0x60(%rbp), %eax
movb %cl, -0x2c(%rbp,%rax)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0xdd90a
movq -0x38(%rbp), %rax
shlq $0x4, %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0xdd972
movq -0x68(%rbp), %rax
subq $0x8, %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x5c(%rbp)
cmpl $0x8, -0x5c(%rbp)
jae 0xdda48
movl $0x0, -0x80(%rbp)
cmpl $0x2, -0x80(%rbp)
jae 0xdda38
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0xdd9ee
movl -0x80(%rbp), %eax
shll %eax
addl -0x60(%rbp), %eax
movl %eax, %eax
movzbl -0x2c(%rbp,%rax), %eax
movl $0x7, %ecx
subl -0x5c(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0xdd9e1
movl -0x60(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
orl -0x7c(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0xdd9e3
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0xdd9a2
movq -0x68(%rbp), %rax
movl -0x80(%rbp), %ecx
shll $0x4, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movl -0x5c(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x7c(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
callq 0x16b310
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0xdd98a
jmp 0xdda3a
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xdd979
jmp 0xdda4a
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0xdd8e5
jmp 0xdda5d
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xdd8b3
jmp 0xdda70
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xdd86e
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)