// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/lha.c
// Function: do_read_ext_headers
static int do_read_ext_headers(deark *c, lctx *d, struct member_data *md,
	i64 pos1, i64 len, i64 first_ext_hdr_size, i64 *tot_bytes_consumed)
{
	i64 pos = pos1;
	i64 this_ext_hdr_size, next_ext_hdr_size;
	int retval = 0;
	i64 size_of_size_field;

	*tot_bytes_consumed = 0;

	if(first_ext_hdr_size==0) {
		return 1;
	}

	de_dbg(c, "ext headers section at %"I64_FMT, pos);
	de_dbg_indent(c, 1);

	size_of_size_field = (md->hlev==3) ? 4 : 2;

	next_ext_hdr_size = first_ext_hdr_size;
	while(1) {
		this_ext_hdr_size = next_ext_hdr_size;
		if(this_ext_hdr_size==0) {
			retval = 1;
			*tot_bytes_consumed = pos - pos1;
			goto done;
		}
		if(this_ext_hdr_size<size_of_size_field) goto done;
		if(pos+this_ext_hdr_size > pos1+len) goto done;

		do_read_ext_header(c, d, md, pos, this_ext_hdr_size, this_ext_hdr_size-size_of_size_field);

		// Each ext header ends with a "size of next header" field.
		// We'll read it at this level, instead of in do_read_ext_header().
		pos += this_ext_hdr_size-size_of_size_field;
		if(size_of_size_field==2) {
			next_ext_hdr_size = de_getu16le(pos);
		}
		else {
			next_ext_hdr_size = de_getu32le(pos);
		}
		pos += size_of_size_field;
	}

done:
	if(retval) {
		de_dbg(c, "size of ext headers section: %"I64_FMT, (i64)*tot_bytes_consumed);
	}
	else {
		de_dbg(c, "failed to parse all extended headers");
	}
	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, 0x50(%rsp)
movq 0x90(%rsp), %rax
andq $0x0, (%rax)
testq %r9, %r9
je 0x82037
movq %r9, %rbp
movq %r8, %r12
movq %rcx, %r15
movq %rdx, %r14
movq %rdi, %rbx
leaq 0x9d0f2(%rip), %rsi     # 0x11ef4d
movq %rcx, %rdx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, 0x28(%rsp)
movq %rbx, %rdi
callq 0xdeba7
movb (%r14), %cl
xorl %eax, %eax
movb %cl, 0x1b(%rsp)
cmpb $0x3, %cl
sete %al
leaq 0x2(,%rax,2), %rax
movq %rax, 0x30(%rsp)
addq %r15, %r12
movq %r15, %rdx
movq %r14, 0x48(%rsp)
movq %r15, 0x40(%rsp)
movq %r12, 0x38(%rsp)
testq %rbp, %rbp
je 0x8203c
cmpq 0x30(%rsp), %rbp
jl 0x8201d
leaq (%rdx,%rbp), %r14
cmpq %r12, %r14
jg 0x8201d
movq %rbp, %r12
subq 0x30(%rsp), %r12
movq %rdx, 0x20(%rsp)
jle 0x81f10
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rdi
movq %rdx, %rsi
callq 0xe3eb4
pushq $0x16
popq %rcx
leaq 0x104f97(%rip), %rdx    # 0x186e88
decq %rcx
je 0x81f24
leaq 0x18(%rdx), %r15
cmpb %al, 0x18(%rdx)
movq %r15, %rdx
jne 0x81ef1
movq 0x8(%r15), %rcx
movl $0x0, 0x1c(%rsp)
jmp 0x81f34
movb $0x1, %al
movl %eax, 0x1c(%rsp)
xorl %r15d, %r15d
xorl %eax, %eax
leaq 0x9cfbf(%rip), %rcx     # 0x11eee1
jmp 0x81f39
movb $0x1, %cl
movl %ecx, 0x1c(%rsp)
xorl %r15d, %r15d
leaq 0x9cfad(%rip), %rcx     # 0x11eee1
movq 0x20(%rsp), %rdx
leaq -0x1(%r12), %r13
movzbl %al, %ebx
movq %rcx, 0x8(%rsp)
movl %ebx, (%rsp)
movq 0x28(%rsp), %rdi
leaq 0x9d059(%rip), %rsi     # 0x11efae
movq %rbp, %rcx
movq %rdi, %rbp
movq %r13, %r8
movq 0x30(%rsp), %r9
xorl %eax, %eax
callq 0xde896
testq %r12, %r12
jle 0x81fe6
movq %rbp, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
cmpb $0x0, 0x1c(%rsp)
jne 0x81fad
movq 0x10(%r15), %rax
testq %rax, %rax
je 0x81fad
movq 0x20(%rsp), %rcx
leaq 0x1(%rcx), %r9
movq %r13, (%rsp)
movq %rbp, %rdi
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdx
movl %ebx, %ecx
movq %r15, %r8
callq *%rax
jmp 0x81fdb
cmpl $0x2, (%rbp)
jl 0x81fdb
movq 0x18(%rbp), %rsi
movq 0x20(%rsp), %rax
leaq 0x1(%rax), %rdx
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %rbp, %rdi
movq %r13, %rcx
xorl %r9d, %r9d
callq 0xded3a
movq %rbp, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
addq 0x20(%rsp), %r12
movq 0x18(%rbp), %rdi
cmpb $0x3, 0x1b(%rsp)
jne 0x82000
movq %r12, %rsi
callq 0xe409f
jmp 0x82008
movq %r12, %rsi
callq 0xe3fa3
movq %rax, %rbp
movq %r14, %rdx
movq 0x40(%rsp), %r15
movq 0x38(%rsp), %r12
jmp 0x81ea6
leaq 0x9cf65(%rip), %rsi     # 0x11ef89
xorl %ebp, %ebp
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
jmp 0x82063
pushq $0x1
popq %rbp
jmp 0x8206e
subq %r15, %rdx
movq 0x90(%rsp), %rax
movq %rdx, (%rax)
leaq 0x9cf17(%rip), %rsi     # 0x11ef68
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rbp
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq