// File: /workspace/github_c_makefile_star2_O0/excess-c64[P]lib1541img/src/lib/1541img/zc45writer.c
// Function: writeSector
static int writeSector(uint8_t *zcfile, size_t zcfilelen, size_t *wpos,
        uint8_t trackno, const Track *track, uint8_t sectno)
{
    const uint8_t *data = Sector_rcontent(Track_rsector(track, sectno));
    uint8_t rlelen;
    uint8_t repcode;
    enum method met = getMethod(data, &rlelen, &repcode);
    if (writebyte(zcfile, wpos, zcfilelen, trackno | (met<<6) ) < 0)
    {
        return -1;
    }
    if (writebyte(zcfile, wpos, zcfilelen, sectno) < 0)
    {
        return -1;
    }
    switch (met)
    {
        case M_PLAIN:
            logfmt(L_DEBUG, "zc45_write: processing sector %hhu:%hhu (plain)",
                    trackno, sectno);
            return writePlain(zcfile, zcfilelen, wpos, data);
        case M_FILL:
            logfmt(L_DEBUG, "zc45_write: processing sector %hhu:%hhu (fill)",
                    trackno, sectno);
            return writebyte(zcfile, wpos, zcfilelen, *data);
        case M_RLE:
            logfmt(L_DEBUG, "zc45_write: processing sector %hhu:%hhu (rle)",
                    trackno, sectno);
            return writeRle(zcfile, zcfilelen, wpos, data, rlelen, repcode);
    }
    return -1; // unreachable
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %r9b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movb %cl, -0x21(%rbp)
movq %r8, -0x30(%rbp)
movb %al, -0x31(%rbp)
movq -0x30(%rbp), %rdi
movzbl -0x31(%rbp), %esi
callq 0x54d0
movq %rax, %rdi
callq 0x56d0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x41(%rbp), %rsi
leaq -0x42(%rbp), %rdx
callq 0xc380
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
movzbl -0x21(%rbp), %eax
movl -0x48(%rbp), %ecx
shll $0x6, %ecx
orl %ecx, %eax
movzbl %al, %ecx
callq 0xbfe0
cmpl $0x0, %eax
jge 0xc1df
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xc2e0
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
movzbl -0x31(%rbp), %ecx
callq 0xbfe0
cmpl $0x0, %eax
jge 0xc205
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xc2e0
movl -0x48(%rbp), %eax
movl %eax, -0x4c(%rbp)
testl %eax, %eax
je 0xc228
jmp 0xc211
movl -0x4c(%rbp), %eax
subl $0x1, %eax
je 0xc260
jmp 0xc21b
movl -0x4c(%rbp), %eax
subl $0x2, %eax
je 0xc298
jmp 0xc2d9
movzbl -0x21(%rbp), %edx
movzbl -0x31(%rbp), %ecx
movl $0x4, %edi
leaq 0x7d63(%rip), %rsi      # 0x13f9f
movb $0x0, %al
callq 0x5ab0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x40(%rbp), %rcx
callq 0xc4f0
movl %eax, -0x4(%rbp)
jmp 0xc2e0
movzbl -0x21(%rbp), %edx
movzbl -0x31(%rbp), %ecx
movl $0x4, %edi
leaq 0x7d5b(%rip), %rsi      # 0x13fcf
movb $0x0, %al
callq 0x5ab0
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x40(%rbp), %rax
movzbl (%rax), %ecx
callq 0xbfe0
movl %eax, -0x4(%rbp)
jmp 0xc2e0
movzbl -0x21(%rbp), %edx
movzbl -0x31(%rbp), %ecx
movl $0x4, %edi
leaq 0x7d52(%rip), %rsi      # 0x13ffe
movb $0x0, %al
callq 0x5ab0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x40(%rbp), %rcx
movb -0x41(%rbp), %al
movzbl %al, %r8d
movzbl -0x42(%rbp), %r9d
callq 0xc560
movl %eax, -0x4(%rbp)
jmp 0xc2e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)