static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax,

                                 int32_t *data, int n, int pred_order)

{

    int i;

    uint64_t bits[MAX_PARTITION_ORDER+1];

    int opt_porder;

    RiceContext tmp_rc;

    uint32_t *udata;

    uint64_t sums[MAX_PARTITION_ORDER + 1][MAX_PARTITIONS] = { { 0 } };



    assert(pmin >= 0 && pmin <= MAX_PARTITION_ORDER);

    assert(pmax >= 0 && pmax <= MAX_PARTITION_ORDER);

    assert(pmin <= pmax);



    tmp_rc.coding_mode = rc->coding_mode;



    udata = av_malloc(n * sizeof(uint32_t));

    for (i = 0; i < n; i++)

        udata[i] = (2*data[i]) ^ (data[i]>>31);



    calc_sums(pmin, pmax, udata, n, pred_order, sums);



    opt_porder = pmin;

    bits[pmin] = UINT32_MAX;

    for (i = pmin; i <= pmax; i++) {

        bits[i] = calc_optimal_rice_params(&tmp_rc, i, sums[i], n, pred_order);

        if (bits[i] <= bits[opt_porder]) {

            opt_porder = i;

            *rc = tmp_rc;

        }

    }



    av_freep(&udata);

    return bits[opt_porder];

}

static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax,

                                 int32_t *data, int n, int pred_order)

{

    int i;

    uint64_t bits[MAX_PARTITION_ORDER+1];

    int opt_porder;

    RiceContext tmp_rc;

    uint32_t *udata;

    uint64_t sums[MAX_PARTITION_ORDER + 1][MAX_PARTITIONS] = { { 0 } };



    assert(pmin >= 0 && pmin <= MAX_PARTITION_ORDER);

    assert(pmax >= 0 && pmax <= MAX_PARTITION_ORDER);

    assert(pmin <= pmax);



    tmp_rc.coding_mode = rc->coding_mode;



    udata = av_malloc(n * sizeof(uint32_t));

    for (i = 0; i < n; i++)

        udata[i] = (2*data[i]) ^ (data[i]>>31);



    calc_sums(pmin, pmax, udata, n, pred_order, sums);



    opt_porder = pmin;

    bits[pmin] = UINT32_MAX;

    for (i = pmin; i <= pmax; i++) {

        bits[i] = calc_optimal_rice_params(&tmp_rc, i, sums[i], n, pred_order);

        if (bits[i] <= bits[opt_porder]) {

            opt_porder = i;

            *rc = tmp_rc;

        }

    }



    av_freep(&udata);

    return bits[opt_porder];

}

static uint64_t FUNC_0(RiceContext *rc, int pmin, int pmax,

                                 int32_t *data, int n, int pred_order)

{

    int VAR_0;

    uint64_t bits[MAX_PARTITION_ORDER+1];

    int VAR_1;

    RiceContext tmp_rc;

    uint32_t *udata;

    uint64_t sums[MAX_PARTITION_ORDER + 1][MAX_PARTITIONS] = { { 0 } };



    assert(pmin >= 0 && pmin <= MAX_PARTITION_ORDER);

    assert(pmax >= 0 && pmax <= MAX_PARTITION_ORDER);

    assert(pmin <= pmax);



    tmp_rc.coding_mode = rc->coding_mode;



    udata = av_malloc(n * sizeof(uint32_t));

    for (VAR_0 = 0; VAR_0 < n; VAR_0++)

        udata[VAR_0] = (2*data[VAR_0]) ^ (data[VAR_0]>>31);



    calc_sums(pmin, pmax, udata, n, pred_order, sums);



    VAR_1 = pmin;

    bits[pmin] = UINT32_MAX;

    for (VAR_0 = pmin; VAR_0 <= pmax; VAR_0++) {

        bits[VAR_0] = calc_optimal_rice_params(&tmp_rc, VAR_0, sums[VAR_0], n, pred_order);

        if (bits[VAR_0] <= bits[VAR_1]) {

            VAR_1 = VAR_0;

            *rc = tmp_rc;

        }

    }



    av_freep(&udata);

    return bits[VAR_1];

}

static uint64_t FUNC_0(RiceContext *rc, int pmin, int pmax,
int32_t *data, int n, int pred_order)
{ int VAR_0; uint64_t bits[MAX_PARTITION_ORDER+1]; int VAR_1; RiceContext tmp_rc; uint32_t *udata; uint64_t sums[MAX_PARTITION_ORDER + 1][MAX_PARTITIONS] = { { 0 } }; assert(pmin >= 0 && pmin <= MAX_PARTITION_ORDER); assert(pmax >= 0 && pmax <= MAX_PARTITION_ORDER); assert(pmin <= pmax); tmp_rc.coding_mode = rc->coding_mode; udata = av_malloc(n * sizeof(uint32_t)); for (VAR_0 = 0; VAR_0 < n; VAR_0++) udata[VAR_0] = (2*data[VAR_0]) ^ (data[VAR_0]>>31); calc_sums(pmin, pmax, udata, n, pred_order, sums); VAR_1 = pmin; bits[pmin] = UINT32_MAX; for (VAR_0 = pmin; VAR_0 <= pmax; VAR_0++) { bits[VAR_0] = calc_optimal_rice_params(&tmp_rc, VAR_0, sums[VAR_0], n, pred_order); if (bits[VAR_0] <= bits[VAR_1]) { VAR_1 = VAR_0; *rc = tmp_rc; } } av_freep(&udata); return bits[VAR_1]; }