// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/mp3.c
// Function: do_ape_binary_item
static int do_ape_binary_item(deark *c, struct ape_tag_header_footer *ah,
   i64 pos, i64 len, struct de_stringreaderdata *key)
{
	struct de_stringreaderdata *name = NULL;
	i64 nbytes_to_scan;
	i64 img_pos, img_len;
	de_finfo *fi = NULL;
	struct fmtutil_fmtid_ctx *idctx = NULL;
	const char *ext = NULL;
	int retval = 0;

	if(de_strncasecmp(key->sz, "cover art", 9)) {
		goto done;
	}

	nbytes_to_scan = len;
	if(nbytes_to_scan>256) nbytes_to_scan=256;
	name = dbuf_read_string(c->infile, pos, nbytes_to_scan, nbytes_to_scan,
		DE_CONVFLAG_STOP_AT_NUL, DE_ENCODING_ASCII);
	if(!name->found_nul) goto done;

	img_pos = pos + name->bytes_consumed;
	img_len = len - name->bytes_consumed;
	if(len < 16) goto done;

	fi = de_finfo_create(c);

	if(c->filenames_from_file) {
		de_finfo_set_name_from_ucstring(c, fi, name->str, 0);
	}
	else {
		de_finfo_set_name_from_sz(c, fi, "cover_art", 0, DE_ENCODING_LATIN1);

		idctx = de_malloc(c, sizeof(struct fmtutil_fmtid_ctx));
		idctx->inf = c->infile;
		idctx->inf_pos = img_pos;
		idctx->inf_len = img_len;
		idctx->mode = FMTUTIL_FMTIDMODE_ALL_IMG; // expecting PNG or JPEG
		fmtutil_fmtid(c, idctx);
		ext = idctx->ext_sz;
	}
	dbuf_create_file_from_slice(c->infile, img_pos, img_len, ext,
		fi, DE_CREATEFLAG_IS_AUX);
	retval = 1;

done:
	de_finfo_destroy(c, fi);
	de_destroy_stringreaderdata(c, name);
	de_free(c, idctx);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xdbf8b(%rip), %rsi     # 0x1bc7bd
movl $0x9, %edx
callq 0x15abb0
cmpl $0x0, %eax
je 0xe0846
jmp 0xe0992
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x100, -0x38(%rbp)     # imm = 0x100
jle 0xe0860
movq $0x100, -0x38(%rbp)     # imm = 0x100
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl $0x1, %r9d
movl %r9d, %r8d
callq 0x1664c0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jne 0xe0895
jmp 0xe0992
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
addq (%rcx), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
subq (%rcx), %rax
movq %rax, -0x48(%rbp)
cmpq $0x10, -0x20(%rbp)
jge 0xe08bf
jmp 0xe0992
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0xd0(%rax)
je 0xe08f2
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdx
xorl %ecx, %ecx
callq 0x15d2c0
jmp 0xe0968
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq 0xdbec6(%rip), %rdx     # 0x1bc7c7
xorl %ecx, %ecx
movl $0x5, %r8d
callq 0x15d4c0
movq -0x8(%rbp), %rdi
movl $0x78, %esi
callq 0x15b780
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x48(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x58(%rbp), %rax
movb $0x1, (%rax)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x176960
movq -0x58(%rbp), %rax
addq $0x6c, %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x50(%rbp), %r8
movl $0x1, %r9d
callq 0x166be0
movl $0x1, -0x64(%rbp)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x166830
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x15b820
movl -0x64(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)