// File: /workspace/github_c_makefile_star2_O0/excess-c64[P]lib1541img/src/lib/1541img/cbmdosfs.c
// Function: vfsChanged
static void vfsChanged(void *receiver, int id, const void *sender,
	const void *args)
{
    (void)id;
    (void)sender;

    CbmdosFs *self = receiver;
    if (self->status & CFS_BROKEN) return;
    const CbmdosVfsEventArgs *ea = args;
    switch (ea->what)
    {
	DirEntry tmpEntry;

	case CVE_DOSVERCHANGED:
	case CVE_NAMECHANGED:
	case CVE_IDCHANGED:
	    updateBam(self);
	    break;

	case CVE_FILEADDED:
	    if (ea->filepos > self->dir.size)
	    {
		logmsg(L_ERROR, "CbmdosFs: inconsistent state, file added at "
			"invalid position.");
		self->status |= CFS_BROKEN;
		break;
	    }
	    if (self->dir.size == self->dir.capa)
	    {
		self->dir.capa += DIRCHUNK;
		self->dir.entries = xrealloc(self->dir.entries,
			self->dir.capa * sizeof *self->dir.entries);
	    }
	    if (ea->filepos < self->dir.size)
	    {
		memmove(self->dir.entries + ea->filepos + 1,
			self->dir.entries + ea->filepos,
			(self->dir.size - ea->filepos)
			* sizeof *self->dir.entries);
	    }
	    ++self->dir.size;
            memset(self->dir.entries + ea->filepos, 0,
                    sizeof *self->dir.entries);
	    if (updateDir(self) < 0)
	    {
		self->status |= CFS_DIRFULL;
		updateBam(self);
		break;
	    }
	    if (updateFile(self, ea->filepos) < 0)
	    {
		self->status |= CFS_DISKFULL;
	    }
	    updateDir(self);
	    updateBam(self);
	    break;

	case CVE_FILEDELETED:
	    if (ea->filepos >= self->dir.size)
	    {
		logmsg(L_ERROR, "CbmdosFs: inconsistent state, non-existent "
			"file removed.");
		self->status |= CFS_BROKEN;
		break;
	    }
	    scratchFile(self, ea->filepos);
	    --self->dir.size;
	    if (ea->filepos < self->dir.size)
	    {
		memmove(self->dir.entries + ea->filepos,
			self->dir.entries + ea->filepos + 1,
			(self->dir.size - ea->filepos)
			* sizeof *self->dir.entries);
	    }
	    if (self->status & CFS_DISKFULL)
	    {
		self->status &= ~CFS_DISKFULL;
		for (unsigned pos = 0; pos < self->dir.size; ++pos)
		{
		    if (updateFile(self, pos) < 0)
		    {
			self->status |= CFS_DISKFULL;
		    }
		}
	    }
	    updateDir(self);
	    updateBam(self);
	    break;

	case CVE_FILEMOVED:
	    if (ea->filepos >= self->dir.size
		    || ea->targetpos >= self->dir.size)
	    {
		logmsg(L_ERROR, "CbmdosFs: inconsistent state, file moved to "
			"or from invalid position.");
		self->status |= CFS_BROKEN;
		break;
	    }
	    memcpy(&tmpEntry, self->dir.entries + ea->filepos,
		    sizeof tmpEntry);
	    if (ea->targetpos > ea->filepos)
	    {
		memmove(self->dir.entries + ea->filepos,
			self->dir.entries + ea->filepos + 1,
			(ea->targetpos - ea->filepos)
			* sizeof *self->dir.entries);
	    }
	    else
	    {
		memmove(self->dir.entries + ea->targetpos + 1,
			self->dir.entries + ea->targetpos,
			(ea->filepos - ea->targetpos)
			* sizeof *self->dir.entries);
	    }
	    memcpy(self->dir.entries + ea->targetpos, &tmpEntry,
		    sizeof *self->dir.entries);
	    updateDir(self);
	    updateBam(self);
	    break;

	case CVE_FILECHANGED:
	    if (ea->fileEventArgs->what == CFE_DATACHANGED
                    || ea->fileEventArgs->what == CFE_TYPECHANGED
                    || ea->fileEventArgs->what == CFE_RECORDLENGTHCHANGED
		    || ea->fileEventArgs->what == CFE_FORCEDBLOCKSCHANGED
		    || ea->fileEventArgs->what == CFE_OPTOVERRIDESCHANGED)
	    {
		if (updateFile(self, ea->filepos) < 0)
		{
		    self->status |= CFS_DISKFULL;
		}
		if (self->status & CFS_DISKFULL)
		{
		    self->status &= ~CFS_DISKFULL;
		    for (unsigned pos = 0; pos < self->dir.size; ++pos)
		    {
			if (updateFile(self, pos) < 0)
			{
			    self->status |= CFS_DISKFULL;
			}
		    }
		}
	    }
	    updateDir(self);
	    updateBam(self);
	    break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xd463
jmp 0xd938
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x48(%rbp)
subq $0x6, %rax
ja 0xd938
movq -0x48(%rbp), %rax
leaq 0x6c4e(%rip), %rcx      # 0x140d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x28(%rbp), %rdi
callq 0xd1e0
jmp 0xd938
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jbe 0xd4d4
movl $0x1, %edi
leaq 0x6f83(%rip), %rsi      # 0x14440
callq 0x5a60
movq -0x28(%rbp), %rax
movl 0x20(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0x20(%rax)
jmp 0xd938
movq -0x28(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0xd517
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %ecx
addl $0x90, %ecx
movl %ecx, 0x1c(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %eax
imulq $0x6, %rax, %rsi
callq 0x5910
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0xd570
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
imulq $0x6, %rax, %rax
addq %rax, %rdi
addq $0x6, %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
imulq $0x6, %rax, %rax
addq %rax, %rsi
movq -0x28(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x30(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
imulq $0x6, %rax, %rdx
callq 0x5670
movq -0x28(%rbp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
imulq $0x6, %rax, %rax
addq %rax, %rdi
xorl %esi, %esi
movl $0x6, %edx
callq 0x5340
movq -0x28(%rbp), %rdi
callq 0xce10
cmpl $0x0, %eax
jge 0xd5c8
movq -0x28(%rbp), %rax
movl 0x20(%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0x20(%rax)
movq -0x28(%rbp), %rdi
callq 0xd1e0
jmp 0xd938
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %esi
callq 0xe030
cmpl $0x0, %eax
jge 0xd5ea
movq -0x28(%rbp), %rax
movl 0x20(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x20(%rax)
movq -0x28(%rbp), %rdi
callq 0xce10
movq -0x28(%rbp), %rdi
callq 0xd1e0
jmp 0xd938
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jb 0xd634
movl $0x1, %edi
leaq 0x6e61(%rip), %rsi      # 0x1447e
callq 0x5a60
movq -0x28(%rbp), %rax
movl 0x20(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0x20(%rax)
jmp 0xd938
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %esi
callq 0xf0a0
movq -0x28(%rbp), %rax
movl 0x18(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x18(%rax)
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0xd6aa
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
imulq $0x6, %rax, %rax
addq %rax, %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
imulq $0x6, %rax, %rax
addq %rax, %rsi
addq $0x6, %rsi
movq -0x28(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x30(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
imulq $0x6, %rax, %rdx
callq 0x5670
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xd706
movq -0x28(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x20(%rax)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0xd704
movq -0x28(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0xe030
cmpl $0x0, %eax
jge 0xd6f7
movq -0x28(%rbp), %rax
movl 0x20(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x20(%rax)
jmp 0xd6f9
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xd6cd
jmp 0xd706
movq -0x28(%rbp), %rdi
callq 0xce10
movq -0x28(%rbp), %rdi
callq 0xd1e0
jmp 0xd938
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0xd73d
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jb 0xd760
movl $0x1, %edi
leaq 0x6d6e(%rip), %rsi      # 0x144b7
callq 0x5a60
movq -0x28(%rbp), %rax
movl 0x20(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0x20(%rax)
jmp 0xd938
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %ecx
movl %ecx, -0x36(%rbp)
movw 0x4(%rax), %ax
movw %ax, -0x32(%rbp)
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jbe 0xd7de
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
imulq $0x6, %rax, %rax
addq %rax, %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
imulq $0x6, %rax, %rax
addq %rax, %rsi
addq $0x6, %rsi
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x30(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
imulq $0x6, %rax, %rdx
callq 0x5670
jmp 0xd827
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
imulq $0x6, %rax, %rax
addq %rax, %rdi
addq $0x6, %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
imulq $0x6, %rax, %rax
addq %rax, %rsi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x30(%rbp), %rcx
subl 0x14(%rcx), %eax
movl %eax, %eax
imulq $0x6, %rax, %rdx
callq 0x5670
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movl 0x14(%rcx), %ecx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movl -0x36(%rbp), %ecx
movl %ecx, (%rax)
movw -0x32(%rbp), %cx
movw %cx, 0x4(%rax)
movq -0x28(%rbp), %rdi
callq 0xce10
movq -0x28(%rbp), %rdi
callq 0xd1e0
jmp 0xd938
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x2, (%rax)
je 0xd8a6
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x0, (%rax)
je 0xd8a6
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x6, (%rax)
je 0xd8a6
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x5, (%rax)
je 0xd8a6
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x7, (%rax)
jne 0xd926
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %esi
callq 0xe030
cmpl $0x0, %eax
jge 0xd8c8
movq -0x28(%rbp), %rax
movl 0x20(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x20(%rax)
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xd924
movq -0x28(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x20(%rax)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0xd922
movq -0x28(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0xe030
cmpl $0x0, %eax
jge 0xd915
movq -0x28(%rbp), %rax
movl 0x20(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x20(%rax)
jmp 0xd917
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xd8eb
jmp 0xd924
jmp 0xd926
movq -0x28(%rbp), %rdi
callq 0xce10
movq -0x28(%rbp), %rdi
callq 0xd1e0
addq $0x50, %rsp
popq %rbp
retq
nop