decompiled_code:
__int64 __fastcall reset_inc_cov(unsigned __int64 *a1)
{
__int64 v1; // r12
unsigned __int64 i; // rbx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 *a1)
{
__int64 v1; // r12
unsigned __int64 i; // rbx
__int64 result; // rax

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

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

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

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

variable_types: oi int

variable_types: oii int

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


repo: QCaudron/iterated-inference-pipeline

decompiled_code:
__int64 __fastcall check_and_correct_Ct(unsigned __int64 *a1, _QWORD *a2)
{
__int64 v2; // rbp
unsigned __int64 i; // r15
__int64 v4; // r13
__int64 v5; // r15
unsigned int v6; // eax
__int64 result; // rax
__int64 v8; // r12
double v9; // r12
double v10; // xmm2_8
unsigned __int64 j; // r13
const char *v12; // rax
double v13; // xmm0_8
__int64 v14; // r12
unsigned int v15; // eax
const char *v16; // rax
const char *v17; // rax
int v18; // [rsp+Ch] [rbp-13Ch]
char s[312]; // [rsp+10h] [rbp-138h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 *a1, _QWORD *a2)
{
__int64 v2; // rbp
unsigned __int64 i; // r15
__int64 v4; // r13
__int64 v5; // r15
unsigned int v6; // eax
__int64 result; // rax
__int64 v8; // r12
double v9; // r12
double v10; // xmm2_8
unsigned __int64 j; // r13
const char *v12; // rax
double v13; // xmm0_8
__int64 v14; // r12
unsigned int v15; // eax
const char *v16; // rax
const char *v17; // rax
int v18; // [rsp+Ch] [rbp-13Ch]
char s[312]; // [rsp+10h] [rbp-138h] BYREF

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

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

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

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

variable_types:
str
char [255]

variable_types: i int

variable_types: j int

variable_types: status int

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

return_type: void

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


decompiled_code:
__int64 __fastcall ekf_gain_computation(__int64 a1, unsigned __int64 *a2, double a3, double a4)
{
__int64 v4; // r12
unsigned int v5; // eax
unsigned int v6; // eax
double v7; // xmm0_8
__int64 result; // rax
const char *v9; // rax
const char *v10; // rax
const char *v11; // rax
char v12[280]; // [rsp+0h] [rbp-118h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int64 *a2, double a3, double a4)
{
__int64 v4; // r12
unsigned int v5; // eax
unsigned int v6; // eax
double v7; // xmm0_8
__int64 result; // rax
const char *v9; // rax
const char *v10; // rax
const char *v11; // rax
char v12[280]; // [rsp+0h] [rbp-118h] BYREF

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

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

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

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

variable_types:
Ct
struct gsl_matrix *

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


decompiled_code:
__int64 __fastcall ekf_update(__int64 a1, unsigned __int64 *a2)
{
_QWORD *v2; // r12
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
double v6; // xmm1_8
double v7; // xmm1_8
const char *v9; // rax
const char *v10; // rax
const char *v11; // rax
_BYTE v12[48]; // [rsp+0h] [rbp-178h] BYREF
char v13[48]; // [rsp+30h] [rbp-148h] BYREF
char s[280]; // [rsp+60h] [rbp-118h] BYREF

v2 = *(_QWORD **)(a1 + 48);
v3 = gsl_blas_daxpy(*(_QWORD *)(a1 + 8), *(_QWORD *)a1, *(double *)(a1 + 32));
if ( v3 )
{
v9 = (const char *)gsl_strerror(v3);
sprintf(s, "error: %s\n", v9);
print_err(s);
}
v4 = gsl_blas_dgemv(112LL, a2, *(_QWORD *)(a1 + 16), v2, 1.0, 0.0);
if ( v4 )
{
v10 = (const char *)gsl_strerror(v4);
sprintf(s, "error: %s\n", v10);
print_err(s);
}
gsl_matrix_view_vector(v13, *(_QWORD *)(a1 + 8), **(_QWORD **)(a1 + 8), 1LL);
gsl_matrix_view_vector(v12, v2, *v2, 1LL);
v5 = gsl_blas_dgemm(111LL, 112LL, v12, v13, a2, -1.0, 1.0);
if ( v5 )
{
v11 = (const char *)gsl_strerror(v5);
sprintf(s, "error: %s\n", v11);
print_err(s);
}
check_and_correct_Ct(a2, (_QWORD *)a1);
v6 = *(double *)(a1 + 24);
if ( v6 < 0.0 )
v7 = sqrt(*(double *)(a1 + 24));
else
v7 = sqrt(v6);
gsl_ran_gaussian_pdf(*(double *)(a1 + 32), v7);
return sanitize_likelihood();
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int64 *a2)
{
_QWORD *v2; // r12
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
double v6; // xmm1_8
double v7; // xmm1_8
const char *v9; // rax
const char *v10; // rax
const char *v11; // rax
_BYTE v12[48]; // [rsp+0h] [rbp-178h] BYREF
char v13[48]; // [rsp+30h] [rbp-148h] BYREF
char s[280]; // [rsp+60h] [rbp-118h] BYREF

v2 = *(_QWORD **)(a1 + 48);
v3 = gsl_blas_daxpy(*(_QWORD *)(a1 + 8), *(_QWORD *)a1, *(double *)(a1 + 32));
if ( v3 )
{
v9 = (const char *)gsl_strerror(v3);
sprintf(s, "error: %s\n", v9);
print_err(s);
}
v4 = gsl_blas_dgemv(112LL, a2, *(_QWORD *)(a1 + 16), v2, 1.0, 0.0);
if ( v4 )
{
v10 = (const char *)gsl_strerror(v4);
sprintf(s, "error: %s\n", v10);
print_err(s);
}
gsl_matrix_view_vector(v13, *(_QWORD *)(a1 + 8), **(_QWORD **)(a1 + 8), 1LL);
gsl_matrix_view_vector(v12, v2, *v2, 1LL);
v5 = gsl_blas_dgemm(111LL, 112LL, v12, v13, a2, -1.0, 1.0);
if ( v5 )
{
v11 = (const char *)gsl_strerror(v5);
sprintf(s, "error: %s\n", v11);
print_err(s);
}
func0(a2, (_QWORD *)a1);
v6 = *(double *)(a1 + 24);
if ( v6 < 0.0 )
v7 = sqrt(*(double *)(a1 + 24));
else
v7 = sqrt(v6);
gsl_ran_gaussian_pdf(*(double *)(a1 + 32), v7);
return sanitize_likelihood();
}

original_code:
double ekf_update(struct s_kalman_update *p, gsl_matrix *Ct)
{
    char str[255];
    int status;
    gsl_vector *workn = p->v_n_kal;
    double like;
    status = gsl_blas_daxpy(p->sc_pred_error, p->kt, p->xk);
    if (status) {
        sprintf(str, "error: %s\n", gsl_strerror (status));
        print_err(str);
    }
    status = gsl_blas_dgemv(CblasTrans, 1.0, Ct, p->ht, 0.0, workn);
    if (status) {
        sprintf(str, "error: %s\n", gsl_strerror (status));
        print_err(str);
    }
    gsl_matrix_view Workn1 = gsl_matrix_view_vector (p->kt, p->kt->size, 1);
    gsl_matrix_view Workn2 = gsl_matrix_view_vector (workn, workn->size, 1);
    status = gsl_blas_dgemm(CblasNoTrans, CblasTrans, -1.0, &Workn2.matrix, &Workn1.matrix, 1.0, Ct);
    if (status) {
        sprintf(str, "error: %s\n", gsl_strerror (status));
        print_err(str);
    }
    check_and_correct_Ct(Ct, p);
    like = gsl_ran_gaussian_pdf(p->sc_pred_error, sqrt(p->sc_st));
    return sanitize_likelihood(like);
}

canonical_original_code:
double ekf_update(struct s_kalman_update *p, struct gsl_matrix *Ct)
{
    char str[255];
    int status;
    struct gsl_vector *workn = p->v_n_kal;
    double like;
    status = gsl_blas_daxpy(p->sc_pred_error, p->kt, p->xk);
    if (status) {
        sprintf(str, "error: %s\n", gsl_strerror (status));
        print_err(str);
    }
    status = gsl_blas_dgemv(CblasTrans, 1.0, Ct, p->ht, 0.0, workn);
    if (status) {
        sprintf(str, "error: %s\n", gsl_strerror (status));
        print_err(str);
    }
    struct _gsl_matrix_view Workn1 = gsl_matrix_view_vector (p->kt, p->kt->size, 1);
    struct _gsl_matrix_view Workn2 = gsl_matrix_view_vector (workn, workn->size, 1);
    status = gsl_blas_dgemm(CblasNoTrans, CblasTrans, -1.0, &Workn2.matrix, &Workn1.matrix, 1.0, Ct);
    if (status) {
        sprintf(str, "error: %s\n", gsl_strerror (status));
        print_err(str);
    }
    check_and_correct_Ct(Ct, p);
    like = gsl_ran_gaussian_pdf(p->sc_pred_error, sqrt(p->sc_st));
    return sanitize_likelihood(like);
}

variable_types: like double

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

return_type: double

user_defined_types: struct _gsl_matrix_view { struct gsl_matrix matrix; }

user_defined_types: struct gsl_eigen_symmv_workspace { unsigned long size; double *d; double *sd; double *gc; double *gs; }


original_code:
plom_err_code log_prob_prior(double *log_like, struct s_best *p_best, gsl_vector *mean, gsl_matrix *var, struct s_data *p_data)
{
    int i, k, offset;
    int is_err = 0;
    double p_tmp, Lp;
    p_tmp=0.0, Lp=0.0;
    double back_transformed;
    for(i=0; i<p_data->p_it_all->length; i++) {
 struct s_router *p_router = p_data->routers[p_data->p_it_all->ind[i]];
        for(k=0; k<p_router->n_gp; k++) {
     offset = p_data->p_it_all->offset[i] + k;
     if(p_best->is_estimated[offset]) {
                back_transformed = (*(p_router->f_inv[k]))(gsl_vector_get(mean, offset), p_router->min[k], p_router->max[k]);
                p_tmp = (*(p_best->prior[offset]))(back_transformed, p_best->par_prior[offset][0], p_best->par_prior[offset][1]);
                if( (__builtin_isnan (p_tmp)==1) || (__builtin_isinf_sign (p_tmp)==1) || (p_tmp<0.0) ) {
      is_err =1;
      p_tmp = LIKE_MIN;
  } else {
      p_tmp = (p_tmp <= LIKE_MIN) ? LIKE_MIN : p_tmp;
  }
                Lp += log(p_tmp);
            }
        }
    }
    *log_like = Lp;
    return (is_err) ? PLOM_ERR_LIKE: PLOM_SUCCESS;
}

canonical_original_code:
enum plom_err_code log_prob_prior(double *log_like, struct s_best *p_best, struct gsl_vector *mean, struct gsl_matrix *var, struct s_data *p_data)
{
    int i; int k; int offset;
    int is_err = 0;
    double p_tmp; double Lp;
    p_tmp=0.0, Lp=0.0;
    double back_transformed;
    for(i=0; i<p_data->p_it_all->length; i++) {
 struct s_router *p_router = p_data->routers[p_data->p_it_all->ind[i]];
        for(k=0; k<p_router->n_gp; k++) {
     offset = p_data->p_it_all->offset[i] + k;
     if(p_best->is_estimated[offset]) {
                back_transformed = (*(p_router->f_inv[k]))(gsl_vector_get(mean, offset), p_router->min[k], p_router->max[k]);
                p_tmp = (*(p_best->prior[offset]))(back_transformed, p_best->par_prior[offset][0], p_best->par_prior[offset][1]);
                if( (__builtin_isnan (p_tmp)==1) || (__builtin_isinf_sign (p_tmp)==1) || (p_tmp<0.0) ) {
      is_err =1;
      p_tmp = LIKE_MIN;
  } else {
      p_tmp = (p_tmp <= LIKE_MIN) ? LIKE_MIN : p_tmp;
  }
                Lp += log(p_tmp);
            }
        }
    }
    *log_like = Lp;
    return (is_err) ? PLOM_ERR_LIKE: PLOM_SUCCESS;
}

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

variable_types:
mean
struct gsl_vector *

variable_types:
var
struct gsl_matrix *

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

variable_types: offset int

variable_types: Lp double

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

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

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


original_code:
int metropolis_hastings(struct s_best *p_best, struct s_likelihood *p_like, double *alpha, struct s_data *p_data, struct s_calc *p_calc, gsl_matrix *var, double sd_fac, int is_mvn)
{
    double ran;
    double Lproposal_new, Lproposal_prev, Lprior_new, Lprior_prev;
    plom_err_code rc_proposal_new = log_prob_proposal(&Lproposal_new, p_best, p_best->proposed, p_best->mean, var, sd_fac, p_data, is_mvn);
    plom_err_code rc_proposal_prev = log_prob_proposal(&Lproposal_prev, p_best, p_best->mean, p_best->proposed, var, sd_fac, p_data, is_mvn);
    plom_err_code rc_prior_new = log_prob_prior(&Lprior_new, p_best, p_best->proposed, var, p_data);
    plom_err_code rc_prior_prev = log_prob_prior(&Lprior_prev, p_best, p_best->mean, var, p_data);
    if( (rc_proposal_new == PLOM_SUCCESS) && (rc_proposal_prev == PLOM_SUCCESS) && (rc_prior_new == PLOM_SUCCESS) && (rc_prior_prev == PLOM_SUCCESS) ) {
        *alpha = exp( (p_like->Llike_new - p_like->Llike_prev + Lproposal_prev - Lproposal_new + Lprior_new - Lprior_prev) );
        ran = gsl_ran_flat(p_calc->randgsl, 0.0, 1.0);
        if(ran < *alpha) {
            return 1;
        }
    } else {
        *alpha = 0.0;
        return 0;
    }
    return 0;
}

canonical_original_code:
int metropolis_hastings(struct s_best *p_best, struct s_likelihood *p_like, double *alpha, struct s_data *p_data, struct s_calc *p_calc, struct gsl_matrix *var, double sd_fac, int is_mvn)
{
    double ran;
    double Lproposal_new; double Lproposal_prev; double Lprior_new; double Lprior_prev;
    enum plom_err_code rc_proposal_new = log_prob_proposal(&Lproposal_new, p_best, p_best->proposed, p_best->mean, var, sd_fac, p_data, is_mvn);
    enum plom_err_code rc_proposal_prev = log_prob_proposal(&Lproposal_prev, p_best, p_best->mean, p_best->proposed, var, sd_fac, p_data, is_mvn);
    enum plom_err_code rc_prior_new = log_prob_prior(&Lprior_new, p_best, p_best->proposed, var, p_data);
    enum plom_err_code rc_prior_prev = log_prob_prior(&Lprior_prev, p_best, p_best->mean, var, p_data);
    if( (rc_proposal_new == PLOM_SUCCESS) && (rc_proposal_prev == PLOM_SUCCESS) && (rc_prior_new == PLOM_SUCCESS) && (rc_prior_prev == PLOM_SUCCESS) ) {
        *alpha = exp( (p_like->Llike_new - p_like->Llike_prev + Lproposal_prev - Lproposal_new + Lprior_new - Lprior_prev) );
        ran = gsl_ran_flat(p_calc->randgsl, 0.0, 1.0);
        if(ran < *alpha) {
            return 1;
        }
    } else {
        *alpha = 0.0;
        return 0;
    }
    return 0;
}

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:
alpha
double *

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

variable_types: ran double

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

return_type: int

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall normal_prior(double a1, double a2, double a3)
{
return gsl_ran_gaussian_pdf(a1 - (a3 + a2) * 0.5, (a3 - a2) * 0.25);
}

canonical_decompiled_code:
__int64 __fastcall func2(double a1, double a2, double a3)
{
return gsl_ran_gaussian_pdf(a1 - (a3 + a2) * 0.5, (a3 - a2) * 0.25);
}

original_code:
double normal_prior(double x, double min, double max)
{
    double mean = (max+min)/2.0;
    double sd = (max-min)/4.0;
    return gsl_ran_gaussian_pdf((x-mean), sd);
}

variable_types: x double

variable_types: min double

variable_types: max double

variable_types: mean double

variable_types: sd double


decompiled_code:
double __fastcall get_smallest_log_likelihood(__int64 a1)
{
int v1; // edx
int **v2; // rax
__int64 v3; // rcx
double v4; // xmm0_8

v1 = *(_DWORD *)(a1 + 172);
if ( v1 <= 0 )
{
v4 = 0.0;
}
else
{
v2 = *(int ***)(a1 + 64);
v3 = (__int64)&v2[(unsigned int)(v1 - 1) + 1];
v4 = 0.0;
do
v4 = v4 + (double)**v2++;
while ( v2 != (int **)v3 );
}
return v4 * *(double *)&LOG_LIKE_MIN;
}

original_code:
double get_smallest_log_likelihood(struct s_data *p_data)
{
  int n;
  double smallest_log_like = 0.0;
  for(n=0 ; n<p_data->nb_obs_nonan; n++) {
      smallest_log_like += p_data->data_ind[n]->n_nonan;
  }
  return smallest_log_like * LOG_LIKE_MIN;
}

variable_types: n int


original_code:
double sanitize_likelihood(double like)
{
    if ((__builtin_isinf_sign (like)==1) || (__builtin_isnan (like)==1) || (like<0.0) ) {
        return LIKE_MIN;
    } else {
        return (like <= LIKE_MIN) ? LIKE_MIN : like;
    }
}

variable_types: like double


decompiled_code:
void __fastcall clean_kalman_specific_data(__int64 a1, __int64 a2)
{
_QWORD *v2; // r12
__int64 v3; // rbx

v2 = *(_QWORD **)(a1 + 176);
if ( N_DRIFT > 0 )
{
v3 = 0LL;
do
{
clean_groups_compo(
*(_QWORD *)(v2[1] + 8 * v3),
*(unsigned int *)(*(_QWORD *)(*(_QWORD *)(a2 + 80) + 8LL * **(int **)(*(_QWORD *)(a2 + 88) + 8 * v3)) + 4LL));
++v3;
}
while ( N_DRIFT > (int)v3 );
}
free((void *)v2[1]);
v2[1] = 0LL;
gsl_matrix_free(v2[3]);
gsl_matrix_free(*v2);
gsl_matrix_free(v2[2]);
free(v2);
}

original_code:
void clean_kalman_specific_data(struct s_calc *p_calc, struct s_data *p_data)
{
    int i;
    struct s_kalman_specific_data *p = (struct s_kalman_specific_data *) p_calc->method_specific_thread_safe_data;
    for(i=0; i<N_DRIFT; i++) {
        clean_groups_compo(p->compo_groups_drift_par_proc[i], p_data->routers[ p_data->drift[i]->ind_par_Xdrift_applied ]->n_gp );
    }
    do { free( p->compo_groups_drift_par_proc ); p->compo_groups_drift_par_proc = ((void *)0); }while(0);
    gsl_matrix_free(p->FtCt);
    gsl_matrix_free(p->Ft);
    gsl_matrix_free(p->Q);
    do { free( p ); p = ((void *)0); }while(0);
}

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

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

user_defined_types: struct s_kalman_specific_data { struct gsl_matrix *Ft; struct s_group ***compo_groups_drift_par_proc; struct gsl_matrix *Q; struct gsl_matrix *FtCt; void (*eval_Q)(struct gsl_matrix *Q, double *X, struct s_par *p_par, struct s_data *p_data, struct s_calc *p_calc, struct s_kalman_specific_data *p_kalman_specific_data, double t); }

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


decompiled_code:
void __fastcall clean_kalman_update(void *ptr)
{
gsl_vector_free(*(_QWORD *)ptr);
gsl_vector_free(*((_QWORD *)ptr + 1));
gsl_vector_free(*((_QWORD *)ptr + 2));
gsl_vector_free(*((_QWORD *)ptr + 6));
gsl_matrix_free(*((_QWORD *)ptr + 7));
gsl_matrix_free(*((_QWORD *)ptr + 8));
gsl_eigen_symmv_free(*((_QWORD *)ptr + 9));
gsl_vector_free(*((_QWORD *)ptr + 10));
gsl_matrix_free(*((_QWORD *)ptr + 11));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
gsl_vector_free(*(_QWORD *)ptr);
gsl_vector_free(*((_QWORD *)ptr + 1));
gsl_vector_free(*((_QWORD *)ptr + 2));
gsl_vector_free(*((_QWORD *)ptr + 6));
gsl_matrix_free(*((_QWORD *)ptr + 7));
gsl_matrix_free(*((_QWORD *)ptr + 8));
gsl_eigen_symmv_free(*((_QWORD *)ptr + 9));
gsl_vector_free(*((_QWORD *)ptr + 10));
gsl_matrix_free(*((_QWORD *)ptr + 11));
free(ptr);
}

original_code:
void clean_kalman_update(struct s_kalman_update *p)
{
    gsl_vector_free(p->xk);
    gsl_vector_free(p->kt);
    gsl_vector_free(p->ht);
    gsl_vector_free(p->v_n_kal);
    gsl_matrix_free(p->M_symm_n_kal);
    gsl_matrix_free(p->M_symm_n_kal2);
    gsl_eigen_symmv_free(p->w_eigen_vv_nkal);
    gsl_vector_free(p->eval_nkal);
    gsl_matrix_free(p->evec_nkal);
    do { free( p ); p = ((void *)0); }while(0);
}

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

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

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


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

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

original_code:
void clean_kalman(struct s_kalman *p_kalman)
{
    clean_X(p_kalman->p_X);
    clean_best(p_kalman->p_best);
    clean_par(p_kalman->p_par);
    clean_kalman_update(p_kalman->p_kalman_update);
    clean_kalman_specific_data(p_kalman->calc[0], p_kalman->p_data);
    clean_calc(p_kalman->calc, p_kalman->p_data);
    clean_data(p_kalman->p_data);
    do { free( p_kalman ); p_kalman = ((void *)0); }while(0);
}

variable_types: struct s_kalman { 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; 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 { 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; } *p_kalman_update; } *

user_defined_types: struct s_kalman { 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; struct s_kalman_update *p_kalman_update; }

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


decompiled_code:
void __fastcall clean_mcmc_calc_data(void *ptr)
{
free(*((void **)ptr + 8));
free(*((void **)ptr + 9));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 8));
free(*((void **)ptr + 9));
free(ptr);
}

original_code:
void clean_mcmc_calc_data(struct s_mcmc_calc_data *p)
{
    do { free( p->acceptance_rates ); p->acceptance_rates = ((void *)0); }while(0);
    do { free( p->smoothed_acceptance_rates ); p->smoothed_acceptance_rates = ((void *)0); }while(0);
    do { free( p ); p = ((void *)0); }while(0);
}

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


original_code:
gsl_matrix * get_var_and_sd_fac(double *sd_fac, struct s_best *p_best, struct s_mcmc_calc_data *p, struct s_calc *p_calc, int m)
{
    if (OPTION_FULL_UPDATE) {
        if ( (m > p->m_epsilon) && (m*p->global_acceptance_rate < p->m_switch) ) {
     double ar = (p->is_smoothed_tunning) ? p->smoothed_global_acceptance_rate : p->global_acceptance_rate;
            p->epsilon *= exp(pow(p->a, (double)(m-1)) * (ar - 0.234));
        } else {
            p->epsilon = 1.0;
        }
 p->epsilon = ((p->epsilon) < (p->epsilon_max) ? (p->epsilon) : (p->epsilon_max));
 char str[255];
 snprintf(str, 255, "epsilon = %g", p->epsilon);
 print_log(str);
        *sd_fac = p->epsilon * 2.38/sqrt(p_best->n_to_be_estimated);
        if( (m * p->global_acceptance_rate) >= p->m_switch) {
     return p_best->var_sampling;
 } else {
     return p_best->var;
 }
    } else {
        *sd_fac = 1.0;
        if(p_best->n_to_be_estimated > 0) {
            if(p->has_cycled) {
                gsl_ran_shuffle(p_calc->randgsl, p_best->to_be_estimated, p_best->n_to_be_estimated, sizeof (unsigned int));
            }
        }
 return p_best->var;
    }
}

canonical_original_code:
struct gsl_matrix *get_var_and_sd_fac(double *sd_fac, struct s_best *p_best, struct s_mcmc_calc_data *p, struct s_calc *p_calc, int m)
{
    if (OPTION_FULL_UPDATE) {
        if ( (m > p->m_epsilon) && (m*p->global_acceptance_rate < p->m_switch) ) {
     double ar = (p->is_smoothed_tunning) ? p->smoothed_global_acceptance_rate : p->global_acceptance_rate;
            p->epsilon *= exp(pow(p->a, (double)(m-1)) * (ar - 0.234));
        } else {
            p->epsilon = 1.0;
        }
 p->epsilon = ((p->epsilon) < (p->epsilon_max) ? (p->epsilon) : (p->epsilon_max));
 char str[255];
 snprintf(str, 255, "epsilon = %g", p->epsilon);
 print_log(str);
        *sd_fac = p->epsilon * 2.38/sqrt(p_best->n_to_be_estimated);
        if( (m * p->global_acceptance_rate) >= p->m_switch) {
     return p_best->var_sampling;
 } else {
     return p_best->var;
 }
    } else {
        *sd_fac = 1.0;
        if(p_best->n_to_be_estimated > 0) {
            if(p->has_cycled) {
                gsl_ran_shuffle(p_calc->randgsl, p_best->to_be_estimated, p_best->n_to_be_estimated, sizeof (unsigned int));
            }
        }
 return p_best->var;
    }
}

variable_types: struct s_best { int length; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; } *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); } *

variable_types: m int

variable_types: ar double

variable_types:
str
char [255]

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

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

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

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

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 gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); }

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

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

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

user_defined_types: struct gsl_odeiv2_system { int (*function)(double t, double y[], double dydt[], void *params); int (*jacobian)(double t, double y[], double *dfdy, double dfdt[], void *params); unsigned long dimension; void *params; }

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

user_defined_types: struct gsl_odeiv2_evolve_struct { unsigned long dimension; double *y0; double *yerr; double *dydt_in; double *dydt_out; double last_step; unsigned long count; unsigned long failed_steps; struct gsl_odeiv2_driver_struct *driver; }

user_defined_types: struct gsl_interp_type { char *name; unsigned int min_size; void *(*alloc)(unsigned long size); int (*init)(void *, double xa[], double ya[], unsigned long size); int (*eval)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y); int (*eval_deriv)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_p); int (*eval_deriv2)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_pp); int (*eval_integ)(void *, double xa[], double ya[], unsigned long size, struct gsl_interp_accel *, double a, double b, double *result); void (*free)(void *); }

user_defined_types: struct gsl_odeiv2_control_type { char *name; void *(*alloc)(); int (*init)(void *state, double eps_abs, double eps_rel, double a_y, double a_dydt); int (*hadjust)(void *state, unsigned long dim, unsigned int ord, double y[], double yerr[], double yp[], double *h); int (*errlevel)(void *state, double y, double dydt, double h, unsigned long ind, double *errlev); int (*set_driver)(void *state, struct gsl_odeiv2_driver_struct *d); void (*free)(void *state); }


original_code:
void compute_acceptance_rates(struct s_best *p_best, struct s_mcmc_calc_data *p, double is_accepted, int m)
{
    if (!OPTION_FULL_UPDATE) {
        if(p_best->n_to_be_estimated > 0) {
            int mm = p_best->to_be_estimated[ p->cycle_id ];
            p->smoothed_acceptance_rates[mm] = (1.0 - p->alpha) * p->smoothed_acceptance_rates[mm] + p->alpha * is_accepted;
            p->acceptance_rates[mm] += ((is_accepted - p->acceptance_rates[mm])/ ((double) p->m_full_iteration));
        }
    }
    p->smoothed_global_acceptance_rate = (1.0 - p->alpha) * p->smoothed_global_acceptance_rate + p->alpha * is_accepted;
    p->global_acceptance_rate += ( (is_accepted - p->global_acceptance_rate) / ((double) m) );
}

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

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


decompiled_code:
__int64 __fastcall ran_proposal_sequential(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5)
{
__int64 v8; // r14
double v9; // r15
double v10; // xmm0_8
double v11; // xmm0_8
double v12; // xmm0_8
__int64 result; // rax

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

original_code:
void ran_proposal_sequential(gsl_vector *proposed, struct s_best *p_best, gsl_matrix *var, double sd_fac, struct s_calc *p_calc)
{
    int k;
    struct s_mcmc_calc_data *p = (struct s_mcmc_calc_data *) p_calc->method_specific_shared_data;
    if (p_best->n_to_be_estimated > 0) {
        k = p_best->to_be_estimated[ p->cycle_id ];
        gsl_vector_set(proposed, k, gsl_vector_get(p_best->mean, k) + gsl_ran_gaussian(p_calc->randgsl, sd_fac*sqrt(gsl_matrix_get(var, k, k))));
    }
}

canonical_original_code:
void ran_proposal_sequential(struct gsl_vector *proposed, struct s_best *p_best, struct gsl_matrix *var, double sd_fac, struct s_calc *p_calc)
{
    int k;
    struct s_mcmc_calc_data *p = (struct s_mcmc_calc_data *) p_calc->method_specific_shared_data;
    if (p_best->n_to_be_estimated > 0) {
        k = p_best->to_be_estimated[ p->cycle_id ];
        gsl_vector_set(proposed, k, gsl_vector_get(p_best->mean, k) + gsl_ran_gaussian(p_calc->randgsl, sd_fac*sqrt(gsl_matrix_get(var, k, k))));
    }
}

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

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

variable_types:
var
struct gsl_matrix *

variable_types: k int

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 s_mcmc_calc_data { double epsilon; double epsilon_max; double a; int m_switch; int m_epsilon; double global_acceptance_rate; double smoothed_global_acceptance_rate; double alpha; int is_smoothed_tunning; int n_acceptance_rates; double *acceptance_rates; double *smoothed_acceptance_rates; int has_cycled; int m_full_iteration; int cycle_id; }

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

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

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

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

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

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


decompiled_code:
__m128d __fastcall f_simplex_kalman(__int64 a1, _QWORD *a2)
{
__m128d v2; // xmm0
__int64 v4; // rax

transfer_estimated(a2[2], a1, *a2);
if ( (unsigned int)plom_check_IC_assign_theta_remainder(*(_QWORD *)(a2[2] + 8LL), *a2) )
{
v2 = (__m128d)(unsigned __int64)a2[5];
}
else
{
back_transform_theta2par(a2[3], *(_QWORD *)(a2[2] + 8LL), *(_QWORD *)(*a2 + 96LL));
linearize_and_repeat(a2[4], a2[3], *a2, *(_QWORD *)(*a2 + 112LL));
prop2Xpop_size(a2[4], *a2, *(_QWORD *)a2[1]);
theta_driftIC2Xdrift(a2[4], *(_QWORD *)(a2[2] + 8LL), *a2);
v4 = a2[4];
v2 = (__m128d)*(unsigned __int64 *)(v4 + 24);
*(double *)(v4 + 16) = v2.m128d_f64[0];
run_kalman(a2[4], a2[2], a2[3], a2[6], *a2, a2[1], &f_prediction_ode, 0LL, 0LL, 0LL, 0LL, 0LL);
}
return _mm_xor_pd(v2, (__m128d)LC0);
}

original_code:
double f_simplex_kalman(const gsl_vector *x, void *params)
{
    struct s_kalman *p = (struct s_kalman *) params;
    double log_like;
    transfer_estimated(p->p_best, x, p->p_data);
    if(plom_check_IC_assign_theta_remainder(p->p_best->mean, p->p_data)){
 log_like = p->smallest_log_like;
    } else {
 back_transform_theta2par(p->p_par, p->p_best->mean, p->p_data->p_it_all, p->p_data);
 linearize_and_repeat(p->p_X, p->p_par, p->p_data, p->p_data->p_it_par_sv);
 prop2Xpop_size(p->p_X, p->p_data, p->calc[0]);
 theta_driftIC2Xdrift(p->p_X, p->p_best->mean, p->p_data);
 p->p_X->dt = p->p_X->dt0;
 log_like = run_kalman(p->p_X, p->p_best, p->p_par, p->p_kalman_update, p->p_data, p->calc, f_prediction_ode, 0, ((void *)0), ((void *)0), ((void *)0), 0);
    }
    return - log_like;
}

canonical_original_code:
double f_simplex_kalman(struct gsl_vector *x, void *params)
{
    struct s_kalman *p = (struct s_kalman *) params;
    double log_like;
    transfer_estimated(p->p_best, x, p->p_data);
    if(plom_check_IC_assign_theta_remainder(p->p_best->mean, p->p_data)){
 log_like = p->smallest_log_like;
    } else {
 back_transform_theta2par(p->p_par, p->p_best->mean, p->p_data->p_it_all, p->p_data);
 linearize_and_repeat(p->p_X, p->p_par, p->p_data, p->p_data->p_it_par_sv);
 prop2Xpop_size(p->p_X, p->p_data, p->calc[0]);
 theta_driftIC2Xdrift(p->p_X, p->p_best->mean, p->p_data);
 p->p_X->dt = p->p_X->dt0;
 log_like = run_kalman(p->p_X, p->p_best, p->p_par, p->p_kalman_update, p->p_data, p->calc, f_prediction_ode, 0, ((void *)0), ((void *)0), ((void *)0), 0);
    }
    return - log_like;
}

variable_types:
params
void *

user_defined_types: struct s_kalman { 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; struct s_kalman_update *p_kalman_update; }

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

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

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

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 gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; }

user_defined_types: struct gsl_eigen_symmv_workspace { unsigned long size; double *d; double *sd; double *gc; double *gs; }

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

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

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

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

user_defined_types: struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); }

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

user_defined_types: struct gsl_odeiv2_system { int (*function)(double t, double y[], double dydt[], void *params); int (*jacobian)(double t, double y[], double *dfdy, double dfdt[], void *params); unsigned long dimension; void *params; }


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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

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

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

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

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


rmvnorm

decompiled_code:
__int64 __fastcall rmvnorm(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v8; // r14
__int64 i; // rbx

v8 = gsl_matrix_alloc(a2, a2);
gsl_matrix_memcpy(v8, a4);
gsl_linalg_cholesky_decomp(v8);
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; gsl_vector_set(a5, i++) )
gsl_ran_ugaussian(a1);
}
gsl_blas_dtrmv(122LL, 111LL, 131LL, v8, a5);
gsl_vector_add(a5, a3);
gsl_matrix_free(v8);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v8; // r14
__int64 i; // rbx

v8 = gsl_matrix_alloc(a2, a2);
gsl_matrix_memcpy(v8, a4);
gsl_linalg_cholesky_decomp(v8);
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; gsl_vector_set(a5, i++) )
gsl_ran_ugaussian(a1);
}
gsl_blas_dtrmv(122LL, 111LL, 131LL, v8, a5);
gsl_vector_add(a5, a3);
gsl_matrix_free(v8);
return 0LL;
}

original_code:
int rmvnorm(const gsl_rng *r, const int n, const gsl_vector *mean, const gsl_matrix *var, gsl_vector *result)
{
    int k;
    gsl_matrix *work = gsl_matrix_alloc(n,n);
    gsl_matrix_memcpy(work,var);
    gsl_linalg_cholesky_decomp(work);
    for(k=0; k<n; k++)
        gsl_vector_set( result, k, gsl_ran_ugaussian(r) );
    gsl_blas_dtrmv(CblasLower, CblasNoTrans, CblasNonUnit, work, result);
    gsl_vector_add(result,mean);
    gsl_matrix_free(work);
    return 0;
}

canonical_original_code:
int rmvnorm(struct gsl_rng *r, int n, struct gsl_vector *mean, struct gsl_matrix *var, struct gsl_vector *result)
{
    int k;
    struct gsl_matrix *work = gsl_matrix_alloc(n,n);
    gsl_matrix_memcpy(work,var);
    gsl_linalg_cholesky_decomp(work);
    for(k=0; k<n; k++)
        gsl_vector_set( result, k, gsl_ran_ugaussian(r) );
    gsl_blas_dtrmv(CblasLower, CblasNoTrans, CblasNonUnit, work, result);
    gsl_vector_add(result,mean);
    gsl_matrix_free(work);
    return 0;
}

variable_types: struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *

variable_types: n int

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

variable_types:
result
struct gsl_vector *

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

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


decompiled_code:
__int64 __fastcall plom_rmvnorm(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5)
{
int v5; // ebx
__int64 v6; // rax
__int64 v7; // r15
__int64 v8; // r13
__int64 i; // rbp
__int64 j; // rbx
double v11; // xmm1_8
__int64 v12; // rbp
__int64 v13; // rbx
__int64 v14; // rbx
int v19; // [rsp+24h] [rbp-44h]
__int64 v20; // [rsp+28h] [rbp-40h]

v5 = *(_DWORD *)(a2 + 32);
v19 = v5;
v20 = v5;
v6 = gsl_matrix_alloc(v5, v5);
v7 = v6;
if ( v5 <= 0 )
{
if ( (unsigned int)gsl_linalg_cholesky_decomp(v6) != 1 )
{
v12 = gsl_vector_alloc(v5);
LABEL_17:
gsl_blas_dtrmv(122LL, 111LL, 131LL, v7, v12);
gsl_vector_memcpy(a1, *(_QWORD *)(a2 + 8));
goto LABEL_12;
}
}
else
{
v8 = (unsigned int)v5;
for ( i = 0LL; i != v8; ++i )
{
for ( j = 0LL; j != v8; ++j )
{
v11 = gsl_matrix_get(
a3,
*(unsigned int *)(*(_QWORD *)(a2 + 40) + 4 * i),
*(unsigned int *)(*(_QWORD *)(a2 + 40) + 4 * j));
gsl_matrix_set(v7, i, j, a5 * a5 * v11);
}
}
if ( (unsigned int)gsl_linalg_cholesky_decomp(v7) != 1 )
{
v12 = gsl_vector_alloc(v20);
goto LABEL_8;
}
}
print_err("Covariance matrix is not positive definite");
v12 = gsl_vector_alloc(v20);
if ( v19 <= 0 )
goto LABEL_17;
LABEL_8:
v13 = 0LL;
do
{
gsl_ran_ugaussian(*(_QWORD *)(a4 + 8));
gsl_vector_set(v12, v13++);
}
while ( v19 != v13 );
gsl_blas_dtrmv(122LL, 111LL, 131LL, v7, v12);
gsl_vector_memcpy(a1, *(_QWORD *)(a2 + 8));
v14 = 0LL;
do
{
gsl_vector_get(*(_QWORD *)(a2 + 8), *(unsigned int *)(*(_QWORD *)(a2 + 40) + 4 * v14));
gsl_vector_get(v12, v14);
gsl_vector_set(a1, *(unsigned int *)(*(_QWORD *)(a2 + 40) + 4 * v14++));
}
while ( v19 != v14 );
LABEL_12:
gsl_matrix_free(v7);
return gsl_vector_free(v12);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double a5)
{
int v5; // ebx
__int64 v6; // rax
__int64 v7; // r15
__int64 v8; // r13
__int64 i; // rbp
__int64 j; // rbx
double v11; // xmm1_8
__int64 v12; // rbp
__int64 v13; // rbx
__int64 v14; // rbx
int v19; // [rsp+24h] [rbp-44h]
__int64 v20; // [rsp+28h] [rbp-40h]

v5 = *(_DWORD *)(a2 + 32);
v19 = v5;
v20 = v5;
v6 = gsl_matrix_alloc(v5, v5);
v7 = v6;
if ( v5 <= 0 )
{
if ( (unsigned int)gsl_linalg_cholesky_decomp(v6) != 1 )
{
v12 = gsl_vector_alloc(v5);
LABEL_17:
gsl_blas_dtrmv(122LL, 111LL, 131LL, v7, v12);
gsl_vector_memcpy(a1, *(_QWORD *)(a2 + 8));
goto LABEL_12;
}
}
else
{
v8 = (unsigned int)v5;
for ( i = 0LL; i != v8; ++i )
{
for ( j = 0LL; j != v8; ++j )
{
v11 = gsl_matrix_get(
a3,
*(unsigned int *)(*(_QWORD *)(a2 + 40) + 4 * i),
*(unsigned int *)(*(_QWORD *)(a2 + 40) + 4 * j));
gsl_matrix_set(v7, i, j, a5 * a5 * v11);
}
}
if ( (unsigned int)gsl_linalg_cholesky_decomp(v7) != 1 )
{
v12 = gsl_vector_alloc(v20);
goto LABEL_8;
}
}
print_err("Covariance matrix is not positive definite");
v12 = gsl_vector_alloc(v20);
if ( v19 <= 0 )
goto LABEL_17;
LABEL_8:
v13 = 0LL;
do
{
gsl_ran_ugaussian(*(_QWORD *)(a4 + 8));
gsl_vector_set(v12, v13++);
}
while ( v19 != v13 );
gsl_blas_dtrmv(122LL, 111LL, 131LL, v7, v12);
gsl_vector_memcpy(a1, *(_QWORD *)(a2 + 8));
v14 = 0LL;
do
{
gsl_vector_get(*(_QWORD *)(a2 + 8), *(unsigned int *)(*(_QWORD *)(a2 + 40) + 4 * v14));
gsl_vector_get(v12, v14);
gsl_vector_set(a1, *(unsigned int *)(*(_QWORD *)(a2 + 40) + 4 * v14++));
}
while ( v19 != v14 );
LABEL_12:
gsl_matrix_free(v7);
return gsl_vector_free(v12);
}

original_code:
void plom_rmvnorm(gsl_vector *proposed, struct s_best *p_best, gsl_matrix *var, double sd_fac, struct s_calc *p_calc)
{
    int n = p_best->n_to_be_estimated;
    int i,k;
    gsl_matrix *work = gsl_matrix_alloc(n,n);
    double value;
    for(i=0; i<n; i++) {
        for(k=0; k<n; k++) {
            value = gsl_matrix_get(var, p_best->to_be_estimated[i], p_best->to_be_estimated[k]);
            value *= sd_fac*sd_fac;
            gsl_matrix_set(work, i, k, value);
        }
    }
    int status = gsl_linalg_cholesky_decomp(work);
    if(status == GSL_EDOM) {
        print_err("Covariance matrix is not positive definite");
    }
    gsl_vector *xwork = gsl_vector_alloc(n);
    for(k=0; k<n; k++){
        gsl_vector_set(xwork, k, gsl_ran_ugaussian(p_calc->randgsl) );
    }
    gsl_blas_dtrmv(CblasLower, CblasNoTrans, CblasNonUnit, work, xwork);
    gsl_vector_memcpy(proposed, p_best->mean);
    for (k=0; k<n; k++) {
        value = gsl_vector_get(p_best->mean, p_best->to_be_estimated[k]);
        value += gsl_vector_get(xwork, k);
        gsl_vector_set(proposed, p_best->to_be_estimated[k], value);
    }
    gsl_matrix_free(work);
    gsl_vector_free(xwork);
}

