decompiled_code:
__int64 voice_detect_modemtype()
{
const char **v1; // rax
char *v2; // rax
const char *v3; // rbx
char v4; // al
const unsigned __int16 *v5; // rcx
__int64 i; // rbp
const char *v7; // r13
const char *j; // rbp
char **v9; // rbx
const char *v10; // rdi
char *v11; // rbx
const unsigned __int16 *v12; // rdx
const unsigned __int16 *v13; // rdx
const char *v14; // r15
const char **v15; // rax
const char *v16; // r12
const char *v17; // r13
char v18[312]; // [rsp+0h] [rbp-138h] BYREF

lprintf(4LL, "detecting voice modem type");
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
if ( cvd[31] )
delay();
if ( cvd[85] )
{
if ( (unsigned int)voice_write("ATE1") )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
if ( (voice_command(&unk_7FC, "OK|ATE1") & 0x1000) == 0 )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
voice_flush(1LL);
}
else
{
if ( (unsigned int)voice_write("ATE0") )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
voice_flush(3LL);
}
memset(v18, 0, 0x100uLL);
if ( (unsigned int)voice_command("ATI9", &unk_7FC) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
if ( (unsigned int)voice_read(v18) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
if ( cvd[91] == 1LL )
{
lprintf(5LL, "V253 forced");
voice_modem = &V253modem;
}
if ( cvd[94] == 1LL )
{
lprintf(5LL, "V253ugly forced");
voice_modem = &V253ugly;
}
v1 = (const char **)voice_modem;
if ( (_UNKNOWN *)voice_modem == &no_modem
&& (memcmp("SMARTY ", v18, 7uLL)
|| (voice_modem = &Dr_Neuhaus, v1 = (const char **)&Dr_Neuhaus, &Dr_Neuhaus == &no_modem)) )
{
v2 = strchr(v18, 40);
v3 = v2;
if ( v2 )
{
v4 = v2[1];
if ( v4 )
{
if ( v4 == 1 )
{
v3 += 3;
}
else
{
v5 = *_ctype_b_loc();
do
{
do
++v3;
while ( (v5[*v3] & 0x800) != 0 );
}
while ( *v3 == 46 );
}
lprintf(5LL, "PNP String: '%s'", v3);
for ( i = 0LL; (_UNKNOWN *)voice_modem == &no_modem; ++i )
{
v16 = (&pnp_modem_database)[4 * i];
if ( !v16 )
break;
v17 = (const char *)qword_1828[4 * i];
if ( v17 )
{
lprintf(
6LL,
"checking pnpid %s / modelid %s",
(&pnp_modem_database)[4 * i],
(const char *)qword_1828[4 * i]);
if ( !strncmp(v16, v3, 3uLL) && !strncmp(v17, v3 + 3, 4uLL) )
{
LABEL_84:
lprintf(4LL, "PNP: found modem: %s", off_1838[4 * (int)i]);
voice_modem = *(&off_1830 + 4 * (int)i);
break;
}
}
else
{
lprintf(6LL, "checking pnpid %s / modelid %s", (&pnp_modem_database)[4 * i], "<none>");
if ( !strncmp(v16, v3, 3uLL) )
goto LABEL_84;
}
}
voice_read(v18);
}
}
voice_flush(3LL);
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
if ( (unsigned int)voice_command("ATI3", &unk_7FC) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
if ( (unsigned int)voice_read(v18) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
if ( !strstr(v18, "OK")
&& !strstr(v18, "ERROR")
&& !(unsigned int)voice_read(v18)
&& strstr(v18, "SupraExpress 56e PRO") )
{
voice_modem = &Supra56ePRO;
}
voice_flush(1LL);
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
if ( (unsigned int)voice_command("ATI", &unk_7FC) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
v7 = "ATI";
LABEL_57:
if ( (unsigned int)voice_read(v18) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
v11 = &v18[strlen(v18) - 1];
if ( v11 >= v18 )
{
v12 = *_ctype_b_loc();
do
{
if ( (v12[*v11] & 0x2000) == 0 )
break;
*v11-- = 0;
}
while ( v11 >= v18 );
}
v13 = *_ctype_b_loc();
for ( j = v18; (v13[*j] & 0x2000) != 0; ++j )
;
v9 = &off_1088;
v10 = "ATI";
while ( (_UNKNOWN *)voice_modem == &no_modem )
{
if ( !strcmp(v10, v7) && !strcmp(*v9, j) )
{
v14 = v9[1];
if ( v14 )
{
voice_flush(1LL);
if ( (unsigned int)voice_command(v14, &unk_7FC) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
strcpy(v18, "OK");
v7 = v14;
LABEL_55:
if ( (_UNKNOWN *)voice_modem != &no_modem || (unsigned int)voice_analyze(v18, &unk_7FC, 1LL) == 0x4000 )
break;
goto LABEL_57;
}
voice_modem = v9[2];
}
v9 += 4;
v10 = *(v9 - 1);
if ( !v10 )
goto LABEL_55;
}
voice_flush(1LL);
v15 = (const char **)voice_modem;
if ( !*(_QWORD *)(voice_modem + 304LL) )
{
lprintf(3LL, "%s detected, but driver is not available", (const char *)*voice_modem);
voice_modem = &no_modem;
exit(-1);
}
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
voice_command("AT+FCLASS=8", "OK");
if ( (unsigned int)voice_command("AT+VSM=1,8000", "OK") == 4096 )
voice_modem = &V253modem;
voice_command("AT+FCLASS=0", "OK");
v15 = (const char **)voice_modem;
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
voice_flush(1LL);
voice_modem = &no_modem;
lprintf(3LL, "no voice modem detected");
exit(-1);
}
}
lprintf(4LL, "%s detected", *v15);
}
else
{
lprintf(4LL, "%s detected", (const char *)*voice_modem);
lprintf(5LL, "voice modem type was set by using identification strings");
}
}
else
{
lprintf(5LL, "voice modem type was set by pnp id");
}
}
else
{
lprintf(4LL, "%s detected", *v1);
lprintf(5LL, "voice modem type was set by ATI9 partial match");
}
}
else
{
lprintf(5LL, "voice modem type was set directly");
}
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
const char **v1; // rax
char *v2; // rax
const char *v3; // rbx
char v4; // al
const unsigned __int16 *v5; // rcx
__int64 i; // rbp
const char *v7; // r13
const char *j; // rbp
char **v9; // rbx
const char *v10; // rdi
char *v11; // rbx
const unsigned __int16 *v12; // rdx
const unsigned __int16 *v13; // rdx
const char *v14; // r15
const char **v15; // rax
const char *v16; // r12
const char *v17; // r13
char v18[312]; // [rsp+0h] [rbp-138h] BYREF

lprintf(4LL, "detecting voice modem type");
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
if ( cvd[31] )
delay();
if ( cvd[85] )
{
if ( (unsigned int)voice_write("ATE1") )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
if ( (voice_command(&unk_7FC, "OK|ATE1") & 0x1000) == 0 )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
voice_flush(1LL);
}
else
{
if ( (unsigned int)voice_write("ATE0") )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
voice_flush(3LL);
}
memset(v18, 0, 0x100uLL);
if ( (unsigned int)voice_command("ATI9", &unk_7FC) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
if ( (unsigned int)voice_read(v18) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
if ( cvd[91] == 1LL )
{
lprintf(5LL, "V253 forced");
voice_modem = &V253modem;
}
if ( cvd[94] == 1LL )
{
lprintf(5LL, "V253ugly forced");
voice_modem = &V253ugly;
}
v1 = (const char **)voice_modem;
if ( (_UNKNOWN *)voice_modem == &no_modem
&& (memcmp("SMARTY ", v18, 7uLL)
|| (voice_modem = &Dr_Neuhaus, v1 = (const char **)&Dr_Neuhaus, &Dr_Neuhaus == &no_modem)) )
{
v2 = strchr(v18, 40);
v3 = v2;
if ( v2 )
{
v4 = v2[1];
if ( v4 )
{
if ( v4 == 1 )
{
v3 += 3;
}
else
{
v5 = *_ctype_b_loc();
do
{
do
++v3;
while ( (v5[*v3] & 0x800) != 0 );
}
while ( *v3 == 46 );
}
lprintf(5LL, "PNP String: '%s'", v3);
for ( i = 0LL; (_UNKNOWN *)voice_modem == &no_modem; ++i )
{
v16 = (&pnp_modem_database)[4 * i];
if ( !v16 )
break;
v17 = (const char *)qword_1828[4 * i];
if ( v17 )
{
lprintf(
6LL,
"checking pnpid %s / modelid %s",
(&pnp_modem_database)[4 * i],
(const char *)qword_1828[4 * i]);
if ( !strncmp(v16, v3, 3uLL) && !strncmp(v17, v3 + 3, 4uLL) )
{
LABEL_84:
lprintf(4LL, "PNP: found modem: %s", off_1838[4 * (int)i]);
voice_modem = *(&off_1830 + 4 * (int)i);
break;
}
}
else
{
lprintf(6LL, "checking pnpid %s / modelid %s", (&pnp_modem_database)[4 * i], "<none>");
if ( !strncmp(v16, v3, 3uLL) )
goto LABEL_84;
}
}
voice_read(v18);
}
}
voice_flush(3LL);
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
if ( (unsigned int)voice_command("ATI3", &unk_7FC) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
if ( (unsigned int)voice_read(v18) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
if ( !strstr(v18, "OK")
&& !strstr(v18, "ERROR")
&& !(unsigned int)voice_read(v18)
&& strstr(v18, "SupraExpress 56e PRO") )
{
voice_modem = &Supra56ePRO;
}
voice_flush(1LL);
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
if ( (unsigned int)voice_command("ATI", &unk_7FC) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
v7 = "ATI";
LABEL_57:
if ( (unsigned int)voice_read(v18) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
v11 = &v18[strlen(v18) - 1];
if ( v11 >= v18 )
{
v12 = *_ctype_b_loc();
do
{
if ( (v12[*v11] & 0x2000) == 0 )
break;
*v11-- = 0;
}
while ( v11 >= v18 );
}
v13 = *_ctype_b_loc();
for ( j = v18; (v13[*j] & 0x2000) != 0; ++j )
;
v9 = &off_1088;
v10 = "ATI";
while ( (_UNKNOWN *)voice_modem == &no_modem )
{
if ( !strcmp(v10, v7) && !strcmp(*v9, j) )
{
v14 = v9[1];
if ( v14 )
{
voice_flush(1LL);
if ( (unsigned int)voice_command(v14, &unk_7FC) )
{
lprintf(3LL, "modem detection failed");
exit(-1);
}
strcpy(v18, "OK");
v7 = v14;
LABEL_55:
if ( (_UNKNOWN *)voice_modem != &no_modem || (unsigned int)voice_analyze(v18, &unk_7FC, 1LL) == 0x4000 )
break;
goto LABEL_57;
}
voice_modem = v9[2];
}
v9 += 4;
v10 = *(v9 - 1);
if ( !v10 )
goto LABEL_55;
}
voice_flush(1LL);
v15 = (const char **)voice_modem;
if ( !*(_QWORD *)(voice_modem + 304LL) )
{
lprintf(3LL, "%s detected, but driver is not available", (const char *)*voice_modem);
voice_modem = &no_modem;
exit(-1);
}
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
voice_command("AT+FCLASS=8", "OK");
if ( (unsigned int)voice_command("AT+VSM=1,8000", "OK") == 4096 )
voice_modem = &V253modem;
voice_command("AT+FCLASS=0", "OK");
v15 = (const char **)voice_modem;
if ( (_UNKNOWN *)voice_modem == &no_modem )
{
voice_flush(1LL);
voice_modem = &no_modem;
lprintf(3LL, "no voice modem detected");
exit(-1);
}
}
lprintf(4LL, "%s detected", *v15);
}
else
{
lprintf(4LL, "%s detected", (const char *)*voice_modem);
lprintf(5LL, "voice modem type was set by using identification strings");
}
}
else
{
lprintf(5LL, "voice modem type was set by pnp id");
}
}
else
{
lprintf(4LL, "%s detected", *v1);
lprintf(5LL, "voice modem type was set by ATI9 partial match");
}
}
else
{
lprintf(5LL, "voice modem type was set directly");
}
return 0LL;
}

original_code:
int voice_detect_modemtype(void)
     {
     char buffer[(256)];
     char *cmnd;
     lprintf(4, "detecting voice modem type");
     if (voice_modem != &no_modem)
          {
          lprintf(5, "voice modem type was set directly");
          return((0));
          }
     else
          {
          int i;
          char *s;
   if (cvd.command_delay.d.i != 0)
   delay(cvd.command_delay.d.i);
          if (cvd.enable_command_echo.d.i)
               {
               if (voice_write("ATE1") != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               if ((voice_command("", "OK|ATE1") & (0x1000)) == (0x1000))
                    voice_flush(1);
               else
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               }
          else
               {
               if (voice_write("ATE0") != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               voice_flush(3);
               }
   memset( buffer, '\0', sizeof(buffer) );
   cmnd=(char *)ati9;
   if (voice_command(cmnd, "") != (0))
               {
               lprintf(3, "modem detection failed");
               exit((-1));
               }
   if (voice_read(buffer) != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
   }
          if((0==0)==cvd.forceV253.d.i)
          {
             lprintf(5, "V253 forced");
             voice_modem = &V253modem;
          }
          if((0==0)==cvd.forceV253subset.d.i)
          {
             lprintf(5, "V253ugly forced");
             voice_modem = &V253ugly;
          }
          i = 0;
          while ((voice_modem == &no_modem) && (pnp_partial_matches[i].s)) {
             if (!strncmp(pnp_partial_matches[i].s,
                          buffer,
                          strlen(pnp_partial_matches[i].s))) {
                voice_modem = pnp_partial_matches[i].modem_type;
             }
             i++;
          }
          if (voice_modem != &no_modem) {
             lprintf(4, "%s detected", voice_modem->name);
             lprintf(5,
                     "voice modem type was set by ATI9 partial match");
             return((0));
          }
   s = strchr(buffer, '(');
   if ( s && s[1] != '\0' )
   {
       if ( s[1] == '\1' )
    s+=3;
       else
           do { s++; } while( ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISdigit) || *s == '.' );
       lprintf(5, "PNP String: '%s'", s);
       i = 0;
       while (voice_modem == &no_modem &&
       pnp_modem_database[i].pnpid)
       {
     lprintf(6, "checking pnpid %s / modelid %s",
          pnp_modem_database[i].pnpid,
          pnp_modem_database[i].modelid ?
       pnp_modem_database[i].modelid : "<none>");
     if (strncmp(pnp_modem_database[i].pnpid, s, 3) == 0)
     {
         if (pnp_modem_database[i].modelid == ((void *)0) ||
      strncmp(pnp_modem_database[i].modelid, s+3, 4) == 0)
         {
      lprintf( 4, "PNP: found modem: %s",
     pnp_modem_database[i].verbose );
      voice_modem = pnp_modem_database[i].modem_type;
      break;
         }
     }
     i++;
        }
        voice_read(buffer);
   }
   voice_flush(3);
   if (voice_modem != &no_modem)
    {
           lprintf(5, "voice modem type was set by pnp id");
           return((0));
          }
   cmnd = (char *) ati3;
   if (voice_command(cmnd, "") != (0)) {
             lprintf(3, "modem detection failed");
             exit((-1));
          }
          if (voice_read(buffer) != (0)) {
             lprintf(3, "modem detection failed");
             exit((-1));
          }
          if ((strstr(buffer, "OK") == ((void *)0))
              && (strstr(buffer, "ERROR") == ((void *)0))) {
             if (voice_read(buffer) == (0)) {
                if (strstr(buffer, "SupraExpress 56e PRO")) {
                   voice_modem = &Supra56ePRO;
                }
             }
          }
          voice_flush(1);
          if (voice_modem != &no_modem) {
             lprintf(4, "%s detected", voice_modem->name);
             lprintf(5, "voice modem type was set by using                               identification strings");
             return((0));
          }
          cmnd = (char *) ati;
          if (voice_command(cmnd, "") != (0)) {
             lprintf(3, "modem detection failed");
             exit((-1));
          }
          do
               {
               if (voice_read(buffer) != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               s = buffer + strlen(buffer) - 1;
               while ((s >= buffer) && ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace) )
                    *s-- = '\0';
               s = buffer;
        while( ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace) ) s++;
               for (i = 0; ((modem_database[i].at_cmnd != ((void *)0)) &&
                (voice_modem == &no_modem)); i++)
                    {
                    if ((strcmp(modem_database[i].at_cmnd, cmnd) == 0) &&
                     (strcmp(modem_database[i].at_answr, s) == 0))
                         {
                         if (modem_database[i].next_cmnd != ((void *)0))
                              {
                              voice_flush(1);
                              cmnd = (char *) modem_database[i].next_cmnd;
                              if (voice_command(cmnd, "") != (0))
                                   {
                                   lprintf(3, "modem detection failed");
                                   exit((-1));
                                   }
                              sprintf(buffer, "OK");
                              break;
                              }
                         else
                              voice_modem = modem_database[i].modem_type;
                         }
                    }
               }
          while ((voice_modem == &no_modem) &&
           (voice_analyze(buffer, "", (0==0)) != (0x4000)));
          voice_flush(1);
          }
     if (voice_modem->init == ((void *)0))
          {
          lprintf(3, "%s detected, but driver is not available",
           voice_modem->name);
          voice_modem = &no_modem;
          exit((-1));
          };
     if (voice_modem == &no_modem) {
        voice_command("AT+FCLASS=8", "OK");
        if (voice_command("AT+VSM=1,8000", "OK")== (0x1000)) {
           voice_modem=&V253modem;
        }
        voice_command("AT+FCLASS=0", "OK");
     }
     if (voice_modem != &no_modem)
          {
          lprintf(4, "%s detected", voice_modem->name);
          return((0));
          };
     voice_flush(1);
     voice_modem = &no_modem;
     lprintf(3, "no voice modem detected");
     exit((-1));
     }

canonical_original_code:
int voice_detect_modemtype()
     {
     char buffer[-1];
     char *cmnd;
     lprintf(4, "detecting voice modem type");
     if (voice_modem != &no_modem)
          {
          lprintf(5, "voice modem type was set directly");
          return((0));
          }
     else
          {
          int i;
          char *s;
   if (cvd.command_delay.d.i != 0)
   delay(cvd.command_delay.d.i);
          if (cvd.enable_command_echo.d.i)
               {
               if (voice_write("ATE1") != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               if ((voice_command("", "OK|ATE1") & (0x1000)) == (0x1000))
                    voice_flush(1);
               else
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               }
          else
               {
               if (voice_write("ATE0") != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               voice_flush(3);
               }
   memset( buffer, '\0', sizeof(buffer) );
   cmnd=(char *)ati9;
   if (voice_command(cmnd, "") != (0))
               {
               lprintf(3, "modem detection failed");
               exit((-1));
               }
   if (voice_read(buffer) != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
   }
          if((0==0)==cvd.forceV253.d.i)
          {
             lprintf(5, "V253 forced");
             voice_modem = &V253modem;
          }
          if((0==0)==cvd.forceV253subset.d.i)
          {
             lprintf(5, "V253ugly forced");
             voice_modem = &V253ugly;
          }
          i = 0;
          while ((voice_modem == &no_modem) && (pnp_partial_matches[i].s)) {
             if (!strncmp(pnp_partial_matches[i].s,
                          buffer,
                          strlen(pnp_partial_matches[i].s))) {
                voice_modem = pnp_partial_matches[i].modem_type;
             }
             i++;
          }
          if (voice_modem != &no_modem) {
             lprintf(4, "%s detected", voice_modem->name);
             lprintf(5,
                     "voice modem type was set by ATI9 partial match");
             return((0));
          }
   s = strchr(buffer, '(');
   if ( s && s[1] != '\0' )
   {
       if ( s[1] == '\1' )
    s+=3;
       else
           do { s++; } while( ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISdigit) || *s == '.' );
       lprintf(5, "PNP String: '%s'", s);
       i = 0;
       while (voice_modem == &no_modem &&
       pnp_modem_database[i].pnpid)
       {
     lprintf(6, "checking pnpid %s / modelid %s",
          pnp_modem_database[i].pnpid,
          pnp_modem_database[i].modelid ?
       pnp_modem_database[i].modelid : "<none>");
     if (strncmp(pnp_modem_database[i].pnpid, s, 3) == 0)
     {
         if (pnp_modem_database[i].modelid == ((void *)0) ||
      strncmp(pnp_modem_database[i].modelid, s+3, 4) == 0)
         {
      lprintf( 4, "PNP: found modem: %s",
     pnp_modem_database[i].verbose );
      voice_modem = pnp_modem_database[i].modem_type;
      break;
         }
     }
     i++;
        }
        voice_read(buffer);
   }
   voice_flush(3);
   if (voice_modem != &no_modem)
    {
           lprintf(5, "voice modem type was set by pnp id");
           return((0));
          }
   cmnd = (char *) ati3;
   if (voice_command(cmnd, "") != (0)) {
             lprintf(3, "modem detection failed");
             exit((-1));
          }
          if (voice_read(buffer) != (0)) {
             lprintf(3, "modem detection failed");
             exit((-1));
          }
          if ((strstr(buffer, "OK") == ((void *)0))
              && (strstr(buffer, "ERROR") == ((void *)0))) {
             if (voice_read(buffer) == (0)) {
                if (strstr(buffer, "SupraExpress 56e PRO")) {
                   voice_modem = &Supra56ePRO;
                }
             }
          }
          voice_flush(1);
          if (voice_modem != &no_modem) {
             lprintf(4, "%s detected", voice_modem->name);
             lprintf(5, "voice modem type was set by using                               identification strings");
             return((0));
          }
          cmnd = (char *) ati;
          if (voice_command(cmnd, "") != (0)) {
             lprintf(3, "modem detection failed");
             exit((-1));
          }
          do
               {
               if (voice_read(buffer) != (0))
                    {
                    lprintf(3, "modem detection failed");
                    exit((-1));
                    }
               s = buffer + strlen(buffer) - 1;
               while ((s >= buffer) && ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace) )
                    *s-- = '\0';
               s = buffer;
        while( ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace) ) s++;
               for (i = 0; ((modem_database[i].at_cmnd != ((void *)0)) &&
                (voice_modem == &no_modem)); i++)
                    {
                    if ((strcmp(modem_database[i].at_cmnd, cmnd) == 0) &&
                     (strcmp(modem_database[i].at_answr, s) == 0))
                         {
                         if (modem_database[i].next_cmnd != ((void *)0))
                              {
                              voice_flush(1);
                              cmnd = (char *) modem_database[i].next_cmnd;
                              if (voice_command(cmnd, "") != (0))
                                   {
                                   lprintf(3, "modem detection failed");
                                   exit((-1));
                                   }
                              sprintf(buffer, "OK");
                              break;
                              }
                         else
                              voice_modem = modem_database[i].modem_type;
                         }
                    }
               }
          while ((voice_modem == &no_modem) &&
           (voice_analyze(buffer, "", (0==0)) != (0x4000)));
          voice_flush(1);
          }
     if (voice_modem->init == ((void *)0))
          {
          lprintf(3, "%s detected, but driver is not available",
           voice_modem->name);
          voice_modem = &no_modem;
          exit((-1));
          };
     if (voice_modem == &no_modem) {
        voice_command("AT+FCLASS=8", "OK");
        if (voice_command("AT+VSM=1,8000", "OK")== (0x1000)) {
           voice_modem=&V253modem;
        }
        voice_command("AT+FCLASS=0", "OK");
     }
     if (voice_modem != &no_modem)
          {
          lprintf(4, "%s detected", voice_modem->name);
          return((0));
          };
     voice_flush(1);
     voice_modem = &no_modem;
     lprintf(3, "no voice modem detected");
     exit((-1));
     }

variable_types:
cmnd
char *

variable_types: i int

variable_types:
s
char *


mydup

repo: Distrotech/mgetty

decompiled_code:
char *__fastcall mydup(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
if ( !v2 )
{
lprintf(1LL, "mydup can't malloc");
exit(1);
}
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
if ( !v2 )
{
lprintf(1LL, "mydup can't malloc");
exit(1);
}
return strcpy(v2, src);
}

original_code:
char * mydup (register char *s)
{
    register char *p = (char *) malloc(strlen(s) + 1);
    if (!p) {
 lprintf(1, "mydup can't malloc");
 exit(1);
    }
    strcpy(p, s);
    return(p);
}

canonical_original_code:
char *mydup(char *s)
{
    register char *p = (char *) malloc(strlen(s) + 1);
    if (!p) {
 lprintf(1, "mydup can't malloc");
 exit(1);
    }
    strcpy(p, s);
    return(p);
}

variable_types:
p
char *

return_type: char *


faxinit

decompiled_code:
__int64 faxinit()
{
FillTable((__int64)&MainTable, 7u, Pass, 1);
FillTable((__int64)&MainTable, 7u, Horiz, 2);
FillTable((__int64)&MainTable, 7u, V0, 3);
FillTable((__int64)&MainTable, 7u, VR, 4);
FillTable((__int64)&MainTable, 7u, VL, 5);
FillTable((__int64)&MainTable, 7u, (unsigned __int16 *)ExtV, 6);
FillTable((__int64)&MainTable, 7u, EOLV, 12);
FillTable((__int64)&WhiteTable, 0xCu, MakeUpW, 9);
FillTable((__int64)&WhiteTable, 0xCu, MakeUp, 11);
FillTable((__int64)&WhiteTable, 0xCu, TermW, 7);
FillTable((__int64)&WhiteTable, 0xCu, ExtH, 6);
FillTable((__int64)&WhiteTable, 0xCu, EOLH, 12);
FillTable((__int64)&BlackTable, 0xDu, MakeUpB, 10);
FillTable((__int64)&BlackTable, 0xDu, MakeUp, 11);
FillTable((__int64)&BlackTable, 0xDu, TermB, 8);
FillTable((__int64)&BlackTable, 0xDu, ExtH, 6);
return FillTable((__int64)&BlackTable, 0xDu, EOLH, 12);
}

canonical_decompiled_code:
__int64 func1()
{
func0((__int64)&MainTable, 7u, Pass, 1);
func0((__int64)&MainTable, 7u, Horiz, 2);
func0((__int64)&MainTable, 7u, V0, 3);
func0((__int64)&MainTable, 7u, VR, 4);
func0((__int64)&MainTable, 7u, VL, 5);
func0((__int64)&MainTable, 7u, (unsigned __int16 *)ExtV, 6);
func0((__int64)&MainTable, 7u, EOLV, 12);
func0((__int64)&WhiteTable, 0xCu, MakeUpW, 9);
func0((__int64)&WhiteTable, 0xCu, MakeUp, 11);
func0((__int64)&WhiteTable, 0xCu, TermW, 7);
func0((__int64)&WhiteTable, 0xCu, ExtH, 6);
func0((__int64)&WhiteTable, 0xCu, EOLH, 12);
func0((__int64)&BlackTable, 0xDu, MakeUpB, 10);
func0((__int64)&BlackTable, 0xDu, MakeUp, 11);
func0((__int64)&BlackTable, 0xDu, TermB, 8);
func0((__int64)&BlackTable, 0xDu, ExtH, 6);
return func0((__int64)&BlackTable, 0xDu, EOLH, 12);
}

original_code:
void
faxinit(void)
{
    FillTable(MainTable, 7, Pass, 1);
    FillTable(MainTable, 7, Horiz, 2);
    FillTable(MainTable, 7, V0, 3);
    FillTable(MainTable, 7, VR, 4);
    FillTable(MainTable, 7, VL, 5);
    FillTable(MainTable, 7, ExtV, 6);
    FillTable(MainTable, 7, EOLV, 12);
    FillTable(WhiteTable, 12, MakeUpW, 9);
    FillTable(WhiteTable, 12, MakeUp, 11);
    FillTable(WhiteTable, 12, TermW, 7);
    FillTable(WhiteTable, 12, ExtH, 6);
    FillTable(WhiteTable, 12, EOLH, 12);
    FillTable(BlackTable, 13, MakeUpB, 10);
    FillTable(BlackTable, 13, MakeUp, 11);
    FillTable(BlackTable, 13, TermB, 8);
    FillTable(BlackTable, 13, ExtH, 6);
    FillTable(BlackTable, 13, EOLH, 12);
}

canonical_original_code:
void faxinit()
{
    FillTable(MainTable, 7, Pass, 1);
    FillTable(MainTable, 7, Horiz, 2);
    FillTable(MainTable, 7, V0, 3);
    FillTable(MainTable, 7, VR, 4);
    FillTable(MainTable, 7, VL, 5);
    FillTable(MainTable, 7, ExtV, 6);
    FillTable(MainTable, 7, EOLV, 12);
    FillTable(WhiteTable, 12, MakeUpW, 9);
    FillTable(WhiteTable, 12, MakeUp, 11);
    FillTable(WhiteTable, 12, TermW, 7);
    FillTable(WhiteTable, 12, ExtH, 6);
    FillTable(WhiteTable, 12, EOLH, 12);
    FillTable(BlackTable, 13, MakeUpB, 10);
    FillTable(BlackTable, 13, MakeUp, 11);
    FillTable(BlackTable, 13, TermB, 8);
    FillTable(BlackTable, 13, ExtH, 6);
    FillTable(BlackTable, 13, EOLH, 12);
}

return_type: void


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

if ( a2 != 1 )
return 0xFFFFFFFFLL;
result = (unsigned int)*(char *)(a1 + 654);
if ( a3 )
*(_BYTE *)(a1 + 654) = *a3;
return result;
}

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

if ( a2 != 1 )
return 0xFFFFFFFFLL;
result = (unsigned int)*(char *)(a1 + 654);
if ( a3 )
*(_BYTE *)(a1 + 654) = *a3;
return result;
}

original_code:
int gsm_option (gsm r, int opt, int * val)
{
     int result = -1;
     switch (opt) {
     case 3:
          break;
     case 1:
          result = r->verbose;
          if (val) r->verbose = *val;
          break;
     case 2:
          break;
     default:
          break;
     }
     return result;
}

canonical_original_code:
int gsm_option(struct gsm_state *r, int opt, int *val)
{
     int result = -1;
     switch (opt) {
     case 3:
          break;
     case 1:
          result = r->verbose;
          if (val) r->verbose = *val;
          break;
     case 2:
          break;
     default:
          break;
     }
     return result;
}

variable_types: struct gsm_state { short dp0[280]; short z1; long L_z2; int mp; short u[8]; short LARpp[2][8]; short j; short ltp_cut; short nrp; short v[9]; short msr; char verbose; char fast; } *

variable_types: opt int

variable_types:
val
int *

variable_types: result int

return_type: int


timeout

decompiled_code:
void timeout()
{
has_timeout = 1;
}

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

original_code:
static RETSIGTYPE timeout()
{
    has_timeout = (1==1);
}

canonical_original_code:
static void timeout()
{
    has_timeout = (1==1);
}


decompiled_code:
const char *__fastcall voice_device_mode_name(int a1)
{
const char *result; // rax
__int64 v2[14]; // [rsp+0h] [rbp-70h]

v2[0] = (__int64)"undefined";
v2[1] = (__int64)"No Device";
v2[2] = (__int64)"Dialup Line";
v2[3] = (__int64)"Ext. Microphone";
v2[4] = (__int64)"Int. Microphone";
v2[5] = (__int64)"Ext. Speaker";
v2[6] = (__int64)"Int. Speaker";
v2[7] = (__int64)"Local Handset";
v2[8] = (__int64)"Dialup Line and Ext. Speaker";
v2[9] = (__int64)"Dialup Line and Int. Speaker";
v2[10] = (__int64)"Dialup Line and Local Handset";
v2[11] = (__int64)"Dialup Line, Ext. Mic. and Ext. Speaker";
v2[12] = (__int64)"Dialup Line, Int. Mic. and Int. Speaker";
result = "undefined";
if ( a1 <= 12 )
result = (const char *)v2[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax
__int64 v2[14]; // [rsp+0h] [rbp-70h]

v2[0] = (__int64)"undefined";
v2[1] = (__int64)"No Device";
v2[2] = (__int64)"Dialup Line";
v2[3] = (__int64)"Ext. Microphone";
v2[4] = (__int64)"Int. Microphone";
v2[5] = (__int64)"Ext. Speaker";
v2[6] = (__int64)"Int. Speaker";
v2[7] = (__int64)"Local Handset";
v2[8] = (__int64)"Dialup Line and Ext. Speaker";
v2[9] = (__int64)"Dialup Line and Int. Speaker";
v2[10] = (__int64)"Dialup Line and Local Handset";
v2[11] = (__int64)"Dialup Line, Ext. Mic. and Ext. Speaker";
v2[12] = (__int64)"Dialup Line, Int. Mic. and Int. Speaker";
result = "undefined";
if ( a1 <= 12 )
result = (const char *)v2[a1];
return result;
}

original_code:
char *voice_device_mode_name(int device_number)
     {
       char* device_name[(0x000C)+1] =
       {"undefined",
 "No Device",
 "Dialup Line",
 "Ext. Microphone",
 "Int. Microphone",
 "Ext. Speaker",
 "Int. Speaker",
 "Local Handset",
 "Dialup Line and Ext. Speaker",
 "Dialup Line and Int. Speaker",
 "Dialup Line and Local Handset",
 "Dialup Line, Ext. Mic. and Ext. Speaker",
 "Dialup Line, Int. Mic. and Int. Speaker"};
     if (device_number > (0x000C))
       {
  return(device_name[0]);
       }
     else
       {
  return(device_name[device_number]);
       };
     }

canonical_original_code:
char *voice_device_mode_name(int device_number)
     {
       char *device_name[-1] = {"undefined",
 "No Device",
 "Dialup Line",
 "Ext. Microphone",
 "Int. Microphone",
 "Ext. Speaker",
 "Int. Speaker",
 "Local Handset",
 "Dialup Line and Ext. Speaker",
 "Dialup Line and Int. Speaker",
 "Dialup Line and Local Handset",
 "Dialup Line, Ext. Mic. and Ext. Speaker",
 "Dialup Line, Int. Mic. and Int. Speaker"};
     if (device_number > (0x000C))
       {
  return(device_name[0]);
       }
     else
       {
  return(device_name[device_number]);
       };
     }


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

lprintf(4LL, "closing voice modem device");
v0 = voice_fd;
if ( voice_fd == -1 )
{
lprintf(3LL, "no voice modem device open");
}
else
{
close(voice_fd);
voice_fd = -1;
rmlocks();
v0 = 0;
}
return v0;
}

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

lprintf(4LL, "closing voice modem device");
v0 = voice_fd;
if ( voice_fd == -1 )
{
lprintf(3LL, "no voice modem device open");
}
else
{
close(voice_fd);
voice_fd = -1;
rmlocks();
v0 = 0;
}
return v0;
}

original_code:
int voice_close_device(void)
     {
     lprintf(4, "closing voice modem device");
     if (voice_fd == (-1))
          {
          lprintf(3, "no voice modem device open");
          return((-1));
          };
     close(voice_fd);
     voice_fd = (-1);
     rmlocks();
     return((0));
     }

canonical_original_code:
int voice_close_device()
     {
     lprintf(4, "closing voice modem device");
     if (voice_fd == (-1))
          {
          lprintf(3, "no voice modem device open");
          return((-1));
          };
     close(voice_fd);
     voice_fd = (-1);
     rmlocks();
     return((0));
     }


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

if ( a1 == 8200 && use_on_hook_off_hook )
{
if ( voice_modem_state == 7 )
{
(*(void (**)(void))(voice_modem + 408LL))();
start_action = 1;
}
result = 0LL;
}
else if ( a1 == 8199 && use_on_hook_off_hook )
{
if ( voice_modem_state != 6
|| ((*(void (**)(void))(voice_modem + 400LL))(), result = use_on_hook_off_hook, use_on_hook_off_hook) )
{
if ( voice_modem_state == 5 )
(*(void (**)(void))(voice_modem + 392LL))();
result = 0LL;
}
}
else if ( (unsigned int)(a1 - 8199) <= 1 )
{
result = 0LL;
}
else if ( a1 == 8209 )
{
result = dtmf_mode;
if ( dtmf_mode == 1 )
{
printf("%c\n", (unsigned int)a2);
voice_stop_current_action();
result = 0LL;
}
else if ( dtmf_mode == 2 )
{
if ( a2 == 42 )
{
dtmf_string_buffer = 0;
result = 0LL;
}
else
{
v3 = strlen(&dtmf_string_buffer);
if ( v3 > 254 || a2 == 35 )
{
puts(&dtmf_string_buffer);
voice_stop_current_action();
result = 0LL;
}
else
{
*(&dtmf_string_buffer + v3 + 1) = 0;
*(&dtmf_string_buffer + v3) = a2;
result = 0LL;
}
}
}
else if ( dtmf_mode )
{
result = 4294967294LL;
}
}
else if ( a1 == 16387 )
{
result = voice_stop_current_action();
}
else
{
result = 4294967294LL;
}
return result;
}

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

if ( a1 == 8200 && use_on_hook_off_hook )
{
if ( voice_modem_state == 7 )
{
(*(void (**)(void))(voice_modem + 408LL))();
start_action = 1;
}
result = 0LL;
}
else if ( a1 == 8199 && use_on_hook_off_hook )
{
if ( voice_modem_state != 6
|| ((*(void (**)(void))(voice_modem + 400LL))(), result = use_on_hook_off_hook, use_on_hook_off_hook) )
{
if ( voice_modem_state == 5 )
(*(void (**)(void))(voice_modem + 392LL))();
result = 0LL;
}
}
else if ( (unsigned int)(a1 - 8199) <= 1 )
{
result = 0LL;
}
else if ( a1 == 8209 )
{
result = dtmf_mode;
if ( dtmf_mode == 1 )
{
printf("%c\n", (unsigned int)a2);
voice_stop_current_action();
result = 0LL;
}
else if ( dtmf_mode == 2 )
{
if ( a2 == 42 )
{
dtmf_string_buffer = 0;
result = 0LL;
}
else
{
v3 = strlen(&dtmf_string_buffer);
if ( v3 > 254 || a2 == 35 )
{
puts(&dtmf_string_buffer);
voice_stop_current_action();
result = 0LL;
}
else
{
*(&dtmf_string_buffer + v3 + 1) = 0;
*(&dtmf_string_buffer + v3) = a2;
result = 0LL;
}
}
}
else if ( dtmf_mode )
{
result = 4294967294LL;
}
}
else if ( a1 == 16387 )
{
result = voice_stop_current_action();
}
else
{
result = 4294967294LL;
}
return result;
}

original_code:
int handle_event(int event, event_data data)
     {
     if ((use_on_hook_off_hook) && (event == (0x2008)) &&
      (voice_modem_state == (0x0007)))
          {
          voice_modem->stop_waiting();
          start_action = (0==0);
          };
     if ((use_on_hook_off_hook) && (event == (0x2007)) &&
      (voice_modem_state == (0x0006)))
          {
          voice_modem->stop_recording();
          };
     if ((use_on_hook_off_hook) && (event == (0x2007)) &&
   (voice_modem_state == (0x0005)))
          {
          voice_modem->stop_playing();
          };
     if ((event == (0x2008)) || (event == (0x2007)))
          return((0));
     if (event == (0x2011))
          switch (dtmf_mode)
               {
               case (0):
                    return((0));
               case (1):
                    printf("%c\n", data.c);
                    voice_stop_current_action();
                    return((0));
               case (2):
      {
                       int length;
         if (data.c == '*')
       {
       dtmf_string_buffer[0] = 0x00;
       return((0));
       };
         length = strlen(dtmf_string_buffer);
         if ((data.c != '#') && (length < ((256) - 1)))
       {
       dtmf_string_buffer[length + 1] = 0x00;
       dtmf_string_buffer[length] = data.c;
       return((0));
       };
         printf("%s\n", dtmf_string_buffer);
         voice_stop_current_action();
         return((0));
                    }
               };
     if (event == (0x4003))
          return(voice_stop_current_action());
     return((-2));
     }

canonical_original_code:
int handle_event(int event, union event_data data)
     {
     if ((use_on_hook_off_hook) && (event == (0x2008)) &&
      (voice_modem_state == (0x0007)))
          {
          voice_modem->stop_waiting();
          start_action = (0==0);
          };
     if ((use_on_hook_off_hook) && (event == (0x2007)) &&
      (voice_modem_state == (0x0006)))
          {
          voice_modem->stop_recording();
          };
     if ((use_on_hook_off_hook) && (event == (0x2007)) &&
   (voice_modem_state == (0x0005)))
          {
          voice_modem->stop_playing();
          };
     if ((event == (0x2008)) || (event == (0x2007)))
          return((0));
     if (event == (0x2011))
          switch (dtmf_mode)
               {
               case (0):
                    return((0));
               case (1):
                    printf("%c\n", data.c);
                    voice_stop_current_action();
                    return((0));
               case (2):
      {
                       int length;
         if (data.c == '*')
       {
       dtmf_string_buffer[0] = 0x00;
       return((0));
       };
         length = strlen(dtmf_string_buffer);
         if ((data.c != '#') && (length < ((256) - 1)))
       {
       dtmf_string_buffer[length + 1] = 0x00;
       dtmf_string_buffer[length] = data.c;
       return((0));
       };
         printf("%s\n", dtmf_string_buffer);
         voice_stop_current_action();
         return((0));
                    }
               };
     if (event == (0x4003))
          return(voice_stop_current_action());
     return((-2));
     }

variable_types: event int

variable_types: union event_data { char c; int i; void *p; struct { int frequency; int length; } beep; }

variable_types: length int


decompiled_code:
__int64 __fastcall voice_command(const char *a1, const char *a2)
{
unsigned int v2; // ebx
unsigned int v3; // eax
int v4; // eax
_BYTE v6[296]; // [rsp+0h] [rbp-128h] BYREF

lprintf(5LL, "voice command: '%s' -> '%s'", a1, a2);
if ( cvd[31] )
delay();
v2 = 0x4000;
if ( *a1 )
{
v2 = voice_write("%s", a1);
if ( v2 )
{
voice_flush(1LL);
return 0x4000;
}
if ( cvd[85] )
{
do
{
v2 = voice_read(v6);
if ( v2 )
goto LABEL_21;
v4 = voice_analyze(v6, a1, 1LL);
if ( v4 == 0x4000 )
{
lprintf(3LL, "%s: Modem did not echo the command", program_name);
voice_flush(1LL);
return 0x4000;
}
if ( v4 == 8195 )
{
LABEL_20:
lprintf(3LL, "%s: Modem returned ERROR", program_name);
voice_flush(1LL);
return 0x4000;
}
}
while ( v4 != 4096 );
}
}
if ( *a2 )
{
while ( !(unsigned int)voice_read(v6) )
{
v3 = voice_analyze(v6, a2, 0LL);
v2 = v3;
if ( v3 == 0x4000 )
{
lprintf(3LL, "%s: Invalid modem answer", program_name);
voice_flush(1LL);
return v2;
}
if ( v3 == 8195 )
goto LABEL_20;
if ( (v3 & 0x1000) != 0 )
return v2;
}
LABEL_21:
voice_flush(1LL);
v2 = 0x4000;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
unsigned int v2; // ebx
unsigned int v3; // eax
int v4; // eax
_BYTE v6[296]; // [rsp+0h] [rbp-128h] BYREF

lprintf(5LL, "voice command: '%s' -> '%s'", a1, a2);
if ( cvd[31] )
delay();
v2 = 0x4000;
if ( *a1 )
{
v2 = voice_write("%s", a1);
if ( v2 )
{
voice_flush(1LL);
return 0x4000;
}
if ( cvd[85] )
{
do
{
v2 = voice_read(v6);
if ( v2 )
goto LABEL_21;
v4 = voice_analyze(v6, a1, 1LL);
if ( v4 == 0x4000 )
{
lprintf(3LL, "%s: Modem did not echo the command", program_name);
voice_flush(1LL);
return 0x4000;
}
if ( v4 == 8195 )
{
LABEL_20:
lprintf(3LL, "%s: Modem returned ERROR", program_name);
voice_flush(1LL);
return 0x4000;
}
}
while ( v4 != 4096 );
}
}
if ( *a2 )
{
while ( !(unsigned int)voice_read(v6) )
{
v3 = voice_analyze(v6, a2, 0LL);
v2 = v3;
if ( v3 == 0x4000 )
{
lprintf(3LL, "%s: Invalid modem answer", program_name);
voice_flush(1LL);
return v2;
}
if ( v3 == 8195 )
goto LABEL_20;
if ( (v3 & 0x1000) != 0 )
return v2;
}
LABEL_21:
voice_flush(1LL);
v2 = 0x4000;
}
return v2;
}

original_code:
int voice_command(char *command, char *expected_answer)
     {
     char buffer[(256)];
     int result = (0x4000);
     lprintf(5, "voice command: '%s' -> '%s'", command,
      expected_answer);
     if (cvd.command_delay.d.i != 0)
          delay(cvd.command_delay.d.i);
     if (strlen(command) != 0)
          {
          if (voice_write("%s", command) != (0))
               {
               voice_flush(1);
               return((0x4000));
               };
          if (cvd.enable_command_echo.d.i)
               do
                    {
                    if (voice_read(buffer) != (0))
                         {
                         voice_flush(1);
                         return((0x4000));
                         };
                    result = voice_analyze(buffer, command, (0==0));
                    if (result == (0x4000))
                         {
                         lprintf(3,
                          "%s: Modem did not echo the command", program_name);
                         voice_flush(1);
                         return((0x4000));
                         };
                    if (result == (0x2003))
                         {
                         lprintf(3, "%s: Modem returned ERROR",
                          program_name);
                         voice_flush(1);
                         return((0x4000));
                         };
                    }
               while (result != (0x1000));
          result = (0);
          };
     if (strlen(expected_answer) != 0)
          {
          do
               {
               if (voice_read(buffer) != (0))
                    {
                    voice_flush(1);
                    return((0x4000));
                    };
               result = voice_analyze(buffer, expected_answer, (0==1));
               if (result == (0x4000))
                    {
                    lprintf(3, "%s: Invalid modem answer",
                     program_name);
                    voice_flush(1);
                    return((0x4000));
                    };
               if (result == (0x2003))
                    {
                    lprintf(3, "%s: Modem returned ERROR",
                     program_name);
                    voice_flush(1);
                    return((0x4000));
                    };
               }
          while ((result & (0x1000)) != (0x1000));
          };
     return(result);
     }

canonical_original_code:
int voice_command(char *command, char *expected_answer)
     {
     char buffer[-1];
     int result = (0x4000);
     lprintf(5, "voice command: '%s' -> '%s'", command,
      expected_answer);
     if (cvd.command_delay.d.i != 0)
          delay(cvd.command_delay.d.i);
     if (strlen(command) != 0)
          {
          if (voice_write("%s", command) != (0))
               {
               voice_flush(1);
               return((0x4000));
               };
          if (cvd.enable_command_echo.d.i)
               do
                    {
                    if (voice_read(buffer) != (0))
                         {
                         voice_flush(1);
                         return((0x4000));
                         };
                    result = voice_analyze(buffer, command, (0==0));
                    if (result == (0x4000))
                         {
                         lprintf(3,
                          "%s: Modem did not echo the command", program_name);
                         voice_flush(1);
                         return((0x4000));
                         };
                    if (result == (0x2003))
                         {
                         lprintf(3, "%s: Modem returned ERROR",
                          program_name);
                         voice_flush(1);
                         return((0x4000));
                         };
                    }
               while (result != (0x1000));
          result = (0);
          };
     if (strlen(expected_answer) != 0)
          {
          do
               {
               if (voice_read(buffer) != (0))
                    {
                    voice_flush(1);
                    return((0x4000));
                    };
               result = voice_analyze(buffer, expected_answer, (0==1));
               if (result == (0x4000))
                    {
                    lprintf(3, "%s: Invalid modem answer",
                     program_name);
                    voice_flush(1);
                    return((0x4000));
                    };
               if (result == (0x2003))
                    {
                    lprintf(3, "%s: Modem returned ERROR",
                     program_name);
                    voice_flush(1);
                    return((0x4000));
                    };
               }
          while ((result & (0x1000)) != (0x1000));
          };
     return(result);
     }

variable_types:
command
char *

variable_types:
buffer
char [-1]


repo: Distrotech/selinux

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

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

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

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

original_code:
queue_t queue_create(void)
{
 queue_t q;
 q = (queue_t) malloc(sizeof(struct queue_info));
 if (q == ((void *)0))
  return ((void *)0);
 q->head = q->tail = ((void *)0);
 return q;
}

canonical_original_code:
struct queue_info *queue_create()
{
 struct queue_info *q;
 q = (struct queue_info *) malloc(sizeof(struct queue_info));
 if (q == ((void *)0))
  return ((void *)0);
 q->head = q->tail = ((void *)0);
 return q;
}

variable_types: struct queue_info { struct queue_node { void *element; struct queue_node *next; } *head; struct queue_node *tail; } *

user_defined_types: struct queue_info { struct queue_node *head; struct queue_node *tail; }


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

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = a2;
v2[1] = 0LL;
if ( *a1 )
{
*(_QWORD *)(a1[1] + 8LL) = v2;
a1[1] = v2;
}
else
{
a1[1] = v2;
*a1 = v2;
}
return 0LL;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = a2;
v2[1] = 0LL;
if ( *a1 )
{
*(_QWORD *)(a1[1] + 8LL) = v2;
a1[1] = v2;
}
else
{
a1[1] = v2;
*a1 = v2;
}
return 0LL;
}

original_code:
int queue_insert(queue_t q, queue_element_t e)
{
 queue_node_ptr_t newnode;
 if (!q)
  return -1;
 newnode = (queue_node_ptr_t) malloc(sizeof(struct queue_node));
 if (newnode == ((void *)0))
  return -1;
 newnode->element = e;
 newnode->next = ((void *)0);
 if (q->head == ((void *)0)) {
  q->head = q->tail = newnode;
 } else {
  q->tail->next = newnode;
  q->tail = newnode;
 }
 return 0;
}

canonical_original_code:
int queue_insert(struct queue_info *q, void *e)
{
 struct queue_node *newnode;
 if (!q)
  return -1;
 newnode = (struct queue_node *) malloc(sizeof(struct queue_node));
 if (newnode == ((void *)0))
  return -1;
 newnode->element = e;
 newnode->next = ((void *)0);
 if (q->head == ((void *)0)) {
  q->head = q->tail = newnode;
 } else {
  q->tail->next = newnode;
  q->tail = newnode;
 }
 return 0;
}

variable_types:
e
void *

variable_types: struct queue_node { void *element; struct queue_node *next; } *


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

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = a2;
v2[1] = 0LL;
if ( *a1 )
v2[1] = *a1;
else
a1[1] = v2;
*a1 = v2;
return 0LL;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = a2;
v2[1] = 0LL;
if ( *a1 )
v2[1] = *a1;
else
a1[1] = v2;
*a1 = v2;
return 0LL;
}

original_code:
int queue_push(queue_t q, queue_element_t e)
{
 queue_node_ptr_t newnode;
 if (!q)
  return -1;
 newnode = (queue_node_ptr_t) malloc(sizeof(struct queue_node));
 if (newnode == ((void *)0))
  return -1;
 newnode->element = e;
 newnode->next = ((void *)0);
 if (q->head == ((void *)0)) {
  q->head = q->tail = newnode;
 } else {
  newnode->next = q->head;
  q->head = newnode;
 }
 return 0;
}

canonical_original_code:
int queue_push(struct queue_info *q, void *e)
{
 struct queue_node *newnode;
 if (!q)
  return -1;
 newnode = (struct queue_node *) malloc(sizeof(struct queue_node));
 if (newnode == ((void *)0))
  return -1;
 newnode->element = e;
 newnode->next = ((void *)0);
 if (q->head == ((void *)0)) {
  q->head = q->tail = newnode;
 } else {
  newnode->next = q->head;
  q->head = newnode;
 }
 return 0;
}

user_defined_types: struct queue_node { void *element; struct queue_node *next; }


original_code:
queue_element_t queue_remove(queue_t q)
{
 queue_node_ptr_t node;
 queue_element_t e;
 if (!q)
  return ((void *)0);
 if (q->head == ((void *)0))
  return ((void *)0);
 node = q->head;
 q->head = q->head->next;
 if (q->head == ((void *)0))
  q->tail = ((void *)0);
 e = node->element;
 free(node);
 return e;
}

canonical_original_code:
void *queue_remove(struct queue_info *q)
{
 struct queue_node *node;
 void *e;
 if (!q)
  return ((void *)0);
 if (q->head == ((void *)0))
  return ((void *)0);
 node = q->head;
 q->head = q->head->next;
 if (q->head == ((void *)0))
  q->tail = ((void *)0);
 e = node->element;
 free(node);
 return e;
}

return_type: void *


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

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

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

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

original_code:
void queue_destroy(queue_t q)
{
 queue_node_ptr_t p, temp;
 if (!q)
  return;
 p = q->head;
 while (p != ((void *)0)) {
  temp = p;
  p = p->next;
  free(temp);
 }
 free(q);
}

canonical_original_code:
void queue_destroy(struct queue_info *q)
{
 struct queue_node *p; struct queue_node *temp;
 if (!q)
  return;
 p = q->head;
 while (p != ((void *)0)) {
  temp = p;
  p = p->next;
  free(temp);
 }
 free(q);
}


decompiled_code:
__int64 __fastcall queue_map(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3)
{
_QWORD *v4; // rbx
__int64 result; // rax

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

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

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

original_code:
int queue_map(queue_t q, int (*f) (queue_element_t, void *), void *vp)
{
 queue_node_ptr_t p;
 int ret;
 if (!q)
  return 0;
 p = q->head;
 while (p != ((void *)0)) {
  ret = f(p->element, vp);
  if (ret)
   return ret;
  p = p->next;
 }
 return 0;
}

canonical_original_code:
int queue_map(struct queue_info *q, int (*f)(void *, void *), void *vp)
{
 struct queue_node *p;
 int ret;
 if (!q)
  return 0;
 p = q->head;
 while (p != ((void *)0)) {
  ret = f(p->element, vp);
  if (ret)
   return ret;
  p = p->next;
 }
 return 0;
}

variable_types:
f
int (*)(void *, void *)

variable_types:
vp
void *

variable_types: ret int


original_code:
void queue_map_remove_on_error(queue_t q,
          int (*f) (queue_element_t, void *),
          void (*g) (queue_element_t, void *), void *vp)
{
 queue_node_ptr_t p, last, temp;
 int ret;
 if (!q)
  return;
 last = ((void *)0);
 p = q->head;
 while (p != ((void *)0)) {
  ret = f(p->element, vp);
  if (ret) {
   if (last) {
    last->next = p->next;
    if (last->next == ((void *)0))
     q->tail = last;
   } else {
    q->head = p->next;
    if (q->head == ((void *)0))
     q->tail = ((void *)0);
   }
   temp = p;
   p = p->next;
   g(temp->element, vp);
   free(temp);
  } else {
   last = p;
   p = p->next;
  }
 }
 return;
}

canonical_original_code:
void queue_map_remove_on_error(struct queue_info *q, int (*f)(void *, void *), void (*g)(void *, void *), void *vp)
{
 struct queue_node *p; struct queue_node *last; struct queue_node *temp;
 int ret;
 if (!q)
  return;
 last = ((void *)0);
 p = q->head;
 while (p != ((void *)0)) {
  ret = f(p->element, vp);
  if (ret) {
   if (last) {
    last->next = p->next;
    if (last->next == ((void *)0))
     q->tail = last;
   } else {
    q->head = p->next;
    if (q->head == ((void *)0))
     q->tail = ((void *)0);
   }
   temp = p;
   p = p->next;
   g(temp->element, vp);
   free(temp);
  } else {
   last = p;
   p = p->next;
  }
 }
 return;
}

variable_types:
g
void (*)(void *, void *)


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

if ( argc != 3 )
usage(*argv);
v3 = fopen(argv[1], "r");
if ( v3 )
{
if ( (int)sepol_set_policydb_from_file() >= 0 )
{
fclose(v3);
if ( (int)sepol_check_context() >= 0 )
{
printf("%s is valid\n", argv[2]);
exit(0);
}
fprintf(stderr, "%s is not valid\n", argv[2]);
exit(1);
}
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Error while processing %s: %s\n", argv[1], v7);
exit(1);
}
v4 = __errno_location();
v5 = strerror(*v4);
fprintf(stderr, "Can't open '%s': %s\n", argv[1], v5);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

if ( argc != 3 )
func7(*argv);
v3 = fopen(argv[1], "r");
if ( v3 )
{
if ( (int)sepol_set_policydb_from_file() >= 0 )
{
fclose(v3);
if ( (int)sepol_check_context() >= 0 )
{
printf("%s is valid\n", argv[2]);
exit(0);
}
fprintf(stderr, "%s is not valid\n", argv[2]);
exit(1);
}
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Error while processing %s: %s\n", argv[1], v7);
exit(1);
}
v4 = __errno_location();
v5 = strerror(*v4);
fprintf(stderr, "Can't open '%s': %s\n", argv[1], v5);
exit(1);
}

