decompiled_code:
unsigned __int64 __fastcall go_up_of_cmd_high(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, __int64 a15)
{
unsigned __int64 result; // rax
unsigned __int64 v16; // rtt
int v17; // ebx
char v19[2]; // [rsp+8h] [rbp-20h] BYREF
unsigned __int16 v20; // [rsp+Ah] [rbp-1Eh]

ioctl(0, 0x5413uLL, v19);
v16 = my_strlen(a1) + a2;
result = v16 / v20;
v17 = result - 1;
if ( (int)result - 1 >= 0 )
{
do
result = my_putstr(a15, 1LL);
while ( v17-- != 0 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, __int64 a15)
{
unsigned __int64 result; // rax
unsigned __int64 v16; // rtt
int v17; // ebx
char v19[2]; // [rsp+8h] [rbp-20h] BYREF
unsigned __int16 v20; // [rsp+Ah] [rbp-1Eh]

ioctl(0, 0x5413uLL, v19);
v16 = my_strlen(a1) + a2;
result = v16 / v20;
v17 = result - 1;
if ( (int)result - 1 >= 0 )
{
do
result = my_putstr(a15, 1LL);
while ( v17-- != 0 );
}
return result;
}

original_code:
void go_up_of_cmd_high(char *cmd, int len, t_options opt)
{
  int high;
  struct winsize ws;
  ioctl(0, 0x5413, &ws);
  high = (my_strlen(cmd) + len) / ws.ws_col;
  while (--high >= 0)
    my_putstr(opt.up_cursor, 1);
}

canonical_original_code:
void go_up_of_cmd_high(char *cmd, int len, struct s_options opt)
{
  int high;
  struct winsize ws;
  ioctl(0, 0x5413, &ws);
  high = (my_strlen(cmd) + len) / ws.ws_col;
  while (--high >= 0)
    my_putstr(opt.up_cursor, 1);
}

variable_types:
cmd
char *

variable_types: len int

variable_types: struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; }

variable_types: high int

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


original_code:
void show_cmd(char key, int fd, char *cmd, int reverse_case)
{
  int i;
  t_options options;
  int len;
  i = -1;
  len = prompt(0);
  retain_struct_options(2, &options);
  while (cmd[++i] != '\0')
    {
      if (key != 10 && i == reverse_case && cmd[i] != '\t')
 aff_str_cmd(fd, options.reverse);
      aff_char_cmd(fd, cmd[i]);
 aff_str_cmd(fd, options.forward);
    }
  if (key != 10 && i == reverse_case)
    aff_str_cmd(fd, options.reverse);
  aff_char_cmd(fd, ' ');
  aff_str_cmd(fd, options.forward);
  if (key != 10)
    {
      aff_str_cmd(fd, options.clean_end);
      go_up_of_cmd_high(cmd, len, options);
    }
  aff_str_cmd(fd, "\r");
}

canonical_original_code:
void show_cmd(char key, int fd, char *cmd, int reverse_case)
{
  int i;
  struct s_options options;
  int len;
  i = -1;
  len = prompt(0);
  retain_struct_options(2, &options);
  while (cmd[++i] != '\0')
    {
      if (key != 10 && i == reverse_case && cmd[i] != '\t')
 aff_str_cmd(fd, options.reverse);
      aff_char_cmd(fd, cmd[i]);
 aff_str_cmd(fd, options.forward);
    }
  if (key != 10 && i == reverse_case)
    aff_str_cmd(fd, options.reverse);
  aff_char_cmd(fd, ' ');
  aff_str_cmd(fd, options.forward);
  if (key != 10)
    {
      aff_str_cmd(fd, options.clean_end);
      go_up_of_cmd_high(cmd, len, options);
    }
  aff_str_cmd(fd, "\r");
}

variable_types: key char

variable_types: fd int

variable_types: i int

return_type: void

user_defined_types: struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; }


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

result = 0LL;
if ( a1 && *a1 )
{
do
++result;
while ( a1[result] );
}
return result;
}

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

result = 0LL;
if ( a1 && *a1 )
{
do
++result;
while ( a1[result] );
}
return result;
}

original_code:
size_t my_strlen(const char *s)
{
  size_t i;
  i = 0;
  if (!s)
    return (0);
  while (s[i])
    i++;
  return (i);
}

canonical_original_code:
unsigned long my_strlen(char *s)
{
  unsigned long i;
  i = 0;
  if (!s)
    return (0);
  while (s[i])
    i++;
  return (i);
}

variable_types:
s
char *

variable_types:
i
unsigned long

return_type: unsigned long


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

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

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

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

original_code:
size_t my_strilen(const char *s, char c)
{
  size_t i;
  i = 0;
  while (s[i] && s[i] != c)
    i++;
  return (i);
}

canonical_original_code:
unsigned long my_strilen(char *s, char c)
{
  unsigned long i;
  i = 0;
  while (s[i] && s[i] != c)
    i++;
  return (i);
}

variable_types: c char


decompiled_code:
__int64 __fastcall my_strslen(_BYTE *a1, _BYTE *a2)
{
__int64 v2; // r12
__int64 v3; // rax

v2 = 0LL;
if ( *a1 )
{
do
{
if ( a2 )
{
v3 = my_strlen(a2);
if ( !(unsigned int)my_strncmp(a2, &a1[v2], v3) )
break;
}
++v2;
}
while ( a1[v2] );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, _BYTE *a2)
{
__int64 v2; // r12
__int64 v3; // rax

v2 = 0LL;
if ( *a1 )
{
do
{
if ( a2 )
{
v3 = func0(a2);
if ( !(unsigned int)my_strncmp(a2, &a1[v2], v3) )
break;
}
++v2;
}
while ( a1[v2] );
}
return v2;
}

original_code:
size_t my_strslen(const char *s, const char *c)
{
  size_t i;
  i = 0;
  while (s[i] && !(((c) && (s + i)) ? (!my_strncmp((c), (s + i), my_strlen(c))) : (0)))
    i++;
  return (i);
}

canonical_original_code:
unsigned long my_strslen(char *s, char *c)
{
  unsigned long i;
  i = 0;
  while (s[i] && !(((c) && (s + i)) ? (!my_strncmp((c), (s + i), my_strlen(c))) : (0)))
    i++;
  return (i);
}

variable_types:
c
char *


decompiled_code:
__int64 __fastcall my_sstrlen(char *a1, _BYTE *a2)
{
__int64 v4; // r8
char i; // si
__int64 v6; // r9

v4 = 0LL;
for ( i = *a1; i; i = *(_BYTE *)(v6 + v4) )
{
if ( a2[my_strilen(a2, i)] )
break;
++v4;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, _BYTE *a2)
{
__int64 v4; // r8
char i; // si
__int64 v6; // r9

v4 = 0LL;
for ( i = *a1; i; i = *(_BYTE *)(v6 + v4) )
{
if ( a2[func1(a2, i)] )
break;
++v4;
}
return v4;
}

original_code:
size_t my_sstrlen(const char *s, const char *c)
{
  size_t i;
  i = 0;
  while (s[i] && !((c)[my_strilen(c, s[i])] != 0))
    i++;
  return (i);
}

canonical_original_code:
unsigned long my_sstrlen(char *s, char *c)
{
  unsigned long i;
  i = 0;
  while (s[i] && !((c)[my_strilen(c, s[i])] != 0))
    i++;
  return (i);
}


lenmatch

decompiled_code:
__int64 __fastcall lenmatch(char *a1, _BYTE *a2)
{
__int64 v4; // r8
char i; // si
__int64 v6; // r9

v4 = 0LL;
for ( i = *a1; i; i = *(_BYTE *)(v6 + v4) )
{
if ( !a2[my_strilen(a2, i)] )
break;
++v4;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, _BYTE *a2)
{
__int64 v4; // r8
char i; // si
__int64 v6; // r9

v4 = 0LL;
for ( i = *a1; i; i = *(_BYTE *)(v6 + v4) )
{
if ( !a2[func1(a2, i)] )
break;
++v4;
}
return v4;
}

original_code:
size_t lenmatch(const char *s, const char *c)
{
  size_t i;
  i = 0;
  while (s[i] && ((c)[my_strilen(c, s[i])] != 0))
    i++;
  return (i);
}

canonical_original_code:
unsigned long lenmatch(char *s, char *c)
{
  unsigned long i;
  i = 0;
  while (s[i] && ((c)[my_strilen(c, s[i])] != 0))
    i++;
  return (i);
}


decompiled_code:
bool __fastcall move_env(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char *v4; // rbx

if ( !a1 )
return 0;
if ( !environ[a2] )
return 0;
v2 = ((__int64 (*)(void))my_strlen)();
if ( (unsigned int)my_strncmp(a1, environ[a2], v2) )
return 0;
v4 = environ[a2];
return v4[my_strlen(a1)] == 61;
}

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

if ( !a1 )
return 0;
if ( !environ[a2] )
return 0;
v2 = ((__int64 (*)(void))my_strlen)();
if ( (unsigned int)my_strncmp(a1, environ[a2], v2) )
return 0;
v4 = environ[a2];
return v4[my_strlen(a1)] == 61;
}

original_code:
static unsigned char move_env(char *s, size_t i)
{
  if ((((s) && (environ[i])) ? (!my_strncmp((s), (environ[i]), my_strlen(s))) : (0)) && (environ[i][my_strlen(s)] == '='))
    return (1);
  return (0);
}

canonical_original_code:
static unsigned char move_env(char *s, unsigned long i)
{
  if ((((s) && (environ[i])) ? (!my_strncmp((s), (environ[i]), my_strlen(s))) : (0)) && (environ[i][my_strlen(s)] == '='))
    return (1);
  return (0);
}

return_type: unsigned char


decompiled_code:
char __fastcall set_env(__int64 a1, __int64 a2)
{
char **v2; // rax
__int64 v4; // rdi
__int64 i; // rsi
__int64 v7; // rax
_QWORD *v8; // r13
char **v9; // rcx
char *v10; // rdx
__int64 v11; // rax
_QWORD *v12; // rbx
_QWORD *v13; // r14
__int64 v14; // rsi
char result; // al

v2 = environ;
v4 = 24LL;
if ( environ )
{
for ( i = 0LL; ; ++i )
{
if ( !v2[i] )
{
v4 = 8 * i + 24;
goto LABEL_7;
}
if ( move_env(a1, i) )
break;
v2 = environ;
}
result = fill_env(a1, a2, i);
}
else
{
LABEL_7:
v7 = xmalloc(v4);
v8 = (_QWORD *)v7;
if ( v7 )
{
v9 = environ;
if ( environ )
{
v10 = *environ;
v11 = 1LL;
v12 = v8 + 1;
v13 = v8;
if ( *environ )
{
do
{
v8[v11 - 1] = v10;
v10 = v9[v11];
v14 = v11 * 8;
++v11;
}
while ( v10 );
v13 = (_QWORD *)((char *)v8 + v14);
v12 = &v8[v11];
}
}
else
{
v13 = (_QWORD *)(v7 - 8);
v12 = (_QWORD *)v7;
}
*v13 = my_stricat(a1, a2, 61LL);
*v12 = 0LL;
result = switch_env(v8, 0LL);
}
else
{
result = 0;
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func2(__int64 a1, __int64 a2)
{
char **v2; // rax
__int64 v4; // rdi
__int64 i; // rsi
__int64 v7; // rax
_QWORD *v8; // r13
char **v9; // rcx
char *v10; // rdx
__int64 v11; // rax
_QWORD *v12; // rbx
_QWORD *v13; // r14
__int64 v14; // rsi
char result; // al

v2 = environ;
v4 = 24LL;
if ( environ )
{
for ( i = 0LL; ; ++i )
{
if ( !v2[i] )
{
v4 = 8 * i + 24;
goto LABEL_7;
}
if ( func0(a1, i) )
break;
v2 = environ;
}
result = func1(a1, a2, i);
}
else
{
LABEL_7:
v7 = xmalloc(v4);
v8 = (_QWORD *)v7;
if ( v7 )
{
v9 = environ;
if ( environ )
{
v10 = *environ;
v11 = 1LL;
v12 = v8 + 1;
v13 = v8;
if ( *environ )
{
do
{
v8[v11 - 1] = v10;
v10 = v9[v11];
v14 = v11 * 8;
++v11;
}
while ( v10 );
v13 = (_QWORD *)((char *)v8 + v14);
v12 = &v8[v11];
}
}
else
{
v13 = (_QWORD *)(v7 - 8);
v12 = (_QWORD *)v7;
}
*v13 = my_stricat(a1, a2, 61LL);
*v12 = 0LL;
result = switch_env(v8, 0LL);
}
else
{
result = 0;
}
}
return result;
}

original_code:
unsigned char set_env(char *s, char *s2)
{
  char **tab;
  size_t i;
  i = 0;
  if (environ)
    while (environ[i])
      if (move_env(s, i++))
 return (fill_env(s, s2, i - 1));
  if ((tab = xmalloc(sizeof(*tab) * (i + 3))) == ((void *)0))
    return (0);
  i = 0;
  if (environ)
    while (environ[i++])
      tab[i - 1] = environ[i - 1];
  tab[i - 1] = my_stricat(s, s2, '=');
  tab[i] = ((void *)0);
  return (switch_env(tab, 0));
}

canonical_original_code:
unsigned char set_env(char *s, char *s2)
{
  char **tab;
  unsigned long i;
  i = 0;
  if (environ)
    while (environ[i])
      if (move_env(s, i++))
 return (fill_env(s, s2, i - 1));
  if ((tab = xmalloc(sizeof(*tab) * (i + 3))) == ((void *)0))
    return (0);
  i = 0;
  if (environ)
    while (environ[i++])
      tab[i - 1] = environ[i - 1];
  tab[i - 1] = my_stricat(s, s2, '=');
  tab[i] = ((void *)0);
  return (switch_env(tab, 0));
}

variable_types:
tab
char **


decompiled_code:
__int64 __fastcall get_env(__int64 a1)
{
char **v1; // rax
__int64 v2; // rbx
__int64 v3; // rax
bool v4; // zf
char *v6; // rbx

v1 = environ;
if ( !environ || !*environ )
return 0LL;
v2 = 0LL;
while ( 1 )
{
if ( a1 )
{
v3 = my_strlen(a1);
v4 = (unsigned int)my_strncmp(a1, environ[v2], v3) == 0;
v1 = environ;
if ( v4 )
break;
}
if ( !v1[++v2] )
return 0LL;
}
v6 = environ[v2];
return (__int64)&v6[my_strilen(v6, 61LL) + 1];
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
char **v1; // rax
__int64 v2; // rbx
__int64 v3; // rax
bool v4; // zf
char *v6; // rbx

v1 = environ;
if ( !environ || !*environ )
return 0LL;
v2 = 0LL;
while ( 1 )
{
if ( a1 )
{
v3 = my_strlen(a1);
v4 = (unsigned int)my_strncmp(a1, environ[v2], v3) == 0;
v1 = environ;
if ( v4 )
break;
}
if ( !v1[++v2] )
return 0LL;
}
v6 = environ[v2];
return (__int64)&v6[my_strilen(v6, 61LL) + 1];
}

original_code:
char *get_env(char *s)
{
  size_t i;
  i = 0;
  if (!environ)
    return (((void *)0));
  while (environ[i])
    {
      if ((((s) && (environ[i])) ? (!my_strncmp((s), (environ[i]), my_strlen(s))) : (0)))
 return (environ[i] + my_strilen(environ[i], '=') + 1);
      i++;
    }
  return (((void *)0));
}

canonical_original_code:
char *get_env(char *s)
{
  unsigned long i;
  i = 0;
  if (!environ)
    return (((void *)0));
  while (environ[i])
    {
      if ((((s) && (environ[i])) ? (!my_strncmp((s), (environ[i]), my_strlen(s))) : (0)))
 return (environ[i] + my_strilen(environ[i], '=') + 1);
      i++;
    }
  return (((void *)0));
}

return_type: char *


decompiled_code:
char *__fastcall get_full_env(__int64 a1)
{
char **v1; // rax
__int64 v2; // rbx
__int64 v3; // rax
bool v4; // zf

v1 = environ;
if ( !environ || !*environ )
return 0LL;
v2 = 0LL;
while ( 1 )
{
if ( a1 )
{
v3 = my_strlen(a1);
v4 = (unsigned int)my_strncmp(a1, environ[v2], v3) == 0;
v1 = environ;
if ( v4 )
break;
}
if ( !v1[++v2] )
return 0LL;
}
return environ[v2];
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1)
{
char **v1; // rax
__int64 v2; // rbx
__int64 v3; // rax
bool v4; // zf

v1 = environ;
if ( !environ || !*environ )
return 0LL;
v2 = 0LL;
while ( 1 )
{
if ( a1 )
{
v3 = my_strlen(a1);
v4 = (unsigned int)my_strncmp(a1, environ[v2], v3) == 0;
v1 = environ;
if ( v4 )
break;
}
if ( !v1[++v2] )
return 0LL;
}
return environ[v2];
}

original_code:
char *get_full_env(char *s)
{
  size_t i;
  i = 0;
  if (!environ)
    return (((void *)0));
  while (environ[i])
    {
      if ((((s) && (environ[i])) ? (!my_strncmp((s), (environ[i]), my_strlen(s))) : (0)))
 return (environ[i]);
      i++;
    }
  return (((void *)0));
}

canonical_original_code:
char *get_full_env(char *s)
{
  unsigned long i;
  i = 0;
  if (!environ)
    return (((void *)0));
  while (environ[i])
    {
      if ((((s) && (environ[i])) ? (!my_strncmp((s), (environ[i]), my_strlen(s))) : (0)))
 return (environ[i]);
      i++;
    }
  return (((void *)0));
}


decompiled_code:
bool __fastcall fill_env(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx
char **v4; // rbx
__int64 v5; // rax

v3 = a3;
free(environ[v3]);
v4 = &environ[v3];
v5 = my_stricat(a1, a2, 61LL);
*v4 = (char *)v5;
return v5 != 0;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx
char **v4; // rbx
__int64 v5; // rax

v3 = a3;
free(environ[v3]);
v4 = &environ[v3];
v5 = my_stricat(a1, a2, 61LL);
*v4 = (char *)v5;
return v5 != 0;
}

original_code:
static unsigned char fill_env(char *s, char *s2, int i)
{
  free(environ[i]);
  if ((environ[i] = my_stricat(s, s2, '=')) == ((void *)0))
    return (0);
  return (1);
}


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

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

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

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

original_code:
int my_strcmp(const char *s1, const char *s2)
{
  size_t i;
  if (s1 == ((void *)0))
    return (1);
  if (s2 == ((void *)0))
    return (-1);
  i = 0;
  while (s1[i] == s2[i] && s1[i])
    i++;
  return (s1[i] - s2[i]);
}

canonical_original_code:
int my_strcmp(char *s1, char *s2)
{
  unsigned long i;
  if (s1 == ((void *)0))
    return (1);
  if (s2 == ((void *)0))
    return (-1);
  i = 0;
  while (s1[i] == s2[i] && s1[i])
    i++;
  return (s1[i] - s2[i]);
}

return_type: int


decompiled_code:
__int64 __fastcall my_strncmp(char *a1, _BYTE *a2, __int64 a3)
{
__int64 result; // rax
char v7; // dl
int v8; // ecx
__int64 v9; // rsi
__int64 v10; // rax

result = 0LL;
if ( a3 )
{
v7 = *a1;
v8 = (char)*a2;
v9 = a3 - 1;
v10 = 0LL;
if ( *a2 == *a1 )
{
while ( v7 )
{
if ( v9 != v10 )
{
v7 = a1[++v10];
v8 = (char)a2[v10];
if ( v7 == a2[v10] )
continue;
}
goto LABEL_9;
}
result = (unsigned int)-v8;
}
else
{
LABEL_9:
result = (unsigned int)(v7 - v8);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, _BYTE *a2, __int64 a3)
{
__int64 result; // rax
char v7; // dl
int v8; // ecx
__int64 v9; // rsi
__int64 v10; // rax

result = 0LL;
if ( a3 )
{
v7 = *a1;
v8 = (char)*a2;
v9 = a3 - 1;
v10 = 0LL;
if ( *a2 == *a1 )
{
while ( v7 )
{
if ( v9 != v10 )
{
v7 = a1[++v10];
v8 = (char)a2[v10];
if ( v7 == a2[v10] )
continue;
}
goto LABEL_9;
}
result = (unsigned int)-v8;
}
else
{
LABEL_9:
result = (unsigned int)(v7 - v8);
}
}
return result;
}

original_code:
int my_strncmp(const char *s1, const char *s2, size_t n)
{
  size_t i;
  if (!n)
    return (0);
  i = 0;
  while (s1[i] == s2[i] && s1[i] && i < n - 1)
    i++;
  return (s1[i] - s2[i]);
}

canonical_original_code:
int my_strncmp(char *s1, char *s2, unsigned long n)
{
  unsigned long i;
  if (!n)
    return (0);
  i = 0;
  while (s1[i] == s2[i] && s1[i] && i < n - 1)
    i++;
  return (s1[i] - s2[i]);
}

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall last_soccur(_BYTE *a1, char *a2)
{
__int64 v2; // r14
__int64 v3; // rbx
__int64 v4; // rax

if ( !*a1 )
return 0LL;
v2 = 0LL;
v3 = 0LL;
do
{
if ( a2 )
{
v4 = my_strlen(a2);
if ( !(unsigned int)my_strncmp(a2, &a1[v3], v4) )
v2 = v3;
}
++v3;
}
while ( a1[v3] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, char *a2)
{
__int64 v2; // r14
__int64 v3; // rbx
__int64 v4; // rax

if ( !*a1 )
return 0LL;
v2 = 0LL;
v3 = 0LL;
do
{
if ( a2 )
{
v4 = my_strlen(a2);
if ( !(unsigned int)func1(a2, &a1[v3], v4) )
v2 = v3;
}
++v3;
}
while ( a1[v3] );
return v2;
}

original_code:
size_t last_soccur(const char *s1, const char *s2)
{
  size_t i;
  size_t r;
  i = 0;
  r = 0;
  while (s1[i])
    {
      if ((((s2) && (s1 + i)) ? (!my_strncmp((s2), (s1 + i), my_strlen(s2))) : (0)))
 r = i;
      i++;
    }
  return (r);
}

canonical_original_code:
unsigned long last_soccur(char *s1, char *s2)
{
  unsigned long i;
  unsigned long r;
  i = 0;
  r = 0;
  while (s1[i])
    {
      if ((((s2) && (s1 + i)) ? (!my_strncmp((s2), (s1 + i), my_strlen(s2))) : (0)))
 r = i;
      i++;
    }
  return (r);
}

variable_types:
r
unsigned long


decompiled_code:
ssize_t __fastcall date_and_time(char a1)
{
char *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
if ( timer == -1 )
return 0LL;
v1 = ctime(&timer);
if ( !v1 )
return 0LL;
if ( a1 )
return write(1, v1, 0xAuLL);
return write(1, v1 + 11, 8uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func0(char a1)
{
char *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
if ( timer == -1 )
return 0LL;
v1 = ctime(&timer);
if ( !v1 )
return 0LL;
if ( a1 )
return write(1, v1, 0xAuLL);
return write(1, v1 + 11, 8uLL);
}

original_code:
static int date_and_time(unsigned char t)
{
  time_t current_time;
  char* c_time_string;
  current_time = time(((void *)0));
  if (current_time == ((time_t)-1))
    return (0);
  c_time_string = ctime(&current_time);
  if (!c_time_string)
    return (0);
  if (t)
    return (write(1, c_time_string, 10));
  return (write(1, c_time_string + 11, 8));
}

canonical_original_code:
static int date_and_time(unsigned char t)
{
  long current_time;
  char *c_time_string;
  current_time = time(((void *)0));
  if (current_time == ((time_t)-1))
    return (0);
  c_time_string = ctime(&current_time);
  if (!c_time_string)
    return (0);
  if (t)
    return (write(1, c_time_string, 10));
  return (write(1, c_time_string + 11, 8));
}

variable_types:
t
unsigned char


decompiled_code:
ssize_t put_dir()
{
char *v0; // rbp
ssize_t result; // rax
size_t v2; // rax

v0 = getcwd(0LL, 0LL);
result = 0LL;
if ( v0 )
{
v2 = my_strlen(v0);
result = write(1, v0, v2);
}
return result;
}

canonical_decompiled_code:
ssize_t func1()
{
char *v0; // rbp
ssize_t result; // rax
size_t v2; // rax

v0 = getcwd(0LL, 0LL);
result = 0LL;
if ( v0 )
{
v2 = my_strlen(v0);
result = write(1, v0, v2);
}
return result;
}

original_code:
static int put_dir()
{
  int r;
  char *apwd;
  if ((apwd = getcwd(((void *)0), 0)) == ((void *)0))
    return (0);
  r = write(1, apwd, my_strlen(apwd));
  return (r);
}

variable_types: r int

variable_types:
apwd
char *


interpret

decompiled_code:
__int64 __fastcall interpret(__int64 a1, _DWORD *a2)
{
__uid_t v3; // eax
struct passwd *v4; // r12
char v5; // al
__int64 result; // rax
__int64 v7; // rax
char *v8; // rsi
size_t v9; // rdx

v3 = getuid();
v4 = getpwuid(v3);
v5 = *(_BYTE *)(a1 + 1);
switch ( v5 )
{
case 'd':
*a2 = date_and_time(1);
result = 2LL;
break;
case 'h':
*a2 = date_and_time(0);
result = 2LL;
break;
case 'u':
if ( v4 )
{
v7 = my_strlen(v4->pw_name);
v8 = v4->pw_name;
v9 = v7;
}
else
{
v8 = (char *)&unk_4D1;
v9 = my_strlen(&unk_4D1);
}
*a2 = write(1, v8, v9);
result = 2LL;
break;
case '/':
*a2 = put_dir();
result = 2LL;
break;
default:
*a2 = write(1, &unk_4D5, 1uLL);
result = 1LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _DWORD *a2)
{
__uid_t v3; // eax
struct passwd *v4; // r12
char v5; // al
__int64 result; // rax
__int64 v7; // rax
char *v8; // rsi
size_t v9; // rdx

v3 = getuid();
v4 = getpwuid(v3);
v5 = *(_BYTE *)(a1 + 1);
switch ( v5 )
{
case 'd':
*a2 = func0(1);
result = 2LL;
break;
case 'h':
*a2 = func0(0);
result = 2LL;
break;
case 'u':
if ( v4 )
{
v7 = my_strlen(v4->pw_name);
v8 = v4->pw_name;
v9 = v7;
}
else
{
v8 = (char *)&unk_4D1;
v9 = my_strlen(&unk_4D1);
}
*a2 = write(1, v8, v9);
result = 2LL;
break;
case '/':
*a2 = func1();
result = 2LL;
break;
default:
*a2 = write(1, &unk_4D5, 1uLL);
result = 1LL;
break;
}
return result;
}

original_code:
static size_t interpret(char *s, int *add)
{
  register struct passwd *pw;
  register uid_t uid;
  uid = getuid();
  pw = getpwuid(uid);
  if (s[1] == 'd')
    *add = date_and_time(1);
  else if (s[1] == 'h')
    *add = date_and_time(0);
  else if (s[1] == 'u')
    *add = write(1, (pw) ? (pw->pw_name) : ("✗"),
   my_strlen((pw) ? (pw->pw_name) : ("✗")));
  else if (s[1] == '/')
    *add = put_dir();
  else
    {
      *add = write(1, "%", 1);
      return (1);
    }
  return (2);
}

canonical_original_code:
static unsigned long interpret(char *s, int *add)
{
  register struct passwd *pw;
  register unsigned int uid;
  uid = getuid();
  pw = getpwuid(uid);
  if (s[1] == 'd')
    *add = date_and_time(1);
  else if (s[1] == 'h')
    *add = date_and_time(0);
  else if (s[1] == 'u')
    *add = write(1, (pw) ? (pw->pw_name) : ("✗"),
   my_strlen((pw) ? (pw->pw_name) : ("✗")));
  else if (s[1] == '/')
    *add = put_dir();
  else
    {
      *add = write(1, "%", 1);
      return (1);
    }
  return (2);
}

variable_types:
add
int *

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

variable_types:
uid
unsigned int


decompiled_code:
__int64 __fastcall inter_prompt(char *a1, unsigned __int64 a2, unsigned __int64 a3, unsigned int a4)
{
__int64 v7; // rax
char v8; // al
__int64 v9; // rax
__int64 v10; // r13
unsigned __int64 v11; // r13
bool v12; // cf
unsigned __int64 v13; // r13
char v14; // [rsp+Bh] [rbp-2Dh] BYREF
int v15[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( a2 && a2 <= a3 || !*a1 )
return 0LL;
v7 = my_strlen(&unk_4D7);
if ( (unsigned int)my_strncmp(&unk_4D7, a1, v7) )
{
v8 = *a1;
if ( *a1 != 27 )
goto LABEL_7;
}
v13 = my_strilen(a1, 91LL);
if ( v13 < my_strilen(a1, 109LL) )
{
v11 = my_strilen(a1, 109LL);
v12 = v11 < my_strslen(a1 + 1, &unk_4D7) + 1;
v8 = *a1;
if ( v12 )
{
if ( v8 != 109 )
{
LABEL_22:
a4 = 1;
if ( v8 == 91 )
{
v15[0] = -2;
a4 = 2;
v14 = 0;
goto LABEL_18;
}
goto LABEL_23;
}
goto LABEL_17;
}
LABEL_7:
if ( v8 != 109 )
goto LABEL_8;
LABEL_17:
v15[0] = 1;
a4 = 0;
v14 = 0;
goto LABEL_18;
}
v8 = *a1;
if ( *a1 == 109 )
goto LABEL_17;
LABEL_8:
if ( a4 == 1 )
goto LABEL_22;
if ( a4 == 2 )
{
v15[0] = 0;
goto LABEL_11;
}
LABEL_23:
v15[0] = 1;
LABEL_11:
v14 = 0;
if ( v8 == 37 )
{
v9 = interpret((__int64)a1, v15);
goto LABEL_13;
}
LABEL_18:
v9 = print_seq(a1, 3LL, &v14);
LABEL_13:
if ( v14 )
return 0LL;
v10 = v15[0];
return v10 + inter_prompt(&a1[v9], a2, v9 + a3, a4);
}

original_code:
static size_t inter_prompt(char *s, size_t h, size_t n, int is_color)
{
  int add;
  unsigned char end;
  size_t next;
  if ((h && n >= h) || !s[0])
    return (0);
  if ((((("\\0") && (s)) ? (!my_strncmp(("\\0"), (s), my_strlen("\\0"))) : (0)) || s[0] == 27) && my_strilen(s, '[') <
      my_strilen(s, 'm') && my_strilen(s, 'm') < 1 + my_strslen(s + 1, "\\0"))
    is_color = 1;
  if (s[0] == 'm')
    is_color = 0;
  if (is_color == 1 && s[0] == '[')
    add = -((is_color = 2));
  else if (is_color == 2)
    add = 0;
  else
    add = 1;
  end = 0;
  if (s[0] == '%')
    next = interpret(s, &add);
  else
    next = print_seq(s, 3, &end);
  if (end)
    return (0);
  return (add + inter_prompt((s + next), h, n + next, is_color));
}

canonical_original_code:
static unsigned long inter_prompt(char *s, unsigned long h, unsigned long n, int is_color)
{
  int add;
  unsigned char end;
  unsigned long next;
  if ((h && n >= h) || !s[0])
    return (0);
  if ((((("\\0") && (s)) ? (!my_strncmp(("\\0"), (s), my_strlen("\\0"))) : (0)) || s[0] == 27) && my_strilen(s, '[') <
      my_strilen(s, 'm') && my_strilen(s, 'm') < 1 + my_strslen(s + 1, "\\0"))
    is_color = 1;
  if (s[0] == 'm')
    is_color = 0;
  if (is_color == 1 && s[0] == '[')
    add = -((is_color = 2));
  else if (is_color == 2)
    add = 0;
  else
    add = 1;
  end = 0;
  if (s[0] == '%')
    next = interpret(s, &add);
  else
    next = print_seq(s, 3, &end);
  if (end)
    return (0);
  return (add + inter_prompt((s + next), h, n + next, is_color));
}

variable_types:
h
unsigned long

variable_types: add int

variable_types:
end
unsigned char

variable_types:
next
unsigned long


prompt

decompiled_code:
__int64 __fastcall prompt(char a1)
{
char *v1; // rbp
unsigned __int64 v2; // rbx
unsigned __int64 v3; // r12
__int64 result; // rax
__int64 v5; // rbx
__int64 v6; // rax
unsigned __int64 v7; // rbx
__int64 v8; // rbx
__int64 v9; // rbx

v1 = (char *)get_env("PS1");
if ( !v1 )
v1 = "------>Prompt test\n[Sla.sh] ";
if ( a1 )
{
if ( !v1[my_strilen(v1, 10LL)] && !v1[my_strslen(v1, "\\n")] )
return 0LL;
}
else
{
v7 = last_soccur(v1, "\\n");
if ( v7 < last_occur(v1, 10LL, 0LL) )
{
v9 = last_occur(v1, 10LL, 0LL);
v1 += v9 - ((v1[my_strilen(v1, 10LL)] == 0) - 1LL);
}
else
{
v8 = last_soccur(v1, "\\n");
if ( v1[my_strslen(v1, "\\n")] )
v8 += 2LL;
v1 += v8;
}
}
v2 = last_soccur(v1, "\\n");
if ( v2 < last_occur(v1, 10LL, 0LL) )
{
v5 = last_occur(v1, 10LL, 0LL);
v6 = my_strilen(v1, 10LL);
result = inter_prompt(v1, v5 - ((v1[v6] == 0) - 1LL), 0LL, 0);
}
else
{
v3 = last_soccur(v1, "\\n");
if ( v1[my_strslen(v1, "\\n")] )
v3 += 2LL;
result = inter_prompt(v1, v3, 0LL, 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
char *v1; // rbp
unsigned __int64 v2; // rbx
unsigned __int64 v3; // r12
__int64 result; // rax
__int64 v5; // rbx
__int64 v6; // rax
unsigned __int64 v7; // rbx
__int64 v8; // rbx
__int64 v9; // rbx

v1 = (char *)get_env("PS1");
if ( !v1 )
v1 = "------>Prompt test\n[Sla.sh] ";
if ( a1 )
{
if ( !v1[my_strilen(v1, 10LL)] && !v1[my_strslen(v1, "\\n")] )
return 0LL;
}
else
{
v7 = last_soccur(v1, "\\n");
if ( v7 < last_occur(v1, 10LL, 0LL) )
{
v9 = last_occur(v1, 10LL, 0LL);
v1 += v9 - ((v1[my_strilen(v1, 10LL)] == 0) - 1LL);
}
else
{
v8 = last_soccur(v1, "\\n");
if ( v1[my_strslen(v1, "\\n")] )
v8 += 2LL;
v1 += v8;
}
}
v2 = last_soccur(v1, "\\n");
if ( v2 < last_occur(v1, 10LL, 0LL) )
{
v5 = last_occur(v1, 10LL, 0LL);
v6 = my_strilen(v1, 10LL);
result = func3(v1, v5 - ((v1[v6] == 0) - 1LL), 0LL, 0);
}
else
{
v3 = last_soccur(v1, "\\n");
if ( v1[my_strslen(v1, "\\n")] )
v3 += 2LL;
result = func3(v1, v3, 0LL, 0);
}
return result;
}

original_code:
size_t prompt(unsigned char b)
{
  char *p;
  p = get_env("PS1");
  if (!p)
    p = "------>Prompt test\n[Sla.sh] ";
  if (!b)
    {
      if (last_soccur(p, "\\n") < last_occur(p, '\n', 0))
 p += last_occur(p, '\n', 0) + ((p)[my_strilen(p, '\n')] != 0);
      else
 p += last_soccur(p, "\\n") + ((p)[my_strslen(p, "\\n")] != 0) * 2;
    }
  if (b && !((p)[my_strilen(p, '\n')] != 0) && !((p)[my_strslen(p, "\\n")] != 0))
    return (0);
  if (last_soccur(p, "\\n") < last_occur(p, '\n', 0))
    return (inter_prompt(p, last_occur(p, '\n', 0) + ((p)[my_strilen(p, '\n')] != 0), 0, 0));
  else
    return (inter_prompt(p, last_soccur(p, "\\n") + ((p)[my_strslen(p, "\\n")] != 0) * 2, 0, 0));
}

canonical_original_code:
unsigned long prompt(unsigned char b)
{
  char *p;
  p = get_env("PS1");
  if (!p)
    p = "------>Prompt test\n[Sla.sh] ";
  if (!b)
    {
      if (last_soccur(p, "\\n") < last_occur(p, '\n', 0))
 p += last_occur(p, '\n', 0) + ((p)[my_strilen(p, '\n')] != 0);
      else
 p += last_soccur(p, "\\n") + ((p)[my_strslen(p, "\\n")] != 0) * 2;
    }
  if (b && !((p)[my_strilen(p, '\n')] != 0) && !((p)[my_strslen(p, "\\n")] != 0))
    return (0);
  if (last_soccur(p, "\\n") < last_occur(p, '\n', 0))
    return (inter_prompt(p, last_occur(p, '\n', 0) + ((p)[my_strilen(p, '\n')] != 0), 0, 0));
  else
    return (inter_prompt(p, last_soccur(p, "\\n") + ((p)[my_strslen(p, "\\n")] != 0) * 2, 0, 0));
}

variable_types:
b
unsigned char

variable_types:
p
char *


decompiled_code:
__int64 open_it()
{
__int64 v0; // rax
char *v1; // rbp
unsigned int v2; // er12

v0 = get_env("HOME");
v1 = (char *)my_strcat(v0, ".Slashrc");
v2 = open(v1, 0);
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
char *v1; // rbp
unsigned int v2; // er12

v0 = get_env("HOME");
v1 = (char *)my_strcat(v0, ".Slashrc");
v2 = open(v1, 0);
free(v1);
return v2;
}

original_code:
static int open_it(void)
{
  int file;
  char *name;
  name = my_strcat(get_env("HOME"), ".Slashrc");
  file = open(name, 00);
  free(name);
  return (file);
}

canonical_original_code:
static int open_it()
{
  int file;
  char *name;
  name = my_strcat(get_env("HOME"), ".Slashrc");
  file = open(name, 00);
  free(name);
  return (file);
}

variable_types: file int

variable_types:
name
char *


decompiled_code:
bool __fastcall export_env(__int64 a1, unsigned int a2)
{
bool result; // al
void *ptr; // [rsp+0h] [rbp-18h] BYREF
void *v4; // [rsp+8h] [rbp-10h] BYREF

result = fill_it(a1, (const char **)&ptr, &v4, a2);
if ( result )
{
set_env(ptr, v4);
free(ptr);
free(v4);
result = 1;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func2(__int64 a1, unsigned int a2)
{
bool result; // al
void *ptr; // [rsp+0h] [rbp-18h] BYREF
void *v4; // [rsp+8h] [rbp-10h] BYREF

result = func1(a1, (const char **)&ptr, &v4, a2);
if ( result )
{
set_env(ptr, v4);
free(ptr);
free(v4);
result = 1;
}
return result;
}

original_code:
static unsigned char export_env(char *s, int no)
{
  char *s1;
  char *s2;
  if (fill_it(s, &s1, &s2, no) == 0)
    return (0);
  set_env(s1, s2);
  free(s1);
  free(s2);
  return (1);
}

variable_types:
s
char *

variable_types: no int


decompiled_code:
bool __fastcall export_alias(__int64 a1, __int64 *a2, unsigned int a3)
{
__int64 v5; // rsi
__int64 v6; // rbx
void *v7; // r8
void *v8; // rdi
void *ptr; // [rsp+0h] [rbp-28h] BYREF
__int64 v11[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !fill_it(a1, (const char **)&ptr, v11, a3) )
return 0;
if ( !ptr || (v5 = v11[0]) == 0 )
{
printf("error at line %d\n", a3);
if ( !ptr )
return 0;
v5 = v11[0];
if ( !v11[0] )
return 0;
}
v6 = *a2;
v7 = ptr;
if ( *a2 )
{
do
{
if ( *(_QWORD *)v6 && v7 )
{
if ( !(unsigned int)my_strcmp(*(_QWORD *)v6, v7) )
{
free(*(void **)(v6 + 16));
v8 = ptr;
*(_QWORD *)(v6 + 8) = v11[0];
free(v8);
return 0;
}
v7 = ptr;
}
v6 = *(_QWORD *)(v6 + 16);
}
while ( v6 );
v5 = v11[0];
}
return (unsigned int)mod_alias(v7, v5, a2) == 0;
}

canonical_decompiled_code:
bool __fastcall func3(__int64 a1, __int64 *a2, unsigned int a3)
{
__int64 v5; // rsi
__int64 v6; // rbx
void *v7; // r8
void *v8; // rdi
void *ptr; // [rsp+0h] [rbp-28h] BYREF
__int64 v11[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !func1(a1, (const char **)&ptr, v11, a3) )
return 0;
if ( !ptr || (v5 = v11[0]) == 0 )
{
printf("error at line %d\n", a3);
if ( !ptr )
return 0;
v5 = v11[0];
if ( !v11[0] )
return 0;
}
v6 = *a2;
v7 = ptr;
if ( *a2 )
{
do
{
if ( *(_QWORD *)v6 && v7 )
{
if ( !(unsigned int)my_strcmp(*(_QWORD *)v6, v7) )
{
free(*(void **)(v6 + 16));
v8 = ptr;
*(_QWORD *)(v6 + 8) = v11[0];
free(v8);
return 0;
}
v7 = ptr;
}
v6 = *(_QWORD *)(v6 + 16);
}
while ( v6 );
v5 = v11[0];
}
return (unsigned int)mod_alias(v7, v5, a2) == 0;
}

original_code:
static unsigned char export_alias(char *s, t_alias **alias, int no)
{
  t_alias *link;
  unsigned char c;
  char *s1;
  char *s2;
  if (fill_it(s, &s1, &s2, no) == 0)
    return (0);
  if (!s1 || !s2)
    printf("error at line %d\n", no);
  if (!s1 || !s2)
    return (0);
  link = *alias + (unsigned int)(c = 0);
  while (link && !c)
    if (((link->name && s1) ? (!my_strcmp(link->name, s1)) : (0)))
      c = 1;
    else
      link = link->next;
  if (!c)
    return (!mod_alias(s1, s2, alias));
  free(link->next);
  link->fill = s2;
  free(s1);
  return (0);
}

canonical_original_code:
static unsigned char export_alias(char *s, struct s_alias **alias, int no)
{
  struct s_alias *link;
  unsigned char c;
  char *s1;
  char *s2;
  if (fill_it(s, &s1, &s2, no) == 0)
    return (0);
  if (!s1 || !s2)
    printf("error at line %d\n", no);
  if (!s1 || !s2)
    return (0);
  link = *alias + (unsigned int)(c = 0);
  while (link && !c)
    if (((link->name && s1) ? (!my_strcmp(link->name, s1)) : (0)))
      c = 1;
    else
      link = link->next;
  if (!c)
    return (!mod_alias(s1, s2, alias));
  free(link->next);
  link->fill = s2;
  free(s1);
  return (0);
}

variable_types: struct s_alias { char *name; char *fill; struct s_alias *next; struct s_alias *prev; unsigned long w; unsigned long n; } **

variable_types:
c
unsigned char


decompiled_code:
__int64 __fastcall scan_export(__int64 *a1)
{
__int64 result; // rax
unsigned int v2; // er13
bool v3; // bl
unsigned int i; // er12
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rbx
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax

result = open_it();
if ( (_DWORD)result != -1 )
{
v2 = result;
v3 = 1;
for ( i = 0; ; ++i )
{
result = get_next_line(v2);
v8 = result;
if ( !result || !v3 )
break;
v9 = my_strlen("export");
if ( (unsigned int)my_strncmp("export", v8, v9) )
{
v10 = my_strlen("alias");
if ( (unsigned int)my_strncmp("alias", v8, v10) )
{
v14 = my_strilen(v8, 35LL);
result = nempty(v8, v14);
if ( !(_BYTE)result )
return result;
}
else
{
v11 = my_strlen("export");
v12 = my_strlen("export");
v13 = hempty(v8 + v12);
v3 = export_alias(v8 + v11 + v13, a1, i);
}
}
else
{
v5 = my_strlen("export");
v6 = my_strlen("export");
v7 = hempty(v8 + v6);
v3 = export_env(v8 + v5 + v7, i);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
__int64 result; // rax
unsigned int v2; // er13
bool v3; // bl
unsigned int i; // er12
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rbx
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax

result = func0();
if ( (_DWORD)result != -1 )
{
v2 = result;
v3 = 1;
for ( i = 0; ; ++i )
{
result = get_next_line(v2);
v8 = result;
if ( !result || !v3 )
break;
v9 = my_strlen("export");
if ( (unsigned int)my_strncmp("export", v8, v9) )
{
v10 = my_strlen("alias");
if ( (unsigned int)my_strncmp("alias", v8, v10) )
{
v14 = my_strilen(v8, 35LL);
result = nempty(v8, v14);
if ( !(_BYTE)result )
return result;
}
else
{
v11 = my_strlen("export");
v12 = my_strlen("export");
v13 = hempty(v8 + v12);
v3 = func3(v8 + v11 + v13, a1, i);
}
}
else
{
v5 = my_strlen("export");
v6 = my_strlen("export");
v7 = hempty(v8 + v6);
v3 = func2(v8 + v5 + v7, i);
}
}
}
return result;
}

original_code:
void scan_export(t_alias **alias)
{
  int no;
  unsigned char c;
  char *s;
  int file;
  c = 1;
  no = 0;
  if ((file = open_it()) == -1)
    return ;
  while ((s = get_next_line(file)) != ((void *)0) && c)
    {
      if (((("export") && (s)) ? (!my_strncmp(("export"), (s), my_strlen("export"))) : (0)))
 c = export_env(s + my_strlen("export")
         + hempty(s + my_strlen("export")), no);
      else if (((("alias") && (s)) ? (!my_strncmp(("alias"), (s), my_strlen("alias"))) : (0)))
 c = export_alias(s + my_strlen("export")
    + hempty(s + my_strlen("export")),
    alias, no);
      else if (!nempty(s, my_strilen(s, '#')))
 return ;
      no++;
    }
}

canonical_original_code:
void scan_export(struct s_alias **alias)
{
  int no;
  unsigned char c;
  char *s;
  int file;
  c = 1;
  no = 0;
  if ((file = open_it()) == -1)
    return ;
  while ((s = get_next_line(file)) != ((void *)0) && c)
    {
      if (((("export") && (s)) ? (!my_strncmp(("export"), (s), my_strlen("export"))) : (0)))
 c = export_env(s + my_strlen("export")
         + hempty(s + my_strlen("export")), no);
      else if (((("alias") && (s)) ? (!my_strncmp(("alias"), (s), my_strlen("alias"))) : (0)))
 c = export_alias(s + my_strlen("export")
    + hempty(s + my_strlen("export")),
    alias, no);
      else if (!nempty(s, my_strilen(s, '#')))
 return ;
      no++;
    }
}

user_defined_types: struct s_alias { char *name; char *fill; struct s_alias *next; struct s_alias *prev; unsigned long w; unsigned long n; }


decompiled_code:
bool __fastcall fill_it(__int64 a1, const char **a2, _QWORD *a3, unsigned int a4)
{
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // r14
_BOOL8 v11; // rdi
char *v12; // rbx
unsigned int v13; // er14
__int64 v14; // rax
__int64 v15; // r14
__int64 v16; // rax
__int64 v17; // rbp
__int64 v18; // r14

*a2 = 0LL;
*a3 = 0LL;
if ( (unsigned __int8)((__int64 (*)(void))empty)() )
return 0;
v8 = my_sstrlen(a1, "= \t");
v9 = my_strndup(a1, v8);
*a2 = (const char *)v9;
if ( !v9 )
return 1;
v10 = my_sstrlen(a1, "= \t");
if ( *(_BYTE *)(a1 + my_strilen(a1, 61LL)) || *(_BYTE *)(a1 + my_strilen(a1, 32LL)) )
v11 = 1LL;
else
v11 = *(_BYTE *)(a1 + my_strilen(a1, 9LL)) != 0;
v12 = (char *)(v11 + v10 + a1);
v13 = *v12;
if ( asc_54D[my_strilen("\"'", v13)] && !v12[my_strilen(v12 + 1, (unsigned int)*v12) + 1] )
printf("error in conf file at line #%d, in %s definition\n", a4, *a2);
if ( asc_54D[my_strilen("\"'", (unsigned int)*v12)] && !v12[my_strilen(v12 + 1, (unsigned int)*v12) + 1] )
return 0;
if ( !asc_550[my_strilen("'\"", (unsigned int)*v12)] )
v13 = 0;
v14 = my_strilen("'\"", (unsigned int)*v12);
v15 = my_strilen(&v12[-(asc_550[v14] == 0) + 1], v13);
v16 = my_strilen("'\"", (unsigned int)*v12);
*a3 = my_strndup(&v12[-(asc_550[v16] == 0) + 1], v15);
if ( asc_550[my_strilen("'\"", (unsigned int)*v12)] )
{
v18 = my_strlen(*a3);
if ( asc_550[my_strilen("'\"", (unsigned int)*v12)] )
v18 += 2LL;
if ( !(unsigned __int8)empty(&v12[v18]) )
printf("error in conf file at line #%d, in %s definition\n", a4, *a2);
}
if ( !asc_550[my_strilen("'\"", (unsigned int)*v12)] )
return 1;
v17 = my_strlen(*a3);
if ( asc_550[my_strilen("'\"", (unsigned int)*v12)] )
v17 += 2LL;
return (unsigned __int8)empty(&v12[v17]) != 0;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1, const char **a2, _QWORD *a3, unsigned int a4)
{
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // r14
_BOOL8 v11; // rdi
char *v12; // rbx
unsigned int v13; // er14
__int64 v14; // rax
__int64 v15; // r14
__int64 v16; // rax
__int64 v17; // rbp
__int64 v18; // r14

*a2 = 0LL;
*a3 = 0LL;
if ( (unsigned __int8)((__int64 (*)(void))empty)() )
return 0;
v8 = my_sstrlen(a1, "= \t");
v9 = my_strndup(a1, v8);
*a2 = (const char *)v9;
if ( !v9 )
return 1;
v10 = my_sstrlen(a1, "= \t");
if ( *(_BYTE *)(a1 + my_strilen(a1, 61LL)) || *(_BYTE *)(a1 + my_strilen(a1, 32LL)) )
v11 = 1LL;
else
v11 = *(_BYTE *)(a1 + my_strilen(a1, 9LL)) != 0;
v12 = (char *)(v11 + v10 + a1);
v13 = *v12;
if ( asc_54D[my_strilen("\"'", v13)] && !v12[my_strilen(v12 + 1, (unsigned int)*v12) + 1] )
printf("error in conf file at line #%d, in %s definition\n", a4, *a2);
if ( asc_54D[my_strilen("\"'", (unsigned int)*v12)] && !v12[my_strilen(v12 + 1, (unsigned int)*v12) + 1] )
return 0;
if ( !asc_550[my_strilen("'\"", (unsigned int)*v12)] )
v13 = 0;
v14 = my_strilen("'\"", (unsigned int)*v12);
v15 = my_strilen(&v12[-(asc_550[v14] == 0) + 1], v13);
v16 = my_strilen("'\"", (unsigned int)*v12);
*a3 = my_strndup(&v12[-(asc_550[v16] == 0) + 1], v15);
if ( asc_550[my_strilen("'\"", (unsigned int)*v12)] )
{
v18 = my_strlen(*a3);
if ( asc_550[my_strilen("'\"", (unsigned int)*v12)] )
v18 += 2LL;
if ( !(unsigned __int8)empty(&v12[v18]) )
printf("error in conf file at line #%d, in %s definition\n", a4, *a2);
}
if ( !asc_550[my_strilen("'\"", (unsigned int)*v12)] )
return 1;
v17 = my_strlen(*a3);
if ( asc_550[my_strilen("'\"", (unsigned int)*v12)] )
v17 += 2LL;
return (unsigned __int8)empty(&v12[v17]) != 0;
}

variable_types: get char


decompiled_code:
__int64 __fastcall nullify_all_jobs(_QWORD *a1)
{
__int64 v1; // r12

if ( !a1 )
return 0LL;
if ( a1[2] )
nullify_all_exec();
else
nullify_words(a1[3]);
v1 = a1[1];
free(a1);
nullify_all_jobs(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 v1; // r12

if ( !a1 )
return 0LL;
if ( a1[2] )
nullify_all_exec();
else
nullify_words(a1[3]);
v1 = a1[1];
free(a1);
func0(v1);
return 0LL;
}

original_code:
void *nullify_all_jobs(t_jobs *jobs)
{
  t_jobs *next;
  if (!jobs)
    return (((void *)0));
  if (jobs->exec)
    nullify_all_exec(jobs->exec);
  else
    nullify_words(jobs->tmp);
  next = jobs->next;
  free(jobs);
  nullify_all_jobs(next);
  return (((void *)0));
}

canonical_original_code:
void *nullify_all_jobs(struct s_jobs *jobs)
{
  struct s_jobs *next;
  if (!jobs)
    return (((void *)0));
  if (jobs->exec)
    nullify_all_exec(jobs->exec);
  else
    nullify_words(jobs->tmp);
  next = jobs->next;
  free(jobs);
  nullify_all_jobs(next);
  return (((void *)0));
}

variable_types: struct s_jobs { unsigned int type; struct s_jobs *next; struct s_exec { unsigned int type; struct s_exec *next; struct s_pipes { struct s_pipes *next; struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *tmp; struct s_cmd { struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *redir; unsigned int type; struct s_words { char *word; struct s_words *next; } *params; struct s_jobs *parents; } *cmd; } *pipes; struct s_get *tmp; } *exec; struct s_get *tmp; } *

return_type: void *

user_defined_types: struct s_jobs { unsigned int type; struct s_jobs *next; struct s_exec *exec; struct s_get *tmp; }

user_defined_types: struct s_exec { unsigned int type; struct s_exec *next; struct s_pipes *pipes; struct s_get *tmp; }

user_defined_types: struct s_pipes { struct s_pipes *next; struct s_get *tmp; struct s_cmd *cmd; }

user_defined_types: struct s_cmd { struct s_redir *redir; unsigned int type; struct s_words *params; struct s_jobs *parents; }


decompiled_code:
__int64 __fastcall nullify_jobs(void *ptr, char a2)
{
__int64 result; // rax

if ( *((_QWORD *)ptr + 2) )
{
if ( a2 )
{
LABEL_3:
nullify_exec();
free(ptr);
return 0LL;
}
nullify_all_exec();
free(ptr);
result = 0LL;
}
else
{
if ( a2 )
goto LABEL_3;
nullify_words(*((_QWORD *)ptr + 3));
free(ptr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr, char a2)
{
__int64 result; // rax

if ( *((_QWORD *)ptr + 2) )
{
if ( a2 )
{
LABEL_3:
nullify_exec();
free(ptr);
return 0LL;
}
nullify_all_exec();
free(ptr);
result = 0LL;
}
else
{
if ( a2 )
goto LABEL_3;
nullify_words(*((_QWORD *)ptr + 3));
free(ptr);
result = 0LL;
}
return result;
}

original_code:
unsigned char nullify_jobs(t_jobs *jobs, unsigned char ex)
{
  if (jobs->exec && !ex)
    nullify_all_exec(jobs->exec);
  else if (!ex)
    nullify_words(jobs->tmp);
  if (ex)
    nullify_exec(jobs->exec);
  free(jobs);
  return (0);
}

canonical_original_code:
unsigned char nullify_jobs(struct s_jobs *jobs, unsigned char ex)
{
  if (jobs->exec && !ex)
    nullify_all_exec(jobs->exec);
  else if (!ex)
    nullify_words(jobs->tmp);
  if (ex)
    nullify_exec(jobs->exec);
  free(jobs);
  return (0);
}

variable_types:
ex
unsigned char

user_defined_types: struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; }

user_defined_types: struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; }

user_defined_types: struct s_words { char *word; struct s_words *next; }


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

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

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

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

original_code:
void nullify_cmd_words(t_words *s)
{
  t_words *n;
  if (!s)
    return ;
  n = s->next;
  if (s->word)
    free(s->word);
  free(s);
  nullify_cmd_words(n);
}

canonical_original_code:
void nullify_cmd_words(struct s_words *s)
{
  struct s_words *n;
  if (!s)
    return ;
  n = s->next;
  if (s->word)
    free(s->word);
  free(s);
  nullify_cmd_words(n);
}

variable_types: struct s_words { char *word; struct s_words *next; } *


decompiled_code:
__int64 __fastcall nullify_redir(_QWORD *a1)
{
__int64 v2; // r12
void *v3; // rdi

if ( !a1 )
return 0LL;
v2 = a1[3];
v3 = (void *)a1[2];
if ( v3 )
free(v3);
free(a1);
nullify_redir(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 v2; // r12
void *v3; // rdi

if ( !a1 )
return 0LL;
v2 = a1[3];
v3 = (void *)a1[2];
if ( v3 )
free(v3);
free(a1);
func3(v2);
return 0LL;
}

original_code:
unsigned char nullify_redir(t_redir *r)
{
  t_redir *n;
  if (!r)
    return (0);
  n = r->next;
  if (r->file)
    free(r->file);
  free(r);
  nullify_redir(n);
  return (0);
}

canonical_original_code:
unsigned char nullify_redir(struct s_redir *r)
{
  struct s_redir *n;
  if (!r)
    return (0);
  n = r->next;
  if (r->file)
    free(r->file);
  free(r);
  nullify_redir(n);
  return (0);
}

variable_types: struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *


decompiled_code:
__int64 __fastcall nullify_cmd(void *ptr)
{
void *v2; // rdi
_QWORD *v4; // rdi

if ( !ptr )
return 0LL;
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
{
nullify_cmd_words(v2);
}
else
{
v4 = (_QWORD *)*((_QWORD *)ptr + 3);
if ( v4 )
nullify_all_jobs(v4);
}
if ( *(_QWORD *)ptr )
nullify_redir(*(_QWORD **)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
void *v2; // rdi
_QWORD *v4; // rdi

if ( !ptr )
return 0LL;
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
{
func2(v2);
}
else
{
v4 = (_QWORD *)*((_QWORD *)ptr + 3);
if ( v4 )
func0(v4);
}
if ( *(_QWORD *)ptr )
func3(*(_QWORD **)ptr);
free(ptr);
return 0LL;
}

original_code:
unsigned char nullify_cmd(t_cmd *cmd)
{
  if (!cmd)
    return (0);
  if (cmd->params)
    nullify_cmd_words(cmd->params);
  else if (cmd->parents)
    nullify_all_jobs(cmd->parents);
  if (cmd->redir)
    nullify_redir(cmd->redir);
  free(cmd);
  return (0);
}

canonical_original_code:
unsigned char nullify_cmd(struct s_cmd *cmd)
{
  if (!cmd)
    return (0);
  if (cmd->params)
    nullify_cmd_words(cmd->params);
  else if (cmd->parents)
    nullify_all_jobs(cmd->parents);
  if (cmd->redir)
    nullify_redir(cmd->redir);
  free(cmd);
  return (0);
}

variable_types: struct s_cmd { struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *redir; unsigned int type; struct s_words { char *word; struct s_words *next; } *params; struct s_jobs { unsigned int type; struct s_jobs *next; struct s_exec { unsigned int type; struct s_exec *next; struct s_pipes { struct s_pipes *next; struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *tmp; struct s_cmd *cmd; } *pipes; struct s_get *tmp; } *exec; struct s_get *tmp; } *parents; } *


decompiled_code:
__int64 __fastcall del_letter_in_str(__int64 a1, int *a2, __int64 *a3)
{
__int64 result; // rax
__int64 v5; // rcx
_BYTE *i; // rdx

result = *a2;
if ( (int)result > 0 )
{
v5 = *a3;
for ( i = (_BYTE *)(*a3 + (int)result - 1); *i; ++result )
{
*i = *(_BYTE *)(v5 + result);
v5 = *a3;
i = (_BYTE *)(*a3 + result);
}
result = my_putstr(&unk_2AA, 1LL);
--*a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int *a2, __int64 *a3)
{
__int64 result; // rax
__int64 v5; // rcx
_BYTE *i; // rdx

result = *a2;
if ( (int)result > 0 )
{
v5 = *a3;
for ( i = (_BYTE *)(*a3 + (int)result - 1); *i; ++result )
{
*i = *(_BYTE *)(v5 + result);
v5 = *a3;
i = (_BYTE *)(*a3 + result);
}
result = my_putstr(&unk_2AA, 1LL);
--*a2;
}
return result;
}

original_code:
void del_letter_in_str(char value, int *reverse_case, char **cmd)
{
  int suppr;
  (void)value;
  suppr = (*reverse_case) - 1;
  if ((*reverse_case) > 0)
    {
      while ((*cmd)[suppr] != '\0')
        {
          (*cmd)[suppr] = (*cmd)[suppr + 1];
          suppr++;
        }
      my_putstr("\r", 1);
      (*reverse_case)--;
    }
}

variable_types: value char

variable_types:
cmd
char **

variable_types: suppr int


original_code:
int add_letter_in_str(char value, int *reverse_case, char **cmd)
{
  int len;
  len = my_strlen(*cmd) + 1;
  while (--len > (*reverse_case))
    (*cmd)[len + 1] = (*cmd)[len];
  if (my_strlen(*cmd) + 1 > 1)
    (*cmd)[len + 1] = (*cmd)[len];
  (*cmd)[len] = value;
  (*reverse_case)++;
  if (((*cmd) = my_realloc(*cmd,
      my_strlen(*cmd), my_strlen(*cmd) + 2)) == ((void *)0))
    return (-1);
  (*cmd)[my_strlen(*cmd) + 1] = '\0';
  return (0);
}

variable_types: len int


decompiled_code:
__int64 __fastcall modif_cmd(__int64 *a1, char *a2, _DWORD *a3)
{
__int64 v5; // rax
__int64 v6; // rdi
unsigned int v7; // er12
char *i; // rbp
char v10[14]; // [rsp+2h] [rbp-B6h] BYREF
__int64 v11[21]; // [rsp+10h] [rbp-A8h] BYREF

fill_tab((__int64)v10);
fill_fct_ptr(v11);
v6 = (unsigned int)*a2;
do
{
v7 = v5;
if ( v10[v5] == *a2 )
{
if ( (_DWORD)v5 )
{
if ( (unsigned int)(v5 - 8) > 1 && (_DWORD)v5 != 13 )
v6 = (unsigned int)a2[2];
}
else
{
v6 = (unsigned int)a2[2];
if ( !a2[2] )
{
((void (__fastcall *)(_QWORD, _DWORD *, __int64 *))v11[0])((unsigned int)a2[1], a3, a1);
return v7;
}
}
((void (__fastcall *)(__int64, _DWORD *, __int64 *))v11[(int)v5])(v6, a3, a1);
return 0;
}
++v5;
}
while ( v5 != 14 );
for ( i = a2 + 1; (char)v6 > 31; ++i )
{
v7 = add_letter_in_str(v6, a3, a1);
if ( v7 == -1 )
return v7;
if ( i == a2 + 4 )
break;
LOBYTE(v6) = *i;
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, char *a2, _DWORD *a3)
{
__int64 v5; // rax
__int64 v6; // rdi
unsigned int v7; // er12
char *i; // rbp
char v10[14]; // [rsp+2h] [rbp-B6h] BYREF
__int64 v11[21]; // [rsp+10h] [rbp-A8h] BYREF

func1((__int64)v10);
func0(v11);
v6 = (unsigned int)*a2;
do
{
v7 = v5;
if ( v10[v5] == *a2 )
{
if ( (_DWORD)v5 )
{
if ( (unsigned int)(v5 - 8) > 1 && (_DWORD)v5 != 13 )
v6 = (unsigned int)a2[2];
}
else
{
v6 = (unsigned int)a2[2];
if ( !a2[2] )
{
((void (__fastcall *)(_QWORD, _DWORD *, __int64 *))v11[0])((unsigned int)a2[1], a3, a1);
return v7;
}
}
((void (__fastcall *)(__int64, _DWORD *, __int64 *))v11[(int)v5])(v6, a3, a1);
return 0;
}
++v5;
}
while ( v5 != 14 );
for ( i = a2 + 1; (char)v6 > 31; ++i )
{
v7 = func3(v6, a3, a1);
if ( v7 == -1 )
return v7;
if ( i == a2 + 4 )
break;
LOBYTE(v6) = *i;
}
return 0;
}

original_code:
int modif_cmd(char **cmd, char *str, int *reverse_case)
{
  int i;
  void (*options[15])(char, int *, char **);
  char opt[14];
  i = -1;
  fill_tab(opt);
  fill_fct_ptr(options);
  while (++i < 14 && opt[i] != str[0]);
  if (i != 14)
    if (i == 0 && str[2] == 0)
      (options[i])(str[1], reverse_case, cmd);
    else if (i == 8 || i == 9 || i == 13)
      (options[i])(str[0], reverse_case, cmd);
    else
      (options[i])(str[2], reverse_case, cmd);
  else
    {
      i = -1;
      while (++i < 4 && str[i] >= ' ')
 if (add_letter_in_str(str[i], reverse_case, cmd) == -1)
   return (-1);
    }
  return (0);
}

variable_types:
str
char *

variable_types: i int

variable_types:
options
void (*[15])(char, int *, char **)

variable_types:
opt
char [14]


decompiled_code:
__int64 __fastcall my_strnslen(_BYTE *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12

v3 = 0LL;
if ( *a1 )
{
do
{
if ( !(unsigned int)my_strncmp(a2, &a1[v3], a3) )
break;
++v3;
}
while ( a1[v3] );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12

v3 = 0LL;
if ( *a1 )
{
do
{
if ( !(unsigned int)my_strncmp(a2, &a1[v3], a3) )
break;
++v3;
}
while ( a1[v3] );
}
return v3;
}

original_code:
size_t my_strnslen(const char *s, const char *c, size_t n)
{
  size_t i;
  i = 0;
  while (s[i] && my_strncmp(c, s + i, n))
    i++;
  return (i);
}

canonical_original_code:
unsigned long my_strnslen(char *s, char *c, unsigned long n)
{
  unsigned long i;
  i = 0;
  while (s[i] && my_strncmp(c, s + i, n))
    i++;
  return (i);
}

variable_types:
s
char *

variable_types:
c
char *

variable_types:
n
unsigned long

variable_types:
i
unsigned long


decompiled_code:
bool __fastcall recur_match(_BYTE *a1, _BYTE *a2, __int64 a3)
{
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // rax
__int64 v9; // r13
__int64 v10; // rbx
unsigned __int64 v12; // rbx
__int64 v13; // rbx
__int64 v14; // rax

while ( 1 )
{
if ( !*a1 && (!*a2 || !(unsigned int)my_strcmp(a2, &unk_3E5)) || !a3 )
return 1;
if ( !a2[my_strilen(a2, 42LL)] )
break;
v6 = my_strilen(a2, 42LL);
if ( !a1[my_strnslen(a1, (__int64)a2, v6)] )
return 0;
v7 = my_strilen(a2, 42LL);
v8 = my_strilen(a2, 42LL);
v9 = my_strnslen(a1, (__int64)a2, v8);
a1 += my_strilen(a2, 42LL) + v9;
v10 = v7 - ((a2[my_strilen(a2, 42LL)] == 0) - 1LL);
a2 += v10;
a3 -= v10;
}
v12 = my_strlen(a1);
if ( v12 < my_strlen(a2) )
return 0;
my_strlen(a1);
my_strlen(a2);
v13 = my_strlen(a1);
v14 = my_strlen(a2);
return (unsigned int)my_strcmp(a2, &a1[v13 - v14]) == 0;
}

canonical_decompiled_code:
bool __fastcall func1(_BYTE *a1, _BYTE *a2, __int64 a3)
{
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // rax
__int64 v9; // r13
__int64 v10; // rbx
unsigned __int64 v12; // rbx
__int64 v13; // rbx
__int64 v14; // rax

while ( 1 )
{
if ( !*a1 && (!*a2 || !(unsigned int)my_strcmp(a2, &unk_3E5)) || !a3 )
return 1;
if ( !a2[my_strilen(a2, 42LL)] )
break;
v6 = my_strilen(a2, 42LL);
if ( !a1[func0(a1, (__int64)a2, v6)] )
return 0;
v7 = my_strilen(a2, 42LL);
v8 = my_strilen(a2, 42LL);
v9 = func0(a1, (__int64)a2, v8);
a1 += my_strilen(a2, 42LL) + v9;
v10 = v7 - ((a2[my_strilen(a2, 42LL)] == 0) - 1LL);
a2 += v10;
a3 -= v10;
}
v12 = my_strlen(a1);
if ( v12 < my_strlen(a2) )
return 0;
my_strlen(a1);
my_strlen(a2);
v13 = my_strlen(a1);
v14 = my_strlen(a2);
return (unsigned int)my_strcmp(a2, &a1[v13 - v14]) == 0;
}

original_code:
static unsigned char recur_match(const char *s, const char *c, size_t n)
{
  size_t l;
  unsigned char k;
  if ((!s[0] && (!c[0] || ((c && "*") ? (!my_strcmp(c, "*")) : (0)))) || n <= 0)
    return (1);
  if (!((c)[my_strilen(c, '*')] != 0))
    {
      if (my_strlen(s) < my_strlen(c))
 return (0);
      if (((c && s + my_strlen(s) - my_strlen(c)) ? (!my_strcmp(c, s + my_strlen(s) - my_strlen(c))) : (0)))
 return (1);
      else
 return (0);
    }
  if (!((s)[my_strnslen(s, c, my_strilen(c, '*'))] != 0))
    return (0);
  l = my_strilen(c, '*');
  s += my_strnslen(s, c, my_strilen(c, '*')) + my_strilen(c, '*');
  c += l + (k = ((c)[my_strilen(c, '*')] != 0));
  return (recur_match(s, c, n - l - k));
}

canonical_original_code:
static unsigned char recur_match(char *s, char *c, unsigned long n)
{
  unsigned long l;
  unsigned char k;
  if ((!s[0] && (!c[0] || ((c && "*") ? (!my_strcmp(c, "*")) : (0)))) || n <= 0)
    return (1);
  if (!((c)[my_strilen(c, '*')] != 0))
    {
      if (my_strlen(s) < my_strlen(c))
 return (0);
      if (((c && s + my_strlen(s) - my_strlen(c)) ? (!my_strcmp(c, s + my_strlen(s) - my_strlen(c))) : (0)))
 return (1);
      else
 return (0);
    }
  if (!((s)[my_strnslen(s, c, my_strilen(c, '*'))] != 0))
    return (0);
  l = my_strilen(c, '*');
  s += my_strnslen(s, c, my_strilen(c, '*')) + my_strilen(c, '*');
  c += l + (k = ((c)[my_strilen(c, '*')] != 0));
  return (recur_match(s, c, n - l - k));
}

variable_types:
l
unsigned long

variable_types:
k
unsigned char


original_code:
size_t last_occur(const char *s, char c, char e)
{
  size_t i;
  size_t l;
  i = 0;
  l = 0;
  while (s[i] && s[i] != e)
    {
      if (s[i] == c)
 l = i;
      i++;
    }
  return (l);
}

canonical_original_code:
unsigned long last_occur(char *s, char c, char e)
{
  unsigned long i;
  unsigned long l;
  i = 0;
  l = 0;
  while (s[i] && s[i] != e)
    {
      if (s[i] == c)
 l = i;
      i++;
    }
  return (l);
}

variable_types: c char

variable_types: e char


match

decompiled_code:
bool __fastcall match(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r12
__int64 v4; // r12
__int64 v5; // r13
__int64 v6; // r12
__int64 v7; // r12
__int64 v8; // rax

if ( !a1 )
return 0;
if ( !a2 )
return 0;
v2 = my_strilen(a2, 42LL);
if ( (unsigned int)my_strncmp(a1, a2, v2) )
return 0;
v3 = my_strlen(a2);
v4 = v3 - my_strilen(a2, 42LL);
v5 = (*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) + v4 - 1;
v6 = my_strilen(a2, 42LL);
v7 = v6 - ((*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) - 1LL);
v8 = my_strilen(a2, 42LL);
return recur_match((_BYTE *)(a1 + v8), (_BYTE *)(a2 + v7), v5);
}

original_code:
unsigned char match(const char *s, const char *c)
{
  if (!(s && c))
    return (0);
  if (!(((s) && (c)) ? (!my_strncmp((s), (c), my_strilen(c, '*'))) : (0)))
    return (0);
  return (recur_match(s + my_strilen(c, '*'), c + my_strilen(c, '*')
        + ((c)[my_strilen(c, '*')] != 0), my_strlen(c) - my_strilen(c, '*')
        - ((c)[my_strilen(c, '*')] != 0)));
}

canonical_original_code:
unsigned char match(char *s, char *c)
{
  if (!(s && c))
    return (0);
  if (!(((s) && (c)) ? (!my_strncmp((s), (c), my_strilen(c, '*'))) : (0)))
    return (0);
  return (recur_match(s + my_strilen(c, '*'), c + my_strilen(c, '*')
        + ((c)[my_strilen(c, '*')] != 0), my_strlen(c) - my_strilen(c, '*')
        - ((c)[my_strilen(c, '*')] != 0)));
}


nmatch

decompiled_code:
bool __fastcall nmatch(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned __int64 v6; // r12
__int64 v7; // r12
__int64 v8; // r13
__int64 v9; // r13
__int64 v10; // rax

if ( !a1 )
return 0;
if ( a2 )
{
if ( my_strilen(a2, 42LL) > a3 && !(unsigned int)my_strncmp(a1, a2, a3) )
return 1;
v4 = my_strilen(a2, 42LL);
if ( !(unsigned int)my_strncmp(a1, a2, v4) )
{
v6 = a3 - my_strilen(a2, 42LL);
v7 = (*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) + v6 - 1;
v8 = my_strilen(a2, 42LL);
v9 = v8 - ((*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) - 1LL);
v10 = my_strilen(a2, 42LL);
return recur_match((_BYTE *)(a1 + v10), (_BYTE *)(a2 + v9), v7);
}
}
return 0;
}

canonical_decompiled_code:
bool __fastcall func4(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned __int64 v6; // r12
__int64 v7; // r12
__int64 v8; // r13
__int64 v9; // r13
__int64 v10; // rax

if ( !a1 )
return 0;
if ( a2 )
{
if ( my_strilen(a2, 42LL) > a3 && !(unsigned int)my_strncmp(a1, a2, a3) )
return 1;
v4 = my_strilen(a2, 42LL);
if ( !(unsigned int)my_strncmp(a1, a2, v4) )
{
v6 = a3 - my_strilen(a2, 42LL);
v7 = (*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) + v6 - 1;
v8 = my_strilen(a2, 42LL);
v9 = v8 - ((*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) - 1LL);
v10 = my_strilen(a2, 42LL);
return func1((_BYTE *)(a1 + v10), (_BYTE *)(a2 + v9), v7);
}
}
return 0;
}

original_code:
unsigned char nmatch(const char *s, const char *c, size_t n)
{
  if (!(s && c))
    return (0);
  if (n < my_strilen(c, '*') && (((s) && (c)) ? (!my_strncmp((s), (c), n)) : (0)))
    return (1);
  if (!(((s) && (c)) ? (!my_strncmp((s), (c), my_strilen(c, '*'))) : (0)))
    return (0);
  return (recur_match(s + my_strilen(c, '*'), c + my_strilen(c, '*')
        + ((c)[my_strilen(c, '*')] != 0), n - my_strilen(c, '*')
        - ((c)[my_strilen(c, '*')] != 0)));
}

canonical_original_code:
unsigned char nmatch(char *s, char *c, unsigned long n)
{
  if (!(s && c))
    return (0);
  if (n < my_strilen(c, '*') && (((s) && (c)) ? (!my_strncmp((s), (c), n)) : (0)))
    return (1);
  if (!(((s) && (c)) ? (!my_strncmp((s), (c), my_strilen(c, '*'))) : (0)))
    return (0);
  return (recur_match(s + my_strilen(c, '*'), c + my_strilen(c, '*')
        + ((c)[my_strilen(c, '*')] != 0), n - my_strilen(c, '*')
        - ((c)[my_strilen(c, '*')] != 0)));
}


decompiled_code:
void __fastcall seek_seek(_QWORD *a1, _QWORD *a2, __int64 a3)
{
_QWORD *v4; // rbx
__int64 v5; // rax

if ( a1 )
{
v4 = a1;
while ( 1 )
{
if ( a3 )
{
if ( *v4 )
{
v5 = my_strlen(a3);
if ( !(unsigned int)my_strncmp(a3, *v4, v5) )
break;
}
}
v4 = (_QWORD *)v4[2];
if ( !v4 )
return;
}
*a2 = my_strdup(*v4);
}
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1, _QWORD *a2, __int64 a3)
{
_QWORD *v4; // rbx
__int64 v5; // rax

if ( a1 )
{
v4 = a1;
while ( 1 )
{
if ( a3 )
{
if ( *v4 )
{
v5 = my_strlen(a3);
if ( !(unsigned int)my_strncmp(a3, *v4, v5) )
break;
}
}
v4 = (_QWORD *)v4[2];
if ( !v4 )
return;
}
*a2 = my_strdup(*v4);
}
}

original_code:
static void seek_seek(t_history *hist, char **fill, char *seek)
{
  if (!hist)
    return ;
  if ((((seek) && (hist->str)) ? (!my_strncmp((seek), (hist->str), my_strlen(seek))) : (0)))
    {
      *fill = my_strdup(hist->str);
      return ;
    }
  seek_seek(hist->next, fill, seek);
}

canonical_original_code:
static void seek_seek(struct s_history *hist, char **fill, char *seek)
{
  if (!hist)
    return ;
  if ((((seek) && (hist->str)) ? (!my_strncmp((seek), (hist->str), my_strlen(seek))) : (0)))
    {
      *fill = my_strdup(hist->str);
      return ;
    }
  seek_seek(hist->next, fill, seek);
}

variable_types: struct s_history { char *str; struct s_history *prev; struct s_history *next; } *

variable_types:
fill
char **

variable_types:
seek
char *


decompiled_code:
__int64 __fastcall seek_for(_QWORD *a1, _QWORD *a2, int a3, int a4)
{
unsigned int v5; // er12

if ( !a1 )
return 0LL;
if ( a3 >= 0 || a3 + a4 )
{
v5 = seek_for(a1[2], a2, (unsigned int)a3, (unsigned int)(a4 + 1)) + 1;
if ( a3 == v5 && !*a2 )
*a2 = my_strdup(*a1);
}
else
{
v5 = 0;
*a2 = my_strdup(*a1);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, _QWORD *a2, int a3, int a4)
{
unsigned int v5; // er12

if ( !a1 )
return 0LL;
if ( a3 >= 0 || a3 + a4 )
{
v5 = func1(a1[2], a2, (unsigned int)a3, (unsigned int)(a4 + 1)) + 1;
if ( a3 == v5 && !*a2 )
*a2 = my_strdup(*a1);
}
else
{
v5 = 0;
*a2 = my_strdup(*a1);
}
return v5;
}

original_code:
static int seek_for(t_history *hist, char **fill, int sn, int n)
{
  int nr;
  if (!hist)
    return (0);
  if (sn < 0 && -sn == n)
    *fill = my_strdup(hist->str);
  if (sn < 0 && -sn == n)
    return (0);
  nr = seek_for(hist->next, fill, sn, n + 1) + 1;
  if (nr == sn && !*fill)
    *fill = my_strdup(hist->str);
  return (nr);
}

canonical_original_code:
static int seek_for(struct s_history *hist, char **fill, int sn, int n)
{
  int nr;
  if (!hist)
    return (0);
  if (sn < 0 && -sn == n)
    *fill = my_strdup(hist->str);
  if (sn < 0 && -sn == n)
    return (0);
  nr = seek_for(hist->next, fill, sn, n + 1) + 1;
  if (nr == sn && !*fill)
    *fill = my_strdup(hist->str);
  return (nr);
}

variable_types: sn int

variable_types: n int

variable_types: nr int

user_defined_types: struct s_history { char *str; struct s_history *prev; struct s_history *next; }


decompiled_code:
__int64 __fastcall mod_var(_BYTE *a1, __int64 a2, void **a3, __int64 a4)
{
void *v6; // r12
__int64 v7; // rax
void *v8; // r13
__int64 v9; // rax
void *v10; // rbp
__int64 v11; // rax
__int64 v13; // rax

v6 = (void *)my_strndup(*a3, a1 - (_BYTE *)*a3);
if ( !v6 && *a3 != a1 )
return 0LL;
v7 = my_strlen(a4);
v8 = (void *)my_strdup(&a1[v7 + 1]);
if ( !v8 )
{
v13 = my_strlen(a4);
if ( my_strlen(&a1[v13 + 1]) )
return 0LL;
}
free(*a3);
v9 = my_strcat(v6, a2);
*a3 = (void *)v9;
if ( !v9 && my_strlen(0LL) && my_strlen(a2) )
return 0LL;
free(v6);
v10 = *a3;
v11 = my_strcat(*a3, v8);
*a3 = (void *)v11;
if ( !v11 && my_strlen(0LL) && my_strlen(v8) )
return 0LL;
free(v10);
free(v8);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1, __int64 a2, void **a3, __int64 a4)
{
void *v6; // r12
__int64 v7; // rax
void *v8; // r13
__int64 v9; // rax
void *v10; // rbp
__int64 v11; // rax
__int64 v13; // rax

v6 = (void *)my_strndup(*a3, a1 - (_BYTE *)*a3);
if ( !v6 && *a3 != a1 )
return 0LL;
v7 = my_strlen(a4);
v8 = (void *)my_strdup(&a1[v7 + 1]);
if ( !v8 )
{
v13 = my_strlen(a4);
if ( my_strlen(&a1[v13 + 1]) )
return 0LL;
}
free(*a3);
v9 = my_strcat(v6, a2);
*a3 = (void *)v9;
if ( !v9 && my_strlen(0LL) && my_strlen(a2) )
return 0LL;
free(v6);
v10 = *a3;
v11 = my_strcat(*a3, v8);
*a3 = (void *)v11;
if ( !v11 && my_strlen(0LL) && my_strlen(v8) )
return 0LL;
free(v10);
free(v8);
return 1LL;
}

original_code:
static unsigned char mod_var(char *s, char *fill, char **mod, char *seek)
{
  char *modif[2];
  if ((modif[0] = my_strndup(*mod, s - *mod)) == ((void *)0) && (s != *mod))
    return (0);
  if ((modif[1] = my_strdup(s + my_strlen(seek) + 1)) == ((void *)0) &&
      my_strlen(s + my_strlen(seek) + 1))
    return (0);
  free(*mod);
  if ((*mod = my_strcat(modif[0], fill)) == ((void *)0) && my_strlen(*mod) &&
      my_strlen(fill))
    return (0);
  free(modif[0]);
  s = *mod;
  if ((*mod = my_strcat(*mod, modif[1])) == ((void *)0) && my_strlen(*mod) &&
      my_strlen(modif[1]))
    return (0);
  free(s);
  free(modif[1]);
  return (1);
}

variable_types:
fill
char *

variable_types:
mod
char **

variable_types:
modif
char *[2]


canonical_original_code:
unsigned char grow_hist(char *s, char **mod, unsigned long n, struct s_info *info)
{
  char *seek;
  char *fill;
  n += my_sstrlen(s, "!");
  s += my_sstrlen(s, "!");
  if (!s[0])
    return (1);
  if (((("/!\\ \t(;|&")[my_strilen("/!\\ \t(;|&", s[1])] != 0) || !s[1]) || (n && s[-1] == '\\'))
    return (grow_hist(s + 1 + my_sstrlen(s + 1, "$~"), mod, n +
       1 + my_sstrlen(s + 1, "$~"), info));
  seek = ((void *)0);
  if (s[0] == '!' && !(("-+0123456789")[my_strilen("-+0123456789", s[1])] != 0))
    seek = my_strndup(s + 1, my_sstrlen(s + 1, " \"\t(;|&"));
  else
    seek = my_strndup(s + 1, (("+-")[my_strilen("+-", s[1])] != 0)
        + lenmatch(s + 1 + (("+-")[my_strilen("+-", s[1])] != 0), "0123456789"));
  if ((fill = fill_it(seek, info, mod)) == ((void *)0))
    return (0);
  if (mod_var(s, fill, mod, seek) == 0)
    return (0);
  s = *mod + n + my_strlen(fill);
  n += my_strlen(fill);
  free(fill);
  free(seek);
  return (1 + grow_hist(s, mod, n, info));
}

variable_types:
s
char *

variable_types: struct s_info { struct s_history { char *str; struct s_history *prev; struct s_history *next; } *hist; struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; } termcaps; unsigned char term_caps; int *wr; int st; int value; unsigned int son; struct s_alias { char *name; char *fill; struct s_alias *next; struct s_alias *prev; unsigned long w; unsigned long n; } *alias; } *

user_defined_types: struct s_info { struct s_history *hist; struct s_options termcaps; unsigned char term_caps; int *wr; int st; int value; unsigned int son; struct s_alias *alias; }


decompiled_code:
unsigned __int64 __fastcall plus_seq(char *a1, int a2, unsigned __int64 a3, __int64 a4, __int64 a5, unsigned __int64 a6)
{
unsigned __int64 v8; // r12
int v9; // edi
unsigned __int64 v10; // rax
int v11; // eax
unsigned __int8 v12; // si
char i; // al

if ( a2 != 8 )
{
if ( a2 != 16 )
return 0LL;
v8 = 1LL;
v9 = 0;
while ( 1 )
{
v11 = (unsigned __int8)a1[v8 - 1];
a6 = v8 - 1;
a5 = (unsigned int)(v11 - 97);
v12 = v11 - 48;
if ( (unsigned __int8)(v11 - 97) > 5u && v12 > 9u )
break;
a5 = (unsigned int)(16 * v9);
if ( v12 > 9u )
{
if ( (unsigned __int8)(v11 - 65) > 5u )
{
v9 = v11 + a5 - 87;
LABEL_7:
v10 = v8 + 1;
if ( a3 <= v8 )
goto LABEL_13;
goto LABEL_8;
}
LABEL_6:
v9 = v11 + 16 * v9 - 55;
goto LABEL_7;
}
v9 = v11 + a5 - 48;
v10 = v8 + 1;
if ( a3 <= v8 )
goto LABEL_13;
LABEL_8:
v8 = v10;
}
if ( (unsigned __int8)(v11 - 65) > 5u )
{
--v8;
if ( a6 )
goto LABEL_13;
return v8;
}
goto LABEL_6;
}
v8 = 0LL;
LOBYTE(v9) = 0;
for ( i = *a1; (unsigned __int8)(i - 48) <= 7u; i = a1[v8] )
{
++v8;
LOBYTE(v9) = i + 8 * v9 - 48;
if ( a3 == v8 )
goto LABEL_13;
}
if ( !v8 )
return v8;
LABEL_13:
my_putchar((unsigned int)(char)v9, 1LL, a3, a1, a5, a6);
return v8;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(char *a1, int a2, unsigned __int64 a3, __int64 a4, __int64 a5, unsigned __int64 a6)
{
unsigned __int64 v8; // r12
int v9; // edi
unsigned __int64 v10; // rax
int v11; // eax
unsigned __int8 v12; // si
char i; // al

if ( a2 != 8 )
{
if ( a2 != 16 )
return 0LL;
v8 = 1LL;
v9 = 0;
while ( 1 )
{
v11 = (unsigned __int8)a1[v8 - 1];
a6 = v8 - 1;
a5 = (unsigned int)(v11 - 97);
v12 = v11 - 48;
if ( (unsigned __int8)(v11 - 97) > 5u && v12 > 9u )
break;
a5 = (unsigned int)(16 * v9);
if ( v12 > 9u )
{
if ( (unsigned __int8)(v11 - 65) > 5u )
{
v9 = v11 + a5 - 87;
LABEL_7:
v10 = v8 + 1;
if ( a3 <= v8 )
goto LABEL_13;
goto LABEL_8;
}
LABEL_6:
v9 = v11 + 16 * v9 - 55;
goto LABEL_7;
}
v9 = v11 + a5 - 48;
v10 = v8 + 1;
if ( a3 <= v8 )
goto LABEL_13;
LABEL_8:
v8 = v10;
}
if ( (unsigned __int8)(v11 - 65) > 5u )
{
--v8;
if ( a6 )
goto LABEL_13;
return v8;
}
goto LABEL_6;
}
v8 = 0LL;
LOBYTE(v9) = 0;
for ( i = *a1; (unsigned __int8)(i - 48) <= 7u; i = a1[v8] )
{
++v8;
LOBYTE(v9) = i + 8 * v9 - 48;
if ( a3 == v8 )
goto LABEL_13;
}
if ( !v8 )
return v8;
LABEL_13:
my_putchar((unsigned int)(char)v9, 1LL, a3, a1, a5, a6);
return v8;
}

original_code:
static size_t plus_seq(char *seq, int mult, size_t l)
{
  unsigned char n;
  size_t i;
  n = 0;
  i = 0;
  if (mult == 8)
    while (i < l && (seq[i] >= '0' && seq[i] < '8'))
      n = n * mult + seq[i++] - '0';
  if (mult == 16)
    while (i < l && ((seq[i] >= '0' && seq[i] <= '9') ||
       (seq[i] >= 'a' && seq[i] <= 'f') ||
       (seq[i] >= 'A' && seq[i] <= 'F')))
      if (seq[i] >= '0' && seq[i] <= '9')
 n = n * mult + seq[i++] - '0';
      else if (seq[i] >= 'A' && seq[i] <= 'F')
 n = n * mult + seq[i++] - 'A' + 10;
      else
 n = n * mult + seq[i++] - 'a' + 10;
  if (i)
    my_putchar((unsigned char)n, 1);
  return (i);
}

canonical_original_code:
static unsigned long plus_seq(char *seq, int mult, unsigned long l)
{
  unsigned char n;
  unsigned long i;
  n = 0;
  i = 0;
  if (mult == 8)
    while (i < l && (seq[i] >= '0' && seq[i] < '8'))
      n = n * mult + seq[i++] - '0';
  if (mult == 16)
    while (i < l && ((seq[i] >= '0' && seq[i] <= '9') ||
       (seq[i] >= 'a' && seq[i] <= 'f') ||
       (seq[i] >= 'A' && seq[i] <= 'F')))
      if (seq[i] >= '0' && seq[i] <= '9')
 n = n * mult + seq[i++] - '0';
      else if (seq[i] >= 'A' && seq[i] <= 'F')
 n = n * mult + seq[i++] - 'A' + 10;
      else
 n = n * mult + seq[i++] - 'a' + 10;
  if (i)
    my_putchar((unsigned char)n, 1);
  return (i);
}

variable_types:
seq
char *

variable_types: mult int

variable_types:
n
unsigned char


decompiled_code:
__int64 __fastcall print_seq2(char *a1, char a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // r9
int v11; // ebp
__int64 v12; // rax
__int64 v13; // rdx
__int64 v14; // rcx
__int64 v15; // r8
__int64 v16; // r9
__int64 v17; // rax
__int64 v18; // rdx
__int64 v19; // rcx
__int64 v20; // r8
__int64 v21; // r9
__int64 v22; // rax
__int64 result; // rax
__int64 v24; // rax

if ( !a1 )
return my_putchar((unsigned int)*a1, 1LL, a3, a4, a5, a6);
v6 = my_strlen(&unk_4AA);
if ( !(unsigned int)my_strncmp(&unk_4AA, a1, v6) )
return my_putchar(10LL, 1LL, v7, v8, v9, v10) + 1;
v11 = a2 & 4;
v12 = my_strlen(&unk_4B3);
if ( !(v11 | (unsigned int)my_strncmp(&unk_4B3, a1, v12)) )
return my_putchar(13LL, 1LL, v13, v14, v15, v16) + 1;
v17 = my_strlen(&unk_4B0);
if ( (unsigned int)my_strncmp(&unk_4B0, a1, v17) )
{
v24 = my_strlen(&unk_4AD);
if ( v11 | (unsigned int)my_strncmp(&unk_4AD, a1, v24) )
return my_putchar((unsigned int)*a1, 1LL, a3, a4, a5, a6);
result = my_putchar(11LL, 1LL, a3, a4, a5, a6) + 1;
}
else
{
if ( (a2 & 4) != 0 )
{
v22 = my_strlen(&unk_4AD);
my_strncmp(&unk_4AD, a1, v22);
return my_putchar((unsigned int)*a1, 1LL, a3, a4, a5, a6);
}
result = my_putchar(9LL, 1LL, v18, v19, v20, v21) + 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, char a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // r9
int v11; // ebp
__int64 v12; // rax
__int64 v13; // rdx
__int64 v14; // rcx
__int64 v15; // r8
__int64 v16; // r9
__int64 v17; // rax
__int64 v18; // rdx
__int64 v19; // rcx
__int64 v20; // r8
__int64 v21; // r9
__int64 v22; // rax
__int64 result; // rax
__int64 v24; // rax

if ( !a1 )
return my_putchar((unsigned int)*a1, 1LL, a3, a4, a5, a6);
v6 = my_strlen(&unk_4AA);
if ( !(unsigned int)my_strncmp(&unk_4AA, a1, v6) )
return my_putchar(10LL, 1LL, v7, v8, v9, v10) + 1;
v11 = a2 & 4;
v12 = my_strlen(&unk_4B3);
if ( !(v11 | (unsigned int)my_strncmp(&unk_4B3, a1, v12)) )
return my_putchar(13LL, 1LL, v13, v14, v15, v16) + 1;
v17 = my_strlen(&unk_4B0);
if ( (unsigned int)my_strncmp(&unk_4B0, a1, v17) )
{
v24 = my_strlen(&unk_4AD);
if ( v11 | (unsigned int)my_strncmp(&unk_4AD, a1, v24) )
return my_putchar((unsigned int)*a1, 1LL, a3, a4, a5, a6);
result = my_putchar(11LL, 1LL, a3, a4, a5, a6) + 1;
}
else
{
if ( (a2 & 4) != 0 )
{
v22 = my_strlen(&unk_4AD);
my_strncmp(&unk_4AD, a1, v22);
return my_putchar((unsigned int)*a1, 1LL, a3, a4, a5, a6);
}
result = my_putchar(9LL, 1LL, v18, v19, v20, v21) + 1;
}
return result;
}

canonical_original_code:
static unsigned long print_seq2(char *seq, unsigned int echo)
{
  if (((("\\n") && (seq)) ? (!my_strncmp(("\\n"), (seq), my_strlen("\\n"))) : (0)))
    return (1 + my_putchar('\n', 1));
  else if (((("\\r") && (seq)) ? (!my_strncmp(("\\r"), (seq), my_strlen("\\r"))) : (0)) && !(echo & 4))
    return (1 + my_putchar('\r', 1));
  else if (((("\\t") && (seq)) ? (!my_strncmp(("\\t"), (seq), my_strlen("\\t"))) : (0)) && !(echo & 4))
    return (1 + my_putchar('\t', 1));
  else if (((("\\v") && (seq)) ? (!my_strncmp(("\\v"), (seq), my_strlen("\\v"))) : (0)) && !(echo & 4))
    return (1 + my_putchar('\v', 1));
  return (my_putchar(*seq, 1));
}

variable_types:
echo
unsigned int


decompiled_code:
__int64 __fastcall print_seq(char *a1, char a2, _BYTE *a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v7; // rax
__int64 v8; // rcx
__int64 v9; // r8
unsigned __int64 v10; // r9
__int64 v11; // rax
__int64 v12; // rcx
__int64 v13; // r8
unsigned __int64 v14; // r9
__int64 v15; // rax
__int64 v16; // rdx
__int64 v17; // rcx
__int64 v18; // r8
__int64 v19; // r9
__int64 v20; // rax
int v21; // er13
__int64 v22; // rdx
__int64 v23; // rcx
__int64 v24; // r8
__int64 v25; // r9
__int64 v26; // rax
__int64 v27; // rdx
__int64 v28; // rcx
__int64 v29; // r8
__int64 v30; // r9
__int64 v31; // rax
__int64 v32; // rax
__int64 v33; // rdx
__int64 v34; // rcx
__int64 v35; // r8
__int64 v36; // r9
__int64 v37; // rax
__int64 result; // rax
__int64 v39; // rax

if ( (a2 & 2) == 0 )
return my_putchar((unsigned int)*a1, 1LL, a3, a4, a5, a6);
if ( !a1 )
return print_seq2(a1, a2, (__int64)a3, a4, a5, a6);
v7 = my_strlen(&unk_4B6);
if ( !(unsigned int)my_strncmp(&unk_4B6, a1, v7) )
return plus_seq(a1 + 2, 8, 3uLL, v8, v9, v10) + 2;
v11 = my_strlen(&unk_4CB);
if ( !(unsigned int)my_strncmp(&unk_4CB, a1, v11) )
return plus_seq(a1 + 2, 16, 2uLL, v12, v13, v14) + 2;
v15 = my_strlen(&unk_4C8);
if ( !(unsigned int)my_strncmp(&unk_4C8, a1, v15) )
return my_putchar(92LL, 1LL, v16, v17, v18, v19) + 1;
v20 = my_strlen(&unk_4C5);
v21 = a2 & 4;
if ( !(v21 | (unsigned int)my_strncmp(&unk_4C5, a1, v20)) )
return my_putchar(7LL, 1LL, v22, v23, v24, v25) + 1;
v26 = my_strlen(&unk_4C2);
if ( !(v21 | (unsigned int)my_strncmp(&unk_4C2, a1, v26)) )
return my_putchar(8LL, 1LL, v27, v28, v29, v30) + 1;
v31 = my_strlen(&unk_4BF);
if ( v21 | (unsigned int)my_strncmp(&unk_4BF, a1, v31) )
{
v32 = my_strlen(&unk_4BC);
if ( (unsigned int)my_strncmp(&unk_4BC, a1, v32) )
{
v39 = my_strlen(&unk_4B9);
if ( v21 | (unsigned int)my_strncmp(&unk_4B9, a1, v39) )
return print_seq2(a1, a2, (__int64)a3, a4, a5, a6);
result = my_putchar(12LL, 1LL, a3, a4, a5, a6) + 1;
}
else
{
if ( (a2 & 4) != 0 )
{
v37 = my_strlen(&unk_4B9);
my_strncmp(&unk_4B9, a1, v37);
return print_seq2(a1, a2, (__int64)a3, a4, a5, a6);
}
result = my_putchar(27LL, 1LL, v33, v34, v35, v36) + 1;
}
}
else
{
*a3 = 1;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, char a2, _BYTE *a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v7; // rax
__int64 v8; // rcx
__int64 v9; // r8
unsigned __int64 v10; // r9
__int64 v11; // rax
__int64 v12; // rcx
__int64 v13; // r8
unsigned __int64 v14; // r9
__int64 v15; // rax
__int64 v16; // rdx
__int64 v17; // rcx
__int64 v18; // r8
__int64 v19; // r9
__int64 v20; // rax
int v21; // er13
__int64 v22; // rdx
__int64 v23; // rcx
__int64 v24; // r8
__int64 v25; // r9
__int64 v26; // rax
__int64 v27; // rdx
__int64 v28; // rcx
__int64 v29; // r8
__int64 v30; // r9
__int64 v31; // rax
__int64 v32; // rax
__int64 v33; // rdx
__int64 v34; // rcx
__int64 v35; // r8
__int64 v36; // r9
__int64 v37; // rax
__int64 result; // rax
__int64 v39; // rax

if ( (a2 & 2) == 0 )
return my_putchar((unsigned int)*a1, 1LL, a3, a4, a5, a6);
if ( !a1 )
return func1(a1, a2, (__int64)a3, a4, a5, a6);
v7 = my_strlen(&unk_4B6);
if ( !(unsigned int)my_strncmp(&unk_4B6, a1, v7) )
return func0(a1 + 2, 8, 3uLL, v8, v9, v10) + 2;
v11 = my_strlen(&unk_4CB);
if ( !(unsigned int)my_strncmp(&unk_4CB, a1, v11) )
return func0(a1 + 2, 16, 2uLL, v12, v13, v14) + 2;
v15 = my_strlen(&unk_4C8);
if ( !(unsigned int)my_strncmp(&unk_4C8, a1, v15) )
return my_putchar(92LL, 1LL, v16, v17, v18, v19) + 1;
v20 = my_strlen(&unk_4C5);
v21 = a2 & 4;
if ( !(v21 | (unsigned int)my_strncmp(&unk_4C5, a1, v20)) )
return my_putchar(7LL, 1LL, v22, v23, v24, v25) + 1;
v26 = my_strlen(&unk_4C2);
if ( !(v21 | (unsigned int)my_strncmp(&unk_4C2, a1, v26)) )
return my_putchar(8LL, 1LL, v27, v28, v29, v30) + 1;
v31 = my_strlen(&unk_4BF);
if ( v21 | (unsigned int)my_strncmp(&unk_4BF, a1, v31) )
{
v32 = my_strlen(&unk_4BC);
if ( (unsigned int)my_strncmp(&unk_4BC, a1, v32) )
{
v39 = my_strlen(&unk_4B9);
if ( v21 | (unsigned int)my_strncmp(&unk_4B9, a1, v39) )
return func1(a1, a2, (__int64)a3, a4, a5, a6);
result = my_putchar(12LL, 1LL, a3, a4, a5, a6) + 1;
}
else
{
if ( (a2 & 4) != 0 )
{
v37 = my_strlen(&unk_4B9);
my_strncmp(&unk_4B9, a1, v37);
return func1(a1, a2, (__int64)a3, a4, a5, a6);
}
result = my_putchar(27LL, 1LL, v33, v34, v35, v36) + 1;
}
}
else
{
*a3 = 1;
result = 1LL;
}
return result;
}

variable_types:
end
unsigned char *


decompiled_code:
__int64 __fastcall free_str_edit_lines(void *a1, void *a2)
{
void *v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a1;
if ( a1 )
free(a1);
if ( a2 )
free(a2);
v3 = 0LL;
remind_save_str(1LL, &v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1, void *a2)
{
void *v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a1;
if ( a1 )
free(a1);
if ( a2 )
free(a2);
v3 = 0LL;
remind_save_str(1LL, &v3);
return 0LL;
}

original_code:
char *free_str_edit_lines(char *s1, char *s2)
{
  if (s1 != ((void *)0))
    free(s1);
  if (s2 != ((void *)0))
    free(s2);
  s1 = ((void *)0);
  remind_save_str(1, &s1);
  return (((void *)0));
}


decompiled_code:
__int64 __fastcall finish_usr_cmd(__int64 a1, void *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
my_putstr(&unk_8D, 1LL);
unset_termios(&a7);
free_str_edit_lines(a2, 0LL);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, void *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
my_putstr(&unk_8D, 1LL);
unset_termios(&a7);
func0(a2, 0LL);
return a1;
}

original_code:
char *finish_usr_cmd(char *cmd, char *str, struct termios unset)
{
  my_putstr("\n", 1);
  unset_termios(&unset);
  free_str_edit_lines(str, ((void *)0));
  return (cmd);
}

variable_types:
cmd
char *

variable_types:
str
char *

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


decompiled_code:
__int64 __fastcall swap_chars_on_cmd(__int64 a1, _DWORD *a2, _QWORD *a3)
{
int v5; // ecx
__int64 result; // rax
int v7; // esi
char *v8; // rdx
char v9; // r8

v5 = my_strlen(*a3);
result = (unsigned int)*a2;
if ( (int)result > 0 )
{
v7 = result == v5;
v8 = (char *)(*a3 + (int)result + ~v7);
v9 = *v8;
*v8 = *(_BYTE *)(*a3 + (int)result - v7);
*(_BYTE *)(*a3 + *a2 - v7) = v9;
result = (unsigned int)*a2;
if ( (_DWORD)result != v5 )
{
result = (unsigned int)(result + 1);
*a2 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _DWORD *a2, _QWORD *a3)
{
int v5; // ecx
__int64 result; // rax
int v7; // esi
char *v8; // rdx
char v9; // r8

v5 = my_strlen(*a3);
result = (unsigned int)*a2;
if ( (int)result > 0 )
{
v7 = result == v5;
v8 = (char *)(*a3 + (int)result + ~v7);
v9 = *v8;
*v8 = *(_BYTE *)(*a3 + (int)result - v7);
*(_BYTE *)(*a3 + *a2 - v7) = v9;
result = (unsigned int)*a2;
if ( (_DWORD)result != v5 )
{
result = (unsigned int)(result + 1);
*a2 = result;
}
}
return result;
}

original_code:
void swap_chars_on_cmd(char value, int *reverse_case, char **cmd)
{
  char reserve;
  int len;
  int i;
  (void)value;
  i = 0;
  len = my_strlen(*cmd);
  if (*reverse_case == len)
    i--;
  if (*reverse_case > 0)
    {
      reserve = (*cmd)[(*reverse_case) + (i - 1)];
      (*cmd)[(*reverse_case) + (i - 1)] = (*cmd)[(*reverse_case) + i];
      (*cmd)[(*reverse_case) + i] = reserve;
      if (*reverse_case != len)
 (*reverse_case)++;
    }
}

variable_types: value char

variable_types:
cmd
char **

variable_types: reserve char

variable_types: len int

variable_types: i int


xfork

decompiled_code:
__int64 xfork()
{
unsigned int v0; // er12

v0 = fork();
if ( v0 == -1 )
my_putpath("fork(): fail\n", "/dev/tty");
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er12

v0 = fork();
if ( v0 == -1 )
my_putpath("fork(): fail\n", "/dev/tty");
return v0;
}

original_code:
pid_t xfork(void)
{
  pid_t pid;
  if ((pid = fork()) == -1)
    my_putpath("fork(): fail\n", "/dev/tty");
  return (pid);
}

canonical_original_code:
int xfork()
{
  int pid;
  if ((pid = fork()) == -1)
    my_putpath("fork(): fail\n", "/dev/tty");
  return (pid);
}

variable_types: pid int


decompiled_code:
_BOOL8 __fastcall test_nl(_BYTE *a1)
{
return *a1 == 10;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_BYTE *a1)
{
return *a1 == 10;
}

original_code:
int test_nl(char *str)
{
  int i;
  i = 0;
  while (i < 1)
    if (str[i++] == '\n')
      return (1);
  return (0);
}


inc

decompiled_code:
__int64 __fastcall inc(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax

result = *(unsigned __int8 *)(a2 + a3);
*(_BYTE *)(a1 + a3) = result;
return result;
}

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

result = *(unsigned __int8 *)(a2 + a3);
*(_BYTE *)(a1 + a3) = result;
return result;
}

original_code:
void inc(char *str1, char *str2, int i)
{
  str1[i] = str2[i];
}


decompiled_code:
__int64 __fastcall get_next_line(int fd)
{
int v1; // ebp
int v2; // eax
int v3; // eax
bool v4; // cc
__int64 result; // rax
int v6; // [rsp+4h] [rbp-24h] BYREF
__int64 v7; // [rsp+8h] [rbp-20h] BYREF

v1 = 1;
v6 = 0;
v7 = 0LL;
while ( (!test_nl(&memory_0) || !v6) && v1 == 1 )
{
if ( memory_0 )
{
v2 = v6;
}
else
{
v3 = read(fd, &memory_0, 1uLL);
v4 = v3 <= 0;
v1 = v3;
v2 = v6;
if ( v4 && !v6 )
return 0LL;
}
v6 = v2 + 1;
memorize(&v6, (void **)&v7, (unsigned __int8 *)&memory_0);
if ( !v7 )
return 0LL;
}
result = v7;
memory_0 = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd)
{
int v1; // ebp
int v2; // eax
int v3; // eax
bool v4; // cc
__int64 result; // rax
int v6; // [rsp+4h] [rbp-24h] BYREF
__int64 v7; // [rsp+8h] [rbp-20h] BYREF

v1 = 1;
v6 = 0;
v7 = 0LL;
while ( (!func0(&memory_0) || !v6) && v1 == 1 )
{
if ( memory_0 )
{
v2 = v6;
}
else
{
v3 = read(fd, &memory_0, 1uLL);
v4 = v3 <= 0;
v1 = v3;
v2 = v6;
if ( v4 && !v6 )
return 0LL;
}
v6 = v2 + 1;
func3(&v6, (void **)&v7, (unsigned __int8 *)&memory_0);
if ( !v7 )
return 0LL;
}
result = v7;
memory_0 = 0;
return result;
}

original_code:
char *get_next_line(const int fd)
{
  char *buffer;
  static char memory[1 + 1];
  int w;
  int lr;
  w = 0;
  lr = 1;
  buffer = ((void *)0);
  while ((!test_nl(memory) || !w) && lr == 1)
    {
      if (!memory[0])
 if ((lr = read(fd, memory, 1)) <= 0 && w == 0)
   return (((void *)0));
      w = w + 1;
      memorize(&w, &buffer, memory);
      if (buffer == ((void *)0))
 return (((void *)0));
    }
  w = 0;
  lr = 1;
  while (w + 1 < 1 && memory[w])
    memory[w++] = memory[lr++];
  memory[w] = '\0';
  return (buffer);
}

canonical_original_code:
char *get_next_line(int fd)
{
  char *buffer;
  static char memory[-1];
  int w;
  int lr;
  w = 0;
  lr = 1;
  buffer = ((void *)0);
  while ((!test_nl(memory) || !w) && lr == 1)
    {
      if (!memory[0])
 if ((lr = read(fd, memory, 1)) <= 0 && w == 0)
   return (((void *)0));
      w = w + 1;
      memorize(&w, &buffer, memory);
      if (buffer == ((void *)0))
 return (((void *)0));
    }
  w = 0;
  lr = 1;
  while (w + 1 < 1 && memory[w])
    memory[w++] = memory[lr++];
  memory[w] = '\0';
  return (buffer);
}

variable_types: fd int

variable_types:
buffer
char *

variable_types:
memory
char [-1]

variable_types: w int

variable_types: lr int


empty

decompiled_code:
bool __fastcall empty(char *a1)
{
char v1; // al
char *v2; // rdi

if ( !a1 )
return 0;
v1 = *a1;
if ( *a1 == 32 || v1 == 9 )
{
v2 = a1 + 1;
do
{
do
v1 = *v2++;
while ( v1 == 32 );
}
while ( v1 == 9 );
}
return v1 == 0;
}

original_code:
unsigned char empty(const char *s)
{
  size_t i;
  if (!s)
    return (0);
  i = 0;
  while (s[i] == ' ' || s[i] == 9)
    i++;
  return (s[i] == '\0');
}

canonical_original_code:
unsigned char empty(char *s)
{
  unsigned long i;
  if (!s)
    return (0);
  i = 0;
  while (s[i] == ' ' || s[i] == 9)
    i++;
  return (s[i] == '\0');
}

variable_types:
s
char *

variable_types:
i
unsigned long


nempty

decompiled_code:
__int64 __fastcall nempty(unsigned __int8 *a1, unsigned __int64 a2)
{
int v2; // edx
unsigned __int64 v3; // rax

v2 = *a1;
v3 = 0LL;
if ( ((_BYTE)v2 == 9 || (_BYTE)v2 == 32) && a2 )
{
do
v2 = a1[++v3];
while ( ((_BYTE)v2 == 9 || (_BYTE)v2 == 32) && a2 > v3 );
}
LOBYTE(v2) = (_BYTE)v2 == 0;
LOBYTE(v3) = a2 == v3;
return v2 | (unsigned int)v3;
}

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

v2 = *a1;
v3 = 0LL;
if ( ((_BYTE)v2 == 9 || (_BYTE)v2 == 32) && a2 )
{
do
v2 = a1[++v3];
while ( ((_BYTE)v2 == 9 || (_BYTE)v2 == 32) && a2 > v3 );
}
LOBYTE(v2) = (_BYTE)v2 == 0;
LOBYTE(v3) = a2 == v3;
return v2 | (unsigned int)v3;
}

original_code:
unsigned char nempty(const char *s, size_t n)
{
  size_t i;
  i = 0;
  while ((s[i] == ' ' || s[i] == 9) && i < n)
    i++;
  return (s[i] == '\0' || i == n);
}

canonical_original_code:
unsigned char nempty(char *s, unsigned long n)
{
  unsigned long i;
  i = 0;
  while ((s[i] == ' ' || s[i] == 9) && i < n)
    i++;
  return (s[i] == '\0' || i == n);
}

variable_types:
n
unsigned long


hempty

decompiled_code:
__int64 __fastcall hempty(_BYTE *a1)
{
__int64 result; // rax
char v2; // dl

if ( *a1 != 32 && *a1 != 9 )
return 0LL;
result = 0LL;
do
{
do
v2 = a1[++result];
while ( v2 == 32 );
}
while ( v2 == 9 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
__int64 result; // rax
char v2; // dl

if ( *a1 != 32 && *a1 != 9 )
return 0LL;
result = 0LL;
do
{
do
v2 = a1[++result];
while ( v2 == 32 );
}
while ( v2 == 9 );
return result;
}

original_code:
size_t hempty(const char *s)
{
  size_t i;
  i = 0;
  while (s[i] == ' ' || s[i] == 9)
    i++;
  return (i);
}

canonical_original_code:
unsigned long hempty(char *s)
{
  unsigned long i;
  i = 0;
  while (s[i] == ' ' || s[i] == 9)
    i++;
  return (i);
}


decompiled_code:
unsigned __int64 __fastcall lastoccur_bf(char *a1, char a2, unsigned __int64 a3)
{
char v4; // dl
unsigned __int64 v5; // rax
unsigned __int64 v6; // r8

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

canonical_decompiled_code:
unsigned __int64 __fastcall func3(char *a1, char a2, unsigned __int64 a3)
{
char v4; // dl
unsigned __int64 v5; // rax
unsigned __int64 v6; // r8

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

original_code:
size_t lastoccur_bf(const char *s, char c, size_t e)
{
  size_t cseek;
  size_t i;
  i = 0;
  cseek = 0;
  while (s[i] && i < e)
    {
      if (s[i] == c)
 cseek = i;
      i++;
    }
  return (cseek);
}

canonical_original_code:
unsigned long lastoccur_bf(char *s, char c, unsigned long e)
{
  unsigned long cseek;
  unsigned long i;
  i = 0;
  cseek = 0;
  while (s[i] && i < e)
    {
      if (s[i] == c)
 cseek = i;
      i++;
    }
  return (cseek);
}

variable_types: c char

variable_types:
e
unsigned long

variable_types:
cseek
unsigned long


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

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

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

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

original_code:
static size_t size_list(t_words *list)
{
  size_t i;
  i = 0;
  while (list)
    {
      i++;
      list = list->next;
    }
  return (i);
}

canonical_original_code:
static unsigned long size_list(struct s_words *list)
{
  unsigned long i;
  i = 0;
  while (list)
    {
      i++;
      list = list->next;
    }
  return (i);
}

variable_types: struct s_words { char *word; struct s_words *next; } *


original_code:
char **to_tab(t_words *list, unsigned char *sys_fail)
{
  char **tab;
  size_t i;
  i = size_list(list);
  if ((tab = xmalloc(sizeof(*tab) * (i + 1))) == ((void *)0))
    {
      (*sys_fail) = 1;
      return (((void *)0));
    }
  i = 0;
  while (list)
    {
      tab[i] = list->word;
      list = list->next;
      i++;
    }
  tab[i] = ((void *)0);
  return (tab);
}

canonical_original_code:
char **to_tab(struct s_words *list, unsigned char *sys_fail)
{
  char **tab;
  unsigned long i;
  i = size_list(list);
  if ((tab = xmalloc(sizeof(*tab) * (i + 1))) == ((void *)0))
    {
      (*sys_fail) = 1;
      return (((void *)0));
    }
  i = 0;
  while (list)
    {
      tab[i] = list->word;
      list = list->next;
      i++;
    }
  tab[i] = ((void *)0);
  return (tab);
}

variable_types:
tab
char **

return_type: char **


cond

decompiled_code:
bool __fastcall cond(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 v5; // rax

v2 = a1 + 19;
v3 = my_strilen(a2, 47LL);
if ( !(unsigned __int8)nmatch(a1 + 19, a2, v3) )
return 0;
if ( (unsigned int)my_strcmp(v2, ".") && (unsigned int)my_strcmp(v2, "..") || !*(_BYTE *)(a2 + my_strilen(a2, 47LL)) )
return 1;
if ( !a2 )
return 0;
v5 = my_strlen("..");
return (unsigned int)my_strncmp("..", a2, v5) == 0;
}

canonical_decompiled_code:
bool __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 v5; // rax

v2 = a1 + 19;
v3 = my_strilen(a2, 47LL);
if ( !(unsigned __int8)nmatch(a1 + 19, a2, v3) )
return 0;
if ( (unsigned int)my_strcmp(v2, ".") && (unsigned int)my_strcmp(v2, "..") || !*(_BYTE *)(a2 + my_strilen(a2, 47LL)) )
return 1;
if ( !a2 )
return 0;
v5 = my_strlen("..");
return (unsigned int)my_strncmp("..", a2, v5) == 0;
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *

variable_types:
m
char *


decompiled_code:
bool __fastcall is_dir(const char *a1)
{
int v1; // er8
bool result; // al
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0;
if ( v1 != -1 )
result = (v3.st_mode & 0xF000) == 0x4000;
return result;
}

canonical_decompiled_code:
bool __fastcall func1(const char *a1)
{
int v1; // er8
bool result; // al
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0;
if ( v1 != -1 )
result = (v3.st_mode & 0xF000) == 0x4000;
return result;
}

original_code:
static unsigned char is_dir(char *dp)
{
  struct stat st;
  if (stat(dp, &st) == -1)
    return (0);
  if ((st.st_mode & 0170000) == 0040000)
    return (1);
  return (0);
}

variable_types:
dp
char *

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

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


decompiled_code:
__int64 __fastcall cond2(__int64 a1, char *a2)
{
if ( *(_BYTE *)(a1 + my_strilen(a1, 47LL)) && is_dir(a2) || !*(_BYTE *)(a1 + my_strilen(a1, 47LL)) )
return 1LL;
free(a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2)
{
if ( *(_BYTE *)(a1 + my_strilen(a1, 47LL)) && func1(a2) || !*(_BYTE *)(a1 + my_strilen(a1, 47LL)) )
return 1LL;
free(a2);
return 0LL;
}

original_code:
static unsigned char cond2(char *m, char *f_dp)
{
  if ((((m)[my_strilen(m, '/')] != 0) && is_dir(f_dp)) || !((m)[my_strilen(m, '/')] != 0))
    return (1);
  free(f_dp);
  return (0);
}


decompiled_code:
__int64 print_env()
{
char *v0; // rdi
__int64 i; // rbx

if ( !environ )
return 1LL;
v0 = *environ;
for ( i = 1LL; v0; ++i )
{
my_putstr(v0, 1LL);
my_putstr(&unk_241, 1LL);
v0 = environ[i];
}
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
char *v0; // rdi
__int64 i; // rbx

if ( !environ )
return 1LL;
v0 = *environ;
for ( i = 1LL; v0; ++i )
{
my_putstr(v0, 1LL);
my_putstr(&unk_241, 1LL);
v0 = environ[i];
}
return 0LL;
}

original_code:
static int print_env()
{
  size_t i;
  if (!environ)
    return (1);
  i = 0;
  while (environ[i])
    {
      my_putstr(environ[i++], 1);
      my_putstr("\n", 1);
    }
  return (0);
}

canonical_original_code:
static int print_env()
{
  unsigned long i;
  if (!environ)
    return (1);
  i = 0;
  while (environ[i])
    {
      my_putstr(environ[i++], 1);
      my_putstr("\n", 1);
    }
  return (0);
}


decompiled_code:
__int64 __fastcall seek_fail(void *ptr)
{
if ( ptr )
{
((void (*)(void))print_err)();
print_err(&unk_241);
free(ptr);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
if ( ptr )
{
((void (*)(void))print_err)();
print_err(&unk_241);
free(ptr);
}
return 1LL;
}

original_code:
static int seek_fail(char *r)
{
  if (!r)
    return (1);
  print_err(r);
  print_err("\n");
  free(r);
  return (1);
}

variable_types:
r
char *


decompiled_code:
__int64 print_help()
{
my_putstr("Uasge: env [options]\n", 1LL);
my_putstr("env built-in loads a temporary environment, wich is setted by:\n", 1LL);
my_putstr(" -i : unset all\n", 1LL);
my_putstr(" -u {p} : unset {p}\n", 1LL);
my_putstr(" -s {v,p}: set {v} with {p}\n", 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
my_putstr("Uasge: env [options]\n", 1LL);
my_putstr("env built-in loads a temporary environment, wich is setted by:\n", 1LL);
my_putstr(" -i : unset all\n", 1LL);
my_putstr(" -u {p} : unset {p}\n", 1LL);
my_putstr(" -s {v,p}: set {v} with {p}\n", 1LL);
return 0LL;
}

original_code:
unsigned char print_help(void)
{
  my_putstr("Uasge: env [options]\n", 1);
  my_putstr("env built-in loads a temporary environment, wich is setted by:\n",
     1);
  my_putstr("    -i      : unset all\n", 1);
  my_putstr("    -u {p}  : unset {p}\n", 1);
  my_putstr("    -s {v,p}: set {v} with {p}\n", 1);
  return (0);
}

canonical_original_code:
unsigned char print_help()
{
  my_putstr("Uasge: env [options]\n", 1);
  my_putstr("env built-in loads a temporary environment, wich is setted by:\n",
     1);
  my_putstr("    -i      : unset all\n", 1);
  my_putstr("    -u {p}  : unset {p}\n", 1);
  my_putstr("    -s {v,p}: set {v} with {p}\n", 1);
  return (0);
}


decompiled_code:
void destroy_env()
{
char *v0; // rdi
__int64 v1; // rbx

if ( environ )
{
v0 = *environ;
if ( *environ )
{
v1 = 1LL;
do
{
free(v0);
v0 = environ[v1++];
}
while ( v0 );
}
free(environ);
}
}

canonical_decompiled_code:
void func3()
{
char *v0; // rdi
__int64 v1; // rbx

if ( environ )
{
v0 = *environ;
if ( *environ )
{
v1 = 1LL;
do
{
free(v0);
v0 = environ[v1++];
}
while ( v0 );
}
free(environ);
}
}

original_code:
void destroy_env(void)
{
  size_t i;
  i = 0;
  if (!environ)
    return ;
  while (environ[i])
    free(environ[i++]);
  free(environ);
}

canonical_original_code:
void destroy_env()
{
  unsigned long i;
  i = 0;
  if (!environ)
    return ;
  while (environ[i])
    free(environ[i++]);
  free(environ);
}