static void lz_unpack(const unsigned char *src, int src_len,

                      unsigned char *dest, int dest_len)

{

    const unsigned char *s;

    const unsigned char *s_end;

    unsigned char *d;

    unsigned char *d_end;

    unsigned char queue[QUEUE_SIZE];

    unsigned int qpos;

    unsigned int dataleft;

    unsigned int chainofs;

    unsigned int chainlen;

    unsigned int speclen;

    unsigned char tag;

    unsigned int i, j;



    s = src;

    s_end = src + src_len;

    d = dest;

    d_end = d + dest_len;



    if (s_end - s < 8)

        return;

    dataleft = AV_RL32(s);

    s += 4;

    memset(queue, 0x20, QUEUE_SIZE);

    if (AV_RL32(s) == 0x56781234) {

        s += 4;

        qpos = 0x111;

        speclen = 0xF + 3;

    } else {

        qpos = 0xFEE;

        speclen = 100;  /* no speclen */

    }



    while (s_end - s > 0 && dataleft > 0) {

        tag = *s++;

        if ((tag == 0xFF) && (dataleft > 8)) {

            if (d + 8 > d_end || s_end - s < 8)

                return;

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

                queue[qpos++] = *d++ = *s++;

                qpos &= QUEUE_MASK;

            }

            dataleft -= 8;

        } else {

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

                if (dataleft == 0)

                    break;

                if (tag & 0x01) {

                    if (d + 1 > d_end || s_end - s < 1)

                        return;

                    queue[qpos++] = *d++ = *s++;

                    qpos &= QUEUE_MASK;

                    dataleft--;

                } else {

                    if (s_end - s < 2)

                        return;

                    chainofs = *s++;

                    chainofs |= ((*s & 0xF0) << 4);

                    chainlen = (*s++ & 0x0F) + 3;

                    if (chainlen == speclen) {

                        if (s_end - s < 1)

                            return;

                        chainlen = *s++ + 0xF + 3;

                    }

                    if (d + chainlen > d_end)

                        return;

                    for (j = 0; j < chainlen; j++) {

                        *d = queue[chainofs++ & QUEUE_MASK];

                        queue[qpos++] = *d++;

                        qpos &= QUEUE_MASK;

                    }

                    dataleft -= chainlen;

                }

                tag >>= 1;

            }

        }

    }

}

static void lz_unpack(const unsigned char *src, int src_len,

                      unsigned char *dest, int dest_len)

{

    const unsigned char *s;

    const unsigned char *s_end;

    unsigned char *d;

    unsigned char *d_end;

    unsigned char queue[QUEUE_SIZE];

    unsigned int qpos;

    unsigned int dataleft;

    unsigned int chainofs;

    unsigned int chainlen;

    unsigned int speclen;

    unsigned char tag;

    unsigned int i, j;



    s = src;

    s_end = src + src_len;

    d = dest;

    d_end = d + dest_len;



    if (s_end - s < 8)

        return;

    dataleft = AV_RL32(s);

    s += 4;

    memset(queue, 0x20, QUEUE_SIZE);

    if (AV_RL32(s) == 0x56781234) {

        s += 4;

        qpos = 0x111;

        speclen = 0xF + 3;

    } else {

        qpos = 0xFEE;

        speclen = 100;  

    }



    while (s_end - s > 0 && dataleft > 0) {

        tag = *s++;

        if ((tag == 0xFF) && (dataleft > 8)) {

            if (d + 8 > d_end || s_end - s < 8)

                return;

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

                queue[qpos++] = *d++ = *s++;

                qpos &= QUEUE_MASK;

            }

            dataleft -= 8;

        } else {

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

                if (dataleft == 0)

                    break;

                if (tag & 0x01) {

                    if (d + 1 > d_end || s_end - s < 1)

                        return;

                    queue[qpos++] = *d++ = *s++;

                    qpos &= QUEUE_MASK;

                    dataleft--;

                } else {

                    if (s_end - s < 2)

                        return;

                    chainofs = *s++;

                    chainofs |= ((*s & 0xF0) << 4);

                    chainlen = (*s++ & 0x0F) + 3;

                    if (chainlen == speclen) {

                        if (s_end - s < 1)

                            return;

                        chainlen = *s++ + 0xF + 3;

                    }

                    if (d + chainlen > d_end)

                        return;

                    for (j = 0; j < chainlen; j++) {

                        *d = queue[chainofs++ & QUEUE_MASK];

                        queue[qpos++] = *d++;

                        qpos &= QUEUE_MASK;

                    }

                    dataleft -= chainlen;

                }

                tag >>= 1;

            }

        }

    }

}

            if (d + 8 > d_end || s_end - s < 8)                     if (d + 1 > d_end || s_end - s < 1)                     if (d + chainlen > d_end)
static void FUNC_0(const unsigned char *VAR_0, int VAR_1,

                      unsigned char *VAR_2, int VAR_3)

{

    const unsigned char *VAR_4;

    const unsigned char *VAR_5;

    unsigned char *VAR_6;

    unsigned char *VAR_7;

    unsigned char VAR_8[QUEUE_SIZE];

    unsigned int VAR_9;

    unsigned int VAR_10;

    unsigned int VAR_11;

    unsigned int VAR_12;

    unsigned int VAR_13;

    unsigned char VAR_14;

    unsigned int VAR_15, VAR_16;



    VAR_4 = VAR_0;

    VAR_5 = VAR_0 + VAR_1;

    VAR_6 = VAR_2;

    VAR_7 = VAR_6 + VAR_3;



    if (VAR_5 - VAR_4 < 8)

        return;

    VAR_10 = AV_RL32(VAR_4);

    VAR_4 += 4;

    memset(VAR_8, 0x20, QUEUE_SIZE);

    if (AV_RL32(VAR_4) == 0x56781234) {

        VAR_4 += 4;

        VAR_9 = 0x111;

        VAR_13 = 0xF + 3;

    } else {

        VAR_9 = 0xFEE;

        VAR_13 = 100;  

    }



    while (VAR_5 - VAR_4 > 0 && VAR_10 > 0) {

        VAR_14 = *VAR_4++;

        if ((VAR_14 == 0xFF) && (VAR_10 > 8)) {

            if (VAR_6 + 8 > VAR_7 || VAR_5 - VAR_4 < 8)

                return;

            for (VAR_15 = 0; VAR_15 < 8; VAR_15++) {

                VAR_8[VAR_9++] = *VAR_6++ = *VAR_4++;

                VAR_9 &= QUEUE_MASK;

            }

            VAR_10 -= 8;

        } else {

            for (VAR_15 = 0; VAR_15 < 8; VAR_15++) {

                if (VAR_10 == 0)

                    break;

                if (VAR_14 & 0x01) {

                    if (VAR_6 + 1 > VAR_7 || VAR_5 - VAR_4 < 1)

                        return;

                    VAR_8[VAR_9++] = *VAR_6++ = *VAR_4++;

                    VAR_9 &= QUEUE_MASK;

                    VAR_10--;

                } else {

                    if (VAR_5 - VAR_4 < 2)

                        return;

                    VAR_11 = *VAR_4++;

                    VAR_11 |= ((*VAR_4 & 0xF0) << 4);

                    VAR_12 = (*VAR_4++ & 0x0F) + 3;

                    if (VAR_12 == VAR_13) {

                        if (VAR_5 - VAR_4 < 1)

                            return;

                        VAR_12 = *VAR_4++ + 0xF + 3;

                    }

                    if (VAR_6 + VAR_12 > VAR_7)

                        return;

                    for (VAR_16 = 0; VAR_16 < VAR_12; VAR_16++) {

                        *VAR_6 = VAR_8[VAR_11++ & QUEUE_MASK];

                        VAR_8[VAR_9++] = *VAR_6++;

                        VAR_9 &= QUEUE_MASK;

                    }

                    VAR_10 -= VAR_12;

                }

                VAR_14 >>= 1;

            }

        }

    }

}

static void FUNC_0(const unsigned char *VAR_0, int VAR_1,
unsigned char *VAR_2, int VAR_3)
{ const unsigned char *VAR_4; const unsigned char *VAR_5; unsigned char *VAR_6; unsigned char *VAR_7; unsigned char VAR_8[QUEUE_SIZE]; unsigned int VAR_9; unsigned int VAR_10; unsigned int VAR_11; unsigned int VAR_12; unsigned int VAR_13; unsigned char VAR_14; unsigned int VAR_15, VAR_16; VAR_4 = VAR_0; VAR_5 = VAR_0 + VAR_1; VAR_6 = VAR_2; VAR_7 = VAR_6 + VAR_3; if (VAR_5 - VAR_4 < 8)
return; VAR_10 = AV_RL32(VAR_4); VAR_4 += 4; memset(VAR_8, 0x20, QUEUE_SIZE); if (AV_RL32(VAR_4) == 0x56781234) { VAR_4 += 4; VAR_9 = 0x111; VAR_13 = 0xF + 3; } else { VAR_9 = 0xFEE; VAR_13 = 100; } while (VAR_5 - VAR_4 > 0 && VAR_10 > 0) { VAR_14 = *VAR_4++; if ((VAR_14 == 0xFF) && (VAR_10 > 8)) { if (VAR_6 + 8 > VAR_7 || VAR_5 - VAR_4 < 8)
return; for (VAR_15 = 0; VAR_15 < 8; VAR_15++) { VAR_8[VAR_9++] = *VAR_6++ = *VAR_4++; VAR_9 &= QUEUE_MASK; } VAR_10 -= 8; } else { for (VAR_15 = 0; VAR_15 < 8; VAR_15++) { if (VAR_10 == 0)
break; if (VAR_14 & 0x01) { if (VAR_6 + 1 > VAR_7 || VAR_5 - VAR_4 < 1)
return; VAR_8[VAR_9++] = *VAR_6++ = *VAR_4++; VAR_9 &= QUEUE_MASK; VAR_10--; } else { if (VAR_5 - VAR_4 < 2)
return; VAR_11 = *VAR_4++; VAR_11 |= ((*VAR_4 & 0xF0) << 4); VAR_12 = (*VAR_4++ & 0x0F) + 3; if (VAR_12 == VAR_13) { if (VAR_5 - VAR_4 < 1)
return; VAR_12 = *VAR_4++ + 0xF + 3; } if (VAR_6 + VAR_12 > VAR_7)
return; for (VAR_16 = 0; VAR_16 < VAR_12; VAR_16++) { *VAR_6 = VAR_8[VAR_11++ & QUEUE_MASK]; VAR_8[VAR_9++] = *VAR_6++; VAR_9 &= QUEUE_MASK; } VAR_10 -= VAR_12; } VAR_14 >>= 1; } } } }