yyparse

decompiled_code:
__int64 yyparse()
{
int v0; // ebp
unsigned __int64 v1; // r15
char *v2; // r12
__int16 *v3; // rbx
__int16 *v4; // r14
int v5; // edx
unsigned int v6; // er13
char *v7; // rcx
int v8; // er13
unsigned __int8 v9; // bp
__int16 *v10; // r13
unsigned int v11; // ebp
int v12; // eax
unsigned int v13; // edx
unsigned __int64 v14; // rax
signed __int64 v15; // rbx
__int64 v16; // r12
__int16 *v17; // rax
__int16 *v18; // r13
size_t v19; // r12
char *v20; // r13
int v21; // er13
__int64 v22; // rax
size_t v23; // rsi
void *v24; // rax
__int64 v25; // rcx
int v26; // eax
unsigned int v27; // eax
char *v29; // [rsp+0h] [rbp-828h]
int v30; // [rsp+Ch] [rbp-81Ch]
__int64 v31; // [rsp+10h] [rbp-818h]
__int16 *v32; // [rsp+10h] [rbp-818h]
unsigned __int64 v33; // [rsp+18h] [rbp-810h]
char v34[1600]; // [rsp+20h] [rbp-808h] BYREF
__int16 src[228]; // [rsp+660h] [rbp-1C8h] BYREF

yynerrs = 0;
yychar = -2;
src[0] = 0;
v30 = 0;
v0 = 0;
v1 = 200LL;
v2 = v34;
v29 = v34;
v3 = src;
v4 = src;
while ( 1 )
{
v21 = yypact[v0];
if ( v21 == -13 )
break;
if ( yychar == -2 )
yychar = yylex();
if ( yychar <= 0 )
{
yychar = 0;
v5 = 0;
}
else
{
v5 = 2;
if ( (unsigned int)yychar <= 0x102 )
v5 = (unsigned __int8)yytranslate[yychar];
}
v6 = v5 + v21;
if ( v6 > 0x14 || yycheck[v6] != v5 )
break;
v0 = yytable[v6];
if ( v0 > 0 )
{
v30 = (v30 == 0) + v30 - 1;
yychar = -2;
v7 = v2 + 8;
*((_QWORD *)v2 + 1) = yylval;
goto LABEL_21;
}
v8 = -v0;
LABEL_9:
v9 = yyr2[v8];
v31 = *(_QWORD *)&v2[8 * (1 - v9)];
switch ( v8 )
{
case 2:
return 0;
case 3:
case 4:
return 1;
case 6:
is_bg = 0;
goto LABEL_18;
case 7:
is_bg = 1;
goto LABEL_18;
case 8:
case 9:
v22 = create_node(cmd);
insert(head, v22);
init_temp_cmd();
goto LABEL_18;
case 11:
v33 = cmd;
if ( !*(_QWORD *)(cmd + 8) )
*(_QWORD *)(v33 + 8) = malloc(8uLL);
**(_QWORD **)(v33 + 8) = *((_QWORD *)v2 - 1);
*(_QWORD *)(*(_QWORD *)(cmd + 8) + 8LL * (int)++*(_DWORD *)cmd) = 0LL;
goto LABEL_18;
case 13:
if ( !*(_QWORD *)(cmd + 16) )
*(_QWORD *)(cmd + 16) = *((_QWORD *)v2 - 1);
goto LABEL_18;
case 14:
if ( !*(_QWORD *)(cmd + 24) )
*(_QWORD *)(cmd + 24) = *((_QWORD *)v2 - 1);
goto LABEL_18;
case 16:
*(_DWORD *)(cmd + 4) = 0;
goto LABEL_18;
case 17:
*(_DWORD *)(cmd + 4) = 1;
goto LABEL_18;
case 19:
v23 = 8LL * (*(_DWORD *)cmd + 3);
v33 = cmd;
v24 = realloc(*(void **)(cmd + 8), v23);
*(_QWORD *)(v33 + 8) = v24;
v25 = *(_QWORD *)(cmd + 8);
LODWORD(v24) = *(_DWORD *)cmd + 1;
*(_DWORD *)cmd = (_DWORD)v24;
*(_QWORD *)(v25 + 8LL * (int)v24) = *(_QWORD *)v2;
goto LABEL_18;
default:
LABEL_18:
v3 -= v9;
v7 = &v2[-8 * v9 + 8];
*(_QWORD *)v7 = v31;
v12 = (unsigned __int8)yyr1[v8] - 9;
v13 = *v3 + yypgoto[v12];
if ( v13 <= 0x14 && *v3 == yycheck[v13] )
v0 = yytable[v13];
else
v0 = yydefgoto[v12];
break;
}
LABEL_21:
v10 = v3 + 1;
v3[1] = v0;
v14 = 2 * v1;
if ( v3 + 1 < &v4[v1 - 1] )
{
v2 = v7;
++v3;
}
else
{
v15 = (char *)v10 - (char *)v4;
v16 = v10 - v4 + 1;
if ( v1 > 0x270F )
goto LABEL_59;
v1 = 10000LL;
if ( v14 <= 0x2710 )
v1 = v14;
v17 = (__int16 *)malloc(10 * v1 + 7);
v32 = v17;
if ( !v17 )
{
LABEL_59:
yyerror("memory exhausted");
v3 = v4;
v11 = 2;
goto LABEL_61;
}
v18 = v17;
memcpy(v17, v4, v15 + 2);
v19 = 8 * v16;
v33 = 2 * v1;
v20 = (char *)&v18[v1];
memcpy(v20, v29, v19);
if ( v4 != src )
free(v4);
v4 = v32;
v3 = (__int16 *)((char *)v32 + v15);
v2 = &v20[v19 - 8];
if ( v3 >= (__int16 *)((char *)v32 + v33 - 2) )
{
if ( v32 == v3 )
{
v3 = v32;
v11 = 1;
goto LABEL_64;
}
v10 = v3;
v3 = v32;
v11 = 1;
goto LABEL_62;
}
v29 = v20;
}
if ( v0 == 11 )
{
v10 = v3;
v3 = v4;
v11 = 0;
goto LABEL_61;
}
}
v8 = (unsigned __int8)yydefact[v0];
if ( yydefact[v0] )
goto LABEL_9;
if ( !v30 )
{
++yynerrs;
yyerror("syntax error");
goto LABEL_54;
}
if ( v30 == 3 )
{
if ( yychar > 0 )
{
yychar = -2;
goto LABEL_54;
}
if ( !yychar )
{
v10 = v3;
v3 = v4;
v11 = 1;
LABEL_61:
if ( v10 == v3 )
goto LABEL_63;
do
LABEL_62:
--v10;
while ( v10 != v3 );
goto LABEL_63;
}
}
while ( 1 )
{
LABEL_54:
v26 = yypact[v0];
if ( v26 != -13 )
{
v27 = v26 + 1;
if ( v27 <= 0x14 && yycheck[v27] == 1 )
{
v0 = yytable[v27];
if ( v0 > 0 )
{
v7 = v2 + 8;
*((_QWORD *)v2 + 1) = yylval;
v30 = 3;
goto LABEL_21;
}
}
}
if ( v4 == v3 )
break;
v2 -= 8;
v0 = *--v3;
}
v11 = 1;
LABEL_63:
if ( v3 == src )
return v11;
LABEL_64:
free(v3);
return v11;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // ebp
unsigned __int64 v1; // r15
char *v2; // r12
__int16 *v3; // rbx
__int16 *v4; // r14
int v5; // edx
unsigned int v6; // er13
char *v7; // rcx
int v8; // er13
unsigned __int8 v9; // bp
__int16 *v10; // r13
unsigned int v11; // ebp
int v12; // eax
unsigned int v13; // edx
unsigned __int64 v14; // rax
signed __int64 v15; // rbx
__int64 v16; // r12
__int16 *v17; // rax
__int16 *v18; // r13
size_t v19; // r12
char *v20; // r13
int v21; // er13
__int64 v22; // rax
size_t v23; // rsi
void *v24; // rax
__int64 v25; // rcx
int v26; // eax
unsigned int v27; // eax
char *v29; // [rsp+0h] [rbp-828h]
int v30; // [rsp+Ch] [rbp-81Ch]
__int64 v31; // [rsp+10h] [rbp-818h]
__int16 *v32; // [rsp+10h] [rbp-818h]
unsigned __int64 v33; // [rsp+18h] [rbp-810h]
char v34[1600]; // [rsp+20h] [rbp-808h] BYREF
__int16 src[228]; // [rsp+660h] [rbp-1C8h] BYREF

yynerrs = 0;
yychar = -2;
src[0] = 0;
v30 = 0;
v0 = 0;
v1 = 200LL;
v2 = v34;
v29 = v34;
v3 = src;
v4 = src;
while ( 1 )
{
v21 = yypact[v0];
if ( v21 == -13 )
break;
if ( yychar == -2 )
yychar = yylex();
if ( yychar <= 0 )
{
yychar = 0;
v5 = 0;
}
else
{
v5 = 2;
if ( (unsigned int)yychar <= 0x102 )
v5 = (unsigned __int8)yytranslate[yychar];
}
v6 = v5 + v21;
if ( v6 > 0x14 || yycheck[v6] != v5 )
break;
v0 = yytable[v6];
if ( v0 > 0 )
{
v30 = (v30 == 0) + v30 - 1;
yychar = -2;
v7 = v2 + 8;
*((_QWORD *)v2 + 1) = yylval;
goto LABEL_21;
}
v8 = -v0;
LABEL_9:
v9 = yyr2[v8];
v31 = *(_QWORD *)&v2[8 * (1 - v9)];
switch ( v8 )
{
case 2:
return 0;
case 3:
case 4:
return 1;
case 6:
is_bg = 0;
goto LABEL_18;
case 7:
is_bg = 1;
goto LABEL_18;
case 8:
case 9:
v22 = create_node(cmd);
insert(head, v22);
func1();
goto LABEL_18;
case 11:
v33 = cmd;
if ( !*(_QWORD *)(cmd + 8) )
*(_QWORD *)(v33 + 8) = malloc(8uLL);
**(_QWORD **)(v33 + 8) = *((_QWORD *)v2 - 1);
*(_QWORD *)(*(_QWORD *)(cmd + 8) + 8LL * (int)++*(_DWORD *)cmd) = 0LL;
goto LABEL_18;
case 13:
if ( !*(_QWORD *)(cmd + 16) )
*(_QWORD *)(cmd + 16) = *((_QWORD *)v2 - 1);
goto LABEL_18;
case 14:
if ( !*(_QWORD *)(cmd + 24) )
*(_QWORD *)(cmd + 24) = *((_QWORD *)v2 - 1);
goto LABEL_18;
case 16:
*(_DWORD *)(cmd + 4) = 0;
goto LABEL_18;
case 17:
*(_DWORD *)(cmd + 4) = 1;
goto LABEL_18;
case 19:
v23 = 8LL * (*(_DWORD *)cmd + 3);
v33 = cmd;
v24 = realloc(*(void **)(cmd + 8), v23);
*(_QWORD *)(v33 + 8) = v24;
v25 = *(_QWORD *)(cmd + 8);
LODWORD(v24) = *(_DWORD *)cmd + 1;
*(_DWORD *)cmd = (_DWORD)v24;
*(_QWORD *)(v25 + 8LL * (int)v24) = *(_QWORD *)v2;
goto LABEL_18;
default:
LABEL_18:
v3 -= v9;
v7 = &v2[-8 * v9 + 8];
*(_QWORD *)v7 = v31;
v12 = (unsigned __int8)yyr1[v8] - 9;
v13 = *v3 + yypgoto[v12];
if ( v13 <= 0x14 && *v3 == yycheck[v13] )
v0 = yytable[v13];
else
v0 = yydefgoto[v12];
break;
}
LABEL_21:
v10 = v3 + 1;
v3[1] = v0;
v14 = 2 * v1;
if ( v3 + 1 < &v4[v1 - 1] )
{
v2 = v7;
++v3;
}
else
{
v15 = (char *)v10 - (char *)v4;
v16 = v10 - v4 + 1;
if ( v1 > 0x270F )
goto LABEL_59;
v1 = 10000LL;
if ( v14 <= 0x2710 )
v1 = v14;
v17 = (__int16 *)malloc(10 * v1 + 7);
v32 = v17;
if ( !v17 )
{
LABEL_59:
func0("memory exhausted");
v3 = v4;
v11 = 2;
goto LABEL_61;
}
v18 = v17;
memcpy(v17, v4, v15 + 2);
v19 = 8 * v16;
v33 = 2 * v1;
v20 = (char *)&v18[v1];
memcpy(v20, v29, v19);
if ( v4 != src )
free(v4);
v4 = v32;
v3 = (__int16 *)((char *)v32 + v15);
v2 = &v20[v19 - 8];
if ( v3 >= (__int16 *)((char *)v32 + v33 - 2) )
{
if ( v32 == v3 )
{
v3 = v32;
v11 = 1;
goto LABEL_64;
}
v10 = v3;
v3 = v32;
v11 = 1;
goto LABEL_62;
}
v29 = v20;
}
if ( v0 == 11 )
{
v10 = v3;
v3 = v4;
v11 = 0;
goto LABEL_61;
}
}
v8 = (unsigned __int8)yydefact[v0];
if ( yydefact[v0] )
goto LABEL_9;
if ( !v30 )
{
++yynerrs;
func0("syntax error");
goto LABEL_54;
}
if ( v30 == 3 )
{
if ( yychar > 0 )
{
yychar = -2;
goto LABEL_54;
}
if ( !yychar )
{
v10 = v3;
v3 = v4;
v11 = 1;
LABEL_61:
if ( v10 == v3 )
goto LABEL_63;
do
LABEL_62:
--v10;
while ( v10 != v3 );
goto LABEL_63;
}
}
while ( 1 )
{
LABEL_54:
v26 = yypact[v0];
if ( v26 != -13 )
{
v27 = v26 + 1;
if ( v27 <= 0x14 && yycheck[v27] == 1 )
{
v0 = yytable[v27];
if ( v0 > 0 )
{
v7 = v2 + 8;
*((_QWORD *)v2 + 1) = yylval;
v30 = 3;
goto LABEL_21;
}
}
}
if ( v4 == v3 )
break;
v2 -= 8;
v0 = *--v3;
}
v11 = 1;
LABEL_63:
if ( v3 == src )
return v11;
LABEL_64:
free(v3);
return v11;
}

original_code:
int
yyparse (void)
{
    int yystate;
    int yyerrstatus;
    yytype_int16 yyssa[200];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;
    char * yyvsa[200];
    char * *yyvs;
    char * *yyvsp;
    long unsigned int yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  char * yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (yytype_int16) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      long unsigned int yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (char *)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 11)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-13))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 258 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 20 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 2:
    { return 0; }
    break;
  case 3:
    { (yyerrstatus = 0);
       return 1;
   }
    break;
  case 4:
    { return 1; }
    break;
  case 6:
    { is_bg = 0; }
    break;
  case 7:
    { is_bg = 1; }
    break;
  case 8:
    {
        insert(head, create_node(cmd));
        init_temp_cmd();
    }
    break;
  case 9:
    {
        insert(head, create_node(cmd));
        init_temp_cmd();
    }
    break;
  case 11:
    {
       if (!cmd->args) cmd->args = malloc(sizeof(char *));
       cmd->args[0] = yyvsp[-1];
       cmd->argc++;
       cmd->args[cmd->argc] = ((void *)0);
   }
    break;
  case 13:
    { if (!cmd->input) cmd->input = yyvsp[-1]; }
    break;
  case 14:
    { if (!cmd->output) cmd->output = yyvsp[-1]; }
    break;
  case 16:
    { cmd->append = 0; }
    break;
  case 17:
    { cmd->append = 1; }
    break;
  case 19:
    {
       cmd->args = (char**) realloc(cmd->args, sizeof(char *) * (cmd->argc + 3));
       cmd->args[1 + (cmd->argc)++] = yyvsp[0];
   }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 9;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 20 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 258 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-13))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 20 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned) (yychar) <= 258 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

canonical_original_code:
int yyparse()
{
    int yystate;
    int yyerrstatus;
    short yyssa[200];
    short *yyss;
    short *yyssp;
    char *yyvsa[200];
    char **yyvs;
    char **yyvsp;
    unsigned long yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  char *yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (short) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      unsigned long yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        short *yyss1 = yyss;
        union yyalloc *yyptr = (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (char *)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 11)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-13))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 258 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 20 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 2:
    { return 0; }
    break;
  case 3:
    { (yyerrstatus = 0);
       return 1;
   }
    break;
  case 4:
    { return 1; }
    break;
  case 6:
    { is_bg = 0; }
    break;
  case 7:
    { is_bg = 1; }
    break;
  case 8:
    {
        insert(head, create_node(cmd));
        init_temp_cmd();
    }
    break;
  case 9:
    {
        insert(head, create_node(cmd));
        init_temp_cmd();
    }
    break;
  case 11:
    {
       if (!cmd->args) cmd->args = malloc(sizeof(char *));
       cmd->args[0] = yyvsp[-1];
       cmd->argc++;
       cmd->args[cmd->argc] = ((void *)0);
   }
    break;
  case 13:
    { if (!cmd->input) cmd->input = yyvsp[-1]; }
    break;
  case 14:
    { if (!cmd->output) cmd->output = yyvsp[-1]; }
    break;
  case 16:
    { cmd->append = 0; }
    break;
  case 17:
    { cmd->append = 1; }
    break;
  case 19:
    {
       cmd->args = (char **) realloc(cmd->args, sizeof(char *) * (cmd->argc + 3));
       cmd->args[1 + (cmd->argc)++] = yyvsp[0];
   }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 9;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 20 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 258 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-13))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 20 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned int) (yychar) <= 258 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

variable_types: yystate int

variable_types: yyerrstatus int

variable_types:
yyssa
short [200]

variable_types:
yyss
short *

variable_types:
yyssp
short *

variable_types:
yyvsa
char *[200]

variable_types:
yyvs
char **

variable_types:
yyvsp
char **

variable_types:
yystacksize
unsigned long

variable_types: yyn int

variable_types: yyresult int

variable_types: yytoken int

variable_types:
yyval
char *

variable_types: yylen int

variable_types:
yysize
unsigned long

variable_types: union yyalloc { short yyss_alloc; char *yyvs_alloc; } *

variable_types:
yynewbytes
unsigned long

variable_types: yylhs int

variable_types: yyi int


stop

decompiled_code:
int stop()
{
return puts("stop here");
}

canonical_decompiled_code:
int func3()
{
return puts("stop here");
}

original_code:
void stop() {
    printf("stop here\n");
}

canonical_original_code:
void stop() {
    printf("stop here\n");
}

return_type: void


main

canonical_name: main

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

init(argc, argv, envp);
init_temp_cmd();
while ( 1 )
{
prompt();
if ( !(unsigned int)yyparse() )
{
v3 = cmd_input;
v3[strlen(cmd_input) - 1] = 0;
execute();
}
check_job_list();
*cmd_input = 0;
}
}

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

init(argc, argv, envp);
func1();
while ( 1 )
{
prompt();
if ( !(unsigned int)func2() )
{
v3 = cmd_input;
v3[strlen(cmd_input) - 1] = 0;
execute();
}
check_job_list();
*cmd_input = 0;
}
}

original_code:
int main(void) {
    init();
    init_temp_cmd();
    while (1) {
        prompt();
        if (yyparse() == 0) {
            cmd_input[strlen(cmd_input) - 1] = '\0';
            execute();
        }
        check_job_list();
        cmd_input[0] = '\0';
    }
    return 0;
}

canonical_original_code:
int main() {
    init();
    init_temp_cmd();
    while (1) {
        prompt();
        if (yyparse() == 0) {
            cmd_input[strlen(cmd_input) - 1] = '\0';
            execute();
        }
        check_job_list();
        cmd_input[0] = '\0';
    }
    return 0;
}

return_type: int


setGoon

decompiled_code:
void setGoon()
{
goon = 1;
}

canonical_decompiled_code:
void func0()
{
goon = 1;
}

original_code:
void setGoon() {
    goon = 1;
}

canonical_original_code:
void setGoon() {
    goon = 1;
}


decompiled_code:
int __fastcall error_handler(unsigned int a1)
{
if ( a1 == 2 )
return puts("user-sh: command or filename not found");
if ( a1 == 13 )
return puts("user-sh: permission denied");
return printf("user-sh: error: %d\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
if ( a1 == 2 )
return puts("user-sh: command or filename not found");
if ( a1 == 13 )
return puts("user-sh: permission denied");
return printf("user-sh: error: %d\n", a1);
}

original_code:
void error_handler(int err) {
    switch (err) {
 case 2: printf("user-sh: command or filename not found\n");
   break;
 case 13: printf("user-sh: permission denied\n");
   break;
 default: printf("user-sh: error: %d\n", err);
    }
}

variable_types: err int


decompiled_code:
int __fastcall redirect2(int fd, char *file, int a3)
{
int v3; // ebp

if ( fd )
v3 = open(file, a3 == 0 ? 577 : 1089, 420LL);
else
v3 = open(file, 64, 448LL);
close(fd);
return dup(v3);
}

canonical_decompiled_code:
int __fastcall func2(int fd, char *file, int a3)
{
int v3; // ebp

if ( fd )
v3 = open(file, a3 == 0 ? 577 : 1089, 420LL);
else
v3 = open(file, 64, 448LL);
close(fd);
return dup(v3);
}

original_code:
void redirect2(int file_desc, char* file, int is_append) {
    int f;
    if (file_desc == 0) {
        f = open(file, 0100 | 00, (0400|0200|0100));
    } else {
        f = open(file, 0100 | 01 | (is_append?02000:01000), 0644);
    }
    close(file_desc);
    dup(f);
}

canonical_original_code:
void redirect2(int file_desc, char *file, int is_append) {
    int f;
    if (file_desc == 0) {
        f = open(file, 0100 | 00, (0400|0200|0100));
    } else {
        f = open(file, 0100 | 01 | (is_append?02000:01000), 0644);
    }
    close(file_desc);
    dup(f);
}

variable_types:
file
char *

variable_types: f int


decompiled_code:
void connect_pipe()
{
if ( count == 1 )
{
if ( len == 1 )
return;
goto LABEL_3;
}
close(0);
dup2(pre_pipe, 0);
close(pre_pipe);
close(*(&pre_pipe + 1));
if ( len != 1 && len != count )
{
LABEL_3:
close(1);
dup2(current_pipe[1], 1);
close(current_pipe[1]);
close(current_pipe[0]);
}
}

canonical_decompiled_code:
void func3()
{
if ( count == 1 )
{
if ( len == 1 )
return;
goto LABEL_3;
}
close(0);
dup2(pre_pipe, 0);
close(pre_pipe);
close(*(&pre_pipe + 1));
if ( len != 1 && len != count )
{
LABEL_3:
close(1);
dup2(current_pipe[1], 1);
close(current_pipe[1]);
close(current_pipe[0]);
}
}

original_code:
void connect_pipe() {
    if (count != 1) {
        close(0);
        dup2(pre_pipe[0], 0);
        close(pre_pipe[0]);
        close(pre_pipe[1]);
    }
    if (len != 1 && count != len) {
        close(1);
        dup2(current_pipe[1], 1);
        close(current_pipe[1]);
        close(current_pipe[0]);
    }
}


decompiled_code:
int __fastcall reset_fd(int fd2)
{
dup2(STDIO[fd2], fd2);
return close(STDIO[fd2]);
}

canonical_decompiled_code:
int __fastcall func4(int fd2)
{
dup2(STDIO[fd2], fd2);
return close(STDIO[fd2]);
}

original_code:
void reset_fd(int file_desc) {
    dup2(STDIO[file_desc], file_desc);
    close(STDIO[file_desc]);
}


decompiled_code:
__int64 __fastcall is_int_cmd(char *s2)
{
const char **v1; // rbx

v1 = (const char **)&INT_CMD;
while ( strcmp(*v1, s2) )
{
if ( ++v1 == (const char **)(unsigned int)((_DWORD)&INT_CMD + 32) )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2)
{
const char **v1; // rbx

v1 = (const char **)&INT_CMD;
while ( strcmp(*v1, s2) )
{
if ( ++v1 == (const char **)(unsigned int)((_DWORD)&INT_CMD + 32) )
return 0LL;
}
return 1LL;
}

original_code:
int is_int_cmd(char* path) {
    int i;
    for (i = 0; i < sizeof(_INT_CMD)/sizeof((_INT_CMD)[0]); i++) {
 if (strcmp(_INT_CMD[i], path) == 0)
     return 1;
    }
    return 0;
}

canonical_original_code:
int is_int_cmd(char *path) {
    int i;
    for (i = 0; i < sizeof(_INT_CMD)/sizeof((_INT_CMD)[0]); i++) {
 if (strcmp(_INT_CMD[i], path) == 0)
     return 1;
    }
    return 0;
}

variable_types:
path
char *

variable_types: i int


decompiled_code:
int __fastcall exec_ext_command(__int64 a1)
{
int result; // eax
int *v2; // rax

result = execvp(**(const char ***)(a1 + 8), *(char *const **)(a1 + 8));
if ( result < 0 )
{
v2 = _errno_location();
result = error_handler(*v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
int result; // eax
int *v2; // rax

result = execvp(**(const char ***)(a1 + 8), *(char *const **)(a1 + 8));
if ( result < 0 )
{
v2 = _errno_location();
result = func1(*v2);
}
return result;
}

original_code:
void exec_ext_command(command cmd) {
    if (execvp(cmd->args[0], cmd->args) < 0) {
        error_handler((*__errno_location ()));
    }
}

canonical_original_code:
void exec_ext_command(struct simple_cmd *cmd) {
    if (execvp(cmd->args[0], cmd->args) < 0) {
        error_handler((*__errno_location ()));
    }
}

variable_types: struct simple_cmd { int argc; int append; char **args; char *input; char *output; } *


original_code:
void exec_int_command(command cmd) {
    char* path = cmd->args[0];
    if (strcmp(path, "jobs") == 0) {
        jobs();
    } else if (strcmp(path, "history") == 0) {
        history();
    } else if (strcmp(path, "fg") == 0) {
        fg(atoi(cmd->args[1]));
    } else if (strcmp(path, "bg") == 0) {
        bg(atoi(cmd->args[1]));
    } else if (strcmp(path, "pwd") == 0) {
        pwd();
    } else {
        printf("error internal command\n");
    }
}

canonical_original_code:
void exec_int_command(struct simple_cmd *cmd) {
    char *path = cmd->args[0];
    if (strcmp(path, "jobs") == 0) {
        jobs();
    } else if (strcmp(path, "history") == 0) {
        history();
    } else if (strcmp(path, "fg") == 0) {
        fg(atoi(cmd->args[1]));
    } else if (strcmp(path, "bg") == 0) {
        bg(atoi(cmd->args[1]));
    } else if (strcmp(path, "pwd") == 0) {
        pwd();
    } else {
        printf("error internal command\n");
    }
}

user_defined_types: struct simple_cmd { int argc; int append; char **args; char *input; char *output; }


waitchild

decompiled_code:
void waitchild()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rsi
__int64 i; // rbx
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = plist;
if ( is_bg )
{
add_job(plist, cmd_input);
v1 = jlist;
if ( jlist )
{
LODWORD(v2) = 0;
do
{
v1 = *(_QWORD *)(v1 + 24);
v2 = (unsigned int)(v2 + 1);
}
while ( v1 );
}
else
{
v2 = 0LL;
}
printf("[%d]\t%d\tRUNNING\t\t%s\n", v2, *(unsigned int *)plist, cmd_input);
for ( i = plist; i; i = *(_QWORD *)(i + 8) )
kill(*(_DWORD *)i, 10);
}
else if ( plist )
{
do
{
waitpid(*(_DWORD *)v0, stat_loc, 2);
v0 = *(_QWORD *)(v0 + 8);
}
while ( v0 );
}
}

canonical_decompiled_code:
void func8()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rsi
__int64 i; // rbx
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = plist;
if ( is_bg )
{
add_job(plist, cmd_input);
v1 = jlist;
if ( jlist )
{
LODWORD(v2) = 0;
do
{
v1 = *(_QWORD *)(v1 + 24);
v2 = (unsigned int)(v2 + 1);
}
while ( v1 );
}
else
{
v2 = 0LL;
}
printf("[%d]\t%d\tRUNNING\t\t%s\n", v2, *(unsigned int *)plist, cmd_input);
for ( i = plist; i; i = *(_QWORD *)(i + 8) )
kill(*(_DWORD *)i, 10);
}
else if ( plist )
{
do
{
waitpid(*(_DWORD *)v0, stat_loc, 2);
v0 = *(_QWORD *)(v0 + 8);
}
while ( v0 );
}
}

original_code:
void waitchild() {
    struct pid_node *p = plist;
    joblist j;
    int count = 0;
    if (is_bg) {
        add_job(plist, cmd_input);
        for (count = 0, j = jlist; j != ((void *)0); j = j->next, count++);
        printf("[%d]\t%d\tRUNNING\t\t%s\n", count, plist->pid, cmd_input);
        for (p = plist; p != ((void *)0); p = p->next)
            kill(p->pid, 10);
    } else {
        for (p = plist; p != ((void *)0); p = p->next) {
            int status;
            waitpid(p->pid, &status, 2);
        }
    }
}

canonical_original_code:
void waitchild() {
    struct pid_node *p = plist;
    struct jobs_node *j;
    int count = 0;
    if (is_bg) {
        add_job(plist, cmd_input);
        for (count = 0, j = jlist; j != ((void *)0); j = j->next, count++);
        printf("[%d]\t%d\tRUNNING\t\t%s\n", count, plist->pid, cmd_input);
        for (p = plist; p != ((void *)0); p = p->next)
            kill(p->pid, 10);
    } else {
        for (p = plist; p != ((void *)0); p = p->next) {
            int status;
            waitpid(p->pid, &status, 2);
        }
    }
}

variable_types: struct jobs_node { struct pid_node { int pid; struct pid_node *next; } *plist; char *cmd; int state; struct jobs_node *next; } *

variable_types: count int

variable_types: status int

user_defined_types: struct jobs_node { struct pid_node *plist; char *cmd; int state; struct jobs_node *next; }


decompiled_code:
char *add_to_history()
{
__int64 v0; // rbp
int v1; // ebx
char *result; // rax

*(_DWORD *)(envhis + 4LL) = (*(_DWORD *)(envhis + 4LL) + 1) % 100;
if ( *(_DWORD *)(envhis + 4LL) == *envhis )
*envhis = (*envhis + 1) % 100;
v0 = envhis;
v1 = *(_DWORD *)(envhis + 4LL);
result = strdup(cmd_input);
*(_QWORD *)(v0 + 8LL * v1 + 8) = result;
return result;
}

canonical_decompiled_code:
char *func9()
{
__int64 v0; // rbp
int v1; // ebx
char *result; // rax

*(_DWORD *)(envhis + 4LL) = (*(_DWORD *)(envhis + 4LL) + 1) % 100;
if ( *(_DWORD *)(envhis + 4LL) == *envhis )
*envhis = (*envhis + 1) % 100;
v0 = envhis;
v1 = *(_DWORD *)(envhis + 4LL);
result = strdup(cmd_input);
*(_QWORD *)(v0 + 8LL * v1 + 8) = result;
return result;
}

original_code:
void add_to_history() {
    envhis->end = (envhis->end + 1) % 100;
    if (envhis->end == envhis->start)
        envhis->start = (envhis->start + 1) % 100;
    envhis->his_cmd[envhis->end] = strdup(cmd_input);
}


execute

original_code:
void execute() {
    cmd_list p = head->next;
    command cmd = ((void *)0);
    count = 0;
    len = length(head);
    STDIO[0] = dup(0);
    STDIO[1] = dup(1);
    add_to_history();
    while (p) {
        count++;
        cmd = p->cmd;
        pre_pipe[0] = current_pipe[0];
        pre_pipe[1] = current_pipe[1];
        if (len != 1 && count != len) {
            if (pipe(current_pipe) != 0)
                printf("error in making pipe\n");
        }
        if (cmd->input)
            redirect2(0, cmd->input, 0);
        if (cmd->output)
            redirect2(1, cmd->output, cmd->append);
        if (strcmp(cmd->args[0], "exit") == 0)
            exit(0);
        if (strcmp(cmd->args[0], "fg") == 0) {
            fg(atoi(cmd->args[1]));
        } else if (strcmp(cmd->args[0], "bg") == 0) {
            bg(atoi(cmd->args[1]));
        } else if (strcmp(cmd->args[0], "cd") == 0) {
            cd(cmd->args[1]);
        } else {
            exec_command( cmd );
        }
        if (cmd->input)
            reset_fd(0);
        if (cmd->output)
            reset_fd(1);
        if (len != 1 && count != len)
            close(current_pipe[1]);
        p = p->next;
    }
    waitchild();
    clear_plist();
    clear_list(head);
}

canonical_original_code:
void execute() {
    struct command_list *p = head->next;
    struct simple_cmd *cmd = ((void *)0);
    count = 0;
    len = length(head);
    STDIO[0] = dup(0);
    STDIO[1] = dup(1);
    add_to_history();
    while (p) {
        count++;
        cmd = p->cmd;
        pre_pipe[0] = current_pipe[0];
        pre_pipe[1] = current_pipe[1];
        if (len != 1 && count != len) {
            if (pipe(current_pipe) != 0)
                printf("error in making pipe\n");
        }
        if (cmd->input)
            redirect2(0, cmd->input, 0);
        if (cmd->output)
            redirect2(1, cmd->output, cmd->append);
        if (strcmp(cmd->args[0], "exit") == 0)
            exit(0);
        if (strcmp(cmd->args[0], "fg") == 0) {
            fg(atoi(cmd->args[1]));
        } else if (strcmp(cmd->args[0], "bg") == 0) {
            bg(atoi(cmd->args[1]));
        } else if (strcmp(cmd->args[0], "cd") == 0) {
            cd(cmd->args[1]);
        } else {
            exec_command( cmd );
        }
        if (cmd->input)
            reset_fd(0);
        if (cmd->output)
            reset_fd(1);
        if (len != 1 && count != len)
            close(current_pipe[1]);
        p = p->next;
    }
    waitchild();
    clear_plist();
    clear_list(head);
}

variable_types: struct command_list { struct simple_cmd { int argc; int append; char **args; char *input; char *output; } *cmd; struct command_list *next; } *

user_defined_types: struct command_list { struct simple_cmd *cmd; struct command_list *next; }


original_code:
void clear_temp_cmd(command cmd) {
    int i;
    for (i=0; i<cmd->argc; i++) {
 free(cmd->args[i]);
    }
    cmd->argc = 0;
    cmd->args = ((void *)0);
    cmd->append = 0;
    cmd->input = ((void *)0);
    cmd->output = ((void *)0);
}

canonical_original_code:
void clear_temp_cmd(struct simple_cmd *cmd) {
    int i;
    for (i=0; i<cmd->argc; i++) {
 free(cmd->args[i]);
    }
    cmd->argc = 0;
    cmd->args = ((void *)0);
    cmd->append = 0;
    cmd->input = ((void *)0);
    cmd->output = ((void *)0);
}


decompiled_code:
void check_job_list()
{
const char **v0; // rbx
unsigned int v1; // ebp
const char **v2; // r12
char *v3; // r13

v0 = (const char **)jlist;
if ( jlist )
{
v1 = 1;
v2 = 0LL;
do
{
if ( *((_DWORD *)v0 + 4) == -1 )
{
printf("[%d]\tDone\t\t%s\n", v1, v0[1]);
v3 = (char *)v0[3];
if ( jlist == v0 )
{
free(v0);
jlist = v3;
}
else
{
v2[3] = v3;
free(v0);
}
v0 = (const char **)v3;
}
else
{
v2 = v0;
v0 = (const char **)v0[3];
}
++v1;
}
while ( v0 );
}
}

canonical_decompiled_code:
void func1()
{
const char **v0; // rbx
unsigned int v1; // ebp
const char **v2; // r12
char *v3; // r13

v0 = (const char **)jlist;
if ( jlist )
{
v1 = 1;
v2 = 0LL;
do
{
if ( *((_DWORD *)v0 + 4) == -1 )
{
printf("[%d]\tDone\t\t%s\n", v1, v0[1]);
v3 = (char *)v0[3];
if ( jlist == v0 )
{
free(v0);
jlist = v3;
}
else
{
v2[3] = v3;
free(v0);
}
v0 = (const char **)v3;
}
else
{
v2 = v0;
v0 = (const char **)v0[3];
}
++v1;
}
while ( v0 );
}
}

original_code:
void check_job_list() {
    joblist pre, j, temp;
    int count = 0;
    count = 1;
    pre = ((void *)0);
    j = jlist;
    while (j != ((void *)0)) {
        if (j->state == -1) {
            printf("[%d]\tDone\t\t%s\n", count, j->cmd);
            if (j == jlist) {
                j = j->next;
                free(jlist);
                jlist = j;
            } else {
                temp = j;
                pre->next = j->next;
                j = j->next;
                free(temp);
            }
        } else {
            pre = j;
            j = j->next;
        }
        count++;
    }
}

canonical_original_code:
void check_job_list() {
    struct jobs_node *pre; struct jobs_node *j; struct jobs_node *temp;
    int count = 0;
    count = 1;
    pre = ((void *)0);
    j = jlist;
    while (j != ((void *)0)) {
        if (j->state == -1) {
            printf("[%d]\tDone\t\t%s\n", count, j->cmd);
            if (j == jlist) {
                j = j->next;
                free(jlist);
                jlist = j;
            } else {
                temp = j;
                pre->next = j->next;
                j = j->next;
                free(temp);
            }
        } else {
            pre = j;
            j = j->next;
        }
        count++;
    }
}

user_defined_types: struct pid_node { int pid; struct pid_node *next; }


decompiled_code:
char *get_current_dir()
{
char *v0; // rbx
char *v1; // rbp

v0 = (char *)malloc(0x100uLL);
getcwd(v0, 0x100uLL);
do
{
v1 = v0 + 1;
v0 = strchr(v0 + 1, 47);
}
while ( v0 );
return v1;
}

canonical_decompiled_code:
char *func2()
{
char *v0; // rbx
char *v1; // rbp

v0 = (char *)malloc(0x100uLL);
getcwd(v0, 0x100uLL);
do
{
v1 = v0 + 1;
v0 = strchr(v0 + 1, 47);
}
while ( v0 );
return v1;
}

original_code:
char * get_current_dir() {
    char *pwd = malloc(256 * sizeof(char));
    getcwd(pwd, 256);
    while (strstr(pwd+1, "/") != 0x0) {
     pwd = strstr(pwd+1, "/");
    }
    pwd++;
    return pwd;
}

canonical_original_code:
char *get_current_dir() {
    char *pwd = malloc(256 * sizeof(char));
    getcwd(pwd, 256);
    while (strstr(pwd+1, "/") != 0x0) {
     pwd = strstr(pwd+1, "/");
    }
    pwd++;
    return pwd;
}

variable_types:
pwd
char *

return_type: char *


decompiled_code:
_QWORD *init_history()
{
_DWORD *v0; // rdx
_QWORD *result; // rax
_QWORD *v2; // rdx

v0 = malloc(0x328uLL);
envhis = v0;
*v0 = 0;
v0[1] = 0;
result = v0 + 2;
v2 = v0 + 202;
do
*result++ = 0LL;
while ( result != v2 );
return result;
}

canonical_decompiled_code:
_QWORD *func3()
{
_DWORD *v0; // rdx
_QWORD *result; // rax
_QWORD *v2; // rdx

v0 = malloc(0x328uLL);
envhis = v0;
*v0 = 0;
v0[1] = 0;
result = v0 + 2;
v2 = v0 + 202;
do
*result++ = 0LL;
while ( result != v2 );
return result;
}

original_code:
void init_history() {
    int i;
    envhis = malloc(sizeof(struct ENV_HISTORY));
    envhis->start = 0;
    envhis->end = 0;
    for (i=0; i<100; i++) {
    envhis->his_cmd[i] = ((void *)0);
    }
}

user_defined_types: struct ENV_HISTORY { int start; int end; char *his_cmd[100]; }


prompt

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

v0 = get_current_dir();
return printf("%s@%s> ", (const char *)USER, v0);
}

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

v0 = func2();
return printf("%s@%s> ", (const char *)USER, v0);
}

original_code:
void prompt() {
    printf("%s@%s> ", USER, get_current_dir());
}


init

decompiled_code:
int init()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

USER = (__int64)getenv("USER");
jlist = 0LL;
cmd_input = malloc(0x400uLL);
head = init_cmd_list();
init_history();
signal(20, (__sighandler_t)&sigstp_handler);
v1.sa_handler = (__sighandler_t)&remove_job;
sigfillset(&v1.sa_mask);
v1.sa_flags = 268435462;
result = sigaction(17, &v1, 0LL);
if ( result )
result = puts("signal error");
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

USER = (__int64)getenv("USER");
jlist = 0LL;
cmd_input = malloc(0x400uLL);
head = init_cmd_list();
func3();
signal(20, (__sighandler_t)&sigstp_handler);
v1.sa_handler = (__sighandler_t)&remove_job;
sigfillset(&v1.sa_mask);
v1.sa_flags = 268435462;
result = sigaction(17, &v1, 0LL);
if ( result )
result = puts("signal error");
return result;
}

original_code:
void init() {
    USER = getenv("USER");
    jlist = ((void *)0);
    cmd_input = malloc(1024 * sizeof(char));
    head = init_cmd_list();
    init_history();
    signal(20, sigstp_handler);
    struct sigaction act;
    act.__sigaction_handler.sa_sigaction = remove_job;
    sigfillset(&act.sa_mask);
    act.sa_flags = 4 | 0x10000000 | 2;
    if (sigaction(17, &act, ((void *)0))) {
        printf("signal error\n");
    }
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


cd

decompiled_code:
int __fastcall cd(const char *a1)
{
int result; // eax

result = chdir(a1);
if ( result < 0 )
result = printf("%s\t the wrong path name.\n", a1);
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int result; // eax

result = chdir(a1);
if ( result < 0 )
result = printf("%s\t the wrong path name.\n", a1);
return result;
}

original_code:
void cd(char* dir) {
    if(chdir(dir) < 0)
        printf("%s\t the wrong path name.\n",dir);
}

canonical_original_code:
void cd(char *dir) {
    if(chdir(dir) < 0)
        printf("%s\t the wrong path name.\n",dir);
}

variable_types:
dir
char *


history

decompiled_code:
__int64 history()
{
__int64 result; // rax
int v1; // ebp
int v2; // edx
int v3; // ebx
int v4; // ebp
int v5; // ebx
int v6; // ebx

result = envhis;
v1 = *(_DWORD *)envhis;
v2 = *(_DWORD *)(envhis + 4);
if ( *(_DWORD *)envhis <= v2 )
{
if ( *(_QWORD *)(envhis + 8LL * v1 + 8) || (++v1, v2 >= v1) )
{
v6 = v1;
do
{
printf("%d\t%s\n", (unsigned int)(1 - v1 + v6), *(const char **)(result + 8LL * v6 + 8));
++v6;
result = envhis;
}
while ( *(_DWORD *)(envhis + 4) >= v6 );
}
}
else
{
v3 = *(_DWORD *)envhis;
if ( v1 > 99 )
{
v4 = 1;
}
else
{
do
{
printf("%d\t%s\n", (unsigned int)(1 - v1 + v3), *(const char **)(envhis + 8LL * v3 + 8));
++v3;
}
while ( v3 != 100 );
v4 = 101 - v1;
}
result = envhis;
if ( *(int *)(envhis + 4) >= 0 )
{
v5 = 0;
do
{
printf("%d\t%s\n", (unsigned int)(v5 + v4), *(const char **)(result + 8LL * v5 + 8));
++v5;
result = envhis;
}
while ( *(_DWORD *)(envhis + 4) >= v5 );
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
int v1; // ebp
int v2; // edx
int v3; // ebx
int v4; // ebp
int v5; // ebx
int v6; // ebx

result = envhis;
v1 = *(_DWORD *)envhis;
v2 = *(_DWORD *)(envhis + 4);
if ( *(_DWORD *)envhis <= v2 )
{
if ( *(_QWORD *)(envhis + 8LL * v1 + 8) || (++v1, v2 >= v1) )
{
v6 = v1;
do
{
printf("%d\t%s\n", (unsigned int)(1 - v1 + v6), *(const char **)(result + 8LL * v6 + 8));
++v6;
result = envhis;
}
while ( *(_DWORD *)(envhis + 4) >= v6 );
}
}
else
{
v3 = *(_DWORD *)envhis;
if ( v1 > 99 )
{
v4 = 1;
}
else
{
do
{
printf("%d\t%s\n", (unsigned int)(1 - v1 + v3), *(const char **)(envhis + 8LL * v3 + 8));
++v3;
}
while ( v3 != 100 );
v4 = 101 - v1;
}
result = envhis;
if ( *(int *)(envhis + 4) >= 0 )
{
v5 = 0;
do
{
printf("%d\t%s\n", (unsigned int)(v5 + v4), *(const char **)(result + 8LL * v5 + 8));
++v5;
result = envhis;
}
while ( *(_DWORD *)(envhis + 4) >= v5 );
}
}
return result;
}

original_code:
void history() {
    int i,j=1;
    int start =0;
    if(envhis->start <= envhis->end)
    {
        if(envhis->his_cmd[envhis->start] == ((void *)0))
            start = envhis->start+1;
        else
            start = envhis->start;
        for(i=start;i <= envhis->end;i++)
        {
            printf("%d\t%s\n",j,envhis->his_cmd[i]);
            j++;
        }
    }
    else
    {
        for(i=envhis->start;i < 100;i++)
        {
            printf("%d\t%s\n",j,envhis->his_cmd[i]);
            j++;
        }
        for(i=0;i <= envhis->end;i++)
        {
            printf("%d\t%s\n",j,envhis->his_cmd[i]);
            j++;
        }
    }
}

canonical_original_code:
void history() {
    int i; int j = 1;
    int start = 0;
    if(envhis->start <= envhis->end)
    {
        if(envhis->his_cmd[envhis->start] == ((void *)0))
            start = envhis->start+1;
        else
            start = envhis->start;
        for(i=start;i <= envhis->end;i++)
        {
            printf("%d\t%s\n",j,envhis->his_cmd[i]);
            j++;
        }
    }
    else
    {
        for(i=envhis->start;i < 100;i++)
        {
            printf("%d\t%s\n",j,envhis->his_cmd[i]);
            j++;
        }
        for(i=0;i <= envhis->end;i++)
        {
            printf("%d\t%s\n",j,envhis->his_cmd[i]);
            j++;
        }
    }
}

variable_types: j int

variable_types: start int


jobs

decompiled_code:
int jobs()
{
__int64 v0; // rbx
unsigned int v1; // ebp
int result; // eax
const char *v3; // rdx
int v4; // eax

v0 = jlist;
v1 = 1;
if ( !jlist )
return printf("There is no jobs!");
do
{
v4 = *(_DWORD *)(v0 + 16);
v3 = "RUNNING";
if ( v4 != 1 )
{
v3 = "STOPPED";
if ( v4 )
v3 = "DONE";
}
result = printf("[%d]\t%s\t\t%s\n", v1, v3, *(const char **)(v0 + 8));
v0 = *(_QWORD *)(v0 + 24);
++v1;
}
while ( v0 );
return result;
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rbx
unsigned int v1; // ebp
int result; // eax
const char *v3; // rdx
int v4; // eax

v0 = jlist;
v1 = 1;
if ( !jlist )
return printf("There is no jobs!");
do
{
v4 = *(_DWORD *)(v0 + 16);
v3 = "RUNNING";
if ( v4 != 1 )
{
v3 = "STOPPED";
if ( v4 )
v3 = "DONE";
}
result = printf("[%d]\t%s\t\t%s\n", v1, v3, *(const char **)(v0 + 8));
v0 = *(_QWORD *)(v0 + 24);
++v1;
}
while ( v0 );
return result;
}

original_code:
void jobs() {
    int i = 0;
    struct pid_node* p;
    joblist j;
    if (jlist == ((void *)0))
        printf("There is no jobs!");
    else {
        for (i=1, j = jlist; j != ((void *)0); j = j->next, i++) {
           printf("[%d]\t%s\t\t%s\n", i, j->state==1?"RUNNING":j->state==0?"STOPPED":"DONE", j->cmd);
        }
    }
}

canonical_original_code:
void jobs() {
    int i = 0;
    struct pid_node *p;
    struct jobs_node *j;
    if (jlist == ((void *)0))
        printf("There is no jobs!");
    else {
        for (i=1, j = jlist; j != ((void *)0); j = j->next, i++) {
           printf("[%d]\t%s\t\t%s\n", i, j->state==1?"RUNNING":j->state==0?"STOPPED":"DONE", j->cmd);
        }
    }
}

variable_types: struct pid_node { int pid; struct pid_node *next; } *


original_code:
void remove_job(int sig, siginfo_t *sip, void* nosed) {
    pid_t pid;
    struct pid_node* p, *temp;
    int found;
    joblist j, pre_j;
    if (sip->si_code != CLD_EXITED)
        return;
    pid = sip->_sifields._kill.si_pid;
    j = jlist;
    found = 0;
    while (j != ((void *)0)) {
        if (j->plist == ((void *)0))
            break;
        p = j->plist;
        if (p->pid == pid) {
            j->plist = j->plist->next;
            free(p);
            found = 1;
        } else {
            while (p->next != ((void *)0)) {
                if (p->next->pid == pid) {
                    temp = p->next;
                    p->next = temp->next;
                    free(temp);
                    found = 1;
                    break;
                }
                p = p->next;
            }
        }
        if (found) break;
        j = j->next;
    }
    j = jlist;
    while (j != ((void *)0)) {
        if (j->plist == ((void *)0))
            j->state = -1;
        j = j->next;
    }
}

canonical_original_code:
void remove_job(int sig, struct siginfo_t *sip, void *nosed) {
    int pid;
    struct pid_node *p; struct pid_node *temp;
    int found;
    struct jobs_node *j; struct jobs_node *pre_j;
    if (sip->si_code != CLD_EXITED)
        return;
    pid = sip->_sifields._kill.si_pid;
    j = jlist;
    found = 0;
    while (j != ((void *)0)) {
        if (j->plist == ((void *)0))
            break;
        p = j->plist;
        if (p->pid == pid) {
            j->plist = j->plist->next;
            free(p);
            found = 1;
        } else {
            while (p->next != ((void *)0)) {
                if (p->next->pid == pid) {
                    temp = p->next;
                    p->next = temp->next;
                    free(temp);
                    found = 1;
                    break;
                }
                p = p->next;
            }
        }
        if (found) break;
        j = j->next;
    }
    j = jlist;
    while (j != ((void *)0)) {
        if (j->plist == ((void *)0))
            j->state = -1;
        j = j->next;
    }
}

variable_types: sig int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
nosed
void *

variable_types: pid int

variable_types: found int


decompiled_code:
void clear_plist()
{
_QWORD *i; // rdi

for ( i = plist; plist; i = plist )
{
plist = (void *)i[1];
free(i);
}
}

canonical_decompiled_code:
void func4()
{
_QWORD *i; // rdi

for ( i = plist; plist; i = plist )
{
plist = (void *)i[1];
free(i);
}
}

original_code:
void clear_plist() {
    struct pid_node* p;
    while (plist != ((void *)0)) {
        p = plist;
        plist = plist->next;
        free(p);
    }
}

canonical_original_code:
void clear_plist() {
    struct pid_node *p;
    while (plist != ((void *)0)) {
        p = plist;
        plist = plist->next;
        free(p);
    }
}


decompiled_code:
void sigstp_handler()
{
__pid_t *v0; // rbx
_QWORD *v1; // rbx
__int64 v2; // rax
char *v3; // rbp
size_t v4; // rax
const char *v5; // rbp

v0 = (__pid_t *)plist;
if ( plist )
{
do
{
kill(*v0, 19);
v0 = (__pid_t *)*((_QWORD *)v0 + 1);
}
while ( v0 );
v1 = (_QWORD *)jlist;
if ( jlist )
{
while ( 1 )
{
v2 = *v1;
if ( *v1 )
break;
LABEL_5:
v1 = (_QWORD *)v1[3];
if ( !v1 )
goto LABEL_12;
}
while ( *(_DWORD *)v2 != *(_DWORD *)plist )
{
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
goto LABEL_5;
}
}
else
{
LABEL_12:
v1 = add_job((__int64)plist, cmd_input);
}
*((_DWORD *)v1 + 4) = 0;
v3 = (char *)v1[1];
v4 = strlen(v3);
v5 = (const char *)realloc(v3, v4 + 1);
v1[1] = v5;
*(_WORD *)&v5[strlen(v5)] = 38;
if ( jlist && v1 != (_QWORD *)jlist )
{
while ( 1 )
;
}
printf("[%d]\tStopped\t\t%s\n", 1LL, (const char *)v1[1]);
clear_plist();
}
}

canonical_decompiled_code:
void func5()
{
__pid_t *v0; // rbx
_QWORD *v1; // rbx
__int64 v2; // rax
char *v3; // rbp
size_t v4; // rax
const char *v5; // rbp

v0 = (__pid_t *)plist;
if ( plist )
{
do
{
kill(*v0, 19);
v0 = (__pid_t *)*((_QWORD *)v0 + 1);
}
while ( v0 );
v1 = (_QWORD *)jlist;
if ( jlist )
{
while ( 1 )
{
v2 = *v1;
if ( *v1 )
break;
LABEL_5:
v1 = (_QWORD *)v1[3];
if ( !v1 )
goto LABEL_12;
}
while ( *(_DWORD *)v2 != *(_DWORD *)plist )
{
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
goto LABEL_5;
}
}
else
{
LABEL_12:
v1 = add_job((__int64)plist, cmd_input);
}
*((_DWORD *)v1 + 4) = 0;
v3 = (char *)v1[1];
v4 = strlen(v3);
v5 = (const char *)realloc(v3, v4 + 1);
v1[1] = v5;
*(_WORD *)&v5[strlen(v5)] = 38;
if ( jlist && v1 != (_QWORD *)jlist )
{
while ( 1 )
;
}
printf("[%d]\tStopped\t\t%s\n", 1LL, (const char *)v1[1]);
func4();
}
}

original_code:
void sigstp_handler() {
    struct pid_node* p;
    joblist j, job;
    int found = 0, jid;
    if (plist == ((void *)0))
        return;
    for (p = plist; p != ((void *)0); p = p->next)
        kill(p->pid, 19);
    job = ((void *)0);
    j = jlist;
    while (j != ((void *)0)) {
        for (p = j->plist; p != ((void *)0); p = p->next)
            if (p->pid == plist->pid) {
                found = 1;
                break;
            }
        if (found) {
            job = j;
            break;
        }
        j = j->next;
    }
    if (job == ((void *)0))
        job = add_job(plist, cmd_input);
    job->state = 0;
    job->cmd = realloc(job->cmd, (strlen(job->cmd) + 1) * sizeof(char));
    strcat(job->cmd, "&");
    j = jlist;
    jid = 1;
    while (j != ((void *)0) && j != job) jid++;
    printf("[%d]\tStopped\t\t%s\n", jid, job->cmd);
    clear_plist();
}

canonical_original_code:
void sigstp_handler() {
    struct pid_node *p;
    struct jobs_node *j; struct jobs_node *job;
    int found = 0; int jid;
    if (plist == ((void *)0))
        return;
    for (p = plist; p != ((void *)0); p = p->next)
        kill(p->pid, 19);
    job = ((void *)0);
    j = jlist;
    while (j != ((void *)0)) {
        for (p = j->plist; p != ((void *)0); p = p->next)
            if (p->pid == plist->pid) {
                found = 1;
                break;
            }
        if (found) {
            job = j;
            break;
        }
        j = j->next;
    }
    if (job == ((void *)0))
        job = add_job(plist, cmd_input);
    job->state = 0;
    job->cmd = realloc(job->cmd, (strlen(job->cmd) + 1) * sizeof(char));
    strcat(job->cmd, "&");
    j = jlist;
    jid = 1;
    while (j != ((void *)0) && j != job) jid++;
    printf("[%d]\tStopped\t\t%s\n", jid, job->cmd);
    clear_plist();
}

variable_types: jid int


fg

decompiled_code:
int __fastcall fg(unsigned int a1)
{
__int64 v1; // rbx
int i; // eax
const char *v3; // rbp
char *v4; // rbp
size_t v5; // rax
const char *v6; // rax
int result; // eax
__pid_t *v8; // rbx
_QWORD *v9; // rbx
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = jlist;
if ( !jlist )
return printf("fg: %d: There is no this task!\n", a1);
if ( a1 != 1 )
{
for ( i = 1; i != a1; ++i )
{
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return printf("fg: %d: There is no this task!\n", a1);
}
}
plist = plistdup(*(_QWORD *)v1);
*(_DWORD *)(v1 + 16) = 1;
v3 = *(const char **)(v1 + 8);
v3[strlen(v3) - 1] = 0;
v4 = *(char **)(v1 + 8);
v5 = strlen(v4);
v6 = (const char *)realloc(v4, v5 - 1);
*(_QWORD *)(v1 + 8) = v6;
result = puts(v6);
v8 = (__pid_t *)plist;
if ( plist )
{
do
{
result = kill(*v8, 18);
v8 = (__pid_t *)*((_QWORD *)v8 + 1);
}
while ( v8 );
v9 = plist;
if ( plist )
{
do
{
result = waitpid(*(_DWORD *)v9, stat_loc, 2);
v9 = (_QWORD *)v9[1];
}
while ( v9 );
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1)
{
__int64 v1; // rbx
int i; // eax
const char *v3; // rbp
char *v4; // rbp
size_t v5; // rax
const char *v6; // rax
int result; // eax
__pid_t *v8; // rbx
_QWORD *v9; // rbx
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = jlist;
if ( !jlist )
return printf("fg: %d: There is no this task!\n", a1);
if ( a1 != 1 )
{
for ( i = 1; i != a1; ++i )
{
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return printf("fg: %d: There is no this task!\n", a1);
}
}
plist = plistdup(*(_QWORD *)v1);
*(_DWORD *)(v1 + 16) = 1;
v3 = *(const char **)(v1 + 8);
v3[strlen(v3) - 1] = 0;
v4 = *(char **)(v1 + 8);
v5 = strlen(v4);
v6 = (const char *)realloc(v4, v5 - 1);
*(_QWORD *)(v1 + 8) = v6;
result = puts(v6);
v8 = (__pid_t *)plist;
if ( plist )
{
do
{
result = kill(*v8, 18);
v8 = (__pid_t *)*((_QWORD *)v8 + 1);
}
while ( v8 );
v9 = plist;
if ( plist )
{
do
{
result = waitpid(*(_DWORD *)v9, stat_loc, 2);
v9 = (_QWORD *)v9[1];
}
while ( v9 );
}
}
return result;
}

original_code:
void fg(int jid) {
    joblist j, job;
    struct pid_node* p, h;
    int count, found = 0;
    for (count = 1, j = jlist; j != ((void *)0); count++, j = j->next) {
        if (count == jid) {
            job = j;
            found = 1;
            break;
        }
    }
    if (!found)
        printf("fg: %d: There is no this task!\n", jid);
    else {
        plist = plistdup(job->plist);
        job->state = 1;
        job->cmd[strlen(job->cmd) - 1] = '\0';
        job->cmd = realloc(job->cmd, (strlen(job->cmd) - 1) * sizeof(char));
        printf("%s\n", job->cmd);
        for (p = plist; p != ((void *)0); p = p->next) {
            kill(p->pid, 18);
        }
        for (p = plist; p != ((void *)0); p = p->next) {
            int status;
            waitpid(p->pid, &status, 2);
        }
    }
}

canonical_original_code:
void fg(int jid) {
    struct jobs_node *j; struct jobs_node *job;
    struct pid_node *p; struct pid_node h;
    int count; int found = 0;
    for (count = 1, j = jlist; j != ((void *)0); count++, j = j->next) {
        if (count == jid) {
            job = j;
            found = 1;
            break;
        }
    }
    if (!found)
        printf("fg: %d: There is no this task!\n", jid);
    else {
        plist = plistdup(job->plist);
        job->state = 1;
        job->cmd[strlen(job->cmd) - 1] = '\0';
        job->cmd = realloc(job->cmd, (strlen(job->cmd) - 1) * sizeof(char));
        printf("%s\n", job->cmd);
        for (p = plist; p != ((void *)0); p = p->next) {
            kill(p->pid, 18);
        }
        for (p = plist; p != ((void *)0); p = p->next) {
            int status;
            waitpid(p->pid, &status, 2);
        }
    }
}

variable_types: struct pid_node { int pid; struct pid_node *next; }


bg

decompiled_code:
int __fastcall bg(unsigned int a1)
{
__int64 v1; // rbx
int i; // eax
int result; // eax
__int64 j; // rbx

v1 = jlist;
if ( !jlist )
return printf("bg: %d: Theres is no this task!\n", a1);
if ( a1 != 1 )
{
for ( i = 1; i != a1; ++i )
{
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return printf("bg: %d: Theres is no this task!\n", a1);
}
}
*(_DWORD *)(v1 + 16) = 1;
result = printf("[%d]\t%s\n", a1, *(const char **)(v1 + 8));
for ( j = *(_QWORD *)v1; j; j = *(_QWORD *)(j + 8) )
result = kill(*(_DWORD *)j, 18);
return result;
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
__int64 v1; // rbx
int i; // eax
int result; // eax
__int64 j; // rbx

v1 = jlist;
if ( !jlist )
return printf("bg: %d: Theres is no this task!\n", a1);
if ( a1 != 1 )
{
for ( i = 1; i != a1; ++i )
{
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return printf("bg: %d: Theres is no this task!\n", a1);
}
}
*(_DWORD *)(v1 + 16) = 1;
result = printf("[%d]\t%s\n", a1, *(const char **)(v1 + 8));
for ( j = *(_QWORD *)v1; j; j = *(_QWORD *)(j + 8) )
result = kill(*(_DWORD *)j, 18);
return result;
}

original_code:
void bg(int jid) {
    joblist j, job;
    struct pid_node* p;
    int count, found = 0;
    for (count = 1, j = jlist; j != ((void *)0); count++, j = j->next) {
        if (count == jid) {
            job = j;
            found = 1;
            break;
        }
    }
    if (!found)
        printf("bg: %d: Theres is no this task!\n", jid);
    else {
        job->state = 1;
        printf("[%d]\t%s\n", jid, job->cmd);
        for (p = job->plist; p != ((void *)0); p = p->next) {
            int status;
            kill(p->pid, 18);
        }
    }
}

canonical_original_code:
void bg(int jid) {
    struct jobs_node *j; struct jobs_node *job;
    struct pid_node *p;
    int count; int found = 0;
    for (count = 1, j = jlist; j != ((void *)0); count++, j = j->next) {
        if (count == jid) {
            job = j;
            found = 1;
            break;
        }
    }
    if (!found)
        printf("bg: %d: Theres is no this task!\n", jid);
    else {
        job->state = 1;
        printf("[%d]\t%s\n", jid, job->cmd);
        for (p = job->plist; p != ((void *)0); p = p->next) {
            int status;
            kill(p->pid, 18);
        }
    }
}

variable_types: struct jobs_node { struct pid_node { int pid; struct pid_node *next; } *plist; char *cmd; int state; struct jobs_node *next; } *


pwd

decompiled_code:
int pwd()
{
char v1[120]; // [rsp+0h] [rbp-78h] BYREF

getcwd(v1, 0x64uLL);
return puts(v1);
}

canonical_decompiled_code:
int func8()
{
char v1[120]; // [rsp+0h] [rbp-78h] BYREF

getcwd(v1, 0x64uLL);
return puts(v1);
}

original_code:
void pwd()
{
    char curdir[100];
    getcwd(curdir,sizeof(curdir));
    printf("%s\n",curdir);
}

variable_types:
curdir
char [100]


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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
cmd_list init_cmd_list() {
    cmd_list node;
    node = malloc(sizeof(struct command_list));
    node->cmd = ((void *)0);
    node->next = ((void *)0);
    return node;
}

canonical_original_code:
struct command_list *init_cmd_list() {
    struct command_list *node;
    node = malloc(sizeof(struct command_list));
    node->cmd = ((void *)0);
    node->next = ((void *)0);
    return node;
}

return_type: struct command_list { struct simple_cmd { int argc; int append; char **args; char *input; char *output; } *cmd; struct command_list *next; } *


insert

original_code:
int insert(cmd_list head, cmd_list node) {
    cmd_list p = head;
    while (p->next)
 p = p->next;
    p->next = node;
    node->next = ((void *)0);
    return 0;
}

canonical_original_code:
int insert(struct command_list *head, struct command_list *node) {
    struct command_list *p = head;
    while (p->next)
 p = p->next;
    p->next = node;
    node->next = ((void *)0);
    return 0;
}

variable_types:
node
struct command_list *


decompiled_code:
__int64 __fastcall clear_list(__int64 a1)
{
void **v2; // rbx
void *v3; // rdi
void **v4; // rbp

v2 = *(void ***)(a1 + 8);
while ( v2 )
{
v3 = *v2;
v4 = v2;
v2 = (void **)v2[1];
free(v3);
free(v4);
}
*(_QWORD *)(a1 + 8) = 0LL;
return 0LL;
}

original_code:
int clear_list(cmd_list head) {
    cmd_list h, p;
    command cmd;
    h = head->next;
    while (h != ((void *)0)) {
 p = h;
 cmd = p->cmd;
 h = h->next;
 free(cmd);
 free(p);
    }
    head->next = ((void *)0);
    return 0;
}

canonical_original_code:
int clear_list(struct command_list *head) {
    struct command_list *h; struct command_list *p;
    struct simple_cmd *cmd;
    h = head->next;
    while (h != ((void *)0)) {
 p = h;
 cmd = p->cmd;
 h = h->next;
 free(cmd);
 free(p);
    }
    head->next = ((void *)0);
    return 0;
}

variable_types: struct command_list { struct simple_cmd { int argc; int append; char **args; char *input; char *output; } *cmd; struct command_list *next; } *


length

decompiled_code:
__int64 __fastcall length(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

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

original_code:
int length(cmd_list head) {
    cmd_list p = head;
    int count = 0;
    while (p->next) {
 p = p->next;
 count++;
    }
    return count;
}

canonical_original_code:
int length(struct command_list *head) {
    struct command_list *p = head;
    int count = 0;
    while (p->next) {
 p = p->next;
 count++;
    }
    return count;
}

variable_types: count int


main

repo: popwarfour/HackVtProject

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbx
char *v4; // rbx
void *v5; // rbx
char *v6; // rbx
void *v7; // rbx
char *v8; // rbx

v3 = (void *)gh_build_get_query("greenupapi.appspot.com", "/api/comments", envp);
gh_get_ip("greenupapi.appspot.com");
v4 = (char *)gh_make_request(v3);
puts(v4);
free(v4);
v5 = (void *)gh_build_post_query(
"greenupapi.appspot.com",
4202501LL,
"{\"type\" : \"forum\", \"message\" : \"Have you guys heard about the free cookies on Pearl St and South"
" Winooski? Bring your green bags down there and get one!\"}");
gh_get_ip("greenupapi.appspot.com");
v6 = (char *)gh_make_request(v5);
puts(v6);
free(v6);
v7 = (void *)gh_build_put_query(
"greenupapi.appspot.com",
"api/heatmap",
"[{\"latDegrees\" : 24.53, \"lonDegrees\" : 43.2, \"secondsWorked\" : 120}]");
gh_get_ip("greenupapi.appspot.com");
v8 = (char *)gh_make_request(v7);
puts(v8);
free(v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbx
char *v4; // rbx
void *v5; // rbx
char *v6; // rbx
void *v7; // rbx
char *v8; // rbx

v3 = (void *)func8("greenupapi.appspot.com", "/api/comments", envp);
func13("greenupapi.appspot.com");
v4 = (char *)func12(v3);
puts(v4);
free(v4);
v5 = (void *)func9(
"greenupapi.appspot.com",
4202501LL,
"{\"type\" : \"forum\", \"message\" : \"Have you guys heard about the free cookies on Pearl St and South"
" Winooski? Bring your green bags down there and get one!\"}");
func13("greenupapi.appspot.com");
v6 = (char *)func12(v5);
puts(v6);
free(v6);
v7 = (void *)func10(
"greenupapi.appspot.com",
"api/heatmap",
"[{\"latDegrees\" : 24.53, \"lonDegrees\" : 43.2, \"secondsWorked\" : 120}]");
func13("greenupapi.appspot.com");
v8 = (char *)func12(v7);
puts(v8);
free(v8);
return 0;
}

original_code:
int main() {
 char * request;
 char * request2;
 char * request3;
 char * returned_content1;
 char * returned_content2;
 char * returned_content3;
 request = gh_build_get_query("greenupapi.appspot.com","/api/comments");
 returned_content1 = gh_make_request(request,"greenupapi.appspot.com",_gh_get_ip("greenupapi.appspot.com"),80);
 printf("%s\n", returned_content1 );
 free(returned_content1);
 request2 = gh_build_post_query("greenupapi.appspot.com","api/comments", "{\"type\" : \"forum\", \"message\" : \"Have you guys heard about the free cookies on Pearl St and South Winooski? Bring your green bags down there and get one!\"}");
 returned_content2 = gh_make_request(request2,"greenupapi.appspot.com",_gh_get_ip("greenupapi.appspot.com"),80);
 printf("%s\n", returned_content2 );
 free(returned_content2);
 request3 = gh_build_put_query("greenupapi.appspot.com","api/heatmap","[{\"latDegrees\" : 24.53, \"lonDegrees\" : 43.2, \"secondsWorked\" : 120}]");
 returned_content3 = gh_make_request(request3,"greenupapi.appspot.com",_gh_get_ip("greenupapi.appspot.com"),80);
 printf("%s\n", returned_content3 );
 free(returned_content3);
 return 0;
}

canonical_original_code:
int main() {
 char *request;
 char *request2;
 char *request3;
 char *returned_content1;
 char *returned_content2;
 char *returned_content3;
 request = gh_build_get_query("greenupapi.appspot.com","/api/comments");
 returned_content1 = gh_make_request(request,"greenupapi.appspot.com",_gh_get_ip("greenupapi.appspot.com"),80);
 printf("%s\n", returned_content1 );
 free(returned_content1);
 request2 = gh_build_post_query("greenupapi.appspot.com","api/comments", "{\"type\" : \"forum\", \"message\" : \"Have you guys heard about the free cookies on Pearl St and South Winooski? Bring your green bags down there and get one!\"}");
 returned_content2 = gh_make_request(request2,"greenupapi.appspot.com",_gh_get_ip("greenupapi.appspot.com"),80);
 printf("%s\n", returned_content2 );
 free(returned_content2);
 request3 = gh_build_put_query("greenupapi.appspot.com","api/heatmap","[{\"latDegrees\" : 24.53, \"lonDegrees\" : 43.2, \"secondsWorked\" : 120}]");
 returned_content3 = gh_make_request(request3,"greenupapi.appspot.com",_gh_get_ip("greenupapi.appspot.com"),80);
 printf("%s\n", returned_content3 );
 free(returned_content3);
 return 0;
}

variable_types:
request
char *


inserirAntes

repo: porthunt/memory-management-simulator

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

result = *(_QWORD *)(a2 + 16);
*(_QWORD *)(a2 + 16) = a3;
*(_QWORD *)(a3 + 8) = a2;
*(_QWORD *)(result + 8) = a3;
*(_QWORD *)(a3 + 16) = result;
return result;
}

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

result = *(_QWORD *)(a2 + 16);
*(_QWORD *)(a2 + 16) = a3;
*(_QWORD *)(a3 + 8) = a2;
*(_QWORD *)(result + 8) = a3;
*(_QWORD *)(a3 + 16) = result;
return result;
}

original_code:
void inserirAntes (Lista * lst, No * no, No * novoNo)
{
    No * ant = no->ant;
    no->ant = novoNo;
    novoNo->prox = no;
    ant->prox = novoNo;
    novoNo->ant = ant;
}

canonical_original_code:
void inserirAntes(struct lista *lst, struct no *no, struct no *novoNo)
{
    struct no *ant = no->ant;
    no->ant = novoNo;
    novoNo->prox = no;
    ant->prox = novoNo;
    novoNo->ant = ant;
}

variable_types: struct lista { struct no { struct QuadroPagina { int addrReal; int numQuadro; int R; char M; char MemFisica; } *info; struct no *prox; struct no *ant; } *prim; struct no *ult; int tam; } *

variable_types:
no
struct no *

variable_types:
novoNo
struct no *

user_defined_types: struct lista { struct no *prim; struct no *ult; int tam; }

user_defined_types: struct no { struct QuadroPagina *info; struct no *prox; struct no *ant; }


pegarPorID

decompiled_code:
__int64 __fastcall pegarPorID(__int64 a1, int a2)
{
int v2; // eax
_QWORD *v4; // rdx
int i; // eax

v2 = *(_DWORD *)(a1 + 16);
if ( !v2 )
return 0LL;
if ( v2 <= a2 )
{
printf(format);
exit(0);
}
if ( !a2 )
return **(_QWORD **)a1;
if ( v2 - 1 == a2 )
return **(_QWORD **)(a1 + 8);
v4 = *(_QWORD **)a1;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
v4 = (_QWORD *)v4[1];
}
return *v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
int v2; // eax
_QWORD *v4; // rdx
int i; // eax

v2 = *(_DWORD *)(a1 + 16);
if ( !v2 )
return 0LL;
if ( v2 <= a2 )
{
printf(format);
exit(0);
}
if ( !a2 )
return **(_QWORD **)a1;
if ( v2 - 1 == a2 )
return **(_QWORD **)(a1 + 8);
v4 = *(_QWORD **)a1;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
v4 = (_QWORD *)v4[1];
}
return *v4;
}

original_code:
QuadroPagina* pegarPorID (Lista * lst, int posicao)
{
 QuadroPagina* retorno;
 No * no;
    if (lst->tam == 0)
        retorno = ((void *)0);
    else
  {
        if (posicao >= lst->tam)
        {
            printf("Indice de lista não existente.");
            exit(0);
        }
     if (posicao == 0)
         retorno = lst->prim->info;
     else
   {
          if (posicao == lst->tam-1)
             retorno = lst->ult->info;
          else
          {
             no = lst->prim;
             int i = 0;
             while (i < posicao)
             {
                 no = no->prox;
                 i++;
             }
             retorno= no->info;
          }
    }
    }
  return retorno;
}

canonical_original_code:
struct QuadroPagina *pegarPorID(struct lista *lst, int posicao)
{
 struct QuadroPagina *retorno;
 struct no *no;
    if (lst->tam == 0)
        retorno = ((void *)0);
    else
  {
        if (posicao >= lst->tam)
        {
            printf("Indice de lista não existente.");
            exit(0);
        }
     if (posicao == 0)
         retorno = lst->prim->info;
     else
   {
          if (posicao == lst->tam-1)
             retorno = lst->ult->info;
          else
          {
             no = lst->prim;
             int i = 0;
             while (i < posicao)
             {
                 no = no->prox;
                 i++;
             }
             retorno= no->info;
          }
    }
    }
  return retorno;
}

variable_types: struct lista { struct no { struct QuadroPagina *info; struct no *prox; struct no *ant; } *prim; struct no *ult; int tam; } *

variable_types: posicao int

variable_types: struct no { struct QuadroPagina { int addrReal; int numQuadro; int R; char M; char MemFisica; } *info; struct no *prox; struct no *ant; } *

variable_types: i int


pegarIndiceNo

decompiled_code:
__int64 __fastcall pegarIndiceNo(_QWORD **a1, __int64 a2)
{
_QWORD *v2; // rax
unsigned int v3; // ecx
unsigned int v4; // edx

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

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD **a1, __int64 a2)
{
_QWORD *v2; // rax
unsigned int v3; // ecx
unsigned int v4; // edx

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

original_code:
int pegarIndiceNo(Lista * lst, QuadroPagina* tb)
{
    No * atual = lst->prim;
    int i=0,indice=-1;
    for(; atual!=((void *)0) ; atual = atual->prox)
  {
       if(atual->info==tb)
           indice=i;
   else
   {
    i++;
   }
  }
    return indice;
}

canonical_original_code:
int pegarIndiceNo(struct lista *lst, struct QuadroPagina *tb)
{
    struct no *atual = lst->prim;
    int i = 0; int indice = -1;
    for(; atual!=((void *)0) ; atual = atual->prox)
  {
       if(atual->info==tb)
           indice=i;
   else
   {
    i++;
   }
  }
    return indice;
}

variable_types:
tb
struct QuadroPagina *

variable_types: indice int

user_defined_types: struct QuadroPagina { int addrReal; int numQuadro; int R; char M; char MemFisica; }


removerPrimeiro

original_code:
QuadroPagina* removerPrimeiro (Lista * lst)
{
    No * cabeca = lst->prim;
    QuadroPagina* retorno;
    if (cabeca == ((void *)0))
        retorno = ((void *)0);
    else
  {
     lst->prim = cabeca->prox;
     if (lst->prim != ((void *)0))
         lst->prim->ant = ((void *)0);
   retorno = cabeca->info;
     free(cabeca);
     lst->tam--;
     if (lst->tam <= 1)
         lst->ult = ((void *)0);
  }
    return retorno;
}

canonical_original_code:
struct QuadroPagina *removerPrimeiro(struct lista *lst)
{
    struct no *cabeca = lst->prim;
    struct QuadroPagina *retorno;
    if (cabeca == ((void *)0))
        retorno = ((void *)0);
    else
  {
     lst->prim = cabeca->prox;
     if (lst->prim != ((void *)0))
         lst->prim->ant = ((void *)0);
   retorno = cabeca->info;
     free(cabeca);
     lst->tam--;
     if (lst->tam <= 1)
         lst->ult = ((void *)0);
  }
    return retorno;
}

variable_types: struct QuadroPagina { int addrReal; int numQuadro; int R; char M; char MemFisica; } *


limparLista

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

for ( ; *(int *)(a1 + 16) > 0; result = removerPrimeiro(a1) )
;
return result;
}

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

for ( ; *(int *)(a1 + 16) > 0; result = func4(a1) )
;
return result;
}

original_code:
void limparLista (Lista * lst)
{
    while(lst->tam > 0)
  removerPrimeiro(lst);
}

canonical_original_code:
void limparLista(struct lista *lst)
{
    while(lst->tam > 0)
  removerPrimeiro(lst);
}


removerUltimo

original_code:
QuadroPagina* removerUltimo (Lista * lst)
{
 QuadroPagina * retorno;
   No * cauda = lst->ult;
    if (lst->tam == 0)
        retorno = ((void *)0);
    else
  {
     if (lst->tam == 1)
         retorno = lst->ult->info;
     else
     {
         retorno = cauda->info;
         cauda->ant->prox= ((void *)0);
         if (lst->tam > 1)
             lst->ult = cauda->ant;
         if (lst->tam <= 1)
             lst->ult = ((void *)0);
     lst->tam--;
     }
  }
  return retorno;
}

canonical_original_code:
struct QuadroPagina *removerUltimo(struct lista *lst)
{
 struct QuadroPagina *retorno;
   struct no *cauda = lst->ult;
    if (lst->tam == 0)
        retorno = ((void *)0);
    else
  {
     if (lst->tam == 1)
         retorno = lst->ult->info;
     else
     {
         retorno = cauda->info;
         cauda->ant->prox= ((void *)0);
         if (lst->tam > 1)
             lst->ult = cauda->ant;
         if (lst->tam <= 1)
             lst->ult = ((void *)0);
     lst->tam--;
     }
  }
  return retorno;
}

return_type: struct QuadroPagina { int addrReal; int numQuadro; int R; char M; char MemFisica; } *


removerPorID

decompiled_code:
__int64 __fastcall removerPorID(__int64 a1, int a2)
{
int v2; // eax
__int64 *v4; // rdi
int i; // eax
__int64 v6; // rdx
__int64 v7; // rax
__int64 v8; // rbp

v2 = *(_DWORD *)(a1 + 16);
if ( !v2 )
return 0LL;
if ( v2 <= a2 )
{
puts("LIST: Index out of bound ");
exit(0);
}
if ( !a2 )
return removerPrimeiro(a1);
if ( v2 - 1 == a2 )
return removerUltimo(a1);
v4 = *(__int64 **)a1;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
v4 = (__int64 *)v4[1];
}
v6 = v4[2];
v7 = v4[1];
*(_QWORD *)(v6 + 8) = v7;
*(_QWORD *)(v7 + 16) = v6;
v8 = *v4;
free(v4);
--*(_DWORD *)(a1 + 16);
return v8;
}

original_code:
QuadroPagina* removerPorID (Lista * lst, int posicao)
{
 QuadroPagina * retorno;
 No * node,*ant,*prox;
 int i = 0;
    if (lst->tam == 0)
        retorno = ((void *)0);
    else
 {
        if (posicao >= lst->tam)
        {
            printf("LIST: Index out of bound \n");
            exit(0);
        }
      if (posicao == 0)
          retorno = removerPrimeiro(lst);
     else
  {
         if (posicao == lst->tam-1)
             retorno = removerUltimo(lst);
         else
         {
            node = lst->prim;
             while (i < posicao)
             {
                 node = node->prox;
                 i++;
             }
             ant = node->ant;
             prox = node->prox;
             ant->prox = prox;
             prox->ant = ant;
             retorno = node->info;
             free(node);
             lst->tam--;
       }
  }
   }
 return retorno;
}

canonical_original_code:
struct QuadroPagina *removerPorID(struct lista *lst, int posicao)
{
 struct QuadroPagina *retorno;
 struct no *node; struct no *ant; struct no *prox;
 int i = 0;
    if (lst->tam == 0)
        retorno = ((void *)0);
    else
 {
        if (posicao >= lst->tam)
        {
            printf("LIST: Index out of bound \n");
            exit(0);
        }
      if (posicao == 0)
          retorno = removerPrimeiro(lst);
     else
  {
         if (posicao == lst->tam-1)
             retorno = removerUltimo(lst);
         else
         {
            node = lst->prim;
             while (i < posicao)
             {
                 node = node->prox;
                 i++;
             }
             ant = node->ant;
             prox = node->prox;
             ant->prox = prox;
             prox->ant = ant;
             retorno = node->info;
             free(node);
             lst->tam--;
       }
  }
   }
 return retorno;
}


