// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x54(%rbp)
movq 0x10(%rbp), %rax
movq $0x0, (%rax)
cmpq $0x0, -0x38(%rbp)
jne 0xc4521
movl $0x1, -0x4(%rbp)
jmp 0xc4676
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0xf3769(%rip), %rsi     # 0x1b7c99
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x20(%rbp), %rax
movzbl (%rax), %edx
movl $0x2, %eax
movl $0x4, %ecx
cmpl $0x3, %edx
cmovel %ecx, %eax
cltq
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xc4594
movl $0x1, -0x54(%rbp)
movq -0x40(%rbp), %rcx
subq -0x28(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0xc462f
movq -0x48(%rbp), %rax
cmpq -0x60(%rbp), %rax
jge 0xc45a3
jmp 0xc462f
movq -0x40(%rbp), %rax
addq -0x48(%rbp), %rax
movq -0x28(%rbp), %rcx
addq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jle 0xc45ba
jmp 0xc462f
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x48(%rbp), %r9
subq -0x60(%rbp), %r9
callq 0xc59a0
movq -0x48(%rbp), %rax
subq -0x60(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x2, -0x60(%rbp)
jne 0xc4609
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x165280
movq %rax, -0x50(%rbp)
jmp 0xc461e
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x165540
movq %rax, -0x50(%rbp)
movq -0x60(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0xc456a
cmpl $0x0, -0x54(%rbp)
je 0xc4650
movq -0x10(%rbp), %rdi
movq 0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0xf366d(%rip), %rsi     # 0x1b7cb4
movb $0x0, %al
callq 0x15b0d0
jmp 0xc4662
movq -0x10(%rbp), %rdi
leaq 0xf367a(%rip), %rsi     # 0x1b7cd5
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x54(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop