newList

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

result = xmalloc(32LL);
if ( result )
{
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
}
return result;
}

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

result = xmalloc(32LL);
if ( result )
{
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
}
return result;
}

original_code:
s_list *newList(void)
{
 s_list *list;
 if ((list = xmalloc(sizeof(*list))) == ((void *)0))
 {
  return ((void *)0);
 }
 list->len = 0;
 list->curr = ((void *)0);
 list->head = ((void *)0);
 list->tail = ((void *)0);
 return list;
}

canonical_original_code:
struct s_list *newList()
{
 struct s_list *list;
 if ((list = xmalloc(sizeof(*list))) == ((void *)0))
 {
  return ((void *)0);
 }
 list->len = 0;
 list->curr = ((void *)0);
 list->head = ((void *)0);
 list->tail = ((void *)0);
 return list;
}

variable_types: struct s_list { int len; struct s_item { struct s_var { enum e_var { INT=0, CHAR=1, STR=2, PTR=3 } type; union u_var { int _int; char _char; char *_str; void *_ptr; } value; } *val; struct s_item *next; struct s_item *prev; } *curr; struct s_item *head; struct s_item *tail; } *


newItem

repo: HallowTeam/CLib

decompiled_code:
__int64 newItem()
{
__int64 v0; // rax
_QWORD *v1; // r12
__int64 v2; // rax
__int64 result; // rax

v0 = xmalloc(24LL);
v1 = (_QWORD *)v0;
if ( v0 && (*(_QWORD *)(v0 + 16) = 0LL, *(_QWORD *)(v0 + 8) = 0LL, v2 = xmalloc(16LL), (*v1 = v2) == 0LL) )
result = xfree(v1);
else
result = (__int64)v1;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
_QWORD *v1; // r12
__int64 v2; // rax
__int64 result; // rax

v0 = xmalloc(24LL);
v1 = (_QWORD *)v0;
if ( v0 && (*(_QWORD *)(v0 + 16) = 0LL, *(_QWORD *)(v0 + 8) = 0LL, v2 = xmalloc(16LL), (*v1 = v2) == 0LL) )
result = xfree(v1);
else
result = (__int64)v1;
return result;
}

original_code:
s_item *newItem(void)
{
 s_item *item;
 if ((item = xmalloc(sizeof(*item))) == ((void *)0))
 {
  return ((void *)0);
 }
 item->prev = ((void *)0);
 item->next = ((void *)0);
 item->val = xmalloc(sizeof(*(item->val)));
 if (item->val == ((void *)0))
 {
  return xfree(item);
 }
 return item;
}

canonical_original_code:
struct s_item *newItem()
{
 struct s_item *item;
 if ((item = xmalloc(sizeof(*item))) == ((void *)0))
 {
  return ((void *)0);
 }
 item->prev = ((void *)0);
 item->next = ((void *)0);
 item->val = xmalloc(sizeof(*(item->val)));
 if (item->val == ((void *)0))
 {
  return xfree(item);
 }
 return item;
}

variable_types: struct s_item { struct s_var { enum e_var { INT=0, CHAR=1, STR=2, PTR=3 } type; union u_var { int _int; char _char; char *_str; void *_ptr; } value; } *val; struct s_item *next; struct s_item *prev; } *

user_defined_types: struct s_item { struct s_var *val; struct s_item *next; struct s_item *prev; }

user_defined_types: struct s_var { enum e_var type; union u_var value; }


getItem

decompiled_code:
__int64 __fastcall getItem(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // edx

result = *(_QWORD *)(a1 + 16);
if ( result )
{
if ( a2 <= 0 )
return result;
v3 = 0;
while ( 1 )
{
result = *(_QWORD *)(result + 8);
++v3;
if ( !result )
break;
if ( a2 == v3 )
return result;
}
}
return *(_QWORD *)(a1 + 24);
}

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

result = *(_QWORD *)(a1 + 16);
if ( result )
{
if ( a2 <= 0 )
return result;
v3 = 0;
while ( 1 )
{
result = *(_QWORD *)(result + 8);
++v3;
if ( !result )
break;
if ( a2 == v3 )
return result;
}
}
return *(_QWORD *)(a1 + 24);
}

original_code:
s_item *getItem(s_list *list, int index)
{
 int i;
 s_item *item = list->head;
 for (i = 0; item != ((void *)0); i++)
 {
  if (i >= index)
  {
   return item;
  }
  item = item->next;
 }
 return list->tail;
}

canonical_original_code:
struct s_item *getItem(struct s_list *list, int index)
{
 int i;
 struct s_item *item = list->head;
 for (i = 0; item != ((void *)0); i++)
 {
  if (i >= index)
  {
   return item;
  }
  item = item->next;
 }
 return list->tail;
}

variable_types: struct s_list { int len; struct s_item *curr; struct s_item *head; struct s_item *tail; } *

variable_types: index int

variable_types: i int

return_type: struct s_item { struct s_var { enum e_var { INT=0, CHAR=1, STR=2, PTR=3 } type; union u_var { int _int; char _char; char *_str; void *_ptr; } value; } *val; struct s_item *next; struct s_item *prev; } *


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *v1; // r12

v1 = malloc(a1);
if ( !v1 )
printf("Error : malloc()");
return v1;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *v1; // r12

v1 = malloc(a1);
if ( !v1 )
printf("Error : malloc()");
return v1;
}

original_code:
void *xmalloc(size_t size)
{
 void *ptr;
 if ((ptr = malloc(size)) == ((void *)0))
 {
  printf("Error : malloc()");
 }
 return ptr;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
 void *ptr;
 if ((ptr = malloc(size)) == ((void *)0))
 {
  printf("Error : malloc()");
 }
 return ptr;
}

variable_types:
size
unsigned long

variable_types:
ptr
void *

return_type: void *


min

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

original_code:
int min(int a, int b)
{
 return ((a < b) ? a : b);
}

variable_types: a int

variable_types: b int

return_type: int


max

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

original_code:
int max(int a, int b)
{
 return ((a > b) ? a : b);
}


freeItem

decompiled_code:
__int64 __fastcall freeItem(__int64 a1, _QWORD *a2)
{
__int64 v2; // rdx
__int64 v3; // rax
__int64 result; // rax

v2 = a2[2];
v3 = a2[1];
if ( !v2 )
{
*(_QWORD *)(a1 + 16) = v3;
if ( v3 )
goto LABEL_3;
LABEL_6:
*(_QWORD *)(a1 + 24) = v2;
goto LABEL_4;
}
*(_QWORD *)(v2 + 8) = v3;
if ( !v3 )
goto LABEL_6;
LABEL_3:
*(_QWORD *)(v3 + 16) = v2;
LABEL_4:
xfree(*a2);
xfree(a2);
result = (unsigned int)(*(_DWORD *)a1 - 1);
*(_DWORD *)a1 = result;
return result;
}

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

v2 = a2[2];
v3 = a2[1];
if ( !v2 )
{
*(_QWORD *)(a1 + 16) = v3;
if ( v3 )
goto LABEL_3;
LABEL_6:
*(_QWORD *)(a1 + 24) = v2;
goto LABEL_4;
}
*(_QWORD *)(v2 + 8) = v3;
if ( !v3 )
goto LABEL_6;
LABEL_3:
*(_QWORD *)(v3 + 16) = v2;
LABEL_4:
xfree(*a2);
xfree(a2);
result = (unsigned int)(*(_DWORD *)a1 - 1);
*(_DWORD *)a1 = result;
return result;
}

original_code:
int freeItem(s_list *list, s_item *item)
{
 if (item->prev == ((void *)0))
 {
  list->head = item->next;
 }
 else
 {
  item->prev->next = item->next;
 }
 if (item->next == ((void *)0))
 {
  list->tail = item->prev;
 }
 else
 {
  item->next->prev = item->prev;
 }
 xfree(item->val);
 xfree(item);
 return list->len = list->len - 1;
}

canonical_original_code:
int freeItem(struct s_list *list, struct s_item *item)
{
 if (item->prev == ((void *)0))
 {
  list->head = item->next;
 }
 else
 {
  item->prev->next = item->next;
 }
 if (item->next == ((void *)0))
 {
  list->tail = item->prev;
 }
 else
 {
  item->next->prev = item->prev;
 }
 xfree(item->val);
 xfree(item);
 return list->len = list->len - 1;
}

variable_types:
item
struct s_item *

user_defined_types: struct s_list { int len; struct s_item *curr; struct s_item *head; struct s_item *tail; }

user_defined_types: enum e_var { INT=0, CHAR=1, STR=2, PTR=3 }

user_defined_types: union u_var { int _int; char _char; char *_str; void *_ptr; }


freeList

decompiled_code:
__int64 __fastcall freeList(__int64 a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

v1 = *(_QWORD **)(a1 + 16);
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)v1[1];
xfree(*v2);
xfree(v2);
}
return xfree(a1);
}

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

v1 = *(_QWORD **)(a1 + 16);
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)v1[1];
xfree(*v2);
xfree(v2);
}
return xfree(a1);
}

original_code:
void freeList(s_list *list)
{
 s_item *temp;
 s_item *item = list->head;
 while (item != ((void *)0))
 {
  temp = item;
  item = item->next;
  xfree(temp->val);
  xfree(temp);
 }
 xfree(list);
}

canonical_original_code:
void freeList(struct s_list *list)
{
 struct s_item *temp;
 struct s_item *item = list->head;
 while (item != ((void *)0))
 {
  temp = item;
  item = item->next;
  xfree(temp->val);
  xfree(temp);
 }
 xfree(list);
}

return_type: void


freeSocket

decompiled_code:
__int64 __fastcall freeSocket(int *a1)
{
int v2; // edi

v2 = *a1;
if ( v2 != -1 )
close(v2);
return xfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
int v2; // edi

v2 = *a1;
if ( v2 != -1 )
close(v2);
return xfree(a1);
}

original_code:
void *freeSocket(s_socket *sock)
{
 if (sock->fd != -1)
 {
  close(sock->fd);
 }
 return xfree(sock);
}

canonical_original_code:
void *freeSocket(struct s_socket *sock)
{
 if (sock->fd != -1)
 {
  close(sock->fd);
 }
 return xfree(sock);
}

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

user_defined_types: struct s_socket { int fd; struct sockaddr_in in; }

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


invertEndian

decompiled_code:
unsigned __int64 __fastcall invertEndian(__int64 a1)
{
return ((_DWORD)a1 << 8) & 0xFF0000 | (unsigned __int64)(unsigned int)((_DWORD)a1 << 24) | (a1 >> 8) & 0xFF00 | BYTE3(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1)
{
return ((_DWORD)a1 << 8) & 0xFF0000 | (unsigned __int64)(unsigned int)((_DWORD)a1 << 24) | (a1 >> 8) & 0xFF00 | BYTE3(a1);
}

variable_types: addr long

return_type: long


dumpStr

decompiled_code:
int __fastcall dumpStr(char *a1, int a2)
{
char *v2; // rbx
const unsigned __int16 **v3; // r12
__int64 v4; // rbp
__int64 v5; // rsi

if ( a2 > 0 )
{
v2 = a1;
v3 = _ctype_b_loc();
v4 = (__int64)&a1[a2 - 1 + 1];
do
{
while ( 1 )
{
v5 = *v2;
if ( ((*v3)[v5] & 0x4000) == 0 )
break;
++v2;
putchar(v5);
if ( (char *)v4 == v2 )
return putchar(10);
}
++v2;
printf("{%02X}", v5);
}
while ( (char *)v4 != v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(char *a1, int a2)
{
char *v2; // rbx
const unsigned __int16 **v3; // r12
__int64 v4; // rbp
__int64 v5; // rsi

if ( a2 > 0 )
{
v2 = a1;
v3 = _ctype_b_loc();
v4 = (__int64)&a1[a2 - 1 + 1];
do
{
while ( 1 )
{
v5 = *v2;
if ( ((*v3)[v5] & 0x4000) == 0 )
break;
++v2;
putchar(v5);
if ( (char *)v4 == v2 )
return putchar(10);
}
++v2;
printf("{%02X}", v5);
}
while ( (char *)v4 != v2 );
}
return putchar(10);
}

original_code:
void dumpStr(char *str, int len)
{
 int i;
 for (i = 0; i < len; i++)
 {
  if (((*__ctype_b_loc ())[(int) ((str[i]))] & (unsigned short int) _ISprint))
  {
   printf("%c", str[i]);
  }
  else
  {
   printf("{%02X}", str[i]);
  }
 }
 printf("\n");
}

canonical_original_code:
void dumpStr(char *str, int len)
{
 int i;
 for (i = 0; i < len; i++)
 {
  if (((*__ctype_b_loc ())[(int) ((str[i]))] & (unsigned short) _ISprint))
  {
   printf("%c", str[i]);
  }
  else
  {
   printf("{%02X}", str[i]);
  }
 }
 printf("\n");
}

variable_types:
str
char *

variable_types: len int


xcalloc

decompiled_code:
void *__fastcall xcalloc(size_t a1, size_t a2)
{
void *v2; // r12

v2 = calloc(a1, a2);
if ( !v2 )
printf("Error : malloc()");
return v2;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1, size_t a2)
{
void *v2; // r12

v2 = calloc(a1, a2);
if ( !v2 )
printf("Error : malloc()");
return v2;
}

original_code:
void *xcalloc(size_t members, size_t size)
{
 void *ptr;
 if ((ptr = calloc(members, size)) == ((void *)0))
 {
  printf("Error : malloc()");
 }
 return ptr;
}

canonical_original_code:
void *xcalloc(unsigned long members, unsigned long size)
{
 void *ptr;
 if ((ptr = calloc(members, size)) == ((void *)0))
 {
  printf("Error : malloc()");
 }
 return ptr;
}

variable_types:
members
unsigned long


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, size_t a2)
{
void *v2; // r12

v2 = realloc(a1, a2);
if ( !v2 )
{
xfree(a1);
printf("Error : malloc()");
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1, size_t a2)
{
void *v2; // r12

v2 = realloc(a1, a2);
if ( !v2 )
{
xfree(a1);
printf("Error : malloc()");
}
return v2;
}

original_code:
void *xrealloc(void *ptr, size_t size)
{
 void *copy = realloc(ptr, size);
 if (copy == ((void *)0))
 {
  xfree(ptr);
  printf("Error : malloc()");
 }
 return copy;
}

canonical_original_code:
void *xrealloc(void *ptr, unsigned long size)
{
 void *copy = realloc(ptr, size);
 if (copy == ((void *)0))
 {
  xfree(ptr);
  printf("Error : malloc()");
 }
 return copy;
}

variable_types:
copy
void *


printList

decompiled_code:
int __fastcall printList(__int64 a1)
{
__int64 v1; // rbx
char v2; // al
unsigned int v3; // eax
unsigned int v4; // eax
const void *v6; // rax
const char *v7; // rax

v1 = *(_QWORD *)(a1 + 16);
printf("NULL => ");
if ( v1 )
{
while ( 1 )
{
v3 = **(_DWORD **)v1;
if ( v3 == 2 )
break;
if ( v3 > 2 )
{
if ( v3 == 3 )
{
v6 = (const void *)getPtr();
printf("PTR : %p => ", v6);
}
else
{
printf("UNDEF => ");
}
goto LABEL_4;
}
if ( v3 )
{
v2 = getChar();
printf("CHAR : %c => ", (unsigned int)v2);
LABEL_4:
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
return puts("NULL");
}
else
{
v4 = getInt();
printf("INT : %d => ", v4);
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
return puts("NULL");
}
}
v7 = (const char *)getStr();
printf("STR : %s => ", v7);
goto LABEL_4;
}
return puts("NULL");
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
char v2; // al
unsigned int v3; // eax
unsigned int v4; // eax
const void *v6; // rax
const char *v7; // rax

v1 = *(_QWORD *)(a1 + 16);
printf("NULL => ");
if ( v1 )
{
while ( 1 )
{
v3 = **(_DWORD **)v1;
if ( v3 == 2 )
break;
if ( v3 > 2 )
{
if ( v3 == 3 )
{
v6 = (const void *)getPtr();
printf("PTR : %p => ", v6);
}
else
{
printf("UNDEF => ");
}
goto LABEL_4;
}
if ( v3 )
{
v2 = getChar();
printf("CHAR : %c => ", (unsigned int)v2);
LABEL_4:
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
return puts("NULL");
}
else
{
v4 = getInt();
printf("INT : %d => ", v4);
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
return puts("NULL");
}
}
v7 = (const char *)getStr();
printf("STR : %s => ", v7);
goto LABEL_4;
}
return puts("NULL");
}

original_code:
void printList(s_list *list)
{
 s_item *item = list->head;
 printf("NULL => ");
 while (item != ((void *)0))
 {
  switch (item->val->type)
  {
   case INT : printf("INT : %d => ", getInt(item->val)); break;
   case STR : printf("STR : %s => ", getStr(item->val)); break;
   case PTR : printf("PTR : %p => ", getPtr(item->val)); break;
   case CHAR: printf("CHAR : %c => ", getChar(item->val)); break;
   default : printf("UNDEF => ") ; break;
  }
  item = item->next;
 }
 printf("NULL\n");
}

canonical_original_code:
void printList(struct s_list *list)
{
 struct s_item *item = list->head;
 printf("NULL => ");
 while (item != ((void *)0))
 {
  switch (item->val->type)
  {
   case INT : printf("INT : %d => ", getInt(item->val)); break;
   case STR : printf("STR : %s => ", getStr(item->val)); break;
   case PTR : printf("PTR : %p => ", getPtr(item->val)); break;
   case CHAR: printf("CHAR : %c => ", getChar(item->val)); break;
   default : printf("UNDEF => ") ; break;
  }
  item = item->next;
 }
 printf("NULL\n");
}


main

canonical_name: main

repo: HalosGhost/immio

decompiled_code:
__int64 __fastcall main(int a1, char **a2, char **a3)
{
const char **v3; // rbp
int i; // eax
const char *v6; // rdi
char v7; // cl
__int64 result; // rax

v3 = (const char **)a2;
if ( !a2[1] )
LABEL_12:
sub_4012A0(*v3, a2, a3);
dword_404090 = 1;
if ( a1 > 1 )
{
for ( i = 1; i < a1; dword_404090 = i )
{
v6 = v3[i];
if ( *v6 == 45 )
{
v7 = v6[1];
a3 = (char **)(unsigned __int8)(v7 - 100);
switch ( v7 )
{
case 'd':
dword_404084 = 1;
goto LABEL_7;
case 'h':
goto LABEL_12;
case 'm':
sub_401520(v3[i + 1], v3[i + 2], v3[i + 3]);
return result;
case 'r':
sub_4014F0(v3[i + 1], v3[i + 2]);
return result;
case 'v':
dword_404080 = 1;
goto LABEL_7;
default:
fprintf(_bss_start, "Unrecognized option (%s).\nSee `%s -h` or `man %s` for help.\n", v3[i], *v3, *v3);
exit(1);
}
}
a2 = (char **)(unsigned int)dword_404084;
sub_401350(v6, (unsigned int)dword_404084, a3);
LABEL_7:
i = dword_404090 + 1;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall main(int a1, char **a2, char **a3)
{
const char **v3; // rbp
int i; // eax
const char *v6; // rdi
char v7; // cl
__int64 result; // rax

v3 = (const char **)a2;
if ( !a2[1] )
LABEL_12:
func6(*v3, a2, a3);
dword_404090 = 1;
if ( a1 > 1 )
{
for ( i = 1; i < a1; dword_404090 = i )
{
v6 = v3[i];
if ( *v6 == 45 )
{
v7 = v6[1];
a3 = (char **)(unsigned __int8)(v7 - 100);
switch ( v7 )
{
case 'd':
dword_404084 = 1;
goto LABEL_7;
case 'h':
goto LABEL_12;
case 'm':
func9(v3[i + 1], v3[i + 2], v3[i + 3]);
return result;
case 'r':
func8(v3[i + 1], v3[i + 2]);
return result;
case 'v':
dword_404080 = 1;
goto LABEL_7;
default:
fprintf(_bss_start, "Unrecognized option (%s).\nSee `%s -h` or `man %s` for help.\n", v3[i], *v3, *v3);
exit(1);
}
}
a2 = (char **)(unsigned int)dword_404084;
func7(v6, (unsigned int)dword_404084, a3);
LABEL_7:
i = dword_404090 + 1;
}
}
return 0LL;
}

original_code:
int main(int argc, char** argv) {
 if ( !argv[1] ) usage(argv[0]);
 for ( i = 1; i < argc; i++ ) {
  if ( argv[i][0]=='-' ) {
   switch ( argv[i][1] ) {
    case 'h': usage(argv[0]); break;
    case 'd': dirlnk=1; break;
    case 'r':
                                       rmimg(argv[i+1],argv[i+2]); break;
    case 'm':
                                                    mvimg(argv[i+1],argv[i+2],argv[i+3]); break;
    case 'v': verbose=1; break;
    default:
     fprintf(stderr,"Unrecognized option (%s).\nSee `%s -h` or `man %s` for help.\n",argv[i],argv[0],argv[0]);
     exit(1); break;
   }
  }
  else upload(argv[i],dirlnk);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 if ( !argv[1] ) usage(argv[0]);
 for ( i = 1; i < argc; i++ ) {
  if ( argv[i][0]=='-' ) {
   switch ( argv[i][1] ) {
    case 'h': usage(argv[0]); break;
    case 'd': dirlnk=1; break;
    case 'r':
                                       rmimg(argv[i+1],argv[i+2]); break;
    case 'm':
                                                    mvimg(argv[i+1],argv[i+2],argv[i+3]); break;
    case 'v': verbose=1; break;
    default:
     fprintf(stderr,"Unrecognized option (%s).\nSee `%s -h` or `man %s` for help.\n",argv[i],argv[0],argv[0]);
     exit(1); break;
   }
  }
  else upload(argv[i],dirlnk);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


repo: HalosGhost/vulpes

decompiled_code:
void __fastcall __noreturn main(int a1, char **a2, char **a3)
{
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
struct tm *v7; // rax
__int64 v8; // rdx
__int64 v9; // rax

stream = fopen("/proc/stat", "r");
__isoc99_fscanf();
fclose(stream);
if ( a2[1] )
sub_4016E0(*a2, "cpu %ld %ld %ld %ld", v3, v4, v5, v6);
while ( 1 )
{
stream = fopen("/sys/class/net/eth0/operstate", "r");
if ( stream )
{
__isoc99_fscanf();
fclose(stream);
printf("E:");
if ( byte_40411C == 117 )
printf("CN");
else
printf("DC");
printf(" | ");
}
stream = fopen("/proc/net/wireless", "r");
if ( stream )
{
dword_404124 = 0;
__isoc99_fscanf();
fclose(stream);
dword_404120 = 15;
if ( dword_404124 > 50 )
{
printf(".:l");
}
else if ( dword_404124 > 25 )
{
printf(".:");
}
else if ( dword_404124 <= 1 )
{
printf("DC");
}
else
{
putchar(46);
}
printf(" | ");
}
stream = fopen("/sys/bus/platform/devices/coretemp.0/temp1_input", "r");
if ( stream )
break;
LABEL_6:
stream = popen("ponymix get-volume", "r");
if ( stream )
{
__isoc99_fscanf();
pclose(stream);
printf("a:");
if ( system("ponymix is-muted") )
printf("%d", (unsigned int)dword_404124);
else
putchar(77);
printf(" | ");
}
stream = fopen("/sys/class/power_supply/BAT0/capacity", "r");
if ( stream )
{
__isoc99_fscanf();
fclose(stream);
stream = fopen("/sys/class/power_supply/BAT0/status", "r");
if ( stream )
{
__isoc99_fscanf();
fclose(stream);
}
printf("B:%d", (unsigned int)dword_404124);
if ( byte_40411D == 67 )
putchar(67);
printf(" | ");
}
time(&timer);
v7 = localtime(&timer);
strftime(s, 0x26uLL, "%H.%M | %A, %d %B %Y", v7);
printf("%s \n", s);
fflush(stdout);
sleep(1u);
}
__isoc99_fscanf();
fclose(stream);
printf("CPU:");
if ( dword_404120 > 88000 )
putchar(87);
stream = fopen("/proc/stat", "r");
__isoc99_fscanf();
fclose(stream);
if ( qword_404148 <= qword_404128 )
{
dword_404124 = 0;
}
else
{
v8 = qword_404150 + qword_404158 + qword_404160 - qword_404140 - qword_404138 - qword_404130;
v9 = 100 * v8 / (v8 + qword_404148 - qword_404128);
dword_404124 = v9;
if ( (int)v9 > 90 )
{
putchar(108);
goto LABEL_5;
}
if ( (int)v9 > 66 )
{
putchar(105);
goto LABEL_5;
}
if ( (int)v9 > 33 )
{
putchar(58);
goto LABEL_5;
}
}
putchar(46);
LABEL_5:
printf(" | ");
goto LABEL_6;
}

canonical_decompiled_code:
void __fastcall __noreturn main(int a1, char **a2, char **a3)
{
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
struct tm *v7; // rax
__int64 v8; // rdx
__int64 v9; // rax

stream = fopen("/proc/stat", "r");
__isoc99_fscanf();
fclose(stream);
if ( a2[1] )
func6(*a2, "cpu %ld %ld %ld %ld", v3, v4, v5, v6);
while ( 1 )
{
stream = fopen("/sys/class/net/eth0/operstate", "r");
if ( stream )
{
__isoc99_fscanf();
fclose(stream);
printf("E:");
if ( byte_40411C == 117 )
printf("CN");
else
printf("DC");
printf(" | ");
}
stream = fopen("/proc/net/wireless", "r");
if ( stream )
{
dword_404124 = 0;
__isoc99_fscanf();
fclose(stream);
dword_404120 = 15;
if ( dword_404124 > 50 )
{
printf(".:l");
}
else if ( dword_404124 > 25 )
{
printf(".:");
}
else if ( dword_404124 <= 1 )
{
printf("DC");
}
else
{
putchar(46);
}
printf(" | ");
}
stream = fopen("/sys/bus/platform/devices/coretemp.0/temp1_input", "r");
if ( stream )
break;
LABEL_6:
stream = popen("ponymix get-volume", "r");
if ( stream )
{
__isoc99_fscanf();
pclose(stream);
printf("a:");
if ( system("ponymix is-muted") )
printf("%d", (unsigned int)dword_404124);
else
putchar(77);
printf(" | ");
}
stream = fopen("/sys/class/power_supply/BAT0/capacity", "r");
if ( stream )
{
__isoc99_fscanf();
fclose(stream);
stream = fopen("/sys/class/power_supply/BAT0/status", "r");
if ( stream )
{
__isoc99_fscanf();
fclose(stream);
}
printf("B:%d", (unsigned int)dword_404124);
if ( byte_40411D == 67 )
putchar(67);
printf(" | ");
}
time(&timer);
v7 = localtime(&timer);
strftime(s, 0x26uLL, "%H.%M | %A, %d %B %Y", v7);
printf("%s \n", s);
fflush(stdout);
sleep(1u);
}
__isoc99_fscanf();
fclose(stream);
printf("CPU:");
if ( dword_404120 > 88000 )
putchar(87);
stream = fopen("/proc/stat", "r");
__isoc99_fscanf();
fclose(stream);
if ( qword_404148 <= qword_404128 )
{
dword_404124 = 0;
}
else
{
v8 = qword_404150 + qword_404158 + qword_404160 - qword_404140 - qword_404138 - qword_404130;
v9 = 100 * v8 / (v8 + qword_404148 - qword_404128);
dword_404124 = v9;
if ( (int)v9 > 90 )
{
putchar(108);
goto LABEL_5;
}
if ( (int)v9 > 66 )
{
putchar(105);
goto LABEL_5;
}
if ( (int)v9 > 33 )
{
putchar(58);
goto LABEL_5;
}
}
putchar(46);
LABEL_5:
printf(" | ");
goto LABEL_6;
}

original_code:
int main(int argc, char** argv) {
   in = fopen(CPU_FILE,"r");
   fscanf(in,"cpu %ld %ld %ld %ld",&j1,&j2,&j3,&j4);
   fclose(in);
   if (argv[1]) usage(argv[0]);
   for (;;) {
    if ( (in=fopen(WIRD_FILE,"r")) ) {
     fscanf(in,"%c",&stat); fclose(in);
     printf("E:");
     if (stat=='u') printf("CN");
     else printf("DC");
     printf(" | ");
    }
    if ( (in=fopen(WIFI_FILE,"r")) ) {
     n=0;
     fscanf(in,"%*[^\n]\n%*[^\n]\nwlan0: %*d %d.",&n); fclose(in);
     t=15;
     if ( n > 50 ) printf(".:l");
     else if ( n > 25 ) printf(".:");
     else if ( n > 1 ) printf(".");
     else printf("DC");
     printf(" | ");
    }
    if ( (in=fopen(CPU_TEMP,"r")) ) {
     fscanf(in,"%d",&t); fclose(in);
     printf("CPU:");
     if (t > 88000) printf("W");
     in = fopen(CPU_FILE,"r");
     fscanf(in,"cpu %ld %ld %ld %ld",&ln1,&ln2,&ln3,&ln4); fclose(in);
     if (ln4>j4) n=(int)100*(ln1-j1+ln2-j2+ln3-j3)/(ln1-j1+ln2-j2+ln3-j3+ln4-j4);
     else n=0;
     if (n > 90) printf("l");
     else if (n > 66) printf("i");
     else if (n > 33) printf(":");
     else printf(".");
     printf(" | ");
    }
    if ( (in=popen("ponymix get-volume","r")) ) {
     fscanf(in,"%d",&n); pclose(in);
     printf("a:");
     if (system("ponymix is-muted")==0) printf("M");
     else printf("%d", n);
     printf(" | ");
    }
    if ( (in=fopen(BATT_NOW,"r")) ) {
     fscanf(in,"%d\n",&n); fclose(in);
     if ( (in=fopen(BATT_STAT,"r")) ) { fscanf(in,"%c",&c); fclose(in); }
     printf("B:%d", n);
     if (c=='C') printf("C");
     printf(" | ");
    }
    if ((loops % 40) == 0) {
     time(&current);
     strftime(clk,38,"%H.%M | %A, %d %B %Y",localtime(&current));
     printf("%s \n",clk);
    }
    fflush(stdout);
    sleep(1);
   }
   return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
   in = fopen(CPU_FILE,"r");
   fscanf(in,"cpu %ld %ld %ld %ld",&j1,&j2,&j3,&j4);
   fclose(in);
   if (argv[1]) usage(argv[0]);
   for (;;) {
    if ( (in=fopen(WIRD_FILE,"r")) ) {
     fscanf(in,"%c",&stat); fclose(in);
     printf("E:");
     if (stat=='u') printf("CN");
     else printf("DC");
     printf(" | ");
    }
    if ( (in=fopen(WIFI_FILE,"r")) ) {
     n=0;
     fscanf(in,"%*[^\n]\n%*[^\n]\nwlan0: %*d %d.",&n); fclose(in);
     t=15;
     if ( n > 50 ) printf(".:l");
     else if ( n > 25 ) printf(".:");
     else if ( n > 1 ) printf(".");
     else printf("DC");
     printf(" | ");
    }
    if ( (in=fopen(CPU_TEMP,"r")) ) {
     fscanf(in,"%d",&t); fclose(in);
     printf("CPU:");
     if (t > 88000) printf("W");
     in = fopen(CPU_FILE,"r");
     fscanf(in,"cpu %ld %ld %ld %ld",&ln1,&ln2,&ln3,&ln4); fclose(in);
     if (ln4>j4) n=(int)100*(ln1-j1+ln2-j2+ln3-j3)/(ln1-j1+ln2-j2+ln3-j3+ln4-j4);
     else n=0;
     if (n > 90) printf("l");
     else if (n > 66) printf("i");
     else if (n > 33) printf(":");
     else printf(".");
     printf(" | ");
    }
    if ( (in=popen("ponymix get-volume","r")) ) {
     fscanf(in,"%d",&n); pclose(in);
     printf("a:");
     if (system("ponymix is-muted")==0) printf("M");
     else printf("%d", n);
     printf(" | ");
    }
    if ( (in=fopen(BATT_NOW,"r")) ) {
     fscanf(in,"%d\n",&n); fclose(in);
     if ( (in=fopen(BATT_STAT,"r")) ) { fscanf(in,"%c",&c); fclose(in); }
     printf("B:%d", n);
     if (c=='C') printf("C");
     printf(" | ");
    }
    if ((loops % 40) == 0) {
     time(&current);
     strftime(clk,38,"%H.%M | %A, %d %B %Y",localtime(&current));
     printf("%s \n",clk);
    }
    fflush(stdout);
    sleep(1);
   }
   return 0;
}


vectSetValue

repo: HammurabiCode/Simulation

decompiled_code:
void __fastcall vectSetValue(float *a1, float a2, float a3, float a4)
{
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
}

canonical_decompiled_code:
void __fastcall func1(float *a1, float a2, float a3, float a4)
{
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
}

original_code:
static inline void vectSetValue(vect v, float x, float y, float z)
{
  v[0] = x; v[1] = y; v[2] = z;
}

canonical_original_code:
static inline void vectSetValue(float v[3], float x, float y, float z)
{
  v[0] = x; v[1] = y; v[2] = z;
}

variable_types:
v
float [3]

variable_types: x float

variable_types: y float

variable_types: z float


povFree

original_code:
static
void povFree(pov *p) {
 if (p->num_light != 0) {
  free(p->lights);
 }
 if (p->num_include != 0) {
  for (unsigned i = 0; i< p->num_include; i++) {
   free(p->include[i]);
  }
  free(p->include);
 }
}

canonical_original_code:
static void povFree(struct pov *p) {
 if (p->num_light != 0) {
  free(p->lights);
 }
 if (p->num_include != 0) {
  for (unsigned int i = 0; i< p->num_include; i++) {
   free(p->include[i]);
  }
  free(p->include);
 }
}

variable_types: struct pov { struct pov_camera { float location[3]; float lookAt[3]; } camera; struct pov_light { float location[3]; char color[8]; } *lights; unsigned int num_light; char **include; unsigned int num_include; struct Demon { float time_step; unsigned int num; struct Particle { unsigned int index; unsigned int granIndex; float radius; float position[3]; float velocity[3]; float force[3]; } *ptrPartPool; struct Granular { unsigned int index; unsigned int iStart; float mass; float density; float position[3]; float velocity[3]; float acceleration[3]; float angularVelocity[3]; float angularMomentum[3]; unsigned int num; struct Particle *component; float (*offset)[3]; float inertiaInv[3][3]; float quaternion[4]; } *sand; float max_radius; struct HashTable { struct HashGrid { unsigned int num; unsigned int capacity; unsigned int *content; } *content; unsigned int table_size; float min_pos[3]; float cell_length; } sand_ht; float vDisplayOffset[3]; } *dem_scene; } *

variable_types:
i
unsigned int

user_defined_types: struct pov { struct pov_camera camera; struct pov_light *lights; unsigned int num_light; char **include; unsigned int num_include; struct Demon *dem_scene; }

user_defined_types: struct Demon { float time_step; unsigned int num; struct Particle *ptrPartPool; struct Granular *sand; float max_radius; struct HashTable sand_ht; float vDisplayOffset[3]; }

user_defined_types: struct HashTable { struct HashGrid *content; unsigned int table_size; float min_pos[3]; float cell_length; }


vectGetLength

decompiled_code:
void __fastcall vectGetLength(float *a1)
{
float v1; // xmm0_4

v1 = (float)((float)(a1[1] * a1[1]) + (float)(*a1 * *a1)) + (float)(a1[2] * a1[2]);
if ( v1 < 0.0 )
sqrtf(v1);
}

original_code:
static inline float vectGetLength(const vect v)
{
  return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
}

canonical_original_code:
static inline float vectGetLength(float v[3])
{
  return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
}

return_type: float


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
unsigned int v4; // er12
char *v5; // r13
unsigned int v6; // ebx
__int64 v7; // rsi
float v9[3]; // [rsp+18h] [rbp-1F0h] BYREF
float v10[3]; // [rsp+24h] [rbp-1E4h] BYREF
__m128i v11[2]; // [rsp+30h] [rbp-1D8h] BYREF
float v12[3]; // [rsp+50h] [rbp-1B8h] BYREF
float v13[11]; // [rsp+5Ch] [rbp-1ACh] BYREF
int *v14; // [rsp+88h] [rbp-180h]
int v15[4]; // [rsp+90h] [rbp-178h] BYREF
__int64 v16; // [rsp+A0h] [rbp-168h]
char s[296]; // [rsp+E0h] [rbp-128h] BYREF

vectSetZero((__int64)v9);
vectGetLength(v9);
printf("%f\n", v3);
if ( (float)abs((int)"%f\n") > 0.0 )
puts("aaa");
v4 = 0;
v5 = (char *)malloc(0x400uLL);
vectSetValue(v10, 1.0, 1.0, 1.0);
v13[5] = 0.0;
v13[9] = 0.0;
vectSetValue(v12, 0.0, 15.0, 5.0);
vectSetValue(v13, 0.0, 0.0, 0.0);
vectSetValue((float *)v11, 20.0, 0.0, 20.0);
lightSetColor_constprop_0((__int64)v11);
povAddLight((__int64)v12, v11);
vectSetValue((float *)v11, -20.0, 0.0, 20.0);
lightSetColor_constprop_0((__int64)v11);
povAddLight((__int64)v12, v11);
vectSetValue((float *)v11, 0.0, -20.0, 20.0);
lightSetColor_constprop_0((__int64)v11);
povAddLight((__int64)v12, v11);
vectSetValue((float *)v11, 0.0, 20.0, 20.0);
lightSetColor_constprop_0((__int64)v11);
povAddLight((__int64)v12, v11);
povAddInclude_constprop_0((__int64)v12);
InitDemonGranOneNor(v15);
v14 = v15;
v6 = (int)(0.04 / *(float *)v15);
sprintf(s, "mkdir out/%s", "gran-one-nor");
system(s);
sprintf(s, "mkdir out/%s/pov", "gran-one-nor");
system(s);
sprintf(s, "rm out/%s/pov/*.pov", "gran-one-nor");
system(s);
do
{
if ( !(v4 % v6) )
{
sprintf(v5, "out/%s/pov/%03u.pov", "gran-one-nor", v4 / v6);
if ( !(unsigned int)povSave((__int64)v12, v5) )
{
printf("Can't open file: %s\n", v5);
return -1;
}
}
v7 = v4++;
printf("%04u:", v7);
GranularPrint(v16);
ComputeForce(v15);
TimeIntergration(v15);
}
while ( v4 != 9000 );
FreeDemon(v15);
free(v5);
povFree((__int64)v12);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
unsigned int v4; // er12
char *v5; // r13
unsigned int v6; // ebx
__int64 v7; // rsi
float v9[3]; // [rsp+18h] [rbp-1F0h] BYREF
float v10[3]; // [rsp+24h] [rbp-1E4h] BYREF
__m128i v11[2]; // [rsp+30h] [rbp-1D8h] BYREF
float v12[3]; // [rsp+50h] [rbp-1B8h] BYREF
float v13[11]; // [rsp+5Ch] [rbp-1ACh] BYREF
int *v14; // [rsp+88h] [rbp-180h]
int v15[4]; // [rsp+90h] [rbp-178h] BYREF
__int64 v16; // [rsp+A0h] [rbp-168h]
char s[296]; // [rsp+E0h] [rbp-128h] BYREF

func0((__int64)v9);
func3(v9);
printf("%f\n", v3);
if ( (float)abs((int)"%f\n") > 0.0 )
puts("aaa");
v4 = 0;
v5 = (char *)malloc(0x400uLL);
func1(v10, 1.0, 1.0, 1.0);
v13[5] = 0.0;
v13[9] = 0.0;
func1(v12, 0.0, 15.0, 5.0);
func1(v13, 0.0, 0.0, 0.0);
func1((float *)v11, 20.0, 0.0, 20.0);
func9((__int64)v11);
povAddLight((__int64)v12, v11);
func1((float *)v11, -20.0, 0.0, 20.0);
func9((__int64)v11);
povAddLight((__int64)v12, v11);
func1((float *)v11, 0.0, -20.0, 20.0);
func9((__int64)v11);
povAddLight((__int64)v12, v11);
func1((float *)v11, 0.0, 20.0, 20.0);
func9((__int64)v11);
povAddLight((__int64)v12, v11);
func8((__int64)v12);
InitDemonGranOneNor(v15);
v14 = v15;
v6 = (int)(0.04 / *(float *)v15);
sprintf(s, "mkdir out/%s", "gran-one-nor");
system(s);
sprintf(s, "mkdir out/%s/pov", "gran-one-nor");
system(s);
sprintf(s, "rm out/%s/pov/*.pov", "gran-one-nor");
system(s);
do
{
if ( !(v4 % v6) )
{
sprintf(v5, "out/%s/pov/%03u.pov", "gran-one-nor", v4 / v6);
if ( !(unsigned int)func7((__int64)v12, v5) )
{
printf("Can't open file: %s\n", v5);
return -1;
}
}
v7 = v4++;
printf("%04u:", v7);
GranularPrint(v16);
ComputeForce(v15);
TimeIntergration(v15);
}
while ( v4 != 9000 );
FreeDemon(v15);
free(v5);
func2((__int64)v12);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  vect zero;
  vectSetZero(zero);
  float a = vectGetLength(zero);
  printf("%f\n", abs((int)(a)));
  if (abs(a) > 0.0f) printf("aaa\n");
 char *strFileName = (char*) malloc(sizeof(char)*1024);
 Demon d1;
  vect or;
  vectSetValue(or, 1.0, 1.0, 1.0);
 pov pov1;
  pov1.num_light = 0;
  pov1.num_include= 0;
 vectSetValue(&(pov1.camera.location), 0, 15, 5);
 vectSetValue(&(pov1.camera.lookAt), 0, 0, 0);
 pov_light light1;
 vectSetValue(&(light1.location), 20, 0, 20);
 lightSetColor(&light1, "White");
 povAddLight(&pov1, &light1);
 vectSetValue(&(light1.location), -20, 0, 20);
 lightSetColor(&light1, "White");
 povAddLight(&pov1, &light1);
 vectSetValue(&(light1.location), 0, -20, 20);
 lightSetColor(&light1, "White");
 povAddLight(&pov1, &light1);
 vectSetValue(&(light1.location), 0, 20, 20);
 lightSetColor(&light1, "White");
 povAddLight(&pov1, &light1);
 povAddInclude(&pov1, "colors");
  unsigned iCurDemon = INIT_GRAN_ONE_NOR;
  {
    (initList[iCurDemon])(&d1);
    pov1.dem_scene = &d1;
    unsigned output_rate = (unsigned)(1.0/25.0/d1.time_step);
    char cmd[256];
    sprintf(cmd, "mkdir out/%s", filenameList[iCurDemon]);
    system(cmd);
    sprintf(cmd, "mkdir out/%s/pov", filenameList[iCurDemon]);
    system(cmd);
    sprintf(cmd, "rm out/%s/pov/*.pov", filenameList[iCurDemon]);
    system(cmd);
    for (unsigned iFrame = 0; iFrame < 9000; iFrame ++) {
      if (iFrame % output_rate == 0) {
        sprintf(strFileName, "out/%s/pov/%03u.pov", filenameList[iCurDemon], iFrame/output_rate);
        if( 0 == povSave(&pov1, strFileName)) {
          printf("Can't open file: %s\n", strFileName);
          return -1;
        }
      }
      printf("%04u:", iFrame);
      GranularPrint(d1.sand);
      ComputeForce(&d1);
      TimeIntergration(&d1);
    }
    FreeDemon(&d1);
  }
  free(strFileName);
 povFree(&pov1);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  float zero[3];
  vectSetZero(zero);
  float a = vectGetLength(zero);
  printf("%f\n", abs((int)(a)));
  if (abs(a) > 0.0f) printf("aaa\n");
 char *strFileName = (char*) malloc(sizeof(char)*1024);
 struct Demon d1;
  float or[3];
  vectSetValue(or, 1.0, 1.0, 1.0);
 struct pov pov1;
  pov1.num_light = 0;
  pov1.num_include= 0;
 vectSetValue(&(pov1.camera.location), 0, 15, 5);
 vectSetValue(&(pov1.camera.lookAt), 0, 0, 0);
 struct pov_light light1;
 vectSetValue(&(light1.location), 20, 0, 20);
 lightSetColor(&light1, "White");
 povAddLight(&pov1, &light1);
 vectSetValue(&(light1.location), -20, 0, 20);
 lightSetColor(&light1, "White");
 povAddLight(&pov1, &light1);
 vectSetValue(&(light1.location), 0, -20, 20);
 lightSetColor(&light1, "White");
 povAddLight(&pov1, &light1);
 vectSetValue(&(light1.location), 0, 20, 20);
 lightSetColor(&light1, "White");
 povAddLight(&pov1, &light1);
 povAddInclude(&pov1, "colors");
  unsigned int iCurDemon = INIT_GRAN_ONE_NOR;
  {
    (initList[iCurDemon])(&d1);
    pov1.dem_scene = &d1;
    unsigned int output_rate = (unsigned)(1.0/25.0/d1.time_step);
    char cmd[256];
    sprintf(cmd, "mkdir out/%s", filenameList[iCurDemon]);
    system(cmd);
    sprintf(cmd, "mkdir out/%s/pov", filenameList[iCurDemon]);
    system(cmd);
    sprintf(cmd, "rm out/%s/pov/*.pov", filenameList[iCurDemon]);
    system(cmd);
    for (unsigned int iFrame = 0; iFrame < 9000; iFrame ++) {
      if (iFrame % output_rate == 0) {
        sprintf(strFileName, "out/%s/pov/%03u.pov", filenameList[iCurDemon], iFrame/output_rate);
        if( 0 == povSave(&pov1, strFileName)) {
          printf("Can't open file: %s\n", strFileName);
          return -1;
        }
      }
      printf("%04u:", iFrame);
      GranularPrint(d1.sand);
      ComputeForce(&d1);
      TimeIntergration(&d1);
    }
    FreeDemon(&d1);
  }
  free(strFileName);
 povFree(&pov1);
  return 0;
}

variable_types:
argv
char *[]

variable_types:
zero
float [3]

variable_types: a float

variable_types:
strFileName
char *

variable_types:
or
float [3]

variable_types: struct pov { struct pov_camera { float location[3]; float lookAt[3]; } camera; struct pov_light { float location[3]; char color[8]; } *lights; unsigned int num_light; char **include; unsigned int num_include; struct Demon { float time_step; unsigned int num; struct Particle { unsigned int index; unsigned int granIndex; float radius; float position[3]; float velocity[3]; float force[3]; } *ptrPartPool; struct Granular { unsigned int index; unsigned int iStart; float mass; float density; float position[3]; float velocity[3]; float acceleration[3]; float angularVelocity[3]; float angularMomentum[3]; unsigned int num; struct Particle *component; float (*offset)[3]; float inertiaInv[3][3]; float quaternion[4]; } *sand; float max_radius; struct HashTable { struct HashGrid { unsigned int num; unsigned int capacity; unsigned int *content; } *content; unsigned int table_size; float min_pos[3]; float cell_length; } sand_ht; float vDisplayOffset[3]; } *dem_scene; }

variable_types:
iCurDemon
unsigned int

variable_types:
cmd
char [256]

variable_types:
iFrame
unsigned int


PopBGJob

original_code:
bgjobL* PopBGJob(int n) {
    bgjobL *p= bgjobs->next, *pre = bgjobs;
    while(p->next!=((void *)0)){
  if(p->job_id == n)
   break;
        p= p->next;
        pre= pre->next;
    }
 if(p->job_id != n)
  return 0;
    pre->next = p->next;
    return p;
}

canonical_original_code:
struct bgjob_l *PopBGJob(int n) {
    struct bgjob_l *p = bgjobs->next; struct bgjob_l *pre = bgjobs;
    while(p->next!=((void *)0)){
  if(p->job_id == n)
   break;
        p= p->next;
        pre= pre->next;
    }
 if(p->job_id != n)
  return 0;
    pre->next = p->next;
    return p;
}

variable_types: n int

variable_types: struct bgjob_l { int pid; enum status { RUNNING=0, STOPPED=1, DONE=2 } state; int job_id; char *cmd; struct bgjob_l *next; } *

user_defined_types: struct bgjob_l { int pid; enum status state; int job_id; char *cmd; struct bgjob_l *next; }


IsBuiltIn

original_code:
static short IsBuiltIn(char* cmd)
{
    if (strcmp(cmd, "bg") == 0) return 1;
    if (strcmp(cmd, "fg") == 0) return 1;
    if (strcmp(cmd, "jobs") == 0) return 1;
    if (strcmp(cmd, "cd") == 0) return 1;
    return 0;
}

canonical_original_code:
static short IsBuiltIn(char *cmd)
{
    if (strcmp(cmd, "bg") == 0) return 1;
    if (strcmp(cmd, "fg") == 0) return 1;
    if (strcmp(cmd, "jobs") == 0) return 1;
    if (strcmp(cmd, "cd") == 0) return 1;
    return 0;
}

variable_types:
cmd
char *

return_type: short


ResolveExternalCmd

original_code:
static short ResolveExternalCmd(commandT* cmd)
{
    char *pathlist, *c;
    char buf[1024];
    int i, j;
    struct stat fs;
    if(strchr(cmd->argv[0],'/') != ((void *)0)){
        if(stat(cmd->argv[0], &fs) >= 0){
            if(((((fs.st_mode)) & 0170000) == (0040000)) == 0)
                if(access(cmd->argv[0],1) == 0){
                    cmd->name = strdup(cmd->argv[0]);
                    return 1;
                }
        }
        return 0;
    }
    pathlist = getenv("PATH");
    if(pathlist == ((void *)0)) return 0;
    i = 0;
    while(i<strlen(pathlist)){
        c = strchr(&(pathlist[i]),':');
        if(c != ((void *)0)){
            for(j = 0; c != &(pathlist[i]); i++, j++)
                buf[j] = pathlist[i];
            i++;
        }
        else{
            for(j = 0; i < strlen(pathlist); i++, j++)
                buf[j] = pathlist[i];
        }
        buf[j] = '\0';
        strcat(buf, "/");
        strcat(buf,cmd->argv[0]);
        if(stat(buf, &fs) >= 0){
            if(((((fs.st_mode)) & 0170000) == (0040000)) == 0)
                if(access(buf,1) == 0){
                    cmd->name = strdup(buf);
                    return 1;
                }
        }
    }
    return 0;
}

canonical_original_code:
static short ResolveExternalCmd(struct command_t *cmd)
{
    char *pathlist; char *c;
    char buf[1024];
    int i; int j;
    struct stat fs;
    if(strchr(cmd->argv[0],'/') != ((void *)0)){
        if(stat(cmd->argv[0], &fs) >= 0){
            if(((((fs.st_mode)) & 0170000) == (0040000)) == 0)
                if(access(cmd->argv[0],1) == 0){
                    cmd->name = strdup(cmd->argv[0]);
                    return 1;
                }
        }
        return 0;
    }
    pathlist = getenv("PATH");
    if(pathlist == ((void *)0)) return 0;
    i = 0;
    while(i<strlen(pathlist)){
        c = strchr(&(pathlist[i]),':');
        if(c != ((void *)0)){
            for(j = 0; c != &(pathlist[i]); i++, j++)
                buf[j] = pathlist[i];
            i++;
        }
        else{
            for(j = 0; i < strlen(pathlist); i++, j++)
                buf[j] = pathlist[i];
        }
        buf[j] = '\0';
        strcat(buf, "/");
        strcat(buf,cmd->argv[0]);
        if(stat(buf, &fs) >= 0){
            if(((((fs.st_mode)) & 0170000) == (0040000)) == 0)
                if(access(buf,1) == 0){
                    cmd->name = strdup(buf);
                    return 1;
                }
        }
    }
    return 0;
}

variable_types: struct command_t { char *name; char *cmdline; char *redirect_in; int is_redirect_in; int bg; int argc; char *argv[]; } *

variable_types:
pathlist
char *

variable_types:
c
char *

variable_types:
buf
char [1024]

variable_types: i int

variable_types: j int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


RunBuiltInCmd

original_code:
static void RunBuiltInCmd(commandT* cmd)
{
    if (strcmp(cmd -> argv[0], "bg") == 0) {
        if(bgjobs == ((void *)0) || bgjobs->next==((void *)0))
            return;
        int job_num = 0;
        if (cmd -> argc == 1) {
            bgjobL *p = bgjobs->next;
            while(p->next!=((void *)0)){
                p = p->next;
            }
   job_num = p->job_id;
        } else {
            job_num = atoi(cmd -> argv[1]);
        }
        bgjobL *p = bgjobs;
  while(p->next !=((void *)0)){
   if(p->job_id == job_num) {
    p->state = STOPPED;
    break;
   }
   p = p->next;
  }
  if(p->job_id!=job_num){
   printf("job not found[bg]\n");
   fflush(stdout);
   return;
  }
        kill(p->pid, 18);
  p->state = RUNNING;
        return;
    }
    if (strcmp(cmd -> argv[0], "fg") == 0) {
        int job_num = 0;
        if(bgjobs == ((void *)0) || bgjobs->next==((void *)0))
            return;
        if (cmd -> argc == 1){
            bgjobL *p = bgjobs->next;
            while(p->next!=((void *)0)){
                p = p->next;
            }
   job_num = p->job_id;
        } else job_num = atoi(cmd->argv[1]);
  bgjobL *proc;
  if (( proc = PopBGJob( job_num)) == 0)
            return;
        fg_job = proc->pid;
  fgCmd = proc->cmd;
  free(proc);
        kill(-fg_job, 18);
  waitfg(fg_job);
  return;
    }
    if (strcmp(cmd -> cmdline, "jobs") == 0) {
        if(bgjobs == ((void *)0) || bgjobs->next==((void *)0))
            return;
        else {
            bgjobL * p= bgjobs->next;
            while(1){
                if(p->state == RUNNING){
                    if(p->cmd[strlen(p->cmd)-1]==' ')
      printf("[%d]   %s                 %s&\n",p->job_id, "Running",p->cmd);
     else
      printf("[%d]   %s                 %s &\n",p->job_id, "Running",p->cmd);
    }
                else if(p->state == STOPPED)
                    printf("[%d]   %s                 %s\n",p->job_id, "Stopped",p->cmd);
                else if(p->state ==DONE)
     printf("[%d]   %s                    %s\n",p->job_id, "Done",p->cmd);
                fflush(stdout);
                if(p->next==((void *)0))
                    break;
                p=p->next;
            }
        }
        return;
    }
 if (strcmp(cmd -> argv[0], "cd") == 0) {
  int rc;
  if(cmd->argc == 1) {
   struct passwd *pw = getpwuid(getuid());
   const char *homedir = pw->pw_dir;
   rc = chdir(homedir);
  } else {
   rc = chdir(cmd->argv[1]);
  }
  if(rc < 0){
   fprintf(stderr,"cd error\n");
  }
  return;
 }
}

canonical_original_code:
static void RunBuiltInCmd(struct command_t *cmd)
{
    if (strcmp(cmd -> argv[0], "bg") == 0) {
        if(bgjobs == ((void *)0) || bgjobs->next==((void *)0))
            return;
        int job_num = 0;
        if (cmd -> argc == 1) {
            struct bgjob_l *p = bgjobs->next;
            while(p->next!=((void *)0)){
                p = p->next;
            }
   job_num = p->job_id;
        } else {
            job_num = atoi(cmd -> argv[1]);
        }
        struct bgjob_l *p = bgjobs;
  while(p->next !=((void *)0)){
   if(p->job_id == job_num) {
    p->state = STOPPED;
    break;
   }
   p = p->next;
  }
  if(p->job_id!=job_num){
   printf("job not found[bg]\n");
   fflush(stdout);
   return;
  }
        kill(p->pid, 18);
  p->state = RUNNING;
        return;
    }
    if (strcmp(cmd -> argv[0], "fg") == 0) {
        int job_num = 0;
        if(bgjobs == ((void *)0) || bgjobs->next==((void *)0))
            return;
        if (cmd -> argc == 1){
            struct bgjob_l *p = bgjobs->next;
            while(p->next!=((void *)0)){
                p = p->next;
            }
   job_num = p->job_id;
        } else job_num = atoi(cmd->argv[1]);
  struct bgjob_l *proc;
  if (( proc = PopBGJob( job_num)) == 0)
            return;
        fg_job = proc->pid;
  fgCmd = proc->cmd;
  free(proc);
        kill(-fg_job, 18);
  waitfg(fg_job);
  return;
    }
    if (strcmp(cmd -> cmdline, "jobs") == 0) {
        if(bgjobs == ((void *)0) || bgjobs->next==((void *)0))
            return;
        else {
            struct bgjob_l *p = bgjobs->next;
            while(1){
                if(p->state == RUNNING){
                    if(p->cmd[strlen(p->cmd)-1]==' ')
      printf("[%d]   %s                 %s&\n",p->job_id, "Running",p->cmd);
     else
      printf("[%d]   %s                 %s &\n",p->job_id, "Running",p->cmd);
    }
                else if(p->state == STOPPED)
                    printf("[%d]   %s                 %s\n",p->job_id, "Stopped",p->cmd);
                else if(p->state ==DONE)
     printf("[%d]   %s                    %s\n",p->job_id, "Done",p->cmd);
                fflush(stdout);
                if(p->next==((void *)0))
                    break;
                p=p->next;
            }
        }
        return;
    }
 if (strcmp(cmd -> argv[0], "cd") == 0) {
  int rc;
  if(cmd->argc == 1) {
   struct passwd *pw = getpwuid(getuid());
   char *homedir = pw->pw_dir;
   rc = chdir(homedir);
  } else {
   rc = chdir(cmd->argv[1]);
  }
  if(rc < 0){
   fprintf(stderr,"cd error\n");
  }
  return;
 }
}

variable_types: rc int

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:
homedir
char *

user_defined_types: struct command_t { char *name; char *cmdline; char *redirect_in; int is_redirect_in; int bg; int argc; char *argv[]; }

user_defined_types: enum status { RUNNING=0, STOPPED=1, DONE=2 }


RunCmdBg

decompiled_code:
void RunCmdBg()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void RunCmdBg(commandT* cmd)
{
}

canonical_original_code:
void RunCmdBg(struct command_t *cmd)
{
}


RunCmdPipe

decompiled_code:
__pid_t __fastcall RunCmdPipe(const char ***a1, int a2)
{
__int64 *v2; // rbx
__pid_t result; // eax
__pid_t v4; // ebx
int v5; // [rsp+0h] [rbp-28h] BYREF
int fd; // [rsp+4h] [rbp-24h]
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( a2 <= 0 )
{
LABEL_6:
pipe(&v5);
pipe(pipedes);
v4 = fork();
close(pipedes[0]);
close(pipedes[1]);
if ( !v4 )
{
close(v5);
dup2(fd, 1);
execv(**a1, (char *const *)*a1 + 6);
}
close(fd);
wait(0LL);
if ( !fork() )
{
close(pipedes[0]);
dup2(v5, 0);
dup2(pipedes[1], 1);
execv(*a1[1], (char *const *)a1[1] + 6);
}
close(v5);
close(pipedes[1]);
if ( !fork() )
{
dup2(pipedes[0], 0);
execv(*a1[2], (char *const *)a1[2] + 6);
}
close(pipedes[0]);
wait(0LL);
result = wait(0LL);
}
else
{
v2 = (__int64 *)a1;
while ( (unsigned __int16)ResolveExternalCmd(*v2) )
{
if ( ++v2 == (__int64 *)&a1[(unsigned int)(a2 - 1) + 1] )
goto LABEL_6;
}
result = printf("%s command not found\n", *(const char **)(*v2 + 48));
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func6(const char ***a1, int a2)
{
__int64 *v2; // rbx
__pid_t result; // eax
__pid_t v4; // ebx
int v5; // [rsp+0h] [rbp-28h] BYREF
int fd; // [rsp+4h] [rbp-24h]
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( a2 <= 0 )
{
LABEL_6:
pipe(&v5);
pipe(pipedes);
v4 = fork();
close(pipedes[0]);
close(pipedes[1]);
if ( !v4 )
{
close(v5);
dup2(fd, 1);
execv(**a1, (char *const *)*a1 + 6);
}
close(fd);
wait(0LL);
if ( !fork() )
{
close(pipedes[0]);
dup2(v5, 0);
dup2(pipedes[1], 1);
execv(*a1[1], (char *const *)a1[1] + 6);
}
close(v5);
close(pipedes[1]);
if ( !fork() )
{
dup2(pipedes[0], 0);
execv(*a1[2], (char *const *)a1[2] + 6);
}
close(pipedes[0]);
wait(0LL);
result = wait(0LL);
}
else
{
v2 = (__int64 *)a1;
while ( (unsigned __int16)func2(*v2) )
{
if ( ++v2 == (__int64 *)&a1[(unsigned int)(a2 - 1) + 1] )
goto LABEL_6;
}
result = printf("%s command not found\n", *(const char **)(*v2 + 48));
}
return result;
}

original_code:
void RunCmdPipe(commandT** cmd, int n )
{
    int k = 0;
    for(k=0;k<n;k++){
        if(!ResolveExternalCmd(cmd[k])){
            printf("%s command not found\n", cmd[k]->argv[0]);
            return;
        }
    }
    int A_B[2], B_C[2];
    pipe(A_B);
    pipe(B_C);
    int pid;
    pid = fork();
    close(B_C[0]);
    close(B_C[1]);
    if (pid == 0) {
        close(A_B[0]);
        dup2(A_B[1], 1);
        execv(cmd[0] -> name, cmd[0] -> argv);
    }
    close(A_B[1]);
    wait(((void *)0));
    pid = fork();
    if (pid == 0) {
        close(B_C[0]);
        dup2(A_B[0], 0);
        dup2(B_C[1], 1);
        execv(cmd[1] -> name, cmd[1] -> argv);
    }
    close(A_B[0]);
    close(B_C[1]);
    pid = fork();
    if (pid == 0) {
        dup2(B_C[0], 0);
        execv(cmd[2] -> name, cmd[2]-> argv);
    }
    close(B_C[0]);
    wait(((void *)0));
    wait(((void *)0));
}

canonical_original_code:
void RunCmdPipe(struct command_t **cmd, int n)
{
    int k = 0;
    for(k=0;k<n;k++){
        if(!ResolveExternalCmd(cmd[k])){
            printf("%s command not found\n", cmd[k]->argv[0]);
            return;
        }
    }
    int A_B[2]; int B_C[2];
    pipe(A_B);
    pipe(B_C);
    int pid;
    pid = fork();
    close(B_C[0]);
    close(B_C[1]);
    if (pid == 0) {
        close(A_B[0]);
        dup2(A_B[1], 1);
        execv(cmd[0] -> name, cmd[0] -> argv);
    }
    close(A_B[1]);
    wait(((void *)0));
    pid = fork();
    if (pid == 0) {
        close(B_C[0]);
        dup2(A_B[0], 0);
        dup2(B_C[1], 1);
        execv(cmd[1] -> name, cmd[1] -> argv);
    }
    close(A_B[0]);
    close(B_C[1]);
    pid = fork();
    if (pid == 0) {
        dup2(B_C[0], 0);
        execv(cmd[2] -> name, cmd[2]-> argv);
    }
    close(B_C[0]);
    wait(((void *)0));
    wait(((void *)0));
}

variable_types: struct command_t { char *name; char *cmdline; char *redirect_in; int is_redirect_in; int bg; int argc; char *argv[]; } **

variable_types: k int

variable_types: pid int


RunCmdRedirOut

decompiled_code:
void RunCmdRedirOut()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void RunCmdRedirOut(commandT* cmd, char* file)
{
}

canonical_original_code:
void RunCmdRedirOut(struct command_t *cmd, char *file)
{
}

variable_types:
file
char *


RunCmdRedirIn

decompiled_code:
void RunCmdRedirIn()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void RunCmdRedirIn(commandT* cmd, char* file)
{
}

canonical_original_code:
void RunCmdRedirIn(struct command_t *cmd, char *file)
{
}


AddToBgJobs

decompiled_code:
__int64 __fastcall AddToBgJobs(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdx
int v3; // eax
__int64 result; // rax
_QWORD *v5; // rax

v1 = bgjobs;
if ( bgjobs )
{
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
v3 = *(_DWORD *)(v2 + 8);
*(_QWORD *)(v2 + 24) = a1;
result = (unsigned int)(v3 + 1);
*(_DWORD *)(a1 + 8) = result;
}
else
{
v5 = malloc(0x20uLL);
*(_DWORD *)(a1 + 8) = 1;
v5[3] = a1;
bgjobs = (__int64)v5;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdx
int v3; // eax
__int64 result; // rax
_QWORD *v5; // rax

v1 = bgjobs;
if ( bgjobs )
{
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
v3 = *(_DWORD *)(v2 + 8);
*(_QWORD *)(v2 + 24) = a1;
result = (unsigned int)(v3 + 1);
*(_DWORD *)(a1 + 8) = result;
}
else
{
v5 = malloc(0x20uLL);
*(_DWORD *)(a1 + 8) = 1;
v5[3] = a1;
bgjobs = (__int64)v5;
result = 1LL;
}
return result;
}

original_code:
int AddToBgJobs(bgjobL *p){
    if(bgjobs==((void *)0)){
        bgjobs = malloc(sizeof(bgjobL));
        bgjobs->next = p;
        p->job_id = 1;
  return 1;
    }
    int num = 0;
    bgjobL *pt = bgjobs;
    while(pt->next !=((void *)0)){
        pt=pt->next;
        num++;
    }
    pt->next = p;
 p->job_id = pt->job_id + 1;
    return p->job_id;
}

canonical_original_code:
int AddToBgJobs(struct bgjob_l *p){
    if(bgjobs==((void *)0)){
        bgjobs = malloc(sizeof(bgjobL));
        bgjobs->next = p;
        p->job_id = 1;
  return 1;
    }
    int num = 0;
    struct bgjob_l *pt = bgjobs;
    while(pt->next !=((void *)0)){
        pt=pt->next;
        num++;
    }
    pt->next = p;
 p->job_id = pt->job_id + 1;
    return p->job_id;
}

variable_types: num int


Exec

decompiled_code:
void __fastcall Exec(__int64 a1, __int16 a2)
{
__pid_t v2; // eax
__pid_t v3; // ebp
const char *v4; // rbp
int v5; // eax
int v6; // er12
int v7; // er13
int v8; // ebp
int v9; // er14
int v10; // eax
_DWORD *v11; // rax
const char *v12; // rbp
__int64 v13; // r12
size_t v14; // rbx
void *v15; // rax
void *v16; // rax
int v17; // eax
const char *v18; // rdx

if ( !a2 )
return;
v2 = fork();
v3 = v2;
if ( v2 < 0 )
{
fwrite("fork() failed at Exec().\n", 1uLL, 0x19uLL, stderr);
return;
}
if ( !v2 )
{
v6 = -1;
v7 = -1;
setpgid(0, 0);
if ( *(_DWORD *)(a1 + 36) )
{
v7 = dup(1);
v17 = open(*(const char **)(a1 + 24), 66, 420LL);
v6 = v17;
if ( v17 == -1 )
{
v18 = *(const char **)(a1 + 24);
goto LABEL_23;
}
dup2(v17, 1);
}
if ( !*(_DWORD *)(a1 + 32) )
{
v8 = -1;
v9 = -1;
goto LABEL_11;
}
v9 = dup(0);
v10 = open(*(const char **)(a1 + 16), 0, 420LL);
v8 = v10;
if ( v10 != -1 )
{
dup2(v10, 0);
LABEL_11:
execv(*(const char **)a1, (char *const *)(a1 + 48));
if ( *(_DWORD *)(a1 + 36) )
{
dup2(v7, 1);
close(v6);
close(v7);
}
if ( *(_DWORD *)(a1 + 32) )
{
dup2(v9, 0);
close(v8);
close(v9);
}
fflush(stdout);
exit(0);
}
v18 = *(const char **)(a1 + 16);
LABEL_23:
fprintf(stderr, "create file %s failed\n.", v18);
return;
}
if ( *(_DWORD *)(a1 + 40) == 1 )
{
v11 = malloc(0x20uLL);
*v11 = v3;
v12 = *(const char **)(a1 + 8);
v13 = (__int64)v11;
v11[1] = 0;
v14 = strlen(v12);
v15 = malloc((int)v14 + 1);
v16 = memcpy(v15, v12, v14 + 1);
*(_QWORD *)(v13 + 24) = 0LL;
*(_QWORD *)(v13 + 16) = v16;
AddToBgJobs(v13);
}
else
{
fg_job = v2;
if ( fgCmd )
free(fgCmd);
v4 = *(const char **)(a1 + 8);
v5 = strlen(v4);
fgCmd = malloc(v5 + 1);
strcpy((char *)fgCmd, v4);
waitfg_constprop_0();
}
}

original_code:
static void Exec(commandT* cmd, short forceFork)
{
    if(forceFork){
        pid_t pid = fork();
        if(pid<0){
            fprintf(stderr,"fork() failed at Exec().\n");
            return;
        }
        if(pid ==0){
            setpgid(0, 0);
            int defout=-1;
            int fd= -1;
            if(cmd->is_redirect_out){
                defout = dup(1);
                fd=open(cmd->redirect_out, 02|0100,
                        0400 | 0200 | (0400 >> 3) | ((0400 >> 3) >> 3));
                if(fd == -1){
                    fprintf(stderr,"create file %s failed\n.",cmd->redirect_out);
                    return;
                }
                dup2(fd, 1);
            }
            int defin = -1;
            int fd_in = -1;
            if(cmd->is_redirect_in){
                defin = dup(0);
                fd_in = open(cmd->redirect_in, 00,0400 | 0200 | (0400 >> 3) | ((0400 >> 3) >> 3));
                if(fd_in == -1){
                    fprintf(stderr,"create file %s failed\n.",cmd->redirect_in);
                    return;
                }
                dup2(fd_in,0);
            }
            execv(cmd->name,cmd->argv);
            if(cmd->is_redirect_out){
                dup2(defout, 1);
                close(fd);
                close(defout);
            }
            if(cmd->is_redirect_in){
                dup2(defin,0);
                close(fd_in);
                close(defin);
            }
            fflush(stdout);
            exit(0);
        }else {
            if (cmd -> bg == 1) {
                bgjobL *bgjob = (bgjobL*) malloc (sizeof(bgjobL));
                bgjob -> pid = pid;
                bgjob -> state = RUNNING;
                int size = strlen(cmd->cmdline);
                char * pa = malloc(size+1);
                strcpy(pa, cmd->cmdline);
                bgjob -> cmd = pa;
                bgjob -> next = ((void *)0);
                AddToBgJobs(bgjob);
            } else {
                fg_job = pid;
                if(fgCmd!=((void *)0))
                    free(fgCmd);
                int size = strlen (cmd->cmdline);
                fgCmd = malloc(size+1);
                strcpy(fgCmd, cmd->cmdline);
                waitfg(pid);
            }
        }
    }
}

canonical_original_code:
static void Exec(struct command_t *cmd, short forceFork)
{
    if(forceFork){
        int pid = fork();
        if(pid<0){
            fprintf(stderr,"fork() failed at Exec().\n");
            return;
        }
        if(pid ==0){
            setpgid(0, 0);
            int defout = -1;
            int fd = -1;
            if(cmd->is_redirect_out){
                defout = dup(1);
                fd=open(cmd->redirect_out, 02|0100,
                        0400 | 0200 | (0400 >> 3) | ((0400 >> 3) >> 3));
                if(fd == -1){
                    fprintf(stderr,"create file %s failed\n.",cmd->redirect_out);
                    return;
                }
                dup2(fd, 1);
            }
            int defin = -1;
            int fd_in = -1;
            if(cmd->is_redirect_in){
                defin = dup(0);
                fd_in = open(cmd->redirect_in, 00,0400 | 0200 | (0400 >> 3) | ((0400 >> 3) >> 3));
                if(fd_in == -1){
                    fprintf(stderr,"create file %s failed\n.",cmd->redirect_in);
                    return;
                }
                dup2(fd_in,0);
            }
            execv(cmd->name,cmd->argv);
            if(cmd->is_redirect_out){
                dup2(defout, 1);
                close(fd);
                close(defout);
            }
            if(cmd->is_redirect_in){
                dup2(defin,0);
                close(fd_in);
                close(defin);
            }
            fflush(stdout);
            exit(0);
        }else {
            if (cmd -> bg == 1) {
                struct bgjob_l *bgjob = (bgjobL*) malloc (sizeof(bgjobL));
                bgjob -> pid = pid;
                bgjob -> state = RUNNING;
                int size = strlen(cmd->cmdline);
                char *pa = malloc(size+1);
                strcpy(pa, cmd->cmdline);
                bgjob -> cmd = pa;
                bgjob -> next = ((void *)0);
                AddToBgJobs(bgjob);
            } else {
                fg_job = pid;
                if(fgCmd!=((void *)0))
                    free(fgCmd);
                int size = strlen (cmd->cmdline);
                fgCmd = malloc(size+1);
                strcpy(fgCmd, cmd->cmdline);
                waitfg(pid);
            }
        }
    }
}

variable_types: forceFork short

variable_types: defout int

variable_types: fd int

variable_types: defin int

variable_types: struct bgjob_l { int pid; enum status { RUNNING=0, STOPPED=1, DONE=2 } state; int job_id; char *cmd; struct bgjob_l *next; } *

variable_types: size int

variable_types:
pa
char *


CheckJobs

original_code:
void CheckJobs()
{
    if (bgjobs == ((void *)0) || bgjobs -> next == ((void *)0))
        return;
    bgjobL *parent = bgjobs;
    bgjobL *current = parent -> next;
    while (current != ((void *)0)) {
        if(current->state == DONE){
            printf("[%d]   %s                    %s\n",current->job_id, "Done",current->cmd);
            fflush(stdout);
            parent->next = current->next;
            free(current->cmd);
            free(current);
        }
        current = current -> next;
        parent = parent -> next;
    }
}

canonical_original_code:
void CheckJobs()
{
    if (bgjobs == ((void *)0) || bgjobs -> next == ((void *)0))
        return;
    struct bgjob_l *parent = bgjobs;
    struct bgjob_l *current = parent -> next;
    while (current != ((void *)0)) {
        if(current->state == DONE){
            printf("[%d]   %s                    %s\n",current->job_id, "Done",current->cmd);
            fflush(stdout);
            parent->next = current->next;
            free(current->cmd);
            free(current);
        }
        current = current -> next;
        parent = parent -> next;
    }
}


ReleaseCmdT

original_code:
void ReleaseCmdT(commandT **cmd){
    int i;
    if((*cmd)->name != ((void *)0)) free((*cmd)->name);
    if((*cmd)->cmdline != ((void *)0)) free((*cmd)->cmdline);
    if((*cmd)->redirect_in != ((void *)0)) free((*cmd)->redirect_in);
    if((*cmd)->redirect_out != ((void *)0)) free((*cmd)->redirect_out);
    for(i = 0; i < (*cmd)->argc; i++)
        if((*cmd)->argv[i] != ((void *)0)) free((*cmd)->argv[i]);
    free(*cmd);
}

canonical_original_code:
void ReleaseCmdT(struct command_t **cmd){
    int i;
    if((*cmd)->name != ((void *)0)) free((*cmd)->name);
    if((*cmd)->cmdline != ((void *)0)) free((*cmd)->cmdline);
    if((*cmd)->redirect_in != ((void *)0)) free((*cmd)->redirect_in);
    if((*cmd)->redirect_out != ((void *)0)) free((*cmd)->redirect_out);
    for(i = 0; i < (*cmd)->argc; i++)
        if((*cmd)->argv[i] != ((void *)0)) free((*cmd)->argv[i]);
    free(*cmd);
}

variable_types: i int


RunExternalCmd

decompiled_code:
void __fastcall RunExternalCmd(__int64 a1, __int16 a2)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = a1;
if ( (unsigned __int16)ResolveExternalCmd(a1) )
{
Exec(v2, a2);
}
else
{
printf("%s: command not found\n", *(const char **)(v2 + 48));
fflush(stdout);
ReleaseCmdT(&v2);
}
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, __int16 a2)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = a1;
if ( (unsigned __int16)func2(a1) )
{
func10(v2, a2);
}
else
{
printf("%s: command not found\n", *(const char **)(v2 + 48));
fflush(stdout);
func12(&v2);
}
}

original_code:
static void RunExternalCmd(commandT* cmd, short fork)
{
    if (ResolveExternalCmd(cmd)){
        Exec(cmd, fork);
    }
    else {
        printf("%s: command not found\n", cmd->argv[0]);
        fflush(stdout);
        ReleaseCmdT(&cmd);
    }
}

canonical_original_code:
static void RunExternalCmd(struct command_t *cmd, short fork)
{
    if (ResolveExternalCmd(cmd)){
        Exec(cmd, fork);
    }
    else {
        printf("%s: command not found\n", cmd->argv[0]);
        fflush(stdout);
        ReleaseCmdT(&cmd);
    }
}

variable_types: struct command_t { char *name; char *cmdline; char *redirect_in; int is_redirect_in; int bg; int argc; char *argv[]; } *

variable_types: fork short


RunCmd

decompiled_code:
void __fastcall RunCmd(__int64 *a1, int a2)
{
__int64 *v2; // rbx
__int64 v3; // rbp
__int64 *v4; // rdi

v2 = a1;
total_task = a2;
if ( a2 == 1 )
{
RunCmdFork_constprop_0(*a1);
}
else
{
RunCmdPipe((const char ***)a1, a2);
if ( a2 > 0 )
{
v3 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
do
{
v4 = v2++;
ReleaseCmdT(v4);
}
while ( v2 != (__int64 *)v3 );
}
}
}

original_code:
void RunCmd(commandT** cmd, int n)
{
    int i;
    total_task = n;
    if(n == 1)
        RunCmdFork(cmd[0], 1);
    else{
        RunCmdPipe(cmd, n);
        for(i = 0; i < n; i++)
            ReleaseCmdT(&cmd[i]);
    }
}

canonical_original_code:
void RunCmd(struct command_t **cmd, int n)
{
    int i;
    total_task = n;
    if(n == 1)
        RunCmdFork(cmd[0], 1);
    else{
        RunCmdPipe(cmd, n);
        for(i = 0; i < n; i++)
            ReleaseCmdT(&cmd[i]);
    }
}

variable_types: n int


decompiled_code:
void sigchld_handler()
{
__pid_t v0; // edx
__int64 v1; // rax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

LABEL_1:
while ( 1 )
{
v0 = waitpid(-1, stat_loc, 1);
if ( v0 <= 0 )
break;
if ( (stat_loc[0] & 0x7F) == 0 )
{
if ( fg_job == v0 )
{
fg_job = 0;
}
else if ( bgjobs )
{
v1 = *((_QWORD *)bgjobs + 3);
if ( v1 )
{
while ( *(_DWORD *)v1 != v0 )
{
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
goto LABEL_1;
}
*(_DWORD *)(v1 + 4) = 2;
}
}
return;
}
}
}

canonical_decompiled_code:
void func0()
{
__pid_t v0; // edx
__int64 v1; // rax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

LABEL_1:
while ( 1 )
{
v0 = waitpid(-1, stat_loc, 1);
if ( v0 <= 0 )
break;
if ( (stat_loc[0] & 0x7F) == 0 )
{
if ( fg_job == v0 )
{
fg_job = 0;
}
else if ( bgjobs )
{
v1 = *((_QWORD *)bgjobs + 3);
if ( v1 )
{
while ( *(_DWORD *)v1 != v0 )
{
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
goto LABEL_1;
}
*(_DWORD *)(v1 + 4) = 2;
}
}
return;
}
}
}

original_code:
static void sigchld_handler(int signo){
    pid_t pid;
    int status;
    while ((pid = waitpid(-1, &status, 1)) > 0) {
        if((((status) & 0x7f) == 0)){
            if (pid == fg_job){
                fg_job = 0;
                return;
            }
            if(bgjobs == ((void *)0) || bgjobs->next==((void *)0))
                return;
            else {
                bgjobL * pre = bgjobs;
                bgjobL * p= bgjobs->next;
                while(p!=((void *)0)){
                    if(p->pid == pid){
                        p->state = DONE;
                        return;
                    }
                    p=p->next;
                    pre=pre->next;
                }
            }
        }
    }
    return;
}

canonical_original_code:
static void sigchld_handler(int signo){
    int pid;
    int status;
    while ((pid = waitpid(-1, &status, 1)) > 0) {
        if((((status) & 0x7f) == 0)){
            if (pid == fg_job){
                fg_job = 0;
                return;
            }
            if(bgjobs == ((void *)0) || bgjobs->next==((void *)0))
                return;
            else {
                struct bgjob_l *pre = bgjobs;
                struct bgjob_l *p = bgjobs->next;
                while(p!=((void *)0)){
                    if(p->pid == pid){
                        p->state = DONE;
                        return;
                    }
                    p=p->next;
                    pre=pre->next;
                }
            }
        }
    }
    return;
}

variable_types: signo int

variable_types: status int


sig

decompiled_code:
void __fastcall sig(int a1)
{
_DWORD *v1; // rdi
__int64 v2; // rax
unsigned int v3; // eax

switch ( a1 )
{
case 2:
if ( fg_job )
{
kill(-fg_job, 2);
fg_job = 0;
}
break;
case 18:
printf("fuck!");
break;
case 20:
if ( fg_job )
{
kill(-fg_job, 20);
v1 = malloc(0x20uLL);
v2 = fgCmd;
v1[1] = 1;
*((_QWORD *)v1 + 2) = v2;
*v1 = fg_job;
v3 = AddToBgJobs();
printf("[%d] %s %s\n", v3, "Stopped", fgCmd);
fg_job = 0;
fgCmd = 0LL;
}
break;
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
_DWORD *v1; // rdi
__int64 v2; // rax
unsigned int v3; // eax

switch ( a1 )
{
case 2:
if ( fg_job )
{
kill(-fg_job, 2);
fg_job = 0;
}
break;
case 18:
printf("fuck!");
break;
case 20:
if ( fg_job )
{
kill(-fg_job, 20);
v1 = malloc(0x20uLL);
v2 = fgCmd;
v1[1] = 1;
*((_QWORD *)v1 + 2) = v2;
*v1 = fg_job;
v3 = AddToBgJobs();
printf("[%d] %s %s\n", v3, "Stopped", fgCmd);
fg_job = 0;
fgCmd = 0LL;
}
break;
}
}

original_code:
static void sig(int signo)
{
    if(signo == 2)
    {
        if(fg_job){
            kill(-fg_job,2);
            fg_job = 0;
        }
        return ;
    }
    if(signo == 18) {
 printf("fuck!");
    }
    if( signo ==20 ) {
        if(fg_job){
            kill(-fg_job,20);
            bgjobL *p = (bgjobL *)malloc(sizeof(bgjobL));
            p->cmd = fgCmd;
            p->pid = fg_job;
            p->state = STOPPED;
            int job_num = AddToBgJobs(p);
            printf("[%d]   %s                 %s\n",job_num, "Stopped", fgCmd);
     fg_job = 0;
            fgCmd = ((void *)0);
        }
        return;
    }
}

canonical_original_code:
static void sig(int signo)
{
    if(signo == 2)
    {
        if(fg_job){
            kill(-fg_job,2);
            fg_job = 0;
        }
        return ;
    }
    if(signo == 18) {
 printf("fuck!");
    }
    if( signo ==20 ) {
        if(fg_job){
            kill(-fg_job,20);
            struct bgjob_l *p = (bgjobL *)malloc(sizeof(bgjobL));
            p->cmd = fgCmd;
            p->pid = fg_job;
            p->state = STOPPED;
            int job_num = AddToBgJobs(p);
            printf("[%d]   %s                 %s\n",job_num, "Stopped", fgCmd);
     fg_job = 0;
            fgCmd = ((void *)0);
        }
        return;
    }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v3; // cf
bool v4; // zf
const char *v5; // rsi
__int64 v6; // rcx
const char *v7; // rdi
void **v8; // rbx
void **v9; // rbp
void *ptr; // [rsp+8h] [rbp-20h] BYREF

ptr = malloc(0x280uLL);
if ( signal(2, sig) == (__sighandler_t)-1LL )
PrintPError("SIGINT");
if ( signal(20, sig) == (__sighandler_t)-1LL )
PrintPError("SIGTSTP");
if ( signal(18, sig) == (__sighandler_t)-1LL )
PrintPError("SIGCONT");
if ( signal(17, (__sighandler_t)sigchld_handler) == (__sighandler_t)-1LL )
PrintPError("SIGCHLD");
if ( !forceExit )
{
while ( 1 )
{
getCommandLine(&ptr, 80LL);
v5 = (const char *)ptr;
v6 = 5LL;
v7 = "exit";
do
{
if ( !v6 )
break;
v3 = *v5 < (unsigned int)*v7;
v4 = *v5++ == *v7++;
--v6;
}
while ( v4 );
if ( (!v3 && !v4) == v3 )
break;
CheckJobs(v7, v5);
Interpret(ptr);
if ( forceExit )
goto LABEL_15;
}
forceExit = 1;
}
LABEL_15:
v8 = (void **)bgjobs;
if ( bgjobs )
{
do
{
v9 = v8;
v8 = (void **)v8[3];
free(v9[2]);
free(v9);
}
while ( v8 );
}
free(ptr);
fflush(stdout);
return 0;
}

original_code:
int main (int argc, char *argv[])
{
    char* cmdLine = malloc(sizeof(char*)*80);
    if (signal(2, sig) == ((__sighandler_t) -1)) PrintPError("SIGINT");
    if (signal(20, sig) == ((__sighandler_t) -1)) PrintPError("SIGTSTP");
    if (signal(18, sig) == ((__sighandler_t) -1)) PrintPError("SIGCONT");
    if (signal(17, sigchld_handler) == ((__sighandler_t) -1)) PrintPError("SIGCHLD");
    while (!forceExit)
    {
        getCommandLine(&cmdLine, 80);
        if(strcmp(cmdLine, "exit") == 0)
        {
            forceExit=1;
            continue;
        }
        CheckJobs();
        Interpret(cmdLine);
    }
    if(bgjobs != ((void *)0)){
        bgjobL * p = bgjobs;
        bgjobL * tmp;
        while(p!=((void *)0)){
            tmp = p->next;
            free(p->cmd);
            free(p);
            p = tmp;
        }
    }
    free(cmdLine);
    fflush(stdout);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char *cmdLine = malloc(sizeof(char*)*80);
    if (signal(2, sig) == ((__sighandler_t) -1)) PrintPError("SIGINT");
    if (signal(20, sig) == ((__sighandler_t) -1)) PrintPError("SIGTSTP");
    if (signal(18, sig) == ((__sighandler_t) -1)) PrintPError("SIGCONT");
    if (signal(17, sigchld_handler) == ((__sighandler_t) -1)) PrintPError("SIGCHLD");
    while (!forceExit)
    {
        getCommandLine(&cmdLine, 80);
        if(strcmp(cmdLine, "exit") == 0)
        {
            forceExit=1;
            continue;
        }
        CheckJobs();
        Interpret(cmdLine);
    }
    if(bgjobs != ((void *)0)){
        struct bgjob_l *p = bgjobs;
        struct bgjob_l *tmp;
        while(p!=((void *)0)){
            tmp = p->next;
            free(p->cmd);
            free(p);
            p = tmp;
        }
    }
    free(cmdLine);
    fflush(stdout);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
cmdLine
char *


PrintNewline

decompiled_code:
int PrintNewline()
{
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
return putchar(10);
}

original_code:
void PrintNewline()
 {
  putchar('\n');
 }

canonical_original_code:
void PrintNewline()
 {
  putchar('\n');
 }


Print

decompiled_code:
int __fastcall Print(const char *a1)
{
if ( !a1 )
_assert_fail("msg != NULL", "io.c", 0x47u, "Print");
return puts(a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
if ( !a1 )
_assert_fail("msg != NULL", "io.c", 0x47u, "Print");
return puts(a1);
}

original_code:
void Print(char* msg)
 {
  ((void) sizeof ((msg != ((void *)0)) ? 1 : 0), __extension__ ({ if (msg != ((void *)0)) ; else __assert_fail ("msg != NULL", "io.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  puts(msg);
 }

canonical_original_code:
void Print(char *msg)
 {
  ((void) sizeof ((msg != ((void *)0)) ? 1 : 0), __extension__ ({ if (msg != ((void *)0)) ; else __assert_fail ("msg != NULL", "io.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  puts(msg);
 }

variable_types:
msg
char *


PrintPError

decompiled_code:
void __fastcall PrintPError(const char *a1)
{
char v1[136]; // [rsp-88h] [rbp-88h] BYREF

if ( a1 )
{
snprintf(v1, 0x77uLL, "%s: %s", "tsh", a1);
perror(v1);
}
else
{
perror("tsh");
}
}

canonical_decompiled_code:
void __fastcall func2(const char *a1)
{
char v1[136]; // [rsp-88h] [rbp-88h] BYREF

if ( a1 )
{
snprintf(v1, 0x77uLL, "%s: %s", "tsh", a1);
perror(v1);
}
else
{
perror("tsh");
}
}

original_code:
void PrintPError(char* msg)
 {
  char* format = "%s: %s";
  char str[120];
  if (msg == ((void *)0))
  {
   perror("tsh");
   return;
  }
  snprintf(str, 120 -1, format, "tsh", msg);
  perror(str);
 }

canonical_original_code:
void PrintPError(char *msg)
 {
  char *format = "%s: %s";
  char str[120];
  if (msg == ((void *)0))
  {
   perror("tsh");
   return;
  }
  snprintf(str, 120 -1, format, "tsh", msg);
  perror(str);
 }

variable_types:
format
char *

variable_types:
str
char [120]


IsReading

decompiled_code:
__int64 IsReading()
{
return (unsigned __int16)isReading;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned __int16)isReading;
}

original_code:
short IsReading()
 {
  return isReading;
 }

canonical_original_code:
short IsReading()
 {
  return isReading;
 }


getCommandLine

decompiled_code:
__int64 __fastcall getCommandLine(_BYTE **a1, int a2)
{
__int64 v3; // rbp
_BYTE *v4; // r12
char v5; // al
char v6; // bl
__int64 result; // rax

v3 = 0LL;
v4 = *a1;
**a1 = 0;
isReading = 1;
while ( 1 )
{
v5 = getc(stdin);
v6 = v5;
if ( v5 == -1 || v5 == 10 )
break;
if ( a2 == v3 )
{
a2 *= 2;
v4 = realloc(v4, a2 + 1);
}
v4[v3++] = v6;
v4[v3] = 0;
}
result = 0LL;
isReading = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE **a1, int a2)
{
__int64 v3; // rbp
_BYTE *v4; // r12
char v5; // al
char v6; // bl
__int64 result; // rax

v3 = 0LL;
v4 = *a1;
**a1 = 0;
isReading = 1;
while ( 1 )
{
v5 = getc(stdin);
v6 = v5;
if ( v5 == -1 || v5 == 10 )
break;
if ( a2 == v3 )
{
a2 *= 2;
v4 = realloc(v4, a2 + 1);
}
v4[v3++] = v6;
v4[v3] = 0;
}
result = 0LL;
isReading = 0;
return result;
}

original_code:
void getCommandLine(char** buf, int size)
 {
  char ch;
  size_t used=0;
  char* cmd = *buf;
  cmd[0] = '\0';
  isReading = 1;
  while (((ch = getc(stdin)) != (-1)) &&
         (ch != '\n'))
  {
   if (used == size)
   {
    size *= 2;
    cmd = realloc(cmd, sizeof(char)*(size+1));
   }
   cmd[used] = ch;
   used++;
   cmd[used] = '\0';
  }
  isReading = 0;
 }

canonical_original_code:
void getCommandLine(char **buf, int size)
 {
  char ch;
  unsigned long used = 0;
  char *cmd = *buf;
  cmd[0] = '\0';
  isReading = 1;
  while (((ch = getc(stdin)) != (-1)) &&
         (ch != '\n'))
  {
   if (used == size)
   {
    size *= 2;
    cmd = realloc(cmd, sizeof(char)*(size+1));
   }
   cmd[used] = ch;
   used++;
   cmd[used] = '\0';
  }
  isReading = 0;
 }

variable_types:
buf
char **

variable_types: ch char

variable_types:
used
unsigned long

variable_types:
cmd
char *


original_code:
void parser_single(char *c, int sz, commandT** cd, int bg)
{
  int i, task_argc = 0, quot1 = 0, quot2 = 0;
  char *in = ((void *)0), * out = ((void *)0), *tmp;
  int cmd_length;
  c[sz] = '\0';
  for(i = 0; i < sz; i++)
    if(c[i] != ' ') break;
  c = &(c[i]);
  sz = sz - i;
  cmd_length = sz;
  for(i = 0; i < sz; i++){
    if(c[i] == '\''){
      if(quot2) continue;
      else if(quot1){
 quot1 = 0;continue;
      }
      else quot1 = 1;
    }
    if(c[i] == '"'){
      if(quot1) continue;
      else if(quot2){
        quot2 = 0;continue;
      }
      else quot2 = 1;
    }
    if(c[i] == '<' && quot1 != 1 && quot2 != 1){
      if(cmd_length == sz) cmd_length = i;
      while(i < (sz - 1) && c[i + 1] == ' ') i++;
      in = &(c[i+1]);
    }
    if(c[i] == '>' && quot1 != 1 && quot2 != 1){
      if(cmd_length == sz) cmd_length = i;
      while(i < (sz - 1) && c[i+1] == ' ') i++;
      out = &(c[i+1]);
    }
    if(c[i] == ' ' && quot1 != 1 && quot2 != 1){
      if(cmd_length == sz) task_argc++;
      while(i < (sz - 1) && c[i+1] == ' ') i++;
    }
  }
  if(c[cmd_length - 1] != ' ') task_argc++;
  (*cd) = CreateCmdT(task_argc);
  (*cd) -> bg = bg;
  (*cd)->cmdline = strdup(c);
  tmp = c;
  for(i = 0; i < task_argc; i++){
    (*cd) -> argv[i] = strdup(single_param(tmp));
    while ((*tmp) != '\0') tmp++;
    tmp ++;
  }
  if(in){
    (*cd) -> is_redirect_in = 1;
    (*cd) -> redirect_in = strdup(single_param(in));
  }
  if(out){
    (*cd) -> is_redirect_out = 1;
    (*cd) -> redirect_out = strdup(single_param(out));
  }
}

canonical_original_code:
void parser_single(char *c, int sz, struct command_t **cd, int bg)
{
  int i; int task_argc = 0; int quot1 = 0; int quot2 = 0;
  char *in = ((void *)0); char *out = ((void *)0); char *tmp;
  int cmd_length;
  c[sz] = '\0';
  for(i = 0; i < sz; i++)
    if(c[i] != ' ') break;
  c = &(c[i]);
  sz = sz - i;
  cmd_length = sz;
  for(i = 0; i < sz; i++){
    if(c[i] == '\''){
      if(quot2) continue;
      else if(quot1){
 quot1 = 0;continue;
      }
      else quot1 = 1;
    }
    if(c[i] == '"'){
      if(quot1) continue;
      else if(quot2){
        quot2 = 0;continue;
      }
      else quot2 = 1;
    }
    if(c[i] == '<' && quot1 != 1 && quot2 != 1){
      if(cmd_length == sz) cmd_length = i;
      while(i < (sz - 1) && c[i + 1] == ' ') i++;
      in = &(c[i+1]);
    }
    if(c[i] == '>' && quot1 != 1 && quot2 != 1){
      if(cmd_length == sz) cmd_length = i;
      while(i < (sz - 1) && c[i+1] == ' ') i++;
      out = &(c[i+1]);
    }
    if(c[i] == ' ' && quot1 != 1 && quot2 != 1){
      if(cmd_length == sz) task_argc++;
      while(i < (sz - 1) && c[i+1] == ' ') i++;
    }
  }
  if(c[cmd_length - 1] != ' ') task_argc++;
  (*cd) = CreateCmdT(task_argc);
  (*cd) -> bg = bg;
  (*cd)->cmdline = strdup(c);
  tmp = c;
  for(i = 0; i < task_argc; i++){
    (*cd) -> argv[i] = strdup(single_param(tmp));
    while ((*tmp) != '\0') tmp++;
    tmp ++;
  }
  if(in){
    (*cd) -> is_redirect_in = 1;
    (*cd) -> redirect_in = strdup(single_param(in));
  }
  if(out){
    (*cd) -> is_redirect_out = 1;
    (*cd) -> redirect_out = strdup(single_param(out));
  }
}

variable_types:
c
char *

variable_types: sz int

variable_types: struct command_t { char *name; char *cmdline; char *redirect_in; int is_redirect_in; int bg; int argc; char *argv[]; } **

variable_types: bg int

variable_types:
in
char *

variable_types:
out
char *

variable_types:
tmp
char *


Interpret

original_code:
void Interpret(char* cmdLine)
{
  int task = 1;
  int bg = 0, i,k,j = 0, quotation1 = 0, quotation2 = 0;
  commandT **command;
  if(cmdLine[0] == '\0') return;
  for(i = 0; i < strlen(cmdLine); i++){
    if(cmdLine[i] == '\''){
      if(quotation2) continue;
      else if(quotation1){
 quotation1 = 0;continue;
      }
      else quotation1 = 1;
    }
    if(cmdLine[i] == '"'){
      if(quotation1) continue;
      else if(quotation2){
        quotation2 = 0;continue;
      }
      else quotation2 = 1;
    }
    if(cmdLine[i] == '|' && quotation1 != 1 && quotation2 != 1){
      task ++;
    }
  }
  command = (commandT **) malloc(sizeof(commandT *) * task);
  i = strlen(cmdLine) - 1;
  while(i >= 0 && cmdLine[i] == ' ') i--;
  if(cmdLine[i] == '&'){
    if(i == 0) return;
    bg = 1;
    cmdLine[i] = '\0';
  }
  quotation1 = quotation2 = 0;
  task = 0;
  k = strlen(cmdLine);
  for(i = 0; i < k; i++, j++){
    if(cmdLine[i] == '\''){
      if(quotation2) continue;
      else if(quotation1){
 quotation1 = 0;continue;
      }
      else quotation1 = 1;
    }
    if(cmdLine[i] == '"'){
      if(quotation1) continue;
      else if(quotation2){
        quotation2 = 0;continue;
      }
      else quotation2 = 1;
    }
    if(cmdLine[i] == '|' && quotation1 != 1 && quotation2 != 1){
      parser_single(&(cmdLine[i-j]), j, &(command[task]),bg);
      task++;
      j = -1;
    }
  }
  parser_single(&(cmdLine[i-j]), j, &(command[task]),bg);
  RunCmd(command, task+1);
  free(command);
}

canonical_original_code:
void Interpret(char *cmdLine)
{
  int task = 1;
  int bg = 0; int i; int k; int j = 0; int quotation1 = 0; int quotation2 = 0;
  struct command_t **command;
  if(cmdLine[0] == '\0') return;
  for(i = 0; i < strlen(cmdLine); i++){
    if(cmdLine[i] == '\''){
      if(quotation2) continue;
      else if(quotation1){
 quotation1 = 0;continue;
      }
      else quotation1 = 1;
    }
    if(cmdLine[i] == '"'){
      if(quotation1) continue;
      else if(quotation2){
        quotation2 = 0;continue;
      }
      else quotation2 = 1;
    }
    if(cmdLine[i] == '|' && quotation1 != 1 && quotation2 != 1){
      task ++;
    }
  }
  command = (struct command_t **) malloc(sizeof(struct command_t *) * task);
  i = strlen(cmdLine) - 1;
  while(i >= 0 && cmdLine[i] == ' ') i--;
  if(cmdLine[i] == '&'){
    if(i == 0) return;
    bg = 1;
    cmdLine[i] = '\0';
  }
  quotation1 = quotation2 = 0;
  task = 0;
  k = strlen(cmdLine);
  for(i = 0; i < k; i++, j++){
    if(cmdLine[i] == '\''){
      if(quotation2) continue;
      else if(quotation1){
 quotation1 = 0;continue;
      }
      else quotation1 = 1;
    }
    if(cmdLine[i] == '"'){
      if(quotation1) continue;
      else if(quotation2){
        quotation2 = 0;continue;
      }
      else quotation2 = 1;
    }
    if(cmdLine[i] == '|' && quotation1 != 1 && quotation2 != 1){
      parser_single(&(cmdLine[i-j]), j, &(command[task]),bg);
      task++;
      j = -1;
    }
  }
  parser_single(&(cmdLine[i-j]), j, &(command[task]),bg);
  RunCmd(command, task+1);
  free(command);
}

variable_types: task int

variable_types: i int

variable_types: k int

variable_types: j int


main

repo: HeisSpiter/hepunion

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
unsigned int *v4; // rbx
int *v5; // [rsp-8h] [rbp-1020h]
char v6[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( geteuid() )
{
fprintf(
stderr,
"%s:%d \"%s\" failed: %s",
"hepunion_tests_main.c",
24LL,
"geteuid() == 0",
"Please, run the program as root!\n");
result = -13;
}
else
{
if ( argc <= 1 )
{
getcwd(v6, 0x1000uLL);
}
else
{
strncpy(v6, argv[1], 0x1000uLL);
if ( chdir(v6) == -1 )
{
v5 = __errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: working_dir=\"%s\" errno=%d\n",
"hepunion_tests_main.c",
30LL,
"chdir(working_dir) != -1",
v6,
(unsigned int)*v5);
return -*v5;
}
}
fprintf(_bss_start, "%s:%d Will execute tests on: %s\n", "hepunion_tests_main.c", 36LL, v6);
if ( (unsigned int)check_tree_dir("export/") == -1 )
{
v4 = (unsigned int *)__errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: Failed stat() on export directory, errno = %d\n",
"hepunion_tests_main.c",
39LL,
"check_tree_dir(\"export/\") != -1",
*v4);
}
else if ( (unsigned int)check_tree_dir("root/") == -1 )
{
v4 = (unsigned int *)__errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: Failed stat() on root directory, errno = %d\n",
"hepunion_tests_main.c",
40LL,
"check_tree_dir(\"root/\") != -1",
*v4);
}
else
{
if ( (unsigned int)check_tree_dir("snapshot/") != -1 )
{
do_tests(v6);
return 0;
}
v4 = (unsigned int *)__errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: Failed stat() on snapshot directory, errno = %d\n",
"hepunion_tests_main.c",
41LL,
"check_tree_dir(\"snapshot/\") != -1",
*v4);
}
result = -*v4;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
unsigned int *v4; // rbx
int *v5; // [rsp-8h] [rbp-1020h]
char v6[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( geteuid() )
{
fprintf(
stderr,
"%s:%d \"%s\" failed: %s",
"hepunion_tests_main.c",
24LL,
"geteuid() == 0",
"Please, run the program as root!\n");
result = -13;
}
else
{
if ( argc <= 1 )
{
getcwd(v6, 0x1000uLL);
}
else
{
strncpy(v6, argv[1], 0x1000uLL);
if ( chdir(v6) == -1 )
{
v5 = __errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: working_dir=\"%s\" errno=%d\n",
"hepunion_tests_main.c",
30LL,
"chdir(working_dir) != -1",
v6,
(unsigned int)*v5);
return -*v5;
}
}
fprintf(_bss_start, "%s:%d Will execute tests on: %s\n", "hepunion_tests_main.c", 36LL, v6);
if ( (unsigned int)func9("export/") == -1 )
{
v4 = (unsigned int *)__errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: Failed stat() on export directory, errno = %d\n",
"hepunion_tests_main.c",
39LL,
"check_tree_dir(\"export/\") != -1",
*v4);
}
else if ( (unsigned int)func9("root/") == -1 )
{
v4 = (unsigned int *)__errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: Failed stat() on root directory, errno = %d\n",
"hepunion_tests_main.c",
40LL,
"check_tree_dir(\"root/\") != -1",
*v4);
}
else
{
if ( (unsigned int)func9("snapshot/") != -1 )
{
func8(v6);
return 0;
}
v4 = (unsigned int *)__errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: Failed stat() on snapshot directory, errno = %d\n",
"hepunion_tests_main.c",
41LL,
"check_tree_dir(\"snapshot/\") != -1",
*v4);
}
result = -*v4;
}
return result;
}

original_code:
int main(int argc, char **argv) {
 char working_dir[4096];
 if (!(geteuid() == 0)) { fprintf(stderr, "%s:%d \"%s\" failed: " "%s", "hepunion_tests_main.c", 24, "geteuid() == 0", "Please, run the program as root!\n"); return -13; };
 if (argc > 1) {
  strncpy(working_dir, argv[1], sizeof(working_dir) / sizeof(working_dir[0]));
  if (!(chdir(working_dir) != -1)) { fprintf(stderr, "%s:%d \"%s\" failed: " "working_dir=\"%s\" errno=%d\n", "hepunion_tests_main.c", 30, "chdir(working_dir) != -1", working_dir, (*__errno_location ())); return -(*__errno_location ()); };
 } else {
  getcwd(working_dir, sizeof(working_dir));
 }
 fprintf(stdout, "%s:%d " "Will execute tests on: %s\n", "hepunion_tests_main.c", 36, working_dir);
 if (!(check_tree_dir("export/") != -1)) { fprintf(stderr, "%s:%d \"%s\" failed: " "Failed stat() on export directory, errno = %d\n", "hepunion_tests_main.c", 39, "check_tree_dir(\"export/\") != -1", (*__errno_location ())); return -(*__errno_location ()); };
 if (!(check_tree_dir("root/") != -1)) { fprintf(stderr, "%s:%d \"%s\" failed: " "Failed stat() on root directory, errno = %d\n", "hepunion_tests_main.c", 40, "check_tree_dir(\"root/\") != -1", (*__errno_location ())); return -(*__errno_location ()); };
 if (!(check_tree_dir("snapshot/") != -1)) { fprintf(stderr, "%s:%d \"%s\" failed: " "Failed stat() on snapshot directory, errno = %d\n", "hepunion_tests_main.c", 41, "check_tree_dir(\"snapshot/\") != -1", (*__errno_location ())); return -(*__errno_location ()); };
 do_tests(working_dir);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **