decompiled_code:
__int64 __fastcall ft_exe_cmd_with_new_env(_QWORD *a1, _QWORD *a2)
{
__int64 v3; // rax
_QWORD *v4; // r12
__int64 v5; // rax
__int64 v6; // rax
__int64 i; // rbx
__int64 *v8; // rbx
__int64 v9; // rax
__int64 v10; // r13
unsigned int v11; // er13

v3 = gmalloc(24LL);
if ( !v3 )
return (unsigned int)-1;
v4 = (_QWORD *)v3;
v5 = ft_copy_ts(*a2);
if ( (*v4 = v5) == 0LL )
return (unsigned int)-1;
v6 = ft_copy_ts(a2[1]);
if ( (v4[1] = v6) == 0LL )
return (unsigned int)-1;
for ( i = 0LL; ; i = v10 )
{
v10 = i + 8;
if ( !(unsigned int)ft_find(*a1, &unk_390) )
break;
v8 = (__int64 *)(*v4 + i);
v9 = ft_strdup(*a1);
a1 = (_QWORD *)a1[2];
*v8 = v9;
}
*(_QWORD *)(*v4 + i) = 0LL;
v11 = ft_perform_exe(a1, v4);
ft_free_char2(*v4);
ft_free_char2(v4[1]);
gfree(v4);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2)
{
__int64 v3; // rax
_QWORD *v4; // r12
__int64 v5; // rax
__int64 v6; // rax
__int64 i; // rbx
__int64 *v8; // rbx
__int64 v9; // rax
__int64 v10; // r13
unsigned int v11; // er13

v3 = gmalloc(24LL);
if ( !v3 )
return (unsigned int)-1;
v4 = (_QWORD *)v3;
v5 = ft_copy_ts(*a2);
if ( (*v4 = v5) == 0LL )
return (unsigned int)-1;
v6 = ft_copy_ts(a2[1]);
if ( (v4[1] = v6) == 0LL )
return (unsigned int)-1;
for ( i = 0LL; ; i = v10 )
{
v10 = i + 8;
if ( !(unsigned int)ft_find(*a1, &unk_390) )
break;
v8 = (__int64 *)(*v4 + i);
v9 = ft_strdup(*a1);
a1 = (_QWORD *)a1[2];
*v8 = v9;
}
*(_QWORD *)(*v4 + i) = 0LL;
v11 = ft_perform_exe(a1, v4);
ft_free_char2(*v4);
ft_free_char2(v4[1]);
gfree(v4);
return v11;
}

original_code:
int ft_exe_cmd_with_new_env(t_p *p, t_env *e)
{
 t_p *move;
 int i;
 t_env *new_env;
 int value;
 i = -1;
 value = 0;
 if (!(new_env = (t_env *)gmalloc(sizeof(t_env)))
  || !(new_env->env = ft_copy_ts(e->env))
  || !(new_env->env_s = ft_copy_ts(e->env_s)))
  return (-1);
 move = p;
 while (ft_find(move->tok, "="))
 {
  new_env->env[++i] = ft_strdup(move->tok);
  move = move->next;
 }
 new_env->env[++i] = ((void *)0);
 value = ft_perform_exe(move, new_env);
 ft_free_char2(new_env->env);
 ft_free_char2(new_env->env_s);
 gfree((void *)new_env);
 return (value);
}

canonical_original_code:
int ft_exe_cmd_with_new_env(struct s_p *p, struct s_env *e)
{
 struct s_p *move;
 int i;
 struct s_env *new_env;
 int value;
 i = -1;
 value = 0;
 if (!(new_env = (struct s_env *)gmalloc(sizeof(t_env)))
  || !(new_env->env = ft_copy_ts(e->env))
  || !(new_env->env_s = ft_copy_ts(e->env_s)))
  return (-1);
 move = p;
 while (ft_find(move->tok, "="))
 {
  new_env->env[++i] = ft_strdup(move->tok);
  move = move->next;
 }
 new_env->env[++i] = ((void *)0);
 value = ft_perform_exe(move, new_env);
 ft_free_char2(new_env->env);
 ft_free_char2(new_env->env_s);
 gfree((void *)new_env);
 return (value);
}


original_code:
int ft_find_in_env(char *str, t_p **p, t_p *save)
{
 char *var;
 int i;
 t_p *move;
 move = *p;
 if (!(var = (char *)gmalloc(sizeof(char) * ft_strlen(str))))
  return (-2);
 i = -1;
 while (str[++i] != '=')
  var[i] = str[i];
 var[i] = '=';
 var[++i] = '\0';
 while (move)
 {
  if (move->tok && !ft_strncmp(var, move->tok, i))
   save = move;
  move = move->next;
 }
 gfree((void *)var);
 if (!save)
  return (-1);
 ft_putendl(save->tok);
 gfree((void *)save->tok);
 save->tok = ((void *)0);
 return (0);
}

canonical_original_code:
int ft_find_in_env(char *str, struct s_p **p, struct s_p *save)
{
 char *var;
 int i;
 struct s_p *move;
 move = *p;
 if (!(var = (char *)gmalloc(sizeof(char) * ft_strlen(str))))
  return (-2);
 i = -1;
 while (str[++i] != '=')
  var[i] = str[i];
 var[i] = '=';
 var[++i] = '\0';
 while (move)
 {
  if (move->tok && !ft_strncmp(var, move->tok, i))
   save = move;
  move = move->next;
 }
 gfree((void *)var);
 if (!save)
  return (-1);
 ft_putendl(save->tok);
 gfree((void *)save->tok);
 save->tok = ((void *)0);
 return (0);
}

variable_types:
str
char *

variable_types: struct s_p { char *tok; int type; struct s_p *next; struct s_p *prev; } **

variable_types:
save
struct s_p *

variable_types:
var
char *

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall ft_display_env_modify(__int64 a1, char ***a2)
{
_QWORD *v2; // rbp
char **v3; // rax
char *v4; // rdi
__int64 v5; // rbx
int v6; // eax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = (_QWORD *)a1;
v3 = *a2;
v8[0] = a1;
v4 = *v3;
if ( *v3 )
{
v5 = 0LL;
do
{
v6 = ft_find_in_env(v4, v8, 0LL);
if ( v6 == -1 )
{
ft_putendl((*a2)[v5]);
}
else if ( v6 == -2 )
{
return 0xFFFFFFFFLL;
}
v4 = (*a2)[++v5];
}
while ( v4 );
}
while ( v2 )
{
if ( *v2 )
ft_putendl(*v2);
v2 = (_QWORD *)v2[2];
}
return 0LL;
}

original_code:
int ft_display_env_modify(t_p *p, t_env *e)
{
 int i;
 t_p *move;
 int ret;
 move = p;
 i = -1;
 while (e->env[++i])
 {
  if ((ret = ft_find_in_env(e->env[i], &p, ((void *)0))) == -1)
   ft_putendl(e->env[i]);
  if (ret == -2)
   return (-1);
 }
 while (move)
 {
  if (move->tok)
   ft_putendl(move->tok);
  move = move->next;
 }
 return (0);
}

canonical_original_code:
int ft_display_env_modify(struct s_p *p, struct s_env *e)
{
 int i;
 struct s_p *move;
 int ret;
 move = p;
 i = -1;
 while (e->env[++i])
 {
  if ((ret = ft_find_in_env(e->env[i], &p, ((void *)0))) == -1)
   ft_putendl(e->env[i]);
  if (ret == -2)
   return (-1);
 }
 while (move)
 {
  if (move->tok)
   ft_putendl(move->tok);
  move = move->next;
 }
 return (0);
}

variable_types: struct s_p { char *tok; int type; struct s_p *next; struct s_p *prev; } *

variable_types: struct s_env { char **env; char **env_s; char **envc; } *

variable_types: ret int


decompiled_code:
__int64 __fastcall ft_env2(_QWORD *a1, int a2, char ***a3)
{
_QWORD *v4; // rbp
_QWORD *v5; // rbx
__int64 result; // rax

v4 = a1;
v5 = a1;
if ( a1 )
{
do
{
if ( !(unsigned int)ft_find(*v5, &unk_390) )
{
if ( a2 )
result = ft_exe_cmd_with_new_env(a1, a3);
else
result = ft_perform_exe(a1, a3);
return result;
}
v5 = (_QWORD *)v5[2];
}
while ( v5 );
if ( !a2 )
return ft_display_env_modify((__int64)a1, a3);
do
{
ft_putendl(*v4);
v4 = (_QWORD *)v4[2];
}
while ( v4 );
return 0LL;
}
if ( a2 )
return 0LL;
return ft_display_env_modify((__int64)a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, int a2, char ***a3)
{
_QWORD *v4; // rbp
_QWORD *v5; // rbx
__int64 result; // rax

v4 = a1;
v5 = a1;
if ( a1 )
{
do
{
if ( !(unsigned int)ft_find(*v5, &unk_390) )
{
if ( a2 )
result = func0(a1, a3);
else
result = ft_perform_exe(a1, a3);
return result;
}
v5 = (_QWORD *)v5[2];
}
while ( v5 );
if ( !a2 )
return func2((__int64)a1, a3);
do
{
ft_putendl(*v4);
v4 = (_QWORD *)v4[2];
}
while ( v4 );
return 0LL;
}
if ( a2 )
return 0LL;
return func2((__int64)a1, a3);
}

original_code:
int ft_env2(t_p *p, int modif_env, t_env *e)
{
 t_p *move;
 int nb_elem_new_env;
 nb_elem_new_env = 0;
 move = p;
 while (move && ft_find(move->tok, "="))
 {
  ++nb_elem_new_env;
  move = move->next;
 }
 if (move && !modif_env)
  return (ft_perform_exe(p, e));
 if (!move && !modif_env)
  return (ft_display_env_modify(p, e));
 if (!move && modif_env)
 {
  move = p;
  while (move)
  {
   ft_putendl(move->tok);
   move = move->next;
  }
  return (0);
 }
 return (ft_exe_cmd_with_new_env(p, e));
}

canonical_original_code:
int ft_env2(struct s_p *p, int modif_env, struct s_env *e)
{
 struct s_p *move;
 int nb_elem_new_env;
 nb_elem_new_env = 0;
 move = p;
 while (move && ft_find(move->tok, "="))
 {
  ++nb_elem_new_env;
  move = move->next;
 }
 if (move && !modif_env)
  return (ft_perform_exe(p, e));
 if (!move && !modif_env)
  return (ft_display_env_modify(p, e));
 if (!move && modif_env)
 {
  move = p;
  while (move)
  {
   ft_putendl(move->tok);
   move = move->next;
  }
  return (0);
 }
 return (ft_exe_cmd_with_new_env(p, e));
}

user_defined_types: struct s_p { char *tok; int type; struct s_p *next; struct s_p *prev; }

user_defined_types: struct s_env { char **env; char **env_s; char **envc; }


decompiled_code:
__int64 __fastcall ft_env(__int64 a1, char ***a2)
{
int v2; // er12
_QWORD *v3; // rbp
__int64 result; // rax
__int64 v5; // rbp
char *i; // rdi

v2 = 0;
v3 = *(_QWORD **)(a1 + 16);
if ( v3 )
{
do
{
if ( (unsigned int)ft_strcmp(*v3, &unk_392) )
break;
v3 = (_QWORD *)v3[2];
++v2;
}
while ( v3 );
result = ft_env2(v3, v2, a2);
}
else
{
v5 = 1LL;
for ( i = **a2; i; ++v5 )
{
ft_putendl(i);
i = (*a2)[v5];
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char ***a2)
{
int v2; // er12
_QWORD *v3; // rbp
__int64 result; // rax
__int64 v5; // rbp
char *i; // rdi

v2 = 0;
v3 = *(_QWORD **)(a1 + 16);
if ( v3 )
{
do
{
if ( (unsigned int)ft_strcmp(*v3, &unk_392) )
break;
v3 = (_QWORD *)v3[2];
++v2;
}
while ( v3 );
result = func3(v3, v2, a2);
}
else
{
v5 = 1LL;
for ( i = **a2; i; ++v5 )
{
ft_putendl(i);
i = (*a2)[v5];
}
result = 0LL;
}
return result;
}

original_code:
int ft_env(t_p *p, t_env *e)
{
 int modif_env;
 t_p *move;
 int i;
 modif_env = 0;
 move = p->next;
 if (!move)
 {
  i = -1;
  while (e->env[++i])
   ft_putendl(e->env[i]);
  return (0);
 }
 while (move && !ft_strcmp(move->tok, "-i"))
 {
  move = move->next;
  ++modif_env;
 }
 return (ft_env2(move, modif_env, e));
}

canonical_original_code:
int ft_env(struct s_p *p, struct s_env *e)
{
 int modif_env;
 struct s_p *move;
 int i;
 modif_env = 0;
 move = p->next;
 if (!move)
 {
  i = -1;
  while (e->env[++i])
   ft_putendl(e->env[i]);
  return (0);
 }
 while (move && !ft_strcmp(move->tok, "-i"))
 {
  move = move->next;
  ++modif_env;
 }
 return (ft_env2(move, modif_env, e));
}


repo: andreisoare/memfrag

original_code:
int search_node (void *ptr)
{
   Allocation_List *node;
   int i;
   if (first == ((void *)0)) return 0;
   for (i = H+1; i <= 200; i++) path[i] = first;
   for (node = first, i = H; i >= 0; i--) {
      while (node->next[i] != ((void *)0) && node->next[i]->ptr < ptr)
         node = node->next[i];
      path[i] = node;
   }
   if (path[0]->next[0] != ((void *)0) && path[0]->next[0]->ptr == ptr) return 1;
   else return 0;
}

canonical_original_code:
int search_node(void *ptr)
{
   struct _Allocation_List *node;
   int i;
   if (first == ((void *)0)) return 0;
   for (i = H+1; i <= 200; i++) path[i] = first;
   for (node = first, i = H; i >= 0; i--) {
      while (node->next[i] != ((void *)0) && node->next[i]->ptr < ptr)
         node = node->next[i];
      path[i] = node;
   }
   if (path[0]->next[0] != ((void *)0) && path[0]->next[0]->ptr == ptr) return 1;
   else return 0;
}

variable_types:
ptr
void *

variable_types: struct _Allocation_List { struct _Allocation_List **next; unsigned long szB; void *ptr; } *


original_code:
void del_node (void *ptr)
{
   Allocation_List *node;
   int i;
   if (!search_node(ptr)) return;
   node = path[0]->next[0];
   if (node == last) last = node->prev;
   if (node->next[0] != ((void *)0))
      node->next[0]->prev = path[0];
   for (i = 0; i <= 200; i++)
      if (path[i]->next[i] == node)
         path[i]->next[i] = node->next[i];
   free(node);
}

canonical_original_code:
void del_node(void *ptr)
{
   struct _Allocation_List *node;
   int i;
   if (!search_node(ptr)) return;
   node = path[0]->next[0];
   if (node == last) last = node->prev;
   if (node->next[0] != ((void *)0))
      node->next[0]->prev = path[0];
   for (i = 0; i <= 200; i++)
      if (path[i]->next[i] == node)
         path[i]->next[i] = node->next[i];
   free(node);
}

return_type: void

user_defined_types: struct _Allocation_List { struct _Allocation_List **next; unsigned long szB; void *ptr; }


decompiled_code:
unsigned __int64 __fastcall hash_gen(unsigned __int64 a1)
{
return a1 % 0xA299D;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(unsigned __int64 a1)
{
return a1 % 0xA299D;
}

original_code:
int hash_gen (Ptr key) {
 return (size_t) key % 666013;
}

canonical_original_code:
int hash_gen(void *key) {
 return (unsigned long) key % 666013;
}

variable_types:
key
void *


delH

original_code:
void delH (Hash h, Ptr adr) {
 int k = hash_gen (adr);
 Node *p = h[k], *q;
 if(!p) return;
 if (p->adr == adr) {
  h[k] = p->lnk;
  free(p);
 }
 else {
  while (p->lnk && p->lnk->adr != adr)
   p = p->lnk;
  if (p->lnk) {
   q = p->lnk;
   p->lnk = q->lnk;
   free(q);
  }
 }
}

canonical_original_code:
void delH(struct Node *h[666013], void *adr) {
 int k = hash_gen (adr);
 struct Node *p = h[k]; struct Node *q;
 if(!p) return;
 if (p->adr == adr) {
  h[k] = p->lnk;
  free(p);
 }
 else {
  while (p->lnk && p->lnk->adr != adr)
   p = p->lnk;
  if (p->lnk) {
   q = p->lnk;
   p->lnk = q->lnk;
   free(q);
  }
 }
}

variable_types: struct Node { void *adr; unsigned long size; struct Node *lnk; } *[666013]

variable_types:
adr
void *

variable_types: k int


decompiled_code:
__int64 __fastcall client_cleanup(pthread_mutex_t *a1)
{
unsigned int v1; // eax

v1 = pthread_mutex_unlock(a1);
if ( v1 )
syserr(v1, "Thread cleanup failed\n");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(pthread_mutex_t *a1)
{
unsigned int v1; // eax

v1 = pthread_mutex_unlock(a1);
if ( v1 )
syserr(v1, "Thread cleanup failed\n");
return 0LL;
}

original_code:
void * client_cleanup(void * arg){
 int err;
 if ((err = pthread_mutex_unlock((pthread_mutex_t *) arg)) != 0)
  syserr(err, "Thread cleanup failed\n");
 return 0;
}

canonical_original_code:
void *client_cleanup(void *arg){
 int err;
 if ((err = pthread_mutex_unlock((union pthread_mutex_t *) arg)) != 0)
  syserr(err, "Thread cleanup failed\n");
 return 0;
}

variable_types:
arg
void *

variable_types: err int

return_type: void *

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; 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; }

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


decompiled_code:
__int64 __fastcall client_kill_cleanup(__pid_t *a1)
{
kill(*a1, 15);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__pid_t *a1)
{
kill(*a1, 15);
return 0LL;
}

original_code:
void * client_kill_cleanup(void * arg){
 kill (*(int *) arg, 15);
 return 0;
}

canonical_original_code:
void *client_kill_cleanup(void *arg){
 kill (*(int *) arg, 15);
 return 0;
}


decompiled_code:
unsigned int __fastcall res_init(__int64 a1, int a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int result; // eax

v2 = pthread_mutex_init((pthread_mutex_t *)a1, 0LL);
if ( v2 )
{
syserr(v2, "Server: mutex init failed");
v3 = pthread_cond_init((pthread_cond_t *)(a1 + 40), 0LL);
if ( !v3 )
goto LABEL_3;
}
else
{
v3 = pthread_cond_init((pthread_cond_t *)(a1 + 40), 0LL);
if ( !v3 )
goto LABEL_3;
}
syserr(v3, "Server: cond init failed");
LABEL_3:
*(_DWORD *)(a1 + 88) = 0;
result = pthread_cond_init((pthread_cond_t *)(a1 + 96), 0LL);
if ( result )
result = syserr(result, "Server: cond init failed");
*(_DWORD *)(a1 + 148) = a2;
*(_DWORD *)(a1 + 144) = 0;
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func2(__int64 a1, int a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int result; // eax

v2 = pthread_mutex_init((pthread_mutex_t *)a1, 0LL);
if ( v2 )
{
syserr(v2, "Server: mutex init failed");
v3 = pthread_cond_init((pthread_cond_t *)(a1 + 40), 0LL);
if ( !v3 )
goto LABEL_3;
}
else
{
v3 = pthread_cond_init((pthread_cond_t *)(a1 + 40), 0LL);
if ( !v3 )
goto LABEL_3;
}
syserr(v3, "Server: cond init failed");
LABEL_3:
*(_DWORD *)(a1 + 88) = 0;
result = pthread_cond_init((pthread_cond_t *)(a1 + 96), 0LL);
if ( result )
result = syserr(result, "Server: cond init failed");
*(_DWORD *)(a1 + 148) = a2;
*(_DWORD *)(a1 + 144) = 0;
return result;
}

original_code:
void res_init(t_resource * r, int N){
 int err = 0;
 if ((err = pthread_mutex_init(&(r->mutex), 0)) != 0)
  syserr(err, "Server: mutex init failed");
 if ((err = pthread_cond_init(&(r->res_q), 0)) != 0)
  syserr(err, "Server: cond init failed");
 r->c_res_q = 0;
 if ((err = pthread_cond_init(&(r->res_p), 0)) != 0)
  syserr(err, "Server: cond init failed");
 r->c_res_p = 0;
 r->free = N;
}

canonical_original_code:
void res_init(struct resource *r, int N){
 int err = 0;
 if ((err = pthread_mutex_init(&(r->mutex), 0)) != 0)
  syserr(err, "Server: mutex init failed");
 if ((err = pthread_cond_init(&(r->res_q), 0)) != 0)
  syserr(err, "Server: cond init failed");
 r->c_res_q = 0;
 if ((err = pthread_cond_init(&(r->res_p), 0)) != 0)
  syserr(err, "Server: cond init failed");
 r->c_res_p = 0;
 r->free = N;
}

variable_types: struct resource { 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; } mutex; 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; } res_q; int c_res_q; union pthread_cond_t res_p; int c_res_p; int free; int pair_pid; int pair_weight; union pthread_cond_t *free_pair; int *partner_finished; } *

variable_types: N int

user_defined_types: struct resource { union pthread_mutex_t mutex; union pthread_cond_t res_q; int c_res_q; union pthread_cond_t res_p; int c_res_p; int free; int pair_pid; int pair_weight; union pthread_cond_t *free_pair; int *partner_finished; }

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


decompiled_code:
unsigned int __fastcall res_delete(pthread_mutex_t *mutex)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int result; // eax

v1 = pthread_attr_destroy(&client_thread_attr);
if ( v1 )
{
syserr(v1, "Server: pthread attr destroy failed");
v2 = pthread_mutex_destroy(mutex);
if ( !v2 )
{
LABEL_3:
v3 = pthread_cond_destroy((pthread_cond_t *)&mutex[1]);
if ( !v3 )
goto LABEL_4;
goto LABEL_8;
}
}
else
{
v2 = pthread_mutex_destroy(mutex);
if ( !v2 )
goto LABEL_3;
}
syserr(v2, "Server: mutex destroy failed\n");
v3 = pthread_cond_destroy((pthread_cond_t *)&mutex[1]);
if ( !v3 )
{
LABEL_4:
result = pthread_cond_destroy((pthread_cond_t *)(&mutex[2].__align + 2));
if ( !result )
return result;
return syserr(result, "Server: cond destroy failed\n");
}
LABEL_8:
syserr(v3, "Server: cond destroy failed\n");
result = pthread_cond_destroy((pthread_cond_t *)(&mutex[2].__align + 2));
if ( result )
return syserr(result, "Server: cond destroy failed\n");
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func3(pthread_mutex_t *mutex)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int result; // eax

v1 = pthread_attr_destroy(&client_thread_attr);
if ( v1 )
{
syserr(v1, "Server: pthread attr destroy failed");
v2 = pthread_mutex_destroy(mutex);
if ( !v2 )
{
LABEL_3:
v3 = pthread_cond_destroy((pthread_cond_t *)&mutex[1]);
if ( !v3 )
goto LABEL_4;
goto LABEL_8;
}
}
else
{
v2 = pthread_mutex_destroy(mutex);
if ( !v2 )
goto LABEL_3;
}
syserr(v2, "Server: mutex destroy failed\n");
v3 = pthread_cond_destroy((pthread_cond_t *)&mutex[1]);
if ( !v3 )
{
LABEL_4:
result = pthread_cond_destroy((pthread_cond_t *)(&mutex[2].__align + 2));
if ( !result )
return result;
return syserr(result, "Server: cond destroy failed\n");
}
LABEL_8:
syserr(v3, "Server: cond destroy failed\n");
result = pthread_cond_destroy((pthread_cond_t *)(&mutex[2].__align + 2));
if ( result )
return syserr(result, "Server: cond destroy failed\n");
return result;
}

original_code:
void res_delete(t_resource * r){
 int err = 0;
 if ((err = pthread_attr_destroy(&(client_thread_attr))) != 0)
  syserr(err, "Server: pthread attr destroy failed");
 if ((err = pthread_mutex_destroy(&(r->mutex))) != 0)
  syserr(err, "Server: mutex destroy failed\n");
 if ((err = pthread_cond_destroy(&(r->res_q))) != 0)
  syserr(err, "Server: cond destroy failed\n");
 if ((err = pthread_cond_destroy(&(r->res_p))) != 0)
  syserr(err, "Server: cond destroy failed\n");
}

canonical_original_code:
void res_delete(struct resource *r){
 int err = 0;
 if ((err = pthread_attr_destroy(&(client_thread_attr))) != 0)
  syserr(err, "Server: pthread attr destroy failed");
 if ((err = pthread_mutex_destroy(&(r->mutex))) != 0)
  syserr(err, "Server: mutex destroy failed\n");
 if ((err = pthread_cond_destroy(&(r->res_q))) != 0)
  syserr(err, "Server: cond destroy failed\n");
 if ((err = pthread_cond_destroy(&(r->res_p))) != 0)
  syserr(err, "Server: cond destroy failed\n");
}

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


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

v1 = pthread_cond_broadcast((pthread_cond_t *)(a1 + 40));
if ( !v1 )
{
result = pthread_cond_broadcast((pthread_cond_t *)(a1 + 96));
if ( !result )
return result;
return syserr(result, "Server: broadcast failed\n");
}
syserr(v1, "Server: broadcast failed\n");
result = pthread_cond_broadcast((pthread_cond_t *)(a1 + 96));
if ( result )
return syserr(result, "Server: broadcast failed\n");
return result;
}

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

v1 = pthread_cond_broadcast((pthread_cond_t *)(a1 + 40));
if ( !v1 )
{
result = pthread_cond_broadcast((pthread_cond_t *)(a1 + 96));
if ( !result )
return result;
return syserr(result, "Server: broadcast failed\n");
}
syserr(v1, "Server: broadcast failed\n");
result = pthread_cond_broadcast((pthread_cond_t *)(a1 + 96));
if ( result )
return syserr(result, "Server: broadcast failed\n");
return result;
}

original_code:
void res_free(t_resource * r){
 int err;
 if ((err = pthread_cond_broadcast(&(r->res_q))) != 0)
  syserr(err, "Server: broadcast failed\n");
 if ((err = pthread_cond_broadcast(&(r->res_p))) != 0)
  syserr(err, "Server: broadcast failed\n");
}

canonical_original_code:
void res_free(struct resource *r){
 int err;
 if ((err = pthread_cond_broadcast(&(r->res_q))) != 0)
  syserr(err, "Server: broadcast failed\n");
 if ((err = pthread_cond_broadcast(&(r->res_p))) != 0)
  syserr(err, "Server: broadcast failed\n");
}


decompiled_code:
void __noreturn exit_server()
{
unsigned int v0; // eax
__int64 v1; // rbp
int v2; // ebx
char *v3; // rdi
unsigned int v4; // eax
__int64 v5; // rbp
int v6; // ebx
pthread_mutex_t *v7; // rdi

v0 = pthread_mutex_lock(&running_lock);
if ( v0 )
syserr(v0, "Thread mutex lock fail\n");
interrupt = 1;
sleep(1u);
if ( running_threads )
{
if ( K > 0 )
{
v1 = 0LL;
v2 = 0;
do
{
++v2;
v3 = (char *)resources + v1;
v1 += 176LL;
res_free((__int64)v3);
}
while ( K > v2 );
}
printf("waiting for this madness to stop %i\n", (unsigned int)running_threads);
pthread_cond_wait(&no_threads, &running_lock);
}
v4 = pthread_mutex_unlock(&running_lock);
if ( v4 )
syserr(v4, "Thread mutex unlock fail\n");
if ( msgctl(query_msg_qid, 0, 0LL) == -1 )
syserr(0LL, "Server: msgctl failed RMID\n");
if ( msgctl(acqu_msg_qid, 0, 0LL) == -1 )
syserr(0LL, "Server: msgctl failed RMID\n");
if ( msgctl(free_msg_qid, 0, 0LL) == -1 )
syserr(0LL, "Server: msgctl failed RMID\n");
if ( K > 0 )
{
v5 = 0LL;
v6 = 0;
do
{
++v6;
v7 = (pthread_mutex_t *)((char *)resources + v5);
v5 += 176LL;
res_delete(v7);
}
while ( K > v6 );
}
free(resources);
exit(0);
}

canonical_decompiled_code:
void __noreturn func5()
{
unsigned int v0; // eax
__int64 v1; // rbp
int v2; // ebx
char *v3; // rdi
unsigned int v4; // eax
__int64 v5; // rbp
int v6; // ebx
pthread_mutex_t *v7; // rdi

v0 = pthread_mutex_lock(&running_lock);
if ( v0 )
syserr(v0, "Thread mutex lock fail\n");
interrupt = 1;
sleep(1u);
if ( running_threads )
{
if ( K > 0 )
{
v1 = 0LL;
v2 = 0;
do
{
++v2;
v3 = (char *)resources + v1;
v1 += 176LL;
func4((__int64)v3);
}
while ( K > v2 );
}
printf("waiting for this madness to stop %i\n", (unsigned int)running_threads);
pthread_cond_wait(&no_threads, &running_lock);
}
v4 = pthread_mutex_unlock(&running_lock);
if ( v4 )
syserr(v4, "Thread mutex unlock fail\n");
if ( msgctl(query_msg_qid, 0, 0LL) == -1 )
syserr(0LL, "Server: msgctl failed RMID\n");
if ( msgctl(acqu_msg_qid, 0, 0LL) == -1 )
syserr(0LL, "Server: msgctl failed RMID\n");
if ( msgctl(free_msg_qid, 0, 0LL) == -1 )
syserr(0LL, "Server: msgctl failed RMID\n");
if ( K > 0 )
{
v5 = 0LL;
v6 = 0;
do
{
++v6;
v7 = (pthread_mutex_t *)((char *)resources + v5);
v5 += 176LL;
func3(v7);
}
while ( K > v6 );
}
free(resources);
exit(0);
}

original_code:
void exit_server(int sig){
 int err;
 int i;
 if ((err = pthread_mutex_lock(&(running_lock))) != 0)
  syserr(err, "Thread mutex lock fail\n");
 interrupt = 1;
 sleep(1);
 if (running_threads != 0){
  for (i = 0; i < K; i++){
   res_free(&resources[i]);
  }
  printf("waiting for this madness to stop %i\n", running_threads);
  pthread_cond_wait(&no_threads, &running_lock);
 }
 if ((err = pthread_mutex_unlock(&(running_lock))) != 0)
  syserr(err, "Thread mutex unlock fail\n");
 if (debug)
  printf("Server: exit\n");
 if (msgctl(query_msg_qid, 0, 0) == -1)
  syserr(0,"Server: msgctl failed RMID\n");
 if (msgctl(acqu_msg_qid, 0, 0) == -1)
  syserr(0,"Server: msgctl failed RMID\n");
 if (msgctl(free_msg_qid, 0, 0) == -1)
  syserr(0,"Server: msgctl failed RMID\n");
 if (debug)
  printf("Server: msg queue destroyed\n");
 for (i = 0; i < K; i++){
  res_delete(&resources[i]);
 }
 free(resources);
 if (debug)
  printf("Server: resources freed\n");
 if (debug)
  printf("Server: end of exit protocol\n");
 exit(0);
}

variable_types: sig int


decompiled_code:
unsigned int check_int()
{
unsigned int v0; // eax
unsigned int result; // eax
unsigned int v2; // eax

v0 = pthread_mutex_lock(&running_lock);
if ( v0 )
syserr(v0, "Thread mutex lock fail\n");
if ( interrupt == 1 )
{
--running_threads;
v2 = pthread_mutex_unlock(&running_lock);
if ( v2 )
syserr(v2, "Thread mutex unlock fail\n");
if ( !running_threads )
pthread_cond_signal(&no_threads);
pthread_exit((void *)0xFFFFFFFFFFFFFFFFLL);
}
result = pthread_mutex_unlock(&running_lock);
if ( result )
result = syserr(result, "Thread mutex unlock fail\n");
return result;
}

canonical_decompiled_code:
unsigned int func6()
{
unsigned int v0; // eax
unsigned int result; // eax
unsigned int v2; // eax

v0 = pthread_mutex_lock(&running_lock);
if ( v0 )
syserr(v0, "Thread mutex lock fail\n");
if ( interrupt == 1 )
{
--running_threads;
v2 = pthread_mutex_unlock(&running_lock);
if ( v2 )
syserr(v2, "Thread mutex unlock fail\n");
if ( !running_threads )
pthread_cond_signal(&no_threads);
pthread_exit((void *)0xFFFFFFFFFFFFFFFFLL);
}
result = pthread_mutex_unlock(&running_lock);
if ( result )
result = syserr(result, "Thread mutex unlock fail\n");
return result;
}

original_code:
void check_int(){
 int err;
 if ((err = pthread_mutex_lock(&(running_lock))) != 0)
   syserr(err, "Thread mutex lock fail\n");
 if (interrupt == 1){
  running_threads --;
  if (debug)
   printf("Left %i\n", running_threads);
  if ((err = pthread_mutex_unlock(&(running_lock))) != 0)
   syserr(err, "Thread mutex unlock fail\n");
  if (running_threads == 0)
   pthread_cond_signal(&no_threads);
  pthread_exit(((void *) -1));
 }
 if ((err = pthread_mutex_unlock(&(running_lock))) != 0)
  syserr(err, "Thread mutex unlock fail\n");
}


client

decompiled_code:
void __fastcall __noreturn client(void *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
int v6; // eax
int v7; // eax
__int64 v8; // rdx
int v9; // eax
__int64 v10; // r12
__int64 v11; // r13
__int64 v12; // rbx
int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
__int64 v16; // rdx
unsigned int v17; // eax
unsigned int v18; // eax
unsigned int v19; // eax
int v20; // eax
int v21; // eax
bool v22; // zf
__int64 v23; // rax
pthread_t v24; // [rsp-8h] [rbp-1F0h]
pthread_mutex_t *mutex; // [rsp+10h] [rbp-1D8h]
_DWORD *v26; // [rsp+18h] [rbp-1D0h]
int oldstate; // [rsp+3Ch] [rbp-1ACh] BYREF
char v28[48]; // [rsp+40h] [rbp-1A8h] BYREF
struct __jmp_buf_tag env; // [rsp+70h] [rbp-178h] BYREF
__pthread_unwind_buf_t buf; // [rsp+150h] [rbp-98h] BYREF

v1 = pthread_mutex_lock(&running_lock);
if ( v1 )
syserr(v1, "Thread mutex lock fail\n");
++running_threads;
v2 = pthread_mutex_unlock(&running_lock);
if ( v2 )
syserr(v2, "Thread mutex unlock fail\n");
v3 = pthread_setcancelstate(0, &oldstate);
if ( v3 )
syserr(v3, "Thread setcancelstate fail\n");
v4 = pthread_setcanceltype(1, &oldstate);
if ( v4 )
syserr(v4, "Thread setcanceltype fail\n");
mutex = (pthread_mutex_t *)((char *)resources + 176 * *((_QWORD *)a1 + 3) - 176);
if ( !_sigsetjmp(&env, 0) )
{
_pthread_register_cancel((__pthread_unwind_buf_t *)&env);
if ( !_sigsetjmp((struct __jmp_buf_tag *)&env.__saved_mask.__val[5], 0) )
{
_pthread_register_cancel((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
v5 = pthread_mutex_lock(mutex);
if ( v5 )
syserr(v5, "Thread mutex lock fail\n");
v6 = mutex[2].__owner;
if ( v6 || *((_DWORD *)&mutex[3].__align + 6) == 2 )
{
mutex[2].__owner = v6 + 1;
pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex);
check_int();
--mutex[2].__owner;
}
v7 = *((_DWORD *)&mutex[3].__align + 6);
if ( v7 )
{
v8 = *((int *)&mutex[3].__align + 8);
*((_DWORD *)&mutex[3].__align + 6) = v7 + 1;
v9 = *((_DWORD *)a1 + 8) + *((_DWORD *)&mutex[3].__align + 9);
*((_DWORD *)&mutex[3].__align + 9) = v9;
*((_QWORD *)a1 + 2) = v8;
*((_DWORD *)&mutex[3].__align + 8) = *((_QWORD *)a1 + 1);
if ( v9 > *((_DWORD *)&mutex[3].__align + 7) )
{
pthread_cond_wait((pthread_cond_t *)(&mutex[2].__align + 2), mutex);
check_int();
}
v10 = *((int *)&mutex[3].__align + 9);
v11 = *((_QWORD *)a1 + 4);
v12 = (unsigned int)(*((_DWORD *)&mutex[3].__align + 7) - v10);
*((_DWORD *)&mutex[3].__align + 7) = v12;
v24 = pthread_self();
printf(
"Watek %ld przyznal %li+%li zasobow klientom %li %li, pozostalo %i zasobow\n",
v24,
v11,
v10 - v11,
*((_QWORD *)a1 + 1),
*((_QWORD *)a1 + 2),
v12);
}
else
{
*(&mutex[4].__align + 1) = (__int64)calloc(4uLL, 1uLL);
v23 = *((_QWORD *)a1 + 4);
*((_DWORD *)&mutex[3].__align + 6) = 1;
v22 = mutex[2].__owner == 0;
*((_DWORD *)&mutex[3].__align + 9) = v23;
*((_DWORD *)&mutex[3].__align + 8) = *((_QWORD *)a1 + 1);
if ( !v22 )
pthread_cond_signal((pthread_cond_t *)&mutex[1]);
pthread_cond_wait((pthread_cond_t *)(&mutex[2].__align + 2), mutex);
check_int();
*((_QWORD *)a1 + 2) = *((int *)&mutex[3].__align + 8);
}
v13 = *((_DWORD *)&mutex[3].__align + 6);
if ( v13 == 2 )
{
*((_DWORD *)&mutex[3].__align + 6) = 1;
pthread_cond_signal((pthread_cond_t *)(&mutex[2].__align + 2));
}
else
{
*((_DWORD *)&mutex[3].__align + 6) = v13 - 1;
pthread_cond_signal((pthread_cond_t *)&mutex[1]);
}
*(_QWORD *)a1 = *((_QWORD *)a1 + 1);
v26 = (_DWORD *)*(&mutex[4].__align + 1);
v14 = pthread_mutex_unlock(mutex);
if ( v14 )
syserr(v14, "Thread mutex unlock fail\n");
_pthread_unregister_cancel((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
if ( msgsnd(acqu_msg_qid, a1, 0x20uLL, 0) == -1 )
syserr(0LL, "Thread msgsnd fail\n");
check_int();
msgrcv(free_msg_qid, v28, 0x20uLL, *((_QWORD *)a1 + 1), 0);
check_int();
if ( !_sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
_pthread_register_cancel(&buf);
v15 = pthread_mutex_lock(mutex);
if ( v15 )
syserr(v15, "Thread mutex lock fail\n");
v16 = *((_QWORD *)a1 + 4);
if ( *v26 )
{
v20 = v16 + *v26;
*v26 = v20;
v21 = *((_DWORD *)&mutex[3].__align + 7) + v20;
v22 = *((_DWORD *)&mutex[3].__align + 6) == 2;
*((_DWORD *)&mutex[3].__align + 7) = v21;
if ( v22 && v21 >= *((_DWORD *)&mutex[3].__align + 9) )
pthread_cond_signal((pthread_cond_t *)(&mutex[2].__align + 2));
}
else
{
*v26 = v16;
}
v17 = pthread_mutex_unlock(mutex);
if ( v17 )
syserr(v17, "Thread mutex unlock fail\n");
_pthread_unregister_cancel(&buf);
free(a1);
v18 = pthread_mutex_lock(&running_lock);
if ( v18 )
syserr(v18, "Thread mutex lock fail\n");
--running_threads;
v19 = pthread_mutex_unlock(&running_lock);
if ( v19 )
syserr(v19, "Thread mutex unlock fail\n");
_pthread_unregister_cancel((__pthread_unwind_buf_t *)&env);
pthread_exit(0LL);
}
client_cleanup(mutex);
_pthread_unwind_next(&buf);
}
client_cleanup(mutex);
_pthread_unwind_next((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
}
client_kill_cleanup((__pid_t *)a1 + 2);
_pthread_unwind_next((__pthread_unwind_buf_t *)&env);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
int v6; // eax
int v7; // eax
__int64 v8; // rdx
int v9; // eax
__int64 v10; // r12
__int64 v11; // r13
__int64 v12; // rbx
int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
__int64 v16; // rdx
unsigned int v17; // eax
unsigned int v18; // eax
unsigned int v19; // eax
int v20; // eax
int v21; // eax
bool v22; // zf
__int64 v23; // rax
pthread_t v24; // [rsp-8h] [rbp-1F0h]
pthread_mutex_t *mutex; // [rsp+10h] [rbp-1D8h]
_DWORD *v26; // [rsp+18h] [rbp-1D0h]
int oldstate; // [rsp+3Ch] [rbp-1ACh] BYREF
char v28[48]; // [rsp+40h] [rbp-1A8h] BYREF
struct __jmp_buf_tag env; // [rsp+70h] [rbp-178h] BYREF
__pthread_unwind_buf_t buf; // [rsp+150h] [rbp-98h] BYREF

v1 = pthread_mutex_lock(&running_lock);
if ( v1 )
syserr(v1, "Thread mutex lock fail\n");
++running_threads;
v2 = pthread_mutex_unlock(&running_lock);
if ( v2 )
syserr(v2, "Thread mutex unlock fail\n");
v3 = pthread_setcancelstate(0, &oldstate);
if ( v3 )
syserr(v3, "Thread setcancelstate fail\n");
v4 = pthread_setcanceltype(1, &oldstate);
if ( v4 )
syserr(v4, "Thread setcanceltype fail\n");
mutex = (pthread_mutex_t *)((char *)resources + 176 * *((_QWORD *)a1 + 3) - 176);
if ( !_sigsetjmp(&env, 0) )
{
_pthread_register_cancel((__pthread_unwind_buf_t *)&env);
if ( !_sigsetjmp((struct __jmp_buf_tag *)&env.__saved_mask.__val[5], 0) )
{
_pthread_register_cancel((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
v5 = pthread_mutex_lock(mutex);
if ( v5 )
syserr(v5, "Thread mutex lock fail\n");
v6 = mutex[2].__owner;
if ( v6 || *((_DWORD *)&mutex[3].__align + 6) == 2 )
{
mutex[2].__owner = v6 + 1;
pthread_cond_wait((pthread_cond_t *)&mutex[1], mutex);
func6();
--mutex[2].__owner;
}
v7 = *((_DWORD *)&mutex[3].__align + 6);
if ( v7 )
{
v8 = *((int *)&mutex[3].__align + 8);
*((_DWORD *)&mutex[3].__align + 6) = v7 + 1;
v9 = *((_DWORD *)a1 + 8) + *((_DWORD *)&mutex[3].__align + 9);
*((_DWORD *)&mutex[3].__align + 9) = v9;
*((_QWORD *)a1 + 2) = v8;
*((_DWORD *)&mutex[3].__align + 8) = *((_QWORD *)a1 + 1);
if ( v9 > *((_DWORD *)&mutex[3].__align + 7) )
{
pthread_cond_wait((pthread_cond_t *)(&mutex[2].__align + 2), mutex);
func6();
}
v10 = *((int *)&mutex[3].__align + 9);
v11 = *((_QWORD *)a1 + 4);
v12 = (unsigned int)(*((_DWORD *)&mutex[3].__align + 7) - v10);
*((_DWORD *)&mutex[3].__align + 7) = v12;
v24 = pthread_self();
printf(
"Watek %ld przyznal %li+%li zasobow klientom %li %li, pozostalo %i zasobow\n",
v24,
v11,
v10 - v11,
*((_QWORD *)a1 + 1),
*((_QWORD *)a1 + 2),
v12);
}
else
{
*(&mutex[4].__align + 1) = (__int64)calloc(4uLL, 1uLL);
v23 = *((_QWORD *)a1 + 4);
*((_DWORD *)&mutex[3].__align + 6) = 1;
v22 = mutex[2].__owner == 0;
*((_DWORD *)&mutex[3].__align + 9) = v23;
*((_DWORD *)&mutex[3].__align + 8) = *((_QWORD *)a1 + 1);
if ( !v22 )
pthread_cond_signal((pthread_cond_t *)&mutex[1]);
pthread_cond_wait((pthread_cond_t *)(&mutex[2].__align + 2), mutex);
func6();
*((_QWORD *)a1 + 2) = *((int *)&mutex[3].__align + 8);
}
v13 = *((_DWORD *)&mutex[3].__align + 6);
if ( v13 == 2 )
{
*((_DWORD *)&mutex[3].__align + 6) = 1;
pthread_cond_signal((pthread_cond_t *)(&mutex[2].__align + 2));
}
else
{
*((_DWORD *)&mutex[3].__align + 6) = v13 - 1;
pthread_cond_signal((pthread_cond_t *)&mutex[1]);
}
*(_QWORD *)a1 = *((_QWORD *)a1 + 1);
v26 = (_DWORD *)*(&mutex[4].__align + 1);
v14 = pthread_mutex_unlock(mutex);
if ( v14 )
syserr(v14, "Thread mutex unlock fail\n");
_pthread_unregister_cancel((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
if ( msgsnd(acqu_msg_qid, a1, 0x20uLL, 0) == -1 )
syserr(0LL, "Thread msgsnd fail\n");
func6();
msgrcv(free_msg_qid, v28, 0x20uLL, *((_QWORD *)a1 + 1), 0);
func6();
if ( !_sigsetjmp((struct __jmp_buf_tag *)&buf, 0) )
{
_pthread_register_cancel(&buf);
v15 = pthread_mutex_lock(mutex);
if ( v15 )
syserr(v15, "Thread mutex lock fail\n");
v16 = *((_QWORD *)a1 + 4);
if ( *v26 )
{
v20 = v16 + *v26;
*v26 = v20;
v21 = *((_DWORD *)&mutex[3].__align + 7) + v20;
v22 = *((_DWORD *)&mutex[3].__align + 6) == 2;
*((_DWORD *)&mutex[3].__align + 7) = v21;
if ( v22 && v21 >= *((_DWORD *)&mutex[3].__align + 9) )
pthread_cond_signal((pthread_cond_t *)(&mutex[2].__align + 2));
}
else
{
*v26 = v16;
}
v17 = pthread_mutex_unlock(mutex);
if ( v17 )
syserr(v17, "Thread mutex unlock fail\n");
_pthread_unregister_cancel(&buf);
free(a1);
v18 = pthread_mutex_lock(&running_lock);
if ( v18 )
syserr(v18, "Thread mutex lock fail\n");
--running_threads;
v19 = pthread_mutex_unlock(&running_lock);
if ( v19 )
syserr(v19, "Thread mutex unlock fail\n");
_pthread_unregister_cancel((__pthread_unwind_buf_t *)&env);
pthread_exit(0LL);
}
func0(mutex);
_pthread_unwind_next(&buf);
}
func0(mutex);
_pthread_unwind_next((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
}
func1((__pid_t *)a1 + 2);
_pthread_unwind_next((__pthread_unwind_buf_t *)&env);
}

original_code:
void * client(void * m){
 t_msg * msg = m;
 int err;
 int state;
 int * pair_finished;
 if ((err = pthread_mutex_lock(&(running_lock))) != 0)
  syserr(err, "Thread mutex lock fail\n");
  running_threads ++;
 if ((err = pthread_mutex_unlock(&(running_lock))) != 0)
  syserr(err, "Thread mutex unlock fail\n");
 if ((err = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &state)) != 0)
  syserr(err, "Thread setcancelstate fail\n");
 if ((err = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &state)) != 0)
  syserr(err, "Thread setcanceltype fail\n");
 if (debug)
  printf("Thread with msg %li %li %li %li %li\n",
     msg->mtype,
     msg->my_pid,
     msg->res_number,
     msg->res_quantity,
     msg->partner_pid);
 t_resource * res = &(resources[msg->res_number-1]);
 do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (client_kill_cleanup); void *__cancel_arg = ((void *)&(msg->my_pid)); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
 do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (client_cleanup); void *__cancel_arg = ((void *)&(res->mutex)); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
 if ((err = pthread_mutex_lock(&(res->mutex))) != 0)
  syserr(err, "Thread mutex lock fail\n");
 if (res->c_res_q != 0 || res->c_res_p == 2){
  res->c_res_q++;
  if (debug)
   printf("Czekamy na miejsce w parze %li\n", msg->my_pid);
  pthread_cond_wait(&(res->res_q), &(res->mutex));
  check_int();
  res->c_res_q--;
 }
 if (res->c_res_p == 0){
  res->partner_finished = calloc(sizeof(int), 1);
  res->c_res_p++;
  res->pair_weight = msg->res_quantity;
  res->pair_pid = msg->my_pid;
  if (res->c_res_q != 0)
   pthread_cond_signal(&(res->res_q));
  if (debug)
   printf("Czekamy na drugiego w parze %li\n", msg->my_pid);
  pthread_cond_wait(&(res->res_p), &(res->mutex));
  check_int();
  msg->partner_pid = res->pair_pid;
 } else {
  res->c_res_p++;
  res->pair_weight += msg->res_quantity;
  msg->partner_pid = res->pair_pid;
  res->pair_pid = msg->my_pid;
  if (res->pair_weight > res->free){
   if (debug)
    printf("Czekamy na wolne zasoby %li\n", msg->my_pid);
   pthread_cond_wait(&(res->res_p), &(res->mutex));
   check_int();
  }
  res->free -= res->pair_weight;
  printf("Watek %ld przyznal %li+%li zasobow klientom %li %li, pozostalo %i zasobow\n",
   pthread_self(),
   msg->res_quantity,
   res->pair_weight - msg->res_quantity,
   msg->my_pid,
   msg->partner_pid,
   res->free);
 }
 if (res->c_res_p == 2){
  res->c_res_p--;
  pthread_cond_signal(&(res->res_p));
 } else {
  res->c_res_p--;
  pthread_cond_signal(&(res->res_q));
 }
 msg->mtype = msg->my_pid;
 pair_finished = res->partner_finished;
 if ((err = pthread_mutex_unlock(&(res->mutex))) != 0)
  syserr(err, "Thread mutex unlock fail\n");
 do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (0) __cancel_routine (__cancel_arg); } while (0);
 if (msgsnd(acqu_msg_qid, msg, sizeof(long) * 4, 0) == -1)
  syserr(0, "Thread msgsnd fail\n");
 if (debug)
  printf("Message sent to klient %li, starting work\n", msg->mtype);
 check_int();
 t_msg msgend;
 if (debug)
  printf("Waiting for klient %li end\n", msg->my_pid);
 msgrcv(free_msg_qid, &msgend, sizeof(long) * 4, msg->my_pid, 0);
 check_int();
 do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (client_cleanup); void *__cancel_arg = ((void *)&(res->mutex)); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
 if ((err = pthread_mutex_lock(&(res->mutex))) != 0)
  syserr(err, "Thread mutex lock fail\n");
 if ((*pair_finished) == 0){
  *pair_finished = msg->res_quantity;
 } else {
  *pair_finished += msg->res_quantity;
  res->free += *pair_finished;
  if (res->c_res_p == 2 && res->free >= res->pair_weight)
   pthread_cond_signal(&(res->res_p));
  if (debug)
   printf("Zwolniono %i dostepnych %i\n", *pair_finished, res->free);
 }
 if ((err = pthread_mutex_unlock(&(res->mutex))) != 0)
  syserr(err, "Thread mutex unlock fail\n");
 do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (0) __cancel_routine (__cancel_arg); } while (0);
 if (debug)
  printf("Koniec watku %li\n", msg->my_pid);
 free(msg);
 if ((err = pthread_mutex_lock(&(running_lock))) != 0)
  syserr(err, "Thread mutex lock fail\n");
 running_threads --;
 if ((err = pthread_mutex_unlock(&(running_lock))) != 0)
  syserr(err, "Thread mutex unlock fail\n");
 do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (0) __cancel_routine (__cancel_arg); } while (0);
 pthread_exit(0);
}

canonical_original_code:
void *client(void *m){
 struct msg *msg = m;
 int err;
 int state;
 int *pair_finished;
 if ((err = pthread_mutex_lock(&(running_lock))) != 0)
  syserr(err, "Thread mutex lock fail\n");
  running_threads ++;
 if ((err = pthread_mutex_unlock(&(running_lock))) != 0)
  syserr(err, "Thread mutex unlock fail\n");
 if ((err = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &state)) != 0)
  syserr(err, "Thread setcancelstate fail\n");
 if ((err = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &state)) != 0)
  syserr(err, "Thread setcanceltype fail\n");
 if (debug)
  printf("Thread with msg %li %li %li %li %li\n",
     msg->mtype,
     msg->my_pid,
     msg->res_number,
     msg->res_quantity,
     msg->partner_pid);
 struct resource *res = &(resources[msg->res_number-1]);
 do { struct __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine)(void *) = (client_kill_cleanup); void *__cancel_arg = ((void *)&(msg->my_pid)); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
 do { struct __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine)(void *) = (client_cleanup); void *__cancel_arg = ((void *)&(res->mutex)); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
 if ((err = pthread_mutex_lock(&(res->mutex))) != 0)
  syserr(err, "Thread mutex lock fail\n");
 if (res->c_res_q != 0 || res->c_res_p == 2){
  res->c_res_q++;
  if (debug)
   printf("Czekamy na miejsce w parze %li\n", msg->my_pid);
  pthread_cond_wait(&(res->res_q), &(res->mutex));
  check_int();
  res->c_res_q--;
 }
 if (res->c_res_p == 0){
  res->partner_finished = calloc(sizeof(int), 1);
  res->c_res_p++;
  res->pair_weight = msg->res_quantity;
  res->pair_pid = msg->my_pid;
  if (res->c_res_q != 0)
   pthread_cond_signal(&(res->res_q));
  if (debug)
   printf("Czekamy na drugiego w parze %li\n", msg->my_pid);
  pthread_cond_wait(&(res->res_p), &(res->mutex));
  check_int();
  msg->partner_pid = res->pair_pid;
 } else {
  res->c_res_p++;
  res->pair_weight += msg->res_quantity;
  msg->partner_pid = res->pair_pid;
  res->pair_pid = msg->my_pid;
  if (res->pair_weight > res->free){
   if (debug)
    printf("Czekamy na wolne zasoby %li\n", msg->my_pid);
   pthread_cond_wait(&(res->res_p), &(res->mutex));
   check_int();
  }
  res->free -= res->pair_weight;
  printf("Watek %ld przyznal %li+%li zasobow klientom %li %li, pozostalo %i zasobow\n",
   pthread_self(),
   msg->res_quantity,
   res->pair_weight - msg->res_quantity,
   msg->my_pid,
   msg->partner_pid,
   res->free);
 }
 if (res->c_res_p == 2){
  res->c_res_p--;
  pthread_cond_signal(&(res->res_p));
 } else {
  res->c_res_p--;
  pthread_cond_signal(&(res->res_q));
 }
 msg->mtype = msg->my_pid;
 pair_finished = res->partner_finished;
 if ((err = pthread_mutex_unlock(&(res->mutex))) != 0)
  syserr(err, "Thread mutex unlock fail\n");
 do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (0) __cancel_routine (__cancel_arg); } while (0);
 if (msgsnd(acqu_msg_qid, msg, sizeof(long) * 4, 0) == -1)
  syserr(0, "Thread msgsnd fail\n");
 if (debug)
  printf("Message sent to klient %li, starting work\n", msg->mtype);
 check_int();
 struct msg msgend;
 if (debug)
  printf("Waiting for klient %li end\n", msg->my_pid);
 msgrcv(free_msg_qid, &msgend, sizeof(long) * 4, msg->my_pid, 0);
 check_int();
 do { struct __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine)(void *) = (client_cleanup); void *__cancel_arg = ((void *)&(res->mutex)); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
 if ((err = pthread_mutex_lock(&(res->mutex))) != 0)
  syserr(err, "Thread mutex lock fail\n");
 if ((*pair_finished) == 0){
  *pair_finished = msg->res_quantity;
 } else {
  *pair_finished += msg->res_quantity;
  res->free += *pair_finished;
  if (res->c_res_p == 2 && res->free >= res->pair_weight)
   pthread_cond_signal(&(res->res_p));
  if (debug)
   printf("Zwolniono %i dostepnych %i\n", *pair_finished, res->free);
 }
 if ((err = pthread_mutex_unlock(&(res->mutex))) != 0)
  syserr(err, "Thread mutex unlock fail\n");
 do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (0) __cancel_routine (__cancel_arg); } while (0);
 if (debug)
  printf("Koniec watku %li\n", msg->my_pid);
 free(msg);
 if ((err = pthread_mutex_lock(&(running_lock))) != 0)
  syserr(err, "Thread mutex lock fail\n");
 running_threads --;
 if ((err = pthread_mutex_unlock(&(running_lock))) != 0)
  syserr(err, "Thread mutex unlock fail\n");
 do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (0) __cancel_routine (__cancel_arg); } while (0);
 pthread_exit(0);
}

variable_types:
m
void *

variable_types: struct msg { long mtype; long my_pid; long partner_pid; long res_number; long res_quantity; } *

variable_types: state int

variable_types: struct __pthread_unwind_buf_t { struct { long __cancel_jmp_buf[8]; int __mask_was_saved; } __cancel_jmp_buf[1]; void *__pad[4]; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v4; // rdi
int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
int v8; // ebx
__int64 v9; // rbx
int v10; // er12
char *v11; // rdi
unsigned int v12; // eax
void *v13; // r12
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc != 3 )
{
puts("Wrong arguments, terminating");
exit(0);
}
v3 = atoi(argv[1]);
v4 = argv[2];
K = v3;
v5 = atoi(v4);
interrupt = 0;
N = v5;
running_threads = 0;
if ( signal(2, (__sighandler_t)exit_server) == (__sighandler_t)-1LL )
syserr(0LL, "Server: signal failed\n");
if ( signal(15, (__sighandler_t)exit_server) == (__sighandler_t)-1LL )
syserr(0LL, "Server: signal failed\n");
v6 = pthread_mutex_init(&running_lock, 0LL);
if ( v6 )
syserr(v6, "Mutex init fail\n");
v7 = pthread_cond_init(&no_threads, 0LL);
if ( v7 )
syserr(v7, "Cond init fail\n");
v8 = K;
resources = calloc(0xB0uLL, K);
if ( v8 > 0 )
{
v9 = 0LL;
v10 = 0;
do
{
++v10;
v11 = (char *)resources + v9;
v9 += 176LL;
res_init((__int64)v11, N);
}
while ( K > v10 );
}
query_msg_qid = msgget(1234, 1974);
if ( query_msg_qid == -1 )
syserr(0LL, "Server: msgget failed\n");
free_msg_qid = msgget(1236, 1974);
if ( free_msg_qid == -1 )
syserr(0LL, "Server: msgget failed\n");
acqu_msg_qid = msgget(1235, 1974);
if ( acqu_msg_qid == -1 )
syserr(0LL, "Server: msgget failed\n");
if ( pthread_attr_init(&client_thread_attr) == -1 )
syserr(0xFFFFFFFFLL, "Server pthread attr init failed\n");
v12 = pthread_attr_setdetachstate(&client_thread_attr, 1);
if ( v12 )
syserr(v12, "Server: setdetachstate failed\n");
while ( interrupt != 1 )
{
v13 = malloc(0x28uLL);
msgrcv(query_msg_qid, v13, 0x20uLL, 32769LL, 0);
if ( pthread_create(newthread, &client_thread_attr, (void *(*)(void *))client, v13) == -1 )
syserr(0xFFFFFFFFLL, "Server: pthread create failed\n");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v4; // rdi
int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
int v8; // ebx
__int64 v9; // rbx
int v10; // er12
char *v11; // rdi
unsigned int v12; // eax
void *v13; // r12
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc != 3 )
{
puts("Wrong arguments, terminating");
exit(0);
}
v3 = atoi(argv[1]);
v4 = argv[2];
K = v3;
v5 = atoi(v4);
interrupt = 0;
N = v5;
running_threads = 0;
if ( signal(2, (__sighandler_t)exit_server) == (__sighandler_t)-1LL )
syserr(0LL, "Server: signal failed\n");
if ( signal(15, (__sighandler_t)exit_server) == (__sighandler_t)-1LL )
syserr(0LL, "Server: signal failed\n");
v6 = pthread_mutex_init(&running_lock, 0LL);
if ( v6 )
syserr(v6, "Mutex init fail\n");
v7 = pthread_cond_init(&no_threads, 0LL);
if ( v7 )
syserr(v7, "Cond init fail\n");
v8 = K;
resources = calloc(0xB0uLL, K);
if ( v8 > 0 )
{
v9 = 0LL;
v10 = 0;
do
{
++v10;
v11 = (char *)resources + v9;
v9 += 176LL;
func2((__int64)v11, N);
}
while ( K > v10 );
}
query_msg_qid = msgget(1234, 1974);
if ( query_msg_qid == -1 )
syserr(0LL, "Server: msgget failed\n");
free_msg_qid = msgget(1236, 1974);
if ( free_msg_qid == -1 )
syserr(0LL, "Server: msgget failed\n");
acqu_msg_qid = msgget(1235, 1974);
if ( acqu_msg_qid == -1 )
syserr(0LL, "Server: msgget failed\n");
if ( pthread_attr_init(&client_thread_attr) == -1 )
syserr(0xFFFFFFFFLL, "Server pthread attr init failed\n");
v12 = pthread_attr_setdetachstate(&client_thread_attr, 1);
if ( v12 )
syserr(v12, "Server: setdetachstate failed\n");
while ( interrupt != 1 )
{
v13 = malloc(0x28uLL);
msgrcv(query_msg_qid, v13, 0x20uLL, 32769LL, 0);
if ( pthread_create(newthread, &client_thread_attr, (void *(*)(void *))client, v13) == -1 )
syserr(0xFFFFFFFFLL, "Server: pthread create failed\n");
}
return 0;
}

original_code:
int main(int argc, char ** argv){
 int err;
 if (argc != 3){
  printf("Wrong arguments, terminating\n");
  exit(0);
 }
 K = atoi(argv[1]);
 N = atoi(argv[2]);
 interrupt = 0;
 running_threads = 0;
 if (signal(2, exit_server) == ((__sighandler_t) -1))
  syserr(0, "Server: signal failed\n");
 if (signal(15, exit_server) == ((__sighandler_t) -1))
  syserr(0, "Server: signal failed\n");
 if (debug)
  printf("Server: run with K: %i N: %i\n", K, N);
 int i = 0;
 if ((err = pthread_mutex_init(&running_lock, 0)) != 0)
  syserr(err,"Mutex init fail\n");
 if ((err = pthread_cond_init(&no_threads, 0)) != -0)
  syserr(err,"Cond init fail\n");
 resources = calloc(sizeof(t_resource), K);
 for (i = 0; i < K; i++){
  res_init(&resources[i], N);
 }
 if (debug)
  printf("Server: resources initialized\n");
 if ((query_msg_qid = msgget(QUER_MSGQID, 0666 | 01000 | 02000)) == -1)
  syserr(0,"Server: msgget failed\n");
 if ((free_msg_qid = msgget(FREE_MSGQID, 0666 | 01000 | 02000)) == -1)
  syserr(0,"Server: msgget failed\n");
 if ((acqu_msg_qid = msgget(ACQD_MSGQID, 0666 | 01000 | 02000)) == -1)
  syserr(0,"Server: msgget failed\n");
 if (debug)
  printf("Server: msg queue created\n");
 if ((err = pthread_attr_init(&client_thread_attr)) == -1)
  syserr(err, "Server pthread attr init failed\n");
 if ((err = pthread_attr_setdetachstate(
    &client_thread_attr,
    PTHREAD_CREATE_DETACHED)) != 0)
  syserr(err, "Server: setdetachstate failed\n");
 if (debug)
  printf("Server: initialization successful\n");
 while(interrupt != 1){
  t_msg * msg = malloc(sizeof(t_msg));
  if (debug)
   printf("Waiting for msg\n");
  msgrcv(query_msg_qid, msg, sizeof(long) * 4, 32768 +1, 0);
  pthread_t client_thread;
  if ((err = pthread_create(
     &client_thread,
     &client_thread_attr,
     client, msg))
     == -1)
   syserr(err, "Server: pthread create failed\n");
  if (debug)
   printf("Msg rcv %li %li %li %li\n",
    msg->mtype,
    msg->res_number,
    msg->res_quantity,
    msg->partner_pid);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 int err;
 if (argc != 3){
  printf("Wrong arguments, terminating\n");
  exit(0);
 }
 K = atoi(argv[1]);
 N = atoi(argv[2]);
 interrupt = 0;
 running_threads = 0;
 if (signal(2, exit_server) == ((__sighandler_t) -1))
  syserr(0, "Server: signal failed\n");
 if (signal(15, exit_server) == ((__sighandler_t) -1))
  syserr(0, "Server: signal failed\n");
 if (debug)
  printf("Server: run with K: %i N: %i\n", K, N);
 int i = 0;
 if ((err = pthread_mutex_init(&running_lock, 0)) != 0)
  syserr(err,"Mutex init fail\n");
 if ((err = pthread_cond_init(&no_threads, 0)) != -0)
  syserr(err,"Cond init fail\n");
 resources = calloc(sizeof(t_resource), K);
 for (i = 0; i < K; i++){
  res_init(&resources[i], N);
 }
 if (debug)
  printf("Server: resources initialized\n");
 if ((query_msg_qid = msgget(QUER_MSGQID, 0666 | 01000 | 02000)) == -1)
  syserr(0,"Server: msgget failed\n");
 if ((free_msg_qid = msgget(FREE_MSGQID, 0666 | 01000 | 02000)) == -1)
  syserr(0,"Server: msgget failed\n");
 if ((acqu_msg_qid = msgget(ACQD_MSGQID, 0666 | 01000 | 02000)) == -1)
  syserr(0,"Server: msgget failed\n");
 if (debug)
  printf("Server: msg queue created\n");
 if ((err = pthread_attr_init(&client_thread_attr)) == -1)
  syserr(err, "Server pthread attr init failed\n");
 if ((err = pthread_attr_setdetachstate(
    &client_thread_attr,
    PTHREAD_CREATE_DETACHED)) != 0)
  syserr(err, "Server: setdetachstate failed\n");
 if (debug)
  printf("Server: initialization successful\n");
 while(interrupt != 1){
  struct msg *msg = malloc(sizeof(t_msg));
  if (debug)
   printf("Waiting for msg\n");
  msgrcv(query_msg_qid, msg, sizeof(long) * 4, 32768 +1, 0);
  unsigned long client_thread;
  if ((err = pthread_create(
     &client_thread,
     &client_thread_attr,
     client, msg))
     == -1)
   syserr(err, "Server: pthread create failed\n");
  if (debug)
   printf("Msg rcv %li %li %li %li\n",
    msg->mtype,
    msg->res_number,
    msg->res_quantity,
    msg->partner_pid);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

user_defined_types: struct msg { long mtype; long my_pid; long partner_pid; long res_number; long res_quantity; }


syserr

decompiled_code:
void __noreturn syserr(int errnum, char *format, ...)
{
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
v2 = strerror(errnum);
fprintf(stderr, " (%d; %s)\n", (unsigned int)errnum, v2);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7(int errnum, char *format, ...)
{
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
v2 = strerror(errnum);
fprintf(stderr, " (%d; %s)\n", (unsigned int)errnum, v2);
exit(1);
}

original_code:
void syserr(int bl, const char *fmt, ...)
{
  va_list fmt_args;
  fprintf(stderr, "ERROR: ");
  __builtin_va_start(fmt_args,fmt);
  vfprintf(stderr, fmt, fmt_args);
  __builtin_va_end(fmt_args);
  fprintf(stderr," (%d; %s)\n", bl, strerror(bl));
  exit(1);
}

canonical_original_code:
void syserr(int bl, char *fmt, ...)
{
  __builtin_va_list fmt_args;
  fprintf(stderr, "ERROR: ");
  __builtin_va_start(fmt_args,fmt);
  vfprintf(stderr, fmt, fmt_args);
  __builtin_va_end(fmt_args);
  fprintf(stderr," (%d; %s)\n", bl, strerror(bl));
  exit(1);
}

variable_types: bl int

variable_types:
fmt
char *


fatal

decompiled_code:
void __noreturn fatal(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func8(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

original_code:
void fatal(const char *fmt, ...)
{
  va_list fmt_args;
  fprintf(stderr, "ERROR: ");
  __builtin_va_start(fmt_args,fmt);
  vfprintf(stderr, fmt, fmt_args);
  __builtin_va_end(fmt_args);
  fprintf(stderr,"\n");
  exit(1);
}

canonical_original_code:
void fatal(char *fmt, ...)
{
  __builtin_va_list fmt_args;
  fprintf(stderr, "ERROR: ");
  __builtin_va_start(fmt_args,fmt);
  vfprintf(stderr, fmt, fmt_args);
  __builtin_va_end(fmt_args);
  fprintf(stderr,"\n");
  exit(1);
}


decompiled_code:
double __fastcall slope2(double a1, double a2, double a3, double a4)
{
int v4; // eax
double v6; // [rsp+10h] [rbp-28h]
double v7; // [rsp+20h] [rbp-18h]

v7 = (double)(int)((__int64 (*)(void))function)();
v6 = (double)(int)function(0.5 * a4 + a1, 0.5 * (a4 * v7) + a2);
v4 = function(0.5 * a4 + a1, a4 * v6 * 0.5 + a2);
return ((double)(int)function(a4 + a1, a4 * (double)v4 + a2) + v6 + v6 + v7 + (double)v4 + (double)v4) / 6.0;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3, double a4)
{
int v4; // eax
double v6; // [rsp+10h] [rbp-28h]
double v7; // [rsp+20h] [rbp-18h]

v7 = (double)(int)((__int64 (*)(void))function)();
v6 = (double)(int)function(0.5 * a4 + a1, 0.5 * (a4 * v7) + a2);
v4 = function(0.5 * a4 + a1, a4 * v6 * 0.5 + a2);
return ((double)(int)function(a4 + a1, a4 * (double)v4 + a2) + v6 + v6 + v7 + (double)v4 + (double)v4) / 6.0;
}

original_code:
double slope2(double x, double y1, double y2, double h)
{
 double k1 = function(x,y1);
 double k2 = function(x + h/2, y1 + k1*h/2);
 double k3 = function(x + h/2, y1 + k2*h/2);
 double k4 = function(x + h, y1 + k3*h);
 return (k1+2*k2+2*k3+k4)/6;
}

variable_types: x double

variable_types: h double

return_type: double


decompiled_code:
double __fastcall slope1(double a1, double a2, double a3, double a4)
{
double v4; // xmm0_8

v4 = a3 * a4 * 0.5 + a3;
return (v4 + v4 + a3 + a4 * v4 * 0.5 + a3 + a4 * v4 * 0.5 + a3 + a4 * (a4 * v4 * 0.5 + a3) + a3) / 6.0;
}

original_code:
double slope1(double x, double y1, double y2, double h)
{
 double k1 = y2;
 double k2 = y2 + k1*h/2;
 double k3 = y2 + k2*h/2;
 double k4 = y2 + k3*h;
 return (k1+2*k2+2*k3+k4)/6;
}


function

decompiled_code:
double __fastcall function(double a1, double a2)
{
return sin(a2) * -4.0;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2)
{
return sin(a2) * -4.0;
}

original_code:
double function(double x, double y)
{
 return (-4*(sin(y)));
}

variable_types: y double


repo: andrew-bodine/dragon

decompiled_code:
_DWORD *make_integer_record()
{
_DWORD *v0; // rax
_DWORD *v1; // r12
_QWORD *v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
_assert_fail("ptr != NULL", "sym_table.c", 0x10u, "make_integer_record");
*v0 = 274;
v1 = v0;
v2 = malloc(8uLL);
*((_QWORD *)v1 + 1) = v2;
if ( !v2 )
_assert_fail("ptr->record.i_info != NULL", "sym_table.c", 0x14u, "make_integer_record");
*v2 = 0LL;
return v1;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *v0; // rax
_DWORD *v1; // r12
_QWORD *v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
_assert_fail("ptr != NULL", "sym_table.c", 0x10u, "make_integer_record");
*v0 = 274;
v1 = v0;
v2 = malloc(8uLL);
*((_QWORD *)v1 + 1) = v2;
if ( !v2 )
_assert_fail("ptr->record.i_info != NULL", "sym_table.c", 0x14u, "make_integer_record");
*v2 = 0LL;
return v1;
}

original_code:
r_ptr *make_integer_record( ) {
 r_ptr *ptr;
 ptr = ( r_ptr * )malloc( sizeof( r_ptr ) );
 ((void) sizeof ((ptr != ((void *)0)) ? 1 : 0), __extension__ ({ if (ptr != ((void *)0)) ; else __assert_fail ("ptr != NULL", "sym_table.c", 16, __extension__ __PRETTY_FUNCTION__); }));
 ptr->e_rtype = 274;
 ptr->record.i_info = ( i_rinfo * )malloc( sizeof( i_rinfo ) );
 ((void) sizeof ((ptr->record.i_info != ((void *)0)) ? 1 : 0), __extension__ ({ if (ptr->record.i_info != ((void *)0)) ; else __assert_fail ("ptr->record.i_info != NULL", "sym_table.c", 20, __extension__ __PRETTY_FUNCTION__); }));
 ptr->record.i_info->e_init = 0;
 ptr->record.i_info->e_value = 0;
 return ptr;
}

canonical_original_code:
struct r_ptr *make_integer_record() {
 struct r_ptr *ptr;
 ptr = ( struct r_ptr * )malloc( sizeof( r_ptr ) );
 ((void) sizeof ((ptr != ((void *)0)) ? 1 : 0), __extension__ ({ if (ptr != ((void *)0)) ; else __assert_fail ("ptr != NULL", "sym_table.c", 16, __extension__ __PRETTY_FUNCTION__); }));
 ptr->e_rtype = 274;
 ptr->record.i_info = ( struct i_rinfo * )malloc( sizeof( i_rinfo ) );
 ((void) sizeof ((ptr->record.i_info != ((void *)0)) ? 1 : 0), __extension__ ({ if (ptr->record.i_info != ((void *)0)) ; else __assert_fail ("ptr->record.i_info != NULL", "sym_table.c", 20, __extension__ __PRETTY_FUNCTION__); }));
 ptr->record.i_info->e_init = 0;
 ptr->record.i_info->e_value = 0;
 return ptr;
}

variable_types: struct r_ptr { int e_rtype; union { struct i_rinfo { int e_init; int e_value; } *i_info; struct r_rinfo { int e_init; float e_value; } *r_info; struct a_rinfo { int a_type; int a_size; union { int *i_ptr; float *r_ptr; } e_value; } *a_info; struct f_rinfo { int r_type; union { int ival; float fval; } rec; struct ident_n { struct t_entry { char *e_symbol; struct r_ptr *e_record; struct t_entry *n_entry; } *e_ptr; struct ident_n *n_ident; } *a_ptr; } *f_info; struct p_rinfo { struct ident_n *a_ptr; } *p_info; } record; } *

user_defined_types: struct r_ptr { int e_rtype; union { struct i_rinfo *i_info; struct r_rinfo *r_info; struct a_rinfo *a_info; struct f_rinfo *f_info; struct p_rinfo *p_info; } record; }

user_defined_types: struct f_rinfo { int r_type; union { int ival; float fval; } rec; struct ident_n *a_ptr; }

user_defined_types: struct ident_n { struct t_entry *e_ptr; struct ident_n *n_ident; }


decompiled_code:
_DWORD *make_real_record()
{
_DWORD *v0; // rax
_DWORD *v1; // r12
_QWORD *v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
_assert_fail("ptr != NULL", "sym_table.c", 0x1Eu, "make_real_record");
*v0 = 275;
v1 = v0;
v2 = malloc(8uLL);
*((_QWORD *)v1 + 1) = v2;
if ( !v2 )
_assert_fail("ptr->record.r_info != NULL", "sym_table.c", 0x22u, "make_real_record");
*v2 = 0LL;
return v1;
}

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

v0 = malloc(0x10uLL);
if ( !v0 )
_assert_fail("ptr != NULL", "sym_table.c", 0x1Eu, "make_real_record");
*v0 = 275;
v1 = v0;
v2 = malloc(8uLL);
*((_QWORD *)v1 + 1) = v2;
if ( !v2 )
_assert_fail("ptr->record.r_info != NULL", "sym_table.c", 0x22u, "make_real_record");
*v2 = 0LL;
return v1;
}

original_code:
r_ptr *make_real_record( ) {
 r_ptr *ptr;
 ptr = ( r_ptr * )malloc( sizeof( r_ptr ) );
 ((void) sizeof ((ptr != ((void *)0)) ? 1 : 0), __extension__ ({ if (ptr != ((void *)0)) ; else __assert_fail ("ptr != NULL", "sym_table.c", 30, __extension__ __PRETTY_FUNCTION__); }));
 ptr->e_rtype = 275;
 ptr->record.r_info = ( r_rinfo * )malloc( sizeof( r_rinfo ) );
 ((void) sizeof ((ptr->record.r_info != ((void *)0)) ? 1 : 0), __extension__ ({ if (ptr->record.r_info != ((void *)0)) ; else __assert_fail ("ptr->record.r_info != NULL", "sym_table.c", 34, __extension__ __PRETTY_FUNCTION__); }));
 ptr->record.r_info->e_init = 0;
 ptr->record.r_info->e_value = ( float )0;
 return ptr;
}

canonical_original_code:
struct r_ptr *make_real_record() {
 struct r_ptr *ptr;
 ptr = ( struct r_ptr * )malloc( sizeof( r_ptr ) );
 ((void) sizeof ((ptr != ((void *)0)) ? 1 : 0), __extension__ ({ if (ptr != ((void *)0)) ; else __assert_fail ("ptr != NULL", "sym_table.c", 30, __extension__ __PRETTY_FUNCTION__); }));
 ptr->e_rtype = 275;
 ptr->record.r_info = ( struct r_rinfo * )malloc( sizeof( r_rinfo ) );
 ((void) sizeof ((ptr->record.r_info != ((void *)0)) ? 1 : 0), __extension__ ({ if (ptr->record.r_info != ((void *)0)) ; else __assert_fail ("ptr->record.r_info != NULL", "sym_table.c", 34, __extension__ __PRETTY_FUNCTION__); }));
 ptr->record.r_info->e_init = 0;
 ptr->record.r_info->e_value = ( float )0;
 return ptr;
}

return_type: struct r_ptr { int e_rtype; union { struct i_rinfo { int e_init; int e_value; } *i_info; struct r_rinfo { int e_init; float e_value; } *r_info; struct a_rinfo { int a_type; int a_size; union { int *i_ptr; float *r_ptr; } e_value; } *a_info; struct f_rinfo { int r_type; union { int ival; float fval; } rec; struct ident_n { struct t_entry { char *e_symbol; struct r_ptr *e_record; struct t_entry *n_entry; } *e_ptr; struct ident_n *n_ident; } *a_ptr; } *f_info; struct p_rinfo { struct ident_n *a_ptr; } *p_info; } record; } *


decompiled_code:
void __fastcall free_record(void *ptr)
{
int v1; // eax

if ( ptr )
{
v1 = *(_DWORD *)ptr;
if ( *(_DWORD *)ptr != 274 )
{
if ( v1 > 274 )
{
if ( v1 != 275 )
{
LABEL_7:
free(ptr);
return;
}
}
else if ( v1 != 261 )
{
if ( v1 == 270 )
{
free(*(void **)(*((_QWORD *)ptr + 1) + 8LL));
free(*((void **)ptr + 1));
}
goto LABEL_7;
}
}
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
int v1; // eax

if ( ptr )
{
v1 = *(_DWORD *)ptr;
if ( *(_DWORD *)ptr != 274 )
{
if ( v1 > 274 )
{
if ( v1 != 275 )
{
LABEL_7:
free(ptr);
return;
}
}
else if ( v1 != 261 )
{
if ( v1 == 270 )
{
free(*(void **)(*((_QWORD *)ptr + 1) + 8LL));
free(*((void **)ptr + 1));
}
goto LABEL_7;
}
}
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void free_record( r_ptr *ptr ) {
 if( ptr == ((void *)0) ) return;
 switch( ptr->e_rtype ) {
   case 274:
    free( ptr->record.i_info );
    break;
   case 275:
    free( ptr->record.r_info );
    break;
   case 270:
    if( ptr->record.a_info->a_type == 274 )
     free( ptr->record.a_info->e_value.i_ptr );
    else
     free( ptr->record.a_info->e_value.r_ptr );
    free( ptr->record.a_info );
    break;
   case 261:
    free( ptr->record.f_info );
    break;
   case 262:
    break;
   default:
    break;
  }
 free( ptr );
}

canonical_original_code:
void free_record(struct r_ptr *ptr) {
 if( ptr == ((void *)0) ) return;
 switch( ptr->e_rtype ) {
   case 274:
    free( ptr->record.i_info );
    break;
   case 275:
    free( ptr->record.r_info );
    break;
   case 270:
    if( ptr->record.a_info->a_type == 274 )
     free( ptr->record.a_info->e_value.i_ptr );
    else
     free( ptr->record.a_info->e_value.r_ptr );
    free( ptr->record.a_info );
    break;
   case 261:
    free( ptr->record.f_info );
    break;
   case 262:
    break;
   default:
    break;
  }
 free( ptr );
}

user_defined_types: struct i_rinfo { int e_init; int e_value; }

user_defined_types: struct r_rinfo { int e_init; float e_value; }

user_defined_types: struct a_rinfo { int a_type; int a_size; union { int *i_ptr; float *r_ptr; } e_value; }

user_defined_types: struct p_rinfo { struct ident_n *a_ptr; }

user_defined_types: struct t_entry { char *e_symbol; struct r_ptr *e_record; struct t_entry *n_entry; }


decompiled_code:
void __fastcall install_entry_record(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

original_code:
void install_entry_record( t_entry *ptr, r_ptr *record ) {
 ptr->e_record = record;
}

canonical_original_code:
void install_entry_record(struct t_entry *ptr, struct r_ptr *record) {
 ptr->e_record = record;
}

variable_types: struct t_entry { char *e_symbol; struct r_ptr { int e_rtype; union { struct i_rinfo { int e_init; int e_value; } *i_info; struct r_rinfo { int e_init; float e_value; } *r_info; struct a_rinfo { int a_type; int a_size; union { int *i_ptr; float *r_ptr; } e_value; } *a_info; struct f_rinfo { int r_type; union { int ival; float fval; } rec; struct ident_n { struct t_entry *e_ptr; struct ident_n *n_ident; } *a_ptr; } *f_info; struct p_rinfo { struct ident_n *a_ptr; } *p_info; } record; } *e_record; struct t_entry *n_entry; } *

variable_types:
record
struct r_ptr *


decompiled_code:
void __fastcall free_entry(void *ptr)
{
if ( ptr )
{
free_entry(*((void **)ptr + 2));
free(*(void **)ptr);
free_record(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
if ( ptr )
{
func4(*((void **)ptr + 2));
free(*(void **)ptr);
func2(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void free_entry( t_entry *ptr ) {
 if( ptr == ((void *)0) )
  return;
 else {
  free_entry( ptr->n_entry );
  free( ptr->e_symbol );
  free_record( ptr->e_record );
  free( ptr );
 }
}

canonical_original_code:
void free_entry(struct t_entry *ptr) {
 if( ptr == ((void *)0) )
  return;
 else {
  free_entry( ptr->n_entry );
  free( ptr->e_symbol );
  free_record( ptr->e_record );
  free( ptr );
 }
}


decompiled_code:
__int64 __fastcall pop_scope(void *ptr)
{
__int64 v1; // r13
void **v2; // rbx

if ( !ptr )
return 0LL;
v1 = *((_QWORD *)ptr + 211);
v2 = (void **)ptr;
do
{
if ( *v2 )
free_entry(*v2);
++v2;
}
while ( v2 != (void **)((char *)ptr + 1688) );
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *ptr)
{
__int64 v1; // r13
void **v2; // rbx

if ( !ptr )
return 0LL;
v1 = *((_QWORD *)ptr + 211);
v2 = (void **)ptr;
do
{
if ( *v2 )
func4(*v2);
++v2;
}
while ( v2 != (void **)((char *)ptr + 1688) );
free(ptr);
return v1;
}

original_code:
s_table *pop_scope( s_table *s_stack ) {
 s_table *ptr;
 int i;
 if( s_stack == ((void *)0) )
  return ((void *)0);
 else {
  ptr = s_stack->e_scope;
  for( i = 0; i < 211; i++ ) {
   if( s_stack->s_entries[ i ] != ((void *)0) )
    free_entry( s_stack->s_entries[ i ] );
  }
  free( s_stack );
  return ptr;
 }
}

canonical_original_code:
struct s_table *pop_scope(struct s_table *s_stack) {
 struct s_table *ptr;
 int i;
 if( s_stack == ((void *)0) )
  return ((void *)0);
 else {
  ptr = s_stack->e_scope;
  for( i = 0; i < 211; i++ ) {
   if( s_stack->s_entries[ i ] != ((void *)0) )
    free_entry( s_stack->s_entries[ i ] );
  }
  free( s_stack );
  return ptr;
 }
}

variable_types: struct s_table { struct t_entry { char *e_symbol; struct r_ptr { int e_rtype; union { struct i_rinfo { int e_init; int e_value; } *i_info; struct r_rinfo { int e_init; float e_value; } *r_info; struct a_rinfo { int a_type; int a_size; union { int *i_ptr; float *r_ptr; } e_value; } *a_info; struct f_rinfo { int r_type; union { int ival; float fval; } rec; struct ident_n { struct t_entry *e_ptr; struct ident_n *n_ident; } *a_ptr; } *f_info; struct p_rinfo { struct ident_n *a_ptr; } *p_info; } record; } *e_record; struct t_entry *n_entry; } *s_entries[211]; struct s_table *e_scope; } *

user_defined_types: struct s_table { struct t_entry *s_entries[211]; struct s_table *e_scope; }


original_code:
int hash_pjw( const void *t_key, int t_size ) {
 const char *ptr = t_key;
 int val = 0;
 while( *ptr != '\0' ) {
  int tmp;
  val = ( ( val << 4 ) + ( *ptr ) );
  if( ( tmp = ( val & 0xf0000000 ) ) ) {
   val = val ^ ( tmp >> 24 );
   val = val ^ tmp;
  }
  ptr++;
 }
 return val % t_size;
}

canonical_original_code:
int hash_pjw(void *t_key, int t_size) {
 char *ptr = t_key;
 int val = 0;
 while( *ptr != '\0' ) {
  int tmp;
  val = ( ( val << 4 ) + ( *ptr ) );
  if( ( tmp = ( val & 0xf0000000 ) ) ) {
   val = val ^ ( tmp >> 24 );
   val = val ^ tmp;
  }
  ptr++;
 }
 return val % t_size;
}

variable_types:
ptr
char *

variable_types: val int

variable_types: tmp int


decompiled_code:
__int64 __fastcall find_entry(__int64 a1, char *a2)
{
__int64 v2; // r13
int v3; // eax
__int64 v4; // r14
__int64 v5; // r12
size_t v7; // rbp

v2 = a1;
v3 = hash_pjw(a2, 211);
if ( !a1 )
return 0LL;
v4 = v3;
while ( 1 )
{
v5 = *(_QWORD *)(v2 + 8 * v4);
if ( v5 )
break;
LABEL_4:
v2 = *(_QWORD *)(v2 + 1688);
if ( !v2 )
return 0LL;
}
v7 = strlen(a2);
while ( strncmp(a2, *(const char **)v5, v7) )
{
v5 = *(_QWORD *)(v5 + 16);
if ( !v5 )
goto LABEL_4;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char *a2)
{
__int64 v2; // r13
int v3; // eax
__int64 v4; // r14
__int64 v5; // r12
size_t v7; // rbp

v2 = a1;
v3 = func6(a2, 211);
if ( !a1 )
return 0LL;
v4 = v3;
while ( 1 )
{
v5 = *(_QWORD *)(v2 + 8 * v4);
if ( v5 )
break;
LABEL_4:
v2 = *(_QWORD *)(v2 + 1688);
if ( !v2 )
return 0LL;
}
v7 = strlen(a2);
while ( strncmp(a2, *(const char **)v5, v7) )
{
v5 = *(_QWORD *)(v5 + 16);
if ( !v5 )
goto LABEL_4;
}
return v5;
}

original_code:
t_entry *find_entry( s_table *s_stack, char *e_symbol ) {
 t_entry *ptr;
 int index;
 index = hash_pjw( e_symbol, 211 );
 while( s_stack != ((void *)0) ) {
  if( s_stack->s_entries[ index ] != ((void *)0) ) {
   ptr = s_stack->s_entries[ index ];
   while( ptr != ((void *)0) ) {
    if( strncmp( e_symbol, ptr->e_symbol, strlen( e_symbol ) ) == 0 )
     return ptr;
    ptr = ptr->n_entry;
   }
  }
  s_stack = s_stack->e_scope;
 }
 return ((void *)0);
}

canonical_original_code:
struct t_entry *find_entry(struct s_table *s_stack, char *e_symbol) {
 struct t_entry *ptr;
 int index;
 index = hash_pjw( e_symbol, 211 );
 while( s_stack != ((void *)0) ) {
  if( s_stack->s_entries[ index ] != ((void *)0) ) {
   ptr = s_stack->s_entries[ index ];
   while( ptr != ((void *)0) ) {
    if( strncmp( e_symbol, ptr->e_symbol, strlen( e_symbol ) ) == 0 )
     return ptr;
    ptr = ptr->n_entry;
   }
  }
  s_stack = s_stack->e_scope;
 }
 return ((void *)0);
}

variable_types: struct s_table { struct t_entry *s_entries[211]; struct s_table *e_scope; } *

variable_types: index int

return_type: struct t_entry { char *e_symbol; struct r_ptr { int e_rtype; union { struct i_rinfo { int e_init; int e_value; } *i_info; struct r_rinfo { int e_init; float e_value; } *r_info; struct a_rinfo { int a_type; int a_size; union { int *i_ptr; float *r_ptr; } e_value; } *a_info; struct f_rinfo { int r_type; union { int ival; float fval; } rec; struct ident_n { struct t_entry *e_ptr; struct ident_n *n_ident; } *a_ptr; } *f_info; struct p_rinfo { struct ident_n *a_ptr; } *p_info; } record; } *e_record; struct t_entry *n_entry; } *


decompiled_code:
const char *__fastcall type_to_str(__int64 a1)
{
_DWORD *v1; // rax
__int64 v2; // rax
const char *result; // rax

v1 = *(_DWORD **)(a1 + 8);
if ( !v1 )
return "NULL";
v2 = (unsigned int)(*v1 - 258);
if ( (unsigned int)v2 <= 0x18 )
result = (&CSWTCH_27)[v2];
else
result = (const char *)&unk_A31;
return result;
}

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

v1 = *(_DWORD **)(a1 + 8);
if ( !v1 )
return "NULL";
v2 = (unsigned int)(*v1 - 258);
if ( (unsigned int)v2 <= 0x18 )
result = (&CSWTCH_27)[v2];
else
result = (const char *)&unk_A31;
return result;
}

original_code:
char *type_to_str( t_entry *ptr ) {
 if( ptr->e_record == ((void *)0) ) return "NULL";
 switch( ptr->e_record->e_rtype ) {
  case 282:
   return "UNKN";
  case 258:
   return "PROG";
  case 274:
   return "INT";
  case 275:
   return "REAL";
  case 270:
   return "ARRAY";
  case 261:
   return "FUNC";
  case 262:
   return "PROC";
  default:
   return "";
 }
}

canonical_original_code:
char *type_to_str(struct t_entry *ptr) {
 if( ptr->e_record == ((void *)0) ) return "NULL";
 switch( ptr->e_record->e_rtype ) {
  case 282:
   return "UNKN";
  case 258:
   return "PROG";
  case 274:
   return "INT";
  case 275:
   return "REAL";
  case 270:
   return "ARRAY";
  case 261:
   return "FUNC";
  case 262:
   return "PROC";
  default:
   return "";
 }
}

return_type: char *


original_code:
void print_sstack( s_table *s_stack ) {
 t_entry *ptr;
 int i;
 fprintf( stderr, "SYMBOL TABLE(S)\n---------------------------------------\n" );
 if( s_stack == ((void *)0) ) return;
 else {
  while( s_stack != ((void *)0) ) {
   for( i = 0; i < 211; i++ ) {
    if( s_stack->s_entries[ i ] != ((void *)0) ) {
     ptr = s_stack->s_entries[ i ];
     while( ptr != ((void *)0) ) {
      fprintf( stderr, "[%s|%s", ptr->e_symbol, type_to_str( ptr ) );
      switch( ptr->e_record->e_rtype ) {
       case 274:
        fprintf( stderr, "|%d]->", ptr->e_record->record.i_info->e_init );
        break;
       case 275:
        fprintf( stderr, "|%d]->", ptr->e_record->record.r_info->e_init );
        break;
       case 270:
        if( ptr->e_record->record.a_info->a_type == 274 ) {
         fprintf( stderr, "|%d|%d|%d]->", ptr->e_record->record.a_info->a_size,
          ptr->e_record->record.a_info->e_value.i_ptr[ 0 ],
          ptr->e_record->record.a_info->e_value.i_ptr[ ptr->e_record->record.a_info->a_size - 1 ] );
        }
        else if( ptr->e_record->record.a_info->a_type == 275 ) {
         fprintf( stderr, "|%d|%d|%d]->", ptr->e_record->record.a_info->a_size,
          ptr->e_record->record.a_info->e_value.r_ptr[ 0 ],
          ptr->e_record->record.a_info->e_value.r_ptr[ ptr->e_record->record.a_info->a_size - 1 ] );
        }
        else {
         fprintf( stderr, "unrecognized array type in symbol table\n" );
        }
        break;
       case 261:
        break;
       default:
        fprintf( stderr, "]->" );
      }
      ptr = ptr->n_entry;
     }
     fprintf( stderr, "\n" );
    }
   }
   s_stack = s_stack->e_scope;
  }
  fprintf( stderr, "---------------------------------------\n" );
 }
}

canonical_original_code:
void print_sstack(struct s_table *s_stack) {
 struct t_entry *ptr;
 int i;
 fprintf( stderr, "SYMBOL TABLE(S)\n---------------------------------------\n" );
 if( s_stack == ((void *)0) ) return;
 else {
  while( s_stack != ((void *)0) ) {
   for( i = 0; i < 211; i++ ) {
    if( s_stack->s_entries[ i ] != ((void *)0) ) {
     ptr = s_stack->s_entries[ i ];
     while( ptr != ((void *)0) ) {
      fprintf( stderr, "[%s|%s", ptr->e_symbol, type_to_str( ptr ) );
      switch( ptr->e_record->e_rtype ) {
       case 274:
        fprintf( stderr, "|%d]->", ptr->e_record->record.i_info->e_init );
        break;
       case 275:
        fprintf( stderr, "|%d]->", ptr->e_record->record.r_info->e_init );
        break;
       case 270:
        if( ptr->e_record->record.a_info->a_type == 274 ) {
         fprintf( stderr, "|%d|%d|%d]->", ptr->e_record->record.a_info->a_size,
          ptr->e_record->record.a_info->e_value.i_ptr[ 0 ],
          ptr->e_record->record.a_info->e_value.i_ptr[ ptr->e_record->record.a_info->a_size - 1 ] );
        }
        else if( ptr->e_record->record.a_info->a_type == 275 ) {
         fprintf( stderr, "|%d|%d|%d]->", ptr->e_record->record.a_info->a_size,
          ptr->e_record->record.a_info->e_value.r_ptr[ 0 ],
          ptr->e_record->record.a_info->e_value.r_ptr[ ptr->e_record->record.a_info->a_size - 1 ] );
        }
        else {
         fprintf( stderr, "unrecognized array type in symbol table\n" );
        }
        break;
       case 261:
        break;
       default:
        fprintf( stderr, "]->" );
      }
      ptr = ptr->n_entry;
     }
     fprintf( stderr, "\n" );
    }
   }
   s_stack = s_stack->e_scope;
  }
  fprintf( stderr, "---------------------------------------\n" );
 }
}


decompiled_code:
void __fastcall free_comp(_QWORD *a1)
{
if ( a1[4] )
free_comp();
if ( a1[5] )
free_comp();
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1)
{
if ( a1[4] )
func0();
if ( a1[5] )
func0();
free(a1);
}

original_code:
void free_comp( comp_n *ptr ) {
 if( ptr->left != ((void *)0) )
  free_comp( ptr->left );
 if( ptr->right != ((void *)0) )
  free_comp( ptr->right );
 free( ptr );
}

canonical_original_code:
void free_comp(struct comp_n *ptr) {
 if( ptr->left != ((void *)0) )
  free_comp( ptr->left );
 if( ptr->right != ((void *)0) )
  free_comp( ptr->right );
 free( ptr );
}

variable_types: struct comp_n { int type; int index; int l_not; int u_minus; int call; union { int ival; float rval; int oval; char *woval; struct ident_n { struct t_entry { char *e_symbol; struct r_ptr { int e_rtype; union { struct i_rinfo { int e_init; int e_value; } *i_info; struct r_rinfo { int e_init; float e_value; } *r_info; struct a_rinfo { int a_type; int a_size; union { int *i_ptr; float *r_ptr; } e_value; } *a_info; struct f_rinfo { int r_type; union { int ival; float fval; } rec; struct ident_n *a_ptr; } *f_info; struct p_rinfo { struct ident_n *a_ptr; } *p_info; } record; } *e_record; struct t_entry *n_entry; } *e_ptr; struct ident_n *n_ident; } *ident; struct statement_n { struct comp_n *root; struct statement_n *n_statement; } *statement; } attr; struct comp_n *left; } *

user_defined_types: struct comp_n { int type; int index; int l_not; int u_minus; int call; union { int ival; float rval; int oval; char *woval; struct ident_n *ident; struct statement_n *statement; } attr; struct comp_n *left; }


decompiled_code:
void __fastcall free_statement(_QWORD *a1)
{
if ( a1[1] )
free_statement();
free_comp((_QWORD *)*a1);
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(_QWORD *a1)
{
if ( a1[1] )
func1();
func0((_QWORD *)*a1);
free(a1);
}

original_code:
void free_statement( statement_n *ptr ) {
 if( ptr->n_statement != ((void *)0) )
  free_statement( ptr->n_statement );
 if( ptr != ((void *)0) ) {
  free_comp( ptr->root );
  free( ptr );
 }
}

canonical_original_code:
void free_statement(struct statement_n *ptr) {
 if( ptr->n_statement != ((void *)0) )
  free_statement( ptr->n_statement );
 if( ptr != ((void *)0) ) {
  free_comp( ptr->root );
  free( ptr );
 }
}

variable_types: struct statement_n { struct comp_n { int type; int index; int l_not; int u_minus; int call; union { int ival; float rval; int oval; char *woval; struct ident_n { struct t_entry { char *e_symbol; struct r_ptr { int e_rtype; union { struct i_rinfo { int e_init; int e_value; } *i_info; struct r_rinfo { int e_init; float e_value; } *r_info; struct a_rinfo { int a_type; int a_size; union { int *i_ptr; float *r_ptr; } e_value; } *a_info; struct f_rinfo { int r_type; union { int ival; float fval; } rec; struct ident_n *a_ptr; } *f_info; struct p_rinfo { struct ident_n *a_ptr; } *p_info; } record; } *e_record; struct t_entry *n_entry; } *e_ptr; struct ident_n *n_ident; } *ident; struct statement_n *statement; } attr; struct comp_n *left; } *root; struct statement_n *n_statement; } *

user_defined_types: struct statement_n { struct comp_n *root; struct statement_n *n_statement; }


decompiled_code:
void __fastcall free_ident(_QWORD *a1)
{
if ( a1[1] )
free_ident();
free(a1);
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1)
{
if ( a1[1] )
func2();
free(a1);
}

original_code:
void free_ident( ident_n *ptr ) {
 if( ptr->n_ident != ((void *)0) )
  free_ident( ptr->n_ident );
 if( ptr != ((void *)0) )
  free( ptr );
}

canonical_original_code:
void free_ident(struct ident_n *ptr) {
 if( ptr->n_ident != ((void *)0) )
  free_ident( ptr->n_ident );
 if( ptr != ((void *)0) )
  free( ptr );
}

variable_types: struct ident_n { struct t_entry { char *e_symbol; struct r_ptr { int e_rtype; union { struct i_rinfo { int e_init; int e_value; } *i_info; struct r_rinfo { int e_init; float e_value; } *r_info; struct a_rinfo { int a_type; int a_size; union { int *i_ptr; float *r_ptr; } e_value; } *a_info; struct f_rinfo { int r_type; union { int ival; float fval; } rec; struct ident_n *a_ptr; } *f_info; struct p_rinfo { struct ident_n *a_ptr; } *p_info; } record; } *e_record; struct t_entry *n_entry; } *e_ptr; struct ident_n *n_ident; } *


decompiled_code:
void __fastcall free_program(void *ptr)
{
_QWORD *v2; // rdi

free_ident(*((_QWORD **)ptr + 1));
free_ident(*((_QWORD **)ptr + 2));
v2 = (_QWORD *)*((_QWORD *)ptr + 3);
if ( v2 )
free_ident(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
_QWORD *v2; // rdi

func2(*((_QWORD **)ptr + 1));
func2(*((_QWORD **)ptr + 2));
v2 = (_QWORD *)*((_QWORD *)ptr + 3);
if ( v2 )
func2(v2);
free(ptr);
}

original_code:
void free_program( program_n *ptr ) {
 free_ident( ptr->p_name );
 free_ident( ptr->p_ilist );
 if( ptr->p_declarations != ((void *)0) )
  free_ident( ptr->p_declarations );
 free( ptr );
}

canonical_original_code:
void free_program(struct program_n *ptr) {
 free_ident( ptr->p_name );
 free_ident( ptr->p_ilist );
 if( ptr->p_declarations != ((void *)0) )
  free_ident( ptr->p_declarations );
 free( ptr );
}

variable_types: struct program_n { int type; struct ident_n { struct t_entry { char *e_symbol; struct r_ptr { int e_rtype; union { struct i_rinfo { int e_init; int e_value; } *i_info; struct r_rinfo { int e_init; float e_value; } *r_info; struct a_rinfo { int a_type; int a_size; union { int *i_ptr; float *r_ptr; } e_value; } *a_info; struct f_rinfo { int r_type; union { int ival; float fval; } rec; struct ident_n *a_ptr; } *f_info; struct p_rinfo { struct ident_n *a_ptr; } *p_info; } record; } *e_record; struct t_entry *n_entry; } *e_ptr; struct ident_n *n_ident; } *p_name; struct ident_n *p_ilist; struct ident_n *p_declarations; struct program_n *p_sprograms; struct statement_n { struct comp_n { int type; int index; int l_not; int u_minus; int call; union { int ival; float rval; int oval; char *woval; struct ident_n *ident; struct statement_n *statement; } attr; struct comp_n *left; } *root; struct statement_n *n_statement; } *p_statements; struct program_n *p_nprogram; } *

user_defined_types: struct program_n { int type; struct ident_n *p_name; struct ident_n *p_ilist; struct ident_n *p_declarations; struct program_n *p_sprograms; struct statement_n *p_statements; struct program_n *p_nprogram; }


decompiled_code:
__int64 __fastcall print_comp(__int64 a1, int a2)
{
__int64 v2; // r12
int v4; // ebx
__int64 result; // rax

if ( a1 )
{
v2 = a1;
do
{
v4 = 0;
if ( a2 > 0 )
{
do
{
++v4;
fputc(32, stderr);
}
while ( v4 != a2 );
}
switch ( *(_DWORD *)v2 )
{
case 0x107:
fputc(10, stderr);
print_statement(*(_QWORD *)(v2 + 24), (unsigned int)(a2 + 16));
break;
case 0x108:
fwrite("[IF]", 1uLL, 4uLL, stderr);
break;
case 0x109:
fwrite("[THEN]", 1uLL, 6uLL, stderr);
break;
case 0x10A:
fwrite("[ELSE]", 1uLL, 6uLL, stderr);
break;
case 0x10B:
fwrite("[WHILE]", 1uLL, 7uLL, stderr);
break;
case 0x10C:
fwrite("[DO]", 1uLL, 4uLL, stderr);
break;
case 0x112:
fprintf(
stderr,
"[INUM:%d|%d|%d|%d]",
*(unsigned int *)(v2 + 24),
*(unsigned int *)(v2 + 4),
*(unsigned int *)(v2 + 8),
*(unsigned int *)(v2 + 12));
break;
case 0x113:
fprintf(
stderr,
"[RNUM:%f|%d|%d|%d]",
*(float *)(v2 + 24),
*(unsigned int *)(v2 + 4),
*(unsigned int *)(v2 + 8),
*(unsigned int *)(v2 + 12));
break;
case 0x114:
fprintf(stderr, "[RELOP:%s]", *(const char **)(v2 + 24));
break;
case 0x115:
fprintf(stderr, "[ADDOP:%c]", (unsigned int)*(char *)(v2 + 24));
break;
case 0x116:
fprintf(stderr, "[ADDOP:%s]", *(const char **)(v2 + 24));
break;
case 0x117:
fprintf(stderr, "[MULOP:%c]", (unsigned int)*(char *)(v2 + 24));
break;
case 0x118:
fprintf(stderr, "[MULOP:%s]", *(const char **)(v2 + 24));
break;
case 0x119:
fwrite("[ASSIGNOP]", 1uLL, 0xAuLL, stderr);
break;
case 0x11A:
fprintf(
stderr,
"[IDENT:%s|%d|%d|%d]",
***(const char ****)(v2 + 24),
*(unsigned int *)(v2 + 4),
*(unsigned int *)(v2 + 8),
*(unsigned int *)(v2 + 12));
break;
default:
fwrite("[UNKNOWN]", 1uLL, 9uLL, stderr);
break;
}
a2 += 4;
fputc(10, stderr);
result = print_comp(*(_QWORD *)(v2 + 32), (unsigned int)a2);
v2 = *(_QWORD *)(v2 + 40);
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
__int64 v2; // r12
int v4; // ebx
__int64 result; // rax

if ( a1 )
{
v2 = a1;
do
{
v4 = 0;
if ( a2 > 0 )
{
do
{
++v4;
fputc(32, stderr);
}
while ( v4 != a2 );
}
switch ( *(_DWORD *)v2 )
{
case 0x107:
fputc(10, stderr);
func5(*(_QWORD *)(v2 + 24), (unsigned int)(a2 + 16));
break;
case 0x108:
fwrite("[IF]", 1uLL, 4uLL, stderr);
break;
case 0x109:
fwrite("[THEN]", 1uLL, 6uLL, stderr);
break;
case 0x10A:
fwrite("[ELSE]", 1uLL, 6uLL, stderr);
break;
case 0x10B:
fwrite("[WHILE]", 1uLL, 7uLL, stderr);
break;
case 0x10C:
fwrite("[DO]", 1uLL, 4uLL, stderr);
break;
case 0x112:
fprintf(
stderr,
"[INUM:%d|%d|%d|%d]",
*(unsigned int *)(v2 + 24),
*(unsigned int *)(v2 + 4),
*(unsigned int *)(v2 + 8),
*(unsigned int *)(v2 + 12));
break;
case 0x113:
fprintf(
stderr,
"[RNUM:%f|%d|%d|%d]",
*(float *)(v2 + 24),
*(unsigned int *)(v2 + 4),
*(unsigned int *)(v2 + 8),
*(unsigned int *)(v2 + 12));
break;
case 0x114:
fprintf(stderr, "[RELOP:%s]", *(const char **)(v2 + 24));
break;
case 0x115:
fprintf(stderr, "[ADDOP:%c]", (unsigned int)*(char *)(v2 + 24));
break;
case 0x116:
fprintf(stderr, "[ADDOP:%s]", *(const char **)(v2 + 24));
break;
case 0x117:
fprintf(stderr, "[MULOP:%c]", (unsigned int)*(char *)(v2 + 24));
break;
case 0x118:
fprintf(stderr, "[MULOP:%s]", *(const char **)(v2 + 24));
break;
case 0x119:
fwrite("[ASSIGNOP]", 1uLL, 0xAuLL, stderr);
break;
case 0x11A:
fprintf(
stderr,
"[IDENT:%s|%d|%d|%d]",
***(const char ****)(v2 + 24),
*(unsigned int *)(v2 + 4),
*(unsigned int *)(v2 + 8),
*(unsigned int *)(v2 + 12));
break;
default:
fwrite("[UNKNOWN]", 1uLL, 9uLL, stderr);
break;
}
a2 += 4;
fputc(10, stderr);
result = func4(*(_QWORD *)(v2 + 32), (unsigned int)a2);
v2 = *(_QWORD *)(v2 + 40);
}
while ( v2 );
}
return result;
}

original_code:
void print_comp( comp_n *ptr, int spaces ) {
 int i;
 if( ptr == ((void *)0) ) return;
 for( i = 0; i < spaces; i++ )
  fprintf( stderr, " " );
 switch( ptr->type ) {
  case 263:
   fprintf( stderr, "\n" );
   print_statement( ptr->attr.statement, spaces+16 );
   break;
  case 281:
   fprintf( stderr, "[ASSIGNOP]" );
   break;
  case 276:
   fprintf( stderr, "[RELOP:%s]", ptr->attr.woval );
   break;
  case 278:
   fprintf( stderr, "[ADDOP:%s]", ptr->attr.woval );
   break;
  case 277:
   fprintf( stderr, "[ADDOP:%c]", ( char )ptr->attr.ival );
   break;
  case 280:
   fprintf( stderr, "[MULOP:%s]", ptr->attr.woval );
   break;
  case 279:
   fprintf( stderr, "[MULOP:%c]", ( char )ptr->attr.ival );
   break;
  case 274:
   fprintf( stderr, "[INUM:%d|%d|%d|%d]", ptr->attr.ival, ptr->index, ptr->l_not, ptr->u_minus );
   break;
  case 275:
   fprintf( stderr, "[RNUM:%f|%d|%d|%d]", ptr->attr.rval, ptr->index, ptr->l_not, ptr->u_minus );
   break;
  case 282:
   fprintf( stderr, "[IDENT:%s|%d|%d|%d]", ptr->attr.ident->e_ptr->e_symbol, ptr->index, ptr->l_not, ptr->u_minus );
   break;
  case 264:
   fprintf( stderr, "[IF]" );
   break;
  case 265:
   fprintf( stderr, "[THEN]" );
   break;
  case 266:
   fprintf( stderr, "[ELSE]" );
   break;
  case 267:
   fprintf( stderr, "[WHILE]" );
   break;
  case 268:
   fprintf( stderr, "[DO]" );
   break;
  default:
   fprintf( stderr, "[UNKNOWN]" );
   break;
 }
 fprintf( stderr, "\n" );
 print_comp( ptr->left, spaces + 4 );
 print_comp( ptr->right, spaces + 4 );
}

canonical_original_code:
void print_comp(struct comp_n *ptr, int spaces) {
 int i;
 if( ptr == ((void *)0) ) return;
 for( i = 0; i < spaces; i++ )
  fprintf( stderr, " " );
 switch( ptr->type ) {
  case 263:
   fprintf( stderr, "\n" );
   print_statement( ptr->attr.statement, spaces+16 );
   break;
  case 281:
   fprintf( stderr, "[ASSIGNOP]" );
   break;
  case 276:
   fprintf( stderr, "[RELOP:%s]", ptr->attr.woval );
   break;
  case 278:
   fprintf( stderr, "[ADDOP:%s]", ptr->attr.woval );
   break;
  case 277:
   fprintf( stderr, "[ADDOP:%c]", ( char )ptr->attr.ival );
   break;
  case 280:
   fprintf( stderr, "[MULOP:%s]", ptr->attr.woval );
   break;
  case 279:
   fprintf( stderr, "[MULOP:%c]", ( char )ptr->attr.ival );
   break;
  case 274:
   fprintf( stderr, "[INUM:%d|%d|%d|%d]", ptr->attr.ival, ptr->index, ptr->l_not, ptr->u_minus );
   break;
  case 275:
   fprintf( stderr, "[RNUM:%f|%d|%d|%d]", ptr->attr.rval, ptr->index, ptr->l_not, ptr->u_minus );
   break;
  case 282:
   fprintf( stderr, "[IDENT:%s|%d|%d|%d]", ptr->attr.ident->e_ptr->e_symbol, ptr->index, ptr->l_not, ptr->u_minus );
   break;
  case 264:
   fprintf( stderr, "[IF]" );
   break;
  case 265:
   fprintf( stderr, "[THEN]" );
   break;
  case 266:
   fprintf( stderr, "[ELSE]" );
   break;
  case 267:
   fprintf( stderr, "[WHILE]" );
   break;
  case 268:
   fprintf( stderr, "[DO]" );
   break;
  default:
   fprintf( stderr, "[UNKNOWN]" );
   break;
 }
 fprintf( stderr, "\n" );
 print_comp( ptr->left, spaces + 4 );
 print_comp( ptr->right, spaces + 4 );
}

variable_types: spaces int

variable_types: i int


decompiled_code:
int __fastcall print_ident(__int64 a1)
{
__int64 v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
fprintf(stderr, "[%s]->", **(const char ***)v1);
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
__int64 v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
fprintf(stderr, "[%s]->", **(const char ***)v1);
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return fputc(10, stderr);
}

original_code:
void print_ident( ident_n *ptr ) {
 while( ptr != ((void *)0) ) {
  fprintf( stderr, "[%s]->", ptr->e_ptr->e_symbol );
  ptr = ptr->n_ident;
 }
 fprintf( stderr, "\n" );
}

canonical_original_code:
void print_ident(struct ident_n *ptr) {
 while( ptr != ((void *)0) ) {
  fprintf( stderr, "[%s]->", ptr->e_ptr->e_symbol );
  ptr = ptr->n_ident;
 }
 fprintf( stderr, "\n" );
}


decompiled_code:
int __fastcall print_spaces(int a1)
{
int i; // ebx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = fputc(32, stderr);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
int i; // ebx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = fputc(32, stderr);
}
return result;
}

original_code:
void print_spaces( int spaces ) {
 int i;
 for( i = 0; i < spaces; i++ )
  fprintf( stderr, " " );
}

canonical_original_code:
void print_spaces(int spaces) {
 int i;
 for( i = 0; i < spaces; i++ )
  fprintf( stderr, " " );
}