daemonize

decompiled_code:
void __fastcall daemonize(char *src)
{
struct passwd *v1; // rbx
__pid_t v2; // eax
__pid_t v3; // eax
__pid_t v4; // ebp
int *v5; // rbx
char *v6; // rax
int *v7; // rbx
char *v8; // rax
__pid_t v9; // eax
int *v10; // rbx
char *v11; // rax
int *v12; // rbx
char *v13; // rax
int *v14; // rbx
char *v15; // rax
int *v16; // rbx
char *v17; // rax
struct sched_param param; // [rsp+Ch] [rbp-FCh] BYREF
char s[112]; // [rsp+10h] [rbp-F8h] BYREF
char filename[136]; // [rsp+80h] [rbp-88h] BYREF

strcpy(gdaemon_name, src);
syslog(5, "Starting daemonization for %s", src);
daemon_sig_quit = 0;
daemon_sig_usr1 = 0;
daemon_sig_usr2 = 0;
if ( getppid() == 1 )
return;
sprintf(lockfile, "/var/lock/%s", src);
if ( lockfile[0] && open(lockfile, 194, 416LL) < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(
3,
"Unable to create lock file %s, code=%d (%s) Check if daemon already exists!",
lockfile,
(unsigned int)*v5,
v6);
exit(1);
}
if ( !getuid() || !geteuid() )
{
v1 = getpwnam("root");
if ( v1 )
{
syslog(5, "Setting user to root");
setuid(v1->pw_uid);
}
}
signal(17, daemon_sig_handler);
signal(12, daemon_sig_handler);
signal(14, daemon_sig_handler);
signal(2, daemon_sig_handler);
signal(3, daemon_sig_handler);
signal(15, daemon_sig_handler);
signal(10, fork_sig_handler);
v2 = fork();
if ( v2 < 0 )
goto LABEL_24;
if ( v2 )
goto LABEL_27;
v3 = fork();
if ( v3 < 0 )
{
LABEL_24:
v7 = _errno_location();
v8 = strerror(*v7);
syslog(3, "Unable to fork daemon, code=%d (%s)", (unsigned int)*v7, v8);
goto LABEL_25;
}
if ( v3 )
{
v9 = getppid();
kill(v9, 10);
LABEL_27:
alarm(2u);
pause();
exit(1);
}
v4 = getppid();
signal(17, 0LL);
signal(20, (void (*)(int))((char *)fork_sig_handler + 1));
signal(22, (void (*)(int))((char *)fork_sig_handler + 1));
signal(21, (void (*)(int))((char *)fork_sig_handler + 1));
signal(1, (void (*)(int))((char *)fork_sig_handler + 1));
signal(10, daemon_sig_handler);
umask(0);
if ( setsid() < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
syslog(3, "Unable to create new session, code=%d (%s)", (unsigned int)*v14, v15);
goto LABEL_25;
}
if ( chdir("/") < 0 )
{
v16 = _errno_location();
v17 = strerror(*v16);
syslog(3, "Unable to change directory, code=%d (%s)", (unsigned int)*v16, v17);
LABEL_25:
exit(1);
}
sprintf(s, "/var/log/daemon/%s-output", src);
sprintf(filename, "/var/log/daemon/%s-error", src);
if ( !fopen(s, "w") || !fopen(filename, "w") )
{
v10 = _errno_location();
v11 = strerror(*v10);
syslog(3, "Unable to create log files, code=%d (%s)", (unsigned int)*v10, v11);
goto LABEL_25;
}
if ( !freopen(s, "w", stdout) || !freopen(filename, "w", stderr) )
{
v12 = _errno_location();
v13 = strerror(*v12);
syslog(3, "Unable to stream output, code=%d (%s)", (unsigned int)*v12, v13);
goto LABEL_25;
}
kill(v4, 10);
param.__sched_priority = 49;
if ( sched_setscheduler(0, 1, &param) == -1 )
{
fwrite("sched_setscheduler Failed!\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
if ( mlockall(3) == -1 )
{
fwrite("mlockall Failed!\n", 1uLL, 0x11uLL, stderr);
exit(1);
}
syslog(5, "Daemonization finished - Process Beginning");
}

canonical_decompiled_code:
void __fastcall func2(char *src)
{
struct passwd *v1; // rbx
__pid_t v2; // eax
__pid_t v3; // eax
__pid_t v4; // ebp
int *v5; // rbx
char *v6; // rax
int *v7; // rbx
char *v8; // rax
__pid_t v9; // eax
int *v10; // rbx
char *v11; // rax
int *v12; // rbx
char *v13; // rax
int *v14; // rbx
char *v15; // rax
int *v16; // rbx
char *v17; // rax
struct sched_param param; // [rsp+Ch] [rbp-FCh] BYREF
char s[112]; // [rsp+10h] [rbp-F8h] BYREF
char filename[136]; // [rsp+80h] [rbp-88h] BYREF

strcpy(gdaemon_name, src);
syslog(5, "Starting daemonization for %s", src);
daemon_sig_quit = 0;
daemon_sig_usr1 = 0;
daemon_sig_usr2 = 0;
if ( getppid() == 1 )
return;
sprintf(lockfile, "/var/lock/%s", src);
if ( lockfile[0] && open(lockfile, 194, 416LL) < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(
3,
"Unable to create lock file %s, code=%d (%s) Check if daemon already exists!",
lockfile,
(unsigned int)*v5,
v6);
exit(1);
}
if ( !getuid() || !geteuid() )
{
v1 = getpwnam("root");
if ( v1 )
{
syslog(5, "Setting user to root");
setuid(v1->pw_uid);
}
}
signal(17, daemon_sig_handler);
signal(12, daemon_sig_handler);
signal(14, daemon_sig_handler);
signal(2, daemon_sig_handler);
signal(3, daemon_sig_handler);
signal(15, daemon_sig_handler);
signal(10, fork_sig_handler);
v2 = fork();
if ( v2 < 0 )
goto LABEL_24;
if ( v2 )
goto LABEL_27;
v3 = fork();
if ( v3 < 0 )
{
LABEL_24:
v7 = _errno_location();
v8 = strerror(*v7);
syslog(3, "Unable to fork daemon, code=%d (%s)", (unsigned int)*v7, v8);
goto LABEL_25;
}
if ( v3 )
{
v9 = getppid();
kill(v9, 10);
LABEL_27:
alarm(2u);
pause();
exit(1);
}
v4 = getppid();
signal(17, 0LL);
signal(20, (void (*)(int))((char *)fork_sig_handler + 1));
signal(22, (void (*)(int))((char *)fork_sig_handler + 1));
signal(21, (void (*)(int))((char *)fork_sig_handler + 1));
signal(1, (void (*)(int))((char *)fork_sig_handler + 1));
signal(10, daemon_sig_handler);
umask(0);
if ( setsid() < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
syslog(3, "Unable to create new session, code=%d (%s)", (unsigned int)*v14, v15);
goto LABEL_25;
}
if ( chdir("/") < 0 )
{
v16 = _errno_location();
v17 = strerror(*v16);
syslog(3, "Unable to change directory, code=%d (%s)", (unsigned int)*v16, v17);
LABEL_25:
exit(1);
}
sprintf(s, "/var/log/daemon/%s-output", src);
sprintf(filename, "/var/log/daemon/%s-error", src);
if ( !fopen(s, "w") || !fopen(filename, "w") )
{
v10 = _errno_location();
v11 = strerror(*v10);
syslog(3, "Unable to create log files, code=%d (%s)", (unsigned int)*v10, v11);
goto LABEL_25;
}
if ( !freopen(s, "w", stdout) || !freopen(filename, "w", stderr) )
{
v12 = _errno_location();
v13 = strerror(*v12);
syslog(3, "Unable to stream output, code=%d (%s)", (unsigned int)*v12, v13);
goto LABEL_25;
}
kill(v4, 10);
param.__sched_priority = 49;
if ( sched_setscheduler(0, 1, &param) == -1 )
{
fwrite("sched_setscheduler Failed!\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
if ( mlockall(3) == -1 )
{
fwrite("mlockall Failed!\n", 1uLL, 0x11uLL, stderr);
exit(1);
}
syslog(5, "Daemonization finished - Process Beginning");
}

original_code:
void daemonize(const char *daemon_name)
{
    char pbuff[100];
    sprintf(gdaemon_name, "%s", daemon_name);
    syslog( 5, "Starting daemonization for %s", daemon_name );
    daemon_sig_quit = 0;
    daemon_sig_usr1 = 0;
    daemon_sig_usr2 = 0;
    pid_t pid, child, sid, parent;
    int lfp = -1;
    if( getppid() == 1 ) return;
    sprintf(lockfile, "/var/lock/%s", daemon_name);
    if( lockfile && lockfile[0] )
    {
        lfp = open(lockfile,02|0100|0200,0640);
        if( lfp < 0 )
        {
            syslog( 3, "Unable to create lock file %s, code=%d (%s)"
                             "  Check if daemon already exists!",
                    lockfile, (*__errno_location ()), strerror((*__errno_location ())) );
            exit( 1 );
        }
    }
    if( getuid()==0 || geteuid()==0 )
    {
        struct passwd *pw = getpwnam("root");
        if( pw )
        {
            syslog( 5, "Setting user to " "root" );
            setuid( pw->pw_uid );
        }
    }
    signal( 17, daemon_sig_handler );
    signal( 12, daemon_sig_handler );
    signal( 14, daemon_sig_handler );
    signal( 2, daemon_sig_handler );
    signal( 3, daemon_sig_handler );
    signal( 15, daemon_sig_handler );
    signal( 10, fork_sig_handler );
    child = fork();
    if( child<0 )
    {
        syslog( 3, "Unable to fork daemon, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit( 1 );
    }
    if( child>0 )
    {
        alarm(2);
        pause();
        exit( 1 );
    }
    pid = fork();
    if( pid<0 )
    {
        syslog( 3, "Unable to fork daemon, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit( 1 );
    }
    if( pid>0 )
    {
        parent = getppid();
        kill( parent, 10 );
        alarm(2);
        pause();
        exit( 1 );
    }
    parent = getppid();
    signal( 17, ((__sighandler_t) 0) );
    signal( 20, ((__sighandler_t) 1) );
    signal( 22, ((__sighandler_t) 1) );
    signal( 21, ((__sighandler_t) 1) );
    signal( 1, ((__sighandler_t) 1) );
    signal( 10, daemon_sig_handler );
    umask(0);
    sid = setsid();
    if( sid<0 )
    {
        syslog( 3, "Unable to create new session, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit( 1 );
    }
    if( (chdir("/")) < 0 )
    {
        syslog( 3, "Unable to change directory, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit( 1 );
    }
    char outfile[100];
    char errfile[100];
    sprintf(outfile, "/var/log/daemon/%s-output", daemon_name);
    sprintf(errfile, "/var/log/daemon/%s-error", daemon_name);
    if( !fopen( outfile, "w" ) ||
            !fopen( errfile, "w" ) )
    {
        syslog( 3, "Unable to create log files, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit(1);
    }
    if( !freopen( outfile, "w", stdout ) ||
            !freopen( errfile, "w", stderr ) )
    {
        syslog( 3, "Unable to stream output, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit( 1 );
    }
    kill( parent, 10 );
    struct sched_param param;
    param.sched_priority = (49);
    if( sched_setscheduler(0, 1, &param) == -1 )
    {
        fprintf(stderr, "sched_setscheduler Failed!\n");
        exit( 1 );
    }
    if(mlockall(1|2) == -1)
    {
        fprintf(stderr, "mlockall Failed!\n");
        exit( 1 );
    }
    stack_prefault();
    syslog( 5, "Daemonization finished - Process Beginning" );
}

canonical_original_code:
void daemonize(char *daemon_name)
{
    char pbuff[100];
    sprintf(gdaemon_name, "%s", daemon_name);
    syslog( 5, "Starting daemonization for %s", daemon_name );
    daemon_sig_quit = 0;
    daemon_sig_usr1 = 0;
    daemon_sig_usr2 = 0;
    int pid; int child; int sid; int parent;
    int lfp = -1;
    if( getppid() == 1 ) return;
    sprintf(lockfile, "/var/lock/%s", daemon_name);
    if( lockfile && lockfile[0] )
    {
        lfp = open(lockfile,02|0100|0200,0640);
        if( lfp < 0 )
        {
            syslog( 3, "Unable to create lock file %s, code=%d (%s)"
                             "  Check if daemon already exists!",
                    lockfile, (*__errno_location ()), strerror((*__errno_location ())) );
            exit( 1 );
        }
    }
    if( getuid()==0 || geteuid()==0 )
    {
        struct passwd *pw = getpwnam("root");
        if( pw )
        {
            syslog( 5, "Setting user to " "root" );
            setuid( pw->pw_uid );
        }
    }
    signal( 17, daemon_sig_handler );
    signal( 12, daemon_sig_handler );
    signal( 14, daemon_sig_handler );
    signal( 2, daemon_sig_handler );
    signal( 3, daemon_sig_handler );
    signal( 15, daemon_sig_handler );
    signal( 10, fork_sig_handler );
    child = fork();
    if( child<0 )
    {
        syslog( 3, "Unable to fork daemon, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit( 1 );
    }
    if( child>0 )
    {
        alarm(2);
        pause();
        exit( 1 );
    }
    pid = fork();
    if( pid<0 )
    {
        syslog( 3, "Unable to fork daemon, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit( 1 );
    }
    if( pid>0 )
    {
        parent = getppid();
        kill( parent, 10 );
        alarm(2);
        pause();
        exit( 1 );
    }
    parent = getppid();
    signal( 17, ((void (*)(int)) 0) );
    signal( 20, ((void (*)(int)) 1) );
    signal( 22, ((void (*)(int)) 1) );
    signal( 21, ((void (*)(int)) 1) );
    signal( 1, ((void (*)(int)) 1) );
    signal( 10, daemon_sig_handler );
    umask(0);
    sid = setsid();
    if( sid<0 )
    {
        syslog( 3, "Unable to create new session, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit( 1 );
    }
    if( (chdir("/")) < 0 )
    {
        syslog( 3, "Unable to change directory, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit( 1 );
    }
    char outfile[100];
    char errfile[100];
    sprintf(outfile, "/var/log/daemon/%s-output", daemon_name);
    sprintf(errfile, "/var/log/daemon/%s-error", daemon_name);
    if( !fopen( outfile, "w" ) ||
            !fopen( errfile, "w" ) )
    {
        syslog( 3, "Unable to create log files, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit(1);
    }
    if( !freopen( outfile, "w", stdout ) ||
            !freopen( errfile, "w", stderr ) )
    {
        syslog( 3, "Unable to stream output, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit( 1 );
    }
    kill( parent, 10 );
    struct sched_param param;
    param.sched_priority = (49);
    if( sched_setscheduler(0, 1, &param) == -1 )
    {
        fprintf(stderr, "sched_setscheduler Failed!\n");
        exit( 1 );
    }
    if(mlockall(1|2) == -1)
    {
        fprintf(stderr, "mlockall Failed!\n");
        exit( 1 );
    }
    stack_prefault();
    syslog( 5, "Daemonization finished - Process Beginning" );
}

variable_types:
pbuff
char [100]

variable_types: pid int

variable_types: child int

variable_types: sid int

variable_types: parent int

variable_types: lfp int

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types:
outfile
char [100]

variable_types:
errfile
char [100]

variable_types: struct sched_param { int sched_priority; }


repo: saulrh/Liberty-Daemon

decompiled_code:
void daemon_close()
{
remove(lockfile);
fclose(stdout);
fclose(stderr);
syslog(5, "Terminated process %s gracefully", gdaemon_name);
closelog();
}

canonical_decompiled_code:
void func3()
{
remove(lockfile);
fclose(stdout);
fclose(stderr);
syslog(5, "Terminated process %s gracefully", gdaemon_name);
closelog();
}

original_code:
void daemon_close()
{
    remove( lockfile );
    fclose( stdout );
    fclose( stderr );
    char buff[100];
    syslog( 5, "Terminated process %s gracefully", gdaemon_name );
    closelog();
}

variable_types:
buff
char [100]

return_type: void


repo: sballesteros/ssm

decompiled_code:
__int64 __fastcall ssm_zmq_send_par(__int64 a1, _QWORD *a2, unsigned int a3)
{
return zmq_send(a1, a2[2], 8LL * *a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2, unsigned int a3)
{
return zmq_send(a1, a2[2], 8LL * *a2, a3);
}

original_code:
void ssm_zmq_send_par(void *socket, ssm_par_t *par, int zmq_options)
{
    zmq_send(socket, par->data, par->size * sizeof (double), zmq_options);
}

canonical_original_code:
void ssm_zmq_send_par(void *socket, struct gsl_vector *par, int zmq_options)
{
    zmq_send(socket, par->data, par->size * sizeof (double), zmq_options);
}

variable_types:
socket
void *

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

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


decompiled_code:
__int64 __fastcall ssm_zmq_recv_par(_QWORD *a1, __int64 a2)
{
return zmq_recv(a2, a1[2], 8LL * *a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2)
{
return zmq_recv(a2, a1[2], 8LL * *a1, 0LL);
}

original_code:
void ssm_zmq_recv_par(ssm_par_t *par, void *socket)
{
    zmq_recv(socket, par->data, par->size * sizeof (double), 0);
}

canonical_original_code:
void ssm_zmq_recv_par(struct gsl_vector *par, void *socket)
{
    zmq_recv(socket, par->data, par->size * sizeof (double), 0);
}

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


decompiled_code:
__int64 __fastcall ssm_zmq_send_X(__int64 a1, int *a2, unsigned int a3)
{
zmq_send(a1, a2 + 4, 8LL, 2LL);
return zmq_send(a1, *((_QWORD *)a2 + 1), 8LL * *a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int *a2, unsigned int a3)
{
zmq_send(a1, a2 + 4, 8LL, 2LL);
return zmq_send(a1, *((_QWORD *)a2 + 1), 8LL * *a2, a3);
}

original_code:
void ssm_zmq_send_X(void *socket, ssm_X_t *X, int zmq_options)
{
    zmq_send(socket, &(X->dt), sizeof (double), 2);
    zmq_send(socket, X->proj, X->length * sizeof (double), zmq_options);
}

canonical_original_code:
void ssm_zmq_send_X(void *socket, struct ssm_X_t *X, int zmq_options)
{
    zmq_send(socket, &(X->dt), sizeof (double), 2);
    zmq_send(socket, X->proj, X->length * sizeof (double), zmq_options);
}

variable_types: struct ssm_X_t { int length; double *proj; double dt; double dt0; } *


decompiled_code:
__int64 __fastcall ssm_zmq_recv_X(int *a1, __int64 a2)
{
zmq_recv(a2, a1 + 4, 8LL, 0LL);
return zmq_recv(a2, *((_QWORD *)a1 + 1), 8LL * *a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, __int64 a2)
{
zmq_recv(a2, a1 + 4, 8LL, 0LL);
return zmq_recv(a2, *((_QWORD *)a1 + 1), 8LL * *a1, 0LL);
}

original_code:
void ssm_zmq_recv_X(ssm_X_t *X, void *socket)
{
    zmq_recv(socket, &(X->dt), sizeof (double), 0);
    zmq_recv(socket, X->proj, X->length * sizeof (double), 0);
}

canonical_original_code:
void ssm_zmq_recv_X(struct ssm_X_t *X, void *socket)
{
    zmq_recv(socket, &(X->dt), sizeof (double), 0);
    zmq_recv(socket, X->proj, X->length * sizeof (double), 0);
}

user_defined_types: struct ssm_X_t { int length; double *proj; double dt; double dt0; }


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

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

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

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

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

variable_types:
tab
double **

variable_types: n int

variable_types: i int


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

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

variable_types:
tab
double ***

variable_types: j int


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

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

variable_types:
tab
double ****

variable_types: k int


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

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


decompiled_code:
void ssm_f_id()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
double ssm_f_id(double x)
{
    return x;
}

canonical_original_code:
double ssm_f_id(double x)
{
    return x;
}

variable_types: x double

return_type: double


decompiled_code:
void __fastcall ssm_f_log(double a1)
{
log(fmax(a1, 1.0e-17));
}

canonical_decompiled_code:
void __fastcall func1(double a1)
{
log(fmax(a1, 1.0e-17));
}

original_code:
double ssm_f_log(double x)
{
    double safe = ( x > 1e-17 ) ? x : 1e-17;
    return log(safe);
}

variable_types: safe double


decompiled_code:
// attributes: thunk
double ssm_f_inv_log(double x)
{
return exp(x);
}

canonical_decompiled_code:
double func2(double x)
{
return exp(x);
}


original_code:
double ssm_f_logit(double x)
{
    double safe = ( x > 1e-17 ) ? x : 1e-17;
    safe = (safe < 0.999999999 ) ? safe : 0.999999999;
    return log(safe/(1.0-safe));
}


decompiled_code:
void __fastcall ssm_f_logit_ab(double a1, double a2, double a3)
{
double v3; // xmm3_8

if ( a2 != a3 )
{
v3 = (a1 - a2) / (a3 - a1);
if ( v3 < 1.0e-17 )
log(1.0e-17);
else
log(fmin(1.0e17, v3));
}
}

canonical_decompiled_code:
void __fastcall func5(double a1, double a2, double a3)
{
double v3; // xmm3_8

if ( a2 != a3 )
{
v3 = (a1 - a2) / (a3 - a1);
if ( v3 < 1.0e-17 )
log(1.0e-17);
else
log(fmin(1.0e17, v3));
}
}

original_code:
double ssm_f_logit_ab(double x, double a, double b)
{
    if (a == b)
        return x;
    else{
        double ratio = (x-a)/(b-x);
        if(ratio < 1e-17){
            ratio = 1e-17;
        } else if(ratio > (1.0/1e-17)) {
            ratio = 1.0/1e-17;
        }
        return log(ratio);
    }
}

variable_types: a double

variable_types: b double

variable_types: ratio double


decompiled_code:
double __fastcall ssm_f_inv_logit_ab(double result, double a2, double a3)
{
double v3; // xmm3_8
double v4; // [rsp+0h] [rbp-28h]
double v5; // [rsp+0h] [rbp-28h]

v3 = result;
if ( a2 != a3 )
{
if ( result < 0.0 )
{
v5 = exp(result);
result = (a3 * v5 + a2) / (exp(v3) + 1.0);
}
else
{
v4 = exp(COERCE_DOUBLE(*(_QWORD *)&result ^ LC5));
result = (a2 * v4 + a3) / (exp(COERCE_DOUBLE(*(_QWORD *)&v3 ^ LC5)) + 1.0);
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func6(double result, double a2, double a3)
{
double v3; // xmm3_8
double v4; // [rsp+0h] [rbp-28h]
double v5; // [rsp+0h] [rbp-28h]

v3 = result;
if ( a2 != a3 )
{
if ( result < 0.0 )
{
v5 = exp(result);
result = (a3 * v5 + a2) / (exp(v3) + 1.0);
}
else
{
v4 = exp(COERCE_DOUBLE(*(_QWORD *)&result ^ LC5));
result = (a2 * v4 + a3) / (exp(COERCE_DOUBLE(*(_QWORD *)&v3 ^ LC5)) + 1.0);
}
}
return result;
}

original_code:
double ssm_f_inv_logit_ab(double x, double a, double b)
{
    if (a == b) {
        return x ;
    } else {
        if (x < 0) {
            return (b*exp(x)+a)/(1.0+exp(x));
        } else {
            return (b+a*exp(-x))/(1.0+exp(-x));
        }
    }
}


decompiled_code:
double ssm_f_der_id()
{
return *(double *)&LC3;
}

canonical_decompiled_code:
double func7()
{
return *(double *)&LC3;
}

original_code:
double ssm_f_der_id(double x)
{
    return 1;
}


decompiled_code:
double __fastcall ssm_f_der_log(double a1)
{
return 1.0 / a1;
}

canonical_decompiled_code:
double __fastcall func8(double a1)
{
return 1.0 / a1;
}

original_code:
double ssm_f_der_log(double x)
{
    return 1.0/x;
}


decompiled_code:
// attributes: thunk
double ssm_f_der_inv_log(double x)
{
return ssm_f_inv_log(x);
}

canonical_decompiled_code:
double func9(double x)
{
return func2(x);
}

original_code:
double ssm_f_der_inv_log(double x)
{
    return exp(x);
}


decompiled_code:
double ssm_f_der2_inv_id()
{
return 0.0;
}

canonical_decompiled_code:
double func10()
{
return 0.0;
}

original_code:
double ssm_f_der2_inv_id(double x)
{
    return 0;
}


decompiled_code:
// attributes: thunk
double ssm_f_der2_inv_log(double x)
{
return ssm_f_inv_log(x);
}

canonical_decompiled_code:
double func11(double x)
{
return func2(x);
}

original_code:
double ssm_f_der2_inv_log(double x)
{
    return exp(x);
}


decompiled_code:
double __fastcall ssm_f_der2_inv_logit(double a1)
{
double v1; // xmm0_8
double result; // xmm0_8
double v3; // xmm0_8
double v4; // [rsp+8h] [rbp-20h]
double v5; // [rsp+8h] [rbp-20h]
double x; // [rsp+10h] [rbp-18h]
double xa; // [rsp+10h] [rbp-18h]
double xc; // [rsp+10h] [rbp-18h]
double v10; // [rsp+18h] [rbp-10h]
double v11; // [rsp+18h] [rbp-10h]

if ( a1 <= 0.0 )
{
v5 = exp(a1);
v11 = a1;
xc = exp(a1);
v3 = exp(v11);
result = v5 * (1.0 - xc) / pow(v3 + 1.0, 3.0);
}
else
{
*(_QWORD *)&x = *(_QWORD *)&a1 ^ LC5;
v4 = exp(COERCE_DOUBLE(*(_QWORD *)&a1 ^ LC5));
v10 = x;
xa = exp(x);
v1 = exp(v10);
result = v4 * (xa - 1.0) / pow(v1 + 1.0, 3.0);
}
return result;
}

canonical_decompiled_code:
double __fastcall func12(double a1)
{
double v1; // xmm0_8
double result; // xmm0_8
double v3; // xmm0_8
double v4; // [rsp+8h] [rbp-20h]
double v5; // [rsp+8h] [rbp-20h]
double x; // [rsp+10h] [rbp-18h]
double xa; // [rsp+10h] [rbp-18h]
double xc; // [rsp+10h] [rbp-18h]
double v10; // [rsp+18h] [rbp-10h]
double v11; // [rsp+18h] [rbp-10h]

if ( a1 <= 0.0 )
{
v5 = exp(a1);
v11 = a1;
xc = exp(a1);
v3 = exp(v11);
result = v5 * (1.0 - xc) / pow(v3 + 1.0, 3.0);
}
else
{
*(_QWORD *)&x = *(_QWORD *)&a1 ^ LC5;
v4 = exp(COERCE_DOUBLE(*(_QWORD *)&a1 ^ LC5));
v10 = x;
xa = exp(x);
v1 = exp(v10);
result = v4 * (xa - 1.0) / pow(v1 + 1.0, 3.0);
}
return result;
}

original_code:
double ssm_f_der2_inv_logit(double x)
{
    if (x > 0) {
        return exp(-x)*(exp(-x)-1)/pow(1.0 + exp(-x), 3.0);
    } else {
        return exp(x)*(1-exp(x))/pow(1.0 + exp(x), 3.0);
    }
}


original_code:
double ssm_f_der_logit_ab(double x, double a, double b)
{
    if (a == b) {
        return x ;
    } else {
        return (b-a)/((x-a)*(b-x));
    }
}


decompiled_code:
double __fastcall ssm_f_der_inv_logit_ab(double result, double a2, double a3)
{
double v3; // xmm3_8
double v4; // xmm1_8
double v5; // [rsp+0h] [rbp-20h]
double v6; // [rsp+8h] [rbp-18h]

v3 = result;
if ( a2 != a3 )
{
v5 = a3 - a2;
if ( result > 0.0 )
*(_QWORD *)&v3 = *(_QWORD *)&result ^ LC5;
v6 = exp(v3);
v4 = exp(v3) + 1.0;
result = v6 * v5 / (v4 * v4);
}
return result;
}

canonical_decompiled_code:
double __fastcall func14(double result, double a2, double a3)
{
double v3; // xmm3_8
double v4; // xmm1_8
double v5; // [rsp+0h] [rbp-20h]
double v6; // [rsp+8h] [rbp-18h]

v3 = result;
if ( a2 != a3 )
{
v5 = a3 - a2;
if ( result > 0.0 )
*(_QWORD *)&v3 = *(_QWORD *)&result ^ LC5;
v6 = exp(v3);
v4 = exp(v3) + 1.0;
result = v6 * v5 / (v4 * v4);
}
return result;
}

original_code:
double ssm_f_der_inv_logit_ab(double x, double a, double b)
{
    if (a == b) {
        return x ;
    } else {
        if (x > 0) {
            return (b-a)*exp(-x)/pow(exp(-x) + 1.0, 2.0);
        } else {
            return (b-a)*exp(x)/pow(exp(x) + 1.0, 2.0);
        }
    }
}


decompiled_code:
double __fastcall ssm_f_der2_inv_logit_ab(double result, double a2, double a3)
{
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // [rsp+0h] [rbp-28h]
double v6; // [rsp+8h] [rbp-20h]
double v7; // [rsp+8h] [rbp-20h]
double x; // [rsp+10h] [rbp-18h]
double xa; // [rsp+10h] [rbp-18h]
double xb; // [rsp+10h] [rbp-18h]
double xc; // [rsp+10h] [rbp-18h]
double v12; // [rsp+18h] [rbp-10h]
double v13; // [rsp+18h] [rbp-10h]

if ( a2 != a3 )
{
v5 = a3 - a2;
if ( result <= 0.0 )
{
xb = result;
v7 = exp(result);
v13 = xb;
xc = exp(xb);
v4 = exp(v13);
result = v7 * v5 * (1.0 - xc) / pow(v4 + 1.0, 3.0);
}
else
{
*(_QWORD *)&x = *(_QWORD *)&result ^ LC5;
v6 = exp(COERCE_DOUBLE(*(_QWORD *)&result ^ LC5));
v12 = x;
xa = exp(x);
v3 = exp(v12);
result = v6 * v5 * (xa - 1.0) / pow(v3 + 1.0, 3.0);
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func15(double result, double a2, double a3)
{
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // [rsp+0h] [rbp-28h]
double v6; // [rsp+8h] [rbp-20h]
double v7; // [rsp+8h] [rbp-20h]
double x; // [rsp+10h] [rbp-18h]
double xa; // [rsp+10h] [rbp-18h]
double xb; // [rsp+10h] [rbp-18h]
double xc; // [rsp+10h] [rbp-18h]
double v12; // [rsp+18h] [rbp-10h]
double v13; // [rsp+18h] [rbp-10h]

if ( a2 != a3 )
{
v5 = a3 - a2;
if ( result <= 0.0 )
{
xb = result;
v7 = exp(result);
v13 = xb;
xc = exp(xb);
v4 = exp(v13);
result = v7 * v5 * (1.0 - xc) / pow(v4 + 1.0, 3.0);
}
else
{
*(_QWORD *)&x = *(_QWORD *)&result ^ LC5;
v6 = exp(COERCE_DOUBLE(*(_QWORD *)&result ^ LC5));
v12 = x;
xa = exp(x);
v3 = exp(v12);
result = v6 * v5 * (xa - 1.0) / pow(v3 + 1.0, 3.0);
}
}
return result;
}

original_code:
double ssm_f_der2_inv_logit_ab(double x, double a, double b)
{
    if (a == b) {
        return x ;
    } else {
        if (x > 0) {
            return (b-a)*exp(-x)*(exp(-x)-1)/pow(1.0 + exp(-x), 3.0);
        } else {
            return (b-a)*exp(x)*(1-exp(x))/pow(1.0 + exp(x), 3.0);
        }
    }
}


decompiled_code:
__int64 __fastcall ssm_rmvnorm(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5, double a6)
{
__int64 v7; // r12
__int64 v9; // r14
__int64 v10; // rbx
__int64 v11; // rsi

v7 = a2;
v9 = gsl_matrix_alloc(v7, v7);
gsl_matrix_memcpy(v9, a4);
gsl_matrix_scale(v9, a6 * a6);
gsl_linalg_cholesky_decomp(v9);
if ( a2 > 0 )
{
v10 = 0LL;
do
{
gsl_ran_ugaussian(a1);
v11 = v10++;
gsl_vector_set(a5, v11);
}
while ( v10 != v7 );
}
gsl_blas_dtrmv(122LL, 111LL, 131LL, v9, a5);
gsl_vector_add(a5, a3);
gsl_matrix_free(v9);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5, double a6)
{
__int64 v7; // r12
__int64 v9; // r14
__int64 v10; // rbx
__int64 v11; // rsi

v7 = a2;
v9 = gsl_matrix_alloc(v7, v7);
gsl_matrix_memcpy(v9, a4);
gsl_matrix_scale(v9, a6 * a6);
gsl_linalg_cholesky_decomp(v9);
if ( a2 > 0 )
{
v10 = 0LL;
do
{
gsl_ran_ugaussian(a1);
v11 = v10++;
gsl_vector_set(a5, v11);
}
while ( v10 != v7 );
}
gsl_blas_dtrmv(122LL, 111LL, 131LL, v9, a5);
gsl_vector_add(a5, a3);
gsl_matrix_free(v9);
return 0LL;
}

original_code:
int ssm_rmvnorm(const gsl_rng *r, const int n, const gsl_vector *mean, const gsl_matrix *var, double sd_fac, gsl_vector *result)
{
    int k;
    gsl_matrix *work = gsl_matrix_alloc(n,n);
    gsl_matrix_memcpy(work,var);
    gsl_matrix_scale(work, sd_fac*sd_fac);
    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 ssm_rmvnorm(struct gsl_rng *r, int n, struct gsl_vector *mean, struct gsl_matrix *var, double sd_fac, struct gsl_vector *result)
{
    int k;
    struct gsl_matrix *work = gsl_matrix_alloc(n,n);
    gsl_matrix_memcpy(work,var);
    gsl_matrix_scale(work, sd_fac*sd_fac);
    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: 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; } *

return_type: int

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


original_code:
void ssm_adapt_var(ssm_adapt_t *adapt, ssm_theta_t *x, int m)
{
    int i, k;
    double *x_bar = adapt->mean_sampling;
    gsl_matrix *cov = adapt->var_sampling;
    double dm = (double) m;
    double val;
    for (i=0; i < x->size; i++) {
        for (k=0; k <= i; k++) {
            val = ((dm - 1.0) / dm) * (gsl_vector_get(x, i) - x_bar[i]) * (gsl_vector_get(x, k) - x_bar[k]);
            gsl_matrix_set(cov, i, k, (((dm-1.0)*gsl_matrix_get(cov, i, k)) + val ) / dm);
        }
    }
    for (i=0; i < x->size; 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 < x->size; i++) {
        x_bar[i] += (gsl_vector_get(x, i) - x_bar[i]) / dm;
    }
}

canonical_original_code:
void ssm_adapt_var(struct ssm_adapt_t *adapt, struct gsl_vector *x, int m)
{
    int i; int k;
    double *x_bar = adapt->mean_sampling;
    struct gsl_matrix *cov = adapt->var_sampling;
    double dm = (double) m;
    double val;
    for (i=0; i < x->size; i++) {
        for (k=0; k <= i; k++) {
            val = ((dm - 1.0) / dm) * (gsl_vector_get(x, i) - x_bar[i]) * (gsl_vector_get(x, k) - x_bar[k]);
            gsl_matrix_set(cov, i, k, (((dm-1.0)*gsl_matrix_get(cov, i, k)) + val ) / dm);
        }
    }
    for (i=0; i < x->size; 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 < x->size; i++) {
        x_bar[i] += (gsl_vector_get(x, i) - x_bar[i]) / dm;
    }
}

variable_types: struct ssm_adapt_t { double ar; double ar_smoothed; double eps; double eps_a; double eps_max; int eps_switch; int m_switch; int flag_smooth; double alpha; double *mean_sampling; 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; } *var_sampling; } *

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

variable_types: m int

variable_types: dm double

variable_types: val double

user_defined_types: struct ssm_adapt_t { double ar; double ar_smoothed; double eps; double eps_a; double eps_max; int eps_switch; int m_switch; int flag_smooth; double alpha; double *mean_sampling; struct gsl_matrix *var_sampling; }

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 ssm_X_copy(__int64 a1, int *a2)
{
void *result; // rax

result = memcpy(*(void **)(a1 + 8), *((const void **)a2 + 1), 8LL * *a2);
*(_QWORD *)(a1 + 16) = *((_QWORD *)a2 + 2);
return result;
}

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

result = memcpy(*(void **)(a1 + 8), *((const void **)a2 + 1), 8LL * *a2);
*(_QWORD *)(a1 + 16) = *((_QWORD *)a2 + 2);
return result;
}

original_code:
void ssm_X_copy(ssm_X_t *dest, ssm_X_t *src)
{
    memcpy(dest->proj, src->proj, src->length * sizeof(double));
    dest->dt = src->dt;
}

canonical_original_code:
void ssm_X_copy(struct ssm_X_t *dest, struct ssm_X_t *src)
{
    memcpy(dest->proj, src->proj, src->length * sizeof(double));
    dest->dt = src->dt;
}

variable_types: struct ssm_X_t { int length; double *proj; double dt; double dt0; } *

variable_types:
src
struct ssm_X_t *


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

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

variable_types:
K
unsigned long

variable_types:
N
unsigned int

variable_types:
p
double []

variable_types:
n
unsigned int []

variable_types:
k
unsigned long

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


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

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

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

variable_types: rate double

variable_types: dt double


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

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

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

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

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

variable_types:
tab
unsigned int **

variable_types: n int

variable_types: i int


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

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

variable_types:
tab
unsigned int ***

variable_types: j int


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

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

variable_types:
tab
unsigned int ****

variable_types: k int


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

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


decompiled_code:
void __fastcall ssm_dic_init(double *a1, double a2, double a3)
{
double v3; // xmm1_8
double v4; // xmm0_8

v3 = a3 + a2;
a1[16] = a2;
v4 = a2 * -2.0;
a1[17] = v3;
a1[20] = v4;
a1[21] = v4;
}

original_code:
void ssm_dic_init(ssm_fitness_t *fitness, double log_like, double log_prior)
{
    fitness->summary_log_likelihood = log_like;
    fitness->summary_log_ltp = log_like + log_prior;
    fitness->_min_deviance = -2*log_like;
    fitness->_deviance_cum = -2*log_like;
}

canonical_original_code:
void ssm_dic_init(struct ssm_fitness_t *fitness, double log_like, double log_prior)
{
    fitness->summary_log_likelihood = log_like;
    fitness->summary_log_ltp = log_like + log_prior;
    fitness->_min_deviance = -2*log_like;
    fitness->_deviance_cum = -2*log_like;
}

variable_types: struct ssm_fitness_t { int J; int data_length; double like_min; double log_like_min; double ess_n; double log_like_n; double log_like; double *weights; unsigned int **select; enum ssm_err_code_t { SSM_SUCCESS=expr, SSM_ERR_LIKE=expr, SSM_ERR_REM_SV=expr, SSM_ERR_PRED=expr, SSM_ERR_KAL=expr, SSM_ERR_IC=expr, SSM_MH_REJECT=expr, SSM_ERR_PROPOSAL=expr, SSM_ERR_PRIOR=expr } *cum_status; int n_all_fail; double log_like_prev; double log_prior; double log_prior_prev; double AIC; double AICc; double DIC; double summary_log_likelihood; double summary_log_ltp; double summary_sum_squares; int n; double _min_deviance; double _deviance_cum; } *

user_defined_types: struct ssm_fitness_t { int J; int data_length; double like_min; double log_like_min; double ess_n; double log_like_n; double log_like; double *weights; unsigned int **select; enum ssm_err_code_t *cum_status; int n_all_fail; double log_like_prev; double log_prior; double log_prior_prev; double AIC; double AICc; double DIC; double summary_log_likelihood; double summary_log_ltp; double summary_sum_squares; int n; double _min_deviance; double _deviance_cum; }


original_code:
void ssm_dic_update(ssm_fitness_t *fitness, double log_like, double log_prior)
{
    if( log_like > fitness->summary_log_likelihood){
 fitness->summary_log_likelihood = log_like;
    }
    if( (log_like+log_prior) > fitness->summary_log_ltp){
 fitness->summary_log_ltp = (log_like+log_prior);
    }
    double deviance = -2*log_like;
    fitness->_deviance_cum += deviance;
    if( deviance < fitness->_min_deviance){
 fitness->_min_deviance = deviance;
    }
}

canonical_original_code:
void ssm_dic_update(struct ssm_fitness_t *fitness, double log_like, double log_prior)
{
    if( log_like > fitness->summary_log_likelihood){
 fitness->summary_log_likelihood = log_like;
    }
    if( (log_like+log_prior) > fitness->summary_log_ltp){
 fitness->summary_log_ltp = (log_like+log_prior);
    }
    double deviance = -2*log_like;
    fitness->_deviance_cum += deviance;
    if( deviance < fitness->_min_deviance){
 fitness->_min_deviance = deviance;
    }
}

variable_types: deviance double

user_defined_types: enum ssm_err_code_t { SSM_SUCCESS=expr, SSM_ERR_LIKE=expr, SSM_ERR_REM_SV=expr, SSM_ERR_PRED=expr, SSM_ERR_KAL=expr, SSM_ERR_IC=expr, SSM_MH_REJECT=expr, SSM_ERR_PROPOSAL=expr, SSM_ERR_PRIOR=expr }


decompiled_code:
void *__fastcall ssm_c1_new(int a1)
{
void *result; // rax
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

result = malloc(a1);
if ( !result )
{
sprintf(v2, "Allocation impossible in file :%s line : %d", "core/alloc_c.c", 28LL);
ssm_print_err(v2);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
void *result; // rax
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

result = malloc(a1);
if ( !result )
{
sprintf(v2, "Allocation impossible in file :%s line : %d", "core/alloc_c.c", 28LL);
ssm_print_err(v2);
exit(1);
}
return result;
}

original_code:
char *ssm_c1_new(int n)
{
    char *tab = malloc(n*sizeof (char));
    if(tab==((void *)0))
    {
        char str[255];
        sprintf(str, "Allocation impossible in file :%s line : %d","core/alloc_c.c",28);
        ssm_print_err(str);
        exit(1);
    }
    return tab;
}

variable_types:
tab
char *

variable_types:
str
char [255]

return_type: char *


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

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

original_code:
void ssm_c2_free(char **tab, int n)
{
    int i;
    for(i=0; i<n; i++)
        free(tab[i]);
    free(tab);
}

variable_types:
tab
char **


original_code:
void ssm_adapt_ar(ssm_adapt_t *a, int is_accepted, int m)
{
    a->ar_smoothed = (1.0 - a->alpha) * a->ar_smoothed + a->alpha * is_accepted;
    a->ar += ( ((double) is_accepted - a->ar) / ((double) (m + 1)) );
}

canonical_original_code:
void ssm_adapt_ar(struct ssm_adapt_t *a, int is_accepted, int m)
{
    a->ar_smoothed = (1.0 - a->alpha) * a->ar_smoothed + a->alpha * is_accepted;
    a->ar += ( ((double) is_accepted - a->ar) / ((double) (m + 1)) );
}

variable_types: struct ssm_adapt_t { double ar; double ar_smoothed; double eps; double eps_a; double eps_max; int eps_switch; int m_switch; int flag_smooth; double alpha; double *mean_sampling; 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; } *var_sampling; } *

variable_types: m int


decompiled_code:
// attributes: thunk
__int64 ssm_theta_copy()
{
return gsl_vector_memcpy();
}

canonical_decompiled_code:
__int64 func5()
{
return gsl_vector_memcpy();
}

original_code:
int ssm_theta_copy(ssm_theta_t *dest, ssm_theta_t *src)
{
    return gsl_vector_memcpy(dest, src);
}

canonical_original_code:
int ssm_theta_copy(struct gsl_vector *dest, struct gsl_vector *src)
{
    return gsl_vector_memcpy(dest, src);
}

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:
src
struct gsl_vector *


decompiled_code:
// attributes: thunk
__int64 ssm_par_copy()
{
return ssm_theta_copy();
}

canonical_decompiled_code:
__int64 func6()
{
return func5();
}

original_code:
int ssm_par_copy(ssm_par_t *dest, ssm_par_t *src)
{
    return gsl_vector_memcpy(dest, src);
}

canonical_original_code:
int ssm_par_copy(struct gsl_vector *dest, struct gsl_vector *src)
{
    return gsl_vector_memcpy(dest, src);
}


decompiled_code:
__int64 __fastcall ssm_in_jarray(__int64 a1, const char *a2)
{
unsigned __int64 v3; // rbx
unsigned __int64 v4; // rsi
__int64 v5; // rax
const char *v6; // rax

v3 = 0LL;
do
{
if ( json_array_size(a1) <= v3 )
return 0LL;
v4 = v3++;
v5 = json_array_get(a1, v4);
v6 = (const char *)json_string_value(v5);
}
while ( strcmp(v6, a2) );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
unsigned __int64 v3; // rbx
unsigned __int64 v4; // rsi
__int64 v5; // rax
const char *v6; // rax

v3 = 0LL;
do
{
if ( json_array_size(a1) <= v3 )
return 0LL;
v4 = v3++;
v5 = json_array_get(a1, v4);
v6 = (const char *)json_string_value(v5);
}
while ( strcmp(v6, a2) );
return 1LL;
}

original_code:
int ssm_in_jarray(json_t *jarray, const char *name)
{
    int i;
    for(i=0; i<json_array_size(jarray); i++){
        if(strcmp(json_string_value(json_array_get(jarray, i)), name) == 0){
            return 1;
        }
    }
    return 0;
}

canonical_original_code:
int ssm_in_jarray(struct json_t *jarray, char *name)
{
    int i;
    for(i=0; i<json_array_size(jarray); i++){
        if(strcmp(json_string_value(json_array_get(jarray, i)), name) == 0){
            return 1;
        }
    }
    return 0;
}

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

variable_types:
name
char *

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


decompiled_code:
__int64 __fastcall ssm_str_to_interp_type(const char *a1)
{
bool v1; // dl
bool v2; // cf
bool v3; // zf
const char *v4; // rsi
const char *v5; // rdi
__int64 v6; // rcx

if ( !strcmp(a1, "linear") )
return gsl_interp_linear;
if ( !strcmp(a1, "polynomial") )
return gsl_interp_polynomial;
if ( !strcmp(a1, "cspline") )
return gsl_interp_cspline;
if ( !strcmp(a1, "cspline_periodic") )
return gsl_interp_cspline_periodic;
v1 = strcmp(a1, "akima") != 0;
v2 = 0;
v3 = !v1;
if ( !v1 )
return gsl_interp_akima;
v4 = a1;
v5 = "akima_periodic";
v6 = 15LL;
do
{
if ( !v6 )
break;
v2 = *v4 < (unsigned int)*v5;
v3 = *v4++ == *v5++;
--v6;
}
while ( v3 );
if ( (!v2 && !v3) == v2 )
return gsl_interp_akima_periodic;
ssm_print_warning("Unknown gsl interpolator for metadata. Linear interpolator will be used instead.", v4);
return gsl_interp_linear;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
bool v1; // dl
bool v2; // cf
bool v3; // zf
const char *v4; // rsi
const char *v5; // rdi
__int64 v6; // rcx

if ( !strcmp(a1, "linear") )
return gsl_interp_linear;
if ( !strcmp(a1, "polynomial") )
return gsl_interp_polynomial;
if ( !strcmp(a1, "cspline") )
return gsl_interp_cspline;
if ( !strcmp(a1, "cspline_periodic") )
return gsl_interp_cspline_periodic;
v1 = strcmp(a1, "akima") != 0;
v2 = 0;
v3 = !v1;
if ( !v1 )
return gsl_interp_akima;
v4 = a1;
v5 = "akima_periodic";
v6 = 15LL;
do
{
if ( !v6 )
break;
v2 = *v4 < (unsigned int)*v5;
v3 = *v4++ == *v5++;
--v6;
}
while ( v3 );
if ( (!v2 && !v3) == v2 )
return gsl_interp_akima_periodic;
ssm_print_warning("Unknown gsl interpolator for metadata. Linear interpolator will be used instead.", v4);
return gsl_interp_linear;
}

original_code:
const gsl_interp_type *ssm_str_to_interp_type(const char *optarg)
{
    if (strcmp(optarg, "linear") == 0) {
        return gsl_interp_linear;
    } else if (strcmp(optarg, "polynomial") == 0){
        return gsl_interp_polynomial;
    } else if (strcmp(optarg, "cspline") == 0){
        return gsl_interp_cspline;
    } else if (strcmp(optarg, "cspline_periodic") == 0){
        return gsl_interp_cspline_periodic;
    } else if (strcmp(optarg, "akima") == 0){
        return gsl_interp_akima;
    } else if (strcmp(optarg, "akima_periodic") == 0){
        return gsl_interp_akima_periodic;
    }
    ssm_print_warning("Unknown gsl interpolator for metadata. Linear interpolator will be used instead.");
    return gsl_interp_linear;
}

canonical_original_code:
struct gsl_interp_type *ssm_str_to_interp_type(char *optarg)
{
    if (strcmp(optarg, "linear") == 0) {
        return gsl_interp_linear;
    } else if (strcmp(optarg, "polynomial") == 0){
        return gsl_interp_polynomial;
    } else if (strcmp(optarg, "cspline") == 0){
        return gsl_interp_cspline;
    } else if (strcmp(optarg, "cspline_periodic") == 0){
        return gsl_interp_cspline_periodic;
    } else if (strcmp(optarg, "akima") == 0){
        return gsl_interp_akima;
    } else if (strcmp(optarg, "akima_periodic") == 0){
        return gsl_interp_akima_periodic;
    }
    ssm_print_warning("Unknown gsl interpolator for metadata. Linear interpolator will be used instead.");
    return gsl_interp_linear;
}

variable_types:
optarg
char *

return_type: 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 { unsigned long cache; unsigned long miss_count; unsigned long hit_count; } *, 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_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 *); }


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

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

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

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

original_code:
int ssm_sanitize_n_threads(int n_threads, ssm_fitness_t *fitness)
{
    if(n_threads > fitness->J){
        return fitness->J;
    } else {
        return n_threads;
    }
}

canonical_original_code:
int ssm_sanitize_n_threads(int n_threads, struct ssm_fitness_t *fitness)
{
    if(n_threads > fitness->J){
        return fitness->J;
    } else {
        return n_threads;
    }
}


original_code:
void ssm_resample_X(ssm_fitness_t *fitness, ssm_X_t ***J_p_X, ssm_X_t ***J_p_X_tmp, int n)
{
    int j;
    unsigned int *select = fitness->select[n];
    for(j=0;j<fitness->J;j++) {
        (*J_p_X_tmp)[j]->dt = (*J_p_X)[select[j]]->dt;
        memcpy((*J_p_X_tmp)[j]->proj, (*J_p_X)[select[j]]->proj, (*J_p_X)[select[j]]->length * sizeof(double));
    }
    ssm_swap_X(J_p_X, J_p_X_tmp);
}

canonical_original_code:
void ssm_resample_X(struct ssm_fitness_t *fitness, struct ssm_X_t ***J_p_X, struct ssm_X_t ***J_p_X_tmp, int n)
{
    int j;
    unsigned int *select = fitness->select[n];
    for(j=0;j<fitness->J;j++) {
        (*J_p_X_tmp)[j]->dt = (*J_p_X)[select[j]]->dt;
        memcpy((*J_p_X_tmp)[j]->proj, (*J_p_X)[select[j]]->proj, (*J_p_X)[select[j]]->length * sizeof(double));
    }
    ssm_swap_X(J_p_X, J_p_X_tmp);
}

variable_types: struct ssm_X_t { int length; double *proj; double dt; double dt0; } ***

variable_types: n int

variable_types:
select
unsigned int *


decompiled_code:
__int64 __fastcall ssm_load_json_file(__int64 a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-108h] BYREF
char v3[172]; // [rsp+5Ch] [rbp-ACh] BYREF

result = json_load_file(a1, 0LL, &v2);
if ( !result )
{
ssm_print_err(v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-108h] BYREF
char v3[172]; // [rsp+5Ch] [rbp-ACh] BYREF

result = json_load_file(a1, 0LL, &v2);
if ( !result )
{
ssm_print_err(v3);
exit(1);
}
return result;
}

original_code:
json_t *ssm_load_json_file(const char *path)
{
    json_error_t error;
    json_t *data = json_load_file(path, 0, &error);
    if(!data) {
        ssm_print_err(error.text);
        exit(1);
    }
    return data;
}

canonical_original_code:
struct json_t *ssm_load_json_file(char *path)
{
    struct json_error_t error;
    struct json_t *data = json_load_file(path, 0, &error);
    if(!data) {
        ssm_print_err(error.text);
        exit(1);
    }
    return data;
}

variable_types:
path
char *

variable_types: struct json_error_t { int line; int column; int position; char source[80]; char text[160]; }

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


decompiled_code:
__int64 ssm_load_data()
{
return ssm_load_json_file((__int64)".data.json");
}

canonical_decompiled_code:
__int64 func2()
{
return func1((__int64)".data.json");
}

original_code:
json_t *ssm_load_data(ssm_options_t *opts)
{
    json_t *jdata = ssm_load_json_file(".data.json");
    return jdata;
}

canonical_original_code:
struct json_t *ssm_load_data(struct ssm_options_t *opts)
{
    struct json_t *jdata = ssm_load_json_file(".data.json");
    return jdata;
}

variable_types: struct ssm_options_t { enum ssm_algo_t { SSM_SMC=expr, SSM_MIF=expr, SSM_PMCMC=expr, SSM_KMCMC=expr, SSM_KALMAN=expr, SSM_KSIMPLEX=expr, SSM_SIMUL=expr, SSM_SIMPLEX=expr, SSM_WORKER=expr } algo; enum ssm_algo_t { SSM_SMC=expr, SSM_MIF=expr, SSM_PMCMC=expr, SSM_KMCMC=expr, SSM_KALMAN=expr, SSM_KSIMPLEX=expr, SSM_SIMUL=expr, SSM_SIMPLEX=expr, SSM_WORKER=expr } worker_algo; enum ssm_implementations_t { SSM_ODE=0, SSM_SDE=1, SSM_PSR=2, SSM_EKF=3 } implementation; enum ssm_noises_off_t { SSM_NO_DEM_STO=expr, SSM_NO_WHITE_NOISE=expr, SSM_NO_DIFF=expr } noises_off; enum ssm_print_t { SSM_PRINT_TRACE=expr, SSM_PRINT_X=expr, SSM_PRINT_HAT=expr, SSM_PRINT_DIAG=expr, SSM_PRINT_LOG=expr, SSM_PRINT_WARNING=expr } print; int id; int flag_seed_time; int flag_prior; double dt; double eps_abs; double eps_rel; char *freeze_forcing; char *root; char *next; int n_thread; double like_min; int J; int n_obs; char *interpolator; int n_iter; double a; double b; double L; int m_switch; int flag_ic_only; int eps_switch; double eps_max; double flag_smooth; double alpha; int n_traj; int flag_tcp; int flag_least_squares; double size_stop; int freq; char *start; char *end; char *server; int flag_no_filter; } *

user_defined_types: struct ssm_options_t { enum ssm_algo_t algo; enum ssm_algo_t worker_algo; enum ssm_implementations_t implementation; enum ssm_noises_off_t noises_off; enum ssm_print_t print; int id; int flag_seed_time; int flag_prior; double dt; double eps_abs; double eps_rel; char *freeze_forcing; char *root; char *next; int n_thread; double like_min; int J; int n_obs; char *interpolator; int n_iter; double a; double b; double L; int m_switch; int flag_ic_only; int eps_switch; double eps_max; double flag_smooth; double alpha; int n_traj; int flag_tcp; int flag_least_squares; double size_stop; int freq; char *start; char *end; char *server; int flag_no_filter; }

user_defined_types: enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 }


heaviside

decompiled_code:
double __fastcall heaviside(double a1)
{
double result; // xmm0_8

result = 0.0;
if ( a1 >= 0.0 )
result = *(double *)&LC1;
return result;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
double result; // xmm0_8

result = 0.0;
if ( a1 >= 0.0 )
result = *(double *)&LC1;
return result;
}

original_code:
double heaviside(double x)
{
    return (x < 0.0) ? 0.0 : 1.0;
}

variable_types: x double


ramp

original_code:
double ramp(double x)
{
    return (x >= 0) ? x : 0.0;
}


slowstep

original_code:
double slowstep(double x, double d)
{
    return ( x >= 0.0 ? ( x >= d ? d : x ) : 0.0 );
}

variable_types: d double


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

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

original_code:
void ssm_st2_free(size_t **tab, int n)
{
    int i;
    for(i=0; i<n; i++){
        free(tab[i]);
    }
    free(tab);
}

canonical_original_code:
void ssm_st2_free(unsigned long **tab, int n)
{
    int i;
    for(i=0; i<n; i++){
        free(tab[i]);
    }
    free(tab);
}

variable_types:
tab
unsigned long **

variable_types: i int


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

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

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

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

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

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


main

canonical_name: main

original_code:
int main(int argc, char *argv[])
{
    return clar_test(argc, argv);
}

variable_types: argc int

variable_types:
argv
char *[]


canonical_original_code:
int main(int argc, char *argv[])
{
    return clar_test(argc, argv);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
_DWORD *v4; // rbx
__int64 v5; // r12
__int64 v6; // r14
__int64 v7; // rbp
__int64 v8; // r15
double *v9; // r13
__int64 v10; // r14
int v11; // eax
int v12; // eax
__int64 v13; // rax
__int64 v15; // [rsp+0h] [rbp-A8h]
__int64 v16; // [rsp+8h] [rbp-A0h]
__int64 v17; // [rsp+10h] [rbp-98h]
__int64 v18; // [rsp+18h] [rbp-90h]
__int64 v19; // [rsp+20h] [rbp-88h]
double v20; // [rsp+28h] [rbp-80h]
__int64 v21[7]; // [rsp+30h] [rbp-78h] BYREF
int v22; // [rsp+68h] [rbp-40h]
int v23; // [rsp+6Ch] [rbp-3Ch]

v4 = (_DWORD *)ssm_options_new(argc, argv, envp);
ssm_options_load(v4, 128LL, (unsigned int)argc, argv);
v5 = ssm_load_json_stream(stdin);
v6 = ssm_load_data(v4);
v7 = ssm_nav_new(v5, v4);
v8 = ssm_data_new(v6, v7, v4);
v9 = (double *)ssm_fitness_new(v8, v4);
v15 = ssm_calc_new(v6, v7, v8, v9, v4, 0LL);
v17 = ssm_X_new(v7, v4);
json_decref(v6);
v10 = ssm_input_new(v5, v7);
v18 = ssm_par_new(v10, v15, v7);
v16 = ssm_theta_new(v10, v7);
v21[0] = v8;
v19 = ssm_var_new(v5, v7);
v21[1] = v7;
v21[5] = v17;
v11 = v4[7];
v21[2] = v15;
v22 = v11;
v12 = v4[48];
v21[3] = v10;
v21[4] = v18;
v21[6] = (__int64)v9;
v23 = v12;
gsl_set_error_handler_off();
if ( !v4[28] && (*(_BYTE *)(v7 + 8) & 1) != 0 )
{
v20 = f_simplex(v16, v21);
v13 = ssm_print_trace(*(_QWORD *)(v7 + 40), v16, v7, 0LL);
v3 = v20;
}
else
{
v13 = ssm_simplex(v16, v19, v21, f_simplex, v7, v4);
}
if ( (*(_BYTE *)(v7 + 8) & 0x10) == 0 )
{
if ( v4[48] )
{
v9[18] = v3;
}
else if ( v4[7] )
{
v9[17] = v3;
}
else
{
v9[5] = v3;
v13 = ssm_aic(v9, v7);
}
ssm_pipe_theta(stdout, v5, v16, 0LL, v9, v7, v4, v13);
}
json_decref(v5);
ssm_X_free(v17);
ssm_calc_free(v15, v7);
ssm_data_free(v8);
ssm_nav_free(v7);
ssm_fitness_free(v9);
ssm_input_free(v10);
ssm_par_free(v18);
ssm_theta_free(v16);
ssm_var_free(v19);
return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // xmm0_8
__int64 v4; // rbx
__int64 v5; // r12
__int64 v6; // r14
__int64 v7; // rbp
__int64 v8; // r15
__int64 v9; // r13
__int64 v10; // r14
int v11; // eax
__int64 v12; // rax
__int64 v14; // [rsp+8h] [rbp-A0h]
__int64 v15; // [rsp+10h] [rbp-98h]
__int64 v16; // [rsp+18h] [rbp-90h]
__int64 v17; // [rsp+20h] [rbp-88h]
__int64 v18; // [rsp+28h] [rbp-80h]
__int64 v19[7]; // [rsp+30h] [rbp-78h] BYREF
int v20; // [rsp+68h] [rbp-40h]

v4 = ssm_options_new(argc, argv, envp);
ssm_options_load(v4, 32LL, (unsigned int)argc, argv);
v5 = ssm_load_json_stream(stdin);
v6 = ssm_load_data(v4);
v7 = ssm_nav_new(v5, v4);
v8 = ssm_data_new(v6, v7, v4);
v9 = ssm_fitness_new(v8, v4);
v14 = ssm_calc_new(v6, v7, v8, v9, v4, 0LL);
v16 = ssm_X_new(v7, v4);
json_decref(v6);
v10 = ssm_input_new(v5, v7);
v17 = ssm_par_new(v10, v14, v7);
v15 = ssm_theta_new(v10, v7);
v19[0] = v8;
v18 = ssm_var_new(v5, v7);
v11 = *(_DWORD *)(v4 + 28);
v19[2] = v14;
v19[4] = v17;
v19[5] = v16;
v19[1] = v7;
v19[3] = v10;
v19[6] = v9;
v20 = v11;
gsl_set_error_handler_off();
v12 = ssm_simplex(v15, v18, v19, f_ksimplex, v7, v4);
if ( (*(_BYTE *)(v7 + 8) & 0x10) == 0 )
{
if ( *(_DWORD *)(v4 + 28) )
{
*(_QWORD *)(v9 + 136) = v3;
}
else
{
*(_QWORD *)(v9 + 40) = v3;
v12 = ssm_aic(v9, v7);
}
ssm_pipe_theta(stdout, v5, v15, 0LL, v9, v7, v4, v12);
}
json_decref(v5);
ssm_X_free(v16);
ssm_calc_free(v14, v7);
ssm_data_free(v8);
ssm_nav_free(v7);
ssm_fitness_free(v9);
ssm_input_free(v10);
ssm_par_free(v17);
ssm_theta_free(v15);
ssm_var_free(v18);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // xmm0_8
__int64 v4; // rbx
__int64 v5; // r12
__int64 v6; // r14
__int64 v7; // rbp
__int64 v8; // r15
__int64 v9; // r13
__int64 v10; // r14
int v11; // eax
__int64 v12; // rax
__int64 v14; // [rsp+8h] [rbp-A0h]
__int64 v15; // [rsp+10h] [rbp-98h]
__int64 v16; // [rsp+18h] [rbp-90h]
__int64 v17; // [rsp+20h] [rbp-88h]
__int64 v18; // [rsp+28h] [rbp-80h]
__int64 v19[7]; // [rsp+30h] [rbp-78h] BYREF
int v20; // [rsp+68h] [rbp-40h]

v4 = ssm_options_new(argc, argv, envp);
ssm_options_load(v4, 32LL, (unsigned int)argc, argv);
v5 = ssm_load_json_stream(stdin);
v6 = ssm_load_data(v4);
v7 = ssm_nav_new(v5, v4);
v8 = ssm_data_new(v6, v7, v4);
v9 = ssm_fitness_new(v8, v4);
v14 = ssm_calc_new(v6, v7, v8, v9, v4, 0LL);
v16 = ssm_X_new(v7, v4);
func1(v6);
v10 = ssm_input_new(v5, v7);
v17 = ssm_par_new(v10, v14, v7);
v15 = ssm_theta_new(v10, v7);
v19[0] = v8;
v18 = ssm_var_new(v5, v7);
v11 = *(_DWORD *)(v4 + 28);
v19[2] = v14;
v19[4] = v17;
v19[5] = v16;
v19[1] = v7;
v19[3] = v10;
v19[6] = v9;
v20 = v11;
gsl_set_error_handler_off();
v12 = ssm_simplex(v15, v18, v19, f_ksimplex, v7, v4);
if ( (*(_BYTE *)(v7 + 8) & 0x10) == 0 )
{
if ( *(_DWORD *)(v4 + 28) )
{
*(_QWORD *)(v9 + 136) = v3;
}
else
{
*(_QWORD *)(v9 + 40) = v3;
v12 = ssm_aic(v9, v7);
}
ssm_pipe_theta(stdout, v5, v15, 0LL, v9, v7, v4, v12);
}
func1(v5);
ssm_X_free(v16);
ssm_calc_free(v14, v7);
ssm_data_free(v8);
ssm_nav_free(v7);
ssm_fitness_free(v9);
ssm_input_free(v10);
ssm_par_free(v17);
ssm_theta_free(v15);
ssm_var_free(v18);
return 0;
}


decompiled_code:
void *__fastcall thread_start(void *a1)
{
int v1; // eax
int v2; // eax
unsigned int v3; // er12
int v4; // eax
unsigned int v5; // er12
char *v7; // rax
unsigned int v8; // er12
char *v9; // rax
char *v10; // rax

v1 = pthread_mutex_lock(&gBarrierMu);
if ( v1 )
{
v8 = v1;
v9 = strerror(v1);
printf("Mutex lock failed at thread %d, error %d (%s)\n", (unsigned int)a1, v8, v9);
exit(1);
}
while ( gThreadWait )
{
if ( gVerbosity > 1 )
printf("Thread %d: waiting\n", (unsigned int)a1);
v2 = pthread_cond_wait(&gBarrierCv, &gBarrierMu);
v3 = v2;
if ( v2 )
{
v7 = strerror(v2);
printf("Cond wait failed at thread %d, error %d (%s)\n", (unsigned int)a1, v3, v7);
exit(1);
}
}
v4 = pthread_mutex_unlock(&gBarrierMu);
v5 = v4;
if ( v4 )
{
v10 = strerror(v4);
printf("Mutex unlock failed at thread %d, error %d (%s)\n", (unsigned int)a1, v5, v10);
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // eax
int v2; // eax
unsigned int v3; // er12
int v4; // eax
unsigned int v5; // er12
char *v7; // rax
unsigned int v8; // er12
char *v9; // rax
char *v10; // rax

v1 = pthread_mutex_lock(&gBarrierMu);
if ( v1 )
{
v8 = v1;
v9 = strerror(v1);
printf("Mutex lock failed at thread %d, error %d (%s)\n", (unsigned int)a1, v8, v9);
exit(1);
}
while ( gThreadWait )
{
if ( gVerbosity > 1 )
printf("Thread %d: waiting\n", (unsigned int)a1);
v2 = pthread_cond_wait(&gBarrierCv, &gBarrierMu);
v3 = v2;
if ( v2 )
{
v7 = strerror(v2);
printf("Cond wait failed at thread %d, error %d (%s)\n", (unsigned int)a1, v3, v7);
exit(1);
}
}
v4 = pthread_mutex_unlock(&gBarrierMu);
v5 = v4;
if ( v4 )
{
v10 = strerror(v4);
printf("Mutex unlock failed at thread %d, error %d (%s)\n", (unsigned int)a1, v5, v10);
exit(1);
}
return 0LL;
}

original_code:
void *thread_start(void *state) {
  int tid = (int) (uintptr_t) state;
  int rv = 0;
  if (0 != (rv = pthread_mutex_lock(&gBarrierMu))) {
    printf("Mutex lock failed at thread %d, error %d (%s)\n",
           tid, rv, strerror(rv));
    exit(1);
  }
  while (gThreadWait) {
    if (gVerbosity > 1) {
      printf("Thread %d: waiting\n", tid);
    }
    if (0 != (rv = pthread_cond_wait(&gBarrierCv, &gBarrierMu))) {
      printf("Cond wait failed at thread %d, error %d (%s)\n",
             tid, rv, strerror(rv));
      exit(1);
    }
  }
  if (0 != (rv = pthread_mutex_unlock(&gBarrierMu))) {
    printf("Mutex unlock failed at thread %d, error %d (%s)\n",
           tid, rv, strerror(rv));
    exit(1);
  }
  return ((void *)0);
}

variable_types:
state
void *

variable_types: tid int

variable_types: rv int

return_type: void *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // r13
unsigned __int64 v4; // r12
int v5; // eax
__int64 v6; // rax
const char **v7; // rbx
const char *v8; // rdx
const char *v9; // rsi
int v10; // eax
unsigned int v11; // ebx
char *v12; // rax
int v13; // eax
unsigned int v14; // ebp
int v15; // eax
unsigned int v16; // ebp
int v17; // eax
unsigned int v18; // ebp
int v19; // eax
char *v20; // rbp
unsigned __int64 i; // r14
int v22; // eax
char *v23; // rax
char *v24; // rax
char *v25; // rax
char *v26; // rax
char *v27; // rax
char *v28; // rax
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-68h] BYREF

v3 = 4096LL;
v4 = 0x4000LL;
while ( 2 )
{
v5 = getopt(argc, (char *const *)argv, "mfhn:s:v");
if ( v5 != -1 )
{
switch ( v5 )
{
case 'f':
gExpectThreadCreationFailure = 1;
continue;
case 'h':
v7 = (const char **)long_winded_explanation;
fprintf(
stderr,
"%s%s\n",
"Usage: egytian_cotton [-fhv] [-n num_threads] [-s bytes]\n",
" -f expect thread creation to fail for given\n"
" thread creation parameters\n"
" -h longer help\n"
" -v increase verbosity\n"
" -m use manual allocation of stacks\n"
" -n number of additional threads to create\n"
" -s stack size for each new thread\n");
v8 = long_winded_explanation[0];
if ( long_winded_explanation[0] )
{
do
{
++v7;
fprintf(stderr, " %s\n", v8);
v8 = *v7;
}
while ( *v7 );
}
LODWORD(v6) = 0;
return v6;
case 'm':
gAllocateStacksUsingMalloc = 1;
continue;
case 'n':
v3 = strtoul(optarg, 0LL, 0);
continue;
case 's':
v4 = strtoul(optarg, 0LL, 0);
continue;
case 'v':
++gVerbosity;
continue;
default:
fprintf(stderr, "%s\n", "Usage: egytian_cotton [-fhv] [-n num_threads] [-s bytes]\n");
LODWORD(v6) = 1;
return v6;
}
}
break;
}
if ( gVerbosity > 1 )
{
printf("Creating %zd threads with 0x%zx byte stacks\n", v3, v4);
v9 = " not";
if ( !gExpectThreadCreationFailure )
v9 = "";
printf("According to the command line parameters, this is%s expected to work.\n", v9);
}
v10 = pthread_attr_init(&attr);
v11 = v10;
if ( v10 )
{
v24 = strerror(v10);
printf("Pthread attr initializetion failed, error %d (%s)\n", v11, v24);
}
else
{
if ( !gAllocateStacksUsingMalloc )
{
v11 = pthread_attr_setstacksize(&attr, v4);
if ( v11 )
{
LABEL_20:
v12 = strerror(v11);
printf("Pthread stack size selection failed, error %d (%s)\n", v11, v12);
goto LABEL_21;
}
}
v19 = pthread_attr_setdetachstate(&attr, 1);
v11 = v19;
if ( v19 )
{
v25 = strerror(v19);
printf("Pthread detach state selection failed, error %d (%s)\n", v11, v25);
}
else
{
v20 = 0LL;
if ( !gAllocateStacksUsingMalloc || (v20 = (char *)malloc(v4 * v3)) != 0LL )
{
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
{
if ( gVerbosity > 0 )
{
printf("Creating thread %zd\n", i);
fflush(stdout);
}
if ( gAllocateStacksUsingMalloc )
{
v11 = pthread_attr_setstack(&attr, v20, v4);
if ( v11 )
goto LABEL_20;
}
v22 = pthread_create(&newthread, &attr, thread_start, (void *)i);
v11 = v22;
if ( v22 )
{
v23 = strerror(v22);
printf("Thread creation failed at thread %zd, error %d (%s)\n", i, v11, v23);
if ( gExpectThreadCreationFailure && v11 == 11 )
{
v11 = 0;
puts("This is expected.");
}
goto LABEL_21;
}
putchar(46);
if ( kCountMask == (i & kCountMask) )
printf("%zd", i);
if ( kNewlineMask == (i & kNewlineMask) )
putchar(10);
v20 += v4;
}
}
v11 = gExpectThreadCreationFailure;
if ( gExpectThreadCreationFailure )
{
v11 = 1;
puts("Expected thread creation failure.");
}
}
else
{
v11 = 12;
printf("Can not allocate memory for stacks");
}
}
}
LABEL_21:
v13 = pthread_mutex_lock(&gBarrierMu);
v14 = v13;
if ( v13 )
{
v28 = strerror(v13);
printf("Mutex lock failed at main thread, error %d (%s)\n", v14, v28);
exit(1);
}
gThreadWait = 0;
v15 = pthread_cond_broadcast(&gBarrierCv);
v16 = v15;
if ( v15 )
{
v27 = strerror(v15);
printf("Cond wait failed at main thread, error %d (%s)\n", v16, v27);
exit(1);
}
v17 = pthread_mutex_unlock(&gBarrierMu);
v18 = v17;
if ( v17 )
{
v26 = strerror(v17);
printf("Mutex unlock failed at main thread, error %d (%s)\n", v18, v26);
exit(1);
}
if ( v11 )
puts("FAILED");
else
puts("PASSED");
return v11 != 0;
}

original_code:
int main(int ac,
         char **av) {
  int opt;
  size_t num_threads = ((size_t) 0x1000);
  size_t stack_size = ((size_t) 0x4000);
  char const **line;
  int rv = 0;
  int cleanup_rv;
  pthread_t thr_state;
  pthread_attr_t attr;
  size_t tid;
  char *stacks = 0;
  while ((-1) != (opt = getopt(ac, av, "mfhn:s:v"))) {
    switch (opt) {
      case 'm':
        gAllocateStacksUsingMalloc = 1;
        break;
      case 'f':
        gExpectThreadCreationFailure = 1;
        break;
      case 'n':
        num_threads = strtoul(optarg, (char **) ((void *)0), 0);
        break;
      case 's':
        stack_size = strtoul(optarg, (char **) ((void *)0), 0);
        break;
      case 'v':
        ++gVerbosity;
        break;
      case 'h':
        fprintf(stderr, "%s%s\n", short_usage, flags_usage);
        for (line = long_winded_explanation; ((void *)0) != *line; ++line) {
          fprintf(stderr, "       %s\n", *line);
        }
        return 0;
      default:
        fprintf(stderr, "%s\n", short_usage);
        return 1;
    }
  }
  if (gVerbosity > 1) {
    printf("Creating %""zd"" threads with 0x%""zx"" byte stacks\n",
           num_threads,
           stack_size);
    printf("According to the command line parameters,"
           " this is%s expected to work.\n",
           gExpectThreadCreationFailure ? " not" : "");
  }
  if (0 != (rv = pthread_attr_init(&attr))) {
    printf("Pthread attr initializetion failed, error %d (%s)\n",
           rv, strerror(rv));
    goto cleanup_exit;
  }
  if (!gAllocateStacksUsingMalloc) {
    if (0 != (rv = pthread_attr_setstacksize(&attr, stack_size))) {
      printf("Pthread stack size selection failed, error %d (%s)\n",
             rv, strerror(rv));
      goto cleanup_exit;
    }
  }
  if (0 != (rv = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))) {
    printf("Pthread detach state selection failed, error %d (%s)\n",
           rv, strerror(rv));
    goto cleanup_exit;
  }
  if (gAllocateStacksUsingMalloc) {
    stacks = malloc(stack_size * num_threads);
    if (((void *)0) == stacks) {
      printf("Can not allocate memory for stacks");
      rv = 12;
      goto cleanup_exit;
    }
  }
  for (tid = 0; tid < num_threads; ++tid) {
    if (gVerbosity > 0) {
      printf("Creating thread %""zd""\n", tid); fflush(stdout);
    }
    if (gAllocateStacksUsingMalloc) {
      if (0 != (rv = pthread_attr_setstack(&attr, stacks + stack_size * tid,
                                           stack_size))) {
        printf("Pthread stack size selection failed, error %d (%s)\n",
               rv, strerror(rv));
        goto cleanup_exit;
      }
    }
    if (0 != (rv = pthread_create(&thr_state,
                                  &attr,
                                  thread_start,
                                  (void *) tid))) {
      printf("Thread creation failed at thread %""zd"", error %d (%s)\n",
             tid, rv, strerror(rv));
      if (gExpectThreadCreationFailure) {
        if (11 == rv) {
          printf("This is expected.\n");
          rv = 0;
          goto cleanup_exit;
        }
      }
      break;
    }
    putchar('.');
    if (kCountMask == (tid & kCountMask)) {
      printf("%""zd", tid);
    }
    if (kNewlineMask == (tid & kNewlineMask)) {
      putchar('\n');
    }
  }
  if (0 == rv && gExpectThreadCreationFailure) {
    printf("Expected thread creation failure.\n");
    rv = 1;
  }
cleanup_exit:
  if (0 != (cleanup_rv = pthread_mutex_lock(&gBarrierMu))) {
    printf("Mutex lock failed at main thread, error %d (%s)\n",
           cleanup_rv, strerror(cleanup_rv));
    exit(1);
  }
  gThreadWait = 0;
  if (0 != (cleanup_rv = pthread_cond_broadcast(&gBarrierCv))) {
    printf("Cond wait failed at main thread, error %d (%s)\n",
           cleanup_rv, strerror(cleanup_rv));
    exit(1);
  }
  if (0 != (cleanup_rv = pthread_mutex_unlock(&gBarrierMu))) {
    printf("Mutex unlock failed at main thread, error %d (%s)\n",
           cleanup_rv, strerror(cleanup_rv));
    exit(1);
  }
  if (0 == rv) {
    printf("PASSED\n");
  } else {
    printf("FAILED\n");
  }
  return rv != 0;
}

canonical_original_code:
int main(int ac, char **av) {
  int opt;
  unsigned long num_threads = ((size_t) 0x1000);
  unsigned long stack_size = ((size_t) 0x4000);
  char **line;
  int rv = 0;
  int cleanup_rv;
  unsigned long thr_state;
  union pthread_attr_t attr;
  unsigned long tid;
  char *stacks = 0;
  while ((-1) != (opt = getopt(ac, av, "mfhn:s:v"))) {
    switch (opt) {
      case 'm':
        gAllocateStacksUsingMalloc = 1;
        break;
      case 'f':
        gExpectThreadCreationFailure = 1;
        break;
      case 'n':
        num_threads = strtoul(optarg, (char **) ((void *)0), 0);
        break;
      case 's':
        stack_size = strtoul(optarg, (char **) ((void *)0), 0);
        break;
      case 'v':
        ++gVerbosity;
        break;
      case 'h':
        fprintf(stderr, "%s%s\n", short_usage, flags_usage);
        for (line = long_winded_explanation; ((void *)0) != *line; ++line) {
          fprintf(stderr, "       %s\n", *line);
        }
        return 0;
      default:
        fprintf(stderr, "%s\n", short_usage);
        return 1;
    }
  }
  if (gVerbosity > 1) {
    printf("Creating %""zd"" threads with 0x%""zx"" byte stacks\n",
           num_threads,
           stack_size);
    printf("According to the command line parameters,"
           " this is%s expected to work.\n",
           gExpectThreadCreationFailure ? " not" : "");
  }
  if (0 != (rv = pthread_attr_init(&attr))) {
    printf("Pthread attr initializetion failed, error %d (%s)\n",
           rv, strerror(rv));
    goto cleanup_exit;
  }
  if (!gAllocateStacksUsingMalloc) {
    if (0 != (rv = pthread_attr_setstacksize(&attr, stack_size))) {
      printf("Pthread stack size selection failed, error %d (%s)\n",
             rv, strerror(rv));
      goto cleanup_exit;
    }
  }
  if (0 != (rv = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))) {
    printf("Pthread detach state selection failed, error %d (%s)\n",
           rv, strerror(rv));
    goto cleanup_exit;
  }
  if (gAllocateStacksUsingMalloc) {
    stacks = malloc(stack_size * num_threads);
    if (((void *)0) == stacks) {
      printf("Can not allocate memory for stacks");
      rv = 12;
      goto cleanup_exit;
    }
  }
  for (tid = 0; tid < num_threads; ++tid) {
    if (gVerbosity > 0) {
      printf("Creating thread %""zd""\n", tid); fflush(stdout);
    }
    if (gAllocateStacksUsingMalloc) {
      if (0 != (rv = pthread_attr_setstack(&attr, stacks + stack_size * tid,
                                           stack_size))) {
        printf("Pthread stack size selection failed, error %d (%s)\n",
               rv, strerror(rv));
        goto cleanup_exit;
      }
    }
    if (0 != (rv = pthread_create(&thr_state,
                                  &attr,
                                  thread_start,
                                  (void *) tid))) {
      printf("Thread creation failed at thread %""zd"", error %d (%s)\n",
             tid, rv, strerror(rv));
      if (gExpectThreadCreationFailure) {
        if (11 == rv) {
          printf("This is expected.\n");
          rv = 0;
          goto cleanup_exit;
        }
      }
      break;
    }
    putchar('.');
    if (kCountMask == (tid & kCountMask)) {
      printf("%""zd", tid);
    }
    if (kNewlineMask == (tid & kNewlineMask)) {
      putchar('\n');
    }
  }
  if (0 == rv && gExpectThreadCreationFailure) {
    printf("Expected thread creation failure.\n");
    rv = 1;
  }
cleanup_exit:
  if (0 != (cleanup_rv = pthread_mutex_lock(&gBarrierMu))) {
    printf("Mutex lock failed at main thread, error %d (%s)\n",
           cleanup_rv, strerror(cleanup_rv));
    exit(1);
  }
  gThreadWait = 0;
  if (0 != (cleanup_rv = pthread_cond_broadcast(&gBarrierCv))) {
    printf("Cond wait failed at main thread, error %d (%s)\n",
           cleanup_rv, strerror(cleanup_rv));
    exit(1);
  }
  if (0 != (cleanup_rv = pthread_mutex_unlock(&gBarrierMu))) {
    printf("Mutex unlock failed at main thread, error %d (%s)\n",
           cleanup_rv, strerror(cleanup_rv));
    exit(1);
  }
  if (0 == rv) {
    printf("PASSED\n");
  } else {
    printf("FAILED\n");
  }
  return rv != 0;
}

variable_types: ac int

variable_types:
av
char **

variable_types: opt int

variable_types:
line
char **

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types:
tid
unsigned long

variable_types:
stacks
char *


addbyte

decompiled_code:
void __fastcall addbyte(void *src, void *dest, int a3, int a4)
{
int v4; // er13
int v5; // er12
_BYTE *v6; // r8
__int64 v7; // rax
int v8; // eax
__int64 v9; // rax
int v10; // ecx
int v11; // edx
int v12; // edx
_BYTE v13[400040]; // [rsp+0h] [rbp-61AA8h] BYREF

v4 = a3;
v5 = a4;
if ( a3 >= a4 )
{
if ( a3 > 0 )
goto LABEL_8;
}
else
{
if ( a4 <= 0 )
{
if ( a3 <= 0 )
return;
}
else
{
v6 = memcpy(v13, src, 4LL * a4);
if ( v4 <= 0 )
{
LABEL_7:
memcpy(dest, v6, 4LL * (unsigned int)(v5 - 1) + 4);
v8 = v4;
v4 = v5;
v5 = v8;
LABEL_8:
v9 = 0LL;
v10 = 0;
while ( 1 )
{
if ( v5 <= (int)v9 )
goto LABEL_18;
if ( *(_DWORD *)src )
{
if ( *(_DWORD *)src != 1 )
goto LABEL_18;
v11 = *(_DWORD *)dest;
if ( *(_DWORD *)dest )
goto LABEL_17;
if ( !v10 )
goto LABEL_35;
}
else
{
if ( !*(_DWORD *)dest )
{
addvalue[v9] = 1;
v10 = *(_DWORD *)src;
if ( *(_DWORD *)src )
{
if ( v10 != 1 )
goto LABEL_25;
}
else
{
if ( *(_DWORD *)dest != 1 )
goto LABEL_18;
LABEL_33:
addvalue[v9] = 1;
if ( *(_DWORD *)src != 1 )
goto LABEL_25;
}
if ( *(_DWORD *)dest )
{
if ( *(_DWORD *)dest == 1 )
{
LABEL_40:
addvalue[v9] = 0;
v10 = 1;
goto LABEL_18;
}
LABEL_25:
v10 = 0;
goto LABEL_18;
}
LABEL_35:
addvalue[v9] = 1;
v10 = 0;
v12 = *(_DWORD *)src;
goto LABEL_15;
}
if ( *(_DWORD *)dest != 1 )
goto LABEL_18;
if ( !v10 )
goto LABEL_33;
addvalue[v9] = 0;
if ( *(_DWORD *)src != 1 )
goto LABEL_18;
if ( *(_DWORD *)dest )
{
if ( *(_DWORD *)dest == 1 )
goto LABEL_37;
goto LABEL_38;
}
}
addvalue[v9] = 0;
v12 = *(_DWORD *)src;
v10 = 1;
LABEL_15:
if ( v12 != 1 )
goto LABEL_18;
v11 = *(_DWORD *)dest;
LABEL_17:
if ( v11 == 1 )
{
if ( !v10 )
goto LABEL_40;
LABEL_37:
addvalue[v9] = 1;
LABEL_38:
v10 = 1;
}
LABEL_18:
++v9;
dest = (char *)dest + 4;
src = (char *)src + 4;
if ( v4 <= (int)v9 )
return;
}
}
}
v7 = 0LL;
do
{
*((_DWORD *)src + v7) = *((_DWORD *)dest + v7);
++v7;
}
while ( v4 != v7 );
v6 = v13;
if ( v5 > 0 )
goto LABEL_7;
}
}

canonical_decompiled_code:
void __fastcall func0(void *src, void *dest, int a3, int a4)
{
int v4; // er13
int v5; // er12
_BYTE *v6; // r8
__int64 v7; // rax
int v8; // eax
__int64 v9; // rax
int v10; // ecx
int v11; // edx
int v12; // edx
_BYTE v13[400040]; // [rsp+0h] [rbp-61AA8h] BYREF

v4 = a3;
v5 = a4;
if ( a3 >= a4 )
{
if ( a3 > 0 )
goto LABEL_8;
}
else
{
if ( a4 <= 0 )
{
if ( a3 <= 0 )
return;
}
else
{
v6 = memcpy(v13, src, 4LL * a4);
if ( v4 <= 0 )
{
LABEL_7:
memcpy(dest, v6, 4LL * (unsigned int)(v5 - 1) + 4);
v8 = v4;
v4 = v5;
v5 = v8;
LABEL_8:
v9 = 0LL;
v10 = 0;
while ( 1 )
{
if ( v5 <= (int)v9 )
goto LABEL_18;
if ( *(_DWORD *)src )
{
if ( *(_DWORD *)src != 1 )
goto LABEL_18;
v11 = *(_DWORD *)dest;
if ( *(_DWORD *)dest )
goto LABEL_17;
if ( !v10 )
goto LABEL_35;
}
else
{
if ( !*(_DWORD *)dest )
{
addvalue[v9] = 1;
v10 = *(_DWORD *)src;
if ( *(_DWORD *)src )
{
if ( v10 != 1 )
goto LABEL_25;
}
else
{
if ( *(_DWORD *)dest != 1 )
goto LABEL_18;
LABEL_33:
addvalue[v9] = 1;
if ( *(_DWORD *)src != 1 )
goto LABEL_25;
}
if ( *(_DWORD *)dest )
{
if ( *(_DWORD *)dest == 1 )
{
LABEL_40:
addvalue[v9] = 0;
v10 = 1;
goto LABEL_18;
}
LABEL_25:
v10 = 0;
goto LABEL_18;
}
LABEL_35:
addvalue[v9] = 1;
v10 = 0;
v12 = *(_DWORD *)src;
goto LABEL_15;
}
if ( *(_DWORD *)dest != 1 )
goto LABEL_18;
if ( !v10 )
goto LABEL_33;
addvalue[v9] = 0;
if ( *(_DWORD *)src != 1 )
goto LABEL_18;
if ( *(_DWORD *)dest )
{
if ( *(_DWORD *)dest == 1 )
goto LABEL_37;
goto LABEL_38;
}
}
addvalue[v9] = 0;
v12 = *(_DWORD *)src;
v10 = 1;
LABEL_15:
if ( v12 != 1 )
goto LABEL_18;
v11 = *(_DWORD *)dest;
LABEL_17:
if ( v11 == 1 )
{
if ( !v10 )
goto LABEL_40;
LABEL_37:
addvalue[v9] = 1;
LABEL_38:
v10 = 1;
}
LABEL_18:
++v9;
dest = (char *)dest + 4;
src = (char *)src + 4;
if ( v4 <= (int)v9 )
return;
}
}
}
v7 = 0LL;
do
{
*((_DWORD *)src + v7) = *((_DWORD *)dest + v7);
++v7;
}
while ( v4 != v7 );
v6 = v13;
if ( v5 > 0 )
goto LABEL_7;
}
}

original_code:
void addbyte(int temp1[],int temp2[],int u,int v)
{
 int carry=0;
 int i,j,t,f=0,t1[100000];
 if(u<v)
 {
  t=u;
  u=v;
  v=t;
  for(i=0;i<u;i++)
  {
   t1[i]=temp1[i];
  }
  for(i=0;i<v;i++)
  {
   temp1[i]=temp2[i];
  }
  for(i=0;i<u;i++)
  {
   temp2[i]=t1[i];
  }
 }
 if(f==0)
 {
  for(i=0,j=0;i<u;i++,j++)
     {
   if(j<v)
   {
    if((temp1[i]==0)&&(temp2[j]==0))
    {
     if(carry=0)
     addvalue[i]=0;
     else
     {
      addvalue[i]=1;
      carry=0;
     }
    }
    if((temp1[i]==0)&&(temp2[j]==1))
    {
     if(carry==0)
     addvalue[i]=1;
     else
     addvalue[i]=0;
    }
    if((temp1[i]==1)&&(temp2[j]==0))
    {
     if(carry==0)
     addvalue[i]=1;
     else
     addvalue[i]=0;
    }
    if((temp1[i]==1)&&(temp2[j]==1))
    {
     if(carry==0)
     {
      addvalue[i]=0;
      carry=1;
     }
     else
     addvalue[i]=1;
    }
   }
   if((carry!=0)&&(j>=u))
   {
    if(temp1[i]==0)
    {
     addvalue[i]=1;
     carry=0;
    }
    else
    addvalue[i]=0;
   }
   if((carry==0)&&(j>=u))
   addvalue[i]=temp1[i];
  }
 }
}

canonical_original_code:
void addbyte(int temp1[], int temp2[], int u, int v)
{
 int carry = 0;
 int i; int j; int t; int f = 0; int t1[100000];
 if(u<v)
 {
  t=u;
  u=v;
  v=t;
  for(i=0;i<u;i++)
  {
   t1[i]=temp1[i];
  }
  for(i=0;i<v;i++)
  {
   temp1[i]=temp2[i];
  }
  for(i=0;i<u;i++)
  {
   temp2[i]=t1[i];
  }
 }
 if(f==0)
 {
  for(i=0,j=0;i<u;i++,j++)
     {
   if(j<v)
   {
    if((temp1[i]==0)&&(temp2[j]==0))
    {
     if(carry=0)
     addvalue[i]=0;
     else
     {
      addvalue[i]=1;
      carry=0;
     }
    }
    if((temp1[i]==0)&&(temp2[j]==1))
    {
     if(carry==0)
     addvalue[i]=1;
     else
     addvalue[i]=0;
    }
    if((temp1[i]==1)&&(temp2[j]==0))
    {
     if(carry==0)
     addvalue[i]=1;
     else
     addvalue[i]=0;
    }
    if((temp1[i]==1)&&(temp2[j]==1))
    {
     if(carry==0)
     {
      addvalue[i]=0;
      carry=1;
     }
     else
     addvalue[i]=1;
    }
   }
   if((carry!=0)&&(j>=u))
   {
    if(temp1[i]==0)
    {
     addvalue[i]=1;
     carry=0;
    }
    else
    addvalue[i]=0;
   }
   if((carry==0)&&(j>=u))
   addvalue[i]=temp1[i];
  }
 }
}

variable_types: u int

variable_types: v int

variable_types: carry int

variable_types: j int

variable_types: t int

variable_types: f int


changebyte

original_code:
void changebyte(int temp4[],int u)
{
 int i,s,w=0,v=0;
 s=0;
 for(i=0;i<u;i++)
 {
  if((i%8)==7)
  {
   tweakbyte[w]=s;
   s=0;
   v=0;
   w=w+1;
  }
  s=s+pow(2,v)*temp4[i];
 }
}

canonical_original_code:
void changebyte(int temp4[], int u)
{
 int i; int s; int w = 0; int v = 0;
 s=0;
 for(i=0;i<u;i++)
 {
  if((i%8)==7)
  {
   tweakbyte[w]=s;
   s=0;
   v=0;
   w=w+1;
  }
  s=s+pow(2,v)*temp4[i];
 }
}

variable_types: i int

variable_types: s int

variable_types: w int


ubiimplement

decompiled_code:
__int64 ubiimplement()
{
int v0; // er12
__int64 v1; // rax
char v2; // dl
unsigned int v3; // er8
__int64 result; // rax
int v5; // ebp
int v6; // ebx
int v7; // eax
__int64 v8; // rcx
unsigned int v9; // er13
__int64 i; // rax
int v11; // ecx
__int64 v12; // rdx
__int64 j; // rax
int v14; // ecx
__int64 v15; // rdx
int v16; // edx
__int64 v17; // rax
char v18; // si
__int64 v19; // rcx
__int64 v20; // rsi
int v21[16]; // [rsp+0h] [rbp-620E8h] BYREF
char v22[504]; // [rsp+40h] [rbp-620A8h] BYREF
int v23; // [rsp+238h] [rbp-61EB0h]
int v24[128]; // [rsp+240h] [rbp-61EA8h] BYREF
char v25[504]; // [rsp+440h] [rbp-61CA8h] BYREF
int v26; // [rsp+638h] [rbp-61AB0h]
int v27; // [rsp+63Ch] [rbp-61AACh]
char v28[400040]; // [rsp+640h] [rbp-61AA8h] BYREF

v0 = sizeofplaintext;
if ( (sizeofplaintext & 0x1F) != 0 )
{
v1 = sizeofplaintext + 1;
do
{
plaintext[v1 - 1] = 0;
v2 = v1;
v3 = v1++;
}
while ( (v2 & 0x1F) != 0 );
sizeofplaintext = v3;
}
else
{
v3 = sizeofplaintext;
}
result = bytestowords(plaintext, 0LL, v3);
if ( sizeofplaintext > 31 )
{
v5 = 1024;
v6 = 1;
if ( v0 >= 1024 )
v5 = v0;
do
{
v7 = v5;
v8 = 1LL;
do
{
v9 = v8;
*(&v27 + v8++) = v7 % 2;
v7 /= 2;
}
while ( v7 );
for ( i = 0LL; i != -128; --i )
{
v11 = tweak[i + 127];
v12 = i * 4;
*(int *)((char *)v24 - v12) = v11;
}
addbyte(v24, v28, 128LL, v9);
if ( (int)v9 < 128 )
v9 = 128;
if ( v6 == 1 )
{
v23 = 1;
memset(v22, 0, sizeof(v22));
addbyte(&addvalue, v22, v9, 127LL);
if ( sizeofplaintext == 2 )
{
LABEL_27:
memset(v25, 0, sizeof(v25));
v26 = 0;
v27 = 1;
addbyte(&addvalue, v25, v9, 128LL);
goto LABEL_16;
}
}
else if ( sizeofplaintext - 1 == v6 )
{
goto LABEL_27;
}
LABEL_16:
changebyte(&addvalue, v9);
for ( j = 0LL; j != -16; --j )
{
v14 = tweakbyte[j + 15];
v15 = j * 4;
*(int *)((char *)v21 - v15) = v14;
}
bytestowords(blockcipherkey, 1LL, 32LL);
bytestowords(v21, 2LL, 16LL);
keyschedule();
rounds();
v16 = move1;
v17 = 0LL;
v18 = 0;
do
{
v19 = ciphertext[v17];
blockcipherkey[v17] = v19;
if ( v16 < v0 )
{
v20 = v16++;
entireciphertext[v20] = v19;
v18 = 1;
}
++v17;
}
while ( v17 != 32 );
if ( v18 )
move1 = v16;
++v6;
result = (unsigned int)(sizeofplaintext / 32);
}
while ( (int)result >= v6 );
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // er12
__int64 v1; // rax
char v2; // dl
unsigned int v3; // er8
__int64 result; // rax
int v5; // ebp
int v6; // ebx
int v7; // eax
__int64 v8; // rcx
unsigned int v9; // er13
__int64 i; // rax
int v11; // ecx
__int64 v12; // rdx
__int64 j; // rax
int v14; // ecx
__int64 v15; // rdx
int v16; // edx
__int64 v17; // rax
char v18; // si
__int64 v19; // rcx
__int64 v20; // rsi
int v21[16]; // [rsp+0h] [rbp-620E8h] BYREF
char v22[504]; // [rsp+40h] [rbp-620A8h] BYREF
int v23; // [rsp+238h] [rbp-61EB0h]
int v24[128]; // [rsp+240h] [rbp-61EA8h] BYREF
char v25[504]; // [rsp+440h] [rbp-61CA8h] BYREF
int v26; // [rsp+638h] [rbp-61AB0h]
int v27; // [rsp+63Ch] [rbp-61AACh]
char v28[400040]; // [rsp+640h] [rbp-61AA8h] BYREF

v0 = sizeofplaintext;
if ( (sizeofplaintext & 0x1F) != 0 )
{
v1 = sizeofplaintext + 1;
do
{
plaintext[v1 - 1] = 0;
v2 = v1;
v3 = v1++;
}
while ( (v2 & 0x1F) != 0 );
sizeofplaintext = v3;
}
else
{
v3 = sizeofplaintext;
}
result = bytestowords(plaintext, 0LL, v3);
if ( sizeofplaintext > 31 )
{
v5 = 1024;
v6 = 1;
if ( v0 >= 1024 )
v5 = v0;
do
{
v7 = v5;
v8 = 1LL;
do
{
v9 = v8;
*(&v27 + v8++) = v7 % 2;
v7 /= 2;
}
while ( v7 );
for ( i = 0LL; i != -128; --i )
{
v11 = tweak[i + 127];
v12 = i * 4;
*(int *)((char *)v24 - v12) = v11;
}
addbyte(v24, v28, 128LL, v9);
if ( (int)v9 < 128 )
v9 = 128;
if ( v6 == 1 )
{
v23 = 1;
memset(v22, 0, sizeof(v22));
addbyte(&addvalue, v22, v9, 127LL);
if ( sizeofplaintext == 2 )
{
LABEL_27:
memset(v25, 0, sizeof(v25));
v26 = 0;
v27 = 1;
addbyte(&addvalue, v25, v9, 128LL);
goto LABEL_16;
}
}
else if ( sizeofplaintext - 1 == v6 )
{
goto LABEL_27;
}
LABEL_16:
changebyte(&addvalue, v9);
for ( j = 0LL; j != -16; --j )
{
v14 = tweakbyte[j + 15];
v15 = j * 4;
*(int *)((char *)v21 - v15) = v14;
}
bytestowords(blockcipherkey, 1LL, 32LL);
bytestowords(v21, 2LL, 16LL);
keyschedule();
rounds();
v16 = move1;
v17 = 0LL;
v18 = 0;
do
{
v19 = ciphertext[v17];
blockcipherkey[v17] = v19;
if ( v16 < v0 )
{
v20 = v16++;
entireciphertext[v20] = v19;
v18 = 1;
}
++v17;
}
while ( v17 != 32 );
if ( v18 )
move1 = v16;
++v6;
result = (unsigned int)(sizeofplaintext / 32);
}
while ( (int)result >= v6 );
}
return result;
}

original_code:
void ubiimplement(void)
{
 int originalsize,i1,mini,w,j,tempe[100000],tempe1[128],i,tempe2[127],maxaddvalue,tempe3[128],tweakbyte1[16];
 originalsize=sizeofplaintext;
 while((sizeofplaintext%32)!=0)
 {
  plaintext[sizeofplaintext]=0;
  sizeofplaintext=sizeofplaintext+1;
 }
 bytestowords(plaintext,0,sizeofplaintext);
 for(i1=1;i1<=(sizeofplaintext/32);i1++)
 {
  mini=originalsize;
  if(mini<(i*32))
  mini=(i*32);
  w=0;
  for(j=mini;j!=0;j=(j/2))
  {
   tempe[w]=(j%2);
   w=w+1;
  }
  for(i=0,j=127;i<128;i++,j--)
  {
   tempe1[i]=tweak[j];
  }
  addbyte(tempe1,tempe,128,w);
  if(w>128)
  maxaddvalue=w;
  else
  maxaddvalue=128;
  if((i1-1)==0)
  {
   for(i=0;i<126;i++)
   {
    tempe2[i]=0;
   }
   tempe2[i]=1;
   addbyte(addvalue,tempe2,maxaddvalue,127);
   if(maxaddvalue<127)
   maxaddvalue=127;
  }
  if(i1==(sizeofplaintext-1))
  {
   for(i=0;i<127;i++)
   {
    tempe3[i]=0;
   }
   tempe3[i]=1;
   addbyte(addvalue,tempe3,maxaddvalue,128);
   if(maxaddvalue<128)
   maxaddvalue=128;
  }
  changebyte(addvalue,maxaddvalue);
  for(i=0,j=15;i<16;i++,j--)
  {
   tweakbyte1[i]=tweakbyte[j];
  }
  bytestowords(blockcipherkey,1,32);
  bytestowords(tweakbyte1,2,16);
  keyschedule();
  rounds();
  for(i=0;i<32;i++)
  {
   blockcipherkey[i]=ciphertext[i];
   if(move1<originalsize)
   {
    entireciphertext[move1]=ciphertext[i];
    move1=move1+1;
   }
  }
 }
}

canonical_original_code:
void ubiimplement()
{
 int originalsize; int i1; int mini; int w; int j; int tempe[100000]; int tempe1[128]; int i; int tempe2[127]; int maxaddvalue; int tempe3[128]; int tweakbyte1[16];
 originalsize=sizeofplaintext;
 while((sizeofplaintext%32)!=0)
 {
  plaintext[sizeofplaintext]=0;
  sizeofplaintext=sizeofplaintext+1;
 }
 bytestowords(plaintext,0,sizeofplaintext);
 for(i1=1;i1<=(sizeofplaintext/32);i1++)
 {
  mini=originalsize;
  if(mini<(i*32))
  mini=(i*32);
  w=0;
  for(j=mini;j!=0;j=(j/2))
  {
   tempe[w]=(j%2);
   w=w+1;
  }
  for(i=0,j=127;i<128;i++,j--)
  {
   tempe1[i]=tweak[j];
  }
  addbyte(tempe1,tempe,128,w);
  if(w>128)
  maxaddvalue=w;
  else
  maxaddvalue=128;
  if((i1-1)==0)
  {
   for(i=0;i<126;i++)
   {
    tempe2[i]=0;
   }
   tempe2[i]=1;
   addbyte(addvalue,tempe2,maxaddvalue,127);
   if(maxaddvalue<127)
   maxaddvalue=127;
  }
  if(i1==(sizeofplaintext-1))
  {
   for(i=0;i<127;i++)
   {
    tempe3[i]=0;
   }
   tempe3[i]=1;
   addbyte(addvalue,tempe3,maxaddvalue,128);
   if(maxaddvalue<128)
   maxaddvalue=128;
  }
  changebyte(addvalue,maxaddvalue);
  for(i=0,j=15;i<16;i++,j--)
  {
   tweakbyte1[i]=tweakbyte[j];
  }
  bytestowords(blockcipherkey,1,32);
  bytestowords(tweakbyte1,2,16);
  keyschedule();
  rounds();
  for(i=0;i<32;i++)
  {
   blockcipherkey[i]=ciphertext[i];
   if(move1<originalsize)
   {
    entireciphertext[move1]=ciphertext[i];
    move1=move1+1;
   }
  }
 }
}

variable_types: originalsize int

variable_types: mini int

variable_types:
tempe
int [100000]

variable_types: maxaddvalue int


repo: sbksba/Delaunay

decompiled_code:
__int64 Graphique_ResetPerspectiveProjection()
{
glMatrixMode(5889LL);
glPopMatrix();
return glMatrixMode(5888LL);
}

canonical_decompiled_code:
__int64 func0()
{
glMatrixMode(5889LL);
glPopMatrix();
return glMatrixMode(5888LL);
}

original_code:
void Graphique_ResetPerspectiveProjection()
{
 glMatrixMode(0x1701);
 glPopMatrix();
 glMatrixMode(0x1700);
}


decompiled_code:
__int64 Graphique_SetOrthographicProjection()
{
glMatrixMode(5889LL);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
glScalef(1.0, -1.0);
glTranslatef(0.0, -480.0);
return glMatrixMode(5888LL);
}

canonical_decompiled_code:
__int64 func1()
{
glMatrixMode(5889LL);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
glScalef(1.0, -1.0);
glTranslatef(0.0, -480.0);
return glMatrixMode(5888LL);
}

original_code:
void Graphique_SetOrthographicProjection()
{
 glMatrixMode(0x1701);
 glPushMatrix();
 glLoadIdentity();
 gluOrtho2D(0,640, 0, 480);
 glScalef(1, -1, 1);
 glTranslatef(0, -480, 0);
 glMatrixMode(0x1700);
}


original_code:
void Graphique_Dessin3D()
{
 SLTriangle *tmp;
 STriangle *t;
 tmp = tab.triangles->first;
 glColor3f(0.0,1.0,0.0);
 while(tmp!=((void *)0))
  {
  glPolygonMode(0x0408, 0x1B01);
  t=tmp->t;
  if((t->p1>3)&&(t->p2>3)&&(t->p3>3))
   {
   glBegin(0x0004);
    glVertex3d(tab.p[t->p1].x,tab.p[t->p1].y,tab.p[t->p1].z);
    glVertex3d(tab.p[t->p2].x,tab.p[t->p2].y,tab.p[t->p2].z);
    glVertex3d(tab.p[t->p3].x,tab.p[t->p3].y,tab.p[t->p3].z);
   glEnd();
   }
  tmp = tmp->next;
  }
 tmp = tab.triangles->first;
 glColor3f(0.0,0.0,0.0);
 glPolygonMode(0x0408, 0x1B02);
 glEnable(0x8037);
 glPolygonOffset(1.0,1.0);
 glBegin(0x0004);
  while(tmp!=((void *)0))
   {
   t=tmp->t;
   if((t->p1>3)&&(t->p2>3)&&(t->p3>3))
    {
    glVertex3d(tab.p[t->p1].x,tab.p[t->p1].y,tab.p[t->p1].z);
    glVertex3d(tab.p[t->p2].x,tab.p[t->p2].y,tab.p[t->p2].z);
    glVertex3d(tab.p[t->p3].x,tab.p[t->p3].y,tab.p[t->p3].z);
    }
   tmp = tmp->next;
   }
 glEnd();
 glDisable(0x8037);
}

canonical_original_code:
void Graphique_Dessin3D()
{
 struct sLTriangle *tmp;
 struct sTriangle *t;
 tmp = tab.triangles->first;
 glColor3f(0.0,1.0,0.0);
 while(tmp!=((void *)0))
  {
  glPolygonMode(0x0408, 0x1B01);
  t=tmp->t;
  if((t->p1>3)&&(t->p2>3)&&(t->p3>3))
   {
   glBegin(0x0004);
    glVertex3d(tab.p[t->p1].x,tab.p[t->p1].y,tab.p[t->p1].z);
    glVertex3d(tab.p[t->p2].x,tab.p[t->p2].y,tab.p[t->p2].z);
    glVertex3d(tab.p[t->p3].x,tab.p[t->p3].y,tab.p[t->p3].z);
   glEnd();
   }
  tmp = tmp->next;
  }
 tmp = tab.triangles->first;
 glColor3f(0.0,0.0,0.0);
 glPolygonMode(0x0408, 0x1B02);
 glEnable(0x8037);
 glPolygonOffset(1.0,1.0);
 glBegin(0x0004);
  while(tmp!=((void *)0))
   {
   t=tmp->t;
   if((t->p1>3)&&(t->p2>3)&&(t->p3>3))
    {
    glVertex3d(tab.p[t->p1].x,tab.p[t->p1].y,tab.p[t->p1].z);
    glVertex3d(tab.p[t->p2].x,tab.p[t->p2].y,tab.p[t->p2].z);
    glVertex3d(tab.p[t->p3].x,tab.p[t->p3].y,tab.p[t->p3].z);
    }
   tmp = tmp->next;
   }
 glEnd();
 glDisable(0x8037);
}

variable_types: struct sLTriangle { struct sTriangle { int type; int flip_param; int p1; struct sTriangle *t1; struct sPoint { double x; } centre; double rayon; double critere; } *t; struct sLTriangle *next; } *

user_defined_types: struct sLTriangle { struct sTriangle *t; struct sLTriangle *next; }

user_defined_types: struct sTriangle { int type; int flip_param; int p1; struct sTriangle *t1; struct sPoint centre; double rayon; double critere; }


variable_types:
v
double *

variable_types: height double