static int decode_cabac_mb_ref( H264Context *h, int list, int n ) {

    int refa = h->ref_cache[list][scan8[n] - 1];

    int refb = h->ref_cache[list][scan8[n] - 8];

    int ref  = 0;

    int ctx  = 0;



    if( h->slice_type_nos == FF_B_TYPE) {

        if( refa > 0 && !h->direct_cache[scan8[n] - 1] )

            ctx++;

        if( refb > 0 && !h->direct_cache[scan8[n] - 8] )

            ctx += 2;

    } else {

        if( refa > 0 )

            ctx++;

        if( refb > 0 )

            ctx += 2;

    }



    while( get_cabac( &h->cabac, &h->cabac_state[54+ctx] ) ) {

        ref++;

        if( ctx < 4 )

            ctx = 4;

        else

            ctx = 5;

        if(ref >= 32 /*h->ref_list[list]*/){

            av_log(h->s.avctx, AV_LOG_ERROR, "overflow in decode_cabac_mb_ref\n");

            return 0; //FIXME we should return -1 and check the return everywhere

        }

    }

    return ref;

}

static int decode_cabac_mb_ref( H264Context *h, int list, int n ) {

    int refa = h->ref_cache[list][scan8[n] - 1];

    int refb = h->ref_cache[list][scan8[n] - 8];

    int ref  = 0;

    int ctx  = 0;



    if( h->slice_type_nos == FF_B_TYPE) {

        if( refa > 0 && !h->direct_cache[scan8[n] - 1] )

            ctx++;

        if( refb > 0 && !h->direct_cache[scan8[n] - 8] )

            ctx += 2;

    } else {

        if( refa > 0 )

            ctx++;

        if( refb > 0 )

            ctx += 2;

    }



    while( get_cabac( &h->cabac, &h->cabac_state[54+ctx] ) ) {

        ref++;

        if( ctx < 4 )

            ctx = 4;

        else

            ctx = 5;

        if(ref >= 32 ){

            av_log(h->s.avctx, AV_LOG_ERROR, "overflow in decode_cabac_mb_ref\n");

            return 0; 

        }

    }

    return ref;

}

static int FUNC_0( H264Context *VAR_0, int VAR_1, int VAR_2 ) {

    int VAR_3 = VAR_0->ref_cache[VAR_1][scan8[VAR_2] - 1];

    int VAR_4 = VAR_0->ref_cache[VAR_1][scan8[VAR_2] - 8];

    int VAR_5  = 0;

    int VAR_6  = 0;



    if( VAR_0->slice_type_nos == FF_B_TYPE) {

        if( VAR_3 > 0 && !VAR_0->direct_cache[scan8[VAR_2] - 1] )

            VAR_6++;

        if( VAR_4 > 0 && !VAR_0->direct_cache[scan8[VAR_2] - 8] )

            VAR_6 += 2;

    } else {

        if( VAR_3 > 0 )

            VAR_6++;

        if( VAR_4 > 0 )

            VAR_6 += 2;

    }



    while( get_cabac( &VAR_0->cabac, &VAR_0->cabac_state[54+VAR_6] ) ) {

        VAR_5++;

        if( VAR_6 < 4 )

            VAR_6 = 4;

        else

            VAR_6 = 5;

        if(VAR_5 >= 32 ){

            av_log(VAR_0->s.avctx, AV_LOG_ERROR, "overflow in FUNC_0\VAR_2");

            return 0; 

        }

    }

    return VAR_5;

}

static int FUNC_0( H264Context *VAR_0, int VAR_1, int VAR_2 ) { int VAR_3 = VAR_0->ref_cache[VAR_1][scan8[VAR_2] - 1]; int VAR_4 = VAR_0->ref_cache[VAR_1][scan8[VAR_2] - 8]; int VAR_5  = 0; int VAR_6  = 0; if( VAR_0->slice_type_nos == FF_B_TYPE) { if( VAR_3 > 0 && !VAR_0->direct_cache[scan8[VAR_2] - 1] )
VAR_6++; if( VAR_4 > 0 && !VAR_0->direct_cache[scan8[VAR_2] - 8] )
VAR_6 += 2; } else { if( VAR_3 > 0 )
VAR_6++; if( VAR_4 > 0 )
VAR_6 += 2; } while( get_cabac( &VAR_0->cabac, &VAR_0->cabac_state[54+VAR_6] ) ) { VAR_5++; if( VAR_6 < 4 )
VAR_6 = 4; else
VAR_6 = 5; if(VAR_5 >= 32 ){ av_log(VAR_0->s.avctx, AV_LOG_ERROR, "overflow in FUNC_0\VAR_2"); return 0; } } return VAR_5; }