// File: /workspace/github_c_makefile_star2_O2/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 0xe3fc4
movq %rax, %r13
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
movq %rax, %rbp
movq %rbx, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0xdf038
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
movq %rax, %r12
leaq 0xbcebe(%rip), %rsi     # 0x1151ea
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
cmpl $0x1, %r12d
jne 0x583bb
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x58625
movq %rax, %r13
movq %rax, 0x48(%r14)
pushq $0x24
popq %rdi
pushq $0x6
popq %r8
movb $0x6, %r9b
xorl %ecx, %ecx
movq 0x8(%rsp), %r12
movl %ecx, %eax
xorl %edx, %edx
divl %edi
movl %eax, %esi
movl %ecx, %eax
xorl %edx, %edx
divl %r8d
cmpq $0xd8, %rcx
je 0x583c3
imull $0x330000, %esi, %edx   # imm = 0x330000
addl %r15d, %edx
imull $0x132, %eax, %eax      # imm = 0x132
subl %eax, %edx
movzbl %cl, %eax
divb %r9b
movzbl %al, %eax
divb %r9b
movzbl %ah, %eax
imull $0x3300, %eax, %eax     # imm = 0x3300
orl %edx, %eax
orl $0xff000000, %eax       # imm = 0xFF000000
movl %eax, 0x38(%r13,%rcx,4)
incq %rcx
addl $0x33, %r15d
jmp 0x58368
xorl %r13d, %r13d
jmp 0x5845e
movq 0x10(%rsp), %rcx
pushq $-0x1
popq %r8
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5866f
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %r15
movupd 0x28(%r12), %xmm0
movupd %xmm0, 0x68(%rax)
movq 0x40(%r12), %rax
testq %rax, %rax
je 0x58429
movq 0x48(%r12), %rcx
testq %rcx, %rcx
je 0x58429
movl $0x1, 0x78(%r15)
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x80(%r15)
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x88(%r15)
leaq 0xc5a76(%rip), %rdx     # 0x11dea6
pushq $0x5
popq %r8
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xdffbd
cmpl $0x0, 0x10(%r13)
jle 0x5845e
cmpl $0x0, 0x14(%r13)
jne 0x5845e
movq 0x30(%r13), %rdi
pushq $0x1
popq %rdx
movq %r15, %rsi
callq 0xe70ab
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5875a
andq $0x0, 0x48(%r14)
movq %rbx, %rdi
movq %r15, %rsi
callq 0xdfd24
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq