// File: /workspace/github_c_makefile_star2_O0/excess-c64[P]lib1541img/src/lib/1541img/cbmdosfs.c
// Function: CbmdosFs_fromImage
SOEXPORT CbmdosFs *CbmdosFs_fromImage(D64 *d64, CbmdosFsOptions options)
{
    if (validateOptions(options) < 0) return 0;
    switch (D64_type(d64))
    {
	case D64_STANDARD:
	    if (options.flags & (CFF_40TRACK | CFF_42TRACK))
	    {
		logmsg(L_ERROR, "CbmdosFs_fromImage: trying to read a 40- or "
			"42-tracks filesystem from an image that only has "
			"35 tracks.");
		return 0;
	    }
	    break;
	case D64_40TRACK:
	    if (options.flags & CFF_42TRACK)
	    {
		logmsg(L_ERROR, "CbmdosFs_fromImage: trying to read a "
			"42-tracks filesystem from an image that only has "
			"40 tracks.");
		return 0;
	    }
	    if (!(options.flags & CFF_40TRACK))
	    {
		logmsg(L_WARNING, "CbmdosFs_fromImage: trying to read a "
			"35-tracks filesystem from an image that has 40 "
			"tracks, this will fail if the filesystem spans "
			"all 40 tracks.");
	    }
	    break;
	case D64_42TRACK:
	    if (!(options.flags & CFF_42TRACK))
	    {
		logmsg(L_WARNING, "CbmdosFs_fromImage: trying to read a 35- "
			"or 40-tracks filesystem from an image that has 42 "
			"tracks, this will fail if the filesystem spans "
			"all 42 tracks.");
	    }
	    break;
    }

    CbmdosFs *self = xmalloc(sizeof *self);
    memset(self, 0, sizeof *self);
    self->d64 = d64;
    self->dir.capa = DIRCHUNK;
    self->dir.entries = xmalloc(DIRCHUNK * sizeof *self->dir.entries);
    self->vfs = CbmdosVfs_create();
    self->options = options;
    int rc = readCbmdosVfsInternal(self->vfs, self->d64,
	    &self->options, self->bam, &self->dir);
    switch (rc)
    {
	case -1:
	    self->d64 = 0;
	    CbmdosFs_destroy(self);
	    return 0;
	case -2:
	    self->status |= CFS_INVALIDBAM;
	    break;
    }
    if (self->options.flags & CFF_RECOVER)
    {
	self->options.flags &= ~CFF_RECOVER;
	self->status |= CFS_BROKEN;
    }
    Event_register(CbmdosVfs_changedEvent(self->vfs), self, vfsChanged);
    return self;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rsi, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0xcd50
cmpl $0x0, %eax
jge 0xd96b
movq $0x0, -0x8(%rbp)
jmp 0xdb4b
movq -0x18(%rbp), %rdi
callq 0x5480
movl %eax, %ecx
movl %ecx, -0x28(%rbp)
testl %eax, %eax
je 0xd996
jmp 0xd97f
movl -0x28(%rbp), %eax
subl $0x1, %eax
je 0xd9c1
jmp 0xd989
movl -0x28(%rbp), %eax
subl $0x2, %eax
je 0xda08
jmp 0xda26
movl -0x10(%rbp), %eax
andl $0xc, %eax
cmpl $0x0, %eax
je 0xd9bf
movl $0x1, %edi
leaq 0x674f(%rip), %rsi      # 0x140fc
callq 0x5a60
movq $0x0, -0x8(%rbp)
jmp 0xdb4b
jmp 0xda26
movl -0x10(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xd9ea
movl $0x1, %edi
leaq 0x678c(%rip), %rsi      # 0x14164
callq 0x5a60
movq $0x0, -0x8(%rbp)
jmp 0xdb4b
movl -0x10(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0xda06
movl $0x2, %edi
leaq 0x67c4(%rip), %rsi      # 0x141c5
callq 0x5a60
jmp 0xda26
movl -0x10(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0xda24
movl $0x2, %edi
leaq 0x6838(%rip), %rsi      # 0x14257
callq 0x5a60
jmp 0xda26
movl $0x3a0, %edi            # imm = 0x3A0
movq %rdi, -0x38(%rbp)
callq 0x58d0
movq -0x38(%rbp), %rdx
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
xorl %esi, %esi
callq 0x5340
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movl $0x90, 0x1c(%rax)
movl $0x360, %edi            # imm = 0x360
callq 0x58d0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
callq 0x5570
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, 0x24(%rax)
movq -0x20(%rbp), %r8
movq (%r8), %rsi
movq 0x8(%r8), %rdi
movq %r8, %rdx
addq $0x24, %rdx
movq %r8, %rcx
addq $0x2c, %rcx
addq $0x10, %r8
callq 0x9fc0
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
subl $-0x2, %eax
je 0xdae8
jmp 0xdac0
movl -0x2c(%rbp), %eax
subl $-0x1, %eax
jne 0xdaf5
jmp 0xdaca
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rdi
callq 0x54b0
movq $0x0, -0x8(%rbp)
jmp 0xdb4b
movq -0x20(%rbp), %rax
movl 0x20(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x20(%rax)
movq -0x20(%rbp), %rax
movl 0x24(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0xdb23
movq -0x20(%rbp), %rax
movl 0x24(%rax), %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
movl %ecx, 0x24(%rax)
movq -0x20(%rbp), %rax
movl 0x20(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0x20(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5200
movq %rax, %rdi
movq -0x20(%rbp), %rsi
leaq -0x70e(%rip), %rdx      # 0xd430
callq 0x5590
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)