decompiled_code:
__int64 __fastcall symbol_hash(char *s1, int a2)
{
int v2; // er12
unsigned int v3; // ebx
int v4; // er12
int *v5; // r15
__int64 v6; // r15

v2 = *s1;
if ( a2 >= 0 && (_BYTE)v2 )
{
v3 = abs32(403 * (v2 + s1[strlen(s1) - 1]) % 100);
v4 = v3;
while ( 1 )
{
v6 = 7LL * v4;
if ( !LOBYTE(symbol_table[v6 + 1]) )
break;
if ( !strcmp(s1, (const char *)&symbol_table[v6 + 1]) )
{
v5 = &symbol_table[v6];
if ( symbol_table[7 * v4] == 1 || v5[5] == a2 )
break;
}
v4 = (v4 + 1) % 100;
if ( v3 == v4 )
goto LABEL_10;
}
}
else
{
LABEL_10:
v4 = -1;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1, int a2)
{
int v2; // er12
unsigned int v3; // ebx
int v4; // er12
int *v5; // r15
__int64 v6; // r15

v2 = *s1;
if ( a2 >= 0 && (_BYTE)v2 )
{
v3 = abs32(403 * (v2 + s1[strlen(s1) - 1]) % 100);
v4 = v3;
while ( 1 )
{
v6 = 7LL * v4;
if ( !LOBYTE(symbol_table[v6 + 1]) )
break;
if ( !strcmp(s1, (const char *)&symbol_table[v6 + 1]) )
{
v5 = &symbol_table[v6];
if ( symbol_table[7 * v4] == 1 || v5[5] == a2 )
break;
}
v4 = (v4 + 1) % 100;
if ( v3 == v4 )
goto LABEL_10;
}
}
else
{
LABEL_10:
v4 = -1;
}
return (unsigned int)v4;
}

original_code:
int symbol_hash(char *value, int level) {
  int hash = -1;
  int extra = 'a' + 'd' + 'a' + 'm';
  if(strlen(value) && level >= 0) {
    hash = abs(((value[0] + value[strlen(value) - 1]) * extra) % 100);
    if(0) printf("DEBUG: initial hash: %d\n", hash);
    int tmp = hash;
    while(strlen(symbol_table[hash].name) && (strcmp(value, symbol_table[hash].name) != 0 || (symbol_table[hash].kind != 1 && symbol_table[hash].level != level))) {
      hash = (hash + 1) % 100;
      if(tmp == hash)
        return -1;
    }
  }
  if(0) printf("DEBUG: final hash: %d\n", hash);
  return hash;
}

variable_types:
value
char *

variable_types: level int

variable_types: hash int

variable_types: extra int

variable_types: tmp int


system

repo: adamel/chrome-deps

decompiled_code:
__int64 __fastcall system(char *haystack)
{
char *v1; // r13
char *v2; // r12
__int64 (__fastcall *v3)(char *); // rbx
unsigned int v4; // er12

v1 = getenv("LD_LIBRARY_PATH");
v2 = getenv("LD_PRELOAD");
v3 = (__int64 (__fastcall *)(char *))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "system");
if ( v1 && *v1 )
snprintf(&pathsavebuf_7, 0x2000uLL, "LD_LIBRARY_PATH=%s", v1);
else
pathsavebuf_7 = 0;
if ( v2 && *v2 )
snprintf(&preloadsavebuf_6, 0x2000uLL, "LD_PRELOAD=%s", v2);
else
preloadsavebuf_6 = 0;
if ( !strchr(haystack, 47)
|| strstr(haystack, "/opt/google/talkplugin/")
|| !strcmp(haystack, "/opt/google/chrome/google-chrome") )
{
unsetenv("LD_LIBRARY_PATH");
}
unsetenv("LD_PRELOAD");
v4 = v3(haystack);
if ( pathsavebuf_7 )
{
putenv(&pathsavebuf_7);
if ( preloadsavebuf_6 )
{
LABEL_12:
putenv(&preloadsavebuf_6);
return v4;
}
}
else
{
unsetenv("LD_LIBRARY_PATH");
if ( preloadsavebuf_6 )
goto LABEL_12;
}
unsetenv("LD_PRELOAD");
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *haystack)
{
char *v1; // r13
char *v2; // r12
__int64 (__fastcall *v3)(char *); // rbx
unsigned int v4; // er12

v1 = getenv("LD_LIBRARY_PATH");
v2 = getenv("LD_PRELOAD");
v3 = (__int64 (__fastcall *)(char *))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "system");
if ( v1 && *v1 )
snprintf(&pathsavebuf_7, 0x2000uLL, "LD_LIBRARY_PATH=%s", v1);
else
pathsavebuf_7 = 0;
if ( v2 && *v2 )
snprintf(&preloadsavebuf_6, 0x2000uLL, "LD_PRELOAD=%s", v2);
else
preloadsavebuf_6 = 0;
if ( !strchr(haystack, 47)
|| strstr(haystack, "/opt/google/talkplugin/")
|| !strcmp(haystack, "/opt/google/chrome/google-chrome") )
{
unsetenv("LD_LIBRARY_PATH");
}
unsetenv("LD_PRELOAD");
v4 = v3(haystack);
if ( pathsavebuf_7 )
{
putenv(&pathsavebuf_7);
if ( preloadsavebuf_6 )
{
LABEL_12:
putenv(&preloadsavebuf_6);
return v4;
}
}
else
{
unsetenv("LD_LIBRARY_PATH");
if ( preloadsavebuf_6 )
goto LABEL_12;
}
unsetenv("LD_PRELOAD");
return v4;
}

original_code: int system(const char * cmd) { char *pathenvptr=getenv("LD_LIBRARY_PATH"), *preloadenvptr=getenv("LD_PRELOAD"); static char pathsavebuf[8192],preloadsavebuf[8192]; int retval; int (*original_system)(const char *); original_system=dlsym(((void *) -1l),"system"); if (pathenvptr!=(char *)((void *)0) && pathenvptr[0]!='\0') (void)snprintf(pathsavebuf,8192,"LD_LIBRARY_PATH" "=%s",pathenvptr); else pathsavebuf[0]='\0'; if (preloadenvptr!=(char *)((void *)0) && preloadenvptr[0]!='\0') (void)snprintf(preloadsavebuf,8192,"LD_PRELOAD" "=%s",preloadenvptr); else preloadsavebuf[0]='\0'; if (strstr(cmd,"/")==(char *)((void *)0) || strstr(cmd,"/opt/google/talkplugin/")!=(char *)((void *)0) || !strcmp(cmd,"/opt/google/chrome/google-chrome")) unsetenv("LD_LIBRARY_PATH"); unsetenv("LD_PRELOAD"); retval=(*original_system)(cmd); if (pathsavebuf[0]) putenv(pathsavebuf); else unsetenv("LD_LIBRARY_PATH"); if (preloadsavebuf[0]) putenv(preloadsavebuf); else unsetenv("LD_PRELOAD"); return(retval); }

canonical_original_code: int system(char *cmd) { char *pathenvptr = getenv("LD_LIBRARY_PATH"); char *preloadenvptr = getenv("LD_PRELOAD"); static char pathsavebuf[8192]; static char preloadsavebuf[8192]; int retval; int (*original_system)(char *); original_system=dlsym(((void *) -1l),"system"); if (pathenvptr!=(char *)((void *)0) && pathenvptr[0]!='\0') (void)snprintf(pathsavebuf,8192,"LD_LIBRARY_PATH" "=%s",pathenvptr); else pathsavebuf[0]='\0'; if (preloadenvptr!=(char *)((void *)0) && preloadenvptr[0]!='\0') (void)snprintf(preloadsavebuf,8192,"LD_PRELOAD" "=%s",preloadenvptr); else preloadsavebuf[0]='\0'; if (strstr(cmd,"/")==(char *)((void *)0) || strstr(cmd,"/opt/google/talkplugin/")!=(char *)((void *)0) || !strcmp(cmd,"/opt/google/chrome/google-chrome")) unsetenv("LD_LIBRARY_PATH"); unsetenv("LD_PRELOAD"); retval=(*original_system)(cmd); if (pathsavebuf[0]) putenv(pathsavebuf); else unsetenv("LD_LIBRARY_PATH"); if (preloadsavebuf[0]) putenv(preloadsavebuf); else unsetenv("LD_PRELOAD"); return(retval); }

variable_types:
cmd
char *

variable_types:
pathenvptr
char *

variable_types:
preloadenvptr
char *

variable_types:
pathsavebuf
char [8192]

variable_types:
preloadsavebuf
char [8192]

variable_types: retval int

return_type: int


execvp

decompiled_code:
__int64 __fastcall execvp(char *haystack, __int64 a2)
{
char *v2; // r13
char *v3; // r12
__int64 (__fastcall *v4)(char *, __int64); // rbx
unsigned int v5; // er12

v2 = getenv("LD_LIBRARY_PATH");
v3 = getenv("LD_PRELOAD");
v4 = (__int64 (__fastcall *)(char *, __int64))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "execvp");
if ( v2 && *v2 )
snprintf(&pathsavebuf_5, 0x2000uLL, "LD_LIBRARY_PATH=%s", v2);
else
pathsavebuf_5 = 0;
if ( v3 && *v3 )
snprintf(&preloadsavebuf_4, 0x2000uLL, "LD_PRELOAD=%s", v3);
else
preloadsavebuf_4 = 0;
if ( !strchr(haystack, 47)
|| strstr(haystack, "/opt/google/talkplugin/")
|| !strcmp(haystack, "/opt/google/chrome/google-chrome") )
{
unsetenv("LD_LIBRARY_PATH");
}
unsetenv("LD_PRELOAD");
v5 = v4(haystack, a2);
if ( pathsavebuf_5 )
{
putenv(&pathsavebuf_5);
if ( preloadsavebuf_4 )
{
LABEL_12:
putenv(&preloadsavebuf_4);
return v5;
}
}
else
{
unsetenv("LD_LIBRARY_PATH");
if ( preloadsavebuf_4 )
goto LABEL_12;
}
unsetenv("LD_PRELOAD");
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *haystack, __int64 a2)
{
char *v2; // r13
char *v3; // r12
__int64 (__fastcall *v4)(char *, __int64); // rbx
unsigned int v5; // er12

v2 = getenv("LD_LIBRARY_PATH");
v3 = getenv("LD_PRELOAD");
v4 = (__int64 (__fastcall *)(char *, __int64))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "execvp");
if ( v2 && *v2 )
snprintf(&pathsavebuf_5, 0x2000uLL, "LD_LIBRARY_PATH=%s", v2);
else
pathsavebuf_5 = 0;
if ( v3 && *v3 )
snprintf(&preloadsavebuf_4, 0x2000uLL, "LD_PRELOAD=%s", v3);
else
preloadsavebuf_4 = 0;
if ( !strchr(haystack, 47)
|| strstr(haystack, "/opt/google/talkplugin/")
|| !strcmp(haystack, "/opt/google/chrome/google-chrome") )
{
unsetenv("LD_LIBRARY_PATH");
}
unsetenv("LD_PRELOAD");
v5 = v4(haystack, a2);
if ( pathsavebuf_5 )
{
putenv(&pathsavebuf_5);
if ( preloadsavebuf_4 )
{
LABEL_12:
putenv(&preloadsavebuf_4);
return v5;
}
}
else
{
unsetenv("LD_LIBRARY_PATH");
if ( preloadsavebuf_4 )
goto LABEL_12;
}
unsetenv("LD_PRELOAD");
return v5;
}

original_code: int execvp(const char * file,const char ** argv) { char *pathenvptr=getenv("LD_LIBRARY_PATH"), *preloadenvptr=getenv("LD_PRELOAD"); static char pathsavebuf[8192],preloadsavebuf[8192]; int retval; int (*original_execvp)(const char *,const char **); original_execvp=dlsym(((void *) -1l),"execvp"); if (pathenvptr!=(char *)((void *)0) && pathenvptr[0]!='\0') (void)snprintf(pathsavebuf,8192,"LD_LIBRARY_PATH" "=%s",pathenvptr); else pathsavebuf[0]='\0'; if (preloadenvptr!=(char *)((void *)0) && preloadenvptr[0]!='\0') (void)snprintf(preloadsavebuf,8192,"LD_PRELOAD" "=%s",preloadenvptr); else preloadsavebuf[0]='\0'; if (strstr(file,"/")==(char *)((void *)0) || strstr(file,"/opt/google/talkplugin/")!=(char *)((void *)0) || !strcmp(file,"/opt/google/chrome/google-chrome")) unsetenv("LD_LIBRARY_PATH"); unsetenv("LD_PRELOAD"); retval=(*original_execvp)(file,argv); if (pathsavebuf[0]) putenv(pathsavebuf); else unsetenv("LD_LIBRARY_PATH"); if (preloadsavebuf[0]) putenv(preloadsavebuf); else unsetenv("LD_PRELOAD"); return(retval); }

canonical_original_code: int execvp(char *file, char **argv) { char *pathenvptr = getenv("LD_LIBRARY_PATH"); char *preloadenvptr = getenv("LD_PRELOAD"); static char pathsavebuf[8192]; static char preloadsavebuf[8192]; int retval; int (*original_execvp)(char *, char **); original_execvp=dlsym(((void *) -1l),"execvp"); if (pathenvptr!=(char *)((void *)0) && pathenvptr[0]!='\0') (void)snprintf(pathsavebuf,8192,"LD_LIBRARY_PATH" "=%s",pathenvptr); else pathsavebuf[0]='\0'; if (preloadenvptr!=(char *)((void *)0) && preloadenvptr[0]!='\0') (void)snprintf(preloadsavebuf,8192,"LD_PRELOAD" "=%s",preloadenvptr); else preloadsavebuf[0]='\0'; if (strstr(file,"/")==(char *)((void *)0) || strstr(file,"/opt/google/talkplugin/")!=(char *)((void *)0) || !strcmp(file,"/opt/google/chrome/google-chrome")) unsetenv("LD_LIBRARY_PATH"); unsetenv("LD_PRELOAD"); retval=(*original_execvp)(file,argv); if (pathsavebuf[0]) putenv(pathsavebuf); else unsetenv("LD_LIBRARY_PATH"); if (preloadsavebuf[0]) putenv(preloadsavebuf); else unsetenv("LD_PRELOAD"); return(retval); }

variable_types:
file
char *

variable_types:
argv
char **


execve

decompiled_code:
__int64 __fastcall execve(char *haystack, __int64 a2, __int64 a3)
{
char *v4; // r13
char *v5; // r12
__int64 (__fastcall *v6)(char *, __int64, __int64); // rbx
unsigned int v7; // er12

v4 = getenv("LD_LIBRARY_PATH");
v5 = getenv("LD_PRELOAD");
v6 = (__int64 (__fastcall *)(char *, __int64, __int64))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "execve");
if ( v4 && *v4 )
snprintf(&pathsavebuf_3, 0x2000uLL, "LD_LIBRARY_PATH=%s", v4);
else
pathsavebuf_3 = 0;
if ( v5 && *v5 )
snprintf(&preloadsavebuf_2, 0x2000uLL, "LD_PRELOAD=%s", v5);
else
preloadsavebuf_2 = 0;
if ( !strchr(haystack, 47)
|| strstr(haystack, "/opt/google/talkplugin/")
|| !strcmp(haystack, "/opt/google/chrome/google-chrome") )
{
unsetenv("LD_LIBRARY_PATH");
}
unsetenv("LD_PRELOAD");
v7 = v6(haystack, a2, a3);
if ( !pathsavebuf_3 )
{
unsetenv("LD_LIBRARY_PATH");
if ( preloadsavebuf_2 )
goto LABEL_12;
LABEL_15:
unsetenv("LD_PRELOAD");
return v7;
}
putenv(&pathsavebuf_3);
if ( !preloadsavebuf_2 )
goto LABEL_15;
LABEL_12:
putenv(&preloadsavebuf_2);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *haystack, __int64 a2, __int64 a3)
{
char *v4; // r13
char *v5; // r12
__int64 (__fastcall *v6)(char *, __int64, __int64); // rbx
unsigned int v7; // er12

v4 = getenv("LD_LIBRARY_PATH");
v5 = getenv("LD_PRELOAD");
v6 = (__int64 (__fastcall *)(char *, __int64, __int64))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "execve");
if ( v4 && *v4 )
snprintf(&pathsavebuf_3, 0x2000uLL, "LD_LIBRARY_PATH=%s", v4);
else
pathsavebuf_3 = 0;
if ( v5 && *v5 )
snprintf(&preloadsavebuf_2, 0x2000uLL, "LD_PRELOAD=%s", v5);
else
preloadsavebuf_2 = 0;
if ( !strchr(haystack, 47)
|| strstr(haystack, "/opt/google/talkplugin/")
|| !strcmp(haystack, "/opt/google/chrome/google-chrome") )
{
unsetenv("LD_LIBRARY_PATH");
}
unsetenv("LD_PRELOAD");
v7 = v6(haystack, a2, a3);
if ( !pathsavebuf_3 )
{
unsetenv("LD_LIBRARY_PATH");
if ( preloadsavebuf_2 )
goto LABEL_12;
LABEL_15:
unsetenv("LD_PRELOAD");
return v7;
}
putenv(&pathsavebuf_3);
if ( !preloadsavebuf_2 )
goto LABEL_15;
LABEL_12:
putenv(&preloadsavebuf_2);
return v7;
}

original_code: int execve(const char * filename,const char ** argv,const char ** envp) { char *pathenvptr=getenv("LD_LIBRARY_PATH"), *preloadenvptr=getenv("LD_PRELOAD"); static char pathsavebuf[8192],preloadsavebuf[8192]; int retval; int (*original_execve)(const char *,const char **,const char **); original_execve=dlsym(((void *) -1l),"execve"); if (pathenvptr!=(char *)((void *)0) && pathenvptr[0]!='\0') (void)snprintf(pathsavebuf,8192,"LD_LIBRARY_PATH" "=%s",pathenvptr); else pathsavebuf[0]='\0'; if (preloadenvptr!=(char *)((void *)0) && preloadenvptr[0]!='\0') (void)snprintf(preloadsavebuf,8192,"LD_PRELOAD" "=%s",preloadenvptr); else preloadsavebuf[0]='\0'; if (strstr(filename,"/")==(char *)((void *)0) || strstr(filename,"/opt/google/talkplugin/")!=(char *)((void *)0) || !strcmp(filename,"/opt/google/chrome/google-chrome")) unsetenv("LD_LIBRARY_PATH"); unsetenv("LD_PRELOAD"); retval=(*original_execve)(filename,argv,envp); if (pathsavebuf[0]) putenv(pathsavebuf); else unsetenv("LD_LIBRARY_PATH"); if (preloadsavebuf[0]) putenv(preloadsavebuf); else unsetenv("LD_PRELOAD"); return(retval); }

canonical_original_code: int execve(char *filename, char **argv, char **envp) { char *pathenvptr = getenv("LD_LIBRARY_PATH"); char *preloadenvptr = getenv("LD_PRELOAD"); static char pathsavebuf[8192]; static char preloadsavebuf[8192]; int retval; int (*original_execve)(char *, char **, char **); original_execve=dlsym(((void *) -1l),"execve"); if (pathenvptr!=(char *)((void *)0) && pathenvptr[0]!='\0') (void)snprintf(pathsavebuf,8192,"LD_LIBRARY_PATH" "=%s",pathenvptr); else pathsavebuf[0]='\0'; if (preloadenvptr!=(char *)((void *)0) && preloadenvptr[0]!='\0') (void)snprintf(preloadsavebuf,8192,"LD_PRELOAD" "=%s",preloadenvptr); else preloadsavebuf[0]='\0'; if (strstr(filename,"/")==(char *)((void *)0) || strstr(filename,"/opt/google/talkplugin/")!=(char *)((void *)0) || !strcmp(filename,"/opt/google/chrome/google-chrome")) unsetenv("LD_LIBRARY_PATH"); unsetenv("LD_PRELOAD"); retval=(*original_execve)(filename,argv,envp); if (pathsavebuf[0]) putenv(pathsavebuf); else unsetenv("LD_LIBRARY_PATH"); if (preloadsavebuf[0]) putenv(preloadsavebuf); else unsetenv("LD_PRELOAD"); return(retval); }

variable_types:
filename
char *

variable_types:
envp
char **


execlp

decompiled_code:
__int64 execlp(char *haystack, __int64 a2, ...)
{
char *v2; // r13
char *v3; // r12
__int64 (__fastcall *v4)(char *, __int64, __va_list_tag *); // rbx
unsigned int v5; // er12
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF

v2 = getenv("LD_LIBRARY_PATH");
v3 = getenv("LD_PRELOAD");
v4 = (__int64 (__fastcall *)(char *, __int64, __va_list_tag *))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "execlp");
if ( v2 && *v2 )
snprintf(&pathsavebuf_1, 0x2000uLL, "LD_LIBRARY_PATH=%s", v2);
else
pathsavebuf_1 = 0;
if ( v3 && *v3 )
snprintf(&preloadsavebuf_0, 0x2000uLL, "LD_PRELOAD=%s", v3);
else
preloadsavebuf_0 = 0;
if ( !strchr(haystack, 47)
|| strstr(haystack, "/opt/google/talkplugin/")
|| !strcmp(haystack, "/opt/google/chrome/google-chrome") )
{
unsetenv("LD_LIBRARY_PATH");
}
unsetenv("LD_PRELOAD");
va_start(va, a2);
v5 = v4(haystack, a2, va);
if ( !pathsavebuf_1 )
{
unsetenv("LD_LIBRARY_PATH");
if ( preloadsavebuf_0 )
goto LABEL_12;
LABEL_15:
unsetenv("LD_PRELOAD");
return v5;
}
putenv(&pathsavebuf_1);
if ( !preloadsavebuf_0 )
goto LABEL_15;
LABEL_12:
putenv(&preloadsavebuf_0);
return v5;
}

canonical_decompiled_code:
__int64 func9(char *haystack, __int64 a2, ...)
{
char *v2; // r13
char *v3; // r12
__int64 (__fastcall *v4)(char *, __int64, __va_list_tag *); // rbx
unsigned int v5; // er12
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF

v2 = getenv("LD_LIBRARY_PATH");
v3 = getenv("LD_PRELOAD");
v4 = (__int64 (__fastcall *)(char *, __int64, __va_list_tag *))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "execlp");
if ( v2 && *v2 )
snprintf(&pathsavebuf_1, 0x2000uLL, "LD_LIBRARY_PATH=%s", v2);
else
pathsavebuf_1 = 0;
if ( v3 && *v3 )
snprintf(&preloadsavebuf_0, 0x2000uLL, "LD_PRELOAD=%s", v3);
else
preloadsavebuf_0 = 0;
if ( !strchr(haystack, 47)
|| strstr(haystack, "/opt/google/talkplugin/")
|| !strcmp(haystack, "/opt/google/chrome/google-chrome") )
{
unsetenv("LD_LIBRARY_PATH");
}
unsetenv("LD_PRELOAD");
va_start(va, a2);
v5 = v4(haystack, a2, va);
if ( !pathsavebuf_1 )
{
unsetenv("LD_LIBRARY_PATH");
if ( preloadsavebuf_0 )
goto LABEL_12;
LABEL_15:
unsetenv("LD_PRELOAD");
return v5;
}
putenv(&pathsavebuf_1);
if ( !preloadsavebuf_0 )
goto LABEL_15;
LABEL_12:
putenv(&preloadsavebuf_0);
return v5;
}

original_code: int execlp(const char * file,const char * arg,...) { va_list args; char *pathenvptr=getenv("LD_LIBRARY_PATH"), *preloadenvptr=getenv("LD_PRELOAD"); static char pathsavebuf[8192],preloadsavebuf[8192]; int retval; int (*original_execlp)(const char *,const char *,...); original_execlp=dlsym(((void *) -1l),"execlp"); if (pathenvptr!=(char *)((void *)0) && pathenvptr[0]!='\0') (void)snprintf(pathsavebuf,8192,"LD_LIBRARY_PATH" "=%s",pathenvptr); else pathsavebuf[0]='\0'; if (preloadenvptr!=(char *)((void *)0) && preloadenvptr[0]!='\0') (void)snprintf(preloadsavebuf,8192,"LD_PRELOAD" "=%s",preloadenvptr); else preloadsavebuf[0]='\0'; if (strstr(file,"/")==(char *)((void *)0) || strstr(file,"/opt/google/talkplugin/")!=(char *)((void *)0) || !strcmp(file,"/opt/google/chrome/google-chrome")) unsetenv("LD_LIBRARY_PATH"); unsetenv("LD_PRELOAD"); __builtin_va_start(args,arg); retval=(*original_execlp)(file,arg,args); __builtin_va_end(args); if (pathsavebuf[0]) putenv(pathsavebuf); else unsetenv("LD_LIBRARY_PATH"); if (preloadsavebuf[0]) putenv(preloadsavebuf); else unsetenv("LD_PRELOAD"); return(retval); }

canonical_original_code: int execlp(char *file, char *arg, ...) { __builtin_va_list args; char *pathenvptr = getenv("LD_LIBRARY_PATH"); char *preloadenvptr = getenv("LD_PRELOAD"); static char pathsavebuf[8192]; static char preloadsavebuf[8192]; int retval; int (*original_execlp)(char *, char *, ...); original_execlp=dlsym(((void *) -1l),"execlp"); if (pathenvptr!=(char *)((void *)0) && pathenvptr[0]!='\0') (void)snprintf(pathsavebuf,8192,"LD_LIBRARY_PATH" "=%s",pathenvptr); else pathsavebuf[0]='\0'; if (preloadenvptr!=(char *)((void *)0) && preloadenvptr[0]!='\0') (void)snprintf(preloadsavebuf,8192,"LD_PRELOAD" "=%s",preloadenvptr); else preloadsavebuf[0]='\0'; if (strstr(file,"/")==(char *)((void *)0) || strstr(file,"/opt/google/talkplugin/")!=(char *)((void *)0) || !strcmp(file,"/opt/google/chrome/google-chrome")) unsetenv("LD_LIBRARY_PATH"); unsetenv("LD_PRELOAD"); __builtin_va_start(args,arg); retval=(*original_execlp)(file,arg,args); __builtin_va_end(args); if (pathsavebuf[0]) putenv(pathsavebuf); else unsetenv("LD_LIBRARY_PATH"); if (preloadsavebuf[0]) putenv(preloadsavebuf); else unsetenv("LD_PRELOAD"); return(retval); }

variable_types:
arg
char *


decompiled_code:
void __fastcall add_node_at(_QWORD *a1, _QWORD **a2, int a3)
{
_QWORD *v3; // rax
_QWORD *v4; // rdx

if ( a1 )
{
if ( a3 <= 0 )
{
add_node();
}
else
{
v3 = *a2;
do
{
v4 = v3;
v3 = (_QWORD *)*v3;
}
while ( v3 );
*a1 = 0LL;
*v4 = a1;
}
}
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1, _QWORD **a2, int a3)
{
_QWORD *v3; // rax
_QWORD *v4; // rdx

if ( a1 )
{
if ( a3 <= 0 )
{
add_node();
}
else
{
v3 = *a2;
do
{
v4 = v3;
v3 = (_QWORD *)*v3;
}
while ( v3 );
*a1 = 0LL;
*v4 = a1;
}
}
}

original_code:
void add_node_at(t_node *node, t_node **head, int n)
{
  int i;
  t_node *search;
  search = *head;
  if(node==((void *)0) || head==((void *)0))
    return;
  if (n<=0)
    add_node(node, head);
  else
    {
      for(i=1;i<n,search->next!=((void *)0);i++)
 {
   search = search->next;
 }
      node->next = search->next;
      search->next = node;
    }
}

canonical_original_code:
void add_node_at(struct s_node *node, struct s_node **head, int n)
{
  int i;
  struct s_node *search;
  search = *head;
  if(node==((void *)0) || head==((void *)0))
    return;
  if (n<=0)
    add_node(node, head);
  else
    {
      for(i=1;i<n,search->next!=((void *)0);i++)
 {
   search = search->next;
 }
      node->next = search->next;
      search->next = node;
    }
}

variable_types: struct s_node { struct s_node *next; void *elem; } *

variable_types:
head
struct s_node **

variable_types: n int

variable_types: i int

return_type: void


original_code:
char* my_strconcat(char* s1, char* s2)
{
  int i=0;
  int j=0;
  int lens1=my_strlen(s1);
  int lens2=my_strlen(s2);
  char* s3 = (char*)xmalloc(lens1+lens2+1);
  if (s1==((void *)0) && s2==((void *)0))
    return ((void *)0);
  if (s2==((void *)0))
    return s1;
  if (s1==((void *)0))
    return s3=s2;
  for(i;i<lens1;i++)
    {
      s3[i]=s1[i];
    }
  for(j;j<lens2;i++,j++)
    {
      s3[i]=s2[j];
    }
  s3[i]='\0';
  return s3;
}

canonical_original_code:
char *my_strconcat(char *s1, char *s2)
{
  int i = 0;
  int j = 0;
  int lens1 = my_strlen(s1);
  int lens2 = my_strlen(s2);
  char *s3 = (char*)xmalloc(lens1+lens2+1);
  if (s1==((void *)0) && s2==((void *)0))
    return ((void *)0);
  if (s2==((void *)0))
    return s1;
  if (s1==((void *)0))
    return s3=s2;
  for(i;i<lens1;i++)
    {
      s3[i]=s1[i];
    }
  for(j;j<lens2;i++,j++)
    {
      s3[i]=s2[j];
    }
  s3[i]='\0';
  return s3;
}

variable_types: j int

return_type: char *


decompiled_code:
__int64 __fastcall my_strindex(char *a1, char a2)
{
char v2; // dl
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( a2 != v2 )
{
v2 = a1[++result];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( a2 != v2 )
{
v2 = a1[++result];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
int my_strindex(char* str, char c)
{
  int i;
  if(str==((void *)0))
    return -1;
  else
    {
      for(i=0;str[i]!='\0';i++)
 {
   if(c==str[i])
     return i;
 }
      return -1;
    }
}

canonical_original_code:
int my_strindex(char *str, char c)
{
  int i;
  if(str==((void *)0))
    return -1;
  else
    {
      for(i=0;str[i]!='\0';i++)
 {
   if(c==str[i])
     return i;
 }
      return -1;
    }
}

variable_types:
str
char *

variable_types: c char


decompiled_code:
ssize_t __fastcall my_char(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func0(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

original_code:
void my_char(char c)
{
  write(1,&c,1);
}

canonical_original_code:
void my_char(char c)
{
  write(1,&c,1);
}


decompiled_code:
__int64 __fastcall travere_string(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 result; // rax

v1 = a1;
for ( result = my_str("Printing Linked List: "); v1; v1 = (_QWORD *)*v1 )
{
my_str(v1[1]);
result = my_char(32LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 result; // rax

v1 = a1;
for ( result = my_str("Printing Linked List: "); v1; v1 = (_QWORD *)*v1 )
{
my_str(v1[1]);
result = my_char(32LL);
}
return result;
}

original_code:
void travere_string(t_node* head)
{
  t_node* node = head;
  my_str("Printing Linked List: ");
  while(node!=((void *)0))
    {
      my_str(node->elem);
      my_char(' ');
      node=node->next;
    }
}

canonical_original_code:
void travere_string(struct s_node *head)
{
  struct s_node *node = head;
  my_str("Printing Linked List: ");
  while(node!=((void *)0))
    {
      my_str(node->elem);
      my_char(' ');
      node=node->next;
    }
}

user_defined_types: struct s_node { struct s_node *next; void *elem; }


decompiled_code:
__int64 __fastcall my_strlen(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

if ( !a1 )
return (unsigned int)-1;
if ( *a1 )
{
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

if ( !a1 )
return (unsigned int)-1;
if ( *a1 )
{
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}
return 0LL;
}

original_code:
int my_strlen(char* str)
{
  int i=0;
  if (str == ((void *)0))
    return -1;
  while(str[i]!='\0')
    {
      i++;
    }
  return i;
}

canonical_original_code:
int my_strlen(char *str)
{
  int i = 0;
  if (str == ((void *)0))
    return -1;
  while(str[i]!='\0')
    {
      i++;
    }
  return i;
}


original_code:
int my_atoi(char* strint)
{
  char check=1;
  if(strint[0] == '-')
    {
      check = -1;
      strint = &strint[1];
    }
  int i;
  int ret;
  for(i=0, ret=0; strint[i]!='\0' && strint[i]!='.'; i++)
    {
      ret *= 10;
      ret += strint[i] - '0';
    }
  return ret*check;
}

canonical_original_code:
int my_atoi(char *strint)
{
  char check = 1;
  if(strint[0] == '-')
    {
      check = -1;
      strint = &strint[1];
    }
  int i;
  int ret;
  for(i=0, ret=0; strint[i]!='\0' && strint[i]!='.'; i++)
    {
      ret *= 10;
      ret += strint[i] - '0';
    }
  return ret*check;
}

variable_types:
strint
char *

variable_types: check char

variable_types: ret int


decompiled_code:
__int64 __fastcall my_strcmp(char *a1, __int64 a2)
{
char v2; // dl
__int64 result; // rax
char v4; // cl

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
v2 = *a1;
result = 0LL;
if ( *a1 )
{
while ( 1 )
{
v4 = *(_BYTE *)(a2 + result);
if ( !v4 )
return 0LL;
if ( v4 < v2 )
break;
if ( v4 > v2 )
return 0xFFFFFFFFLL;
v2 = a1[++result];
if ( !v2 )
return 0LL;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, __int64 a2)
{
char v2; // dl
__int64 result; // rax
char v4; // cl

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
v2 = *a1;
result = 0LL;
if ( *a1 )
{
while ( 1 )
{
v4 = *(_BYTE *)(a2 + result);
if ( !v4 )
return 0LL;
if ( v4 < v2 )
break;
if ( v4 > v2 )
return 0xFFFFFFFFLL;
v2 = a1[++result];
if ( !v2 )
return 0LL;
}
result = 1LL;
}
return result;
}


decompiled_code:
__int64 __fastcall traverse_int(__int64 **a1)
{
__int64 **v1; // rbx
__int64 result; // rax

v1 = a1;
for ( result = my_str("Printing Linked List: "); v1; v1 = (__int64 **)*v1 )
{
my_int(*(unsigned int *)v1[1]);
result = my_char(32LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 **a1)
{
__int64 **v1; // rbx
__int64 result; // rax

v1 = a1;
for ( result = my_str("Printing Linked List: "); v1; v1 = (__int64 **)*v1 )
{
my_int(*(unsigned int *)v1[1]);
result = my_char(32LL);
}
return result;
}

original_code:
void traverse_int(t_node *head)
{
  t_node* node = head;
  my_str("Printing Linked List: ");
  while(node!=((void *)0))
    {
      my_int(*(int*)node->elem);
      my_char(' ');
      node=node->next;
    }
}

canonical_original_code:
void traverse_int(struct s_node *head)
{
  struct s_node *node = head;
  my_str("Printing Linked List: ");
  while(node!=((void *)0))
    {
      my_int(*(int *)node->elem);
      my_char(' ');
      node=node->next;
    }
}


decompiled_code:
__int64 __fastcall my_num_base(int a1, char *a2)
{
unsigned int v2; // ebp
int v3; // eax
unsigned int v4; // er12
unsigned int v5; // ebx
__int64 result; // rax
__int64 v7; // rdi
unsigned int v8; // ecx
unsigned int v9; // ebp

v3 = my_strlen(a2);
if ( v3 <= 0 )
return my_str("YOUR BASE IS SHIT\n");
v4 = v3;
if ( a1 < 0 )
{
my_char(45LL);
v2 = -a1;
}
if ( v4 == 1 )
{
v9 = v2 - 1;
do
result = my_char((unsigned int)*a2);
while ( v9-- != 0 );
}
else
{
v5 = 1;
if ( v2 < v4 )
{
result = my_char((unsigned int)a2[v2]);
}
else
{
do
{
v5 *= v4;
result = v2 / v5;
}
while ( (unsigned int)result >= v4 );
if ( v5 )
{
do
{
v7 = (unsigned int)a2[v2 / v5];
v2 %= v5;
my_char(v7);
v8 = v5;
result = v5 / v4;
v5 /= v4;
}
while ( v4 <= v8 );
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, char *a2)
{
unsigned int v2; // ebp
int v3; // eax
unsigned int v4; // er12
unsigned int v5; // ebx
__int64 result; // rax
__int64 v7; // rdi
unsigned int v8; // ecx
unsigned int v9; // ebp

v3 = my_strlen(a2);
if ( v3 <= 0 )
return my_str("YOUR BASE IS SHIT\n");
v4 = v3;
if ( a1 < 0 )
{
my_char(45LL);
v2 = -a1;
}
if ( v4 == 1 )
{
v9 = v2 - 1;
do
result = my_char((unsigned int)*a2);
while ( v9-- != 0 );
}
else
{
v5 = 1;
if ( v2 < v4 )
{
result = my_char((unsigned int)a2[v2]);
}
else
{
do
{
v5 *= v4;
result = v2 / v5;
}
while ( (unsigned int)result >= v4 );
if ( v5 )
{
do
{
v7 = (unsigned int)a2[v2 / v5];
v2 %= v5;
my_char(v7);
v8 = v5;
result = v5 / v4;
v5 /= v4;
}
while ( v4 <= v8 );
}
}
}
return result;
}

original_code:
void my_num_base(int in, char* base)
{
  int r;
  unsigned int e;
  unsigned int u;
  if((r=my_strlen(base))>0)
    {
      if(in<0)
 {
   my_char('-');
   u=-in;
 }
      if(r==1)
 {
   while(u-->0)
     my_char(*base);
 }
      else
 {
   for(e=1;(u/e)>=r;e*=r)
     ;
   for(;e;u%=e,e/=r)
     {
       my_char(base[u/e]);
     }
 }
    }
  else
    {
      my_str("YOUR BASE IS SHIT\n");
    }
}

canonical_original_code:
void my_num_base(int in, char *base)
{
  int r;
  unsigned int e;
  unsigned int u;
  if((r=my_strlen(base))>0)
    {
      if(in<0)
 {
   my_char('-');
   u=-in;
 }
      if(r==1)
 {
   while(u-->0)
     my_char(*base);
 }
      else
 {
   for(e=1;(u/e)>=r;e*=r)
     ;
   for(;e;u%=e,e/=r)
     {
       my_char(base[u/e]);
     }
 }
    }
  else
    {
      my_str("YOUR BASE IS SHIT\n");
    }
}

variable_types: in int

variable_types:
base
char *

variable_types: r int

variable_types:
e
unsigned int

variable_types:
u
unsigned int


xmalloc

decompiled_code:
void *__fastcall xmalloc(int a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
my_str("VIRTUAL MEMORY EXHASUTED\n");
exit(1);
}
return result;
}

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

result = malloc(a1);
if ( !result )
{
my_str("VIRTUAL MEMORY EXHASUTED\n");
exit(1);
}
return result;
}

original_code:
void *xmalloc(int n)
{
  void *p;
  p=malloc(n);
  if (p==0)
    {
      my_str("VIRTUAL MEMORY EXHASUTED\n");
      exit(1);
    }
  return p;
}

variable_types:
p
void *

return_type: void *


decompiled_code:
__int64 __fastcall my_str(_BYTE *a1)
{
_BYTE *v1; // rbx
__int64 result; // rax

if ( a1 && *a1 )
{
v1 = a1 + 1;
do
result = my_char();
while ( *v1++ );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
_BYTE *v1; // rbx
__int64 result; // rax

if ( a1 && *a1 )
{
v1 = a1 + 1;
do
result = my_char();
while ( *v1++ );
}
return result;
}

original_code:
void my_str(char* str)
{
  int i=0;
  if (str != ((void *)0))
    {
      while(str[i]!='\0')
 {
   my_char(str[i++]);
 }
    }
}

canonical_original_code:
void my_str(char *str)
{
  int i = 0;
  if (str != ((void *)0))
    {
      while(str[i]!='\0')
 {
   my_char(str[i++]);
 }
    }
}


decompiled_code:
__int64 __fastcall my_strcat(__int64 a1, char *a2)
{
__int64 v2; // rax
char v3; // dl
char *v4; // rbx

LODWORD(v2) = my_strlen();
if ( a1 )
{
if ( a2 )
{
v3 = *a2;
if ( *a2 )
{
v2 = (int)v2;
v4 = &a2[-(int)v2];
do
{
*(_BYTE *)(a1 + v2++) = v3;
v3 = v4[v2];
}
while ( v3 );
}
}
}
return a1;
}

original_code:
char* my_strcat(char* s1, char* s2)
{
  int i=my_strlen(s1);
  int j=0;
  if(s1==((void *)0))
    return ((void *)0);
  if(s2==((void *)0))
    return s1;
  while(s2[j]!='\0')
    {
      s1[i]=s2[j];
      i++;
      j++;
    }
  return s1;
}

canonical_original_code:
char *my_strcat(char *s1, char *s2)
{
  int i = my_strlen(s1);
  int j = 0;
  if(s1==((void *)0))
    return ((void *)0);
  if(s2==((void *)0))
    return s1;
  while(s2[j]!='\0')
    {
      s1[i]=s2[j];
      i++;
      j++;
    }
  return s1;
}


decompiled_code:
__int64 my_alpha()
{
unsigned int i; // ebx
__int64 v1; // rdi
__int64 result; // rax

for ( i = 97; i != 123; ++i )
{
v1 = i;
result = my_char(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int i; // ebx
__int64 v1; // rdi
__int64 result; // rax

for ( i = 97; i != 123; ++i )
{
v1 = i;
result = my_char(v1);
}
return result;
}

original_code:
void my_alpha()
{
  char i='a';
  for(i;i<='z';i++)
    {
      my_char(i);
    }
}

canonical_original_code:
void my_alpha()
{
  char i = 'a';
  for(i;i<='z';i++)
    {
      my_char(i);
    }
}

variable_types: i char


decompiled_code:
__int64 __fastcall add_elem(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = new_node(a1, 0LL);
return add_node(v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = new_node(a1, 0LL);
return add_node(v2, a2);
}

original_code:
void add_elem(void* in, t_node** head)
{
  add_node(new_node(in, ((void *)0)), head);
}

canonical_original_code:
void add_elem(void *in, struct s_node **head)
{
  add_node(new_node(in, ((void *)0)), head);
}

variable_types:
in
void *

variable_types: struct s_node { struct s_node *next; void *elem; } **


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

if ( a1 && *a1 )
{
do
result = remove_node(a1);
while ( *a1 );
}
return result;
}

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

if ( a1 && *a1 )
{
do
result = remove_node(a1);
while ( *a1 );
}
return result;
}

original_code:
void empty_list(t_node** list)
{
  if(list==((void *)0))
    return;
  while(*list!=((void *)0))
    remove_node(list);
}

canonical_original_code:
void empty_list(struct s_node **list)
{
  if(list==((void *)0))
    return;
  while(*list!=((void *)0))
    remove_node(list);
}


decompiled_code:
__int64 __fastcall my_int(int a1)
{
int v1; // ebx
__int64 result; // rax
unsigned int v3; // edx
unsigned int v4; // ebx
unsigned int v5; // ecx
unsigned int v6; // er12
unsigned int v7; // edx

v1 = a1;
if ( a1 < 0 )
{
v1 = -a1;
my_char(45LL);
}
result = (unsigned int)v1;
v3 = v1 / 0xAu;
if ( v1 <= 9 )
return my_char((unsigned __int8)(v1 + 48));
v4 = 1;
do
{
v5 = v3;
v4 *= 10;
v3 /= 0xAu;
}
while ( v5 > 9 );
if ( v4 )
{
do
{
v6 = (unsigned int)result % v4;
my_char((unsigned int)(char)((unsigned int)result / v4 + 48));
v7 = v4;
result = v6;
v4 /= 0xAu;
}
while ( v7 > 9 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // ebx
__int64 result; // rax
unsigned int v3; // edx
unsigned int v4; // ebx
unsigned int v5; // ecx
unsigned int v6; // er12
unsigned int v7; // edx

v1 = a1;
if ( a1 < 0 )
{
v1 = -a1;
my_char(45LL);
}
result = (unsigned int)v1;
v3 = v1 / 0xAu;
if ( v1 <= 9 )
return my_char((unsigned __int8)(v1 + 48));
v4 = 1;
do
{
v5 = v3;
v4 *= 10;
v3 /= 0xAu;
}
while ( v5 > 9 );
if ( v4 )
{
do
{
v6 = (unsigned int)result % v4;
my_char((unsigned int)(char)((unsigned int)result / v4 + 48));
v7 = v4;
result = v6;
v4 /= 0xAu;
}
while ( v7 > 9 );
}
return result;
}

original_code:
void my_int(int in)
{
  unsigned int temp;
  unsigned int exp=1;
  if (in<0)
    {
      my_char('-');
      in = -in;
    }
  for(exp=1, temp=in; temp/=10;temp!=0, exp*=10);
  for(temp=in; exp!=0; temp%=exp,exp/=10)
    {
      my_char(temp/exp+'0');
    }
}

canonical_original_code:
void my_int(int in)
{
  unsigned int temp;
  unsigned int exp = 1;
  if (in<0)
    {
      my_char('-');
      in = -in;
    }
  for(exp=1, temp=in; temp/=10;temp!=0, exp*=10);
  for(temp=in; exp!=0; temp%=exp,exp/=10)
    {
      my_char(temp/exp+'0');
    }
}

variable_types:
temp
unsigned int

variable_types:
exp
unsigned int


original_code:
char* my_strnconcat(char* s1, char* s2, int n)
{
  int i=0;
  int j=0;
  int lens1=my_strlen(s1);
  int lens2=my_strlen(s2);
  if(n>lens2)
    {
      n=lens2;
    }
  char* s3 = (char*)xmalloc(lens1+n+1);
  if(s1==((void *)0) && s2==((void *)0))
    return ((void *)0);
  if(s2==((void *)0))
    return s1;
  if(s1==((void *)0))
    return s3=s2;
  for(i;i<lens1;i++)
    {
      s3[i]=s1[i];
    }
  for(j;j<n;i++,j++)
    {
      s3[i]=s2[j];
    }
  s3[i]='\0';
  return s3;
}

canonical_original_code:
char *my_strnconcat(char *s1, char *s2, int n)
{
  int i = 0;
  int j = 0;
  int lens1 = my_strlen(s1);
  int lens2 = my_strlen(s2);
  if(n>lens2)
    {
      n=lens2;
    }
  char *s3 = (char*)xmalloc(lens1+n+1);
  if(s1==((void *)0) && s2==((void *)0))
    return ((void *)0);
  if(s2==((void *)0))
    return s1;
  if(s1==((void *)0))
    return s3=s2;
  for(i;i<lens1;i++)
    {
      s3[i]=s1[i];
    }
  for(j;j<n;i++,j++)
    {
      s3[i]=s2[j];
    }
  s3[i]='\0';
  return s3;
}

variable_types: n int

variable_types: i int

variable_types: j int


original_code:
char* my_vect2str(char** vect)
{
  char* str;
  int i;
  int length;
  int total;
  if(vect==((void *)0))
    return ((void *)0);
  if(*vect==((void *)0))
    return ((void *)0);
  for(i=0,length=0;vect[i]!=((void *)0);i++)
    {
      length+=my_strlen(vect[i]);
    }
  str = (char*)xmalloc((length+1)*sizeof(char));
  for(total=0,i=0;vect[i]!=((void *)0);i++)
    {
      for(length=0;vect[i][length]!='\0';length++,total++)
 {
   str[total] = vect[i][length];
 }
      str[total++] = ' ';
    }
  str[total-1] = '\0';
  return str;
}

canonical_original_code:
char *my_vect2str(char **vect)
{
  char *str;
  int i;
  int length;
  int total;
  if(vect==((void *)0))
    return ((void *)0);
  if(*vect==((void *)0))
    return ((void *)0);
  for(i=0,length=0;vect[i]!=((void *)0);i++)
    {
      length+=my_strlen(vect[i]);
    }
  str = (char *)xmalloc((length+1)*sizeof(char));
  for(total=0,i=0;vect[i]!=((void *)0);i++)
    {
      for(length=0;vect[i][length]!='\0';length++,total++)
 {
   str[total] = vect[i][length];
 }
      str[total++] = ' ';
    }
  str[total-1] = '\0';
  return str;
}

variable_types:
vect
char **

variable_types:
str
char *

variable_types: length int

variable_types: total int


decompiled_code:
__int64 my_digits()
{
unsigned int i; // ebx
__int64 v1; // rdi
__int64 result; // rax

for ( i = 48; i != 58; ++i )
{
v1 = i;
result = my_char(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int i; // ebx
__int64 v1; // rdi
__int64 result; // rax

for ( i = 48; i != 58; ++i )
{
v1 = i;
result = my_char(v1);
}
return result;
}

original_code:
void my_digits()
{
  char i='0';
  for(i;i<='9';i++)
    {
      my_char(i);
    }
}

canonical_original_code:
void my_digits()
{
  char i = '0';
  for(i;i<='9';i++)
    {
      my_char(i);
    }
}


decompiled_code:
__int64 __fastcall my_strrindex(char *a1, char a2)
{
char v2; // dl
__int64 v3; // rax
unsigned int v4; // er8

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v3 = 0LL;
v4 = -1;
do
{
if ( a2 == v2 )
v4 = v3;
v2 = a1[++v3];
}
while ( v2 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char a2)
{
char v2; // dl
__int64 v3; // rax
unsigned int v4; // er8

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v3 = 0LL;
v4 = -1;
do
{
if ( a2 == v2 )
v4 = v3;
v2 = a1[++v3];
}
while ( v2 );
return v4;
}

original_code:
int my_strrindex(char* str, char c)
{
  int i;
  int pos;
  if(str==((void *)0))
    return -1;
  for(i=0,pos=-1;str[i]!='\0';i++)
    {
      if(c==str[i])
 pos=i;
    }
  return pos;
}

canonical_original_code:
int my_strrindex(char *str, char c)
{
  int i;
  int pos;
  if(str==((void *)0))
    return -1;
  for(i=0,pos=-1;str[i]!='\0';i++)
    {
      if(c==str[i])
 pos=i;
    }
  return pos;
}

variable_types: c char

variable_types: pos int


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

if ( (int)my_strlen(a2) < a3 || a3 < 0 )
result = 0LL;
else
result = my_strnconcat(a1, a2, (unsigned int)a3);
return result;
}

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

if ( (int)my_strlen(a2) < a3 || a3 < 0 )
result = 0LL;
else
result = my_strnconcat(a1, a2, (unsigned int)a3);
return result;
}

original_code:
char* my_stdstrnconcat(char* s1, char* s2, int n)
{
  int lens2=my_strlen(s2);
  if(n>lens2 || n<0)
    return ((void *)0);
  return my_strnconcat(s1, s2, n);
}

canonical_original_code:
char *my_stdstrnconcat(char *s1, char *s2, int n)
{
  int lens2 = my_strlen(s2);
  if(n>lens2 || n<0)
    return ((void *)0);
  return my_strnconcat(s1, s2, n);
}


decompiled_code:
__int64 __fastcall my_strncmp(__int64 a1, __int64 a2, int a3)
{
__int64 i; // rax
char v5; // cl
char v6; // dl

my_strlen(a2);
if ( a3 < 0 || a1 == 0 || !a2 )
return 0xFFFFFFFFLL;
if ( a3 )
{
for ( i = 0LL; i != a3; ++i )
{
v6 = *(_BYTE *)(a1 + i);
if ( !v6 )
break;
v5 = *(_BYTE *)(a2 + i);
if ( !v5 )
break;
if ( v6 > v5 )
return 1LL;
if ( v6 < v5 )
return 0xFFFFFFFFLL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3)
{
__int64 i; // rax
char v5; // cl
char v6; // dl

my_strlen(a2);
if ( a3 < 0 || a1 == 0 || !a2 )
return 0xFFFFFFFFLL;
if ( a3 )
{
for ( i = 0LL; i != a3; ++i )
{
v6 = *(_BYTE *)(a1 + i);
if ( !v6 )
break;
v5 = *(_BYTE *)(a2 + i);
if ( !v5 )
break;
if ( v6 > v5 )
return 1LL;
if ( v6 < v5 )
return 0xFFFFFFFFLL;
}
}
return 0LL;
}

original_code:
int my_strncmp(char* s1, char* s2, int n)
{
  int i=0;
  int length=my_strlen(s2);
  if(s1==((void *)0)||s2==((void *)0))
    return -1;
  if(n<0)
    return -1;
  while((i<n) && (s1[i]!='\0') && (s2[i]!='\0'))
    {
      if (s1[i]>s2[i])
 return 1;
      if (s1[i]<s2[i])
 return -1;
      i++;
    }
  return 0;
}

canonical_original_code:
int my_strncmp(char *s1, char *s2, int n)
{
  int i = 0;
  int length = my_strlen(s2);
  if(s1==((void *)0)||s2==((void *)0))
    return -1;
  if(n<0)
    return -1;
  while((i<n) && (s1[i]!='\0') && (s2[i]!='\0'))
    {
      if (s1[i]>s2[i])
 return 1;
      if (s1[i]<s2[i])
 return -1;
      i++;
    }
  return 0;
}


decompiled_code:
__int64 __fastcall traverse_char(__int64 **a1)
{
__int64 **v1; // rbx
__int64 result; // rax

v1 = a1;
for ( result = my_str("Printing Linked List: "); v1; v1 = (__int64 **)*v1 )
{
my_char((unsigned int)*(char *)v1[1]);
result = my_char(32LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 **a1)
{
__int64 **v1; // rbx
__int64 result; // rax

v1 = a1;
for ( result = my_str("Printing Linked List: "); v1; v1 = (__int64 **)*v1 )
{
my_char((unsigned int)*(char *)v1[1]);
result = my_char(32LL);
}
return result;
}

original_code:
void traverse_char(t_node* head)
{
  t_node* node = head;
  my_str("Printing Linked List: ");
  while(node!=((void *)0))
    {
      my_char(*(char*)node->elem);
      my_char(' ');
      node=node->next;
    }
}

canonical_original_code:
void traverse_char(struct s_node *head)
{
  struct s_node *node = head;
  my_str("Printing Linked List: ");
  while(node!=((void *)0))
    {
      my_char(*(char *)node->elem);
      my_char(' ');
      node=node->next;
    }
}

variable_types: struct s_node { struct s_node *next; void *elem; } *


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

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

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

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

original_code:
int count_nodes(t_node* head)
{
  int count=0;
  if(head==((void *)0))
    return;
  while(head!=((void *)0))
    {
      head=head->next;
      count++;
    }
  return count;
}

canonical_original_code:
int count_nodes(struct s_node *head)
{
  int count = 0;
  if(head==((void *)0))
    return;
  while(head!=((void *)0))
    {
      head=head->next;
      count++;
    }
  return count;
}

variable_types: count int


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall elem_at(_QWORD *a1, int a2)
{
__int64 result; // rax

if ( a1 )
{
if ( a2 > 0 )
{
while ( *a1 )
*(_QWORD *)elem_at = *a1;
result = *(_QWORD *)((char *)&loc_7 + 1);
}
else
{
result = a1[1];
}
}
return result;
}

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

if ( a1 )
{
if ( a2 > 0 )
{
while ( *a1 )
*(_QWORD *)elem_at = *a1;
result = *(_QWORD *)((char *)&loc_7 + 1);
}
else
{
result = a1[1];
}
}
return result;
}

original_code:
void* elem_at(t_node* node, int n)
{
  int i;
  t_node* temp;
  if(node==((void *)0))
    return;
  if(n<=0)
    return node->elem;
  for(i=1;i<n,node->next!=((void *)0);i++)
    {
      temp->next = node->next;
    }
  return temp->elem;
}

canonical_original_code:
void *elem_at(struct s_node *node, int n)
{
  int i;
  struct s_node *temp;
  if(node==((void *)0))
    return;
  if(n<=0)
    return node->elem;
  for(i=1;i<n,node->next!=((void *)0);i++)
    {
      temp->next = node->next;
    }
  return temp->elem;
}


decompiled_code:
char *__fastcall my_rfind(char *a1, char a2)
{
char v2; // dl
__int64 v3; // rax
int v4; // ecx

if ( !a1 )
return 0LL;
v2 = *a1;
if ( !*a1 )
return a1 - 1;
v3 = 0LL;
v4 = -1;
do
{
if ( a2 == v2 )
v4 = v3;
v2 = a1[++v3];
}
while ( v2 );
return &a1[v4];
}

canonical_decompiled_code:
char *__fastcall func0(char *a1, char a2)
{
char v2; // dl
__int64 v3; // rax
int v4; // ecx

if ( !a1 )
return 0LL;
v2 = *a1;
if ( !*a1 )
return a1 - 1;
v3 = 0LL;
v4 = -1;
do
{
if ( a2 == v2 )
v4 = v3;
v2 = a1[++v3];
}
while ( v2 );
return &a1[v4];
}

original_code:
char* my_rfind(char* str, char c)
{
  int i;
  int pos;
  if(str==((void *)0))
    return ((void *)0);
  for(i=0,pos=-1;str[i]!='\0';i++)
    {
      if(c==str[i])
 pos=i;
    }
  return &str[pos];
}

canonical_original_code:
char *my_rfind(char *str, char c)
{
  int i;
  int pos;
  if(str==((void *)0))
    return ((void *)0);
  for(i=0,pos=-1;str[i]!='\0';i++)
    {
      if(c==str[i])
 pos=i;
    }
  return &str[pos];
}


decompiled_code:
__int64 __fastcall my_strdup(__int64 a1)
{
int v1; // ebx
__int64 v2; // rax
__int64 v3; // r8
__int64 i; // rax

v1 = my_strlen();
v2 = xmalloc((unsigned int)(v1 + 1));
if ( !a1 )
return 0LL;
v3 = v2;
if ( v1 > 0 )
{
for ( i = 0LL; i != v1; ++i )
*(_BYTE *)(v3 + i) = *(_BYTE *)(a1 + i);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // ebx
__int64 v2; // rax
__int64 v3; // r8
__int64 i; // rax

v1 = my_strlen();
v2 = xmalloc((unsigned int)(v1 + 1));
if ( !a1 )
return 0LL;
v3 = v2;
if ( v1 > 0 )
{
for ( i = 0LL; i != v1; ++i )
*(_BYTE *)(v3 + i) = *(_BYTE *)(a1 + i);
}
return v3;
}

original_code:
char* my_strdup(char* str)
{
  int len = my_strlen(str);
  char* str2 = (char*)xmalloc(len+1);
  int i;
  if (str==((void *)0))
    return ((void *)0);
  for(i=0;i<len;i++)
    {
      str2[i]=str[i];
    }
  return str2;
}

canonical_original_code:
char *my_strdup(char *str)
{
  int len = my_strlen(str);
  char *str2 = (char*)xmalloc(len+1);
  int i;
  if (str==((void *)0))
    return ((void *)0);
  for(i=0;i<len;i++)
    {
      str2[i]=str[i];
    }
  return str2;
}

variable_types: len int


decompiled_code:
__int64 __fastcall my_revstr(__int64 a1)
{
int v2; // eax
int v3; // edi
unsigned int v4; // er12
int v5; // edx
__int64 v6; // rax
char *v7; // rdx
char v8; // si
char v9; // cl

v2 = my_strlen();
v3 = v2 / 2;
if ( !a1 )
return (unsigned int)-1;
v4 = v2;
if ( v2 > 1 )
{
v5 = v2 - 1;
v6 = 0LL;
v7 = (char *)(a1 + v5);
do
{
v8 = *v7;
v9 = *(_BYTE *)(a1 + v6);
--v7;
*(_BYTE *)(a1 + v6++) = v8;
v7[1] = v9;
}
while ( v3 > (int)v6 );
}
my_str(a1);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v2; // eax
int v3; // edi
unsigned int v4; // er12
int v5; // edx
__int64 v6; // rax
char *v7; // rdx
char v8; // si
char v9; // cl

v2 = my_strlen();
v3 = v2 / 2;
if ( !a1 )
return (unsigned int)-1;
v4 = v2;
if ( v2 > 1 )
{
v5 = v2 - 1;
v6 = 0LL;
v7 = (char *)(a1 + v5);
do
{
v8 = *v7;
v9 = *(_BYTE *)(a1 + v6);
--v7;
*(_BYTE *)(a1 + v6++) = v8;
v7[1] = v9;
}
while ( v3 > (int)v6 );
}
my_str(a1);
return v4;
}

original_code:
int my_revstr(char* str)
{
  char temp;
  int i=0;
  int len=my_strlen(str);
  int end;
  int halfway = len/2;
  if(str==((void *)0))
    return -1;
  for(i;i<halfway;i++)
    {
      end = len-1-i;
      temp = str[i];
      str[i] = str[end];
      str[end] = temp;
    }
  my_str(str);
  return len;
}

canonical_original_code:
int my_revstr(char *str)
{
  char temp;
  int i = 0;
  int len = my_strlen(str);
  int end;
  int halfway = len/2;
  if(str==((void *)0))
    return -1;
  for(i;i<halfway;i++)
    {
      end = len-1-i;
      temp = str[i];
      str[i] = str[end];
      str[end] = temp;
    }
  my_str(str);
  return len;
}

variable_types: temp char

variable_types: end int

variable_types: halfway int


bg

decompiled_code:
void bg()
{
int v0[266]; // [rsp+0h] [rbp-428h] BYREF

if ( (unsigned int)findlaststopped(v0) == 1 )
{
if ( killpg(v0[1], 18) == -1 )
perror("killpg() error");
else
qchangestate((unsigned int)v0[0], 1LL);
}
else
{
puts("Background Queue is empty or no background processes are stopped");
}
}

canonical_decompiled_code:
void func0()
{
int v0[266]; // [rsp+0h] [rbp-428h] BYREF

if ( (unsigned int)findlaststopped(v0) == 1 )
{
if ( killpg(v0[1], 18) == -1 )
perror("killpg() error");
else
qchangestate((unsigned int)v0[0], 1LL);
}
else
{
puts("Background Queue is empty or no background processes are stopped");
}
}

original_code:
void bg(){
 struct BGProc lsproc;
 if(findlaststopped(&lsproc) == 1){
  if(killpg(lsproc.pgid,18) == -1)
   perror("killpg() error");
  else
  {
   qchangestate(lsproc.pid, 1);
  }
 }
 else
 {
  printf("Background Queue is empty or no background processes are stopped\n");
 }
}

variable_types: struct BGProc { int pid; int pgid; char command[1024]; enum STATE { stopped=0, running=1 } state; enum VIS { background=0, foreground=1 } visibility; struct BGProc *next; struct BGProc *prev; }

user_defined_types: struct BGProc { int pid; int pgid; char command[1024]; enum STATE state; enum VIS visibility; struct BGProc *next; struct BGProc *prev; }


bringLastBGtoFG

decompiled_code:
void bringLastBGtoFG()
{
int stat_loc; // [rsp+Ch] [rbp-42Ch] BYREF
__pid_t pid; // [rsp+10h] [rbp-428h] BYREF
__pid_t pgrp; // [rsp+14h] [rbp-424h]
char v3[1056]; // [rsp+18h] [rbp-420h] BYREF

removehead(&pid);
setFGProc((unsigned int)pid, (unsigned int)pgrp, v3);
if ( killpg(pgrp, 18) == -1 )
{
perror("killpg() error");
}
else
{
tcsetpgrp(0, pgrp);
waitpid(pid, &stat_loc, 2);
tcsetpgrp(0, shellPID);
tcsetpgrp(1, shellPID);
tcsetpgrp(2, shellPID);
}
}

canonical_decompiled_code:
void func1()
{
int stat_loc; // [rsp+Ch] [rbp-42Ch] BYREF
__pid_t pid; // [rsp+10h] [rbp-428h] BYREF
__pid_t pgrp; // [rsp+14h] [rbp-424h]
char v3[1056]; // [rsp+18h] [rbp-420h] BYREF

removehead(&pid);
setFGProc((unsigned int)pid, (unsigned int)pgrp, v3);
if ( killpg(pgrp, 18) == -1 )
{
perror("killpg() error");
}
else
{
tcsetpgrp(0, pgrp);
waitpid(pid, &stat_loc, 2);
tcsetpgrp(0, shellPID);
tcsetpgrp(1, shellPID);
tcsetpgrp(2, shellPID);
}
}

original_code:
void bringLastBGtoFG(){
 int status;
 struct BGProc last;
 removehead(&last);
 setFGProc(last.pid, last.pgid, last.command);
 if(killpg(last.pgid,18) == -1)
  perror("killpg() error");
 else{
  tcsetpgrp(0, last.pgid);
  waitpid(last.pid, &status, 2);
  tcsetpgrp(0, shellPID);
  tcsetpgrp(1, shellPID);
  tcsetpgrp(2, shellPID);
 }
}

variable_types: status int


fg

decompiled_code:
void fg()
{
bringLastBGtoFG();
}

canonical_decompiled_code:
void func2()
{
func1();
}

original_code:
void fg(){
 bringLastBGtoFG();
}

canonical_original_code:
void fg(){
 bringLastBGtoFG();
}


sendToFG

decompiled_code:
void __fastcall sendToFG(__int64 a1)
{
unsigned int v1; // [rsp+0h] [rbp-428h] BYREF
__pid_t pgrp_id; // [rsp+4h] [rbp-424h]
char v3[1056]; // [rsp+8h] [rbp-420h] BYREF

if ( (unsigned int)remqueue(a1, &v1) == 1 )
{
if ( tcsetpgrp(0, pgrp_id) == -1 )
perror("setpgid() error");
else
setFGProc(v1, (unsigned int)pgrp_id, v3);
}
else
{
puts("Process is not in background");
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
unsigned int v1; // [rsp+0h] [rbp-428h] BYREF
__pid_t pgrp_id; // [rsp+4h] [rbp-424h]
char v3[1056]; // [rsp+8h] [rbp-420h] BYREF

if ( (unsigned int)remqueue(a1, &v1) == 1 )
{
if ( tcsetpgrp(0, pgrp_id) == -1 )
perror("setpgid() error");
else
setFGProc(v1, (unsigned int)pgrp_id, v3);
}
else
{
puts("Process is not in background");
}
}

original_code:
void sendToFG(pid_t pid){
 struct BGProc tofg;
 if(remqueue(pid, &tofg) == 1){
  if(tcsetpgrp(0, tofg.pgid) != -1){
   setFGProc(tofg.pid, tofg.pgid, tofg.command);
  }
  else
   perror("setpgid() error");
 }
 else
 {
  printf("Process is not in background\n");
 }
}

canonical_original_code:
void sendToFG(int pid){
 struct BGProc tofg;
 if(remqueue(pid, &tofg) == 1){
  if(tcsetpgrp(0, tofg.pgid) != -1){
   setFGProc(tofg.pid, tofg.pgid, tofg.command);
  }
  else
   perror("setpgid() error");
 }
 else
 {
  printf("Process is not in background\n");
 }
}

variable_types: pid int


sendToBG

decompiled_code:
__int64 __fastcall sendToBG(unsigned int a1, __int64 a2)
{
unsigned int v2; // eax

v2 = getpgid(a1);
enqueue(a1, v2, a2);
return setFGProc((unsigned int)shellPID, (unsigned int)shellPID, "Shell");
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2)
{
unsigned int v2; // eax

v2 = getpgid(a1);
enqueue(a1, v2, a2);
return setFGProc((unsigned int)shellPID, (unsigned int)shellPID, "Shell");
}

original_code:
void sendToBG(pid_t pid, char* com){
 enqueue(pid, getpgid(pid), com);
 setFGProc(shellPID, shellPID, "Shell");
}

canonical_original_code:
void sendToBG(int pid, char *com){
 enqueue(pid, getpgid(pid), com);
 setFGProc(shellPID, shellPID, "Shell");
}

variable_types:
com
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rdi
int v4; // eax
int v5; // ebx
__pid_t v6; // eax
unsigned int v7; // er12
unsigned int v8; // eax
int v10; // eax
int v11; // er13
size_t v12; // r12
void *v13; // rsp
void *v14; // rsp
_BYTE v15[12]; // [rsp+0h] [rbp-440h] BYREF
int stat_loc; // [rsp+Ch] [rbp-434h] BYREF
char buf[1072]; // [rsp+10h] [rbp-430h] BYREF

v3 = (unsigned int)((_DWORD)&sigAction + 8);
shname = (__int64)"kinda-sh";
memset((void *)v3, 0, 0x90uLL);
sigAction.sa_handler = (__sighandler_t)&signal_handler;
sigAction.sa_flags = 268435460;
queue_init(v3 + 144, argv);
msgbuffer_init();
shellPID = getpid();
while ( 1 )
{
do
{
while ( 1 )
{
msgbuffer_tostring();
printf("%s> ", (const char *)shname);
fflush(stdout);
stat_loc = 0;
sigaction(20, &sigAction, 0LL);
sigaction(2, &sigAction, 0LL);
v4 = read(0, buf, 0x400uLL);
stat_loc = v4;
v5 = v4;
if ( v4 != -1 )
break;
perror("READ ERROR");
}
}
while ( v4 <= 1 );
buf[v4] = 0;
if ( (unsigned int)cmp(buf, "exit\n") )
break;
if ( (unsigned int)cmp(buf, "help\n") )
{
puts("help");
}
else if ( (unsigned int)cmp(buf, "bg\n") )
{
bg();
}
else if ( (unsigned int)cmp(buf, "fg\n") || buf[0] == 20 )
{
fg();
}
else
{
v6 = fork();
v7 = v6;
if ( !v6 )
{
v10 = checkPipe(buf, (unsigned int)stat_loc);
stat_loc = v10;
v11 = v10;
if ( v10 >= 0 )
{
v12 = v5 - v10;
buf[v10] = 0;
v13 = alloca(v10);
v14 = alloca(v12);
memcpy(v15, buf, v10);
memcpy(v15, &buf[v11 + 1], v12);
processPipe(v15, v15);
}
else if ( v10 == -1 )
{
processCommand(buf);
}
exit(0);
}
if ( v6 <= 0 )
{
puts("Error: Could not create child");
}
else
{
sigaction(17, &sigAction, 0LL);
setpgid(v7, v7);
stat_loc = checkBG(buf);
if ( stat_loc == 1 )
{
sendToBG(v7, buf);
waitpid(v7, &stat_loc, 3);
}
else
{
v8 = getpgid(v7);
setFGProc(v7, v8, buf);
waitpid(v7, &stat_loc, 2);
}
}
}
}
return 0;
}

original_code:
int main(int argc, char* args[]){
 shname = "kinda-sh";
 int length;
 pid_t pid = -1;
 memset (&sigAction, '\0', sizeof(sigAction));
 sigAction.__sigaction_handler.sa_sigaction = signal_handler;
 sigAction.sa_flags = 4 | 0x10000000;
 queue_init();
 msgbuffer_init();
 if(pid != 0){
  shellPID = getpid();
 }
 while(1){
  msgbuffer_tostring();
  printf("%s> ", shname);
  fflush(stdout);
  char input[1024];
  int status = 0;
  sigaction(20, &sigAction, ((void *)0));
  sigaction(2, &sigAction, ((void *)0));
  status = read(0, input, 1024);
  if(status == -1){
   perror("READ ERROR");
  }
  else if(status <= 1){
   continue;
  }
  else{
   input[status] = '\0';
   length = status;
   if(cmp(input,"exit\n")){
    return 0;
   }
   else if(cmp(input,"help\n")){
    printf("help\n");
    continue;
   }
   else if(cmp(input,"bg\n")){
    bg();
    continue;
   }
   else if(cmp(input,"fg\n")){
    fg();
    continue;
   }
   else if(input[0] == 20){
    fg();
    continue;
   }
   pid = fork();
   if(pid==0){
    status = checkPipe(input, status);
    if(status > -1){
     char p1[status];
     char p2[length - status];
     input[status] = '\0';
     memcpy(p1, &input[0], status);
     memcpy(p2, &input[status +1], length - status);
     processPipe(p1, p2);
    }
    else if(status == -1){
     processCommand(input);
    }
    _exit(0);
   }
   else if(pid > 0){
    sigaction(17, &sigAction, ((void *)0));
    setpgid(pid, pid);
    status = checkBG(input);
    if(status == 1){
     sendToBG(pid, input);
     waitpid(pid, &status, 1|2);
    }
    else{
     setFGProc(pid, getpgid(pid), input);
     waitpid(pid, &status, 2);
    }
   }
   else
    printf("Error: Could not create child\n");
  }
 }
 free_queue();
 return 0;
}

canonical_original_code:
int main(int argc, char *args[]){
 shname = "kinda-sh";
 int length;
 int pid = -1;
 memset (&sigAction, '\0', sizeof(sigAction));
 sigAction.__sigaction_handler.sa_sigaction = signal_handler;
 sigAction.sa_flags = 4 | 0x10000000;
 queue_init();
 msgbuffer_init();
 if(pid != 0){
  shellPID = getpid();
 }
 while(1){
  msgbuffer_tostring();
  printf("%s> ", shname);
  fflush(stdout);
  char input[1024];
  int status = 0;
  sigaction(20, &sigAction, ((void *)0));
  sigaction(2, &sigAction, ((void *)0));
  status = read(0, input, 1024);
  if(status == -1){
   perror("READ ERROR");
  }
  else if(status <= 1){
   continue;
  }
  else{
   input[status] = '\0';
   length = status;
   if(cmp(input,"exit\n")){
    return 0;
   }
   else if(cmp(input,"help\n")){
    printf("help\n");
    continue;
   }
   else if(cmp(input,"bg\n")){
    bg();
    continue;
   }
   else if(cmp(input,"fg\n")){
    fg();
    continue;
   }
   else if(input[0] == 20){
    fg();
    continue;
   }
   pid = fork();
   if(pid==0){
    status = checkPipe(input, status);
    if(status > -1){
     char p1[-1];
     char p2[-1];
     input[status] = '\0';
     memcpy(p1, &input[0], status);
     memcpy(p2, &input[status +1], length - status);
     processPipe(p1, p2);
    }
    else if(status == -1){
     processCommand(input);
    }
    _exit(0);
   }
   else if(pid > 0){
    sigaction(17, &sigAction, ((void *)0));
    setpgid(pid, pid);
    status = checkBG(input);
    if(status == 1){
     sendToBG(pid, input);
     waitpid(pid, &status, 1|2);
    }
    else{
     setFGProc(pid, getpgid(pid), input);
     waitpid(pid, &status, 2);
    }
   }
   else
    printf("Error: Could not create child\n");
  }
 }
 free_queue();
 return 0;
}

variable_types: argc int

variable_types:
args
char *[]

variable_types:
input
char [1024]


cmp

decompiled_code:
__int64 __fastcall cmp(char *a1, __int64 a2)
{
char v2; // dl
__int64 v3; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, __int64 a2)
{
char v2; // dl
__int64 v3; // rax

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

variable_types: j int


decompiled_code:
__int64 queue_init()
{
void *v0; // rax
__int64 result; // rax

v0 = calloc(0x100uLL, 0x420uLL);
qhead = 0LL;
queue = v0;
result = 1LL;
qtail = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
void *v0; // rax
__int64 result; // rax

v0 = calloc(0x100uLL, 0x420uLL);
qhead = 0LL;
queue = v0;
result = 1LL;
qtail = 0LL;
return result;
}

original_code:
int queue_init(){
 if((long)(queue = calloc(256, sizeof(struct BGProc))) != -1){
  qhead = ((void *)0);
  qtail = ((void *)0);
  return 1;
 }
 else
 {
  printf("Error: Message Queue failed to initialize\n");
  return -1;
 }
}


qisempty

decompiled_code:
_BOOL8 qisempty()
{
return qhead == 0LL;
}

canonical_decompiled_code:
_BOOL8 func2()
{
return qhead == 0LL;
}

original_code:
int qisempty(){
 if(qhead==((void *)0))
  return 1;
 else
  return 0;
}


enqueue

original_code:
int enqueue(pid_t pid, pid_t pgid, char* command){
 struct BGProc* nproc;
 if((long)(nproc = malloc(sizeof(struct BGProc))) != -1){
  nproc->pid = pid;
  nproc->pgid = pgid;
  nproc->state = running;
  nproc->visibility = background;
  nproc->next = ((void *)0);
  nproc->prev = ((void *)0);
  int i = 0;
  while(command[i] != '\0'){
   nproc->command[i] = command[i];
   i++;
  }
  nproc->command[i]='\0';
  if(qisempty()){
   qtail = qhead = nproc;
   nproc->prev = ((void *)0);
   nproc->next = ((void *)0);
  }
  else
  {
   nproc->next = qhead;
   qhead->prev = nproc;
  }
  qhead = nproc;
  return 1;
 }
 else{
  printf("Memory alocation failed\n");
  return -1;
 }
}

canonical_original_code:
int enqueue(int pid, int pgid, char *command){
 struct BGProc *nproc;
 if((long)(nproc = malloc(sizeof(struct BGProc))) != -1){
  nproc->pid = pid;
  nproc->pgid = pgid;
  nproc->state = running;
  nproc->visibility = background;
  nproc->next = ((void *)0);
  nproc->prev = ((void *)0);
  int i = 0;
  while(command[i] != '\0'){
   nproc->command[i] = command[i];
   i++;
  }
  nproc->command[i]='\0';
  if(qisempty()){
   qtail = qhead = nproc;
   nproc->prev = ((void *)0);
   nproc->next = ((void *)0);
  }
  else
  {
   nproc->next = qhead;
   qhead->prev = nproc;
  }
  qhead = nproc;
  return 1;
 }
 else{
  printf("Memory alocation failed\n");
  return -1;
 }
}

variable_types: pgid int

variable_types:
command
char *

variable_types: struct BGProc { int pid; int pgid; char command[1024]; enum STATE { stopped=0, running=1 } state; enum VIS { background=0, foreground=1 } visibility; struct BGProc *next; struct BGProc *prev; } *

variable_types: i int


dequeue

decompiled_code:
__int64 __fastcall dequeue(_DWORD *a1)
{
_BOOL4 v1; // eax
__int64 v2; // rcx
_DWORD *v3; // r8
char v4; // dl
__int64 v5; // rax
__int64 result; // rax

v1 = qisempty();
v2 = v1;
if ( v1 )
{
puts("Message Queue is empty. No messages waiting");
result = 0xFFFFFFFFLL;
}
else
{
v3 = qtail;
*a1 = *(_DWORD *)qtail;
a1[1] = v3[1];
a1[258] = v3[258];
a1[259] = v3[259];
v4 = *((_BYTE *)v3 + 8);
if ( v4 )
{
v5 = 1LL;
do
{
*((_BYTE *)a1 + v5 + 7) = v4;
v2 = (int)v5++;
v4 = *((_BYTE *)v3 + v5 + 7);
}
while ( v4 );
}
*((_BYTE *)a1 + v2 + 8) = 0;
qtail = (void *)*((_QWORD *)v3 + 131);
free(v3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1)
{
_BOOL4 v1; // eax
__int64 v2; // rcx
_DWORD *v3; // r8
char v4; // dl
__int64 v5; // rax
__int64 result; // rax

v1 = func2();
v2 = v1;
if ( v1 )
{
puts("Message Queue is empty. No messages waiting");
result = 0xFFFFFFFFLL;
}
else
{
v3 = qtail;
*a1 = *(_DWORD *)qtail;
a1[1] = v3[1];
a1[258] = v3[258];
a1[259] = v3[259];
v4 = *((_BYTE *)v3 + 8);
if ( v4 )
{
v5 = 1LL;
do
{
*((_BYTE *)a1 + v5 + 7) = v4;
v2 = (int)v5++;
v4 = *((_BYTE *)v3 + v5 + 7);
}
while ( v4 );
}
*((_BYTE *)a1 + v2 + 8) = 0;
qtail = (void *)*((_QWORD *)v3 + 131);
free(v3);
result = 1LL;
}
return result;
}

original_code:
int dequeue(struct BGProc* dproc){
 if(!qisempty()){
  dproc->pid = qtail->pid;
  dproc->pgid = qtail->pgid;
  dproc->state = qtail->state;
  dproc->visibility = qtail->visibility;
  int i = 0;
  while(qtail->command[i] != '\0'){
   dproc->command[i] = qtail->command[i];
   i++;
  }
  dproc->command[i] = '\0';
  struct BGProc* tempTail = qtail;
  qtail = qtail->prev;
  free(tempTail);
  return 1;
 }
 else
 {
  printf("Message Queue is empty. No messages waiting\n");
  return -1;
 }
}

canonical_original_code:
int dequeue(struct BGProc *dproc){
 if(!qisempty()){
  dproc->pid = qtail->pid;
  dproc->pgid = qtail->pgid;
  dproc->state = qtail->state;
  dproc->visibility = qtail->visibility;
  int i = 0;
  while(qtail->command[i] != '\0'){
   dproc->command[i] = qtail->command[i];
   i++;
  }
  dproc->command[i] = '\0';
  struct BGProc *tempTail = qtail;
  qtail = qtail->prev;
  free(tempTail);
  return 1;
 }
 else
 {
  printf("Message Queue is empty. No messages waiting\n");
  return -1;
 }
}


decompiled_code:
__int64 free_queue()
{
while ( !qisempty() )
dequeue(0LL);
free(queue);
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
while ( !func2() )
func4(0LL);
free(queue);
return 1LL;
}

original_code:
int free_queue(){
 while(!qisempty()){dequeue(((void *)0));}
 free(queue);
 return 1;
}


remqueue

decompiled_code:
__int64 __fastcall remqueue(int a1, _DWORD *a2)
{
_BOOL4 v2; // eax
__int64 v3; // r8
_BYTE *v4; // r9
_QWORD *v6; // rcx
_QWORD *v7; // rdi
__int64 v8; // rax
__int64 v9; // rdx
__int64 result; // rax

v2 = qisempty();
v3 = v2;
if ( v2 )
{
puts("Background queue is empty");
result = 0xFFFFFFFFLL;
}
else
{
v4 = qtail;
v6 = qtail;
v7 = qtail;
if ( qtail )
{
while ( 1 )
{
v8 = v7[131];
if ( *(_DWORD *)v7 == a1 )
break;
v6 = v7;
if ( !v8 )
goto LABEL_12;
v7 = (_QWORD *)v7[131];
}
*a2 = a1;
a2[1] = *((_DWORD *)v7 + 1);
a2[258] = *((_DWORD *)v7 + 258);
a2[259] = *((_DWORD *)v7 + 259);
v9 = 1LL;
v6[131] = v8;
if ( v4[8] )
{
do
{
v3 = (int)v9;
*((_BYTE *)a2 + v9 + 7) = *((_BYTE *)v7 + v9 + 7);
++v9;
}
while ( v4[v9 + 7] );
}
*((_BYTE *)a2 + v3 + 8) = 0;
if ( v8 )
*(_QWORD *)(v8 + 1040) = v7[130];
free(v7);
result = 1LL;
}
else
{
LABEL_12:
puts("child not in queue");
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, _DWORD *a2)
{
_BOOL4 v2; // eax
__int64 v3; // r8
_BYTE *v4; // r9
_QWORD *v6; // rcx
_QWORD *v7; // rdi
__int64 v8; // rax
__int64 v9; // rdx
__int64 result; // rax

v2 = func2();
v3 = v2;
if ( v2 )
{
puts("Background queue is empty");
result = 0xFFFFFFFFLL;
}
else
{
v4 = qtail;
v6 = qtail;
v7 = qtail;
if ( qtail )
{
while ( 1 )
{
v8 = v7[131];
if ( *(_DWORD *)v7 == a1 )
break;
v6 = v7;
if ( !v8 )
goto LABEL_12;
v7 = (_QWORD *)v7[131];
}
*a2 = a1;
a2[1] = *((_DWORD *)v7 + 1);
a2[258] = *((_DWORD *)v7 + 258);
a2[259] = *((_DWORD *)v7 + 259);
v9 = 1LL;
v6[131] = v8;
if ( v4[8] )
{
do
{
v3 = (int)v9;
*((_BYTE *)a2 + v9 + 7) = *((_BYTE *)v7 + v9 + 7);
++v9;
}
while ( v4[v9 + 7] );
}
*((_BYTE *)a2 + v3 + 8) = 0;
if ( v8 )
*(_QWORD *)(v8 + 1040) = v7[130];
free(v7);
result = 1LL;
}
else
{
LABEL_12:
puts("child not in queue");
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int remqueue(pid_t pid, struct BGProc* dproc){
 if(!qisempty()){
  struct BGProc* temptail = qtail;
  struct BGProc* tempProc = temptail;
  while(temptail != ((void *)0) && temptail->pid != pid){
   tempProc = temptail;
   temptail = temptail->prev;
  }
  if(temptail != ((void *)0) && temptail->pid == pid){
   dproc->pid = temptail->pid;
   dproc->pgid = temptail->pgid;
   dproc->state = temptail->state;
   dproc->visibility = temptail->visibility;
   tempProc->prev = temptail->prev;
   int i = 0;
   while(qtail->command[i] != '\0'){
    dproc->command[i] = temptail->command[i];
    i++;
   }
   dproc->command[i] = '\0';
   if(tempProc->prev != ((void *)0))
    tempProc->prev->next = temptail->next;
   free(temptail);
   return 1;
  }
  else
  {
   printf("child not in queue\n");
   return -1;
  }
 }
 else
 {
  printf("Background queue is empty\n");
  return -1;
 }
}

canonical_original_code:
int remqueue(int pid, struct BGProc *dproc){
 if(!qisempty()){
  struct BGProc *temptail = qtail;
  struct BGProc *tempProc = temptail;
  while(temptail != ((void *)0) && temptail->pid != pid){
   tempProc = temptail;
   temptail = temptail->prev;
  }
  if(temptail != ((void *)0) && temptail->pid == pid){
   dproc->pid = temptail->pid;
   dproc->pgid = temptail->pgid;
   dproc->state = temptail->state;
   dproc->visibility = temptail->visibility;
   tempProc->prev = temptail->prev;
   int i = 0;
   while(qtail->command[i] != '\0'){
    dproc->command[i] = temptail->command[i];
    i++;
   }
   dproc->command[i] = '\0';
   if(tempProc->prev != ((void *)0))
    tempProc->prev->next = temptail->next;
   free(temptail);
   return 1;
  }
  else
  {
   printf("child not in queue\n");
   return -1;
  }
 }
 else
 {
  printf("Background queue is empty\n");
  return -1;
 }
}


findlaststopped

original_code:
int findlaststopped(struct BGProc* dproc){
 if(!qisempty()){
  struct BGProc* tempHead = qhead;
  while(tempHead != ((void *)0)){
   if(tempHead->state == stopped){
    dproc->pid = tempHead->pid;
    dproc->pgid = tempHead->pgid;
    int i = 0;
    while(tempHead->command[i] != '\0'){
     dproc->command[i] = tempHead->command[i];
     i++;
    }
    dproc->command[i] = '\0';
    return 1;
   }
   else
   {
    tempHead = tempHead->next;
   }
  }
  return -1;
 }
 else
 {
  return -1;
 }
}

canonical_original_code:
int findlaststopped(struct BGProc *dproc){
 if(!qisempty()){
  struct BGProc *tempHead = qhead;
  while(tempHead != ((void *)0)){
   if(tempHead->state == stopped){
    dproc->pid = tempHead->pid;
    dproc->pgid = tempHead->pgid;
    int i = 0;
    while(tempHead->command[i] != '\0'){
     dproc->command[i] = tempHead->command[i];
     i++;
    }
    dproc->command[i] = '\0';
    return 1;
   }
   else
   {
    tempHead = tempHead->next;
   }
  }
  return -1;
 }
 else
 {
  return -1;
 }
}


removehead

original_code:
int removehead(struct BGProc* dproc){
 if(!qisempty()){
  dproc->pid = qhead->pid;
  dproc->pgid = qhead->pgid;
  dproc->state = qhead->state;
  dproc->visibility = qhead->visibility;
  int i = 0;
  while(qhead->command[i] != '\0'){
   dproc->command[i] = qhead->command[i];
   i++;
  }
  dproc->command[i] = '\0';
  struct BGProc* temphead = qhead;
  if(qhead->next != ((void *)0))
   qhead->next->prev = qhead->prev;
  qhead = qhead->next;
  free(temphead);
  return 1;
 }
 else
 {
  return -1;
 }
}

canonical_original_code:
int removehead(struct BGProc *dproc){
 if(!qisempty()){
  dproc->pid = qhead->pid;
  dproc->pgid = qhead->pgid;
  dproc->state = qhead->state;
  dproc->visibility = qhead->visibility;
  int i = 0;
  while(qhead->command[i] != '\0'){
   dproc->command[i] = qhead->command[i];
   i++;
  }
  dproc->command[i] = '\0';
  struct BGProc *temphead = qhead;
  if(qhead->next != ((void *)0))
   qhead->next->prev = qhead->prev;
  qhead = qhead->next;
  free(temphead);
  return 1;
 }
 else
 {
  return -1;
 }
}


qchangestate

decompiled_code:
__int64 __fastcall qchangestate(int a1, int a2)
{
unsigned int v2; // er8
_DWORD *v3; // rax

if ( qisempty() )
return v2;
v3 = qhead;
if ( !qhead )
return v2;
do
{
if ( *v3 == a1 )
{
v3[258] = a2;
return 1;
}
v3 = (_DWORD *)*((_QWORD *)v3 + 130);
}
while ( v3 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
unsigned int v2; // er8
_DWORD *v3; // rax

if ( func2() )
return v2;
v3 = qhead;
if ( !qhead )
return v2;
do
{
if ( *v3 == a1 )
{
v3[258] = a2;
return 1;
}
v3 = (_DWORD *)*((_QWORD *)v3 + 130);
}
while ( v3 );
return 0xFFFFFFFFLL;
}

original_code:
int qchangestate(pid_t pid, int state){
 if(!qisempty()){
  struct BGProc* tempHead = qhead;
  while(tempHead != ((void *)0)){
   if(tempHead->pid == pid){
    tempHead->state = state;
    return 1;
   }
   else
   {
    tempHead = tempHead->next;
   }
  }
  return -1;
 }
 else
 {
  return -1;
 }
}

canonical_original_code:
int qchangestate(int pid, int state){
 if(!qisempty()){
  struct BGProc *tempHead = qhead;
  while(tempHead != ((void *)0)){
   if(tempHead->pid == pid){
    tempHead->state = state;
    return 1;
   }
   else
   {
    tempHead = tempHead->next;
   }
  }
  return -1;
 }
 else
 {
  return -1;
 }
}

variable_types: state int


qchangevis

decompiled_code:
__int64 __fastcall qchangevis(int a1, int a2)
{
unsigned int v2; // er8
_DWORD *v3; // rax

if ( qisempty() )
return v2;
v3 = qhead;
if ( !qhead )
return v2;
do
{
if ( *v3 == a1 )
{
v3[259] = a2;
return 1;
}
v3 = (_DWORD *)*((_QWORD *)v3 + 130);
}
while ( v3 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
unsigned int v2; // er8
_DWORD *v3; // rax

if ( func2() )
return v2;
v3 = qhead;
if ( !qhead )
return v2;
do
{
if ( *v3 == a1 )
{
v3[259] = a2;
return 1;
}
v3 = (_DWORD *)*((_QWORD *)v3 + 130);
}
while ( v3 );
return 0xFFFFFFFFLL;
}

original_code:
int qchangevis(pid_t pid, int vis){
 if(!qisempty()){
  struct BGProc* tempHead = qhead;
  while(tempHead != ((void *)0)){
   if(tempHead->pid == pid){
    tempHead->visibility = vis;
    return 1;
   }
   else
   {
    tempHead = tempHead->next;
   }
  }
  return -1;
 }
 else
 {
  return -1;
 }
}

canonical_original_code:
int qchangevis(int pid, int vis){
 if(!qisempty()){
  struct BGProc *tempHead = qhead;
  while(tempHead != ((void *)0)){
   if(tempHead->pid == pid){
    tempHead->visibility = vis;
    return 1;
   }
   else
   {
    tempHead = tempHead->next;
   }
  }
  return -1;
 }
 else
 {
  return -1;
 }
}

variable_types: vis int


findqproc

decompiled_code:
__int64 __fastcall findqproc(int a1)
{
void *v1; // rdx
_BOOL4 v2; // er8
__int64 result; // rax
_QWORD *v4; // rsi

v2 = qisempty();
result = 0xFFFFFFFFLL;
if ( !v2 )
{
v4 = qhead;
if ( qhead )
{
do
{
if ( *(_DWORD *)v4 == a1 )
{
result = 1LL;
qmemcpy(v1, v4, 0x420uLL);
return result;
}
v4 = (_QWORD *)v4[130];
}
while ( v4 );
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
void *v1; // rdx
_BOOL4 v2; // er8
__int64 result; // rax
_QWORD *v4; // rsi

v2 = func2();
result = 0xFFFFFFFFLL;
if ( !v2 )
{
v4 = qhead;
if ( qhead )
{
do
{
if ( *(_DWORD *)v4 == a1 )
{
result = 1LL;
qmemcpy(v1, v4, 0x420uLL);
return result;
}
v4 = (_QWORD *)v4[130];
}
while ( v4 );
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int findqproc(pid_t pid, bgproc* dproc){
 if(!qisempty()){
  struct BGProc* tempHead = qhead;
  while(tempHead != ((void *)0)){
   if(tempHead->pid == pid){
    *dproc = *tempHead;
    return 1;
   }
   else
   {
    tempHead = tempHead->next;
   }
  }
  return -1;
 }
 else
 {
  return -1;
 }
}

canonical_original_code:
int findqproc(int pid, struct BGProc *dproc){
 if(!qisempty()){
  struct BGProc *tempHead = qhead;
  while(tempHead != ((void *)0)){
   if(tempHead->pid == pid){
    *dproc = *tempHead;
    return 1;
   }
   else
   {
    tempHead = tempHead->next;
   }
  }
  return -1;
 }
 else
 {
  return -1;
 }
}


decompiled_code:
__int64 msgbuffer_init()
{
msgbufferpos = 0;
bgmsgbuffer = (__int64)calloc(0x400uLL, 8uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 func12()
{
msgbufferpos = 0;
bgmsgbuffer = (__int64)calloc(0x400uLL, 8uLL);
return 1LL;
}

original_code:
int msgbuffer_init(){
 msgbufferpos = 0;
 if((long)(bgmsgbuffer = calloc(1024, sizeof(char*))) != -1)
  return 1;
 else
  return -1;
}

canonical_original_code:
int msgbuffer_init(){
 msgbufferpos = 0;
 if((long)(bgmsgbuffer = calloc(1024, sizeof(char *))) != -1)
  return 1;
 else
  return -1;
}


decompiled_code:
__int64 __fastcall insert_msgbuffer(char *a1)
{
const char *v1; // rax
char v2; // dl
const char *v3; // rsi
__int64 v4; // rax
__int64 v5; // rax

v1 = (const char *)malloc(9uLL);
v2 = *a1;
v3 = v1;
if ( *a1 )
{
v4 = 0LL;
do
{
v3[v4++] = v2;
v2 = a1[v4];
}
while ( v2 );
v1 = &v3[v4];
}
*v1 = 0;
v5 = msgbufferpos++;
*(_QWORD *)(bgmsgbuffer + 8 * v5) = v3;
printf("string buffered is: %s\n", v3);
return 8LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1)
{
const char *v1; // rax
char v2; // dl
const char *v3; // rsi
__int64 v4; // rax
__int64 v5; // rax

v1 = (const char *)malloc(9uLL);
v2 = *a1;
v3 = v1;
if ( *a1 )
{
v4 = 0LL;
do
{
v3[v4++] = v2;
v2 = a1[v4];
}
while ( v2 );
v1 = &v3[v4];
}
*v1 = 0;
v5 = msgbufferpos++;
*(_QWORD *)(bgmsgbuffer + 8 * v5) = v3;
printf("string buffered is: %s\n", v3);
return 8LL;
}

original_code:
int insert_msgbuffer(char* msg){
 if(sizeof msg > 0){
  int i=0;
  char* com = malloc(sizeof msg+1);
  while(msg[i] != '\0'){
   com[i] = msg[i];
   i++;
  }
  com[i] = '\0';
  bgmsgbuffer[msgbufferpos++] = com;
  printf("string buffered is: %s\n", bgmsgbuffer[msgbufferpos-1]);
  return sizeof com;
 }
 else
 {
  printf("Background message buffer is full\n");
  return -1;
 }
}

canonical_original_code:
int insert_msgbuffer(char *msg){
 if(sizeof msg > 0){
  int i = 0;
  char *com = malloc(sizeof msg+1);
  while(msg[i] != '\0'){
   com[i] = msg[i];
   i++;
  }
  com[i] = '\0';
  bgmsgbuffer[msgbufferpos++] = com;
  printf("string buffered is: %s\n", bgmsgbuffer[msgbufferpos-1]);
  return sizeof com;
 }
 else
 {
  printf("Background message buffer is full\n");
  return -1;
 }
}

variable_types:
msg
char *


decompiled_code:
__int64 msgbuffer_tostring()
{
__int64 v0; // rbx
void *v1; // rdi

if ( !msgbufferpos )
return 0xFFFFFFFFLL;
puts("Queued messages from backgrounded processes");
if ( msgbufferpos > 0 )
{
v0 = 0LL;
do
{
puts(*(const char **)(bgmsgbuffer + 8 * v0));
v1 = *(void **)(bgmsgbuffer + 8 * v0++);
free(v1);
}
while ( msgbufferpos > (int)v0 );
}
msgbufferpos = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 v0; // rbx
void *v1; // rdi

if ( !msgbufferpos )
return 0xFFFFFFFFLL;
puts("Queued messages from backgrounded processes");
if ( msgbufferpos > 0 )
{
v0 = 0LL;
do
{
puts(*(const char **)(bgmsgbuffer + 8 * v0));
v1 = *(void **)(bgmsgbuffer + 8 * v0++);
free(v1);
}
while ( msgbufferpos > (int)v0 );
}
msgbufferpos = 0;
return 0LL;
}

original_code:
int msgbuffer_tostring(){
 if(msgbufferpos != 0){
  printf("Queued messages from backgrounded processes\n");
  int i = 0;
  while(i <msgbufferpos){
   printf("%s\n",bgmsgbuffer[i]);
   free(bgmsgbuffer[i]);
   i++;
  }
  msgbufferpos = 0;
  return 0;
 }
 else
 {
  return -1;
 }
}


setFGProc

decompiled_code:
__int64 __fastcall setFGProc(int a1, int a2, char *a3)
{
__int64 result; // rax
char v5; // dl
__int64 v6; // rax
__int64 v7; // rsi

result = 0xFFFFFFFFLL;
if ( a1 > 0 )
{
*(&fproc + 1) = a2;
fproc = a1;
v5 = *a3;
if ( v5 )
{
v6 = 1LL;
do
{
*((_BYTE *)&fproc + v6 + 7) = v5;
v7 = (int)v6++;
v5 = a3[v6 - 1];
}
while ( v5 );
}
else
{
v7 = 0LL;
}
*((_BYTE *)&fproc + v7 + 8) = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1, int a2, char *a3)
{
__int64 result; // rax
char v5; // dl
__int64 v6; // rax
__int64 v7; // rsi

result = 0xFFFFFFFFLL;
if ( a1 > 0 )
{
*(&fproc + 1) = a2;
fproc = a1;
v5 = *a3;
if ( v5 )
{
v6 = 1LL;
do
{
*((_BYTE *)&fproc + v6 + 7) = v5;
v7 = (int)v6++;
v5 = a3[v6 - 1];
}
while ( v5 );
}
else
{
v7 = 0LL;
}
*((_BYTE *)&fproc + v7 + 8) = 0;
result = 1LL;
}
return result;
}

original_code:
int setFGProc(pid_t pid, pid_t pgid, char* com){
 if(pid > 0){
  fproc.pgid = pgid;
  fproc.pid = pid;
  int i = 0;
  while(com[i] != '\0'){
   fproc.command[i] = com[i];
   i++;
  }
  fproc.command[i] = '\0';
  return 1;
 }
 else
 {
  return -1;
 }
}

canonical_original_code:
int setFGProc(int pid, int pgid, char *com){
 if(pid > 0){
  fproc.pgid = pgid;
  fproc.pid = pid;
  int i = 0;
  while(com[i] != '\0'){
   fproc.command[i] = com[i];
   i++;
  }
  fproc.command[i] = '\0';
  return 1;
 }
 else
 {
  return -1;
 }
}


getFGProc

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

result = 0xFFFFFFFFLL;
if ( a1 )
{
*a1 = fproc;
a1[1] = *(&fproc + 1);
v2 = *((_BYTE *)&fproc + 8);
if ( v2 )
{
v3 = 1LL;
do
{
*((_BYTE *)a1 + v3 + 7) = v2;
v4 = (int)v3;
v2 = *((_BYTE *)&fproc + v3++ + 8);
}
while ( v2 );
}
else
{
v4 = 0LL;
}
*((_BYTE *)a1 + v4 + 8) = 0;
result = 1LL;
}
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a1 )
{
*a1 = fproc;
a1[1] = *(&fproc + 1);
v2 = *((_BYTE *)&fproc + 8);
if ( v2 )
{
v3 = 1LL;
do
{
*((_BYTE *)a1 + v3 + 7) = v2;
v4 = (int)v3;
v2 = *((_BYTE *)&fproc + v3++ + 8);
}
while ( v2 );
}
else
{
v4 = 0LL;
}
*((_BYTE *)a1 + v4 + 8) = 0;
result = 1LL;
}
return result;
}

original_code:
int getFGProc(struct FGProc* fg){
 if(fg != ((void *)0)){
  fg->pid = fproc.pid;
  fg->pgid = fproc.pgid;
  int i = 0;
  while(fproc.command[i] != '\0'){
   fg->command[i] = fproc.command[i];
   i++;
  }
  fg->command[i] = '\0';
  return 1;
 }
 else
 {
  return -1;
 }
}

canonical_original_code:
int getFGProc(struct FGProc *fg){
 if(fg != ((void *)0)){
  fg->pid = fproc.pid;
  fg->pgid = fproc.pgid;
  int i = 0;
  while(fproc.command[i] != '\0'){
   fg->command[i] = fproc.command[i];
   i++;
  }
  fg->command[i] = '\0';
  return 1;
 }
 else
 {
  return -1;
 }
}

variable_types: struct FGProc { int pid; int pgid; char command[1024]; struct FGProc *next; } *


checkPipe

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

if ( a2 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_BYTE *)(a1 + result) != 124 )
{
if ( ++result == a2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

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

if ( a2 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_BYTE *)(a1 + result) != 124 )
{
if ( ++result == a2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
int checkPipe(char input[], int length){
 int i = 0;
 while(i < length){
  if(input[i] == '|')
   return i;
  else
   i++;
 }
 return -1;
}

variable_types:
input
char []

variable_types: length int


checkRed

decompiled_code:
void __fastcall checkRed(const char **a1, int a2)
{
const char *v2; // rdx
const char **i; // r12
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rbx
const char *v7; // rbx
int v8; // eax
int v9; // eax

v2 = *a1;
if ( *a1 )
{
for ( i = a1 + 1; ; ++i )
{
v4 = 1LL;
v5 = -1LL;
if ( *v2 )
{
do
v6 = v4++;
while ( v2[v4 - 1] );
v5 = v6 - 1;
}
v7 = &v2[v5];
if ( *v7 == 62 )
break;
if ( *v7 == 60 )
{
if ( a2 != 2 )
{
v9 = open(*(i - 2), 0);
if ( dup2(v9, 0) == -1 )
perror("Pipe Error");
puts("input redirected");
*v7 = 0;
goto LABEL_8;
}
goto LABEL_18;
}
LABEL_8:
v2 = *i;
if ( !v2 )
return;
}
if ( a2 != 1 )
{
puts("redirecting output");
v8 = open(*i, 65, 420LL);
if ( dup2(v8, 1) == -1 )
perror("Pipe error");
printf("output redirected to %s\n", *i);
*v7 = 0;
goto LABEL_8;
}
LABEL_18:
puts("Error: Overlapping Redirection");
goto LABEL_8;
}
}

canonical_decompiled_code:
void __fastcall func1(const char **a1, int a2)
{
const char *v2; // rdx
const char **i; // r12
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rbx
const char *v7; // rbx
int v8; // eax
int v9; // eax

v2 = *a1;
if ( *a1 )
{
for ( i = a1 + 1; ; ++i )
{
v4 = 1LL;
v5 = -1LL;
if ( *v2 )
{
do
v6 = v4++;
while ( v2[v4 - 1] );
v5 = v6 - 1;
}
v7 = &v2[v5];
if ( *v7 == 62 )
break;
if ( *v7 == 60 )
{
if ( a2 != 2 )
{
v9 = open(*(i - 2), 0);
if ( dup2(v9, 0) == -1 )
perror("Pipe Error");
puts("input redirected");
*v7 = 0;
goto LABEL_8;
}
goto LABEL_18;
}
LABEL_8:
v2 = *i;
if ( !v2 )
return;
}
if ( a2 != 1 )
{
puts("redirecting output");
v8 = open(*i, 65, 420LL);
if ( dup2(v8, 1) == -1 )
perror("Pipe error");
printf("output redirected to %s\n", *i);
*v7 = 0;
goto LABEL_8;
}
LABEL_18:
puts("Error: Overlapping Redirection");
goto LABEL_8;
}
}

original_code:
void checkRed(char** tokens, int proc){
 int i = 0;
 while(tokens[i] != ((void *)0)){
  char* arg = tokens[i];
  int j = 0;
  while(arg[j] != '\0'){
   j++;
  }
  if(arg[j-1] == '>'){
   if(proc == 1){
    printf("Error: Overlapping Redirection\n");
   }
   else{
    printf("redirecting output\n");
    int new_out = open(tokens[i+1], 01 | 0100 , 0644);
    if(dup2(new_out, 1)==-1)
     perror("Pipe error");
    printf("output redirected to %s\n", tokens[i+1]);
    arg[j-1] = '\0';
   }
  }
  else if(arg[j-1] == '<'){
   if(proc == 2){
    printf("Error: Overlapping Redirection\n");
   }
   else{
    int new_in = open(tokens[i-1], 00);
    if(dup2(new_in, 0)==-1)
     perror("Pipe Error");
    printf("input redirected\n");
    arg[j-1] = '\0';
   }
  }
  i++;
 }
 return;
}

canonical_original_code:
void checkRed(char **tokens, int proc){
 int i = 0;
 while(tokens[i] != ((void *)0)){
  char *arg = tokens[i];
  int j = 0;
  while(arg[j] != '\0'){
   j++;
  }
  if(arg[j-1] == '>'){
   if(proc == 1){
    printf("Error: Overlapping Redirection\n");
   }
   else{
    printf("redirecting output\n");
    int new_out = open(tokens[i+1], 01 | 0100 , 0644);
    if(dup2(new_out, 1)==-1)
     perror("Pipe error");
    printf("output redirected to %s\n", tokens[i+1]);
    arg[j-1] = '\0';
   }
  }
  else if(arg[j-1] == '<'){
   if(proc == 2){
    printf("Error: Overlapping Redirection\n");
   }
   else{
    int new_in = open(tokens[i-1], 00);
    if(dup2(new_in, 0)==-1)
     perror("Pipe Error");
    printf("input redirected\n");
    arg[j-1] = '\0';
   }
  }
  i++;
 }
 return;
}

variable_types:
tokens
char **

variable_types: proc int

variable_types:
arg
char *


getTokens

decompiled_code:
__int64 __fastcall getTokens(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 i; // rdi
__int64 v4; // rax
unsigned int v5; // er12

v2 = 1LL;
tokenizer = init_tokenizer();
for ( i = tokenizer; ; i = tokenizer )
{
v4 = get_next_token(i);
v5 = v2++;
tok = v4;
if ( !v4 )
break;
*(_QWORD *)(a2 + 8 * v2 - 16) = v4;
}
free_tokenizer(tokenizer);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 i; // rdi
__int64 v4; // rax
unsigned int v5; // er12

v2 = 1LL;
tokenizer = init_tokenizer();
for ( i = tokenizer; ; i = tokenizer )
{
v4 = get_next_token(i);
v5 = v2++;
tok = v4;
if ( !v4 )
break;
*(_QWORD *)(a2 + 8 * v2 - 16) = v4;
}
free_tokenizer(tokenizer);
return v5;
}

original_code:
int getTokens(char* input, char** tokens){
 tokenizer = init_tokenizer(input);
 int i = 0;
 while((tok = get_next_token(tokenizer)) != ((void *)0)){
  tokens[i++] = tok;
 }
 free_tokenizer(tokenizer);
 return i + 1;
}

canonical_original_code:
int getTokens(char *input, char **tokens){
 tokenizer = init_tokenizer(input);
 int i = 0;
 while((tok = get_next_token(tokenizer)) != ((void *)0)){
  tokens[i++] = tok;
 }
 free_tokenizer(tokenizer);
 return i + 1;
}

variable_types:
input
char *


checkBG

decompiled_code:
__int64 __fastcall checkBG(_BYTE *a1)
{
while ( 1 )
{
if ( !*a1 )
return 0LL;
if ( *a1 == 38 )
break;
++a1;
}
*a1 = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1)
{
while ( 1 )
{
if ( !*a1 )
return 0LL;
if ( *a1 == 38 )
break;
++a1;
}
*a1 = 0;
return 1LL;
}

original_code:
int checkBG(char* command){
 int j =0;
 while(command[j] != '\0'){
  if (command[j] == '&'){
    command[j] = '\0';
   return 1;
  }
  j++;
 }
  return 0;
}

canonical_original_code:
int checkBG(char *command){
 int j = 0;
 while(command[j] != '\0'){
  if (command[j] == '&'){
    command[j] = '\0';
   return 1;
  }
  j++;
 }
  return 0;
}


processCommand

decompiled_code:
__int64 __fastcall processCommand(_BYTE *a1)
{
tokens = (char **)calloc(0x100uLL, 8uLL);
status = checkBG(a1);
getTokens((__int64)a1, (__int64)tokens);
checkRed((const char **)tokens, 0);
status = execvp(*tokens, tokens);
if ( status == -1 )
perror("execvp error");
free(tokens);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1)
{
tokens = (char **)calloc(0x100uLL, 8uLL);
status = func3(a1);
func2((__int64)a1, (__int64)tokens);
func1((const char **)tokens, 0);
status = execvp(*tokens, tokens);
if ( status == -1 )
perror("execvp error");
free(tokens);
return 0LL;
}

original_code:
int processCommand(char* command){
 tokens = calloc(256, sizeof *tokens);
 status = checkBG(command);
 getTokens(command, tokens);
 checkRed(tokens, 0);
 status = execvp(tokens[0], tokens);
 if(status==-1)
  perror("execvp error");
 free(tokens);
 return(0);
}

canonical_original_code:
int processCommand(char *command){
 tokens = calloc(256, sizeof *tokens);
 status = checkBG(command);
 getTokens(command, tokens);
 checkRed(tokens, 0);
 status = execvp(tokens[0], tokens);
 if(status==-1)
  perror("execvp error");
 free(tokens);
 return(0);
}


processPipe

decompiled_code:
__pid_t __fastcall processPipe(_BYTE *a1, _BYTE *a2)
{
int v3; // edi
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

groupID = getpid();
if ( pipe(pipedes) == -1 )
perror("pipe(pipeFD) error");
if ( !fork() )
{
if ( close(pipedes[0]) == -1 )
{
perror("process 1, close(pipeFD[0] error");
v3 = pipedes[1];
if ( pipedes[1] == 1 )
{
LABEL_6:
processCommand(a1);
if ( close(pipedes[1]) == -1 )
{
perror("process 1 close(pipeFD[1]) error");
exit(0);
}
goto LABEL_7;
}
}
else
{
v3 = pipedes[1];
if ( pipedes[1] == 1 )
goto LABEL_6;
}
if ( dup2(v3, 1) == -1 )
perror("process 1 dup2(pipeFD[1],1) error");
goto LABEL_6;
}
if ( !fork() )
{
if ( close(pipedes[1] == -1) )
perror("process 2, close(pipeFD[1] error");
if ( pipedes[0] && dup2(pipedes[0], 0) == -1 )
perror("process 2 dup2(pipeFD[0],0) error");
processCommand(a2);
if ( close(pipedes[0] == -1) )
perror("process 2, close(pipeFD[0] error");
LABEL_7:
exit(0);
}
return wait((__WAIT_STATUS)&status);
}

canonical_decompiled_code:
__pid_t __fastcall func5(_BYTE *a1, _BYTE *a2)
{
int v3; // edi
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

groupID = getpid();
if ( pipe(pipedes) == -1 )
perror("pipe(pipeFD) error");
if ( !fork() )
{
if ( close(pipedes[0]) == -1 )
{
perror("process 1, close(pipeFD[0] error");
v3 = pipedes[1];
if ( pipedes[1] == 1 )
{
LABEL_6:
func4(a1);
if ( close(pipedes[1]) == -1 )
{
perror("process 1 close(pipeFD[1]) error");
exit(0);
}
goto LABEL_7;
}
}
else
{
v3 = pipedes[1];
if ( pipedes[1] == 1 )
goto LABEL_6;
}
if ( dup2(v3, 1) == -1 )
perror("process 1 dup2(pipeFD[1],1) error");
goto LABEL_6;
}
if ( !fork() )
{
if ( close(pipedes[1] == -1) )
perror("process 2, close(pipeFD[1] error");
if ( pipedes[0] && dup2(pipedes[0], 0) == -1 )
perror("process 2 dup2(pipeFD[0],0) error");
func4(a2);
if ( close(pipedes[0] == -1) )
perror("process 2, close(pipeFD[0] error");
LABEL_7:
exit(0);
}
return wait((__WAIT_STATUS)&status);
}

original_code:
void processPipe(char* process1, char* process2){
 groupID = getpid();
 int pipeFD[2];
 if(pipe(pipeFD)==-1)
  perror("pipe(pipeFD) error");
 pid_t pid = fork();
 if(pid == 0){
  if(close(pipeFD[0])==-1)
   perror("process 1, close(pipeFD[0] error");
  if(pipeFD[1] != 1){
   if(dup2(pipeFD[1],1)==-1)
    perror("process 1 dup2(pipeFD[1],1) error");
  }
  processCommand(process1);
  if(close(pipeFD[1])==-1)
   perror("process 1 close(pipeFD[1]) error");
  _exit(0);
 }
 else{
  pid = fork();
  if(pid == 0){
   if(close(pipeFD[1]==-1))
    perror("process 2, close(pipeFD[1] error");
   if(pipeFD[0] != 0){
    if(dup2(pipeFD[0],0)==-1)
     perror("process 2 dup2(pipeFD[0],0) error");
   }
   processCommand(process2);
   if(close(pipeFD[0]==-1))
    perror("process 2, close(pipeFD[0] error");
   _exit(0);
  }
  else{
   wait(&status);
  }
 }
}

canonical_original_code:
void processPipe(char *process1, char *process2){
 groupID = getpid();
 int pipeFD[2];
 if(pipe(pipeFD)==-1)
  perror("pipe(pipeFD) error");
 int pid = fork();
 if(pid == 0){
  if(close(pipeFD[0])==-1)
   perror("process 1, close(pipeFD[0] error");
  if(pipeFD[1] != 1){
   if(dup2(pipeFD[1],1)==-1)
    perror("process 1 dup2(pipeFD[1],1) error");
  }
  processCommand(process1);
  if(close(pipeFD[1])==-1)
   perror("process 1 close(pipeFD[1]) error");
  _exit(0);
 }
 else{
  pid = fork();
  if(pid == 0){
   if(close(pipeFD[1]==-1))
    perror("process 2, close(pipeFD[1] error");
   if(pipeFD[0] != 0){
    if(dup2(pipeFD[0],0)==-1)
     perror("process 2 dup2(pipeFD[0],0) error");
   }
   processCommand(process2);
   if(close(pipeFD[0]==-1))
    perror("process 2, close(pipeFD[0] error");
   _exit(0);
  }
  else{
   wait(&status);
  }
 }
}

variable_types:
pipeFD
int [2]

variable_types: pid int


decompiled_code:
void __fastcall free_tokenizer(void *ptr)
{
if ( !ptr )
_assert_fail("tokenizer != NULL", "tokenizer.c", 0x29u, "free_tokenizer");
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( !ptr )
_assert_fail("tokenizer != NULL", "tokenizer.c", 0x29u, "free_tokenizer");
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_tokenizer( TOKENIZER *tokenizer )
{
  ((void) sizeof ((tokenizer != ((void *)0)) ? 1 : 0), __extension__ ({ if (tokenizer != ((void *)0)) ; else __assert_fail ("tokenizer != NULL", "tokenizer.c", 41, __extension__ __PRETTY_FUNCTION__); }));
  free( tokenizer->str );
  free( tokenizer );
}

canonical_original_code:
void free_tokenizer(struct tokenizer *tokenizer)
{
  ((void) sizeof ((tokenizer != ((void *)0)) ? 1 : 0), __extension__ ({ if (tokenizer != ((void *)0)) ; else __assert_fail ("tokenizer != NULL", "tokenizer.c", 41, __extension__ __PRETTY_FUNCTION__); }));
  free( tokenizer->str );
  free( tokenizer );
}

variable_types: struct tokenizer { char *str; char *pos; } *


cleanrequest

decompiled_code:
char *__fastcall cleanrequest(const char *a1)
{
char *v1; // r12
char *v2; // rax

if ( !a1 )
return 0LL;
v1 = strdup(a1);
v2 = strchr(v1, 63);
if ( !v2 )
return v1;
*v2 = 0;
if ( v1 == v2 || *(v2 - 1) != 47 )
return v1;
*(v2 - 1) = 0;
return v1;
}

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

if ( !a1 )
return 0LL;
v1 = strdup(a1);
v2 = strchr(v1, 63);
if ( !v2 )
return v1;
*v2 = 0;
if ( v1 == v2 || *(v2 - 1) != 47 )
return v1;
*(v2 - 1) = 0;
return v1;
}

original_code:
char * cleanrequest( char * request_uri ) {
  char * r;
  char *p;
  if( !request_uri ) return ((void *)0);
  r = strdup(request_uri);
  p = strchr( r, '?' );
  if( p ) *p = 0;
  else return r;
  if( p != r && *(p-1) == '/' ) {
    *(p-1) = 0;
  }
  return r;
}

canonical_original_code:
char *cleanrequest(char *request_uri) {
  char *r;
  char *p;
  if( !request_uri ) return ((void *)0);
  r = strdup(request_uri);
  p = strchr( r, '?' );
  if( p ) *p = 0;
  else return r;
  if( p != r && *(p-1) == '/' ) {
    *(p-1) = 0;
  }
  return r;
}

variable_types:
r
char *

variable_types:
p
char *


dumpcgi

decompiled_code:
__int64 dumpcgi()
{
char **v0; // rbx
__int64 result; // rax
const char *v2; // rsi
char **v3; // rbx

v0 = environ;
result = FCGI_printf("Content-type: text/html\r\n\r\n");
v2 = *v0;
if ( *v0 )
{
v3 = v0 + 1;
do
{
++v3;
result = FCGI_printf("CGI: %s\n", v2);
v2 = *(v3 - 1);
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
char **v0; // rbx
__int64 result; // rax
const char *v2; // rsi
char **v3; // rbx

v0 = environ;
result = FCGI_printf("Content-type: text/html\r\n\r\n");
v2 = *v0;
if ( *v0 )
{
v3 = v0 + 1;
do
{
++v3;
result = FCGI_printf("CGI: %s\n", v2);
v2 = *(v3 - 1);
}
while ( v2 );
}
return result;
}

original_code:
void dumpcgi() {
  char **e = environ;
  int k=0;
  FCGI_printf("Content-type: text/html\r\n\r\n");
  while( e[k] ) {
    FCGI_printf( "CGI: %s\n", e[k] );
    k++;
  }
}

canonical_original_code:
void dumpcgi() {
  char **e = environ;
  int k = 0;
  FCGI_printf("Content-type: text/html\r\n\r\n");
  while( e[k] ) {
    FCGI_printf( "CGI: %s\n", e[k] );
    k++;
  }
}

variable_types:
e
char **

variable_types: k int


original_code:
static int free_rule( struct array_t *arr, int k, node *n ) {
  if( n->bits & 0x2 ) {
    struct rule_t *r = n->obj;
    free( r->display_name );
    free( n->obj );
  }
}

canonical_original_code:
static int free_rule(struct array_t *arr, int k, struct node_t *n) {
  if( n->bits & 0x2 ) {
    struct rule_t *r = n->obj;
    free( r->display_name );
    free( n->obj );
  }
}

variable_types: struct array_t { struct node_t { char *key; char *value; void *obj; int bits; char color_field; struct node_t *left; struct node_t *right; } *head; struct sglib_node_iterator { struct node_t *currentelem; char pass[128]; struct node_t *path[128]; short pathi; short order; struct node_t *equalto; int (*subcomparator)(struct node_t *, struct node_t *); } it; } *

variable_types:
n
struct node_t *

variable_types: struct rule_t { char *display_name; int rule; int ival; float fval; } *

user_defined_types: struct array_t { struct node_t *head; struct sglib_node_iterator it; }