repo: gittoken/pthread

decompiled_code:
void *__fastcall functionCount1(void *a1)
{
do
{
pthread_mutex_lock(&condition_mutex);
if ( (unsigned int)(count - 3) <= 3 )
pthread_cond_wait(&condition_cond, &condition_mutex);
pthread_mutex_unlock(&condition_mutex);
pthread_mutex_lock(&count_mutex);
printf("counter value functionCount1:%d\n", (unsigned int)++count);
pthread_mutex_unlock(&count_mutex);
}
while ( count <= 9 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
do
{
pthread_mutex_lock(&condition_mutex);
if ( (unsigned int)(count - 3) <= 3 )
pthread_cond_wait(&condition_cond, &condition_mutex);
pthread_mutex_unlock(&condition_mutex);
pthread_mutex_lock(&count_mutex);
printf("counter value functionCount1:%d\n", (unsigned int)++count);
pthread_mutex_unlock(&count_mutex);
}
while ( count <= 9 );
return 0LL;
}

original_code:
void *functionCount1()
{
    for(;;)
    {
        pthread_mutex_lock(&condition_mutex);
        if(count >= 3 && count <= 6)
        {
            pthread_cond_wait(&condition_cond, &condition_mutex);
        }
        pthread_mutex_unlock(&condition_mutex);
        pthread_mutex_lock(&count_mutex);
        count++;
        printf("counter value functionCount1:%d\n", count);
        pthread_mutex_unlock(&count_mutex);
        if(count >= 10)
            return ((void *)0);
    }
}

return_type: void *


decompiled_code:
void *__fastcall functionCount2(void *a1)
{
do
{
pthread_mutex_lock(&condition_mutex);
if ( (unsigned int)(count - 3) > 3 )
pthread_cond_signal(&condition_cond);
pthread_mutex_unlock(&condition_mutex);
pthread_mutex_lock(&count_mutex);
printf("counter value functionCount2:%d \n", (unsigned int)++count);
pthread_mutex_unlock(&count_mutex);
}
while ( count <= 9 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
do
{
pthread_mutex_lock(&condition_mutex);
if ( (unsigned int)(count - 3) > 3 )
pthread_cond_signal(&condition_cond);
pthread_mutex_unlock(&condition_mutex);
pthread_mutex_lock(&count_mutex);
printf("counter value functionCount2:%d \n", (unsigned int)++count);
pthread_mutex_unlock(&count_mutex);
}
while ( count <= 9 );
return 0LL;
}

original_code:
void *functionCount2()
{
    for(;;)
    {
        pthread_mutex_lock(&condition_mutex);
        if(count < 3 || count > 6)
        {
            pthread_cond_signal(&condition_cond);
        }
        pthread_mutex_unlock(&condition_mutex);
        pthread_mutex_lock(&count_mutex);
        count++;
        printf("counter value functionCount2:%d \n", count);
        pthread_mutex_unlock(&count_mutex);
        if(count >= 10)
            return ((void *)0);
    }
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

pthread_create(&th, 0LL, functionCount1, 0LL);
pthread_create(newthread, 0LL, functionCount2, 0LL);
pthread_join(th, 0LL);
pthread_join(newthread[0], 0LL);
exit(0);
}

original_code:
int main(int argc, char **argv)
{
    pthread_t thread1, thread2;
    pthread_create(&thread1, ((void *)0), &functionCount1, ((void *)0));
    pthread_create(&thread2, ((void *)0), &functionCount2, ((void *)0));
    pthread_join(thread1, ((void *)0));
    pthread_join(thread2, ((void *)0));
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned long thread1; unsigned long thread2;
    pthread_create(&thread1, ((void *)0), &functionCount1, ((void *)0));
    pthread_create(&thread2, ((void *)0), &functionCount2, ((void *)0));
    pthread_join(thread1, ((void *)0));
    pthread_join(thread2, ((void *)0));
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


decompiled_code:
void __fastcall __noreturn thread_function(void *a1)
{
int v1; // ebx

v1 = 3;
while ( 1 )
{
if ( !pthread_mutex_lock(&mutex) )
puts("thread lock. ");
if ( run_now == 1 )
{
puts("function thread is run. ");
run_now = 2;
pthread_mutex_lock(&condition_mutex);
pthread_cond_signal(&condition_cond);
pthread_mutex_unlock(&condition_mutex);
if ( !pthread_mutex_unlock(&mutex) )
{
LABEL_9:
puts("thread unlock. ");
goto LABEL_6;
}
}
else
{
puts("function thread is sleep:");
usleep(0xAu);
if ( !pthread_mutex_unlock(&mutex) )
goto LABEL_9;
}
LABEL_6:
if ( !--v1 )
pthread_exit(0LL);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // ebx

v1 = 3;
while ( 1 )
{
if ( !pthread_mutex_lock(&mutex) )
puts("thread lock. ");
if ( run_now == 1 )
{
puts("function thread is run. ");
run_now = 2;
pthread_mutex_lock(&condition_mutex);
pthread_cond_signal(&condition_cond);
pthread_mutex_unlock(&condition_mutex);
if ( !pthread_mutex_unlock(&mutex) )
{
LABEL_9:
puts("thread unlock. ");
goto LABEL_6;
}
}
else
{
puts("function thread is sleep:");
usleep(0xAu);
if ( !pthread_mutex_unlock(&mutex) )
goto LABEL_9;
}
LABEL_6:
if ( !--v1 )
pthread_exit(0LL);
}
}

original_code:
void *thread_function(void *arg)
{
    int print_count2 = 0;
    while(print_count2++ < 3)
    {
        if(pthread_mutex_lock(&mutex) == 0)
        {
            printf("thread lock. \n");
        }
        if(run_now == 1)
        {
            printf("function thread is run. \n");
            run_now = 2;
            pthread_mutex_lock(&condition_mutex);
            pthread_cond_signal(&condition_cond);
            pthread_mutex_unlock(&condition_mutex);
        }
        else
        {
            printf("function thread is sleep:\n");
            usleep(10);
        }
        if(pthread_mutex_unlock(&mutex) == 0)
        {
            printf("thread unlock. \n");
        }
    }
    pthread_exit(((void *)0));
}

variable_types:
arg
void *


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = 2;
if ( !pthread_create(newthread, 0LL, thread_function, 0LL) )
{
while ( 1 )
{
pthread_mutex_lock(&condition_mutex);
puts("main cond_mutex lock. ");
pthread_cond_wait(&condition_cond, &condition_mutex);
pthread_mutex_unlock(&condition_mutex);
puts("main cond_mutex unlock. ");
if ( !pthread_mutex_lock(&mutex) )
puts("main lock. ");
if ( run_now == 2 )
{
puts("main thread is run .");
run_now = 1;
}
else
{
puts("main thread is sleep");
usleep(0xAu);
}
if ( !pthread_mutex_unlock(&mutex) )
puts("main unlock. ");
if ( v3 == 1 )
{
pthread_mutex_destroy(&mutex);
pthread_join(newthread[0], 0LL);
exit(0);
}
v3 = 1;
}
}
perror("thread creation failed.\n");
exit(1);
}

original_code:
int main(int argc, char **argv)
{
    int print_count1 = 0;
    pthread_t a_thread;
    if(pthread_create(&a_thread, ((void *)0), thread_function, ((void *)0)) != 0 )
    {
        perror("thread creation failed.\n");
        exit(1);
    }
    while(print_count1++ < 2)
    {
        pthread_mutex_lock(&condition_mutex);
        printf("main cond_mutex lock. \n");
        pthread_cond_wait(&condition_cond, &condition_mutex);
        pthread_mutex_unlock(&condition_mutex);
        printf("main cond_mutex unlock. \n");
        if(pthread_mutex_lock(&mutex) == 0)
        {
            printf("main lock. \n");
        }
        if(run_now == 2)
        {
            printf("main thread is run .\n");
           run_now = 1;
        }
        else
        {
            printf("main thread is sleep\n");
            usleep(10);
        }
        if(pthread_mutex_unlock(&mutex) == 0)
        {
            printf("main unlock. \n");
        }
    }
    pthread_mutex_destroy(&mutex);
    pthread_join(a_thread, ((void *)0));
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    int print_count1 = 0;
    unsigned long a_thread;
    if(pthread_create(&a_thread, ((void *)0), thread_function, ((void *)0)) != 0 )
    {
        perror("thread creation failed.\n");
        exit(1);
    }
    while(print_count1++ < 2)
    {
        pthread_mutex_lock(&condition_mutex);
        printf("main cond_mutex lock. \n");
        pthread_cond_wait(&condition_cond, &condition_mutex);
        pthread_mutex_unlock(&condition_mutex);
        printf("main cond_mutex unlock. \n");
        if(pthread_mutex_lock(&mutex) == 0)
        {
            printf("main lock. \n");
        }
        if(run_now == 2)
        {
            printf("main thread is run .\n");
           run_now = 1;
        }
        else
        {
            printf("main thread is sleep\n");
            usleep(10);
        }
        if(pthread_mutex_unlock(&mutex) == 0)
        {
            printf("main unlock. \n");
        }
    }
    pthread_mutex_destroy(&mutex);
    pthread_join(a_thread, ((void *)0));
    exit(0);
}


decompiled_code:
int __fastcall function_count(void *a1)
{
int v1; // ebx
pthread_t v2; // rbp

v1 = 4;
pthread_mutex_lock(&mutex1);
v2 = pthread_self();
do
{
++counter;
printf("pid:%ld ", v2);
printf("counter value:%d\n", (unsigned int)counter);
--v1;
}
while ( v1 );
return pthread_mutex_unlock(&mutex1);
}

canonical_decompiled_code:
int __fastcall func7(void *a1)
{
int v1; // ebx
pthread_t v2; // rbp

v1 = 4;
pthread_mutex_lock(&mutex1);
v2 = pthread_self();
do
{
++counter;
printf("pid:%ld ", v2);
printf("counter value:%d\n", (unsigned int)counter);
--v1;
}
while ( v1 );
return pthread_mutex_unlock(&mutex1);
}

original_code:
void *function_count(void)
{
    int i;
    pthread_mutex_lock(&mutex1);
    for(i=0;i<4;i++)
    {
        counter++;
        printf("pid:%ld ", pthread_self());
        printf("counter value:%d\n", counter);
    }
    pthread_mutex_unlock(&mutex1);
}

canonical_original_code:
void *function_count()
{
    int i;
    pthread_mutex_lock(&mutex1);
    for(i=0;i<4;i++)
    {
        counter++;
        printf("pid:%ld ", pthread_self());
        printf("counter value:%d\n", counter);
    }
    pthread_mutex_unlock(&mutex1);
}

variable_types: i int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = pthread_create(&th, 0LL, function_count, 0LL);
if ( v3 )
printf("thread creation failed:%d\n", v3);
v4 = pthread_create(newthread, 0LL, function_count, 0LL);
if ( v4 )
printf("thread creation failed:%d\n", v4);
pthread_join(th, 0LL);
pthread_join(newthread[0], 0LL);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    int rc1, rc2;
    pthread_t thread1, thread2;
    if(rc1 = pthread_create(&thread1, ((void *)0), (void*) function_count, ((void *)0)))
    {
        printf("thread creation failed:%d\n", rc1);
    }
    if(rc2 = pthread_create(&thread2, ((void *)0), (void *)function_count, ((void *)0)))
    {
        printf("thread creation failed:%d\n", rc2);
    }
    pthread_join(thread1, ((void *)0));
    pthread_join(thread2, ((void *)0));
}

canonical_original_code:
int main(int argc, char **argv)
{
    int rc1; int rc2;
    unsigned long thread1; unsigned long thread2;
    if(rc1 = pthread_create(&thread1, ((void *)0), (void *) function_count, ((void *)0)))
    {
        printf("thread creation failed:%d\n", rc1);
    }
    if(rc2 = pthread_create(&thread2, ((void *)0), (void *)function_count, ((void *)0)))
    {
        printf("thread creation failed:%d\n", rc2);
    }
    pthread_join(thread1, ((void *)0));
    pthread_join(thread2, ((void *)0));
}


decompiled_code:
char *__fastcall get_ext(const char *a1)
{
char *v1; // rax

v1 = strrchr(a1, 46);
if ( !v1 )
exit(1);
return strdup(v1 + 1);
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1)
{
char *v1; // rax

v1 = strrchr(a1, 46);
if ( !v1 )
exit(1);
return strdup(v1 + 1);
}

original_code:
char *get_ext(const char *path)
{
  char *dot_addr = strrchr(path, '.');
  if(!dot_addr)
    exit(1);
  return strdup(++dot_addr);
}

canonical_original_code:
char *get_ext(char *path)
{
  char *dot_addr = strrchr(path, '.');
  if(!dot_addr)
    exit(1);
  return strdup(++dot_addr);
}

variable_types:
path
char *

return_type: char *


decompiled_code:
__int64 __fastcall in_array(char *s1, const char **a2)
{
const char **v2; // rbx
const char *v3; // rsi

v2 = a2;
v3 = *a2;
if ( !v3 )
return 0LL;
while ( strcasecmp(s1, v3) )
{
v3 = v2[1];
++v2;
if ( !v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1, const char **a2)
{
const char **v2; // rbx
const char *v3; // rsi

v2 = a2;
v3 = *a2;
if ( !v3 )
return 0LL;
while ( strcasecmp(s1, v3) )
{
v3 = v2[1];
++v2;
if ( !v3 )
return 0LL;
}
return 1LL;
}

original_code:
int in_array(const char *str, const char **array)
{
  while (*array != ((void *)0))
  {
    if (strcasecmp(str, *array) == 0) return 1;
    array++;
  }
  return 0;
}

canonical_original_code:
int in_array(char *str, char **array)
{
  while (*array != ((void *)0))
  {
    if (strcasecmp(str, *array) == 0) return 1;
    array++;
  }
  return 0;
}

variable_types:
str
char *

variable_types:
array
char **


repo: gkhighelf/OpenRelayScaner

decompiled_code:
__int64 __fastcall lookup_host(const char *a1, char *a2)
{
char *v2; // rbp
unsigned int v3; // er12
int v4; // edi
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
req.ai_flags = 2;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a1, 0LL, &req, &pai) )
return (unsigned int)-1;
v3 = 0;
v4 = pai->ai_family;
if ( v4 == 2 )
{
v2 = &pai->ai_addr->sa_data[2];
}
else if ( v4 == 10 )
{
v2 = &pai->ai_addr->sa_data[6];
}
inet_ntop(v4, v2, a2, 0x100u);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, char *a2)
{
char *v2; // rbp
unsigned int v3; // er12
int v4; // edi
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
req.ai_flags = 2;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a1, 0LL, &req, &pai) )
return (unsigned int)-1;
v3 = 0;
v4 = pai->ai_family;
if ( v4 == 2 )
{
v2 = &pai->ai_addr->sa_data[2];
}
else if ( v4 == 10 )
{
v2 = &pai->ai_addr->sa_data[6];
}
inet_ntop(v4, v2, a2, 0x100u);
return v3;
}

original_code:
int lookup_host (const char *host, char *ret )
{
    struct addrinfo hints, *res;
    int errcode;
    void *ptr;
    memset(&hints, 0, sizeof (hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags |= 0x0002;
    errcode = getaddrinfo (host, ((void *)0), &hints, &res);
    if (errcode != 0)
    {
        return -1;
    }
        switch (res->ai_family)
        {
            case 2:
                ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
                break;
            case 10:
                ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
                break;
        }
        inet_ntop(res->ai_family, ptr, ret, 256);
    return 0;
}

canonical_original_code:
int lookup_host(char *host, char *ret)
{
    struct addrinfo hints; struct addrinfo *res;
    int errcode;
    void *ptr;
    memset(&hints, 0, sizeof (hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags |= 0x0002;
    errcode = getaddrinfo (host, ((void *)0), &hints, &res);
    if (errcode != 0)
    {
        return -1;
    }
        switch (res->ai_family)
        {
            case 2:
                ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
                break;
            case 10:
                ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
                break;
        }
        inet_ntop(res->ai_family, ptr, ret, 256);
    return 0;
}

variable_types:
host
char *

variable_types:
ret
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: errcode int

variable_types:
ptr
void *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
int __fastcall resolv_host(char *name, char *dest)
{
struct hostent *v2; // rbx
int *v4; // rbp
const char *v5; // rax
__int64 v6; // rsi
signed int v7; // eax
int result; // eax

v4 = _h_errno_location();
do
{
v2->h_name = 0LL;
v2 = gethostbyname(name);
v5 = hstrerror(*v4);
puts(v5);
v6 = (unsigned int)*v4;
}
while ( (_DWORD)v6 == 2 );
if ( v2 )
{
v7 = (unsigned int)inet_ntoa((struct in_addr)(*(struct in_addr **)v2->h_addr_list)->s_addr);
result = (unsigned int)strcpy(dest, (const char *)v7);
}
else
{
result = printf("Error %d resolving host %s\n", v6, name);
*dest = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *name, char *dest)
{
struct hostent *v2; // rbx
int *v4; // rbp
const char *v5; // rax
__int64 v6; // rsi
signed int v7; // eax
int result; // eax

v4 = _h_errno_location();
do
{
v2->h_name = 0LL;
v2 = gethostbyname(name);
v5 = hstrerror(*v4);
puts(v5);
v6 = (unsigned int)*v4;
}
while ( (_DWORD)v6 == 2 );
if ( v2 )
{
v7 = (unsigned int)inet_ntoa((struct in_addr)(*(struct in_addr **)v2->h_addr_list)->s_addr);
result = (unsigned int)strcpy(dest, (const char *)v7);
}
else
{
result = printf("Error %d resolving host %s\n", v6, name);
*dest = 0;
}
return result;
}

original_code:
void resolv_host( char *host, char *res )
{
    struct hostent *pp, *gethostbyname();
    for(;;)
    {
        memset( pp, 0, sizeof( pp ) );
        pp = gethostbyname( host );
        printf( "%s\n", hstrerror( (*__h_errno_location ()) ) );
        if( (*__h_errno_location ()) == 2 ) continue;
        else break;
    }
    if( pp == (struct hostent*) 0 )
    {
        printf( "Error %d resolving host %s\n", (*__h_errno_location ()), host );
        res[0] = 0x0;
        return;
    }
    sprintf( res, "%s", (char*)inet_ntoa( *(struct in_addr*)( pp->h_addr_list[0] ) ) );
}

canonical_original_code:
void resolv_host(char *host, char *res)
{
    struct hostent *pp; struct hostent *gethostbyname();
    for(;;)
    {
        memset( pp, 0, sizeof( pp ) );
        pp = gethostbyname( host );
        printf( "%s\n", hstrerror( (*__h_errno_location ()) ) );
        if( (*__h_errno_location ()) == 2 ) continue;
        else break;
    }
    if( pp == (struct hostent *) 0 )
    {
        printf( "Error %d resolving host %s\n", (*__h_errno_location ()), host );
        res[0] = 0x0;
        return;
    }
    sprintf( res, "%s", (char *)inet_ntoa( *(struct in_addr *)( pp->h_addr_list[0] ) ) );
}

variable_types:
res
char *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *()

return_type: void


repo: glennklockwood/simulate

original_code:
void calculate_new_forces
(
    sim_params_t *simulation_parameters,
    system_info_t *system_info,
    atom_list_t *atoms
)
{
    neighbor_list_verlet_t *neighbors;
    double *restrict pos = atoms->pos,
           *restrict force = atoms->force,
           *restrict stress = atoms->stress;
    double boxl2[3];
    for ( int i = 0; i < 3; i++ )
        boxl2[i] = 2.0*system_info->boxli[i];
    neighbors = construct_neighbor_list( system_info, atoms );
    for ( int i = 0; i < atoms->count; i++ )
    {
        double pos_i[3];
        for ( int k = 0; k < 3; k++ )
            pos_i[k] = pos[(i)*3 +(k)];
        for ( int m = neighbors->nlb[i]; m < neighbors->nle[i]; m++ )
        {
            double rij2 = 0.0;
            double potential_mag, force_mag;
            double rij[3],
                   fij[3];
            int j;
            j = neighbors->nlist[m];
            for ( int k = 0; k < 3; k++ )
            {
                int mx;
                rij[k] = pos[(j)*3 +(k)] - pos_i[k];
                mx = (int)(rij[k] * boxl2[k]);
                rij[k] -= (double)mx * system_info->boxl[k];
            }
            for ( int k = 0; k < 3; k++ )
                rij2 += rij[k]*rij[k];
            if ( sqrt(rij2) > system_info->boxl[0] )
            {
                fprintf( stderr, "Interatomic spacing is larger than box!\n" );
                exit(1);
            }
            simulation_parameters->calculate_2body(
                atoms->type[i],
                atoms->type[j],
                rij2,
                simulation_parameters,
                &potential_mag,
                &force_mag);
            fprintf(stderr, "Interaction at %15g is %15g erg, %15g dyne\n",
                sqrt(rij2), potential_mag, force_mag * sqrt(rij2));
            for ( int k = 0; k < 3; k++ )
            {
                fij[k] = rij[k] * force_mag;
                force[(i)*3 +(k)] += fij[k];
                force[(j)*3 +(k)] -= fij[k];
                stress[k] += fij[k] * rij[k];
            }
        }
    }
    return;
}

canonical_original_code:
void calculate_new_forces(struct sim_params *simulation_parameters, struct system_info *system_info, struct atom_list *atoms)
{
    struct neighbor_list_verlet *neighbors;
    double *pos = atoms->pos; double *force = atoms->force; double *stress = atoms->stress;
    double boxl2[3];
    for ( int i = 0; i < 3; i++ )
        boxl2[i] = 2.0*system_info->boxli[i];
    neighbors = construct_neighbor_list( system_info, atoms );
    for ( int i = 0; i < atoms->count; i++ )
    {
        double pos_i[3];
        for ( int k = 0; k < 3; k++ )
            pos_i[k] = pos[(i)*3 +(k)];
        for ( int m = neighbors->nlb[i]; m < neighbors->nle[i]; m++ )
        {
            double rij2 = 0.0;
            double potential_mag; double force_mag;
            double rij[3]; double fij[3];
            int j;
            j = neighbors->nlist[m];
            for ( int k = 0; k < 3; k++ )
            {
                int mx;
                rij[k] = pos[(j)*3 +(k)] - pos_i[k];
                mx = (int)(rij[k] * boxl2[k]);
                rij[k] -= (double)mx * system_info->boxl[k];
            }
            for ( int k = 0; k < 3; k++ )
                rij2 += rij[k]*rij[k];
            if ( sqrt(rij2) > system_info->boxl[0] )
            {
                fprintf( stderr, "Interatomic spacing is larger than box!\n" );
                exit(1);
            }
            simulation_parameters->calculate_2body(
                atoms->type[i],
                atoms->type[j],
                rij2,
                simulation_parameters,
                &potential_mag,
                &force_mag);
            fprintf(stderr, "Interaction at %15g is %15g erg, %15g dyne\n",
                sqrt(rij2), potential_mag, force_mag * sqrt(rij2));
            for ( int k = 0; k < 3; k++ )
            {
                fij[k] = rij[k] * force_mag;
                force[(i)*3 +(k)] += fij[k];
                force[(j)*3 +(k)] -= fij[k];
                stress[k] += fij[k] * rij[k];
            }
        }
    }
    return;
}

variable_types: struct sim_params { int num_types; int *ltype; double timestep; double *mass; double *time_over_mass; double **pair_param; void (*calculate_2body)(int, int, double, struct sim_params *, double *, double *); void (*calculate_3body)(int, int, int, double, double, struct sim_params *, double *, double *); } *

variable_types: struct system_info { double boxl[3]; double boxli[3]; } *

variable_types: struct atom_list { unsigned int count; unsigned int *index; unsigned int *type; double *pos; double *stress; } *

variable_types: struct neighbor_list_verlet { int *nlb; int *nle; int *nlist; } *

variable_types:
pos
double *

variable_types:
force
double *

variable_types:
stress
double *

variable_types: k int

variable_types: m int

variable_types:
rij
double [3]

variable_types:
fij
double [3]

variable_types: j int

variable_types: mx int


original_code:
void pair_lj
(
    int itype,
    int jtype,
    double rij2,
    sim_params_t *simulation_parameters,
    double *potential_mag,
    double *force_mag
)
{
    double rij6;
    double rij12;
    double epsilon4, sigma, sigma12, sigma6;
    double part1, part2;
    int kt = (itype)*(simulation_parameters->num_types) - (itype)*((itype)+1)/2 + (jtype);
    rij6 = rij2*rij2*rij2;
    rij12 = rij6*rij6;
    epsilon4= 4.0 * simulation_parameters->pair_param[kt][0];
    sigma = simulation_parameters->pair_param[kt][1];
    sigma6 = sigma*sigma*sigma;
    sigma6 *= sigma6;
    sigma12 = sigma6*sigma6;
    part1 = epsilon4 * sigma12 / rij12;
    part2 = epsilon4 * sigma6 / rij6;
    *potential_mag = part1 - part2;
    *force_mag = part2 - 2.0*part1;
    *force_mag *= 6.0 / sqrt(rij2);
    return;
}

canonical_original_code:
void pair_lj(int itype, int jtype, double rij2, struct sim_params *simulation_parameters, double *potential_mag, double *force_mag)
{
    double rij6;
    double rij12;
    double epsilon4; double sigma; double sigma12; double sigma6;
    double part1; double part2;
    int kt = (itype)*(simulation_parameters->num_types) - (itype)*((itype)+1)/2 + (jtype);
    rij6 = rij2*rij2*rij2;
    rij12 = rij6*rij6;
    epsilon4= 4.0 * simulation_parameters->pair_param[kt][0];
    sigma = simulation_parameters->pair_param[kt][1];
    sigma6 = sigma*sigma*sigma;
    sigma6 *= sigma6;
    sigma12 = sigma6*sigma6;
    part1 = epsilon4 * sigma12 / rij12;
    part2 = epsilon4 * sigma6 / rij6;
    *potential_mag = part1 - part2;
    *force_mag = part2 - 2.0*part1;
    *force_mag *= 6.0 / sqrt(rij2);
    return;
}

variable_types: itype int

variable_types: jtype int

variable_types: sigma double

variable_types: kt int

user_defined_types: struct sim_params { int num_types; int *ltype; double timestep; double *mass; double *time_over_mass; double **pair_param; void (*calculate_2body)(int, int, double, struct sim_params *, double *, double *); void (*calculate_3body)(int, int, int, double, double, struct sim_params *, double *, double *); }


decompiled_code:
void __fastcall __noreturn dump_table(__int64 a1)
{
int v1; // ebx
double v2; // xmm3_8
double v3; // [rsp+10h] [rbp-28h] BYREF
double v4[4]; // [rsp+18h] [rbp-20h] BYREF

v1 = 96;
v2 = *(double *)&LC3;
do
{
(*(void (__fastcall **)(_QWORD, _QWORD, __int64, double *, double *, double))(a1 + 48))(
0LL,
0LL,
a1,
&v3,
v4,
v2 * v2);
printf("%15.8g %15.8g %15.8g\n", v2, v3, v4[0] * v2);
v2 = v2 + 0.000000001;
--v1;
}
while ( v1 );
exit(0);
}

original_code:
void dump_table( sim_params_t *simulation_parameters )
{
    double r0;
    double dx = 0.10e-08;
    r0 = 0.5e-08;
    while ( r0 < 10e-08 )
    {
        double potential_mag, force_mag;
        simulation_parameters->calculate_2body(
            0, 0, r0*r0,
            simulation_parameters,
            &potential_mag,
            &force_mag);
        printf( "%15.8g %15.8g %15.8g\n",
            r0, potential_mag, force_mag*r0 );
        r0 += dx;
    }
    exit(0);
    return;
}

canonical_original_code:
void dump_table(struct sim_params *simulation_parameters)
{
    double r0;
    double dx = 0.10e-08;
    r0 = 0.5e-08;
    while ( r0 < 10e-08 )
    {
        double potential_mag; double force_mag;
        simulation_parameters->calculate_2body(
            0, 0, r0*r0,
            simulation_parameters,
            &potential_mag,
            &force_mag);
        printf( "%15.8g %15.8g %15.8g\n",
            r0, potential_mag, force_mag*r0 );
        r0 += dx;
    }
    exit(0);
    return;
}

variable_types: struct sim_params { int num_types; int *ltype; double timestep; double *mass; double *time_over_mass; double **pair_param; void (*calculate_2body)(int, int, double, struct sim_params *, double *, double *); void (*calculate_3body)(int, int, int, double, double, struct sim_params *, double *, double *); } *

variable_types: dx double


decompiled_code:
void *create_link_cell()
{
void *result; // rax

if ( cell_list_0 )
free(cell_list_0);
result = malloc(0x38uLL);
cell_list_0 = result;
if ( !result )
{
malloc_error();
result = cell_list_0;
}
return result;
}

canonical_decompiled_code:
void *func0()
{
void *result; // rax

if ( cell_list_0 )
free(cell_list_0);
result = malloc(0x38uLL);
cell_list_0 = result;
if ( !result )
{
malloc_error();
result = cell_list_0;
}
return result;
}

original_code:
cell_map_t *create_link_cell( system_info_t *system_info, atom_list_t *atoms )
{
    static cell_map_t *cell_list;
    if ( cell_list )
    {
        free(cell_list);
    }
    cell_list = malloc(sizeof(*cell_list));
    if (!cell_list)
        malloc_error();
    return cell_list;
}

canonical_original_code:
struct cell_map *create_link_cell(struct system_info *system_info, struct atom_list *atoms)
{
    static struct cell_map *cell_list;
    if ( cell_list )
    {
        free(cell_list);
    }
    cell_list = malloc(sizeof(*cell_list));
    if (!cell_list)
        malloc_error();
    return cell_list;
}

variable_types: struct system_info { double boxl[3]; double boxli[3]; } *

variable_types: struct atom_list { unsigned int count; unsigned int *index; unsigned int *type; double *pos; double *stress; } *

variable_types: struct cell_map { double lcell[3]; int ncell; int *lhead; int *llist; int *map; } *


original_code:
void next_iteration
(
    sim_params_t *simulation_parameters,
    system_info_t *system_info,
    atom_list_t *atoms
)
{
    double *restrict pos = atoms->pos,
           *restrict vel = atoms->vel,
           *restrict accel = atoms->accel,
           *restrict force = atoms->force,
           *restrict inv_mass = simulation_parameters->time_over_mass,
           *restrict boxl = system_info->boxl,
           *restrict boxli = system_info->boxli;
    for ( int i = 0; i < atoms->count; i++ )
    {
        double displacement = 0.0;
        for ( int j = 0; j < 3; j++ )
        {
            double t;
            int m, n;
            vel[(i)*3 +(j)] += accel[(i)*3 +(j)];
            pos[(i)*3 +(j)] += vel[(i)*3 +(j)];
            displacement += vel[(i)*3 +(j)] * vel[(i)*3 +(j)];
            t = pos[(i)*3 +(j)] * boxli[j];
            m = (int)t;
            n = (int)(t - 1.0);
            pos[(i)*3 +(j)] = (t - (double)(m + n)) * boxl[j];
        }
    }
    calculate_new_forces( simulation_parameters, system_info, atoms );
    for ( int i = 0; i < atoms->count; i++ )
    {
        for ( int j = 0; j < 3; j++ )
        {
            accel[(i)*3 +(j)] = force[(i)*3 +(j)]
                * inv_mass[atoms->type[i]];
            vel[(i)*3 +(j)] += accel[(i)*3 +(j)];
        }
    }
    return;
}

canonical_original_code:
void next_iteration(struct sim_params *simulation_parameters, struct system_info *system_info, struct atom_list *atoms)
{
    double *pos = atoms->pos; double *vel = atoms->vel; double *accel = atoms->accel; double *force = atoms->force; double *inv_mass = simulation_parameters->time_over_mass; double *boxl = system_info->boxl; double *boxli = system_info->boxli;
    for ( int i = 0; i < atoms->count; i++ )
    {
        double displacement = 0.0;
        for ( int j = 0; j < 3; j++ )
        {
            double t;
            int m; int n;
            vel[(i)*3 +(j)] += accel[(i)*3 +(j)];
            pos[(i)*3 +(j)] += vel[(i)*3 +(j)];
            displacement += vel[(i)*3 +(j)] * vel[(i)*3 +(j)];
            t = pos[(i)*3 +(j)] * boxli[j];
            m = (int)t;
            n = (int)(t - 1.0);
            pos[(i)*3 +(j)] = (t - (double)(m + n)) * boxl[j];
        }
    }
    calculate_new_forces( simulation_parameters, system_info, atoms );
    for ( int i = 0; i < atoms->count; i++ )
    {
        for ( int j = 0; j < 3; j++ )
        {
            accel[(i)*3 +(j)] = force[(i)*3 +(j)]
                * inv_mass[atoms->type[i]];
            vel[(i)*3 +(j)] += accel[(i)*3 +(j)];
        }
    }
    return;
}

variable_types:
pos
double *

variable_types:
vel
double *

variable_types:
accel
double *

variable_types:
force
double *

variable_types:
boxl
double *

variable_types:
boxli
double *

variable_types: i int

variable_types: displacement double

variable_types: t double

variable_types: n int

user_defined_types: struct system_info { double boxl[3]; double boxli[3]; }

user_defined_types: struct atom_list { unsigned int count; unsigned int *index; unsigned int *type; double *pos; double *stress; }


repo: glguida/libhacktm-old

decompiled_code:
__int64 __fastcall synapse_init_random(_QWORD *a1, __int64 a2, unsigned __int64 a3)
{
char *v4; // rax
char *v5; // rbx
__int64 v6; // r14
__int64 v7; // rax
char *v8; // rbx
_BYTE v10[72]; // [rsp+0h] [rbp-48h] BYREF

*a1 = 0LL;
bitar_init(v10, (a3 >> 6) + 1);
v4 = (char *)malloc(16 * a2);
a1[1] = v4;
if ( !v4 )
_assert_fail("(s->wconn) != NULL", "components.c", 0x2Cu, "synapse_init_random");
v5 = v4;
v6 = 0LL;
if ( a2 )
{
while ( 1 )
{
v7 = v6++;
v8 = &v5[16 * v7];
*((_QWORD *)v8 + 1) = 0LL;
*(_QWORD *)v8 = bitar_setrandomid_range(v10, a3);
if ( a2 == v6 )
break;
v5 = (char *)a1[1];
}
}
return bitar_fini(v10);
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, unsigned __int64 a3)
{
char *v4; // rax
char *v5; // rbx
__int64 v6; // r14
__int64 v7; // rax
char *v8; // rbx
_BYTE v10[72]; // [rsp+0h] [rbp-48h] BYREF

*a1 = 0LL;
bitar_init(v10, (a3 >> 6) + 1);
v4 = (char *)malloc(16 * a2);
a1[1] = v4;
if ( !v4 )
_assert_fail("(s->wconn) != NULL", "components.c", 0x2Cu, "synapse_init_random");
v5 = v4;
v6 = 0LL;
if ( a2 )
{
while ( 1 )
{
v7 = v6++;
v8 = &v5[16 * v7];
*((_QWORD *)v8 + 1) = 0LL;
*(_QWORD *)v8 = bitar_setrandomid_range(v10, a3);
if ( a2 == v6 )
break;
v5 = (char *)a1[1];
}
}
return bitar_fini(v10);
}

original_code:
void
synapse_init_random(struct synapse *s, size_t wconns, size_t ndest)
{
  size_t i;
  bitar_t tmp;
  s->totcount = 0;
  bitar_init(&tmp, ndest/64 + 1);
  s->wconn = malloc(sizeof(struct wconn) * wconns);
  ((void) sizeof (((s->wconn) != ((void *)0)) ? 1 : 0), __extension__ ({ if ((s->wconn) != ((void *)0)) ; else __assert_fail ("(s->wconn) != NULL", "components.c", 44, __extension__ __PRETTY_FUNCTION__); }));
  for ( i = 0; i < wconns; i++ ) {
    s->wconn[i].count = 0;
    s->wconn[i].id = bitar_setrandomid_range(&tmp, ndest);
  }
  bitar_fini(&tmp);
}

canonical_original_code:
void synapse_init_random(struct synapse *s, unsigned long wconns, unsigned long ndest)
{
  unsigned long i;
  struct bitar tmp;
  s->totcount = 0;
  bitar_init(&tmp, ndest/64 + 1);
  s->wconn = malloc(sizeof(struct wconn) * wconns);
  ((void) sizeof (((s->wconn) != ((void *)0)) ? 1 : 0), __extension__ ({ if ((s->wconn) != ((void *)0)) ; else __assert_fail ("(s->wconn) != NULL", "components.c", 44, __extension__ __PRETTY_FUNCTION__); }));
  for ( i = 0; i < wconns; i++ ) {
    s->wconn[i].count = 0;
    s->wconn[i].id = bitar_setrandomid_range(&tmp, ndest);
  }
  bitar_fini(&tmp);
}

variable_types: struct synapse { unsigned long totcount; struct wconn { unsigned long id; unsigned long count; } *wconn; } *

variable_types:
wconns
unsigned long

variable_types:
ndest
unsigned long

variable_types:
i
unsigned long

variable_types: struct bitar { unsigned long count; unsigned long map_size; unsigned long *map; }

user_defined_types: struct synapse { unsigned long totcount; struct wconn *wconn; }


decompiled_code:
unsigned __int64 __fastcall synapse_predict(unsigned __int64 *a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v5; // rsi
__int64 v7; // rbx
_QWORD *v8; // rcx
unsigned __int64 result; // rax

v5 = *a1;
if ( *a1 && a2 )
{
v7 = 0LL;
while ( 1 )
{
v8 = (_QWORD *)(a1[1] + 16 * v7);
result = 10LL * v8[1] / v5;
if ( result <= 7 )
{
if ( a2 == ++v7 )
return result;
}
else
{
++v7;
result = bitar_set(a4, *v8, 10LL * v8[1] % v5);
if ( a2 == v7 )
return result;
}
v5 = *a1;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 *a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v5; // rsi
__int64 v7; // rbx
_QWORD *v8; // rcx
unsigned __int64 result; // rax

v5 = *a1;
if ( *a1 && a2 )
{
v7 = 0LL;
while ( 1 )
{
v8 = (_QWORD *)(a1[1] + 16 * v7);
result = 10LL * v8[1] / v5;
if ( result <= 7 )
{
if ( a2 == ++v7 )
return result;
}
else
{
++v7;
result = bitar_set(a4, *v8, 10LL * v8[1] % v5);
if ( a2 == v7 )
return result;
}
v5 = *a1;
}
}
return result;
}

original_code:
void
synapse_predict(struct synapse *s, size_t wconns, bitar_t *src, bitar_t *dst)
{
  size_t i;
  if ( s->totcount == 0 )
    return;
  for ( i = 0; i < wconns; i++ ) {
    if ( ((s->wconn[i].count * 10) / s->totcount) > 7 )
      bitar_set(dst, s->wconn[i].id);
  }
}

canonical_original_code:
void synapse_predict(struct synapse *s, unsigned long wconns, struct bitar *src, struct bitar *dst)
{
  unsigned long i;
  if ( s->totcount == 0 )
    return;
  for ( i = 0; i < wconns; i++ ) {
    if ( ((s->wconn[i].count * 10) / s->totcount) > 7 )
      bitar_set(dst, s->wconn[i].id);
  }
}

variable_types: struct bitar { unsigned long count; unsigned long map_size; unsigned long *map; } *

variable_types:
dst
struct bitar *

user_defined_types: struct wconn { unsigned long id; unsigned long count; }


original_code:
void
synapse_dump(struct synapse *s, size_t wconns)
{
  size_t i;
  for ( i = 0; i < wconns; i++ ) {
    if ( s->wconn[i].count == 0 )
      continue;
    printf("%lu:%lu/%lu\t", s->wconn[i].id, s->wconn[i].count, s->totcount);
  }
}

canonical_original_code:
void synapse_dump(struct synapse *s, unsigned long wconns)
{
  unsigned long i;
  for ( i = 0; i < wconns; i++ ) {
    if ( s->wconn[i].count == 0 )
      continue;
    printf("%lu:%lu/%lu\t", s->wconn[i].id, s->wconn[i].count, s->totcount);
  }
}


decompiled_code:
__int64 __fastcall synarray_init_sub(_QWORD *a1, __int64 a2, unsigned __int64 a3, __int64 a4)
{
__int64 result; // rax
__int64 v8; // r14
__int64 v9; // rdi

*a1 = a2;
a1[1] = a4;
result = (__int64)malloc(16 * a2);
a1[2] = result;
if ( !result )
_assert_fail("(sa->array) != NULL", "components.c", 0x72u, "synarray_init_sub");
v8 = 0LL;
if ( a2 )
{
while ( 1 )
{
v9 = v8++;
result = synapse_init_random((_QWORD *)(result + 16 * v9), a4, a3);
if ( a2 == v8 )
break;
result = a1[2];
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2, unsigned __int64 a3, __int64 a4)
{
__int64 result; // rax
__int64 v8; // r14
__int64 v9; // rdi

*a1 = a2;
a1[1] = a4;
result = (__int64)malloc(16 * a2);
a1[2] = result;
if ( !result )
_assert_fail("(sa->array) != NULL", "components.c", 0x72u, "synarray_init_sub");
v8 = 0LL;
if ( a2 )
{
while ( 1 )
{
v9 = v8++;
result = func0((_QWORD *)(result + 16 * v9), a4, a3);
if ( a2 == v8 )
break;
result = a1[2];
}
}
return result;
}

original_code:
void
synarray_init_sub(struct synar *sa, size_t syns, size_t dest, size_t wconns)
{
  size_t i;
  sa->syns = syns;
  sa->wconns = wconns;
  sa->array = malloc(sizeof(struct synapse) * syns);
  ((void) sizeof (((sa->array) != ((void *)0)) ? 1 : 0), __extension__ ({ if ((sa->array) != ((void *)0)) ; else __assert_fail ("(sa->array) != NULL", "components.c", 114, __extension__ __PRETTY_FUNCTION__); }));
  for ( i = 0; i < syns; i++ )
    synapse_init_random(sa->array + i, wconns, dest);
}

canonical_original_code:
void synarray_init_sub(struct synar *sa, unsigned long syns, unsigned long dest, unsigned long wconns)
{
  unsigned long i;
  sa->syns = syns;
  sa->wconns = wconns;
  sa->array = malloc(sizeof(struct synapse) * syns);
  ((void) sizeof (((sa->array) != ((void *)0)) ? 1 : 0), __extension__ ({ if ((sa->array) != ((void *)0)) ; else __assert_fail ("(sa->array) != NULL", "components.c", 114, __extension__ __PRETTY_FUNCTION__); }));
  for ( i = 0; i < syns; i++ )
    synapse_init_random(sa->array + i, wconns, dest);
}

variable_types: struct synar { unsigned long syns; unsigned long wconns; struct synapse { unsigned long totcount; struct wconn { unsigned long id; unsigned long count; } *wconn; } *array; } *

variable_types:
syns
unsigned long

variable_types:
dest
unsigned long

user_defined_types: struct synar { unsigned long syns; unsigned long wconns; struct synapse *array; }


decompiled_code:
unsigned __int64 __fastcall synarray_learn(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r14
unsigned __int64 result; // rax
unsigned __int64 i; // rbx

v3 = a1[1];
result = *(_QWORD *)(a2 + 8) << 6;
if ( result != *a1 )
_assert_fail("syns == bitar_bitsize(prev)", "components.c", 0x8Cu, "synarray_learn");
for ( i = 0LL; result > i; result = *(_QWORD *)(a2 + 8) << 6 )
{
if ( (unsigned int)bitar_get(a2, i) )
synapse_learn((_QWORD *)(a1[2] + 16 * i), v3, a3);
++i;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r14
unsigned __int64 result; // rax
unsigned __int64 i; // rbx

v3 = a1[1];
result = *(_QWORD *)(a2 + 8) << 6;
if ( result != *a1 )
_assert_fail("syns == bitar_bitsize(prev)", "components.c", 0x8Cu, "synarray_learn");
for ( i = 0LL; result > i; result = *(_QWORD *)(a2 + 8) << 6 )
{
if ( (unsigned int)bitar_get(a2, i) )
func1((_QWORD *)(a1[2] + 16 * i), v3, a3);
++i;
}
return result;
}

original_code:
void
synarray_learn(struct synar *sa, bitar_t *prev, bitar_t *cur)
{
  size_t i;
  const size_t syns = (const size_t)sa->syns;
  const size_t wconns = (const size_t)sa->wconns;
  ((void) sizeof ((syns == ((prev)->map_size * 64)) ? 1 : 0), __extension__ ({ if (syns == ((prev)->map_size * 64)) ; else __assert_fail ("syns == bitar_bitsize(prev)", "components.c", 140, __extension__ __PRETTY_FUNCTION__); }));
  for ( i = 0; i < ((prev)->map_size * 64); i++ )
    if ( bitar_get(prev, i) )
      synapse_learn(sa->array + i, wconns, cur);
}

canonical_original_code:
void synarray_learn(struct synar *sa, struct bitar *prev, struct bitar *cur)
{
  unsigned long i;
  unsigned long syns = (const size_t)sa->syns;
  unsigned long wconns = (const size_t)sa->wconns;
  ((void) sizeof ((syns == ((prev)->map_size * 64)) ? 1 : 0), __extension__ ({ if (syns == ((prev)->map_size * 64)) ; else __assert_fail ("syns == bitar_bitsize(prev)", "components.c", 140, __extension__ __PRETTY_FUNCTION__); }));
  for ( i = 0; i < ((prev)->map_size * 64); i++ )
    if ( bitar_get(prev, i) )
      synapse_learn(sa->array + i, wconns, cur);
}

variable_types:
cur
struct bitar *

user_defined_types: struct bitar { unsigned long count; unsigned long map_size; unsigned long *map; }


decompiled_code:
unsigned __int64 __fastcall synarray_predict(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r14
unsigned __int64 result; // rax
unsigned __int64 i; // rbx

v3 = a1[1];
if ( *(_QWORD *)(a2 + 8) << 6 != *a1 )
_assert_fail("syns == bitar_bitsize(cur)", "components.c", 0x9Au, "synarray_predict");
bitar_reset(a3);
result = *(_QWORD *)(a2 + 8) << 6;
if ( result )
{
for ( i = 0LL; i < result; ++i )
{
if ( (unsigned int)bitar_get(a2, i) )
synapse_predict((unsigned __int64 *)(a1[2] + 16 * i), v3, a2, a3);
result = *(_QWORD *)(a2 + 8) << 6;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r14
unsigned __int64 result; // rax
unsigned __int64 i; // rbx

v3 = a1[1];
if ( *(_QWORD *)(a2 + 8) << 6 != *a1 )
_assert_fail("syns == bitar_bitsize(cur)", "components.c", 0x9Au, "synarray_predict");
bitar_reset(a3);
result = *(_QWORD *)(a2 + 8) << 6;
if ( result )
{
for ( i = 0LL; i < result; ++i )
{
if ( (unsigned int)bitar_get(a2, i) )
func2((unsigned __int64 *)(a1[2] + 16 * i), v3, a2, a3);
result = *(_QWORD *)(a2 + 8) << 6;
}
}
return result;
}

original_code:
void
synarray_predict(struct synar *sa, bitar_t *cur, bitar_t *next)
{
  size_t i;
  const size_t syns = (const size_t)sa->syns;
  const size_t wconns = (const size_t)sa->wconns;
  ((void) sizeof ((syns == ((cur)->map_size * 64)) ? 1 : 0), __extension__ ({ if (syns == ((cur)->map_size * 64)) ; else __assert_fail ("syns == bitar_bitsize(cur)", "components.c", 154, __extension__ __PRETTY_FUNCTION__); }));
  bitar_reset(next);
  for ( i = 0; i < ((cur)->map_size * 64); i++ ) {
    if ( bitar_get(cur, i) )
      synapse_predict(sa->array + i, wconns, cur, next);
  }
}

canonical_original_code:
void synarray_predict(struct synar *sa, struct bitar *cur, struct bitar *next)
{
  unsigned long i;
  unsigned long syns = (const size_t)sa->syns;
  unsigned long wconns = (const size_t)sa->wconns;
  ((void) sizeof ((syns == ((cur)->map_size * 64)) ? 1 : 0), __extension__ ({ if (syns == ((cur)->map_size * 64)) ; else __assert_fail ("syns == bitar_bitsize(cur)", "components.c", 154, __extension__ __PRETTY_FUNCTION__); }));
  bitar_reset(next);
  for ( i = 0; i < ((cur)->map_size * 64); i++ ) {
    if ( bitar_get(cur, i) )
      synapse_predict(sa->array + i, wconns, cur, next);
  }
}

variable_types:
next
struct bitar *


original_code:
void
synarray_dump(struct synar *sa)
{
  size_t i;
  const size_t syns = (const size_t)sa->syns;
  const size_t wconns = (const size_t)sa->wconns;
  for ( i = 0; i < syns; i++ ) {
    if ( sa->array[i].totcount < 2 )
      continue;
    printf("\n %lu\n", i);
    synapse_dump(sa->array + i, wconns);
  }
}

canonical_original_code:
void synarray_dump(struct synar *sa)
{
  unsigned long i;
  unsigned long syns = (const size_t)sa->syns;
  unsigned long wconns = (const size_t)sa->wconns;
  for ( i = 0; i < syns; i++ ) {
    if ( sa->array[i].totcount < 2 )
      continue;
    printf("\n %lu\n", i);
    synapse_dump(sa->array + i, wconns);
  }
}


original_code:
void
spool_init(struct spool *sp, size_t input_w, size_t columns_w, size_t conns, size_t maxbits)
{
  sp->input_w = input_w;
  sp->columns_w = columns_w;
  sp->conns = conns;
  sp->maxbits = maxbits;
  fdr_init(sp->in2col, input_w, columns_w, conns, maxbits);
}

canonical_original_code:
void spool_init(struct spool *sp, unsigned long input_w, unsigned long columns_w, unsigned long conns, unsigned long maxbits)
{
  sp->input_w = input_w;
  sp->columns_w = columns_w;
  sp->conns = conns;
  sp->maxbits = maxbits;
  fdr_init(sp->in2col, input_w, columns_w, conns, maxbits);
}

variable_types: struct spool { unsigned long input_w; unsigned long columns_w; unsigned long conns; unsigned long maxbits; struct bitar { unsigned long count; unsigned long map_size; unsigned long *map; } input[1]; struct fdr { unsigned long input_mapsize; unsigned long output_mapsize; unsigned long conn_bits; unsigned long trunc; struct bitar and; struct bitar *incols; struct coinc_array { unsigned long col; unsigned long val; } *coinc_array; } in2col[1]; struct synar { unsigned long syns; unsigned long wconns; struct synapse { unsigned long totcount; struct wconn { unsigned long id; unsigned long count; } *wconn; } *array; } synar[1]; } *

variable_types:
conns
unsigned long

variable_types:
maxbits
unsigned long

user_defined_types: struct spool { unsigned long input_w; unsigned long columns_w; unsigned long conns; unsigned long maxbits; struct bitar input[1]; struct fdr in2col[1]; struct synar synar[1]; }

user_defined_types: struct fdr { unsigned long input_mapsize; unsigned long output_mapsize; unsigned long conn_bits; unsigned long trunc; struct bitar and; struct bitar *incols; struct coinc_array *coinc_array; }


decompiled_code:
__int64 __fastcall spool_init_std(_QWORD *a1, __int64 a2, __int64 a3, unsigned __int64 a4, unsigned __int64 a5)
{
return spool_init(a1, a2, a3, (a2 << 6) / a4, (a3 << 6) / a5);
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int64 a2, __int64 a3, unsigned __int64 a4, unsigned __int64 a5)
{
return func8(a1, a2, a3, (a2 << 6) / a4, (a3 << 6) / a5);
}

original_code:
void
spool_init_std(struct spool *sp, size_t input_w, size_t columns_w, size_t conn_factor, size_t act_factor)
{
  size_t conns = ((input_w) * 64)/conn_factor;
  size_t maxbits = ((columns_w) * 64)/act_factor;
  spool_init(sp, input_w, columns_w, conns, maxbits);
}

canonical_original_code:
void spool_init_std(struct spool *sp, unsigned long input_w, unsigned long columns_w, unsigned long conn_factor, unsigned long act_factor)
{
  unsigned long conns = ((input_w) * 64)/conn_factor;
  unsigned long maxbits = ((columns_w) * 64)/act_factor;
  spool_init(sp, input_w, columns_w, conns, maxbits);
}

user_defined_types: struct coinc_array { unsigned long col; unsigned long val; }


spool

decompiled_code:
__int64 __fastcall spool(__int64 a1)
{
return fdr_feedback_generate(a1 + 56);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return fdr_feedback_generate(a1 + 56);
}

original_code:
void spool(struct spool *sp, bitar_t *in, bitar_t *expected, bitar_t *out)
{
  fdr_feedback_generate(sp->in2col, in, expected, out);
}

canonical_original_code:
void spool(struct spool *sp, struct bitar *in, struct bitar *expected, struct bitar *out)
{
  fdr_feedback_generate(sp->in2col, in, expected, out);
}

variable_types:
in
struct bitar *

variable_types:
expected
struct bitar *

variable_types:
out
struct bitar *


original_code:
void
seqlearn_init(struct seqlearn *sq, size_t columns_w, size_t cells_per_col, size_t col2cur_conns, size_t prev2cur_conns)
{
  size_t i;
  sq->columns_w = columns_w;
  sq->output_w = columns_w * cells_per_col;
  fdr_init(sq->col2cur, sq->columns_w, sq->output_w, col2cur_conns, 1);
  synarray_init_sub(sq->prev2cur, ((sq->output_w) * 64), ((sq->output_w) * 64), prev2cur_conns);
  bitar_init(sq->col_prev, sq->columns_w);
  bitar_init(sq->prev, sq->output_w);
  bitar_init(sq->expected, sq->output_w);
  bitar_setall(sq->prev);
}

canonical_original_code:
void seqlearn_init(struct seqlearn *sq, unsigned long columns_w, unsigned long cells_per_col, unsigned long col2cur_conns, unsigned long prev2cur_conns)
{
  unsigned long i;
  sq->columns_w = columns_w;
  sq->output_w = columns_w * cells_per_col;
  fdr_init(sq->col2cur, sq->columns_w, sq->output_w, col2cur_conns, 1);
  synarray_init_sub(sq->prev2cur, ((sq->output_w) * 64), ((sq->output_w) * 64), prev2cur_conns);
  bitar_init(sq->col_prev, sq->columns_w);
  bitar_init(sq->prev, sq->output_w);
  bitar_init(sq->expected, sq->output_w);
  bitar_setall(sq->prev);
}

variable_types: struct seqlearn { unsigned long columns_w; unsigned long output_w; struct fdr { unsigned long input_mapsize; unsigned long output_mapsize; unsigned long conn_bits; unsigned long trunc; struct bitar { unsigned long count; unsigned long map_size; unsigned long *map; } and; struct bitar *incols; struct coinc_array { unsigned long col; unsigned long val; } *coinc_array; } col2cur[1]; unsigned long col2cur_conns; struct synar { unsigned long syns; unsigned long wconns; struct synapse { unsigned long totcount; struct wconn { unsigned long id; unsigned long count; } *wconn; } *array; } prev2cur[1]; struct bitar col_prev[1]; struct bitar prev[1]; struct bitar expected[1]; } *

user_defined_types: struct seqlearn { unsigned long columns_w; unsigned long output_w; struct fdr col2cur[1]; unsigned long col2cur_conns; struct synar prev2cur[1]; struct bitar col_prev[1]; struct bitar prev[1]; struct bitar expected[1]; }


decompiled_code:
__int64 __fastcall seqlearn_init_std(_QWORD *a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
return seqlearn_init(a1, a2, a3, (a2 << 6) / a4, ((a3 * a2) << 6) / a4);
}

original_code:
void
seqlearn_init_std(struct seqlearn *sq, size_t columns_w, size_t cells_per_col, size_t conn_factor)
{
  size_t col2cur_conns = ((columns_w) * 64)/conn_factor;
  size_t prev2cur_conns = (((columns_w) * 64) * cells_per_col) / conn_factor;
  seqlearn_init(sq, columns_w, cells_per_col, col2cur_conns, prev2cur_conns);
}

canonical_original_code:
void seqlearn_init_std(struct seqlearn *sq, unsigned long columns_w, unsigned long cells_per_col, unsigned long conn_factor)
{
  unsigned long col2cur_conns = ((columns_w) * 64)/conn_factor;
  unsigned long prev2cur_conns = (((columns_w) * 64) * cells_per_col) / conn_factor;
  seqlearn_init(sq, columns_w, cells_per_col, col2cur_conns, prev2cur_conns);
}


seqlearn

decompiled_code:
__int64 __fastcall seqlearn(unsigned __int64 *a1, __int64 a2, __int64 a3, __int64 a4)
{
_QWORD *v5; // r13
__int64 v6; // rax
__int64 v7; // rdx
unsigned __int64 v8; // rcx
int v9; // ebx
__int64 v10; // rdx
__int64 v11; // rcx
__int64 v12; // r8
__int64 v13; // rdx
__int64 v14; // rcx
__int64 v15; // r8
__int64 result; // rax
unsigned __int64 v17; // [rsp+8h] [rbp-50h]
__int64 v18; // [rsp+8h] [rbp-50h]
unsigned __int64 v20; // [rsp+18h] [rbp-40h]

v20 = a1[1];
if ( *a1 != *(_QWORD *)(a2 + 8) )
_assert_fail("bitar_size(col_in) == sq->columns_w", "components.c", 0xFEu, "seqlearn");
v5 = a1 + 15;
v17 = *a1;
v6 = bitar_dist(a1 + 15);
v8 = v17;
v18 = (__int64)(a1 + 21);
if ( v6 )
{
fdr_groupselect(a1 + 2, v20 / v8, v5, a4, a3, a2);
v9 = bitar_dist(a4);
synarray_learn(a1 + 12, (__int64)(a1 + 18), a4);
synarray_predict(a1 + 12, a4, v18);
bitar_copy(a1 + 18, a4, v10, v11, v12);
bitar_copy(v5, a2, v13, v14, v15);
result = (unsigned int)(v9 + 1);
}
else
{
bitar_copy(a4, a1 + 18, v7, v8, a3);
synarray_predict(a1 + 12, a4, v18);
result = 0LL;
}
return result;
}

original_code:
int
seqlearn(struct seqlearn *sq, bitar_t *col_in, bitar_t *feedback, bitar_t *out)
{
  size_t i;
  size_t cells_per_col = sq->output_w/sq->columns_w;
  ((void) sizeof ((((col_in)->map_size) == sq->columns_w) ? 1 : 0), __extension__ ({ if (((col_in)->map_size) == sq->columns_w) ; else __assert_fail ("bitar_size(col_in) == sq->columns_w", "components.c", 254, __extension__ __PRETTY_FUNCTION__); }));
  if ( bitar_dist(sq->col_prev, col_in) == 0 ) {
    bitar_copy(out, sq->prev);
    synarray_predict(sq->prev2cur, out, sq->expected);
    return 0;
  }
  fdr_groupselect(sq->col2cur, cells_per_col, sq->col_prev, out, feedback, col_in);
  i = bitar_dist(out, sq->expected);
  synarray_learn(sq->prev2cur, sq->prev, out);
  synarray_predict(sq->prev2cur, out, sq->expected);
  bitar_copy(sq->prev, out);
  bitar_copy(sq->col_prev, col_in);
  return 1 + i;
}

canonical_original_code:
int seqlearn(struct seqlearn *sq, struct bitar *col_in, struct bitar *feedback, struct bitar *out)
{
  unsigned long i;
  unsigned long cells_per_col = sq->output_w/sq->columns_w;
  ((void) sizeof ((((col_in)->map_size) == sq->columns_w) ? 1 : 0), __extension__ ({ if (((col_in)->map_size) == sq->columns_w) ; else __assert_fail ("bitar_size(col_in) == sq->columns_w", "components.c", 254, __extension__ __PRETTY_FUNCTION__); }));
  if ( bitar_dist(sq->col_prev, col_in) == 0 ) {
    bitar_copy(out, sq->prev);
    synarray_predict(sq->prev2cur, out, sq->expected);
    return 0;
  }
  fdr_groupselect(sq->col2cur, cells_per_col, sq->col_prev, out, feedback, col_in);
  i = bitar_dist(out, sq->expected);
  synarray_learn(sq->prev2cur, sq->prev, out);
  synarray_predict(sq->prev2cur, out, sq->expected);
  bitar_copy(sq->prev, out);
  bitar_copy(sq->col_prev, col_in);
  return 1 + i;
}

variable_types:
feedback
struct bitar *


decompiled_code:
__int64 __fastcall tpool_init(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rdi

v4 = a1 + 8;
*(_QWORD *)(v4 - 8) = a3;
bitar_init(v4, a2);
bitar_init(a1 + 56, a2);
bitar_init(a1 + 32, a2);
bitar_init(a1 + 80, a2);
return bitar_init(a1 + 104, a2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rdi

v4 = a1 + 8;
*(_QWORD *)(v4 - 8) = a3;
bitar_init(v4, a2);
bitar_init(a1 + 56, a2);
bitar_init(a1 + 32, a2);
bitar_init(a1 + 80, a2);
return bitar_init(a1 + 104, a2);
}

original_code:
void
tpool_init(struct tpool *tp, size_t output_w, struct synar *synar)
{
  tp->synar = synar;
  bitar_init(tp->and, output_w);
  bitar_init(tp->in_prev, output_w);
  bitar_init(tp->out_prev, output_w);
  bitar_init(tp->tmp, output_w);
  bitar_init(tp->tmp + 1, output_w);
}

canonical_original_code:
void tpool_init(struct tpool *tp, unsigned long output_w, struct synar *synar)
{
  tp->synar = synar;
  bitar_init(tp->and, output_w);
  bitar_init(tp->in_prev, output_w);
  bitar_init(tp->out_prev, output_w);
  bitar_init(tp->tmp, output_w);
  bitar_init(tp->tmp + 1, output_w);
}

variable_types: struct tpool { struct synar { unsigned long syns; unsigned long wconns; struct synapse { unsigned long totcount; struct wconn { unsigned long id; unsigned long count; } *wconn; } *array; } *synar; struct bitar { unsigned long count; unsigned long map_size; unsigned long *map; } and[1]; struct bitar out_prev[1]; struct bitar in_prev[1]; struct bitar tmp[2]; } *

variable_types:
synar
struct synar *

user_defined_types: struct tpool { struct synar *synar; struct bitar and[1]; struct bitar out_prev[1]; struct bitar in_prev[1]; struct bitar tmp[2]; }


tpool

original_code:
int
tpool(struct tpool *tp, bitar_t *out)
{
  int i;
  bitar_and(out, tp->out_prev, tp->and);
  if ( tp->and->count == out->count ) {
    bitar_copy(tp->in_prev, out);
    bitar_copy(out, tp->out_prev);
    return 0;
  }
  bitar_copy(tp->in_prev, out);
  bitar_copy(tp->tmp, out);
  for ( i = 0; i < 5; i++ ) {
    bitar_reset(tp->tmp + ((i + 1) % 2));
    synarray_predict(tp->synar, tp->tmp + (i % 2),
       tp->tmp + ((i + 1) % 2));
    bitar_or(tp->tmp + ((i + 1) % 2), out, out);
  }
  bitar_copy(tp->out_prev, out);
  return 1;
}

canonical_original_code:
int tpool(struct tpool *tp, struct bitar *out)
{
  int i;
  bitar_and(out, tp->out_prev, tp->and);
  if ( tp->and->count == out->count ) {
    bitar_copy(tp->in_prev, out);
    bitar_copy(out, tp->out_prev);
    return 0;
  }
  bitar_copy(tp->in_prev, out);
  bitar_copy(tp->tmp, out);
  for ( i = 0; i < 5; i++ ) {
    bitar_reset(tp->tmp + ((i + 1) % 2));
    synarray_predict(tp->synar, tp->tmp + (i % 2),
       tp->tmp + ((i + 1) % 2));
    bitar_or(tp->tmp + ((i + 1) % 2), out, out);
  }
  bitar_copy(tp->out_prev, out);
  return 1;
}

variable_types: i int


decompiled_code:
__int64 __fastcall node_conn_init(__int64 a1, __int64 a2)
{
((void (*)(void))bitar_init)();
return bitar_init(a1 + 24, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
((void (*)(void))bitar_init)();
return bitar_init(a1 + 24, a2);
}

original_code:
void
node_conn_init(struct node_conn *nc, size_t mapsize)
{
  bitar_init(nc->val, mapsize);
  bitar_init(nc->val + 1, mapsize);
}

canonical_original_code:
void node_conn_init(struct node_conn *nc, unsigned long mapsize)
{
  bitar_init(nc->val, mapsize);
  bitar_init(nc->val + 1, mapsize);
}

variable_types: struct node_conn { struct bitar { unsigned long count; unsigned long map_size; unsigned long *map; } val[2]; } *

variable_types:
mapsize
unsigned long

user_defined_types: struct node_conn { struct bitar val[2]; }


original_code:
void
node_init(node_t *n, size_t input_w, size_t columns_w,
   size_t sp_in_conn_fct, size_t sp_act_fct,
   size_t sq_cells_per_col, size_t sq_col_conn_fct)
{
  n->input_w = input_w;
  n->output_w = columns_w * sq_cells_per_col;
  bitar_init(n->col_temp, columns_w);
  bitar_init(n->col_exp, columns_w);
  spool_init_std(n->sp, input_w, columns_w, sp_in_conn_fct, sp_act_fct);
  seqlearn_init_std(n->sq, columns_w, sq_cells_per_col, sq_col_conn_fct);
  tpool_init(n->tp, n->output_w, n->sq->prev2cur);
}

canonical_original_code:
void node_init(struct node *n, unsigned long input_w, unsigned long columns_w, unsigned long sp_in_conn_fct, unsigned long sp_act_fct, unsigned long sq_cells_per_col, unsigned long sq_col_conn_fct)
{
  n->input_w = input_w;
  n->output_w = columns_w * sq_cells_per_col;
  bitar_init(n->col_temp, columns_w);
  bitar_init(n->col_exp, columns_w);
  spool_init_std(n->sp, input_w, columns_w, sp_in_conn_fct, sp_act_fct);
  seqlearn_init_std(n->sq, columns_w, sq_cells_per_col, sq_col_conn_fct);
  tpool_init(n->tp, n->output_w, n->sq->prev2cur);
}

variable_types: struct node { unsigned long input_w; unsigned long output_w; struct bitar { unsigned long count; unsigned long map_size; unsigned long *map; } col_temp[1]; struct bitar col_exp[1]; struct spool { unsigned long input_w; unsigned long columns_w; unsigned long conns; unsigned long maxbits; struct bitar input[1]; struct fdr { unsigned long input_mapsize; unsigned long output_mapsize; unsigned long conn_bits; unsigned long trunc; struct bitar and; struct bitar *incols; struct coinc_array { unsigned long col; unsigned long val; } *coinc_array; } in2col[1]; struct synar { unsigned long syns; unsigned long wconns; struct synapse { unsigned long totcount; struct wconn { unsigned long id; unsigned long count; } *wconn; } *array; } synar[1]; } sp[1]; struct seqlearn { unsigned long columns_w; unsigned long output_w; struct fdr col2cur[1]; unsigned long col2cur_conns; struct synar prev2cur[1]; struct bitar col_prev[1]; struct bitar prev[1]; struct bitar expected[1]; } sq[1]; struct tpool { struct synar *synar; struct bitar and[1]; struct bitar out_prev[1]; struct bitar in_prev[1]; struct bitar tmp[2]; } tp[1]; } *

user_defined_types: struct node { unsigned long input_w; unsigned long output_w; struct bitar col_temp[1]; struct bitar col_exp[1]; struct spool sp[1]; struct seqlearn sq[1]; struct tpool tp[1]; }


decompiled_code:
__int64 __fastcall node_process(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

bitar_reset(a3);
bitar_reset(a1 + 16);
bitar_reset(a1 + 40);
bitar_scale(a1 + 384, a1 + 40);
spool(a1 + 64, a2, a1 + 40, a1 + 16);
result = seqlearn(a1 + 216, a1 + 16, a3 + 24, a3);
if ( (_DWORD)result )
result = (unsigned int)tpool(a1 + 408, a3) != 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

bitar_reset(a3);
bitar_reset(a1 + 16);
bitar_reset(a1 + 40);
bitar_scale(a1 + 384, a1 + 40);
spool(a1 + 64, a2, a1 + 40, a1 + 16);
result = seqlearn(a1 + 216, a1 + 16, a3 + 24, a3);
if ( (_DWORD)result )
result = (unsigned int)tpool(a1 + 408, a3) != 0;
return result;
}

original_code:
int
node_process(node_t *n, struct node_conn *in, struct node_conn *out)
{
  int r;
  bitar_reset(((out)->val));
  bitar_reset(n->col_temp);
  bitar_reset(n->col_exp);
  bitar_scale(n->sq->expected, n->col_exp);
  spool(n->sp, ((in)->val), n->col_exp, n->col_temp);
  r = seqlearn(n->sq, n->col_temp, ((out)->val + 1), ((out)->val));
  if ( !r )
    return 0;
  r = tpool(n->tp, ((out)->val));
  if ( !r )
    return 0;
  return 1;
}

canonical_original_code:
int node_process(struct node *n, struct node_conn *in, struct node_conn *out)
{
  int r;
  bitar_reset(((out)->val));
  bitar_reset(n->col_temp);
  bitar_reset(n->col_exp);
  bitar_scale(n->sq->expected, n->col_exp);
  spool(n->sp, ((in)->val), n->col_exp, n->col_temp);
  r = seqlearn(n->sq, n->col_temp, ((out)->val + 1), ((out)->val));
  if ( !r )
    return 0;
  r = tpool(n->tp, ((out)->val));
  if ( !r )
    return 0;
  return 1;
}

variable_types: struct node_conn { struct bitar val[2]; } *

variable_types:
out
struct node_conn *

variable_types: r int


decompiled_code:
__int64 __fastcall bytequeue_init(__int64 a1, __int64 a2, char a3)
{
__int64 result; // rax

result = 0LL;
*(_BYTE *)(a1 + 2) = a3;
*(_QWORD *)(a1 + 8) = a2;
*(_WORD *)a1 = 0;
return result;
}

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

result = 0LL;
*(_BYTE *)(a1 + 2) = a3;
*(_QWORD *)(a1 + 8) = a2;
*(_WORD *)a1 = 0;
return result;
}

original_code:
void bytequeue_init(byteQueue_t * queue, uint8_t * dataArray, byteQueueIndex_t arrayLen){
   queue->length = arrayLen;
   queue->data = dataArray;
   queue->start = queue->end = 0;
}

canonical_original_code:
void bytequeue_init(struct byteQueue_t *queue, unsigned char *dataArray, unsigned char arrayLen){
   queue->length = arrayLen;
   queue->data = dataArray;
   queue->start = queue->end = 0;
}

variable_types: struct byteQueue_t { unsigned char start; unsigned char end; unsigned char length; unsigned char *data; } *

variable_types:
dataArray
unsigned char *

variable_types:
arrayLen
unsigned char


decompiled_code:
__int64 __fastcall bytequeue_enqueue(unsigned __int8 *a1, char a2)
{
unsigned __int8 v2; // al
__int64 v3; // rcx
__int64 result; // rax

v2 = store_and_clear_interrupt();
v3 = a1[1];
if ( ((int)v3 + 1) % a1[2] == *a1 )
{
restore_interrupt_setting(v2);
result = 0LL;
}
else
{
*(_BYTE *)(*((_QWORD *)a1 + 1) + v3) = a2;
a1[1] = (a1[1] + 1) % a1[2];
restore_interrupt_setting(v2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1, char a2)
{
unsigned __int8 v2; // al
__int64 v3; // rcx
__int64 result; // rax

v2 = store_and_clear_interrupt();
v3 = a1[1];
if ( ((int)v3 + 1) % a1[2] == *a1 )
{
restore_interrupt_setting(v2);
result = 0LL;
}
else
{
*(_BYTE *)(*((_QWORD *)a1 + 1) + v3) = a2;
a1[1] = (a1[1] + 1) % a1[2];
restore_interrupt_setting(v2);
result = 1LL;
}
return result;
}

original_code:
_Bool bytequeue_enqueue(byteQueue_t * queue, uint8_t item){
   interrupt_setting_t setting = store_and_clear_interrupt();
   if(((queue->end + 1) % queue->length) == queue->start){
      restore_interrupt_setting(setting);
      return 0;
   } else {
      queue->data[queue->end] = item;
      queue->end = (queue->end + 1) % queue->length;
      restore_interrupt_setting(setting);
      return 1;
   }
}

canonical_original_code:
_Bool bytequeue_enqueue(struct byteQueue_t *queue, unsigned char item){
   unsigned char setting = store_and_clear_interrupt();
   if(((queue->end + 1) % queue->length) == queue->start){
      restore_interrupt_setting(setting);
      return 0;
   } else {
      queue->data[queue->end] = item;
      queue->end = (queue->end + 1) % queue->length;
      restore_interrupt_setting(setting);
      return 1;
   }
}

variable_types:
item
unsigned char

variable_types:
setting
unsigned char

user_defined_types: struct byteQueue_t { unsigned char start; unsigned char end; unsigned char length; unsigned char *data; }


decompiled_code:
__int64 __fastcall bytequeue_length(unsigned __int8 *a1)
{
unsigned __int8 v2; // al
int v3; // edx
__int64 v4; // rdi
int v5; // eax
unsigned int v6; // er12

v2 = store_and_clear_interrupt();
v3 = *a1;
v4 = v2;
v5 = a1[1];
if ( (unsigned __int8)v5 < (unsigned __int8)v3 )
LOBYTE(v5) = a1[2] + v5;
v6 = v5 - v3;
restore_interrupt_setting(v4);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1)
{
unsigned __int8 v2; // al
int v3; // edx
__int64 v4; // rdi
int v5; // eax
unsigned int v6; // er12

v2 = store_and_clear_interrupt();
v3 = *a1;
v4 = v2;
v5 = a1[1];
if ( (unsigned __int8)v5 < (unsigned __int8)v3 )
LOBYTE(v5) = a1[2] + v5;
v6 = v5 - v3;
restore_interrupt_setting(v4);
return v6;
}

original_code:
byteQueueIndex_t bytequeue_length(byteQueue_t * queue){
   byteQueueIndex_t len;
   interrupt_setting_t setting = store_and_clear_interrupt();
   if(queue->end >= queue->start)
      len = queue->end - queue->start;
   else
      len = (queue->length - queue->start) + queue->end;
   restore_interrupt_setting(setting);
   return len;
}

canonical_original_code:
unsigned char bytequeue_length(struct byteQueue_t *queue){
   unsigned char len;
   unsigned char setting = store_and_clear_interrupt();
   if(queue->end >= queue->start)
      len = queue->end - queue->start;
   else
      len = (queue->length - queue->start) + queue->end;
   restore_interrupt_setting(setting);
   return len;
}

variable_types:
len
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall bytequeue_get(unsigned __int8 *a1, unsigned __int8 a2)
{
return *(unsigned __int8 *)(*((_QWORD *)a1 + 1) + (a2 + *a1) % a1[2]);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1, unsigned __int8 a2)
{
return *(unsigned __int8 *)(*((_QWORD *)a1 + 1) + (a2 + *a1) % a1[2]);
}

original_code:
uint8_t bytequeue_get(byteQueue_t * queue, byteQueueIndex_t index){
   return queue->data[(queue->start + index) % queue->length];
}

canonical_original_code:
unsigned char bytequeue_get(struct byteQueue_t *queue, unsigned char index){
   return queue->data[(queue->start + index) % queue->length];
}

variable_types:
index
unsigned char


decompiled_code:
__int64 __fastcall bytequeue_remove(unsigned __int8 *a1, unsigned __int8 a2)
{
unsigned __int8 v2; // al

v2 = store_and_clear_interrupt();
*a1 = (a2 + *a1) % a1[2];
return restore_interrupt_setting(v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1, unsigned __int8 a2)
{
unsigned __int8 v2; // al

v2 = store_and_clear_interrupt();
*a1 = (a2 + *a1) % a1[2];
return restore_interrupt_setting(v2);
}

original_code:
void bytequeue_remove(byteQueue_t * queue, byteQueueIndex_t numToRemove){
   interrupt_setting_t setting = store_and_clear_interrupt();
   queue->start = (queue->start + numToRemove) % queue->length;
   restore_interrupt_setting(setting);
}

canonical_original_code:
void bytequeue_remove(struct byteQueue_t *queue, unsigned char numToRemove){
   unsigned char setting = store_and_clear_interrupt();
   queue->start = (queue->start + numToRemove) % queue->length;
   restore_interrupt_setting(setting);
}

variable_types:
numToRemove
unsigned char


decompiled_code:
char __fastcall midi_is_statusbyte(unsigned __int8 a1)
{
return a1 >> 7;
}

canonical_decompiled_code:
char __fastcall func0(unsigned __int8 a1)
{
return a1 >> 7;
}

original_code:
_Bool midi_is_statusbyte(uint8_t theByte){
   return (_Bool)(theByte & 0x80);
}

canonical_original_code:
_Bool midi_is_statusbyte(unsigned char theByte){
   return (_Bool)(theByte & 0x80);
}

variable_types:
theByte
unsigned char


decompiled_code:
bool __fastcall midi_is_realtime(unsigned __int8 a1)
{
return a1 > 0xF7u;
}

canonical_decompiled_code:
bool __fastcall func1(unsigned __int8 a1)
{
return a1 > 0xF7u;
}

original_code:
_Bool midi_is_realtime(uint8_t theByte){
   return (theByte >= 0xF8);
}

canonical_original_code:
_Bool midi_is_realtime(unsigned char theByte){
   return (theByte >= 0xF8);
}


decompiled_code:
__int64 __fastcall midi_packet_length(char a1)
{
unsigned __int8 v1; // cl
__int64 result; // rax

v1 = a1 & 0xF0;
if ( (a1 & 0xF0) == 0xD0 )
return 2LL;
if ( (a1 & 0xF0u) > 0xD0 )
{
if ( v1 == 0xE0 )
{
LABEL_10:
result = 3LL;
}
else if ( v1 == 0xF0 && (unsigned __int8)a1 >= 0xF1u )
{
switch ( a1 )
{
case -15:
case -13:
return 2LL;
case -14:
goto LABEL_10;
case -12:
case -11:
case -9:
case -3:
goto LABEL_13;
case -10:
case -8:
case -7:
case -6:
case -5:
case -4:
case -2:
case -1:
result = 1LL;
break;
}
}
else
{
LABEL_13:
result = 0LL;
}
}
else if ( v1 > 0xB0u )
{
result = 2 * (unsigned int)(v1 == 0xC0);
}
else
{
result = 0LL;
if ( a1 < 0 )
result = ((1LL << (v1 + 0x80)) & 0x1000100010001LL) != 0 ? 3 : 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
unsigned __int8 v1; // cl
__int64 result; // rax

v1 = a1 & 0xF0;
if ( (a1 & 0xF0) == 0xD0 )
return 2LL;
if ( (a1 & 0xF0u) > 0xD0 )
{
if ( v1 == 0xE0 )
{
LABEL_10:
result = 3LL;
}
else if ( v1 == 0xF0 && (unsigned __int8)a1 >= 0xF1u )
{
switch ( a1 )
{
case -15:
case -13:
return 2LL;
case -14:
goto LABEL_10;
case -12:
case -11:
case -9:
case -3:
goto LABEL_13;
case -10:
case -8:
case -7:
case -6:
case -5:
case -4:
case -2:
case -1:
result = 1LL;
break;
}
}
else
{
LABEL_13:
result = 0LL;
}
}
else if ( v1 > 0xB0u )
{
result = 2 * (unsigned int)(v1 == 0xC0);
}
else
{
result = 0LL;
if ( a1 < 0 )
result = ((1LL << (v1 + 0x80)) & 0x1000100010001LL) != 0 ? 3 : 0;
}
return result;
}

original_code:
midi_packet_length_t midi_packet_length(uint8_t status){
   switch(status & 0xF0){
      case 0xB0:
      case 0x90:
      case 0x80:
      case 0xA0:
      case 0xE0:
         return THREE;
      case 0xC0:
      case 0xD0:
      case 0xF3:
         return TWO;
      case 0xF0:
         switch(status) {
            case 0xF8:
            case 0xF9:
            case 0xFA:
            case 0xFB:
            case 0xFC:
            case 0xFE:
            case 0xFF:
            case 0xF6:
               return ONE;
            case 0xF2:
               return THREE;
            case 0xF1:
            case 0xF3:
               return TWO;
            case 0xF7:
            case 0xF0:
            default:
               return UNDEFINED;
         }
      default:
         return UNDEFINED;
   }
}

canonical_original_code:
enum midi_packet_length_t midi_packet_length(unsigned char status){
   switch(status & 0xF0){
      case 0xB0:
      case 0x90:
      case 0x80:
      case 0xA0:
      case 0xE0:
         return THREE;
      case 0xC0:
      case 0xD0:
      case 0xF3:
         return TWO;
      case 0xF0:
         switch(status) {
            case 0xF8:
            case 0xF9:
            case 0xFA:
            case 0xFB:
            case 0xFC:
            case 0xFE:
            case 0xFF:
            case 0xF6:
               return ONE;
            case 0xF2:
               return THREE;
            case 0xF1:
            case 0xF3:
               return TWO;
            case 0xF7:
            case 0xF0:
            default:
               return UNDEFINED;
         }
      default:
         return UNDEFINED;
   }
}

variable_types:
status
unsigned char

return_type: enum midi_packet_length_t { UNDEFINED=0, ONE=1, TWO=2, THREE=3 }


decompiled_code:
__int64 __fastcall midi_send_cc(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), char a2, char a3, char a4)
{
return (*a1)(a1, 3LL, a2 & 0xF | 0xB0u, a3 & 0x7F, a4 & 0x7F);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), char a2, char a3, char a4)
{
return (*a1)(a1, 3LL, a2 & 0xF | 0xB0u, a3 & 0x7F, a4 & 0x7F);
}

original_code:
void midi_send_cc(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t val){
   device->send_func(device, 3,
         0xB0 | (chan & 0x0F),
         num & 0x7F,
         val & 0x7F);
}

canonical_original_code:
void midi_send_cc(struct _midi_device *device, unsigned char chan, unsigned char num, unsigned char val){
   device->send_func(device, 3,
         0xB0 | (chan & 0x0F),
         num & 0x7F,
         val & 0x7F);
}

variable_types: struct _midi_device { void (*send_func)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_cc_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_noteon_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_noteoff_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_aftertouch_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_pitchbend_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_songposition_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_progchange_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_chanpressure_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_songselect_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_tc_quarterframe_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_realtime_callback)(struct _midi_device *device, unsigned char byte); void (*input_tunerequest_callback)(struct _midi_device *device, unsigned char byte); void (*input_sysex_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_fallthrough_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_catchall_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*pre_input_process_callback)(struct _midi_device *device); unsigned char input_buffer[3]; enum input_state_t { IDLE=0, ONE_BYTE_MESSAGE=1, TWO_BYTE_MESSAGE=2, THREE_BYTE_MESSAGE=3, SYSEX_MESSAGE=4 } input_state; unsigned short input_count; unsigned char input_queue_data[192]; struct byteQueue_t { unsigned char start; unsigned char end; unsigned char length; unsigned char *data; } input_queue; } *

variable_types:
chan
unsigned char

variable_types:
num
unsigned char

variable_types:
val
unsigned char

user_defined_types: struct _midi_device { void (*send_func)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_cc_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_noteon_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_noteoff_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_aftertouch_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_pitchbend_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_songposition_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_progchange_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_chanpressure_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_songselect_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_tc_quarterframe_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_realtime_callback)(struct _midi_device *device, unsigned char byte); void (*input_tunerequest_callback)(struct _midi_device *device, unsigned char byte); void (*input_sysex_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_fallthrough_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_catchall_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*pre_input_process_callback)(struct _midi_device *device); unsigned char input_buffer[3]; enum input_state_t input_state; unsigned short input_count; unsigned char input_queue_data[192]; struct byteQueue_t input_queue; }


decompiled_code:
__int64 __fastcall midi_send_noteon(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), char a2, char a3, char a4)
{
return (*a1)(a1, 3LL, a2 & 0xF | 0x90u, a3 & 0x7F, a4 & 0x7F);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), char a2, char a3, char a4)
{
return (*a1)(a1, 3LL, a2 & 0xF | 0x90u, a3 & 0x7F, a4 & 0x7F);
}

original_code:
void midi_send_noteon(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel){
   device->send_func(device, 3,
         0x90 | (chan & 0x0F),
         num & 0x7F,
         vel & 0x7F);
}

canonical_original_code:
void midi_send_noteon(struct _midi_device *device, unsigned char chan, unsigned char num, unsigned char vel){
   device->send_func(device, 3,
         0x90 | (chan & 0x0F),
         num & 0x7F,
         vel & 0x7F);
}

variable_types:
vel
unsigned char

user_defined_types: enum input_state_t { IDLE=0, ONE_BYTE_MESSAGE=1, TWO_BYTE_MESSAGE=2, THREE_BYTE_MESSAGE=3, SYSEX_MESSAGE=4 }


decompiled_code:
__int64 __fastcall midi_send_noteoff(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), char a2, char a3, char a4)
{
return (*a1)(a1, 3LL, a2 & 0xF | 0x80u, a3 & 0x7F, a4 & 0x7F);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), char a2, char a3, char a4)
{
return (*a1)(a1, 3LL, a2 & 0xF | 0x80u, a3 & 0x7F, a4 & 0x7F);
}

original_code:
void midi_send_noteoff(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel){
   device->send_func(device, 3,
         0x80 | (chan & 0x0F),
         num & 0x7F,
         vel & 0x7F);
}

canonical_original_code:
void midi_send_noteoff(struct _midi_device *device, unsigned char chan, unsigned char num, unsigned char vel){
   device->send_func(device, 3,
         0x80 | (chan & 0x0F),
         num & 0x7F,
         vel & 0x7F);
}


decompiled_code:
__int64 __fastcall midi_send_aftertouch(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), char a2, char a3, char a4)
{
return (*a1)(a1, 3LL, a2 & 0xF | 0xA0u, a3 & 0x7F, a4 & 0x7F);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), char a2, char a3, char a4)
{
return (*a1)(a1, 3LL, a2 & 0xF | 0xA0u, a3 & 0x7F, a4 & 0x7F);
}

original_code:
void midi_send_aftertouch(MidiDevice * device, uint8_t chan, uint8_t note_num, uint8_t amt){
   device->send_func(device, 3,
         0xA0 | (chan & 0x0F),
         note_num & 0x7F,
         amt & 0x7F);
}

canonical_original_code:
void midi_send_aftertouch(struct _midi_device *device, unsigned char chan, unsigned char note_num, unsigned char amt){
   device->send_func(device, 3,
         0xA0 | (chan & 0x0F),
         note_num & 0x7F,
         amt & 0x7F);
}

variable_types:
amt
unsigned char


decompiled_code:
__int64 __fastcall midi_send_pitchbend(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), char a2, __int16 a3)
{
return (*a1)(a1, 3LL, a2 & 0xF | 0xE0u, ((a3 + 0x8000) >> 2) & 0x7F, (unsigned __int16)((a3 + 0x8000) >> 2) >> 7);
}

original_code:
void midi_send_pitchbend(MidiDevice * device, uint8_t chan, int16_t amt){
   uint16_t uAmt;
   uAmt=(amt-(-32767-1))>>2;
   device->send_func(device, 3,
         0xE0 | (chan & 0x0F),
         uAmt & 0x7F,
         (uAmt >> 7) & 0x7F);
}

canonical_original_code:
void midi_send_pitchbend(struct _midi_device *device, unsigned char chan, short amt){
   unsigned short uAmt;
   uAmt=(amt-(-32767-1))>>2;
   device->send_func(device, 3,
         0xE0 | (chan & 0x0F),
         uAmt & 0x7F,
         (uAmt >> 7) & 0x7F);
}

variable_types: amt short

variable_types:
uAmt
unsigned short


decompiled_code:
__int64 __fastcall midi_send_programchange(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), char a2, char a3)
{
return (*a1)(a1, 2LL, a2 & 0xF | 0xC0u, a3 & 0x7F, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), char a2, char a3)
{
return (*a1)(a1, 2LL, a2 & 0xF | 0xC0u, a3 & 0x7F, 0LL);
}

original_code:
void midi_send_programchange(MidiDevice * device, uint8_t chan, uint8_t num){
   device->send_func(device, 2,
         0xC0 | (chan & 0x0F),
         num & 0x7F,
         0);
}

canonical_original_code:
void midi_send_programchange(struct _midi_device *device, unsigned char chan, unsigned char num){
   device->send_func(device, 2,
         0xC0 | (chan & 0x0F),
         num & 0x7F,
         0);
}


decompiled_code:
__int64 __fastcall midi_send_channelpressure(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), char a2, char a3)
{
return (*a1)(a1, 2LL, a2 & 0xF | 0xD0u, a3 & 0x7F, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), char a2, char a3)
{
return (*a1)(a1, 2LL, a2 & 0xF | 0xD0u, a3 & 0x7F, 0LL);
}

original_code:
void midi_send_channelpressure(MidiDevice * device, uint8_t chan, uint8_t amt){
   device->send_func(device, 2,
         0xD0 | (chan & 0x0F),
         amt & 0x7F,
         0);
}

canonical_original_code:
void midi_send_channelpressure(struct _midi_device *device, unsigned char chan, unsigned char amt){
   device->send_func(device, 2,
         0xD0 | (chan & 0x0F),
         amt & 0x7F,
         0);
}


decompiled_code:
__int64 __fastcall midi_send_clock(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 248LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 248LL, 0LL, 0LL);
}

original_code:
void midi_send_clock(MidiDevice * device){
   device->send_func(device, 1, 0xF8, 0, 0);
}

canonical_original_code:
void midi_send_clock(struct _midi_device *device){
   device->send_func(device, 1, 0xF8, 0, 0);
}


decompiled_code:
__int64 __fastcall midi_send_tick(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 249LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 249LL, 0LL, 0LL);
}

original_code:
void midi_send_tick(MidiDevice * device){
   device->send_func(device, 1, 0xF9, 0, 0);
}

canonical_original_code:
void midi_send_tick(struct _midi_device *device){
   device->send_func(device, 1, 0xF9, 0, 0);
}


decompiled_code:
__int64 __fastcall midi_send_start(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 250LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 250LL, 0LL, 0LL);
}

original_code:
void midi_send_start(MidiDevice * device){
   device->send_func(device, 1, 0xFA, 0, 0);
}

canonical_original_code:
void midi_send_start(struct _midi_device *device){
   device->send_func(device, 1, 0xFA, 0, 0);
}


decompiled_code:
__int64 __fastcall midi_send_continue(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 251LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 251LL, 0LL, 0LL);
}

