// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movq %r9, 0x10(%rsp)
movl %r8d, 0xc(%rsp)
movq %rcx, %r13
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq %rdx, (%rsp)
movl $0x30, %esi
callq 0xe969b
movq %rax, %r12
addq %rbx, %r13
movq (%rsp), %rax
leaq 0x2(%rax), %rcx
cmpq %r13, %rcx
jg 0x27342
xorl %ebp, %ebp
movq %rsp, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movups %xmm0, 0x10(%r12)
movups %xmm0, 0x20(%r12)
movl 0xc(%rsp), %ecx
movl %ecx, (%r12)
movl %ebp, 0x4(%r12)
movq %rax, 0x10(%r12)
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xef14d
movb %al, 0x8(%r12)
cmpb $-0x2, %al
jne 0x27209
cmpl $0x4, (%r15)
jne 0x27209
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xef14d
movzbl %al, %eax
movq %rax, 0x28(%r12)
movq (%rsp), %rcx
movq %rcx, 0x20(%r12)
addq $0x2, %rax
jmp 0x272d6
cmpb 0x24(%r15), %al
jne 0x27322
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xef14d
movb %al, 0x9(%r12)
movl %eax, %ecx
andb $0x7f, %cl
movb %cl, 0xa(%r12)
testb %al, %al
je 0x2730e
movzbl %al, %eax
cmpl $0x80, %eax
je 0x2730e
cmpl $0x1f, %eax
je 0x2730e
cmpl $0x3, (%r15)
jne 0x27284
addq $0x39, (%rsp)
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xef14d
cmpb $0x1a, %al
jne 0x27342
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xef14d
movb %al, 0x9(%r12)
andb $0x7f, %al
movb %al, 0xa(%r12)
addq $0xd, (%rsp)
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xef3a0
movq %rax, 0x28(%r12)
movq (%rsp), %rax
leaq 0x6(%rax), %rcx
movq %rcx, (%rsp)
cmpb $0x1, 0xa(%r12)
je 0x272b6
addq $0xa, %rax
movq %rax, (%rsp)
cmpb $0x0, 0x9(%r12)
jns 0x272c3
addq $0xc, (%rsp)
movq (%rsp), %rax
movq %rax, 0x20(%r12)
addq 0x28(%r12), %rax
subq 0x10(%r12), %rax
movq %rax, 0x18(%r12)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *0x10(%rsp)
movq 0x10(%r12), %rcx
movq 0x18(%r12), %rdx
leaq (%rdx,%rcx), %rax
movq %rax, (%rsp)
addq %rdx, %rcx
addq $0x2, %rcx
incl %ebp
cmpq %r13, %rcx
jle 0x271a2
jmp 0x27342
movq $0x2, 0x18(%r12)
movq 0x10(%r12), %rax
addq $0x2, %rax
jmp 0x27330
movq $0x1, 0x18(%r12)
movq 0x10(%r12), %rax
movq %rax, 0x20(%r12)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *0x10(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0xe9752
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq