static av_always_inline int encode_line(FFV1Context *s, int w,

                                        int16_t *sample[3],

                                        int plane_index, int bits)

{

    PlaneContext *const p = &s->plane[plane_index];

    RangeCoder *const c   = &s->c;

    int x;

    int run_index = s->run_index;

    int run_count = 0;

    int run_mode  = 0;



    if (s->ac) {

        if (c->bytestream_end - c->bytestream < w * 20) {

            av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");

            return AVERROR_INVALIDDATA;

        }

    } else {

        if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < w * 4) {

            av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");

            return AVERROR_INVALIDDATA;

        }

    }



    for (x = 0; x < w; x++) {

        int diff, context;



        context = get_context(p, sample[0] + x, sample[1] + x, sample[2] + x);

        diff    = sample[0][x] - predict(sample[0] + x, sample[1] + x);



        if (context < 0) {

            context = -context;

            diff    = -diff;

        }



        diff = fold(diff, bits);



        if (s->ac) {

            if (s->flags & CODEC_FLAG_PASS1) {

                put_symbol_inline(c, p->state[context], diff, 1, s->rc_stat,

                                  s->rc_stat2[p->quant_table_index][context]);

            } else {

                put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL);

            }

        } else {

            if (context == 0)

                run_mode = 1;



            if (run_mode) {

                if (diff) {

                    while (run_count >= 1 << ff_log2_run[run_index]) {

                        run_count -= 1 << ff_log2_run[run_index];

                        run_index++;

                        put_bits(&s->pb, 1, 1);

                    }



                    put_bits(&s->pb, 1 + ff_log2_run[run_index], run_count);

                    if (run_index)

                        run_index--;

                    run_count = 0;

                    run_mode  = 0;

                    if (diff > 0)

                        diff--;

                } else {

                    run_count++;

                }

            }



            av_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",

                    run_count, run_index, run_mode, x,

                    (int)put_bits_count(&s->pb));



            if (run_mode == 0)

                put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits);

        }

    }

    if (run_mode) {

        while (run_count >= 1 << ff_log2_run[run_index]) {

            run_count -= 1 << ff_log2_run[run_index];

            run_index++;

            put_bits(&s->pb, 1, 1);

        }



        if (run_count)

            put_bits(&s->pb, 1, 1);

    }

    s->run_index = run_index;



    return 0;

}

static av_always_inline int encode_line(FFV1Context *s, int w,

                                        int16_t *sample[3],

                                        int plane_index, int bits)

{

    PlaneContext *const p = &s->plane[plane_index];

    RangeCoder *const c   = &s->c;

    int x;

    int run_index = s->run_index;

    int run_count = 0;

    int run_mode  = 0;



    if (s->ac) {

        if (c->bytestream_end - c->bytestream < w * 20) {

            av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");

            return AVERROR_INVALIDDATA;

        }

    } else {

        if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < w * 4) {

            av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");

            return AVERROR_INVALIDDATA;

        }

    }



    for (x = 0; x < w; x++) {

        int diff, context;



        context = get_context(p, sample[0] + x, sample[1] + x, sample[2] + x);

        diff    = sample[0][x] - predict(sample[0] + x, sample[1] + x);



        if (context < 0) {

            context = -context;

            diff    = -diff;

        }



        diff = fold(diff, bits);



        if (s->ac) {

            if (s->flags & CODEC_FLAG_PASS1) {

                put_symbol_inline(c, p->state[context], diff, 1, s->rc_stat,

                                  s->rc_stat2[p->quant_table_index][context]);

            } else {

                put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL);

            }

        } else {

            if (context == 0)

                run_mode = 1;



            if (run_mode) {

                if (diff) {

                    while (run_count >= 1 << ff_log2_run[run_index]) {

                        run_count -= 1 << ff_log2_run[run_index];

                        run_index++;

                        put_bits(&s->pb, 1, 1);

                    }



                    put_bits(&s->pb, 1 + ff_log2_run[run_index], run_count);

                    if (run_index)

                        run_index--;

                    run_count = 0;

                    run_mode  = 0;

                    if (diff > 0)

                        diff--;

                } else {

                    run_count++;

                }

            }



            av_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",

                    run_count, run_index, run_mode, x,

                    (int)put_bits_count(&s->pb));



            if (run_mode == 0)

                put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits);

        }

    }

    if (run_mode) {

        while (run_count >= 1 << ff_log2_run[run_index]) {

            run_count -= 1 << ff_log2_run[run_index];

            run_index++;

            put_bits(&s->pb, 1, 1);

        }



        if (run_count)

            put_bits(&s->pb, 1, 1);

    }

    s->run_index = run_index;



    return 0;

}

static av_always_inline int FUNC_0(FFV1Context *s, int w,

                                        int16_t *sample[3],

                                        int plane_index, int bits)

