// File: /workspace/github_c_makefile_star2_O3/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 0xe8a1c
cmpq $0x0, 0x20(%r12)
je 0x7c115
leaq 0xad205(%rip), %rsi     # 0x1291b7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movl 0x18(%r12), %ecx
cmpl $0x2, %ecx
jae 0x7c0fc
xorl %eax, %eax
testl %ecx, %ecx
setne %cl
cmpq $0x5f5e100, %r13        # imm = 0x5F5E100
jg 0x7c10d
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 0xf09c5
movq %rax, %rbp
movq 0x18(%rbx), %rdi
movq %r15, %rsi
movq %r13, 0x20(%rsp)
movq %r13, %rdx
movq %rax, %rcx
callq 0xef481
leaq 0x28(%rsp), %r15
movq $0x0, (%r15)
movq %rbp, %rdi
movq %r15, %rsi
callq 0xeed31
movq %rax, 0x70(%rsp,%r12,8)
incq %r12
cmpq $0x8, %r12
jne 0x7c028
xorl %r12d, %r12d
leaq 0x28(%rsp), %r15
movq %rbp, %rdi
movq %r15, %rsi
callq 0xeed31
movq %rax, 0x30(%rsp,%r12,8)
incq %r12
cmpq $0x8, %r12
jne 0x7c049
xorl %r15d, %r15d
cmpl $0x0, 0x1c(%r14)
jne 0x7c117
movq 0x8(%rsp), %rax
cmpq %r15, 0x18(%rax)
jle 0x7c0ed
movq 0x70(%rsp,%r15,8), %r12
movq %rbx, %rdi
leaq 0xad13b(%rip), %rsi     # 0x1291c5
movl %r15d, %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0xe87e4
movq 0x30(%rsp,%r15,8), %r13
movq %rbx, %rdi
leaq 0xad139(%rip), %rsi     # 0x1291df
movl %r15d, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0xe87e4
testq %r12, %r12
jle 0x7c0ed
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 0x7c75f
addq $0x40, %rsp
incq %r15
cmpq $0x8, %r15
jne 0x7c065
jmp 0x7c117
leaq 0xad01f(%rip), %rsi     # 0x129122
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movl $0x1, 0x1c(%r14)
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0xf052b
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq