static int decode_unit(SCPRContext *s, PixelModel *pixel, unsigned step, unsigned *rval)

{

    GetByteContext *gb = &s->gb;

    RangeCoder *rc = &s->rc;

    unsigned totfr = pixel->total_freq;

    unsigned value, x = 0, cumfr = 0, cnt_x = 0;

    int i, j, ret, c, cnt_c;



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

        return ret;



    while (x < 16) {

        cnt_x = pixel->lookup[x];

        if (value >= cumfr + cnt_x)

            cumfr += cnt_x;

        else

            break;

        x++;




    c = x * 16;

    cnt_c = 0;

    while (c < 256) {

        cnt_c = pixel->freq[c];

        if (value >= cumfr + cnt_c)

            cumfr += cnt_c;

        else

            break;

        c++;







    if ((ret = s->decode(gb, rc, cumfr, cnt_c, totfr)) < 0)

        return ret;



    pixel->freq[c] = cnt_c + step;

    pixel->lookup[x] = cnt_x + step;

    totfr += step;

    if (totfr > BOT) {

        totfr = 0;

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

            unsigned nc = (pixel->freq[i] >> 1) + 1;

            pixel->freq[i] = nc;

            totfr += nc;


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

            unsigned sum = 0;

            unsigned i16_17 = i << 4;

            for (j = 0; j < 16; j++)

                sum += pixel->freq[i16_17 + j];

            pixel->lookup[i] = sum;



    pixel->total_freq = totfr;



    *rval = c & s->cbits;



    return 0;

static int decode_unit(SCPRContext *s, PixelModel *pixel, unsigned step, unsigned *rval)

{

    GetByteContext *gb = &s->gb;

    RangeCoder *rc = &s->rc;

    unsigned totfr = pixel->total_freq;

    unsigned value, x = 0, cumfr = 0, cnt_x = 0;

    int i, j, ret, c, cnt_c;



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

        return ret;



    while (x < 16) {

        cnt_x = pixel->lookup[x];

        if (value >= cumfr + cnt_x)

            cumfr += cnt_x;

        else

            break;

        x++;




    c = x * 16;

    cnt_c = 0;

    while (c < 256) {

        cnt_c = pixel->freq[c];

        if (value >= cumfr + cnt_c)

            cumfr += cnt_c;

        else

            break;

        c++;







    if ((ret = s->decode(gb, rc, cumfr, cnt_c, totfr)) < 0)

        return ret;



    pixel->freq[c] = cnt_c + step;

    pixel->lookup[x] = cnt_x + step;

    totfr += step;

    if (totfr > BOT) {

        totfr = 0;

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

            unsigned nc = (pixel->freq[i] >> 1) + 1;

            pixel->freq[i] = nc;

            totfr += nc;


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

            unsigned sum = 0;

            unsigned i16_17 = i << 4;

            for (j = 0; j < 16; j++)

                sum += pixel->freq[i16_17 + j];

            pixel->lookup[i] = sum;



    pixel->total_freq = totfr;



    *rval = c & s->cbits;



    return 0;

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

{

    GetByteContext *gb = &VAR_0->gb;

    RangeCoder *rc = &VAR_0->rc;

    unsigned VAR_4 = VAR_1->total_freq;

    unsigned VAR_5, VAR_6 = 0, VAR_7 = 0, VAR_8 = 0;

    int VAR_9, VAR_10, VAR_11, VAR_12, VAR_13;



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

        return VAR_11;



    while (VAR_6 < 16) {

        VAR_8 = VAR_1->lookup[VAR_6];

        if (VAR_5 >= VAR_7 + VAR_8)

            VAR_7 += VAR_8;

        else

            break;

        VAR_6++;




    VAR_12 = VAR_6 * 16;

    VAR_13 = 0;

    while (VAR_12 < 256) {

        VAR_13 = VAR_1->freq[VAR_12];

        if (VAR_5 >= VAR_7 + VAR_13)

            VAR_7 += VAR_13;

        else

            break;

        VAR_12++;







    if ((VAR_11 = VAR_0->decode(gb, rc, VAR_7, VAR_13, VAR_4)) < 0)

        return VAR_11;



    VAR_1->freq[VAR_12] = VAR_13 + VAR_2;

    VAR_1->lookup[VAR_6] = VAR_8 + VAR_2;

    VAR_4 += VAR_2;

    if (VAR_4 > BOT) {

        VAR_4 = 0;

        for (VAR_9 = 0; VAR_9 < 256; VAR_9++) {

            unsigned VAR_14 = (VAR_1->freq[VAR_9] >> 1) + 1;

            VAR_1->freq[VAR_9] = VAR_14;

            VAR_4 += VAR_14;


        for (VAR_9 = 0; VAR_9 < 16; VAR_9++) {

            unsigned VAR_15 = 0;

            unsigned VAR_16 = VAR_9 << 4;

            for (VAR_10 = 0; VAR_10 < 16; VAR_10++)

                VAR_15 += VAR_1->freq[VAR_16 + VAR_10];

            VAR_1->lookup[VAR_9] = VAR_15;



    VAR_1->total_freq = VAR_4;



    *VAR_3 = VAR_12 & VAR_0->cbits;



    return 0;

static int FUNC_0(SCPRContext *VAR_0, PixelModel *VAR_1, unsigned VAR_2, unsigned *VAR_3)
{ GetByteContext *gb = &VAR_0->gb; RangeCoder *rc = &VAR_0->rc; unsigned VAR_4 = VAR_1->total_freq; unsigned VAR_5, VAR_6 = 0, VAR_7 = 0, VAR_8 = 0; int VAR_9, VAR_10, VAR_11, VAR_12, VAR_13; if ((VAR_11 = VAR_0->get_freq(rc, VAR_4, &VAR_5)) < 0)
return VAR_11; while (VAR_6 < 16) { VAR_8 = VAR_1->lookup[VAR_6]; if (VAR_5 >= VAR_7 + VAR_8)
VAR_7 += VAR_8; else
break; VAR_6++; VAR_12 = VAR_6 * 16; VAR_13 = 0; while (VAR_12 < 256) { VAR_13 = VAR_1->freq[VAR_12]; if (VAR_5 >= VAR_7 + VAR_13)
VAR_7 += VAR_13; else
break; VAR_12++; if ((VAR_11 = VAR_0->decode(gb, rc, VAR_7, VAR_13, VAR_4)) < 0)
return VAR_11; VAR_1->freq[VAR_12] = VAR_13 + VAR_2; VAR_1->lookup[VAR_6] = VAR_8 + VAR_2; VAR_4 += VAR_2; if (VAR_4 > BOT) { VAR_4 = 0; for (VAR_9 = 0; VAR_9 < 256; VAR_9++) { unsigned VAR_14 = (VAR_1->freq[VAR_9] >> 1) + 1; VAR_1->freq[VAR_9] = VAR_14; VAR_4 += VAR_14; for (VAR_9 = 0; VAR_9 < 16; VAR_9++) { unsigned VAR_15 = 0; unsigned VAR_16 = VAR_9 << 4; for (VAR_10 = 0; VAR_10 < 16; VAR_10++) VAR_15 += VAR_1->freq[VAR_16 + VAR_10]; VAR_1->lookup[VAR_9] = VAR_15; VAR_1->total_freq = VAR_4; *VAR_3 = VAR_12 & VAR_0->cbits; return 0;