LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/zcfileset.c
// Function: fromFileData
static ZcFileSet *fromFileData(
        const char *name, FileData **files, int logerrors)
{
    ZcFileSet *self = 0;

    if (files[0] && files[1] && files[2] && files[3])
    {
        if (files[4])
        {
            logmsg(L_INFO, "ZcFileSet: 5-file disk-packed zipcode "
                    "read successfully.");
            self = xmalloc(sizeof *self + 5 * sizeof *self->files);
            self->type = ZT_5PACK;
            self->count = 5;
            memcpy(self->files, files, 5 * sizeof *self->files);
        }
        else
        {
            logmsg(L_INFO, "ZcFileSet: 4-file disk-packed zipcode "
                    "read successfully.");
            self = xmalloc(sizeof *self + 4 * sizeof *self->files);
            self->type = ZT_4PACK;
            self->count = 4;
            memcpy(self->files, files, 4 * sizeof *self->files);
        }
        self->name = copystr(name);
    }
    else
    {
        if (logerrors)
        {
            logmsg(L_ERROR, "ZcFileSet: reading failed (missing or "
                    "unreadable files).");
        }
        for (int i = 0; i < 5; ++i) FileData_destroy(files[i]);
    }

    return self;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
cmpq $0x0, (%rsi)
je 0x6ccd
cmpq $0x0, 0x8(%rbx)
je 0x6ccd
cmpq $0x0, 0x10(%rbx)
je 0x6ccd
cmpq $0x0, 0x18(%rbx)
je 0x6ccd
movq %rdi, %r14
cmpq $0x0, 0x20(%rbx)
je 0x6cfa
leaq 0x6b24(%rip), %rsi      # 0xd7b6
pushq $0x3
popq %rdi
callq 0x5960
pushq $0x38
popq %rdi
callq 0x589c
movq %rax, %r15
movabsq $0x500000001, %rax      # imm = 0x500000001
movq %rax, (%r15)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm0, 0x10(%r15)
movups %xmm1, 0x20(%r15)
movq 0x20(%rbx), %rax
movq %rax, 0x30(%r15)
jmp 0x6d32
testl %edx, %edx
je 0x6ce0
leaq 0x6b50(%rip), %rsi      # 0xd828
pushq $0x1
popq %rdi
callq 0x5960
xorl %r15d, %r15d
xorl %r14d, %r14d
cmpq $0x5, %r14
je 0x6d3e
movq (%rbx,%r14,8), %rdi
callq 0x53f0
incq %r14
jmp 0x6ce6
leaq 0x6aee(%rip), %rsi      # 0xd7ef
pushq $0x3
popq %rdi
callq 0x5960
pushq $0x30
popq %rdi
callq 0x589c
movq %rax, %r15
movabsq $0x400000000, %rax      # imm = 0x400000000
movq %rax, (%r15)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm0, 0x10(%r15)
movups %xmm1, 0x20(%r15)
movq %r14, %rdi
callq 0x58dc
movq %rax, 0x8(%r15)
movq %r15, %rax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/zcfileset.c
// Function: ZcFileSet_saveVfs
SOEXPORT int ZcFileSet_saveVfs(const ZcFileSet *self, CbmdosVfs *vfs)
{
    char name[16];
    uint8_t baselen = strlen(self->name) > 14 ? 14 : strlen(self->name);
    memcpy(name+2, self->name, baselen);
    name[1] = '!';
    for (name[0] = '1'; name[0] < (self->type == ZT_5PACK ? '6' : '5');
	    ++name [0])
    {
	CbmdosFile *file = CbmdosFile_create();
	CbmdosFile_setName(file, name, baselen+2);
	FileData *cfd = CbmdosFile_data(file);
	const FileData *fd = self->files[name[0]-'1'];
	if (FileData_append(cfd, FileData_rcontent(fd), FileData_size(fd)) < 0)
	{
	    return -1;
	}
	if (CbmdosVfs_append(vfs, file))
	{
	    return -1;
	}
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
movq 0x8(%rdi), %r15
movq %r15, %rdi
callq 0x5260
cmpq $0xe, %rax
pushq $0xe
popq %r12
cmovbq %rax, %r12
leaq 0x2(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x54a0
movb $0x21, -0x1(%r13)
leal 0x2(%r12), %ecx
movb $0x31, %al
movzbl %cl, %r15d
movb %al, (%rsp)
xorl %ecx, %ecx
cmpl $0x1, (%r14)
movsbl %al, %eax
sete %cl
addl $0x35, %ecx
cmpl %eax, %ecx
jle 0x703e
callq 0x53b0
movq %rax, %r13
movq %rax, %rdi
movq %rsp, %rsi
movl %r15d, %edx
callq 0x5300
movq %r13, %rdi
callq 0x5640
movq %rax, %rbp
movsbq (%rsp), %rax
movq -0x178(%r14,%rax,8), %r12
movq %r12, %rdi
callq 0x5680
movq %rax, %rbx
movq %r12, %rdi
callq 0x5530
movq %rbp, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x5760
testl %eax, %eax
js 0x7039
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x54e0
testl %eax, %eax
jne 0x7039
movb (%rsp), %al
incb %al
jmp 0x6fb5
pushq $-0x1
popq %rax
jmp 0x7040
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/zcfileset.c
// Function: ZcFileSet_destroy
SOEXPORT void ZcFileSet_destroy(ZcFileSet *self)
{
    if (!self) return;
    free(self->name);
    for (int i = 0; i < self->count; ++i) FileData_destroy(self->files[i]);
    free(self);
}

// Assembly:
testq %rdi, %rdi
je 0x708e
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
callq 0x5080
xorl %r14d, %r14d
movslq 0x4(%rbx), %rax
cmpq %rax, %r14
jge 0x707f
movq 0x10(%rbx,%r14,8), %rdi
callq 0x53f0
incq %r14
jmp 0x7067
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x5080
retq
nop
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/zc45extractor.c
// Function: extractZc45
SOEXPORT D64 *extractZc45(const ZcFileSet *fileset)
{
    if (!fileset) return 0;
    ZcType type = ZcFileSet_type(fileset);
    if (type != ZT_4PACK && type != ZT_5PACK)
    {
        logmsg(L_ERROR, "extractZc45: trying to extract something that isn't "
                "a 4 or 5 file disk Zippack.");
        return 0;
    }

    D64 *extracted = D64_create(type == ZT_4PACK ? D64_STANDARD : D64_40TRACK);
    for (int i = 0; i < (type == ZT_4PACK ? 4 : 5); ++i)
    {
	const FileData *fd = ZcFileSet_rfileData(fileset, i);
	if (zc45_read(extracted, sectorcount[i],
                    FileData_rcontent(fd), FileData_size(fd))
		!= sectorcount[i])
	{
            logfmt(L_ERROR, "extractZc45: extraction failed in part %d.", i+1);
	    D64_destroy(extracted);
	    return 0;
	}
    }

    logfmt(L_DEBUG, "extractZc45: %d-file zipcode successfully extracted.",
            type == ZT_4PACK ? 4 : 5);
    return extracted;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdi, %rdi
je 0x7158
movq %rdi, %rbx
callq 0x5510
cmpl $0x2, %eax
jb 0x70c8
leaq 0x6827(%rip), %rsi      # 0xd8e2
pushq $0x1
popq %rdi
callq 0x5960
jmp 0x7158
movl %eax, %ebp
movl %eax, %edi
callq 0x55f0
movq %rax, %r14
cmpl $0x1, %ebp
pushq $0x5
popq %rax
sbbl $0x0, %eax
movq %rax, 0x8(%rsp)
leaq 0x68b7(%rip), %r15      # 0xd9a0
xorl %r12d, %r12d
movq %rbx, 0x10(%rsp)
cmpq %r12, 0x8(%rsp)
je 0x716d
movq %rbx, %rdi
movl %r12d, %esi
callq 0x5360
movq %rax, %r13
movl (%r15), %ebp
movq %rax, %rdi
callq 0x5680
movq %rax, %rbx
movq %r13, %rdi
callq 0x5530
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
movq 0x10(%rsp), %rbx
movq %rax, %rcx
callq 0x5070
incq %r12
addq $0x4, %r15
cmpl %ebp, %eax
je 0x70f1
leaq 0x67ef(%rip), %rsi      # 0xd932
pushq $0x1
popq %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x598d
movq %r14, %rdi
callq 0x55e0
xorl %r14d, %r14d
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x67e9(%rip), %rsi      # 0xd95d
pushq $0x4
popq %rdi
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x598d
jmp 0x715b
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosfile.c
// Function: CbmdosFile_baseCreate
static CbmdosFile *CbmdosFile_baseCreate(CbmdosInode *inode)
{
    CbmdosFile *self = xmalloc(sizeof *self);
    memset(self, 0, sizeof *self);
    self->inode = inode;
    self->changedEvent = Event_create(0, self);
    self->type = CFT_PRG;
    self->invalidType = -1;
    self->closed = 1;
    self->forcedBlocks = 0xffff;
    self->recordLength = 254;
    CbmdosInode_attach(self->inode);
    Event_register(CbmdosInode_changedEvent(self->inode), self, inodeHandler);
    return self;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %r14
pushq $0x30
popq %rdi
callq 0x589c
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movups %xmm0, 0x20(%rax)
movq %r14, 0x10(%rax)
xorl %edi, %edi
movq %rax, %rsi
callq 0x5280
movq %rax, (%rbx)
movabsq $-0xfffffffe, %rax      # imm = 0xFFFFFFFF00000002
movq %rax, 0x18(%rbx)
movl $0x1, 0x24(%rbx)
orw $-0x1, 0x2e(%rbx)
movb $-0x2, 0x2d(%rbx)
movq 0x10(%rbx), %rdi
callq 0xaff1
movq 0x10(%rbx), %rdi
callq 0x5700
leaq 0x174(%rip), %rdx       # 0x7386
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5580
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosfile.c
// Function: CbmdosFile_clone
SOEXPORT CbmdosFile *CbmdosFile_clone(const CbmdosFile *other)
{
    CbmdosFile *self = xmalloc(sizeof *self);
    self->type = other->type;
    self->invalidType = other->invalidType;
    self->locked = other->locked;
    self->closed = other->closed;
    self->autoMapToLc = 0;
    self->name = 0;
    self->inode = CbmdosInode_clone(other->inode);
    self->changedEvent = Event_create(0, self);
    self->nameLength = 0;
    self->recordLength = other->recordLength;
    self->forcedBlocks = other->forcedBlocks;
    uint8_t len;
    const char *name = CbmdosFile_name(other, &len);
    CbmdosFile_setName(self, name, len);
    self->autoMapToLc = other->autoMapToLc;
    CbmdosInode_attach(self->inode);
    Event_register(CbmdosInode_changedEvent(self->inode), self, inodeHandler);
    return self;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %r14
pushq $0x30
popq %rdi
callq 0x589c
movq %rax, %rbx
movups 0x18(%r14), %xmm0
movups %xmm0, 0x18(%rax)
andl $0x0, 0x28(%rax)
andq $0x0, 0x8(%rax)
movq 0x10(%r14), %rdi
callq 0xaec2
movq %rax, 0x10(%rbx)
xorl %edi, %edi
movq %rbx, %rsi
callq 0x5280
movq %rax, (%rbx)
movb $0x0, 0x2c(%rbx)
movb 0x2d(%r14), %al
movb %al, 0x2d(%rbx)
movzwl 0x2e(%r14), %eax
movw %ax, 0x2e(%rbx)
movzbl 0x2c(%r14), %edx
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x5300
movl 0x28(%r14), %eax
movl %eax, 0x28(%rbx)
movq 0x10(%rbx), %rdi
callq 0xaff1
movq 0x10(%rbx), %rdi
callq 0x5700
leaq 0xdb(%rip), %rdx        # 0x7386
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5580
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosfile.c
// Function: CbmdosFile_setName
SOEXPORT void CbmdosFile_setName(
	CbmdosFile *self, const char *name, uint8_t length)
{
    if (length > 16)
    {
        logmsg(L_WARNING, "CbmdosFile_setName: truncating long name.");
        length = 16;
    }
    free(self->name);
    if (name)
    {
        self->name = xmalloc(length+1);
        memcpy(self->name, name, length);
        self->name[length] = 0;
    }
    else
    {
        self->name = 0;
        if (length)
        {
            logmsg(L_WARNING, "CbmdosFile_setName: length > 0 given for empty "
                    "name.");
            length = 0;
        }
    }
    self->nameLength = length;
    if (self->autoMapToLc)
    {
	petscii_mapUpperGfxToLower(self->name, self->nameLength);
    }
    CbmdosFileEventArgs args = { CFE_NAMECHANGED };
    Event_raise(self->changedEvent, &args);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbx
cmpb $0x11, %r14b
jb 0x72f9
leaq 0x66e8(%rip), %rsi      # 0xd9d6
pushq $0x2
popq %rdi
callq 0x5960
movb $0x10, %r14b
movq 0x8(%rbx), %rdi
callq 0x5080
testq %r15, %r15
je 0x7334
leal 0x1(%r14), %eax
movzbl %al, %edi
callq 0x589c
movq %rax, 0x8(%rbx)
movzbl %r14b, %r12d
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x54a0
movq 0x8(%rbx), %rax
movb $0x0, (%rax,%r12)
jmp 0x7350
andq $0x0, 0x8(%rbx)
testb %r14b, %r14b
je 0x734d
leaq 0x66bb(%rip), %rsi      # 0xda00
pushq $0x2
popq %rdi
callq 0x5960
xorl %r14d, %r14d
movb %r14b, 0x2c(%rbx)
cmpl $0x0, 0x28(%rbx)
je 0x7367
movq 0x8(%rbx), %rdi
movzbl %r14b, %esi
callq 0x57a0
leaq 0x4(%rsp), %rsi
movl $0x1, (%rsi)
movq (%rbx), %rdi
callq 0x5610
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosfile.c
// Function: CbmdosFile_setType
SOEXPORT int CbmdosFile_setType(CbmdosFile *self, CbmdosFileType type)
{
    int rc = 0;
    int invalidType = -1;
    type &= 0xf;
    if (type < CFT_DEL || type > CFT_REL)
    {
        logmsg(L_WARNING, "CbmdosFile_setType: invalid type.");
	invalidType = type;
        type = CFT_DEL;
	rc = -1;
    }
    if (type == self->type && invalidType == self->invalidType) return rc;
    if ((self->invalidType < 0 && self->type == CFT_DEL) ||
	    (invalidType < 0 && type == CFT_DEL))
    {
	CbmdosFile_setData(self, FileData_create());
    }
    self->type = type;
    self->invalidType = invalidType;
    CbmdosFileEventArgs args = { CFE_TYPECHANGED };
    Event_raise(self->changedEvent, &args);
    return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
andl $0xf, %ebp
cmpl $0x5, %ebp
jb 0x73ef
leaq 0x65d6(%rip), %rsi      # 0xd9b4
pushq $0x2
popq %rdi
callq 0x5960
pushq $-0x1
popq %r14
xorl %r15d, %r15d
jmp 0x73f8
movl %ebp, %r15d
pushq $-0x1
popq %rbp
xorl %r14d, %r14d
movl 0x18(%rbx), %eax
movl 0x1c(%rbx), %ecx
movl %r15d, %edx
xorl %eax, %edx
movl %ebp, %esi
xorl %ecx, %esi
orl %edx, %esi
je 0x744f
testl %ecx, %ecx
sets %cl
testl %eax, %eax
sete %al
testb %cl, %al
jne 0x7428
testl %ebp, %ebp
setns %al
testl %r15d, %r15d
setne %cl
orb %al, %cl
jne 0x7438
callq 0x5520
movq %rbx, %rdi
movq %rax, %rsi
callq 0x51b0
movl %r15d, 0x18(%rbx)
movl %ebp, 0x1c(%rbx)
leaq 0x4(%rsp), %rsi
andl $0x0, (%rsi)
movq (%rbx), %rdi
callq 0x5610
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosfile.c
// Function: CbmdosFile_exportPC64
SOEXPORT int CbmdosFile_exportPC64(const CbmdosFile *self, FILE *file)
{
    uint8_t header[26] = "C64File";
    memcpy(header+8, self->name, self->nameLength);
    if (self->type == CFT_REL) header[25] = self->recordLength;
    if (fwrite(header, sizeof header, 1, file) != 1) return -1;
    return writeHostFile(CbmdosInode_rdata(self->inode), file);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movups 0x6607(%rip), %xmm0     # 0xdada
leaq 0x8(%rsp), %rdi
movups %xmm0, 0x2(%rdi)
movaps 0x65ed(%rip), %xmm0     # 0xdad0
movaps %xmm0, -0x8(%rdi)
movq 0x8(%r14), %rsi
movzbl 0x2c(%r14), %edx
callq 0x54a0
cmpl $0x4, 0x18(%r14)
jne 0x7504
movb 0x2d(%r14), %al
movb %al, 0x19(%rsp)
movq %rsp, %rdi
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x5720
cmpq $0x1, %rax
jne 0x7536
movq 0x10(%r14), %rdi
callq 0x5240
movq %rax, %rdi
movq %rbx, %rsi
addq $0x28, %rsp
popq %rbx
popq %r14
jmp 0x55d0
pushq $-0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosfile.c
// Function: CbmdosFile_import
SOEXPORT int CbmdosFile_import(CbmdosFile *self, FILE *file)
{
    FileData *data = readHostFile(file);
    if (!data) return -1;
    const uint8_t *content = FileData_rcontent(data);
    if (FileData_size(data) > 26 && !content[24]
	    && !memcmp(content, "C64File", sizeof "C64File"))
    {
	FileData *raw = FileData_create();
	if (!raw)
	{
	    FileData_destroy(data);
	    return -1;
	}
	if (FileData_append(raw, content+26, FileData_size(data)-26) < 0)
	{
	    FileData_destroy(raw);
	    FileData_destroy(data);
	    return -1;
	}
	CbmdosFile_setData(self, raw);
	CbmdosFile_setName(self, (const char *)content+8,
		strlen((const char *)content+8));
	CbmdosFile_setRecordLength(self, content[25] ? content[25] : 254);
	FileData_destroy(data);
    }
    else
    {
	CbmdosFile_setData(self, data);
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movq %rsi, %rdi
callq 0x52e0
pushq $-0x1
popq %rbp
testq %rax, %rax
je 0x759e
movq %rax, %rbx
movq %rax, %rdi
callq 0x5680
movq %rax, %r15
movq %rbx, %rdi
callq 0x5530
cmpq $0x1b, %rax
jb 0x7591
cmpb $0x0, 0x18(%r15)
jne 0x7591
movabsq $0x656c6946343643, %rax # imm = 0x656C6946343643
cmpq %rax, (%r15)
je 0x75af
movq %r14, %rdi
movq %rbx, %rsi
callq 0x51b0
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5520
testq %rax, %rax
je 0x7637
movq %rax, %r12
leaq 0x1a(%r15), %r13
movq %rbx, %rdi
callq 0x5530
leaq -0x1a(%rax), %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x5760
testl %eax, %eax
js 0x762f
movq %r14, %rdi
movq %r12, %rsi
callq 0x51b0
movq %r15, %r12
addq $0x8, %r12
movq %r12, %rdi
callq 0x5260
movl $0xff, %ebp
andl %ebp, %eax
movq %r14, %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0x5300
movzbl 0x19(%r15), %eax
testb %al, %al
movl $0xfe, %esi
cmovnel %eax, %esi
andl %ebp, %esi
movq %r14, %rdi
callq 0x55b0
movq %rbx, %rdi
callq 0x53f0
jmp 0x759c
movq %r12, %rdi
callq 0x53f0
movq %rbx, %rdi
callq 0x53f0
jmp 0x759e
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosfile.c
// Function: CbmdosFile_setRecordLength
SOEXPORT int CbmdosFile_setRecordLength(CbmdosFile *self, uint8_t recordLength)
{
    if (recordLength > 254)
    {
        logmsg(L_WARNING, "CbmdosFile_setRecordLength: invalid length, "
                "max is 254.");
        return -1;
    }
    if (recordLength < 1)
    {
        logmsg(L_WARNING, "CbmdosFile_setRecordLength: invalid length, "
                "min is 1.");
        return -1;
    }
    self->recordLength = recordLength;
    CbmdosFileEventArgs ea = { CFE_RECORDLENGTHCHANGED };
    Event_raise(self->changedEvent, &ea);
    return 0;
}

// Assembly:
pushq %rax
testl %esi, %esi
je 0x765a
cmpl $0xff, %esi
jne 0x766e
leaq 0x63e5(%rip), %rsi      # 0xda3d
jmp 0x7661
leaq 0x6414(%rip), %rsi      # 0xda75
pushq $0x2
popq %rdi
callq 0x5960
pushq $-0x1
popq %rax
jmp 0x7687
movb %sil, 0x2d(%rdi)
leaq 0x4(%rsp), %rsi
movl $0x6, (%rsi)
movq (%rdi), %rdi
callq 0x5610
xorl %eax, %eax
popq %rcx
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosfile.c
// Function: CbmdosFile_getDirLine
SOEXPORT void CbmdosFile_getDirLine(const CbmdosFile *self, uint8_t *line)
{
    int blocklen = sprintf((char *)line, "%u", CbmdosFile_blocks(self));
    memset(line + blocklen, 0xa0, 28 - blocklen);
    memcpy(line + 6, self->name, self->nameLength);
    if (self->invalidType < 0)
    {
	memcpy(line + 24, CbmdosFileType_name(self->type), 3);
    }
    else
    {
	memcpy(line + 24, "?  ", 3);
    }
    line[5] = 0x22;
    uint8_t endidx = 6;
    int qclosed = 0;
    while (line[endidx] != 0xa0)
    {
	if (line[endidx] == 0x22) qclosed = 1;
	++endidx;
    }
    if (!qclosed) line[endidx] = 0x22;
    if (!self->closed) line[23] = 0x2a;
    if (self->locked) line[27] = 0x3c;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
callq 0x5380
movzwl %ax, %edx
leaq 0x635c(%rip), %rsi      # 0xdaab
movq %rbx, %rdi
xorl %eax, %eax
callq 0x5710
cltq
leaq (%rbx,%rax), %rdi
pushq $0x1c
popq %rcx
subl %eax, %ecx
movslq %ecx, %rdx
movl $0xa0, %esi
callq 0x5330
leaq 0x6(%rbx), %rdi
movq 0x8(%r14), %rsi
movzbl 0x2c(%r14), %edx
callq 0x54a0
leaq 0x18(%rbx), %rax
cmpl $0x0, 0x1c(%r14)
js 0x7799
movb $0x20, 0x2(%rax)
movw $0x203f, (%rax)         # imm = 0x203F
jmp 0x77b4
movl 0x18(%r14), %ecx
leaq 0xb15c(%rip), %rdx      # 0x12900
movq (%rdx,%rcx,8), %rcx
movb 0x2(%rcx), %dl
movb %dl, 0x2(%rax)
movzwl (%rcx), %ecx
movw %cx, (%rax)
movb $0x22, 0x5(%rbx)
xorl %ecx, %ecx
movb $0x6, %al
pushq $0x1
popq %rdx
movzbl %al, %eax
movzbl (%rbx,%rax), %esi
cmpl $0x22, %esi
je 0x77d5
cmpl $0xa0, %esi
jne 0x77d7
jmp 0x77db
movl %edx, %ecx
incb %al
jmp 0x77bf
testl %ecx, %ecx
jne 0x77e3
movb $0x22, (%rbx,%rax)
cmpl $0x0, 0x24(%r14)
jne 0x77ee
movb $0x2a, 0x17(%rbx)
cmpl $0x0, 0x20(%r14)
je 0x77f9
movb $0x3c, 0x1b(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosfile.c
// Function: CbmdosFile_destroy
SOEXPORT void CbmdosFile_destroy(CbmdosFile *self)
{
    if (!self) return;
    free(self->name);
    Event_destroy(self->changedEvent);
    Event_unregister(CbmdosInode_changedEvent(self->inode), self, inodeHandler);
    CbmdosInode_detach(self->inode);
    CbmdosInode_tryDestroy(self->inode);
    free(self);
}

// Assembly:
testq %rdi, %rdi
je 0x7855
pushq %rbx
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
callq 0x5080
movq (%rbx), %rdi
callq 0x5170
movq 0x10(%rbx), %rdi
callq 0x5700
leaq -0x4a9(%rip), %rdx      # 0x7386
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5340
movq 0x10(%rbx), %rdi
callq 0xaff5
movq 0x10(%rbx), %rdi
callq 0xb011
movq %rbx, %rdi
popq %rbx
jmp 0x5080
retq
nop
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: CbmdosVfs_create
SOEXPORT CbmdosVfs *CbmdosVfs_create(void)
{
    CbmdosVfs *self = xmalloc(sizeof *self);
    memset(self, 0, sizeof *self);
    self->files = xmalloc(DIRCHUNKSIZE * sizeof *self->files);
    self->fileCapa = DIRCHUNKSIZE;
    self->dosver = 0x41;
    self->changedEvent = Event_create(0, self);
    return self;
}

// Assembly:
pushq %rbx
pushq $0x38
popq %rdi
callq 0x589c
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
andq $0x0, 0x30(%rax)
movl $0x480, %edi            # imm = 0x480
callq 0x589c
movq %rax, 0x18(%rbx)
movl $0x90, 0x2c(%rbx)
movb $0x41, 0x32(%rbx)
xorl %edi, %edi
movq %rbx, %rsi
callq 0x5280
movq %rax, 0x20(%rbx)
movq %rbx, %rax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: CbmdosVfs_setName
SOEXPORT void CbmdosVfs_setName(
	CbmdosVfs *self, const char *name, uint8_t length)
{
    if (length > 16)
    {
        logmsg(L_WARNING, "CbmdosVfs_setName: truncating long name.");
        length = 16;
    }
    free(self->name);
    if (name)
    {
        self->name = xmalloc(length+1);
        memcpy(self->name, name, length);
        self->name[length] = 0;
    }
    else
    {
        self->name = 0;
        if (length)
        {
            logmsg(L_WARNING, "CbmdosVfs_setName: length > 0 given for empty "
                    "name.");
            length = 0;
        }
    }
    self->nameLength = length;
    if (self->autoMapToLc)
    {
	petscii_mapUpperGfxToLower(self->name, self->nameLength);
    }
    CbmdosVfsEventArgs args = { .what = CVE_NAMECHANGED };
    Event_raise(self->changedEvent, &args);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbx
cmpb $0x11, %r14b
jb 0x7905
leaq 0x6206(%rip), %rsi      # 0xdb00
pushq $0x2
popq %rdi
callq 0x5960
movb $0x10, %r14b
movq (%rbx), %rdi
callq 0x5080
testq %r15, %r15
je 0x793d
leal 0x1(%r14), %eax
movzbl %al, %edi
callq 0x589c
movq %rax, (%rbx)
movzbl %r14b, %r12d
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x54a0
movq (%rbx), %rax
movb $0x0, (%rax,%r12)
jmp 0x7958
andq $0x0, (%rbx)
testb %r14b, %r14b
je 0x7955
leaq 0x61dc(%rip), %rsi      # 0xdb29
pushq $0x2
popq %rdi
callq 0x5960
xorl %r14d, %r14d
movb %r14b, 0x30(%rbx)
cmpl $0x0, 0x10(%rbx)
je 0x796e
movq (%rbx), %rdi
movzbl %r14b, %esi
callq 0x57a0
movq 0x62f3(%rip), %rax      # 0xdc68
movq %rsp, %rsi
movq %rax, 0x10(%rsi)
movups 0x62d5(%rip), %xmm0     # 0xdc58
movaps %xmm0, (%rsi)
movq 0x20(%rbx), %rdi
callq 0x5610
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: CbmdosVfs_setId
SOEXPORT void CbmdosVfs_setId(CbmdosVfs *self, const char *id, uint8_t length)
{
    if (length > 5)
    {
        logmsg(L_WARNING, "CbmdosVfs_setId: truncating long id.");
        length = 5;
    }
    free(self->id);
    if (id)
    {
        self->id = xmalloc(length+1);
        memcpy(self->id, id, length);
        self->id[length] = 0;
    }
    else
    {
        self->id = 0;
        if (length)
        {
            logmsg(L_WARNING, "CbmdosVfs_setId: length > 0 given for empty "
                    "id.");
            length = 0;
        }
    }
    self->idLength = length;
    if (self->autoMapToLc)
    {
	petscii_mapUpperGfxToLower(self->id, self->idLength);
    }
    CbmdosVfsEventArgs args = { .what = CVE_IDCHANGED };
    Event_raise(self->changedEvent, &args);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbx
cmpb $0x6, %r14b
jb 0x79d6
leaq 0x6192(%rip), %rsi      # 0xdb5d
pushq $0x2
popq %rdi
callq 0x5960
movb $0x5, %r14b
movq 0x8(%rbx), %rdi
callq 0x5080
testq %r15, %r15
je 0x7a11
leal 0x1(%r14), %eax
movzbl %al, %edi
callq 0x589c
movq %rax, 0x8(%rbx)
movzbl %r14b, %r12d
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x54a0
movq 0x8(%rbx), %rax
movb $0x0, (%rax,%r12)
jmp 0x7a2d
andq $0x0, 0x8(%rbx)
testb %r14b, %r14b
je 0x7a2a
leaq 0x6160(%rip), %rsi      # 0xdb82
pushq $0x2
popq %rdi
callq 0x5960
xorl %r14d, %r14d
movb %r14b, 0x31(%rbx)
cmpl $0x0, 0x10(%rbx)
je 0x7a44
movq 0x8(%rbx), %rdi
movzbl %r14b, %esi
callq 0x57a0
movq 0x6205(%rip), %rax      # 0xdc50
movq %rsp, %rsi
movq %rax, 0x10(%rsi)
movups 0x61e7(%rip), %xmm0     # 0xdc40
movaps %xmm0, (%rsi)
movq 0x20(%rbx), %rdi
callq 0x5610
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: CbmdosVfs_mapUpperGfxToLower
SOEXPORT void CbmdosVfs_mapUpperGfxToLower(CbmdosVfs *self, int mapFiles)
{
    if (mapFiles)
    {
	for (unsigned i = 0; i < self->fileCount; ++i)
	{
	    CbmdosFile_mapUpperGfxToLower(self->files[i]);
	}
    }
    petscii_mapUpperGfxToLower(self->name, self->nameLength);
    CbmdosVfsEventArgs args = { .what = CVE_NAMECHANGED };
    Event_raise(self->changedEvent, &args);
    petscii_mapUpperGfxToLower(self->id, self->idLength);
    args.what = CVE_IDCHANGED;
    Event_raise(self->changedEvent, &args);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
testl %esi, %esi
je 0x7a9c
xorl %r14d, %r14d
movl 0x28(%rbx), %eax
cmpq %rax, %r14
jae 0x7a9c
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x5750
incq %r14
jmp 0x7a82
movq (%rbx), %rdi
movzbl 0x30(%rbx), %esi
callq 0x57a0
movq 0x61b9(%rip), %rax      # 0xdc68
movq %rsp, %r14
movq %rax, 0x10(%r14)
movups 0x619b(%rip), %xmm0     # 0xdc58
movaps %xmm0, (%r14)
movq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0x5610
movq 0x8(%rbx), %rdi
movzbl 0x31(%rbx), %esi
callq 0x57a0
movl $0x2, (%r14)
movq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0x5610
addq $0x18, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: CbmdosVfs_delete
SOEXPORT int CbmdosVfs_delete(CbmdosVfs *self, const CbmdosFile *file)
{
    unsigned pos;
    for (pos = 0; pos < self->fileCount; ++pos)
    {
        if (self->files[pos] == file) break;
    }
    if (pos == self->fileCount)
    {
        logmsg(L_WARNING, "CbmdosVfs_delete: file not found.");
        return -1;
    }
    return CbmdosVfs_deleteAt(self, pos);
}

// Assembly:
pushq %rax
movq %rsi, %rax
movl 0x28(%rdi), %ecx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x7b40
movq 0x18(%rdi), %rdx
cmpq %rax, (%rdx,%rsi,8)
je 0x7b3c
incq %rsi
jmp 0x7b28
cmpl %esi, %ecx
jne 0x7b54
leaq 0x606b(%rip), %rsi      # 0xdbb2
pushq $0x2
popq %rdi
callq 0x5960
pushq $-0x1
popq %rax
popq %rcx
retq
popq %rax
jmp 0x5120
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: CbmdosVfs_deleteAt
SOEXPORT int CbmdosVfs_deleteAt(CbmdosVfs *self, unsigned pos)
{
    if (pos >= self->fileCount)
    {
        logmsg(L_WARNING, "CbmdosVfs_deleteAt: file not found.");
        return -1;
    }
    CbmdosFile_destroy(self->files[pos]);
    if (pos < --self->fileCount)
    {
        memmove(self->files + pos, self->files + pos + 1,
                (self->fileCount - pos) * sizeof *self->files);
    }
    CbmdosVfsEventArgs args = {
        .what = CVE_FILEDELETED,
        .filepos = pos
    };
    Event_raise(self->changedEvent, &args);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x20, %rsp
cmpl %esi, 0x28(%rdi)
jbe 0x7bc5
movl %esi, %ebp
movq %rdi, %rbx
movq 0x18(%rdi), %rax
movl %esi, %r14d
movq (%rax,%r14,8), %rdi
callq 0x50e0
movl 0x28(%rbx), %edx
decl %edx
movl %edx, 0x28(%rbx)
subl %ebp, %edx
jbe 0x7ba1
movq 0x18(%rbx), %rax
leaq (%rax,%r14,8), %rdi
leaq (%rax,%r14,8), %rsi
addq $0x8, %rsi
shlq $0x3, %rdx
callq 0x5660
leaq 0x8(%rsp), %rsi
movl $0x4, (%rsi)
andq $0x0, 0x8(%rsi)
movl %ebp, 0x10(%rsi)
andl $0x0, 0x14(%rsi)
movq 0x20(%rbx), %rdi
callq 0x5610
xorl %eax, %eax
jmp 0x7bd7
leaq 0x6008(%rip), %rsi      # 0xdbd4
pushq $0x2
popq %rdi
callq 0x5960
pushq $-0x1
popq %rax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: CbmdosVfs_append
SOEXPORT int CbmdosVfs_append(CbmdosVfs *self, CbmdosFile *file)
{
    if (ensureSpace(self) < 0) return -1;
    self->files[self->fileCount++] = file;
    Event_register(CbmdosFile_changedEvent(file), self, fileHandler);
    CbmdosVfsEventArgs args = {
        .what = CVE_FILEADDED,
        .filepos = self->fileCount - 1
    };
    Event_raise(self->changedEvent, &args);
    return 0;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x7c53
testl %eax, %eax
js 0x7c48
movq 0x18(%rbx), %rax
movl 0x28(%rbx), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x28(%rbx)
movq %r14, (%rax,%rcx,8)
movq %r14, %rdi
callq 0x56a0
leaq 0x96(%rip), %rdx        # 0x7cac
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5580
movq %rsp, %rsi
movl $0x3, (%rsi)
andq $0x0, 0x8(%rsi)
movl 0x28(%rbx), %eax
decl %eax
movl %eax, 0x10(%rsi)
andl $0x0, 0x14(%rsi)
movq 0x20(%rbx), %rdi
callq 0x5610
xorl %eax, %eax
jmp 0x7c4b
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: ensureSpace
static int ensureSpace(CbmdosVfs *self)
{
    if (self->fileCount == self->fileCapa)
    {
        unsigned newCapa = self->fileCapa + DIRCHUNKSIZE;
        if (newCapa <= self->fileCapa)
        {
            logmsg(L_ERROR, "CbmdosVfs: directory overflow.");
            return -1;
        }
        CbmdosFile **newFiles = realloc(self->files,
                newCapa * sizeof *newFiles);
        if (!newFiles)
        {
            logmsg(L_ERROR, "CbmdosVfs: memory allocation failed.");
            return -1;
        }
        self->files = newFiles;
        self->fileCapa = newCapa;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl 0x28(%rdi), %ebp
xorl %ebx, %ebx
cmpl 0x2c(%rdi), %ebp
jne 0x7ca5
subl $0xffffff70, %ebp       # imm = 0xFFFFFF70
jae 0x7c8a
movq %rdi, %r14
movq 0x18(%rdi), %rdi
movl %ebp, %esi
shlq $0x3, %rsi
callq 0x55c0
testq %rax, %rax
je 0x7c93
movq %rax, 0x18(%r14)
movl %ebp, 0x2c(%r14)
jmp 0x7ca5
leaq 0x5f67(%rip), %rsi      # 0xdbf8
jmp 0x7c9a
leaq 0x5f7d(%rip), %rsi      # 0xdc17
pushq $0x1
popq %rdi
callq 0x5960
pushq $-0x1
popq %rbx
movl %ebx, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: fileHandler
static void fileHandler(void *receiver, int id, const void *sender,
        const void *args)
{
    (void)id;

    CbmdosVfs *self = receiver;
    unsigned pos;
    for (pos = 0; pos < self->fileCount; ++pos)
    {
        if (self->files[pos] == sender) break;
    }
    CbmdosVfsEventArgs ea = {
        .what = CVE_FILECHANGED,
        .fileEventArgs = args,
        .filepos = pos
    };
    Event_raise(self->changedEvent, &ea);
}

// Assembly:
subq $0x18, %rsp
movl 0x28(%rdi), %esi
xorl %eax, %eax
cmpq %rax, %rsi
je 0x7cc9
movq 0x18(%rdi), %r8
cmpq %rdx, (%r8,%rax,8)
je 0x7ccb
incq %rax
jmp 0x7cb5
movl %esi, %eax
movq %rsp, %rsi
movl $0x6, (%rsi)
movq %rcx, 0x8(%rsi)
movl %eax, 0x10(%rsi)
andl $0x0, 0x14(%rsi)
movq 0x20(%rdi), %rdi
callq 0x5610
addq $0x18, %rsp
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: CbmdosVfs_insert
SOEXPORT int CbmdosVfs_insert(CbmdosVfs *self, CbmdosFile *file, unsigned pos)
{
    if (pos >= self->fileCount) return CbmdosVfs_append(self, file);
    if (ensureSpace(self) < 0) return -1;
    memmove(self->files + pos + 1, self->files + pos,
            (self->fileCount++ - pos) * sizeof *self->files);
    self->files[pos] = file;
    Event_register(CbmdosFile_changedEvent(file), self, fileHandler);
    CbmdosVfsEventArgs args = {
        .what = CVE_FILEADDED,
        .filepos = pos
    };
    Event_raise(self->changedEvent, &args);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
cmpl %edx, 0x28(%rdi)
jbe 0x7d7f
movl %edx, %ebp
movq %rbx, %rdi
callq 0x7c53
testl %eax, %eax
js 0x7d94
movq 0x18(%rbx), %rax
movl %ebp, %r15d
leaq (%rax,%r15,8), %rsi
leaq (%rax,%r15,8), %rdi
addq $0x8, %rdi
movl 0x28(%rbx), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x28(%rbx)
subl %ebp, %edx
shlq $0x3, %rdx
callq 0x5660
movq 0x18(%rbx), %rax
movq %r14, (%rax,%r15,8)
movq %r14, %rdi
callq 0x56a0
leaq -0xa6(%rip), %rdx       # 0x7cac
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5580
movq %rsp, %rsi
movl $0x3, (%rsi)
andq $0x0, 0x8(%rsi)
movl %ebp, 0x10(%rsi)
andl $0x0, 0x14(%rsi)
movq 0x20(%rbx), %rdi
callq 0x5610
xorl %eax, %eax
jmp 0x7d97
movq %rbx, %rdi
movq %r14, %rsi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x54e0
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: CbmdosVfs_move
SOEXPORT int CbmdosVfs_move(CbmdosVfs *self, unsigned to, unsigned from)
{
    if (from >= self->fileCount) return -1;
    if (to >= self->fileCount) to = self->fileCount - 1;
    if (to == from) return 0;
    CbmdosFile *tmp = self->files[from];
    if (to > from)
    {
	memmove(self->files + from, self->files + from + 1,
		(to - from) * sizeof *self->files);
    }
    else
    {
	memmove(self->files + to + 1, self->files + to,
		(from - to) * sizeof *self->files);
    }
    self->files[to] = tmp;
    CbmdosVfsEventArgs args = {
	.what = CVE_FILEMOVED,
	.filepos = from,
	.targetpos = to
    };
    Event_raise(self->changedEvent, &args);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x28(%rdi), %eax
cmpl %edx, %eax
jbe 0x7df4
movl %edx, %ebp
leal -0x1(%rax), %r15d
cmpl %esi, %eax
cmoval %esi, %r15d
xorl %ebx, %ebx
cmpl %edx, %r15d
je 0x7e3c
movq %rdi, %r14
movq 0x18(%rdi), %rax
movl %ebp, %ecx
movq (%rax,%rcx,8), %r12
movl %r15d, %edx
subl %ebp, %edx
jbe 0x7df9
leaq (%rax,%rcx,8), %rdi
leaq 0x8(%rdi), %rsi
shlq $0x3, %rdx
callq 0x5660
movl %r15d, %r13d
jmp 0x7e16
pushq $-0x1
popq %rbx
jmp 0x7e3c
movl %r15d, %r13d
leaq (%rax,%r13,8), %rsi
leaq (%rax,%r13,8), %rdi
addq $0x8, %rdi
movl %ebp, %edx
subl %r15d, %edx
shlq $0x3, %rdx
callq 0x5660
movq 0x18(%r14), %rax
movq %r12, (%rax,%r13,8)
movq %rsp, %rsi
movl $0x5, (%rsi)
andq $0x0, 0x8(%rsi)
movl %ebp, 0x10(%rsi)
movl %r15d, 0x14(%rsi)
movq 0x20(%r14), %rdi
callq 0x5610
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: CbmdosVfs_getDirHeader
SOEXPORT void CbmdosVfs_getDirHeader(const CbmdosVfs *self, uint8_t *line)
{
    memset(line, 0xa0, 24);
    line[0] = 0x22;
    line[17] = 0x22;
    line[22] = 0x32;
    line[23] = self->dosver;
    memcpy(line+1, self->name, self->nameLength);
    memcpy(line+19, self->id, self->idLength);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x1(%rsi), %rdi
movabsq $-0x5f5f5f5f5f5f5f60, %rax # imm = 0xA0A0A0A0A0A0A0A0
movq %rax, 0x10(%rsi)
movaps 0x5c80(%rip), %xmm0     # 0xdaf0
movups %xmm0, 0x1(%rsi)
movb $0x22, %al
movb %al, (%rsi)
movb %al, 0x11(%rsi)
movb $0x32, 0x16(%rsi)
movb 0x32(%r14), %al
movb %al, 0x17(%rsi)
movq (%r14), %rsi
movzbl 0x30(%r14), %edx
callq 0x54a0
addq $0x13, %rbx
movq 0x8(%r14), %rsi
movzbl 0x31(%r14), %edx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x54a0
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: CbmdosVfs_setAutoMapToLc
SOEXPORT void CbmdosVfs_setAutoMapToLc(
	CbmdosVfs *self, int autoMapToLc, int applyToFiles)
{
    if (applyToFiles)
    {
	for (unsigned i = 0; i < self->fileCount; ++i)
	{
	    CbmdosFile_setAutoMapToLc(self->files[i], autoMapToLc);
	}
    }
    self->autoMapToLc = !!autoMapToLc;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebp
movq %rdi, %rbx
testl %edx, %edx
je 0x7edf
xorl %r14d, %r14d
movl 0x28(%rbx), %eax
cmpq %rax, %r14
jae 0x7edf
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rdi
movl %ebp, %esi
callq 0x50d0
incq %r14
jmp 0x7ec3
xorl %eax, %eax
testl %ebp, %ebp
setne %al
movl %eax, 0x10(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfs.c
// Function: CbmdosVfs_destroy
SOEXPORT void CbmdosVfs_destroy(CbmdosVfs *self)
{
    if (!self) return;
    for (unsigned pos = 0; pos < self->fileCount; ++pos)
    {
        CbmdosFile_destroy(self->files[pos]);
    }
    Event_destroy(self->changedEvent);
    free(self->files);
    free(self->name);
    free(self->id);
    free(self);
}

// Assembly:
testq %rdi, %rdi
je 0x7f4e
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorl %r14d, %r14d
movl 0x28(%rbx), %eax
cmpq %rax, %r14
jae 0x7f1c
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x50e0
incq %r14
jmp 0x7f02
movq 0x20(%rbx), %rdi
callq 0x5170
movq 0x18(%rbx), %rdi
callq 0x5080
movq (%rbx), %rdi
callq 0x5080
movq 0x8(%rbx), %rdi
callq 0x5080
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x5080
retq
nop
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfsreader.c
// Function: parseTrackBam
static int parseTrackBam(uint8_t *bamdata, uint8_t sectors,
	const uint8_t *trackbam)
{
    uint8_t tmp[21] = {0};
    uint8_t sectfree = 0;
    for (uint8_t sectno = 0; sectno < sectors; ++sectno)
    {
	if (trackbam[1+sectno/8] & (1U << (sectno%8)))
	{
	    ++sectfree;
	}
	else
	{
	    tmp[sectno] = 1;
	}
    }
    if (bamdata) memcpy(bamdata, tmp, 21);
    if (sectfree != trackbam[0]) return -1;
    return 0;
}

// Assembly:
xorps %xmm0, %xmm0
movaps %xmm0, -0x18(%rsp)
andq $0x0, -0xb(%rsp)
movl %esi, %eax
xorl %esi, %esi
xorl %ecx, %ecx
cmpq %rsi, %rax
je 0x8836
movl %esi, %r8d
shrl $0x3, %r8d
movzbl 0x1(%rdx,%r8), %r8d
movl %esi, %r9d
andl $0x7, %r9d
btl %r9d, %r8d
jae 0x882c
incb %cl
jmp 0x8831
movb $0x1, -0x18(%rsp,%rsi)
incq %rsi
jmp 0x8809
testq %rdi, %rdi
je 0x884c
movq -0xb(%rsp), %rax
movq %rax, 0xd(%rdi)
movaps -0x18(%rsp), %xmm0
movups %xmm0, (%rdi)
xorl %eax, %eax
cmpb (%rdx), %cl
setne %al
negl %eax
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/cbmdosvfsreader.c
// Function: readCbmdosVfs
SOEXPORT int readCbmdosVfs(CbmdosVfs *vfs, const D64 *d64,
	const CbmdosFsOptions *options)
{
    CbmdosFsOptions probeopts = CFO_DEFAULT;
    if (!options)
    {
	if (probeCbmdosFsOptions(&probeopts, d64) < 0) return -1;
	options = &probeopts;
    }
    return readCbmdosVfsInternal(vfs, d64, options, 0, 0);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movq 0xa771(%rip), %rax      # 0x12fe0
movq (%rax), %rax
movq %rax, 0x8(%rsp)
testq %rdx, %rdx
jne 0x8890
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5390
testl %eax, %eax
js 0x88ad
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x7f50
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
pushq $-0x1
popq %rax
jmp 0x88a3
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/d64reader.c
// Function: readD64FromFileData
SOEXPORT D64 *readD64FromFileData(const FileData *file)
{
    size_t size = FileData_size(file);
    D64Type type;

    switch (size)
    {
        case 174848UL:
        case 175531UL:
            type = D64_STANDARD;
            break;
        case 196608UL:
        case 197376UL:
            type = D64_40TRACK;
            break;
        case 205312UL:
        case 206114UL:
            type = D64_42TRACK;
            break;
        default:
            logmsg(L_WARNING, "readD64FromFileData: not a valid D64 file.");
            return 0;
    }

    D64 *d64 = D64_create(type);
    const uint8_t *bytes = FileData_rcontent(file);
    uint8_t tracks = D64_tracks(d64);
    for (uint8_t trackno = 1; trackno <= tracks; ++trackno)
    {
        Track *track = D64_track(d64, trackno);
        uint8_t sectors = Track_sectors(track);
        for (uint8_t sectno = 0; sectno < sectors; ++sectno)
        {
            uint8_t *sectbytes = Sector_content(Track_sector(track, sectno));
            memcpy(sectbytes, bytes, 256);
            bytes += 256;
        }
    }
    return d64;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
callq 0x5530
xorl %edi, %edi
cmpq $0x2ab00, %rax          # imm = 0x2AB00
je 0x8fe4
cmpq $0x2adab, %rax          # imm = 0x2ADAB
je 0x8fe4
cmpq $0x30000, %rax          # imm = 0x30000
je 0x8fdd
cmpq $0x32522, %rax          # imm = 0x32522
je 0x8fe1
cmpq $0x32200, %rax          # imm = 0x32200
je 0x8fe1
cmpq $0x30300, %rax          # imm = 0x30300
jne 0x9062
pushq $0x1
jmp 0x8fe3
pushq $0x2
popq %rdi
callq 0x55f0
movq %rax, %rbx
movq %r14, %rdi
callq 0x5680
movq %rax, %r14
movq %rbx, (%rsp)
movq %rbx, %rdi
callq 0x5620
movl %eax, %ebp
movb $0x1, %r13b
cmpb %bpl, %r13b
ja 0x9079
movzbl %r13b, %esi
movq (%rsp), %rdi
callq 0x5290
movq %rax, %r15
movq %rax, %rdi
callq 0x5780
movl %eax, %r12d
xorl %ebx, %ebx
cmpb %bl, %r12b
je 0x905d
movzbl %bl, %esi
movq %r15, %rdi
callq 0x5090
movq %rax, %rdi
callq 0x56d0
movl $0x100, %edx            # imm = 0x100
movq %rax, %rdi
movq %r14, %rsi
callq 0x54a0
addq $0x100, %r14            # imm = 0x100
incb %bl
jmp 0x902a
incb %r13b
jmp 0x9008
leaq 0x4e0c(%rip), %rsi      # 0xde75
pushq $0x2
popq %rdi
callq 0x5960
movq $0x0, (%rsp)
movq (%rsp), %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/d64reader.c
// Function: readD64
SOEXPORT D64 *readD64(FILE *file)
{
    FileData *data = readHostFile(file);
    if (!data)
    {
        logmsg(L_WARNING, "readD64: error reading file.");
        return 0;
    }

    D64 *d64 = readD64FromFileData(data);
    FileData_destroy(data);
    return d64;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
callq 0x52e0
testq %rax, %rax
je 0x90b5
movq %rax, %rbx
movq %rax, %rdi
callq 0x5210
movq %rax, %r14
movq %rbx, %rdi
callq 0x53f0
movq %r14, %rax
jmp 0x90c6
leaq 0x4de4(%rip), %rsi      # 0xdea0
pushq $0x2
popq %rdi
callq 0x5960
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/zc45compressor.c
// Function: compressZc45
SOEXPORT ZcFileSet *compressZc45(const D64 *d64)
{
    char name[17];
    uint8_t buf[MAXZCFILESIZE];
    if (!d64) return 0;
    D64Type type = D64_type(d64);
    const uint8_t *bam = Sector_rcontent(D64_rsector(d64, 18, 0));
    int namelen = 16;
    while (namelen && bam[0x8f + namelen] == 0xa0) --namelen;
    memcpy(name, bam+0x90, namelen);
    name[namelen] = 0;

    ZcFileSet *compressed = ZcFileSet_create(
            type == D64_STANDARD ? ZT_4PACK : ZT_5PACK, name);

    for (int i = 0; i < (type == D64_STANDARD ? 4 : 5); ++i)
    {
        size_t filelen = zc45_write(buf, MAXZCFILESIZE, i+1, d64);
        if (!filelen)
        {
            logfmt(L_ERROR, "compressZc45: compression failed in part %d.",
                    i+1);
            ZcFileSet_destroy(compressed);
            return 0;
        }
        FileData *fd = ZcFileSet_fileData(compressed, i);
        if (FileData_append(fd, buf, filelen) < 0)
        {
            logfmt(L_ERROR, "compressZc45: compression failed in part %d.",
                    i+1);
            ZcFileSet_destroy(compressed);
            return 0;
        }
    }

    logfmt(L_DEBUG, "compressZc45: %d-file zipcode successfully created.",
            type == D64_40TRACK ? 5 : 4);
    return compressed;
}

// Assembly:
testq %rdi, %rdi
je 0x9608
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb098, %rsp           # imm = 0xB098
movq %rdi, %rbx
callq 0x5460
movl %eax, %ebp
pushq $0x12
popq %rsi
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %edx, %edx
callq 0x50c0
movq %rax, %rdi
callq 0x56b0
cmpq $-0x10, %r15
je 0x956e
cmpb $-0x60, 0x9f(%rax,%r15)
jne 0x956e
decq %r15
jmp 0x9558
addq $0x90, %rax
leaq 0x10(%r15), %rdx
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x54a0
movb $0x0, 0x20(%rsp,%r15)
xorl %r15d, %r15d
movl %ebp, 0xc(%rsp)
testl %ebp, %ebp
setne %r15b
movl %r15d, %edi
movq %r14, %rsi
callq 0x5200
movq %rax, (%rsp)
orl $0x4, %r15d
xorl %r13d, %r13d
leaq 0x30(%rsp), %r12
cmpl %r13d, %r15d
je 0x960b
leal 0x1(%r13), %ebp
movl $0xb060, %esi           # imm = 0xB060
movq %r12, %rdi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x5220
testq %rax, %rax
je 0x962f
movq %rax, %r14
movq (%rsp), %rdi
movl %r13d, %esi
callq 0x5770
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5760
movl %ebp, %r13d
testl %eax, %eax
jns 0x95b6
leaq 0x4a44(%rip), %rsi      # 0xe045
pushq $0x1
popq %rdi
movl %ebp, %edx
jmp 0x963f
xorl %eax, %eax
retq
xorl %edx, %edx
cmpl $0x1, 0xc(%rsp)
sete %dl
orl $0x4, %edx
leaq 0x4a53(%rip), %rsi      # 0xe072
pushq $0x4
popq %rdi
xorl %eax, %eax
callq 0x598d
movq (%rsp), %rax
jmp 0x9651
incl %r13d
leaq 0x4a0c(%rip), %rsi      # 0xe045
pushq $0x1
popq %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x598d
movq (%rsp), %rdi
callq 0x5790
xorl %eax, %eax
addq $0xb098, %rsp           # imm = 0xB098
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/event.c
// Function: Event_create
SOEXPORT Event *Event_create(int id, const void *sender)
{
    Event *self = xmalloc(sizeof *self);
    self->sender = sender;
    self->handlers = 0;
    self->size = 0;
    self->capa = 0;
    self->id = id;
    return self;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edi, %ebp
pushq $0x28
popq %rdi
callq 0x589c
movq %rbx, (%rax)
andq $0x0, 0x18(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movl %ebp, 0x20(%rax)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/event.c
// Function: Event_register
SOEXPORT void Event_register(Event *self, void *receiver, EventHandler handler)
{
    if (self->size == self->capa)
    {
        self->capa += EVCHUNKSIZE;
        self->handlers = xrealloc(self->handlers,
                self->capa * sizeof *self->handlers);
    }
    self->handlers[self->size].receiver = receiver;
    self->handlers[self->size].handler = handler;
    ++self->size;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq 0x10(%rdi), %rsi
cmpq 0x18(%rdi), %rsi
jne 0x96c4
addq $0x4, %rsi
movq %rsi, 0x18(%rbx)
movq 0x8(%rbx), %rdi
shlq $0x4, %rsi
callq 0x58bc
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rsi
jmp 0x96c8
movq 0x8(%rbx), %rax
movq %rsi, %rcx
shlq $0x4, %rcx
movq %r15, (%rax,%rcx)
movq %r14, 0x8(%rax,%rcx)
incq %rsi
movq %rsi, 0x10(%rbx)
popq %rbx
popq %r14
popq %r15
retq