static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s,
                                  void *last, void *dst, int last2, int w,
                                  int stride, int comp, int bits)
{
    int i, x = 0;
    int Ra, Rb, Rc, Rd;
    int D0, D1, D2;
    while (x < w) {
        int err, pred;
        /* compute gradients */
        Ra = x ? R(dst, x - stride) : R(last, x);
        Rb = R(last, x);
        Rc = x ? R(last, x - stride) : last2;
        Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride);
        D0 = Rd - Rb;
        D1 = Rb - Rc;
        D2 = Rc - Ra;
        /* run mode */
        if ((FFABS(D0) <= state->near) &&
            (FFABS(D1) <= state->near) &&
            (FFABS(D2) <= state->near)) {
            int r;
            int RItype;
            /* decode full runs while available */
            while (get_bits1(&s->gb)) {
                int r;
                r = 1 << ff_log2_run[state->run_index[comp]];
                if (x + r * stride > w)
                    r = (w - x) / stride;
                for (i = 0; i < r; i++) {
                    W(dst, x, Ra);
                    x += stride;
                }
                /* if EOL reached, we stop decoding */
                if (r != 1 << ff_log2_run[state->run_index[comp]])
                if (state->run_index[comp] < 31)
                    state->run_index[comp]++;
                if (x + stride > w)
            }
            /* decode aborted run */
            r = ff_log2_run[state->run_index[comp]];
            if (r)
                r = get_bits_long(&s->gb, r);
            if (x + r * stride > w) {
                r = (w - x) / stride;
            }
            for (i = 0; i < r; i++) {
                W(dst, x, Ra);
                x += stride;
            }
            if (x >= w) {
                av_log(NULL, AV_LOG_ERROR, "run overflow\n");
                av_assert0(x <= w);
            }
            /* decode run termination value */
            Rb     = R(last, x);
            RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0;
            err    = ls_get_code_runterm(&s->gb, state, RItype,
                                         ff_log2_run[state->run_index[comp]]);
            if (state->run_index[comp])
                state->run_index[comp]--;
            if (state->near && RItype) {
                pred = Ra + err;
            } else {
                if (Rb < Ra)
                    pred = Rb - err;
                else
                    pred = Rb + err;
            }
        } else { /* regular mode */
            int context, sign;
            context = ff_jpegls_quantize(state, D0) * 81 +
                      ff_jpegls_quantize(state, D1) *  9 +
                      ff_jpegls_quantize(state, D2);
            pred    = mid_pred(Ra, Ra + Rb - Rc, Rb);
            if (context < 0) {
                context = -context;
                sign    = 1;
            } else {
                sign = 0;
            }
            if (sign) {
                pred = av_clip(pred - state->C[context], 0, state->maxval);
                err  = -ls_get_code_regular(&s->gb, state, context);
            } else {
                pred = av_clip(pred + state->C[context], 0, state->maxval);
                err  = ls_get_code_regular(&s->gb, state, context);
            }
            /* we have to do something more for near-lossless coding */
            pred += err;
        }
        if (state->near) {
            if (pred < -state->near)
                pred += state->range * state->twonear;
            else if (pred > state->maxval + state->near)
                pred -= state->range * state->twonear;
            pred = av_clip(pred, 0, state->maxval);
        }
        pred &= state->maxval;
        W(dst, x, pred);
        x += stride;
    }
}
static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s,
                                  void *last, void *dst, int last2, int w,
                                  int stride, int comp, int bits)
{
    int i, x = 0;
    int Ra, Rb, Rc, Rd;
    int D0, D1, D2;
    while (x < w) {
        int err, pred;
        
        Ra = x ? R(dst, x - stride) : R(last, x);
        Rb = R(last, x);
        Rc = x ? R(last, x - stride) : last2;
        Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride);
        D0 = Rd - Rb;
        D1 = Rb - Rc;
        D2 = Rc - Ra;
        
        if ((FFABS(D0) <= state->near) &&
            (FFABS(D1) <= state->near) &&
            (FFABS(D2) <= state->near)) {
            int r;
            int RItype;
            
            while (get_bits1(&s->gb)) {
                int r;
                r = 1 << ff_log2_run[state->run_index[comp]];
                if (x + r * stride > w)
                    r = (w - x) / stride;
                for (i = 0; i < r; i++) {
                    W(dst, x, Ra);
                    x += stride;
                }
                
                if (r != 1 << ff_log2_run[state->run_index[comp]])
                if (state->run_index[comp] < 31)
                    state->run_index[comp]++;
                if (x + stride > w)
            }
            
            r = ff_log2_run[state->run_index[comp]];
            if (r)
                r = get_bits_long(&s->gb, r);
            if (x + r * stride > w) {
                r = (w - x) / stride;
            }
            for (i = 0; i < r; i++) {
                W(dst, x, Ra);
                x += stride;
            }
            if (x >= w) {
                av_log(NULL, AV_LOG_ERROR, "run overflow\n");
                av_assert0(x <= w);
            }
            
            Rb     = R(last, x);
            RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0;
            err    = ls_get_code_runterm(&s->gb, state, RItype,
                                         ff_log2_run[state->run_index[comp]]);
            if (state->run_index[comp])
                state->run_index[comp]--;
            if (state->near && RItype) {
                pred = Ra + err;
            } else {
                if (Rb < Ra)
                    pred = Rb - err;
                else
                    pred = Rb + err;
            }
        } else { 
            int context, sign;
            context = ff_jpegls_quantize(state, D0) * 81 +
                      ff_jpegls_quantize(state, D1) *  9 +
                      ff_jpegls_quantize(state, D2);
            pred    = mid_pred(Ra, Ra + Rb - Rc, Rb);
            if (context < 0) {
                context = -context;
                sign    = 1;
            } else {
                sign = 0;
            }
            if (sign) {
                pred = av_clip(pred - state->C[context], 0, state->maxval);
                err  = -ls_get_code_regular(&s->gb, state, context);
            } else {
                pred = av_clip(pred + state->C[context], 0, state->maxval);
                err  = ls_get_code_regular(&s->gb, state, context);
            }
            
            pred += err;
        }
        if (state->near) {
            if (pred < -state->near)
                pred += state->range * state->twonear;
            else if (pred > state->maxval + state->near)
                pred -= state->range * state->twonear;
            pred = av_clip(pred, 0, state->maxval);
        }
        pred &= state->maxval;
        W(dst, x, pred);
        x += stride;
    }
}
static inline void FUNC_0(JLSState *VAR_0, MJpegDecodeContext *VAR_1,
                                  void *VAR_2, void *VAR_3, int VAR_4, int VAR_5,
                                  int VAR_6, int VAR_7, int VAR_8)
{
    int VAR_9, VAR_10 = 0;
    int VAR_11, VAR_12, VAR_13, VAR_14;
    int VAR_15, VAR_16, VAR_17;
    while (VAR_10 < VAR_5) {
        int VAR_18, VAR_19;
        
        VAR_11 = VAR_10 ? R(VAR_3, VAR_10 - VAR_6) : R(VAR_2, VAR_10);
        VAR_12 = R(VAR_2, VAR_10);
        VAR_13 = VAR_10 ? R(VAR_2, VAR_10 - VAR_6) : VAR_4;
        VAR_14 = (VAR_10 >= VAR_5 - VAR_6) ? R(VAR_2, VAR_10) : R(VAR_2, VAR_10 + VAR_6);
        VAR_15 = VAR_14 - VAR_12;
        VAR_16 = VAR_12 - VAR_13;
        VAR_17 = VAR_13 - VAR_11;
        
        if ((FFABS(VAR_15) <= VAR_0->near) &&
            (FFABS(VAR_16) <= VAR_0->near) &&
            (FFABS(VAR_17) <= VAR_0->near)) {
            int VAR_22;
            int VAR_21;
            
            while (get_bits1(&VAR_1->gb)) {
                int VAR_22;
                VAR_22 = 1 << ff_log2_run[VAR_0->run_index[VAR_7]];
                if (VAR_10 + VAR_22 * VAR_6 > VAR_5)
                    VAR_22 = (VAR_5 - VAR_10) / VAR_6;
                for (VAR_9 = 0; VAR_9 < VAR_22; VAR_9++) {
                    W(VAR_3, VAR_10, VAR_11);
                    VAR_10 += VAR_6;
                }
                
                if (VAR_22 != 1 << ff_log2_run[VAR_0->run_index[VAR_7]])
                if (VAR_0->run_index[VAR_7] < 31)
                    VAR_0->run_index[VAR_7]++;
                if (VAR_10 + VAR_6 > VAR_5)
            }
            
            VAR_22 = ff_log2_run[VAR_0->run_index[VAR_7]];
            if (VAR_22)
                VAR_22 = get_bits_long(&VAR_1->gb, VAR_22);
            if (VAR_10 + VAR_22 * VAR_6 > VAR_5) {
                VAR_22 = (VAR_5 - VAR_10) / VAR_6;
            }
            for (VAR_9 = 0; VAR_9 < VAR_22; VAR_9++) {
                W(VAR_3, VAR_10, VAR_11);
                VAR_10 += VAR_6;
            }
            if (VAR_10 >= VAR_5) {
                av_log(NULL, AV_LOG_ERROR, "run overflow\n");
                av_assert0(VAR_10 <= VAR_5);
            }
            
            VAR_12     = R(VAR_2, VAR_10);
            VAR_21 = (FFABS(VAR_11 - VAR_12) <= VAR_0->near) ? 1 : 0;
            VAR_18    = ls_get_code_runterm(&VAR_1->gb, VAR_0, VAR_21,
                                         ff_log2_run[VAR_0->run_index[VAR_7]]);
            if (VAR_0->run_index[VAR_7])
                VAR_0->run_index[VAR_7]--;
            if (VAR_0->near && VAR_21) {
                VAR_19 = VAR_11 + VAR_18;
            } else {
                if (VAR_12 < VAR_11)
                    VAR_19 = VAR_12 - VAR_18;
                else
                    VAR_19 = VAR_12 + VAR_18;
            }
        } else { 
            int VAR_22, VAR_23;
            VAR_22 = ff_jpegls_quantize(VAR_0, VAR_15) * 81 +
                      ff_jpegls_quantize(VAR_0, VAR_16) *  9 +
                      ff_jpegls_quantize(VAR_0, VAR_17);
            VAR_19    = mid_pred(VAR_11, VAR_11 + VAR_12 - VAR_13, VAR_12);
            if (VAR_22 < 0) {
                VAR_22 = -VAR_22;
                VAR_23    = 1;
            } else {
                VAR_23 = 0;
            }
            if (VAR_23) {
                VAR_19 = av_clip(VAR_19 - VAR_0->C[VAR_22], 0, VAR_0->maxval);
                VAR_18  = -ls_get_code_regular(&VAR_1->gb, VAR_0, VAR_22);
            } else {
                VAR_19 = av_clip(VAR_19 + VAR_0->C[VAR_22], 0, VAR_0->maxval);
                VAR_18  = ls_get_code_regular(&VAR_1->gb, VAR_0, VAR_22);
            }
            
            VAR_19 += VAR_18;
        }
        if (VAR_0->near) {
            if (VAR_19 < -VAR_0->near)
                VAR_19 += VAR_0->range * VAR_0->twonear;
            else if (VAR_19 > VAR_0->maxval + VAR_0->near)
                VAR_19 -= VAR_0->range * VAR_0->twonear;
            VAR_19 = av_clip(VAR_19, 0, VAR_0->maxval);
        }
        VAR_19 &= VAR_0->maxval;
        W(VAR_3, VAR_10, VAR_19);
        VAR_10 += VAR_6;
    }
}
static inline void FUNC_0(JLSState *VAR_0, MJpegDecodeContext *VAR_1,
void *VAR_2, void *VAR_3, int VAR_4, int VAR_5,
int VAR_6, int VAR_7, int VAR_8)
{ int VAR_9, VAR_10 = 0; int VAR_11, VAR_12, VAR_13, VAR_14; int VAR_15, VAR_16, VAR_17; while (VAR_10 < VAR_5) { int VAR_18, VAR_19; VAR_11 = VAR_10 ? R(VAR_3, VAR_10 - VAR_6) : R(VAR_2, VAR_10); VAR_12 = R(VAR_2, VAR_10); VAR_13 = VAR_10 ? R(VAR_2, VAR_10 - VAR_6) : VAR_4; VAR_14 = (VAR_10 >= VAR_5 - VAR_6) ? R(VAR_2, VAR_10) : R(VAR_2, VAR_10 + VAR_6); VAR_15 = VAR_14 - VAR_12; VAR_16 = VAR_12 - VAR_13; VAR_17 = VAR_13 - VAR_11; if ((FFABS(VAR_15) <= VAR_0->near) &&
(FFABS(VAR_16) <= VAR_0->near) &&
(FFABS(VAR_17) <= VAR_0->near)) { int VAR_22; int VAR_21; while (get_bits1(&VAR_1->gb)) { int VAR_22; VAR_22 = 1 << ff_log2_run[VAR_0->run_index[VAR_7]]; if (VAR_10 + VAR_22 * VAR_6 > VAR_5)
VAR_22 = (VAR_5 - VAR_10) / VAR_6; for (VAR_9 = 0; VAR_9 < VAR_22; VAR_9++) { W(VAR_3, VAR_10, VAR_11); VAR_10 += VAR_6; } if (VAR_22 != 1 << ff_log2_run[VAR_0->run_index[VAR_7]])
if (VAR_0->run_index[VAR_7] < 31)
VAR_0->run_index[VAR_7]++; if (VAR_10 + VAR_6 > VAR_5)
} VAR_22 = ff_log2_run[VAR_0->run_index[VAR_7]]; if (VAR_22)
VAR_22 = get_bits_long(&VAR_1->gb, VAR_22); if (VAR_10 + VAR_22 * VAR_6 > VAR_5) { VAR_22 = (VAR_5 - VAR_10) / VAR_6; } for (VAR_9 = 0; VAR_9 < VAR_22; VAR_9++) { W(VAR_3, VAR_10, VAR_11); VAR_10 += VAR_6; } if (VAR_10 >= VAR_5) { av_log(NULL, AV_LOG_ERROR, "run overflow\n"); av_assert0(VAR_10 <= VAR_5); } VAR_12     = R(VAR_2, VAR_10); VAR_21 = (FFABS(VAR_11 - VAR_12) <= VAR_0->near) ? 1 : 0; VAR_18    = ls_get_code_runterm(&VAR_1->gb, VAR_0, VAR_21,
ff_log2_run[VAR_0->run_index[VAR_7]]); if (VAR_0->run_index[VAR_7])
VAR_0->run_index[VAR_7]--; if (VAR_0->near && VAR_21) { VAR_19 = VAR_11 + VAR_18; } else { if (VAR_12 < VAR_11)
VAR_19 = VAR_12 - VAR_18; else
VAR_19 = VAR_12 + VAR_18; } } else { int VAR_22, VAR_23; VAR_22 = ff_jpegls_quantize(VAR_0, VAR_15) * 81 +
ff_jpegls_quantize(VAR_0, VAR_16) *  9 +
ff_jpegls_quantize(VAR_0, VAR_17); VAR_19    = mid_pred(VAR_11, VAR_11 + VAR_12 - VAR_13, VAR_12); if (VAR_22 < 0) { VAR_22 = -VAR_22; VAR_23    = 1; } else { VAR_23 = 0; } if (VAR_23) { VAR_19 = av_clip(VAR_19 - VAR_0->C[VAR_22], 0, VAR_0->maxval); VAR_18  = -ls_get_code_regular(&VAR_1->gb, VAR_0, VAR_22); } else { VAR_19 = av_clip(VAR_19 + VAR_0->C[VAR_22], 0, VAR_0->maxval); VAR_18  = ls_get_code_regular(&VAR_1->gb, VAR_0, VAR_22); } VAR_19 += VAR_18; } if (VAR_0->near) { if (VAR_19 < -VAR_0->near)
VAR_19 += VAR_0->range * VAR_0->twonear; else if (VAR_19 > VAR_0->maxval + VAR_0->near)
VAR_19 -= VAR_0->range * VAR_0->twonear; VAR_19 = av_clip(VAR_19, 0, VAR_0->maxval); } VAR_19 &= VAR_0->maxval; W(VAR_3, VAR_10, VAR_19); VAR_10 += VAR_6; } }