// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/ilbm.c
// Function: do_delta74_blocks
static void do_delta74_blocks(deark *c, struct d74state *d74s)
{
	i64 blkidx, rowidx, planeidx, byteidx;
	i64 d74_bytes_per_row_per_plane;

	// Reportedly, the 'offset' field assumes a potentially-different measuring
	// system than one would expect.
	d74_bytes_per_row_per_plane = (d74s->ibi->width + 7)/8;

	for(blkidx=0; blkidx<d74s->nblocks; blkidx++) {
		i64 offset;
		i64 block_srcpos = d74s->pos;
		i64 block_dstpos;

		if(d74s->pos+2 >= d74s->endpos) goto done;
		offset = de_getu16be_p(&d74s->pos);

		block_dstpos = (offset / d74_bytes_per_row_per_plane) * d74s->ibi->frame_buffer_rowspan +
			(offset % d74_bytes_per_row_per_plane);

		for(rowidx=0; rowidx<d74s->nrows; rowidx++) {
			for(planeidx=0; planeidx<d74s->ibi->planes_total; planeidx++) {
				i64 dstpos;

				// Calculate the offset in our frame buffer.
				dstpos = block_dstpos + (rowidx * d74s->ibi->frame_buffer_rowspan) +
					planeidx * d74s->ibi->bytes_per_row_per_plane;

				for(byteidx=0; byteidx<d74s->nbytes; byteidx++) {
					u8 val;

					val = de_getbyte_p(&d74s->pos);
					if(d74s->op) val ^= dbuf_getbyte(d74s->frctx->frame_buffer, dstpos);
					dbuf_writebyte_at(d74s->frctx->frame_buffer, dstpos, val);
					dstpos++;
				}
			}
		}

		if((d74s->pos - block_srcpos) & 0x1) {
			d74s->pos++; // padding byte
		}
	}

done:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
addq $0x7, %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, -0x38(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jge 0xb5d08
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x2, %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jl 0xb5b6d
jmp 0xb5d0a
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x10, %rsi
callq 0x165210
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cqto
idivq -0x38(%rbp)
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imulq 0x48(%rcx), %rax
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rax
cqto
idivq -0x38(%rbp)
movq -0x68(%rbp), %rax
addq %rdx, %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jge 0xb5ccf
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x18(%rcx), %rax
jge 0xb5cbc
movq -0x50(%rbp), %rax
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rdx
movq (%rdx), %rdx
imulq 0x48(%rdx), %rcx
addq %rcx, %rax
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rdx
movq (%rdx), %rdx
imulq 0x40(%rdx), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jge 0xb5ca9
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x10, %rsi
callq 0x165170
movb %al, -0x59(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0xb5c73
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rdi
movq -0x58(%rbp), %rsi
callq 0x165060
movzbl %al, %ecx
movzbl -0x59(%rbp), %eax
xorl %ecx, %eax
movb %al, -0x59(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rdi
movq -0x58(%rbp), %rsi
movzbl -0x59(%rbp), %edx
callq 0x168790
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xb5c22
jmp 0xb5cab
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xb5bd7
jmp 0xb5cbe
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xb5bbd
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
subq -0x48(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0xb5cf5
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rax)
jmp 0xb5cf7
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xb5b34
jmp 0xb5d0a
addq $0x70, %rsp
popq %rbp
retq