// File: /workspace/github_c_makefile_star2_O3/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, 0x40(%rsp)
movq 0x90(%rsp), %rax
movq $0x0, (%rax)
testq %r9, %r9
je 0x86fbd
movq %r9, %r15
movq %r8, %r13
movq %rcx, %r12
movq %rdx, %r14
movq %rdi, %rbx
leaq 0xa541e(%rip), %rsi     # 0x12c1bd
movq %rcx, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %r14, 0x38(%rsp)
movb (%r14), %cl
xorl %eax, %eax
movb %cl, 0x13(%rsp)
cmpb $0x3, %cl
sete %al
leaq 0x2(,%rax,2), %rax
movq %rax, 0x28(%rsp)
addq %r12, %r13
leaq 0xfd0aa(%rip), %r14     # 0x183e90
movq %r12, 0x30(%rsp)
movq %r13, 0x48(%rsp)
cmpq 0x28(%rsp), %r15
jl 0x86f96
leaq (%r15,%r12), %rax
cmpq %r13, %rax
jg 0x86f96
movq %rax, 0x50(%rsp)
movq %r15, %r13
subq 0x28(%rsp), %r13
jle 0x86e4e
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rdi
movq %r12, %rsi
callq 0xeead3
xorl %ecx, %ecx
cmpb %al, (%rcx,%r14)
je 0x86e68
addq $0x18, %rcx
cmpq $0x1f8, %rcx            # imm = 0x1F8
jne 0x86e2a
movb $0x1, %cl
movl %ecx, 0x14(%rsp)
movq $0x0, 0x18(%rsp)
jmp 0x86e5f
movb $0x1, %al
movl %eax, 0x14(%rsp)
movq $0x0, 0x18(%rsp)
xorl %eax, %eax
leaq 0xa52eb(%rip), %rcx     # 0x12c151
jmp 0x86e7e
leaq (%r14,%rcx), %rdx
movq %rdx, 0x18(%rsp)
movq 0x8(%rcx,%r14), %rcx
movl $0x0, 0x14(%rsp)
leaq -0x1(%r13), %rbp
movzbl %al, %ebx
movq %rcx, 0x8(%rsp)
movl %ebx, (%rsp)
movq 0x20(%rsp), %rdi
leaq 0xa5385(%rip), %rsi     # 0x12c21e
movq %r12, %rdx
movq %r15, %rcx
movq %rdi, %r15
movq %rbp, %r8
movq 0x28(%rsp), %r9
xorl %eax, %eax
callq 0xe8617
testq %r13, %r13
jle 0x86f30
movq %r15, %rdi
movl $0x1, %esi
callq 0xe8a15
cmpb $0x0, 0x14(%rsp)
jne 0x86ef9
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x86ef9
leaq 0x1(%r12), %r9
movq %rbp, (%rsp)
movq %r15, %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
movl %ebx, %ecx
movq 0x18(%rsp), %r8
callq *%rax
jmp 0x86f23
cmpl $0x2, (%r15)
jl 0x86f23
movq 0x18(%r15), %rsi
leaq 0x1(%r12), %rdx
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %r15, %rdi
movq %rbp, %rcx
xorl %r9d, %r9d
callq 0xe8bea
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
addq %r12, %r13
movq 0x18(%r15), %rdi
cmpb $0x3, 0x13(%rsp)
jne 0x86f48
movq %r13, %rsi
callq 0xeed61
jmp 0x86f50
movq %r13, %rsi
callq 0xeebc8
movq %rax, %r15
movq 0x50(%rsp), %rdx
movq %rdx, %r12
testq %rax, %rax
movq 0x48(%rsp), %r13
jne 0x86df0
subq 0x30(%rsp), %rdx
movq 0x90(%rsp), %rax
movq %rdx, (%rax)
leaq 0xa5258(%rip), %rsi     # 0x12c1d8
movq 0x20(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8617
movl $0x1, %ebx
jmp 0x86fae
leaq 0xa525c(%rip), %rsi     # 0x12c1f9
xorl %ebx, %ebx
movq 0x20(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8617
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
jmp 0x86fc2
movl $0x1, %ebx
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq