static int rle_unpack(const unsigned char *src, unsigned char *dest,

                      int src_count, int src_size, int dest_len)

{

    unsigned char *pd;

    int i, l;

    unsigned char *dest_end = dest + dest_len;

    GetByteContext gb;



    bytestream2_init(&gb, src, src_size);

    pd = dest;

    if (src_count & 1) {

        if (bytestream2_get_bytes_left(&gb) < 1)

            return 0;

        *pd++ = bytestream2_get_byteu(&gb);

    }



    src_count >>= 1;

    i = 0;

    do {

        if (bytestream2_get_bytes_left(&gb) < 1)

            break;

        l = bytestream2_get_byteu(&gb);

        if (l & 0x80) {

            l = (l & 0x7F) * 2;

            if (dest_end - pd < l || bytestream2_get_bytes_left(&gb) < l)

                return bytestream2_tell(&gb);

            bytestream2_get_bufferu(&gb, pd, l);

            pd += l;

        } else {

            if (dest_end - pd < i || bytestream2_get_bytes_left(&gb) < 2)

                return bytestream2_tell(&gb);

            for (i = 0; i < l; i++) {

                *pd++ = bytestream2_get_byteu(&gb);

                *pd++ = bytestream2_get_byteu(&gb);

            }

            bytestream2_skip(&gb, 2);

        }

        i += l;

    } while (i < src_count);



    return bytestream2_tell(&gb);

}

static int rle_unpack(const unsigned char *src, unsigned char *dest,

                      int src_count, int src_size, int dest_len)

{

    unsigned char *pd;

    int i, l;

    unsigned char *dest_end = dest + dest_len;

    GetByteContext gb;



    bytestream2_init(&gb, src, src_size);

    pd = dest;

    if (src_count & 1) {

        if (bytestream2_get_bytes_left(&gb) < 1)

            return 0;

        *pd++ = bytestream2_get_byteu(&gb);

    }



    src_count >>= 1;

    i = 0;

    do {

        if (bytestream2_get_bytes_left(&gb) < 1)

            break;

        l = bytestream2_get_byteu(&gb);

        if (l & 0x80) {

            l = (l & 0x7F) * 2;

            if (dest_end - pd < l || bytestream2_get_bytes_left(&gb) < l)

                return bytestream2_tell(&gb);

            bytestream2_get_bufferu(&gb, pd, l);

            pd += l;

        } else {

            if (dest_end - pd < i || bytestream2_get_bytes_left(&gb) < 2)

                return bytestream2_tell(&gb);

            for (i = 0; i < l; i++) {

                *pd++ = bytestream2_get_byteu(&gb);

                *pd++ = bytestream2_get_byteu(&gb);

            }

            bytestream2_skip(&gb, 2);

        }

        i += l;

    } while (i < src_count);



    return bytestream2_tell(&gb);

}

static int FUNC_0(const unsigned char *VAR_0, unsigned char *VAR_1,

                      int VAR_2, int VAR_3, int VAR_4)

{

    unsigned char *VAR_5;

    int VAR_6, VAR_7;

    unsigned char *VAR_8 = VAR_1 + VAR_4;

    GetByteContext gb;



    bytestream2_init(&gb, VAR_0, VAR_3);

    VAR_5 = VAR_1;

    if (VAR_2 & 1) {

        if (bytestream2_get_bytes_left(&gb) < 1)

            return 0;

        *VAR_5++ = bytestream2_get_byteu(&gb);

    }



    VAR_2 >>= 1;

    VAR_6 = 0;

    do {

        if (bytestream2_get_bytes_left(&gb) < 1)

            break;

        VAR_7 = bytestream2_get_byteu(&gb);

        if (VAR_7 & 0x80) {

            VAR_7 = (VAR_7 & 0x7F) * 2;

            if (VAR_8 - VAR_5 < VAR_7 || bytestream2_get_bytes_left(&gb) < VAR_7)

                return bytestream2_tell(&gb);

            bytestream2_get_bufferu(&gb, VAR_5, VAR_7);

            VAR_5 += VAR_7;

        } else {

            if (VAR_8 - VAR_5 < VAR_6 || bytestream2_get_bytes_left(&gb) < 2)

                return bytestream2_tell(&gb);

            for (VAR_6 = 0; VAR_6 < VAR_7; VAR_6++) {

                *VAR_5++ = bytestream2_get_byteu(&gb);

                *VAR_5++ = bytestream2_get_byteu(&gb);

            }

            bytestream2_skip(&gb, 2);

        }

        VAR_6 += VAR_7;

    } while (VAR_6 < VAR_2);



    return bytestream2_tell(&gb);

}

static int FUNC_0(const unsigned char *VAR_0, unsigned char *VAR_1,
int VAR_2, int VAR_3, int VAR_4)
{ unsigned char *VAR_5; int VAR_6, VAR_7; unsigned char *VAR_8 = VAR_1 + VAR_4; GetByteContext gb; bytestream2_init(&gb, VAR_0, VAR_3); VAR_5 = VAR_1; if (VAR_2 & 1) { if (bytestream2_get_bytes_left(&gb) < 1)
return 0; *VAR_5++ = bytestream2_get_byteu(&gb); } VAR_2 >>= 1; VAR_6 = 0; do { if (bytestream2_get_bytes_left(&gb) < 1)
break; VAR_7 = bytestream2_get_byteu(&gb); if (VAR_7 & 0x80) { VAR_7 = (VAR_7 & 0x7F) * 2; if (VAR_8 - VAR_5 < VAR_7 || bytestream2_get_bytes_left(&gb) < VAR_7)
return bytestream2_tell(&gb); bytestream2_get_bufferu(&gb, VAR_5, VAR_7); VAR_5 += VAR_7; } else { if (VAR_8 - VAR_5 < VAR_6 || bytestream2_get_bytes_left(&gb) < 2)
return bytestream2_tell(&gb); for (VAR_6 = 0; VAR_6 < VAR_7; VAR_6++) { *VAR_5++ = bytestream2_get_byteu(&gb); *VAR_5++ = bytestream2_get_byteu(&gb); } bytestream2_skip(&gb, 2); } VAR_6 += VAR_7; } while (VAR_6 < VAR_2); return bytestream2_tell(&gb); }