canonical_original_code:
void plom_rmvnorm(struct gsl_vector *proposed, struct s_best *p_best, struct gsl_matrix *var, double sd_fac, struct s_calc *p_calc)
{
    int n = p_best->n_to_be_estimated;
    int i; int k;
    struct gsl_matrix *work = gsl_matrix_alloc(n,n);
    double value;
    for(i=0; i<n; i++) {
        for(k=0; k<n; k++) {
            value = gsl_matrix_get(var, p_best->to_be_estimated[i], p_best->to_be_estimated[k]);
            value *= sd_fac*sd_fac;
            gsl_matrix_set(work, i, k, value);
        }
    }
    int status = gsl_linalg_cholesky_decomp(work);
    if(status == GSL_EDOM) {
        print_err("Covariance matrix is not positive definite");
    }
    struct gsl_vector *xwork = gsl_vector_alloc(n);
    for(k=0; k<n; k++){
        gsl_vector_set(xwork, k, gsl_ran_ugaussian(p_calc->randgsl) );
    }
    gsl_blas_dtrmv(CblasLower, CblasNoTrans, CblasNonUnit, work, xwork);
    gsl_vector_memcpy(proposed, p_best->mean);
    for (k=0; k<n; k++) {
        value = gsl_vector_get(p_best->mean, p_best->to_be_estimated[k]);
        value += gsl_vector_get(xwork, k);
        gsl_vector_set(proposed, p_best->to_be_estimated[k], value);
    }
    gsl_matrix_free(work);
    gsl_vector_free(xwork);
}

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

variable_types: value double

variable_types: status int

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_block_struct { unsigned long size; double *data; }

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

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

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

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

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


original_code:
void eval_var_emp(struct s_best *p_best, double m)
{
    int i, k;
    double *x_bar = p_best->mean_sampling;
    gsl_vector *x = p_best->mean;
    gsl_matrix *cov = p_best->var_sampling;
    double val;
    for (i=0; i < p_best->length; i++) {
        for (k=0; k <= i; k++) {
            val = ((m - 1.0) / m) * (gsl_vector_get(x, i) - x_bar[i]) * (gsl_vector_get(x, k) - x_bar[k]);
            gsl_matrix_set(cov, i, k, (((m-1.0)*gsl_matrix_get(cov, i, k)) + val ) / m);
        }
    }
    for (i=0; i < p_best->length; i++) {
        for (k=0; k < i; k++) {
            val = gsl_matrix_get(cov, i, k);
            gsl_matrix_set(cov, k, i, val);
        }
    }
    for (i=0; i < p_best->length; i++) {
        x_bar[i] += (gsl_vector_get(x, i) - x_bar[i]) / m;
    }
}

canonical_original_code:
void eval_var_emp(struct s_best *p_best, double m)
{
    int i; int k;
    double *x_bar = p_best->mean_sampling;
    struct gsl_vector *x = p_best->mean;
    struct gsl_matrix *cov = p_best->var_sampling;
    double val;
    for (i=0; i < p_best->length; i++) {
        for (k=0; k <= i; k++) {
            val = ((m - 1.0) / m) * (gsl_vector_get(x, i) - x_bar[i]) * (gsl_vector_get(x, k) - x_bar[k]);
            gsl_matrix_set(cov, i, k, (((m-1.0)*gsl_matrix_get(cov, i, k)) + val ) / m);
        }
    }
    for (i=0; i < p_best->length; i++) {
        for (k=0; k < i; k++) {
            val = gsl_matrix_get(cov, i, k);
            gsl_matrix_set(cov, k, i, val);
        }
    }
    for (i=0; i < p_best->length; i++) {
        x_bar[i] += (gsl_vector_get(x, i) - x_bar[i]) / m;
    }
}

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

variable_types: val double