// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/fli.c
// Function: do_chunk_FLI_FLC
static void do_chunk_FLI_FLC(deark *c, lctx *d, struct chunk_info_type *ci)
{
	i64 pos = ci->dpos;
	i64 scr_width, scr_height;
	i64 n;
	struct image_ctx_type *ictx = NULL;
	double fps = 0.0;
	int can_decode_images = 1;

	d->main_chunktype = ci->chunktype;
	if(d->main_chunktype==CHUNKTYPE_FLI) {
		de_declare_fmt(c, "FLI");
	}
	else if(d->main_chunktype==CHUNKTYPE_FLC) {
		de_declare_fmt(c, "FLC");
	}
	else {
		de_warn(c, "Unrecognized signature (0x%04x). This might not be a FLI/FLC file.",
			d->main_chunktype);
	}

	d->num_frames = de_getu16le_p(&pos);
	de_dbg(c, "num frames: %d", (int)d->num_frames);

	scr_width = de_getu16le_p(&pos);
	scr_height = de_getu16le_p(&pos);
	de_dbg(c, "screen dimensions: %"I64_FMT DE_CHAR_TIMES "%"I64_FMT, scr_width, scr_height);

	d->depth = (int)de_getu16le_p(&pos);
	de_dbg(c, "depth: %d", d->depth);
	if(d->depth==0) d->depth = 8;
	pos += 2; // flags

	n = de_getu32le_p(&pos);
	if(ci->chunktype==CHUNKTYPE_FLI && n!=0) {
		fps = 70.0/(double)n;
	}
	else if(ci->chunktype==CHUNKTYPE_FLC && n!=0) {
		fps = 1000.0/(double)n;
	}
	de_dbg(c, "speed: %"I64_FMT" (%.4f frames/sec)", n, fps);

	pos += 2; // reserved

	if(ci->chunktype==CHUNKTYPE_FLI) {
		if(scr_width==320 && scr_height==200) {
			d->aspect_x = 6;
			d->aspect_y = 5;
		}
	}

	if(ci->chunktype==CHUNKTYPE_FLC) {
		read_timestamp(c, d, pos, &d->create_timestamp, "create");
		pos += 4;
		dbg_id(c, d, pos, "creator ID");
		pos += 4;

		read_timestamp(c, d, pos, &d->mod_timestamp, "mod");
		pos += 4;
		dbg_id(c, d, pos, "updater ID");
		pos += 4;

		d->aspect_x = de_getu16le_p(&pos);
		d->aspect_y = de_getu16le_p(&pos);
		de_dbg(c, "aspect ratio: %d,%d", (int)d->aspect_x, (int)d->aspect_y);
	}

	can_decode_images = 1;
	if(d->depth != 8) {
		de_err(c, "Unsupported depth: %d", d->depth);
		can_decode_images = 0;
	}
	if(!de_good_image_dimensions(c, scr_width, scr_height)) {
		can_decode_images = 0;
	}

	if(can_decode_images) {
		ictx = create_image_ctx(c, d, scr_width, scr_height);
		ci->ictx = ictx;
		if(d->aspect_x && d->aspect_y) {
			ictx->density.code = DE_DENSITY_UNK_UNITS;
			ictx->density.xdens = (double)d->aspect_x;
			ictx->density.ydens = (double)d->aspect_y;
		}
	}

	pos = ci->pos + 128;
	do_sequence_of_chunks(c, d, ci, pos, -1);

	destroy_image_ctx(c, ictx);
	ci->ictx = NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movl $0x1, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
cmpl $0xaf11, (%rax)         # imm = 0xAF11
jne 0x81021
movq -0x8(%rbp), %rdi
leaq 0x12cb5f(%rip), %rsi    # 0x1adb79
callq 0x15e380
jmp 0x81059
movq -0x10(%rbp), %rax
cmpl $0xaf12, (%rax)         # imm = 0xAF12
jne 0x8103f
movq -0x8(%rbp), %rdi
leaq 0x12cb45(%rip), %rsi    # 0x1adb7d
callq 0x15e380
jmp 0x81057
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %edx
leaq 0x12cbde(%rip), %rsi    # 0x1adc2e
movb $0x0, %al
callq 0x15bc10
jmp 0x81059
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edx
leaq 0x12cbe7(%rip), %rsi    # 0x1adc71
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
leaq 0x12cbb2(%rip), %rsi    # 0x1adc80
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x38(%rax), %edx
leaq 0x12cbee(%rip), %rsi    # 0x1adcef
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x8111d
movq -0x10(%rbp), %rax
movl $0x8, 0x38(%rax)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpl $0xaf11, (%rax)         # imm = 0xAF11
jne 0x8116a
cmpq $0x0, -0x38(%rbp)
je 0x8116a
cvtsi2sdq -0x38(%rbp), %xmm1
movsd 0x12c951(%rip), %xmm0   # 0x1adab0
divsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x81196
movq -0x18(%rbp), %rax
cmpl $0xaf12, (%rax)         # imm = 0xAF12
jne 0x81194
cmpq $0x0, -0x38(%rbp)
je 0x81194
cvtsi2sdq -0x38(%rbp), %xmm1
movsd 0x12c91d(%rip), %xmm0   # 0x1adaa8
divsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x81196
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
movsd -0x48(%rbp), %xmm0
leaq 0x12caf2(%rip), %rsi    # 0x1adc9c
movb $0x1, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0xaf11, (%rax)         # imm = 0xAF11
jne 0x811f7
cmpq $0x140, -0x28(%rbp)     # imm = 0x140
jne 0x811f5
cmpq $0xc8, -0x30(%rbp)
jne 0x811f5
movq -0x10(%rbp), %rax
movq $0x6, 0x40(%rax)
movq -0x10(%rbp), %rax
movq $0x5, 0x48(%rax)
jmp 0x811f7
movq -0x18(%rbp), %rax
cmpl $0xaf12, (%rax)         # imm = 0xAF12
jne 0x81305
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rcx
addq $0x18, %rcx
leaq 0x122e19(%rip), %r8     # 0x1a403b
callq 0x82300
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq 0x12ca73(%rip), %rcx    # 0x1adcb9
callq 0x82430
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rcx
addq $0x28, %rcx
leaq 0x122c81(%rip), %r8     # 0x1a3ef3
callq 0x82300
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq 0x12ca2e(%rip), %rcx    # 0x1adcc4
callq 0x82430
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl %eax, %ecx
leaq 0x12c9d1(%rip), %rsi    # 0x1adccf
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x4c(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x8, 0x38(%rax)
je 0x81336
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x38(%rax), %edx
leaq 0x12c9bb(%rip), %rsi    # 0x1adce3
movb $0x0, %al
callq 0x15bfb0
movl $0x0, -0x4c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x81353
movl $0x0, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x813c7
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x824d0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x813c5
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x813c5
movq -0x40(%rbp), %rax
movl $0x1, 0x18(%rax)
movq -0x10(%rbp), %rax
cvtsi2sdq 0x40(%rax), %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, 0x20(%rax)
movq -0x10(%rbp), %rax
cvtsi2sdq 0x48(%rax), %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, 0x28(%rax)
jmp 0x813c7
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x80, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq $-0x1, %r8
callq 0x82540
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x82680
movq -0x18(%rbp), %rax
movq $0x0, 0x48(%rax)
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)