yyparse

original_code:
int
yyparse (void)
{
    int yystate;
    int yyerrstatus;
    yytype_int16 yyssa[200];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;
    YYSTYPE yyvsa[200];
    YYSTYPE *yyvs;
    YYSTYPE *yyvsp;
    long unsigned int yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  YYSTYPE 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 (YYSTYPE)) + (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 == 40)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-71))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 285 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 134 < 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 4:
    {
                    INSTRUCTION_LIST list;
                    list = createInstructionList();
                    if (list == 0)
                    {
                      exit(1);
                    }
                    addInstruction(list, (yyvsp[0].instruction));
                    (yyval.instruction_list) = list;
                  }
    break;
  case 5:
    {
                       INSTRUCTION_LIST list = (yyvsp[-1].instruction_list);
                       addInstruction(list, (yyvsp[0].instruction));
                       (yyval.instruction_list) = list;
                     }
    break;
  case 14:
    {
                (yyval.instruction_list) = (yyvsp[-1].instruction_list);
              }
    break;
  case 15:
    {
                  printf("Skip instruction\n");
                  INSTRUCTION instruction = createSkipInstruction();
                  if (instruction == 0)
                  {
                    exit(1);
                  }
                }
    break;
  case 16:
    {
                  printf("Read instruction for label <%s>\n", (yyvsp[-1].string));
                  printf(">> CONST %s\n", (yyvsp[-1].string));
                  printf(">> SWAPA\n");
                  printf(">> READ\n");
                  printf(">> STORE\n");
                  VARIABLE_TYPE label = createVariable((yyvsp[-1].string));
                  if (label == 0)
                  {
                    exit(1);
                  }
                  INSTRUCTION instruction = createReadInstruction(label);
                  if (instruction == 0)
                  {
                    exit(1);
                  }
                  (yyval.instruction) = instruction;
                }
    break;
  case 17:
    {
                   printf("Write instruction\n");
                   printf(">> WRITE\n");
                   INSTRUCTION instruction = createWriteInstruction((yyvsp[-1].arithmetic_expression_type));
                   if (instruction == 0)
                   {
                     exit(1);
                   }
                   (yyval.instruction) = instruction;
                 }
    break;
  case 18:
    {
                    printf("Assign instruction for label <%s>\n", (yyvsp[-3].string));
                    printf(">> SWAPD\n");
                    printf(">> CONST %s\n", (yyvsp[-3].string));
                    printf(">> SWAPA\n");
                    printf(">> SWAPD\n");
                    printf(">> STORE\n");
                    VARIABLE_TYPE label = createVariable((yyvsp[-3].string));
                    if (label == 0)
                    {
                      exit(1);
                    }
                    INSTRUCTION instruction = createAssignInstruction(label, (yyvsp[-1].arithmetic_expression_type));
                    if (instruction == 0)
                    {
                      exit(1);
                    }
                    (yyval.instruction) = instruction;
                  }
    break;
  case 19:
    {
              printf("If instruction\n");
            }
    break;
  case 20:
    {
                   printf("If-else instruction\n");
                 }
    break;
  case 21:
    {
                 printf("While instruction\n");
               }
    break;
  case 25:
    {
                            printf("Complete if-else instruction\n");
                          }
    break;
  case 26:
    {
                          printf("Complete while instruction\n");
                        }
    break;
  case 29:
    {
                         INSTRUCTION_LIST list;
                         list = createInstructionList();
                         if (list == 0)
                         {
                           exit(1);
                         }
                         addInstruction(list, (yyvsp[0].instruction));
                         (yyval.instruction_list) = list;
                       }
    break;
  case 32:
    {
                                  INSTRUCTION_LIST list;
                                  list = createInstructionList();
                                  if (list == 0)
                                  {
                                    exit(1);
                                  }
                                  addInstruction(list, (yyvsp[0].instruction));
                                  (yyval.instruction_list) = list;
                                }
    break;
  case 37:
    {
                              (yyval.arithmetic_expression_type) = (yyvsp[-1].arithmetic_expression_type);
                            }
    break;
  case 38:
    {
              printf("Factor with label <%s> loaded\n", (yyvsp[0].string));
              printf(">> CONST %s\n", (yyvsp[0].string));
              printf(">> SWAPA\n");
              printf(">> LOAD\n");
            }
    break;
  case 39:
    {
               printf("Factor with value <%d> loaded\n", (yyvsp[0].number));
               printf(">> CONST %d\n", (yyvsp[0].number));
             }
    break;
  case 40:
    {
                 printf("Negative factor loaded\n");
                 printf(">> CONST -%d\n", (yyvsp[0].number));
               }
    break;
  case 45:
    {
               printf("Mul operation loaded\n");
             }
    break;
  case 46:
    {
               printf("Div operation loaded\n");
             }
    break;
  case 47:
    {
               printf("Mod operation loaded\n");
             }
    break;
  case 51:
    {
               printf("Add operation loaded\n");
             }
    break;
  case 52:
    {
               printf("Sub operation loaded\n");
             }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 31;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 134 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 285 ? 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) == (-71))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 134 && 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) <= 285 ? 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;
    union YYSTYPE yyvsa[200];
    union YYSTYPE *yyvs;
    union YYSTYPE *yyvsp;
    unsigned long yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  union YYSTYPE 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 (YYSTYPE)) + (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 == 40)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-71))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 285 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 134 < 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 4:
    {
                    struct _T_INSTRUCTION_LIST *list;
                    list = createInstructionList();
                    if (list == 0)
                    {
                      exit(1);
                    }
                    addInstruction(list, (yyvsp[0].instruction));
                    (yyval.instruction_list) = list;
                  }
    break;
  case 5:
    {
                       struct _T_INSTRUCTION_LIST *list = (yyvsp[-1].instruction_list);
                       addInstruction(list, (yyvsp[0].instruction));
                       (yyval.instruction_list) = list;
                     }
    break;
  case 14:
    {
                (yyval.instruction_list) = (yyvsp[-1].instruction_list);
              }
    break;
  case 15:
    {
                  printf("Skip instruction\n");
                  struct T_INSTRUCTION *instruction = createSkipInstruction();
                  if (instruction == 0)
                  {
                    exit(1);
                  }
                }
    break;
  case 16:
    {
                  printf("Read instruction for label <%s>\n", (yyvsp[-1].string));
                  printf(">> CONST %s\n", (yyvsp[-1].string));
                  printf(">> SWAPA\n");
                  printf(">> READ\n");
                  printf(">> STORE\n");
                  struct T_VARIABLE_TYPE *label = createVariable((yyvsp[-1].string));
                  if (label == 0)
                  {
                    exit(1);
                  }
                  struct T_INSTRUCTION *instruction = createReadInstruction(label);
                  if (instruction == 0)
                  {
                    exit(1);
                  }
                  (yyval.instruction) = instruction;
                }
    break;
  case 17:
    {
                   printf("Write instruction\n");
                   printf(">> WRITE\n");
                   struct T_INSTRUCTION *instruction = createWriteInstruction((yyvsp[-1].arithmetic_expression_type));
                   if (instruction == 0)
                   {
                     exit(1);
                   }
                   (yyval.instruction) = instruction;
                 }
    break;
  case 18:
    {
                    printf("Assign instruction for label <%s>\n", (yyvsp[-3].string));
                    printf(">> SWAPD\n");
                    printf(">> CONST %s\n", (yyvsp[-3].string));
                    printf(">> SWAPA\n");
                    printf(">> SWAPD\n");
                    printf(">> STORE\n");
                    struct T_VARIABLE_TYPE *label = createVariable((yyvsp[-3].string));
                    if (label == 0)
                    {
                      exit(1);
                    }
                    struct T_INSTRUCTION *instruction = createAssignInstruction(label, (yyvsp[-1].arithmetic_expression_type));
                    if (instruction == 0)
                    {
                      exit(1);
                    }
                    (yyval.instruction) = instruction;
                  }
    break;
  case 19:
    {
              printf("If instruction\n");
            }
    break;
  case 20:
    {
                   printf("If-else instruction\n");
                 }
    break;
  case 21:
    {
                 printf("While instruction\n");
               }
    break;
  case 25:
    {
                            printf("Complete if-else instruction\n");
                          }
    break;
  case 26:
    {
                          printf("Complete while instruction\n");
                        }
    break;
  case 29:
    {
                         struct _T_INSTRUCTION_LIST *list;
                         list = createInstructionList();
                         if (list == 0)
                         {
                           exit(1);
                         }
                         addInstruction(list, (yyvsp[0].instruction));
                         (yyval.instruction_list) = list;
                       }
    break;
  case 32:
    {
                                  struct _T_INSTRUCTION_LIST *list;
                                  list = createInstructionList();
                                  if (list == 0)
                                  {
                                    exit(1);
                                  }
                                  addInstruction(list, (yyvsp[0].instruction));
                                  (yyval.instruction_list) = list;
                                }
    break;
  case 37:
    {
                              (yyval.arithmetic_expression_type) = (yyvsp[-1].arithmetic_expression_type);
                            }
    break;
  case 38:
    {
              printf("Factor with label <%s> loaded\n", (yyvsp[0].string));
              printf(">> CONST %s\n", (yyvsp[0].string));
              printf(">> SWAPA\n");
              printf(">> LOAD\n");
            }
    break;
  case 39:
    {
               printf("Factor with value <%d> loaded\n", (yyvsp[0].number));
               printf(">> CONST %d\n", (yyvsp[0].number));
             }
    break;
  case 40:
    {
                 printf("Negative factor loaded\n");
                 printf(">> CONST -%d\n", (yyvsp[0].number));
               }
    break;
  case 45:
    {
               printf("Mul operation loaded\n");
             }
    break;
  case 46:
    {
               printf("Div operation loaded\n");
             }
    break;
  case 47:
    {
               printf("Mod operation loaded\n");
             }
    break;
  case 51:
    {
               printf("Add operation loaded\n");
             }
    break;
  case 52:
    {
               printf("Sub operation loaded\n");
             }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 31;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 134 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 285 ? 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) == (-71))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 134 && 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) <= 285 ? 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: union YYSTYPE { char *string; int number; struct T_INSTRUCTION { enum INSTRUCTION_TYPE { INSTRUCTION_SKIP=0, INSTRUCTION_READ=1, INSTRUCTION_WRITE=2, INSTRUCTION_ASSIGN=3, INSTRUCTION_IF=4, INSTRUCTION_WHILE=5 } type; union { struct INSTRUCTION_READ_PARAMS { struct T_VARIABLE_TYPE { enum VARIABLE_ENTRY_TYPE { CONST_VARIABLE=0, MUTABLE_VARIABLE=1 } type; union { char *variable_name; int variable_value; }; } *variable; } read_params; struct INSTRUCTION_WRITE_PARAMS { struct _T_ARITHMETIC_EXPRESSION { enum ARITHMETIC_EXPRESSION_ENTRY_TYPE { SIMPLE_ARITHMETIC_EXPRESSION=0, COMPOSITE_ARITHMETIC_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum ARITHMETIC_OPERATION { ARITHMETIC_ADD=0, ARITHMETIC_SUB=1, ARITHMETIC_MUL=2, ARITHMETIC_DIV=3, ARITHMETIC_MOD=4 } operation; struct _T_ARITHMETIC_EXPRESSION *param1; struct _T_ARITHMETIC_EXPRESSION *param2; }; }; } *expression; } write_params; struct INSTRUCTION_ASSIGN_PARAMS { struct T_VARIABLE_TYPE *variable; struct _T_ARITHMETIC_EXPRESSION *expression; } assign_params; struct INSTRUCTION_IF_PARAMS { struct _T_LOGICAL_EXPRESSION { enum LOGICAL_EXPRESSION_ENTRY_TYPE { SIMPLE_LOGICAL_EXPRESSION=0, COMPOSITE_LOGICAL_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum LOGICAL_OPERATION { LOGICAL_TRUE=0, LOGICAL_FALSE=1, LOGICAL_NOT=2, LOGICAL_AND=3, LOGICAL_OR=4 } operation; struct _T_LOGICAL_EXPRESSION *param1; struct _T_LOGICAL_EXPRESSION *param2; }; }; } *expression; struct _T_INSTRUCTION_LIST { struct _T_INSTRUCTION_LIST_ENTRY { struct T_INSTRUCTION *instruction; struct _T_INSTRUCTION_LIST_ENTRY *next; } *first; struct _T_INSTRUCTION_LIST_ENTRY *last; } *nested_true_code_block; struct _T_INSTRUCTION_LIST *nested_false_code_block; } if_params; struct INSTRUCTION_WHILE_PARAMS { struct _T_LOGICAL_EXPRESSION *expression; struct _T_INSTRUCTION_LIST *nested_code_block; } while_params; }; } *instruction; struct _T_INSTRUCTION_LIST *instruction_list; struct _T_ARITHMETIC_EXPRESSION *arithmetic_expression_type; } [200]

variable_types: union YYSTYPE { char *string; int number; struct T_INSTRUCTION { enum INSTRUCTION_TYPE { INSTRUCTION_SKIP=0, INSTRUCTION_READ=1, INSTRUCTION_WRITE=2, INSTRUCTION_ASSIGN=3, INSTRUCTION_IF=4, INSTRUCTION_WHILE=5 } type; union { struct INSTRUCTION_READ_PARAMS { struct T_VARIABLE_TYPE { enum VARIABLE_ENTRY_TYPE { CONST_VARIABLE=0, MUTABLE_VARIABLE=1 } type; union { char *variable_name; int variable_value; }; } *variable; } read_params; struct INSTRUCTION_WRITE_PARAMS { struct _T_ARITHMETIC_EXPRESSION { enum ARITHMETIC_EXPRESSION_ENTRY_TYPE { SIMPLE_ARITHMETIC_EXPRESSION=0, COMPOSITE_ARITHMETIC_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum ARITHMETIC_OPERATION { ARITHMETIC_ADD=0, ARITHMETIC_SUB=1, ARITHMETIC_MUL=2, ARITHMETIC_DIV=3, ARITHMETIC_MOD=4 } operation; struct _T_ARITHMETIC_EXPRESSION *param1; struct _T_ARITHMETIC_EXPRESSION *param2; }; }; } *expression; } write_params; struct INSTRUCTION_ASSIGN_PARAMS { struct T_VARIABLE_TYPE *variable; struct _T_ARITHMETIC_EXPRESSION *expression; } assign_params; struct INSTRUCTION_IF_PARAMS { struct _T_LOGICAL_EXPRESSION { enum LOGICAL_EXPRESSION_ENTRY_TYPE { SIMPLE_LOGICAL_EXPRESSION=0, COMPOSITE_LOGICAL_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum LOGICAL_OPERATION { LOGICAL_TRUE=0, LOGICAL_FALSE=1, LOGICAL_NOT=2, LOGICAL_AND=3, LOGICAL_OR=4 } operation; struct _T_LOGICAL_EXPRESSION *param1; struct _T_LOGICAL_EXPRESSION *param2; }; }; } *expression; struct _T_INSTRUCTION_LIST { struct _T_INSTRUCTION_LIST_ENTRY { struct T_INSTRUCTION *instruction; struct _T_INSTRUCTION_LIST_ENTRY *next; } *first; struct _T_INSTRUCTION_LIST_ENTRY *last; } *nested_true_code_block; struct _T_INSTRUCTION_LIST *nested_false_code_block; } if_params; struct INSTRUCTION_WHILE_PARAMS { struct _T_LOGICAL_EXPRESSION *expression; struct _T_INSTRUCTION_LIST *nested_code_block; } while_params; }; } *instruction; struct _T_INSTRUCTION_LIST *instruction_list; struct _T_ARITHMETIC_EXPRESSION *arithmetic_expression_type; } *

variable_types:
yystacksize
unsigned long

variable_types: yyn int

variable_types: yyresult int

variable_types: yytoken int

variable_types: yylen int

variable_types:
yysize
unsigned long

variable_types: union yyalloc { short yyss_alloc; union YYSTYPE { char *string; int number; struct T_INSTRUCTION { enum INSTRUCTION_TYPE { INSTRUCTION_SKIP=0, INSTRUCTION_READ=1, INSTRUCTION_WRITE=2, INSTRUCTION_ASSIGN=3, INSTRUCTION_IF=4, INSTRUCTION_WHILE=5 } type; union { struct INSTRUCTION_READ_PARAMS { struct T_VARIABLE_TYPE { enum VARIABLE_ENTRY_TYPE { CONST_VARIABLE=0, MUTABLE_VARIABLE=1 } type; union { char *variable_name; int variable_value; }; } *variable; } read_params; struct INSTRUCTION_WRITE_PARAMS { struct _T_ARITHMETIC_EXPRESSION { enum ARITHMETIC_EXPRESSION_ENTRY_TYPE { SIMPLE_ARITHMETIC_EXPRESSION=0, COMPOSITE_ARITHMETIC_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum ARITHMETIC_OPERATION { ARITHMETIC_ADD=0, ARITHMETIC_SUB=1, ARITHMETIC_MUL=2, ARITHMETIC_DIV=3, ARITHMETIC_MOD=4 } operation; struct _T_ARITHMETIC_EXPRESSION *param1; struct _T_ARITHMETIC_EXPRESSION *param2; }; }; } *expression; } write_params; struct INSTRUCTION_ASSIGN_PARAMS { struct T_VARIABLE_TYPE *variable; struct _T_ARITHMETIC_EXPRESSION *expression; } assign_params; struct INSTRUCTION_IF_PARAMS { struct _T_LOGICAL_EXPRESSION { enum LOGICAL_EXPRESSION_ENTRY_TYPE { SIMPLE_LOGICAL_EXPRESSION=0, COMPOSITE_LOGICAL_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum LOGICAL_OPERATION { LOGICAL_TRUE=0, LOGICAL_FALSE=1, LOGICAL_NOT=2, LOGICAL_AND=3, LOGICAL_OR=4 } operation; struct _T_LOGICAL_EXPRESSION *param1; struct _T_LOGICAL_EXPRESSION *param2; }; }; } *expression; struct _T_INSTRUCTION_LIST { struct _T_INSTRUCTION_LIST_ENTRY { struct T_INSTRUCTION *instruction; struct _T_INSTRUCTION_LIST_ENTRY *next; } *first; struct _T_INSTRUCTION_LIST_ENTRY *last; } *nested_true_code_block; struct _T_INSTRUCTION_LIST *nested_false_code_block; } if_params; struct INSTRUCTION_WHILE_PARAMS { struct _T_LOGICAL_EXPRESSION *expression; struct _T_INSTRUCTION_LIST *nested_code_block; } while_params; }; } *instruction; struct _T_INSTRUCTION_LIST *instruction_list; struct _T_ARITHMETIC_EXPRESSION *arithmetic_expression_type; } yyvs_alloc; } *

variable_types:
yynewbytes
unsigned long

variable_types: struct _T_INSTRUCTION_LIST { struct _T_INSTRUCTION_LIST_ENTRY { struct T_INSTRUCTION { enum INSTRUCTION_TYPE { INSTRUCTION_SKIP=0, INSTRUCTION_READ=1, INSTRUCTION_WRITE=2, INSTRUCTION_ASSIGN=3, INSTRUCTION_IF=4, INSTRUCTION_WHILE=5 } type; union { struct INSTRUCTION_READ_PARAMS { struct T_VARIABLE_TYPE { enum VARIABLE_ENTRY_TYPE { CONST_VARIABLE=0, MUTABLE_VARIABLE=1 } type; union { char *variable_name; int variable_value; }; } *variable; } read_params; struct INSTRUCTION_WRITE_PARAMS { struct _T_ARITHMETIC_EXPRESSION { enum ARITHMETIC_EXPRESSION_ENTRY_TYPE { SIMPLE_ARITHMETIC_EXPRESSION=0, COMPOSITE_ARITHMETIC_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum ARITHMETIC_OPERATION { ARITHMETIC_ADD=0, ARITHMETIC_SUB=1, ARITHMETIC_MUL=2, ARITHMETIC_DIV=3, ARITHMETIC_MOD=4 } operation; struct _T_ARITHMETIC_EXPRESSION *param1; struct _T_ARITHMETIC_EXPRESSION *param2; }; }; } *expression; } write_params; struct INSTRUCTION_ASSIGN_PARAMS { struct T_VARIABLE_TYPE *variable; struct _T_ARITHMETIC_EXPRESSION *expression; } assign_params; struct INSTRUCTION_IF_PARAMS { struct _T_LOGICAL_EXPRESSION { enum LOGICAL_EXPRESSION_ENTRY_TYPE { SIMPLE_LOGICAL_EXPRESSION=0, COMPOSITE_LOGICAL_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum LOGICAL_OPERATION { LOGICAL_TRUE=0, LOGICAL_FALSE=1, LOGICAL_NOT=2, LOGICAL_AND=3, LOGICAL_OR=4 } operation; struct _T_LOGICAL_EXPRESSION *param1; struct _T_LOGICAL_EXPRESSION *param2; }; }; } *expression; struct _T_INSTRUCTION_LIST *nested_true_code_block; struct _T_INSTRUCTION_LIST *nested_false_code_block; } if_params; struct INSTRUCTION_WHILE_PARAMS { struct _T_LOGICAL_EXPRESSION *expression; struct _T_INSTRUCTION_LIST *nested_code_block; } while_params; }; } *instruction; struct _T_INSTRUCTION_LIST_ENTRY *next; } *first; struct _T_INSTRUCTION_LIST_ENTRY *last; } *

variable_types: yylhs int

variable_types: yyi int

user_defined_types: union YYSTYPE { char *string; int number; struct T_INSTRUCTION *instruction; struct _T_INSTRUCTION_LIST *instruction_list; struct _T_ARITHMETIC_EXPRESSION *arithmetic_expression_type; }

user_defined_types: union yyalloc { short yyss_alloc; union YYSTYPE yyvs_alloc; }

user_defined_types: struct _T_INSTRUCTION_LIST { struct _T_INSTRUCTION_LIST_ENTRY *first; struct _T_INSTRUCTION_LIST_ENTRY *last; }

user_defined_types: struct T_INSTRUCTION { enum INSTRUCTION_TYPE type; union { struct INSTRUCTION_READ_PARAMS read_params; struct INSTRUCTION_WRITE_PARAMS write_params; struct INSTRUCTION_ASSIGN_PARAMS assign_params; struct INSTRUCTION_IF_PARAMS if_params; struct INSTRUCTION_WHILE_PARAMS while_params; }; }

user_defined_types: struct T_VARIABLE_TYPE { enum VARIABLE_ENTRY_TYPE type; union { char *variable_name; int variable_value; }; }

user_defined_types: struct INSTRUCTION_READ_PARAMS { struct T_VARIABLE_TYPE *variable; }

user_defined_types: struct INSTRUCTION_WRITE_PARAMS { struct _T_ARITHMETIC_EXPRESSION *expression; }

user_defined_types: struct INSTRUCTION_IF_PARAMS { struct _T_LOGICAL_EXPRESSION *expression; struct _T_INSTRUCTION_LIST *nested_true_code_block; struct _T_INSTRUCTION_LIST *nested_false_code_block; }

user_defined_types: struct _T_ARITHMETIC_EXPRESSION { enum ARITHMETIC_EXPRESSION_ENTRY_TYPE type; union { struct T_VARIABLE_TYPE *variable; struct { enum ARITHMETIC_OPERATION operation; struct _T_ARITHMETIC_EXPRESSION *param1; struct _T_ARITHMETIC_EXPRESSION *param2; }; }; }

user_defined_types: struct _T_LOGICAL_EXPRESSION { enum LOGICAL_EXPRESSION_ENTRY_TYPE type; union { struct T_VARIABLE_TYPE *variable; struct { enum LOGICAL_OPERATION operation; struct _T_LOGICAL_EXPRESSION *param1; struct _T_LOGICAL_EXPRESSION *param2; }; }; }


hctoi

repo: dce/one-timer

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

switch ( a1 )
{
case '0':
result = 0LL;
break;
case '1':
result = 1LL;
break;
case '2':
result = 2LL;
break;
case '3':
result = 3LL;
break;
case '4':
result = 4LL;
break;
case '5':
result = 5LL;
break;
case '6':
result = 6LL;
break;
case '7':
result = 7LL;
break;
case '8':
result = 8LL;
break;
case '9':
result = 9LL;
break;
case 'a':
result = 10LL;
break;
case 'b':
result = 11LL;
break;
case 'c':
result = 12LL;
break;
case 'd':
result = 13LL;
break;
case 'e':
result = 14LL;
break;
case 'f':
result = 15LL;
break;
default:
puts("Invalid hex char.");
exit(1);
}
return result;
}

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

switch ( a1 )
{
case '0':
result = 0LL;
break;
case '1':
result = 1LL;
break;
case '2':
result = 2LL;
break;
case '3':
result = 3LL;
break;
case '4':
result = 4LL;
break;
case '5':
result = 5LL;
break;
case '6':
result = 6LL;
break;
case '7':
result = 7LL;
break;
case '8':
result = 8LL;
break;
case '9':
result = 9LL;
break;
case 'a':
result = 10LL;
break;
case 'b':
result = 11LL;
break;
case 'c':
result = 12LL;
break;
case 'd':
result = 13LL;
break;
case 'e':
result = 14LL;
break;
case 'f':
result = 15LL;
break;
default:
puts("Invalid hex char.");
exit(1);
}
return result;
}

original_code:
int
hctoi(char c)
{
    int i;
    switch (c) {
        case '0': i = 0; break;
        case '1': i = 1; break;
        case '2': i = 2; break;
        case '3': i = 3; break;
        case '4': i = 4; break;
        case '5': i = 5; break;
        case '6': i = 6; break;
        case '7': i = 7; break;
        case '8': i = 8; break;
        case '9': i = 9; break;
        case 'a': i = 10; break;
        case 'b': i = 11; break;
        case 'c': i = 12; break;
        case 'd': i = 13; break;
        case 'e': i = 14; break;
        case 'f': i = 15; break;
        default:
            printf("Invalid hex char.\n");
            exit(1);
    }
    return i;
}

variable_types: c char

variable_types: i int

return_type: int


itohc

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

switch ( a1 )
{
case 0:
result = 48LL;
break;
case 1:
result = 49LL;
break;
case 2:
result = 50LL;
break;
case 3:
result = 51LL;
break;
case 4:
result = 52LL;
break;
case 5:
result = 53LL;
break;
case 6:
result = 54LL;
break;
case 7:
result = 55LL;
break;
case 8:
result = 56LL;
break;
case 9:
result = 57LL;
break;
case 10:
result = 97LL;
break;
case 11:
result = 98LL;
break;
case 12:
result = 99LL;
break;
case 13:
result = 100LL;
break;
case 14:
result = 101LL;
break;
case 15:
result = 102LL;
break;
default:
puts("Invalid hex int.");
exit(1);
}
return result;
}

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

switch ( a1 )
{
case 0:
result = 48LL;
break;
case 1:
result = 49LL;
break;
case 2:
result = 50LL;
break;
case 3:
result = 51LL;
break;
case 4:
result = 52LL;
break;
case 5:
result = 53LL;
break;
case 6:
result = 54LL;
break;
case 7:
result = 55LL;
break;
case 8:
result = 56LL;
break;
case 9:
result = 57LL;
break;
case 10:
result = 97LL;
break;
case 11:
result = 98LL;
break;
case 12:
result = 99LL;
break;
case 13:
result = 100LL;
break;
case 14:
result = 101LL;
break;
case 15:
result = 102LL;
break;
default:
puts("Invalid hex int.");
exit(1);
}
return result;
}

original_code:
char
itohc(int i) {
    char c;
    switch (i) {
        case 0: c = '0'; break;
        case 1: c = '1'; break;
        case 2: c = '2'; break;
        case 3: c = '3'; break;
        case 4: c = '4'; break;
        case 5: c = '5'; break;
        case 6: c = '6'; break;
        case 7: c = '7'; break;
        case 8: c = '8'; break;
        case 9: c = '9'; break;
        case 10: c = 'a'; break;
        case 11: c = 'b'; break;
        case 12: c = 'c'; break;
        case 13: c = 'd'; break;
        case 14: c = 'e'; break;
        case 15: c = 'f'; break;
        default:
            printf("Invalid hex int.\n");
            exit(1);
    }
    return c;
}

return_type: char


hctoi

canonical_original_code:
int hctoi(char c)
{
    int i;
    switch (c) {
        case '0': i = 0; break;
        case '1': i = 1; break;
        case '2': i = 2; break;
        case '3': i = 3; break;
        case '4': i = 4; break;
        case '5': i = 5; break;
        case '6': i = 6; break;
        case '7': i = 7; break;
        case '8': i = 8; break;
        case '9': i = 9; break;
        case 'a': i = 10; break;
        case 'b': i = 11; break;
        case 'c': i = 12; break;
        case 'd': i = 13; break;
        case 'e': i = 14; break;
        case 'f': i = 15; break;
        default:
            printf("Invalid hex char.\n");
            exit(1);
    }
    return i;
}


itohc

canonical_original_code:
char itohc(int i) {
    char c;
    switch (i) {
        case 0: c = '0'; break;
        case 1: c = '1'; break;
        case 2: c = '2'; break;
        case 3: c = '3'; break;
        case 4: c = '4'; break;
        case 5: c = '5'; break;
        case 6: c = '6'; break;
        case 7: c = '7'; break;
        case 8: c = '8'; break;
        case 9: c = '9'; break;
        case 10: c = 'a'; break;
        case 11: c = 'b'; break;
        case 12: c = 'c'; break;
        case 13: c = 'd'; break;
        case 14: c = 'e'; break;
        case 15: c = 'f'; break;
        default:
            printf("Invalid hex int.\n");
            exit(1);
    }
    return c;
}


usage

repo: dcolascione/cygspawn

decompiled_code:
size_t usage()
{
return fwrite("testspawn [-vg] SHELL_REDIR* PROGRAM ARGS*: test posix_spawn\n", 1uLL, 0x3DuLL, _bss_start);
}

canonical_decompiled_code:
size_t func7()
{
return fwrite("testspawn [-vg] SHELL_REDIR* PROGRAM ARGS*: test posix_spawn\n", 1uLL, 0x3DuLL, _bss_start);
}

original_code:
static void
usage ()
{
  fprintf (stderr,
           "testspawn [-vg] SHELL_REDIR* PROGRAM ARGS*: test posix_spawn\n");
}

canonical_original_code:
static void usage()
{
  fprintf (stderr,
           "testspawn [-vg] SHELL_REDIR* PROGRAM ARGS*: test posix_spawn\n");
}

return_type: void


decompiled_code:
__int64 __fastcall do_work(__int64 a1, __int64 a2)
{
__pid_t v2; // eax
char *const *v3; // rbp
char *v4; // rbx
__int64 result; // rax
char v6; // al
_BYTE *v7; // rbx
__int64 v8; // [rsp+0h] [rbp-28h] BYREF
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = fork();
if ( v2 < 0 )
{
perror("fork");
return 1LL;
}
if ( v2 )
{
if ( wait((__WAIT_STATUS)&stat_loc) < 0 )
{
perror("wait");
result = 1LL;
}
else if ( ((__int64)stat_loc.__uptr & 0x7F) != 0 )
{
if ( verbose )
printf("child killed: %d\n", (__int64)stat_loc.__uptr & 0x7F);
result = ((__int64)stat_loc.__uptr & 0x7F) + 127;
}
else
{
if ( verbose )
printf("child exited: %d\n", BYTE1(stat_loc.__uptr));
result = BYTE1(stat_loc.__uptr);
}
return result;
}
v3 = (char *const *)(a2 + 8);
v4 = *(char **)(a2 + 8);
if ( !v4 )
{
LABEL_4:
fwrite("testspawn: no program given!\n", 1uLL, 0x1DuLL, _bss_start);
usage();
return 1LL;
}
while ( *v4 != 45 )
{
if ( !strchr("0123456789<>", *v4) )
{
execvp(v4, v3);
perror("execvp");
_exit(127);
}
if ( (int)process_redirection((__int64)&v8, v4) < 0 )
return 1LL;
LABEL_15:
v4 = *++v3;
if ( !*v3 )
goto LABEL_4;
}
v6 = v4[1];
if ( !v6 )
goto LABEL_15;
v7 = v4 + 1;
while ( v6 == 118 )
{
verbose = 1;
v6 = *++v7;
if ( !*v7 )
goto LABEL_15;
}
fprintf(_bss_start, "testspawn: unknown flag '%c'\n", (unsigned int)v6);
usage();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
__pid_t v2; // eax
char *const *v3; // rbp
char *v4; // rbx
__int64 result; // rax
char v6; // al
_BYTE *v7; // rbx
__int64 v8; // [rsp+0h] [rbp-28h] BYREF
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = fork();
if ( v2 < 0 )
{
perror("fork");
return 1LL;
}
if ( v2 )
{
if ( wait((__WAIT_STATUS)&stat_loc) < 0 )
{
perror("wait");
result = 1LL;
}
else if ( ((__int64)stat_loc.__uptr & 0x7F) != 0 )
{
if ( verbose )
printf("child killed: %d\n", (__int64)stat_loc.__uptr & 0x7F);
result = ((__int64)stat_loc.__uptr & 0x7F) + 127;
}
else
{
if ( verbose )
printf("child exited: %d\n", BYTE1(stat_loc.__uptr));
result = BYTE1(stat_loc.__uptr);
}
return result;
}
v3 = (char *const *)(a2 + 8);
v4 = *(char **)(a2 + 8);
if ( !v4 )
{
LABEL_4:
fwrite("testspawn: no program given!\n", 1uLL, 0x1DuLL, _bss_start);
func7();
return 1LL;
}
while ( *v4 != 45 )
{
if ( !strchr("0123456789<>", *v4) )
{
execvp(v4, v3);
perror("execvp");
_exit(127);
}
if ( (int)func8((__int64)&v8, v4) < 0 )
return 1LL;
LABEL_15:
v4 = *++v3;
if ( !*v3 )
goto LABEL_4;
}
v6 = v4[1];
if ( !v6 )
goto LABEL_15;
v7 = v4 + 1;
while ( v6 == 118 )
{
verbose = 1;
v6 = *++v7;
if ( !*v7 )
goto LABEL_15;
}
fprintf(_bss_start, "testspawn: unknown flag '%c'\n", (unsigned int)v6);
func7();
return 1LL;
}

original_code:
int
do_work (int argc, char **argv)
{
  char *c;
  pid_t child;
  int status;
  void *file_actions;
  child = fork ();
  if (child < 0)
    {
      perror ("fork");
      return 1;
    }
  if (child != 0)
    goto parent;
  for (++argv; *argv; ++argv)
    {
      if (**argv == '-')
        {
          for (c = *argv + 1; *c; ++c)
            switch (*c)
              {
              case 'v':
                verbose = 1;
                break;
              default:
                fprintf (stderr, "testspawn: unknown flag '%c'\n", *c);
                usage ();
                return 1;
              }
          continue;
        }
      if (!strchr ("0123456789<>", **argv))
        break;
      if (process_redirection (&file_actions, *argv) < 0)
        return 1;
    }
  if (!argv[0])
    {
      fprintf (stderr, "testspawn: no program given!\n");
      usage ();
      return 1;
    }
  execvp (argv[0], argv);
  perror ("execvp");
  _exit (127);
 parent:
  if (wait (&status) < 0)
    {
      perror ("wait");
      return 1;
    }
  if ((((status) & 0x7f) == 0))
    {
      if (verbose)
        printf ("child exited: %d\n", (((status) & 0xff00) >> 8));
      return (((status) & 0xff00) >> 8);
    }
  if (verbose)
    printf ("child killed: %d\n", ((status) & 0x7f));
  return 127 + ((status) & 0x7f);
}

canonical_original_code:
int do_work(int argc, char **argv)
{
  char *c;
  int child;
  int status;
  void *file_actions;
  child = fork ();
  if (child < 0)
    {
      perror ("fork");
      return 1;
    }
  if (child != 0)
    goto parent;
  for (++argv; *argv; ++argv)
    {
      if (**argv == '-')
        {
          for (c = *argv + 1; *c; ++c)
            switch (*c)
              {
              case 'v':
                verbose = 1;
                break;
              default:
                fprintf (stderr, "testspawn: unknown flag '%c'\n", *c);
                usage ();
                return 1;
              }
          continue;
        }
      if (!strchr ("0123456789<>", **argv))
        break;
      if (process_redirection (&file_actions, *argv) < 0)
        return 1;
    }
  if (!argv[0])
    {
      fprintf (stderr, "testspawn: no program given!\n");
      usage ();
      return 1;
    }
  execvp (argv[0], argv);
  perror ("execvp");
  _exit (127);
 parent:
  if (wait (&status) < 0)
    {
      perror ("wait");
      return 1;
    }
  if ((((status) & 0x7f) == 0))
    {
      if (verbose)
        printf ("child exited: %d\n", (((status) & 0xff00) >> 8));
      return (((status) & 0xff00) >> 8);
    }
  if (verbose)
    printf ("child killed: %d\n", ((status) & 0x7f));
  return 127 + ((status) & 0x7f);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
c
char *

variable_types: child int

variable_types: status int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char *v5; // rdi
int v6; // er12
char *v7; // rdi
size_t v8; // rbp
void *v9; // rax
int i; // ebp

v5 = getenv("ITER");
if ( !v5 )
v5 = "1";
v6 = atoi(v5);
v7 = getenv("JUNKBYTES");
if ( !v7 )
v7 = "0";
v8 = atoi(v7);
v9 = malloc(v8);
memset(v9, 42, v8);
if ( v6 )
{
for ( i = 0; i != v6; ++i )
{
v3 = do_work((unsigned int)argc, (__int64)argv);
if ( v3 )
break;
}
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char *v5; // rdi
int v6; // er12
char *v7; // rdi
size_t v8; // rbp
void *v9; // rax
int i; // ebp

v5 = getenv("ITER");
if ( !v5 )
v5 = "1";
v6 = atoi(v5);
v7 = getenv("JUNKBYTES");
if ( !v7 )
v7 = "0";
v8 = atoi(v7);
v9 = malloc(v8);
memset(v9, 42, v8);
if ( v6 )
{
for ( i = 0; i != v6; ++i )
{
v3 = func9((unsigned int)argc, (__int64)argv);
if ( v3 )
break;
}
}
return v3;
}

original_code:
int
main (int argc, char **argv)
{
  int i;
  int ret;
  unsigned iter = atoi (getenv ("ITER") ?: "1");
  size_t junk_size = atoi (getenv ("JUNKBYTES") ?: "0");
  char *junk = malloc (junk_size);
  memset (junk, 42, junk_size);
  for (i = 0; i < iter; ++i)
    {
      ret = do_work (argc, argv);
      if (ret != 0)
        break;
    }
  return ret;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int i;
  int ret;
  unsigned int iter = atoi (getenv ("ITER") ?: "1");
  unsigned long junk_size = atoi (getenv ("JUNKBYTES") ?: "0");
  char *junk = malloc (junk_size);
  memset (junk, 42, junk_size);
  for (i = 0; i < iter; ++i)
    {
      ret = do_work (argc, argv);
      if (ret != 0)
        break;
    }
  return ret;
}

variable_types: ret int

variable_types:
iter
unsigned int

variable_types:
junk
char *


repo: dcollien/Alcubierre

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

result = malloc(0x18uLL);
if ( !result )
_assert_fail("list != NULL", "types/List.c", 0x1Au, "new_List");
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

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

result = malloc(0x18uLL);
if ( !result )
_assert_fail("list != NULL", "types/List.c", 0x1Au, "new_List");
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

original_code:
List new_List(void) {
 List list = malloc(sizeof(struct _list));
 ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "types/List.c", 26, __extension__ __PRETTY_FUNCTION__); }));
 list->first = ((void *)0);
 list->last = ((void *)0);
 list->size = 0;
 return list;
}

canonical_original_code:
struct _list *new_List() {
 struct _list *list = malloc(sizeof(struct _list));
 ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "types/List.c", 26, __extension__ __PRETTY_FUNCTION__); }));
 list->first = ((void *)0);
 list->last = ((void *)0);
 list->size = 0;
 return list;
}

variable_types: struct _list { struct listNode { unsigned long value; struct listNode *next; struct listNode *prev; } *first; struct listNode *last; unsigned int size; } *

user_defined_types: struct _list { struct listNode *first; struct listNode *last; unsigned int size; }


decompiled_code:
void __fastcall destroy_List(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

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

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

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

original_code:
void destroy_List(List list) {
 listNodePtr_t node, prevNode;
 node = list->first;
 while (node != ((void *)0)) {
  prevNode = node;
  node = node->next;
  free(prevNode);
 }
 free(list);
}

canonical_original_code:
void destroy_List(struct _list *list) {
 struct listNode *node; struct listNode *prevNode;
 node = list->first;
 while (node != ((void *)0)) {
  prevNode = node;
  node = node->next;
  free(prevNode);
 }
 free(list);
}

variable_types: struct listNode { unsigned long value; struct listNode *next; struct listNode *prev; } *


decompiled_code:
__int64 __fastcall removeFirst_List(__int64 a1)
{
__int64 *v2; // rdi
__int64 v3; // rbp

v2 = *(__int64 **)a1;
if ( !v2 )
_assert_fail("list->first != NULL", "types/List.c", 0x4Du, "removeFirst_List");
v3 = *v2;
*(_QWORD *)a1 = v2[1];
free(v2);
if ( *(_QWORD *)a1 )
*(_QWORD *)(*(_QWORD *)a1 + 16LL) = 0LL;
else
*(_QWORD *)(a1 + 8) = 0LL;
--*(_DWORD *)(a1 + 16);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 *v2; // rdi
__int64 v3; // rbp

v2 = *(__int64 **)a1;
if ( !v2 )
_assert_fail("list->first != NULL", "types/List.c", 0x4Du, "removeFirst_List");
v3 = *v2;
*(_QWORD *)a1 = v2[1];
free(v2);
if ( *(_QWORD *)a1 )
*(_QWORD *)(*(_QWORD *)a1 + 16LL) = 0LL;
else
*(_QWORD *)(a1 + 8) = 0LL;
--*(_DWORD *)(a1 + 16);
return v3;
}

original_code:
any_t removeFirst_List(List list) {
 ((void) sizeof ((list->first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list->first != ((void *)0)) ; else __assert_fail ("list->first != NULL", "types/List.c", 77, __extension__ __PRETTY_FUNCTION__); }));
 any_t value = list->first->value;
 listNodePtr_t removedNode = list->first;
 list->first = removedNode->next;
 free(removedNode);
 if (list->first == ((void *)0)) {
  list->last = list->first;
 } else {
  list->first->prev = ((void *)0);
 }
 --(list->size);
 return value;
}

canonical_original_code:
unsigned long removeFirst_List(struct _list *list) {
 ((void) sizeof ((list->first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list->first != ((void *)0)) ; else __assert_fail ("list->first != NULL", "types/List.c", 77, __extension__ __PRETTY_FUNCTION__); }));
 unsigned long value = list->first->value;
 struct listNode *removedNode = list->first;
 list->first = removedNode->next;
 free(removedNode);
 if (list->first == ((void *)0)) {
  list->last = list->first;
 } else {
  list->first->prev = ((void *)0);
 }
 --(list->size);
 return value;
}

variable_types:
value
unsigned long

return_type: unsigned long

user_defined_types: struct listNode { unsigned long value; struct listNode *next; struct listNode *prev; }


original_code:
any_t removeLast_List(List list) {
 ((void) sizeof ((list->last != ((void *)0)) ? 1 : 0), __extension__ ({ if (list->last != ((void *)0)) ; else __assert_fail ("list->last != NULL", "types/List.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 any_t value = list->last->value;
 listNodePtr_t removedNode = list->last;
 list->last = removedNode->prev;
 free(removedNode);
 if (list->last == ((void *)0)) {
  list->first = list->last;
 } else {
  list->last->next = ((void *)0);
 }
 --(list->size);
 return value;
}

canonical_original_code:
unsigned long removeLast_List(struct _list *list) {
 ((void) sizeof ((list->last != ((void *)0)) ? 1 : 0), __extension__ ({ if (list->last != ((void *)0)) ; else __assert_fail ("list->last != NULL", "types/List.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 unsigned long value = list->last->value;
 struct listNode *removedNode = list->last;
 list->last = removedNode->prev;
 free(removedNode);
 if (list->last == ((void *)0)) {
  list->first = list->last;
 } else {
  list->last->next = ((void *)0);
 }
 --(list->size);
 return value;
}


decompiled_code:
__int64 __fastcall in_List(_QWORD *a1, __int64 a2, unsigned __int8 (__fastcall *a3)(_QWORD, __int64))
{
_QWORD *v4; // rbx

v4 = (_QWORD *)*a1;
if ( !*a1 )
return 0LL;
do
{
if ( a3 )
{
if ( a3(*v4, a2) )
return 1LL;
}
else if ( *v4 == a2 )
{
return 1LL;
}
v4 = (_QWORD *)v4[1];
}
while ( v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2, unsigned __int8 (__fastcall *a3)(_QWORD, __int64))
{
_QWORD *v4; // rbx

v4 = (_QWORD *)*a1;
if ( !*a1 )
return 0LL;
do
{
if ( a3 )
{
if ( a3(*v4, a2) )
return 1LL;
}
else if ( *v4 == a2 )
{
return 1LL;
}
v4 = (_QWORD *)v4[1];
}
while ( v4 );
return 0LL;
}

original_code:
_Bool in_List(List list, any_t value, anyEqDelegate isEqualFunc) {
 _Bool isFound = 0;
 listNodePtr_t currentNode = list->first;
 while (currentNode != ((void *)0) && !isFound) {
  if (isEqualFunc == ((void *)0) && currentNode->value == value) {
   isFound = 1;
  } else if (isEqualFunc != ((void *)0) && isEqualFunc(currentNode->value, value)) {
   isFound = 1;
  }
  currentNode = currentNode->next;
 }
 return isFound;
}

canonical_original_code:
_Bool in_List(struct _list *list, unsigned long value, _Bool (*isEqualFunc)(unsigned long, unsigned long)) {
 _Bool isFound = 0;
 struct listNode *currentNode = list->first;
 while (currentNode != ((void *)0) && !isFound) {
  if (isEqualFunc == ((void *)0) && currentNode->value == value) {
   isFound = 1;
  } else if (isEqualFunc != ((void *)0) && isEqualFunc(currentNode->value, value)) {
   isFound = 1;
  }
  currentNode = currentNode->next;
 }
 return isFound;
}

variable_types:
isEqualFunc
_Bool (*)(unsigned long, unsigned long)


decompiled_code:
__int64 __fastcall size_List(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
unsigned int size_List(List list) {
 return list->size;
}

canonical_original_code:
unsigned int size_List(struct _list *list) {
 return list->size;
}

return_type: unsigned int


canonical_decompiled_code:
void func0()
{
;
}

original_code:
vector2d_t v_(scalar_t x, scalar_t y) {
 vector2d_t v;
 v.x = x;
 v.y = y;
 return v;
}

canonical_original_code:
struct vector2d_t v_(double x, double y) {
 struct vector2d_t v;
 v.x = x;
 v.y = y;
 return v;
}

variable_types: x double

variable_types: y double

variable_types: struct vector2d_t { double x; double y; }


decompiled_code:
double __fastcall v_len2(double a1, double a2)
{
double v2; // r14

v2 = ((double (*)(void))sq)();
return sq(a2) + v2;
}

canonical_decompiled_code:
double __fastcall func1(double a1, double a2)
{
double v2; // r14

v2 = ((double (*)(void))sq)();
return sq(a2) + v2;
}

original_code:
scalar_t v_len2(vector2d_t v) {
 return sq(v.x) + sq(v.y);
}

canonical_original_code:
double v_len2(struct vector2d_t v) {
 return sq(v.x) + sq(v.y);
}

return_type: double

user_defined_types: struct vector2d_t { double x; double y; }


decompiled_code:
double __fastcall v_len(double a1, double a2)
{
double v2; // xmm0_8
double result; // xmm0_8

v2 = v_len2(a1, a2);
if ( v2 < 0.0 )
result = sqrt(v2);
else
result = sqrt(v2);
return result;
}

canonical_decompiled_code:
double __fastcall func2(double a1, double a2)
{
double v2; // xmm0_8
double result; // xmm0_8

v2 = func1(a1, a2);
if ( v2 < 0.0 )
result = sqrt(v2);
else
result = sqrt(v2);
return result;
}

original_code:
scalar_t v_len(vector2d_t v) {
 return sqrt(v_len2(v));
}

canonical_original_code:
double v_len(struct vector2d_t v) {
 return sqrt(v_len2(v));
}


decompiled_code:
double __fastcall v_angle(double a1, double a2)
{
return atan2(a2, a1);
}

canonical_decompiled_code:
double __fastcall func3(double a1, double a2)
{
return atan2(a2, a1);
}

original_code:
double v_angle(vector2d_t v) {
 return atan2(v.y, v.x);
}

canonical_original_code:
double v_angle(struct vector2d_t v) {
 return atan2(v.y, v.x);
}


decompiled_code:
_BOOL8 __fastcall v_eq(double a1, double a2, double a3, double a4)
{
bool v4; // al

if ( a1 == a3 )
v4 = a2 == a4;
else
v4 = 0;
return v4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(double a1, double a2, double a3, double a4)
{
bool v4; // al

if ( a1 == a3 )
v4 = a2 == a4;
else
v4 = 0;
return v4;
}

original_code:
_Bool v_eq(vector2d_t v1, vector2d_t v2) {
 return (v1.x == v2.x && v1.y == v2.y);
}

canonical_original_code:
_Bool v_eq(struct vector2d_t v1, struct vector2d_t v2) {
 return (v1.x == v2.x && v1.y == v2.y);
}


decompiled_code:
void v_rotate()
{
v_();
}

canonical_decompiled_code:
void func5()
{
func0();
}

original_code:
vector2d_t v_rotate(vector2d_t v1, vector2d_t v2) {
 return v_(v1.x * v2.x - v1.y * v2.y, v1.x * v2.y + v1.y * v2.x);
}

canonical_original_code:
struct vector2d_t v_rotate(struct vector2d_t v1, struct vector2d_t v2) {
 return v_(v1.x * v2.x - v1.y * v2.y, v1.x * v2.y + v1.y * v2.x);
}

return_type: struct vector2d_t { double x; double y; }


decompiled_code:
void v_add()
{
v_();
}

canonical_decompiled_code:
void func6()
{
func0();
}

original_code:
vector2d_t v_add(vector2d_t v1, vector2d_t v2) {
 return v_(v1.x + v2.x, v1.y + v2.y);
}

canonical_original_code:
struct vector2d_t v_add(struct vector2d_t v1, struct vector2d_t v2) {
 return v_(v1.x + v2.x, v1.y + v2.y);
}


decompiled_code:
void v_sub()
{
v_();
}

canonical_decompiled_code:
void func7()
{
func0();
}

original_code:
vector2d_t v_sub(vector2d_t v1, vector2d_t v2) {
 return v_(v1.x - v2.x, v1.y - v2.y);
}

canonical_original_code:
struct vector2d_t v_sub(struct vector2d_t v1, struct vector2d_t v2) {
 return v_(v1.x - v2.x, v1.y - v2.y);
}


decompiled_code:
void v_mul()
{
v_();
}

canonical_decompiled_code:
void func8()
{
func0();
}

original_code:
vector2d_t v_mul(vector2d_t v1, scalar_t s) {
 return v_(v1.x * s, v1.y * s);
}

canonical_original_code:
struct vector2d_t v_mul(struct vector2d_t v1, double s) {
 return v_(v1.x * s, v1.y * s);
}

variable_types: s double


decompiled_code:
void v_div()
{
v_();
}

canonical_decompiled_code:
void func9()
{
func0();
}

original_code:
vector2d_t v_div(vector2d_t v1, scalar_t s) {
 return v_(v1.x / s, v1.y / s);
}

canonical_original_code:
struct vector2d_t v_div(struct vector2d_t v1, double s) {
 return v_(v1.x / s, v1.y / s);
}


decompiled_code:
void __fastcall v_lerp(double a1, double a2, double a3, double a4, double a5)
{
lerp(a1, a3, a5);
lerp(a1, a2, a4);
v_();
}

canonical_decompiled_code:
void __fastcall func10(double a1, double a2, double a3, double a4, double a5)
{
lerp(a1, a3, a5);
lerp(a1, a2, a4);
func0();
}

original_code:
vector2d_t v_lerp(scalar_t t, vector2d_t v1, vector2d_t v2) {
 return v_(lerp(t, v1.x, v2.x), lerp(t, v1.y, v2.y));
}

canonical_original_code:
struct vector2d_t v_lerp(double t, struct vector2d_t v1, struct vector2d_t v2) {
 return v_(lerp(t, v1.x, v2.x), lerp(t, v1.y, v2.y));
}

variable_types: t double


decompiled_code:
void __fastcall v_unit(double a1, double a2)
{
v_len(a1, a2);
v_();
}

canonical_decompiled_code:
void __fastcall func11(double a1, double a2)
{
func2(a1, a2);
func0();
}

original_code:
vector2d_t v_unit(vector2d_t v1) {
  int len = v_len(v1);
  return v_(v1.x/len, v1.y/len);
}

canonical_original_code:
struct vector2d_t v_unit(struct vector2d_t v1) {
  int len = v_len(v1);
  return v_(v1.x/len, v1.y/len);
}

variable_types: len int


decompiled_code:
void __fastcall v_scale(double a1, double a2)
{
v_unit(a1, a2);
v_mul();
}

canonical_decompiled_code:
void __fastcall func12(double a1, double a2)
{
func11(a1, a2);
func8();
}

original_code:
vector2d_t v_scale(vector2d_t v1, scalar_t s) {
  return v_mul(v_unit(v1), s);
}

canonical_original_code:
struct vector2d_t v_scale(struct vector2d_t v1, double s) {
  return v_mul(v_unit(v1), s);
}


decompiled_code:
void __fastcall v_forAngle(double a1)
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a1, sinx, (double *)&v1);
v_();
}

canonical_decompiled_code:
void __fastcall func13(double a1)
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a1, sinx, (double *)&v1);
func0();
}

canonical_original_code:
struct vector2d_t v_forAngle(double a) {
 return v_(cos(a), sin(a));
}

variable_types: a double


decompiled_code:
void __fastcall v_rotateAngle(double a1, double a2, double a3)
{
v_forAngle(a3);
v_rotate();
}

canonical_decompiled_code:
void __fastcall func14(double a1, double a2, double a3)
{
func13(a3);
func5();
}

original_code:
vector2d_t v_rotateAngle(vector2d_t v1, double a) {
 return v_rotate(v1, v_forAngle(a));
}

canonical_original_code:
struct vector2d_t v_rotateAngle(struct vector2d_t v1, double a) {
 return v_rotate(v1, v_forAngle(a));
}


decompiled_code:
void __fastcall v_forAngleLength(double a1)
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a1, sinx, (double *)&v1);
v_();
}

canonical_decompiled_code:
void __fastcall func15(double a1)
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a1, sinx, (double *)&v1);
func0();
}

original_code:
vector2d_t v_forAngleLength(double a, scalar_t s) {
 return v_(cos(a) * s, sin(a) * s);
}

canonical_original_code:
struct vector2d_t v_forAngleLength(double a, double s) {
 return v_(cos(a) * s, sin(a) * s);
}


decompiled_code:
double __fastcall v_dot(double a1, double a2, double a3, double a4)
{
return a1 * a3 + a2 * a4;
}

canonical_decompiled_code:
double __fastcall func16(double a1, double a2, double a3, double a4)
{
return a1 * a3 + a2 * a4;
}

original_code:
scalar_t v_dot(vector2d_t v1, vector2d_t v2) {
 return (v1.x * v2.x + v1.y * v2.y);
}

canonical_original_code:
double v_dot(struct vector2d_t v1, struct vector2d_t v2) {
 return (v1.x * v2.x + v1.y * v2.y);
}


decompiled_code:
double __fastcall v_dist(double a1, double a2)
{
v_sub();
return v_len(a1, a2);
}

canonical_decompiled_code:
double __fastcall func17(double a1, double a2)
{
func7();
return func2(a1, a2);
}

original_code:
scalar_t v_dist(vector2d_t v1, vector2d_t v2) {
 return v_len(v_sub(v1, v2));
}

canonical_original_code:
double v_dist(struct vector2d_t v1, struct vector2d_t v2) {
 return v_len(v_sub(v1, v2));
}


decompiled_code:
double __fastcall v_dist2(double a1, double a2)
{
v_sub();
return v_len2(a1, a2);
}

canonical_decompiled_code:
double __fastcall func18(double a1, double a2)
{
func7();
return func1(a1, a2);
}

original_code:
scalar_t v_dist2(vector2d_t v1, vector2d_t v2) {
 return v_len2(v_sub(v1, v2));
}

canonical_original_code:
double v_dist2(struct vector2d_t v1, struct vector2d_t v2) {
 return v_len2(v_sub(v1, v2));
}


original_code:
void remove_HashMap(HashMap map, any_t key) {
   unsigned int hash = map->hashFunction(key) % map->size;
   collisionNode_t *node = map->array[hash];
   collisionNode_t *prev = ((void *)0);
   while (node != ((void *)0) && !isEqual(map, node->key, key)) {
      node = node->next;
   }
   if (node != ((void *)0) && isEqual(map, node->key, key)) {
      if (prev == ((void *)0)) {
         map->array[hash] = node->next;
      } else {
         prev->next = node->next;
      }
      free(node);
   }
}

canonical_original_code:
void remove_HashMap(struct _hashmap *map, unsigned long key) {
   unsigned int hash = map->hashFunction(key) % map->size;
   struct collisionNode *node = map->array[hash];
   struct collisionNode *prev = ((void *)0);
   while (node != ((void *)0) && !isEqual(map, node->key, key)) {
      node = node->next;
   }
   if (node != ((void *)0) && isEqual(map, node->key, key)) {
      if (prev == ((void *)0)) {
         map->array[hash] = node->next;
      } else {
         prev->next = node->next;
      }
      free(node);
   }
}

variable_types: struct _hashmap { struct collisionNode { unsigned long key; unsigned long value; struct collisionNode *next; } **array; int size; unsigned int (*hashFunction)(unsigned long); _Bool (*isEqual)(unsigned long, unsigned long); } *

variable_types:
key
unsigned long

variable_types:
hash
unsigned int

user_defined_types: struct _hashmap { struct collisionNode **array; int size; unsigned int (*hashFunction)(unsigned long); _Bool (*isEqual)(unsigned long, unsigned long); }


original_code:
void set_HashMap(HashMap map, any_t key, any_t value) {
   unsigned int hash = map->hashFunction(key) % map->size;
   collisionNode_t *prevNode;
   collisionNode_t *node = malloc(sizeof(collisionNode_t));
   ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "types/HashMap.c", 71, __extension__ __PRETTY_FUNCTION__); }));
   node->key = key;
   node->value = value;
   node->next = ((void *)0);
   prevNode = map->array[hash];
   if (prevNode == ((void *)0)) {
      map->array[hash] = node;
   } else {
      while (prevNode->next != ((void *)0)) {
         if (isEqual(map, prevNode->key, key)) {
            break;
         }
         prevNode = prevNode->next;
      }
      if (isEqual(map, prevNode->key, key)) {
         prevNode->value = node->value;
         free(node);
      } else {
         prevNode->next = node;
      }
   }
}

canonical_original_code:
void set_HashMap(struct _hashmap *map, unsigned long key, unsigned long value) {
   unsigned int hash = map->hashFunction(key) % map->size;
   struct collisionNode *prevNode;
   struct collisionNode *node = malloc(sizeof(collisionNode_t));
   ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "types/HashMap.c", 71, __extension__ __PRETTY_FUNCTION__); }));
   node->key = key;
   node->value = value;
   node->next = ((void *)0);
   prevNode = map->array[hash];
   if (prevNode == ((void *)0)) {
      map->array[hash] = node;
   } else {
      while (prevNode->next != ((void *)0)) {
         if (isEqual(map, prevNode->key, key)) {
            break;
         }
         prevNode = prevNode->next;
      }
      if (isEqual(map, prevNode->key, key)) {
         prevNode->value = node->value;
         free(node);
      } else {
         prevNode->next = node;
      }
   }
}

variable_types: struct collisionNode { unsigned long key; unsigned long value; struct collisionNode *next; } *


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

v2 = *(__int64 **)(*(_QWORD *)a1
+ 8LL * ((*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)(a1 + 8)));
if ( !v2 )
return 0LL;
while ( !(unsigned __int8)isEqual(a1, *v2, a2) )
{
v2 = (__int64 *)v2[2];
if ( !v2 )
return 0LL;
}
if ( (unsigned __int8)isEqual(a1, *v2, a2) )
result = v2[1];
else
result = 0LL;
return result;
}

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

v2 = *(__int64 **)(*(_QWORD *)a1
+ 8LL * ((*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)(a1 + 8)));
if ( !v2 )
return 0LL;
while ( !(unsigned __int8)func0(a1, *v2, a2) )
{
v2 = (__int64 *)v2[2];
if ( !v2 )
return 0LL;
}
if ( (unsigned __int8)func0(a1, *v2, a2) )
result = v2[1];
else
result = 0LL;
return result;
}

original_code:
any_t get_HashMap(HashMap map, any_t key) {
   unsigned int hash = map->hashFunction(key) % map->size;
   collisionNode_t *node = map->array[hash];
   any_t value;
   while (node != ((void *)0) && !isEqual(map, node->key, key)) {
      node = node->next;
   }
   if (node == ((void *)0) || !isEqual(map, node->key, key)) {
      value = (any_t)((void *)0);
   } else {
      value = node->value;
   }
   return value;
}

canonical_original_code:
unsigned long get_HashMap(struct _hashmap *map, unsigned long key) {
   unsigned int hash = map->hashFunction(key) % map->size;
   struct collisionNode *node = map->array[hash];
   unsigned long value;
   while (node != ((void *)0) && !isEqual(map, node->key, key)) {
      node = node->next;
   }
   if (node == ((void *)0) || !isEqual(map, node->key, key)) {
      value = (any_t)((void *)0);
   } else {
      value = node->value;
   }
   return value;
}

user_defined_types: struct collisionNode { unsigned long key; unsigned long value; struct collisionNode *next; }


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

v2 = *(__int64 **)(*(_QWORD *)a1
+ 8LL * ((*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)(a1 + 8)));
if ( !v2 )
return 0LL;
do
{
result = isEqual(a1, *v2, a2);
if ( (_BYTE)result )
break;
v2 = (__int64 *)v2[2];
}
while ( v2 );
return result;
}

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

v2 = *(__int64 **)(*(_QWORD *)a1
+ 8LL * ((*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)(a1 + 8)));
if ( !v2 )
return 0LL;
do
{
result = func0(a1, *v2, a2);
if ( (_BYTE)result )
break;
v2 = (__int64 *)v2[2];
}
while ( v2 );
return result;
}

original_code:
_Bool in_HashMap(HashMap map, any_t key) {
   unsigned int hash = map->hashFunction(key) % map->size;
   collisionNode_t *node = map->array[hash];
   while (node != ((void *)0)) {
      if (isEqual(map, node->key, key)) {
         return 1;
      }
      node = node->next;
   }
   return 0;
}

canonical_original_code:
_Bool in_HashMap(struct _hashmap *map, unsigned long key) {
   unsigned int hash = map->hashFunction(key) % map->size;
   struct collisionNode *node = map->array[hash];
   while (node != ((void *)0)) {
      if (isEqual(map, node->key, key)) {
         return 1;
      }
      node = node->next;
   }
   return 0;
}


decompiled_code:
void __fastcall destroy_HashMap(void *ptr)
{
empty_HashMap((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
func6((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}

original_code:
void destroy_HashMap(HashMap map) {
   empty_HashMap(map);
   free(map->array);
   free(map);
}

canonical_original_code:
void destroy_HashMap(struct _hashmap *map) {
   empty_HashMap(map);
   free(map->array);
   free(map);
}


randDouble

decompiled_code:
double __fastcall randDouble(double a1)
{
return (double)rand() / 2147483647.0 * a1;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
return (double)rand() / 2147483647.0 * a1;
}

original_code:
double randDouble(double amt) {
   return amt * (rand()/(double)2147483647);
}

variable_types: amt double


vary

decompiled_code:
double __fastcall vary(double a1)
{
return (a1 + a1) * (randDouble(1.0) - 0.5);
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
return (a1 + a1) * (func0(1.0) - 0.5);
}

original_code:
double vary(double amt) {
   return 2.0 * amt * (randDouble(1.0) - 0.5);
}


randInt

decompiled_code:
__int64 __fastcall randInt(int a1)
{
return (unsigned int)(rand() % a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return (unsigned int)(rand() % a1);
}

original_code:
int randInt(int amt) {
   return rand() % amt;
}

variable_types: amt int


lerp

decompiled_code:
double __fastcall lerp(double a1, double a2, double a3)
{
return (1.0 - a1) * a2 + a1 * a3;
}

canonical_decompiled_code:
double __fastcall func3(double a1, double a2, double a3)
{
return (1.0 - a1) * a2 + a1 * a3;
}

original_code:
double lerp(double t, double from, double to) {
   return t * to + (1.0 - t) * from;
}

variable_types: from double

variable_types: to double


sq

decompiled_code:
double __fastcall sq(double a1)
{
return a1 * a1;
}

canonical_decompiled_code:
double __fastcall func4(double a1)
{
return a1 * a1;
}

original_code:
double sq(double x) {
   return x * x;
}

canonical_original_code:
double sq(double x) {
   return x * x;
}


cube

decompiled_code:
double __fastcall cube(double a1)
{
return a1 * a1 * a1;
}

canonical_decompiled_code:
double __fastcall func5(double a1)
{
return a1 * a1 * a1;
}

original_code:
double cube(double x) {
   return x * x * x;
}


decompiled_code:
_DWORD *new_PQueue()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx
void *v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
_assert_fail("pq != NULL", "types/PQueue.c", 0x1Au, "new_PQueue");
v1 = v0;
v2 = malloc(0x400uLL);
*(_QWORD *)v1 = v2;
if ( !v2 )
_assert_fail("pq->elements != NULL", "types/PQueue.c", 0x1Du, "new_PQueue");
v1[2] = 128;
v1[3] = 0;
return v1;
}

canonical_decompiled_code:
_DWORD *func1()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx
void *v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
_assert_fail("pq != NULL", "types/PQueue.c", 0x1Au, "new_PQueue");
v1 = v0;
v2 = malloc(0x400uLL);
*(_QWORD *)v1 = v2;
if ( !v2 )
_assert_fail("pq->elements != NULL", "types/PQueue.c", 0x1Du, "new_PQueue");
v1[2] = 128;
v1[3] = 0;
return v1;
}

original_code:
PQueue new_PQueue(void) {
   PQueue pq = malloc(sizeof(struct _pq));
   ((void) sizeof ((pq != ((void *)0)) ? 1 : 0), __extension__ ({ if (pq != ((void *)0)) ; else __assert_fail ("pq != NULL", "types/PQueue.c", 26, __extension__ __PRETTY_FUNCTION__); }));
   pq->elements = malloc(sizeof(pq_node_ptr) * 128);
   ((void) sizeof ((pq->elements != ((void *)0)) ? 1 : 0), __extension__ ({ if (pq->elements != ((void *)0)) ; else __assert_fail ("pq->elements != NULL", "types/PQueue.c", 29, __extension__ __PRETTY_FUNCTION__); }));
   pq->size = 128;
   pq->length = 0;
   return pq;
}

canonical_original_code:
struct _pq *new_PQueue() {
   struct _pq *pq = malloc(sizeof(struct _pq));
   ((void) sizeof ((pq != ((void *)0)) ? 1 : 0), __extension__ ({ if (pq != ((void *)0)) ; else __assert_fail ("pq != NULL", "types/PQueue.c", 26, __extension__ __PRETTY_FUNCTION__); }));
   pq->elements = malloc(sizeof(pq_node_ptr) * 128);
   ((void) sizeof ((pq->elements != ((void *)0)) ? 1 : 0), __extension__ ({ if (pq->elements != ((void *)0)) ; else __assert_fail ("pq->elements != NULL", "types/PQueue.c", 29, __extension__ __PRETTY_FUNCTION__); }));
   pq->size = 128;
   pq->length = 0;
   return pq;
}

variable_types: struct _pq { struct pq_node { unsigned long value; int priority; } **elements; int size; int length; } *

user_defined_types: struct _pq { struct pq_node **elements; int size; int length; }


decompiled_code:
__int64 __fastcall remove_PQueue(__int64 *a1)
{
__int64 *v2; // rdi
__int64 v3; // rbp

if ( *((int *)a1 + 3) <= 0 )
_assert_fail("pq->length > 0", "types/PQueue.c", 0x2Eu, "remove_PQueue");
v2 = *(__int64 **)*a1;
v3 = *v2;
free(v2);
*(_QWORD *)*a1 = *(_QWORD *)(*a1 + 8LL * (int)(*((_DWORD *)a1 + 3))-- - 8);
heapify(a1, 0);
return v3;
}

original_code:
any_t remove_PQueue(PQueue pq) {
   ((void) sizeof ((pq->length > 0) ? 1 : 0), __extension__ ({ if (pq->length > 0) ; else __assert_fail ("pq->length > 0", "types/PQueue.c", 46, __extension__ __PRETTY_FUNCTION__); }));
   pq_node_ptr removed = pq->elements[0];
   any_t removedValue = removed->value;
   free(removed);
   pq->elements[0] = pq->elements[pq->length-1];
   --(pq->length);
   heapify(pq, 0);
   return removedValue;
}

canonical_original_code:
unsigned long remove_PQueue(struct _pq *pq) {
   ((void) sizeof ((pq->length > 0) ? 1 : 0), __extension__ ({ if (pq->length > 0) ; else __assert_fail ("pq->length > 0", "types/PQueue.c", 46, __extension__ __PRETTY_FUNCTION__); }));
   struct pq_node *removed = pq->elements[0];
   unsigned long removedValue = removed->value;
   free(removed);
   pq->elements[0] = pq->elements[pq->length-1];
   --(pq->length);
   heapify(pq, 0);
   return removedValue;
}

variable_types: struct pq_node { unsigned long value; int priority; } *

variable_types:
removedValue
unsigned long


decompiled_code:
void __fastcall destroy_PQueue(void *ptr)
{
while ( *((int *)ptr + 3) > 0 )
remove_PQueue((__int64 *)ptr);
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
while ( *((int *)ptr + 3) > 0 )
func2((__int64 *)ptr);
free(*(void **)ptr);
free(ptr);
}

original_code:
void destroy_PQueue(PQueue pq) {
   while (pq->length > 0) {
      remove_PQueue(pq);
   }
   free(pq->elements);
   free(pq);
}

canonical_original_code:
void destroy_PQueue(struct _pq *pq) {
   while (pq->length > 0) {
      remove_PQueue(pq);
   }
   free(pq->elements);
   free(pq);
}

user_defined_types: struct pq_node { unsigned long value; int priority; }


decompiled_code:
__int64 __fastcall size_PQueue(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

original_code:
unsigned int size_PQueue(PQueue pq) {
   return pq->length;
}

canonical_original_code:
unsigned int size_PQueue(struct _pq *pq) {
   return pq->length;
}


decompiled_code:
int __fastcall printPriorities_PQueue(__int64 a1, void (__fastcall *a2)(_QWORD))
{
int result; // eax
int v3; // er12
int v4; // er13
int v5; // ebx
__int64 v6; // r14
int v7; // [rsp+8h] [rbp-40h]
int v8; // [rsp+Ch] [rbp-3Ch]

result = *(_DWORD *)(a1 + 12);
v3 = result / 2;
v8 = 1;
v4 = 0;
if ( result > 0 )
{
do
{
if ( v8 > 0 )
{
v6 = 8LL * v4;
v7 = v4 + v8;
do
{
if ( *(_DWORD *)(a1 + 12) <= v4 )
break;
v5 = 0;
if ( v3 )
{
do
{
printf(" ");
if ( a2 )
a2(0LL);
++v5;
}
while ( v5 != v3 );
}
printf("%3d", *(unsigned int *)(*(_QWORD *)(*(_QWORD *)a1 + v6) + 8LL));
if ( a2 )
a2(**(_QWORD **)(*(_QWORD *)a1 + v6));
++v4;
v6 += 8LL;
}
while ( v7 != v4 );
}
v3 /= 2;
v8 *= 2;
result = putchar(10);
}
while ( *(_DWORD *)(a1 + 12) > v4 );
}
return result;
}

original_code:
void printPriorities_PQueue(PQueue pq, anyPrintDelegate printer) {
   int i;
   int space;
   int spacing;
   int col;
   int rowLength;
   spacing = pq->length/2;
   rowLength = 1;
   i = 0;
   while (i < pq->length) {
      for (col = 0; col < rowLength && i < pq->length; ++col) {
         for (space = 0; space != spacing; ++space) {
            printf("   ");
            if (printer != ((void *)0)) {
               printer((any_t)((void *)0));
            }
         }
         printf("%3d", pq->elements[i]->priority);
         if (printer != ((void *)0)) {
            printer(pq->elements[i]->value);
         }
         i++;
      }
      spacing /= 2;
      rowLength *= 2;
      printf("\n");
   }
}

canonical_original_code:
void printPriorities_PQueue(struct _pq *pq, void (*printer)(unsigned long)) {
   int i;
   int space;
   int spacing;
   int col;
   int rowLength;
   spacing = pq->length/2;
   rowLength = 1;
   i = 0;
   while (i < pq->length) {
      for (col = 0; col < rowLength && i < pq->length; ++col) {
         for (space = 0; space != spacing; ++space) {
            printf("   ");
            if (printer != ((void *)0)) {
               printer((any_t)((void *)0));
            }
         }
         printf("%3d", pq->elements[i]->priority);
         if (printer != ((void *)0)) {
            printer(pq->elements[i]->value);
         }
         i++;
      }
      spacing /= 2;
      rowLength *= 2;
      printf("\n");
   }
}

variable_types:
printer
void (*)(unsigned long)

variable_types: i int

variable_types: space int

variable_types: spacing int

variable_types: col int

variable_types: rowLength int


keymapHash

decompiled_code:
__int64 __fastcall keymapHash(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1;
}

original_code:
static unsigned int keymapHash(any_t value) {
   return (unsigned int)value;
}

canonical_original_code:
static unsigned int keymapHash(unsigned long value) {
   return (unsigned int)value;
}

variable_types:
value
unsigned long


decompiled_code:
__int64 send_net()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
int send_net(net_address_t address, protocol_t protocol) {
    return 0;
}

canonical_original_code:
int send_net(int address, struct protocol protocol) {
    return 0;
}

variable_types: address int

variable_types:
protocol
struct protocol {  }


version

repo: ddribin/kents-nes-stuff

decompiled_code:
void __noreturn version()
{
puts(program_version);
exit(0);
}

canonical_decompiled_code:
void __noreturn func9()
{
puts(program_version);
exit(0);
}

original_code:
static void version()
{
    printf("%s\n", program_version);
    exit(0);
}


original_code:
void pack_chr(const char *chr_in, int sz_in, int null_tile, int nametable_base,
              char **chr_out, long *sz_out, unsigned char *nametable)
{
    static const char null_tile_data[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    long buf_sz = 0;
    long pos_in = 0;
    long pos_out = 0;
    long nametable_pos = 0;
    int warn_wraparound = 1;
    *chr_out = 0;
    while (pos_in < sz_in) {
 long i;
 const char *tile_in = &chr_in[pos_in];
 const int is_null_tile = !memcmp(tile_in, null_tile_data, 16);
 if (!is_null_tile || (null_tile == -1)) {
     for (i = 0; i < pos_out; i += 16) {
  if (!memcmp(tile_in, &(*chr_out)[i], 16))
      break;
     }
     if (i == pos_out) {
  if (pos_out == buf_sz) {
      buf_sz += 1024;
      *chr_out = realloc(*chr_out, buf_sz);
      ((void) sizeof ((*chr_out) ? 1 : 0), __extension__ ({ if (*chr_out) ; else __assert_fail ("*chr_out", "packchr.c", 92, __extension__ __PRETTY_FUNCTION__); }));
  }
  memcpy(&(*chr_out)[pos_out], tile_in, 16);
  pos_out += 16;
     }
     int tile_index = (i / 16) + nametable_base;
     if ((tile_index >= 256) && warn_wraparound) {
  fprintf(stderr, "packchr: warning: tile index >= 256 (wrap-around); "
   "you should reduce the size and/or detail of the input and retry\n");
  warn_wraparound = 0;
     }
     nametable[nametable_pos] = (unsigned char)tile_index;
 } else {
     nametable[nametable_pos] = (unsigned char)null_tile;
 }
 ++nametable_pos;
 pos_in += 16;
    }
    *sz_out = pos_out;
    ((void) sizeof (((sz_in/16) == nametable_pos) ? 1 : 0), __extension__ ({ if ((sz_in/16) == nametable_pos) ; else __assert_fail ("(sz_in/16) == nametable_pos", "packchr.c", 111, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void pack_chr(char *chr_in, int sz_in, int null_tile, int nametable_base, char **chr_out, long *sz_out, unsigned char *nametable)
{
    static char null_tile_data[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    long buf_sz = 0;
    long pos_in = 0;
    long pos_out = 0;
    long nametable_pos = 0;
    int warn_wraparound = 1;
    *chr_out = 0;
    while (pos_in < sz_in) {
 long i;
 char *tile_in = &chr_in[pos_in];
 int is_null_tile = !memcmp(tile_in, null_tile_data, 16);
 if (!is_null_tile || (null_tile == -1)) {
     for (i = 0; i < pos_out; i += 16) {
  if (!memcmp(tile_in, &(*chr_out)[i], 16))
      break;
     }
     if (i == pos_out) {
  if (pos_out == buf_sz) {
      buf_sz += 1024;
      *chr_out = realloc(*chr_out, buf_sz);
      ((void) sizeof ((*chr_out) ? 1 : 0), __extension__ ({ if (*chr_out) ; else __assert_fail ("*chr_out", "packchr.c", 92, __extension__ __PRETTY_FUNCTION__); }));
  }
  memcpy(&(*chr_out)[pos_out], tile_in, 16);
  pos_out += 16;
     }
     int tile_index = (i / 16) + nametable_base;
     if ((tile_index >= 256) && warn_wraparound) {
  fprintf(stderr, "packchr: warning: tile index >= 256 (wrap-around); "
   "you should reduce the size and/or detail of the input and retry\n");
  warn_wraparound = 0;
     }
     nametable[nametable_pos] = (unsigned char)tile_index;
 } else {
     nametable[nametable_pos] = (unsigned char)null_tile;
 }
 ++nametable_pos;
 pos_in += 16;
    }
    *sz_out = pos_out;
    ((void) sizeof (((sz_in/16) == nametable_pos) ? 1 : 0), __extension__ ({ if ((sz_in/16) == nametable_pos) ; else __assert_fail ("(sz_in/16) == nametable_pos", "packchr.c", 111, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types:
nametable
unsigned char *

variable_types: i long


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

result = (unsigned int)*a2;
v3 = *(_BYTE *)(a1 + (int)result);
if ( v3 == 9 || v3 == 32 )
{
result = (int)result + 1;
do
{
do
{
*a2 = result;
v4 = *(_BYTE *)(a1 + result++);
}
while ( v4 == 9 );
}
while ( v4 == 32 );
}
return result;
}

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

result = (unsigned int)*a2;
v3 = *(_BYTE *)(a1 + (int)result);
if ( v3 == 9 || v3 == 32 )
{
result = (int)result + 1;
do
{
do
{
*a2 = result;
v4 = *(_BYTE *)(a1 + result++);
}
while ( v4 == 9 );
}
while ( v4 == 32 );
}
return result;
}

variable_types:
s
char *

variable_types:
i
int *


original_code:
static int get_key(char *s, int *i, char *d)
{
    char key;
    key = s[(*i)++];
    if ((key == '\0') || (key == '\n')) { return 0; }
    if (key == '\\') {
        key = s[(*i)++];
        if ((key == '\0') || (key == '\n')) { return 0; }
        switch (key) {
            case '0': key = '\0'; break;
            case 'a': key = '\a'; break;
            case 'b': key = '\b'; break;
            case 't': key = '\t'; break;
            case 'f': key = '\f'; break;
            case 'n': key = '\n'; break;
            case 'r': key = '\r'; break;
        }
    }
    *d = key;
    return 1;
}

variable_types:
d
char *

variable_types: key char


maperr

decompiled_code:
int maperr(const char *a1, unsigned int a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a3);
fprintf(stderr, "error: %s:%d: ", a1, a2);
vfprintf(stderr, a3, arg);
return fputc(10, stderr);
}

canonical_decompiled_code:
int func2(const char *a1, unsigned int a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a3);
fprintf(stderr, "error: %s:%d: ", a1, a2);
vfprintf(stderr, a3, arg);
return fputc(10, stderr);
}

original_code:
static void maperr(const char *filename, int line, char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    fprintf(stderr, "error: %s:%d: ", filename, line);
    vfprintf(stderr, fmt, ap);
    fprintf(stderr, "\n");
    __builtin_va_end(ap);
}

canonical_original_code:
static void maperr(char *filename, int line, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    fprintf(stderr, "error: %s:%d: ", filename, line);
    vfprintf(stderr, fmt, ap);
    fprintf(stderr, "\n");
    __builtin_va_end(ap);
}

variable_types:
filename
char *

variable_types: line int

variable_types:
fmt
char *


original_code:
void xm_destroy(struct xm *xm)
{
    int i;
    for (i = 0; i < xm->header.pattern_count; ++i)
        free(xm->patterns[i].data);
    free(xm->patterns);
}

variable_types: struct xm { struct xm_header { char id_text[17]; char module_name[20]; char pad1a; char tracker_name[20]; unsigned short version; unsigned int header_size; unsigned short song_length; unsigned short restart_position; unsigned short channel_count; unsigned short pattern_count; unsigned short instrument_count; unsigned short flags; unsigned short default_tempo; unsigned short default_bpm; unsigned char pattern_order_table[256]; } header; struct xm_pattern { int row_count; struct xm_pattern_slot { unsigned char note; unsigned char instrument; unsigned char volume; unsigned char effect_type; unsigned char effect_param; } *data; } *patterns; } *

variable_types: i int

user_defined_types: struct xm { struct xm_header header; struct xm_pattern *patterns; }

user_defined_types: struct xm_pattern { int row_count; struct xm_pattern_slot *data; }


decompiled_code:
float __fastcall note_hz(int a1)
{
return pow(2.0, (double)(a1 - 57) / 12.0) * 440.0;
}

canonical_decompiled_code:
float __fastcall func2(int a1)
{
return pow(2.0, (double)(a1 - 57) / 12.0) * 440.0;
}

original_code:
static float note_hz(int note)
{
    return pow(2, (note - 57) / 12.0) * 440;
}

variable_types: note int

return_type: float


version

canonical_decompiled_code:
void __noreturn func3()
{
puts(program_version);
exit(0);
}

canonical_original_code:
static void version()
{
    printf("%s\n", program_version);
    exit(0);
}


decompiled_code:
__int64 __fastcall get_ident(__int64 a1, int a2)
{
const unsigned __int16 *v3; // rsi
__int64 v4; // rax
unsigned int v5; // ecx
__int64 v6; // rdx

v3 = *_ctype_b_loc();
v4 = 0LL;
do
{
v5 = v4;
v6 = *(char *)(a1 + a2 + v4++);
}
while ( (v3[v6] & 0x400) != 0 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
const unsigned __int16 *v3; // rsi
__int64 v4; // rax
unsigned int v5; // ecx
__int64 v6; // rdx

v3 = *_ctype_b_loc();
v4 = 0LL;
do
{
v5 = v4;
v6 = *(char *)(a1 + a2 + v4++);
}
while ( (v3[v6] & 0x400) != 0 );
return v5;
}

original_code:
static int get_ident(char *s, int i)
{
    int len = 0;
    while (((*__ctype_b_loc ())[(int) ((s[i+len]))] & (unsigned short int) _ISalpha))
        ++len;
    return len;
}

canonical_original_code:
static int get_ident(char *s, int i)
{
    int len = 0;
    while (((*__ctype_b_loc ())[(int) ((s[i+len]))] & (unsigned short) _ISalpha))
        ++len;
    return len;
}

variable_types: len int


kmpGetNext

original_code:
void kmpGetNext(void)
{
 int i = 0, j = -1;
 b[i] = j;
 while (i < m)
 {
  while (j >= 0 && p[i] != p[j])
   j = b[j];
  i++;
  j++;
  b[i] = j;
 }
 return;
}

canonical_original_code:
void kmpGetNext()
{
 int i = 0; int j = -1;
 b[i] = j;
 while (i < m)
 {
  while (j >= 0 && p[i] != p[j])
   j = b[j];
  i++;
  j++;
  b[i] = j;
 }
 return;
}

variable_types: j int


kmpSearch

original_code:
void kmpSearch(void)
{
 int i = 0, j = 0;
 while (i < n)
 {
  while (j >= 0 && t[i] !=p [j])
   j =b [j];
  i++;
  j++;
  if (j == m)
  {
   j = b[j];
  }
 }
 return;
}

canonical_original_code:
void kmpSearch()
{
 int i = 0; int j = 0;
 while (i < n)
 {
  while (j >= 0 && t[i] !=p [j])
   j =b [j];
  i++;
  j++;
  if (j == m)
  {
   j = b[j];
  }
 }
 return;
}


original_code:
void kmpSearch2(void)
{
 int i = 0, j = 0;
 while (i < n)
 {
  while (j >= 0 && t2[i] !=p [j])
   j = b[j];
  i++;
  j++;
  if (j == m)
  {
   j = b[j];
  }
 }
 return;
}

canonical_original_code:
void kmpSearch2()
{
 int i = 0; int j = 0;
 while (i < n)
 {
  while (j >= 0 && t2[i] !=p [j])
   j = b[j];
  i++;
  j++;
  if (j == m)
  {
   j = b[j];
  }
 }
 return;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
kmpGetNext();
kmpSearch();
kmpSearch2();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func6();
func7();
func8();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 kmpGetNext();
 kmpSearch();
 kmpSearch2();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: deardaniel/PizzaTest

decompiled_code:
__int64 __fastcall val_relation(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_relation )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "relation");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_relation )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "relation");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

original_code: cst_relation *val_relation(const cst_val *v) { if (v && ((v)->c.a.type) == cst_val_type_relation) return (cst_relation *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "relation", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

canonical_original_code: struct cst_relation_struct *val_relation(struct cst_val_struct *v) { if (v && ((v)->c.a.type) == cst_val_type_relation) return (struct cst_relation_struct *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "relation", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

variable_types:
v
struct cst_val_struct *

return_type: struct cst_relation_struct { char *name; struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *utterance; struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *head; struct cst_item_struct *tail; } *

user_defined_types: struct cst_relation_struct { char *name; struct cst_features_struct *features; struct cst_utterance_struct *utterance; struct cst_item_struct *head; struct cst_item_struct *tail; }

user_defined_types: struct cst_features_struct { struct cst_featvalpair_struct *head; void *ctx; }

user_defined_types: struct cst_item_struct { struct cst_item_contents_struct *contents; struct cst_relation_struct *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; }

user_defined_types: struct cst_featvalpair_struct { char *name; struct cst_val_struct *val; struct cst_featvalpair_struct *next; }

user_defined_types: struct cst_val_struct { union { struct cst_val_cons_struct cc; struct cst_val_atom_struct a; } c; }


decompiled_code:
__int64 __fastcall relation_val(__int64 a1)
{
return val_new_typed(cst_val_type_relation, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return val_new_typed(cst_val_type_relation, a1);
}

original_code: cst_val *relation_val(const cst_relation *v) { return val_new_typed(cst_val_type_relation, (void *)v); }

canonical_original_code: struct cst_val_struct *relation_val(struct cst_relation_struct *v) { return val_new_typed(cst_val_type_relation, (void *)v); }

variable_types: struct cst_relation_struct { char *name; struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *utterance; struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *head; struct cst_item_struct *tail; } *

return_type: struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } *


decompiled_code:
__int64 __fastcall val_item(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_item )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "item");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_item )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "item");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

original_code: cst_item *val_item(const cst_val *v) { if (v && ((v)->c.a.type) == cst_val_type_item) return (cst_item *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "item", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

canonical_original_code: struct cst_item_struct *val_item(struct cst_val_struct *v) { if (v && ((v)->c.a.type) == cst_val_type_item) return (struct cst_item_struct *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "item", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

return_type: struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct { char *name; struct cst_features_struct *features; struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *utterance; struct cst_item_struct *head; struct cst_item_struct *tail; } *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *

user_defined_types: struct cst_item_contents_struct { struct cst_features_struct *features; struct cst_features_struct *relations; }


decompiled_code:
__int64 __fastcall item_val(__int64 a1)
{
return val_new_typed(cst_val_type_item, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return val_new_typed(cst_val_type_item, a1);
}

original_code: cst_val *item_val(const cst_item *v) { return val_new_typed(cst_val_type_item, (void *)v); }

canonical_original_code: struct cst_val_struct *item_val(struct cst_item_struct *v) { return val_new_typed(cst_val_type_item, (void *)v); }

variable_types: struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct { char *name; struct cst_features_struct *features; struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *utterance; struct cst_item_struct *head; struct cst_item_struct *tail; } *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *

user_defined_types: struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; }

user_defined_types: struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; }