// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/id3.c
// Function: decode_id3v2_frame_pic_apic
static void decode_id3v2_frame_pic_apic(deark *c, id3v2ctx *d,
	dbuf *f, i64 pos1, i64 len, struct de_fourcc *tag4cc)
{
	u8 id3_encoding;
	u8 picture_type;
	i64 pos = pos1;
	struct de_stringreaderdata *fmt_srd = NULL;
	de_ucstring *mimetype = NULL;
	de_ucstring *description = NULL;
	const struct apic_type_info *ptinfo = NULL;
	i64 bytes_consumed = 0;
	int ret;

	id3_encoding = dbuf_getbyte(f, pos++);
	de_dbg(c, "text encoding: %d (%s)", (int)id3_encoding,
		get_id3v2_textenc_name(d, id3_encoding));

	if(tag4cc->id==CODE_PIC) {
		fmt_srd = dbuf_read_string(f, pos, 3, 3, 0, DE_ENCODING_ASCII);
		de_dbg(c, "format: \"%s\"", ucstring_getpsz(fmt_srd->str));
		pos += 3;
	}
	else {
		mimetype = ucstring_create(c);
		ret = read_id3v2_terminated_string(c, d, f, pos, pos1+len-pos, 256, ID3ENC_ISO_8859_1,
			mimetype, &bytes_consumed);
		if(!ret) goto done;
		de_dbg(c, "mime type: \"%s\"", ucstring_getpsz(mimetype));
		pos += bytes_consumed;
	}

	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:"?");

	description = ucstring_create(c);
	// "The description has a maximum length of 64 characters" [we'll allow more]
	ret = read_id3v2_terminated_string(c, d, f, pos, pos1+len-pos, 256, id3_encoding,
		description, &bytes_consumed);
	if(!ret) goto done;
	de_dbg(c, "description: \"%s\"", ucstring_getpsz(description));
	pos += bytes_consumed;

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

done:
	de_destroy_stringreaderdata(c, fmt_srd);
	ucstring_destroy(mimetype);
	ucstring_destroy(description);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r15
movq %r8, 0x38(%rsp)
movq %rcx, %r13
movq %rsi, %r14
movq %rdi, %rbx
andq $0x0, 0x20(%rsp)
leaq 0x1(%rcx), %rbp
movq %rdx, 0x18(%rsp)
movq %rdx, %rdi
movq %rcx, %rsi
callq 0xe3eb4
movzbl %al, %r12d
movq %r14, 0x40(%rsp)
movq %r14, %rdi
movl %r12d, %esi
callq 0x72350
leaq 0xa8c1b(%rip), %rsi     # 0x11acc9
movq %rbx, %rdi
movl %r12d, 0x34(%rsp)
movl %r12d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0xde896
cmpl $0x504943, 0x4(%r15)    # imm = 0x504943
jne 0x72123
pushq $0x3
popq %rcx
movq $0x0, 0x10(%rsp)
pushq $0x1
popq %r9
movq 0x18(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
movq %rcx, %rdx
xorl %r8d, %r8d
callq 0xe495c
movq %rax, 0x28(%rsp)
movq 0x18(%rax), %rdi
callq 0xeb7e4
leaq 0xa8c80(%rip), %rsi     # 0x11ad88
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
leaq 0x4(%r13), %rbp
movq %r14, %rdi
movq 0x38(%rsp), %r14
jmp 0x72193
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r15
movq 0x38(%rsp), %r14
leaq -0x1(%r14), %rcx
leaq 0x20(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq 0x18(%rsp), %r12
movq %r12, %rsi
movq %rbp, %rdx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x723ac
testl %eax, %eax
je 0x72266
movq %r15, 0x10(%rsp)
movq %r15, %rdi
callq 0xeb7e4
leaq 0xa8bd1(%rip), %rsi     # 0x11ad46
movq $0x0, 0x28(%rsp)
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq 0x20(%rsp), %rbp
movq %r12, %rdi
movq %r13, %r12
leaq 0x1(%rbp), %r13
movq %rbp, %rsi
callq 0xe3eb4
movzbl %al, %ebp
movl %ebp, %edi
callq 0x72589
movq %rax, %r15
testq %rax, %rax
je 0x721ba
movq 0x8(%r15), %rcx
jmp 0x721c1
leaq 0xacd20(%rip), %rcx     # 0x11eee1
leaq 0xa8bcd(%rip), %rsi     # 0x11ad95
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
callq 0xeac74
movq %rax, %rbp
addq %r12, %r14
movq %r14, %rcx
subq %r13, %rcx
leaq 0x20(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq %r13, %rdx
movl 0x34(%rsp), %r8d
movq %rbp, %r9
callq 0x723ac
testl %eax, %eax
je 0x7225a
movq %rbp, %rdi
callq 0xeb7e4
leaq 0xa8b18(%rip), %rsi     # 0x11ad34
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq 0x20(%rsp), %r13
subq %r13, %r14
movq 0x28(%rsp), %r12
jle 0x72253
movq %rbx, %rdi
movq 0x40(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r13, %rcx
movq %r14, %r8
movq %r15, %r9
callq 0x725b3
movq 0x10(%rsp), %r15
jmp 0x7226b
movq 0x10(%rsp), %r15
movq 0x28(%rsp), %r12
jmp 0x7226b
xorl %ebp, %ebp
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe4b94
movq %r15, %rdi
callq 0xeaf3c
movq %rbp, %rdi
callq 0xeaf3c
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq