int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen)

{

    int i = 0, d = 0;

    int ret;

    uint32_t count = 0;



    while (i < slen) {



        /* zrun */

        if ((slen - i) < 2) {

            return -1;

        }



        ret = uleb128_decode_small(src + i, &count);

        if (ret < 0 || (i && !count)) {

            return -1;

        }

        i += ret;

        d += count;



        /* overflow */

        if (d > dlen) {

            return -1;

        }



        /* nzrun */

        if ((slen - i) < 2) {

            return -1;

        }



        ret = uleb128_decode_small(src + i, &count);

        if (ret < 0 || !count) {

            return -1;

        }

        i += ret;



        /* overflow */

        if (d + count > dlen || i + count > slen) {

            return -1;

        }



        memcpy(dst + d, src + i, count);

        d += count;

        i += count;

    }



    return d;

}

int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen)

{

    int i = 0, d = 0;

    int ret;

    uint32_t count = 0;



    while (i < slen) {



        

        if ((slen - i) < 2) {

            return -1;

        }



        ret = uleb128_decode_small(src + i, &count);

        if (ret < 0 || (i && !count)) {

            return -1;

        }

        i += ret;

        d += count;



        

        if (d > dlen) {

            return -1;

        }



        

        if ((slen - i) < 2) {

            return -1;

        }



        ret = uleb128_decode_small(src + i, &count);

        if (ret < 0 || !count) {

            return -1;

        }

        i += ret;



        

        if (d + count > dlen || i + count > slen) {

            return -1;

        }



        memcpy(dst + d, src + i, count);

        d += count;

        i += count;

    }



    return d;

}

int FUNC_0(uint8_t *VAR_0, int VAR_1, uint8_t *VAR_2, int VAR_3)

{

    int VAR_4 = 0, VAR_5 = 0;

    int VAR_6;

    uint32_t count = 0;



    while (VAR_4 < VAR_1) {



        

        if ((VAR_1 - VAR_4) < 2) {

            return -1;

        }



        VAR_6 = uleb128_decode_small(VAR_0 + VAR_4, &count);

        if (VAR_6 < 0 || (VAR_4 && !count)) {

            return -1;

        }

        VAR_4 += VAR_6;

        VAR_5 += count;



        

        if (VAR_5 > VAR_3) {

            return -1;

        }



        

        if ((VAR_1 - VAR_4) < 2) {

            return -1;

        }



        VAR_6 = uleb128_decode_small(VAR_0 + VAR_4, &count);

        if (VAR_6 < 0 || !count) {

            return -1;

        }

        VAR_4 += VAR_6;



        

        if (VAR_5 + count > VAR_3 || VAR_4 + count > VAR_1) {

            return -1;

        }



        memcpy(VAR_2 + VAR_5, VAR_0 + VAR_4, count);

        VAR_5 += count;

        VAR_4 += count;

    }



    return VAR_5;

}

int FUNC_0(uint8_t *VAR_0, int VAR_1, uint8_t *VAR_2, int VAR_3)
{ int VAR_4 = 0, VAR_5 = 0; int VAR_6; uint32_t count = 0; while (VAR_4 < VAR_1) { if ((VAR_1 - VAR_4) < 2) { return -1; } VAR_6 = uleb128_decode_small(VAR_0 + VAR_4, &count); if (VAR_6 < 0 || (VAR_4 && !count)) { return -1; } VAR_4 += VAR_6; VAR_5 += count; if (VAR_5 > VAR_3) { return -1; } if ((VAR_1 - VAR_4) < 2) { return -1; } VAR_6 = uleb128_decode_small(VAR_0 + VAR_4, &count); if (VAR_6 < 0 || !count) { return -1; } VAR_4 += VAR_6; if (VAR_5 + count > VAR_3 || VAR_4 + count > VAR_1) { return -1; } memcpy(VAR_2 + VAR_5, VAR_0 + VAR_4, count); VAR_5 += count; VAR_4 += count; } return VAR_5; }