int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,

                         uint8_t *dst, int dlen)

{

    uint32_t zrun_len = 0, nzrun_len = 0;

    int d = 0, i = 0;

    long res, xor;

    uint8_t *nzrun_start = NULL;



    g_assert(!(((uintptr_t)old_buf | (uintptr_t)new_buf | slen) %

               sizeof(long)));



    while (i < slen) {

        /* overflow */

        if (d + 2 > dlen) {

            return -1;

        }



        /* not aligned to sizeof(long) */

        res = (slen - i) % sizeof(long);

        while (res && old_buf[i] == new_buf[i]) {

            zrun_len++;

            i++;

            res--;

        }



        /* word at a time for speed */

        if (!res) {

            while (i < slen &&

                   (*(long *)(old_buf + i)) == (*(long *)(new_buf + i))) {

                i += sizeof(long);

                zrun_len += sizeof(long);

            }



            /* go over the rest */

            while (i < slen && old_buf[i] == new_buf[i]) {

                zrun_len++;

                i++;

            }

        }



        /* buffer unchanged */

        if (zrun_len == slen) {

            return 0;

        }



        /* skip last zero run */

        if (i == slen) {

            return d;

        }



        d += uleb128_encode_small(dst + d, zrun_len);



        zrun_len = 0;

        nzrun_start = new_buf + i;



        /* overflow */

        if (d + 2 > dlen) {

            return -1;

        }

        /* not aligned to sizeof(long) */

        res = (slen - i) % sizeof(long);

        while (res && old_buf[i] != new_buf[i]) {

            i++;

            nzrun_len++;

            res--;

        }



        /* word at a time for speed, use of 32-bit long okay */

        if (!res) {

            /* truncation to 32-bit long okay */

            long mask = (long)0x0101010101010101ULL;

            while (i < slen) {

                xor = *(long *)(old_buf + i) ^ *(long *)(new_buf + i);

                if ((xor - mask) & ~xor & (mask << 7)) {

                    /* found the end of an nzrun within the current long */

                    while (old_buf[i] != new_buf[i]) {

                        nzrun_len++;

                        i++;

                    }

                    break;

                } else {

                    i += sizeof(long);

                    nzrun_len += sizeof(long);

                }

            }

        }



        d += uleb128_encode_small(dst + d, nzrun_len);

        /* overflow */

        if (d + nzrun_len > dlen) {

            return -1;

        }

        memcpy(dst + d, nzrun_start, nzrun_len);

        d += nzrun_len;

        nzrun_len = 0;

    }



    return d;

}

int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,

                         uint8_t *dst, int dlen)

{

    uint32_t zrun_len = 0, nzrun_len = 0;

    int d = 0, i = 0;

    long res, xor;

    uint8_t *nzrun_start = NULL;



    g_assert(!(((uintptr_t)old_buf | (uintptr_t)new_buf | slen) %

               sizeof(long)));



    while (i < slen) {

        

        if (d + 2 > dlen) {

            return -1;

        }



        

        res = (slen - i) % sizeof(long);

        while (res && old_buf[i] == new_buf[i]) {

            zrun_len++;

            i++;

            res--;

        }



        

        if (!res) {

            while (i < slen &&

                   (*(long *)(old_buf + i)) == (*(long *)(new_buf + i))) {

                i += sizeof(long);

                zrun_len += sizeof(long);

            }



            

            while (i < slen && old_buf[i] == new_buf[i]) {

                zrun_len++;

                i++;

            }

        }



        

        if (zrun_len == slen) {

            return 0;

        }



        

        if (i == slen) {

            return d;

        }



        d += uleb128_encode_small(dst + d, zrun_len);



        zrun_len = 0;

        nzrun_start = new_buf + i;



        

        if (d + 2 > dlen) {

            return -1;

        }

        

        res = (slen - i) % sizeof(long);

        while (res && old_buf[i] != new_buf[i]) {

            i++;

            nzrun_len++;

            res--;

        }



        

        if (!res) {

            

            long mask = (long)0x0101010101010101ULL;

            while (i < slen) {

                xor = *(long *)(old_buf + i) ^ *(long *)(new_buf + i);

                if ((xor - mask) & ~xor & (mask << 7)) {

                    

                    while (old_buf[i] != new_buf[i]) {

                        nzrun_len++;

                        i++;

                    }

                    break;

                } else {

                    i += sizeof(long);

                    nzrun_len += sizeof(long);

                }

            }

        }



        d += uleb128_encode_small(dst + d, nzrun_len);

        

        if (d + nzrun_len > dlen) {

            return -1;

        }

        memcpy(dst + d, nzrun_start, nzrun_len);

        d += nzrun_len;

        nzrun_len = 0;

    }



    return d;

}

    long res, xor;             long mask = (long)0x0101010101010101ULL;                 xor = *(long *)(old_buf + i) ^ *(long *)(new_buf + i);
int FUNC_0(uint8_t *VAR_0, uint8_t *VAR_1, int VAR_2,

                         uint8_t *VAR_3, int VAR_4)

