static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel, int *last)

{

    int t, t2;

    int sign, base, add, ret;

    WvChannel *c = &ctx->ch[channel];



    *last = 0;



    if((ctx->ch[0].median[0] < 2U) && (ctx->ch[1].median[0] < 2U) && !ctx->zero && !ctx->one){

        if(ctx->zeroes){

            ctx->zeroes--;

            if(ctx->zeroes){

                c->slow_level -= LEVEL_DECAY(c->slow_level);

                return 0;

            }

        }else{

            t = get_unary_0_33(gb);

            if(t >= 2) t = get_bits(gb, t - 1) | (1 << (t-1));

            ctx->zeroes = t;

            if(ctx->zeroes){

                memset(ctx->ch[0].median, 0, sizeof(ctx->ch[0].median));

                memset(ctx->ch[1].median, 0, sizeof(ctx->ch[1].median));

                c->slow_level -= LEVEL_DECAY(c->slow_level);

                return 0;

            }

        }

    }



    if(get_bits_count(gb) >= ctx->data_size){

        *last = 1;

        return 0;

    }



    if(ctx->zero){

        t = 0;

        ctx->zero = 0;

    }else{

        t = get_unary_0_33(gb);

        if(get_bits_count(gb) >= ctx->data_size){

            *last = 1;

            return 0;

        }

        if(t == 16) {

            t2 = get_unary_0_33(gb);

            if(t2 < 2) t += t2;

            else t += get_bits(gb, t2 - 1) | (1 << (t2 - 1));

        }



        if(ctx->one){

            ctx->one = t&1;

            t = (t>>1) + 1;

        }else{

            ctx->one = t&1;

            t >>= 1;

        }

        ctx->zero = !ctx->one;

    }



    if(ctx->hybrid && !channel)

        update_error_limit(ctx);



    if(!t){

        base = 0;

        add = GET_MED(0) - 1;

        DEC_MED(0);

    }else if(t == 1){

        base = GET_MED(0);

        add = GET_MED(1) - 1;

        INC_MED(0);

        DEC_MED(1);

    }else if(t == 2){

        base = GET_MED(0) + GET_MED(1);

        add = GET_MED(2) - 1;

        INC_MED(0);

        INC_MED(1);

        DEC_MED(2);

    }else{

        base = GET_MED(0) + GET_MED(1) + GET_MED(2) * (t - 2);

        add = GET_MED(2) - 1;

        INC_MED(0);

        INC_MED(1);

        INC_MED(2);

    }

    if(!c->error_limit){

        ret = base + get_tail(gb, add);

    }else{

        int mid = (base*2 + add + 1) >> 1;

        while(add > c->error_limit){

            if(get_bits1(gb)){

                add -= (mid - base);

                base = mid;

            }else

                add = mid - base - 1;

            mid = (base*2 + add + 1) >> 1;

        }

        ret = mid;

    }

    sign = get_bits1(gb);

    if(ctx->hybrid_bitrate)

        c->slow_level += wp_log2(ret) - LEVEL_DECAY(c->slow_level);

    return sign ? ~ret : ret;

}

static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel, int *last)

{

    int t, t2;

    int sign, base, add, ret;

    WvChannel *c = &ctx->ch[channel];



    *last = 0;



    if((ctx->ch[0].median[0] < 2U) && (ctx->ch[1].median[0] < 2U) && !ctx->zero && !ctx->one){

        if(ctx->zeroes){

            ctx->zeroes--;

            if(ctx->zeroes){

                c->slow_level -= LEVEL_DECAY(c->slow_level);

                return 0;

            }

        }else{

            t = get_unary_0_33(gb);

            if(t >= 2) t = get_bits(gb, t - 1) | (1 << (t-1));

            ctx->zeroes = t;

            if(ctx->zeroes){

                memset(ctx->ch[0].median, 0, sizeof(ctx->ch[0].median));

                memset(ctx->ch[1].median, 0, sizeof(ctx->ch[1].median));

                c->slow_level -= LEVEL_DECAY(c->slow_level);

                return 0;

            }

        }

    }



    if(get_bits_count(gb) >= ctx->data_size){

        *last = 1;

        return 0;

    }



    if(ctx->zero){

        t = 0;

        ctx->zero = 0;

    }else{

        t = get_unary_0_33(gb);

        if(get_bits_count(gb) >= ctx->data_size){

            *last = 1;

            return 0;

        }

        if(t == 16) {

            t2 = get_unary_0_33(gb);

            if(t2 < 2) t += t2;

            else t += get_bits(gb, t2 - 1) | (1 << (t2 - 1));

        }



        if(ctx->one){

            ctx->one = t&1;

            t = (t>>1) + 1;

        }else{

            ctx->one = t&1;

            t >>= 1;

        }

        ctx->zero = !ctx->one;

    }



    if(ctx->hybrid && !channel)

        update_error_limit(ctx);



    if(!t){

        base = 0;

        add = GET_MED(0) - 1;

        DEC_MED(0);

    }else if(t == 1){

        base = GET_MED(0);

        add = GET_MED(1) - 1;

        INC_MED(0);

        DEC_MED(1);

    }else if(t == 2){

        base = GET_MED(0) + GET_MED(1);

        add = GET_MED(2) - 1;

        INC_MED(0);

        INC_MED(1);

        DEC_MED(2);

    }else{

        base = GET_MED(0) + GET_MED(1) + GET_MED(2) * (t - 2);

        add = GET_MED(2) - 1;

        INC_MED(0);

        INC_MED(1);

        INC_MED(2);

    }

    if(!c->error_limit){

        ret = base + get_tail(gb, add);

    }else{

        int mid = (base*2 + add + 1) >> 1;

        while(add > c->error_limit){

            if(get_bits1(gb)){

                add -= (mid - base);

                base = mid;

            }else

                add = mid - base - 1;

            mid = (base*2 + add + 1) >> 1;

        }

        ret = mid;

    }

    sign = get_bits1(gb);

    if(ctx->hybrid_bitrate)

        c->slow_level += wp_log2(ret) - LEVEL_DECAY(c->slow_level);

    return sign ? ~ret : ret;

}

            if(t >= 2) t = get_bits(gb, t - 1) | (1 << (t-1));     if(get_bits_count(gb) >= ctx->data_size){         *last = 1;         return 0;         if(get_bits_count(gb) >= ctx->data_size){             *last = 1;             return 0;             if(t2 < 2) t += t2;             else t += get_bits(gb, t2 - 1) | (1 << (t2 - 1));
static int FUNC_0(WavpackFrameContext *VAR_0, GetBitContext *VAR_1, int VAR_2, int *VAR_3)

{

    int VAR_4, VAR_5;

    int VAR_6, VAR_7, VAR_8, VAR_9;

    WvChannel *c = &VAR_0->ch[VAR_2];



    *VAR_3 = 0;



    if((VAR_0->ch[0].median[0] < 2U) && (VAR_0->ch[1].median[0] < 2U) && !VAR_0->zero && !VAR_0->one){

        if(VAR_0->zeroes){

            VAR_0->zeroes--;

            if(VAR_0->zeroes){

                c->slow_level -= LEVEL_DECAY(c->slow_level);

                return 0;

            }

        }else{

            VAR_4 = get_unary_0_33(VAR_1);

            if(VAR_4 >= 2) VAR_4 = get_bits(VAR_1, VAR_4 - 1) | (1 << (VAR_4-1));

            VAR_0->zeroes = VAR_4;

            if(VAR_0->zeroes){

                memset(VAR_0->ch[0].median, 0, sizeof(VAR_0->ch[0].median));

                memset(VAR_0->ch[1].median, 0, sizeof(VAR_0->ch[1].median));

                c->slow_level -= LEVEL_DECAY(c->slow_level);

                return 0;

            }

        }

    }



    if(get_bits_count(VAR_1) >= VAR_0->data_size){

        *VAR_3 = 1;

        return 0;

    }



    if(VAR_0->zero){

        VAR_4 = 0;

        VAR_0->zero = 0;

    }else{

        VAR_4 = get_unary_0_33(VAR_1);

        if(get_bits_count(VAR_1) >= VAR_0->data_size){

            *VAR_3 = 1;

            return 0;

        }

        if(VAR_4 == 16) {

            VAR_5 = get_unary_0_33(VAR_1);

            if(VAR_5 < 2) VAR_4 += VAR_5;

            else VAR_4 += get_bits(VAR_1, VAR_5 - 1) | (1 << (VAR_5 - 1));

        }



        if(VAR_0->one){

            VAR_0->one = VAR_4&1;

            VAR_4 = (VAR_4>>1) + 1;

        }else{

            VAR_0->one = VAR_4&1;

            VAR_4 >>= 1;

        }

        VAR_0->zero = !VAR_0->one;

    }



    if(VAR_0->hybrid && !VAR_2)

        update_error_limit(VAR_0);



    if(!VAR_4){

        VAR_7 = 0;

        VAR_8 = GET_MED(0) - 1;

        DEC_MED(0);

    }else if(VAR_4 == 1){

        VAR_7 = GET_MED(0);

        VAR_8 = GET_MED(1) - 1;

        INC_MED(0);

        DEC_MED(1);

    }else if(VAR_4 == 2){

        VAR_7 = GET_MED(0) + GET_MED(1);

        VAR_8 = GET_MED(2) - 1;

        INC_MED(0);

        INC_MED(1);

        DEC_MED(2);

    }else{

        VAR_7 = GET_MED(0) + GET_MED(1) + GET_MED(2) * (VAR_4 - 2);

        VAR_8 = GET_MED(2) - 1;

        INC_MED(0);

        INC_MED(1);

        INC_MED(2);

    }

    if(!c->error_limit){

        VAR_9 = VAR_7 + get_tail(VAR_1, VAR_8);

    }else{

        int VAR_10 = (VAR_7*2 + VAR_8 + 1) >> 1;

        while(VAR_8 > c->error_limit){

            if(get_bits1(VAR_1)){

                VAR_8 -= (VAR_10 - VAR_7);

                VAR_7 = VAR_10;

            }else

                VAR_8 = VAR_10 - VAR_7 - 1;

            VAR_10 = (VAR_7*2 + VAR_8 + 1) >> 1;

        }

        VAR_9 = VAR_10;

    }

    VAR_6 = get_bits1(VAR_1);

    if(VAR_0->hybrid_bitrate)

        c->slow_level += wp_log2(VAR_9) - LEVEL_DECAY(c->slow_level);

    return VAR_6 ? ~VAR_9 : VAR_9;

}

static int FUNC_0(WavpackFrameContext *VAR_0, GetBitContext *VAR_1, int VAR_2, int *VAR_3)
{ int VAR_4, VAR_5; int VAR_6, VAR_7, VAR_8, VAR_9; WvChannel *c = &VAR_0->ch[VAR_2]; *VAR_3 = 0; if((VAR_0->ch[0].median[0] < 2U) && (VAR_0->ch[1].median[0] < 2U) && !VAR_0->zero && !VAR_0->one){ if(VAR_0->zeroes){ VAR_0->zeroes--; if(VAR_0->zeroes){ c->slow_level -= LEVEL_DECAY(c->slow_level); return 0; } }else{ VAR_4 = get_unary_0_33(VAR_1); if(VAR_4 >= 2) VAR_4 = get_bits(VAR_1, VAR_4 - 1) | (1 << (VAR_4-1)); VAR_0->zeroes = VAR_4; if(VAR_0->zeroes){ memset(VAR_0->ch[0].median, 0, sizeof(VAR_0->ch[0].median)); memset(VAR_0->ch[1].median, 0, sizeof(VAR_0->ch[1].median)); c->slow_level -= LEVEL_DECAY(c->slow_level); return 0; } } } if(get_bits_count(VAR_1) >= VAR_0->data_size){ *VAR_3 = 1; return 0; } if(VAR_0->zero){ VAR_4 = 0; VAR_0->zero = 0; }else{ VAR_4 = get_unary_0_33(VAR_1); if(get_bits_count(VAR_1) >= VAR_0->data_size){ *VAR_3 = 1; return 0; } if(VAR_4 == 16) { VAR_5 = get_unary_0_33(VAR_1); if(VAR_5 < 2) VAR_4 += VAR_5; else VAR_4 += get_bits(VAR_1, VAR_5 - 1) | (1 << (VAR_5 - 1)); } if(VAR_0->one){ VAR_0->one = VAR_4&1; VAR_4 = (VAR_4>>1) + 1; }else{ VAR_0->one = VAR_4&1; VAR_4 >>= 1; } VAR_0->zero = !VAR_0->one; } if(VAR_0->hybrid && !VAR_2)
update_error_limit(VAR_0); if(!VAR_4){ VAR_7 = 0; VAR_8 = GET_MED(0) - 1; DEC_MED(0); }else if(VAR_4 == 1){ VAR_7 = GET_MED(0); VAR_8 = GET_MED(1) - 1; INC_MED(0); DEC_MED(1); }else if(VAR_4 == 2){ VAR_7 = GET_MED(0) + GET_MED(1); VAR_8 = GET_MED(2) - 1; INC_MED(0); INC_MED(1); DEC_MED(2); }else{ VAR_7 = GET_MED(0) + GET_MED(1) + GET_MED(2) * (VAR_4 - 2); VAR_8 = GET_MED(2) - 1; INC_MED(0); INC_MED(1); INC_MED(2); } if(!c->error_limit){ VAR_9 = VAR_7 + get_tail(VAR_1, VAR_8); }else{ int VAR_10 = (VAR_7*2 + VAR_8 + 1) >> 1; while(VAR_8 > c->error_limit){ if(get_bits1(VAR_1)){ VAR_8 -= (VAR_10 - VAR_7); VAR_7 = VAR_10; }else VAR_8 = VAR_10 - VAR_7 - 1; VAR_10 = (VAR_7*2 + VAR_8 + 1) >> 1; } VAR_9 = VAR_10; } VAR_6 = get_bits1(VAR_1); if(VAR_0->hybrid_bitrate)
c->slow_level += wp_log2(VAR_9) - LEVEL_DECAY(c->slow_level); return VAR_6 ? ~VAR_9 : VAR_9; }