// File: /workspace/github_c_makefile_star2_O3/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 0xeebeb
movq %rax, %r13
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebeb
movq %rax, %rbp
movq %rbx, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0xe8f88
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebeb
movq %rax, %r12
leaq 0xc70be(%rip), %rsi     # 0x1223aa
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
cmpl $0x1, %r12d
jne 0x5b557
movl $0x438, %esi            # imm = 0x438
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r15
movq %rbp, (%rax)
movq %r13, 0x8(%rax)
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl $0x3, %ecx
callq 0xf266a
movq %rax, 0x30(%r15)
movq %r15, 0x48(%r14)
movd 0xc6c40(%rip), %xmm4    # 0x121f80
movl $0xe, %eax
movdqa 0xc6c43(%rip), %xmm1    # 0x121f90
pxor %xmm2, %xmm2
movdqa 0xc6c67(%rip), %xmm5    # 0x121fc0
movdqa 0xc6c7f(%rip), %xmm7    # 0x121fe0
movdqa 0xc6c86(%rip), %xmm8    # 0x121ff0
movdqa 0xc6c8d(%rip), %xmm9    # 0x122000
movdqa 0xc6c94(%rip), %xmm10   # 0x122010
movdqa 0xc6c9b(%rip), %xmm11   # 0x122020
movdqa 0xc6ca2(%rip), %xmm12   # 0x122030
movdqa 0xb59e9(%rip), %xmm13   # 0x110d80
movdqa 0xc6ca0(%rip), %xmm14   # 0x122040
movdqa %xmm4, %xmm0
punpckhbw %xmm2, %xmm0    # xmm0 = xmm0[8],xmm2[8],xmm0[9],xmm2[9],xmm0[10],xmm2[10],xmm0[11],xmm2[11],xmm0[12],xmm2[12],xmm0[13],xmm2[13],xmm0[14],xmm2[14],xmm0[15],xmm2[15]
pmullw %xmm1, %xmm0
psrlw $0x8, %xmm0
movdqa %xmm4, %xmm15
punpcklbw %xmm2, %xmm15   # xmm15 = xmm15[0],xmm2[0],xmm15[1],xmm2[1],xmm15[2],xmm2[2],xmm15[3],xmm2[3],xmm15[4],xmm2[4],xmm15[5],xmm2[5],xmm15[6],xmm2[6],xmm15[7],xmm2[7]
movdqa %xmm15, %xmm6
pmullw %xmm1, %xmm6
psrlw $0x8, %xmm6
packuswb %xmm0, %xmm6
psrlw $0x2, %xmm6
pand 0xc6bc6(%rip), %xmm6    # 0x121fa0
movdqa %xmm6, %xmm3
punpcklbw %xmm3, %xmm3    # xmm3 = xmm3[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
pmullw 0xc6bc6(%rip), %xmm3    # 0x121fb0
pand %xmm5, %xmm3
packuswb %xmm3, %xmm3
movdqa %xmm4, %xmm0
psubb %xmm3, %xmm0
movdqa %xmm6, %xmm3
punpcklbw %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1],xmm3[2],xmm2[2],xmm3[3],xmm2[3],xmm3[4],xmm2[4],xmm3[5],xmm2[5],xmm3[6],xmm2[6],xmm3[7],xmm2[7]
pmullw %xmm7, %xmm3
psrlw $0x8, %xmm3
pmullw %xmm8, %xmm3
pand %xmm5, %xmm3
packuswb %xmm3, %xmm3
psubb %xmm3, %xmm6
pmullw %xmm9, %xmm15
psrlw $0x8, %xmm15
packuswb %xmm15, %xmm15
psrlw $0x3, %xmm15
pand %xmm10, %xmm15
punpcklbw %xmm2, %xmm15   # xmm15 = xmm15[0],xmm2[0],xmm15[1],xmm2[1],xmm15[2],xmm2[2],xmm15[3],xmm2[3],xmm15[4],xmm2[4],xmm15[5],xmm2[5],xmm15[6],xmm2[6],xmm15[7],xmm2[7]
punpcklwd %xmm2, %xmm15   # xmm15 = xmm15[0],xmm2[0],xmm15[1],xmm2[1],xmm15[2],xmm2[2],xmm15[3],xmm2[3]
pshufd $0xf5, %xmm15, %xmm3    # xmm3 = xmm15[1,1,3,3]
pmuludq %xmm11, %xmm15
pshufd $0xe8, %xmm15, %xmm15   # xmm15 = xmm15[0,2,2,3]
pmuludq %xmm11, %xmm3
pshufd $0xe8, %xmm3, %xmm3     # xmm3 = xmm3[0,2,2,3]
punpckldq %xmm3, %xmm15   # xmm15 = xmm15[0],xmm3[0],xmm15[1],xmm3[1]
punpcklbw %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1],xmm0[2],xmm2[2],xmm0[3],xmm2[3],xmm0[4],xmm2[4],xmm0[5],xmm2[5],xmm0[6],xmm2[6],xmm0[7],xmm2[7]
punpcklwd %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1],xmm0[2],xmm2[2],xmm0[3],xmm2[3]
pmaddwd 0xc6b5f(%rip), %xmm0    # 0x121fd0
por %xmm0, %xmm15
punpcklbw %xmm2, %xmm6    # xmm6 = xmm6[0],xmm2[0],xmm6[1],xmm2[1],xmm6[2],xmm2[2],xmm6[3],xmm2[3],xmm6[4],xmm2[4],xmm6[5],xmm2[5],xmm6[6],xmm2[6],xmm6[7],xmm2[7]
punpcklwd %xmm2, %xmm6    # xmm6 = xmm6[0],xmm2[0],xmm6[1],xmm2[1],xmm6[2],xmm2[2],xmm6[3],xmm2[3]
pmaddwd %xmm12, %xmm6
por %xmm6, %xmm15
por %xmm13, %xmm15
movdqu %xmm15, (%r15,%rax,4)
paddb %xmm14, %xmm4
addq $0x4, %rax
cmpq $0xe6, %rax
jne 0x5b3a0
movq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq 0x8(%rsp), %r12
movq %r12, %rsi
movq %r14, %rdx
movq $-0x1, %r8
callq 0x5b733
movq %rbx, %rdi
callq 0xea504
movq %rax, %r13
movupd 0x28(%r12), %xmm0
movupd %xmm0, 0x68(%rax)
movq 0x40(%r12), %rax
testq %rax, %rax
je 0x5b51c
movq 0x48(%r12), %rcx
testq %rcx, %rcx
je 0x5b51c
movl $0x1, 0x78(%r13)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x80(%r13)
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x88(%r13)
leaq 0xcfbf3(%rip), %rdx     # 0x12b116
movq %rbx, %rdi
movq %r13, %rsi
xorl %ecx, %ecx
movl $0x5, %r8d
callq 0xea78f
cmpl $0x0, 0x10(%r15)
jle 0x5b55a
cmpl $0x0, 0x14(%r15)
jne 0x5b55a
movq 0x30(%r15), %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0xf22d0
jmp 0x5b55a
xorl %r13d, %r13d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5b831
movq $0x0, 0x48(%r14)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xea50e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq