private static int Decompress(byte[] input, uint offset, int end, byte[] output) {
uint oidx = 0;
do {
uint ctrl = input[offset++];
if (ctrl < 1 << 5) {
ctrl++;
do {
output[oidx++] = input[offset++];
} while (--ctrl != 0);
} else {
var len = ctrl >> 5;
var reference = (int)(oidx - ((ctrl & 0x1f) << 8) - 1);
if (len == 7) len += input[offset++];
reference -= input[offset++];
output[oidx++] = output[reference++];
output[oidx++] = output[reference++];
do {
output[oidx++] = output[reference++];
} while (--len != 0);
}
} while (offset < end);
return (int)oidx;
}