// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/mbk.c
// Function: render_stos_pp3
static void render_stos_pp3(deark *c, struct pictbank_params *pb, i64 width_in_words)
{
	i64 planesize;
	i64 lump;

	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 * 2;

		// col_idx=0 = the first 32 pixels of the even numbered rows
		// col_idx=width_in_words = the first 32 pixels of the odd numbered rows
		// (TODO: What happens if width_in_words is odd?)
		for(col_idx=0; col_idx<pb->width_in_bytes; col_idx++) {
			i64 col_start_srcpos_in_plane;
			i64 ypos_in_lump;
			UI rowparity;

			if(col_idx & 1) {
				continue; // We process 2 columns at a time
			}

			if(col_idx >= width_in_words) {
				rowparity = 1;
			}
			else {
				rowparity = 0;
			}

			col_start_srcpos_in_plane = lump_start_srcpos_in_plane + col_idx*pb->lines_per_lump;

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

				ypos = lump_start_ypos + ypos_in_lump*2 + rowparity;

				if(rowparity) {
					xpos = (col_idx % width_in_words)*16;
				}
				else {
					xpos = col_idx*16;
				}

				// n=0: the first 8 pixels of every 32   plane 0 lump+0
				// n=1: the second 8 pixels of every 32  plane 0 lump+1
				// n=2: the third 8 pixels of every 32   plane 1 lump+0
				// n=3: the fourth 8 pixels of every 32  plane 1 lump+1
				for(n=0; n<4; n++) {
					u8 v;

					v = dbuf_getbyte(pb->unc_pixels, planesize*(n>>1) +
						col_start_srcpos_in_plane + pb->lines_per_lump*(n&1) + ypos_in_lump);

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

						palent = (v>>(7-i)) & 1;
						de_bitmap_setpixel_rgb(pb->img, xpos, ypos, pb->pal[palent]);
						xpos++;
					}
				}
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
imulq 0x28(%rcx), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0xdd81e
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
imulq 0x20(%rcx), %rax
imulq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
imulq -0x28(%rbp), %rax
shlq %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0xdd80b
movq -0x30(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0xdd6a1
jmp 0xdd7fa
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jl 0xdd6b4
movl $0x1, -0x54(%rbp)
jmp 0xdd6bb
movl $0x0, -0x54(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rdx
imulq 0x20(%rdx), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jge 0xdd7f8
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
shlq %rcx
addq %rcx, %rax
movl -0x54(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
cmpl $0x0, -0x54(%rbp)
je 0xdd71f
movq -0x30(%rbp), %rax
cqto
idivq -0x18(%rbp)
shlq $0x4, %rdx
movq %rdx, -0x68(%rbp)
jmp 0xdd72b
movq -0x30(%rbp), %rax
shlq $0x4, %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x5c(%rbp)
cmpl $0x4, -0x5c(%rbp)
jae 0xdd7e5
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x20(%rbp), %rsi
movl -0x5c(%rbp), %eax
shrl %eax
movl %eax, %eax
imulq %rax, %rsi
addq -0x48(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x5c(%rbp), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq %rcx, %rax
addq %rax, %rsi
addq -0x50(%rbp), %rsi
callq 0x165060
movb %al, -0x71(%rbp)
movl $0x0, -0x58(%rbp)
cmpl $0x8, -0x58(%rbp)
jae 0xdd7d5
movzbl -0x71(%rbp), %eax
movl $0x7, %ecx
subl -0x58(%rbp), %ecx
sarl %cl, %eax
andl $0x1, %eax
movl %eax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x78(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
callq 0x16b310
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0xdd781
jmp 0xdd7d7
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xdd732
jmp 0xdd7e7
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xdd6db
jmp 0xdd7fa
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xdd67c
jmp 0xdd80d
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xdd634
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)