original_code:
int main(int argc, char **argv)
{
 char *file = txtfile, *outfile = ((void *)0);
 unsigned int binary = 0;
 int ch;
 int show_version = 0;
 policydb_t modpolicydb;
 struct option long_options[] = {
  {"help", 0, ((void *)0), 'h'},
  {"output", 1, ((void *)0), 'o'},
  {"binary", 0, ((void *)0), 'b'},
  {"version", 0, ((void *)0), 'V'},
  {"handle-unknown", 1, ((void *)0), 'U'},
  {"mls", 0, ((void *)0), 'M'},
  {((void *)0), 0, ((void *)0), 0}
 };
 while ((ch = getopt_long(argc, argv, "ho:bVU:mM", long_options, ((void *)0))) != -1) {
  switch (ch) {
  case 'h':
   usage(argv[0]);
   break;
  case 'o':
   outfile = optarg;
   break;
  case 'b':
   binary = 1;
   file = binfile;
   break;
  case 'V':
   show_version = 1;
   break;
  case 'U':
   if (!strcasecmp(optarg, "deny")) {
    handle_unknown = 0;
    break;
   }
   if (!strcasecmp(optarg, "reject")) {
    handle_unknown = 2;
    break;
   }
   if (!strcasecmp(optarg, "allow")) {
    handle_unknown = 4;
    break;
   }
   usage(argv[0]);
  case 'm':
   policy_type = 2;
   policyvers = 19;
   break;
  case 'M':
   mlspol = 1;
   break;
  default:
   usage(argv[0]);
  }
 }
 if (show_version) {
  printf("Module versions %d-%d\n",
         4, 19);
  exit(0);
 }
 if (handle_unknown && (policy_type != 1)) {
  fprintf(stderr, "%s:  Handling of unknown classes and permissions is only valid in the base module.\n", argv[0]);
  exit(1);
 }
 if (binary && (policy_type != 1)) {
  fprintf(stderr, "%s:  -b and -m are incompatible with each other.\n", argv[0]);
  exit(1);
 }
 if (optind != argc) {
  file = argv[optind++];
  if (optind != argc)
   usage(argv[0]);
 }
 printf("%s:  loading policy configuration from %s\n", argv[0], file);
 sepol_set_policydb(&modpolicydb);
 sepol_set_sidtab(&sidtab);
 if (binary) {
  if (read_binary_policy(&modpolicydb, file, argv[0]) == -1) {
   exit(1);
  }
 } else {
  if (policydb_init(&modpolicydb)) {
   fprintf(stderr, "%s: out of memory!\n", argv[0]);
   return -1;
  }
  modpolicydb.policy_type = policy_type;
  modpolicydb.mls = mlspol;
  modpolicydb.handle_unknown = handle_unknown;
  if (read_source_policy(&modpolicydb, file, argv[0]) == -1) {
   exit(1);
  }
  if (hierarchy_check_constraints(((void *)0), &modpolicydb)) {
   return -1;
  }
 }
 if (modpolicydb.policy_type == 1) {
  policydb_t kernpolicydb;
  if (policydb_init(&kernpolicydb)) {
   fprintf(stderr, "%s:  policydb_init failed\n", argv[0]);
   exit(1);
  }
  if (link_modules(((void *)0), &modpolicydb, ((void *)0), 0, 0)) {
   fprintf(stderr, "%s:  link modules failed\n", argv[0]);
   exit(1);
  }
  if (expand_module(((void *)0), &modpolicydb, &kernpolicydb, 0, 1)) {
   fprintf(stderr, "%s:  expand module failed\n", argv[0]);
   exit(1);
  }
  policydb_destroy(&kernpolicydb);
 }
 if (policydb_load_isids(&modpolicydb, &sidtab))
  exit(1);
 sepol_sidtab_destroy(&sidtab);
 printf("%s:  policy configuration loaded\n", argv[0]);
 if (outfile &&
     write_binary_policy(&modpolicydb, outfile, argv[0]) == -1) {
  exit(1);
 }
 policydb_destroy(&modpolicydb);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *file = txtfile; char *outfile = ((void *)0);
 unsigned int binary = 0;
 int ch;
 int show_version = 0;
 struct policydb modpolicydb;
 struct option long_options[] = {
  {"help", 0, ((void *)0), 'h'},
  {"output", 1, ((void *)0), 'o'},
  {"binary", 0, ((void *)0), 'b'},
  {"version", 0, ((void *)0), 'V'},
  {"handle-unknown", 1, ((void *)0), 'U'},
  {"mls", 0, ((void *)0), 'M'},
  {((void *)0), 0, ((void *)0), 0}
 };
 while ((ch = getopt_long(argc, argv, "ho:bVU:mM", long_options, ((void *)0))) != -1) {
  switch (ch) {
  case 'h':
   usage(argv[0]);
   break;
  case 'o':
   outfile = optarg;
   break;
  case 'b':
   binary = 1;
   file = binfile;
   break;
  case 'V':
   show_version = 1;
   break;
  case 'U':
   if (!strcasecmp(optarg, "deny")) {
    handle_unknown = 0;
    break;
   }
   if (!strcasecmp(optarg, "reject")) {
    handle_unknown = 2;
    break;
   }
   if (!strcasecmp(optarg, "allow")) {
    handle_unknown = 4;
    break;
   }
   usage(argv[0]);
  case 'm':
   policy_type = 2;
   policyvers = 19;
   break;
  case 'M':
   mlspol = 1;
   break;
  default:
   usage(argv[0]);
  }
 }
 if (show_version) {
  printf("Module versions %d-%d\n",
         4, 19);
  exit(0);
 }
 if (handle_unknown && (policy_type != 1)) {
  fprintf(stderr, "%s:  Handling of unknown classes and permissions is only valid in the base module.\n", argv[0]);
  exit(1);
 }
 if (binary && (policy_type != 1)) {
  fprintf(stderr, "%s:  -b and -m are incompatible with each other.\n", argv[0]);
  exit(1);
 }
 if (optind != argc) {
  file = argv[optind++];
  if (optind != argc)
   usage(argv[0]);
 }
 printf("%s:  loading policy configuration from %s\n", argv[0], file);
 sepol_set_policydb(&modpolicydb);
 sepol_set_sidtab(&sidtab);
 if (binary) {
  if (read_binary_policy(&modpolicydb, file, argv[0]) == -1) {
   exit(1);
  }
 } else {
  if (policydb_init(&modpolicydb)) {
   fprintf(stderr, "%s: out of memory!\n", argv[0]);
   return -1;
  }
  modpolicydb.policy_type = policy_type;
  modpolicydb.mls = mlspol;
  modpolicydb.handle_unknown = handle_unknown;
  if (read_source_policy(&modpolicydb, file, argv[0]) == -1) {
   exit(1);
  }
  if (hierarchy_check_constraints(((void *)0), &modpolicydb)) {
   return -1;
  }
 }
 if (modpolicydb.policy_type == 1) {
  struct policydb kernpolicydb;
  if (policydb_init(&kernpolicydb)) {
   fprintf(stderr, "%s:  policydb_init failed\n", argv[0]);
   exit(1);
  }
  if (link_modules(((void *)0), &modpolicydb, ((void *)0), 0, 0)) {
   fprintf(stderr, "%s:  link modules failed\n", argv[0]);
   exit(1);
  }
  if (expand_module(((void *)0), &modpolicydb, &kernpolicydb, 0, 1)) {
   fprintf(stderr, "%s:  expand module failed\n", argv[0]);
   exit(1);
  }
  policydb_destroy(&kernpolicydb);
 }
 if (policydb_load_isids(&modpolicydb, &sidtab))
  exit(1);
 sepol_sidtab_destroy(&sidtab);
 printf("%s:  policy configuration loaded\n", argv[0]);
 if (outfile &&
     write_binary_policy(&modpolicydb, outfile, argv[0]) == -1) {
  exit(1);
 }
 policydb_destroy(&modpolicydb);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
file
char *

variable_types:
outfile
char *

variable_types:
binary
unsigned int

variable_types: ch int

variable_types: struct policydb { unsigned int policy_type; char *name; char *version; int target_platform; int unsupported_format; int mls; struct symtab_t { struct hashtab_val { struct hashtab_node { char *key; void *datum; struct hashtab_node *next; } **htable; unsigned int size; unsigned int nel; unsigned int (*hash_value)(struct hashtab_val *h, char *key); int (*keycmp)(struct hashtab_val *h, char *key1, char *key2); } *table; unsigned int nprim; } symtab[8]; char **sym_val_to_name[8]; struct class_datum { struct symtab_datum { unsigned int value; } s; char *comkey; struct common_datum { struct symtab_datum s; struct symtab_t permissions; } *comdatum; struct symtab_t permissions; struct constraint_node { unsigned int permissions; struct constraint_expr { unsigned int expr_type; unsigned int attr; unsigned int op; struct ebitmap { struct ebitmap_node { unsigned int startbit; unsigned long map; struct ebitmap_node *next; } *node; unsigned int highbit; } names; struct type_set { struct ebitmap types; struct ebitmap negset; unsigned int flags; } *type_names; struct constraint_expr *next; } *expr; struct constraint_node *next; } *constraints; struct constraint_node *validatetrans; char default_user; char default_role; char default_type; char default_range; } **class_val_to_struct; struct role_datum { struct symtab_datum s; struct ebitmap dominates; struct type_set types; struct ebitmap cache; unsigned int bounds; unsigned int flavor; struct ebitmap roles; } **role_val_to_struct; struct user_datum { struct symtab_datum s; struct role_set { struct ebitmap roles; unsigned int flags; } roles; struct mls_semantic_range { struct mls_semantic_level { unsigned int sens; struct mls_semantic_cat { unsigned int low; unsigned int high; struct mls_semantic_cat *next; } *cat; } level[2]; } range; struct mls_semantic_level dfltlevel; struct ebitmap cache; struct mls_range { struct mls_level { unsigned int sens; struct ebitmap cat; } level[2]; } exp_range; struct mls_level exp_dfltlevel; unsigned int bounds; } **user_val_to_struct; struct type_datum { struct symtab_datum s; unsigned int primary; unsigned int flavor; struct ebitmap types; unsigned int flags; unsigned int bounds; } **type_val_to_struct; struct symtab_t scope[8]; struct avrule_block { struct avrule_decl { unsigned int decl_id; unsigned int enabled; struct cond_node { int cur_state; struct cond_expr { unsigned int expr_type; unsigned int bool; struct cond_expr *next; } *expr; struct cond_av_list { struct avtab_node { struct avtab_key { unsigned short source_type; unsigned short target_type; unsigned short target_class; unsigned short specified; } key; struct avtab_datum { unsigned int data; struct avtab_extended_perms { unsigned char specified; unsigned char driver; unsigned int perms[8]; } *xperms; } datum; struct avtab_node *next; void *parse_context; unsigned int merged; } *node; struct cond_av_list *next; } *true_list; struct cond_av_list *false_list; struct avrule { unsigned int specified; unsigned int flags; struct type_set stypes; struct type_set ttypes; struct class_perm_node { unsigned int tclass; unsigned int data; struct class_perm_node *next; } *perms; struct av_extended_perms { unsigned char specified; unsigned char driver; unsigned int perms[8]; } *xperms; unsigned long line; char *source_filename; unsigned long source_line; struct avrule *next; } *avtrue_list; struct avrule *avfalse_list; unsigned int nbools; unsigned int bool_ids[5]; unsigned int expr_pre_comp; struct cond_node *next; unsigned int flags; } *cond_list; struct avrule *avrules; struct role_trans_rule { struct role_set roles; struct type_set types; struct ebitmap classes; unsigned int new_role; struct role_trans_rule *next; } *role_tr_rules; struct role_allow_rule { struct role_set roles; struct role_set new_roles; struct role_allow_rule *next; } *role_allow_rules; struct range_trans_rule { struct type_set stypes; struct type_set ttypes; struct ebitmap tclasses; struct mls_semantic_range trange; struct range_trans_rule *next; } *range_tr_rules; struct scope_index { struct ebitmap scope[8]; struct ebitmap *class_perms_map; unsigned int class_perms_len; } required; struct scope_index declared; struct filename_trans_rule { struct type_set stypes; struct type_set ttypes; unsigned int tclass; char *name; unsigned int otype; struct filename_trans_rule *next; } *filename_trans_rules; struct symtab_t symtab[8]; char *module_name; struct avrule_decl *next; } *branch_list; struct avrule_decl *enabled; unsigned int flags; struct avrule_block *next; } *global; struct avrule_decl **decl_val_to_struct; struct avtab { struct avtab_node **htable; unsigned int nel; unsigned int nslot; unsigned int mask; } te_avtab; struct cond_bool_datum { struct symtab_datum s; int state; unsigned int flags; } **bool_val_to_struct; struct avtab te_cond_avtab; struct cond_node *cond_list; struct role_trans { unsigned int role; unsigned int type; unsigned int tclass; unsigned int new_role; struct role_trans *next; } *role_tr; struct role_allow { unsigned int role; unsigned int new_role; struct role_allow *next; } *role_allow; struct ocontext { union { char *name; struct { unsigned char protocol; unsigned short low_port; unsigned short high_port; } port; struct { unsigned int addr; unsigned int mask; } node; struct { unsigned int addr[4]; unsigned int mask[4]; } node6; unsigned int device; unsigned short pirq; struct { unsigned long low_iomem; unsigned long high_iomem; } iomem; struct { unsigned int low_ioport; unsigned int high_ioport; } ioport; struct { unsigned long subnet_prefix; unsigned short low_pkey; unsigned short high_pkey; } ibpkey; struct { char *dev_name; unsigned char port; } ibendport; } u; union { unsigned int sclass; unsigned int behavior; } v; struct context_struct { unsigned int user; unsigned int role; unsigned int type; struct mls_range range; } context[2]; unsigned int sid[2]; struct ocontext *next; } *ocontexts[9]; struct genfs { char *fstype; struct ocontext *head; struct genfs *next; } *genfs; struct hashtab_val *range_tr; struct hashtab_val *filename_trans; struct ebitmap *type_attr_map; struct ebitmap *attr_type_map; struct ebitmap policycaps; struct ebitmap permissive_map; unsigned int policyvers; unsigned int handle_unknown; }

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

user_defined_types: struct policydb { unsigned int policy_type; char *name; char *version; int target_platform; int unsupported_format; int mls; struct symtab_t symtab[8]; char **sym_val_to_name[8]; struct class_datum **class_val_to_struct; struct role_datum **role_val_to_struct; struct user_datum **user_val_to_struct; struct type_datum **type_val_to_struct; struct symtab_t scope[8]; struct avrule_block *global; struct avrule_decl **decl_val_to_struct; struct avtab te_avtab; struct cond_bool_datum **bool_val_to_struct; struct avtab te_cond_avtab; struct cond_node *cond_list; struct role_trans *role_tr; struct role_allow *role_allow; struct ocontext *ocontexts[9]; struct genfs *genfs; struct hashtab_val *range_tr; struct hashtab_val *filename_trans; struct ebitmap *type_attr_map; struct ebitmap *attr_type_map; struct ebitmap policycaps; struct ebitmap permissive_map; unsigned int policyvers; unsigned int handle_unknown; }

user_defined_types: struct symtab_t { struct hashtab_val *table; unsigned int nprim; }

user_defined_types: struct avrule_block { struct avrule_decl *branch_list; struct avrule_decl *enabled; unsigned int flags; struct avrule_block *next; }

user_defined_types: struct class_datum { struct symtab_datum s; char *comkey; struct common_datum *comdatum; struct symtab_t permissions; struct constraint_node *constraints; struct constraint_node *validatetrans; char default_user; char default_role; char default_type; char default_range; }

user_defined_types: struct user_datum { struct symtab_datum s; struct role_set roles; struct mls_semantic_range range; struct mls_semantic_level dfltlevel; struct ebitmap cache; struct mls_range exp_range; struct mls_level exp_dfltlevel; unsigned int bounds; }

user_defined_types: struct ocontext { union { char *name; struct { unsigned char protocol; unsigned short low_port; unsigned short high_port; } port; struct { unsigned int addr; unsigned int mask; } node; struct { unsigned int addr[4]; unsigned int mask[4]; } node6; unsigned int device; unsigned short pirq; struct { unsigned long low_iomem; unsigned long high_iomem; } iomem; struct { unsigned int low_ioport; unsigned int high_ioport; } ioport; struct { unsigned long subnet_prefix; unsigned short low_pkey; unsigned short high_pkey; } ibpkey; struct { char *dev_name; unsigned char port; } ibendport; } u; union { unsigned int sclass; unsigned int behavior; } v; struct context_struct context[2]; unsigned int sid[2]; struct ocontext *next; }

user_defined_types: struct hashtab_val { struct hashtab_node **htable; unsigned int size; unsigned int nel; unsigned int (*hash_value)(struct hashtab_val *h, char *key); int (*keycmp)(struct hashtab_val *h, char *key1, char *key2); }

user_defined_types: struct mls_semantic_range { struct mls_semantic_level level[2]; }

user_defined_types: struct mls_range { struct mls_level level[2]; }

user_defined_types: struct avrule_decl { unsigned int decl_id; unsigned int enabled; struct cond_node *cond_list; struct avrule *avrules; struct role_trans_rule *role_tr_rules; struct role_allow_rule *role_allow_rules; struct range_trans_rule *range_tr_rules; struct scope_index required; struct scope_index declared; struct filename_trans_rule *filename_trans_rules; struct symtab_t symtab[8]; char *module_name; struct avrule_decl *next; }

user_defined_types: struct constraint_node { unsigned int permissions; struct constraint_expr *expr; struct constraint_node *next; }

user_defined_types: struct mls_semantic_level { unsigned int sens; struct mls_semantic_cat *cat; }

user_defined_types: struct cond_node { int cur_state; struct cond_expr *expr; struct cond_av_list *true_list; struct cond_av_list *false_list; struct avrule *avtrue_list; struct avrule *avfalse_list; unsigned int nbools; unsigned int bool_ids[5]; unsigned int expr_pre_comp; struct cond_node *next; unsigned int flags; }

user_defined_types: struct constraint_expr { unsigned int expr_type; unsigned int attr; unsigned int op; struct ebitmap names; struct type_set *type_names; struct constraint_expr *next; }

user_defined_types: struct ebitmap { struct ebitmap_node *node; unsigned int highbit; }

user_defined_types: struct cond_av_list { struct avtab_node *node; struct cond_av_list *next; }

user_defined_types: struct avrule { unsigned int specified; unsigned int flags; struct type_set stypes; struct type_set ttypes; struct class_perm_node *perms; struct av_extended_perms *xperms; unsigned long line; char *source_filename; unsigned long source_line; struct avrule *next; }

user_defined_types: struct avtab_node { struct avtab_key key; struct avtab_datum datum; struct avtab_node *next; void *parse_context; unsigned int merged; }

user_defined_types: struct avtab_datum { unsigned int data; struct avtab_extended_perms *xperms; }


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("usage: %s policy context\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
printf("usage: %s policy context\n", a1);
exit(1);
}

original_code:
static void usage(char *progname)
{
 printf("usage:  %s [-h] [-V] [-b] [-U handle_unknown] [-m] [-M] [-o FILE] [INPUT]\n", progname);
 printf("Build base and policy modules.\n");
 printf("Options:\n");
 printf("  INPUT      build module from INPUT (else read from \"%s\")\n",
        txtfile);
 printf("  -V         show policy versions created by this program\n");
 printf("  -b         treat input as a binary policy file\n");
 printf("  -h         print usage\n");
 printf("  -U OPTION  How to handle unknown classes and permissions\n");
 printf("               deny: Deny unknown kernel checks\n");
 printf("               reject: Reject loading of policy with unknowns\n");
 printf("               allow: Allow unknown kernel checks\n");
 printf("  -m         build a policy module instead of a base module\n");
 printf("  -M         enable MLS policy\n");
 printf("  -o FILE    write module to FILE (else just check syntax)\n");
 exit(1);
}

variable_types:
progname
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
char *v4; // r13
const char *v5; // r14
int v6; // ebx
char *v7; // rbx
int v8; // eax
int v10; // eax
int v11; // [rsp+Ch] [rbp-61Ch]
char v12[640]; // [rsp+10h] [rbp-618h] BYREF
struct option longopts; // [rsp+290h] [rbp-398h] BYREF
const char *v14; // [rsp+2B0h] [rbp-378h]
int v15; // [rsp+2B8h] [rbp-370h]
__int64 v16; // [rsp+2C0h] [rbp-368h]
int v17; // [rsp+2C8h] [rbp-360h]
const char *v18; // [rsp+2D0h] [rbp-358h]
int v19; // [rsp+2D8h] [rbp-350h]
__int64 v20; // [rsp+2E0h] [rbp-348h]
int v21; // [rsp+2E8h] [rbp-340h]
const char *v22; // [rsp+2F0h] [rbp-338h]
int v23; // [rsp+2F8h] [rbp-330h]
__int64 v24; // [rsp+300h] [rbp-328h]
int v25; // [rsp+308h] [rbp-320h]
const char *v26; // [rsp+310h] [rbp-318h]
int v27; // [rsp+318h] [rbp-310h]
__int64 v28; // [rsp+320h] [rbp-308h]
int v29; // [rsp+328h] [rbp-300h]
const char *v30; // [rsp+330h] [rbp-2F8h]
int v31; // [rsp+338h] [rbp-2F0h]
__int64 v32; // [rsp+340h] [rbp-2E8h]
int v33; // [rsp+348h] [rbp-2E0h]
__int64 v34; // [rsp+350h] [rbp-2D8h]
int v35; // [rsp+358h] [rbp-2D0h]
__int64 v36; // [rsp+360h] [rbp-2C8h]
int v37; // [rsp+368h] [rbp-2C0h]
int v38[174]; // [rsp+370h] [rbp-2B8h] BYREF

longopts.name = "help";
longopts.has_arg = 0;
longopts.flag = 0LL;
longopts.val = 104;
v14 = "output";
v15 = 1;
v16 = 0LL;
v17 = 111;
v18 = "binary";
v19 = 0;
v20 = 0LL;
v21 = 98;
v22 = "version";
v23 = 0;
v24 = 0LL;
v25 = 86;
v26 = "handle-unknown";
v27 = 1;
v28 = 0LL;
v29 = 85;
v30 = "mls";
v31 = 0;
v32 = 0LL;
v33 = 77;
v34 = 0LL;
v35 = 0;
v36 = 0LL;
v37 = 0;
v3 = 0;
v11 = 0;
v4 = 0LL;
v5 = "policy.conf";
while ( 1 )
{
v6 = getopt_long(argc, (char *const *)argv, "ho:bVU:mM", &longopts, 0LL);
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'M':
mlspol = 1;
break;
case 'U':
v7 = optarg;
if ( !strcasecmp(optarg, "deny") )
{
handle_unknown = 0;
}
else if ( !strcasecmp(v7, "reject") )
{
handle_unknown = 2;
}
else
{
if ( strcasecmp(v7, "allow") )
usage(*argv);
handle_unknown = 4;
}
break;
case 'V':
v3 = 1;
break;
case 'b':
v11 = 1;
v5 = "policy";
break;
case 'h':
usage(*argv);
case 'm':
policy_type = 2;
policyvers = 19;
break;
case 'o':
v4 = optarg;
break;
default:
usage(*argv);
}
}
if ( v3 )
{
printf("Module versions %d-%d\n", 4LL, 19LL);
exit(0);
}
if ( handle_unknown )
{
if ( policy_type != 1 )
{
fprintf(stderr, "%s: Handling of unknown classes and permissions is only valid in the base module.\n", *argv);
exit(1);
}
if ( v11 )
{
LABEL_22:
v8 = optind;
if ( argc == optind )
{
printf("%s: loading policy configuration from %s\n", *argv, v5);
sepol_set_policydb(v38);
sepol_set_sidtab(&sidtab);
LABEL_25:
if ( (unsigned int)read_binary_policy((__int64)v38, v5, *argv) == -1 )
exit(1);
LABEL_26:
if ( v38[0] == 1 )
{
if ( (unsigned int)policydb_init(v12) )
{
fprintf(stderr, "%s: policydb_init failed\n", *argv);
exit(1);
}
if ( (unsigned int)link_modules(0LL, v38, 0LL, 0LL, 0LL) )
{
fprintf(stderr, "%s: link modules failed\n", *argv);
exit(1);
}
if ( (unsigned int)expand_module(0LL, v38, v12, 0LL, 1LL) )
{
fprintf(stderr, "%s: expand module failed\n", *argv);
exit(1);
}
policydb_destroy(v12);
}
v6 = policydb_load_isids(v38, &sidtab);
if ( v6 )
exit(1);
sepol_sidtab_destroy(&sidtab);
printf("%s: policy configuration loaded\n", *argv);
if ( v4 && (unsigned int)write_binary_policy(v38, v4, *argv) == -1 )
exit(1);
policydb_destroy(v38);
return v6;
}
++optind;
v5 = argv[v8];
if ( argc == v8 + 1 )
{
printf("%s: loading policy configuration from %s\n", *argv, argv[v8]);
sepol_set_policydb(v38);
sepol_set_sidtab(&sidtab);
goto LABEL_25;
}
LABEL_37:
usage(*argv);
}
}
else if ( v11 )
{
if ( policy_type != 1 )
{
fprintf(stderr, "%s: -b and -m are incompatible with each other.\n", *argv);
exit(1);
}
goto LABEL_22;
}
v10 = optind;
if ( argc == optind )
{
printf("%s: loading policy configuration from %s\n", *argv, v5);
sepol_set_policydb(v38);
sepol_set_sidtab(&sidtab);
}
else
{
++optind;
v5 = argv[v10];
if ( argc != v10 + 1 )
goto LABEL_37;
printf("%s: loading policy configuration from %s\n", *argv, argv[v10]);
sepol_set_policydb(v38);
sepol_set_sidtab(&sidtab);
}
if ( (unsigned int)policydb_init(v38) )
{
fprintf(stderr, "%s: out of memory!\n", *argv);
return v6;
}
v38[0] = policy_type;
v38[8] = mlspol;
v38[159] = handle_unknown;
if ( (unsigned int)read_source_policy(v38, v5, *argv) == -1 )
exit(1);
if ( !(unsigned int)hierarchy_check_constraints(0LL, v38) )
goto LABEL_26;
return v6;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
char *v4; // r13
const char *v5; // r14
int v6; // ebx
char *v7; // rbx
int v8; // eax
int v10; // eax
int v11; // [rsp+Ch] [rbp-61Ch]
char v12[640]; // [rsp+10h] [rbp-618h] BYREF
struct option longopts; // [rsp+290h] [rbp-398h] BYREF
const char *v14; // [rsp+2B0h] [rbp-378h]
int v15; // [rsp+2B8h] [rbp-370h]
__int64 v16; // [rsp+2C0h] [rbp-368h]
int v17; // [rsp+2C8h] [rbp-360h]
const char *v18; // [rsp+2D0h] [rbp-358h]
int v19; // [rsp+2D8h] [rbp-350h]
__int64 v20; // [rsp+2E0h] [rbp-348h]
int v21; // [rsp+2E8h] [rbp-340h]
const char *v22; // [rsp+2F0h] [rbp-338h]
int v23; // [rsp+2F8h] [rbp-330h]
__int64 v24; // [rsp+300h] [rbp-328h]
int v25; // [rsp+308h] [rbp-320h]
const char *v26; // [rsp+310h] [rbp-318h]
int v27; // [rsp+318h] [rbp-310h]
__int64 v28; // [rsp+320h] [rbp-308h]
int v29; // [rsp+328h] [rbp-300h]
const char *v30; // [rsp+330h] [rbp-2F8h]
int v31; // [rsp+338h] [rbp-2F0h]
__int64 v32; // [rsp+340h] [rbp-2E8h]
int v33; // [rsp+348h] [rbp-2E0h]
__int64 v34; // [rsp+350h] [rbp-2D8h]
int v35; // [rsp+358h] [rbp-2D0h]
__int64 v36; // [rsp+360h] [rbp-2C8h]
int v37; // [rsp+368h] [rbp-2C0h]
int v38[174]; // [rsp+370h] [rbp-2B8h] BYREF

longopts.name = "help";
longopts.has_arg = 0;
longopts.flag = 0LL;
longopts.val = 104;
v14 = "output";
v15 = 1;
v16 = 0LL;
v17 = 111;
v18 = "binary";
v19 = 0;
v20 = 0LL;
v21 = 98;
v22 = "version";
v23 = 0;
v24 = 0LL;
v25 = 86;
v26 = "handle-unknown";
v27 = 1;
v28 = 0LL;
v29 = 85;
v30 = "mls";
v31 = 0;
v32 = 0LL;
v33 = 77;
v34 = 0LL;
v35 = 0;
v36 = 0LL;
v37 = 0;
v3 = 0;
v11 = 0;
v4 = 0LL;
v5 = "policy.conf";
while ( 1 )
{
v6 = getopt_long(argc, (char *const *)argv, "ho:bVU:mM", &longopts, 0LL);
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'M':
mlspol = 1;
break;
case 'U':
v7 = optarg;
if ( !strcasecmp(optarg, "deny") )
{
handle_unknown = 0;
}
else if ( !strcasecmp(v7, "reject") )
{
handle_unknown = 2;
}
else
{
if ( strcasecmp(v7, "allow") )
func0(*argv);
handle_unknown = 4;
}
break;
case 'V':
v3 = 1;
break;
case 'b':
v11 = 1;
v5 = "policy";
break;
case 'h':
func0(*argv);
case 'm':
policy_type = 2;
policyvers = 19;
break;
case 'o':
v4 = optarg;
break;
default:
func0(*argv);
}
}
if ( v3 )
{
printf("Module versions %d-%d\n", 4LL, 19LL);
exit(0);
}
if ( handle_unknown )
{
if ( policy_type != 1 )
{
fprintf(stderr, "%s: Handling of unknown classes and permissions is only valid in the base module.\n", *argv);
exit(1);
}
if ( v11 )
{
LABEL_22:
v8 = optind;
if ( argc == optind )
{
printf("%s: loading policy configuration from %s\n", *argv, v5);
sepol_set_policydb(v38);
sepol_set_sidtab(&sidtab);
LABEL_25:
if ( (unsigned int)func1((__int64)v38, v5, *argv) == -1 )
exit(1);
LABEL_26:
if ( v38[0] == 1 )
{
if ( (unsigned int)policydb_init(v12) )
{
fprintf(stderr, "%s: policydb_init failed\n", *argv);
exit(1);
}
if ( (unsigned int)link_modules(0LL, v38, 0LL, 0LL, 0LL) )
{
fprintf(stderr, "%s: link modules failed\n", *argv);
exit(1);
}
if ( (unsigned int)expand_module(0LL, v38, v12, 0LL, 1LL) )
{
fprintf(stderr, "%s: expand module failed\n", *argv);
exit(1);
}
policydb_destroy(v12);
}
v6 = policydb_load_isids(v38, &sidtab);
if ( v6 )
exit(1);
sepol_sidtab_destroy(&sidtab);
printf("%s: policy configuration loaded\n", *argv);
if ( v4 && (unsigned int)func2(v38, v4, *argv) == -1 )
exit(1);
policydb_destroy(v38);
return v6;
}
++optind;
v5 = argv[v8];
if ( argc == v8 + 1 )
{
printf("%s: loading policy configuration from %s\n", *argv, argv[v8]);
sepol_set_policydb(v38);
sepol_set_sidtab(&sidtab);
goto LABEL_25;
}
LABEL_37:
func0(*argv);
}
}
else if ( v11 )
{
if ( policy_type != 1 )
{
fprintf(stderr, "%s: -b and -m are incompatible with each other.\n", *argv);
exit(1);
}
goto LABEL_22;
}
v10 = optind;
if ( argc == optind )
{
printf("%s: loading policy configuration from %s\n", *argv, v5);
sepol_set_policydb(v38);
sepol_set_sidtab(&sidtab);
}
else
{
++optind;
v5 = argv[v10];
if ( argc != v10 + 1 )
goto LABEL_37;
printf("%s: loading policy configuration from %s\n", *argv, argv[v10]);
sepol_set_policydb(v38);
sepol_set_sidtab(&sidtab);
}
if ( (unsigned int)policydb_init(v38) )
{
fprintf(stderr, "%s: out of memory!\n", *argv);
return v6;
}
v38[0] = policy_type;
v38[8] = mlspol;
v38[159] = handle_unknown;
if ( (unsigned int)read_source_policy(v38, v5, *argv) == -1 )
exit(1);
if ( !(unsigned int)hierarchy_check_constraints(0LL, v38) )
goto LABEL_26;
return v6;
}

user_defined_types: struct policydb { unsigned int policy_type; char *name; char *version; int target_platform; int unsupported_format; int mls; struct symtab_t symtab[8]; char **sym_val_to_name[8]; struct class_datum **class_val_to_struct; struct role_datum **role_val_to_struct; struct user_datum **user_val_to_struct; struct type_datum **type_val_to_struct; struct symtab_t scope[8]; struct avrule_block *global; struct avrule_decl **decl_val_to_struct; struct avtab te_avtab; struct cond_bool_datum **bool_val_to_struct; struct avtab te_cond_avtab; struct cond_node *cond_list; struct role_trans *role_tr; struct role_allow *role_allow; struct ocontext *ocontexts[9]; struct genfs *genfs; struct hashtab_val *range_tr; struct hashtab_val *filename_trans; struct ebitmap *type_attr_map; struct ebitmap *attr_type_map; struct ebitmap policycaps; struct ebitmap permissive_map; unsigned int policyvers; unsigned int handle_unknown; }

user_defined_types: struct avtab { struct avtab_node **htable; unsigned int nel; unsigned int nslot; unsigned int mask; }

user_defined_types: struct option { char *name; int has_arg; int *flag; int val; }

user_defined_types: struct symtab_t { struct hashtab_val *table; unsigned int nprim; }

user_defined_types: struct avrule_block { struct avrule_decl *branch_list; struct avrule_decl *enabled; unsigned int flags; struct avrule_block *next; }

user_defined_types: struct role_trans { unsigned int role; unsigned int type; unsigned int tclass; unsigned int new_role; struct role_trans *next; }

user_defined_types: struct role_allow { unsigned int role; unsigned int new_role; struct role_allow *next; }

user_defined_types: struct genfs { char *fstype; struct ocontext *head; struct genfs *next; }

user_defined_types: struct role_datum { struct symtab_datum s; struct ebitmap dominates; struct type_set types; struct ebitmap cache; unsigned int bounds; unsigned int flavor; struct ebitmap roles; }

user_defined_types: struct type_datum { struct symtab_datum s; unsigned int primary; unsigned int flavor; struct ebitmap types; unsigned int flags; unsigned int bounds; }

user_defined_types: struct cond_bool_datum { struct symtab_datum s; int state; unsigned int flags; }

user_defined_types: struct symtab_datum { unsigned int value; }

user_defined_types: struct role_set { struct ebitmap roles; unsigned int flags; }

user_defined_types: struct common_datum { struct symtab_datum s; struct symtab_t permissions; }

user_defined_types: struct scope_index { struct ebitmap scope[8]; struct ebitmap *class_perms_map; unsigned int class_perms_len; }

user_defined_types: struct context_struct { unsigned int user; unsigned int role; unsigned int type; struct mls_range range; }

user_defined_types: struct mls_level { unsigned int sens; struct ebitmap cat; }

user_defined_types: struct role_trans_rule { struct role_set roles; struct type_set types; struct ebitmap classes; unsigned int new_role; struct role_trans_rule *next; }

user_defined_types: struct role_allow_rule { struct role_set roles; struct role_set new_roles; struct role_allow_rule *next; }

user_defined_types: struct range_trans_rule { struct type_set stypes; struct type_set ttypes; struct ebitmap tclasses; struct mls_semantic_range trange; struct range_trans_rule *next; }

user_defined_types: struct filename_trans_rule { struct type_set stypes; struct type_set ttypes; unsigned int tclass; char *name; unsigned int otype; struct filename_trans_rule *next; }

user_defined_types: struct hashtab_node { char *key; void *datum; struct hashtab_node *next; }

user_defined_types: struct mls_semantic_cat { unsigned int low; unsigned int high; struct mls_semantic_cat *next; }

user_defined_types: struct cond_expr { unsigned int expr_type; unsigned int bool; struct cond_expr *next; }

user_defined_types: struct type_set { struct ebitmap types; struct ebitmap negset; unsigned int flags; }

user_defined_types: struct ebitmap_node { unsigned int startbit; unsigned long map; struct ebitmap_node *next; }

user_defined_types: struct class_perm_node { unsigned int tclass; unsigned int data; struct class_perm_node *next; }

user_defined_types: struct av_extended_perms { unsigned char specified; unsigned char driver; unsigned int perms[8]; }

user_defined_types: struct avtab_key { unsigned short source_type; unsigned short target_type; unsigned short target_class; unsigned short specified; }

user_defined_types: struct avtab_extended_perms { unsigned char specified; unsigned char driver; unsigned int perms[8]; }


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("usage: %s [-h] [-V] [-b] [-U handle_unknown] [-m] [-M] [-o FILE] [INPUT]\n", a1);
puts("Build base and policy modules.");
puts("Options:");
printf(" INPUT build module from INPUT (else read from \"%s\")\n", "policy.conf");
puts(" -V show policy versions created by this program");
puts(" -b treat input as a binary policy file");
puts(" -h print usage");
puts(" -U OPTION How to handle unknown classes and permissions");
puts(" deny: Deny unknown kernel checks");
puts(" reject: Reject loading of policy with unknowns");
puts(" allow: Allow unknown kernel checks");
puts(" -m build a policy module instead of a base module");
puts(" -M enable MLS policy");
puts(" -o FILE write module to FILE (else just check syntax)");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
printf("usage: %s [-h] [-V] [-b] [-U handle_unknown] [-m] [-M] [-o FILE] [INPUT]\n", a1);
puts("Build base and policy modules.");
puts("Options:");
printf(" INPUT build module from INPUT (else read from \"%s\")\n", "policy.conf");
puts(" -V show policy versions created by this program");
puts(" -b treat input as a binary policy file");
puts(" -h print usage");
puts(" -U OPTION How to handle unknown classes and permissions");
puts(" deny: Deny unknown kernel checks");
puts(" reject: Reject loading of policy with unknowns");
puts(" allow: Allow unknown kernel checks");
puts(" -m build a policy module instead of a base module");
puts(" -M enable MLS policy");
puts(" -o FILE write module to FILE (else just check syntax)");
exit(1);
}

canonical_original_code:
static void usage(char *progname)
{
 printf("usage:  %s [-h] [-V] [-b] [-U handle_unknown] [-m] [-M] [-o FILE] [INPUT]\n", progname);
 printf("Build base and policy modules.\n");
 printf("Options:\n");
 printf("  INPUT      build module from INPUT (else read from \"%s\")\n",
        txtfile);
 printf("  -V         show policy versions created by this program\n");
 printf("  -b         treat input as a binary policy file\n");
 printf("  -h         print usage\n");
 printf("  -U OPTION  How to handle unknown classes and permissions\n");
 printf("               deny: Deny unknown kernel checks\n");
 printf("               reject: Reject loading of policy with unknowns\n");
 printf("               allow: Allow unknown kernel checks\n");
 printf("  -m         build a policy module instead of a base module\n");
 printf("  -M         enable MLS policy\n");
 printf("  -o FILE    write module to FILE (else just check syntax)\n");
 exit(1);
}


repo: Distrotech/sysklogd

decompiled_code:
__int64 __fastcall check_pid(const char *a1)
{
unsigned int v1; // ebx

v1 = read_pid(a1);
if ( v1 )
{
if ( getpid() == v1 )
{
v1 = 0;
}
else if ( kill(v1, 0) && *_errno_location() == 3 )
{
v1 = 0;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
unsigned int v1; // ebx

v1 = func0(a1);
if ( v1 )
{
if ( getpid() == v1 )
{
v1 = 0;
}
else if ( kill(v1, 0) && *_errno_location() == 3 )
{
v1 = 0;
}
}
return v1;
}

original_code:
int check_pid (char *pidfile)
{
  int pid = read_pid(pidfile);
  if ((!pid) || (pid == getpid ()))
    return 0;
  if (kill(pid, 0) && (*__errno_location ()) == 3)
   return(0);
  return pid;
}

canonical_original_code:
int check_pid(char *pidfile)
{
  int pid = read_pid(pidfile);
  if ((!pid) || (pid == getpid ()))
    return 0;
  if (kill(pid, 0) && (*__errno_location ()) == 3)
   return(0);
  return pid;
}

variable_types:
pidfile
char *

variable_types: pid int


decompiled_code:
int __fastcall remove_pid(const char *a1)
{
return unlink(a1);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
return unlink(a1);
}

original_code:
int remove_pid (char *pidfile)
{
  return unlink (pidfile);
}

canonical_original_code:
int remove_pid(char *pidfile)
{
  return unlink (pidfile);
}


copyin

decompiled_code:
__int64 __fastcall copyin(__int64 a1, int a2, __int64 a3, int a4, const char *a5)
{
__int64 i; // rbx
unsigned int v7; // er12
char v8; // bp

if ( a2 > a4 )
a2 = a4;
if ( a2 <= 0 )
return 0;
for ( i = 0LL; i != a2; v7 = ++i )
{
v7 = i;
v8 = *(_BYTE *)(a3 + i);
if ( strchr(a5, v8) )
break;
*(_BYTE *)(a1 + i) = v8;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, __int64 a3, int a4, const char *a5)
{
__int64 i; // rbx
unsigned int v7; // er12
char v8; // bp

if ( a2 > a4 )
a2 = a4;
if ( a2 <= 0 )
return 0;
for ( i = 0LL; i != a2; v7 = ++i )
{
v7 = i;
v8 = *(_BYTE *)(a3 + i);
if ( strchr(a5, v8) )
break;
*(_BYTE *)(a1 + i) = v8;
}
return v7;
}

original_code:
static int copyin( char *line, int space,
                   const char *ptr, int len,
                   const char *delim )
{
    auto int i;
    auto int count;
    count = len < space ? len : space;
    for(i=0; i<count && !strchr(delim, *ptr); i++ ) { *line++ = *ptr++; }
    return( i );
}

canonical_original_code:
static int copyin(char *line, int space, char *ptr, int len, char *delim)
{
    auto int i;
    auto int count;
    count = len < space ? len : space;
    for(i=0; i<count && !strchr(delim, *ptr); i++ ) { *line++ = *ptr++; }
    return( i );
}

variable_types:
line
char *

variable_types: space int

variable_types:
ptr
char *

variable_types: len int

variable_types:
delim
char *

variable_types: i int

variable_types: count int


ReloadSymbols

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

if ( symbol_lookup )
{
if ( reload_symbols > 1 )
InitKsyms(symfile);
result = InitMsyms();
}
change_state = 0;
reload_symbols = 0;
return result;
}

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

if ( symbol_lookup )
{
if ( reload_symbols > 1 )
InitKsyms(symfile);
result = InitMsyms();
}
change_state = 0;
reload_symbols = 0;
return result;
}

original_code:
static void ReloadSymbols()
{
 if (symbol_lookup) {
  if ( reload_symbols > 1 )
   InitKsyms(symfile);
  InitMsyms();
 }
 reload_symbols = change_state = 0;
 return;
}


GetKernelLogSrc

decompiled_code:
__int64 GetKernelLogSrc()
{
__int64 result; // rax
int *v1; // rbx
char *v2; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( console_log_level != -1 && klogctl(8, 0LL, console_log_level) < 0 && *_errno_location() == 22 )
Syslog(4, "Cannot set console log level - disabling console output.");
if ( use_syscall || stat("/proc/kmsg", &v3) < 0 && *_errno_location() == 2 )
{
klogctl(1, 0LL, 0);
Syslog(6, "klogd %s.%s, log source = ksyslog started.", "1.5", "0");
result = 2LL;
}
else
{
kmsg = open("/proc/kmsg", 0);
if ( kmsg < 0 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "klogd: Cannot open proc file system, %d - %s.\n", (unsigned int)*v1, v2);
klogctl(7, 0LL, 0);
exit(1);
}
Syslog(6, "klogd %s.%s, log source = %s started.", "1.5", "0", "/proc/kmsg");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 result; // rax
int *v1; // rbx
char *v2; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( console_log_level != -1 && klogctl(8, 0LL, console_log_level) < 0 && *_errno_location() == 22 )
func7(4, "Cannot set console log level - disabling console output.");
if ( use_syscall || stat("/proc/kmsg", &v3) < 0 && *_errno_location() == 2 )
{
klogctl(1, 0LL, 0);
func7(6, "klogd %s.%s, log source = ksyslog started.", "1.5", "0");
result = 2LL;
}
else
{
kmsg = open("/proc/kmsg", 0);
if ( kmsg < 0 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "klogd: Cannot open proc file system, %d - %s.\n", (unsigned int)*v1, v2);
klogctl(7, 0LL, 0);
exit(1);
}
func7(6, "klogd %s.%s, log source = %s started.", "1.5", "0", "/proc/kmsg");
result = 1LL;
}
return result;
}

original_code:
static enum LOGSRC GetKernelLogSrc(void)
{
 auto struct stat sb;
 if ( (console_log_level != -1)
 && (klogctl(8, ((void *)0), console_log_level) < 0) && ((*__errno_location ()) == 22) )
 {
  Syslog(4, "Cannot set console log level - disabling "
         "console output.");
 }
 if ( use_syscall ||
     ((stat("/proc/kmsg", &sb) < 0) && ((*__errno_location ()) == 2)) )
 {
    klogctl(1, ((void *)0), 0);
  Syslog(6, "klogd %s.%s, log source = ksyslog "
         "started.", "1.5", "0");
  return(kernel);
 }
 if ( (kmsg = open("/proc/kmsg", 00)) < 0 )
 {
  fprintf(stderr, "klogd: Cannot open proc file system, " "%d - %s.\n", (*__errno_location ()), strerror((*__errno_location ())));
  klogctl(7, ((void *)0), 0);
  exit(1);
 }
 Syslog(6, "klogd %s.%s, log source = %s started.", "1.5", "0", "/proc/kmsg");
 return(proc);
}

canonical_original_code:
static enum LOGSRC GetKernelLogSrc()
{
 auto struct stat sb;
 if ( (console_log_level != -1)
 && (klogctl(8, ((void *)0), console_log_level) < 0) && ((*__errno_location ()) == 22) )
 {
  Syslog(4, "Cannot set console log level - disabling "
         "console output.");
 }
 if ( use_syscall ||
     ((stat("/proc/kmsg", &sb) < 0) && ((*__errno_location ()) == 2)) )
 {
    klogctl(1, ((void *)0), 0);
  Syslog(6, "klogd %s.%s, log source = ksyslog "
         "started.", "1.5", "0");
  return(kernel);
 }
 if ( (kmsg = open("/proc/kmsg", 00)) < 0 )
 {
  fprintf(stderr, "klogd: Cannot open proc file system, " "%d - %s.\n", (*__errno_location ()), strerror((*__errno_location ())));
  klogctl(7, ((void *)0), 0);
  exit(1);
 }
 Syslog(6, "klogd %s.%s, log source = %s started.", "1.5", "0", "/proc/kmsg");
 return(proc);
}

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

return_type: enum LOGSRC { none=0, proc=1, kernel=2 }

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