// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movl $0x30, %esi
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rax
addq $0x2, %rax
movq -0x18(%rbp), %rcx
addq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jle 0x30033
jmp 0x302f4
movq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x19140
movl -0x24(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movl -0x3c(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165170
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0x8(%rax)
movq -0x38(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0xfe, %eax
jne 0x30105
movq -0x10(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x30105
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x2, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq *%rax
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
addq 0x18(%rcx), %rax
movq %rax, -0x48(%rbp)
jmp 0x30019
movq -0x38(%rbp), %rax
movzbl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x24(%rcx), %ecx
cmpl %ecx, %eax
je 0x3014c
movq -0x38(%rbp), %rax
movq $0x1, 0x18(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq *%rax
jmp 0x302f4
jmp 0x3014e
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165170
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0x9(%rax)
movq -0x38(%rbp), %rax
movzbl 0x9(%rax), %eax
andl $0x7f, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0xa(%rax)
movq -0x38(%rbp), %rax
movzbl 0xa(%rax), %eax
cmpl $0x0, %eax
je 0x30196
movq -0x38(%rbp), %rax
movzbl 0x9(%rax), %eax
cmpl $0x1f, %eax
jne 0x301cd
movq -0x38(%rbp), %rax
movq $0x2, 0x18(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x2, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq *%rax
jmp 0x302f4
movq -0x10(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x30232
movq -0x48(%rbp), %rax
addq $0x39, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165170
movb %al, -0x49(%rbp)
movzbl -0x49(%rbp), %eax
cmpl $0x1a, %eax
je 0x30204
jmp 0x302f4
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165170
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0x9(%rax)
movq -0x38(%rbp), %rax
movzbl 0x9(%rax), %eax
andl $0x7f, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0xa(%rax)
movq -0x48(%rbp), %rax
addq $0xd, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x48(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movzbl 0xa(%rax), %eax
cmpl $0x1, %eax
je 0x3027f
movq -0x48(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movzbl 0x9(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x3029d
movq -0x48(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x38(%rbp), %rax
addq 0x28(%rax), %rcx
movq -0x38(%rbp), %rax
subq 0x10(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq *%rax
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
addq 0x18(%rcx), %rax
movq %rax, -0x48(%rbp)
jmp 0x30019
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15b820
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)