static int xan_unpack(uint8_t *dest, const int dest_len,

                      const uint8_t *src, const int src_len)

{

    uint8_t opcode;

    int size;

    uint8_t *orig_dest = dest;

    const uint8_t *src_end = src + src_len;

    const uint8_t *dest_end = dest + dest_len;



    while (dest < dest_end) {

        opcode = *src++;



        if (opcode < 0xe0) {

            int size2, back;

            if ((opcode & 0x80) == 0) {

                size  = opcode & 3;

                back  = ((opcode & 0x60) << 3) + *src++ + 1;

                size2 = ((opcode & 0x1c) >> 2) + 3;

            } else if ((opcode & 0x40) == 0) {

                size  = *src >> 6;

                back  = (bytestream_get_be16(&src) & 0x3fff) + 1;

                size2 = (opcode & 0x3f) + 4;

            } else {

                size  = opcode & 3;

                back  = ((opcode & 0x10) << 12) + bytestream_get_be16(&src) + 1;

                size2 = ((opcode & 0x0c) <<  6) + *src++ + 5;

                if (size + size2 > dest_end - dest)

                    break;

            }

            if (src + size > src_end || dest + size + size2 > dest_end ||

                dest - orig_dest + size < back)

                return -1;

            bytestream_get_buffer(&src, dest, size);

            dest += size;

            av_memcpy_backptr(dest, back, size2);

            dest += size2;

        } else {

            int finish = opcode >= 0xfc;



            size = finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4;

            if (src + size > src_end || dest + size > dest_end)

                return -1;

            bytestream_get_buffer(&src, dest, size);

            dest += size;

            if (finish)

                break;

        }

    }

    return dest - orig_dest;

}

static int xan_unpack(uint8_t *dest, const int dest_len,

                      const uint8_t *src, const int src_len)

{

    uint8_t opcode;

    int size;

    uint8_t *orig_dest = dest;

    const uint8_t *src_end = src + src_len;

    const uint8_t *dest_end = dest + dest_len;



    while (dest < dest_end) {

        opcode = *src++;



        if (opcode < 0xe0) {

            int size2, back;

            if ((opcode & 0x80) == 0) {

                size  = opcode & 3;

                back  = ((opcode & 0x60) << 3) + *src++ + 1;

                size2 = ((opcode & 0x1c) >> 2) + 3;

            } else if ((opcode & 0x40) == 0) {

                size  = *src >> 6;

                back  = (bytestream_get_be16(&src) & 0x3fff) + 1;

                size2 = (opcode & 0x3f) + 4;

            } else {

                size  = opcode & 3;

                back  = ((opcode & 0x10) << 12) + bytestream_get_be16(&src) + 1;

                size2 = ((opcode & 0x0c) <<  6) + *src++ + 5;

                if (size + size2 > dest_end - dest)

                    break;

            }

            if (src + size > src_end || dest + size + size2 > dest_end ||

                dest - orig_dest + size < back)

                return -1;

            bytestream_get_buffer(&src, dest, size);

            dest += size;

            av_memcpy_backptr(dest, back, size2);

            dest += size2;

        } else {

            int finish = opcode >= 0xfc;



            size = finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4;

            if (src + size > src_end || dest + size > dest_end)

                return -1;

            bytestream_get_buffer(&src, dest, size);

            dest += size;

            if (finish)

                break;

        }

    }

    return dest - orig_dest;

}

static int xan_unpack(uint8_t *dest, const int dest_len,                       const uint8_t *src, const int src_len)     const uint8_t *src_end = src + src_len;         opcode = *src++;                 back  = ((opcode & 0x60) << 3) + *src++ + 1;                 size  = *src >> 6;                 back  = (bytestream_get_be16(&src) & 0x3fff) + 1;                 back  = ((opcode & 0x10) << 12) + bytestream_get_be16(&src) + 1;                 size2 = ((opcode & 0x0c) <<  6) + *src++ + 5;             if (src + size > src_end || dest + size + size2 > dest_end ||             bytestream_get_buffer(&src, dest, size);             if (src + size > src_end || dest + size > dest_end)             bytestream_get_buffer(&src, dest, size);
static int FUNC_0(uint8_t *VAR_0, const int VAR_1,

                      const uint8_t *VAR_2, const int VAR_3)

{

    uint8_t opcode;

    int VAR_4;

    uint8_t *orig_dest = VAR_0;

    const uint8_t *VAR_5 = VAR_2 + VAR_3;

    const uint8_t *VAR_6 = VAR_0 + VAR_1;



    while (VAR_0 < VAR_6) {

        opcode = *VAR_2++;



        if (opcode < 0xe0) {

            int VAR_7, VAR_8;

            if ((opcode & 0x80) == 0) {

                VAR_4  = opcode & 3;

                VAR_8  = ((opcode & 0x60) << 3) + *VAR_2++ + 1;

                VAR_7 = ((opcode & 0x1c) >> 2) + 3;

            } else if ((opcode & 0x40) == 0) {

                VAR_4  = *VAR_2 >> 6;

                VAR_8  = (bytestream_get_be16(&VAR_2) & 0x3fff) + 1;

                VAR_7 = (opcode & 0x3f) + 4;

            } else {

                VAR_4  = opcode & 3;

                VAR_8  = ((opcode & 0x10) << 12) + bytestream_get_be16(&VAR_2) + 1;

                VAR_7 = ((opcode & 0x0c) <<  6) + *VAR_2++ + 5;

                if (VAR_4 + VAR_7 > VAR_6 - VAR_0)

                    break;

            }

            if (VAR_2 + VAR_4 > VAR_5 || VAR_0 + VAR_4 + VAR_7 > VAR_6 ||

                VAR_0 - orig_dest + VAR_4 < VAR_8)

                return -1;

            bytestream_get_buffer(&VAR_2, VAR_0, VAR_4);

            VAR_0 += VAR_4;

            av_memcpy_backptr(VAR_0, VAR_8, VAR_7);

            VAR_0 += VAR_7;

        } else {

            int VAR_9 = opcode >= 0xfc;



            VAR_4 = VAR_9 ? opcode & 3 : ((opcode & 0x1f) << 2) + 4;

            if (VAR_2 + VAR_4 > VAR_5 || VAR_0 + VAR_4 > VAR_6)

                return -1;

            bytestream_get_buffer(&VAR_2, VAR_0, VAR_4);

            VAR_0 += VAR_4;

            if (VAR_9)

                break;

        }

    }

    return VAR_0 - orig_dest;

}

static int FUNC_0(uint8_t *VAR_0, const int VAR_1,
const uint8_t *VAR_2, const int VAR_3)
{ uint8_t opcode; int VAR_4; uint8_t *orig_dest = VAR_0; const uint8_t *VAR_5 = VAR_2 + VAR_3; const uint8_t *VAR_6 = VAR_0 + VAR_1; while (VAR_0 < VAR_6) { opcode = *VAR_2++; if (opcode < 0xe0) { int VAR_7, VAR_8; if ((opcode & 0x80) == 0) { VAR_4  = opcode & 3; VAR_8  = ((opcode & 0x60) << 3) + *VAR_2++ + 1; VAR_7 = ((opcode & 0x1c) >> 2) + 3; } else if ((opcode & 0x40) == 0) { VAR_4  = *VAR_2 >> 6; VAR_8  = (bytestream_get_be16(&VAR_2) & 0x3fff) + 1; VAR_7 = (opcode & 0x3f) + 4; } else { VAR_4  = opcode & 3; VAR_8  = ((opcode & 0x10) << 12) + bytestream_get_be16(&VAR_2) + 1; VAR_7 = ((opcode & 0x0c) <<  6) + *VAR_2++ + 5; if (VAR_4 + VAR_7 > VAR_6 - VAR_0)
break; } if (VAR_2 + VAR_4 > VAR_5 || VAR_0 + VAR_4 + VAR_7 > VAR_6 ||
VAR_0 - orig_dest + VAR_4 < VAR_8)
return -1; bytestream_get_buffer(&VAR_2, VAR_0, VAR_4); VAR_0 += VAR_4; av_memcpy_backptr(VAR_0, VAR_8, VAR_7); VAR_0 += VAR_7; } else { int VAR_9 = opcode >= 0xfc; VAR_4 = VAR_9 ? opcode & 3 : ((opcode & 0x1f) << 2) + 4; if (VAR_2 + VAR_4 > VAR_5 || VAR_0 + VAR_4 > VAR_6)
return -1; bytestream_get_buffer(&VAR_2, VAR_0, VAR_4); VAR_0 += VAR_4; if (VAR_9)
break; } } return VAR_0 - orig_dest; }