static int decode_plane(UtvideoContext *c, int plane_no,

                        uint8_t *dst, int step, ptrdiff_t stride,

                        int width, int height,

                        const uint8_t *src, int use_pred)

{

    int i, j, slice, pix;

    int sstart, send;

    VLC vlc;

    GetBitContext gb;

    int prev, fsym;

    const int cmask = c->interlaced ? ~(1 + 2 * (!plane_no && c->avctx->pix_fmt == AV_PIX_FMT_YUV420P)) : ~(!plane_no && c->avctx->pix_fmt == AV_PIX_FMT_YUV420P);



    if (build_huff(src, &vlc, &fsym)) {

        av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");

        return AVERROR_INVALIDDATA;

    }

    if (fsym >= 0) { // build_huff reported a symbol to fill slices with

        send = 0;

        for (slice = 0; slice < c->slices; slice++) {

            uint8_t *dest;



            sstart = send;

            send   = (height * (slice + 1) / c->slices) & cmask;

            dest   = dst + sstart * stride;



            prev = 0x80;

            for (j = sstart; j < send; j++) {

                for (i = 0; i < width * step; i += step) {

                    pix = fsym;

                    if (use_pred) {

                        prev += pix;

                        pix   = prev;

                    }

                    dest[i] = pix;

                }

                dest += stride;

            }

        }

        return 0;

    }



    src      += 256;



    send = 0;

    for (slice = 0; slice < c->slices; slice++) {

        uint8_t *dest;

        int slice_data_start, slice_data_end, slice_size;



        sstart = send;

        send   = (height * (slice + 1) / c->slices) & cmask;

        dest   = dst + sstart * stride;



        // slice offset and size validation was done earlier

        slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;

        slice_data_end   = AV_RL32(src + slice * 4);

        slice_size       = slice_data_end - slice_data_start;



        if (!slice_size) {

            av_log(c->avctx, AV_LOG_ERROR, "Plane has more than one symbol "

                   "yet a slice has a length of zero.\n");

            goto fail;

        }



        memset(c->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);

        c->bdsp.bswap_buf((uint32_t *) c->slice_bits,

                          (uint32_t *)(src + slice_data_start + c->slices * 4),

                          (slice_data_end - slice_data_start + 3) >> 2);

        init_get_bits(&gb, c->slice_bits, slice_size * 8);



        prev = 0x80;

        for (j = sstart; j < send; j++) {

            for (i = 0; i < width * step; i += step) {

                pix = get_vlc2(&gb, vlc.table, VLC_BITS, 3);

                if (pix < 0) {

                    av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");

                    goto fail;

                }

                if (use_pred) {

                    prev += pix;

                    pix   = prev;

                }

                dest[i] = pix;

            }

            if (get_bits_left(&gb) < 0) {

                av_log(c->avctx, AV_LOG_ERROR,

                        "Slice decoding ran out of bits\n");

                goto fail;

            }

            dest += stride;

        }

        if (get_bits_left(&gb) > 32)

            av_log(c->avctx, AV_LOG_WARNING,

                   "%d bits left after decoding slice\n", get_bits_left(&gb));

    }



    ff_free_vlc(&vlc);



    return 0;

fail:

    ff_free_vlc(&vlc);

    return AVERROR_INVALIDDATA;

}

static int decode_plane(UtvideoContext *c, int plane_no,

                        uint8_t *dst, int step, ptrdiff_t stride,

                        int width, int height,

                        const uint8_t *src, int use_pred)

{

    int i, j, slice, pix;

    int sstart, send;

    VLC vlc;

    GetBitContext gb;

    int prev, fsym;

    const int cmask = c->interlaced ? ~(1 + 2 * (!plane_no && c->avctx->pix_fmt == AV_PIX_FMT_YUV420P)) : ~(!plane_no && c->avctx->pix_fmt == AV_PIX_FMT_YUV420P);



    if (build_huff(src, &vlc, &fsym)) {

        av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");

        return AVERROR_INVALIDDATA;

    }

    if (fsym >= 0) { 

        send = 0;

        for (slice = 0; slice < c->slices; slice++) {

            uint8_t *dest;



            sstart = send;

            send   = (height * (slice + 1) / c->slices) & cmask;

            dest   = dst + sstart * stride;



            prev = 0x80;

            for (j = sstart; j < send; j++) {

                for (i = 0; i < width * step; i += step) {

                    pix = fsym;

                    if (use_pred) {

                        prev += pix;

                        pix   = prev;

                    }

                    dest[i] = pix;

                }

                dest += stride;

            }

        }

        return 0;

    }



    src      += 256;



    send = 0;

    for (slice = 0; slice < c->slices; slice++) {

        uint8_t *dest;

        int slice_data_start, slice_data_end, slice_size;



        sstart = send;

        send   = (height * (slice + 1) / c->slices) & cmask;

        dest   = dst + sstart * stride;



        

        slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0;

        slice_data_end   = AV_RL32(src + slice * 4);

        slice_size       = slice_data_end - slice_data_start;



        if (!slice_size) {

            av_log(c->avctx, AV_LOG_ERROR, "Plane has more than one symbol "

                   "yet a slice has a length of zero.\n");

            goto fail;

        }



        memset(c->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);

        c->bdsp.bswap_buf((uint32_t *) c->slice_bits,

                          (uint32_t *)(src + slice_data_start + c->slices * 4),

                          (slice_data_end - slice_data_start + 3) >> 2);

        init_get_bits(&gb, c->slice_bits, slice_size * 8);



        prev = 0x80;

        for (j = sstart; j < send; j++) {

            for (i = 0; i < width * step; i += step) {

                pix = get_vlc2(&gb, vlc.table, VLC_BITS, 3);

                if (pix < 0) {

                    av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n");

                    goto fail;

                }

                if (use_pred) {

                    prev += pix;

                    pix   = prev;

                }

                dest[i] = pix;

            }

            if (get_bits_left(&gb) < 0) {

                av_log(c->avctx, AV_LOG_ERROR,

                        "Slice decoding ran out of bits\n");

                goto fail;

            }

            dest += stride;

        }

        if (get_bits_left(&gb) > 32)

            av_log(c->avctx, AV_LOG_WARNING,

                   "%d bits left after decoding slice\n", get_bits_left(&gb));

    }



    ff_free_vlc(&vlc);



    return 0;

fail:

    ff_free_vlc(&vlc);

    return AVERROR_INVALIDDATA;

}

static int FUNC_0(UtvideoContext *VAR_0, int VAR_1,

                        uint8_t *VAR_2, int VAR_3, ptrdiff_t VAR_4,

                        int VAR_5, int VAR_6,

                        const uint8_t *VAR_7, int VAR_8)

{

    int VAR_9, VAR_10, VAR_11, VAR_12;

    int VAR_13, VAR_14;

    VLC vlc;

    GetBitContext gb;

    int VAR_15, VAR_16;

    const int VAR_17 = VAR_0->interlaced ? ~(1 + 2 * (!VAR_1 && VAR_0->avctx->pix_fmt == AV_PIX_FMT_YUV420P)) : ~(!VAR_1 && VAR_0->avctx->pix_fmt == AV_PIX_FMT_YUV420P);



    if (build_huff(VAR_7, &vlc, &VAR_16)) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");

        return AVERROR_INVALIDDATA;

    }

    if (VAR_16 >= 0) { 

        VAR_14 = 0;

        for (VAR_11 = 0; VAR_11 < VAR_0->slices; VAR_11++) {

            uint8_t *dest;



            VAR_13 = VAR_14;

            VAR_14   = (VAR_6 * (VAR_11 + 1) / VAR_0->slices) & VAR_17;

            dest   = VAR_2 + VAR_13 * VAR_4;



            VAR_15 = 0x80;

            for (VAR_10 = VAR_13; VAR_10 < VAR_14; VAR_10++) {

                for (VAR_9 = 0; VAR_9 < VAR_5 * VAR_3; VAR_9 += VAR_3) {

                    VAR_12 = VAR_16;

                    if (VAR_8) {

                        VAR_15 += VAR_12;

                        VAR_12   = VAR_15;

                    }

                    dest[VAR_9] = VAR_12;

                }

                dest += VAR_4;

            }

        }

        return 0;

    }



    VAR_7      += 256;



    VAR_14 = 0;

    for (VAR_11 = 0; VAR_11 < VAR_0->slices; VAR_11++) {

        uint8_t *dest;

        int slice_data_start, slice_data_end, slice_size;



        VAR_13 = VAR_14;

        VAR_14   = (VAR_6 * (VAR_11 + 1) / VAR_0->slices) & VAR_17;

        dest   = VAR_2 + VAR_13 * VAR_4;



        

        slice_data_start = VAR_11 ? AV_RL32(VAR_7 + VAR_11 * 4 - 4) : 0;

        slice_data_end   = AV_RL32(VAR_7 + VAR_11 * 4);

        slice_size       = slice_data_end - slice_data_start;



        if (!slice_size) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "Plane has more than one symbol "

                   "yet a VAR_11 has a length of zero.\n");

            goto fail;

        }



        memset(VAR_0->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);

        VAR_0->bdsp.bswap_buf((uint32_t *) VAR_0->slice_bits,

                          (uint32_t *)(VAR_7 + slice_data_start + VAR_0->slices * 4),

                          (slice_data_end - slice_data_start + 3) >> 2);

        init_get_bits(&gb, VAR_0->slice_bits, slice_size * 8);



        VAR_15 = 0x80;

        for (VAR_10 = VAR_13; VAR_10 < VAR_14; VAR_10++) {

            for (VAR_9 = 0; VAR_9 < VAR_5 * VAR_3; VAR_9 += VAR_3) {

                VAR_12 = get_vlc2(&gb, vlc.table, VLC_BITS, 3);

                if (VAR_12 < 0) {

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "Decoding error\n");

                    goto fail;

                }

                if (VAR_8) {

                    VAR_15 += VAR_12;

                    VAR_12   = VAR_15;

                }

                dest[VAR_9] = VAR_12;

            }

            if (get_bits_left(&gb) < 0) {

                av_log(VAR_0->avctx, AV_LOG_ERROR,

                        "Slice decoding ran out of bits\n");

                goto fail;

            }

            dest += VAR_4;

        }

        if (get_bits_left(&gb) > 32)

            av_log(VAR_0->avctx, AV_LOG_WARNING,

                   "%d bits left after decoding VAR_11\n", get_bits_left(&gb));

    }



    ff_free_vlc(&vlc);



    return 0;

