// File: /workspace/github_c_makefile_star2_O0/j-hoppe[P]tu58fs/hostdir.c
// Function: hostdir_sync
int hostdir_sync(hostdir_t *_this) {
	// int any_file_change;
	int update_pdp;
	int update_snapshot;
	int i;
	// entry: snapshot contains files in shared dir,
	// as PDP filesystem and hostdir where synched

	// scan hostdir
	snapshot_scan_hostdir(_this);

	// scan PDP image
	snapshot_scan_pdpimage(_this);

	// print state
	if (opt_debug)
		snapshot_print(&_this->snapshot, ferr, 1);
	else if (opt_verbose)
		snapshot_print(&_this->snapshot, ferr, 0);

	update_pdp = 0;
	update_snapshot = 0;
	if (_this->pdp_fs->readonly) {
		// readonly: only sync hostdir from PDP file system
		int hostdir_changed = 0;
		for (i = 0; i < _this->snapshot.file_count; i++) {
			hostdir_file_t *f = &_this->snapshot.file[i];
			if (f->state[side_host] != fs_unchanged)
				hostdir_changed = 1;
		}
		if (hostdir_changed) {
			// short code: rebuild whole hostdir
			info("Unit %d: Device is readonly, reverting changes in shared dir \"%s\".", _this->unit, _this->path) ;
			hostdir_prepare(_this, /*wipe*/1, /*exists*/0, NULL);
			hostdir_from_pdp_fs(_this);
			update_snapshot = 1;
		}
	} else {
		// not readonly: update hostdir and PDP file system
		for (i = 0; i < _this->snapshot.file_count; i++) {
			hostdir_file_t *f = &_this->snapshot.file[i];
			// 16 cases. The cases when one side is unchanged are easy
			if (f->state[side_pdp] == fs_unchanged && f->state[side_host] == fs_unchanged) {
				// do nothing
			} else if (f->state[side_pdp] == fs_unchanged
					&& f->state[side_host] == fs_missing) {
				if (f->pdp_fixed)
					hostdir_file_copy_from_pdp(_this, f); // restore
				else
					update_pdp = 1; // update PDP from hostdir
			} else if (f->state[side_pdp] == fs_unchanged
					&& f->state[side_host] == fs_changed) {
				update_pdp = 1; // update PDP from hostdir
			} else if (f->state[side_pdp] == fs_unchanged
					&& f->state[side_host] == fs_created) {
				update_pdp = 1; // update PDP from hostdir

			} else if (f->state[side_pdp] == fs_missing
					&& f->state[side_host] == fs_unchanged) {
				hostdir_file_delete(_this, f);
				update_snapshot = 1;
			} else if (f->state[side_pdp] == fs_missing && f->state[side_host] == fs_missing) {
				// no need to update hostdir from pdp
				update_snapshot = 1; // but delete file from snapshot!
			} else if (f->state[side_pdp] == fs_missing && f->state[side_host] == fs_changed) {
				if (_this->pdp_priority)
					hostdir_file_delete(_this, f);
				else
					update_pdp = 1;
				update_snapshot = 1;
			} else if (f->state[side_pdp] == fs_missing && f->state[side_host] == fs_created) {
				// the file was created on host and is not yet on PDP
				update_pdp = 1; // force reload
			} else if (f->state[side_pdp] == fs_changed
					&& f->state[side_host] == fs_unchanged) {
				hostdir_file_copy_from_pdp(_this, f);
				update_snapshot = 1;
			} else if (f->state[side_pdp] == fs_changed && f->state[side_host] == fs_missing) {
				if (f->pdp_fixed || _this->pdp_priority)
					hostdir_file_copy_from_pdp(_this, f);
				else
					update_pdp = 1;
				update_snapshot = 1;
			} else if (f->state[side_pdp] == fs_changed && f->state[side_host] == fs_changed) {
				if (_this->pdp_priority)
					hostdir_file_copy_from_pdp(_this, f);
				else
					update_pdp = 1;
				update_snapshot = 1;
			} else if (f->state[side_pdp] == fs_changed && f->state[side_host] == fs_created) {
				if (_this->pdp_priority)
					hostdir_file_copy_from_pdp(_this, f);
				else
					update_pdp = 1;
				update_snapshot = 1;
			} else if (f->state[side_pdp] == fs_created
					&& f->state[side_host] == fs_unchanged) {
				hostdir_file_copy_from_pdp(_this, f);
				update_snapshot = 1;
			} else if (f->state[side_pdp] == fs_created && f->state[side_host] == fs_missing) {
				// new on PDP
				hostdir_file_copy_from_pdp(_this, f);
				update_snapshot = 1;
			} else if (f->state[side_pdp] == fs_created && f->state[side_host] == fs_changed) {
				if (_this->pdp_priority)
					hostdir_file_copy_from_pdp(_this, f);
				else
					update_pdp = 1;
				update_snapshot = 1;
			} else if (f->state[side_pdp] == fs_created && f->state[side_host] == fs_created) {
				if (_this->pdp_priority)
					hostdir_file_copy_from_pdp(_this, f);
				else
					update_pdp = 1;
				update_snapshot = 1;
			}
		}
	}
	if (update_pdp) {
		hostdir_file_t *f;
		// files in the host dir have changed:
		// reload the tu58 image
		hostdir_image_reload(_this);
		// send volum.inf (RT11)
		f = snapshot_file_find(&_this->snapshot, "$VOLUM.INF");
		if (f)
			hostdir_file_copy_from_pdp(_this, f);
		if (opt_verbose)
			info("Unit %d: Updated PDP image with shared dir \"%s\".", _this->unit, _this->path);
	}
	if (update_pdp || update_snapshot) {
		// if file was deleted
		snapshot_init(_this);
		if (opt_verbose)
			info("Unit %d: Scanned content of shared dir \"%s\".", _this->unit, _this->path);
	}

	return ERROR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0xc5b0
movq -0x8(%rbp), %rdi
callq 0xc860
leaq 0x17d7f(%rip), %rax     # 0x23d74
cmpl $0x0, (%rax)
je 0xc01b
movq -0x8(%rbp), %rdi
addq $0x1010, %rdi           # imm = 0x1010
leaq 0x19524(%rip), %rax     # 0x25530
movq (%rax), %rsi
movl $0x1, %edx
callq 0xca70
jmp 0xc045
leaq 0x17d42(%rip), %rax     # 0x23d64
cmpl $0x0, (%rax)
je 0xc043
movq -0x8(%rbp), %rdi
addq $0x1010, %rdi           # imm = 0x1010
leaq 0x194f7(%rip), %rax     # 0x25530
movq (%rax), %rsi
xorl %edx, %edx
callq 0xca70
jmp 0xc045
movl $0x0, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x1008(%rax), %rax
cmpl $0x0, 0x4(%rax)
je 0xc111
movl $0x0, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x1018(%rcx), %eax
jge 0xc0c6
movq -0x8(%rbp), %rax
addq $0x1010, %rax           # imm = 0x1010
addq $0x10, %rax
movslq -0x14(%rbp), %rcx
imulq $0x150, %rcx, %rcx      # imm = 0x150
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x12c(%rax)
je 0xc0b9
movl $0x1, -0x18(%rbp)
jmp 0xc0bb
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xc076
cmpl $0x0, -0x18(%rbp)
je 0xc10c
movq -0x8(%rbp), %rax
movl (%rax), %esi
movq -0x8(%rbp), %rdx
addq $0x4, %rdx
leaq 0x10397(%rip), %rdi     # 0x1c478
movb $0x0, %al
callq 0xcf60
movq -0x8(%rbp), %rdi
movl $0x1, %esi
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xb360
movq -0x8(%rbp), %rdi
callq 0xb800
movl $0x1, -0x10(%rbp)
jmp 0xc4fb
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x1018(%rcx), %eax
jge 0xc4f9
movq -0x8(%rbp), %rax
addq $0x1010, %rax           # imm = 0x1010
addq $0x10, %rax
movslq -0x14(%rbp), %rcx
imulq $0x150, %rcx, %rcx      # imm = 0x150
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x128(%rax)
jne 0xc16a
movq -0x28(%rbp), %rax
cmpl $0x0, 0x12c(%rax)
jne 0xc16a
jmp 0xc4e9
movq -0x28(%rbp), %rax
cmpl $0x0, 0x128(%rax)
jne 0xc1ac
movq -0x28(%rbp), %rax
cmpl $0x1, 0x12c(%rax)
jne 0xc1ac
movq -0x28(%rbp), %rax
cmpl $0x0, 0x148(%rax)
je 0xc1a0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xcb50
jmp 0xc1a7
movl $0x1, -0xc(%rbp)
jmp 0xc4e7
movq -0x28(%rbp), %rax
cmpl $0x0, 0x128(%rax)
jne 0xc1d2
movq -0x28(%rbp), %rax
cmpl $0x2, 0x12c(%rax)
jne 0xc1d2
movl $0x1, -0xc(%rbp)
jmp 0xc4e5
movq -0x28(%rbp), %rax
cmpl $0x0, 0x128(%rax)
jne 0xc1f8
movq -0x28(%rbp), %rax
cmpl $0x3, 0x12c(%rax)
jne 0xc1f8
movl $0x1, -0xc(%rbp)
jmp 0xc4e3
movq -0x28(%rbp), %rax
cmpl $0x1, 0x128(%rax)
jne 0xc22b
movq -0x28(%rbp), %rax
cmpl $0x0, 0x12c(%rax)
jne 0xc22b
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xcc30
movl $0x1, -0x10(%rbp)
jmp 0xc4e1
movq -0x28(%rbp), %rax
cmpl $0x1, 0x128(%rax)
jne 0xc251
movq -0x28(%rbp), %rax
cmpl $0x1, 0x12c(%rax)
jne 0xc251
movl $0x1, -0x10(%rbp)
jmp 0xc4df
movq -0x28(%rbp), %rax
cmpl $0x1, 0x128(%rax)
jne 0xc29a
movq -0x28(%rbp), %rax
cmpl $0x2, 0x12c(%rax)
jne 0xc29a
movq -0x8(%rbp), %rax
cmpl $0x0, 0x530a0(%rax)
je 0xc287
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xcc30
jmp 0xc28e
movl $0x1, -0xc(%rbp)
movl $0x1, -0x10(%rbp)
jmp 0xc4dd
movq -0x28(%rbp), %rax
cmpl $0x1, 0x128(%rax)
jne 0xc2c0
movq -0x28(%rbp), %rax
cmpl $0x3, 0x12c(%rax)
jne 0xc2c0
movl $0x1, -0xc(%rbp)
jmp 0xc4db
movq -0x28(%rbp), %rax
cmpl $0x2, 0x128(%rax)
jne 0xc2f3
movq -0x28(%rbp), %rax
cmpl $0x0, 0x12c(%rax)
jne 0xc2f3
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xcb50
movl $0x1, -0x10(%rbp)
jmp 0xc4d9
movq -0x28(%rbp), %rax
cmpl $0x2, 0x128(%rax)
jne 0xc349
movq -0x28(%rbp), %rax
cmpl $0x1, 0x12c(%rax)
jne 0xc349
movq -0x28(%rbp), %rax
cmpl $0x0, 0x148(%rax)
jne 0xc327
movq -0x8(%rbp), %rax
cmpl $0x0, 0x530a0(%rax)
je 0xc336
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xcb50
jmp 0xc33d
movl $0x1, -0xc(%rbp)
movl $0x1, -0x10(%rbp)
jmp 0xc4d7
movq -0x28(%rbp), %rax
cmpl $0x2, 0x128(%rax)
jne 0xc392
movq -0x28(%rbp), %rax
cmpl $0x2, 0x12c(%rax)
jne 0xc392
movq -0x8(%rbp), %rax
cmpl $0x0, 0x530a0(%rax)
je 0xc37f
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xcb50
jmp 0xc386
movl $0x1, -0xc(%rbp)
movl $0x1, -0x10(%rbp)
jmp 0xc4d5
movq -0x28(%rbp), %rax
cmpl $0x2, 0x128(%rax)
jne 0xc3db
movq -0x28(%rbp), %rax
cmpl $0x3, 0x12c(%rax)
jne 0xc3db
movq -0x8(%rbp), %rax
cmpl $0x0, 0x530a0(%rax)
je 0xc3c8
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xcb50
jmp 0xc3cf
movl $0x1, -0xc(%rbp)
movl $0x1, -0x10(%rbp)
jmp 0xc4d3
movq -0x28(%rbp), %rax
cmpl $0x3, 0x128(%rax)
jne 0xc40e
movq -0x28(%rbp), %rax
cmpl $0x0, 0x12c(%rax)
jne 0xc40e
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xcb50
movl $0x1, -0x10(%rbp)
jmp 0xc4d1
movq -0x28(%rbp), %rax
cmpl $0x3, 0x128(%rax)
jne 0xc441
movq -0x28(%rbp), %rax
cmpl $0x1, 0x12c(%rax)
jne 0xc441
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xcb50
movl $0x1, -0x10(%rbp)
jmp 0xc4cf
movq -0x28(%rbp), %rax
cmpl $0x3, 0x128(%rax)
jne 0xc487
movq -0x28(%rbp), %rax
cmpl $0x2, 0x12c(%rax)
jne 0xc487
movq -0x8(%rbp), %rax
cmpl $0x0, 0x530a0(%rax)
je 0xc477
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xcb50
jmp 0xc47e
movl $0x1, -0xc(%rbp)
movl $0x1, -0x10(%rbp)
jmp 0xc4cd
movq -0x28(%rbp), %rax
cmpl $0x3, 0x128(%rax)
jne 0xc4cb
movq -0x28(%rbp), %rax
cmpl $0x3, 0x12c(%rax)
jne 0xc4cb
movq -0x8(%rbp), %rax
cmpl $0x0, 0x530a0(%rax)
je 0xc4bd
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xcb50
jmp 0xc4c4
movl $0x1, -0xc(%rbp)
movl $0x1, -0x10(%rbp)
jmp 0xc4cd
jmp 0xc4cf
jmp 0xc4d1
jmp 0xc4d3
jmp 0xc4d5
jmp 0xc4d7
jmp 0xc4d9
jmp 0xc4db
jmp 0xc4dd
jmp 0xc4df
jmp 0xc4e1
jmp 0xc4e3
jmp 0xc4e5
jmp 0xc4e7
jmp 0xc4e9
jmp 0xc4eb
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xc118
jmp 0xc4fb
cmpl $0x0, -0xc(%rbp)
je 0xc563
movq -0x8(%rbp), %rdi
callq 0xbe60
movq -0x8(%rbp), %rdi
addq $0x1010, %rdi           # imm = 0x1010
leaq 0xfecd(%rip), %rsi      # 0x1c3e9
callq 0xb100
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xc539
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xcb50
leaq 0x17824(%rip), %rax     # 0x23d64
cmpl $0x0, (%rax)
je 0xc561
movq -0x8(%rbp), %rax
movl (%rax), %esi
movq -0x8(%rbp), %rdx
addq $0x4, %rdx
leaq 0xff61(%rip), %rdi      # 0x1c4bb
movb $0x0, %al
callq 0xcf60
jmp 0xc563
cmpl $0x0, -0xc(%rbp)
jne 0xc56f
cmpl $0x0, -0x10(%rbp)
je 0xc5a2
movq -0x8(%rbp), %rdi
callq 0xccb0
leaq 0x177e5(%rip), %rax     # 0x23d64
cmpl $0x0, (%rax)
je 0xc5a0
movq -0x8(%rbp), %rax
movl (%rax), %esi
movq -0x8(%rbp), %rdx
addq $0x4, %rdx
leaq 0xff53(%rip), %rdi      # 0x1c4ec
movb $0x0, %al
callq 0xcf60
jmp 0xc5a2
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)