// File: /workspace/github_c_makefile_star2_O1/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 %r8, 0x30(%rsp)
movq %rsi, 0x48(%rsp)
movq 0x90(%rsp), %rax
movq $0x0, (%rax)
testq %r9, %r9
je 0x87623
movq %r9, %r13
movq %rdi, %r14
leaq 0xa4a70(%rip), %rsi     # 0x12bed5
movq %rcx, %r15
movq %rdx, %r12
xorl %ebx, %ebx
movq %rcx, %rdx
xorl %eax, %eax
callq 0xe9226
movq %r14, 0x20(%rsp)
movq %r14, %rdi
movl $0x1, %esi
callq 0xe9585
movq %r12, 0x40(%rsp)
movb (%r12), %cl
xorl %eax, %eax
movb %cl, 0x1f(%rsp)
cmpb $0x3, %cl
sete %al
leaq 0x2(,%rax,2), %rax
movl $0x0, %r14d
movq %rax, 0x28(%rsp)
cmpq %r13, %rax
jg 0x87641
addq %r15, 0x30(%rsp)
leaq 0xfc92a(%rip), %rbp     # 0x183df0
movq %r15, 0x38(%rsp)
xorl %ebx, %ebx
leaq (%r15,%r13), %rax
cmpq 0x30(%rsp), %rax
jg 0x8761e
movq %rax, 0x50(%rsp)
movq %r13, %r14
subq 0x28(%rsp), %r14
jle 0x87514
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rdi
movq %r15, %rsi
callq 0xef0d5
xorl %r12d, %r12d
cmpb %al, (%r12,%rbp)
je 0x8751b
addq $0x18, %r12
cmpq $0x1f8, %r12            # imm = 0x1F8
jne 0x874ff
jmp 0x87516
xorl %eax, %eax
xorl %r12d, %r12d
jmp 0x8751e
addq %rbp, %r12
leaq 0xa4944(%rip), %rcx     # 0x12be69
testq %r12, %r12
je 0x8752f
movq 0x8(%r12), %rcx
leaq -0x1(%r14), %rbp
movzbl %al, %ebx
movq %rcx, 0x8(%rsp)
movl %ebx, (%rsp)
movq 0x20(%rsp), %rdi
leaq 0xa49ec(%rip), %rsi     # 0x12bf36
movq %r15, %rdx
movq %r13, %rcx
movq %rdi, %r13
movq %rbp, %r8
movq 0x28(%rsp), %r9
xorl %eax, %eax
callq 0xe9226
testq %r14, %r14
jle 0x875d8
movq %r13, %rdi
movl $0x1, %esi
callq 0xe9585
testq %r12, %r12
je 0x875a1
movq 0x10(%r12), %rax
testq %rax, %rax
je 0x875a1
leaq 0x1(%r15), %r9
movq %rbp, (%rsp)
movq %r13, %rdi
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdx
movl %ebx, %ecx
movq %r12, %r8
callq *%rax
jmp 0x875cb
cmpl $0x2, (%r13)
jl 0x875cb
movq 0x18(%r13), %rsi
leaq 0x1(%r15), %rdx
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %r13, %rdi
movq %rbp, %rcx
xorl %r9d, %r9d
callq 0xe975a
movq %r13, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
addq %r15, %r14
cmpb $0x3, 0x1f(%rsp)
jne 0x875f0
movq 0x18(%r13), %rdi
movq %r14, %rsi
callq 0xef37e
jmp 0x875fc
movq 0x18(%r13), %rdi
movq %r14, %rsi
callq 0xef1ca
movq %rax, %r13
leaq 0xfc7ea(%rip), %rbp     # 0x183df0
testq %rax, %rax
sete %bl
movq 0x50(%rsp), %r15
je 0x8762b
cmpq 0x28(%rsp), %r13
jge 0x874cd
xorl %r14d, %r14d
jmp 0x87641
movl $0x1, %r14d
jmp 0x8768c
subq 0x38(%rsp), %r15
movq 0x90(%rsp), %rax
movq %r15, (%rax)
movl $0x1, %r14d
testb $0x1, %bl
je 0x87669
movq 0x90(%rsp), %rax
movq (%rax), %rdx
leaq 0xa4898(%rip), %rsi     # 0x12bef0
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
jmp 0x8767f
leaq 0xa48a1(%rip), %rsi     # 0x12bf11
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq