// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/amiga-dsk.c
// Function: do_directory
static void do_directory(deark *c, lctx *d, struct member_data *md)
{
	i64 pos1;
	i64 ht_size_in_longs;
	int saved_indent_level;
	int need_curpath_pop = 0;
	de_ucstring *fullfn = NULL;
	struct de_timestamp tmpts;

	de_dbg_indent_save(c, &saved_indent_level);

	md->is_dir = 1;
	pos1 = md->header_pos;
	de_dbg(c, "directory header block: #%"I64_FMT" (%"I64_FMT")", md->header_blknum, pos1);
	de_dbg_indent(c, 1);
	if(md->sec_type!=ADF_ST_ROOT && md->sec_type!=ADF_ST_USERDIR) {
		goto done;
	}

	if(md->sec_type==ADF_ST_ROOT) {
		ht_size_in_longs = de_getu32be(pos1+12);
		de_dbg(c, "hashtable size: %"I64_FMT" longwords", ht_size_in_longs);
		if(ht_size_in_longs>128) {
			on_adf_error(c, d, 20);
			goto done;
		}
	}
	else {
		ht_size_in_longs = (d->bsize/4) - 56;
	}

	read_protection_flags(c, d, md, pos1+d->bsize-192);

	read_ofs_timestamp(c, pos1+d->bsize-92, &md->mod_time, "dir mod time");

	if(md->sec_type==ADF_ST_USERDIR) {
		i64 fnlen;

		fnlen = (i64)de_getbyte(pos1+d->bsize-80);
		if(fnlen>30) fnlen=30;
		md->fn = ucstring_create(c);
		dbuf_read_to_ucstring(c->infile, pos1+d->bsize-79, fnlen, md->fn, 0, DE_ENCODING_LATIN1);
		de_dbg(c, "dirname: \"%s\"", ucstring_getpsz_d(md->fn));
		de_strarray_push(d->curpath, md->fn);
		need_curpath_pop = 1;
	}

	if(md->sec_type==ADF_ST_ROOT) {
		read_ofs_timestamp(c, pos1+d->bsize-40, &tmpts, "disk mod time");
		read_ofs_timestamp(c, pos1+d->bsize-28, &tmpts, "filesystem create time");
	}

	// "extract"
	md->fi->is_directory = 1;
	if(md->sec_type==ADF_ST_ROOT) {
		md->fi->is_root_dir = 1;
	}
	if(md->sec_type==ADF_ST_USERDIR) {
		if(md->fn) {
			md->fi->original_filename_flag = 1;
			fullfn = ucstring_create(c);
			de_strarray_make_path(d->curpath, fullfn, DE_MPFLAG_NOTRAILINGSLASH);
			de_finfo_set_name_from_ucstring(c, md->fi, fullfn, DE_SNFLAG_FULLPATH);
		}
	}

	if(md->mod_time.is_valid) {
		md->fi->timestamp[DE_TIMESTAMPIDX_MODIFY] = md->mod_time;
	}

	md->outf = dbuf_create_output_file(c, NULL, md->fi, 0x0);
	dbuf_close(md->outf);
	md->outf = NULL;

	// Now recurse into the files and subdirs in this directory.
	do_hashtable(c, d, pos1+24, ht_size_in_longs);

done:
	if(need_curpath_pop) {
		de_strarray_pop(d->curpath);
	}
	ucstring_destroy(fullfn);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x15b580
movq -0x18(%rbp), %rax
movb $0x1, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
movq -0x20(%rbp), %rcx
leaq 0x16cff1(%rip), %rsi    # 0x1a0c3b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x18(%rbp), %rax
cmpl $0x1, 0x30(%rax)
je 0x33c78
movq -0x18(%rbp), %rax
cmpl $0x2, 0x30(%rax)
je 0x33c78
jmp 0x33f55
movq -0x18(%rbp), %rax
cmpl $0x1, 0x30(%rax)
jne 0x33cd4
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0xc, %rsi
callq 0x165470
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x16cfb4(%rip), %rsi    # 0x1a0c5e
movb $0x0, %al
callq 0x15b0d0
cmpq $0x80, -0x28(%rbp)
jle 0x33cd2
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x14, %edx
callq 0x34440
jmp 0x33f55
jmp 0x33cee
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl $0x4, %ecx
cqto
idivq %rcx
subq $0x38, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rcx
subq $0xc0, %rcx
callq 0x34470
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rsi
subq $0x5c, %rsi
movq -0x18(%rbp), %rdx
addq $0x40, %rdx
leaq 0x16cf47(%rip), %rcx    # 0x1a0c7c
callq 0x34510
movq -0x18(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jne 0x33e07
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rsi
subq $0x50, %rsi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x50(%rbp)
cmpq $0x1e, -0x50(%rbp)
jle 0x33d7b
movq $0x1e, -0x50(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rsi
subq $0x4f, %rsi
movq -0x50(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rcx
xorl %r8d, %r8d
movl $0x5, %r9d
callq 0x1669f0
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x172650
movq -0x58(%rbp), %rdi
movq %rax, %rdx
leaq 0x16cea5(%rip), %rsi    # 0x1a0c89
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x1728d0
movl $0x1, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x30(%rax)
jne 0x33e59
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rsi
subq $0x28, %rsi
leaq -0x48(%rbp), %rdx
leaq 0x16ce67(%rip), %rcx    # 0x1a0c97
callq 0x34510
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rsi
subq $0x1c, %rsi
leaq -0x48(%rbp), %rdx
leaq 0x16ce51(%rip), %rcx    # 0x1a0ca5
callq 0x34510
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rax
movb $0x1, 0x9(%rax)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x30(%rax)
jne 0x33e7b
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rax
movb $0x1, 0xb(%rax)
movq -0x18(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jne 0x33edb
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x33ed9
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rax
movb $0x1, 0x8(%rax)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x38(%rbp), %rsi
movl $0x1, %edx
callq 0x1729c0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rsi
movq -0x38(%rbp), %rdx
movl $0x1, %ecx
callq 0x15d2c0
jmp 0x33edb
movq -0x18(%rbp), %rax
cmpb $0x0, 0x40(%rax)
je 0x33f01
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x40(%rcx), %rdx
movq %rdx, 0x18(%rax)
movq 0x48(%rcx), %rcx
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rdx
xorl %eax, %eax
movl %eax, %esi
xorl %ecx, %ecx
callq 0x166c60
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x1676a0
movq -0x18(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
addq $0x18, %rdx
movq -0x28(%rbp), %rcx
callq 0x34660
cmpl $0x0, -0x30(%rbp)
je 0x33f68
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x172850
movq -0x38(%rbp), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x15b5a0
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)