decompiled_code:
void __fastcall ft_vect_difference(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_difference(t_v *vect, t_v vect1, t_v vect2)
{
 vect->x = vect1.x - vect2.x;
 vect->y = vect1.y - vect2.y;
 vect->z = vect1.z - vect2.z;
}

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


decompiled_code:
double __fastcall ft_dot_product(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)
{
return a9 * a12 + a10 * a13 + a11 * a14;
}

canonical_decompiled_code:
double __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, double a13, double a14)
{
return a9 * a12 + a10 * a13 + a11 * a14;
}

original_code:
double ft_dot_product(t_v vect1, t_v vect2)
{
 return (vect1.x * vect2.x + vect1.y * vect2.y + vect1.z * vect2.z);
}

canonical_original_code:
double ft_dot_product(struct s_v vect1, struct s_v vect2)
{
 return (vect1.x * vect2.x + vect1.y * vect2.y + vect1.z * vect2.z);
}

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

return_type: double


original_code:
void ft_cross_product(t_v *vect, t_v *vect1, t_v *vect2)
{
 vect->x = vect1->y * vect2->z - vect1->z * vect2->y;
 vect->y = -(vect1->x * vect2->z - vect1->z * vect2->x);
 vect->z = vect1->x * vect2->y - vect1->y * vect2->x;
}

canonical_original_code:
void ft_cross_product(struct s_v *vect, struct s_v *vect1, struct s_v *vect2)
{
 vect->x = vect1->y * vect2->z - vect1->z * vect2->y;
 vect->y = -(vect1->x * vect2->z - vect1->z * vect2->x);
 vect->z = vect1->x * vect2->y - vect1->y * vect2->x;
}

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

return_type: void


decompiled_code:
__int64 __fastcall ft_init_basic_env(__int64 *a1)
{
__int64 v1; // rax
__int64 v2; // rbp
_QWORD *v3; // r12
char *v4; // rbp
_QWORD *v5; // r12

v1 = gmalloc(16LL);
*a1 = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = ft_strdup("PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin");
v3 = (_QWORD *)*a1;
*v3 = ft_strjoin(v2, ":/opt/X11/bin:/usr/texbin");
gfree(v2);
v4 = getcwd(0LL, 0LL);
v5 = (_QWORD *)*a1;
v5[1] = ft_strjoin("PWD=", v4);
free(v4);
*(_QWORD *)(*a1 + 16) = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1)
{
__int64 v1; // rax
__int64 v2; // rbp
_QWORD *v3; // r12
char *v4; // rbp
_QWORD *v5; // r12

v1 = gmalloc(16LL);
*a1 = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = ft_strdup("PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin");
v3 = (_QWORD *)*a1;
*v3 = ft_strjoin(v2, ":/opt/X11/bin:/usr/texbin");
gfree(v2);
v4 = getcwd(0LL, 0LL);
v5 = (_QWORD *)*a1;
v5[1] = ft_strjoin("PWD=", v4);
free(v4);
*(_QWORD *)(*a1 + 16) = 0LL;
return 0LL;
}

original_code:
static int ft_init_basic_env(char ***env)
{
 char *buf;
 if (!(*env = (char **)gmalloc(sizeof(char *) * 2)))
  return (-1);
 buf = ft_strdup("PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin");
 (*env)[0] = ft_strjoin(buf, ":/opt/X11/bin:/usr/texbin");
 gfree(buf);
 buf = ((void *)0);
 buf = getcwd(buf, 0);
 (*env)[1] = ft_strjoin("PWD=", buf);
 free(buf);
 (*env)[2] = ((void *)0);
 return (0);
}

variable_types:
env
char ***

variable_types:
buf
char *

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // rdi
const char **v5; // rdi
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
int v13; // ebx
__m128i v15; // [rsp+0h] [rbp-A8h]
__m128i v16; // [rsp+40h] [rbp-68h] BYREF
__int128 v17; // [rsp+80h] [rbp-28h] BYREF
__int64 v18; // [rsp+90h] [rbp-18h]

if ( argc != 1 || !argv )
return -1;
if ( !(unsigned int)ft_check_signal() )
return -1;
v4 = envp;
v18 = ft_copy_ts(envp);
if ( v18 && (v4 = envp, ft_copy_ts(envp)) )
{
v5 = envp;
*(_QWORD *)&v17 = ft_copy_ts(envp);
if ( !(_QWORD)v17 || (v5 = (const char **)&v17 + 1, (unsigned int)ft_init_basic_env((__int64 *)&v17 + 1) == -1) )
{
cfree(v5);
v13 = -1;
}
else
{
v15 = _mm_loadu_si128(&v16);
v13 = 0;
if ( (unsigned int)ft_init_terminal_mode(
(char *)&v17 + 8,
argv,
v6,
v7,
v8,
v9,
v15.m128i_i64[0],
v15.m128i_i64[1]) != -1 )
{
v5 = 0LL;
v13 = ft_find_the_line(0LL, 0LL, 0LL, v10, v11, v12, v17);
}
cfree(v5);
}
}
else
{
cfree(v4);
v13 = -1;
}
return v13;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // rdi
const char **v5; // rdi
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
int v13; // ebx
__m128i v15; // [rsp+0h] [rbp-A8h]
__m128i v16; // [rsp+40h] [rbp-68h] BYREF
__int128 v17; // [rsp+80h] [rbp-28h] BYREF
__int64 v18; // [rsp+90h] [rbp-18h]

if ( argc != 1 || !argv )
return -1;
if ( !(unsigned int)ft_check_signal() )
return -1;
v4 = envp;
v18 = ft_copy_ts(envp);
if ( v18 && (v4 = envp, ft_copy_ts(envp)) )
{
v5 = envp;
*(_QWORD *)&v17 = ft_copy_ts(envp);
if ( !(_QWORD)v17 || (v5 = (const char **)&v17 + 1, (unsigned int)func0((__int64 *)&v17 + 1) == -1) )
{
cfree(v5);
v13 = -1;
}
else
{
v15 = _mm_loadu_si128(&v16);
v13 = 0;
if ( (unsigned int)ft_init_terminal_mode(
(char *)&v17 + 8,
argv,
v6,
v7,
v8,
v9,
v15.m128i_i64[0],
v15.m128i_i64[1]) != -1 )
{
v5 = 0LL;
v13 = func1(0LL, 0LL, 0LL, v10, v11, v12, v17);
}
cfree(v5);
}
}
else
{
cfree(v4);
v13 = -1;
}
return v13;
}

original_code:
int main(int ac, char **av, char **env)
{
 t_env e;
 int exit;
 struct termios tattr;
 if (ac != 1 || av == ((void *)0))
  return (-1);
 exit = 0;
 if (!ft_check_signal())
  return (-1);
 if (!(e.envc = ft_copy_ts(env))
  || !(e.env = ft_copy_ts(env)))
 {
  cfree();
  return (-1);
 }
 if (!(e.env = ft_copy_ts(env)) || (ft_init_basic_env(&(e.env_s)) == -1))
 {
  cfree();
  return (-1);
 }
 if (ft_init_terminal_mode(tattr) != -1)
  exit = ft_find_the_line(e, ((void *)0), ((void *)0), ((void *)0));
 cfree();
 return (exit);
}

canonical_original_code:
int main(int ac, char **av, char **env)
{
 struct s_env e;
 int exit;
 struct termios tattr;
 if (ac != 1 || av == ((void *)0))
  return (-1);
 exit = 0;
 if (!ft_check_signal())
  return (-1);
 if (!(e.envc = ft_copy_ts(env))
  || !(e.env = ft_copy_ts(env)))
 {
  cfree();
  return (-1);
 }
 if (!(e.env = ft_copy_ts(env)) || (ft_init_basic_env(&(e.env_s)) == -1))
 {
  cfree();
  return (-1);
 }
 if (ft_init_terminal_mode(tattr) != -1)
  exit = ft_find_the_line(e, ((void *)0), ((void *)0), ((void *)0));
 cfree();
 return (exit);
}

variable_types: ac int

variable_types:
av
char **

variable_types:
env
char **

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

variable_types: exit int

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


decompiled_code:
__int64 __fastcall ft_find(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbx
int v3; // eax
unsigned int v4; // ebp
__int64 v5; // r12

v2 = a1;
v3 = ft_strlen(a2);
if ( !*a1 )
return 0;
v4 = 0;
v5 = v3;
do
v4 += ft_strncmp(v2++, a2, v5) == 0;
while ( *v2 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbx
int v3; // eax
unsigned int v4; // ebp
__int64 v5; // r12

v2 = a1;
v3 = ft_strlen(a2);
if ( !*a1 )
return 0;
v4 = 0;
v5 = v3;
do
v4 += ft_strncmp(v2++, a2, v5) == 0;
while ( *v2 );
return v4;
}

original_code:
int ft_find(char *s1, char *s2)
{
 int i;
 int j;
 int size;
 i = 0;
 j = 0;
 size = ft_strlen(s2);
 while (*(s1 + i))
 {
  if (ft_strncmp(s1 + i, s2, size) == 0)
   ++j;
  ++i;
 }
 return (j);
}

variable_types: i int

variable_types: j int

variable_types: size int


original_code:
static void ft_init(t_save *save)
{
 save->cursor = 0;
 save->hist_nb = 0;
 save->copy = ((void *)0);
}

canonical_original_code:
static void ft_init(struct s_save *save)
{
 save->cursor = 0;
 save->hist_nb = 0;
 save->copy = ((void *)0);
}

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

user_defined_types: struct s_save { int cursor; int co; int hist_nb; struct s_sl *copy; }


decompiled_code:
__int64 __fastcall ft_check(__int64 a1, _QWORD *a2, _DWORD *a3, __int64 a4)
{
unsigned int v6; // ebp
unsigned int v8; // er15
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
char v13[2]; // [rsp+8h] [rbp-40h] BYREF
unsigned __int16 v14; // [rsp+Ah] [rbp-3Eh]

ioctl(0, 0x5413uLL, v13);
a3[1] = v14;
if ( (unsigned int)ft_is_key_enter(a1) )
{
*a3 = -1;
v6 = 0;
}
else
{
v6 = 0;
v8 = (*a3 + 4) / a3[1];
v9 = ft_put_or_del_char(a1, a2, a3, a4);
if ( v9 == -1 )
{
v6 = -1;
}
else
{
if ( !v9 )
goto LABEL_6;
v10 = ft_little_move(a1, a2, a3, (unsigned int)a3[1]);
if ( v10 == -1 )
return (unsigned int)-1;
if ( !v10 )
goto LABEL_6;
v11 = ft_fast_move(a1, a2, a3);
if ( v11 == -1 )
return (unsigned int)-1;
if ( !v11 )
goto LABEL_6;
v12 = ft_move_in_history(a1, a2, a3, a4);
if ( v12 == -1 )
return (unsigned int)-1;
if ( v12 && (unsigned int)ft_cut_copy_or_paste(a1, a2, a3) == -1 )
v6 = -1;
else
LABEL_6:
ft_print(*a2, a3, v8);
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2, _DWORD *a3, __int64 a4)
{
unsigned int v6; // ebp
unsigned int v8; // er15
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
char v13[2]; // [rsp+8h] [rbp-40h] BYREF
unsigned __int16 v14; // [rsp+Ah] [rbp-3Eh]

ioctl(0, 0x5413uLL, v13);
a3[1] = v14;
if ( (unsigned int)ft_is_key_enter(a1) )
{
*a3 = -1;
v6 = 0;
}
else
{
v6 = 0;
v8 = (*a3 + 4) / a3[1];
v9 = ft_put_or_del_char(a1, a2, a3, a4);
if ( v9 == -1 )
{
v6 = -1;
}
else
{
if ( !v9 )
goto LABEL_6;
v10 = ft_little_move(a1, a2, a3, (unsigned int)a3[1]);
if ( v10 == -1 )
return (unsigned int)-1;
if ( !v10 )
goto LABEL_6;
v11 = ft_fast_move(a1, a2, a3);
if ( v11 == -1 )
return (unsigned int)-1;
if ( !v11 )
goto LABEL_6;
v12 = ft_move_in_history(a1, a2, a3, a4);
if ( v12 == -1 )
return (unsigned int)-1;
if ( v12 && (unsigned int)ft_cut_copy_or_paste(a1, a2, a3) == -1 )
v6 = -1;
else
LABEL_6:
ft_print(*a2, a3, v8);
}
}
return v6;
}

original_code:
static int ft_check(char *buf, t_sl **sl, t_save *save, t_hl **hl)
{
 int go;
 struct winsize w;
 int old_line;
 go = 1;
 ioctl(0, 0x5413, &w);
 save->co = w.ws_col;
 if (ft_is_key_enter(buf))
 {
  save->cursor = -1;
  return (0);
 }
 old_line = (4 + save->cursor) / save->co;
 if (go && (go = ft_put_or_del_char(buf, sl, save, hl)) == -1)
  return (-1);
 if (go && (go = ft_little_move(buf, sl, &(save->cursor), save->co)) == -1)
  return (-1);
 if (go && (go = ft_fast_move(buf, sl, &(save->cursor))) == -1)
  return (-1);
 if (go && (go = ft_move_in_history(buf, sl, save, hl)) == -1)
  return (-1);
 if (go && (go = ft_cut_copy_or_paste(buf, sl, save)) == -1)
  return (-1);
 ft_print(*sl, save, old_line);
 return (0);
}

canonical_original_code:
static int ft_check(char *buf, struct s_sl **sl, struct s_save *save, struct s_hl **hl)
{
 int go;
 struct winsize w;
 int old_line;
 go = 1;
 ioctl(0, 0x5413, &w);
 save->co = w.ws_col;
 if (ft_is_key_enter(buf))
 {
  save->cursor = -1;
  return (0);
 }
 old_line = (4 + save->cursor) / save->co;
 if (go && (go = ft_put_or_del_char(buf, sl, save, hl)) == -1)
  return (-1);
 if (go && (go = ft_little_move(buf, sl, &(save->cursor), save->co)) == -1)
  return (-1);
 if (go && (go = ft_fast_move(buf, sl, &(save->cursor))) == -1)
  return (-1);
 if (go && (go = ft_move_in_history(buf, sl, save, hl)) == -1)
  return (-1);
 if (go && (go = ft_cut_copy_or_paste(buf, sl, save)) == -1)
  return (-1);
 ft_print(*sl, save, old_line);
 return (0);
}

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

variable_types: struct s_save { int cursor; int co; int hist_nb; struct s_sl *copy; } *

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

variable_types: go int

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


decompiled_code:
__int64 __fastcall ft_save_cmd_line(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-50h] BYREF
int v4[8]; // [rsp+10h] [rbp-48h] BYREF
__int64 v5; // [rsp+30h] [rbp-28h] BYREF
char buf[31]; // [rsp+39h] [rbp-1Fh] BYREF

v3 = 0LL;
v5 = *a1;
ft_init((__int64)v4);
ft_putstr("_$> ");
while ( v4[0] != -1 )
{
ft_bzero(buf, 7LL);
if ( read(0, buf, 6uLL) == -1 )
return 0xFFFFFFFFLL;
result = ft_check((__int64)buf, &v3, v4, (__int64)&v5);
if ( (_DWORD)result == -1 )
return result;
}
v4[0] = ft_slist_len(v3);
ft_print(v3, v4, (unsigned int)((v4[0] + 4) / v4[1]));
result = ft_update_history(a1, v3);
if ( (_DWORD)result != -1 )
{
ft_slist_to_ts(a2, &v3);
ft_putchar(10LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-50h] BYREF
int v4[8]; // [rsp+10h] [rbp-48h] BYREF
__int64 v5; // [rsp+30h] [rbp-28h] BYREF
char buf[31]; // [rsp+39h] [rbp-1Fh] BYREF

v3 = 0LL;
v5 = *a1;
func0((__int64)v4);
ft_putstr("_$> ");
while ( v4[0] != -1 )
{
ft_bzero(buf, 7LL);
if ( read(0, buf, 6uLL) == -1 )
return 0xFFFFFFFFLL;
result = func1((__int64)buf, &v3, v4, (__int64)&v5);
if ( (_DWORD)result == -1 )
return result;
}
v4[0] = ft_slist_len(v3);
ft_print(v3, v4, (unsigned int)((v4[0] + 4) / v4[1]));
result = ft_update_history(a1, v3);
if ( (_DWORD)result != -1 )
{
ft_slist_to_ts(a2, &v3);
ft_putchar(10LL);
result = 0LL;
}
return result;
}

original_code:
int ft_save_cmd_line(t_hl **hl, char **line)
{
 char buf[6 + 1];
 t_hl *move;
 t_save save;
 t_sl *sl;
 sl = ((void *)0);
 move = *hl;
 ft_init(&save);
 ft_putstr("_$> ");
 while (save.cursor != -1)
 {
  ft_bzero(buf, 6 + 1);
  if (read(0, buf, 6) == -1)
   return (-1);
  if (ft_check(buf, &sl, &save, &move) == -1)
   return (-1);
 }
 save.cursor = ft_slist_len(sl);
 ft_print(sl, &save, (4 + save.cursor) / save.co);
 if (ft_update_history(hl, sl) == -1)
  return (-1);
 ft_slist_to_ts(line, &sl);
 ft_putchar('\n');
 return (0);
}

canonical_original_code:
int ft_save_cmd_line(struct s_hl **hl, char **line)
{
 char buf[-1];
 struct s_hl *move;
 struct s_save save;
 struct s_sl *sl;
 sl = ((void *)0);
 move = *hl;
 ft_init(&save);
 ft_putstr("_$> ");
 while (save.cursor != -1)
 {
  ft_bzero(buf, 6 + 1);
  if (read(0, buf, 6) == -1)
   return (-1);
  if (ft_check(buf, &sl, &save, &move) == -1)
   return (-1);
 }
 save.cursor = ft_slist_len(sl);
 ft_print(sl, &save, (4 + save.cursor) / save.co);
 if (ft_update_history(hl, sl) == -1)
  return (-1);
 ft_slist_to_ts(line, &sl);
 ft_putchar('\n');
 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:
buf
char [-1]

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

user_defined_types: struct s_hl { struct s_sl *hist; struct s_hl *next; struct s_hl *prev; }


decompiled_code:
__int64 __fastcall ft_check_links(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r12
__int64 v4; // rbp

result = sf_check_links();
if ( !(_DWORD)result )
{
v3 = ft_get_name(a1, 45LL, 0LL);
if ( (unsigned int)ft_is_str_a_room(v3, *(_QWORD *)(a2 + 40))
&& (gfree(v3), v4 = ft_get_name(a1, 45LL, 1LL), (unsigned int)ft_is_str_a_room(v4, *(_QWORD *)(a2 + 40))) )
{
gfree(v4);
result = 2LL;
}
else
{
ft_putendl_fd("ERROR", 2LL);
result = 4294967291LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r12
__int64 v4; // rbp

result = sf_check_links();
if ( !(_DWORD)result )
{
v3 = ft_get_name(a1, 45LL, 0LL);
if ( (unsigned int)ft_is_str_a_room(v3, *(_QWORD *)(a2 + 40))
&& (gfree(v3), v4 = ft_get_name(a1, 45LL, 1LL), (unsigned int)ft_is_str_a_room(v4, *(_QWORD *)(a2 + 40))) )
{
gfree(v4);
result = 2LL;
}
else
{
ft_putendl_fd("ERROR", 2LL);
result = 4294967291LL;
}
}
return result;
}

original_code:
static int ft_check_links(char *line, t_game *game)
{
 char *name;
 t_room *tmproom;
 int i;
 if ((i = sf_check_links(line, game)))
  return (i);
 name = ft_get_name(line, '-', 0);
 tmproom = game->tmp_room;
 if (ft_is_str_a_room(name, tmproom))
 {
  gfree(name);
  name = ft_get_name(line, '-', 1);
  tmproom = game->tmp_room;
  if (ft_is_str_a_room(name, tmproom))
  {
   gfree(name);
   return (2);
  }
 }
 ft_putendl_fd("ERROR", 2);
 return (-5);
}

canonical_original_code:
static int ft_check_links(char *line, struct s_game *game)
{
 char *name;
 struct s_room *tmproom;
 int i;
 if ((i = sf_check_links(line, game)))
  return (i);
 name = ft_get_name(line, '-', 0);
 tmproom = game->tmp_room;
 if (ft_is_str_a_room(name, tmproom))
 {
  gfree(name);
  name = ft_get_name(line, '-', 1);
  tmproom = game->tmp_room;
  if (ft_is_str_a_room(name, tmproom))
  {
   gfree(name);
   return (2);
  }
 }
 ft_putendl_fd("ERROR", 2);
 return (-5);
}

variable_types:
line
char *

variable_types: struct s_game { int nb_ant; int i_start; int i_end; char *start; char *end; struct s_room { char *name; int coord_x; int coord_y; struct s_link { char *name; struct s_link *prev; struct s_link *next; } *link; struct s_link *tmp_link; struct s_room *next; } *room; struct s_room *tmp_room; } *

variable_types:
name
char *

user_defined_types: struct s_game { int nb_ant; int i_start; int i_end; char *start; char *end; struct s_room *room; struct s_room *tmp_room; }

user_defined_types: struct s_room { char *name; int coord_x; int coord_y; struct s_link *link; struct s_link *tmp_link; struct s_room *next; }


decompiled_code:
_BOOL8 __fastcall ft_upper_to_int(_BYTE *a1)
{
unsigned __int64 v1; // rdx
_BOOL8 result; // rax
unsigned __int64 v3; // rdx

v1 = ((__int64 (*)(void))ft_strlen)();
result = 1LL;
if ( v1 <= 0xA )
{
v3 = ft_strlen(a1);
result = 0LL;
if ( v3 > 8 )
{
result = 1LL;
if ( *a1 == 50 )
result = (int)ft_atoi(a1 + 1) > 147483647;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_BYTE *a1)
{
unsigned __int64 v1; // rdx
_BOOL8 result; // rax
unsigned __int64 v3; // rdx

v1 = ((__int64 (*)(void))ft_strlen)();
result = 1LL;
if ( v1 <= 0xA )
{
v3 = ft_strlen(a1);
result = 0LL;
if ( v3 > 8 )
{
result = 1LL;
if ( *a1 == 50 )
result = (int)ft_atoi(a1 + 1) > 147483647;
}
}
return result;
}

original_code:
int ft_upper_to_int(char *line)
{
 int nb;
 nb = 0;
 if (ft_strlen(line) > 10)
  return (1);
 if (ft_strlen(line) < 9)
  return (0);
 else if (line[0] == '2')
 {
  nb = ft_atoi(line + 1);
  if (nb > 147483647)
   return (1);
  else
   return (0);
 }
 else
  return (1);
}

variable_types: nb int


decompiled_code:
__int64 __fastcall ft_check_line(unsigned int a1, _BYTE *a2, __int64 a3)
{
unsigned int v3; // ebx

v3 = a1;
if ( a1 )
{
if ( a1 == 1 )
v3 = ft_check_coords(1u, a2, a3);
if ( v3 == 2 )
v3 = ft_check_links((__int64)a2, a3);
}
else if ( *a2 == 45 || ft_upper_to_int(a2) || !(unsigned int)is_number(a2) || *a2 == 48 )
{
ft_putendl_fd("ERROR", 2LL);
cfree("ERROR");
exit(0);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, _BYTE *a2, __int64 a3)
{
unsigned int v3; // ebx

v3 = a1;
if ( a1 )
{
if ( a1 == 1 )
v3 = func0(1u, a2, a3);
if ( v3 == 2 )
v3 = func1((__int64)a2, a3);
}
else if ( *a2 == 45 || func2(a2) || !(unsigned int)is_number(a2) || *a2 == 48 )
{
ft_putendl_fd("ERROR", 2LL);
cfree("ERROR");
exit(0);
}
return v3;
}

original_code:
int ft_check_line(int index, char *line, t_game *game)
{
 if (index == 0)
 {
  if (*line == '-' || ft_upper_to_int(line) == 1
   || !(is_number(line)) || *line == '0')
  {
   ft_putendl_fd("ERROR", 2);
   cfree();
   exit(0);
  }
  return (0);
 }
 if (index == 1)
  index = ft_check_coords(index, line, game);
 if (index == 2)
  index = ft_check_links(line, game);
 return (index);
}

canonical_original_code:
int ft_check_line(int index, char *line, struct s_game *game)
{
 if (index == 0)
 {
  if (*line == '-' || ft_upper_to_int(line) == 1
   || !(is_number(line)) || *line == '0')
  {
   ft_putendl_fd("ERROR", 2);
   cfree();
   exit(0);
  }
  return (0);
 }
 if (index == 1)
  index = ft_check_coords(index, line, game);
 if (index == 2)
  index = ft_check_links(line, game);
 return (index);
}

variable_types: index int

user_defined_types: struct s_link { char *name; struct s_link *prev; struct s_link *next; }


decompiled_code:
char **__fastcall ft_syst_bin(char **argv, char **envp)
{
char **v2; // rbx
const char *v3; // rbp
__pid_t v4; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = envp;
v3 = ft_good_path(argv, envp);
if ( !v3 )
return 0LL;
v4 = fork();
LODWORD(stat_loc.__uptr) = v4;
if ( v4 > 0 )
{
wait((__WAIT_STATUS)&stat_loc);
}
else if ( !v4 && execve(v3, argv, envp) == -1 )
{
ft_putendl("command not found");
exit(-1);
}
return v2;
}

canonical_decompiled_code:
char **__fastcall func2(char **argv, char **envp)
{
char **v2; // rbx
const char *v3; // rbp
__pid_t v4; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = envp;
v3 = func1(argv, envp);
if ( !v3 )
return 0LL;
v4 = fork();
LODWORD(stat_loc.__uptr) = v4;
if ( v4 > 0 )
{
wait((__WAIT_STATUS)&stat_loc);
}
else if ( !v4 && execve(v3, argv, envp) == -1 )
{
ft_putendl("command not found");
exit(-1);
}
return v2;
}

original_code:
char **ft_syst_bin(char **all, char **env)
{
 int father;
 char *path;
 if (!(path = ft_good_path(all, env)))
  return (((void *)0));
 if ((father = fork()) > 0)
 {
  wait(&father);
  return (env);
 }
 else if (father == 0)
 {
  if (execve(path, all, env) == -1)
  {
   ft_putendl("command not found");
   exit(-1);
  }
 }
 return (env);
}

variable_types:
all
char **

variable_types:
env
char **

variable_types: father int

variable_types:
path
char *

return_type: char **


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);
if ( !v1 )
break;
}
v3 = *++v2;
}
while ( *v2 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(_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);
if ( !v1 )
break;
}
v3 = *++v2;
}
while ( *v2 );
}
return v1;
}

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

variable_types: i int

variable_types:
paths
char **


decompiled_code:
const char *__fastcall ft_good_path(_QWORD *a1, _QWORD *a2)
{
_QWORD *v2; // rbp
struct stat *v3; // r12
__int64 v4; // rax
const char *v5; // rbx
__int64 v6; // r14

v2 = (_QWORD *)ft_find_paths_in_env(a2);
if ( !v2 )
return 0LL;
v3 = (struct stat *)gmalloc(144LL);
if ( !v3 )
return 0LL;
if ( !*v2 )
return (const char *)*a1;
while ( 1 )
{
v4 = ft_strlen();
v5 = (const char *)gmalloc(v4 + 1);
if ( !v5 )
break;
v6 = ft_strjoin(*v2, "/");
v5 = (const char *)ft_strjoin(v6, *a1);
gofree(v6);
if ( !lstat(v5, v3) )
break;
if ( !*++v2 )
return (const char *)*a1;
}
return v5;
}

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

v2 = (_QWORD *)func0(a2);
if ( !v2 )
return 0LL;
v3 = (struct stat *)gmalloc(144LL);
if ( !v3 )
return 0LL;
if ( !*v2 )
return (const char *)*a1;
while ( 1 )
{
v4 = ft_strlen();
v5 = (const char *)gmalloc(v4 + 1);
if ( !v5 )
break;
v6 = ft_strjoin(*v2, "/");
v5 = (const char *)ft_strjoin(v6, *a1);
gofree(v6);
if ( !lstat(v5, v3) )
break;
if ( !*++v2 )
return (const char *)*a1;
}
return v5;
}

original_code:
static char *ft_good_path(char **all, char **env)
{
 int i;
 char *tmp;
 char *str;
 char **paths;
 struct stat *buf;
 if (!(paths = ft_find_paths_in_env(env)))
  return (((void *)0));
 if (!(buf = (struct stat *)gmalloc(sizeof(*buf))))
  return (((void *)0));
 i = 0;
 while (paths[i])
 {
  if (!(str = (char *)gmalloc(sizeof(*str) * ft_strlen(paths[i]) + 1)))
   return (((void *)0));
  tmp = ft_strjoin(paths[i], "/");
  str = ft_strjoin(tmp, all[0]);
  gofree((void *)tmp);
  if (lstat(str, buf) == 0)
   return (str);
  ++i;
 }
 return (all[0]);
}

variable_types:
tmp
char *

variable_types:
str
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]; }


variable_types: c char

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


original_code:
static void ft_print_mode(struct stat *p_stat)
{
 if (0170000 & 0010000 & p_stat->st_mode)
  ft_putchar('p');
 else if (0020000 & p_stat->st_mode)
  ft_putchar('c');
 else if (0040000 & p_stat->st_mode)
  ft_putchar('d');
 else if (0060000 & p_stat->st_mode)
  ft_putchar('b');
 else if (0100000 & p_stat->st_mode)
  ft_putchar('-');
 else if (0120000 & p_stat->st_mode)
  ft_putchar('l');
 else if (0140000 & p_stat->st_mode)
  ft_putchar('s');
 ft_print_rights(p_stat);
}


decompiled_code:
int __fastcall ft_total(__int64 a1, struct stat *a2)
{
__int64 v2; // rbx
__int64 v3; // r12
int result; // eax

v2 = a1;
ft_putstr("total ");
if ( a1 )
{
v3 = 0LL;
while ( 1 )
{
result = lstat(*(const char **)v2, a2);
if ( result == -1 )
break;
v3 += a2->st_blocks;
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_5;
}
}
else
{
LODWORD(v3) = 0;
LABEL_5:
result = v3;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, struct stat *a2)
{
__int64 v2; // rbx
__int64 v3; // r12
int result; // eax

v2 = a1;
ft_putstr("total ");
if ( a1 )
{
v3 = 0LL;
while ( 1 )
{
result = lstat(*(const char **)v2, a2);
if ( result == -1 )
break;
v3 += a2->st_blocks;
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_5;
}
}
else
{
LODWORD(v3) = 0;
LABEL_5:
result = v3;
}
return result;
}

original_code:
static int ft_total(t_ls *list, struct stat *p_stat)
{
 blkcnt_t block_size;
 block_size = 0;
 ft_putstr("total ");
 while (list != ((void *)0))
 {
  if (lstat(list->name, p_stat) == -1)
   return (-1);
  block_size += p_stat->st_blocks;
  list = list->next;
 }
 return (block_size);
}

canonical_original_code:
static int ft_total(struct s_ls *list, struct stat *p_stat)
{
 long block_size;
 block_size = 0;
 ft_putstr("total ");
 while (list != ((void *)0))
 {
  if (lstat(list->name, p_stat) == -1)
   return (-1);
  block_size += p_stat->st_blocks;
  list = list->next;
 }
 return (block_size);
}

variable_types: struct s_ls { char *name; long time; struct s_ls *next; } *


decompiled_code:
__int64 __fastcall ft_ls_l_print_info(__int64 a1)
{
struct passwd *v1; // r12
struct group *v2; // rbp
char *v3; // rax
__int64 v4; // rax

if ( !malloc(0x30uLL) )
return 0xFFFFFFFFLL;
if ( !malloc(0x20uLL) )
return 0xFFFFFFFFLL;
v1 = getpwuid(*(_DWORD *)(a1 + 28));
v2 = getgrgid(*(_DWORD *)(a1 + 32));
ft_print_mode(a1);
ft_putstr(" ");
ft_putnbr(*(unsigned int *)(a1 + 16));
ft_putchar(9LL);
ft_putstr(v1->pw_name);
ft_putstr(" ");
ft_putstr(v2->gr_name);
ft_putstr(" ");
ft_putnbr(*(unsigned int *)(a1 + 48));
ft_putstr("\t");
v3 = ctime((const time_t *)(a1 + 88));
v4 = ft_strsub(v3, 4LL, 12LL);
ft_putstr(v4);
ft_putstr(" ");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
struct passwd *v1; // r12
struct group *v2; // rbp
char *v3; // rax
__int64 v4; // rax

if ( !malloc(0x30uLL) )
return 0xFFFFFFFFLL;
if ( !malloc(0x20uLL) )
return 0xFFFFFFFFLL;
v1 = getpwuid(*(_DWORD *)(a1 + 28));
v2 = getgrgid(*(_DWORD *)(a1 + 32));
func1(a1);
ft_putstr(" ");
ft_putnbr(*(unsigned int *)(a1 + 16));
ft_putchar(9LL);
ft_putstr(v1->pw_name);
ft_putstr(" ");
ft_putstr(v2->gr_name);
ft_putstr(" ");
ft_putnbr(*(unsigned int *)(a1 + 48));
ft_putstr("\t");
v3 = ctime((const time_t *)(a1 + 88));
v4 = ft_strsub(v3, 4LL, 12LL);
ft_putstr(v4);
ft_putstr(" ");
return 1LL;
}

original_code:
static int ft_ls_l_print_info(struct stat *p_stat)
{
 struct passwd *p_pwd;
 struct group *p_group;
 if (!(p_pwd = (struct passwd *)malloc(sizeof(*p_pwd))))
  return (-1);
 if (!(p_group = (struct group *)malloc(sizeof(*p_group))))
  return (-1);
 p_pwd = getpwuid(p_stat->st_uid);
 p_group = getgrgid(p_stat->st_gid);
 ft_print_mode(p_stat);
 ft_putstr("  ");
 ft_putnbr(p_stat->st_nlink);
 ft_putchar('\t');
 ft_putstr(p_pwd->pw_name);
 ft_putstr("  ");
 ft_putstr(p_group->gr_name);
 ft_putstr("  ");
 ft_putnbr(p_stat->st_size);
 ft_putstr("\t");
 ft_putstr(ft_strsub(ctime(&p_stat->st_mtim.tv_sec), 4, 12));
 ft_putstr(" ");
 return (1);
}

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *


decompiled_code:
int __fastcall ft_ls_l(__int64 a1)
{
_QWORD *v1; // rbx
struct stat *v2; // rax
struct stat *v3; // rbp
unsigned int v4; // eax
int result; // eax

v1 = (_QWORD *)a1;
v2 = (struct stat *)malloc(0x90uLL);
if ( !v2 )
return -1;
v3 = v2;
v4 = ft_total(a1, v2);
ft_putnbr(v4);
ft_putchar(10LL);
if ( !a1 )
return 1;
while ( 1 )
{
result = lstat((const char *)*v1, v3);
if ( result == -1 )
break;
result = ft_ls_l_print_info((__int64)v3);
if ( result == -1 )
break;
ft_putendl(*v1);
v1 = (_QWORD *)v1[2];
if ( !v1 )
return 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
_QWORD *v1; // rbx
struct stat *v2; // rax
struct stat *v3; // rbp
unsigned int v4; // eax
int result; // eax

v1 = (_QWORD *)a1;
v2 = (struct stat *)malloc(0x90uLL);
if ( !v2 )
return -1;
v3 = v2;
v4 = func2(a1, v2);
ft_putnbr(v4);
ft_putchar(10LL);
if ( !a1 )
return 1;
while ( 1 )
{
result = lstat((const char *)*v1, v3);
if ( result == -1 )
break;
result = func3((__int64)v3);
if ( result == -1 )
break;
ft_putendl(*v1);
v1 = (_QWORD *)v1[2];
if ( !v1 )
return 1;
}
return result;
}

original_code:
int ft_ls_l(t_ls *list)
{
 struct stat *p_stat;
 if (!(p_stat = (struct stat *)malloc(sizeof(*p_stat))))
  return (-1);
 ft_putnbr(ft_total(list, p_stat));
 ft_putchar('\n');
 while (list != ((void *)0))
 {
  if (lstat(list->name, p_stat) == -1)
   return (-1);
  if (ft_ls_l_print_info(p_stat) == -1)
   return (-1);
  ft_putendl(list->name);
  list = list->next;
 }
 return (1);
}

canonical_original_code:
int ft_ls_l(struct s_ls *list)
{
 struct stat *p_stat;
 if (!(p_stat = (struct stat *)malloc(sizeof(*p_stat))))
  return (-1);
 ft_putnbr(ft_total(list, p_stat));
 ft_putchar('\n');
 while (list != ((void *)0))
 {
  if (lstat(list->name, p_stat) == -1)
   return (-1);
  if (ft_ls_l_print_info(p_stat) == -1)
   return (-1);
  ft_putendl(list->name);
  list = list->next;
 }
 return (1);
}

user_defined_types: struct s_ls { char *name; long time; struct s_ls *next; }


original_code:
int ft_intersect_a_cylinder(t_r *r, void *data)
{
 t_cyl *cyl;
 t_r new_r;
 t_v coeff;
 cyl = (t_cyl *)data;
 new_r = *r;
 ft_vect_difference(&new_r.o_w, r->o_w, cyl->c);
 ft_find_coeff(&new_r, &coeff, cyl);
 if (ft_nearest_solution(coeff.x, coeff.y, coeff.z, &new_r) == -1)
  return (-1);
 r->t0 = new_r.t0;
 r->t1 = new_r.t1;
 if (r->t1 < 0)
  return (-1);
 if (r->t0 < 0)
  r->t0 = r->t1;
 return (0);
}

canonical_original_code:
int ft_intersect_a_cylinder(struct s_r *r, void *data)
{
 struct s_cyl *cyl;
 struct s_r new_r;
 struct s_v coeff;
 cyl = (struct s_cyl *)data;
 new_r = *r;
 ft_vect_difference(&new_r.o_w, r->o_w, cyl->c);
 ft_find_coeff(&new_r, &coeff, cyl);
 if (ft_nearest_solution(coeff.x, coeff.y, coeff.z, &new_r) == -1)
  return (-1);
 r->t0 = new_r.t0;
 r->t1 = new_r.t1;
 if (r->t1 < 0)
  return (-1);
 if (r->t0 < 0)
  r->t0 = r->t1;
 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: struct s_cyl { struct s_v { double x; double y; double z; } c; double r; struct s_c { int b; int g; int r; } sf; char flag; } *

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_cyl { struct s_v c; double r; struct s_c sf; char flag; }


variable_types:
c
struct s_v *

variable_types: struct s_cyl { struct s_v c; double r; struct s_c sf; char flag; } *

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


decompiled_code:
__int64 __fastcall ft_new_token(__int64 *a1, _QWORD *a2, int a3, int a4)
{
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // rax
__int64 result; // rax
__int64 v10; // rdx

v6 = gmalloc(32LL);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
v8 = ft_strsub(*a2, 0LL, a3);
*(_QWORD *)v7 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
*a2 += a3;
*(_DWORD *)(v7 + 8) = a4;
*(_QWORD *)(v7 + 16) = 0LL;
*(_QWORD *)(v7 + 24) = 0LL;
result = *a1;
if ( *a1 )
{
do
{
v10 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v7 + 24) = v10;
*(_QWORD *)(v10 + 16) = v7;
}
else
{
*a1 = v7;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, _QWORD *a2, int a3, int a4)
{
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // rax
__int64 result; // rax
__int64 v10; // rdx

v6 = gmalloc(32LL);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
v8 = ft_strsub(*a2, 0LL, a3);
*(_QWORD *)v7 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
*a2 += a3;
*(_DWORD *)(v7 + 8) = a4;
*(_QWORD *)(v7 + 16) = 0LL;
*(_QWORD *)(v7 + 24) = 0LL;
result = *a1;
if ( *a1 )
{
do
{
v10 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v7 + 24) = v10;
*(_QWORD *)(v10 + 16) = v7;
}
else
{
*a1 = v7;
result = 0LL;
}
return result;
}

original_code:
int ft_new_token(t_p **p, char **line, int size, int type)
{
 t_p *new;
 t_p *move;
 if (!(new = (t_p *)gmalloc(sizeof(t_p))))
  return (-1);
 if (!(new->tok = ft_strsub(*line, 0, size)))
  return (-1);
 *line = *line + size;
 new->type = type;
 new->next = ((void *)0);
 new->prev = ((void *)0);
 move = *p;
 if (*p)
 {
  while (move->next)
   move = move->next;
  new->prev = move;
  move->next = new;
 }
 else
  *p = new;
 return (0);
}

canonical_original_code:
int ft_new_token(struct s_p **p, char **line, int size, int type)
{
 struct s_p *new;
 struct s_p *move;
 if (!(new = (struct s_p *)gmalloc(sizeof(t_p))))
  return (-1);
 if (!(new->tok = ft_strsub(*line, 0, size)))
  return (-1);
 *line = *line + size;
 new->type = type;
 new->next = ((void *)0);
 new->prev = ((void *)0);
 move = *p;
 if (*p)
 {
  while (move->next)
   move = move->next;
  new->prev = move;
  move->next = new;
 }
 else
  *p = new;
 return (0);
}

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

variable_types:
line
char **

variable_types: size int

variable_types: type int


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

for ( result = *a1; result; result = *(_QWORD *)(result + 16) )
{
if ( *(_DWORD *)(result + 8) == 11 )
{
v2 = *(_QWORD *)(result + 24);
if ( v2 )
*(_DWORD *)(result + 8) = ((unsigned int)(*(_DWORD *)(v2 + 8) - 8) < 6) + 12;
else
*(_DWORD *)(result + 8) = 12;
}
}
return result;
}

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

for ( result = *a1; result; result = *(_QWORD *)(result + 16) )
{
if ( *(_DWORD *)(result + 8) == 11 )
{
v2 = *(_QWORD *)(result + 24);
if ( v2 )
*(_DWORD *)(result + 8) = ((unsigned int)(*(_DWORD *)(v2 + 8) - 8) < 6) + 12;
else
*(_DWORD *)(result + 8) = 12;
}
}
return result;
}

original_code:
void ft_differentiate_word_types(t_p **p)
{
 t_p *move;
 move = *p;
 while (move)
 {
  if (move->type == 11)
  {
   if (!move->prev)
    move->type = 12;
   else if (move->prev->type == 11 || move->prev->type == 8
     || move->prev->type == 9 || move->prev->type == 10
     || move->prev->type == 12 || move->prev->type == 13)
    move->type = 13;
   else
    move->type = 12;
  }
  move = move->next;
 }
}

canonical_original_code:
void ft_differentiate_word_types(struct s_p **p)
{
 struct s_p *move;
 move = *p;
 while (move)
 {
  if (move->type == 11)
  {
   if (!move->prev)
    move->type = 12;
   else if (move->prev->type == 11 || move->prev->type == 8
     || move->prev->type == 9 || move->prev->type == 10
     || move->prev->type == 12 || move->prev->type == 13)
    move->type = 13;
   else
    move->type = 12;
  }
  move = move->next;
 }
}

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


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

result = ft_delete_quotes_and_spaces();
if ( (_DWORD)result != -1 )
{
result = ft_delete_backslashes(a1);
if ( (_DWORD)result != -1 )
{
result = ft_check_wrong_nb_of_pth(*a1);
if ( (_DWORD)result != -1 )
{
ft_differentiate_word_types(a1);
result = 0LL;
}
}
}
return result;
}

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

result = ft_delete_quotes_and_spaces();
if ( (_DWORD)result != -1 )
{
result = ft_delete_backslashes(a1);
if ( (_DWORD)result != -1 )
{
result = ft_check_wrong_nb_of_pth(*a1);
if ( (_DWORD)result != -1 )
{
func1(a1);
result = 0LL;
}
}
}
return result;
}

original_code:
int ft_clean_list(t_p **p, int ind)
{
 if (ft_delete_quotes_and_spaces(p, ind) == -1)
  return (-1);
 if (ft_delete_backslashes(p) == -1)
  return (-1);
 if (ft_check_wrong_nb_of_pth(*p) == -1)
  return (-1);
 ft_differentiate_word_types(p);
 return (0);
}

canonical_original_code:
int ft_clean_list(struct s_p **p, int ind)
{
 if (ft_delete_quotes_and_spaces(p, ind) == -1)
  return (-1);
 if (ft_delete_backslashes(p) == -1)
  return (-1);
 if (ft_check_wrong_nb_of_pth(*p) == -1)
  return (-1);
 ft_differentiate_word_types(p);
 return (0);
}

variable_types: ind int

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


decompiled_code:
__int64 __fastcall ft_lexical_analyzer(__int64 a1, __int64 *a2)
{
int v3; // edx
int v4; // eax
__int64 v5[2]; // [rsp+8h] [rbp-20h] BYREF
int v6; // [rsp+18h] [rbp-10h] BYREF
int v7[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v5[0] = a1;
v7[0] = 0;
while ( *(_BYTE *)v5[0] )
{
v4 = ft_word_size_before_ope(a1, v7, &v6);
if ( v4 )
ft_new_token(a2, v5, v4, 11);
if ( !*(_BYTE *)v5[0] )
break;
if ( (unsigned int)(v6 - 5) > 1 )
{
v3 = 1;
if ( v6 != 9 )
continue;
}
v3 = 2;
ft_new_token(a2, v5, v3, v6);
a1 = v5[0];
}
return (unsigned int)-((unsigned int)ft_clean_list(a2) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 *a2)
{
int v3; // edx
int v4; // eax
__int64 v5[2]; // [rsp+8h] [rbp-20h] BYREF
int v6; // [rsp+18h] [rbp-10h] BYREF
int v7[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v5[0] = a1;
v7[0] = 0;
while ( *(_BYTE *)v5[0] )
{
v4 = ft_word_size_before_ope(a1, v7, &v6);
if ( v4 )
func0(a2, v5, v4, 11);
if ( !*(_BYTE *)v5[0] )
break;
if ( (unsigned int)(v6 - 5) > 1 )
{
v3 = 1;
if ( v6 != 9 )
continue;
}
v3 = 2;
func0(a2, v5, v3, v6);
a1 = v5[0];
}
return (unsigned int)-((unsigned int)func2(a2) == -1);
}

original_code:
int ft_lexical_analyzer(char *line, t_p **p)
{
 int ind;
 int type;
 int size;
 ind = 0;
 while (*line)
 {
  size = ft_word_size_before_ope(line, &ind, &type);
  if (size != 0)
   ft_new_token(p, &line, size, 11);
  if (!*line)
   break ;
  size = (type == 5 || type == 6 || type == 9) ? 2 : 1;
  ft_new_token(p, &line, size, type);
 }
 if (ft_clean_list(p, ind) == -1)
  return (-1);
 return (0);
}

canonical_original_code:
int ft_lexical_analyzer(char *line, struct s_p **p)
{
 int ind;
 int type;
 int size;
 ind = 0;
 while (*line)
 {
  size = ft_word_size_before_ope(line, &ind, &type);
  if (size != 0)
   ft_new_token(p, &line, size, 11);
  if (!*line)
   break ;
  size = (type == 5 || type == 6 || type == 9) ? 2 : 1;
  ft_new_token(p, &line, size, type);
 }
 if (ft_clean_list(p, ind) == -1)
  return (-1);
 return (0);
}

variable_types:
line
char *


decompiled_code:
__int64 __fastcall ft_grid_is_full(char **a1)
{
char *v1; // rax
_BYTE **v2; // rcx
char v3; // dl
char *v4; // rax
__int64 result; // rax

v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
while ( 1 )
{
v3 = *v1;
v4 = v1 + 1;
if ( v3 )
break;
LABEL_6:
v1 = *v2++;
if ( !v1 )
goto LABEL_7;
}
while ( v3 != 46 )
{
v3 = *v4++;
if ( !v3 )
goto LABEL_6;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_7:
ft_putendl("\n*** DRAW GAME ***\n");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char **a1)
{
char *v1; // rax
_BYTE **v2; // rcx
char v3; // dl
char *v4; // rax
__int64 result; // rax

v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
while ( 1 )
{
v3 = *v1;
v4 = v1 + 1;
if ( v3 )
break;
LABEL_6:
v1 = *v2++;
if ( !v1 )
goto LABEL_7;
}
while ( v3 != 46 )
{
v3 = *v4++;
if ( !v3 )
goto LABEL_6;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_7:
ft_putendl("\n*** DRAW GAME ***\n");
result = 0LL;
}
return result;
}

original_code:
static int ft_grid_is_full(char **grid)
{
 int i;
 int j;
 i = 0;
 while (grid[i])
 {
  j = 0;
  while (grid[i][j])
  {
   if (grid[i][j] == '.')
    return (-1);
   ++j;
  }
  ++i;
 }
 ft_putendl("\n***  DRAW GAME  ***\n");
 return (0);
}

variable_types:
grid
char **

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall ft_init_turn(__int64 a1, __int64 a2)
{
void *v2; // rax
void *v3; // rax
unsigned int v4; // eax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(0x10uLL);
*(_QWORD *)(a1 + 8) = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = malloc(0x10uLL);
*(_QWORD *)(a2 + 8) = v3;
if ( !v3 )
return 0xFFFFFFFFLL;
*(_BYTE *)(a1 + 16) = 88;
*(_BYTE *)(a1 + 17) = 79;
*(_BYTE *)(a2 + 16) = 79;
*(_BYTE *)(a2 + 17) = 88;
v4 = time(&timer);
srand(v4);
return (unsigned int)(rand() % 2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
void *v2; // rax
void *v3; // rax
unsigned int v4; // eax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(0x10uLL);
*(_QWORD *)(a1 + 8) = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = malloc(0x10uLL);
*(_QWORD *)(a2 + 8) = v3;
if ( !v3 )
return 0xFFFFFFFFLL;
*(_BYTE *)(a1 + 16) = 88;
*(_BYTE *)(a1 + 17) = 79;
*(_BYTE *)(a2 + 16) = 79;
*(_BYTE *)(a2 + 17) = 88;
v4 = time(&timer);
srand(v4);
return (unsigned int)(rand() % 2);
}

original_code:
static int ft_init_turn(t_s *me, t_s *you)
{
 time_t tloc;
 int turn;
 if (!((*me).save = (int *)malloc(sizeof(int) * 4)))
  return (-1);
 if (!((*you).save = (int *)malloc(sizeof(int) * 4)))
  return (-1);
 (*me).symb1 = 'X';
 (*me).symb2 = 'O';
 (*you).symb1 = 'O';
 (*you).symb2 = 'X';
 srand(time(&tloc));
 turn = rand() % 2;
 return (turn);
}

canonical_original_code:
static int ft_init_turn(struct s_s *me, struct s_s *you)
{
 long tloc;
 int turn;
 if (!((*me).save = (int *)malloc(sizeof(int) * 4)))
  return (-1);
 if (!((*you).save = (int *)malloc(sizeof(int) * 4)))
  return (-1);
 (*me).symb1 = 'X';
 (*me).symb2 = 'O';
 (*you).symb1 = 'O';
 (*you).symb2 = 'X';
 srand(time(&tloc));
 turn = rand() % 2;
 return (turn);
}

variable_types: struct s_s { int *choices; int *save; char symb1; char symb2; int keep; } *

variable_types:
you
struct s_s *

variable_types: tloc long

variable_types: turn int


decompiled_code:
__int64 __fastcall ft_play_the_game(__int64 a1, _QWORD *a2, __int64 a3)
{
__int64 result; // rax
_BOOL4 v7; // er12
__int64 v8; // rsi
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
__int64 v13; // rdx
char **v14; // rdi
__int64 v15; // rdx
__int64 v16; // rcx
__int64 v17; // r8
__int64 v18; // r9
__int64 v19; // rdx
__int64 v20; // rcx
__int64 v21; // r8
__int64 v22; // r9

result = ft_init_turn((__int64)a2, a3);
v7 = result;
if ( (_DWORD)result != -1 )
{
while ( 1 )
{
v8 = a3;
if ( (unsigned int)ft_won(a2, a3) != -1 )
break;
v14 = *(char ***)a1;
if ( (unsigned int)ft_grid_is_full(*(char ***)a1) != -1 )
return 0LL;
if ( v7 )
{
v8 = a3;
ft_update_grid_of_choices(a2, a3);
ft_play_a_piece((_QWORD *)a1, a3, v9, v10, v11, v12, *a2, a2[1], a2[2]);
}
else
{
result = ft_choose_where_to_play((__int64)v14, a3, v15, v16, v17, v18, *(_QWORD *)a1, *(_QWORD *)(a1 + 8));
*(_DWORD *)(a3 + 20) = result;
if ( (_DWORD)result == -1 )
return result;
ft_play_a_piece((_QWORD *)a1, a3, v19, v20, v21, v22, *(_QWORD *)a3, *(_QWORD *)(a3 + 8), *(_QWORD *)(a3 + 16));
}
ft_putendl("\n");
ft_print_grid("\n", v8, v13);
v7 = !v7;
}
result = 0LL;
}
return result;
}

original_code:
int ft_play_the_game(t_all *a, t_s *me, t_s *you)
{
 int turn;
 if ((turn = ft_init_turn(me, you)) == -1)
  return (-1);
 while (ft_won(*a, me, you) == -1 && ft_grid_is_full((*a).grid) == -1)
 {
  if (turn == 0)
  {
   if (((*you).keep = ft_choose_where_to_play(*a)) == -1)
    return (-1);
   ft_play_a_piece(a, *you);
  }
  else
  {
   ft_update_grid_of_choices(*a, me, you);
   ft_play_a_piece(a, *me);
  }
  ft_putendl("\n");
  ft_print_grid(*a);
  turn = (turn == 0 ? 1 : 0);
 }
 return (0);
}

canonical_original_code:
int ft_play_the_game(struct s_all *a, struct s_s *me, struct s_s *you)
{
 int turn;
 if ((turn = ft_init_turn(me, you)) == -1)
  return (-1);
 while (ft_won(*a, me, you) == -1 && ft_grid_is_full((*a).grid) == -1)
 {
  if (turn == 0)
  {
   if (((*you).keep = ft_choose_where_to_play(*a)) == -1)
    return (-1);
   ft_play_a_piece(a, *you);
  }
  else
  {
   ft_update_grid_of_choices(*a, me, you);
   ft_play_a_piece(a, *me);
  }
  ft_putendl("\n");
  ft_print_grid(*a);
  turn = (turn == 0 ? 1 : 0);
 }
 return (0);
}

variable_types: struct s_all { char **grid; int li; int co; int i; int j; } *

user_defined_types: struct s_s { int *choices; int *save; char symb1; char symb2; int keep; }


decompiled_code:
void *ft_set_fov_angle()
{
return &fov_0;
}

canonical_decompiled_code:
void *func0()
{
return &fov_0;
}

original_code:
double *ft_set_fov_angle(void)
{
 static double fov = 3.14159265358979323846 * 60 / 180;
 return (&fov);
}

canonical_original_code:
double *ft_set_fov_angle()
{
 static double fov = 3.14159265358979323846 * 60 / 180;
 return (&fov);
}

variable_types: fov double

return_type: double *


original_code:
void ft_init_camera(t_cam *cam)
{
 ft_init_vect(&cam->b.vx, 1, 0, 0);
 ft_init_vect(&cam->b.vy, 0, 1, 0);
 ft_init_vect(&cam->b.vz, 0, 0, 1);
 ft_init_vect(&cam->ro, 0, 0, 0);
 ft_init_vect(&cam->rp, 0, 0, 0);
 ft_init_vect(&cam->trans, 0, 0, 0);
}

canonical_original_code:
void ft_init_camera(struct s_cam *cam)
{
 ft_init_vect(&cam->b.vx, 1, 0, 0);
 ft_init_vect(&cam->b.vy, 0, 1, 0);
 ft_init_vect(&cam->b.vz, 0, 0, 1);
 ft_init_vect(&cam->ro, 0, 0, 0);
 ft_init_vect(&cam->rp, 0, 0, 0);
 ft_init_vect(&cam->trans, 0, 0, 0);
}

variable_types: struct s_cam { struct s_b { struct s_v { double x; double y; double z; } vx; struct s_v vy; struct s_v vz; } b; struct s_v trans; struct s_v ro; struct s_v rp; } *

user_defined_types: struct s_cam { struct s_b b; struct s_v trans; struct s_v ro; struct s_v rp; }

user_defined_types: struct s_b { struct s_v vx; struct s_v vy; struct s_v vz; }


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

variable_types: ratio double


decompiled_code:
__int64 __fastcall ft_a_before_send2(__int64 *a1, _DWORD *a2)
{
unsigned int v2; // ebp
__int64 v3; // rax

if ( *(_DWORD *)*a1 == *a2 )
return 0;
do
{
v3 = ft_swap_rr();
*a1 = v3;
if ( !a1[1] )
{
v2 = ft_sort1(v3);
if ( v2 == 1 )
{
ft_putstr("rra\n");
return v2;
}
}
ft_putstr("rra ");
}
while ( *(_DWORD *)*a1 != *a2 );
return 0;
}

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

if ( *(_DWORD *)*a1 == *a2 )
return 0;
do
{
v3 = ft_swap_rr();
*a1 = v3;
if ( !a1[1] )
{
v2 = ft_sort1(v3);
if ( v2 == 1 )
{
ft_putstr("rra\n");
return v2;
}
}
ft_putstr("rra ");
}
while ( *(_DWORD *)*a1 != *a2 );
return 0;
}

original_code:
static int ft_a_before_send2(t_push *list, t_min *min)
{
 int i;
 i = 0;
 while ((list->a)->nb != min->min)
 {
  list->a = ft_swap_rr(list->a);
  if (!list->b && ft_sort1(list->a) == 1)
  {
   ft_putstr("rra\n");
   return (1);
  }
  else
   ft_putstr("rra ");
 }
 return (0);
}

canonical_original_code:
static int ft_a_before_send2(struct s_push *list, struct s_min *min)
{
 int i;
 i = 0;
 while ((list->a)->nb != min->min)
 {
  list->a = ft_swap_rr(list->a);
  if (!list->b && ft_sort1(list->a) == 1)
  {
   ft_putstr("rra\n");
   return (1);
  }
  else
   ft_putstr("rra ");
 }
 return (0);
}

variable_types: struct s_push { struct s_lst { int nb; struct s_lst *next; } *a; struct s_lst *b; } *

variable_types: struct s_min { int min; int ind_min; } *

user_defined_types: struct s_push { struct s_lst *a; struct s_lst *b; }


decompiled_code:
__int64 __fastcall ft_a_before_send(__int64 *a1, _DWORD *a2)
{
unsigned int v2; // er12
__int64 v3; // rax

if ( a2[1] > (int)ft_count_elem(*a1) / 2 )
return ft_a_before_send2(a1, a2) == 1;
if ( *(_DWORD *)*a1 == *a2 )
return 0;
do
{
v3 = ft_swap_r();
*a1 = v3;
if ( !a1[1] )
{
v2 = ft_sort1(v3);
if ( v2 == 1 )
{
ft_putstr("ra\n");
return v2;
}
}
ft_putstr("ra ");
}
while ( *(_DWORD *)*a1 != *a2 );
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, _DWORD *a2)
{
unsigned int v2; // er12
__int64 v3; // rax

if ( a2[1] > (int)ft_count_elem(*a1) / 2 )
return func0(a1, a2) == 1;
if ( *(_DWORD *)*a1 == *a2 )
return 0;
do
{
v3 = ft_swap_r();
*a1 = v3;
if ( !a1[1] )
{
v2 = ft_sort1(v3);
if ( v2 == 1 )
{
ft_putstr("ra\n");
return v2;
}
}
ft_putstr("ra ");
}
while ( *(_DWORD *)*a1 != *a2 );
return 0;
}

original_code:
static int ft_a_before_send(t_push *list, t_min *min)
{
 int i;
 int m;
 m = ft_count_elem(list->a);
 i = 0;
 if (min->ind_min <= m / 2)
 {
  while ((list->a)->nb != min->min)
  {
   list->a = ft_swap_r(list->a);
   if (!list->b && ft_sort1(list->a) == 1)
   {
    ft_putstr("ra\n");
    return (1);
   }
   else
    ft_putstr("ra ");
  }
 }
 else
 {
  if (ft_a_before_send2(list, min) == 1)
   return (1);
 }
 return (0);
}

canonical_original_code:
static int ft_a_before_send(struct s_push *list, struct s_min *min)
{
 int i;
 int m;
 m = ft_count_elem(list->a);
 i = 0;
 if (min->ind_min <= m / 2)
 {
  while ((list->a)->nb != min->min)
  {
   list->a = ft_swap_r(list->a);
   if (!list->b && ft_sort1(list->a) == 1)
   {
    ft_putstr("ra\n");
    return (1);
   }
   else
    ft_putstr("ra ");
  }
 }
 else
 {
  if (ft_a_before_send2(list, min) == 1)
   return (1);
 }
 return (0);
}

variable_types: m int

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


decompiled_code:
__int64 __fastcall ft_put_all_b_in_a(__int64 a1)
{
__int64 v1; // rbx
__int64 i; // rax

v1 = a1;
for ( i = *(_QWORD *)(a1 + 8); i; i = *(_QWORD *)(v1 + 8) )
{
if ( *(_QWORD *)(i + 8) )
{
v1 = ft_swap_pa(v1);
ft_putstr("pa ");
}
else
{
v1 = ft_swap_pa(v1);
ft_putstr("pa\n");
}
}
return 1LL;
}

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

v1 = a1;
for ( i = *(_QWORD *)(a1 + 8); i; i = *(_QWORD *)(v1 + 8) )
{
if ( *(_QWORD *)(i + 8) )
{
v1 = ft_swap_pa(v1);
ft_putstr("pa ");
}
else
{
v1 = ft_swap_pa(v1);
ft_putstr("pa\n");
}
}
return 1LL;
}

original_code:
static int ft_put_all_b_in_a(t_push *list)
{
 while (list->b)
 {
  if ((list->b)->next)
  {
   list = ft_swap_pa(list);
   ft_putstr("pa ");
  }
  else
  {
   list = ft_swap_pa(list);
   ft_putstr("pa\n");
  }
 }
 return (1);
}

canonical_original_code:
static int ft_put_all_b_in_a(struct s_push *list)
{
 while (list->b)
 {
  if ((list->b)->next)
  {
   list = ft_swap_pa(list);
   ft_putstr("pa ");
  }
  else
  {
   list = ft_swap_pa(list);
   ft_putstr("pa\n");
  }
 }
 return (1);
}


decompiled_code:
__int64 __fastcall ft_change_value_variable(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 v4; // rbx
__int64 v5; // rax
unsigned int v6; // ebp
__int64 v7; // rax

v4 = 0LL;
if ( !*(_QWORD *)*a3 )
return (unsigned int)-1;
while ( 1 )
{
v5 = ft_strlen(a1);
v6 = ft_strncmp(*(_QWORD *)(*a3 + v4), a1, v5);
if ( !v6 )
break;
v4 += 8LL;
if ( !*(_QWORD *)(*a3 + v4) )
return (unsigned int)-1;
}
if ( !*(_QWORD *)(*a3 + v4) )
return (unsigned int)-1;
gfree();
if ( a2 )
v7 = ft_strjoin(a1, a2);
else
v7 = ft_strdup(a1);
*(_QWORD *)(*a3 + v4) = v7;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 v4; // rbx
__int64 v5; // rax
unsigned int v6; // ebp
__int64 v7; // rax

v4 = 0LL;
if ( !*(_QWORD *)*a3 )
return (unsigned int)-1;
while ( 1 )
{
v5 = ft_strlen(a1);
v6 = ft_strncmp(*(_QWORD *)(*a3 + v4), a1, v5);
if ( !v6 )
break;
v4 += 8LL;
if ( !*(_QWORD *)(*a3 + v4) )
return (unsigned int)-1;
}
if ( !*(_QWORD *)(*a3 + v4) )
return (unsigned int)-1;
gfree();
if ( a2 )
v7 = ft_strjoin(a1, a2);
else
v7 = ft_strdup(a1);
*(_QWORD *)(*a3 + v4) = v7;
return v6;
}

original_code:
int ft_change_value_variable(char *var, char *val, char ***env)
{
 int i;
 i = 0;
 while ((*env)[i] && ft_strncmp((*env)[i], var, ft_strlen(var)))
  ++i;
 if (!((*env)[i]))
  return (-1);
 gfree((*env)[i]);
 (*env)[i] = val ? ft_strjoin(var, val) : ft_strdup(var);
 return (0);
}

variable_types:
var
char *

variable_types:
val
char *

variable_types:
env
char ***


original_code:
int ft_add_var(char *var, char *val, char ***env)
{
 int i;
 char **new_env;
 char *new_line;
 new_line = ((void *)0);
 i = 0;
 while ((*env)[i])
  ++i;
 if (!(new_env = gmalloc(sizeof(char *) * (i + 2))))
  return (-1);
 i = -1;
 while ((*env)[++i])
  new_env[i] = (char *)c_calls("dup", (void *)(*env)[i]);
 gfree((void *)*env);
 new_line = ft_strjoin(var, "=");
 new_env[i] = val ? ft_strjoin(new_line, val) : ft_strdup(new_line);
 new_env[++i] = ((void *)0);
 gfree(new_line);
 *env = new_env;
 return (0);
}

variable_types: i int


decompiled_code:
__int64 __fastcall ft_replace_or_add(__int64 *a1, __int64 *a2)
{
__int64 *v2; // rax
__int64 v3; // r12
__int64 v4; // rax
int v5; // edx
__int64 result; // rax
__int64 v7; // rax
int v8; // edx

v2 = (__int64 *)a1[2];
if ( v2 )
{
v3 = *v2;
v4 = ft_strjoin(*a1, &unk_317);
v5 = ft_change_value_variable(v4, v3, a2);
result = 0LL;
if ( v5 == -1 )
result = (unsigned int)-((unsigned int)ft_add_var(*a1, *(_QWORD *)a1[2], a2) == -1);
}
else
{
v7 = ft_strjoin(*a1, &unk_317);
v8 = ft_change_value_variable(v7, 0LL, a2);
result = 0LL;
if ( v8 == -1 )
result = (unsigned int)-((unsigned int)ft_add_var(*a1, 0LL, a2) == -1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, __int64 *a2)
{
__int64 *v2; // rax
__int64 v3; // r12
__int64 v4; // rax
int v5; // edx
__int64 result; // rax
__int64 v7; // rax
int v8; // edx

v2 = (__int64 *)a1[2];
if ( v2 )
{
v3 = *v2;
v4 = ft_strjoin(*a1, &unk_317);
v5 = func0(v4, v3, a2);
result = 0LL;
if ( v5 == -1 )
result = (unsigned int)-((unsigned int)func1(*a1, *(_QWORD *)a1[2], a2) == -1);
}
else
{
v7 = ft_strjoin(*a1, &unk_317);
v8 = func0(v7, 0LL, a2);
result = 0LL;
if ( v8 == -1 )
result = (unsigned int)-((unsigned int)func1(*a1, 0LL, a2) == -1);
}
return result;
}

original_code:
int ft_replace_or_add(t_p *move, char ***env)
{
 if (move->next)
 {
  if (ft_change_value_variable(ft_strjoin(move->tok, "="),
          move->next->tok, env) == -1)
  {
   if (ft_add_var(move->tok, move->next->tok, env) == -1)
    return (-1);
  }
  return (0);
 }
 else
 {
  if (ft_change_value_variable(ft_strjoin(move->tok, "="),
          ((void *)0), env) == -1)
  {
   if (ft_add_var(move->tok, ((void *)0), env) == -1)
    return (-1);
  }
 }
 return (0);
}

canonical_original_code:
int ft_replace_or_add(struct s_p *move, char ***env)
{
 if (move->next)
 {
  if (ft_change_value_variable(ft_strjoin(move->tok, "="),
          move->next->tok, env) == -1)
  {
   if (ft_add_var(move->tok, move->next->tok, env) == -1)
    return (-1);
  }
  return (0);
 }
 else
 {
  if (ft_change_value_variable(ft_strjoin(move->tok, "="),
          ((void *)0), env) == -1)
  {
   if (ft_add_var(move->tok, ((void *)0), env) == -1)
    return (-1);
  }
 }
 return (0);
}

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


decompiled_code:
__int64 __fastcall ft_setenv(__int64 a1, __int64 *a2)
{
__int64 *v2; // rbp
__int64 v3; // rax
_QWORD *v4; // rax
__int64 result; // rax
__int64 v6; // rbp
__int64 v7; // rdi

v2 = *(__int64 **)(a1 + 16);
if ( v2 )
{
v3 = v2[2];
if ( v3 && *(_QWORD *)(v3 + 16) )
{
result = ft_error_msg("setenv: Too many arguments.", &unk_319);
}
else if ( (unsigned int)ft_find(*v2, &unk_317)
|| (v4 = (_QWORD *)v2[2]) != 0LL && (unsigned int)ft_find(*v4, &unk_317) )
{
result = ft_error_msg("setenv: Avoid the character '='", &unk_319);
}
else
{
result = ft_replace_or_add(v2, a2);
}
}
else if ( *(_QWORD *)*a2 )
{
v6 = 8LL;
do
{
ft_putendl();
v7 = *(_QWORD *)(*a2 + v6);
v6 += 8LL;
}
while ( v7 );
result = 0LL;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 *a2)
{
__int64 *v2; // rbp
__int64 v3; // rax
_QWORD *v4; // rax
__int64 result; // rax
__int64 v6; // rbp
__int64 v7; // rdi

v2 = *(__int64 **)(a1 + 16);
if ( v2 )
{
v3 = v2[2];
if ( v3 && *(_QWORD *)(v3 + 16) )
{
result = ft_error_msg("setenv: Too many arguments.", &unk_319);
}
else if ( (unsigned int)ft_find(*v2, &unk_317)
|| (v4 = (_QWORD *)v2[2]) != 0LL && (unsigned int)ft_find(*v4, &unk_317) )
{
result = ft_error_msg("setenv: Avoid the character '='", &unk_319);
}
else
{
result = func2(v2, a2);
}
}
else if ( *(_QWORD *)*a2 )
{
v6 = 8LL;
do
{
ft_putendl();
v7 = *(_QWORD *)(*a2 + v6);
v6 += 8LL;
}
while ( v7 );
result = 0LL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int ft_setenv(t_p *p, char ***env)
{
 t_p *move;
 int i;
 move = p->next;
 if (!move)
 {
  i = -1;
  while ((*env)[++i])
   ft_putendl((*env)[i]);
  return (0);
 }
 if (move->next && move->next->next)
  return (ft_error_msg("setenv: Too many arguments.", ""));
 if (ft_find(move->tok, "=")
  || (move->next && ft_find(move->next->tok, "=")))
  return (ft_error_msg("setenv: Avoid the character '='", ""));
 return (ft_replace_or_add(move, env));
}

canonical_original_code:
int ft_setenv(struct s_p *p, char ***env)
{
 struct s_p *move;
 int i;
 move = p->next;
 if (!move)
 {
  i = -1;
  while ((*env)[++i])
   ft_putendl((*env)[i]);
  return (0);
 }
 if (move->next && move->next->next)
  return (ft_error_msg("setenv: Too many arguments.", ""));
 if (ft_find(move->tok, "=")
  || (move->next && ft_find(move->next->tok, "=")))
  return (ft_error_msg("setenv: Avoid the character '='", ""));
 return (ft_replace_or_add(move, env));
}


original_code:
static int ft_s_w_m(char const *s, int i)
{
 int m;
 m = 0;
 while (*(s + i) && *(s + i) != ' ' && *(s + i) != 't')
 {
  ++i;
  ++m;
 }
 return (m);
}

variable_types:
s
char *


original_code:
char **ft_strsplim(char const *s)
{
 char **s3;
 int i;
 int k;
 if (!(s3 = (char **)gmalloc(sizeof(char *) * (ft_wc_w_m(s) + 1))))
  return (((void *)0));
 i = 0;
 k = 0;
 while (*(s + i))
 {
  while ((*(s + i) == ' ' || *(s + i) == '\t') && *(s + i))
   ++i;
  if (*(s + i))
  {
   if (!(s3[k] = (char *)gmalloc(sizeof(char) * (ft_s_w_m(s, i) + 1))))
    return (((void *)0));
   s3[k] = ft_fill_m(s3[k], &i, s);
   ++k;
  }
 }
 if (!(s3[k] = (char *)gmalloc(sizeof(char) * (1 + 1))))
  return (((void *)0));
 *(s3 + k) = '\0';
 return (s3);
}

variable_types: k int


decompiled_code:
__int64 __fastcall ft_win_now(__int64 a1)
{
_DWORD *v1; // rax
_DWORD *v2; // rdx

v1 = *(_DWORD **)(a1 + 8);
v2 = v1 + 4;
while ( *v1 != 4 )
{
if ( ++v1 == v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
_DWORD *v1; // rax
_DWORD *v2; // rdx

v1 = *(_DWORD **)(a1 + 8);
v2 = v1 + 4;
while ( *v1 != 4 )
{
if ( ++v1 == v2 )
return 0LL;
}
return 1LL;
}

original_code:
static int ft_win_now(t_s *s)
{
 int k;
 k = 0;
 while (k < 4)
 {
  if ((*s).save[k] == 4)
   return (1);
  ++k;
 }
 return (0);
}

canonical_original_code:
static int ft_win_now(struct s_s *s)
{
 int k;
 k = 0;
 while (k < 4)
 {
  if ((*s).save[k] == 4)
   return (1);
  ++k;
 }
 return (0);
}

variable_types: struct s_s { int *choices; int *save; char symb1; char symb2; int keep; } *


decompiled_code:
__int64 __fastcall ft_compute_mixed_value(_DWORD *a1)
{
return (unsigned int)(26 * *a1 + 15 * a1[1] + 10 * (a1[2] + a1[3]));
}

original_code:
static int ft_compute_mixed_value(int *save)
{
 return (26 * save[0] + 15 * save[1] + 10 * (save[2] + save[3]));
}

variable_types:
save
int *


original_code:
static void ft_fill_save_board(t_all a, t_s *s)
{
 (*s).choices[a.i] = 0;
 ft_reset_save_board(&((*s).save));
 (*s).save[0] = ft_find_nb_for_row(a, *s);
 (*s).save[1] = ft_find_nb_for_column(a, *s);
 (*s).save[2] = ft_find_nb_for_diag_up_left(a, *s);
 (*s).save[3] = ft_find_nb_for_diag_up_right(a, *s);
}

canonical_original_code:
static void ft_fill_save_board(struct s_all a, struct s_s *s)
{
 (*s).choices[a.i] = 0;
 ft_reset_save_board(&((*s).save));
 (*s).save[0] = ft_find_nb_for_row(a, *s);
 (*s).save[1] = ft_find_nb_for_column(a, *s);
 (*s).save[2] = ft_find_nb_for_diag_up_left(a, *s);
 (*s).save[3] = ft_find_nb_for_diag_up_right(a, *s);
}

variable_types: struct s_all { char **grid; int li; int co; int i; int j; }


original_code:
int ft_update_grid_of_choices(t_all a, t_s *me, t_s *you)
{
 int i;
 int j;
 int max;
 max = 0;
 i = 0;
 while (a.grid[i])
 {
  j = 0;
  while (a.grid[i][j] && a.grid[i][j + 1] && a.grid[i][j + 1] == '.')
   ++j;
  a.i = i;
  a.j = j;
  ft_number_of_awesomeness(a, me, you);
  if ((*me).choices[i] > max)
  {
   max = (*me).choices[i];
   (*me).keep = i;
  }
  ++i;
 }
 return (0);
}

canonical_original_code:
int ft_update_grid_of_choices(struct s_all a, struct s_s *me, struct s_s *you)
{
 int i;
 int j;
 int max;
 max = 0;
 i = 0;
 while (a.grid[i])
 {
  j = 0;
  while (a.grid[i][j] && a.grid[i][j + 1] && a.grid[i][j + 1] == '.')
   ++j;
  a.i = i;
  a.j = j;
  ft_number_of_awesomeness(a, me, you);
  if ((*me).choices[i] > max)
  {
   max = (*me).choices[i];
   (*me).keep = i;
  }
  ++i;
 }
 return (0);
}

variable_types:
you
struct s_s *

variable_types: j int

variable_types: max int

user_defined_types: struct s_all { char **grid; int li; int co; int i; int j; }


decompiled_code:
__int64 __fastcall ft_return_last_rep(__int64 **a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rbp
unsigned int v5; // ebx
__int64 v6; // rdi
char *v7; // rbp

v3 = **a1;
v4 = 0LL;
if ( !v3 )
return (unsigned int)ft_error_msg(": No such file or directory", &unk_465);
while ( 1 )
{
v5 = ft_strncmp(v3, "OLDPWD=", 7LL);
if ( !v5 )
break;
v3 = (*a1)[++v4];
if ( !v3 )
return (unsigned int)ft_error_msg(": No such file or directory", &unk_465);
}
v6 = (*a1)[v4];
if ( !v6 || chdir((const char *)(v6 + 7)) == -1 )
return (unsigned int)ft_error_msg(": No such file or directory", &unk_465);
v7 = getcwd(0LL, 0LL);
ft_change_value_variable("PWD=", v7, a1);
ft_change_value_variable("PWD=", v7, a1 + 1);
ft_change_value_variable("OLDPWD=", a2, a1);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 **a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rbp
unsigned int v5; // ebx
__int64 v6; // rdi
char *v7; // rbp

v3 = **a1;
v4 = 0LL;
if ( !v3 )
return (unsigned int)ft_error_msg(": No such file or directory", &unk_465);
while ( 1 )
{
v5 = ft_strncmp(v3, "OLDPWD=", 7LL);
if ( !v5 )
break;
v3 = (*a1)[++v4];
if ( !v3 )
return (unsigned int)ft_error_msg(": No such file or directory", &unk_465);
}
v6 = (*a1)[v4];
if ( !v6 || chdir((const char *)(v6 + 7)) == -1 )
return (unsigned int)ft_error_msg(": No such file or directory", &unk_465);
v7 = getcwd(0LL, 0LL);
ft_change_value_variable("PWD=", v7, a1);
ft_change_value_variable("PWD=", v7, a1 + 1);
ft_change_value_variable("OLDPWD=", a2, a1);
return v5;
}

original_code:
int ft_return_last_rep(t_env *e, char *old_pwd)
{
 int i;
 char *pwd;
 pwd = ((void *)0);
 i = 0;
 while (e->env[i] && ft_strncmp(e->env[i], "OLDPWD=", 7))
  ++i;
 if (!(e->env[i]) || (chdir(&(e->env[i][7])) == -1))
  return (ft_error_msg(": No such file or directory", ""));
 pwd = getcwd(pwd, 0);
 ft_change_value_variable("PWD=", pwd, &(e->env));
 ft_change_value_variable("PWD=", pwd, &(e->env_s));
 ft_change_value_variable("OLDPWD=", old_pwd, &(e->env));
 return (0);
}

canonical_original_code:
int ft_return_last_rep(struct s_env *e, char *old_pwd)
{
 int i;
 char *pwd;
 pwd = ((void *)0);
 i = 0;
 while (e->env[i] && ft_strncmp(e->env[i], "OLDPWD=", 7))
  ++i;
 if (!(e->env[i]) || (chdir(&(e->env[i][7])) == -1))
  return (ft_error_msg(": No such file or directory", ""));
 pwd = getcwd(pwd, 0);
 ft_change_value_variable("PWD=", pwd, &(e->env));
 ft_change_value_variable("PWD=", pwd, &(e->env_s));
 ft_change_value_variable("OLDPWD=", old_pwd, &(e->env));
 return (0);
}

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

variable_types:
pwd
char *


decompiled_code:
__int64 __fastcall ft_return_home(__int64 **a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rbp
unsigned int v5; // ebx
__int64 v6; // rdi
char *v7; // rbp

v3 = **a1;
v4 = 0LL;
if ( !v3 )
return (unsigned int)ft_error_msg("cd: No home directory", &unk_465);
while ( 1 )
{
v5 = ft_strncmp(v3, "HOME=", 5LL);
if ( !v5 )
break;
v3 = (*a1)[++v4];
if ( !v3 )
return (unsigned int)ft_error_msg("cd: No home directory", &unk_465);
}
v6 = (*a1)[v4];
if ( !v6 )
return (unsigned int)ft_error_msg("cd: No home directory", &unk_465);
if ( chdir((const char *)(v6 + 5)) == -1 )
return (unsigned int)ft_error_msg("cd: Can't change to home directory", &unk_465);
v7 = getcwd(0LL, 0LL);
ft_change_value_variable("PWD=", v7, a1);
ft_change_value_variable("PWD=", v7, a1 + 1);
ft_change_value_variable("OLDPWD=", a2, a1);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 **a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rbp
unsigned int v5; // ebx
__int64 v6; // rdi
char *v7; // rbp

v3 = **a1;
v4 = 0LL;
if ( !v3 )
return (unsigned int)ft_error_msg("cd: No home directory", &unk_465);
while ( 1 )
{
v5 = ft_strncmp(v3, "HOME=", 5LL);
if ( !v5 )
break;
v3 = (*a1)[++v4];
if ( !v3 )
return (unsigned int)ft_error_msg("cd: No home directory", &unk_465);
}
v6 = (*a1)[v4];
if ( !v6 )
return (unsigned int)ft_error_msg("cd: No home directory", &unk_465);
if ( chdir((const char *)(v6 + 5)) == -1 )
return (unsigned int)ft_error_msg("cd: Can't change to home directory", &unk_465);
v7 = getcwd(0LL, 0LL);
ft_change_value_variable("PWD=", v7, a1);
ft_change_value_variable("PWD=", v7, a1 + 1);
ft_change_value_variable("OLDPWD=", a2, a1);
return v5;
}

original_code:
int ft_return_home(t_env *e, char *old_pwd)
{
 char *pwd;
 int i;
 pwd = ((void *)0);
 i = 0;
 while (e->env[i] && ft_strncmp(e->env[i], "HOME=", 5))
  ++i;
 if (!(e->env[i]))
  return (ft_error_msg("cd: No home directory", ""));
 if (chdir(&(e->env[i][5])) == -1)
  return (ft_error_msg("cd: Can't change to home directory", ""));
 pwd = getcwd(pwd, 0);
 ft_change_value_variable("PWD=", pwd, &(e->env));
 ft_change_value_variable("PWD=", pwd, &(e->env_s));
 ft_change_value_variable("OLDPWD=", old_pwd, &(e->env));
 return (0);
}

canonical_original_code:
int ft_return_home(struct s_env *e, char *old_pwd)
{
 char *pwd;
 int i;
 pwd = ((void *)0);
 i = 0;
 while (e->env[i] && ft_strncmp(e->env[i], "HOME=", 5))
  ++i;
 if (!(e->env[i]))
  return (ft_error_msg("cd: No home directory", ""));
 if (chdir(&(e->env[i][5])) == -1)
  return (ft_error_msg("cd: Can't change to home directory", ""));
 pwd = getcwd(pwd, 0);
 ft_change_value_variable("PWD=", pwd, &(e->env));
 ft_change_value_variable("PWD=", pwd, &(e->env_s));
 ft_change_value_variable("OLDPWD=", old_pwd, &(e->env));
 return (0);
}

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


original_code:
char *ft_change_pwd(char *rep, char *old_pwd)
{
 int len;
 char *new_pwd;
 new_pwd = ((void *)0);
 len = ft_strlen(old_pwd) - 1;
 if (len < 0)
  return (old_pwd);
 while (len >= 0 && old_pwd[len] != '/')
  --len;
 if (len <= 0)
  return (old_pwd);
 new_pwd = ft_strjoin(ft_strsub(old_pwd, 0, len + 1), rep);
 gfree(old_pwd);
 return (new_pwd);
}

variable_types:
rep
char *

variable_types: len int


decompiled_code:
__int64 __fastcall ft_go_to_rep(char *file, __int64 a2, __int64 a3, int a4)
{
__int64 v6; // rax
struct stat *v7; // r12
int v8; // ebp
int v9; // eax
__int64 result; // rax
char *v11; // rax
__int64 v12; // rbp

v6 = gmalloc(144LL);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = (struct stat *)v6;
v8 = chdir(file);
v9 = lstat(file, v7);
if ( v8 != -1 || v9 )
{
if ( (v8 & v9) == -1 )
{
result = ft_error_msg(file, ": No such file or directory");
}
else
{
v11 = getcwd(0LL, 0LL);
v12 = (__int64)v11;
if ( *file != 46 && !a4 )
v12 = ft_change_pwd((__int64)file, (__int64)v11);
ft_change_value_variable("PWD=", v12, a2);
ft_change_value_variable("PWD=", v12, a2 + 8);
ft_change_value_variable("OLDPWD=", a3, a2);
result = 0LL;
}
}
else if ( (v7->st_mode & 0xE000) != 0 )
{
result = ft_error_msg(file, ": Permission denied");
}
else
{
result = ft_error_msg(file, ": Not a directory");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *file, __int64 a2, __int64 a3, int a4)
{
__int64 v6; // rax
struct stat *v7; // r12
int v8; // ebp
int v9; // eax
__int64 result; // rax
char *v11; // rax
__int64 v12; // rbp

v6 = gmalloc(144LL);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = (struct stat *)v6;
v8 = chdir(file);
v9 = lstat(file, v7);
if ( v8 != -1 || v9 )
{
if ( (v8 & v9) == -1 )
{
result = ft_error_msg(file, ": No such file or directory");
}
else
{
v11 = getcwd(0LL, 0LL);
v12 = (__int64)v11;
if ( *file != 46 && !a4 )
v12 = func2((__int64)file, (__int64)v11);
ft_change_value_variable("PWD=", v12, a2);
ft_change_value_variable("PWD=", v12, a2 + 8);
ft_change_value_variable("OLDPWD=", a3, a2);
result = 0LL;
}
}
else if ( (v7->st_mode & 0xE000) != 0 )
{
result = ft_error_msg(file, ": Permission denied");
}
else
{
result = ft_error_msg(file, ": Not a directory");
}
return result;
}

original_code:
int ft_go_to_rep(char *rep, t_env *e, char *old_pwd, int flag)
{
 char *pwd;
 struct stat *buf;
 int value1;
 int value2;
 pwd = ((void *)0);
 if (!(buf = (struct stat *)gmalloc(sizeof(*buf))))
  return (-1);
 value1 = chdir(rep);
 value2 = lstat(rep, buf);
 if (value1 == -1 && value2 == 0
  && (buf->st_mode & 0040000 || buf->st_mode & 0120000))
  return (ft_error_msg(rep, ": Permission denied"));
 else if (value1 == -1 && value2 == 0)
  return (ft_error_msg(rep, ": Not a directory"));
 else if (value1 == -1 && value2 == -1)
  return (ft_error_msg(rep, ": No such file or directory"));
 pwd = getcwd(pwd, 0);
 if (rep[0] != '.' && flag == 0)
  pwd = ft_change_pwd(rep, pwd);
 ft_change_value_variable("PWD=", pwd, &(e->env));
 ft_change_value_variable("PWD=", pwd, &(e->env_s));
 ft_change_value_variable("OLDPWD=", old_pwd, &(e->env));
 return (0);
}

canonical_original_code:
int ft_go_to_rep(char *rep, struct s_env *e, char *old_pwd, int flag)
{
 char *pwd;
 struct stat *buf;
 int value1;
 int value2;
 pwd = ((void *)0);
 if (!(buf = (struct stat *)gmalloc(sizeof(*buf))))
  return (-1);
 value1 = chdir(rep);
 value2 = lstat(rep, buf);
 if (value1 == -1 && value2 == 0
  && (buf->st_mode & 0040000 || buf->st_mode & 0120000))
  return (ft_error_msg(rep, ": Permission denied"));
 else if (value1 == -1 && value2 == 0)
  return (ft_error_msg(rep, ": Not a directory"));
 else if (value1 == -1 && value2 == -1)
  return (ft_error_msg(rep, ": No such file or directory"));
 pwd = getcwd(pwd, 0);
 if (rep[0] != '.' && flag == 0)
  pwd = ft_change_pwd(rep, pwd);
 ft_change_value_variable("PWD=", pwd, &(e->env));
 ft_change_value_variable("PWD=", pwd, &(e->env_s));
 ft_change_value_variable("OLDPWD=", old_pwd, &(e->env));
 return (0);
}

variable_types: flag int

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


original_code:
int ft_cd(t_p *p, t_env *e)
{
 int value;
 char *buf;
 value = 0;
 buf = ((void *)0);
 buf = getcwd(buf, 0);
 if (!p->next
  || (p->next && !ft_strcmp(p->next->tok, "-P") && !p->next->next))
  value = ft_return_home(e, buf);
 else if ((p->next->next && p->next->tok[0] != '-')
   || (p->next->next && p->next->next->next))
  value = ft_error_msg("cd: Too many arguments", "");
 else if (!ft_strcmp(p->next->tok, "-"))
  value = ft_return_last_rep(e, buf);
 else if (!ft_strcmp(p->next->tok, "-P"))
  value = ft_go_to_rep(p->next->next->tok, e, buf, 1);
 else if (!ft_strcmp(p->next->tok, "-L"))
  value = ft_go_to_rep(p->next->next->tok, e, buf, 0);
 else if (p->next->tok[0] == '-')
  value = ft_error_msg("Usage: cd [-L|-P][dir]", "");
 else
  value = ft_go_to_rep(p->next->tok, e, buf, 0);
 free(buf);
 return (value);
}

canonical_original_code:
int ft_cd(struct s_p *p, struct s_env *e)
{
 int value;
 char *buf;
 value = 0;
 buf = ((void *)0);
 buf = getcwd(buf, 0);
 if (!p->next
  || (p->next && !ft_strcmp(p->next->tok, "-P") && !p->next->next))
  value = ft_return_home(e, buf);
 else if ((p->next->next && p->next->tok[0] != '-')
   || (p->next->next && p->next->next->next))
  value = ft_error_msg("cd: Too many arguments", "");
 else if (!ft_strcmp(p->next->tok, "-"))
  value = ft_return_last_rep(e, buf);
 else if (!ft_strcmp(p->next->tok, "-P"))
  value = ft_go_to_rep(p->next->next->tok, e, buf, 1);
 else if (!ft_strcmp(p->next->tok, "-L"))
  value = ft_go_to_rep(p->next->next->tok, e, buf, 0);
 else if (p->next->tok[0] == '-')
  value = ft_error_msg("Usage: cd [-L|-P][dir]", "");
 else
  value = ft_go_to_rep(p->next->tok, e, buf, 0);
 free(buf);
 return (value);
}

variable_types: value int

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall ft_save_new_map(void *a1, int *a2)
{
__int64 v2; // rbx
__int64 v3; // rax
int v4; // er12
void *v5; // rax
__int64 v6; // rbx
__int64 result; // rax
_QWORD *v8; // r12
void *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

ptr[0] = a1;
v2 = ft_strsplit(a1, 32LL);
v3 = ft_strlen(*(_QWORD *)(v2 + 16));
*(_QWORD *)(v2 + 16) = ft_strsub(*(_QWORD *)(v2 + 16), 0LL, v3 - 1);
*a2 = ft_atoi(*(_QWORD *)(v2 + 8));
a2[1] = ft_atoi(*(_QWORD *)(v2 + 16));
ft_free_chtab(v2);
free(ptr[0]);
get_next_line(0LL, ptr);
free(ptr[0]);
v4 = *a2;
v5 = malloc(8LL * *a2);
*((_QWORD *)a2 + 1) = v5;
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = 0LL;
result = 0LL;
if ( v4 > 0 )
{
while ( 1 )
{
result = get_next_line(0LL, ptr);
if ( !(_DWORD)result )
break;
v8 = (_QWORD *)(*((_QWORD *)a2 + 1) + 8 * v6);
*v8 = ft_strdup((char *)ptr[0] + 4);
free(ptr[0]);
if ( *a2 <= (int)++v6 )
return 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1, int *a2)
{
__int64 v2; // rbx
__int64 v3; // rax
int v4; // er12
void *v5; // rax
__int64 v6; // rbx
__int64 result; // rax
_QWORD *v8; // r12
void *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

ptr[0] = a1;
v2 = ft_strsplit(a1, 32LL);
v3 = ft_strlen(*(_QWORD *)(v2 + 16));
*(_QWORD *)(v2 + 16) = ft_strsub(*(_QWORD *)(v2 + 16), 0LL, v3 - 1);
*a2 = ft_atoi(*(_QWORD *)(v2 + 8));
a2[1] = ft_atoi(*(_QWORD *)(v2 + 16));
ft_free_chtab(v2);
free(ptr[0]);
get_next_line(0LL, ptr);
free(ptr[0]);
v4 = *a2;
v5 = malloc(8LL * *a2);
*((_QWORD *)a2 + 1) = v5;
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = 0LL;
result = 0LL;
if ( v4 > 0 )
{
while ( 1 )
{
result = get_next_line(0LL, ptr);
if ( !(_DWORD)result )
break;
v8 = (_QWORD *)(*((_QWORD *)a2 + 1) + 8 * v6);
*v8 = ft_strdup((char *)ptr[0] + 4);
free(ptr[0]);
if ( *a2 <= (int)++v6 )
return 0LL;
}
}
return result;
}

original_code:
int ft_save_new_map(char *line, t_m *m)
{
 int i;
 char **map_info;
 map_info = ft_strsplit(line, ' ');
 map_info[2] = ft_strsub(map_info[2], 0, ft_strlen(map_info[2]) - 1);
 m->li = ft_atoi(map_info[1]);
 m->co = ft_atoi(map_info[2]);
 ft_free_chtab(map_info);
 free((void *)line);
 get_next_line(0, &line);
 free((void *)line);
 if (!(m->all = (char **)malloc(sizeof(char *) * (m->li))))
  return (-1);
 i = 0;
 while (i < m->li && get_next_line(0, &line))
 {
  m->all[i] = ft_strdup(line + 4);
  free((void *)line);
  ++i;
 }
 return (0);
}

canonical_original_code:
int ft_save_new_map(char *line, struct s_m *m)
{
 int i;
 char **map_info;
 map_info = ft_strsplit(line, ' ');
 map_info[2] = ft_strsub(map_info[2], 0, ft_strlen(map_info[2]) - 1);
 m->li = ft_atoi(map_info[1]);
 m->co = ft_atoi(map_info[2]);
 ft_free_chtab(map_info);
 free((void *)line);
 get_next_line(0, &line);
 free((void *)line);
 if (!(m->all = (char **)malloc(sizeof(char *) * (m->li))))
  return (-1);
 i = 0;
 while (i < m->li && get_next_line(0, &line))
 {
  m->all[i] = ft_strdup(line + 4);
  free((void *)line);
  ++i;
 }
 return (0);
}

variable_types:
line
char *

variable_types: struct s_m { int li; int co; char **all; int gli; int gco; int x; int y; } *

variable_types: i int


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:
save
struct s_save { int i; int j; } *


original_code:
t_c ft_trace(t_obj obj, t_r *r, t_save *save)
{
 int i;
 int j;
 t_c color;
 ft_init_save_and_ray(r, save);
 i = -1;
 while (++i < 6)
 {
  j = -1;
  while (++j < obj.nb[i])
  {
   if (obj.intersect[i](r, (obj.type)[i][j]) == 0 && r->t0 < r->tnear)
   {
    r->tnear = r->t0;
    save->i = i;
    save->j = j;
   }
  }
 }
 if (save->i == -1)
  return (obj.bg_clr);
 r->hit_i = save->i;
 r->hit_j = save->j;
 obj.treatment[save->i]((obj.type)[save->i][save->j], &color, &obj, r);
 return (color);
}

canonical_original_code:
struct s_c ft_trace(struct s_obj obj, struct s_r *r, struct s_save *save)
{
 int i;
 int j;
 struct s_c color;
 ft_init_save_and_ray(r, save);
 i = -1;
 while (++i < 6)
 {
  j = -1;
  while (++j < obj.nb[i])
  {
   if (obj.intersect[i](r, (obj.type)[i][j]) == 0 && r->t0 < r->tnear)
   {
    r->tnear = r->t0;
    save->i = i;
    save->j = j;
   }
  }
 }
 if (save->i == -1)
  return (obj.bg_clr);
 r->hit_i = save->i;
 r->hit_j = save->j;
 obj.treatment[save->i]((obj.type)[save->i][save->j], &color, &obj, r);
 return (color);
}

variable_types: struct s_obj { int depth; struct s_c **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; }

variable_types:
r
struct s_r *

variable_types:
color
struct s_c { int b; int g; int r; }

return_type: struct s_c { int b; int g; int r; }

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 ft_init_ray()
{
ft_init_vect(0.0, 0.0);
ft_init_vect(0.0, 0.0);
ft_init_vect(0.0, 0.0);
return ft_init_vect(0.0, 0.0);
}

original_code:
void ft_init_ray(t_r *r)
{
 ft_init_vect(&r->o_w, 0, 0, 0);
 ft_init_vect(&r->d_w, 0, 0, 0);
 ft_init_vect(&r->p_hit, 0, 0, 0);
 ft_init_vect(&r->n_hit, 0, 0, 0);
}

canonical_original_code:
void ft_init_ray(struct s_r *r)
{
 ft_init_vect(&r->o_w, 0, 0, 0);
 ft_init_vect(&r->d_w, 0, 0, 0);
 ft_init_vect(&r->p_hit, 0, 0, 0);
 ft_init_vect(&r->n_hit, 0, 0, 0);
}


raytracer

original_code:
int raytracer(t_obj *obj, t_cam cam)
{
 int i;
 int j;
 t_r r;
 double **c2w;
 t_save save;
 if (!(c2w = ft_init_matrix(&cam.b.vx, &cam.b.vy, &cam.b.vz)))
  return (-1);
 ft_init_ray(&r);
 r.o_w = cam.ro;
 j = -1;
 while (++j < (1200.0))
 {
  i = -1;
  while (++i < (2400.0))
  {
   obj->depth = 0;
   ft_find_pixel_pos_on_screen(&cam.rp, i, j);
   ft_mult_vect_by_matrix(&r.d_w, c2w, cam.rp);
   ft_vect_difference(&r.d_w, r.d_w, r.o_w);
   ft_normalize_vect(&r.d_w);
   obj->pixel[j][i] = ft_trace(*obj, &r, &save);
  }
 }
 return (0);
}

canonical_original_code:
int raytracer(struct s_obj *obj, struct s_cam cam)
{
 int i;
 int j;
 struct s_r r;
 double **c2w;
 struct s_save save;
 if (!(c2w = ft_init_matrix(&cam.b.vx, &cam.b.vy, &cam.b.vz)))
  return (-1);
 ft_init_ray(&r);
 r.o_w = cam.ro;
 j = -1;
 while (++j < (1200.0))
 {
  i = -1;
  while (++i < (2400.0))
  {
   obj->depth = 0;
   ft_find_pixel_pos_on_screen(&cam.rp, i, j);
   ft_mult_vect_by_matrix(&r.d_w, c2w, cam.rp);
   ft_vect_difference(&r.d_w, r.d_w, r.o_w);
   ft_normalize_vect(&r.d_w);
   obj->pixel[j][i] = ft_trace(*obj, &r, &save);
  }
 }
 return (0);
}

variable_types: 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; } *

variable_types: struct s_cam { struct s_b { struct s_v vx; struct s_v vy; struct s_v vz; } b; struct s_v trans; struct s_v ro; struct s_v rp; }

variable_types: j int

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:
save
struct s_save { int i; int j; }


decompiled_code:
__int64 __fastcall ft_is_no_quote(char *a1)
{
char v1; // dl
__int64 result; // rax

v1 = *a1;
if ( *a1 == 124 )
return (unsigned int)(a1[1] != 124) + 6;
if ( v1 == 38 )
{
result = 5LL;
if ( a1[1] != 38 )
result = 11LL;
}
else if ( v1 == 62 )
{
result = (unsigned int)(a1[1] == 62) + 8;
}
else
{
result = 4LL;
if ( v1 != 59 )
{
result = 10LL;
if ( v1 != 60 )
{
result = 14LL;
if ( v1 != 32 )
{
result = 15LL;
if ( v1 != 40 )
result = 5 * (unsigned int)(v1 == 41) + 11;
}
}
}
}
return result;
}

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

v1 = *a1;
if ( *a1 == 124 )
return (unsigned int)(a1[1] != 124) + 6;
if ( v1 == 38 )
{
result = 5LL;
if ( a1[1] != 38 )
result = 11LL;
}
else if ( v1 == 62 )
{
result = (unsigned int)(a1[1] == 62) + 8;
}
else
{
result = 4LL;
if ( v1 != 59 )
{
result = 10LL;
if ( v1 != 60 )
{
result = 14LL;
if ( v1 != 32 )
{
result = 15LL;
if ( v1 != 40 )
result = 5 * (unsigned int)(v1 == 41) + 11;
}
}
}
}
return result;
}


decompiled_code:
__int64 __fastcall ft_is_quote(_BYTE *a1, int *a2)
{
int v2; // eax
__int64 result; // rax

v2 = *a2;
if ( *a2 == 1 )
{
result = 11LL;
if ( *a1 == 39 )
{
*a2 = 0;
result = 2LL;
}
}
else if ( v2 == 2 )
{
result = 11LL;
if ( *a1 == 34 )
{
*a2 = 0;
result = 3LL;
}
}
else if ( (unsigned int)(v2 - 1) <= 1 )
{
result = 11LL;
}
else if ( *a1 == 39 )
{
*a2 = 1;
result = 2LL;
}
else
{
result = 0LL;
if ( *a1 == 34 )
{
*a2 = 2;
result = 3LL;
}
}
return result;
}

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

v2 = *a2;
if ( *a2 == 1 )
{
result = 11LL;
if ( *a1 == 39 )
{
*a2 = 0;
result = 2LL;
}
}
else if ( v2 == 2 )
{
result = 11LL;
if ( *a1 == 34 )
{
*a2 = 0;
result = 3LL;
}
}
else if ( (unsigned int)(v2 - 1) <= 1 )
{
result = 11LL;
}
else if ( *a1 == 39 )
{
*a2 = 1;
result = 2LL;
}
else
{
result = 0LL;
if ( *a1 == 34 )
{
*a2 = 2;
result = 3LL;
}
}
return result;
}

original_code:
static int ft_is_quote(char *line, int *ind)
{
 if (*ind == 1 && *line == '\'')
 {
  *ind = 0;
  return (2);
 }
 if (*ind == 2 && *line == '\"')
 {
  *ind = 0;
  return (3);
 }
 if (*ind == 1 || *ind == 2)
  return (11);
 if (*line == '\'')
 {
  *ind = 1;
  return (2);
 }
 if (*line == '\"')
 {
  *ind = 2;
  return (3);
 }
 return (0);
}

variable_types:
ind
int *


decompiled_code:
__int64 __fastcall ft_is_operand(char *a1, int *a2, _DWORD *a3)
{
__int64 result; // rax

if ( *a3 == 1 )
{
*a3 = 0;
result = 11LL;
}
else
{
if ( *a1 == 92 )
*a3 = 1;
result = ft_is_quote(a1, a2);
if ( !(_DWORD)result )
result = ft_is_no_quote(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, int *a2, _DWORD *a3)
{
__int64 result; // rax

if ( *a3 == 1 )
{
*a3 = 0;
result = 11LL;
}
else
{
if ( *a1 == 92 )
*a3 = 1;
result = func1(a1, a2);
if ( !(_DWORD)result )
result = func0(a1);
}
return result;
}

original_code:
static int ft_is_operand(char *line, int *ind, int *type_bs)
{
 int type;
 if (*type_bs == 1)
 {
  *type_bs = 0;
  return (11);
 }
 if (*line == '\\')
  *type_bs = 1;
 if ((type = ft_is_quote(line, ind)))
  return (type);
 type = ft_is_no_quote(line);
 return (type);
}

variable_types: type int


decompiled_code:
__int64 __fastcall ft_word_size_before_ope(char *a1, int *a2, _DWORD *a3)
{
char *v3; // rbx
unsigned int i; // ebp
int v6; // eax
int v8[9]; // [rsp+Ch] [rbp-24h] BYREF

v3 = a1;
v8[0] = 0;
for ( i = 0; *v3; ++v3 )
{
v6 = ft_is_operand(v3, a2, v8);
*a3 = v6;
if ( v6 != 11 )
break;
++i;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, int *a2, _DWORD *a3)
{
char *v3; // rbx
unsigned int i; // ebp
int v6; // eax
int v8[9]; // [rsp+Ch] [rbp-24h] BYREF

v3 = a1;
v8[0] = 0;
for ( i = 0; *v3; ++v3 )
{
v6 = func2(v3, a2, v8);
*a3 = v6;
if ( v6 != 11 )
break;
++i;
}
return i;
}

original_code:
int ft_word_size_before_ope(char *line, int *ind, int *type)
{
 int i;
 int type_bs;
 type_bs = 0;
 i = 0;
 while (*(line + i)
   && (*type = ft_is_operand(line + i, ind, &type_bs)) == 11)
  ++i;
 return (i);
}

variable_types:
type
int *


decompiled_code:
__int64 __fastcall c_calld(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12

if ( !(unsigned int)ft_strcmp(a1, "join") )
v3 = ft_strjoin(a2, a3);
gfree(a2);
gfree(a3);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12

if ( !(unsigned int)ft_strcmp(a1, "join") )
v3 = ft_strjoin(a2, a3);
gfree(a2);
gfree(a3);
return v3;
}

original_code:
void *c_calld(char *str, char *s1, char *s2)
{
 void *s3;
 if (!(ft_strcmp(str, "join")))
  s3 = ft_strjoin(s1, s2);
 gfree(s1);
 gfree(s2);
 return (s3);
}

variable_types:
str
char *

return_type: void *


decompiled_code:
__int64 ft_run_big_part()
{
return ft_run_small_part();
}

canonical_decompiled_code:
__int64 func0()
{
return ft_run_small_part();
}

original_code:
char **ft_run_big_part(char *line, char **env)
{
 int a;
 a = 0;
 if (a != 0)
 {
  if (!ft_check_pipe(line))
  {
   if (!(env = ft_run_the_pipe(line, env)))
    return (((void *)0));
  }
  else
  {
   if (!(env = ft_run_middle_part_1(line, env)))
    return (((void *)0));
  }
 }
 if (!(env = ft_run_small_part(line, env)))
  return (((void *)0));
 return (env);
}

variable_types:
line
char *

variable_types:
env
char **

variable_types: a int


decompiled_code:
__int64 __fastcall ft_check_key(char *a1, _QWORD *a2, int *a3, __int64 a4)
{
int v5; // er14
int v6; // er15
unsigned int v7; // ebp
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
char v14[2]; // [rsp+18h] [rbp-40h] BYREF
unsigned __int16 v15; // [rsp+1Ah] [rbp-3Eh]

ioctl(0, 0x5413uLL, v14);
v5 = v15;
a3[2] = v15;
if ( v5 )
{
v6 = *a3;
v7 = ft_is_key_enter(a1);
if ( v7 )
{
*a3 = -1;
v7 = 0;
}
else
{
v9 = ft_put_or_del_char(a1, a2, a3, a4);
if ( v9 == -1 )
{
v7 = -1;
}
else
{
if ( !v9 )
goto LABEL_8;
v10 = ft_short_mv((__int64)a1, (unsigned __int64)a2, a3, a3[2]);
if ( v10 == -1 )
return (unsigned int)-1;
if ( !v10 )
goto LABEL_8;
v11 = ft_fast_move(a1, a2, a3);
if ( v11 == -1 )
return (unsigned int)-1;
if ( !v11 )
goto LABEL_8;
v12 = ft_historic(a1, a2, a3, a4);
if ( v12 == -1 )
return (unsigned int)-1;
if ( v12 && (unsigned int)ft_cut_copy_or_paste(a1, a2, a3) == -1 )
v7 = -1;
else
LABEL_8:
ft_print(*a2, a3, (unsigned int)((v6 + 4) / v5));
}
}
}
else
{
*a3 = -1;
v7 = ft_error_msg("Put valid entry", &unk_41C);
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, _QWORD *a2, int *a3, __int64 a4)
{
int v5; // er14
int v6; // er15
unsigned int v7; // ebp
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
char v14[2]; // [rsp+18h] [rbp-40h] BYREF
unsigned __int16 v15; // [rsp+1Ah] [rbp-3Eh]

ioctl(0, 0x5413uLL, v14);
v5 = v15;
a3[2] = v15;
if ( v5 )
{
v6 = *a3;
v7 = ft_is_key_enter(a1);
if ( v7 )
{
*a3 = -1;
v7 = 0;
}
else
{
v9 = func0(a1, a2, a3, a4);
if ( v9 == -1 )
{
v7 = -1;
}
else
{
if ( !v9 )
goto LABEL_8;
v10 = func1((__int64)a1, (unsigned __int64)a2, a3, a3[2]);
if ( v10 == -1 )
return (unsigned int)-1;
if ( !v10 )
goto LABEL_8;
v11 = ft_fast_move(a1, a2, a3);
if ( v11 == -1 )
return (unsigned int)-1;
if ( !v11 )
goto LABEL_8;
v12 = ft_historic(a1, a2, a3, a4);
if ( v12 == -1 )
return (unsigned int)-1;
if ( v12 && (unsigned int)ft_cut_copy_or_paste(a1, a2, a3) == -1 )
v7 = -1;
else
LABEL_8:
ft_print(*a2, a3, (unsigned int)((v6 + 4) / v5));
}
}
}
else
{
*a3 = -1;
v7 = ft_error_msg("Put valid entry", &unk_41C);
}
return v7;
}

original_code:
static int ft_check_key(char *b, t_sl **l, t_save *s, t_hl **hl)
{
 int do_it;
 struct winsize w;
 int old_line;
 do_it = 1;
 ioctl(0, 0x5413, &w);
 if ((s->co = w.ws_col) == 0)
 {
  s->cursor_l = -1;
  return (ft_error_msg("Put valid entry", ""));
 }
 old_line = (4 + s->cursor_l) / s->co;
 if (ft_is_key_enter(b))
 {
  s->cursor_l = -1;
  return (0);
 }
 if (((do_it = ft_put_or_del_char(b, l, s, hl)) == -1)
  || (do_it && (do_it = ft_short_mv(b, l, &(s->cursor_l), s->co)) == -1)
  || (do_it && (do_it = ft_fast_move(b, l, &(s->cursor_l))) == -1)
  || (do_it && (do_it = ft_historic(b, l, s, hl)) == -1)
  || (do_it && (do_it = ft_cut_copy_or_paste(b, l, s)) == -1))
  return (-1);
 ft_print(*l, s, old_line);
 return (0);
}

canonical_original_code:
static int ft_check_key(char *b, struct s_sl **l, struct s_save *s, struct s_hl **hl)
{
 int do_it;
 struct winsize w;
 int old_line;
 do_it = 1;
 ioctl(0, 0x5413, &w);
 if ((s->co = w.ws_col) == 0)
 {
  s->cursor_l = -1;
  return (ft_error_msg("Put valid entry", ""));
 }
 old_line = (4 + s->cursor_l) / s->co;
 if (ft_is_key_enter(b))
 {
  s->cursor_l = -1;
  return (0);
 }
 if (((do_it = ft_put_or_del_char(b, l, s, hl)) == -1)
  || (do_it && (do_it = ft_short_mv(b, l, &(s->cursor_l), s->co)) == -1)
  || (do_it && (do_it = ft_fast_move(b, l, &(s->cursor_l))) == -1)
  || (do_it && (do_it = ft_historic(b, l, s, hl)) == -1)
  || (do_it && (do_it = ft_cut_copy_or_paste(b, l, s)) == -1))
  return (-1);
 ft_print(*l, s, old_line);
 return (0);
}

variable_types:
b
char *

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

variable_types: struct s_save { int cursor_l; int cursor_hl; int co; struct s_sl *copy; } *

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

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


decompiled_code:
__int64 __fastcall ft_put_or_del_char(char *a1, _QWORD *a2, int *a3, __int64 a4)
{
char v7; // di
int v8; // er14
int v9; // edx
__int64 result; // rax
int v11; // edx

v7 = *a1;
if ( (unsigned __int8)(v7 - 32) > 0x5Eu || a1[1] )
{
if ( *a3 > 0 && (unsigned int)ft_is_key_del_left(a1) )
{
--*a3;
ft_list_del_elem(a2);
}
else
{
v8 = *a3;
v9 = ft_slist_len(*a2);
result = 1LL;
if ( v8 >= v9 )
return result;
v11 = ft_is_key_del_right(a1);
result = 1LL;
if ( !v11 )
return result;
ft_list_del_elem(a2);
}
}
else
{
result = ft_list_put_elem((unsigned int)v7, a2, (unsigned int)*a3);
if ( (_DWORD)result == -1 )
return result;
++*a3;
}
result = (unsigned int)a3[1];
if ( (_DWORD)result )
{
a3[1] = 0;
result = *(_QWORD *)(*(_QWORD *)a4 + 16LL);
if ( result )
{
do
{
*(_QWORD *)a4 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, _QWORD *a2, int *a3, __int64 a4)
{
char v7; // di
int v8; // er14
int v9; // edx
__int64 result; // rax
int v11; // edx

v7 = *a1;
if ( (unsigned __int8)(v7 - 32) > 0x5Eu || a1[1] )
{
if ( *a3 > 0 && (unsigned int)ft_is_key_del_left(a1) )
{
--*a3;
ft_list_del_elem(a2);
}
else
{
v8 = *a3;
v9 = ft_slist_len(*a2);
result = 1LL;
if ( v8 >= v9 )
return result;
v11 = ft_is_key_del_right(a1);
result = 1LL;
if ( !v11 )
return result;
ft_list_del_elem(a2);
}
}
else
{
result = ft_list_put_elem((unsigned int)v7, a2, (unsigned int)*a3);
if ( (_DWORD)result == -1 )
return result;
++*a3;
}
result = (unsigned int)a3[1];
if ( (_DWORD)result )
{
a3[1] = 0;
result = *(_QWORD *)(*(_QWORD *)a4 + 16LL);
if ( result )
{
do
{
*(_QWORD *)a4 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
static int ft_put_or_del_char(char *buf, t_sl **l, t_save *s, t_hl **hl)
{
 if (buf[0] >= ' ' && buf[0] <= '~' && buf[1] == 0)
 {
  if (ft_list_put_elem(buf[0], l, s->cursor_l) == -1)
   return (-1);
  ++(s->cursor_l);
 }
 else if (s->cursor_l > 0 && ft_is_key_del_left(buf))
 {
  --(s->cursor_l);
  ft_list_del_elem(l, s->cursor_l);
 }
 else if (s->cursor_l < ft_slist_len(*l) && ft_is_key_del_right(buf))
  ft_list_del_elem(l, s->cursor_l);
 else
  return (1);
 if (s->cursor_hl)
 {
  s->cursor_hl = 0;
  while ((*hl)->prev)
   *hl = (*hl)->prev;
 }
 return (0);
}

canonical_original_code:
static int ft_put_or_del_char(char *buf, struct s_sl **l, struct s_save *s, struct s_hl **hl)
{
 if (buf[0] >= ' ' && buf[0] <= '~' && buf[1] == 0)
 {
  if (ft_list_put_elem(buf[0], l, s->cursor_l) == -1)
   return (-1);
  ++(s->cursor_l);
 }
 else if (s->cursor_l > 0 && ft_is_key_del_left(buf))
 {
  --(s->cursor_l);
  ft_list_del_elem(l, s->cursor_l);
 }
 else if (s->cursor_l < ft_slist_len(*l) && ft_is_key_del_right(buf))
  ft_list_del_elem(l, s->cursor_l);
 else
  return (1);
 if (s->cursor_hl)
 {
  s->cursor_hl = 0;
  while ((*hl)->prev)
   *hl = (*hl)->prev;
 }
 return (0);
}

variable_types:
buf
char *

user_defined_types: struct s_save { int cursor_l; int cursor_hl; int co; struct s_sl *copy; }

user_defined_types: struct s_sl { char c; struct s_sl *next; struct s_sl *prev; }

user_defined_types: struct s_hl { struct s_sl *hist; struct s_hl *next; struct s_hl *prev; }


decompiled_code:
__int64 __fastcall ft_putc(char a1)
{
ft_putchar_fd((unsigned int)a1, 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1)
{
ft_putchar_fd((unsigned int)a1, 1LL);
return 0LL;
}

original_code:
int ft_putc(int c)
{
 ft_putchar_fd((char)c, 1);
 return (0);
}

variable_types: c int