original_code:
void midi_send_continue(MidiDevice * device){
   device->send_func(device, 1, 0xFB, 0, 0);
}

canonical_original_code:
void midi_send_continue(struct _midi_device *device){
   device->send_func(device, 1, 0xFB, 0, 0);
}


decompiled_code:
__int64 __fastcall midi_send_stop(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 252LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 252LL, 0LL, 0LL);
}

original_code:
void midi_send_stop(MidiDevice * device){
   device->send_func(device, 1, 0xFC, 0, 0);
}

canonical_original_code:
void midi_send_stop(struct _midi_device *device){
   device->send_func(device, 1, 0xFC, 0, 0);
}


decompiled_code:
__int64 __fastcall midi_send_activesense(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 254LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 254LL, 0LL, 0LL);
}

original_code:
void midi_send_activesense(MidiDevice * device){
   device->send_func(device, 1, 0xFE, 0, 0);
}

canonical_original_code:
void midi_send_activesense(struct _midi_device *device){
   device->send_func(device, 1, 0xFE, 0, 0);
}


decompiled_code:
__int64 __fastcall midi_send_reset(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 255LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 255LL, 0LL, 0LL);
}

original_code:
void midi_send_reset(MidiDevice * device){
   device->send_func(device, 1, 0xFF, 0, 0);
}

canonical_original_code:
void midi_send_reset(struct _midi_device *device){
   device->send_func(device, 1, 0xFF, 0, 0);
}


decompiled_code:
__int64 __fastcall midi_send_tcquarterframe(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD), char a2)
{
return (*a1)(a1, 2LL, 241LL, a2 & 0x7F, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD), char a2)
{
return (*a1)(a1, 2LL, 241LL, a2 & 0x7F, 0LL);
}

original_code:
void midi_send_tcquarterframe(MidiDevice * device, uint8_t time){
   device->send_func(device, 2,
         0xF1,
         time & 0x7F,
         0);
}

canonical_original_code:
void midi_send_tcquarterframe(struct _midi_device *device, unsigned char time){
   device->send_func(device, 2,
         0xF1,
         time & 0x7F,
         0);
}

variable_types:
time
unsigned char


decompiled_code:
__int64 __fastcall midi_send_songposition(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD), unsigned __int16 a2)
{
return (*a1)(a1, 3LL, 242LL, a2 & 0x7F, (a2 >> 7) & 0x7F);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD), unsigned __int16 a2)
{
return (*a1)(a1, 3LL, 242LL, a2 & 0x7F, (a2 >> 7) & 0x7F);
}

original_code:
void midi_send_songposition(MidiDevice * device, uint16_t pos){
   device->send_func(device, 3,
         0xF2,
         pos & 0x7F,
         (pos >> 7) & 0x7F);
}

canonical_original_code:
void midi_send_songposition(struct _midi_device *device, unsigned short pos){
   device->send_func(device, 3,
         0xF2,
         pos & 0x7F,
         (pos >> 7) & 0x7F);
}

variable_types:
pos
unsigned short


decompiled_code:
__int64 __fastcall midi_send_songselect(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD), char a2)
{
return (*a1)(a1, 2LL, 243LL, a2 & 0x7F, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD), char a2)
{
return (*a1)(a1, 2LL, 243LL, a2 & 0x7F, 0LL);
}

original_code:
void midi_send_songselect(MidiDevice * device, uint8_t song){
   device->send_func(device, 2,
         0xF3,
         song & 0x7F,
         0);
}

canonical_original_code:
void midi_send_songselect(struct _midi_device *device, unsigned char song){
   device->send_func(device, 2,
         0xF3,
         song & 0x7F,
         0);
}

variable_types:
song
unsigned char


decompiled_code:
__int64 __fastcall midi_send_tunerequest(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 246LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 (__fastcall **a1)(_QWORD, __int64, __int64, _QWORD, _QWORD))
{
return (*a1)(a1, 1LL, 246LL, 0LL, 0LL);
}

original_code:
void midi_send_tunerequest(MidiDevice * device){
   device->send_func(device, 1, 0xF6, 0, 0);
}

canonical_original_code:
void midi_send_tunerequest(struct _midi_device *device){
   device->send_func(device, 1, 0xF6, 0, 0);
}


decompiled_code:
__int64 __fastcall midi_send_byte(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), unsigned __int8 a2)
{
return (*a1)(a1, 1LL, a2, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 (__fastcall **a1)(_QWORD, __int64, _QWORD, _QWORD, _QWORD), unsigned __int8 a2)
{
return (*a1)(a1, 1LL, a2, 0LL, 0LL);
}

original_code:
void midi_send_byte(MidiDevice * device, uint8_t b){
   device->send_func(device, 1, b, 0, 0);
}

canonical_original_code:
void midi_send_byte(struct _midi_device *device, unsigned char b){
   device->send_func(device, 1, b, 0, 0);
}

variable_types:
b
unsigned char


decompiled_code:
__int64 __fastcall midi_send_data(__int64 (__fastcall **a1)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD), unsigned __int16 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int8 a5)
{
return (*a1)(a1, a2, a3, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 (__fastcall **a1)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD), unsigned __int16 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int8 a5)
{
return (*a1)(a1, a2, a3, a4, a5);
}

original_code:
void midi_send_data(MidiDevice * device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2){
   if (count > 3) {
   }
   device->send_func(device, count, byte0, byte1, byte2);
}

canonical_original_code:
void midi_send_data(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2){
   if (count > 3) {
   }
   device->send_func(device, count, byte0, byte1, byte2);
}

variable_types:
count
unsigned short


decompiled_code:
void __fastcall midi_send_array(__int64 (__fastcall **a1)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD), unsigned __int16 a2, __int64 a3)
{
unsigned __int16 i; // r12
unsigned __int16 v6; // si
unsigned int v7; // eax
__int64 v8; // rdx
__int16 v9; // [rsp+1h] [rbp-2Bh]
unsigned __int8 v10; // [rsp+3h] [rbp-29h]

if ( a2 )
{
for ( i = 0; i < a2; i += 3 )
{
v10 = 0;
v6 = a2 - i;
v9 = 0;
if ( (unsigned __int16)(a2 - i) > 3u )
v6 = 3;
if ( v6 )
{
v7 = 0;
do
{
v8 = v7++;
*((_BYTE *)&v9 + v8) = *(_BYTE *)(a3 + v8);
}
while ( v7 < v6 );
}
a3 += 3LL;
midi_send_data(a1, v6, v9, HIBYTE(v9), v10);
}
}
}

canonical_decompiled_code:
void __fastcall func23(__int64 (__fastcall **a1)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD), unsigned __int16 a2, __int64 a3)
{
unsigned __int16 i; // r12
unsigned __int16 v6; // si
unsigned int v7; // eax
__int64 v8; // rdx
__int16 v9; // [rsp+1h] [rbp-2Bh]
unsigned __int8 v10; // [rsp+3h] [rbp-29h]

if ( a2 )
{
for ( i = 0; i < a2; i += 3 )
{
v10 = 0;
v6 = a2 - i;
v9 = 0;
if ( (unsigned __int16)(a2 - i) > 3u )
v6 = 3;
if ( v6 )
{
v7 = 0;
do
{
v8 = v7++;
*((_BYTE *)&v9 + v8) = *(_BYTE *)(a3 + v8);
}
while ( v7 < v6 );
}
a3 += 3LL;
func22(a1, v6, v9, HIBYTE(v9), v10);
}
}
}

