// File: /workspace/github_c_makefile_star2_O1/j-hoppe[P]tu58fs/hostdir.c
// Function: hostdir_to_pdp_fs
int hostdir_to_pdp_fs(hostdir_t *_this) {
	char pathbuff[4096];
	char *names[10000];
	int filecount;
	// load filenames
	// delete content
	struct stat sb;
	DIR *dfd;
	struct dirent *dp;
	int i;

	dfd = opendir(_this->path); // error checking done, compact code
	filecount = 0;
	// make list of regular files
	while ((dp = readdir(dfd))) {
		sprintf(pathbuff, "%s/%s", _this->path, dp->d_name);
		// beware of . and ..
		if (stat(pathbuff, &sb))
			break;
		if (S_ISREG(sb.st_mode)) {
			names[filecount++] = strdup(dp->d_name);
		}
	}

	// sort names[] according to filesystem order
	filename_sort(names, filecount, filesystem_fileorder(_this->pdp_fs), -1);

	// add all files
	filesystem_init(_this->pdp_fs);
	for (i = 0; i < filecount; i++) {
		if (pdp_fs_file_add(_this, _this->pdp_fs, _this->path, names[i]))
			return error_set(error_code, "Unit %d: Host dir to PDP filesystem", _this->unit);
	}

	return ERROR_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x159c8, %rsp          # imm = 0x159C8
movq %rdi, (%rsp)
leaq 0x4(%rdi), %r14
movq %r14, %rdi
callq 0x3170
movq %rax, %r12
movq %rax, %rdi
callq 0x33a0
movl $0x0, %r15d
testq %rax, %rax
je 0x927f
movq %rax, %r13
leaq 0x1140(%rsp), %rbp
movl $0xf000, %ebx           # imm = 0xF000
xorl %r15d, %r15d
addq $0x13, %r13
movq %rbp, %rdi
leaq 0xc21f(%rip), %rsi      # 0x15447
movq %r14, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x3540
movq %rbp, %rdi
leaq 0xb0(%rsp), %rsi
callq 0x3330
testl %eax, %eax
jne 0x927f
movl 0xc8(%rsp), %eax
andl %ebx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x926f
movq %r13, %rdi
callq 0x3580
movslq %r15d, %rcx
incl %r15d
movq %rax, 0x2140(%rsp,%rcx,8)
movq %r12, %rdi
callq 0x33a0
movq %rax, %r13
testq %rax, %rax
jne 0x921a
movq (%rsp), %r12
movq 0x1008(%r12), %rdi
callq 0xbcdc
leaq 0x2140(%rsp), %rdi
movl %r15d, %esi
movq %rax, %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0xb3e0
movq 0x1008(%r12), %rdi
callq 0xb7eb
testl %r15d, %r15d
movl $0x0, %eax
jle 0x9445
movq %r14, 0x18(%rsp)
movl %r15d, %eax
movq %rax, 0x10(%rsp)
leaq 0xc170(%rip), %rbx      # 0x15447
leaq 0x140(%rsp), %rbp
xorl %r14d, %r14d
movq 0x1008(%r12), %r13
movq 0x2140(%rsp,%r14,8), %r15
movq %rbp, %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x3540
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x3330
testl %eax, %eax
je 0x9337
movl (%r12), %edx
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
leaq 0xc2c3(%rip), %rsi      # 0x155eb
movq %rbp, %rcx
xorl %eax, %eax
callq 0x9f8f
jmp 0x9414
movq %r13, 0x8(%rsp)
movq %rbp, %rdi
leaq 0xdc90(%rip), %rsi      # 0x16fd6
callq 0x34c0
testq %rax, %rax
je 0x93c4
movq %rax, %rbx
movq 0x50(%rsp), %r13
movl %r13d, %r12d
movq %r12, %rdi
callq 0x33c0
movl $0x1, %esi
movq %rax, %rbp
movq %rax, %rdi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x3110
movq %rax, %r12
movq %rbx, %rdi
callq 0x3160
cmpl %r13d, %r12d
jne 0x93e0
movq 0x78(%rsp), %rdx
movl 0x38(%rsp), %ecx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %rbp, %r8
movl %r13d, %r9d
callq 0xb85a
movq %rbp, %rdi
callq 0x3050
xorl %eax, %eax
movq (%rsp), %r12
leaq 0xc08d(%rip), %rbx      # 0x15447
leaq 0x140(%rsp), %rbp
jmp 0x9414
movl (%r12), %edx
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
leaq 0xc23c(%rip), %rsi      # 0x15610
movq %rbp, %rcx
xorl %eax, %eax
callq 0x9f8f
jmp 0x940d
movq (%rsp), %rax
movl (%rax), %edx
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
leaq 0xc239(%rip), %rsi      # 0x1562b
movl %r12d, %ecx
movq %rax, %r12
movl %r13d, %r8d
leaq 0x140(%rsp), %rbp
movq %rbp, %r9
xorl %eax, %eax
callq 0x9f8f
leaq 0xc033(%rip), %rbx      # 0x15447
testl %eax, %eax
jne 0x942a
incq %r14
cmpq %r14, 0x10(%rsp)
jne 0x92e2
xorl %eax, %eax
jmp 0x9445
leaq 0x14e17(%rip), %rax     # 0x1e248
movl (%rax), %edi
movl (%r12), %edx
leaq 0xc088(%rip), %rsi      # 0x154c6
xorl %eax, %eax
callq 0x9f8f
addq $0x159c8, %rsp          # imm = 0x159C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq