// File: /workspace/github_c_makefile_star2_O3/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)
addq $0x4, %rdi
movq %rdi, 0x8(%rsp)
callq 0x3160
movq %rax, %r12
movq %rax, %rdi
callq 0x3390
xorl %r14d, %r14d
movl $0x0, %r15d
testq %rax, %rax
je 0x917a
movq %rax, %r13
leaq 0x1140(%rsp), %rbp
movl $0xf000, %ebx           # imm = 0xF000
xorl %r15d, %r15d
addq $0x13, %r13
movq %rbp, %rdi
leaq 0xc396(%rip), %rsi      # 0x154b7
movq 0x8(%rsp), %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x3530
movq %rbp, %rdi
leaq 0xb0(%rsp), %rsi
callq 0x3320
testl %eax, %eax
jne 0x917a
movl 0xc8(%rsp), %eax
andl %ebx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x916a
movq %r13, %rdi
callq 0x3570
movslq %r15d, %rcx
incl %r15d
movq %rax, 0x2140(%rsp,%rcx,8)
movq %r12, %rdi
callq 0x3390
movq %rax, %r13
testq %rax, %rax
jne 0x9113
movq (%rsp), %r12
movq 0x1008(%r12), %rdi
callq 0xbc5e
leaq 0x2140(%rsp), %rdi
movl %r15d, %esi
movq %rax, %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0xb374
movq 0x1008(%r12), %rdi
callq 0xb773
testl %r15d, %r15d
jle 0x9338
movl %r15d, %eax
movq %rax, 0x18(%rsp)
leaq 0xc2ef(%rip), %rbx      # 0x154b7
leaq 0x140(%rsp), %rbp
xorl %r14d, %r14d
movq 0x1008(%r12), %r13
movq 0x2140(%rsp,%r14,8), %r15
movq %rbp, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x3530
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x3320
testl %eax, %eax
je 0x9228
movl (%r12), %edx
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
leaq 0xc43f(%rip), %rsi      # 0x15658
movq %rbp, %rcx
xorl %eax, %eax
callq 0x9f73
jmp 0x9303
movq %r13, 0x10(%rsp)
movq %rbp, %rdi
leaq 0xde37(%rip), %rsi      # 0x1706e
callq 0x34b0
testq %rax, %rax
je 0x92b3
movq %rax, %rbx
movq 0x50(%rsp), %r13
movl %r13d, %r12d
movq %r12, %rdi
callq 0x33b0
movl $0x1, %esi
movq %rax, %rbp
movq %rax, %rdi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x3100
movq %rax, %r12
movq %rbx, %rdi
callq 0x3150
cmpl %r13d, %r12d
jne 0x92cf
movq 0x78(%rsp), %rdx
movl 0x38(%rsp), %ecx
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %rbp, %r8
movl %r13d, %r9d
callq 0xb7e2
movq %rbp, %rdi
callq 0x3050
movq (%rsp), %r12
leaq 0xc20e(%rip), %rbx      # 0x154b7
leaq 0x140(%rsp), %rbp
jmp 0x9307
movl (%r12), %edx
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
leaq 0xc3ba(%rip), %rsi      # 0x1567d
movq %rbp, %rcx
xorl %eax, %eax
callq 0x9f73
jmp 0x92fc
movq (%rsp), %rax
movl (%rax), %edx
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
leaq 0xc3b7(%rip), %rsi      # 0x15698
movl %r12d, %ecx
movq %rax, %r12
movl %r13d, %r8d
leaq 0x140(%rsp), %rbp
movq %rbp, %r9
xorl %eax, %eax
callq 0x9f73
leaq 0xc1b4(%rip), %rbx      # 0x154b7
testl %eax, %eax
jne 0x931a
incq %r14
cmpq %r14, 0x18(%rsp)
jne 0x91d3
xorl %r14d, %r14d
jmp 0x9338
leaq 0x14f17(%rip), %rax     # 0x1e238
movl (%rax), %edi
movl (%r12), %edx
leaq 0xc205(%rip), %rsi      # 0x15533
xorl %eax, %eax
callq 0x9f73
movl %eax, %r14d
movl %r14d, %eax
addq $0x159c8, %rsp          # imm = 0x159C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq