// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/id3.c
// Function: do_id3v2_header
static int do_id3v2_header(deark *c, dbuf *f, id3v2ctx *d)
{
	i64 pos;
	u8 flags;
	int retval = 0;
	int has_global_compression = 0;

	pos = 0;
	d->approx_mark = "";

	de_dbg(c, "ID3v2 header at %d", (int)pos);
	de_dbg_indent(c, 1);

	// TODO: Verify signature
	d->has_id3v2 = 1;
	pos += 3; // ID3v2 file identifier

	d->version_code = dbuf_getbyte(f, pos++);
	d->ver_revision = dbuf_getbyte(f, pos++);
	de_dbg(c, "ID3v2 version: (2.)%d.%d", (int)d->version_code, (int)d->ver_revision);
	if(d->version_code<2 || d->version_code>4) {
		de_warn(c, "Unsupported ID3v2 version: (2.)%d.x", (int)d->version_code);
		goto done;
	}

	flags = dbuf_getbyte(f, pos++);
	de_dbg(c, "flags: 0x%02x", (unsigned int)flags);
	de_dbg_indent(c, 1);

	if(d->version_code<=3) {
		d->global_level_unsync = (flags&0x80)?1:0;
		de_dbg(c, "global-level unsynchronisation: %d", (int)d->global_level_unsync);
	}
	else if(d->version_code==4) {
		d->global_frame_level_unsync = (flags&0x80)?1:0;
		de_dbg(c, "all frames use unsynchronisation: %d", (int)d->global_frame_level_unsync);
	}

	if(d->global_level_unsync) {
		d->approx_mark = "~";
	}

	if(d->version_code==2) {
		has_global_compression = (flags&0x40)?1:0;
		de_dbg(c, "uses compression: %d", d->has_ext_header);
	}
	else if(d->version_code>=3) {
		d->has_ext_header = (flags&0x40)?1:0;
		de_dbg(c, "has extended header: %d", d->has_ext_header);
	}

	if(d->version_code>=3) {
		d->is_experimental = (flags&0x20)?1:0;
		de_dbg(c, "is experimental: %d", d->is_experimental);
	}

	if(d->version_code >= 4) {
		d->has_footer = (flags&0x10)?1:0;
		de_dbg(c, "has footer: %d", d->has_footer);
	}

	de_dbg_indent(c, -1);

	d->data_len = get_synchsafe_int(f, pos);
	de_dbg(c, "size: %d", (int)d->data_len);
	//pos += 4;

	d->data_start = 10;

	d->total_len = d->data_start + d->data_len;
	if(d->has_footer) d->total_len += 10;

	de_dbg(c, "calculated end of ID3v2 data: %d", (int)d->total_len);

	if(has_global_compression) {
		de_warn(c, "ID3v2.2.x Compression not supported");
		goto done;
	}

	retval = 1;

done:
	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
leaq 0x1274eb(%rip), %rcx    # 0x1d0bd0
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0x109a6f(%rip), %rsi    # 0x1b3169
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x18(%rbp), %rax
movb $0x1, (%rax)
movq -0x20(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
callq 0x165060
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x30(%rax)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
callq 0x165060
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x31(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl 0x30(%rax), %edx
movq -0x18(%rbp), %rax
movzbl 0x31(%rax), %ecx
leaq 0x1099fd(%rip), %rsi    # 0x1b317c
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x2, %eax
jl 0xa97a0
movq -0x18(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x4, %eax
jle 0xa97bf
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl 0x30(%rax), %edx
leaq 0x1099e2(%rip), %rsi    # 0x1b3195
movb $0x0, %al
callq 0x15bc10
jmp 0xa9a74
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
callq 0x165060
movb %al, -0x21(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x21(%rbp), %edx
leaq 0x112330(%rip), %rsi    # 0x1bbb19
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x18(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x3, %eax
jg 0xa9847
movzbl -0x21(%rbp), %edx
andl $0x80, %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x32(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl 0x32(%rax), %edx
leaq 0x10997b(%rip), %rsi    # 0x1b31b9
movb $0x0, %al
callq 0x15b0d0
jmp 0xa9890
movq -0x18(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x4, %eax
jne 0xa988e
movzbl -0x21(%rbp), %edx
andl $0x80, %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x33(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl 0x33(%rax), %edx
leaq 0x109955(%rip), %rsi    # 0x1b31dc
movb $0x0, %al
callq 0x15b0d0
jmp 0xa9890
movq -0x18(%rbp), %rax
cmpb $0x0, 0x32(%rax)
je 0xa98a9
movq -0x18(%rbp), %rax
leaq 0x12546b(%rip), %rcx    # 0x1ced10
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x2, %eax
jne 0xa98e9
movzbl -0x21(%rbp), %edx
andl $0x40, %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl 0x34(%rax), %edx
leaq 0x109921(%rip), %rsi    # 0x1b3201
movb $0x0, %al
callq 0x15b0d0
jmp 0xa992f
movq -0x18(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x3, %eax
jl 0xa992d
movzbl -0x21(%rbp), %edx
andl $0x40, %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x34(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl 0x34(%rax), %edx
leaq 0x1098f0(%rip), %rsi    # 0x1b3216
movb $0x0, %al
callq 0x15b0d0
jmp 0xa992f
movq -0x18(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x3, %eax
jl 0xa9973
movzbl -0x21(%rbp), %edx
andl $0x20, %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x35(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl 0x35(%rax), %edx
leaq 0x1098c2(%rip), %rsi    # 0x1b322e
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x4, %eax
jl 0xa99b7
movzbl -0x21(%rbp), %edx
andl $0x10, %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x36(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movzbl 0x36(%rax), %edx
leaq 0x109892(%rip), %rsi    # 0x1b3242
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xa9a90
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0x118fbd(%rip), %rsi    # 0x1c29af
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq $0xa, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x18(%rbp), %rax
addq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x36(%rax)
je 0xa9a37
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0xa, %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edx
leaq 0x109805(%rip), %rsi    # 0x1b3251
movb $0x0, %al
callq 0x15b0d0
cmpl $0x0, -0x2c(%rbp)
je 0xa9a6d
movq -0x8(%rbp), %rdi
leaq 0x10980e(%rip), %rsi    # 0x1b3272
movb $0x0, %al
callq 0x15bc10
jmp 0xa9a74
movl $0x1, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x28(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)