decompiled_code:
void __fastcall Condition_print(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax

if ( a1 )
{
v1 = a1;
while ( 2 )
{
switch ( *(_DWORD *)v1 )
{
case 0:
Expression_print(*(_QWORD *)(v1 + 8));
printf(" = ");
goto LABEL_8;
case 1:
Expression_print(*(_QWORD *)(v1 + 8));
printf(" < ");
goto LABEL_8;
case 2:
Expression_print(*(_QWORD *)(v1 + 8));
printf(" > ");
goto LABEL_8;
case 3:
Expression_print(*(_QWORD *)(v1 + 8));
printf(" <= ");
goto LABEL_8;
case 4:
Expression_print(*(_QWORD *)(v1 + 8));
printf(" >= ");
LABEL_8:
Expression_print(*(_QWORD *)(v1 + 16));
return;
case 5:
Condition_print(*(_QWORD *)(v1 + 8));
printf(" and ");
v1 = *(_QWORD *)(v1 + 16);
goto LABEL_11;
case 6:
Condition_print(*(_QWORD *)(v1 + 8));
printf(" or ");
v1 = *(_QWORD *)(v1 + 16);
LABEL_11:
if ( !v1 )
return;
continue;
case 7:
v2 = *(_QWORD *)(v1 + 8);
if ( *(_DWORD *)v2 )
{
printf("not (");
Condition_print(*(_QWORD *)(v1 + 8));
putchar(41);
}
else
{
Expression_print(*(_QWORD *)(v2 + 8));
printf(" != ");
Expression_print(*(_QWORD *)(*(_QWORD *)(v1 + 8) + 16LL));
}
return;
case 8:
Expression_print(*(_QWORD *)(v1 + 8));
printf(" in ");
Literal_printList(*(_QWORD *)(v1 + 16));
return;
default:
puts("Unknown condession type");
return;
}
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax

if ( a1 )
{
v1 = a1;
while ( 2 )
{
switch ( *(_DWORD *)v1 )
{
case 0:
Expression_print(*(_QWORD *)(v1 + 8));
printf(" = ");
goto LABEL_8;
case 1:
Expression_print(*(_QWORD *)(v1 + 8));
printf(" < ");
goto LABEL_8;
case 2:
Expression_print(*(_QWORD *)(v1 + 8));
printf(" > ");
goto LABEL_8;
case 3:
Expression_print(*(_QWORD *)(v1 + 8));
printf(" <= ");
goto LABEL_8;
case 4:
Expression_print(*(_QWORD *)(v1 + 8));
printf(" >= ");
LABEL_8:
Expression_print(*(_QWORD *)(v1 + 16));
return;
case 5:
func0(*(_QWORD *)(v1 + 8));
printf(" and ");
v1 = *(_QWORD *)(v1 + 16);
goto LABEL_11;
case 6:
func0(*(_QWORD *)(v1 + 8));
printf(" or ");
v1 = *(_QWORD *)(v1 + 16);
LABEL_11:
if ( !v1 )
return;
continue;
case 7:
v2 = *(_QWORD *)(v1 + 8);
if ( *(_DWORD *)v2 )
{
printf("not (");
func0(*(_QWORD *)(v1 + 8));
putchar(41);
}
else
{
Expression_print(*(_QWORD *)(v2 + 8));
printf(" != ");
Expression_print(*(_QWORD *)(*(_QWORD *)(v1 + 8) + 16LL));
}
return;
case 8:
Expression_print(*(_QWORD *)(v1 + 8));
printf(" in ");
Literal_printList(*(_QWORD *)(v1 + 16));
return;
default:
puts("Unknown condession type");
return;
}
}
}
}

original_code:
void Condition_print(Condition_t *cond) {
   if (!cond) return;
   switch(cond->t) {
      case RA_COND_EQ:
         Expression_print(cond->cond.comp.expr1);
         printf(" = ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_LT:
         Expression_print(cond->cond.comp.expr1);
         printf(" < ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_GT:
         Expression_print(cond->cond.comp.expr1);
         printf(" > ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_LEQ:
         Expression_print(cond->cond.comp.expr1);
         printf(" <= ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_GEQ:
         Expression_print(cond->cond.comp.expr1);
         printf(" >= ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_AND:
         Condition_print(cond->cond.binary.cond1);
         printf(" and ");
         Condition_print(cond->cond.binary.cond2);
         break;
      case RA_COND_OR:
         Condition_print(cond->cond.binary.cond1);
         printf(" or ");
         Condition_print(cond->cond.binary.cond2);
         break;
      case RA_COND_NOT:
         if (cond->cond.unary.cond->t == RA_COND_EQ) {
            Expression_print(cond->cond.unary.cond->cond.comp.expr1);
            printf(" != ");
            Expression_print(cond->cond.unary.cond->cond.comp.expr2);
         } else {
            printf("not (");
            Condition_print(cond->cond.unary.cond);
            printf(")");
         }
         break;
      case RA_COND_IN:
         Expression_print(cond->cond.in.expr);
         printf(" in ");
         Literal_printList(cond->cond.in.values_list);
         break;
      default:
         puts("Unknown condession type");
   }
}

canonical_original_code:
void Condition_print(struct Condition_t *cond) {
   if (!cond) return;
   switch(cond->t) {
      case RA_COND_EQ:
         Expression_print(cond->cond.comp.expr1);
         printf(" = ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_LT:
         Expression_print(cond->cond.comp.expr1);
         printf(" < ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_GT:
         Expression_print(cond->cond.comp.expr1);
         printf(" > ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_LEQ:
         Expression_print(cond->cond.comp.expr1);
         printf(" <= ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_GEQ:
         Expression_print(cond->cond.comp.expr1);
         printf(" >= ");
         Expression_print(cond->cond.comp.expr2);
         break;
      case RA_COND_AND:
         Condition_print(cond->cond.binary.cond1);
         printf(" and ");
         Condition_print(cond->cond.binary.cond2);
         break;
      case RA_COND_OR:
         Condition_print(cond->cond.binary.cond1);
         printf(" or ");
         Condition_print(cond->cond.binary.cond2);
         break;
      case RA_COND_NOT:
         if (cond->cond.unary.cond->t == RA_COND_EQ) {
            Expression_print(cond->cond.unary.cond->cond.comp.expr1);
            printf(" != ");
            Expression_print(cond->cond.unary.cond->cond.comp.expr2);
         } else {
            printf("not (");
            Condition_print(cond->cond.unary.cond);
            printf(")");
         }
         break;
      case RA_COND_IN:
         Expression_print(cond->cond.in.expr);
         printf(" in ");
         Literal_printList(cond->cond.in.values_list);
         break;
      default:
         puts("Unknown condession type");
   }
}

variable_types: struct Condition_t { enum CondType { RA_COND_EQ=0, RA_COND_LT=1, RA_COND_GT=2, RA_COND_LEQ=3, RA_COND_GEQ=4, RA_COND_AND=5, RA_COND_OR=6, RA_COND_NOT=7, RA_COND_IN=8 } t; union { struct CondComp { struct Expression_s { enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 } t; union { struct ExprTerm { enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 } t; union { char *id; struct Literal_t { enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } t; union LitVal { int ival; double dval; char cval; char *strval; } val; struct Literal_t *next; } *val; struct ColumnReference_t { char *tableName; } *ref; struct Func { enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 } t; struct Expression_s *expr; } f; }; } term; struct ExprBinary { struct Expression_s *expr1; } binary; struct ExprUnary { struct Expression_s *expr; } unary; } expr; char *alias; struct Expression_s *next; } *expr1; } comp; struct CondBinary { struct Condition_t *cond1; } binary; struct CondUnary { struct Condition_t *cond; } unary; struct CondIn { struct Expression_s *expr; struct Literal_t *values_list; } in; } cond; } *

user_defined_types: struct Expression_s { enum ExprType t; union { struct ExprTerm term; struct ExprBinary binary; struct ExprUnary unary; } expr; char *alias; struct Expression_s *next; }


decompiled_code:
void __fastcall Condition_free(void *ptr)
{
unsigned int v1; // eax
void *v3; // rdi

v1 = *(_DWORD *)ptr;
if ( *(_DWORD *)ptr == 7 )
{
Condition_free(*((void **)ptr + 1));
free(ptr);
}
else if ( v1 > 7 )
{
if ( v1 != 8 )
goto LABEL_5;
Literal_freeList(*((_QWORD *)ptr + 2));
Expression_freeList(*((_QWORD *)ptr + 1));
free(ptr);
}
else
{
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v1 > 4 )
{
Condition_free(v3);
Condition_free(*((void **)ptr + 2));
LABEL_5:
free(ptr);
return;
}
free(v3);
free(*((void **)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
unsigned int v1; // eax
void *v3; // rdi

v1 = *(_DWORD *)ptr;
if ( *(_DWORD *)ptr == 7 )
{
func1(*((void **)ptr + 1));
free(ptr);
}
else if ( v1 > 7 )
{
if ( v1 != 8 )
goto LABEL_5;
Literal_freeList(*((_QWORD *)ptr + 2));
Expression_freeList(*((_QWORD *)ptr + 1));
free(ptr);
}
else
{
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v1 > 4 )
{
func1(v3);
func1(*((void **)ptr + 2));
LABEL_5:
free(ptr);
return;
}
free(v3);
free(*((void **)ptr + 2));
free(ptr);
}
}

original_code:
void Condition_free(Condition_t *cond) {
   switch (cond->t) {
      case RA_COND_EQ:
      case RA_COND_LEQ:
      case RA_COND_GEQ:
      case RA_COND_GT:
      case RA_COND_LT:
         free(cond->cond.comp.expr1);
         free(cond->cond.comp.expr2);
         break;
      case RA_COND_AND:
      case RA_COND_OR:
         Condition_free(cond->cond.binary.cond1);
         Condition_free(cond->cond.binary.cond2);
         break;
      case RA_COND_NOT:
         Condition_free(cond->cond.unary.cond);
         break;
      case RA_COND_IN:
         Literal_freeList(cond->cond.in.values_list);
         Expression_freeList(cond->cond.in.expr);
         break;
   }
   free(cond);
}

canonical_original_code:
void Condition_free(struct Condition_t *cond) {
   switch (cond->t) {
      case RA_COND_EQ:
      case RA_COND_LEQ:
      case RA_COND_GEQ:
      case RA_COND_GT:
      case RA_COND_LT:
         free(cond->cond.comp.expr1);
         free(cond->cond.comp.expr2);
         break;
      case RA_COND_AND:
      case RA_COND_OR:
         Condition_free(cond->cond.binary.cond1);
         Condition_free(cond->cond.binary.cond2);
         break;
      case RA_COND_NOT:
         Condition_free(cond->cond.unary.cond);
         break;
      case RA_COND_IN:
         Literal_freeList(cond->cond.in.values_list);
         Expression_freeList(cond->cond.in.expr);
         break;
   }
   free(cond);
}

return_type: void

user_defined_types: struct Condition_t { enum CondType t; union { struct CondComp comp; struct CondBinary binary; struct CondUnary unary; struct CondIn in; } cond; }

user_defined_types: enum CondType { RA_COND_EQ=0, RA_COND_LT=1, RA_COND_GT=2, RA_COND_LEQ=3, RA_COND_GEQ=4, RA_COND_AND=5, RA_COND_OR=6, RA_COND_NOT=7, RA_COND_IN=8 }

user_defined_types: struct CondComp { struct Expression_s *expr1; }

user_defined_types: struct CondBinary { struct Condition_t *cond1; }

user_defined_types: struct CondUnary { struct Condition_t *cond; }

user_defined_types: struct CondIn { struct Expression_s *expr; struct Literal_t *values_list; }

user_defined_types: enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 }

user_defined_types: struct ExprTerm { enum TermType t; union { char *id; struct Literal_t *val; struct ColumnReference_t *ref; struct Func f; }; }

user_defined_types: struct ExprBinary { struct Expression_s *expr1; }

user_defined_types: struct ExprUnary { struct Expression_s *expr; }

user_defined_types: enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 }

user_defined_types: struct Func { enum FuncType t; struct Expression_s *expr; }

user_defined_types: struct Literal_t { enum data_type t; union LitVal val; struct Literal_t *next; }

user_defined_types: struct ColumnReference_t { char *tableName; }

user_defined_types: enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 }

user_defined_types: enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 }

user_defined_types: union LitVal { int ival; double dval; char cval; char *strval; }


repo: thlorenz/cre-downloader

decompiled_code:
__int64 __fastcall name_from_url(const char *a1)
{
signed int v1; // eax
__int64 v3[1025]; // [rsp+0h] [rbp-2008h] BYREF

v1 = (unsigned int)strdup(a1);
return v3[(int)(strsplit(v1, v3, &unk_CF) - 1)];
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
signed int v1; // eax
__int64 v3[1025]; // [rsp+0h] [rbp-2008h] BYREF

v1 = (unsigned int)strdup(a1);
return v3[(int)(strsplit(v1, v3, &unk_CF) - 1)];
}

original_code:
char* name_from_url(char* url) {
  char* parts[1024];
  char *s = strdup(url);
  int len = strsplit(s, parts, "/");
  return parts[len -1];
}

canonical_original_code:
char *name_from_url(char *url) {
  char *parts[1024];
  char *s = strdup(url);
  int len = strsplit(s, parts, "/");
  return parts[len -1];
}

variable_types:
url
char *

variable_types:
parts
char *[1024]

variable_types:
s
char *

variable_types: len int

return_type: char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er14
int v5; // er13
__int64 v6; // rbx
int v7; // er12
const char *v9; // rdi
__int64 v10[4]; // [rsp+0h] [rbp-2048h] BYREF
_QWORD v11[1029]; // [rsp+20h] [rbp-2028h] BYREF

if ( argc > 1 )
{
v4 = strtol(argv[1], 0LL, 10);
if ( argc == 2 )
v5 = 0x7FFFFFFF;
else
v5 = strtol(argv[2], 0LL, 10);
download_url_buffer(v10, "http://cre.fm/archiv");
v3 = get_links(v10[0], v11);
if ( v5 <= v3 )
{
LABEL_5:
printf("Downloading episodes %d-%d\n", (unsigned int)v4, (unsigned int)v5);
LODWORD(v6) = v4 - 1;
v7 = v5 - 1;
if ( v5 <= v4 )
return 0;
goto LABEL_8;
}
LABEL_4:
v5 = v3 + 1;
goto LABEL_5;
}
download_url_buffer(v10, "http://cre.fm/archiv");
v3 = get_links(v10[0], v11);
if ( v3 != 0x7FFFFFFF )
{
v4 = 1;
goto LABEL_4;
}
LODWORD(v6) = 0;
v7 = 2147483646;
printf("Downloading episodes %d-%d\n", 1LL, 0x7FFFFFFFLL);
LABEL_8:
v6 = (int)v6;
do
{
v9 = (const char *)v11[v6++];
download_episode(v9);
}
while ( v7 > (int)v6 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er14
int v5; // er13
__int64 v6; // rbx
int v7; // er12
const char *v9; // rdi
__int64 v10[4]; // [rsp+0h] [rbp-2048h] BYREF
_QWORD v11[1029]; // [rsp+20h] [rbp-2028h] BYREF

if ( argc > 1 )
{
v4 = strtol(argv[1], 0LL, 10);
if ( argc == 2 )
v5 = 0x7FFFFFFF;
else
v5 = strtol(argv[2], 0LL, 10);
download_url_buffer(v10, "http://cre.fm/archiv");
v3 = get_links(v10[0], v11);
if ( v5 <= v3 )
{
LABEL_5:
printf("Downloading episodes %d-%d\n", (unsigned int)v4, (unsigned int)v5);
LODWORD(v6) = v4 - 1;
v7 = v5 - 1;
if ( v5 <= v4 )
return 0;
goto LABEL_8;
}
LABEL_4:
v5 = v3 + 1;
goto LABEL_5;
}
download_url_buffer(v10, "http://cre.fm/archiv");
v3 = get_links(v10[0], v11);
if ( v3 != 0x7FFFFFFF )
{
v4 = 1;
goto LABEL_4;
}
LODWORD(v6) = 0;
v7 = 2147483646;
printf("Downloading episodes %d-%d\n", 1LL, 0x7FFFFFFFLL);
LABEL_8:
v6 = (int)v6;
do
{
v9 = (const char *)v11[v6++];
func1(v9);
}
while ( v7 > (int)v6 );
return 0;
}

original_code:
int main(int argc, const char *argv[]) {
  char *links[1024];
  int from_episode = 1;
  int to_episode = 0x7fffffff;
  if (argc > 1) from_episode = strtol(argv[1], ((void *)0), 10);
  if (argc > 2) to_episode = strtol(argv[2], ((void *)0), 10);
  DownloadResult res = download_url_buffer("http://cre.fm/archiv");
  int len = get_links(res.html, links);
  to_episode = (((to_episode)<(len + 1))?(to_episode):(len + 1));
  printf("Downloading episodes %d-%d\n", from_episode, to_episode);
  from_episode--;
  to_episode--;
  for (int i = from_episode; i < to_episode; i++) {
    download_episode(links[i]);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  char *links[1024];
  int from_episode = 1;
  int to_episode = 0x7fffffff;
  if (argc > 1) from_episode = strtol(argv[1], ((void *)0), 10);
  if (argc > 2) to_episode = strtol(argv[2], ((void *)0), 10);
  struct DownloadResult res = download_url_buffer("http://cre.fm/archiv");
  int len = get_links(res.html, links);
  to_episode = (((to_episode)<(len + 1))?(to_episode):(len + 1));
  printf("Downloading episodes %d-%d\n", from_episode, to_episode);
  from_episode--;
  to_episode--;
  for (int i = from_episode; i < to_episode; i++) {
    download_episode(links[i]);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
links
char *[1024]

variable_types: struct DownloadResult { char *html; unsigned long size; long status; }

variable_types: i int

return_type: int


decompiled_code:
const unsigned __int16 **__fastcall get_episode(_BYTE *a1)
{
int v1; // ebx
char *v2; // rbp
int v3; // edx
__int64 v4; // rsi
const unsigned __int16 **result; // rax

v1 = (char)*a1;
if ( *a1 )
{
v2 = a1 + 1;
result = _ctype_b_loc();
v3 = 0;
v4 = (__int64)*result;
LODWORD(result) = 0;
do
{
while ( (*(_BYTE *)(v4 + 2LL * (char)v1 + 1) & 8) == 0 )
{
v1 = *v2++;
LODWORD(result) = 0;
v3 = 0;
if ( !(_BYTE)v1 )
return 0LL;
}
++v3;
result = (const unsigned __int16 **)(unsigned int)(v1 + 10 * (_DWORD)result - 48);
if ( v3 == 3 )
return result;
v1 = *v2++;
}
while ( (_BYTE)v1 );
}
return 0LL;
}

canonical_decompiled_code:
const unsigned __int16 **__fastcall func0(_BYTE *a1)
{
int v1; // ebx
char *v2; // rbp
int v3; // edx
__int64 v4; // rsi
const unsigned __int16 **result; // rax

v1 = (char)*a1;
if ( *a1 )
{
v2 = a1 + 1;
result = _ctype_b_loc();
v3 = 0;
v4 = (__int64)*result;
LODWORD(result) = 0;
do
{
while ( (*(_BYTE *)(v4 + 2LL * (char)v1 + 1) & 8) == 0 )
{
v1 = *v2++;
LODWORD(result) = 0;
v3 = 0;
if ( !(_BYTE)v1 )
return 0LL;
}
++v3;
result = (const unsigned __int16 **)(unsigned int)(v1 + 10 * (_DWORD)result - 48);
if ( v3 == 3 )
return result;
v1 = *v2++;
}
while ( (_BYTE)v1 );
}
return 0LL;
}

original_code:
static int get_episode(const char* s) {
  char c;
  int count = 0;
  int episode = 0;
  while((c = *(s++)) != '\0') {
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit)) {
      count++;
      episode = episode * 10 + (c - '0');
    } else {
      episode = count = 0;
    }
    if (count == 3) return episode;
  }
  return 0;
}

canonical_original_code:
static int get_episode(char *s) {
  char c;
  int count = 0;
  int episode = 0;
  while((c = *(s++)) != '\0') {
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit)) {
      count++;
      episode = episode * 10 + (c - '0');
    } else {
      episode = count = 0;
    }
    if (count == 3) return episode;
  }
  return 0;
}

variable_types: c char

variable_types: count int

variable_types: episode int


decompiled_code:
__int64 __fastcall compare_links(_BYTE **a1, _BYTE **a2)
{
unsigned int v2; // ebx

v2 = (unsigned int)get_episode(*a1);
return v2 - (unsigned int)get_episode(*a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE **a1, _BYTE **a2)
{
unsigned int v2; // ebx

v2 = (unsigned int)func0(*a1);
return v2 - (unsigned int)func0(*a2);
}

original_code:
int compare_links(const void* a, const void* b) {
  const char **ia = (const char **)a;
  const char **ib = (const char **)b;
  int ep1 = get_episode(*ia);
  int ep2 = get_episode(*ib);
  return ep1 - ep2;
}

canonical_original_code:
int compare_links(void *a, void *b) {
  char **ia = (const char **)a;
  char **ib = (const char **)b;
  int ep1 = get_episode(*ia);
  int ep2 = get_episode(*ib);
  return ep1 - ep2;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
ia
char **

variable_types:
ib
char **


decompiled_code:
size_t __fastcall write_chunk_to_memory(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v5; // r12
char *v6; // rax
_BYTE *v7; // rdx
size_t v8; // rax

v5 = a3 * a2;
v6 = (char *)realloc(*(void **)a4, a3 * a2 + *(_QWORD *)(a4 + 8) + 1);
*(_QWORD *)a4 = v6;
if ( v6 )
{
memcpy(&v6[*(_QWORD *)(a4 + 8)], src, v5);
v7 = *(_BYTE **)a4;
v8 = v5 + *(_QWORD *)(a4 + 8);
*(_QWORD *)(a4 + 8) = v8;
v7[v8] = 0;
}
else
{
v5 = 0LL;
puts("not enough memory (realloc returned NULL)");
}
return v5;
}

canonical_decompiled_code:
size_t __fastcall func0(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v5; // r12
char *v6; // rax
_BYTE *v7; // rdx
size_t v8; // rax

v5 = a3 * a2;
v6 = (char *)realloc(*(void **)a4, a3 * a2 + *(_QWORD *)(a4 + 8) + 1);
*(_QWORD *)a4 = v6;
if ( v6 )
{
memcpy(&v6[*(_QWORD *)(a4 + 8)], src, v5);
v7 = *(_BYTE **)a4;
v8 = v5 + *(_QWORD *)(a4 + 8);
*(_QWORD *)(a4 + 8) = v8;
v7[v8] = 0;
}
else
{
v5 = 0LL;
puts("not enough memory (realloc returned NULL)");
}
return v5;
}

original_code:
static size_t write_chunk_to_memory(void *contents, size_t size, size_t nmemb, void *userp) {
  size_t realsize = size * nmemb;
  MemoryStruct *mem = (MemoryStruct *)userp;
  mem->memory = realloc(mem->memory, mem->size + realsize + 1);
  if(mem->memory == ((void *)0)) {
    printf("not enough memory (realloc returned NULL)\n");
    return 0;
  }
  memcpy(&(mem->memory[mem->size]), contents, realsize);
  mem->size += realsize;
  mem->memory[mem->size] = 0;
  return realsize;
}

canonical_original_code:
static unsigned long write_chunk_to_memory(void *contents, unsigned long size, unsigned long nmemb, void *userp) {
  unsigned long realsize = size * nmemb;
  struct MemoryStruct *mem = (MemoryStruct *)userp;
  mem->memory = realloc(mem->memory, mem->size + realsize + 1);
  if(mem->memory == ((void *)0)) {
    printf("not enough memory (realloc returned NULL)\n");
    return 0;
  }
  memcpy(&(mem->memory[mem->size]), contents, realsize);
  mem->size += realsize;
  mem->memory[mem->size] = 0;
  return realsize;
}

variable_types:
contents
void *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
userp
void *

variable_types:
realsize
unsigned long

variable_types: struct MemoryStruct { char *memory; unsigned long size; } *

return_type: unsigned long


strsplit

decompiled_code:
__int64 __fastcall strsplit(char *a1, _QWORD *a2, const char *a3)
{
char *v4; // rbx
__int64 i; // rbx
unsigned int v6; // er13
char *v7; // rdi

v4 = strtok(a1, a3);
*a2 = (int)strdup(v4);
if ( !v4 )
return 1;
for ( i = 1LL; ; ++i )
{
v6 = i;
v7 = strtok(0LL, a3);
if ( !v7 )
break;
a2[i] = (int)strdup(v7);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, _QWORD *a2, const char *a3)
{
char *v4; // rbx
__int64 i; // rbx
unsigned int v6; // er13
char *v7; // rdi

v4 = strtok(a1, a3);
*a2 = (int)strdup(v4);
if ( !v4 )
return 1;
for ( i = 1LL; ; ++i )
{
v6 = i;
v7 = strtok(0LL, a3);
if ( !v7 )
break;
a2[i] = (int)strdup(v7);
}
return v6;
}

original_code:
int strsplit (char *str, char *parts[], char *delimiter) {
  char *pch;
  int i = 0;
  pch = strtok(str, delimiter);
  parts[i++] = strdup(pch);
  while (pch) {
    pch = strtok(((void *)0), delimiter);
    if (((void *)0) == pch) break;
    parts[i++] = strdup(pch);
  }
  free(pch);
  return i;
}

canonical_original_code:
int strsplit(char *str, char *parts[], char *delimiter) {
  char *pch;
  int i = 0;
  pch = strtok(str, delimiter);
  parts[i++] = strdup(pch);
  while (pch) {
    pch = strtok(((void *)0), delimiter);
    if (((void *)0) == pch) break;
    parts[i++] = strdup(pch);
  }
  free(pch);
  return i;
}

variable_types:
str
char *

variable_types:
parts
char *[]

variable_types:
delimiter
char *

variable_types:
pch
char *


isJobNull

repo: thomascampbelladams/dash

decompiled_code:
_BOOL8 __fastcall isJobNull(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
return a1 == 0;
}

original_code: int isJobNull(JobPtr job){ return job == ((void *)0); }

canonical_original_code: int isJobNull(struct job *job){ return job == ((void *)0); }

variable_types: struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *


isJobRunning

decompiled_code:
_BOOL8 __fastcall isJobRunning(__int64 a1)
{
return *(_DWORD *)(a1 + 20) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return *(_DWORD *)(a1 + 20) == 1;
}

original_code: int isJobRunning(JobPtr job){ return job->running == 1;}

canonical_original_code: int isJobRunning(struct job *job){ return job->running == 1;}

user_defined_types: struct job { int jobid; int jobNu; char *command; int status; int running; int background; }


isJobStopped

decompiled_code:
_BOOL8 __fastcall isJobStopped(__int64 a1)
{
return *(_DWORD *)(a1 + 20) == 2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_DWORD *)(a1 + 20) == 2;
}

original_code: int isJobStopped(JobPtr job){ return job->running == 2; }

canonical_original_code: int isJobStopped(struct job *job){ return job->running == 2; }


isJobInBackground

decompiled_code:
_BOOL8 __fastcall isJobInBackground(__int64 a1)
{
return *(_DWORD *)(a1 + 24) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
return *(_DWORD *)(a1 + 24) == 1;
}

original_code: int isJobInBackground(JobPtr job) { return job->background == 1; }

canonical_original_code: int isJobInBackground(struct job *job) { return job->background == 1; }


isJobDone

decompiled_code:
_BOOL8 __fastcall isJobDone(__int64 a1)
{
return *(_DWORD *)(a1 + 20) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
return *(_DWORD *)(a1 + 20) == 0;
}

original_code: int isJobDone(JobPtr job) { return job->running == 0; }

canonical_original_code: int isJobDone(struct job *job) { return job->running == 0; }


getStatusString

decompiled_code:
const char *__fastcall getStatusString(unsigned int a1)
{
const char *result; // rax

result = "Invalid";
if ( a1 <= 2 )
result = CSWTCH_7[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func5(unsigned int a1)
{
const char *result; // rax

result = "Invalid";
if ( a1 <= 2 )
result = CSWTCH_7[a1];
return result;
}

original_code:
char *getStatusString(int status){
 char *running;
 switch(status){
         case 0:
   running = "Done   ";
   break;
  case 1:
          running = "Running";
          break;
  case 2:
          running = "Stopped";
          break;
  default:
          running = "Invalid";
          break;
 }
 return running;
}

variable_types: status int

variable_types:
running
char *


toString

decompiled_code:
char *__fastcall toString(__int64 a1)
{
const char *v1; // r13
size_t v2; // rax
char *v3; // r12

v1 = getStatusString(*(_DWORD *)(a1 + 20));
v2 = strlen(*(const char **)(a1 + 8));
v3 = (char *)buddy_malloc(v2 + 25);
sprintf(v3, "[%i] %s %s\n", *(unsigned int *)(a1 + 4), v1, *(const char **)(a1 + 8));
return v3;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1)
{
const char *v1; // r13
size_t v2; // rax
char *v3; // r12

v1 = func5(*(_DWORD *)(a1 + 20));
v2 = strlen(*(const char **)(a1 + 8));
v3 = (char *)buddy_malloc(v2 + 25);
sprintf(v3, "[%i] %s %s\n", *(unsigned int *)(a1 + 4), v1, *(const char **)(a1 + 8));
return v3;
}

original_code:
char *toString(JobPtr node)
{
 char *temp;
 char *running;
 running = getStatusString(node->running);
 temp = (char *)buddy_malloc(sizeof(char)*strlen(node->command)+1+20 +4);
 sprintf(temp, "[%i] %s %s\n", node->jobNu, running, node->command);
 return temp;
}

canonical_original_code:
char *toString(struct job *node)
{
 char *temp;
 char *running;
 running = getStatusString(node->running);
 temp = (char *)buddy_malloc(sizeof(char)*strlen(node->command)+1+20 +4);
 sprintf(temp, "[%i] %s %s\n", node->jobNu, running, node->command);
 return temp;
}

variable_types:
temp
char *


freeJob

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

if ( a1 )
{
buddy_free(*(_QWORD *)(a1 + 8));
result = buddy_free(a1);
}
return result;
}

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

if ( a1 )
{
buddy_free(*(_QWORD *)(a1 + 8));
result = buddy_free(a1);
}
return result;
}

original_code:
void freeJob(JobPtr job)
{
 if (job == ((void *)0)) return;
 buddy_free(job->command);
 buddy_free(job);
}

canonical_original_code:
void freeJob(struct job *job)
{
 if (job == ((void *)0)) return;
 buddy_free(job->command);
 buddy_free(job);
}


freeArguments

decompiled_code:
__int64 __fastcall freeArguments(int a1, __int64 *a2, __int64 a3)
{
__int64 *v4; // rbx
__int64 v5; // rbp
__int64 v6; // rdi
__int64 result; // rax

if ( a1 > 0 )
{
v4 = a2;
v5 = (__int64)&a2[(unsigned int)(a1 - 1) + 1];
do
{
v6 = *v4++;
result = buddy_free(v6);
}
while ( v4 != (__int64 *)v5 );
}
if ( a3 )
result = buddy_free(a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 *a2, __int64 a3)
{
__int64 *v4; // rbx
__int64 v5; // rbp
__int64 v6; // rdi
__int64 result; // rax

if ( a1 > 0 )
{
v4 = a2;
v5 = (__int64)&a2[(unsigned int)(a1 - 1) + 1];
do
{
v6 = *v4++;
result = buddy_free(v6);
}
while ( v4 != (__int64 *)v5 );
}
if ( a3 )
result = buddy_free(a3);
return result;
}

original_code:
void freeArguments(int count, char** args, char* bufCopy){
    int i;
    for(i=0; i< count; i++){
    buddy_free(args[i]);
    }
    if(bufCopy != ((void *)0)) buddy_free(bufCopy);
}

canonical_original_code:
void freeArguments(int count, char **args, char *bufCopy){
    int i;
    for(i=0; i< count; i++){
    buddy_free(args[i]);
    }
    if(bufCopy != ((void *)0)) buddy_free(bufCopy);
}

variable_types: count int

variable_types:
args
char **

variable_types:
bufCopy
char *

variable_types: i int


changeDir

decompiled_code:
int __fastcall changeDir(__int64 a1)
{
const char *v2; // rdi
int result; // eax
__uid_t v4; // eax
char *v5; // rbp

v2 = *(const char **)(a1 + 8);
if ( v2 )
{
result = chdir(v2);
if ( result < 0 )
result = err_ret("couldn't change to directory: %s", *(const char **)(a1 + 8));
}
else
{
v4 = getuid();
v5 = getpwuid(v4)->pw_dir;
result = chdir(v5);
if ( result < 0 )
result = err_ret("couldn't change to home directory: %s", v5);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
const char *v2; // rdi
int result; // eax
__uid_t v4; // eax
char *v5; // rbp

v2 = *(const char **)(a1 + 8);
if ( v2 )
{
result = chdir(v2);
if ( result < 0 )
result = err_ret("couldn't change to directory: %s", *(const char **)(a1 + 8));
}
else
{
v4 = getuid();
v5 = getpwuid(v4)->pw_dir;
result = chdir(v5);
if ( result < 0 )
result = err_ret("couldn't change to home directory: %s", v5);
}
return result;
}

original_code:
void changeDir(char** arguments)
{
 if(arguments[1] == ((void *)0))
 {
  struct passwd * userData = getpwuid(getuid());
  char * path = userData->pw_dir;
  if(chdir(path) < 0)
  {
   err_ret("couldn't change to home directory: %s", path);
  }
 }
 else
 {
  if(chdir(arguments[1]) < 0)
  {
   err_ret("couldn't change to directory: %s", arguments[1]);
  }
 }
}

canonical_original_code:
void changeDir(char **arguments)
{
 if(arguments[1] == ((void *)0))
 {
  struct passwd *userData = getpwuid(getuid());
  char *path = userData->pw_dir;
  if(chdir(path) < 0)
  {
   err_ret("couldn't change to home directory: %s", path);
  }
 }
 else
 {
  if(chdir(arguments[1]) < 0)
  {
   err_ret("couldn't change to directory: %s", arguments[1]);
  }
 }
}

variable_types:
arguments
char **

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

variable_types:
path
char *


fg

decompiled_code:
__int64 __fastcall fg(__int64 a1, __int64 a2, unsigned int a3, __int64 a4)
{
const char *v7; // rdi
unsigned int v8; // er15
__int64 v9; // rax
_QWORD *v10; // rbp
__int64 result; // rax

v7 = *(const char **)(a1 + 8);
if ( v7 )
{
v8 = atoi(v7);
freeArguments(a3, a1, a4);
v9 = searchOnJobNu(a2, v8);
goto LABEL_3;
}
freeArguments(a3, a1, a4);
v10 = (_QWORD *)searchOnRunning(a2, 1LL);
if ( (unsigned int)isNodeNull(v10) )
{
v9 = searchOnRunning(a2, 2LL);
LABEL_3:
v10 = (_QWORD *)v9;
result = isNodeNull(v9);
if ( (_DWORD)result )
return result;
}
result = isJobNull(*v10);
if ( !(_DWORD)result )
result = continueJobInForeground(v10, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3, __int64 a4)
{
const char *v7; // rdi
unsigned int v8; // er15
__int64 v9; // rax
_QWORD *v10; // rbp
__int64 result; // rax

v7 = *(const char **)(a1 + 8);
if ( v7 )
{
v8 = atoi(v7);
freeArguments(a3, a1, a4);
v9 = searchOnJobNu(a2, v8);
goto LABEL_3;
}
freeArguments(a3, a1, a4);
v10 = (_QWORD *)searchOnRunning(a2, 1LL);
if ( (unsigned int)isNodeNull(v10) )
{
v9 = searchOnRunning(a2, 2LL);
LABEL_3:
v10 = (_QWORD *)v9;
result = isNodeNull(v9);
if ( (_DWORD)result )
return result;
}
result = isJobNull(*v10);
if ( !(_DWORD)result )
result = continueJobInForeground(v10, a2);
return result;
}

original_code:
void fg(char** arguments, ListPtr l, int count, char* bufCopy)
{
 int isArgumentNull = arguments[1] == ((void *)0);
 if(isArgumentNull)
 {
  freeArguments(count, arguments, bufCopy);
  NodePtr n = searchOnRunning(l, 1);
  if(!isNodeNull(n))
  {
   JobPtr j = n->data;
   if(!isJobNull(j)) continueJobInForeground(n, l);
  }
  else{
   NodePtr n = searchOnRunning(l, 2);
   if(!isNodeNull(n))
   {
    JobPtr j = n->data;
    if(!isJobNull(j)) continueJobInForeground(n, l);
   }
  }
 }
 else
 {
  int jobNumber = atoi(arguments[1]);
  freeArguments(count, arguments, bufCopy);
  NodePtr n = searchOnJobNu(l, jobNumber);
  if(!isNodeNull(n))
  {
   JobPtr j = n->data;
   if(!isJobNull(j)) continueJobInForeground(n, l);
  }
 }
}

canonical_original_code:
void fg(char **arguments, struct list *l, int count, char *bufCopy)
{
 int isArgumentNull = arguments[1] == ((void *)0);
 if(isArgumentNull)
 {
  freeArguments(count, arguments, bufCopy);
  struct node *n = searchOnRunning(l, 1);
  if(!isNodeNull(n))
  {
   struct job *j = n->data;
   if(!isJobNull(j)) continueJobInForeground(n, l);
  }
  else{
   struct node *n = searchOnRunning(l, 2);
   if(!isNodeNull(n))
   {
    struct job *j = n->data;
    if(!isJobNull(j)) continueJobInForeground(n, l);
   }
  }
 }
 else
 {
  int jobNumber = atoi(arguments[1]);
  freeArguments(count, arguments, bufCopy);
  struct node *n = searchOnJobNu(l, jobNumber);
  if(!isNodeNull(n))
  {
   struct job *j = n->data;
   if(!isJobNull(j)) continueJobInForeground(n, l);
  }
 }
}

variable_types: struct list { int size; struct node { struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *data; struct node *next; struct node *prev; } *head; struct node *tail; } *

variable_types: isArgumentNull int

variable_types: jobNumber int

user_defined_types: struct list { int size; struct node *head; struct node *tail; }

user_defined_types: struct node { struct job *data; struct node *next; struct node *prev; }


bgS

decompiled_code:
__int64 __fastcall bgS(__int64 a1, __int64 a2, unsigned int a3, __int64 a4)
{
const char *v7; // rdi
unsigned int v8; // er15
__int64 v9; // rax
_QWORD *v10; // rbp
__int64 result; // rax

v7 = *(const char **)(a1 + 8);
if ( v7 )
{
v8 = atoi(v7);
freeArguments(a3, a1, a4);
v9 = searchOnJobNu(a2, v8);
}
else
{
freeArguments(a3, a1, a4);
v9 = searchOnRunning(a2, 2LL);
}
v10 = (_QWORD *)v9;
result = isNodeNull(v9);
if ( !(_DWORD)result )
{
result = isJobNull(*v10);
if ( !(_DWORD)result )
result = continueJobInBackground(v10, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3, __int64 a4)
{
const char *v7; // rdi
unsigned int v8; // er15
__int64 v9; // rax
_QWORD *v10; // rbp
__int64 result; // rax

v7 = *(const char **)(a1 + 8);
if ( v7 )
{
v8 = atoi(v7);
freeArguments(a3, a1, a4);
v9 = searchOnJobNu(a2, v8);
}
else
{
freeArguments(a3, a1, a4);
v9 = searchOnRunning(a2, 2LL);
}
v10 = (_QWORD *)v9;
result = isNodeNull(v9);
if ( !(_DWORD)result )
{
result = isJobNull(*v10);
if ( !(_DWORD)result )
result = continueJobInBackground(v10, a2);
}
return result;
}

original_code:
void bgS(char** arguments, ListPtr l, int count, char* bufCopy)
{
 int isNull = arguments[1] == ((void *)0);
 if(isNull)
        {
  freeArguments(count, arguments, bufCopy);
  NodePtr n = searchOnRunning(l, 2);
  if(!isNodeNull(n))
  {
   JobPtr j = n->data;
   if(!isJobNull(j)) continueJobInBackground(n, l);
  }
 }
 else
 {
  int jobNumber = atoi(arguments[1]);
  freeArguments(count, arguments, bufCopy);
  NodePtr n = searchOnJobNu(l, jobNumber);
  if(!isNodeNull(n))
  {
   JobPtr j = n->data;
   if(!isJobNull(j)) continueJobInBackground(n, l);
  }
 }
}

canonical_original_code:
void bgS(char **arguments, struct list *l, int count, char *bufCopy)
{
 int isNull = arguments[1] == ((void *)0);
 if(isNull)
        {
  freeArguments(count, arguments, bufCopy);
  struct node *n = searchOnRunning(l, 2);
  if(!isNodeNull(n))
  {
   struct job *j = n->data;
   if(!isJobNull(j)) continueJobInBackground(n, l);
  }
 }
 else
 {
  int jobNumber = atoi(arguments[1]);
  freeArguments(count, arguments, bufCopy);
  struct node *n = searchOnJobNu(l, jobNumber);
  if(!isNodeNull(n))
  {
   struct job *j = n->data;
   if(!isJobNull(j)) continueJobInBackground(n, l);
  }
 }
}

variable_types: isNull int

variable_types: struct node { struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *data; struct node *next; struct node *prev; } *


getPrompt

decompiled_code:
char *getPrompt()
{
char *result; // rax

result = getenv("DASH_PROMPT");
if ( !result )
result = "%% ";
return result;
}

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

result = getenv("DASH_PROMPT");
if ( !result )
result = "%% ";
return result;
}

original_code:
char* getPrompt()
{
 char *prompt = getenv("DASH_PROMPT");
 return (prompt == ((void *)0)) ? "%% " : prompt;
}

canonical_original_code:
char *getPrompt()
{
 char *prompt = getenv("DASH_PROMPT");
 return (prompt == ((void *)0)) ? "%% " : prompt;
}

variable_types:
prompt
char *


isExitCommand

decompiled_code:
_BOOL8 __fastcall isExitCommand(const char *a1)
{
_BOOL4 v1; // er8

v1 = 1;
if ( strcmp(a1, "exit") )
v1 = strcmp(a1, "logout") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(const char *a1)
{
_BOOL4 v1; // er8

v1 = 1;
if ( strcmp(a1, "exit") )
v1 = strcmp(a1, "logout") == 0;
return v1;
}

original_code:
int isExitCommand(char *buf)
{
 return (strcmp(buf, "exit") == 0 || strcmp(buf, "logout") == 0);
}

variable_types:
buf
char *


isBackgroundCommand

decompiled_code:
__int64 __fastcall isBackgroundCommand(const char *a1)
{
const char *v1; // rdx
__int64 result; // rax

v1 = &a1[strlen(a1) - 1];
result = 0LL;
if ( *v1 == 38 )
{
*v1 = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
const char *v1; // rdx
__int64 result; // rax

v1 = &a1[strlen(a1) - 1];
result = 0LL;
if ( *v1 == 38 )
{
*v1 = 0;
result = 1LL;
}
return result;
}

original_code:
int isBackgroundCommand(char *buf)
{
 if(buf[strlen(buf)-1] == '&')
 {
  buf[strlen(buf)-1] = '\0';
  return 1;
 }
 else
  return 0;
}


isCdCommand

decompiled_code:
_BOOL8 __fastcall isCdCommand(_BYTE *a1, unsigned __int8 **a2)
{
_BOOL8 result; // rax
_BYTE *v3; // rdx
int v4; // eax

result = 0LL;
if ( *a1 )
{
v3 = *a2;
v4 = **a2 - 99;
if ( **a2 == 99 && (v4 = (unsigned __int8)v3[1] - 100, v3[1] == 100) )
result = v3[2] == 0;
else
result = v4 == 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_BYTE *a1, unsigned __int8 **a2)
{
_BOOL8 result; // rax
_BYTE *v3; // rdx
int v4; // eax

result = 0LL;
if ( *a1 )
{
v3 = *a2;
v4 = **a2 - 99;
if ( **a2 == 99 && (v4 = (unsigned __int8)v3[1] - 100, v3[1] == 100) )
result = v3[2] == 0;
else
result = v4 == 0;
}
return result;
}

original_code:
int isCdCommand(char* bufCopy, char** arguments)
{
 return (strlen(bufCopy) > 0 && strcmp(arguments[0], "cd") == 0);
}

canonical_original_code:
int isCdCommand(char *bufCopy, char **arguments)
{
 return (strlen(bufCopy) > 0 && strcmp(arguments[0], "cd") == 0);
}


isJobsCommand

decompiled_code:
_BOOL8 __fastcall isJobsCommand(const char *a1)
{
return strcmp(a1, "jobs") == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(const char *a1)
{
return strcmp(a1, "jobs") == 0;
}

original_code:
int isJobsCommand(char* buf)
{
 return (strcmp(buf, "jobs") == 0);
}

canonical_original_code:
int isJobsCommand(char *buf)
{
 return (strcmp(buf, "jobs") == 0);
}


isCommandNotEmpty

decompiled_code:
_BOOL8 __fastcall isCommandNotEmpty(_BYTE *a1)
{
return *a1 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(_BYTE *a1)
{
return *a1 != 0;
}

original_code:
int isCommandNotEmpty(char* buf)
{
 return (strlen(buf) != 0);
}

canonical_original_code:
int isCommandNotEmpty(char *buf)
{
 return (strlen(buf) != 0);
}


isFgCommand

decompiled_code:
_BOOL8 __fastcall isFgCommand(_BYTE *a1, unsigned __int8 **a2)
{
_BOOL8 result; // rax
_BYTE *v3; // rdx
int v4; // eax

result = 0LL;
if ( *a1 )
{
v3 = *a2;
v4 = **a2 - 102;
if ( **a2 == 102 && (v4 = (unsigned __int8)v3[1] - 103, v3[1] == 103) )
result = v3[2] == 0;
else
result = v4 == 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(_BYTE *a1, unsigned __int8 **a2)
{
_BOOL8 result; // rax
_BYTE *v3; // rdx
int v4; // eax

result = 0LL;
if ( *a1 )
{
v3 = *a2;
v4 = **a2 - 102;
if ( **a2 == 102 && (v4 = (unsigned __int8)v3[1] - 103, v3[1] == 103) )
result = v3[2] == 0;
else
result = v4 == 0;
}
return result;
}

original_code:
int isFgCommand(char* bufCopy, char** arguments)
{
 return (strlen(bufCopy) > 0 && strcmp(arguments[0], "fg") == 0);
}

canonical_original_code:
int isFgCommand(char *bufCopy, char **arguments)
{
 return (strlen(bufCopy) > 0 && strcmp(arguments[0], "fg") == 0);
}


isBgCommand

decompiled_code:
_BOOL8 __fastcall isBgCommand(_BYTE *a1, unsigned __int8 **a2)
{
_BOOL8 result; // rax
_BYTE *v3; // rdx
int v4; // eax

result = 0LL;
if ( *a1 )
{
v3 = *a2;
v4 = **a2 - 98;
if ( **a2 == 98 && (v4 = (unsigned __int8)v3[1] - 103, v3[1] == 103) )
result = v3[2] == 0;
else
result = v4 == 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(_BYTE *a1, unsigned __int8 **a2)
{
_BOOL8 result; // rax
_BYTE *v3; // rdx
int v4; // eax

result = 0LL;
if ( *a1 )
{
v3 = *a2;
v4 = **a2 - 98;
if ( **a2 == 98 && (v4 = (unsigned __int8)v3[1] - 103, v3[1] == 103) )
result = v3[2] == 0;
else
result = v4 == 0;
}
return result;
}

original_code:
int isBgCommand(char* bufCopy, char** arguments)
{
 return (strlen(bufCopy) > 0 && strcmp(arguments[0], "bg") == 0);
}

canonical_original_code:
int isBgCommand(char *bufCopy, char **arguments)
{
 return (strlen(bufCopy) > 0 && strcmp(arguments[0], "bg") == 0);
}


runCommand

decompiled_code:
void __fastcall __noreturn runCommand(char **argv, const char *a2)
{
printf("%s", *argv);
execvp(*argv, argv);
err_ret("couldn't execute: %s", a2);
exit(127);
}

canonical_decompiled_code:
void __fastcall __noreturn func12(char **argv, const char *a2)
{
printf("%s", *argv);
execvp(*argv, argv);
err_ret("couldn't execute: %s", a2);
exit(127);
}

original_code:
void runCommand(char **args, char* buf)
{
 printf("%s", args[0]);
 execvp(*args, args);
 err_ret("couldn't execute: %s", buf);
 exit(127);
}

canonical_original_code:
void runCommand(char **args, char *buf)
{
 printf("%s", args[0]);
 execvp(*args, args);
 err_ret("couldn't execute: %s", buf);
 exit(127);
}


isArgumentForShowingVersion

decompiled_code:
_BOOL8 __fastcall isArgumentForShowingVersion(__int64 a1)
{
unsigned __int8 *v1; // rdx
_BOOL8 result; // rax
int v3; // eax

v1 = *(unsigned __int8 **)(a1 + 8);
result = 0LL;
if ( v1 )
{
v3 = *v1 - 118;
if ( *v1 == 118 )
v3 = v1[1];
result = v3 != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(__int64 a1)
{
unsigned __int8 *v1; // rdx
_BOOL8 result; // rax
int v3; // eax

v1 = *(unsigned __int8 **)(a1 + 8);
result = 0LL;
if ( v1 )
{
v3 = *v1 - 118;
if ( *v1 == 118 )
v3 = v1[1];
result = v3 != 0;
}
return result;
}

original_code:
int isArgumentForShowingVersion(char **argv)
{
 return (argv[1] != ((void *)0) && strcmp(argv[1],"v"));
}

variable_types:
argv
char **


showVersionAndExit

decompiled_code:
void __noreturn showVersionAndExit()
{
printf("Version %s\n", "Unversioned directory");
exit(0);
}

canonical_decompiled_code:
void __noreturn func14()
{
printf("Version %s\n", "Unversioned directory");
exit(0);
}

original_code:
void showVersionAndExit()
{
 printf("Version %s\n", "Unversioned directory");
 exit(0);
}


stop

decompiled_code:
void stop()
{
__pid_t *v0; // rbx

if ( !node
|| (v0 = *(__pid_t **)node, (unsigned int)isJobNull(*(_QWORD *)node))
|| (unsigned int)isJobInBackground(v0)
|| (unsigned int)isJobStopped(v0)
|| (unsigned int)isJobDone(v0) )
{
printf("\nCaught Control-z\n%s", pr);
}
else
{
kill(*v0, 20);
}
}

canonical_decompiled_code:
void func0()
{
__pid_t *v0; // rbx

if ( !node
|| (v0 = *(__pid_t **)node, (unsigned int)isJobNull(*(_QWORD *)node))
|| (unsigned int)isJobInBackground(v0)
|| (unsigned int)isJobStopped(v0)
|| (unsigned int)isJobDone(v0) )
{
printf("\nCaught Control-z\n%s", pr);
}
else
{
kill(*v0, 20);
}
}

original_code:
void stop(int a){
 if(node == ((void *)0)){
         printf("\nCaught Control-z\n%s", pr);
         return;
 }
 JobPtr job = node->data;
 if(isJobNull(job) || isJobInBackground(job) || isJobStopped(job) || isJobDone(job)){
         printf("\nCaught Control-z\n%s", pr);
 }
 else kill(job->jobid, 20);
}

canonical_original_code:
void stop(int a){
 if(node == ((void *)0)){
         printf("\nCaught Control-z\n%s", pr);
         return;
 }
 struct job *job = node->data;
 if(isJobNull(job) || isJobInBackground(job) || isJobStopped(job) || isJobDone(job)){
         printf("\nCaught Control-z\n%s", pr);
 }
 else kill(job->jobid, 20);
}

variable_types: a int

variable_types: struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *


interrupt

decompiled_code:
void interrupt()
{
__pid_t *v0; // rbx

if ( node )
{
v0 = *(__pid_t **)node;
if ( (unsigned int)isJobNull(*(_QWORD *)node)
|| (unsigned int)isJobInBackground(v0)
|| (unsigned int)isJobStopped(v0)
|| (unsigned int)isJobDone(v0) )
{
printf("\nCaught Control-c\n%s", pr);
printf(pr);
}
else
{
printf("Killing PID: %d", (unsigned int)*v0);
kill(*v0, 2);
}
}
else
{
printf("\nCaught Control-c\n%s", pr);
}
}

canonical_decompiled_code:
void func1()
{
__pid_t *v0; // rbx

if ( node )
{
v0 = *(__pid_t **)node;
if ( (unsigned int)isJobNull(*(_QWORD *)node)
|| (unsigned int)isJobInBackground(v0)
|| (unsigned int)isJobStopped(v0)
|| (unsigned int)isJobDone(v0) )
{
printf("\nCaught Control-c\n%s", pr);
printf(pr);
}
else
{
printf("Killing PID: %d", (unsigned int)*v0);
kill(*v0, 2);
}
}
else
{
printf("\nCaught Control-c\n%s", pr);
}
}

original_code:
void interrupt(){
 if(node == ((void *)0)){
  printf("\nCaught Control-c\n%s", pr);
  return;
 }
 JobPtr job = node->data;
 if(isJobNull(job) || isJobInBackground(job) || isJobStopped(job) || isJobDone(job)){
  printf("\nCaught Control-c\n%s", pr);
  printf(pr);
 }
 else{
  printf("Killing PID: %d", job->jobid);
  kill(job->jobid, 2);
 }
}

canonical_original_code:
void interrupt(){
 if(node == ((void *)0)){
  printf("\nCaught Control-c\n%s", pr);
  return;
 }
 struct job *job = node->data;
 if(isJobNull(job) || isJobInBackground(job) || isJobStopped(job) || isJobDone(job)){
  printf("\nCaught Control-c\n%s", pr);
  printf(pr);
 }
 else{
  printf("Killing PID: %d", job->jobid);
  kill(job->jobid, 2);
 }
}


initSignals

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

signal(2, (__sighandler_t)interrupt);
result = signal(20, (__sighandler_t)stop);
jumpB = a1;
node = 0LL;
return result;
}

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

signal(2, (__sighandler_t)interrupt);
result = signal(20, (__sighandler_t)stop);
jumpB = a1;
node = 0LL;
return result;
}

original_code:
void initSignals(void (*jb)(void)){
 signal(2, interrupt);
 signal(20, stop);
 jumpB = jb;
 node = ((void *)0);
}

canonical_original_code:
void initSignals(void (*jb)()){
 signal(2, interrupt);
 signal(20, stop);
 jumpB = jb;
 node = ((void *)0);
}

variable_types:
jb
void (*)()


setNode

decompiled_code:
void __fastcall setNode(__int64 a1)
{
node = a1;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
node = a1;
}

original_code: void setNode(NodePtr nodee){ node = nodee; }

canonical_original_code: void setNode(struct node *nodee){ node = nodee; }


setPrompt

decompiled_code:
void __fastcall setPrompt(char *a1)
{
pr = a1;
}

canonical_decompiled_code:
void __fastcall func4(char *a1)
{
pr = a1;
}

original_code: void setPrompt(char* prompts){ pr = prompts; }

canonical_original_code: void setPrompt(char *prompts){ pr = prompts; }

variable_types:
prompts
char *


restoreSignals

decompiled_code:
__sighandler_t restoreSignals()
{
signal(2, (__sighandler_t)interrupt);
return signal(20, (__sighandler_t)stop);
}

canonical_decompiled_code:
__sighandler_t func5()
{
signal(2, (__sighandler_t)interrupt);
return signal(20, (__sighandler_t)stop);
}

original_code:
void restoreSignals(){
    signal(2, interrupt);
 signal(20, stop);
}


markAsStopped

decompiled_code:
__int64 __fastcall markAsStopped(__int64 a1, __int64 *a2)
{
__int64 v2; // rax
__int64 v3; // rsi
const char *v4; // rcx

v2 = *a2;
v3 = *(unsigned int *)(*a2 + 4);
v4 = *(const char **)(v2 + 8);
*(_DWORD *)(v2 + 20) = 2;
printf("\n[%d] %s %s\n", v3, "Stopped", v4);
return addAtFront(a1, node);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 *a2)
{
__int64 v2; // rax
__int64 v3; // rsi
const char *v4; // rcx

v2 = *a2;
v3 = *(unsigned int *)(*a2 + 4);
v4 = *(const char **)(v2 + 8);
*(_DWORD *)(v2 + 20) = 2;
printf("\n[%d] %s %s\n", v3, "Stopped", v4);
return addAtFront(a1, node);
}

original_code:
void markAsStopped(ListPtr l, NodePtr n){
 JobPtr job = n->data;
 job->running = 2;
 printf("\n[%d] %s %s\n", job->jobNu, "Stopped", job->command);
 addAtFront(l, node);
}

canonical_original_code:
void markAsStopped(struct list *l, struct node *n){
 struct job *job = n->data;
 job->running = 2;
 printf("\n[%d] %s %s\n", job->jobNu, "Stopped", job->command);
 addAtFront(l, node);
}

variable_types:
n
struct node *


markAsKilled

decompiled_code:
int __fastcall markAsKilled(__int64 a1)
{
return printf(
"\n[%d] %s %s\n",
*(unsigned int *)(*(_QWORD *)a1 + 4LL),
"Killed",
*(const char **)(*(_QWORD *)a1 + 8LL));
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
return printf(
"\n[%d] %s %s\n",
*(unsigned int *)(*(_QWORD *)a1 + 4LL),
"Killed",
*(const char **)(*(_QWORD *)a1 + 8LL));
}

original_code:
void markAsKilled(NodePtr n){
 JobPtr job = n->data;
 printf("\n[%d] %s %s\n", job->jobNu, "Killed", job->command);
}

canonical_original_code:
void markAsKilled(struct node *n){
 struct job *job = n->data;
 printf("\n[%d] %s %s\n", job->jobNu, "Killed", job->command);
}


ignoreSignals

decompiled_code:
__sighandler_t ignoreSignals()
{
signal(2, (__sighandler_t)((char *)stop + 1));
return signal(20, (__sighandler_t)((char *)stop + 1));
}

canonical_decompiled_code:
__sighandler_t func8()
{
signal(2, (__sighandler_t)((char *)stop + 1));
return signal(20, (__sighandler_t)((char *)stop + 1));
}

original_code:
void ignoreSignals(){
 signal(2, ((__sighandler_t) 1));
 signal(20, ((__sighandler_t) 1));
}

canonical_original_code:
void ignoreSignals(){
 signal(2, ((void (*)(int)) 1));
 signal(20, ((void (*)(int)) 1));
}


continueJobInBackground

decompiled_code:
__int64 __fastcall continueJobInBackground(__pid_t **a1)
{
__pid_t *v1; // rax
__pid_t v2; // ebp
const char *v3; // rdx

v1 = *a1;
v2 = **a1;
v3 = (const char *)*((_QWORD *)*a1 + 1);
v1[5] = 1;
printf("\n[%d] %s\n", (unsigned int)v1[1], v3);
kill(v2, 18);
restoreSignals();
return jumpB();
}

canonical_decompiled_code:
__int64 __fastcall func9(__pid_t **a1)
{
__pid_t *v1; // rax
__pid_t v2; // ebp
const char *v3; // rdx

v1 = *a1;
v2 = **a1;
v3 = (const char *)*((_QWORD *)*a1 + 1);
v1[5] = 1;
printf("\n[%d] %s\n", (unsigned int)v1[1], v3);
kill(v2, 18);
func5();
return jumpB();
}

original_code:
void continueJobInBackground(NodePtr nodee, ListPtr jobList){
 JobPtr job = nodee->data;
 int pid = job->jobid;
 job->running = 1;
 printf("\n[%d] %s\n", job->jobNu, job->command);
 kill(pid, 18);
 restoreSignals();
 jumpB();
}

canonical_original_code:
void continueJobInBackground(struct node *nodee, struct list *jobList){
 struct job *job = nodee->data;
 int pid = job->jobid;
 job->running = 1;
 printf("\n[%d] %s\n", job->jobNu, job->command);
 kill(pid, 18);
 restoreSignals();
 jumpB();
}

variable_types: struct list { int size; struct node *head; struct node *tail; } *

variable_types: pid int


restoreSignalsAndDetermineStatus

decompiled_code:
int __fastcall restoreSignalsAndDetermineStatus(unsigned __int8 a1, __int64 a2, __int64 *a3)
{
int result; // eax

restoreSignals();
result = a1;
if ( (char)((a1 & 0x7F) + 1) > 1 )
{
if ( a1 != 127 )
return markAsKilled((__int64)a3);
return markAsStopped(a2, a3);
}
if ( a1 == 127 )
return markAsStopped(a2, a3);
return result;
}

canonical_decompiled_code:
int __fastcall func10(unsigned __int8 a1, __int64 a2, __int64 *a3)
{
int result; // eax

func5();
result = a1;
if ( (char)((a1 & 0x7F) + 1) > 1 )
{
if ( a1 != 127 )
return func7((__int64)a3);
return func6(a2, a3);
}
if ( a1 == 127 )
return func6(a2, a3);
return result;
}

original_code:
void restoreSignalsAndDetermineStatus(int status, ListPtr jobList, NodePtr n){
 restoreSignals();
 if((((signed char) (((status) & 0x7f) + 1) >> 1) > 0) || (((status) & 0xff) == 0x7f)){
  if((((status) & 0xff) == 0x7f)) markAsStopped(jobList, n);
  else markAsKilled(n);
 }
 else
 {
 }
}

canonical_original_code:
void restoreSignalsAndDetermineStatus(int status, struct list *jobList, struct node *n){
 restoreSignals();
 if((((char) (((status) & 0x7f) + 1) >> 1) > 0) || (((status) & 0xff) == 0x7f)){
  if((((status) & 0xff) == 0x7f)) markAsStopped(jobList, n);
  else markAsKilled(n);
 }
 else
 {
 }
}

variable_types: status int


continueJobInForeground

decompiled_code:
int __fastcall continueJobInForeground(__int64 *a1, __int64 a2)
{
__pid_t v2; // er13
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

setNode((__int64)a1);
v2 = *(_DWORD *)*a1;
stat_loc[0] = 0;
ignoreSignals();
removeNode(a2, a1);
kill(v2, 18);
if ( waitpid(v2, stat_loc, 2) < 0 )
err_sys("waitpid error");
return restoreSignalsAndDetermineStatus(stat_loc[0], a2, a1);
}

canonical_decompiled_code:
int __fastcall func11(__int64 *a1, __int64 a2)
{
__pid_t v2; // er13
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

func3((__int64)a1);
v2 = *(_DWORD *)*a1;
stat_loc[0] = 0;
func8();
removeNode(a2, a1);
kill(v2, 18);
if ( waitpid(v2, stat_loc, 2) < 0 )
err_sys("waitpid error");
return func10(stat_loc[0], a2, a1);
}

original_code:
void continueJobInForeground(NodePtr nodee, ListPtr jobList){
 setNode(nodee);
 JobPtr job = nodee->data;
 int pid = job->jobid;
 int status = 0;
 ignoreSignals();
 removeNode(jobList, nodee);
 kill(pid, 18);
 if((pid=waitpid(pid,&status,2))<0) err_sys("waitpid error");
 restoreSignalsAndDetermineStatus(status, jobList, nodee);
}

canonical_original_code:
void continueJobInForeground(struct node *nodee, struct list *jobList){
 setNode(nodee);
 struct job *job = nodee->data;
 int pid = job->jobid;
 int status = 0;
 ignoreSignals();
 removeNode(jobList, nodee);
 kill(pid, 18);
 if((pid=waitpid(pid,&status,2))<0) err_sys("waitpid error");
 restoreSignalsAndDetermineStatus(status, jobList, nodee);
}


addToAddress

decompiled_code:
__int64 __fastcall addToAddress(__int64 a1, int a2)
{
return a1 + a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
return a1 + a2;
}

original_code:
size_t addToAddress(BlockPtr block, int amount){
 size_t *iA = (size_t *) █
 size_t initialAddress = *iA;
 size_t newAddress = initialAddress + amount;
 return newAddress;
}

canonical_original_code:
unsigned long addToAddress(struct block *block, int amount){
 unsigned long *iA = (size_t *) █
 unsigned long initialAddress = *iA;
 unsigned long newAddress = initialAddress + amount;
 return newAddress;
}

variable_types: struct block { int tag; int kval; char *blockStartingAddress; struct block *next; struct block *prev; } *

variable_types: amount int

variable_types:
iA
unsigned long *

variable_types:
initialAddress
unsigned long

variable_types:
newAddress
unsigned long


buddy

decompiled_code:
__int64 __fastcall buddy(__int64 a1)
{
int v1; // eax

v1 = addToAddress(a1, -(int)initialBlockAddress);
return addToAddress(initialBlock, v1 ^ (unsigned int)(1 << *(_DWORD *)(a1 + 4)));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // eax

v1 = func0(a1, -(int)initialBlockAddress);
return func0(initialBlock, v1 ^ (unsigned int)(1 << *(_DWORD *)(a1 + 4)));
}

original_code:
size_t buddy(BlockPtr block){
 size_t address = addToAddress(block, -initialBlockAddress);
 return (addToAddress(initialBlock, address^(1<<block->kval)));
}

canonical_original_code:
unsigned long buddy(struct block *block){
 unsigned long address = addToAddress(block, -initialBlockAddress);
 return (addToAddress(initialBlock, address^(1<<block->kval)));
}

variable_types:
address
unsigned long

user_defined_types: struct block { int tag; int kval; char *blockStartingAddress; struct block *next; struct block *prev; }


initializeFreeBlock

decompiled_code:
void __fastcall initializeFreeBlock(__int64 a1, int a2, int a3)
{
__int64 v3; // rcx

initializeReservedBlock((_DWORD *)a1, a2, a3);
*(_QWORD *)(a1 + 24) = v3;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2, int a3)
{
__int64 v3; // rcx

func2((_DWORD *)a1, a2, a3);
*(_QWORD *)(a1 + 24) = v3;
}

original_code:
void initializeFreeBlock(BlockPtr block, int tag, int kval, BlockPtr prevBlock)
{
 initializeReservedBlock(block, tag, kval);
 block->prev = prevBlock;
}

canonical_original_code:
void initializeFreeBlock(struct block *block, int tag, int kval, struct block *prevBlock)
{
 initializeReservedBlock(block, tag, kval);
 block->prev = prevBlock;
}

variable_types: tag int

variable_types: kval int

variable_types:
prevBlock
struct block *


initial

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

v0 = sbrk(0x4000000LL);
initialBlock = (__int64)v0;
blockAddress[26] = (__int64)v0;
initializeFreeBlock((__int64)v0, 0, 26);
result = addToAddress(initialBlock, 0);
initialized = 1;
initialBlockAddress = result;
return result;
}

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

v0 = sbrk(0x4000000LL);
initialBlock = (__int64)v0;
blockAddress[26] = (__int64)v0;
func3((__int64)v0, 0, 26);
result = func0(initialBlock, 0);
initialized = 1;
initialBlockAddress = result;
return result;
}

original_code:
void initial(){
 initialBlock = (BlockPtr) sbrk(67108864);
 blockAddress[26] = initialBlock;
 initializeFreeBlock(initialBlock, 0, 26, ((void *)0));
 initialBlockAddress = addToAddress(initialBlock, 0);
 initialized = 1;
}

canonical_original_code:
void initial(){
 initialBlock = (struct block *) sbrk(67108864);
 blockAddress[26] = initialBlock;
 initializeFreeBlock(initialBlock, 0, 26, ((void *)0));
 initialBlockAddress = addToAddress(initialBlock, 0);
 initialized = 1;
}


decompiled_code:
__int64 __fastcall buddy_getSize(__int64 a1)
{
return (unsigned int)(1 << *(_DWORD *)(a1 + 4));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return (unsigned int)(1 << *(_DWORD *)(a1 + 4));
}

original_code:
int buddy_getSize(BlockPtr block){
 return 1 << block->kval;
}

canonical_original_code:
int buddy_getSize(struct block *block){
 return 1 << block->kval;
}


isReserved

decompiled_code:
_BOOL8 __fastcall isReserved(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 1;
}

original_code:
int isReserved(BlockPtr block){
 return block->kval == 1;
}

canonical_original_code:
int isReserved(struct block *block){
 return block->kval == 1;
}


isNextBlockNull

decompiled_code:
_BOOL8 __fastcall isNextBlockNull(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

original_code:
int isNextBlockNull(BlockPtr block){
 return block->next == ((void *)0);
}

canonical_original_code:
int isNextBlockNull(struct block *block){
 return block->next == ((void *)0);
}


isBlockIndexNull

decompiled_code:
_BOOL8 __fastcall isBlockIndexNull(int a1)
{
return blockAddress[a1] == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(int a1)
{
return blockAddress[a1] == 0;
}

original_code:
int isBlockIndexNull(int index){
 return blockAddress[index] == ((void *)0);
}

variable_types: index int


nextFreeBlock

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

if ( isNextBlockNull(a1) )
result = 0LL;
else
result = *(_QWORD *)(a1 + 16);
return result;
}

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

if ( func7(a1) )
result = 0LL;
else
result = *(_QWORD *)(a1 + 16);
return result;
}

original_code:
BlockPtr nextFreeBlock(BlockPtr block){
 if(isNextBlockNull(block)) return ((void *)0);
 return block->next;
}

canonical_original_code:
struct block *nextFreeBlock(struct block *block){
 if(isNextBlockNull(block)) return ((void *)0);
 return block->next;
}

variable_types:
block
struct block *

return_type: struct block { int tag; int kval; char *blockStartingAddress; struct block *next; struct block *prev; } *


isKvalEmpty

decompiled_code:
// attributes: thunk
_BOOL8 __fastcall isKvalEmpty(int a1)
{
return isBlockIndexNull(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(int a1)
{
return func8(a1);
}

original_code:
int isKvalEmpty(int kval){
 return blockAddress[kval] == ((void *)0);
}


searchAndRemoveBlockFromFreeList

decompiled_code:
__int64 __fastcall searchAndRemoveBlockFromFreeList(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax
__int64 v3; // rdx

v1 = *(int *)(a1 + 4);
result = blockAddress[v1];
if ( result == a1 )
{
result = *(_QWORD *)(result + 16);
blockAddress[v1] = result;
}
else
{
do
{
v3 = result;
result = *(_QWORD *)(result + 16);
}
while ( result != a1 );
*(_QWORD *)(v3 + 16) = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax
__int64 v3; // rdx

v1 = *(int *)(a1 + 4);
result = blockAddress[v1];
if ( result == a1 )
{
result = *(_QWORD *)(result + 16);
blockAddress[v1] = result;
}
else
{
do
{
v3 = result;
result = *(_QWORD *)(result + 16);
}
while ( result != a1 );
*(_QWORD *)(v3 + 16) = 0LL;
}
return result;
}

original_code:
void searchAndRemoveBlockFromFreeList(BlockPtr block){
 if(block == blockAddress[block->kval]) blockAddress[block->kval] = block->next;
 else {
  BlockPtr searchBlock = blockAddress[block->kval];
  while(searchBlock->next != block) searchBlock = searchBlock->next;
  searchBlock->next = ((void *)0);
 }
}

canonical_original_code:
void searchAndRemoveBlockFromFreeList(struct block *block){
 if(block == blockAddress[block->kval]) blockAddress[block->kval] = block->next;
 else {
  struct block *searchBlock = blockAddress[block->kval];
  while(searchBlock->next != block) searchBlock = searchBlock->next;
  searchBlock->next = ((void *)0);
 }
}


isBlockFree

decompiled_code:
_BOOL8 __fastcall isBlockFree(_DWORD *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(_DWORD *a1)
{
return *a1 == 0;
}

original_code: int isBlockFree(BlockPtr block){ return block->tag == 0; }

canonical_original_code: int isBlockFree(struct block *block){ return block->tag == 0; }


isKvalLessThanMin

decompiled_code:
_BOOL8 __fastcall isKvalLessThanMin(int a1)
{
return a1 <= 4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(int a1)
{
return a1 <= 4;
}

original_code: int isKvalLessThanMin(int kval){ return kval < 5; }


isKvalAtMax

decompiled_code:
_BOOL8 __fastcall isKvalAtMax(__int64 a1)
{
return *(_DWORD *)(a1 + 4) > 25;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(__int64 a1)
{
return *(_DWORD *)(a1 + 4) > 25;
}

original_code: int isKvalAtMax(BlockPtr block) { return block->kval >= 26; }

canonical_original_code: int isKvalAtMax(struct block *block) { return block->kval >= 26; }


isBlockAddressValid

decompiled_code:
_BOOL8 __fastcall isBlockAddressValid(unsigned __int64 a1)
{
return initialBlockAddress <= a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(unsigned __int64 a1)
{
return initialBlockAddress <= a1;
}

original_code: int isBlockAddressValid(size_t blockAddress) { return blockAddress >= initialBlockAddress; }

canonical_original_code: int isBlockAddressValid(unsigned long blockAddress) { return blockAddress >= initialBlockAddress; }

variable_types:
blockAddress
unsigned long


isNextBuddyBlockReadyToJoin

decompiled_code:
_BOOL8 __fastcall isNextBuddyBlockReadyToJoin(__int64 a1, _DWORD *a2)
{
unsigned __int64 v2; // rdx
_BOOL4 v3; // er8
_BOOL8 result; // rax

v3 = isKvalAtMax(a1);
result = 0LL;
if ( !v3 )
{
result = isBlockAddressValid(v2);
if ( result )
result = isBlockFree(a2);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func17(__int64 a1, _DWORD *a2)
{
unsigned __int64 v2; // rdx
_BOOL4 v3; // er8
_BOOL8 result; // rax

v3 = func15(a1);
result = 0LL;
if ( !v3 )
{
result = func16(v2);
if ( result )
result = func12(a2);
}
return result;
}

original_code:
int isNextBuddyBlockReadyToJoin(BlockPtr block, BlockPtr buddyBlock, size_t buddyAddress){
 return !isKvalAtMax(block) && isBlockAddressValid(buddyAddress) && isBlockFree(buddyBlock);
}

canonical_original_code:
int isNextBuddyBlockReadyToJoin(struct block *block, struct block *buddyBlock, unsigned long buddyAddress){
 return !isKvalAtMax(block) && isBlockAddressValid(buddyAddress) && isBlockFree(buddyBlock);
}

variable_types:
buddyBlock
struct block *

variable_types:
buddyAddress
unsigned long


setNodeInFreeList

decompiled_code:
__int64 __fastcall setNodeInFreeList(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = blockAddress[*(int *)(a1 + 4)];
do
{
v2 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v2 + 16) = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = blockAddress[*(int *)(a1 + 4)];
do
{
v2 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v2 + 16) = a1;
return result;
}

original_code:
void setNodeInFreeList(BlockPtr block){
 BlockPtr nextBlock = blockAddress[block->kval];
 while(nextBlock->next != ((void *)0)) nextBlock = nextBlock->next;
 nextBlock->next = block;
}

canonical_original_code:
void setNodeInFreeList(struct block *block){
 struct block *nextBlock = blockAddress[block->kval];
 while(nextBlock->next != ((void *)0)) nextBlock = nextBlock->next;
 nextBlock->next = block;
}


joinBlock

decompiled_code:
__int64 __fastcall joinBlock(__int64 a1)
{
__int64 v1; // r9
__int64 v2; // r9
__int64 v3; // r10
__int64 v4; // r9
int v5; // eax
__int64 v6; // rcx
_DWORD *v7; // rax
__int64 v8; // r9
__int64 v9; // r9
_DWORD *v10; // rdi
__int64 result; // rax
__int64 v12; // rdx
__int64 v13; // r9

buddy(a1);
while ( 1 )
{
v10 = (_DWORD *)v1;
result = isKvalAtMax(v1);
if ( (_DWORD)result )
break;
if ( isBlockFree(v10) )
{
searchAndRemoveBlockFromFreeList(v3);
v5 = *(_DWORD *)(v4 + 4);
v2 = v6;
*(_DWORD *)(v6 + 4) = v5 + 1;
}
*(_DWORD *)v2 = 0;
*(_QWORD *)(v2 + 16) = 0LL;
*(_QWORD *)(v2 + 24) = 0LL;
v7 = (_DWORD *)buddy(v2);
if ( !isNextBuddyBlockReadyToJoin(v8, v7) )
{
result = isBlockIndexNull(*(_DWORD *)(v9 + 4));
if ( !(_DWORD)result )
return setNodeInFreeList(v13);
blockAddress[v12] = v13;
return result;
}
addToAddress(v9, 0);
}
return result;
}

original_code:
void joinBlock(BlockPtr block, size_t blocksAddress){
 size_t buddyAddress = buddy(block);
 BlockPtr buddyBlock = (BlockPtr) buddyAddress;
 BlockPtr reallocBlock;
 if(isKvalAtMax(block)) return;
 if(isBlockFree(block)){
  reallocBlock = (buddyAddress < blocksAddress) ? buddyBlock : block;
  searchAndRemoveBlockFromFreeList(buddyBlock);
  reallocBlock->kval = block->kval+1;
 }
 else reallocBlock = block;
 reallocBlock->tag = 0;
 reallocBlock->next = ((void *)0);
 reallocBlock->prev = ((void *)0);
 buddyAddress = buddy(reallocBlock);
 buddyBlock = (BlockPtr) buddyAddress;
 if(isNextBuddyBlockReadyToJoin(reallocBlock, buddyBlock, buddyAddress)){
  size_t reallocBlocksAddress = addToAddress(reallocBlock, 0);
  joinBlock(reallocBlock, reallocBlocksAddress);
 }
 else {
  if(isKvalEmpty(reallocBlock->kval)) blockAddress[reallocBlock->kval] = reallocBlock;
  else setNodeInFreeList(reallocBlock);
 }
}

canonical_original_code:
void joinBlock(struct block *block, unsigned long blocksAddress){
 unsigned long buddyAddress = buddy(block);
 struct block *buddyBlock = (BlockPtr) buddyAddress;
 struct block *reallocBlock;
 if(isKvalAtMax(block)) return;
 if(isBlockFree(block)){
  reallocBlock = (buddyAddress < blocksAddress) ? buddyBlock : block;
  searchAndRemoveBlockFromFreeList(buddyBlock);
  reallocBlock->kval = block->kval+1;
 }
 else reallocBlock = block;
 reallocBlock->tag = 0;
 reallocBlock->next = ((void *)0);
 reallocBlock->prev = ((void *)0);
 buddyAddress = buddy(reallocBlock);
 buddyBlock = (struct block *) buddyAddress;
 if(isNextBuddyBlockReadyToJoin(reallocBlock, buddyBlock, buddyAddress)){
  unsigned long reallocBlocksAddress = addToAddress(reallocBlock, 0);
  joinBlock(reallocBlock, reallocBlocksAddress);
 }
 else {
  if(isKvalEmpty(reallocBlock->kval)) blockAddress[reallocBlock->kval] = reallocBlock;
  else setNodeInFreeList(reallocBlock);
 }
}

variable_types:
blocksAddress
unsigned long

variable_types:
reallocBlocksAddress
unsigned long


decompiled_code:
__int64 __fastcall buddy_free(__int64 a1)
{
__int64 v1; // rax

v1 = addToAddress(a1, -9);
return joinBlock(v1);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
__int64 v1; // rax

v1 = func0(a1, -9);
return func19(v1);
}

original_code:
void buddy_free(void *address){
 size_t blocksAddress = addToAddress((BlockPtr)address, -9);
 BlockPtr block = (BlockPtr) blocksAddress;
 joinBlock(block, blocksAddress);
}

canonical_original_code:
void buddy_free(void *address){
 unsigned long blocksAddress = addToAddress((BlockPtr)address, -9);
 struct block *block = (BlockPtr) blocksAddress;
 joinBlock(block, blocksAddress);
}

variable_types:
address
void *


printBlock

decompiled_code:
void __fastcall printBlock(unsigned int *a1)
{
unsigned int *v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
printf(
"Address: %p kval:%d tag:%d blockStartingAddress:%p next:%p prev:%p -->",
v1,
v1[1],
*v1,
*((const void **)v1 + 1),
*((const void **)v1 + 2),
*((const void **)v1 + 3));
if ( isNextBlockNull((__int64)v1) )
break;
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func21(unsigned int *a1)
{
unsigned int *v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
printf(
"Address: %p kval:%d tag:%d blockStartingAddress:%p next:%p prev:%p -->",
v1,
v1[1],
*v1,
*((const void **)v1 + 1),
*((const void **)v1 + 2),
*((const void **)v1 + 3));
if ( func7((__int64)v1) )
break;
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
}
while ( v1 );
}
}

original_code:
void printBlock(BlockPtr block){
 if(block == ((void *)0)) return;
 printf("Address: %p kval:%d tag:%d blockStartingAddress:%p next:%p prev:%p -->", block, block->kval, block->tag, block->blockStartingAddress, block->next, block->prev);
 if(!isNextBlockNull(block)) printBlock(block->next);
}

canonical_original_code:
void printBlock(struct block *block){
 if(block == ((void *)0)) return;
 printf("Address: %p kval:%d tag:%d blockStartingAddress:%p next:%p prev:%p -->", block, block->kval, block->tag, block->blockStartingAddress, block->next, block->prev);
 if(!isNextBlockNull(block)) printBlock(block->next);
}

variable_types: struct block { int tag; int kval; char *blockStartingAddress; struct block *next; struct block *prev; } *


printAddress

decompiled_code:
void __fastcall printAddress(__int64 a1)
{
unsigned int *v1; // rax

if ( a1 )
{
v1 = (unsigned int *)addToAddress(a1, -9);
printBlock(v1);
}
}

canonical_decompiled_code:
void __fastcall func22(__int64 a1)
{
unsigned int *v1; // rax

if ( a1 )
{
v1 = (unsigned int *)func0(a1, -9);
func21(v1);
}
}

original_code:
void printAddress(BlockPtr block){
 if(block == ((void *)0)) return;
 size_t blockHeaderAddress = addToAddress(block, -9);
 BlockPtr blockToPrint = (BlockPtr) blockHeaderAddress;
 printBlock(blockToPrint);
}

canonical_original_code:
void printAddress(struct block *block){
 if(block == ((void *)0)) return;
 unsigned long blockHeaderAddress = addToAddress(block, -9);
 struct block *blockToPrint = (BlockPtr) blockHeaderAddress;
 printBlock(blockToPrint);
}

variable_types:
blockHeaderAddress
unsigned long


printMemory

decompiled_code:
void printMemory()
{
__int64 i; // rbx
unsigned int *v1; // rdi

for ( i = 0LL; i != 27; ++i )
{
while ( isBlockIndexNull(i) )
{
if ( ++i == 27 )
return;
}
printf("\n\tBlock at index:%d ", (unsigned int)i);
v1 = (unsigned int *)blockAddress[i];
printBlock(v1);
}
}

canonical_decompiled_code:
void func23()
{
__int64 i; // rbx
unsigned int *v1; // rdi

for ( i = 0LL; i != 27; ++i )
{
while ( func8(i) )
{
if ( ++i == 27 )
return;
}
printf("\n\tBlock at index:%d ", (unsigned int)i);
v1 = (unsigned int *)blockAddress[i];
func21(v1);
}
}

original_code:
void printMemory(){
 int i = 0;
 for(; i <= 26; i++)
  if(!isBlockIndexNull(i)) {
   printf("\n\tBlock at index:%d ", i);
   printBlock(blockAddress[i]);
  }
}

variable_types: i int


decompiled_code:
__int64 __fastcall upper_power_of_two(unsigned int a1)
{
int v1; // esi
__int64 v2; // rdx
int v3; // eax
int v4; // ecx
bool v5; // cf

v1 = a1;
v2 = 4LL;
v3 = 0;
if ( (a1 & 0xFFFF0000) == 0 )
goto LABEL_3;
while ( 1 )
{
v4 = S[v2];
a1 >>= v4;
v3 |= v4;
LABEL_3:
v5 = v2-- == 0;
if ( v5 )
break;
while ( (a1 & b[v2]) == 0 )
{
v5 = v2-- == 0;
if ( v5 )
return (unsigned int)(1 << v3 < v1) + v3;
}
}
return (unsigned int)(1 << v3 < v1) + v3;
}

canonical_decompiled_code:
__int64 __fastcall func24(unsigned int a1)
{
int v1; // esi
__int64 v2; // rdx
int v3; // eax
int v4; // ecx
bool v5; // cf

v1 = a1;
v2 = 4LL;
v3 = 0;
if ( (a1 & 0xFFFF0000) == 0 )
goto LABEL_3;
while ( 1 )
{
v4 = S[v2];
a1 >>= v4;
v3 |= v4;
LABEL_3:
v5 = v2-- == 0;
if ( v5 )
break;
while ( (a1 & b[v2]) == 0 )
{
v5 = v2-- == 0;
if ( v5 )
return (unsigned int)(1 << v3 < v1) + v3;
}
}
return (unsigned int)(1 << v3 < v1) + v3;
}

original_code:
int upper_power_of_two(uint v)
{
 int o = v;
 int i;
 register uint r = 0;
 for (i = 4; i >= 0; i--)
 {
   if (v & b[i])
   {
  v >>= S[i];
  r |= S[i];
   }
 }
 if(o > (1<<r)) r++;
 return r;
}

canonical_original_code:
int upper_power_of_two(unsigned int v)
{
 int o = v;
 int i;
 register unsigned int r = 0;
 for (i = 4; i >= 0; i--)
 {
   if (v & b[i])
   {
  v >>= S[i];
  r |= S[i];
   }
 }
 if(o > (1<<r)) r++;
 return r;
}

variable_types:
v
unsigned int

variable_types: o int

variable_types:
r
unsigned int


printNode

decompiled_code:
int __fastcall printNode(_QWORD *a1)
{
const char *v1; // rax

v1 = (const char *)toString(*a1);
return printf(" %s -->", v1);
}

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

v1 = (const char *)toString(*a1);
return printf(" %s -->", v1);
}

original_code:
void printNode(NodePtr node)
{
 char* output = toString(node->data);
 printf(" %s -->",output);
}

canonical_original_code:
void printNode(struct node *node)
{
 char *output = toString(node->data);
 printf(" %s -->",output);
}

variable_types: struct node { struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *data; struct node *next; struct node *prev; } *

variable_types:
output
char *


isNodeNull

decompiled_code:
_BOOL8 __fastcall isNodeNull(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return a1 == 0;
}

original_code:
int isNodeNull(NodePtr n){
        return n == ((void *)0);
}

canonical_original_code:
int isNodeNull(struct node *n){
        return n == ((void *)0);
}


freeNode

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

result = isNodeNull((__int64)a1);
if ( !(_DWORD)result )
{
freeJob(*a1);
result = buddy_free(a1);
}
return result;
}

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

result = func1((__int64)a1);
if ( !(_DWORD)result )
{
freeJob(*a1);
result = buddy_free(a1);
}
return result;
}

original_code:
void freeNode (NodePtr node)
{
 if (isNodeNull(node)) return;
 freeJob(node->data);
 buddy_free(node);
}

canonical_original_code:
void freeNode(struct node *node)
{
 if (isNodeNull(node)) return;
 freeJob(node->data);
 buddy_free(node);
}


reverse

original_code:
static NodePtr reverse(NodePtr L)
{
 NodePtr list = ((void *)0);
 while (L != ((void *)0)) {
  NodePtr tmp = L;
  L = L->next;
  if (L != ((void *)0)) L->prev = tmp;
  tmp->next = list;
  tmp->prev = L;
  list = tmp;
 }
 return list;
}

canonical_original_code:
static struct node *reverse(struct node *L)
{
 struct node *list = ((void *)0);
 while (L != ((void *)0)) {
  struct node *tmp = L;
  L = L->next;
  if (L != ((void *)0)) L->prev = tmp;
  tmp->next = list;
  tmp->prev = L;
  list = tmp;
 }
 return list;
}

variable_types:
L
struct node *

return_type: struct node { struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *data; struct node *next; struct node *prev; } *


print

decompiled_code:
void __fastcall print(_QWORD *a1)
{
_QWORD *v1; // rbx
const char *v2; // rbp

if ( a1 )
{
v1 = a1;
do
{
v2 = (const char *)toString(*v1);
printf("%s", v2);
buddy_free(v2);
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(_QWORD *a1)
{
_QWORD *v1; // rbx
const char *v2; // rbp

if ( a1 )
{
v1 = a1;
do
{
v2 = (const char *)toString(*v1);
printf("%s", v2);
buddy_free(v2);
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
}

original_code:
static void print(NodePtr node)
{
 char *output;
 while (node) {
  output = toString(node->data);
  printf("%s",output);
  buddy_free(output);
  node = node->next;
 }
}

canonical_original_code:
static void print(struct node *node)
{
 char *output;
 while (node) {
  output = toString(node->data);
  printf("%s",output);
  buddy_free(output);
  node = node->next;
 }
}


createList

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

result = buddy_malloc(24LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
return result;
}

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

result = buddy_malloc(24LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
return result;
}

original_code:
ListPtr createList()
{
 ListPtr list;
 list = (ListPtr) buddy_malloc(sizeof(List));
 list->size = 0;
 list->head = ((void *)0);
 list->tail = ((void *)0);
 return list;
}

canonical_original_code:
struct list *createList()
{
 struct list *list;
 list = (struct list *) buddy_malloc(sizeof(List));
 list->size = 0;
 list->head = ((void *)0);
 list->tail = ((void *)0);
 return list;
}

variable_types: struct list { int size; struct node { struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *data; struct node *next; struct node *prev; } *head; struct node *tail; } *


freeList

decompiled_code:
__int64 __fastcall freeList(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

if ( a1 )
{
if ( *(_DWORD *)a1 )
{
v2 = *(_QWORD *)(a1 + 8);
while ( v2 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
freeNode(v3);
}
}
result = buddy_free(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

if ( a1 )
{
if ( *(_DWORD *)a1 )
{
v2 = *(_QWORD *)(a1 + 8);
while ( v2 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
freeNode(v3);
}
}
result = buddy_free(a1);
}
return result;
}

original_code:
void freeList(ListPtr L)
{
 if(L==((void *)0)) return;
 if(L->size == 0) buddy_free(L);
 else
 {
  NodePtr currentNode = L->head;
  while(currentNode != ((void *)0)){
   NodePtr temp = currentNode;
   currentNode = currentNode->next;
   freeNode(temp);
  }
  buddy_free(L);
 }
}

canonical_original_code:
void freeList(struct list *L)
{
 if(L==((void *)0)) return;
 if(L->size == 0) buddy_free(L);
 else
 {
  struct node *currentNode = L->head;
  while(currentNode != ((void *)0)){
   struct node *temp = currentNode;
   currentNode = currentNode->next;
   freeNode(temp);
  }
  buddy_free(L);
 }
}


getSize

decompiled_code:
__int64 __fastcall getSize(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
return *a1;
}

original_code:
int getSize(ListPtr L)
{
 return L->size;
}

canonical_original_code:
int getSize(struct list *L)
{
 return L->size;
}


isEmpty

decompiled_code:
_BOOL8 __fastcall isEmpty(_DWORD *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_DWORD *a1)
{
return *a1 == 0;
}

original_code:
Boolean isEmpty(ListPtr L)
{
 if (L->size == 0)
  return 1;
 else
  return 0;
}

canonical_original_code:
int isEmpty(struct list *L)
{
 if (L->size == 0)
  return 1;
 else
  return 0;
}


addAtFront

original_code:
void addAtFront(ListPtr list, NodePtr node)
{
 if (list == ((void *)0)) return;
 if (node == ((void *)0)) return;
 list->size++;
 node->next = list->head;
 node->prev = ((void *)0);
 if (list->head == ((void *)0))
 {
  list->head = node;
  list->tail = node;
 } else {
  list->head->prev = node;
  list->head = node;
 }
}

canonical_original_code:
void addAtFront(struct list *list, struct node *node)
{
 if (list == ((void *)0)) return;
 if (node == ((void *)0)) return;
 list->size++;
 node->next = list->head;
 node->prev = ((void *)0);
 if (list->head == ((void *)0))
 {
  list->head = node;
  list->tail = node;
 } else {
  list->head->prev = node;
  list->head = node;
 }
}

variable_types:
node
struct node *


addAtRear

original_code:
void addAtRear(ListPtr list, NodePtr node)
{
 if(list == ((void *)0) || node == ((void *)0)) return;
 list->size++;
 node->next = ((void *)0);
 node->prev = list->tail;
 if(list->head == ((void *)0))
 {
  list->head = node;
  list->tail = node;
 } else {
  list->tail->next = node;
  list->tail = node;
 }
}

canonical_original_code:
void addAtRear(struct list *list, struct node *node)
{
 if(list == ((void *)0) || node == ((void *)0)) return;
 list->size++;
 node->next = ((void *)0);
 node->prev = list->tail;
 if(list->head == ((void *)0))
 {
  list->head = node;
  list->tail = node;
 } else {
  list->tail->next = node;
  list->tail = node;
 }
}


removeFront

decompiled_code:
__int64 __fastcall removeFront(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( !a1 || !*(_DWORD *)a1 )
return 0LL;
--*(_DWORD *)a1;
result = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(result + 8);
*(_QWORD *)(a1 + 8) = v2;
if ( v2 )
{
*(_QWORD *)(v2 + 16) = 0LL;
*(_QWORD *)(result + 8) = 0LL;
}
else
{
*(_QWORD *)(a1 + 16) = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( !a1 || !*(_DWORD *)a1 )
return 0LL;
--*(_DWORD *)a1;
result = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(result + 8);
*(_QWORD *)(a1 + 8) = v2;
if ( v2 )
{
*(_QWORD *)(v2 + 16) = 0LL;
*(_QWORD *)(result + 8) = 0LL;
}
else
{
*(_QWORD *)(a1 + 16) = 0LL;
}
return result;
}

original_code:
NodePtr removeFront(ListPtr list)
{
 if(list == ((void *)0) || list->size == 0) return ((void *)0);
 list->size--;
 NodePtr prevHeadNode = list->head;
 list->head = list->head->next;
 if(list->head != ((void *)0))
 {
  list->head->prev = ((void *)0);
  prevHeadNode->next = ((void *)0);
 } else {
  list->tail = ((void *)0);
 }
 return prevHeadNode;
}

canonical_original_code:
struct node *removeFront(struct list *list)
{
 if(list == ((void *)0) || list->size == 0) return ((void *)0);
 list->size--;
 struct node *prevHeadNode = list->head;
 list->head = list->head->next;
 if(list->head != ((void *)0))
 {
  list->head->prev = ((void *)0);
  prevHeadNode->next = ((void *)0);
 } else {
  list->tail = ((void *)0);
 }
 return prevHeadNode;
}

variable_types: struct list { int size; struct node *head; struct node *tail; } *


removeRear

decompiled_code:
__int64 __fastcall removeRear(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( !a1 || !*(_DWORD *)a1 )
return 0LL;
--*(_DWORD *)a1;
result = *(_QWORD *)(a1 + 16);
v2 = *(_QWORD *)(result + 16);
*(_QWORD *)(a1 + 16) = v2;
if ( v2 )
{
*(_QWORD *)(v2 + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
}
else
{
*(_QWORD *)(a1 + 8) = 0LL;
}
return result;
}

original_code:
NodePtr removeRear(ListPtr list)
{
 if(list == ((void *)0) || list->size == 0) return ((void *)0);
 list->size--;
 NodePtr prevTailNode = list->tail;
 list->tail = list->tail->prev;
 if(list->tail != ((void *)0))
 {
  list->tail->next = ((void *)0);
  prevTailNode->prev = ((void *)0);
 } else {
  list->head = ((void *)0);
 }
 return prevTailNode;
}

canonical_original_code:
struct node *removeRear(struct list *list)
{
 if(list == ((void *)0) || list->size == 0) return ((void *)0);
 list->size--;
 struct node *prevTailNode = list->tail;
 list->tail = list->tail->prev;
 if(list->tail != ((void *)0))
 {
  list->tail->next = ((void *)0);
  prevTailNode->prev = ((void *)0);
 } else {
  list->head = ((void *)0);
 }
 return prevTailNode;
}


removeNode

decompiled_code:
__int64 __fastcall removeNode(int *a1, __int64 a2)
{
int v2; // ecx
__int64 v3; // r8
__int64 result; // rax
__int64 v5; // rdx
__int64 v6; // rsi

if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
if ( a2 )
{
v3 = *((_QWORD *)a1 + 1);
result = v3;
while ( 1 )
{
v5 = result;
result = *(_QWORD *)(result + 8);
if ( v5 == a2 )
break;
if ( !result )
return result;
}
if ( result )
*(_QWORD *)(result + 16) = *(_QWORD *)(a2 + 16);
v6 = *(_QWORD *)(v5 + 16);
if ( v6 )
*(_QWORD *)(v6 + 8) = result;
if ( v5 == v3 )
{
*((_QWORD *)a1 + 1) = *(_QWORD *)(v5 + 8);
if ( *((_QWORD *)a1 + 2) != v5 )
goto LABEL_13;
}
else if ( *((_QWORD *)a1 + 2) != v5 )
{
LABEL_13:
*(_QWORD *)(v5 + 16) = 0LL;
result = v5;
*(_QWORD *)(v5 + 8) = 0LL;
*a1 = v2 - 1;
return result;
}
*((_QWORD *)a1 + 2) = v6;
goto LABEL_13;
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1, __int64 a2)
{
int v2; // ecx
__int64 v3; // r8
__int64 result; // rax
__int64 v5; // rdx
__int64 v6; // rsi

if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
if ( a2 )
{
v3 = *((_QWORD *)a1 + 1);
result = v3;
while ( 1 )
{
v5 = result;
result = *(_QWORD *)(result + 8);
if ( v5 == a2 )
break;
if ( !result )
return result;
}
if ( result )
*(_QWORD *)(result + 16) = *(_QWORD *)(a2 + 16);
v6 = *(_QWORD *)(v5 + 16);
if ( v6 )
*(_QWORD *)(v6 + 8) = result;
if ( v5 == v3 )
{
*((_QWORD *)a1 + 1) = *(_QWORD *)(v5 + 8);
if ( *((_QWORD *)a1 + 2) != v5 )
goto LABEL_13;
}
else if ( *((_QWORD *)a1 + 2) != v5 )
{
LABEL_13:
*(_QWORD *)(v5 + 16) = 0LL;
result = v5;
*(_QWORD *)(v5 + 8) = 0LL;
*a1 = v2 - 1;
return result;
}
*((_QWORD *)a1 + 2) = v6;
goto LABEL_13;
}
}
}
return 0LL;
}

original_code:
NodePtr removeNode(ListPtr list, NodePtr node)
{
 if(list == ((void *)0) || list->size == 0 || node == ((void *)0)) return ((void *)0);
 NodePtr currentNode = list->head;
 while (currentNode != node){
  if(currentNode->next != ((void *)0))
   currentNode = currentNode->next;
  else{
   currentNode = ((void *)0);
   break;
  }
 }
 if(currentNode != ((void *)0))
 {
  if(currentNode->next != ((void *)0))
   currentNode->next->prev = currentNode->prev;
  if(currentNode->prev != ((void *)0))
   currentNode->prev->next = currentNode->next;
  if(list->head == currentNode)
   list->head = currentNode->next;
  if(list->tail == currentNode)
   list->tail = currentNode->prev;
  currentNode->next = currentNode->prev = ((void *)0);
  list->size--;
 }
 return currentNode;
}

canonical_original_code:
struct node *removeNode(struct list *list, struct node *node)
{
 if(list == ((void *)0) || list->size == 0 || node == ((void *)0)) return ((void *)0);
 struct node *currentNode = list->head;
 while (currentNode != node){
  if(currentNode->next != ((void *)0))
   currentNode = currentNode->next;
  else{
   currentNode = ((void *)0);
   break;
  }
 }
 if(currentNode != ((void *)0))
 {
  if(currentNode->next != ((void *)0))
   currentNode->next->prev = currentNode->prev;
  if(currentNode->prev != ((void *)0))
   currentNode->prev->next = currentNode->next;
  if(list->head == currentNode)
   list->head = currentNode->next;
  if(list->tail == currentNode)
   list->tail = currentNode->prev;
  currentNode->next = currentNode->prev = ((void *)0);
  list->size--;
 }
 return currentNode;
}


search

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

if ( !a1 || !*(_DWORD *)a1 )
return 0LL;
result = *(_QWORD *)(a1 + 8);
do
{
if ( **(_DWORD **)result == a2 )
break;
result = *(_QWORD *)(result + 8);
}
while ( result );
return result;
}

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

if ( !a1 || !*(_DWORD *)a1 )
return 0LL;
result = *(_QWORD *)(a1 + 8);
do
{
if ( **(_DWORD **)result == a2 )
break;
result = *(_QWORD *)(result + 8);
}
while ( result );
return result;
}

original_code:
NodePtr search(ListPtr list, int key)
{
 if(list == ((void *)0) || list->size == 0) return ((void *)0);
 NodePtr currentNode = list->head;
 while(currentNode->data->jobid != key){
  if(currentNode->next != ((void *)0))
   currentNode = currentNode->next;
  else{
   currentNode = ((void *)0);
   break;
  }
 }
 return currentNode;
}

canonical_original_code:
struct node *search(struct list *list, int key)
{
 if(list == ((void *)0) || list->size == 0) return ((void *)0);
 struct node *currentNode = list->head;
 while(currentNode->data->jobid != key){
  if(currentNode->next != ((void *)0))
   currentNode = currentNode->next;
  else{
   currentNode = ((void *)0);
   break;
  }
 }
 return currentNode;
}

variable_types: key int


reverseList

original_code:
void reverseList(ListPtr L)
{
 if (L == ((void *)0)) return;
 L->tail = L->head;
 L->head = reverse (L->head);
}

canonical_original_code:
void reverseList(struct list *L)
{
 if (L == ((void *)0)) return;
 L->tail = L->head;
 L->head = reverse (L->head);
}


printList

decompiled_code:
void __fastcall printList(__int64 a1)
{
if ( a1 )
print(*(_QWORD **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1)
{
if ( a1 )
func1(*(_QWORD **)(a1 + 8));
}

original_code:
void printList(ListPtr L)
{
 if (L) print(L->head);
}

canonical_original_code:
void printList(struct list *L)
{
 if (L) print(L->head);
}


decompiled_code:
int __fastcall err_doit(int a1, const char *a2, void *a3)
{
int v4; // er13
size_t v5; // rax
FILE *v6; // rdi
char *v8; // r12
size_t v9; // rax
char s[2]; // [rsp+0h] [rbp-1028h] BYREF

v4 = *_errno_location();
vsprintf(s, a2, a3);
if ( a1 )
{
v8 = strerror(v4);
v9 = strlen(s);
sprintf(&s[v9], ": %s", v8);
}
v5 = strlen(s);
v6 = stdout;
*(_WORD *)&s[v5] = 10;
fflush(v6);
fputs(s, stderr);
return fflush(0LL);
}

canonical_decompiled_code:
int __fastcall func0(int a1, const char *a2, void *a3)
{
int v4; // er13
size_t v5; // rax
FILE *v6; // rdi
char *v8; // r12
size_t v9; // rax
char s[2]; // [rsp+0h] [rbp-1028h] BYREF

v4 = *_errno_location();
vsprintf(s, a2, a3);
if ( a1 )
{
v8 = strerror(v4);
v9 = strlen(s);
sprintf(&s[v9], ": %s", v8);
}
v5 = strlen(s);
v6 = stdout;
*(_WORD *)&s[v5] = 10;
fflush(v6);
fputs(s, stderr);
return fflush(0LL);
}

original_code:
static void
err_doit(int errnoflag, const char *fmt, va_list ap)
{
 int errno_save;
 char buf[4096];
 errno_save = (*__errno_location ());
 vsprintf(buf, fmt, ap);
 if (errnoflag)
  sprintf(buf+strlen(buf), ": %s", strerror(errno_save));
 strcat(buf, "\n");
 fflush(stdout);
 fputs(buf, stderr);
 fflush(((void *)0));
 return;
}

canonical_original_code:
static void err_doit(int errnoflag, char *fmt, __builtin_va_list ap)
{
 int errno_save;
 char buf[4096];
 errno_save = (*__errno_location ());
 vsprintf(buf, fmt, ap);
 if (errnoflag)
  sprintf(buf+strlen(buf), ": %s", strerror(errno_save));
 strcat(buf, "\n");
 fflush(stdout);
 fputs(buf, stderr);
 fflush(((void *)0));
 return;
}

variable_types: errnoflag int

variable_types:
fmt
char *

variable_types:
buf
char [4096]


decompiled_code:
int err_ret(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return err_doit(1, a1, va);
}

canonical_decompiled_code:
int func1(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func0(1, a1, va);
}

original_code:
void
err_ret(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, fmt, ap);
 __builtin_va_end(ap);
 return;
}

canonical_original_code:
void err_ret(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, fmt, ap);
 __builtin_va_end(ap);
 return;
}


decompiled_code:
void __noreturn err_sys(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
err_doit(1, a1, va);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(1, a1, va);
exit(1);
}

original_code:
void
err_sys(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
void err_sys(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}


decompiled_code:
void __noreturn err_dump(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
err_doit(1, a1, va);
abort();
}

canonical_decompiled_code:
void __noreturn func3(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(1, a1, va);
abort();
}

original_code:
void
err_dump(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, fmt, ap);
 __builtin_va_end(ap);
 abort();
 exit(1);
}

canonical_original_code:
void err_dump(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, fmt, ap);
 __builtin_va_end(ap);
 abort();
 exit(1);
}


decompiled_code:
int err_msg(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return err_doit(0, a1, va);
}

canonical_decompiled_code:
int func4(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func0(0, a1, va);
}

original_code:
void
err_msg(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(0, fmt, ap);
 __builtin_va_end(ap);
 return;
}

canonical_original_code:
void err_msg(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(0, fmt, ap);
 __builtin_va_end(ap);
 return;
}


decompiled_code:
void __noreturn err_quit(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
err_doit(0, a1, va);
exit(1);
}

canonical_decompiled_code:
void __noreturn func5(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(0, a1, va);
exit(1);
}

original_code:
void
err_quit(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(0, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
void err_quit(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(0, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}


jumpBack

decompiled_code:
void __noreturn jumpBack()
{
siglongjmp(env, 333333);
}

canonical_decompiled_code:
void __noreturn func0()
{
siglongjmp(env, 333333);
}

original_code: void jumpBack(){ siglongjmp(env,333333); }


initialize

decompiled_code:
__int64 initialize()
{
jobList = createList();
using_history();
bindKeys();
return initSignals(jumpBack);
}

canonical_decompiled_code:
__int64 func1()
{
jobList = createList();
using_history();
bindKeys();
return initSignals(jumpBack);
}

original_code:
void initialize()
{
 jobList = createList();
 using_history();
 bindKeys();
 initSignals(jumpBack);
}


createAndSetNode

decompiled_code:
__int64 __fastcall createAndSetNode(_DWORD *a1, unsigned int a2, __int64 a3, int a4)
{
__int64 v5; // rax
__int64 v6; // r12

v5 = createJob(a2, a3, (unsigned int)*a1);
if ( a4 == 1 )
*(_DWORD *)(v5 + 24) = 1;
++*a1;
v6 = createNode(v5);
setNode(v6);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, unsigned int a2, __int64 a3, int a4)
{
__int64 v5; // rax
__int64 v6; // r12

v5 = createJob(a2, a3, (unsigned int)*a1);
if ( a4 == 1 )
*(_DWORD *)(v5 + 24) = 1;
++*a1;
v6 = createNode(v5);
setNode(v6);
return v6;
}

original_code:
NodePtr createAndSetNode(int *jobNumber, int backgroundJob, char* bufCopy, int isBackground){
     JobPtr job = createJob((int)backgroundJob, bufCopy, *jobNumber);
  if(isBackground == 1) job->background = 1;
  (*jobNumber)++;
  NodePtr node = createNode(job);
  setNode(node);
  return node;
}

canonical_original_code:
struct node *createAndSetNode(int *jobNumber, int backgroundJob, char *bufCopy, int isBackground){
     struct job *job = createJob((int)backgroundJob, bufCopy, *jobNumber);
  if(isBackground == 1) job->background = 1;
  (*jobNumber)++;
  struct node *node = createNode(job);
  setNode(node);
  return node;
}

variable_types:
jobNumber
int *

variable_types: backgroundJob int

variable_types:
bufCopy
char *

variable_types: isBackground int

variable_types: struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *


recordCommand

decompiled_code:
__int64 __fastcall recordCommand(unsigned int **a1, __int64 a2)
{
printf("[%i] %i %s\n", a2, **a1, *((const char **)*a1 + 1));
return addAtFront(jobList, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int **a1, __int64 a2)
{
printf("[%i] %i %s\n", a2, **a1, *((const char **)*a1 + 1));
return addAtFront(jobList, a1);
}

original_code:
void recordCommand(NodePtr n, int jobNumber, int isBackground)
{
 printf("[%i] %i %s\n", jobNumber, n->data->jobid, n->data->command);
 addAtFront(jobList, n);
}

canonical_original_code:
void recordCommand(struct node *n, int jobNumber, int isBackground)
{
 printf("[%i] %i %s\n", jobNumber, n->data->jobid, n->data->command);
 addAtFront(jobList, n);
}

variable_types: jobNumber int