// File: /workspace/github_c_makefile_star2_O3/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 0xeead3
movzbl %al, %edx
cmpb $0x3, %dl
movq %r15, 0x30(%rsp)
ja 0x76285
leaq 0xb16da(%rip), %rax     # 0x127914
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0xb1cda(%rip), %rcx     # 0x127f24
jmp 0x7628c
leaq 0xb1cfb(%rip), %rcx     # 0x127f4e
jmp 0x7628c
leaq 0xae09d(%rip), %rcx     # 0x1242f9
jmp 0x7628c
movb 0x30(%r15), %al
cmpb $0x3, %al
leaq 0xb1cca(%rip), %rcx     # 0x127f35
leaq 0xb1ccf(%rip), %rsi     # 0x127f41
cmoveq %rcx, %rsi
cmpb $0x2, %al
leaq 0xb1cb0(%rip), %rcx     # 0x127f2f
cmovneq %rsi, %rcx
jmp 0x7628c
leaq 0xb5ec5(%rip), %rcx     # 0x12c151
movq 0x10(%rsp), %r12
leaq 0x1(%r12), %r15
leaq 0xb1c6c(%rip), %rsi     # 0x127f09
movq %rbx, %rdi
movq %rdx, 0x40(%rsp)
xorl %eax, %eax
callq 0xe8617
cmpl $0x504943, 0x4(%r13)    # imm = 0x504943
jne 0x76307
movq $0x0, 0x18(%rsp)
movl $0x3, %edx
movl $0x3, %ecx
movq %rbp, %rdi
movq %r15, %rsi
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0xef87c
movq %rax, %r13
movq 0x18(%rax), %rdi
callq 0xf705c
leaq 0xb1cd8(%rip), %rsi     # 0x127fc8
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
leaq 0x4(%r12), %r15
movq %r13, %r12
jmp 0x76367
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r13
leaq -0x1(%r14), %rcx
leaq 0x20(%rsp), %rax
movq %rax, (%rsp)
xorl %r12d, %r12d
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
xorl %r8d, %r8d
movq %r13, %r9
callq 0x7665b
testl %eax, %eax
je 0x7647b
movq %r13, 0x18(%rsp)
movq %r13, %rdi
callq 0xf705c
leaq 0xb1c34(%rip), %rsi     # 0x127f86
xorl %r12d, %r12d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq 0x20(%rsp), %r15
movq %rbp, %rdi
leaq 0xb5de0(%rip), %rbp     # 0x12c151
leaq 0x1(%r15), %r13
movq %rdi, 0x38(%rsp)
movq %r15, %rsi
callq 0xeead3
leaq 0x10c4d7(%rip), %rcx    # 0x182860
xorl %edx, %edx
cmpb %al, (%rdx,%rcx)
je 0x763a8
addq $0x18, %rdx
cmpq $0x1e0, %rdx            # imm = 0x1E0
jne 0x7638b
movq $0x0, 0x28(%rsp)
jmp 0x763b6
leaq (%rcx,%rdx), %rsi
movq %rsi, 0x28(%rsp)
movq 0x8(%rdx,%rcx), %rbp
movzbl %al, %edx
leaq 0xb1c15(%rip), %rsi     # 0x127fd5
movq %rbx, %rdi
movq %rbp, %rcx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r15
addq 0x10(%rsp), %r14
movq %r14, %rcx
subq %r13, %rcx
leaq 0x20(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq 0x38(%rsp), %rbp
movq %rbp, %rsi
movq %r13, %rdx
movq 0x40(%rsp), %r8
movq %r15, %r9
callq 0x7665b
testl %eax, %eax
je 0x7644c
movq %r15, %rdi
callq 0xf705c
leaq 0xb1b5a(%rip), %rsi     # 0x127f74
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq 0x20(%rsp), %r13
subq %r13, %r14
jle 0x7644c
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %r14, %r8
movq 0x28(%rsp), %r9
callq 0x76845
movq 0x18(%rsp), %r13
movq %rbx, %rdi
movq %r12, %rsi
callq 0xefaca
movq %r13, %rdi
callq 0xf6753
movq %r15, %rdi
callq 0xf6753
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
jmp 0x76451