removerNo

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

v2 = (_QWORD *)*a1;
if ( !*a1 )
return 0LL;
v3 = 0;
result = 0LL;
do
{
if ( *v2 == a2 )
result = removerPorID((__int64)a1, v3);
else
++v3;
v2 = (_QWORD *)v2[1];
}
while ( v2 );
return result;
}

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

v2 = (_QWORD *)*a1;
if ( !*a1 )
return 0LL;
v3 = 0;
result = 0LL;
do
{
if ( *v2 == a2 )
result = func7((__int64)a1, v3);
else
++v3;
v2 = (_QWORD *)v2[1];
}
while ( v2 );
return result;
}

original_code:
QuadroPagina* removerNo(Lista * lst, QuadroPagina* tb)
{
 QuadroPagina* retorno=((void *)0);
   No * atual=lst->prim;
   int i=0;
   for(; atual!=((void *)0) ; atual = atual->prox)
 {
      if(atual->info==tb)
   retorno = removerPorID(lst, i);
  else
  {
   i++;
  }
 }
   return retorno ;
}

canonical_original_code:
struct QuadroPagina *removerNo(struct lista *lst, struct QuadroPagina *tb)
{
 struct QuadroPagina *retorno = ((void *)0);
   struct no *atual = lst->prim;
   int i = 0;
   for(; atual!=((void *)0) ; atual = atual->prox)
 {
      if(atual->info==tb)
   retorno = removerPorID(lst, i);
  else
  {
   i++;
  }
 }
   return retorno ;
}


colocar

decompiled_code:
__int64 __fastcall colocar(int a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax

*(_QWORD *)(memVirtual + 8LL * a1) = a2;
v2 = memVirtual + 8LL * a1;
*(_DWORD *)(*(_QWORD *)v2 + 8LL) = 0;
*(_BYTE *)(*(_QWORD *)v2 + 12LL) = 0;
*(_BYTE *)(*(_QWORD *)v2 + 13LL) = 1;
result = (unsigned int)TAM_PAG;
memOcupada += TAM_PAG;
return result;
}

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

*(_QWORD *)(memVirtual + 8LL * a1) = a2;
v2 = memVirtual + 8LL * a1;
*(_DWORD *)(*(_QWORD *)v2 + 8LL) = 0;
*(_BYTE *)(*(_QWORD *)v2 + 12LL) = 0;
*(_BYTE *)(*(_QWORD *)v2 + 13LL) = 1;
result = (unsigned int)TAM_PAG;
memOcupada += TAM_PAG;
return result;
}

original_code:
void colocar(int quadro, QuadroPagina * criarPagina)
{
  memVirtual[quadro] = criarPagina;
    memVirtual[quadro]->R = 0;
    memVirtual[quadro]->M = 0;
    memVirtual[quadro]->MemFisica = 1;
    memOcupada = memOcupada + TAM_PAG;
}

canonical_original_code:
void colocar(int quadro, struct QuadroPagina *criarPagina)
{
  memVirtual[quadro] = criarPagina;
    memVirtual[quadro]->R = 0;
    memVirtual[quadro]->M = 0;
    memVirtual[quadro]->MemFisica = 1;
    memOcupada = memOcupada + TAM_PAG;
}

variable_types: quadro int


retirar

decompiled_code:
void **__fastcall retirar(int a1, int a2)
{
void **result; // rax

result = (void **)(memVirtual + 8LL * a1);
if ( *result )
{
Relatorio[a2 + 6] += *((char *)*result + 12);
++Relatorio[a2 + 4];
*((_BYTE *)*result + 12) = 0;
*((_BYTE *)*result + 13) = 0;
free(*result);
*(_QWORD *)(memVirtual + 8LL * a1) = 0LL;
result = (void **)(unsigned int)TAM_PAG;
memOcupada -= TAM_PAG;
}
return result;
}

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

result = (void **)(memVirtual + 8LL * a1);
if ( *result )
{
Relatorio[a2 + 6] += *((char *)*result + 12);
++Relatorio[a2 + 4];
*((_BYTE *)*result + 12) = 0;
*((_BYTE *)*result + 13) = 0;
free(*result);
*(_QWORD *)(memVirtual + 8LL * a1) = 0LL;
result = (void **)(unsigned int)TAM_PAG;
memOcupada -= TAM_PAG;
}
return result;
}

original_code:
void retirar(int quadro, int tipo)
{
   if(memVirtual[quadro] != ((void *)0))
   {
      Relatorio.Sujas[tipo]+=memVirtual[quadro]->M;
      Relatorio.Trocas[tipo]++;
      memVirtual[quadro]->M = 0;
      memVirtual[quadro]->MemFisica = 0;
      free(memVirtual[quadro]);
      memVirtual[quadro] = ((void *)0);
      memOcupada -= TAM_PAG;
   }
 }

variable_types: tipo int


decompiled_code:
__int64 __fastcall ts_lua_decode_base64(_BYTE *a1, _QWORD *a2, unsigned __int8 *a3, unsigned __int64 a4)
{
return ts_lua_decode_base64_internal(a1, a2, a3, a4, (__int64)basis64_7);
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, _QWORD *a2, unsigned __int8 *a3, unsigned __int64 a4)
{
return func0(a1, a2, a3, a4, (__int64)basis64_7);
}

variable_types:
dst
unsigned char *

variable_types:
src
unsigned char *


original_code:
uintptr_t
ts_lua_escape_internal(u_char *dst, u_char *src, size_t size, int type)
{
    uint32_t n;
    uint32_t *escape;
    static u_char hex[] = "0123456789abcdef";
    static uint32_t uri[] = {
        0xffffffff,
        0xfc00886d,
        0x78000000,
        0xa8000000,
        0xffffffff,
        0xffffffff,
        0xffffffff,
        0xffffffff
    };
    static uint32_t args[] = {
        0xffffffff,
        0x80000829,
        0x00000000,
        0x80000000,
        0xffffffff,
        0xffffffff,
        0xffffffff,
        0xffffffff
    };
    static uint32_t html[] = {
        0xffffffff,
        0x000000ad,
        0x00000000,
        0x80000000,
        0xffffffff,
        0xffffffff,
        0xffffffff,
        0xffffffff
    };
    static uint32_t refresh[] = {
        0xffffffff,
        0x00000085,
        0x00000000,
        0x80000000,
        0xffffffff,
        0xffffffff,
        0xffffffff,
        0xffffffff
    };
    static uint32_t memcached[] = {
        0xffffffff,
        0x00000021,
        0x00000000,
        0x00000000,
        0x00000000,
        0x00000000,
        0x00000000,
        0x00000000,
    };
    static uint32_t *map[] =
        { uri, args, html, refresh, memcached, memcached };
    escape = map[type];
    if (dst == ((void *)0)) {
        n = 0;
        while (size) {
            if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
                n++;
            }
            src++;
            size--;
        }
        return (uintptr_t) n;
    }
    while (size) {
        if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
            *dst++ = '%';
            *dst++ = hex[*src >> 4];
            *dst++ = hex[*src & 0xf];
            src++;
        } else {
            *dst++ = *src++;
        }
        size--;
    }
    return (uintptr_t) dst;
}

canonical_original_code:
unsigned long ts_lua_escape_internal(unsigned char *dst, unsigned char *src, unsigned long size, int type)
{
    unsigned int n;
    unsigned int *escape;
    static unsigned char hex[] = "0123456789abcdef";
    static unsigned int uri[] = {
        0xffffffff,
        0xfc00886d,
        0x78000000,
        0xa8000000,
        0xffffffff,
        0xffffffff,
        0xffffffff,
        0xffffffff
    };
    static unsigned int args[] = {
        0xffffffff,
        0x80000829,
        0x00000000,
        0x80000000,
        0xffffffff,
        0xffffffff,
        0xffffffff,
        0xffffffff
    };
    static unsigned int html[] = {
        0xffffffff,
        0x000000ad,
        0x00000000,
        0x80000000,
        0xffffffff,
        0xffffffff,
        0xffffffff,
        0xffffffff
    };
    static unsigned int refresh[] = {
        0xffffffff,
        0x00000085,
        0x00000000,
        0x80000000,
        0xffffffff,
        0xffffffff,
        0xffffffff,
        0xffffffff
    };
    static unsigned int memcached[] = {
        0xffffffff,
        0x00000021,
        0x00000000,
        0x00000000,
        0x00000000,
        0x00000000,
        0x00000000,
        0x00000000,
    };
    static unsigned int *map[] = { uri, args, html, refresh, memcached, memcached };
    escape = map[type];
    if (dst == ((void *)0)) {
        n = 0;
        while (size) {
            if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
                n++;
            }
            src++;
            size--;
        }
        return (unsigned long) n;
    }
    while (size) {
        if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
            *dst++ = '%';
            *dst++ = hex[*src >> 4];
            *dst++ = hex[*src & 0xf];
            src++;
        } else {
            *dst++ = *src++;
        }
        size--;
    }
    return (unsigned long) dst;
}

variable_types:
size
unsigned long

variable_types: type int

variable_types:
n
unsigned int

variable_types:
escape
unsigned int *

variable_types:
hex
unsigned char []

variable_types:
uri
unsigned int []

variable_types:
args
unsigned int []

variable_types:
html
unsigned int []

variable_types:
refresh
unsigned int []

variable_types:
memcached
unsigned int []

variable_types:
map
unsigned int *[]

return_type: unsigned long


original_code:
void
ts_lua_unescape_internal(u_char **dst, u_char **src, size_t size, int type)
{
    u_char *d, *s, ch, c, decoded;
    enum {
        sw_usual = 0,
        sw_quoted,
        sw_quoted_second
    } state;
    d = *dst;
    s = *src;
    state = 0;
    decoded = 0;
    while (size--) {
        ch = *s++;
        switch (state) {
        case sw_usual:
            if (ch == '?'
                && (type & (1|2)))
            {
                *d++ = ch;
                goto done;
            }
            if (ch == '%') {
                state = sw_quoted;
                break;
            }
            if (ch == '+') {
                *d++ = ' ';
                break;
            }
            *d++ = ch;
            break;
        case sw_quoted:
            if (ch >= '0' && ch <= '9') {
                decoded = (u_char) (ch - '0');
                state = sw_quoted_second;
                break;
            }
            c = (u_char) (ch | 0x20);
            if (c >= 'a' && c <= 'f') {
                decoded = (u_char) (c - 'a' + 10);
                state = sw_quoted_second;
                break;
            }
            state = sw_usual;
            *d++ = ch;
            break;
        case sw_quoted_second:
            state = sw_usual;
            if (ch >= '0' && ch <= '9') {
                ch = (u_char) ((decoded << 4) + ch - '0');
                if (type & 2) {
                    if (ch > '%' && ch < 0x7f) {
                        *d++ = ch;
                        break;
                    }
                    *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1);
                    break;
                }
                *d++ = ch;
                break;
            }
            c = (u_char) (ch | 0x20);
            if (c >= 'a' && c <= 'f') {
                ch = (u_char) ((decoded << 4) + c - 'a' + 10);
                if (type & 1) {
                    if (ch == '?') {
                        *d++ = ch;
                        goto done;
                    }
                    *d++ = ch;
                    break;
                }
                if (type & 2) {
                    if (ch == '?') {
                        *d++ = ch;
                        goto done;
                    }
                    if (ch > '%' && ch < 0x7f) {
                        *d++ = ch;
                        break;
                    }
                    *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1);
                    break;
                }
                *d++ = ch;
                break;
            }
            break;
        }
    }
done:
    *dst = d;
    *src = s;
}

canonical_original_code:
void ts_lua_unescape_internal(unsigned char **dst, unsigned char **src, unsigned long size, int type)
{
    unsigned char *d; unsigned char *s; unsigned char ch; unsigned char c; unsigned char decoded;
    enum { sw_usual=0, sw_quoted=1, sw_quoted_second=2 } state;
    d = *dst;
    s = *src;
    state = 0;
    decoded = 0;
    while (size--) {
        ch = *s++;
        switch (state) {
        case sw_usual:
            if (ch == '?'
                && (type & (1|2)))
            {
                *d++ = ch;
                goto done;
            }
            if (ch == '%') {
                state = sw_quoted;
                break;
            }
            if (ch == '+') {
                *d++ = ' ';
                break;
            }
            *d++ = ch;
            break;
        case sw_quoted:
            if (ch >= '0' && ch <= '9') {
                decoded = (u_char) (ch - '0');
                state = sw_quoted_second;
                break;
            }
            c = (u_char) (ch | 0x20);
            if (c >= 'a' && c <= 'f') {
                decoded = (u_char) (c - 'a' + 10);
                state = sw_quoted_second;
                break;
            }
            state = sw_usual;
            *d++ = ch;
            break;
        case sw_quoted_second:
            state = sw_usual;
            if (ch >= '0' && ch <= '9') {
                ch = (u_char) ((decoded << 4) + ch - '0');
                if (type & 2) {
                    if (ch > '%' && ch < 0x7f) {
                        *d++ = ch;
                        break;
                    }
                    *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1);
                    break;
                }
                *d++ = ch;
                break;
            }
            c = (u_char) (ch | 0x20);
            if (c >= 'a' && c <= 'f') {
                ch = (u_char) ((decoded << 4) + c - 'a' + 10);
                if (type & 1) {
                    if (ch == '?') {
                        *d++ = ch;
                        goto done;
                    }
                    *d++ = ch;
                    break;
                }
                if (type & 2) {
                    if (ch == '?') {
                        *d++ = ch;
                        goto done;
                    }
                    if (ch > '%' && ch < 0x7f) {
                        *d++ = ch;
                        break;
                    }
                    *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1);
                    break;
                }
                *d++ = ch;
                break;
            }
            break;
        }
    }
done:
    *dst = d;
    *src = s;
}

variable_types:
dst
unsigned char **

variable_types:
src
unsigned char **

variable_types:
d
unsigned char *

variable_types:
s
unsigned char *

variable_types:
ch
unsigned char

variable_types:
c
unsigned char

variable_types:
decoded
unsigned char


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

if ( *(_DWORD *)a2 == 2 )
{
v3 = *(_DWORD **)(a2 + 8);
if ( *v3 )
{
strcpy(a3, "jfget() requires a string for first argument");
result = 1LL;
}
else if ( v3[1] )
{
strcpy(a3, "jfget() requires a string for second argument");
result = 1LL;
}
else
{
**(_BYTE **)(a2 + 32) = 0;
*(_BYTE *)(*(_QWORD *)(a2 + 32) + 1LL) = 0;
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
}
}
else
{
strcpy(a3, "jfget() requires two arguments");
result = 1LL;
}
return result;
}

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

if ( *(_DWORD *)a2 == 2 )
{
v3 = *(_DWORD **)(a2 + 8);
if ( *v3 )
{
strcpy(a3, "jfget() requires a string for first argument");
result = 1LL;
}
else if ( v3[1] )
{
strcpy(a3, "jfget() requires a string for second argument");
result = 1LL;
}
else
{
**(_BYTE **)(a2 + 32) = 0;
*(_BYTE *)(*(_QWORD *)(a2 + 32) + 1LL) = 0;
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
}
}
else
{
strcpy(a3, "jfget() requires two arguments");
result = 1LL;
}
return result;
}

original_code:
my_bool
jfget_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
 if (args->arg_count != 2) {
  strcpy(message, "jfget() requires two arguments");
  return 1;
 }
 if (args->arg_type[0] != STRING_RESULT) {
  strcpy(message, "jfget() requires a string for first argument");
  return 1;
 }
 if (args->arg_type[1] != STRING_RESULT) {
  strcpy(message, "jfget() requires a string for second argument");
  return 1;
 }
 args->maybe_null[0] = 0;
 args->maybe_null[1] = 0;
 initid->ptr = ((void *)0);
 return 0;
}

canonical_original_code:
char jfget_init(struct st_udf_init *initid, struct st_udf_args *args, char *message)
{
 if (args->arg_count != 2) {
  strcpy(message, "jfget() requires two arguments");
  return 1;
 }
 if (args->arg_type[0] != STRING_RESULT) {
  strcpy(message, "jfget() requires a string for first argument");
  return 1;
 }
 if (args->arg_type[1] != STRING_RESULT) {
  strcpy(message, "jfget() requires a string for second argument");
  return 1;
 }
 args->maybe_null[0] = 0;
 args->maybe_null[1] = 0;
 initid->ptr = ((void *)0);
 return 0;
}

variable_types: struct st_udf_init { char maybe_null; unsigned int decimals; unsigned int max_length; char *ptr; char const_item; } *

variable_types: struct st_udf_args { unsigned int arg_count; enum Item_result { STRING_RESULT=0, REAL_RESULT=1, INT_RESULT=2, ROW_RESULT=3, DECIMAL_RESULT=4 } *arg_type; char **args; unsigned long *lengths; char *maybe_null; } *

variable_types:
message
char *

return_type: char

user_defined_types: struct st_udf_args { unsigned int arg_count; enum Item_result *arg_type; char **args; unsigned long *lengths; char *maybe_null; }