// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/mp3.c
// Function: do_ape_item
static int do_ape_item(deark *c, struct ape_tag_header_footer *ah,
   i64 pos1, i64 bytes_avail, i64 *bytes_consumed)
{
	i64 item_value_len;
	i64 pos = pos1;
	u32 flags;
	unsigned int item_type;
	struct de_stringreaderdata *key = NULL;
	int handled = 0;
	int retval = 0;

	de_dbg(c, "APE item at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);

	item_value_len = de_getu32le(pos);
	pos += 4;

	flags = (u32)de_getu32le(pos);
	de_dbg(c, "flags: 0x%08x", (unsigned int)flags);
	if(ah->ape_ver>=2000) {
		de_dbg_indent(c, 1);
		item_type = (flags&0x00000006)>>1;
		de_dbg(c, "type: %u (%s)", item_type, get_ape_item_type_name(item_type));
		de_dbg_indent(c, -1);
	}
	else {
		item_type = 0;
	}
	pos += 4;

	key = dbuf_read_string(c->infile, pos, 256, 256, DE_CONVFLAG_STOP_AT_NUL,
		DE_ENCODING_ASCII);
	if(!key->found_nul) goto done;
	de_dbg(c, "key: \"%s\"", ucstring_getpsz(key->str));
	pos += key->bytes_consumed;

	de_dbg(c, "item data at %"I64_FMT", len=%"I64_FMT, pos, item_value_len);
	de_dbg_indent(c, 1);
	if(item_type==0 || item_type==2) {
		do_ape_text_item(c, ah, pos, item_value_len);
		handled = 1;
	}
	else if(item_type==1) { // binary
		handled = do_ape_binary_item(c, ah, pos, item_value_len, key);
	}

	if(!handled && c->debug_level>=2) {
		de_dbg_hexdump(c, c->infile, pos, item_value_len, 256, NULL, 0x1);
	}
	de_dbg_indent(c, -1);

	pos += item_value_len;
	*bytes_consumed = pos - pos1;
	retval = 1;

done:
	de_dbg_indent(c, -1);
	de_destroy_stringreaderdata(c, key);
	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 -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0xdc2ed(%rip), %rsi     # 0x1bc776
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x165540
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x165540
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %edx
leaq 0xd1b9d(%rip), %rsi     # 0x1b207e
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0x7d0, (%rax)          # imm = 0x7D0
jb 0xe054b
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movl -0x3c(%rbp), %eax
andl $0x6, %eax
shrl %eax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x40(%rbp), %edi
callq 0xe06d0
movq -0x60(%rbp), %rdi
movl -0x54(%rbp), %edx
movq %rax, %rcx
leaq 0xbe2be(%rip), %rsi     # 0x19e7f2
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0xe0552
movl $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movl $0x100, %ecx            # imm = 0x100
movl $0x1, %r9d
movq %rcx, %rdx
movl %r9d, %r8d
callq 0x1664c0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jne 0xe0593
jmp 0xe06ac
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172500
movq -0x68(%rbp), %rdi
movq %rax, %rdx
leaq 0xdc1d0(%rip), %rsi     # 0x1bc786
movb $0x0, %al
callq 0x15b0d0
movq -0x48(%rbp), %rax
movq (%rax), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
leaq 0xdc1b1(%rip), %rsi     # 0x1bc790
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
cmpl $0x0, -0x40(%rbp)
je 0xe0600
cmpl $0x2, -0x40(%rbp)
jne 0xe061e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0xe0730
movl $0x1, -0x4c(%rbp)
jmp 0xe0642
cmpl $0x1, -0x40(%rbp)
jne 0xe0640
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x48(%rbp), %r8
callq 0xe07e0
movl %eax, -0x4c(%rbp)
jmp 0xe0642
cmpl $0x0, -0x4c(%rbp)
jne 0xe067c
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0xe067c
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, (%rsp)
callq 0x15b840
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x30(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
subq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x166830
movl -0x50(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq