// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/gif.c
// Function: do_image
static int do_image(deark *c, lctx *d, i64 pos1, i64 *bytesused)
{
	int retval = 0;
	struct gif_image_data *gi = NULL;
	de_bitmap *prev_img = NULL;
	u8 disposal_method = 0;

	de_dbg_indent(c, 1);
	gi = de_malloc(c, sizeof(struct gif_image_data));

	retval = do_image_internal(c, d, gi, pos1, bytesused);

	if(!retval) goto done;
	if(d->bad_screen_flag || !gi->img) {
		de_warn(c, "Skipping image due to errors");
		retval = 1;
		goto done;
	}

	if(d->compose) {
		if(d->gce) {
			disposal_method = d->gce->disposal_method;
		}

		if(disposal_method == DISPOSE_PREVIOUS) {
			// In this case, we need to save a copy of the pixels that may
			// be overwritten
			prev_img = de_bitmap_create(c, gi->width, gi->height, 4);
			de_bitmap_copy_rect(d->screen_img, prev_img,
				gi->xpos, gi->ypos, gi->width, gi->height,
				0, 0, 0);
		}

		de_bitmap_copy_rect(gi->img, d->screen_img,
			0, 0, d->screen_img->width, d->screen_img->height,
			gi->xpos, gi->ypos, DE_BITMAPFLAG_MERGE);

		de_bitmap_write_to_file_finfo(d->screen_img, d->fi, DE_CREATEFLAG_OPT_IMAGE);

		if(disposal_method == DISPOSE_BKGD) {
			de_bitmap_rect(d->screen_img, gi->xpos, gi->ypos, gi->width, gi->height,
				DE_STOCKCOLOR_TRANSPARENT, 0);
		}
		else if(disposal_method == DISPOSE_PREVIOUS && prev_img) {
			de_bitmap_copy_rect(prev_img, d->screen_img,
				0, 0, gi->width, gi->height,
				gi->xpos, gi->ypos, 0);
		}
	}
	else {
		de_bitmap_write_to_file_finfo(gi->img, d->fi, 0);
	}

done:
	de_bitmap_destroy(prev_img);
	if(gi) {
		de_bitmap_destroy(gi->img);
		de_free(c, gi->interlace_map);
		de_free(c, gi);
	}

	// A Graphic Control Extension applies only to the next image (or plaintext
	// extension), so if there was one, delete it now that we've used it up.
	discard_current_gce_data(c, d);

	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movb $0x0, -0x39(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movl $0x458, %esi            # imm = 0x458
callq 0x15b780
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
callq 0x74e10
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x7309a
jmp 0x732ae
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x730ae
movq -0x30(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x730cc
movq -0x8(%rbp), %rdi
leaq 0x138a1b(%rip), %rsi    # 0x1abad4
movb $0x0, %al
callq 0x15bc10
movl $0x1, -0x24(%rbp)
jmp 0x732ae
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x73293
movq -0x10(%rbp), %rax
cmpq $0x0, 0x440(%rax)
je 0x730f7
movq -0x10(%rbp), %rax
movq 0x440(%rax), %rax
movb (%rax), %al
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
cmpl $0x3, %eax
jne 0x73173
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdx
movl $0x4, %ecx
callq 0x16b750
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x438(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
movq 0x18(%rax), %r8
movq -0x30(%rbp), %rax
movq 0x20(%rax), %r9
xorl %eax, %eax
xorl %eax, %eax
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0x16ce50
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x438(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x438(%rax), %rax
movq 0x8(%rax), %r8
movq -0x10(%rbp), %rax
movq 0x438(%rax), %rax
movq 0x10(%rax), %r9
movq -0x30(%rbp), %rax
movq 0x8(%rax), %r10
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
xorl %ecx, %ecx
movq %rcx, %rdx
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movl $0x2, 0x10(%rsp)
callq 0x16ce50
movq -0x10(%rbp), %rax
movq 0x438(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x448(%rax), %rsi
movl $0x2, %edx
callq 0x16afa0
movzbl -0x39(%rbp), %eax
cmpl $0x2, %eax
jne 0x73233
movq -0x10(%rbp), %rax
movq 0x438(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x30(%rbp), %rax
movq 0x20(%rax), %r8
xorl %r9d, %r9d
movl $0x0, (%rsp)
callq 0x16cdc0
jmp 0x73291
movzbl -0x39(%rbp), %eax
cmpl $0x3, %eax
jne 0x7328f
cmpq $0x0, -0x38(%rbp)
je 0x7328f
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x438(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x18(%rax), %r8
movq -0x30(%rbp), %rax
movq 0x20(%rax), %r9
movq -0x30(%rbp), %rax
movq 0x8(%rax), %r10
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq %rcx, %rdx
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0x16ce50
jmp 0x73291
jmp 0x732ac
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x448(%rax), %rsi
xorl %edx, %edx
callq 0x16afa0
jmp 0x732ae
movq -0x38(%rbp), %rdi
callq 0x16af60
cmpq $0x0, -0x30(%rbp)
je 0x732e8
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x733e0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x24(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)