// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc2.c
// Function: do_thumbsplus_icon
static void do_thumbsplus_icon(deark *c, struct thumbsplus_ctx *d,
	struct thumbsplus_icon_ctx *md)
{
	de_bitmap *img = NULL;
	de_finfo *fi = NULL;
	dbuf *unc_pixels = NULL;
	i64 pos;
	i64 mod_time_raw, mod_date_raw;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "icon at %"I64_FMT, md->icon_pos);
	de_dbg_indent(c, 1);
	pos = md->icon_pos;
	pos += 2; // ?

	mod_date_raw = de_getu16le_p(&pos);
	mod_time_raw = de_getu16le_p(&pos);
	de_dos_datetime_to_timestamp(&md->mod_dt, mod_date_raw, mod_time_raw);
	md->mod_dt.tzcode = DE_TZCODE_LOCAL;
	datetime_dbgmsg(c, &md->mod_dt, "mod time");

	md->data_len = de_getu16le_p(&pos);
	de_dbg(c, "cmpr len: %"I64_FMT, md->data_len);
	pos += 12; // ?

	md->orig_name_srd = dbuf_read_string(c->infile, pos, 260, 260,
		DE_CONVFLAG_STOP_AT_NUL, d->input_encoding);
	if(!md->orig_name_srd->found_nul) {
		d->need_errmsg = 1;
		goto done;
	}
	de_dbg(c, "name: \"%s\"", ucstring_getpsz_d(md->orig_name_srd->str));
	pos += md->orig_name_srd->bytes_consumed;

	md->name_token = ucstring_create(c);
	get_base_filename(md->orig_name_srd->str, md->name_token);

	de_dbg(c, "bitmap at %"I64_FMT, pos);
	unc_pixels = dbuf_create_membuf(c, THUMBSPLUS_IMGSIZE+2, 0x1);
	dbuf_enable_wbuffer(unc_pixels);
	thumbsplus_decompress(c, d, md, pos, md->data_len, unc_pixels);
	dbuf_flush(unc_pixels);
	if(unc_pixels->len != THUMBSPLUS_IMGSIZE) {
		// We're strict about this, because it's how we detect if we've gone off
		// the rails.
		de_err(c, "Decompression failed");
		goto done;
	}

	img = de_bitmap_create(c, THUMBSPLUS_W, THUMBSPLUS_H, 3);
	de_convert_image_paletted(unc_pixels, 0, 8, THUMBSPLUS_W, d->pal, img, 0);

	fi = de_finfo_create(c);
	if(c->filenames_from_file && ucstring_isnonempty(md->name_token)) {
		de_finfo_set_name_from_ucstring(c, fi, md->name_token, 0);
	}
	fi->timestamp[DE_TIMESTAMPIDX_MODIFY] = md->mod_dt;
	de_bitmap_write_to_file_finfo(img, fi, DE_CREATEFLAG_FLIP_IMAGE|DE_CREATEFLAG_OPT_IMAGE);

	pos += md->data_len;
	md->total_len = pos - md->icon_pos;

done:
	dbuf_close(unc_pixels);
	de_bitmap_destroy(img);
	de_finfo_destroy(c, fi);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq 0x11489a(%rip), %rsi    # 0x1b0d25
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x15d750
movq -0x18(%rbp), %rax
movb $0x2, 0x29(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x28, %rsi
leaq 0x11d661(%rip), %rdx    # 0x1b9b72
callq 0x9c7b0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x13a11c(%rip), %rsi    # 0x1d6661
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %r9d
movl $0x104, %ecx            # imm = 0x104
movl $0x1, %r8d
movq %rcx, %rdx
callq 0x1664c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
cmpl $0x0, 0x34(%rax)
jne 0x9c5a5
movq -0x10(%rbp), %rax
movb $0x1, 0x1(%rax)
jmp 0x9c773
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0x58(%rbp), %rdi
movq %rax, %rdx
leaq 0x111c04(%rip), %rsi    # 0x1ae1d0
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x9c800
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x1258e5(%rip), %rsi    # 0x1c1f07
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1b02, %esi           # imm = 0x1B02
movl $0x1, %edx
callq 0x168020
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x167b90
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %r8
movq -0x30(%rbp), %r9
callq 0x9c890
movq -0x30(%rbp), %rdi
callq 0x167c30
movq -0x30(%rbp), %rax
cmpq $0x1b00, 0x18(%rax)     # imm = 0x1B00
je 0x9c698
movq -0x8(%rbp), %rdi
leaq 0x10278c(%rip), %rsi    # 0x19ee18
movb $0x0, %al
callq 0x15bfb0
jmp 0x9c773
movq -0x8(%rbp), %rdi
movl $0x60, %esi
movl $0x48, %edx
movl $0x3, %ecx
callq 0x16b750
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %r8
addq $0x18, %r8
movq -0x20(%rbp), %r9
xorl %eax, %eax
movl %eax, %esi
movl $0x8, %edx
movl $0x60, %ecx
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16c520
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movzbl 0xd0(%rax), %eax
cmpl $0x0, %eax
je 0x9c726
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x1717f0
cmpl $0x0, %eax
je 0x9c726
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdx
xorl %ecx, %ecx
callq 0x15d2c0
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x28(%rcx), %rdx
movq %rdx, 0x18(%rax)
movq 0x30(%rcx), %rcx
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x6, %edx
callq 0x16afa0
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
subq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rdi
callq 0x1676a0
movq -0x20(%rbp), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x15b5a0
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)