// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
callq 0x165060
movb %al, -0x31(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movzbl -0x31(%rbp), %eax
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movzbl -0x31(%rbp), %esi
callq 0xab3f0
movq -0x78(%rbp), %rdi
movl -0x70(%rbp), %edx
movq %rax, %rcx
leaq 0x108826(%rip), %rsi    # 0x1b36b1
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
cmpl $0x504943, 0x4(%rax)    # imm = 0x504943
jne 0xaaefc
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl $0x3, %ecx
xorl %r8d, %r8d
movl $0x1, %r9d
movq %rcx, %rdx
callq 0x1664c0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172500
movq -0x80(%rbp), %rdi
movq %rax, %rdx
leaq 0x10888c(%rip), %rsi    # 0x1b3770
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x40(%rbp)
jmp 0xaaf91
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %r8
addq -0x28(%rbp), %r8
subq -0x40(%rbp), %r8
movq -0x50(%rbp), %r10
movl $0x100, %r9d            # imm = 0x100
xorl %eax, %eax
leaq -0x68(%rbp), %rax
movl $0x0, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0xab4a0
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
jne 0xaaf59
jmp 0xab0e5
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x50(%rbp), %rdi
callq 0x172500
movq -0x88(%rbp), %rdi
movq %rax, %rdx
leaq 0x1087b0(%rip), %rsi    # 0x1b372e
movb $0x0, %al
callq 0x15b0d0
movq -0x68(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
callq 0x165060
movb %al, -0x32(%rbp)
movzbl -0x32(%rbp), %edi
callq 0xab710
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movzbl -0x32(%rbp), %eax
movl %eax, -0x8c(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0xaafe6
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xa0(%rbp)
jmp 0xaaff6
leaq 0x10cc40(%rip), %rax    # 0x1b7c2d
movq %rax, -0xa0(%rbp)
jmp 0xaaff6
movl -0x8c(%rbp), %edx
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rcx
leaq 0x10876c(%rip), %rsi    # 0x1b377d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %r8
addq -0x28(%rbp), %r8
subq -0x40(%rbp), %r8
movb -0x31(%rbp), %r11b
movq -0x58(%rbp), %r10
movl $0x100, %r9d            # imm = 0x100
leaq -0x68(%rbp), %rax
movzbl %r11b, %r11d
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0xab4a0
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
jne 0xab075
jmp 0xab0e5
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x58(%rbp), %rdi
callq 0x172500
movq -0xa8(%rbp), %rdi
movq %rax, %rdx
leaq 0x108682(%rip), %rsi    # 0x1b371c
movb $0x0, %al
callq 0x15b0d0
movq -0x68(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
addq -0x28(%rbp), %rcx
cmpq %rcx, %rax
jl 0xab0c0
jmp 0xab0e5
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %r8
addq -0x28(%rbp), %r8
subq -0x40(%rbp), %r8
movq -0x60(%rbp), %r9
callq 0xab780
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x166830
movq -0x50(%rbp), %rdi
callq 0x171750
movq -0x58(%rbp), %rdi
callq 0x171750
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)