// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/arcfs.c
// Function: do_arcfs_member
static int do_arcfs_member(deark *c, lctx *d, i64 idx, i64 pos1)
{
	i64 pos = pos1;
	u32 info_word;
	u8 info_byte;
	unsigned int tmpflags;
	int saved_indent_level;
	struct arcfs_member_data *md;
	int retval = 0;

	de_dbg_indent_save(c, &saved_indent_level);
	md = de_malloc(c, sizeof(struct arcfs_member_data));
	de_dbg(c, "header at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);

	retval = 1;
	info_byte = de_getbyte_p(&pos);
	md->cmpr_meth_name = get_info_byte_name(info_byte);
	de_dbg(c, "info byte: 0x%02x (%s)", (unsigned int)info_byte, md->cmpr_meth_name);
	if(info_byte==1) goto done; // deleted object
	if(info_byte==0) { // end of directory marker
		if(d->subdir_level>0) d->subdir_level--;
		de_strarray_pop(d->curpath);
		goto done;
	}
	md->cmpr_method = info_byte;

	// Look ahead at the "information word".
	// TODO: Is this the right way to check for a directory?
	info_word = (u32)de_getu32le(pos1+32);
	md->is_dir = (info_word&0x80000000U)?1:0;
	md->is_regular_file = !md->is_dir;

	md->fn = ucstring_create(c);
	dbuf_read_to_ucstring(c->infile, pos, 11, md->fn, DE_CONVFLAG_STOP_AT_NUL,
		DE_ENCODING_RISCOS);
	de_dbg(c, "filename: \"%s\"", ucstring_getpsz_d(md->fn));
	if(md->is_dir) {
		if(d->subdir_level >= MAX_NESTING_LEVEL) {
			de_err(c, "Directories nested too deeply");
			retval = 0;
			goto done;
		}
		d->subdir_level++;
		de_strarray_push(d->curpath, md->fn);
	}
	pos += 11;

	md->orig_len = de_getu32le_p(&pos);
	if(md->is_regular_file) {
		de_dbg(c, "orig file length: %"I64_FMT, md->orig_len);
	}

	fmtutil_riscos_read_load_exec(c, c->infile, &md->rfa, pos);
	pos += 8;

	tmpflags = 0;
	if(md->is_regular_file)
		tmpflags |= DE_RISCOS_FLAG_HAS_CRC;
	if(md->cmpr_method==0xff || md->cmpr_method==0x88)
		tmpflags |= DE_RISCOS_FLAG_HAS_LZWMAXBITS;
	fmtutil_riscos_read_attribs_field(c, c->infile, &md->rfa, pos, tmpflags);
	pos += 4;

	md->cmpr_len = de_getu32le_p(&pos);
	if(md->is_regular_file) {
		de_dbg(c, "compressed length: %"I64_FMT, md->cmpr_len);
	}

	de_dbg(c, "info word: 0x%08x", (unsigned int)info_word);
	de_dbg_indent(c, 1);
	de_dbg(c, "is directory: %d", md->is_dir);
	if(md->is_regular_file) {
		md->file_data_offs_rel = (i64)info_word;
		md->file_data_offs_abs = d->data_offs+md->file_data_offs_rel;
		de_dbg(c, "file data offset: (%"I64_FMT"+)%"I64_FMT,
			d->data_offs, md->file_data_offs_rel);
	}
	de_dbg_indent(c, -1);

	de_dbg_indent(c, -1);

	do_arcfs_extract_member(c, d, md);

done:
	destroy_arcfs_member_data(c, md);
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// 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)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movl $0x70, %esi
callq 0x15b780
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x18193e(%rip), %rsi    # 0x1aed63
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movl $0x1, -0x44(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165170
movb %al, -0x2d(%rbp)
movzbl -0x2d(%rbp), %edi
callq 0x2d7d0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x8(%rbp), %rdi
movzbl -0x2d(%rbp), %edx
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rcx
leaq 0x172a91(%rip), %rsi    # 0x19ff11
movb $0x0, %al
callq 0x15b0d0
movzbl -0x2d(%rbp), %eax
cmpl $0x1, %eax
jne 0x2d495
jmp 0x2d7aa
movzbl -0x2d(%rbp), %eax
cmpl $0x0, %eax
jne 0x2d4c4
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x2d4b2
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x172850
jmp 0x2d7aa
movb -0x2d(%rbp), %cl
movq -0x40(%rbp), %rax
movb %cl, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x20, %rsi
callq 0x165540
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edx
andl $0x80000000, %edx       # imm = 0x80000000
xorl %ecx, %ecx
movl $0x1, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x30(%rax)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rcx
movl $0xb, %edx
movl $0x1, %r8d
movl $0x14, %r9d
callq 0x1669f0
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x172650
movq -0x50(%rbp), %rdi
movq %rax, %rdx
leaq 0x19a006(%rip), %rsi    # 0x1c7583
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x2d5d5
movq -0x10(%rbp), %rax
cmpl $0x20, (%rax)
jl 0x2d5b5
movq -0x8(%rbp), %rdi
leaq 0x172986(%rip), %rsi    # 0x19ff28
movb $0x0, %al
callq 0x15bfb0
movl $0x0, -0x44(%rbp)
jmp 0x2d7aa
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rsi
callq 0x1728d0
movq -0x28(%rbp), %rax
addq $0xb, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x2d621
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x50(%rax), %rdx
leaq 0x17292c(%rip), %rsi    # 0x19ff46
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x1755e0
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x2d660
movl -0x34(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x40(%rbp), %rax
movzbl 0x38(%rax), %eax
cmpl $0xff, %eax
je 0x2d67e
movq -0x40(%rbp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x88, %eax
jne 0x2d687
movl -0x34(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl -0x34(%rbp), %r8d
callq 0x175740
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x2d6f0
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x58(%rax), %rdx
leaq 0x172873(%rip), %rsi    # 0x19ff5c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %edx
leaq 0x172875(%rip), %rsi    # 0x19ff73
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl 0x30(%rax), %edx
leaq 0x172860(%rip), %rsi    # 0x19ff85
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x2d77d
movl -0x2c(%rbp), %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x40(%rbp), %rax
addq 0x40(%rax), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rcx
leaq 0x172820(%rip), %rsi    # 0x19ff96
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x2d8c0
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x2d9b0
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x15b5a0
movl -0x44(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)