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;



    if(f->version>1){

        extra=20;

        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+ bytestream_size+ wordstream_size + extra != length

       || bitstream_size  > (1<<26)

       || bytestream_size > (1<<26)

       || wordstream_size > (1<<26)

       ){

        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);



    f->wordstream= (const uint16_t*)(buf + extra + bitstream_size);

    f->bytestream= buf + extra + bitstream_size + wordstream_size;



    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;

    }



    if(   bitstream_size != (get_bits_count(&f->gb)+31)/32*4

       || (((const char*)f->wordstream - (const char*)buf + 2)&~2) != extra + bitstream_size + wordstream_size

       || (((const char*)f->bytestream - (const char*)buf + 3)&~3) != extra + bitstream_size + wordstream_size + bytestream_size)

        av_log(f->avctx, AV_LOG_ERROR, " %d %td %td bytes left\n",

            bitstream_size - (get_bits_count(&f->gb)+31)/32*4,

            -(((const char*)f->bytestream - (const char*)buf + 3)&~3) + (extra + bitstream_size + wordstream_size + bytestream_size),

            -(((const char*)f->wordstream - (const char*)buf + 2)&~2) + (extra + bitstream_size + wordstream_size)

        );



    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;



    if(f->version>1){

        extra=20;

        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+ bytestream_size+ wordstream_size + extra != length

       || bitstream_size  > (1<<26)

       || bytestream_size > (1<<26)

       || wordstream_size > (1<<26)

       ){

        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);



    f->wordstream= (const uint16_t*)(buf + extra + bitstream_size);

    f->bytestream= buf + extra + bitstream_size + wordstream_size;



    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;

    }



    if(   bitstream_size != (get_bits_count(&f->gb)+31)/32*4

       || (((const char*)f->wordstream - (const char*)buf + 2)&~2) != extra + bitstream_size + wordstream_size

       || (((const char*)f->bytestream - (const char*)buf + 3)&~3) != extra + bitstream_size + wordstream_size + bytestream_size)

        av_log(f->avctx, AV_LOG_ERROR, " %d %td %td bytes left\n",

            bitstream_size - (get_bits_count(&f->gb)+31)/32*4,

            -(((const char*)f->bytestream - (const char*)buf + 3)&~3) + (extra + bitstream_size + wordstream_size + bytestream_size),

            -(((const char*)f->wordstream - (const char*)buf + 2)&~2) + (extra + bitstream_size + wordstream_size)

        );



    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;



    if(VAR_0->version>1){

        VAR_11=20;

        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_9+ VAR_10 + VAR_11 != VAR_2

       || VAR_8  > (1<<26)

       || VAR_9 > (1<<26)

       || VAR_10 > (1<<26)

       ){

        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_0->wordstream= (const uint16_t*)(VAR_1 + VAR_11 + VAR_8);

    VAR_0->bytestream= VAR_1 + VAR_11 + VAR_8 + VAR_10;



    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;

    }



    if(   VAR_8 != (get_bits_count(&VAR_0->gb)+31)/32*4

       || (((const char*)VAR_0->wordstream - (const char*)VAR_1 + 2)&~2) != VAR_11 + VAR_8 + VAR_10

       || (((const char*)VAR_0->bytestream - (const char*)VAR_1 + 3)&~3) != VAR_11 + VAR_8 + VAR_10 + VAR_9)

        av_log(VAR_0->avctx, AV_LOG_ERROR, " %d %td %td bytes left\n",

            VAR_8 - (get_bits_count(&VAR_0->gb)+31)/32*4,

            -(((const char*)VAR_0->bytestream - (const char*)VAR_1 + 3)&~3) + (VAR_11 + VAR_8 + VAR_10 + VAR_9),

            -(((const char*)VAR_0->wordstream - (const char*)VAR_1 + 2)&~2) + (VAR_11 + VAR_8 + VAR_10)

        );



    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; if(VAR_0->version>1){ VAR_11=20; 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_9+ VAR_10 + VAR_11 != VAR_2
|| VAR_8  > (1<<26)
|| VAR_9 > (1<<26)
|| VAR_10 > (1<<26)
){ 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_0->wordstream= (const uint16_t*)(VAR_1 + VAR_11 + VAR_8); VAR_0->bytestream= VAR_1 + VAR_11 + VAR_8 + VAR_10; 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; } if(   VAR_8 != (get_bits_count(&VAR_0->gb)+31)/32*4
|| (((const char*)VAR_0->wordstream - (const char*)VAR_1 + 2)&~2) != VAR_11 + VAR_8 + VAR_10
|| (((const char*)VAR_0->bytestream - (const char*)VAR_1 + 3)&~3) != VAR_11 + VAR_8 + VAR_10 + VAR_9)
av_log(VAR_0->avctx, AV_LOG_ERROR, " %d %td %td bytes left\n",
VAR_8 - (get_bits_count(&VAR_0->gb)+31)/32*4,
-(((const char*)VAR_0->bytestream - (const char*)VAR_1 + 3)&~3) + (VAR_11 + VAR_8 + VAR_10 + VAR_9),
-(((const char*)VAR_0->wordstream - (const char*)VAR_1 + 2)&~2) + (VAR_11 + VAR_8 + VAR_10)
); return 0; }