main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r13
int v4; // eax
__int64 v5; // r15
__int64 v6; // rbp
int v7; // ebx
const char *v8; // rcx
const char *v9; // rdx
const char *v11; // rax
const char **v12; // rbx
__int64 v13; // r12
const char **v14; // r14
const char *v15; // rbx
const char *v16; // rax
__int64 v17; // rsi
const char *v18; // r8
const char *v19; // rcx
const char *v20; // rdx
char v21; // [rsp+Bh] [rbp-28Dh]
int v22; // [rsp+Ch] [rbp-28Ch]
unsigned __int64 v23; // [rsp+18h] [rbp-280h] BYREF
__int64 v24[33]; // [rsp+20h] [rbp-278h] BYREF
int v25; // [rsp+12Ch] [rbp-16Ch]
char v26; // [rsp+130h] [rbp-168h]
__int64 v27[34]; // [rsp+140h] [rbp-158h] BYREF
char v28; // [rsp+250h] [rbp-48h]

SetUtilityName("GnuGenBootSector", argv, envp);
ZeroMem(v27, 280LL);
ZeroMem(v24, 280LL);
v3 = argv + 1;
v4 = argc - 1;
v22 = argc - 1;
if ( argc == 1 )
{
PrintUsage();
}
else
{
v5 = v4;
if ( v4 > 0 )
{
v21 = 0;
v6 = 0LL;
while ( 1 )
{
v13 = v6;
v14 = &v3[v6];
v15 = *v14;
if ( !strcasecmp(*v14, "-l") || !strcasecmp(v15, "--list") )
{
ListDrive();
return 0;
}
if ( !strcasecmp(v15, "-m") )
{
v21 = 1;
}
else if ( !strcasecmp(v15, "--mbr") )
{
v21 = 1;
}
else if ( !strcasecmp(v15, "-i") || !strcasecmp(v15, "--input") )
{
v16 = v3[v13 + 1];
v27[0] = (__int64)v16;
v28 = 1;
if ( !v16 )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "Input file name can't be NULL");
return 1;
}
if ( *v16 == 45 )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "Input file is missing");
return 1;
}
++v6;
}
else if ( !strcasecmp(v15, "-o") || !strcasecmp(v15, "--output") )
{
v11 = v3[v13 + 1];
v24[0] = (__int64)v11;
v26 = 0;
if ( !v11 )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "Output file name can't be NULL");
return 1;
}
if ( *v11 == 45 )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "Output file is missing");
return 1;
}
++v6;
}
else
{
if ( !strcasecmp(v15, "-h") || !strcasecmp(v15, "--help") )
{
PrintUsage();
return 0;
}
v22 = strcasecmp(v15, "--version");
if ( !v22 )
{
Version();
return v22;
}
if ( strcasecmp(v15, "-v")
&& strcasecmp(v15, "--verbose")
&& strcasecmp(v15, "-q")
&& strcasecmp(v15, "--quiet") )
{
if ( strcasecmp(v15, "-d") && strcasecmp(v15, "--debug") )
{
Error(0LL, 0LL, 1000LL, "Unknown option", "%s", v15);
return 1;
}
v12 = &v3[v13 + 1];
if ( AsciiStringToUint64(*v12, 0LL, &v23) < 0 )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "%s = %s", *v14, *v12);
return 1;
}
if ( v23 > 9 )
{
Error(
0LL,
0LL,
1003LL,
"Invalid option value",
"Debug Level range is 0-9, currnt input level is %d",
(unsigned int)v23);
return 1;
}
SetPrintLevel();
DebugMsg(0LL, 0LL, 9LL, "Debug Mode Set", "Debug Output Mode Level %s is set!", *v12);
++v6;
}
}
if ( ++v6 >= v5 )
goto LABEL_5;
}
}
v21 = 0;
LABEL_5:
if ( v27[0] )
{
if ( v24[0] )
{
if ( (unsigned int)GetPathInfo((__int64)v27) )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "Input file can't be found.");
v22 = 1;
}
else if ( (unsigned int)GetPathInfo((__int64)v24) )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "Output file can't be found.");
v22 = 1;
}
else
{
v7 = ProcessBsOrMbr((__int64)v27, (__int64)v24, v21);
if ( v7 )
{
v17 = (unsigned int)*_errno_location();
v18 = "MBR";
if ( !v21 )
v18 = "DBR";
v19 = "Write";
if ( v25 == 1 )
v19 = "Read";
v20 = "WARNING";
if ( v7 != 3 )
v20 = "ERROR";
fprintf(stderr, "%s: %s %s: failed - %s (LastError: 0x%x)!\n", v20, v19, v18, ErrorStatusDesc[v7], v17);
v22 = 1;
}
else
{
v8 = "MBR";
if ( !v21 )
v8 = "DBR";
v9 = "Write";
if ( v25 == 1 )
v9 = "Read";
fprintf(stdout, "%s %s: successful!\n", v9, v8);
v22 = 0;
}
}
}
else
{
Error(0LL, 0LL, 1001LL, "Missing options", "Output file is missing");
v22 = 1;
}
}
else
{
Error(0LL, 0LL, 1001LL, "Missing options", "Input file is missing");
v22 = 1;
}
}
return v22;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r13
int v4; // eax
__int64 v5; // r15
__int64 v6; // rbp
int v7; // ebx
const char *v8; // rcx
const char *v9; // rdx
const char *v11; // rax
const char **v12; // rbx
__int64 v13; // r12
const char **v14; // r14
const char *v15; // rbx
const char *v16; // rax
__int64 v17; // rsi
const char *v18; // r8
const char *v19; // rcx
const char *v20; // rdx
char v21; // [rsp+Bh] [rbp-28Dh]
int v22; // [rsp+Ch] [rbp-28Ch]
unsigned __int64 v23; // [rsp+18h] [rbp-280h] BYREF
__int64 v24[33]; // [rsp+20h] [rbp-278h] BYREF
int v25; // [rsp+12Ch] [rbp-16Ch]
char v26; // [rsp+130h] [rbp-168h]
__int64 v27[34]; // [rsp+140h] [rbp-158h] BYREF
char v28; // [rsp+250h] [rbp-48h]

SetUtilityName("GnuGenBootSector", argv, envp);
ZeroMem(v27, 280LL);
ZeroMem(v24, 280LL);
v3 = argv + 1;
v4 = argc - 1;
v22 = argc - 1;
if ( argc == 1 )
{
func5();
}
else
{
v5 = v4;
if ( v4 > 0 )
{
v21 = 0;
v6 = 0LL;
while ( 1 )
{
v13 = v6;
v14 = &v3[v6];
v15 = *v14;
if ( !strcasecmp(*v14, "-l") || !strcasecmp(v15, "--list") )
{
func2();
return 0;
}
if ( !strcasecmp(v15, "-m") )
{
v21 = 1;
}
else if ( !strcasecmp(v15, "--mbr") )
{
v21 = 1;
}
else if ( !strcasecmp(v15, "-i") || !strcasecmp(v15, "--input") )
{
v16 = v3[v13 + 1];
v27[0] = (__int64)v16;
v28 = 1;
if ( !v16 )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "Input file name can't be NULL");
return 1;
}
if ( *v16 == 45 )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "Input file is missing");
return 1;
}
++v6;
}
else if ( !strcasecmp(v15, "-o") || !strcasecmp(v15, "--output") )
{
v11 = v3[v13 + 1];
v24[0] = (__int64)v11;
v26 = 0;
if ( !v11 )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "Output file name can't be NULL");
return 1;
}
if ( *v11 == 45 )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "Output file is missing");
return 1;
}
++v6;
}
else
{
if ( !strcasecmp(v15, "-h") || !strcasecmp(v15, "--help") )
{
func5();
return 0;
}
v22 = strcasecmp(v15, "--version");
if ( !v22 )
{
func4();
return v22;
}
if ( strcasecmp(v15, "-v")
&& strcasecmp(v15, "--verbose")
&& strcasecmp(v15, "-q")
&& strcasecmp(v15, "--quiet") )
{
if ( strcasecmp(v15, "-d") && strcasecmp(v15, "--debug") )
{
Error(0LL, 0LL, 1000LL, "Unknown option", "%s", v15);
return 1;
}
v12 = &v3[v13 + 1];
if ( AsciiStringToUint64(*v12, 0LL, &v23) < 0 )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "%s = %s", *v14, *v12);
return 1;
}
if ( v23 > 9 )
{
Error(
0LL,
0LL,
1003LL,
"Invalid option value",
"Debug Level range is 0-9, currnt input level is %d",
(unsigned int)v23);
return 1;
}
SetPrintLevel();
DebugMsg(0LL, 0LL, 9LL, "Debug Mode Set", "Debug Output Mode Level %s is set!", *v12);
++v6;
}
}
if ( ++v6 >= v5 )
goto LABEL_5;
}
}
v21 = 0;
LABEL_5:
if ( v27[0] )
{
if ( v24[0] )
{
if ( (unsigned int)func1((__int64)v27) )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "Input file can't be found.");
v22 = 1;
}
else if ( (unsigned int)func1((__int64)v24) )
{
Error(0LL, 0LL, 1003LL, "Invalid option value", "Output file can't be found.");
v22 = 1;
}
else
{
v7 = func3((__int64)v27, (__int64)v24, v21);
if ( v7 )
{
v17 = (unsigned int)*_errno_location();
v18 = "MBR";
if ( !v21 )
v18 = "DBR";
v19 = "Write";
if ( v25 == 1 )
v19 = "Read";
v20 = "WARNING";
if ( v7 != 3 )
v20 = "ERROR";
fprintf(stderr, "%s: %s %s: failed - %s (LastError: 0x%x)!\n", v20, v19, v18, ErrorStatusDesc[v7], v17);
v22 = 1;
}
else
{
v8 = "MBR";
if ( !v21 )
v8 = "DBR";
v9 = "Write";
if ( v25 == 1 )
v9 = "Read";
fprintf(stdout, "%s %s: successful!\n", v9, v8);
v22 = 0;
}
}
}
else
{
Error(0LL, 0LL, 1001LL, "Missing options", "Output file is missing");
v22 = 1;
}
}
else
{
Error(0LL, 0LL, 1001LL, "Missing options", "Input file is missing");
v22 = 1;
}
}
return v22;
}

original_code:
int
main (
  int argc,
  char *argv[]
  )
{
  CHAR8 *AppName;
  INTN Index;
  BOOLEAN ProcessMbr;
  ERROR_STATUS Status;
  EFI_STATUS EfiStatus;
  PATH_INFO InputPathInfo;
  PATH_INFO OutputPathInfo;
  UINT64 LogLevel;
  SetUtilityName ("GnuGenBootSector");
  ZeroMem(&InputPathInfo, sizeof(PATH_INFO));
  ZeroMem(&OutputPathInfo, sizeof(PATH_INFO));
  AppName = *argv;
  argv ++;
  argc --;
  ProcessMbr = ((BOOLEAN)(0==1));
  if (argc == 0) {
    PrintUsage();
    return 0;
  }
  for (Index = 0; Index < argc; Index ++) {
    if ((strcasecmp (argv[Index], "-l") == 0) || (strcasecmp (argv[Index], "--list") == 0)) {
      ListDrive ();
      return 0;
    }
    if ((strcasecmp (argv[Index], "-m") == 0) || (strcasecmp (argv[Index], "--mbr") == 0)) {
      ProcessMbr = ((BOOLEAN)(1==1));
      continue;
    }
    if ((strcasecmp (argv[Index], "-i") == 0) || (strcasecmp (argv[Index], "--input") == 0)) {
      InputPathInfo.Path = argv[Index + 1];
      InputPathInfo.Input = ((BOOLEAN)(1==1));
      if (InputPathInfo.Path == ((void *)0)) {
        Error (((void *)0), 0, 1003, "Invalid option value", "Input file name can't be NULL");
        return 1;
      }
      if (InputPathInfo.Path[0] == '-') {
        Error (((void *)0), 0, 1003, "Invalid option value", "Input file is missing");
        return 1;
      }
      ++Index;
      continue;
    }
    if ((strcasecmp (argv[Index], "-o") == 0) || (strcasecmp (argv[Index], "--output") == 0)) {
      OutputPathInfo.Path = argv[Index + 1];
      OutputPathInfo.Input = ((BOOLEAN)(0==1));
      if (OutputPathInfo.Path == ((void *)0)) {
        Error (((void *)0), 0, 1003, "Invalid option value", "Output file name can't be NULL");
        return 1;
      }
      if (OutputPathInfo.Path[0] == '-') {
        Error (((void *)0), 0, 1003, "Invalid option value", "Output file is missing");
        return 1;
      }
      ++Index;
      continue;
    }
    if ((strcasecmp (argv[Index], "-h") == 0) || (strcasecmp (argv[Index], "--help") == 0)) {
      PrintUsage ();
      return 0;
    }
    if (strcasecmp (argv[Index], "--version") == 0) {
      Version ();
      return 0;
    }
    if ((strcasecmp (argv[Index], "-v") == 0) || (strcasecmp (argv[Index], "--verbose") == 0)) {
      continue;
    }
    if ((strcasecmp (argv[Index], "-q") == 0) || (strcasecmp (argv[Index], "--quiet") == 0)) {
      continue;
    }
    if ((strcasecmp (argv[Index], "-d") == 0) || (strcasecmp (argv[Index], "--debug") == 0)) {
      EfiStatus = AsciiStringToUint64 (argv[Index + 1], ((BOOLEAN)(0==1)), &LogLevel);
      if (((EfiStatus) < 0)) {
        Error (((void *)0), 0, 1003, "Invalid option value", "%s = %s", argv[Index], argv[Index + 1]);
        return 1;
      }
      if (LogLevel > 9) {
        Error (((void *)0), 0, 1003, "Invalid option value", "Debug Level range is 0-9, currnt input level is %d", (int) LogLevel);
        return 1;
      }
      SetPrintLevel (LogLevel);
      DebugMsg (((void *)0), 0, 9, "Debug Mode Set", "Debug Output Mode Level %s is set!", argv[Index + 1]);
      ++Index;
      continue;
    }
    Error (((void *)0), 0, 1000, "Unknown option", "%s", argv[Index]);
    return 1;
  }
  if (InputPathInfo.Path == ((void *)0)) {
    Error (((void *)0), 0, 1001, "Missing options", "Input file is missing");
    return 1;
  }
  if (OutputPathInfo.Path == ((void *)0)) {
    Error (((void *)0), 0, 1001, "Missing options", "Output file is missing");
    return 1;
  }
  if (GetPathInfo(&InputPathInfo) != ErrorSuccess) {
    Error (((void *)0), 0, 1003, "Invalid option value", "Input file can't be found.");
    return 1;
  }
  if (GetPathInfo(&OutputPathInfo) != ErrorSuccess) {
    Error (((void *)0), 0, 1003, "Invalid option value", "Output file can't be found.");
    return 1;
  }
  Status = ProcessBsOrMbr (&InputPathInfo, &OutputPathInfo, ProcessMbr);
  if (Status == ErrorSuccess) {
    fprintf (
      stdout,
      "%s %s: successful!\n",
      (OutputPathInfo.Type != PathFile) ? "Write" : "Read",
      ProcessMbr ? "MBR" : "DBR"
      );
    return 0;
  } else {
    fprintf (
      stderr,
      "%s: %s %s: failed - %s (LastError: 0x%x)!\n",
      (Status == ErrorNoMbr) ? "WARNING" : "ERROR",
      (OutputPathInfo.Type != PathFile) ? "Write" : "Read",
      ProcessMbr ? "MBR" : "DBR",
      ErrorStatusDesc[Status],
      (*__errno_location ())
      );
    return 1;
  }
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char *AppName;
  long Index;
  unsigned char ProcessMbr;
  enum ERROR_STATUS Status;
  long EfiStatus;
  struct _PATH_INFO InputPathInfo;
  struct _PATH_INFO OutputPathInfo;
  unsigned long LogLevel;
  SetUtilityName ("GnuGenBootSector");
  ZeroMem(&InputPathInfo, sizeof(PATH_INFO));
  ZeroMem(&OutputPathInfo, sizeof(PATH_INFO));
  AppName = *argv;
  argv ++;
  argc --;
  ProcessMbr = ((BOOLEAN)(0==1));
  if (argc == 0) {
    PrintUsage();
    return 0;
  }
  for (Index = 0; Index < argc; Index ++) {
    if ((strcasecmp (argv[Index], "-l") == 0) || (strcasecmp (argv[Index], "--list") == 0)) {
      ListDrive ();
      return 0;
    }
    if ((strcasecmp (argv[Index], "-m") == 0) || (strcasecmp (argv[Index], "--mbr") == 0)) {
      ProcessMbr = ((BOOLEAN)(1==1));
      continue;
    }
    if ((strcasecmp (argv[Index], "-i") == 0) || (strcasecmp (argv[Index], "--input") == 0)) {
      InputPathInfo.Path = argv[Index + 1];
      InputPathInfo.Input = ((BOOLEAN)(1==1));
      if (InputPathInfo.Path == ((void *)0)) {
        Error (((void *)0), 0, 1003, "Invalid option value", "Input file name can't be NULL");
        return 1;
      }
      if (InputPathInfo.Path[0] == '-') {
        Error (((void *)0), 0, 1003, "Invalid option value", "Input file is missing");
        return 1;
      }
      ++Index;
      continue;
    }
    if ((strcasecmp (argv[Index], "-o") == 0) || (strcasecmp (argv[Index], "--output") == 0)) {
      OutputPathInfo.Path = argv[Index + 1];
      OutputPathInfo.Input = ((BOOLEAN)(0==1));
      if (OutputPathInfo.Path == ((void *)0)) {
        Error (((void *)0), 0, 1003, "Invalid option value", "Output file name can't be NULL");
        return 1;
      }
      if (OutputPathInfo.Path[0] == '-') {
        Error (((void *)0), 0, 1003, "Invalid option value", "Output file is missing");
        return 1;
      }
      ++Index;
      continue;
    }
    if ((strcasecmp (argv[Index], "-h") == 0) || (strcasecmp (argv[Index], "--help") == 0)) {
      PrintUsage ();
      return 0;
    }
    if (strcasecmp (argv[Index], "--version") == 0) {
      Version ();
      return 0;
    }
    if ((strcasecmp (argv[Index], "-v") == 0) || (strcasecmp (argv[Index], "--verbose") == 0)) {
      continue;
    }
    if ((strcasecmp (argv[Index], "-q") == 0) || (strcasecmp (argv[Index], "--quiet") == 0)) {
      continue;
    }
    if ((strcasecmp (argv[Index], "-d") == 0) || (strcasecmp (argv[Index], "--debug") == 0)) {
      EfiStatus = AsciiStringToUint64 (argv[Index + 1], ((BOOLEAN)(0==1)), &LogLevel);
      if (((EfiStatus) < 0)) {
        Error (((void *)0), 0, 1003, "Invalid option value", "%s = %s", argv[Index], argv[Index + 1]);
        return 1;
      }
      if (LogLevel > 9) {
        Error (((void *)0), 0, 1003, "Invalid option value", "Debug Level range is 0-9, currnt input level is %d", (int) LogLevel);
        return 1;
      }
      SetPrintLevel (LogLevel);
      DebugMsg (((void *)0), 0, 9, "Debug Mode Set", "Debug Output Mode Level %s is set!", argv[Index + 1]);
      ++Index;
      continue;
    }
    Error (((void *)0), 0, 1000, "Unknown option", "%s", argv[Index]);
    return 1;
  }
  if (InputPathInfo.Path == ((void *)0)) {
    Error (((void *)0), 0, 1001, "Missing options", "Input file is missing");
    return 1;
  }
  if (OutputPathInfo.Path == ((void *)0)) {
    Error (((void *)0), 0, 1001, "Missing options", "Output file is missing");
    return 1;
  }
  if (GetPathInfo(&InputPathInfo) != ErrorSuccess) {
    Error (((void *)0), 0, 1003, "Invalid option value", "Input file can't be found.");
    return 1;
  }
  if (GetPathInfo(&OutputPathInfo) != ErrorSuccess) {
    Error (((void *)0), 0, 1003, "Invalid option value", "Output file can't be found.");
    return 1;
  }
  Status = ProcessBsOrMbr (&InputPathInfo, &OutputPathInfo, ProcessMbr);
  if (Status == ErrorSuccess) {
    fprintf (
      stdout,
      "%s %s: successful!\n",
      (OutputPathInfo.Type != PathFile) ? "Write" : "Read",
      ProcessMbr ? "MBR" : "DBR"
      );
    return 0;
  } else {
    fprintf (
      stderr,
      "%s: %s %s: failed - %s (LastError: 0x%x)!\n",
      (Status == ErrorNoMbr) ? "WARNING" : "ERROR",
      (OutputPathInfo.Type != PathFile) ? "Write" : "Read",
      ProcessMbr ? "MBR" : "DBR",
      ErrorStatusDesc[Status],
      (*__errno_location ())
      );
    return 1;
  }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
AppName
char *

variable_types: Index long

variable_types:
ProcessMbr
unsigned char

variable_types: enum ERROR_STATUS { ErrorSuccess=0, ErrorFileCreate=1, ErrorFileReadWrite=2, ErrorNoMbr=3, ErrorFatType=4, ErrorPath=5 }

variable_types: EfiStatus long

variable_types: struct _PATH_INFO { char *Path; char PhysicalPath[260]; enum PATH_TYPE { PathUnknown=0, PathFile=1, PathFloppy=2, PathUsb=3, PathIde=4 } Type; unsigned char Input; }

variable_types:
LogLevel
unsigned long

user_defined_types: struct _PATH_INFO { char *Path; char PhysicalPath[260]; enum PATH_TYPE Type; unsigned char Input; }


repo: guobamantou/loongson-uefi

decompiled_code:
__int64 *clear_hash()
{
__int64 *result; // rax

result = &dfa_hash;
do
*result++ = 0LL;
while ( result != (__int64 *)(unsigned int)((_DWORD)&dfa_hash + 1688) );
return result;
}

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

result = &dfa_hash;
do
*result++ = 0LL;
while ( result != (__int64 *)(unsigned int)((_DWORD)&dfa_hash + 1688) );
return result;
}

original_code:
void
clear_hash(void)
{
 register int i;
 for(i=0; i<211; ++i)
  dfa_hash[i] = 0;
}

canonical_original_code:
void clear_hash()
{
 register int i;
 for(i=0; i<211; ++i)
  dfa_hash[i] = 0;
}

variable_types: i int

return_type: void


reach

decompiled_code:
__int64 __fastcall reach(_DWORD *a1, unsigned int a2, _DWORD *a3)
{
unsigned int v4; // er13
_DWORD *v5; // rbx
unsigned int v6; // eax
__int64 v7; // r15
int *v8; // rdx
int v9; // eax

v4 = 0;
if ( a1 )
{
v5 = a1;
v6 = *a1;
if ( *a1 == -1 )
{
v4 = 0;
}
else
{
do
{
v7 = *(_QWORD *)(nfa_array + 8LL * v6);
if ( (unsigned int)set_el(a2, *(unsigned int *)(v7 + 32), *(_QWORD *)(v7 + 40)) )
{
v8 = *(int **)(v7 + 16);
v9 = 0;
if ( v8 )
v9 = *v8;
*a3++ = v9;
v4 = 1;
}
v6 = *++v5;
}
while ( *v5 != -1 );
}
}
*a3 = -1;
return v4;
}

original_code:
int
reach(unsigned *nfa_list, register int a, unsigned *reach_list)
{
 register unsigned *e;
 register struct _nfa_node *node;
 int t=0;
 e = nfa_list;
 if (e){
  while (*e != (~((unsigned) 0))){
   node = (nfa_array[*e]);
   if (set_el(a,node->label)){
    t=1;
    *reach_list=( (node->trans[0]) ? (node->trans[0])->node_no : 0);
    ++reach_list;
   }
   ++e;
  }
 }
 *reach_list=(~((unsigned) 0));
 return t;
}

canonical_original_code:
int reach(unsigned int *nfa_list, int a, unsigned int *reach_list)
{
 register unsigned int *e;
 register struct _nfa_node *node;
 int t = 0;
 e = nfa_list;
 if (e){
  while (*e != (~((unsigned int) 0))){
   node = (nfa_array[*e]);
   if (set_el(a,node->label)){
    t=1;
    *reach_list=( (node->trans[0]) ? (node->trans[0])->node_no : 0);
    ++reach_list;
   }
   ++e;
  }
 }
 *reach_list=(~((unsigned int) 0));
 return t;
}

variable_types: a int

variable_types:
e
unsigned int *

variable_types: struct _nfa_node { int node_no; int nfa_set; int accept; struct _nfa_node *trans[2]; struct _set { unsigned int n; unsigned int *setword; } label; } *

variable_types: t int

return_type: int

user_defined_types: struct _nfa_node { int node_no; int nfa_set; int accept; struct _nfa_node *trans[2]; struct _set label; }


decompiled_code:
void __fastcall close1(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int *v4; // r13
unsigned int *v5; // rbx

*(_DWORD *)(a1 + 4) = a2;
v4 = *(unsigned int **)(a1 + 16);
if ( v4 && (unsigned int)set_nil(*(unsigned int *)(a1 + 32), *(_QWORD *)(a1 + 40)) && v4[1] != a2 )
{
set_orel(*v4, a3);
close1(v4, a2, a3);
}
v5 = *(unsigned int **)(a1 + 24);
if ( v5 )
{
if ( v5[1] != a2 )
{
set_orel(*v5, a3);
close1(v5, a2, a3);
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int *v4; // r13
unsigned int *v5; // rbx

*(_DWORD *)(a1 + 4) = a2;
v4 = *(unsigned int **)(a1 + 16);
if ( v4 && (unsigned int)set_nil(*(unsigned int *)(a1 + 32), *(_QWORD *)(a1 + 40)) && v4[1] != a2 )
{
set_orel(*v4, a3);
func3(v4, a2, a3);
}
v5 = *(unsigned int **)(a1 + 24);
if ( v5 )
{
if ( v5[1] != a2 )
{
set_orel(*v5, a3);
func3(v5, a2, a3);
}
}
}

original_code:
void close1(struct _nfa_node *node, int o, set *b)
{
 register struct _nfa_node *n;
 node->nfa_set = o;
 if ((n=node->trans[0]) != 0 && set_nil(node->label) &&
   (n->nfa_set != o)){
  set_orel(( (n) ? (n)->node_no : 0),b);
  close1(n,o,b);
 }
 if ((n=node->trans[1]) != 0 &&
   (n->nfa_set != o)){
  set_orel(( (node->trans[1]) ? (node->trans[1])->node_no : 0),b);
  close1(n,o,b);
 }
}

canonical_original_code:
void close1(struct _nfa_node *node, int o, struct _set *b)
{
 register struct _nfa_node *n;
 node->nfa_set = o;
 if ((n=node->trans[0]) != 0 && set_nil(node->label) &&
   (n->nfa_set != o)){
  set_orel(( (n) ? (n)->node_no : 0),b);
  close1(n,o,b);
 }
 if ((n=node->trans[1]) != 0 &&
   (n->nfa_set != o)){
  set_orel(( (node->trans[1]) ? (node->trans[1])->node_no : 0),b);
  close1(n,o,b);
 }
}

variable_types: o int

variable_types:
b
struct _set *

user_defined_types: struct _set { unsigned int n; unsigned int *setword; }


closure

decompiled_code:
__int64 __fastcall closure(__int64 a1, unsigned int *a2)
{
unsigned int v3; // eax
unsigned int *v4; // rbp
unsigned int *v5; // rbx
unsigned int *v6; // rbx
__int64 v7; // rdi
unsigned int *v8; // r14

++operation_no;
v3 = *a2;
if ( *a2 != -1 )
{
v4 = a2;
do
{
v6 = *(unsigned int **)(nfa_array + 8LL * v3);
v7 = 0LL;
if ( v6 )
v7 = *v6;
set_orel(v7, a1);
v6[1] = operation_no;
v8 = (unsigned int *)*((_QWORD *)v6 + 2);
if ( v8 && (unsigned int)set_nil(v6[8], *((_QWORD *)v6 + 5)) && v8[1] != operation_no )
{
set_orel(*v8, a1);
close1((__int64)v8, operation_no, a1);
}
v5 = (unsigned int *)*((_QWORD *)v6 + 3);
if ( v5 && v5[1] != operation_no )
{
set_orel(*v5, a1);
close1((__int64)v5, operation_no, a1);
}
v3 = *++v4;
}
while ( *v4 != -1 );
}
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int *a2)
{
unsigned int v3; // eax
unsigned int *v4; // rbp
unsigned int *v5; // rbx
unsigned int *v6; // rbx
__int64 v7; // rdi
unsigned int *v8; // r14

++operation_no;
v3 = *a2;
if ( *a2 != -1 )
{
v4 = a2;
do
{
v6 = *(unsigned int **)(nfa_array + 8LL * v3);
v7 = 0LL;
if ( v6 )
v7 = *v6;
set_orel(v7, a1);
v6[1] = operation_no;
v8 = (unsigned int *)*((_QWORD *)v6 + 2);
if ( v8 && (unsigned int)set_nil(v6[8], *((_QWORD *)v6 + 5)) && v8[1] != operation_no )
{
set_orel(*v8, a1);
func3((__int64)v8, operation_no, a1);
}
v5 = (unsigned int *)*((_QWORD *)v6 + 3);
if ( v5 && v5[1] != operation_no )
{
set_orel(*v5, a1);
func3((__int64)v5, operation_no, a1);
}
v3 = *++v4;
}
while ( *v4 != -1 );
}
return *(_QWORD *)a1;
}

original_code:
set
closure(set *b, unsigned *reach_list)
{
 register struct _nfa_node *node,*n;
 register unsigned *e;
 ++operation_no;
 e=reach_list;
 while (*e != (~((unsigned) 0))){
  node = (nfa_array[*e]);
  set_orel(( (node) ? (node)->node_no : 0),b);
  node->nfa_set = operation_no;
  if ((n=node->trans[0]) != 0 && set_nil(node->label) &&
    (n->nfa_set != operation_no)){
   set_orel(( (n) ? (n)->node_no : 0),b);
   close1(n,operation_no,b);
  }
  if ((n=node->trans[1]) != 0 &&
    (n->nfa_set != operation_no)){
   set_orel(( (node->trans[1]) ? (node->trans[1])->node_no : 0),b);
   close1(n,operation_no,b);
  }
  ++e;
 }
 return *b;
}

canonical_original_code:
struct _set closure(struct _set *b, unsigned int *reach_list)
{
 register struct _nfa_node *node; register struct _nfa_node *n;
 register unsigned int *e;
 ++operation_no;
 e=reach_list;
 while (*e != (~((unsigned int) 0))){
  node = (nfa_array[*e]);
  set_orel(( (node) ? (node)->node_no : 0),b);
  node->nfa_set = operation_no;
  if ((n=node->trans[0]) != 0 && set_nil(node->label) &&
    (n->nfa_set != operation_no)){
   set_orel(( (n) ? (n)->node_no : 0),b);
   close1(n,operation_no,b);
  }
  if ((n=node->trans[1]) != 0 &&
    (n->nfa_set != operation_no)){
   set_orel(( (node->trans[1]) ? (node->trans[1])->node_no : 0),b);
   close1(n,operation_no,b);
  }
  ++e;
 }
 return *b;
}

return_type: struct _set { unsigned int n; unsigned int *setword; }


decompiled_code:
void *__fastcall nfa_to_dfa(unsigned int *a1)
{
unsigned int *v1; // rax
unsigned int *v2; // rbp
__int64 v3; // rdx
int *v4; // rax
int *v5; // r12
int v6; // er14
__int64 v7; // r15
int *v8; // rax
int v9; // edx
__int64 v10; // rbx
_DWORD *v11; // r13
__m128i ptr; // [rsp+0h] [rbp-48h] BYREF

v1 = (unsigned int *)malloc(4LL * (nfa_allocated + 2));
if ( !a1 )
return 0LL;
v2 = v1;
ptr.m128i_i32[0] = set_of(*a1);
ptr.m128i_i64[1] = v3;
set_pdq(ptr.m128i_u32[0], v3, v2);
closure((__int64)&ptr, v2);
v4 = (int *)dfastate(ptr.m128i_u32[0], ptr.m128i_i64[1]);
v5 = v4;
v6 = 0;
if ( v4 )
v6 = *v4;
v7 = 8LL * v6 + 8;
do
{
v5[3] = 1;
v11 = (_DWORD *)set_pdq((unsigned int)v5[4], *((_QWORD *)v5 + 3));
if ( class_no > 0 )
{
v10 = 0LL;
do
{
reach(v11, v10, v2);
if ( *v2 != -1 )
{
if ( ptr.m128i_i64[1] )
free((void *)ptr.m128i_i64[1]);
ptr = _mm_loadu_si128(&empty);
closure((__int64)&ptr, v2);
v8 = (int *)dfastate(ptr.m128i_u32[0], ptr.m128i_i64[1]);
v9 = 0;
if ( v8 )
v9 = *v8;
v5[v10 + 8] = v9;
v5[2] = 1;
}
++v10;
}
while ( class_no > (int)v10 );
}
free(v11);
++v6;
v5 = *(int **)((char *)dfa_array + v7);
v7 += 8LL;
}
while ( dfa_allocated >= v6 );
free(v2);
if ( ptr.m128i_i64[1] )
free((void *)ptr.m128i_i64[1]);
return dfa_array;
}

original_code:
struct _dfa_node **
nfa_to_dfa(struct _nfa_node *start)
{
 register struct _dfa_node *d_state, *trans_d_state;
 register int a;
 set t;
 int last_done;
 unsigned *nfa_list;
 unsigned *reach_list;
 reach_list = (unsigned *) malloc((2+nfa_allocated)*sizeof(unsigned));
 if (!start) return ((void *)0);
 t = set_of(( (start) ? (start)->node_no : 0));
 _set_pdq(t,reach_list);
 closure(&t,reach_list);
 d_state = dfastate(t);
 last_done = ( (d_state) ? (d_state)->node_no : 0);
 do {
  d_state->done = 1;
  nfa_list = set_pdq(d_state->nfa_states);
  for (a = 0; a<class_no; ++a) {
   reach(nfa_list,a,reach_list);
   if ((*reach_list)!=(~((unsigned) 0))) {
    {if ( (t).setword != ((void *)0) ) free((char *)((t).setword)); (t) = empty;};
    closure(&t,reach_list);
    trans_d_state = dfastate(t);
    d_state->trans[a] = ( (trans_d_state) ? (trans_d_state)->node_no : 0);
    d_state->alternatives = 1;
   }
  }
  free(nfa_list);
  ++last_done;
  d_state = (dfa_array[last_done]);
 } while (last_done<=dfa_allocated);
 free(reach_list);
 {if ( (t).setword != ((void *)0) ) free((char *)((t).setword)); (t) = empty;};
 return dfa_array;
}

canonical_original_code:
struct _dfa_node **nfa_to_dfa(struct _nfa_node *start)
{
 register struct _dfa_node *d_state; register struct _dfa_node *trans_d_state;
 register int a;
 struct _set t;
 int last_done;
 unsigned int *nfa_list;
 unsigned int *reach_list;
 reach_list = (unsigned int *) malloc((2+nfa_allocated)*sizeof(unsigned int));
 if (!start) return ((void *)0);
 t = set_of(( (start) ? (start)->node_no : 0));
 _set_pdq(t,reach_list);
 closure(&t,reach_list);
 d_state = dfastate(t);
 last_done = ( (d_state) ? (d_state)->node_no : 0);
 do {
  d_state->done = 1;
  nfa_list = set_pdq(d_state->nfa_states);
  for (a = 0; a<class_no; ++a) {
   reach(nfa_list,a,reach_list);
   if ((*reach_list)!=(~((unsigned int) 0))) {
    {if ( (t).setword != ((void *)0) ) free((char *)((t).setword)); (t) = empty;};
    closure(&t,reach_list);
    trans_d_state = dfastate(t);
    d_state->trans[a] = ( (trans_d_state) ? (trans_d_state)->node_no : 0);
    d_state->alternatives = 1;
   }
  }
  free(nfa_list);
  ++last_done;
  d_state = (dfa_array[last_done]);
 } while (last_done<=dfa_allocated);
 free(reach_list);
 {if ( (t).setword != ((void *)0) ) free((char *)((t).setword)); (t) = empty;};
 return dfa_array;
}

variable_types: struct _nfa_node { int node_no; int nfa_set; int accept; struct _nfa_node *trans[2]; struct _set label; } *

return_type: struct _dfa_node { int node_no; int dfa_set; int alternatives; int done; struct _set { unsigned int n; unsigned int *setword; } nfa_states; int trans[1]; } **

user_defined_types: struct _dfa_node { int node_no; int dfa_set; int alternatives; int done; struct _set nfa_states; int trans[1]; }


CommonLibBinderAllocate

decompiled_code:
void *__fastcall CommonLibBinderAllocate(size_t a1)
{
return malloc(a1);
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
return malloc(a1);
}

original_code:
void *
CommonLibBinderAllocate (
  UINTN Size
  )
{
  return (void *) malloc (Size);
}

canonical_original_code:
void *CommonLibBinderAllocate(unsigned int Size)
{
  return (void *) malloc (Size);
}

variable_types:
Size
unsigned int

return_type: void *


CommonLibBinderFree

decompiled_code:
void __fastcall CommonLibBinderFree(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
free(a1);
}

original_code:
void
CommonLibBinderFree (
  void *Pointer
  )
{
  free (Pointer);
}

canonical_original_code:
void CommonLibBinderFree(void *Pointer)
{
  free (Pointer);
}

variable_types:
Pointer
void *


CommonLibBinderCopyMem

decompiled_code:
void *__fastcall CommonLibBinderCopyMem(void *a1, const void *a2, size_t a3)
{
return memmove(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, const void *a2, size_t a3)
{
return memmove(a1, a2, a3);
}

original_code:
void
CommonLibBinderCopyMem (
  void *Destination,
  void *Source,
  UINTN Length
  )
{
  memmove (Destination, Source, Length);
}

canonical_original_code:
void CommonLibBinderCopyMem(void *Destination, void *Source, unsigned int Length)
{
  memmove (Destination, Source, Length);
}

variable_types:
Destination
void *

variable_types:
Source
void *

variable_types:
Length
unsigned int


CommonLibBinderSetMem

decompiled_code:
void *__fastcall CommonLibBinderSetMem(void *a1, size_t a2, unsigned __int8 a3)
{
return memset(a1, a3, a2);
}

canonical_decompiled_code:
void *__fastcall func3(void *a1, size_t a2, unsigned __int8 a3)
{
return memset(a1, a3, a2);
}

original_code:
void
CommonLibBinderSetMem (
  void *Destination,
  UINTN Length,
  UINT8 Value
  )
{
  memset (Destination, Value, Length);
}

canonical_original_code:
void CommonLibBinderSetMem(void *Destination, unsigned int Length, unsigned char Value)
{
  memset (Destination, Value, Length);
}

variable_types:
Value
unsigned char


CommonLibBinderCompareMem

decompiled_code:
__int64 __fastcall CommonLibBinderCompareMem(const void *a1, const void *a2, size_t a3)
{
return memcmp(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func4(const void *a1, const void *a2, size_t a3)
{
return memcmp(a1, a2, a3);
}

original_code:
INTN
CommonLibBinderCompareMem (
  void *MemOne,
  void *MemTwo,
  UINTN Length
  )
{
  return memcmp (MemOne, MemTwo, Length);
}

canonical_original_code:
int CommonLibBinderCompareMem(void *MemOne, void *MemTwo, unsigned int Length)
{
  return memcmp (MemOne, MemTwo, Length);
}

variable_types:
MemOne
void *

variable_types:
MemTwo
void *


CommonLibBinderCompareGuid

decompiled_code:
bool CommonLibBinderCompareGuid()
{
return CompareGuid() == 0;
}

canonical_decompiled_code:
bool func5()
{
return CompareGuid() == 0;
}

original_code:
BOOLEAN
CommonLibBinderCompareGuid (
  EFI_GUID *Guid1,
  EFI_GUID *Guid2
  )
{
  return CompareGuid (Guid1, Guid2) ? ((BOOLEAN)(0==1)) : ((BOOLEAN)(1==1));
}

canonical_original_code:
unsigned char CommonLibBinderCompareGuid(struct EFI_GUID *Guid1, struct EFI_GUID *Guid2)
{
  return CompareGuid (Guid1, Guid2) ? ((BOOLEAN)(0==1)) : ((BOOLEAN)(1==1));
}

variable_types: struct EFI_GUID { unsigned int Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8]; } *

return_type: unsigned char


decompiled_code:
void p_comp0()
{
comp_level = 0;
}

canonical_decompiled_code:
void func0()
{
comp_level = 0;
}

original_code: void p_comp0(void) {comp_level = 0;}

canonical_original_code: void p_comp0() {comp_level = 0;}


decompiled_code:
void p_comp1()
{
comp_level = 1;
}

canonical_decompiled_code:
void func1()
{
comp_level = 1;
}

original_code: void p_comp1(void) {comp_level = 1;}

canonical_original_code: void p_comp1() {comp_level = 1;}


decompiled_code:
void p_comp2()
{
comp_level = 2;
}

canonical_decompiled_code:
void func2()
{
comp_level = 2;
}

original_code: void p_comp2(void) {comp_level = 2;}

canonical_original_code: void p_comp2() {comp_level = 2;}


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

LODWORD(result) = numfiles++;
result = (int)result;
file_str[(int)result] = 0LL;
return result;
}

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

LODWORD(result) = numfiles++;
result = (int)result;
file_str[(int)result] = 0LL;
return result;
}

original_code: void p_stdio(void) { file_str[numfiles++] = ((void *)0);}

canonical_original_code: void p_stdio() { file_str[numfiles++] = ((void *)0);}


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

LODWORD(result) = numfiles++;
result = (int)result;
file_str[(int)result] = a1;
return result;
}

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

LODWORD(result) = numfiles++;
result = (int)result;
file_str[(int)result] = a1;
return result;
}

original_code: void p_file(char *s) { file_str[numfiles++] = s;}

variable_types:
s
char *


decompiled_code:
void __fastcall p_mode_file(__int64 a1, char *a2)
{
mode_file = a2;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, char *a2)
{
mode_file = a2;
}

original_code: void p_mode_file(char *s, char *t){mode_file=t;}

variable_types:
t
char *


decompiled_code:
void __fastcall p_outdir(__int64 a1, char *a2)
{
OutputDirectory[0] = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, char *a2)
{
OutputDirectory[0] = a2;
}

original_code: void p_outdir(char *s,char *t) {OutputDirectory=t;}

canonical_original_code: void p_outdir(char *s, char *t) {OutputDirectory=t;}


decompiled_code:
void p_ansi()
{
gen_ansi = 1;
}

canonical_decompiled_code:
void func7()
{
gen_ansi = 1;
}

original_code: void p_ansi(void) {gen_ansi = 1;}

canonical_original_code: void p_ansi() {gen_ansi = 1;}


decompiled_code:
void p_interactive()
{
interactive = 1;
}

canonical_decompiled_code:
void func8()
{
interactive = 1;
}

original_code: void p_interactive(void) {interactive = 1;}

canonical_original_code: void p_interactive() {interactive = 1;}


decompiled_code:
void p_case_s()
{
case_insensitive = 0;
}

canonical_decompiled_code:
void func9()
{
case_insensitive = 0;
}

original_code: void p_case_s(void) { case_insensitive = 0; }


decompiled_code:
void p_case_i()
{
case_insensitive = 1;
}

canonical_decompiled_code:
void func10()
{
case_insensitive = 1;
}

original_code: void p_case_i(void) { case_insensitive = 1; }


decompiled_code:
void p_warn_ambig()
{
warn_ambig = 1;
}

canonical_decompiled_code:
void func11()
{
warn_ambig = 1;
}

original_code: void p_warn_ambig(void) { warn_ambig = 1; }

canonical_original_code: void p_warn_ambig() { warn_ambig = 1; }


decompiled_code:
void p_cpp()
{
gen_cpp = 1;
}

canonical_decompiled_code:
void func12()
{
gen_cpp = 1;
}

original_code: void p_cpp(void) { gen_cpp = 1; }

canonical_original_code: void p_cpp() { gen_cpp = 1; }


decompiled_code:
__int64 __fastcall p_cl_name(__int64 a1, char *a2)
{
__int64 result; // rax

if ( !gen_cpp )
return warning("-cl only valid in C++ mode; -cl ignored...", 0LL);
class_name[0] = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, char *a2)
{
__int64 result; // rax

if ( !gen_cpp )
return warning("-cl only valid in C++ mode; -cl ignored...", 0LL);
class_name[0] = a2;
return result;
}

original_code:
void p_cl_name(char *s, char *t)
 {
  if ( gen_cpp ) {
   class_name = t;
  }
  else {
   warning("-cl only valid in C++ mode; -cl ignored...",0);
  }
 }


decompiled_code:
__int64 new_automaton_mode()
{
void *v0; // rdi

v0 = (void *)used_chars.m128i_i64[1];
if ( v0 )
free(v0);
used_chars = _mm_loadu_si128((const __m128i *)empty);
return clear_hash();
}

canonical_decompiled_code:
__int64 func17()
{
void *v0; // rdi

v0 = (void *)used_chars.m128i_i64[1];
if ( v0 )
free(v0);
used_chars = _mm_loadu_si128((const __m128i *)empty);
return clear_hash();
}

original_code:
void
new_automaton_mode(void)
{
 {if ( (used_chars).setword != ((void *)0) ) free((char *)((used_chars).setword)); (used_chars) = empty;};
 clear_hash();
}

canonical_original_code:
void new_automaton_mode()
{
 {if ( (used_chars).setword != ((void *)0) ) free((char *)((used_chars).setword)); (used_chars) = empty;};
 clear_hash();
}


decompiled_code:
_BOOL8 __fastcall ci_strequ(unsigned __int8 *a1, char *a2)
{
unsigned __int8 *v2; // r13
unsigned __int8 i; // bl
char v5; // bp
const __int32_t **v6; // rax

v2 = a1;
for ( i = *a1; *v2; i = *v2 )
{
v5 = *a2;
if ( !*a2 )
break;
v6 = _ctype_toupper_loc();
if ( (*v6)[v5] != (*v6)[(char)i] )
return 0LL;
++v2;
++a2;
}
return *a2 == (char)i;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(unsigned __int8 *a1, char *a2)
{
unsigned __int8 *v2; // r13
unsigned __int8 i; // bl
char v5; // bp
const __int32_t **v6; // rax

v2 = a1;
for ( i = *a1; *v2; i = *v2 )
{
v5 = *a2;
if ( !*a2 )
break;
v6 = _ctype_toupper_loc();
if ( (*v6)[v5] != (*v6)[(char)i] )
return 0LL;
++v2;
++a2;
}
return *a2 == (char)i;
}

original_code:
static int ci_strequ(char *a,char *b)
{
  for ( ;*a != 0 && *b != 0; a++, b++) {
    if (toupper(*a) != toupper(*b)) return 0;
  }
  return (*a == *b);
}

canonical_original_code:
static int ci_strequ(char *a, char *b)
{
  for ( ;*a != 0 && *b != 0; a++, b++) {
    if (toupper(*a) != toupper(*b)) return 0;
  }
  return (*a == *b);
}

variable_types:
a
char *

variable_types:
b
char *


ProcessArgs

original_code:
void ProcessArgs(int argc, char **argv, Opt *options)
{
 Opt *p;
 while ( argc-- > 0 )
 {
  p = options;
  while ( p->option != ((void *)0) )
  {
   if ( strcmp(p->option, "*") == 0 ||
     ci_strequ(p->option,*argv) )
   {
    if ( p->arg )
    {
     (*p->process)( *argv, *(argv+1) );
     argv++;
     argc--;
    }
    else
     (*p->process)( *argv );
    break;
   }
   p++;
  }
  argv++;
 }
}

canonical_original_code:
void ProcessArgs(int argc, char **argv, struct Opt *options)
{
 struct Opt *p;
 while ( argc-- > 0 )
 {
  p = options;
  while ( p->option != ((void *)0) )
  {
   if ( strcmp(p->option, "*") == 0 ||
     ci_strequ(p->option,*argv) )
   {
    if ( p->arg )
    {
     (*p->process)( *argv, *(argv+1) );
     argv++;
     argc--;
    }
    else
     (*p->process)( *argv );
    break;
   }
   p++;
  }
  argv++;
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct Opt { char *option; int arg; void (*process)(); char *descr; } *


init

decompiled_code:
__int64 init()
{
void *v0; // rax
void *v1; // rdx
unsigned int i; // ebx
__int64 result; // rax

v0 = (void *)empty[0];
v1 = (void *)empty[1];
used_chars[0] = empty[0];
used_chars[1] = v1;
used_classes = v0;
*(&used_classes + 1) = v1;
normal_chars[0] = v0;
normal_chars[1] = v1;
for ( i = 1; i != 257; ++i )
set_orel(i, normal_chars);
make_nfa_model_node();
result = clear_hash();
func_action = 0;
return result;
}

canonical_decompiled_code:
__int64 func16()
{
void *v0; // rax
void *v1; // rdx
unsigned int i; // ebx
__int64 result; // rax

v0 = (void *)empty[0];
v1 = (void *)empty[1];
used_chars[0] = empty[0];
used_chars[1] = v1;
used_classes = v0;
*(&used_classes + 1) = v1;
normal_chars[0] = v0;
normal_chars[1] = v1;
for ( i = 1; i != 257; ++i )
set_orel(i, normal_chars);
make_nfa_model_node();
result = clear_hash();
func_action = 0;
return result;
}

original_code:
void
init(void)
{
 register int i;
 used_chars = empty;
 used_classes = empty;
 normal_chars = empty;
 for (i = 1; i<(1+(255) - ((-1))); ++i){
  set_orel(i,&normal_chars);
 }
 make_nfa_model_node();
 clear_hash();
    func_action = 0;
}

canonical_original_code:
void init()
{
 register int i;
 used_chars = empty;
 used_classes = empty;
 normal_chars = empty;
 for (i = 1; i<(1+(255) - ((-1))); ++i){
  set_orel(i,&normal_chars);
 }
 make_nfa_model_node();
 clear_hash();
    func_action = 0;
}

variable_types: i int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rax
int v5; // ebx
int v6; // eax
const char *v7; // rdx
char **v8; // rbx
const char *v9; // rcx
int v10; // eax
void *v11; // rdi

init(argc, argv, envp);
fprintf(stderr, "%s Version %s 1989-2001\n", program, version);
if ( argc == 1 )
{
fprintf(stderr, "%s [options] f1 f2 ... fn\n", *argv);
v7 = options;
if ( *options != 42 )
{
v8 = &options;
do
{
v9 = " ";
if ( *((_DWORD *)v8 + 2) )
v9 = "___";
fprintf(stderr, "\t%s %s\t%s\n", v7, v9, v8[3]);
v8 += 4;
v7 = *v8;
}
while ( **v8 != 42 );
}
}
else
{
ProcessArgs(argc - 1, (char **)argv + 1, (unsigned __int8 **)&options);
if ( interactive && gen_cpp )
fputc(10, stderr);
input_stream = read_stream(file_str[0]);
if ( input_stream )
{
if ( gen_cpp )
{
v3 = ClassName(".cpp");
output_stream = (FILE *)write_stream(v3);
if ( file_str[1] )
warning("output file implicit in C++ mode; ignored...", 0LL);
v4 = ClassName(".h");
class_stream = (FILE *)write_stream(v4);
mode_stream = class_stream;
}
else
{
output_stream = (FILE *)write_stream(file_str[1]);
mode_stream = (FILE *)write_stream(mode_file);
}
if ( input_stream )
{
if ( output_stream )
{
if ( mode_stream )
{
zzbufsize = (_DWORD)&unk_10000;
zzlextext = &zztoktext_0;
zzrdstream();
zzgettok();
v5 = zzasp;
grammar();
v6 = zzasp;
if ( v5 > zzasp )
{
do
{
v11 = (void *)zzaStack[5 * v6 + 4];
if ( v11 )
free(v11);
v10 = zzasp;
*(__m128i *)&zzaStack[5 * zzasp + 3] = _mm_loadu_si128((const __m128i *)empty);
v6 = v10 + 1;
zzasp = v6;
}
while ( v5 > v6 );
}
}
}
}
}
p_class_def2();
}
if ( output_stream )
fclose(output_stream);
if ( !gen_cpp && mode_stream )
fclose(mode_stream);
if ( class_stream )
fclose(class_stream);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rax
int v5; // ebx
int v6; // eax
const char *v7; // rdx
char **v8; // rbx
const char *v9; // rcx
int v10; // eax
void *v11; // rdi

func16(argc, argv, envp);
fprintf(stderr, "%s Version %s 1989-2001\n", program, version);
if ( argc == 1 )
{
fprintf(stderr, "%s [options] f1 f2 ... fn\n", *argv);
v7 = options;
if ( *options != 42 )
{
v8 = &options;
do
{
v9 = " ";
if ( *((_DWORD *)v8 + 2) )
v9 = "___";
fprintf(stderr, "\t%s %s\t%s\n", v7, v9, v8[3]);
v8 += 4;
v7 = *v8;
}
while ( **v8 != 42 );
}
}
else
{
func15(argc - 1, (char **)argv + 1, (unsigned __int8 **)&options);
if ( interactive && gen_cpp )
fputc(10, stderr);
input_stream = read_stream(file_str[0]);
if ( input_stream )
{
if ( gen_cpp )
{
v3 = ClassName(".cpp");
output_stream = (FILE *)write_stream(v3);
if ( file_str[1] )
warning("output file implicit in C++ mode; ignored...", 0LL);
v4 = ClassName(".h");
class_stream = (FILE *)write_stream(v4);
mode_stream = class_stream;
}
else
{
output_stream = (FILE *)write_stream(file_str[1]);
mode_stream = (FILE *)write_stream(mode_file);
}
if ( input_stream )
{
if ( output_stream )
{
if ( mode_stream )
{
zzbufsize = (_DWORD)&unk_10000;
zzlextext = &zztoktext_0;
zzrdstream();
zzgettok();
v5 = zzasp;
grammar();
v6 = zzasp;
if ( v5 > zzasp )
{
do
{
v11 = (void *)zzaStack[5 * v6 + 4];
if ( v11 )
free(v11);
v10 = zzasp;
*(__m128i *)&zzaStack[5 * zzasp + 3] = _mm_loadu_si128((const __m128i *)empty);
v6 = v10 + 1;
zzasp = v6;
}
while ( v5 > v6 );
}
}
}
}
}
p_class_def2();
}
if ( output_stream )
fclose(output_stream);
if ( !gen_cpp && mode_stream )
fclose(mode_stream);
if ( class_stream )
fclose(class_stream);
exit(0);
}

original_code:
int main(int argc, char *argv[])
{
 init();
 fprintf(stderr, "%s  Version %s   1989-2001\n", &(program[0]),
  &(version[0]));
 if ( argc == 1 )
 {
  Opt *p = options;
  fprintf(stderr, "%s [options] f1 f2 ... fn\n",argv[0]);
  while ( *(p->option) != '*' )
  {
   fprintf(stderr, "\t%s %s\t%s\n",
       p->option,
       (p->arg)?"___":"   ",
       p->descr);
   p++;
  }
 }else{
  ProcessArgs(argc-1, &(argv[1]), options);
  if (interactive && gen_cpp) {
   fprintf(stderr,"\n");
  }
  input_stream = read_stream(file_str[0]);
  if (input_stream) {
   if ( gen_cpp ) {
    output_stream = write_stream(ClassName(".cpp"));
    if ( file_str[1]!=((void *)0) ) {
     warning("output file implicit in C++ mode; ignored...",0);
    }
    class_stream = write_stream(ClassName(".h"));
    mode_stream = class_stream;
   }
   else {
    output_stream = write_stream(file_str[1]);
    mode_stream = write_stream(mode_file);
   }
  }
  if (input_stream && output_stream && mode_stream){
   zzbufsize = 65536; {static char zztoktext[65536]; zzlextext = zztoktext; zzrdstream( input_stream ); zzgettok();}; { int zztasp1 = zzasp - 1; grammar(); for (; zzasp<(zztasp1 + 1); zzasp++) { {if ( ((&(zzaStack[zzasp]))->label).setword != ((void *)0) ) free((char *)(((&(zzaStack[zzasp]))->label).setword)); ((&(zzaStack[zzasp]))->label) = empty;};; }; } ;;
  }
  p_class_def2();
 }
 if ( output_stream!=((void *)0) ) fclose(output_stream);
 if ( !gen_cpp && mode_stream!=((void *)0) ) fclose(mode_stream);
 if ( class_stream!=((void *)0) ) fclose(class_stream);
 exit(0);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 init();
 fprintf(stderr, "%s  Version %s   1989-2001\n", &(program[0]),
  &(version[0]));
 if ( argc == 1 )
 {
  struct Opt *p = options;
  fprintf(stderr, "%s [options] f1 f2 ... fn\n",argv[0]);
  while ( *(p->option) != '*' )
  {
   fprintf(stderr, "\t%s %s\t%s\n",
       p->option,
       (p->arg)?"___":"   ",
       p->descr);
   p++;
  }
 }else{
  ProcessArgs(argc-1, &(argv[1]), options);
  if (interactive && gen_cpp) {
   fprintf(stderr,"\n");
  }
  input_stream = read_stream(file_str[0]);
  if (input_stream) {
   if ( gen_cpp ) {
    output_stream = write_stream(ClassName(".cpp"));
    if ( file_str[1]!=((void *)0) ) {
     warning("output file implicit in C++ mode; ignored...",0);
    }
    class_stream = write_stream(ClassName(".h"));
    mode_stream = class_stream;
   }
   else {
    output_stream = write_stream(file_str[1]);
    mode_stream = write_stream(mode_file);
   }
  }
  if (input_stream && output_stream && mode_stream){
   zzbufsize = 65536; {static char zztoktext[65536]; zzlextext = zztoktext; zzrdstream( input_stream ); zzgettok();}; { int zztasp1 = zzasp - 1; grammar(); for (; zzasp<(zztasp1 + 1); zzasp++) { {if ( ((&(zzaStack[zzasp]))->label).setword != ((void *)0) ) free((char *)(((&(zzaStack[zzasp]))->label).setword)); ((&(zzaStack[zzasp]))->label) = empty;};; }; } ;;
  }
  p_class_def2();
 }
 if ( output_stream!=((void *)0) ) fclose(output_stream);
 if ( !gen_cpp && mode_stream!=((void *)0) ) fclose(mode_stream);
 if ( class_stream!=((void *)0) ) fclose(class_stream);
 exit(0);
 return 0;
}

variable_types:
argv
char *[]

variable_types:
zztoktext
char [65536]

user_defined_types: struct Opt { char *option; int arg; void (*process)(); char *descr; }


newHashTable

decompiled_code:
void *newHashTable()
{
void *v0; // rax
void *v1; // rbx
void *v3; // rax

v0 = calloc(0x229uLL, 8uLL);
if ( !v0 )
{
fprintf(stderr, "%s(%d):", "hash.c", 78LL);
fprintf(stderr, " %s\n", "cannot allocate hash table");
exit(1);
}
v1 = v0;
if ( !strings )
{
v3 = calloc(0xF4240uLL, 1uLL);
strings = (__int64)v3;
if ( !v3 )
{
fprintf(stderr, "%s(%d):", "hash.c", 82LL);
fprintf(stderr, " %s\n", "cannot allocate string table");
exit(1);
}
strp = (__int64)v3;
}
return v1;
}

canonical_decompiled_code:
void *func0()
{
void *v0; // rax
void *v1; // rbx
void *v3; // rax

v0 = calloc(0x229uLL, 8uLL);
if ( !v0 )
{
fprintf(stderr, "%s(%d):", "hash.c", 78LL);
fprintf(stderr, " %s\n", "cannot allocate hash table");
exit(1);
}
v1 = v0;
if ( !strings )
{
v3 = calloc(0xF4240uLL, 1uLL);
strings = (__int64)v3;
if ( !v3 )
{
fprintf(stderr, "%s(%d):", "hash.c", 82LL);
fprintf(stderr, " %s\n", "cannot allocate string table");
exit(1);
}
strp = (__int64)v3;
}
return v1;
}

original_code:
Entry **
newHashTable( void )
{
 Entry **table;
 table = (Entry **) calloc(size, sizeof(Entry *));
 {if ( !(table != ((void *)0)) ) {fprintf(stderr, "%s(%d):", "hash.c", 78); fprintf(stderr, " %s\n", "cannot allocate hash table"); exit(1);};};
 if ( strings == ((void *)0) )
 {
  strings = (char *) calloc(strsize, sizeof(char));
  {if ( !(strings != ((void *)0)) ) {fprintf(stderr, "%s(%d):", "hash.c", 82); fprintf(stderr, " %s\n", "cannot allocate string table"); exit(1);};};
  strp = strings;
 }
 return table;
}

canonical_original_code:
struct _entry **newHashTable()
{
 struct _entry **table;
 table = (struct _entry **) calloc(size, sizeof(struct _entry *));
 {if ( !(table != ((void *)0)) ) {fprintf(stderr, "%s(%d):", "hash.c", 78); fprintf(stderr, " %s\n", "cannot allocate hash table"); exit(1);};};
 if ( strings == ((void *)0) )
 {
  strings = (char *) calloc(strsize, sizeof(char));
  {if ( !(strings != ((void *)0)) ) {fprintf(stderr, "%s(%d):", "hash.c", 82); fprintf(stderr, " %s\n", "cannot allocate string table"); exit(1);};};
  strp = strings;
 }
 return table;
}

variable_types: struct _entry { char *str; struct _entry *next; } **


killHashTable

decompiled_code:
void __fastcall killHashTable(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
free(a1);
}

original_code:
void
killHashTable( Entry **table )
{
 free( (char *) table );
}

canonical_original_code:
void killHashTable(struct _entry **table)
{
 free( (char *) table );
}

user_defined_types: struct _entry { char *str; struct _entry *next; }


decompiled_code:
__int64 __fastcall hash_add(__int64 a1, char *a2, __int64 a3)
{
char v4; // al
unsigned int i; // edx
_QWORD *v6; // rax

if ( a3 == 0 || a1 == 0 || !a2 )
{
fprintf(stderr, "%s(%d):", "hash.c", 113LL);
fprintf(stderr, " %s\n", "add: invalid addition");
exit(1);
}
v4 = *a2;
for ( i = 0; *a2; v4 = *a2 )
{
++a2;
i = v4 + 2 * i;
}
v6 = (_QWORD *)(a1 + 8LL * (i % 0x229));
*(_QWORD *)(a3 + 8) = *v6;
*v6 = a3;
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, __int64 a3)
{
char v4; // al
unsigned int i; // edx
_QWORD *v6; // rax

if ( a3 == 0 || a1 == 0 || !a2 )
{
fprintf(stderr, "%s(%d):", "hash.c", 113LL);
fprintf(stderr, " %s\n", "add: invalid addition");
exit(1);
}
v4 = *a2;
for ( i = 0; *a2; v4 = *a2 )
{
++a2;
i = v4 + 2 * i;
}
v6 = (_QWORD *)(a1 + 8LL * (i % 0x229));
*(_QWORD *)(a3 + 8) = *v6;
*v6 = a3;
return a3;
}

original_code:
Entry *
hash_add( Entry **table, char *key, Entry *rec )
{
 unsigned h=0;
 char *p=key;
 {if ( !(table!=((void *)0) && key!=((void *)0) && rec!=((void *)0)) ) {fprintf(stderr, "%s(%d):", "hash.c", 113); fprintf(stderr, " %s\n", "add: invalid addition"); exit(1);};};
 {while ( *p != '\0' ) h = (h<<1) + *p++; h %= size;};
 rec->next = table[h];
 table[h] = rec;
 return rec;
}

canonical_original_code:
struct _entry *hash_add(struct _entry **table, char *key, struct _entry *rec)
{
 unsigned int h = 0;
 char *p = key;
 {if ( !(table!=((void *)0) && key!=((void *)0) && rec!=((void *)0)) ) {fprintf(stderr, "%s(%d):", "hash.c", 113); fprintf(stderr, " %s\n", "add: invalid addition"); exit(1);};};
 {while ( *p != '\0' ) h = (h<<1) + *p++; h %= size;};
 rec->next = table[h];
 table[h] = rec;
 return rec;
}

variable_types:
table
struct _entry **

variable_types:
key
char *

variable_types:
rec
struct _entry *

variable_types:
h
unsigned int

variable_types:
p
char *

return_type: struct _entry { char *str; struct _entry *next; } *


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall hash_get(__int64 a1, const char *a2)
{
char v2; // al
char *v3; // rdx
unsigned int v4; // ecx
__int64 i; // rbx

if ( !a1 || !a2 )
loc_22 = 3;
v2 = *a2;
if ( *a2 )
{
v3 = (char *)a2;
v4 = 0;
do
{
++v3;
v4 = v2 + 2 * v4;
v2 = *v3;
}
while ( *v3 );
}
else
{
v4 = 0;
}
for ( i = *(_QWORD *)(a1 + 8LL * (v4 % 0x229)); i; i = *(_QWORD *)(i + 8) )
{
if ( !strcmp(a2, *(const char **)i) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
char v2; // al
char *v3; // rdx
unsigned int v4; // ecx
__int64 i; // rbx

if ( !a1 || !a2 )
loc_22 = 3;
v2 = *a2;
if ( *a2 )
{
v3 = (char *)a2;
v4 = 0;
do
{
++v3;
v4 = v2 + 2 * v4;
v2 = *v3;
}
while ( *v3 );
}
else
{
v4 = 0;
}
for ( i = *(_QWORD *)(a1 + 8LL * (v4 % 0x229)); i; i = *(_QWORD *)(i + 8) )
{
if ( !strcmp(a2, *(const char **)i) )
break;
}
return i;
}

original_code:
Entry *
hash_get( Entry **table, char *key )
{
 unsigned h=0;
 char *p=key;
 Entry *q;
 if ( !(table!=((void *)0) && key!=((void *)0)) ) *((char *) 34) = 3;
 {while ( *p != '\0' ) h = (h<<1) + *p++; h %= size;};
 for (q = table[h]; q != ((void *)0); q = q->next)
 {
  if ( strcmp(key, q->str) == 0 ) return( q );
 }
 return( ((void *)0) );
}

canonical_original_code:
struct _entry *hash_get(struct _entry **table, char *key)
{
 unsigned int h = 0;
 char *p = key;
 struct _entry *q;
 if ( !(table!=((void *)0) && key!=((void *)0)) ) *((char *) 34) = 3;
 {while ( *p != '\0' ) h = (h<<1) + *p++; h %= size;};
 for (q = table[h]; q != ((void *)0); q = q->next)
 {
  if ( strcmp(key, q->str) == 0 ) return( q );
 }
 return( ((void *)0) );
}

variable_types: struct _entry { char *str; struct _entry *next; } *


mystrdup

decompiled_code:
__int64 __fastcall mystrdup(char *a1)
{
__int64 v1; // r9
char v2; // dl
unsigned __int64 v3; // rcx
_BYTE *v4; // rax
char v5; // si
_BYTE *v6; // rax

v1 = strp;
if ( !a1 )
{
fprintf(stderr, "%s(%d):", "hash.c", 210LL);
fprintf(stderr, " %s\n", "mystrdup: NULL string");
exit(1);
}
v2 = *a1;
if ( *a1 )
{
v3 = strings + 999998;
v4 = (_BYTE *)strp;
v5 = 0;
do
{
if ( v3 < (unsigned __int64)v4 )
{
if ( v5 )
strp = (__int64)v4;
fprintf(stderr, "%s(%d):", "hash.c", 214LL);
fprintf(stderr, " %s\n", "string table overflow\nIncrease StrTableSize in hash.h and recompile hash.c\n");
exit(1);
}
++a1;
*v4++ = v2;
v2 = *a1;
v5 = 1;
}
while ( *a1 );
strp = (__int64)v4;
}
v6 = (_BYTE *)strp++;
*v6 = 0;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
__int64 v1; // r9
char v2; // dl
unsigned __int64 v3; // rcx
_BYTE *v4; // rax
char v5; // si
_BYTE *v6; // rax

v1 = strp;
if ( !a1 )
{
fprintf(stderr, "%s(%d):", "hash.c", 210LL);
fprintf(stderr, " %s\n", "mystrdup: NULL string");
exit(1);
}
v2 = *a1;
if ( *a1 )
{
v3 = strings + 999998;
v4 = (_BYTE *)strp;
v5 = 0;
do
{
if ( v3 < (unsigned __int64)v4 )
{
if ( v5 )
strp = (__int64)v4;
fprintf(stderr, "%s(%d):", "hash.c", 214LL);
fprintf(stderr, " %s\n", "string table overflow\nIncrease StrTableSize in hash.h and recompile hash.c\n");
exit(1);
}
++a1;
*v4++ = v2;
v2 = *a1;
v5 = 1;
}
while ( *a1 );
strp = (__int64)v4;
}
v6 = (_BYTE *)strp++;
*v6 = 0;
return v1;
}

original_code:
char *
mystrdup( char *s )
{
 char *start=strp;
 {if ( !(s!=((void *)0)) ) {fprintf(stderr, "%s(%d):", "hash.c", 210); fprintf(stderr, " %s\n", "mystrdup: NULL string"); exit(1);};};
 while ( *s != '\0' )
 {
  {if ( !(strp <= &(strings[strsize-2])) ) {fprintf(stderr, "%s(%d):", "hash.c", 214); fprintf(stderr, " %s\n", "string table overflow\nIncrease StrTableSize in hash.h and recompile hash.c\n"); exit(1);};};
  *strp++ = *s++;
 }
 *strp++ = '\0';
 return( start );
}

canonical_original_code:
char *mystrdup(char *s)
{
 char *start = strp;
 {if ( !(s!=((void *)0)) ) {fprintf(stderr, "%s(%d):", "hash.c", 210); fprintf(stderr, " %s\n", "mystrdup: NULL string"); exit(1);};};
 while ( *s != '\0' )
 {
  {if ( !(strp <= &(strings[strsize-2])) ) {fprintf(stderr, "%s(%d):", "hash.c", 214); fprintf(stderr, " %s\n", "string table overflow\nIncrease StrTableSize in hash.h and recompile hash.c\n"); exit(1);};};
  *strp++ = *s++;
 }
 *strp++ = '\0';
 return( start );
}

variable_types:
s
char *

variable_types:
start
char *

return_type: char *


GetLength

decompiled_code:
__int64 __fastcall GetLength(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1 & 0xFFFFFF;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1 & 0xFFFFFF;
else
result = 0LL;
return result;
}

original_code:
UINT32
GetLength (
  UINT8 *ThreeByteLength
  )
{
  UINT32 Length;
  if (ThreeByteLength == ((void *)0)) {
    return 0;
  }
  Length = *((UINT32 *) ThreeByteLength);
  Length = Length & 0x00FFFFFF;
  return Length;
}

canonical_original_code:
unsigned int GetLength(unsigned char *ThreeByteLength)
{
  unsigned int Length;
  if (ThreeByteLength == ((void *)0)) {
    return 0;
  }
  Length = *((unsigned int *) ThreeByteLength);
  Length = Length & 0x00FFFFFF;
  return Length;
}

variable_types:
ThreeByteLength
unsigned char *

variable_types:
Length
unsigned int

return_type: unsigned int


GetFileState

decompiled_code:
unsigned __int8 __fastcall GetFileState(char a1, __int64 a2)
{
char v2; // dl
unsigned __int8 result; // al

v2 = *(_BYTE *)(a2 + 23);
if ( a1 )
v2 = ~*(_BYTE *)(a2 + 23);
result = 64;
if ( v2 < 0 )
return 0x80;
do
{
if ( (result & (unsigned __int8)v2) != 0 )
break;
result >>= 1;
}
while ( result );
return result;
}

canonical_decompiled_code:
unsigned __int8 __fastcall func11(char a1, __int64 a2)
{
char v2; // dl
unsigned __int8 result; // al

v2 = *(_BYTE *)(a2 + 23);
if ( a1 )
v2 = ~*(_BYTE *)(a2 + 23);
result = 64;
if ( v2 < 0 )
return 0x80;
do
{
if ( (result & (unsigned __int8)v2) != 0 )
break;
result >>= 1;
}
while ( result );
return result;
}

original_code:
UINT8
GetFileState (
  BOOLEAN ErasePolarity,
  EFI_FFS_FILE_HEADER *FfsHeader
  )
{
  UINT8 FileState;
  UINT8 HighestBit;
  FileState = FfsHeader->State;
  if (ErasePolarity) {
    FileState = (UINT8)~FileState;
  }
  HighestBit = 0x80;
  while (HighestBit != 0 && (HighestBit & FileState) == 0) {
    HighestBit >>= 1;
  }
  return HighestBit;
}

canonical_original_code:
unsigned char GetFileState(unsigned char ErasePolarity, struct EFI_FFS_FILE_HEADER *FfsHeader)
{
  unsigned char FileState;
  unsigned char HighestBit;
  FileState = FfsHeader->State;
  if (ErasePolarity) {
    FileState = (unsigned char)~FileState;
  }
  HighestBit = 0x80;
  while (HighestBit != 0 && (HighestBit & FileState) == 0) {
    HighestBit >>= 1;
  }
  return HighestBit;
}

variable_types:
ErasePolarity
unsigned char

variable_types: struct EFI_FFS_FILE_HEADER { struct EFI_GUID { unsigned int Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8]; } Name; union EFI_FFS_INTEGRITY_CHECK { struct { unsigned char Header; unsigned char File; } Checksum; unsigned short Checksum16; } IntegrityCheck; unsigned char Type; unsigned char Attributes; unsigned char Size[3]; unsigned char State; } *

variable_types:
FileState
unsigned char

variable_types:
HighestBit
unsigned char

user_defined_types: struct EFI_FFS_FILE_HEADER { struct EFI_GUID Name; union EFI_FFS_INTEGRITY_CHECK IntegrityCheck; unsigned char Type; unsigned char Attributes; unsigned char Size[3]; unsigned char State; }


OsPathPeerFilePath

decompiled_code:
char *__fastcall OsPathPeerFilePath(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rax
char *v5; // rbx
size_t v6; // rax
char v7; // dl

v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
v5 = v4;
if ( v4 )
{
strcpy(v4, src);
v6 = strlen(v5);
while ( 1 )
{
v7 = v5[v6];
if ( v7 == 47 || v7 == 92 )
break;
if ( (--v6 & 0x8000000000000000LL) != 0LL )
{
strcpy(v5, a2);
return v5;
}
}
v5[v6 + 1] = 0;
strcat(v5, a2);
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func0(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rax
char *v5; // rbx
size_t v6; // rax
char v7; // dl

v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
v5 = v4;
if ( v4 )
{
strcpy(v4, src);
v6 = strlen(v5);
while ( 1 )
{
v7 = v5[v6];
if ( v7 == 47 || v7 == 92 )
break;
if ( (--v6 & 0x8000000000000000LL) != 0LL )
{
strcpy(v5, a2);
return v5;
}
}
v5[v6 + 1] = 0;
strcat(v5, a2);
}
return v5;
}

original_code:
CHAR8*
OsPathPeerFilePath (
  CHAR8 *OldPath,
  CHAR8 *Peer
  )
{
  CHAR8 *Result;
  INTN Offset;
  Result = (CHAR8 *) malloc (strlen (OldPath) + strlen (Peer) + 1);
  if (Result == ((void *)0)) {
    return ((void *)0);
  }
  strcpy (Result, OldPath);
  for (Offset = strlen (Result); Offset >= 0; Offset--) {
    if ((Result[Offset] == '/') || (Result[Offset] == '\\')) {
      Result[Offset + 1] = '\0';
      strcat (Result, Peer);
      return Result;
    }
  }
  strcpy (Result, Peer);
  return Result;
}

canonical_original_code:
char *OsPathPeerFilePath(char *OldPath, char *Peer)
{
  char *Result;
  int Offset;
  Result = (char *) malloc (strlen (OldPath) + strlen (Peer) + 1);
  if (Result == ((void *)0)) {
    return ((void *)0);
  }
  strcpy (Result, OldPath);
  for (Offset = strlen (Result); Offset >= 0; Offset--) {
    if ((Result[Offset] == '/') || (Result[Offset] == '\\')) {
      Result[Offset + 1] = '\0';
      strcat (Result, Peer);
      return Result;
    }
  }
  strcpy (Result, Peer);
  return Result;
}

variable_types:
OldPath
char *

variable_types:
Peer
char *

variable_types:
Result
char *

variable_types: Offset int


LookupGuidedSectionToolPath

decompiled_code:
__int64 __fastcall LookupGuidedSectionToolPath(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = a1;
if ( !a1 )
return 0LL;
while ( CompareGuid(v2, a2) )
{
v2 = *(_QWORD *)(v2 + 32);
if ( !v2 )
return 0LL;
}
return CloneString(*(_QWORD *)(v2 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = a1;
if ( !a1 )
return 0LL;
while ( CompareGuid(v2, a2) )
{
v2 = *(_QWORD *)(v2 + 32);
if ( !v2 )
return 0LL;
}
return CloneString(*(_QWORD *)(v2 + 24));
}

original_code:
CHAR8*
LookupGuidedSectionToolPath (
  EFI_HANDLE ParsedGuidedSectionToolsHandle,
  EFI_GUID *SectionGuid
  )
{
  GUID_SEC_TOOL_ENTRY *GuidTool;
  GuidTool = (GUID_SEC_TOOL_ENTRY*)ParsedGuidedSectionToolsHandle;
  if (GuidTool == ((void *)0)) {
    return ((void *)0);
  }
  for ( ; GuidTool != ((void *)0); GuidTool = GuidTool->Next) {
    if (CompareGuid (&(GuidTool->Guid), SectionGuid) == 0) {
      return CloneString (GuidTool->Path);
    }
  }
  return ((void *)0);
}

canonical_original_code:
char *LookupGuidedSectionToolPath(void *ParsedGuidedSectionToolsHandle, struct EFI_GUID *SectionGuid)
{
  struct _GUID_SEC_TOOL_ENTRY *GuidTool;
  GuidTool = (struct _GUID_SEC_TOOL_ENTRY *)ParsedGuidedSectionToolsHandle;
  if (GuidTool == ((void *)0)) {
    return ((void *)0);
  }
  for ( ; GuidTool != ((void *)0); GuidTool = GuidTool->Next) {
    if (CompareGuid (&(GuidTool->Guid), SectionGuid) == 0) {
      return CloneString (GuidTool->Path);
    }
  }
  return ((void *)0);
}

variable_types:
ParsedGuidedSectionToolsHandle
void *

variable_types: struct EFI_GUID { unsigned int Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8]; } *

variable_types: struct _GUID_SEC_TOOL_ENTRY { struct EFI_GUID { unsigned int Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8]; } Guid; char *Name; char *Path; struct _GUID_SEC_TOOL_ENTRY *Next; } *

user_defined_types: struct _GUID_SEC_TOOL_ENTRY { struct EFI_GUID Guid; char *Name; char *Path; struct _GUID_SEC_TOOL_ENTRY *Next; }


original_code:
void *
sstack_pop( SStack **st )
{
  SStack *p = *st;
  void *r;
  *st = (*st)->next;
  r = p->elem;
  free(p);
  return r;
}

canonical_original_code:
void *sstack_pop(struct _SList **st)
{
  struct _SList *p = *st;
  void *r;
  *st = (*st)->next;
  r = p->elem;
  free(p);
  return r;
}

variable_types: struct _SList { void *elem; struct _SList *next; } **

variable_types:
r
void *


MyCheck

decompiled_code:
void __fastcall MyCheck(unsigned __int8 a1, const char *a2, unsigned int a3)
{
__int64 v4; // r15
__int64 v5; // rbx
unsigned int *v6; // rbp
__int64 i; // rbx

if ( !a2 || !a3 )
{
printf("\nMyCheck(Final=%u, File=%s, Line=%u)Invalid parameter(s).\n", a1, a2, a3);
exit(1);
}
if ( !*a2 )
{
printf("\nMyCheck(Final=%u, File=%s, Line=%u)Invalid parameter.\n", a1, a2, a3);
exit(1);
}
v4 = MyAllocData;
if ( MyAllocData )
{
v5 = MyAllocData;
do
{
v6 = *(unsigned int **)(v5 + 32);
if ( memcmp(v6, &MyAllocHeadMagik, 4uLL)
|| memcmp((char *)v6 + *(unsigned int *)(v5 + 20) + 4, &MyAllocTailMagik, 4uLL) )
{
printf(
"\n"
"MyCheck(Final=%u, File=%s, Line=%u)\n"
"Structure corrupted!\n"
"File=%s, Line=%u, nSize=%u, Head=%xh, Tail=%xh\n",
a1,
a2,
a3,
*(const char **)(v5 + 24),
*(unsigned int *)(v5 + 16),
*(unsigned int *)(v5 + 20),
*v6,
*(unsigned int *)((char *)v6 + *(unsigned int *)(v5 + 20) + 4));
exit(1);
}
v5 = *(_QWORD *)(v5 + 8);
}
while ( v5 );
if ( v4 )
{
if ( a1 )
{
printf("\nMyCheck(Final=%u, File=%s, Line=%u)\nSome allocated items have not been freed.\n", a1, a2, a3);
for ( i = MyAllocData; i; i = *(_QWORD *)(i + 8) )
printf(
"File=%s, Line=%u, nSize=%u, Head=%xh, Tail=%xh\n",
*(const char **)(i + 24),
*(unsigned int *)(i + 16),
*(unsigned int *)(i + 20),
**(unsigned int **)(i + 32),
*(unsigned int *)(*(_QWORD *)(i + 32) + *(unsigned int *)(i + 20) + 4LL));
}
}
}
}

canonical_decompiled_code:
void __fastcall func0(unsigned __int8 a1, const char *a2, unsigned int a3)
{
__int64 v4; // r15
__int64 v5; // rbx
unsigned int *v6; // rbp
__int64 i; // rbx

if ( !a2 || !a3 )
{
printf("\nMyCheck(Final=%u, File=%s, Line=%u)Invalid parameter(s).\n", a1, a2, a3);
exit(1);
}
if ( !*a2 )
{
printf("\nMyCheck(Final=%u, File=%s, Line=%u)Invalid parameter.\n", a1, a2, a3);
exit(1);
}
v4 = MyAllocData;
if ( MyAllocData )
{
v5 = MyAllocData;
do
{
v6 = *(unsigned int **)(v5 + 32);
if ( memcmp(v6, &MyAllocHeadMagik, 4uLL)
|| memcmp((char *)v6 + *(unsigned int *)(v5 + 20) + 4, &MyAllocTailMagik, 4uLL) )
{
printf(
"\n"
"MyCheck(Final=%u, File=%s, Line=%u)\n"
"Structure corrupted!\n"
"File=%s, Line=%u, nSize=%u, Head=%xh, Tail=%xh\n",
a1,
a2,
a3,
*(const char **)(v5 + 24),
*(unsigned int *)(v5 + 16),
*(unsigned int *)(v5 + 20),
*v6,
*(unsigned int *)((char *)v6 + *(unsigned int *)(v5 + 20) + 4));
exit(1);
}
v5 = *(_QWORD *)(v5 + 8);
}
while ( v5 );
if ( v4 )
{
if ( a1 )
{
printf("\nMyCheck(Final=%u, File=%s, Line=%u)\nSome allocated items have not been freed.\n", a1, a2, a3);
for ( i = MyAllocData; i; i = *(_QWORD *)(i + 8) )
printf(
"File=%s, Line=%u, nSize=%u, Head=%xh, Tail=%xh\n",
*(const char **)(i + 24),
*(unsigned int *)(i + 16),
*(unsigned int *)(i + 20),
**(unsigned int **)(i + 32),
*(unsigned int *)(*(_QWORD *)(i + 32) + *(unsigned int *)(i + 20) + 4LL));
}
}
}
}

original_code:
void
MyCheck (
  BOOLEAN Final,
  UINT8 File[],
  UINTN Line
  )
{
  MY_ALLOC_STRUCT *Tmp;
  if (File == ((void *)0) || Line == 0) {
    printf (
      "\nMyCheck(Final=%u, File=%s, Line=%u)"
      "Invalid parameter(s).\n",
      Final,
      File,
      (unsigned)Line
      );
    exit (1);
  }
  if (strlen ((CHAR8 *)File) == 0) {
    printf (
      "\nMyCheck(Final=%u, File=%s, Line=%u)"
      "Invalid parameter.\n",
      Final,
      File,
      (unsigned)Line
      );
    exit (1);
  }
  for (Tmp = MyAllocData; Tmp != ((void *)0); Tmp = Tmp->Next) {
    if (memcmp(Tmp->Buffer, &MyAllocHeadMagik, sizeof MyAllocHeadMagik) ||
        memcmp(&Tmp->Buffer[Tmp->Size + sizeof(UINT32)], &MyAllocTailMagik, sizeof MyAllocTailMagik)) {
      break;
    }
  }
  if (Tmp != ((void *)0)) {
    printf (
      "\nMyCheck(Final=%u, File=%s, Line=%u)""\nStructure corrupted!"
      "\nFile=%s, Line=%u, nSize=%u, Head=%xh, Tail=%xh\n",
      Final,
      File,
      (unsigned)Line,
      Tmp->File,
      (unsigned) Tmp->Line,
      (unsigned) Tmp->Size,
      (unsigned) *(UINT32 *) (Tmp->Buffer),
      (unsigned) *(UINT32 *) (&Tmp->Buffer[Tmp->Size + sizeof (UINT32)])
      );
    exit (1);
  }
  if (Final) {
    if (MyAllocData != ((void *)0)) {
      printf (
        "\nMyCheck(Final=%u, File=%s, Line=%u)"
        "\nSome allocated items have not been freed.\n",
        Final,
        File,
        (unsigned)Line
        );
      for (Tmp = MyAllocData; Tmp != ((void *)0); Tmp = Tmp->Next) {
        printf (
          "File=%s, Line=%u, nSize=%u, Head=%xh, Tail=%xh\n",
          Tmp->File,
          (unsigned) Tmp->Line,
          (unsigned) Tmp->Size,
          (unsigned) *(UINT32 *) (Tmp->Buffer),
          (unsigned) *(UINT32 *) (&Tmp->Buffer[Tmp->Size + sizeof (UINT32)])
          );
      }
    }
  }
}

canonical_original_code:
void MyCheck(unsigned char Final, unsigned char File[], unsigned long Line)
{
  struct MyAllocStruct *Tmp;
  if (File == ((void *)0) || Line == 0) {
    printf (
      "\nMyCheck(Final=%u, File=%s, Line=%u)"
      "Invalid parameter(s).\n",
      Final,
      File,
      (unsigned int)Line
      );
    exit (1);
  }
  if (strlen ((char *)File) == 0) {
    printf (
      "\nMyCheck(Final=%u, File=%s, Line=%u)"
      "Invalid parameter.\n",
      Final,
      File,
      (unsigned int)Line
      );
    exit (1);
  }
  for (Tmp = MyAllocData; Tmp != ((void *)0); Tmp = Tmp->Next) {
    if (memcmp(Tmp->Buffer, &MyAllocHeadMagik, sizeof MyAllocHeadMagik) ||
        memcmp(&Tmp->Buffer[Tmp->Size + sizeof(UINT32)], &MyAllocTailMagik, sizeof MyAllocTailMagik)) {
      break;
    }
  }
  if (Tmp != ((void *)0)) {
    printf (
      "\nMyCheck(Final=%u, File=%s, Line=%u)""\nStructure corrupted!"
      "\nFile=%s, Line=%u, nSize=%u, Head=%xh, Tail=%xh\n",
      Final,
      File,
      (unsigned int)Line,
      Tmp->File,
      (unsigned int) Tmp->Line,
      (unsigned int) Tmp->Size,
      (unsigned int) *(unsigned int *) (Tmp->Buffer),
      (unsigned int) *(unsigned int *) (&Tmp->Buffer[Tmp->Size + sizeof (UINT32)])
      );
    exit (1);
  }
  if (Final) {
    if (MyAllocData != ((void *)0)) {
      printf (
        "\nMyCheck(Final=%u, File=%s, Line=%u)"
        "\nSome allocated items have not been freed.\n",
        Final,
        File,
        (unsigned int)Line
        );
      for (Tmp = MyAllocData; Tmp != ((void *)0); Tmp = Tmp->Next) {
        printf (
          "File=%s, Line=%u, nSize=%u, Head=%xh, Tail=%xh\n",
          Tmp->File,
          (unsigned int) Tmp->Line,
          (unsigned int) Tmp->Size,
          (unsigned int) *(unsigned int *) (Tmp->Buffer),
          (unsigned int) *(unsigned int *) (&Tmp->Buffer[Tmp->Size + sizeof (UINT32)])
          );
      }
    }
  }
}

variable_types:
Final
unsigned char

variable_types:
File
unsigned char []

variable_types:
Line
unsigned long

variable_types: struct MyAllocStruct { unsigned long Cksum; struct MyAllocStruct *Next; unsigned long Line; unsigned long Size; unsigned char *File; unsigned char *Buffer; } *


MyRealloc

decompiled_code:
__int64 __fastcall MyRealloc(const void *a1, unsigned int a2, const char *a3, unsigned int a4)
{
unsigned int v4; // ebx
__int64 v5; // r13
void *v6; // rax
void *v7; // r12
__int64 i; // rax

v4 = a2;
if ( a4 == 0 || a3 == 0LL || !a2 )
{
printf("\nMyRealloc(Ptr=%p, Size=%u, File=%s, Line=%u)\nInvalid parameter(s).\n", a1, a2, a3, a4);
exit(1);
}
if ( !*a3 )
{
printf("\nMyRealloc(Ptr=%p, Size=%u, File=%s, Line=%u)\nInvalid parameter.\n", a1, a2, a3, a4);
exit(1);
}
if ( !a1 )
return MyAlloc(a2, a3, a4);
v5 = MyAllocData;
if ( a1 != (const void *)(*(_QWORD *)(MyAllocData + 32) + 4LL) )
{
for ( i = *(_QWORD *)(MyAllocData + 8); i; i = *(_QWORD *)(*(_QWORD *)(i + 8) + 8LL) )
;
printf("\nMyRealloc(Ptr=%p, Size=%u, File=%s, Line=%u)\nCould not find buffer.\n", a1, a2, a3, a4);
exit(1);
}
v6 = (void *)MyAlloc(a2, a3, a4);
v7 = v6;
if ( v6 )
{
if ( *(_DWORD *)(v5 + 20) <= a2 )
v4 = *(_DWORD *)(v5 + 20);
memcpy(v6, (const void *)(*(_QWORD *)(v5 + 32) + 4LL), v4);
MyFree(a1, "MyAlloc.c", 0x177u);
}
return (__int64)v7;
}

canonical_decompiled_code:
__int64 __fastcall func3(const void *a1, unsigned int a2, const char *a3, unsigned int a4)
{
unsigned int v4; // ebx
__int64 v5; // r13
void *v6; // rax
void *v7; // r12
__int64 i; // rax

v4 = a2;
if ( a4 == 0 || a3 == 0LL || !a2 )
{
printf("\nMyRealloc(Ptr=%p, Size=%u, File=%s, Line=%u)\nInvalid parameter(s).\n", a1, a2, a3, a4);
exit(1);
}
if ( !*a3 )
{
printf("\nMyRealloc(Ptr=%p, Size=%u, File=%s, Line=%u)\nInvalid parameter.\n", a1, a2, a3, a4);
exit(1);
}
if ( !a1 )
return func1(a2, a3, a4);
v5 = MyAllocData;
if ( a1 != (const void *)(*(_QWORD *)(MyAllocData + 32) + 4LL) )
{
for ( i = *(_QWORD *)(MyAllocData + 8); i; i = *(_QWORD *)(*(_QWORD *)(i + 8) + 8LL) )
;
printf("\nMyRealloc(Ptr=%p, Size=%u, File=%s, Line=%u)\nCould not find buffer.\n", a1, a2, a3, a4);
exit(1);
}
v6 = (void *)func1(a2, a3, a4);
v7 = v6;
if ( v6 )
{
if ( *(_DWORD *)(v5 + 20) <= a2 )
v4 = *(_DWORD *)(v5 + 20);
memcpy(v6, (const void *)(*(_QWORD *)(v5 + 32) + 4LL), v4);
func2(a1, "MyAlloc.c", 0x177u);
}
return (__int64)v7;
}

original_code:
void *
MyRealloc (
  void *Ptr,
  UINTN Size,
  UINT8 File[],
  UINTN Line
  )
{
  MY_ALLOC_STRUCT *Tmp;
  void *Buffer;
  if (Size == 0 || File == ((void *)0) || Line == 0) {
    printf (
      "\nMyRealloc(Ptr=%p, Size=%u, File=%s, Line=%u)"
      "\nInvalid parameter(s).\n",
      Ptr,
      (unsigned)Size,
      File,
      (unsigned)Line
      );
    exit (1);
  }
  if (strlen ((CHAR8 *)File) == 0) {
    printf (
      "\nMyRealloc(Ptr=%p, Size=%u, File=%s, Line=%u)"
      "\nInvalid parameter.\n",
      Ptr,
      (unsigned)Size,
      File,
      (unsigned)Line
      );
    exit (1);
  }
  if (Ptr == ((void *)0)) {
    Tmp = ((void *)0);
  } else if (&MyAllocData->Buffer[sizeof (UINT32)] == Ptr) {
    Tmp = MyAllocData;
  } else {
    for (Tmp = MyAllocData;; Tmp = Tmp->Next) {
      if (Tmp->Next == ((void *)0)) {
        printf (
          "\nMyRealloc(Ptr=%p, Size=%u, File=%s, Line=%u)"
          "\nCould not find buffer.\n",
          Ptr,
          (unsigned)Size,
          File,
          (unsigned)Line
          );
        exit (1);
      }
      Tmp = Tmp->Next;
    }
  }
  Buffer = MyAlloc (Size, File, Line);
  if (Buffer != ((void *)0) && Tmp != ((void *)0)) {
    memcpy (
      Buffer,
      &Tmp->Buffer[sizeof (UINT32)],
      ((Size <= Tmp->Size) ? Size : Tmp->Size)
      );
    MyFree (Ptr, (UINT8 *)"MyAlloc.c", 375);
  }
  return Buffer;
}

canonical_original_code:
void *MyRealloc(void *Ptr, unsigned long Size, unsigned char File[], unsigned long Line)
{
  struct MyAllocStruct *Tmp;
  void *Buffer;
  if (Size == 0 || File == ((void *)0) || Line == 0) {
    printf (
      "\nMyRealloc(Ptr=%p, Size=%u, File=%s, Line=%u)"
      "\nInvalid parameter(s).\n",
      Ptr,
      (unsigned int)Size,
      File,
      (unsigned int)Line
      );
    exit (1);
  }
  if (strlen ((char *)File) == 0) {
    printf (
      "\nMyRealloc(Ptr=%p, Size=%u, File=%s, Line=%u)"
      "\nInvalid parameter.\n",
      Ptr,
      (unsigned int)Size,
      File,
      (unsigned int)Line
      );
    exit (1);
  }
  if (Ptr == ((void *)0)) {
    Tmp = ((void *)0);
  } else if (&MyAllocData->Buffer[sizeof (UINT32)] == Ptr) {
    Tmp = MyAllocData;
  } else {
    for (Tmp = MyAllocData;; Tmp = Tmp->Next) {
      if (Tmp->Next == ((void *)0)) {
        printf (
          "\nMyRealloc(Ptr=%p, Size=%u, File=%s, Line=%u)"
          "\nCould not find buffer.\n",
          Ptr,
          (unsigned int)Size,
          File,
          (unsigned int)Line
          );
        exit (1);
      }
      Tmp = Tmp->Next;
    }
  }
  Buffer = MyAlloc (Size, File, Line);
  if (Buffer != ((void *)0) && Tmp != ((void *)0)) {
    memcpy (
      Buffer,
      &Tmp->Buffer[sizeof (UINT32)],
      ((Size <= Tmp->Size) ? Size : Tmp->Size)
      );
    MyFree (Ptr, (unsigned char *)"MyAlloc.c", 375);
  }
  return Buffer;
}

variable_types:
Ptr
void *

variable_types:
Size
unsigned long

variable_types:
Buffer
void *

user_defined_types: struct MyAllocStruct { unsigned long Cksum; struct MyAllocStruct *Next; unsigned long Line; unsigned long Size; unsigned char *File; unsigned char *Buffer; }


CheckMemoryFileState

decompiled_code:
unsigned __int64 __fastcall CheckMemoryFileState(unsigned __int64 *a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // rdx
unsigned __int64 v3; // rcx

if ( !a1 )
_assert_fail("InputMemoryFile != NULL", "MemoryFile.c", 0xF8u, "CheckMemoryFileState");
result = *a1;
if ( !*a1 )
_assert_fail("MemoryFile->FileImage != NULL", "MemoryFile.c", 0xFCu, "CheckMemoryFileState");
v2 = a1[2];
if ( !v2 )
_assert_fail("MemoryFile->CurrentFilePointer != NULL", "MemoryFile.c", 0xFDu, "CheckMemoryFileState");
v3 = a1[1];
if ( !v3 )
_assert_fail("MemoryFile->Eof != NULL", "MemoryFile.c", 0xFEu, "CheckMemoryFileState");
if ( result > v3 )
_assert_fail("MemoryFile->Eof >= MemoryFile->FileImage", "MemoryFile.c", 0xFFu, "CheckMemoryFileState");
if ( result > v2 )
_assert_fail(
"MemoryFile->CurrentFilePointer >= MemoryFile->FileImage",
"MemoryFile.c",
0x100u,
"CheckMemoryFileState");
if ( v2 > v3 )
_assert_fail("MemoryFile->CurrentFilePointer <= MemoryFile->Eof", "MemoryFile.c", 0x101u, "CheckMemoryFileState");
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int64 *a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // rdx
unsigned __int64 v3; // rcx

if ( !a1 )
_assert_fail("InputMemoryFile != NULL", "MemoryFile.c", 0xF8u, "CheckMemoryFileState");
result = *a1;
if ( !*a1 )
_assert_fail("MemoryFile->FileImage != NULL", "MemoryFile.c", 0xFCu, "CheckMemoryFileState");
v2 = a1[2];
if ( !v2 )
_assert_fail("MemoryFile->CurrentFilePointer != NULL", "MemoryFile.c", 0xFDu, "CheckMemoryFileState");
v3 = a1[1];
if ( !v3 )
_assert_fail("MemoryFile->Eof != NULL", "MemoryFile.c", 0xFEu, "CheckMemoryFileState");
if ( result > v3 )
_assert_fail("MemoryFile->Eof >= MemoryFile->FileImage", "MemoryFile.c", 0xFFu, "CheckMemoryFileState");
if ( result > v2 )
_assert_fail(
"MemoryFile->CurrentFilePointer >= MemoryFile->FileImage",
"MemoryFile.c",
0x100u,
"CheckMemoryFileState");
if ( v2 > v3 )
_assert_fail("MemoryFile->CurrentFilePointer <= MemoryFile->Eof", "MemoryFile.c", 0x101u, "CheckMemoryFileState");
return result;
}

original_code:
static
void
CheckMemoryFileState (
  EFI_HANDLE InputMemoryFile
  )
{
  MEMORY_FILE *MemoryFile;
  ((void) sizeof ((InputMemoryFile != ((void *)0)) ? 1 : 0), __extension__ ({ if (InputMemoryFile != ((void *)0)) ; else __assert_fail ("InputMemoryFile != NULL", "MemoryFile.c", 248, __extension__ __PRETTY_FUNCTION__); }));
  MemoryFile = (MEMORY_FILE*)InputMemoryFile;
  ((void) sizeof ((MemoryFile->FileImage != ((void *)0)) ? 1 : 0), __extension__ ({ if (MemoryFile->FileImage != ((void *)0)) ; else __assert_fail ("MemoryFile->FileImage != NULL", "MemoryFile.c", 252, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((MemoryFile->CurrentFilePointer != ((void *)0)) ? 1 : 0), __extension__ ({ if (MemoryFile->CurrentFilePointer != ((void *)0)) ; else __assert_fail ("MemoryFile->CurrentFilePointer != NULL", "MemoryFile.c", 253, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((MemoryFile->Eof != ((void *)0)) ? 1 : 0), __extension__ ({ if (MemoryFile->Eof != ((void *)0)) ; else __assert_fail ("MemoryFile->Eof != NULL", "MemoryFile.c", 254, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((MemoryFile->Eof >= MemoryFile->FileImage) ? 1 : 0), __extension__ ({ if (MemoryFile->Eof >= MemoryFile->FileImage) ; else __assert_fail ("MemoryFile->Eof >= MemoryFile->FileImage", "MemoryFile.c", 255, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((MemoryFile->CurrentFilePointer >= MemoryFile->FileImage) ? 1 : 0), __extension__ ({ if (MemoryFile->CurrentFilePointer >= MemoryFile->FileImage) ; else __assert_fail ("MemoryFile->CurrentFilePointer >= MemoryFile->FileImage", "MemoryFile.c", 256, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((MemoryFile->CurrentFilePointer <= MemoryFile->Eof) ? 1 : 0), __extension__ ({ if (MemoryFile->CurrentFilePointer <= MemoryFile->Eof) ; else __assert_fail ("MemoryFile->CurrentFilePointer <= MemoryFile->Eof", "MemoryFile.c", 257, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void CheckMemoryFileState(void *InputMemoryFile)
{
  struct MEMORY_FILE *MemoryFile;
  ((void) sizeof ((InputMemoryFile != ((void *)0)) ? 1 : 0), __extension__ ({ if (InputMemoryFile != ((void *)0)) ; else __assert_fail ("InputMemoryFile != NULL", "MemoryFile.c", 248, __extension__ __PRETTY_FUNCTION__); }));
  MemoryFile = (struct MEMORY_FILE *)InputMemoryFile;
  ((void) sizeof ((MemoryFile->FileImage != ((void *)0)) ? 1 : 0), __extension__ ({ if (MemoryFile->FileImage != ((void *)0)) ; else __assert_fail ("MemoryFile->FileImage != NULL", "MemoryFile.c", 252, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((MemoryFile->CurrentFilePointer != ((void *)0)) ? 1 : 0), __extension__ ({ if (MemoryFile->CurrentFilePointer != ((void *)0)) ; else __assert_fail ("MemoryFile->CurrentFilePointer != NULL", "MemoryFile.c", 253, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((MemoryFile->Eof != ((void *)0)) ? 1 : 0), __extension__ ({ if (MemoryFile->Eof != ((void *)0)) ; else __assert_fail ("MemoryFile->Eof != NULL", "MemoryFile.c", 254, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((MemoryFile->Eof >= MemoryFile->FileImage) ? 1 : 0), __extension__ ({ if (MemoryFile->Eof >= MemoryFile->FileImage) ; else __assert_fail ("MemoryFile->Eof >= MemoryFile->FileImage", "MemoryFile.c", 255, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((MemoryFile->CurrentFilePointer >= MemoryFile->FileImage) ? 1 : 0), __extension__ ({ if (MemoryFile->CurrentFilePointer >= MemoryFile->FileImage) ; else __assert_fail ("MemoryFile->CurrentFilePointer >= MemoryFile->FileImage", "MemoryFile.c", 256, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((MemoryFile->CurrentFilePointer <= MemoryFile->Eof) ? 1 : 0), __extension__ ({ if (MemoryFile->CurrentFilePointer <= MemoryFile->Eof) ; else __assert_fail ("MemoryFile->CurrentFilePointer <= MemoryFile->Eof", "MemoryFile.c", 257, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types:
InputMemoryFile
void *

variable_types: struct MEMORY_FILE { char *FileImage; char *Eof; char *CurrentFilePointer; } *


FreeMemoryFile

decompiled_code:
__int64 __fastcall FreeMemoryFile(void *ptr)
{
CheckMemoryFileState((unsigned __int64 *)ptr);
free(*(void **)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
func0((unsigned __int64 *)ptr);
free(*(void **)ptr);
free(ptr);
return 0LL;
}

original_code:
EFI_STATUS
FreeMemoryFile (
  EFI_HANDLE InputMemoryFile
  )
{
  MEMORY_FILE *MemoryFile;
  CheckMemoryFileState (InputMemoryFile);
  MemoryFile = (MEMORY_FILE*)InputMemoryFile;
  free (MemoryFile->FileImage);
  memset (MemoryFile, 0xcc, sizeof (*MemoryFile));
  MemoryFile->Eof -= 1;
  free (MemoryFile);
  return 0;
}

canonical_original_code:
int FreeMemoryFile(void *InputMemoryFile)
{
  struct MEMORY_FILE *MemoryFile;
  CheckMemoryFileState (InputMemoryFile);
  MemoryFile = (struct MEMORY_FILE *)InputMemoryFile;
  free (MemoryFile->FileImage);
  memset (MemoryFile, 0xcc, sizeof (*MemoryFile));
  MemoryFile->Eof -= 1;
  free (MemoryFile);
  return 0;
}

user_defined_types: struct MEMORY_FILE { char *FileImage; char *Eof; char *CurrentFilePointer; }


repo: guofei/jscrypto

decompiled_code:
int __fastcall print_error(const char *a1, __int64 a2)
{
const char *v2; // rax

v2 = (const char *)ERR_error_string(a2, 0LL);
return fprintf(stderr, "%s(%s)\n", a1, v2);
}

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

v2 = (const char *)ERR_error_string(a2, 0LL);
return fprintf(stderr, "%s(%s)\n", a1, v2);
}

original_code:
static void print_error(char *msg, unsigned long err)
{
        char *errmsg = ERR_error_string(err, ((void *)0));
        fprintf(stderr, "%s(%s)\n", msg, errmsg);
}

variable_types:
msg
char *

variable_types:
err
unsigned long

variable_types:
errmsg
char *


decompiled_code:
char *__fastcall str_join(__int128 src)
{
char *v1; // r14
size_t v2; // r13
size_t v3; // r15

v1 = (char *)(*((_QWORD *)&src + 1) | src);
if ( src != 0 )
{
v2 = 0LL;
if ( (_QWORD)src )
v2 = strlen((const char *)src);
v3 = 0LL;
if ( *((_QWORD *)&src + 1) )
v3 = strlen(*((const char **)&src + 1));
v1 = (char *)malloc(v2 + v3 + 1);
memcpy(v1, (const void *)src, v2);
memcpy(&v1[v2], *((const void **)&src + 1), v3 + 1);
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func1(__int128 src)
{
char *v1; // r14
size_t v2; // r13
size_t v3; // r15

v1 = (char *)(*((_QWORD *)&src + 1) | src);
if ( src != 0 )
{
v2 = 0LL;
if ( (_QWORD)src )
v2 = strlen((const char *)src);
v3 = 0LL;
if ( *((_QWORD *)&src + 1) )
v3 = strlen(*((const char **)&src + 1));
v1 = (char *)malloc(v2 + v3 + 1);
memcpy(v1, (const void *)src, v2);
memcpy(&v1[v2], *((const void **)&src + 1), v3 + 1);
}
return v1;
}

original_code:
static char* str_join(const char* a, const char* b)
{
        if(a == ((void *)0) && b == ((void *)0))
                return ((void *)0);
        size_t la = 0;
        if(a)
                la = strlen(a);
        size_t lb = 0;
        if(b)
                lb = strlen(b);
        char* p = malloc(la + lb + 1);
        memcpy(p, a, la);
        memcpy(p + la, b, lb + 1);
        return p;
}

canonical_original_code:
static char *str_join(char *a, char *b)
{
        if(a == ((void *)0) && b == ((void *)0))
                return ((void *)0);
        unsigned long la = 0;
        if(a)
                la = strlen(a);
        unsigned long lb = 0;
        if(b)
                lb = strlen(b);
        char *p = malloc(la + lb + 1);
        memcpy(p, a, la);
        memcpy(p + la, b, lb + 1);
        return p;
}

variable_types:
a
char *

variable_types:
b
char *

variable_types:
la
unsigned long

variable_types:
lb
unsigned long

variable_types:
p
char *


decompiled_code:
__int64 __fastcall pass_cb2(void *dest, int a2, __int64 a3, const char *a4)
{
int v4; // ebx

v4 = a2;
printf("Enter pass phrase for \"%s\"\n", a4);
if ( a2 > 4 )
v4 = 5;
memcpy(dest, "hello", v4);
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func10(void *dest, int a2, __int64 a3, const char *a4)
{
int v4; // ebx

v4 = a2;
printf("Enter pass phrase for \"%s\"\n", a4);
if ( a2 > 4 )
v4 = 5;
memcpy(dest, "hello", v4);
return (unsigned int)v4;
}

original_code:
int pass_cb2(char *buf, int size, int rwflag, void *u)
{
        int len;
        char *tmp;
        printf("Enter pass phrase for \"%s\"\n", (char *)u);
        tmp = "hello";
        len = 5;
        if (len <= 0) return 0;
        if (len > size) len = size;
        memcpy(buf, tmp, len);
        return len;
}

variable_types:
buf
char *

variable_types: size int

variable_types: rwflag int

variable_types:
u
void *

variable_types: len int

variable_types:
tmp
char *


test

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

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

original_code:
int test(int test){
        return 0;
}

canonical_original_code:
int test(int test){
        return 0;
}

variable_types: test int


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

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

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

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

original_code:
NP_Array NP_Array_new()
{
 NP_Array array = malloc(sizeof(struct NP_Array));
 array->elem = ((void *)0);
 array->length = 0;
 return array;
}

canonical_original_code:
struct NP_Array *NP_Array_new()
{
 struct NP_Array *array = malloc(sizeof(struct NP_Array));
 array->elem = ((void *)0);
 array->length = 0;
 return array;
}

variable_types: struct NP_Array { void **elem; unsigned long length; } *


decompiled_code:
void __fastcall NP_Array_free(void *ptr, void (__fastcall *a2)(_QWORD))
{
unsigned __int64 v2; // rbx

if ( *((_QWORD *)ptr + 1) )
{
v2 = 0LL;
do
a2(*(_QWORD *)(*(_QWORD *)ptr + 8 * v2++));
while ( *((_QWORD *)ptr + 1) > v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr, void (__fastcall *a2)(_QWORD))
{
unsigned __int64 v2; // rbx

if ( *((_QWORD *)ptr + 1) )
{
v2 = 0LL;
do
a2(*(_QWORD *)(*(_QWORD *)ptr + 8 * v2++));
while ( *((_QWORD *)ptr + 1) > v2 );
}
free(ptr);
}

original_code:
void NP_Array_free(NP_Array array, void (*free_elem)(void *))
{
 for (int i = 0; i < array->length; ++i)
  free_elem(array->elem[i]);
 free(array);
}

canonical_original_code:
void NP_Array_free(struct NP_Array *array, void (*free_elem)(void *))
{
 for (int i = 0; i < array->length; ++i)
  free_elem(array->elem[i]);
 free(array);
}

variable_types: i int

user_defined_types: struct NP_Array { void **elem; unsigned long length; }


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

v2 = realloc(*(void **)a1, 8LL * *(_QWORD *)(a1 + 8) + 8);
*(_QWORD *)a1 = v2;
v2[*(_QWORD *)(a1 + 8)] = a2;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = result + 1;
return result;
}

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

v2 = realloc(*(void **)a1, 8LL * *(_QWORD *)(a1 + 8) + 8);
*(_QWORD *)a1 = v2;
v2[*(_QWORD *)(a1 + 8)] = a2;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = result + 1;
return result;
}

original_code:
int NP_Array_push(NP_Array array, void *data)
{
 array->elem = realloc(array->elem, sizeof(void *) * (array->length + 1));
 array->elem[array->length] = data;
 return array->length++;
}

canonical_original_code:
int NP_Array_push(struct NP_Array *array, void *data)
{
 array->elem = realloc(array->elem, sizeof(void *) * (array->length + 1));
 array->elem[array->length] = data;
 return array->length++;
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall NP_Array_get(_QWORD *a1, int a2)
{
return *(_QWORD *)(*a1 + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, int a2)
{
return *(_QWORD *)(*a1 + 8LL * a2);
}

original_code:
void *NP_Array_get(NP_Array array, int index)
{
 return array->elem[index];
}

canonical_original_code:
void *NP_Array_get(struct NP_Array *array, int index)
{
 return array->elem[index];
}

variable_types: index int


decompiled_code:
__int64 __fastcall base64_calc_decode_length(const char *a1)
{
int v1; // eax
char v2; // dl
int v3; // esi

v1 = strlen(a1);
v2 = a1[v1 - 1];
if ( v2 != 61 || (v3 = 2, a1[v1 - 2] != 61) )
v3 = v2 == 61;
return (unsigned int)(int)((double)v1 * 0.75 - (double)v3);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v1; // eax
char v2; // dl
int v3; // esi

v1 = strlen(a1);
v2 = a1[v1 - 1];
if ( v2 != 61 || (v3 = 2, a1[v1 - 2] != 61) )
v3 = v2 == 61;
return (unsigned int)(int)((double)v1 * 0.75 - (double)v3);
}

original_code:
int base64_calc_decode_length(const char* b64input) {
 int len = strlen(b64input);
 int padding = 0;
 if (b64input[len-1] == '=' && b64input[len-2] == '=')
  padding = 2;
 else if (b64input[len-1] == '=')
  padding = 1;
 return (int)len*0.75 - padding;
}

canonical_original_code:
int base64_calc_decode_length(char *b64input) {
 int len = strlen(b64input);
 int padding = 0;
 if (b64input[len-1] == '=' && b64input[len-2] == '=')
  padding = 2;
 else if (b64input[len-1] == '=')
  padding = 1;
 return (int)len*0.75 - padding;
}

variable_types: padding int


CreateString

decompiled_code:
__int64 __fastcall CreateString(int a1)
{
return GetBlock(a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return GetBlock(a1 + 1);
}

original_code:
static string CreateString(int len)
{
    return ((string) GetBlock(len + 1));
}

canonical_original_code:
static char *CreateString(int len)
{
    return ((char *) GetBlock(len + 1));
}


Concat

decompiled_code:
char *__fastcall Concat(char *src, char *a2)
{
int v2; // ebx
int v3; // eax
char *v4; // rbp

if ( !src || !a2 )
Error("NULL string passed to Concat");
v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)CreateString(v2 + v3);
strcpy(v4, src);
strcpy(&v4[v2], a2);
return v4;
}

canonical_decompiled_code:
char *__fastcall func1(char *src, char *a2)
{
int v2; // ebx
int v3; // eax
char *v4; // rbp

if ( !src || !a2 )
Error("NULL string passed to Concat");
v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)func0(v2 + v3);
strcpy(v4, src);
strcpy(&v4[v2], a2);
return v4;
}

original_code:
string Concat(string s1, string s2)
{
    string s;
    int len1, len2;
    if (s1 == ((void *)0) || s2 == ((void *)0)) {
        Error("NULL string passed to Concat");
    }
    len1 = strlen(s1);
    len2 = strlen(s2);
    s = CreateString(len1 + len2);
    strcpy(s, s1);
    strcpy(s + len1, s2);
    return (s);
}

canonical_original_code:
char *Concat(char *s1, char *s2)
{
    char *s;
    int len1; int len2;
    if (s1 == ((void *)0) || s2 == ((void *)0)) {
        Error("NULL string passed to Concat");
    }
    len1 = strlen(s1);
    len2 = strlen(s2);
    s = CreateString(len1 + len2);
    strcpy(s, s1);
    strcpy(s + len1, s2);
    return (s);
}

variable_types:
s
char *


IthChar

decompiled_code:
__int64 __fastcall IthChar(char *s, int a2)
{
int v2; // eax

if ( !s )
Error("NULL string passed to IthChar");
v2 = strlen(s);
if ( a2 < 0 || a2 > v2 )
Error("Index outside of string range in IthChar");
return (unsigned __int8)s[a2];
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s, int a2)
{
int v2; // eax

if ( !s )
Error("NULL string passed to IthChar");
v2 = strlen(s);
if ( a2 < 0 || a2 > v2 )
Error("Index outside of string range in IthChar");
return (unsigned __int8)s[a2];
}

original_code:
char IthChar(string s, int i)
{
    int len;
    if (s == ((void *)0)) Error("NULL string passed to IthChar");
    len = strlen(s);
    if (i < 0 || i > len) {
        Error("Index outside of string range in IthChar");
    }
    return (s[i]);
}

canonical_original_code:
char IthChar(char *s, int i)
{
    int len;
    if (s == ((void *)0)) Error("NULL string passed to IthChar");
    len = strlen(s);
    if (i < 0 || i > len) {
        Error("Index outside of string range in IthChar");
    }
    return (s[i]);
}

return_type: char


SubString

decompiled_code:
char *__fastcall SubString(char *s, int a2, int a3)
{
int v3; // ebp
int v5; // eax
int v6; // ebx
char *v7; // r13
char *result; // rax

v3 = a2;
if ( !s )
Error("NULL string passed to SubString");
v5 = strlen(s);
if ( a2 < 0 )
v3 = 0;
if ( a3 >= v5 )
a3 = v5 - 1;
v6 = a3 - v3 + 1;
if ( v6 < 0 )
v6 = 0;
v7 = (char *)CreateString(v6);
result = strncpy(v7, &s[v3], v6);
v7[v6] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(char *s, int a2, int a3)
{
int v3; // ebp
int v5; // eax
int v6; // ebx
char *v7; // r13
char *result; // rax

v3 = a2;
if ( !s )
Error("NULL string passed to SubString");
v5 = strlen(s);
if ( a2 < 0 )
v3 = 0;
if ( a3 >= v5 )
a3 = v5 - 1;
v6 = a3 - v3 + 1;
if ( v6 < 0 )
v6 = 0;
v7 = (char *)func0(v6);
result = strncpy(v7, &s[v3], v6);
v7[v6] = 0;
return result;
}

original_code:
string SubString(string s, int p1, int p2)
{
    int len;
    string result;
    if (s == ((void *)0)) Error("NULL string passed to SubString");
    len = strlen(s);
    if (p1 < 0) p1 = 0;
    if (p2 >= len) p2 = len - 1;
    len = p2 - p1 + 1;
    if (len < 0) len = 0;
    result = CreateString(len);
    strncpy(result, s + p1, len);
    result[len] = '\0';
    return (result);
}

canonical_original_code:
char *SubString(char *s, int p1, int p2)
{
    int len;
    char *result;
    if (s == ((void *)0)) Error("NULL string passed to SubString");
    len = strlen(s);
    if (p1 < 0) p1 = 0;
    if (p2 >= len) p2 = len - 1;
    len = p2 - p1 + 1;
    if (len < 0) len = 0;
    result = CreateString(len);
    strncpy(result, s + p1, len);
    result[len] = '\0';
    return (result);
}

variable_types:
result
char *


StringLength

decompiled_code:
size_t __fastcall StringLength(char *s)
{
if ( !s )
Error("NULL string passed to StringLength");
return strlen(s);
}

canonical_decompiled_code:
size_t __fastcall func4(char *s)
{
if ( !s )
Error("NULL string passed to StringLength");
return strlen(s);
}

original_code:
int StringLength(string s)
{
    if (s == ((void *)0)) Error("NULL string passed to StringLength");
    return (strlen(s));
}

canonical_original_code:
int StringLength(char *s)
{
    if (s == ((void *)0)) Error("NULL string passed to StringLength");
    return (strlen(s));
}


CopyString

decompiled_code:
char *__fastcall CopyString(char *src)
{
int v1; // eax
char *v2; // rax

if ( !src )
Error("NULL string passed to CopyString");
v1 = strlen(src);
v2 = (char *)CreateString(v1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func5(char *src)
{
int v1; // eax
char *v2; // rax

if ( !src )
Error("NULL string passed to CopyString");
v1 = strlen(src);
v2 = (char *)func0(v1);
return strcpy(v2, src);
}

original_code:
string CopyString(string s)
{
    string newstr;
    if (s == ((void *)0)) Error("NULL string passed to CopyString");
    newstr = CreateString(strlen(s));
    strcpy(newstr, s);
    return (newstr);
}

canonical_original_code:
char *CopyString(char *s)
{
    char *newstr;
    if (s == ((void *)0)) Error("NULL string passed to CopyString");
    newstr = CreateString(strlen(s));
    strcpy(newstr, s);
    return (newstr);
}

variable_types:
newstr
char *


StringCompare

decompiled_code:
int __fastcall StringCompare(char *s1, char *s2)
{
if ( !s1 || !s2 )
Error("NULL string passed to StringCompare");
return strcmp(s1, s2);
}

canonical_decompiled_code:
int __fastcall func7(char *s1, char *s2)
{
if ( !s1 || !s2 )
Error("NULL string passed to StringCompare");
return strcmp(s1, s2);
}

original_code:
int StringCompare(string s1, string s2)
{
    if (s1 == ((void *)0) || s2 == ((void *)0)) {
        Error("NULL string passed to StringCompare");
    }
    return (strcmp(s1, s2));
}

canonical_original_code:
int StringCompare(char *s1, char *s2)
{
    if (s1 == ((void *)0) || s2 == ((void *)0)) {
        Error("NULL string passed to StringCompare");
    }
    return (strcmp(s1, s2));
}