void ff_init_elbg(int *points, int dim, int numpoints, int *codebook,

                  int numCB, int max_steps, int *closest_cb,

                  AVLFG *rand_state)

{

    int i, k;



    if (numpoints > 24*numCB) {

        /* ELBG is very costly for a big number of points. So if we have a lot

           of them, get a good initial codebook to save on iterations       */

        int *temp_points = av_malloc(dim*(numpoints/8)*sizeof(int));

        for (i=0; i<numpoints/8; i++) {

            k = (i*BIG_PRIME) % numpoints;

            memcpy(temp_points + i*dim, points + k*dim, dim*sizeof(int));

        }



        ff_init_elbg(temp_points, dim, numpoints/8, codebook, numCB, 2*max_steps, closest_cb, rand_state);

        ff_do_elbg(temp_points, dim, numpoints/8, codebook, numCB, 2*max_steps, closest_cb, rand_state);



        av_free(temp_points);



    } else  // If not, initialize the codebook with random positions

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

            memcpy(codebook + i*dim, points + ((i*BIG_PRIME)%numpoints)*dim,

                   dim*sizeof(int));



}

void ff_init_elbg(int *points, int dim, int numpoints, int *codebook,

                  int numCB, int max_steps, int *closest_cb,

                  AVLFG *rand_state)

{

    int i, k;



    if (numpoints > 24*numCB) {

        



        int *temp_points = av_malloc(dim*(numpoints/8)*sizeof(int));

        for (i=0; i<numpoints/8; i++) {

            k = (i*BIG_PRIME) % numpoints;

            memcpy(temp_points + i*dim, points + k*dim, dim*sizeof(int));

        }



        ff_init_elbg(temp_points, dim, numpoints/8, codebook, numCB, 2*max_steps, closest_cb, rand_state);

        ff_do_elbg(temp_points, dim, numpoints/8, codebook, numCB, 2*max_steps, closest_cb, rand_state);



        av_free(temp_points);



    } else  

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

            memcpy(codebook + i*dim, points + ((i*BIG_PRIME)%numpoints)*dim,

                   dim*sizeof(int));



}

void FUNC_0(int *VAR_0, int VAR_1, int VAR_2, int *VAR_3,

                  int VAR_4, int VAR_5, int *VAR_6,

                  AVLFG *VAR_7)

{

    int VAR_8, VAR_9;



    if (VAR_2 > 24*VAR_4) {

        



        int *VAR_10 = av_malloc(VAR_1*(VAR_2/8)*sizeof(int));

        for (VAR_8=0; VAR_8<VAR_2/8; VAR_8++) {

            VAR_9 = (VAR_8*BIG_PRIME) % VAR_2;

            memcpy(VAR_10 + VAR_8*VAR_1, VAR_0 + VAR_9*VAR_1, VAR_1*sizeof(int));

        }



        FUNC_0(VAR_10, VAR_1, VAR_2/8, VAR_3, VAR_4, 2*VAR_5, VAR_6, VAR_7);

        ff_do_elbg(VAR_10, VAR_1, VAR_2/8, VAR_3, VAR_4, 2*VAR_5, VAR_6, VAR_7);



        av_free(VAR_10);



    } else  

        for (VAR_8=0; VAR_8 < VAR_4; VAR_8++)

            memcpy(VAR_3 + VAR_8*VAR_1, VAR_0 + ((VAR_8*BIG_PRIME)%VAR_2)*VAR_1,

                   VAR_1*sizeof(int));



}

void FUNC_0(int *VAR_0, int VAR_1, int VAR_2, int *VAR_3,
int VAR_4, int VAR_5, int *VAR_6,
AVLFG *VAR_7)
{ int VAR_8, VAR_9; if (VAR_2 > 24*VAR_4) { int *VAR_10 = av_malloc(VAR_1*(VAR_2/8)*sizeof(int)); for (VAR_8=0; VAR_8<VAR_2/8; VAR_8++) { VAR_9 = (VAR_8*BIG_PRIME) % VAR_2; memcpy(VAR_10 + VAR_8*VAR_1, VAR_0 + VAR_9*VAR_1, VAR_1*sizeof(int)); } FUNC_0(VAR_10, VAR_1, VAR_2/8, VAR_3, VAR_4, 2*VAR_5, VAR_6, VAR_7); ff_do_elbg(VAR_10, VAR_1, VAR_2/8, VAR_3, VAR_4, 2*VAR_5, VAR_6, VAR_7); av_free(VAR_10); } else for (VAR_8=0; VAR_8 < VAR_4; VAR_8++) memcpy(VAR_3 + VAR_8*VAR_1, VAR_0 + ((VAR_8*BIG_PRIME)%VAR_2)*VAR_1,
VAR_1*sizeof(int)); }