// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/packdir.c
// Function: do_packdir_object
static int do_packdir_object(deark *c, struct pdctx_struct *d, i64 pos1,
	int level, i64 *bytes_consumed1)
{
	int saved_indent_level;
	i64 foundpos = 0;
	i64 pos = pos1;
	i64 name_len;
	i64 length_raw;
	struct pdctx_object *md = NULL;
	int retval = 0;
	int need_dirname_pop = 0;

	de_dbg_indent_save(c, &saved_indent_level);

	if(level >= MAX_NESTING_LEVEL) {
		goto done;
	}

	md = de_malloc(c, sizeof(struct pdctx_object));
	de_dbg(c, "object at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);
	*bytes_consumed1 = 0;

	if(!dbuf_search_byte(c->infile, 0x00, pos, 128, &foundpos)) {
		goto done;
	}
	name_len = foundpos - pos1;
	md->name = ucstring_create(c);
	dbuf_read_to_ucstring(c->infile, pos, name_len, md->name, 0x0, DE_ENCODING_RISCOS);
	de_dbg(c, "name: \"%s\"", ucstring_getpsz_d(md->name));
	pos += name_len + 1;

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

	length_raw = de_getu32le_p(&pos);

	fmtutil_riscos_read_attribs_field(c, c->infile, &md->rfa, pos, 0);
	pos += 4;

	if(level==0) {
		md->object_type = 1;
	}
	else {
		md->object_type = (u32)de_getu32le_p(&pos);
		de_dbg(c, "type: %u", (unsigned int)md->object_type);
	}

	if(md->object_type==0) {
		; // regular file
	}
	else if(md->object_type==1) {
		md->is_dir = 1;
	}
	else {
		goto done; // unknown type
	}

	if(md->is_dir) {
		i64 bytes_consumed2 = 0;
		i64 i;
		int ret;

		md->num_children = length_raw;
		de_dbg(c, "number of dir entries: %"I64_FMT, md->num_children);

		if(level<=0) {
			de_ucstring *tmpstr = ucstring_create(c);
			convert_root_name(c, d, md->name, tmpstr);
			de_strarray_push(d->curpath, tmpstr);
			ucstring_destroy(tmpstr);
		}
		else {
			de_strarray_push(d->curpath, md->name);
			need_dirname_pop = 1;
		}

		md->is_compressed = 0;
		md->orig_len = 0;
		md->cmpr_len = 0;
		do_packdir_extract_file(c, d, md, pos);

		for(i=0; i<md->num_children; i++) {
			if(pos >= c->infile->len) goto done;
			ret = do_packdir_object(c, d, pos, level+1, &bytes_consumed2);
			if((!ret) || bytes_consumed2<1) goto done;
			pos += bytes_consumed2;
		}
	}
	else {
		md->orig_len = length_raw;
		de_dbg(c, "original len: %"I64_FMT, md->orig_len);

		md->cmpr_len = de_getu32le_p(&pos);
		if(md->cmpr_len==0xffffffffLL) {
			// uncompressed
			md->cmpr_len = md->orig_len;
		}
		else {
			md->is_compressed = 1;
		}
		de_dbg(c, "is compressed: %d", md->is_compressed);
		if(md->is_compressed) {
			de_dbg(c, "cmpr len: %"I64_FMT, md->cmpr_len);
		}

		do_packdir_extract_file(c, d, md, pos);

		pos += md->cmpr_len;
	}

	*bytes_consumed1 = pos - pos1;
	retval = 1;

done:
	if(!retval && c->error_count==0) {
		de_err(c, "Can't parse object at %"I64_FMT, pos1);
	}
	if(md) {
		ucstring_destroy(md->name);
		de_free(c, md);
	}
	if(need_dirname_pop) {
		de_strarray_pop(d->curpath);
	}
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x15b580
cmpl $0x20, -0x1c(%rbp)
jl 0x11086c
jmp 0x110c65
movq -0x8(%rbp), %rdi
movl $0x60, %esi
callq 0x15b780
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x8df4c(%rip), %rsi     # 0x19e7d9
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rdx
xorl %esi, %esi
movl $0x80, %ecx
leaq -0x38(%rbp), %r8
callq 0x1667a0
cmpl $0x0, %eax
jne 0x1108d3
jmp 0x110c65
movq -0x38(%rbp), %rax
subq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rcx
xorl %r8d, %r8d
movl $0x14, %r9d
callq 0x1669f0
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x172650
movq -0x88(%rbp), %rdi
movq %rax, %rdx
leaq 0x9d88e(%rip), %rsi     # 0x1ae1d0
movb $0x0, %al
callq 0x15b0d0
movq -0x48(%rbp), %rax
addq $0x1, %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x58(%rbp), %rdx
addq $0x30, %rdx
movq -0x40(%rbp), %rcx
callq 0x1755e0
movq -0x40(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x165580
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x58(%rbp), %rdx
addq $0x30, %rdx
movq -0x40(%rbp), %rcx
xorl %r8d, %r8d
callq 0x175740
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x1109d5
movq -0x58(%rbp), %rax
movl $0x1, (%rax)
jmp 0x110a06
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x165580
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl (%rax), %edx
leaq 0xaccbb(%rip), %rsi     # 0x1bd6ba
movb $0x0, %al
callq 0x15b0d0
movq -0x58(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x110a11
jmp 0x110a2b
movq -0x58(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x110a24
movq -0x58(%rbp), %rax
movb $0x1, 0x4(%rax)
jmp 0x110a29
jmp 0x110c65
jmp 0x110a2b
movq -0x58(%rbp), %rax
cmpb $0x0, 0x4(%rax)
je 0x110b7f
movq $0x0, -0x68(%rbp)
movq -0x50(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0xb2ff0(%rip), %rsi     # 0x1c3a50
movb $0x0, %al
callq 0x15b0d0
cmpl $0x0, -0x1c(%rbp)
jg 0x110aaf
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rdx
movq -0x80(%rbp), %rcx
callq 0x110ce0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x80(%rbp), %rsi
callq 0x1728d0
movq -0x80(%rbp), %rdi
callq 0x171750
jmp 0x110acb
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x1728d0
movl $0x1, -0x60(%rbp)
movq -0x58(%rbp), %rax
movl $0x0, 0x20(%rax)
movq -0x58(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x58(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x40(%rbp), %rcx
callq 0x110d60
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq -0x58(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x110b7a
movq -0x40(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x110b30
jmp 0x110c65
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
leaq -0x68(%rbp), %r8
callq 0x110810
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x74(%rbp)
je 0x110b5b
cmpq $0x1, -0x68(%rbp)
jge 0x110b60
jmp 0x110c65
movq -0x68(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x110b0b
jmp 0x110c4f
movq -0x50(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0xb2ecd(%rip), %rsi     # 0x1c3a6b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x58(%rbp), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, 0x18(%rax)
jne 0x110be2
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x110bed
movq -0x58(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl 0x20(%rax), %edx
leaq 0xb2e7e(%rip), %rsi     # 0x1c3a7d
movb $0x0, %al
callq 0x15b0d0
movq -0x58(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x110c2a
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0xc5a3e(%rip), %rsi     # 0x1d6661
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x40(%rbp), %rcx
callq 0x110d60
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
subq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jne 0x110c8b
movq -0x8(%rbp), %rax
cmpl $0x0, 0x48(%rax)
jne 0x110c8b
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0xb2e0b(%rip), %rsi     # 0x1c3a8f
movb $0x0, %al
callq 0x15bfb0
cmpq $0x0, -0x58(%rbp)
je 0x110cac
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x15b820
cmpl $0x0, -0x60(%rbp)
je 0x110cbf
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x172850
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x15b5a0
movl -0x5c(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)