decompiled_code:
int __fastcall generator_yield(__int64 a1, __int64 a2)
{
pthread_cond_t *v2; // rbp
void **v3; // r14
__int64 v4; // rax
int result; // eax

v2 = (pthread_cond_t *)(a1 + 64);
pthread_testcancel();
if ( *(_DWORD *)(a1 + 112) == -1 )
{
*(_QWORD *)(a1 + 128) = a2;
*(_DWORD *)(a1 + 136) = 1;
result = pthread_cond_signal((pthread_cond_t *)(a1 + 64));
if ( *(_DWORD *)(a1 + 136) )
{
do
{
pthread_cond_wait(v2, (pthread_mutex_t *)(a1 + 24));
result = *(_DWORD *)(a1 + 136);
}
while ( result );
}
}
else
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
pthread_testcancel();
v3 = *(void ***)(a1 + 136);
*v3 = calloc(1uLL, 0x10uLL);
v4 = *(_QWORD *)(a1 + 136);
*(_QWORD *)(*(_QWORD *)v4 + 8LL) = a2;
*(_QWORD *)(a1 + 136) = *(_QWORD *)v4;
pthread_cond_signal(v2);
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
pthread_cond_t *v2; // rbp
void **v3; // r14
__int64 v4; // rax
int result; // eax

v2 = (pthread_cond_t *)(a1 + 64);
pthread_testcancel();
if ( *(_DWORD *)(a1 + 112) == -1 )
{
*(_QWORD *)(a1 + 128) = a2;
*(_DWORD *)(a1 + 136) = 1;
result = pthread_cond_signal((pthread_cond_t *)(a1 + 64));
if ( *(_DWORD *)(a1 + 136) )
{
do
{
pthread_cond_wait(v2, (pthread_mutex_t *)(a1 + 24));
result = *(_DWORD *)(a1 + 136);
}
while ( result );
}
}
else
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
pthread_testcancel();
v3 = *(void ***)(a1 + 136);
*v3 = calloc(1uLL, 0x10uLL);
v4 = *(_QWORD *)(a1 + 136);
*(_QWORD *)(*(_QWORD *)v4 + 8LL) = a2;
*(_QWORD *)(a1 + 136) = *(_QWORD *)v4;
pthread_cond_signal(v2);
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
return result;
}

original_code:
void
generator_yield(generator *g, void *item) {
 pthread_testcancel();
 if(g->async == -1) {
  g->item = item;
  g->has_item = 1;
  pthread_cond_signal(&g->cond);
  while(g->has_item) {
   pthread_cond_wait(&g->cond, &g->lock);
  }
 } else {
  pthread_mutex_lock(&g->lock);
  pthread_testcancel();
  *g->output_last = calloc(1, sizeof(struct generator_item));
  (*g->output_last)->item = item;
  g->output_last = &((*g->output_last)->next);
  pthread_cond_signal(&g->cond);
  pthread_mutex_unlock(&g->lock);
 }
}

canonical_original_code:
void generator_yield(struct _generator *g, void *item) {
 pthread_testcancel();
 if(g->async == -1) {
  g->item = item;
  g->has_item = 1;
  pthread_cond_signal(&g->cond);
  while(g->has_item) {
   pthread_cond_wait(&g->cond, &g->lock);
  }
 } else {
  pthread_mutex_lock(&g->lock);
  pthread_testcancel();
  *g->output_last = calloc(1, sizeof(struct generator_item));
  (*g->output_last)->item = item;
  g->output_last = &((*g->output_last)->next);
  pthread_cond_signal(&g->cond);
  pthread_mutex_unlock(&g->lock);
 }
}

variable_types:
item
void *


repo: Jille/splparser

decompiled_code:
__int64 __fastcall generator_eof(__int64 a1)
{
__int64 v1; // rax
pthread_mutex_t *i; // rbp
__int64 j; // rax
unsigned int v4; // er8
int v6; // eax
pthread_cond_t *v7; // rbp

v1 = *(_QWORD *)(a1 + 120);
if ( *(_DWORD *)(a1 + 112) != -1 )
{
for ( i = (pthread_mutex_t *)(a1 + 24); !v1; v1 = *(_QWORD *)(a1 + 120) )
{
pthread_mutex_lock(i);
for ( j = *(_QWORD *)(a1 + 128); !j; j = *(_QWORD *)(a1 + 128) )
pthread_cond_wait((pthread_cond_t *)(a1 + 64), i);
*(_QWORD *)(a1 + 120) = j;
*(_QWORD *)(a1 + 128) = 0LL;
*(_QWORD *)(a1 + 136) = a1 + 128;
pthread_mutex_unlock(i);
}
return v1 == -1;
}
v4 = 0;
if ( v1 )
return v4;
v6 = *(_DWORD *)(a1 + 136);
if ( !v6 )
{
v7 = (pthread_cond_t *)(a1 + 64);
do
{
pthread_cond_signal(v7);
pthread_cond_wait(v7, (pthread_mutex_t *)(a1 + 24));
v6 = *(_DWORD *)(a1 + 136);
}
while ( !v6 );
}
return v6 == -1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
pthread_mutex_t *i; // rbp
__int64 j; // rax
unsigned int v4; // er8
int v6; // eax
pthread_cond_t *v7; // rbp

v1 = *(_QWORD *)(a1 + 120);
if ( *(_DWORD *)(a1 + 112) != -1 )
{
for ( i = (pthread_mutex_t *)(a1 + 24); !v1; v1 = *(_QWORD *)(a1 + 120) )
{
pthread_mutex_lock(i);
for ( j = *(_QWORD *)(a1 + 128); !j; j = *(_QWORD *)(a1 + 128) )
pthread_cond_wait((pthread_cond_t *)(a1 + 64), i);
*(_QWORD *)(a1 + 120) = j;
*(_QWORD *)(a1 + 128) = 0LL;
*(_QWORD *)(a1 + 136) = a1 + 128;
pthread_mutex_unlock(i);
}
return v1 == -1;
}
v4 = 0;
if ( v1 )
return v4;
v6 = *(_DWORD *)(a1 + 136);
if ( !v6 )
{
v7 = (pthread_cond_t *)(a1 + 64);
do
{
pthread_cond_signal(v7);
pthread_cond_wait(v7, (pthread_mutex_t *)(a1 + 24));
v6 = *(_DWORD *)(a1 + 136);
}
while ( !v6 );
}
return v6 == -1;
}

original_code:
int
generator_eof(generator *g) {
 if(g->async == -1) {
  if(g->ready != ((void *)0)) {
   return 0;
  }
  while(g->has_item == 0) {
   pthread_cond_signal(&g->cond);
   pthread_cond_wait(&g->cond, &g->lock);
  }
  return (g->has_item == -1);
 } else {
  while(g->ready == ((void *)0)) {
   pthread_mutex_lock(&g->lock);
   while(g->output == ((void *)0)) {
    pthread_cond_wait(&g->cond, &g->lock);
   }
   g->ready = g->output;
   g->output = ((void *)0);
   g->output_last = &g->output;
   pthread_mutex_unlock(&g->lock);
  }
  return (g->ready == (void *)-1);
 }
}

canonical_original_code:
int generator_eof(struct _generator *g) {
 if(g->async == -1) {
  if(g->ready != ((void *)0)) {
   return 0;
  }
  while(g->has_item == 0) {
   pthread_cond_signal(&g->cond);
   pthread_cond_wait(&g->cond, &g->lock);
  }
  return (g->has_item == -1);
 } else {
  while(g->ready == ((void *)0)) {
   pthread_mutex_lock(&g->lock);
   while(g->output == ((void *)0)) {
    pthread_cond_wait(&g->cond, &g->lock);
   }
   g->ready = g->output;
   g->output = ((void *)0);
   g->output_last = &g->output;
   pthread_mutex_unlock(&g->lock);
  }
  return (g->ready == (void *)-1);
 }
}

variable_types: struct _generator { unsigned long thr; void (*function)(struct _generator *, void *); void *arg; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int async; struct generator_item { struct generator_item *next; void *item; } *ready; union { struct { void *item; int has_item; }; struct { struct generator_item *output; struct generator_item **output_last; }; }; } *

return_type: int

user_defined_types: struct _generator { unsigned long thr; void (*function)(struct _generator *, void *); void *arg; union pthread_mutex_t lock; union pthread_cond_t cond; int async; struct generator_item *ready; union { struct { void *item; int has_item; }; struct { struct generator_item *output; struct generator_item **output_last; }; }; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


original_code:
void *
generator_shift(generator *g) {
 void *ret;
 if(generator_eof(g)) {
  return ((void *)0);
 }
 if(g->async == -1 && g->ready == ((void *)0)) {
  ret = g->item;
  g->item = ((void *)0);
  if(g->has_item == -2) {
   g->has_item = -1;
  } else {
   g->has_item = 0;
  }
 } else {
  void *container = g->ready;
  ret = g->ready->item;
  g->ready = g->ready->next;
  free(container);
 }
 return ret;
}

canonical_original_code:
void *generator_shift(struct _generator *g) {
 void *ret;
 if(generator_eof(g)) {
  return ((void *)0);
 }
 if(g->async == -1 && g->ready == ((void *)0)) {
  ret = g->item;
  g->item = ((void *)0);
  if(g->has_item == -2) {
   g->has_item = -1;
  } else {
   g->has_item = 0;
  }
 } else {
  void *container = g->ready;
  ret = g->ready->item;
  g->ready = g->ready->next;
  free(container);
 }
 return ret;
}

variable_types:
ret
void *

variable_types:
container
void *

return_type: void *

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct generator_item { struct generator_item *next; void *item; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
void __fastcall generator_destroy(void *ptr)
{
_DWORD *v2; // rdi
_QWORD *v3; // rdx
_QWORD *i; // rdi

if ( *((_DWORD *)ptr + 28) == -1 )
{
v2 = *(_DWORD **)ptr;
if ( !*v2 )
goto LABEL_8;
goto LABEL_3;
}
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 24));
v2 = *(_DWORD **)ptr;
if ( **(_DWORD **)ptr )
LABEL_3:
pthread_cancel((pthread_t)v2);
if ( *((_DWORD *)ptr + 28) != -1 )
{
v3 = (_QWORD *)*((_QWORD *)ptr + 17);
if ( (unsigned __int64)(*v3 - 1LL) <= 0xFFFFFFFFFFFFFFFDLL )
_assert_fail(
"*g->output_last == NULL || *g->output_last == (void *)-1",
"generator.c",
0x98u,
"generator_destroy");
*v3 = *((_QWORD *)ptr + 15);
for ( i = (_QWORD *)*((_QWORD *)ptr + 16);
(unsigned __int64)i - 1 <= 0xFFFFFFFFFFFFFFFDLL;
i = (_QWORD *)*((_QWORD *)ptr + 16) )
{
*((_QWORD *)ptr + 16) = *i;
free(i);
}
}
LABEL_8:
pthread_mutex_unlock((pthread_mutex_t *)((char *)ptr + 24));
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 24));
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 64));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
_DWORD *v2; // rdi
_QWORD *v3; // rdx
_QWORD *i; // rdi

if ( *((_DWORD *)ptr + 28) == -1 )
{
v2 = *(_DWORD **)ptr;
if ( !*v2 )
goto LABEL_8;
goto LABEL_3;
}
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 24));
v2 = *(_DWORD **)ptr;
if ( **(_DWORD **)ptr )
LABEL_3:
pthread_cancel((pthread_t)v2);
if ( *((_DWORD *)ptr + 28) != -1 )
{
v3 = (_QWORD *)*((_QWORD *)ptr + 17);
if ( (unsigned __int64)(*v3 - 1LL) <= 0xFFFFFFFFFFFFFFFDLL )
_assert_fail(
"*g->output_last == NULL || *g->output_last == (void *)-1",
"generator.c",
0x98u,
"generator_destroy");
*v3 = *((_QWORD *)ptr + 15);
for ( i = (_QWORD *)*((_QWORD *)ptr + 16);
(unsigned __int64)i - 1 <= 0xFFFFFFFFFFFFFFFDLL;
i = (_QWORD *)*((_QWORD *)ptr + 16) )
{
*((_QWORD *)ptr + 16) = *i;
free(i);
}
}
LABEL_8:
pthread_mutex_unlock((pthread_mutex_t *)((char *)ptr + 24));
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 24));
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 64));
free(ptr);
}

original_code:
void
generator_destroy(generator *g) {
 if(g->async != -1) {
  pthread_mutex_lock(&g->lock);
 }
 if(*(int *)g->thr != 0) {
  pthread_cancel(g->thr);
 }
 if(g->async != -1) {
  ((void) sizeof ((*g->output_last == ((void *)0) || *g->output_last == (void *)-1) ? 1 : 0), __extension__ ({ if (*g->output_last == ((void *)0) || *g->output_last == (void *)-1) ; else __assert_fail ("*g->output_last == NULL || *g->output_last == (void *)-1", "generator.c", 152, __extension__ __PRETTY_FUNCTION__); }));
  *g->output_last = g->ready;
  while(g->output != ((void *)0) && g->output != (void *)-1) {
   struct generator_item *c = g->output;
   g->output = c->next;
   free(c);
  }
 }
 pthread_mutex_unlock(&g->lock);
 pthread_mutex_destroy(&g->lock);
 pthread_cond_destroy(&g->cond);
 free(g);
}

canonical_original_code:
void generator_destroy(struct _generator *g) {
 if(g->async != -1) {
  pthread_mutex_lock(&g->lock);
 }
 if(*(int *)g->thr != 0) {
  pthread_cancel(g->thr);
 }
 if(g->async != -1) {
  ((void) sizeof ((*g->output_last == ((void *)0) || *g->output_last == (void *)-1) ? 1 : 0), __extension__ ({ if (*g->output_last == ((void *)0) || *g->output_last == (void *)-1) ; else __assert_fail ("*g->output_last == NULL || *g->output_last == (void *)-1", "generator.c", 152, __extension__ __PRETTY_FUNCTION__); }));
  *g->output_last = g->ready;
  while(g->output != ((void *)0) && g->output != (void *)-1) {
   struct generator_item *c = g->output;
   g->output = c->next;
   free(c);
  }
 }
 pthread_mutex_unlock(&g->lock);
 pthread_mutex_destroy(&g->lock);
 pthread_cond_destroy(&g->cond);
 free(g);
}

variable_types: struct generator_item { struct generator_item *next; void *item; } *

return_type: void


original_code:
int
lazyarray_exists(lazyarray *la, int num) {
 while(num >= la->last) {
  if(generator_eof(la->g)) {
   return 0;
  }
  if(la->last == la->size) {
   la->size *= 2;
   la->array = realloc(la->array, la->size * sizeof(void *));
  }
  la->array[la->last++] = generator_shift(la->g);
 }
 return 1;
}

canonical_original_code:
int lazyarray_exists(struct _lazyarray *la, int num) {
 while(num >= la->last) {
  if(generator_eof(la->g)) {
   return 0;
  }
  if(la->last == la->size) {
   la->size *= 2;
   la->array = realloc(la->array, la->size * sizeof(void *));
  }
  la->array[la->last++] = generator_shift(la->g);
 }
 return 1;
}

variable_types: struct _lazyarray { struct _generator { unsigned long thr; void (*function)(struct _generator *, void *); void *arg; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int async; struct generator_item { struct generator_item *next; void *item; } *ready; union { struct { void *item; int has_item; }; struct { struct generator_item *output; struct generator_item **output_last; }; }; } *g; void **array; int last; int size; } *

variable_types: num int

user_defined_types: struct _lazyarray { struct _generator *g; void **array; int last; int size; }


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

if ( (unsigned int)lazyarray_exists(a1, a2) )
result = *(_QWORD *)(a1[1] + 8LL * a2);
else
result = 0LL;
return result;
}

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

if ( (unsigned int)func0(a1, a2) )
result = *(_QWORD *)(a1[1] + 8LL * a2);
else
result = 0LL;
return result;
}

original_code:
void *
lazyarray_get(lazyarray *la, int num) {
 if(!lazyarray_exists(la, num)) {
  return ((void *)0);
 }
 return la->array[num];
}

canonical_original_code:
void *lazyarray_get(struct _lazyarray *la, int num) {
 if(!lazyarray_exists(la, num)) {
  return ((void *)0);
 }
 return la->array[num];
}


decompiled_code:
void __fastcall lazyarray_destroy(__int64 a1)
{
generator_destroy(*(_QWORD *)a1);
free(*(void **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
generator_destroy(*(_QWORD *)a1);
free(*(void **)(a1 + 8));
}

original_code:
void
lazyarray_destroy(lazyarray *la) {
 generator_destroy(la->g);
 free(la->array);
}

canonical_original_code:
void lazyarray_destroy(struct _lazyarray *la) {
 generator_destroy(la->g);
 free(la->array);
}


repo: JinTu/sandbox

decompiled_code:
const char *__fastcall bus_str(int a1)
{
__int64 v1; // rdi
const char *result; // rax

v1 = (unsigned int)(a1 - 3);
result = "Other";
if ( (unsigned int)v1 <= 3 )
result = CSWTCH_12[v1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func8(int a1)
{
__int64 v1; // rdi
const char *result; // rax

v1 = (unsigned int)(a1 - 3);
result = "Other";
if ( (unsigned int)v1 <= 3 )
result = CSWTCH_12[v1];
return result;
}

original_code:
const char *
bus_str(int bus)
{
 switch (bus) {
 case 0x03:
  return "USB";
  break;
 case 0x04:
  return "HIL";
  break;
 case 0x05:
  return "Bluetooth";
  break;
 case 0x06:
  return "Virtual";
  break;
 default:
  return "Other";
  break;
 }
}

canonical_original_code:
char *bus_str(int bus)
{
 switch (bus) {
 case 0x03:
  return "USB";
  break;
 case 0x04:
  return "HIL";
  break;
 case 0x05:
  return "Bluetooth";
  break;
 case 0x06:
  return "Virtual";
  break;
 default:
  return "Other";
  break;
 }
}

variable_types: bus int

return_type: char *


repo: JnuSimba/APUE

decompiled_code:
int my_exit1()
{
return puts("my exit1 ... ");
}

canonical_decompiled_code:
int func7()
{
return puts("my exit1 ... ");
}

original_code:
void my_exit1(void)
{
 printf("my exit1 ... \n");
}

canonical_original_code:
void my_exit1()
{
 printf("my exit1 ... \n");
}


decompiled_code:
int my_exit2()
{
return puts("my exit2 ... ");
}

canonical_decompiled_code:
int func8()
{
return puts("my exit2 ... ");
}

original_code:
void my_exit2(void)
{
 printf("my exit2 ... \n");
}

canonical_original_code:
void my_exit2()
{
 printf("my exit2 ... \n");
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
printf("hello world");
putchar(10);
atexit(my_exit1, argv);
atexit(my_exit2, argv);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
printf("hello world");
putchar(10);
func11(my_exit1, argv);
func11(my_exit2, argv);
exit(0);
}

original_code:
int main(int argc, char *argv[])
{
 printf("hello world");
 printf("\n");
 atexit(my_exit1);
 atexit(my_exit2);
 exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall my_system(__int64 a1)
{
__pid_t v1; // eax
__pid_t v2; // ebx
int stat_loc[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( !a1 )
return 1LL;
v1 = fork();
v2 = v1;
if ( v1 < 0 )
return 0xFFFFFFFFLL;
if ( !v1 )
{
execl("/bin/sh", "sh", &unk_402004, a1, 0LL);
exit(127);
}
while ( waitpid(v2, stat_loc, 0) < 0 )
{
if ( *__errno_location() != 4 )
return 0xFFFFFFFFLL;
}
return (unsigned int)stat_loc[0];
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__pid_t v1; // eax
__pid_t v2; // ebx
int stat_loc[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( !a1 )
return 1LL;
v1 = fork();
v2 = v1;
if ( v1 < 0 )
return 0xFFFFFFFFLL;
if ( !v1 )
{
execl("/bin/sh", "sh", &unk_402004, a1, 0LL);
exit(127);
}
while ( waitpid(v2, stat_loc, 0) < 0 )
{
if ( *__errno_location() != 4 )
return 0xFFFFFFFFLL;
}
return (unsigned int)stat_loc[0];
}

original_code:
int my_system(const char* command)
{
 pid_t pid;
 int status;
 if (command == ((void *)0))
  return 1;
 if ((pid = fork()) < 0)
   status = -1;
 else if (pid == 0) {
  execl("/bin/sh", "sh", "-c", command, ((void *)0));
  exit(127);
 }
 else {
  while (waitpid(pid, &status, 0) < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   status = -1;
   break;
  }
 }
 return status;
}

canonical_original_code:
int my_system(char *command)
{
 int pid;
 int status;
 if (command == ((void *)0))
  return 1;
 if ((pid = fork()) < 0)
   status = -1;
 else if (pid == 0) {
  execl("/bin/sh", "sh", "-c", command, ((void *)0));
  exit(127);
 }
 else {
  while (waitpid(pid, &status, 0) < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   status = -1;
   break;
  }
 }
 return status;
}

variable_types:
command
char *

variable_types: pid int

variable_types: status int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
my_system("ls -l | wc -w", argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7("ls -l | wc -w", argv, envp);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 my_system("ls -l | wc -w");
 return 0;
}


decompiled_code:
__int64 __fastcall my_signal(int sig, void (*a2)(int))
{
bool v2; // sf
__int64 result; // rax
struct sigaction v4; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v5; // [rsp+A0h] [rbp-A8h] BYREF

v4.sa_handler = a2;
sigemptyset(&v4.sa_mask);
v4.sa_flags = 0;
v2 = sigaction(sig, &v4, &v5) < 0;
result = -1LL;
if ( !v2 )
result = (__int64)v5.sa_handler;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int sig, void (*a2)(int))
{
bool v2; // sf
__int64 result; // rax
struct sigaction v4; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v5; // [rsp+A0h] [rbp-A8h] BYREF

v4.sa_handler = a2;
sigemptyset(&v4.sa_mask);
v4.sa_flags = 0;
v2 = sigaction(sig, &v4, &v5) < 0;
result = -1LL;
if ( !v2 )
result = (__int64)v5.sa_handler;
return result;
}

original_code:
__sighandler_t my_signal(int sig, __sighandler_t handler)
{
 struct sigaction act;
 struct sigaction oldact;
 act.__sigaction_handler.sa_handler = handler;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 if (sigaction(sig, &act, &oldact) < 0)
  return ((__sighandler_t) -1);
 return oldact.__sigaction_handler.sa_handler;
}

canonical_original_code:
void (*my_signal(int sig, void (*handler)(int)))(int)
{
 struct sigaction act;
 struct sigaction oldact;
 act.__sigaction_handler.sa_handler = handler;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 if (sigaction(sig, &act, &oldact) < 0)
  return ((__sighandler_t) -1);
 return oldact.__sigaction_handler.sa_handler;
}

variable_types: sig int

variable_types:
handler
void (*)(int)

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

return_type: void (*)(int)

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
my_signal(2);
while ( 1 )
pause();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func8(2);
while ( 1 )
pause();
}

original_code:
int main(int argc, char *argv[])
{
 my_signal(2, handler);
 for (; ;)
  pause();
 return 0;
}


handler

decompiled_code:
int __fastcall handler(unsigned int a1)
{
return printf("rev sig=%d\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
return printf("rev sig=%d\n", a1);
}

original_code:
void handler(int sig)
{
 printf("rev sig=%d\n", sig);
}


decompiled_code:
__int64 read_command()
{
return (unsigned int)-(fgets(cmdline, 1024, stdin) == 0LL);
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)-(fgets(cmdline, 1024, stdin) == 0LL);
}

original_code:
int read_command(void)
{
 if (fgets(cmdline, 1024, stdin) == ((void *)0))
  return -1;
 return 0;
}

canonical_original_code:
int read_command()
{
 if (fgets(cmdline, 1024, stdin) == ((void *)0))
  return -1;
 return 0;
}


decompiled_code:
__int64 execute_command()
{
execute_disk_command();
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
func19();
return 0LL;
}

original_code:
int execute_command(void)
{
 execute_disk_command();
 return 0;
}

canonical_original_code:
int execute_command()
{
 execute_disk_command();
 return 0;
}


decompiled_code:
__int64 __fastcall get_command(int a1)
{
__int64 result; // rax
char v2; // cl
__int64 i; // r9
char *v4; // rdx
char v5; // cl
_BYTE *v6; // rsi
bool v7; // dl
char v8; // cl
bool v9; // r13
bool v10; // dl
char v11; // cl
int v12; // er13

result = lineptr;
v2 = *(_BYTE *)lineptr;
if ( *(_BYTE *)lineptr )
{
for ( i = 0LL; ; ++i )
{
if ( v2 == 32 || v2 == 9 )
{
v4 = (char *)(result + 1);
do
{
do
{
lineptr = (__int64)v4;
v5 = *v4;
result = (__int64)v4++;
}
while ( v5 == 32 );
}
while ( v5 == 9 );
}
v6 = (_BYTE *)avptr;
v7 = 1;
cmd[22 * a1 + i] = avptr;
v8 = *(_BYTE *)result;
if ( *(_BYTE *)result <= 0x3Eu )
v7 = ((0x5000004100000600uLL >> v8) & 1) == 0;
v9 = v7 && v8 != 124;
if ( v9 )
{
do
{
lineptr = result + 1;
avptr = (__int64)(v6 + 1);
v10 = v9;
*v6 = *(_BYTE *)result;
result = lineptr;
v11 = *(_BYTE *)lineptr;
if ( *(_BYTE *)lineptr <= 0x3Eu )
v10 = ((0x5000004100000600uLL >> v11) & 1) == 0;
v6 = (_BYTE *)avptr;
}
while ( v11 != 124 && v10 );
v12 = 1;
}
else
{
v12 = 0;
}
avptr = (__int64)(v6 + 1);
*v6 = 0;
result = lineptr;
v2 = *(_BYTE *)lineptr;
if ( *(char *)lineptr > 60 )
break;
if ( v2 <= 8 )
return result;
if ( ((1LL << v2) & 0x1000004000000400LL) != 0 )
goto LABEL_24;
if ( ((1LL << v2) & 0x100000200LL) == 0 )
return result;
}
if ( v2 == 62 || v2 == 124 )
{
LABEL_24:
if ( !v12 )
{
result = (int)i + 22LL * a1;
cmd[result] = 0LL;
}
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
__int64 result; // rax
char v2; // cl
__int64 i; // r9
char *v4; // rdx
char v5; // cl
_BYTE *v6; // rsi
bool v7; // dl
char v8; // cl
bool v9; // r13
bool v10; // dl
char v11; // cl
int v12; // er13

result = lineptr;
v2 = *(_BYTE *)lineptr;
if ( *(_BYTE *)lineptr )
{
for ( i = 0LL; ; ++i )
{
if ( v2 == 32 || v2 == 9 )
{
v4 = (char *)(result + 1);
do
{
do
{
lineptr = (__int64)v4;
v5 = *v4;
result = (__int64)v4++;
}
while ( v5 == 32 );
}
while ( v5 == 9 );
}
v6 = (_BYTE *)avptr;
v7 = 1;
cmd[22 * a1 + i] = avptr;
v8 = *(_BYTE *)result;
if ( *(_BYTE *)result <= 0x3Eu )
v7 = ((0x5000004100000600uLL >> v8) & 1) == 0;
v9 = v7 && v8 != 124;
if ( v9 )
{
do
{
lineptr = result + 1;
avptr = (__int64)(v6 + 1);
v10 = v9;
*v6 = *(_BYTE *)result;
result = lineptr;
v11 = *(_BYTE *)lineptr;
if ( *(_BYTE *)lineptr <= 0x3Eu )
v10 = ((0x5000004100000600uLL >> v11) & 1) == 0;
v6 = (_BYTE *)avptr;
}
while ( v11 != 124 && v10 );
v12 = 1;
}
else
{
v12 = 0;
}
avptr = (__int64)(v6 + 1);
*v6 = 0;
result = lineptr;
v2 = *(_BYTE *)lineptr;
if ( *(char *)lineptr > 60 )
break;
if ( v2 <= 8 )
return result;
if ( ((1LL << v2) & 0x1000004000000400LL) != 0 )
goto LABEL_24;
if ( ((1LL << v2) & 0x100000200LL) == 0 )
return result;
}
if ( v2 == 62 || v2 == 124 )
{
LABEL_24:
if ( !v12 )
{
result = (int)i + 22LL * a1;
cmd[result] = 0LL;
}
return result;
}
}
return result;
}

original_code:
void get_command(int num)
{
 int j = 0;
 int inword = 0;
 while(*lineptr != '\0')
 {
  while(*lineptr == ' ' || *lineptr == '\t')
   lineptr++;
  cmd[num].args[j] = avptr;
  while(*lineptr != ' '
   && *lineptr != '\t'
   && *lineptr != '|'
   && *lineptr != '<'
   && *lineptr != '>'
   && *lineptr != '&'
   && *lineptr != '\n')
  {
    *avptr++ = *lineptr++;
    inword = 1;
  }
  *avptr++ = '\0';
  switch(*lineptr)
  {
   case ' ':
   case '\t':
    inword = 0;
    j++;
    break;
   case '<':
   case '>':
   case '|':
   case '&':
   case '\n':
    if (inword == 0)
     cmd[num].args[j] = ((void *)0);
    return;
   default:
    return;
  }
 }
}

variable_types: j int

variable_types: inword int


check

decompiled_code:
__int64 __fastcall check(char *a1)
{
char *v1; // rdx
char *v2; // rax
char v3; // cl
char v4; // al
__int64 result; // rax

v1 = (char *)lineptr;
if ( *(_BYTE *)lineptr != 32 && *(_BYTE *)lineptr != 9 )
goto LABEL_9;
v2 = (char *)(lineptr + 1);
do
{
do
{
lineptr = (__int64)v2;
v3 = *v2;
v1 = v2++;
}
while ( v3 == 32 );
}
while ( v3 == 9 );
v4 = *a1;
if ( *a1 )
{
while ( *v1 == v4 )
{
++a1;
++v1;
LABEL_9:
v4 = *a1;
if ( !*a1 )
goto LABEL_10;
}
result = 0LL;
}
else
{
LABEL_10:
lineptr = (__int64)v1;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1)
{
char *v1; // rdx
char *v2; // rax
char v3; // cl
char v4; // al
__int64 result; // rax

v1 = (char *)lineptr;
if ( *(_BYTE *)lineptr != 32 && *(_BYTE *)lineptr != 9 )
goto LABEL_9;
v2 = (char *)(lineptr + 1);
do
{
do
{
lineptr = (__int64)v2;
v3 = *v2;
v1 = v2++;
}
while ( v3 == 32 );
}
while ( v3 == 9 );
v4 = *a1;
if ( *a1 )
{
while ( *v1 == v4 )
{
++a1;
++v1;
LABEL_9:
v4 = *a1;
if ( !*a1 )
goto LABEL_10;
}
result = 0LL;
}
else
{
LABEL_10:
lineptr = (__int64)v1;
result = 1LL;
}
return result;
}

original_code:
int check(const char* str)
{
 while(*lineptr == ' ' || *lineptr == '\t')
   lineptr++;
 char* p = lineptr;
 while(*str != '\0' && *p == *str)
 {
  str++;
  p++;
 }
 if(*str == '\0')
 {
  lineptr = p;
  return 1;
 }
 return 0;
}

canonical_original_code:
int check(char *str)
{
 while(*lineptr == ' ' || *lineptr == '\t')
   lineptr++;
 char *p = lineptr;
 while(*str != '\0' && *p == *str)
 {
  str++;
  p++;
 }
 if(*str == '\0')
 {
  lineptr = p;
  return 1;
 }
 return 0;
}

variable_types:
str
char *

variable_types:
p
char *


decompiled_code:
__int64 parse_command()
{
unsigned int v0; // er12
int v1; // edi

if ( (unsigned int)check("\n") || (unsigned int)builtins() )
return (unsigned int)-1;
get_command(0);
if ( (unsigned int)check((char *)asc_402004) )
get_name(infile);
v0 = 1;
do
{
if ( !(unsigned int)check((char *)&asc_402004[1]) )
break;
v1 = v0++;
get_command(v1);
}
while ( v0 != 5 );
if ( (unsigned int)check((char *)&asc_402004[2]) )
{
if ( (unsigned int)check((char *)&asc_402004[2]) )
append = 1;
get_name(outfile);
}
if ( (unsigned int)check((char *)&asc_402004[3]) )
backgnd = 1;
if ( !(unsigned int)check("\n") )
{
fwrite("command line syntax error.\n", 1uLL, 0x1BuLL, stderr);
return (unsigned int)-1;
}
cmd_count = v0;
return v0;
}

canonical_decompiled_code:
__int64 func12()
{
unsigned int v0; // er12
int v1; // edi

if ( (unsigned int)func11("\n") || (unsigned int)func21() )
return (unsigned int)-1;
func9(0);
if ( (unsigned int)func11((char *)asc_402004) )
func10(infile);
v0 = 1;
do
{
if ( !(unsigned int)func11((char *)&asc_402004[1]) )
break;
v1 = v0++;
func9(v1);
}
while ( v0 != 5 );
if ( (unsigned int)func11((char *)&asc_402004[2]) )
{
if ( (unsigned int)func11((char *)&asc_402004[2]) )
append = 1;
func10(outfile);
}
if ( (unsigned int)func11((char *)&asc_402004[3]) )
backgnd = 1;
if ( !(unsigned int)func11("\n") )
{
fwrite("command line syntax error.\n", 1uLL, 0x1BuLL, stderr);
return (unsigned int)-1;
}
cmd_count = v0;
return v0;
}

original_code:
int parse_command(void)
{
 if (check("\n"))
  return -1;
 if(builtins())
  return -1;
 get_command(0);
 if (check("<"))
  get_name(infile);
 int i;
 for (i = 1; i < 5; i++)
 {
  if (check("|"))
   get_command(i);
  else
   break;
 }
 if(check(">"))
 {
  if(check(">"))
   append = 1;
  get_name(outfile);
 }
 if(check("&"))
  backgnd = 1;
 if(check("\n"))
 {
  cmd_count = i;
  return cmd_count;
 }
 else
 {
  fprintf(stderr, "command line syntax error.\n");
  return -1;
 }
}

canonical_original_code:
int parse_command()
{
 if (check("\n"))
  return -1;
 if(builtins())
  return -1;
 get_command(0);
 if (check("<"))
  get_name(infile);
 int i;
 for (i = 1; i < 5; i++)
 {
  if (check("|"))
   get_command(i);
  else
   break;
 }
 if(check(">"))
 {
  if(check(">"))
   append = 1;
  get_name(outfile);
 }
 if(check("&"))
  backgnd = 1;
 if(check("\n"))
 {
  cmd_count = i;
  return cmd_count;
 }
 else
 {
  fprintf(stderr, "command line syntax error.\n");
  return -1;
 }
}

variable_types: i int


decompiled_code:
int shell_loop()
{
while ( 1 )
{
printf("[minishell]$ ");
fflush(_bss_start);
init();
if ( (unsigned int)read_command() == -1 )
break;
if ( (unsigned int)parse_command() != -1 )
execute_command();
}
return puts("\nexit");
}

canonical_decompiled_code:
int func13()
{
while ( 1 )
{
printf("[minishell]$ ");
fflush(_bss_start);
func17();
if ( (unsigned int)func7() == -1 )
break;
if ( (unsigned int)func12() != -1 )
func8();
}
return puts("\nexit");
}

original_code:
void shell_loop(void)
{
 while(1)
 {
  printf("[minishell]$ ");
  fflush(stdout);
  init();
  if(read_command() == -1)
   break;
  if (parse_command() != -1)
  {
   execute_command();
  }
 }
 printf("\nexit\n");
}

canonical_original_code:
void shell_loop()
{
 while(1)
 {
  printf("[minishell]$ ");
  fflush(stdout);
  init();
  if(read_command() == -1)
   break;
  if (parse_command() != -1)
  {
   execute_command();
  }
 }
 printf("\nexit\n");
}


decompiled_code:
int print_command()
{
int result; // eax
_QWORD *v1; // rbp
int v2; // er12
const char *v3; // rsi
_QWORD *i; // rbx

printf("cmd_count=%d\n", (unsigned int)cmd_count);
result = cmd_count;
if ( cmd_count > 0 )
{
v1 = &unk_404128;
v2 = 0;
do
{
v3 = (const char *)*(v1 - 1);
for ( i = v1; v3; v3 = (const char *)*(i - 1) )
{
++i;
printf("[%s] ", v3);
}
++v2;
v1 += 22;
result = putchar(10);
}
while ( cmd_count > v2 );
}
if ( !infile[0] )
{
if ( !outfile[0] )
return result;
return printf("outfile=[%s]\n", outfile);
}
result = printf("infile=[%s]\n", infile);
if ( outfile[0] )
return printf("outfile=[%s]\n", outfile);
return result;
}

canonical_decompiled_code:
int func14()
{
int result; // eax
_QWORD *v1; // rbp
int v2; // er12
const char *v3; // rsi
_QWORD *i; // rbx

printf("cmd_count=%d\n", (unsigned int)cmd_count);
result = cmd_count;
if ( cmd_count > 0 )
{
v1 = &unk_404128;
v2 = 0;
do
{
v3 = (const char *)*(v1 - 1);
for ( i = v1; v3; v3 = (const char *)*(i - 1) )
{
++i;
printf("[%s] ", v3);
}
++v2;
v1 += 22;
result = putchar(10);
}
while ( cmd_count > v2 );
}
if ( !infile[0] )
{
if ( !outfile[0] )
return result;
return printf("outfile=[%s]\n", outfile);
}
result = printf("infile=[%s]\n", infile);
if ( outfile[0] )
return printf("outfile=[%s]\n", outfile);
return result;
}

original_code:
void print_command(void)
{
 printf("cmd_count=%d\n", cmd_count);
 int i, j;
 for (i = 0; i < cmd_count ; i++ )
 {
  j = 0;
  while (cmd[i].args[j] != ((void *)0))
  {
   printf("[%s] ", cmd[i].args[j]);
   j++;
  }
  printf("\n");
 }
 if(infile[0] != '\0')
  printf("infile=[%s]\n", infile);
 if(outfile[0] != '\0')
  printf("outfile=[%s]\n", outfile);
}

canonical_original_code:
void print_command()
{
 printf("cmd_count=%d\n", cmd_count);
 int i; int j;
 for (i = 0; i < cmd_count ; i++ )
 {
  j = 0;
  while (cmd[i].args[j] != ((void *)0))
  {
   printf("[%s] ", cmd[i].args[j]);
   j++;
  }
  printf("\n");
 }
 if(infile[0] != '\0')
  printf("infile=[%s]\n", infile);
 if(outfile[0] != '\0')
  printf("outfile=[%s]\n", outfile);
}


decompiled_code:
void int_handler()
{
printf("\n[minishell]$ ");
fflush(_bss_start);
}

canonical_decompiled_code:
void func15()
{
printf("\n[minishell]$ ");
fflush(_bss_start);
}

original_code:
void int_handler(int sig)
{
 printf("\n[minishell]$ ");
 fflush(stdout);
}


setup

decompiled_code:
__sighandler_t setup()
{
signal(2, (__sighandler_t)int_handler);
return signal(3, (__sighandler_t)1);
}

canonical_decompiled_code:
__sighandler_t func16()
{
signal(2, (__sighandler_t)int_handler);
return signal(3, (__sighandler_t)1);
}

original_code:
void setup(void)
{
 signal(2, int_handler);
 signal(3, ((__sighandler_t) 1));
}

canonical_original_code:
void setup()
{
 signal(2, int_handler);
 signal(3, ((void (*)(int)) 1));
}


init

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

result = 0LL;
*(_QWORD *)cmdline = 0LL;
qword_404DD9 = 0LL;
memset(
(void *)((unsigned __int64)&unk_4049E8 & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)cmdline - (unsigned int)((unsigned __int64)&unk_4049E8 & 0xFFFFFFFFFFFFFFF8LL) + 1025) >> 3));
memset(cmd, 0, 0x370uLL);
avgline = 0LL;
qword_4049B9 = 0LL;
memset(
(void *)((unsigned __int64)&unk_4045C8 & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)&avgline - (unsigned int)((unsigned __int64)&unk_4045C8 & 0xFFFFFFFFFFFFFFF8LL) + 1025) >> 3));
lineptr = (__int64)cmdline;
avptr = (__int64)&avgline;
cmd_count = 0;
backgnd = 0;
append = 0;
*(_QWORD *)outfile = 0LL;
qword_40451D = 0LL;
memset(
(void *)((unsigned __int64)&unk_4044C8 & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)outfile - (unsigned int)((unsigned __int64)&unk_4044C8 & 0xFFFFFFFFFFFFFFF8LL) + 101) >> 3));
*(_QWORD *)infile = 0LL;
qword_40459D = 0LL;
memset(
(void *)((unsigned __int64)&unk_404548 & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)infile - (unsigned int)((unsigned __int64)&unk_404548 & 0xFFFFFFFFFFFFFFF8LL) + 101) >> 3));
dword_4041CC = 1;
dword_40427C = 1;
dword_40432C = 1;
dword_4043DC = 1;
dword_40448C = 1;
lastpid = 0;
return result;
}

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

result = 0LL;
*(_QWORD *)cmdline = 0LL;
qword_404DD9 = 0LL;
memset(
(void *)((unsigned __int64)&unk_4049E8 & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)cmdline - (unsigned int)((unsigned __int64)&unk_4049E8 & 0xFFFFFFFFFFFFFFF8LL) + 1025) >> 3));
memset(cmd, 0, 0x370uLL);
avgline = 0LL;
qword_4049B9 = 0LL;
memset(
(void *)((unsigned __int64)&unk_4045C8 & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)&avgline - (unsigned int)((unsigned __int64)&unk_4045C8 & 0xFFFFFFFFFFFFFFF8LL) + 1025) >> 3));
lineptr = (__int64)cmdline;
avptr = (__int64)&avgline;
cmd_count = 0;
backgnd = 0;
append = 0;
*(_QWORD *)outfile = 0LL;
qword_40451D = 0LL;
memset(
(void *)((unsigned __int64)&unk_4044C8 & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)outfile - (unsigned int)((unsigned __int64)&unk_4044C8 & 0xFFFFFFFFFFFFFFF8LL) + 101) >> 3));
*(_QWORD *)infile = 0LL;
qword_40459D = 0LL;
memset(
(void *)((unsigned __int64)&unk_404548 & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)infile - (unsigned int)((unsigned __int64)&unk_404548 & 0xFFFFFFFFFFFFFFF8LL) + 101) >> 3));
dword_4041CC = 1;
dword_40427C = 1;
dword_40432C = 1;
dword_4043DC = 1;
dword_40448C = 1;
lastpid = 0;
return result;
}

original_code:
void init(void)
{
 memset(cmdline, 0, sizeof(cmdline));
 memset(cmd, 0, sizeof(cmd));
 memset(avgline, 0, sizeof(avgline));
 lineptr = cmdline;
 avptr = avgline;
 cmd_count = 0;
 backgnd = 0;
 append = 0;
 memset(outfile, 0, sizeof(outfile));
 memset(infile, 0, sizeof(infile));
 int i;
 for (i = 0;i < 5 ; ++i )
 {
  cmd[i].infd = 0;
  cmd[i].outfd = 1;
 }
 lastpid = 0;
}

canonical_original_code:
void init()
{
 memset(cmdline, 0, sizeof(cmdline));
 memset(cmd, 0, sizeof(cmd));
 memset(avgline, 0, sizeof(avgline));
 lineptr = cmdline;
 avptr = avgline;
 cmd_count = 0;
 backgnd = 0;
 append = 0;
 memset(outfile, 0, sizeof(outfile));
 memset(infile, 0, sizeof(infile));
 int i;
 for (i = 0;i < 5 ; ++i )
 {
  cmd[i].infd = 0;
  cmd[i].outfd = 1;
 }
 lastpid = 0;
}


forkexec

decompiled_code:
__pid_t __fastcall forkexec(int a1)
{
__int64 v1; // rbx
__pid_t result; // eax
int i; // ebp
int v4; // edi
int v5; // eax

v1 = a1;
result = fork();
if ( result == -1 )
{
perror("fork");
exit(1);
}
if ( result > 0 )
{
lastpid = result;
}
else if ( !result )
{
if ( dword_4041C8[44 * a1] || backgnd == 1 && (v5 = open("/dev/null", 0), (LODWORD(cmd[22 * a1 + 21]) = v5) != 0) )
{
close(0);
dup(dword_4041C8[44 * a1]);
}
if ( dword_4041CC[44 * a1] != 1 )
{
close(1);
dup(HIDWORD(cmd[22 * a1 + 21]));
}
for ( i = 3; i != 16; ++i )
{
v4 = i;
close(v4);
}
if ( !backgnd )
{
signal(2, 0LL);
signal(3, 0LL);
}
execvp((const char *)cmd[22 * v1], (char *const *)&cmd[22 * v1]);
exit(1);
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func18(int a1)
{
__int64 v1; // rbx
__pid_t result; // eax
int i; // ebp
int v4; // edi
int v5; // eax

v1 = a1;
result = fork();
if ( result == -1 )
{
perror("fork");
exit(1);
}
if ( result > 0 )
{
lastpid = result;
}
else if ( !result )
{
if ( dword_4041C8[44 * a1] || backgnd == 1 && (v5 = open("/dev/null", 0), (LODWORD(cmd[22 * a1 + 21]) = v5) != 0) )
{
close(0);
dup(dword_4041C8[44 * a1]);
}
if ( dword_4041CC[44 * a1] != 1 )
{
close(1);
dup(HIDWORD(cmd[22 * a1 + 21]));
}
for ( i = 3; i != 16; ++i )
{
v4 = i;
close(v4);
}
if ( !backgnd )
{
signal(2, 0LL);
signal(3, 0LL);
}
execvp((const char *)cmd[22 * v1], (char *const *)&cmd[22 * v1]);
exit(1);
}
return result;
}

original_code:
void forkexec(int num)
{
 int i;
 pid_t pid;
 pid = fork();
 if (pid == -1)
  do{ perror("fork"); exit(1);} while (0);
 if (pid > 0)
 {
  lastpid = pid;
  return;
 }
 else if(pid == 0)
 {
  if (cmd[num].infd == 0 && backgnd == 1)
   cmd[num].infd = open("/dev/null", 00);
  if(cmd[num].infd != 0)
  {
   close(0);
   dup(cmd[num].infd);
  }
  if (cmd[num].outfd != 1)
  {
   close(1);
   dup(cmd[num].outfd);
  }
  for (i = 3; i < 16; ++i )
   close(i);
  if (backgnd == 0)
  {
   signal(2, ((__sighandler_t) 0));
   signal(3, ((__sighandler_t) 0));
  }
  execvp(cmd[num].args[0], cmd[num].args);
  exit(1);
 }
}

canonical_original_code:
void forkexec(int num)
{
 int i;
 int pid;
 pid = fork();
 if (pid == -1)
  do{ perror("fork"); exit(1);} while (0);
 if (pid > 0)
 {
  lastpid = pid;
  return;
 }
 else if(pid == 0)
 {
  if (cmd[num].infd == 0 && backgnd == 1)
   cmd[num].infd = open("/dev/null", 00);
  if(cmd[num].infd != 0)
  {
   close(0);
   dup(cmd[num].infd);
  }
  if (cmd[num].outfd != 1)
  {
   close(1);
   dup(cmd[num].outfd);
  }
  for (i = 3; i < 16; ++i )
   close(i);
  if (backgnd == 0)
  {
   signal(2, ((void (*)(int)) 0));
   signal(3, ((void (*)(int)) 0));
  }
  execvp(cmd[num].args[0], cmd[num].args);
  exit(1);
 }
}


decompiled_code:
__pid_t execute_disk_command()
{
int v0; // esi
int v1; // ebx
int v2; // eax
__int64 *v3; // rbp
int i; // ebx
int v5; // edi
int v6; // edi
__pid_t result; // eax
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( backgnd )
{
signal(17, (__sighandler_t)1);
if ( !infile[0] )
goto LABEL_3;
}
else
{
signal(17, 0LL);
if ( !infile[0] )
goto LABEL_3;
}
dword_4041C8[0] = open(infile, 0);
LABEL_3:
if ( outfile[0] )
{
v0 = 577;
if ( append )
v0 = 1089;
v1 = cmd_count - 1;
dword_4041CC[44 * v1] = open(outfile, v0);
}
v2 = cmd_count;
v3 = cmd;
for ( i = 0; i < cmd_count; v3 += 22 )
{
if ( v2 - 1 > i )
{
pipe(pipedes);
*((_DWORD *)v3 + 43) = pipedes[1];
*((_DWORD *)v3 + 86) = pipedes[0];
}
forkexec(i);
v5 = *((_DWORD *)v3 + 42);
if ( v5 )
close(v5);
v6 = *((_DWORD *)v3 + 43);
if ( v6 != 1 )
close(v6);
v2 = cmd_count;
++i;
}
result = backgnd;
if ( !backgnd )
{
do
{
result = wait(0LL);
if ( result == lastpid )
break;
result = wait(0LL);
}
while ( result != lastpid );
}
return result;
}

canonical_decompiled_code:
__pid_t func19()
{
int v0; // esi
int v1; // ebx
int v2; // eax
__int64 *v3; // rbp
int i; // ebx
int v5; // edi
int v6; // edi
__pid_t result; // eax
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( backgnd )
{
signal(17, (__sighandler_t)1);
if ( !infile[0] )
goto LABEL_3;
}
else
{
signal(17, 0LL);
if ( !infile[0] )
goto LABEL_3;
}
dword_4041C8[0] = open(infile, 0);
LABEL_3:
if ( outfile[0] )
{
v0 = 577;
if ( append )
v0 = 1089;
v1 = cmd_count - 1;
dword_4041CC[44 * v1] = open(outfile, v0);
}
v2 = cmd_count;
v3 = cmd;
for ( i = 0; i < cmd_count; v3 += 22 )
{
if ( v2 - 1 > i )
{
pipe(pipedes);
*((_DWORD *)v3 + 43) = pipedes[1];
*((_DWORD *)v3 + 86) = pipedes[0];
}
func18(i);
v5 = *((_DWORD *)v3 + 42);
if ( v5 )
close(v5);
v6 = *((_DWORD *)v3 + 43);
if ( v6 != 1 )
close(v6);
v2 = cmd_count;
++i;
}
result = backgnd;
if ( !backgnd )
{
do
{
result = wait(0LL);
if ( result == lastpid )
break;
result = wait(0LL);
}
while ( result != lastpid );
}
return result;
}

original_code:
void execute_disk_command(void)
{
 int i;
 int fds[2];
 int fd;
 if (backgnd)
  signal(17, ((__sighandler_t) 1));
 else
  signal(17, ((__sighandler_t) 0));
 if (infile[0] != '\0')
  cmd[0].infd = open(infile, 00);
 if (outfile[0] != '\0')
 {
  if (append)
   cmd[cmd_count-1].outfd = open(outfile, 01 | 0100 | 02000);
  else
   cmd[cmd_count-1].outfd = open(outfile, 01 | 0100 | 01000);
 }
 for (i = 0; i < cmd_count ; ++i)
 {
  if (i < cmd_count-1)
  {
   pipe(fds);
   cmd[i].outfd = fds[1];
   cmd[i+1].infd = fds[0];
  }
  forkexec(i);
  if((fd = cmd[i].infd) != 0)
   close(fd);
  if((fd = cmd[i].outfd) != 1)
   close(fd);
 }
 if (backgnd == 0)
 {
  while (wait(((void *)0)) != lastpid)
   ;
 }
}

canonical_original_code:
void execute_disk_command()
{
 int i;
 int fds[2];
 int fd;
 if (backgnd)
  signal(17, ((void (*)(int)) 1));
 else
  signal(17, ((void (*)(int)) 0));
 if (infile[0] != '\0')
  cmd[0].infd = open(infile, 00);
 if (outfile[0] != '\0')
 {
  if (append)
   cmd[cmd_count-1].outfd = open(outfile, 01 | 0100 | 02000);
  else
   cmd[cmd_count-1].outfd = open(outfile, 01 | 0100 | 01000);
 }
 for (i = 0; i < cmd_count ; ++i)
 {
  if (i < cmd_count-1)
  {
   pipe(fds);
   cmd[i].outfd = fds[1];
   cmd[i+1].infd = fds[0];
  }
  forkexec(i);
  if((fd = cmd[i].infd) != 0)
   close(fd);
  if((fd = cmd[i].outfd) != 1)
   close(fd);
 }
 if (backgnd == 0)
 {
  while (wait(((void *)0)) != lastpid)
   ;
 }
}

variable_types:
fds
int [2]

variable_types: fd int


decompiled_code:
void __noreturn do_exit()
{
puts("exit");
exit(0);
}

canonical_decompiled_code:
void __noreturn func20()
{
puts("exit");
exit(0);
}

original_code:
void do_exit(void)
{
 printf("exit\n");
 exit(0);
}

canonical_original_code:
void do_exit()
{
 printf("exit\n");
 exit(0);
}


builtins

decompiled_code:
__int64 builtins()
{
__int64 v0; // rax

if ( !builtins_arr )
return 0LL;
if ( (unsigned int)check((char *)builtins_arr) )
{
v0 = 0LL;
}
else
{
if ( !qword_4040D0 )
return 0LL;
check((char *)qword_4040D0);
v0 = 1LL;
}
(*(&off_4040C8 + 2 * v0))();
return 1LL;
}

canonical_decompiled_code:
__int64 func21()
{
__int64 v0; // rax

if ( !builtins_arr )
return 0LL;
if ( (unsigned int)func11((char *)builtins_arr) )
{
v0 = 0LL;
}
else
{
if ( !qword_4040D0 )
return 0LL;
func11((char *)qword_4040D0);
v0 = 1LL;
}
(*(&off_4040C8 + 2 * v0))();
return 1LL;
}

original_code:
int builtins(void)
{
 int i = 0;
 int found = 0;
 while(builtins_arr[i].name != ((void *)0))
 {
  if(check(builtins_arr[i].name))
  {
   builtins_arr[i].handler();
   found = 1;
   break;
  }
  i++;
 }
 return found;
}

canonical_original_code:
int builtins()
{
 int i = 0;
 int found = 0;
 while(builtins_arr[i].name != ((void *)0))
 {
  if(check(builtins_arr[i].name))
  {
   builtins_arr[i].handler();
   found = 1;
   break;
  }
  i++;
 }
 return found;
}

variable_types: found int


printsigset

decompiled_code:
int __fastcall printsigset(sigset_t *set)
{
int i; // ebx

for ( i = 1; i != 65; ++i )
{
while ( sigismember(set, i) )
{
++i;
putchar(49);
if ( i == 65 )
return putchar(10);
}
putchar(48);
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(sigset_t *set)
{
int i; // ebx

for ( i = 1; i != 65; ++i )
{
while ( sigismember(set, i) )
{
++i;
putchar(49);
if ( i == 65 )
return putchar(10);
}
putchar(48);
}
return putchar(10);
}

original_code:
void printsigset(sigset_t* set)
{
 int i;
 for (i = 1; i < (64 + 1); i++) {
  if (sigismember(set, i))
    putchar('1');
  else
   putchar('0');
 }
 printf("\n");
}

canonical_original_code:
void printsigset(struct __sigset_t *set)
{
 int i;
 for (i = 1; i < (64 + 1); i++) {
  if (sigismember(set, i))
    putchar('1');
  else
   putchar('0');
 }
 printf("\n");
}

variable_types: struct __sigset_t { unsigned long __val[-1]; } *


decompiled_code:
int __fastcall set_flag(int fd, int a2)
{
int v2; // eax
int result; // eax

v2 = fcntl(fd, 3, 0LL);
if ( v2 == -1 )
{
perror("fcntl get flag error");
exit(1);
}
result = fcntl(fd, 4, a2 | (unsigned int)v2);
if ( result < 0 )
{
perror("fcntl set flag error");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int fd, int a2)
{
int v2; // eax
int result; // eax

v2 = fcntl(fd, 3, 0LL);
if ( v2 == -1 )
{
perror("fcntl get flag error");
exit(1);
}
result = fcntl(fd, 4, a2 | (unsigned int)v2);
if ( result < 0 )
{
perror("fcntl set flag error");
exit(1);
}
return result;
}

original_code:
void set_flag(int fd, int flags)
{
 int val;
 val = fcntl(fd, 3, 0);
 if (val == -1)
  do { perror("fcntl get flag error"); exit(1); } while(0);
 val |= flags;
 if (fcntl(fd, 4, val) < 0)
  do { perror("fcntl set flag error"); exit(1); } while(0);
}

variable_types: flags int

variable_types: val int


decompiled_code:
int __fastcall clr_flag(int fd, int a2)
{
int v2; // eax
int result; // eax

v2 = fcntl(fd, 3, 0LL);
if ( v2 == -1 )
{
perror("fcntl get flag error");
exit(1);
}
result = fcntl(fd, 4, ~a2 & (unsigned int)v2);
if ( result < 0 )
{
perror("fcntl set flag error");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int fd, int a2)
{
int v2; // eax
int result; // eax

v2 = fcntl(fd, 3, 0LL);
if ( v2 == -1 )
{
perror("fcntl get flag error");
exit(1);
}
result = fcntl(fd, 4, ~a2 & (unsigned int)v2);
if ( result < 0 )
{
perror("fcntl set flag error");
exit(1);
}
return result;
}

original_code:
void clr_flag(int fd, int flags)
{
 int val;
 val = fcntl(fd, 3, 0);
 if (val == -1)
  do { perror("fcntl get flag error"); exit(1); } while(0);
 val &= ~flags;
 if (fcntl(fd, 4, val) < 0)
  do { perror("fcntl set flag error"); exit(1); } while(0);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int128 v4; // [rsp+0h] [rbp-408h] BYREF
char v5[1008]; // [rsp+10h] [rbp-3F8h] BYREF

v4 = 0LL;
memset(v5, 0, sizeof(v5));
set_flag(0);
if ( (unsigned int)read(0, &v4, 0x400uLL) == -1 )
{
perror("read error");
exit(1);
}
printf("buf=%s\n", (const char *)&v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int128 v4; // [rsp+0h] [rbp-408h] BYREF
char v5[1008]; // [rsp+10h] [rbp-3F8h] BYREF

v4 = 0LL;
memset(v5, 0, sizeof(v5));
func7(0);
if ( (unsigned int)read(0, &v4, 0x400uLL) == -1 )
{
perror("read error");
exit(1);
}
printf("buf=%s\n", (const char *)&v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char buf[1024] = {0};
 int ret;
 set_flag(0, 04000);
 ret = read(0, buf, 1024);
 if (ret == -1)
  do { perror("read error"); exit(1); } while(0);
 printf("buf=%s\n", buf);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
buf
char [1024]

variable_types: ret int


filetype

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

printf("Filetype:");
v1 = *(_DWORD *)(a1 + 24) & 0xF000;
if ( v1 == 24576 )
{
puts("block device");
return 1LL;
}
if ( v1 <= 0x6000 )
{
switch ( v1 )
{
case 0x2000u:
puts("character device");
return 1LL;
case 0x4000u:
puts("directory");
return 0LL;
case 0x1000u:
puts("FIFO");
return 0LL;
}
goto LABEL_15;
}
if ( v1 != 40960 )
{
if ( v1 == 49152 )
{
puts("socket");
return 0LL;
}
if ( v1 == 0x8000 )
{
puts("regular file");
return 0LL;
}
LABEL_15:
puts("unknown file type");
return 0LL;
}
puts("symbolic link");
return 0LL;
}

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

printf("Filetype:");
v1 = *(_DWORD *)(a1 + 24) & 0xF000;
if ( v1 == 24576 )
{
puts("block device");
return 1LL;
}
if ( v1 <= 0x6000 )
{
switch ( v1 )
{
case 0x2000u:
puts("character device");
return 1LL;
case 0x4000u:
puts("directory");
return 0LL;
case 0x1000u:
puts("FIFO");
return 0LL;
}
goto LABEL_15;
}
if ( v1 != 40960 )
{
if ( v1 == 49152 )
{
puts("socket");
return 0LL;
}
if ( v1 == 0x8000 )
{
puts("regular file");
return 0LL;
}
LABEL_15:
puts("unknown file type");
return 0LL;
}
puts("symbolic link");
return 0LL;
}

original_code:
int filetype(struct stat *buf)
{
    int flag = 0;
    printf("Filetype:");
    mode_t mode;
    mode = buf->st_mode;
    switch (mode & 0170000) {
    case 0140000:
  printf("socket\n");
  break;
    case 0120000:
  printf("symbolic link\n");
  break;
    case 0100000:
  printf("regular file\n");
  break;
    case 0060000:
  printf("block device\n");
  flag = 1;
  break;
    case 0040000:
  printf("directory\n");
  break;
    case 0020000:
  printf("character device\n");
  flag = 1;
  break;
    case 0010000:
  printf("FIFO\n");
  break;
    default:
  printf("unknown file type\n");
  break;
    }
    return flag;
}

canonical_original_code:
int filetype(struct stat *buf)
{
    int flag = 0;
    printf("Filetype:");
    unsigned int mode;
    mode = buf->st_mode;
    switch (mode & 0170000) {
    case 0140000:
  printf("socket\n");
  break;
    case 0120000:
  printf("symbolic link\n");
  break;
    case 0100000:
  printf("regular file\n");
  break;
    case 0060000:
  printf("block device\n");
  flag = 1;
  break;
    case 0040000:
  printf("directory\n");
  break;
    case 0020000:
  printf("character device\n");
  flag = 1;
  break;
    case 0010000:
  printf("FIFO\n");
  break;
    default:
  printf("unknown file type\n");
  break;
    }
    return flag;
}

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

variable_types: flag int

variable_types:
mode
unsigned int

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


fileperm

variable_types:
perm
char []

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+5h] [rbp-A3h] BYREF
__int16 v5; // [rsp+Dh] [rbp-9Bh]
char v6; // [rsp+Fh] [rbp-99h]
struct stat stat_buf; // [rsp+10h] [rbp-98h] BYREF

if ( argc != 2 )
{
fprintf(stderr, "Usage %s file\n", *argv);
exit(1);
}
printf("Filename:%s\n", argv[1]);
if ( (unsigned int)lstat((char *)argv[1], &stat_buf) == -1 )
{
perror("stat error");
exit(1);
}
printf("file in Dev number:major %d, minor %d\n", BYTE1(stat_buf.st_dev), LOBYTE(stat_buf.st_dev));
printf("File inode:%d\n", LODWORD(stat_buf.st_ino));
if ( (unsigned int)filetype(&stat_buf) )
printf("Device number:major %d, minor %d\n", BYTE1(stat_buf.st_rdev), LOBYTE(stat_buf.st_rdev));
v4 = 0LL;
v5 = 0;
v6 = 0;
fileperm(&stat_buf, &v4);
printf("File permission bits=%o %s\n", stat_buf.st_mode & 0x1FF, (const char *)&v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+5h] [rbp-A3h] BYREF
__int16 v5; // [rsp+Dh] [rbp-9Bh]
char v6; // [rsp+Fh] [rbp-99h]
struct stat stat_buf; // [rsp+10h] [rbp-98h] BYREF

if ( argc != 2 )
{
fprintf(stderr, "Usage %s file\n", *argv);
exit(1);
}
printf("Filename:%s\n", argv[1]);
if ( (unsigned int)func11((char *)argv[1], &stat_buf) == -1 )
{
perror("stat error");
exit(1);
}
printf("file in Dev number:major %d, minor %d\n", BYTE1(stat_buf.st_dev), LOBYTE(stat_buf.st_dev));
printf("File inode:%d\n", LODWORD(stat_buf.st_ino));
if ( (unsigned int)func7(&stat_buf) )
printf("Device number:major %d, minor %d\n", BYTE1(stat_buf.st_rdev), LOBYTE(stat_buf.st_rdev));
v4 = 0LL;
v5 = 0;
v6 = 0;
func8(&stat_buf, &v4);
printf("File permission bits=%o %s\n", stat_buf.st_mode & 0x1FF, (const char *)&v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 if (argc != 2) {
     fprintf(stderr, "Usage %s file\n", argv[0]);
     exit(1);
 }
 printf("Filename:%s\n", argv[1]);
 struct stat sbuf;
 if (lstat(argv[1], &sbuf) == -1)
     do { perror("stat error"); exit(1); } while(0);
 printf("file in Dev number:major %d, minor %d\n",
        (int)((unsigned short)sbuf.st_dev >> 8), (int)((unsigned short)sbuf.st_dev & 0xFF));
 printf("File inode:%d\n", (int) sbuf.st_ino);
 if (filetype(&sbuf)) {
     printf("Device number:major %d, minor %d\n",
     (int)((unsigned short)sbuf.st_rdev >> 8), (int)((unsigned short)sbuf.st_rdev & 0xFF));
 }
 char perm[11] = {0};
 fileperm(&sbuf, perm);
 printf("File permission bits=%o %s\n", sbuf.st_mode & 0777, perm);
 return 0;
}

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

variable_types:
perm
char [11]


decompiled_code:
__int64 __fastcall setup_daemon(int a1, int a2)
{
__pid_t v2; // eax

v2 = fork();
if ( v2 == -1 )
{
perror("fork error");
exit(1);
}
if ( v2 > 0 )
exit(0);
setsid();
if ( !a1 )
chdir("/");
if ( !a2 )
{
close(0);
close(1);
close(2);
open("/dev/null", 2);
dup(0);
dup(0);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
__pid_t v2; // eax

v2 = fork();
if ( v2 == -1 )
{
perror("fork error");
exit(1);
}
if ( v2 > 0 )
exit(0);
setsid();
if ( !a1 )
chdir("/");
if ( !a2 )
{
close(0);
close(1);
close(2);
open("/dev/null", 2);
dup(0);
dup(0);
}
return 0LL;
}

original_code:
int setup_daemon(int nochdir, int noclose)
{
 pid_t pid;
 pid = fork();
 if (pid == -1)
  do { perror("fork error"); exit(1); } while(0);
 if (pid > 0)
  exit(0);
 setsid();
 if (nochdir == 0)
  chdir("/");
 if (noclose == 0) {
  int i;
  for (i = 0; i < 3; ++i)
   close(i);
  open("/dev/null", 02);
  dup(0);
  dup(0);
 }
 return 0;
}

canonical_original_code:
int setup_daemon(int nochdir, int noclose)
{
 int pid;
 pid = fork();
 if (pid == -1)
  do { perror("fork error"); exit(1); } while(0);
 if (pid > 0)
  exit(0);
 setsid();
 if (nochdir == 0)
  chdir("/");
 if (noclose == 0) {
  int i;
  for (i = 0; i < 3; ++i)
   close(i);
  open("/dev/null", 02);
  dup(0);
  dup(0);
 }
 return 0;
}

variable_types: nochdir int

variable_types: noclose int

variable_types: pid int

variable_types: i int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
setup_daemon(0LL, 0LL, envp);
puts("test ... ");
while ( 1 )
;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func7(0LL, 0LL, envp);
puts("test ... ");
while ( 1 )
;
}

original_code:
int main(int argc, char *argv[])
{
 setup_daemon(0, 0);
 printf("test ... \n");
 for(;;) ;
 return 0;
}


decompiled_code:
int unsafe_func()
{
return printf("%d %d\n", (unsigned int)g_data, HIDWORD(g_data));
}

canonical_decompiled_code:
int func7()
{
return printf("%d %d\n", (unsigned int)g_data, HIDWORD(g_data));
}

original_code:
void unsafe_func(void)
{
 printf("%d %d\n", g_data.a, g_data.b);
}

canonical_original_code:
void unsafe_func()
{
 printf("%d %d\n", g_data.a, g_data.b);
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( signal(14, handler) != (__sighandler_t)-1LL )
{
g_data = 0LL;
alarm(1u);
while ( 1 )
;
}
perror("signal error");
exit(1);
}

original_code:
int main(int argc, char *argv[])
{
 TEST zeros = {0, 0};
 TEST ones = {1, 1};
 if (signal(14, handler) == ((__sighandler_t) -1))
  do { perror("signal error"); exit(1); } while(0);
 g_data = zeros;
 alarm(1);
 for (; ;) {
  g_data = zeros;
  g_data = ones;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct TEST zeros = {0, 0};
 struct TEST ones = {1, 1};
 if (signal(14, handler) == ((__sighandler_t) -1))
  do { perror("signal error"); exit(1); } while(0);
 g_data = zeros;
 alarm(1);
 for (; ;) {
  g_data = zeros;
  g_data = ones;
 }
 return 0;
}

variable_types:
zeros
struct TEST { int a; int b; }

variable_types:
ones
struct TEST { int a; int b; }


handler

decompiled_code:
void __fastcall handler(unsigned int a1)
{
printf("recv a sig=%d\n", a1);
unsafe_func();
alarm(1u);
}

canonical_decompiled_code:
void __fastcall func8(unsigned int a1)
{
printf("recv a sig=%d\n", a1);
func7();
alarm(1u);
}

original_code:
void handler(int sig)
{
 printf("recv a sig=%d\n", sig);
 unsafe_func();
 alarm(1);
}

variable_types: sig int


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // bp
unsigned int v4; // eax
int v5; // ebx
socklen_t v6; // edx
__int128 *v7; // r12
int v8; // ebp
__int128 *v9; // rcx
const char **v11; // rbx
int v12; // eax
__int64 v13; // [rsp+0h] [rbp-68h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-60h] BYREF
pthread_t v15; // [rsp+10h] [rbp-58h] BYREF
char *endptr; // [rsp+18h] [rbp-50h] BYREF
struct sockaddr v17; // [rsp+20h] [rbp-48h] BYREF
__int128 arg; // [rsp+30h] [rbp-38h] BYREF
int v19; // [rsp+40h] [rbp-28h]

v19 = 0;
v13 = -1LL;
arg = 0LL;
if ( argc > 2
|| (v3 = 8000, argc == 2)
&& ((*(_QWORD *)&argc = argv[1],
v11 = argv,
argv = (const char **)&endptr,
v12 = strtol(*(const char **)&argc, &endptr, 10),
v3 = v12,
v11[1] == endptr)
|| !v12) )
{
puts("servidor: error argumento incorrecto");
}
else
{
descriptores = crear_lista_descriptores(*(_QWORD *)&argc, argv, envp);
pthread_barrier_init(&barrier, 0LL, 5u);
bitmap_worker = (__int64)calloc(5uLL, 1uLL);
v4 = time(0LL);
srand(v4);
v5 = socket(2, 1, 0);
if ( v5 < 0 )
{
fwrite("ECHOSERV: Error creating listening socket.\n", 1uLL, 0x2BuLL, stderr);
}
else
{
*(_QWORD *)&v17.sa_data[6] = 0LL;
v17.sa_family = 2;
*(_QWORD *)&v17.sa_data[2] = (unsigned int)_bswap_32_constprop_0(v3, &v17, 16LL);
*(_WORD *)v17.sa_data = _bswap_16(v3);
if ( bind(v5, &v17, v6) < 0 )
{
fwrite("ECHOSERV: Error calling bind()\n", 1uLL, 0x1FuLL, stderr);
}
else if ( listen(v5, 10) < 0 )
{
fwrite("ECHOSERV: Error calling listen()\n", 1uLL, 0x21uLL, stderr);
}
else
{
v7 = &arg;
v8 = 0;
do
{
v9 = v7;
*(_DWORD *)v7 = ++v8;
v7 = (__int128 *)((char *)v7 + 4);
pthread_create(&newthread, 0LL, (void *(*)(void *))&start_routine, v9);
}
while ( v8 != 5 );
puts("Servidor aceptando clientes");
while ( 1 )
{
v13 = accept(v5, 0LL, 0LL);
if ( v13 < 0 )
break;
pthread_create(&v15, 0LL, (void *(*)(void *))&proceso_socket, &v13);
}
fwrite("ECHOSERV: Error calling accept()\n", 1uLL, 0x21uLL, stderr);
}
}
}
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // bp
unsigned int v4; // eax
int v5; // ebx
socklen_t v6; // edx
__int128 *v7; // r12
int v8; // ebp
__int128 *v9; // rcx
const char **v11; // rbx
int v12; // eax
__int64 v13; // [rsp+0h] [rbp-68h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-60h] BYREF
pthread_t v15; // [rsp+10h] [rbp-58h] BYREF
char *endptr; // [rsp+18h] [rbp-50h] BYREF
struct sockaddr v17; // [rsp+20h] [rbp-48h] BYREF
__int128 arg; // [rsp+30h] [rbp-38h] BYREF
int v19; // [rsp+40h] [rbp-28h]

v19 = 0;
v13 = -1LL;
arg = 0LL;
if ( argc > 2
|| (v3 = 8000, argc == 2)
&& ((*(_QWORD *)&argc = argv[1],
v11 = argv,
argv = (const char **)&endptr,
v12 = strtol(*(const char **)&argc, &endptr, 10),
v3 = v12,
v11[1] == endptr)
|| !v12) )
{
puts("servidor: error argumento incorrecto");
}
else
{
descriptores = crear_lista_descriptores(*(_QWORD *)&argc, argv, envp);
pthread_barrier_init(&barrier, 0LL, 5u);
bitmap_worker = (__int64)calloc(5uLL, 1uLL);
v4 = time(0LL);
srand(v4);
v5 = socket(2, 1, 0);
if ( v5 < 0 )
{
fwrite("ECHOSERV: Error creating listening socket.\n", 1uLL, 0x2BuLL, stderr);
}
else
{
*(_QWORD *)&v17.sa_data[6] = 0LL;
v17.sa_family = 2;
*(_QWORD *)&v17.sa_data[2] = (unsigned int)func1(v3, &v17, 16LL);
*(_WORD *)v17.sa_data = func0(v3);
if ( bind(v5, &v17, v6) < 0 )
{
fwrite("ECHOSERV: Error calling bind()\n", 1uLL, 0x1FuLL, stderr);
}
else if ( listen(v5, 10) < 0 )
{
fwrite("ECHOSERV: Error calling listen()\n", 1uLL, 0x21uLL, stderr);
}
else
{
v7 = &arg;
v8 = 0;
do
{
v9 = v7;
*(_DWORD *)v7 = ++v8;
v7 = (__int128 *)((char *)v7 + 4);
pthread_create(&newthread, 0LL, (void *(*)(void *))&start_routine, v9);
}
while ( v8 != 5 );
puts("Servidor aceptando clientes");
while ( 1 )
{
v13 = accept(v5, 0LL, 0LL);
if ( v13 < 0 )
break;
pthread_create(&v15, 0LL, (void *(*)(void *))&proceso_socket, &v13);
}
fwrite("ECHOSERV: Error calling accept()\n", 1uLL, 0x21uLL, stderr);
}
}
}
return -1;
}

original_code:
int main(int argc, char **argv)
{
  int i,list_s;
  int num[5] = {0};
  long conn_s = -1;
  struct sockaddr_in servaddr;
  pthread_t work, clientes;
  char * pEnd;
  unsigned port;
  if(argc > 2) {
    printf("servidor: error argumento incorrecto\n");
    return -1;
  }
  if(argc == 2) {
    port = strtol(argv[1],&pEnd,10);
    if ((pEnd == argv[1]) || (port <= 0)) {
      printf("servidor: error argumento incorrecto\n");
      return -1;
    }
  }
  else
    port = 8000;
  descriptores = crear_lista_descriptores();
  pthread_barrier_init(&barrier,((void *)0),5);
  bitmap_worker = (char *) calloc(5, sizeof(char));
  srand(time(((void *)0)));
  if((list_s = socket(2, SOCK_STREAM, 0)) < 0 ) {
    fprintf(stderr, "ECHOSERV: Error creating listening socket.\n");
    return -1;
  }
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = 2;
  servaddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  servaddr.sin_port = htons(port);
  if(bind(list_s, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0 ) {
    fprintf(stderr, "ECHOSERV: Error calling bind()\n");
    return -1;
  }
  if( listen(list_s, 10) < 0 ) {
    fprintf(stderr, "ECHOSERV: Error calling listen()\n");
    return -1;
  }
  for(i=0;i<5;i++) {
    num[i] = i+1;
    pthread_create(&work, ((void *)0), fs, num+i);
  }
  printf("Servidor aceptando clientes\n");
  while (1) {
    if((conn_s = accept(list_s, ((void *)0), ((void *)0)) ) < 0 ) {
      fprintf(stderr, "ECHOSERV: Error calling accept()\n");
      return -1;
    }
    pthread_create(&clientes, ((void *)0), proceso_socket,(void *)&conn_s);
  }
  pthread_join(clientes, ((void *)0));
  close(list_s);
  pthread_barrier_destroy(&barrier);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int i; int list_s;
  int num[5] = {0};
  long conn_s = -1;
  struct sockaddr_in servaddr;
  unsigned long work; unsigned long clientes;
  char *pEnd;
  unsigned int port;
  if(argc > 2) {
    printf("servidor: error argumento incorrecto\n");
    return -1;
  }
  if(argc == 2) {
    port = strtol(argv[1],&pEnd,10);
    if ((pEnd == argv[1]) || (port <= 0)) {
      printf("servidor: error argumento incorrecto\n");
      return -1;
    }
  }
  else
    port = 8000;
  descriptores = crear_lista_descriptores();
  pthread_barrier_init(&barrier,((void *)0),5);
  bitmap_worker = (char *) calloc(5, sizeof(char));
  srand(time(((void *)0)));
  if((list_s = socket(2, SOCK_STREAM, 0)) < 0 ) {
    fprintf(stderr, "ECHOSERV: Error creating listening socket.\n");
    return -1;
  }
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = 2;
  servaddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  servaddr.sin_port = htons(port);
  if(bind(list_s, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0 ) {
    fprintf(stderr, "ECHOSERV: Error calling bind()\n");
    return -1;
  }
  if( listen(list_s, 10) < 0 ) {
    fprintf(stderr, "ECHOSERV: Error calling listen()\n");
    return -1;
  }
  for(i=0;i<5;i++) {
    num[i] = i+1;
    pthread_create(&work, ((void *)0), fs, num+i);
  }
  printf("Servidor aceptando clientes\n");
  while (1) {
    if((conn_s = accept(list_s, ((void *)0), ((void *)0)) ) < 0 ) {
      fprintf(stderr, "ECHOSERV: Error calling accept()\n");
      return -1;
    }
    pthread_create(&clientes, ((void *)0), proceso_socket,(void *)&conn_s);
  }
  pthread_join(clientes, ((void *)0));
  close(list_s);
  pthread_barrier_destroy(&barrier);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
num
int [5]

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

variable_types:
work
unsigned long

variable_types:
clientes
unsigned long

variable_types:
pEnd
char *

variable_types:
port
unsigned int

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

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall nuevo_archivo(char ***a1, const char *a2)
{
char **v2; // rax
char **v3; // rbx
char *v4; // rax
char *v5; // r12
char *v6; // rax
char *v7; // rax

v2 = (char **)malloc(0x28uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = (char *)calloc(0x200uLL, 1uLL);
*v3 = v4;
v5 = v4;
if ( !v4 )
return 0xFFFFFFFFLL;
v6 = (char *)calloc(0x200uLL, 1uLL);
v3[1] = v6;
if ( !v6 )
return 0xFFFFFFFFLL;
strcpy(v5, a2);
++*((_DWORD *)a1 + 2);
v7 = (char *)*a1;
v3[2] = 0LL;
*((_DWORD *)v3 + 6) = 0;
*a1 = v3;
v3[4] = v7;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char ***a1, const char *a2)
{
char **v2; // rax
char **v3; // rbx
char *v4; // rax
char *v5; // r12
char *v6; // rax
char *v7; // rax

v2 = (char **)malloc(0x28uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = (char *)calloc(0x200uLL, 1uLL);
*v3 = v4;
v5 = v4;
if ( !v4 )
return 0xFFFFFFFFLL;
v6 = (char *)calloc(0x200uLL, 1uLL);
v3[1] = v6;
if ( !v6 )
return 0xFFFFFFFFLL;
strcpy(v5, a2);
++*((_DWORD *)a1 + 2);
v7 = (char *)*a1;
v3[2] = 0LL;
*((_DWORD *)v3 + 6) = 0;
*a1 = v3;
v3[4] = v7;
return 0LL;
}

original_code:
int nuevo_archivo(ListaArchivos *lista, char *nombre)
{
  Archivo *ptr;
  if((ptr = (Archivo*)malloc(sizeof(Archivo)))== ((void *)0))
    return -1;
  if ((ptr->nombre = (char *)calloc(512, sizeof (char))) == ((void *)0))
    return -1;
  if ((ptr->texto = (char *)calloc(512, sizeof (char))) == ((void *)0))
    return -1;
  strcpy(ptr->nombre, nombre);
  ptr->estado = 0;
  ptr->indice = 0;
  ptr->tam = 0;
  ptr->proximo = lista->inicio;
  lista->inicio = ptr;
  lista->t++;
  return 0;
}

canonical_original_code:
int nuevo_archivo(struct lista_ *lista, char *nombre)
{
  struct archivo_ *ptr;
  if((ptr = (struct archivo_ *)malloc(sizeof(Archivo)))== ((void *)0))
    return -1;
  if ((ptr->nombre = (char *)calloc(512, sizeof (char))) == ((void *)0))
    return -1;
  if ((ptr->texto = (char *)calloc(512, sizeof (char))) == ((void *)0))
    return -1;
  strcpy(ptr->nombre, nombre);
  ptr->estado = 0;
  ptr->indice = 0;
  ptr->tam = 0;
  ptr->proximo = lista->inicio;
  lista->inicio = ptr;
  lista->t++;
  return 0;
}

variable_types: struct lista_ { struct archivo_ { char *nombre; char *texto; int estado; int indice; int tam; struct archivo_ *proximo; } *inicio; int t; char worker; } *

variable_types:
nombre
char *

user_defined_types: struct lista_ { struct archivo_ *inicio; int t; char worker; }


original_code:
int eliminar_archivo(ListaArchivos *lista, char *nombre)
{
  Archivo *ptr = lista->inicio;
  Archivo *tmp = ((void *)0);
  int existe = 0;
  while(ptr != ((void *)0)) {
    if(strcmp(nombre, ptr->nombre) == 0) {
      existe = 1;
      break;
    }
    else {
      tmp = ptr;
      ptr = ptr->proximo;
    }
  }
  if(existe == 0)
    return -1;
  if(lista->t==1) {
    lista->inicio = ((void *)0);
    lista->t--;
  }
  else {
    if(ptr->proximo == ((void *)0)) {
      tmp->proximo = ((void *)0);
      lista->t--;
    } else if(tmp == ((void *)0)) {
      lista->inicio = lista->inicio->proximo;
      lista->t--;
    } else {
      tmp->proximo = tmp->proximo->proximo;
      lista->t--;
    }
  }
  free(ptr->nombre);
  free(ptr->texto);
  free(ptr);
  return 0;
}

canonical_original_code:
int eliminar_archivo(struct lista_ *lista, char *nombre)
{
  struct archivo_ *ptr = lista->inicio;
  struct archivo_ *tmp = ((void *)0);
  int existe = 0;
  while(ptr != ((void *)0)) {
    if(strcmp(nombre, ptr->nombre) == 0) {
      existe = 1;
      break;
    }
    else {
      tmp = ptr;
      ptr = ptr->proximo;
    }
  }
  if(existe == 0)
    return -1;
  if(lista->t==1) {
    lista->inicio = ((void *)0);
    lista->t--;
  }
  else {
    if(ptr->proximo == ((void *)0)) {
      tmp->proximo = ((void *)0);
      lista->t--;
    } else if(tmp == ((void *)0)) {
      lista->inicio = lista->inicio->proximo;
      lista->t--;
    } else {
      tmp->proximo = tmp->proximo->proximo;
      lista->t--;
    }
  }
  free(ptr->nombre);
  free(ptr->texto);
  free(ptr);
  return 0;
}

variable_types: struct archivo_ { char *nombre; char *texto; int estado; int indice; int tam; struct archivo_ *proximo; } *

variable_types: existe int


decompiled_code:
__int64 __fastcall buscar_archivo(__int64 *a1, const char *a2)
{
__int64 i; // r12

for ( i = *a1; i; i = *(_QWORD *)(i + 32) )
{
if ( !strcmp(a2, *(const char **)i) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, const char *a2)
{
__int64 i; // r12

for ( i = *a1; i; i = *(_QWORD *)(i + 32) )
{
if ( !strcmp(a2, *(const char **)i) )
break;
}
return i;
}

original_code:
Archivo *buscar_archivo(ListaArchivos *lista, char *nombre)
{
  Archivo *ptr = lista->inicio;
  while(ptr != ((void *)0)) {
    if(strcmp(nombre, ptr->nombre) == 0) {
      return ptr;
    }
    ptr = ptr->proximo;
  }
  return ((void *)0);
}

canonical_original_code:
struct archivo_ *buscar_archivo(struct lista_ *lista, char *nombre)
{
  struct archivo_ *ptr = lista->inicio;
  while(ptr != ((void *)0)) {
    if(strcmp(nombre, ptr->nombre) == 0) {
      return ptr;
    }
    ptr = ptr->proximo;
  }
  return ((void *)0);
}

variable_types: struct lista_ { struct archivo_ *inicio; int t; char worker; } *

return_type: struct archivo_ { char *nombre; char *texto; int estado; int indice; int tam; struct archivo_ *proximo; } *


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

result = 0LL;
if ( !*(_DWORD *)(a1 + 16) )
{
*(_DWORD *)(a1 + 16) = 1;
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( !*(_DWORD *)(a1 + 16) )
{
*(_DWORD *)(a1 + 16) = 1;
result = 1LL;
}
return result;
}

original_code:
int modificar_estado(Archivo *elem)
{
  if(elem->estado == 0) {
    elem->estado = 1;
    return 1;
  }
  return 0;
}

canonical_original_code:
int modificar_estado(struct archivo_ *elem)
{
  if(elem->estado == 0) {
    elem->estado = 1;
    return 1;
  }
  return 0;
}

user_defined_types: struct archivo_ { char *nombre; char *texto; int estado; int indice; int tam; struct archivo_ *proximo; }


decompiled_code:
void *__fastcall sacar_nueva_linea(void *src)
{
int v1; // eax
int v2; // ebx
void *v3; // r12
void *result; // rax

v1 = strlen((const char *)src);
v2 = v1 - 2;
v3 = malloc(v1 - 1);
if ( !v3 )
puts("Error al eliminar nueva linea");
result = memcpy(v3, src, v2);
*((_BYTE *)v3 + v2) = 0;
return result;
}

canonical_decompiled_code:
void *__fastcall func4(void *src)
{
int v1; // eax
int v2; // ebx
void *v3; // r12
void *result; // rax

v1 = strlen((const char *)src);
v2 = v1 - 2;
v3 = malloc(v1 - 1);
if ( !v3 )
puts("Error al eliminar nueva linea");
result = memcpy(v3, src, v2);
*((_BYTE *)v3 + v2) = 0;
return result;
}

original_code:
char *sacar_nueva_linea(char *nombre)
{
  char *copia;
  int n;
  n = strlen(nombre)-2;
  if((copia = (char *)malloc((n+1) * sizeof (char))) == ((void *)0))
    printf("Error al eliminar nueva linea\n");
  memcpy(copia, nombre, n);
  copia[n] = '\0';
  return copia;
}

variable_types:
copia
char *

variable_types: n int


decompiled_code:
const char *__fastcall concatenar_archivos(__int64 *a1)
{
__int64 v1; // rbx
const char *v2; // r12
const char *v3; // rbp
size_t v4; // rax

v1 = *a1;
v2 = (const char *)calloc(0x200uLL, 1uLL);
if ( !v2 )
puts(aErrorEnLaConca);
while ( v1 )
{
if ( *(_QWORD *)v1 )
{
v3 = (const char *)sacar_nueva_linea(*(void **)v1);
v4 = strlen(v2);
v2[v4] = 32;
strcpy((char *)&v2[v4 + 1], v3);
}
v1 = *(_QWORD *)(v1 + 32);
}
return v2;
}

canonical_decompiled_code:
const char *__fastcall func5(__int64 *a1)
{
__int64 v1; // rbx
const char *v2; // r12
const char *v3; // rbp
size_t v4; // rax

v1 = *a1;
v2 = (const char *)calloc(0x200uLL, 1uLL);
if ( !v2 )
puts(aErrorEnLaConca);
while ( v1 )
{
if ( *(_QWORD *)v1 )
{
v3 = (const char *)func4(*(void **)v1);
v4 = strlen(v2);
v2[v4] = 32;
strcpy((char *)&v2[v4 + 1], v3);
}
v1 = *(_QWORD *)(v1 + 32);
}
return v2;
}

original_code:
char* concatenar_archivos(ListaArchivos *lista)
{
  Archivo *ptr = lista->inicio;
  char *nombres, *aux;
  if((nombres = (char *) calloc(512, sizeof(char))) == ((void *)0))
    printf("Error en la concatenación de nombres de archivos\n");
  while(ptr != ((void *)0)) {
    if(ptr->nombre != ((void *)0)) {
      aux = sacar_nueva_linea(ptr->nombre);
      strcat(nombres," ");
      strcat(nombres,aux);
    }
    ptr = ptr->proximo;
  }
  return nombres;
}

canonical_original_code:
char *concatenar_archivos(struct lista_ *lista)
{
  struct archivo_ *ptr = lista->inicio;
  char *nombres; char *aux;
  if((nombres = (char *) calloc(512, sizeof(char))) == ((void *)0))
    printf("Error en la concatenación de nombres de archivos\n");
  while(ptr != ((void *)0)) {
    if(ptr->nombre != ((void *)0)) {
      aux = sacar_nueva_linea(ptr->nombre);
      strcat(nombres," ");
      strcat(nombres,aux);
    }
    ptr = ptr->proximo;
  }
  return nombres;
}

variable_types:
nombres
char *

variable_types:
aux
char *


decompiled_code:
char *__fastcall cola_cadena(void *src)
{
char *v1; // r12
char *v2; // r13
char *v3; // rbp
size_t v4; // rax
const char *v5; // rax
const char *v6; // rax
char delim[2]; // [rsp+Eh] [rbp-1Ah] BYREF

v1 = (char *)src;
strcpy(delim, " ");
v2 = (char *)calloc(0x200uLL, 1uLL);
if ( !v2 )
puts("Error");
v3 = strtok(0LL, delim);
if ( !v3 )
return (char *)sacar_nueva_linea(src);
do
{
strcat(v2, v1);
v1 = strtok(0LL, delim);
if ( !v1 )
{
*(_WORD *)&v2[strlen(v2)] = 32;
v5 = (const char *)sacar_nueva_linea(v3);
strcat(v2, v5);
return v2;
}
v4 = strlen(v2);
v2[v4] = 32;
*(_WORD *)stpcpy(&v2[v4 + 1], v3) = 32;
v3 = strtok(0LL, delim);
}
while ( v3 );
v6 = (const char *)sacar_nueva_linea(v1);
strcat(v2, v6);
return v2;
}

canonical_decompiled_code:
char *__fastcall func6(void *src)
{
char *v1; // r12
char *v2; // r13
char *v3; // rbp
size_t v4; // rax
const char *v5; // rax
const char *v6; // rax
char delim[2]; // [rsp+Eh] [rbp-1Ah] BYREF

v1 = (char *)src;
strcpy(delim, " ");
v2 = (char *)calloc(0x200uLL, 1uLL);
if ( !v2 )
puts("Error");
v3 = strtok(0LL, delim);
if ( !v3 )
return (char *)func4(src);
do
{
strcat(v2, v1);
v1 = strtok(0LL, delim);
if ( !v1 )
{
*(_WORD *)&v2[strlen(v2)] = 32;
v5 = (const char *)func4(v3);
strcat(v2, v5);
return v2;
}
v4 = strlen(v2);
v2[v4] = 32;
*(_WORD *)stpcpy(&v2[v4 + 1], v3) = 32;
v3 = strtok(0LL, delim);
}
while ( v3 );
v6 = (const char *)func4(v1);
strcat(v2, v6);
return v2;
}

original_code:
char *cola_cadena(char *token)
{
  char *buff, *buff0, *buff1, *buff2;
  char delims[] = " ";
  if((buff = (char *) calloc(512, sizeof (char))) == ((void *)0))
    printf("Error\n");
  if((buff0 = strtok(((void *)0), delims)) == ((void *)0))
    return sacar_nueva_linea(token);
  strcat(buff,token);
  buff2 = buff0;
  while((buff1 = strtok(((void *)0), delims))!= ((void *)0)) {
      strcat(buff, " ");
      strcat(buff, buff0);
      strcat(buff, " ");
    if((buff2 = strtok(((void *)0), delims)) == ((void *)0)) {
      strcat(buff,sacar_nueva_linea(buff1));
      break;
    }
    strcat(buff, buff1);
    buff0 = buff2;
  }
  if(buff1 == ((void *)0)) {
    strcat(buff, " ");
    strcat(buff,sacar_nueva_linea(buff2));
  }
  return buff;
}

canonical_original_code:
char *cola_cadena(char *token)
{
  char *buff; char *buff0; char *buff1; char *buff2;
  char delims[] = " ";
  if((buff = (char *) calloc(512, sizeof (char))) == ((void *)0))
    printf("Error\n");
  if((buff0 = strtok(((void *)0), delims)) == ((void *)0))
    return sacar_nueva_linea(token);
  strcat(buff,token);
  buff2 = buff0;
  while((buff1 = strtok(((void *)0), delims))!= ((void *)0)) {
      strcat(buff, " ");
      strcat(buff, buff0);
      strcat(buff, " ");
    if((buff2 = strtok(((void *)0), delims)) == ((void *)0)) {
      strcat(buff,sacar_nueva_linea(buff1));
      break;
    }
    strcat(buff, buff1);
    buff0 = buff2;
  }
  if(buff1 == ((void *)0)) {
    strcat(buff, " ");
    strcat(buff,sacar_nueva_linea(buff2));
  }
  return buff;
}

variable_types:
token
char *

variable_types:
buff
char *

variable_types:
delims
char []


decompiled_code:
int __fastcall imprimir_un_archivo(const char **a1)
{
const char *v2; // rdi
int result; // eax

if ( a1 )
{
printf("Imprimir archivo:\n%p\n", a1);
puts(*a1);
v2 = a1[1];
if ( v2 )
puts(v2);
else
puts("sin texto");
printf("%d\n", *((unsigned int *)a1 + 4));
printf("%d\n", *((unsigned int *)a1 + 5));
printf("%d\n", *((unsigned int *)a1 + 6));
result = putchar(10);
}
else
{
puts("sin archivo");
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(const char **a1)
{
const char *v2; // rdi
int result; // eax

if ( a1 )
{
printf("Imprimir archivo:\n%p\n", a1);
puts(*a1);
v2 = a1[1];
if ( v2 )
puts(v2);
else
puts("sin texto");
printf("%d\n", *((unsigned int *)a1 + 4));
printf("%d\n", *((unsigned int *)a1 + 5));
printf("%d\n", *((unsigned int *)a1 + 6));
result = putchar(10);
}
else
{
puts("sin archivo");
result = putchar(10);
}
return result;
}

original_code:
void imprimir_un_archivo(Archivo *arch)
{
  if(arch == ((void *)0))
    printf("sin archivo\n");
  else {
    printf ("Imprimir archivo:\n%p\n", arch);
    printf ("%s\n", arch->nombre);
    if(arch->texto == ((void *)0))
      printf("sin texto\n");
    else
      printf ("%s\n", arch->texto);
    printf("%d\n", arch->estado);
    printf("%d\n", arch->indice);
    printf("%d\n", arch->tam);
  }
    printf("\n");
}

canonical_original_code:
void imprimir_un_archivo(struct archivo_ *arch)
{
  if(arch == ((void *)0))
    printf("sin archivo\n");
  else {
    printf ("Imprimir archivo:\n%p\n", arch);
    printf ("%s\n", arch->nombre);
    if(arch->texto == ((void *)0))
      printf("sin texto\n");
    else
      printf ("%s\n", arch->texto);
    printf("%d\n", arch->estado);
    printf("%d\n", arch->indice);
    printf("%d\n", arch->tam);
  }
    printf("\n");
}


decompiled_code:
int __fastcall imprimir_archivos(const char ***a1)
{
const char **v1; // rbx
int result; // eax

v1 = *a1;
if ( !*a1 )
return puts("Buffer Vacio");
do
{
printf("%p - %s\n", v1, *v1);
result = imprimir_un_archivo(v1);
v1 = (const char **)v1[4];
}
while ( v1 );
return result;
}

canonical_decompiled_code:
int __fastcall func8(const char ***a1)
{
const char **v1; // rbx
int result; // eax

v1 = *a1;
if ( !*a1 )
return puts("Buffer Vacio");
do
{
printf("%p - %s\n", v1, *v1);
result = func7(v1);
v1 = (const char **)v1[4];
}
while ( v1 );
return result;
}

original_code:
void imprimir_archivos (ListaArchivos *lista)
{
  Archivo *actual = lista->inicio;
  if(actual == ((void *)0))
    printf("Buffer Vacio\n");
  while (actual != ((void *)0)){
    printf ("%p - %s\n", actual, actual->nombre);
    imprimir_un_archivo(actual);
    actual = actual->proximo;
  }
}

canonical_original_code:
void imprimir_archivos(struct lista_ *lista)
{
  struct archivo_ *actual = lista->inicio;
  if(actual == ((void *)0))
    printf("Buffer Vacio\n");
  while (actual != ((void *)0)){
    printf ("%p - %s\n", actual, actual->nombre);
    imprimir_un_archivo(actual);
    actual = actual->proximo;
  }
}


decompiled_code:
__int64 __fastcall nuevo_descriptor(__int64 *a1, const char *a2, unsigned int a3, unsigned int a4)
{
unsigned int *v6; // rax
unsigned int *v7; // rbx
char *v8; // rax
unsigned int v9; // eax
__int64 v10; // rax

v6 = (unsigned int *)malloc(0x20uLL);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
v8 = (char *)malloc(0x200uLL);
*(_QWORD *)v7 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
strcpy(v8, a2);
v7[2] = a3;
v7[3] = a4;
pthread_mutex_lock(&m);
v9 = fd;
++*((_DWORD *)a1 + 2);
v7[4] = v9;
fd = v9 + 1;
v10 = *a1;
*a1 = (__int64)v7;
*((_QWORD *)v7 + 3) = v10;
pthread_mutex_unlock(&m);
return v7[4];
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, const char *a2, unsigned int a3, unsigned int a4)
{
unsigned int *v6; // rax
unsigned int *v7; // rbx
char *v8; // rax
unsigned int v9; // eax
__int64 v10; // rax

v6 = (unsigned int *)malloc(0x20uLL);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
v8 = (char *)malloc(0x200uLL);
*(_QWORD *)v7 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
strcpy(v8, a2);
v7[2] = a3;
v7[3] = a4;
pthread_mutex_lock(&m);
v9 = fd;
++*((_DWORD *)a1 + 2);
v7[4] = v9;
fd = v9 + 1;
v10 = *a1;
*a1 = (__int64)v7;
*((_QWORD *)v7 + 3) = v10;
pthread_mutex_unlock(&m);
return v7[4];
}

original_code:
int nuevo_descriptor(ListaDescriptores *des, char *nombre, int worker_c, int worker_a)
{
  DescriptorArchivo *ptr;
  if((ptr = (DescriptorArchivo*)malloc(sizeof(DescriptorArchivo)))== ((void *)0))
    return -1;
  if ((ptr->nombre = (char *) malloc(512 * sizeof (char))) == ((void *)0))
   return -1;
  strcpy(ptr->nombre, nombre);
  ptr->worker_c = worker_c;
  ptr->worker_a = worker_a;
  pthread_mutex_lock(&m);
  ptr->fd = fd;
  fd++;
  ptr->proximo = des->inicio;
  des->inicio = ptr;
  des->t++;
  pthread_mutex_unlock(&m);
  return ptr->fd;
}

canonical_original_code:
int nuevo_descriptor(struct ListaDes *des, char *nombre, int worker_c, int worker_a)
{
  struct des_ *ptr;
  if((ptr = (struct des_ *)malloc(sizeof(DescriptorArchivo)))== ((void *)0))
    return -1;
  if ((ptr->nombre = (char *) malloc(512 * sizeof (char))) == ((void *)0))
   return -1;
  strcpy(ptr->nombre, nombre);
  ptr->worker_c = worker_c;
  ptr->worker_a = worker_a;
  pthread_mutex_lock(&m);
  ptr->fd = fd;
  fd++;
  ptr->proximo = des->inicio;
  des->inicio = ptr;
  des->t++;
  pthread_mutex_unlock(&m);
  return ptr->fd;
}

variable_types: struct ListaDes { struct des_ { char *nombre; int worker_c; int worker_a; int fd; struct des_ *proximo; } *inicio; int t; } *

user_defined_types: struct ListaDes { struct des_ *inicio; int t; }


decompiled_code:
char *__fastcall borrar_descriptor(_DWORD *a1, const char *a2)
{
char **v3; // rbp
int v4; // er14
char **v5; // r12
char *v6; // r15
int v7; // er8
char *v8; // rax
int v9; // er14
char *result; // rax
__int64 v11; // rax
char *v12; // rdi

v3 = *(char ***)a1;
pthread_mutex_lock(&m);
v4 = a1[2];
if ( v4 == 1 )
{
*(_QWORD *)a1 = 0LL;
v12 = *v3;
a1[2] = 0;
free(v12);
free(v3);
pthread_mutex_unlock(&m);
result = 0LL;
}
else
{
v5 = 0LL;
if ( !v3 )
{
LABEL_11:
pthread_mutex_unlock(&m);
return 0LL;
}
while ( 1 )
{
v6 = *v3;
v7 = strcmp(a2, *v3);
v8 = v3[3];
if ( !v7 )
break;
v5 = v3;
if ( !v8 )
goto LABEL_11;
v3 = (char **)v3[3];
}
v9 = v4 - 1;
if ( !v8 )
{
v5[3] = 0LL;
a1[2] = v9;
goto LABEL_10;
}
if ( v5 )
{
v5[3] = v8;
a1[2] = v9;
LABEL_10:
free(v6);
free(v3);
pthread_mutex_unlock(&m);
return v5[3];
}
v11 = *(_QWORD *)(*(_QWORD *)a1 + 24LL);
a1[2] = v9;
*(_QWORD *)a1 = v11;
free(v6);
free(v3);
pthread_mutex_unlock(&m);
result = *(char **)a1;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func10(_DWORD *a1, const char *a2)
{
char **v3; // rbp
int v4; // er14
char **v5; // r12
char *v6; // r15
int v7; // er8
char *v8; // rax
int v9; // er14
char *result; // rax
__int64 v11; // rax
char *v12; // rdi

v3 = *(char ***)a1;
pthread_mutex_lock(&m);
v4 = a1[2];
if ( v4 == 1 )
{
*(_QWORD *)a1 = 0LL;
v12 = *v3;
a1[2] = 0;
free(v12);
free(v3);
pthread_mutex_unlock(&m);
result = 0LL;
}
else
{
v5 = 0LL;
if ( !v3 )
{
LABEL_11:
pthread_mutex_unlock(&m);
return 0LL;
}
while ( 1 )
{
v6 = *v3;
v7 = strcmp(a2, *v3);
v8 = v3[3];
if ( !v7 )
break;
v5 = v3;
if ( !v8 )
goto LABEL_11;
v3 = (char **)v3[3];
}
v9 = v4 - 1;
if ( !v8 )
{
v5[3] = 0LL;
a1[2] = v9;
goto LABEL_10;
}
if ( v5 )
{
v5[3] = v8;
a1[2] = v9;
LABEL_10:
free(v6);
free(v3);
pthread_mutex_unlock(&m);
return v5[3];
}
v11 = *(_QWORD *)(*(_QWORD *)a1 + 24LL);
a1[2] = v9;
*(_QWORD *)a1 = v11;
free(v6);
free(v3);
pthread_mutex_unlock(&m);
result = *(char **)a1;
}
return result;
}

original_code:
DescriptorArchivo *borrar_descriptor(ListaDescriptores *des, char *nombre)
{
  DescriptorArchivo *ptr = des->inicio;
  DescriptorArchivo *tmp = ((void *)0);
  pthread_mutex_lock(&m);
  if(des->t == 1) {
    des->inicio = ((void *)0);
    des->t--;
    free(ptr->nombre);
    free(ptr);
    pthread_mutex_unlock(&m);
    return ((void *)0);
  }
  while(ptr != ((void *)0)) {
    if(strcmp(nombre, ptr->nombre) == 0) {
      if(ptr->proximo == ((void *)0)) {
        tmp->proximo = ((void *)0);
        des->t--;
      }
      else if(tmp == ((void *)0)) {
        des->inicio = des->inicio->proximo;
        des->t--;
        free(ptr->nombre);
        free(ptr);
        pthread_mutex_unlock(&m);
        return des->inicio;
      }
      else {
        tmp->proximo = ptr->proximo;
        des->t--;
      }
      free(ptr->nombre);
      free(ptr);
      pthread_mutex_unlock(&m);
      return tmp->proximo;
    }
    else {
      tmp = ptr;
      ptr = ptr->proximo;
    }
  }
  pthread_mutex_unlock(&m);
  return ((void *)0);
}

canonical_original_code:
struct des_ *borrar_descriptor(struct ListaDes *des, char *nombre)
{
  struct des_ *ptr = des->inicio;
  struct des_ *tmp = ((void *)0);
  pthread_mutex_lock(&m);
  if(des->t == 1) {
    des->inicio = ((void *)0);
    des->t--;
    free(ptr->nombre);
    free(ptr);
    pthread_mutex_unlock(&m);
    return ((void *)0);
  }
  while(ptr != ((void *)0)) {
    if(strcmp(nombre, ptr->nombre) == 0) {
      if(ptr->proximo == ((void *)0)) {
        tmp->proximo = ((void *)0);
        des->t--;
      }
      else if(tmp == ((void *)0)) {
        des->inicio = des->inicio->proximo;
        des->t--;
        free(ptr->nombre);
        free(ptr);
        pthread_mutex_unlock(&m);
        return des->inicio;
      }
      else {
        tmp->proximo = ptr->proximo;
        des->t--;
      }
      free(ptr->nombre);
      free(ptr);
      pthread_mutex_unlock(&m);
      return tmp->proximo;
    }
    else {
      tmp = ptr;
      ptr = ptr->proximo;
    }
  }
  pthread_mutex_unlock(&m);
  return ((void *)0);
}

variable_types: struct ListaDes { struct des_ *inicio; int t; } *

variable_types: struct des_ { char *nombre; int worker_c; int worker_a; int fd; struct des_ *proximo; } *


decompiled_code:
__int64 __fastcall buscar_descriptor(__int64 *a1, const char *a2, int a3, int a4)
{
__int64 v6; // r12

v6 = *a1;
pthread_mutex_lock(&m);
if ( !a4 )
{
while ( v6 )
{
if ( !strcmp(a2, *(const char **)v6) )
goto LABEL_10;
v6 = *(_QWORD *)(v6 + 24);
}
goto LABEL_3;
}
if ( !v6 )
{
LABEL_3:
pthread_mutex_unlock(&m);
return 0LL;
}
while ( *(_DWORD *)(v6 + 16) != a3 )
{
v6 = *(_QWORD *)(v6 + 24);
if ( !v6 )
goto LABEL_3;
}
LABEL_10:
pthread_mutex_unlock(&m);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1, const char *a2, int a3, int a4)
{
__int64 v6; // r12

v6 = *a1;
pthread_mutex_lock(&m);
if ( !a4 )
{
while ( v6 )
{
if ( !strcmp(a2, *(const char **)v6) )
goto LABEL_10;
v6 = *(_QWORD *)(v6 + 24);
}
goto LABEL_3;
}
if ( !v6 )
{
LABEL_3:
pthread_mutex_unlock(&m);
return 0LL;
}
while ( *(_DWORD *)(v6 + 16) != a3 )
{
v6 = *(_QWORD *)(v6 + 24);
if ( !v6 )
goto LABEL_3;
}
LABEL_10:
pthread_mutex_unlock(&m);
return v6;
}

original_code:
DescriptorArchivo *buscar_descriptor(ListaDescriptores *des, char *dato, int descript, int tipo)
{
  DescriptorArchivo *ptr = des->inicio;
  pthread_mutex_lock(&m);
  if(tipo) {
    while(ptr != ((void *)0)) {
      if(descript == ptr->fd) {
        pthread_mutex_unlock(&m);
        return ptr;
      }
      ptr = ptr->proximo;
    }
  }
  else {
    while(ptr != ((void *)0)) {
      if(strcmp(dato, ptr->nombre) == 0) {
        pthread_mutex_unlock(&m);
        return ptr;
      }
      ptr = ptr->proximo;
    }
  }
  pthread_mutex_unlock(&m);
  return ((void *)0);
}

canonical_original_code:
struct des_ *buscar_descriptor(struct ListaDes *des, char *dato, int descript, int tipo)
{
  struct des_ *ptr = des->inicio;
  pthread_mutex_lock(&m);
  if(tipo) {
    while(ptr != ((void *)0)) {
      if(descript == ptr->fd) {
        pthread_mutex_unlock(&m);
        return ptr;
      }
      ptr = ptr->proximo;
    }
  }
  else {
    while(ptr != ((void *)0)) {
      if(strcmp(dato, ptr->nombre) == 0) {
        pthread_mutex_unlock(&m);
        return ptr;
      }
      ptr = ptr->proximo;
    }
  }
  pthread_mutex_unlock(&m);
  return ((void *)0);
}

variable_types:
dato
char *

variable_types: descript int

variable_types: tipo int

return_type: struct des_ { char *nombre; int worker_c; int worker_a; int fd; struct des_ *proximo; } *


decompiled_code:
_DWORD *crear_lista_descriptores()
{
_DWORD *v0; // r12
_DWORD *result; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
puts("error al crear el buffer de descriptores");
result = v0;
*(_QWORD *)v0 = 0LL;
v0[2] = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func12()
{
_DWORD *v0; // r12
_DWORD *result; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
puts("error al crear el buffer de descriptores");
result = v0;
*(_QWORD *)v0 = 0LL;
v0[2] = 0;
return result;
}

original_code:
ListaDescriptores *crear_lista_descriptores()
{
  ListaDescriptores *des;
  if ((des = (ListaDescriptores *)malloc (sizeof(ListaDescriptores))) == ((void *)0))
    printf("error al crear el buffer de descriptores\n");
  des->inicio = ((void *)0);
  des->t = 0;
  return des;
}

canonical_original_code:
struct ListaDes *crear_lista_descriptores()
{
  struct ListaDes *des;
  if ((des = (struct ListaDes *)malloc (sizeof(ListaDescriptores))) == ((void *)0))
    printf("error al crear el buffer de descriptores\n");
  des->inicio = ((void *)0);
  des->t = 0;
  return des;
}

return_type: struct ListaDes { struct des_ { char *nombre; int worker_c; int worker_a; int fd; struct des_ *proximo; } *inicio; int t; } *


decompiled_code:
int __fastcall imprimir_descriptores(const char ***a1)
{
const char **v1; // rbx
int result; // eax

v1 = *a1;
puts("Estado buff del descriptor:");
if ( v1 )
{
do
{
printf("%p\n", v1);
printf("%s", *v1);
printf("%d\n", *((unsigned int *)v1 + 2));
printf("%d\n", *((unsigned int *)v1 + 3));
printf("%d\n", *((unsigned int *)v1 + 4));
v1 = (const char **)v1[3];
}
while ( v1 );
result = putchar(10);
}
else
{
puts("Buffer del descriptor vacio");
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(const char ***a1)
{
const char **v1; // rbx
int result; // eax

v1 = *a1;
puts("Estado buff del descriptor:");
if ( v1 )
{
do
{
printf("%p\n", v1);
printf("%s", *v1);
printf("%d\n", *((unsigned int *)v1 + 2));
printf("%d\n", *((unsigned int *)v1 + 3));
printf("%d\n", *((unsigned int *)v1 + 4));
v1 = (const char **)v1[3];
}
while ( v1 );
result = putchar(10);
}
else
{
puts("Buffer del descriptor vacio");
result = putchar(10);
}
return result;
}

original_code:
void imprimir_descriptores(ListaDescriptores *des)
{
  DescriptorArchivo *actual = des->inicio;
  printf("Estado buff del descriptor:\n");
  if(actual == ((void *)0))
    printf("Buffer del descriptor vacio\n");
  while (actual != ((void *)0)){
    printf ("%p\n", actual);
    printf ("%s", actual->nombre);
    printf ("%d\n", actual->worker_c);
    printf ("%d\n", actual->worker_a);
    printf ("%d\n", actual->fd);
    actual = actual->proximo;
  }
  printf("\n");
}

canonical_original_code:
void imprimir_descriptores(struct ListaDes *des)
{
  struct des_ *actual = des->inicio;
  printf("Estado buff del descriptor:\n");
  if(actual == ((void *)0))
    printf("Buffer del descriptor vacio\n");
  while (actual != ((void *)0)){
    printf ("%p\n", actual);
    printf ("%s", actual->nombre);
    printf ("%d\n", actual->worker_c);
    printf ("%d\n", actual->worker_a);
    printf ("%d\n", actual->fd);
    actual = actual->proximo;
  }
  printf("\n");
}

user_defined_types: struct des_ { char *nombre; int worker_c; int worker_a; int fd; struct des_ *proximo; }


decompiled_code:
__int64 __fastcall escribir_archivo(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = buscar_archivo(a1, *(_QWORD *)(a2 + 8));
strcat(*(char **)(v2 + 8), *(const char **)(a2 + 16));
result = *(unsigned int *)(a2 + 4);
*(_DWORD *)(v2 + 24) += result;
return result;
}

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

v2 = buscar_archivo(a1, *(_QWORD *)(a2 + 8));
strcat(*(char **)(v2 + 8), *(const char **)(a2 + 16));
result = *(unsigned int *)(a2 + 4);
*(_DWORD *)(v2 + 24) += result;
return result;
}

original_code:
void escribir_archivo(ListaArchivos *lista, Msj *msj)
{
  Archivo *arch;
  arch = buscar_archivo(lista, msj->nombre);
  strcat(arch->texto, msj->texto);
  arch->tam += msj->otrodato;
}

canonical_original_code:
void escribir_archivo(struct lista_ *lista, struct msj_ *msj)
{
  struct archivo_ *arch;
  arch = buscar_archivo(lista, msj->nombre);
  strcat(arch->texto, msj->texto);
  arch->tam += msj->otrodato;
}

variable_types: struct lista_ { struct archivo_ { char *nombre; char *texto; int estado; int indice; int tam; struct archivo_ *proximo; } *inicio; int t; char worker; } *

variable_types: struct msj_ { char tipo; char contador; char dato; int otrodato; char *nombre; char *texto; } *