static int decode_value(SCPRContext *s, unsigned *cnt, unsigned maxc, unsigned step, unsigned *rval)

{

    GetByteContext *gb = &s->gb;

    RangeCoder *rc = &s->rc;

    unsigned totfr = cnt[maxc];

    unsigned value;

    unsigned c = 0, cumfr = 0, cnt_c = 0;

    int i, ret;



    if ((ret = s->get_freq(rc, totfr, &value)) < 0)

        return ret;



    while (c < maxc) {

        cnt_c = cnt[c];

        if (value >= cumfr + cnt_c)

            cumfr += cnt_c;

        else

            break;

        c++;

    }

    s->decode(gb, rc, cumfr, cnt_c, totfr);



    cnt[c] = cnt_c + step;

    totfr += step;

    if (totfr > BOT) {

        totfr = 0;

        for (i = 0; i < maxc; i++) {

            unsigned nc = (cnt[i] >> 1) + 1;

            cnt[i] = nc;

            totfr += nc;

        }

    }



    cnt[maxc] = totfr;

    *rval = c;



    return 0;

}

static int decode_value(SCPRContext *s, unsigned *cnt, unsigned maxc, unsigned step, unsigned *rval)

{

    GetByteContext *gb = &s->gb;

    RangeCoder *rc = &s->rc;

    unsigned totfr = cnt[maxc];

    unsigned value;

    unsigned c = 0, cumfr = 0, cnt_c = 0;

    int i, ret;



    if ((ret = s->get_freq(rc, totfr, &value)) < 0)

        return ret;



    while (c < maxc) {

        cnt_c = cnt[c];

        if (value >= cumfr + cnt_c)

            cumfr += cnt_c;

        else

            break;

        c++;

    }

    s->decode(gb, rc, cumfr, cnt_c, totfr);



    cnt[c] = cnt_c + step;

    totfr += step;

    if (totfr > BOT) {

        totfr = 0;

        for (i = 0; i < maxc; i++) {

            unsigned nc = (cnt[i] >> 1) + 1;

            cnt[i] = nc;

            totfr += nc;

        }

    }



    cnt[maxc] = totfr;

    *rval = c;



    return 0;

}

static int FUNC_0(SCPRContext *VAR_0, unsigned *VAR_1, unsigned VAR_2, unsigned VAR_3, unsigned *VAR_4)

{

    GetByteContext *gb = &VAR_0->gb;

    RangeCoder *rc = &VAR_0->rc;

    unsigned VAR_5 = VAR_1[VAR_2];

    unsigned VAR_6;

    unsigned VAR_7 = 0, VAR_8 = 0, VAR_9 = 0;

    int VAR_10, VAR_11;



    if ((VAR_11 = VAR_0->get_freq(rc, VAR_5, &VAR_6)) < 0)

        return VAR_11;



    while (VAR_7 < VAR_2) {

        VAR_9 = VAR_1[VAR_7];

        if (VAR_6 >= VAR_8 + VAR_9)

            VAR_8 += VAR_9;

        else

            break;

        VAR_7++;

    }

    VAR_0->decode(gb, rc, VAR_8, VAR_9, VAR_5);



    VAR_1[VAR_7] = VAR_9 + VAR_3;

    VAR_5 += VAR_3;

    if (VAR_5 > BOT) {

        VAR_5 = 0;

        for (VAR_10 = 0; VAR_10 < VAR_2; VAR_10++) {

            unsigned VAR_12 = (VAR_1[VAR_10] >> 1) + 1;

            VAR_1[VAR_10] = VAR_12;

            VAR_5 += VAR_12;

        }

    }



    VAR_1[VAR_2] = VAR_5;

    *VAR_4 = VAR_7;



    return 0;

}

static int FUNC_0(SCPRContext *VAR_0, unsigned *VAR_1, unsigned VAR_2, unsigned VAR_3, unsigned *VAR_4)
{ GetByteContext *gb = &VAR_0->gb; RangeCoder *rc = &VAR_0->rc; unsigned VAR_5 = VAR_1[VAR_2]; unsigned VAR_6; unsigned VAR_7 = 0, VAR_8 = 0, VAR_9 = 0; int VAR_10, VAR_11; if ((VAR_11 = VAR_0->get_freq(rc, VAR_5, &VAR_6)) < 0)
return VAR_11; while (VAR_7 < VAR_2) { VAR_9 = VAR_1[VAR_7]; if (VAR_6 >= VAR_8 + VAR_9)
VAR_8 += VAR_9; else
break; VAR_7++; } VAR_0->decode(gb, rc, VAR_8, VAR_9, VAR_5); VAR_1[VAR_7] = VAR_9 + VAR_3; VAR_5 += VAR_3; if (VAR_5 > BOT) { VAR_5 = 0; for (VAR_10 = 0; VAR_10 < VAR_2; VAR_10++) { unsigned VAR_12 = (VAR_1[VAR_10] >> 1) + 1; VAR_1[VAR_10] = VAR_12; VAR_5 += VAR_12; } } VAR_1[VAR_2] = VAR_5; *VAR_4 = VAR_7; return 0; }