{

    uint32_t zrun_len = 0, nzrun_len = 0;

    int VAR_5 = 0, VAR_6 = 0;

    long VAR_7, VAR_8;

    uint8_t *nzrun_start = NULL;



    g_assert(!(((uintptr_t)VAR_0 | (uintptr_t)VAR_1 | VAR_2) %

               sizeof(long)));



    while (VAR_6 < VAR_2) {

        

        if (VAR_5 + 2 > VAR_4) {

            return -1;

        }



        

        VAR_7 = (VAR_2 - VAR_6) % sizeof(long);

        while (VAR_7 && VAR_0[VAR_6] == VAR_1[VAR_6]) {

            zrun_len++;

            VAR_6++;

            VAR_7--;

        }



        

        if (!VAR_7) {

            while (VAR_6 < VAR_2 &&

                   (*(long *)(VAR_0 + VAR_6)) == (*(long *)(VAR_1 + VAR_6))) {

                VAR_6 += sizeof(long);

                zrun_len += sizeof(long);

            }



            

            while (VAR_6 < VAR_2 && VAR_0[VAR_6] == VAR_1[VAR_6]) {

                zrun_len++;

                VAR_6++;

            }

        }



        

        if (zrun_len == VAR_2) {

            return 0;

        }



        

        if (VAR_6 == VAR_2) {

            return VAR_5;

        }



        VAR_5 += uleb128_encode_small(VAR_3 + VAR_5, zrun_len);



        zrun_len = 0;

        nzrun_start = VAR_1 + VAR_6;



        

        if (VAR_5 + 2 > VAR_4) {

            return -1;

        }

        

        VAR_7 = (VAR_2 - VAR_6) % sizeof(long);

        while (VAR_7 && VAR_0[VAR_6] != VAR_1[VAR_6]) {

            VAR_6++;

            nzrun_len++;

            VAR_7--;

        }



        

        if (!VAR_7) {

            

            long VAR_9 = (long)0x0101010101010101ULL;

            while (VAR_6 < VAR_2) {

                VAR_8 = *(long *)(VAR_0 + VAR_6) ^ *(long *)(VAR_1 + VAR_6);

                if ((VAR_8 - VAR_9) & ~VAR_8 & (VAR_9 << 7)) {

                    

                    while (VAR_0[VAR_6] != VAR_1[VAR_6]) {

                        nzrun_len++;

                        VAR_6++;

                    }

                    break;

                } else {

                    VAR_6 += sizeof(long);

                    nzrun_len += sizeof(long);

                }

            }

        }



        VAR_5 += uleb128_encode_small(VAR_3 + VAR_5, nzrun_len);

        

        if (VAR_5 + nzrun_len > VAR_4) {

            return -1;

        }

        memcpy(VAR_3 + VAR_5, nzrun_start, nzrun_len);

        VAR_5 += nzrun_len;

        nzrun_len = 0;

    }



    return VAR_5;

}

int FUNC_0(uint8_t *VAR_0, uint8_t *VAR_1, int VAR_2,
uint8_t *VAR_3, int VAR_4)
{ uint32_t zrun_len = 0, nzrun_len = 0; int VAR_5 = 0, VAR_6 = 0; long VAR_7, VAR_8; uint8_t *nzrun_start = NULL; g_assert(!(((uintptr_t)VAR_0 | (uintptr_t)VAR_1 | VAR_2) %
sizeof(long))); while (VAR_6 < VAR_2) { if (VAR_5 + 2 > VAR_4) { return -1; } VAR_7 = (VAR_2 - VAR_6) % sizeof(long); while (VAR_7 && VAR_0[VAR_6] == VAR_1[VAR_6]) { zrun_len++; VAR_6++; VAR_7--; } if (!VAR_7) { while (VAR_6 < VAR_2 &&
(*(long *)(VAR_0 + VAR_6)) == (*(long *)(VAR_1 + VAR_6))) { VAR_6 += sizeof(long); zrun_len += sizeof(long); } while (VAR_6 < VAR_2 && VAR_0[VAR_6] == VAR_1[VAR_6]) { zrun_len++; VAR_6++; } } if (zrun_len == VAR_2) { return 0; } if (VAR_6 == VAR_2) { return VAR_5; } VAR_5 += uleb128_encode_small(VAR_3 + VAR_5, zrun_len); zrun_len = 0; nzrun_start = VAR_1 + VAR_6; if (VAR_5 + 2 > VAR_4) { return -1; } VAR_7 = (VAR_2 - VAR_6) % sizeof(long); while (VAR_7 && VAR_0[VAR_6] != VAR_1[VAR_6]) { VAR_6++; nzrun_len++; VAR_7--; } if (!VAR_7) { long VAR_9 = (long)0x0101010101010101ULL; while (VAR_6 < VAR_2) { VAR_8 = *(long *)(VAR_0 + VAR_6) ^ *(long *)(VAR_1 + VAR_6); if ((VAR_8 - VAR_9) & ~VAR_8 & (VAR_9 << 7)) { while (VAR_0[VAR_6] != VAR_1[VAR_6]) { nzrun_len++; VAR_6++; } break; } else { VAR_6 += sizeof(long); nzrun_len += sizeof(long); } } } VAR_5 += uleb128_encode_small(VAR_3 + VAR_5, nzrun_len); if (VAR_5 + nzrun_len > VAR_4) { return -1; } memcpy(VAR_3 + VAR_5, nzrun_start, nzrun_len); VAR_5 += nzrun_len; nzrun_len = 0; } return VAR_5; }