// File: /workspace/github_c_makefile_star2_O3/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 0x9921
leal 0x3(%rax), %ecx
decq %rax
movq %rax, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %ecx
imulq $0x540, %rcx, %rax      # imm = 0x540
movdqa 0xbaf8(%rip), %xmm1     # 0x15330
movdqa 0xbb00(%rip), %xmm2     # 0x15340
xorl %ecx, %ecx
movdqa 0xbb06(%rip), %xmm3     # 0x15350
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0xbb06(%rip), %xmm5     # 0x15360
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %edx
notl %edx
testb $0x1, %dl
je 0x9899
movl $0x1, 0x114c(%rbx,%rcx)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %edx
testb $0x1, %dl
je 0x98b2
movl $0x1, 0x129c(%rbx,%rcx)
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %edx
testb $0x1, %dl
je 0x98f4
movl $0x1, 0x13ec(%rbx,%rcx)
pextrw $0x4, %xmm6, %edx
testb $0x1, %dl
je 0x9909
movl $0x1, 0x153c(%rbx,%rcx)
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x540, %rcx            # imm = 0x540
cmpq %rcx, %rax
jne 0x985a
leaq 0x4(%rbx), %rdi
movq %rdi, (%rsp)
callq 0x3160
movq %rax, %r15
movb $0x0, 0xa0(%rsp)
movq %rax, %rdi
callq 0x3390
testq %rax, %rax
je 0x9acc
movq %rax, %r12
leaq 0x1010(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0xbb57(%rip), %r14      # 0x154b7
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 0x3530
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3320
testl %eax, %eax
jne 0x9acc
movl 0x28(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x9ab8
movq %r15, %r14
movq 0x1008(%rbx), %rdi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xbc33
movq %rax, %rbp
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movl $0x1, %edx
callq 0x8b3b
movq %rax, %r13
leaq 0x28(%rax), %r15
cmpb $0x0, 0x28(%rax)
je 0x9a4c
movq %r15, %rdi
movq %r12, %rsi
callq 0x3060
testl %eax, %eax
je 0x9a4c
movq (%rsp), %rdi
movq %r15, %rsi
callq 0xaabf
testl %eax, %eax
je 0x9a4c
leaq 0x14824(%rip), %rax     # 0x1e230
movq (%rax), %rdi
leaq 0xbcb1(%rip), %rsi      # 0x156c7
movq %r12, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x3310
leaq 0xa0(%rsp), %rdi
leaq 0x10a0(%rsp), %r13
movq %r13, %rsi
callq 0x30c0
movq %r14, %r15
leaq 0xba72(%rip), %r14      # 0x154b7
leaq 0x10(%rsp), %rbp
jmp 0x9ab8
movq %r15, %rdi
movq %r12, %rsi
callq 0x30c0
cmpl $0x3, 0x12c(%r13)
movq 0x40(%rsp), %rax
movq %r14, %r15
leaq 0xba49(%rip), %r14      # 0x154b7
leaq 0x10(%rsp), %rbp
je 0x9a9d
movl $0x2, %ecx
cmpq %rax, 0x130(%r13)
jne 0x9a96
movq 0x138(%r13), %rdx
xorl %ecx, %ecx
cmpq 0x68(%rsp), %rdx
setne %cl
addl %ecx, %ecx
movl %ecx, 0x12c(%r13)
movq %rax, 0x130(%r13)
movq 0x68(%rsp), %rax
movq %rax, 0x138(%r13)
leaq 0x10a0(%rsp), %r13
movq %r15, %rdi
callq 0x3390
movq %rax, %r12
testq %rax, %rax
jne 0x996d
movq %r15, %rdi
callq 0x3270
cmpb $0x0, 0xa0(%rsp)
je 0x9aeb
leaq 0xa0(%rsp), %rdi
callq 0x3090
addq $0x20a8, %rsp           # imm = 0x20A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq