decompiled_code:
unsigned __int64 gethrcycle_x86()
{
return __rdtsc();
}

canonical_decompiled_code:
unsigned __int64 func7()
{
return __rdtsc();
}

original_code:
hrtime_t gethrcycle_x86(void)
{
    unsigned int tmp[2];
    __asm__ ("rdtsc"
      : "=a" (tmp[1]), "=d" (tmp[0])
      : "c" (0x10) );
    return ( ((hrtime_t)tmp[0] << 32 | tmp[1]) );
}

canonical_original_code:
long long gethrcycle_x86()
{
    unsigned int tmp[2];
    __asm__ ("rdtsc"
      : "=a" (tmp[1]), "=d" (tmp[0])
      : "c" (0x10) );
    return ( ((long long)tmp[0] << 32 | tmp[1]) );
}

variable_types:
tmp
unsigned int [2]

return_type: long long


decompiled_code:
double gethrtime_x86()
{
__int64 v0; // xmm1_8

v0 = CPU_MHZ_0;
if ( *(double *)&CPU_MHZ_0 == 0.0 )
{
*(double *)&v0 = getMHZ_x86();
CPU_MHZ_0 = v0;
}
return (double)(int)gethrcycle_x86() * 0.000001 / *(double *)&v0;
}

canonical_decompiled_code:
double func9()
{
__int64 v0; // xmm1_8

v0 = CPU_MHZ_0;
if ( *(double *)&CPU_MHZ_0 == 0.0 )
{
*(double *)&v0 = func8();
CPU_MHZ_0 = v0;
}
return (double)(int)func7() * 0.000001 / *(double *)&v0;
}

original_code:
double gethrtime_x86(void)
{
    static double CPU_MHZ=0;
    if (CPU_MHZ==0) CPU_MHZ=getMHZ_x86();
    return (gethrcycle_x86()*0.000001)/CPU_MHZ;
}

canonical_original_code:
double gethrtime_x86()
{
    static double CPU_MHZ = 0;
    if (CPU_MHZ==0) CPU_MHZ=getMHZ_x86();
    return (gethrcycle_x86()*0.000001)/CPU_MHZ;
}

return_type: double


empty

decompiled_code:
void empty()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code: void empty(void){}

canonical_original_code: void empty(){}

return_type: void


threadMain

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

v1 = 10000;
do
{
pthread_spin_lock(&lock);
++shared_counter;
pthread_spin_unlock(&lock);
--v1;
}
while ( v1 );
return 0LL;
}

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

v1 = 10000;
do
{
pthread_spin_lock(&lock);
++shared_counter;
pthread_spin_unlock(&lock);
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
void *threadMain(void *args)
{
 int i;
 for (i = 0; i < 10000; ++i)
 {
  pthread_spin_lock(&lock);
  shared_counter++;
  pthread_spin_unlock(&lock);
 }
 return ((void *)0);
}

variable_types:
args
void *

variable_types: i int

return_type: void *


canonical_decompiled_code:
unsigned __int64 func8()
{
return __rdtsc();
}


canonical_decompiled_code:
double func10()
{
__int64 v0; // xmm1_8

v0 = CPU_MHZ_0;
if ( *(double *)&CPU_MHZ_0 == 0.0 )
{
*(double *)&v0 = func9();
CPU_MHZ_0 = v0;
}
return (double)(int)func8() * 0.000001 / *(double *)&v0;
}


NewRecEle

decompiled_code:
void *NewRecEle()
{
return calloc(0x20uLL, 1uLL);
}

canonical_decompiled_code:
void *func1()
{
return calloc(0x20uLL, 1uLL);
}

original_code:
REC_INFO* NewRecEle()
{
    REC_INFO* pRec = ((void *)0);
    pRec = (REC_INFO*)malloc(sizeof(REC_INFO));
    OutString((1<<3),"Malloc ELE\n");
    if(pRec == ((void *)0))
    {
        return ((void *)0);
    }
    memset(pRec,0,sizeof(REC_INFO));
    return pRec;
}

canonical_original_code:
struct REC_INFO_STRU *NewRecEle()
{
    struct REC_INFO_STRU *pRec = ((void *)0);
    pRec = (struct REC_INFO_STRU *)malloc(sizeof(REC_INFO));
    OutString((1<<3),"Malloc ELE\n");
    if(pRec == ((void *)0))
    {
        return ((void *)0);
    }
    memset(pRec,0,sizeof(REC_INFO));
    return pRec;
}

variable_types: struct REC_INFO_STRU { enum ELE_TYPE { ELE_SEPERATOR=0, ELE_TEXT=1, ELE_END=2 } type; char *pContent; enum ELE_SEPERATOR_TYPE { SEP_COMMA=0, SEP_COLON=1, SEP_EQUAL=2, SEP_SPACE=3, SEP_RETURN=4, SEP_NEXTLINE=5, SEP_END=6 } sep; struct REC_INFO_STRU *pNext; } *

user_defined_types: struct REC_INFO_STRU { enum ELE_TYPE type; char *pContent; enum ELE_SEPERATOR_TYPE sep; struct REC_INFO_STRU *pNext; }


SaveTextInfo

decompiled_code:
__int64 __fastcall SaveTextInfo(__int64 a1, const void *a2, size_t a3)
{
unsigned int v3; // er12
void *v6; // rax

v3 = 0;
if ( !a3 )
return v3;
v6 = malloc(a3 + 1);
*(_QWORD *)(a1 + 8) = v6;
if ( !v6 )
return (unsigned int)-1;
*((_BYTE *)memcpy(v6, a2, a3) + a3) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const void *a2, size_t a3)
{
unsigned int v3; // er12
void *v6; // rax

v3 = 0;
if ( !a3 )
return v3;
v6 = malloc(a3 + 1);
*(_QWORD *)(a1 + 8) = v6;
if ( !v6 )
return (unsigned int)-1;
*((_BYTE *)memcpy(v6, a2, a3) + a3) = 0;
return 0LL;
}

original_code:
int SaveTextInfo(REC_INFO* pEle, char* pStr, size_t strLen)
{
    if(strLen > 0)
    {
        pEle->pContent = (char*)malloc(strLen + 1);
        if(pEle->pContent == ((void *)0))
        {
            return -1;
        }
        memcpy(pEle->pContent, pStr, strLen);
        pEle->pContent[strLen] = '\0';
    }
    return 0;
}

canonical_original_code:
int SaveTextInfo(struct REC_INFO_STRU *pEle, char *pStr, unsigned long strLen)
{
    if(strLen > 0)
    {
        pEle->pContent = (char *)malloc(strLen + 1);
        if(pEle->pContent == ((void *)0))
        {
            return -1;
        }
        memcpy(pEle->pContent, pStr, strLen);
        pEle->pContent[strLen] = '\0';
    }
    return 0;
}

variable_types:
pStr
char *

variable_types:
strLen
unsigned long

return_type: int

user_defined_types: enum ELE_TYPE { ELE_SEPERATOR=0, ELE_TEXT=1, ELE_END=2 }

user_defined_types: enum ELE_SEPERATOR_TYPE { SEP_COMMA=0, SEP_COLON=1, SEP_EQUAL=2, SEP_SPACE=3, SEP_RETURN=4, SEP_NEXTLINE=5, SEP_END=6 }


SaveSepInfo

decompiled_code:
__int64 __fastcall SaveSepInfo(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
return 0LL;
}

original_code:
int SaveSepInfo(REC_INFO* pEle, enum ELE_SEPERATOR_TYPE sepType)
{
    pEle->sep = sepType;
    return 0;
}

canonical_original_code:
int SaveSepInfo(struct REC_INFO_STRU *pEle, enum ELE_SEPERATOR_TYPE sepType)
{
    pEle->sep = sepType;
    return 0;
}

variable_types: enum ELE_SEPERATOR_TYPE { SEP_COMMA=0, SEP_COLON=1, SEP_EQUAL=2, SEP_SPACE=3, SEP_RETURN=4, SEP_NEXTLINE=5, SEP_END=6 }


DelAllEle

decompiled_code:
void __fastcall DelAllEle(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void *v3; // rdi

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)v1[3];
v3 = (void *)v2[1];
if ( v3 )
free(v3);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void *v3; // rdi

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)v1[3];
v3 = (void *)v2[1];
if ( v3 )
free(v3);
free(v2);
}
while ( v1 );
}
}

original_code:
void DelAllEle(REC_INFO* pEle)
{
    REC_INFO* pEleDel;
    REC_INFO* pEleNext;
    pEleDel = pEle;
    while(pEleDel)
    {
        pEleNext = pEleDel->pNext;
        if(pEleDel->pContent)
        {
            free(pEleDel->pContent);
        }
        free(pEleDel);
        OutString((1<<3), "FREE ELE\n");
        pEleDel = pEleNext;
    }
    return;
}

canonical_original_code:
void DelAllEle(struct REC_INFO_STRU *pEle)
{
    struct REC_INFO_STRU *pEleDel;
    struct REC_INFO_STRU *pEleNext;
    pEleDel = pEle;
    while(pEleDel)
    {
        pEleNext = pEleDel->pNext;
        if(pEleDel->pContent)
        {
            free(pEleDel->pContent);
        }
        free(pEleDel);
        OutString((1<<3), "FREE ELE\n");
        pEleDel = pEleNext;
    }
    return;
}


OutputRecInfo

decompiled_code:
void __fastcall OutputRecInfo(__int64 a1)
{
__int64 v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
if ( *(_DWORD *)v1 )
{
if ( *(_DWORD *)v1 != 1 )
return;
printf("ELE_TEXT[%s]\n", *(const char **)(v1 + 8));
}
else
{
printf("ELE_SEPERATOR[%c]\n", (unsigned int)seperator[*(unsigned int *)(v1 + 16)]);
}
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
__int64 v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
if ( *(_DWORD *)v1 )
{
if ( *(_DWORD *)v1 != 1 )
return;
printf("ELE_TEXT[%s]\n", *(const char **)(v1 + 8));
}
else
{
printf("ELE_SEPERATOR[%c]\n", (unsigned int)seperator[*(unsigned int *)(v1 + 16)]);
}
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
}

original_code:
void OutputRecInfo(REC_INFO* pEle)
{
    while(pEle)
    {
        switch(pEle->type)
        {
            case ELE_TEXT:
                printf("ELE_TEXT[%s]\n", pEle->pContent);
                break;
            case ELE_SEPERATOR:
                printf("ELE_SEPERATOR[%c]\n", seperator[pEle->sep]);
                break;
            default:
                return;
        }
        pEle = pEle->pNext;
    }
    return;
}

canonical_original_code:
void OutputRecInfo(struct REC_INFO_STRU *pEle)
{
    while(pEle)
    {
        switch(pEle->type)
        {
            case ELE_TEXT:
                printf("ELE_TEXT[%s]\n", pEle->pContent);
                break;
            case ELE_SEPERATOR:
                printf("ELE_SEPERATOR[%c]\n", seperator[pEle->sep]);
                break;
            default:
                return;
        }
        pEle = pEle->pNext;
    }
    return;
}


fillBuffer

decompiled_code:
void *__fastcall fillBuffer(float a1)
{
void *result; // rax

result = memmove(&unk_4040A4, &sampleBuffer, 0xC8uLL);
sampleBuffer = LODWORD(a1);
return result;
}

canonical_decompiled_code:
void *__fastcall func7(float a1)
{
void *result; // rax

result = memmove(&unk_4040A4, &sampleBuffer, 0xC8uLL);
sampleBuffer = LODWORD(a1);
return result;
}

original_code:
void fillBuffer(float v){
 for(int i = 51 -1; i>0; i--){
  sampleBuffer[i] = sampleBuffer[i-1];
 }
 sampleBuffer[0] = v;
}

variable_types: v float


rms

decompiled_code:
void __fastcall rms(void *src, float a2)
{
float *v3; // rdi
float v4; // xmm0_4
float v5; // xmm0_4
float v6; // [rsp+4h] [rbp-Ch]

v3 = (float *)((char *)src + 4);
v6 = a2 * a2;
v4 = (float)((float)(a2 * a2) + v3[178]) - v3[126];
v3[178] = v4;
memmove(v3, src, 0x1FCuLL);
v5 = v4 * 0.0078125;
*(float *)src = v6;
if ( v5 < 0.0 )
sqrtf(v5);
}

canonical_decompiled_code:
void __fastcall func8(void *src, float a2)
{
float *v3; // rdi
float v4; // xmm0_4
float v5; // xmm0_4
float v6; // [rsp+4h] [rbp-Ch]

v3 = (float *)((char *)src + 4);
v6 = a2 * a2;
v4 = (float)((float)(a2 * a2) + v3[178]) - v3[126];
v3[178] = v4;
memmove(v3, src, 0x1FCuLL);
v5 = v4 * 0.0078125;
*(float *)src = v6;
if ( v5 < 0.0 )
sqrtf(v5);
}

original_code:
float rms(float v, struct Filter* filter){
 filter->sum = filter->sum + v*v - filter->squareBuffer[128 -1];
 for(int i = 128 -1; i>0; i--){
  filter->squareBuffer[i] = filter->squareBuffer[i-1];
 }
 filter->squareBuffer[0] = v*v;
 return sqrt(filter->sum/128);
}

canonical_original_code:
float rms(float v, struct Filter *filter){
 filter->sum = filter->sum + v*v - filter->squareBuffer[128 -1];
 for(int i = 128 -1; i>0; i--){
  filter->squareBuffer[i] = filter->squareBuffer[i-1];
 }
 filter->squareBuffer[0] = v*v;
 return sqrt(filter->sum/128);
}

variable_types: struct Filter { float squareBuffer[128]; float coeffBuffer[51]; float sum; } *

return_type: float


generateSample

decompiled_code:
float __fastcall generateSample(float a1)
{
float i; // xmm0_4

for ( i = a1 * 3.1415; i > 0.0; i = i - 6.283 )
;
return cos(i);
}

canonical_decompiled_code:
float __fastcall func10(float a1)
{
float i; // xmm0_4

for ( i = a1 * 3.1415; i > 0.0; i = i - 6.283 )
;
return cos(i);
}

original_code:
float generateSample(float x){
 float y = (3.1415*x);
 while(y>0){
  y-=2*3.1415;
 }
 return cos(y);
}

variable_types: x float

variable_types: y float


dft

original_code:
float* dft(float values[]){
 float resRE[512];
 float resIM[512];
 float *resAbs = (float*)malloc(sizeof(float)*512);
 if(resAbs==((void *)0)){
  printf("ERROR");
  return ((void *)0);
 }
 for(int i = 0; i<512; i++){
  resRE[i] = 0;
  resIM[i] = 0;
 }
 for(int k = 0; k< 512; k++){
  for(int j = 0; j< 512; j++){
  resRE[k] = resRE[k]+values[j]*cos(2*3.1415*j*k/512);
  resIM[k] = resIM[k]+values[j]*sin(-2*3.1415*j*k/512);
  }
 }
 for(int i = 0; i<512; i++){
  resAbs[i] = resRE[i]*resRE[i]+resIM[i]*resIM[i];
 }
 return resAbs;
}

canonical_original_code:
float *dft(float values[]){
 float resRE[512];
 float resIM[512];
 float *resAbs = (float*)malloc(sizeof(float)*512);
 if(resAbs==((void *)0)){
  printf("ERROR");
  return ((void *)0);
 }
 for(int i = 0; i<512; i++){
  resRE[i] = 0;
  resIM[i] = 0;
 }
 for(int k = 0; k< 512; k++){
  for(int j = 0; j< 512; j++){
  resRE[k] = resRE[k]+values[j]*cos(2*3.1415*j*k/512);
  resIM[k] = resIM[k]+values[j]*sin(-2*3.1415*j*k/512);
  }
 }
 for(int i = 0; i<512; i++){
  resAbs[i] = resRE[i]*resRE[i]+resIM[i]*resIM[i];
 }
 return resAbs;
}

variable_types:
values
float []

variable_types:
resRE
float [512]

variable_types:
resIM
float [512]

variable_types:
resAbs
float *

variable_types: k int

variable_types: j int

return_type: float *


main

canonical_name: main

repo: sofuture/tfig

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
void *v4; // r12

v3 = (void *)parse_opts(argc, (char **)argv);
v4 = (void *)load_data(v3);
draw_data(v4, v3);
ll_free(v4);
free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
void *v4; // r12

v3 = (void *)parse_opts(argc, (char **)argv);
v4 = (void *)func10(v3);
func11(v4, v3);
func15(v4);
free(v3);
return 0;
}

original_code:
int main (int argc, char **argv) {
    settings *set = parse_opts(argc, argv);
    list *dat = load_data(set);
    draw_data(dat, set);
    ll_free(dat);
    free(set);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    struct settings *set = parse_opts(argc, argv);
    struct list *dat = load_data(set);
    draw_data(dat, set);
    ll_free(dat);
    free(set);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct settings { int xmin; int xmax; int ymin; int ymax; int height; int width; char asize; char *sym; } *

variable_types: struct list { struct node { double x; double y; struct node *next; } *head; int ct; } *

user_defined_types: struct list { struct node *head; int ct; }


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "%s -x xMin -X xMax -y yMin -Y yMax -w width -h height -s symbol\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(const char *a1)
{
fprintf(stderr, "%s -x xMin -X xMax -y yMin -Y yMax -w width -h height -s symbol\n", a1);
exit(1);
}

original_code:
static void usage(const char * const prog){
    fprintf(stderr, "%s -x xMin -X xMax -y yMin -Y yMax"
                    " -w width -h height -s symbol\n", prog);
    exit(1);
}

canonical_original_code:
static void usage(char *prog){
    fprintf(stderr, "%s -x xMin -X xMax -y yMin -Y yMax"
                    " -w width -h height -s symbol\n", prog);
    exit(1);
}

variable_types:
prog
char *


decompiled_code:
_QWORD *ll_new()
{
_QWORD *result; // rax

result = malloc(8uLL);
result[1] = 0LL;
*result = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

canonical_decompiled_code:
_QWORD *func13()
{
_QWORD *result; // rax

result = malloc(8uLL);
result[1] = 0LL;
*result = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

original_code:
list *ll_new(){
    list *list = malloc(sizeof(list));
    list->head = list->tail = ((void *)0);
    list->ct = 0;
    return list;
}

canonical_original_code:
struct list *ll_new(){
    struct list *list = malloc(sizeof(list));
    list->head = list->tail = ((void *)0);
    list->ct = 0;
    return list;
}

return_type: struct list { struct node { double x; double y; struct node *next; } *head; int ct; } *


decompiled_code:
void __fastcall ll_free(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func15(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void ll_free(list * list){
    node *current = list->head;
    node *next = current;
    while(current != ((void *)0)){
        next = current->next;
        free(current);
        current = next;
    }
    free(list);
}

canonical_original_code:
void ll_free(struct list *list){
    struct node *current = list->head;
    struct node *next = current;
    while(current != ((void *)0)){
        next = current->next;
        free(current);
        current = next;
    }
    free(list);
}

variable_types: struct node { double x; double y; struct node *next; } *


repo: sohgoh/mysql

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

if ( (unsigned int)(*(_DWORD *)a2 - 2) > 1 )
{
strncpy(a3, "file_put('/path/to/file','file_contents'[,0755])", 0x200uLL);
result = 1LL;
}
else
{
v3 = *(_QWORD *)(a2 + 8);
*(_QWORD *)v3 = 0LL;
*(_DWORD *)(v3 + 8) = 2;
result = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
return result;
}

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

if ( (unsigned int)(*(_DWORD *)a2 - 2) > 1 )
{
strncpy(a3, "file_put('/path/to/file','file_contents'[,0755])", 0x200uLL);
result = 1LL;
}
else
{
v3 = *(_QWORD *)(a2 + 8);
*(_QWORD *)v3 = 0LL;
*(_DWORD *)(v3 + 8) = 2;
result = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
return result;
}

original_code:
my_bool file_put_init(UDF_INIT *initid, UDF_ARGS *args, char *message){
  if( args->arg_count!=2 && args->arg_count!=3 ){
    strncpy(message, "file_put('/path/to/file','file_contents'[,0755])", 512);
    return 1;
  }
  args->arg_type[0] = STRING_RESULT;
  args->arg_type[1] = STRING_RESULT;
  args->arg_type[2] = INT_RESULT;
  initid->ptr = ((void *)0);
  return 0;
}

canonical_original_code:
char file_put_init(struct st_udf_init *initid, struct st_udf_args *args, char *message){
  if( args->arg_count!=2 && args->arg_count!=3 ){
    strncpy(message, "file_put('/path/to/file','file_contents'[,0755])", 512);
    return 1;
  }
  args->arg_type[0] = STRING_RESULT;
  args->arg_type[1] = STRING_RESULT;
  args->arg_type[2] = INT_RESULT;
  initid->ptr = ((void *)0);
  return 0;
}

variable_types: struct st_udf_init { char maybe_null; unsigned int decimals; unsigned int max_length; char *ptr; char const_item; } *

variable_types: struct st_udf_args { unsigned int arg_count; enum Item_result { STRING_RESULT=0, REAL_RESULT=1, INT_RESULT=2, ROW_RESULT=3, DECIMAL_RESULT=4 } *arg_type; char **args; unsigned long *lengths; char *maybe_null; } *

variable_types:
message
char *

return_type: char

user_defined_types: struct st_udf_args { unsigned int arg_count; enum Item_result *arg_type; char **args; unsigned long *lengths; char *maybe_null; }


original_code:
char *file_put(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error){
  pthread_mutex_lock(&file_servers_mutex);
  unsigned int perm=0,perm_arg=0;
  if( args->arg_count==3 ){
    perm_arg = *((long*)args->args[2]);
    char buf[12];
    if( args->arg_type[2] == INT_RESULT && args->lengths[2] == 4 ){
      sprintf(buf,"0%d",perm_arg);
      perm_arg = strtol(buf,((void *)0),8);
    }
    if( perm_arg & 0400 ){ perm |= 0400; }
    if( perm_arg & 0200 ){ perm |= 0200; }
    if( perm_arg & 0100 ){ perm |= 0100; }
    if( perm_arg & 0040 ){ perm |= (0400 >> 3); }
    if( perm_arg & 0020 ){ perm |= (0200 >> 3); }
    if( perm_arg & 0010 ){ perm |= (0100 >> 3); }
    if( perm_arg & 0004 ){ perm |= ((0400 >> 3) >> 3); }
    if( perm_arg & 0002 ){ perm |= ((0200 >> 3) >> 3); }
    if( perm_arg & 0001 ){ perm |= ((0100 >> 3) >> 3); }
  }else{
    perm = 00666;
  }
  int fd;
  long written_bytes = 0;
  fd = open(args->args[0],02|0100|01000,perm);
  written_bytes = write(fd,args->args[1],args->lengths[1]);
  close(fd);
  chmod(args->args[0],perm);
  sprintf(result,"%ld",written_bytes);
  *length = strlen(result);
  pthread_mutex_unlock(&file_servers_mutex);
  return result;
}

canonical_original_code:
char *file_put(struct st_udf_init *initid, struct st_udf_args *args, char *result, unsigned long *length, char *is_null, char *error){
  pthread_mutex_lock(&file_servers_mutex);
  unsigned int perm = 0; unsigned int perm_arg = 0;
  if( args->arg_count==3 ){
    perm_arg = *((long *)args->args[2]);
    char buf[12];
    if( args->arg_type[2] == INT_RESULT && args->lengths[2] == 4 ){
      sprintf(buf,"0%d",perm_arg);
      perm_arg = strtol(buf,((void *)0),8);
    }
    if( perm_arg & 0400 ){ perm |= 0400; }
    if( perm_arg & 0200 ){ perm |= 0200; }
    if( perm_arg & 0100 ){ perm |= 0100; }
    if( perm_arg & 0040 ){ perm |= (0400 >> 3); }
    if( perm_arg & 0020 ){ perm |= (0200 >> 3); }
    if( perm_arg & 0010 ){ perm |= (0100 >> 3); }
    if( perm_arg & 0004 ){ perm |= ((0400 >> 3) >> 3); }
    if( perm_arg & 0002 ){ perm |= ((0200 >> 3) >> 3); }
    if( perm_arg & 0001 ){ perm |= ((0100 >> 3) >> 3); }
  }else{
    perm = 00666;
  }
  int fd;
  long written_bytes = 0;
  fd = open(args->args[0],02|0100|01000,perm);
  written_bytes = write(fd,args->args[1],args->lengths[1]);
  close(fd);
  chmod(args->args[0],perm);
  sprintf(result,"%ld",written_bytes);
  *length = strlen(result);
  pthread_mutex_unlock(&file_servers_mutex);
  return result;
}

variable_types:
result
char *

variable_types:
length
unsigned long *

variable_types:
error
char *

variable_types:
perm
unsigned int

variable_types:
buf
char [12]

variable_types: fd int

return_type: char *

user_defined_types: struct st_udf_init { char maybe_null; unsigned int decimals; unsigned int max_length; char *ptr; char const_item; }

user_defined_types: enum Item_result { STRING_RESULT=0, REAL_RESULT=1, INT_RESULT=2, ROW_RESULT=3, DECIMAL_RESULT=4 }


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

if ( *(_DWORD *)a2 == 1 )
{
**(_DWORD **)(a2 + 8) = 0;
result = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
else
{
strncpy(a3, "file_delete('/path/to/file')", 0x200uLL);
result = 1LL;
}
return result;
}

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

if ( *(_DWORD *)a2 == 1 )
{
**(_DWORD **)(a2 + 8) = 0;
result = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
else
{
strncpy(a3, "file_delete('/path/to/file')", 0x200uLL);
result = 1LL;
}
return result;
}

original_code:
my_bool file_delete_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
  if( args->arg_count!=1 ){
    strncpy(message, "file_delete('/path/to/file')", 512);
    return 1;
  }
  args->arg_type[0] = STRING_RESULT;
  initid->ptr = ((void *)0);
  return 0;
}

canonical_original_code:
char file_delete_init(struct st_udf_init *initid, struct st_udf_args *args, char *message)
{
  if( args->arg_count!=1 ){
    strncpy(message, "file_delete('/path/to/file')", 512);
    return 1;
  }
  args->arg_type[0] = STRING_RESULT;
  initid->ptr = ((void *)0);
  return 0;
}


decompiled_code:
char *__fastcall file_delete(__int64 a1, __int64 a2, char *a3, size_t *a4)
{
unsigned int v6; // eax

pthread_mutex_lock(&file_servers_mutex);
v6 = unlink(**(const char ***)(a2 + 16));
sprintf(a3, "%d", v6);
*a4 = strlen(a3);
pthread_mutex_unlock(&file_servers_mutex);
return a3;
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1, __int64 a2, char *a3, size_t *a4)
{
unsigned int v6; // eax

pthread_mutex_lock(&file_servers_mutex);
v6 = unlink(**(const char ***)(a2 + 16));
sprintf(a3, "%d", v6);
*a4 = strlen(a3);
pthread_mutex_unlock(&file_servers_mutex);
return a3;
}

original_code:
char *file_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error)
{
  pthread_mutex_lock(&file_servers_mutex);
  int is_deleted = unlink(args->args[0]);
  sprintf(result,"%d",is_deleted);
  *length = strlen(result);
  pthread_mutex_unlock(&file_servers_mutex);
  return result;
}

canonical_original_code:
char *file_delete(struct st_udf_init *initid, struct st_udf_args *args, char *result, unsigned long *length, char *is_null, char *error)
{
  pthread_mutex_lock(&file_servers_mutex);
  int is_deleted = unlink(args->args[0]);
  sprintf(result,"%d",is_deleted);
  *length = strlen(result);
  pthread_mutex_unlock(&file_servers_mutex);
  return result;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4; // rdi
unsigned int i; // ebx
__int64 v6; // rdi

v3 = 7;
gpio_init(argc, argv, envp);
do
{
v4 = v3++;
gpio_inout(v4, 1LL);
}
while ( v3 != 12 );
for ( i = 7; i != 12; ++i )
{
gpio_write(i, 1LL);
sleep(1u);
v6 = i;
gpio_write(v6, 0LL);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4; // rdi
unsigned int i; // ebx
__int64 v6; // rdi

v3 = 7;
func7(argc, argv, envp);
do
{
v4 = v3++;
func8(v4, 1LL);
}
while ( v3 != 12 );
for ( i = 7; i != 12; ++i )
{
func9(i, 1LL);
sleep(1u);
v6 = i;
func9(v6, 0LL);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int i;
    gpio_init();
    for(i = 7; i < 12; i++) {
        gpio_inout(i, E_GPIO_OUT);
    }
    for(i = 7; i < 12; i++) {
        gpio_write(i, 1);
        sleep(1);
        gpio_write(i, 0);
    }
    return 0;
}

variable_types:
argv
char *[]

variable_types: i int


decompiled_code:
void *gpio_init()
{
int v0; // eax
int v1; // ebx
char *v2; // rax
char *v3; // rdi
void *result; // rax

v0 = open("/dev/mem", 1052674);
if ( v0 < 0 )
{
puts("Cannot open /dev/mem ");
exit(-1);
}
v1 = v0;
v2 = (char *)malloc(0x1FFFuLL);
v3 = v2;
if ( !v2 )
{
puts("Cannot allocate");
exit(-1);
}
if ( ((unsigned __int16)v2 & 0xFFF) != 0 )
v3 = &v2[4096 - ((unsigned __int16)v2 & 0xFFF)];
result = mmap(v3, 0x1000uLL, 3, 17, v1, 538968064LL);
if ( (int)result < 0 )
{
puts("mmap error");
exit(-1);
}
gpio_addr = (__int64)result;
return result;
}

canonical_decompiled_code:
void *func7()
{
int v0; // eax
int v1; // ebx
char *v2; // rax
char *v3; // rdi
void *result; // rax

v0 = open("/dev/mem", 1052674);
if ( v0 < 0 )
{
puts("Cannot open /dev/mem ");
exit(-1);
}
v1 = v0;
v2 = (char *)malloc(0x1FFFuLL);
v3 = v2;
if ( !v2 )
{
puts("Cannot allocate");
exit(-1);
}
if ( ((unsigned __int16)v2 & 0xFFF) != 0 )
v3 = &v2[4096 - ((unsigned __int16)v2 & 0xFFF)];
result = mmap(v3, 0x1000uLL, 3, 17, v1, 538968064LL);
if ( (int)result < 0 )
{
puts("mmap error");
exit(-1);
}
gpio_addr = (__int64)result;
return result;
}

original_code:
void gpio_init(void)
{
    int mem_fd;
    char *gpio_map;
    char *gpio_mem;
    if((mem_fd = open("/dev/mem", 02 | 04010000)) < 0) {
        printf("Cannot open /dev/mem \n");
        exit(-1);
    }
    if((gpio_mem = malloc((4*1024) + ((4*1024) -1))) == ((void *)0)) {
        printf("Cannot allocate\n");
        exit(-1);
    }
    if((unsigned int)gpio_mem % (4*1024)) {
        gpio_mem += ((4*1024) - (unsigned int)gpio_mem % (4*1024));
    }
    gpio_map = (char *)mmap(
        (caddr_t)gpio_mem,
        (4*1024),
        0x1 | 0x2,
        0x01 | 0x10,
        mem_fd,
        (0x20200000));
    if((int)gpio_map < 0) {
        printf("mmap error\n");
        exit(-1);
    }
    gpio_addr = (volatile unsigned *)gpio_map;
}

canonical_original_code:
void gpio_init()
{
    int mem_fd;
    char *gpio_map;
    char *gpio_mem;
    if((mem_fd = open("/dev/mem", 02 | 04010000)) < 0) {
        printf("Cannot open /dev/mem \n");
        exit(-1);
    }
    if((gpio_mem = malloc((4*1024) + ((4*1024) -1))) == ((void *)0)) {
        printf("Cannot allocate\n");
        exit(-1);
    }
    if((unsigned int)gpio_mem % (4*1024)) {
        gpio_mem += ((4*1024) - (unsigned int)gpio_mem % (4*1024));
    }
    gpio_map = (char *)mmap(
        (char *)gpio_mem,
        (4*1024),
        0x1 | 0x2,
        0x01 | 0x10,
        mem_fd,
        (0x20200000));
    if((int)gpio_map < 0) {
        printf("mmap error\n");
        exit(-1);
    }
    gpio_addr = (unsigned int *)gpio_map;
}


decompiled_code:
int __fastcall gpio_inout(signed int a1, int a2)
{
int result; // eax
int *v3; // rdx
int v4; // edi
int *v5; // rsi

if ( (unsigned int)a1 <= 0x19 )
{
result = a1;
if ( valid_port[a1] )
{
if ( gpio_addr )
{
if ( a2 )
{
if ( a2 == 1 )
{
v3 = (int *)(gpio_addr + 4LL * (a1 / 10));
v4 = a1 % 10;
*v3 &= ~(7 << (3 * v4));
result = *v3 | (1 << (3 * v4));
*v3 = result;
}
}
else
{
v5 = (int *)(gpio_addr + 4LL * (a1 / 10));
result = *v5 & ~(7 << (3 * (a1 % 10)));
*v5 = result;
}
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(signed int a1, int a2)
{
int result; // eax
int *v3; // rdx
int v4; // edi
int *v5; // rsi

if ( (unsigned int)a1 <= 0x19 )
{
result = a1;
if ( valid_port[a1] )
{
if ( gpio_addr )
{
if ( a2 )
{
if ( a2 == 1 )
{
v3 = (int *)(gpio_addr + 4LL * (a1 / 10));
v4 = a1 % 10;
*v3 &= ~(7 << (3 * v4));
result = *v3 | (1 << (3 * v4));
*v3 = result;
}
}
else
{
v5 = (int *)(gpio_addr + 4LL * (a1 / 10));
result = *v5 & ~(7 << (3 * (a1 % 10)));
*v5 = result;
}
}
}
}
return result;
}

original_code:
void gpio_inout(int port_no, GPIO_INOUT inout)
{
    if(!(((port_no < 0 || 25 < port_no) ? 0 : (int)valid_port[port_no] ) && gpio_addr)) return;
    switch(inout) {
    case E_GPIO_IN:
        *(gpio_addr+((port_no)/10)) &= ~(7<<(((port_no)%10)*3));
        break;
    case E_GPIO_OUT:
        *(gpio_addr+((port_no)/10)) &= ~(7<<(((port_no)%10)*3));
        *(gpio_addr+((port_no)/10)) |= (1<<(((port_no)%10)*3));
        break;
    default:
        break;
    }
}

canonical_original_code:
void gpio_inout(int port_no, enum GPIO_INOUT inout)
{
    if(!(((port_no < 0 || 25 < port_no) ? 0 : (int)valid_port[port_no] ) && gpio_addr)) return;
    switch(inout) {
    case E_GPIO_IN:
        *(gpio_addr+((port_no)/10)) &= ~(7<<(((port_no)%10)*3));
        break;
    case E_GPIO_OUT:
        *(gpio_addr+((port_no)/10)) &= ~(7<<(((port_no)%10)*3));
        *(gpio_addr+((port_no)/10)) |= (1<<(((port_no)%10)*3));
        break;
    default:
        break;
    }
}

variable_types: enum GPIO_INOUT { E_GPIO_IN=0, E_GPIO_OUT=1 }


decompiled_code:
void __fastcall gpio_write(unsigned int a1, int a2)
{
int v2; // eax

if ( a1 <= 0x19 && valid_port[a1] && gpio_addr )
{
v2 = 1 << a1;
if ( a2 )
*(_DWORD *)(gpio_addr + 28) = v2;
else
*(_DWORD *)(gpio_addr + 40) = v2;
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1, int a2)
{
int v2; // eax

if ( a1 <= 0x19 && valid_port[a1] && gpio_addr )
{
v2 = 1 << a1;
if ( a2 )
*(_DWORD *)(gpio_addr + 28) = v2;
else
*(_DWORD *)(gpio_addr + 40) = v2;
}
}

original_code:
void gpio_write(int port_no, int data)
{
    if(!(((port_no < 0 || 25 < port_no) ? 0 : (int)valid_port[port_no] ) && gpio_addr)) return;
    if(data == 0) {
        *(gpio_addr + 10) = 1 << (port_no);
    } else {
        *(gpio_addr + 7) = 1 << (port_no);
    }
}

variable_types: data int


decompiled_code:
_BOOL8 __fastcall gpio_read(unsigned int a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 <= 0x19 && valid_port[a1] )
{
if ( gpio_addr )
result = (*(_DWORD *)(gpio_addr + 52) & (1 << a1)) != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(unsigned int a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 <= 0x19 && valid_port[a1] )
{
if ( gpio_addr )
result = (*(_DWORD *)(gpio_addr + 52) & (1 << a1)) != 0;
}
return result;
}

original_code:
int gpio_read(int port_no)
{
    if(!(((port_no < 0 || 25 < port_no) ? 0 : (int)valid_port[port_no] ) && gpio_addr)) return 0;
    return (*(gpio_addr + 13) & (1 << port_no) ? 1 : 0);
}


forodec

repo: flr/FLash

original_code:
int forodec(short tag,
            int n,
            double tau,
            int dol,
            int deg,
            double** Y)
{
    int rc= 3;
    int i, j, k;
    double taut;
    ;
    ;
    if ( n > currentTapeInfos.pTapeInfos.forodec_nax ||
            deg > currentTapeInfos.pTapeInfos.forodec_dax )
    {
        if (currentTapeInfos.pTapeInfos.forodec_nax) {
            myfree1(currentTapeInfos.pTapeInfos.forodec_y);
            myfree1(currentTapeInfos.pTapeInfos.forodec_z);
            myfree2(currentTapeInfos.pTapeInfos.forodec_Z);
        }
        currentTapeInfos.pTapeInfos.forodec_Z = myalloc2(n, deg);
        currentTapeInfos.pTapeInfos.forodec_z = myalloc1(n);
        currentTapeInfos.pTapeInfos.forodec_y = myalloc1(n);
        currentTapeInfos.pTapeInfos.forodec_nax = n;
        currentTapeInfos.pTapeInfos.forodec_dax = deg;
    }
    for (i = 0; i < n; ++i) {
        currentTapeInfos.pTapeInfos.forodec_y[i] = Y[i][0];
        for (k = 0; k < deg; ++k) {
            Y[i][k] = Y[i][k+1];
        }
    }
    if (dol == 0) {
        j = dol;
        k = (deg) * (j == deg-1 ) ;
        do { int __r = (zos_forward(tag, n, n, k, currentTapeInfos.pTapeInfos.forodec_y, currentTapeInfos.pTapeInfos.forodec_z)); if ( __r < (rc) ) (rc) = __r; } while (0);
        if(rc < 0) return rc;
        taut = tau / (1 + j);
        for (i = 0; i < n; ++i)
            Y[i][j] = taut * currentTapeInfos.pTapeInfos.forodec_z[i];
        dol++;
    }
    for (j = dol; j < deg; ++j) {
        k = (deg)*(j == deg-1) ;
        do { int __r = (hos_forward(tag, n, n, j, k, currentTapeInfos.pTapeInfos.forodec_y, Y, currentTapeInfos.pTapeInfos.forodec_z, currentTapeInfos.pTapeInfos.forodec_Z)); if ( __r < (rc) ) (rc) = __r; } while (0);
        if( rc < 0) return rc;
        taut = tau / (1 + j);
        for (i = 0; i < n; ++i)
            Y[i][j] = taut *
                currentTapeInfos.pTapeInfos.forodec_Z[i][j-1];
    }
    for (i = 0; i < n; ++i) {
        for (k = deg; k > 0; --k) {
            Y[i][k] = Y[i][k-1];
        }
        Y[i][0] = currentTapeInfos.pTapeInfos.forodec_y[i];
    }
    return rc;
}

canonical_original_code:
int forodec(short tag, int n, double tau, int dol, int deg, double **Y)
{
    int rc = 3;
    int i; int j; int k;
    double taut;
    ;
    ;
    if ( n > currentTapeInfos.pTapeInfos.forodec_nax ||
            deg > currentTapeInfos.pTapeInfos.forodec_dax )
    {
        if (currentTapeInfos.pTapeInfos.forodec_nax) {
            myfree1(currentTapeInfos.pTapeInfos.forodec_y);
            myfree1(currentTapeInfos.pTapeInfos.forodec_z);
            myfree2(currentTapeInfos.pTapeInfos.forodec_Z);
        }
        currentTapeInfos.pTapeInfos.forodec_Z = myalloc2(n, deg);
        currentTapeInfos.pTapeInfos.forodec_z = myalloc1(n);
        currentTapeInfos.pTapeInfos.forodec_y = myalloc1(n);
        currentTapeInfos.pTapeInfos.forodec_nax = n;
        currentTapeInfos.pTapeInfos.forodec_dax = deg;
    }
    for (i = 0; i < n; ++i) {
        currentTapeInfos.pTapeInfos.forodec_y[i] = Y[i][0];
        for (k = 0; k < deg; ++k) {
            Y[i][k] = Y[i][k+1];
        }
    }
    if (dol == 0) {
        j = dol;
        k = (deg) * (j == deg-1 ) ;
        do { int __r = (zos_forward(tag, n, n, k, currentTapeInfos.pTapeInfos.forodec_y, currentTapeInfos.pTapeInfos.forodec_z)); if ( __r < (rc) ) (rc) = __r; } while (0);
        if(rc < 0) return rc;
        taut = tau / (1 + j);
        for (i = 0; i < n; ++i)
            Y[i][j] = taut * currentTapeInfos.pTapeInfos.forodec_z[i];
        dol++;
    }
    for (j = dol; j < deg; ++j) {
        k = (deg)*(j == deg-1) ;
        do { int __r = (hos_forward(tag, n, n, j, k, currentTapeInfos.pTapeInfos.forodec_y, Y, currentTapeInfos.pTapeInfos.forodec_z, currentTapeInfos.pTapeInfos.forodec_Z)); if ( __r < (rc) ) (rc) = __r; } while (0);
        if( rc < 0) return rc;
        taut = tau / (1 + j);
        for (i = 0; i < n; ++i)
            Y[i][j] = taut *
                currentTapeInfos.pTapeInfos.forodec_Z[i][j-1];
    }
    for (i = 0; i < n; ++i) {
        for (k = deg; k > 0; --k) {
            Y[i][k] = Y[i][k-1];
        }
        Y[i][0] = currentTapeInfos.pTapeInfos.forodec_y[i];
    }
    return rc;
}

variable_types: tag short

variable_types: n int

variable_types: tau double

variable_types: dol int

variable_types: deg int

variable_types:
Y
double **

variable_types: rc int

variable_types: j int

variable_types: k int

variable_types: taut double


accodec

original_code:
void accodec(int n,
             double tau,
             int deg,
             double*** A,
             double*** B,
             short** nonzero )
{
    int i,j,k,m,p,nzip,nzpj,isum;
    double *Aip, *Bpj, scale, sum;
    for (k=0;k<=deg;k++)
    {
        scale = tau/(1.0+k);
        if(nonzero) {
            for (i=0;i<n;i++)
                for(j=0;j<n;j++)
                    if(k < -nonzero[i][j])
                        B[i][j][k] = 0.0;
                    else {
                        sum = A[i][j][k];
                        isum = (nonzero[i][j] > 0);
                        for (p=0;p<n;p++) {
                            nzip = nonzero[i][p];
                            nzpj = nonzero[p][j];
                            if(nzpj > 0) nzpj = 0;
                            if(nzip > 0 && k > -nzpj )
                            {
                                Aip = A[i][p];
                                Bpj = B[p][j]+k-1;
                                sum += *Aip*(*Bpj);
                                isum =1;
                                if(nzip > 1 )
                                    for(m=k-1; m>-nzpj;m--)
          sum += (*(++Aip))*(*(--Bpj));
                            }
                        }
                        if(isum)
                            B[i][j][k] = sum*scale;
                        else {
                            B[i][j][k]= 0;
                            nonzero[i][j]--;
                        }
                    }
        } else {
            for (i=0;i<n;i++)
                for(j=0;j<n;j++) {
                    sum = A[i][j][k];
                    for (p=0;p<n;p++) {
                        Aip = A[i][p];
                        Bpj = B[p][j]+k-1;
                        for(m=k; m>0 ;m--)
     sum += (*(Aip++))*(*Bpj--);
                        B[i][j][k] = sum*scale;
                    }
                }
        }
    }
}

canonical_original_code:
void accodec(int n, double tau, int deg, double ***A, double ***B, short **nonzero)
{
    int i; int j; int k; int m; int p; int nzip; int nzpj; int isum;
    double *Aip; double *Bpj; double scale; double sum;
    for (k=0;k<=deg;k++)
    {
        scale = tau/(1.0+k);
        if(nonzero) {
            for (i=0;i<n;i++)
                for(j=0;j<n;j++)
                    if(k < -nonzero[i][j])
                        B[i][j][k] = 0.0;
                    else {
                        sum = A[i][j][k];
                        isum = (nonzero[i][j] > 0);
                        for (p=0;p<n;p++) {
                            nzip = nonzero[i][p];
                            nzpj = nonzero[p][j];
                            if(nzpj > 0) nzpj = 0;
                            if(nzip > 0 && k > -nzpj )
                            {
                                Aip = A[i][p];
                                Bpj = B[p][j]+k-1;
                                sum += *Aip*(*Bpj);
                                isum =1;
                                if(nzip > 1 )
                                    for(m=k-1; m>-nzpj;m--)
          sum += (*(++Aip))*(*(--Bpj));
                            }
                        }
                        if(isum)
                            B[i][j][k] = sum*scale;
                        else {
                            B[i][j][k]= 0;
                            nonzero[i][j]--;
                        }
                    }
        } else {
            for (i=0;i<n;i++)
                for(j=0;j<n;j++) {
                    sum = A[i][j][k];
                    for (p=0;p<n;p++) {
                        Aip = A[i][p];
                        Bpj = B[p][j]+k-1;
                        for(m=k; m>0 ;m--)
     sum += (*(Aip++))*(*Bpj--);
                        B[i][j][k] = sum*scale;
                    }
                }
        }
    }
}

variable_types:
A
double ***

variable_types:
B
double ***

variable_types:
nonzero
short **

variable_types: m int

variable_types: p int

variable_types: nzip int

variable_types: nzpj int

variable_types: isum int

variable_types:
Aip
double *

variable_types:
Bpj
double *

variable_types: scale double

variable_types: sum double


original_code:
long forodec_(long* ftag,
              long* fn,
              double* ftau,
              long* fdol,
              long* fdeg,
              double* fy)
{
    int rc= -1;
    short tag= (short) *ftag;
    int n=*fn, dol=*fdol, deg=*fdeg;
    int i;
    double tau=*ftau;
    double** Y = myalloc2(n,deg+1);
    for(i=0;i<n;i++)
        *Y[i] = fy[i];
    rc= forodec(tag,n,tau,dol,deg,Y);
    pack2(n,deg+1,Y,fy);
    free((char*)*Y);
    free((char*)Y);
    return rc;
}

canonical_original_code:
long forodec_(long *ftag, long *fn, double *ftau, long *fdol, long *fdeg, double *fy)
{
    int rc = -1;
    short tag = (short) *ftag;
    int n = *fn; int dol = *fdol; int deg = *fdeg;
    int i;
    double tau = *ftau;
    double **Y = myalloc2(n,deg+1);
    for(i=0;i<n;i++)
        *Y[i] = fy[i];
    rc= forodec(tag,n,tau,dol,deg,Y);
    pack2(n,deg+1,Y,fy);
    free((char *)*Y);
    free((char *)Y);
    return rc;
}

variable_types:
ftag
long *

variable_types:
fn
long *

variable_types:
ftau
double *

variable_types:
fdol
long *

variable_types:
fdeg
long *

variable_types:
fy
double *

variable_types: tag short

variable_types: n int

variable_types: dol int

variable_types: deg int

variable_types: i int

variable_types: tau double

variable_types:
Y
double **

return_type: long


decompiled_code:
__int64 __fastcall accodec_(__int64 *a1, double *a2, __int64 *a3, __int64 a4, __int64 a5)
{
__int64 v7; // rbx
__int64 v8; // r13
__int64 v9; // rbp
void ***v10; // r12
void ***v11; // rbp
double v13; // [rsp+8h] [rbp-40h]

v7 = *a1;
v8 = *a3;
v9 = (int)*a1;
v13 = *a2;
v10 = (void ***)myalloc3(v9, v9);
v11 = (void ***)myalloc3(v9, v9);
spread3((unsigned int)v7, (unsigned int)v7, (unsigned int)v8, a4, v10);
accodec((unsigned int)v7, (unsigned int)v8, v10, v11, 0LL, v13);
pack3((unsigned int)v7, (unsigned int)v7, (unsigned int)v8, v11, a5);
free(**v10);
free(*v10);
free(v10);
free(**v11);
free(*v11);
free(v11);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, double *a2, __int64 *a3, __int64 a4, __int64 a5)
{
__int64 v7; // rbx
__int64 v8; // r13
__int64 v9; // rbp
void ***v10; // r12
void ***v11; // rbp
double v13; // [rsp+8h] [rbp-40h]

v7 = *a1;
v8 = *a3;
v9 = (int)*a1;
v13 = *a2;
v10 = (void ***)myalloc3(v9, v9);
v11 = (void ***)myalloc3(v9, v9);
spread3((unsigned int)v7, (unsigned int)v7, (unsigned int)v8, a4, v10);
accodec((unsigned int)v7, (unsigned int)v8, v10, v11, 0LL, v13);
pack3((unsigned int)v7, (unsigned int)v7, (unsigned int)v8, v11, a5);
free(**v10);
free(*v10);
free(v10);
free(**v11);
free(*v11);
free(v11);
return 1LL;
}

original_code:
long accodec_(long* fn,
              double* ftau,
              long* fdeg,
              double* fa,
              double* fb)
{
    int rc= 1;
    int n=*fn, deg=*fdeg;
    double tau=*ftau;
    double*** A = myalloc3(n,n,deg);
    double*** B = myalloc3(n,n,deg);
    spread3(n,n,deg,fa,A);
    accodec(n,tau,deg,A,B,0);
    pack3(n,n,deg,B,fb);
    free((char*)**A);
    free((char*)*A);
    free((char*)A);
    free((char*)**B);
    free((char*)*B);
    free((char*)B);
    return rc;
}

canonical_original_code:
long accodec_(long *fn, double *ftau, long *fdeg, double *fa, double *fb)
{
    int rc = 1;
    int n = *fn; int deg = *fdeg;
    double tau = *ftau;
    double ***A = myalloc3(n,n,deg);
    double ***B = myalloc3(n,n,deg);
    spread3(n,n,deg,fa,A);
    accodec(n,tau,deg,A,B,0);
    pack3(n,n,deg,B,fb);
    free((char *)**A);
    free((char *)*A);
    free((char *)A);
    free((char *)**B);
    free((char *)*B);
    free((char *)B);
    return rc;
}

variable_types:
fa
double *

variable_types:
fb
double *

variable_types: rc int

variable_types:
A
double ***

variable_types:
B
double ***


decompiled_code:
int bs_dump()
{
__int64 v0; // r12
unsigned int *i; // rbx
const char *v2; // rcx

putchar(10);
if ( orderCount )
{
v0 = 0LL;
do
{
printf("order %d: ", (unsigned int)v0);
for ( i = (unsigned int *)*((_QWORD *)nodeListArray + v0); i; i = (unsigned int *)*((_QWORD *)i + 2) )
{
v2 = (const char *)&unk_402035;
if ( *((_BYTE *)i + 8) )
v2 = "free";
printf("[ %d - %d (%s) ] ", *i, *i + i[1], v2);
}
++v0;
putchar(10);
}
while ( orderCount > (unsigned int)v0 );
}
return putchar(10);
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // r12
unsigned int *i; // rbx
const char *v2; // rcx

putchar(10);
if ( orderCount )
{
v0 = 0LL;
do
{
printf("order %d: ", (unsigned int)v0);
for ( i = (unsigned int *)*((_QWORD *)nodeListArray + v0); i; i = (unsigned int *)*((_QWORD *)i + 2) )
{
v2 = (const char *)&unk_402035;
if ( *((_BYTE *)i + 8) )
v2 = "free";
printf("[ %d - %d (%s) ] ", *i, *i + i[1], v2);
}
++v0;
putchar(10);
}
while ( orderCount > (unsigned int)v0 );
}
return putchar(10);
}

original_code:
void bs_dump(void) {
    printf("\n");
    int i=0;
    Node* nodePtr = ((void *)0);
    for( i=0; i<orderCount; i++) {
        printf("order %d: ", i);
        nodePtr = nodeListArray[i];
        while(nodePtr) {
            printf("[ %d - %d (%s) ] ", nodePtr->startPos, nodePtr->startPos + nodePtr->size, nodePtr->free?"free":"not free");
            nodePtr = nodePtr->next;
        }
        printf("\n");
    }
    printf("\n");
}

canonical_original_code:
void bs_dump() {
    printf("\n");
    int i = 0;
    struct Node *nodePtr = ((void *)0);
    for( i=0; i<orderCount; i++) {
        printf("order %d: ", i);
        nodePtr = nodeListArray[i];
        while(nodePtr) {
            printf("[ %d - %d (%s) ] ", nodePtr->startPos, nodePtr->startPos + nodePtr->size, nodePtr->free?"free":"not free");
            nodePtr = nodePtr->next;
        }
        printf("\n");
    }
    printf("\n");
}

variable_types: struct Node { unsigned int startPos; unsigned int size; char free; struct Node *next; struct Node *prev; struct Node *childLeft; struct Node *childRight; struct Node *parent; } *


memoryInit

decompiled_code:
_BYTE *memoryInit()
{
_QWORD *v0; // rbx
_BYTE *result; // rax

pthread_mutex_init(&lock, 0LL);
orderCount = 8;
v0 = calloc(0x40uLL, 1uLL);
nodeListArray = v0;
result = malloc(0x38uLL);
v0[7] = result;
*(_QWORD *)result = 0x100000000000LL;
result[8] = 1;
*((_QWORD *)result + 2) = 0LL;
*((_QWORD *)result + 3) = 0LL;
*((_QWORD *)result + 4) = 0LL;
*((_QWORD *)result + 5) = 0LL;
*((_QWORD *)result + 6) = 0LL;
return result;
}

canonical_decompiled_code:
_BYTE *func8()
{
_QWORD *v0; // rbx
_BYTE *result; // rax

pthread_mutex_init(&lock, 0LL);
orderCount = 8;
v0 = calloc(0x40uLL, 1uLL);
nodeListArray = v0;
result = malloc(0x38uLL);
v0[7] = result;
*(_QWORD *)result = 0x100000000000LL;
result[8] = 1;
*((_QWORD *)result + 2) = 0LL;
*((_QWORD *)result + 3) = 0LL;
*((_QWORD *)result + 4) = 0LL;
*((_QWORD *)result + 5) = 0LL;
*((_QWORD *)result + 6) = 0LL;
return result;
}

original_code:
void memoryInit(void) {
    pthread_mutex_init(&lock, ((void *)0));
    orderCount = 1;
    unsigned int logReference = 32;
    while(logReference < 4096) {
        logReference *= 2;
        orderCount++;
    }
    if(logReference > 4096) {
        printf("MEM_SIZE and BUDDY_MIN_SIZE have to be powers of 2!\n");
        exit(1);
    }
    nodeListArray = (Node**)malloc(orderCount * sizeof(Node*));
    unsigned int i=0;
    for(i=0; i<orderCount; i++) {
        nodeListArray[i] = ((void *)0);
    }
    Node* rootNode = (Node*)malloc(sizeof(Node));
    nodeListArray[orderCount - 1] = rootNode;
    rootNode->startPos = 0;
    rootNode->size = 4096;
    rootNode->free = 1;
    rootNode->next = ((void *)0);
    rootNode->prev = ((void *)0);
    rootNode->childLeft = ((void *)0);
    rootNode->childRight = ((void *)0);
    rootNode->parent = ((void *)0);
}

canonical_original_code:
void memoryInit() {
    pthread_mutex_init(&lock, ((void *)0));
    orderCount = 1;
    unsigned int logReference = 32;
    while(logReference < 4096) {
        logReference *= 2;
        orderCount++;
    }
    if(logReference > 4096) {
        printf("MEM_SIZE and BUDDY_MIN_SIZE have to be powers of 2!\n");
        exit(1);
    }
    nodeListArray = (struct Node **)malloc(orderCount * sizeof(struct Node *));
    unsigned int i = 0;
    for(i=0; i<orderCount; i++) {
        nodeListArray[i] = ((void *)0);
    }
    struct Node *rootNode = (Node*)malloc(sizeof(Node));
    nodeListArray[orderCount - 1] = rootNode;
    rootNode->startPos = 0;
    rootNode->size = 4096;
    rootNode->free = 1;
    rootNode->next = ((void *)0);
    rootNode->prev = ((void *)0);
    rootNode->childLeft = ((void *)0);
    rootNode->childRight = ((void *)0);
    rootNode->parent = ((void *)0);
}

variable_types:
logReference
unsigned int

variable_types:
i
unsigned int

user_defined_types: struct Node { unsigned int startPos; unsigned int size; char free; struct Node *next; struct Node *prev; struct Node *childLeft; struct Node *childRight; struct Node *parent; }


memoryCleanup

decompiled_code:
int memoryCleanup()
{
char *v0; // rdi
int v1; // ebp
__int64 v2; // r12
_QWORD *v3; // rbx
void *v4; // rdi

v0 = (char *)nodeListArray;
v1 = orderCount - 1;
if ( orderCount - 1 >= 0 )
{
v2 = 8LL * v1;
do
{
v3 = *(_QWORD **)&v0[v2];
if ( v3 )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
while ( v3 );
v0 = (char *)nodeListArray;
}
--v1;
v2 -= 8LL;
}
while ( v1 != -1 );
}
free(v0);
return pthread_mutex_destroy(&lock);
}

canonical_decompiled_code:
int func9()
{
char *v0; // rdi
int v1; // ebp
__int64 v2; // r12
_QWORD *v3; // rbx
void *v4; // rdi

v0 = (char *)nodeListArray;
v1 = orderCount - 1;
if ( orderCount - 1 >= 0 )
{
v2 = 8LL * v1;
do
{
v3 = *(_QWORD **)&v0[v2];
if ( v3 )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
while ( v3 );
v0 = (char *)nodeListArray;
}
--v1;
v2 -= 8LL;
}
while ( v1 != -1 );
}
free(v0);
return pthread_mutex_destroy(&lock);
}

original_code:
void memoryCleanup(void) {
    int i=0;
    Node* nodePtr = ((void *)0);
    for( i=(orderCount-1); i>=0; i--) {
        nodePtr = nodeListArray[i];
        while(nodePtr) {
            Node* toBeDeleted = nodePtr;
            nodePtr = nodePtr->next;
            free(toBeDeleted);
        }
    }
    free(nodeListArray);
    pthread_mutex_destroy(&lock);
}

canonical_original_code:
void memoryCleanup() {
    int i = 0;
    struct Node *nodePtr = ((void *)0);
    for( i=(orderCount-1); i>=0; i--) {
        nodePtr = nodeListArray[i];
        while(nodePtr) {
            struct Node *toBeDeleted = nodePtr;
            nodePtr = nodePtr->next;
            free(toBeDeleted);
        }
    }
    free(nodeListArray);
    pthread_mutex_destroy(&lock);
}


collapseNode

original_code:
void collapseNode(Node* nodePtr) {
    if(!nodePtr) { return; }
    if(!nodePtr->childLeft || !nodePtr->childRight) { return; }
    if(!nodePtr->childLeft->free || !nodePtr->childRight->free) { return; }
    int order = 0;
    int logReference = 32;
    while(logReference < nodePtr->childLeft->size) {
        logReference *= 2;
        order++;
    }
    if(nodePtr->childRight->next) {
        nodePtr->childRight->next->prev = nodePtr->childLeft->prev;
    }
    if(nodePtr->childLeft->prev) {
        nodePtr->childLeft->prev->next = nodePtr->childRight->next;
    }
    if(nodeListArray[order] == nodePtr->childLeft) {
        nodeListArray[order] = nodePtr->childRight->next;
    }
    free(nodePtr->childLeft);
    free(nodePtr->childRight);
    nodePtr->childLeft = ((void *)0);
    nodePtr->childRight = ((void *)0);
    nodePtr->free = 1;
    collapseNode(nodePtr->parent);
}

canonical_original_code:
void collapseNode(struct Node *nodePtr) {
    if(!nodePtr) { return; }
    if(!nodePtr->childLeft || !nodePtr->childRight) { return; }
    if(!nodePtr->childLeft->free || !nodePtr->childRight->free) { return; }
    int order = 0;
    int logReference = 32;
    while(logReference < nodePtr->childLeft->size) {
        logReference *= 2;
        order++;
    }
    if(nodePtr->childRight->next) {
        nodePtr->childRight->next->prev = nodePtr->childLeft->prev;
    }
    if(nodePtr->childLeft->prev) {
        nodePtr->childLeft->prev->next = nodePtr->childRight->next;
    }
    if(nodeListArray[order] == nodePtr->childLeft) {
        nodeListArray[order] = nodePtr->childRight->next;
    }
    free(nodePtr->childLeft);
    free(nodePtr->childRight);
    nodePtr->childLeft = ((void *)0);
    nodePtr->childRight = ((void *)0);
    nodePtr->free = 1;
    collapseNode(nodePtr->parent);
}

variable_types: order int

variable_types: logReference int


decompiled_code:
void __fastcall bs_unsafe_free(_BYTE *a1)
{
__int64 v1; // rdx
unsigned int *v2; // rax
unsigned int *v3; // rcx
__int64 v4; // rdi

bs_dump();
printf("request to free pointer %p\n", a1);
v1 = a1 - (_BYTE *)&mem;
if ( (unsigned __int64)(a1 - (_BYTE *)&mem) > 0x1000 )
{
printf("that pointer (%p) is not inside my data block.\n", a1);
}
else
{
v2 = (unsigned int *)*((_QWORD *)nodeListArray + (unsigned int)(orderCount - 1));
while ( v2 )
{
v3 = (unsigned int *)*((_QWORD *)v2 + 4);
if ( *v2 == v1 )
{
if ( !v3 )
{
v4 = *((_QWORD *)v2 + 6);
*((_BYTE *)v2 + 8) = 1;
if ( v4 )
collapseNode(v4);
return;
}
}
else if ( !v3 )
{
return;
}
v2 = (unsigned int *)*((_QWORD *)v2 + 5);
if ( *v2 > v1 )
v2 = v3;
}
}
}

canonical_decompiled_code:
void __fastcall func11(_BYTE *a1)
{
__int64 v1; // rdx
unsigned int *v2; // rax
unsigned int *v3; // rcx
__int64 v4; // rdi

func7();
printf("request to free pointer %p\n", a1);
v1 = a1 - (_BYTE *)&mem;
if ( (unsigned __int64)(a1 - (_BYTE *)&mem) > 0x1000 )
{
printf("that pointer (%p) is not inside my data block.\n", a1);
}
else
{
v2 = (unsigned int *)*((_QWORD *)nodeListArray + (unsigned int)(orderCount - 1));
while ( v2 )
{
v3 = (unsigned int *)*((_QWORD *)v2 + 4);
if ( *v2 == v1 )
{
if ( !v3 )
{
v4 = *((_QWORD *)v2 + 6);
*((_BYTE *)v2 + 8) = 1;
if ( v4 )
func10(v4);
return;
}
}
else if ( !v3 )
{
return;
}
v2 = (unsigned int *)*((_QWORD *)v2 + 5);
if ( *v2 > v1 )
v2 = v3;
}
}
}

original_code:
void bs_unsafe_free(void *ptr) {
    bs_dump();
    printf("request to free pointer %p\n", ptr);
    long offset = (long)ptr - (long)mem;
    if(offset < 0 || offset > 4096) {
        printf("that pointer (%p) is not inside my data block.\n", ptr);
        return;
    }
    Node* nodePtr = nodeListArray[orderCount - 1];
    while(nodePtr) {
        if(nodePtr->startPos == offset && !nodePtr->childLeft) {
            nodePtr->free = 1;
            if(nodePtr->parent) {
                collapseNode(nodePtr->parent);
            }
            return;
        }
        if(!nodePtr->childLeft && nodePtr->startPos != offset) {
            return;
        }
        if(nodePtr->childRight->startPos > offset) {
            nodePtr = nodePtr->childLeft;
        }else{
            nodePtr = nodePtr->childRight;
        }
    }
}

canonical_original_code:
void bs_unsafe_free(void *ptr) {
    bs_dump();
    printf("request to free pointer %p\n", ptr);
    long offset = (long)ptr - (long)mem;
    if(offset < 0 || offset > 4096) {
        printf("that pointer (%p) is not inside my data block.\n", ptr);
        return;
    }
    struct Node *nodePtr = nodeListArray[orderCount - 1];
    while(nodePtr) {
        if(nodePtr->startPos == offset && !nodePtr->childLeft) {
            nodePtr->free = 1;
            if(nodePtr->parent) {
                collapseNode(nodePtr->parent);
            }
            return;
        }
        if(!nodePtr->childLeft && nodePtr->startPos != offset) {
            return;
        }
        if(nodePtr->childRight->startPos > offset) {
            nodePtr = nodePtr->childLeft;
        }else{
            nodePtr = nodePtr->childRight;
        }
    }
}

variable_types:
ptr
void *

variable_types: offset long


decompiled_code:
int __fastcall bs_free(_BYTE *a1)
{
pthread_mutex_lock(&lock);
bs_unsafe_free(a1);
return pthread_mutex_unlock(&lock);
}

canonical_decompiled_code:
int __fastcall func12(_BYTE *a1)
{
pthread_mutex_lock(&lock);
func11(a1);
return pthread_mutex_unlock(&lock);
}

original_code:
void bs_free(void* pointer) {
    pthread_mutex_lock(&lock);
    bs_unsafe_free(pointer);
    pthread_mutex_unlock(&lock);
}

canonical_original_code:
void bs_free(void *pointer) {
    pthread_mutex_lock(&lock);
    bs_unsafe_free(pointer);
    pthread_mutex_unlock(&lock);
}

variable_types:
pointer
void *


threadRoutine

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

printf("new thread starting at offset %d, calculating %d values.\n", *(unsigned int *)a1, *((unsigned int *)a1 + 1));
if ( *((int *)a1 + 1) > 0 )
{
v1 = 0;
do
{
++v1;
getColorValuesAt();
}
while ( *((_DWORD *)a1 + 1) > v1 );
}
free(a1);
}

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

printf("new thread starting at offset %d, calculating %d values.\n", *(unsigned int *)a1, *((unsigned int *)a1 + 1));
if ( *((int *)a1 + 1) > 0 )
{
v1 = 0;
do
{
++v1;
getColorValuesAt();
}
while ( *((_DWORD *)a1 + 1) > v1 );
}
free(a1);
}

original_code:
void *threadRoutine (void *dataPointer) {
    struct ThreadData *td = (struct ThreadData *) dataPointer;
    int i, x, y;
    char* c;
    printf("new thread starting at offset %d, calculating %d values.\n", td->startPos, td->pixelCount);
    for (i = 0; i < td->pixelCount; ++i) {
        x = (td->startPos + i) % 500;
        y = (td->startPos + i) / 500;
        c = colorArray[y][x];
        getColorValuesAt(x * (2.0 / 500) - 1.5, y * (2.0 / 500) - 1.0,&c[2],&c[1],&c[0]);
    }
    free(td);
    td = ((void *)0);
}

canonical_original_code:
void *threadRoutine(void *dataPointer) {
    struct ThreadData *td = (struct ThreadData *) dataPointer;
    int i; int x; int y;
    char *c;
    printf("new thread starting at offset %d, calculating %d values.\n", td->startPos, td->pixelCount);
    for (i = 0; i < td->pixelCount; ++i) {
        x = (td->startPos + i) % 500;
        y = (td->startPos + i) / 500;
        c = colorArray[y][x];
        getColorValuesAt(x * (2.0 / 500) - 1.5, y * (2.0 / 500) - 1.0,&c[2],&c[1],&c[0]);
    }
    free(td);
    td = ((void *)0);
}

variable_types:
dataPointer
void *

variable_types: struct ThreadData { int startPos; int pixelCount; } *

variable_types: x int

variable_types: y int

variable_types:
c
char *


writeToString

repo: flyingOwl/mensaplan-C

decompiled_code:
size_t __fastcall writeToString(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v4; // r12
__int64 v6; // rbp
char *v7; // rax
size_t result; // rax

v4 = a3 * a2;
v6 = a3 * a2 + *(_QWORD *)(a4 + 8);
v7 = (char *)realloc(*(void **)a4, v6 + 1);
*(_QWORD *)a4 = v7;
memcpy(&v7[*(_QWORD *)(a4 + 8)], src, v4);
*(_BYTE *)(*(_QWORD *)a4 + v6) = 0;
result = v4;
*(_QWORD *)(a4 + 8) = v6;
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v4; // r12
__int64 v6; // rbp
char *v7; // rax
size_t result; // rax

v4 = a3 * a2;
v6 = a3 * a2 + *(_QWORD *)(a4 + 8);
v7 = (char *)realloc(*(void **)a4, v6 + 1);
*(_QWORD *)a4 = v7;
memcpy(&v7[*(_QWORD *)(a4 + 8)], src, v4);
*(_BYTE *)(*(_QWORD *)a4 + v6) = 0;
result = v4;
*(_QWORD *)(a4 + 8) = v6;
return result;
}

original_code:
size_t writeToString(void * ptr, size_t size, size_t nmemb, struct string * s) {
    size_t _newLength = s->length + (size * nmemb);
    s->str = realloc(s->str, _newLength + 1);
    memcpy(s->str + s->length, ptr, size * nmemb);
    s->str[_newLength] = '\0';
    s->length = _newLength;
    return size * nmemb;
}

canonical_original_code:
unsigned long writeToString(void *ptr, unsigned long size, unsigned long nmemb, struct string *s) {
    unsigned long _newLength = s->length + (size * nmemb);
    s->str = realloc(s->str, _newLength + 1);
    memcpy(s->str + s->length, ptr, size * nmemb);
    s->str[_newLength] = '\0';
    s->length = _newLength;
    return size * nmemb;
}

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types: struct string { char *str; unsigned long length; } *

return_type: unsigned long


getValueNextDay

decompiled_code:
char *__fastcall getValueNextDay(int a1)
{
struct tm *v1; // rax
char *v2; // r12
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
*(__m128i *)&tp.tm_sec = _mm_loadu_si128((const __m128i *)v1);
*(__m128i *)&tp.tm_mon = _mm_loadu_si128((const __m128i *)&v1->tm_mon);
*(__m128i *)&tp.tm_isdst = _mm_loadu_si128((const __m128i *)&v1->tm_isdst);
tp.tm_zone = v1->tm_zone;
if ( a1 == 0xFFFF )
{
do
{
do
{
++tp.tm_mday;
mktime(&tp);
}
while ( !tp.tm_wday );
}
while ( tp.tm_wday == 6 );
}
else
{
tp.tm_mday += a1;
mktime(&tp);
}
v2 = (char *)calloc(0xCuLL, 1uLL);
snprintf(
v2,
0xCuLL,
"%d-%d-%d",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday);
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(int a1)
{
struct tm *v1; // rax
char *v2; // r12
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
*(__m128i *)&tp.tm_sec = _mm_loadu_si128((const __m128i *)v1);
*(__m128i *)&tp.tm_mon = _mm_loadu_si128((const __m128i *)&v1->tm_mon);
*(__m128i *)&tp.tm_isdst = _mm_loadu_si128((const __m128i *)&v1->tm_isdst);
tp.tm_zone = v1->tm_zone;
if ( a1 == 0xFFFF )
{
do
{
do
{
++tp.tm_mday;
mktime(&tp);
}
while ( !tp.tm_wday );
}
while ( tp.tm_wday == 6 );
}
else
{
tp.tm_mday += a1;
mktime(&tp);
}
v2 = (char *)calloc(0xCuLL, 1uLL);
snprintf(
v2,
0xCuLL,
"%d-%d-%d",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday);
return v2;
}

original_code:
char * getValueNextDay (int daysInFuture) {
    time_t _time = time(((void *)0));
    struct tm _timeStruct = *localtime(&_time);
    if (daysInFuture == 0xffff) {
        do {
            _timeStruct.tm_mday += 1;
            mktime(&_timeStruct);
        } while (_timeStruct.tm_wday == 0 || _timeStruct.tm_wday == 6);
    } else {
        _timeStruct.tm_mday += daysInFuture;
        mktime(&_timeStruct);
    }
    size_t _maxLen = 12;
    char * _splDay = calloc(_maxLen, sizeof(char));
    snprintf(_splDay, _maxLen, "%d-%d-%d", _timeStruct.tm_year + 1900, _timeStruct.tm_mon + 1, _timeStruct.tm_mday);
    return _splDay;
}

canonical_original_code:
char *getValueNextDay(int daysInFuture) {
    long _time = time(((void *)0));
    struct tm _timeStruct = *localtime(&_time);
    if (daysInFuture == 0xffff) {
        do {
            _timeStruct.tm_mday += 1;
            mktime(&_timeStruct);
        } while (_timeStruct.tm_wday == 0 || _timeStruct.tm_wday == 6);
    } else {
        _timeStruct.tm_mday += daysInFuture;
        mktime(&_timeStruct);
    }
    unsigned long _maxLen = 12;
    char *_splDay = calloc(_maxLen, sizeof(char));
    snprintf(_splDay, _maxLen, "%d-%d-%d", _timeStruct.tm_year + 1900, _timeStruct.tm_mon + 1, _timeStruct.tm_mday);
    return _splDay;
}

variable_types: daysInFuture int

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


readUserNumber

decompiled_code:
__int64 __fastcall readUserNumber(int a1, int a2)
{
__int64 result; // rax
int i; // eax
char s[4]; // [rsp+4h] [rbp-24h] BYREF
char *endptr; // [rsp+8h] [rbp-20h] BYREF

while ( 1 )
{
while ( !fgets(s, 4, stdin) )
;
result = strtol(s, &endptr, 10);
if ( s[0] != 10 && (*endptr == 10 || !*endptr) && a1 <= (int)result && a2 >= (int)result )
break;
printf("Try again: ");
if ( !strchr(s, 10) )
{
for ( i = getchar(); i != -1; i = getchar() )
{
if ( i == 10 )
break;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__int64 result; // rax
int i; // eax
char s[4]; // [rsp+4h] [rbp-24h] BYREF
char *endptr; // [rsp+8h] [rbp-20h] BYREF

while ( 1 )
{
while ( !fgets(s, 4, stdin) )
;
result = strtol(s, &endptr, 10);
if ( s[0] != 10 && (*endptr == 10 || !*endptr) && a1 <= (int)result && a2 >= (int)result )
break;
printf("Try again: ");
if ( !strchr(s, 10) )
{
for ( i = getchar(); i != -1; i = getchar() )
{
if ( i == 10 )
break;
}
}
}
return result;
}

original_code:
int readUserNumber(int min, int max){
    char buf[4], *p;
    int i = 0;
    while(!i){
        if (fgets(buf, sizeof(buf), stdin) != ((void *)0)) {
            i = strtol(buf, &p, 10);
            if (buf[0] != '\n' && (*p == '\n' || *p == '\0') && i >= min && i <= max){
                return i;
            } else {
                printf("Try again: ");
  if(strchr(buf, '\n') == ((void *)0)){
   while ((i = getchar()) != '\n' && i != (-1));
  }
                i = 0;
            }
        }
    }
    return 1;
}

canonical_original_code:
int readUserNumber(int min, int max){
    char buf[4]; char *p;
    int i = 0;
    while(!i){
        if (fgets(buf, sizeof(buf), stdin) != ((void *)0)) {
            i = strtol(buf, &p, 10);
            if (buf[0] != '\n' && (*p == '\n' || *p == '\0') && i >= min && i <= max){
                return i;
            } else {
                printf("Try again: ");
  if(strchr(buf, '\n') == ((void *)0)){
   while ((i = getchar()) != '\n' && i != (-1));
  }
                i = 0;
            }
        }
    }
    return 1;
}

variable_types: min int

variable_types: max int

variable_types:
buf
char [4]

variable_types:
p
char *

variable_types: i int


getConfigPath

decompiled_code:
char *getConfigPath()
{
__uid_t v0; // eax
char *v1; // rbp
size_t v2; // rbx
void *v3; // rax
char *result; // rax
__m128i v5; // xmm0
__m128i *v6; // rbx

v0 = getuid();
v1 = getpwuid(v0)->pw_dir;
v2 = strlen(v1);
v3 = malloc(v2 + 20);
result = (char *)memcpy(v3, v1, v2);
v5 = _mm_load_si128((const __m128i *)&LC6);
v6 = (__m128i *)&result[v2];
v6[1].m128i_i32[0] = 6712943;
*v6 = v5;
return result;
}

canonical_decompiled_code:
char *func1()
{
__uid_t v0; // eax
char *v1; // rbp
size_t v2; // rbx
void *v3; // rax
char *result; // rax
__m128i v5; // xmm0
__m128i *v6; // rbx

v0 = getuid();
v1 = getpwuid(v0)->pw_dir;
v2 = strlen(v1);
v3 = malloc(v2 + 20);
result = (char *)memcpy(v3, v1, v2);
v5 = _mm_load_si128((const __m128i *)&LC6);
v6 = (__m128i *)&result[v2];
v6[1].m128i_i32[0] = 6712943;
*v6 = v5;
return result;
}

original_code:
char * getConfigPath(){
    struct passwd *pw = getpwuid(getuid());
    char * path = malloc(strlen(pw->pw_dir) + strlen("/.config/mensa.conf\0") + 1);
    strcpy(path, pw->pw_dir);
    strcat(path, "/.config/mensa.conf\0");
    return path;
}

canonical_original_code:
char *getConfigPath(){
    struct passwd *pw = getpwuid(getuid());
    char *path = malloc(strlen(pw->pw_dir) + strlen("/.config/mensa.conf\0") + 1);
    strcpy(path, pw->pw_dir);
    strcat(path, "/.config/mensa.conf\0");
    return path;
}

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

variable_types:
path
char *


printHelp

decompiled_code:
int __fastcall printHelp(const char *a1)
{
puts("Mensaplan application in C\n");
puts("Usage:");
printf("%s [--init] [-n|--next-day] [--not-colored] [-S -M -F] [-h|--help]\n", a1);
puts("\t[--init] Select your Mensa from a list to set your config file");
puts("\t[-n|--next-day] Show the meal-plan of the next day");
puts("\t[--not-colored] Don't use colored descriptions");
puts("\t[-S -M -F] Show only the prices for student (-S), workers (-M) or stranger (-F)");
puts("\t[-h|--help] Show this help");
puts("\t[-v|--version] Show the version of this tool");
return puts(&byte_A6);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
puts("Mensaplan application in C\n");
puts("Usage:");
printf("%s [--init] [-n|--next-day] [--not-colored] [-S -M -F] [-h|--help]\n", a1);
puts("\t[--init] Select your Mensa from a list to set your config file");
puts("\t[-n|--next-day] Show the meal-plan of the next day");
puts("\t[--not-colored] Don't use colored descriptions");
puts("\t[-S -M -F] Show only the prices for student (-S), workers (-M) or stranger (-F)");
puts("\t[-h|--help] Show this help");
puts("\t[-v|--version] Show the version of this tool");
return puts(&byte_A6);
}

original_code:
void printHelp(char * exec){
    puts("Mensaplan application in C\n");
    puts("Usage:");
    printf("%s [--init] [-n|--next-day] [--not-colored] [-S -M -F] [-h|--help]\n", exec);
    puts("\t[--init]          Select your Mensa from a list to set your config file");
    puts("\t[-n|--next-day]   Show the meal-plan of the next day");
    puts("\t[--not-colored]   Don't use colored descriptions");
    puts("\t[-S -M -F]        Show only the prices for student (-S), workers (-M) or stranger (-F)");
    puts("\t[-h|--help]       Show this help");
    puts("\t[-v|--version]    Show the version of this tool");
    puts("");
}

canonical_original_code:
void printHelp(char *exec){
    puts("Mensaplan application in C\n");
    puts("Usage:");
    printf("%s [--init] [-n|--next-day] [--not-colored] [-S -M -F] [-h|--help]\n", exec);
    puts("\t[--init]          Select your Mensa from a list to set your config file");
    puts("\t[-n|--next-day]   Show the meal-plan of the next day");
    puts("\t[--not-colored]   Don't use colored descriptions");
    puts("\t[-S -M -F]        Show only the prices for student (-S), workers (-M) or stranger (-F)");
    puts("\t[-h|--help]       Show this help");
    puts("\t[-v|--version]    Show the version of this tool");
    puts("");
}

variable_types:
exec
char *


printVersion

decompiled_code:
int printVersion()
{
return printf("Version: %s\n", "e48dc88");
}

canonical_decompiled_code:
int func1()
{
return printf("Version: %s\n", "e48dc88");
}

original_code:
void printVersion() {
    printf("Version: %s\n", "e48dc88");
}


getMealColor

decompiled_code:
__int64 __fastcall getMealColor(const char *a1)
{
unsigned int v1; // er8

v1 = 1;
if ( strcmp(a1, "gruen") )
{
v1 = 2;
if ( strcmp(a1, "gelb") )
v1 = strcmp(a1, "rot") == 0 ? 3 : 0;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
unsigned int v1; // er8

v1 = 1;
if ( strcmp(a1, "gruen") )
{
v1 = 2;
if ( strcmp(a1, "gelb") )
v1 = strcmp(a1, "rot") == 0 ? 3 : 0;
}
return v1;
}

original_code:
int getMealColor(char * mColor){
    if(!strcmp(mColor, "gruen")){
        return 1;
    }
    if(!strcmp(mColor, "gelb")){
        return 2;
    }
    if(!strcmp(mColor, "rot")){
        return 3;
    }
    return 0;
}

canonical_original_code:
int getMealColor(char *mColor){
    if(!strcmp(mColor, "gruen")){
        return 1;
    }
    if(!strcmp(mColor, "gelb")){
        return 2;
    }
    if(!strcmp(mColor, "rot")){
        return 3;
    }
    return 0;
}

variable_types:
mColor
char *


trimTrailingSpace

decompiled_code:
__int64 __fastcall trimTrailingSpace(const char *a1)
{
__int64 result; // rax
const char *v2; // rcx
char v3; // dl
char v4; // dl

result = (int)(strlen(a1) - 1);
v2 = &a1[result];
v3 = a1[result];
if ( v3 == 32 || v3 == 10 )
{
result = (__int64)&a1[result - 1];
do
{
do
{
*v2 = 0;
v4 = *(_BYTE *)result;
v2 = (const char *)result--;
}
while ( v4 == 32 );
}
while ( v4 == 10 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int64 result; // rax
const char *v2; // rcx
char v3; // dl
char v4; // dl

result = (int)(strlen(a1) - 1);
v2 = &a1[result];
v3 = a1[result];
if ( v3 == 32 || v3 == 10 )
{
result = (__int64)&a1[result - 1];
do
{
do
{
*v2 = 0;
v4 = *(_BYTE *)result;
v2 = (const char *)result--;
}
while ( v4 == 32 );
}
while ( v4 == 10 );
}
return result;
}

original_code:
void trimTrailingSpace(char * string){
    int len = strlen(string) - 1;
    while(string[len] == ' ' || string[len] == '\n'){
        string[len] = '\0';
        len--;
    }
}

canonical_original_code:
void trimTrailingSpace(char *string){
    int len = strlen(string) - 1;
    while(string[len] == ' ' || string[len] == '\n'){
        string[len] = '\0';
        len--;
    }
}

variable_types:
string
char *

variable_types: len int


countMealItems

decompiled_code:
__int64 __fastcall countMealItems(_QWORD *a1)
{
__int64 result; // rax

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = (_QWORD *)*a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 result; // rax

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = (_QWORD *)*a1;
return result;
}

original_code:
int countMealItems(struct mealListItem * list){
    int i = 0;
    while(list){
        i++;
        list = list->nextItem;
    }
    return i;
}

canonical_original_code:
int countMealItems(struct mealListItem *list){
    int i = 0;
    while(list){
        i++;
        list = list->nextItem;
    }
    return i;
}

variable_types: struct mealListItem { struct mealListItem *nextItem; int color; char *description; char *priceStudent; char *priceWorker; char *priceForeigner; } *


copyColorCode

decompiled_code:
__int64 __fastcall copyColorCode(char *a1, int a2)
{
__int64 result; // rax

switch ( a2 )
{
case 2:
strcpy(a1, "\x1B[33m");
break;
case 3:
result = 109LL;
strcpy(a1, "\x1B[31m");
break;
case 1:
strcpy(a1, "\x1B[32m");
break;
}
return result;
}

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

switch ( a2 )
{
case 2:
strcpy(a1, "\x1B[33m");
break;
case 3:
result = 109LL;
strcpy(a1, "\x1B[31m");
break;
case 1:
strcpy(a1, "\x1B[32m");
break;
}
return result;
}

original_code:
void copyColorCode(char * destString, int colorCode){
    switch(colorCode){
        case 1: {
            strcpy(destString, "\033[32m");
            return;
        }
        case 2: {
            strcpy(destString, "\033[33m");
            return;
        }
        case 3: {
            strcpy(destString, "\033[31m");
            return;
        }
    }
}

canonical_original_code:
void copyColorCode(char *destString, int colorCode){
    switch(colorCode){
        case 1: {
            strcpy(destString, "\033[32m");
            return;
        }
        case 2: {
            strcpy(destString, "\033[33m");
            return;
        }
        case 3: {
            strcpy(destString, "\033[31m");
            return;
        }
    }
}

variable_types:
destString
char *

variable_types: colorCode int


printMealPlan

decompiled_code:
void __fastcall printMealPlan(__int64 a1, int a2, _DWORD *a3)
{
__int64 v3; // r14
unsigned int v5; // eax
__int64 *v6; // rbx
char *i; // rbp
char *v8; // r15
size_t v9; // rax
size_t v10; // rax
size_t v11; // rax
size_t v12; // rax

if ( *(_QWORD *)(a1 + 8) )
{
v3 = a1;
do
{
v5 = countMealItems(*(_QWORD **)(v3 + 16));
printf("%s: (%d)\n", *(const char **)v3, v5);
v6 = *(__int64 **)(v3 + 16);
for ( i = (char *)malloc(0x20uLL); v6; v6 = (__int64 *)*v6 )
{
v8 = (char *)v6[2];
if ( !a2 )
{
v9 = strlen((const char *)v6[2]);
v8 = (char *)malloc(v9 + 16);
copyColorCode(v8, *((_DWORD *)v6 + 2));
v10 = strlen(v8);
*(_DWORD *)stpcpy(&v8[v10], (const char *)v6[2]) = 7166747;
}
strcpy(i, "€ ");
if ( *a3 )
strcpy(stpcpy(i + 4, (const char *)v6[3]), " ");
if ( a3[1] )
{
v12 = strlen(i);
strcpy(stpcpy(&i[v12], (const char *)v6[4]), " ");
}
if ( a3[2] )
{
v11 = strlen(i);
strcpy(stpcpy(&i[v11], (const char *)v6[5]), " ");
}
printf("%s%s\n", i, v8);
}
puts(&byte_94D);
v3 = *(_QWORD *)(v3 + 8);
}
while ( *(_QWORD *)(v3 + 8) );
}
}

original_code:
void printMealPlan(struct mealTopic * cTopics, int pNotColored, int pPrices[3]){
    while(cTopics->nextTopic){
        printf("%s: (%d)\n",cTopics->description, countMealItems(cTopics->mealList));
        struct mealListItem * iTemp = cTopics->mealList;
        char * priceString = malloc(32);
        char * descString;
        while(iTemp){
            if(!pNotColored){
                descString = malloc(strlen(iTemp->description) + 16);
                copyColorCode(descString, iTemp->color);
                strcat(descString, iTemp->description);
                strcat(descString, "\033[m");
            } else {
                descString = iTemp->description;
            }
            strcpy(priceString, "€ ");
            if(pPrices[0]){
                strcat(priceString, iTemp->priceStudent);
                strcat(priceString, "  ");
            }
            if(pPrices[1]){
                strcat(priceString, iTemp->priceWorker);
                strcat(priceString, "  ");
            }
            if(pPrices[2]){
                strcat(priceString, iTemp->priceForeigner);
                strcat(priceString, "  ");
            }
            printf("%s%s\n", priceString, descString);
            iTemp = iTemp->nextItem;
        }
        puts("");
        cTopics = cTopics->nextTopic;
    }
}

canonical_original_code:
void printMealPlan(struct mealTopic *cTopics, int pNotColored, int pPrices[3]){
    while(cTopics->nextTopic){
        printf("%s: (%d)\n",cTopics->description, countMealItems(cTopics->mealList));
        struct mealListItem *iTemp = cTopics->mealList;
        char *priceString = malloc(32);
        char *descString;
        while(iTemp){
            if(!pNotColored){
                descString = malloc(strlen(iTemp->description) + 16);
                copyColorCode(descString, iTemp->color);
                strcat(descString, iTemp->description);
                strcat(descString, "\033[m");
            } else {
                descString = iTemp->description;
            }
            strcpy(priceString, "€ ");
            if(pPrices[0]){
                strcat(priceString, iTemp->priceStudent);
                strcat(priceString, "  ");
            }
            if(pPrices[1]){
                strcat(priceString, iTemp->priceWorker);
                strcat(priceString, "  ");
            }
            if(pPrices[2]){
                strcat(priceString, iTemp->priceForeigner);
                strcat(priceString, "  ");
            }
            printf("%s%s\n", priceString, descString);
            iTemp = iTemp->nextItem;
        }
        puts("");
        cTopics = cTopics->nextTopic;
    }
}

variable_types: struct mealTopic { char *description; struct mealTopic *nextTopic; struct mealListItem { struct mealListItem *nextItem; int color; char *description; char *priceStudent; char *priceWorker; char *priceForeigner; } *mealList; long positionInFile; } *

variable_types: pNotColored int

variable_types:
pPrices
int [3]

variable_types:
priceString
char *

variable_types:
descString
char *

user_defined_types: struct mealTopic { char *description; struct mealTopic *nextTopic; struct mealListItem *mealList; long positionInFile; }


check

repo: flyingcircle/ProgrammingLanguage

decompiled_code:
_BOOL8 __fastcall check(char *s2)
{
return strcmp(*(const char **)currLexeme, s2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char *s2)
{
return strcmp(*(const char **)currLexeme, s2) == 0;
}

original_code:
int check(char* type){
 return (strcmp(currLexeme->type, type) == 0);
}

canonical_original_code:
int check(char *type){
 return (strcmp(currLexeme->type, type) == 0);
}

variable_types:
type
char *


advance

decompiled_code:
__int64 advance()
{
__int64 result; // rax

result = lex();
currLexeme = result;
return result;
}

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

result = lex();
currLexeme = result;
return result;
}

original_code:
void advance(void){
 currLexeme = lex();
}

canonical_original_code:
void advance(){
 currLexeme = lex();
}


newParser

decompiled_code:
// attributes: thunk
__int64 newParser()
{
return advance();
}

canonical_decompiled_code:
__int64 func2()
{
return func1();
}

original_code:
void newParser(void){
 advance();
}

canonical_original_code:
void newParser(){
 advance();
}


matchNoAdvance

decompiled_code:
_BOOL8 __fastcall matchNoAdvance(char *a1)
{
_BOOL8 result; // rax

result = check(a1);
if ( !result )
{
puts("illegal");
fprintf(
stderr,
"expected %s, but encountered %s %s\n",
a1,
*(const char **)currLexeme,
*(const char **)(currLexeme + 8));
exit(1);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char *a1)
{
_BOOL8 result; // rax

result = func0(a1);
if ( !result )
{
puts("illegal");
fprintf(
stderr,
"expected %s, but encountered %s %s\n",
a1,
*(const char **)currLexeme,
*(const char **)(currLexeme + 8));
exit(1);
}
return result;
}

original_code:
void matchNoAdvance(char* type){
 if(!check(type)){
  printf("illegal\n");
  fprintf(stderr, "expected %s, but encountered %s %s\n",type,currLexeme->type, currLexeme->string);
  exit(1);
 }
}

canonical_original_code:
void matchNoAdvance(char *type){
 if(!check(type)){
  printf("illegal\n");
  fprintf(stderr, "expected %s, but encountered %s %s\n",type,currLexeme->type, currLexeme->string);
  exit(1);
 }
}


match

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

matchNoAdvance(a1);
v3 = "ENDOFINPUT";
v4 = 11LL;
v5 = currLexeme;
v6 = *(const char **)currLexeme;
do
{
if ( !v4 )
break;
v1 = *v6 < (unsigned int)*v3;
v2 = *v6++ == *v3++;
--v4;
}
while ( v2 );
if ( (!v1 && !v2) == v1 )
return currLexeme;
advance(v3, v6);
return v5;
}

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

func3(a1);
v3 = "ENDOFINPUT";
v4 = 11LL;
v5 = currLexeme;
v6 = *(const char **)currLexeme;
do
{
if ( !v4 )
break;
v1 = *v6 < (unsigned int)*v3;
v2 = *v6++ == *v3++;
--v4;
}
while ( v2 );
if ( (!v1 && !v2) == v1 )
return currLexeme;
func1(v3, v6);
return v5;
}

original_code:
lexeme* match(char* type){
 matchNoAdvance(type);
    lexeme* temp = currLexeme;
 if(strcmp(currLexeme->type,"ENDOFINPUT") != 0)
  advance();
    return temp;
}

canonical_original_code:
struct lexeme *match(char *type){
 matchNoAdvance(type);
    struct lexeme *temp = currLexeme;
 if(strcmp(currLexeme->type,"ENDOFINPUT") != 0)
  advance();
    return temp;
}

variable_types: struct lexeme { char *type; char *string; int integer; struct lexeme *left; struct lexeme *right; } *


operator

decompiled_code:
__int64 operator()
{
if ( check("PLUS") )
return match("PLUS");
if ( check("TIMES") )
return match("TIMES");
if ( check("DIVIDE") )
return match("DIVIDE");
if ( check("SUBTRACT") )
return match("SUBTRACT");
if ( check("MODULUS") )
return match("MODULUS");
if ( check("AND") )
return match("AND");
if ( check("OR") )
return match("OR");
if ( check("NOT") )
return match("NOT");
if ( check("XOR") )
return match("XOR");
if ( check("EQUALS") )
return match("EQUALS");
if ( check("NOTEQUALS") )
return match("NOTEQUALS");
if ( check("GREATERTHAN") )
return match("GREATERTHAN");
if ( check("LESSTHAN") )
return match("LESSTHAN");
if ( check("GREATEROREQUAL") )
return match("GREATEROREQUAL");
return match("LESSOREQUAL");
}

canonical_decompiled_code:
__int64 func5()
{
if ( func0("PLUS") )
return func4("PLUS");
if ( func0("TIMES") )
return func4("TIMES");
if ( func0("DIVIDE") )
return func4("DIVIDE");
if ( func0("SUBTRACT") )
return func4("SUBTRACT");
if ( func0("MODULUS") )
return func4("MODULUS");
if ( func0("AND") )
return func4("AND");
if ( func0("OR") )
return func4("OR");
if ( func0("NOT") )
return func4("NOT");
if ( func0("XOR") )
return func4("XOR");
if ( func0("EQUALS") )
return func4("EQUALS");
if ( func0("NOTEQUALS") )
return func4("NOTEQUALS");
if ( func0("GREATERTHAN") )
return func4("GREATERTHAN");
if ( func0("LESSTHAN") )
return func4("LESSTHAN");
if ( func0("GREATEROREQUAL") )
return func4("GREATEROREQUAL");
return func4("LESSOREQUAL");
}

original_code:
lexeme* operator(void){
 if(check("PLUS"))
  return match("PLUS");
 else if(check("TIMES"))
  return match("TIMES");
 else if(check("DIVIDE"))
  return match("DIVIDE");
 else if(check("SUBTRACT"))
  return match("SUBTRACT");
 else if(check("MODULUS"))
  return match("MODULUS");
 else if(check("AND"))
  return match("AND");
 else if(check("OR"))
  return match("OR");
 else if(check("NOT"))
  return match("NOT");
 else if(check("XOR"))
  return match("XOR");
 else if(check("EQUALS"))
  return match("EQUALS");
 else if(check("NOTEQUALS"))
  return match("NOTEQUALS");
 else if(check("GREATERTHAN"))
  return match("GREATERTHAN");
 else if(check("LESSTHAN"))
  return match("LESSTHAN");
 else if(check("GREATEROREQUAL"))
  return match("GREATEROREQUAL");
 else
  return match("LESSOREQUAL");
}

canonical_original_code:
struct lexeme *operator(){
 if(check("PLUS"))
  return match("PLUS");
 else if(check("TIMES"))
  return match("TIMES");
 else if(check("DIVIDE"))
  return match("DIVIDE");
 else if(check("SUBTRACT"))
  return match("SUBTRACT");
 else if(check("MODULUS"))
  return match("MODULUS");
 else if(check("AND"))
  return match("AND");
 else if(check("OR"))
  return match("OR");
 else if(check("NOT"))
  return match("NOT");
 else if(check("XOR"))
  return match("XOR");
 else if(check("EQUALS"))
  return match("EQUALS");
 else if(check("NOTEQUALS"))
  return match("NOTEQUALS");
 else if(check("GREATERTHAN"))
  return match("GREATERTHAN");
 else if(check("LESSTHAN"))
  return match("LESSTHAN");
 else if(check("GREATEROREQUAL"))
  return match("GREATEROREQUAL");
 else
  return match("LESSOREQUAL");
}

return_type: struct lexeme { char *type; char *string; int integer; struct lexeme *left; struct lexeme *right; } *


operatorPending

decompiled_code:
_BOOL8 operatorPending()
{
_BOOL4 v0; // er12

v0 = 1;
if ( !check("PLUS")
&& !check("TIMES")
&& !check("DIVIDE")
&& !check("SUBTRACT")
&& !check("MODULUS")
&& !check("AND")
&& !check("OR")
&& !check("XOR")
&& !check("EQUALS")
&& !check("NOTEQUALS")
&& !check("GREATERTHAN")
&& !check("LESSTHAN")
&& !check("GREATEROREQUAL") )
{
v0 = check("LESSOREQUAL");
}
return v0;
}

canonical_decompiled_code:
_BOOL8 func6()
{
_BOOL4 v0; // er12

v0 = 1;
if ( !func0("PLUS")
&& !func0("TIMES")
&& !func0("DIVIDE")
&& !func0("SUBTRACT")
&& !func0("MODULUS")
&& !func0("AND")
&& !func0("OR")
&& !func0("XOR")
&& !func0("EQUALS")
&& !func0("NOTEQUALS")
&& !func0("GREATERTHAN")
&& !func0("LESSTHAN")
&& !func0("GREATEROREQUAL") )
{
v0 = func0("LESSOREQUAL");
}
return v0;
}

original_code:
int operatorPending(void){
 return (check("PLUS") ||
  check("TIMES") ||
  check("DIVIDE") ||
  check("SUBTRACT") ||
  check("MODULUS") ||
  check("AND") ||
  check("OR") ||
  check("XOR") ||
  check("EQUALS") ||
  check("NOTEQUALS") ||
  check("GREATERTHAN") ||
  check("LESSTHAN") ||
  check("GREATEROREQUAL") ||
  check("LESSOREQUAL"));
}

canonical_original_code:
int operatorPending(){
 return (check("PLUS") ||
  check("TIMES") ||
  check("DIVIDE") ||
  check("SUBTRACT") ||
  check("MODULUS") ||
  check("AND") ||
  check("OR") ||
  check("XOR") ||
  check("EQUALS") ||
  check("NOTEQUALS") ||
  check("GREATERTHAN") ||
  check("LESSTHAN") ||
  check("GREATEROREQUAL") ||
  check("LESSOREQUAL"));
}


varExpressionPending

decompiled_code:
_BOOL8 varExpressionPending()
{
return check("VARIABLE");
}

canonical_decompiled_code:
_BOOL8 func7()
{
return func0("VARIABLE");
}

original_code:
int varExpressionPending(void){
 return(check("VARIABLE"));
}

canonical_original_code:
int varExpressionPending(){
 return(check("VARIABLE"));
}


primaryPending

decompiled_code:
_BOOL8 primaryPending()
{
_BOOL8 result; // rax

if ( check("NUMBER") || check("STRING") || varExpressionPending() )
result = 1LL;
else
result = check("OBRACKET");
return result;
}

canonical_decompiled_code:
_BOOL8 func8()
{
_BOOL8 result; // rax

if ( func0("NUMBER") || func0("STRING") || func7() )
result = 1LL;
else
result = func0("OBRACKET");
return result;
}

original_code:
int primaryPending(void){
 return (check("NUMBER") ||
  check("STRING") ||
  varExpressionPending() ||
  check("OBRACKET"));
}

canonical_original_code:
int primaryPending(){
 return (check("NUMBER") ||
  check("STRING") ||
  varExpressionPending() ||
  check("OBRACKET"));
}


expressionPending

decompiled_code:
// attributes: thunk
_BOOL8 expressionPending()
{
return primaryPending();
}

canonical_decompiled_code:
_BOOL8 func9()
{
return func8();
}

original_code:
int expressionPending(void){
 return (primaryPending());
}

canonical_original_code:
int expressionPending(){
 return (primaryPending());
}


arrayPending

decompiled_code:
_BOOL8 arrayPending()
{
return check("COLON");
}

canonical_decompiled_code:
_BOOL8 func10()
{
return func0("COLON");
}

original_code:
int arrayPending(void){
 return (check("COLON"));
}

canonical_original_code:
int arrayPending(){
 return (check("COLON"));
}


primary

decompiled_code:
__int64 primary()
{
__int64 result; // rax
void *v1; // rdi
__int64 v2; // r12
void *v3; // rax

if ( check("NUMBER") )
return match("NUMBER");
if ( check("STRING") )
return match("STRING");
if ( check("OBRACKET") )
{
v1 = (void *)match("OBRACKET");
free(v1);
v2 = expression();
v3 = (void *)match("CBRACKET");
free(v3);
result = v2;
}
else if ( arrayPending() )
{
result = array();
}
else
{
result = varExpression();
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 result; // rax
void *v1; // rdi
__int64 v2; // r12
void *v3; // rax

if ( func0("NUMBER") )
return func4("NUMBER");
if ( func0("STRING") )
return func4("STRING");
if ( func0("OBRACKET") )
{
v1 = (void *)func4("OBRACKET");
free(v1);
v2 = func12();
v3 = (void *)func4("CBRACKET");
free(v3);
result = v2;
}
else if ( func10() )
{
result = func16();
}
else
{
result = func15();
}
return result;
}

original_code:
lexeme* primary(void){
    lexeme* e;
 if(check("NUMBER"))
  return match("NUMBER");
 else if(check("STRING"))
  return match("STRING");
 else if(check("OBRACKET")){
  free(match("OBRACKET"));
  e = expression();
  free(match("CBRACKET"));
        return e;
 }
 else if(arrayPending())
  return array();
 else
  return varExpression();
}

canonical_original_code:
struct lexeme *primary(){
    struct lexeme *e;
 if(check("NUMBER"))
  return match("NUMBER");
 else if(check("STRING"))
  return match("STRING");
 else if(check("OBRACKET")){
  free(match("OBRACKET"));
  e = expression();
  free(match("CBRACKET"));
        return e;
 }
 else if(arrayPending())
  return array();
 else
  return varExpression();
}

user_defined_types: struct lexeme { char *type; char *string; int integer; struct lexeme *left; struct lexeme *right; }


expression

decompiled_code:
__int64 __fastcall expression(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
_BOOL4 v3; // eax
__int64 v4; // rdx
__int64 v5; // r12
__int64 v6; // rax

v2 = primary();
v3 = operatorPending();
v4 = 0LL;
if ( v3 )
{
v5 = operator(a1, a2, 0LL);
v6 = expression();
v4 = cons("GLUE", v5, v6);
}
return cons("EXPRESSION", v2, v4);
}

original_code:
lexeme* expression(void){
    lexeme* p, *o, *e;
 p = primary();
 if(operatorPending()){
  o = operator();
  e = expression();
        return cons("EXPRESSION", p, cons("GLUE", o, e));
 }
    return cons("EXPRESSION", p, ((void *)0));
}

canonical_original_code:
struct lexeme *expression(){
    struct lexeme *p; struct lexeme *o; struct lexeme *e;
 p = primary();
 if(operatorPending()){
  o = operator();
  e = expression();
        return cons("EXPRESSION", p, cons("GLUE", o, e));
 }
    return cons("EXPRESSION", p, ((void *)0));
}


list

decompiled_code:
__int64 __fastcall list(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
void *v4; // rdi
__int64 v5; // rax

v2 = expression(a1, a2);
if ( !check("COMMA") )
return cons("LIST", v2, 0LL);
v4 = (void *)match("COMMA");
free(v4);
v5 = list();
return cons("LIST", v2, v5);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
void *v4; // rdi
__int64 v5; // rax

v2 = func12(a1, a2);
if ( !func0("COMMA") )
return cons("LIST", v2, 0LL);
v4 = (void *)func4("COMMA");
free(v4);
v5 = func13();
return cons("LIST", v2, v5);
}

original_code:
lexeme* list(void){
    lexeme* e;
 e = expression();
 if(check("COMMA")){
  free(match("COMMA"));
  return cons("LIST", e, list());
 }
    return cons("LIST", e, ((void *)0));
}

canonical_original_code:
struct lexeme *list(){
    struct lexeme *e;
 e = expression();
 if(check("COMMA")){
  free(match("COMMA"));
  return cons("LIST", e, list());
 }
    return cons("LIST", e, ((void *)0));
}


optList

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

if ( expressionPending() )
result = list(a1, a2);
else
result = 0LL;
return result;
}

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

if ( func9() )
result = func13(a1, a2);
else
result = 0LL;
return result;
}

original_code:
lexeme* optList(void){
 if(expressionPending()){
  return list();
 }
    return ((void *)0);
}

canonical_original_code:
struct lexeme *optList(){
 if(expressionPending()){
  return list();
 }
    return ((void *)0);
}


varExpression

decompiled_code:
__int64 __fastcall varExpression(__int64 a1, __int64 a2)
{
__int64 v2; // r12
void *v4; // rdi
__int64 v5; // r13
void *v6; // rax

v2 = match("VARIABLE");
if ( !check("OBRACKET") )
return v2;
v4 = (void *)match("OBRACKET");
free(v4);
v5 = optList((__int64)v4, a2);
v6 = (void *)match("CBRACKET");
free(v6);
return cons("FUNCTION_CALL", v2, v5);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
__int64 v2; // r12
void *v4; // rdi
__int64 v5; // r13
void *v6; // rax

v2 = func4("VARIABLE");
if ( !func0("OBRACKET") )
return v2;
v4 = (void *)func4("OBRACKET");
free(v4);
v5 = func14((__int64)v4, a2);
v6 = (void *)func4("CBRACKET");
free(v6);
return cons("FUNCTION_CALL", v2, v5);
}

original_code:
lexeme* varExpression(void){
    lexeme* v, *l;
 v = match("VARIABLE");
 if(check("OBRACKET")){
  free(match("OBRACKET"));
  l = optList();
  free(match("CBRACKET"));
        return cons("FUNCTION_CALL", v, l);
 }
    return v;
}

canonical_original_code:
struct lexeme *varExpression(){
    struct lexeme *v; struct lexeme *l;
 v = match("VARIABLE");
 if(check("OBRACKET")){
  free(match("OBRACKET"));
  l = optList();
  free(match("CBRACKET"));
        return cons("FUNCTION_CALL", v, l);
 }
    return v;
}


array

decompiled_code:
__int64 __fastcall array(__int64 a1, __int64 a2)
{
void *v2; // rdi
__int64 v3; // r12
void *v4; // rax

v2 = (void *)match("COLON");
free(v2);
v3 = optList((__int64)v2, a2);
v4 = (void *)match("SEMICOLON");
free(v4);
return cons("ARRAY", 0LL, v3);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2)
{
void *v2; // rdi
__int64 v3; // r12
void *v4; // rax

v2 = (void *)func4("COLON");
free(v2);
v3 = func14((__int64)v2, a2);
v4 = (void *)func4("SEMICOLON");
free(v4);
return cons("ARRAY", 0LL, v3);
}

original_code:
lexeme* array(void){
 free(match("COLON"));
 lexeme* l = optList();
 free(match("SEMICOLON"));
    return cons("ARRAY", ((void *)0), l);
}

canonical_original_code:
struct lexeme *array(){
 free(match("COLON"));
 struct lexeme *l = optList();
 free(match("SEMICOLON"));
    return cons("ARRAY", ((void *)0), l);
}


assignment

decompiled_code:
__int64 __fastcall assignment(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
void *v3; // rdi
__int64 v4; // rax

v2 = match("VARIABLE");
v3 = (void *)match("ASSIGN");
free(v3);
v4 = expression((__int64)v3, a2);
return cons("ASSIGN", v2, v4);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
void *v3; // rdi
__int64 v4; // rax

v2 = func4("VARIABLE");
v3 = (void *)func4("ASSIGN");
free(v3);
v4 = func12((__int64)v3, a2);
return cons("ASSIGN", v2, v4);
}

original_code:
lexeme* assignment(void){
    lexeme* v, *e;
 v = match("VARIABLE");
 free(match("ASSIGN"));
    e = expression();
    return cons("ASSIGN", v, e);
}

canonical_original_code:
struct lexeme *assignment(){
    struct lexeme *v; struct lexeme *e;
 v = match("VARIABLE");
 free(match("ASSIGN"));
    e = expression();
    return cons("ASSIGN", v, e);
}


ifStatementPending

decompiled_code:
_BOOL8 ifStatementPending()
{
return check("IF");
}

canonical_decompiled_code:
_BOOL8 func18()
{
return func0("IF");
}

original_code:
int ifStatementPending(void){
 return (check("IF"));
}

canonical_original_code:
int ifStatementPending(){
 return (check("IF"));
}


whileStatementPending

decompiled_code:
_BOOL8 whileStatementPending()
{
return check("WHILE");
}

canonical_decompiled_code:
_BOOL8 func19()
{
return func0("WHILE");
}

original_code:
int whileStatementPending(void){
 return (check("WHILE"));
}

canonical_original_code:
int whileStatementPending(){
 return (check("WHILE"));
}


args

decompiled_code:
__int64 args()
{
__int64 v0; // rbp
void *v2; // rdi
__int64 v3; // rax

v0 = match("VARIABLE");
if ( !check("COMMA") )
return cons("PARAMETERS", v0, 0LL);
v2 = (void *)match("COMMA");
free(v2);
v3 = args();
return cons("PARAMETERS", v0, v3);
}

canonical_decompiled_code:
__int64 func20()
{
__int64 v0; // rbp
void *v2; // rdi
__int64 v3; // rax

v0 = func4("VARIABLE");
if ( !func0("COMMA") )
return cons("PARAMETERS", v0, 0LL);
v2 = (void *)func4("COMMA");
free(v2);
v3 = func20();
return cons("PARAMETERS", v0, v3);
}

original_code:
lexeme* args(void){
    lexeme* param;
 param = match("VARIABLE");
 if(check("COMMA")){
  free(match("COMMA"));
  return cons("PARAMETERS", param, args());
 }
    return cons("PARAMETERS", param, ((void *)0));
}

canonical_original_code:
struct lexeme *args(){
    struct lexeme *param;
 param = match("VARIABLE");
 if(check("COMMA")){
  free(match("COMMA"));
  return cons("PARAMETERS", param, args());
 }
    return cons("PARAMETERS", param, ((void *)0));
}


optArgs

decompiled_code:
__int64 optArgs()
{
__int64 result; // rax

if ( check("VARIABLE") )
result = args();
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func21()
{
__int64 result; // rax

if ( func0("VARIABLE") )
result = func20();
else
result = 0LL;
return result;
}

original_code:
lexeme* optArgs(void){
 if(check("VARIABLE")){
  return args();
 }
    return ((void *)0);
}

canonical_original_code:
struct lexeme *optArgs(){
 if(check("VARIABLE")){
  return args();
 }
    return ((void *)0);
}


functionDefPending

decompiled_code:
_BOOL8 functionDefPending()
{
return check("FUNCTION");
}

canonical_decompiled_code:
_BOOL8 func22()
{
return func0("FUNCTION");
}

original_code:
int functionDefPending(void){
 return (check("FUNCTION"));
}

canonical_original_code:
int functionDefPending(){
 return (check("FUNCTION"));
}