// File: /workspace/github_c_makefile_star2_O2/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, 0x10(%rsp)
callq 0x3160
movq %rax, %r12
leaq 0xb7f5(%rip), %r14      # 0x1448f
leaq 0x1140(%rsp), %r13
leaq 0xb0(%rsp), %rbp
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x3390
testq %rax, %rax
je 0x8d12
movq %rax, %rbx
addq $0x13, %rbx
movq %r13, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3530
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3320
testl %eax, %eax
jne 0x8d12
movl 0xc8(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x8cad
movq %rbx, %rdi
callq 0x3570
movl %r15d, %ecx
incq %r15
movq %rax, 0x2140(%rsp,%rcx,8)
jmp 0x8cad
movq (%rsp), %rbx
movq 0x1008(%rbx), %rdi
callq 0xb25d
leaq 0x2140(%rsp), %r14
pushq $-0x1
popq %rcx
movq %r14, %rdi
movl %r15d, %esi
movq %rax, %rdx
callq 0xa9cc
movq 0x1008(%rbx), %rdi
callq 0xad85
leaq 0x140(%rsp), %rbp
leaq 0x20(%rsp), %r13
subq $0x1, %r15
jb 0x8e96
movq 0x1008(%rbx), %r12
movq %r14, 0x8(%rsp)
movq (%r14), %r14
movq %rbp, %rdi
leaq 0xb718(%rip), %rsi      # 0x1448f
movq 0x10(%rsp), %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x3530
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3320
testl %eax, %eax
je 0x8db0
movl (%rbx), %edx
pushq $-0x6
popq %rdi
leaq 0xb88f(%rip), %rsi      # 0x14630
movq %rbp, %rcx
xorl %eax, %eax
callq 0x982c
jmp 0x8e84
movq %r12, 0x18(%rsp)
movq %rbp, %rdi
leaq 0xd263(%rip), %rsi      # 0x16022
callq 0x34b0
testq %rax, %rax
je 0x8e3c
movq %rax, %rbp
movq 0x50(%rsp), %rbx
movl %ebx, %r13d
movq %r13, %rdi
callq 0x33b0
movq %rax, %r12
movq %rax, %rdi
pushq $0x1
popq %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x3100
movq %rax, %r13
movq %rbp, %rdi
callq 0x3150
cmpl %ebx, %r13d
jne 0x8e54
movq 0x78(%rsp), %rdx
movl 0x38(%rsp), %ecx
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movq %r12, %r8
movl %ebx, %r9d
callq 0xadee
movq %r12, %rdi
callq 0x3050
movq (%rsp), %rbx
leaq 0x140(%rsp), %rbp
leaq 0x20(%rsp), %r13
movq 0x8(%rsp), %r14
jmp 0x8e8d
movl (%rbx), %edx
pushq $-0x6
popq %rdi
leaq 0xb80d(%rip), %rsi      # 0x14655
movq %rbp, %rcx
xorl %eax, %eax
callq 0x982c
jmp 0x8e7f
movq (%rsp), %rax
movl (%rax), %edx
pushq $-0x6
popq %rdi
leaq 0xb80c(%rip), %rsi      # 0x14670
movl %r13d, %ecx
movl %ebx, %r8d
movq %rax, %rbx
leaq 0x140(%rsp), %rbp
movq %rbp, %r9
xorl %eax, %eax
callq 0x982c
leaq 0x20(%rsp), %r13
testl %eax, %eax
movq 0x8(%rsp), %r14
jne 0x8e9a
addq $0x8, %r14
jmp 0x8d54
xorl %eax, %eax
jmp 0x8eb3
leaq 0x15397(%rip), %rax     # 0x1e238
movl (%rax), %edi
movl (%rbx), %edx
leaq 0xb65f(%rip), %rsi      # 0x1450b
xorl %eax, %eax
callq 0x982c
addq $0x159c8, %rsp          # imm = 0x159C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq