// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/fli.c
// Function: do_chunk_thumbnail
static void do_chunk_thumbnail(deark *c, lctx *d, struct chunk_info_type *ci)
{
	UI colortype;
	i64 w, h;
	struct image_ctx_type *ictx = NULL;
	i64 pos = ci->dpos;
	de_finfo *fi = NULL;

	h = de_getu16le_p(&pos);
	w = de_getu16le_p(&pos);
	de_dbg_dimensions(c, w, h);
	colortype = (UI)de_getu16le_p(&pos);
	de_dbg(c, "color type: %u", colortype);
	if(colortype!=1) goto done;

	ictx = create_image_ctx(c, d, w, h);
	ci->ictx = ictx;
	make_6cube_pal(ictx->pal);
	do_sequence_of_chunks(c, d, ci, pos, -1);

	fi = de_finfo_create(c);
	fi->internal_mod_time = d->mod_timestamp;
	if(d->aspect_x && d->aspect_y) {
		// Evidence suggests the thumbnail has the same aspect ratio as the animation,
		// at least approximately.
		fi->density.code = DE_DENSITY_UNK_UNITS;
		fi->density.xdens = (double)d->aspect_x;
		fi->density.ydens = (double)d->aspect_y;
	}
	de_finfo_set_name_from_sz(c, fi, "thumb", 0, DE_ENCODING_LATIN1);

	if(ictx->use_count>0 && !ictx->error_flag) {
		de_bitmap_write_to_file_finfo(ictx->img, fi, DE_CREATEFLAG_IS_AUX);
	}

done:
	destroy_image_ctx(c, ictx);
	ci->ictx = NULL;
	de_finfo_destroy(c, fi);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
movq 0x20(%rdx), %rax
leaq 0x10(%rsp), %r15
movq %rax, (%r15)
movq 0x18(%rdi), %rdi
movq %r15, %rsi
callq 0xef1ed
movq %rax, %rbp
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
movq %rax, %r12
movq %rbx, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0xe9b05
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
movq %rax, %r13
leaq 0xc6c15(%rip), %rsi     # 0x1221a2
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9226
cmpl $0x1, %r13d
jne 0x5b6ea
movl $0x438, %esi            # imm = 0x438
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r13
movq %r12, (%rax)
movq %rbp, 0x8(%rax)
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movl $0x3, %ecx
callq 0xf2cab
movq %rax, 0x30(%r13)
movq %r13, 0x48(%r14)
movl $0xaaaaaaab, %eax       # imm = 0xAAAAAAAB
xorl %ecx, %ecx
movl %ecx, %edx
imulq $0x38e38e39, %rdx, %rsi # imm = 0x38E38E39
shrq $0x23, %rsi
imull $0x330000, %esi, %esi   # imm = 0x330000
addl %r15d, %esi
imulq %rax, %rdx
shrq $0x22, %rdx
imull $0x132, %edx, %edi      # imm = 0x132
subl %edi, %esi
imulq $0x2aaaaaab, %rdx, %rdi # imm = 0x2AAAAAAB
shrq $0x20, %rdi
addl %edi, %edi
leal (%rdi,%rdi,2), %edi
subl %edi, %edx
imull $0x3300, %edx, %edx     # imm = 0x3300
orl %esi, %edx
orl $0xff000000, %edx       # imm = 0xFF000000
movl %edx, 0x38(%r13,%rcx,4)
incq %rcx
addl $0x33, %r15d
cmpq $0xd8, %rcx
jne 0x5b5e0
movq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq 0x8(%rsp), %r12
movq %r12, %rsi
movq %r14, %rdx
movq $-0x1, %r8
callq 0x5b8c6
movq %rbx, %rdi
callq 0xea9a9
movq %rax, %r15
movupd 0x28(%r12), %xmm0
movupd %xmm0, 0x68(%rax)
movq 0x40(%r12), %rax
testq %rax, %rax
je 0x5b6af
movq 0x48(%r12), %rcx
testq %rcx, %rcx
je 0x5b6af
movl $0x1, 0x78(%r15)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x80(%r15)
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x88(%r15)
leaq 0xcf790(%rip), %rdx     # 0x12ae46
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
movl $0x5, %r8d
callq 0xeac7c
cmpl $0x0, 0x10(%r13)
jle 0x5b6ed
cmpl $0x0, 0x14(%r13)
jne 0x5b6ed
movq 0x30(%r13), %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xf2917
jmp 0x5b6ed
xorl %r13d, %r13d
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5b9cf
movq $0x0, 0x48(%r14)
movq %rbx, %rdi
movq %r15, %rsi
callq 0xea9b3
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq