// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, 0x20(%rsp)
movq (%rsi), %rax
movq (%rax), %rcx
leaq 0x7(%rcx), %rax
addq $0xe, %rcx
testq %rax, %rax
cmovnsq %rax, %rcx
movq %rcx, 0x10(%rsp)
cmpq $0x0, 0x28(%rsi)
jle 0x7d4f5
movq %rsi, %rbx
sarq $0x3, 0x10(%rsp)
leaq 0x10(%rsi), %r15
xorl %eax, %eax
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rcx
leaq 0x2(%rsi), %rdx
cmpq %rcx, %rdx
jge 0x7d4f5
movq %rsi, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rdi
movq %r15, %rsi
callq 0xef193
cqto
idivq 0x10(%rsp)
movq %rdx, 0x18(%rsp)
cmpq $0x0, 0x30(%rbx)
jle 0x7d4c3
movq (%rbx), %rcx
imulq 0x48(%rcx), %rax
addq %rax, 0x18(%rsp)
movq $0x0, (%rsp)
movq (%rbx), %rax
cmpq $0x0, 0x18(%rax)
jle 0x7d4ae
movq $0x0, 0x8(%rsp)
cmpq $0x0, 0x38(%rbx)
jle 0x7d494
movq 0x48(%rax), %rcx
imulq (%rsp), %rcx
addq 0x18(%rsp), %rcx
movq 0x40(%rax), %r12
imulq 0x8(%rsp), %r12
addq %rcx, %r12
xorl %r14d, %r14d
leaq (%r12,%r14), %r13
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rdi
movq %r15, %rsi
callq 0xef14d
movl %eax, %ebp
cmpl $0x0, 0x20(%rbx)
je 0x7d477
movq 0x8(%rbx), %rax
movq 0x20(%rax), %rdi
movq %r13, %rsi
callq 0xef0d5
xorb %al, %bpl
movq 0x8(%rbx), %rax
movq 0x20(%rax), %rdi
movzbl %bpl, %edx
movq %r13, %rsi
callq 0xf148e
incq %r14
cmpq 0x38(%rbx), %r14
jl 0x7d447
movq 0x8(%rsp), %rdx
incq %rdx
movq (%rbx), %rax
movq %rdx, 0x8(%rsp)
cmpq 0x18(%rax), %rdx
jl 0x7d422
movq (%rsp), %rcx
incq %rcx
movq %rcx, (%rsp)
cmpq 0x30(%rbx), %rcx
jl 0x7d40b
movq (%r15), %rax
movl %eax, %ecx
subl 0x28(%rsp), %ecx
testb $0x1, %cl
movq 0x30(%rsp), %rcx
je 0x7d4dc
incq %rax
movq %rax, (%r15)
cmpq 0x38(%rsp), %rcx
movq 0x40(%rsp), %rax
jge 0x7d4f5
incq %rax
cmpq 0x28(%rbx), %rax
jl 0x7d3a5
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq