decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int64 v4; // rsi
__int64 v5; // r12
unsigned int v6; // eax
unsigned int v7; // eax

if ( argc <= 2 )
{
fprintf(stderr, "usage: %s [access_mem_count] [seed]\n", *argv);
exit(-1);
}
v3 = atoi(argv[1]);
v4 = (unsigned int)atoi(argv[2]);
if ( v3 - 100 > 0xF41DC )
{
fwrite("First parameter is wrong range\n", 1uLL, 0x1FuLL, stderr);
exit(-1);
}
v5 = genAddr(v3, v4);
v6 = fifo(v5, v3);
printf("FIFO: %d\n", v6);
v7 = lru(v5, v3);
printf("LRU: %d\n", v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int64 v4; // rsi
__int64 v5; // r12
unsigned int v6; // eax
unsigned int v7; // eax

if ( argc <= 2 )
{
fprintf(stderr, "usage: %s [access_mem_count] [seed]\n", *argv);
exit(-1);
}
v3 = atoi(argv[1]);
v4 = (unsigned int)atoi(argv[2]);
if ( v3 - 100 > 0xF41DC )
{
fwrite("First parameter is wrong range\n", 1uLL, 0x1FuLL, stderr);
exit(-1);
}
v5 = genAddr(v3, v4);
v6 = func8(v5, v3);
printf("FIFO: %d\n", v6);
v7 = func9(v5, v3);
printf("LRU: %d\n", v7);
return 0;
}

original_code:
int main(int argc, char** argv) {
    int i;
    int *arr;
    int access_mem_count;
    int seed;
    if(argc<3) {
     fprintf(stderr,"usage: %s [access_mem_count] [seed]\n",argv[0]);
     exit(-1);
    }
    access_mem_count=atoi(argv[1]);
    seed=atoi(argv[2]);
    if(access_mem_count<100||access_mem_count>1000000) {
     fprintf(stderr,"First parameter is wrong range\n");
     exit(-1);
    }
    arr=(int*)malloc(sizeof(int)*access_mem_count);
 arr = genAddr(access_mem_count, seed);
    printf("FIFO: %d\n",fifo(arr,access_mem_count));
    printf("LRU: %d\n",lru(arr,access_mem_count));
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    int i;
    int *arr;
    int access_mem_count;
    int seed;
    if(argc<3) {
     fprintf(stderr,"usage: %s [access_mem_count] [seed]\n",argv[0]);
     exit(-1);
    }
    access_mem_count=atoi(argv[1]);
    seed=atoi(argv[2]);
    if(access_mem_count<100||access_mem_count>1000000) {
     fprintf(stderr,"First parameter is wrong range\n");
     exit(-1);
    }
    arr=(int *)malloc(sizeof(int)*access_mem_count);
 arr = genAddr(access_mem_count, seed);
    printf("FIFO: %d\n",fifo(arr,access_mem_count));
    printf("LRU: %d\n",lru(arr,access_mem_count));
 return 0;
}

variable_types: i int

variable_types:
arr
int *

variable_types: seed int


isexist

decompiled_code:
__int64 __fastcall isexist(_DWORD *a1, int a2, int a3)
{
__int64 v3; // rax

if ( a2 <= 0 )
return 0LL;
v3 = (__int64)&a1[2 * (a2 - 1) + 2];
while ( *a1 != a3 )
{
a1 += 2;
if ( a1 == (_DWORD *)v3 )
return 0LL;
}
return 1LL;
}

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

if ( a2 <= 0 )
return 0LL;
v3 = (__int64)&a1[2 * (a2 - 1) + 2];
while ( *a1 != a3 )
{
a1 += 2;
if ( a1 == (_DWORD *)v3 )
return 0LL;
}
return 1LL;
}

original_code:
_Bool isexist(PAGE* arr, int size, int value) {
 int i=0;
 for(; i<size; i++) {
  if(arr[i].page_num==value) {
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
_Bool isexist(struct page *arr, int size, int value) {
 int i = 0;
 for(; i<size; i++) {
  if(arr[i].page_num==value) {
   return 1;
  }
 }
 return 0;
}

variable_types: struct page { int page_num; int recently_used; } *

variable_types: size int

variable_types: value int


fifo

original_code:
int fifo(int* arr, int size) {
 int pages_size=16/1;
 PAGE* pages=(PAGE*)malloc(sizeof(PAGE)*pages_size);
 int fault_count=0;
 int victim_frame=0;
 memset(pages,-1,sizeof(PAGE)*pages_size);
 int i;
 for(i=0; i<size; i++) {
  int frame_num=arr[i]/1024;
  if(!isexist(pages, pages_size, frame_num)) {
   fault_count++;
   pages[victim_frame].page_num=frame_num;
   pages[victim_frame].recently_used=0;
   victim_frame++;
   if(victim_frame>pages_size) {
    victim_frame=0;
   }
  }
 }
 free(pages);
 return fault_count;
}

canonical_original_code:
int fifo(int *arr, int size) {
 int pages_size = 16/1;
 struct page *pages = (PAGE*)malloc(sizeof(PAGE)*pages_size);
 int fault_count = 0;
 int victim_frame = 0;
 memset(pages,-1,sizeof(PAGE)*pages_size);
 int i;
 for(i=0; i<size; i++) {
  int frame_num = arr[i]/1024;
  if(!isexist(pages, pages_size, frame_num)) {
   fault_count++;
   pages[victim_frame].page_num=frame_num;
   pages[victim_frame].recently_used=0;
   victim_frame++;
   if(victim_frame>pages_size) {
    victim_frame=0;
   }
  }
 }
 free(pages);
 return fault_count;
}

return_type: int

user_defined_types: struct page { int page_num; int recently_used; }


lru

original_code:
int lru(int* arr, int size) {
 int pages_size=16/1;
 PAGE* pages=(PAGE*)malloc(sizeof(PAGE)*pages_size);
 int fault_count=0;
 int victim_frame=0;
 memset(pages,-1,sizeof(PAGE)*pages_size);
 int i;
 for(i=0; i<size; i++) {
  int frame_num=arr[i]/1024;
  if(!isexist(pages, pages_size, frame_num)) {
   fault_count++;
   int j;
   int high_value=0;
   for(j=0; j<pages_size; j++) {
    int temp=i-pages[j].recently_used;
    if(temp>high_value) {
     victim_frame=j;
     high_value=temp;
    }
   }
   pages[victim_frame].page_num=frame_num;
   pages[victim_frame].recently_used=i;
  }else {
   int j;
   for(j=0; j<size; j++) {
    if(pages[j].page_num==frame_num) {
     pages[j].recently_used=i;
     break;
    }
   }
  }
 }
 free(pages);
 return fault_count;
}

canonical_original_code:
int lru(int *arr, int size) {
 int pages_size = 16/1;
 struct page *pages = (PAGE*)malloc(sizeof(PAGE)*pages_size);
 int fault_count = 0;
 int victim_frame = 0;
 memset(pages,-1,sizeof(PAGE)*pages_size);
 int i;
 for(i=0; i<size; i++) {
  int frame_num = arr[i]/1024;
  if(!isexist(pages, pages_size, frame_num)) {
   fault_count++;
   int j;
   int high_value = 0;
   for(j=0; j<pages_size; j++) {
    int temp = i-pages[j].recently_used;
    if(temp>high_value) {
     victim_frame=j;
     high_value=temp;
    }
   }
   pages[victim_frame].page_num=frame_num;
   pages[victim_frame].recently_used=i;
  }else {
   int j;
   for(j=0; j<size; j++) {
    if(pages[j].page_num==frame_num) {
     pages[j].recently_used=i;
     break;
    }
   }
  }
 }
 free(pages);
 return fault_count;
}

variable_types: j int

variable_types: temp int


optimal

decompiled_code:
void optimal()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
int optimal(int* arr, int size) {
}

canonical_original_code:
int optimal(int *arr, int size) {
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
char v5[13]; // [rsp+Eh] [rbp-1Ah] BYREF

strcpy(&v5[5], "hahlfjdla df");
printf("a:%s\n", &v5[5]);
strcpy(v5, "hfad");
printf("b:%s\n", v5);
v3 = (const char *)my_strstr(&v5[5], v5);
puts(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
char v5[13]; // [rsp+Eh] [rbp-1Ah] BYREF

strcpy(&v5[5], "hahlfjdla df");
printf("a:%s\n", &v5[5]);
strcpy(v5, "hfad");
printf("b:%s\n", v5);
v3 = (const char *)func7(&v5[5], v5);
puts(v3);
return 0;
}

original_code:
int main(int argc,char* argv[])
{
 char a[]="hahlfjdla df";
 printf("a:%s\n",a);
 char b[]="hfad";
 printf("b:%s\n",b);
 char *p = my_strstr(a,b);
 printf("%s\n",p);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char a[] = "hahlfjdla df";
 printf("a:%s\n",a);
 char b[] = "hfad";
 printf("b:%s\n",b);
 char *p = my_strstr(a,b);
 printf("%s\n",p);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
a
char []

variable_types:
b
char []

variable_types:
p
char *


decompiled_code:
char *__fastcall my_strstr(char *s, char *a2)
{
int v4; // er12
size_t v5; // rax
int v6; // edx
size_t v7; // rsi
__int64 v8; // rax
char v9; // cl
int v10; // edi

v4 = strlen(a2);
v5 = strlen(s);
v6 = 0;
v7 = v5;
v8 = 0LL;
do
{
v10 = v8;
if ( v7 == v8 )
return &s[v6];
v9 = a2[v6++];
if ( s[v8] != v9 )
v6 = 0;
++v8;
}
while ( v6 != v4 );
return &s[v10 - v6 + 1];
}

canonical_decompiled_code:
char *__fastcall func7(char *s, char *a2)
{
int v4; // er12
size_t v5; // rax
int v6; // edx
size_t v7; // rsi
__int64 v8; // rax
char v9; // cl
int v10; // edi

v4 = strlen(a2);
v5 = strlen(s);
v6 = 0;
v7 = v5;
v8 = 0LL;
do
{
v10 = v8;
if ( v7 == v8 )
return &s[v6];
v9 = a2[v6++];
if ( s[v8] != v9 )
v6 = 0;
++v8;
}
while ( v6 != v4 );
return &s[v10 - v6 + 1];
}

original_code:
char *my_strstr(char *ptr,char *q)
{
 int lenth = strlen(q);
 int sum = 0;
 int i,j=0;
 for (i = 0; i < strlen(ptr); i++)
 {
  if (ptr[i] == q[j])
  {
   sum++;
   j++;
  }
  else
  {
   sum = 0;
   j = 0;
  }
  if (sum == lenth)
  {
   j = i-lenth+1;
   break;
  }
 }
 return &ptr[j];
}

canonical_original_code:
char *my_strstr(char *ptr, char *q)
{
 int lenth = strlen(q);
 int sum = 0;
 int i; int j = 0;
 for (i = 0; i < strlen(ptr); i++)
 {
  if (ptr[i] == q[j])
  {
   sum++;
   j++;
  }
  else
  {
   sum = 0;
   j = 0;
  }
  if (sum == lenth)
  {
   j = i-lenth+1;
   break;
  }
 }
 return &ptr[j];
}

variable_types:
ptr
char *

variable_types:
q
char *

variable_types: lenth int

variable_types: sum int

return_type: char *


execute

decompiled_code:
__int64 __fastcall execute(char **argv)
{
unsigned int v1; // er12
__int64 v3; // rbp
char *v4; // r8
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
char *v9; // rsi
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = 1;
v3 = (unsigned int)fork();
printf("The PID is %d\n", v3);
if ( !strcmp(*argv, "exit") || !strcmp(*argv, "quit") )
return v1;
if ( (int)v3 < 0 )
{
puts("There was an error with not enough memory");
return v1;
}
if ( !(_DWORD)v3 )
{
printf("I am the child! PID %d\n", 0LL);
v4 = *argv;
v5 = (unsigned __int8)**argv < 0x63u;
v6 = **argv == 99;
if ( **argv == 99
&& (v5 = (unsigned __int8)v4[1] < 0x64u, v6 = v4[1] == 100)
&& (v1 = (unsigned __int8)v4[2], v5 = 0, v6 = v1 == 0, !v4[2]) )
{
printf("Changing directory to %s\n", argv[1]);
chdir(argv[1]);
}
else
{
v7 = "history";
v8 = 8LL;
v9 = *argv;
do
{
if ( !v8 )
break;
v5 = (unsigned __int8)*v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
v1 = (char)((!v5 && !v6) - v5);
if ( (!v5 && !v6) == v5 )
{
printf("Viewing history!");
view_hist("Viewing history!", v9);
}
else
{
printf("Executing command: %s\n", *argv);
v1 = (unsigned int)execvp(*argv, argv) >> 31;
}
}
return v1;
}
printf("I am the parent! PID %d\n", (unsigned int)v3);
wait((__WAIT_STATUS)&stat_loc);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **argv)
{
unsigned int v1; // er12
__int64 v3; // rbp
char *v4; // r8
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
char *v9; // rsi
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = 1;
v3 = (unsigned int)fork();
printf("The PID is %d\n", v3);
if ( !strcmp(*argv, "exit") || !strcmp(*argv, "quit") )
return v1;
if ( (int)v3 < 0 )
{
puts("There was an error with not enough memory");
return v1;
}
if ( !(_DWORD)v3 )
{
printf("I am the child! PID %d\n", 0LL);
v4 = *argv;
v5 = (unsigned __int8)**argv < 0x63u;
v6 = **argv == 99;
if ( **argv == 99
&& (v5 = (unsigned __int8)v4[1] < 0x64u, v6 = v4[1] == 100)
&& (v1 = (unsigned __int8)v4[2], v5 = 0, v6 = v1 == 0, !v4[2]) )
{
printf("Changing directory to %s\n", argv[1]);
chdir(argv[1]);
}
else
{
v7 = "history";
v8 = 8LL;
v9 = *argv;
do
{
if ( !v8 )
break;
v5 = (unsigned __int8)*v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
v1 = (char)((!v5 && !v6) - v5);
if ( (!v5 && !v6) == v5 )
{
printf("Viewing history!");
view_hist("Viewing history!", v9);
}
else
{
printf("Executing command: %s\n", *argv);
v1 = (unsigned int)execvp(*argv, argv) >> 31;
}
}
return v1;
}
printf("I am the parent! PID %d\n", (unsigned int)v3);
wait((__WAIT_STATUS)&stat_loc);
return 0LL;
}

original_code:
int execute(char** argv) {
    int status;
    int exe_r;
    pid_t pid = fork();
    printf("The PID is %d\n", pid);
    if (!strcmp(argv[0], "exit") || !strcmp(argv[0], "quit")){
        return 1;
    }
    if (pid < 0){
        printf("There was an error with not enough memory\n");
        return 1;
    } else if (pid == 0){
        printf("I am the child! PID %d\n", pid);
        if (!strcmp(argv[0], "cd")){
            printf("Changing directory to %s\n", argv[1]);
            chdir(argv[1]);
        } else if (!strcmp(argv[0], "history")){
            printf("Viewing history!");
            view_hist();
        } else {
            printf("Executing command: %s\n", argv[0]);
            exe_r = execvp(argv[0], argv);
            if(exe_r < 0){
                return 1;
            }
        }
    } else {
        printf("I am the parent! PID %d\n", pid);
        wait(&status);
    }
    return 0;
}

canonical_original_code:
int execute(char **argv) {
    int status;
    int exe_r;
    int pid = fork();
    printf("The PID is %d\n", pid);
    if (!strcmp(argv[0], "exit") || !strcmp(argv[0], "quit")){
        return 1;
    }
    if (pid < 0){
        printf("There was an error with not enough memory\n");
        return 1;
    } else if (pid == 0){
        printf("I am the child! PID %d\n", pid);
        if (!strcmp(argv[0], "cd")){
            printf("Changing directory to %s\n", argv[1]);
            chdir(argv[1]);
        } else if (!strcmp(argv[0], "history")){
            printf("Viewing history!");
            view_hist();
        } else {
            printf("Executing command: %s\n", argv[0]);
            exe_r = execvp(argv[0], argv);
            if(exe_r < 0){
                return 1;
            }
        }
    } else {
        printf("I am the parent! PID %d\n", pid);
        wait(&status);
    }
    return 0;
}

variable_types:
argv
char **

variable_types: status int

variable_types: pid int


parse

decompiled_code:
char **__fastcall parse(char *a1)
{
char *v1; // rax
char *v2; // rax
char *v3; // rsi

v1 = strtok(a1, " ");
strcpy(*cmd, v1);
v2 = strtok(0LL, " ");
if ( v2 )
{
v3 = v2;
do
{
strcpy(cmd[++num_args], v3);
v3 = strtok(0LL, " ");
}
while ( v3 );
}
return cmd;
}

canonical_decompiled_code:
char **__fastcall func1(char *a1)
{
char *v1; // rax
char *v2; // rax
char *v3; // rsi

v1 = strtok(a1, " ");
strcpy(*cmd, v1);
v2 = strtok(0LL, " ");
if ( v2 )
{
v3 = v2;
do
{
strcpy(cmd[++num_args], v3);
v3 = strtok(0LL, " ");
}
while ( v3 );
}
return cmd;
}

original_code:
char** parse(char* input) {
    char *temp = ((void *)0);
    strcpy(cmd[0], strtok(input, " "));
    temp = strtok(((void *)0), " ");
    while (temp != ((void *)0)) {
        num_args++;
        strcpy(cmd[num_args], temp);
        temp = strtok(((void *)0), " ");
    }
    return cmd;
}

canonical_original_code:
char **parse(char *input) {
    char *temp = ((void *)0);
    strcpy(cmd[0], strtok(input, " "));
    temp = strtok(((void *)0), " ");
    while (temp != ((void *)0)) {
        num_args++;
        strcpy(cmd[num_args], temp);
        temp = strtok(((void *)0), " ");
    }
    return cmd;
}

variable_types:
input
char *

variable_types:
temp
char *

return_type: char **


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx
char **v4; // rbp
char *v5; // rbp
const char *v6; // rbx
char **v7; // rdi
__int64 v8; // rdi
char *v9; // rdx
int v10; // eax
__int64 v11; // rdx
int v12; // ecx
char *v13; // rax
char v15[104]; // [rsp+0h] [rbp-68h] BYREF

cmd = (char **)malloc(0x280uLL);
v3 = cmd;
v4 = cmd + 80;
do
*v3++ = (char *)malloc(0x50uLL);
while ( v3 != v4 );
v5 = 0LL;
home_path = getwd(home_path);
strcat(home_path, "/.history");
init_history(home_path, argv);
do
{
v5 = getwd(v5);
printf("jdcsh: %s>", v5);
fflush(stdout);
fgets(v15, 80, stdin);
*cmd = *parse(v15);
v6 = cmd[num_args];
v6[(int)strlen(v6) - 1] = 0;
v7 = cmd;
if ( *(_BYTE *)cmd == 33 && *((_BYTE *)cmd + 1) == 33 && !*((_BYTE *)cmd + 2) )
{
v8 = (unsigned int)get_hist_count() - 1;
}
else
{
if ( **cmd != 33 )
goto LABEL_9;
v8 = (unsigned int)atoi(*cmd + 1);
}
v9 = *(char **)get_from_hist(v8);
*cmd = v9;
v7 = cmd;
LABEL_9:
save_in_hist(v7, (unsigned int)num_args);
v10 = execute(cmd);
v11 = 0LL;
v12 = v10;
do
{
v13 = cmd[v11++];
*(_OWORD *)v13 = 0LL;
*((_OWORD *)v13 + 1) = 0LL;
*((_OWORD *)v13 + 2) = 0LL;
*((_OWORD *)v13 + 3) = 0LL;
*((_OWORD *)v13 + 4) = 0LL;
}
while ( v11 != 80 );
}
while ( !v12 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx
char **v4; // rbp
char *v5; // rbp
const char *v6; // rbx
char **v7; // rdi
__int64 v8; // rdi
char *v9; // rdx
int v10; // eax
__int64 v11; // rdx
int v12; // ecx
char *v13; // rax
char v15[104]; // [rsp+0h] [rbp-68h] BYREF

cmd = (char **)malloc(0x280uLL);
v3 = cmd;
v4 = cmd + 80;
do
*v3++ = (char *)malloc(0x50uLL);
while ( v3 != v4 );
v5 = 0LL;
home_path = getwd(home_path);
strcat(home_path, "/.history");
init_history(home_path, argv);
do
{
v5 = getwd(v5);
printf("jdcsh: %s>", v5);
fflush(stdout);
fgets(v15, 80, stdin);
*cmd = *func1(v15);
v6 = cmd[num_args];
v6[(int)strlen(v6) - 1] = 0;
v7 = cmd;
if ( *(_BYTE *)cmd == 33 && *((_BYTE *)cmd + 1) == 33 && !*((_BYTE *)cmd + 2) )
{
v8 = (unsigned int)get_hist_count() - 1;
}
else
{
if ( **cmd != 33 )
goto LABEL_9;
v8 = (unsigned int)atoi(*cmd + 1);
}
v9 = *(char **)get_from_hist(v8);
*cmd = v9;
v7 = cmd;
LABEL_9:
save_in_hist(v7, (unsigned int)num_args);
v10 = func0(cmd);
v11 = 0LL;
v12 = v10;
do
{
v13 = cmd[v11++];
*(_OWORD *)v13 = 0LL;
*((_OWORD *)v13 + 1) = 0LL;
*((_OWORD *)v13 + 2) = 0LL;
*((_OWORD *)v13 + 3) = 0LL;
*((_OWORD *)v13 + 4) = 0LL;
}
while ( v11 != 80 );
}
while ( !v12 );
return 0;
}

original_code:
int main(void) {
    char *cwd = ((void *)0);
    int should_run = 1;
    int history_cmd;
    int i;
    char input[80];
    cmd = (char **) malloc(80*sizeof(char *));
    for(i = 0; i < 80; i++) {
        cmd[i] = (char *) malloc(80*sizeof(char));
    }
    home_path = getwd(home_path);
    strcat(home_path, "/.history");
    init_history(home_path);
    while (should_run){
        cwd = getwd(cwd);
        printf("jdcsh: %s>", cwd);
        fflush(stdout);
        fgets(input, 80, stdin);
        memcpy(cmd , parse(input), sizeof(cmd));
        int lcmd_len = (int) strlen(cmd[num_args]);
        cmd[num_args][lcmd_len-1] = '\0';
        if(!strcmp(cmd, "!!")) {
            memcpy(cmd, get_from_hist(get_hist_count() - 1), sizeof(cmd));
        } else if(cmd[0][0] == '!') {
            history_cmd = atoi(cmd[0] + 1);
            memcpy(cmd, get_from_hist(history_cmd), sizeof(cmd));
        }
        save_in_hist(cmd, num_args);
        should_run = !execute(cmd);
        for(i = 0; i < 80; i++) {
            memset(cmd[i], '\0', 80);
        }
    }
    return 0;
}

canonical_original_code:
int main() {
    char *cwd = ((void *)0);
    int should_run = 1;
    int history_cmd;
    int i;
    char input[80];
    cmd = (char **) malloc(80*sizeof(char *));
    for(i = 0; i < 80; i++) {
        cmd[i] = (char *) malloc(80*sizeof(char));
    }
    home_path = getwd(home_path);
    strcat(home_path, "/.history");
    init_history(home_path);
    while (should_run){
        cwd = getwd(cwd);
        printf("jdcsh: %s>", cwd);
        fflush(stdout);
        fgets(input, 80, stdin);
        memcpy(cmd , parse(input), sizeof(cmd));
        int lcmd_len = (int) strlen(cmd[num_args]);
        cmd[num_args][lcmd_len-1] = '\0';
        if(!strcmp(cmd, "!!")) {
            memcpy(cmd, get_from_hist(get_hist_count() - 1), sizeof(cmd));
        } else if(cmd[0][0] == '!') {
            history_cmd = atoi(cmd[0] + 1);
            memcpy(cmd, get_from_hist(history_cmd), sizeof(cmd));
        }
        save_in_hist(cmd, num_args);
        should_run = !execute(cmd);
        for(i = 0; i < 80; i++) {
            memset(cmd[i], '\0', 80);
        }
    }
    return 0;
}

variable_types:
cwd
char *

variable_types: i int

variable_types:
input
char [80]


decompiled_code:
void *__fastcall init_history(char *src)
{
char *v1; // rax
FILE *v2; // rdi
char *v3; // rbx
char *v4; // rbp
void *result; // rax

history_file_path = (char *)malloc(0x50uLL);
v1 = strcpy(history_file_path, src);
h_count = 0;
history_file = fopen(v1, "w");
v2 = history_file;
if ( !history_file )
{
fwrite("history file could not open\n", 1uLL, 0x1CuLL, stderr);
v2 = history_file;
}
fclose(v2);
cmd = malloc(0x280uLL);
v3 = (char *)cmd;
v4 = (char *)cmd + 640;
do
{
v3 += 8;
result = malloc(0x50uLL);
*((_QWORD *)v3 - 1) = result;
}
while ( v3 != v4 );
return result;
}

canonical_decompiled_code:
void *__fastcall func0(char *src)
{
char *v1; // rax
FILE *v2; // rdi
char *v3; // rbx
char *v4; // rbp
void *result; // rax

history_file_path = (char *)malloc(0x50uLL);
v1 = strcpy(history_file_path, src);
h_count = 0;
history_file = fopen(v1, "w");
v2 = history_file;
if ( !history_file )
{
fwrite("history file could not open\n", 1uLL, 0x1CuLL, stderr);
v2 = history_file;
}
fclose(v2);
cmd = malloc(0x280uLL);
v3 = (char *)cmd;
v4 = (char *)cmd + 640;
do
{
v3 += 8;
result = malloc(0x50uLL);
*((_QWORD *)v3 - 1) = result;
}
while ( v3 != v4 );
return result;
}

original_code:
void init_history(char* file_path) {
    int i;
    history_file_path = (char *) malloc(80*sizeof(char));
    strcpy(history_file_path, file_path);
    h_count = 0;
    history_file = fopen(history_file_path, "w");
    if (!history_file){
        fprintf(stderr, "history file could not open\n");
    }
    fclose(history_file);
    cmd = (char **) malloc(80*sizeof(char *));
    for(i = 0; i < 80; i++) {
        cmd[i] = (char *) malloc(80*sizeof(char));
    }
}

canonical_original_code:
void init_history(char *file_path) {
    int i;
    history_file_path = (char *) malloc(80*sizeof(char));
    strcpy(history_file_path, file_path);
    h_count = 0;
    history_file = fopen(history_file_path, "w");
    if (!history_file){
        fprintf(stderr, "history file could not open\n");
    }
    fclose(history_file);
    cmd = (char **) malloc(80*sizeof(char *));
    for(i = 0; i < 80; i++) {
        cmd[i] = (char *) malloc(80*sizeof(char));
    }
}

return_type: void


decompiled_code:
void reclaim_history_memory()
{
char *v0; // rdi
__int64 i; // rbx

v0 = (char *)cmd;
for ( i = 0LL; i != 640; i += 8LL )
{
free(*(void **)&v0[i]);
v0 = (char *)cmd;
*(_QWORD *)((char *)cmd + i) = 0LL;
}
free(v0);
cmd = 0LL;
}

canonical_decompiled_code:
void func1()
{
char *v0; // rdi
__int64 i; // rbx

v0 = (char *)cmd;
for ( i = 0LL; i != 640; i += 8LL )
{
free(*(void **)&v0[i]);
v0 = (char *)cmd;
*(_QWORD *)((char *)cmd + i) = 0LL;
}
free(v0);
cmd = 0LL;
}

original_code:
void reclaim_history_memory() {
   int i;
   for(i = 0; i < 80; i++) {
        free(cmd[i]);
        cmd[i] = ((void *)0);
    }
    free(cmd);
    cmd = ((void *)0);
}


decompiled_code:
int view_hist()
{
int result; // eax
int v1; // ebx

history_file = fopen(history_file_path, "r");
if ( !history_file )
printf("Could not open the history");
putchar(10);
result = h_count;
if ( h_count >= 0 )
{
v1 = 0;
do
{
++v1;
fgets(0LL, 80, history_file);
result = puts(0LL);
}
while ( h_count >= v1 );
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax
int v1; // ebx

history_file = fopen(history_file_path, "r");
if ( !history_file )
printf("Could not open the history");
putchar(10);
result = h_count;
if ( h_count >= 0 )
{
v1 = 0;
do
{
++v1;
fgets(0LL, 80, history_file);
result = puts(0LL);
}
while ( h_count >= v1 );
}
return result;
}

original_code:
void view_hist() {
    int i;
    char* temp;
    history_file = fopen(history_file_path, "r");
    if (!history_file){
        printf("Could not open the history");
    }
    printf("\n");
    for (i = 0; i<=h_count; i++){
        fgets(temp, 80, history_file);
        printf("%s\n", temp);
    }
}

canonical_original_code:
void view_hist() {
    int i;
    char *temp;
    history_file = fopen(history_file_path, "r");
    if (!history_file){
        printf("Could not open the history");
    }
    printf("\n");
    for (i = 0; i<=h_count; i++){
        fgets(temp, 80, history_file);
        printf("%s\n", temp);
    }
}


decompiled_code:
__int64 __fastcall save_in_hist(const char **a1, int a2)
{
FILE *v2; // rax
__int64 v3; // rbx
const char *v4; // rdx
__int64 result; // rax

v2 = fopen(history_file_path, "a");
history_file = v2;
if ( v2 )
{
fprintf(v2, "%d %s ", (unsigned int)h_count, *a1);
if ( a2 > 0 )
{
v3 = 1LL;
do
{
v4 = a1[v3++];
fprintf(history_file, "%s ", v4);
}
while ( a2 >= (int)v3 );
}
fputc(10, history_file);
fclose(history_file);
result = 0LL;
++h_count;
}
else
{
printf("history read error");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char **a1, int a2)
{
FILE *v2; // rax
__int64 v3; // rbx
const char *v4; // rdx
__int64 result; // rax

v2 = fopen(history_file_path, "a");
history_file = v2;
if ( v2 )
{
fprintf(v2, "%d %s ", (unsigned int)h_count, *a1);
if ( a2 > 0 )
{
v3 = 1LL;
do
{
v4 = a1[v3++];
fprintf(history_file, "%s ", v4);
}
while ( a2 >= (int)v3 );
}
fputc(10, history_file);
fclose(history_file);
result = 0LL;
++h_count;
}
else
{
printf("history read error");
result = 1LL;
}
return result;
}

original_code:
int save_in_hist(char** cmd, int args) {
    int i;
    history_file = fopen(history_file_path, "a");
    if (!history_file){
        printf("history read error");
        return 1;
    }
    fprintf (history_file, "%d %s ", h_count, cmd[0]);
    for (i=1; i<=args; i++){
        fprintf (history_file, "%s ", cmd[i]);
    }
    fprintf (history_file, "\n");
    fclose(history_file);
    h_count++;
    return 0;
}

canonical_original_code:
int save_in_hist(char **cmd, int args) {
    int i;
    history_file = fopen(history_file_path, "a");
    if (!history_file){
        printf("history read error");
        return 1;
    }
    fprintf (history_file, "%d %s ", h_count, cmd[0]);
    for (i=1; i<=args; i++){
        fprintf (history_file, "%s ", cmd[i]);
    }
    fprintf (history_file, "\n");
    fclose(history_file);
    h_count++;
    return 0;
}

variable_types:
cmd
char **

variable_types: args int


decompiled_code:
__int64 get_hist_count()
{
return (unsigned int)h_count;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)h_count;
}

original_code:
int get_hist_count() {
    return h_count;
}


decompiled_code:
void *__fastcall get_from_hist(int a1)
{
FILE *v1; // rdx
int i; // ebx
__int64 v3; // rbx
char *v4; // rax
char *j; // rsi
char *v6; // rdi

history_file = fopen(history_file_path, "r");
v1 = history_file;
if ( !history_file )
{
puts("History Read Error:");
puts("Those who forget their history are doomed to repeat it...");
v1 = history_file;
}
if ( a1 >= 0 )
{
for ( i = 0; i <= a1; ++i )
{
fgets(0LL, 80, v1);
v1 = history_file;
}
}
v3 = 8LL;
fclose(v1);
strtok(0LL, " ");
v4 = strtok(0LL, " ");
strcpy(*(char **)cmd, v4);
for ( j = strtok(0LL, " "); j; j = strtok(0LL, " ") )
{
v6 = *(char **)((char *)cmd + v3);
v3 += 8LL;
strcpy(v6, j);
}
return cmd;
}

canonical_decompiled_code:
void *__fastcall func5(int a1)
{
FILE *v1; // rdx
int i; // ebx
__int64 v3; // rbx
char *v4; // rax
char *j; // rsi
char *v6; // rdi

history_file = fopen(history_file_path, "r");
v1 = history_file;
if ( !history_file )
{
puts("History Read Error:");
puts("Those who forget their history are doomed to repeat it...");
v1 = history_file;
}
if ( a1 >= 0 )
{
for ( i = 0; i <= a1; ++i )
{
fgets(0LL, 80, v1);
v1 = history_file;
}
}
v3 = 8LL;
fclose(v1);
strtok(0LL, " ");
v4 = strtok(0LL, " ");
strcpy(*(char **)cmd, v4);
for ( j = strtok(0LL, " "); j; j = strtok(0LL, " ") )
{
v6 = *(char **)((char *)cmd + v3);
v3 += 8LL;
strcpy(v6, j);
}
return cmd;
}

original_code:
char** get_from_hist(int num) {
    char* hist_cmd;
    char* temp;
    int num_args = 0;
    int i;
    history_file = fopen(history_file_path, "r");
    if(!history_file) {
        printf("History Read Error:\n");
        printf("Those who forget their history are doomed to repeat it...\n");
    }
    for (i = 0; i <= num; i++){
        fgets(hist_cmd, 80, history_file);
    }
    fclose(history_file);
    strtok(hist_cmd, " ");
    strcpy(cmd[0], strtok(((void *)0), " "));
    temp = strtok(((void *)0), " ");
    while (temp != ((void *)0)) {
        num_args++;
        strcpy(cmd[num_args], temp);
        temp = strtok(((void *)0), " ");
    }
    return cmd;
}

canonical_original_code:
char **get_from_hist(int num) {
    char *hist_cmd;
    char *temp;
    int num_args = 0;
    int i;
    history_file = fopen(history_file_path, "r");
    if(!history_file) {
        printf("History Read Error:\n");
        printf("Those who forget their history are doomed to repeat it...\n");
    }
    for (i = 0; i <= num; i++){
        fgets(hist_cmd, 80, history_file);
    }
    fclose(history_file);
    strtok(hist_cmd, " ");
    strcpy(cmd[0], strtok(((void *)0), " "));
    temp = strtok(((void *)0), " ");
    while (temp != ((void *)0)) {
        num_args++;
        strcpy(cmd[num_args], temp);
        temp = strtok(((void *)0), " ");
    }
    return cmd;
}

variable_types: num int


repo: oakey-dev/moonitor

decompiled_code:
int catch_sigpipe()
{
return puts("caught SIGPIPE");
}

canonical_decompiled_code:
int func0()
{
return puts("caught SIGPIPE");
}

original_code:
void catch_sigpipe(int i){
 printf("caught SIGPIPE\n");
}


decompiled_code:
__int64 listener_thread()
{
int v0; // edx
int v1; // eax
int v2; // ebp
pthread_t v3; // r12
int v4; // ebx
__int64 result; // rax
int v6; // [rsp+0h] [rbp-D8h] BYREF
socklen_t addr_len; // [rsp+4h] [rbp-D4h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-D0h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-C8h] BYREF
struct sigaction v10; // [rsp+20h] [rbp-B8h] BYREF

addr_len = 16;
v10.sa_handler = (__sighandler_t)catch_sigpipe;
memset(&v10.sa_mask, 0, 0x90uLL);
sigaction(13, &v10, 0LL);
addr = 0LL;
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = inet_addr("127.0.0.1");
*(_WORD *)addr.sa_data = _bswap_16_constprop_0(2LL, 1LL, 0LL);
v1 = socket(2, 1, v0);
if ( v1 < 0 )
{
perror("error creating socket. terminating sockshell thread.");
result = 0LL;
}
else
{
v2 = v1;
if ( bind(v1, &addr, 0x10u) )
{
perror("error binding to DEFAULT_HOST:DEFAULT_PORT. terminating sockshell thread.");
}
else
{
if ( !listen(v2, 1024) )
{
v3 = pthread_self();
while ( 1 )
{
pthread_mutex_lock(&lock);
v6 = accept(v2, &addr, &addr_len);
if ( v6 < 0 )
perror("error accepting connections on socket");
printf("sockshell main thread (thread id:%ld) accepted connection\n", v3);
v4 = pthread_create(&newthread, 0LL, session, &v6);
if ( v4 )
{
*_errno_location() = v4;
perror("error creating thread for sockshell session");
pthread_mutex_unlock(&lock);
}
}
}
perror("error listening on socket. terminating sockshell thread.");
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // edx
int v1; // eax
int v2; // ebp
pthread_t v3; // r12
int v4; // ebx
__int64 result; // rax
int v6; // [rsp+0h] [rbp-D8h] BYREF
socklen_t addr_len; // [rsp+4h] [rbp-D4h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-D0h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-C8h] BYREF
struct sigaction v10; // [rsp+20h] [rbp-B8h] BYREF

addr_len = 16;
v10.sa_handler = (__sighandler_t)catch_sigpipe;
memset(&v10.sa_mask, 0, 0x90uLL);
sigaction(13, &v10, 0LL);
addr = 0LL;
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = inet_addr("127.0.0.1");
*(_WORD *)addr.sa_data = func1(2LL, 1LL, 0LL);
v1 = socket(2, 1, v0);
if ( v1 < 0 )
{
perror("error creating socket. terminating sockshell thread.");
result = 0LL;
}
else
{
v2 = v1;
if ( bind(v1, &addr, 0x10u) )
{
perror("error binding to DEFAULT_HOST:DEFAULT_PORT. terminating sockshell thread.");
}
else
{
if ( !listen(v2, 1024) )
{
v3 = pthread_self();
while ( 1 )
{
pthread_mutex_lock(&lock);
v6 = accept(v2, &addr, &addr_len);
if ( v6 < 0 )
perror("error accepting connections on socket");
printf("sockshell main thread (thread id:%ld) accepted connection\n", v3);
v4 = pthread_create(&newthread, 0LL, session, &v6);
if ( v4 )
{
*_errno_location() = v4;
perror("error creating thread for sockshell session");
pthread_mutex_unlock(&lock);
}
}
}
perror("error listening on socket. terminating sockshell thread.");
}
result = 0LL;
}
return result;
}

original_code:
void* listener_thread(void* p_arg){
 ((void) sizeof ((sizeof(void*) >= sizeof(int)) ? 1 : 0), __extension__ ({ if (sizeof(void*) >= sizeof(int)) ; else __assert_fail ("sizeof(void*) >= sizeof(int)", "listener.c", 18, __extension__ __PRETTY_FUNCTION__); }));
 int consock;
 pthread_t last_session;
 socklen_t socksize = sizeof(struct sockaddr_in);
 struct sigaction sig_act;
 memset(&sig_act,0,sizeof(struct sigaction));
 sig_act.__sigaction_handler.sa_handler = catch_sigpipe;
 sigaction(13,&sig_act,((void *)0));
 struct sockaddr_in addr;
 memset(&addr,0,sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = inet_addr("127.0.0.1");
 addr.sin_port = htons(2130);
 int sock = socket(2,SOCK_STREAM,0);
 if(sock < 0){
  perror("error creating socket. terminating sockshell thread.");
  return ((void *)0);
 }
 if( 0 != bind(sock,(struct sockaddr*)&addr,sizeof(addr))){
  perror("error binding to DEFAULT_HOST:DEFAULT_PORT. terminating sockshell thread.");
  return ((void *)0);
 }
 if( 0 != listen(sock,1024)){
  perror("error listening on socket. terminating sockshell thread.");
  return ((void *)0);
 }
 int status;
 for(;;){
  pthread_mutex_lock(&lock);
  consock = accept(sock,(struct sockaddr*)&addr,&socksize);
  if(consock<0){
   perror("error accepting connections on socket");
  }
  printf("sockshell main thread (thread id:%ld) accepted connection\n",(long)pthread_self());
  status = pthread_create(&last_session,((void *)0),session,&consock);
  if(status != 0){
   do{ (*__errno_location ()) = status; perror("error creating thread for sockshell session"); } while(0);
   pthread_mutex_unlock(&lock);
  }
 }
 return 0;
}

canonical_original_code:
void *listener_thread(void *p_arg){
 ((void) sizeof ((sizeof(void *) >= sizeof(int)) ? 1 : 0), __extension__ ({ if (sizeof(void *) >= sizeof(int)) ; else __assert_fail ("sizeof(void*) >= sizeof(int)", "listener.c", 18, __extension__ __PRETTY_FUNCTION__); }));
 int consock;
 unsigned long last_session;
 unsigned int socksize = sizeof(struct sockaddr_in);
 struct sigaction sig_act;
 memset(&sig_act,0,sizeof(struct sigaction));
 sig_act.__sigaction_handler.sa_handler = catch_sigpipe;
 sigaction(13,&sig_act,((void *)0));
 struct sockaddr_in addr;
 memset(&addr,0,sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = inet_addr("127.0.0.1");
 addr.sin_port = htons(2130);
 int sock = socket(2,SOCK_STREAM,0);
 if(sock < 0){
  perror("error creating socket. terminating sockshell thread.");
  return ((void *)0);
 }
 if( 0 != bind(sock,(struct sockaddr *)&addr,sizeof(addr))){
  perror("error binding to DEFAULT_HOST:DEFAULT_PORT. terminating sockshell thread.");
  return ((void *)0);
 }
 if( 0 != listen(sock,1024)){
  perror("error listening on socket. terminating sockshell thread.");
  return ((void *)0);
 }
 int status;
 for(;;){
  pthread_mutex_lock(&lock);
  consock = accept(sock,(struct sockaddr *)&addr,&socksize);
  if(consock<0){
   perror("error accepting connections on socket");
  }
  printf("sockshell main thread (thread id:%ld) accepted connection\n",(long)pthread_self());
  status = pthread_create(&last_session,((void *)0),session,&consock);
  if(status != 0){
   do{ (*__errno_location ()) = status; perror("error creating thread for sockshell session"); } while(0);
   pthread_mutex_unlock(&lock);
  }
 }
 return 0;
}

variable_types: consock int

variable_types:
socksize
unsigned int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

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

variable_types: sock int

return_type: void *

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

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

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


nwrite

decompiled_code:
__int64 __fastcall nwrite(int fd, __int64 a2, size_t a3)
{
size_t i; // rbx
int v5; // eax
unsigned int v6; // er14
__int64 result; // rax

if ( a3 )
{
for ( i = 0LL; i < a3; i += v5 )
{
v5 = write(fd, (const void *)(a2 + i), a3);
v6 = v5;
if ( v5 < 0 )
{
perror("error writing to file descriptor");
goto LABEL_6;
}
}
result = (unsigned int)i;
}
else
{
v6 = 0;
LABEL_6:
result = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, __int64 a2, size_t a3)
{
size_t i; // rbx
int v5; // eax
unsigned int v6; // er14
__int64 result; // rax

if ( a3 )
{
for ( i = 0LL; i < a3; i += v5 )
{
v5 = write(fd, (const void *)(a2 + i), a3);
v6 = v5;
if ( v5 < 0 )
{
perror("error writing to file descriptor");
goto LABEL_6;
}
}
result = (unsigned int)i;
}
else
{
v6 = 0;
LABEL_6:
result = v6;
}
return result;
}

original_code:
int nwrite(int fd, const void* buf,size_t count){
 int n=0;
 size_t written=0;
 char* bytebuf=(char*)buf;
 while(written < count){
  n = write(fd,(void*)&(bytebuf[written]),count);
  if(n<0){
   perror("error writing to file descriptor");
   return n;
  } else {
   written += n;
  }
 }
 return written;
}

canonical_original_code:
int nwrite(int fd, void *buf, unsigned long count){
 int n = 0;
 unsigned long written = 0;
 char *bytebuf = (char*)buf;
 while(written < count){
  n = write(fd,(void *)&(bytebuf[written]),count);
  if(n<0){
   perror("error writing to file descriptor");
   return n;
  } else {
   written += n;
  }
 }
 return written;
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
count
unsigned long

variable_types: n int

variable_types:
written
unsigned long

variable_types:
bytebuf
char *


callback

decompiled_code:
__int64 __fastcall callback(int *a1, int a2, __int64 a3, __int64 a4)
{
int v4; // ebp
__int64 v7; // rbx
const char *v8; // r15
size_t v9; // rax
const char *v10; // r15
size_t v11; // rax

v4 = *a1;
if ( a2 > 0 )
{
v7 = 0LL;
do
{
v8 = *(const char **)(a4 + 8 * v7);
v9 = strlen(v8);
nwrite(v4, (__int64)v8, v9);
nwrite(v4, (__int64)"=", 1uLL);
v10 = *(const char **)(a3 + 8 * v7++);
v11 = strlen(v10);
nwrite(v4, (__int64)v10, v11);
nwrite(v4, (__int64)"\n", 1uLL);
}
while ( a2 != v7 );
}
return 0LL;
}

original_code:
int callback(void* p_sock, int column_count, char** column_text, char** column_names){
 int sock = *(int*)p_sock;
 int i;
 for(i=0;i<column_count;i++){
  nwrite(sock,column_names[i],strlen(column_names[i]));
  nwrite(sock,"=",strlen("="));
  nwrite(sock,column_text[i],strlen(column_text[i]));
  nwrite(sock,"\n",strlen("\n"));
 }
 return 0;
}

canonical_original_code:
int callback(void *p_sock, int column_count, char **column_text, char **column_names){
 int sock = *(int*)p_sock;
 int i;
 for(i=0;i<column_count;i++){
  nwrite(sock,column_names[i],strlen(column_names[i]));
  nwrite(sock,"=",strlen("="));
  nwrite(sock,column_text[i],strlen(column_text[i]));
  nwrite(sock,"\n",strlen("\n"));
 }
 return 0;
}


decompiled_code:
__int64 __fastcall db_query(__int64 a1, __int64 a2)
{
__int64 result; // rax
const char *v3; // [rsp+8h] [rbp-10h] BYREF

v3 = 0LL;
result = sqlite3_exec(sqlite_db, a1, callback, a2, &v3);
if ( (_DWORD)result )
{
fprintf(stderr, "SQL error: %s\n", v3);
sqlite3_free(v3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 result; // rax
const char *v3; // [rsp+8h] [rbp-10h] BYREF

v3 = 0LL;
result = sqlite3_exec(sqlite_db, a1, callback, a2, &v3);
if ( (_DWORD)result )
{
fprintf(stderr, "SQL error: %s\n", v3);
sqlite3_free(v3);
result = 1LL;
}
return result;
}

original_code:
int db_query(char* query,int* p_sock){
 char* errMsg = ((void *)0);
 if ( sqlite3_exec(sqlite_db, query, callback, p_sock, &errMsg) != 0 ) {
  fprintf(stderr, "SQL error: %s\n", errMsg);
  sqlite3_free(errMsg);
  return 1;
 }
 return 0;
}

canonical_original_code:
int db_query(char *query, int *p_sock){
 char *errMsg = ((void *)0);
 if ( sqlite3_exec(sqlite_db, query, callback, p_sock, &errMsg) != 0 ) {
  fprintf(stderr, "SQL error: %s\n", errMsg);
  sqlite3_free(errMsg);
  return 1;
 }
 return 0;
}

variable_types:
query
char *

variable_types:
errMsg
char *


session

decompiled_code:
void *__fastcall session(void *a1)
{
int v1; // eax
pthread_t v2; // r12
size_t v3; // rax
char *v4; // r12
size_t v5; // rax
int v6; // er12
int fd; // [rsp+Ch] [rbp-ACh] BYREF
char s[168]; // [rsp+10h] [rbp-A8h] BYREF

v1 = *(_DWORD *)a1;
s[128] = 0;
fd = v1;
pthread_mutex_unlock(&lock);
v2 = pthread_self();
pthread_detach(v2);
snprintf(s, 0x80uLL, "Welcome to moonitor shell. Session thread id: %ld\n", v2);
v3 = strlen(s);
nwrite(fd, (__int64)s, v3);
do
{
while ( 1 )
{
v4 = ps;
v5 = strlen(ps);
v6 = nwrite(fd, (__int64)v4, v5);
read(fd, s, 0x80uLL);
if ( !memcmp(s, "plugins", 7uLL) )
break;
if ( s[0] == 4 || memcmp(s, "exit", 4uLL) || memcmp(s, "quit", 4uLL) )
{
nwrite(fd, (__int64)"bye\n", 5uLL);
if ( close(fd) )
goto LABEL_11;
return 0LL;
}
if ( v6 < 0 )
goto LABEL_8;
}
db_query((__int64)"SELECT id FROM plugin", (__int64)&fd);
}
while ( v6 >= 0 );
LABEL_8:
if ( !close(fd) )
return 0LL;
LABEL_11:
perror("error closing socket");
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func6(void *a1)
{
int v1; // eax
pthread_t v2; // r12
size_t v3; // rax
char *v4; // r12
size_t v5; // rax
int v6; // er12
int fd; // [rsp+Ch] [rbp-ACh] BYREF
char s[168]; // [rsp+10h] [rbp-A8h] BYREF

v1 = *(_DWORD *)a1;
s[128] = 0;
fd = v1;
pthread_mutex_unlock(&lock);
v2 = pthread_self();
pthread_detach(v2);
snprintf(s, 0x80uLL, "Welcome to moonitor shell. Session thread id: %ld\n", v2);
v3 = strlen(s);
func3(fd, (__int64)s, v3);
do
{
while ( 1 )
{
v4 = ps;
v5 = strlen(ps);
v6 = func3(fd, (__int64)v4, v5);
read(fd, s, 0x80uLL);
if ( !memcmp(s, "plugins", 7uLL) )
break;
if ( s[0] == 4 || memcmp(s, "exit", 4uLL) || memcmp(s, "quit", 4uLL) )
{
func3(fd, (__int64)"bye\n", 5uLL);
if ( close(fd) )
goto LABEL_11;
return 0LL;
}
if ( v6 < 0 )
goto LABEL_8;
}
func5((__int64)"SELECT id FROM plugin", (__int64)&fd);
}
while ( v6 >= 0 );
LABEL_8:
if ( !close(fd) )
return 0LL;
LABEL_11:
perror("error closing socket");
return 0LL;
}

original_code:
void* session(void* p_sock){
 char buf[128 +1];
 buf[128] = '\0';
 int consock = *(int*)p_sock;
 pthread_mutex_unlock(&lock);
 pthread_detach(pthread_self());
 snprintf(buf,128,"Welcome to moonitor shell. Session thread id: %ld\n",(long)pthread_self());
 nwrite(consock,buf,strlen(buf));
 int status=0;
 while(status>=0){
  status = nwrite(consock,ps,strlen(ps));
  read(consock,buf,128);
  if(strncmp(buf,"plugins",strlen("plugins")) == 0){
   db_query("SELECT id FROM plugin",&consock);
  }
  else if(buf[0] == 0x04
    || strncmp(buf,"exit",strlen("exit"))
    || strncmp(buf,"quit",strlen("quit"))
         )
  {
   nwrite(consock,"bye\n",5);
   break;
  }
 }
 if(close(consock) != 0){
  perror("error closing socket");
 }
 return 0;
}

canonical_original_code:
void *session(void *p_sock){
 char buf[-1];
 buf[128] = '\0';
 int consock = *(int*)p_sock;
 pthread_mutex_unlock(&lock);
 pthread_detach(pthread_self());
 snprintf(buf,128,"Welcome to moonitor shell. Session thread id: %ld\n",(long)pthread_self());
 nwrite(consock,buf,strlen(buf));
 int status = 0;
 while(status>=0){
  status = nwrite(consock,ps,strlen(ps));
  read(consock,buf,128);
  if(strncmp(buf,"plugins",strlen("plugins")) == 0){
   db_query("SELECT id FROM plugin",&consock);
  }
  else if(buf[0] == 0x04
    || strncmp(buf,"exit",strlen("exit"))
    || strncmp(buf,"quit",strlen("quit"))
         )
  {
   nwrite(consock,"bye\n",5);
   break;
  }
 }
 if(close(consock) != 0){
  perror("error closing socket");
 }
 return 0;
}

variable_types:
buf
char [-1]

variable_types: status int


decompiled_code:
__int64 sql_open()
{
__int64 result; // rax
const char *v1; // rax

result = sqlite3_open("node.db", &sqlite_db);
if ( (_DWORD)result )
{
v1 = (const char *)sqlite3_errmsg(sqlite_db);
fprintf(stderr, "Critical: Can't open database: %s\n", v1);
sqlite3_close(sqlite_db);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
const char *v1; // rax

result = sqlite3_open("node.db", &sqlite_db);
if ( (_DWORD)result )
{
v1 = (const char *)sqlite3_errmsg(sqlite_db);
fprintf(stderr, "Critical: Can't open database: %s\n", v1);
sqlite3_close(sqlite_db);
result = 1LL;
}
return result;
}

original_code:
int sql_open() {
   if ( sqlite3_open("node.db", &sqlite_db) ) {
      fprintf(stderr, "Critical: Can't open database: %s\n", sqlite3_errmsg(sqlite_db));
      sqlite3_close(sqlite_db);
      return 1;
   }
   return 0;
}


decompiled_code:
__int64 sql_close()
{
return sqlite3_close(sqlite_db);
}

canonical_decompiled_code:
__int64 func1()
{
return sqlite3_close(sqlite_db);
}

original_code:
void sql_close() {
   sqlite3_close(sqlite_db);
}


decompiled_code:
__int64 __fastcall sql_exec(__int64 a1)
{
__int64 result; // rax
const char *v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
result = sqlite3_exec(sqlite_db, a1, 0LL, 0LL, &v2);
if ( (_DWORD)result )
{
fprintf(stderr, "SQL error: %s\n", v2);
sqlite3_free(v2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
const char *v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
result = sqlite3_exec(sqlite_db, a1, 0LL, 0LL, &v2);
if ( (_DWORD)result )
{
fprintf(stderr, "SQL error: %s\n", v2);
sqlite3_free(v2);
result = 1LL;
}
return result;
}

original_code:
int sql_exec(char* sql) {
   char* errMsg = ((void *)0);
   if ( sqlite3_exec(sqlite_db, sql, ((void *)0), 0, &errMsg) != 0 ) {
      fprintf(stderr, "SQL error: %s\n", errMsg);
      sqlite3_free(errMsg);
      return 1;
   }
   return 0;
}

canonical_original_code:
int sql_exec(char *sql) {
   char *errMsg = ((void *)0);
   if ( sqlite3_exec(sqlite_db, sql, ((void *)0), 0, &errMsg) != 0 ) {
      fprintf(stderr, "SQL error: %s\n", errMsg);
      sqlite3_free(errMsg);
      return 1;
   }
   return 0;
}

variable_types:
sql
char *


decompiled_code:
__int64 sql_init()
{
int v0; // er8
__int64 result; // rax

v0 = sql_open();
result = 1LL;
if ( !v0 )
{
if ( (unsigned int)sql_exec((__int64)"CREATE TABLE IF NOT EXISTS plugin ( id VARCHAR(16), "
" category VARCHAR(32), title VARCHAR(64), "
" description VARCHAR(256), desc_x VARCHAR(64)"
", unit_x VARCHAR(8), desc_y VARCHAR(64)"
", unit_y VARCHAR(8), base_y INT DEFAULT"
" 1024, min_y INT DEFAULT 0, max_y INT D"
"EFAULT 0, PRIMARY KEY (id) )")
|| (result = sql_exec((__int64)"CREATE TABLE IF NOT EXISTS option ( id VARCHAR(16), "
" field VARCHAR(16), draw TINYINT DEFAULT 1, "
" type TINYINT DEFAULT 1, warn INT DEFAULT 0, "
" crit INT DEFAULT 0, PRIMARY KEY (id, field) )"),
(_DWORD)result) )
{
result = 2LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // er8
__int64 result; // rax

v0 = func0();
result = 1LL;
if ( !v0 )
{
if ( (unsigned int)func2((__int64)"CREATE TABLE IF NOT EXISTS plugin ( id VARCHAR(16), "
" category VARCHAR(32), title VARCHAR(64), "
" description VARCHAR(256), desc_x VARCHAR(64)"
", unit_x VARCHAR(8), desc_y VARCHAR(64)"
", unit_y VARCHAR(8), base_y INT DEFAULT"
" 1024, min_y INT DEFAULT 0, max_y INT D"
"EFAULT 0, PRIMARY KEY (id) )")
|| (result = func2((__int64)"CREATE TABLE IF NOT EXISTS option ( id VARCHAR(16), "
" field VARCHAR(16), draw TINYINT DEFAULT 1, "
" type TINYINT DEFAULT 1, warn INT DEFAULT 0, "
" crit INT DEFAULT 0, PRIMARY KEY (id, field) )"),
(_DWORD)result) )
{
result = 2LL;
}
}
return result;
}

original_code:
int sql_init() {
   if ( sql_open() != 0 ) {
      return 1;
   }
   if ( sql_exec("CREATE TABLE IF NOT EXISTS plugin (                     id VARCHAR(16),                     category VARCHAR(32),                     title VARCHAR(64),                     description VARCHAR(256),                     desc_x VARCHAR(64),                     unit_x VARCHAR(8),                     desc_y VARCHAR(64),                     unit_y VARCHAR(8),                     base_y INT DEFAULT 1024,                     min_y INT DEFAULT 0,                     max_y INT DEFAULT 0,                     PRIMARY KEY (id)                 )") != 0 ) {
      return 2;
   }
   if ( sql_exec("CREATE TABLE IF NOT EXISTS option (                     id VARCHAR(16),                     field VARCHAR(16),                     draw TINYINT DEFAULT 1,                     type TINYINT DEFAULT 1,                     warn INT DEFAULT 0,                     crit INT DEFAULT 0,                     PRIMARY KEY (id, field)                 )") != 0 ) {
      return 2;
   }
   return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
__int64 v4; // rcx
bool v5; // cf
bool v6; // zf
const char *v7; // rsi
int v8; // er12
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = "./daemon";
v4 = 9LL;
v5 = 0;
v6 = 0;
v7 = *argv;
do
{
if ( !v4 )
break;
v5 = *v7 < (unsigned int)*v3;
v6 = *v7++ == *v3++;
--v4;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
v8 = sql_init(v3, v7, envp);
if ( v8 )
{
v8 = 1;
}
else
{
pthread_create(newthread, 0LL, (void *(*)(void *))&listener_thread, 0LL);
collector_thread(0LL);
sql_close();
}
}
else
{
v8 = 2;
fwrite("Error: while development, daemon musst be called with \"./daemon\"\n", 1uLL, 0x41uLL, stderr);
}
return v8;
}

original_code:
int main(int argc, char* argv[]) {
   if ( strcmp(*argv, "./daemon") ) {
      fprintf(stderr, "Error: while development, daemon musst be called with \"./daemon\"\n");
      return 2;
   }
   if ( sql_init() != 0 ) {
      return 1;
   }
   pthread_t last_thread;
   pthread_create(&last_thread,((void *)0),listener_thread,((void *)0));
   collector_thread(((void *)0));
   sql_close();
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
   if ( strcmp(*argv, "./daemon") ) {
      fprintf(stderr, "Error: while development, daemon musst be called with \"./daemon\"\n");
      return 2;
   }
   if ( sql_init() != 0 ) {
      return 1;
   }
   unsigned long last_thread;
   pthread_create(&last_thread,((void *)0),listener_thread,((void *)0));
   collector_thread(((void *)0));
   sql_close();
   return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


init

decompiled_code:
const char *init()
{
return "CREATE TABLE IF NOT EXISTS cpu_avg ( time TIMESTAMP PRIMARY KEY DEFAULT CURRENT_TIMESTAMP, "
" avg1 INTEGER, avg5 INTEGER, avg15 INTEGER );";
}

canonical_decompiled_code:
const char *func6()
{
return "CREATE TABLE IF NOT EXISTS cpu_avg ( time TIMESTAMP PRIMARY KEY DEFAULT CURRENT_TIMESTAMP, "
" avg1 INTEGER, avg5 INTEGER, avg15 INTEGER );";
}

original_code:
char* init() {
   return "CREATE TABLE IF NOT EXISTS cpu_avg (             time  TIMESTAMP PRIMARY KEY DEFAULT CURRENT_TIMESTAMP,             avg1  INTEGER,             avg5  INTEGER,             avg15 INTEGER          );";
}

canonical_original_code:
char *init() {
   return "CREATE TABLE IF NOT EXISTS cpu_avg (             time  TIMESTAMP PRIMARY KEY DEFAULT CURRENT_TIMESTAMP,             avg1  INTEGER,             avg5  INTEGER,             avg15 INTEGER          );";
}


decompiled_code:
__int64 default_interval()
{
return 60LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 60LL;
}

original_code:
int default_interval() {
   return 60;
}

canonical_original_code:
int default_interval() {
   return 60;
}


decompiled_code:
void unload_plugins(void)
{
__int64 v0; // rbx
__int64 v1; // rbp
char v2[7]; // [rsp+0h] [rbp-38h] BYREF
__int16 v3; // [rsp+7h] [rbp-31h]

v0 = *(_QWORD *)plugins;
if ( *(_QWORD *)plugins )
{
v1 = 8LL;
do
{
dlclose(*(void **)(v0 + 16));
snprintf(v2, 0x1AuLL, "/moonit%p", *(const void **)(v0 + 24));
v3 = 29295;
sem_unlink(v2);
v0 = *(_QWORD *)(plugins + v1);
v1 += 8LL;
}
while ( v0 );
}
}

canonical_decompiled_code:
void func0(void)
{
__int64 v0; // rbx
__int64 v1; // rbp
char v2[7]; // [rsp+0h] [rbp-38h] BYREF
__int16 v3; // [rsp+7h] [rbp-31h]

v0 = *(_QWORD *)plugins;
if ( *(_QWORD *)plugins )
{
v1 = 8LL;
do
{
dlclose(*(void **)(v0 + 16));
snprintf(v2, 0x1AuLL, "/moonit%p", *(const void **)(v0 + 24));
v3 = 29295;
sem_unlink(v2);
v0 = *(_QWORD *)(plugins + v1);
v1 += 8LL;
}
while ( v0 );
}
}

original_code:
void unload_plugins(void) {
   int i;
   struct plugin* p;
   for ( i = 0; (p = plugins[i]) != ((void *)0); i++ ) {
      dlclose(p->handle);
      char str[sizeof(void*)*2+1];
      snprintf(str, (sizeof(void*)*2+10), "/moonit%p", p->cmd);
      *(str+7) = 'o';
      *(str+8) = 'r';
      sem_unlink(str);
   }
}

canonical_original_code:
void unload_plugins() {
   int i;
   struct plugin *p;
   for ( i = 0; (p = plugins[i]) != ((void *)0); i++ ) {
      dlclose(p->handle);
      char str[-1];
      snprintf(str, (sizeof(void *)*2+10), "/moonit%p", p->cmd);
      *(str+7) = 'o';
      *(str+8) = 'r';
      sem_unlink(str);
   }
}

variable_types: i int

variable_types: struct plugin { int interval; union sem_t { char __size[32]; long __align; } *lock; void *handle; char *(*cmd)(); } *

variable_types:
str
char [-1]

user_defined_types: struct plugin { int interval; union sem_t *lock; void *handle; char *(*cmd)(); }


decompiled_code:
void __noreturn collector_thread()
{
time_t *v0; // rax
time_t *v1; // r12
time_t v2; // rbx
unsigned int **v3; // rdi
unsigned int *v4; // rbp
__int64 v5; // rbx
int v6; // eax
__int64 v7; // rdi
time_t v8; // rax
time_t v9; // rax
time_t *v10; // rbx
void *v11; // r12

v0 = (time_t *)malloc(0x18uLL);
if ( v0 )
{
*v0 = 0LL;
v1 = v0;
v0[1] = 0LL;
v0[2] = 0LL;
load_plugins((__int64)v0);
while ( 1 )
{
v2 = *v1;
if ( v2 <= time(0LL) )
{
v3 = (unsigned int **)v1[1];
v4 = *v3;
if ( *v3 )
{
v5 = 1LL;
do
{
printf("running cmd %p, with interval %d\n", *((const void **)v4 + 3), *v4);
if ( sem_trywait(*((sem_t **)v4 + 1)) )
{
fprintf(stderr, "Error: runtime for %p is to short (%d)\n", *((const void **)v4 + 3), *v4);
v9 = time(0LL);
queue_add(v1, (__int64)v4, v9 + 1);
}
else
{
v6 = fork();
v7 = (unsigned int)v6;
if ( !v6 )
{
if ( !fork() )
{
v11 = (void *)(*((__int64 (__fastcall **)(__int64))v4 + 3))(v7);
sem_post(*((sem_t **)v4 + 1));
if ( v11 )
sql_exec(v11);
else
fprintf(stderr, "Error: Command %p failed\n", *((const void **)v4 + 3));
free(v11);
}
exit(0);
}
if ( v6 < 0 )
{
fprintf(stderr, "Error: could not fork child %p", *((const void **)v4 + 3));
sem_post(*((sem_t **)v4 + 1));
}
else
{
waitpid(v6, 0LL, 8);
}
v8 = time(0LL);
queue_add(v1, (__int64)v4, v8 + (int)*v4);
}
v3 = (unsigned int **)v1[1];
v4 = v3[v5++];
}
while ( v4 );
}
v10 = (time_t *)v1[2];
free(v3);
free(v1);
v1 = v10;
}
sleep(1u);
}
}
fwrite("Critical: not enough memory!", 1uLL, 0x1CuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
time_t *v0; // rax
time_t *v1; // r12
time_t v2; // rbx
unsigned int **v3; // rdi
unsigned int *v4; // rbp
__int64 v5; // rbx
int v6; // eax
__int64 v7; // rdi
time_t v8; // rax
time_t v9; // rax
time_t *v10; // rbx
void *v11; // r12

v0 = (time_t *)malloc(0x18uLL);
if ( v0 )
{
*v0 = 0LL;
v1 = v0;
v0[1] = 0LL;
v0[2] = 0LL;
func1((__int64)v0);
while ( 1 )
{
v2 = *v1;
if ( v2 <= time(0LL) )
{
v3 = (unsigned int **)v1[1];
v4 = *v3;
if ( *v3 )
{
v5 = 1LL;
do
{
printf("running cmd %p, with interval %d\n", *((const void **)v4 + 3), *v4);
if ( sem_trywait(*((sem_t **)v4 + 1)) )
{
fprintf(stderr, "Error: runtime for %p is to short (%d)\n", *((const void **)v4 + 3), *v4);
v9 = time(0LL);
queue_add(v1, (__int64)v4, v9 + 1);
}
else
{
v6 = fork();
v7 = (unsigned int)v6;
if ( !v6 )
{
if ( !fork() )
{
v11 = (void *)(*((__int64 (__fastcall **)(__int64))v4 + 3))(v7);
sem_post(*((sem_t **)v4 + 1));
if ( v11 )
sql_exec(v11);
else
fprintf(stderr, "Error: Command %p failed\n", *((const void **)v4 + 3));
free(v11);
}
exit(0);
}
if ( v6 < 0 )
{
fprintf(stderr, "Error: could not fork child %p", *((const void **)v4 + 3));
sem_post(*((sem_t **)v4 + 1));
}
else
{
waitpid(v6, 0LL, 8);
}
v8 = time(0LL);
queue_add(v1, (__int64)v4, v8 + (int)*v4);
}
v3 = (unsigned int **)v1[1];
v4 = v3[v5++];
}
while ( v4 );
}
v10 = (time_t *)v1[2];
free(v3);
free(v1);
v1 = v10;
}
sleep(1u);
}
}
fwrite("Critical: not enough memory!", 1uLL, 0x1CuLL, stderr);
exit(1);
}

original_code:
void* collector_thread(void* arg) {
   struct queue *que, *tmp;
   struct plugin* p;
   pid_t pid, cpid;
   int i;
   que = malloc(sizeof(struct queue));
   if ( que == ((void *)0) ) {
      fprintf(stderr, "Critical: not enough memory!");
      exit(1);
   }
   que->timestamp = 0;
   que->plugins = ((void *)0);
   que->next = ((void *)0);
   load_plugins(que);
   while ( 1 ) {
      if ( que->timestamp <= time(((void *)0)) ) {
         for ( i=0; (p = que->plugins[i]) != ((void *)0); i++ ) {
            printf("running cmd %p, with interval %d\n", p->cmd, p->interval);
            if ( sem_trywait(p->lock) == 0 ) {
               if ( (pid = fork()) == 0 ) {
                  if ( (cpid = fork()) == 0 ) {
                     char* ret = (p->cmd)();
                     sem_post(p->lock);
                     if ( ret == ((void *)0) ) {
                        fprintf(stderr, "Error: Command %p failed\n", p->cmd);
                     }
                     else {
                        sql_exec(ret);
                     }
                     free(ret);
                  }
                  else if ( pid < 0 ) {
                     fprintf(stderr, "Error: could not fork daemon %p", p->cmd);
                     sem_post(p->lock);
                     exit(1);
                  }
                  exit(0);
               }
               else if ( pid < 0 ) {
                  fprintf(stderr, "Error: could not fork child %p", p->cmd);
                  sem_post(p->lock);
               }
               else {
                  waitpid(pid, ((void *)0), 8);
               }
               queue_add(que, p, (time_t)(time(((void *)0))+p->interval));
            }
            else {
               fprintf(stderr, "Error: runtime for %p is to short (%d)\n", p->cmd, p->interval);
               queue_add(que, p, (time_t)(time(((void *)0))+1));
            }
         }
         tmp = que->next;
         free(que->plugins);
         free(que);
         que = tmp;
      }
      sleep(1);
   }
}

canonical_original_code:
void *collector_thread(void *arg) {
   struct queue *que; struct queue *tmp;
   struct plugin *p;
   int pid; int cpid;
   int i;
   que = malloc(sizeof(struct queue));
   if ( que == ((void *)0) ) {
      fprintf(stderr, "Critical: not enough memory!");
      exit(1);
   }
   que->timestamp = 0;
   que->plugins = ((void *)0);
   que->next = ((void *)0);
   load_plugins(que);
   while ( 1 ) {
      if ( que->timestamp <= time(((void *)0)) ) {
         for ( i=0; (p = que->plugins[i]) != ((void *)0); i++ ) {
            printf("running cmd %p, with interval %d\n", p->cmd, p->interval);
            if ( sem_trywait(p->lock) == 0 ) {
               if ( (pid = fork()) == 0 ) {
                  if ( (cpid = fork()) == 0 ) {
                     char *ret = (p->cmd)();
                     sem_post(p->lock);
                     if ( ret == ((void *)0) ) {
                        fprintf(stderr, "Error: Command %p failed\n", p->cmd);
                     }
                     else {
                        sql_exec(ret);
                     }
                     free(ret);
                  }
                  else if ( pid < 0 ) {
                     fprintf(stderr, "Error: could not fork daemon %p", p->cmd);
                     sem_post(p->lock);
                     exit(1);
                  }
                  exit(0);
               }
               else if ( pid < 0 ) {
                  fprintf(stderr, "Error: could not fork child %p", p->cmd);
                  sem_post(p->lock);
               }
               else {
                  waitpid(pid, ((void *)0), 8);
               }
               queue_add(que, p, (time_t)(time(((void *)0))+p->interval));
            }
            else {
               fprintf(stderr, "Error: runtime for %p is to short (%d)\n", p->cmd, p->interval);
               queue_add(que, p, (time_t)(time(((void *)0))+1));
            }
         }
         tmp = que->next;
         free(que->plugins);
         free(que);
         que = tmp;
      }
      sleep(1);
   }
}

variable_types:
arg
void *

variable_types: struct queue { long timestamp; struct plugin { int interval; union sem_t { char __size[32]; long __align; } *lock; void *handle; char *(*cmd)(); } **plugins; struct queue *next; } *

variable_types: pid int

variable_types: cpid int

variable_types:
ret
char *

user_defined_types: struct queue { long timestamp; struct plugin **plugins; struct queue *next; }


main

repo: oasynnoum/c-linked-list

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

v3 = (void *)init_state_storage(argc, argv, envp);
store_state_to_first(v3, L"321");
store_state_to_first(v3, 4202514LL);
store_state_to_first(v3, 4202516LL);
destroy_state_storage(v3);
return 0;
}

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

v3 = (void *)func7(argc, argv, envp);
store_state_to_first(v3, L"321");
store_state_to_first(v3, 4202514LL);
store_state_to_first(v3, 4202516LL);
func8(v3);
return 0;
}

original_code:
int main (int argc, char* argv[]) {
    state_storage* storage = init_state_storage();
    store_state_to_first(storage, "3");
    store_state_to_first(storage, "2");
    store_state_to_first(storage, "1");
    destroy_state_storage(storage);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    struct _state_storage *storage = init_state_storage();
    store_state_to_first(storage, "3");
    store_state_to_first(storage, "2");
    store_state_to_first(storage, "1");
    destroy_state_storage(storage);
    return 0;
}

variable_types: struct _state_storage { struct _state_element { char *state; struct _state_element *next; } *first; } *

user_defined_types: struct _state_storage { struct _state_element *first; }


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

result = malloc(8uLL);
*result = 0LL;
return result;
}

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

result = malloc(8uLL);
*result = 0LL;
return result;
}

original_code:
state_storage* init_state_storage() {
    state_storage* storage = (state_storage*)malloc(sizeof (state_storage));
    storage->first = ((void *)0);
    return storage;
}

canonical_original_code:
struct _state_storage *init_state_storage() {
    struct _state_storage *storage = (state_storage*)malloc(sizeof (state_storage));
    storage->first = ((void *)0);
    return storage;
}

return_type: struct _state_storage { struct _state_element { char *state; struct _state_element *next; } *first; } *


decompiled_code:
void __fastcall destroy_state_storage(void *ptr)
{
const char **v2; // rbx
const char **v3; // rdi

v2 = *(const char ***)ptr;
if ( *(_QWORD *)ptr )
{
do
{
printf("current:%s\n", *v2);
v3 = v2;
v2 = (const char **)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
const char **v2; // rbx
const char **v3; // rdi

v2 = *(const char ***)ptr;
if ( *(_QWORD *)ptr )
{
do
{
printf("current:%s\n", *v2);
v3 = v2;
v2 = (const char **)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void destroy_state_storage(state_storage* storage) {
    state_element* current_element = storage->first;
    while (current_element) {
        printf("current:%s\n", current_element->state);
        state_element* next = current_element->next;
        free(current_element);
        current_element = next;
    }
    free(storage);
}

canonical_original_code:
void destroy_state_storage(struct _state_storage *storage) {
    struct _state_element *current_element = storage->first;
    while (current_element) {
        printf("current:%s\n", current_element->state);
        struct _state_element *next = current_element->next;
        free(current_element);
        current_element = next;
    }
    free(storage);
}

variable_types: struct _state_element { char *state; struct _state_element *next; } *


repo: ob/cache

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
void *v4; // r12
int v5; // eax
int result; // eax
__int64 v7; // rsi

v4 = &unk_8000000;
while ( 1 )
{
v5 = getopt_long(argc, (char *const *)argv, shortopts, &longopts, 0LL);
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'r':
v3 = 0;
break;
case 's':
v3 = 1;
break;
case 'b':
v4 = (void *)((unsigned __int64)strtol(optarg, 0LL, 10) >> 3);
break;
default:
fprintf(stderr, "usage: %s (--random|--sequential) [--buffer <size>]\n", *argv);
return 1;
}
}
if ( (unsigned int)v4 <= 0x7F )
{
fprintf(stderr, off_402080, *argv, 1024LL);
result = 1;
}
else if ( (unsigned int)v4 > (unsigned int)&unk_8000000 )
{
fprintf(stderr, off_4020A8, *argv, &unk_40000000);
result = 1;
}
else
{
v7 = 8LL * (unsigned int)v4;
if ( v3 == 1 )
{
printf("# doing sequential access with a max buffer of %ld\n", v7);
sequential_access((unsigned int)v4);
}
else
{
printf("# doing random access with a max buffer of %ld\n", v7);
random_access((unsigned int)v4);
}
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
void *v4; // r12
int v5; // eax
int result; // eax
__int64 v7; // rsi

v4 = &unk_8000000;
while ( 1 )
{
v5 = getopt_long(argc, (char *const *)argv, shortopts, &longopts, 0LL);
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'r':
v3 = 0;
break;
case 's':
v3 = 1;
break;
case 'b':
v4 = (void *)((unsigned __int64)strtol(optarg, 0LL, 10) >> 3);
break;
default:
fprintf(stderr, "usage: %s (--random|--sequential) [--buffer <size>]\n", *argv);
return 1;
}
}
if ( (unsigned int)v4 <= 0x7F )
{
fprintf(stderr, off_402080, *argv, 1024LL);
result = 1;
}
else if ( (unsigned int)v4 > (unsigned int)&unk_8000000 )
{
fprintf(stderr, off_4020A8, *argv, &unk_40000000);
result = 1;
}
else
{
v7 = 8LL * (unsigned int)v4;
if ( v3 == 1 )
{
printf("# doing sequential access with a max buffer of %ld\n", v7);
func11((unsigned int)v4);
}
else
{
printf("# doing random access with a max buffer of %ld\n", v7);
func10((unsigned int)v4);
}
result = 0;
}
return result;
}

original_code:
int
main(int ac, char **av)
{
    int c;
    u32 cache_size;
    access_kind kind;
    cache_size = ((1024 * 1024 * 1024) / sizeof(u32*));
    while ((c = getopt_long(ac, av, "rsc:", longopts, ((void *)0))) != -1) {
 switch (c) {
 case 'r':
     kind = rand_access;
     break;
 case 's':
     kind = seq_access;
     break;
 case 'b':
     cache_size = strtol(optarg, 0, 10) / sizeof(u32*);
     break;
 default:
usage: fprintf(stderr, "usage: %s (--random|--sequential) "
      "[--buffer <size>]\n", av[0]);
     return (1);
     break;
 }
    }
    if (cache_size < (1024 / sizeof(u32*))) {
 fprintf(stderr, "%s: buffer needs to be at least %ld\n",
  av[0], (1024 / sizeof(u32*)) * sizeof(u32*));
 return (1);
    }
    if (cache_size > ((1024 * 1024 * 1024) / sizeof(u32*))) {
 fprintf(stderr, "%s: buffer needs to be less than %ld\n",
  av[0], ((1024 * 1024 * 1024) / sizeof(u32*)) * sizeof(u32*));
 return (1);
    }
    switch (kind) {
    case rand_access:
 printf("# doing random access with a max buffer of %ld\n",
        cache_size * sizeof(u32*));
 random_access(cache_size);
 break;
    case seq_access:
 printf("# doing sequential access with a max buffer of %ld\n",
        cache_size * sizeof(u32*));
 sequential_access(cache_size);
 break;
    default:
 goto usage;
 break;
    }
    return (0);
}

canonical_original_code:
int main(int ac, char **av)
{
    int c;
    unsigned int cache_size;
    enum access_kind kind;
    cache_size = ((1024 * 1024 * 1024) / sizeof(unsigned int *));
    while ((c = getopt_long(ac, av, "rsc:", longopts, ((void *)0))) != -1) {
 switch (c) {
 case 'r':
     kind = rand_access;
     break;
 case 's':
     kind = seq_access;
     break;
 case 'b':
     cache_size = strtol(optarg, 0, 10) / sizeof(unsigned int *);
     break;
 default:
usage: fprintf(stderr, "usage: %s (--random|--sequential) "
      "[--buffer <size>]\n", av[0]);
     return (1);
     break;
 }
    }
    if (cache_size < (1024 / sizeof(unsigned int *))) {
 fprintf(stderr, "%s: buffer needs to be at least %ld\n",
  av[0], (1024 / sizeof(unsigned int *)) * sizeof(unsigned int *));
 return (1);
    }
    if (cache_size > ((1024 * 1024 * 1024) / sizeof(unsigned int *))) {
 fprintf(stderr, "%s: buffer needs to be less than %ld\n",
  av[0], ((1024 * 1024 * 1024) / sizeof(unsigned int *)) * sizeof(unsigned int *));
 return (1);
    }
    switch (kind) {
    case rand_access:
 printf("# doing random access with a max buffer of %ld\n",
        cache_size * sizeof(unsigned int *));
 random_access(cache_size);
 break;
    case seq_access:
 printf("# doing sequential access with a max buffer of %ld\n",
        cache_size * sizeof(unsigned int *));
 sequential_access(cache_size);
 break;
    default:
 goto usage;
 break;
    }
    return (0);
}

variable_types: ac int

variable_types:
av
char **

variable_types: c int

variable_types: enum access_kind { rand_access=0, seq_access=1 }


timestamp

decompiled_code:
double timestamp()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
double func7()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

original_code:
double
timestamp(void)
{
    struct timeval tv;
    gettimeofday(&tv, 0);
    return (tv.tv_sec + (tv.tv_usec/1000000.0));
}

canonical_original_code:
double timestamp()
{
    struct timeval tv;
    gettimeofday(&tv, 0);
    return (tv.tv_sec + (tv.tv_usec/1000000.0));
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: double


shuffle

original_code:
u32 **
shuffle(u32 **buffer, u32 stride, u32 max)
{
    u32 i, j, r, n, tmp;
    static int *indices = ((void *)0);
    if (indices == ((void *)0)) {
 indices = calloc(((1024 * 1024 * 1024) / sizeof(u32*)), sizeof(int));
 if (indices == ((void *)0)) {
     printf("not enough memory\n");
     exit(1);
 }
    } else {
 bzero(indices, ((1024 * 1024 * 1024) / sizeof(u32*)));
    }
    for (i = 1, j = 0; i <= max; i+=stride, j++) indices[j] = i;
     n = j;
     while (n > 1) {
  n--;
  r = random() % n;
  tmp = indices[r];
  indices[r] = indices[n];
  indices[n] = tmp;
     }
     for (i = 0; i < j-1; i++) {
  buffer[indices[i]] = (u32 *)&buffer[indices[i+1]];
     }
     buffer[indices[i]] = ((void *)0);
     return (&buffer[indices[0]]);
}

canonical_original_code:
unsigned int **shuffle(unsigned int **buffer, unsigned int stride, unsigned int max)
{
    unsigned int i; unsigned int j; unsigned int r; unsigned int n; unsigned int tmp;
    static int *indices = ((void *)0);
    if (indices == ((void *)0)) {
 indices = calloc(((1024 * 1024 * 1024) / sizeof(unsigned int *)), sizeof(int));
 if (indices == ((void *)0)) {
     printf("not enough memory\n");
     exit(1);
 }
    } else {
 bzero(indices, ((1024 * 1024 * 1024) / sizeof(unsigned int *)));
    }
    for (i = 1, j = 0; i <= max; i+=stride, j++) indices[j] = i;
     n = j;
     while (n > 1) {
  n--;
  r = random() % n;
  tmp = indices[r];
  indices[r] = indices[n];
  indices[n] = tmp;
     }
     for (i = 0; i < j-1; i++) {
  buffer[indices[i]] = (unsigned int *)&buffer[indices[i+1]];
     }
     buffer[indices[i]] = ((void *)0);
     return (&buffer[indices[0]]);
}

variable_types:
buffer
unsigned int **

variable_types:
stride
unsigned int

variable_types:
max
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
r
unsigned int

variable_types:
n
unsigned int

variable_types:
tmp
unsigned int

variable_types:
indices
int *

return_type: unsigned int **


linear

decompiled_code:
__int64 __fastcall linear(__int64 a1, int a2, unsigned int a3)
{
__int64 v3; // r9
unsigned int v4; // eax
unsigned int i; // edx
__int64 v6; // r8
__int64 v7; // rcx

v3 = a3;
v4 = a2 + 1;
for ( i = 1; (unsigned int)v3 >= v4; *(_QWORD *)(a1 + 8 * v7) = a1 + 8 * v6 )
{
v6 = v4;
v7 = i;
v4 += a2;
i += a2;
}
*(_QWORD *)(a1 + 8 * v3) = 0LL;
return a1 + 8;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, unsigned int a3)
{
__int64 v3; // r9
unsigned int v4; // eax
unsigned int i; // edx
__int64 v6; // r8
__int64 v7; // rcx

v3 = a3;
v4 = a2 + 1;
for ( i = 1; (unsigned int)v3 >= v4; *(_QWORD *)(a1 + 8 * v7) = a1 + 8 * v6 )
{
v6 = v4;
v7 = i;
v4 += a2;
i += a2;
}
*(_QWORD *)(a1 + 8 * v3) = 0LL;
return a1 + 8;
}

original_code:
u32 **
linear(u32 **buffer, u32 stride, u32 max)
{
    u32 i, last;
    last = 1;
    for (i = stride + 1; i <= max; i += stride) {
 buffer[last] = (u32 *)&buffer[i];
 last = i;
    }
    buffer[max] = 0;
    return (&buffer[1]);
}

canonical_original_code:
unsigned int **linear(unsigned int **buffer, unsigned int stride, unsigned int max)
{
    unsigned int i; unsigned int last;
    last = 1;
    for (i = stride + 1; i <= max; i += stride) {
 buffer[last] = (unsigned int *)&buffer[i];
 last = i;
    }
    buffer[max] = 0;
    return (&buffer[1]);
}

variable_types:
last
unsigned int


decompiled_code:
void __fastcall random_access(unsigned int a1)
{
unsigned int i; // er14
unsigned int v2; // er13
int v3; // ebp
int v4; // ebx
__int64 v5; // r12
double v6; // xmm0_8
int v7; // edx
_QWORD *v8; // rax
__int64 v9; // rsi
unsigned int v10; // eax
double v11; // [rsp+0h] [rbp-58h]

if ( a1 > 0x7F )
{
for ( i = 128; i <= a1; i *= 2 )
{
if ( i >> 1 )
{
v2 = 1;
do
{
v3 = 0;
v4 = 10 * v2;
v5 = shuffle((__int64)&buffer, v2, i - v2 + 1);
v11 = 0.0;
do
{
v6 = timestamp();
v7 = 10 * v2;
if ( v4 )
{
do
{
v8 = (_QWORD *)v5;
if ( v5 )
{
do
v8 = (_QWORD *)*v8;
while ( v8 );
}
--v7;
}
while ( v7 );
}
++v3;
v11 = timestamp() - v6 + v11;
}
while ( v11 < 1.0 );
v9 = 8LL * v2;
v10 = (i - v2) / v2;
v2 *= 2;
printf(off_402016, v9, 8LL * i, 1000000000.0 * v11 / (double)(int)(v3 * v4 * (v10 + 1)));
fflush(_bss_start);
}
while ( v2 <= i >> 1 );
}
puts("\n");
fflush(_bss_start);
}
}
}

original_code:
void
random_access(u32 cache_max)
{
    u32 register i, stride;
    u32 steps, csize, limit;
    double sec0, sec;
    u32 register **start, **p;
    for (csize=(1024 / sizeof(u32*)); csize <= cache_max; csize*=2) {
 for (stride=1; stride <= csize/2; stride=stride*2) {
     sec = 0.0;
     limit = csize - stride + 1;
     steps = 0;
     start = shuffle(buffer, stride, limit);
     do {
  sec0 = timestamp();
  for (i=10*stride; i > 0; i--)
      for (p = start; p; p = (u32 **)*p) ;
  steps++;
  sec += timestamp() - sec0;
     } while (sec < 1.0);
     printf("%lu\t%lu\t%.1lf\n",
     stride * sizeof(u32*),
     csize * sizeof(u32*),
     sec*1e9/(steps*10*stride*((limit-1)/stride+1)));
     fflush(stdout);
 }
 printf("\n\n");
 fflush(stdout);
    }
}

canonical_original_code:
void random_access(unsigned int cache_max)
{
    register unsigned int i; register unsigned int stride;
    unsigned int steps; unsigned int csize; unsigned int limit;
    double sec0; double sec;
    register unsigned int **start; register unsigned int **p;
    for (csize=(1024 / sizeof(unsigned int *)); csize <= cache_max; csize*=2) {
 for (stride=1; stride <= csize/2; stride=stride*2) {
     sec = 0.0;
     limit = csize - stride + 1;
     steps = 0;
     start = shuffle(buffer, stride, limit);
     do {
  sec0 = timestamp();
  for (i=10*stride; i > 0; i--)
      for (p = start; p; p = (unsigned int **)*p) ;
  steps++;
  sec += timestamp() - sec0;
     } while (sec < 1.0);
     printf("%lu\t%lu\t%.1lf\n",
     stride * sizeof(unsigned int *),
     csize * sizeof(unsigned int *),
     sec*1e9/(steps*10*stride*((limit-1)/stride+1)));
     fflush(stdout);
 }
 printf("\n\n");
 fflush(stdout);
    }
}

variable_types:
steps
unsigned int

variable_types:
csize
unsigned int

variable_types:
limit
unsigned int

variable_types: sec double

variable_types:
start
unsigned int **

variable_types:
p
unsigned int **


decompiled_code:
void __fastcall sequential_access(unsigned int a1)
{
unsigned int i; // er14
unsigned int v2; // er13
int v3; // ebp
int v4; // ebx
__int64 v5; // rax
double v6; // xmm5_8
_QWORD *v7; // r12
double v8; // xmm0_8
int v9; // edx
_QWORD *j; // rax
__int64 v11; // rsi
unsigned int v12; // eax
double v13; // [rsp+0h] [rbp-58h]

if ( a1 > 0x7F )
{
for ( i = 128; i <= a1; i *= 2 )
{
if ( i >> 1 )
{
v2 = 1;
do
{
v3 = 0;
v4 = 10 * v2;
v5 = linear((__int64)&buffer, v2, i - v2 + 1);
v13 = v6;
v7 = (_QWORD *)v5;
do
{
v8 = timestamp();
v9 = 10 * v2;
if ( v4 )
{
do
{
for ( j = v7; j; j = (_QWORD *)*j )
;
--v9;
}
while ( v9 );
}
++v3;
v13 = timestamp() - v8 + v13;
}
while ( v13 < 1.0 );
v11 = 8LL * v2;
v12 = (i - v2) / v2;
v2 *= 2;
printf(off_402016, v11, 8LL * i, 1000000000.0 * v13 / (double)(int)(v3 * v4 * (v12 + 1)));
fflush(_bss_start);
}
while ( v2 <= i >> 1 );
}
puts("\n");
fflush(_bss_start);
}
}
}

original_code:
void
sequential_access(u32 cache_max)
{
    u32 i, stride;
    u32 steps, csize, limit;
    double sec0, sec;
    u32 **start;
    register u32 **p;
    for (csize=(1024 / sizeof(u32*)); csize <= cache_max; csize*=2) {
 for (stride=1; stride <= csize/2; stride=stride*2) {
     sec = 0.0;
     limit = csize - stride + 1;
     steps = 0;
     start = linear(buffer, stride, limit);
     do {
  sec0 = timestamp();
  for (i=10*stride; i > 0; i--)
      for (p = start; p; p = (u32 **)*p) ;
  steps++;
  sec += timestamp() - sec0;
     } while (sec < 1.0);
     printf("%lu\t%lu\t%.1lf\n",
     stride * sizeof(u32*),
     csize * sizeof(u32*),
     sec*1e9/(steps*10*stride*((limit-1)/stride+1)));
     fflush(stdout);
 }
 printf("\n\n");
 fflush(stdout);
    }
}

canonical_original_code:
void sequential_access(unsigned int cache_max)
{
    unsigned int i; unsigned int stride;
    unsigned int steps; unsigned int csize; unsigned int limit;
    double sec0; double sec;
    unsigned int **start;
    register unsigned int **p;
    for (csize=(1024 / sizeof(unsigned int *)); csize <= cache_max; csize*=2) {
 for (stride=1; stride <= csize/2; stride=stride*2) {
     sec = 0.0;
     limit = csize - stride + 1;
     steps = 0;
     start = linear(buffer, stride, limit);
     do {
  sec0 = timestamp();
  for (i=10*stride; i > 0; i--)
      for (p = start; p; p = (unsigned int **)*p) ;
  steps++;
  sec += timestamp() - sec0;
     } while (sec < 1.0);
     printf("%lu\t%lu\t%.1lf\n",
     stride * sizeof(unsigned int *),
     csize * sizeof(unsigned int *),
     sec*1e9/(steps*10*stride*((limit-1)/stride+1)));
     fflush(stdout);
 }
 printf("\n\n");
 fflush(stdout);
    }
}


BcTestMode

decompiled_code:
_BOOL8 BcTestMode()
{
return *barnyard2_conf == 4;
}

canonical_decompiled_code:
_BOOL8 func0()
{
return *barnyard2_conf == 4;
}

original_code:
static inline int BcTestMode(void)
{
    return barnyard2_conf->run_mode == RUN_MODE__TEST;
}

canonical_original_code:
static inline int BcTestMode()
{
    return barnyard2_conf->run_mode == RUN_MODE__TEST;
}


BcLogVerbose

decompiled_code:
__int64 BcLogVerbose()
{
return *(_DWORD *)(barnyard2_conf + 16LL) & 1;
}

canonical_decompiled_code:
__int64 func1()
{
return *(_DWORD *)(barnyard2_conf + 16LL) & 1;
}

original_code:
static inline int BcLogVerbose(void)
{
    return barnyard2_conf->logging_flags & LOGGING_FLAG__VERBOSE;
}

canonical_original_code:
static inline int BcLogVerbose()
{
    return barnyard2_conf->logging_flags & LOGGING_FLAG__VERBOSE;
}


BcLogQuiet

decompiled_code:
__int64 BcLogQuiet()
{
return *(_DWORD *)(barnyard2_conf + 16LL) & 2;
}

canonical_decompiled_code:
__int64 func2()
{
return *(_DWORD *)(barnyard2_conf + 16LL) & 2;
}

original_code:
static inline int BcLogQuiet(void)
{
    return barnyard2_conf->logging_flags & LOGGING_FLAG__QUIET;
}

canonical_original_code:
static inline int BcLogQuiet()
{
    return barnyard2_conf->logging_flags & LOGGING_FLAG__QUIET;
}


BcOutputUseUtc

decompiled_code:
__int64 BcOutputUseUtc()
{
return *(_DWORD *)(barnyard2_conf + 12LL) & 0x40;
}

canonical_decompiled_code:
__int64 func3()
{
return *(_DWORD *)(barnyard2_conf + 12LL) & 0x40;
}

original_code:
static inline int BcOutputUseUtc(void)
{
    return barnyard2_conf->output_flags & OUTPUT_FLAG__USE_UTC;
}

canonical_original_code:
static inline int BcOutputUseUtc()
{
    return barnyard2_conf->output_flags & OUTPUT_FLAG__USE_UTC;
}


Sguil

decompiled_code:
void Sguil()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void Sguil(Packet *p, void *event, uint32_t event_type, void *arg)
{
}

canonical_original_code:
void Sguil(struct _Packet *p, void *event, unsigned int event_type, void *arg)
{
}

variable_types: struct _Packet { struct pcap_pkthdr { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int caplen; unsigned int len; } *pkth; unsigned char *pkt; struct _EtherARP { struct _ARPHdr { unsigned short ar_hrd; unsigned short ar_pro; unsigned char ar_hln; unsigned char ar_pln; unsigned short ar_op; } ea_hdr; unsigned char arp_sha[6]; unsigned char arp_spa[4]; unsigned char arp_tha[6]; unsigned char arp_tpa[4]; } *ah; struct _EtherHdr { unsigned char ether_dst[6]; unsigned char ether_src[6]; unsigned short ether_type; } *eh; struct _VlanTagHdr { unsigned short vth_pri_cfi_vlan; unsigned short vth_proto; } *vh; struct _EthLlc { unsigned char dsap; unsigned char ssap; } *ehllc; struct _EthLlcOther { unsigned char ctrl; unsigned char org_code[3]; unsigned short proto_id; } *ehllcother; struct _GREHdr { unsigned char flags; unsigned char version; unsigned short ether_type; } *greh; unsigned int *mpls; struct _IPHdr { unsigned char ip_verhl; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_proto; unsigned short ip_csum; struct in_addr { unsigned int s_addr; } ip_src; struct in_addr ip_dst; } *iph; struct _IPHdr *inner_iph; struct _IPHdr *outer_iph; struct _TCPHdr { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_offx2; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; } *tcph; struct _UDPHdr { unsigned short uh_sport; unsigned short uh_dport; unsigned short uh_len; unsigned short uh_chk; } *udph; struct _ICMPHdr { unsigned char type; unsigned char code; unsigned short csum; union { unsigned char pptr; struct in_addr gwaddr; struct idseq { unsigned short id; unsigned short seq; } idseq; int sih_void; struct pmtu { unsigned short ipm_void; unsigned short nextmtu; } pmtu; struct rtradv { unsigned char num_addrs; unsigned char wpa; unsigned short lifetime; } rtradv; } icmp_hun; union { struct ts { unsigned int otime; unsigned int rtime; unsigned int ttime; } ts; struct ih_ip { struct _IPHdr *ip; } ip; struct ra_addr { unsigned int addr; unsigned int preference; } radv; unsigned int mask; char data[1]; } icmp_dun; } *icmph; unsigned char *data; unsigned char *ip_data; unsigned char *outer_ip_data; unsigned char *ip_frag_start; unsigned char *ip_options_data; unsigned char *tcp_options_data; void *ssnptr; void *fragtracker; void *flow; void *streamptr; struct _IPv4Hdr { unsigned char ip_verhl; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_proto; unsigned short ip_csum; struct _ip { int family; int bits; union { unsigned int u6_addr8[16]; unsigned int u6_addr16[8]; unsigned int u6_addr32[4]; } ip; } ip_src; struct _ip ip_dst; } *ip4h; struct _IPv6Hdr { unsigned int vcl; unsigned short len; unsigned char next; unsigned char hop_lmt; struct _ip ip_src; struct _ip ip_dst; } *ip6h; struct _ICMP6 { unsigned char type; unsigned char code; unsigned short csum; } *icmp6h; struct _IPH_API { struct _ip *(*iph_ret_src)(struct _Packet *); struct _ip *(*iph_ret_dst)(struct _Packet *); unsigned short (*iph_ret_tos)(struct _Packet *); unsigned char (*iph_ret_ttl)(struct _Packet *); unsigned short (*iph_ret_len)(struct _Packet *); unsigned int (*iph_ret_id)(struct _Packet *); unsigned char (*iph_ret_proto)(struct _Packet *); unsigned short (*iph_ret_off)(struct _Packet *); unsigned char (*iph_ret_ver)(struct _Packet *); unsigned char (*iph_ret_hlen)(struct _Packet *); struct _ip *(*orig_iph_ret_src)(struct _Packet *); struct _ip *(*orig_iph_ret_dst)(struct _Packet *); unsigned short (*orig_iph_ret_tos)(struct _Packet *); unsigned char (*orig_iph_ret_ttl)(struct _Packet *); unsigned short (*orig_iph_ret_len)(struct _Packet *); unsigned int (*orig_iph_ret_id)(struct _Packet *); unsigned char (*orig_iph_ret_proto)(struct _Packet *); unsigned short (*orig_iph_ret_off)(struct _Packet *); unsigned char (*orig_iph_ret_ver)(struct _Packet *); unsigned char (*orig_iph_ret_hlen)(struct _Packet *); char ver; } *iph_api; struct _IPH_API *orig_iph_api; struct _IPH_API *outer_iph_api; struct _IPH_API *outer_orig_iph_api; struct _IPv4Hdr inner_ip4h; struct _IPv6Hdr inner_ip6h; struct _IPv4Hdr outer_ip4h; struct _IPv6Hdr outer_ip6h; struct _MplsHdr { unsigned int label; unsigned char exp; unsigned char bos; unsigned char ttl; } mplsHdr; int family; int orig_family; int outer_family; int bytes_to_inspect; unsigned int preprocessor_bits; unsigned int preproc_reassembly_pkt_bits; unsigned int caplen; unsigned int http_pipeline_count; unsigned int packet_flags; unsigned int proto_bits; unsigned short dsize; unsigned short ip_dsize; unsigned short alt_dsize; unsigned short actual_ip_len; unsigned short outer_ip_dsize; unsigned short frag_offset; unsigned short ip_frag_len; unsigned short ip_options_len; unsigned short tcp_options_len; unsigned short sp; unsigned short dp; unsigned short orig_sp; unsigned short orig_dp; short application_protocol_ordinal; unsigned char frag_flag; unsigned char mf; unsigned char df; unsigned char rf; unsigned char uri_count; unsigned char csum_flags; unsigned char encapsulated; unsigned char ip_option_count; unsigned char tcp_option_count; unsigned char ip6_extension_count; unsigned char ip6_frag_index; unsigned char ip_lastopt_bad; unsigned char tcp_lastopt_bad; struct _Fddi_hdr { unsigned char fc; unsigned char daddr[6]; unsigned char saddr[6]; } *fddihdr; struct _Fddi_llc_saps { unsigned char dsap; unsigned char ssap; } *fddisaps; struct _Fddi_llc_sna { unsigned char ctrl_fld[2]; } *fddisna; struct _Fddi_llc_iparp { unsigned char ctrl_fld; unsigned char protid[3]; unsigned short ethertype; } *fddiiparp; struct _Fddi_llc_other { unsigned char ctrl_fld[1]; } *fddiother; struct _Trh_hdr { unsigned char ac; unsigned char fc; unsigned char daddr[6]; unsigned char saddr[6]; } *trh; struct _Trh_llc { unsigned char dsap; unsigned char ssap; unsigned char protid[3]; unsigned short ethertype; } *trhllc; struct _Trh_mr { unsigned short bcast_len_dir_lf_res; unsigned short rseg[8]; } *trhmr; struct _Pflog1_hdr { unsigned int af; char intf[16]; short rule; unsigned short reason; unsigned short action; unsigned short dir; } *pf1h; struct _Pflog2_hdr { char length; unsigned char af; unsigned char action; unsigned char reason; char ifname[16]; char ruleset[16]; unsigned int rulenr; unsigned int subrulenr; unsigned char dir; unsigned char pad[3]; } *pf2h; struct _Pflog3_hdr { char length; unsigned char af; unsigned char action; unsigned char reason; char ifname[16]; char ruleset[16]; unsigned int rulenr; unsigned int subrulenr; unsigned int uid; unsigned int pid; unsigned int rule_uid; unsigned int rule_pid; unsigned char dir; unsigned char pad[3]; } *pf3h; struct _SLLHdr { unsigned short sll_pkttype; unsigned short sll_hatype; unsigned short sll_halen; unsigned char sll_addr[8]; unsigned short sll_protocol; } *sllh; struct _WifiHdr { unsigned short frame_control; unsigned short duration_id; unsigned char addr1[6]; unsigned char addr2[6]; unsigned char addr3[6]; unsigned short seq_control; unsigned char addr4[6]; } *wifih; struct _PPPoEHdr { struct _EtherHdr ethhdr; unsigned char ver_type; unsigned char code; unsigned short session; unsigned short length; } *pppoeh; struct _EtherEapol { unsigned char version; unsigned char eaptype; unsigned short len; } *eplh; struct _EAPHdr { unsigned char code; unsigned char id; unsigned short len; } *eaph; unsigned char *eaptype; struct _EapolKey { unsigned char type; unsigned char length[2]; unsigned char counter[8]; unsigned char iv[16]; unsigned char index; unsigned char sig[16]; } *eapolk; struct _Options { unsigned char code; unsigned char len; unsigned char *data; } ip_options[40]; struct _Options tcp_options[40]; struct _IP6Option { unsigned char type; unsigned char *data; } ip6_extensions[40]; unsigned short configPolicyId; int linktype; } *

variable_types:
event
void *

variable_types:
arg
void *

user_defined_types: struct _Packet { struct pcap_pkthdr *pkth; unsigned char *pkt; struct _EtherARP *ah; struct _EtherHdr *eh; struct _VlanTagHdr *vh; struct _EthLlc *ehllc; struct _EthLlcOther *ehllcother; struct _GREHdr *greh; unsigned int *mpls; struct _IPHdr *iph; struct _IPHdr *inner_iph; struct _IPHdr *outer_iph; struct _TCPHdr *tcph; struct _UDPHdr *udph; struct _ICMPHdr *icmph; unsigned char *data; unsigned char *ip_data; unsigned char *outer_ip_data; unsigned char *ip_frag_start; unsigned char *ip_options_data; unsigned char *tcp_options_data; void *ssnptr; void *fragtracker; void *flow; void *streamptr; struct _IPv4Hdr *ip4h; struct _IPv6Hdr *ip6h; struct _ICMP6 *icmp6h; struct _IPH_API *iph_api; struct _IPH_API *orig_iph_api; struct _IPH_API *outer_iph_api; struct _IPH_API *outer_orig_iph_api; struct _IPv4Hdr inner_ip4h; struct _IPv6Hdr inner_ip6h; struct _IPv4Hdr outer_ip4h; struct _IPv6Hdr outer_ip6h; struct _MplsHdr mplsHdr; int family; int orig_family; int outer_family; int bytes_to_inspect; unsigned int preprocessor_bits; unsigned int preproc_reassembly_pkt_bits; unsigned int caplen; unsigned int http_pipeline_count; unsigned int packet_flags; unsigned int proto_bits; unsigned short dsize; unsigned short ip_dsize; unsigned short alt_dsize; unsigned short actual_ip_len; unsigned short outer_ip_dsize; unsigned short frag_offset; unsigned short ip_frag_len; unsigned short ip_options_len; unsigned short tcp_options_len; unsigned short sp; unsigned short dp; unsigned short orig_sp; unsigned short orig_dp; short application_protocol_ordinal; unsigned char frag_flag; unsigned char mf; unsigned char df; unsigned char rf; unsigned char uri_count; unsigned char csum_flags; unsigned char encapsulated; unsigned char ip_option_count; unsigned char tcp_option_count; unsigned char ip6_extension_count; unsigned char ip6_frag_index; unsigned char ip_lastopt_bad; unsigned char tcp_lastopt_bad; struct _Fddi_hdr *fddihdr; struct _Fddi_llc_saps *fddisaps; struct _Fddi_llc_sna *fddisna; struct _Fddi_llc_iparp *fddiiparp; struct _Fddi_llc_other *fddiother; struct _Trh_hdr *trh; struct _Trh_llc *trhllc; struct _Trh_mr *trhmr; struct _Pflog1_hdr *pf1h; struct _Pflog2_hdr *pf2h; struct _Pflog3_hdr *pf3h; struct _SLLHdr *sllh; struct _WifiHdr *wifih; struct _PPPoEHdr *pppoeh; struct _EtherEapol *eplh; struct _EAPHdr *eaph; unsigned char *eaptype; struct _EapolKey *eapolk; struct _Options ip_options[40]; struct _Options tcp_options[40]; struct _IP6Option ip6_extensions[40]; unsigned short configPolicyId; int linktype; }

user_defined_types: struct pcap_pkthdr { struct timeval ts; unsigned int caplen; unsigned int len; }

user_defined_types: struct _EtherARP { struct _ARPHdr ea_hdr; unsigned char arp_sha[6]; unsigned char arp_spa[4]; unsigned char arp_tha[6]; unsigned char arp_tpa[4]; }

user_defined_types: struct _IPHdr { unsigned char ip_verhl; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_proto; unsigned short ip_csum; struct in_addr ip_src; struct in_addr ip_dst; }

user_defined_types: struct _ICMPHdr { unsigned char type; unsigned char code; unsigned short csum; union { unsigned char pptr; struct in_addr gwaddr; struct idseq idseq; int sih_void; struct pmtu pmtu; struct rtradv rtradv; } icmp_hun; union { struct ts ts; struct ih_ip ip; struct ra_addr radv; unsigned int mask; char data[1]; } icmp_dun; }

user_defined_types: struct _IPv4Hdr { unsigned char ip_verhl; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_proto; unsigned short ip_csum; struct _ip ip_src; struct _ip ip_dst; }


SguilCleanExitFunc

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

DebugMessageFile = "spo_sguil.c";
DebugMessageLine = 1085;
DebugMessageFunc(32LL, "SguilCleanExitFunc\n");
if ( a2 )
{
if ( *(_QWORD *)a2 )
free(*(void **)a2);
v2 = *(void **)(a2 + 8);
if ( v2 )
free(v2);
v3 = *(void **)(a2 + 16);
if ( v3 )
free(v3);
v4 = *(void **)(a2 + 40);
if ( v4 )
free(v4);
free((void *)a2);
}
}

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

DebugMessageFile = "spo_sguil.c";
DebugMessageLine = 1085;
DebugMessageFunc(32LL, "SguilCleanExitFunc\n");
if ( a2 )
{
if ( *(_QWORD *)a2 )
free(*(void **)a2);
v2 = *(void **)(a2 + 8);
if ( v2 )
free(v2);
v3 = *(void **)(a2 + 16);
if ( v3 )
free(v3);
v4 = *(void **)(a2 + 40);
if ( v4 )
free(v4);
free((void *)a2);
}
}

original_code:
void SguilCleanExitFunc(int signal, void *arg)
{
    SpoSguilData *ssd_data = (SpoSguilData *)arg;
    DebugMessageFile = "spo_sguil.c"; DebugMessageLine = 1085; DebugMessageFunc(0x00000020,"SguilCleanExitFunc\n");;
 if (ssd_data)
 {
  if (ssd_data->sensor_name)
   free(ssd_data->sensor_name);
  if (ssd_data->tag_path)
   free(ssd_data->tag_path);
  if (ssd_data->passwd)
   free(ssd_data->passwd);
  if (ssd_data->args)
   free(ssd_data->args);
  free(ssd_data);
 }
}

canonical_original_code:
void SguilCleanExitFunc(int signal, void *arg)
{
    struct _SpoSguilData *ssd_data = (SpoSguilData *)arg;
    DebugMessageFile = "spo_sguil.c"; DebugMessageLine = 1085; DebugMessageFunc(0x00000020,"SguilCleanExitFunc\n");;
 if (ssd_data)
 {
  if (ssd_data->sensor_name)
   free(ssd_data->sensor_name);
  if (ssd_data->tag_path)
   free(ssd_data->tag_path);
  if (ssd_data->passwd)
   free(ssd_data->passwd);
  if (ssd_data->args)
   free(ssd_data->args);
  free(ssd_data);
 }
}

variable_types: signal int

variable_types: struct _SpoSguilData { char *sensor_name; char *tag_path; char *passwd; unsigned int sensor_id; unsigned int event_id; unsigned int agent_port; int agent_sock; char *args; } *


SguilRestartFunc

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

DebugMessageFile = "spo_sguil.c";
DebugMessageLine = 1110;
DebugMessageFunc(32LL, "SguilCleanExitFunc\n");
if ( a2 )
{
if ( *(_QWORD *)a2 )
free(*(void **)a2);
v2 = *(void **)(a2 + 8);
if ( v2 )
free(v2);
v3 = *(void **)(a2 + 16);
if ( v3 )
free(v3);
v4 = *(void **)(a2 + 40);
if ( v4 )
free(v4);
free((void *)a2);
}
}

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

DebugMessageFile = "spo_sguil.c";
DebugMessageLine = 1110;
DebugMessageFunc(32LL, "SguilCleanExitFunc\n");
if ( a2 )
{
if ( *(_QWORD *)a2 )
free(*(void **)a2);
v2 = *(void **)(a2 + 8);
if ( v2 )
free(v2);
v3 = *(void **)(a2 + 16);
if ( v3 )
free(v3);
v4 = *(void **)(a2 + 40);
if ( v4 )
free(v4);
free((void *)a2);
}
}

original_code:
void SguilRestartFunc(int signal, void *arg)
{
    SpoSguilData *ssd_data = (SpoSguilData *)arg;
    DebugMessageFile = "spo_sguil.c"; DebugMessageLine = 1110; DebugMessageFunc(0x00000020,"SguilCleanExitFunc\n");;
 if (ssd_data)
 {
  if (ssd_data->sensor_name)
   free(ssd_data->sensor_name);
  if (ssd_data->tag_path)
   free(ssd_data->tag_path);
  if (ssd_data->passwd)
   free(ssd_data->passwd);
  if (ssd_data->args)
   free(ssd_data->args);
  free(ssd_data);
 }
}

canonical_original_code:
void SguilRestartFunc(int signal, void *arg)
{
    struct _SpoSguilData *ssd_data = (SpoSguilData *)arg;
    DebugMessageFile = "spo_sguil.c"; DebugMessageLine = 1110; DebugMessageFunc(0x00000020,"SguilCleanExitFunc\n");;
 if (ssd_data)
 {
  if (ssd_data->sensor_name)
   free(ssd_data->sensor_name);
  if (ssd_data->tag_path)
   free(ssd_data->tag_path);
  if (ssd_data->passwd)
   free(ssd_data->passwd);
  if (ssd_data->args)
   free(ssd_data->args);
  free(ssd_data);
 }
}

user_defined_types: struct _SpoSguilData { char *sensor_name; char *tag_path; char *passwd; unsigned int sensor_id; unsigned int event_id; unsigned int agent_port; int agent_sock; char *args; }


SguilSetup

decompiled_code:
__int64 SguilSetup()
{
RegisterOutputPlugin("sguil", 1LL, SguilInit);
DebugMessageFile = "spo_sguil.c";
DebugMessageLine = 129;
return DebugMessageFunc(4LL, "Output: Sguil is setup\n");
}

canonical_decompiled_code:
__int64 func8()
{
RegisterOutputPlugin("sguil", 1LL, SguilInit);
DebugMessageFile = "spo_sguil.c";
DebugMessageLine = 129;
return DebugMessageFunc(4LL, "Output: Sguil is setup\n");
}

original_code:
void SguilSetup()
{
    RegisterOutputPlugin("sguil", OUTPUT_TYPE_FLAG__ALERT, SguilInit);
    DebugMessageFile = "spo_sguil.c"; DebugMessageLine = 129; DebugMessageFunc(0x00000004, "Output: Sguil is setup\n");;
}