// File: /workspace/github_c_makefile_star2_O0/excess-c64[P]lib1541img/src/lib/1541img/zc45reader.c
// Function: decoderle
static int decoderle(uint8_t *data, const uint8_t *zcfile,
	size_t *pos, size_t zcfilelen)
{
    int i = 0;
    int len = nextbyte(zcfile, pos, zcfilelen);
    if (len < 0)
    {
        logmsg(L_ERROR, "zc45_read: unexpected end of file trying to read "
                "length of RLE encoded sector.");
        return -1;
    }
    int repeat = nextbyte(zcfile, pos, zcfilelen);
    if (repeat < 0)
    {
        logmsg(L_ERROR, "zc45_read: unexpected end of file trying to read "
                "repeat marker of RLE encoded sector.");
        return -1;
    }
    while (i < SECTOR_SIZE)
    {
	int byte = nextbyte(zcfile, pos, zcfilelen);
	if (byte < 0)
        {
            logmsg(L_ERROR, "zc45_read: unexpected end of file in RLE encoded "
                    "sector.");
            return -1;
        }
	if (byte == repeat)
	{
	    int repcount = nextbyte(zcfile, pos, zcfilelen);
	    if (repcount < 0)
            {
                logmsg(L_ERROR, "zc45_read: unexpected end of file trying to "
                        "read repeat count of sequence.");
                return -1;
            }
	    int repbyte = nextbyte(zcfile, pos, zcfilelen);
	    if (repbyte < 0)
            {
                logmsg(L_ERROR, "zc45_read: unexpected end of file trying to "
                        "read fill value of sequence.");
                return -1;
            }
	    for (int j = 0; j < repcount; ++j)
	    {
		data[i++] = repbyte;
		if (i == SECTOR_SIZE && j+1 < repcount)
                {
                    logmsg(L_WARNING, "zc45_read: end of sector reached while "
                            "filling sequence in RLE encoded sector.");
                    break;
                }
	    }
	}
	else
	{
	    data[i++] = byte;
	}
    }
    return 0;
}

// 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)
movl $0x0, -0x2c(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x66e0
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jge 0x68a6
movl $0x1, %edi
leaq 0xcaff(%rip), %rsi      # 0x13394
callq 0x5a60
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6a22
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x66e0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x68dd
movl $0x1, %edi
leaq 0xcb17(%rip), %rsi      # 0x133e3
callq 0x5a60
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6a22
jmp 0x68df
cmpl $0x100, -0x2c(%rbp)     # imm = 0x100
jge 0x6a1b
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x66e0
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jge 0x6923
movl $0x1, %edi
leaq 0xcb27(%rip), %rsi      # 0x13439
callq 0x5a60
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6a22
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x69fc
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x66e0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x6966
movl $0x1, %edi
leaq 0xcb1d(%rip), %rsi      # 0x13472
callq 0x5a60
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6a22
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x66e0
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jge 0x699d
movl $0x1, %edi
leaq 0xcb31(%rip), %rsi      # 0x134bd
callq 0x5a60
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6a22
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x69fa
movl -0x40(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
cmpl $0x100, -0x2c(%rbp)     # imm = 0x100
jne 0x69ed
movl -0x44(%rbp), %eax
addl $0x1, %eax
cmpl -0x3c(%rbp), %eax
jge 0x69ed
movl $0x2, %edi
leaq 0xcb20(%rip), %rsi      # 0x13506
callq 0x5a60
jmp 0x69fa
jmp 0x69ef
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x69a4
jmp 0x6a16
movl -0x38(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x68df
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)