decompiled_code:
__int64 __fastcall ft_garb(int a1, __int64 a2, __int64 a3, __int64 a4)
{
_QWORD *v4; // rax
__int64 v5; // rdx
__int64 result; // rax

if ( !list_0 && a1 == 2 )
{
list_0 = (__int64)ft_listnew(a2);
result = (unsigned int)-(list_0 == 0);
}
else if ( a1 )
{
if ( a1 == 1 )
{
gfree(a2, &list_0);
result = 0LL;
}
else
{
v4 = ft_listnew(a2);
if ( v4 )
{
v5 = list_0;
list_0 = (__int64)v4;
v4[1] = v5;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
}
else
{
gclean(&list_0, a2, a3, a4, a2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, __int64 a3, __int64 a4)
{
_QWORD *v4; // rax
__int64 v5; // rdx
__int64 result; // rax

if ( !list_0 && a1 == 2 )
{
list_0 = (__int64)ft_listnew(a2);
result = (unsigned int)-(list_0 == 0);
}
else if ( a1 )
{
if ( a1 == 1 )
{
gfree(a2, &list_0);
result = 0LL;
}
else
{
v4 = ft_listnew(a2);
if ( v4 )
{
v5 = list_0;
list_0 = (__int64)v4;
v4[1] = v5;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
}
else
{
gclean(&list_0, a2, a3, a4, a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int ft_garb(int flag, void *ptr)
{
 static t_list *list = ((void *)0);
 t_list *tmp;
 if (!list && flag == 2)
 {
  if (!(list = ft_listnew(ptr)))
   return (-1);
  return (0);
 }
 if (flag == 0)
 {
  gclean(&list);
  return (-1);
 }
 else if (flag == 1)
  gfree(ptr, &list);
 else
 {
  if (!(tmp = ft_listnew(ptr)))
   return (-1);
  tmp->next = list;
  list = tmp;
 }
 return (0);
}

canonical_original_code:
int ft_garb(int flag, void *ptr)
{
 static struct s_list *list = ((void *)0);
 struct s_list *tmp;
 if (!list && flag == 2)
 {
  if (!(list = ft_listnew(ptr)))
   return (-1);
  return (0);
 }
 if (flag == 0)
 {
  gclean(&list);
  return (-1);
 }
 else if (flag == 1)
  gfree(ptr, &list);
 else
 {
  if (!(tmp = ft_listnew(ptr)))
   return (-1);
  tmp->next = list;
  list = tmp;
 }
 return (0);
}

variable_types: flag int

variable_types:
ptr
void *

variable_types: struct s_list { void *content; struct s_list *next; } *


decompiled_code:
__int64 __fastcall ft_put_char2(_QWORD *a1)
{
__int64 result; // rax
_QWORD *v2; // rbx

result = (__int64)a1;
if ( *a1 )
{
v2 = a1 + 1;
do
result = ft_putendl();
while ( *v2++ );
}
return result;
}

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

result = (__int64)a1;
if ( *a1 )
{
v2 = a1 + 1;
do
result = ft_putendl();
while ( *v2++ );
}
return result;
}

original_code:
void ft_put_char2(char **s)
{
 int i;
 i = 0;
 while (s[i])
 {
  ft_putendl(s[i]);
  ++i;
 }
}

variable_types:
s
char **

variable_types: i int

return_type: void


decompiled_code:
void ft_signal()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void ft_signal(int sign)
{
 if (sign == 10)
  return ;
 else if (sign == 12)
  return ;
}

variable_types: sign int


decompiled_code:
int __fastcall ft_send_bit_by_bit(char a1, __pid_t a2)
{
int v2; // ebp
int v3; // ebx
int result; // eax

v2 = 8;
v3 = 1;
do
{
if ( (a1 & v3) != 0 )
kill(a2, 10);
else
kill(a2, 12);
v3 *= 2;
result = usleep(0xAu);
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
int __fastcall func8(char a1, __pid_t a2)
{
int v2; // ebp
int v3; // ebx
int result; // eax

v2 = 8;
v3 = 1;
do
{
if ( (a1 & v3) != 0 )
kill(a2, 10);
else
kill(a2, 12);
v3 *= 2;
result = usleep(0xAu);
--v2;
}
while ( v2 );
return result;
}

original_code:
void ft_send_bit_by_bit(char c, pid_t pid_s)
{
 int tmp;
 int i;
 tmp = 1;
 i = -1;
 while (++i < 8)
 {
  if (c & tmp)
   kill(pid_s, 10);
  else
   kill(pid_s, 12);
  usleep(10);
   tmp = tmp << 1;
 }
}

canonical_original_code:
void ft_send_bit_by_bit(char c, int pid_s)
{
 int tmp;
 int i;
 tmp = 1;
 i = -1;
 while (++i < 8)
 {
  if (c & tmp)
   kill(pid_s, 10);
  else
   kill(pid_s, 12);
  usleep(10);
   tmp = tmp << 1;
 }
}

variable_types: c char

variable_types: tmp int


decompiled_code:
int __fastcall ft_send_pid_bit_by_bit(int a1, __pid_t a2)
{
int v2; // ebp
int v3; // ebx
int result; // eax

v2 = 32;
v3 = 1;
do
{
if ( (v3 & a1) != 0 )
kill(a2, 10);
else
kill(a2, 12);
v3 *= 2;
result = usleep(0xAu);
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
int __fastcall func9(int a1, __pid_t a2)
{
int v2; // ebp
int v3; // ebx
int result; // eax

v2 = 32;
v3 = 1;
do
{
if ( (v3 & a1) != 0 )
kill(a2, 10);
else
kill(a2, 12);
v3 *= 2;
result = usleep(0xAu);
--v2;
}
while ( v2 );
return result;
}

original_code:
void ft_send_pid_bit_by_bit(pid_t pid_c, pid_t pid_s)
{
 int tmp;
 int i;
 tmp = 1;
 i = -1;
 while (++i < 32)
 {
  if (pid_c & tmp)
   kill(pid_s, 10);
  else
   kill(pid_s, 12);
  usleep(10);
  tmp = tmp << 1;
 }
}

canonical_original_code:
void ft_send_pid_bit_by_bit(int pid_c, int pid_s)
{
 int tmp;
 int i;
 tmp = 1;
 i = -1;
 while (++i < 32)
 {
  if (pid_c & tmp)
   kill(pid_s, 10);
  else
   kill(pid_s, 12);
  usleep(10);
  tmp = tmp << 1;
 }
}


decompiled_code:
int __fastcall ft_send_string(char *a1, __pid_t a2)
{
int result; // eax
char v4; // di
char *v5; // rbx

signal(10, (__sighandler_t)ft_signal);
result = (unsigned int)signal(12, (__sighandler_t)ft_signal);
v4 = *a1;
if ( v4 )
{
v5 = a1 + 1;
do
{
++v5;
result = ft_send_bit_by_bit(v4, a2);
v4 = *(v5 - 1);
}
while ( v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(char *a1, __pid_t a2)
{
int result; // eax
char v4; // di
char *v5; // rbx

signal(10, (__sighandler_t)ft_signal);
result = (unsigned int)signal(12, (__sighandler_t)ft_signal);
v4 = *a1;
if ( v4 )
{
v5 = a1 + 1;
do
{
++v5;
result = func8(v4, a2);
v4 = *(v5 - 1);
}
while ( v4 );
}
return result;
}

original_code:
void ft_send_string(char *str, pid_t pid_s)
{
 int i;
 i = -1;
 signal(10, ft_signal);
 signal(12, ft_signal);
 while (str[++i])
  ft_send_bit_by_bit(str[i], pid_s);
}

canonical_original_code:
void ft_send_string(char *str, int pid_s)
{
 int i;
 i = -1;
 signal(10, ft_signal);
 signal(12, ft_signal);
 while (str[++i])
  ft_send_bit_by_bit(str[i], pid_s);
}

variable_types:
str
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // ebp
unsigned int v5; // er12
unsigned int v6; // er12

if ( argc == 3 )
{
v4 = ft_atoi(argv[1], argv, envp);
v5 = getpid();
ft_send_pid_bit_by_bit(v5, v4);
ft_putstr("pid_c = ");
ft_putnbr(v5);
ft_putchar(10LL);
v6 = ft_strlen(argv[2]);
ft_putstr("len = ");
ft_putnbr(v6);
ft_putchar(10LL);
ft_send_pid_bit_by_bit(v6, v4);
ft_send_string(argv[2], v4);
}
else
{
ft_putendl_fd("Too few or too many arguments", 2LL, envp);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // ebp
unsigned int v5; // er12
unsigned int v6; // er12

if ( argc == 3 )
{
v4 = func11(argv[1], argv, envp);
v5 = getpid();
func9(v5, v4);
func15("pid_c = ");
func14(v5);
func12(10LL);
v6 = func17(argv[2]);
func15("len = ");
func14(v6);
func12(10LL);
func9(v6, v4);
func10(argv[2], v4);
}
else
{
func13("Too few or too many arguments", 2LL, envp);
}
return 0;
}

original_code:
int main(int ac, char **av)
{
 pid_t pid_s;
 pid_t pid_c;
 pid_t len;
 if (ac != 3)
 {
  ft_putendl_fd("Too few or too many arguments", 2);
  return (0);
 }
 pid_s = (pid_t)ft_atoi(av[1]);
 pid_c = getpid();
 ft_send_pid_bit_by_bit(pid_c, pid_s);
 ft_putstr("pid_c = ");
 ft_putnbr(pid_c);
 ft_putchar('\n');
 len = (pid_t)ft_strlen(av[2]);
 ft_putstr("len = ");
 ft_putnbr(len);
 ft_putchar('\n');
 ft_send_pid_bit_by_bit(len, pid_s);
 ft_send_string(av[2], pid_s);
 return (0);
}

canonical_original_code:
int main(int ac, char **av)
{
 int pid_s;
 int pid_c;
 int len;
 if (ac != 3)
 {
  ft_putendl_fd("Too few or too many arguments", 2);
  return (0);
 }
 pid_s = (int)ft_atoi(av[1]);
 pid_c = getpid();
 ft_send_pid_bit_by_bit(pid_c, pid_s);
 ft_putstr("pid_c = ");
 ft_putnbr(pid_c);
 ft_putchar('\n');
 len = (int)ft_strlen(av[2]);
 ft_putstr("len = ");
 ft_putnbr(len);
 ft_putchar('\n');
 ft_send_pid_bit_by_bit(len, pid_s);
 ft_send_string(av[2], pid_s);
 return (0);
}

variable_types: ac int

variable_types:
av
char **

variable_types: len int

return_type: int


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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
t_lst *ft_last(t_lst *list)
{
 while (list->next)
  list = list->next;
 return (list);
}

canonical_original_code:
struct s_lst *ft_last(struct s_lst *list)
{
 while (list->next)
  list = list->next;
 return (list);
}

variable_types:
list
struct s_lst *

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


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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 8);
return result;
}

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 8);
return result;
}

original_code:
int ft_count_elem(t_lst *list)
{
 int n;
 n = 0;
 while (list)
 {
  n++;
  list = list->next;
 }
 return (n);
}

canonical_original_code:
int ft_count_elem(struct s_lst *list)
{
 int n;
 n = 0;
 while (list)
 {
  n++;
  list = list->next;
 }
 return (n);
}

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

variable_types: n int


decompiled_code:
__int64 __fastcall ft_sort1(__int64 a1)
{
_DWORD *v1; // rax

while ( 1 )
{
if ( !a1 )
return 1LL;
v1 = *(_DWORD **)(a1 + 8);
if ( !v1 )
return 1LL;
if ( *(_DWORD *)a1 > *v1 )
break;
a1 = *(_QWORD *)(a1 + 8);
}
return 0xFFFFFFFFLL;
}

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

while ( 1 )
{
if ( !a1 )
return 1LL;
v1 = *(_DWORD **)(a1 + 8);
if ( !v1 )
return 1LL;
if ( *(_DWORD *)a1 > *v1 )
break;
a1 = *(_QWORD *)(a1 + 8);
}
return 0xFFFFFFFFLL;
}

original_code:
int ft_sort1(t_lst *list)
{
 while (list && list->next)
 {
  if (list->nb > (list->next)->nb)
   return (-1);
  list = list->next;
 }
 return (1);
}

canonical_original_code:
int ft_sort1(struct s_lst *list)
{
 while (list && list->next)
 {
  if (list->nb > (list->next)->nb)
   return (-1);
  list = list->next;
 }
 return (1);
}

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


decompiled_code:
__int64 __fastcall ft_sort2(__int64 a1)
{
_DWORD *v1; // rax

while ( 1 )
{
if ( !a1 )
return 1LL;
v1 = *(_DWORD **)(a1 + 8);
if ( !v1 )
return 1LL;
if ( *(_DWORD *)a1 < *v1 )
break;
a1 = *(_QWORD *)(a1 + 8);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
_DWORD *v1; // rax

while ( 1 )
{
if ( !a1 )
return 1LL;
v1 = *(_DWORD **)(a1 + 8);
if ( !v1 )
return 1LL;
if ( *(_DWORD *)a1 < *v1 )
break;
a1 = *(_QWORD *)(a1 + 8);
}
return 0xFFFFFFFFLL;
}

original_code:
int ft_sort2(t_lst *list)
{
 while (list && list->next)
 {
  if (list->nb < (list->next)->nb)
   return (-1);
  list = list->next;
 }
 return (1);
}

canonical_original_code:
int ft_sort2(struct s_lst *list)
{
 while (list && list->next)
 {
  if (list->nb < (list->next)->nb)
   return (-1);
  list = list->next;
 }
 return (1);
}


original_code:
static int ft_try_position(t_m *m, t_p *p, t_s *s)
{
 int i;
 int j;
 int touch;
 touch = 0;
 i = 0;
 while (i < p->li && touch <= 1)
 {
  j = 0;
  while (j < p->co && touch <= 1)
  {
   if (p->fig[i][j] == '*')
   {
    m->x = (m->gli + i + m->li) % m->li;
    m->y = (m->gco + j + m->co) % m->co;
    if ((touch = ft_special_symb(m, s, touch)) == -1)
     return (-1);
   }
   ++j;
  }
  ++i;
 }
 if (touch != 1)
  return (-1);
 return (1);
}

canonical_original_code:
static int ft_try_position(struct s_m *m, struct s_p *p, struct s_s *s)
{
 int i;
 int j;
 int touch;
 touch = 0;
 i = 0;
 while (i < p->li && touch <= 1)
 {
  j = 0;
  while (j < p->co && touch <= 1)
  {
   if (p->fig[i][j] == '*')
   {
    m->x = (m->gli + i + m->li) % m->li;
    m->y = (m->gco + j + m->co) % m->co;
    if ((touch = ft_special_symb(m, s, touch)) == -1)
     return (-1);
   }
   ++j;
  }
  ++i;
 }
 if (touch != 1)
  return (-1);
 return (1);
}

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

variable_types: struct s_p { int li; int co; char **fig; } *

variable_types: struct s_s { char mef; char mel; char opf; char opl; } *

variable_types: j int

variable_types: touch int


decompiled_code:
__int64 __fastcall ft_place_my_piece(int *a1, int *a2, _BYTE *a3)
{
int v5; // edx
int v6; // esi
__int64 result; // rax
int v8; // ecx
int v9; // edx
int v10; // ecx
int v11; // eax
int v12; // ecx
int v13; // ecx

v5 = *a2;
v6 = *a1;
result = (unsigned int)-v5;
v8 = *a1 - v5;
a1[4] = result;
if ( (int)result < v8 )
{
v9 = a1[1];
while ( 1 )
{
v10 = a2[1];
a1[5] = -v10;
if ( -v10 < v9 - v10 )
break;
LABEL_9:
v13 = v6 - *a2;
result = (unsigned int)(a1[4] + 1);
a1[4] = result;
if ( (int)result >= v13 )
return result;
}
while ( 1 )
{
result = ft_try_position((__int64)a1, (__int64)a2, a3);
if ( (_DWORD)result == 1 )
break;
v9 = a1[1];
v11 = a1[5] + 1;
v12 = v9 - a2[1];
a1[5] = v11;
if ( v11 >= v12 )
{
v6 = *a1;
goto LABEL_9;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, int *a2, _BYTE *a3)
{
int v5; // edx
int v6; // esi
__int64 result; // rax
int v8; // ecx
int v9; // edx
int v10; // ecx
int v11; // eax
int v12; // ecx
int v13; // ecx

v5 = *a2;
v6 = *a1;
result = (unsigned int)-v5;
v8 = *a1 - v5;
a1[4] = result;
if ( (int)result < v8 )
{
v9 = a1[1];
while ( 1 )
{
v10 = a2[1];
a1[5] = -v10;
if ( -v10 < v9 - v10 )
break;
LABEL_9:
v13 = v6 - *a2;
result = (unsigned int)(a1[4] + 1);
a1[4] = result;
if ( (int)result >= v13 )
return result;
}
while ( 1 )
{
result = func1((__int64)a1, (__int64)a2, a3);
if ( (_DWORD)result == 1 )
break;
v9 = a1[1];
v11 = a1[5] + 1;
v12 = v9 - a2[1];
a1[5] = v11;
if ( v11 >= v12 )
{
v6 = *a1;
goto LABEL_9;
}
}
}
return result;
}

original_code:
static void ft_place_my_piece(t_m *m, t_p *p, t_s *s)
{
 m->gli = -p->li;
 while (m->gli < m->li - p->li)
 {
  m->gco = -p->co;
  while (m->gco < m->co - p->co)
  {
   if (ft_try_position(m, p, s) == 1)
    return ;
   ++m->gco;
  }
  ++m->gli;
 }
}

canonical_original_code:
static void ft_place_my_piece(struct s_m *m, struct s_p *p, struct s_s *s)
{
 m->gli = -p->li;
 while (m->gli < m->li - p->li)
 {
  m->gco = -p->co;
  while (m->gco < m->co - p->co)
  {
   if (ft_try_position(m, p, s) == 1)
    return ;
   ++m->gco;
  }
  ++m->gli;
 }
}

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

user_defined_types: struct s_p { int li; int co; char **fig; }

user_defined_types: struct s_s { char mef; char mel; char opf; char opl; }


decompiled_code:
__int64 __fastcall ft_find_best_position(__int64 a1, int *a2, int *a3, _BYTE *a4)
{
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

v7[0] = a1;
if ( (unsigned int)ft_save_new_map() == -1 )
return 0xFFFFFFFFLL;
get_next_line(0LL, v7);
if ( (unsigned int)ft_save_new_piece(v7[0], a3) == -1 )
return 0xFFFFFFFFLL;
ft_place_my_piece(a2, a3, a4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int *a2, int *a3, _BYTE *a4)
{
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

v7[0] = a1;
if ( (unsigned int)ft_save_new_map() == -1 )
return 0xFFFFFFFFLL;
get_next_line(0LL, v7);
if ( (unsigned int)ft_save_new_piece(v7[0], a3) == -1 )
return 0xFFFFFFFFLL;
func2(a2, a3, a4);
return 0LL;
}

original_code:
static int ft_find_best_position(char *line, t_m *m, t_p *p, t_s *s)
{
 if (ft_save_new_map(line, m) == -1)
  return (-1);
 get_next_line(0, &line);
 if (ft_save_new_piece(line, p) == -1)
  return (-1);
 ft_place_my_piece(m, p, s);
 return (0);
}

canonical_original_code:
static int ft_find_best_position(char *line, struct s_m *m, struct s_p *p, struct s_s *s)
{
 if (ft_save_new_map(line, m) == -1)
  return (-1);
 get_next_line(0, &line);
 if (ft_save_new_piece(line, p) == -1)
  return (-1);
 ft_place_my_piece(m, p, s);
 return (0);
}

variable_types:
line
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rax
int *v4; // rbx
int *v5; // r12
_BYTE *v6; // rax
_BYTE *v7; // rbp
int result; // eax
__int64 v9[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = (int *)malloc(0x20uLL);
if ( !v3 )
return -1;
v4 = v3;
v5 = (int *)malloc(0x10uLL);
if ( !v5 )
return -1;
v6 = malloc(4uLL);
v7 = v6;
if ( !v6 )
return -1;
ft_init_player_info(v6, argv);
while ( 1 )
{
result = get_next_line(0LL, v9);
if ( !result )
break;
if ( *(_BYTE *)v9[0] == 61 )
return 0;
if ( (unsigned int)ft_find_best_position(v9[0], v4, v5, v7) == -1 )
return -1;
ft_putnbr((unsigned int)v4[4]);
ft_putstr(&unk_229);
ft_putnbr((unsigned int)v4[5]);
ft_putchar(10LL);
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rax
int *v4; // rbx
int *v5; // r12
_BYTE *v6; // rax
_BYTE *v7; // rbp
int result; // eax
__int64 v9[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = (int *)malloc(0x20uLL);
if ( !v3 )
return -1;
v4 = v3;
v5 = (int *)malloc(0x10uLL);
if ( !v5 )
return -1;
v6 = malloc(4uLL);
v7 = v6;
if ( !v6 )
return -1;
ft_init_player_info(v6, argv);
while ( 1 )
{
result = get_next_line(0LL, v9);
if ( !result )
break;
if ( *(_BYTE *)v9[0] == 61 )
return 0;
if ( (unsigned int)func3(v9[0], v4, v5, v7) == -1 )
return -1;
ft_putnbr((unsigned int)v4[4]);
ft_putstr(&unk_229);
ft_putnbr((unsigned int)v4[5]);
ft_putchar(10LL);
}
return result;
}

original_code:
int main(void)
{
 char *line;
 t_m *m;
 t_p *p;
 t_s *s;
 if (!(m = (t_m *)malloc(sizeof(*m))) || !(p = (t_p *)malloc(sizeof(*p)))
  || !(s = (t_s *)malloc(sizeof(*s))))
  return (-1);
 ft_init_player_info(s);
 while (get_next_line(0, &line) && line[0] != '=')
 {
  if (ft_find_best_position(line, m, p, s) == -1)
   return (-1);
  ft_putnbr(m->gli);
  ft_putstr(" ");
  ft_putnbr(m->gco);
  ft_putchar('\n');
 }
 return (0);
}

canonical_original_code:
int main()
{
 char *line;
 struct s_m *m;
 struct s_p *p;
 struct s_s *s;
 if (!(m = (struct s_m *)malloc(sizeof(*m))) || !(p = (struct s_p *)malloc(sizeof(*p)))
  || !(s = (struct s_s *)malloc(sizeof(*s))))
  return (-1);
 ft_init_player_info(s);
 while (get_next_line(0, &line) && line[0] != '=')
 {
  if (ft_find_best_position(line, m, p, s) == -1)
   return (-1);
  ft_putnbr(m->gli);
  ft_putstr(" ");
  ft_putnbr(m->gco);
  ft_putchar('\n');
 }
 return (0);
}


original_code:
char *ft_strrchr(const char *s, int c)
{
 size_t i;
 i = ft_strlen(s) - 1;
 if ((char)c == '\0')
  return ((char *)(s + i + 1));
 while (*(s + i))
 {
  if (*(s + i) == (char)c)
   return ((char *)(s + i));
  i--;
 }
 return (((void *)0));
}

canonical_original_code:
char *ft_strrchr(char *s, int c)
{
 unsigned long i;
 i = ft_strlen(s) - 1;
 if ((char)c == '\0')
  return ((char *)(s + i + 1));
 while (*(s + i))
 {
  if (*(s + i) == (char)c)
   return ((char *)(s + i));
  i--;
 }
 return (((void *)0));
}

variable_types:
s
char *

variable_types: c int

variable_types:
i
unsigned long

return_type: char *


decompiled_code:
void __fastcall catch_sign(int a1)
{
if ( a1 == 2 )
{
ft_putstr_fd("\n_$> ", 1LL);
}
else if ( a1 == 11 )
{
ft_putendl_fd("Segmentation fault", 2LL);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 2 )
{
ft_putstr_fd("\n_$> ", 1LL);
}
else if ( a1 == 11 )
{
ft_putendl_fd("Segmentation fault", 2LL);
}
}

original_code:
void catch_sign(int sign)
{
 if (sign == 2)
 {
  ft_putstr_fd("\n_$> ", 1);
  return ;
 }
 if (sign == 11)
 {
  ft_putendl_fd("Segmentation fault", 2);
  return ;
 }
}

variable_types: sign int


decompiled_code:
__int64 ft_check_signal()
{
signal(2, catch_sign);
signal(3, catch_sign);
signal(20, catch_sign);
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
signal(2, catch_sign);
signal(3, catch_sign);
signal(20, catch_sign);
return 1LL;
}

original_code:
int ft_check_signal(void)
{
 signal(2, catch_sign);
 signal(3, catch_sign);
 signal(20, catch_sign);
 return (1);
}

canonical_original_code:
int ft_check_signal()
{
 signal(2, catch_sign);
 signal(3, catch_sign);
 signal(20, catch_sign);
 return (1);
}


original_code:
int ft_nearest_solution(double a, double b, double c, t_r *r)
{
 double delta;
 double q;
 delta = b * b - 4.0 * a * c;
 if (delta < 0)
  return (-1);
 else if (delta == 0)
 {
  r->t0 = (-0.5 * b) / a;
  r->t1 = r->t0;
 }
 else
 {
  q = (b > 0) ? -0.5 * (b + sqrt(delta)) : -0.5 * (b - sqrt(delta));
  r->t0 = q / a;
  r->t1 = c / q;
 }
 if (r->t0 > r->t1)
  ft_swap(&r->t0, &r->t1);
 return (0);
}

canonical_original_code:
int ft_nearest_solution(double a, double b, double c, struct s_r *r)
{
 double delta;
 double q;
 delta = b * b - 4.0 * a * c;
 if (delta < 0)
  return (-1);
 else if (delta == 0)
 {
  r->t0 = (-0.5 * b) / a;
  r->t1 = r->t0;
 }
 else
 {
  q = (b > 0) ? -0.5 * (b + sqrt(delta)) : -0.5 * (b - sqrt(delta));
  r->t0 = q / a;
  r->t1 = c / q;
 }
 if (r->t0 > r->t1)
  ft_swap(&r->t0, &r->t1);
 return (0);
}

variable_types: a double

variable_types: b double

variable_types: c double

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: delta double

variable_types: q double

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


decompiled_code:
char *__fastcall ft_strsplit_bypass(char **a1, char a2)
{
char *result; // rax
char v3; // dl
char v4; // dl

result = *a1;
v3 = **a1;
if ( v3 == a2 && v3 )
{
++result;
do
{
*a1 = result;
v4 = *result++;
}
while ( v4 && v4 == a2 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char **a1, char a2)
{
char *result; // rax
char v3; // dl
char v4; // dl

result = *a1;
v3 = **a1;
if ( v3 == a2 && v3 )
{
++result;
do
{
*a1 = result;
v4 = *result++;
}
while ( v4 && v4 == a2 );
}
return result;
}

original_code:
static void ft_strsplit_bypass(char const **s, char c)
{
 while (*(*s) && *(*s) == c)
  ++(*s);
}

canonical_original_code:
static void ft_strsplit_bypass(char **s, char c)
{
 while (*(*s) && *(*s) == c)
  ++(*s);
}

variable_types:
s
char **

variable_types: c char


original_code:
static size_t ft_strsplit_count(char const *s, char c)
{
 size_t count;
 size_t len;
 count = 0;
 len = 0;
 ft_strsplit_bypass(&s, c);
 while (*s)
 {
  ++len;
  if (*s == c)
  {
   while (*s == c)
    ++s;
   if (*s)
   {
    ++count;
    len = 0;
   }
   --s;
  }
  ++s;
 }
 if (len)
  ++count;
 return (count);
}

canonical_original_code:
static unsigned long ft_strsplit_count(char *s, char c)
{
 unsigned long count;
 unsigned long len;
 count = 0;
 len = 0;
 ft_strsplit_bypass(&s, c);
 while (*s)
 {
  ++len;
  if (*s == c)
  {
   while (*s == c)
    ++s;
   if (*s)
   {
    ++count;
    len = 0;
   }
   --s;
  }
  ++s;
 }
 if (len)
  ++count;
 return (count);
}

variable_types:
count
unsigned long

variable_types:
len
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall ft_strsplit_fill(char *a1, char a2, __int64 a3)
{
char *v4; // rdi
__int64 result; // rax
int v6; // er12
__int64 v7; // rdx
char *v8; // rax
__int64 v9; // rax
__int64 *v10; // r13
__int64 v11; // rax
char *v12; // [rsp+8h] [rbp-30h] BYREF

v12 = a1;
ft_strsplit_bypass(&v12, a2);
v4 = v12;
result = (unsigned __int8)*v12;
if ( (_BYTE)result )
{
v6 = 0;
v7 = 0LL;
do
{
if ( a2 == (_BYTE)result )
{
v9 = v6++;
v10 = (__int64 *)(a3 + 8 * v9);
v11 = ft_strsub(&v4[-v7], 0LL);
v4 = v12;
*v10 = v11;
if ( a2 == *v4 )
{
do
{
v8 = v4++;
v12 = v4;
}
while ( *v4 == a2 );
v7 = 0LL;
}
else
{
v8 = v4 - 1;
v7 = 0LL;
}
}
else
{
v8 = v12;
++v7;
v4 = v12 + 1;
}
v12 = v4;
result = (unsigned __int8)v8[1];
}
while ( (_BYTE)result );
if ( v7 )
{
result = ft_strsub(&v4[-v7], 0LL);
*(_QWORD *)(a3 + 8LL * v6) = result;
}
}
return result;
}

original_code:
static void ft_strsplit_fill(char const *s, char c, char **tab)
{
 size_t len;
 int i;
 i = 0;
 len = 0;
 ft_strsplit_bypass(&s, c);
 while (*s)
 {
  ++len;
  if (*s == c)
  {
   tab[i] = ft_strsub(s - len + 1, 0, len - 1);
   ++i;
   while (*s == c)
    ++s;
   len = 0;
   --s;
  }
  ++s;
 }
 if (!(*s) && len)
  tab[i] = ft_strsub(s - len, 0, len);
}

canonical_original_code:
static void ft_strsplit_fill(char *s, char c, char **tab)
{
 unsigned long len;
 int i;
 i = 0;
 len = 0;
 ft_strsplit_bypass(&s, c);
 while (*s)
 {
  ++len;
  if (*s == c)
  {
   tab[i] = ft_strsub(s - len + 1, 0, len - 1);
   ++i;
   while (*s == c)
    ++s;
   len = 0;
   --s;
  }
  ++s;
 }
 if (!(*s) && len)
  tab[i] = ft_strsub(s - len, 0, len);
}

variable_types:
tab
char **

variable_types: i int


decompiled_code:
__int64 __fastcall ft_putnbr_long(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // r12

if ( a1 > 9 )
{
v2 = ft_putnbr_long(a1 / 0xA);
ft_putchar((unsigned __int8)(a1 % 0xA + 48));
result = v2 + 1;
}
else
{
ft_putchar((unsigned __int8)(a1 + 48));
result = 1LL;
}
return result;
}

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

if ( a1 > 9 )
{
v2 = func0(a1 / 0xA);
ft_putchar((unsigned __int8)(a1 % 0xA + 48));
result = v2 + 1;
}
else
{
ft_putchar((unsigned __int8)(a1 + 48));
result = 1LL;
}
return result;
}

original_code:
ssize_t ft_putnbr_long(unsigned int n)
{
 ssize_t i;
 i = 0;
 if (n <= 9)
  ft_putchar(n + '0');
 else
 {
  i += ft_putnbr_long(n / 10);
  ft_putchar(n % 10 + '0');
 }
 return (i + 1);
}

canonical_original_code:
long ft_putnbr_long(unsigned int n)
{
 long i;
 i = 0;
 if (n <= 9)
  ft_putchar(n + '0');
 else
 {
  i += ft_putnbr_long(n / 10);
  ft_putchar(n % 10 + '0');
 }
 return (i + 1);
}

variable_types:
n
unsigned int

variable_types: i long

return_type: long


decompiled_code:
__int64 __fastcall ft_init_tree(__int64 a1)
{
__int64 v1; // rax

v1 = gmalloc(32LL);
*(_QWORD *)a1 = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
*(_QWORD *)(v1 + 8) = 0LL;
*(_QWORD *)(*(_QWORD *)a1 + 16LL) = 0LL;
*(_QWORD *)(*(_QWORD *)a1 + 24LL) = 0LL;
**(_QWORD **)a1 = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rax

v1 = gmalloc(32LL);
*(_QWORD *)a1 = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
*(_QWORD *)(v1 + 8) = 0LL;
*(_QWORD *)(*(_QWORD *)a1 + 16LL) = 0LL;
*(_QWORD *)(*(_QWORD *)a1 + 24LL) = 0LL;
**(_QWORD **)a1 = 0LL;
return 0LL;
}

canonical_original_code:
int ft_init_tree(struct s_tree **t)
{
 if (!(*t = (struct s_tree *)gmalloc(sizeof(**t))))
  return (-1);
 (*t)->fa = ((void *)0);
 (*t)->le = ((void *)0);
 (*t)->ri = ((void *)0);
 (*t)->p = ((void *)0);
 return (0);
}

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

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


original_code:
int ft_p_list_sub(t_p **list, t_p *start, t_p *end)
{
 t_p *new;
 t_p *move;
 move = ((void *)0);
 while (start != end)
 {
  if (!(new = ft_p_list_new_elem(start->tok, start->type)))
   return (-1);
  if (move)
  {
   move->next = new;
   new->prev = move;
   move = new;
  }
  else
  {
   *list = new;
   move = *list;
  }
  start = start->next;
 }
 return (0);
}

canonical_original_code:
int ft_p_list_sub(struct s_p **list, struct s_p *start, struct s_p *end)
{
 struct s_p *new;
 struct s_p *move;
 move = ((void *)0);
 while (start != end)
 {
  if (!(new = ft_p_list_new_elem(start->tok, start->type)))
   return (-1);
  if (move)
  {
   move->next = new;
   new->prev = move;
   move = new;
  }
  else
  {
   *list = new;
   move = *list;
  }
  start = start->next;
 }
 return (0);
}

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

variable_types:
start
struct s_p *

variable_types:
end
struct s_p *


decompiled_code:
__int64 __fastcall ft_new_tree_elem(__int64 **a1, __int64 a2)
{
__int64 *v3; // rax
__int64 v4; // rax
_QWORD *v5; // rax
__int64 *v6; // rdi
__int64 result; // rax

if ( (unsigned int)ft_init_tree((__int64)(*a1 + 2)) == -1 )
return 0xFFFFFFFFLL;
if ( (unsigned int)ft_init_tree((__int64)(*a1 + 3)) == -1 )
return 0xFFFFFFFFLL;
v3 = *a1;
*(_QWORD *)((*a1)[2] + 8) = *a1;
*(_QWORD *)(v3[3] + 8) = v3;
if ( (unsigned int)ft_p_list_sub((__int64 *)(*a1)[2], **a1, a2) == -1
|| (unsigned int)ft_p_list_sub((__int64 *)(*a1)[3], *(_QWORD *)(a2 + 16), 0LL) == -1 )
{
return 0xFFFFFFFFLL;
}
v4 = **a1;
*(_DWORD *)(v4 + 8) = *(_DWORD *)(a2 + 8);
ft_free_list(*(_QWORD *)(v4 + 16));
v5 = (_QWORD *)**a1;
v5[2] = 0LL;
gfree(*v5);
v6 = *a1;
*(_QWORD *)**a1 = 0LL;
if ( !*(_QWORD *)v6[2] )
goto LABEL_8;
if ( (unsigned int)ft_syntaxical_analyzer(v6 + 2) == -1 )
return 0xFFFFFFFFLL;
v6 = *a1;
LABEL_8:
result = 0LL;
if ( *(_QWORD *)v6[3] )
result = (unsigned int)-((unsigned int)ft_syntaxical_analyzer(v6 + 3) == -1);
return result;
}

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

if ( (unsigned int)func0((__int64)(*a1 + 2)) == -1 )
return 0xFFFFFFFFLL;
if ( (unsigned int)func0((__int64)(*a1 + 3)) == -1 )
return 0xFFFFFFFFLL;
v3 = *a1;
*(_QWORD *)((*a1)[2] + 8) = *a1;
*(_QWORD *)(v3[3] + 8) = v3;
if ( (unsigned int)func2((__int64 *)(*a1)[2], **a1, a2) == -1
|| (unsigned int)func2((__int64 *)(*a1)[3], *(_QWORD *)(a2 + 16), 0LL) == -1 )
{
return 0xFFFFFFFFLL;
}
v4 = **a1;
*(_DWORD *)(v4 + 8) = *(_DWORD *)(a2 + 8);
ft_free_list(*(_QWORD *)(v4 + 16));
v5 = (_QWORD *)**a1;
v5[2] = 0LL;
gfree(*v5);
v6 = *a1;
*(_QWORD *)**a1 = 0LL;
if ( !*(_QWORD *)v6[2] )
goto LABEL_8;
if ( (unsigned int)ft_syntaxical_analyzer(v6 + 2) == -1 )
return 0xFFFFFFFFLL;
v6 = *a1;
LABEL_8:
result = 0LL;
if ( *(_QWORD *)v6[3] )
result = (unsigned int)-((unsigned int)ft_syntaxical_analyzer(v6 + 3) == -1);
return result;
}

canonical_original_code:
int ft_new_tree_elem(struct s_tree **t, struct s_p *keep)
{
 if (ft_init_tree(&((*t)->le)) == -1 || ft_init_tree(&((*t)->ri)) == -1)
  return (-1);
 (*t)->le->fa = *t;
 (*t)->ri->fa = *t;
 if (ft_p_list_sub(&((*t)->le->p), (*t)->p, keep) == -1)
  return (-1);
 if (ft_p_list_sub(&((*t)->ri->p), keep->next, ((void *)0)) == -1)
  return (-1);
 (*t)->p->type = keep->type;
 ft_free_list((*t)->p->next);
 (*t)->p->next = ((void *)0);
 gfree((void *)(*t)->p->tok);
 (*t)->p->tok = ((void *)0);
 if ((*t)->le->p)
 {
  if (ft_syntaxical_analyzer(&((*t)->le)) == -1)
   return (-1);
 }
 if ((*t)->ri->p)
 {
  if (ft_syntaxical_analyzer(&((*t)->ri)) == -1)
   return (-1);
 }
 return (0);
}

variable_types:
keep
struct s_p *

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


decompiled_code:
__int64 __fastcall ft_put_parenthesis_in_tree(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rbx
__int64 v4; // rax
__int64 *v5; // rdi
__int64 v6; // rdx
_QWORD *v7; // rax
__int64 v8; // rax

v2 = *a1;
v3 = *(_QWORD *)v2;
if ( *(_DWORD *)(*(_QWORD *)v2 + 8LL) == 15 && *(_DWORD *)(*(_QWORD *)(v3 + 16) + 8LL) == 16 )
return ft_error_msg("badly placed ", "()'s");
if ( (unsigned int)ft_init_tree(v2 + 16) == -1 )
return 0xFFFFFFFFLL;
v4 = *a1;
v5 = *(__int64 **)(*a1 + 16);
v5[1] = *a1;
do
{
v6 = v3;
v3 = *(_QWORD *)(v3 + 16);
}
while ( v3 );
if ( (unsigned int)ft_p_list_sub(v5, *(_QWORD *)(*(_QWORD *)v4 + 16LL), v6) == -1 )
return 0xFFFFFFFFLL;
ft_free_list(*(_QWORD *)(*(_QWORD *)*a1 + 16LL));
v7 = *(_QWORD **)*a1;
v7[2] = 0LL;
gfree(*v7);
v8 = *(_QWORD *)*a1;
*(_QWORD *)v8 = 0LL;
*(_DWORD *)(v8 + 8) = 17;
return 0LL;
}

original_code:
int ft_put_parenthesis_in_tree(t_tree **t)
{
 t_p *move;
 move = (*t)->p;
 if ((*t)->p->type == 15 && (*t)->p->next->type == 16)
  return (ft_error_msg("badly placed ", "()'s"));
 if (ft_init_tree(&((*t)->le)) == -1)
  return (-1);
 (*t)->le->fa = *t;
 while (move && move->next)
  move = move->next;
 if (ft_p_list_sub(&((*t)->le->p), (*t)->p->next, move) == -1)
  return (-1);
 ft_free_list((*t)->p->next);
 (*t)->p->next = ((void *)0);
 gfree((void *)(*t)->p->tok);
 (*t)->p->tok = ((void *)0);
 (*t)->p->type = 17;
 return (0);
}

canonical_original_code:
int ft_put_parenthesis_in_tree(struct s_tree **t)
{
 struct s_p *move;
 move = (*t)->p;
 if ((*t)->p->type == 15 && (*t)->p->next->type == 16)
  return (ft_error_msg("badly placed ", "()'s"));
 if (ft_init_tree(&((*t)->le)) == -1)
  return (-1);
 (*t)->le->fa = *t;
 while (move && move->next)
  move = move->next;
 if (ft_p_list_sub(&((*t)->le->p), (*t)->p->next, move) == -1)
  return (-1);
 ft_free_list((*t)->p->next);
 (*t)->p->next = ((void *)0);
 gfree((void *)(*t)->p->tok);
 (*t)->p->tok = ((void *)0);
 (*t)->p->type = 17;
 return (0);
}

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


original_code:
int ft_treat_a_box(void *data, t_c *color, t_obj *obj, t_r *r)
{
 t_box *box;
 t_obj *obj2;
 t_r *r2;
 obj2 = obj;
 obj = obj2;
 r2 = r;
 r = r2;
 box = (t_box *)data;
 *color = box->sf;
 return (0);
}

canonical_original_code:
int ft_treat_a_box(void *data, struct s_c *color, struct s_obj *obj, struct s_r *r)
{
 struct s_box *box;
 struct s_obj *obj2;
 struct s_r *r2;
 obj2 = obj;
 obj = obj2;
 r2 = r;
 r = r2;
 box = (struct s_box *)data;
 *color = box->sf;
 return (0);
}

variable_types:
data
void *

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

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: struct s_box { double xmin; double xmax; double ymin; double ymax; double zmin; double zmax; struct s_c { int b; int g; int r; } sf; } *

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

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

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


decompiled_code:
__int64 __fastcall after_options(int a1, __int64 a2)
{
_QWORD *v2; // rsi
int i; // er8
_BYTE *v4; // rax

v2 = (_QWORD *)(a2 + 8);
for ( i = 1; i < a1; ++i )
{
v4 = (_BYTE *)*v2;
if ( *(_BYTE *)*v2 != 45 )
break;
++v2;
if ( v4[1] == 45 )
break;
}
return (unsigned int)i;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2)
{
_QWORD *v2; // rsi
int i; // er8
_BYTE *v4; // rax

v2 = (_QWORD *)(a2 + 8);
for ( i = 1; i < a1; ++i )
{
v4 = (_BYTE *)*v2;
if ( *(_BYTE *)*v2 != 45 )
break;
++v2;
if ( v4[1] == 45 )
break;
}
return (unsigned int)i;
}

original_code:
static int after_options(int argc, char **argv)
{
 int n;
 n = 1;
 while (n < argc)
 {
  if ((argv[n][0] == '-' && argv[n][1] == '-') || argv[n][0] != '-')
   return (n);
  if (argv[n][0] == '-' && argv[n][1] != '-')
   n++;
 }
 return (n);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: n int


decompiled_code:
__int64 __fastcall ft_do_it(__int64 a1, char a2)
{
__int64 v3; // rdi
__int64 v4; // rsi
__int64 v5; // rdi
__int64 result; // rax

r_0 = 1;
if ( (a2 & 1) != 0 )
v3 = ft_create_list_a();
else
v3 = ft_create_list();
v4 = (unsigned int)r_0;
if ( (a2 & 2) != 0 )
{
r_0 = -1;
v4 = 0xFFFFFFFFLL;
}
v5 = ft_sort(v3, v4);
if ( (a2 & 4) != 0 )
v5 = ft_sort_t(v5, (unsigned int)r_0);
if ( (a2 & 8) != 0 )
result = ft_ls_l(v5);
else
result = ft_print_list(v5);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2)
{
__int64 v3; // rdi
__int64 v4; // rsi
__int64 v5; // rdi
__int64 result; // rax

r_0 = 1;
if ( (a2 & 1) != 0 )
v3 = ft_create_list_a();
else
v3 = ft_create_list();
v4 = (unsigned int)r_0;
if ( (a2 & 2) != 0 )
{
r_0 = -1;
v4 = 0xFFFFFFFFLL;
}
v5 = ft_sort(v3, v4);
if ( (a2 & 4) != 0 )
v5 = ft_sort_t(v5, (unsigned int)r_0);
if ( (a2 & 8) != 0 )
result = ft_ls_l(v5);
else
result = ft_print_list(v5);
return result;
}

original_code:
static void ft_do_it(char *dir, int opt)
{
 static int r;
 t_ls *list;
 r = 1;
 if (opt & 1)
  list = ft_create_list_a(dir);
 else
  list = ft_create_list(dir);
 if (opt & 2)
  r = -1;
 list = ft_sort(list, r);
 if (opt & 4)
  list = ft_sort_t(list, r);
 if (opt & 8)
  ft_ls_l(list);
 else
  ft_print_list(list);
}

canonical_original_code:
static void ft_do_it(char *dir, int opt)
{
 static int r;
 struct s_ls *list;
 r = 1;
 if (opt & 1)
  list = ft_create_list_a(dir);
 else
  list = ft_create_list(dir);
 if (opt & 2)
  r = -1;
 list = ft_sort(list, r);
 if (opt & 4)
  list = ft_sort_t(list, r);
 if (opt & 8)
  ft_ls_l(list);
 else
  ft_print_list(list);
}

variable_types:
dir
char *

variable_types: opt int

variable_types: r int

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


decompiled_code:
__int64 __fastcall ft_main_2(int a1, __int64 a2, char a3)
{
int v4; // eax
char v5; // dl
__int64 v6; // rbx
__int64 v7; // rbp
__int64 v8; // r15
__int64 v10; // [rsp+0h] [rbp-38h]

v4 = after_options(a1, a2);
if ( a1 == v4 )
return ft_do_it((__int64)&unk_24C, v5);
if ( a1 == 2 )
return ft_do_it(*(_QWORD *)(a2 + 8LL * v4), v5);
if ( a1 > v4 )
{
v6 = v4;
v7 = v4 + 1LL;
v8 = v7 + (unsigned int)(a1 - 1 - v4);
while ( 1 )
{
ft_putstr(*(_QWORD *)(a2 + 8 * v6));
ft_putendl(&unk_24E);
ft_do_it(*(_QWORD *)(a2 + 8 * v6), a3);
if ( a1 - 1 != (_DWORD)v6 )
ft_putchar(10LL);
v6 = v7;
if ( v7 == v8 )
break;
++v7;
}
}
return v10;
}

original_code:
static void ft_main_2(int argc, char **argv, int opt)
{
 int n;
 n = after_options(argc, argv);
 if (n == argc)
  ft_do_it(".", opt);
 else if (argc == 2)
  ft_do_it(argv[n], opt);
 else
 {
  while (n < argc)
  {
   ft_putstr(argv[n]);
   ft_putendl(":");
   ft_do_it(argv[n], opt);
   if (n != argc - 1)
    ft_putchar('\n');
   n++;
  }
 }
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // al

if ( argc == 1 )
{
ft_do_it((__int64)&unk_24C, 0);
}
else
{
v3 = ft_options(argc, (__int64)argv);
ft_main_2(argc, (__int64)argv, v3);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // al

if ( argc == 1 )
{
func1((__int64)&unk_24C, 0);
}
else
{
v3 = func2(argc, (__int64)argv);
func3(argc, (__int64)argv, v3);
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int opt;
 opt = 0;
 if (argc == 1)
  ft_do_it(".", 0);
 else
 {
  opt = ft_options(argc, argv);
  ft_main_2(argc, argv, opt);
 }
 return (0);
}


decompiled_code:
__int64 __fastcall ft_compare(_QWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v3; // rbx
unsigned int v5; // er12
__int64 v6; // rax
__int64 v7; // rax

if ( !a1 )
return (unsigned int)-1;
v3 = a1;
while ( 1 )
{
v5 = ft_strcmp(*v3, a2);
if ( !v5 )
break;
v3 = (_QWORD *)v3[2];
if ( !v3 )
return (unsigned int)-1;
}
v6 = ft_strlen(a3);
v7 = ft_strnew(v6 + 1);
v3[1] = v7;
if ( v7 )
{
ft_strcpy(v7, a3);
return v5;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v3; // rbx
unsigned int v5; // er12
__int64 v6; // rax
__int64 v7; // rax

if ( !a1 )
return (unsigned int)-1;
v3 = a1;
while ( 1 )
{
v5 = func14(*v3, a2);
if ( !v5 )
break;
v3 = (_QWORD *)v3[2];
if ( !v3 )
return (unsigned int)-1;
}
v6 = func15(a3);
v7 = func10(v6 + 1);
v3[1] = v7;
if ( v7 )
{
ft_strcpy(v7, a3);
return v5;
}
return v5;
}

original_code:
static int ft_compare(t_race *list, char *str1, char *str2)
{
 t_race *tmp;
 tmp = list;
 while (list)
 {
  if (ft_strcmp(list->key, str1) == 0)
  {
   if (!(list->val = ft_strnew(ft_strlen(str2) + 1)))
    return (0);
   ft_strcpy(list->val, str2);
   list = tmp;
   return (0);
  }
  list = list->next;
 }
 list = tmp;
 return (-1);
}

canonical_original_code:
static int ft_compare(struct s_race *list, char *str1, char *str2)
{
 struct s_race *tmp;
 tmp = list;
 while (list)
 {
  if (ft_strcmp(list->key, str1) == 0)
  {
   if (!(list->val = ft_strnew(ft_strlen(str2) + 1)))
    return (0);
   ft_strcpy(list->val, str2);
   list = tmp;
   return (0);
  }
  list = list->next;
 }
 list = tmp;
 return (-1);
}

variable_types: struct s_race { char *key; char *val; struct s_race *next; } *


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

if ( a2 )
{
v2 = a2;
while ( (unsigned int)ft_strcmp(*v2, a1) )
{
v2 = (_QWORD *)v2[2];
if ( !v2 )
goto LABEL_6;
}
result = ft_putendl(v2[1]);
}
else
{
LABEL_6:
ft_putstr(a1);
ft_putstr(&unk_402004);
result = ft_putendl("Not found.");
}
return result;
}

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

if ( a2 )
{
v2 = a2;
while ( (unsigned int)func14(*v2, a1) )
{
v2 = (_QWORD *)v2[2];
if ( !v2 )
goto LABEL_6;
}
result = func12(v2[1]);
}
else
{
LABEL_6:
func13(a1);
func13(&unk_402004);
result = func12("Not found.");
}
return result;
}

original_code:
static void ft_search(char *word, t_race *list)
{
 t_race *tmp;
 tmp = list;
 while (list)
 {
  if (ft_strcmp(list->key, word) == 0)
  {
   ft_putendl(list->val);
   list = tmp;
   return ;
  }
  list = list->next;
 }
 list = tmp;
 ft_putstr(word);
 ft_putstr(": ");
 ft_putendl("Not found.");
}

canonical_original_code:
static void ft_search(char *word, struct s_race *list)
{
 struct s_race *tmp;
 tmp = list;
 while (list)
 {
  if (ft_strcmp(list->key, word) == 0)
  {
   ft_putendl(list->val);
   list = tmp;
   return ;
  }
  list = list->next;
 }
 list = tmp;
 ft_putstr(word);
 ft_putstr(": ");
 ft_putendl("Not found.");
}

variable_types:
word
char *

user_defined_types: struct s_race { char *key; char *val; struct s_race *next; }


decompiled_code:
__int64 __fastcall ft_do_list(void *a1, __int64 *a2, void *a3, void *a4)
{
__int64 *v5; // r13
void *v7; // rbp
__int64 *v8; // rax
__int64 result; // rax
void *ptr[6]; // [rsp+8h] [rbp-30h] BYREF

v5 = a2;
ptr[0] = a1;
free(a1);
free(a3);
free(a4);
while ( (int)get_next_line(0LL, ptr) > 0 && *(_BYTE *)ptr[0] )
{
v7 = (void *)ft_strdup(ptr[0]);
free(ptr[0]);
if ( (int)get_next_line(0LL, ptr) > 0 )
{
a4 = (void *)ft_strdup(ptr[0]);
free(ptr[0]);
if ( (unsigned int)ft_compare(a2, (__int64)v7, (__int64)a4) == -1 )
{
v8 = ft_lst_race((__int64)v7, (__int64)a4);
v5[2] = (__int64)v8;
v5 = v8;
}
}
free(v7);
free(a4);
}
while ( 1 )
{
result = get_next_line(0LL, ptr);
if ( (int)result <= 0 )
break;
ft_search((__int64)ptr[0], a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(void *a1, __int64 *a2, void *a3, void *a4)
{
__int64 *v5; // r13
void *v7; // rbp
__int64 *v8; // rax
__int64 result; // rax
void *ptr[6]; // [rsp+8h] [rbp-30h] BYREF

v5 = a2;
ptr[0] = a1;
free(a1);
free(a3);
free(a4);
while ( (int)func19(0LL, ptr) > 0 && *(_BYTE *)ptr[0] )
{
v7 = (void *)ft_strdup(ptr[0]);
free(ptr[0]);
if ( (int)func19(0LL, ptr) > 0 )
{
a4 = (void *)ft_strdup(ptr[0]);
free(ptr[0]);
if ( (unsigned int)func7(a2, (__int64)v7, (__int64)a4) == -1 )
{
v8 = ft_lst_race((__int64)v7, (__int64)a4);
v5[2] = (__int64)v8;
v5 = v8;
}
}
free(v7);
free(a4);
}
while ( 1 )
{
result = func19(0LL, ptr);
if ( (int)result <= 0 )
break;
func8((__int64)ptr[0], a2);
}
return result;
}

original_code:
static void ft_do_list(char *line, t_race *list, char *str1, char *str2)
{
 t_race *tmp;
 tmp = list;
 free((void *)line);
 free((void *)str1);
 free((void *)str2);
 while (get_next_line(0, &line) > 0 && *(line) != '\0')
 {
  str1 = ft_strdup(line);
  free((void *)line);
  if (get_next_line(0, &line) > 0)
  {
   str2 = ft_strdup(line);
   free((void *)line);
   if (ft_compare(tmp, str1, str2) == -1)
   {
    list->next = ft_lst_race(str1, str2);
    list = list->next;
   }
  }
  free((void *)str1);
  free((void *)str2);
 }
 while (get_next_line(0, &line) > 0)
  ft_search(line, tmp);
}

canonical_original_code:
static void ft_do_list(char *line, struct s_race *list, char *str1, char *str2)
{
 struct s_race *tmp;
 tmp = list;
 free((void *)line);
 free((void *)str1);
 free((void *)str2);
 while (get_next_line(0, &line) > 0 && *(line) != '\0')
 {
  str1 = ft_strdup(line);
  free((void *)line);
  if (get_next_line(0, &line) > 0)
  {
   str2 = ft_strdup(line);
   free((void *)line);
   if (ft_compare(tmp, str1, str2) == -1)
   {
    list->next = ft_lst_race(str1, str2);
    list = list->next;
   }
  }
  free((void *)str1);
  free((void *)str2);
 }
 while (get_next_line(0, &line) > 0)
  ft_search(line, tmp);
}

variable_types:
line
char *


decompiled_code:
void __fastcall ft_strclr(_BYTE *a1)
{
if ( a1 )
{
while ( *a1 )
*a1++ = 0;
}
}

canonical_decompiled_code:
void __fastcall func20(_BYTE *a1)
{
if ( a1 )
{
while ( *a1 )
*a1++ = 0;
}
}

original_code:
void ft_strclr(char *s)
{
 int i;
 if (s == ((void *)0))
  return ;
 i = 0;
 while (*(s + i))
 {
  *(s + i) = '\0';
  i++;
 }
}

variable_types:
s
char *

variable_types: i int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // r13
__int64 v6; // rbx
void *v7; // rdi
void *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = ft_strnew(2uLL);
if ( v3 )
{
v4 = v3;
v5 = ft_strnew(2uLL);
if ( v5 )
{
if ( (int)get_next_line(0LL, ptr) > 0 )
v4 = ft_strdup(ptr[0]);
free(ptr[0]);
if ( (int)get_next_line(0LL, ptr) > 0 )
v5 = ft_strdup(ptr[0]);
v6 = ft_lst_race(v4, v5);
ft_do_list(ptr[0], v6, v4, v5);
while ( v6 )
{
v7 = (void *)v6;
v6 = *(_QWORD *)(v6 + 16);
free(v7);
}
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // r13
__int64 v6; // rbx
void *v7; // rdi
void *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = func10(2uLL);
if ( v3 )
{
v4 = v3;
v5 = func10(2uLL);
if ( v5 )
{
if ( (int)func19(0LL, ptr) > 0 )
v4 = ft_strdup(ptr[0]);
free(ptr[0]);
if ( (int)func19(0LL, ptr) > 0 )
v5 = ft_strdup(ptr[0]);
v6 = ft_lst_race(v4, v5);
func9(ptr[0], v6, v4, v5);
while ( v6 )
{
v7 = (void *)v6;
v6 = *(_QWORD *)(v6 + 16);
free(v7);
}
}
}
return 0;
}

original_code:
int main(void)
{
 char *line;
 t_race *list;
 char *str1;
 char *str2;
 t_race *tmp;
 if (!(str1 = ft_strnew(2)) || !(str2 = ft_strnew(2)))
  return (0);
 if (get_next_line(0, &line) > 0)
  str1 = ft_strdup(line);
 free((void *)line);
 if (get_next_line(0, &line) > 0)
  str2 = ft_strdup(line);
 list = ft_lst_race(str1, str2);
 tmp = list;
 ft_do_list(line, list, str1, str2);
 while ((list = tmp))
 {
  tmp = tmp->next;
  list->key = ((void *)0);
  list->val = ((void *)0);
  list->next = ((void *)0);
  free((void *)list);
 }
 return (0);
}

canonical_original_code:
int main()
{
 char *line;
 struct s_race *list;
 char *str1;
 char *str2;
 struct s_race *tmp;
 if (!(str1 = ft_strnew(2)) || !(str2 = ft_strnew(2)))
  return (0);
 if (get_next_line(0, &line) > 0)
  str1 = ft_strdup(line);
 free((void *)line);
 if (get_next_line(0, &line) > 0)
  str2 = ft_strdup(line);
 list = ft_lst_race(str1, str2);
 tmp = list;
 ft_do_list(line, list, str1, str2);
 while ((list = tmp))
 {
  tmp = tmp->next;
  list->key = ((void *)0);
  list->val = ((void *)0);
  list->next = ((void *)0);
  free((void *)list);
 }
 return (0);
}


original_code:
int ft_treat_a_disk(void *data, t_c *color, t_obj *obj, t_r *r)
{
 t_dis *dis;
 double mult;
 t_v tmp;
 dis = (t_dis *)data;
 ft_mult_vect_by_nb(&r->p_hit, r->d_w, r->tnear);
 ft_vect_sum(&r->p_hit, r->p_hit, r->o_w);
 r->n_hit = dis->n;
 ft_normalize_vect(&r->n_hit);
 ft_mult_vect_by_nb(&tmp, r->n_hit, (0.0001));
 ft_vect_sum(&r->p_hit, tmp, r->p_hit);
 mult = ft_hit_light(r, obj);
 ft_init_color(color, dis->sf.b * mult, dis->sf.g * mult, dis->sf.r * mult);
 return (0);
}

canonical_original_code:
int ft_treat_a_disk(void *data, struct s_c *color, struct s_obj *obj, struct s_r *r)
{
 struct s_dis *dis;
 double mult;
 struct s_v tmp;
 dis = (struct s_dis *)data;
 ft_mult_vect_by_nb(&r->p_hit, r->d_w, r->tnear);
 ft_vect_sum(&r->p_hit, r->p_hit, r->o_w);
 r->n_hit = dis->n;
 ft_normalize_vect(&r->n_hit);
 ft_mult_vect_by_nb(&tmp, r->n_hit, (0.0001));
 ft_vect_sum(&r->p_hit, tmp, r->p_hit);
 mult = ft_hit_light(r, obj);
 ft_init_color(color, dis->sf.b * mult, dis->sf.g * mult, dis->sf.r * mult);
 return (0);
}

variable_types:
data
void *

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

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: struct s_dis { struct s_v { double x; double y; double z; } c; struct s_v n; double r; struct s_c { int b; int g; int r; } sf; } *

variable_types: mult double

user_defined_types: struct s_dis { struct s_v c; struct s_v n; double r; struct s_c sf; }


decompiled_code:
__int64 __fastcall ft_size_word(__int64 a1, char a2, int a3)
{
__int64 result; // rax
_BYTE *v4; // rdi

if ( a2 == *(_BYTE *)(a1 + a3) )
return 0LL;
result = 0LL;
v4 = (_BYTE *)(a3 + 1 + a1);
do
{
if ( !*v4 )
break;
v4 += 2;
result = (unsigned int)(result + 1);
}
while ( *(v4 - 1) != a2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, int a3)
{
__int64 result; // rax
_BYTE *v4; // rdi

if ( a2 == *(_BYTE *)(a1 + a3) )
return 0LL;
result = 0LL;
v4 = (_BYTE *)(a3 + 1 + a1);
do
{
if ( !*v4 )
break;
v4 += 2;
result = (unsigned int)(result + 1);
}
while ( *(v4 - 1) != a2 );
return result;
}

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

canonical_original_code:
static int ft_size_word(char *s, char c, int i)
{
 int m;
 m = 0;
 while (*(s + i++) != c && *(s + i++))
  m++;
 return (m);
}

variable_types: c char

variable_types: m int


decompiled_code:
__int64 __fastcall ft_error_msg(__int64 a1, __int64 a2)
{
ft_putstr_fd(a1, 2LL);
ft_putendl_fd(a2, 2LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
ft_putstr_fd(a1, 2LL);
ft_putendl_fd(a2, 2LL);
return 0xFFFFFFFFLL;
}

original_code:
int ft_error_msg(char *s1, char *s2)
{
 ft_putstr_fd(s1, 2);
 ft_putendl_fd(s2, 2);
 return (-1);
}


original_code:
int ft_check_wrong_nb_of_pth(t_p *p)
{
 t_p *move;
 int ind_pth;
 ind_pth = 0;
 move = p;
 while (move)
 {
  if ((move->type == 15 && move->prev
   && (move->prev->type == 11 || move->prev->type == 16))
   || (move->type == 16 && move->next
    && (move->next->type == 11 || move->next->type == 15)))
   return (ft_error_msg("Badly placed ", "()'s"));
  if (move->type == 15)
   ++ind_pth;
  if (move->type == 16)
   --ind_pth;
  if (ind_pth < 0)
   return (ft_error_msg("Too many ", ")'s."));
  move = move->next;
 }
 if (ind_pth > 0)
  return (ft_error_msg("Too many ", "('s."));
 return (0);
}

canonical_original_code:
int ft_check_wrong_nb_of_pth(struct s_p *p)
{
 struct s_p *move;
 int ind_pth;
 ind_pth = 0;
 move = p;
 while (move)
 {
  if ((move->type == 15 && move->prev
   && (move->prev->type == 11 || move->prev->type == 16))
   || (move->type == 16 && move->next
    && (move->next->type == 11 || move->next->type == 15)))
   return (ft_error_msg("Badly placed ", "()'s"));
  if (move->type == 15)
   ++ind_pth;
  if (move->type == 16)
   --ind_pth;
  if (ind_pth < 0)
   return (ft_error_msg("Too many ", ")'s."));
  move = move->next;
 }
 if (ind_pth > 0)
  return (ft_error_msg("Too many ", "('s."));
 return (0);
}

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


decompiled_code:
__int64 __fastcall ft_syntaxical_analyzer(__int64 ***a1)
{
__int64 *v1; // rax
__int64 result; // rax
unsigned int v3; // [rsp+4h] [rbp-14h] BYREF
__int64 *v4; // [rsp+8h] [rbp-10h] BYREF

v1 = **a1;
v3 = 0;
v4 = v1;
ft_find_priority_operand(&v4, &v3);
result = v3;
if ( v3 )
{
if ( v4[2] && v4[3] )
result = (unsigned int)-((unsigned int)ft_new_tree_elem(a1) == -1);
else
result = ft_error_msg((__int64)"Badly placed ", *v4);
}
else if ( *((_DWORD *)**a1 + 2) == 15 )
{
result = ft_put_parenthesis_in_tree(a1);
if ( (_DWORD)result != -1 )
result = ft_syntaxical_analyzer(*a1 + 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 ***a1)
{
__int64 *v1; // rax
__int64 result; // rax
unsigned int v3; // [rsp+4h] [rbp-14h] BYREF
__int64 *v4; // [rsp+8h] [rbp-10h] BYREF

v1 = **a1;
v3 = 0;
v4 = v1;
ft_find_priority_operand(&v4, &v3);
result = v3;
if ( v3 )
{
if ( v4[2] && v4[3] )
result = (unsigned int)-((unsigned int)ft_new_tree_elem(a1) == -1);
else
result = func0((__int64)"Badly placed ", *v4);
}
else if ( *((_DWORD *)**a1 + 2) == 15 )
{
result = ft_put_parenthesis_in_tree(a1);
if ( (_DWORD)result != -1 )
result = func2(*a1 + 2);
}
return result;
}

original_code:
int ft_syntaxical_analyzer(t_tree **t)
{
 int ind_pth;
 t_p *keep;
 int type;
 ind_pth = 0;
 keep = (*t)->p;
 type = 0;
 ft_find_priority_operand(&keep, &type);
 if (type == 0 && (*t)->p->type != 15)
  return (0);
 else if (type == 0)
 {
  if (ft_put_parenthesis_in_tree(t) == -1)
   return (-1);
  return (ft_syntaxical_analyzer(&((*t)->le)));
 }
 if (!keep->next || !keep->prev)
  return (ft_error_msg("Badly placed ", keep->tok));
 if (ft_new_tree_elem(t, keep) == -1)
  return (-1);
 return (0);
}

canonical_original_code:
int ft_syntaxical_analyzer(struct s_tree **t)
{
 int ind_pth;
 struct s_p *keep;
 int type;
 ind_pth = 0;
 keep = (*t)->p;
 type = 0;
 ft_find_priority_operand(&keep, &type);
 if (type == 0 && (*t)->p->type != 15)
  return (0);
 else if (type == 0)
 {
  if (ft_put_parenthesis_in_tree(t) == -1)
   return (-1);
  return (ft_syntaxical_analyzer(&((*t)->le)));
 }
 if (!keep->next || !keep->prev)
  return (ft_error_msg("Badly placed ", keep->tok));
 if (ft_new_tree_elem(t, keep) == -1)
  return (-1);
 return (0);
}

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

variable_types: type int


decompiled_code:
__int64 __fastcall ft_do_line(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbp
int v3; // ebx
_BYTE *v4; // rax
__int64 v5; // rbx
int v6; // er14
__int64 v7; // r13

v2 = a2;
v3 = ft_slist_len(a2);
if ( *a1 )
((void (*)(void))gfree)();
v4 = (_BYTE *)gmalloc(v3 + 1);
*a1 = v4;
if ( !v4 )
return 0xFFFFFFFFLL;
if ( a2 )
{
v5 = 0LL;
while ( 1 )
{
v6 = v5;
v4[v5] = *(_BYTE *)v2;
v7 = *(_QWORD *)(v2 + 8);
++v5;
gfree(v2);
if ( !v7 )
break;
v4 = (_BYTE *)*a1;
v2 = v7;
}
v4 = (_BYTE *)(*a1 + v6 + 1);
}
*v4 = 0;
ft_putchar_fd(10LL, 1LL);
return 0LL;
}

original_code:
int ft_do_line(char **line, t_sl *list)
{
 int i;
 t_sl *move;
 move = list;
 i = ft_slist_len(move);
 if (*line)
  gfree((void *)*line);
 if (!(*line = (char *)gmalloc(sizeof(char) * (i + 1))))
  return (-1);
 i = -1;
 while (move)
 {
  (*line)[++i] = move->c;
  move = move->next;
  gfree((void *)list);
  list = move;
 }
 (*line)[++i] = '\0';
 ft_putchar_fd('\n', 1);
 return (0);
}

canonical_original_code:
int ft_do_line(char **line, struct s_sl *list)
{
 int i;
 struct s_sl *move;
 move = list;
 i = ft_slist_len(move);
 if (*line)
  gfree((void *)*line);
 if (!(*line = (char *)gmalloc(sizeof(char) * (i + 1))))
  return (-1);
 i = -1;
 while (move)
 {
  (*line)[++i] = move->c;
  move = move->next;
  gfree((void *)list);
  list = move;
 }
 (*line)[++i] = '\0';
 ft_putchar_fd('\n', 1);
 return (0);
}

variable_types:
line
char **

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


decompiled_code:
__int64 __fastcall ft_init_player_info(_BYTE *a1)
{
__int64 v1; // rbp
void *ptr; // [rsp+8h] [rbp-20h] BYREF

get_next_line(0LL, &ptr);
v1 = ft_strsplit(ptr, 32LL);
if ( (unsigned int)ft_strcmp(*(_QWORD *)(v1 + 16), &unk_D3) )
{
if ( (unsigned int)ft_strcmp(*(_QWORD *)(v1 + 16), &unk_D6) )
ft_putendl_fd("Wrong player info line", 2LL);
else
ft_init_symbols(a1, 88, 79);
}
else
{
ft_init_symbols(a1, 79, 88);
}
free(ptr);
return ft_free_chtab(v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
__int64 v1; // rbp
void *ptr; // [rsp+8h] [rbp-20h] BYREF

get_next_line(0LL, &ptr);
v1 = ft_strsplit(ptr, 32LL);
if ( (unsigned int)ft_strcmp(*(_QWORD *)(v1 + 16), &unk_D3) )
{
if ( (unsigned int)ft_strcmp(*(_QWORD *)(v1 + 16), &unk_D6) )
ft_putendl_fd("Wrong player info line", 2LL);
else
func0(a1, 88, 79);
}
else
{
func0(a1, 79, 88);
}
free(ptr);
return ft_free_chtab(v1);
}

original_code:
void ft_init_player_info(t_s *s)
{
 char *line;
 char **tmp;
 get_next_line(0, &line);
 tmp = ft_strsplit(line, ' ');
 if (!ft_strcmp(tmp[2], "p1"))
  ft_init_symbols(s, 'O', 'X');
 else if (!ft_strcmp(tmp[2], "p2"))
  ft_init_symbols(s, 'X', 'O');
 else
  ft_putendl_fd("Wrong player info line", 2);
 free((void *)line);
 ft_free_chtab(tmp);
}

canonical_original_code:
void ft_init_player_info(struct s_s *s)
{
 char *line;
 char **tmp;
 get_next_line(0, &line);
 tmp = ft_strsplit(line, ' ');
 if (!ft_strcmp(tmp[2], "p1"))
  ft_init_symbols(s, 'O', 'X');
 else if (!ft_strcmp(tmp[2], "p2"))
  ft_init_symbols(s, 'X', 'O');
 else
  ft_putendl_fd("Wrong player info line", 2);
 free((void *)line);
 ft_free_chtab(tmp);
}

variable_types: struct s_s { char mef; char mel; char opf; char opl; } *

variable_types:
tmp
char **


decompiled_code:
__int64 __fastcall ft_treat_a_cone(int *a1, __int64 a2, __int64 a3, double *a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
double *v12; // r14
double v15; // xmm0_8
double v16; // xmm4_8
double v17; // xmm5_8
double v18; // xmm0_8

v12 = a4 + 6;
ft_mult_vect_by_nb(a4 + 6, a4[14]);
v15 = ft_vect_sum(v12);
ft_init_normal((__int64)(a4 + 9), (__int64)a1, v15, a6, a7, a8, v16, v17, a11, a12, a4[6], a4[7], a4[8]);
ft_normalize_vect();
v18 = ft_hit_light(a4, a3);
ft_init_color(
a2,
(unsigned int)(int)(v18 * (double)a1[6]),
(unsigned int)(int)((double)a1[7] * v18),
(unsigned int)(int)((double)a1[8] * v18));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, __int64 a2, __int64 a3, double *a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
double *v12; // r14
double v15; // xmm0_8
double v16; // xmm4_8
double v17; // xmm5_8
double v18; // xmm0_8

v12 = a4 + 6;
ft_mult_vect_by_nb(a4 + 6, a4[14]);
v15 = ft_vect_sum(v12);
func0((__int64)(a4 + 9), (__int64)a1, v15, a6, a7, a8, v16, v17, a11, a12, a4[6], a4[7], a4[8]);
ft_normalize_vect();
v18 = ft_hit_light(a4, a3);
ft_init_color(
a2,
(unsigned int)(int)(v18 * (double)a1[6]),
(unsigned int)(int)((double)a1[7] * v18),
(unsigned int)(int)((double)a1[8] * v18));
return 0LL;
}

original_code:
int ft_treat_a_cone(void *data, t_c *color, t_obj *obj, t_r *r)
{
 t_con *con;
 double mult;
 con = (t_con *)data;
 ft_mult_vect_by_nb(&r->p_hit, r->d_w, r->tnear);
 ft_vect_sum(&r->p_hit, r->p_hit, r->o_w);
 ft_init_normal(&r->n_hit, r->p_hit, con);
 ft_normalize_vect(&r->n_hit);
 mult = ft_hit_light(r, obj);
 ft_init_color(color, con->sf.b * mult, con->sf.g * mult, con->sf.r * mult);
 return (0);
}

canonical_original_code:
int ft_treat_a_cone(void *data, struct s_c *color, struct s_obj *obj, struct s_r *r)
{
 struct s_con *con;
 double mult;
 con = (struct s_con *)data;
 ft_mult_vect_by_nb(&r->p_hit, r->d_w, r->tnear);
 ft_vect_sum(&r->p_hit, r->p_hit, r->o_w);
 ft_init_normal(&r->n_hit, r->p_hit, con);
 ft_normalize_vect(&r->n_hit);
 mult = ft_hit_light(r, obj);
 ft_init_color(color, con->sf.b * mult, con->sf.g * mult, con->sf.r * mult);
 return (0);
}

variable_types:
r
struct s_r *

variable_types: struct s_con { struct s_v { double x; double y; double z; } c; struct s_c { int b; int g; int r; } sf; char flag; double cst; } *

user_defined_types: struct s_con { struct s_v c; struct s_c sf; char flag; double cst; }


decompiled_code:
__int64 __fastcall ft_init_normal(__int64 a1, __int64 a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13)
{
__int64 result; // rax
double v10; // xmm2_8
double v11; // xmm0_8
double v12; // xmm1_8
double v13; // xmm0_8
double v14; // xmm1_8
double v15; // xmm2_8

result = *(unsigned __int8 *)(a2 + 36);
switch ( (_BYTE)result )
{
case 'x':
v12 = a12 - *(double *)(a2 + 8);
v13 = a13 - *(double *)(a2 + 16);
*(_QWORD *)a1 = 0LL;
*(double *)(a1 + 8) = v12;
*(double *)(a1 + 16) = v13;
break;
case 'y':
v10 = a11 - *(double *)a2;
v11 = a13 - *(double *)(a2 + 16);
*(_QWORD *)(a1 + 8) = 0LL;
*(double *)a1 = v10;
*(double *)(a1 + 16) = v11;
break;
case 'z':
v14 = a12 - *(double *)(a2 + 8);
v15 = a11 - *(double *)a2;
*(_QWORD *)(a1 + 16) = 0LL;
*(double *)(a1 + 8) = v14;
*(double *)a1 = v15;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13)
{
__int64 result; // rax
double v10; // xmm2_8
double v11; // xmm0_8
double v12; // xmm1_8
double v13; // xmm0_8
double v14; // xmm1_8
double v15; // xmm2_8

result = *(unsigned __int8 *)(a2 + 36);
switch ( (_BYTE)result )
{
case 'x':
v12 = a12 - *(double *)(a2 + 8);
v13 = a13 - *(double *)(a2 + 16);
*(_QWORD *)a1 = 0LL;
*(double *)(a1 + 8) = v12;
*(double *)(a1 + 16) = v13;
break;
case 'y':
v10 = a11 - *(double *)a2;
v11 = a13 - *(double *)(a2 + 16);
*(_QWORD *)(a1 + 8) = 0LL;
*(double *)a1 = v10;
*(double *)(a1 + 16) = v11;
break;
case 'z':
v14 = a12 - *(double *)(a2 + 8);
v15 = a11 - *(double *)a2;
*(_QWORD *)(a1 + 16) = 0LL;
*(double *)(a1 + 8) = v14;
*(double *)a1 = v15;
break;
}
return result;
}

original_code:
void ft_init_normal(t_v *n_hit, t_v p_hit, t_con *con)
{
 if (con->flag == 'x')
 {
  n_hit->x = 0;
  n_hit->y = p_hit.y - con->c.y;
  n_hit->z = p_hit.z - con->c.z;
 }
 else if (con->flag == 'y')
 {
  n_hit->y = 0;
  n_hit->x = p_hit.x - con->c.x;
  n_hit->z = p_hit.z - con->c.z;
 }
 else if (con->flag == 'z')
 {
  n_hit->z = 0;
  n_hit->y = p_hit.y - con->c.y;
  n_hit->x = p_hit.x - con->c.x;
 }
}

canonical_original_code:
void ft_init_normal(struct s_v *n_hit, struct s_v p_hit, struct s_con *con)
{
 if (con->flag == 'x')
 {
  n_hit->x = 0;
  n_hit->y = p_hit.y - con->c.y;
  n_hit->z = p_hit.z - con->c.z;
 }
 else if (con->flag == 'y')
 {
  n_hit->y = 0;
  n_hit->x = p_hit.x - con->c.x;
  n_hit->z = p_hit.z - con->c.z;
 }
 else if (con->flag == 'z')
 {
  n_hit->z = 0;
  n_hit->y = p_hit.y - con->c.y;
  n_hit->x = p_hit.x - con->c.x;
 }
}

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

variable_types: struct s_con { struct s_v c; struct s_c { int b; int g; int r; } sf; char flag; double cst; } *


decompiled_code:
__int64 __fastcall ft_intersect_a_disk(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
double v6; // xmm0_8
__int64 v7; // rdx
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // r9
double v11; // xmm0_8
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // r8
__int64 v15; // r9
__int64 v17; // [rsp+10h] [rbp-78h] BYREF
__int64 v18; // [rsp+30h] [rbp-58h] BYREF
__int64 v19; // [rsp+50h] [rbp-38h] BYREF

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

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

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

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

variable_types:
data
void *

variable_types: denom double


original_code:
static int ft_find_sphere_inter(t_r *r, t_sph *sph)
{
 t_v o_to_c;
 double a;
 double b;
 double c;
 ft_vect_difference(&o_to_c, r->o_w, sph->c);
 a = ft_dot_product(r->d_w, r->d_w);
 b = 2 * ft_dot_product(r->d_w, o_to_c);
 c = ft_dot_product(o_to_c, o_to_c) - sph->r * sph->r;
 if (ft_nearest_solution(a, b, c, r) == -1)
  return (-1);
 if (r->t1 < 0)
  return (-1);
 if (r->t0 < 0)
  r->t0 = r->t1;
 return (0);
}

canonical_original_code:
static int ft_find_sphere_inter(struct s_r *r, struct s_sph *sph)
{
 struct s_v o_to_c;
 double a;
 double b;
 double c;
 ft_vect_difference(&o_to_c, r->o_w, sph->c);
 a = ft_dot_product(r->d_w, r->d_w);
 b = 2 * ft_dot_product(r->d_w, o_to_c);
 c = ft_dot_product(o_to_c, o_to_c) - sph->r * sph->r;
 if (ft_nearest_solution(a, b, c, r) == -1)
  return (-1);
 if (r->t1 < 0)
  return (-1);
 if (r->t0 < 0)
  r->t0 = r->t1;
 return (0);
}

variable_types: struct s_sph { struct s_v c; double r; struct s_c sf; struct s_c em; double trsp; double refl; double ior; } *

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

variable_types: a double

variable_types: b double

variable_types: c double


decompiled_code:
__int64 __fastcall ft_intersect_a_sphere(__int64 a1, __int64 a2)
{
return (unsigned int)-((unsigned int)ft_find_sphere_inter(a1, a2) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return (unsigned int)-((unsigned int)func0(a1, a2) == -1);
}

original_code:
int ft_intersect_a_sphere(t_r *r, void *data)
{
 t_sph *sph;
 sph = (t_sph *)data;
 if (ft_find_sphere_inter(r, sph) == -1)
  return (-1);
 return (0);
}

canonical_original_code:
int ft_intersect_a_sphere(struct s_r *r, void *data)
{
 struct s_sph *sph;
 sph = (struct s_sph *)data;
 if (ft_find_sphere_inter(r, sph) == -1)
  return (-1);
 return (0);
}

variable_types: struct s_sph { struct s_v { double x; double y; double z; } c; double r; struct s_c { int b; int g; int r; } sf; struct s_c em; double trsp; double refl; double ior; } *

user_defined_types: struct s_sph { struct s_v c; double r; struct s_c sf; struct s_c em; double trsp; double refl; double ior; }


decompiled_code:
__int64 __fastcall ft_free_list(_QWORD *a1)
{
_QWORD *i; // rbp
_QWORD *v2; // rdi
_QWORD *v3; // rbx
__int64 result; // rax

if ( a1 )
{
for ( i = a1; ; i = v3 )
{
v3 = (_QWORD *)i[2];
if ( !v3 )
break;
v2 = (_QWORD *)v3[3];
if ( *v2 )
{
gfree(*v2);
v2 = (_QWORD *)v3[3];
}
gfree(v2);
}
if ( *i )
gfree(*i);
result = gfree(i);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
_QWORD *i; // rbp
_QWORD *v2; // rdi
_QWORD *v3; // rbx
__int64 result; // rax

if ( a1 )
{
for ( i = a1; ; i = v3 )
{
v3 = (_QWORD *)i[2];
if ( !v3 )
break;
v2 = (_QWORD *)v3[3];
if ( *v2 )
{
gfree(*v2);
v2 = (_QWORD *)v3[3];
}
gfree(v2);
}
if ( *i )
gfree(*i);
result = gfree(i);
}
return result;
}

original_code:
void ft_free_list(t_p *move)
{
 while (move && move->next)
 {
  move = move->next;
  if (move->prev->tok)
   gfree((void *)move->prev->tok);
  gfree((void *)move->prev);
 }
 if (move && move->tok)
  gfree((void *)move->tok);
 if (move)
  gfree((void *)move);
}

canonical_original_code:
void ft_free_list(struct s_p *move)
{
 while (move && move->next)
 {
  move = move->next;
  if (move->prev->tok)
   gfree((void *)move->prev->tok);
  gfree((void *)move->prev);
 }
 if (move && move->tok)
  gfree((void *)move->tok);
 if (move)
  gfree((void *)move);
}

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


decompiled_code:
__int64 __fastcall ft_free_tree(_QWORD *a1)
{
__int64 v2; // rdi

v2 = *a1;
if ( *(_QWORD *)(v2 + 16) )
{
ft_free_tree(v2 + 16);
v2 = *a1;
}
if ( *(_QWORD *)(v2 + 24) )
{
ft_free_tree(v2 + 24);
v2 = *a1;
}
ft_free_list(*(_QWORD **)v2);
return gfree(*a1);
}

original_code:
void ft_free_tree(t_tree **t)
{
 if ((*t)->le)
  ft_free_tree(&((*t)->le));
 if ((*t)->ri)
  ft_free_tree(&((*t)->ri));
 ft_free_list((*t)->p);
 gfree((void *)*t);
}

canonical_original_code:
void ft_free_tree(struct s_tree **t)
{
 if ((*t)->le)
  ft_free_tree(&((*t)->le));
 if ((*t)->ri)
  ft_free_tree(&((*t)->ri));
 ft_free_list((*t)->p);
 gfree((void *)*t);
}

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


decompiled_code:
__int64 __fastcall ft_historic(__int64 a1, __int64 *a2, _DWORD *a3, char ***a4)
{
int v6; // ecx
__int64 result; // rax
int v8; // er8
int v9; // edx

if ( (unsigned int)ft_is_key_arrow_up() && *a4 )
{
if ( !a3[1] )
{
v6 = 0;
LABEL_5:
ft_move_hist(a4, a3, a2, v6);
return 0LL;
}
result = 0LL;
if ( (*a4)[1] )
{
v6 = 1;
goto LABEL_5;
}
}
else
{
v8 = ft_is_key_arrow_down(a1);
result = 1LL;
if ( v8 )
{
if ( *a4 )
{
v9 = a3[1];
if ( v9 > 0 )
{
if ( v9 == 1 )
{
*a2 = 0LL;
result = 0LL;
*(_QWORD *)a3 = 0LL;
}
else
{
ft_move_hist(a4, a3, a2, -1);
result = 0LL;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 *a2, _DWORD *a3, char ***a4)
{
int v6; // ecx
__int64 result; // rax
int v8; // er8
int v9; // edx

if ( (unsigned int)ft_is_key_arrow_up() && *a4 )
{
if ( !a3[1] )
{
v6 = 0;
LABEL_5:
func1(a4, a3, a2, v6);
return 0LL;
}
result = 0LL;
if ( (*a4)[1] )
{
v6 = 1;
goto LABEL_5;
}
}
else
{
v8 = ft_is_key_arrow_down(a1);
result = 1LL;
if ( v8 )
{
if ( *a4 )
{
v9 = a3[1];
if ( v9 > 0 )
{
if ( v9 == 1 )
{
*a2 = 0LL;
result = 0LL;
*(_QWORD *)a3 = 0LL;
}
else
{
func1(a4, a3, a2, -1);
result = 0LL;
}
}
}
}
}
return result;
}

original_code:
int ft_historic(char *buf, t_sl **list, t_save *save, t_hl **hlist)
{
 if (ft_is_key_arrow_up(buf) && *hlist)
 {
  if (save->cursor_hl && (*hlist)->next)
   ft_move_hist(hlist, save, list, 1);
  else if (save->cursor_hl == 0)
   ft_move_hist(hlist, save, list, 0);
 }
 else if (ft_is_key_arrow_down(buf) && *hlist && save->cursor_hl > 0)
 {
  if (save->cursor_hl > 1)
   ft_move_hist(hlist, save, list, -1);
  else
  {
   *list = ((void *)0);
   save->cursor_l = 0;
   save->cursor_hl = 0;
  }
 }
 else
  return (1);
 return (0);
}

canonical_original_code:
int ft_historic(char *buf, struct s_sl **list, struct s_save *save, struct s_hl **hlist)
{
 if (ft_is_key_arrow_up(buf) && *hlist)
 {
  if (save->cursor_hl && (*hlist)->next)
   ft_move_hist(hlist, save, list, 1);
  else if (save->cursor_hl == 0)
   ft_move_hist(hlist, save, list, 0);
 }
 else if (ft_is_key_arrow_down(buf) && *hlist && save->cursor_hl > 0)
 {
  if (save->cursor_hl > 1)
   ft_move_hist(hlist, save, list, -1);
  else
  {
   *list = ((void *)0);
   save->cursor_l = 0;
   save->cursor_hl = 0;
  }
 }
 else
  return (1);
 return (0);
}

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


original_code:
int ft_put_in_hist(t_hl **hlist, t_sl *list)
{
 t_hl *new_elem;
 if (!list)
  return (0);
 if (!(new_elem = ft_hlist_new_elem(list)))
  return (-1);
 if (!*hlist)
  *hlist = new_elem;
 else
 {
  new_elem->next = *hlist;
  (*hlist)->prev = new_elem;
  *hlist = new_elem;
 }
 return (0);
}

canonical_original_code:
int ft_put_in_hist(struct s_hl **hlist, struct s_sl *list)
{
 struct s_hl *new_elem;
 if (!list)
  return (0);
 if (!(new_elem = ft_hlist_new_elem(list)))
  return (-1);
 if (!*hlist)
  *hlist = new_elem;
 else
 {
  new_elem->next = *hlist;
  (*hlist)->prev = new_elem;
  *hlist = new_elem;
 }
 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:
list
struct s_sl *

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


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

v1 = ft_list_new_elem((unsigned int)*a1);
if ( v1 )
{
v2 = (char *)*((_QWORD *)a1 + 1);
v3 = v1;
if ( !v2 )
return v3;
while ( 1 )
{
v4 = v1;
v1 = ft_list_new_elem((unsigned int)*v2);
*(_QWORD *)(v4 + 8) = v1;
if ( !v1 )
break;
v2 = (char *)*((_QWORD *)v2 + 1);
*(_QWORD *)(v1 + 16) = v4;
if ( !v2 )
return v3;
}
}
return 0LL;
}

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

v1 = ft_list_new_elem((unsigned int)*a1);
if ( v1 )
{
v2 = (char *)*((_QWORD *)a1 + 1);
v3 = v1;
if ( !v2 )
return v3;
while ( 1 )
{
v4 = v1;
v1 = ft_list_new_elem((unsigned int)*v2);
*(_QWORD *)(v4 + 8) = v1;
if ( !v1 )
break;
v2 = (char *)*((_QWORD *)v2 + 1);
*(_QWORD *)(v1 + 16) = v4;
if ( !v2 )
return v3;
}
}
return 0LL;
}

original_code:
t_sl *ft_listdup(t_sl *list)
{
 t_sl *new;
 t_sl *move;
 if (!(new = ft_list_new_elem(list->c)))
  return (((void *)0));
 move = new;
 list = list->next;
 while (list)
 {
  if (!(move->next = ft_list_new_elem(list->c)))
   return (((void *)0));
  move->next->prev = move;
  move = move->next;
  list = list->next;
 }
 return (new);
}

canonical_original_code:
struct s_sl *ft_listdup(struct s_sl *list)
{
 struct s_sl *new;
 struct s_sl *move;
 if (!(new = ft_list_new_elem(list->c)))
  return (((void *)0));
 move = new;
 list = list->next;
 while (list)
 {
  if (!(move->next = ft_list_new_elem(list->c)))
   return (((void *)0));
  move->next->prev = move;
  move = move->next;
  list = list->next;
 }
 return (new);
}

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


decompiled_code:
__int64 __fastcall ft_execute_all(_QWORD *a1, __int64 a2)
{
int v3; // eax
unsigned int v4; // er12
__int64 result; // rax

while ( 1 )
{
v3 = *(_DWORD *)(*a1 + 8LL);
if ( v3 != 4 )
break;
LABEL_6:
ft_execute_all(a1[2], a2);
a1 = (_QWORD *)a1[3];
}
while ( 1 )
{
v4 = 0;
if ( v3 == 5 )
{
v4 = ft_execute_all(a1[2], a2);
if ( v4 != -1 )
goto LABEL_5;
v3 = *(_DWORD *)(*a1 + 8LL);
if ( v3 != 6 )
{
LABEL_9:
if ( v3 != 7 )
goto LABEL_10;
return ft_perform_pipe(a1, a2);
}
}
else if ( v3 != 6 )
{
goto LABEL_9;
}
v4 = ft_execute_all(a1[2], a2);
if ( v4 != -1 )
break;
LABEL_5:
a1 = (_QWORD *)a1[3];
v3 = *(_DWORD *)(*a1 + 8LL);
if ( v3 == 4 )
goto LABEL_6;
}
v3 = *(_DWORD *)(*a1 + 8LL);
if ( v3 == 7 )
return ft_perform_pipe(a1, a2);
LABEL_10:
if ( v3 == 17 )
{
ft_execute_all(a1[2], a2);
result = v4;
}
else if ( (unsigned int)(v3 - 8) <= 2 )
{
result = ft_perform_redir(a1, a2);
}
else if ( v3 == 12 )
{
result = ft_perform_cmd(a1, a2);
}
else
{
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2)
{
int v3; // eax
unsigned int v4; // er12
__int64 result; // rax

while ( 1 )
{
v3 = *(_DWORD *)(*a1 + 8LL);
if ( v3 != 4 )
break;
LABEL_6:
func0(a1[2], a2);
a1 = (_QWORD *)a1[3];
}
while ( 1 )
{
v4 = 0;
if ( v3 == 5 )
{
v4 = func0(a1[2], a2);
if ( v4 != -1 )
goto LABEL_5;
v3 = *(_DWORD *)(*a1 + 8LL);
if ( v3 != 6 )
{
LABEL_9:
if ( v3 != 7 )
goto LABEL_10;
return ft_perform_pipe(a1, a2);
}
}
else if ( v3 != 6 )
{
goto LABEL_9;
}
v4 = func0(a1[2], a2);
if ( v4 != -1 )
break;
LABEL_5:
a1 = (_QWORD *)a1[3];
v3 = *(_DWORD *)(*a1 + 8LL);
if ( v3 == 4 )
goto LABEL_6;
}
v3 = *(_DWORD *)(*a1 + 8LL);
if ( v3 == 7 )
return ft_perform_pipe(a1, a2);
LABEL_10:
if ( v3 == 17 )
{
func0(a1[2], a2);
result = v4;
}
else if ( (unsigned int)(v3 - 8) <= 2 )
{
result = ft_perform_redir(a1, a2);
}
else if ( v3 == 12 )
{
result = ft_perform_cmd(a1, a2);
}
else
{
result = v4;
}
return result;
}

original_code:
int ft_execute_all(t_tree *t, t_env *e)
{
 int value;
 value = 0;
 if (t->p->type == 4)
 {
  value = ft_execute_all(t->le, e);
  value = ft_execute_all(t->ri, e);
 }
 else if (t->p->type == 5 && ((value = ft_execute_all(t->le, e)) != -1))
  value = ft_execute_all(t->ri, e);
 else if (t->p->type == 6 && ((value = ft_execute_all(t->le, e)) == -1))
  value = ft_execute_all(t->ri, e);
 else if (t->p->type == 7)
  value = ft_perform_pipe(t, e);
 else if (t->p->type == 17)
  ft_execute_all(t->le, e);
 else if (t->p->type == 8
    || t->p->type == 9 || t->p->type == 10)
  value = ft_perform_redir(t, e);
 else if (t->p->type == 12)
  value = ft_perform_cmd(t, e);
 return (value);
}

canonical_original_code:
int ft_execute_all(struct s_tree *t, struct s_env *e)
{
 int value;
 value = 0;
 if (t->p->type == 4)
 {
  value = ft_execute_all(t->le, e);
  value = ft_execute_all(t->ri, e);
 }
 else if (t->p->type == 5 && ((value = ft_execute_all(t->le, e)) != -1))
  value = ft_execute_all(t->ri, e);
 else if (t->p->type == 6 && ((value = ft_execute_all(t->le, e)) == -1))
  value = ft_execute_all(t->ri, e);
 else if (t->p->type == 7)
  value = ft_perform_pipe(t, e);
 else if (t->p->type == 17)
  ft_execute_all(t->le, e);
 else if (t->p->type == 8
    || t->p->type == 9 || t->p->type == 10)
  value = ft_perform_redir(t, e);
 else if (t->p->type == 12)
  value = ft_perform_cmd(t, e);
 return (value);
}

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

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

variable_types: value int


decompiled_code:
__int64 __fastcall ft_run(__int64 a1, char *const *a2, int *a3, __int64 a4)
{
char *const *v6; // r14
char *const *v7; // r15
__pid_t v8; // eax
bool v9; // zf
__int64 result; // rax
int pipedes[2]; // [rsp+8h] [rbp-40h] BYREF

v6 = (char *const *)ft_strsplit(*(_QWORD *)(a1 + 16), 32LL);
v7 = (char *const *)ft_strsplit(*(_QWORD *)(a1 + 24), 32LL);
pipe(pipedes);
v8 = fork();
v9 = v8 == 0;
if ( v8 > 0 )
{
dup2(*a3, 0);
dup2(pipedes[1], 1);
close(pipedes[0]);
execve(*(const char **)(a4 + 8), v6, a2);
result = 0LL;
}
else
{
result = 0LL;
if ( v9 )
{
close(pipedes[1]);
dup2(pipedes[0], 0);
dup2(a3[1], 1);
execve(*(const char **)(a4 + 24), v7, a2);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *const *a2, int *a3, __int64 a4)
{
char *const *v6; // r14
char *const *v7; // r15
__pid_t v8; // eax
bool v9; // zf
__int64 result; // rax
int pipedes[2]; // [rsp+8h] [rbp-40h] BYREF

v6 = (char *const *)ft_strsplit(*(_QWORD *)(a1 + 16), 32LL);
v7 = (char *const *)ft_strsplit(*(_QWORD *)(a1 + 24), 32LL);
pipe(pipedes);
v8 = fork();
v9 = v8 == 0;
if ( v8 > 0 )
{
dup2(*a3, 0);
dup2(pipedes[1], 1);
close(pipedes[0]);
execve(*(const char **)(a4 + 8), v6, a2);
result = 0LL;
}
else
{
result = 0LL;
if ( v9 )
{
close(pipedes[1]);
dup2(pipedes[0], 0);
dup2(a3[1], 1);
execve(*(const char **)(a4 + 24), v7, a2);
result = 1LL;
}
}
return result;
}

original_code:
int ft_run(char **av, char **env, t_fd *fd, t_pipex *pipex)
{
 int father;
 int pipe_fd[2];
 char **opt1;
 char **opt2;
 opt1 = ft_strsplit(av[2], ' ');
 opt2 = ft_strsplit(av[3], ' ');
 pipe(pipe_fd);
 if ((father = fork()) > 0)
 {
  dup2(fd->fd1, 0);
  dup2(pipe_fd[1], 1);
  close(pipe_fd[0]);
  execve(pipex->cmd1, opt1, env);
  return (0);
 }
 if (father == 0)
 {
  close(pipe_fd[1]);
  dup2(pipe_fd[0], 0);
  dup2(fd->fd2, 1);
  execve(pipex->cmd2, opt2, env);
  return (1);
 }
 return (0);
}

canonical_original_code:
int ft_run(char **av, char **env, struct s_fd *fd, struct s_pipex *pipex)
{
 int father;
 int pipe_fd[2];
 char **opt1;
 char **opt2;
 opt1 = ft_strsplit(av[2], ' ');
 opt2 = ft_strsplit(av[3], ' ');
 pipe(pipe_fd);
 if ((father = fork()) > 0)
 {
  dup2(fd->fd1, 0);
  dup2(pipe_fd[1], 1);
  close(pipe_fd[0]);
  execve(pipex->cmd1, opt1, env);
  return (0);
 }
 if (father == 0)
 {
  close(pipe_fd[1]);
  dup2(pipe_fd[0], 0);
  dup2(fd->fd2, 1);
  execve(pipex->cmd2, opt2, env);
  return (1);
 }
 return (0);
}

variable_types:
av
char **

variable_types:
env
char **

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

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

variable_types: father int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v4; // r12
int *v5; // rax
int *v6; // r13
int result; // eax

if ( argc == 5 )
{
v4 = malloc(0x20uLL);
if ( v4 && (v5 = (int *)malloc(0xCuLL), (v6 = v5) != 0LL) && (unsigned int)ft_init_struct(argv, envp, v4, v5) != -1 )
{
ft_run((__int64)argv, (char *const *)envp, v6, (__int64)v4);
result = 0;
}
else
{
result = -1;
}
}
else
{
ft_putendl("Error: too many or missing arguments", argv, envp);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v4; // r12
int *v5; // rax
int *v6; // r13
int result; // eax

if ( argc == 5 )
{
v4 = malloc(0x20uLL);
if ( v4 && (v5 = (int *)malloc(0xCuLL), (v6 = v5) != 0LL) && (unsigned int)ft_init_struct(argv, envp, v4, v5) != -1 )
{
func0((__int64)argv, (char *const *)envp, v6, (__int64)v4);
result = 0;
}
else
{
result = -1;
}
}
else
{
ft_putendl("Error: too many or missing arguments", argv, envp);
result = -1;
}
return result;
}

original_code:
int main(int ac, char **av, char **env)
{
 t_fd *fd;
 t_pipex *pipex;
 if (ac != 5)
 {
  ft_putendl("Error: too many or missing arguments");
  return (-1);
 }
 if (!(pipex = (t_pipex *)malloc(sizeof(*pipex)))
  || !(fd = (t_fd *)malloc(sizeof(*fd))))
  return (-1);
 if (ft_init_struct(av, env, pipex, fd) == -1)
  return (-1);
 ft_run(av, env, fd, pipex);
 return (0);
}

canonical_original_code:
int main(int ac, char **av, char **env)
{
 struct s_fd *fd;
 struct s_pipex *pipex;
 if (ac != 5)
 {
  ft_putendl("Error: too many or missing arguments");
  return (-1);
 }
 if (!(pipex = (struct s_pipex *)malloc(sizeof(*pipex)))
  || !(fd = (struct s_fd *)malloc(sizeof(*fd))))
  return (-1);
 if (ft_init_struct(av, env, pipex, fd) == -1)
  return (-1);
 ft_run(av, env, fd, pipex);
 return (0);
}

variable_types: ac int

user_defined_types: struct s_fd { int fd1; int fd2; int fd_tmp; }

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


original_code:
static int ft_token_without_backslashes(char **tok)
{
 char *ret;
 int i;
 int j;
 if (!(ret = (char *)gmalloc(sizeof(char) * (ft_strlen(*tok) + 1))))
  return (-1);
 j = -1;
 i = -1;
 while ((*tok)[++i])
 {
  if ((*tok)[i] == '\\')
  {
   if ((*tok)[++i])
    ret[++j] = (*tok)[i];
   else
    return (-2);
  }
  else
   ret[++j] = (*tok)[i];
 }
 ret[++j] = '\0';
 gfree((void *)(*tok));
 *tok = ft_strdup(ret);
 gfree((void *)ret);
 return (0);
}

variable_types:
tok
char **

variable_types:
ret
char *

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall ft_delete_backslashes(__int64 *a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
if ( *(_DWORD *)(v1 + 8) != 11 || !(unsigned int)ft_find(*(_QWORD *)v1, &unk_134) )
goto LABEL_3;
result = ft_token_without_backslashes((char **)v1);
if ( (_DWORD)result == -2 )
break;
if ( (_DWORD)result == -1 )
return result;
LABEL_3:
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return 0LL;
}
ft_putendl_fd("Parse error near '\\'", 2LL);
return 0xFFFFFFFFLL;
}

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

v1 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
if ( *(_DWORD *)(v1 + 8) != 11 || !(unsigned int)ft_find(*(_QWORD *)v1, &unk_134) )
goto LABEL_3;
result = func0((char **)v1);
if ( (_DWORD)result == -2 )
break;
if ( (_DWORD)result == -1 )
return result;
LABEL_3:
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return 0LL;
}
ft_putendl_fd("Parse error near '\\'", 2LL);
return 0xFFFFFFFFLL;
}

original_code:
int ft_delete_backslashes(t_p **p)
{
 t_p *move;
 int cont;
 move = *p;
 while (move)
 {
  if (move->type == 11 && ft_find(move->tok, "\\"))
  {
   if ((cont = ft_token_without_backslashes(&(move->tok))) == -2)
   {
    ft_putendl_fd("Parse error near \'\\\'", 2);
    return (-1);
   }
   else if (cont == -1)
    return (-1);
  }
  move = move->next;
 }
 return (0);
}

canonical_original_code:
int ft_delete_backslashes(struct s_p **p)
{
 struct s_p *move;
 int cont;
 move = *p;
 while (move)
 {
  if (move->type == 11 && ft_find(move->tok, "\\"))
  {
   if ((cont = ft_token_without_backslashes(&(move->tok))) == -2)
   {
    ft_putendl_fd("Parse error near \'\\\'", 2);
    return (-1);
   }
   else if (cont == -1)
    return (-1);
  }
  move = move->next;
 }
 return (0);
}

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

variable_types: cont int


decompiled_code:
__int64 __fastcall ft_s_w(__int64 a1, char a2, int a3)
{
_BYTE *v3; // rdi
int v4; // edx
char v5; // al
unsigned int v6; // er8

v3 = (_BYTE *)(a3 + a1);
if ( *v3 == a2 || !*v3 )
return 0LL;
v4 = 1 - (_DWORD)v3;
do
{
v5 = v3[1];
v6 = v4 + (_DWORD)v3++;
}
while ( v5 != a2 && v5 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, int a3)
{
_BYTE *v3; // rdi
int v4; // edx
char v5; // al
unsigned int v6; // er8

v3 = (_BYTE *)(a3 + a1);
if ( *v3 == a2 || !*v3 )
return 0LL;
v4 = 1 - (_DWORD)v3;
do
{
v5 = v3[1];
v6 = v4 + (_DWORD)v3++;
}
while ( v5 != a2 && v5 );
return v6;
}

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

canonical_original_code:
static int ft_s_w(char *s, char c, int i)
{
 int m;
 m = 0;
 while (*(s + i) && *(s + i) != c)
 {
  ++i;
  ++m;
 }
 return (m);
}

variable_types:
s
char *

variable_types: c char

variable_types: m int


original_code:
char **ft_strsplit(char const *s, char c)
{
 char **s3;
 int i;
 int k;
 if (!s || !(s3 = (char **)gmalloc(sizeof(*s3) * (ft_wc_w(s, c) + 1))))
  return (((void *)0));
 i = 0;
 k = 0;
 while (*(s + i))
 {
  while (*(s + i) == c && *(s + i))
   ++i;
  if (*(s + i))
  {
   s3[k] = (char *)gmalloc(sizeof(char) * (ft_s_w(s, c, i) + 1));
   if (!(s3[k]))
    return (((void *)0));
   s3[k] = ft_fill_t(s3[k], c, &i, s);
   ++k;
  }
 }
 if (!(s3[k] = (char *)gmalloc(sizeof(char) * (1 + 1))))
  return (((void *)0));
 s3[k] = '\0';
 return (s3);
}

canonical_original_code:
char **ft_strsplit(char *s, char c)
{
 char **s3;
 int i;
 int k;
 if (!s || !(s3 = (char **)gmalloc(sizeof(*s3) * (ft_wc_w(s, c) + 1))))
  return (((void *)0));
 i = 0;
 k = 0;
 while (*(s + i))
 {
  while (*(s + i) == c && *(s + i))
   ++i;
  if (*(s + i))
  {
   s3[k] = (char *)gmalloc(sizeof(char) * (ft_s_w(s, c, i) + 1));
   if (!(s3[k]))
    return (((void *)0));
   s3[k] = ft_fill_t(s3[k], c, &i, s);
   ++k;
  }
 }
 if (!(s3[k] = (char *)gmalloc(sizeof(char) * (1 + 1))))
  return (((void *)0));
 s3[k] = '\0';
 return (s3);
}

variable_types: k int

return_type: char **


decompiled_code:
__int64 __fastcall ft_find_sph_normal(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rdi
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
__int64 v9; // [rsp+8h] [rbp-38h] BYREF

v2 = a1 + 48;
ft_mult_vect_by_nb(&v9, *(double *)(a1 + 112));
ft_vect_sum(a1 + 48);
ft_vect_difference(a1 + 72);
v3 = a1 + 72;
ft_normalize_vect(v3);
if ( ft_dot_product(v3, a2, v4, v5, v6, v7) > 0.0 )
return 0xFFFFFFFFLL;
ft_mult_vect_by_nb(&v9, 0.0001);
ft_vect_sum(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rdi
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
__int64 v9; // [rsp+8h] [rbp-38h] BYREF

v2 = a1 + 48;
ft_mult_vect_by_nb(&v9, *(double *)(a1 + 112));
ft_vect_sum(a1 + 48);
ft_vect_difference(a1 + 72);
v3 = a1 + 72;
ft_normalize_vect(v3);
if ( ft_dot_product(v3, a2, v4, v5, v6, v7) > 0.0 )
return 0xFFFFFFFFLL;
ft_mult_vect_by_nb(&v9, 0.0001);
ft_vect_sum(v2);
return 0LL;
}

original_code:
static int ft_find_sph_normal(t_r *r, t_v c)
{
 t_v tmp;
 ft_mult_vect_by_nb(&tmp, r->d_w, r->tnear);
 ft_vect_sum(&r->p_hit, r->o_w, tmp);
 ft_vect_difference(&r->n_hit, r->p_hit, c);
 ft_normalize_vect(&r->n_hit);
 if (ft_dot_product(r->d_w, r->n_hit) > 0)
  return (-1);
 ft_mult_vect_by_nb(&tmp, r->n_hit, (0.0001));
 ft_vect_sum(&r->p_hit, tmp, r->p_hit);
 return (0);
}

canonical_original_code:
static int ft_find_sph_normal(struct s_r *r, struct s_v c)
{
 struct s_v tmp;
 ft_mult_vect_by_nb(&tmp, r->d_w, r->tnear);
 ft_vect_sum(&r->p_hit, r->o_w, tmp);
 ft_vect_difference(&r->n_hit, r->p_hit, c);
 ft_normalize_vect(&r->n_hit);
 if (ft_dot_product(r->d_w, r->n_hit) > 0)
  return (-1);
 ft_mult_vect_by_nb(&tmp, r->n_hit, (0.0001));
 ft_vect_sum(&r->p_hit, tmp, r->p_hit);
 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:
c
struct s_v


decompiled_code:
__int64 __fastcall ft_treat_a_sphere(_DWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
double v7; // xmm0_8

if ( (unsigned int)ft_find_sph_normal(a4, a2) == -1 )
{
ft_init_color(a2, (unsigned int)(a1[8] / 2), (unsigned int)(a1[9] / 2), (unsigned int)(a1[10] / 2));
result = 0LL;
}
else
{
if ( *(int *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a3 + 16) + 8LL) + 8LL * *(int *)(a4 + 136)) + 52LL) <= 0 )
{
v7 = ft_hit_light(a4, a3);
ft_init_color(
a2,
(unsigned int)(int)(v7 * (double)(int)a1[8]),
(unsigned int)(int)((double)(int)a1[9] * v7),
(unsigned int)(int)((double)(int)a1[10] * v7));
}
else
{
*(_QWORD *)a2 = *((_QWORD *)a1 + 4);
*(_DWORD *)(a2 + 8) = a1[10];
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
double v7; // xmm0_8

if ( (unsigned int)func0(a4, a2) == -1 )
{
ft_init_color(a2, (unsigned int)(a1[8] / 2), (unsigned int)(a1[9] / 2), (unsigned int)(a1[10] / 2));
result = 0LL;
}
else
{
if ( *(int *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a3 + 16) + 8LL) + 8LL * *(int *)(a4 + 136)) + 52LL) <= 0 )
{
v7 = ft_hit_light(a4, a3);
ft_init_color(
a2,
(unsigned int)(int)(v7 * (double)(int)a1[8]),
(unsigned int)(int)((double)(int)a1[9] * v7),
(unsigned int)(int)((double)(int)a1[10] * v7));
}
else
{
*(_QWORD *)a2 = *((_QWORD *)a1 + 4);
*(_DWORD *)(a2 + 8) = a1[10];
}
result = 0LL;
}
return result;
}

original_code:
int ft_treat_a_sphere(void *data, t_c *color, t_obj *obj, t_r *r)
{
 t_sph *sph;
 double mult;
 sph = (t_sph *)data;
 if (ft_find_sph_normal(r, sph->c) == -1)
  ft_init_color(color, sph->sf.b / 2, sph->sf.g / 2, sph->sf.r / 2);
 else
 {
  if ((((t_sph ***)obj->type)[1][r->hit_j])->em.r > 0)
   *color = sph->sf;
  else
  {
   mult = ft_hit_light(r, obj);
   ft_init_color(color, sph->sf.b * mult,
       sph->sf.g * mult, sph->sf.r * mult);
  }
 }
 return (0);
}

canonical_original_code:
int ft_treat_a_sphere(void *data, struct s_c *color, struct s_obj *obj, struct s_r *r)
{
 struct s_sph *sph;
 double mult;
 sph = (struct s_sph *)data;
 if (ft_find_sph_normal(r, sph->c) == -1)
  ft_init_color(color, sph->sf.b / 2, sph->sf.g / 2, sph->sf.r / 2);
 else
 {
  if ((((struct s_sph ***)obj->type)[1][r->hit_j])->em.r > 0)
   *color = sph->sf;
  else
  {
   mult = ft_hit_light(r, obj);
   ft_init_color(color, sph->sf.b * mult,
       sph->sf.g * mult, sph->sf.r * mult);
  }
 }
 return (0);
}

variable_types:
data
void *

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

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: struct s_sph { struct s_v { double x; double y; double z; } c; double r; struct s_c { int b; int g; int r; } sf; struct s_c em; double trsp; double refl; double ior; } *

variable_types: mult double


decompiled_code:
__int64 __fastcall ft_count_word(char *a1, char a2)
{
char v2; // al
unsigned int v3; // er8
int v4; // edx

if ( !a1 )
return (unsigned int)-1;
v2 = *a1;
v3 = 0;
if ( *a1 )
{
v4 = 0;
do
{
while ( a2 == v2 )
{
v2 = *++a1;
v4 = 0;
if ( !v2 )
return v3;
}
if ( !v4 )
{
++v3;
v4 = 1;
}
v2 = *++a1;
}
while ( v2 );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char a2)
{
char v2; // al
unsigned int v3; // er8
int v4; // edx

if ( !a1 )
return (unsigned int)-1;
v2 = *a1;
v3 = 0;
if ( *a1 )
{
v4 = 0;
do
{
while ( a2 == v2 )
{
v2 = *++a1;
v4 = 0;
if ( !v2 )
return v3;
}
if ( !v4 )
{
++v3;
v4 = 1;
}
v2 = *++a1;
}
while ( v2 );
}
return v3;
}

original_code:
int ft_count_word(char *str, char c)
{
 int in_word;
 int n;
 if (str == ((void *)0))
  return (-1);
 in_word = 0;
 n = 0;
 while (*str)
 {
  if (*str == c)
   in_word = 0;
  else
  {
   if (in_word == 0)
    ++n;
   in_word = 1;
  }
  ++str;
 }
 return (n);
}

variable_types:
str
char *

variable_types: n int


decompiled_code:
__int64 __fastcall ft_move_in_history(__int64 a1, __int64 *a2, _DWORD *a3, __int64 a4)
{
unsigned int v6; // er15
__int64 result; // rax

if ( (unsigned int)ft_is_key_arrow_up() && *(_QWORD *)a4 )
{
if ( a3[2] )
{
v6 = 0;
if ( *(_QWORD *)(*(_QWORD *)a4 + 8LL) )
ft_move_hist(a4, a3, a2, 1u);
return v6;
}
ft_move_hist(a4, a3, a2, 0);
result = 0LL;
}
else
{
v6 = 1;
if ( !(unsigned int)ft_is_key_arrow_down(a1) || !*(_QWORD *)a4 )
return v6;
if ( *(_QWORD *)(*(_QWORD *)a4 + 16LL) )
{
ft_move_hist(a4, a3, a2, 0xFFFFFFFF);
result = 0LL;
}
else
{
*a2 = 0LL;
result = 0LL;
*a3 = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 *a2, _DWORD *a3, __int64 a4)
{
unsigned int v6; // er15
__int64 result; // rax

if ( (unsigned int)ft_is_key_arrow_up() && *(_QWORD *)a4 )
{
if ( a3[2] )
{
v6 = 0;
if ( *(_QWORD *)(*(_QWORD *)a4 + 8LL) )
func0(a4, a3, a2, 1u);
return v6;
}
func0(a4, a3, a2, 0);
result = 0LL;
}
else
{
v6 = 1;
if ( !(unsigned int)ft_is_key_arrow_down(a1) || !*(_QWORD *)a4 )
return v6;
if ( *(_QWORD *)(*(_QWORD *)a4 + 16LL) )
{
func0(a4, a3, a2, 0xFFFFFFFF);
result = 0LL;
}
else
{
*a2 = 0LL;
result = 0LL;
*a3 = 0;
}
}
return result;
}

original_code:
int ft_move_in_history(char *buf, t_sl **sl, t_save *save, t_hl **move)
{
 if (ft_is_key_arrow_up(buf) && *move)
 {
  if (save->hist_nb == 0)
   ft_move_hist(move, save, sl, 0);
  else if ((*move)->next)
   ft_move_hist(move, save, sl, 1);
 }
 else if (ft_is_key_arrow_down(buf) && *move)
 {
  if ((*move)->prev)
   ft_move_hist(move, save, sl, -1);
  else
  {
   *sl = ((void *)0);
   save->cursor = 0;
  }
 }
 else
  return (1);
 return (0);
}

canonical_original_code:
int ft_move_in_history(char *buf, struct s_sl **sl, struct s_save *save, struct s_hl **move)
{
 if (ft_is_key_arrow_up(buf) && *move)
 {
  if (save->hist_nb == 0)
   ft_move_hist(move, save, sl, 0);
  else if ((*move)->next)
   ft_move_hist(move, save, sl, 1);
 }
 else if (ft_is_key_arrow_down(buf) && *move)
 {
  if ((*move)->prev)
   ft_move_hist(move, save, sl, -1);
  else
  {
   *sl = ((void *)0);
   save->cursor = 0;
  }
 }
 else
  return (1);
 return (0);
}

variable_types:
buf
char *

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