fail:

    ff_free_vlc(&vlc);

    return AVERROR_INVALIDDATA;

}

static int FUNC_0(UtvideoContext *VAR_0, int VAR_1,
uint8_t *VAR_2, int VAR_3, ptrdiff_t VAR_4,
int VAR_5, int VAR_6,
const uint8_t *VAR_7, int VAR_8)
{ int VAR_9, VAR_10, VAR_11, VAR_12; int VAR_13, VAR_14; VLC vlc; GetBitContext gb; int VAR_15, VAR_16; const int VAR_17 = VAR_0->interlaced ? ~(1 + 2 * (!VAR_1 && VAR_0->avctx->pix_fmt == AV_PIX_FMT_YUV420P)) : ~(!VAR_1 && VAR_0->avctx->pix_fmt == AV_PIX_FMT_YUV420P); if (build_huff(VAR_7, &vlc, &VAR_16)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n"); return AVERROR_INVALIDDATA; } if (VAR_16 >= 0) { VAR_14 = 0; for (VAR_11 = 0; VAR_11 < VAR_0->slices; VAR_11++) { uint8_t *dest; VAR_13 = VAR_14; VAR_14   = (VAR_6 * (VAR_11 + 1) / VAR_0->slices) & VAR_17; dest   = VAR_2 + VAR_13 * VAR_4; VAR_15 = 0x80; for (VAR_10 = VAR_13; VAR_10 < VAR_14; VAR_10++) { for (VAR_9 = 0; VAR_9 < VAR_5 * VAR_3; VAR_9 += VAR_3) { VAR_12 = VAR_16; if (VAR_8) { VAR_15 += VAR_12; VAR_12   = VAR_15; } dest[VAR_9] = VAR_12; } dest += VAR_4; } } return 0; } VAR_7      += 256; VAR_14 = 0; for (VAR_11 = 0; VAR_11 < VAR_0->slices; VAR_11++) { uint8_t *dest; int slice_data_start, slice_data_end, slice_size; VAR_13 = VAR_14; VAR_14   = (VAR_6 * (VAR_11 + 1) / VAR_0->slices) & VAR_17; dest   = VAR_2 + VAR_13 * VAR_4; slice_data_start = VAR_11 ? AV_RL32(VAR_7 + VAR_11 * 4 - 4) : 0; slice_data_end   = AV_RL32(VAR_7 + VAR_11 * 4); slice_size       = slice_data_end - slice_data_start; if (!slice_size) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Plane has more than one symbol "
"yet a VAR_11 has a length of zero.\n"); goto fail; } memset(VAR_0->slice_bits + slice_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); VAR_0->bdsp.bswap_buf((uint32_t *) VAR_0->slice_bits,
(uint32_t *)(VAR_7 + slice_data_start + VAR_0->slices * 4),
(slice_data_end - slice_data_start + 3) >> 2); init_get_bits(&gb, VAR_0->slice_bits, slice_size * 8); VAR_15 = 0x80; for (VAR_10 = VAR_13; VAR_10 < VAR_14; VAR_10++) { for (VAR_9 = 0; VAR_9 < VAR_5 * VAR_3; VAR_9 += VAR_3) { VAR_12 = get_vlc2(&gb, vlc.table, VLC_BITS, 3); if (VAR_12 < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Decoding error\n"); goto fail; } if (VAR_8) { VAR_15 += VAR_12; VAR_12   = VAR_15; } dest[VAR_9] = VAR_12; } if (get_bits_left(&gb) < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"Slice decoding ran out of bits\n"); goto fail; } dest += VAR_4; } if (get_bits_left(&gb) > 32)
av_log(VAR_0->avctx, AV_LOG_WARNING,
"%d bits left after decoding VAR_11\n", get_bits_left(&gb)); } ff_free_vlc(&vlc); return 0; fail:
ff_free_vlc(&vlc); return AVERROR_INVALIDDATA; }