// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/arc.c
// Function: parse_member_sequence
static void parse_member_sequence(deark *c, lctx *d, i64 pos1, i64 len, int nesting_level,
	member_cb_type member_cbfn)
{
	struct member_parser_data *mpd = NULL;
	int member_idx = 0;
	i64 pos = pos1;

	mpd = de_malloc(c, sizeof(struct member_parser_data));

	while(1) {
		if(pos+2 > pos1+len) break;
		de_zeromem(mpd, sizeof(struct member_parser_data));
		mpd->nesting_level = nesting_level;
		mpd->member_idx = member_idx++;
		mpd->member_pos = pos;

		mpd->magic = de_getbyte_p(&pos);

		if(mpd->magic==0xfe && d->fmt==FMT_PAK16SFX) {
			// Some hacks here. We're not setting all the fields correctly,
			// just the ones we need.
			mpd->cmpr_data_len = (i64)de_getbyte_p(&pos);
			mpd->cmpr_data_pos = pos;
			mpd->member_len = 2+mpd->cmpr_data_len;
			member_cbfn(c, d, mpd);
			pos = mpd->member_pos + mpd->member_len;
			continue;
		}
		else if(mpd->magic!=d->sig_byte) {
			mpd->member_len = 1;
			mpd->cmpr_data_pos = mpd->member_pos; // dummy value
			member_cbfn(c, d, mpd);
			break;
		}
		mpd->cmpr_meth = de_getbyte_p(&pos);
		mpd->cmpr_meth_masked = mpd->cmpr_meth & 0x7f;

		if(mpd->cmpr_meth_masked==0x00 || mpd->cmpr_meth==0x1f) { // end of archive/dir
			mpd->member_len = 2;
			mpd->cmpr_data_pos = mpd->member_pos+2; // dummy value
			member_cbfn(c, d, mpd);
			break;
		}

		if(d->fmt==FMT_ARCMAC) {
			u8 magic2;

			// TODO: Check for EOF?
			pos += 57; // Skip remainder of 59-byte ArcMac preheader
			magic2 = de_getbyte_p(&pos);
			if(magic2 != 0x1a) { // Error
				// TODO: Call member_cbfn()?
				break;
			}

			// Read the "real" compression method field (should be the same?).
			mpd->cmpr_meth = de_getbyte_p(&pos);
			mpd->cmpr_meth_masked = mpd->cmpr_meth & 0x7f;
		}

		pos += 13;
		mpd->cmpr_data_len = de_getu32le_p(&pos);
		pos += 2+2+2;
		if(mpd->cmpr_meth_masked!=0x01) {
			pos += 4; // original size
		}
		if(mpd->cmpr_meth & 0x80) {
			pos += 12; // Spark-specific data
		}

		mpd->cmpr_data_pos = pos;
		mpd->member_len = mpd->cmpr_data_pos + mpd->cmpr_data_len - mpd->member_pos;
		member_cbfn(c, d, mpd);

		pos = mpd->member_pos + mpd->member_len;
	}

	de_free(c, mpd);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x18(%rsp)
movl %r8d, 0x14(%rsp)
movq %rcx, %rbx
movq %rdx, %rbp
movq %rsi, %r15
movq %rdi, %r14
movq %rdx, 0x8(%rsp)
movl $0x30, %esi
callq 0xe8b2b
movq %rax, %r12
movq %rbx, 0x20(%rsp)
cmpq $0x2, %rbx
jl 0x27354
addq %rbp, 0x20(%rsp)
movq %r12, %r13
addq $0x8, %r13
xorl %ebx, %ebx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r13)
movups %xmm0, (%r13)
movq $0x0, 0x20(%r13)
movl 0x14(%rsp), %eax
movl %eax, (%r12)
movl %ebx, 0x4(%r12)
movq %rbp, 0x10(%r12)
movq 0x18(%r14), %rdi
leaq 0x8(%rsp), %rbp
movq %rbp, %rsi
callq 0xeeb4b
movb %al, 0x8(%r12)
cmpb $-0x2, %al
jne 0x2720d
cmpl $0x4, (%r15)
jne 0x2720d
movq 0x18(%r14), %rdi
movq %rbp, %rsi
callq 0xeeb4b
movzbl %al, %eax
movq %rax, 0x28(%r12)
movq 0x8(%rsp), %rcx
movq %rcx, 0x20(%r12)
addq $0x2, %rax
jmp 0x272e5
cmpb 0x24(%r15), %al
jne 0x27334
movq 0x18(%r14), %rdi
movq %rbp, %rsi
callq 0xeeb4b
movb %al, 0x9(%r12)
movl %eax, %ecx
andb $0x7f, %cl
movb %cl, 0xa(%r12)
testb %al, %al
je 0x27320
movzbl %al, %eax
cmpl $0x80, %eax
je 0x27320
cmpl $0x1f, %eax
je 0x27320
cmpl $0x3, (%r15)
jne 0x2728e
addq $0x39, 0x8(%rsp)
movq 0x18(%r14), %rdi
movq %rbp, %rsi
callq 0xeeb4b
cmpb $0x1a, %al
jne 0x27354
movq 0x18(%r14), %rdi
leaq 0x8(%rsp), %rbp
movq %rbp, %rsi
callq 0xeeb4b
movb %al, 0x9(%r12)
andb $0x7f, %al
movb %al, 0xa(%r12)
addq $0xd, 0x8(%rsp)
movq 0x18(%r14), %rdi
movq %rbp, %rsi
callq 0xeed83
movq %rax, 0x28(%r12)
movq 0x8(%rsp), %rdx
leaq 0x6(%rdx), %rcx
movq %rcx, 0x8(%rsp)
cmpb $0x1, 0xa(%r12)
je 0x272c7
addq $0xa, %rdx
movq %rdx, 0x8(%rsp)
movq %rdx, %rcx
cmpb $0x0, 0x9(%r12)
jns 0x272d8
addq $0xc, %rcx
movq %rcx, 0x8(%rsp)
movq %rcx, 0x20(%r12)
addq %rcx, %rax
subq 0x10(%r12), %rax
movq %rax, 0x18(%r12)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *0x18(%rsp)
movq 0x10(%r12), %rax
movq 0x18(%r12), %rcx
leaq (%rcx,%rax), %rbp
movq %rbp, 0x8(%rsp)
addq %rcx, %rax
addq $0x2, %rax
incl %ebx
cmpq 0x20(%rsp), %rax
jle 0x2719f
jmp 0x27354
movq $0x2, 0x18(%r12)
movq 0x10(%r12), %rax
addq $0x2, %rax
jmp 0x27342
movq $0x1, 0x18(%r12)
movq 0x10(%r12), %rax
movq %rax, 0x20(%r12)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *0x18(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0xe8be2
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq