// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/ilbm.c
// Function: decompress_delta_op7
static void decompress_delta_op7(deark *c, lctx *d, struct imgbody_info *ibi,
	struct frame_ctx *frctx, i64 pos1, i64 len)
{
	i64 opcodelist_offs[8];
	i64 datalist_offs[8];
	i64 infpos;
	int i;
	int saved_indent_level;
	i64 dataelem_size;
	dbuf *inf = NULL;

	de_dbg_indent_save(c, &saved_indent_level);
	if(!frctx->frame_buffer) goto done;

	de_dbg(c, "[delta7 data]");

	if(frctx->bits & 0xfffffffeU) {
		de_err(c, "Unsupported ANHD options");
		d->errflag = 1;
		goto done;
	}
	if(frctx->bits & 0x00000001) {
		dataelem_size = 4;
	}
	else {
		dataelem_size = 2;
	}

	// We'll have to interleave lots of short reads between two different segments of
	// the file, with no way to know how big either segment is.
	// I see no good way to process this DLTA#7 format, except by first reading the
	// entire chunk into memory.
	if(len > DE_MAX_SANE_OBJECT_SIZE) {
		d->errflag = 1;
		goto done;
	}
	inf = dbuf_create_membuf(c, len, 0);
	dbuf_copy(c->infile, pos1, len, inf);
	infpos = 0;

	for(i=0; i<8; i++) {
		opcodelist_offs[i] = dbuf_getu32be_p(inf, &infpos);
	}

	for(i=0; i<8; i++) {
		datalist_offs[i] = dbuf_getu32be_p(inf, &infpos);
	}

	for(i=0; i<8; i++) {
		if(d->errflag) goto done;
		if(i<ibi->planes_total) {
			de_dbg2(c, "opcode_list[%d] offs: %"I64_FMT, i, opcodelist_offs[i]);
			de_dbg2(c, "data_list[%d] offs: %"I64_FMT, i, datalist_offs[i]);
			if(opcodelist_offs[i]>0) {
				decompress_plane_vdelta(c, d, ibi, frctx, i, inf,
					opcodelist_offs[i], datalist_offs[i], len,
					1, dataelem_size, 1, 0);
			}
		}
	}

done:
	dbuf_close(inf);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, %r13
movq %r8, %r15
movq %rcx, %r12
movq %rdx, 0x8(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x4(%rsp), %rsi
callq 0xe958c
cmpq $0x0, 0x20(%r12)
je 0x7c508
leaq 0xacbe2(%rip), %rsi     # 0x128f87
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x18(%r12), %ecx
cmpl $0x2, %ecx
jae 0x7c4ef
xorl %eax, %eax
testl %ecx, %ecx
setne %cl
cmpq $0x5f5e100, %r13        # imm = 0x5F5E100
jg 0x7c500
movq %r12, 0x18(%rsp)
movb %cl, %al
leaq 0x2(,%rax,2), %rax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0xf0faf
movq %rax, %rbp
movq 0x18(%rbx), %rdi
movq %r15, %rsi
movq %r13, 0x20(%rsp)
movq %r13, %rdx
movq %rax, %rcx
callq 0xefabc
leaq 0x28(%rsp), %r15
movq $0x0, (%r15)
movq %rbp, %rdi
movq %r15, %rsi
callq 0xef34e
movq %rax, 0x70(%rsp,%r12,8)
incq %r12
cmpq $0x8, %r12
jne 0x7c41b
xorl %r12d, %r12d
leaq 0x28(%rsp), %r15
movq %rbp, %rdi
movq %r15, %rsi
callq 0xef34e
movq %rax, 0x30(%rsp,%r12,8)
incq %r12
cmpq $0x8, %r12
jne 0x7c43c
xorl %r15d, %r15d
cmpl $0x0, 0x1c(%r14)
jne 0x7c50a
movq 0x8(%rsp), %rax
cmpq %r15, 0x18(%rax)
jle 0x7c4e0
movq 0x70(%rsp,%r15,8), %r12
movq %rbx, %rdi
leaq 0xacb18(%rip), %rsi     # 0x128f95
movl %r15d, %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0xe93cf
movq 0x30(%rsp,%r15,8), %r13
movq %rbx, %rdi
leaq 0xacb16(%rip), %rsi     # 0x128faf
movl %r15d, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0xe93cf
testq %r12, %r12
jle 0x7c4e0
subq $0x8, %rsp
movq %rbx, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %r15, %r8
movq %rbp, %r9
pushq $0x0
pushq $0x1
pushq 0x28(%rsp)
pushq $0x1
pushq 0x48(%rsp)
pushq %r13
pushq %r12
callq 0x7cc50
addq $0x40, %rsp
incq %r15
cmpq $0x8, %r15
jne 0x7c458
jmp 0x7c50a
leaq 0xac9fc(%rip), %rsi     # 0x128ef2
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movl $0x1, 0x1c(%r14)
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0xf0b13
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq