// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0xb0d0, %rsp           # imm = 0xB0D0
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xc723
movq $0x0, -0x8(%rbp)
jmp 0xc944
movq -0x10(%rbp), %rdi
callq 0x5480
movl %eax, -0xb094(%rbp)
movq -0x10(%rbp), %rdi
movl $0x12, %esi
xorl %edx, %edx
callq 0x50c0
movq %rax, %rdi
callq 0x56d0
movq %rax, -0xb0a0(%rbp)
movl $0x10, -0xb0a4(%rbp)
xorl %eax, %eax
cmpl $0x0, -0xb0a4(%rbp)
movb %al, -0xb0c9(%rbp)
je 0xc794
movq -0xb0a0(%rbp), %rax
movl -0xb0a4(%rbp), %ecx
addl $0x8f, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xa0, %eax
sete %al
movb %al, -0xb0c9(%rbp)
movb -0xb0c9(%rbp), %al
testb $0x1, %al
jne 0xc7a0
jmp 0xc7b1
movl -0xb0a4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xb0a4(%rbp)
jmp 0xc75b
leaq -0x30(%rbp), %rdi
movq -0xb0a0(%rbp), %rsi
addq $0x90, %rsi
movslq -0xb0a4(%rbp), %rdx
callq 0x54c0
movslq -0xb0a4(%rbp), %rax
movb $0x0, -0x30(%rbp,%rax)
movl -0xb094(%rbp), %ecx
movl $0x1, %edi
xorl %eax, %eax
cmpl $0x0, %ecx
cmovel %eax, %edi
leaq -0x30(%rbp), %rsi
callq 0x5210
movq %rax, -0xb0b0(%rbp)
movl $0x0, -0xb0b4(%rbp)
movl -0xb0b4(%rbp), %eax
movl -0xb094(%rbp), %esi
movl $0x5, %ecx
movl $0x4, %edx
cmpl $0x0, %esi
cmovel %edx, %ecx
cmpl %ecx, %eax
jge 0xc910
leaq -0xb090(%rbp), %rdi
movl -0xb0b4(%rbp), %edx
addl $0x1, %edx
movq -0x10(%rbp), %rcx
movl $0xb060, %esi           # imm = 0xB060
callq 0x5230
movq %rax, -0xb0c0(%rbp)
cmpq $0x0, -0xb0c0(%rbp)
jne 0xc890
movl -0xb0b4(%rbp), %edx
addl $0x1, %edx
movl $0x1, %edi
leaq 0x7805(%rip), %rsi      # 0x14075
movb $0x0, %al
callq 0x5ab0
movq -0xb0b0(%rbp), %rdi
callq 0x57c0
movq $0x0, -0x8(%rbp)
jmp 0xc944
movq -0xb0b0(%rbp), %rdi
movl -0xb0b4(%rbp), %esi
callq 0x57a0
movq %rax, -0xb0c8(%rbp)
movq -0xb0c8(%rbp), %rdi
leaq -0xb090(%rbp), %rsi
movq -0xb0c0(%rbp), %rdx
callq 0x5790
cmpl $0x0, %eax
jge 0xc8fa
movl -0xb0b4(%rbp), %edx
addl $0x1, %edx
movl $0x1, %edi
leaq 0x7798(%rip), %rsi      # 0x14075
movb $0x0, %al
callq 0x5ab0
movq -0xb0b0(%rbp), %rdi
callq 0x57c0
movq $0x0, -0x8(%rbp)
jmp 0xc944
jmp 0xc8fc
movl -0xb0b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb0b4(%rbp)
jmp 0xc808
movl -0xb094(%rbp), %ecx
movl $0x4, %edx
movl $0x5, %eax
cmpl $0x1, %ecx
cmovel %eax, %edx
movl $0x4, %edi
leaq 0x7770(%rip), %rsi      # 0x140a2
movb $0x0, %al
callq 0x5ab0
movq -0xb0b0(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0d0, %rsp           # imm = 0xB0D0
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)