// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/id3.c
// Function: decode_id3v2_frame_wmpicture
static void decode_id3v2_frame_wmpicture(deark *c, id3v2ctx *d,
	dbuf *f, i64 pos1, i64 len)
{
	u8 picture_type;
	i64 pos = pos1;
	i64 pic_data_len;
	i64 stringlen; // includes terminating 0x0000
	de_ucstring *mimetype = NULL;
	de_ucstring *description = NULL;
	const struct apic_type_info *ptinfo = NULL;
	int ret;

	picture_type = dbuf_getbyte(f, pos++);
	ptinfo = get_apic_type_info(picture_type);
	de_dbg(c, "picture type: 0x%02x (%s)", (unsigned int)picture_type,
		ptinfo?ptinfo->name:"?");

	pic_data_len = dbuf_getu32le(f, pos);
	de_dbg(c, "picture size: %u", (unsigned int)pic_data_len);
	pos += 4;

	ret = dbuf_get_utf16_NULterm_len(f, pos, pos1+len-pos, &stringlen);
	if(!ret) goto done;
	mimetype = ucstring_create(c);
	dbuf_read_to_ucstring_n(f, pos, stringlen-2, 256, mimetype, 0, DE_ENCODING_UTF16LE);
	de_dbg(c, "mime type: \"%s\"", ucstring_getpsz_d(mimetype));
	pos += stringlen;

	ret = dbuf_get_utf16_NULterm_len(f, pos, pos1+len-pos, &stringlen);
	if(!ret) goto done;
	mimetype = ucstring_create(c);
	dbuf_read_to_ucstring_n(f, pos, stringlen-2, 2048, mimetype, 0, DE_ENCODING_UTF16LE);
	de_dbg(c, "description: \"%s\"", ucstring_getpsz_d(mimetype));
	// TODO: Maybe the description should be used in the filename?
	pos += stringlen;

	if(pos+pic_data_len > pos1+len) goto done;
	extract_pic_apic(c, d, f, pos, pic_data_len, ptinfo);

done:
	ucstring_destroy(mimetype);
	ucstring_destroy(description);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x165060
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %edi
callq 0xab710
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movzbl -0x29(%rbp), %eax
movl %eax, -0x68(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0xab9ab
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
jmp 0xab9b8
leaq 0x10c27b(%rip), %rax    # 0x1b7c2d
movq %rax, -0x78(%rbp)
jmp 0xab9b8
movl -0x68(%rbp), %edx
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rcx
leaq 0x107db3(%rip), %rsi    # 0x1b377d
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x165540
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0x108377(%rip), %rsi    # 0x1b3d6a
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
addq -0x28(%rbp), %rdx
subq -0x38(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x1695b0
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jne 0xaba31
jmp 0xabb64
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
subq $0x2, %rdx
movq -0x50(%rbp), %r8
movl $0x100, %ecx            # imm = 0x100
xorl %r9d, %r9d
movl $0x3, (%rsp)
callq 0x166a40
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x50(%rbp), %rdi
callq 0x172650
movq -0x80(%rbp), %rdi
movq %rax, %rdx
leaq 0x107ca9(%rip), %rsi    # 0x1b372e
movb $0x0, %al
callq 0x15b0d0
movq -0x48(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
addq -0x28(%rbp), %rdx
subq -0x38(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x1695b0
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jne 0xabac3
jmp 0xabb64
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
subq $0x2, %rdx
movq -0x50(%rbp), %r8
movl $0x800, %ecx            # imm = 0x800
xorl %r9d, %r9d
movl $0x3, (%rsp)
callq 0x166a40
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x50(%rbp), %rdi
callq 0x172650
movq -0x88(%rbp), %rdi
movq %rax, %rdx
leaq 0x107bff(%rip), %rsi    # 0x1b371c
movb $0x0, %al
callq 0x15b0d0
movq -0x48(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
addq -0x28(%rbp), %rcx
cmpq %rcx, %rax
jle 0xabb47
jmp 0xabb64
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x60(%rbp), %r9
callq 0xab780
movq -0x50(%rbp), %rdi
callq 0x171750
movq -0x58(%rbp), %rdi
callq 0x171750
addq $0x90, %rsp
popq %rbp
retq
nop