// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/arj.c
// Function: do_extended_headers
static int do_extended_headers(deark *c, lctx *d, struct member_data *md,
	i64 pos1, i64 *pbytes_consumed)
{
	i64 pos = pos1;
	int idx = 0;
	u32 crc_reported;
	u32 crc_calc;
	int retval = 0;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "ext hdrs at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);

	while(1) {
		i64 ext_hdr_size;
		i64 ext_hdr_startpos = pos;
		i64 dpos;

		ext_hdr_size = dbuf_getu16le_p(d->inf, &pos);

		if(ext_hdr_size==0) {
			de_dbg(c, "end of ext hdrs at %"I64_FMT, pos);
			retval = 1;
			goto done;
		}
		de_dbg(c, "ext hdr #%d at %"I64_FMT", dlen=%"I64_FMT, idx, ext_hdr_startpos,
			ext_hdr_size);
		de_dbg_indent(c, 1);

		if(pos+ext_hdr_size+4 > d->inf->len) goto done;

		dpos = pos;

		de_crcobj_reset(d->crco);
		de_crcobj_addslice(d->crco, d->inf, dpos, ext_hdr_size);
		crc_calc = de_crcobj_getval(d->crco);

		pos = dpos + ext_hdr_size;
		crc_reported = (u32)dbuf_getu32le_p(d->inf, &pos);

		de_dbg(c, "ext hdr crc (reported): 0x%08x", (UI)crc_reported);
		de_dbg(c, "ext hdr crc (calculated): 0x%08x", (UI)crc_calc);
		if(crc_calc != crc_reported) goto done; // Assume we've gone off the rails

		de_dbg_hexdump(c, d->inf, dpos, ext_hdr_size, 256, NULL, 0x1);

		idx++;
		de_dbg_indent(c, -1);
	}

done:
	*pbytes_consumed = pos - pos1;
	de_dbg_indent_restore(c, saved_indent_level);
	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 -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x15a5f5(%rip), %rsi    # 0x1a4263
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x49cc8
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x15a5a7(%rip), %rsi    # 0x1a425c
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x40(%rbp)
jmp 0x49deb
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %edx
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %r8
leaq 0x15a595(%rip), %rsi    # 0x1a4273
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x30(%rbp), %rax
addq -0x50(%rbp), %rax
addq $0x4, %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x49d11
jmp 0x49deb
movq -0x30(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x15f250
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x60(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq 0x15f500
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x15f340
movl %eax, -0x3c(%rbp)
movq -0x60(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %edx
leaq 0x15a511(%rip), %rsi    # 0x1a4290
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %edx
leaq 0x15a51b(%rip), %rsi    # 0x1a42af
movb $0x0, %al
callq 0x15b0d0
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
je 0x49da5
jmp 0x49deb
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x60(%rbp), %rdx
movq -0x50(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, (%rsp)
callq 0x15b840
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0x49c83
movq -0x30(%rbp), %rcx
subq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x15b5a0
movl -0x40(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop