getPtr

decompiled_code:
__int64 __fastcall getPtr(__int64 a1)
{
if ( *(_DWORD *)a1 != 3 )
puts("WARNING: var is not a PTR");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( *(_DWORD *)a1 != 3 )
puts("WARNING: var is not a PTR");
return *(_QWORD *)(a1 + 8);
}

original_code:
void *getPtr(s_var *var)
{
 if (var->type != PTR)
 {
  printf("WARNING: var is not a PTR\n");
 }
 return (var->value._ptr);
}

canonical_original_code:
void *getPtr(struct s_var *var)
{
 if (var->type != PTR)
 {
  printf("WARNING: var is not a PTR\n");
 }
 return (var->value._ptr);
}


getChar

repo: HallowTeam/CLib

decompiled_code:
__int64 __fastcall getChar(__int64 a1)
{
if ( *(_DWORD *)a1 != 1 )
puts("WARNING: var is not a CHAR");
return *(unsigned __int8 *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
if ( *(_DWORD *)a1 != 1 )
puts("WARNING: var is not a CHAR");
return *(unsigned __int8 *)(a1 + 8);
}

original_code:
char getChar(s_var *var)
{
 if (var->type != CHAR)
 {
  printf("WARNING: var is not a CHAR\n");
 }
 return (var->value._char);
}

canonical_original_code:
char getChar(struct s_var *var)
{
 if (var->type != CHAR)
 {
  printf("WARNING: var is not a CHAR\n");
 }
 return (var->value._char);
}

variable_types: 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; } *

return_type: char

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


xfree

decompiled_code:
__int64 __fastcall xfree(void *a1)
{
if ( a1 )
free(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1)
{
if ( a1 )
free(a1);
return 0LL;
}

original_code:
void *xfree(void *ptr)
{
 if (ptr != ((void *)0))
 {
  free(ptr);
 }
 return ptr = ((void *)0);
}

variable_types:
ptr
void *

return_type: void *


recvTCP

decompiled_code:
__int64 __fastcall recvTCP(int *a1, __int64 *a2)
{
__int64 v2; // r12
unsigned int v3; // ebx
int v4; // ebp
__int64 v5; // rax
unsigned int v6; // eax
unsigned int v7; // er15

v2 = 512LL;
v3 = 0;
v4 = 1;
while ( 1 )
{
++v4;
v5 = xrealloc(*a2, v2);
*a2 = v5;
if ( !v5 )
{
xfree(0LL);
return (unsigned int)-1;
}
v6 = recv(*a1, (void *)(v5 + (int)v3), 0x1FFuLL, 0);
v7 = v6;
if ( v6 == -1 )
break;
v3 += v6;
if ( v6 != 511 )
goto LABEL_10;
if ( v4 == 2 )
blockFile((unsigned int)*a1, 1LL);
v2 += 511LL;
}
if ( *_errno_location() != 11 )
{
xfree(*a2);
perror("recv()");
return v7;
}
LABEL_10:
if ( v4 != 2 )
blockFile((unsigned int)*a1, 0LL);
*(_BYTE *)(*a2 + (int)v3) = 0;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, __int64 *a2)
{
__int64 v2; // r12
unsigned int v3; // ebx
int v4; // ebp
__int64 v5; // rax
unsigned int v6; // eax
unsigned int v7; // er15

v2 = 512LL;
v3 = 0;
v4 = 1;
while ( 1 )
{
++v4;
v5 = xrealloc(*a2, v2);
*a2 = v5;
if ( !v5 )
{
xfree(0LL);
return (unsigned int)-1;
}
v6 = recv(*a1, (void *)(v5 + (int)v3), 0x1FFuLL, 0);
v7 = v6;
if ( v6 == -1 )
break;
v3 += v6;
if ( v6 != 511 )
goto LABEL_10;
if ( v4 == 2 )
blockFile((unsigned int)*a1, 1LL);
v2 += 511LL;
}
if ( *_errno_location() != 11 )
{
xfree(*a2);
perror("recv()");
return v7;
}
LABEL_10:
if ( v4 != 2 )
blockFile((unsigned int)*a1, 0LL);
*(_BYTE *)(*a2 + (int)v3) = 0;
return v3;
}

original_code:
int recvTCP(s_socket *sock, char **message)
{
 int i = 1;
 int len = 0;
 int total = 0;
 do
 {
  if (i == 2)
  {
   blockFile(sock->fd, false);
  }
  if ((*message = xrealloc(*message, (512 - 1) * i++ + 1)) == ((void *)0))
  {
   xfree(*message);
   return -1;
  }
  if ((len = recv(sock->fd, *message + total, 512 - 1, 0)) == -1)
  {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11)
   {
    break;
   }
   xfree(*message);
   perror("recv()");
   return -1;
  }
  total += len;
 } while (len == 512 - 1);
 if (i != 2)
 {
  blockFile(sock->fd, true);
 }
 (*message)[total] = '\0';
 return total;
}

canonical_original_code:
int recvTCP(struct s_socket *sock, char **message)
{
 int i = 1;
 int len = 0;
 int total = 0;
 do
 {
  if (i == 2)
  {
   blockFile(sock->fd, false);
  }
  if ((*message = xrealloc(*message, (512 - 1) * i++ + 1)) == ((void *)0))
  {
   xfree(*message);
   return -1;
  }
  if ((len = recv(sock->fd, *message + total, 512 - 1, 0)) == -1)
  {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11)
   {
    break;
   }
   xfree(*message);
   perror("recv()");
   return -1;
  }
  total += len;
 } while (len == 512 - 1);
 if (i != 2)
 {
  blockFile(sock->fd, true);
 }
 (*message)[total] = '\0';
 return total;
}

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; } *

variable_types:
message
char **

variable_types: i int

variable_types: len int

variable_types: total int

return_type: int

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]; }


sendTCP

decompiled_code:
__int64 __fastcall sendTCP(int *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
if ( send(*a1, a2, v2, 0) != -1 )
return 0LL;
perror("send()");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
if ( send(*a1, a2, v2, 0) != -1 )
return 0LL;
perror("send()");
return 0xFFFFFFFFLL;
}

original_code:
int sendTCP(s_socket *sock, char *message)
{
 if (send(sock->fd, message, strlen(message), 0) == -1)
 {
  perror("send()");
  return -1;
 }
 return 0;
}

canonical_original_code:
int sendTCP(struct s_socket *sock, char *message)
{
 if (send(sock->fd, message, strlen(message), 0) == -1)
 {
  perror("send()");
  return -1;
 }
 return 0;
}

variable_types:
message
char *


printVar

decompiled_code:
int __fastcall printVar(unsigned int *a1)
{
unsigned int v1; // eax
char v2; // al
int result; // eax
const void *v4; // rax
unsigned int v5; // eax
const char *v6; // rax

v1 = *a1;
if ( *a1 == 2 )
{
v6 = (const char *)getStr();
result = printf("STR : %s\n", v6);
}
else if ( v1 > 2 )
{
if ( v1 == 3 )
{
v4 = (const void *)getPtr();
result = printf("PTR : %p\n", v4);
}
else
{
result = puts("UNDEF");
}
}
else if ( v1 )
{
v2 = getChar();
result = printf("CHAR : %c\n", (unsigned int)v2);
}
else
{
v5 = getInt();
result = printf("INT : %d\n", v5);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(unsigned int *a1)
{
unsigned int v1; // eax
char v2; // al
int result; // eax
const void *v4; // rax
unsigned int v5; // eax
const char *v6; // rax

v1 = *a1;
if ( *a1 == 2 )
{
v6 = (const char *)getStr();
result = printf("STR : %s\n", v6);
}
else if ( v1 > 2 )
{
if ( v1 == 3 )
{
v4 = (const void *)getPtr();
result = printf("PTR : %p\n", v4);
}
else
{
result = puts("UNDEF");
}
}
else if ( v1 )
{
v2 = getChar();
result = printf("CHAR : %c\n", (unsigned int)v2);
}
else
{
v5 = getInt();
result = printf("INT : %d\n", v5);
}
return result;
}

original_code:
void printVar(s_var *var)
{
 switch (var->type)
 {
  case INT : printf("INT : %d\n", getInt(var)); break;
  case STR : printf("STR : %s\n", getStr(var)); break;
  case PTR : printf("PTR : %p\n", getPtr(var)); break;
  case CHAR: printf("CHAR : %c\n", getChar(var)); break;
  default : printf("UNDEF\n") ; break;
 }
}

canonical_original_code:
void printVar(struct s_var *var)
{
 switch (var->type)
 {
  case INT : printf("INT : %d\n", getInt(var)); break;
  case STR : printf("STR : %s\n", getStr(var)); break;
  case PTR : printf("PTR : %p\n", getPtr(var)); break;
  case CHAR: printf("CHAR : %c\n", getChar(var)); break;
  default : printf("UNDEF\n") ; break;
 }
}

return_type: void

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; }


newTCPClient

decompiled_code:
__int64 __fastcall newTCPClient(char *cp, __int16 a2)
{
__int64 v2; // rbx
int v3; // eax

v2 = xmalloc(20LL);
if ( v2 )
{
v3 = socket(2, 1, 0);
*(_DWORD *)v2 = v3;
if ( v3 == -1 )
{
perror("socket()");
v2 = freeSocket(v2);
}
else
{
*(_DWORD *)(v2 + 8) = inet_addr(cp);
*(_WORD *)(v2 + 4) = 2;
*(_WORD *)(v2 + 6) = _bswap_16(a2);
if ( connect(*(_DWORD *)v2, (const struct sockaddr *)(v2 + 4), 0x10u) == -1 )
{
perror("connect()");
v2 = freeSocket(v2);
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *cp, __int16 a2)
{
__int64 v2; // rbx
int v3; // eax

v2 = xmalloc(20LL);
if ( v2 )
{
v3 = socket(2, 1, 0);
*(_DWORD *)v2 = v3;
if ( v3 == -1 )
{
perror("socket()");
v2 = freeSocket(v2);
}
else
{
*(_DWORD *)(v2 + 8) = inet_addr(cp);
*(_WORD *)(v2 + 4) = 2;
*(_WORD *)(v2 + 6) = func0(a2);
if ( connect(*(_DWORD *)v2, (const struct sockaddr *)(v2 + 4), 0x10u) == -1 )
{
perror("connect()");
v2 = freeSocket(v2);
}
}
}
return v2;
}

original_code:
s_socket *newTCPClient(char *server, int port)
{
 s_socket *sock;
 if ((sock = xmalloc(sizeof(*sock))) == ((void *)0))
 {
  return ((void *)0);
 }
 if ((sock->fd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("socket()");
  return freeSocket(sock);
 }
 sock->in.sin_addr.s_addr = inet_addr(server);
 sock->in.sin_family = 2;
 sock->in.sin_port = htons(port);
 if (connect(sock->fd, (SOCKADDR *)&(sock->in), sizeof(sock->in)) == -1)
 {
  perror("connect()");
  return freeSocket(sock);
 }
 return sock;
}

canonical_original_code:
struct s_socket *newTCPClient(char *server, int port)
{
 struct s_socket *sock;
 if ((sock = xmalloc(sizeof(*sock))) == ((void *)0))
 {
  return ((void *)0);
 }
 if ((sock->fd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("socket()");
  return freeSocket(sock);
 }
 sock->in.sin_addr.s_addr = inet_addr(server);
 sock->in.sin_family = 2;
 sock->in.sin_port = htons(port);
 if (connect(sock->fd, (struct sockaddr *)&(sock->in), sizeof(sock->in)) == -1)
 {
  perror("connect()");
  return freeSocket(sock);
 }
 return sock;
}

variable_types:
server
char *

variable_types: port int

return_type: 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 sockaddr { unsigned short sa_family; char sa_data[14]; }


newTCPServer

decompiled_code:
__int64 __fastcall newTCPServer(__int16 a1)
{
__int64 v2; // rbx
int v3; // edi
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v2 = xmalloc(20LL);
if ( v2 )
{
v3 = socket(2, 1, 0);
*(_DWORD *)v2 = v3;
if ( v3 == -1 )
{
perror("socket()");
v2 = freeSocket(v2);
}
else
{
setsockopt(v3, 1, 2, optval, 4u);
*(_DWORD *)(v2 + 8) = _bswap_32(0);
*(_WORD *)(v2 + 4) = 2;
*(_WORD *)(v2 + 6) = _bswap_16(a1);
if ( bind(*(_DWORD *)v2, (const struct sockaddr *)(v2 + 4), 0x10u) == -1 )
{
perror("bind()");
v2 = freeSocket(v2);
}
else if ( listen(*(_DWORD *)v2, 5) == -1 )
{
perror("listen()");
v2 = freeSocket(v2);
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1)
{
__int64 v2; // rbx
int v3; // edi
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v2 = xmalloc(20LL);
if ( v2 )
{
v3 = socket(2, 1, 0);
*(_DWORD *)v2 = v3;
if ( v3 == -1 )
{
perror("socket()");
v2 = freeSocket(v2);
}
else
{
setsockopt(v3, 1, 2, optval, 4u);
*(_DWORD *)(v2 + 8) = func1(0);
*(_WORD *)(v2 + 4) = 2;
*(_WORD *)(v2 + 6) = func0(a1);
if ( bind(*(_DWORD *)v2, (const struct sockaddr *)(v2 + 4), 0x10u) == -1 )
{
perror("bind()");
v2 = freeSocket(v2);
}
else if ( listen(*(_DWORD *)v2, 5) == -1 )
{
perror("listen()");
v2 = freeSocket(v2);
}
}
}
return v2;
}

original_code:
s_socket *newTCPServer(int port)
{
 int reuse = 1;
 s_socket *sock;
 if ((sock = xmalloc(sizeof(*sock))) == ((void *)0))
 {
  return ((void *)0);
 }
 if ((sock->fd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("socket()");
  return freeSocket(sock);
 }
 setsockopt(sock->fd, 1, 2, &reuse, sizeof(reuse));
 sock->in.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 sock->in.sin_family = 2;
 sock->in.sin_port = htons(port);
 if (bind(sock->fd, (SOCKADDR *)&(sock->in), sizeof(sock->in)) == -1)
 {
  perror("bind()");
  return freeSocket(sock);
 }
 if (listen(sock->fd, 5) == -1)
 {
  perror("listen()");
  return freeSocket(sock);
 }
 return sock;
}

canonical_original_code:
struct s_socket *newTCPServer(int port)
{
 int reuse = 1;
 struct s_socket *sock;
 if ((sock = xmalloc(sizeof(*sock))) == ((void *)0))
 {
  return ((void *)0);
 }
 if ((sock->fd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("socket()");
  return freeSocket(sock);
 }
 setsockopt(sock->fd, 1, 2, &reuse, sizeof(reuse));
 sock->in.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 sock->in.sin_family = 2;
 sock->in.sin_port = htons(port);
 if (bind(sock->fd, (struct sockaddr *)&(sock->in), sizeof(sock->in)) == -1)
 {
  perror("bind()");
  return freeSocket(sock);
 }
 if (listen(sock->fd, 5) == -1)
 {
  perror("listen()");
  return freeSocket(sock);
 }
 return sock;
}

variable_types: reuse int


nextItem

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

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 || (result = *(_QWORD *)(v1 + 8)) == 0 )
result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 || (result = *(_QWORD *)(v1 + 8)) == 0 )
result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
s_item *nextItem(s_list *list)
{
 if (list->curr == ((void *)0) || list->curr->next == ((void *)0))
 {
  return list->curr = list->head;
 }
 return list->curr = list->curr->next;
}

canonical_original_code:
struct s_item *nextItem(struct s_list *list)
{
 if (list->curr == ((void *)0) || list->curr->next == ((void *)0))
 {
  return list->curr = list->head;
 }
 return list->curr = list->curr->next;
}

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

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; } *

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


prevItem

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

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 || (result = *(_QWORD *)(v1 + 16)) == 0 )
result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 || (result = *(_QWORD *)(v1 + 16)) == 0 )
result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
s_item *prevItem(s_list *list)
{
 if (list->curr == ((void *)0) || list->curr->prev == ((void *)0))
 {
  return list->curr = list->tail;
 }
 return list->curr = list->curr->prev;
}

canonical_original_code:
struct s_item *prevItem(struct s_list *list)
{
 if (list->curr == ((void *)0) || list->curr->prev == ((void *)0))
 {
  return list->curr = list->tail;
 }
 return list->curr = list->curr->prev;
}

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


serverAccept

decompiled_code:
int *__fastcall serverAccept(__int64 a1)
{
int *v1; // rbx
int v2; // eax
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = (int *)xmalloc(20LL);
if ( v1 )
{
addr_len[0] = 16;
v2 = accept(*(_DWORD *)a1, (struct sockaddr *)(a1 + 4), addr_len);
*v1 = v2;
if ( v2 == -1 )
{
perror("accept()");
v1 = (int *)freeSocket(v1);
}
}
return v1;
}

canonical_decompiled_code:
int *__fastcall func0(__int64 a1)
{
int *v1; // rbx
int v2; // eax
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = (int *)xmalloc(20LL);
if ( v1 )
{
addr_len[0] = 16;
v2 = accept(*(_DWORD *)a1, (struct sockaddr *)(a1 + 4), addr_len);
*v1 = v2;
if ( v2 == -1 )
{
perror("accept()");
v1 = (int *)freeSocket(v1);
}
}
return v1;
}

original_code:
s_socket *serverAccept(s_socket *server)
{
 int sinsize;
 s_socket *client;
 if ((client = xmalloc(sizeof(*client))) == ((void *)0))
 {
  return ((void *)0);
 }
 sinsize = sizeof(server->in);
 if ((client->fd = accept(server->fd, (SOCKADDR *)&(server->in), (socklen_t *)&sinsize)) == -1)
 {
  perror("accept()");
  return freeSocket(client);
 }
 return client;
}

canonical_original_code:
struct s_socket *serverAccept(struct s_socket *server)
{
 int sinsize;
 struct s_socket *client;
 if ((client = xmalloc(sizeof(*client))) == ((void *)0))
 {
  return ((void *)0);
 }
 sinsize = sizeof(server->in);
 if ((client->fd = accept(server->fd, (struct sockaddr *)&(server->in), (unsigned int *)&sinsize)) == -1)
 {
  perror("accept()");
  return freeSocket(client);
 }
 return client;
}

variable_types:
server
struct s_socket *

variable_types: sinsize int


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

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

v0 = xmalloc(24LL);
v1 = (_QWORD *)v0;
if ( v0 )
{
*(_QWORD *)(v0 + 16) = 0LL;
*(_QWORD *)(v0 + 8) = 0LL;
v2 = xmalloc(16LL);
*v1 = v2;
if ( !v2 )
v1 = (_QWORD *)xfree(v1);
}
return v1;
}

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; } *


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: index int


xmalloc

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

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

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

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


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


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

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 *


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);
}


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; } *


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)
{
const unsigned __int16 **v2; // rbp
char *v3; // rbx
__int64 v4; // r12
char v5; // si

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

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

if ( a2 > 0 )
{
v2 = _ctype_b_loc();
v3 = a1;
v4 = (__int64)&a1[a2 - 1 + 1];
do
{
v5 = *v3;
if ( ((*v2)[*v3] & 0x4000) != 0 )
putchar(v5);
else
printf("{%02X}", (unsigned int)v5);
++v3;
}
while ( v3 != (char *)v4 );
}
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

variable_types: i int


xcalloc

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

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; // rbx

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

variable_types:
ptr
void *


xrealloc

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

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; // rbx

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
const void *v3; // rax
unsigned int v4; // eax
unsigned int v5; // eax
char v6; // al
const char *v7; // rax

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

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

v1 = *(_QWORD *)(a1 + 16);
printf("NULL => ");
for ( ; v1; v1 = *(_QWORD *)(v1 + 8) )
{
v5 = **(_DWORD **)v1;
if ( v5 == 2 )
{
v7 = (const char *)getStr();
printf("STR : %s => ", v7);
}
else if ( v5 > 2 )
{
if ( v5 == 3 )
{
v3 = (const void *)getPtr();
printf("PTR : %p => ", v3);
}
else
{
printf("UNDEF => ");
}
}
else if ( v5 )
{
v6 = getChar();
printf("CHAR : %c => ", (unsigned int)v6);
}
else
{
v4 = getInt();
printf("INT : %d => ", v4);
}
}
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)
{
int i; // eax
char *v5; // rdi
__int64 result; // rax

if ( !a2[1] )
sub_401182(*a2);
dword_404090 = 1;
if ( a1 > 1 )
{
for ( i = 1; i < a1; dword_404090 = i )
{
v5 = a2[i];
if ( *v5 == 45 )
{
switch ( v5[1] )
{
case 'd':
dword_404084 = 1;
break;
case 'h':
sub_401182(*a2);
case 'm':
sub_4013F3(a2[i + 1], a2[i + 2], a2[i + 3]);
return result;
case 'r':
sub_4013CA(a2[i + 1], a2[i + 2]);
return result;
case 'v':
dword_404080 = 1;
break;
default:
fprintf(_bss_start, "Unrecognized option (%s).\nSee `%s -h` or `man %s` for help.\n", a2[i], *a2, *a2);
exit(1);
}
}
else
{
sub_40122E(v5, dword_404084);
}
i = dword_404090 + 1;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall main(int a1, char **a2, char **a3)
{
int i; // eax
char *v5; // rdi
__int64 result; // rax

if ( !a2[1] )
func6(*a2);
dword_404090 = 1;
if ( a1 > 1 )
{
for ( i = 1; i < a1; dword_404090 = i )
{
v5 = a2[i];
if ( *v5 == 45 )
{
switch ( v5[1] )
{
case 'd':
dword_404084 = 1;
break;
case 'h':
func6(*a2);
case 'm':
func9(a2[i + 1], a2[i + 2], a2[i + 3]);
return result;
case 'r':
func8(a2[i + 1], a2[i + 2]);
return result;
case 'v':
dword_404080 = 1;
break;
default:
fprintf(_bss_start, "Unrecognized option (%s).\nSee `%s -h` or `man %s` for help.\n", a2[i], *a2, *a2);
exit(1);
}
}
else
{
func7(v5, dword_404084);
}
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; // rax
struct tm *v5; // rax

stream = fopen("/proc/stat", "r");
__isoc99_fscanf();
fclose(stream);
if ( a2[1] )
sub_401202(*a2);
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_18:
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);
v5 = localtime(&timer);
strftime(s, 0x26uLL, "%H.%M | %A, %d %B %Y", v5);
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
{
v3 = qword_404150 + qword_404158 + qword_404160 - qword_404140 - qword_404138 - qword_404130;
v4 = 100 * v3 / (v3 + qword_404148 - qword_404128);
dword_404124 = v4;
if ( (int)v4 > 90 )
{
putchar(108);
goto LABEL_17;
}
if ( (int)v4 > 66 )
{
putchar(105);
goto LABEL_17;
}
if ( (int)v4 > 33 )
{
putchar(58);
LABEL_17:
printf(" | ");
goto LABEL_18;
}
}
putchar(46);
goto LABEL_17;
}

canonical_decompiled_code:
void __fastcall __noreturn main(int a1, char **a2, char **a3)
{
__int64 v3; // rdx
__int64 v4; // rax
struct tm *v5; // rax

stream = fopen("/proc/stat", "r");
__isoc99_fscanf();
fclose(stream);
if ( a2[1] )
func6(*a2);
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_18:
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);
v5 = localtime(&timer);
strftime(s, 0x26uLL, "%H.%M | %A, %d %B %Y", v5);
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
{
v3 = qword_404150 + qword_404158 + qword_404160 - qword_404140 - qword_404138 - qword_404130;
v4 = 100 * v3 / (v3 + qword_404148 - qword_404128);
dword_404124 = v4;
if ( (int)v4 > 90 )
{
putchar(108);
goto LABEL_17;
}
if ( (int)v4 > 66 )
{
putchar(105);
goto LABEL_17;
}
if ( (int)v4 > 33 )
{
putchar(58);
LABEL_17:
printf(" | ");
goto LABEL_18;
}
}
putchar(46);
goto LABEL_17;
}

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:
float __fastcall vectGetLength(float *a1)
{
float v1; // xmm0_4
float result; // xmm0_4

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

canonical_decompiled_code:
float __fastcall func3(float *a1)
{
float v1; // xmm0_4
float result; // xmm0_4

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

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
char *v4; // r12
unsigned int v5; // ebp
unsigned int i; // ebx
char s[256]; // [rsp+10h] [rbp-1E8h] BYREF
__m128i v9[2]; // [rsp+110h] [rbp-E8h] BYREF
float v10[3]; // [rsp+130h] [rbp-C8h] BYREF
float v11[11]; // [rsp+13Ch] [rbp-BCh] BYREF
int *v12; // [rsp+168h] [rbp-90h]
float v13[3]; // [rsp+174h] [rbp-84h] BYREF
int v14[4]; // [rsp+180h] [rbp-78h] BYREF
__int64 v15; // [rsp+190h] [rbp-68h]
float v16[9]; // [rsp+1D4h] [rbp-24h] BYREF

vectSetZero(v16);
*(float *)&v3 = vectGetLength(v16);
printf("%f\n", v3);
if ( (float)abs((int)"%f\n") > 0.0 )
puts("aaa");
v4 = (char *)malloc(0x400uLL);
vectSetValue(v13, 1.0, 1.0, 1.0);
v11[5] = 0.0;
v11[9] = 0.0;
vectSetValue(v10, 0.0, 15.0, 5.0);
vectSetValue(v11, 0.0, 0.0, 0.0);
vectSetValue((float *)v9, 20.0, 0.0, 20.0);
lightSetColor((__int64)v9, "White");
povAddLight((__int64)v10, v9);
vectSetValue((float *)v9, -20.0, 0.0, 20.0);
lightSetColor((__int64)v9, "White");
povAddLight((__int64)v10, v9);
vectSetValue((float *)v9, 0.0, -20.0, 20.0);
lightSetColor((__int64)v9, "White");
povAddLight((__int64)v10, v9);
vectSetValue((float *)v9, 0.0, 20.0, 20.0);
lightSetColor((__int64)v9, "White");
povAddLight((__int64)v10, v9);
povAddInclude((__int64)v10, "colors");
InitDemonGranOneNor(v14);
v12 = v14;
v5 = (int)(0.04 / *(float *)v14);
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);
for ( i = 0; i != 9000; ++i )
{
if ( !(i % v5) )
{
sprintf(v4, "out/%s/pov/%03u.pov", "gran-one-nor", i / v5);
if ( !(unsigned int)povSave((__int64)v10, v4) )
{
printf("Can't open file: %s\n", v4);
return -1;
}
}
printf("%04u:", i);
GranularPrint(v15);
ComputeForce(v14);
TimeIntergration(v14);
}
FreeDemon(v14);
free(v4);
povFree((__int64)v10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
char *v4; // r12
unsigned int v5; // ebp
unsigned int i; // ebx
char s[256]; // [rsp+10h] [rbp-1E8h] BYREF
__m128i v9[2]; // [rsp+110h] [rbp-E8h] BYREF
float v10[3]; // [rsp+130h] [rbp-C8h] BYREF
float v11[11]; // [rsp+13Ch] [rbp-BCh] BYREF
int *v12; // [rsp+168h] [rbp-90h]
float v13[3]; // [rsp+174h] [rbp-84h] BYREF
int v14[4]; // [rsp+180h] [rbp-78h] BYREF
__int64 v15; // [rsp+190h] [rbp-68h]
float v16[9]; // [rsp+1D4h] [rbp-24h] BYREF

func0(v16);
*(float *)&v3 = func3(v16);
printf("%f\n", v3);
if ( (float)abs((int)"%f\n") > 0.0 )
puts("aaa");
v4 = (char *)malloc(0x400uLL);
func1(v13, 1.0, 1.0, 1.0);
v11[5] = 0.0;
v11[9] = 0.0;
func1(v10, 0.0, 15.0, 5.0);
func1(v11, 0.0, 0.0, 0.0);
func1((float *)v9, 20.0, 0.0, 20.0);
func4((__int64)v9, "White");
povAddLight((__int64)v10, v9);
func1((float *)v9, -20.0, 0.0, 20.0);
func4((__int64)v9, "White");
povAddLight((__int64)v10, v9);
func1((float *)v9, 0.0, -20.0, 20.0);
func4((__int64)v9, "White");
povAddLight((__int64)v10, v9);
func1((float *)v9, 0.0, 20.0, 20.0);
func4((__int64)v9, "White");
povAddLight((__int64)v10, v9);
func5((__int64)v10, "colors");
InitDemonGranOneNor(v14);
v12 = v14;
v5 = (int)(0.04 / *(float *)v14);
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);
for ( i = 0; i != 9000; ++i )
{
if ( !(i % v5) )
{
sprintf(v4, "out/%s/pov/%03u.pov", "gran-one-nor", i / v5);
if ( !(unsigned int)func9((__int64)v10, v4) )
{
printf("Can't open file: %s\n", v4);
return -1;
}
}
printf("%04u:", i);
GranularPrint(v15);
ComputeForce(v14);
TimeIntergration(v14);
}
FreeDemon(v14);
free(v4);
func2((__int64)v10);
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

decompiled_code:
_BOOL8 __fastcall IsBuiltIn(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "bg") )
{
v1 = 1;
if ( strcmp(a1, "fg") )
{
v1 = 1;
if ( strcmp(a1, "jobs") )
v1 = strcmp(a1, "cd") == 0;
}
}
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "bg") )
{
v1 = 1;
if ( strcmp(a1, "fg") )
{
v1 = 1;
if ( strcmp(a1, "jobs") )
v1 = strcmp(a1, "cd") == 0;
}
}
return v1;
}

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


RunBuiltInCmd

decompiled_code:
int __fastcall RunBuiltInCmd(__int64 a1)
{
_QWORD *v1; // rax
const char *v2; // r8
__pid_t *v3; // rbp
__int64 v4; // rbx
int v5; // edx
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // rdx
int v9; // edi
__int64 v10; // rax
__int64 i; // rbx
int v12; // eax
const char *v13; // rbp
__uid_t v14; // eax
struct passwd *v15; // rax

LODWORD(v1) = a1;
v2 = *(const char **)(a1 + 48);
if ( !strcmp(v2, "bg") )
{
v3 = (__pid_t *)bgjobs;
if ( bgjobs )
{
v4 = *(_QWORD *)(bgjobs + 24);
if ( v4 )
{
if ( *(_DWORD *)(a1 + 44) == 1 )
{
v6 = *(_QWORD *)(bgjobs + 24);
do
{
v7 = v6;
v6 = *(_QWORD *)(v6 + 24);
}
while ( v6 );
v5 = *(_DWORD *)(v7 + 8);
}
else
{
v5 = atoi(*(const char **)(a1 + 56));
}
while ( 1 )
{
if ( v3[2] == v5 )
{
v3[1] = 1;
goto LABEL_16;
}
v3 = (__pid_t *)v4;
if ( !*(_QWORD *)(v4 + 24) )
break;
v4 = *(_QWORD *)(v4 + 24);
}
if ( *(_DWORD *)(v4 + 8) != v5 )
{
puts("job not found[bg]");
LODWORD(v1) = fflush(stdout);
return (int)v1;
}
LABEL_16:
LODWORD(v1) = kill(*v3, 18);
v3[1] = 0;
}
}
}
else if ( !strcmp(v2, "fg") )
{
if ( bgjobs )
{
v8 = *(_QWORD *)(bgjobs + 24);
if ( v8 )
{
if ( *(_DWORD *)(a1 + 44) == 1 )
{
do
{
v10 = v8;
v8 = *(_QWORD *)(v8 + 24);
}
while ( v8 );
v9 = *(_DWORD *)(v10 + 8);
}
else
{
v9 = atoi(*(const char **)(a1 + 56));
}
v1 = (_QWORD *)PopBGJob(v9);
if ( v1 )
{
fg_job = *(_DWORD *)v1;
fgCmd = (void *)v1[2];
free(v1);
kill(-fg_job, 18);
LODWORD(v1) = waitfg();
}
}
}
}
else if ( !strcmp(*(const char **)(a1 + 8), "jobs") )
{
LODWORD(v1) = bgjobs;
if ( bgjobs )
{
for ( i = *(_QWORD *)(bgjobs + 24); i; i = *(_QWORD *)(i + 24) )
{
v12 = *(_DWORD *)(i + 4);
if ( v12 )
{
if ( v12 == 1 )
{
printf("[%d] %s %s\n", *(unsigned int *)(i + 8), "Stopped", *(const char **)(i + 16));
}
else if ( v12 == 2 )
{
printf("[%d] %s %s\n", *(unsigned int *)(i + 8), "Done", *(const char **)(i + 16));
}
}
else
{
v13 = *(const char **)(i + 16);
if ( v13[strlen(v13) - 1] == 32 )
printf("[%d] %s %s&\n", *(unsigned int *)(i + 8), "Running", v13);
else
printf("[%d] %s %s &\n", *(unsigned int *)(i + 8), "Running", v13);
}
LODWORD(v1) = fflush(stdout);
}
}
}
else if ( !strcmp(v2, "cd") )
{
if ( *(_DWORD *)(a1 + 44) == 1 )
{
v14 = getuid();
v15 = getpwuid(v14);
LODWORD(v1) = chdir(v15->pw_dir);
}
else
{
LODWORD(v1) = chdir(*(const char **)(a1 + 56));
}
if ( (int)v1 < 0 )
LODWORD(v1) = fwrite("cd error\n", 1uLL, 9uLL, stderr);
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
_QWORD *v1; // rax
const char *v2; // r8
__pid_t *v3; // rbp
__int64 v4; // rbx
int v5; // edx
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // rdx
int v9; // edi
__int64 v10; // rax
__int64 i; // rbx
int v12; // eax
const char *v13; // rbp
__uid_t v14; // eax
struct passwd *v15; // rax

LODWORD(v1) = a1;
v2 = *(const char **)(a1 + 48);
if ( !strcmp(v2, "bg") )
{
v3 = (__pid_t *)bgjobs;
if ( bgjobs )
{
v4 = *(_QWORD *)(bgjobs + 24);
if ( v4 )
{
if ( *(_DWORD *)(a1 + 44) == 1 )
{
v6 = *(_QWORD *)(bgjobs + 24);
do
{
v7 = v6;
v6 = *(_QWORD *)(v6 + 24);
}
while ( v6 );
v5 = *(_DWORD *)(v7 + 8);
}
else
{
v5 = atoi(*(const char **)(a1 + 56));
}
while ( 1 )
{
if ( v3[2] == v5 )
{
v3[1] = 1;
goto LABEL_16;
}
v3 = (__pid_t *)v4;
if ( !*(_QWORD *)(v4 + 24) )
break;
v4 = *(_QWORD *)(v4 + 24);
}
if ( *(_DWORD *)(v4 + 8) != v5 )
{
puts("job not found[bg]");
LODWORD(v1) = fflush(stdout);
return (int)v1;
}
LABEL_16:
LODWORD(v1) = kill(*v3, 18);
v3[1] = 0;
}
}
}
else if ( !strcmp(v2, "fg") )
{
if ( bgjobs )
{
v8 = *(_QWORD *)(bgjobs + 24);
if ( v8 )
{
if ( *(_DWORD *)(a1 + 44) == 1 )
{
do
{
v10 = v8;
v8 = *(_QWORD *)(v8 + 24);
}
while ( v8 );
v9 = *(_DWORD *)(v10 + 8);
}
else
{
v9 = atoi(*(const char **)(a1 + 56));
}
v1 = (_QWORD *)func0(v9);
if ( v1 )
{
fg_job = *(_DWORD *)v1;
fgCmd = (void *)v1[2];
free(v1);
kill(-fg_job, 18);
LODWORD(v1) = func2();
}
}
}
}
else if ( !strcmp(*(const char **)(a1 + 8), "jobs") )
{
LODWORD(v1) = bgjobs;
if ( bgjobs )
{
for ( i = *(_QWORD *)(bgjobs + 24); i; i = *(_QWORD *)(i + 24) )
{
v12 = *(_DWORD *)(i + 4);
if ( v12 )
{
if ( v12 == 1 )
{
printf("[%d] %s %s\n", *(unsigned int *)(i + 8), "Stopped", *(const char **)(i + 16));
}
else if ( v12 == 2 )
{
printf("[%d] %s %s\n", *(unsigned int *)(i + 8), "Done", *(const char **)(i + 16));
}
}
else
{
v13 = *(const char **)(i + 16);
if ( v13[strlen(v13) - 1] == 32 )
printf("[%d] %s %s&\n", *(unsigned int *)(i + 8), "Running", v13);
else
printf("[%d] %s %s &\n", *(unsigned int *)(i + 8), "Running", v13);
}
LODWORD(v1) = fflush(stdout);
}
}
}
else if ( !strcmp(v2, "cd") )
{
if ( *(_DWORD *)(a1 + 44) == 1 )
{
v14 = getuid();
v15 = getpwuid(v14);
LODWORD(v1) = chdir(v15->pw_dir);
}
else
{
LODWORD(v1) = chdir(*(const char **)(a1 + 56));
}
if ( (int)v1 < 0 )
LODWORD(v1) = fwrite("cd error\n", 1uLL, 9uLL, stderr);
}
return (int)v1;
}

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: struct command_t { char *name; char *cmdline; char *redirect_in; int is_redirect_in; int bg; int argc; char *argv[]; } *

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: enum status { RUNNING=0, STOPPED=1, DONE=2 }


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:
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]; }

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


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 v3; // ebx
__pid_t result; // eax
int fd; // [rsp+0h] [rbp-38h] BYREF
int v6; // [rsp+4h] [rbp-34h]
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

if ( a2 <= 0 )
{
LABEL_5:
pipe(pipedes);
pipe(&fd);
v3 = fork();
close(fd);
close(v6);
if ( !v3 )
{
close(pipedes[0]);
dup2(pipedes[1], 1);
execv(**a1, (char *const *)*a1 + 6);
}
close(pipedes[1]);
wait(0LL);
if ( !fork() )
{
close(fd);
dup2(pipedes[0], 0);
dup2(v6, 1);
execv(*a1[1], (char *const *)a1[1] + 6);
}
close(pipedes[0]);
close(v6);
if ( !fork() )
{
dup2(fd, 0);
execv(*a1[2], (char *const *)a1[2] + 6);
}
close(fd);
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_5;
}
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 v3; // ebx
__pid_t result; // eax
int fd; // [rsp+0h] [rbp-38h] BYREF
int v6; // [rsp+4h] [rbp-34h]
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

if ( a2 <= 0 )
{
LABEL_5:
pipe(pipedes);
pipe(&fd);
v3 = fork();
close(fd);
close(v6);
if ( !v3 )
{
close(pipedes[0]);
dup2(pipedes[1], 1);
execv(**a1, (char *const *)*a1 + 6);
}
close(pipedes[1]);
wait(0LL);
if ( !fork() )
{
close(fd);
dup2(pipedes[0], 0);
dup2(v6, 1);
execv(*a1[1], (char *const *)a1[1] + 6);
}
close(pipedes[0]);
close(v6);
if ( !fork() )
{
dup2(fd, 0);
execv(*a1[2], (char *const *)a1[2] + 6);
}
close(fd);
wait(0LL);
result = wait(0LL);
}
else
{
v2 = (__int64 *)a1;
while ( (unsigned __int16)func4(*v2) )
{
if ( ++v2 == (__int64 *)&a1[(unsigned int)(a2 - 1) + 1] )
goto LABEL_5;
}
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
__int64 result; // rax

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

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

v1 = bgjobs;
if ( bgjobs )
{
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
*(_QWORD *)(v2 + 24) = a1;
result = (unsigned int)(*(_DWORD *)(v2 + 8) + 1);
*(_DWORD *)(a1 + 8) = result;
}
else
{
bgjobs = (__int64)malloc(0x20uLL);
*(_QWORD *)(bgjobs + 24) = a1;
*(_DWORD *)(a1 + 8) = 1;
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; // rbx
int v5; // eax
int v6; // er12
int v7; // er13
int v8; // er14
int v9; // eax
int v10; // ebp
int v11; // eax
_DWORD *v12; // r12
const char *v13; // rbp
int v14; // eax
char *v15; // rbx

if ( a2 )
{
v2 = fork();
v3 = v2;
if ( v2 < 0 )
{
fwrite("fork() failed at Exec().\n", 1uLL, 0x19uLL, stderr);
return;
}
if ( !v2 )
{
setpgid(0, 0);
v6 = -1;
v7 = -1;
if ( *(_DWORD *)(a1 + 36) )
{
v7 = dup(1);
v11 = open(*(const char **)(a1 + 24), 66, 420LL);
v6 = v11;
if ( v11 == -1 )
{
fprintf(stderr, "create file %s failed\n.", *(const char **)(a1 + 24));
return;
}
dup2(v11, 1);
}
if ( *(_DWORD *)(a1 + 32) )
{
v8 = dup(0);
v9 = open(*(const char **)(a1 + 16), 0, 420LL);
v10 = v9;
if ( v9 == -1 )
{
fprintf(stderr, "create file %s failed\n.", *(const char **)(a1 + 16));
return;
}
dup2(v9, 0);
}
else
{
v10 = -1;
v8 = -1;
}
execv(*(const char **)a1, (char *const *)(a1 + 48));
if ( *(_DWORD *)(a1 + 36) )
{
dup2(v7, 1);
close(v6);
close(v7);
}
if ( *(_DWORD *)(a1 + 32) )
{
dup2(v8, 0);
close(v10);
close(v8);
}
fflush(stdout);
exit(0);
}
if ( *(_DWORD *)(a1 + 40) == 1 )
{
v12 = malloc(0x20uLL);
*v12 = v3;
v12[1] = 0;
v13 = *(const char **)(a1 + 8);
v14 = strlen(v13);
v15 = (char *)malloc(v14 + 1);
strcpy(v15, v13);
*((_QWORD *)v12 + 2) = v15;
*((_QWORD *)v12 + 3) = 0LL;
AddToBgJobs((__int64)v12);
}
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();
}
}
}

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

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

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);
}


RunExternalCmd

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

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

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

v2 = a1;
if ( (unsigned __int16)func4((__int64)a1) )
{
func10((__int64)v2, a2);
}
else
{
printf("%s: command not found\n", (const char *)v2[6]);
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)
{
void ***v2; // rbx

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

canonical_decompiled_code:
void __fastcall func15(__int64 *a1, int a2)
{
void ***v2; // rbx

total_task = a2;
if ( a2 == 1 )
{
func14(*a1, 1);
}
else
{
func6((const char ***)a1, a2);
if ( a2 > 0 )
{
v2 = (void ***)a1;
do
func12(v2++);
while ( v2 != (void ***)&a1[(unsigned int)(a2 - 1) + 1] );
}
}
}

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

variable_types: i 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)
{
_QWORD *v1; // rax
unsigned int v2; // 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);
v1[2] = fgCmd;
*(_DWORD *)v1 = fg_job;
*((_DWORD *)v1 + 1) = 1;
v2 = AddToBgJobs();
printf("[%d] %s %s\n", v2, "Stopped", fgCmd);
fg_job = 0;
fgCmd = 0LL;
}
break;
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
_QWORD *v1; // rax
unsigned int v2; // 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);
v1[2] = fgCmd;
*(_DWORD *)v1 = fg_job;
*((_DWORD *)v1 + 1) = 1;
v2 = AddToBgJobs();
printf("[%d] %s %s\n", v2, "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)
{
void **v3; // rbx
void **v4; // 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);
if ( !strcmp((const char *)ptr, "exit") )
break;
CheckJobs();
Interpret(ptr);
if ( forceExit )
goto LABEL_14;
}
forceExit = 1;
}
LABEL_14:
v3 = (void **)bgjobs;
if ( bgjobs )
{
do
{
v4 = v3;
v3 = (void **)v3[3];
free(v4[2]);
free(v4);
}
while ( v3 );
}
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+0h] [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+0h] [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;
 }