yyparse

decompiled_code:
__int64 yyparse()
{
int v0; // ebp
unsigned __int64 v1; // r14
char *v2; // r12
__int16 *v3; // rbx
__int16 *v4; // r13
int v5; // edx
unsigned int v6; // er15
__int16 *v7; // rcx
char *v8; // r15
int v9; // edx
unsigned __int8 v10; // bp
int v11; // eax
int v12; // esi
unsigned int v13; // edx
unsigned __int64 v14; // rax
signed __int64 v15; // r12
__int16 *v16; // rax
__int16 *v17; // r15
size_t v18; // rdx
int v19; // er15
unsigned __int8 v20; // al
__int16 *v21; // rax
unsigned int v22; // ebp
size_t v23; // r15
size_t v24; // rax
char *v25; // r15
__int64 v26; // rax
size_t v27; // r15
size_t v28; // rax
char *v29; // rsi
int v30; // eax
unsigned int v31; // eax
char *v33; // [rsp+8h] [rbp-830h]
int v34; // [rsp+14h] [rbp-824h]
char *v35; // [rsp+18h] [rbp-820h]
char *v36; // [rsp+20h] [rbp-818h]
__int16 *v37; // [rsp+28h] [rbp-810h]
char v38[1600]; // [rsp+30h] [rbp-808h] BYREF
__int16 src[228]; // [rsp+670h] [rbp-1C8h] BYREF

yynerrs = 0;
yychar = -2;
src[0] = 0;
v34 = 0;
v0 = 0;
v1 = 200LL;
v2 = v38;
v33 = v38;
v3 = src;
v4 = src;
while ( 1 )
{
v19 = yypact[v0];
if ( v19 == -7 )
break;
if ( yychar == -2 )
yychar = yylex();
if ( yychar <= 0 )
{
yychar = 0;
v5 = 0;
}
else
{
v5 = 2;
if ( (unsigned int)yychar <= 0x108 )
v5 = (unsigned __int8)yytranslate[yychar];
}
v6 = v5 + v19;
if ( v6 > 0xD || (unsigned __int8)yycheck[v6] != v5 )
break;
v0 = (unsigned __int8)yytable[v6];
if ( yytable[v6] )
{
v34 = (v34 == 0) + v34 - 1;
yychar = -2;
*((_QWORD *)v2 + 1) = yylval;
v2 += 8;
v7 = v3;
goto LABEL_11;
}
v8 = (char *)*((_QWORD *)v2 + 1);
v9 = 0;
v10 = 0;
LABEL_8:
v7 = &v3[-v10];
v2 = &v2[-8 * v10 + 8];
*(_QWORD *)v2 = v8;
v11 = (unsigned __int8)yyr1[v9] - 10;
v12 = *v7;
v13 = v12 + yypgoto[v11];
if ( v13 <= 0xD && v12 == (unsigned __int8)yycheck[v13] )
v0 = (unsigned __int8)yytable[v13];
else
v0 = yydefgoto[v11];
LABEL_11:
v3 = v7 + 1;
v7[1] = v0;
v14 = 2 * v1;
if ( v7 + 1 >= &v4[v1 - 1] )
{
v15 = (char *)v3 - (char *)v4;
v35 = (char *)(v3 - v4 + 1);
if ( v1 > 0x270F )
goto LABEL_55;
v1 = 10000LL;
if ( v14 <= 0x2710 )
v1 = v14;
v16 = (__int16 *)malloc(10 * v1 + 7);
v17 = v16;
if ( !v16 )
{
LABEL_55:
yyerror("memory exhausted");
v21 = v3;
v3 = v4;
v22 = 2;
goto LABEL_57;
}
memcpy(v16, v4, v15 + 2);
v18 = 8LL * (_QWORD)v35;
v36 = (char *)(8LL * (_QWORD)v35);
v35 = (char *)(2 * v1);
v37 = &v17[v1];
memcpy(v37, v33, v18);
if ( v4 != src )
free(v4);
v3 = (__int16 *)((char *)v17 + v15);
v2 = &v36[(_QWORD)v37 - 8];
if ( (char *)v3 >= &v35[(_QWORD)v17 - 2] )
{
if ( v17 == v3 )
{
v3 = v17;
v22 = 1;
goto LABEL_60;
}
v21 = v3;
v3 = v17;
v22 = 1;
goto LABEL_58;
}
v33 = (char *)v37;
v4 = v17;
}
if ( v0 == 3 )
{
v21 = v3;
v3 = v4;
v22 = 0;
goto LABEL_57;
}
}
v20 = yydefact[v0];
v9 = v20;
if ( v20 )
{
v10 = yyr2[v20];
v8 = *(char **)&v2[8 * (1 - v10)];
switch ( v20 )
{
case 4u:
add(d, *((_QWORD *)v2 - 3), *((_QWORD *)v2 - 1));
v9 = 4;
break;
case 5u:
v8 = (char *)&unk_610;
break;
case 6u:
v35 = (char *)*((_QWORD *)v2 - 1);
v23 = strlen(v35);
v36 = *(char **)v2;
v24 = strlen(v36);
v8 = (char *)GC_malloc(v23 + v24 + 1);
strcpy(v8, v35);
strcat(v8, v36);
v9 = 6;
break;
case 7u:
v25 = (char *)*((_QWORD *)v2 - 1);
v26 = find(d, v25);
if ( v26 )
v25 = (char *)v26;
v36 = v25;
v27 = strlen(v25);
v35 = *(char **)v2;
v28 = strlen(v35);
v8 = (char *)GC_malloc(v27 + v28 + 1);
strcpy(v8, v36);
strcat(v8, v35);
v9 = 7;
break;
case 0xAu:
printf("%s", *(const char **)v2);
v9 = 10;
break;
case 0xBu:
v35 = *(char **)v2;
v29 = (char *)find(d, v35);
if ( !v29 )
v29 = v35;
printf("%s", v29);
v9 = 11;
break;
case 0xCu:
putchar(10);
v9 = 12;
break;
default:
goto LABEL_8;
}
goto LABEL_8;
}
if ( !v34 )
{
++yynerrs;
yyerror("syntax error");
goto LABEL_50;
}
if ( v34 == 3 )
{
if ( yychar > 0 )
{
yychar = -2;
goto LABEL_50;
}
if ( !yychar )
{
v21 = v3;
v3 = v4;
v22 = 1;
LABEL_57:
if ( v21 == v3 )
goto LABEL_59;
do
LABEL_58:
--v21;
while ( v21 != v3 );
goto LABEL_59;
}
}
while ( 1 )
{
LABEL_50:
v30 = yypact[v0];
if ( v30 != -7 )
{
v31 = v30 + 1;
if ( v31 <= 0xD && yycheck[v31] == 1 )
{
v0 = (unsigned __int8)yytable[v31];
if ( yytable[v31] )
{
*((_QWORD *)v2 + 1) = yylval;
v2 += 8;
v7 = v3;
v34 = 3;
goto LABEL_11;
}
}
}
if ( v3 == v4 )
break;
v2 -= 8;
v0 = *--v3;
}
v22 = 1;
LABEL_59:
if ( v3 == src )
return v22;
LABEL_60:
free(v3);
return v22;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // ebp
unsigned __int64 v1; // r14
char *v2; // r12
__int16 *v3; // rbx
__int16 *v4; // r13
int v5; // edx
unsigned int v6; // er15
__int16 *v7; // rcx
char *v8; // r15
int v9; // edx
unsigned __int8 v10; // bp
int v11; // eax
int v12; // esi
unsigned int v13; // edx
unsigned __int64 v14; // rax
signed __int64 v15; // r12
__int16 *v16; // rax
__int16 *v17; // r15
size_t v18; // rdx
int v19; // er15
unsigned __int8 v20; // al
__int16 *v21; // rax
unsigned int v22; // ebp
size_t v23; // r15
size_t v24; // rax
char *v25; // r15
__int64 v26; // rax
size_t v27; // r15
size_t v28; // rax
char *v29; // rsi
int v30; // eax
unsigned int v31; // eax
char *v33; // [rsp+8h] [rbp-830h]
int v34; // [rsp+14h] [rbp-824h]
char *v35; // [rsp+18h] [rbp-820h]
char *v36; // [rsp+20h] [rbp-818h]
__int16 *v37; // [rsp+28h] [rbp-810h]
char v38[1600]; // [rsp+30h] [rbp-808h] BYREF
__int16 src[228]; // [rsp+670h] [rbp-1C8h] BYREF

yynerrs = 0;
yychar = -2;
src[0] = 0;
v34 = 0;
v0 = 0;
v1 = 200LL;
v2 = v38;
v33 = v38;
v3 = src;
v4 = src;
while ( 1 )
{
v19 = yypact[v0];
if ( v19 == -7 )
break;
if ( yychar == -2 )
yychar = yylex();
if ( yychar <= 0 )
{
yychar = 0;
v5 = 0;
}
else
{
v5 = 2;
if ( (unsigned int)yychar <= 0x108 )
v5 = (unsigned __int8)yytranslate[yychar];
}
v6 = v5 + v19;
if ( v6 > 0xD || (unsigned __int8)yycheck[v6] != v5 )
break;
v0 = (unsigned __int8)yytable[v6];
if ( yytable[v6] )
{
v34 = (v34 == 0) + v34 - 1;
yychar = -2;
*((_QWORD *)v2 + 1) = yylval;
v2 += 8;
v7 = v3;
goto LABEL_11;
}
v8 = (char *)*((_QWORD *)v2 + 1);
v9 = 0;
v10 = 0;
LABEL_8:
v7 = &v3[-v10];
v2 = &v2[-8 * v10 + 8];
*(_QWORD *)v2 = v8;
v11 = (unsigned __int8)yyr1[v9] - 10;
v12 = *v7;
v13 = v12 + yypgoto[v11];
if ( v13 <= 0xD && v12 == (unsigned __int8)yycheck[v13] )
v0 = (unsigned __int8)yytable[v13];
else
v0 = yydefgoto[v11];
LABEL_11:
v3 = v7 + 1;
v7[1] = v0;
v14 = 2 * v1;
if ( v7 + 1 >= &v4[v1 - 1] )
{
v15 = (char *)v3 - (char *)v4;
v35 = (char *)(v3 - v4 + 1);
if ( v1 > 0x270F )
goto LABEL_55;
v1 = 10000LL;
if ( v14 <= 0x2710 )
v1 = v14;
v16 = (__int16 *)malloc(10 * v1 + 7);
v17 = v16;
if ( !v16 )
{
LABEL_55:
yyerror("memory exhausted");
v21 = v3;
v3 = v4;
v22 = 2;
goto LABEL_57;
}
memcpy(v16, v4, v15 + 2);
v18 = 8LL * (_QWORD)v35;
v36 = (char *)(8LL * (_QWORD)v35);
v35 = (char *)(2 * v1);
v37 = &v17[v1];
memcpy(v37, v33, v18);
if ( v4 != src )
free(v4);
v3 = (__int16 *)((char *)v17 + v15);
v2 = &v36[(_QWORD)v37 - 8];
if ( (char *)v3 >= &v35[(_QWORD)v17 - 2] )
{
if ( v17 == v3 )
{
v3 = v17;
v22 = 1;
goto LABEL_60;
}
v21 = v3;
v3 = v17;
v22 = 1;
goto LABEL_58;
}
v33 = (char *)v37;
v4 = v17;
}
if ( v0 == 3 )
{
v21 = v3;
v3 = v4;
v22 = 0;
goto LABEL_57;
}
}
v20 = yydefact[v0];
v9 = v20;
if ( v20 )
{
v10 = yyr2[v20];
v8 = *(char **)&v2[8 * (1 - v10)];
switch ( v20 )
{
case 4u:
add(d, *((_QWORD *)v2 - 3), *((_QWORD *)v2 - 1));
v9 = 4;
break;
case 5u:
v8 = (char *)&unk_610;
break;
case 6u:
v35 = (char *)*((_QWORD *)v2 - 1);
v23 = strlen(v35);
v36 = *(char **)v2;
v24 = strlen(v36);
v8 = (char *)GC_malloc(v23 + v24 + 1);
strcpy(v8, v35);
strcat(v8, v36);
v9 = 6;
break;
case 7u:
v25 = (char *)*((_QWORD *)v2 - 1);
v26 = find(d, v25);
if ( v26 )
v25 = (char *)v26;
v36 = v25;
v27 = strlen(v25);
v35 = *(char **)v2;
v28 = strlen(v35);
v8 = (char *)GC_malloc(v27 + v28 + 1);
strcpy(v8, v36);
strcat(v8, v35);
v9 = 7;
break;
case 0xAu:
printf("%s", *(const char **)v2);
v9 = 10;
break;
case 0xBu:
v35 = *(char **)v2;
v29 = (char *)find(d, v35);
if ( !v29 )
v29 = v35;
printf("%s", v29);
v9 = 11;
break;
case 0xCu:
putchar(10);
v9 = 12;
break;
default:
goto LABEL_8;
}
goto LABEL_8;
}
if ( !v34 )
{
++yynerrs;
yyerror("syntax error");
goto LABEL_50;
}
if ( v34 == 3 )
{
if ( yychar > 0 )
{
yychar = -2;
goto LABEL_50;
}
if ( !yychar )
{
v21 = v3;
v3 = v4;
v22 = 1;
LABEL_57:
if ( v21 == v3 )
goto LABEL_59;
do
LABEL_58:
--v21;
while ( v21 != v3 );
goto LABEL_59;
}
}
while ( 1 )
{
LABEL_50:
v30 = yypact[v0];
if ( v30 != -7 )
{
v31 = v30 + 1;
if ( v31 <= 0xD && yycheck[v31] == 1 )
{
v0 = (unsigned __int8)yytable[v31];
if ( yytable[v31] )
{
*((_QWORD *)v2 + 1) = yylval;
v2 += 8;
v7 = v3;
v34 = 3;
goto LABEL_11;
}
}
}
if ( v3 == v4 )
break;
v2 -= 8;
v0 = *--v3;
}
v22 = 1;
LABEL_59:
if ( v3 == src )
return v22;
LABEL_60:
free(v3);
return v22;
}

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 == 3)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-7))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 264 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 13 < 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:
    {add(d, (yyvsp[-3].str), (yyvsp[-1].str));}
    break;
  case 5:
    {(yyval.str) = "";}
    break;
  case 6:
    {(yyval.str) = GC_malloc(sizeof(char) * (strlen((yyvsp[-1].str)) + strlen((yyvsp[0].str)) + 1)); strcpy((yyval.str), (yyvsp[-1].str)); strcat((yyval.str), (yyvsp[0].str));}
    break;
  case 7:
    {char* con = find(d, (yyvsp[-1].str)); if (con == ((void *)0)) con = (yyvsp[-1].str); (yyval.str) = GC_malloc(sizeof(char) * (strlen(con) + strlen((yyvsp[0].str)) + 1)); strcpy((yyval.str), con);strcat((yyval.str), (yyvsp[0].str));}
    break;
  case 10:
    {printf("%s", (yyvsp[0].str));}
    break;
  case 11:
    {char *content = find(d, (yyvsp[0].str)); if (content == ((void *)0)) content = (yyvsp[0].str); printf("%s", content);}
    break;
  case 12:
    {printf("\n");}
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 10;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 13 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 264 ? 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) == (-7))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 13 && 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) <= 264 ? 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 == 3)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-7))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 264 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 13 < 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:
    {add(d, (yyvsp[-3].str), (yyvsp[-1].str));}
    break;
  case 5:
    {(yyval.str) = "";}
    break;
  case 6:
    {(yyval.str) = GC_malloc(sizeof(char) * (strlen((yyvsp[-1].str)) + strlen((yyvsp[0].str)) + 1)); strcpy((yyval.str), (yyvsp[-1].str)); strcat((yyval.str), (yyvsp[0].str));}
    break;
  case 7:
    {char *con = find(d, (yyvsp[-1].str)); if (con == ((void *)0)) con = (yyvsp[-1].str); (yyval.str) = GC_malloc(sizeof(char) * (strlen(con) + strlen((yyvsp[0].str)) + 1)); strcpy((yyval.str), con);strcat((yyval.str), (yyvsp[0].str));}
    break;
  case 10:
    {printf("%s", (yyvsp[0].str));}
    break;
  case 11:
    {char *content = find(d, (yyvsp[0].str)); if (content == ((void *)0)) content = (yyvsp[0].str); printf("%s", content);}
    break;
  case 12:
    {printf("\n");}
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 10;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 13 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 264 ? 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) == (-7))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 13 && 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) <= 264 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

variable_types: yystate int

variable_types: yyerrstatus int

variable_types:
yyssa
short [200]

variable_types:
yyss
short *

variable_types:
yyssp
short *

variable_types:
yyvsa
union YYSTYPE { char *str; } [200]

variable_types:
yyvs
union YYSTYPE { char *str; } *

variable_types:
yyvsp
union YYSTYPE { char *str; } *

variable_types:
yystacksize
unsigned long

variable_types: yyn int

variable_types: yyresult int

variable_types: yytoken int

variable_types:
yyval
union YYSTYPE { char *str; }

variable_types: yylen int

variable_types:
yysize
unsigned long

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

variable_types:
yynewbytes
unsigned long

variable_types:
con
char *

variable_types: yylhs int

variable_types: yyi int

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


main

canonical_name: main

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

if ( argc == 2 )
{
yyin = fopen(argv[1], "r");
if ( yyin )
{
GC_init();
d = GC_malloc(8LL);
yyparse();
fclose(yyin);
result = 0;
}
else
{
puts("File does not exist");
result = 1;
}
}
else
{
puts("We need the file name!");
result = 1;
}
return result;
}

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

if ( argc == 2 )
{
yyin = fopen(argv[1], "r");
if ( yyin )
{
GC_init();
d = GC_malloc(8LL);
func0();
fclose(yyin);
result = 0;
}
else
{
puts("File does not exist");
result = 1;
}
}
else
{
puts("We need the file name!");
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[]){
    if (argc == 2){
 yyin = fopen(argv[1], "r");
 if (yyin == ((void *)0)) {
     printf("File does not exist\n");
     return 1;
 }
    } else {
 printf("We need the file name!\n");
 return 1;
    }
    { ; ; ; ; ; ; ; ; ; GC_init(); ; ; ; };
    d = GC_malloc(sizeof(dict));
    yyparse();
    fclose(yyin);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


usage

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"Canon Pixma Scanner Driver %s\n"
"Copyright (C) 2006 Martin Schewe <pixma@schewe.com>\n"
"\n"
"Usage: pixma_scan [OPTION]... -o <outfile.pnm>\n"
"\n"
"-r <resolution> set resolution in dpi (default: 75)\n"
"-x <x> -y <y> set image offset\n"
"-w <width> -h <height> set image size\n"
"-c calibrate before scanning\n"
"-a use ADF\n"
"-m use monochrome color weights\n"
"-v <level> set verbosity level (default: 1)\n"
"-o <outfile.pnm> write PNM image date to outfile.pnm\n",
"0.1");
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
fprintf(
stderr,
"Canon Pixma Scanner Driver %s\n"
"Copyright (C) 2006 Martin Schewe <pixma@schewe.com>\n"
"\n"
"Usage: pixma_scan [OPTION]... -o <outfile.pnm>\n"
"\n"
"-r <resolution> set resolution in dpi (default: 75)\n"
"-x <x> -y <y> set image offset\n"
"-w <width> -h <height> set image size\n"
"-c calibrate before scanning\n"
"-a use ADF\n"
"-m use monochrome color weights\n"
"-v <level> set verbosity level (default: 1)\n"
"-o <outfile.pnm> write PNM image date to outfile.pnm\n",
"0.1");
exit(1);
}

original_code:
void usage()
{
 fprintf(stderr,
  "Canon Pixma Scanner Driver %s\n"
  "Copyright (C) 2006  Martin Schewe  <pixma@schewe.com>\n\n"
  "Usage: pixma_scan [OPTION]... -o <outfile.pnm>\n\n"
  "-r <resolution>        set resolution in dpi (default: 75)\n"
  "-x <x>     -y <y>      set image offset\n"
  "-w <width> -h <height> set image size\n"
  "-c                     calibrate before scanning\n"
  "-a                     use ADF\n"
  "-m                     use monochrome color weights\n"
  "-v <level>             set verbosity level (default: 1)\n"
  "-o <outfile.pnm>       write PNM image date to outfile.pnm\n",
  "0.1");
 exit(1);
}

return_type: void


testAdf

decompiled_code:
__int64 testAdf()
{
unsigned int v0; // ebx

if ( (int)pixma_open() < 0 )
{
fwrite("Could not connect to scanner\n", 1uLL, 0x1DuLL, stderr);
v0 = 1;
}
else
{
pixma_init();
if ( (unsigned int)pixma_adf_is_ready() )
{
DBG(1LL, "There is a sheet in the ADF\n");
v0 = 0;
}
else
{
DBG(1LL, "There is NOT a sheet in the ADF\n");
v0 = 1;
}
pixma_close();
}
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx

if ( (int)pixma_open() < 0 )
{
fwrite("Could not connect to scanner\n", 1uLL, 0x1DuLL, stderr);
v0 = 1;
}
else
{
pixma_init();
if ( (unsigned int)pixma_adf_is_ready() )
{
DBG(1LL, "There is a sheet in the ADF\n");
v0 = 0;
}
else
{
DBG(1LL, "There is NOT a sheet in the ADF\n");
v0 = 1;
}
pixma_close();
}
return v0;
}

original_code:
int testAdf()
{
 int code = 1;
 if (pixma_open() < 0) {
  fprintf(stderr, "Could not connect to scanner\n");
  return code;
 }
 pixma_init();
 if (pixma_adf_is_ready()){
  DBG(1,"There is a sheet in the ADF\n");
  code = 0;
 } else {
  DBG(1, "There is NOT a sheet in the ADF\n");
 }
 pixma_close();
 return code;
}

variable_types: code int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er13
unsigned int v4; // er12
char *v5; // r14
int v6; // eax
__int64 v7; // rdx
int result; // eax
unsigned int v9; // eax
void *v10; // rbx
int v11; // [rsp+8h] [rbp-50h]
unsigned int v12; // [rsp+Ch] [rbp-4Ch]
unsigned int v13; // [rsp+10h] [rbp-48h]
int v14; // [rsp+14h] [rbp-44h]
unsigned int v15; // [rsp+18h] [rbp-40h]
unsigned int v16; // [rsp+1Ch] [rbp-3Ch]

v3 = 0;
v4 = 0;
v13 = 0;
v12 = 0;
v15 = 0;
v16 = 0;
v11 = 75;
v14 = 0;
v5 = 0LL;
while ( 2 )
{
v6 = getopt(argc, (char *const *)argv, "r:x:y:w:h:tcamv:o:");
if ( v6 != -1 )
{
switch ( v6 )
{
case 'a':
v15 = 1;
continue;
case 'c':
v14 = 1;
continue;
case 'h':
v3 = atoi(optarg);
continue;
case 'm':
v16 = 1;
continue;
case 'o':
v5 = strdup(optarg);
continue;
case 'r':
v11 = atoi(optarg);
continue;
case 't':
return testAdf();
case 'v':
v9 = atoi(optarg);
set_verbosity(v9);
continue;
case 'w':
v4 = atoi(optarg);
continue;
case 'x':
v12 = atoi(optarg);
continue;
case 'y':
v13 = atoi(optarg);
continue;
default:
usage();
return result;
}
}
break;
}
if ( !v5 )
usage();
if ( !v4 )
{
v7 = (unsigned int)(v11 >> 31);
LODWORD(v7) = v11 % 75;
v4 = 638 * (v11 / 75) - v12;
}
if ( !v3 )
{
v7 = (unsigned int)(v11 >> 31);
LODWORD(v7) = v11 % 75;
v3 = 877 * (v11 / 75) - v13;
}
if ( (int)pixma_open((unsigned int)argc, argv, v7) < 0 )
{
fwrite("Could not connect to scanner\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
pixma_init();
if ( !v15 )
{
if ( (int)pixma_set_resolution((unsigned int)v11) >= 0 )
goto LABEL_32;
LABEL_30:
fwrite("Resolution is not supported\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
if ( !(unsigned int)pixma_adf_is_ready() )
{
fwrite("There is no sheet in the ADF\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
if ( (int)pixma_set_resolution((unsigned int)v11) < 0 )
goto LABEL_30;
if ( !(unsigned int)pixma_adf_is_ready() )
{
fwrite("There is no sheet in the ADF\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
LABEL_32:
pixma_activate(1LL);
if ( v14 )
pixma_calibration();
pixma_scan_mode();
pixma_set_monochrome(v16);
pixma_set_adf(v15);
pixma_set_window(v12, v13, v4, v3);
pixma_setup();
pixma_gamma(1.0);
pixma_scan();
if ( (unsigned int)pixma_is_warming_up() )
{
DBG(1LL, "Lamp warmup in progress...\n");
sleep(0xFu);
}
v10 = malloc((int)(3 * v3 * v4));
pixma_get_img(v10);
pixma_close();
write_pnm(v10, v4, v3, v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er13
unsigned int v4; // er12
char *v5; // r14
int v6; // eax
__int64 v7; // rdx
int result; // eax
unsigned int v9; // eax
void *v10; // rbx
int v11; // [rsp+8h] [rbp-50h]
unsigned int v12; // [rsp+Ch] [rbp-4Ch]
unsigned int v13; // [rsp+10h] [rbp-48h]
int v14; // [rsp+14h] [rbp-44h]
unsigned int v15; // [rsp+18h] [rbp-40h]
unsigned int v16; // [rsp+1Ch] [rbp-3Ch]

v3 = 0;
v4 = 0;
v13 = 0;
v12 = 0;
v15 = 0;
v16 = 0;
v11 = 75;
v14 = 0;
v5 = 0LL;
while ( 2 )
{
v6 = getopt(argc, (char *const *)argv, "r:x:y:w:h:tcamv:o:");
if ( v6 != -1 )
{
switch ( v6 )
{
case 'a':
v15 = 1;
continue;
case 'c':
v14 = 1;
continue;
case 'h':
v3 = atoi(optarg);
continue;
case 'm':
v16 = 1;
continue;
case 'o':
v5 = strdup(optarg);
continue;
case 'r':
v11 = atoi(optarg);
continue;
case 't':
return func2();
case 'v':
v9 = atoi(optarg);
set_verbosity(v9);
continue;
case 'w':
v4 = atoi(optarg);
continue;
case 'x':
v12 = atoi(optarg);
continue;
case 'y':
v13 = atoi(optarg);
continue;
default:
func1();
return result;
}
}
break;
}
if ( !v5 )
func1();
if ( !v4 )
{
v7 = (unsigned int)(v11 >> 31);
LODWORD(v7) = v11 % 75;
v4 = 638 * (v11 / 75) - v12;
}
if ( !v3 )
{
v7 = (unsigned int)(v11 >> 31);
LODWORD(v7) = v11 % 75;
v3 = 877 * (v11 / 75) - v13;
}
if ( (int)pixma_open((unsigned int)argc, argv, v7) < 0 )
{
fwrite("Could not connect to scanner\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
pixma_init();
if ( !v15 )
{
if ( (int)pixma_set_resolution((unsigned int)v11) >= 0 )
goto LABEL_32;
LABEL_30:
fwrite("Resolution is not supported\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
if ( !(unsigned int)pixma_adf_is_ready() )
{
fwrite("There is no sheet in the ADF\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
if ( (int)pixma_set_resolution((unsigned int)v11) < 0 )
goto LABEL_30;
if ( !(unsigned int)pixma_adf_is_ready() )
{
fwrite("There is no sheet in the ADF\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
LABEL_32:
pixma_activate(1LL);
if ( v14 )
pixma_calibration();
pixma_scan_mode();
pixma_set_monochrome(v16);
pixma_set_adf(v15);
pixma_set_window(v12, v13, v4, v3);
pixma_setup();
pixma_gamma(1.0);
pixma_scan();
if ( (unsigned int)pixma_is_warming_up() )
{
DBG(1LL, "Lamp warmup in progress...\n");
sleep(0xFu);
}
v10 = malloc((int)(3 * v3 * v4));
pixma_get_img(v10);
pixma_close();
func0(v10, v4, v3, v5);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 unsigned char* img = ((void *)0);
 char* outfile = ((void *)0);
 int calibration = 0;
 int resolution = 75;
 int monochrome = 0;
 int adf = 0;
 int x = 0;
 int y = 0;
 int width = 0;
 int height = 0;
 int opt;
 while ((opt = getopt(argc, argv, "r:x:y:w:h:tcamv:o:")) != -1) {
  switch (opt) {
   case 'r':
    resolution = atoi(optarg);
    break;
   case 'x':
    x = atoi(optarg);
    break;
   case 'y':
    y = atoi(optarg);
    break;
   case 'w':
    width = atoi(optarg);
    break;
   case 'h':
    height = atoi(optarg);
    break;
   case 't':
    return testAdf();
    break;
   case 'c':
    calibration = 1;
    break;
   case 'a':
    adf = 1;
    break;
   case 'm':
    monochrome = 1;
    break;
   case 'v':
    set_verbosity(atoi(optarg));
    break;
   case 'o':
    outfile = strdup(optarg);
    break;
   default:
    usage();
  }
 }
 if (!outfile)
  usage();
 if (!width)
  width = (resolution / 75) * 638 - x;
 if (!height)
  height = (resolution / 75) * 877 - y;
 if (pixma_open() < 0) {
  fprintf(stderr, "Could not connect to scanner\n");
  exit(1);
 }
 pixma_init();
 if (adf && !pixma_adf_is_ready()) {
  fprintf(stderr, "There is no sheet in the ADF\n");
  exit(1);
 }
 if (pixma_set_resolution(resolution) < 0) {
  fprintf(stderr, "Resolution is not supported\n");
  exit(1);
 }
 if (adf && !pixma_adf_is_ready()) {
  fprintf(stderr, "There is no sheet in the ADF\n");
  exit(1);
 }
 pixma_activate(1);
 if (calibration)
  pixma_calibration();
 pixma_scan_mode();
 pixma_set_monochrome(monochrome);
 pixma_set_adf(adf);
 pixma_set_window(x, y, width, height);
 pixma_setup();
 pixma_gamma(1);
 pixma_scan();
 if (pixma_is_warming_up()) {
  DBG(1, "Lamp warmup in progress...\n");
  sleep(15);
 }
 img = malloc(3 * width * height);
 pixma_get_img(img);
 pixma_close();
 write_pnm(img, width, height, outfile);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned char *img = ((void *)0);
 char *outfile = ((void *)0);
 int calibration = 0;
 int resolution = 75;
 int monochrome = 0;
 int adf = 0;
 int x = 0;
 int y = 0;
 int width = 0;
 int height = 0;
 int opt;
 while ((opt = getopt(argc, argv, "r:x:y:w:h:tcamv:o:")) != -1) {
  switch (opt) {
   case 'r':
    resolution = atoi(optarg);
    break;
   case 'x':
    x = atoi(optarg);
    break;
   case 'y':
    y = atoi(optarg);
    break;
   case 'w':
    width = atoi(optarg);
    break;
   case 'h':
    height = atoi(optarg);
    break;
   case 't':
    return testAdf();
    break;
   case 'c':
    calibration = 1;
    break;
   case 'a':
    adf = 1;
    break;
   case 'm':
    monochrome = 1;
    break;
   case 'v':
    set_verbosity(atoi(optarg));
    break;
   case 'o':
    outfile = strdup(optarg);
    break;
   default:
    usage();
  }
 }
 if (!outfile)
  usage();
 if (!width)
  width = (resolution / 75) * 638 - x;
 if (!height)
  height = (resolution / 75) * 877 - y;
 if (pixma_open() < 0) {
  fprintf(stderr, "Could not connect to scanner\n");
  exit(1);
 }
 pixma_init();
 if (adf && !pixma_adf_is_ready()) {
  fprintf(stderr, "There is no sheet in the ADF\n");
  exit(1);
 }
 if (pixma_set_resolution(resolution) < 0) {
  fprintf(stderr, "Resolution is not supported\n");
  exit(1);
 }
 if (adf && !pixma_adf_is_ready()) {
  fprintf(stderr, "There is no sheet in the ADF\n");
  exit(1);
 }
 pixma_activate(1);
 if (calibration)
  pixma_calibration();
 pixma_scan_mode();
 pixma_set_monochrome(monochrome);
 pixma_set_adf(adf);
 pixma_set_window(x, y, width, height);
 pixma_setup();
 pixma_gamma(1);
 pixma_scan();
 if (pixma_is_warming_up()) {
  DBG(1, "Lamp warmup in progress...\n");
  sleep(15);
 }
 img = malloc(3 * width * height);
 pixma_get_img(img);
 pixma_close();
 write_pnm(img, width, height, outfile);
 return 0;
}

variable_types:
argv
char **

variable_types:
img
unsigned char *

variable_types:
outfile
char *

variable_types: calibration int

variable_types: resolution int

variable_types: monochrome int

variable_types: adf int

variable_types: x int

variable_types: y int

variable_types: width int

variable_types: height int

variable_types: opt int


decompiled_code:
__int64 pixma_open()
{
_QWORD *v0; // r9
__int64 *v1; // rbx
__int64 v2; // rax
const char *v3; // rdx
unsigned int v4; // ebp
int v6; // esi

usb_init();
usb_find_busses();
usb_find_devices();
v0 = (_QWORD *)usb_busses;
if ( !usb_busses )
return (unsigned int)-1;
while ( 1 )
{
v1 = (__int64 *)v0[515];
if ( v1 )
break;
LABEL_14:
v0 = (_QWORD *)*v0;
if ( !v0 )
return (unsigned int)-1;
}
while ( 1 )
{
model = ⊧
if ( models )
break;
LABEL_11:
v1 = (__int64 *)*v1;
if ( !v1 )
goto LABEL_14;
}
v6 = *((unsigned __int16 *)v1 + 2068);
v2 = (unsigned int)((_DWORD)&models + 40);
v3 = (const char *)models;
while ( v6 != *(_DWORD *)(v2 - 32) || *((unsigned __int16 *)v1 + 2069) != *(_DWORD *)(v2 - 28) )
{
model = v2;
v2 += 40LL;
v3 = *(const char **)(v2 - 40);
if ( !v3 )
goto LABEL_11;
}
DBG(1LL, "%s detected\n", v3);
v4 = *(_DWORD *)(model + 32LL);
if ( v4 == -1 )
{
DBG(1LL, "...but unsupported\n");
}
else
{
prot = (char *)&protocols + 20 * (int)v4;
devh = usb_open(v1);
v4 = usb_claim_interface(devh, *(unsigned int *)(model + 16LL));
}
return v4;
}

canonical_decompiled_code:
__int64 func0()
{
_QWORD *v0; // r9
__int64 *v1; // rbx
__int64 v2; // rax
const char *v3; // rdx
unsigned int v4; // ebp
int v6; // esi

usb_init();
usb_find_busses();
usb_find_devices();
v0 = (_QWORD *)usb_busses;
if ( !usb_busses )
return (unsigned int)-1;
while ( 1 )
{
v1 = (__int64 *)v0[515];
if ( v1 )
break;
LABEL_14:
v0 = (_QWORD *)*v0;
if ( !v0 )
return (unsigned int)-1;
}
while ( 1 )
{
model = ⊧
if ( models )
break;
LABEL_11:
v1 = (__int64 *)*v1;
if ( !v1 )
goto LABEL_14;
}
v6 = *((unsigned __int16 *)v1 + 2068);
v2 = (unsigned int)((_DWORD)&models + 40);
v3 = (const char *)models;
while ( v6 != *(_DWORD *)(v2 - 32) || *((unsigned __int16 *)v1 + 2069) != *(_DWORD *)(v2 - 28) )
{
model = v2;
v2 += 40LL;
v3 = *(const char **)(v2 - 40);
if ( !v3 )
goto LABEL_11;
}
DBG(1LL, "%s detected\n", v3);
v4 = *(_DWORD *)(model + 32LL);
if ( v4 == -1 )
{
DBG(1LL, "...but unsupported\n");
}
else
{
prot = (char *)&protocols + 20 * (int)v4;
devh = usb_open(v1);
v4 = usb_claim_interface(devh, *(unsigned int *)(model + 16LL));
}
return v4;
}

original_code:
int pixma_open()
{
 struct usb_bus *bus;
 struct usb_device *dev;
 usb_init();
 usb_find_busses();
 usb_find_devices();
 for (bus = usb_busses; bus; bus = bus->next)
  for (dev = bus->devices; dev; dev = dev->next)
   for (model = models; model->name; model++) {
    if (dev->descriptor.idVendor == model->vendor &&
        dev->descriptor.idProduct == model->product)
    {
     DBG(1, "%s detected\n", model->name);
     if (model->protocol == -1) {
      DBG(1, "...but unsupported\n");
      return -1;
     }
     prot = protocols + model->protocol;
     devh = usb_open(dev);
     return usb_claim_interface(devh,
       model->interface);
    }
   }
 return -1;
}

variable_types: struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus *bus; struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; } descriptor; struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface { struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; } *endpoint; unsigned char *extra; int extralen; } *altsetting; int num_altsetting; } *interface; unsigned char *extra; int extralen; } *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; } *devices; unsigned int location; struct usb_device *root_dev; } *

variable_types: struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device *devices; unsigned int location; struct usb_device *root_dev; } *bus; struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; } descriptor; struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface { struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; } *endpoint; unsigned char *extra; int extralen; } *altsetting; int num_altsetting; } *interface; unsigned char *extra; int extralen; } *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; } *

user_defined_types: struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus *bus; struct usb_device_descriptor descriptor; struct usb_config_descriptor *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; }

user_defined_types: struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface *interface; unsigned char *extra; int extralen; }

user_defined_types: struct usb_interface { struct usb_interface_descriptor *altsetting; int num_altsetting; }

user_defined_types: struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor *endpoint; unsigned char *extra; int extralen; }


decompiled_code:
__int64 pixma_close()
{
usb_release_interface(devh, 0LL);
return usb_close(devh);
}

canonical_decompiled_code:
__int64 func1()
{
usb_release_interface(devh, 0LL);
return usb_close(devh);
}

original_code:
int pixma_close()
{
 usb_release_interface(devh, 0);
 return usb_close(devh);
}


decompiled_code:
__int64 __fastcall pixma_send(__int64 a1, int a2)
{
unsigned int v2; // eax
unsigned int v3; // ebp

v2 = usb_bulk_write(devh, *(unsigned int *)(model + 20LL), a1, (unsigned int)a2, 1000LL);
v3 = v2;
if ( a2 != v2 && a2 > 0 )
DBG(2LL, "Incomplete write (0x%04x/0x%04x)\n", v2, (unsigned int)a2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
unsigned int v2; // eax
unsigned int v3; // ebp

v2 = usb_bulk_write(devh, *(unsigned int *)(model + 20LL), a1, (unsigned int)a2, 1000LL);
v3 = v2;
if ( a2 != v2 && a2 > 0 )
DBG(2LL, "Incomplete write (0x%04x/0x%04x)\n", v2, (unsigned int)a2);
return v3;
}

original_code:
int pixma_send(unsigned char *buf, int len)
{
 int ret = usb_bulk_write(devh, model->out, (char*) buf, len, 1000);
 if (ret != len && len > 0)
  DBG(2, "Incomplete write (0x%04x/0x%04x)\n", ret, len);
 return ret;
}

variable_types:
buf
unsigned char *

variable_types: len int

variable_types: ret int


decompiled_code:
__int64 __fastcall pixma_recv(__int64 a1, int a2)
{
unsigned int v2; // eax
unsigned int v3; // ebp

v2 = usb_bulk_write(devh, *(unsigned int *)(model + 24LL), a1, (unsigned int)a2, 1000LL);
v3 = v2;
if ( a2 != v2 && a2 > 0 )
DBG(3LL, "Incomplete read (0x%04x/0x%04x)\n", v2, (unsigned int)a2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
unsigned int v2; // eax
unsigned int v3; // ebp

v2 = usb_bulk_write(devh, *(unsigned int *)(model + 24LL), a1, (unsigned int)a2, 1000LL);
v3 = v2;
if ( a2 != v2 && a2 > 0 )
DBG(3LL, "Incomplete read (0x%04x/0x%04x)\n", v2, (unsigned int)a2);
return v3;
}

original_code:
int pixma_recv(unsigned char *buf, int len)
{
 int ret = usb_bulk_write(devh, model->in, (char*) buf, len, 1000);
 if (ret != len && len > 0)
  DBG(3, "Incomplete read (0x%04x/0x%04x)\n", ret, len);
 return ret;
}


decompiled_code:
__int64 pixma_comm_reset()
{
return usb_reset(devh);
}

canonical_decompiled_code:
__int64 func4()
{
return usb_reset(devh);
}

original_code:
int pixma_comm_reset()
{
 return usb_reset(devh);
}


checksum

decompiled_code:
__int64 __fastcall checksum(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rdx
__int64 v3; // rsi
__int64 result; // rax

if ( a2 <= 0 )
return 0LL;
v2 = a1;
v3 = (__int64)&a1[a2 - 1 + 1];
LODWORD(result) = 0;
do
result = (unsigned int)result - *v2++;
while ( v2 != (unsigned __int8 *)v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rdx
__int64 v3; // rsi
__int64 result; // rax

if ( a2 <= 0 )
return 0LL;
v2 = a1;
v3 = (__int64)&a1[a2 - 1 + 1];
LODWORD(result) = 0;
do
result = (unsigned int)result - *v2++;
while ( v2 != (unsigned __int8 *)v3 );
return result;
}

original_code:
unsigned char checksum(unsigned char *buf, int len)
{
 int sum = 0;
 int i;
 for (i = 0; i < len; i++)
  sum -= buf[i];
 return sum;
}

variable_types: sum int

variable_types: i int

return_type: unsigned char


decompiled_code:
__int64 __fastcall cmd_set_byte(int a1, char a2)
{
__int64 result; // rax

result = prot;
*((_BYTE *)&pixma_buf + *(_DWORD *)(prot + 4LL) + a1 - 1) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, char a2)
{
__int64 result; // rax

result = prot;
*((_BYTE *)&pixma_buf + *(_DWORD *)(prot + 4LL) + a1 - 1) = a2;
return result;
}

original_code:
void cmd_set_byte(int pos, char value)
{
 pixma_buf[pos + prot->cmd_base_len - 1] = value;
}

variable_types: pos int

variable_types: value char


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

v2 = _bswap_16(a2);
result = *(int *)(prot + 4LL);
*(_WORD *)((char *)&pixma_buf + result + a1 - 1) = v2;
return result;
}

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

v2 = func0(a2);
result = *(int *)(prot + 4LL);
*(_WORD *)((char *)&pixma_buf + result + a1 - 1) = v2;
return result;
}

original_code:
void cmd_set_word(int pos, int value)
{
 *((uint16_t*) (pixma_buf + prot->cmd_base_len + pos - 1)) =
  htons(value);
}

canonical_original_code:
void cmd_set_word(int pos, int value)
{
 *((unsigned short *) (pixma_buf + prot->cmd_base_len + pos - 1)) =
  htons(value);
}

variable_types: value int


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

v2 = _bswap_32(a2);
result = *(int *)(prot + 4LL);
*(int *)((char *)&pixma_buf + result + a1 - 1) = v2;
return result;
}

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

v2 = func1(a2);
result = *(int *)(prot + 4LL);
*(int *)((char *)&pixma_buf + result + a1 - 1) = v2;
return result;
}

original_code:
void cmd_set_dword(int pos, long value)
{
 *((uint32_t*) (pixma_buf + prot->cmd_base_len + pos - 1)) =
  htonl(value);
}

canonical_original_code:
void cmd_set_dword(int pos, long value)
{
 *((unsigned int *) (pixma_buf + prot->cmd_base_len + pos - 1)) =
  htonl(value);
}

variable_types: value long


decompiled_code:
void *__fastcall cmd_insert_buf(int a1, const void *a2, int a3)
{
return memcpy((char *)&pixma_buf + *(int *)(prot + 4LL) + (__int64)a1 - 1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func6(int a1, const void *a2, int a3)
{
return memcpy((char *)&pixma_buf + *(int *)(prot + 4LL) + (__int64)a1 - 1, a2, a3);
}

original_code:
void cmd_insert_buf(int pos, unsigned char *buf, int len)
{
 memcpy(pixma_buf + prot->cmd_base_len + pos - 1, buf, len);
}


decompiled_code:
__int64 __fastcall cmd_prepare(__int64 a1, void *a2)
{
int v2; // er12
int v3; // edx
__int64 v4; // r13
__int64 result; // rax

v2 = HIDWORD(a1);
if ( SHIDWORD(a1) > 0 )
{
if ( *(_DWORD *)(prot + 16LL) >= SHIDWORD(a1) )
v2 = *(_DWORD *)(prot + 16LL);
v2 += (*(_DWORD *)(prot + 12LL) - v2 % *(_DWORD *)(prot + 12LL)) % *(_DWORD *)(prot + 12LL);
}
if ( a2 )
{
answer_len = v2;
v3 = 0;
}
else
{
answer_len = 0;
v3 = v2;
}
cmd_arg_len = v3;
v4 = prot;
memset(&pixma_buf, 0, *(_DWORD *)(prot + 4LL) + v3);
cmd_set_word(1 - *(_DWORD *)(v4 + 4), a1);
result = cmd_set_word(*(_DWORD *)(prot + 8LL), v2);
answer_buf = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, void *a2)
{
int v2; // er12
int v3; // edx
__int64 v4; // r13
__int64 result; // rax

v2 = HIDWORD(a1);
if ( SHIDWORD(a1) > 0 )
{
if ( *(_DWORD *)(prot + 16LL) >= SHIDWORD(a1) )
v2 = *(_DWORD *)(prot + 16LL);
v2 += (*(_DWORD *)(prot + 12LL) - v2 % *(_DWORD *)(prot + 12LL)) % *(_DWORD *)(prot + 12LL);
}
if ( a2 )
{
answer_len = v2;
v3 = 0;
}
else
{
answer_len = 0;
v3 = v2;
}
cmd_arg_len = v3;
v4 = prot;
memset(&pixma_buf, 0, *(_DWORD *)(prot + 4LL) + v3);
func4(1 - *(_DWORD *)(v4 + 4), a1);
result = func4(*(_DWORD *)(prot + 8LL), v2);
answer_buf = a2;
return result;
}

original_code:
void cmd_prepare(cmd_t cmd, unsigned char *answer)
{
 int extra_bytes = cmd.extra_bytes;
 if (extra_bytes > 0)
  extra_bytes = ((cmd.extra_bytes) > (prot->min_bytes) ? (cmd.extra_bytes) : (prot->min_bytes)) + ((prot->alignment_bytes) - ((cmd.extra_bytes) > (prot->min_bytes) ? (cmd.extra_bytes) : (prot->min_bytes)) % (prot->alignment_bytes)) % (prot->alignment_bytes);;
 answer_len = answer != ((void *)0) ? extra_bytes : 0;
 cmd_arg_len = answer != ((void *)0) ? 0 : extra_bytes;
 memset(pixma_buf, 0, prot->cmd_base_len + cmd_arg_len);
 cmd_set_word(1 - prot->cmd_base_len, cmd.opcode);
 cmd_set_word(prot->cmd_extra_bytes_pos, extra_bytes);
 answer_buf = answer;
}

canonical_original_code:
void cmd_prepare(struct cmd_t cmd, unsigned char *answer)
{
 int extra_bytes = cmd.extra_bytes;
 if (extra_bytes > 0)
  extra_bytes = ((cmd.extra_bytes) > (prot->min_bytes) ? (cmd.extra_bytes) : (prot->min_bytes)) + ((prot->alignment_bytes) - ((cmd.extra_bytes) > (prot->min_bytes) ? (cmd.extra_bytes) : (prot->min_bytes)) % (prot->alignment_bytes)) % (prot->alignment_bytes);;
 answer_len = answer != ((void *)0) ? extra_bytes : 0;
 cmd_arg_len = answer != ((void *)0) ? 0 : extra_bytes;
 memset(pixma_buf, 0, prot->cmd_base_len + cmd_arg_len);
 cmd_set_word(1 - prot->cmd_base_len, cmd.opcode);
 cmd_set_word(prot->cmd_extra_bytes_pos, extra_bytes);
 answer_buf = answer;
}

variable_types: struct cmd_t { int opcode; int extra_bytes; }

variable_types:
answer
unsigned char *


decompiled_code:
__int64 cmd_exec()
{
int v0; // ebx
unsigned int v1; // ebx
unsigned int v2; // ebx
int v3; // ebp
char v5; // al
unsigned int v6; // ebx
__int64 v7; // rax
unsigned int v8; // er12

v0 = cmd_arg_len;
if ( cmd_arg_len )
{
v5 = checksum((unsigned __int8 *)&pixma_buf + *(int *)(prot + 4LL), cmd_arg_len - 1);
cmd_set_byte(v0, v5);
}
DBG(2LL, "\n");
DBG_buf(2LL, &pixma_buf, (unsigned int)(cmd_arg_len + *(_DWORD *)(prot + 4LL)));
v1 = 0;
if ( (unsigned int)pixma_send(&pixma_buf, (unsigned int)(*(_DWORD *)(prot + 4LL) + cmd_arg_len)) == cmd_arg_len + *(_DWORD *)(prot + 4LL) )
{
if ( *(_DWORD *)(model + 32LL) != 1 || (v2 = 0x4000, !*((_BYTE *)&pixma_buf + *(_DWORD *)(prot + 4LL) - 3)) )
v2 = *prot + answer_len;
DBG(3LL, "expecting %i status and %i answer bytes...\n", (unsigned int)*prot, (unsigned int)answer_len);
v3 = pixma_recv(&pixma_buf, v2);
v1 = 0;
if ( *prot <= v3 )
{
v6 = BYTE1(pixma_buf) | ((unsigned __int8)pixma_buf << 8);
v7 = status2str(v6);
DBG(2LL, "%s\n", v7);
v8 = v6;
v1 = 0;
if ( *prot + answer_len <= v3 )
v1 = v8;
if ( answer_len > 0 )
{
memcpy(answer_buf, (char *)&pixma_buf + (int)*prot, answer_len);
DBG_buf(2LL, answer_buf, (unsigned int)answer_len);
}
hangover_buf = (char *)&pixma_buf + (int)*prot + (__int64)answer_len;
hangover_len = v3 - *prot - answer_len;
DBG(3LL, "0x%04x bytes in hangover buffer\n", (unsigned int)hangover_len);
}
}
return v1;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // ebx
unsigned int v1; // ebx
unsigned int v2; // ebx
int v3; // ebp
char v5; // al
unsigned int v6; // ebx
__int64 v7; // rax
unsigned int v8; // er12

v0 = cmd_arg_len;
if ( cmd_arg_len )
{
v5 = func2((unsigned __int8 *)&pixma_buf + *(int *)(prot + 4LL), cmd_arg_len - 1);
func3(v0, v5);
}
DBG(2LL, "\n");
DBG_buf(2LL, &pixma_buf, (unsigned int)(cmd_arg_len + *(_DWORD *)(prot + 4LL)));
v1 = 0;
if ( (unsigned int)pixma_send(&pixma_buf, (unsigned int)(*(_DWORD *)(prot + 4LL) + cmd_arg_len)) == cmd_arg_len + *(_DWORD *)(prot + 4LL) )
{
if ( *(_DWORD *)(model + 32LL) != 1 || (v2 = 0x4000, !*((_BYTE *)&pixma_buf + *(_DWORD *)(prot + 4LL) - 3)) )
v2 = *prot + answer_len;
DBG(3LL, "expecting %i status and %i answer bytes...\n", (unsigned int)*prot, (unsigned int)answer_len);
v3 = pixma_recv(&pixma_buf, v2);
v1 = 0;
if ( *prot <= v3 )
{
v6 = BYTE1(pixma_buf) | ((unsigned __int8)pixma_buf << 8);
v7 = status2str(v6);
DBG(2LL, "%s\n", v7);
v8 = v6;
v1 = 0;
if ( *prot + answer_len <= v3 )
v1 = v8;
if ( answer_len > 0 )
{
memcpy(answer_buf, (char *)&pixma_buf + (int)*prot, answer_len);
DBG_buf(2LL, answer_buf, (unsigned int)answer_len);
}
hangover_buf = (char *)&pixma_buf + (int)*prot + (__int64)answer_len;
hangover_len = v3 - *prot - answer_len;
DBG(3LL, "0x%04x bytes in hangover buffer\n", (unsigned int)hangover_len);
}
}
return v1;
}

original_code:
int cmd_exec()
{
 if (cmd_arg_len)
  cmd_set_byte(cmd_arg_len,
        checksum(pixma_buf + prot->cmd_base_len,
          cmd_arg_len - 1));
 DBG(2, "\n");
 DBG_buf(2, pixma_buf, prot->cmd_base_len + cmd_arg_len,
     prot->cmd_base_len);
 if (pixma_send(pixma_buf, prot->cmd_base_len + cmd_arg_len) !=
     prot->cmd_base_len + cmd_arg_len)
  return 0x0000;
 int bytes_to_recv =
  model->protocol == 1 && pixma_buf[prot->cmd_base_len - 3] ?
  0x4000 : prot->status_len + answer_len;
 DBG(3, "expecting %i status and %i answer bytes...\n",
        prot->status_len, answer_len);
 int buf_len = pixma_recv(pixma_buf, bytes_to_recv);
 if (buf_len < prot->status_len)
  return 0x0000;
 int status = pixma_buf[0] << 8 | pixma_buf[1];
 DBG(2, "%s\n", status2str(status));
 if (buf_len < prot->status_len + answer_len)
  status = 0x0000;
 if (answer_len > 0) {
  memcpy(answer_buf, pixma_buf + prot->status_len, answer_len);
  DBG_buf(2, answer_buf, answer_len, 16);
 }
 hangover_buf = pixma_buf + prot->status_len + answer_len;
 hangover_len = buf_len - prot->status_len - answer_len;
 DBG(3, "0x%04x bytes in hangover buffer\n", hangover_len);
 return status;
}

variable_types: status int


decompiled_code:
__int64 __fastcall read_hangover(void *a1, int a2)
{
int v2; // ebx

v2 = 0;
if ( hangover_len > 0 )
{
v2 = a2;
if ( hangover_len <= a2 )
v2 = hangover_len;
memcpy(a1, hangover_buf, v2);
hangover_len -= v2;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(void *a1, int a2)
{
int v2; // ebx

v2 = 0;
if ( hangover_len > 0 )
{
v2 = a2;
if ( hangover_len <= a2 )
v2 = hangover_len;
memcpy(a1, hangover_buf, v2);
hangover_len -= v2;
}
return (unsigned int)v2;
}

original_code:
int read_hangover(unsigned char *buf, int len)
{
 if (hangover_len <= 0)
  return 0;
 int ret = (len) < (hangover_len) ? (len) : (hangover_len);
 memcpy(buf, hangover_buf, ret);
 hangover_len -= ret;
 return ret;
}


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

result = (unsigned int)(a1 % 75);
if ( a1 % 75 )
return 0xFFFFFFFFLL;
resolution = a1;
return result;
}

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

result = (unsigned int)(a1 % 75);
if ( a1 % 75 )
return 0xFFFFFFFFLL;
resolution = a1;
return result;
}

original_code:
int pixma_set_resolution(int r)
{
 if (r % 75)
  return -1;
 resolution = r;
 return 0;
}

variable_types: r int


decompiled_code:
__int64 __fastcall pixma_set_monochrome(int a1)
{
monochrome = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
monochrome = a1;
return 0LL;
}

original_code:
int pixma_set_monochrome(int m)
{
 monochrome = m;
 return 0;
}

variable_types: m int


decompiled_code:
__int64 __fastcall pixma_set_adf(int a1)
{
adf = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
adf = a1;
return 0LL;
}

original_code:
int pixma_set_adf(int a)
{
 adf = a;
 return 0;
}

variable_types: a int


decompiled_code:
__int64 __fastcall pixma_set_window(int a1, int a2, int a3, int a4)
{
x = a1;
y = a2;
width = a3;
height = a4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2, int a3, int a4)
{
x = a1;
y = a2;
width = a3;
height = a4;
return 0LL;
}

original_code:
int pixma_set_window(int win_x, int win_y, int win_width, int win_height)
{
 x = win_x;
 y = win_y;
 width = win_width;
 height = win_height;
 return 0;
}


decompiled_code:
__int64 __fastcall raw2rgb(__int64 a1, __int64 a2)
{
int i; // er9
int v5; // eax
__int64 v6; // r10
__int64 result; // rax
int v8; // er10
int v9; // er8
int v10; // esi
int v11; // edx
__int64 v12; // rsi
__int64 v13; // rdi
int v14; // eax

for ( i = 0; i != 3; ++i )
{
v8 = 0;
result = model;
if ( *(int *)(model + 32) <= 0 )
{
v14 = 2 * i;
if ( !adf )
v14 = -2 * i + 4;
v5 = resolution * v14;
v6 = (458129845LL * v5) >> 35;
result = (unsigned int)(v5 >> 31);
v8 = v6 - result;
}
if ( height > 0 )
{
v9 = 0;
do
{
result = (unsigned int)(raw_width * (v9 + v8));
v10 = i + 3 * result;
if ( width > 0 )
{
result = 0LL;
v11 = 0;
v12 = a2 + v10;
v13 = a1 + i + 3 * v9 * width;
do
{
*(_BYTE *)(v13 + result) = *(_BYTE *)(v12 + result);
++v11;
result += 3LL;
}
while ( width > v11 );
}
++v9;
}
while ( height > v9 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
int i; // er9
int v5; // eax
__int64 v6; // r10
__int64 result; // rax
int v8; // er10
int v9; // er8
int v10; // esi
int v11; // edx
__int64 v12; // rsi
__int64 v13; // rdi
int v14; // eax

for ( i = 0; i != 3; ++i )
{
v8 = 0;
result = model;
if ( *(int *)(model + 32) <= 0 )
{
v14 = 2 * i;
if ( !adf )
v14 = -2 * i + 4;
v5 = resolution * v14;
v6 = (458129845LL * v5) >> 35;
result = (unsigned int)(v5 >> 31);
v8 = v6 - result;
}
if ( height > 0 )
{
v9 = 0;
do
{
result = (unsigned int)(raw_width * (v9 + v8));
v10 = i + 3 * result;
if ( width > 0 )
{
result = 0LL;
v11 = 0;
v12 = a2 + v10;
v13 = a1 + i + 3 * v9 * width;
do
{
*(_BYTE *)(v13 + result) = *(_BYTE *)(v12 + result);
++v11;
result += 3LL;
}
while ( width > v11 );
}
++v9;
}
while ( height > v9 );
}
}
return result;
}

original_code:
void raw2rgb(unsigned char *rgb, unsigned char *raw)
{
 int comp, x, y;
 for (comp = 0; comp < 3; comp++) {
  int shifting = model->protocol > 0 ? 0 :
          (adf ? comp : 2 - comp) * 2 * resolution / 75;
  for (y = 0; y < height; y++) {
   int rgb_off = comp + 3 * width * y;
   int raw_off = comp + 3 * raw_width * (y + shifting);
   for (x = 0; x < width; x++)
    rgb[rgb_off + 3 * x] = raw[raw_off + 3 * x];
  }
 }
}

canonical_original_code:
void raw2rgb(unsigned char *rgb, unsigned char *raw)
{
 int comp; int x; int y;
 for (comp = 0; comp < 3; comp++) {
  int shifting = model->protocol > 0 ? 0 :
          (adf ? comp : 2 - comp) * 2 * resolution / 75;
  for (y = 0; y < height; y++) {
   int rgb_off = comp + 3 * width * y;
   int raw_off = comp + 3 * raw_width * (y + shifting);
   for (x = 0; x < width; x++)
    rgb[rgb_off + 3 * x] = raw[raw_off + 3 * x];
  }
 }
}

variable_types:
rgb
unsigned char *

variable_types:
raw
unsigned char *

variable_types: comp int

variable_types: x int

variable_types: y int

variable_types: shifting int


decompiled_code:
__int64 __fastcall pixma_get_info(__int64 a1)
{
cmd_prepare(cmd_get_info, a1);
return cmd_exec();
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
cmd_prepare(cmd_get_info, a1);
return cmd_exec();
}

original_code:
int pixma_get_info(unsigned char *info)
{
 cmd_prepare(cmd_get_info, info);
 return cmd_exec();
}

variable_types:
info
unsigned char *


decompiled_code:
_BOOL8 pixma_adf_is_ready()
{
int v0; // edx
_BOOL8 result; // rax
char v2[20]; // [rsp+4h] [rbp-14h] BYREF

v0 = pixma_get_info((__int64)v2);
result = 0LL;
if ( v0 == 1542 )
result = v2[1] == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 func8()
{
int v0; // edx
_BOOL8 result; // rax
char v2[20]; // [rsp+4h] [rbp-14h] BYREF

v0 = func7((__int64)v2);
result = 0LL;
if ( v0 == 1542 )
result = v2[1] == 0;
return result;
}

original_code:
int pixma_adf_is_ready()
{
 unsigned char info[0x0c];
 return pixma_get_info(info) == 0x0606 && !info[1];
}

canonical_original_code:
int pixma_adf_is_ready()
{
 unsigned char info[12];
 return pixma_get_info(info) == 0x0606 && !info[1];
}

variable_types:
info
unsigned char [12]


decompiled_code:
_BOOL8 pixma_is_warming_up()
{
_BOOL8 result; // rax
char v1[20]; // [rsp+4h] [rbp-14h] BYREF

if ( (unsigned int)pixma_get_info((__int64)v1) != 1542 || *(_DWORD *)(model + 32) )
result = v1[8] != 1;
else
result = v1[7] != 3;
return result;
}

canonical_decompiled_code:
_BOOL8 func9()
{
_BOOL8 result; // rax
char v1[20]; // [rsp+4h] [rbp-14h] BYREF

if ( (unsigned int)func7((__int64)v1) != 1542 || *(_DWORD *)(model + 32) )
result = v1[8] != 1;
else
result = v1[7] != 3;
return result;
}

original_code:
int pixma_is_warming_up()
{
 unsigned char info[0x0c];
 return pixma_get_info(info) == 0x0606 &&
           model->protocol == 0 ? info[7] != 0x03 :
                    info[8] != 0x01;
}

canonical_original_code:
int pixma_is_warming_up()
{
 unsigned char info[12];
 return pixma_get_info(info) == 0x0606 &&
           model->protocol == 0 ? info[7] != 0x03 :
                    info[8] != 0x01;
}


decompiled_code:
_BOOL8 pixma_is_calibrated()
{
int v0; // edx
_BOOL8 result; // rax
char v2[20]; // [rsp+4h] [rbp-14h] BYREF

v0 = pixma_get_info((__int64)v2);
result = 1LL;
if ( v0 == 1542 && !*(_DWORD *)(model + 32) )
result = v2[8] == 15;
return result;
}

canonical_decompiled_code:
_BOOL8 func10()
{
int v0; // edx
_BOOL8 result; // rax
char v2[20]; // [rsp+4h] [rbp-14h] BYREF

v0 = func7((__int64)v2);
result = 1LL;
if ( v0 == 1542 && !*(_DWORD *)(model + 32) )
result = v2[8] == 15;
return result;
}

original_code:
int pixma_is_calibrated()
{
 unsigned char info[0x0c];
 return pixma_get_info(info) == 0x0606 &&
           model->protocol == 0 ? info[8] == 0x0f :
                    1;
}

canonical_original_code:
int pixma_is_calibrated()
{
 unsigned char info[12];
 return pixma_get_info(info) == 0x0606 &&
           model->protocol == 0 ? info[8] == 0x0f :
                    1;
}


decompiled_code:
__int64 pixma_abort()
{
cmd_prepare(cmd_abort, 0LL);
return cmd_exec();
}

canonical_decompiled_code:
__int64 func11()
{
cmd_prepare(cmd_abort, 0LL);
return cmd_exec();
}

original_code:
int pixma_abort()
{
 cmd_prepare(cmd_abort, ((void *)0));
 return cmd_exec();
}


decompiled_code:
__int64 pixma_reset()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-18h] BYREF

pixma_comm_reset();
result = 1542LL;
if ( *(int *)(model + 32) <= 0 )
{
cmd_prepare(cmd_reset, &v1);
result = cmd_exec();
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-18h] BYREF

pixma_comm_reset();
result = 1542LL;
if ( *(int *)(model + 32) <= 0 )
{
cmd_prepare(cmd_reset, &v1);
result = cmd_exec();
}
return result;
}

original_code:
int pixma_reset()
{
 unsigned char answer[0x10];
 pixma_comm_reset();
 if (model->protocol > 0)
  return 0x0606;
 cmd_prepare(cmd_reset, answer);
 return cmd_exec();
}

canonical_original_code:
int pixma_reset()
{
 unsigned char answer[16];
 pixma_comm_reset();
 if (model->protocol > 0)
  return 0x0606;
 cmd_prepare(cmd_reset, answer);
 return cmd_exec();
}

variable_types:
answer
unsigned char [16]


decompiled_code:
__int64 pixma_calibration()
{
unsigned int v0; // ebx

cmd_prepare(cmd_calibration, 0LL);
cmd_set_byte(4294967290LL, 16LL);
v0 = cmd_exec();
if ( v0 == 1542 && !pixma_is_calibrated() )
{
sleep(0x4Bu);
while ( !pixma_is_calibrated() )
sleep(5u);
}
return v0;
}

canonical_decompiled_code:
__int64 func13()
{
unsigned int v0; // ebx

cmd_prepare(cmd_calibration, 0LL);
cmd_set_byte(4294967290LL, 16LL);
v0 = cmd_exec();
if ( v0 == 1542 && !func10() )
{
sleep(0x4Bu);
while ( !func10() )
sleep(5u);
}
return v0;
}

original_code:
int pixma_calibration()
{
 cmd_prepare(cmd_calibration, ((void *)0));
 cmd_set_byte(-6, 0x10);
 int status = cmd_exec();
 if (status == 0x0606 && !pixma_is_calibrated()) {
  sleep(75);
  while (!pixma_is_calibrated())
   sleep(5);
 }
 return status;
}


decompiled_code:
__int64 __fastcall pixma_activate(unsigned int a1)
{
__int64 result; // rax
unsigned int v2; // ebx

result = 1542LL;
if ( *(int *)(model + 32) <= 0 )
{
v2 = a1;
cmd_prepare(cmd_activate, 0LL);
cmd_set_byte(1LL, 1LL);
if ( a1 )
v2 = 32;
cmd_set_byte(4LL, v2);
result = cmd_exec();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1)
{
__int64 result; // rax
unsigned int v2; // ebx

result = 1542LL;
if ( *(int *)(model + 32) <= 0 )
{
v2 = a1;
cmd_prepare(cmd_activate, 0LL);
cmd_set_byte(1LL, 1LL);
if ( a1 )
v2 = 32;
cmd_set_byte(4LL, v2);
result = cmd_exec();
}
return result;
}

original_code:
int pixma_activate(int activate)
{
 if (model->protocol > 0)
  return 0x0606;
 cmd_prepare(cmd_activate, ((void *)0));
 cmd_set_byte(1, 1);
 cmd_set_byte(4, activate ? 0x20 : 0);
 return cmd_exec();
}

variable_types: activate int


decompiled_code:
__int64 pixma_scan_mode()
{
__int64 result; // rax

do
{
cmd_prepare(cmd_scan_mode, 0LL);
result = cmd_exec();
}
while ( (_DWORD)result == 5140 );
return result;
}

canonical_decompiled_code:
__int64 func15()
{
__int64 result; // rax

do
{
cmd_prepare(cmd_scan_mode, 0LL);
result = cmd_exec();
}
while ( (_DWORD)result == 5140 );
return result;
}

original_code:
int pixma_scan_mode()
{
 int status;
 do {
  cmd_prepare(cmd_scan_mode, ((void *)0));
  status = cmd_exec();
 } while (status == 0x1414);
 return status;
}


decompiled_code:
__int64 __fastcall pixma_gamma(double a1)
{
__int64 result; // rax
double v2; // r14
__int64 i; // rbx
char v4[4120]; // [rsp+0h] [rbp-1018h] BYREF

result = 1542LL;
if ( *(_DWORD *)(model + 32) )
{
v2 = 1.0 / a1;
for ( i = 0LL; i != 4096; ++i )
v4[i] = (int)(pow((double)(int)i * 0.000244140625, v2) * 256.0);
cmd_prepare(cmd_gamma, 0LL);
cmd_set_dword(1LL, 268439556LL);
cmd_insert_buf(5LL, v4, 4096LL);
result = cmd_exec();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(double a1)
{
__int64 result; // rax
double v2; // r14
__int64 i; // rbx
char v4[4120]; // [rsp+0h] [rbp-1018h] BYREF

result = 1542LL;
if ( *(_DWORD *)(model + 32) )
{
v2 = 1.0 / a1;
for ( i = 0LL; i != 4096; ++i )
v4[i] = (int)(pow((double)(int)i * 0.000244140625, v2) * 256.0);
cmd_prepare(cmd_gamma, 0LL);
cmd_set_dword(1LL, 268439556LL);
cmd_insert_buf(5LL, v4, 4096LL);
result = cmd_exec();
}
return result;
}

original_code:
int pixma_gamma(double gamma)
{
 if (model->protocol == 0)
  return 0x0606;
 unsigned char table[4096];
 int i;
 for (i = 0; i < 4096; i++)
  table[i] = (int) (256 * pow((double) i / 4096,
        1 / gamma));
 cmd_prepare(cmd_gamma, ((void *)0));
 cmd_set_dword(1, 0x10001004);
 cmd_insert_buf(5, table, 4096);
 return cmd_exec();
}

variable_types: gamma double

variable_types:
table
unsigned char [4096]

variable_types: i int


decompiled_code:
__int64 pixma_setup()
{
cmd_prepare(cmd_setup, 0LL);
cmd_set_byte(1LL, 1 - ((unsigned int)(adf == 0) - 1));
cmd_set_byte(2LL, 1LL);
return cmd_exec();
}

canonical_decompiled_code:
__int64 func17()
{
cmd_prepare(cmd_setup, 0LL);
cmd_set_byte(1LL, 1 - ((unsigned int)(adf == 0) - 1));
cmd_set_byte(2LL, 1LL);
return cmd_exec();
}

original_code:
int pixma_setup()
{
 cmd_prepare(cmd_setup, ((void *)0));
 cmd_set_byte(1, adf ? 2 : 1);
 cmd_set_byte(2, 1);
 return cmd_exec();
}


decompiled_code:
__int64 pixma_init()
{
__int64 result; // rax

do
{
pixma_reset();
result = pixma_activate(0);
}
while ( (_DWORD)result != 1542 );
return result;
}

canonical_decompiled_code:
__int64 func18()
{
__int64 result; // rax

do
{
func12();
result = func14(0);
}
while ( (_DWORD)result != 1542 );
return result;
}

original_code:
int pixma_init()
{
 int status;
 do {
  pixma_reset();
  status = pixma_activate(0);
 } while (status != 0x0606);
 return status;
}

variable_types: status int


decompiled_code:
__int64 pixma_scan()
{
unsigned int v0; // edx
int v1; // eax

v0 = (int)(((unsigned int)(width >> 31) >> 30) - (((_BYTE)width + ((unsigned int)(width >> 31) >> 30)) & 3) + 4) >> 31;
raw_width = width
+ (((v0 >> 30)
+ ((unsigned int)(width >> 31) >> 30)
- (((_BYTE)width + ((unsigned int)(width >> 31) >> 30)) & 3)
+ 4) & 3)
- (v0 >> 30);
v1 = 0;
if ( !*(_DWORD *)(model + 32) )
v1 = 4 * resolution / 75 + 1;
raw_height = height + v1;
cmd_prepare(cmd_scan, 0LL);
cmd_set_word(5LL, resolution | 0x8000u);
cmd_set_word(7LL, resolution | 0x8000u);
cmd_set_dword(9LL, x);
cmd_set_dword(13LL, y);
cmd_set_dword(17LL, raw_width);
cmd_set_dword(21LL, raw_height);
cmd_set_word(25LL, 2072LL);
cmd_set_byte(33LL, 0xFFFFFFFFLL);
cmd_set_byte(36LL, 4294967169LL);
cmd_set_word(39LL, 513LL);
cmd_set_byte(42LL, (monochrome | *(_DWORD *)(model + 32)) == 0);
return cmd_exec();
}

canonical_decompiled_code:
__int64 func19()
{
unsigned int v0; // edx
int v1; // eax

v0 = (int)(((unsigned int)(width >> 31) >> 30) - (((_BYTE)width + ((unsigned int)(width >> 31) >> 30)) & 3) + 4) >> 31;
raw_width = width
+ (((v0 >> 30)
+ ((unsigned int)(width >> 31) >> 30)
- (((_BYTE)width + ((unsigned int)(width >> 31) >> 30)) & 3)
+ 4) & 3)
- (v0 >> 30);
v1 = 0;
if ( !*(_DWORD *)(model + 32) )
v1 = 4 * resolution / 75 + 1;
raw_height = height + v1;
cmd_prepare(cmd_scan, 0LL);
cmd_set_word(5LL, resolution | 0x8000u);
cmd_set_word(7LL, resolution | 0x8000u);
cmd_set_dword(9LL, x);
cmd_set_dword(13LL, y);
cmd_set_dword(17LL, raw_width);
cmd_set_dword(21LL, raw_height);
cmd_set_word(25LL, 2072LL);
cmd_set_byte(33LL, 0xFFFFFFFFLL);
cmd_set_byte(36LL, 4294967169LL);
cmd_set_word(39LL, 513LL);
cmd_set_byte(42LL, (monochrome | *(_DWORD *)(model + 32)) == 0);
return cmd_exec();
}

original_code:
int pixma_scan()
{
 raw_width = width + (4 - width % 4) % 4;
 raw_height = height + (model->protocol == 0 ?
          4 * resolution / 75 + 1 : 0);
 cmd_prepare(cmd_scan, ((void *)0));
 cmd_set_word ( 5, resolution | 0x8000);
 cmd_set_word ( 7, resolution | 0x8000);
 cmd_set_dword( 9, x);
 cmd_set_dword(13, y);
 cmd_set_dword(17, raw_width);
 cmd_set_dword(21, raw_height);
 cmd_set_word (25, 0x0818);
 cmd_set_byte (33, 0xff);
 cmd_set_byte (36, 0x81);
 cmd_set_word (39, 0x0201);
 cmd_set_byte (42, model->protocol == 0 && !monochrome);
 return cmd_exec();
}


decompiled_code:
__int64 __fastcall pixma_packet_req(_DWORD *a1, _DWORD *a2)
{
unsigned int v2; // ebx
int v3; // eax
char v5[2]; // [rsp+8h] [rbp-20h] BYREF
__int16 v6; // [rsp+Ah] [rbp-1Eh]
unsigned int v7; // [rsp+Ch] [rbp-1Ch]

cmd_prepare(cmd_packet_req, v5);
cmd_set_byte(4294967294LL, *(_DWORD *)(model + 32) == 0 ? -64 : 8);
v2 = cmd_exec();
if ( *(_DWORD *)(model + 32) )
v3 = _bswap_32(v7);
else
v3 = (unsigned __int16)_bswap_16(v6);
*a1 = v3;
*a2 = v5[0] != 0;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func20(_DWORD *a1, _DWORD *a2)
{
unsigned int v2; // ebx
int v3; // eax
char v5[2]; // [rsp+8h] [rbp-20h] BYREF
__int16 v6; // [rsp+Ah] [rbp-1Eh]
unsigned int v7; // [rsp+Ch] [rbp-1Ch]

cmd_prepare(cmd_packet_req, v5);
cmd_set_byte(4294967294LL, *(_DWORD *)(model + 32) == 0 ? -64 : 8);
v2 = cmd_exec();
if ( *(_DWORD *)(model + 32) )
v3 = func1(v7);
else
v3 = (unsigned __int16)func0(v6);
*a1 = v3;
*a2 = v5[0] != 0;
return v2;
}

original_code:
int pixma_packet_req(int *packet_len, int *last_packet_flag)
{
 unsigned char header[8];
 cmd_prepare(cmd_packet_req, header);
 cmd_set_byte(-2, model->protocol == 0 ? 0xc000 >> 8 : 0x08);
 int status = cmd_exec();
 *packet_len = model->protocol == 0 ? ntohs(((uint16_t*) header)[1]) :
          ntohl(((uint32_t*) header)[1]);
 *last_packet_flag = header[0] && 0x20;
 return status;
}

canonical_original_code:
int pixma_packet_req(int *packet_len, int *last_packet_flag)
{
 unsigned char header[8];
 cmd_prepare(cmd_packet_req, header);
 cmd_set_byte(-2, model->protocol == 0 ? 0xc000 >> 8 : 0x08);
 int status = cmd_exec();
 *packet_len = model->protocol == 0 ? ntohs(((unsigned short *) header)[1]) :
          ntohl(((unsigned int *) header)[1]);
 *last_packet_flag = header[0] && 0x20;
 return status;
}

variable_types:
header
unsigned char [8]


decompiled_code:
__int64 __fastcall pixma_get_img(__int64 a1)
{
char *v1; // rbp
char *v2; // rbx
unsigned int v3; // er13
int v4; // eax
unsigned int v6; // [rsp+8h] [rbp-30h] BYREF
int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = (char *)malloc(3 * raw_height * raw_width);
v2 = v1;
while ( 1 )
{
v3 = pixma_packet_req(&v6, v7);
if ( v3 != 1542 )
return v3;
for ( ; (int)v6 > 0; v6 -= v4 )
{
v4 = read_hangover(v2);
if ( v4 <= 0 )
v4 = pixma_recv(v2, v6);
if ( v4 < 0 )
return 0;
v2 += v4;
}
if ( !*(_DWORD *)(model + 32) )
pixma_recv(v2, 0LL);
if ( v7[0] )
{
v3 = pixma_activate(0);
raw2rgb(a1, (__int64)v1);
free(v1);
return v3;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
char *v1; // rbp
char *v2; // rbx
unsigned int v3; // er13
int v4; // eax
unsigned int v6; // [rsp+8h] [rbp-30h] BYREF
int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = (char *)malloc(3 * raw_height * raw_width);
v2 = v1;
while ( 1 )
{
v3 = func20(&v6, v7);
if ( v3 != 1542 )
return v3;
for ( ; (int)v6 > 0; v6 -= v4 )
{
v4 = read_hangover(v2);
if ( v4 <= 0 )
v4 = pixma_recv(v2, v6);
if ( v4 < 0 )
return 0;
v2 += v4;
}
if ( !*(_DWORD *)(model + 32) )
pixma_recv(v2, 0LL);
if ( v7[0] )
{
v3 = func14(0);
func6(a1, (__int64)v1);
free(v1);
return v3;
}
}
}

original_code:
int pixma_get_img(unsigned char *rgb)
{
 int status;
 int last_packet_flag;
 unsigned char *raw, *rawp;
 rawp = raw = malloc(3 * raw_width * raw_height);
 do {
  int bytes_left;
  status = pixma_packet_req(&bytes_left, &last_packet_flag);
  if (status != 0x0606)
   return status;
  while (bytes_left > 0) {
   int bytes_received = read_hangover(rawp, bytes_left);
   if (bytes_received <= 0)
    bytes_received = pixma_recv(rawp, bytes_left);
   if (bytes_received < 0)
    return 0x0000;
   rawp += bytes_received;
   bytes_left -= bytes_received;
  }
  if (model->protocol == 0)
   pixma_recv(rawp, 0);
 } while (!last_packet_flag);
 status = pixma_activate(0);
 raw2rgb(rgb, raw);
 free(raw);
 return status;
}

canonical_original_code:
int pixma_get_img(unsigned char *rgb)
{
 int status;
 int last_packet_flag;
 unsigned char *raw; unsigned char *rawp;
 rawp = raw = malloc(3 * raw_width * raw_height);
 do {
  int bytes_left;
  status = pixma_packet_req(&bytes_left, &last_packet_flag);
  if (status != 0x0606)
   return status;
  while (bytes_left > 0) {
   int bytes_received = read_hangover(rawp, bytes_left);
   if (bytes_received <= 0)
    bytes_received = pixma_recv(rawp, bytes_left);
   if (bytes_received < 0)
    return 0x0000;
   rawp += bytes_received;
   bytes_left -= bytes_received;
  }
  if (model->protocol == 0)
   pixma_recv(rawp, 0);
 } while (!last_packet_flag);
 status = pixma_activate(0);
 raw2rgb(rgb, raw);
 free(raw);
 return status;
}

variable_types:
rawp
unsigned char *


decompiled_code:
void __fastcall set_verbosity(int a1)
{
verbosity = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
verbosity = a1;
}

original_code:
void set_verbosity(int v)
{
 verbosity = v;
}

variable_types: v int


DBG

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

if ( verbosity >= a1 )
{
va_start(arg, a2);
result = vfprintf(stderr, a2, arg);
}
return result;
}

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

if ( verbosity >= a1 )
{
va_start(arg, a2);
result = vfprintf(stderr, a2, arg);
}
return result;
}

original_code:
void DBG(int level, const char *format, ...)
{
 if (level > verbosity)
  return;
 va_list args;
 __builtin_va_start(args,format);
 vfprintf(stderr, format, args);
 __builtin_va_end(args);
}

canonical_original_code:
void DBG(int level, char *format, ...)
{
 if (level > verbosity)
  return;
 __builtin_va_list args;
 __builtin_va_start(args,format);
 vfprintf(stderr, format, args);
 __builtin_va_end(args);
}

variable_types: level int

variable_types:
format
char *


decompiled_code:
int __fastcall DBG_buf(int a1, __int64 a2, int a3, int a4)
{
__int64 v5; // r15
__int64 v6; // rbx
int v7; // er14
int result; // eax

if ( a3 > 0 )
{
v5 = (unsigned int)a3;
v6 = 0LL;
v7 = a4 - 1;
do
{
DBG(a1, "%02x ", *(unsigned __int8 *)(a2 + v6));
if ( (int)v6 % a4 == v7 || (result = a3 - 1, a3 - 1 == (_DWORD)v6) )
result = DBG(a1, "\n");
++v6;
}
while ( v6 != v5 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, __int64 a2, int a3, int a4)
{
__int64 v5; // r15
__int64 v6; // rbx
int v7; // er14
int result; // eax

if ( a3 > 0 )
{
v5 = (unsigned int)a3;
v6 = 0LL;
v7 = a4 - 1;
do
{
func1(a1, "%02x ", *(unsigned __int8 *)(a2 + v6));
if ( (int)v6 % a4 == v7 || (result = a3 - 1, a3 - 1 == (_DWORD)v6) )
result = func1(a1, "\n");
++v6;
}
while ( v6 != v5 );
}
return result;
}

original_code:
void DBG_buf(int level, unsigned char *buf, int len, int cols)
{
 int i;
 for (i = 0; i < len; i++) {
  DBG(level, "%02x ", buf[i]);
  if (i % cols == cols - 1 || i == len - 1)
   DBG(level, "\n");
 }
}

variable_types:
buf
unsigned char *

variable_types: len int

variable_types: cols int


decompiled_code:
const char *__fastcall status2str(int a1)
{
const char *result; // rax

if ( a1 == 5140 )
return "BUSY";
if ( a1 > 5140 )
{
result = "???";
if ( a1 == 5397 )
result = "ERR";
}
else
{
result = "NULL";
if ( a1 )
{
result = "???";
if ( a1 == 1542 )
result = "READY";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(int a1)
{
const char *result; // rax

if ( a1 == 5140 )
return "BUSY";
if ( a1 > 5140 )
{
result = "???";
if ( a1 == 5397 )
result = "ERR";
}
else
{
result = "NULL";
if ( a1 )
{
result = "???";
if ( a1 == 1542 )
result = "READY";
}
}
return result;
}

original_code:
const char *status2str(int status)
{
 switch (status) {
  case 0x0000:
   return "NULL";
  case 0x0606:
   return "READY";
  case 0x1414:
   return "BUSY";
  case 0x1515:
   return "ERR";
  default:
   return "???";
 }
}

return_type: char *


spnegoInitFromBinary

repo: turnkeylinux/tklbam-squid

decompiled_code:
__int64 __fastcall spnegoInitFromBinary(__int64 a1, __int64 a2, __int64 a3)
{
return InitTokenFromBinary(1LL, 1LL, a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
return InitTokenFromBinary(1LL, 1LL, a1, a2, a3);
}

original_code:
int spnegoInitFromBinary( unsigned char* pbTokenData, unsigned long ulLength, SPNEGO_TOKEN_HANDLE* phSpnegoToken )
{
   int nReturn = -8;
   SPNEGO_TOKEN** ppSpnegoToken = (SPNEGO_TOKEN**) phSpnegoToken;
   nReturn = InitTokenFromBinary( 0x1,
                                 0x1, pbTokenData,
                                 ulLength, ppSpnegoToken );
   ;
   return nReturn;
}

canonical_original_code:
int spnegoInitFromBinary(unsigned char *pbTokenData, unsigned long ulLength, void **phSpnegoToken)
{
   int nReturn = -8;
   struct SpnegoToken **ppSpnegoToken = (SPNEGO_TOKEN**) phSpnegoToken;
   nReturn = InitTokenFromBinary( 0x1,
                                 0x1, pbTokenData,
                                 ulLength, ppSpnegoToken );
   ;
   return nReturn;
}

variable_types:
pbTokenData
unsigned char *

variable_types:
ulLength
unsigned long

variable_types:
phSpnegoToken
void **

variable_types: nReturn int

variable_types: struct SpnegoToken { unsigned long nStructSize; unsigned long ulFlags; int ucTokenType; unsigned char *pbBinaryData; unsigned long ulBinaryDataLen; int nNumElements; struct SpnegoElement { unsigned long nStructSize; int iElementPresent; enum spnego_element_type { spnego_element_min=0, spnego_init_mechtypes=1, spnego_init_reqFlags=2, spnego_init_mechToken=3, spnego_init_mechListMIC=4, spnego_targ_negResult=5, spnego_targ_supportedMech=6, spnego_targ_responseToken=7, spnego_targ_mechListMIC=8, spnego_element_max=9 } eElementType; unsigned char type; unsigned char *pbData; unsigned long nDatalength; } aElementArray[4]; } **

user_defined_types: struct SpnegoToken { unsigned long nStructSize; unsigned long ulFlags; int ucTokenType; unsigned char *pbBinaryData; unsigned long ulBinaryDataLen; int nNumElements; struct SpnegoElement aElementArray[4]; }

user_defined_types: struct SpnegoElement { unsigned long nStructSize; int iElementPresent; enum spnego_element_type eElementType; unsigned char type; unsigned char *pbData; unsigned long nDatalength; }


spnegoCreateNegTokenInit

decompiled_code:
__int64 __fastcall spnegoCreateNegTokenInit(unsigned int a1, unsigned __int8 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
unsigned int v9; // ebx
size_t v11; // rbx
void *v12; // rax
void *v13; // r15
__int64 v16; // [rsp+10h] [rbp-48h] BYREF
size_t size[8]; // [rsp+18h] [rbp-40h] BYREF

size[0] = 0LL;
v16 = 0LL;
if ( !a7 )
return (unsigned int)-8;
if ( !(unsigned int)IsValidMechOid() )
return (unsigned int)-8;
if ( !(unsigned int)IsValidContextFlags(a2) )
return (unsigned int)-8;
v9 = CalculateMinSpnegoInitTokenSize(a4, a6, a1, a2 != 0, size, &v16);
if ( !v9 )
{
v11 = size[0];
v12 = calloc(1uLL, size[0]);
v13 = v12;
if ( v12 )
{
v9 = CreateSpnegoInitToken(a1, a2, a3, a4, a5, a6, v12, v11, v16);
if ( v9 || (v9 = InitTokenFromBinary(0LL, 1LL, v13, size[0], a7)) != 0 )
free(v13);
}
else
{
v9 = -6;
}
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned __int8 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
unsigned int v9; // ebx
size_t v11; // rbx
void *v12; // rax
void *v13; // r15
__int64 v16; // [rsp+10h] [rbp-48h] BYREF
size_t size[8]; // [rsp+18h] [rbp-40h] BYREF

size[0] = 0LL;
v16 = 0LL;
if ( !a7 )
return (unsigned int)-8;
if ( !(unsigned int)IsValidMechOid() )
return (unsigned int)-8;
if ( !(unsigned int)IsValidContextFlags(a2) )
return (unsigned int)-8;
v9 = CalculateMinSpnegoInitTokenSize(a4, a6, a1, a2 != 0, size, &v16);
if ( !v9 )
{
v11 = size[0];
v12 = calloc(1uLL, size[0]);
v13 = v12;
if ( v12 )
{
v9 = CreateSpnegoInitToken(a1, a2, a3, a4, a5, a6, v12, v11, v16);
if ( v9 || (v9 = InitTokenFromBinary(0LL, 1LL, v13, size[0], a7)) != 0 )
free(v13);
}
else
{
v9 = -6;
}
}
return v9;
}

original_code:
int spnegoCreateNegTokenInit( SPNEGO_MECH_OID MechType,
          unsigned char ucContextFlags, unsigned char* pbMechToken,
          unsigned long ulMechTokenLen, unsigned char* pbMechListMIC,
          unsigned long ulMechListMICLen, SPNEGO_TOKEN_HANDLE* phSpnegoToken )
{
   int nReturn = -8;
   long nTokenLength = 0L;
   long nInternalTokenLength = 0L;
   unsigned char* pbTokenData = ((void *)0);
   SPNEGO_TOKEN** ppSpnegoToken = (SPNEGO_TOKEN**) phSpnegoToken;
   if ( ((void *)0) != ppSpnegoToken &&
         IsValidMechOid( MechType ) &&
         IsValidContextFlags( ucContextFlags ) )
   {
      if ( ( nReturn = CalculateMinSpnegoInitTokenSize( ulMechTokenLen, ulMechListMICLen,
                                                         MechType, ( ucContextFlags != 0L ),
                                                         &nTokenLength, &nInternalTokenLength ) )
                        == 0 )
      {
         pbTokenData = calloc( 1, nTokenLength );
         if ( ((void *)0) != pbTokenData )
         {
            if ( ( nReturn = CreateSpnegoInitToken( MechType,
                                                 ucContextFlags, pbMechToken,
                                                 ulMechTokenLen, pbMechListMIC,
                                                 ulMechListMICLen, pbTokenData,
                                                 nTokenLength, nInternalTokenLength ) )
                              == 0 )
            {
               nReturn = InitTokenFromBinary( 0,
                                             0x1,
                                             pbTokenData, nTokenLength, ppSpnegoToken );
            }
            if ( 0 != nReturn )
            {
               free( pbTokenData );
            }
         }
         else
         {
            nReturn = -6;
         }
      }
   }
   ;
   return nReturn;
}

canonical_original_code:
int spnegoCreateNegTokenInit(enum spnego_mech_oid MechType, unsigned char ucContextFlags, unsigned char *pbMechToken, unsigned long ulMechTokenLen, unsigned char *pbMechListMIC, unsigned long ulMechListMICLen, void **phSpnegoToken)
{
   int nReturn = -8;
   long nTokenLength = 0L;
   long nInternalTokenLength = 0L;
   unsigned char *pbTokenData = ((void *)0);
   struct SpnegoToken **ppSpnegoToken = (SPNEGO_TOKEN**) phSpnegoToken;
   if ( ((void *)0) != ppSpnegoToken &&
         IsValidMechOid( MechType ) &&
         IsValidContextFlags( ucContextFlags ) )
   {
      if ( ( nReturn = CalculateMinSpnegoInitTokenSize( ulMechTokenLen, ulMechListMICLen,
                                                         MechType, ( ucContextFlags != 0L ),
                                                         &nTokenLength, &nInternalTokenLength ) )
                        == 0 )
      {
         pbTokenData = calloc( 1, nTokenLength );
         if ( ((void *)0) != pbTokenData )
         {
            if ( ( nReturn = CreateSpnegoInitToken( MechType,
                                                 ucContextFlags, pbMechToken,
                                                 ulMechTokenLen, pbMechListMIC,
                                                 ulMechListMICLen, pbTokenData,
                                                 nTokenLength, nInternalTokenLength ) )
                              == 0 )
            {
               nReturn = InitTokenFromBinary( 0,
                                             0x1,
                                             pbTokenData, nTokenLength, ppSpnegoToken );
            }
            if ( 0 != nReturn )
            {
               free( pbTokenData );
            }
         }
         else
         {
            nReturn = -6;
         }
      }
   }
   ;
   return nReturn;
}

variable_types: enum spnego_mech_oid { spnego_mech_oid_Kerberos_V5_Legacy=0, spnego_mech_oid_Kerberos_V5=1, spnego_mech_oid_Spnego=2, spnego_mech_oid_NotUsed=-1 }

variable_types:
ucContextFlags
unsigned char

variable_types:
pbMechToken
unsigned char *

variable_types:
ulMechTokenLen
unsigned long

variable_types:
pbMechListMIC
unsigned char *

variable_types:
ulMechListMICLen
unsigned long

variable_types: nTokenLength long

variable_types: nInternalTokenLength long

user_defined_types: enum spnego_element_type { spnego_element_min=0, spnego_init_mechtypes=1, spnego_init_reqFlags=2, spnego_init_mechToken=3, spnego_init_mechListMIC=4, spnego_targ_negResult=5, spnego_targ_supportedMech=6, spnego_targ_responseToken=7, spnego_targ_mechListMIC=8, spnego_element_max=9 }


spnegoCreateNegTokenTarg

decompiled_code:
__int64 __fastcall spnegoCreateNegTokenTarg(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
int v9; // eax
int v10; // eax
unsigned int v11; // ebp
size_t v13; // rbp
void *v14; // rax
void *v15; // r15
__int64 v18; // [rsp+10h] [rbp-48h] BYREF
size_t size[8]; // [rsp+18h] [rbp-40h] BYREF

size[0] = 0LL;
v18 = 0LL;
if ( !a7 )
return (unsigned int)-8;
v9 = ((__int64 (*)(void))IsValidMechOid)();
if ( a1 != -1 && !v9 )
return (unsigned int)-8;
v10 = IsValidNegResult(a2);
if ( a2 != -1 && !v10 )
return (unsigned int)-8;
if ( !(unsigned int)IsValidMechOid(a1) && a2 <= 1 )
return (unsigned int)-8;
v11 = CalculateMinSpnegoTargTokenSize(a1, a2, a4, a6, size, &v18);
if ( !v11 )
{
v13 = size[0];
v14 = calloc(1uLL, size[0]);
v15 = v14;
if ( v14 )
{
v11 = CreateSpnegoTargToken(a1, a2, a3, a4, a5, a6, v14, v13, v18);
if ( v11 || (v11 = InitTokenFromBinary(0LL, 1LL, v15, size[0], a7)) != 0 )
free(v15);
}
else
{
v11 = -6;
}
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
int v9; // eax
int v10; // eax
unsigned int v11; // ebp
size_t v13; // rbp
void *v14; // rax
void *v15; // r15
__int64 v18; // [rsp+10h] [rbp-48h] BYREF
size_t size[8]; // [rsp+18h] [rbp-40h] BYREF

size[0] = 0LL;
v18 = 0LL;
if ( !a7 )
return (unsigned int)-8;
v9 = ((__int64 (*)(void))IsValidMechOid)();
if ( a1 != -1 && !v9 )
return (unsigned int)-8;
v10 = IsValidNegResult(a2);
if ( a2 != -1 && !v10 )
return (unsigned int)-8;
if ( !(unsigned int)IsValidMechOid(a1) && a2 <= 1 )
return (unsigned int)-8;
v11 = CalculateMinSpnegoTargTokenSize(a1, a2, a4, a6, size, &v18);
if ( !v11 )
{
v13 = size[0];
v14 = calloc(1uLL, size[0]);
v15 = v14;
if ( v14 )
{
v11 = CreateSpnegoTargToken(a1, a2, a3, a4, a5, a6, v14, v13, v18);
if ( v11 || (v11 = InitTokenFromBinary(0LL, 1LL, v15, size[0], a7)) != 0 )
free(v15);
}
else
{
v11 = -6;
}
}
return v11;
}

original_code:
int spnegoCreateNegTokenTarg( SPNEGO_MECH_OID MechType,
          SPNEGO_NEGRESULT spnegoNegResult, unsigned char* pbMechToken,
          unsigned long ulMechTokenLen, unsigned char* pbMechListMIC,
          unsigned long ulMechListMICLen, SPNEGO_TOKEN_HANDLE* phSpnegoToken )
{
   int nReturn = -8;
   long nTokenLength = 0L;
   long nInternalTokenLength = 0L;
   unsigned char* pbTokenData = ((void *)0);
   SPNEGO_TOKEN** ppSpnegoToken = (SPNEGO_TOKEN**) phSpnegoToken;
   if ( ((void *)0) != ppSpnegoToken &&
         ( IsValidMechOid( MechType ) ||
            spnego_mech_oid_NotUsed == MechType ) &&
         ( IsValidNegResult( spnegoNegResult ) ||
            spnego_negresult_NotUsed == spnegoNegResult ) &&
         !( !IsValidMechOid( MechType ) &&
            ( spnego_negresult_success == spnegoNegResult ||
              spnego_negresult_incomplete == spnegoNegResult ) ) )
   {
      if ( ( nReturn = CalculateMinSpnegoTargTokenSize( MechType, spnegoNegResult, ulMechTokenLen,
                                                         ulMechListMICLen, &nTokenLength,
                                                         &nInternalTokenLength ) )
                        == 0 )
      {
         pbTokenData = calloc( 1, nTokenLength );
         if ( ((void *)0) != pbTokenData )
         {
            if ( ( nReturn = CreateSpnegoTargToken( MechType,
                                                 spnegoNegResult, pbMechToken,
                                                 ulMechTokenLen, pbMechListMIC,
                                                 ulMechListMICLen, pbTokenData,
                                                 nTokenLength, nInternalTokenLength ) )
                              == 0 )
            {
               nReturn = InitTokenFromBinary( 0,
                                             0x1,
                                             pbTokenData, nTokenLength, ppSpnegoToken );
            }
            if ( 0 != nReturn )
            {
               free( pbTokenData );
            }
         }
         else
         {
            nReturn = -6;
         }
      }
   }
   ;
   return nReturn;
}

canonical_original_code:
int spnegoCreateNegTokenTarg(enum spnego_mech_oid MechType, enum spnego_negResult spnegoNegResult, unsigned char *pbMechToken, unsigned long ulMechTokenLen, unsigned char *pbMechListMIC, unsigned long ulMechListMICLen, void **phSpnegoToken)
{
   int nReturn = -8;
   long nTokenLength = 0L;
   long nInternalTokenLength = 0L;
   unsigned char *pbTokenData = ((void *)0);
   struct SpnegoToken **ppSpnegoToken = (SPNEGO_TOKEN**) phSpnegoToken;
   if ( ((void *)0) != ppSpnegoToken &&
         ( IsValidMechOid( MechType ) ||
            spnego_mech_oid_NotUsed == MechType ) &&
         ( IsValidNegResult( spnegoNegResult ) ||
            spnego_negresult_NotUsed == spnegoNegResult ) &&
         !( !IsValidMechOid( MechType ) &&
            ( spnego_negresult_success == spnegoNegResult ||
              spnego_negresult_incomplete == spnegoNegResult ) ) )
   {
      if ( ( nReturn = CalculateMinSpnegoTargTokenSize( MechType, spnegoNegResult, ulMechTokenLen,
                                                         ulMechListMICLen, &nTokenLength,
                                                         &nInternalTokenLength ) )
                        == 0 )
      {
         pbTokenData = calloc( 1, nTokenLength );
         if ( ((void *)0) != pbTokenData )
         {
            if ( ( nReturn = CreateSpnegoTargToken( MechType,
                                                 spnegoNegResult, pbMechToken,
                                                 ulMechTokenLen, pbMechListMIC,
                                                 ulMechListMICLen, pbTokenData,
                                                 nTokenLength, nInternalTokenLength ) )
                              == 0 )
            {
               nReturn = InitTokenFromBinary( 0,
                                             0x1,
                                             pbTokenData, nTokenLength, ppSpnegoToken );
            }
            if ( 0 != nReturn )
            {
               free( pbTokenData );
            }
         }
         else
         {
            nReturn = -6;
         }
      }
   }
   ;
   return nReturn;
}

variable_types: enum spnego_negResult { spnego_negresult_success=0, spnego_negresult_incomplete=1, spnego_negresult_rejected=2, spnego_negresult_NotUsed=-1 }

user_defined_types: enum spnego_mech_oid { spnego_mech_oid_Kerberos_V5_Legacy=0, spnego_mech_oid_Kerberos_V5=1, spnego_mech_oid_Spnego=2, spnego_mech_oid_NotUsed=-1 }


spnegoTokenGetBinary

decompiled_code:
__int64 __fastcall spnegoTokenGetBinary(__int64 a1, void *a2, size_t *a3)
{
int v4; // eax
size_t v5; // rdx
__int64 result; // rax

v4 = IsValidSpnegoToken();
if ( !a3 || !v4 )
return 4294967288LL;
if ( a2 && (v5 = *(_QWORD *)(a1 + 32), v5 <= *a3) )
{
memcpy(a2, *(const void **)(a1 + 24), v5);
*a3 = *(_QWORD *)(a1 + 32);
result = 0LL;
}
else
{
*a3 = *(_QWORD *)(a1 + 32);
result = 4294967284LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, void *a2, size_t *a3)
{
int v4; // eax
size_t v5; // rdx
__int64 result; // rax

v4 = IsValidSpnegoToken();
if ( !a3 || !v4 )
return 4294967288LL;
if ( a2 && (v5 = *(_QWORD *)(a1 + 32), v5 <= *a3) )
{
memcpy(a2, *(const void **)(a1 + 24), v5);
*a3 = *(_QWORD *)(a1 + 32);
result = 0LL;
}
else
{
*a3 = *(_QWORD *)(a1 + 32);
result = 4294967284LL;
}
return result;
}

original_code:
int spnegoTokenGetBinary( SPNEGO_TOKEN_HANDLE hSpnegoToken, unsigned char* pbTokenData,
                           unsigned long * pulDataLen )
{
   int nReturn = -8;
   SPNEGO_TOKEN* pSpnegoToken = (SPNEGO_TOKEN*) hSpnegoToken;
   if ( IsValidSpnegoToken( pSpnegoToken ) &&
         ((void *)0) != pulDataLen )
   {
      if ( ((void *)0) == pbTokenData ||
            pSpnegoToken->ulBinaryDataLen > *pulDataLen )
      {
         *pulDataLen = pSpnegoToken->ulBinaryDataLen;
         nReturn = -12;
      }
      else
      {
         memcpy( pbTokenData, pSpnegoToken->pbBinaryData, pSpnegoToken->ulBinaryDataLen );
         *pulDataLen = pSpnegoToken->ulBinaryDataLen;
         nReturn = 0;
      }
   }
   ;
   return nReturn;;
}

canonical_original_code:
int spnegoTokenGetBinary(void *hSpnegoToken, unsigned char *pbTokenData, unsigned long *pulDataLen)
{
   int nReturn = -8;
   struct SpnegoToken *pSpnegoToken = (SPNEGO_TOKEN*) hSpnegoToken;
   if ( IsValidSpnegoToken( pSpnegoToken ) &&
         ((void *)0) != pulDataLen )
   {
      if ( ((void *)0) == pbTokenData ||
            pSpnegoToken->ulBinaryDataLen > *pulDataLen )
      {
         *pulDataLen = pSpnegoToken->ulBinaryDataLen;
         nReturn = -12;
      }
      else
      {
         memcpy( pbTokenData, pSpnegoToken->pbBinaryData, pSpnegoToken->ulBinaryDataLen );
         *pulDataLen = pSpnegoToken->ulBinaryDataLen;
         nReturn = 0;
      }
   }
   ;
   return nReturn;;
}

variable_types:
hSpnegoToken
void *

variable_types:
pulDataLen
unsigned long *

variable_types: struct SpnegoToken { unsigned long nStructSize; unsigned long ulFlags; int ucTokenType; unsigned char *pbBinaryData; unsigned long ulBinaryDataLen; int nNumElements; struct SpnegoElement { unsigned long nStructSize; int iElementPresent; enum spnego_element_type { spnego_element_min=0, spnego_init_mechtypes=1, spnego_init_reqFlags=2, spnego_init_mechToken=3, spnego_init_mechListMIC=4, spnego_targ_negResult=5, spnego_targ_supportedMech=6, spnego_targ_responseToken=7, spnego_targ_mechListMIC=8, spnego_element_max=9 } eElementType; unsigned char type; unsigned char *pbData; unsigned long nDatalength; } aElementArray[4]; } *


spnegoFreeData

decompiled_code:
__int64 spnegoFreeData()
{
return FreeSpnegoToken();
}

canonical_decompiled_code:
__int64 func4()
{
return FreeSpnegoToken();
}

original_code:
void spnegoFreeData( SPNEGO_TOKEN_HANDLE hSpnegoToken )
{
   FreeSpnegoToken( (SPNEGO_TOKEN*) hSpnegoToken);
   return;
}

canonical_original_code:
void spnegoFreeData(void *hSpnegoToken)
{
   FreeSpnegoToken( (struct SpnegoToken *) hSpnegoToken);
   return;
}


spnegoGetTokenType

decompiled_code:
__int64 __fastcall spnegoGetTokenType(__int64 a1, unsigned int *a2)
{
unsigned int v2; // eax

if ( !(unsigned int)IsValidSpnegoToken() )
return 4294967288LL;
if ( !a2 || !a1 )
return 4294967288LL;
v2 = *(_DWORD *)(a1 + 16);
if ( v2 > 1 )
return 4294967288LL;
*a2 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int *a2)
{
unsigned int v2; // eax

if ( !(unsigned int)IsValidSpnegoToken() )
return 4294967288LL;
if ( !a2 || !a1 )
return 4294967288LL;
v2 = *(_DWORD *)(a1 + 16);
if ( v2 > 1 )
return 4294967288LL;
*a2 = v2;
return 0LL;
}

original_code:
int spnegoGetTokenType( SPNEGO_TOKEN_HANDLE hSpnegoToken, int * piTokenType )
{
   int nReturn = -8;
   SPNEGO_TOKEN* pSpnegoToken = (SPNEGO_TOKEN*) hSpnegoToken;
   if ( IsValidSpnegoToken( pSpnegoToken ) &&
         ((void *)0) != piTokenType &&
         pSpnegoToken)
   {
      if ( 0 == pSpnegoToken->ucTokenType ||
            1 == pSpnegoToken->ucTokenType )
      {
         *piTokenType = pSpnegoToken->ucTokenType;
         nReturn = 0;
      }
   }
   ;
   return nReturn;
}

canonical_original_code:
int spnegoGetTokenType(void *hSpnegoToken, int *piTokenType)
{
   int nReturn = -8;
   struct SpnegoToken *pSpnegoToken = (SPNEGO_TOKEN*) hSpnegoToken;
   if ( IsValidSpnegoToken( pSpnegoToken ) &&
         ((void *)0) != piTokenType &&
         pSpnegoToken)
   {
      if ( 0 == pSpnegoToken->ucTokenType ||
            1 == pSpnegoToken->ucTokenType )
      {
         *piTokenType = pSpnegoToken->ucTokenType;
         nReturn = 0;
      }
   }
   ;
   return nReturn;
}

variable_types:
piTokenType
int *