// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq 0x20(%rdx), %rax
movq %rax, 0x8(%rsp)
movl (%rdx), %edx
movl %edx, (%rsi)
cmpl $0xaf12, %edx           # imm = 0xAF12
je 0x5a78a
cmpl $0xaf11, %edx           # imm = 0xAF11
jne 0x5a79b
leaq 0xc7989(%rip), %rsi     # 0x122111
jmp 0x5a791
leaq 0xc7984(%rip), %rsi     # 0x122115
movq %r14, %rdi
callq 0xeb125
jmp 0x5a7ac
leaq 0xc7a24(%rip), %rsi     # 0x1221c6
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8faa
movq 0x18(%r14), %rdi
leaq 0x8(%rsp), %rbp
movq %rbp, %rsi
callq 0xeebeb
movq %rax, 0x8(%r15)
leaq 0xc7a41(%rip), %rsi     # 0x122209
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq %rbp, %rsi
callq 0xeebeb
movq %rax, %r12
movq 0x18(%r14), %rdi
movq %rbp, %rsi
callq 0xeebeb
movq %rax, %r13
leaq 0xc7a1f(%rip), %rsi     # 0x122218
movq %r14, %rdi
movq %r12, 0x10(%rsp)
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq %rbp, %rsi
callq 0xeebeb
movl %eax, 0x38(%r15)
leaq 0xc7a62(%rip), %rsi     # 0x122287
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
cmpl $0x0, 0x38(%r15)
jne 0x5a840
movl $0x8, 0x38(%r15)
leaq 0x8(%rsp), %rsi
addq $0x2, (%rsi)
movq 0x18(%r14), %rdi
callq 0xeed83
movl (%rbx), %ecx
cmpl $0xaf11, %ecx           # imm = 0xAF11
sete %dl
testq %rax, %rax
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x5a87c
cvtsi2sd %rax, %xmm1
movsd 0xc76fe(%rip), %xmm0    # 0x121f78
jmp 0x5a8a3
testq %rax, %rax
setne %dl
cmpl $0xaf12, %ecx           # imm = 0xAF12
sete %cl
andb %dl, %cl
xorpd %xmm0, %xmm0
cmpb $0x1, %cl
jne 0x5a8a7
cvtsi2sd %rax, %xmm1
movsd 0xc76cd(%rip), %xmm0    # 0x121f70
divsd %xmm1, %xmm0
leaq 0xc7986(%rip), %rsi     # 0x122234
movq %r14, %rdi
movq %rax, %rdx
movb $0x1, %al
callq 0xe8617
movq 0x8(%rsp), %rsi
addq $0x2, %rsi
movq %rsi, 0x8(%rsp)
movl (%rbx), %eax
cmpl $0xaf12, %eax           # imm = 0xAF12
je 0x5a910
cmpl $0xaf11, %eax           # imm = 0xAF11
jne 0x5a9b9
movq 0x10(%rsp), %rax
xorq $0x140, %rax            # imm = 0x140
movq %r13, %rcx
xorq $0xc8, %rcx
orq %rax, %rcx
jne 0x5a9b9
movq $0x6, 0x40(%r15)
movq $0x5, 0x48(%r15)
jmp 0x5a9b9
leaq 0x18(%r15), %rdx
leaq 0xbda03(%rip), %rcx     # 0x11831e
movq %r14, %rdi
callq 0x5b5c7
leaq 0x8(%rsp), %rbp
movq (%rbp), %rsi
addq $0x4, %rsi
movq %rsi, (%rbp)
leaq 0xc7916(%rip), %rdx     # 0x122251
movq %r14, %rdi
callq 0x5b6a5
movq (%rbp), %rsi
addq $0x4, %rsi
movq %rsi, (%rbp)
leaq 0x28(%r15), %rdx
leaq 0xbd87c(%rip), %rcx     # 0x1181d6
movq %r14, %rdi
callq 0x5b5c7
movq (%rbp), %rsi
addq $0x4, %rsi
movq %rsi, (%rbp)
leaq 0xc78e7(%rip), %rdx     # 0x12225c
movq %r14, %rdi
callq 0x5b6a5
addq $0x4, (%rbp)
movq 0x18(%r14), %rdi
movq %rbp, %rsi
callq 0xeebeb
movq %rax, 0x40(%r15)
movq 0x18(%r14), %rdi
movq %rbp, %rsi
callq 0xeebeb
movq %rax, 0x48(%r15)
movl 0x40(%r15), %edx
leaq 0xc78ba(%rip), %rsi     # 0x122267
movq %r14, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0xe8617
movl 0x38(%r15), %r12d
cmpl $0x8, %r12d
je 0x5aa2d
leaq 0xc78b1(%rip), %rsi     # 0x12227b
xorl %ebp, %ebp
movq %r14, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9295
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
callq 0xf1db1
movq 0x10(%rbx), %rcx
subq $-0x80, %rcx
movq %rcx, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq $-0x1, %r8
callq 0x5b733
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5b831
movq $0x0, 0x48(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
callq 0xf1db1
xorl %ebp, %ebp
cmpl $0x8, %r12d
jne 0x5a9e9
testl %eax, %eax
je 0x5a9e9
movl $0x438, %esi            # imm = 0x438
movq %r14, %rdi
callq 0xe8b2b
movq %rax, %rbp
movq 0x10(%rsp), %rsi
movq %rsi, (%rax)
movq %r13, 0x8(%rax)
movq %r14, %rdi
movq %r13, %rdx
movl $0x3, %ecx
callq 0xf266a
movq %rax, 0x30(%rbp)
movq %rbp, 0x48(%rbx)
movq 0x40(%r15), %rax
testq %rax, %rax
je 0x5a9e9
movq 0x48(%r15), %rcx
testq %rcx, %rcx
je 0x5a9e9
movl $0x1, 0x18(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x20(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x28(%rbp)
jmp 0x5a9e9