decompiled_code:
__int64 __fastcall transfer_estimated(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx

if ( *(int *)(a1 + 32) > 0 )
{
v4 = 0LL;
do
{
gsl_vector_get(a2, v4);
gsl_vector_set(*(_QWORD *)(a1 + 8), *(unsigned int *)(*(_QWORD *)(a1 + 40) + 4 * v4++));
}
while ( *(_DWORD *)(a1 + 32) > (int)v4 );
}
return apply_following_constraints(*(_QWORD *)(a1 + 8), a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx

if ( *(int *)(a1 + 32) > 0 )
{
v4 = 0LL;
do
{
gsl_vector_get(a2, v4);
gsl_vector_set(*(_QWORD *)(a1 + 8), *(unsigned int *)(*(_QWORD *)(a1 + 40) + 4 * v4++));
}
while ( *(_DWORD *)(a1 + 32) > (int)v4 );
}
return apply_following_constraints(*(_QWORD *)(a1 + 8), a1, a3);
}

original_code:
void transfer_estimated(struct s_best *p_best, const gsl_vector *x, struct s_data *p_data)
{
    int k;
    for(k=0; k< p_best->n_to_be_estimated; k++){
        gsl_vector_set(p_best->mean,
                       p_best->to_be_estimated[k],
                       gsl_vector_get(x, k));
    }
    apply_following_constraints(p_best->mean, p_best, p_data);
}

canonical_original_code:
void transfer_estimated(struct s_best *p_best, struct gsl_vector *x, struct s_data *p_data)
{
    int k;
    for(k=0; k< p_best->n_to_be_estimated; k++){
        gsl_vector_set(p_best->mean,
                       p_best->to_be_estimated[k],
                       gsl_vector_get(x, k));
    }
    apply_following_constraints(p_best->mean, p_best, p_data);
}

variable_types:
x
struct gsl_vector *

variable_types: struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 } implementation; enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr } noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind { int n_nonan; unsigned int *ind_nonan; } **data_ind; struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; } **obs2ts; struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; } **routers; struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **drift; struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; } *

user_defined_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; }


repo: QCaudron/iterated-inference-pipeline

original_code:
double nextpow2(double x)
{
    return pow(2, ceil(log(x)/log(2)));
}

variable_types: x double

return_type: double


period

decompiled_code:
double __fastcall period(__int64 a1, int a2, int a3)
{
int v3; // edx
double *v4; // rbp
unsigned __int64 v5; // r13
double v6; // rbx
double v8; // [rsp+8h] [rbp-30h]

v3 = a3 - a2;
if ( v3 <= 0 )
return 0.0;
v4 = (double *)(a1 + 8LL * a2);
v5 = a1 + 8 * (a2 + (unsigned __int64)(unsigned int)(v3 - 1)) + 8;
v8 = 0.0;
do
{
v6 = log(*v4);
v8 = fmax(COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v6 - log(v4[-a2])) & LC2), v8);
++v4;
}
while ( v4 != (double *)v5 );
return v8;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1, int a2, int a3)
{
int v3; // edx
double *v4; // rbp
unsigned __int64 v5; // r13
double v6; // rbx
double v8; // [rsp+8h] [rbp-30h]

v3 = a3 - a2;
if ( v3 <= 0 )
return 0.0;
v4 = (double *)(a1 + 8LL * a2);
v5 = a1 + 8 * (a2 + (unsigned __int64)(unsigned int)(v3 - 1)) + 8;
v8 = 0.0;
do
{
v6 = log(*v4);
v8 = fmax(COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v6 - log(v4[-a2])) & LC2), v8);
++v4;
}
while ( v4 != (double *)v5 );
return v8;
}

original_code:
double period(double *traj_obs_ts, int period, int length_traj_obs_ts)
{
    double err=0.0;
    double err_temp;
    int i;
    for(i=0; i<(length_traj_obs_ts-period); i++) {
 err_temp=fabs(log(traj_obs_ts[i+period])-log(traj_obs_ts[i]));
 if( err_temp > err) {
     err=err_temp;
 }
    }
    return err;
}

canonical_original_code:
double period(double *traj_obs_ts, int period, int length_traj_obs_ts)
{
    double err = 0.0;
    double err_temp;
    int i;
    for(i=0; i<(length_traj_obs_ts-period); i++) {
 err_temp=fabs(log(traj_obs_ts[i+period])-log(traj_obs_ts[i]));
 if( err_temp > err) {
     err=err_temp;
 }
    }
    return err;
}

variable_types: period int

variable_types: err double

variable_types: i int


decompiled_code:
__int64 __fastcall get_c_ac(int a1, int *a2, int *a3)
{
__int64 result; // rax

*a2 = a1 / N_AC;
result = (unsigned int)(a1 / N_AC);
*a3 = a1 % N_AC;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int *a2, int *a3)
{
__int64 result; // rax

*a2 = a1 / N_AC;
result = (unsigned int)(a1 / N_AC);
*a3 = a1 % N_AC;
return result;
}

original_code:
void get_c_ac(int cac, int *c, int *ac)
{
  *c = cac/ N_AC;
  *ac = cac % N_AC;
}

variable_types: cac int

variable_types:
c
int *

variable_types:
ac
int *

return_type: void


decompiled_code:
void __fastcall clean_groups_compo(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = (void **)ptr;
do
{
free(*((void **)*v2 + 1));
*((_QWORD *)*v2 + 1) = 0LL;
free(*v2);
*v2++ = 0LL;
}
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = (void **)ptr;
do
{
free(*((void **)*v2 + 1));
*((_QWORD *)*v2 + 1) = 0LL;
free(*v2);
*v2++ = 0LL;
}
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

original_code:
void clean_groups_compo(struct s_group **compo, int n_gp)
{
  int g;
  for(g=0; g< n_gp; g++)
    {
      do { free( compo[g]->elements ); compo[g]->elements = ((void *)0); }while(0);
      do { free( compo[g] ); compo[g] = ((void *)0); }while(0);
    }
  do { free( compo ); compo = ((void *)0); }while(0);
}

variable_types: struct s_group { int length; unsigned int *elements; } **

variable_types: g int


decompiled_code:
__int64 __fastcall apply_following_constraints(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // r14
int j; // ebx
__int64 i; // [rsp+8h] [rbp-40h]

result = *(_QWORD *)(a3 + 96);
v5 = *(_QWORD *)(result + 16);
for ( i = 0LL; *(_DWORD *)(a2 + 56) > (int)i; result = i )
{
for ( j = 0;
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a3 + 80) + 8LL * *(unsigned int *)(*(_QWORD *)(a2 + 64) + 4 * i)) + 4LL) > j;
++j )
{
gsl_vector_get(a1, (unsigned int)(*(_DWORD *)(v5 + 4LL * *(unsigned int *)(*(_QWORD *)(a2 + 72) + 4 * i)) + j));
gsl_vector_set(a1, (unsigned int)(*(_DWORD *)(v5 + 4LL * *(unsigned int *)(*(_QWORD *)(a2 + 64) + 4 * i)) + j));
}
++i;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // r14
int j; // ebx
__int64 i; // [rsp+8h] [rbp-40h]

result = *(_QWORD *)(a3 + 96);
v5 = *(_QWORD *)(result + 16);
for ( i = 0LL; *(_DWORD *)(a2 + 56) > (int)i; result = i )
{
for ( j = 0;
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a3 + 80) + 8LL * *(unsigned int *)(*(_QWORD *)(a2 + 64) + 4 * i)) + 4LL) > j;
++j )
{
gsl_vector_get(a1, (unsigned int)(*(_DWORD *)(v5 + 4LL * *(unsigned int *)(*(_QWORD *)(a2 + 72) + 4 * i)) + j));
gsl_vector_set(a1, (unsigned int)(*(_DWORD *)(v5 + 4LL * *(unsigned int *)(*(_QWORD *)(a2 + 64) + 4 * i)) + j));
}
++i;
}
return result;
}

original_code:
void apply_following_constraints(theta_t *proposed, struct s_best *p_best, struct s_data *p_data)
{
    int i, k;
    unsigned int *offset = p_data->p_it_all->offset;
    for(i=0; i<p_best->n_follow; i++){
        for(k=0; k<p_data->routers[p_best->follower[i]]->n_gp; k++){
            gsl_vector_set(proposed,
                           offset[p_best->follower[i]] + k,
                           gsl_vector_get(proposed, offset[p_best->follow[i]] + k)
                           );
        }
    }
}

canonical_original_code:
void apply_following_constraints(struct gsl_vector *proposed, struct s_best *p_best, struct s_data *p_data)
{
    int i; int k;
    unsigned int *offset = p_data->p_it_all->offset;
    for(i=0; i<p_best->n_follow; i++){
        for(k=0; k<p_data->routers[p_best->follower[i]]->n_gp; k++){
            gsl_vector_set(proposed,
                           offset[p_best->follower[i]] + k,
                           gsl_vector_get(proposed, offset[p_best->follow[i]] + k)
                           );
        }
    }
}

variable_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: struct s_best { int length; struct gsl_vector *mean; struct gsl_vector *proposed; struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; } *var; int n_to_be_estimated; unsigned int *to_be_estimated; unsigned int *is_estimated; int n_follow; unsigned int *follower; unsigned int *follow; unsigned int *is_follower; double *mean_sampling; struct gsl_matrix *var_sampling; double **par_prior; double (**prior)(double x, double a, double b); } *

variable_types: k int

variable_types:
offset
unsigned int *

user_defined_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; }

user_defined_types: struct s_best { int length; struct gsl_vector *mean; struct gsl_vector *proposed; struct gsl_matrix *var; int n_to_be_estimated; unsigned int *to_be_estimated; unsigned int *is_estimated; int n_follow; unsigned int *follower; unsigned int *follow; unsigned int *is_follower; double *mean_sampling; struct gsl_matrix *var_sampling; double **par_prior; double (**prior)(double x, double a, double b); }

user_defined_types: struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations implementation; enum plom_noises_off noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind **data_ind; struct s_obs2ts **obs2ts; struct s_router **routers; struct s_drift **drift; struct s_iterator *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; }

user_defined_types: enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 }

user_defined_types: enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr }

user_defined_types: struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; }

user_defined_types: struct s_data_ind { int n_nonan; unsigned int *ind_nonan; }

user_defined_types: struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; }

user_defined_types: struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; }

user_defined_types: struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; }


decompiled_code:
__int64 __fastcall ran_proposal(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5)
{
__int64 v7; // rbp
__int64 v8; // rbx
double v9; // xmm0_8
double v10; // xmm0_8
__int64 result; // rax

if ( *(int *)(a2 + 32) > 0 )
{
v7 = 0LL;
do
{
v8 = *(int *)(*(_QWORD *)(a2 + 40) + 4 * v7);
gsl_vector_get(*(_QWORD *)(a2 + 8), v8);
v9 = gsl_matrix_get(a3, v8, v8);
if ( v9 < 0.0 )
v10 = sqrt(v9);
else
v10 = sqrt(v9);
gsl_ran_gaussian(*(_QWORD *)(a4 + 8), v10 * a5);
result = gsl_vector_set(a1, v8);
++v7;
}
while ( *(_DWORD *)(a2 + 32) > (int)v7 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5)
{
__int64 v7; // rbp
__int64 v8; // rbx
double v9; // xmm0_8
double v10; // xmm0_8
__int64 result; // rax

if ( *(int *)(a2 + 32) > 0 )
{
v7 = 0LL;
do
{
v8 = *(int *)(*(_QWORD *)(a2 + 40) + 4 * v7);
gsl_vector_get(*(_QWORD *)(a2 + 8), v8);
v9 = gsl_matrix_get(a3, v8, v8);
if ( v9 < 0.0 )
v10 = sqrt(v9);
else
v10 = sqrt(v9);
gsl_ran_gaussian(*(_QWORD *)(a4 + 8), v10 * a5);
result = gsl_vector_set(a1, v8);
++v7;
}
while ( *(_DWORD *)(a2 + 32) > (int)v7 );
}
return result;
}

original_code:
void ran_proposal(theta_t *proposed, struct s_best *p_best, gsl_matrix *var, double sd_fac, struct s_calc *p_calc)
{
    int i, k;
    for (i=0; i< p_best->n_to_be_estimated ; i++) {
 k = p_best->to_be_estimated[i];
 gsl_vector_set(proposed, k, gsl_vector_get(p_best->mean, k) + gsl_ran_gaussian(p_calc->randgsl, sd_fac*sqrt(gsl_matrix_get(var, k, k))));
    }
}

canonical_original_code:
void ran_proposal(struct gsl_vector *proposed, struct s_best *p_best, struct gsl_matrix *var, double sd_fac, struct s_calc *p_calc)
{
    int i; int k;
    for (i=0; i< p_best->n_to_be_estimated ; i++) {
 k = p_best->to_be_estimated[i];
 gsl_vector_set(proposed, k, gsl_vector_get(p_best->mean, k) + gsl_ran_gaussian(p_calc->randgsl, sd_fac*sqrt(gsl_matrix_get(var, k, k))));
    }
}

variable_types:
var
struct gsl_matrix *

variable_types: struct s_calc { int n_threads; int thread_id; struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *randgsl; double **prob; unsigned int ***inc; struct gsl_odeiv2_step_type { char *name; int can_use_dydt_in; int gives_exact_dydt_out; void *(*alloc)(unsigned long dim); int (*apply)(void *state, unsigned long dim, double t, double h, double y[], double yerr[], double dydt_in[], double dydt_out[], struct gsl_odeiv2_system { int (*function)(double t, double y[], double dydt[], void *params); int (*jacobian)(double t, double y[], double *dfdy, double dfdt[], void *params); unsigned long dimension; void *params; } *dydt); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct { struct gsl_odeiv2_system *sys; struct gsl_odeiv2_step_struct { struct gsl_odeiv2_step_type *type; unsigned long dimension; void *state; } *s; struct gsl_odeiv2_control_struct { struct gsl_odeiv2_control_type { char *name; void *(*alloc)(); int (*init)(void *state, double eps_abs, double eps_rel, double a_y, double a_dydt); int (*hadjust)(void *state, unsigned long dim, unsigned int ord, double y[], double yerr[], double yp[], double *h); int (*errlevel)(void *state, double y, double dydt, double h, unsigned long ind, double *errlev); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct *d); void (*free)(void *state); } *type; void *state; } *c; struct gsl_odeiv2_evolve_struct { unsigned long dimension; double *y0; double *yerr; double *dydt_in; double *dydt_out; double last_step; unsigned long count; unsigned long failed_steps; struct gsl_odeiv2_driver_struct *driver; } *e; double h; double hmin; double hmax; unsigned long n; unsigned long nmax; } *d); int (*reset)(void *state, unsigned long dim); unsigned int (*order)(void *state); void (*free)(void *state); } *T; struct gsl_odeiv2_control_struct *control; struct gsl_odeiv2_step_struct *step; struct gsl_odeiv2_evolve_struct *evolve; struct gsl_odeiv2_system sys; double *yerr; double *y_pred; double *to_be_sorted; unsigned long *index_sorted; struct gsl_interp_accel { unsigned long cache; unsigned long miss_count; unsigned long hit_count; } ***acc; struct gsl_spline { struct gsl_interp { struct gsl_interp_type { char *name; unsigned int min_size; void *(*alloc)(unsigned long size); int (*init)(void *, double xa[], double ya[], unsigned long size); int (*eval)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y); int (*eval_deriv)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_p); int (*eval_deriv2)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_pp); int (*eval_integ)(void *, double xa[], double ya[], unsigned long size, struct gsl_interp_accel *, double a, double b, double *result); void (*free)(void *); } *type; double xmin; double xmax; unsigned long size; void *state; } *interp; double *x; double *y; unsigned long size; } ***spline; unsigned int *n_spline; double *pop_size_t0; struct s_par { int size_natural; double **natural; } *p_par; struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 } implementation; enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr } noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind { int n_nonan; unsigned int *ind_nonan; } **data_ind; struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; } **obs2ts; struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; } **routers; struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **drift; struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; } *p_data; void *method_specific_thread_safe_data; void *method_specific_shared_data; } *

user_defined_types: struct s_calc { int n_threads; int thread_id; struct gsl_rng *randgsl; double **prob; unsigned int ***inc; struct gsl_odeiv2_step_type *T; struct gsl_odeiv2_control_struct *control; struct gsl_odeiv2_step_struct *step; struct gsl_odeiv2_evolve_struct *evolve; struct gsl_odeiv2_system sys; double *yerr; double *y_pred; double *to_be_sorted; unsigned long *index_sorted; struct gsl_interp_accel ***acc; struct gsl_spline ***spline; unsigned int *n_spline; double *pop_size_t0; struct s_par *p_par; struct s_data *p_data; void *method_specific_thread_safe_data; void *method_specific_shared_data; }

user_defined_types: struct gsl_block_struct { unsigned long size; double *data; }

user_defined_types: struct gsl_rng { struct gsl_rng_type *type; void *state; }

user_defined_types: struct gsl_odeiv2_step_type { char *name; int can_use_dydt_in; int gives_exact_dydt_out; void *(*alloc)(unsigned long dim); int (*apply)(void *state, unsigned long dim, double t, double h, double y[], double yerr[], double dydt_in[], double dydt_out[], struct gsl_odeiv2_system *dydt); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct *d); int (*reset)(void *state, unsigned long dim); unsigned int (*order)(void *state); void (*free)(void *state); }

user_defined_types: struct gsl_spline { struct gsl_interp *interp; double *x; double *y; unsigned long size; }

user_defined_types: struct gsl_odeiv2_driver_struct { struct gsl_odeiv2_system *sys; struct gsl_odeiv2_step_struct *s; struct gsl_odeiv2_control_struct *c; struct gsl_odeiv2_evolve_struct *e; double h; double hmin; double hmax; unsigned long n; unsigned long nmax; }

user_defined_types: struct gsl_interp { struct gsl_interp_type *type; double xmin; double xmax; unsigned long size; void *state; }

user_defined_types: struct gsl_odeiv2_control_struct { struct gsl_odeiv2_control_type *type; void *state; }


original_code:
int plom_check_IC_assign_theta_remainder(theta_t *proposed, struct s_data *p_data)
{
    int i, cac;
    int cnt_error = 0;
    struct s_iterator *p_it = p_data->p_it_par_sv;
    int ind_theta_remainder = (p_data->p_it_theta_remainder->length) ? p_data->p_it_theta_remainder->ind[0]: -1;
    for (cac=0; cac < N_CAC; cac++) {
 double prop_cac = 0.0;
 for (i=0; i< p_it->length ; i++) {
     struct s_router *p_r = p_data->routers[p_it->ind[i]];
     if(i != ind_theta_remainder){
  prop_cac += back_transform_x(gsl_vector_get(proposed, p_it->offset[i] + p_r->map[cac]), p_r->map[cac], p_r);
     }
        }
        if(prop_cac > 1.0) {
            cnt_error++;
        } else if(ind_theta_remainder != -1) {
     struct s_router *p_r = p_data->routers[ind_theta_remainder];
     gsl_vector_set(proposed, p_data->p_it_theta_remainder->offset[0] +cac, (*(p_r->f))(1.0-prop_cac, p_r->min[cac], p_r->max[cac] ));
 }
    }
    return cnt_error;
}

canonical_original_code:
int plom_check_IC_assign_theta_remainder(struct gsl_vector *proposed, struct s_data *p_data)
{
    int i; int cac;
    int cnt_error = 0;
    struct s_iterator *p_it = p_data->p_it_par_sv;
    int ind_theta_remainder = (p_data->p_it_theta_remainder->length) ? p_data->p_it_theta_remainder->ind[0]: -1;
    for (cac=0; cac < N_CAC; cac++) {
 double prop_cac = 0.0;
 for (i=0; i< p_it->length ; i++) {
     struct s_router *p_r = p_data->routers[p_it->ind[i]];
     if(i != ind_theta_remainder){
  prop_cac += back_transform_x(gsl_vector_get(proposed, p_it->offset[i] + p_r->map[cac]), p_r->map[cac], p_r);
     }
        }
        if(prop_cac > 1.0) {
            cnt_error++;
        } else if(ind_theta_remainder != -1) {
     struct s_router *p_r = p_data->routers[ind_theta_remainder];
     gsl_vector_set(proposed, p_data->p_it_theta_remainder->offset[0] +cac, (*(p_r->f))(1.0-prop_cac, p_r->min[cac], p_r->max[cac] ));
 }
    }
    return cnt_error;
}

variable_types: struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *

variable_types: struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; } *

return_type: int

user_defined_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; }


decompiled_code:
__int64 __fastcall propose_safe_theta_and_load_X0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, _QWORD *a6, double a7, __int64 a8, void (__fastcall *a9)(__int64, __int64, __int64, __int64, double))
{
do
a9(a1, a2, a3, a8, a7);
while ( (int)plom_check_IC_assign_theta_remainder(a1, a6) > 0 );
apply_following_constraints(a1, a2, (__int64)a6);
back_transform_theta2par(a4, a1, a6[14], a6);
linearize_and_repeat(a5, a4, a6, a6[14]);
prop2Xpop_size(a5, a6, a8);
*(_QWORD *)(a5 + 16) = *(_QWORD *)(a5 + 24);
return theta_driftIC2Xdrift(a5, a1, a6);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, _QWORD *a6, double a7, __int64 a8, void (__fastcall *a9)(__int64, __int64, __int64, __int64, double))
{
do
a9(a1, a2, a3, a8, a7);
while ( (int)func2(a1, a6) > 0 );
func0(a1, a2, (__int64)a6);
back_transform_theta2par(a4, a1, a6[14], a6);
linearize_and_repeat(a5, a4, a6, a6[14]);
prop2Xpop_size(a5, a6, a8);
*(_QWORD *)(a5 + 16) = *(_QWORD *)(a5 + 24);
return theta_driftIC2Xdrift(a5, a1, a6);
}

original_code:
void propose_safe_theta_and_load_X0(theta_t *proposed, struct s_best *p_best, gsl_matrix *var, double sd_fac, struct s_par *p_par, struct s_X *p_X, struct s_data *p_data, struct s_calc *p_calc, void (*ran_proposal) (theta_t *proposed, struct s_best *p_best, gsl_matrix *var, double sd_fac, struct s_calc *p_calc))
{
    do
 {
            (*ran_proposal)(proposed, p_best, var, sd_fac, p_calc);
        }
    while (plom_check_IC_assign_theta_remainder(proposed, p_data) > 0);
    apply_following_constraints(proposed, p_best, p_data);
    back_transform_theta2par(p_par, proposed, p_data->p_it_par_sv, p_data);
    linearize_and_repeat(p_X, p_par, p_data, p_data->p_it_par_sv);
    prop2Xpop_size(p_X, p_data, p_calc);
    p_X->dt = p_X->dt0;
    theta_driftIC2Xdrift(p_X, proposed, p_data);
}

canonical_original_code:
void propose_safe_theta_and_load_X0(struct gsl_vector *proposed, struct s_best *p_best, struct gsl_matrix *var, double sd_fac, struct s_par *p_par, struct s_X *p_X, struct s_data *p_data, struct s_calc *p_calc, void (*ran_proposal)(struct gsl_vector *proposed, struct s_best *p_best, struct gsl_matrix *var, double sd_fac, struct s_calc *p_calc))
{
    do
 {
            (*ran_proposal)(proposed, p_best, var, sd_fac, p_calc);
        }
    while (plom_check_IC_assign_theta_remainder(proposed, p_data) > 0);
    apply_following_constraints(proposed, p_best, p_data);
    back_transform_theta2par(p_par, proposed, p_data->p_it_par_sv, p_data);
    linearize_and_repeat(p_X, p_par, p_data, p_data->p_it_par_sv);
    prop2Xpop_size(p_X, p_data, p_calc);
    p_X->dt = p_X->dt0;
    theta_driftIC2Xdrift(p_X, proposed, p_data);
}

variable_types: struct s_par { int size_natural; double **natural; } *

variable_types: struct s_X { double *proj; double *obs; double dt; double dt0; } *

variable_types: struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 } implementation; enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr } noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind { int n_nonan; unsigned int *ind_nonan; } **data_ind; struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; } **obs2ts; struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; } **routers; struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **drift; struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; } *

variable_types: struct s_calc { int n_threads; int thread_id; struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *randgsl; double **prob; unsigned int ***inc; struct gsl_odeiv2_step_type { char *name; int can_use_dydt_in; int gives_exact_dydt_out; void *(*alloc)(unsigned long dim); int (*apply)(void *state, unsigned long dim, double t, double h, double y[], double yerr[], double dydt_in[], double dydt_out[], struct gsl_odeiv2_system { int (*function)(double t, double y[], double dydt[], void *params); int (*jacobian)(double t, double y[], double *dfdy, double dfdt[], void *params); unsigned long dimension; void *params; } *dydt); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct { struct gsl_odeiv2_system *sys; struct gsl_odeiv2_step_struct { struct gsl_odeiv2_step_type *type; unsigned long dimension; void *state; } *s; struct gsl_odeiv2_control_struct { struct gsl_odeiv2_control_type { char *name; void *(*alloc)(); int (*init)(void *state, double eps_abs, double eps_rel, double a_y, double a_dydt); int (*hadjust)(void *state, unsigned long dim, unsigned int ord, double y[], double yerr[], double yp[], double *h); int (*errlevel)(void *state, double y, double dydt, double h, unsigned long ind, double *errlev); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct *d); void (*free)(void *state); } *type; void *state; } *c; struct gsl_odeiv2_evolve_struct { unsigned long dimension; double *y0; double *yerr; double *dydt_in; double *dydt_out; double last_step; unsigned long count; unsigned long failed_steps; struct gsl_odeiv2_driver_struct *driver; } *e; double h; double hmin; double hmax; unsigned long n; unsigned long nmax; } *d); int (*reset)(void *state, unsigned long dim); unsigned int (*order)(void *state); void (*free)(void *state); } *T; struct gsl_odeiv2_control_struct *control; struct gsl_odeiv2_step_struct *step; struct gsl_odeiv2_evolve_struct *evolve; struct gsl_odeiv2_system sys; double *yerr; double *y_pred; double *to_be_sorted; unsigned long *index_sorted; struct gsl_interp_accel { unsigned long cache; unsigned long miss_count; unsigned long hit_count; } ***acc; struct gsl_spline { struct gsl_interp { struct gsl_interp_type { char *name; unsigned int min_size; void *(*alloc)(unsigned long size); int (*init)(void *, double xa[], double ya[], unsigned long size); int (*eval)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y); int (*eval_deriv)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_p); int (*eval_deriv2)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_pp); int (*eval_integ)(void *, double xa[], double ya[], unsigned long size, struct gsl_interp_accel *, double a, double b, double *result); void (*free)(void *); } *type; double xmin; double xmax; unsigned long size; void *state; } *interp; double *x; double *y; unsigned long size; } ***spline; unsigned int *n_spline; double *pop_size_t0; struct s_par *p_par; struct s_data *p_data; void *method_specific_thread_safe_data; void *method_specific_shared_data; } *

variable_types: void (*)(struct gsl_vector *proposed, struct s_best *p_best, struct gsl_matrix *var, double sd_fac, struct s_calc *p_calc)

user_defined_types: struct s_best { int length; struct gsl_vector *mean; struct gsl_vector *proposed; struct gsl_matrix *var; int n_to_be_estimated; unsigned int *to_be_estimated; unsigned int *is_estimated; int n_follow; unsigned int *follower; unsigned int *follow; unsigned int *is_follower; double *mean_sampling; struct gsl_matrix *var_sampling; double **par_prior; double (**prior)(double x, double a, double b); }

user_defined_types: struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations implementation; enum plom_noises_off noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind **data_ind; struct s_obs2ts **obs2ts; struct s_router **routers; struct s_drift **drift; struct s_iterator *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; }

user_defined_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; }


original_code:
plom_err_code log_prob_proposal(double *log_like, struct s_best *p_best, theta_t *proposed, theta_t *mean, gsl_matrix *var, double sd_fac, struct s_data *p_data, int is_mvn)
{
    int i, k, offset;
    double p_tmp, Lp;
    p_tmp=0.0, Lp=0.0;
    if (is_mvn) {
        p_tmp = plom_dmvnorm(p_best, proposed, mean, var, sd_fac);
    }
    for(i=0; i<p_data->p_it_all->length; i++) {
 struct s_router *p_router = p_data->routers[p_data->p_it_all->ind[i]];
        for(k=0; k<p_router->n_gp; k++) {
     offset = p_data->p_it_all->offset[i]+k;
     if(p_best->is_estimated[offset]) {
                if (!is_mvn) {
                    p_tmp = gsl_ran_gaussian_pdf((gsl_vector_get(proposed, offset)-gsl_vector_get(mean, offset)), sd_fac*sqrt(gsl_matrix_get(var, offset, offset)));
                }
                p_tmp /= (*(p_router->f_inv_derivative))(gsl_vector_get(proposed, offset), p_router->min[k], p_router->max[k]);
                if( (__builtin_isnan (p_tmp)==1) || (__builtin_isinf_sign (p_tmp)==1) || (p_tmp<0.0) ) {
      return PLOM_ERR_LIKE;
                }
  if (!is_mvn) {
      Lp += log(p_tmp);
  }
            }
        }
    }
    if (is_mvn) {
 Lp = log(p_tmp);
    }
    if((__builtin_isinf_sign (Lp)==1) || (__builtin_isnan (Lp)==1)) {
 return PLOM_ERR_LIKE;
    }
    *log_like = Lp;
    return PLOM_SUCCESS;
}

canonical_original_code:
enum plom_err_code log_prob_proposal(double *log_like, struct s_best *p_best, struct gsl_vector *proposed, struct gsl_vector *mean, struct gsl_matrix *var, double sd_fac, struct s_data *p_data, int is_mvn)
{
    int i; int k; int offset;
    double p_tmp; double Lp;
    p_tmp=0.0, Lp=0.0;
    if (is_mvn) {
        p_tmp = plom_dmvnorm(p_best, proposed, mean, var, sd_fac);
    }
    for(i=0; i<p_data->p_it_all->length; i++) {
 struct s_router *p_router = p_data->routers[p_data->p_it_all->ind[i]];
        for(k=0; k<p_router->n_gp; k++) {
     offset = p_data->p_it_all->offset[i]+k;
     if(p_best->is_estimated[offset]) {
                if (!is_mvn) {
                    p_tmp = gsl_ran_gaussian_pdf((gsl_vector_get(proposed, offset)-gsl_vector_get(mean, offset)), sd_fac*sqrt(gsl_matrix_get(var, offset, offset)));
                }
                p_tmp /= (*(p_router->f_inv_derivative))(gsl_vector_get(proposed, offset), p_router->min[k], p_router->max[k]);
                if( (__builtin_isnan (p_tmp)==1) || (__builtin_isinf_sign (p_tmp)==1) || (p_tmp<0.0) ) {
      return PLOM_ERR_LIKE;
                }
  if (!is_mvn) {
      Lp += log(p_tmp);
  }
            }
        }
    }
    if (is_mvn) {
 Lp = log(p_tmp);
    }
    if((__builtin_isinf_sign (Lp)==1) || (__builtin_isnan (Lp)==1)) {
 return PLOM_ERR_LIKE;
    }
    *log_like = Lp;
    return PLOM_SUCCESS;
}

