// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/gif.c
// Function: de_run_gif
static void de_run_gif(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 pos;
	i64 bytesused = 0;
	u8 block_type;
	const char *blk_name;

	d = de_malloc(c, sizeof(lctx));
	d->compose = 1;
	d->fi = de_finfo_create(c);

	if(de_get_ext_option(c, "gif:raw")) {
		d->compose = 0;
		// TODO: It would be more consistent to extract an *image* of each
		// plain text extension, but we don't support that, so extract them
		// as text files instead.
		d->dump_plaintext_ext = 1;
	}
	if(de_get_ext_option(c, "gif:dumpplaintext")) {
		d->dump_plaintext_ext = 1;
	}
	if(de_get_ext_option(c, "gif:dumpscreen")) {
		// This lets the user see what the screen looks like after the last
		// "graphic rendering block" has been disposed of.
		d->dump_screen = 1;
	}

	pos = 0;
	if(!do_read_header(c, d, pos)) goto done;
	pos += 6;
	if(!do_read_screen_descriptor(c, d, pos)) goto done;
	pos += 7;
	if(!do_read_global_color_table(c, d, pos, &bytesused)) goto done;
	pos += bytesused;

	// If we're fully rendering the frames, create a "screen" image to
	// track the current state of the animation.
	if(d->compose) {
		if(!de_good_image_dimensions(c, d->screen_w, d->screen_h)) {
			// Try to continue. There could be other interesting things in the file.
			d->bad_screen_flag = 1;
			d->screen_w = 1;
			d->screen_h = 1;
		}
		d->screen_img = de_bitmap_create(c, d->screen_w, d->screen_h, 4);
	}

	while(1) {
		if(pos >= c->infile->len) {
			on_unexpected_eof(c, d);
			goto done;
		}
		block_type = de_getbyte(pos);

		switch(block_type) {
		case 0x2c: blk_name="image"; break;
		case 0x3b: blk_name="trailer"; break;
		case 0x21: blk_name="extension"; break;
		default: blk_name="?"; break;
		}

		de_dbg(c, "block type 0x%02x (%s) at %"I64_FMT, (UI)block_type, blk_name, pos);
		pos++;

		switch(block_type) {
		case 0x3b:
			goto found_trailer;
		case 0x21:
			if(!do_read_extension(c, d, pos, &bytesused)) goto done;
			pos += bytesused;
			break;
		case 0x2c:
			if(!do_image(c, d, pos, &bytesused)) goto done;
			pos += bytesused;
			break;
		default:
			de_err(c, "Unknown block type: 0x%02x", (unsigned int)block_type);
			goto done;
		}
	}

found_trailer:
	do_after_trailer(c, d, pos);

done:
	if(d) {
		if(d->screen_img) {
			if(d->dump_screen) {
				de_finfo_set_name_from_sz(c, d->fi, "screen", 0, DE_ENCODING_LATIN1);
				de_bitmap_write_to_file_finfo(d->screen_img, d->fi, DE_CREATEFLAG_OPT_IMAGE);
				de_finfo_set_name_from_sz(c, d->fi, NULL, 0, DE_ENCODING_LATIN1);
			}
			de_bitmap_destroy(d->screen_img);
		}
		discard_current_gce_data(c, d);
		de_finfo_destroy(c, d->fi);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl $0x450, %esi            # imm = 0x450
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x448(%rax)
movq -0x8(%rbp), %rdi
leaq 0x139120(%rip), %rsi    # 0x1ab66e
callq 0x15cb30
cmpq $0x0, %rax
je 0x7256e
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movl $0x1, 0xc(%rax)
movq -0x8(%rbp), %rdi
leaq 0x1390fd(%rip), %rsi    # 0x1ab676
callq 0x15cb30
cmpq $0x0, %rax
je 0x7258f
movq -0x18(%rbp), %rax
movl $0x1, 0xc(%rax)
movq -0x8(%rbp), %rdi
leaq 0x1390ee(%rip), %rsi    # 0x1ab688
callq 0x15cb30
cmpq $0x0, %rax
je 0x725b0
movq -0x18(%rbp), %rax
movl $0x1, 0x8(%rax)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x729a0
cmpl $0x0, %eax
jne 0x725d3
jmp 0x72804
movq -0x20(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x72a60
cmpl $0x0, %eax
jne 0x725fa
jmp 0x72804
movq -0x20(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x28(%rbp), %rcx
callq 0x72d30
cmpl $0x0, %eax
jne 0x72625
jmp 0x72804
movq -0x28(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x726a7
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x7267b
movq -0x18(%rbp), %rax
movl $0x1, 0x4(%rax)
movq -0x18(%rbp), %rax
movq $0x1, 0x18(%rax)
movq -0x18(%rbp), %rax
movq $0x1, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdx
movl $0x4, %ecx
callq 0x16b750
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x438(%rax)
jmp 0x726a9
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x726cd
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x72dd0
jmp 0x72804
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165060
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %eax
movl %eax, -0x3c(%rbp)
subl $0x21, %eax
je 0x7271d
jmp 0x726ef
movl -0x3c(%rbp), %eax
subl $0x2c, %eax
je 0x72703
jmp 0x726f9
movl -0x3c(%rbp), %eax
subl $0x3b, %eax
je 0x72710
jmp 0x7272a
leaq 0x13dd5a(%rip), %rax    # 0x1b0464
movq %rax, -0x38(%rbp)
jmp 0x72735
leaq 0x164ae2(%rip), %rax    # 0x1d71f9
movq %rax, -0x38(%rbp)
jmp 0x72735
leaq 0x138b4e(%rip), %rax    # 0x1ab272
movq %rax, -0x38(%rbp)
jmp 0x72735
leaq 0x1454fc(%rip), %rax    # 0x1b7c2d
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x29(%rbp), %edx
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %r8
leaq 0x138f4b(%rip), %rsi    # 0x1ab697
xorl %eax, %eax
callq 0x15b0d0
movq -0x20(%rbp), %rax
incq %rax
movq %rax, -0x20(%rbp)
movzbl -0x29(%rbp), %eax
movl %eax, -0x40(%rbp)
subl $0x21, %eax
je 0x72782
jmp 0x7276c
movl -0x40(%rbp), %eax
subl $0x2c, %eax
je 0x727ac
jmp 0x72776
movl -0x40(%rbp), %eax
subl $0x3b, %eax
jne 0x727d6
jmp 0x72780
jmp 0x727f3
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x28(%rbp), %rcx
callq 0x72e10
cmpl $0x0, %eax
jne 0x7279e
jmp 0x72804
movq -0x28(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x727ee
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x28(%rbp), %rcx
callq 0x73020
cmpl $0x0, %eax
jne 0x727c8
jmp 0x72804
movq -0x28(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x727ee
movq -0x8(%rbp), %rdi
movzbl -0x29(%rbp), %edx
leaq 0x138ed0(%rip), %rsi    # 0x1ab6b5
movb $0x0, %al
callq 0x15bfb0
jmp 0x72804
jmp 0x726a9
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x73310
cmpq $0x0, -0x18(%rbp)
je 0x728c8
movq -0x18(%rbp), %rax
cmpq $0x0, 0x438(%rax)
je 0x7289a
movq -0x18(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x7288a
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x448(%rax), %rsi
leaq 0x149610(%rip), %rdx    # 0x1bbe4d
xorl %ecx, %ecx
movl $0x5, %r8d
callq 0x15d4c0
movq -0x18(%rbp), %rax
movq 0x438(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x448(%rax), %rsi
movl $0x2, %edx
callq 0x16afa0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x448(%rax), %rsi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
movl $0x5, %r8d
callq 0x15d4c0
movq -0x18(%rbp), %rax
movq 0x438(%rax), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x733e0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x448(%rax), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nop