// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/ilbm.c
// Function: do_dlta
static void do_dlta(deark *c, lctx *d, i64 pos1, i64 len)
{
	struct frame_ctx *frctx = d->frctx;
	struct frame_ctx *reference_frctx = NULL;
	struct imgbody_info *ibi = NULL;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);

	if(d->errflag) goto done;
	if(!d->found_bmhd) goto done;
	if(!frctx) goto done;
	if(frctx->done_flag) goto done;
	frctx->done_flag = 1;

	// TODO: Should the imgbody_info be saved somewhere, or recalculated for every frame?
	ibi = de_malloc(c, sizeof(struct imgbody_info));

	do_before_image_chunk(c, d);

	if(!init_imgbody_info(c, d, ibi, 0)) {
		d->errflag = 1;
		goto done;
	}

	// Find the reference frame (if it exists).
	// It is the highest numbered oldfrctx[] item whose index is at most
	// frctx->interleave-1, and which is non-NULL.
	if(frctx->interleave>=2) {
		reference_frctx = d->oldfrctx[1];
		if(!reference_frctx) {
			reference_frctx = d->oldfrctx[0];
		}
	}
	else {
		reference_frctx = d->oldfrctx[0];
	}

	// Allocate buffer for this frame
	if(!frctx->frame_buffer) {
		frctx->frame_buffer = dbuf_create_membuf(c, ibi->frame_buffer_size, 0x1);
	}

	// Start by copying the reference frame to this frame. The decompress function
	// will then modify this frame.
	if(reference_frctx && reference_frctx->frame_buffer) {
		dbuf_copy(reference_frctx->frame_buffer, 0, reference_frctx->frame_buffer->len,
			frctx->frame_buffer);
	}

	switch(frctx->op) {
	case 3:
		decompress_delta_op3(c, d, ibi, frctx, pos1, len);
		break;
	case 5:
		decompress_delta_op5(c, d, ibi, frctx, pos1, len);
		break;
	case 7:
		decompress_delta_op7(c, d, ibi, frctx, pos1, len);
		break;
	case 8:
		decompress_delta_op8(c, d, ibi, frctx, pos1, len);
		break;
	case 74:
		decompress_delta_op74(c, d, ibi, frctx, pos1, len);
		break;
	case 108:
		decompress_delta_op108(c, d, ibi, frctx, pos1, len);
		break;
	default:
		de_err(c, "Unsupported DLTA operation: %d", (int)frctx->op);
		d->errflag = 1;
	}
	if(d->errflag) goto done;

	if(frctx->change_flag || d->opt_anim_includedups) {
		write_frame(c, d, ibi, frctx);
	}
	else {
		de_dbg(c, "[suppressing duplicate frame]");
	}

done:
	// For the summary line, and so we can know when encountering an op for the
	// first time.
	if(frctx) {
		d->delta_ops_used[(size_t)frctx->op] = 1;
	}

	de_free(c, ibi);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x15b580
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
je 0xb0e53
jmp 0xb10fb
movq -0x10(%rbp), %rax
cmpb $0x0, 0x32(%rax)
jne 0xb0e62
jmp 0xb10fb
cmpq $0x0, -0x28(%rbp)
jne 0xb0e6e
jmp 0xb10fb
movq -0x28(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0xb0e7d
jmp 0xb10fb
movq -0x28(%rbp), %rax
movl $0x1, 0x8(%rax)
movq -0x8(%rbp), %rdi
movl $0x68, %esi
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xb2010
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
xorl %ecx, %ecx
callq 0xb22c0
cmpl $0x0, %eax
jne 0xb0ecf
movq -0x10(%rbp), %rax
movl $0x1, 0x1c(%rax)
jmp 0xb10fb
movq -0x28(%rbp), %rax
cmpl $0x2, 0x14(%rax)
jb 0xb0f00
movq -0x10(%rbp), %rax
movq 0xc0(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xb0efe
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0xb0f0f
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0xb0f3b
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rsi
movl $0x1, %edx
callq 0x168020
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
cmpq $0x0, -0x30(%rbp)
je 0xb0f72
movq -0x30(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0xb0f72
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %rdx
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rcx
xorl %eax, %eax
movl %eax, %esi
callq 0x166070
movq -0x28(%rbp), %rax
movzbl 0x10(%rax), %eax
movl %eax, -0x40(%rbp)
subl $0x3, %eax
je 0xb0fc5
jmp 0xb0f84
movl -0x40(%rbp), %eax
subl $0x5, %eax
je 0xb0fe7
jmp 0xb0f8e
movl -0x40(%rbp), %eax
subl $0x7, %eax
je 0xb1009
jmp 0xb0f98
movl -0x40(%rbp), %eax
subl $0x8, %eax
je 0xb102b
jmp 0xb0fa6
movl -0x40(%rbp), %eax
subl $0x4a, %eax
je 0xb104a
jmp 0xb0fb4
movl -0x40(%rbp), %eax
subl $0x6c, %eax
je 0xb1069
jmp 0xb1088
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %r9
callq 0xb4420
jmp 0xb10ad
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %r9
callq 0xb4520
jmp 0xb10ad
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %r9
callq 0xb4720
jmp 0xb10ad
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %r9
callq 0xb4a10
jmp 0xb10ad
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %r9
callq 0xb4c20
jmp 0xb10ad
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %r9
callq 0xb4e00
jmp 0xb10ad
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x10(%rax), %edx
leaq 0x103946(%rip), %rsi    # 0x1b49e1
movb $0x0, %al
callq 0x15bfb0
movq -0x10(%rbp), %rax
movl $0x1, 0x1c(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
je 0xb10b9
jmp 0xb10fb
movq -0x28(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0xb10d0
movq -0x10(%rbp), %rax
movzbl 0x31(%rax), %eax
cmpl $0x0, %eax
je 0xb10e7
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0xb2fc0
jmp 0xb10f9
movq -0x8(%rbp), %rdi
leaq 0xffd4b(%rip), %rsi     # 0x1b0e3d
movb $0x0, %al
callq 0x15b0d0
jmp 0xb10fb
cmpq $0x0, -0x28(%rbp)
je 0xb1116
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
movzbl 0x10(%rcx), %ecx
movb $0x1, 0x8d4(%rax,%rcx)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x15b5a0
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)