// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/id3.c
// Function: do_id3v2
static void do_id3v2(deark *c, dbuf *f, i64 pos, i64 bytes_avail,
	 i64 *bytes_consumed)
{
	id3v2ctx *d = NULL;
	dbuf *unescaped_data = NULL;
	i64 ext_header_size = 0;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	*bytes_consumed = 0;
	d = de_malloc(c, sizeof(id3v2ctx));
	if(!do_id3v2_header(c, f, d)) goto done;
	if(!d->has_id3v2) goto done;

	if(d->has_ext_header) {
		de_dbg(c, "ID3v2 extended header at %d", (int)d->data_start);
		de_dbg_indent(c, 1);
		if(d->version_code==3 && !d->global_level_unsync) {
			ext_header_size = 4 + dbuf_getu32be(f, d->data_start);
			de_dbg(c, "extended header size: %d", (int)ext_header_size);
			// TODO: Decode the rest of the extended header
		}
		else if(d->version_code==4) {
			u8 ext_flags;
			ext_header_size = get_synchsafe_int(f, d->data_start);
			de_dbg(c, "extended header size: %d", (int)ext_header_size);
			// [d->data_start+5] = flag byte count that should always be 1
			ext_flags = dbuf_getbyte(f, d->data_start+5);
			de_dbg(c, "extended flags: 0x%02x", (unsigned int)ext_flags);
			// TODO: Decode the rest of the extended header
		}
		else {
			de_warn(c, "Extended header not supported");
			goto done; // TODO: v2.3.x w/ unsynch
		}
		de_dbg_indent(c, -1);
		if(ext_header_size > d->data_len) goto done;
	}

	if(d->global_level_unsync) {
		unescaped_data = dbuf_create_membuf(c, 0, 0);
		unescape_id3v2_data(c, f, d->data_start,
			d->data_len, unescaped_data);
	}
	else {
		unescaped_data = dbuf_open_input_subfile(f,
			d->data_start + ext_header_size,
			d->data_len - ext_header_size);
	}

	do_id3v2_frames(c, d, unescaped_data, 0, unescaped_data->len,
		d->data_start + ext_header_size);

	if(d->has_padding) {
		de_dbg(c, "ID3v2 padding at %s%d", d->approx_mark, (int)d->approx_padding_pos);
	}

	*bytes_consumed = d->total_len;

done:
	de_dbg_indent_restore(c, saved_indent_level);
	dbuf_close(unescaped_data);
	de_free(c, d);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %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, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x15b580
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rdi
movl $0x40, %esi
callq 0x15b780
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0xa96b0
cmpl $0x0, %eax
jne 0xa90c9
jmp 0xa92cd
movq -0x30(%rbp), %rax
cmpb $0x0, (%rax)
jne 0xa90d7
jmp 0xa92cd
movq -0x30(%rbp), %rax
cmpb $0x0, 0x34(%rax)
je 0xa9202
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %edx
leaq 0x109fef(%rip), %rsi    # 0x1b30e9
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x30(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x3, %eax
jne 0xa915c
movq -0x30(%rbp), %rax
cmpb $0x0, 0x32(%rax)
jne 0xa915c
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x165470
addq $0x4, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0x109fb5(%rip), %rsi    # 0x1b3105
movb $0x0, %al
callq 0x15b0d0
jmp 0xa91df
movq -0x30(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x4, %eax
jne 0xa91c6
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0xa9a90
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0x109f76(%rip), %rsi    # 0x1b3105
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
addq $0x5, %rsi
callq 0x165060
movb %al, -0x45(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x45(%rbp), %edx
leaq 0x109f61(%rip), %rsi    # 0x1b311e
movb $0x0, %al
callq 0x15b0d0
jmp 0xa91dd
movq -0x8(%rbp), %rdi
leaq 0x109f64(%rip), %rsi    # 0x1b3135
movb $0x0, %al
callq 0x15bc10
jmp 0xa92cd
jmp 0xa91df
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jle 0xa9200
jmp 0xa92cd
jmp 0xa9202
movq -0x30(%rbp), %rax
cmpb $0x0, 0x32(%rax)
je 0xa9242
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x168020
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x38(%rbp), %r8
callq 0xa9ae0
jmp 0xa9267
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
addq -0x40(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdx
subq -0x40(%rbp), %rdx
callq 0x1691b0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x38(%rbp), %rax
movq 0x18(%rax), %r8
movq -0x30(%rbp), %rax
movq 0x10(%rax), %r9
addq -0x40(%rbp), %r9
xorl %eax, %eax
movl %eax, %ecx
callq 0xa9be0
movq -0x30(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0xa92be
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movl %eax, %ecx
leaq 0x109e9c(%rip), %rsi    # 0x1b3153
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x15b5a0
movq -0x38(%rbp), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15b820
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)