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

ft_builtin();
result = *(unsigned int *)(a2 + 48);
if ( (_DWORD)result )
result = 256LL;
return result;
}

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

ft_builtin();
result = *(unsigned int *)(a2 + 48);
if ( (_DWORD)result )
result = 256LL;
return result;
}

original_code:
int ft_run_builtin(t_process *p, t_gen *env)
{
 ft_builtin(p, env);
 if (env->ret == 0)
  return (0);
 return (256);
}

canonical_original_code:
int ft_run_builtin(struct s_process *p, struct s_gen *env)
{
 ft_builtin(p, env);
 if (env->ret == 0)
  return (0);
 return (256);
}

user_defined_types: struct s_ps1 { char *env; char *aff; int len; }

user_defined_types: struct s_hist { char value[4096]; int pose_buff; int len; int modif; char buff[4096]; struct s_hist *next; struct s_hist *prev; int number; }


decompiled_code:
void __fastcall __noreturn clear_me(sem_t *sem, unsigned int *a2)
{
__int64 v2; // r12

ft_printf("je meure\n");
v2 = *(&sem[1].__align + 2);
*(_BYTE *)(v2 + (int)return_pose(sem, *a2, a2[1])) = 0;
sem_rel(sem);
sem_wait(sem);
shmdt((const void *)sem[2].__align);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(sem_t *sem, unsigned int *a2)
{
__int64 v2; // r12

ft_printf("je meure\n");
v2 = *(&sem[1].__align + 2);
*(_BYTE *)(v2 + (int)return_pose(sem, *a2, a2[1])) = 0;
sem_rel(sem);
sem_wait(sem);
shmdt((const void *)sem[2].__align);
exit(0);
}

original_code:
void clear_me(t_env *env, t_play *p)
{
 ft_printf("je meure\n");
 env->map[return_pose(env, p->init.x, p->init.y)] = 0;
 sem_rel(env);
 sem_wait(env);
 shmdt (env->mem);
 exit(0);
}

canonical_original_code:
void clear_me(struct s_env *env, struct s_play *p)
{
 ft_printf("je meure\n");
 env->map[return_pose(env, p->init.x, p->init.y)] = 0;
 sem_rel(env);
 sem_wait(env);
 shmdt (env->mem);
 exit(0);
}

variable_types: struct s_env { int verbose; char *team_id; int key; int size_x; int size_y; int seg_id; unsigned long turn; unsigned long size_mem; char *map; int sem_id; struct s_mem { int start; int team_nb; int team_max; struct s_team { char id; char name[60]; char nb_player; } team[700]; int size; int size_x; int size_y; } *mem; char player_id; int wait; int brk; int init; } *

variable_types: struct s_play { struct s_move { int x; int y; } init; struct s_move to_do; int etats; } *

return_type: void

user_defined_types: struct s_env { int verbose; char *team_id; int key; int size_x; int size_y; int seg_id; unsigned long turn; unsigned long size_mem; char *map; int sem_id; struct s_mem *mem; char player_id; int wait; int brk; int init; }

user_defined_types: struct s_play { struct s_move init; struct s_move to_do; int etats; }

user_defined_types: struct s_mem { int start; int team_nb; int team_max; struct s_team team[700]; int size; int size_x; int size_y; }


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

if ( !(unsigned int)check_case(a1, *a2, a2[1] + 1) )
return init_moove(a2, 2LL);
if ( !(unsigned int)check_case(a1, *a2 + 1, a2[1]) )
return init_moove(a2, 3LL);
if ( !(unsigned int)check_case(a1, *a2, a2[1] - 1) )
return init_moove(a2, 4LL);
result = check_case(a1, *a2 - 1, a2[1]);
if ( !(_DWORD)result )
result = init_moove(a2, 1LL);
return result;
}

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

if ( !(unsigned int)check_case(a1, *a2, a2[1] + 1) )
return init_moove(a2, 2LL);
if ( !(unsigned int)check_case(a1, *a2 + 1, a2[1]) )
return init_moove(a2, 3LL);
if ( !(unsigned int)check_case(a1, *a2, a2[1] - 1) )
return init_moove(a2, 4LL);
result = check_case(a1, *a2 - 1, a2[1]);
if ( !(_DWORD)result )
result = init_moove(a2, 1LL);
return result;
}

original_code:
void move_other(t_env *env, t_play *p)
{
 if (check_case(env, p->init.x, p->init.y + 1) == 0)
  init_moove(p, 2);
 else if (check_case(env, p->init.x + 1, p->init.y) == 0)
  init_moove(p, 3);
 else if (check_case(env, p->init.x, p->init.y - 1) == 0)
  init_moove(p, 4);
 else if (check_case(env, p->init.x - 1, p->init.y) == 0)
  init_moove(p, 1);
}

canonical_original_code:
void move_other(struct s_env *env, struct s_play *p)
{
 if (check_case(env, p->init.x, p->init.y + 1) == 0)
  init_moove(p, 2);
 else if (check_case(env, p->init.x + 1, p->init.y) == 0)
  init_moove(p, 3);
 else if (check_case(env, p->init.x, p->init.y - 1) == 0)
  init_moove(p, 4);
 else if (check_case(env, p->init.x - 1, p->init.y) == 0)
  init_moove(p, 1);
}

user_defined_types: struct s_team { char id; char name[60]; char nb_player; }


move

original_code:
void move(t_env *env, t_play *p)
{
 if (env->verbose)
  ft_printf("moove to x : %d y : %d\n", p->to_do.x, p->to_do.y);
 if (nb_enemy(env, p) >= 2)
  clear_me(env, p);
 if ((p->init.x != p->to_do.x || p->init.y != p->to_do.y)
  && env->map[return_pose(env, p->to_do.x, p->to_do.y)] == 0)
  env->map[return_pose(env, p->init.x, p->init.y)] = 0;
 if (env->map[return_pose(env, p->to_do.x, p->to_do.y)] == 0)
 {
  env->map[return_pose(env, p->to_do.x, p->to_do.y)] = env->player_id;
  p->init.x = p->to_do.x;
  p->init.y = p->to_do.y;
 }
 else
  move_other(env, p);
}

canonical_original_code:
void move(struct s_env *env, struct s_play *p)
{
 if (env->verbose)
  ft_printf("moove to x : %d y : %d\n", p->to_do.x, p->to_do.y);
 if (nb_enemy(env, p) >= 2)
  clear_me(env, p);
 if ((p->init.x != p->to_do.x || p->init.y != p->to_do.y)
  && env->map[return_pose(env, p->to_do.x, p->to_do.y)] == 0)
  env->map[return_pose(env, p->init.x, p->init.y)] = 0;
 if (env->map[return_pose(env, p->to_do.x, p->to_do.y)] == 0)
 {
  env->map[return_pose(env, p->to_do.x, p->to_do.y)] = env->player_id;
  p->init.x = p->to_do.x;
  p->init.y = p->to_do.y;
 }
 else
  move_other(env, p);
}


decompiled_code:
__int64 __fastcall ckeck_statut(__int64 a1, __int64 a2)
{
return nb_enemy(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return nb_enemy(a1, a2);
}

original_code:
int ckeck_statut(t_env *env, t_play *p)
{
 return (nb_enemy(env, p));
}

canonical_original_code:
int ckeck_statut(struct s_env *env, struct s_play *p)
{
 return (nb_enemy(env, p));
}

return_type: int


play

decompiled_code:
__int64 __fastcall play(sem_t *sem, unsigned int *a2)
{
if ( *(_DWORD *)sem->__size == 1 )
ft_printf("je joue pour la team %c\n", (unsigned int)sem[2].__size[8]);
if ( *a2 == -1 )
{
*a2 = a2[2];
}
else
{
if ( (unsigned int)ckeck_statut((__int64)sem, (__int64)a2) == 1 )
return 1LL;
search_enemy(sem, a2);
}
move(sem, a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(sem_t *sem, unsigned int *a2)
{
if ( *(_DWORD *)sem->__size == 1 )
ft_printf("je joue pour la team %c\n", (unsigned int)sem[2].__size[8]);
if ( *a2 == -1 )
{
*a2 = a2[2];
}
else
{
if ( (unsigned int)func3((__int64)sem, (__int64)a2) == 1 )
return 1LL;
search_enemy(sem, a2);
}
func2(sem, a2);
return 1LL;
}

original_code:
int play(t_env *env, t_play *p)
{
 if (env->verbose == 1)
  ft_printf("je joue pour la team %c\n", env->player_id);
 if (p->init.x != -1)
 {
  if (ckeck_statut(env, p) == 1)
   return (1);
  else
   search_enemy(env, p);
 }
 else
  p->init.x = p->to_do.x;
 move(env, p);
 return (1);
}

canonical_original_code:
int play(struct s_env *env, struct s_play *p)
{
 if (env->verbose == 1)
  ft_printf("je joue pour la team %c\n", env->player_id);
 if (p->init.x != -1)
 {
  if (ckeck_statut(env, p) == 1)
   return (1);
  else
   search_enemy(env, p);
 }
 else
  p->init.x = p->to_do.x;
 move(env, p);
 return (1);
}


original_code:
void change_nickname(t_env *env, int cs)
{
 char *tmp;
 env->fds[cs].save[ft_strlen(env->fds[cs].save) - 1] = '\0';
 printf("client %s change nick to %s\n",
   env->fds[cs].nick, env->fds[cs].save + 6);
 free(env->fds[cs].nick);
 tmp = ft_strjoin(env->fds[cs].save, " : ");
 env->fds[cs].nick = ft_strdup(tmp + 6);
 free(tmp);
 ft_strcat(env->fds[cs].buff_write, "your nick name is now : ");
 ft_strcat(env->fds[cs].buff_write, env->fds[cs].save + 6);
 ft_strcat(env->fds[cs].buff_write, "\n");
}

canonical_original_code:
void change_nickname(struct s_env *env, int cs)
{
 char *tmp;
 env->fds[cs].save[ft_strlen(env->fds[cs].save) - 1] = '\0';
 printf("client %s change nick to %s\n",
   env->fds[cs].nick, env->fds[cs].save + 6);
 free(env->fds[cs].nick);
 tmp = ft_strjoin(env->fds[cs].save, " : ");
 env->fds[cs].nick = ft_strdup(tmp + 6);
 free(tmp);
 ft_strcat(env->fds[cs].buff_write, "your nick name is now : ");
 ft_strcat(env->fds[cs].buff_write, env->fds[cs].save + 6);
 ft_strcat(env->fds[cs].buff_write, "\n");
}

variable_types: struct s_env { char *prg_name; int port; int max; int max_fd; struct s_fd { int type; void (*fct_read)(); void (*fct_write)(); char *save; char *nick; int channel; char buff_read[-1]; char buff_write[-1]; } *fds; struct s_chan { int id; char *name; } chan[100]; int ret; struct fd_set { long __fds_bits[-1]; } fd_read; struct fd_set fd_write; } *

variable_types: cs int

variable_types:
tmp
char *

user_defined_types: struct s_env { char *prg_name; int port; int max; int max_fd; struct s_fd *fds; struct s_chan chan[100]; int ret; struct fd_set fd_read; struct fd_set fd_write; }


original_code:
void change_chan(t_env *env, int cs)
{
 char *tmp;
 int i;
 i = 0;
 env->fds[cs].save[ft_strlen(env->fds[cs].save) - 1] = 0;
 tmp = ft_strtrim(env->fds[cs].save + 6);
 if (tmp[0] == '#')
 {
  while (i < 100 && env->chan[i].name != ((void *)0)
   && ft_strcmp(env->chan[i].name, tmp) != 0)
   i++;
  if (env->chan[i].name == ((void *)0))
  {
   env->chan[i].name = ft_strdup(tmp);
   env->chan[i].id = i;
  }
  env->fds[cs].channel = i;
  ft_strcat(env->fds[cs].buff_write, "you have changed channel to ");
  ft_strcat(env->fds[cs].buff_write, tmp);
  ft_strcat(env->fds[cs].buff_write, "\n");
  printf("client %schange channel to %s\n",
   env->fds[cs].nick, env->chan[i].name);
 }
 else
  send(cs, "channel name not valide start by #\n", 35, 0);
}

canonical_original_code:
void change_chan(struct s_env *env, int cs)
{
 char *tmp;
 int i;
 i = 0;
 env->fds[cs].save[ft_strlen(env->fds[cs].save) - 1] = 0;
 tmp = ft_strtrim(env->fds[cs].save + 6);
 if (tmp[0] == '#')
 {
  while (i < 100 && env->chan[i].name != ((void *)0)
   && ft_strcmp(env->chan[i].name, tmp) != 0)
   i++;
  if (env->chan[i].name == ((void *)0))
  {
   env->chan[i].name = ft_strdup(tmp);
   env->chan[i].id = i;
  }
  env->fds[cs].channel = i;
  ft_strcat(env->fds[cs].buff_write, "you have changed channel to ");
  ft_strcat(env->fds[cs].buff_write, tmp);
  ft_strcat(env->fds[cs].buff_write, "\n");
  printf("client %schange channel to %s\n",
   env->fds[cs].nick, env->chan[i].name);
 }
 else
  send(cs, "channel name not valide start by #\n", 35, 0);
}

variable_types: i int

user_defined_types: struct s_fd { int type; void (*fct_read)(); void (*fct_write)(); char *save; char *nick; int channel; char buff_read[-1]; char buff_write[-1]; }


decompiled_code:
__int64 __fastcall leave_chan(__int64 a1, int a2)
{
__int64 v2; // rdx

v2 = *(_QWORD *)(a1 + 24) + 8240LL * a2;
if ( *(_DWORD *)(v2 + 40) == -1 )
return ft_strcat(v2 + 4141, "you are not in channel\n");
*(_DWORD *)(v2 + 40) = -1;
return ft_strcat(*(_QWORD *)(a1 + 24) + 8240LL * a2 + 4141, "you are leave channel\n");
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 v2; // rdx

v2 = *(_QWORD *)(a1 + 24) + 8240LL * a2;
if ( *(_DWORD *)(v2 + 40) == -1 )
return ft_strcat(v2 + 4141, "you are not in channel\n");
*(_DWORD *)(v2 + 40) = -1;
return ft_strcat(*(_QWORD *)(a1 + 24) + 8240LL * a2 + 4141, "you are leave channel\n");
}

original_code:
void leave_chan(t_env *env, int cs)
{
 if (env->fds[cs].channel == -1)
  ft_strcat(env->fds[cs].buff_write, "you are not in channel\n");
 else
 {
  env->fds[cs].channel = -1;
  ft_strcat(env->fds[cs].buff_write, "you are leave channel\n");
 }
}

canonical_original_code:
void leave_chan(struct s_env *env, int cs)
{
 if (env->fds[cs].channel == -1)
  ft_strcat(env->fds[cs].buff_write, "you are not in channel\n");
 else
 {
  env->fds[cs].channel = -1;
  ft_strcat(env->fds[cs].buff_write, "you are leave channel\n");
 }
}


original_code:
void send_priv(t_env *env, int cs)
{
 char **splt;
 int i;
 i = 0;
 splt = ft_strsplit(env->fds[cs].save, ' ');
 while (i < env->max_fd && ft_strncmp(env->fds[i].nick, splt[1],
   ft_strlen(splt[1])) != 0)
  i++;
 if (i < env->max_fd)
 {
  ft_strcat(env->fds[i].buff_write, env->fds[cs].nick);
  ft_strcat(env->fds[i].buff_write,
    env->fds[cs].save + 7 + ft_strlen(splt[1]));
 }
 else
  ft_strcat(env->fds[cs].buff_write, "client not found\n");
}

canonical_original_code:
void send_priv(struct s_env *env, int cs)
{
 char **splt;
 int i;
 i = 0;
 splt = ft_strsplit(env->fds[cs].save, ' ');
 while (i < env->max_fd && ft_strncmp(env->fds[i].nick, splt[1],
   ft_strlen(splt[1])) != 0)
  i++;
 if (i < env->max_fd)
 {
  ft_strcat(env->fds[i].buff_write, env->fds[cs].nick);
  ft_strcat(env->fds[i].buff_write,
    env->fds[cs].save + 7 + ft_strlen(splt[1]));
 }
 else
  ft_strcat(env->fds[cs].buff_write, "client not found\n");
}

variable_types:
splt
char **


original_code:
void fct_read(t_env *env)
{
 if (recv(env->sock, env->buff_read, 4096, 0) <= 0)
 {
  close(env->sock);
  exit(0);
 }
 ft_printf("\n%s", env->buff_read);
 ft_bzero(env->buff_read, 4096);
}

canonical_original_code:
void fct_read(struct s_env *env)
{
 if (recv(env->sock, env->buff_read, 4096, 0) <= 0)
 {
  close(env->sock);
  exit(0);
 }
 ft_printf("\n%s", env->buff_read);
 ft_bzero(env->buff_read, 4096);
}

variable_types: struct s_env { int port; char *addr; int sock; int channel; char *pseudo; int ret; int aff_prompt; char buff_read[4096]; char buff_write[4096]; struct fd_set { long __fds_bits[-1]; } fd_read; struct fd_set fd_write; } *

user_defined_types: struct s_env { int port; char *addr; int sock; int channel; char *pseudo; int ret; int aff_prompt; char buff_read[4096]; char buff_write[4096]; struct fd_set fd_read; struct fd_set fd_write; }


original_code:
void fct_write(t_env *env)
{
 int ret;
 char *tmp;
 ret = read(0, env->buff_write, 4096 - 1);
 env->buff_write[ret] = 0;
 tmp = ft_strtrim(env->buff_write);
 if (tmp[0] == '/')
  checkcmd(env, tmp, ret);
 send(env->sock, env->buff_write, ret, 0);
 ft_bzero(env->buff_write, ret);
 free(tmp);
}

canonical_original_code:
void fct_write(struct s_env *env)
{
 int ret;
 char *tmp;
 ret = read(0, env->buff_write, 4096 - 1);
 env->buff_write[ret] = 0;
 tmp = ft_strtrim(env->buff_write);
 if (tmp[0] == '/')
  checkcmd(env, tmp, ret);
 send(env->sock, env->buff_write, ret, 0);
 ft_bzero(env->buff_write, ret);
 free(tmp);
}

variable_types: ret int


decompiled_code:
__int64 __fastcall ft_striteri(_BYTE *a1, __int64 (__fastcall *a2)(_QWORD, _BYTE *))
{
_BYTE *v2; // rbx
unsigned int v3; // ebp
__int64 result; // rax

if ( a1 )
{
v2 = a1;
if ( a2 )
{
if ( *a1 )
{
v3 = 0;
do
result = a2(v3++, v2++);
while ( *v2 );
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 (__fastcall *a2)(_QWORD, _BYTE *))
{
_BYTE *v2; // rbx
unsigned int v3; // ebp
__int64 result; // rax

if ( a1 )
{
v2 = a1;
if ( a2 )
{
if ( *a1 )
{
v3 = 0;
do
result = a2(v3++, v2++);
while ( *v2 );
}
}
}
return result;
}

original_code:
void ft_striteri(char *s, void (*f)(unsigned int, char *))
{
 char *s2;
 if (s && f)
 {
  s2 = s;
  while (*s2)
  {
   (*f)((s2 - s), s2);
   s2++;
  }
 }
}

variable_types:
s
char *

variable_types:
f
void (*)(unsigned int, char *)


decompiled_code:
__int64 __fastcall ft_isalnum(int a1)
{
return ((unsigned int)(a1 - 48) <= 9) | (unsigned __int8)((a1 & 0xFFFFFFDF) - 65 <= 0x19);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return ((unsigned int)(a1 - 48) <= 9) | (unsigned __int8)((a1 & 0xFFFFFFDF) - 65 <= 0x19);
}

original_code:
int ft_isalnum(int c)
{
 if (ft_isalpha(c) || ft_isdigit(c))
  return (1);
 return (0);
}

variable_types: c int


original_code:
void free_split(char ***to_free)
{
 int i;
 i = 0;
 while ((*to_free)[i] != ((void *)0))
 {
  free((*to_free)[i]);
  (*to_free)[i] = ((void *)0);
  i++;
 }
 free(*to_free);
 *to_free = ((void *)0);
}


original_code:
void parse_av(t_env *env, char **av)
{
 int i;
 i = 0;
 while (av[++i])
 {
  if (ft_strcmp(av[i], "-v") == 0)
   env->verbose = 1;
  else if (ft_strcmp(av[i], "-x") == 0 && av[i + 1])
   env->size_x = ft_atoi(av[++i]);
  else if (ft_strcmp(av[i], "-y") == 0 && av[i + 1])
   env->size_y = ft_atoi(av[++i]);
  else if (ft_strcmp(av[i], "-g") == 0)
   graphique_mode(env);
  else if (ft_strcmp(av[i], "-s") == 0)
   env->wait = 1;
  else if (env->team_id == 0)
   env->team_id = av[i];
  else
   usage(av[0]);
 }
}

canonical_original_code:
void parse_av(struct s_env *env, char **av)
{
 int i;
 i = 0;
 while (av[++i])
 {
  if (ft_strcmp(av[i], "-v") == 0)
   env->verbose = 1;
  else if (ft_strcmp(av[i], "-x") == 0 && av[i + 1])
   env->size_x = ft_atoi(av[++i]);
  else if (ft_strcmp(av[i], "-y") == 0 && av[i + 1])
   env->size_y = ft_atoi(av[++i]);
  else if (ft_strcmp(av[i], "-g") == 0)
   graphique_mode(env);
  else if (ft_strcmp(av[i], "-s") == 0)
   env->wait = 1;
  else if (env->team_id == 0)
   env->team_id = av[i];
  else
   usage(av[0]);
 }
}

variable_types:
av
char **


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
ft_fprintf(2LL, "%s usage : %s [-v] team_id \n", a1, a1);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
ft_fprintf(2LL, "%s usage : %s [-v] team_id \n", a1, a1);
exit(-1);
}

original_code:
void usage(char *name)
{
 ft_fprintf(2, "%s usage : %s [-v] team_id \n", name, name);
 exit(-1);
}

variable_types:
name
char *


original_code:
void init_env(t_env *env, char **av)
{
 env->key = ftok(av[0], 42);
 env->verbose = 0;
 env->team_id = 0;
 env->size_mem = 0;
 env->mem = ((void *)0);
 env->size_x = 25;
 env->size_y = 25;
 env->brk = 1;
 env->turn = 0;
}

canonical_original_code:
void init_env(struct s_env *env, char **av)
{
 env->key = ftok(av[0], 42);
 env->verbose = 0;
 env->team_id = 0;
 env->size_mem = 0;
 env->mem = ((void *)0);
 env->size_x = 25;
 env->size_y = 25;
 env->brk = 1;
 env->turn = 0;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[104]; // [rsp+0h] [rbp-68h] BYREF

if ( argc == 1 )
usage(*argv);
init_env((__int64)v4, argv);
parse_av((__int64)v4, (__int64)argv);
if ( (unsigned int)init_memory(v4) == 1 )
clearmap(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[104]; // [rsp+0h] [rbp-68h] BYREF

if ( argc == 1 )
func0(*argv);
func2((__int64)v4, argv);
func1((__int64)v4, (__int64)argv);
if ( (unsigned int)init_memory(v4) == 1 )
clearmap(v4);
return 0;
}

original_code:
int main(int ac, char **av)
{
 t_env env;
 if (ac == 1)
  usage(av[0]);
 init_env(&env, av);
 parse_av(&env, av);
 if (init_memory(&env) == 1)
  clearmap(&env);
 return (0);
}

canonical_original_code:
int main(int ac, char **av)
{
 struct s_env env;
 if (ac == 1)
  usage(av[0]);
 init_env(&env, av);
 parse_av(&env, av);
 if (init_memory(&env) == 1)
  clearmap(&env);
 return (0);
}

variable_types: ac int

variable_types: struct s_env { int verbose; char *team_id; int key; int size_x; int size_y; int seg_id; unsigned long turn; unsigned long size_mem; char *map; int sem_id; struct s_mem { int start; int team_nb; int team_max; struct s_team { char id; char name[60]; char nb_player; } team[700]; int size; int size_x; int size_y; } *mem; char player_id; int wait; int brk; int init; }


decompiled_code:
__int64 __fastcall ft_compn(_BYTE *a1, _BYTE *a2)
{
__int64 v2; // rax
char v3; // dl

if ( *a1 != *a2 )
return 0LL;
v2 = 1LL;
while ( a2[v2] )
{
v3 = a1[v2++];
if ( v3 != a2[v2 - 1] )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, _BYTE *a2)
{
__int64 v2; // rax
char v3; // dl

if ( *a1 != *a2 )
return 0LL;
v2 = 1LL;
while ( a2[v2] )
{
v3 = a1[v2++];
if ( v3 != a2[v2 - 1] )
return 0LL;
}
return 1LL;
}

original_code:
static int ft_compn(char *s1, char *s2)
{
 int i;
 i = 0;
 while (s1[i] == s2[i])
 {
  if (s2[i + 1] == '\0')
   return (1);
  i++;
 }
 return (0);
}


decompiled_code:
__sighandler_t init_sig()
{
signal(2, (__sighandler_t)&ft_sig_int);
return signal(20, (__sighandler_t)&ft_sig_tstp);
}

canonical_decompiled_code:
__sighandler_t func2()
{
signal(2, (__sighandler_t)&ft_sig_int);
return signal(20, (__sighandler_t)&ft_sig_tstp);
}

original_code:
void init_sig(void)
{
 signal(2, ft_sig_int);
 signal(20, ft_sig_tstp);
}

canonical_original_code:
void init_sig()
{
 signal(2, ft_sig_int);
 signal(20, ft_sig_tstp);
}


decompiled_code:
int init_term()
{
__int64 v0; // rax
__int64 v1; // rbx
const char *v2; // rbp
char v4[2056]; // [rsp+0h] [rbp-808h] BYREF

v0 = ft_getenv("TERM_PROGRAM=");
if ( (unsigned int)ft_strncmp(v0, "iTerm.app", 5LL) )
{
v2 = (const char *)ft_getenv("TERM=");
v1 = recup_gen();
if ( !v2 )
ft_puterr("term not found in env");
}
else
{
v1 = recup_gen();
v2 = "linux";
}
if ( tgetent(v4, v2) <= 0 )
ft_puterr("no acces termtype");
tcgetattr(0, (struct termios *)(*(_QWORD *)(v1 + 24) + 60LL));
ft_memcpy(*(_QWORD *)(v1 + 24), *(_QWORD *)(v1 + 24) + 60LL, 60LL);
*(_DWORD *)(*(_QWORD *)(v1 + 24) + 12LL) &= 0xFFFFFFF5;
return tcsetattr(0, 0, *(const struct termios **)(v1 + 24));
}

canonical_decompiled_code:
int func0()
{
__int64 v0; // rax
__int64 v1; // rbx
const char *v2; // rbp
char v4[2056]; // [rsp+0h] [rbp-808h] BYREF

v0 = ft_getenv("TERM_PROGRAM=");
if ( (unsigned int)ft_strncmp(v0, "iTerm.app", 5LL) )
{
v2 = (const char *)ft_getenv("TERM=");
v1 = recup_gen();
if ( !v2 )
ft_puterr("term not found in env");
}
else
{
v1 = recup_gen();
v2 = "linux";
}
if ( tgetent(v4, v2) <= 0 )
ft_puterr("no acces termtype");
tcgetattr(0, (struct termios *)(*(_QWORD *)(v1 + 24) + 60LL));
ft_memcpy(*(_QWORD *)(v1 + 24), *(_QWORD *)(v1 + 24) + 60LL, 60LL);
*(_DWORD *)(*(_QWORD *)(v1 + 24) + 12LL) &= 0xFFFFFFF5;
return tcsetattr(0, 0, *(const struct termios **)(v1 + 24));
}

original_code:
void init_term(void)
{
 t_gen *gen;
 char buff[2024];
 char *termtype;
 int ret;
 char *term;
 term = (ft_strncmp(ft_getenv("TERM_PROGRAM="), "iTerm.app", 5) == 0) ? "linux" : ft_getenv("TERM=");
 gen = recup_gen();
 if ((termtype = term) == 0)
  ft_puterr("term not found in env");
 if ((ret = tgetent(buff, termtype)) < 1)
  ft_puterr("no acces termtype");
 tcgetattr(0, &gen->term->term_ori);
 ft_memcpy(&gen->term->term, &gen->term->term_ori, sizeof(struct termios));
 gen->term->term.c_lflag &= ~(0000010 | 0000002);
 tcsetattr(0, 0, &gen->term->term);
}

canonical_original_code:
void init_term()
{
 struct s_gen *gen;
 char buff[2024];
 char *termtype;
 int ret;
 char *term;
 term = (ft_strncmp(ft_getenv("TERM_PROGRAM="), "iTerm.app", 5) == 0) ? "linux" : ft_getenv("TERM=");
 gen = recup_gen();
 if ((termtype = term) == 0)
  ft_puterr("term not found in env");
 if ((ret = tgetent(buff, termtype)) < 1)
  ft_puterr("no acces termtype");
 tcgetattr(0, &gen->term->term_ori);
 ft_memcpy(&gen->term->term, &gen->term->term_ori, sizeof(struct termios));
 gen->term->term.c_lflag &= ~(0000010 | 0000002);
 tcsetattr(0, 0, &gen->term->term);
}

variable_types: struct s_gen { char **env; char **env_orig; struct s_ps1 { char *env; char *aff; int len; } *ps1; struct s_term { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } term; struct termios term_ori; int fd; int wait; char **key; } *term; struct s_hist { char value[4096]; int pose_buff; int len; int modif; char buff[4096]; struct s_hist *next; struct s_hist *prev; int number; } *hist; struct s_builtin { char *name; char *help; } **builtin; int ret; int status; char *path; int pid_fork; } *

variable_types:
buff
char [2024]

variable_types:
termtype
char *

variable_types:
term
char *

user_defined_types: struct s_gen { char **env; char **env_orig; struct s_ps1 *ps1; struct s_term *term; struct s_hist *hist; struct s_builtin **builtin; int ret; int status; char *path; int pid_fork; }

user_defined_types: struct s_term { struct termios term; struct termios term_ori; int fd; int wait; char **key; }


decompiled_code:
int close_term()
{
__int64 v0; // rax

v0 = recup_gen();
return tcsetattr(0, 0, (const struct termios *)(*(_QWORD *)(v0 + 24) + 60LL));
}

canonical_decompiled_code:
int func1()
{
__int64 v0; // rax

v0 = recup_gen();
return tcsetattr(0, 0, (const struct termios *)(*(_QWORD *)(v0 + 24) + 60LL));
}

original_code:
void close_term(void)
{
 t_gen *gen;
 gen = recup_gen();
 tcsetattr(0, 0, &gen->term->term_ori);
}

canonical_original_code:
void close_term()
{
 struct s_gen *gen;
 gen = recup_gen();
 tcsetattr(0, 0, &gen->term->term_ori);
}

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

user_defined_types: struct s_builtin { char *name; char *help; }


clear

original_code:
void clear(t_gen *gen, char *buff)
{
 (void)buff;
 ft_putstr_fd(tgetstr("cl", ((void *)0)), gen->term->fd);
 ft_putstr(gen->ps1->aff);
 while (gen->hist->next)
  gen->hist = gen->hist->next;
 ft_bzero(gen->hist->buff, 4096);
 gen->hist->pose_buff = 0;
 gen->hist->len = 0;
 gen->hist->modif = 0;
 ft_bzero(gen->hist->value, 4096);
}

canonical_original_code:
void clear(struct s_gen *gen, char *buff)
{
 (void)buff;
 ft_putstr_fd(tgetstr("cl", ((void *)0)), gen->term->fd);
 ft_putstr(gen->ps1->aff);
 while (gen->hist->next)
  gen->hist = gen->hist->next;
 ft_bzero(gen->hist->buff, 4096);
 gen->hist->pose_buff = 0;
 gen->hist->len = 0;
 gen->hist->modif = 0;
 ft_bzero(gen->hist->value, 4096);
}

variable_types:
buff
char *


original_code:
t_term *recup_term(void)
{
 static t_term *term = ((void *)0);
 if (term == ((void *)0))
 {
  term = (t_term *)malloc(sizeof(t_term));
  term->fd = open("/dev/tty", 02);
  term->dquote = 0;
  term->quote = 0;
  term->wait_fermeture = 0;
 }
 return (term);
}

canonical_original_code:
struct s_term *recup_term()
{
 static struct s_term *term = ((void *)0);
 if (term == ((void *)0))
 {
  term = (struct s_term *)malloc(sizeof(t_term));
  term->fd = open("/dev/tty", 02);
  term->dquote = 0;
  term->quote = 0;
  term->wait_fermeture = 0;
 }
 return (term);
}

variable_types: struct s_term { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } term; struct termios term_ori; int fd; int ps1_len; char **key; int quote; int dquote; int wait_fermeture; struct s_hist { char value[4096]; int pose_cursor; int len; int modif; char buff[4096]; int exec; struct s_hist *next; struct s_hist *prev; } *hist; } *

user_defined_types: struct s_term { struct termios term; struct termios term_ori; int fd; int ps1_len; char **key; int quote; int dquote; int wait_fermeture; struct s_hist *hist; }


decompiled_code:
int init_term()
{
__int64 v0; // rbx
char *v1; // rbp
char **v2; // rax
char **v3; // rax
char v5[4120]; // [rsp+0h] [rbp-1018h] BYREF

v0 = recup_term();
v1 = getenv("TERM");
if ( !v1 )
ft_puterr("term not found in env");
if ( tgetent(v5, v1) <= 0 )
ft_puterr("no acces termtype");
tcgetattr(0, (struct termios *)(v0 + 60));
ft_memcpy(v0, v0 + 60, 60LL);
*(_DWORD *)(v0 + 12) &= 0xFFFFFFF5;
LODWORD(v2) = tcsetattr(0, 0, (const struct termios *)v0);
if ( !*(_QWORD *)(v0 + 128) )
{
v3 = (char **)malloc(0x58uLL);
*(_QWORD *)(v0 + 128) = v3;
v2 = init_key(v3);
*(_QWORD *)(v0 + 128) = v2;
}
return (int)v2;
}

canonical_decompiled_code:
int func3()
{
__int64 v0; // rbx
char *v1; // rbp
char **v2; // rax
char **v3; // rax
char v5[4120]; // [rsp+0h] [rbp-1018h] BYREF

v0 = func0();
v1 = getenv("TERM");
if ( !v1 )
ft_puterr("term not found in env");
if ( tgetent(v5, v1) <= 0 )
ft_puterr("no acces termtype");
tcgetattr(0, (struct termios *)(v0 + 60));
ft_memcpy(v0, v0 + 60, 60LL);
*(_DWORD *)(v0 + 12) &= 0xFFFFFFF5;
LODWORD(v2) = tcsetattr(0, 0, (const struct termios *)v0);
if ( !*(_QWORD *)(v0 + 128) )
{
v3 = (char **)malloc(0x58uLL);
*(_QWORD *)(v0 + 128) = v3;
v2 = func2(v3);
*(_QWORD *)(v0 + 128) = v2;
}
return (int)v2;
}

original_code:
void init_term(void)
{
 t_term *term;
 char buff[4096];
 char *termtype;
 int ret;
 term = recup_term();
 if ((termtype = getenv("TERM")) == 0)
  ft_puterr("term not found in env");
 if ((ret = tgetent(buff, termtype)) < 1)
  ft_puterr("no acces termtype");
 tcgetattr(0, &term->term_ori);
 ft_memcpy(&term->term, &term->term_ori, sizeof(struct termios));
 term->term.c_lflag &= ~(0000010 | 0000002);
 tcsetattr(0, 0, &term->term);
 if (term->key == ((void *)0))
 {
  term->key = (char **)malloc(sizeof(char *) * 11);
  term->key = init_key(term->key);
 }
}

canonical_original_code:
void init_term()
{
 struct s_term *term;
 char buff[4096];
 char *termtype;
 int ret;
 term = recup_term();
 if ((termtype = getenv("TERM")) == 0)
  ft_puterr("term not found in env");
 if ((ret = tgetent(buff, termtype)) < 1)
  ft_puterr("no acces termtype");
 tcgetattr(0, &term->term_ori);
 ft_memcpy(&term->term, &term->term_ori, sizeof(struct termios));
 term->term.c_lflag &= ~(0000010 | 0000002);
 tcsetattr(0, 0, &term->term);
 if (term->key == ((void *)0))
 {
  term->key = (char **)malloc(sizeof(char *) * 11);
  term->key = init_key(term->key);
 }
}

variable_types:
buff
char [4096]

user_defined_types: struct s_hist { char value[4096]; int pose_cursor; int len; int modif; char buff[4096]; int exec; struct s_hist *next; struct s_hist *prev; }


decompiled_code:
int close_term()
{
const struct termios *v0; // rax

v0 = (const struct termios *)recup_term();
return tcsetattr(0, 0, v0 + 1);
}

canonical_decompiled_code:
int func4()
{
const struct termios *v0; // rax

v0 = (const struct termios *)func0();
return tcsetattr(0, 0, v0 + 1);
}

original_code:
void close_term(void)
{
 t_term *term;
 term = recup_term();
 tcsetattr(0, 0, &term->term_ori);
}

canonical_original_code:
void close_term()
{
 struct s_term *term;
 term = recup_term();
 tcsetattr(0, 0, &term->term_ori);
}


decompiled_code:
void __fastcall check_redirection(int *status, __int64 a2, const char *a3)
{
int v4; // edi
int v5; // edi
int v6; // edi

v4 = status[2];
if ( v4 == -1 )
{
if ( status[4] == -1 && status[3] == -1 )
{
*(_DWORD *)(a2 + 48) = 7;
error((int)status, 0, a3);
return;
}
goto LABEL_8;
}
if ( v4 )
{
LABEL_8:
dup2(v4, 0);
close(status[2]);
}
v5 = status[3];
if ( v5 != 1 )
{
dup2(v5, 1);
close(status[3]);
}
v6 = status[4];
if ( v6 != 2 )
{
dup2(v6, 2);
close(status[4]);
}
}

canonical_decompiled_code:
void __fastcall func0(int *status, __int64 a2, const char *a3)
{
int v4; // edi
int v5; // edi
int v6; // edi

v4 = status[2];
if ( v4 == -1 )
{
if ( status[4] == -1 && status[3] == -1 )
{
*(_DWORD *)(a2 + 48) = 7;
error((int)status, 0, a3);
return;
}
goto LABEL_8;
}
if ( v4 )
{
LABEL_8:
dup2(v4, 0);
close(status[2]);
}
v5 = status[3];
if ( v5 != 1 )
{
dup2(v5, 1);
close(status[3]);
}
v6 = status[4];
if ( v6 != 2 )
{
dup2(v6, 2);
close(status[4]);
}
}

variable_types: struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *


decompiled_code:
unsigned int *__fastcall token_lst_print(unsigned int *a1)
{
unsigned int *v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
ft_putstr(&unk_71);
ft_putstr(*((_QWORD *)v1 + 1));
ft_putstr(&unk_73);
ft_putnbr(*v1);
ft_putstr(&unk_77);
if ( !*((_QWORD *)v1 + 2) )
break;
ft_putstr(" -> ");
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
}
while ( v1 );
ft_putchar(10LL);
}
return a1;
}

canonical_decompiled_code:
unsigned int *__fastcall func0(unsigned int *a1)
{
unsigned int *v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
ft_putstr(&unk_71);
ft_putstr(*((_QWORD *)v1 + 1));
ft_putstr(&unk_73);
ft_putnbr(*v1);
ft_putstr(&unk_77);
if ( !*((_QWORD *)v1 + 2) )
break;
ft_putstr(" -> ");
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
}
while ( v1 );
ft_putchar(10LL);
}
return a1;
}

original_code:
t_token *token_lst_print(t_token *token_list)
{
 t_token *ret;
 ret = token_list;
 if (token_list)
 {
  while (token_list)
  {
   ft_putstr("[");
   ft_putstr(token_list->str);
   ft_putstr("] [");
   ft_putnbr(token_list->type);
   ft_putstr("]");
   if (token_list->next)
    ft_putstr(" -> ");
   token_list = token_list->next;
  }
  ft_putchar('\n');
 }
 return (ret);
}

canonical_original_code:
struct s_token *token_lst_print(struct s_token *token_list)
{
 struct s_token *ret;
 ret = token_list;
 if (token_list)
 {
  while (token_list)
  {
   ft_putstr("[");
   ft_putstr(token_list->str);
   ft_putstr("] [");
   ft_putnbr(token_list->type);
   ft_putstr("]");
   if (token_list->next)
    ft_putstr(" -> ");
   token_list = token_list->next;
  }
  ft_putchar('\n');
 }
 return (ret);
}

variable_types: struct s_token { enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 } type; char *str; struct s_token *next; struct s_token *prev; } *

user_defined_types: struct s_token { enum e_sym type; char *str; struct s_token *next; struct s_token *prev; }


decompiled_code:
__int64 __fastcall get_job_next(__int64 a1, int a2)
{
if ( !a1 )
return 0LL;
while ( *(char *)(a1 + 8) != a2 )
{
a1 = *(_QWORD *)(a1 + 24);
if ( !a1 )
return 0LL;
}
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
if ( !a1 )
return 0LL;
while ( *(char *)(a1 + 8) != a2 )
{
a1 = *(_QWORD *)(a1 + 24);
if ( !a1 )
return 0LL;
}
return *(_QWORD *)(a1 + 24);
}

original_code:
t_job *get_job_next(t_job *job, int success)
{
 t_job *tmp;
 tmp = job;
 while (tmp != ((void *)0))
 {
  if (tmp->need_success == success)
  {
   tmp = tmp->next;
   break ;
  }
  tmp = tmp->next;
 }
 return (tmp);
}

canonical_original_code:
struct s_job *get_job_next(struct s_job *job, int success)
{
 struct s_job *tmp;
 tmp = job;
 while (tmp != ((void *)0))
 {
  if (tmp->need_success == success)
  {
   tmp = tmp->next;
   break ;
  }
  tmp = tmp->next;
 }
 return (tmp);
}

variable_types:
job
struct s_job *

variable_types: success int

variable_types: struct s_job { struct s_token { enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 } type; char *str; struct s_token *next; struct s_token *prev; } *token_lst; char need_success; struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *first_process; struct s_job *next; struct s_job *prev; } *

user_defined_types: struct s_job { struct s_token *token_lst; char need_success; struct s_process *first_process; struct s_job *next; struct s_job *prev; }


original_code:
void ft_command(t_command *com, t_gen *env)
{
 t_command *tmp;
 t_job *job;
 tmp = com;
 while (tmp != ((void *)0))
 {
  job = tmp->first_job;
  while (job)
  {
   launch_job(job, env);
   if (env->status == 256 && job->need_success == 1)
    job = get_job_next(job, 0);
   else if (env->status == 0 && job->need_success == 1)
    job = job->next;
   else if ((env->status == 256 || env->status == 65280)
     && job->need_success == 0)
    job = job->next;
   else if (env->status == 0 && job->need_success == 0)
    job = get_job_next(job, 1);
   else if (job->need_success == 2)
    job = job->next;
  }
  tmp = tmp->next;
 }
}

canonical_original_code:
void ft_command(struct s_command *com, struct s_gen *env)
{
 struct s_command *tmp;
 struct s_job *job;
 tmp = com;
 while (tmp != ((void *)0))
 {
  job = tmp->first_job;
  while (job)
  {
   launch_job(job, env);
   if (env->status == 256 && job->need_success == 1)
    job = get_job_next(job, 0);
   else if (env->status == 0 && job->need_success == 1)
    job = job->next;
   else if ((env->status == 256 || env->status == 65280)
     && job->need_success == 0)
    job = job->next;
   else if (env->status == 0 && job->need_success == 0)
    job = get_job_next(job, 1);
   else if (job->need_success == 2)
    job = job->next;
  }
  tmp = tmp->next;
 }
}

variable_types: struct s_command { struct s_token { enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 } type; char *str; struct s_token *next; struct s_token *prev; } *token_lst; struct s_job { struct s_token *token_lst; char need_success; struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *first_process; struct s_job *next; struct s_job *prev; } *first_job; char background; struct s_command *next; struct s_command *prev; } *

user_defined_types: struct s_command { struct s_token *token_lst; struct s_job *first_job; char background; struct s_command *next; struct s_command *prev; }

user_defined_types: struct s_ps1 { char *env; char *aff; int len; }


decompiled_code:
__int64 __fastcall return_char(__int64 a1)
{
return (unsigned __int8)LC0[*(int *)(*(_QWORD *)(a1 + 64) + 8LL) - 1];
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return (unsigned __int8)LC0[*(int *)(*(_QWORD *)(a1 + 64) + 8LL) - 1];
}

original_code:
char return_char(t_env *env)
{
 char c;
 char *pat;
 pat = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 c = pat[env->mem->team_max - 1];
 return (c);
}

canonical_original_code:
char return_char(struct s_env *env)
{
 char c;
 char *pat;
 pat = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 c = pat[env->mem->team_max - 1];
 return (c);
}

variable_types: struct s_env { int verbose; char *team_id; int key; int size_x; int size_y; int seg_id; unsigned long turn; unsigned long size_mem; char *map; int sem_id; struct s_mem { int start; int team_nb; int team_max; struct s_team { char id; char name[60]; char nb_player; } team[700]; int size; int size_x; int size_y; } *mem; char player_id; int wait; int brk; int init; } *

variable_types: c char

variable_types:
pat
char *

return_type: char

user_defined_types: struct s_env { int verbose; char *team_id; int key; int size_x; int size_y; int seg_id; unsigned long turn; unsigned long size_mem; char *map; int sem_id; struct s_mem *mem; char player_id; int wait; int brk; int init; }


original_code:
int init_team(t_env *env)
{
 int i;
 i = 0;
 while (i < env->mem->team_nb)
 {
  if (!ft_strcmp(env->team_id, env->mem->team[i].name))
   break ;
  i++;
 }
 if (i == env->mem->team_nb)
 {
  env->mem->team_max++;
  env->mem->team[i].id = return_char(env);
  env->player_id = return_char(env);
  ft_strcat(env->mem->team[i].name, env->team_id);
  env->mem->team[i].nb_player = 0;
 }
 else
  env->player_id = env->mem->team[i].id;
 env->mem->team[i].nb_player++;
 return (1);
}

canonical_original_code:
int init_team(struct s_env *env)
{
 int i;
 i = 0;
 while (i < env->mem->team_nb)
 {
  if (!ft_strcmp(env->team_id, env->mem->team[i].name))
   break ;
  i++;
 }
 if (i == env->mem->team_nb)
 {
  env->mem->team_max++;
  env->mem->team[i].id = return_char(env);
  env->player_id = return_char(env);
  ft_strcat(env->mem->team[i].name, env->team_id);
  env->mem->team[i].nb_player = 0;
 }
 else
  env->player_id = env->mem->team[i].id;
 env->mem->team[i].nb_player++;
 return (1);
}

variable_types: i int


decompiled_code:
__int64 __fastcall count_words(_BYTE *a1, char a2)
{
char v2; // dl
unsigned int v3; // ecx
_BYTE *v4; // rax

v2 = *a1;
if ( !*a1 )
return 1;
v3 = 1;
do
{
v4 = a1;
if ( a2 == v2 )
{
for ( ; *a1 == a2; ++a1 )
;
++v3;
v4 = a1;
}
if ( !*v4 )
break;
a1 = v4 + 1;
v2 = v4[1];
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, char a2)
{
char v2; // dl
unsigned int v3; // ecx
_BYTE *v4; // rax

v2 = *a1;
if ( !*a1 )
return 1;
v3 = 1;
do
{
v4 = a1;
if ( a2 == v2 )
{
for ( ; *a1 == a2; ++a1 )
;
++v3;
v4 = a1;
}
if ( !*v4 )
break;
a1 = v4 + 1;
v2 = v4[1];
}
while ( v2 );
return v3;
}

original_code:
static unsigned int count_words(char *s, char c)
{
 unsigned int words;
 words = 1;
 while (*s)
 {
  if (*s == c)
  {
   while (*s == c)
    s++;
   words++;
  }
  if (*s)
   s++;
 }
 return (words);
}

variable_types:
s
char *

variable_types:
words
unsigned int

return_type: unsigned int


mystrlen

decompiled_code:
__int64 __fastcall mystrlen(_BYTE *a1, char a2)
{
__int64 v2; // rax
unsigned int v3; // ecx
char v4; // dl

if ( *a1 == a2 || !*a1 )
return 0;
v2 = 1LL;
do
{
v3 = v2;
v4 = a1[v2++];
}
while ( v4 != a2 && v4 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, char a2)
{
__int64 v2; // rax
unsigned int v3; // ecx
char v4; // dl

if ( *a1 == a2 || !*a1 )
return 0;
v2 = 1LL;
do
{
v3 = v2;
v4 = a1[v2++];
}
while ( v4 != a2 && v4 );
return v3;
}

original_code:
static unsigned int mystrlen(char *s, char c)
{
 int i;
 i = 0;
 while (s[i] && s[i] != c)
  i++;
 return (i);
}


decompiled_code:
void __fastcall __noreturn go_kill(__int64 a1)
{
go_end(a1, 0LL);
destroy_gen();
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(__int64 a1)
{
go_end(a1, 0LL);
destroy_gen();
exit(0);
}

original_code:
void go_kill(t_gen *gen, char *buff)
{
 (void)buff;
 go_end(gen, ((void *)0));
 destroy_gen();
 exit(0);
}

canonical_original_code:
void go_kill(struct s_gen *gen, char *buff)
{
 (void)buff;
 go_end(gen, ((void *)0));
 destroy_gen();
 exit(0);
}

variable_types: struct s_gen { char **env; char **env_orig; struct s_ps1 { char *env; char *aff; int len; } *ps1; struct s_term { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } term; struct termios term_ori; int fd; int wait; char **key; } *term; struct s_hist { char value[4096]; int pose_buff; int len; int modif; char buff[4096]; struct s_hist *next; struct s_hist *prev; int number; } *hist; struct s_builtin { char *name; char *help; } **builtin; int ret; int status; char *path; int pid_fork; } *


original_code:
void ft_sig_int(int x)
{
 t_gen *gen;
 gen = recup_gen();
 if (gen->pid_fork > 0)
 {
  go_end(gen, ((void *)0));
  ft_putchar('\n');
  ft_putstr(gen->ps1->aff);
  while (gen->hist->next)
   gen->hist = gen->hist->next;
  ft_bzero(gen->hist->buff, 4096);
  gen->hist->pose_buff = 0;
  gen->hist->len = 0;
  gen->hist->modif = 0;
  ft_bzero(gen->hist->value, 4096);
 }
 else
  kill(gen->pid_fork, x);
}

canonical_original_code:
void ft_sig_int(int x)
{
 struct s_gen *gen;
 gen = recup_gen();
 if (gen->pid_fork > 0)
 {
  go_end(gen, ((void *)0));
  ft_putchar('\n');
  ft_putstr(gen->ps1->aff);
  while (gen->hist->next)
   gen->hist = gen->hist->next;
  ft_bzero(gen->hist->buff, 4096);
  gen->hist->pose_buff = 0;
  gen->hist->len = 0;
  gen->hist->modif = 0;
  ft_bzero(gen->hist->value, 4096);
 }
 else
  kill(gen->pid_fork, x);
}

variable_types: x int

user_defined_types: struct s_hist { char value[4096]; int pose_buff; int len; int modif; char buff[4096]; struct s_hist *next; struct s_hist *prev; int number; }


decompiled_code:
int __fastcall ft_sig_tstp(int sig)
{
__int64 v2; // rax
__pid_t v3; // edi
int result; // eax

v2 = recup_gen();
v3 = *(_DWORD *)(v2 + 64);
if ( v3 <= 0 )
result = kill(v3, sig);
else
result = ft_putstr_fd(*((_QWORD *)cur_term->type.Strings + 1), *(unsigned int *)(*(_QWORD *)(v2 + 24) + 120LL));
return result;
}

canonical_decompiled_code:
int __fastcall func1(int sig)
{
__int64 v2; // rax
__pid_t v3; // edi
int result; // eax

v2 = recup_gen();
v3 = *(_DWORD *)(v2 + 64);
if ( v3 <= 0 )
result = kill(v3, sig);
else
result = ft_putstr_fd(*((_QWORD *)cur_term->type.Strings + 1), *(unsigned int *)(*(_QWORD *)(v2 + 24) + 120LL));
return result;
}

original_code:
void ft_sig_tstp(int x)
{
 t_gen *gen;
 gen = recup_gen();
 if (gen->pid_fork > 0)
 {
  ft_putstr_fd(((TERMTYPE *)(cur_term))-> Strings[1], gen->term->fd);
 }
 else
 {
  kill(gen->pid_fork, x);
 }
}

canonical_original_code:
void ft_sig_tstp(int x)
{
 struct s_gen *gen;
 gen = recup_gen();
 if (gen->pid_fork > 0)
 {
  ft_putstr_fd(((struct termtype *)(cur_term))-> Strings[1], gen->term->fd);
 }
 else
 {
  kill(gen->pid_fork, x);
 }
}

user_defined_types: struct termtype { char *term_names; char *str_table; char *Booleans; short *Numbers; char **Strings; char *ext_str_table; char **ext_Names; unsigned short num_Booleans; unsigned short num_Numbers; unsigned short num_Strings; unsigned short ext_Booleans; unsigned short ext_Numbers; unsigned short ext_Strings; }


decompiled_code:
_BOOL8 __fastcall is_log_ope(int a1)
{
return (unsigned int)(a1 - 5) <= 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1)
{
return (unsigned int)(a1 - 5) <= 1;
}

original_code:
static t_bool is_log_ope(t_sym type)
{
 if (type == log_and)
  return (TRUE);
 if (type == log_or)
  return (TRUE);
 return (FALSE);
}

canonical_original_code:
static enum e_bool is_log_ope(enum e_sym type)
{
 if (type == log_and)
  return (TRUE);
 if (type == log_or)
  return (TRUE);
 return (FALSE);
}

variable_types: enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 }

return_type: enum e_bool { TRUE=1, FALSE=0 }


decompiled_code:
__int64 __fastcall test_success(_DWORD *a1)
{
__int64 result; // rax

if ( !a1 )
return 2LL;
result = 1LL;
if ( *a1 != 5 )
{
LOBYTE(result) = *a1 != 6;
result = (unsigned int)(2 * result);
}
return result;
}

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

if ( !a1 )
return 2LL;
result = 1LL;
if ( *a1 != 5 )
{
LOBYTE(result) = *a1 != 6;
result = (unsigned int)(2 * result);
}
return result;
}

original_code:
static char test_success(t_token *token)
{
 if (token)
 {
  if (token->type == log_and)
   return (1);
  if (token->type == log_or)
   return (0);
  else
   return (2);
 }
 return (2);
}

canonical_original_code:
static char test_success(struct s_token *token)
{
 if (token)
 {
  if (token->type == log_and)
   return (1);
  if (token->type == log_or)
   return (0);
  else
   return (2);
 }
 return (2);
}

user_defined_types: enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 }


decompiled_code:
__int64 __fastcall make_job_lst(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r13
__int64 v3; // rbp
char v4; // al
unsigned int v5; // er12
char v6; // al

v1 = a1;
v2 = 0LL;
v3 = 0LL;
if ( !a1 )
return 0LL;
do
{
while ( 1 )
{
v5 = *(_DWORD *)v1;
if ( !is_log_ope(*(_DWORD *)v1) )
break;
v4 = test_success((_DWORD *)v1);
v2 = job_lst_add(v2, v3, (unsigned int)v4);
if ( (unsigned int)(*(_DWORD *)v1 - 5) <= 1 )
{
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return v2;
}
v3 = 0LL;
}
v3 = token_add(*(_QWORD *)(v1 + 8), v5, v3);
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
v6 = test_success(0LL);
return job_lst_add(v2, v3, (unsigned int)v6);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r13
__int64 v3; // rbp
char v4; // al
unsigned int v5; // er12
char v6; // al

v1 = a1;
v2 = 0LL;
v3 = 0LL;
if ( !a1 )
return 0LL;
do
{
while ( 1 )
{
v5 = *(_DWORD *)v1;
if ( !func0(*(_DWORD *)v1) )
break;
v4 = func1((_DWORD *)v1);
v2 = job_lst_add(v2, v3, (unsigned int)v4);
if ( (unsigned int)(*(_DWORD *)v1 - 5) <= 1 )
{
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return v2;
}
v3 = 0LL;
}
v3 = token_add(*(_QWORD *)(v1 + 8), v5, v3);
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
v6 = func1(0LL);
return job_lst_add(v2, v3, (unsigned int)v6);
}

original_code:
t_job *make_job_lst(t_token *token_lst)
{
 t_job *job;
 t_token *job_token;
 char success;
 job = ((void *)0);
 while (token_lst)
 {
  job_token = ((void *)0);
  while (token_lst != ((void *)0) && !is_log_ope(token_lst->type))
  {
   job_token = token_add(token_lst->str, token_lst->type, job_token);
   token_lst = token_lst->next;
  }
  success = test_success(token_lst);
  job = job_lst_add(job, job_token, success);
  if (token_lst != ((void *)0) && (token_lst->type == log_or || token_lst->type == log_and))
   token_lst = token_lst->next;
 }
 return (job);
}

canonical_original_code:
struct s_job *make_job_lst(struct s_token *token_lst)
{
 struct s_job *job;
 struct s_token *job_token;
 char success;
 job = ((void *)0);
 while (token_lst)
 {
  job_token = ((void *)0);
  while (token_lst != ((void *)0) && !is_log_ope(token_lst->type))
  {
   job_token = token_add(token_lst->str, token_lst->type, job_token);
   token_lst = token_lst->next;
  }
  success = test_success(token_lst);
  job = job_lst_add(job, job_token, success);
  if (token_lst != ((void *)0) && (token_lst->type == log_or || token_lst->type == log_and))
   token_lst = token_lst->next;
 }
 return (job);
}

variable_types: success char

return_type: struct s_job { struct s_token { enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 } type; char *str; struct s_token *next; struct s_token *prev; } *token_lst; char need_success; struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *first_process; struct s_job *next; struct s_job *prev; } *


decompiled_code:
int aff_err()
{
char *v0; // rax
char *v1; // rax

v0 = tgetstr("mr", 0LL);
tputs(v0, 1, (int (*)(int))&ft_putc);
tputs("term to small", 1, (int (*)(int))&ft_putc);
v1 = tgetstr("me", 0LL);
return tputs(v1, 1, (int (*)(int))&ft_putc);
}

canonical_decompiled_code:
int func0()
{
char *v0; // rax
char *v1; // rax

v0 = tgetstr("mr", 0LL);
tputs(v0, 1, (int (*)(int))&ft_putc);
tputs("term to small", 1, (int (*)(int))&ft_putc);
v1 = tgetstr("me", 0LL);
return tputs(v1, 1, (int (*)(int))&ft_putc);
}

original_code:
void aff_err(void)
{
  tputs(tgetstr("mr", ((void *)0)), 1, ft_putc);
  tputs("term to small", 1, ft_putc);
  tputs(tgetstr("me", ((void *)0)), 1, ft_putc);
}

canonical_original_code:
void aff_err()
{
  tputs(tgetstr("mr", ((void *)0)), 1, ft_putc);
  tputs("term to small", 1, ft_putc);
  tputs(tgetstr("me", ((void *)0)), 1, ft_putc);
}


original_code:
void aff_lst(t_lstsel *lst, t_sig *sig)
{
 int i[2];
 int last_len;
 i[0] = 0;
 sig->y = tgetnum("li");
 sig->x = tgetnum("co");
 while (lst)
 {
  i[1] = 0;
  last_len = 0;
  while (i[1]++ < sig->y && lst)
  {
   if ((int)ft_strlen(lst->value) > sig->max_len)
    sig->max_len = (int)ft_strlen(lst->value);
   if ((int)ft_strlen(lst->value) > last_len)
    last_len = (int)ft_strlen(lst->value);
   lst = lst->next;
   i[0]++;
  }
 }
 tputs(tgetstr("cl", ((void *)0)), 1, ft_putc);
 if ((i[0] / sig->y) * (sig->max_len + 2) + last_len > sig->x)
  aff_err();
 else
  aff_tlst(sig->lst, sig);
}

canonical_original_code:
void aff_lst(struct s_lstsel *lst, struct s_sig *sig)
{
 int i[2];
 int last_len;
 i[0] = 0;
 sig->y = tgetnum("li");
 sig->x = tgetnum("co");
 while (lst)
 {
  i[1] = 0;
  last_len = 0;
  while (i[1]++ < sig->y && lst)
  {
   if ((int)ft_strlen(lst->value) > sig->max_len)
    sig->max_len = (int)ft_strlen(lst->value);
   if ((int)ft_strlen(lst->value) > last_len)
    last_len = (int)ft_strlen(lst->value);
   lst = lst->next;
   i[0]++;
  }
 }
 tputs(tgetstr("cl", ((void *)0)), 1, ft_putc);
 if ((i[0] / sig->y) * (sig->max_len + 2) + last_len > sig->x)
  aff_err();
 else
  aff_tlst(sig->lst, sig);
}

variable_types: struct s_lstsel { char *value; int sel; int pnt; struct s_lstsel *next; struct s_lstsel *prev; } *

variable_types: struct s_sig { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } term; struct termios termo; int x; int y; int max_len; struct s_lstsel *lst; } *

variable_types:
i
int [2]

user_defined_types: struct s_sig { struct termios term; struct termios termo; int x; int y; int max_len; struct s_lstsel *lst; }


affret

decompiled_code:
__int64 __fastcall affret(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = a1; i; i = *(_QWORD *)(i + 16) )
{
if ( *(_DWORD *)(i + 8) == 1 )
{
ft_putstr(*(_QWORD *)i);
result = ft_putchar(32LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = a1; i; i = *(_QWORD *)(i + 16) )
{
if ( *(_DWORD *)(i + 8) == 1 )
{
ft_putstr(*(_QWORD *)i);
result = ft_putchar(32LL);
}
}
return result;
}

original_code:
void affret(t_lstsel *lst)
{
 while (lst)
 {
  if (lst->sel == 1)
  {
   ft_putstr(lst->value);
   ft_putchar(' ');
  }
  lst = lst->next;
 }
}

canonical_original_code:
void affret(struct s_lstsel *lst)
{
 while (lst)
 {
  if (lst->sel == 1)
  {
   ft_putstr(lst->value);
   ft_putchar(' ');
  }
  lst = lst->next;
 }
}

user_defined_types: struct s_lstsel { char *value; int sel; int pnt; struct s_lstsel *next; struct s_lstsel *prev; }


decompiled_code:
void __fastcall av_del(void *ptr)
{
_QWORD *v1; // rbx

if ( *(_QWORD *)ptr )
{
v1 = ptr;
do
ft_strdel(v1++);
while ( *v1 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
_QWORD *v1; // rbx

if ( *(_QWORD *)ptr )
{
v1 = ptr;
do
ft_strdel(v1++);
while ( *v1 );
}
free(ptr);
}

original_code:
static void av_del(char **av)
{
 int i;
 i = 0;
 while (av[i])
 {
  ft_strdel(&av[i]);
  i++;
 }
 free(av);
 av = ((void *)0);
}

variable_types:
av
char **


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

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[3];
av_del(*v2);
free(v2);
}
while ( v1 );
}
}

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

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[3];
func0(*v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void process_lst_free(t_process *process_lst)
{
 t_process *curr;
 t_process *to_free;
 curr = process_lst;
 while (curr)
 {
  to_free = curr;
  curr = curr->next;
  av_del(to_free->av);
  to_free->fd[0] = 0;
  to_free->fd[1] = 0;
  to_free->fd[2] = 0;
  to_free->next = ((void *)0);
  to_free->prev = ((void *)0);
  free(to_free);
  to_free = ((void *)0);
 }
 process_lst = ((void *)0);
}

canonical_original_code:
void process_lst_free(struct s_process *process_lst)
{
 struct s_process *curr;
 struct s_process *to_free;
 curr = process_lst;
 while (curr)
 {
  to_free = curr;
  curr = curr->next;
  av_del(to_free->av);
  to_free->fd[0] = 0;
  to_free->fd[1] = 0;
  to_free->fd[2] = 0;
  to_free->next = ((void *)0);
  to_free->prev = ((void *)0);
  free(to_free);
  to_free = ((void *)0);
 }
 process_lst = ((void *)0);
}

variable_types: struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *


decompiled_code:
int __fastcall sem_block(_DWORD *a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = -1;
sops.sem_flg = 0;
if ( *a1 )
ft_printf("je tente le blockage\n");
return semop(a1[14], &sops, 1uLL);
}

canonical_decompiled_code:
int __fastcall func0(_DWORD *a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = -1;
sops.sem_flg = 0;
if ( *a1 )
ft_printf("je tente le blockage\n");
return semop(a1[14], &sops, 1uLL);
}

original_code:
int sem_block(t_env *env)
{
 struct sembuf op[1];
 int ret;
 ret = 1;
 op[0].sem_num = 0;
 op[0].sem_op = -1;
 op[0].sem_flg = 0;
 if (env->verbose)
  ft_printf("je tente le blockage\n");
 ret = semop(env->sem_id, op, 1);
 return (ret);
}

canonical_original_code:
int sem_block(struct s_env *env)
{
 struct sembuf op[1];
 int ret;
 ret = 1;
 op[0].sem_num = 0;
 op[0].sem_op = -1;
 op[0].sem_flg = 0;
 if (env->verbose)
  ft_printf("je tente le blockage\n");
 ret = semop(env->sem_id, op, 1);
 return (ret);
}

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; } [1]

variable_types: ret int

user_defined_types: struct s_mem { int start; int team_nb; int team_max; struct s_team team[700]; int size; int size_x; int size_y; }

user_defined_types: struct s_team { char id; char name[60]; char nb_player; }


decompiled_code:
int __fastcall sem_rel(_DWORD *a1)
{
int result; // eax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = 1;
sops.sem_flg = 2048;
if ( *a1 )
ft_printf("je tente le blockage\n");
result = semctl(a1[14], 0, 12, 1LL);
if ( !result )
result = semop(a1[14], &sops, 1uLL);
if ( *a1 )
result = ft_printf("je tente le blockage\n");
return result;
}

canonical_decompiled_code:
int __fastcall func1(_DWORD *a1)
{
int result; // eax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = 1;
sops.sem_flg = 2048;
if ( *a1 )
ft_printf("je tente le blockage\n");
result = semctl(a1[14], 0, 12, 1LL);
if ( !result )
result = semop(a1[14], &sops, 1uLL);
if ( *a1 )
result = ft_printf("je tente le blockage\n");
return result;
}

original_code:
void sem_rel(t_env *env)
{
 struct sembuf op[1];
 op[0].sem_num = 0;
 op[0].sem_op = 1;
 op[0].sem_flg = 04000;
 if (env->verbose)
  ft_printf("je tente le blockage\n");
 if (semctl(env->sem_id, 0, 12, 1) == 0)
  semop(env->sem_id, op, 1);
 if (env->verbose)
  ft_printf("je tente le blockage\n");
}

canonical_original_code:
void sem_rel(struct s_env *env)
{
 struct sembuf op[1];
 op[0].sem_num = 0;
 op[0].sem_op = 1;
 op[0].sem_flg = 04000;
 if (env->verbose)
  ft_printf("je tente le blockage\n");
 if (semctl(env->sem_id, 0, 12, 1) == 0)
  semop(env->sem_id, op, 1);
 if (env->verbose)
  ft_printf("je tente le blockage\n");
}

variable_types: struct s_env { int verbose; char *team_id; int key; int size_x; int size_y; int seg_id; unsigned long turn; unsigned long size_mem; char *map; int sem_id; struct s_mem { int start; int team_nb; int team_max; struct s_team { char id; char name[60]; char nb_player; } team[700]; int size; int size_x; int size_y; } *mem; char player_id; int wait; int brk; int init; } *

user_defined_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


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

v1 = semget(*(_DWORD *)(a1 + 16), 1, 896);
*(_DWORD *)(a1 + 56) = v1;
if ( v1 <= 0 )
{
ft_fprintf(2LL, "fail to get semaphore\n");
exit(-1);
}
if ( !semctl(v1, 0, 11, 0LL) )
semctl(*(_DWORD *)(a1 + 56), 0, 16, 1LL);
return 1LL;
}

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

v1 = semget(*(_DWORD *)(a1 + 16), 1, 896);
*(_DWORD *)(a1 + 56) = v1;
if ( v1 <= 0 )
{
ft_fprintf(2LL, "fail to get semaphore\n");
exit(-1);
}
if ( !semctl(v1, 0, 11, 0LL) )
semctl(*(_DWORD *)(a1 + 56), 0, 16, 1LL);
return 1LL;
}

original_code:
int init_sem(t_env *env)
{
 if ((env->sem_id = semget(env->key, 1, 01000 | 0400 | 0200)) <= 0)
 {
  ft_fprintf(2, "fail to get semaphore\n");
  exit (-1);
 }
 if (semctl(env->sem_id, 0, 11, 0) == 0)
  semctl(env->sem_id, 0, 16, 1);
 return (1);
}

canonical_original_code:
int init_sem(struct s_env *env)
{
 if ((env->sem_id = semget(env->key, 1, 01000 | 0400 | 0200)) <= 0)
 {
  ft_fprintf(2, "fail to get semaphore\n");
  exit (-1);
 }
 if (semctl(env->sem_id, 0, 11, 0) == 0)
  semctl(env->sem_id, 0, 16, 1);
 return (1);
}


decompiled_code:
int __fastcall sem_wait(__int64 a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = 0;
sops.sem_flg = 0;
return semop(*(_DWORD *)(a1 + 56), &sops, 1uLL);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = 0;
sops.sem_flg = 0;
return semop(*(_DWORD *)(a1 + 56), &sops, 1uLL);
}

original_code:
void sem_wait(t_env *env)
{
 struct sembuf op[1];
 op[0].sem_num = 0;
 op[0].sem_op = 0;
 op[0].sem_flg = 0;
 semop(env->sem_id, op, 1);
}

canonical_original_code:
void sem_wait(struct s_env *env)
{
 struct sembuf op[1];
 op[0].sem_num = 0;
 op[0].sem_op = 0;
 op[0].sem_flg = 0;
 semop(env->sem_id, op, 1);
}


original_code:
int clean_hist(t_hist *hist)
{
 t_hist *tmp;
 if (hist == ((void *)0))
  return (1) ;
 tmp = hist;
 while (hist->next)
  hist = hist->next;
 if (hist->exec == 0 && hist->next == ((void *)0))
 {
  ft_strcpy(hist->value, tmp->buff);
  ft_strcpy(hist->buff, hist->value);
  hist->exec = 1;
  hist->len = ft_strlen(hist->value);
  hist->pose_cursor = hist->len;
 }
 restor_hist(hist);
 return (0);
}

canonical_original_code:
int clean_hist(struct s_hist *hist)
{
 struct s_hist *tmp;
 if (hist == ((void *)0))
  return (1) ;
 tmp = hist;
 while (hist->next)
  hist = hist->next;
 if (hist->exec == 0 && hist->next == ((void *)0))
 {
  ft_strcpy(hist->value, tmp->buff);
  ft_strcpy(hist->buff, hist->value);
  hist->exec = 1;
  hist->len = ft_strlen(hist->value);
  hist->pose_cursor = hist->len;
 }
 restor_hist(hist);
 return (0);
}

variable_types: struct s_hist { char value[4096]; int pose_cursor; int len; int modif; char buff[4096]; int exec; struct s_hist *next; struct s_hist *prev; } *


original_code:
void restor_hist(t_hist *hist)
{
 while (hist)
 {
  if (hist->modif == 1)
  {
   ft_strcpy(hist->buff, hist->value);
   hist->len = (int)ft_strlen(hist->value);
   hist->pose_cursor = hist->len;
   hist->modif = 0;
  }
 hist = hist->prev;
 }
}

canonical_original_code:
void restor_hist(struct s_hist *hist)
{
 while (hist)
 {
  if (hist->modif == 1)
  {
   ft_strcpy(hist->buff, hist->value);
   hist->len = (int)ft_strlen(hist->value);
   hist->pose_cursor = hist->len;
   hist->modif = 0;
  }
 hist = hist->prev;
 }
}


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

if ( *(int *)(*(_QWORD *)(a1 + 152) + 4096LL) <= 0 )
return ft_putstr(*((_QWORD *)cur_term->type.Strings + 1));
ft_putstr_fd(*(_QWORD *)(*(_QWORD *)(a1 + 128) + 32LL), *(unsigned int *)(a1 + 120));
--*(_DWORD *)(*(_QWORD *)(a1 + 152) + 4096LL);
result = *(_QWORD *)(a1 + 152);
*(_DWORD *)(result + 4104) = 1;
return result;
}

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

if ( *(int *)(*(_QWORD *)(a1 + 152) + 4096LL) <= 0 )
return ft_putstr(*((_QWORD *)cur_term->type.Strings + 1));
ft_putstr_fd(*(_QWORD *)(*(_QWORD *)(a1 + 128) + 32LL), *(unsigned int *)(a1 + 120));
--*(_DWORD *)(*(_QWORD *)(a1 + 152) + 4096LL);
result = *(_QWORD *)(a1 + 152);
*(_DWORD *)(result + 4104) = 1;
return result;
}

original_code:
void arrow_left(t_term *term)
{
 if (term->hist->pose_cursor > 0)
 {
  ft_putstr_fd(term->key[4], term->fd);
  term->hist->pose_cursor--;
  term->hist->modif = 1;
 }
 else
  ft_putstr(((TERMTYPE *)(cur_term))-> Strings[1]);
}

canonical_original_code:
void arrow_left(struct s_term *term)
{
 if (term->hist->pose_cursor > 0)
 {
  ft_putstr_fd(term->key[4], term->fd);
  term->hist->pose_cursor--;
  term->hist->modif = 1;
 }
 else
  ft_putstr(((struct termtype *)(cur_term))-> Strings[1]);
}

variable_types: struct s_term { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } term; struct termios term_ori; int fd; int ps1_len; char **key; int quote; int dquote; int wait_fermeture; struct s_hist { char value[4096]; int pose_cursor; int len; int modif; char buff[4096]; int exec; struct s_hist *next; struct s_hist *prev; } *hist; } *


original_code:
void arrow_right(t_term *term)
{
 if (term->hist->pose_cursor < term->hist->len)
 {
  ft_putstr_fd(term->key[3], term->fd);
  term->hist->modif = 1;
  term->hist->pose_cursor++;
 }
 else
  ft_putstr(((TERMTYPE *)(cur_term))-> Strings[1]);
}

canonical_original_code:
void arrow_right(struct s_term *term)
{
 if (term->hist->pose_cursor < term->hist->len)
 {
  ft_putstr_fd(term->key[3], term->fd);
  term->hist->modif = 1;
  term->hist->pose_cursor++;
 }
 else
  ft_putstr(((struct termtype *)(cur_term))-> Strings[1]);
}

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


original_code:
void arrow_up(t_term *term)
{
 int i;
 i = term->hist->pose_cursor - 1;
 if (term->hist->prev != ((void *)0) && term->wait_fermeture == 0)
 {
  clean_line(term);
  term->hist->exec = 0;
  term->hist = term->hist->prev;
  term->hist->exec = 1;
  ft_putstr(term->hist->buff);
  i = term->hist->len + 1;
  while (--i != term->hist->pose_cursor)
   ft_putstr_fd(term->key[4], term->fd);
 }
 else
  ft_putstr(((TERMTYPE *)(cur_term))-> Strings[1]);
}

canonical_original_code:
void arrow_up(struct s_term *term)
{
 int i;
 i = term->hist->pose_cursor - 1;
 if (term->hist->prev != ((void *)0) && term->wait_fermeture == 0)
 {
  clean_line(term);
  term->hist->exec = 0;
  term->hist = term->hist->prev;
  term->hist->exec = 1;
  ft_putstr(term->hist->buff);
  i = term->hist->len + 1;
  while (--i != term->hist->pose_cursor)
   ft_putstr_fd(term->key[4], term->fd);
 }
 else
  ft_putstr(((struct termtype *)(cur_term))-> Strings[1]);
}

variable_types: i int


original_code:
void arrow_down(t_term *term)
{
 int i;
 i = term->hist->pose_cursor - 1;
 if (term->hist->next != ((void *)0) && term->wait_fermeture == 0)
 {
  clean_line(term);
  term->hist->exec = 0;
  term->hist = term->hist->next;
  term->hist->exec = 1;
   ft_putstr(term->hist->buff);
  i = term->hist->len + 1;
  while (--i != term->hist->pose_cursor)
   ft_putstr_fd(term->key[4], term->fd);
 }
 else
  ft_putstr(((TERMTYPE *)(cur_term))-> Strings[1]);
}

canonical_original_code:
void arrow_down(struct s_term *term)
{
 int i;
 i = term->hist->pose_cursor - 1;
 if (term->hist->next != ((void *)0) && term->wait_fermeture == 0)
 {
  clean_line(term);
  term->hist->exec = 0;
  term->hist = term->hist->next;
  term->hist->exec = 1;
   ft_putstr(term->hist->buff);
  i = term->hist->len + 1;
  while (--i != term->hist->pose_cursor)
   ft_putstr_fd(term->key[4], term->fd);
 }
 else
  ft_putstr(((struct termtype *)(cur_term))-> Strings[1]);
}


clear

original_code:
void clear(t_term *term)
{
 t_env *env;
 while (term->hist->next)
  term->hist = term->hist->next;
 ft_bzero(term->hist->buff, 4096);
 ft_bzero(term->hist->value, 4096);
 env = return_env();
 ft_putstr_fd(tgetstr("cl", ((void *)0)), term->fd);
 term->hist->pose_cursor = 0;
 term->hist->len = 0;
 parse_ps1(env);
}

canonical_original_code:
void clear(struct s_term *term)
{
 struct s_env *env;
 while (term->hist->next)
  term->hist = term->hist->next;
 ft_bzero(term->hist->buff, 4096);
 ft_bzero(term->hist->value, 4096);
 env = return_env();
 ft_putstr_fd(tgetstr("cl", ((void *)0)), term->fd);
 term->hist->pose_cursor = 0;
 term->hist->len = 0;
 parse_ps1(env);
}

variable_types: struct s_env { char **path; char *ps1; int ps1_len; char *home; char pwd[4096]; char **environ; int pid; } *


decompiled_code:
ssize_t __fastcall ft_putchar_fd(char a1, int a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(a2, buf, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func0(char a1, int a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(a2, buf, 1uLL);
}

original_code:
void ft_putchar_fd(char c, int fd)
{
 write(fd, &c, 1);
}

variable_types: c char

variable_types: fd int


original_code:
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
 t_list *tmp;
 t_list *new;
 t_list *curr;
 t_list *save;
 if (lst && f)
 {
  curr = (t_list *)malloc(sizeof(t_list));
  curr = f(lst);
  save = curr;
  tmp = lst->next;
  while (tmp != ((void *)0))
  {
   new = (t_list *)malloc(sizeof(t_list));
   new = f(tmp);
   tmp = tmp->next;
   curr->next = new;
   curr = curr->next;
   new = ((void *)0);
  }
  return (save);
 }
 return (lst);
}

canonical_original_code:
struct s_list *ft_lstmap(struct s_list *lst, struct s_list *(*f)(struct s_list *elem))
{
 struct s_list *tmp;
 struct s_list *new;
 struct s_list *curr;
 struct s_list *save;
 if (lst && f)
 {
  curr = (struct s_list *)malloc(sizeof(t_list));
  curr = f(lst);
  save = curr;
  tmp = lst->next;
  while (tmp != ((void *)0))
  {
   new = (struct s_list *)malloc(sizeof(t_list));
   new = f(tmp);
   tmp = tmp->next;
   curr->next = new;
   curr = curr->next;
   new = ((void *)0);
  }
  return (save);
 }
 return (lst);
}

variable_types:
lst
struct s_list *

variable_types:
f
struct s_list *(*)(struct s_list *elem)

variable_types: struct s_list { void *content; unsigned long content_size; struct s_list *next; } *


decompiled_code:
__int64 ft_printf(char *a1, ...)
{
char v2; // di
unsigned int v3; // ebp
int v4; // ebx
__int64 v5; // rax
char *v6; // rax
char v7; // r13
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF

va_start(va, a1);
v2 = *a1;
if ( !v2 )
return 0;
v3 = 0;
v4 = 0;
v5 = 0LL;
do
{
if ( v2 == 37 && (v6 = &a1[v5 + 1], (v7 = *v6) != 0) )
{
v4 += ft_sizei(v6) + 1;
v3 += ft_arg(a1[v4], (unsigned int *)va, (unsigned int)v7, 1u);
}
else
{
v3 += ft_putchar((unsigned int)v2);
}
v5 = ++v4;
v2 = a1[v4];
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 func1(char *a1, ...)
{
char v2; // di
unsigned int v3; // ebp
int v4; // ebx
__int64 v5; // rax
char *v6; // rax
char v7; // r13
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF

va_start(va, a1);
v2 = *a1;
if ( !v2 )
return 0;
v3 = 0;
v4 = 0;
v5 = 0LL;
do
{
if ( v2 == 37 && (v6 = &a1[v5 + 1], (v7 = *v6) != 0) )
{
v4 += ft_sizei(v6) + 1;
v3 += func0(a1[v4], (unsigned int *)va, (unsigned int)v7, 1u);
}
else
{
v3 += ft_putchar((unsigned int)v2);
}
v5 = ++v4;
v2 = a1[v4];
}
while ( v2 );
return v3;
}

original_code:
int ft_printf(const char *s, ...)
{
 va_list ap;
 int i;
 int result;
 char flag;
 i = 0;
 result = 0;
 __builtin_va_start(ap,s);
 while (s[i] != '\0')
 {
  if (s[i] == '%' && s[i + 1] != '\0')
  {
   i++;
   flag = s[i];
   i = i + ft_sizei((char *)&s[i]);
   result = result + ft_arg(s[i], ap, flag);
  }
  else
   result = result + ft_putchar(s[i]);
  i++;
 }
 __builtin_va_end(ap);
 return (result);
}

canonical_original_code:
int ft_printf(char *s, ...)
{
 __builtin_va_list ap;
 int i;
 int result;
 char flag;
 i = 0;
 result = 0;
 __builtin_va_start(ap,s);
 while (s[i] != '\0')
 {
  if (s[i] == '%' && s[i + 1] != '\0')
  {
   i++;
   flag = s[i];
   i = i + ft_sizei((char *)&s[i]);
   result = result + ft_arg(s[i], ap, flag);
  }
  else
   result = result + ft_putchar(s[i]);
  i++;
 }
 __builtin_va_end(ap);
 return (result);
}

variable_types:
s
char *

variable_types: result int

variable_types: flag char


decompiled_code:
void __fastcall ft_help(unsigned int *a1, const char ***a2)
{
const char ***v2; // rbx
const char **v3; // rax
const char ***v4; // r12
const char *v5; // rdx
const char ***i; // rbx
__int64 v7; // rsi

if ( a2 )
{
v2 = a2;
if ( !(unsigned int)ft_strcmp(**(_QWORD **)a1, "help") || !*(_QWORD *)(*(_QWORD *)a1 + 8LL) )
{
v3 = *a2;
v4 = a2;
if ( *a2 )
{
while ( *v3 )
{
v7 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( v7 && !(unsigned int)ft_strcmp(*v3, v7) )
{
ft_dprintf(a1[3], "NAME : %s\n\n%s\n", **v4, (*v4)[1]);
return;
}
v3 = *++v4;
if ( !*v4 )
break;
}
}
}
v5 = **v2;
for ( i = v2 + 1; v5; ++i )
{
ft_dprintf(a1[3], "%s\n", v5);
v5 = **i;
}
}
}

canonical_decompiled_code:
void __fastcall func0(unsigned int *a1, const char ***a2)
{
const char ***v2; // rbx
const char **v3; // rax
const char ***v4; // r12
const char *v5; // rdx
const char ***i; // rbx
__int64 v7; // rsi

if ( a2 )
{
v2 = a2;
if ( !(unsigned int)ft_strcmp(**(_QWORD **)a1, "help") || !*(_QWORD *)(*(_QWORD *)a1 + 8LL) )
{
v3 = *a2;
v4 = a2;
if ( *a2 )
{
while ( *v3 )
{
v7 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( v7 && !(unsigned int)ft_strcmp(*v3, v7) )
{
ft_dprintf(a1[3], "NAME : %s\n\n%s\n", **v4, (*v4)[1]);
return;
}
v3 = *++v4;
if ( !*v4 )
break;
}
}
}
v5 = **v2;
for ( i = v2 + 1; v5; ++i )
{
ft_dprintf(a1[3], "%s\n", v5);
v5 = **i;
}
}
}

original_code:
void ft_help(t_process *p, t_builtin **builtin)
{
 int i;
 i = 0;
 if (builtin)
 {
  if (!(ft_strcmp(p->av[0], "help") && p->av[1] != ((void *)0)))
  {
   while (builtin[i] && builtin[i]->name != ((void *)0))
   {
    if (p->av[1] && !(ft_strcmp(builtin[i]->name, p->av[1])))
    {
     ft_dprintf(p->fd[1], "NAME : %s\n\n%s\n",
       builtin[i]->name, builtin[i]->help);
     return ;
    }
    i++;
   }
  }
  i = 0;
  while (builtin[i]->name != ((void *)0))
   ft_dprintf(p->fd[1], "%s\n", builtin[i++]->name);
 }
}

canonical_original_code:
void ft_help(struct s_process *p, struct s_builtin **builtin)
{
 int i;
 i = 0;
 if (builtin)
 {
  if (!(ft_strcmp(p->av[0], "help") && p->av[1] != ((void *)0)))
  {
   while (builtin[i] && builtin[i]->name != ((void *)0))
   {
    if (p->av[1] && !(ft_strcmp(builtin[i]->name, p->av[1])))
    {
     ft_dprintf(p->fd[1], "NAME : %s\n\n%s\n",
       builtin[i]->name, builtin[i]->help);
     return ;
    }
    i++;
   }
  }
  i = 0;
  while (builtin[i]->name != ((void *)0))
   ft_dprintf(p->fd[1], "%s\n", builtin[i++]->name);
 }
}

variable_types: struct s_builtin { char *name; char *help; } **

user_defined_types: struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; }


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

result = malloc(0x20uLL);
if ( result )
{
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
*(_DWORD *)result = 11;
}
return result;
}

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

result = malloc(0x20uLL);
if ( result )
{
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
*(_DWORD *)result = 11;
}
return result;
}

original_code:
t_token *create_token(void)
{
 t_token *new;
 if (!(new = (t_token *)malloc(sizeof(t_token))))
  return (((void *)0));
 new->str = ((void *)0);
 new->next = ((void *)0);
 new->prev = ((void *)0);
 new->type = unknown;
 return (new);
}

canonical_original_code:
struct s_token *create_token()
{
 struct s_token *new;
 if (!(new = (struct s_token *)malloc(sizeof(t_token))))
  return (((void *)0));
 new->str = ((void *)0);
 new->next = ((void *)0);
 new->prev = ((void *)0);
 new->type = unknown;
 return (new);
}

variable_types: struct s_token { enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 } type; char *str; struct s_token *next; struct s_token *prev; } *


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

result = is_operator();
if ( (_DWORD)result == 11 )
result = is_word(a1);
return result;
}

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

result = is_operator();
if ( (_DWORD)result == 11 )
result = is_word(a1);
return result;
}

original_code:
t_sym get_token_type(char *str)
{
 t_sym type;
 if ((type = is_operator(str)) != unknown)
  return (type);
 if ((type = is_word(str)) != unknown)
  return (type);
 return (unknown);
}

canonical_original_code:
enum e_sym get_token_type(char *str)
{
 enum e_sym type;
 if ((type = is_operator(str)) != unknown)
  return (type);
 if ((type = is_word(str)) != unknown)
  return (type);
 return (unknown);
}

variable_types:
str
char *

variable_types: enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 }


original_code:
t_command *command_lst_add(t_command *command_lst, t_token *token, char background)
{
 t_command *curr;
 t_command *new;
 if (!(new = create_command(token)))
  return (((void *)0));
 new->background = background;
 if (!command_lst)
  return (new);
 curr = command_lst;
 while (curr->next != ((void *)0))
  curr = curr->next;
 curr->next = new;
 new->prev = curr;
 return (command_lst);
}

canonical_original_code:
struct s_command *command_lst_add(struct s_command *command_lst, struct s_token *token, char background)
{
 struct s_command *curr;
 struct s_command *new;
 if (!(new = create_command(token)))
  return (((void *)0));
 new->background = background;
 if (!command_lst)
  return (new);
 curr = command_lst;
 while (curr->next != ((void *)0))
  curr = curr->next;
 curr->next = new;
 new->prev = curr;
 return (command_lst);
}

variable_types:
token
struct s_token *

variable_types: background char

variable_types: struct s_command { struct s_token { enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 } type; char *str; struct s_token *next; struct s_token *prev; } *token_lst; struct s_job { struct s_token *token_lst; char need_success; struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *first_process; struct s_job *next; struct s_job *prev; } *first_job; char background; struct s_command *next; struct s_command *prev; } *


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

if ( a1 )
{
v2 = a1;
if ( a2 )
{
do
{
result = a2(v2);
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
}
}
return result;
}

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

if ( a1 )
{
v2 = a1;
if ( a2 )
{
do
{
result = a2(v2);
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
}
}
return result;
}

original_code:
void ft_lstiter(t_list *lst, void (*f)(t_list *elem))
{
 t_list *tmp;
 if (lst && f)
 {
  tmp = lst;
  while (tmp != ((void *)0))
  {
   f(tmp);
   tmp = tmp->next;
  }
 }
}

canonical_original_code:
void ft_lstiter(struct s_list *lst, void (*f)(struct s_list *elem))
{
 struct s_list *tmp;
 if (lst && f)
 {
  tmp = lst;
  while (tmp != ((void *)0))
  {
   f(tmp);
   tmp = tmp->next;
  }
 }
}

variable_types:
f
void (*)(struct s_list *elem)

user_defined_types: struct s_list { void *content; unsigned long content_size; struct s_list *next; }


decompiled_code:
__int64 __fastcall make_command_lst(unsigned int *a1)
{
unsigned int *v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rsi

v1 = a1;
v2 = 0LL;
v3 = 0LL;
if ( !a1 )
return 0LL;
do
{
while ( 1 )
{
v4 = *v1;
if ( (unsigned int)(v4 - 7) > 1 )
break;
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
v2 = command_lst_add(v2, v3, (_DWORD)v4 == 7);
if ( !v1 )
return v2;
v3 = 0LL;
}
v3 = token_add(*((_QWORD *)v1 + 1), v4, v3);
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
}
while ( v1 );
return command_lst_add(v2, v3, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
unsigned int *v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rsi

v1 = a1;
v2 = 0LL;
v3 = 0LL;
if ( !a1 )
return 0LL;
do
{
while ( 1 )
{
v4 = *v1;
if ( (unsigned int)(v4 - 7) > 1 )
break;
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
v2 = command_lst_add(v2, v3, (_DWORD)v4 == 7);
if ( !v1 )
return v2;
v3 = 0LL;
}
v3 = token_add(*((_QWORD *)v1 + 1), v4, v3);
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
}
while ( v1 );
return command_lst_add(v2, v3, 0LL);
}

original_code:
t_command *make_command_lst(t_token *token_lst)
{
 t_command *command_lst;
 t_token *curr_tok;
 t_token *com_token;
 char exec;
 curr_tok = token_lst;
 command_lst = ((void *)0);
 while (curr_tok != ((void *)0))
 {
  exec = 0;
  com_token = ((void *)0);
  while (curr_tok && curr_tok->type != colon && curr_tok->type != bg)
  {
   com_token = token_add(curr_tok->str, curr_tok->type, com_token);
   curr_tok = curr_tok->next;
  }
  if (curr_tok)
  {
   if (curr_tok->type == bg)
    exec = 1;
   curr_tok = curr_tok->next;
  }
  command_lst = command_lst_add(command_lst, com_token, exec);
 }
 return (command_lst);
}

canonical_original_code:
struct s_command *make_command_lst(struct s_token *token_lst)
{
 struct s_command *command_lst;
 struct s_token *curr_tok;
 struct s_token *com_token;
 char exec;
 curr_tok = token_lst;
 command_lst = ((void *)0);
 while (curr_tok != ((void *)0))
 {
  exec = 0;
  com_token = ((void *)0);
  while (curr_tok && curr_tok->type != colon && curr_tok->type != bg)
  {
   com_token = token_add(curr_tok->str, curr_tok->type, com_token);
   curr_tok = curr_tok->next;
  }
  if (curr_tok)
  {
   if (curr_tok->type == bg)
    exec = 1;
   curr_tok = curr_tok->next;
  }
  command_lst = command_lst_add(command_lst, com_token, exec);
 }
 return (command_lst);
}

variable_types: exec char

return_type: struct s_command { struct s_token { enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 } type; char *str; struct s_token *next; struct s_token *prev; } *token_lst; struct s_job { struct s_token *token_lst; char need_success; struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *first_process; struct s_job *next; struct s_job *prev; } *first_job; char background; struct s_command *next; struct s_command *prev; } *


decompiled_code:
__int64 __fastcall ft_perr(void *buf)
{
size_t v1; // rax

v1 = ft_strlen();
write(2, buf, v1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *buf)
{
size_t v1; // rax

v1 = ft_strlen();
write(2, buf, v1);
return 1LL;
}

original_code:
int ft_perr(char *s)
{
  write(2, s, ft_strlen(s));
  return (1);
}


decompiled_code:
void __fastcall ft_memdel(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func0(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}

original_code:
void ft_memdel(void **ap)
{
 if (*ap)
 {
  free(*ap);
  *ap = ((void *)0);
 }
}

variable_types:
ap
void **


decompiled_code:
__int64 __fastcall ft_toupper(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( a1 - 97 < 0x1A )
result = a1 - 32;
return result;
}

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

result = a1;
if ( a1 - 97 < 0x1A )
result = a1 - 32;
return result;
}

original_code:
int ft_toupper(int c)
{
 if (c <= 122 && c >= 97)
 {
  return (c - 32);
 }
 else
 {
  return (c);
 }
}

variable_types: c int


decompiled_code:
ssize_t __fastcall ft_echo(int *a1)
{
ssize_t result; // rax
__int64 v3; // rdi
_BOOL4 v4; // er13
int v5; // er12
__int64 v6; // rbx

result = *(_QWORD *)a1;
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( v3 )
{
v4 = ft_strcmp(v3, &unk_D6) == 0;
v5 = v4 - 1 + 2;
result = v4 + 2;
v6 = 8 * result;
if ( *(_QWORD *)(*(_QWORD *)a1 + 8 * result) )
{
if ( *(_QWORD *)(*(_QWORD *)a1 + v6 - 8) )
{
while ( 1 )
{
ft_dprintf((unsigned int)a1[3], &unk_D9);
++v5;
result = *(_QWORD *)a1;
if ( !*(_QWORD *)(*(_QWORD *)a1 + v6) )
break;
v6 += 8LL;
if ( !*(_QWORD *)(result + v6) )
goto LABEL_6;
}
}
}
else
{
LABEL_6:
result = *(_QWORD *)a1;
if ( *(_QWORD *)(*(_QWORD *)a1 + 8LL * v5) )
result = ft_dprintf((unsigned int)a1[3], &unk_DD);
}
if ( !v4 )
result = write(a1[3], &unk_E0, 1uLL);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func0(int *a1)
{
ssize_t result; // rax
__int64 v3; // rdi
_BOOL4 v4; // er13
int v5; // er12
__int64 v6; // rbx

result = *(_QWORD *)a1;
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( v3 )
{
v4 = ft_strcmp(v3, &unk_D6) == 0;
v5 = v4 - 1 + 2;
result = v4 + 2;
v6 = 8 * result;
if ( *(_QWORD *)(*(_QWORD *)a1 + 8 * result) )
{
if ( *(_QWORD *)(*(_QWORD *)a1 + v6 - 8) )
{
while ( 1 )
{
ft_dprintf((unsigned int)a1[3], &unk_D9);
++v5;
result = *(_QWORD *)a1;
if ( !*(_QWORD *)(*(_QWORD *)a1 + v6) )
break;
v6 += 8LL;
if ( !*(_QWORD *)(result + v6) )
goto LABEL_6;
}
}
}
else
{
LABEL_6:
result = *(_QWORD *)a1;
if ( *(_QWORD *)(*(_QWORD *)a1 + 8LL * v5) )
result = ft_dprintf((unsigned int)a1[3], &unk_DD);
}
if ( !v4 )
result = write(a1[3], &unk_E0, 1uLL);
}
return result;
}

variable_types: struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *

variable_types: i int

variable_types: n int


start

decompiled_code:
// positive sp value has been detected, the output may be wrong!
void __fastcall __noreturn start(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

original_code:
void start(void)
{
 char **av;
 t_env *env;
 t_term *term;
 term = recup_term();
 ft_init_signal();
 env = return_env();
 while (1)
 {
  clean_hist(term->hist);
  ft_init_prompte(av, env, 1);
 }
}

canonical_original_code:
void start()
{
 char **av;
 struct s_env *env;
 struct s_term *term;
 term = recup_term();
 ft_init_signal();
 env = return_env();
 while (1)
 {
  clean_hist(term->hist);
  ft_init_prompte(av, env, 1);
 }
}

variable_types:
av
char **

variable_types: struct s_env { char **path; char *ps1; int ps1_len; char *home; char pwd[4096]; char **environ; int pid; } *

variable_types: struct s_term { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } term; struct termios term_ori; int fd; int ps1_len; char **key; int quote; int dquote; int wait_fermeture; struct s_hist { char value[4096]; int pose_cursor; int len; int modif; char buff[4096]; int exec; struct s_hist *next; struct s_hist *prev; } *hist; } *

user_defined_types: struct s_term { struct termios term; struct termios term_ori; int fd; int ps1_len; char **key; int quote; int dquote; int wait_fermeture; struct s_hist *hist; }


user_defined_types: struct s_env { char **path; char *ps1; int ps1_len; char *home; char pwd[4096]; char **environ; int pid; }

user_defined_types: struct s_hist { char value[4096]; int pose_cursor; int len; int modif; char buff[4096]; int exec; struct s_hist *next; struct s_hist *prev; }


repo: kees-jan/physicalmemory

decompiled_code:
__int64 phys_init()
{
unsigned int v0; // ebx

v0 = 0;
if ( fd == -1 )
{
v0 = open("/dev/physicalmemory", 2);
fd = v0;
if ( v0 == -1 )
perror("Open device failed");
else
v0 = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // ebx

v0 = 0;
if ( fd == -1 )
{
v0 = open("/dev/physicalmemory", 2);
fd = v0;
if ( v0 == -1 )
perror("Open device failed");
else
v0 = 0;
}
return v0;
}

original_code:
int phys_init()
{
  if(fd==-1)
  {
    fd=open("/dev/physicalmemory", 02);
    if(fd==-1)
    {
      perror("Open device failed");
      return -1;
    }
  }
  return 0;
}


decompiled_code:
int __fastcall phys_allocate(_QWORD *a1, size_t a2)
{
int v2; // ebp
int result; // eax
char *v4; // rax
size_t len; // [rsp+0h] [rbp-38h] BYREF
__off_t offset; // [rsp+8h] [rbp-30h]
__int64 v7; // [rsp+10h] [rbp-28h]

init_block(a1);
offset = 0LL;
v7 = 4096LL;
len = a2;
v2 = fd;
result = ioctl(fd, 0x5001uLL, &len);
if ( result >= 0 )
{
v4 = (char *)mmap(0LL, len, 3, 1, v2, offset);
if ( (unsigned __int64)(v4 - 1) > 0xFFFFFFFFFFFFFFFDLL )
{
puts("physicalmemory: BUG: alloc succeeded, but mmap did not.");
result = -1;
}
else
{
*a1 = v4;
a1[1] = offset;
a1[2] = len;
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(_QWORD *a1, size_t a2)
{
int v2; // ebp
int result; // eax
char *v4; // rax
size_t len; // [rsp+0h] [rbp-38h] BYREF
__off_t offset; // [rsp+8h] [rbp-30h]
__int64 v7; // [rsp+10h] [rbp-28h]

func4(a1);
offset = 0LL;
v7 = 4096LL;
len = a2;
v2 = fd;
result = ioctl(fd, 0x5001uLL, &len);
if ( result >= 0 )
{
v4 = (char *)mmap(0LL, len, 3, 1, v2, offset);
if ( (unsigned __int64)(v4 - 1) > 0xFFFFFFFFFFFFFFFDLL )
{
puts("physicalmemory: BUG: alloc succeeded, but mmap did not.");
result = -1;
}
else
{
*a1 = v4;
a1[1] = offset;
a1[2] = len;
result = 0;
}
}
return result;
}

original_code:
int phys_allocate(struct physicalmemory_block* block, size_t size)
{
  init_block(block);
  struct MemoryBlock b = { .size = 0, .physicalAddress = 0, .alignment = 4096, };
  b.size = size;
  int result = ioctl(fd, (((0U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((1)) << 0) | ((0) << ((0 +8)+8))), &b);
  if(result>=0)
  {
    void* address=mmap(0, b.size, 0x1 | 0x2, 0x01, fd, b.physicalAddress);
    if(address!=((void *) -1) && address!=((void *)0))
    {
      block->buffer = address;
      block->physicalAddress = b.physicalAddress;
      block->size = b.size;
      return 0;
    }
    printf("physicalmemory: BUG: alloc succeeded, but mmap did not.\n");
    result = -1;
  }
  return result;
}

canonical_original_code:
int phys_allocate(struct physicalmemory_block *block, unsigned long size)
{
  init_block(block);
  struct MemoryBlock b = { .size = 0, .physicalAddress = 0, .alignment = 4096, };
  b.size = size;
  int result = ioctl(fd, (((0U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((1)) << 0) | ((0) << ((0 +8)+8))), &b);
  if(result>=0)
  {
    void *address = mmap(0, b.size, 0x1 | 0x2, 0x01, fd, b.physicalAddress);
    if(address!=((void *) -1) && address!=((void *)0))
    {
      block->buffer = address;
      block->physicalAddress = b.physicalAddress;
      block->size = b.size;
      return 0;
    }
    printf("physicalmemory: BUG: alloc succeeded, but mmap did not.\n");
    result = -1;
  }
  return result;
}

variable_types: struct physicalmemory_block { unsigned char *buffer; unsigned long physicalAddress; unsigned long size; } *

variable_types:
size
unsigned long

variable_types: struct MemoryBlock { unsigned long size; unsigned long physicalAddress; unsigned long alignment; }

variable_types: result int

variable_types:
address
void *


decompiled_code:
int __fastcall phys_allocate_aligned(_QWORD *a1, size_t a2, __int64 a3)
{
int v4; // ebp
int result; // eax
char *v6; // rax
size_t len; // [rsp+0h] [rbp-38h] BYREF
__off_t offset; // [rsp+8h] [rbp-30h]
__int64 v9; // [rsp+10h] [rbp-28h]

init_block(a1);
offset = 0LL;
len = a2;
v9 = a3;
v4 = fd;
result = ioctl(fd, 0x5001uLL, &len);
if ( result >= 0 )
{
v6 = (char *)mmap(0LL, len, 3, 1, v4, offset);
if ( (unsigned __int64)(v6 - 1) > 0xFFFFFFFFFFFFFFFDLL )
{
puts("physicalmemory: BUG: alloc succeeded, but mmap did not");
result = -1;
}
else
{
*a1 = v6;
a1[1] = offset;
a1[2] = len;
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(_QWORD *a1, size_t a2, __int64 a3)
{
int v4; // ebp
int result; // eax
char *v6; // rax
size_t len; // [rsp+0h] [rbp-38h] BYREF
__off_t offset; // [rsp+8h] [rbp-30h]
__int64 v9; // [rsp+10h] [rbp-28h]

func4(a1);
offset = 0LL;
len = a2;
v9 = a3;
v4 = fd;
result = ioctl(fd, 0x5001uLL, &len);
if ( result >= 0 )
{
v6 = (char *)mmap(0LL, len, 3, 1, v4, offset);
if ( (unsigned __int64)(v6 - 1) > 0xFFFFFFFFFFFFFFFDLL )
{
puts("physicalmemory: BUG: alloc succeeded, but mmap did not");
result = -1;
}
else
{
*a1 = v6;
a1[1] = offset;
a1[2] = len;
result = 0;
}
}
return result;
}

original_code:
int phys_allocate_aligned(struct physicalmemory_block* block, size_t size, size_t alignment)
{
  init_block(block);
  struct MemoryBlock b = { .size = 0, .physicalAddress = 0, .alignment = 4096, };
  b.size = size;
  b.alignment = alignment;
  int result = ioctl(fd, (((0U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((1)) << 0) | ((0) << ((0 +8)+8))), &b);
  if(result>=0)
  {
    void* address=mmap(0, b.size, 0x1 | 0x2, 0x01, fd, b.physicalAddress);
    if(address!=((void *) -1) && address!=((void *)0))
    {
      block->buffer = address;
      block->physicalAddress = b.physicalAddress;
      block->size = b.size;
      return 0;
    }
    printf("physicalmemory: BUG: alloc succeeded, but mmap did not\n");
    result = -1;
  }
  return result;
}

canonical_original_code:
int phys_allocate_aligned(struct physicalmemory_block *block, unsigned long size, unsigned long alignment)
{
  init_block(block);
  struct MemoryBlock b = { .size = 0, .physicalAddress = 0, .alignment = 4096, };
  b.size = size;
  b.alignment = alignment;
  int result = ioctl(fd, (((0U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((1)) << 0) | ((0) << ((0 +8)+8))), &b);
  if(result>=0)
  {
    void *address = mmap(0, b.size, 0x1 | 0x2, 0x01, fd, b.physicalAddress);
    if(address!=((void *) -1) && address!=((void *)0))
    {
      block->buffer = address;
      block->physicalAddress = b.physicalAddress;
      block->size = b.size;
      return 0;
    }
    printf("physicalmemory: BUG: alloc succeeded, but mmap did not\n");
    result = -1;
  }
  return result;
}

variable_types:
alignment
unsigned long

user_defined_types: struct MemoryBlock { unsigned long size; unsigned long physicalAddress; unsigned long alignment; }

user_defined_types: struct physicalmemory_block { unsigned char *buffer; unsigned long physicalAddress; unsigned long size; }


decompiled_code:
int __fastcall phys_free(__int64 a1)
{
int result; // eax
__int64 v2[5]; // [rsp+0h] [rbp-28h] BYREF

result = munmap(*(void **)a1, *(_QWORD *)(a1 + 16));
if ( result >= 0 )
{
v2[2] = 4096LL;
v2[0] = *(_QWORD *)(a1 + 16);
v2[1] = *(_QWORD *)(a1 + 8);
result = ioctl(fd, 0x5002uLL, v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
int result; // eax
__int64 v2[5]; // [rsp+0h] [rbp-28h] BYREF

result = munmap(*(void **)a1, *(_QWORD *)(a1 + 16));
if ( result >= 0 )
{
v2[2] = 4096LL;
v2[0] = *(_QWORD *)(a1 + 16);
v2[1] = *(_QWORD *)(a1 + 8);
result = ioctl(fd, 0x5002uLL, v2);
}
return result;
}

original_code:
int phys_free(struct physicalmemory_block* block)
{
  int result=munmap(block->buffer, block->size);
  if(result>=0)
  {
    struct MemoryBlock b = { .size = 0, .physicalAddress = 0, .alignment = 4096, };
    b.size = block->size;
    b.physicalAddress = block->physicalAddress;
    result = ioctl(fd, (((0U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((2)) << 0) | ((0) << ((0 +8)+8))), &b);
  }
  return result;
}

canonical_original_code:
int phys_free(struct physicalmemory_block *block)
{
  int result = munmap(block->buffer, block->size);
  if(result>=0)
  {
    struct MemoryBlock b = { .size = 0, .physicalAddress = 0, .alignment = 4096, };
    b.size = block->size;
    b.physicalAddress = block->physicalAddress;
    result = ioctl(fd, (((0U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((2)) << 0) | ((0) << ((0 +8)+8))), &b);
  }
  return result;
}


repo: keesj/saleae-logic-libusb

decompiled_code:
const char *__fastcall usbutil_transfer_status_to_string(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "Completed.";
break;
case 1:
result = "Error.";
break;
case 2:
result = "Timeout.";
break;
case 3:
result = "Cancelled.";
break;
case 4:
result = "Stalled.";
break;
case 5:
result = "No device.";
break;
case 6:
result = "Overflow.";
break;
default:
result = "libusb_transfer_status: Unkown.";
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "Completed.";
break;
case 1:
result = "Error.";
break;
case 2:
result = "Timeout.";
break;
case 3:
result = "Cancelled.";
break;
case 4:
result = "Stalled.";
break;
case 5:
result = "No device.";
break;
case 6:
result = "Overflow.";
break;
default:
result = "libusb_transfer_status: Unkown.";
break;
}
return result;
}

original_code:
const char *usbutil_transfer_status_to_string(enum libusb_transfer_status transfer_status)
{
 switch (transfer_status) {
 case LIBUSB_TRANSFER_COMPLETED:
  return "Completed.";
 case LIBUSB_TRANSFER_ERROR:
  return "Error.";
 case LIBUSB_TRANSFER_TIMED_OUT:
  return "Timeout.";
 case LIBUSB_TRANSFER_CANCELLED:
  return "Cancelled.";
 case LIBUSB_TRANSFER_STALL:
  return "Stalled.";
 case LIBUSB_TRANSFER_NO_DEVICE:
  return "No device.";
 case LIBUSB_TRANSFER_OVERFLOW:
  return "Overflow.";
 default:
  return "libusb_transfer_status: Unkown.";
 }
}

variable_types: enum libusb_transfer_status { LIBUSB_TRANSFER_COMPLETED=0, LIBUSB_TRANSFER_ERROR=1, LIBUSB_TRANSFER_TIMED_OUT=2, LIBUSB_TRANSFER_CANCELLED=3, LIBUSB_TRANSFER_STALL=4, LIBUSB_TRANSFER_NO_DEVICE=5, LIBUSB_TRANSFER_OVERFLOW=6 }

return_type: char *


decompiled_code:
const char *__fastcall usbutil_error_to_string(int a1)
{
const char *result; // rax

switch ( a1 )
{
case -99:
result = "LIBUSB_ERROR_OTHER";
break;
case -12:
result = "LIBUSB_ERROR_NOT_SUPPORTED";
break;
case -11:
result = "LIBUSB_ERROR_NO_MEM";
break;
case -10:
result = "LIBUSB_ERROR_INTERRUPTED";
break;
case -9:
result = "LIBUSB_ERROR_PIPE";
break;
case -8:
result = "LIBUSB_ERROR_OVERFLOW";
break;
case -7:
result = "LIBUSB_ERROR_TIMEOUT";
break;
case -6:
result = "LIBUSB_ERROR_BUSY";
break;
case -5:
result = "LIBUSB_ERROR_NOT_FOUND";
break;
case -4:
result = "LIBUSB_ERROR_NO_DEVICE";
break;
case -3:
result = "LIBUSB_ERROR_ACCESS";
break;
case -2:
result = "LIBUSB_ERROR_INVALID_PARAM";
break;
case -1:
result = "LIBUSB_ERROR_IO";
break;
case 0:
result = "LIBUSB_SUCCESS";
break;
default:
result = "libusb_error: Unknown error";
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func5(int a1)
{
const char *result; // rax

switch ( a1 )
{
case -99:
result = "LIBUSB_ERROR_OTHER";
break;
case -12:
result = "LIBUSB_ERROR_NOT_SUPPORTED";
break;
case -11:
result = "LIBUSB_ERROR_NO_MEM";
break;
case -10:
result = "LIBUSB_ERROR_INTERRUPTED";
break;
case -9:
result = "LIBUSB_ERROR_PIPE";
break;
case -8:
result = "LIBUSB_ERROR_OVERFLOW";
break;
case -7:
result = "LIBUSB_ERROR_TIMEOUT";
break;
case -6:
result = "LIBUSB_ERROR_BUSY";
break;
case -5:
result = "LIBUSB_ERROR_NOT_FOUND";
break;
case -4:
result = "LIBUSB_ERROR_NO_DEVICE";
break;
case -3:
result = "LIBUSB_ERROR_ACCESS";
break;
case -2:
result = "LIBUSB_ERROR_INVALID_PARAM";
break;
case -1:
result = "LIBUSB_ERROR_IO";
break;
case 0:
result = "LIBUSB_SUCCESS";
break;
default:
result = "libusb_error: Unknown error";
break;
}
return result;
}

original_code:
const char *usbutil_error_to_string(enum libusb_error error)
{
 switch (error) {
 case LIBUSB_SUCCESS:
  return "LIBUSB_SUCCESS";
 case LIBUSB_ERROR_IO:
  return "LIBUSB_ERROR_IO";
 case LIBUSB_ERROR_INVALID_PARAM:
  return "LIBUSB_ERROR_INVALID_PARAM";
 case LIBUSB_ERROR_ACCESS:
  return "LIBUSB_ERROR_ACCESS";
 case LIBUSB_ERROR_NO_DEVICE:
  return "LIBUSB_ERROR_NO_DEVICE";
 case LIBUSB_ERROR_NOT_FOUND:
  return "LIBUSB_ERROR_NOT_FOUND";
 case LIBUSB_ERROR_BUSY:
  return "LIBUSB_ERROR_BUSY";
 case LIBUSB_ERROR_TIMEOUT:
  return "LIBUSB_ERROR_TIMEOUT";
 case LIBUSB_ERROR_OVERFLOW:
  return "LIBUSB_ERROR_OVERFLOW";
 case LIBUSB_ERROR_PIPE:
  return "LIBUSB_ERROR_PIPE";
 case LIBUSB_ERROR_INTERRUPTED:
  return "LIBUSB_ERROR_INTERRUPTED";
 case LIBUSB_ERROR_NO_MEM:
  return "LIBUSB_ERROR_NO_MEM";
 case LIBUSB_ERROR_NOT_SUPPORTED:
  return "LIBUSB_ERROR_NOT_SUPPORTED";
 case LIBUSB_ERROR_OTHER:
  return "LIBUSB_ERROR_OTHER";
 default:
  return "libusb_error: Unknown error";
 }
}

variable_types: enum libusb_error { LIBUSB_SUCCESS=0, LIBUSB_ERROR_IO=-1, LIBUSB_ERROR_INVALID_PARAM=-2, LIBUSB_ERROR_ACCESS=-3, LIBUSB_ERROR_NO_DEVICE=-4, LIBUSB_ERROR_NOT_FOUND=-5, LIBUSB_ERROR_BUSY=-6, LIBUSB_ERROR_TIMEOUT=-7, LIBUSB_ERROR_OVERFLOW=-8, LIBUSB_ERROR_PIPE=-9, LIBUSB_ERROR_INTERRUPTED=-10, LIBUSB_ERROR_NO_MEM=-11, LIBUSB_ERROR_NOT_SUPPORTED=-12, LIBUSB_ERROR_OTHER=-99 }