decompiled_code:
__int64 __fastcall ft_save_line(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v4; // [rsp+8h] [rbp-50h] BYREF
__int64 v5; // [rsp+18h] [rbp-40h] BYREF
int v6[4]; // [rsp+20h] [rbp-38h] BYREF
__int64 v7; // [rsp+30h] [rbp-28h]
char buf[31]; // [rsp+39h] [rbp-1Fh] BYREF

v4 = a3;
v5 = 0LL;
v7 = 0LL;
v6[0] = 0;
v6[1] = 0;
ft_putstr("_$> ");
while ( v6[0] != -1 )
{
ft_bzero(buf, 7LL);
if ( read(0, buf, 6uLL) == -1 )
return 0xFFFFFFFFLL;
if ( (unsigned int)ft_is_key_ctrl_d(buf) )
return 4294967294LL;
if ( (unsigned int)ft_check_key(buf, &v5, v6, (__int64)&v4) )
return 0xFFFFFFFFLL;
}
v6[0] = ft_slist_len(v5);
ft_print(v5, v6, (unsigned int)((v6[0] + 4) / v6[2]));
result = ft_put_in_hist(a1, v5);
if ( (_DWORD)result != -1 )
result = (unsigned int)-((unsigned int)ft_do_line(a2, v5) == -1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v4; // [rsp+8h] [rbp-50h] BYREF
__int64 v5; // [rsp+18h] [rbp-40h] BYREF
int v6[4]; // [rsp+20h] [rbp-38h] BYREF
__int64 v7; // [rsp+30h] [rbp-28h]
char buf[31]; // [rsp+39h] [rbp-1Fh] BYREF

v4 = a3;
v5 = 0LL;
v7 = 0LL;
v6[0] = 0;
v6[1] = 0;
ft_putstr("_$> ");
while ( v6[0] != -1 )
{
ft_bzero(buf, 7LL);
if ( read(0, buf, 6uLL) == -1 )
return 0xFFFFFFFFLL;
if ( (unsigned int)ft_is_key_ctrl_d(buf) )
return 4294967294LL;
if ( (unsigned int)func2(buf, &v5, v6, (__int64)&v4) )
return 0xFFFFFFFFLL;
}
v6[0] = ft_slist_len(v5);
ft_print(v5, v6, (unsigned int)((v6[0] + 4) / v6[2]));
result = ft_put_in_hist(a1, v5);
if ( (_DWORD)result != -1 )
result = (unsigned int)-((unsigned int)ft_do_line(a2, v5) == -1);
return result;
}

original_code:
int ft_save_line(t_hl **hlist, char **line, t_hl *move)
{
 char buf[6 + 1];
 t_save save;
 t_sl *list;
 list = ((void *)0);
 save.copy = ((void *)0);
 save.cursor_l = 0;
 save.cursor_hl = 0;
 ft_putstr("_$> ");
 while (save.cursor_l != -1)
 {
  ft_bzero(buf, 6 + 1);
  if (read(0, buf, 6) == -1)
   return (-1);
  if (ft_is_key_ctrl_d(buf))
   return (-2);
  if (ft_check_key(buf, &list, &save, &move))
   return (-1);
 }
 save.cursor_l = ft_slist_len(list);
 ft_print(list, &save, (4 + save.cursor_l) / save.co);
 if ((ft_put_in_hist(hlist, list) == -1) || (ft_do_line(line, list)) == -1)
  return (-1);
 return (0);
}

canonical_original_code:
int ft_save_line(struct s_hl **hlist, char **line, struct s_hl *move)
{
 char buf[-1];
 struct s_save save;
 struct s_sl *list;
 list = ((void *)0);
 save.copy = ((void *)0);
 save.cursor_l = 0;
 save.cursor_hl = 0;
 ft_putstr("_$> ");
 while (save.cursor_l != -1)
 {
  ft_bzero(buf, 6 + 1);
  if (read(0, buf, 6) == -1)
   return (-1);
  if (ft_is_key_ctrl_d(buf))
   return (-2);
  if (ft_check_key(buf, &list, &save, &move))
   return (-1);
 }
 save.cursor_l = ft_slist_len(list);
 ft_print(list, &save, (4 + save.cursor_l) / save.co);
 if ((ft_put_in_hist(hlist, list) == -1) || (ft_do_line(line, list)) == -1)
  return (-1);
 return (0);
}

variable_types: struct s_hl { struct s_sl { char c; struct s_sl *next; struct s_sl *prev; } *hist; struct s_hl *next; struct s_hl *prev; } **

variable_types:
line
char **

variable_types:
move
struct s_hl *

variable_types:
buf
char [-1]

variable_types: struct s_save { int cursor_l; int cursor_hl; int co; struct s_sl { char c; struct s_sl *next; struct s_sl *prev; } *copy; }


decompiled_code:
void __fastcall ft_init_vect(double *a1, double a2, double a3, double a4)
{
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
}

canonical_decompiled_code:
void __fastcall func0(double *a1, double a2, double a3, double a4)
{
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
}

original_code:
void ft_init_vect(t_v *vect, double x, double y, double z)
{
 vect->x = x;
 vect->y = y;
 vect->z = z;
}

canonical_original_code:
void ft_init_vect(struct s_v *vect, double x, double y, double z)
{
 vect->x = x;
 vect->y = y;
 vect->z = z;
}

variable_types: struct s_v { double x; double y; double z; } *

variable_types: x double

variable_types: y double

variable_types: z double

return_type: void


original_code:
void ft_vect_opposite(t_v *vect, t_v v1)
{
 vect->x = -v1.x;
 vect->y = -v1.y;
 vect->z = -v1.z;
}

canonical_original_code:
void ft_vect_opposite(struct s_v *vect, struct s_v v1)
{
 vect->x = -v1.x;
 vect->y = -v1.y;
 vect->z = -v1.z;
}

user_defined_types: struct s_v { double x; double y; double z; }


decompiled_code:
void __fastcall ft_vect_sum(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, double a15)
{
*a1 = a10 + a13;
a1[1] = a11 + a14;
a1[2] = a12 + a15;
}

canonical_decompiled_code:
void __fastcall func2(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, double a15)
{
*a1 = a10 + a13;
a1[1] = a11 + a14;
a1[2] = a12 + a15;
}

original_code:
void ft_vect_sum(t_v *vect, t_v v1, t_v v2)
{
 vect->x = v1.x + v2.x;
 vect->y = v1.y + v2.y;
 vect->z = v1.z + v2.z;
}

canonical_original_code:
void ft_vect_sum(struct s_v *vect, struct s_v v1, struct s_v v2)
{
 vect->x = v1.x + v2.x;
 vect->y = v1.y + v2.y;
 vect->z = v1.z + v2.z;
}


decompiled_code:
void __fastcall ft_mult_vect_by_nb(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
*a1 = a2 * a10;
a1[1] = a2 * a11;
a1[2] = a2 * a12;
}

canonical_decompiled_code:
void __fastcall func3(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
*a1 = a2 * a10;
a1[1] = a2 * a11;
a1[2] = a2 * a12;
}

original_code:
void ft_mult_vect_by_nb(t_v *vect, t_v v1, double scalar)
{
 vect->x = v1.x * scalar;
 vect->y = v1.y * scalar;
 vect->z = v1.z * scalar;
}

canonical_original_code:
void ft_mult_vect_by_nb(struct s_v *vect, struct s_v v1, double scalar)
{
 vect->x = v1.x * scalar;
 vect->y = v1.y * scalar;
 vect->z = v1.z * scalar;
}

variable_types: scalar double


decompiled_code:
const char *__fastcall ft_command_exist(__int64 a1, _QWORD *a2)
{
const char **v2; // r13
const char **v3; // rbp
struct stat *v4; // r12
const char *i; // rbx
__int64 v6; // rax
__int64 v7; // rax

v2 = (const char **)ft_strsplit(a1, 32LL);
v3 = (const char **)ft_find_paths_in_env(a2);
v4 = (struct stat *)malloc(0x90uLL);
if ( !v4 )
return 0LL;
for ( i = *v3; *v3; i = *v3 )
{
v6 = ft_strlen(i);
i = (const char *)malloc(v6 + 1);
if ( !i )
break;
v7 = ft_strjoin(*v3, "/");
i = (const char *)ft_strjoin(v7, *v2);
if ( !lstat(i, v4) )
break;
if ( !lstat(*v2, v4) )
return *v2;
++v3;
}
return i;
}

canonical_decompiled_code:
const char *__fastcall func2(__int64 a1, _QWORD *a2)
{
const char **v2; // r13
const char **v3; // rbp
struct stat *v4; // r12
const char *i; // rbx
__int64 v6; // rax
__int64 v7; // rax

v2 = (const char **)ft_strsplit(a1, 32LL);
v3 = (const char **)func1(a2);
v4 = (struct stat *)malloc(0x90uLL);
if ( !v4 )
return 0LL;
for ( i = *v3; *v3; i = *v3 )
{
v6 = ft_strlen(i);
i = (const char *)malloc(v6 + 1);
if ( !i )
break;
v7 = ft_strjoin(*v3, "/");
i = (const char *)ft_strjoin(v7, *v2);
if ( !lstat(i, v4) )
break;
if ( !lstat(*v2, v4) )
return *v2;
++v3;
}
return i;
}

original_code:
static char *ft_command_exist(char *com, char **env)
{
 int i;
 char *str;
 char **all_paths;
 char **command;
 struct stat *buf;
 command = ft_strsplit(com, ' ');
 all_paths = ft_find_paths_in_env(env);
 i = 0;
 if (!(buf = (struct stat *)malloc(sizeof(*buf))))
  return (((void *)0));
 while (all_paths[i])
 {
  if (!(str = (char *)malloc(sizeof(*str) * ft_strlen(all_paths[i]) + 1)))
   return (((void *)0));
  str = ft_strjoin(all_paths[i], "/");
  str = ft_strjoin(str, command[0]);
  if (lstat(str, buf) == 0)
   return (str);
  else if (lstat(command[0], buf) == 0)
   return (command[0]);
  i++;
 }
 return (((void *)0));
}

variable_types:
com
char *

variable_types:
env
char **

variable_types: i int

variable_types:
str
char *

variable_types:
command
char **

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

return_type: char *

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


decompiled_code:
__int64 __fastcall ft_init_struct(__int64 a1, _QWORD *a2, __int64 a3, int *a4)
{
__int64 v6; // rax
void *v7; // rax
int v8; // eax
__int64 result; // rax

*(_QWORD *)a3 = ft_file_exist(*(char **)(a1 + 8));
v6 = ft_strlen(*(_QWORD *)(a1 + 32));
v7 = malloc(8 * v6 + 1);
*(_QWORD *)(a3 + 16) = v7;
if ( v7 )
{
ft_strcpy(v7, *(_QWORD *)(a1 + 32));
*(_QWORD *)(a3 + 8) = ft_command_exist(*(_QWORD *)(a1 + 16), a2);
*(_QWORD *)(a3 + 24) = ft_command_exist(*(_QWORD *)(a1 + 24), a2);
*a4 = open(*(const char **)a3, 0);
v8 = open(*(const char **)(a3 + 16), 578, 448LL);
a4[1] = v8;
if ( *a4 == -1 || v8 == -1 || !*(_QWORD *)a3 || !*(_QWORD *)(a3 + 8) || (result = 1LL, !*(_QWORD *)(a3 + 24)) )
{
ft_putendl("Error");
result = 0xFFFFFFFFLL;
}
}
else
{
ft_putendl("Error");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int ft_init_struct(char **av, char **env, t_pipex *pipex, t_fd *fd)
{
 pipex->file1 = ft_file_exist(av[1]);
 if (!(pipex->file2 = (char *)malloc(sizeof(char *) * ft_strlen(av[4]) + 1)))
 {
  ft_putendl("Error");
  return (-1);
 }
 ft_strcpy(pipex->file2, av[4]);
 pipex->cmd1 = ft_command_exist(av[2], env);
 pipex->cmd2 = ft_command_exist(av[3], env);
 fd->fd1 = open(pipex->file1, 00);
 fd->fd2 = open(pipex->file2, 02 | 0100 | 01000, 0400
     | 0200 | 0100);
 if (fd->fd1 == -1 || fd->fd2 == -1 || !pipex->file1
  || !pipex->cmd1 || !pipex->cmd2)
 {
  ft_putendl("Error");
  return (-1);
 }
 return (1);
}

canonical_original_code:
int ft_init_struct(char **av, char **env, struct s_pipex *pipex, struct s_fd *fd)
{
 pipex->file1 = ft_file_exist(av[1]);
 if (!(pipex->file2 = (char *)malloc(sizeof(char *) * ft_strlen(av[4]) + 1)))
 {
  ft_putendl("Error");
  return (-1);
 }
 ft_strcpy(pipex->file2, av[4]);
 pipex->cmd1 = ft_command_exist(av[2], env);
 pipex->cmd2 = ft_command_exist(av[3], env);
 fd->fd1 = open(pipex->file1, 00);
 fd->fd2 = open(pipex->file2, 02 | 0100 | 01000, 0400
     | 0200 | 0100);
 if (fd->fd1 == -1 || fd->fd2 == -1 || !pipex->file1
  || !pipex->cmd1 || !pipex->cmd2)
 {
  ft_putendl("Error");
  return (-1);
 }
 return (1);
}

variable_types:
av
char **

variable_types: struct s_pipex { char *file1; char *cmd1; char *file2; char *cmd2; } *

variable_types: struct s_fd { int fd1; int fd2; int fd_tmp; } *

return_type: int


decompiled_code:
__int64 __fastcall ft_find_paths_in_env(_QWORD *a1)
{
__int64 v1; // rbp
_QWORD *v2; // rbx
__int64 v3; // rdi

v2 = a1;
v3 = *a1;
if ( v3 )
{
do
{
if ( !(unsigned int)ft_strncmp(v3, "PATH=", 5LL) )
v1 = ft_strsplit(*v2 + 5LL, 58LL);
v3 = *++v2;
}
while ( *v2 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 v1; // rbp
_QWORD *v2; // rbx
__int64 v3; // rdi

v2 = a1;
v3 = *a1;
if ( v3 )
{
do
{
if ( !(unsigned int)ft_strncmp(v3, "PATH=", 5LL) )
v1 = ft_strsplit(*v2 + 5LL, 58LL);
v3 = *++v2;
}
while ( *v2 );
}
return v1;
}

original_code:
static char **ft_find_paths_in_env(char **env)
{
 int i;
 char **all_paths;
 i = 0;
 while (env[i])
 {
  if (ft_strncmp(env[i], "PATH=", 5) == 0)
   all_paths = ft_strsplit(&env[i][5], ':');
  i++;
 }
 return (all_paths);
}

return_type: char **


decompiled_code:
__int64 __fastcall ft_intersect_a_box(double *a1, double *a2)
{
double v2; // xmm2_8
double v3; // xmm1_8
double v5; // [rsp+0h] [rbp-30h] BYREF
double v6; // [rsp+8h] [rbp-28h] BYREF
double v7; // [rsp+10h] [rbp-20h] BYREF
double v8[3]; // [rsp+18h] [rbp-18h] BYREF

ft_find_x_box(a1, a2, (__int64 *)v8, (__int64 *)&v7);
ft_find_y_box((__int64)a1, (__int64)a2, (__int64 *)&v6, (__int64 *)&v5);
if ( v6 > v7 )
return 0xFFFFFFFFLL;
if ( v8[0] > v5 )
return 0xFFFFFFFFLL;
v8[0] = fmax(v6, v8[0]);
v7 = fmin(v5, v7);
ft_find_z_box((__int64)a1, (__int64)a2, (__int64 *)&v6, (__int64 *)&v5);
v2 = v7;
if ( v6 > v7 )
return 0xFFFFFFFFLL;
v3 = v5;
if ( v8[0] > v5 )
return 0xFFFFFFFFLL;
a1[12] = fmax(v6, v8[0]);
a1[13] = fmin(v3, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(double *a1, double *a2)
{
double v2; // xmm2_8
double v3; // xmm1_8
double v5; // [rsp+0h] [rbp-30h] BYREF
double v6; // [rsp+8h] [rbp-28h] BYREF
double v7; // [rsp+10h] [rbp-20h] BYREF
double v8[3]; // [rsp+18h] [rbp-18h] BYREF

func1(a1, a2, (__int64 *)v8, (__int64 *)&v7);
func2((__int64)a1, (__int64)a2, (__int64 *)&v6, (__int64 *)&v5);
if ( v6 > v7 )
return 0xFFFFFFFFLL;
if ( v8[0] > v5 )
return 0xFFFFFFFFLL;
v8[0] = fmax(v6, v8[0]);
v7 = fmin(v5, v7);
func3((__int64)a1, (__int64)a2, (__int64 *)&v6, (__int64 *)&v5);
v2 = v7;
if ( v6 > v7 )
return 0xFFFFFFFFLL;
v3 = v5;
if ( v8[0] > v5 )
return 0xFFFFFFFFLL;
a1[12] = fmax(v6, v8[0]);
a1[13] = fmin(v3, v2);
return 0LL;
}

original_code:
int ft_intersect_a_box(t_r *r, void *data)
{
 double tmin;
 double tmax;
 double tmp1;
 double tmp2;
 t_box *box;
 box = (t_box *)data;
 ft_find_x_box(r, box, &tmin, &tmax);
 ft_find_y_box(r, box, &tmp1, &tmp2);
 if (tmp1 > tmax || tmin > tmp2)
  return (-1);
 tmin = (tmp1 > tmin) ? tmp1 : tmin;
 tmax = (tmp2 < tmax) ? tmp2 : tmax;
 ft_find_z_box(r, box, &tmp1, &tmp2);
 if (tmp1 > tmax || tmin > tmp2)
  return (-1);
 tmin = (tmp1 > tmin) ? tmp1 : tmin;
 tmax = (tmp2 < tmax) ? tmp2 : tmax;
 r->t0 = tmin;
 r->t1 = tmax;
 return (0);
}

canonical_original_code:
int ft_intersect_a_box(struct s_r *r, void *data)
{
 double tmin;
 double tmax;
 double tmp1;
 double tmp2;
 struct s_box *box;
 box = (struct s_box *)data;
 ft_find_x_box(r, box, &tmin, &tmax);
 ft_find_y_box(r, box, &tmp1, &tmp2);
 if (tmp1 > tmax || tmin > tmp2)
  return (-1);
 tmin = (tmp1 > tmin) ? tmp1 : tmin;
 tmax = (tmp2 < tmax) ? tmp2 : tmax;
 ft_find_z_box(r, box, &tmp1, &tmp2);
 if (tmp1 > tmax || tmin > tmp2)
  return (-1);
 tmin = (tmp1 > tmin) ? tmp1 : tmin;
 tmax = (tmp2 < tmax) ? tmp2 : tmax;
 r->t0 = tmin;
 r->t1 = tmax;
 return (0);
}

variable_types: struct s_r { struct s_v { double x; double y; double z; } o_w; struct s_v d_w; struct s_v p_hit; struct s_v n_hit; double t0; double t1; double tnear; struct s_c { int b; int g; int r; } color; int hit_i; int hit_j; } *

variable_types:
data
void *

variable_types: tmin double

variable_types: tmax double

variable_types: struct s_box { double xmin; double xmax; double ymin; double ymax; double zmin; double zmax; struct s_c { int b; int g; int r; } sf; } *

user_defined_types: struct s_r { struct s_v o_w; struct s_v d_w; struct s_v p_hit; struct s_v n_hit; double t0; double t1; double tnear; struct s_c color; int hit_i; int hit_j; }

user_defined_types: struct s_box { double xmin; double xmax; double ymin; double ymax; double zmin; double zmax; struct s_c sf; }


original_code:
int ft_draw(t_mlx *mlx)
{
 int i;
 int j;
 j = 0;
 while (j < (1200.0))
 {
  i = 0;
  while (i < (2400.0))
  {
   mlx->i.data[0 + i * 4 + j * mlx->i.sl] = (mlx->obj.pixel[j][i]).b;
   mlx->i.data[1 + i * 4 + j * mlx->i.sl] = (mlx->obj.pixel[j][i]).g;
   mlx->i.data[2 + i * 4 + j * mlx->i.sl] = (mlx->obj.pixel[j][i]).r;
   ++i;
  }
  ++j;
 }
 return (0);
}

canonical_original_code:
int ft_draw(struct s_mlx *mlx)
{
 int i;
 int j;
 j = 0;
 while (j < (1200.0))
 {
  i = 0;
  while (i < (2400.0))
  {
   mlx->i.data[0 + i * 4 + j * mlx->i.sl] = (mlx->obj.pixel[j][i]).b;
   mlx->i.data[1 + i * 4 + j * mlx->i.sl] = (mlx->obj.pixel[j][i]).g;
   mlx->i.data[2 + i * 4 + j * mlx->i.sl] = (mlx->obj.pixel[j][i]).r;
   ++i;
  }
  ++j;
 }
 return (0);
}

variable_types: struct s_mlx { void *mlx; void *win; void *img; struct s_img { char *data; int bpp; int sl; int endian; } i; struct s_obj { int depth; struct s_c { int b; int g; int r; } **pixel; void ***type; int *nb; int (*intersect[6])(struct s_r { struct s_v { double x; double y; double z; } o_w; struct s_v d_w; struct s_v p_hit; struct s_v n_hit; double t0; double t1; double tnear; struct s_c color; int hit_i; int hit_j; } *, void *); int (*treatment[6])(void *, struct s_c *, struct s_obj *, struct s_r *r); struct s_c bg_clr; } obj; } *

variable_types: j int

user_defined_types: struct s_mlx { void *mlx; void *win; void *img; struct s_img i; struct s_obj obj; }

user_defined_types: struct s_obj { int depth; struct s_c **pixel; void ***type; int *nb; int (*intersect[6])(struct s_r *, void *); int (*treatment[6])(void *, struct s_c *, struct s_obj *, struct s_r *r); struct s_c bg_clr; }


decompiled_code:
__int64 __fastcall ft_putbase(unsigned int a1, __int64 a2)
{
unsigned __int64 v2; // rcx
unsigned __int64 v3; // r12
__int64 v4; // rbx

v2 = ft_strlen(a2);
if ( a1 <= v2 )
return ft_putchar((unsigned int)*(char *)(a2 + a1 % v2));
v3 = a1 % v2;
v4 = ft_putbase((unsigned int)(a1 / v2), a2);
ft_putchar((unsigned int)*(char *)(a2 + v3));
return v4 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
unsigned __int64 v2; // rcx
unsigned __int64 v3; // r12
__int64 v4; // rbx

v2 = ft_strlen(a2);
if ( a1 <= v2 )
return ft_putchar((unsigned int)*(char *)(a2 + a1 % v2));
v3 = a1 % v2;
v4 = func0((unsigned int)(a1 / v2), a2);
ft_putchar((unsigned int)*(char *)(a2 + v3));
return v4 + 1;
}

original_code:
ssize_t ft_putbase(unsigned int n, char *base)
{
 ssize_t i;
 size_t len;
 i = 0;
 len = ft_strlen(base);
 if (n <= len)
 {
  i += ft_putchar(*(base + n % len));
  return (i);
 }
 else
 {
  i += ft_putbase(n / len, base);
  ft_putchar(*(base + n % len));
 }
 return (i + 1);
}

canonical_original_code:
long ft_putbase(unsigned int n, char *base)
{
 long i;
 unsigned long len;
 i = 0;
 len = ft_strlen(base);
 if (n <= len)
 {
  i += ft_putchar(*(base + n % len));
  return (i);
 }
 else
 {
  i += ft_putbase(n / len, base);
  ft_putchar(*(base + n % len));
 }
 return (i + 1);
}

variable_types:
n
unsigned int

variable_types:
base
char *

variable_types: i long

variable_types:
len
unsigned long

return_type: long


decompiled_code:
__int64 __fastcall ft_check_if_type_to_split(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // ecx
int v4; // edx

result = a1;
if ( a1 )
{
v3 = 0;
do
{
v4 = *(_DWORD *)(result + 8);
if ( v4 == 15 )
{
++v3;
}
else if ( v4 == 16 )
{
--v3;
}
else if ( v4 == a2 && !v3 )
{
return result;
}
result = *(_QWORD *)(result + 16);
}
while ( result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // ecx
int v4; // edx

result = a1;
if ( a1 )
{
v3 = 0;
do
{
v4 = *(_DWORD *)(result + 8);
if ( v4 == 15 )
{
++v3;
}
else if ( v4 == 16 )
{
--v3;
}
else if ( v4 == a2 && !v3 )
{
return result;
}
result = *(_QWORD *)(result + 16);
}
while ( result );
}
return result;
}

original_code:
static t_p *ft_check_if_type_to_split(t_p *p, int type)
{
 t_p *move;
 int ind_pth;
 move = p;
 ind_pth = 0;
 while (move)
 {
  if (move->type == 15)
   ++ind_pth;
  else if (move->type == 16)
   --ind_pth;
  else if (ind_pth == 0 && move->type == type)
   return (move);
  move = move->next;
 }
 return (move);
}

canonical_original_code:
static struct s_p *ft_check_if_type_to_split(struct s_p *p, int type)
{
 struct s_p *move;
 int ind_pth;
 move = p;
 ind_pth = 0;
 while (move)
 {
  if (move->type == 15)
   ++ind_pth;
  else if (move->type == 16)
   --ind_pth;
  else if (ind_pth == 0 && move->type == type)
   return (move);
  move = move->next;
 }
 return (move);
}

variable_types:
p
struct s_p *

variable_types: type int

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


decompiled_code:
__int64 __fastcall ft_find_priority_between_or_and_and(__int64 *a1)
{
__int64 result; // rax
int v2; // ecx
int v3; // edx

result = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v3 = *(_DWORD *)(result + 8);
if ( v3 == 15 )
{
++v2;
}
else if ( v3 == 16 )
{
--v2;
}
else if ( !v2 && (unsigned int)(v3 - 5) <= 1 )
{
return result;
}
result = *(_QWORD *)(result + 16);
*a1 = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1)
{
__int64 result; // rax
int v2; // ecx
int v3; // edx

result = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v3 = *(_DWORD *)(result + 8);
if ( v3 == 15 )
{
++v2;
}
else if ( v3 == 16 )
{
--v2;
}
else if ( !v2 && (unsigned int)(v3 - 5) <= 1 )
{
return result;
}
result = *(_QWORD *)(result + 16);
*a1 = result;
}
while ( result );
}
return result;
}

original_code:
static void ft_find_priority_between_or_and_and(t_p **keep)
{
 int ind_pth;
 ind_pth = 0;
 while (*keep)
 {
  if ((*keep)->type == 15)
   ++ind_pth;
  else if ((*keep)->type == 16)
   --ind_pth;
  else if (ind_pth == 0
    && ((*keep)->type == 5 || (*keep)->type == 6))
   break ;
  *keep = (*keep)->next;
 }
}

canonical_original_code:
static void ft_find_priority_between_or_and_and(struct s_p **keep)
{
 int ind_pth;
 ind_pth = 0;
 while (*keep)
 {
  if ((*keep)->type == 15)
   ++ind_pth;
  else if ((*keep)->type == 16)
   --ind_pth;
  else if (ind_pth == 0
    && ((*keep)->type == 5 || (*keep)->type == 6))
   break ;
  *keep = (*keep)->next;
 }
}

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


decompiled_code:
__int64 __fastcall ft_find_priority_between_all_the_redir(__int64 *a1)
{
__int64 result; // rax
int v2; // ecx
int v3; // edx

result = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v3 = *(_DWORD *)(result + 8);
if ( v3 == 15 )
{
++v2;
}
else if ( v3 == 16 )
{
--v2;
}
else if ( !v2 && (unsigned int)(v3 - 8) <= 2 )
{
return result;
}
result = *(_QWORD *)(result + 16);
*a1 = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1)
{
__int64 result; // rax
int v2; // ecx
int v3; // edx

result = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v3 = *(_DWORD *)(result + 8);
if ( v3 == 15 )
{
++v2;
}
else if ( v3 == 16 )
{
--v2;
}
else if ( !v2 && (unsigned int)(v3 - 8) <= 2 )
{
return result;
}
result = *(_QWORD *)(result + 16);
*a1 = result;
}
while ( result );
}
return result;
}

original_code:
static void ft_find_priority_between_all_the_redir(t_p **keep)
{
 int ind_pth;
 ind_pth = 0;
 while (*keep)
 {
  if ((*keep)->type == 15)
   ++ind_pth;
  else if ((*keep)->type == 16)
   --ind_pth;
  else if (ind_pth == 0 && ((*keep)->type == 8
         || (*keep)->type == 9
         || (*keep)->type == 10))
   break ;
  *keep = (*keep)->next;
 }
}

canonical_original_code:
static void ft_find_priority_between_all_the_redir(struct s_p **keep)
{
 int ind_pth;
 ind_pth = 0;
 while (*keep)
 {
  if ((*keep)->type == 15)
   ++ind_pth;
  else if ((*keep)->type == 16)
   --ind_pth;
  else if (ind_pth == 0 && ((*keep)->type == 8
         || (*keep)->type == 9
         || (*keep)->type == 10))
   break ;
  *keep = (*keep)->next;
 }
}

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


decompiled_code:
__int64 __fastcall ft_find_priority_operand(__int64 *a1, int *a2)
{
__int64 v2; // r12
__int64 result; // rax
int v4; // edx

v2 = *a1;
result = ft_check_if_type_to_split(*a1, 4);
if ( result
|| (result = ft_check_if_type_to_split(v2, 6)) != 0
|| (result = ft_check_if_type_to_split(v2, 5)) != 0
|| (result = ft_check_if_type_to_split(v2, 7)) != 0
|| (result = ft_check_if_type_to_split(v2, 8)) != 0
|| (result = ft_check_if_type_to_split(v2, 9)) != 0
|| (result = ft_check_if_type_to_split(v2, 10)) != 0 )
{
*a2 = *(_DWORD *)(result + 8);
}
v4 = *a2;
if ( *a2 == 6 )
return ft_find_priority_between_or_and_and(a1);
if ( (unsigned int)(v4 - 8) <= 1 )
return ft_find_priority_between_all_the_redir(a1);
if ( v4 )
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, int *a2)
{
__int64 v2; // r12
__int64 result; // rax
int v4; // edx

v2 = *a1;
result = func0(*a1, 4);
if ( result
|| (result = func0(v2, 6)) != 0
|| (result = func0(v2, 5)) != 0
|| (result = func0(v2, 7)) != 0
|| (result = func0(v2, 8)) != 0
|| (result = func0(v2, 9)) != 0
|| (result = func0(v2, 10)) != 0 )
{
*a2 = *(_DWORD *)(result + 8);
}
v4 = *a2;
if ( *a2 == 6 )
return func1(a1);
if ( (unsigned int)(v4 - 8) <= 1 )
return func2(a1);
if ( v4 )
*a1 = result;
return result;
}

original_code:
void ft_find_priority_operand(t_p **keep, int *type)
{
 t_p *move;
 if ((move = ft_check_if_type_to_split(*keep, 4))
  || (move = ft_check_if_type_to_split(*keep, 6))
  || (move = ft_check_if_type_to_split(*keep, 5))
  || (move = ft_check_if_type_to_split(*keep, 7))
  || (move = ft_check_if_type_to_split(*keep, 8))
  || (move = ft_check_if_type_to_split(*keep, 9))
  || (move = ft_check_if_type_to_split(*keep, 10)))
  *type = move->type;
 if (*type == 6)
  ft_find_priority_between_or_and_and(keep);
 else if (*type == 8 || *type == 9)
  ft_find_priority_between_all_the_redir(keep);
 else if (*type)
  *keep = move;
}

canonical_original_code:
void ft_find_priority_operand(struct s_p **keep, int *type)
{
 struct s_p *move;
 if ((move = ft_check_if_type_to_split(*keep, 4))
  || (move = ft_check_if_type_to_split(*keep, 6))
  || (move = ft_check_if_type_to_split(*keep, 5))
  || (move = ft_check_if_type_to_split(*keep, 7))
  || (move = ft_check_if_type_to_split(*keep, 8))
  || (move = ft_check_if_type_to_split(*keep, 9))
  || (move = ft_check_if_type_to_split(*keep, 10)))
  *type = move->type;
 if (*type == 6)
  ft_find_priority_between_or_and_and(keep);
 else if (*type == 8 || *type == 9)
  ft_find_priority_between_all_the_redir(keep);
 else if (*type)
  *keep = move;
}

variable_types:
type
int *


decompiled_code:
__int64 __fastcall ft_perform_redir(__int64 a1, __int64 a2, __int64 a3)
{
__int64 *v3; // rax
__int64 v4; // rax
__int64 result; // rax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax

v3 = *(__int64 **)(a1 + 24);
if ( v3[2] || v3[3] || (v4 = *v3, *(_QWORD *)(v4 + 16)) )
{
ft_putendl_fd("Invalid null command", 2LL);
result = 0xFFFFFFFFLL;
}
else if ( *(_DWORD *)(*(_QWORD *)a1 + 8LL) == 8 && (v6 = open(*(const char **)v4, 577, 420LL), a3 = v6, v6 == -1)
|| *(_DWORD *)(*(_QWORD *)a1 + 8LL) == 10 && (v7 = open(***(const char ****)(a1 + 24), 0), a3 = v7, v7 == -1)
|| *(_DWORD *)(*(_QWORD *)a1 + 8LL) == 9 && (v8 = open(***(const char ****)(a1 + 24), 1025), a3 = v8, v8 == -1) )
{
result = ft_error_msg(***(_QWORD ***)(a1 + 24), ": open impossible", a3);
}
else
{
ft_exe_redir((_QWORD *)a1, a2, a3);
result = *(unsigned int *)ft_value();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
__int64 *v3; // rax
__int64 v4; // rax
__int64 result; // rax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax

v3 = *(__int64 **)(a1 + 24);
if ( v3[2] || v3[3] || (v4 = *v3, *(_QWORD *)(v4 + 16)) )
{
ft_putendl_fd("Invalid null command", 2LL);
result = 0xFFFFFFFFLL;
}
else if ( *(_DWORD *)(*(_QWORD *)a1 + 8LL) == 8 && (v6 = open(*(const char **)v4, 577, 420LL), a3 = v6, v6 == -1)
|| *(_DWORD *)(*(_QWORD *)a1 + 8LL) == 10 && (v7 = open(***(const char ****)(a1 + 24), 0), a3 = v7, v7 == -1)
|| *(_DWORD *)(*(_QWORD *)a1 + 8LL) == 9 && (v8 = open(***(const char ****)(a1 + 24), 1025), a3 = v8, v8 == -1) )
{
result = ft_error_msg(***(_QWORD ***)(a1 + 24), ": open impossible", a3);
}
else
{
func0((_QWORD *)a1, a2, a3);
result = *(unsigned int *)ft_value();
}
return result;
}

original_code:
int ft_perform_redir(t_tree *t, t_env *e)
{
 int fd;
 int value;
 value = 0;
 if (t->ri->le || t->ri->ri || t->ri->p->next)
 {
  ft_putendl_fd("Invalid null command", 2);
  return (-1);
 }
 if (t->p->type == 8
  && ((fd = open(t->ri->p->tok,
      01 | 0100 | 01000, 0644)) == -1))
  return (ft_error_msg(t->ri->p->tok, ": open impossible"));
 else if (t->p->type == 10
   && ((fd = open(t->ri->p->tok, 00)) == -1))
  return (ft_error_msg(t->ri->p->tok, ": open impossible"));
 else if (t->p->type == 9
   && (fd = open(t->ri->p->tok, 02000 | 01)) == -1)
  return (ft_error_msg(t->ri->p->tok, ": open impossible"));
 ft_exe_redir(t, e, fd);
 value = *ft_value();
 return (value);
}

canonical_original_code:
int ft_perform_redir(struct s_tree *t, struct s_env *e)
{
 int fd;
 int value;
 value = 0;
 if (t->ri->le || t->ri->ri || t->ri->p->next)
 {
  ft_putendl_fd("Invalid null command", 2);
  return (-1);
 }
 if (t->p->type == 8
  && ((fd = open(t->ri->p->tok,
      01 | 0100 | 01000, 0644)) == -1))
  return (ft_error_msg(t->ri->p->tok, ": open impossible"));
 else if (t->p->type == 10
   && ((fd = open(t->ri->p->tok, 00)) == -1))
  return (ft_error_msg(t->ri->p->tok, ": open impossible"));
 else if (t->p->type == 9
   && (fd = open(t->ri->p->tok, 02000 | 01)) == -1)
  return (ft_error_msg(t->ri->p->tok, ": open impossible"));
 ft_exe_redir(t, e, fd);
 value = *ft_value();
 return (value);
}

variable_types: struct s_tree { struct s_p { char *tok; int type; struct s_p *next; struct s_p *prev; } *p; struct s_tree *fa; struct s_tree *le; struct s_tree *ri; } *

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

variable_types: fd int

variable_types: value int

user_defined_types: struct s_tree { struct s_p *p; struct s_tree *fa; struct s_tree *le; struct s_tree *ri; }


decompiled_code:
__int64 __fastcall ft_perform_pipe2(__int64 a1, __int64 a2)
{
__int64 v2; // r12
_DWORD *v3; // rbp
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

pipe(pipedes);
if ( fork() )
{
dup2(pipedes[1], 1);
close(pipedes[0]);
v2 = *(_QWORD *)(a1 + 16);
}
else
{
dup2(pipedes[0], 0);
close(pipedes[1]);
v2 = *(_QWORD *)(a1 + 24);
}
v3 = (_DWORD *)ft_value();
*v3 = ft_execute_all(v2, a2);
return *(unsigned int *)ft_value();
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // r12
_DWORD *v3; // rbp
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

pipe(pipedes);
if ( fork() )
{
dup2(pipedes[1], 1);
close(pipedes[0]);
v2 = *(_QWORD *)(a1 + 16);
}
else
{
dup2(pipedes[0], 0);
close(pipedes[1]);
v2 = *(_QWORD *)(a1 + 24);
}
v3 = (_DWORD *)ft_value();
*v3 = ft_execute_all(v2, a2);
return *(unsigned int *)ft_value();
}

original_code:
int ft_perform_pipe2(t_tree *t, t_env *e)
{
 int fd_pipe[2];
 pid_t father;
 int value;
 value = 0;
 pipe(fd_pipe);
 father = fork();
 if (father == 0)
 {
  dup2(fd_pipe[0], 0);
  close(fd_pipe[1]);
  *ft_value() = ft_execute_all(t->ri, e);
 }
 else
 {
  dup2(fd_pipe[1], 1);
  close(fd_pipe[0]);
  *ft_value() = ft_execute_all(t->le, e);
 }
 value = *ft_value();
 return (value);
}

canonical_original_code:
int ft_perform_pipe2(struct s_tree *t, struct s_env *e)
{
 int fd_pipe[2];
 int father;
 int value;
 value = 0;
 pipe(fd_pipe);
 father = fork();
 if (father == 0)
 {
  dup2(fd_pipe[0], 0);
  close(fd_pipe[1]);
  *ft_value() = ft_execute_all(t->ri, e);
 }
 else
 {
  dup2(fd_pipe[1], 1);
  close(fd_pipe[0]);
  *ft_value() = ft_execute_all(t->le, e);
 }
 value = *ft_value();
 return (value);
}

variable_types: father int

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


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

LODWORD(stat_loc.__uptr) = fork();
if ( SLODWORD(stat_loc.__uptr) <= 0 )
{
ft_perform_pipe2(a1, a2);
exit(1);
}
wait((__WAIT_STATUS)&stat_loc);
return *(unsigned int *)ft_value();
}

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

LODWORD(stat_loc.__uptr) = fork();
if ( SLODWORD(stat_loc.__uptr) <= 0 )
{
func2(a1, a2);
exit(1);
}
wait((__WAIT_STATUS)&stat_loc);
return *(unsigned int *)ft_value();
}

original_code:
int ft_perform_pipe(t_tree *t, t_env *e)
{
 pid_t father;
 int value;
 value = 0;
 father = fork();
 if (father > 0)
  wait(&father);
 else
 {
  value = ft_perform_pipe2(t, e);
  exit(1);
 }
 value = *ft_value();
 return (value);
}

canonical_original_code:
int ft_perform_pipe(struct s_tree *t, struct s_env *e)
{
 int father;
 int value;
 value = 0;
 father = fork();
 if (father > 0)
  wait(&father);
 else
 {
  value = ft_perform_pipe2(t, e);
  exit(1);
 }
 value = *ft_value();
 return (value);
}


decompiled_code:
unsigned __int64 ft_printf(__int64 a1, ...)
{
unsigned __int64 *v1; // rax
unsigned __int64 *v2; // rbx
unsigned __int64 v3; // rax
unsigned __int64 v5; // rax
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rdx
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

v1 = (unsigned __int64 *)malloc(0x20uLL);
v2 = v1;
if ( !v1 )
return 0LL;
*v1 = 0LL;
v1[1] = 0LL;
v3 = ft_strlen(a1);
v2[2] = v3;
v2[3] = 0LL;
va_start(va, a1);
if ( *v2 < v3 )
{
do
{
v7 = *v2;
if ( *v2 < v3 )
{
while ( *(_BYTE *)(a1 + v7) != 37 )
{
*v2 = ++v7;
if ( v7 == v3 )
{
v7 = v3;
break;
}
}
}
v2[3] += write(1, (const void *)(v2[1] + a1), v7 - v2[1]);
v5 = *v2 + 1;
*v2 = v5;
if ( v5 < v2[2] )
ft_all_opt(a1, (unsigned int *)va, v2);
v6 = *v2 + 1;
*v2 = v6;
v2[1] = v6;
v3 = v2[2];
}
while ( v6 < v3 );
}
return v2[3];
}

canonical_decompiled_code:
unsigned __int64 func1(__int64 a1, ...)
{
unsigned __int64 *v1; // rax
unsigned __int64 *v2; // rbx
unsigned __int64 v3; // rax
unsigned __int64 v5; // rax
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rdx
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

v1 = (unsigned __int64 *)malloc(0x20uLL);
v2 = v1;
if ( !v1 )
return 0LL;
*v1 = 0LL;
v1[1] = 0LL;
v3 = ft_strlen(a1);
v2[2] = v3;
v2[3] = 0LL;
va_start(va, a1);
if ( *v2 < v3 )
{
do
{
v7 = *v2;
if ( *v2 < v3 )
{
while ( *(_BYTE *)(a1 + v7) != 37 )
{
*v2 = ++v7;
if ( v7 == v3 )
{
v7 = v3;
break;
}
}
}
v2[3] += write(1, (const void *)(v2[1] + a1), v7 - v2[1]);
v5 = *v2 + 1;
*v2 = v5;
if ( v5 < v2[2] )
func0(a1, (unsigned int *)va, v2);
v6 = *v2 + 1;
*v2 = v6;
v2[1] = v6;
v3 = v2[2];
}
while ( v6 < v3 );
}
return v2[3];
}

original_code:
ssize_t ft_printf(const char *format, ...)
{
 t_struct *info;
 va_list ap;
 if (!(info = (t_struct *)malloc(sizeof(t_struct))))
  return (0);
 info->i = 0;
 info->j = 0;
 info->len = ft_strlen(format);
 info->tot = 0;
 __builtin_va_start(ap,format);
 while (info->i < info->len)
 {
  while (info->i < info->len && *(format + info->i) != '%')
   info->i++;
  info->tot += write(1, format + info->j, info->i - info->j);
  info->i++;
  if (info->i < info->len)
   ft_all_opt(format, ap, info);
  info->i++;
  info->j = info->i;
 }
 __builtin_va_end(ap);
 return (info->tot);
}

canonical_original_code:
long ft_printf(char *format, ...)
{
 struct s_struct *info;
 __builtin_va_list ap;
 if (!(info = (struct s_struct *)malloc(sizeof(t_struct))))
  return (0);
 info->i = 0;
 info->j = 0;
 info->len = ft_strlen(format);
 info->tot = 0;
 __builtin_va_start(ap,format);
 while (info->i < info->len)
 {
  while (info->i < info->len && *(format + info->i) != '%')
   info->i++;
  info->tot += write(1, format + info->j, info->i - info->j);
  info->i++;
  if (info->i < info->len)
   ft_all_opt(format, ap, info);
  info->i++;
  info->j = info->i;
 }
 __builtin_va_end(ap);
 return (info->tot);
}

variable_types:
format
char *

variable_types: struct s_struct { unsigned long i; unsigned long j; unsigned long len; long tot; } *


decompiled_code:
__int64 __fastcall ft_find_home(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 v2; // rdi

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
if ( !(unsigned int)ft_strncmp(v2, "HOME=", 5LL) )
break;
v2 = *++v1;
}
while ( *v1 );
}
return *v1 + 5LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 v2; // rdi

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
if ( !(unsigned int)ft_strncmp(v2, "HOME=", 5LL) )
break;
v2 = *++v1;
}
while ( *v1 );
}
return *v1 + 5LL;
}

original_code:
static char *ft_find_home(char **env)
{
 int i;
 i = 0;
 while (env[i] && ft_strncmp(env[i], "HOME=", 5) != 0)
  ++i;
 return (env[i] + 5);
}

variable_types:
env
char **

variable_types: i int


decompiled_code:
__int64 __fastcall ft_find_oldpwd(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 v2; // rdi

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
if ( !(unsigned int)ft_strncmp(v2, "OLDPWD=", 7LL) )
break;
v2 = *++v1;
}
while ( *v1 );
}
return *v1 + 7LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 v2; // rdi

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
if ( !(unsigned int)ft_strncmp(v2, "OLDPWD=", 7LL) )
break;
v2 = *++v1;
}
while ( *v1 );
}
return *v1 + 7LL;
}

original_code:
static char *ft_find_oldpwd(char **env)
{
 int i;
 i = 0;
 while (env[i] && ft_strncmp(env[i], "OLDPWD=", 7) != 0)
  ++i;
 return (env[i] + 7);
}


decompiled_code:
int __fastcall ft_cd_2(__int64 a1, _QWORD *a2, _DWORD *a3)
{
__int64 v5; // rdi
int result; // eax
const char *v7; // rax
const char *v8; // rax

v5 = *(_QWORD *)(a1 + 8);
if ( v5 )
{
if ( *(_QWORD *)(a1 + 16) )
{
result = ft_putendl("cd: too many arguments");
}
else if ( (unsigned int)ft_strcmp(v5, "-") )
{
result = chdir(*(const char **)(a1 + 8));
if ( result )
result = ft_putendl("cd: not a directory");
else
*a3 = 1;
}
else
{
v8 = (const char *)ft_find_oldpwd(a2);
result = chdir(v8);
if ( result == -1 )
result = ft_putendl_fd("cd: error going to last directory", 2LL);
*a3 = 1;
}
}
else
{
v7 = (const char *)ft_find_home(a2);
result = chdir(v7);
if ( result == -1 )
result = ft_putendl_fd("cd: error going to home directory", 2LL);
*a3 = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, _QWORD *a2, _DWORD *a3)
{
__int64 v5; // rdi
int result; // eax
const char *v7; // rax
const char *v8; // rax

v5 = *(_QWORD *)(a1 + 8);
if ( v5 )
{
if ( *(_QWORD *)(a1 + 16) )
{
result = ft_putendl("cd: too many arguments");
}
else if ( (unsigned int)ft_strcmp(v5, "-") )
{
result = chdir(*(const char **)(a1 + 8));
if ( result )
result = ft_putendl("cd: not a directory");
else
*a3 = 1;
}
else
{
v8 = (const char *)func1(a2);
result = chdir(v8);
if ( result == -1 )
result = ft_putendl_fd("cd: error going to last directory", 2LL);
*a3 = 1;
}
}
else
{
v7 = (const char *)func0(a2);
result = chdir(v7);
if ( result == -1 )
result = ft_putendl_fd("cd: error going to home directory", 2LL);
*a3 = 1;
}
return result;
}

original_code:
static void ft_cd_2(char **all, char **env, int *success)
{
 if (!all[1])
 {
  if (chdir(ft_find_home(env)) == -1)
   ft_putendl_fd("cd: error going to home directory", 2);
  *success = 1;
 }
 else if (all[2])
  ft_putendl("cd: too many arguments");
 else if (!ft_strcmp(all[1], "-"))
 {
  if (chdir(ft_find_oldpwd(env)) == -1)
   ft_putendl_fd("cd: error going to last directory", 2);
  *success = 1;
 }
 else if (!chdir(all[1]))
  *success = 1;
 else
  ft_putendl("cd: not a directory");
}

variable_types:
all
char **

variable_types:
success
int *


decompiled_code:
__int64 __fastcall ft_cd(__int64 a1, _QWORD *a2)
{
__int64 v2; // rbx
char *v3; // rax
char *v4; // rbp
char *v5; // r13
char *v7; // rax
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = (__int64)a2;
v8[0] = 0;
v3 = (char *)gmalloc(1025LL);
v4 = v3;
if ( !v3 )
return 0LL;
v5 = getcwd(v3, 0x400uLL);
ft_cd_2(a1, a2, v8);
if ( v8[0] == 1 )
{
v2 = ft_change_env("OLDPWD", v5, a2);
if ( v2 )
{
v7 = getcwd(v4, 0x400uLL);
v2 = ft_change_env("PWD", v7, v2);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2)
{
__int64 v2; // rbx
char *v3; // rax
char *v4; // rbp
char *v5; // r13
char *v7; // rax
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = (__int64)a2;
v8[0] = 0;
v3 = (char *)gmalloc(1025LL);
v4 = v3;
if ( !v3 )
return 0LL;
v5 = getcwd(v3, 0x400uLL);
func2(a1, a2, v8);
if ( v8[0] == 1 )
{
v2 = ft_change_env("OLDPWD", v5, a2);
if ( v2 )
{
v7 = getcwd(v4, 0x400uLL);
v2 = ft_change_env("PWD", v7, v2);
}
}
return v2;
}

original_code:
char **ft_cd(char **all, char **env)
{
 char *cur_dir;
 char *buf;
 int success;
 success = 0;
 if (!(buf = (char *)gmalloc(sizeof(char) * (1024 + 1))))
  return (((void *)0));
 cur_dir = getcwd(buf, 1024);
 ft_cd_2(all, env, &success);
 if (success == 1)
 {
  if (!(env = ft_change_env("OLDPWD", cur_dir, env)))
   return (((void *)0));
  if (!(env = ft_change_env("PWD", getcwd(buf, 1024), env)))
   return (((void *)0));
 }
 return (env);
}

variable_types:
buf
char *

variable_types: success int


decompiled_code:
__int64 __fastcall ft_simple_left_redir(__int64 a1, const char *a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // er12
__pid_t v6; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = ft_ts_to_str();
if ( !ft_strparse(v4) )
return 0LL;
v5 = open(a2, 0);
if ( v5 == -1 )
ft_putendl("file open failed or file does not exist");
v6 = fork();
LODWORD(stat_loc.__uptr) = v6;
if ( v6 > 0 )
{
wait((__WAIT_STATUS)&stat_loc);
}
else if ( !v6 )
{
dup2(v5, 0);
a3 = ft_run_small_part(v4, a3);
if ( a3 )
exit(-1);
}
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // er12
__pid_t v6; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = ft_ts_to_str();
if ( !ft_strparse(v4) )
return 0LL;
v5 = open(a2, 0);
if ( v5 == -1 )
ft_putendl("file open failed or file does not exist");
v6 = fork();
LODWORD(stat_loc.__uptr) = v6;
if ( v6 > 0 )
{
wait((__WAIT_STATUS)&stat_loc);
}
else if ( !v6 )
{
dup2(v5, 0);
a3 = ft_run_small_part(v4, a3);
if ( a3 )
exit(-1);
}
return a3;
}

original_code:
char **ft_simple_left_redir(char **cmd, char *file, char **env)
{
 int father;
 int fd;
 char *line;
 char **all;
 line = ft_ts_to_str(cmd);
 if (!(all = ft_strparse(line)))
  return (((void *)0));
 if ((fd = open(file, 00)) == -1)
  ft_putendl("file open failed or file does not exist");
 if ((father = fork()) > 0)
 {
  wait(&father);
  return (env);
 }
 if (father == 0)
 {
  dup2(fd, 0);
  if (!(env = ft_run_small_part(line, env)))
   return (((void *)0));
  exit(-1);
 }
 return (env);
}

variable_types:
cmd
char **

variable_types:
file
char *

variable_types:
line
char *


decompiled_code:
__int64 __fastcall ft_simple_right_redir(__int64 a1, const char *a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // er12
__pid_t v6; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = ft_ts_to_str();
if ( !ft_strparse(v4) )
return 0LL;
v5 = open(a2, 578, 384LL);
if ( v5 == -1 )
ft_putendl("file open failed");
v6 = fork();
LODWORD(stat_loc.__uptr) = v6;
if ( v6 > 0 )
{
wait((__WAIT_STATUS)&stat_loc);
}
else if ( !v6 )
{
dup2(v5, 1);
a3 = ft_run_small_part(v4, a3);
if ( a3 )
exit(-1);
}
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // er12
__pid_t v6; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = ft_ts_to_str();
if ( !ft_strparse(v4) )
return 0LL;
v5 = open(a2, 578, 384LL);
if ( v5 == -1 )
ft_putendl("file open failed");
v6 = fork();
LODWORD(stat_loc.__uptr) = v6;
if ( v6 > 0 )
{
wait((__WAIT_STATUS)&stat_loc);
}
else if ( !v6 )
{
dup2(v5, 1);
a3 = ft_run_small_part(v4, a3);
if ( a3 )
exit(-1);
}
return a3;
}

original_code:
char **ft_simple_right_redir(char **cmd, char *file, char **env)
{
 pid_t father;
 int fd;
 char *line;
 char **all;
 line = ft_ts_to_str(cmd);
 if (!(all = ft_strparse(line)))
  return (((void *)0));
 if ((fd = open(file, 02 | 0100 | 01000, 0400
     | 0200 | 0400)) == -1)
  ft_putendl("file open failed");
 if ((father = fork()) > 0)
 {
  wait(&father);
  return (env);
 }
 if (father == 0)
 {
  dup2(fd, 1);
  if (!(env = ft_run_small_part(line, env)))
   return (((void *)0));
  exit(-1);
 }
 return (env);
}

canonical_original_code:
char **ft_simple_right_redir(char **cmd, char *file, char **env)
{
 int father;
 int fd;
 char *line;
 char **all;
 line = ft_ts_to_str(cmd);
 if (!(all = ft_strparse(line)))
  return (((void *)0));
 if ((fd = open(file, 02 | 0100 | 01000, 0400
     | 0200 | 0400)) == -1)
  ft_putendl("file open failed");
 if ((father = fork()) > 0)
 {
  wait(&father);
  return (env);
 }
 if (father == 0)
 {
  dup2(fd, 1);
  if (!(env = ft_run_small_part(line, env)))
   return (((void *)0));
  exit(-1);
 }
 return (env);
}


decompiled_code:
__int64 __fastcall ft_double_right_redir(__int64 a1, const char *a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // er12
__pid_t v6; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = ft_ts_to_str();
if ( !ft_strparse(v4) )
return 0LL;
v5 = open(a2, 1090, 384LL);
if ( v5 == -1 )
ft_putendl("file open failed");
v6 = fork();
LODWORD(stat_loc.__uptr) = v6;
if ( v6 > 0 )
{
wait((__WAIT_STATUS)&stat_loc);
}
else if ( !v6 )
{
dup2(v5, 1);
a3 = ft_run_small_part(v4, a3);
if ( a3 )
exit(-1);
}
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // er12
__pid_t v6; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = ft_ts_to_str();
if ( !ft_strparse(v4) )
return 0LL;
v5 = open(a2, 1090, 384LL);
if ( v5 == -1 )
ft_putendl("file open failed");
v6 = fork();
LODWORD(stat_loc.__uptr) = v6;
if ( v6 > 0 )
{
wait((__WAIT_STATUS)&stat_loc);
}
else if ( !v6 )
{
dup2(v5, 1);
a3 = ft_run_small_part(v4, a3);
if ( a3 )
exit(-1);
}
return a3;
}

original_code:
char **ft_double_right_redir(char **cmd, char *file, char **env)
{
 pid_t father;
 int fd;
 char *line;
 char **all;
 line = ft_ts_to_str(cmd);
 if (!(all = ft_strparse(line)))
  return (((void *)0));
 if ((fd = open(file, 02 | 0100 | 02000, 0400
     | 0200 | 0400)) == -1)
  ft_putendl("file open failed");
 if ((father = fork()) > 0)
 {
  wait(&father);
  return (env);
 }
 if (father == 0)
 {
  dup2(fd, 1);
  if (!(env = ft_run_small_part(line, env)))
   return (((void *)0));
  exit(-1);
 }
 return (env);
}

canonical_original_code:
char **ft_double_right_redir(char **cmd, char *file, char **env)
{
 int father;
 int fd;
 char *line;
 char **all;
 line = ft_ts_to_str(cmd);
 if (!(all = ft_strparse(line)))
  return (((void *)0));
 if ((fd = open(file, 02 | 0100 | 02000, 0400
     | 0200 | 0400)) == -1)
  ft_putendl("file open failed");
 if ((father = fork()) > 0)
 {
  wait(&father);
  return (env);
 }
 if (father == 0)
 {
  dup2(fd, 1);
  if (!(env = ft_run_small_part(line, env)))
   return (((void *)0));
  exit(-1);
 }
 return (env);
}


decompiled_code:
__int64 __fastcall ft_swap_r(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)(a1 + 8) )
return a1;
v1 = a1;
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
*(_QWORD *)(v2 + 8) = a1;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}

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

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)(a1 + 8) )
return a1;
v1 = a1;
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
*(_QWORD *)(v2 + 8) = a1;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}

original_code:
t_lst *ft_swap_r(t_lst *list)
{
 t_lst *tmp;
 if (!list || !list->next)
  return (list);
 tmp = list;
 while (list->next)
  list = list->next;
 list->next = tmp;
 tmp = tmp->next;
 list->next->next = ((void *)0);
 return (tmp);
}

canonical_original_code:
struct s_lst *ft_swap_r(struct s_lst *list)
{
 struct s_lst *tmp;
 if (!list || !list->next)
  return (list);
 tmp = list;
 while (list->next)
  list = list->next;
 list->next = tmp;
 tmp = tmp->next;
 list->next->next = ((void *)0);
 return (tmp);
}

variable_types:
list
struct s_lst *

variable_types: struct s_lst { int nb; struct s_lst *next; } *


decompiled_code:
__int64 __fastcall ft_swap_rr(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)(a1 + 8) )
return a1;
result = a1;
do
{
v2 = result;
result = *(_QWORD *)(result + 8);
}
while ( *(_QWORD *)(result + 8) );
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(v2 + 8) = 0LL;
return result;
}

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

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)(a1 + 8) )
return a1;
result = a1;
do
{
v2 = result;
result = *(_QWORD *)(result + 8);
}
while ( *(_QWORD *)(result + 8) );
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(v2 + 8) = 0LL;
return result;
}

original_code:
t_lst *ft_swap_rr(t_lst *list)
{
 t_lst *tmp;
 t_lst *tmp2;
 if (!list || !list->next)
  return (list);
 tmp = list;
 while (list->next->next)
  list = list->next;
 tmp2 = list;
 list = list->next;
 list->next = tmp;
 tmp2->next = ((void *)0);
 return (list);
}

canonical_original_code:
struct s_lst *ft_swap_rr(struct s_lst *list)
{
 struct s_lst *tmp;
 struct s_lst *tmp2;
 if (!list || !list->next)
  return (list);
 tmp = list;
 while (list->next->next)
  list = list->next;
 tmp2 = list;
 list = list->next;
 list->next = tmp;
 tmp2->next = ((void *)0);
 return (list);
}

return_type: struct s_lst { int nb; struct s_lst *next; } *


decompiled_code:
__int64 __fastcall ft_intersect_a_plane(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
double v6; // xmm0_8
__int64 v7; // rdx
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // r9
double v11; // xmm0_8
__int64 v13; // [rsp+0h] [rbp-38h] BYREF

v6 = ft_dot_product(a1, a2, a3, a4, a5, a6);
if ( COERCE_DOUBLE(*(_QWORD *)&v6 & LC0) < 0.000001 )
return 0xFFFFFFFFLL;
ft_vect_difference(&v13);
v11 = ft_dot_product(&v13, a2, v7, v8, v9, v10) / v6;
*(double *)(a1 + 96) = v11;
*(_QWORD *)(a1 + 104) = LC2;
return (unsigned int)-(v11 <= 0.0);
}

original_code:
int ft_intersect_a_plane(t_r *r, void *data)
{
 t_v o_to_c;
 double denom;
 t_pla *pla;
 pla = (t_pla *)data;
 denom = ft_dot_product(r->d_w, pla->n);
 if (fabs(denom) < (0.000001))
  return (-1);
 ft_vect_difference(&o_to_c, pla->c, r->o_w);
 r->t0 = ft_dot_product(pla->n, o_to_c) / denom;
 r->t1 = (1000000000.0);
 if (r->t0 > 0)
  return (0);
 return (-1);
}

canonical_original_code:
int ft_intersect_a_plane(struct s_r *r, void *data)
{
 struct s_v o_to_c;
 double denom;
 struct s_pla *pla;
 pla = (struct s_pla *)data;
 denom = ft_dot_product(r->d_w, pla->n);
 if (fabs(denom) < (0.000001))
  return (-1);
 ft_vect_difference(&o_to_c, pla->c, r->o_w);
 r->t0 = ft_dot_product(pla->n, o_to_c) / denom;
 r->t1 = (1000000000.0);
 if (r->t0 > 0)
  return (0);
 return (-1);
}

variable_types: struct s_r { struct s_v { double x; double y; double z; } o_w; struct s_v d_w; struct s_v p_hit; struct s_v n_hit; double t0; double t1; double tnear; struct s_c { int b; int g; int r; } color; int hit_i; int hit_j; } *

variable_types:
data
void *

variable_types: denom double

variable_types: struct s_pla { struct s_v { double x; double y; double z; } c; struct s_v n; struct s_c { int b; int g; int r; } sf; } *

user_defined_types: struct s_pla { struct s_v c; struct s_v n; struct s_c sf; }


decompiled_code:
char *__fastcall ft_not_need_variable_env_path(char *file)
{
struct stat *v1; // rax
char *v2; // rbx

v1 = (struct stat *)gmalloc(144LL);
v2 = (char *)v1;
if ( v1 )
{
if ( !lstat(file, v1) && (*((_DWORD *)v2 + 6) & 0x4040) == 64 && (*file == 47 || *file == 46 && file[1] == 47) )
{
gfree(v2);
v2 = file;
}
else
{
gfree(v2);
v2 = 0LL;
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(char *file)
{
struct stat *v1; // rax
char *v2; // rbx

v1 = (struct stat *)gmalloc(144LL);
v2 = (char *)v1;
if ( v1 )
{
if ( !lstat(file, v1) && (*((_DWORD *)v2 + 6) & 0x4040) == 64 && (*file == 47 || *file == 46 && file[1] == 47) )
{
gfree(v2);
v2 = file;
}
else
{
gfree(v2);
v2 = 0LL;
}
}
return v2;
}

original_code:
char *ft_not_need_variable_env_path(char *cmd)
{
 struct stat *buf;
 if (!(buf = (struct stat *)gmalloc(sizeof(*buf))))
  return (((void *)0));
 if (lstat(cmd, buf) == 0
  && buf->st_mode & 0100 && !(buf->st_mode & 0040000)
  && (cmd[0] == '/' || (cmd[0] == '.' && cmd[1] == '/')))
 {
  gfree(buf);
  return (cmd);
 }
 gfree(buf);
 return (((void *)0));
}

variable_types:
cmd
char *

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


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

v2 = a2;
v3 = ft_not_need_variable_env_path(a1);
if ( !v3 )
{
v3 = *a2;
if ( *a2 )
{
do
{
v3 = (char *)gmalloc(144LL);
if ( !v3 )
break;
v5 = ft_strjoin(*v2, &unk_2E0);
v6 = (const char *)ft_strjoin(v5, a1);
if ( !lstat(v6, (struct stat *)v3) && (v3[24] & 0x40) != 0 )
{
gfree(v3);
return (char *)v6;
}
gfree(v6);
gfree(v3);
v3 = *++v2;
}
while ( *v2 );
}
}
return v3;
}

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

v2 = a2;
v3 = func0(a1);
if ( !v3 )
{
v3 = *a2;
if ( *a2 )
{
do
{
v3 = (char *)gmalloc(144LL);
if ( !v3 )
break;
v5 = ft_strjoin(*v2, &unk_2E0);
v6 = (const char *)ft_strjoin(v5, a1);
if ( !lstat(v6, (struct stat *)v3) && (v3[24] & 0x40) != 0 )
{
gfree(v3);
return (char *)v6;
}
gfree(v6);
gfree(v3);
v3 = *++v2;
}
while ( *v2 );
}
}
return v3;
}

original_code:
char *ft_find_the_path(char *cmd, char **paths)
{
 char *good_path;
 struct stat *buf;
 int i;
 good_path = ((void *)0);
 buf = ((void *)0);
 if ((good_path = ft_not_need_variable_env_path(cmd)))
  return (good_path);
 i = -1;
 while (paths[++i])
 {
  if (!(buf = (struct stat *)gmalloc(sizeof(*buf))))
   return (((void *)0));
  good_path = ft_strjoin(ft_strjoin(paths[i], "/"), cmd);
  if (lstat(good_path, buf) == 0 && buf->st_mode & 0100)
  {
   gfree(buf);
   return (good_path);
  }
  gfree(good_path);
  gfree(buf);
 }
 return (((void *)0));
}

variable_types:
paths
char **

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


decompiled_code:
__int64 __fastcall ft_perform_exe(char **a1, __int64 **a2)
{
__int64 v3; // rdi
__int64 v4; // rbx
char **v5; // r13
__int64 v6; // rdi
char *v7; // rax
char *v8; // rbx
unsigned int v9; // ebp

v3 = **a2;
v4 = 0LL;
if ( !v3 )
goto LABEL_4;
while ( (unsigned int)ft_strncmp(v3, "PATH=", 5LL) )
{
v3 = (*a2)[++v4];
if ( !v3 )
goto LABEL_4;
}
v6 = (*a2)[v4];
if ( v6 )
v5 = (char **)ft_strsplit(v6 + 5, 58LL);
else
LABEL_4:
v5 = (char **)ft_strsplit(*a2[1] + 5, 58LL);
v7 = ft_find_the_path(*a1, v5);
v8 = v7;
if ( v7 )
{
v9 = ft_exe_the_cmd(a1, v7, *a2);
gfree(v8);
ft_free_char2(v5);
}
else
{
ft_free_char2(v5);
v9 = ft_error_msg(*a1, ": Command not found");
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func2(char **a1, __int64 **a2)
{
__int64 v3; // rdi
__int64 v4; // rbx
char **v5; // r13
__int64 v6; // rdi
char *v7; // rax
char *v8; // rbx
unsigned int v9; // ebp

v3 = **a2;
v4 = 0LL;
if ( !v3 )
goto LABEL_4;
while ( (unsigned int)ft_strncmp(v3, "PATH=", 5LL) )
{
v3 = (*a2)[++v4];
if ( !v3 )
goto LABEL_4;
}
v6 = (*a2)[v4];
if ( v6 )
v5 = (char **)ft_strsplit(v6 + 5, 58LL);
else
LABEL_4:
v5 = (char **)ft_strsplit(*a2[1] + 5, 58LL);
v7 = func1(*a1, v5);
v8 = v7;
if ( v7 )
{
v9 = ft_exe_the_cmd(a1, v7, *a2);
gfree(v8);
ft_free_char2(v5);
}
else
{
ft_free_char2(v5);
v9 = ft_error_msg(*a1, ": Command not found");
}
return v9;
}

original_code:
int ft_perform_exe(t_p *p, t_env *e)
{
 char **paths;
 char *good_path;
 int i;
 int value;
 i = 0;
 value = 0;
 while (e->env[i] && ft_strncmp(e->env[i], "PATH=", 5))
  ++i;
 if (!e->env[i])
  paths = ft_strsplit(&(e->env_s[0][5]), ':');
 else
  paths = ft_strsplit(&(e->env[i][5]), ':');
 if (!(good_path = ft_find_the_path(p->tok, paths)))
 {
  ft_free_char2(paths);
  return (ft_error_msg(p->tok, ": Command not found"));
 }
 value = ft_exe_the_cmd(p, good_path, e->env);
 gfree(good_path);
 ft_free_char2(paths);
 return (value);
}

canonical_original_code:
int ft_perform_exe(struct s_p *p, struct s_env *e)
{
 char **paths;
 char *good_path;
 int i;
 int value;
 i = 0;
 value = 0;
 while (e->env[i] && ft_strncmp(e->env[i], "PATH=", 5))
  ++i;
 if (!e->env[i])
  paths = ft_strsplit(&(e->env_s[0][5]), ':');
 else
  paths = ft_strsplit(&(e->env[i][5]), ':');
 if (!(good_path = ft_find_the_path(p->tok, paths)))
 {
  ft_free_char2(paths);
  return (ft_error_msg(p->tok, ": Command not found"));
 }
 value = ft_exe_the_cmd(p, good_path, e->env);
 gfree(good_path);
 ft_free_char2(paths);
 return (value);
}

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

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

variable_types: i int

variable_types: value int


decompiled_code:
__int64 __fastcall ft_perform_cmd(char ***a1, __int64 **a2)
{
unsigned int v2; // ebp

if ( !(unsigned int)ft_strcmp(**a1, "exit") )
return (unsigned int)ft_exit(*a1);
v2 = ft_strcmp(**a1, "echo");
if ( v2 )
{
if ( (unsigned int)ft_strcmp(**a1, "cd") )
{
if ( (unsigned int)ft_strcmp(**a1, "env") )
{
if ( (unsigned int)ft_strcmp(**a1, "unsetenv") )
{
if ( (unsigned int)ft_strcmp(**a1, "setenv") )
v2 = ft_perform_exe(*a1, a2);
else
v2 = ft_setenv(*a1, a2);
}
else
{
v2 = ft_unsetenv(*a1, a2);
}
}
else
{
v2 = ft_env(*a1, a2);
}
}
else
{
v2 = ft_cd(*a1, a2);
}
}
else
{
ft_echo(*a1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(char ***a1, __int64 **a2)
{
unsigned int v2; // ebp

if ( !(unsigned int)ft_strcmp(**a1, "exit") )
return (unsigned int)ft_exit(*a1);
v2 = ft_strcmp(**a1, "echo");
if ( v2 )
{
if ( (unsigned int)ft_strcmp(**a1, "cd") )
{
if ( (unsigned int)ft_strcmp(**a1, "env") )
{
if ( (unsigned int)ft_strcmp(**a1, "unsetenv") )
{
if ( (unsigned int)ft_strcmp(**a1, "setenv") )
v2 = func2(*a1, a2);
else
v2 = ft_setenv(*a1, a2);
}
else
{
v2 = ft_unsetenv(*a1, a2);
}
}
else
{
v2 = ft_env(*a1, a2);
}
}
else
{
v2 = ft_cd(*a1, a2);
}
}
else
{
ft_echo(*a1);
}
return v2;
}

original_code:
int ft_perform_cmd(t_tree *t, t_env *e)
{
 int value;
 value = 0;
 if (!ft_strcmp(t->p->tok, "exit"))
  value = ft_exit(t->p);
 else if (!ft_strcmp(t->p->tok, "echo"))
  ft_echo(t->p);
 else if (!(ft_strcmp(t->p->tok, "cd")))
  value = ft_cd(t->p, e);
 else if (!(ft_strcmp(t->p->tok, "env")))
  value = ft_env(t->p, e);
 else if (!(ft_strcmp(t->p->tok, "unsetenv")))
  value = ft_unsetenv(t->p, &(e->env));
 else if (!(ft_strcmp(t->p->tok, "setenv")))
  value = ft_setenv(t->p, &(e->env));
 else
  value = ft_perform_exe(t->p, e);
 return (value);
}

canonical_original_code:
int ft_perform_cmd(struct s_tree *t, struct s_env *e)
{
 int value;
 value = 0;
 if (!ft_strcmp(t->p->tok, "exit"))
  value = ft_exit(t->p);
 else if (!ft_strcmp(t->p->tok, "echo"))
  ft_echo(t->p);
 else if (!(ft_strcmp(t->p->tok, "cd")))
  value = ft_cd(t->p, e);
 else if (!(ft_strcmp(t->p->tok, "env")))
  value = ft_env(t->p, e);
 else if (!(ft_strcmp(t->p->tok, "unsetenv")))
  value = ft_unsetenv(t->p, &(e->env));
 else if (!(ft_strcmp(t->p->tok, "setenv")))
  value = ft_setenv(t->p, &(e->env));
 else
  value = ft_perform_exe(t->p, e);
 return (value);
}

variable_types: struct s_tree { struct s_p { char *tok; int type; struct s_p *next; struct s_p *prev; } *p; struct s_tree *fa; struct s_tree *le; struct s_tree *ri; } *


decompiled_code:
__int64 __fastcall ft_unsetenv(__int64 a1, _QWORD *a2)
{
__int64 *v2; // rbx

v2 = *(__int64 **)(a1 + 16);
if ( v2 )
{
do
{
while ( (unsigned int)ft_find(*v2, "=") )
v2 = (__int64 *)v2[2];
ft_del_var(*v2, a2);
v2 = (__int64 *)v2[2];
}
while ( v2 );
}
else
{
ft_putendl_fd("unsetenv: Too few arguments", 2LL);
}
return 0LL;
}

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

v2 = *(__int64 **)(a1 + 16);
if ( v2 )
{
do
{
while ( (unsigned int)ft_find(*v2, "=") )
v2 = (__int64 *)v2[2];
ft_del_var(*v2, a2);
v2 = (__int64 *)v2[2];
}
while ( v2 );
}
else
{
ft_putendl_fd("unsetenv: Too few arguments", 2LL);
}
return 0LL;
}

original_code:
int ft_unsetenv(t_p *p, char ***env)
{
 t_p *move;
 move = p->next;
 if (!move)
  ft_putendl_fd("unsetenv: Too few arguments", 2);
 while (move)
 {
  while (ft_find(move->tok, "="))
   move = move->next;
  if (move)
   ft_del_var(move->tok, env);
  move = move->next;
 }
 return (0);
}

canonical_original_code:
int ft_unsetenv(struct s_p *p, char ***env)
{
 struct s_p *move;
 move = p->next;
 if (!move)
  ft_putendl_fd("unsetenv: Too few arguments", 2);
 while (move)
 {
  while (ft_find(move->tok, "="))
   move = move->next;
  if (move)
   ft_del_var(move->tok, env);
  move = move->next;
 }
 return (0);
}

variable_types:
env
char ***


decompiled_code:
__int64 __fastcall ft_exe_cmd_with_new_env(_QWORD *a1, _QWORD *a2)
{
__int64 v3; // rax
_QWORD *v4; // r12
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rbp
_QWORD *v8; // r13
unsigned int v9; // ebx

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

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2)
{
__int64 v3; // rax
_QWORD *v4; // r12
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rbp
_QWORD *v8; // r13
unsigned int v9; // ebx

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

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

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


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

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

variable_types:
str
char *

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

variable_types:
save
struct s_p *

variable_types:
var
char *


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

v2 = (_QWORD *)a1;
v7[0] = a1;
for ( i = 0LL; ; i += 8LL )
{
v4 = *(char **)(*a2 + i);
if ( !v4 )
break;
v5 = ft_find_in_env(v4, v7, 0LL);
if ( v5 == -1 )
{
ft_putendl(*(_QWORD *)(*a2 + i));
}
else if ( v5 == -2 )
{
return 0xFFFFFFFFLL;
}
}
if ( !v2 )
return 0LL;
do
{
if ( *v2 )
ft_putendl(*v2);
v2 = (_QWORD *)v2[2];
}
while ( v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // rbp
__int64 i; // rbx
char *v4; // rdi
int v5; // eax
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = (_QWORD *)a1;
v7[0] = a1;
for ( i = 0LL; ; i += 8LL )
{
v4 = *(char **)(*a2 + i);
if ( !v4 )
break;
v5 = func1(v4, v7, 0LL);
if ( v5 == -1 )
{
ft_putendl(*(_QWORD *)(*a2 + i));
}
else if ( v5 == -2 )
{
return 0xFFFFFFFFLL;
}
}
if ( !v2 )
return 0LL;
do
{
if ( *v2 )
ft_putendl(*v2);
v2 = (_QWORD *)v2[2];
}
while ( v2 );
return 0LL;
}

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

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

variable_types: ret int


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

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

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

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

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

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


decompiled_code:
__int64 __fastcall ft_env(__int64 a1, __int64 **a2)
{
_QWORD *v2; // rbx
int v3; // ebp
__int64 result; // rax
__int64 v5; // rdi
__int64 v6; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 **a2)
{
_QWORD *v2; // rbx
int v3; // ebp
__int64 result; // rax
__int64 v5; // rdi
__int64 v6; // rbx

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

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

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


repo: andreisoare/memfrag

decompiled_code:
_BOOL8 __fastcall search_node(unsigned __int64 a1)
{
__int64 v1; // rcx
int v2; // er8
__int64 v3; // rax
__int64 i; // rdx
_QWORD *v5; // rax
__int64 v6; // rax
_BOOL8 result; // rax

v1 = first;
if ( !first )
return 0LL;
v2 = H;
LODWORD(v3) = H + 1;
if ( H + 1 <= 200 )
{
v3 = (int)v3;
do
path[v3++] = v1;
while ( (int)v3 <= 200 );
}
if ( v2 >= 0 )
{
for ( i = v2; ; --i )
{
v5 = (_QWORD *)v1;
do
{
v1 = (__int64)v5;
v5 = *(_QWORD **)(*v5 + i * 8);
}
while ( v5 && v5[3] < a1 );
path[i] = v1;
if ( i == v2 - (unsigned __int64)(unsigned int)v2 )
break;
}
}
v6 = **(_QWORD **)path[0];
if ( v6 )
result = *(_QWORD *)(v6 + 24) == a1;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(unsigned __int64 a1)
{
__int64 v1; // rcx
int v2; // er8
__int64 v3; // rax
__int64 i; // rdx
_QWORD *v5; // rax
__int64 v6; // rax
_BOOL8 result; // rax

v1 = first;
if ( !first )
return 0LL;
v2 = H;
LODWORD(v3) = H + 1;
if ( H + 1 <= 200 )
{
v3 = (int)v3;
do
path[v3++] = v1;
while ( (int)v3 <= 200 );
}
if ( v2 >= 0 )
{
for ( i = v2; ; --i )
{
v5 = (_QWORD *)v1;
do
{
v1 = (__int64)v5;
v5 = *(_QWORD **)(*v5 + i * 8);
}
while ( v5 && v5[3] < a1 );
path[i] = v1;
if ( i == v2 - (unsigned __int64)(unsigned int)v2 )
break;
}
}
v6 = **(_QWORD **)path[0];
if ( v6 )
result = *(_QWORD *)(v6 + 24) == a1;
else
result = 0LL;
return result;
}

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

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

variable_types:
ptr
void *

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


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

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

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


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

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

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

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

variable_types:
key
void *


delH

decompiled_code:
void __fastcall delH(__int64 a1, unsigned __int64 a2)
{
_QWORD **v2; // rax
_QWORD *v3; // rdi
_QWORD *v4; // rax

v2 = (_QWORD **)(a1 + 8LL * (int)hash_gen(a2));
v3 = *v2;
if ( *v2 )
{
if ( *v3 == a2 )
{
*v2 = (_QWORD *)v3[2];
free(v3);
}
else
{
while ( 1 )
{
v4 = v3;
v3 = (_QWORD *)v3[2];
if ( !v3 )
break;
if ( *v3 == a2 )
{
v4[2] = v3[2];
free(v3);
return;
}
}
}
}
}

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

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

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

variable_types:
adr
void *

variable_types: k int


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

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

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

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

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

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

variable_types:
arg
void *

variable_types: err int

return_type: void *

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

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

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


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

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

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

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


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

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

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

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

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

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

variable_types: struct resource { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } res_q; int c_res_q; union pthread_cond_t res_p; int c_res_p; int free; int pair_pid; int pair_weight; union pthread_cond_t *free_pair; int *partner_finished; } *

variable_types: N int

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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


decompiled_code:
void __noreturn exit_server()
{
unsigned int v0; // eax
__int64 v1; // rbp
int v2; // ebx
unsigned int v3; // eax
__int64 v4; // rbp
int v5; // ebx

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

canonical_decompiled_code:
void __noreturn func5()
{
unsigned int v0; // eax
__int64 v1; // rbp
int v2; // ebx
unsigned int v3; // eax
__int64 v4; // rbp
int v5; // ebx

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

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

variable_types: sig int

variable_types: i int


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

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

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

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

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