variable_types: struct s_best { int length; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *mean; struct gsl_vector *proposed; struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; } *var; int n_to_be_estimated; unsigned int *to_be_estimated; unsigned int *is_estimated; int n_follow; unsigned int *follower; unsigned int *follow; unsigned int *is_follower; double *mean_sampling; struct gsl_matrix *var_sampling; double **par_prior; double (**prior)(double x, double a, double b); } *

variable_types:
proposed
struct gsl_vector *

variable_types:
mean
struct gsl_vector *

variable_types: i int

variable_types: offset int

variable_types: Lp double

return_type: enum plom_err_code { PLOM_SUCCESS=0, PLOM_ERR_LIKE=-1 }

user_defined_types: enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 }

user_defined_types: enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr }

user_defined_types: struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; }


decompiled_code:
void __fastcall clean2d(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = (void **)ptr;
do
{
free(*v2);
*v2++ = 0LL;
}
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = (void **)ptr;
do
{
free(*v2);
*v2++ = 0LL;
}
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

original_code:
void clean2d(double **tab, int n)
{
    int i;
    for(i=0; i<n; i++)
        do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}

variable_types:
tab
double **

variable_types: n int


original_code:
void clean3d(double ***tab, int n, int p1)
{
    int i, j;
    for(i=0; i<n; i++)
        for(j=0; j<p1; j++)
            do { free( tab[i][j] ); tab[i][j] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
        do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}

canonical_original_code:
void clean3d(double ***tab, int n, int p1)
{
    int i; int j;
    for(i=0; i<n; i++)
        for(j=0; j<p1; j++)
            do { free( tab[i][j] ); tab[i][j] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
        do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}

variable_types:
tab
double ***

variable_types: j int


original_code:
void clean4d(double ****tab, int n, int p1, int p2)
{
    int i, j, k;
    for(i=0; i<n; i++)
        for(j=0; j<p1; j++)
            for(k=0; k<p2; k++)
                do { free( tab[i][j][k] ); tab[i][j][k] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
        for(j=0; j<p1; j++)
            do { free( tab[i][j] ); tab[i][j] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
        do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}

canonical_original_code:
void clean4d(double ****tab, int n, int p1, int p2)
{
    int i; int j; int k;
    for(i=0; i<n; i++)
        for(j=0; j<p1; j++)
            for(k=0; k<p2; k++)
                do { free( tab[i][j][k] ); tab[i][j][k] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
        for(j=0; j<p1; j++)
            do { free( tab[i][j] ); tab[i][j] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
        do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}

variable_types:
tab
double ****

variable_types: k int


original_code:
void clean3d_var(double ***tab, int n, unsigned int *p1)
{
    int i, j;
    for(i=0; i<n; i++)
        for(j=0; j<p1[i]; j++)
            do { free( tab[i][j] ); tab[i][j] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
        do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}

canonical_original_code:
void clean3d_var(double ***tab, int n, unsigned int *p1)
{
    int i; int j;
    for(i=0; i<n; i++)
        for(j=0; j<p1[i]; j++)
            do { free( tab[i][j] ); tab[i][j] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
        do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}


original_code:
void *worker_routine_smc_inproc(void *params)
{
    int j, n, np1, t0, t1;
    int id;
    struct s_thread_smc *p = (struct s_thread_smc *) params;
    struct s_data *p_data = p->p_data;
    struct s_par *p_par = p->p_par;
    struct s_calc *p_calc = p->p_calc;
    struct s_X ***D_J_p_X = p->D_J_p_X;
    struct s_likelihood *p_like = p->p_like;
    plom_f_pred_t f_pred = get_f_pred(p_data->implementation, p_data->noises_off);
    void *controller = zmq_socket (p->context, 2);
    zmq_connect (controller, "inproc://server_controller");
    zmq_setsockopt (controller, 6, "", 0);
    void *receiver = zmq_socket (p->context, 7);
    zmq_connect (receiver, "inproc://server_sender");
    void *sender = zmq_socket (p->context, 8);
    zmq_connect (sender, "inproc://server_receiver");
    zmq_send(sender, &p->thread_id, sizeof (int), 0);
    zmq_pollitem_t items [] = {
        { receiver, 0, 1, 0 },
        { controller, 0, 1, 0 }
    };
    while (1) {
        zmq_poll (items, 2, -1);
        if (items [0].revents & 1) {
     zmq_recv(receiver, &id, sizeof (int), 0);
     zmq_recv(receiver, &n, sizeof (int), 0);
     np1 = n+1;
     t0 = p_data->times[n];
     t1 = p_data->times[np1];
     int J_start = id * p->J_chunk;
     int J_end = (id+1 == p_calc->n_threads) ? p->J : (id+1)*p->J_chunk;
     for(j=J_start; j<J_end; j++ ){
  reset_inc(D_J_p_X[np1][j], p_data);
  (*f_pred)(D_J_p_X[np1][j], t0, t1, p_par, p_data, p_calc);
  proj2obs(D_J_p_X[np1][j], p_data);
  if(p_data->data_ind[n]->n_nonan) {
      p_like->weights[j] = exp(get_log_likelihood(D_J_p_X[np1][j], p_par, p_data, p_calc, n, t1));
  }
     }
     zmq_send(sender, &p->thread_id, sizeof (int), 0);
 }
        if (items [1].revents & 1) {
     char buf [256];
     zmq_recv(controller, buf, 256, 0);
            if(strcmp(buf, "KILL") == 0) {
                break;
            }
        }
    }
    zmq_close (receiver);
    zmq_close (sender);
    zmq_close (controller);
    return ((void *)0);
}

canonical_original_code:
void *worker_routine_smc_inproc(void *params)
{
    int j; int n; int np1; int t0; int t1;
    int id;
    struct s_thread_smc *p = (struct s_thread_smc *) params;
    struct s_data *p_data = p->p_data;
    struct s_par *p_par = p->p_par;
    struct s_calc *p_calc = p->p_calc;
    struct s_X ***D_J_p_X = p->D_J_p_X;
    struct s_likelihood *p_like = p->p_like;
    void (*f_pred)(struct s_X *, double, double, struct s_par *, struct s_data *, struct s_calc *) = get_f_pred(p_data->implementation, p_data->noises_off);
    void *controller = zmq_socket (p->context, 2);
    zmq_connect (controller, "inproc://server_controller");
    zmq_setsockopt (controller, 6, "", 0);
    void *receiver = zmq_socket (p->context, 7);
    zmq_connect (receiver, "inproc://server_sender");
    void *sender = zmq_socket (p->context, 8);
    zmq_connect (sender, "inproc://server_receiver");
    zmq_send(sender, &p->thread_id, sizeof (int), 0);
    struct zmq_pollitem_t items[] = {
        { receiver, 0, 1, 0 },
        { controller, 0, 1, 0 }
    };
    while (1) {
        zmq_poll (items, 2, -1);
        if (items [0].revents & 1) {
     zmq_recv(receiver, &id, sizeof (int), 0);
     zmq_recv(receiver, &n, sizeof (int), 0);
     np1 = n+1;
     t0 = p_data->times[n];
     t1 = p_data->times[np1];
     int J_start = id * p->J_chunk;
     int J_end = (id+1 == p_calc->n_threads) ? p->J : (id+1)*p->J_chunk;
     for(j=J_start; j<J_end; j++ ){
  reset_inc(D_J_p_X[np1][j], p_data);
  (*f_pred)(D_J_p_X[np1][j], t0, t1, p_par, p_data, p_calc);
  proj2obs(D_J_p_X[np1][j], p_data);
  if(p_data->data_ind[n]->n_nonan) {
      p_like->weights[j] = exp(get_log_likelihood(D_J_p_X[np1][j], p_par, p_data, p_calc, n, t1));
  }
     }
     zmq_send(sender, &p->thread_id, sizeof (int), 0);
 }
        if (items [1].revents & 1) {
     char buf[256];
     zmq_recv(controller, buf, 256, 0);
            if(strcmp(buf, "KILL") == 0) {
                break;
            }
        }
    }
    zmq_close (receiver);
    zmq_close (sender);
    zmq_close (controller);
    return ((void *)0);
}

variable_types:
params
void *

variable_types: id int

variable_types: struct s_thread_smc { void *context; int thread_id; int J_chunk; int J; struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 } implementation; enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr } noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind { int n_nonan; unsigned int *ind_nonan; } **data_ind; struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; } **obs2ts; struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; } **routers; struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **drift; struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; } *p_data; struct s_par { int size_natural; double **natural; } *p_par; struct s_X { double *proj; double *obs; double dt; double dt0; } ***D_J_p_X; struct s_calc { int n_threads; int thread_id; struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *randgsl; double **prob; unsigned int ***inc; struct gsl_odeiv2_step_type { char *name; int can_use_dydt_in; int gives_exact_dydt_out; void *(*alloc)(unsigned long dim); int (*apply)(void *state, unsigned long dim, double t, double h, double y[], double yerr[], double dydt_in[], double dydt_out[], struct gsl_odeiv2_system { int (*function)(double t, double y[], double dydt[], void *params); int (*jacobian)(double t, double y[], double *dfdy, double dfdt[], void *params); unsigned long dimension; void *params; } *dydt); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct { struct gsl_odeiv2_system *sys; struct gsl_odeiv2_step_struct { struct gsl_odeiv2_step_type *type; unsigned long dimension; void *state; } *s; struct gsl_odeiv2_control_struct { struct gsl_odeiv2_control_type { char *name; void *(*alloc)(); int (*init)(void *state, double eps_abs, double eps_rel, double a_y, double a_dydt); int (*hadjust)(void *state, unsigned long dim, unsigned int ord, double y[], double yerr[], double yp[], double *h); int (*errlevel)(void *state, double y, double dydt, double h, unsigned long ind, double *errlev); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct *d); void (*free)(void *state); } *type; void *state; } *c; struct gsl_odeiv2_evolve_struct { unsigned long dimension; double *y0; double *yerr; double *dydt_in; double *dydt_out; double last_step; unsigned long count; unsigned long failed_steps; struct gsl_odeiv2_driver_struct *driver; } *e; double h; double hmin; double hmax; unsigned long n; unsigned long nmax; } *d); int (*reset)(void *state, unsigned long dim); unsigned int (*order)(void *state); void (*free)(void *state); } *T; struct gsl_odeiv2_control_struct *control; struct gsl_odeiv2_step_struct *step; struct gsl_odeiv2_evolve_struct *evolve; struct gsl_odeiv2_system sys; double *yerr; double *y_pred; double *to_be_sorted; unsigned long *index_sorted; struct gsl_interp_accel { unsigned long cache; unsigned long miss_count; unsigned long hit_count; } ***acc; struct gsl_spline { struct gsl_interp { struct gsl_interp_type { char *name; unsigned int min_size; void *(*alloc)(unsigned long size); int (*init)(void *, double xa[], double ya[], unsigned long size); int (*eval)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y); int (*eval_deriv)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_p); int (*eval_deriv2)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_pp); int (*eval_integ)(void *, double xa[], double ya[], unsigned long size, struct gsl_interp_accel *, double a, double b, double *result); void (*free)(void *); } *type; double xmin; double xmax; unsigned long size; void *state; } *interp; double *x; double *y; unsigned long size; } ***spline; unsigned int *n_spline; double *pop_size_t0; struct s_par *p_par; struct s_data *p_data; void *method_specific_thread_safe_data; void *method_specific_shared_data; } *p_calc; struct s_likelihood { double ess_n; double Llike_best_n; double Llike_best; double *weights; unsigned int **select; int n_all_fail; double Llike_prev; double Llike_new; } *p_like; } *

variable_types: struct s_calc { int n_threads; int thread_id; struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *randgsl; double **prob; unsigned int ***inc; struct gsl_odeiv2_step_type { char *name; int can_use_dydt_in; int gives_exact_dydt_out; void *(*alloc)(unsigned long dim); int (*apply)(void *state, unsigned long dim, double t, double h, double y[], double yerr[], double dydt_in[], double dydt_out[], struct gsl_odeiv2_system { int (*function)(double t, double y[], double dydt[], void *params); int (*jacobian)(double t, double y[], double *dfdy, double dfdt[], void *params); unsigned long dimension; void *params; } *dydt); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct { struct gsl_odeiv2_system *sys; struct gsl_odeiv2_step_struct { struct gsl_odeiv2_step_type *type; unsigned long dimension; void *state; } *s; struct gsl_odeiv2_control_struct { struct gsl_odeiv2_control_type { char *name; void *(*alloc)(); int (*init)(void *state, double eps_abs, double eps_rel, double a_y, double a_dydt); int (*hadjust)(void *state, unsigned long dim, unsigned int ord, double y[], double yerr[], double yp[], double *h); int (*errlevel)(void *state, double y, double dydt, double h, unsigned long ind, double *errlev); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct *d); void (*free)(void *state); } *type; void *state; } *c; struct gsl_odeiv2_evolve_struct { unsigned long dimension; double *y0; double *yerr; double *dydt_in; double *dydt_out; double last_step; unsigned long count; unsigned long failed_steps; struct gsl_odeiv2_driver_struct *driver; } *e; double h; double hmin; double hmax; unsigned long n; unsigned long nmax; } *d); int (*reset)(void *state, unsigned long dim); unsigned int (*order)(void *state); void (*free)(void *state); } *T; struct gsl_odeiv2_control_struct *control; struct gsl_odeiv2_step_struct *step; struct gsl_odeiv2_evolve_struct *evolve; struct gsl_odeiv2_system sys; double *yerr; double *y_pred; double *to_be_sorted; unsigned long *index_sorted; struct gsl_interp_accel { unsigned long cache; unsigned long miss_count; unsigned long hit_count; } ***acc; struct gsl_spline { struct gsl_interp { struct gsl_interp_type { char *name; unsigned int min_size; void *(*alloc)(unsigned long size); int (*init)(void *, double xa[], double ya[], unsigned long size); int (*eval)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y); int (*eval_deriv)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_p); int (*eval_deriv2)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_pp); int (*eval_integ)(void *, double xa[], double ya[], unsigned long size, struct gsl_interp_accel *, double a, double b, double *result); void (*free)(void *); } *type; double xmin; double xmax; unsigned long size; void *state; } *interp; double *x; double *y; unsigned long size; } ***spline; unsigned int *n_spline; double *pop_size_t0; struct s_par { int size_natural; double **natural; } *p_par; struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 } implementation; enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr } noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind { int n_nonan; unsigned int *ind_nonan; } **data_ind; struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; } **obs2ts; struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; } **routers; struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **drift; struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; } *p_data; void *method_specific_thread_safe_data; void *method_specific_shared_data; } *

variable_types: void (*)(struct s_X { double *proj; double *obs; double dt; double dt0; } *, double, double, struct s_par { int size_natural; double **natural; } *, struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 } implementation; enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr } noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind { int n_nonan; unsigned int *ind_nonan; } **data_ind; struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; } **obs2ts; struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; } **routers; struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **drift; struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; } *, struct s_calc { int n_threads; int thread_id; struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *randgsl; double **prob; unsigned int ***inc; struct gsl_odeiv2_step_type { char *name; int can_use_dydt_in; int gives_exact_dydt_out; void *(*alloc)(unsigned long dim); int (*apply)(void *state, unsigned long dim, double t, double h, double y[], double yerr[], double dydt_in[], double dydt_out[], struct gsl_odeiv2_system { int (*function)(double t, double y[], double dydt[], void *params); int (*jacobian)(double t, double y[], double *dfdy, double dfdt[], void *params); unsigned long dimension; void *params; } *dydt); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct { struct gsl_odeiv2_system *sys; struct gsl_odeiv2_step_struct { struct gsl_odeiv2_step_type *type; unsigned long dimension; void *state; } *s; struct gsl_odeiv2_control_struct { struct gsl_odeiv2_control_type { char *name; void *(*alloc)(); int (*init)(void *state, double eps_abs, double eps_rel, double a_y, double a_dydt); int (*hadjust)(void *state, unsigned long dim, unsigned int ord, double y[], double yerr[], double yp[], double *h); int (*errlevel)(void *state, double y, double dydt, double h, unsigned long ind, double *errlev); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct *d); void (*free)(void *state); } *type; void *state; } *c; struct gsl_odeiv2_evolve_struct { unsigned long dimension; double *y0; double *yerr; double *dydt_in; double *dydt_out; double last_step; unsigned long count; unsigned long failed_steps; struct gsl_odeiv2_driver_struct *driver; } *e; double h; double hmin; double hmax; unsigned long n; unsigned long nmax; } *d); int (*reset)(void *state, unsigned long dim); unsigned int (*order)(void *state); void (*free)(void *state); } *T; struct gsl_odeiv2_control_struct *control; struct gsl_odeiv2_step_struct *step; struct gsl_odeiv2_evolve_struct *evolve; struct gsl_odeiv2_system sys; double *yerr; double *y_pred; double *to_be_sorted; unsigned long *index_sorted; struct gsl_interp_accel { unsigned long cache; unsigned long miss_count; unsigned long hit_count; } ***acc; struct gsl_spline { struct gsl_interp { struct gsl_interp_type { char *name; unsigned int min_size; void *(*alloc)(unsigned long size); int (*init)(void *, double xa[], double ya[], unsigned long size); int (*eval)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y); int (*eval_deriv)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_p); int (*eval_deriv2)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_pp); int (*eval_integ)(void *, double xa[], double ya[], unsigned long size, struct gsl_interp_accel *, double a, double b, double *result); void (*free)(void *); } *type; double xmin; double xmax; unsigned long size; void *state; } *interp; double *x; double *y; unsigned long size; } ***spline; unsigned int *n_spline; double *pop_size_t0; struct s_par *p_par; struct s_data *p_data; void *method_specific_thread_safe_data; void *method_specific_shared_data; } *)

variable_types:
controller
void *

variable_types:
receiver
void *

variable_types:
sender
void *

variable_types: struct zmq_pollitem_t { void *socket; int fd; short events; short revents; } []

variable_types:
buf
char [256]

return_type: void *

user_defined_types: struct s_thread_smc { void *context; int thread_id; int J_chunk; int J; struct s_data *p_data; struct s_par *p_par; struct s_X ***D_J_p_X; struct s_calc *p_calc; struct s_likelihood *p_like; }


original_code:
void *worker_routine_mif_inproc(void *params)
{
    int j, n, np1, t0, t1;
    int id;
    struct s_thread_mif *p = (struct s_thread_mif *) params;
    struct s_data *p_data = p->p_data;
    struct s_par **J_p_par = p->J_p_par;
    struct s_calc *p_calc = p->p_calc;
    struct s_X ***J_p_X = p->J_p_X;
    struct s_likelihood *p_like = p->p_like;
    plom_f_pred_t f_pred = get_f_pred(p_data->implementation, p_data->noises_off);
    void *controller = zmq_socket (p->context, 2);
    zmq_connect (controller, "inproc://server_controller");
    zmq_setsockopt (controller, 6, "", 0);
    void *receiver = zmq_socket (p->context, 7);
    zmq_connect (receiver, "inproc://server_sender");
    void *sender = zmq_socket (p->context, 8);
    zmq_connect (sender, "inproc://server_receiver");
    zmq_send(sender, &p->thread_id, sizeof (int), 0);
    zmq_pollitem_t items [] = {
        { receiver, 0, 1, 0 },
        { controller, 0, 1, 0 }
    };
    while (1) {
        zmq_poll (items, 2, -1);
        if (items [0].revents & 1) {
     zmq_recv(receiver, &id, sizeof (int), 0);
     zmq_recv(receiver, &n, sizeof (int), 0);
     np1 = n+1;
     t0 = p_data->times[n];
     t1 = p_data->times[np1];
     int J_start = id * p->J_chunk;
     int J_end = (id+1 == p_calc->n_threads) ? p->J : (id+1)*p->J_chunk;
     for(j=J_start; j<J_end; j++ ){
  reset_inc((*J_p_X)[j], p_data);
  f_pred((*J_p_X)[j], t0, t1, J_p_par[j], p_data, p_calc);
  if(p_data->data_ind[n]->n_nonan) {
      proj2obs((*J_p_X)[j], p_data);
      p_like->weights[j] = exp(get_log_likelihood((*J_p_X)[j], J_p_par[j], p_data, p_calc, n, t1));
  }
     }
     zmq_send(sender, &p->thread_id, sizeof (int), 0);
 }
        if (items [1].revents & 1) {
     char buf [256];
     zmq_recv(controller, buf, 256, 0);
            if(strcmp(buf, "KILL") == 0) {
                break;
            }
        }
    }
    zmq_close (receiver);
    zmq_close (sender);
    zmq_close (controller);
    return ((void *)0);
}

canonical_original_code:
void *worker_routine_mif_inproc(void *params)
{
    int j; int n; int np1; int t0; int t1;
    int id;
    struct s_thread_mif *p = (struct s_thread_mif *) params;
    struct s_data *p_data = p->p_data;
    struct s_par **J_p_par = p->J_p_par;
    struct s_calc *p_calc = p->p_calc;
    struct s_X ***J_p_X = p->J_p_X;
    struct s_likelihood *p_like = p->p_like;
    void (*f_pred)(struct s_X *, double, double, struct s_par *, struct s_data *, struct s_calc *) = get_f_pred(p_data->implementation, p_data->noises_off);
    void *controller = zmq_socket (p->context, 2);
    zmq_connect (controller, "inproc://server_controller");
    zmq_setsockopt (controller, 6, "", 0);
    void *receiver = zmq_socket (p->context, 7);
    zmq_connect (receiver, "inproc://server_sender");
    void *sender = zmq_socket (p->context, 8);
    zmq_connect (sender, "inproc://server_receiver");
    zmq_send(sender, &p->thread_id, sizeof (int), 0);
    struct zmq_pollitem_t items[] = {
        { receiver, 0, 1, 0 },
        { controller, 0, 1, 0 }
    };
    while (1) {
        zmq_poll (items, 2, -1);
        if (items [0].revents & 1) {
     zmq_recv(receiver, &id, sizeof (int), 0);
     zmq_recv(receiver, &n, sizeof (int), 0);
     np1 = n+1;
     t0 = p_data->times[n];
     t1 = p_data->times[np1];
     int J_start = id * p->J_chunk;
     int J_end = (id+1 == p_calc->n_threads) ? p->J : (id+1)*p->J_chunk;
     for(j=J_start; j<J_end; j++ ){
  reset_inc((*J_p_X)[j], p_data);
  f_pred((*J_p_X)[j], t0, t1, J_p_par[j], p_data, p_calc);
  if(p_data->data_ind[n]->n_nonan) {
      proj2obs((*J_p_X)[j], p_data);
      p_like->weights[j] = exp(get_log_likelihood((*J_p_X)[j], J_p_par[j], p_data, p_calc, n, t1));
  }
     }
     zmq_send(sender, &p->thread_id, sizeof (int), 0);
 }
        if (items [1].revents & 1) {
     char buf[256];
     zmq_recv(controller, buf, 256, 0);
            if(strcmp(buf, "KILL") == 0) {
                break;
            }
        }
    }
    zmq_close (receiver);
    zmq_close (sender);
    zmq_close (controller);
    return ((void *)0);
}

variable_types: struct s_thread_mif { void *context; int thread_id; int J_chunk; int J; struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 } implementation; enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr } noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind { int n_nonan; unsigned int *ind_nonan; } **data_ind; struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; } **obs2ts; struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; } **routers; struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **drift; struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; } *p_data; struct s_par { int size_natural; double **natural; } **J_p_par; struct s_X { double *proj; double *obs; double dt; double dt0; } ***J_p_X; struct s_calc { int n_threads; int thread_id; struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *randgsl; double **prob; unsigned int ***inc; struct gsl_odeiv2_step_type { char *name; int can_use_dydt_in; int gives_exact_dydt_out; void *(*alloc)(unsigned long dim); int (*apply)(void *state, unsigned long dim, double t, double h, double y[], double yerr[], double dydt_in[], double dydt_out[], struct gsl_odeiv2_system { int (*function)(double t, double y[], double dydt[], void *params); int (*jacobian)(double t, double y[], double *dfdy, double dfdt[], void *params); unsigned long dimension; void *params; } *dydt); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct { struct gsl_odeiv2_system *sys; struct gsl_odeiv2_step_struct { struct gsl_odeiv2_step_type *type; unsigned long dimension; void *state; } *s; struct gsl_odeiv2_control_struct { struct gsl_odeiv2_control_type { char *name; void *(*alloc)(); int (*init)(void *state, double eps_abs, double eps_rel, double a_y, double a_dydt); int (*hadjust)(void *state, unsigned long dim, unsigned int ord, double y[], double yerr[], double yp[], double *h); int (*errlevel)(void *state, double y, double dydt, double h, unsigned long ind, double *errlev); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct *d); void (*free)(void *state); } *type; void *state; } *c; struct gsl_odeiv2_evolve_struct { unsigned long dimension; double *y0; double *yerr; double *dydt_in; double *dydt_out; double last_step; unsigned long count; unsigned long failed_steps; struct gsl_odeiv2_driver_struct *driver; } *e; double h; double hmin; double hmax; unsigned long n; unsigned long nmax; } *d); int (*reset)(void *state, unsigned long dim); unsigned int (*order)(void *state); void (*free)(void *state); } *T; struct gsl_odeiv2_control_struct *control; struct gsl_odeiv2_step_struct *step; struct gsl_odeiv2_evolve_struct *evolve; struct gsl_odeiv2_system sys; double *yerr; double *y_pred; double *to_be_sorted; unsigned long *index_sorted; struct gsl_interp_accel { unsigned long cache; unsigned long miss_count; unsigned long hit_count; } ***acc; struct gsl_spline { struct gsl_interp { struct gsl_interp_type { char *name; unsigned int min_size; void *(*alloc)(unsigned long size); int (*init)(void *, double xa[], double ya[], unsigned long size); int (*eval)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y); int (*eval_deriv)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_p); int (*eval_deriv2)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_pp); int (*eval_integ)(void *, double xa[], double ya[], unsigned long size, struct gsl_interp_accel *, double a, double b, double *result); void (*free)(void *); } *type; double xmin; double xmax; unsigned long size; void *state; } *interp; double *x; double *y; unsigned long size; } ***spline; unsigned int *n_spline; double *pop_size_t0; struct s_par *p_par; struct s_data *p_data; void *method_specific_thread_safe_data; void *method_specific_shared_data; } *p_calc; struct s_likelihood { double ess_n; double Llike_best_n; double Llike_best; double *weights; unsigned int **select; int n_all_fail; double Llike_prev; double Llike_new; } *p_like; } *

user_defined_types: struct s_thread_mif { void *context; int thread_id; int J_chunk; int J; struct s_data *p_data; struct s_par **J_p_par; struct s_X ***J_p_X; struct s_calc *p_calc; struct s_likelihood *p_like; }

user_defined_types: struct zmq_pollitem_t { void *socket; int fd; short events; short revents; }


original_code:
void *worker_routine_predict_inproc(void *params)
{
    int j;
    int k, kp1, id;
    struct s_thread_predict *p = (struct s_thread_predict *) params;
    struct s_data *p_data = p->p_data;
    struct s_par **J_p_par = p->J_p_par;
    struct s_calc *p_calc = p->p_calc;
    struct s_X **J_p_X = p->J_p_X;
    plom_f_pred_t f_pred = get_f_pred(p_data->implementation, p_data->noises_off);
    void *controller = zmq_socket (p->context, 2);
    zmq_connect (controller, "inproc://server_controller");
    zmq_setsockopt (controller, 6, "", 0);
    void *receiver = zmq_socket (p->context, 7);
    zmq_connect (receiver, "inproc://server_sender");
    void *sender = zmq_socket (p->context, 8);
    zmq_connect (sender, "inproc://server_receiver");
    zmq_send(sender, &p->thread_id, sizeof (int), 0);
    zmq_pollitem_t items [] = {
        { receiver, 0, 1, 0 },
        { controller, 0, 1, 0 }
    };
    while (1) {
        zmq_poll (items, 2, -1);
        if (items [0].revents & 1) {
     zmq_recv(receiver, &id, sizeof (int), 0);
     zmq_recv(receiver, &k, sizeof (int), 0);
     kp1 = k+1;
     int J_start = id * p->J_chunk;
     int J_end = (id+1 == p_calc->n_threads) ? p->J : (id+1)*p->J_chunk;
     for(j=J_start; j<J_end; j++ ){
  reset_inc(J_p_X[j], p_data);
  f_pred(J_p_X[j], k, kp1, J_p_par[j], p_data, p_calc);
  proj2obs(J_p_X[j], p_data);
     }
     zmq_send(sender, &p->thread_id, sizeof (int), 0);
 }
        if (items [1].revents & 1) {
     char buf [256];
     zmq_recv(controller, buf, 256, 0);
            if(strcmp(buf, "KILL") == 0) {
                break;
            }
        }
    }
    zmq_close (receiver);
    zmq_close (sender);
    zmq_close (controller);
    return ((void *)0);
}

canonical_original_code:
void *worker_routine_predict_inproc(void *params)
{
    int j;
    int k; int kp1; int id;
    struct s_thread_predict *p = (struct s_thread_predict *) params;
    struct s_data *p_data = p->p_data;
    struct s_par **J_p_par = p->J_p_par;
    struct s_calc *p_calc = p->p_calc;
    struct s_X **J_p_X = p->J_p_X;
    void (*f_pred)(struct s_X *, double, double, struct s_par *, struct s_data *, struct s_calc *) = get_f_pred(p_data->implementation, p_data->noises_off);
    void *controller = zmq_socket (p->context, 2);
    zmq_connect (controller, "inproc://server_controller");
    zmq_setsockopt (controller, 6, "", 0);
    void *receiver = zmq_socket (p->context, 7);
    zmq_connect (receiver, "inproc://server_sender");
    void *sender = zmq_socket (p->context, 8);
    zmq_connect (sender, "inproc://server_receiver");
    zmq_send(sender, &p->thread_id, sizeof (int), 0);
    struct zmq_pollitem_t items[] = {
        { receiver, 0, 1, 0 },
        { controller, 0, 1, 0 }
    };
    while (1) {
        zmq_poll (items, 2, -1);
        if (items [0].revents & 1) {
     zmq_recv(receiver, &id, sizeof (int), 0);
     zmq_recv(receiver, &k, sizeof (int), 0);
     kp1 = k+1;
     int J_start = id * p->J_chunk;
     int J_end = (id+1 == p_calc->n_threads) ? p->J : (id+1)*p->J_chunk;
     for(j=J_start; j<J_end; j++ ){
  reset_inc(J_p_X[j], p_data);
  f_pred(J_p_X[j], k, kp1, J_p_par[j], p_data, p_calc);
  proj2obs(J_p_X[j], p_data);
     }
     zmq_send(sender, &p->thread_id, sizeof (int), 0);
 }
        if (items [1].revents & 1) {
     char buf[256];
     zmq_recv(controller, buf, 256, 0);
            if(strcmp(buf, "KILL") == 0) {
                break;
            }
        }
    }
    zmq_close (receiver);
    zmq_close (sender);
    zmq_close (controller);
    return ((void *)0);
}

variable_types: struct s_thread_predict { void *context; int thread_id; int J_chunk; int J; struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 } implementation; enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr } noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind { int n_nonan; unsigned int *ind_nonan; } **data_ind; struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; } **obs2ts; struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; } **routers; struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **drift; struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; } *p_data; struct s_par { int size_natural; double **natural; } **J_p_par; struct s_X { double *proj; double *obs; double dt; double dt0; } **J_p_X; struct s_calc { int n_threads; int thread_id; struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *randgsl; double **prob; unsigned int ***inc; struct gsl_odeiv2_step_type { char *name; int can_use_dydt_in; int gives_exact_dydt_out; void *(*alloc)(unsigned long dim); int (*apply)(void *state, unsigned long dim, double t, double h, double y[], double yerr[], double dydt_in[], double dydt_out[], struct gsl_odeiv2_system { int (*function)(double t, double y[], double dydt[], void *params); int (*jacobian)(double t, double y[], double *dfdy, double dfdt[], void *params); unsigned long dimension; void *params; } *dydt); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct { struct gsl_odeiv2_system *sys; struct gsl_odeiv2_step_struct { struct gsl_odeiv2_step_type *type; unsigned long dimension; void *state; } *s; struct gsl_odeiv2_control_struct { struct gsl_odeiv2_control_type { char *name; void *(*alloc)(); int (*init)(void *state, double eps_abs, double eps_rel, double a_y, double a_dydt); int (*hadjust)(void *state, unsigned long dim, unsigned int ord, double y[], double yerr[], double yp[], double *h); int (*errlevel)(void *state, double y, double dydt, double h, unsigned long ind, double *errlev); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct *d); void (*free)(void *state); } *type; void *state; } *c; struct gsl_odeiv2_evolve_struct { unsigned long dimension; double *y0; double *yerr; double *dydt_in; double *dydt_out; double last_step; unsigned long count; unsigned long failed_steps; struct gsl_odeiv2_driver_struct *driver; } *e; double h; double hmin; double hmax; unsigned long n; unsigned long nmax; } *d); int (*reset)(void *state, unsigned long dim); unsigned int (*order)(void *state); void (*free)(void *state); } *T; struct gsl_odeiv2_control_struct *control; struct gsl_odeiv2_step_struct *step; struct gsl_odeiv2_evolve_struct *evolve; struct gsl_odeiv2_system sys; double *yerr; double *y_pred; double *to_be_sorted; unsigned long *index_sorted; struct gsl_interp_accel { unsigned long cache; unsigned long miss_count; unsigned long hit_count; } ***acc; struct gsl_spline { struct gsl_interp { struct gsl_interp_type { char *name; unsigned int min_size; void *(*alloc)(unsigned long size); int (*init)(void *, double xa[], double ya[], unsigned long size); int (*eval)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y); int (*eval_deriv)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_p); int (*eval_deriv2)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_pp); int (*eval_integ)(void *, double xa[], double ya[], unsigned long size, struct gsl_interp_accel *, double a, double b, double *result); void (*free)(void *); } *type; double xmin; double xmax; unsigned long size; void *state; } *interp; double *x; double *y; unsigned long size; } ***spline; unsigned int *n_spline; double *pop_size_t0; struct s_par *p_par; struct s_data *p_data; void *method_specific_thread_safe_data; void *method_specific_shared_data; } *p_calc; } *

user_defined_types: struct s_thread_predict { void *context; int thread_id; int J_chunk; int J; struct s_data *p_data; struct s_par **J_p_par; struct s_X **J_p_X; struct s_calc *p_calc; }

user_defined_types: struct s_calc { int n_threads; int thread_id; struct gsl_rng *randgsl; double **prob; unsigned int ***inc; struct gsl_odeiv2_step_type *T; struct gsl_odeiv2_control_struct *control; struct gsl_odeiv2_step_struct *step; struct gsl_odeiv2_evolve_struct *evolve; struct gsl_odeiv2_system sys; double *yerr; double *y_pred; double *to_be_sorted; unsigned long *index_sorted; struct gsl_interp_accel ***acc; struct gsl_spline ***spline; unsigned int *n_spline; double *pop_size_t0; struct s_par *p_par; struct s_data *p_data; void *method_specific_thread_safe_data; void *method_specific_shared_data; }


original_code:
void compute_best_traj(struct s_hat **D_p_hat_best, struct s_hat **D_p_hat_prev, struct s_hat **D_p_hat_new, struct s_data *p_data, double alpha, double m)
{
    int n, i, ts;
    for(n=1; n<(N_DATA+1); n++) {
        for(i=0 ; i<N_PAR_SV*N_CAC ; i++) {
            D_p_hat_best[n]->state[i] = ((m-1.0)/m)*D_p_hat_best[n]->state[i] + (1.0/m)*(alpha*D_p_hat_new[n]->state[i] + (1.0-alpha)*D_p_hat_prev[n]->state[i]);
            D_p_hat_best[n]->state_95[i][0] = ((m-1.0)/m)*D_p_hat_best[n]->state_95[i][0] + (1.0/m)*(alpha*D_p_hat_new[n]->state_95[i][0] + (1.0-alpha)*D_p_hat_prev[n]->state_95[i][0]);
            D_p_hat_best[n]->state_95[i][1] = ((m-1.0)/m)*D_p_hat_best[n]->state_95[i][1] + (1.0/m)*(alpha*D_p_hat_new[n]->state_95[i][1] + (1.0-alpha)*D_p_hat_prev[n]->state_95[i][1]);
        }
        for(ts=0; ts< N_TS; ts++) {
            D_p_hat_best[n]->obs[ts] = ((m-1.0)/m)*D_p_hat_best[n]->obs[ts] + (1.0/m)*(alpha*D_p_hat_new[n]->obs[ts] + (1.0-alpha)*D_p_hat_prev[n]->obs[ts]);
            D_p_hat_best[n]->obs_95[ts][0] = ((m-1.0)/m)*D_p_hat_best[n]->obs_95[ts][0] + (1.0/m)*(alpha*D_p_hat_new[n]->obs_95[ts][0] + (1.0-alpha)*D_p_hat_prev[n]->obs_95[ts][0]);
            D_p_hat_best[n]->obs_95[ts][1] = ((m-1.0)/m)*D_p_hat_best[n]->obs_95[ts][1] + (1.0/m)*(alpha*D_p_hat_new[n]->obs_95[ts][1] + (1.0-alpha)*D_p_hat_prev[n]->obs_95[ts][1]);
        }
        for(i=0; i< p_data->p_it_only_drift->nbtot; i++) {
            D_p_hat_best[n]->drift[i] = ((m-1.0)/m)*D_p_hat_best[n]->drift[i] + (1.0/m)*(alpha*D_p_hat_new[n]->drift[i] + (1.0-alpha)*D_p_hat_prev[n]->drift[i]);
            D_p_hat_best[n]->drift_95[i][0] = ((m-1.0)/m)*D_p_hat_best[n]->drift_95[i][0] + (1.0/m)*(alpha*D_p_hat_new[n]->drift_95[i][0] + (1.0-alpha)*D_p_hat_prev[n]->drift_95[i][0]);
            D_p_hat_best[n]->drift_95[i][1] = ((m-1.0)/m)*D_p_hat_best[n]->drift_95[i][1] + (1.0/m)*(alpha*D_p_hat_new[n]->drift_95[i][1] + (1.0-alpha)*D_p_hat_prev[n]->drift_95[i][1]);
        }
    }
}

canonical_original_code:
void compute_best_traj(struct s_hat **D_p_hat_best, struct s_hat **D_p_hat_prev, struct s_hat **D_p_hat_new, struct s_data *p_data, double alpha, double m)
{
    int n; int i; int ts;
    for(n=1; n<(N_DATA+1); n++) {
        for(i=0 ; i<N_PAR_SV*N_CAC ; i++) {
            D_p_hat_best[n]->state[i] = ((m-1.0)/m)*D_p_hat_best[n]->state[i] + (1.0/m)*(alpha*D_p_hat_new[n]->state[i] + (1.0-alpha)*D_p_hat_prev[n]->state[i]);
            D_p_hat_best[n]->state_95[i][0] = ((m-1.0)/m)*D_p_hat_best[n]->state_95[i][0] + (1.0/m)*(alpha*D_p_hat_new[n]->state_95[i][0] + (1.0-alpha)*D_p_hat_prev[n]->state_95[i][0]);
            D_p_hat_best[n]->state_95[i][1] = ((m-1.0)/m)*D_p_hat_best[n]->state_95[i][1] + (1.0/m)*(alpha*D_p_hat_new[n]->state_95[i][1] + (1.0-alpha)*D_p_hat_prev[n]->state_95[i][1]);
        }
        for(ts=0; ts< N_TS; ts++) {
            D_p_hat_best[n]->obs[ts] = ((m-1.0)/m)*D_p_hat_best[n]->obs[ts] + (1.0/m)*(alpha*D_p_hat_new[n]->obs[ts] + (1.0-alpha)*D_p_hat_prev[n]->obs[ts]);
            D_p_hat_best[n]->obs_95[ts][0] = ((m-1.0)/m)*D_p_hat_best[n]->obs_95[ts][0] + (1.0/m)*(alpha*D_p_hat_new[n]->obs_95[ts][0] + (1.0-alpha)*D_p_hat_prev[n]->obs_95[ts][0]);
            D_p_hat_best[n]->obs_95[ts][1] = ((m-1.0)/m)*D_p_hat_best[n]->obs_95[ts][1] + (1.0/m)*(alpha*D_p_hat_new[n]->obs_95[ts][1] + (1.0-alpha)*D_p_hat_prev[n]->obs_95[ts][1]);
        }
        for(i=0; i< p_data->p_it_only_drift->nbtot; i++) {
            D_p_hat_best[n]->drift[i] = ((m-1.0)/m)*D_p_hat_best[n]->drift[i] + (1.0/m)*(alpha*D_p_hat_new[n]->drift[i] + (1.0-alpha)*D_p_hat_prev[n]->drift[i]);
            D_p_hat_best[n]->drift_95[i][0] = ((m-1.0)/m)*D_p_hat_best[n]->drift_95[i][0] + (1.0/m)*(alpha*D_p_hat_new[n]->drift_95[i][0] + (1.0-alpha)*D_p_hat_prev[n]->drift_95[i][0]);
            D_p_hat_best[n]->drift_95[i][1] = ((m-1.0)/m)*D_p_hat_best[n]->drift_95[i][1] + (1.0/m)*(alpha*D_p_hat_new[n]->drift_95[i][1] + (1.0-alpha)*D_p_hat_prev[n]->drift_95[i][1]);
        }
    }
}

variable_types: struct s_hat { double *state; double **state_95; double *remainder; double **remainder_95; double *obs; double **obs_95; double *drift; double **drift_95; } **

variable_types: struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 } implementation; enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr } noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind { int n_nonan; unsigned int *ind_nonan; } **data_ind; struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; } **obs2ts; struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; } **routers; struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **drift; struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; } *

variable_types: alpha double

variable_types: m double

variable_types: n int

variable_types: i int

variable_types: ts int


decompiled_code:
void __fastcall clean2u(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = (void **)ptr;
do
{
free(*v2);
*v2++ = 0LL;
}
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

original_code:
void clean2u(unsigned int **tab, int n)
{
    int i;
    for(i=0; i<n; i++)
 do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}

variable_types:
tab
unsigned int **


original_code:
void clean3u(unsigned int ***tab, int n, int p1)
{
    int i, j;
    for(i=0; i<n; i++)
 for(j=0; j<p1; j++)
     do { free( tab[i][j] ); tab[i][j] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
 do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}

canonical_original_code:
void clean3u(unsigned int ***tab, int n, int p1)
{
    int i; int j;
    for(i=0; i<n; i++)
 for(j=0; j<p1; j++)
     do { free( tab[i][j] ); tab[i][j] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
 do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}

variable_types:
tab
unsigned int ***

variable_types: j int


original_code:
void clean4u(unsigned int ****tab, int n, int p1, int p2)
{
    int i, j, k;
    for(i=0; i<n; i++)
 for(j=0; j<p1; j++)
     for(k=0; k<p2; k++)
  do { free( tab[i][j][k] ); tab[i][j][k] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
 for(j=0; j<p1; j++)
     do { free( tab[i][j] ); tab[i][j] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
 do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}

canonical_original_code:
void clean4u(unsigned int ****tab, int n, int p1, int p2)
{
    int i; int j; int k;
    for(i=0; i<n; i++)
 for(j=0; j<p1; j++)
     for(k=0; k<p2; k++)
  do { free( tab[i][j][k] ); tab[i][j][k] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
 for(j=0; j<p1; j++)
     do { free( tab[i][j] ); tab[i][j] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
 do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}

variable_types:
tab
unsigned int ****

variable_types: k int


original_code:
void clean3u_var(unsigned int ***tab, int n, unsigned int *p1)
{
    int i, j;
    for(i=0; i<n; i++)
 for(j=0; j<p1[i]; j++)
     do { free( tab[i][j] ); tab[i][j] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
 do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}

canonical_original_code:
void clean3u_var(unsigned int ***tab, int n, unsigned int *p1)
{
    int i; int j;
    for(i=0; i<n; i++)
 for(j=0; j<p1[i]; j++)
     do { free( tab[i][j] ); tab[i][j] = ((void *)0); }while(0);
    for(i=0; i<n; i++)
 do { free( tab[i] ); tab[i] = ((void *)0); }while(0);
    do { free( tab ); tab = ((void *)0); }while(0);
}


decompiled_code:
void __fastcall clean_pmcmc(void *ptr)
{
clean_best(*((_QWORD *)ptr + 2));
clean_par(*((_QWORD *)ptr + 5));
clean_D_J_p_X(*((_QWORD *)ptr + 3));
clean_D_J_p_X(*((_QWORD *)ptr + 4));
clean_D_p_hat(*((_QWORD *)ptr + 7), *(_QWORD *)ptr);
clean_D_p_hat(*((_QWORD *)ptr + 6), *(_QWORD *)ptr);
clean_D_p_hat(*((_QWORD *)ptr + 8), *(_QWORD *)ptr);
clean_likelihood(*((_QWORD *)ptr + 9));
clean_mcmc_calc_data(*(_QWORD *)(**((_QWORD **)ptr + 1) + 184LL));
clean_calc(*((_QWORD *)ptr + 1), *(_QWORD *)ptr);
clean_data(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
clean_best(*((_QWORD *)ptr + 2));
clean_par(*((_QWORD *)ptr + 5));
clean_D_J_p_X(*((_QWORD *)ptr + 3));
clean_D_J_p_X(*((_QWORD *)ptr + 4));
clean_D_p_hat(*((_QWORD *)ptr + 7), *(_QWORD *)ptr);
clean_D_p_hat(*((_QWORD *)ptr + 6), *(_QWORD *)ptr);
clean_D_p_hat(*((_QWORD *)ptr + 8), *(_QWORD *)ptr);
clean_likelihood(*((_QWORD *)ptr + 9));
clean_mcmc_calc_data(*(_QWORD *)(**((_QWORD **)ptr + 1) + 184LL));
clean_calc(*((_QWORD *)ptr + 1), *(_QWORD *)ptr);
clean_data(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void clean_pmcmc(struct s_pmcmc *p)
{
    clean_best(p->p_best);
    clean_par(p->p_par);
    clean_D_J_p_X(p->D_J_p_X);
    clean_D_J_p_X(p->D_J_p_X_tmp);
    clean_D_p_hat(p->D_p_hat_new, p->p_data);
    clean_D_p_hat(p->D_p_hat_prev, p->p_data);
    clean_D_p_hat(p->D_p_hat_best, p->p_data);
    clean_likelihood(p->p_like);
    clean_mcmc_calc_data((struct s_mcmc_calc_data *) p->calc[0]->method_specific_shared_data);
    clean_calc(p->calc, p->p_data);
    clean_data(p->p_data);
    do { free( p ); p = ((void *)0); }while(0);
}

variable_types: struct s_pmcmc { struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 } implementation; enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr } noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind { int n_nonan; unsigned int *ind_nonan; } **data_ind; struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; } **obs2ts; struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; } **routers; struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **drift; struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; } *p_data; struct s_calc { int n_threads; int thread_id; struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *randgsl; double **prob; unsigned int ***inc; struct gsl_odeiv2_step_type { char *name; int can_use_dydt_in; int gives_exact_dydt_out; void *(*alloc)(unsigned long dim); int (*apply)(void *state, unsigned long dim, double t, double h, double y[], double yerr[], double dydt_in[], double dydt_out[], struct gsl_odeiv2_system { int (*function)(double t, double y[], double dydt[], void *params); int (*jacobian)(double t, double y[], double *dfdy, double dfdt[], void *params); unsigned long dimension; void *params; } *dydt); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct { struct gsl_odeiv2_system *sys; struct gsl_odeiv2_step_struct { struct gsl_odeiv2_step_type *type; unsigned long dimension; void *state; } *s; struct gsl_odeiv2_control_struct { struct gsl_odeiv2_control_type { char *name; void *(*alloc)(); int (*init)(void *state, double eps_abs, double eps_rel, double a_y, double a_dydt); int (*hadjust)(void *state, unsigned long dim, unsigned int ord, double y[], double yerr[], double yp[], double *h); int (*errlevel)(void *state, double y, double dydt, double h, unsigned long ind, double *errlev); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct *d); void (*free)(void *state); } *type; void *state; } *c; struct gsl_odeiv2_evolve_struct { unsigned long dimension; double *y0; double *yerr; double *dydt_in; double *dydt_out; double last_step; unsigned long count; unsigned long failed_steps; struct gsl_odeiv2_driver_struct *driver; } *e; double h; double hmin; double hmax; unsigned long n; unsigned long nmax; } *d); int (*reset)(void *state, unsigned long dim); unsigned int (*order)(void *state); void (*free)(void *state); } *T; struct gsl_odeiv2_control_struct *control; struct gsl_odeiv2_step_struct *step; struct gsl_odeiv2_evolve_struct *evolve; struct gsl_odeiv2_system sys; double *yerr; double *y_pred; double *to_be_sorted; unsigned long *index_sorted; struct gsl_interp_accel { unsigned long cache; unsigned long miss_count; unsigned long hit_count; } ***acc; struct gsl_spline { struct gsl_interp { struct gsl_interp_type { char *name; unsigned int min_size; void *(*alloc)(unsigned long size); int (*init)(void *, double xa[], double ya[], unsigned long size); int (*eval)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y); int (*eval_deriv)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_p); int (*eval_deriv2)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_pp); int (*eval_integ)(void *, double xa[], double ya[], unsigned long size, struct gsl_interp_accel *, double a, double b, double *result); void (*free)(void *); } *type; double xmin; double xmax; unsigned long size; void *state; } *interp; double *x; double *y; unsigned long size; } ***spline; unsigned int *n_spline; double *pop_size_t0; struct s_par { int size_natural; double **natural; } *p_par; struct s_data *p_data; void *method_specific_thread_safe_data; void *method_specific_shared_data; } **calc; struct s_best { int length; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *mean; struct gsl_vector *proposed; struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; } *var; int n_to_be_estimated; unsigned int *to_be_estimated; unsigned int *is_estimated; int n_follow; unsigned int *follower; unsigned int *follow; unsigned int *is_follower; double *mean_sampling; struct gsl_matrix *var_sampling; double **par_prior; double (**prior)(double x, double a, double b); } *p_best; struct s_X { double *proj; double *obs; double dt; double dt0; } ***D_J_p_X; struct s_X ***D_J_p_X_tmp; struct s_par *p_par; struct s_hat { double *state; double **state_95; double *remainder; double **remainder_95; double *obs; double **obs_95; double *drift; double **drift_95; } **D_p_hat_prev; struct s_hat **D_p_hat_new; struct s_hat **D_p_hat_best; struct s_likelihood { double ess_n; double Llike_best_n; double Llike_best; double *weights; unsigned int **select; int n_all_fail; double Llike_prev; double Llike_new; } *p_like; } *

user_defined_types: struct s_pmcmc { struct s_data *p_data; struct s_calc **calc; struct s_best *p_best; struct s_X ***D_J_p_X; struct s_X ***D_J_p_X_tmp; struct s_par *p_par; struct s_hat **D_p_hat_prev; struct s_hat **D_p_hat_new; struct s_hat **D_p_hat_best; struct s_likelihood *p_like; }

user_defined_types: struct s_mcmc_calc_data { double epsilon; double epsilon_max; double a; int m_switch; int m_epsilon; double global_acceptance_rate; double smoothed_global_acceptance_rate; double alpha; int is_smoothed_tunning; int n_acceptance_rates; double *acceptance_rates; double *smoothed_acceptance_rates; int has_cycled; int m_full_iteration; int cycle_id; }

user_defined_types: struct gsl_rng { struct gsl_rng_type *type; void *state; }

user_defined_types: struct gsl_odeiv2_step_type { char *name; int can_use_dydt_in; int gives_exact_dydt_out; void *(*alloc)(unsigned long dim); int (*apply)(void *state, unsigned long dim, double t, double h, double y[], double yerr[], double dydt_in[], double dydt_out[], struct gsl_odeiv2_system *dydt); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct *d); int (*reset)(void *state, unsigned long dim); unsigned int (*order)(void *state); void (*free)(void *state); }