// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/abk.c
// Function: process_pictbank_to_membuf
static void process_pictbank_to_membuf(deark *c, struct amos_pictbank_params *pb,
	dbuf *out_pixdata, i64 out_width)
{
	i64 planesize;
	i64 lump;
	u8 xbuf[8];

	if((size_t)pb->num_planes > sizeof(xbuf)) goto done;
	if(pb->bits_per_pixel != pb->num_planes) goto done;
	de_zeromem(xbuf, sizeof(xbuf));
	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;

			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 xpos, ypos;

				ypos = lump_start_ypos + ypos_in_lump;

				for(pn=0; pn<pb->num_planes; pn++) {
					xbuf[pn] = dbuf_getbyte(pb->unc_pixels, planesize*pn +
						col_start_srcpos_in_plane + ypos_in_lump);
				}

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

					palent = 0;
					for(pn=0; pn<pb->bits_per_pixel; pn++) {
						if(xbuf[pn] & (1<<(7-i))) {
							palent |= (1<<pn);
						}
					}

					xpos = col_idx*8 + i;
					dbuf_writebyte_at(out_pixdata, out_width*ypos+xpos, palent);
				}
			}
		}
	}

	pb->ok = 1;

done:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
cmpq $0x8, %rax
jbe 0x1c5dd
jmp 0x1c7df
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
je 0x1c5f2
jmp 0x1c7df
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x19140
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
imulq 0x28(%rcx), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x1c7d8
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
imulq 0x20(%rcx), %rax
imulq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
imulq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x1c7c5
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
imulq -0x40(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jge 0x1c7b2
movq -0x50(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x78(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x1c6fb
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x28(%rbp), %rsi
movl -0x68(%rbp), %eax
imulq %rax, %rsi
addq -0x58(%rbp), %rsi
addq -0x60(%rbp), %rsi
callq 0x165060
movb %al, %cl
movl -0x68(%rbp), %eax
movb %cl, -0x38(%rbp,%rax)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1c6bb
movl $0x0, -0x64(%rbp)
cmpl $0x8, -0x64(%rbp)
jae 0x1c79f
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jae 0x1c763
movl -0x68(%rbp), %eax
movzbl -0x38(%rbp,%rax), %eax
movl $0x7, %ecx
subl -0x64(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x1c756
movl -0x68(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
orl -0x7c(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0x1c758
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1c71a
movq -0x40(%rbp), %rax
shlq $0x3, %rax
movl -0x64(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
imulq -0x78(%rbp), %rsi
addq -0x70(%rbp), %rsi
movl -0x7c(%rbp), %eax
movzbl %al, %edx
callq 0x168790
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x1c702
jmp 0x1c7a1
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x1c696
jmp 0x1c7b4
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1c664
jmp 0x1c7c7
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x1c61f
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)