void qdist_bin__internal(struct qdist *to, const struct qdist *from, size_t n)

{

    double xmin, xmax;

    double step;

    size_t i, j;



    qdist_init(to);



    if (from->n == 0) {

        return;

    }

    if (n == 0 || from->n == 1) {

        n = from->n;

    }



    /* set equally-sized bins between @from's left and right */

    xmin = qdist_xmin(from);

    xmax = qdist_xmax(from);

    step = (xmax - xmin) / n;



    if (n == from->n) {

        /* if @from's entries are equally spaced, no need to re-bin */

        for (i = 0; i < from->n; i++) {

            if (from->entries[i].x != xmin + i * step) {

                goto rebin;

            }

        }

        /* they're equally spaced, so copy the dist and bail out */

        to->entries = g_new(struct qdist_entry, from->n);

        to->n = from->n;

        memcpy(to->entries, from->entries, sizeof(*to->entries) * to->n);

        return;

    }



 rebin:

    j = 0;

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

        double x;

        double left, right;



        left = xmin + i * step;

        right = xmin + (i + 1) * step;



        /* Add x, even if it might not get any counts later */

        x = left;

        qdist_add(to, x, 0);



        /*

         * To avoid double-counting we capture [left, right) ranges, except for

         * the righmost bin, which captures a [left, right] range.

         */

        while (j < from->n && (from->entries[j].x < right || i == n - 1)) {

            struct qdist_entry *o = &from->entries[j];



            qdist_add(to, x, o->count);

            j++;

        }

    }

}

void qdist_bin__internal(struct qdist *to, const struct qdist *from, size_t n)

{

    double xmin, xmax;

    double step;

    size_t i, j;



    qdist_init(to);



    if (from->n == 0) {

        return;

    }

    if (n == 0 || from->n == 1) {

        n = from->n;

    }



    

    xmin = qdist_xmin(from);

    xmax = qdist_xmax(from);

    step = (xmax - xmin) / n;



    if (n == from->n) {

        

        for (i = 0; i < from->n; i++) {

            if (from->entries[i].x != xmin + i * step) {

                goto rebin;

            }

        }

        

        to->entries = g_new(struct qdist_entry, from->n);

        to->n = from->n;

        memcpy(to->entries, from->entries, sizeof(*to->entries) * to->n);

        return;

    }



 rebin:

    j = 0;

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

        double x;

        double left, right;



        left = xmin + i * step;

        right = xmin + (i + 1) * step;



        

        x = left;

        qdist_add(to, x, 0);



        







        while (j < from->n && (from->entries[j].x < right || i == n - 1)) {

            struct qdist_entry *o = &from->entries[j];



            qdist_add(to, x, o->count);

            j++;

        }

    }

}

        to->entries = g_new(struct qdist_entry, from->n);
void FUNC_0(struct qdist *VAR_0, const struct qdist *VAR_1, size_t VAR_2)

{

    double VAR_3, VAR_4;

    double VAR_5;

    size_t i, j;



    qdist_init(VAR_0);



    if (VAR_1->VAR_2 == 0) {

        return;

    }

    if (VAR_2 == 0 || VAR_1->VAR_2 == 1) {

        VAR_2 = VAR_1->VAR_2;

    }



    

    VAR_3 = qdist_xmin(VAR_1);

    VAR_4 = qdist_xmax(VAR_1);

    VAR_5 = (VAR_4 - VAR_3) / VAR_2;



    if (VAR_2 == VAR_1->VAR_2) {

        

        for (i = 0; i < VAR_1->VAR_2; i++) {

            if (VAR_1->entries[i].x != VAR_3 + i * VAR_5) {

                goto rebin;

            }

        }

        

        VAR_0->entries = g_new(struct qdist_entry, VAR_1->VAR_2);

        VAR_0->VAR_2 = VAR_1->VAR_2;

        memcpy(VAR_0->entries, VAR_1->entries, sizeof(*VAR_0->entries) * VAR_0->VAR_2);

        return;

    }



 rebin:

    j = 0;

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

        double x;

        double left, right;



        left = VAR_3 + i * VAR_5;

        right = VAR_3 + (i + 1) * VAR_5;



        

        x = left;

        qdist_add(VAR_0, x, 0);



        







        while (j < VAR_1->VAR_2 && (VAR_1->entries[j].x < right || i == VAR_2 - 1)) {

            struct qdist_entry *o = &VAR_1->entries[j];



            qdist_add(VAR_0, x, o->count);

            j++;

        }

    }

}

void FUNC_0(struct qdist *VAR_0, const struct qdist *VAR_1, size_t VAR_2)
{ double VAR_3, VAR_4; double VAR_5; size_t i, j; qdist_init(VAR_0); if (VAR_1->VAR_2 == 0) { return; } if (VAR_2 == 0 || VAR_1->VAR_2 == 1) { VAR_2 = VAR_1->VAR_2; } VAR_3 = qdist_xmin(VAR_1); VAR_4 = qdist_xmax(VAR_1); VAR_5 = (VAR_4 - VAR_3) / VAR_2; if (VAR_2 == VAR_1->VAR_2) { for (i = 0; i < VAR_1->VAR_2; i++) { if (VAR_1->entries[i].x != VAR_3 + i * VAR_5) { goto rebin; } } VAR_0->entries = g_new(struct qdist_entry, VAR_1->VAR_2); VAR_0->VAR_2 = VAR_1->VAR_2; memcpy(VAR_0->entries, VAR_1->entries, sizeof(*VAR_0->entries) * VAR_0->VAR_2); return; } rebin:
j = 0; for (i = 0; i < VAR_2; i++) { double x; double left, right; left = VAR_3 + i * VAR_5; right = VAR_3 + (i + 1) * VAR_5; x = left; qdist_add(VAR_0, x, 0); while (j < VAR_1->VAR_2 && (VAR_1->entries[j].x < right || i == VAR_2 - 1)) { struct qdist_entry *o = &VAR_1->entries[j]; qdist_add(VAR_0, x, o->count); j++; } } }