{

    PlaneContext *const p = &s->plane[plane_index];

    RangeCoder *const c   = &s->c;

    int VAR_0;

    int VAR_1 = s->VAR_1;

    int VAR_2 = 0;

    int VAR_3  = 0;



    if (s->ac) {

        if (c->bytestream_end - c->bytestream < w * 20) {

            av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");

            return AVERROR_INVALIDDATA;

        }

    } else {

        if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < w * 4) {

            av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");

            return AVERROR_INVALIDDATA;

        }

    }



    for (VAR_0 = 0; VAR_0 < w; VAR_0++) {

        int VAR_4, VAR_5;



        VAR_5 = get_context(p, sample[0] + VAR_0, sample[1] + VAR_0, sample[2] + VAR_0);

        VAR_4    = sample[0][VAR_0] - predict(sample[0] + VAR_0, sample[1] + VAR_0);



        if (VAR_5 < 0) {

            VAR_5 = -VAR_5;

            VAR_4    = -VAR_4;

        }



        VAR_4 = fold(VAR_4, bits);



        if (s->ac) {

            if (s->flags & CODEC_FLAG_PASS1) {

                put_symbol_inline(c, p->state[VAR_5], VAR_4, 1, s->rc_stat,

                                  s->rc_stat2[p->quant_table_index][VAR_5]);

            } else {

                put_symbol_inline(c, p->state[VAR_5], VAR_4, 1, NULL, NULL);

            }

        } else {

            if (VAR_5 == 0)

                VAR_3 = 1;



            if (VAR_3) {

                if (VAR_4) {

                    while (VAR_2 >= 1 << ff_log2_run[VAR_1]) {

                        VAR_2 -= 1 << ff_log2_run[VAR_1];

                        VAR_1++;

                        put_bits(&s->pb, 1, 1);

                    }



                    put_bits(&s->pb, 1 + ff_log2_run[VAR_1], VAR_2);

                    if (VAR_1)

                        VAR_1--;

                    VAR_2 = 0;

                    VAR_3  = 0;

                    if (VAR_4 > 0)

                        VAR_4--;

                } else {

                    VAR_2++;

                }

            }



            av_dlog(s->avctx, "count:%d index:%d, mode:%d, VAR_0:%d pos:%d\n",

                    VAR_2, VAR_1, VAR_3, VAR_0,

                    (int)put_bits_count(&s->pb));



            if (VAR_3 == 0)

                put_vlc_symbol(&s->pb, &p->vlc_state[VAR_5], VAR_4, bits);

        }

    }

    if (VAR_3) {

        while (VAR_2 >= 1 << ff_log2_run[VAR_1]) {

            VAR_2 -= 1 << ff_log2_run[VAR_1];

            VAR_1++;

            put_bits(&s->pb, 1, 1);

        }



        if (VAR_2)

            put_bits(&s->pb, 1, 1);

    }

    s->VAR_1 = VAR_1;



    return 0;

}

static av_always_inline int FUNC_0(FFV1Context *s, int w,
int16_t *sample[3],
int plane_index, int bits)
{ PlaneContext *const p = &s->plane[plane_index]; RangeCoder *const c   = &s->c; int VAR_0; int VAR_1 = s->VAR_1; int VAR_2 = 0; int VAR_3  = 0; if (s->ac) { if (c->bytestream_end - c->bytestream < w * 20) { av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return AVERROR_INVALIDDATA; } } else { if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < w * 4) { av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return AVERROR_INVALIDDATA; } } for (VAR_0 = 0; VAR_0 < w; VAR_0++) { int VAR_4, VAR_5; VAR_5 = get_context(p, sample[0] + VAR_0, sample[1] + VAR_0, sample[2] + VAR_0); VAR_4    = sample[0][VAR_0] - predict(sample[0] + VAR_0, sample[1] + VAR_0); if (VAR_5 < 0) { VAR_5 = -VAR_5; VAR_4    = -VAR_4; } VAR_4 = fold(VAR_4, bits); if (s->ac) { if (s->flags & CODEC_FLAG_PASS1) { put_symbol_inline(c, p->state[VAR_5], VAR_4, 1, s->rc_stat,
s->rc_stat2[p->quant_table_index][VAR_5]); } else { put_symbol_inline(c, p->state[VAR_5], VAR_4, 1, NULL, NULL); } } else { if (VAR_5 == 0)
VAR_3 = 1; if (VAR_3) { if (VAR_4) { while (VAR_2 >= 1 << ff_log2_run[VAR_1]) { VAR_2 -= 1 << ff_log2_run[VAR_1]; VAR_1++; put_bits(&s->pb, 1, 1); } put_bits(&s->pb, 1 + ff_log2_run[VAR_1], VAR_2); if (VAR_1)
VAR_1--; VAR_2 = 0; VAR_3  = 0; if (VAR_4 > 0)
VAR_4--; } else { VAR_2++; } } av_dlog(s->avctx, "count:%d index:%d, mode:%d, VAR_0:%d pos:%d\n",
VAR_2, VAR_1, VAR_3, VAR_0,
(int)put_bits_count(&s->pb)); if (VAR_3 == 0)
put_vlc_symbol(&s->pb, &p->vlc_state[VAR_5], VAR_4, bits); } } if (VAR_3) { while (VAR_2 >= 1 << ff_log2_run[VAR_1]) { VAR_2 -= 1 << ff_log2_run[VAR_1]; VAR_1++; put_bits(&s->pb, 1, 1); } if (VAR_2)
put_bits(&s->pb, 1, 1); } s->VAR_1 = VAR_1; return 0; }