static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length)

{

    int x, y;

    const int width  = f->avctx->width;

    const int height = f->avctx->height;

    uint16_t *src    = (uint16_t *)f->last_picture.data[0];

    uint16_t *dst    = (uint16_t *)f->current_picture.data[0];

    const int stride =             f->current_picture.linesize[0] >> 1;

    unsigned int bitstream_size, bytestream_size, wordstream_size, extra,

                 bytestream_offset, wordstream_offset;



    if (f->version > 1) {

        extra           = 20;

        if (length < extra)

            return -1;

        bitstream_size  = AV_RL32(buf + 8);

        wordstream_size = AV_RL32(buf + 12);

        bytestream_size = AV_RL32(buf + 16);

    } else {

        extra           = 0;

        bitstream_size  = AV_RL16(buf - 4);

        wordstream_size = AV_RL16(buf - 2);

        bytestream_size = FFMAX(length - bitstream_size - wordstream_size, 0);

    }



    if (bitstream_size > length ||

        bytestream_size > length - bitstream_size ||

        wordstream_size > length - bytestream_size - bitstream_size ||

        extra > length - bytestream_size - bitstream_size - wordstream_size) {

        av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", bitstream_size, bytestream_size, wordstream_size,

        bitstream_size+ bytestream_size+ wordstream_size - length);

        return -1;

    }



    av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size,

                   bitstream_size + FF_INPUT_BUFFER_PADDING_SIZE);

    if (!f->bitstream_buffer)

        return AVERROR(ENOMEM);

    f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)(buf + extra),

                     bitstream_size / 4);

    memset((uint8_t*)f->bitstream_buffer + bitstream_size,

           0, FF_INPUT_BUFFER_PADDING_SIZE);

    init_get_bits(&f->gb, f->bitstream_buffer, 8 * bitstream_size);



    wordstream_offset = extra + bitstream_size;

    bytestream_offset = extra + bitstream_size + wordstream_size;

    bytestream2_init(&f->g2, buf + wordstream_offset,

                     length - wordstream_offset);

    bytestream2_init(&f->g, buf + bytestream_offset,

                     length - bytestream_offset);



    init_mv(f);



    for (y = 0; y < height; y += 8) {

        for (x = 0; x < width; x += 8)

            decode_p_block(f, dst + x, src + x, 3, 3, stride);

        src += 8 * stride;

        dst += 8 * stride;

    }



    return 0;

}

static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length)

{

    int x, y;

    const int width  = f->avctx->width;

    const int height = f->avctx->height;

    uint16_t *src    = (uint16_t *)f->last_picture.data[0];

    uint16_t *dst    = (uint16_t *)f->current_picture.data[0];

    const int stride =             f->current_picture.linesize[0] >> 1;

    unsigned int bitstream_size, bytestream_size, wordstream_size, extra,

                 bytestream_offset, wordstream_offset;



    if (f->version > 1) {

        extra           = 20;

        if (length < extra)

            return -1;

        bitstream_size  = AV_RL32(buf + 8);

        wordstream_size = AV_RL32(buf + 12);

        bytestream_size = AV_RL32(buf + 16);

    } else {

        extra           = 0;

        bitstream_size  = AV_RL16(buf - 4);

        wordstream_size = AV_RL16(buf - 2);

        bytestream_size = FFMAX(length - bitstream_size - wordstream_size, 0);

    }



    if (bitstream_size > length ||

        bytestream_size > length - bitstream_size ||

        wordstream_size > length - bytestream_size - bitstream_size ||

        extra > length - bytestream_size - bitstream_size - wordstream_size) {

        av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", bitstream_size, bytestream_size, wordstream_size,

        bitstream_size+ bytestream_size+ wordstream_size - length);

        return -1;

    }



    av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size,

                   bitstream_size + FF_INPUT_BUFFER_PADDING_SIZE);

    if (!f->bitstream_buffer)

        return AVERROR(ENOMEM);

    f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)(buf + extra),

                     bitstream_size / 4);

    memset((uint8_t*)f->bitstream_buffer + bitstream_size,

           0, FF_INPUT_BUFFER_PADDING_SIZE);

    init_get_bits(&f->gb, f->bitstream_buffer, 8 * bitstream_size);



    wordstream_offset = extra + bitstream_size;

    bytestream_offset = extra + bitstream_size + wordstream_size;

    bytestream2_init(&f->g2, buf + wordstream_offset,

                     length - wordstream_offset);

    bytestream2_init(&f->g, buf + bytestream_offset,

                     length - bytestream_offset);



    init_mv(f);



    for (y = 0; y < height; y += 8) {

        for (x = 0; x < width; x += 8)

            decode_p_block(f, dst + x, src + x, 3, 3, stride);

        src += 8 * stride;

        dst += 8 * stride;

    }



    return 0;

}

    if (bitstream_size > length ||
static int FUNC_0(FourXContext *VAR_0, const uint8_t *VAR_1, int VAR_2)

{

    int VAR_3, VAR_4;

    const int VAR_5  = VAR_0->avctx->VAR_5;

    const int VAR_6 = VAR_0->avctx->VAR_6;

    uint16_t *src    = (uint16_t *)VAR_0->last_picture.data[0];

    uint16_t *dst    = (uint16_t *)VAR_0->current_picture.data[0];

    const int VAR_7 =             VAR_0->current_picture.linesize[0] >> 1;

    unsigned int VAR_8, VAR_9, VAR_10, VAR_11,

                 VAR_12, VAR_13;



    if (VAR_0->version > 1) {

        VAR_11           = 20;

        if (VAR_2 < VAR_11)

            return -1;

        VAR_8  = AV_RL32(VAR_1 + 8);

        VAR_10 = AV_RL32(VAR_1 + 12);

        VAR_9 = AV_RL32(VAR_1 + 16);

    } else {

        VAR_11           = 0;

        VAR_8  = AV_RL16(VAR_1 - 4);

        VAR_10 = AV_RL16(VAR_1 - 2);

        VAR_9 = FFMAX(VAR_2 - VAR_8 - VAR_10, 0);

    }



    if (VAR_8 > VAR_2 ||

        VAR_9 > VAR_2 - VAR_8 ||

        VAR_10 > VAR_2 - VAR_9 - VAR_8 ||

        VAR_11 > VAR_2 - VAR_9 - VAR_8 - VAR_10) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", VAR_8, VAR_9, VAR_10,

        VAR_8+ VAR_9+ VAR_10 - VAR_2);

        return -1;

    }



    av_fast_malloc(&VAR_0->bitstream_buffer, &VAR_0->bitstream_buffer_size,

                   VAR_8 + FF_INPUT_BUFFER_PADDING_SIZE);

    if (!VAR_0->bitstream_buffer)

        return AVERROR(ENOMEM);

    VAR_0->dsp.bswap_buf(VAR_0->bitstream_buffer, (const uint32_t*)(VAR_1 + VAR_11),

                     VAR_8 / 4);

    memset((uint8_t*)VAR_0->bitstream_buffer + VAR_8,

           0, FF_INPUT_BUFFER_PADDING_SIZE);

    init_get_bits(&VAR_0->gb, VAR_0->bitstream_buffer, 8 * VAR_8);



    VAR_13 = VAR_11 + VAR_8;

    VAR_12 = VAR_11 + VAR_8 + VAR_10;

    bytestream2_init(&VAR_0->g2, VAR_1 + VAR_13,

                     VAR_2 - VAR_13);

    bytestream2_init(&VAR_0->g, VAR_1 + VAR_12,

                     VAR_2 - VAR_12);



    init_mv(VAR_0);



    for (VAR_4 = 0; VAR_4 < VAR_6; VAR_4 += 8) {

        for (VAR_3 = 0; VAR_3 < VAR_5; VAR_3 += 8)

            decode_p_block(VAR_0, dst + VAR_3, src + VAR_3, 3, 3, VAR_7);

        src += 8 * VAR_7;

        dst += 8 * VAR_7;

    }



    return 0;

}

static int FUNC_0(FourXContext *VAR_0, const uint8_t *VAR_1, int VAR_2)
{ int VAR_3, VAR_4; const int VAR_5  = VAR_0->avctx->VAR_5; const int VAR_6 = VAR_0->avctx->VAR_6; uint16_t *src    = (uint16_t *)VAR_0->last_picture.data[0]; uint16_t *dst    = (uint16_t *)VAR_0->current_picture.data[0]; const int VAR_7 =             VAR_0->current_picture.linesize[0] >> 1; unsigned int VAR_8, VAR_9, VAR_10, VAR_11,
VAR_12, VAR_13; if (VAR_0->version > 1) { VAR_11           = 20; if (VAR_2 < VAR_11)
return -1; VAR_8  = AV_RL32(VAR_1 + 8); VAR_10 = AV_RL32(VAR_1 + 12); VAR_9 = AV_RL32(VAR_1 + 16); } else { VAR_11           = 0; VAR_8  = AV_RL16(VAR_1 - 4); VAR_10 = AV_RL16(VAR_1 - 2); VAR_9 = FFMAX(VAR_2 - VAR_8 - VAR_10, 0); } if (VAR_8 > VAR_2 ||
VAR_9 > VAR_2 - VAR_8 ||
VAR_10 > VAR_2 - VAR_9 - VAR_8 ||
VAR_11 > VAR_2 - VAR_9 - VAR_8 - VAR_10) { av_log(VAR_0->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", VAR_8, VAR_9, VAR_10,
VAR_8+ VAR_9+ VAR_10 - VAR_2); return -1; } av_fast_malloc(&VAR_0->bitstream_buffer, &VAR_0->bitstream_buffer_size,
VAR_8 + FF_INPUT_BUFFER_PADDING_SIZE); if (!VAR_0->bitstream_buffer)
return AVERROR(ENOMEM); VAR_0->dsp.bswap_buf(VAR_0->bitstream_buffer, (const uint32_t*)(VAR_1 + VAR_11),
VAR_8 / 4); memset((uint8_t*)VAR_0->bitstream_buffer + VAR_8,
0, FF_INPUT_BUFFER_PADDING_SIZE); init_get_bits(&VAR_0->gb, VAR_0->bitstream_buffer, 8 * VAR_8); VAR_13 = VAR_11 + VAR_8; VAR_12 = VAR_11 + VAR_8 + VAR_10; bytestream2_init(&VAR_0->g2, VAR_1 + VAR_13,
VAR_2 - VAR_13); bytestream2_init(&VAR_0->g, VAR_1 + VAR_12,
VAR_2 - VAR_12); init_mv(VAR_0); for (VAR_4 = 0; VAR_4 < VAR_6; VAR_4 += 8) { for (VAR_3 = 0; VAR_3 < VAR_5; VAR_3 += 8) decode_p_block(VAR_0, dst + VAR_3, src + VAR_3, 3, 3, VAR_7); src += 8 * VAR_7; dst += 8 * VAR_7; } return 0; }