original_code:
void midi_send_array(MidiDevice * device, uint16_t count, uint8_t * array) {
  uint16_t i;
  for (i = 0; i < count; i += 3) {
    uint8_t b[3] = { 0, 0, 0 };
    uint16_t to_send = count - i;
    to_send = (to_send > 3) ? 3 : to_send;
    memcpy(b, array + i, to_send);
    midi_send_data(device, to_send, b[0], b[1], b[2]);
  }
}

canonical_original_code:
void midi_send_array(struct _midi_device *device, unsigned short count, unsigned char *array) {
  unsigned short i;
  for (i = 0; i < count; i += 3) {
    unsigned char b[3] = { 0, 0, 0 };
    unsigned short to_send = count - i;
    to_send = (to_send > 3) ? 3 : to_send;
    memcpy(b, array + i, to_send);
    midi_send_data(device, to_send, b[0], b[1], b[2]);
  }
}

variable_types:
array
unsigned char *

variable_types:
i
unsigned short

variable_types:
b
unsigned char [3]


decompiled_code:
void __fastcall midi_register_cc_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

original_code:
void midi_register_cc_callback(MidiDevice * device, midi_three_byte_func_t func){
   device->input_cc_callback = func;
}

canonical_original_code:
void midi_register_cc_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2)){
   device->input_cc_callback = func;
}

variable_types: void (*)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2)


decompiled_code:
void __fastcall midi_register_noteon_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 16) = a2;
}

original_code:
void midi_register_noteon_callback(MidiDevice * device, midi_three_byte_func_t func){
   device->input_noteon_callback = func;
}

canonical_original_code:
void midi_register_noteon_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2)){
   device->input_noteon_callback = func;
}

variable_types: struct _midi_device { void (*send_func)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_cc_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_noteon_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_noteoff_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_aftertouch_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_pitchbend_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_songposition_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_progchange_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_chanpressure_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_songselect_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_tc_quarterframe_callback)(struct _midi_device *device, unsigned char byte0, unsigned char byte1); void (*input_realtime_callback)(struct _midi_device *device, unsigned char byte); void (*input_tunerequest_callback)(struct _midi_device *device, unsigned char byte); void (*input_sysex_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_fallthrough_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*input_catchall_callback)(struct _midi_device *device, unsigned short count, unsigned char byte0, unsigned char byte1, unsigned char byte2); void (*pre_input_process_callback)(struct _midi_device *device); unsigned char input_buffer[3]; enum input_state_t { IDLE=0, ONE_BYTE_MESSAGE=1, TWO_BYTE_MESSAGE=2, THREE_BYTE_MESSAGE=3, SYSEX_MESSAGE=4 } input_state; unsigned short input_count; unsigned char input_queue_data[192]; struct byteQueue_t { unsigned char start; unsigned char end; unsigned char length; unsigned char *data; } input_queue; } *


decompiled_code:
void __fastcall midi_register_noteoff_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 24) = a2;
}

original_code:
void midi_register_noteoff_callback(MidiDevice * device, midi_three_byte_func_t func){
   device->input_noteoff_callback = func;
}

canonical_original_code:
void midi_register_noteoff_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2)){
   device->input_noteoff_callback = func;
}


decompiled_code:
void __fastcall midi_register_aftertouch_callback(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 32) = a2;
}

original_code:
void midi_register_aftertouch_callback(MidiDevice * device, midi_three_byte_func_t func){
   device->input_aftertouch_callback = func;
}

canonical_original_code:
void midi_register_aftertouch_callback(struct _midi_device *device, void (*func)(struct _midi_device *device, unsigned char byte0, unsigned char byte1, unsigned char byte2)){
   device->input_aftertouch_callback = func;
}