// File: /workspace/github_c_makefile_star2_O1/j-hoppe[P]tu58fs/hostdir.c
// Function: snapshot_scan_hostdir
static int snapshot_scan_hostdir(hostdir_t *_this) {
	int i;
	struct stat sb;
	DIR *dfd;
	struct dirent *dp;
	char pathbuff[4096];
	char file_to_delete[4096];
	hostdir_file_t *f;

	// set all files "deleted", found files are overwritten with other state
	// only deleted files remain "deleted"
	for (i = 0; i < _this->snapshot.file_count; i++)
		_this->snapshot.file[i].state[side_host] = fs_missing;

	dfd = opendir(_this->path); // error checking done, compact code
	// make list of regular files
	file_to_delete[0] = 0;
	while ((dp = readdir(dfd))) {
		sprintf(pathbuff, "%s/%s", _this->path, dp->d_name);
		// beware of . and .., not regular file
		if (stat(pathbuff, &sb))
			break;
		if (S_ISREG(sb.st_mode)) {
			// file create on both sides handled
			char *pdp_filename_ext;
			// convert to PDP conventions. Then perhaps not unique!
			pdp_filename_ext = filesystem_filename_from_host(_this->pdp_fs, dp->d_name, NULL,
			NULL);
			// Find entries with same pdp filename, but different host fname.
			// These are the cases were truncing the hostname leads double PDP name
			// Delete those hostfiles.
			f = snapshot_file_register(&_this->snapshot, pdp_filename_ext, side_host);
			if (strlen(f->hostfilename) && strcasecmp(f->hostfilename, dp->d_name)
					&& file_exists(_this->path, f->hostfilename)) {
				// duplicate PDP file with different hostnames
				fprintf(ferr,
						"Host file \"%s\" maps to duplicate PDP filename \"%s\", will be deleted\n",
						dp->d_name, pdp_filename_ext);
				strcpy(file_to_delete, pathbuff);
			} else {
				strcpy(f->hostfilename, dp->d_name);
				if (f->state[side_host] != fs_created) {
					if (f->host_len != sb.st_size || f->host_mtime != STAT_ST_MTIM(sb).tv_sec)
						f->state[side_host] = fs_changed;
					else
						f->state[side_host] = fs_unchanged;
				}
				// update to newest state
				f->host_len = sb.st_size;
				f->host_mtime = STAT_ST_MTIM(sb).tv_sec;
			}
		}
	}
	closedir(dfd);
	// delete only one hostfile per round ... in fact a whole file list should be maintained
	if (strlen(file_to_delete))
		unlink(file_to_delete);
	return ERROR_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20a8, %rsp           # imm = 0x20A8
movq %rdi, %rbx
movslq 0x1018(%rdi), %rax
testq %rax, %rax
jle 0x9a27
imulq $0x150, %rax, %rax      # imm = 0x150
xorl %ecx, %ecx
movl $0x1, 0x114c(%rbx,%rcx)
addq $0x150, %rcx            # imm = 0x150
cmpq %rcx, %rax
jne 0x9a10
leaq 0x4(%rbx), %rdi
movq %rdi, (%rsp)
callq 0x3170
movq %rax, %r15
movb $0x0, 0xa0(%rsp)
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0x9bd7
movq %rax, %r12
leaq 0x1010(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0xb9e1(%rip), %r14      # 0x15447
leaq 0x10a0(%rsp), %r13
leaq 0x10(%rsp), %rbp
addq $0x13, %r12
movq %r13, %rdi
movq %r14, %rsi
movq (%rsp), %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x3540
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3330
testl %eax, %eax
jne 0x9bd7
movl 0x28(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x9bc3
movq %r15, %r14
movq 0x1008(%rbx), %rdi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xbcb1
movq %rax, %rbp
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movl $0x1, %edx
callq 0x8c07
movq %rax, %r13
leaq 0x28(%rax), %r15
cmpb $0x0, 0x28(%rax)
je 0x9b52
movq %r15, %rdi
movq %r12, %rsi
callq 0x3060
testl %eax, %eax
je 0x9b52
movq (%rsp), %rdi
movq %r15, %rsi
callq 0xab2c
testl %eax, %eax
je 0x9b52
leaq 0x1472e(%rip), %rax     # 0x1e240
movq (%rax), %rdi
leaq 0xbb3e(%rip), %rsi      # 0x1565a
movq %r12, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x3320
leaq 0xa0(%rsp), %rdi
leaq 0x10a0(%rsp), %r13
movq %r13, %rsi
callq 0x30d0
movq %r14, %r15
leaq 0xb8fc(%rip), %r14      # 0x15447
leaq 0x10(%rsp), %rbp
jmp 0x9bc3
movq %r15, %rdi
movq %r12, %rsi
callq 0x30d0
cmpl $0x3, 0x12c(%r13)
movq %r14, %r15
leaq 0xb8d8(%rip), %r14      # 0x15447
leaq 0x10(%rsp), %rbp
je 0x9ba3
movq 0x130(%r13), %rcx
movl $0x2, %eax
cmpq 0x40(%rsp), %rcx
jne 0x9b9c
movq 0x138(%r13), %rcx
xorl %eax, %eax
cmpq 0x68(%rsp), %rcx
setne %al
addl %eax, %eax
movl %eax, 0x12c(%r13)
movq 0x40(%rsp), %rax
movq %rax, 0x130(%r13)
movq 0x68(%rsp), %rax
movq %rax, 0x138(%r13)
leaq 0x10a0(%rsp), %r13
movq %r15, %rdi
callq 0x33a0
movq %rax, %r12
testq %rax, %rax
jne 0x9a73
movq %r15, %rdi
callq 0x3280
cmpb $0x0, 0xa0(%rsp)
je 0x9bf6
leaq 0xa0(%rsp), %rdi
callq 0x3090
addq $0x20a8, %rsp           # imm = 0x20A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq