decompiled_code:
char *__fastcall tolower_str(void *src)
{
size_t v1; // rbx
char *v2; // r12
const __int32_t *v3; // rsi
char *v4; // rax
__int64 v5; // rdx

v1 = strlen((const char *)src);
v2 = (char *)calloc((int)v1 + 1, 1uLL);
memcpy(v2, src, v1 + 1);
if ( (int)v1 > 0 )
{
v3 = *_ctype_tolower_loc();
v4 = v2;
do
{
v5 = *v4++;
*(v4 - 1) = v3[v5];
}
while ( &v2[(unsigned int)(v1 - 1) + 1] != v4 );
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func8(void *src)
{
size_t v1; // rbx
char *v2; // r12
const __int32_t *v3; // rsi
char *v4; // rax
__int64 v5; // rdx

v1 = strlen((const char *)src);
v2 = (char *)calloc((int)v1 + 1, 1uLL);
memcpy(v2, src, v1 + 1);
if ( (int)v1 > 0 )
{
v3 = *_ctype_tolower_loc();
v4 = v2;
do
{
v5 = *v4++;
*(v4 - 1) = v3[v5];
}
while ( &v2[(unsigned int)(v1 - 1) + 1] != v4 );
}
return v2;
}

original_code:
char *tolower_str (char *string) {
   int len = strlen (string);
   char *lstring = calloc (len+1, sizeof (char));
   strcpy (lstring, string);
   for (int itor = 0; itor < len; ++itor) {
      lstring[itor] = tolower (lstring[itor]);
   }
   return lstring;
}

canonical_original_code:
char *tolower_str(char *string) {
   int len = strlen (string);
   char *lstring = calloc (len+1, sizeof (char));
   strcpy (lstring, string);
   for (int itor = 0; itor < len; ++itor) {
      lstring[itor] = tolower (lstring[itor]);
   }
   return lstring;
}

variable_types:
string
char *

variable_types: len int

variable_types:
lstring
char *

variable_types: itor int


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

result = malloc(0x20uLL);
if ( !result )
_assert_fail("new != NULL", "slist.c", 0x80u, "new_slist");
*result = "struct st_slist";
result[2] = 0LL;
*((_DWORD *)result + 2) = 0;
result[3] = 0LL;
return result;
}

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

result = malloc(0x20uLL);
if ( !result )
_assert_fail("new != NULL", "slist.c", 0x80u, "new_slist");
*result = "struct st_slist";
result[2] = 0LL;
*((_DWORD *)result + 2) = 0;
result[3] = 0LL;
return result;
}

original_code:
slist_ref new_slist (void) {
   slist_ref new = malloc (sizeof (struct st_slist));
   ((void) sizeof ((new != ((void *)0)) ? 1 : 0), __extension__ ({ if (new != ((void *)0)) ; else __assert_fail ("new != NULL", "slist.c", 128, __extension__ __PRETTY_FUNCTION__); }));
   new->tag = slist_tag;
   new->head = ((void *)0);
   new->blkct = 0;
   new->stack_top = ((void *)0);
   return new;
}

canonical_original_code:
struct st_slist *new_slist() {
   struct st_slist *new = malloc (sizeof (struct st_slist));
   ((void) sizeof ((new != ((void *)0)) ? 1 : 0), __extension__ ({ if (new != ((void *)0)) ; else __assert_fail ("new != NULL", "slist.c", 128, __extension__ __PRETTY_FUNCTION__); }));
   new->tag = slist_tag;
   new->head = ((void *)0);
   new->blkct = 0;
   new->stack_top = ((void *)0);
   return new;
}

variable_types: struct st_slist { char *tag; int blkct; struct st_node { char *tag; char *permissions; char *uid; char *gid; char *mtime; char *fname; char *lfname; int blocks; int hlinks; int size; struct st_node *link; struct st_node *slink; } *head; struct st_node *stack_top; } *

user_defined_types: struct st_slist { char *tag; int blkct; struct st_node *head; struct st_node *stack_top; }


decompiled_code:
char __fastcall insert_slist(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
const char *v3; // r12
__int64 v4; // rbp
int v5; // eax

if ( !is_slist((_QWORD *)a1) || !is_slistnode((_QWORD *)a2) )
_assert_fail("is_slist (slist) && is_slistnode (newnode)", "slist.c", 0x8Au, "insert_slist");
v2 = *(_QWORD *)(a1 + 16);
if ( v2 )
{
v3 = *(const char **)(a2 + 48);
v4 = 0LL;
while ( strcmp(*(const char **)(v2 + 48), v3) <= 0 )
{
v4 = v2;
if ( !*(_QWORD *)(v2 + 72) )
{
*(_QWORD *)(a2 + 72) = 0LL;
goto LABEL_14;
}
v2 = *(_QWORD *)(v2 + 72);
}
*(_QWORD *)(a2 + 72) = v2;
if ( !v4 )
goto LABEL_9;
LABEL_14:
*(_QWORD *)(v4 + 72) = a2;
}
else
{
*(_QWORD *)(a2 + 72) = 0LL;
LABEL_9:
*(_QWORD *)(a1 + 16) = a2;
}
LOBYTE(v5) = is_hidden((_QWORD *)a2);
if ( !(_BYTE)v5 )
{
v5 = *(_DWORD *)(a2 + 56);
*(_DWORD *)(a1 + 8) += v5;
}
return v5;
}

original_code:
void insert_slist (slist_ref slist, slist_node newnode) {
   ((void) sizeof ((is_slist (slist) && is_slistnode (newnode)) ? 1 : 0), __extension__ ({ if (is_slist (slist) && is_slistnode (newnode)) ; else __assert_fail ("is_slist (slist) && is_slistnode (newnode)", "slist.c", 138, __extension__ __PRETTY_FUNCTION__); }));
   slist_node prev = ((void *)0);
   slist_node curr = slist->head;
   while (curr != ((void *)0)) {
      if (strcmp (curr->lfname, newnode->lfname) > 0) break;
      prev = curr;
      curr = curr->link;
   }
   newnode->link = curr;
   if (prev == ((void *)0)) slist->head = newnode;
                else prev->link = newnode;
   if (!is_hidden (newnode)) slist->blkct += newnode->blocks;
}

canonical_original_code:
void insert_slist(struct st_slist *slist, struct st_node *newnode) {
   ((void) sizeof ((is_slist (slist) && is_slistnode (newnode)) ? 1 : 0), __extension__ ({ if (is_slist (slist) && is_slistnode (newnode)) ; else __assert_fail ("is_slist (slist) && is_slistnode (newnode)", "slist.c", 138, __extension__ __PRETTY_FUNCTION__); }));
   struct st_node *prev = ((void *)0);
   struct st_node *curr = slist->head;
   while (curr != ((void *)0)) {
      if (strcmp (curr->lfname, newnode->lfname) > 0) break;
      prev = curr;
      curr = curr->link;
   }
   newnode->link = curr;
   if (prev == ((void *)0)) slist->head = newnode;
                else prev->link = newnode;
   if (!is_hidden (newnode)) slist->blkct += newnode->blocks;
}

variable_types:
newnode
struct st_node *

variable_types: struct st_node { char *tag; char *permissions; char *uid; char *gid; char *mtime; char *fname; char *lfname; int blocks; int hlinks; int size; struct st_node *link; struct st_node *slink; } *

return_type: void


decompiled_code:
bool __fastcall has_empty_dirstack(_QWORD *a1)
{
if ( !is_slist(a1) )
_assert_fail("is_slist (slist)", "slist.c", 0x9Cu, "has_empty_dirstack");
return a1[3] == 0LL;
}

canonical_decompiled_code:
bool __fastcall func11(_QWORD *a1)
{
if ( !func0(a1) )
_assert_fail("is_slist (slist)", "slist.c", 0x9Cu, "has_empty_dirstack");
return a1[3] == 0LL;
}

original_code:
_Bool has_empty_dirstack (slist_ref slist) {
   ((void) sizeof ((is_slist (slist)) ? 1 : 0), __extension__ ({ if (is_slist (slist)) ; else __assert_fail ("is_slist (slist)", "slist.c", 156, __extension__ __PRETTY_FUNCTION__); }));
   return slist->stack_top == ((void *)0);
}

canonical_original_code:
_Bool has_empty_dirstack(struct st_slist *slist) {
   ((void) sizeof ((is_slist (slist)) ? 1 : 0), __extension__ ({ if (is_slist (slist)) ; else __assert_fail ("is_slist (slist)", "slist.c", 156, __extension__ __PRETTY_FUNCTION__); }));
   return slist->stack_top == ((void *)0);
}

user_defined_types: struct st_node { char *tag; char *permissions; char *uid; char *gid; char *mtime; char *fname; char *lfname; int blocks; int hlinks; int size; struct st_node *link; struct st_node *slink; }


decompiled_code:
__int64 __fastcall pop_slistdir(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // r8

if ( !is_slist(a1) )
_assert_fail("is_slist (slist)", "slist.c", 0xA1u, "pop_slistdir");
if ( has_empty_dirstack(a1) )
_assert_fail("!has_empty_dirstack (slist)", "slist.c", 0xA2u, "pop_slistdir");
v1 = a1[3];
v2 = *(_QWORD *)(v1 + 40);
a1[3] = *(_QWORD *)(v1 + 80);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // r8

if ( !func0(a1) )
_assert_fail("is_slist (slist)", "slist.c", 0xA1u, "pop_slistdir");
if ( func11(a1) )
_assert_fail("!has_empty_dirstack (slist)", "slist.c", 0xA2u, "pop_slistdir");
v1 = a1[3];
v2 = *(_QWORD *)(v1 + 40);
a1[3] = *(_QWORD *)(v1 + 80);
return v2;
}

original_code:
char *pop_slistdir (slist_ref slist) {
   ((void) sizeof ((is_slist (slist)) ? 1 : 0), __extension__ ({ if (is_slist (slist)) ; else __assert_fail ("is_slist (slist)", "slist.c", 161, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((!has_empty_dirstack (slist)) ? 1 : 0), __extension__ ({ if (!has_empty_dirstack (slist)) ; else __assert_fail ("!has_empty_dirstack (slist)", "slist.c", 162, __extension__ __PRETTY_FUNCTION__); }));
   slist_node tmp = slist->stack_top;
   char *dir = tmp->fname;
   slist->stack_top = slist->stack_top->slink;
   return dir;
}

canonical_original_code:
char *pop_slistdir(struct st_slist *slist) {
   ((void) sizeof ((is_slist (slist)) ? 1 : 0), __extension__ ({ if (is_slist (slist)) ; else __assert_fail ("is_slist (slist)", "slist.c", 161, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((!has_empty_dirstack (slist)) ? 1 : 0), __extension__ ({ if (!has_empty_dirstack (slist)) ; else __assert_fail ("!has_empty_dirstack (slist)", "slist.c", 162, __extension__ __PRETTY_FUNCTION__); }));
   struct st_node *tmp = slist->stack_top;
   char *dir = tmp->fname;
   slist->stack_top = slist->stack_top->slink;
   return dir;
}

variable_types:
dir
char *

return_type: char *


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

if ( !is_slist(a1) )
_assert_fail("is_slist (slist)", "slist.c", 0xAAu, "push_slistdir");
if ( !is_slistnode(a2) )
_assert_fail("is_slistnode (node)", "slist.c", 0xABu, "push_slistdir");
result = *(_QWORD *)(v2 + 24);
a2[10] = result;
*(_QWORD *)(v2 + 24) = a2;
return result;
}

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

if ( !func0(a1) )
_assert_fail("is_slist (slist)", "slist.c", 0xAAu, "push_slistdir");
if ( !func1(a2) )
_assert_fail("is_slistnode (node)", "slist.c", 0xABu, "push_slistdir");
result = *(_QWORD *)(v2 + 24);
a2[10] = result;
*(_QWORD *)(v2 + 24) = a2;
return result;
}

original_code:
void push_slistdir (slist_ref slist, slist_node node) {
   ((void) sizeof ((is_slist (slist)) ? 1 : 0), __extension__ ({ if (is_slist (slist)) ; else __assert_fail ("is_slist (slist)", "slist.c", 170, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((is_slistnode (node)) ? 1 : 0), __extension__ ({ if (is_slistnode (node)) ; else __assert_fail ("is_slistnode (node)", "slist.c", 171, __extension__ __PRETTY_FUNCTION__); }));
   node->slink = slist->stack_top;
   slist->stack_top = node;
}

canonical_original_code:
void push_slistdir(struct st_slist *slist, struct st_node *node) {
   ((void) sizeof ((is_slist (slist)) ? 1 : 0), __extension__ ({ if (is_slist (slist)) ; else __assert_fail ("is_slist (slist)", "slist.c", 170, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((is_slistnode (node)) ? 1 : 0), __extension__ ({ if (is_slistnode (node)) ; else __assert_fail ("is_slistnode (node)", "slist.c", 171, __extension__ __PRETTY_FUNCTION__); }));
   node->slink = slist->stack_top;
   slist->stack_top = node;
}

variable_types:
node
struct st_node *


decompiled_code:
char __fastcall stack_slistdir(_QWORD *a1)
{
char result; // al
_QWORD *i; // rbx

result = is_slist(a1);
if ( !result )
_assert_fail("is_slist (slist)", "slist.c", 0xB2u, "stack_slistdir");
for ( i = (_QWORD *)a1[2]; i; i = (_QWORD *)i[9] )
{
while ( 1 )
{
result = is_dir((__int64)i);
if ( result )
break;
i = (_QWORD *)i[9];
if ( !i )
return result;
}
result = push_slistdir(a1, i);
}
return result;
}

canonical_decompiled_code:
char __fastcall func14(_QWORD *a1)
{
char result; // al
_QWORD *i; // rbx

result = func0(a1);
if ( !result )
_assert_fail("is_slist (slist)", "slist.c", 0xB2u, "stack_slistdir");
for ( i = (_QWORD *)a1[2]; i; i = (_QWORD *)i[9] )
{
while ( 1 )
{
result = func3((__int64)i);
if ( result )
break;
i = (_QWORD *)i[9];
if ( !i )
return result;
}
result = func13(a1, i);
}
return result;
}

original_code:
void stack_slistdir (slist_ref slist) {
   ((void) sizeof ((is_slist (slist)) ? 1 : 0), __extension__ ({ if (is_slist (slist)) ; else __assert_fail ("is_slist (slist)", "slist.c", 178, __extension__ __PRETTY_FUNCTION__); }));
   slist_node curr = slist->head;
   for (;;) {
      if (curr == ((void *)0)) break;
      if (is_dir (curr)) push_slistdir (slist, curr);
      curr = curr->link;
   }
}

canonical_original_code:
void stack_slistdir(struct st_slist *slist) {
   ((void) sizeof ((is_slist (slist)) ? 1 : 0), __extension__ ({ if (is_slist (slist)) ; else __assert_fail ("is_slist (slist)", "slist.c", 178, __extension__ __PRETTY_FUNCTION__); }));
   struct st_node *curr = slist->head;
   for (;;) {
      if (curr == ((void *)0)) break;
      if (is_dir (curr)) push_slistdir (slist, curr);
      curr = curr->link;
   }
}


decompiled_code:
void __fastcall free_slistnode(void *ptr)
{
if ( !is_slistnode(ptr) )
_assert_fail("is_slistnode (node)", "slist.c", 0xBDu, "free_slistnode");
free(*((void **)ptr + 1));
free(*((void **)ptr + 3));
free(*((void **)ptr + 2));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func15(void *ptr)
{
if ( !func1(ptr) )
_assert_fail("is_slistnode (node)", "slist.c", 0xBDu, "free_slistnode");
free(*((void **)ptr + 1));
free(*((void **)ptr + 3));
free(*((void **)ptr + 2));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(ptr);
}

original_code:
void free_slistnode (slist_node node) {
   ((void) sizeof ((is_slistnode (node)) ? 1 : 0), __extension__ ({ if (is_slistnode (node)) ; else __assert_fail ("is_slistnode (node)", "slist.c", 189, __extension__ __PRETTY_FUNCTION__); }));
   free (node->permissions);
   free (node->gid);
   free (node->uid);
   free (node->mtime);
   free (node->fname);
   free (node->lfname);
   free (node);
}

canonical_original_code:
void free_slistnode(struct st_node *node) {
   ((void) sizeof ((is_slistnode (node)) ? 1 : 0), __extension__ ({ if (is_slistnode (node)) ; else __assert_fail ("is_slistnode (node)", "slist.c", 189, __extension__ __PRETTY_FUNCTION__); }));
   free (node->permissions);
   free (node->gid);
   free (node->uid);
   free (node->mtime);
   free (node->fname);
   free (node->lfname);
   free (node);
}


decompiled_code:
void __fastcall free_slist(void *ptr)
{
_QWORD *i; // rdi

if ( !is_slist(ptr) )
_assert_fail("is_slist (slist)", "slist.c", 0xC8u, "free_slist");
for ( i = (_QWORD *)*((_QWORD *)ptr + 2); i; i = (_QWORD *)*((_QWORD *)ptr + 2) )
{
*((_QWORD *)ptr + 2) = i[9];
free_slistnode(i);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func16(void *ptr)
{
_QWORD *i; // rdi

if ( !func0(ptr) )
_assert_fail("is_slist (slist)", "slist.c", 0xC8u, "free_slist");
for ( i = (_QWORD *)*((_QWORD *)ptr + 2); i; i = (_QWORD *)*((_QWORD *)ptr + 2) )
{
*((_QWORD *)ptr + 2) = i[9];
func15(i);
}
free(ptr);
}

original_code:
void free_slist (slist_ref slist) {
   ((void) sizeof ((is_slist (slist)) ? 1 : 0), __extension__ ({ if (is_slist (slist)) ; else __assert_fail ("is_slist (slist)", "slist.c", 200, __extension__ __PRETTY_FUNCTION__); }));
   slist_node old = slist->head;
   for (;;) {
      if (old == ((void *)0)) break;
      slist->head = slist->head->link;
      free_slistnode (old);
      old = slist->head;
   }
   free (slist);
}

canonical_original_code:
void free_slist(struct st_slist *slist) {
   ((void) sizeof ((is_slist (slist)) ? 1 : 0), __extension__ ({ if (is_slist (slist)) ; else __assert_fail ("is_slist (slist)", "slist.c", 200, __extension__ __PRETTY_FUNCTION__); }));
   struct st_node *old = slist->head;
   for (;;) {
      if (old == ((void *)0)) break;
      slist->head = slist->head->link;
      free_slistnode (old);
      old = slist->head;
   }
   free (slist);
}


decompiled_code:
int __fastcall print_slist_long(__int64 a1)
{
int result; // eax
__int64 i; // rbx
int v3; // [rsp-10h] [rbp-18h]

result = printf("total %d\n", (unsigned int)(*(_DWORD *)(a1 + 8) / 2));
for ( i = *(_QWORD *)(a1 + 16); i; result = v3 )
{
printf(
"%s %2d %s %s %5d %s %s\n",
*(const char **)(i + 8),
*(unsigned int *)(i + 60),
*(const char **)(i + 16),
*(const char **)(i + 24),
*(unsigned int *)(i + 64),
*(const char **)(i + 32),
*(const char **)(i + 40));
i = *(_QWORD *)(i + 72);
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(__int64 a1)
{
int result; // eax
__int64 i; // rbx
int v3; // [rsp-10h] [rbp-18h]

result = printf("total %d\n", (unsigned int)(*(_DWORD *)(a1 + 8) / 2));
for ( i = *(_QWORD *)(a1 + 16); i; result = v3 )
{
printf(
"%s %2d %s %s %5d %s %s\n",
*(const char **)(i + 8),
*(unsigned int *)(i + 60),
*(const char **)(i + 16),
*(const char **)(i + 24),
*(unsigned int *)(i + 64),
*(const char **)(i + 32),
*(const char **)(i + 40));
i = *(_QWORD *)(i + 72);
}
return result;
}

original_code:
void print_slist_long (slist_ref slist) {
   printf ("total %d\n", slist->blkct/2);
   slist_node curr = slist->head;
   for (;;) {
      if (curr == ((void *)0)) break;
      printf ("%s %2d %s %s %5d %s %s\n",
              curr->permissions, curr->hlinks, curr->uid,
              curr->gid, curr->size, curr->mtime, curr->fname);
      curr = curr->link;
   }
}

canonical_original_code:
void print_slist_long(struct st_slist *slist) {
   printf ("total %d\n", slist->blkct/2);
   struct st_node *curr = slist->head;
   for (;;) {
      if (curr == ((void *)0)) break;
      printf ("%s %2d %s %s %5d %s %s\n",
              curr->permissions, curr->hlinks, curr->uid,
              curr->gid, curr->size, curr->mtime, curr->fname);
      curr = curr->link;
   }
}


decompiled_code:
int __fastcall print_slist_short(__int64 a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *(_QWORD *)(a1 + 16); i; i = *(_QWORD *)(i + 72) )
result = puts(*(const char **)(i + 40));
return result;
}

canonical_decompiled_code:
int __fastcall func18(__int64 a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *(_QWORD *)(a1 + 16); i; i = *(_QWORD *)(i + 72) )
result = puts(*(const char **)(i + 40));
return result;
}

original_code:
void print_slist_short (slist_ref slist) {
   slist_node curr = slist->head;
   for (;;) {
      if (curr == ((void *)0)) break;
      printf ("%s\n", curr->fname);
      curr = curr->link;
   }
}

canonical_original_code:
void print_slist_short(struct st_slist *slist) {
   struct st_node *curr = slist->head;
   for (;;) {
      if (curr == ((void *)0)) break;
      printf ("%s\n", curr->fname);
      curr = curr->link;
   }
}


decompiled_code:
int __fastcall print_error(const char *a1, const char *a2)
{
int result; // eax

fflush(0LL);
fprintf(stderr, "%s: %s: %s\n", (const char *)execname, a1, a2);
result = fflush(0LL);
exit_status = 1;
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, const char *a2)
{
int result; // eax

fflush(0LL);
fprintf(stderr, "%s: %s: %s\n", (const char *)execname, a1, a2);
result = fflush(0LL);
exit_status = 1;
return result;
}

original_code:
void print_error (char *object, char *message) {
   fflush (((void *)0));
   fprintf (stderr, "%s: %s: %s\n", execname, object, message);
   fflush (((void *)0));
   exit_status = 1;
}

canonical_original_code:
void print_error(char *object, char *message) {
   fflush (((void *)0));
   fprintf (stderr, "%s: %s: %s\n", execname, object, message);
   fflush (((void *)0));
   exit_status = 1;
}

variable_types:
object
char *

variable_types:
message
char *


catlist

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

va_start(arg, a2);
return vsprintf(a1, a2, arg);
}

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

va_start(arg, a2);
return vsprintf(a1, a2, arg);
}

original_code:
void catlist (char *buffer, char *format, ...) {
   va_list args;
   __builtin_va_start(args,format);
   vsprintf (buffer, format, args);
   __builtin_va_end(args);
}

canonical_original_code:
void catlist(char *buffer, char *format, ...) {
   __builtin_va_list args;
   __builtin_va_start(args,format);
   vsprintf (buffer, format, args);
   __builtin_va_end(args);
}

variable_types:
buffer
char *

variable_types:
format
char *


pathstr

original_code:
void pathstr (char *buffer, char *path, char *fname) {
   char *dirc = strdup (path);
   char *basec = strdup (path);
   char *dname = dirname (dirc);
   char *bname = __xpg_basename (basec);
   if (strcmp (dname, ".") == 0) {
      if (strcmp (bname, ".") == 0) {
         catlist (buffer, "%s/%s" , ".", fname);
      }else if (strcmp (bname, "..") == 0) {
         catlist (buffer, "%s/%s", "..", fname);
      }else {
         catlist (buffer, "%s/%s/%s", ".", bname, fname);
      }
   }
   else if (strcmp (dname, "/") == 0) {
      if (strcmp (bname, "/") == 0) {
         catlist (buffer, "/%s", fname);
      }else {
         catlist (buffer, "/%s/%s", bname, fname);
      }
   }
   else {
      catlist (buffer, "%s/%s/%s", dname, bname, fname);
   }
   free (dirc);
   free (basec);
}

canonical_original_code:
void pathstr(char *buffer, char *path, char *fname) {
   char *dirc = strdup (path);
   char *basec = strdup (path);
   char *dname = dirname (dirc);
   char *bname = __xpg_basename (basec);
   if (strcmp (dname, ".") == 0) {
      if (strcmp (bname, ".") == 0) {
         catlist (buffer, "%s/%s" , ".", fname);
      }else if (strcmp (bname, "..") == 0) {
         catlist (buffer, "%s/%s", "..", fname);
      }else {
         catlist (buffer, "%s/%s/%s", ".", bname, fname);
      }
   }
   else if (strcmp (dname, "/") == 0) {
      if (strcmp (bname, "/") == 0) {
         catlist (buffer, "/%s", fname);
      }else {
         catlist (buffer, "/%s/%s", bname, fname);
      }
   }
   else {
      catlist (buffer, "%s/%s/%s", dname, bname, fname);
   }
   free (dirc);
   free (basec);
}

variable_types:
path
char *

variable_types:
fname
char *

variable_types:
dirc
char *

variable_types:
basec
char *

variable_types:
dname
char *

variable_types:
bname
char *


decompiled_code:
__int64 __fastcall recursive_list(__int64 a1)
{
const char *v1; // rbp

stack = new_stack();
push_stack(stack, a1);
while ( 1 )
{
v1 = (const char *)pop_stack(stack);
printf("%s:\n", v1);
list(v1);
if ( (unsigned __int8)is_empty_stack(stack) )
break;
putchar(10);
}
return free_stack(stack);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
const char *v1; // rbp

stack = new_stack();
push_stack(stack, a1);
while ( 1 )
{
v1 = (const char *)pop_stack(stack);
printf("%s:\n", v1);
func6(v1);
if ( (unsigned __int8)is_empty_stack(stack) )
break;
putchar(10);
}
return free_stack(stack);
}

original_code:
void recursive_list (char *path) {
   stack = new_stack ();
   push_stack (stack, path);
   for (;;) {
      char *dir = pop_stack (stack);
      printf ("%s:\n", dir);
      list (dir);
      if (is_empty_stack (stack)) break;
      printf ("\n");
   }
   free_stack (stack);
}

canonical_original_code:
void recursive_list(char *path) {
   stack = new_stack ();
   push_stack (stack, path);
   for (;;) {
      char *dir = pop_stack (stack);
      printf ("%s:\n", dir);
      list (dir);
      if (is_empty_stack (stack)) break;
      printf ("\n");
   }
   free_stack (stack);
}


decompiled_code:
__int64 __fastcall set_options(int argc, char **argv)
{
int v3; // eax
__int64 result; // rax
void *v5; // rax
void *v6; // rdi
char v7[40]; // [rsp+0h] [rbp-28h] BYREF

opterr = 0;
while ( 1 )
{
v3 = getopt_long(argc, argv, "lR@:", &long_options_1, 0LL);
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'R':
*(&flags + 1) = 1;
break;
case 'l':
flags = 1;
break;
case '@':
set_debugflags(optarg);
break;
default:
sprintf(v7, "-%c", (unsigned int)optopt);
print_error(v7, "invalid option");
exit(exit_status);
}
}
result = (unsigned int)optind;
if ( optind < argc )
{
*((_DWORD *)&flags + 4) = argc - optind;
v5 = calloc(argc - (int)result, 8uLL);
*((_QWORD *)&flags + 1) = v5;
v6 = v5;
if ( !v5 )
_assert_fail("flags.pathname != NULL", "main.c", 0xC1u, "set_options");
result = optind;
if ( argc > optind )
result = (__int64)memcpy(v6, &argv[optind], 8LL * (unsigned int)(argc + ~optind) + 8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int argc, char **argv)
{
int v3; // eax
__int64 result; // rax
void *v5; // rax
void *v6; // rdi
char v7[40]; // [rsp+0h] [rbp-28h] BYREF

opterr = 0;
while ( 1 )
{
v3 = getopt_long(argc, argv, "lR@:", &long_options_1, 0LL);
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'R':
*(&flags + 1) = 1;
break;
case 'l':
flags = 1;
break;
case '@':
set_debugflags(optarg);
break;
default:
sprintf(v7, "-%c", (unsigned int)optopt);
func0(v7, "invalid option");
exit(exit_status);
}
}
result = (unsigned int)optind;
if ( optind < argc )
{
*((_DWORD *)&flags + 4) = argc - optind;
v5 = calloc(argc - (int)result, 8uLL);
*((_QWORD *)&flags + 1) = v5;
v6 = v5;
if ( !v5 )
_assert_fail("flags.pathname != NULL", "main.c", 0xC1u, "set_options");
result = optind;
if ( argc > optind )
result = (__int64)memcpy(v6, &argv[optind], 8LL * (unsigned int)(argc + ~optind) + 8);
}
return result;
}

original_code:
void set_options (int argc, char **argv) {
   static struct option long_options[] =
   {
      {"list", 0, ((void *)0), 'l'},
      {"recurse", 0, ((void *)0), 'R'},
      {"debug", 1, ((void *)0), '@'},
      {((void *)0), 0, ((void *)0), 0}
   };
   opterr = 0;
   for (;;) {
      int option = getopt_long (argc, argv, "lR@:", long_options, ((void *)0));
      if (option == (-1)) break;
      switch (option) {
         char optopt_str[16];
         case 'l': flags.long_listing = 1;
                   break;
         case 'R': flags.recursive = 1;
                   break;
         case '@': set_debugflags (optarg);
                   break;
         default : sprintf (optopt_str, "-%c", optopt);
                   print_error (optopt_str, "invalid option");
                   exit (exit_status);
      }
   }
   if (optind < argc) {
      flags.opct = argc - optind;
      flags.pathname = calloc (flags.opct, sizeof (char*));
      ((void) sizeof ((flags.pathname != ((void *)0)) ? 1 : 0), __extension__ ({ if (flags.pathname != ((void *)0)) ; else __assert_fail ("flags.pathname != NULL", "main.c", 193, __extension__ __PRETTY_FUNCTION__); }));
      for (int itor = optind; itor < argc; ++itor) {
         flags.pathname[itor - optind] = argv[itor];
      }
   }
}

canonical_original_code:
void set_options(int argc, char **argv) {
   static struct option long_options[] = {
      {"list", 0, ((void *)0), 'l'},
      {"recurse", 0, ((void *)0), 'R'},
      {"debug", 1, ((void *)0), '@'},
      {((void *)0), 0, ((void *)0), 0}
   };
   opterr = 0;
   for (;;) {
      int option = getopt_long (argc, argv, "lR@:", long_options, ((void *)0));
      if (option == (-1)) break;
      switch (option) {
         char optopt_str[16];
         case 'l': flags.long_listing = 1;
                   break;
         case 'R': flags.recursive = 1;
                   break;
         case '@': set_debugflags (optarg);
                   break;
         default : sprintf (optopt_str, "-%c", optopt);
                   print_error (optopt_str, "invalid option");
                   exit (exit_status);
      }
   }
   if (optind < argc) {
      flags.opct = argc - optind;
      flags.pathname = calloc (flags.opct, sizeof (char *));
      ((void) sizeof ((flags.pathname != ((void *)0)) ? 1 : 0), __extension__ ({ if (flags.pathname != ((void *)0)) ; else __assert_fail ("flags.pathname != NULL", "main.c", 193, __extension__ __PRETTY_FUNCTION__); }));
      for (int itor = optind; itor < argc; ++itor) {
         flags.pathname[itor - optind] = argv[itor];
      }
   }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: option int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // rbx
__int64 v5; // rdi
const char **v7; // rax
int v8; // edx
__int64 v9; // rbx
const char *v10; // rdi

execname = (__int64)_xpg_basename((char *)*argv);
set_execname(execname);
set_options(argc, (char **)argv);
if ( *(&flags + 1) )
{
v3 = *((_DWORD *)&flags + 4);
if ( v3 )
{
if ( v3 == 1 )
{
recursive_list(**((_QWORD **)&flags + 1));
}
else
{
v4 = 0LL;
if ( v3 > 0 )
{
do
{
v5 = *(_QWORD *)(*((_QWORD *)&flags + 1) + 8 * v4++);
recursive_list(v5);
putchar(10);
}
while ( *((_DWORD *)&flags + 4) > (int)v4 );
}
}
}
else
{
recursive_list((__int64)".");
}
}
else
{
v7 = (const char **)*((_QWORD *)&flags + 1);
if ( v7 )
{
v8 = *((_DWORD *)&flags + 4);
if ( v8 == 1 )
{
list(*v7);
}
else
{
v9 = 0LL;
if ( v8 > 0 )
{
while ( 1 )
{
v10 = v7[v9++];
list(v10);
putchar(10);
if ( *((_DWORD *)&flags + 4) <= (int)v9 )
break;
v7 = (const char **)*((_QWORD *)&flags + 1);
}
}
}
}
else
{
list(".");
}
}
return exit_status;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // rbx
__int64 v5; // rdi
const char **v7; // rax
int v8; // edx
__int64 v9; // rbx
const char *v10; // rdi

execname = (__int64)_xpg_basename((char *)*argv);
set_execname(execname);
func8(argc, (char **)argv);
if ( *(&flags + 1) )
{
v3 = *((_DWORD *)&flags + 4);
if ( v3 )
{
if ( v3 == 1 )
{
func7(**((_QWORD **)&flags + 1));
}
else
{
v4 = 0LL;
if ( v3 > 0 )
{
do
{
v5 = *(_QWORD *)(*((_QWORD *)&flags + 1) + 8 * v4++);
func7(v5);
putchar(10);
}
while ( *((_DWORD *)&flags + 4) > (int)v4 );
}
}
}
else
{
func7((__int64)".");
}
}
else
{
v7 = (const char **)*((_QWORD *)&flags + 1);
if ( v7 )
{
v8 = *((_DWORD *)&flags + 4);
if ( v8 == 1 )
{
func6(*v7);
}
else
{
v9 = 0LL;
if ( v8 > 0 )
{
while ( 1 )
{
v10 = v7[v9++];
func6(v10);
putchar(10);
if ( *((_DWORD *)&flags + 4) <= (int)v9 )
break;
v7 = (const char **)*((_QWORD *)&flags + 1);
}
}
}
}
else
{
func6(".");
}
}
return exit_status;
}

original_code:
int main (int argc, char **argv) {
   execname = __xpg_basename (argv[0]);
   set_execname (execname);
   set_options (argc, argv);
   if (flags.recursive == 1) {
      if (flags.opct == 0) { recursive_list ("."); }
      else if (flags.opct == 1) { recursive_list (flags.pathname[0]); }
      else {
         for (int ind = 0; ind < flags.opct; ++ind) {
            recursive_list (flags.pathname[ind]);
            printf ("\n");
         }
      }
   }else {
      if (flags.pathname == 0) { list ("."); }
      else if (flags.opct == 1) { list (flags.pathname[0]); }
      else {
         for (int ind = 0; ind < flags.opct; ++ind) {
            list (flags.pathname[ind]);
            printf ("\n");
         }
      }
   }
   return (exit_status);
}

canonical_original_code:
int main(int argc, char **argv) {
   execname = __xpg_basename (argv[0]);
   set_execname (execname);
   set_options (argc, argv);
   if (flags.recursive == 1) {
      if (flags.opct == 0) { recursive_list ("."); }
      else if (flags.opct == 1) { recursive_list (flags.pathname[0]); }
      else {
         for (int ind = 0; ind < flags.opct; ++ind) {
            recursive_list (flags.pathname[ind]);
            printf ("\n");
         }
      }
   }else {
      if (flags.pathname == 0) { list ("."); }
      else if (flags.opct == 1) { list (flags.pathname[0]); }
      else {
         for (int ind = 0; ind < flags.opct; ++ind) {
            list (flags.pathname[ind]);
            printf ("\n");
         }
      }
   }
   return (exit_status);
}

variable_types: ind int

return_type: int


decompiled_code:
bool __fastcall is_stack(_QWORD *a1)
{
bool result; // al

result = 0;
if ( a1 )
result = *a1 == (_QWORD)"struct st_stack";
return result;
}

canonical_decompiled_code:
bool __fastcall func0(_QWORD *a1)
{
bool result; // al

result = 0;
if ( a1 )
result = *a1 == (_QWORD)"struct st_stack";
return result;
}

original_code:
_Bool is_stack (stack_ref stack) {
   return stack != ((void *)0) && stack->tag == stack_tag;
}

canonical_original_code:
_Bool is_stack(struct st_stack *stack) {
   return stack != ((void *)0) && stack->tag == stack_tag;
}

variable_types: struct st_stack { char *tag; struct stacknode { char *dir; struct stacknode *link; } *top; } *

user_defined_types: struct st_stack { char *tag; struct stacknode *top; }


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

result = malloc(0x10uLL);
if ( !result )
_assert_fail("new != NULL", "dstack.c", 0x1Du, "new_stack");
*result = "struct st_stack";
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
if ( !result )
_assert_fail("new != NULL", "dstack.c", 0x1Du, "new_stack");
*result = "struct st_stack";
result[1] = 0LL;
return result;
}

original_code:
stack_ref new_stack (void) {
   stack_ref new = malloc (sizeof (struct st_stack));
   ((void) sizeof ((new != ((void *)0)) ? 1 : 0), __extension__ ({ if (new != ((void *)0)) ; else __assert_fail ("new != NULL", "dstack.c", 29, __extension__ __PRETTY_FUNCTION__); }));
   new->tag = stack_tag;
   new->top = ((void *)0);
   return new;
}

canonical_original_code:
struct st_stack *new_stack() {
   struct st_stack *new = malloc (sizeof (struct st_stack));
   ((void) sizeof ((new != ((void *)0)) ? 1 : 0), __extension__ ({ if (new != ((void *)0)) ; else __assert_fail ("new != NULL", "dstack.c", 29, __extension__ __PRETTY_FUNCTION__); }));
   new->tag = stack_tag;
   new->top = ((void *)0);
   return new;
}

return_type: struct st_stack { char *tag; struct stacknode { char *dir; struct stacknode *link; } *top; } *


decompiled_code:
void __fastcall free_stack(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp

if ( !is_stack(ptr) )
_assert_fail("is_stack (stack)", "dstack.c", 0x24u, "free_stack");
v1 = *((_QWORD *)ptr + 1);
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 8);
free(*v2);
free(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp

if ( !func0(ptr) )
_assert_fail("is_stack (stack)", "dstack.c", 0x24u, "free_stack");
v1 = *((_QWORD *)ptr + 1);
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 8);
free(*v2);
free(v2);
}
free(ptr);
}

original_code:
void free_stack (stack_ref stack) {
   ((void) sizeof ((is_stack (stack)) ? 1 : 0), __extension__ ({ if (is_stack (stack)) ; else __assert_fail ("is_stack (stack)", "dstack.c", 36, __extension__ __PRETTY_FUNCTION__); }));
   stack_node curr = stack->top;
   for (;;) {
      if (curr == ((void *)0)) break;
      stack_node old = curr;
      curr = curr->link;
      free (old->dir);
      free (old);
   }
   memset (stack, 0, sizeof (struct st_stack));
   free (stack);
}

canonical_original_code:
void free_stack(struct st_stack *stack) {
   ((void) sizeof ((is_stack (stack)) ? 1 : 0), __extension__ ({ if (is_stack (stack)) ; else __assert_fail ("is_stack (stack)", "dstack.c", 36, __extension__ __PRETTY_FUNCTION__); }));
   struct stacknode *curr = stack->top;
   for (;;) {
      if (curr == ((void *)0)) break;
      struct stacknode *old = curr;
      curr = curr->link;
      free (old->dir);
      free (old);
   }
   memset (stack, 0, sizeof (struct st_stack));
   free (stack);
}

variable_types: struct stacknode { char *dir; struct stacknode *link; } *


decompiled_code:
__int64 __fastcall push_stack(_QWORD *a1, const char *a2)
{
_QWORD *v2; // rbp
__int64 result; // rax

if ( !is_stack(a1) )
_assert_fail("is_stack (stack)", "dstack.c", 0x32u, "push_stack");
v2 = malloc(0x10uLL);
*v2 = strdup(a2);
result = a1[1];
a1[1] = v2;
v2[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, const char *a2)
{
_QWORD *v2; // rbp
__int64 result; // rax

if ( !func0(a1) )
_assert_fail("is_stack (stack)", "dstack.c", 0x32u, "push_stack");
v2 = malloc(0x10uLL);
*v2 = strdup(a2);
result = a1[1];
a1[1] = v2;
v2[1] = result;
return result;
}

original_code:
void push_stack (stack_ref stack, char *dir) {
   ((void) sizeof ((is_stack (stack)) ? 1 : 0), __extension__ ({ if (is_stack (stack)) ; else __assert_fail ("is_stack (stack)", "dstack.c", 50, __extension__ __PRETTY_FUNCTION__); }));
   stack_node new = malloc (sizeof (struct stacknode));
   new->dir = strdup (dir);
   new->link = stack->top;
   stack->top = new;
}

canonical_original_code:
void push_stack(struct st_stack *stack, char *dir) {
   ((void) sizeof ((is_stack (stack)) ? 1 : 0), __extension__ ({ if (is_stack (stack)) ; else __assert_fail ("is_stack (stack)", "dstack.c", 50, __extension__ __PRETTY_FUNCTION__); }));
   struct stacknode *new = malloc (sizeof (struct stacknode));
   new->dir = strdup (dir);
   new->link = stack->top;
   stack->top = new;
}

variable_types:
dir
char *

user_defined_types: struct stacknode { char *dir; struct stacknode *link; }


decompiled_code:
bool __fastcall is_empty_stack(_QWORD *a1)
{
if ( !is_stack(a1) )
_assert_fail("is_stack (stack)", "dstack.c", 0x42u, "is_empty_stack");
return a1[1] == 0LL;
}

canonical_decompiled_code:
bool __fastcall func4(_QWORD *a1)
{
if ( !func0(a1) )
_assert_fail("is_stack (stack)", "dstack.c", 0x42u, "is_empty_stack");
return a1[1] == 0LL;
}

original_code:
_Bool is_empty_stack (stack_ref stack) {
   ((void) sizeof ((is_stack (stack)) ? 1 : 0), __extension__ ({ if (is_stack (stack)) ; else __assert_fail ("is_stack (stack)", "dstack.c", 66, __extension__ __PRETTY_FUNCTION__); }));
   return stack->top == ((void *)0);
}

canonical_original_code:
_Bool is_empty_stack(struct st_stack *stack) {
   ((void) sizeof ((is_stack (stack)) ? 1 : 0), __extension__ ({ if (is_stack (stack)) ; else __assert_fail ("is_stack (stack)", "dstack.c", 66, __extension__ __PRETTY_FUNCTION__); }));
   return stack->top == ((void *)0);
}


decompiled_code:
__int64 __fastcall pop_stack(_QWORD *a1)
{
__int64 *v1; // rax
__int64 v2; // rdx
__int64 result; // rax

if ( !is_stack(a1) )
_assert_fail("is_stack (stack)", "dstack.c", 0x3Au, "pop_stack");
if ( is_empty_stack(a1) )
_assert_fail("! is_empty_stack (stack)", "dstack.c", 0x3Bu, "pop_stack");
v1 = (__int64 *)a1[1];
v2 = v1[1];
result = *v1;
a1[1] = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 *v1; // rax
__int64 v2; // rdx
__int64 result; // rax

if ( !func0(a1) )
_assert_fail("is_stack (stack)", "dstack.c", 0x3Au, "pop_stack");
if ( func4(a1) )
_assert_fail("! is_empty_stack (stack)", "dstack.c", 0x3Bu, "pop_stack");
v1 = (__int64 *)a1[1];
v2 = v1[1];
result = *v1;
a1[1] = v2;
return result;
}

original_code:
char *pop_stack (stack_ref stack) {
   ((void) sizeof ((is_stack (stack)) ? 1 : 0), __extension__ ({ if (is_stack (stack)) ; else __assert_fail ("is_stack (stack)", "dstack.c", 58, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((! is_empty_stack (stack)) ? 1 : 0), __extension__ ({ if (! is_empty_stack (stack)) ; else __assert_fail ("! is_empty_stack (stack)", "dstack.c", 59, __extension__ __PRETTY_FUNCTION__); }));
   stack_node tmp = stack->top;
   stack->top = stack->top->link;
   return tmp->dir;
}

canonical_original_code:
char *pop_stack(struct st_stack *stack) {
   ((void) sizeof ((is_stack (stack)) ? 1 : 0), __extension__ ({ if (is_stack (stack)) ; else __assert_fail ("is_stack (stack)", "dstack.c", 58, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((! is_empty_stack (stack)) ? 1 : 0), __extension__ ({ if (! is_empty_stack (stack)) ; else __assert_fail ("! is_empty_stack (stack)", "dstack.c", 59, __extension__ __PRETTY_FUNCTION__); }));
   struct stacknode *tmp = stack->top;
   stack->top = stack->top->link;
   return tmp->dir;
}


decompiled_code:
void __fastcall set_execname(__int64 a1)
{
execname = a1;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
execname = a1;
}

original_code: void set_execname (char *name) { execname = name; }

canonical_original_code: void set_execname(char *name) { execname = name; }

variable_types:
name
char *


decompiled_code:
int __fastcall set_debugflags(char *a1)
{
debugflags = a1;
if ( strchr(a1, 64) )
alldebugflags = 1;
return _debugprintf(97, "debugf.c", 0x24u, "Debugflags = \"%s\"\n", a1);
}

canonical_decompiled_code:
int __fastcall func4(char *a1)
{
debugflags = a1;
if ( strchr(a1, 64) )
alldebugflags = 1;
return func3(97, "debugf.c", 0x24u, "Debugflags = \"%s\"\n", a1);
}

original_code:
void set_debugflags (char *flags) {
   debugflags = flags;
   if (strchr (debugflags, '@') != ((void *)0)) alldebugflags = 1;
   __debugprintf ('a', "debugf.c", 36, "Debugflags = \"%s\"\n", debugflags);
}

canonical_original_code:
void set_debugflags(char *flags) {
   debugflags = flags;
   if (strchr (debugflags, '@') != ((void *)0)) alldebugflags = 1;
   __debugprintf ('a', "debugf.c", 36, "Debugflags = \"%s\"\n", debugflags);
}

variable_types:
flags
char *


decompiled_code:
_QWORD *new_cmdattr()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void *v2; // rax
void *v3; // rax
_QWORD *result; // rax

v0 = malloc(0x30uLL);
if ( !v0 )
_assert_fail("new != NULL", "main.c", 0x24u, "new_cmdattr");
*v0 = 0LL;
v1 = v0;
v2 = calloc(0x40uLL, 8uLL);
v1[1] = v2;
if ( !v2 )
_assert_fail("new->largs != NULL", "main.c", 0x27u, "new_cmdattr");
v1[2] = 0LL;
v3 = calloc(0x40uLL, 8uLL);
v1[3] = v3;
if ( !v3 )
_assert_fail("new->rargs != NULL", "main.c", 0x2Au, "new_cmdattr");
v1[4] = 0LL;
result = v1;
v1[5] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void *v2; // rax
void *v3; // rax
_QWORD *result; // rax

v0 = malloc(0x30uLL);
if ( !v0 )
_assert_fail("new != NULL", "main.c", 0x24u, "new_cmdattr");
*v0 = 0LL;
v1 = v0;
v2 = calloc(0x40uLL, 8uLL);
v1[1] = v2;
if ( !v2 )
_assert_fail("new->largs != NULL", "main.c", 0x27u, "new_cmdattr");
v1[2] = 0LL;
v3 = calloc(0x40uLL, 8uLL);
v1[3] = v3;
if ( !v3 )
_assert_fail("new->rargs != NULL", "main.c", 0x2Au, "new_cmdattr");
v1[4] = 0LL;
result = v1;
v1[5] = 0LL;
return result;
}

original_code:
cmdattr new_cmdattr (void) {
   cmdattr new = malloc (sizeof (struct cmd_attributes));
   ((void) sizeof ((new != ((void *)0)) ? 1 : 0), __extension__ ({ if (new != ((void *)0)) ; else __assert_fail ("new != NULL", "main.c", 36, __extension__ __PRETTY_FUNCTION__); }));
   new->lprog = ((void *)0);
   new->largs = calloc (64, sizeof (char*));
   ((void) sizeof ((new->largs != ((void *)0)) ? 1 : 0), __extension__ ({ if (new->largs != ((void *)0)) ; else __assert_fail ("new->largs != NULL", "main.c", 39, __extension__ __PRETTY_FUNCTION__); }));
   new->rprog = ((void *)0);
   new->rargs = calloc (64, sizeof (char*));
   ((void) sizeof ((new->rargs != ((void *)0)) ? 1 : 0), __extension__ ({ if (new->rargs != ((void *)0)) ; else __assert_fail ("new->rargs != NULL", "main.c", 42, __extension__ __PRETTY_FUNCTION__); }));
   new->input_r = ((void *)0);
   new->output_r = ((void *)0);
   return new;
}

canonical_original_code:
struct cmd_attributes *new_cmdattr() {
   struct cmd_attributes *new = malloc (sizeof (struct cmd_attributes));
   ((void) sizeof ((new != ((void *)0)) ? 1 : 0), __extension__ ({ if (new != ((void *)0)) ; else __assert_fail ("new != NULL", "main.c", 36, __extension__ __PRETTY_FUNCTION__); }));
   new->lprog = ((void *)0);
   new->largs = calloc (64, sizeof (char *));
   ((void) sizeof ((new->largs != ((void *)0)) ? 1 : 0), __extension__ ({ if (new->largs != ((void *)0)) ; else __assert_fail ("new->largs != NULL", "main.c", 39, __extension__ __PRETTY_FUNCTION__); }));
   new->rprog = ((void *)0);
   new->rargs = calloc (64, sizeof (char *));
   ((void) sizeof ((new->rargs != ((void *)0)) ? 1 : 0), __extension__ ({ if (new->rargs != ((void *)0)) ; else __assert_fail ("new->rargs != NULL", "main.c", 42, __extension__ __PRETTY_FUNCTION__); }));
   new->input_r = ((void *)0);
   new->output_r = ((void *)0);
   return new;
}

variable_types: struct cmd_attributes { char *lprog; char **largs; char *rprog; char **rargs; char *input_r; char *output_r; } *


decompiled_code:
void __fastcall free_cmdattr(void *ptr)
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
void free_cmdattr (cmdattr attr) {
   free (attr->largs);
   free (attr->rargs);
   free (attr);
}

canonical_original_code:
void free_cmdattr(struct cmd_attributes *attr) {
   free (attr->largs);
   free (attr->rargs);
   free (attr);
}

user_defined_types: struct cmd_attributes { char *lprog; char **largs; char *rprog; char **rargs; char *input_r; char *output_r; }


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

result = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL);
*(_QWORD *)(a2 + 40) = result;
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL);
*(_QWORD *)(a2 + 40) = result;
return result;
}

original_code:
void cmd_reout (cmdtree tree, cmdattr attr) {
   attr->output_r = tree->first->lexinfo;
}

canonical_original_code:
void cmd_reout(struct cmdtree_rep *tree, struct cmd_attributes *attr) {
   attr->output_r = tree->first->lexinfo;
}

variable_types: struct cmdtree_rep { char *tag; char *lexinfo; int symbol; struct cmdtree_rep *first; struct cmdtree_rep *last; struct cmdtree_rep *next; } *


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

result = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL);
*(_QWORD *)(a2 + 32) = result;
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL);
*(_QWORD *)(a2 + 32) = result;
return result;
}

original_code:
void cmd_rein (cmdtree tree, cmdattr attr) {
   attr->input_r = tree->first->lexinfo;
}

canonical_original_code:
void cmd_rein(struct cmdtree_rep *tree, struct cmd_attributes *attr) {
   attr->input_r = tree->first->lexinfo;
}

user_defined_types: struct cmdtree_rep { char *tag; char *lexinfo; int symbol; struct cmdtree_rep *first; struct cmdtree_rep *last; struct cmdtree_rep *next; }


decompiled_code:
int __fastcall set_output_redirect(__int64 a1)
{
int v1; // eax
int v2; // ebp
int v3; // edi
int v5; // eax
int v6; // eax
int v7; // eax

v1 = open(*(const char **)(a1 + 40), 577, 436LL);
if ( v1 < 0 )
{
syserrprintf(*(_QWORD *)(a1 + 40));
v5 = get_exitstatus();
exit(v5);
}
v2 = v1;
v3 = v1;
if ( close(1) < 0 )
{
close(v3);
syserrprintf("close(2)");
v7 = get_exitstatus();
exit(v7);
}
if ( dup(v3) != 1 )
{
close(v2);
syserrprintf("dup(2)");
v6 = get_exitstatus();
exit(v6);
}
return close(v2);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
int v1; // eax
int v2; // ebp
int v3; // edi
int v5; // eax
int v6; // eax
int v7; // eax

v1 = open(*(const char **)(a1 + 40), 577, 436LL);
if ( v1 < 0 )
{
syserrprintf(*(_QWORD *)(a1 + 40));
v5 = get_exitstatus();
exit(v5);
}
v2 = v1;
v3 = v1;
if ( close(1) < 0 )
{
close(v3);
syserrprintf("close(2)");
v7 = get_exitstatus();
exit(v7);
}
if ( dup(v3) != 1 )
{
close(v2);
syserrprintf("dup(2)");
v6 = get_exitstatus();
exit(v6);
}
return close(v2);
}

original_code:
void set_output_redirect (cmdattr attr) {
   int out_fd = -1;
   out_fd = open (attr->output_r, 01 | 0100 | 01000,
                  0400 | 0200 | (0400 >> 3) | (0200 >> 3) | ((0400 >> 3) >> 3));
   if (out_fd < 0) {
      syserrprintf (attr->output_r);
      exit (get_exitstatus ());
   }
   if (close (1) < 0) {
      close (out_fd);
      syserrprintf ("close(2)");
      exit (get_exitstatus ());
   }
   if (dup (out_fd) != 1) {
      close (out_fd);
      syserrprintf ("dup(2)");
      exit (get_exitstatus ());
   }
   close (out_fd);
}

canonical_original_code:
void set_output_redirect(struct cmd_attributes *attr) {
   int out_fd = -1;
   out_fd = open (attr->output_r, 01 | 0100 | 01000,
                  0400 | 0200 | (0400 >> 3) | (0200 >> 3) | ((0400 >> 3) >> 3));
   if (out_fd < 0) {
      syserrprintf (attr->output_r);
      exit (get_exitstatus ());
   }
   if (close (1) < 0) {
      close (out_fd);
      syserrprintf ("close(2)");
      exit (get_exitstatus ());
   }
   if (dup (out_fd) != 1) {
      close (out_fd);
      syserrprintf ("dup(2)");
      exit (get_exitstatus ());
   }
   close (out_fd);
}


decompiled_code:
int __fastcall set_input_redirect(__int64 a1)
{
int v1; // eax
int v2; // ebp
int v3; // edi
int v5; // eax
int v6; // eax
int v7; // eax

v1 = open(*(const char **)(a1 + 32), 0);
if ( v1 < 0 )
{
syserrprintf(*(_QWORD *)(a1 + 32));
v5 = get_exitstatus();
exit(v5);
}
v2 = v1;
v3 = v1;
if ( close(0) < 0 )
{
close(v3);
syserrprintf("close(2)");
v7 = get_exitstatus();
exit(v7);
}
if ( dup(v3) )
{
close(v2);
syserrprintf("dup(2)");
v6 = get_exitstatus();
exit(v6);
}
return close(v2);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
int v1; // eax
int v2; // ebp
int v3; // edi
int v5; // eax
int v6; // eax
int v7; // eax

v1 = open(*(const char **)(a1 + 32), 0);
if ( v1 < 0 )
{
syserrprintf(*(_QWORD *)(a1 + 32));
v5 = get_exitstatus();
exit(v5);
}
v2 = v1;
v3 = v1;
if ( close(0) < 0 )
{
close(v3);
syserrprintf("close(2)");
v7 = get_exitstatus();
exit(v7);
}
if ( dup(v3) )
{
close(v2);
syserrprintf("dup(2)");
v6 = get_exitstatus();
exit(v6);
}
return close(v2);
}

original_code:
void set_input_redirect (cmdattr attr) {
   int in_fd = -1;
   in_fd = open (attr->input_r, 00);
   if (in_fd < 0) {
      syserrprintf (attr->input_r);
      exit (get_exitstatus ());
   }
   if (close (0) < 0) {
      close (in_fd);
      syserrprintf ("close(2)");
      exit (get_exitstatus ());
   }
   if (dup (in_fd) != 0) {
      close (in_fd);
      syserrprintf ("dup(2)");
      exit (get_exitstatus ());
   }
   close (in_fd);
}

canonical_original_code:
void set_input_redirect(struct cmd_attributes *attr) {
   int in_fd = -1;
   in_fd = open (attr->input_r, 00);
   if (in_fd < 0) {
      syserrprintf (attr->input_r);
      exit (get_exitstatus ());
   }
   if (close (0) < 0) {
      close (in_fd);
      syserrprintf ("close(2)");
      exit (get_exitstatus ());
   }
   if (dup (in_fd) != 0) {
      close (in_fd);
      syserrprintf ("dup(2)");
      exit (get_exitstatus ());
   }
   close (in_fd);
}


decompiled_code:
int __fastcall execvp_cmd(const char *a1, char *const *a2)
{
int result; // eax
int *v3; // rax
char *v4; // rax
int v5; // eax

result = execvp(a1, a2);
if ( result == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
errprintf("%:%s\n", v4);
v5 = get_exitstatus();
exit(v5);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, char *const *a2)
{
int result; // eax
int *v3; // rax
char *v4; // rax
int v5; // eax

result = execvp(a1, a2);
if ( result == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
errprintf("%:%s\n", v4);
v5 = get_exitstatus();
exit(v5);
}
return result;
}

original_code:
void execvp_cmd (char *prog, char **argv) {
   int rc = execvp (prog, argv);
   if (rc == -1) {
      errprintf ("%:%s\n", strerror ((*__errno_location ())));
      exit (get_exitstatus ());
   }
}

canonical_original_code:
void execvp_cmd(char *prog, char **argv) {
   int rc = execvp (prog, argv);
   if (rc == -1) {
      errprintf ("%:%s\n", strerror ((*__errno_location ())));
      exit (get_exitstatus ());
   }
}

variable_types:
prog
char *

variable_types: rc int


decompiled_code:
int __fastcall exec_pipe(__int64 a1)
{
__pid_t v1; // eax
int result; // eax
int v3; // eax
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

pipe(pipedes);
v1 = fork();
if ( v1 )
{
if ( v1 <= 0 )
{
syserrprintf("fork(2)");
v3 = get_exitstatus();
exit(v3);
}
close(0);
dup(pipedes[0]);
close(pipedes[0]);
close(pipedes[1]);
if ( *(_QWORD *)(a1 + 40) )
set_output_redirect(a1);
result = execvp_cmd(*(const char **)(a1 + 16), *(char *const **)(a1 + 24));
}
else
{
close(1);
dup(pipedes[1]);
close(pipedes[0]);
close(pipedes[1]);
if ( *(_QWORD *)(a1 + 32) )
set_input_redirect(a1);
result = execvp_cmd(*(const char **)a1, *(char *const **)(a1 + 8));
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
__pid_t v1; // eax
int result; // eax
int v3; // eax
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

pipe(pipedes);
v1 = fork();
if ( v1 )
{
if ( v1 <= 0 )
{
syserrprintf("fork(2)");
v3 = get_exitstatus();
exit(v3);
}
close(0);
dup(pipedes[0]);
close(pipedes[0]);
close(pipedes[1]);
if ( *(_QWORD *)(a1 + 40) )
func6(a1);
result = func8(*(const char **)(a1 + 16), *(char *const **)(a1 + 24));
}
else
{
close(1);
dup(pipedes[1]);
close(pipedes[0]);
close(pipedes[1]);
if ( *(_QWORD *)(a1 + 32) )
func7(a1);
result = func8(*(const char **)a1, *(char *const **)(a1 + 8));
}
return result;
}

original_code:
void exec_pipe (cmdattr attr) {
   int pipefd[2];
   pipe (pipefd);
   pid_t pid = fork ();
   if (pid == 0) {
      close (1);
      dup (pipefd[1]);
      close (pipefd[0]);
      close (pipefd[1]);
      if (attr->input_r != ((void *)0)) set_input_redirect (attr);
      execvp_cmd (attr->lprog, attr->largs);
   }else if (pid > 0) {
      close (0);
      dup (pipefd[0]);
      close (pipefd[0]);
      close (pipefd[1]);
      if (attr->output_r != ((void *)0)) set_output_redirect (attr);
      execvp_cmd (attr->rprog, attr->rargs);
   }else {
      syserrprintf ("fork(2)");
      exit (get_exitstatus ());
   }
}

canonical_original_code:
void exec_pipe(struct cmd_attributes *attr) {
   int pipefd[2];
   pipe (pipefd);
   int pid = fork ();
   if (pid == 0) {
      close (1);
      dup (pipefd[1]);
      close (pipefd[0]);
      close (pipefd[1]);
      if (attr->input_r != ((void *)0)) set_input_redirect (attr);
      execvp_cmd (attr->lprog, attr->largs);
   }else if (pid > 0) {
      close (0);
      dup (pipefd[0]);
      close (pipefd[0]);
      close (pipefd[1]);
      if (attr->output_r != ((void *)0)) set_output_redirect (attr);
      execvp_cmd (attr->rprog, attr->rargs);
   }else {
      syserrprintf ("fork(2)");
      exit (get_exitstatus ());
   }
}

variable_types:
pipefd
int [2]

variable_types: pid int


decompiled_code:
int __fastcall exec_simple(__int64 a1)
{
if ( *(_QWORD *)(a1 + 40) )
set_output_redirect(a1);
if ( *(_QWORD *)(a1 + 32) )
set_input_redirect(a1);
return execvp_cmd(*(const char **)a1, *(char *const **)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
if ( *(_QWORD *)(a1 + 40) )
func6(a1);
if ( *(_QWORD *)(a1 + 32) )
func7(a1);
return func8(*(const char **)a1, *(char *const **)(a1 + 8));
}

original_code:
void exec_simple (cmdattr attr) {
   if (attr->output_r != ((void *)0)) set_output_redirect (attr);
   if (attr->input_r != ((void *)0)) set_input_redirect (attr);
   execvp_cmd (attr->lprog, attr->largs);
}

canonical_original_code:
void exec_simple(struct cmd_attributes *attr) {
   if (attr->output_r != ((void *)0)) set_output_redirect (attr);
   if (attr->input_r != ((void *)0)) set_input_redirect (attr);
   execvp_cmd (attr->lprog, attr->largs);
}


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

result = (unsigned int)(*(_DWORD *)(a1 + 16) - 260);
switch ( *(_DWORD *)(a1 + 16) )
{
case 0x104:
result = cmd_prog(a1, (_QWORD *)a2);
break;
case 0x105:
result = cmd_args(a1, a2);
break;
case 0x106:
case 0x107:
result = cmd_exec(a1, a2);
break;
case 0x108:
result = cmd_rein(a1, a2);
break;
case 0x109:
result = cmd_reout(a1, a2);
break;
case 0x10A:
case 0x10C:
result = cmd_invoc(a1, a2);
break;
case 0x10B:
result = cmd_right(a1, a2);
break;
default:
return result;
}
return result;
}

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

result = (unsigned int)(*(_DWORD *)(a1 + 16) - 260);
switch ( *(_DWORD *)(a1 + 16) )
{
case 0x104:
result = func5(a1, (_QWORD *)a2);
break;
case 0x105:
result = func4(a1, a2);
break;
case 0x106:
case 0x107:
result = func15(a1, a2);
break;
case 0x108:
result = func3(a1, a2);
break;
case 0x109:
result = func2(a1, a2);
break;
case 0x10A:
case 0x10C:
result = func13(a1, a2);
break;
case 0x10B:
result = func16(a1, a2);
break;
default:
return result;
}
return result;
}

original_code:
void cmd_select (cmdtree tree, cmdattr attr) {
   switch (tree->symbol) {
      case SIMPL: cmd_exec (tree, attr); break;
      case PIPE: cmd_exec (tree, attr); break;
      case LEFT: cmd_left (tree, attr); break;
      case RIGHT: cmd_right (tree, attr); break;
      case INVOC: cmd_invoc (tree, attr); break;
      case PROG: cmd_prog (tree, attr); break;
      case ARGS: cmd_args (tree, attr); break;
      case REIN: cmd_rein (tree, attr); break;
      case REOUT: cmd_reout (tree, attr); break;
      default: break;
   }
}

canonical_original_code:
void cmd_select(struct cmdtree_rep *tree, struct cmd_attributes *attr) {
   switch (tree->symbol) {
      case SIMPL: cmd_exec (tree, attr); break;
      case PIPE: cmd_exec (tree, attr); break;
      case LEFT: cmd_left (tree, attr); break;
      case RIGHT: cmd_right (tree, attr); break;
      case INVOC: cmd_invoc (tree, attr); break;
      case PROG: cmd_prog (tree, attr); break;
      case ARGS: cmd_args (tree, attr); break;
      case REIN: cmd_rein (tree, attr); break;
      case REOUT: cmd_reout (tree, attr); break;
      default: break;
   }
}


decompiled_code:
__int64 __fastcall select_children(__int64 a1, __int64 a2)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = *(_QWORD *)(a1 + 24); i; i = *(_QWORD *)(i + 40) )
result = cmd_select(i, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = *(_QWORD *)(a1 + 24); i; i = *(_QWORD *)(i + 40) )
result = func11(i, a2);
return result;
}

original_code:
void select_children (cmdtree tree, cmdattr attr) {
   cmdtree child = tree->first;
   for (;;) {
      if (child == ((void *)0)) break;
      cmd_select (child, attr);
      child = child->next;
   }
}

canonical_original_code:
void select_children(struct cmdtree_rep *tree, struct cmd_attributes *attr) {
   struct cmdtree_rep *child = tree->first;
   for (;;) {
      if (child == ((void *)0)) break;
      cmd_select (child, attr);
      child = child->next;
   }
}


decompiled_code:
// attributes: thunk
__int64 __fastcall cmd_invoc(__int64 a1, __int64 a2)
{
return select_children(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
return func12(a1, a2);
}

original_code:
void cmd_invoc (cmdtree tree, cmdattr attr) {
   select_children (tree, attr);
}

canonical_original_code:
void cmd_invoc(struct cmdtree_rep *tree, struct cmd_attributes *attr) {
   select_children (tree, attr);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall cmd_left(__int64 a1, __int64 a2)
{
return cmd_invoc(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
return func13(a1, a2);
}

original_code:
void cmd_left (cmdtree tree, cmdattr attr) {
   select_children (tree, attr);
}

canonical_original_code:
void cmd_left(struct cmdtree_rep *tree, struct cmd_attributes *attr) {
   select_children (tree, attr);
}


decompiled_code:
__pid_t __fastcall cmd_exec(__int64 a1, __int64 a2)
{
__pid_t result; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

select_children(a1, a2);
result = fork();
if ( result )
{
if ( result <= 0 )
{
result = syserrprintf("fork(2)");
}
else if ( !yyparse_cmdbg_flag )
{
result = wait((__WAIT_STATUS)&stat_loc);
}
}
else if ( *(_DWORD *)(a1 + 16) == 262 )
{
result = exec_simple(a2);
}
else
{
result = exec_pipe(a2);
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func15(__int64 a1, __int64 a2)
{
__pid_t result; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

func12(a1, a2);
result = fork();
if ( result )
{
if ( result <= 0 )
{
result = syserrprintf("fork(2)");
}
else if ( !yyparse_cmdbg_flag )
{
result = wait((__WAIT_STATUS)&stat_loc);
}
}
else if ( *(_DWORD *)(a1 + 16) == 262 )
{
result = func10(a2);
}
else
{
result = func9(a2);
}
return result;
}

original_code:
void cmd_exec (cmdtree tree, cmdattr attr) {
   select_children (tree, attr);
   int status;
   pid_t pid = fork ();
   if (pid == 0) {
      if (tree->symbol == SIMPL) {
         exec_simple (attr);
      }else {
         exec_pipe (attr);
      }
   }else if (pid > 0) {
      if (! yyparse_cmdbg_flag) wait (&status);
   }else {
      syserrprintf ("fork(2)");
   }
}

canonical_original_code:
void cmd_exec(struct cmdtree_rep *tree, struct cmd_attributes *attr) {
   select_children (tree, attr);
   int status;
   int pid = fork ();
   if (pid == 0) {
      if (tree->symbol == SIMPL) {
         exec_simple (attr);
      }else {
         exec_pipe (attr);
      }
   }else if (pid > 0) {
      if (! yyparse_cmdbg_flag) wait (&status);
   }else {
      syserrprintf ("fork(2)");
   }
}

variable_types: status int


original_code:
void cmd_right (cmdtree tree, cmdattr attr) {
   cmdtree invoc = tree->first;
   attr->rprog = invoc->first->first->lexinfo;
   attr->rargs[0] = attr->rprog;
   cmdtree args = invoc->first->next;
   int ind = 1;
   if (args != ((void *)0)) {
      cmdtree arg = args->first;
      while (ind < 64) {
         if (arg == ((void *)0)) break;
         attr->rargs[ind++] = arg->lexinfo;
         arg = arg->next;
      }
   }
   attr->rargs[ind] = ((void *)0);
   cmdtree reout = invoc->next;
   if (reout != ((void *)0)) cmd_select (reout, attr);
}

canonical_original_code:
void cmd_right(struct cmdtree_rep *tree, struct cmd_attributes *attr) {
   struct cmdtree_rep *invoc = tree->first;
   attr->rprog = invoc->first->first->lexinfo;
   attr->rargs[0] = attr->rprog;
   struct cmdtree_rep *args = invoc->first->next;
   int ind = 1;
   if (args != ((void *)0)) {
      struct cmdtree_rep *arg = args->first;
      while (ind < 64) {
         if (arg == ((void *)0)) break;
         attr->rargs[ind++] = arg->lexinfo;
         arg = arg->next;
      }
   }
   attr->rargs[ind] = ((void *)0);
   struct cmdtree_rep *reout = invoc->next;
   if (reout != ((void *)0)) cmd_select (reout, attr);
}


execute

decompiled_code:
void execute()
{
__int64 i; // rbx
_QWORD *v1; // rbp

for ( i = *(_QWORD *)(yyparse_cmdtree + 24LL); i; i = *(_QWORD *)(i + 40) )
{
v1 = new_cmdattr();
cmd_select(i, (__int64)v1);
free_cmdattr(v1);
}
}

canonical_decompiled_code:
void func17()
{
__int64 i; // rbx
_QWORD *v1; // rbp

for ( i = *(_QWORD *)(yyparse_cmdtree + 24LL); i; i = *(_QWORD *)(i + 40) )
{
v1 = func0();
func11(i, (__int64)v1);
func1(v1);
}
}

original_code:
void execute (void) {
   cmdtree child = yyparse_cmdtree->first;
   for (;;) {
      if (child == ((void *)0)) break;
      cmdattr attr = new_cmdattr ();
      cmd_select (child, attr);
      free_cmdattr (attr);
      child = child->next;
   }
}

canonical_original_code:
void execute() {
   struct cmdtree_rep *child = yyparse_cmdtree->first;
   for (;;) {
      if (child == ((void *)0)) break;
      struct cmd_attributes *attr = new_cmdattr ();
      cmd_select (child, attr);
      free_cmdattr (attr);
      child = child->next;
   }
}


decompiled_code:
int __fastcall set_options(int argc, char **argv)
{
int result; // eax
int v3; // eax
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

yy_flex_debug = 0;
yydebug = 0;
opterr = 0;
while ( 1 )
{
result = getopt(argc, argv, "@:ly");
if ( result == -1 )
break;
switch ( result )
{
case 'l':
yy_flex_debug = 1;
break;
case 'y':
yydebug = 1;
break;
case '@':
set_debugflags(optarg);
break;
default:
sprintf(v4, "-%c", (unsigned int)optopt);
errprintf("%:%c: invalid option\n", v4);
v3 = get_exitstatus();
exit(v3);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func18(int argc, char **argv)
{
int result; // eax
int v3; // eax
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

yy_flex_debug = 0;
yydebug = 0;
opterr = 0;
while ( 1 )
{
result = getopt(argc, argv, "@:ly");
if ( result == -1 )
break;
switch ( result )
{
case 'l':
yy_flex_debug = 1;
break;
case 'y':
yydebug = 1;
break;
case '@':
set_debugflags(optarg);
break;
default:
sprintf(v4, "-%c", (unsigned int)optopt);
errprintf("%:%c: invalid option\n", v4);
v3 = get_exitstatus();
exit(v3);
}
}
return result;
}

original_code:
void set_options (int argc, char **argv) {
   yy_flex_debug = 0;
   yydebug = 0;
   opterr = 0;
   for (;;) {
      int opt = getopt (argc, argv, "@:ly");
      if (opt == (-1)) break;
      switch (opt) {
         char optopt_str[16];
         case '@': set_debugflags (optarg);
                   break;
         case 'l': yy_flex_debug = 1;
                   break;
         case 'y': yydebug = 1;
                   break;
         default : sprintf (optopt_str, "-%c", optopt);
                   errprintf ("%:%c: invalid option\n", optopt_str);
                   exit (get_exitstatus ());
      }
   }
}

canonical_original_code:
void set_options(int argc, char **argv) {
   yy_flex_debug = 0;
   yydebug = 0;
   opterr = 0;
   for (;;) {
      int opt = getopt (argc, argv, "@:ly");
      if (opt == (-1)) break;
      switch (opt) {
         char optopt_str[16];
         case '@': set_debugflags (optarg);
                   break;
         case 'l': yy_flex_debug = 1;
                   break;
         case 'y': yydebug = 1;
                   break;
         default : sprintf (optopt_str, "-%c", optopt);
                   errprintf ("%:%c: invalid option\n", optopt_str);
                   exit (get_exitstatus ());
      }
   }
}

variable_types: argc int

variable_types: opt int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
set_execname(*argv);
set_options(argc, (char **)argv);
while ( 1 )
{
do
printf("mysh$ ");
while ( (unsigned int)yyparse() );
execute();
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
set_execname(*argv);
func18(argc, (char **)argv);
while ( 1 )
{
do
printf("mysh$ ");
while ( (unsigned int)yyparse() );
func17();
}
}

original_code:
int main (int argc, char **argv) {
   set_execname (argv[0]);
   set_options (argc, argv);
   for (;;) {
      printf ("mysh$ ");
      int yyparse_rc = yyparse ();
      if (yyparse_rc == 0) execute ();
   }
   return get_exitstatus ();
}

canonical_original_code:
int main(int argc, char **argv) {
   set_execname (argv[0]);
   set_options (argc, argv);
   for (;;) {
      printf ("mysh$ ");
      int yyparse_rc = yyparse ();
      if (yyparse_rc == 0) execute ();
   }
   return get_exitstatus ();
}

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall scanner_badchar(unsigned __int8 a1)
{
const char *v1; // rsi
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = (const char *)&unk_100;
if ( ((*_ctype_b_loc())[a1] & 0x8000u) == 0 )
v1 = "\\%03o";
sprintf(v3, v1, a1);
return errprintf("%: invalid character (%s)\n", v3);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
const char *v1; // rsi
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = (const char *)&unk_100;
if ( ((*_ctype_b_loc())[a1] & 0x8000u) == 0 )
v1 = "\\%03o";
sprintf(v3, v1, a1);
return errprintf("%: invalid character (%s)\n", v3);
}

original_code:
void scanner_badchar (unsigned char bad) {
   char char_rep[16];
   sprintf (char_rep, ((*__ctype_b_loc ())[(int) (((int) bad))] & (unsigned short int) _ISgraph) ? "%c" : "\\%03o", bad);
   errprintf ("%: invalid character (%s)\n", char_rep);
}

canonical_original_code:
void scanner_badchar(unsigned char bad) {
   char char_rep[16];
   sprintf (char_rep, ((*__ctype_b_loc ())[(int) (((int) bad))] & (unsigned short) _ISgraph) ? "%c" : "\\%03o", bad);
   errprintf ("%: invalid character (%s)\n", char_rep);
}

variable_types:
bad
unsigned char


decompiled_code:
__int64 __fastcall scanner_badtoken(__int64 a1)
{
return errprintf("%: invalid token (%s)\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return errprintf("%: invalid token (%s)\n", a1);
}

original_code:
void scanner_badtoken (char *lexeme) {
   errprintf ("%: invalid token (%s)\n", lexeme);
}

canonical_original_code:
void scanner_badtoken(char *lexeme) {
   errprintf ("%: invalid token (%s)\n", lexeme);
}

variable_types:
lexeme
char *


yyerror

decompiled_code:
__int64 __fastcall yyerror(__int64 a1)
{
return errprintf("%: %s\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return errprintf("%: %s\n", a1);
}

original_code:
void yyerror (char *message) {
   errprintf ("%: %s\n", message);
}

canonical_original_code:
void yyerror(char *message) {
   errprintf ("%: %s\n", message);
}

variable_types:
message
char *


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

result = new_cmdtree(258LL, &unk_142);
yyparse_cmdtree = result;
return result;
}

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

result = new_cmdtree(258LL, &unk_142);
yyparse_cmdtree = result;
return result;
}

original_code:
cmdtree new_parseroot (void) {
   yyparse_cmdtree = new_cmdtree (CMD_ROOT, "");
   return yyparse_cmdtree;
}

canonical_original_code:
struct cmdtree_rep *new_parseroot() {
   yyparse_cmdtree = new_cmdtree (CMD_ROOT, "");
   return yyparse_cmdtree;
}

return_type: struct cmdtree_rep { char *tag; char *lexinfo; int symbol; struct cmdtree_rep *first; struct cmdtree_rep *last; struct cmdtree_rep *next; } *


decompiled_code:
__int64 __fastcall new_parseroot1(__int64 a1)
{
return new_cmdtree(a1, &unk_142);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return new_cmdtree(a1, &unk_142);
}

original_code:
cmdtree new_parseroot1 (int symbol) {
   cmdtree newroot = new_cmdtree (symbol, "");
   return newroot;
}

canonical_original_code:
struct cmdtree_rep *new_parseroot1(int symbol) {
   struct cmdtree_rep *newroot = new_cmdtree (symbol, "");
   return newroot;
}

variable_types: symbol int


decompiled_code:
__int64 __fastcall yylval_token(__int64 a1)
{
yylval = new_cmdtree(a1, yytext);
_debugprintf(116LL, "lyutils.c", 37LL, "yylval_token", "sym=%d, lex=%s\n", (unsigned int)a1, yytext);
return (unsigned int)a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
yylval = new_cmdtree(a1, yytext);
_debugprintf(116LL, "lyutils.c", 37LL, "yylval_token", "sym=%d, lex=%s\n", (unsigned int)a1, yytext);
return (unsigned int)a1;
}

original_code:
int yylval_token (int symbol) {
   yylval = new_cmdtree (symbol, yytext);
   __debugprintf ('t', "lyutils.c", 37, __func__, "sym=%d, lex=%s\n", symbol, yytext);
   return symbol;
}

canonical_original_code:
int yylval_token(int symbol) {
   yylval = new_cmdtree (symbol, yytext);
   __debugprintf ('t', "lyutils.c", 37, __func__, "sym=%d, lex=%s\n", symbol, yytext);
   return symbol;
}


decompiled_code:
char *__fastcall set_execname(char *a1)
{
char *result; // rax

result = _xpg_basename(a1);
execname = (__int64)result;
return result;
}

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

result = _xpg_basename(a1);
execname = (__int64)result;
return result;
}

original_code:
void set_execname (char *argv0) {
   execname = __xpg_basename (argv0);
}

canonical_original_code:
void set_execname(char *argv0) {
   execname = __xpg_basename (argv0);
}


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

result = execname;
if ( !execname )
_assert_fail("execname != NULL", "auxlib.c", 0x1Bu, "get_execname");
return result;
}

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

result = execname;
if ( !execname )
_assert_fail("execname != NULL", "auxlib.c", 0x1Bu, "get_execname");
return result;
}

original_code:
char *get_execname (void) {
   ((void) sizeof ((execname != ((void *)0)) ? 1 : 0), __extension__ ({ if (execname != ((void *)0)) ; else __assert_fail ("execname != NULL", "auxlib.c", 27, __extension__ __PRETTY_FUNCTION__); }));
   return execname;
}

canonical_original_code:
char *get_execname() {
   ((void) sizeof ((execname != ((void *)0)) ? 1 : 0), __extension__ ({ if (execname != ((void *)0)) ; else __assert_fail ("execname != NULL", "auxlib.c", 27, __extension__ __PRETTY_FUNCTION__); }));
   return execname;
}


decompiled_code:
__int64 get_exitstatus()
{
return (unsigned int)exitstatus;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)exitstatus;
}

original_code:
int get_exitstatus (void) {
   return exitstatus;
}

canonical_original_code:
int get_exitstatus() {
   return exitstatus;
}


decompiled_code:
void __fastcall set_exitstatus(unsigned __int8 a1)
{
if ( exitstatus < a1 )
exitstatus = a1;
}

canonical_decompiled_code:
void __fastcall func3(unsigned __int8 a1)
{
if ( exitstatus < a1 )
exitstatus = a1;
}

original_code:
void set_exitstatus (int newexitstatus) {
   newexitstatus &= 0xFF;
   if (exitstatus < newexitstatus) exitstatus = newexitstatus;
}

canonical_original_code:
void set_exitstatus(int newexitstatus) {
   newexitstatus &= 0xFF;
   if (exitstatus < newexitstatus) exitstatus = newexitstatus;
}

variable_types: newexitstatus int


veprintf

decompiled_code:
int __fastcall veprintf(char *format, __gnuc_va_list arg)
{
char *v2; // rbp
const char *v3; // rax

if ( !execname )
_assert_fail("execname != NULL", "auxlib.c", 0x44u, "veprintf");
v2 = format;
if ( !format )
_assert_fail("format != NULL", "auxlib.c", 0x45u, "veprintf");
fflush(0LL);
if ( *format == 37 && format[1] == 58 )
{
v3 = (const char *)get_execname();
v2 = format + 2;
fprintf(stderr, "-%s: ", v3);
}
vfprintf(stderr, v2, arg);
return fflush(0LL);
}

canonical_decompiled_code:
int __fastcall func4(char *format, __gnuc_va_list arg)
{
char *v2; // rbp
const char *v3; // rax

if ( !execname )
_assert_fail("execname != NULL", "auxlib.c", 0x44u, "veprintf");
v2 = format;
if ( !format )
_assert_fail("format != NULL", "auxlib.c", 0x45u, "veprintf");
fflush(0LL);
if ( *format == 37 && format[1] == 58 )
{
v3 = (const char *)func1();
v2 = format + 2;
fprintf(stderr, "-%s: ", v3);
}
vfprintf(stderr, v2, arg);
return fflush(0LL);
}

original_code:
void veprintf (char *format, va_list args) {
   ((void) sizeof ((execname != ((void *)0)) ? 1 : 0), __extension__ ({ if (execname != ((void *)0)) ; else __assert_fail ("execname != NULL", "auxlib.c", 68, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((format != ((void *)0)) ? 1 : 0), __extension__ ({ if (format != ((void *)0)) ; else __assert_fail ("format != NULL", "auxlib.c", 69, __extension__ __PRETTY_FUNCTION__); }));
   fflush (((void *)0));
   if (strstr (format, "%:") == format) {
      fprintf (stderr, "-%s: ", get_execname ());
      format += 2;
   }
   vfprintf (stderr, format, args);
   fflush (((void *)0));
}

canonical_original_code:
void veprintf(char *format, __builtin_va_list args) {
   ((void) sizeof ((execname != ((void *)0)) ? 1 : 0), __extension__ ({ if (execname != ((void *)0)) ; else __assert_fail ("execname != NULL", "auxlib.c", 68, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((format != ((void *)0)) ? 1 : 0), __extension__ ({ if (format != ((void *)0)) ; else __assert_fail ("format != NULL", "auxlib.c", 69, __extension__ __PRETTY_FUNCTION__); }));
   fflush (((void *)0));
   if (strstr (format, "%:") == format) {
      fprintf (stderr, "-%s: ", get_execname ());
      format += 2;
   }
   vfprintf (stderr, format, args);
   fflush (((void *)0));
}

variable_types:
format
char *


eprintf

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

va_start(arg, a1);
return veprintf(a1, arg);
}

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

va_start(arg, a1);
return func4(a1, arg);
}

original_code:
void eprintf (char *format, ...) {
   va_list args;
   __builtin_va_start(args,format);
   veprintf (format, args);
   __builtin_va_end(args);
}

canonical_original_code:
void eprintf(char *format, ...) {
   __builtin_va_list args;
   __builtin_va_start(args,format);
   veprintf (format, args);
   __builtin_va_end(args);
}


decompiled_code:
int __fastcall eprint_signal(const char *a1, unsigned int a2)
{
char *v2; // rax

eprintf(", %s %d", a1, a2);
v2 = strsignal(a2);
if ( v2 )
LODWORD(v2) = fprintf(stderr, " %s", v2);
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func6(const char *a1, unsigned int a2)
{
char *v2; // rax

func5(", %s %d", a1, a2);
v2 = strsignal(a2);
if ( v2 )
LODWORD(v2) = fprintf(stderr, " %s", v2);
return (int)v2;
}

original_code:
static void eprint_signal (char *kind, int signal) {
   eprintf (", %s %d", kind, signal);
   char *sigstr = strsignal (signal);
   if (sigstr != ((void *)0)) fprintf (stderr, " %s", sigstr);
}

canonical_original_code:
static void eprint_signal(char *kind, int signal) {
   eprintf (", %s %d", kind, signal);
   char *sigstr = strsignal (signal);
   if (sigstr != ((void *)0)) fprintf (stderr, " %s", sigstr);
}

variable_types:
kind
char *

variable_types: signal int

variable_types:
sigstr
char *


decompiled_code:
int __fastcall eprint_status(const char *a1, unsigned int a2)
{
int result; // eax

if ( a2 )
{
eprintf("%s: status 0x%04X", a1, a2);
if ( (a2 & 0x7F) == 0 )
eprintf(", exit %d", BYTE1(a2));
if ( !__OFSUB__((a2 & 0x7F) + 1, 1) && (a2 & 0x7F) != 0 )
{
eprint_signal("Terminated", a2 & 0x7F);
if ( (a2 & 0x80u) != 0 )
eprintf(", core dumped");
}
if ( (_BYTE)a2 == 127 )
eprint_signal("Stopped", BYTE1(a2));
if ( a2 == 0xFFFF )
eprintf(", Continued");
result = eprintf("\n");
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, unsigned int a2)
{
int result; // eax

if ( a2 )
{
func5("%s: status 0x%04X", a1, a2);
if ( (a2 & 0x7F) == 0 )
func5(", exit %d", BYTE1(a2));
if ( !__OFSUB__((a2 & 0x7F) + 1, 1) && (a2 & 0x7F) != 0 )
{
func6("Terminated", a2 & 0x7F);
if ( (a2 & 0x80u) != 0 )
func5(", core dumped");
}
if ( (_BYTE)a2 == 127 )
func6("Stopped", BYTE1(a2));
if ( a2 == 0xFFFF )
func5(", Continued");
result = func5("\n");
}
return result;
}

original_code:
void eprint_status (char *command, int status) {
   if (status == 0) return;
   eprintf ("%s: status 0x%04X", command, status);
   if ((((status) & 0x7f) == 0)) {
      eprintf (", exit %d", (((status) & 0xff00) >> 8));
   }
   if ((((signed char) (((status) & 0x7f) + 1) >> 1) > 0)) {
      eprint_signal ("Terminated", ((status) & 0x7f));
      if (((status) & 0x80)) eprintf (", core dumped");
   }
   if ((((status) & 0xff) == 0x7f)) {
      eprint_signal ("Stopped", (((status) & 0xff00) >> 8));
   }
   if (((status) == 0xffff)) {
      eprintf (", Continued");
   }
   eprintf ("\n");
}

canonical_original_code:
void eprint_status(char *command, int status) {
   if (status == 0) return;
   eprintf ("%s: status 0x%04X", command, status);
   if ((((status) & 0x7f) == 0)) {
      eprintf (", exit %d", (((status) & 0xff00) >> 8));
   }
   if ((((char) (((status) & 0x7f) + 1) >> 1) > 0)) {
      eprint_signal ("Terminated", ((status) & 0x7f));
      if (((status) & 0x80)) eprintf (", core dumped");
   }
   if ((((status) & 0xff) == 0x7f)) {
      eprint_signal ("Stopped", (((status) & 0xff00) >> 8));
   }
   if (((status) == 0xffff)) {
      eprintf (", Continued");
   }
   eprintf ("\n");
}

variable_types:
command
char *


errprintf

decompiled_code:
int errprintf(char *a1, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
result = veprintf(a1, arg);
exitstatus = 1;
return result;
}

canonical_decompiled_code:
int func8(char *a1, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
result = func4(a1, arg);
exitstatus = 1;
return result;
}

original_code:
void errprintf (char *format, ...) {
   va_list args;
   __builtin_va_start(args,format);
   veprintf (format, args);
   __builtin_va_end(args);
   exitstatus = 1;
}

canonical_original_code:
void errprintf(char *format, ...) {
   __builtin_va_list args;
   __builtin_va_start(args,format);
   veprintf (format, args);
   __builtin_va_end(args);
   exitstatus = 1;
}


syserrprintf

decompiled_code:
int __fastcall syserrprintf(__int64 a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
return errprintf("%:%s: %s\n", a1, v2);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
return func8("%:%s: %s\n", a1, v2);
}

original_code:
void syserrprintf (char *object) {
   errprintf ("%:%s: %s\n", object, strerror ((*__errno_location ())));
}

canonical_original_code:
void syserrprintf(char *object) {
   errprintf ("%:%s: %s\n", object, strerror ((*__errno_location ())));
}

variable_types:
object
char *


decompiled_code:
char *__fastcall set_debugflags(char *a1)
{
char *result; // rax

debugflags = a1;
result = strchr(a1, 64);
if ( result )
alldebugflags = 1;
return result;
}

canonical_decompiled_code:
char *__fastcall func11(char *a1)
{
char *result; // rax

debugflags = a1;
result = strchr(a1, 64);
if ( result )
alldebugflags = 1;
return result;
}

original_code:
void set_debugflags (char *flags) {
   debugflags = flags;
   if (strchr (debugflags, '@') != ((void *)0)) alldebugflags = 1;
}

canonical_original_code:
void set_debugflags(char *flags) {
   debugflags = flags;
   if (strchr (debugflags, '@') != ((void *)0)) alldebugflags = 1;
}

variable_types:
flags
char *


decompiled_code:
char __fastcall is_debugflag(char a1)
{
char result; // al

result = alldebugflags;
if ( !alldebugflags )
result = strchr(debugflags, a1) != 0LL;
return result;
}

canonical_decompiled_code:
char __fastcall func12(char a1)
{
char result; // al

result = alldebugflags;
if ( !alldebugflags )
result = strchr(debugflags, a1) != 0LL;
return result;
}

original_code:
_Bool is_debugflag (char flag) {
   return alldebugflags || strchr (debugflags, flag) != ((void *)0);
}

canonical_original_code:
_Bool is_debugflag(char flag) {
   return alldebugflags || strchr (debugflags, flag) != ((void *)0);
}

variable_types: flag char


decompiled_code:
bool __fastcall is_cmdtree(_QWORD *a1)
{
bool result; // al

result = 0;
if ( a1 )
result = *a1 == (_QWORD)"struct cmdtree_rep";
return result;
}

canonical_decompiled_code:
bool __fastcall func0(_QWORD *a1)
{
bool result; // al

result = 0;
if ( a1 )
result = *a1 == (_QWORD)"struct cmdtree_rep";
return result;
}

original_code:
_Bool is_cmdtree (void *object) {
   cmdtree tree = (cmdtree) object;
   return tree != ((void *)0) && tree->tag == cmdtree_tag;
}

canonical_original_code:
_Bool is_cmdtree(void *object) {
   struct cmdtree_rep *tree = (cmdtree) object;
   return tree != ((void *)0) && tree->tag == cmdtree_tag;
}

variable_types:
object
void *

variable_types: struct cmdtree_rep { char *tag; char *lexinfo; int symbol; struct cmdtree_rep *first; struct cmdtree_rep *last; struct cmdtree_rep *next; } *


decompiled_code:
int __fastcall dump_node(__int64 a1, int a2)
{
__int64 v3; // rdi
int i; // ebx
const char *v5; // rax

if ( !is_cmdtree((_QWORD *)a1) )
_assert_fail("is_cmdtree (node)", "cmdtree.c", 0x49u, "dump_node");
v3 = *(unsigned int *)(a1 + 16);
if ( (_DWORD)v3 != 258 && a2 > 0 )
{
for ( i = 0; i != a2; ++i )
printf("| ");
v3 = *(unsigned int *)(a1 + 16);
}
v5 = (const char *)get_yytname(v3);
return printf("%s \"%s\"\n", v5, *(const char **)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2)
{
__int64 v3; // rdi
int i; // ebx
const char *v5; // rax

if ( !func0((_QWORD *)a1) )
_assert_fail("is_cmdtree (node)", "cmdtree.c", 0x49u, "dump_node");
v3 = *(unsigned int *)(a1 + 16);
if ( (_DWORD)v3 != 258 && a2 > 0 )
{
for ( i = 0; i != a2; ++i )
printf("| ");
v3 = *(unsigned int *)(a1 + 16);
}
v5 = (const char *)get_yytname(v3);
return printf("%s \"%s\"\n", v5, *(const char **)(a1 + 8));
}

original_code:
static void dump_node (cmdtree node, int depth) {
   ((void) sizeof ((is_cmdtree (node)) ? 1 : 0), __extension__ ({ if (is_cmdtree (node)) ; else __assert_fail ("is_cmdtree (node)", "cmdtree.c", 73, __extension__ __PRETTY_FUNCTION__); }));
   if (node->symbol != CMD_ROOT) {
      for (int itor = 0; itor < depth; ++itor) {
         printf ("|  ");
      }
   }
   const char *tname = get_yytname (node->symbol);
   printf ("%s \"%s\"\n", tname, node->lexinfo);
}

canonical_original_code:
static void dump_node(struct cmdtree_rep *node, int depth) {
   ((void) sizeof ((is_cmdtree (node)) ? 1 : 0), __extension__ ({ if (is_cmdtree (node)) ; else __assert_fail ("is_cmdtree (node)", "cmdtree.c", 73, __extension__ __PRETTY_FUNCTION__); }));
   if (node->symbol != CMD_ROOT) {
      for (int itor = 0; itor < depth; ++itor) {
         printf ("|  ");
      }
   }
   char *tname = get_yytname (node->symbol);
   printf ("%s \"%s\"\n", tname, node->lexinfo);
}

variable_types: depth int

variable_types: itor int

variable_types:
tname
char *


decompiled_code:
void __fastcall dump_cmdtree_rec(_QWORD *a1, int a2)
{
__int64 i; // rbx

if ( a1 )
{
if ( !is_cmdtree(a1) )
_assert_fail("is_cmdtree (root)", "cmdtree.c", 0x55u, "dump_cmdtree_rec");
dump_node((__int64)a1, a2);
for ( i = a1[3]; i; i = *(_QWORD *)(i + 40) )
dump_cmdtree_rec(i, (unsigned int)(a2 + 1));
}
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1, int a2)
{
__int64 i; // rbx

if ( a1 )
{
if ( !func0(a1) )
_assert_fail("is_cmdtree (root)", "cmdtree.c", 0x55u, "dump_cmdtree_rec");
func1((__int64)a1, a2);
for ( i = a1[3]; i; i = *(_QWORD *)(i + 40) )
func2(i, (unsigned int)(a2 + 1));
}
}

original_code:
static void dump_cmdtree_rec (cmdtree root, int depth) {
   if (root == ((void *)0)) return;
   ((void) sizeof ((is_cmdtree (root)) ? 1 : 0), __extension__ ({ if (is_cmdtree (root)) ; else __assert_fail ("is_cmdtree (root)", "cmdtree.c", 85, __extension__ __PRETTY_FUNCTION__); }));
   dump_node (root, depth);
   cmdtree child = root->first;
   for (;;) {
      if (child == ((void *)0)) break;
      dump_cmdtree_rec (child, depth + 1);
      child = child->next;
   }
}

canonical_original_code:
static void dump_cmdtree_rec(struct cmdtree_rep *root, int depth) {
   if (root == ((void *)0)) return;
   ((void) sizeof ((is_cmdtree (root)) ? 1 : 0), __extension__ ({ if (is_cmdtree (root)) ; else __assert_fail ("is_cmdtree (root)", "cmdtree.c", 85, __extension__ __PRETTY_FUNCTION__); }));
   dump_node (root, depth);
   struct cmdtree_rep *child = root->first;
   for (;;) {
      if (child == ((void *)0)) break;
      dump_cmdtree_rec (child, depth + 1);
      child = child->next;
   }
}


adopt

decompiled_code:
_QWORD *adopt(_QWORD *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
_QWORD *v10; // rdx
__int64 v11; // rdx
__int64 v12; // rax
unsigned int v13; // eax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

if ( !is_cmdtree(a1) )
_assert_fail("is_cmdtree (root)", "cmdtree.c", 0x23u, "adopt");
va_start(va, a9);
while ( 1 )
{
v13 = va[0].gp_offset;
if ( va[0].gp_offset > 0x2F )
break;
va[0].gp_offset += 8;
v10 = *(_QWORD **)((char *)va[0].reg_save_area + v13);
if ( !v10 )
return a1;
LABEL_4:
if ( !is_cmdtree(v10) )
_assert_fail("is_cmdtree (child)", "cmdtree.c", 0x2Au, "adopt");
v12 = a1[4];
if ( v12 )
*(_QWORD *)(v12 + 40) = v11;
else
a1[3] = v11;
a1[4] = v11;
}
v10 = *(_QWORD **)va[0].overflow_arg_area;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
if ( v10 )
goto LABEL_4;
return a1;
}

canonical_decompiled_code:
_QWORD *func3(_QWORD *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
_QWORD *v10; // rdx
__int64 v11; // rdx
__int64 v12; // rax
unsigned int v13; // eax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

if ( !func0(a1) )
_assert_fail("is_cmdtree (root)", "cmdtree.c", 0x23u, "adopt");
va_start(va, a9);
while ( 1 )
{
v13 = va[0].gp_offset;
if ( va[0].gp_offset > 0x2F )
break;
va[0].gp_offset += 8;
v10 = *(_QWORD **)((char *)va[0].reg_save_area + v13);
if ( !v10 )
return a1;
LABEL_4:
if ( !func0(v10) )
_assert_fail("is_cmdtree (child)", "cmdtree.c", 0x2Au, "adopt");
v12 = a1[4];
if ( v12 )
*(_QWORD *)(v12 + 40) = v11;
else
a1[3] = v11;
a1[4] = v11;
}
v10 = *(_QWORD **)va[0].overflow_arg_area;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
if ( v10 )
goto LABEL_4;
return a1;
}

original_code:
cmdtree adopt (cmdtree root, ...) {
   ((void) sizeof ((is_cmdtree (root)) ? 1 : 0), __extension__ ({ if (is_cmdtree (root)) ; else __assert_fail ("is_cmdtree (root)", "cmdtree.c", 35, __extension__ __PRETTY_FUNCTION__); }));
   va_list children;
   __builtin_va_start(children,root);
   for (;;) {
      cmdtree child = __builtin_va_arg(children,cmdtree);
      if (child == ((void *)0)) break;
      ((void) sizeof ((is_cmdtree (child)) ? 1 : 0), __extension__ ({ if (is_cmdtree (child)) ; else __assert_fail ("is_cmdtree (child)", "cmdtree.c", 42, __extension__ __PRETTY_FUNCTION__); }));
      if (root->last == ((void *)0)) root->first = child;
                         else root->last->next = child;
      root->last = child;
   }
   __builtin_va_end(children);
   return root;
}

canonical_original_code:
struct cmdtree_rep *adopt(struct cmdtree_rep *root, ...) {
   ((void) sizeof ((is_cmdtree (root)) ? 1 : 0), __extension__ ({ if (is_cmdtree (root)) ; else __assert_fail ("is_cmdtree (root)", "cmdtree.c", 35, __extension__ __PRETTY_FUNCTION__); }));
   __builtin_va_list children;
   __builtin_va_start(children,root);
   for (;;) {
      struct cmdtree_rep *child = __builtin_va_arg(children,cmdtree);
      if (child == ((void *)0)) break;
      ((void) sizeof ((is_cmdtree (child)) ? 1 : 0), __extension__ ({ if (is_cmdtree (child)) ; else __assert_fail ("is_cmdtree (child)", "cmdtree.c", 42, __extension__ __PRETTY_FUNCTION__); }));
      if (root->last == ((void *)0)) root->first = child;
                         else root->last->next = child;
      root->last = child;
   }
   __builtin_va_end(children);
   return root;
}

variable_types:
root
struct cmdtree_rep *


decompiled_code:
int __fastcall dump_cmdtree(_QWORD *a1)
{
dump_cmdtree_rec(a1, 0);
return fflush(0LL);
}

canonical_decompiled_code:
int __fastcall func4(_QWORD *a1)
{
func2(a1, 0);
return fflush(0LL);
}

original_code:
void dump_cmdtree (cmdtree root) {
   dump_cmdtree_rec (root, 0);
   fflush (((void *)0));
}

canonical_original_code:
void dump_cmdtree(struct cmdtree_rep *root) {
   dump_cmdtree_rec (root, 0);
   fflush (((void *)0));
}


freecmd

decompiled_code:
bool __fastcall freecmd(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, const void *a6)
{
bool result; // al
__int64 i; // rbx

_debugprintf(102LL, "cmdtree.c", 101LL, "freecmd", "root=%p\n", a6);
result = is_cmdtree(a1);
if ( !result )
_assert_fail("is_cmdtree (root)", "cmdtree.c", 0x66u, "freecmd");
if ( a1 )
{
for ( i = a1[3]; ; freecmd(i) )
;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func5(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, const void *a6)
{
bool result; // al
__int64 i; // rbx

_debugprintf(102LL, "cmdtree.c", 101LL, "freecmd", "root=%p\n", a6);
result = func0(a1);
if ( !result )
_assert_fail("is_cmdtree (root)", "cmdtree.c", 0x66u, "freecmd");
if ( a1 )
{
for ( i = a1[3]; ; func5(i) )
;
}
return result;
}

original_code:
void freecmd (cmdtree root) {
   __debugprintf ('f', "cmdtree.c", 101, __func__, "root=%p\n");
   ((void) sizeof ((is_cmdtree (root)) ? 1 : 0), __extension__ ({ if (is_cmdtree (root)) ; else __assert_fail ("is_cmdtree (root)", "cmdtree.c", 102, __extension__ __PRETTY_FUNCTION__); }));
   if (root == ((void *)0)) return;
   cmdtree child = root->first;
   for (;;) {
      cmdtree old = child;
      freecmd (old);
   }
   free (root->lexinfo);
   memset (root, 0, sizeof (struct cmdtree_rep));
   free (root);
}

canonical_original_code:
void freecmd(struct cmdtree_rep *root) {
   __debugprintf ('f', "cmdtree.c", 101, __func__, "root=%p\n");
   ((void) sizeof ((is_cmdtree (root)) ? 1 : 0), __extension__ ({ if (is_cmdtree (root)) ; else __assert_fail ("is_cmdtree (root)", "cmdtree.c", 102, __extension__ __PRETTY_FUNCTION__); }));
   if (root == ((void *)0)) return;
   struct cmdtree_rep *child = root->first;
   for (;;) {
      struct cmdtree_rep *old = child;
      freecmd (old);
   }
   free (root->lexinfo);
   memset (root, 0, sizeof (struct cmdtree_rep));
   free (root);
}