decompiled_code:
__int64 __fastcall f_prediction_sde_no_env_sto(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5, double a6)
{
__int64 result; // rax

for ( ; a6 > a5; a5 = a5 + *(double *)(a1 + 16) )
{
while ( 1 )
{
step_sde_no_env_sto(a1, a2, a3, a4);
result = (unsigned int)N_DRIFT;
if ( N_DRIFT )
break;
a5 = a5 + *(double *)(a1 + 16);
if ( a6 <= a5 )
return result;
}
result = compute_drift(a1, a2, a3, a4, a5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5, double a6)
{
__int64 result; // rax

for ( ; a6 > a5; a5 = a5 + *(double *)(a1 + 16) )
{
while ( 1 )
{
step_sde_no_env_sto(a1, a2, a3, a4);
result = (unsigned int)N_DRIFT;
if ( N_DRIFT )
break;
a5 = a5 + *(double *)(a1 + 16);
if ( a6 <= a5 )
return result;
}
result = compute_drift(a1, a2, a3, a4, a5);
}
return result;
}

original_code:
void f_prediction_sde_no_env_sto(struct s_X *p_X, double t0, double t1, struct s_par *p_par, struct s_data *p_data, struct s_calc *p_calc)
{
    double t = t0;
    while (t < t1) {
 step_sde_no_env_sto(p_X, t, p_par, p_data, p_calc);
        if (N_DRIFT) {
            compute_drift(p_X, p_par, p_data, p_calc);
        }
 t += p_X->dt;
    }
}

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

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_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 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; }

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; }


repo: QCaudron/iterated-inference-pipeline

decompiled_code:
__int64 __fastcall f_prediction_sde_no_drift(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5, double a6)
{
__int64 result; // rax

for ( ; a6 > a5; a5 = a5 + *(double *)(a1 + 16) )
result = step_sde_full(a1, a2, a3, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5, double a6)
{
__int64 result; // rax

for ( ; a6 > a5; a5 = a5 + *(double *)(a1 + 16) )
result = step_sde_full(a1, a2, a3, a4);
return result;
}

original_code:
void f_prediction_sde_no_drift(struct s_X *p_X, double t0, double t1, struct s_par *p_par, struct s_data *p_data, struct s_calc *p_calc)
{
    double t = t0;
    while (t < t1) {
 step_sde_full(p_X, t, p_par, p_data, p_calc);
 t += p_X->dt;
    }
}

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

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

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: t double

return_type: void

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_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; }


decompiled_code:
__int64 __fastcall f_prediction_sde_full(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5, double a6)
{
__int64 result; // rax

for ( ; a6 > a5; a5 = a5 + *(double *)(a1 + 16) )
{
while ( 1 )
{
step_sde_full(a1, a2, a3, a4);
result = (unsigned int)N_DRIFT;
if ( N_DRIFT )
break;
a5 = a5 + *(double *)(a1 + 16);
if ( a6 <= a5 )
return result;
}
result = compute_drift(a1, a2, a3, a4, a5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5, double a6)
{
__int64 result; // rax

for ( ; a6 > a5; a5 = a5 + *(double *)(a1 + 16) )
{
while ( 1 )
{
step_sde_full(a1, a2, a3, a4);
result = (unsigned int)N_DRIFT;
if ( N_DRIFT )
break;
a5 = a5 + *(double *)(a1 + 16);
if ( a6 <= a5 )
return result;
}
result = compute_drift(a1, a2, a3, a4, a5);
}
return result;
}

original_code:
void f_prediction_sde_full(struct s_X *p_X, double t0, double t1, struct s_par *p_par, struct s_data *p_data, struct s_calc *p_calc)
{
    double t = t0;
    while (t < t1) {
 step_sde_full(p_X, t, p_par, p_data, p_calc);
        if (N_DRIFT) {
            compute_drift(p_X, p_par, p_data, p_calc);
        }
 t += p_X->dt;
    }
}

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

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 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); }

user_defined_types: struct gsl_interp_accel { unsigned long cache; unsigned long miss_count; unsigned long hit_count; }

user_defined_types: 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; }

user_defined_types: struct gsl_odeiv2_step_struct { struct gsl_odeiv2_step_type *type; unsigned long dimension; void *state; }

user_defined_types: 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; }

user_defined_types: 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 *); }

user_defined_types: 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); }


decompiled_code:
__int64 __fastcall f_prediction_psr(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5, double a6)
{
__int64 result; // rax

for ( ; a6 > a5; a5 = a5 + *(double *)(a1 + 16) )
{
while ( 1 )
{
step_psr(a1, a2, a3, a4);
result = (unsigned int)N_DRIFT;
if ( N_DRIFT )
break;
a5 = a5 + *(double *)(a1 + 16);
if ( a6 <= a5 )
return result;
}
result = compute_drift(a1, a2, a3, a4, a5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5, double a6)
{
__int64 result; // rax

for ( ; a6 > a5; a5 = a5 + *(double *)(a1 + 16) )
{
while ( 1 )
{
step_psr(a1, a2, a3, a4);
result = (unsigned int)N_DRIFT;
if ( N_DRIFT )
break;
a5 = a5 + *(double *)(a1 + 16);
if ( a6 <= a5 )
return result;
}
result = compute_drift(a1, a2, a3, a4, a5);
}
return result;
}

original_code:
void f_prediction_psr(struct s_X *p_X, double t0, double t1, struct s_par *p_par, struct s_data *p_data, struct s_calc *p_calc)
{
    double t = t0;
    while (t < t1) {
        step_psr(p_X, t, p_par, p_data, p_calc);
        if (N_DRIFT) {
            compute_drift(p_X, p_par, p_data, p_calc);
        }
 t += p_X->dt;
    }
}

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

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_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 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; }

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; }


decompiled_code:
__int64 __fastcall f_prediction_psr_no_drift(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5, double a6)
{
__int64 result; // rax

for ( ; a6 > a5; a5 = a5 + *(double *)(a1 + 16) )
result = step_psr(a1, a2, a3, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5, double a6)
{
__int64 result; // rax

for ( ; a6 > a5; a5 = a5 + *(double *)(a1 + 16) )
result = step_psr(a1, a2, a3, a4);
return result;
}

original_code:
void f_prediction_psr_no_drift(struct s_X *p_X, double t0, double t1, struct s_par *p_par, struct s_data *p_data, struct s_calc *p_calc)
{
    double t = t0;
    while (t < t1) {
        step_psr(p_X, t, p_par, p_data, p_calc);
 t += p_X->dt;
    }
}

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

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 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; }


decompiled_code:
unsigned __int64 __fastcall reset_inc(_QWORD *a1, __int64 a2)
{
unsigned __int64 result; // rax

result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(a2 + 104) + 24LL) + N_CAC * N_PAR_SV);
if ( N_TS_INC_UNIQUE > 0 )
result = (unsigned __int64)memset((void *)(*a1 + 8LL * (int)result), 0, 8LL * N_TS_INC_UNIQUE);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(_QWORD *a1, __int64 a2)
{
unsigned __int64 result; // rax

result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(a2 + 104) + 24LL) + N_CAC * N_PAR_SV);
if ( N_TS_INC_UNIQUE > 0 )
result = (unsigned __int64)memset((void *)(*a1 + 8LL * (int)result), 0, 8LL * N_TS_INC_UNIQUE);
return result;
}

original_code:
void reset_inc(struct s_X *p_X, struct s_data *p_data)
{
    double *X = p_X->proj;
    int offset = N_PAR_SV*N_CAC + p_data->p_it_only_drift->nbtot;
    int oi;
    for (oi=0; oi<N_TS_INC_UNIQUE; oi++) {
        X[offset + oi]=0.0;
    }
}

variable_types:
X
double *

variable_types: offset int

variable_types: oi int

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


decompiled_code:
void __fastcall round_inc(__int64 *a1, __int64 a2)
{
__int64 v2; // rcx
int v3; // eax
double *v4; // rbx
__int64 v5; // rbp
double v6; // xmm0_8

v2 = *a1;
v3 = *(_DWORD *)(*(_QWORD *)(a2 + 104) + 24LL) + N_CAC * N_PAR_SV;
if ( N_TS_INC_UNIQUE > 0 )
{
v4 = (double *)(v2 + 8LL * v3);
v5 = v2 + 8 * ((unsigned int)(N_TS_INC_UNIQUE - 1) + (__int64)v3) + 8;
do
{
v6 = *v4++;
*(v4 - 1) = round(v6);
}
while ( v4 != (double *)v5 );
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 *a1, __int64 a2)
{
__int64 v2; // rcx
int v3; // eax
double *v4; // rbx
__int64 v5; // rbp
double v6; // xmm0_8

v2 = *a1;
v3 = *(_DWORD *)(*(_QWORD *)(a2 + 104) + 24LL) + N_CAC * N_PAR_SV;
if ( N_TS_INC_UNIQUE > 0 )
{
v4 = (double *)(v2 + 8LL * v3);
v5 = v2 + 8 * ((unsigned int)(N_TS_INC_UNIQUE - 1) + (__int64)v3) + 8;
do
{
v6 = *v4++;
*(v4 - 1) = round(v6);
}
while ( v4 != (double *)v5 );
}
}

original_code:
void round_inc(struct s_X *p_X, struct s_data *p_data)
{
    double *X = p_X->proj;
    int offset = N_PAR_SV*N_CAC + p_data->p_it_only_drift->nbtot;
    int oi;
    for (oi=0; oi<N_TS_INC_UNIQUE; oi++) {
        X[offset + oi]=round(X[offset + oi]);
    }
}

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


decompiled_code:
double __fastcall sum_SV(__int64 a1, int a2)
{
double *v2; // rdx
double result; // xmm0_8
int v4; // eax

if ( N_PAR_SV <= 0 )
return 0.0;
v2 = (double *)(a1 + 8LL * a2);
result = 0.0;
v4 = 0;
do
{
++v4;
result = result + *v2;
v2 += N_CAC;
}
while ( v4 != N_PAR_SV );
return result;
}

canonical_decompiled_code:
double __fastcall func12(__int64 a1, int a2)
{
double *v2; // rdx
double result; // xmm0_8
int v4; // eax

if ( N_PAR_SV <= 0 )
return 0.0;
v2 = (double *)(a1 + 8LL * a2);
result = 0.0;
v4 = 0;
do
{
++v4;
result = result + *v2;
v2 += N_CAC;
}
while ( v4 != N_PAR_SV );
return result;
}

original_code:
double sum_SV(const double *X_proj, int cac)
{
    int i;
    double current_p=0.0;
    for(i=0; i<N_PAR_SV; i++) {
        current_p += X_proj[i*N_CAC +cac];
    }
    return current_p;
}

canonical_original_code:
double sum_SV(double *X_proj, int cac)
{
    int i;
    double current_p = 0.0;
    for(i=0; i<N_PAR_SV; i++) {
        current_p += X_proj[i*N_CAC +cac];
    }
    return current_p;
}

variable_types: cac int

variable_types: i int

return_type: double


decompiled_code:
double __fastcall correct_rate(double a1, double a2)
{
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(1.0 - a1 * a2)) ^ LC3) / a2;
}

canonical_decompiled_code:
double __fastcall func13(double a1, double a2)
{
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(1.0 - a1 * a2)) ^ LC3) / a2;
}

original_code:
double correct_rate(double rate, double dt)
{
    return -log(1.0-rate*dt)/dt;
}

variable_types: rate double

variable_types: dt double


original_code:
void linearize_and_repeat(struct s_X *p_X, struct s_par *p_par, struct s_data *p_data, const struct s_iterator *p_it)
{
    double *expanded = p_X->proj;
    int i, k;
    struct s_router **routers = p_data->routers;
    int offset = 0;
    for(i=0; i< p_it->length; i++) {
        for(k=0; k< routers[ p_it->ind[i] ]->p; k++) {
            expanded[offset++] = p_par->natural[ p_it->ind[i] ][ routers[ p_it->ind[i] ]->map[k] ];
        }
    }
}

canonical_original_code:
void linearize_and_repeat(struct s_X *p_X, struct s_par *p_par, struct s_data *p_data, struct s_iterator *p_it)
{
    double *expanded = p_X->proj;
    int i; int k;
    struct s_router **routers = p_data->routers;
    int offset = 0;
    for(i=0; i< p_it->length; i++) {
        for(k=0; k< routers[ p_it->ind[i] ]->p; k++) {
            expanded[offset++] = p_par->natural[ p_it->ind[i] ][ routers[ p_it->ind[i] ]->map[k] ];
        }
    }
}

variable_types:
expanded
double *

variable_types: k int

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; } **


original_code:
void theta_driftIC2Xdrift(struct s_X *p_X, const theta_t *best_mean, struct s_data *p_data)
{
    int i, k;
    struct s_iterator *p_it = p_data->p_it_only_drift;
    struct s_router **routers = p_data->routers;
    struct s_drift **drift = p_data->drift;
    for(i=0; i< p_it->length; i++) {
        for(k=0; k< routers[ p_it->ind[i] ]->n_gp; k++) {
            p_X->proj[drift[i]->offset + k] = gsl_vector_get(best_mean, p_it->offset[i] +k );
        }
    }
}

canonical_original_code:
void theta_driftIC2Xdrift(struct s_X *p_X, struct gsl_vector *best_mean, struct s_data *p_data)
{
    int i; int k;
    struct s_iterator *p_it = p_data->p_it_only_drift;
    struct s_router **routers = p_data->routers;
    struct s_drift **drift = p_data->drift;
    for(i=0; i< p_it->length; i++) {
        for(k=0; k< routers[ p_it->ind[i] ]->n_gp; k++) {
            p_X->proj[drift[i]->offset + k] = gsl_vector_get(best_mean, p_it->offset[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_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *

variable_types: struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **

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


original_code:
void plom_ran_multinomial (const gsl_rng * r, const size_t K, unsigned int N, const double p[], unsigned int n[])
{
    size_t k;
    double sum_p = 0.0;
    unsigned int sum_n = 0;
    for (k = 0; k < K; k++) {
        if (p[k] > 0.0) {
            n[k] = gsl_ran_binomial (r, p[k] / (1.0 - sum_p), N - sum_n);
        }
        else {
            n[k] = 0;
        }
        sum_p += p[k];
        sum_n += n[k];
    }
}

canonical_original_code:
void plom_ran_multinomial(struct gsl_rng *r, unsigned long K, unsigned int N, double p[], unsigned int n[])
{
    unsigned long k;
    double sum_p = 0.0;
    unsigned int sum_n = 0;
    for (k = 0; k < K; k++) {
        if (p[k] > 0.0) {
            n[k] = gsl_ran_binomial (r, p[k] / (1.0 - sum_p), N - sum_n);
        }
        else {
            n[k] = 0;
        }
        sum_p += p[k];
        sum_n += n[k];
    }
}

variable_types: 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; } *

variable_types:
K
unsigned long

variable_types:
N
unsigned int

variable_types:
p
double []

variable_types:
n
unsigned int []

variable_types:
k
unsigned long

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


decompiled_code:
__int64 __fastcall has_failed(_QWORD *a1)
{
__int64 v1; // rax

if ( N_CAC * N_PAR_SV <= 0 )
return 0LL;
v1 = (__int64)&a1[(unsigned int)(N_CAC * N_PAR_SV - 1) + 1];
while ( COERCE_DOUBLE(*a1 & LC0) <= 1.797693134862316e308 )
{
if ( ++a1 == (_QWORD *)v1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 v1; // rax

if ( N_CAC * N_PAR_SV <= 0 )
return 0LL;
v1 = (__int64)&a1[(unsigned int)(N_CAC * N_PAR_SV - 1) + 1];
while ( COERCE_DOUBLE(*a1 & LC0) <= 1.797693134862316e308 )
{
if ( ++a1 == (_QWORD *)v1 )
return 0LL;
}
return 1LL;
}

original_code:
int has_failed(double *y)
{
    int i;
    for (i=0; i<(N_PAR_SV*N_CAC); i++) {
        if ( __builtin_isnan (y[i]) || __builtin_isinf_sign (y[i]) ) {
            return 1;
        }
    }
    return 0;
}

variable_types:
y
double *

return_type: int


integrator

decompiled_code:
__int64 __fastcall integrator(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4, __int64 a5, double a6, double a7, double a8, double a9)
{
_QWORD *v13; // rbp
__int64 v14; // xmm0_8
__int64 v15; // rdi
__int64 v16; // rax
int v17; // edx
__int64 i; // rax
unsigned int v20; // eax
__int64 v21; // rdx
double v22; // [rsp+20h] [rbp-148h] BYREF
__int64 v23; // [rsp+28h] [rbp-140h] BYREF
char s[312]; // [rsp+30h] [rbp-138h] BYREF

v13 = *(_QWORD **)a1;
v22 = a6;
v14 = *(_QWORD *)(a1 + 16);
v15 = a4[5];
v23 = v14;
gsl_odeiv2_control_free(v15);
v16 = gsl_odeiv2_control_y_new(a8, a9);
v17 = N_CAC * N_PAR_SV;
a4[20] = a3;
a4[5] = v16;
if ( v17 <= 0 )
goto LABEL_6;
for ( i = 0LL; i != v17; ++i )
v13[i] = *(_QWORD *)(a2 + 8 * i);
if ( a7 <= v22 )
return 0LL;
while ( 1 )
{
reset_inc(a1, a5);
if ( (unsigned int)gsl_odeiv2_evolve_apply(a4[7], a4[5], a4[6], a4 + 8, &v22, &v23, a7, v13) )
break;
LABEL_6:
if ( a7 <= v22 )
return 0LL;
}
v20 = has_failed(v13);
sprintf(s, "integration failure (status: %d has_failed: %d)", v21, v20);
print_err(s);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4, __int64 a5, double a6, double a7, double a8, double a9)
{
_QWORD *v13; // rbp
__int64 v14; // xmm0_8
__int64 v15; // rdi
__int64 v16; // rax
int v17; // edx
__int64 i; // rax
unsigned int v20; // eax
__int64 v21; // rdx
double v22; // [rsp+20h] [rbp-148h] BYREF
__int64 v23; // [rsp+28h] [rbp-140h] BYREF
char s[312]; // [rsp+30h] [rbp-138h] BYREF

v13 = *(_QWORD **)a1;
v22 = a6;
v14 = *(_QWORD *)(a1 + 16);
v15 = a4[5];
v23 = v14;
gsl_odeiv2_control_free(v15);
v16 = gsl_odeiv2_control_y_new(a8, a9);
v17 = N_CAC * N_PAR_SV;
a4[20] = a3;
a4[5] = v16;
if ( v17 <= 0 )
goto LABEL_6;
for ( i = 0LL; i != v17; ++i )
v13[i] = *(_QWORD *)(a2 + 8 * i);
if ( a7 <= v22 )
return 0LL;
while ( 1 )
{
reset_inc(a1, a5);
if ( (unsigned int)gsl_odeiv2_evolve_apply(a4[7], a4[5], a4[6], a4 + 8, &v22, &v23, a7, v13) )
break;
LABEL_6:
if ( a7 <= v22 )
return 0LL;
}
v20 = func0(v13);
sprintf(s, "integration failure (status: %d has_failed: %d)", v21, v20);
print_err(s);
return 1LL;
}

original_code:
int integrator(struct s_X *p_X, double *y0, double t0, double t_end, struct s_par *p_par, double abs_tol, double rel_tol, struct s_calc *p_calc, struct s_data *p_data)
{
    int status;
    int error=0;
    double t = t0;
    double h = p_X->dt;
    int i;
    double *y = p_X->proj;
    gsl_odeiv2_control_free(p_calc->control);
    p_calc->control = gsl_odeiv2_control_y_new(abs_tol, rel_tol);
    p_calc->p_par = p_par;
    for (i=0; i< (N_PAR_SV*N_CAC) ; i++) {
        y[i]=y0[i];
    }
    while (t < t_end) {
        reset_inc(p_X, p_data);
        status = gsl_odeiv2_evolve_apply(p_calc->evolve, p_calc->control, p_calc->step, &(p_calc->sys), &t, t_end, &h, y);
        if ( (status != GSL_SUCCESS) ) {
            char str[255];
            sprintf(str, "integration failure (status: %d has_failed: %d)", status, has_failed(y));
            print_err(str);
            error=1;
            break;
        }
    }
    return error;
}

canonical_original_code:
int integrator(struct s_X *p_X, double *y0, double t0, double t_end, struct s_par *p_par, double abs_tol, double rel_tol, struct s_calc *p_calc, struct s_data *p_data)
{
    int status;
    int error = 0;
    double t = t0;
    double h = p_X->dt;
    int i;
    double *y = p_X->proj;
    gsl_odeiv2_control_free(p_calc->control);
    p_calc->control = gsl_odeiv2_control_y_new(abs_tol, rel_tol);
    p_calc->p_par = p_par;
    for (i=0; i< (N_PAR_SV*N_CAC) ; i++) {
        y[i]=y0[i];
    }
    while (t < t_end) {
        reset_inc(p_X, p_data);
        status = gsl_odeiv2_evolve_apply(p_calc->evolve, p_calc->control, p_calc->step, &(p_calc->sys), &t, t_end, &h, y);
        if ( (status != GSL_SUCCESS) ) {
            char str[255];
            sprintf(str, "integration failure (status: %d has_failed: %d)", status, has_failed(y));
            print_err(str);
            error=1;
            break;
        }
    }
    return error;
}

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

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

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 { 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: status int

variable_types: error int

variable_types: t double

variable_types: h double

variable_types:
str
char [255]

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_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); }


integrate

decompiled_code:
__int64 __fastcall integrate(__int64 a1, __int64 a2, __int64 a3, double *a4, double *a5, _QWORD *a6, double a7, double a8, __int64 a9)
{
__int64 result; // rax

result = 1LL;
while ( *a4 > 9.999999999999999e-21 )
{
if ( *a5 <= 9.999999999999999e-21 )
break;
result = integrator(a1, a2, a3, a6, a9, a7, a8, *a4, *a5);
if ( !(_DWORD)result )
break;
*a4 = *a4 / 10.0;
*a5 = *a5 / 10.0;
}
return result;
}

original_code:
int integrate(struct s_X *p_X, double *y0, double t0, double t_end, struct s_par *p_par, double *abs_tol, double *rel_tol, struct s_calc *p_calc, struct s_data *p_data)
{
    int integration_error=1;
    while( integration_error && (*abs_tol>1e-20) && (*rel_tol>1e-20) ) {
        integration_error = integrator(p_X, y0, t0, t_end, p_par, *abs_tol, *rel_tol, p_calc, p_data);
        if(integration_error) {
            *abs_tol /= 10.0;
            *rel_tol /= 10.0;
        }
    }
    return integration_error;
}

canonical_original_code:
int integrate(struct s_X *p_X, double *y0, double t0, double t_end, struct s_par *p_par, double *abs_tol, double *rel_tol, struct s_calc *p_calc, struct s_data *p_data)
{
    int integration_error = 1;
    while( integration_error && (*abs_tol>1e-20) && (*rel_tol>1e-20) ) {
        integration_error = integrator(p_X, y0, t0, t_end, p_par, *abs_tol, *rel_tol, p_calc, p_data);
        if(integration_error) {
            *abs_tol /= 10.0;
            *rel_tol /= 10.0;
        }
    }
    return integration_error;
}

user_defined_types: 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); }

user_defined_types: struct gsl_interp_accel { unsigned long cache; unsigned long miss_count; unsigned long hit_count; }

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; }

user_defined_types: 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; }

user_defined_types: struct gsl_odeiv2_step_struct { struct gsl_odeiv2_step_type *type; unsigned long dimension; void *state; }

user_defined_types: 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; }

user_defined_types: 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 *); }

user_defined_types: 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); }


original_code:
void *worker_routine (void *params) {
    char str[255];
    int j, jrcv, n, np1, t0, t1;
    struct s_thread_params *p = (struct s_thread_params *) params;
    void *server_controller = zmq_socket (p->context, 2);
    snprintf(str, 255, "tcp://%s:%d", p->host, 5559);
    zmq_connect (server_controller, str);
    zmq_setsockopt (server_controller, 6, "", 0);
    void *server_receiver = zmq_socket (p->context, 7);
    snprintf(str, 255, "tcp://%s:%d", p->host, 5557);
    zmq_connect (server_receiver, str);
    void *server_sender = zmq_socket (p->context, 8);
    snprintf(str, 255, "tcp://%s:%d", p->host, 5558);
    zmq_connect (server_sender, str);
    struct s_data *p_data = p->p_data;
    struct s_par *p_par = build_par(p_data);
    int size_proj = N_PAR_SV*N_CAC + p_data->p_it_only_drift->nbtot + N_TS_INC_UNIQUE;
    struct s_X *p_X = build_X(size_proj, N_TS, p_data, p->dt);
    struct s_calc *p_calc = p->p_calc;
    double like = 0.0;
    plom_f_pred_t f_pred = get_f_pred(p_data->implementation, p_data->noises_off);
    zmq_pollitem_t items [] = {
        { server_receiver, 0, 1, 0 },
        { server_controller, 0, 1, 0 }
    };
    while (1) {
        zmq_poll (items, 2, -1);
        if (items [0].revents & 1) {
     zmq_recv(server_receiver, &n, sizeof (int), 0);
            np1 = n+1;
            t0 = p_data->times[n];
            t1 = p_data->times[np1];
     recv_par(p_par, p_data, server_receiver);
            for(j=0; j<J; j++) {
  zmq_recv(server_receiver, &jrcv, sizeof (int), 0);
                recv_X(p_X, p_data, server_receiver);
                reset_inc(p_X, p_data);
  f_pred(p_X, t0, t1, p_par, p_data, p_calc);
  proj2obs(p_X, p_data);
  if(p_data->data_ind[n]->n_nonan) {
      like = exp(get_log_likelihood(p_X, p_par, p_data, p_calc, n, t1));
  }
  zmq_send(server_sender, &jrcv, sizeof (int), 2);
  send_X(server_sender, p_X, p_data, 2);
  zmq_send(server_sender, &like, sizeof (double), 0);
            }
        }
        if (items [1].revents & 1) {
     char buf [256];
     zmq_recv(server_controller, buf, 256, 0);
            if(strcmp(buf, "KILL") == 0) {
                break;
            }
        }
    }
    zmq_close (server_receiver);
    zmq_close (server_sender);
    zmq_close (server_controller);
    clean_par(p_par);
    clean_X(p_X);
    clean_p_calc(p_calc, p_data);
    return ((void *)0);
}

canonical_original_code:
void *worker_routine(void *params) {
    char str[255];
    int j; int jrcv; int n; int np1; int t0; int t1;
    struct s_thread_params *p = (struct s_thread_params *) params;
    void *server_controller = zmq_socket (p->context, 2);
    snprintf(str, 255, "tcp://%s:%d", p->host, 5559);
    zmq_connect (server_controller, str);
    zmq_setsockopt (server_controller, 6, "", 0);
    void *server_receiver = zmq_socket (p->context, 7);
    snprintf(str, 255, "tcp://%s:%d", p->host, 5557);
    zmq_connect (server_receiver, str);
    void *server_sender = zmq_socket (p->context, 8);
    snprintf(str, 255, "tcp://%s:%d", p->host, 5558);
    zmq_connect (server_sender, str);
    struct s_data *p_data = p->p_data;
    struct s_par *p_par = build_par(p_data);
    int size_proj = N_PAR_SV*N_CAC + p_data->p_it_only_drift->nbtot + N_TS_INC_UNIQUE;
    struct s_X *p_X = build_X(size_proj, N_TS, p_data, p->dt);
    struct s_calc *p_calc = p->p_calc;
    double like = 0.0;
    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);
    struct zmq_pollitem_t items[] = {
        { server_receiver, 0, 1, 0 },
        { server_controller, 0, 1, 0 }
    };
    while (1) {
        zmq_poll (items, 2, -1);
        if (items [0].revents & 1) {
     zmq_recv(server_receiver, &n, sizeof (int), 0);
            np1 = n+1;
            t0 = p_data->times[n];
            t1 = p_data->times[np1];
     recv_par(p_par, p_data, server_receiver);
            for(j=0; j<J; j++) {
  zmq_recv(server_receiver, &jrcv, sizeof (int), 0);
                recv_X(p_X, p_data, server_receiver);
                reset_inc(p_X, p_data);
  f_pred(p_X, t0, t1, p_par, p_data, p_calc);
  proj2obs(p_X, p_data);
  if(p_data->data_ind[n]->n_nonan) {
      like = exp(get_log_likelihood(p_X, p_par, p_data, p_calc, n, t1));
  }
  zmq_send(server_sender, &jrcv, sizeof (int), 2);
  send_X(server_sender, p_X, p_data, 2);
  zmq_send(server_sender, &like, sizeof (double), 0);
            }
        }
        if (items [1].revents & 1) {
     char buf[256];
     zmq_recv(server_controller, buf, 256, 0);
            if(strcmp(buf, "KILL") == 0) {
                break;
            }
        }
    }
    zmq_close (server_receiver);
    zmq_close (server_sender);
    zmq_close (server_controller);
    clean_par(p_par);
    clean_X(p_X);
    clean_p_calc(p_calc, p_data);
    return ((void *)0);
}

variable_types:
params
void *

variable_types: j int

variable_types: jrcv int

variable_types: n int

variable_types: struct s_thread_params { int thread_id; int n_threads; 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; } *p_calc; double dt; char *host; void *context; } *

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: like double

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: 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_params { int thread_id; int n_threads; struct s_data *p_data; struct s_calc *p_calc; double dt; char *host; void *context; }

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_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; }


decompiled_code:
__int64 __fastcall json_decref(__int64 a1)
{
__int64 result; // rax

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 && !_InterlockedSub64((volatile signed __int64 *)(a1 + 8), 1uLL) )
result = json_delete();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 && !_InterlockedSub64((volatile signed __int64 *)(a1 + 8), 1uLL) )
result = json_delete();
}
return result;
}

original_code:
static inline
void json_decref(json_t *json)
{
    if(json && json->refcount != (size_t)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

canonical_original_code:
static inline void json_decref(struct json_t *json)
{
    if(json && json->refcount != (unsigned long)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

variable_types: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *

user_defined_types: struct json_t { enum json_type type; unsigned long refcount; }


decompiled_code:
__int64 __fastcall X2xk(__int64 a1, _QWORD *a2, __int64 a3)
{
int v4; // esi
__int64 v5; // rbp
__int64 v6; // r13
__int64 v7; // rsi
double v8; // xmm0_8
__int64 v9; // r13
double v10; // xmm0_8
int v11; // esi
__int64 result; // rax
int v13; // er13
__int64 v14; // rax
int v15; // esi

v4 = N_PAR_SV;
v5 = *(_QWORD *)(a3 + 104);
if ( N_PAR_SV * N_CAC > 0 )
{
v6 = 0LL;
do
{
v7 = v6;
v8 = *(double *)(*a2 + 8 * v6++);
gsl_vector_set(a1, v7, v8);
v4 = N_PAR_SV;
}
while ( N_PAR_SV * N_CAC > (int)v6 );
}
if ( N_TS > 0 )
{
v9 = 0LL;
while ( 1 )
{
v10 = *(double *)(a2[1] + 8 * v9);
v11 = v9++ + N_CAC * v4;
gsl_vector_set(a1, v11, v10);
if ( N_TS <= (int)v9 )
break;
v4 = N_PAR_SV;
}
}
result = *(unsigned int *)(v5 + 24);
if ( (int)result > 0 )
{
v13 = 0;
do
{
v14 = N_CAC * N_PAR_SV + v13;
v15 = v13 + N_TS + N_CAC * N_PAR_SV;
++v13;
result = gsl_vector_set(a1, v15, *(double *)(*a2 + 8 * v14));
}
while ( *(_DWORD *)(v5 + 24) > v13 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2, __int64 a3)
{
int v4; // esi
__int64 v5; // rbp
__int64 v6; // r13
__int64 v7; // rsi
double v8; // xmm0_8
__int64 v9; // r13
double v10; // xmm0_8
int v11; // esi
__int64 result; // rax
int v13; // er13
__int64 v14; // rax
int v15; // esi

v4 = N_PAR_SV;
v5 = *(_QWORD *)(a3 + 104);
if ( N_PAR_SV * N_CAC > 0 )
{
v6 = 0LL;
do
{
v7 = v6;
v8 = *(double *)(*a2 + 8 * v6++);
gsl_vector_set(a1, v7, v8);
v4 = N_PAR_SV;
}
while ( N_PAR_SV * N_CAC > (int)v6 );
}
if ( N_TS > 0 )
{
v9 = 0LL;
while ( 1 )
{
v10 = *(double *)(a2[1] + 8 * v9);
v11 = v9++ + N_CAC * v4;
gsl_vector_set(a1, v11, v10);
if ( N_TS <= (int)v9 )
break;
v4 = N_PAR_SV;
}
}
result = *(unsigned int *)(v5 + 24);
if ( (int)result > 0 )
{
v13 = 0;
do
{
v14 = N_CAC * N_PAR_SV + v13;
v15 = v13 + N_TS + N_CAC * N_PAR_SV;
++v13;
result = gsl_vector_set(a1, v15, *(double *)(*a2 + 8 * v14));
}
while ( *(_DWORD *)(v5 + 24) > v13 );
}
return result;
}

original_code:
void X2xk(gsl_vector *xk, struct s_X *p_X, struct s_data *p_data)
{
    struct s_iterator *p_it = p_data->p_it_only_drift;
    int i;
    for(i=0; i<N_PAR_SV*N_CAC; i++)
        gsl_vector_set(xk, i, p_X->proj[i]);
    for(i=0; i<N_TS; i++) {
        gsl_vector_set(xk, N_PAR_SV*N_CAC + i, p_X->obs[i]);
    }
    for(i=0; i<p_it->nbtot; i++) {
 gsl_vector_set(xk, N_PAR_SV*N_CAC + N_TS + i, p_X->proj[N_PAR_SV*N_CAC+i]);
    }
}

canonical_original_code:
void X2xk(struct gsl_vector *xk, struct s_X *p_X, struct s_data *p_data)
{
    struct s_iterator *p_it = p_data->p_it_only_drift;
    int i;
    for(i=0; i<N_PAR_SV*N_CAC; i++)
        gsl_vector_set(xk, i, p_X->proj[i]);
    for(i=0; i<N_TS; i++) {
        gsl_vector_set(xk, N_PAR_SV*N_CAC + i, p_X->obs[i]);
    }
    for(i=0; i<p_it->nbtot; i++) {
 gsl_vector_set(xk, N_PAR_SV*N_CAC + N_TS + i, p_X->proj[N_PAR_SV*N_CAC+i]);
    }
}

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_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: i int

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


original_code:
void xk2X(struct s_X *p_X, gsl_vector *xk, struct s_data *p_data, struct s_calc *p_calc, const double t)
{
    struct s_iterator *p_it = p_data->p_it_only_drift;
    int i, cac;
    double sumsv;
    for(i=0; i<N_PAR_SV*N_CAC; i++) {
 gsl_vector_set(xk, i, (gsl_vector_get(xk, i) > 0.0) ? gsl_vector_get(xk, i) : 0.0) ;
    }
    if(!POP_SIZE_EQ_SUM_SV){
 for(cac=0; cac<N_CAC; cac++){
     sumsv = 0.0;
     for(i=0; i<N_PAR_SV; i++) {
  sumsv += gsl_vector_get(xk, i*N_CAC +cac);
     }
     if( (gsl_spline_eval(p_calc->spline[0][cac],t,p_calc->acc[0][cac]) - sumsv) < 0 ){
  for(i=0; i<N_PAR_SV; i++) {
      gsl_vector_set(xk, i*N_CAC +cac, gsl_vector_get(xk, i*N_CAC +cac)/sumsv * gsl_spline_eval(p_calc->spline[0][cac],t,p_calc->acc[0][cac]));
  }
     }
 }
    }
    for(i=0; i<N_PAR_SV*N_CAC; i++) {
        p_X->proj[i] = (gsl_vector_get(xk, i) > 0.0) ? gsl_vector_get(xk, i) : 0.0 ;
 gsl_vector_set(xk, i, (gsl_vector_get(xk, i) > 0.0) ? gsl_vector_get(xk, i) : 0.0) ;
    }
    for(i=0; i<N_TS; i++) {
 p_X->obs[i] = gsl_vector_get(xk, N_PAR_SV*N_CAC + i);
    }
    for(i=0; i<p_it->nbtot; i++) {
 p_X->proj[N_PAR_SV*N_CAC + i] = gsl_vector_get(xk, N_PAR_SV*N_CAC + N_TS + i) ;
    }
}

canonical_original_code:
void xk2X(struct s_X *p_X, struct gsl_vector *xk, struct s_data *p_data, struct s_calc *p_calc, double t)
{
    struct s_iterator *p_it = p_data->p_it_only_drift;
    int i; int cac;
    double sumsv;
    for(i=0; i<N_PAR_SV*N_CAC; i++) {
 gsl_vector_set(xk, i, (gsl_vector_get(xk, i) > 0.0) ? gsl_vector_get(xk, i) : 0.0) ;
    }
    if(!POP_SIZE_EQ_SUM_SV){
 for(cac=0; cac<N_CAC; cac++){
     sumsv = 0.0;
     for(i=0; i<N_PAR_SV; i++) {
  sumsv += gsl_vector_get(xk, i*N_CAC +cac);
     }
     if( (gsl_spline_eval(p_calc->spline[0][cac],t,p_calc->acc[0][cac]) - sumsv) < 0 ){
  for(i=0; i<N_PAR_SV; i++) {
      gsl_vector_set(xk, i*N_CAC +cac, gsl_vector_get(xk, i*N_CAC +cac)/sumsv * gsl_spline_eval(p_calc->spline[0][cac],t,p_calc->acc[0][cac]));
  }
     }
 }
    }
    for(i=0; i<N_PAR_SV*N_CAC; i++) {
        p_X->proj[i] = (gsl_vector_get(xk, i) > 0.0) ? gsl_vector_get(xk, i) : 0.0 ;
 gsl_vector_set(xk, i, (gsl_vector_get(xk, i) > 0.0) ? gsl_vector_get(xk, i) : 0.0) ;
    }
    for(i=0; i<N_TS; i++) {
 p_X->obs[i] = gsl_vector_get(xk, N_PAR_SV*N_CAC + i);
    }
    for(i=0; i<p_it->nbtot; i++) {
 p_X->proj[N_PAR_SV*N_CAC + i] = gsl_vector_get(xk, N_PAR_SV*N_CAC + N_TS + i) ;
    }
}

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 *p_data; void *method_specific_thread_safe_data; void *method_specific_shared_data; } *

variable_types: t double

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

variable_types: cac int

variable_types: sumsv double

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

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: 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 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 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 gsl_odeiv2_control_struct { struct gsl_odeiv2_control_type *type; void *state; }


decompiled_code:
double __fastcall get_total_pop(__int64 a1)
{
double v1; // xmm1_8
int v2; // ebx
__int64 v3; // rsi

if ( N_CAC <= 0 )
return 0.0;
v1 = 0.0;
v2 = 0;
do
{
v3 = (unsigned int)v2++;
v1 = v1 + sum_SV(a1, v3);
}
while ( N_CAC > v2 );
return v1;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1)
{
double v1; // xmm1_8
int v2; // ebx
__int64 v3; // rsi

if ( N_CAC <= 0 )
return 0.0;
v1 = 0.0;
v2 = 0;
do
{
v3 = (unsigned int)v2++;
v1 = v1 + sum_SV(a1, v3);
}
while ( N_CAC > v2 );
return v1;
}

original_code:
double get_total_pop(double *X)
{
    int cac;
    double t_p = 0.0;
    for(cac=0;cac<N_CAC;cac++) {
        t_p += sum_SV(X, cac);
    }
    return t_p;
}

variable_types:
X
double *


original_code:
double log_transf_correc(gsl_vector *mean, gsl_matrix *var, struct s_router **routers)
{
    int i, k;
    double p_tmp, Lp;
    p_tmp=0.0, Lp=0.0;
    int offset = 0;
    for(i=0; i<(N_PAR_SV+N_PAR_PROC+N_PAR_OBS); i++) {
        for(k=0; k<routers[i]->n_gp; k++) {
            if(gsl_matrix_get(var, offset, offset) >0.0) {
                p_tmp = 1./((*(routers[i]->f_inv_derivative[k]))(gsl_vector_get(mean, offset), routers[i]->min[k], routers[i]->max[k]));
                if((__builtin_isinf_sign (p_tmp)==1) || (__builtin_isnan (p_tmp)==1)) {
                    p_tmp=LIKE_MIN;
                } else if(p_tmp <= LIKE_MIN) {
                    p_tmp = LIKE_MIN ;
                }
                Lp += log(p_tmp);
            }
        }
        offset++;
    }
    return(Lp);
}

canonical_original_code:
double log_transf_correc(struct gsl_vector *mean, struct gsl_matrix *var, struct s_router **routers)
{
    int i; int k;
    double p_tmp; double Lp;
    p_tmp=0.0, Lp=0.0;
    int offset = 0;
    for(i=0; i<(N_PAR_SV+N_PAR_PROC+N_PAR_OBS); i++) {
        for(k=0; k<routers[i]->n_gp; k++) {
            if(gsl_matrix_get(var, offset, offset) >0.0) {
                p_tmp = 1./((*(routers[i]->f_inv_derivative[k]))(gsl_vector_get(mean, offset), routers[i]->min[k], routers[i]->max[k]));
                if((__builtin_isinf_sign (p_tmp)==1) || (__builtin_isnan (p_tmp)==1)) {
                    p_tmp=LIKE_MIN;
                } else if(p_tmp <= LIKE_MIN) {
                    p_tmp = LIKE_MIN ;
                }
                Lp += log(p_tmp);
            }
        }
        offset++;
    }
    return(Lp);
}

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

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; } **

variable_types: k int

variable_types: Lp double

variable_types: offset int


decompiled_code:
__int64 __fastcall reset_inc_cov(unsigned __int64 *a1)
{
int v1; // ecx
__int64 result; // rax
__int64 v3; // r12
unsigned __int64 v4; // rbx
__int64 v5; // rsi

v1 = N_PAR_SV;
result = (unsigned int)N_TS_INC;
if ( N_TS_INC > 0 )
{
v3 = N_PAR_SV * N_CAC;
do
{
v4 = 0LL;
if ( *a1 )
{
do
{
gsl_matrix_set(a1, v3, v4, 0.0);
v5 = v4++;
gsl_matrix_set(a1, v5, v3, 0.0);
}
while ( *a1 > v4 );
v1 = N_PAR_SV;
}
result = (unsigned int)++v3;
}
while ( N_TS_INC + v1 * N_CAC > (int)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 *a1)
{
int v1; // ecx
__int64 result; // rax
__int64 v3; // r12
unsigned __int64 v4; // rbx
__int64 v5; // rsi

v1 = N_PAR_SV;
result = (unsigned int)N_TS_INC;
if ( N_TS_INC > 0 )
{
v3 = N_PAR_SV * N_CAC;
do
{
v4 = 0LL;
if ( *a1 )
{
do
{
gsl_matrix_set(a1, v3, v4, 0.0);
v5 = v4++;
gsl_matrix_set(a1, v5, v3, 0.0);
}
while ( *a1 > v4 );
v1 = N_PAR_SV;
}
result = (unsigned int)++v3;
}
while ( N_TS_INC + v1 * N_CAC > (int)v3 );
}
return result;
}

original_code:
void reset_inc_cov(gsl_matrix *Ct)
{
    int oi,oii;
    for (oi=N_PAR_SV*N_CAC; oi<N_PAR_SV*N_CAC+N_TS_INC; oi++) {
        for (oii=0; oii<Ct->size1; oii++) {
            gsl_matrix_set(Ct,oi,oii,0.0);
            gsl_matrix_set(Ct,oii,oi,0.0);
        }
    }
}

canonical_original_code:
void reset_inc_cov(struct gsl_matrix *Ct)
{
    int oi; int oii;
    for (oi=N_PAR_SV*N_CAC; oi<N_PAR_SV*N_CAC+N_TS_INC; oi++) {
        for (oii=0; oii<Ct->size1; oii++) {
            gsl_matrix_set(Ct,oi,oii,0.0);
            gsl_matrix_set(Ct,oii,oi,0.0);
        }
    }
}

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

variable_types: oi int

variable_types: oii int

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


decompiled_code:
__int64 __fastcall check_and_correct_Ct(unsigned __int64 *a1, _QWORD *a2)
{
unsigned __int64 v2; // rbp
__int64 v3; // r13
unsigned __int64 i; // rbx
double v5; // xmm0_8
unsigned __int64 v6; // rdx
__int64 v7; // rbx
unsigned int v8; // eax
__int64 result; // rax
__int64 v10; // r15
int v11; // ebp
double v12; // xmm0_8
__int64 v13; // r14
unsigned int v14; // eax
double v15; // xmm0_8
const char *v16; // rax
const char *v17; // rax
const char *v18; // rax
double v19; // [rsp+8h] [rbp-140h]
__int64 v20; // [rsp+8h] [rbp-140h]
char s[312]; // [rsp+10h] [rbp-138h] BYREF

v2 = 0LL;
v3 = a2[7];
gsl_matrix_memcpy(v3, a1);
if ( *a1 )
{
do
{
for ( i = 0LL; a1[1] > i; ++i )
{
v19 = gsl_matrix_get(v3, v2, i);
v5 = gsl_matrix_get(v3, i, v2);
v6 = i;
gsl_matrix_set(a1, v2, v6, (v5 + v19) * 0.5);
}
++v2;
}
while ( *a1 > v2 );
}
v7 = a2[10];
v20 = a2[11];
v8 = gsl_eigen_symmv(v3, v7, v20, a2[9]);
if ( v8 )
{
v17 = (const char *)gsl_strerror(v8);
sprintf(s, "error: %s\n", v17);
print_err(s);
}
gsl_matrix_set_zero(v3);
result = (unsigned int)N_KAL;
if ( N_KAL > 0 )
{
v10 = 0LL;
v11 = 0;
do
{
if ( gsl_vector_get(v7, v10) < 0.0 )
{
v11 = 1;
gsl_vector_set(v7, v10, 0.0);
}
v12 = gsl_vector_get(v7, v10);
result = gsl_matrix_set(v3, v10, v10, v12);
++v10;
}
while ( N_KAL > (int)v10 );
if ( v11 )
{
v13 = a2[8];
v14 = gsl_blas_dgemm(111LL, 112LL, v3, v20, v13, 1.0, 0.0);
v15 = *(double *)&LC3;
if ( v14 )
{
v18 = (const char *)gsl_strerror(v14);
sprintf(s, "error: %s\n", v18);
print_err(s);
v15 = *(double *)&LC3;
}
result = gsl_blas_dgemm(111LL, 111LL, v20, v13, a1, v15, 0.0);
if ( (_DWORD)result )
{
v16 = (const char *)gsl_strerror((unsigned int)result);
sprintf(s, "error: %s\n", v16);
result = print_err(s);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 *a1, _QWORD *a2)
{
unsigned __int64 v2; // rbp
__int64 v3; // r13
unsigned __int64 i; // rbx
double v5; // xmm0_8
unsigned __int64 v6; // rdx
__int64 v7; // rbx
unsigned int v8; // eax
__int64 result; // rax
__int64 v10; // r15
int v11; // ebp
double v12; // xmm0_8
__int64 v13; // r14
unsigned int v14; // eax
double v15; // xmm0_8
const char *v16; // rax
const char *v17; // rax
const char *v18; // rax
double v19; // [rsp+8h] [rbp-140h]
__int64 v20; // [rsp+8h] [rbp-140h]
char s[312]; // [rsp+10h] [rbp-138h] BYREF

v2 = 0LL;
v3 = a2[7];
gsl_matrix_memcpy(v3, a1);
if ( *a1 )
{
do
{
for ( i = 0LL; a1[1] > i; ++i )
{
v19 = gsl_matrix_get(v3, v2, i);
v5 = gsl_matrix_get(v3, i, v2);
v6 = i;
gsl_matrix_set(a1, v2, v6, (v5 + v19) * 0.5);
}
++v2;
}
while ( *a1 > v2 );
}
v7 = a2[10];
v20 = a2[11];
v8 = gsl_eigen_symmv(v3, v7, v20, a2[9]);
if ( v8 )
{
v17 = (const char *)gsl_strerror(v8);
sprintf(s, "error: %s\n", v17);
print_err(s);
}
gsl_matrix_set_zero(v3);
result = (unsigned int)N_KAL;
if ( N_KAL > 0 )
{
v10 = 0LL;
v11 = 0;
do
{
if ( gsl_vector_get(v7, v10) < 0.0 )
{
v11 = 1;
gsl_vector_set(v7, v10, 0.0);
}
v12 = gsl_vector_get(v7, v10);
result = gsl_matrix_set(v3, v10, v10, v12);
++v10;
}
while ( N_KAL > (int)v10 );
if ( v11 )
{
v13 = a2[8];
v14 = gsl_blas_dgemm(111LL, 112LL, v3, v20, v13, 1.0, 0.0);
v15 = *(double *)&LC3;
if ( v14 )
{
v18 = (const char *)gsl_strerror(v14);
sprintf(s, "error: %s\n", v18);
print_err(s);
v15 = *(double *)&LC3;
}
result = gsl_blas_dgemm(111LL, 111LL, v20, v13, a1, v15, 0.0);
if ( (_DWORD)result )
{
v16 = (const char *)gsl_strerror((unsigned int)result);
sprintf(s, "error: %s\n", v16);
result = print_err(s);
}
}
}
return result;
}

original_code:
void check_and_correct_Ct(gsl_matrix *Ct, struct s_kalman_update *p)
{
    char str[255];
    int i,j;
    int status;
    gsl_matrix *temp = p->M_symm_n_kal;
    gsl_matrix_memcpy(temp, Ct);
    for(i=0; i< Ct->size1; i++){
 for(j=0; j< Ct->size2; j++){
     gsl_matrix_set(Ct, i, j, ((gsl_matrix_get(temp, i, j) + gsl_matrix_get(temp, j, i)) / 2.0) );
 }
    }
    gsl_vector *eval = p->eval_nkal;
    gsl_matrix *evec = p->evec_nkal;
    gsl_eigen_symmv_workspace *w = p->w_eigen_vv_nkal;
    status = gsl_eigen_symmv(temp, eval, evec, w);
    if (status) {
 sprintf(str, "error: %s\n", gsl_strerror (status));
 print_err(str);
    }
    gsl_matrix_set_zero(temp);
    int change_basis = 0;
    for (i=0; i<N_KAL; i++) {
        if (gsl_vector_get(eval,i) < 0.0) {
            gsl_vector_set(eval, i, 0.0);
     change_basis = 1;
        }
        gsl_matrix_set(temp, i, i, gsl_vector_get(eval, i));
    }
    if(change_basis){
 gsl_matrix *temp2 = p->M_symm_n_kal2;
 status = gsl_blas_dgemm(CblasNoTrans, CblasTrans, 1.0, temp, evec, 0.0, temp2);
 if (status) {
     sprintf(str, "error: %s\n", gsl_strerror (status));
     print_err(str);
 }
 status = gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, evec, temp2, 0.0, Ct);
 if (status) {
     sprintf(str, "error: %s\n", gsl_strerror (status));
     print_err(str);
 }
    }
}

canonical_original_code:
void check_and_correct_Ct(struct gsl_matrix *Ct, struct s_kalman_update *p)
{
    char str[255];
    int i; int j;
    int status;
    struct gsl_matrix *temp = p->M_symm_n_kal;
    gsl_matrix_memcpy(temp, Ct);
    for(i=0; i< Ct->size1; i++){
 for(j=0; j< Ct->size2; j++){
     gsl_matrix_set(Ct, i, j, ((gsl_matrix_get(temp, i, j) + gsl_matrix_get(temp, j, i)) / 2.0) );
 }
    }
    struct gsl_vector *eval = p->eval_nkal;
    struct gsl_matrix *evec = p->evec_nkal;
    struct gsl_eigen_symmv_workspace *w = p->w_eigen_vv_nkal;
    status = gsl_eigen_symmv(temp, eval, evec, w);
    if (status) {
 sprintf(str, "error: %s\n", gsl_strerror (status));
 print_err(str);
    }
    gsl_matrix_set_zero(temp);
    int change_basis = 0;
    for (i=0; i<N_KAL; i++) {
        if (gsl_vector_get(eval,i) < 0.0) {
            gsl_vector_set(eval, i, 0.0);
     change_basis = 1;
        }
        gsl_matrix_set(temp, i, i, gsl_vector_get(eval, i));
    }
    if(change_basis){
 struct gsl_matrix *temp2 = p->M_symm_n_kal2;
 status = gsl_blas_dgemm(CblasNoTrans, CblasTrans, 1.0, temp, evec, 0.0, temp2);
 if (status) {
     sprintf(str, "error: %s\n", gsl_strerror (status));
     print_err(str);
 }
 status = gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, evec, temp2, 0.0, Ct);
 if (status) {
     sprintf(str, "error: %s\n", gsl_strerror (status));
     print_err(str);
 }
    }
}

variable_types: struct s_kalman_update { struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; } *xk; struct gsl_vector *kt; struct gsl_vector *ht; double sc_st; double sc_pred_error; double sc_rt; struct gsl_vector *v_n_kal; struct gsl_matrix *M_symm_n_kal; struct gsl_matrix *M_symm_n_kal2; struct gsl_eigen_symmv_workspace { unsigned long size; double *d; double *sd; double *gc; double *gs; } *w_eigen_vv_nkal; struct gsl_vector *eval_nkal; struct gsl_matrix *evec_nkal; } *

variable_types:
str
char [255]

variable_types: j int

variable_types: status int

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; } *

user_defined_types: struct s_kalman_update { struct gsl_vector *xk; struct gsl_vector *kt; struct gsl_vector *ht; double sc_st; double sc_pred_error; double sc_rt; struct gsl_vector *v_n_kal; struct gsl_matrix *M_symm_n_kal; struct gsl_matrix *M_symm_n_kal2; struct gsl_eigen_symmv_workspace *w_eigen_vv_nkal; struct gsl_vector *eval_nkal; struct gsl_matrix *evec_nkal; }


decompiled_code:
__int64 __fastcall ekf_gain_computation(__int64 a1, unsigned __int64 *a2, double a3, double a4)
{
__int64 v4; // r12
unsigned int v5; // eax
unsigned int v6; // eax
__int64 v7; // rcx
__int64 v8; // rdx
double v9; // xmm1_8
__int64 result; // rax
const char *v11; // rax
const char *v12; // rax
const char *v13; // rax
char v14[280]; // [rsp-110h] [rbp-118h] BYREF

*(double *)(a1 + 32) = a4 - a3;
v4 = *(_QWORD *)(a1 + 48);
check_and_correct_Ct(a2, (_QWORD *)a1);
v5 = gsl_blas_dgemv(111LL, a2, *(_QWORD *)(a1 + 16), v4, 1.0, 0.0);
if ( v5 )
{
v11 = (const char *)gsl_strerror(v5);
sprintf(v14, "error: %s\n", v11);
print_err(v14);
}
v6 = gsl_blas_ddot(*(_QWORD *)(a1 + 16), v4, a1 + 24);
if ( v6 )
{
v13 = (const char *)gsl_strerror(v6);
sprintf(v14, "error: %s\n", v13);
print_err(v14);
}
v7 = *(_QWORD *)(a1 + 8);
v8 = *(_QWORD *)(a1 + 16);
v9 = *(double *)(a1 + 24) + *(double *)(a1 + 40);
*(double *)(a1 + 24) = v9;
result = gsl_blas_dgemv(111LL, a2, v8, v7, 1.0 / v9, 0.0);
if ( (_DWORD)result )
{
v12 = (const char *)gsl_strerror((unsigned int)result);
sprintf(v14, "error: %s\n", v12);
result = print_err(v14);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int64 *a2, double a3, double a4)
{
__int64 v4; // r12
unsigned int v5; // eax
unsigned int v6; // eax
__int64 v7; // rcx
__int64 v8; // rdx
double v9; // xmm1_8
__int64 result; // rax
const char *v11; // rax
const char *v12; // rax
const char *v13; // rax
char v14[280]; // [rsp-110h] [rbp-118h] BYREF

*(double *)(a1 + 32) = a4 - a3;
v4 = *(_QWORD *)(a1 + 48);
func0(a2, (_QWORD *)a1);
v5 = gsl_blas_dgemv(111LL, a2, *(_QWORD *)(a1 + 16), v4, 1.0, 0.0);
if ( v5 )
{
v11 = (const char *)gsl_strerror(v5);
sprintf(v14, "error: %s\n", v11);
print_err(v14);
}
v6 = gsl_blas_ddot(*(_QWORD *)(a1 + 16), v4, a1 + 24);
if ( v6 )
{
v13 = (const char *)gsl_strerror(v6);
sprintf(v14, "error: %s\n", v13);
print_err(v14);
}
v7 = *(_QWORD *)(a1 + 8);
v8 = *(_QWORD *)(a1 + 16);
v9 = *(double *)(a1 + 24) + *(double *)(a1 + 40);
*(double *)(a1 + 24) = v9;
result = gsl_blas_dgemv(111LL, a2, v8, v7, 1.0 / v9, 0.0);
if ( (_DWORD)result )
{
v12 = (const char *)gsl_strerror((unsigned int)result);
sprintf(v14, "error: %s\n", v12);
result = print_err(v14);
}
return result;
}

original_code:
void ekf_gain_computation(struct s_kalman_update *p, double xk_t_ts, double data_t_ts, gsl_matrix *Ct)
{
    char str[255];
    int status;
    gsl_vector *workn = p->v_n_kal;
    p->sc_pred_error = data_t_ts - xk_t_ts;
    check_and_correct_Ct(Ct, p);
    status = gsl_blas_dgemv(CblasNoTrans, 1.0, Ct, p->ht, 0.0, workn);
    if (status) {
        sprintf(str, "error: %s\n", gsl_strerror (status));
        print_err(str);
    }
    status = gsl_blas_ddot(p->ht, workn, &(p->sc_st));
    if (status) {
        sprintf(str, "error: %s\n", gsl_strerror (status));
        print_err(str);
    }
    p->sc_st += p->sc_rt;
    double sc_stm1 = 1.0/ (p->sc_st);
    status = gsl_blas_dgemv(CblasNoTrans, sc_stm1, Ct, p->ht, 0.0, p->kt);
    if (status) {
        sprintf(str, "error: %s\n", gsl_strerror (status));
        print_err(str);
    }
}

canonical_original_code:
void ekf_gain_computation(struct s_kalman_update *p, double xk_t_ts, double data_t_ts, struct gsl_matrix *Ct)
{
    char str[255];
    int status;
    struct gsl_vector *workn = p->v_n_kal;
    p->sc_pred_error = data_t_ts - xk_t_ts;
    check_and_correct_Ct(Ct, p);
    status = gsl_blas_dgemv(CblasNoTrans, 1.0, Ct, p->ht, 0.0, workn);
    if (status) {
        sprintf(str, "error: %s\n", gsl_strerror (status));
        print_err(str);
    }
    status = gsl_blas_ddot(p->ht, workn, &(p->sc_st));
    if (status) {
        sprintf(str, "error: %s\n", gsl_strerror (status));
        print_err(str);
    }
    p->sc_st += p->sc_rt;
    double sc_stm1 = 1.0/ (p->sc_st);
    status = gsl_blas_dgemv(CblasNoTrans, sc_stm1, Ct, p->ht, 0.0, p->kt);
    if (status) {
        sprintf(str, "error: %s\n", gsl_strerror (status));
        print_err(str);
    }
}

variable_types: struct s_kalman_update { struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *xk; struct gsl_vector *kt; struct gsl_vector *ht; double sc_st; double sc_pred_error; double sc_rt; struct gsl_vector *v_n_kal; struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; } *M_symm_n_kal; struct gsl_matrix *M_symm_n_kal2; struct gsl_eigen_symmv_workspace { unsigned long size; double *d; double *sd; double *gc; double *gs; } *w_eigen_vv_nkal; struct gsl_vector *eval_nkal; struct gsl_matrix *evec_nkal; } *

variable_types:
Ct
struct gsl_matrix *