// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %r8, %r14
movq %rdx, %rbp
movq %rsi, %r15
movq %rdi, %rbx
movq $0x0, 0x20(%rsp)
movq %rdx, %rdi
movq %rcx, 0x10(%rsp)
movq %rcx, %rsi
callq 0xef0d5
movzbl %al, %r12d
cmpb $0x3, %r12b
movq %r15, 0x40(%rsp)
movq %r14, 0x38(%rsp)
ja 0x765e4
leaq 0xb114b(%rip), %rax     # 0x1276e4
movslq (%rax,%r12,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0xb174b(%rip), %rcx     # 0x127cf4
jmp 0x765eb
leaq 0xb176c(%rip), %rcx     # 0x127d1e
jmp 0x765eb
leaq 0xadb1e(%rip), %rcx     # 0x1240d9
jmp 0x765eb
movb 0x30(%r15), %al
cmpb $0x3, %al
leaq 0xb173b(%rip), %rcx     # 0x127d05
leaq 0xb1740(%rip), %rdx     # 0x127d11
cmoveq %rcx, %rdx
cmpb $0x2, %al
leaq 0xb1721(%rip), %rcx     # 0x127cff
cmovneq %rdx, %rcx
jmp 0x765eb
leaq 0xb587e(%rip), %rcx     # 0x12be69
movq 0x10(%rsp), %r14
leaq 0x1(%r14), %r15
leaq 0xb16de(%rip), %rsi     # 0x127cd9
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
cmpl $0x504943, 0x4(%r13)    # imm = 0x504943
jne 0x76669
movq $0x0, 0x18(%rsp)
movl $0x3, %edx
movl $0x3, %ecx
movq %rbp, %rdi
movq %r15, %rsi
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0xefe67
movq %rax, 0x28(%rsp)
movq 0x18(%rax), %rdi
callq 0xf74bd
leaq 0xb174a(%rip), %rsi     # 0x127d98
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
leaq 0x4(%r14), %r15
movq %rbp, %rdi
movq 0x38(%rsp), %r14
jmp 0x766d4
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r13
movq 0x38(%rsp), %r14
leaq -0x1(%r14), %rcx
leaq 0x20(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
xorl %r8d, %r8d
movq %r13, %r9
callq 0x769ce
testl %eax, %eax
je 0x767c4
movq %r13, 0x18(%rsp)
movq %r13, %rdi
callq 0xf74bd
leaq 0xb16a0(%rip), %rsi     # 0x127d56
movq $0x0, 0x28(%rsp)
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq 0x20(%rsp), %r15
movq %rbp, %rdi
leaq 0xb578e(%rip), %rbp     # 0x12be69
leaq 0x1(%r15), %r13
movq %rdi, 0x30(%rsp)
movq %r15, %rsi
callq 0xef0d5
xorl %r15d, %r15d
leaq 0x10c0ca(%rip), %rcx    # 0x1827c0
xorl %edx, %edx
cmpb %al, (%rdx,%rcx)
je 0x7670c
addq $0x18, %rdx
cmpq $0x1e0, %rdx            # imm = 0x1E0
jne 0x766f8
jmp 0x76712
addq %rdx, %rcx
movq %rcx, %r15
movzbl %al, %edx
testq %r15, %r15
je 0x7671e
movq 0x8(%r15), %rbp
leaq 0xb1680(%rip), %rsi     # 0x127da5
movq %rbx, %rdi
movq %rbp, %rcx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
callq 0xf6870
movq %rax, %rbp
addq 0x10(%rsp), %r14
movq %r14, %rcx
subq %r13, %rcx
leaq 0x20(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
movq %r13, %rdx
movl %r12d, %r8d
movq %rbp, %r9
callq 0x769ce
testl %eax, %eax
je 0x767b8
movq %rbp, %rdi
callq 0xf74bd
leaq 0xb15ca(%rip), %rsi     # 0x127d44
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq 0x20(%rsp), %r13
subq %r13, %r14
movq 0x28(%rsp), %r12
jle 0x767b1
movq %rbx, %rdi
movq 0x40(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %r13, %rcx
movq %r14, %r8
movq %r15, %r9
callq 0x76bc4
movq 0x18(%rsp), %r13
jmp 0x767c9
movq 0x18(%rsp), %r13
movq 0x28(%rsp), %r12
jmp 0x767c9
xorl %ebp, %ebp
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf00aa
movq %r13, %rdi
callq 0xf6bb0
movq %rbp, %rdi
callq 0xf6bb0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq