// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/id3.c
// Function: do_id3v2_frames
static void do_id3v2_frames(deark *c, id3v2ctx *d,
	dbuf *f, i64 pos1, i64 len, i64 orig_pos)
{
	i64 pos = pos1;
	struct de_fourcc tag4cc;
	int saved_indent_level;
	i64 frame_idx = 0;
	i64 frame_header_len;

	de_zeromem(&tag4cc, sizeof(struct de_fourcc));
	if(d->version_code<=2) frame_header_len = 6;
	else frame_header_len = 10;

	de_dbg_indent_save(c, &saved_indent_level);

	de_dbg(c, "ID3v2 frames at %d", (int)orig_pos);
	de_dbg_indent(c, 1);

	while(1) {
		i64 frame_dlen;
		u8 flags1, flags2;
		u8 b;
		char *flg2name;

		if(pos+frame_header_len > pos1+len) break;

		// Peek at the next byte
		b = dbuf_getbyte(f, pos);
		if(b==0x00) {
			d->has_padding = 1;
			d->approx_padding_pos = orig_pos+pos;
			break;
		}

		// The offset we print might not be exact, because of (pre-v2.4.x)
		// unsynchronisation.
		// (We have no efficient way to map the position in the unescaped data
		// back to the corresponding position in the original file.)
		de_dbg(c, "frame #%d at %s%d", (int)frame_idx, d->approx_mark, (int)(orig_pos+pos));
		de_dbg_indent(c, 1);

		if(d->version_code<=2) {
			// Version 2.2.x uses a "THREECC".
			dbuf_read_fourcc(f, pos, &tag4cc, 3, 0x0);
			pos += 3;
		}
		else {
			dbuf_read_fourcc(f, pos, &tag4cc, 4, 0x0);
			pos += 4;
		}

		de_dbg(c, "tag: '%s' (%s)", tag4cc.id_dbgstr,
			get_id3v2_frame_name(d, tag4cc.id));

		if(d->version_code<=2) {
			frame_dlen = dbuf_getint_ext(f, pos, 3, 0, 0); // read 24-bit BE uint
			pos += 3;
		}
		else if(d->version_code==3) {
			frame_dlen = dbuf_getu32be(f, pos);
			pos += 4;
		}
		else {
			frame_dlen = get_synchsafe_int(f, pos);
			pos += 4;
		}
		de_dbg(c, "size: %d", (int)frame_dlen);

		if(d->version_code<=2) {
			flags1 = 0;
			flags2 = 0;
		}
		else {
			flags1 = dbuf_getbyte(f, pos++);
			flags2 = dbuf_getbyte(f, pos++);
			if(d->version_code<=3) flg2name = "encoding";
			else flg2name = "format_description";
			de_dbg(c, "flags: status_messages=0x%02x, %s=0x%02x",
				(unsigned int)flags1, flg2name, (unsigned int)flags2);
		}

		if(pos+frame_dlen > pos1+len) goto done;
		decode_id3v2_frame(c, d, f, pos, frame_dlen, &tag4cc, flags1, flags2);

		pos += frame_dlen;
		frame_idx++;
		de_dbg_indent(c, -1);
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// 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, -0x38(%rbp)
movq $0x0, -0x78(%rbp)
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x19140
movq -0x10(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x2, %eax
jg 0xa9c3a
movq $0x6, -0x80(%rbp)
jmp 0xa9c42
movq $0xa, -0x80(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x6c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
leaq 0x10967c(%rip), %rsi    # 0x1b32dc
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x38(%rbp), %rax
addq -0x80(%rbp), %rax
movq -0x20(%rbp), %rcx
addq -0x28(%rbp), %rcx
cmpq %rcx, %rax
jle 0xa9c8f
jmp 0xa9f79
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x165060
movb %al, -0x8b(%rbp)
movzbl -0x8b(%rbp), %eax
cmpl $0x0, %eax
jne 0xa9cce
movq -0x10(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x30(%rbp), %rcx
addq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
jmp 0xa9f79
movq -0x8(%rbp), %rdi
movq -0x78(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x30(%rbp), %rax
addq -0x38(%rbp), %rax
movl %eax, %r8d
leaq 0x1095fd(%rip), %rsi    # 0x1b32ef
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x2, %eax
jg 0xa9d3b
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x68(%rbp), %rdx
movl $0x3, %ecx
xorl %r8d, %r8d
callq 0x169860
movq -0x38(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x38(%rbp)
jmp 0xa9d60
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x68(%rbp), %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0x169860
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x68(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0xa9f90
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rdx
movq %rax, %rcx
leaq 0x109563(%rip), %rsi    # 0x1b3301
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x2, %eax
jg 0xa9ddf
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x3, %edx
xorl %r8d, %r8d
movl %r8d, %ecx
callq 0x165a80
movq %rax, -0x88(%rbp)
movq -0x38(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x38(%rbp)
jmp 0xa9e30
movq -0x10(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x3, %eax
jne 0xa9e0e
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x165470
movq %rax, -0x88(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
jmp 0xa9e2e
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xa9a90
movq %rax, -0x88(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
jmp 0xa9e30
movq -0x8(%rbp), %rdi
movq -0x88(%rbp), %rax
movl %eax, %edx
leaq 0x118b6b(%rip), %rsi    # 0x1c29af
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x2, %eax
jg 0xa9e6b
movb $0x0, -0x89(%rbp)
movb $0x0, -0x8a(%rbp)
jmp 0xa9efa
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x165060
movb %al, -0x89(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x165060
movb %al, -0x8a(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x3, %eax
jg 0xa9ec4
leaq 0x120de2(%rip), %rax    # 0x1cac9d
movq %rax, -0x98(%rbp)
jmp 0xa9ed2
leaq 0x109445(%rip), %rax    # 0x1b3310
movq %rax, -0x98(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x89(%rbp), %edx
movq -0x98(%rbp), %rcx
movzbl -0x8a(%rbp), %r8d
leaq 0x109430(%rip), %rsi    # 0x1b3323
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
addq -0x88(%rbp), %rax
movq -0x20(%rbp), %rcx
addq -0x28(%rbp), %rcx
cmpq %rcx, %rax
jle 0xa9f14
jmp 0xa9f7b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x88(%rbp), %r8
movzbl -0x89(%rbp), %r10d
movzbl -0x8a(%rbp), %eax
leaq -0x68(%rbp), %r9
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0xaa050
movq -0x88(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0xa9c75
jmp 0xa9f7b
movq -0x8(%rbp), %rdi
movl -0x6c(%rbp), %esi
callq 0x15b5a0
addq $0xc0, %rsp
popq %rbp
retq