decompiled_code:
__int64 __fastcall run_propag(__int64 a1, __int64 a2, __int64 a3, __int64 *a4)
{
__int64 v4; // rcx
__int64 result; // rax

v4 = *a4;
if ( OPTION_PIPELINE )
result = run_SMC_zmq(a1, a2, a3, v4);
else
result = run_SMC_zmq_inproc(a1, a2, a3, v4);
return result;
}

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

v4 = *a4;
if ( OPTION_PIPELINE )
result = run_SMC_zmq(a1, a2, a3, v4);
else
result = run_SMC_zmq_inproc(a1, a2, a3, v4);
return result;
}

original_code:
void run_propag(struct s_X ***D_J_p_X, struct s_X ***D_J_p_X_tmp, struct s_par *p_par, struct s_hat ***D_p_hat_new,
                struct s_likelihood *p_like, struct s_data *p_data, struct s_calc **calc, plom_f_pred_t f_pred,
                void *sender, void *receiver, void *controller, const enum plom_print print_opt)
{
    if (OPTION_PIPELINE) {
 run_SMC_zmq(D_J_p_X, D_J_p_X_tmp, p_par, *D_p_hat_new, p_like, p_data, calc, f_pred, JCHUNK, print_opt, sender, receiver, controller);
    } else {
 run_SMC_zmq_inproc(D_J_p_X, D_J_p_X_tmp, p_par, *D_p_hat_new, p_like, p_data, calc, f_pred, 1, ((void *)0), ((void *)0), ((void *)0), print_opt, sender, receiver, controller);
    }
}

canonical_original_code:
void run_propag(struct s_X ***D_J_p_X, struct s_X ***D_J_p_X_tmp, struct s_par *p_par, struct s_hat ***D_p_hat_new, struct s_likelihood *p_like, struct s_data *p_data, struct s_calc **calc, void (*f_pred)(struct s_X *, double, double, struct s_par *, struct s_data *, struct s_calc *), void *sender, void *receiver, void *controller, enum plom_print print_opt)
{
    if (OPTION_PIPELINE) {
 run_SMC_zmq(D_J_p_X, D_J_p_X_tmp, p_par, *D_p_hat_new, p_like, p_data, calc, f_pred, JCHUNK, print_opt, sender, receiver, controller);
    } else {
 run_SMC_zmq_inproc(D_J_p_X, D_J_p_X_tmp, p_par, *D_p_hat_new, p_like, p_data, calc, f_pred, 1, ((void *)0), ((void *)0), ((void *)0), print_opt, sender, receiver, controller);
    }
}

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_hat { double *state; double **state_95; double *remainder; double **remainder_95; double *obs; double **obs_95; double *drift; double **drift_95; } ***

variable_types: struct s_likelihood { double ess_n; double Llike_best_n; double Llike_best; double *weights; unsigned int **select; int n_all_fail; double Llike_prev; double Llike_new; } *

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

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

variable_types: void (*)(struct s_X *, double, double, struct s_par *, struct s_data *, struct s_calc *)

variable_types:
sender
void *

variable_types:
receiver
void *

variable_types:
controller
void *

variable_types: enum plom_print { PLOM_PRINT_BEST=expr, PLOM_PRINT_X=expr, PLOM_PRINT_HAT=expr, PLOM_PRINT_PRED_RES=expr, PLOM_PRINT_X_SMOOTH=expr, PLOM_PRINT_ACC=expr, PLOM_PIPE=expr, PLOM_QUIET=expr }


repo: QCaudron/iterated-inference-pipeline

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 func0(__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; } *

return_type: void

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


decompiled_code:
void __fastcall clean_simplex(void *ptr)
{
clean_calc(*((_QWORD *)ptr + 1), *(_QWORD *)ptr);
clean_X(*((_QWORD *)ptr + 4));
clean_best(*((_QWORD *)ptr + 2));
clean_par(*((_QWORD *)ptr + 3));
clean_data(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
clean_calc(*((_QWORD *)ptr + 1), *(_QWORD *)ptr);
clean_X(*((_QWORD *)ptr + 4));
clean_best(*((_QWORD *)ptr + 2));
clean_par(*((_QWORD *)ptr + 3));
clean_data(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void clean_simplex(struct s_simplex *p_simplex)
{
    clean_calc(p_simplex->calc, p_simplex->p_data);
    clean_X(p_simplex->p_X);
    clean_best(p_simplex->p_best);
    clean_par(p_simplex->p_par);
    clean_data(p_simplex->p_data);
    do { free( p_simplex ); p_simplex = ((void *)0); }while(0);
}

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

user_defined_types: struct s_simplex { struct s_data *p_data; struct s_calc **calc; struct s_best *p_best; struct s_par *p_par; struct s_X *p_X; double smallest_log_like; }

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 s_best { int length; struct gsl_vector *mean; struct gsl_vector *proposed; struct gsl_matrix *var; int n_to_be_estimated; unsigned int *to_be_estimated; unsigned int *is_estimated; int n_follow; unsigned int *follower; unsigned int *follow; unsigned int *is_follower; double *mean_sampling; struct gsl_matrix *var_sampling; double **par_prior; double (**prior)(double x, double a, double b); }

user_defined_types: struct s_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_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; }

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

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

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

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

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

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


original_code:
void compute_drift(struct s_X *p_X, struct s_par *p_par, struct s_data *p_data, struct s_calc *p_calc)
{
    int i, k;
    double dt = p_X->dt;
    struct s_router **routers = p_data->routers;
    for(i=0; i<p_data->p_it_only_drift->length; i++) {
        struct s_drift *p_drift = p_data->drift[i];
        int ind_par_Xdrift_applied = p_drift->ind_par_Xdrift_applied;
        int ind_volatility_Xdrift = p_drift->ind_volatility_Xdrift;
        for(k=0; k< routers[ind_par_Xdrift_applied]->n_gp; k++) {
            p_X->proj[p_drift->offset +k] += p_par->natural[ ind_volatility_Xdrift ][k]*sqrt(dt)*gsl_ran_ugaussian(p_calc->randgsl);
        }
    }
}

canonical_original_code:
void compute_drift(struct s_X *p_X, struct s_par *p_par, struct s_data *p_data, struct s_calc *p_calc)
{
    int i; int k;
    double dt = p_X->dt;
    struct s_router **routers = p_data->routers;
    for(i=0; i<p_data->p_it_only_drift->length; i++) {
        struct s_drift *p_drift = p_data->drift[i];
        int ind_par_Xdrift_applied = p_drift->ind_par_Xdrift_applied;
        int ind_volatility_Xdrift = p_drift->ind_volatility_Xdrift;
        for(k=0; k< routers[ind_par_Xdrift_applied]->n_gp; k++) {
            p_X->proj[p_drift->offset +k] += p_par->natural[ ind_volatility_Xdrift ][k]*sqrt(dt)*gsl_ran_ugaussian(p_calc->randgsl);
        }
    }
}

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

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

variable_types: k int

variable_types: dt double

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: struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } *

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


decompiled_code:
void __fastcall clean2_gsl_vector_d(void *ptr, int a2)
{
void *v2; // r12
__int64 *v3; // rbx
char *v4; // rbp
__int64 v5; // rdi

v2 = ptr;
if ( a2 > 0 )
{
v3 = (__int64 *)ptr;
v4 = (char *)ptr + 8 * (unsigned int)(a2 - 1) + 8;
do
{
v5 = *v3++;
gsl_vector_free(v5);
}
while ( v3 != (__int64 *)v4 );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr, int a2)
{
void *v2; // r12
__int64 *v3; // rbx
char *v4; // rbp
__int64 v5; // rdi

v2 = ptr;
if ( a2 > 0 )
{
v3 = (__int64 *)ptr;
v4 = (char *)ptr + 8 * (unsigned int)(a2 - 1) + 8;
do
{
v5 = *v3++;
gsl_vector_free(v5);
}
while ( v3 != (__int64 *)v4 );
}
free(v2);
}

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

canonical_original_code:
void clean2_gsl_vector_d(struct gsl_vector **tab, int n)
{
  int i;
  for(i=0; i<n; i++) {
    gsl_vector_free(tab[i]);
  }
  do { free( tab ); tab = ((void *)0); }while(0);
}

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: n int


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

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


decompiled_code:
void __fastcall clean_mif(void *ptr)
{
_DWORD *v1; // rax
__int64 i; // rbx
_DWORD **v3; // rdx

v1 = (_DWORD *)**((_QWORD **)ptr + 1);
if ( (int)*v1 > 0 )
{
for ( i = 0LL; ; v1 = v3[i] )
{
++i;
gsl_vector_free(*((_QWORD *)v1 + 22));
v3 = (_DWORD **)*((_QWORD *)ptr + 1);
v1 = *v3;
if ( **v3 <= (int)i )
break;
}
}
gsl_matrix_free(*((_QWORD *)v1 + 23));
clean_calc(*((_QWORD *)ptr + 1), *(_QWORD *)ptr);
clean_best(*((_QWORD *)ptr + 2));
clean_J_p_par(*((_QWORD *)ptr + 5));
clean_J_p_X(*((_QWORD *)ptr + 3));
clean_J_p_X(*((_QWORD *)ptr + 4));
clean_likelihood(*((_QWORD *)ptr + 6));
clean_data(*(_QWORD *)ptr);
clean2_gsl_vector_d(*((_QWORD *)ptr + 7), (unsigned int)J);
clean2_gsl_vector_d(*((_QWORD *)ptr + 8), (unsigned int)J);
clean2d(*((_QWORD *)ptr + 9), (unsigned int)(N_DATA + 1));
clean2d(*((_QWORD *)ptr + 10), (unsigned int)(N_DATA + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_DWORD *v1; // rax
__int64 i; // rbx
_DWORD **v3; // rdx

v1 = (_DWORD *)**((_QWORD **)ptr + 1);
if ( (int)*v1 > 0 )
{
for ( i = 0LL; ; v1 = v3[i] )
{
++i;
gsl_vector_free(*((_QWORD *)v1 + 22));
v3 = (_DWORD **)*((_QWORD *)ptr + 1);
v1 = *v3;
if ( **v3 <= (int)i )
break;
}
}
gsl_matrix_free(*((_QWORD *)v1 + 23));
clean_calc(*((_QWORD *)ptr + 1), *(_QWORD *)ptr);
clean_best(*((_QWORD *)ptr + 2));
clean_J_p_par(*((_QWORD *)ptr + 5));
clean_J_p_X(*((_QWORD *)ptr + 3));
clean_J_p_X(*((_QWORD *)ptr + 4));
clean_likelihood(*((_QWORD *)ptr + 6));
clean_data(*(_QWORD *)ptr);
clean2_gsl_vector_d(*((_QWORD *)ptr + 7), (unsigned int)J);
clean2_gsl_vector_d(*((_QWORD *)ptr + 8), (unsigned int)J);
clean2d(*((_QWORD *)ptr + 9), (unsigned int)(N_DATA + 1));
clean2d(*((_QWORD *)ptr + 10), (unsigned int)(N_DATA + 1));
free(ptr);
}

original_code:
void clean_mif(struct s_mif *p)
{
    int nt;
    for(nt=0; nt< p->calc[0]->n_threads; nt++){
 gsl_vector_free(p->calc[nt]->method_specific_thread_safe_data);
    }
    gsl_matrix_free(p->calc[0]->method_specific_shared_data);
    clean_calc(p->calc, p->p_data);
    clean_best(p->p_best);
    clean_J_p_par(p->J_p_par);
    clean_J_p_X(p->J_p_X);
    clean_J_p_X(p->J_p_X_tmp);
    clean_likelihood(p->p_like);
    clean_data(p->p_data);
    clean2_gsl_vector_d(p->J_theta, J);
    clean2_gsl_vector_d(p->J_theta_tmp, J);
    clean2d(p->D_theta_bart, N_DATA+1);
    clean2d(p->D_theta_Vt, N_DATA+1);
    do { free( p ); p = ((void *)0); }while(0);
}

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

variable_types: nt int

user_defined_types: struct s_mif { struct s_data *p_data; struct s_calc **calc; struct s_best *p_best; struct s_X **J_p_X; struct s_X **J_p_X_tmp; struct s_par **J_p_par; struct s_likelihood *p_like; struct gsl_vector **J_theta; struct gsl_vector **J_theta_tmp; double **D_theta_bart; double **D_theta_Vt; }

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 s_best { int length; struct gsl_vector *mean; struct gsl_vector *proposed; struct gsl_matrix *var; int n_to_be_estimated; unsigned int *to_be_estimated; unsigned int *is_estimated; int n_follow; unsigned int *follower; unsigned int *follow; unsigned int *is_follower; double *mean_sampling; struct gsl_matrix *var_sampling; double **par_prior; double (**prior)(double x, double a, double b); }


original_code:
double f_simplex(const gsl_vector *x, void *params)
{
    unsigned int n, t0, t1;
    double fitness;
    struct s_simplex *p_params_simplex = (struct s_simplex *) params;
    struct s_data *p_data = p_params_simplex->p_data;
    struct s_best *p_best = p_params_simplex->p_best;
    struct s_calc **calc = p_params_simplex->calc;
    struct s_par *p_par = p_params_simplex->p_par;
    struct s_X *p_X = p_params_simplex->p_X;
    transfer_estimated(p_best, x, p_data);
    if(plom_check_IC_assign_theta_remainder(p_best->mean, p_data)){
        if(OPTION_LEAST_SQUARE) {
            fitness = 1e20*p_data->nb_obs;
        } else {
            fitness = p_params_simplex->smallest_log_like;
        }
    } else {
 back_transform_theta2par(p_par, p_best->mean, p_data->p_it_all, p_data);
 linearize_and_repeat(p_X, p_par, p_data, p_data->p_it_par_sv);
 prop2Xpop_size(p_X, p_data, calc[0]);
 theta_driftIC2Xdrift(p_X, p_best->mean, p_data);
 p_X->dt = p_X->dt0;
 fitness=0.0;
        for(n=0; n< p_data->nb_obs; n++) {
            t0=p_data->times[n];
            t1=p_data->times[n+1];
     reset_inc(p_X, p_data);
     f_prediction_ode(p_X, t0, t1, p_par, p_data, calc[0]);
     if(p_data->data_ind[n]->n_nonan){
  proj2obs(p_X, p_data);
  if (OPTION_LEAST_SQUARE) {
      fitness += get_sum_square(p_X, p_par, p_data, calc[0], n, t1);
  } else {
      fitness += get_log_likelihood(p_X, p_par, p_data, calc[0], n, t1);
  }
     }
        }
 if (OPTION_PRIOR) {
     double log_prob_prior_value;
     plom_err_code rc = log_prob_prior(&log_prob_prior_value, p_best, p_best->mean, p_best->var, p_data);
     if(rc != PLOM_SUCCESS){
     }
     fitness += log_prob_prior_value;
 }
    }
    if(!OPTION_LEAST_SQUARE) {
        fitness = -fitness;
    }
    return fitness;
}

canonical_original_code:
double f_simplex(struct gsl_vector *x, void *params)
{
    unsigned int n; unsigned int t0; unsigned int t1;
    double fitness;
    struct s_simplex *p_params_simplex = (struct s_simplex *) params;
    struct s_data *p_data = p_params_simplex->p_data;
    struct s_best *p_best = p_params_simplex->p_best;
    struct s_calc **calc = p_params_simplex->calc;
    struct s_par *p_par = p_params_simplex->p_par;
    struct s_X *p_X = p_params_simplex->p_X;
    transfer_estimated(p_best, x, p_data);
    if(plom_check_IC_assign_theta_remainder(p_best->mean, p_data)){
        if(OPTION_LEAST_SQUARE) {
            fitness = 1e20*p_data->nb_obs;
        } else {
            fitness = p_params_simplex->smallest_log_like;
        }
    } else {
 back_transform_theta2par(p_par, p_best->mean, p_data->p_it_all, p_data);
 linearize_and_repeat(p_X, p_par, p_data, p_data->p_it_par_sv);
 prop2Xpop_size(p_X, p_data, calc[0]);
 theta_driftIC2Xdrift(p_X, p_best->mean, p_data);
 p_X->dt = p_X->dt0;
 fitness=0.0;
        for(n=0; n< p_data->nb_obs; n++) {
            t0=p_data->times[n];
            t1=p_data->times[n+1];
     reset_inc(p_X, p_data);
     f_prediction_ode(p_X, t0, t1, p_par, p_data, calc[0]);
     if(p_data->data_ind[n]->n_nonan){
  proj2obs(p_X, p_data);
  if (OPTION_LEAST_SQUARE) {
      fitness += get_sum_square(p_X, p_par, p_data, calc[0], n, t1);
  } else {
      fitness += get_log_likelihood(p_X, p_par, p_data, calc[0], n, t1);
  }
     }
        }
 if (OPTION_PRIOR) {
     double log_prob_prior_value;
     enum plom_err_code rc = log_prob_prior(&log_prob_prior_value, p_best, p_best->mean, p_best->var, p_data);
     if(rc != PLOM_SUCCESS){
     }
     fitness += log_prob_prior_value;
 }
    }
    if(!OPTION_LEAST_SQUARE) {
        fitness = -fitness;
    }
    return fitness;
}

variable_types:
params
void *

variable_types:
n
unsigned int

variable_types: fitness double

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

variable_types: 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: enum plom_err_code { PLOM_SUCCESS=0, PLOM_ERR_LIKE=-1 }

return_type: double

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

user_defined_types: struct s_simplex { struct s_data *p_data; struct s_calc **calc; struct s_best *p_best; struct s_par *p_par; struct s_X *p_X; double smallest_log_like; }

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


decompiled_code:
double __fastcall get_var_remainder(__int64 a1, __int64 a2, int a3)
{
int v3; // er13
int v4; // er14
int v6; // er15
__int64 v7; // rbx
double v8; // xmm0_8
int v9; // eax
double i; // [rsp+0h] [rbp-40h]

if ( N_PAR_SV <= 0 )
return 0.0;
v3 = 0;
v4 = 1;
for ( i = gsl_matrix_get(a2, a3, a3) + 0.0; N_PAR_SV > v4; ++v4 )
{
v6 = 0;
v7 = a3 + v4 * N_CAC;
i = gsl_matrix_get(a2, v7, v7) + i;
do
{
v8 = gsl_matrix_get(a2, a3 + v6 * N_CAC, v7);
v9 = v6++;
i = v8 + i;
}
while ( v9 != v3 );
v3 = v4;
}
return i + 0.0;
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1, __int64 a2, int a3)
{
int v3; // er13
int v4; // er14
int v6; // er15
__int64 v7; // rbx
double v8; // xmm0_8
int v9; // eax
double i; // [rsp+0h] [rbp-40h]

if ( N_PAR_SV <= 0 )
return 0.0;
v3 = 0;
v4 = 1;
for ( i = gsl_matrix_get(a2, a3, a3) + 0.0; N_PAR_SV > v4; ++v4 )
{
v6 = 0;
v7 = a3 + v4 * N_CAC;
i = gsl_matrix_get(a2, v7, v7) + i;
do
{
v8 = gsl_matrix_get(a2, a3 + v6 * N_CAC, v7);
v9 = v6++;
i = v8 + i;
}
while ( v9 != v3 );
v3 = v4;
}
return i + 0.0;
}

original_code:
double get_var_remainder(struct s_kalman_update *p, gsl_matrix *Ct, int cac)
{
    int i, j, icac, jcac;
    double sum_V = 0.0;
    double sum_C = 0.0;
    for(j=0; j< N_PAR_SV; j++) {
 jcac = j*N_CAC + cac;
 sum_V += gsl_matrix_get(Ct, jcac, jcac);
 for(i=0; i< j; i++) {
     icac = i*N_CAC + cac;
     sum_V += gsl_matrix_get(Ct, icac, jcac);
 }
    }
    return sum_V + 2.0* sum_C;
}

canonical_original_code:
double get_var_remainder(struct s_kalman_update *p, struct gsl_matrix *Ct, int cac)
{
    int i; int j; int icac; int jcac;
    double sum_V = 0.0;
    double sum_C = 0.0;
    for(j=0; j< N_PAR_SV; j++) {
 jcac = j*N_CAC + cac;
 sum_V += gsl_matrix_get(Ct, jcac, jcac);
 for(i=0; i< j; i++) {
     icac = i*N_CAC + cac;
     sum_V += gsl_matrix_get(Ct, icac, jcac);
 }
    }
    return sum_V + 2.0* sum_C;
}

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 *

variable_types: cac int

variable_types: j int

variable_types: icac int

variable_types: jcac int

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


repo: QMonkey/ACM-ICPC

decompiled_code:
void __fastcall bitset_resize(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
void *v3; // rax
void *v4; // r14
void *v5; // r13

v2 = *(_DWORD *)(a1 + 8);
if ( v2 < a2 )
{
v3 = malloc(a2);
v4 = *(void **)a1;
v5 = v3;
memcpy(v3, *(const void **)a1, v2);
free(v4);
*(_QWORD *)a1 = v5;
*(_DWORD *)(a1 + 8) = a2;
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
void *v3; // rax
void *v4; // r14
void *v5; // r13

v2 = *(_DWORD *)(a1 + 8);
if ( v2 < a2 )
{
v3 = malloc(a2);
v4 = *(void **)a1;
v5 = v3;
memcpy(v3, *(const void **)a1, v2);
free(v4);
*(_QWORD *)a1 = v5;
*(_DWORD *)(a1 + 8) = a2;
}
}

original_code:
void bitset_resize(bitset_t *bset, uint32_t size)
{
 if(bset->size < size)
 {
  char *tmp = (char*)malloc(sizeof(char) * size);
  memcpy(tmp, bset->data, bset->size);
  free(bset->data);
  bset->data = tmp;
  bset->size = size;
 }
}

canonical_original_code:
void bitset_resize(struct bitset_s *bset, unsigned int size)
{
 if(bset->size < size)
 {
  char *tmp = (char*)malloc(sizeof(char) * size);
  memcpy(tmp, bset->data, bset->size);
  free(bset->data);
  bset->data = tmp;
  bset->size = size;
 }
}

variable_types: struct bitset_s { char *data; unsigned int size; } *

variable_types:
size
unsigned int

variable_types:
tmp
char *


decompiled_code:
__int64 __fastcall bitset_isset(_QWORD *a1, unsigned int a2)
{
return (unsigned __int8)(*(_BYTE *)(*a1 + (a2 >> 3)) & (1 << (a2 & 7)));
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, unsigned int a2)
{
return (unsigned __int8)(*(_BYTE *)(*a1 + (a2 >> 3)) & (1 << (a2 & 7)));
}

original_code:
int bitset_isset(bitset_t *bset, uint32_t bidx)
{
 uint32_t idx = bidx >> 3;
 uint32_t offset = bidx & 7;
 uint8_t mask = 1 << offset;
 mask &= bset->data[idx];
 return mask;
}

canonical_original_code:
int bitset_isset(struct bitset_s *bset, unsigned int bidx)
{
 unsigned int idx = bidx >> 3;
 unsigned int offset = bidx & 7;
 unsigned char mask = 1 << offset;
 mask &= bset->data[idx];
 return mask;
}

variable_types:
bidx
unsigned int

variable_types:
idx
unsigned int

variable_types:
offset
unsigned int

variable_types:
mask
unsigned char

return_type: int

user_defined_types: struct bitset_s { char *data; unsigned int size; }


decompiled_code:
void __fastcall bitset_destroy(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void bitset_destroy(bitset_t *bset)
{
 if(bset != ((void *)0))
 {
  free(bset->data);
  free(bset);
 }
}

canonical_original_code:
void bitset_destroy(struct bitset_s *bset)
{
 if(bset != ((void *)0))
 {
  free(bset->data);
  free(bset);
 }
}


most

decompiled_code:
__int64 __fastcall most(unsigned int *a1, unsigned int *a2, int (__fastcall *a3)(_QWORD, _QWORD))
{
unsigned int *v3; // rbx
unsigned int i; // er12

v3 = a1 + 1;
for ( i = *a1; a2 != v3; ++v3 )
{
if ( a3(*v3, i) > 0 )
i = *v3;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1, unsigned int *a2, int (__fastcall *a3)(_QWORD, _QWORD))
{
unsigned int *v3; // rbx
unsigned int i; // er12

v3 = a1 + 1;
for ( i = *a1; a2 != v3; ++v3 )
{
if ( a3(*v3, i) > 0 )
i = *v3;
}
return i;
}

original_code:
static int32_t most(int32_t *begin,int32_t *end,int (*comparator)(int32_t,int32_t))
{
 int32_t result = *begin++;
 while(begin != end)
 {
  if(comparator(*begin,result) > 0)
  {
   result = *begin;
  }
  ++begin;
 }
 return result;
}

canonical_original_code:
static int most(int *begin, int *end, int (*comparator)(int, int))
{
 int result = *begin++;
 while(begin != end)
 {
  if(comparator(*begin,result) > 0)
  {
   result = *begin;
  }
  ++begin;
 }
 return result;
}

variable_types:
begin
int *

variable_types:
end
int *

variable_types:
comparator
int (*)(int, int)

variable_types: result int


greater

decompiled_code:
__int64 __fastcall greater(int a1, int a2)
{
__int64 result; // rax

result = (unsigned int)-(a1 < a2);
if ( a1 > a2 )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
__int64 result; // rax

result = (unsigned int)-(a1 < a2);
if ( a1 > a2 )
result = 1LL;
return result;
}

original_code:
static int greater(int32_t first,int32_t second)
{
 return first > second ? 1 : (first < second ? -1 : 0);
}

canonical_original_code:
static int greater(int first, int second)
{
 return first > second ? 1 : (first < second ? -1 : 0);
}

variable_types: first int

variable_types: second int


less

decompiled_code:
__int64 __fastcall less(int a1, int a2)
{
__int64 result; // rax

result = (unsigned int)-(a1 > a2);
if ( a1 < a2 )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
__int64 result; // rax

result = (unsigned int)-(a1 > a2);
if ( a1 < a2 )
result = 1LL;
return result;
}

original_code:
static int less(int32_t first,int32_t second)
{
 return first < second ? 1 : (first > second ? -1 : 0);
}

canonical_original_code:
static int less(int first, int second)
{
 return first < second ? 1 : (first > second ? -1 : 0);
}


decompiled_code:
__int64 __fastcall closest_point(unsigned int *a1, unsigned int *a2)
{
__int64 result; // rax
unsigned int *v3; // r13
int v4; // ebx
unsigned int v5; // ebx
unsigned int v6; // er12

result = 0xFFFFFFFFLL;
if ( (char *)a2 - (char *)a1 > 4 )
{
v3 = (unsigned int *)select_kth(a1, a2, (unsigned int)(((char *)a2 - (char *)a1) >> 3) + 1, less);
v4 = most(v3, a2, (int (__fastcall *)(_QWORD, _QWORD))less);
v5 = v4 - most(a1, v3, (int (__fastcall *)(_QWORD, _QWORD))greater);
v6 = closest_point(a1, v3);
result = closest_point(v3, a2);
if ( v5 < v6 )
{
if ( v5 <= (unsigned int)result )
result = v5;
}
else if ( v6 <= (unsigned int)result )
{
result = v6;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1, unsigned int *a2)
{
__int64 result; // rax
unsigned int *v3; // r13
int v4; // ebx
unsigned int v5; // ebx
unsigned int v6; // er12

result = 0xFFFFFFFFLL;
if ( (char *)a2 - (char *)a1 > 4 )
{
v3 = (unsigned int *)func11(a1, a2, (unsigned int)(((char *)a2 - (char *)a1) >> 3) + 1, less);
v4 = func7(v3, a2, (int (__fastcall *)(_QWORD, _QWORD))less);
v5 = v4 - func7(a1, v3, (int (__fastcall *)(_QWORD, _QWORD))greater);
v6 = func10(a1, v3);
result = func10(v3, a2);
if ( v5 < v6 )
{
if ( v5 <= (unsigned int)result )
result = v5;
}
else if ( v6 <= (unsigned int)result )
{
result = v6;
}
}
return result;
}

original_code:
uint32_t closest_point(int32_t *begin,int32_t *end)
{
 if(end - begin < 2)
 {
  return (4294967295U);
 }
 int32_t *middle = begin + ((end-begin) >> 1);
 int32_t *kth = select_kth(begin,end,middle - begin + 1,less);
 uint32_t middle_min = most(kth,end,less) - most(begin,kth,greater);
 uint32_t left_min = closest_point(begin,kth);
 uint32_t right_min = closest_point(kth,end);
 return middle_min < left_min ?
  (middle_min < right_min ? middle_min : right_min) :
  (left_min < right_min ? left_min : right_min);
}

canonical_original_code:
unsigned int closest_point(int *begin, int *end)
{
 if(end - begin < 2)
 {
  return (4294967295U);
 }
 int *middle = begin + ((end-begin) >> 1);
 int *kth = select_kth(begin,end,middle - begin + 1,less);
 unsigned int middle_min = most(kth,end,less) - most(begin,kth,greater);
 unsigned int left_min = closest_point(begin,kth);
 unsigned int right_min = closest_point(kth,end);
 return middle_min < left_min ?
  (middle_min < right_min ? middle_min : right_min) :
  (left_min < right_min ? left_min : right_min);
}

variable_types:
middle
int *

variable_types:
kth
int *

return_type: unsigned int


original_code:
int32_t* select_kth(int32_t *begin,int32_t *end,int32_t kth,int (*comparator)(int32_t,int32_t))
{
 int32_t *pivot = partition(begin,end,comparator);
 int32_t nth = pivot - begin + 1;
 int32_t *result = ((void *)0);
 if(nth == kth)
 {
  result = pivot;
 }
 else if(nth > kth)
 {
  result = select_kth(begin,pivot,kth,comparator);
 }
 else
 {
  result = select_kth(pivot + 1,end,kth - nth,comparator);
 }
 return result;
}

canonical_original_code:
int *select_kth(int *begin, int *end, int kth, int (*comparator)(int, int))
{
 int *pivot = partition(begin,end,comparator);
 int nth = pivot - begin + 1;
 int *result = ((void *)0);
 if(nth == kth)
 {
  result = pivot;
 }
 else if(nth > kth)
 {
  result = select_kth(begin,pivot,kth,comparator);
 }
 else
 {
  result = select_kth(pivot + 1,end,kth - nth,comparator);
 }
 return result;
}

variable_types: kth int

variable_types:
pivot
int *

variable_types: nth int

variable_types:
result
int *

return_type: int *


partition

decompiled_code:
unsigned int *__fastcall partition(unsigned int *a1, __int64 a2, int (__fastcall *a3)(_QWORD, _QWORD))
{
unsigned int *v3; // r12
unsigned int v4; // er13
unsigned int *v5; // r14
unsigned int *v7; // rbx
unsigned int *v8; // rax

v3 = (unsigned int *)(a2 - 4);
v4 = *a1;
if ( a1 != (unsigned int *)(a2 - 4) )
{
v5 = a1;
v7 = (unsigned int *)(a2 - 4);
do
{
if ( a3(*v7, v4) < 0 )
{
v8 = v7 - 1;
}
else
{
v3 = v5 + 1;
*v5 = *v7;
if ( v7 == v5 + 1 )
goto LABEL_12;
while ( a3(*v3, v4) > 0 )
{
if ( v7 == ++v3 )
goto LABEL_12;
}
if ( v7 == v3 )
goto LABEL_12;
v8 = v7 - 1;
v5 = v3;
*v7 = *v3;
}
v7 = v8;
}
while ( v8 != v5 );
v3 = v8;
}
LABEL_12:
*v3 = v4;
return v3;
}

canonical_decompiled_code:
unsigned int *__fastcall func12(unsigned int *a1, __int64 a2, int (__fastcall *a3)(_QWORD, _QWORD))
{
unsigned int *v3; // r12
unsigned int v4; // er13
unsigned int *v5; // r14
unsigned int *v7; // rbx
unsigned int *v8; // rax

v3 = (unsigned int *)(a2 - 4);
v4 = *a1;
if ( a1 != (unsigned int *)(a2 - 4) )
{
v5 = a1;
v7 = (unsigned int *)(a2 - 4);
do
{
if ( a3(*v7, v4) < 0 )
{
v8 = v7 - 1;
}
else
{
v3 = v5 + 1;
*v5 = *v7;
if ( v7 == v5 + 1 )
goto LABEL_12;
while ( a3(*v3, v4) > 0 )
{
if ( v7 == ++v3 )
goto LABEL_12;
}
if ( v7 == v3 )
goto LABEL_12;
v8 = v7 - 1;
v5 = v3;
*v7 = *v3;
}
v7 = v8;
}
while ( v8 != v5 );
v3 = v8;
}
LABEL_12:
*v3 = v4;
return v3;
}

original_code:
int32_t* partition(int32_t *begin,int32_t *end,int (*comparator)(int32_t,int32_t))
{
 int32_t key = *begin;
 --end;
 while(1)
 {
  while(begin != end && comparator(*end,key) < 0)
  {
   --end;
  }
  if(begin == end)
  {
   break;
  }
  *begin++ = *end;
  while(begin != end && comparator(*begin,key) > 0)
  {
   ++begin;
  }
  if(begin == end)
  {
   break;
  }
  *end-- = *begin;
 }
 *begin = key;
 return begin;
}

canonical_original_code:
int *partition(int *begin, int *end, int (*comparator)(int, int))
{
 int key = *begin;
 --end;
 while(1)
 {
  while(begin != end && comparator(*end,key) < 0)
  {
   --end;
  }
  if(begin == end)
  {
   break;
  }
  *begin++ = *end;
  while(begin != end && comparator(*begin,key) > 0)
  {
   ++begin;
  }
  if(begin == end)
  {
   break;
  }
  *end-- = *begin;
 }
 *begin = key;
 return begin;
}

variable_types: key int


adjust

decompiled_code:
void __fastcall adjust(__int64 a1, __int64 a2, int *a3, int *a4)
{
int *v5; // rbx
int v6; // er12

if ( a4 != a3 )
{
v5 = a3;
do
{
while ( 1 )
{
v6 = *v5;
if ( v6 < (int)heap_top(a1, a2) )
break;
if ( ++v5 == a4 )
return;
}
++v5;
heap_pop(a1, a2);
heap_push(a1, a2 - 4, (unsigned int)*(v5 - 1));
}
while ( v5 != a4 );
}
}

original_code:
void adjust(int32_t *begin,int32_t *heap_end,int32_t *current,int32_t *end)
{
 if(current != end)
 {
  if(*current < heap_top(begin,heap_end))
  {
   heap_pop(begin,heap_end);
   heap_push(begin,heap_end-1,*current);
  }
  adjust(begin,heap_end,current + 1,end);
 }
}

canonical_original_code:
void adjust(int *begin, int *heap_end, int *current, int *end)
{
 if(current != end)
 {
  if(*current < heap_top(begin,heap_end))
  {
   heap_pop(begin,heap_end);
   heap_push(begin,heap_end-1,*current);
  }
  adjust(begin,heap_end,current + 1,end);
 }
}

variable_types:
current
int *


decompiled_code:
__int64 __fastcall select_kth_heap(__int64 a1, int *a2, unsigned int a3)
{
int *v3; // r12

v3 = (int *)(a1 + 4LL * a3);
build_heap(a1, v3);
adjust(a1, (__int64)v3, v3, a2);
return heap_top(a1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int *a2, unsigned int a3)
{
int *v3; // r12

v3 = (int *)(a1 + 4LL * a3);
func13(a1, v3);
func7(a1, (__int64)v3, v3, a2);
return func14(a1, v3);
}

original_code:
int32_t select_kth_heap(int32_t *begin,int32_t *end,uint32_t kth)
{
 int32_t *heap_end = begin + kth;
 build_heap(begin,heap_end);
 adjust(begin,heap_end,heap_end,end);
 return heap_top(begin,heap_end);
}

canonical_original_code:
int select_kth_heap(int *begin, int *end, unsigned int kth)
{
 int *heap_end = begin + kth;
 build_heap(begin,heap_end);
 adjust(begin,heap_end,heap_end,end);
 return heap_top(begin,heap_end);
}

variable_types:
kth
unsigned int


heapify

decompiled_code:
unsigned __int64 __fastcall heapify(__int64 a1, unsigned __int64 a2, signed int *a3)
{
signed int *v6; // rcx
signed int *v7; // rcx
__int64 v8; // rcx
unsigned __int64 result; // rax

while ( 1 )
{
v8 = 8 * (((__int64)a3 - a1) >> 2) + 8;
result = a1 + v8 - 4;
v6 = (signed int *)(a1 + v8);
if ( result >= a2 || *a3 >= *(_DWORD *)result )
break;
if ( (unsigned __int64)v6 >= a2 || *(_DWORD *)result >= *v6 )
v6 = (signed int *)result;
LABEL_5:
if ( v6 == a3 )
return result;
swap(v6, a3);
a3 = v7;
}
if ( (unsigned __int64)v6 < a2 )
{
result = (unsigned int)*a3;
if ( *v6 > (int)result )
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(__int64 a1, unsigned __int64 a2, signed int *a3)
{
signed int *v6; // rcx
signed int *v7; // rcx
__int64 v8; // rcx
unsigned __int64 result; // rax

while ( 1 )
{
v8 = 8 * (((__int64)a3 - a1) >> 2) + 8;
result = a1 + v8 - 4;
v6 = (signed int *)(a1 + v8);
if ( result >= a2 || *a3 >= *(_DWORD *)result )
break;
if ( (unsigned __int64)v6 >= a2 || *(_DWORD *)result >= *v6 )
v6 = (signed int *)result;
LABEL_5:
if ( v6 == a3 )
return result;
func9(v6, a3);
a3 = v7;
}
if ( (unsigned __int64)v6 < a2 )
{
result = (unsigned int)*a3;
if ( *v6 > (int)result )
goto LABEL_5;
}
return result;
}

original_code:
void heapify(int32_t *begin,int32_t *end,int32_t *current)
{
 int32_t *lchild = (((((current)-(begin) + 1) << 1) - 1) + (begin));
 int32_t *rchild = ((((((current)-(begin) + 1) << 1) - 1) + (begin)) + 1);
 int32_t *ptr = current;
 if(lchild < end && *ptr < *lchild)
 {
  ptr = lchild;
 }
 if(rchild < end && *ptr < *rchild)
 {
  ptr = rchild;
 }
 if(ptr != current)
 {
  swap(ptr,current);
  heapify(begin,end,ptr);
 }
}

canonical_original_code:
void heapify(int *begin, int *end, int *current)
{
 int *lchild = (((((current)-(begin) + 1) << 1) - 1) + (begin));
 int *rchild = ((((((current)-(begin) + 1) << 1) - 1) + (begin)) + 1);
 int *ptr = current;
 if(lchild < end && *ptr < *lchild)
 {
  ptr = lchild;
 }
 if(rchild < end && *ptr < *rchild)
 {
  ptr = rchild;
 }
 if(ptr != current)
 {
  swap(ptr,current);
  heapify(begin,end,ptr);
 }
}

variable_types:
lchild
int *

variable_types:
rchild
int *

variable_types:
ptr
int *


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

for ( ; (unsigned __int64)a3 >= a1; result = heapify(a1, a2, a3) )
;
return result;
}

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

for ( ; (unsigned __int64)a3 >= a1; result = func11(a1, a2, a3) )
;
return result;
}

original_code:
void build_heap3(int32_t *begin,int32_t *end,int32_t *current)
{
 if(begin <= current)
 {
  heapify(begin,end,current);
  build_heap3(begin,end,current - 1);
 }
}

canonical_original_code:
void build_heap3(int *begin, int *end, int *current)
{
 if(begin <= current)
 {
  heapify(begin,end,current);
  build_heap3(begin,end,current - 1);
 }
}

variable_types:
begin
int *

variable_types:
end
int *


decompiled_code:
unsigned __int64 __fastcall build_heap(unsigned __int64 a1, unsigned __int64 a2)
{
return build_heap3(a1, a2, (signed int *)(a1 + ((2 * ((__int64)(a2 - 4 - a1) >> 2) + 2) & 0xFFFFFFFFFFFFFFFCLL) - 4));
}

canonical_decompiled_code:
unsigned __int64 __fastcall func13(unsigned __int64 a1, unsigned __int64 a2)
{
return func12(a1, a2, (signed int *)(a1 + ((2 * ((__int64)(a2 - 4 - a1) >> 2) + 2) & 0xFFFFFFFFFFFFFFFCLL) - 4));
}

original_code:
void build_heap(int32_t *begin,int32_t *end)
{
 build_heap3(begin,end,(((((end-1)-(begin) + 1) >> 1) - 1) + (begin)));
}

canonical_original_code:
void build_heap(int *begin, int *end)
{
 build_heap3(begin,end,(((((end-1)-(begin) + 1) >> 1) - 1) + (begin)));
}


decompiled_code:
__int64 __fastcall heap_top(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int *a1)
{
return *a1;
}

original_code:
int32_t heap_top(int32_t *begin,int32_t *end)
{
 return *begin;
}

canonical_original_code:
int heap_top(int *begin, int *end)
{
 return *begin;
}


decompiled_code:
unsigned __int64 __fastcall heap_pop(signed int *a1, __int64 a2)
{
*a1 = *(_DWORD *)(a2 - 4);
return heapify((__int64)a1, a2 - 4, a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func15(signed int *a1, __int64 a2)
{
*a1 = *(_DWORD *)(a2 - 4);
return func11((__int64)a1, a2 - 4, a1);
}

original_code:
void heap_pop(int32_t *begin,int32_t *end)
{
 *begin = *--end;
 heapify(begin,end,begin);
}

canonical_original_code:
void heap_pop(int *begin, int *end)
{
 *begin = *--end;
 heapify(begin,end,begin);
}


decompiled_code:
__int64 __fastcall heap_push(_DWORD *a1, _DWORD *a2, int a3)
{
*a2 = a3;
return backtrack_constprop_0(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func16(_DWORD *a1, _DWORD *a2, int a3)
{
*a2 = a3;
return func10(a1, a2);
}

original_code:
void heap_push(int32_t *begin,int32_t *end,int32_t value)
{
 *end++ = value;
 backtrack(begin,end,end - 1);
}

canonical_original_code:
void heap_push(int *begin, int *end, int value)
{
 *end++ = value;
 backtrack(begin,end,end - 1);
}

variable_types: value int


swap

decompiled_code:
__int64 __fastcall swap(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void swap(int32_t *first,int32_t *second)
{
 int32_t temp = *first;
 *first = *second;
 *second = temp;
}

canonical_original_code:
void swap(int *first, int *second)
{
 int temp = *first;
 *first = *second;
 *second = temp;
}

variable_types:
first
int *

variable_types:
second
int *

variable_types: temp int


hanoi

decompiled_code:
void __fastcall hanoi(int a1, const char *a2, const char *a3, const char *a4)
{
int v7; // ebx
const char *v8; // rax

if ( a1 )
{
v7 = a1;
while ( 1 )
{
hanoi((unsigned int)--v7, a2, a4, a3);
fprintf(stdout, "(%s,%s)\n", a2, a4);
v8 = a3;
a3 = a2;
if ( !v7 )
break;
a2 = v8;
}
}
}

canonical_decompiled_code:
void __fastcall func7(int a1, const char *a2, const char *a3, const char *a4)
{
int v7; // ebx
const char *v8; // rax

if ( a1 )
{
v7 = a1;
while ( 1 )
{
func7((unsigned int)--v7, a2, a4, a3);
fprintf(stdout, "(%s,%s)\n", a2, a4);
v8 = a3;
a3 = a2;
if ( !v7 )
break;
a2 = v8;
}
}
}

original_code:
void hanoi(uint32_t level,char *src,char *auxiliary,char *dest)
{
 if(level > 0)
 {
  hanoi(level-1,src,dest,auxiliary);
  fprintf(stdout,"(%s,%s)\n",src,dest);
  hanoi(level-1,auxiliary,src,dest);
 }
}

canonical_original_code:
void hanoi(unsigned int level, char *src, char *auxiliary, char *dest)
{
 if(level > 0)
 {
  hanoi(level-1,src,dest,auxiliary);
  fprintf(stdout,"(%s,%s)\n",src,dest);
  hanoi(level-1,auxiliary,src,dest);
 }
}

variable_types:
level
unsigned int

variable_types:
src
char *

variable_types:
auxiliary
char *

variable_types:
dest
char *


decompiled_code:
__int64 __fastcall is_conflict(_DWORD *a1, int *a2)
{
__int64 v2; // rdx
int v3; // ecx

v2 = a2 - a1;
if ( a2 == a1 )
return 0LL;
v3 = *a2;
while ( *a1 + (_DWORD)v2 != v3 && v3 != *a1 - (_DWORD)v2 )
{
++a1;
LODWORD(v2) = v2 - 1;
if ( a2 == a1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, int *a2)
{
__int64 v2; // rdx
int v3; // ecx

v2 = a2 - a1;
if ( a2 == a1 )
return 0LL;
v3 = *a2;
while ( *a1 + (_DWORD)v2 != v3 && v3 != *a1 - (_DWORD)v2 )
{
++a1;
LODWORD(v2) = v2 - 1;
if ( a2 == a1 )
return 0LL;
}
return 1LL;
}

original_code:
int is_conflict(uint32_t *begin,uint32_t *current)
{
 int res = 0;
 uint32_t offset = current - begin;
 while(begin != current)
 {
  if(*begin + offset == *current || *begin - offset == *current)
  {
   res = 1;
   break;
  }
  ++begin;
  --offset;
 }
 return res;
}

canonical_original_code:
int is_conflict(unsigned int *begin, unsigned int *current)
{
 int res = 0;
 unsigned int offset = current - begin;
 while(begin != current)
 {
  if(*begin + offset == *current || *begin - offset == *current)
  {
   res = 1;
   break;
  }
  ++begin;
  --offset;
 }
 return res;
}

variable_types:
begin
unsigned int *

variable_types:
current
unsigned int *

variable_types: res int

variable_types:
offset
unsigned int


decompiled_code:
int __fastcall n_queens3(unsigned int *a1, int *a2, unsigned int *a3)
{
unsigned int *v4; // rbx
int *v5; // rbp
unsigned int *v6; // r12
_DWORD *v7; // r14
unsigned int *v8; // rsi
int result; // eax
unsigned int v10; // ebp
__int64 v11; // rcx
__int64 v12; // rdx

v4 = a1;
if ( a2 == (int *)a3 )
{
if ( a3 != a1 )
{
v10 = 0;
do
{
v11 = *v4++;
v12 = v10++;
fprintf(stdout, "(%d,%u)", v12, v11);
}
while ( a3 != v4 );
}
result = fputc(10, stdout);
}
else
{
v5 = a2;
v6 = (unsigned int *)a2;
v7 = a2 + 1;
do
{
swap(v5, v6);
if ( !(unsigned int)is_conflict(a1, v5) )
n_queens3(a1, v7, a3);
v8 = v6++;
result = swap(v5, v8);
}
while ( a3 != v6 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(unsigned int *a1, int *a2, unsigned int *a3)
{
unsigned int *v4; // rbx
int *v5; // rbp
unsigned int *v6; // r12
_DWORD *v7; // r14
unsigned int *v8; // rsi
int result; // eax
unsigned int v10; // ebp
__int64 v11; // rcx
__int64 v12; // rdx

v4 = a1;
if ( a2 == (int *)a3 )
{
if ( a3 != a1 )
{
v10 = 0;
do
{
v11 = *v4++;
v12 = v10++;
fprintf(stdout, "(%d,%u)", v12, v11);
}
while ( a3 != v4 );
}
result = fputc(10, stdout);
}
else
{
v5 = a2;
v6 = (unsigned int *)a2;
v7 = a2 + 1;
do
{
func7(v5, v6);
if ( !(unsigned int)func8(a1, v5) )
func9(a1, v7, a3);
v8 = v6++;
result = func7(v5, v8);
}
while ( a3 != v6 );
}
return result;
}

original_code:
void n_queens3(uint32_t *begin,uint32_t *current,uint32_t *end)
{
 if(current == end)
 {
  int i = 0;
  while(begin != end)
  {
   fprintf(stdout,"(%d,%u)",i++,*begin++);
  }
  fprintf(stdout,"\n");
 }
 else
 {
  uint32_t *scanner = ((void *)0);
  for(scanner = current; scanner != end; ++scanner)
  {
   swap(current,scanner);
   if(!is_conflict(begin,current))
   {
    n_queens3(begin,current + 1,end);
   }
   swap(current,scanner);
  }
 }
}

canonical_original_code:
void n_queens3(unsigned int *begin, unsigned int *current, unsigned int *end)
{
 if(current == end)
 {
  int i = 0;
  while(begin != end)
  {
   fprintf(stdout,"(%d,%u)",i++,*begin++);
  }
  fprintf(stdout,"\n");
 }
 else
 {
  unsigned int *scanner = ((void *)0);
  for(scanner = current; scanner != end; ++scanner)
  {
   swap(current,scanner);
   if(!is_conflict(begin,current))
   {
    n_queens3(begin,current + 1,end);
   }
   swap(current,scanner);
  }
 }
}

variable_types:
end
unsigned int *

variable_types: i int

variable_types:
scanner
unsigned int *


decompiled_code:
int __fastcall n_queens(unsigned int a1)
{
__int64 v1; // rbx
size_t v2; // rbp
unsigned int *v3; // rdi
__int64 i; // rax

v1 = a1;
v2 = a1;
v3 = (unsigned int *)malloc(v2 * 4);
if ( (_DWORD)v1 )
{
for ( i = 0LL; i != v1; ++i )
v3[i] = i;
}
return n_queens3(v3, (int *)v3, &v3[v2]);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1)
{
__int64 v1; // rbx
size_t v2; // rbp
unsigned int *v3; // rdi
__int64 i; // rax

v1 = a1;
v2 = a1;
v3 = (unsigned int *)malloc(v2 * 4);
if ( (_DWORD)v1 )
{
for ( i = 0LL; i != v1; ++i )
v3[i] = i;
}
return func9(v3, (int *)v3, &v3[v2]);
}

original_code:
void n_queens(uint32_t n)
{
 uint32_t *position = (uint32_t*)malloc(sizeof(uint32_t) * n);
 int i;
 for(i = 0; i < n; ++i)
 {
  position[i] = i;
 }
 n_queens3(position,position,position + n);
}

canonical_original_code:
void n_queens(unsigned int n)
{
 unsigned int *position = (uint32_t*)malloc(sizeof(uint32_t) * n);
 int i;
 for(i = 0; i < n; ++i)
 {
  position[i] = i;
 }
 n_queens3(position,position,position + n);
}

variable_types:
n
unsigned int

variable_types:
position
unsigned int *


swap

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void swap(uint32_t *first,uint32_t *second)
{
 uint32_t tmp = *first;
 *first = *second;
 *second = tmp;
}

canonical_original_code:
void swap(unsigned int *first, unsigned int *second)
{
 unsigned int tmp = *first;
 *first = *second;
 *second = tmp;
}

variable_types:
first
unsigned int *

variable_types:
second
unsigned int *

variable_types:
tmp
unsigned int


sum

decompiled_code:
__int64 __fastcall sum(int *a1, int *a2)
{
__int64 result; // rax
int v3; // edx

for ( result = 0LL; a1 != a2; result = (unsigned int)(v3 + result) )
v3 = *a1++;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1, int *a2)
{
__int64 result; // rax
int v3; // edx

for ( result = 0LL; a1 != a2; result = (unsigned int)(v3 + result) )
v3 = *a1++;
return result;
}

original_code:
static uint32_t sum(uint32_t *begin,uint32_t *end)
{
 uint32_t res;
 if(begin == end)
 {
  res = 0;
 }
 else
 {
  res = *begin + sum(begin + 1,end);
 }
 return res;
}

canonical_original_code:
static unsigned int sum(unsigned int *begin, unsigned int *end)
{
 unsigned int res;
 if(begin == end)
 {
  res = 0;
 }
 else
 {
  res = *begin + sum(begin + 1,end);
 }
 return res;
}

variable_types:
res
unsigned int


decompiled_code:
__int64 __fastcall dp_sum(__int64 a1, int *a2, int *a3, __int64 a4)
{
unsigned int v5; // er13
unsigned int v6; // er12
__int64 v7; // rbx
int v8; // eax
__int64 v9; // rcx
int *v10; // r8
int v11; // ebp

v5 = 0;
v6 = (((__int64)a3 - a1) >> 2) - 1;
v7 = ((__int64)a2 - a1) >> 2;
if ( a2 != a3 )
{
v8 = isset_resultset(a4, (unsigned int)(v7 + 1), v6);
v10 = a3;
if ( !v8 )
dp_sum(a1, a2 + 1, a3, a4);
v11 = *a2;
v5 = v11 + get_resultset(a4, (unsigned int)(v7 + 1), v6, v9, v10);
}
set_resultset(a4, (unsigned int)v7, v6, v5);
return v5;
}

original_code:
static uint32_t dp_sum(uint32_t *numbers,uint32_t *begin,uint32_t *end,resultset_t *srs)
{
 int32_t x = begin - numbers;
 int32_t y = end - numbers - 1;
 uint32_t res;
 if(begin == end)
 {
  res = 0;
 }
 else
 {
  if(!isset_resultset(srs,x + 1,y))
  {
   dp_sum(numbers,begin + 1,end,srs);
  }
  res = *begin + get_resultset(srs,x + 1,y);
 }
 set_resultset(srs,x,y,res);
 return res;
}

canonical_original_code:
static unsigned int dp_sum(unsigned int *numbers, unsigned int *begin, unsigned int *end, struct resultset_t *srs)
{
 int x = begin - numbers;
 int y = end - numbers - 1;
 unsigned int res;
 if(begin == end)
 {
  res = 0;
 }
 else
 {
  if(!isset_resultset(srs,x + 1,y))
  {
   dp_sum(numbers,begin + 1,end,srs);
  }
  res = *begin + get_resultset(srs,x + 1,y);
 }
 set_resultset(srs,x,y,res);
 return res;
}

variable_types:
numbers
unsigned int *

variable_types: struct resultset_t { unsigned int *resultset; int *resultset_flag; unsigned int size; } *

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall dp_merge_stones4(__int64 a1, int *a2, int *a3, __int64 a4, __int64 a5)
{
unsigned int v5; // er14
unsigned int v7; // er12
int *v8; // r14
__int64 v9; // rbx
__int64 v10; // rcx
__int64 v11; // r8
int v12; // er15
__int64 v13; // rcx
__int64 v14; // r8
int v15; // eax
unsigned int v16; // er15
unsigned int v18; // [rsp+Ch] [rbp-5Ch]
__int64 v21; // [rsp+28h] [rbp-40h]

v5 = 0;
v7 = (((__int64)a3 - a1) >> 2) - 1;
v21 = ((__int64)a2 - a1) >> 2;
if ( (char *)a3 - (char *)a2 > 4 && a3 != a2 + 1 )
{
v18 = 0;
v8 = a2 + 1;
do
{
v9 = ((__int64)v8 - a1) >> 2;
if ( !(unsigned int)isset_resultset(a4, (unsigned int)v21, (unsigned int)(v9 - 1)) )
dp_merge_stones4(a1, a2, v8, a4, a5);
if ( !(unsigned int)isset_resultset(a4, (unsigned int)v9, v7) )
dp_merge_stones4(a1, v8, a3, a4, a5);
v12 = get_resultset(a4, (unsigned int)v21, (unsigned int)(v9 - 1), v10, v11);
v15 = get_resultset(a4, (unsigned int)v9, v7, v13, v14);
v16 = dp_sum(a1, a2, a3, a5) + v15 + v12;
if ( v18 >= v16 )
v16 = v18;
++v8;
v18 = v16;
}
while ( a3 != v8 );
v5 = v16;
}
set_resultset(a4, (unsigned int)v21, v7, v5);
return v5;
}

original_code:
static uint32_t dp_merge_stones4(uint32_t *stones,uint32_t *begin,uint32_t *end,
  resultset_t *rs,resultset_t *srs)
{
 int32_t x = begin - stones;
 int32_t y = end - stones - 1;
 uint32_t res;
 if(end - begin < 2)
 {
  res = 0;
 }
 else
 {
  res = 0;
  uint32_t *splitter = ((void *)0);
  for(splitter = begin + 1; splitter != end; ++splitter)
  {
   int32_t splitter_index = splitter - stones - 1;
   if(!isset_resultset(rs,x,splitter_index))
   {
    dp_merge_stones4(stones,begin,splitter,rs,srs);
   }
   if(!isset_resultset(rs,splitter_index + 1,y))
   {
    dp_merge_stones4(stones,splitter,end,rs,srs);
   }
   uint32_t tmpres = get_resultset(rs,x,splitter_index) +
    get_resultset(rs,splitter_index + 1,y) + dp_sum(stones,begin,end,srs);
   if(res < tmpres)
   {
    res = tmpres;
   }
  }
 }
 set_resultset(rs,x,y,res);
 return res;
}

canonical_original_code:
static unsigned int dp_merge_stones4(unsigned int *stones, unsigned int *begin, unsigned int *end, struct resultset_t *rs, struct resultset_t *srs)
{
 int x = begin - stones;
 int y = end - stones - 1;
 unsigned int res;
 if(end - begin < 2)
 {
  res = 0;
 }
 else
 {
  res = 0;
  unsigned int *splitter = ((void *)0);
  for(splitter = begin + 1; splitter != end; ++splitter)
  {
   int splitter_index = splitter - stones - 1;
   if(!isset_resultset(rs,x,splitter_index))
   {
    dp_merge_stones4(stones,begin,splitter,rs,srs);
   }
   if(!isset_resultset(rs,splitter_index + 1,y))
   {
    dp_merge_stones4(stones,splitter,end,rs,srs);
   }
   unsigned int tmpres = get_resultset(rs,x,splitter_index) +
    get_resultset(rs,splitter_index + 1,y) + dp_sum(stones,begin,end,srs);
   if(res < tmpres)
   {
    res = tmpres;
   }
  }
 }
 set_resultset(rs,x,y,res);
 return res;
}

variable_types:
stones
unsigned int *

variable_types:
begin
unsigned int *

variable_types:
srs
struct resultset_t *

variable_types:
splitter
unsigned int *

variable_types:
tmpres
unsigned int

user_defined_types: struct resultset_t { unsigned int *resultset; int *resultset_flag; unsigned int size; }


decompiled_code:
__int64 __fastcall merge_stones(int *a1, int *a2)
{
unsigned int v2; // er14
int *v3; // rbp
int v4; // er13
int v5; // ebx
unsigned int v6; // eax

v2 = 0;
if ( (char *)a2 - (char *)a1 > 4 )
{
v3 = a1 + 1;
if ( a2 != a1 + 1 )
{
v4 = sum(a1, a2);
do
{
v5 = merge_stones(a1, v3);
v6 = v4 + v5 + merge_stones(v3, a2);
if ( v2 < v6 )
v2 = v6;
++v3;
}
while ( a2 != v3 );
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1, int *a2)
{
unsigned int v2; // er14
int *v3; // rbp
int v4; // er13
int v5; // ebx
unsigned int v6; // eax

v2 = 0;
if ( (char *)a2 - (char *)a1 > 4 )
{
v3 = a1 + 1;
if ( a2 != a1 + 1 )
{
v4 = func7(a1, a2);
do
{
v5 = func10(a1, v3);
v6 = v4 + v5 + func10(v3, a2);
if ( v2 < v6 )
v2 = v6;
++v3;
}
while ( a2 != v3 );
}
}
return v2;
}

original_code:
uint32_t merge_stones(uint32_t *begin,uint32_t *end)
{
 uint32_t res;
 if(end - begin < 2)
 {
  res = 0;
 }
 else
 {
  res = 0;
  uint32_t *splitter = ((void *)0);
  for(splitter = begin + 1; splitter != end; ++splitter)
  {
   uint32_t tmpres = merge_stones(begin,splitter) +
    merge_stones(splitter,end) + sum(begin,end);
   if(res < tmpres)
   {
    res = tmpres;
   }
  }
 }
 return res;
}

canonical_original_code:
unsigned int merge_stones(unsigned int *begin, unsigned int *end)
{
 unsigned int res;
 if(end - begin < 2)
 {
  res = 0;
 }
 else
 {
  res = 0;
  unsigned int *splitter = ((void *)0);
  for(splitter = begin + 1; splitter != end; ++splitter)
  {
   unsigned int tmpres = merge_stones(begin,splitter) +
    merge_stones(splitter,end) + sum(begin,end);
   if(res < tmpres)
   {
    res = tmpres;
   }
  }
 }
 return res;
}

variable_types:
end
unsigned int *


decompiled_code:
__int64 __fastcall dp_merge_stones(int *a1, int *a2)
{
void *v2; // r12
__int64 v3; // rax
unsigned int v4; // er13

v2 = (void *)create_resultset((unsigned int)(a2 - a1));
v3 = create_resultset((unsigned int)(a2 - a1));
v4 = dp_merge_stones4((__int64)a1, a1, a2, (__int64)v2, v3);
destroy_resultset(v2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1, int *a2)
{
void *v2; // r12
__int64 v3; // rax
unsigned int v4; // er13

v2 = (void *)create_resultset((unsigned int)(a2 - a1));
v3 = create_resultset((unsigned int)(a2 - a1));
v4 = func9((__int64)a1, a1, a2, (__int64)v2, v3);
func17(v2);
return v4;
}

original_code:
uint32_t dp_merge_stones(uint32_t *begin,uint32_t *end)
{
 uint32_t size = end - begin;
 resultset_t *rs = create_resultset(size);
 resultset_t *srs = create_resultset(size);
 uint32_t res = dp_merge_stones4(begin,begin,end,rs,srs);
 destroy_resultset(rs);
 return res;
}

canonical_original_code:
unsigned int dp_merge_stones(unsigned int *begin, unsigned int *end)
{
 unsigned int size = end - begin;
 struct resultset_t *rs = create_resultset(size);
 struct resultset_t *srs = create_resultset(size);
 unsigned int res = dp_merge_stones4(begin,begin,end,rs,srs);
 destroy_resultset(rs);
 return res;
}

variable_types:
size
unsigned int


decompiled_code:
void *__fastcall init_resultset(__int64 a1, int a2)
{
return memset(*(void **)(a1 + 8), a2, 4 * *(unsigned int *)(a1 + 16) * (unsigned __int64)*(unsigned int *)(a1 + 16));
}

canonical_decompiled_code:
void *__fastcall func12(__int64 a1, int a2)
{
return memset(*(void **)(a1 + 8), a2, 4 * *(unsigned int *)(a1 + 16) * (unsigned __int64)*(unsigned int *)(a1 + 16));
}

original_code:
void init_resultset(resultset_t *rs,int value)
{
 uint32_t size = rs->size;
 memset(rs->resultset_flag,value,sizeof(int) * size * size);
}

canonical_original_code:
void init_resultset(struct resultset_t *rs, int value)
{
 unsigned int size = rs->size;
 memset(rs->resultset_flag,value,sizeof(int) * size * size);
}

variable_types: value int


decompiled_code:
__int64 __fastcall index_resultset(__int64 a1, int a2, int a3)
{
return (unsigned int)(*(_DWORD *)(a1 + 16) * a2 + a3);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2, int a3)
{
return (unsigned int)(*(_DWORD *)(a1 + 16) * a2 + a3);
}

original_code:
int32_t index_resultset(resultset_t *rs,int32_t x,int32_t y)
{
 return x * rs->size + y;
}

canonical_original_code:
int index_resultset(struct resultset_t *rs, int x, int y)
{
 return x * rs->size + y;
}


decompiled_code:
__int64 __fastcall get_resultset(_QWORD *a1, int a2, int a3)
{
return *(unsigned int *)(*a1 + 4LL * (int)index_resultset((__int64)a1, a2, a3));
}

canonical_decompiled_code:
__int64 __fastcall func14(_QWORD *a1, int a2, int a3)
{
return *(unsigned int *)(*a1 + 4LL * (int)func13((__int64)a1, a2, a3));
}

original_code:
uint32_t get_resultset(resultset_t *rs,int32_t x,int32_t y)
{
 return rs->resultset[index_resultset(rs,x,y)];
}

canonical_original_code:
unsigned int get_resultset(struct resultset_t *rs, int x, int y)
{
 return rs->resultset[index_resultset(rs,x,y)];
}


decompiled_code:
__int64 __fastcall isset_resultset(__int64 a1, int a2, int a3)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * (int)index_resultset(a1, a2, a3));
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, int a2, int a3)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * (int)func13(a1, a2, a3));
}

original_code:
int isset_resultset(resultset_t *rs,int32_t x,int32_t y)
{
 return rs->resultset_flag[index_resultset(rs,x,y)];
}

canonical_original_code:
int isset_resultset(struct resultset_t *rs, int x, int y)
{
 return rs->resultset_flag[index_resultset(rs,x,y)];
}


decompiled_code:
__int64 __fastcall destroy_resultset(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

original_code:
int destroy_resultset(resultset_t *rs)
{
 if(rs == ((void *)0))
 {
  return -1;
 }
 free(rs->resultset);
 free(rs->resultset_flag);
 free(rs);
 return 0;
}

canonical_original_code:
int destroy_resultset(struct resultset_t *rs)
{
 if(rs == ((void *)0))
 {
  return -1;
 }
 free(rs->resultset);
 free(rs->resultset_flag);
 free(rs);
 return 0;
}


original_code:
uint32_t dp_lcs7(char *x_sequence,char *begin_x,char *end_x,
  char *y_sequence,char *begin_y,char *end_y,resultset_t *rs)
{
 int32_t x = begin_x - x_sequence;
 int32_t y = begin_y - y_sequence;
 uint32_t res;
 if(begin_x == end_x || begin_y == end_y)
 {
  res = 0;
 }
 else if(*begin_x == *begin_y)
 {
  if(!isset_resultset(rs,x+1,y+1))
  {
   dp_lcs7(x_sequence,begin_x + 1,end_x,y_sequence,begin_y + 1,end_y,rs);
  }
  res = 1 + get_resultset(rs,x+1,y+1);
 }
 else
 {
  if(!isset_resultset(rs,x+1,y))
  {
   dp_lcs7(x_sequence,begin_x + 1,end_x,y_sequence,begin_y,end_y,rs);
  }
  if(!isset_resultset(rs,x,y+1))
  {
   dp_lcs7(x_sequence,begin_x,end_x,y_sequence,begin_y + 1,end_y,rs);
  }
  uint32_t xcs_size = get_resultset(rs,x+1,y);
  uint32_t ycs_size = get_resultset(rs,x,y+1);
  res = xcs_size > ycs_size ? xcs_size : ycs_size;
 }
 set_resultset(rs,x,y,res);
 return res;
}

canonical_original_code:
unsigned int dp_lcs7(char *x_sequence, char *begin_x, char *end_x, char *y_sequence, char *begin_y, char *end_y, struct resultset_t *rs)
{
 int x = begin_x - x_sequence;
 int y = begin_y - y_sequence;
 unsigned int res;
 if(begin_x == end_x || begin_y == end_y)
 {
  res = 0;
 }
 else if(*begin_x == *begin_y)
 {
  if(!isset_resultset(rs,x+1,y+1))
  {
   dp_lcs7(x_sequence,begin_x + 1,end_x,y_sequence,begin_y + 1,end_y,rs);
  }
  res = 1 + get_resultset(rs,x+1,y+1);
 }
 else
 {
  if(!isset_resultset(rs,x+1,y))
  {
   dp_lcs7(x_sequence,begin_x + 1,end_x,y_sequence,begin_y,end_y,rs);
  }
  if(!isset_resultset(rs,x,y+1))
  {
   dp_lcs7(x_sequence,begin_x,end_x,y_sequence,begin_y + 1,end_y,rs);
  }
  unsigned int xcs_size = get_resultset(rs,x+1,y);
  unsigned int ycs_size = get_resultset(rs,x,y+1);
  res = xcs_size > ycs_size ? xcs_size : ycs_size;
 }
 set_resultset(rs,x,y,res);
 return res;
}


lcs

original_code:
uint32_t lcs(char *begin_x,char *end_x,char *begin_y,char *end_y)
{
 uint32_t res;
 if(begin_x == end_x || begin_y == end_y)
 {
  res = 0;
 }
 else if(*begin_x == *begin_y)
 {
  res = 1 + lcs(begin_x + 1,end_x,begin_y + 1,end_y);
 }
 else
 {
  uint32_t xcs_size = lcs(begin_x + 1,end_x,begin_y,end_y);
  uint32_t ycs_size = lcs(begin_x,end_x,begin_y + 1,end_y);
  res = xcs_size > ycs_size ? xcs_size: ycs_size;
 }
 return res;
}

canonical_original_code:
unsigned int lcs(char *begin_x, char *end_x, char *begin_y, char *end_y)
{
 unsigned int res;
 if(begin_x == end_x || begin_y == end_y)
 {
  res = 0;
 }
 else if(*begin_x == *begin_y)
 {
  res = 1 + lcs(begin_x + 1,end_x,begin_y + 1,end_y);
 }
 else
 {
  unsigned int xcs_size = lcs(begin_x + 1,end_x,begin_y,end_y);
  unsigned int ycs_size = lcs(begin_x,end_x,begin_y + 1,end_y);
  res = xcs_size > ycs_size ? xcs_size: ycs_size;
 }
 return res;
}


decompiled_code:
__int64 __fastcall dp_lcs(_BYTE *a1, _BYTE *a2, _BYTE *a3, _BYTE *a4)
{
_BYTE *v4; // r12
void *v6; // r13

v4 = a3;
v6 = (void *)create_resultset((unsigned int)(((_DWORD)a4 - (_DWORD)a3) * ((_DWORD)a2 - (_DWORD)a1)));
LODWORD(v4) = dp_lcs7((int)a1, a1, a2, (__int64)v4, v4, a4, (__int64)v6);
destroy_resultset(v6);
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1, _BYTE *a2, _BYTE *a3, _BYTE *a4)
{
_BYTE *v4; // r12
void *v6; // r13

v4 = a3;
v6 = (void *)create_resultset((unsigned int)(((_DWORD)a4 - (_DWORD)a3) * ((_DWORD)a2 - (_DWORD)a1)));
LODWORD(v4) = func7((int)a1, a1, a2, (__int64)v4, v4, a4, (__int64)v6);
func15(v6);
return (unsigned int)v4;
}

original_code:
uint32_t dp_lcs(char *begin_x,char *end_x,char *begin_y,char *end_y)
{
 uint32_t xsize = end_x - begin_x;
 uint32_t ysize = end_y - begin_y;
 resultset_t *rs = create_resultset(xsize * ysize);
 uint32_t res = dp_lcs7(begin_x,begin_x,end_x,begin_y,begin_y,end_y,rs);
 destroy_resultset(rs);
 return res;
}

canonical_original_code:
unsigned int dp_lcs(char *begin_x, char *end_x, char *begin_y, char *end_y)
{
 unsigned int xsize = end_x - begin_x;
 unsigned int ysize = end_y - begin_y;
 struct resultset_t *rs = create_resultset(xsize * ysize);
 unsigned int res = dp_lcs7(begin_x,begin_x,end_x,begin_y,begin_y,end_y,rs);
 destroy_resultset(rs);
 return res;
}

variable_types:
xsize
unsigned int

variable_types:
ysize
unsigned int


canonical_decompiled_code:
void *__fastcall func10(__int64 a1, int a2)
{
return memset(*(void **)(a1 + 8), a2, 4 * *(unsigned int *)(a1 + 16) * (unsigned __int64)*(unsigned int *)(a1 + 16));
}


canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2, int a3)
{
return (unsigned int)(*(_DWORD *)(a1 + 16) * a2 + a3);
}


canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1, int a2, int a3)
{
return *(unsigned int *)(*a1 + 4LL * (int)func11((__int64)a1, a2, a3));
}


canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2, int a3)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * (int)func11(a1, a2, a3));
}


canonical_decompiled_code:
__int64 __fastcall func15(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}


decompiled_code:
__int64 __fastcall dp_zero_one_knapsack5(__int64 a1, unsigned int *a2, unsigned int *a3, unsigned int a4, __int64 a5)
{
__int64 v6; // r13
unsigned int v8; // er15
int v10; // eax
unsigned int *v11; // r9
unsigned int v12; // er14
unsigned int v13; // er14
unsigned int *v15; // [rsp+0h] [rbp-48h]
unsigned int v16; // [rsp+Ch] [rbp-3Ch]

v6 = ((__int64)a2 - a1) >> 3;
if ( a2 != a3 && a4 )
{
v16 = v6 + 1;
v10 = isset_resultset(a5, (unsigned int)(v6 + 1), a4);
v11 = a3;
if ( !v10 )
{
dp_zero_one_knapsack5(a1, a2 + 2, a3, a4, a5);
v11 = a3;
}
v15 = v11;
v8 = get_resultset(a5, v16, a4);
if ( *a2 <= a4 )
{
if ( !(unsigned int)isset_resultset(a5, v16, a4 - *a2) )
dp_zero_one_knapsack5(a1, a2 + 2, v15, a4 - *a2, a5);
v12 = a2[1];
v13 = get_resultset(a5, v16, a4 - *a2) + v12;
if ( v8 < v13 )
v8 = v13;
}
}
else
{
v8 = 0;
}
set_resultset(a5, (unsigned int)v6, a4, v8);
return v8;
}

original_code:
static uint32_t dp_zero_one_knapsack5(item_t *items,item_t *begin,item_t *end,
  uint32_t kweight,resultset_t *rs)
{
 int32_t x = begin - items;
 int32_t y = kweight;
 uint32_t res;
 if(begin == end || kweight == 0)
 {
  res = 0;
 }
 else
 {
  if(!isset_resultset(rs,x + 1,y))
  {
   dp_zero_one_knapsack5(items,begin + 1,end,kweight,rs);
  }
  res = get_resultset(rs,x + 1,y);
  if((begin->weight) <= kweight)
  {
   if(!isset_resultset(rs,x + 1,y - (begin->weight)))
   {
    dp_zero_one_knapsack5(items,begin + 1,end,kweight - (begin->weight),rs);
   }
   uint32_t tmpres = (begin->value) +
    get_resultset(rs,x + 1,y - (begin->weight));
   if(res < tmpres)
   {
    res = tmpres;
   }
  }
 }
 set_resultset(rs,x,y,res);
 return res;
}

canonical_original_code:
static unsigned int dp_zero_one_knapsack5(struct item_t *items, struct item_t *begin, struct item_t *end, unsigned int kweight, struct resultset_t *rs)
{
 int x = begin - items;
 int y = kweight;
 unsigned int res;
 if(begin == end || kweight == 0)
 {
  res = 0;
 }
 else
 {
  if(!isset_resultset(rs,x + 1,y))
  {
   dp_zero_one_knapsack5(items,begin + 1,end,kweight,rs);
  }
  res = get_resultset(rs,x + 1,y);
  if((begin->weight) <= kweight)
  {
   if(!isset_resultset(rs,x + 1,y - (begin->weight)))
   {
    dp_zero_one_knapsack5(items,begin + 1,end,kweight - (begin->weight),rs);
   }
   unsigned int tmpres = (begin->value) +
    get_resultset(rs,x + 1,y - (begin->weight));
   if(res < tmpres)
   {
    res = tmpres;
   }
  }
 }
 set_resultset(rs,x,y,res);
 return res;
}

variable_types: struct item_t { unsigned int weight; unsigned int value; } *

variable_types:
begin
struct item_t *

variable_types:
end
struct item_t *

variable_types:
kweight
unsigned int


decompiled_code:
void __fastcall destroy_item(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func8(void *a1)
{
free(a1);
}

original_code:
int destroy_item(item_t *item)
{
 free(item);
}

canonical_original_code:
int destroy_item(struct item_t *item)
{
 free(item);
}

user_defined_types: struct item_t { unsigned int weight; unsigned int value; }


decompiled_code:
__int64 __fastcall zero_one_knapsack(unsigned int *a1, unsigned int *a2, __int64 a3)
{
unsigned int v3; // ebp
unsigned int v4; // er13
unsigned int v6; // eax

if ( a1 == a2 )
return 0;
v3 = a3;
if ( !(_DWORD)a3 )
return 0;
v4 = zero_one_knapsack(a1 + 2, a2, a3);
if ( *a1 > v3 )
return v4;
v6 = a1[1] + zero_one_knapsack(a1 + 2, a2, v3 - *a1);
if ( v4 < v6 )
v4 = v6;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1, unsigned int *a2, __int64 a3)
{
unsigned int v3; // ebp
unsigned int v4; // er13
unsigned int v6; // eax

if ( a1 == a2 )
return 0;
v3 = a3;
if ( !(_DWORD)a3 )
return 0;
v4 = func9(a1 + 2, a2, a3);
if ( *a1 > v3 )
return v4;
v6 = a1[1] + func9(a1 + 2, a2, v3 - *a1);
if ( v4 < v6 )
v4 = v6;
return v4;
}

original_code:
uint32_t zero_one_knapsack(item_t *begin,item_t *end,uint32_t kweight)
{
 uint32_t res;
 if(begin == end || kweight == 0)
 {
  res = 0;
 }
 else
 {
  res = zero_one_knapsack(begin + 1,end,kweight);
  if((begin->weight) <= kweight)
  {
   uint32_t tmpres = (begin->value) +
    zero_one_knapsack(begin + 1,end,kweight - (begin->weight));
   if(res < tmpres)
   {
    res = tmpres;
   }
  }
 }
 return res;
}

canonical_original_code:
unsigned int zero_one_knapsack(struct item_t *begin, struct item_t *end, unsigned int kweight)
{
 unsigned int res;
 if(begin == end || kweight == 0)
 {
  res = 0;
 }
 else
 {
  res = zero_one_knapsack(begin + 1,end,kweight);
  if((begin->weight) <= kweight)
  {
   unsigned int tmpres = (begin->value) +
    zero_one_knapsack(begin + 1,end,kweight - (begin->weight));
   if(res < tmpres)
   {
    res = tmpres;
   }
  }
 }
 return res;
}

variable_types:
res
unsigned int


decompiled_code:
__int64 __fastcall dp_zero_one_knapsack(unsigned int *a1, unsigned int *a2, unsigned int a3)
{
void *v4; // r12
unsigned int v5; // er13

v4 = (void *)create_resultset(a3 * (unsigned int)(((char *)a2 - (char *)a1) >> 3));
v5 = dp_zero_one_knapsack5((__int64)a1, a1, a2, a3, (__int64)v4);
destroy_resultset(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1, unsigned int *a2, unsigned int a3)
{
void *v4; // r12
unsigned int v5; // er13

v4 = (void *)create_resultset(a3 * (unsigned int)(((char *)a2 - (char *)a1) >> 3));
v5 = func7((__int64)a1, a1, a2, a3, (__int64)v4);
func17(v4);
return v5;
}

original_code:
uint32_t dp_zero_one_knapsack(item_t *begin,item_t *end,uint32_t kweight)
{
 uint32_t size = end - begin;
 resultset_t *rs = create_resultset(size * kweight);
 uint32_t res = dp_zero_one_knapsack5(begin,begin,end,kweight,rs);
 destroy_resultset(rs);
 return res;
}

canonical_original_code:
unsigned int dp_zero_one_knapsack(struct item_t *begin, struct item_t *end, unsigned int kweight)
{
 unsigned int size = end - begin;
 struct resultset_t *rs = create_resultset(size * kweight);
 unsigned int res = dp_zero_one_knapsack5(begin,begin,end,kweight,rs);
 destroy_resultset(rs);
 return res;
}

variable_types: struct resultset_t { unsigned int *resultset; int *resultset_flag; unsigned int size; } *


knapsack

decompiled_code:
void knapsack()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
uint32_t knapsack(item_t *begin,item_t *end,uint32_t kweight)
{
}

canonical_original_code:
unsigned int knapsack(struct item_t *begin, struct item_t *end, unsigned int kweight)
{
}


variable_types: x int

variable_types: y int