// File: /workspace/github_c_makefile_star2_O0/excess-c64[P]lib1541img/src/lib/1541img/zc45reader.c
// Function: decodesector
static int decodesector(D64 *d64, const uint8_t *zcfile,
	size_t *pos, size_t zcfilelen)
{
    int control = nextbyte(zcfile, pos, zcfilelen);
    if (control < 0)
    {
        logmsg(L_ERROR, "zc45_read: unexpected end of file trying to read "
                "next track number.");
        return -1;
    }
    uint8_t tracknum = control & 0x3f;
    int sectornum = nextbyte(zcfile, pos, zcfilelen);
    if (sectornum < 0)
    {
        logmsg(L_ERROR, "zc45_read: unexpected end of file trying to read "
                "next sector number.");
        return -1;
    }
    logsetsilent(1);
    Sector *sector = D64_sector(d64, tracknum, sectornum);
    logsetsilent(0);
    if (!sector)
    {
        logfmt(L_ERROR, "zc45_read: Invalid sector %hhu:%hhu found.",
                tracknum, sectornum);
	return -1;
    }
    uint8_t *data = Sector_content(sector);

    switch ((unsigned)control >> 6)
    {
	case 0:
            logfmt(L_DEBUG, "zc45_read: processing sector %hhu:%hhu (plain)",
                    tracknum, sectornum);
	    return decodeplain(data, zcfile, pos, zcfilelen);
	case 1:
            logfmt(L_DEBUG, "zc45_read: processing sector %hhu:%hhu (fill)",
                    tracknum, sectornum);
	    return decodefill(data, zcfile, pos, zcfilelen);
	case 2:
            logfmt(L_DEBUG, "zc45_read: processing sector %hhu:%hhu (rle)",
                    tracknum, sectornum);
	    return decoderle(data, zcfile, pos, zcfilelen);
	default:
            logfmt(L_ERROR, "zc45_read: invalid encoding for sector %hhu:%hhu.",
                    tracknum, sectornum);
	    return -1;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x66e0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x653f
movl $0x1, %edi
leaq 0xcc8e(%rip), %rsi      # 0x131bc
callq 0x5a60
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x66c9
movl -0x2c(%rbp), %eax
andl $0x3f, %eax
movb %al, -0x2d(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x66e0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x657f
movl $0x1, %edi
leaq 0xcc92(%rip), %rsi      # 0x13200
callq 0x5a60
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x66c9
movl $0x1, %edi
callq 0x5ba0
movq -0x10(%rbp), %rdi
movb -0x2d(%rbp), %cl
movl -0x34(%rbp), %eax
movzbl %cl, %esi
movzbl %al, %edx
callq 0x5030
movq %rax, -0x40(%rbp)
xorl %edi, %edi
callq 0x5ba0
cmpq $0x0, -0x40(%rbp)
jne 0x65d6
movzbl -0x2d(%rbp), %edx
movl -0x34(%rbp), %ecx
movl $0x1, %edi
leaq 0xcc82(%rip), %rsi      # 0x13245
movb $0x0, %al
callq 0x5ab0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x66c9
movq -0x40(%rbp), %rdi
callq 0x56f0
movq %rax, -0x48(%rbp)
movl -0x2c(%rbp), %eax
shrl $0x6, %eax
movl %eax, -0x4c(%rbp)
testl %eax, %eax
je 0x6609
jmp 0x65f2
movl -0x4c(%rbp), %eax
subl $0x1, %eax
je 0x6640
jmp 0x65fc
movl -0x4c(%rbp), %eax
subl $0x2, %eax
je 0x6674
jmp 0x66a8
movzbl -0x2d(%rbp), %edx
movl -0x34(%rbp), %ecx
movl $0x4, %edi
leaq 0xcc54(%rip), %rsi      # 0x13270
movb $0x0, %al
callq 0x5ab0
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x6730
movl %eax, -0x4(%rbp)
jmp 0x66c9
movzbl -0x2d(%rbp), %edx
movl -0x34(%rbp), %ecx
movl $0x4, %edi
leaq 0xcc4c(%rip), %rsi      # 0x1329f
movb $0x0, %al
callq 0x5ab0
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x67c0
movl %eax, -0x4(%rbp)
jmp 0x66c9
movzbl -0x2d(%rbp), %edx
movl -0x34(%rbp), %ecx
movl $0x4, %edi
leaq 0xcc46(%rip), %rsi      # 0x132cd
movb $0x0, %al
callq 0x5ab0
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x6850
movl %eax, -0x4(%rbp)
jmp 0x66c9
movzbl -0x2d(%rbp), %edx
movl -0x34(%rbp), %ecx
movl $0x1, %edi
leaq 0xcc3f(%rip), %rsi      # 0x132fa
movb $0x0, %al
callq 0x5ab0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)