printDiskHeaderInfoStruct

decompiled_code:
int __fastcall printDiskHeaderInfoStruct(_QWORD *a1)
{
const char *v1; // rdx
const char *v2; // rdx
const char *v3; // rdx
const char *v4; // rdx
const char *v5; // rdx
const char *v6; // rdx
const char *v7; // rdx
const char *v8; // rdx
const char *v9; // rdx
__int64 v11[2]; // [rsp+0h] [rbp-108h] BYREF
char v12[232]; // [rsp+10h] [rbp-F8h] BYREF
int v13; // [rsp+F8h] [rbp-10h]
__int16 v14; // [rsp+FCh] [rbp-Ch]
char v15; // [rsp+FEh] [rbp-Ah]

v11[0] = 0LL;
v11[1] = 0LL;
memset(v12, 0, sizeof(v12));
v13 = 0;
v14 = 0;
v15 = 0;
v1 = "0x%08X";
if ( !hexFlag )
v1 = "%lu";
sprintf((char *)v11, "Debug Monitor Size: %s\n", v1);
printf((const char *)v11, *a1);
v2 = "0x%08X";
if ( !hexFlag )
v2 = "%lu";
sprintf((char *)v11, "Simulated Memory Size: %s\n", v2);
printf((const char *)v11, a1[1]);
v3 = "0x%08X";
if ( !hexFlag )
v3 = "%lu";
sprintf((char *)v11, "Argument Offset: %s\n", v3);
printf((const char *)v11, a1[2]);
v4 = "0x%08X";
if ( !hexFlag )
v4 = "%lu";
sprintf((char *)v11, "Debug Flag: %s\n", v4);
printf((const char *)v11, a1[3]);
v5 = "0x%08X";
if ( !hexFlag )
v5 = "%lu";
sprintf((char *)v11, "Track Location: %s\n", v5);
printf((const char *)v11, a1[4]);
v6 = "0x%08X";
if ( !hexFlag )
v6 = "%lu";
sprintf((char *)v11, "Track Size: %s\n", v6);
printf((const char *)v11, a1[5]);
v7 = "0x%08X";
if ( !hexFlag )
v7 = "%lu";
sprintf((char *)v11, "Country Code: %s\n", v7);
printf((const char *)v11, a1[6]);
v8 = "0x%08X";
if ( !hexFlag )
v8 = "%lu";
sprintf((char *)v11, "Unknown 1: %s\n", v8);
printf((const char *)v11, a1[7]);
v9 = "0x%08X";
if ( !hexFlag )
v9 = "%lu";
sprintf((char *)v11, "Unknown 2: %s\n", v9);
return printf((const char *)v11, a1[8]);
}

canonical_decompiled_code:
int __fastcall func0(_QWORD *a1)
{
const char *v1; // rdx
const char *v2; // rdx
const char *v3; // rdx
const char *v4; // rdx
const char *v5; // rdx
const char *v6; // rdx
const char *v7; // rdx
const char *v8; // rdx
const char *v9; // rdx
__int64 v11[2]; // [rsp+0h] [rbp-108h] BYREF
char v12[232]; // [rsp+10h] [rbp-F8h] BYREF
int v13; // [rsp+F8h] [rbp-10h]
__int16 v14; // [rsp+FCh] [rbp-Ch]
char v15; // [rsp+FEh] [rbp-Ah]

v11[0] = 0LL;
v11[1] = 0LL;
memset(v12, 0, sizeof(v12));
v13 = 0;
v14 = 0;
v15 = 0;
v1 = "0x%08X";
if ( !hexFlag )
v1 = "%lu";
sprintf((char *)v11, "Debug Monitor Size: %s\n", v1);
printf((const char *)v11, *a1);
v2 = "0x%08X";
if ( !hexFlag )
v2 = "%lu";
sprintf((char *)v11, "Simulated Memory Size: %s\n", v2);
printf((const char *)v11, a1[1]);
v3 = "0x%08X";
if ( !hexFlag )
v3 = "%lu";
sprintf((char *)v11, "Argument Offset: %s\n", v3);
printf((const char *)v11, a1[2]);
v4 = "0x%08X";
if ( !hexFlag )
v4 = "%lu";
sprintf((char *)v11, "Debug Flag: %s\n", v4);
printf((const char *)v11, a1[3]);
v5 = "0x%08X";
if ( !hexFlag )
v5 = "%lu";
sprintf((char *)v11, "Track Location: %s\n", v5);
printf((const char *)v11, a1[4]);
v6 = "0x%08X";
if ( !hexFlag )
v6 = "%lu";
sprintf((char *)v11, "Track Size: %s\n", v6);
printf((const char *)v11, a1[5]);
v7 = "0x%08X";
if ( !hexFlag )
v7 = "%lu";
sprintf((char *)v11, "Country Code: %s\n", v7);
printf((const char *)v11, a1[6]);
v8 = "0x%08X";
if ( !hexFlag )
v8 = "%lu";
sprintf((char *)v11, "Unknown 1: %s\n", v8);
printf((const char *)v11, a1[7]);
v9 = "0x%08X";
if ( !hexFlag )
v9 = "%lu";
sprintf((char *)v11, "Unknown 2: %s\n", v9);
return printf((const char *)v11, a1[8]);
}

original_code:
void printDiskHeaderInfoStruct(GCMDiskHeaderInfoStruct *d) {
 char format[255] = "";
 sprintf(format, "Debug Monitor Size:    %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->debugMonitorSize);
 sprintf(format, "Simulated Memory Size: %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->simulatedMemorySize);
 sprintf(format, "Argument Offset:       %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->argumentOffset);
 sprintf(format, "Debug Flag:            %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->debugFlag);
 sprintf(format, "Track Location:        %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->trackLocation);
 sprintf(format, "Track Size:            %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->trackSize);
 sprintf(format, "Country Code:          %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->countryCode);
 sprintf(format, "Unknown 1:             %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->unknown1);
 sprintf(format, "Unknown 2:             %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->unknown2);
}

canonical_original_code:
void printDiskHeaderInfoStruct(struct gcm_disk_header_info_struct *d) {
 char format[255] = "";
 sprintf(format, "Debug Monitor Size:    %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->debugMonitorSize);
 sprintf(format, "Simulated Memory Size: %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->simulatedMemorySize);
 sprintf(format, "Argument Offset:       %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->argumentOffset);
 sprintf(format, "Debug Flag:            %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->debugFlag);
 sprintf(format, "Track Location:        %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->trackLocation);
 sprintf(format, "Track Size:            %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->trackSize);
 sprintf(format, "Country Code:          %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->countryCode);
 sprintf(format, "Unknown 1:             %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->unknown1);
 sprintf(format, "Unknown 2:             %s\n", hexFlag ? "0x%08X" : "%lu");
 printf(format, d->unknown2);
}

variable_types: struct gcm_disk_header_info_struct { unsigned long debugMonitorSize; unsigned long simulatedMemorySize; unsigned long argumentOffset; unsigned long debugFlag; unsigned long trackLocation; unsigned long trackSize; unsigned long countryCode; unsigned long unknown1; unsigned long unknown2; } *


closeFile

repo: sadistech/gcmtool

decompiled_code:
int closeFile()
{
return fclose(dhiFile);
}

canonical_decompiled_code:
int func1()
{
return fclose(dhiFile);
}

original_code:
void closeFile() {
 fclose(dhiFile);
}

canonical_original_code:
void closeFile() {
 fclose(dhiFile);
}

return_type: void


printUsage

decompiled_code:
int printUsage()
{
printf("gcmdiskheaderinfotool %s- Utility for working with GameCube DVD Image diskheaderinfo.\n", "0.3.3d");
puts("http://gcmtool.sourceforge.net\n");
printf("Usage:\t");
puts("gcmdiskheaderinfotool <diskheaderinfo_file>\n");
return printf("Use %s to view extended usage.\n\n", "-?");
}

canonical_decompiled_code:
int func2()
{
printf("gcmdiskheaderinfotool %s- Utility for working with GameCube DVD Image diskheaderinfo.\n", "0.3.3d");
puts("http://gcmtool.sourceforge.net\n");
printf("Usage:\t");
puts("gcmdiskheaderinfotool <diskheaderinfo_file>\n");
return printf("Use %s to view extended usage.\n\n", "-?");
}

original_code:
void printUsage() {
 printf("gcmdiskheaderinfotool %s- Utility for working with GameCube DVD Image diskheaderinfo.\n", "0.3.3d");
 printf("http://gcmtool.sourceforge.net\n\n");
 printf("Usage:\t");
 printf("gcmdiskheaderinfotool <diskheaderinfo_file>\n\n");
 printf("Use %s to view extended usage.\n\n", "-?");
}


printExtendedUsage

decompiled_code:
int printExtendedUsage()
{
printUsage();
printf("\t\x1B[1m-?%s--help \x1B[m\n\t\tDisplays this help.\n\n", ", ");
printf("\t\x1B[1m-h%s--hex \x1B[m\n\t\tDisplay 32bit int values as hex\n\n", ", ");
printf(
"\t\x1B[1m-dms%s--debug-monitor-size <size>\x1B[m\n"
"\t\tSet the debug monitor size to <size> (unsigned 32-bit int)\n"
"\n",
", ");
printf(
"\t\x1B[1m-sms%s--simulated-memory-size <size>\x1B[m\n"
"\t\tSet the simulated memory size to <size> (unsigned 32-bit int)\n"
"\n",
", ");
printf(
"\t\x1B[1m-a%s--argument-offset <offset>\x1B[m\n\t\tSet the argument offset to <offset> (unsigned 32-bit int)\n\n",
", ");
printf("\t\x1B[1m-d%s--debug-flag <flag>\x1B[m\n\t\tSet the debug flag to <flag> (unsigned 32-bit int)\n\n", ", ");
printf(
"\t\x1B[1m-tl%s--track-location <location>\x1B[m\n"
"\t\tSet the track location to <location> (unsigned 32-bit int)\n"
"\n",
", ");
printf("\t\x1B[1m-ts%s--track-size <size>\x1B[m\n\t\tSet the track size to <size> (unsigned 32-bit int)\n\n", ", ");
printf("\t\x1B[1m-c%s--country-code <code>\x1B[m\n\t\tSet the country code to <code> (unsigned 32-bit int)\n\n", ", ");
printf("\t\x1B[1m-u1%s--unknown-1 <value>\x1B[m\n\t\tSet unknown1 to <value> (unsigned 32-bit int)\n\n", ", ");
return printf("\t\x1B[1m-u2%s--unknown-2 <value>\x1B[m\n\t\tSet unknown2 to <value> (unsigned 32-bit int)\n\n", ", ");
}

canonical_decompiled_code:
int func3()
{
func2();
printf("\t\x1B[1m-?%s--help \x1B[m\n\t\tDisplays this help.\n\n", ", ");
printf("\t\x1B[1m-h%s--hex \x1B[m\n\t\tDisplay 32bit int values as hex\n\n", ", ");
printf(
"\t\x1B[1m-dms%s--debug-monitor-size <size>\x1B[m\n"
"\t\tSet the debug monitor size to <size> (unsigned 32-bit int)\n"
"\n",
", ");
printf(
"\t\x1B[1m-sms%s--simulated-memory-size <size>\x1B[m\n"
"\t\tSet the simulated memory size to <size> (unsigned 32-bit int)\n"
"\n",
", ");
printf(
"\t\x1B[1m-a%s--argument-offset <offset>\x1B[m\n\t\tSet the argument offset to <offset> (unsigned 32-bit int)\n\n",
", ");
printf("\t\x1B[1m-d%s--debug-flag <flag>\x1B[m\n\t\tSet the debug flag to <flag> (unsigned 32-bit int)\n\n", ", ");
printf(
"\t\x1B[1m-tl%s--track-location <location>\x1B[m\n"
"\t\tSet the track location to <location> (unsigned 32-bit int)\n"
"\n",
", ");
printf("\t\x1B[1m-ts%s--track-size <size>\x1B[m\n\t\tSet the track size to <size> (unsigned 32-bit int)\n\n", ", ");
printf("\t\x1B[1m-c%s--country-code <code>\x1B[m\n\t\tSet the country code to <code> (unsigned 32-bit int)\n\n", ", ");
printf("\t\x1B[1m-u1%s--unknown-1 <value>\x1B[m\n\t\tSet unknown1 to <value> (unsigned 32-bit int)\n\n", ", ");
return printf("\t\x1B[1m-u2%s--unknown-2 <value>\x1B[m\n\t\tSet unknown2 to <value> (unsigned 32-bit int)\n\n", ", ");
}

original_code:
void printExtendedUsage() {
 printUsage();
 printf("\t\033[1m" "-?" "%s" "--help" " " "" "\033[m\n\t\t" "Displays this help." "\n\n", strcmp("", "--help") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-h" "%s" "--hex" " " "" "\033[m\n\t\t" "Display 32bit int values as hex" "\n\n", strcmp("", "--hex") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-dms" "%s" "--debug-monitor-size" " " "<size>" "\033[m\n\t\t" "Set the debug monitor size to " "<size>" " (unsigned 32-bit int)" "\n\n", strcmp("", "--debug-monitor-size") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-sms" "%s" "--simulated-memory-size" " " "<size>" "\033[m\n\t\t" "Set the simulated memory size to " "<size>" " (unsigned 32-bit int)" "\n\n", strcmp("", "--simulated-memory-size") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-a" "%s" "--argument-offset" " " "<offset>" "\033[m\n\t\t" "Set the argument offset to " "<offset>" " (unsigned 32-bit int)" "\n\n", strcmp("", "--argument-offset") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-d" "%s" "--debug-flag" " " "<flag>" "\033[m\n\t\t" "Set the debug flag to " "<flag>" " (unsigned 32-bit int)" "\n\n", strcmp("", "--debug-flag") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-tl" "%s" "--track-location" " " "<location>" "\033[m\n\t\t" "Set the track location to " "<location>" " (unsigned 32-bit int)" "\n\n", strcmp("", "--track-location") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-ts" "%s" "--track-size" " " "<size>" "\033[m\n\t\t" "Set the track size to " "<size>" " (unsigned 32-bit int)" "\n\n", strcmp("", "--track-size") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-c" "%s" "--country-code" " " "<code>" "\033[m\n\t\t" "Set the country code to " "<code>" " (unsigned 32-bit int)" "\n\n", strcmp("", "--country-code") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-u1" "%s" "--unknown-1" " " "<value>" "\033[m\n\t\t" "Set unknown1 to " "<value>" " (unsigned 32-bit int)" "\n\n", strcmp("", "--unknown-1") == 0 ? "" : ", ");;
 printf("\t\033[1m" "-u2" "%s" "--unknown-2" " " "<value>" "\033[m\n\t\t" "Set unknown2 to " "<value>" " (unsigned 32-bit int)" "\n\n", strcmp("", "--unknown-2") == 0 ? "" : ", ");;
}


main

canonical_name: main

original_code:
int main(int argc, char **argv) {
 int fileChanged = 0;
 hexFlag = 0;
 int modDebugMonitorSize = 0;
 u32 newDebugMonitorSize = 0;
 int modSimulatedMemorySize = 0;
 u32 newSimulatedMemorySize = 0;
 int modArgumentOffset = 0;
 u32 newArgumentOffset = 0;
 int modDebugFlag = 0;
 u32 newDebugFlag = 0;
 int modTrackLocation = 0;
 u32 newTrackLocation = 0;
 int modTrackSize = 0;
 u32 newTrackSize = 0;
 int modCountryCode = 0;
 u32 newCountryCode = 0;
 int modUnknown1 = 0;
 u32 newUnknown1 = 0;
 int modUnknown2 = 0;
 u32 newUnknown2 = 0;
 char *currentArg = ((void *)0);
 do {
  currentArg = *(++argv);
  if (!currentArg) {
   printUsage();
   exit(1);
  } else if (strcmp("-?", currentArg) == 0 || strcmp("--help", currentArg) == 0) {
   printExtendedUsage();
   exit(0);
  } else if (strcmp("-h", currentArg) == 0 || strcmp("--hex", currentArg) == 0) {
   hexFlag = 1;
  } else if (strcmp("-dms", currentArg) == 0 || strcmp("--debug-monitor-size", currentArg) == 0) {
   newDebugMonitorSize = strtoul(*(++argv), ((void *)0), 0);
   modDebugMonitorSize++;
  } else if (strcmp("-sms", currentArg) == 0 || strcmp("--simulated-memory-size", currentArg) == 0) {
   newSimulatedMemorySize = strtoul(*(++argv), ((void *)0), 0);
   modSimulatedMemorySize++;
  } else if (strcmp("-a", currentArg) == 0 || strcmp("--argument-offset", currentArg) == 0) {
   newArgumentOffset = strtoul(*(++argv), ((void *)0), 0);
   modArgumentOffset++;
  } else if (strcmp("-d", currentArg) == 0 || strcmp("--debug-flag", currentArg) == 0) {
   newDebugFlag = strtoul(*(++argv), ((void *)0), 0);
   modDebugFlag++;
  } else if (strcmp("-tl", currentArg) == 0 || strcmp("--track-location", currentArg) == 0) {
   newTrackLocation = strtoul(*(++argv), ((void *)0), 0);
   modTrackLocation++;
  } else if (strcmp("-ts", currentArg) == 0 || strcmp("--track-size", currentArg) == 0) {
   newTrackSize = strtoul(*(++argv), ((void *)0), 0);
   modTrackSize++;
  } else if (strcmp("-c", currentArg) == 0 || strcmp("--country-code", currentArg) == 0) {
   newCountryCode = strtoul(*(++argv), ((void *)0), 0);
   modCountryCode++;
  } else if (strcmp("-u1", currentArg) == 0 || strcmp("--unknown-1", currentArg) == 0) {
   newUnknown1 = strtoul(*(++argv), ((void *)0), 0);
   modUnknown1++;
  } else if (strcmp("-u2", currentArg) == 0 || strcmp("--unknown-2", currentArg) == 0) {
   newUnknown2 = strtoul(*(++argv), ((void *)0), 0);
   modUnknown2++;
  } else {
   filename = currentArg;
   break;
  }
 } while(*argv);
 openFile("r");
 u32 len = GetFilesizeFromStream(dhiFile);
 if (len != 0x2000) {
  printf("%s does not appear to be a GCM diskheaderinfo.\n");
  closeFile();
  exit(1);
 }
 char *data = (char*)malloc(len);
 if (fread(data, 1, len, dhiFile) != len) {
  perror(filename);
  exit(1);
 }
 GCMDiskHeaderInfoStruct *d = GCMRawDiskHeaderInfoToStruct(data);
 printDiskHeaderInfoStruct(d);
 closeFile();
 if (modDebugMonitorSize) {
  d->debugMonitorSize = newDebugMonitorSize;
  fileChanged++;
 }
 if (modSimulatedMemorySize) {
  d->simulatedMemorySize = newSimulatedMemorySize;
  fileChanged++;
 }
 if (modArgumentOffset) {
  d->argumentOffset = newArgumentOffset;
  fileChanged++;
 }
 if (modDebugFlag) {
  d->debugFlag = newDebugFlag;
  fileChanged++;
 }
 if (modTrackLocation) {
  d->trackLocation = newTrackLocation;
  fileChanged++;
 }
 if (modTrackSize) {
  d->trackSize = newTrackSize;
  fileChanged++;
 }
 if (modCountryCode) {
  d->countryCode = newCountryCode;
  fileChanged++;
 }
 if (modUnknown1) {
  d->unknown1 = newUnknown1;
  fileChanged++;
 }
 if (modUnknown2) {
  d->unknown2 = newUnknown2;
  fileChanged++;
 }
 if (fileChanged) {
  openFile("r+");
  printDiskHeaderInfoStruct(d);
  char *data = (char*)malloc(0x2000);
  GCMDiskHeaderInfoStructToRaw(d, data);
  rewind(dhiFile);
  if (fwrite(data, 1, 0x2000, dhiFile) != 0x2000) {
   perror("Error writing diskheaderinfo!");
   exit(1);
  }
  free(data);
  closeFile();
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int fileChanged = 0;
 hexFlag = 0;
 int modDebugMonitorSize = 0;
 unsigned long newDebugMonitorSize = 0;
 int modSimulatedMemorySize = 0;
 unsigned long newSimulatedMemorySize = 0;
 int modArgumentOffset = 0;
 unsigned long newArgumentOffset = 0;
 int modDebugFlag = 0;
 unsigned long newDebugFlag = 0;
 int modTrackLocation = 0;
 unsigned long newTrackLocation = 0;
 int modTrackSize = 0;
 unsigned long newTrackSize = 0;
 int modCountryCode = 0;
 unsigned long newCountryCode = 0;
 int modUnknown1 = 0;
 unsigned long newUnknown1 = 0;
 int modUnknown2 = 0;
 unsigned long newUnknown2 = 0;
 char *currentArg = ((void *)0);
 do {
  currentArg = *(++argv);
  if (!currentArg) {
   printUsage();
   exit(1);
  } else if (strcmp("-?", currentArg) == 0 || strcmp("--help", currentArg) == 0) {
   printExtendedUsage();
   exit(0);
  } else if (strcmp("-h", currentArg) == 0 || strcmp("--hex", currentArg) == 0) {
   hexFlag = 1;
  } else if (strcmp("-dms", currentArg) == 0 || strcmp("--debug-monitor-size", currentArg) == 0) {
   newDebugMonitorSize = strtoul(*(++argv), ((void *)0), 0);
   modDebugMonitorSize++;
  } else if (strcmp("-sms", currentArg) == 0 || strcmp("--simulated-memory-size", currentArg) == 0) {
   newSimulatedMemorySize = strtoul(*(++argv), ((void *)0), 0);
   modSimulatedMemorySize++;
  } else if (strcmp("-a", currentArg) == 0 || strcmp("--argument-offset", currentArg) == 0) {
   newArgumentOffset = strtoul(*(++argv), ((void *)0), 0);
   modArgumentOffset++;
  } else if (strcmp("-d", currentArg) == 0 || strcmp("--debug-flag", currentArg) == 0) {
   newDebugFlag = strtoul(*(++argv), ((void *)0), 0);
   modDebugFlag++;
  } else if (strcmp("-tl", currentArg) == 0 || strcmp("--track-location", currentArg) == 0) {
   newTrackLocation = strtoul(*(++argv), ((void *)0), 0);
   modTrackLocation++;
  } else if (strcmp("-ts", currentArg) == 0 || strcmp("--track-size", currentArg) == 0) {
   newTrackSize = strtoul(*(++argv), ((void *)0), 0);
   modTrackSize++;
  } else if (strcmp("-c", currentArg) == 0 || strcmp("--country-code", currentArg) == 0) {
   newCountryCode = strtoul(*(++argv), ((void *)0), 0);
   modCountryCode++;
  } else if (strcmp("-u1", currentArg) == 0 || strcmp("--unknown-1", currentArg) == 0) {
   newUnknown1 = strtoul(*(++argv), ((void *)0), 0);
   modUnknown1++;
  } else if (strcmp("-u2", currentArg) == 0 || strcmp("--unknown-2", currentArg) == 0) {
   newUnknown2 = strtoul(*(++argv), ((void *)0), 0);
   modUnknown2++;
  } else {
   filename = currentArg;
   break;
  }
 } while(*argv);
 openFile("r");
 unsigned long len = GetFilesizeFromStream(dhiFile);
 if (len != 0x2000) {
  printf("%s does not appear to be a GCM diskheaderinfo.\n");
  closeFile();
  exit(1);
 }
 char *data = (char*)malloc(len);
 if (fread(data, 1, len, dhiFile) != len) {
  perror(filename);
  exit(1);
 }
 struct gcm_disk_header_info_struct *d = GCMRawDiskHeaderInfoToStruct(data);
 printDiskHeaderInfoStruct(d);
 closeFile();
 if (modDebugMonitorSize) {
  d->debugMonitorSize = newDebugMonitorSize;
  fileChanged++;
 }
 if (modSimulatedMemorySize) {
  d->simulatedMemorySize = newSimulatedMemorySize;
  fileChanged++;
 }
 if (modArgumentOffset) {
  d->argumentOffset = newArgumentOffset;
  fileChanged++;
 }
 if (modDebugFlag) {
  d->debugFlag = newDebugFlag;
  fileChanged++;
 }
 if (modTrackLocation) {
  d->trackLocation = newTrackLocation;
  fileChanged++;
 }
 if (modTrackSize) {
  d->trackSize = newTrackSize;
  fileChanged++;
 }
 if (modCountryCode) {
  d->countryCode = newCountryCode;
  fileChanged++;
 }
 if (modUnknown1) {
  d->unknown1 = newUnknown1;
  fileChanged++;
 }
 if (modUnknown2) {
  d->unknown2 = newUnknown2;
  fileChanged++;
 }
 if (fileChanged) {
  openFile("r+");
  printDiskHeaderInfoStruct(d);
  char *data = (char*)malloc(0x2000);
  GCMDiskHeaderInfoStructToRaw(d, data);
  rewind(dhiFile);
  if (fwrite(data, 1, 0x2000, dhiFile) != 0x2000) {
   perror("Error writing diskheaderinfo!");
   exit(1);
  }
  free(data);
  closeFile();
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: fileChanged int

variable_types: modDebugMonitorSize int

variable_types:
newDebugMonitorSize
unsigned long

variable_types: modSimulatedMemorySize int

variable_types:
newSimulatedMemorySize
unsigned long

variable_types: modArgumentOffset int

variable_types:
newArgumentOffset
unsigned long

variable_types: modDebugFlag int

variable_types:
newDebugFlag
unsigned long

variable_types: modTrackLocation int

variable_types:
newTrackLocation
unsigned long

variable_types: modTrackSize int

variable_types:
newTrackSize
unsigned long

variable_types: modCountryCode int

variable_types:
newCountryCode
unsigned long

variable_types:
currentArg
char *

variable_types:
len
unsigned long

variable_types:
data
char *

return_type: int

user_defined_types: struct gcm_disk_header_info_struct { unsigned long debugMonitorSize; unsigned long simulatedMemorySize; unsigned long argumentOffset; unsigned long debugFlag; unsigned long trackLocation; unsigned long trackSize; unsigned long countryCode; unsigned long unknown1; unsigned long unknown2; }


repo: sagarpdy/sapshell

decompiled_code:
int exit_main()
{
int result; // eax

result = puts("Bye bye!!");
shell_exit = 1;
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax

result = puts("Bye bye!!");
shell_exit = 1;
return result;
}

original_code:
static int exit_main(int argc, char **argv)
{
 printf("Bye bye!!\n");
 shell_exit = 1;
}

variable_types: argc int

variable_types:
argv
char **


sapshell

decompiled_code:
void sapshell()
{
unsigned int v0; // ebp
char *v1; // rdi
char *v2; // rax
const char *v3; // r15
__int64 v4; // rbx
const char *v5; // rsi
char *v6; // r12
char *s1[255]; // [rsp+0h] [rbp-838h] BYREF
char *save_ptr; // [rsp+7F8h] [rbp-40h] BYREF

save_ptr = 0LL;
memset(s1, 0, sizeof(s1));
do
{
v6 = (char *)readline();
save_ptr = 0LL;
memset(s1, 0, 0xF8uLL);
LODWORD(s1[31]) = 0;
WORD2(s1[31]) = 0;
BYTE6(s1[31]) = 0;
if ( !v6 )
break;
v1 = v6;
v0 = 0;
while ( 1 )
{
v2 = strtok_r(v1, " ", &save_ptr);
s1[v0] = v2;
if ( !v2 )
break;
v0 -= (*v2 == 0) - 1;
v1 = 0LL;
}
v3 = s1[0];
v4 = 0LL;
v5 = "sapshell";
while ( strcmp(v3, v5) )
{
++v4;
v5 = (&tools)[2 * v4];
if ( !v5 )
goto LABEL_9;
}
((void (__fastcall *)(_QWORD, char **))*(&off_402068 + 2 * (int)v4))(v0, s1);
LABEL_9:
free(v6);
}
while ( !shell_exit );
}

canonical_decompiled_code:
void func8()
{
unsigned int v0; // ebp
char *v1; // rdi
char *v2; // rax
const char *v3; // r15
__int64 v4; // rbx
const char *v5; // rsi
char *v6; // r12
char *s1[255]; // [rsp+0h] [rbp-838h] BYREF
char *save_ptr; // [rsp+7F8h] [rbp-40h] BYREF

save_ptr = 0LL;
memset(s1, 0, sizeof(s1));
do
{
v6 = (char *)readline();
save_ptr = 0LL;
memset(s1, 0, 0xF8uLL);
LODWORD(s1[31]) = 0;
WORD2(s1[31]) = 0;
BYTE6(s1[31]) = 0;
if ( !v6 )
break;
v1 = v6;
v0 = 0;
while ( 1 )
{
v2 = strtok_r(v1, " ", &save_ptr);
s1[v0] = v2;
if ( !v2 )
break;
v0 -= (*v2 == 0) - 1;
v1 = 0LL;
}
v3 = s1[0];
v4 = 0LL;
v5 = "sapshell";
while ( strcmp(v3, v5) )
{
++v4;
v5 = (&tools)[2 * v4];
if ( !v5 )
goto LABEL_9;
}
((void (__fastcall *)(_QWORD, char **))*(&off_402068 + 2 * (int)v4))(v0, s1);
LABEL_9:
free(v6);
}
while ( !shell_exit );
}

original_code:
void sapshell() {
 char* command = 0, *curr = 0, *t = 0;
 char* argv[255] = {0};
 int i = 0, j = 0;
 do {
  command = readline("shapshell $");
  curr = t = 0;
  memset(argv, 0, 255);
  i = 0;
  if (!command)
   return;
  for (t = command; ;t = 0) {
   argv[i] = strtok_r(t, " ", &curr);
   if (argv[i] != ((void *)0))
    if (!strlen(argv[i]))
     continue;
    else
     i++;
   else
    break;
  }
  for (j = 0; tools[j].name != 0; ++j)
  {
   if (!strcmp(argv[0], tools[j].name))
   {
    tools[j].func(i, argv);
    break;
   }
  }
  free(command);
 } while(command && (!shell_exit));
}

canonical_original_code:
void sapshell() {
 char *command = 0; char *curr = 0; char *t = 0;
 char *argv[255] = {0};
 int i = 0; int j = 0;
 do {
  command = readline("shapshell $");
  curr = t = 0;
  memset(argv, 0, 255);
  i = 0;
  if (!command)
   return;
  for (t = command; ;t = 0) {
   argv[i] = strtok_r(t, " ", &curr);
   if (argv[i] != ((void *)0))
    if (!strlen(argv[i]))
     continue;
    else
     i++;
   else
    break;
  }
  for (j = 0; tools[j].name != 0; ++j)
  {
   if (!strcmp(argv[0], tools[j].name))
   {
    tools[j].func(i, argv);
    break;
   }
  }
  free(command);
 } while(command && (!shell_exit));
}

variable_types:
command
char *

variable_types:
curr
char *

variable_types:
t
char *

variable_types:
argv
char *[255]

variable_types: i int

variable_types: j int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 1 )
{
puts("Staring sapshell!!");
sapshell();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 1 )
{
puts("Staring sapshell!!");
func8();
}
return 0;
}

original_code:
int main(int argc, char* argv[]) {
 if (argc <= 1) {
  printf("Staring sapshell!!\n");
  sapshell();
 }
}

canonical_original_code:
int main(int argc, char *argv[]) {
 if (argc <= 1) {
  printf("Staring sapshell!!\n");
  sapshell();
 }
}

variable_types:
argv
char *[]


decompiled_code:
int __fastcall sapshell_main(int a1, __int64 a2, const char **a3)
{
if ( a1 > 1 )
return main(a1 - 1, (const char **)(a2 + 8), a3);
puts("sapshell!");
return 0;
}

canonical_decompiled_code:
int __fastcall func9(int a1, __int64 a2, const char **a3)
{
if ( a1 > 1 )
return main(a1 - 1, (const char **)(a2 + 8), a3);
puts("sapshell!");
return 0;
}

original_code:
static int sapshell_main(int argc, char **argv)
{
    if (argc > 1) {
        return main(argc - 1, argv + 1);
    } else {
        printf("sapshell!\n");
        return 0;
    }
}


decompiled_code:
__int64 version_main()
{
puts("1.0.0");
return 0LL;
}

original_code:
int version_main(int argc, char* argv[])
{
 printf("1.0.0\n");
 return 0;
}

canonical_original_code:
int version_main(int argc, char *argv[])
{
 printf("1.0.0\n");
 return 0;
}


decompiled_code:
__int64 __fastcall cat_main(int a1, const char **a2)
{
const char **v2; // r13
unsigned int v3; // ebx
int v5; // er12
int v6; // eax
int v7; // ebx
__int64 v8[128]; // [rsp+0h] [rbp-468h] BYREF
char v9; // [rsp+400h] [rbp-68h]
__int64 v10[3]; // [rsp+410h] [rbp-58h] BYREF
int v11; // [rsp+428h] [rbp-40h]
__int16 v12; // [rsp+42Ch] [rbp-3Ch]
char v13; // [rsp+42Eh] [rbp-3Ah]

v10[0] = 0LL;
v10[1] = 0LL;
v10[2] = 0LL;
v11 = 0;
v12 = 0;
v13 = 0;
v8[0] = 0LL;
v8[1] = 0LL;
memset(&v8[2], 0, 0x3F0uLL);
v9 = 0;
if ( a1 <= 1 )
{
fprintf(stderr, "USAGE : %s file1 [file2 ...]\n", *a2);
v3 = -22;
}
else
{
v2 = a2 + 1;
do
{
memset(v8, 0, sizeof(v8));
v9 = 0;
v5 = open(*v2, 0);
if ( v5 < 0 )
{
v3 = *__errno_location();
if ( (unsigned int)__xpg_strerror_r() )
fprintf(stderr, "Unable to open file : %s\n", *v2);
else
fprintf(stderr, "Error - %s - when opening : %s\n", (const char *)v10, *v2);
}
else
{
while ( 1 )
{
v6 = read(v5, v8, 0x400uLL);
v7 = v6;
if ( !v6 )
break;
*((_BYTE *)v8 + v6) = 0;
printf("%s", (const char *)v8);
if ( v7 <= 1023 )
{
v3 = 0;
goto LABEL_9;
}
}
v3 = *__errno_location();
if ( (unsigned int)__xpg_strerror_r() )
fprintf(stderr, "Unable to read file : %s\n", *v2);
else
fprintf(stderr, "Error - %s - when reading : %s\n", (const char *)v10, *v2);
LABEL_9:
close(v5);
}
if ( v3 )
break;
++v2;
}
while ( v2 != &a2[(unsigned int)(a1 - 2) + 2] );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, const char **a2)
{
const char **v2; // r13
unsigned int v3; // ebx
int v5; // er12
int v6; // eax
int v7; // ebx
__int64 v8[128]; // [rsp+0h] [rbp-468h] BYREF
char v9; // [rsp+400h] [rbp-68h]
__int64 v10[3]; // [rsp+410h] [rbp-58h] BYREF
int v11; // [rsp+428h] [rbp-40h]
__int16 v12; // [rsp+42Ch] [rbp-3Ch]
char v13; // [rsp+42Eh] [rbp-3Ah]

v10[0] = 0LL;
v10[1] = 0LL;
v10[2] = 0LL;
v11 = 0;
v12 = 0;
v13 = 0;
v8[0] = 0LL;
v8[1] = 0LL;
memset(&v8[2], 0, 0x3F0uLL);
v9 = 0;
if ( a1 <= 1 )
{
fprintf(stderr, "USAGE : %s file1 [file2 ...]\n", *a2);
v3 = -22;
}
else
{
v2 = a2 + 1;
do
{
memset(v8, 0, sizeof(v8));
v9 = 0;
v5 = open(*v2, 0);
if ( v5 < 0 )
{
v3 = *__errno_location();
if ( (unsigned int)__xpg_strerror_r() )
fprintf(stderr, "Unable to open file : %s\n", *v2);
else
fprintf(stderr, "Error - %s - when opening : %s\n", (const char *)v10, *v2);
}
else
{
while ( 1 )
{
v6 = read(v5, v8, 0x400uLL);
v7 = v6;
if ( !v6 )
break;
*((_BYTE *)v8 + v6) = 0;
printf("%s", (const char *)v8);
if ( v7 <= 1023 )
{
v3 = 0;
goto LABEL_9;
}
}
v3 = *__errno_location();
if ( (unsigned int)__xpg_strerror_r() )
fprintf(stderr, "Unable to read file : %s\n", *v2);
else
fprintf(stderr, "Error - %s - when reading : %s\n", (const char *)v10, *v2);
LABEL_9:
close(v5);
}
if ( v3 )
break;
++v2;
}
while ( v2 != &a2[(unsigned int)(a1 - 2) + 2] );
}
return v3;
}

original_code:
int cat_main(int argc, char* argv[]) {
 int i, fd = -1, ret = -22;
 char error_str[30 + 1] = {0};
 char buffer[1024 + 1] = {0};
 if (argc < 2) {
  fprintf(stderr, "USAGE : %s file1 [file2 ...]\n", argv[0]);
  return -22;
 }
 for (i = 1; i < argc; ++i) {
  memset(buffer, 0, 1024 + 1);
  fd = open(argv[i], 00);
  if (fd < 0) {
   ret = (*__errno_location ());
   strerror_r(ret, error_str, 30) ? fprintf(stderr, "Unable to open file : %s\n", argv[i]) : fprintf(stderr, "Error - %s - when opening : %s\n", error_str, argv[i]);
  } else {
   while(ret = read(fd, buffer, 1024)) {
    buffer[ret] = 0;
    printf("%s", buffer);
    if (ret < 1024) break;
   }
   if (!ret) {
    ret = (*__errno_location ());
    strerror_r(ret, error_str, 30) ? fprintf(stderr, "Unable to read file : %s\n", argv[i]) : fprintf(stderr, "Error - %s - when reading : %s\n", error_str, argv[i]);
   } else
    ret = 0;
   close(fd);
  }
  if (ret)
   return ret;
  else
   ret = 0;
 }
 return ret;
}

canonical_original_code:
int cat_main(int argc, char *argv[]) {
 int i; int fd = -1; int ret = -22;
 char error_str[-1] = {0};
 char buffer[-1] = {0};
 if (argc < 2) {
  fprintf(stderr, "USAGE : %s file1 [file2 ...]\n", argv[0]);
  return -22;
 }
 for (i = 1; i < argc; ++i) {
  memset(buffer, 0, 1024 + 1);
  fd = open(argv[i], 00);
  if (fd < 0) {
   ret = (*__errno_location ());
   strerror_r(ret, error_str, 30) ? fprintf(stderr, "Unable to open file : %s\n", argv[i]) : fprintf(stderr, "Error - %s - when opening : %s\n", error_str, argv[i]);
  } else {
   while(ret = read(fd, buffer, 1024)) {
    buffer[ret] = 0;
    printf("%s", buffer);
    if (ret < 1024) break;
   }
   if (!ret) {
    ret = (*__errno_location ());
    strerror_r(ret, error_str, 30) ? fprintf(stderr, "Unable to read file : %s\n", argv[i]) : fprintf(stderr, "Error - %s - when reading : %s\n", error_str, argv[i]);
   } else
    ret = 0;
   close(fd);
  }
  if (ret)
   return ret;
  else
   ret = 0;
 }
 return ret;
}

variable_types: fd int

variable_types: ret int

variable_types:
buffer
char [-1]


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // al
int v4; // eax
bool v5; // zf
int v6; // eax
__int64 v7; // rbx
int v8; // ebp
char v9; // al
bool v10; // dl
int v11; // er14
__int64 v12; // rbx
int v13; // ebp
char v14; // al
bool v15; // dl
int v16; // er13
__int64 v17; // rbx
int v18; // ebp
char v19; // al
bool v20; // dl
int v21; // eax
int v22; // eax
__int64 v23; // r12
char v24; // al
char v25; // al
int v26; // eax
__int64 v27; // rax
__int64 v28; // rbx
unsigned int i; // ebp
__int64 v30; // rax
__int64 v31; // rbp
int v32; // er14
unsigned int v33; // er13
unsigned int v34; // eax
__int64 v35; // r14
__int64 v36; // r15
int v37; // er13
unsigned int v38; // eax
double v40; // [rsp+28h] [rbp-2A0h]
double v41; // [rsp+38h] [rbp-290h]
char v42; // [rsp+43h] [rbp-285h]
unsigned int v43; // [rsp+44h] [rbp-284h]
int v44; // [rsp+48h] [rbp-280h]
int v45; // [rsp+4Ch] [rbp-27Ch]
char nptr[4]; // [rsp+5Ch] [rbp-26Ch] BYREF
char v47[428]; // [rsp+60h] [rbp-268h] BYREF
int v48; // [rsp+20Ch] [rbp-BCh] BYREF
__int128 v49; // [rsp+210h] [rbp-B8h] BYREF
int v50; // [rsp+220h] [rbp-A8h]
char v51; // [rsp+22Eh] [rbp-9Ah] BYREF
char v52; // [rsp+22Fh] [rbp-99h] BYREF
__int64 v53; // [rsp+230h] [rbp-98h] BYREF
__int64 v54; // [rsp+238h] [rbp-90h] BYREF
int v55[8]; // [rsp+240h] [rbp-88h] BYREF
int v56; // [rsp+260h] [rbp-68h]
char v57[3]; // [rsp+26Dh] [rbp-5Bh] BYREF
struct timeval tv; // [rsp+270h] [rbp-58h] BYREF
struct timeval v59; // [rsp+280h] [rbp-48h] BYREF

initscr();
wclear(stdscr);
cbreak();
wrefresh(stdscr);
start_color();
init_pair(1, 3, 4);
init_pair(2, 0, 1);
init_pair(3, 7, 3);
init_pair(4, 7, 4);
init_pair(5, 1, 7);
init_pair(6, 0, 0);
init_pair(9, 3, 7);
init_pair(7, 7, 1);
init_pair(10, 7, 7);
init_pair(11, 0, 7);
init_pair(12, 1, 7);
init_pair(13, 4, 7);
init_pair(14, 5, 7);
mvprintw(10, 19, "Press 'o' for one-player and 't' for two-player:");
wrefresh(stdscr);
while ( 1 )
{
v3 = wgetch(stdscr);
v42 = v3;
if ( v3 == 111 || v3 == 116 )
break;
wclear(stdscr);
mvprintw(10, 19, "Enter o or t only ");
wrefresh(stdscr);
}
wclear(stdscr);
mvprintw(10, 19, "Enter the level (1-3): ");
wrefresh(stdscr);
while ( 1 )
{
v4 = wgetch(stdscr);
if ( (unsigned int)(v4 - 49) <= 2 )
break;
wclear(stdscr);
mvprintw(10, 19, "Enter 1-3 only ");
wrefresh(stdscr);
}
v43 = 40;
if ( v4 != 50 )
{
if ( v4 == 51 )
{
v43 = 30;
}
else
{
v5 = v4 == 49;
v6 = 50;
if ( !v5 )
v6 = 40;
v43 = v6;
}
}
if ( v42 == 116 )
{
wclear(stdscr);
mvprintw(10, 19, "Enter the length for Snake1:");
wrefresh(stdscr);
while ( 2 )
{
nptr[0] = wgetch(stdscr);
v7 = 1LL;
while ( 1 )
{
v8 = v7;
if ( v7 == 4 )
break;
v9 = wgetch(stdscr);
nptr[v7] = v9;
v10 = (_DWORD)v7++ != 0;
if ( v10 && (v9 == 32 || v9 == 10) )
{
nptr[v8] = 0;
break;
}
}
v11 = atoi(nptr);
if ( v11 > 70 )
{
wclear(stdscr);
mvprintw(10, 19, "Enter a length smaller than %d :", 70LL);
wrefresh(stdscr);
continue;
}
break;
}
wclear(stdscr);
mvprintw(10, 19, "Enter the length for Snake2:");
wrefresh(stdscr);
while ( 2 )
{
nptr[0] = wgetch(stdscr);
v12 = 1LL;
while ( 1 )
{
v13 = v12;
if ( v12 == 4 )
break;
v14 = wgetch(stdscr);
nptr[v12] = v14;
v15 = (_DWORD)v12++ != 0;
if ( v15 && (v14 == 32 || v14 == 10) )
{
nptr[v13] = 0;
break;
}
}
v16 = atoi(nptr);
if ( v16 > 70 )
{
wclear(stdscr);
mvprintw(10, 19, "Enter a length smaller than %d :", 70LL);
wrefresh(stdscr);
continue;
}
break;
}
}
else
{
wclear(stdscr);
mvprintw(10, 19, "Enter the length for the Snake:");
wrefresh(stdscr);
while ( 2 )
{
nptr[0] = wgetch(stdscr);
v17 = 1LL;
while ( 1 )
{
v18 = v17;
if ( v17 == 4 )
break;
v19 = wgetch(stdscr);
nptr[v17] = v19;
v20 = (_DWORD)v17++ != 0;
if ( v20 && (v19 == 32 || v19 == 10) )
{
nptr[v18] = 0;
break;
}
}
v16 = atoi(nptr);
if ( v16 > 70 )
{
wclear(stdscr);
mvprintw(10, 19, "Enter a length smaller than %d :", 70LL);
wrefresh(stdscr);
continue;
}
break;
}
v11 = 5;
}
wclear(stdscr);
mvprintw(10, 19, "Enter the Duration of the match (in minutes):");
wrefresh(stdscr);
while ( 1 )
{
v57[0] = wgetch(stdscr);
v24 = wgetch(stdscr);
v57[1] = v24;
if ( v24 == 10 || v24 == 32 )
{
v21 = 1;
LABEL_39:
v57[v21] = 0;
goto LABEL_40;
}
v25 = wgetch(stdscr);
v57[2] = v25;
if ( v25 == 32 || v25 == 10 )
{
v21 = 2;
goto LABEL_39;
}
LABEL_40:
v22 = atoi(v57);
v23 = (unsigned int)v22;
if ( v22 <= 15 )
break;
wclear(stdscr);
mvprintw(10, 19, "Length of match should be lesser than %d :", 15LL);
wrefresh(stdscr);
}
mvprintw(10, 9, "Enter the number of rewards which should be on the screen at a time:");
wrefresh(stdscr);
do
{
v26 = wgetch(stdscr);
v56 = v26 - 48;
if ( (unsigned int)(v26 - 49) > 3 )
{
wclear(stdscr);
mvprintw(10, 19, "Enter 1-4 only ");
wrefresh(stdscr);
}
}
while ( (unsigned int)(v56 - 1) > 3 );
v55[1] = -1;
v55[0] = -1;
v55[3] = -1;
v55[2] = -1;
v55[5] = -1;
v55[4] = -1;
v55[7] = -1;
v55[6] = -1;
wtimeout(stdscr, v43);
noecho();
v54 = make_coord(0LL, 0LL);
v53 = make_coord(79LL, 21LL);
v27 = queue_new();
v28 = queue_push(v27, v54);
if ( v11 > 1 )
{
for ( i = 1; i != v11; ++i )
{
v54 = make_coord(i, 0LL);
v28 = queue_push(v28, v54);
}
}
v30 = queue_new();
v31 = queue_push(v30, v53);
if ( v16 > 1 )
{
v32 = 79 - v16;
v33 = 78;
do
{
v53 = make_coord(v33, 21LL);
v31 = queue_push(v31, v53);
--v33;
}
while ( v32 != v33 );
}
keypad(stdscr, 1);
wrefresh(stdscr);
v52 = 114;
v51 = 108;
v34 = time(0LL);
srand(v34);
*(_QWORD *)&v49 = 1LL;
*((_QWORD *)&v49 + 1) = 0xA00000000LL;
v50 = 10;
v35 = mk_points();
get_points(v28, v31, v35);
v48 = 0;
init_bombregion(v47);
printscreen(v28, v31, v55, &v49, &v48, v47, 0.0, v35, 0LL);
v45 = 10 * (rand() % 20) + 10;
gettimeofday(&tv, 0LL);
v41 = (double)(1000 * LODWORD(tv.tv_sec)) + (double)SLODWORD(tv.tv_usec) / 1000.0;
init_reward(v28, v31, v55);
v44 = 2 * v43;
v36 = 0LL;
do
{
gettimeofday(&v59, 0LL);
++v36;
if ( (_DWORD)v49 )
{
if ( DWORD2(v49) == 10 )
{
*(_QWORD *)&v49 = 0x100000000LL;
v45 = rand() % 20 + v36 + 20;
}
else
{
++DWORD2(v49);
}
}
else if ( v45 == v36 )
{
LODWORD(v49) = 1;
DWORD2(v49) = 0;
HIDWORD(v49) = rand() % 79;
v50 = rand() % 21;
init_bombregion(v47);
}
v40 = (double)(1000 * LODWORD(v59.tv_sec)) + (double)SLODWORD(v59.tv_usec) / 1000.0;
wtimeout(stdscr, v43);
if ( (v40 - v41) / 60000.0 > (double)(int)v23 )
end_game(3LL, v28, v31, v35);
if ( v42 == 111 )
{
v37 = play_one(v28, v31, &v53, &v51, v55, v35);
if ( v37 == 1 )
break;
auto_move(v28, v31, &v52, v55, &v49, v47, v35, v43);
}
else
{
v37 = play(v28, v31, &v54, &v53, &v52, &v51, v55, v35);
if ( v37 == 1 )
break;
}
v38 = collide(v28, v31, (unsigned int)v52, (unsigned int)v51);
end_game(v38, v28, v31, v35);
gettimeofday(&v59, 0LL);
while ( (double)v44 > (double)SLODWORD(v59.tv_usec) / 1000.0 + (double)SLODWORD(v59.tv_sec) * 1000.0 - v40 )
{
wtimeout(stdscr, 0);
wgetch(stdscr);
wgetch(stdscr);
wgetch(stdscr);
gettimeofday(&v59, 0LL);
}
printscreen(v28, v31, v55, &v49, &v48, v47, v40, v35, v23);
wrefresh(stdscr);
}
while ( v37 != 113 );
wclrtoeol(stdscr);
wrefresh(stdscr);
return endwin();
}

original_code:
void main()
{
 initscr();
 wclear(stdscr);
 cbreak();
 wrefresh(stdscr);
 start_color();
 init_pair(1, 3, 4);
 init_pair(2, 0 , 1);
 init_pair(3, 7 , 3);
 init_pair(4, 7 , 4);
 init_pair(5, 1, 7);
 init_pair(6, 0 , 0);
 init_pair(9,3,7);
 init_pair(7, 7 , 1);
 init_pair(10, 7 , 7);
 init_pair(11, 0 , 7);
 init_pair(12, 1 , 7);
 init_pair(13, 4 , 7);
 init_pair(14, 5 , 7);
 int len1=5, len2=1;
 long long int runno=0;
 struct timeval tim;
 struct timeval ini;
 int TIME;
 mvprintw(21/2,79/2-20,"Press 'o' for one-player and 't' for two-player:");
 wrefresh(stdscr);
 char c;
 do
 {
  c=wgetch(stdscr);
  if (!((c=='o')||(c=='t')))
  {
   wclear(stdscr);
   mvprintw(21/2,79/2-20,"Enter o or t only " );
   wrefresh(stdscr);
  }
 }while (!( (c=='o') || (c=='t') ) );
 wclear(stdscr);
 mvprintw(21/2,79/2-20,"Enter the level (1-3): " );
 wrefresh(stdscr);
 int lev;
 do
 {
  lev = wgetch(stdscr);
  if ((lev>'3')||(lev<='0'))
  {
   wclear(stdscr);
   mvprintw(21/2,79/2-20,"Enter 1-3 only " );
   wrefresh(stdscr);
  }
 }while ((lev>'3')||(lev<='0'));
 switch (lev)
 {
  case '1': TIME = 50;
    break;
  case '2': TIME = 40;
    break;
  case '3': TIME = 30;
    break;
 }
 if(c=='t')
 {
  wclear(stdscr);
  mvprintw(21/2,79/2-20,"Enter the length for Snake1:" );
  wrefresh(stdscr);
  char s[4];
  int i;
  do
  {
   for (i=0; i<4; i++)
   {
    s[i]=wgetch(stdscr);
    if (((s[i]==' ')||(s[i]=='\n'))&&(i!=0))
    {
     s[i]='\0';
     break;
    }
   }
   len1=(int)atoi(s);
   if(len1>70){
    wclear(stdscr);
    mvprintw(21/2,79/2-20,"Enter a length smaller than %d :",70 );
    wrefresh(stdscr);
   }
 }while(len1>70);
  wclear(stdscr);
  mvprintw(21/2,79/2-20,"Enter the length for Snake2:" );
  wrefresh(stdscr);
  do
  {
   for (i=0; i<4; i++)
   {
    s[i]=wgetch(stdscr);
    if (((s[i]==' ')||(s[i]=='\n'))&&(i!=0))
    {
     s[i]='\0';
     break;
    }
   }
   len2=(int)atoi(s);
   if(len2>70){
    wclear(stdscr);
    mvprintw(21/2,79/2-20,"Enter a length smaller than %d :",70 );
    wrefresh(stdscr);
   }
 }while(len2>70);
 }
 else{
  wclear(stdscr);
  mvprintw(21/2,79/2-20,"Enter the length for the Snake:" );
  wrefresh(stdscr);
  char s[4];
  int i;
  do
  {
   for (i=0; i<4; i++)
   {
    s[i]=wgetch(stdscr);
    if (((s[i]==' ')||(s[i]=='\n'))&&(i!=0))
    {
     s[i]='\0';
     break;
    }
   }
   len2=(int)atoi(s);
   if(len2>70){
    wclear(stdscr);
    mvprintw(21/2,79/2-20,"Enter a length smaller than %d :",70 );
    wrefresh(stdscr);
   }
 }while(len2>70);
 }
 int maxtime=0;
 char temp[3];
 int i;
 wclear(stdscr);
  mvprintw(21/2,79/2-20,"Enter the Duration of the match (in minutes):" );
  wrefresh(stdscr);
 do
  {
   for (i=0; i<3; i++)
   {
    temp[i]=wgetch(stdscr);
    if (((temp[i]==' ')||(temp[i]=='\n'))&&(i!=0))
    {
     temp[i]='\0';
     break;
    }
   }
   maxtime=(int)atoi(temp);
   if(maxtime>15){
    wclear(stdscr);
    mvprintw(21/2,79/2-20,"Length of match should be lesser  than %d :",15 );
    wrefresh(stdscr);
   }
 }while(maxtime>15);
 reward r;
 mvprintw(21/2,79/2-30,"Enter the number of rewards which should be on the screen at a time:");
 wrefresh(stdscr);
 do
 {
  r.rewnum = wgetch(stdscr) - '0';
  if ((r.rewnum > 4)||(r.rewnum<= 0 ))
  {
   wclear(stdscr);
   mvprintw(21/2,79/2-20,"Enter 1-4 only " );
   wrefresh(stdscr);
  }
 }while ((r.rewnum>4)||r.rewnum<=0);
 int iq;
 for( iq=0 ; iq< 4 ; iq++ )
 r.rewcoord[iq].x = r.rewcoord[iq].y = -1 ;
 wtimeout(stdscr,(TIME));
 noecho();
 coord snake1 = make_coord(0, 0);
 coord snake2 = make_coord(79, 21);
 Queue *s1 = queue_new();
 s1 = queue_push(s1, snake1);
 for (i=1; i<len1; i++)
 {
  snake1 = make_coord(i, 0);
  s1 = queue_push(s1, snake1);
 }
 Queue *s2 = queue_new();
 s2 = queue_push(s2, snake2);
 for (i=1; i<len2; i++)
 {
  snake2 = make_coord(79 -i, 21);
  s2 = queue_push(s2, snake2);
 }
 keypad(stdscr, 1);
 wrefresh(stdscr);
 int ch;
 char snake1dir,snake2dir;
 snake1dir='r';
 snake2dir='l';
 int set_dir1=0 , set_dir2=0;
 srand(time(((void *)0)));
 bomb b={1,0,0,{10,10}};
 int bombx,bomby;
 Points* p=mk_points();
 get_points(s1,s2,p);
 int call_no=0;
 bombregion br;
 init_bombregion(&br, b);
 printscreen(s1, s2, &r ,&b,&call_no,&br,p,0,0,0);
 int nextexplode=( rand() % 20 ) * 10 +runno+10;
 double t2=1000,t1=0;
 double ini_time;
 gettimeofday(&ini, ((void *)0));
 ini_time = ini.tv_sec*1000 + ( ini.tv_usec / 1000.0 );
 init_reward (s1, s2, &r );
 do
 {
  gettimeofday(&tim, ((void *)0));
  runno++;
  if(b.isactive)
  {
   if(b.duration == 10 )
   {
    b.isactive=0;
    b.isexploding=1;
    nextexplode = ( rand() % 20 ) +runno + 20 ;
   }
   else
    b.duration ++;
  }
  else if ( runno == nextexplode )
  {
   b.isactive= 1 ;
   b.duration= 0 ;
   b.topleft.x = (rand()%79) ;
   b.topleft.y= (rand()%21) ;
  init_bombregion(&br,b);
  }
  t1 = tim.tv_sec*1000 + ( tim.tv_usec / 1000.0 );
  wtimeout(stdscr,(TIME));
  if( (t1-ini_time)/60000 > (double)maxtime )
   end_game(3,s1, s2,p);
  if(c=='o')
   ch = play_one(s1, s2, &snake2, &snake2dir, &r,p);
  else
   ch =play(s1, s2, &snake1, &snake2, &snake1dir, &snake2dir, &r,p);
  if (ch==1)
   break;
  if ( c=='o')
   auto_move(s1, s2, &snake1dir, &r, &b,&br,p, TIME);
  int col = collide(s1, s2, snake1dir, snake2dir);
  end_game(col,s1,s2,p);
  gettimeofday(&tim, ((void *)0));
     double t2 = tim.tv_sec*1000.0 + ( tim.tv_usec/1000.0 );
  while( t2-t1 < 2*TIME )
  {
   wtimeout(stdscr,(0));
   wgetch(stdscr);
   wgetch(stdscr);
   wgetch(stdscr);
   gettimeofday(&tim, ((void *)0));
       t2 = tim.tv_sec*1000.0 + ( tim.tv_usec/1000.0 );
  }
  printscreen(s1, s2, &r,&b, &call_no, &br, p,t1,ini_time,maxtime);
  wrefresh(stdscr);
 }
 while (ch!='q');
 wclrtoeol(stdscr);
 wrefresh(stdscr);
 endwin();
}

canonical_original_code:
void main()
{
 initscr();
 wclear(stdscr);
 cbreak();
 wrefresh(stdscr);
 start_color();
 init_pair(1, 3, 4);
 init_pair(2, 0 , 1);
 init_pair(3, 7 , 3);
 init_pair(4, 7 , 4);
 init_pair(5, 1, 7);
 init_pair(6, 0 , 0);
 init_pair(9,3,7);
 init_pair(7, 7 , 1);
 init_pair(10, 7 , 7);
 init_pair(11, 0 , 7);
 init_pair(12, 1 , 7);
 init_pair(13, 4 , 7);
 init_pair(14, 5 , 7);
 int len1 = 5; int len2 = 1;
 long long runno = 0;
 struct timeval tim;
 struct timeval ini;
 int TIME;
 mvprintw(21/2,79/2-20,"Press 'o' for one-player and 't' for two-player:");
 wrefresh(stdscr);
 char c;
 do
 {
  c=wgetch(stdscr);
  if (!((c=='o')||(c=='t')))
  {
   wclear(stdscr);
   mvprintw(21/2,79/2-20,"Enter o or t only " );
   wrefresh(stdscr);
  }
 }while (!( (c=='o') || (c=='t') ) );
 wclear(stdscr);
 mvprintw(21/2,79/2-20,"Enter the level (1-3): " );
 wrefresh(stdscr);
 int lev;
 do
 {
  lev = wgetch(stdscr);
  if ((lev>'3')||(lev<='0'))
  {
   wclear(stdscr);
   mvprintw(21/2,79/2-20,"Enter 1-3 only " );
   wrefresh(stdscr);
  }
 }while ((lev>'3')||(lev<='0'));
 switch (lev)
 {
  case '1': TIME = 50;
    break;
  case '2': TIME = 40;
    break;
  case '3': TIME = 30;
    break;
 }
 if(c=='t')
 {
  wclear(stdscr);
  mvprintw(21/2,79/2-20,"Enter the length for Snake1:" );
  wrefresh(stdscr);
  char s[4];
  int i;
  do
  {
   for (i=0; i<4; i++)
   {
    s[i]=wgetch(stdscr);
    if (((s[i]==' ')||(s[i]=='\n'))&&(i!=0))
    {
     s[i]='\0';
     break;
    }
   }
   len1=(int)atoi(s);
   if(len1>70){
    wclear(stdscr);
    mvprintw(21/2,79/2-20,"Enter a length smaller than %d :",70 );
    wrefresh(stdscr);
   }
 }while(len1>70);
  wclear(stdscr);
  mvprintw(21/2,79/2-20,"Enter the length for Snake2:" );
  wrefresh(stdscr);
  do
  {
   for (i=0; i<4; i++)
   {
    s[i]=wgetch(stdscr);
    if (((s[i]==' ')||(s[i]=='\n'))&&(i!=0))
    {
     s[i]='\0';
     break;
    }
   }
   len2=(int)atoi(s);
   if(len2>70){
    wclear(stdscr);
    mvprintw(21/2,79/2-20,"Enter a length smaller than %d :",70 );
    wrefresh(stdscr);
   }
 }while(len2>70);
 }
 else{
  wclear(stdscr);
  mvprintw(21/2,79/2-20,"Enter the length for the Snake:" );
  wrefresh(stdscr);
  char s[4];
  int i;
  do
  {
   for (i=0; i<4; i++)
   {
    s[i]=wgetch(stdscr);
    if (((s[i]==' ')||(s[i]=='\n'))&&(i!=0))
    {
     s[i]='\0';
     break;
    }
   }
   len2=(int)atoi(s);
   if(len2>70){
    wclear(stdscr);
    mvprintw(21/2,79/2-20,"Enter a length smaller than %d :",70 );
    wrefresh(stdscr);
   }
 }while(len2>70);
 }
 int maxtime = 0;
 char temp[3];
 int i;
 wclear(stdscr);
  mvprintw(21/2,79/2-20,"Enter the Duration of the match (in minutes):" );
  wrefresh(stdscr);
 do
  {
   for (i=0; i<3; i++)
   {
    temp[i]=wgetch(stdscr);
    if (((temp[i]==' ')||(temp[i]=='\n'))&&(i!=0))
    {
     temp[i]='\0';
     break;
    }
   }
   maxtime=(int)atoi(temp);
   if(maxtime>15){
    wclear(stdscr);
    mvprintw(21/2,79/2-20,"Length of match should be lesser  than %d :",15 );
    wrefresh(stdscr);
   }
 }while(maxtime>15);
 struct reward_ r;
 mvprintw(21/2,79/2-30,"Enter the number of rewards which should be on the screen at a time:");
 wrefresh(stdscr);
 do
 {
  r.rewnum = wgetch(stdscr) - '0';
  if ((r.rewnum > 4)||(r.rewnum<= 0 ))
  {
   wclear(stdscr);
   mvprintw(21/2,79/2-20,"Enter 1-4 only " );
   wrefresh(stdscr);
  }
 }while ((r.rewnum>4)||r.rewnum<=0);
 int iq;
 for( iq=0 ; iq< 4 ; iq++ )
 r.rewcoord[iq].x = r.rewcoord[iq].y = -1 ;
 wtimeout(stdscr,(TIME));
 noecho();
 struct coord_ snake1 = make_coord(0, 0);
 struct coord_ snake2 = make_coord(79, 21);
 struct Queue_ *s1 = queue_new();
 s1 = queue_push(s1, snake1);
 for (i=1; i<len1; i++)
 {
  snake1 = make_coord(i, 0);
  s1 = queue_push(s1, snake1);
 }
 struct Queue_ *s2 = queue_new();
 s2 = queue_push(s2, snake2);
 for (i=1; i<len2; i++)
 {
  snake2 = make_coord(79 -i, 21);
  s2 = queue_push(s2, snake2);
 }
 keypad(stdscr, 1);
 wrefresh(stdscr);
 int ch;
 char snake1dir; char snake2dir;
 snake1dir='r';
 snake2dir='l';
 int set_dir1 = 0; int set_dir2 = 0;
 srand(time(((void *)0)));
 struct bomb_ b = {1,0,0,{10,10}};
 int bombx; int bomby;
 struct Points_ *p = mk_points();
 get_points(s1,s2,p);
 int call_no = 0;
 struct bombregion_ br;
 init_bombregion(&br, b);
 printscreen(s1, s2, &r ,&b,&call_no,&br,p,0,0,0);
 int nextexplode = ( rand() % 20 ) * 10 +runno+10;
 double t2 = 1000; double t1 = 0;
 double ini_time;
 gettimeofday(&ini, ((void *)0));
 ini_time = ini.tv_sec*1000 + ( ini.tv_usec / 1000.0 );
 init_reward (s1, s2, &r );
 do
 {
  gettimeofday(&tim, ((void *)0));
  runno++;
  if(b.isactive)
  {
   if(b.duration == 10 )
   {
    b.isactive=0;
    b.isexploding=1;
    nextexplode = ( rand() % 20 ) +runno + 20 ;
   }
   else
    b.duration ++;
  }
  else if ( runno == nextexplode )
  {
   b.isactive= 1 ;
   b.duration= 0 ;
   b.topleft.x = (rand()%79) ;
   b.topleft.y= (rand()%21) ;
  init_bombregion(&br,b);
  }
  t1 = tim.tv_sec*1000 + ( tim.tv_usec / 1000.0 );
  wtimeout(stdscr,(TIME));
  if( (t1-ini_time)/60000 > (double)maxtime )
   end_game(3,s1, s2,p);
  if(c=='o')
   ch = play_one(s1, s2, &snake2, &snake2dir, &r,p);
  else
   ch =play(s1, s2, &snake1, &snake2, &snake1dir, &snake2dir, &r,p);
  if (ch==1)
   break;
  if ( c=='o')
   auto_move(s1, s2, &snake1dir, &r, &b,&br,p, TIME);
  int col = collide(s1, s2, snake1dir, snake2dir);
  end_game(col,s1,s2,p);
  gettimeofday(&tim, ((void *)0));
     double t2 = tim.tv_sec*1000.0 + ( tim.tv_usec/1000.0 );
  while( t2-t1 < 2*TIME )
  {
   wtimeout(stdscr,(0));
   wgetch(stdscr);
   wgetch(stdscr);
   wgetch(stdscr);
   gettimeofday(&tim, ((void *)0));
       t2 = tim.tv_sec*1000.0 + ( tim.tv_usec/1000.0 );
  }
  printscreen(s1, s2, &r,&b, &call_no, &br, p,t1,ini_time,maxtime);
  wrefresh(stdscr);
 }
 while (ch!='q');
 wclrtoeol(stdscr);
 wrefresh(stdscr);
 endwin();
}

variable_types:
runno
long long

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: TIME int

variable_types: c char

variable_types: lev int

variable_types:
s
char [4]

variable_types: maxtime int

variable_types:
temp
char [3]

variable_types: struct reward_ { struct coord_ { int x; int y; } rewcoord[4]; int rewnum; }

variable_types: iq int

variable_types: struct Queue_ { struct Node_ { struct coord_ { int x; int y; } data; struct Node_ *next; } *head; struct Node_ *tail; } *

variable_types: ch int

variable_types: struct bomb_ { int isactive; int isexploding; int duration; struct coord_ { int x; int y; } topleft; }

variable_types: bombx int

variable_types: bomby int

variable_types: struct Points_ { int s1_points; int s2_points; } *

variable_types: struct bombregion_ { struct coord_ { int x; int y; } array[53]; }

variable_types: nextexplode int

variable_types: col int

user_defined_types: struct reward_ { struct coord_ rewcoord[4]; int rewnum; }

user_defined_types: struct bomb_ { int isactive; int isexploding; int duration; struct coord_ topleft; }

user_defined_types: struct bombregion_ { struct coord_ array[53]; }

user_defined_types: struct Queue_ { struct Node_ *head; struct Node_ *tail; }

user_defined_types: struct Node_ { struct coord_ data; struct Node_ *next; }


decompiled_code:
_QWORD *queue_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:
Queue* queue_new(){
 Queue* new_queue=(Queue*)malloc(sizeof(Queue));
 new_queue->head=((void *)0);
 new_queue->tail=((void *)0);
 return new_queue;
}

canonical_original_code:
struct Queue_ *queue_new(){
 struct Queue_ *new_queue = (Queue*)malloc(sizeof(Queue));
 new_queue->head=((void *)0);
 new_queue->tail=((void *)0);
 return new_queue;
}

return_type: struct Queue_ { struct Node_ { struct coord_ { int x; int y; } data; struct Node_ *next; } *head; struct Node_ *tail; } *


original_code:
Queue* queue_pop( Queue* q ){
 Node* ptr;
 if((q->tail)!=((void *)0)){
  if((q->tail)->next!=((void *)0)){
   ptr=q->tail;
   q->tail=(q->tail)->next;
   free(ptr);
   return q;
  }
  else{
   ptr=q->tail;
   free(ptr);
   q->head=((void *)0);
   q->tail=((void *)0);
   return q;
  }
 }
}

canonical_original_code:
struct Queue_ *queue_pop(struct Queue_ *q){
 struct Node_ *ptr;
 if((q->tail)!=((void *)0)){
  if((q->tail)->next!=((void *)0)){
   ptr=q->tail;
   q->tail=(q->tail)->next;
   free(ptr);
   return q;
  }
  else{
   ptr=q->tail;
   free(ptr);
   q->head=((void *)0);
   q->tail=((void *)0);
   return q;
  }
 }
}

variable_types:
q
struct Queue_ *

variable_types: struct Node_ { struct coord_ { int x; int y; } data; struct Node_ *next; } *


decompiled_code:
void __fastcall queue_delete(_QWORD *a1)
{
_QWORD *v1; // rax

if ( a1[1] )
{
do
{
queue_pop(a1);
a1 = v1;
}
while ( v1[1] );
}
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1)
{
_QWORD *v1; // rax

if ( a1[1] )
{
do
{
func1(a1);
a1 = v1;
}
while ( v1[1] );
}
}

original_code:
void queue_delete( Queue* q ){
 while((q->tail)!=((void *)0)){
  q=queue_pop(q);
 }
}

canonical_original_code:
void queue_delete(struct Queue_ *q){
 while((q->tail)!=((void *)0)){
  q=queue_pop(q);
 }
}


decompiled_code:
__int64 __fastcall snake_tail(__int64 a1, _DWORD *a2)
{
unsigned int *v2; // rax
unsigned int v3; // edx
__int64 v4; // rax
__int64 result; // rax

v2 = *(unsigned int **)(a1 + 8);
if ( v2 )
{
v3 = *v2;
v4 = v2[1];
if ( a2 )
*a2 = 0;
result = (v4 << 32) | v3;
}
else
{
if ( a2 )
*a2 = 1;
result = 0LL;
}
return result;
}

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

v2 = *(unsigned int **)(a1 + 8);
if ( v2 )
{
v3 = *v2;
v4 = v2[1];
if ( a2 )
*a2 = 0;
result = (v4 << 32) | v3;
}
else
{
if ( a2 )
*a2 = 1;
result = 0LL;
}
return result;
}

original_code:
coord snake_tail( Queue* q, int* error ){
 coord answer;
 if(q->tail!=((void *)0)){
  answer=(q->tail)->data;
  if(error!=((void *)0))
   *error=0;
  return answer;
 }
 else{
  if(error!=((void *)0))
   *error=1;
  return answer;
 }
}

canonical_original_code:
struct coord_ snake_tail(struct Queue_ *q, int *error){
 struct coord_ answer;
 if(q->tail!=((void *)0)){
  answer=(q->tail)->data;
  if(error!=((void *)0))
   *error=0;
  return answer;
 }
 else{
  if(error!=((void *)0))
   *error=1;
  return answer;
 }
}

variable_types: struct Queue_ { struct Node_ { struct coord_ data; struct Node_ *next; } *head; struct Node_ *tail; } *

variable_types:
error
int *

variable_types:
answer
struct coord_ { int x; int y; }

return_type: struct coord_ { int x; int y; }


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

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

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

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

original_code:
int queue_size( Queue* q ){
 int size=0;
 Node* next_node=q->tail;
 while(next_node!=((void *)0)){
  size++;
  next_node=next_node->next;
 }
 return size;
}

canonical_original_code:
int queue_size(struct Queue_ *q){
 int size = 0;
 struct Node_ *next_node = q->tail;
 while(next_node!=((void *)0)){
  size++;
  next_node=next_node->next;
 }
 return size;
}

variable_types: size int


decompiled_code:
int __fastcall queue_print(__int64 a1)
{
unsigned int *i; // rbx

for ( i = *(unsigned int **)(a1 + 8); i; i = (unsigned int *)*((_QWORD *)i + 1) )
printw("(%d,%d) ", i[1], *i);
printw("\n");
return wrefresh(stdscr);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
unsigned int *i; // rbx

for ( i = *(unsigned int **)(a1 + 8); i; i = (unsigned int *)*((_QWORD *)i + 1) )
printw("(%d,%d) ", i[1], *i);
printw("\n");
return wrefresh(stdscr);
}

original_code:
void queue_print( Queue* q ){
 Node* next_node=q->tail;
 while(next_node!=((void *)0)){
  printw("(%d,%d) ",next_node->data.y,next_node->data.x);
  next_node=next_node->next;
 }
 printw("\n");
 wrefresh(stdscr);
}

canonical_original_code:
void queue_print(struct Queue_ *q){
 struct Node_ *next_node = q->tail;
 while(next_node!=((void *)0)){
  printw("(%d,%d) ",next_node->data.y,next_node->data.x);
  next_node=next_node->next;
 }
 printw("\n");
 wrefresh(stdscr);
}


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

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

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

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

original_code:
coord get_head(Queue *q)
{
 coord ans;
 if(q->head!=((void *)0))
 return (q->head)->data;
 else return ans;
}

canonical_original_code:
struct coord_ get_head(struct Queue_ *q)
{
 struct coord_ ans;
 if(q->head!=((void *)0))
 return (q->head)->data;
 else return ans;
}

variable_types:
ans
struct coord_ { int x; int y; }


decompiled_code:
__int64 __fastcall queue_search(__int64 a1, unsigned __int64 a2)
{
__int64 result; // rax
int v3; // edx
unsigned __int64 v4; // rsi

result = *(_QWORD *)(a1 + 8);
if ( !result )
return 0LL;
v3 = a2;
v4 = HIDWORD(a2);
while ( *(_DWORD *)result != v3 || *(_DWORD *)(result + 4) != (_DWORD)v4 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int64 a2)
{
__int64 result; // rax
int v3; // edx
unsigned __int64 v4; // rsi

result = *(_QWORD *)(a1 + 8);
if ( !result )
return 0LL;
v3 = a2;
v4 = HIDWORD(a2);
while ( *(_DWORD *)result != v3 || *(_DWORD *)(result + 4) != (_DWORD)v4 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return 1LL;
}

original_code:
int queue_search(Queue * q , coord r )
{
 Node* temp = q->tail;
 while( temp != ((void *)0))
 {
     if( temp->data.x == r.x && temp->data.y == r.y )
     return 1;
        temp=temp->next;
 }
 return 0;
}

canonical_original_code:
int queue_search(struct Queue_ *q, struct coord_ r)
{
 struct Node_ *temp = q->tail;
 while( temp != ((void *)0))
 {
     if( temp->data.x == r.x && temp->data.y == r.y )
     return 1;
        temp=temp->next;
 }
 return 0;
}

variable_types:
r
struct coord_


decompiled_code:
__int64 __fastcall auto_dist_to_reward(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // edx

v2 = a2 - a1;
if ( (int)a1 > (int)a2 )
v2 = a1 - a2;
if ( v2 > 39 )
v2 = 79 - v2;
v3 = HIDWORD(a2) - HIDWORD(a1);
if ( SHIDWORD(a1) > SHIDWORD(a2) )
v3 = HIDWORD(a1) - HIDWORD(a2);
if ( v3 > 10 )
v3 = 21 - v3;
return (unsigned int)(v3 + v2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // edx

v2 = a2 - a1;
if ( (int)a1 > (int)a2 )
v2 = a1 - a2;
if ( v2 > 39 )
v2 = 79 - v2;
v3 = HIDWORD(a2) - HIDWORD(a1);
if ( SHIDWORD(a1) > SHIDWORD(a2) )
v3 = HIDWORD(a1) - HIDWORD(a2);
if ( v3 > 10 )
v3 = 21 - v3;
return (unsigned int)(v3 + v2);
}

original_code:
int auto_dist_to_reward(coord auto_head, coord rew)
{
 int distx=0, disty=0;
 distx+=(auto_head.x>rew.x)?(auto_head.x-rew.x):(rew.x-auto_head.x);
 if (distx>79/2)
  distx = 79 -distx;
 disty+=(auto_head.y>rew.y)?(auto_head.y-rew.y):(rew.y-auto_head.y);
 if (disty>21/2)
  disty = 21 -disty;
 return (distx+disty);
}

canonical_original_code:
int auto_dist_to_reward(struct coord_ auto_head, struct coord_ rew)
{
 int distx = 0; int disty = 0;
 distx+=(auto_head.x>rew.x)?(auto_head.x-rew.x):(rew.x-auto_head.x);
 if (distx>79/2)
  distx = 79 -distx;
 disty+=(auto_head.y>rew.y)?(auto_head.y-rew.y):(rew.y-auto_head.y);
 if (disty>21/2)
  disty = 21 -disty;
 return (distx+disty);
}

variable_types:
rew
struct coord_

variable_types: distx int

variable_types: disty int


decompiled_code:
__int64 __fastcall auto_check_bomb(_DWORD *a1, _DWORD *a2, _DWORD *a3)
{
_DWORD *v4; // rax

if ( a1[1] != 1 && *a1 != 1 )
return 0LL;
v4 = a2;
do
{
if ( *v4 == *a3 && v4[1] == a3[1] )
return 1LL;
v4 += 2;
}
while ( v4 != a2 + 106 );
return 0LL;
}

original_code:
int auto_check_bomb(bomb *b, bombregion *br, coord * new_head)
{
 int i;
 if ((b->isexploding==1)|| (b->isactive==1))
 {
  for (i=0; i<53; i++)
   if ((br->array[i].x==new_head->x) && (br->array[i].y==new_head->y))
    return 1;
 }
 return 0;
}

canonical_original_code:
int auto_check_bomb(struct bomb_ *b, struct bombregion_ *br, struct coord_ *new_head)
{
 int i;
 if ((b->isexploding==1)|| (b->isactive==1))
 {
  for (i=0; i<53; i++)
   if ((br->array[i].x==new_head->x) && (br->array[i].y==new_head->y))
    return 1;
 }
 return 0;
}

variable_types: struct bomb_ { int isactive; int isexploding; int duration; struct coord_ { int x; int y; } topleft; } *

variable_types: struct bombregion_ { struct coord_ array[53]; } *

variable_types: i int


decompiled_code:
__int64 __fastcall generate_perm(__int64 *a1, __int64 a2, _DWORD *a3, int a4)
{
__int64 result; // rax
__int64 v7; // rbx
__int64 v8; // r15
int v9; // er14
__int64 v10; // r12
__int64 v11; // rbx

result = *(unsigned int *)(a2 + 32);
if ( (_DWORD)result == a4 )
{
result = auto_dist_to_reward(*a1, *(_QWORD *)(a2 + 8LL * perm[0]));
v9 = result;
if ( a4 > 1 )
{
v10 = (unsigned int)(a4 - 2);
v11 = 0LL;
do
{
v9 += auto_dist_to_reward(*(_QWORD *)(a2 + 8LL * perm[v11]), *(_QWORD *)(a2 + 8LL * perm[v11 + 1]));
result = v11++;
}
while ( v10 != result );
}
if ( *a3 > v9 )
*a3 = v9;
}
else
{
v7 = 0LL;
v8 = a4;
if ( (int)result > 0 )
{
do
{
if ( !over[v7] )
{
perm[v8] = v7;
over[v7] = 1;
result = generate_perm(a1, a2, a3, (unsigned int)(a4 + 1));
over[v7] = 0;
}
++v7;
}
while ( *(_DWORD *)(a2 + 32) > (int)v7 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, __int64 a2, _DWORD *a3, int a4)
{
__int64 result; // rax
__int64 v7; // rbx
__int64 v8; // r15
int v9; // er14
__int64 v10; // r12
__int64 v11; // rbx

result = *(unsigned int *)(a2 + 32);
if ( (_DWORD)result == a4 )
{
result = func0(*a1, *(_QWORD *)(a2 + 8LL * perm[0]));
v9 = result;
if ( a4 > 1 )
{
v10 = (unsigned int)(a4 - 2);
v11 = 0LL;
do
{
v9 += func0(*(_QWORD *)(a2 + 8LL * perm[v11]), *(_QWORD *)(a2 + 8LL * perm[v11 + 1]));
result = v11++;
}
while ( v10 != result );
}
if ( *a3 > v9 )
*a3 = v9;
}
else
{
v7 = 0LL;
v8 = a4;
if ( (int)result > 0 )
{
do
{
if ( !over[v7] )
{
perm[v8] = v7;
over[v7] = 1;
result = func2(a1, a2, a3, (unsigned int)(a4 + 1));
over[v7] = 0;
}
++v7;
}
while ( *(_DWORD *)(a2 + 32) > (int)v7 );
}
}
return result;
}

original_code:
void generate_perm(coord *new_head, reward *rew, int *min_distance, int ctr)
{
 int i, j;
 if (ctr==rew->rewnum)
 {
  int dist = auto_dist_to_reward(*new_head, rew->rewcoord[perm[0]]);
  for (j=1; j<rew->rewnum; j++)
   dist+= auto_dist_to_reward(rew->rewcoord[perm[j-1]], rew->rewcoord[perm[j]]);
  if (*min_distance>dist)
   *min_distance=dist;
  return;
 }
 for (i=0; i<rew->rewnum; i++)
 {
  if (over[i]==0)
  {
   perm[ctr]=i;
   over[i]=1;
   generate_perm(new_head, rew, min_distance, ctr+1);
   over[i]=0;
  }
 }
}

canonical_original_code:
void generate_perm(struct coord_ *new_head, struct reward_ *rew, int *min_distance, int ctr)
{
 int i; int j;
 if (ctr==rew->rewnum)
 {
  int dist = auto_dist_to_reward(*new_head, rew->rewcoord[perm[0]]);
  for (j=1; j<rew->rewnum; j++)
   dist+= auto_dist_to_reward(rew->rewcoord[perm[j-1]], rew->rewcoord[perm[j]]);
  if (*min_distance>dist)
   *min_distance=dist;
  return;
 }
 for (i=0; i<rew->rewnum; i++)
 {
  if (over[i]==0)
  {
   perm[ctr]=i;
   over[i]=1;
   generate_perm(new_head, rew, min_distance, ctr+1);
   over[i]=0;
  }
 }
}

variable_types: struct reward_ { struct coord_ rewcoord[4]; int rewnum; } *

variable_types: ctr int

variable_types: j int

variable_types: dist int


original_code:
int auto_move(Queue *s1, Queue *s2, char *snake1dir, reward *rew, bomb *b, bombregion *br, Points* p, int TIME)
{
 coord auto_head = get_head(s1);
 coord new_head = auto_head;
 int max_dist = 4*(79 +21);
 int points[4]={max_dist, max_dist, max_dist, max_dist};
 switch(*snake1dir)
 {
  case 'u': points[2]=(max_dist+2);
    break;
  case 'r': points[3]=(max_dist+2);
    break;
  case 'd': points[0]=(max_dist+2);
    break;
  case 'l': points[1]=(max_dist+2);
    break;
 }
 int i;
 for (i=0; i<rew->rewnum; i++)
   {
    over[i]=0;
    perm[i]=-1;
   }
 if (points[0]!=(max_dist+2))
 {
  if (new_head.y==0)
   new_head.y = 21;
  else
   new_head.y--;
  if (auto_collide(s2,s1, new_head)==1)
   points[0]=(max_dist+2);
  else if (auto_check_bomb(b, br, &new_head)==1)
   points[0]=(max_dist-2);
  else
  {
   generate_perm(&new_head, rew, &points[0], 0);
   for (i=0; i<rew->rewnum; i++)
   {
    over[i]=0;
    perm[i]=-1;
   }
  }
 }
 new_head=auto_head;
 if (points[1]!=(max_dist+2))
 {
  if (new_head.x==79)
   new_head.x = 0;
  else
   new_head.x++;
  if (auto_collide(s2,s1, new_head)==1)
   points[1]=(max_dist+2);
  else if (auto_check_bomb(b, br, &new_head)==1)
   points[1]=max_dist-2;
  else
  {
   generate_perm(&new_head, rew, &points[1], 0);
   for (i=0; i<rew->rewnum; i++)
   {
    over[i]=0;
    perm[i]=-1;
   }
  }
 }
 new_head=auto_head;
 if (points[2]!=(max_dist+2))
 {
  if (new_head.y==21)
   new_head.y = 0;
  else
   new_head.y++;
  if (auto_collide(s2,s1, new_head)==1)
   points[2]=(max_dist+2);
  else if (auto_check_bomb(b, br, &new_head)==1)
   points[2]=(max_dist-2);
  else
  {
   generate_perm(&new_head, rew, &points[2], 0);
   for (i=0; i<rew->rewnum; i++)
   {
    over[i]=0;
    perm[i]=-1;
   }
  }
 }
 new_head=auto_head;
 if (points[3]!=(max_dist+2))
 {
  if (new_head.x==0)
   new_head.x = 79;
  else
   new_head.x--;
  if (auto_collide(s2, s1, new_head)==1)
   points[3]=(max_dist+2);
  else if (auto_check_bomb(b, br, &new_head)==1)
   points[3]=max_dist-2;
  else
  {
   generate_perm(&new_head, rew, &points[3], 0);
   for (i=0; i<rew->rewnum; i++)
   {
    over[i]=0;
    perm[i]=-1;
   }
  }
 }
 int min = points[0];
 int pos=0;
 for (i=1; i<4; i++)
 {
  if (min>points[i])
  {
   min=points[i];
   pos=i;
  }
 }
 new_head=auto_head;
 wtimeout(stdscr,(TIME));
 switch(pos)
 {
  case 0: if (new_head.y==0)
     new_head.y = 21;
    else
     new_head.y--;
    *snake1dir='u';
    break;
  case 1: if (new_head.x==79)
     new_head.x = 0;
    else
     new_head.x++;
    *snake1dir='r';
    break;
  case 2: if (new_head.y==21)
     new_head.y = 0;
    else
     new_head.y++;
    *snake1dir='d';
    break;
  case 3: if (new_head.x==0)
     new_head.x = 79;
    else
     new_head.x--;
    *snake1dir='l';
    break;
 }
 s1 = queue_push(s1, new_head);
 int flag=0;
  for (i=0; i<rew->rewnum; i++)
  {
   if ((rew->rewcoord[i].x==new_head.x)&&(rew->rewcoord[i].y==new_head.y))
   {
    rew = mk_reward(s1, s2, rew, i);
    p->s1_points++;
    flag=1;
    break;
   }
  }
  if (flag==0)
   s1 = queue_pop(s1);
 usleep(TIME*1000);
 return 0;
}

canonical_original_code:
int auto_move(struct Queue_ *s1, struct Queue_ *s2, char *snake1dir, struct reward_ *rew, struct bomb_ *b, struct bombregion_ *br, struct Points_ *p, int TIME)
{
 struct coord_ auto_head = get_head(s1);
 struct coord_ new_head = auto_head;
 int max_dist = 4*(79 +21);
 int points[4] = {max_dist, max_dist, max_dist, max_dist};
 switch(*snake1dir)
 {
  case 'u': points[2]=(max_dist+2);
    break;
  case 'r': points[3]=(max_dist+2);
    break;
  case 'd': points[0]=(max_dist+2);
    break;
  case 'l': points[1]=(max_dist+2);
    break;
 }
 int i;
 for (i=0; i<rew->rewnum; i++)
   {
    over[i]=0;
    perm[i]=-1;
   }
 if (points[0]!=(max_dist+2))
 {
  if (new_head.y==0)
   new_head.y = 21;
  else
   new_head.y--;
  if (auto_collide(s2,s1, new_head)==1)
   points[0]=(max_dist+2);
  else if (auto_check_bomb(b, br, &new_head)==1)
   points[0]=(max_dist-2);
  else
  {
   generate_perm(&new_head, rew, &points[0], 0);
   for (i=0; i<rew->rewnum; i++)
   {
    over[i]=0;
    perm[i]=-1;
   }
  }
 }
 new_head=auto_head;
 if (points[1]!=(max_dist+2))
 {
  if (new_head.x==79)
   new_head.x = 0;
  else
   new_head.x++;
  if (auto_collide(s2,s1, new_head)==1)
   points[1]=(max_dist+2);
  else if (auto_check_bomb(b, br, &new_head)==1)
   points[1]=max_dist-2;
  else
  {
   generate_perm(&new_head, rew, &points[1], 0);
   for (i=0; i<rew->rewnum; i++)
   {
    over[i]=0;
    perm[i]=-1;
   }
  }
 }
 new_head=auto_head;
 if (points[2]!=(max_dist+2))
 {
  if (new_head.y==21)
   new_head.y = 0;
  else
   new_head.y++;
  if (auto_collide(s2,s1, new_head)==1)
   points[2]=(max_dist+2);
  else if (auto_check_bomb(b, br, &new_head)==1)
   points[2]=(max_dist-2);
  else
  {
   generate_perm(&new_head, rew, &points[2], 0);
   for (i=0; i<rew->rewnum; i++)
   {
    over[i]=0;
    perm[i]=-1;
   }
  }
 }
 new_head=auto_head;
 if (points[3]!=(max_dist+2))
 {
  if (new_head.x==0)
   new_head.x = 79;
  else
   new_head.x--;
  if (auto_collide(s2, s1, new_head)==1)
   points[3]=(max_dist+2);
  else if (auto_check_bomb(b, br, &new_head)==1)
   points[3]=max_dist-2;
  else
  {
   generate_perm(&new_head, rew, &points[3], 0);
   for (i=0; i<rew->rewnum; i++)
   {
    over[i]=0;
    perm[i]=-1;
   }
  }
 }
 int min = points[0];
 int pos = 0;
 for (i=1; i<4; i++)
 {
  if (min>points[i])
  {
   min=points[i];
   pos=i;
  }
 }
 new_head=auto_head;
 wtimeout(stdscr,(TIME));
 switch(pos)
 {
  case 0: if (new_head.y==0)
     new_head.y = 21;
    else
     new_head.y--;
    *snake1dir='u';
    break;
  case 1: if (new_head.x==79)
     new_head.x = 0;
    else
     new_head.x++;
    *snake1dir='r';
    break;
  case 2: if (new_head.y==21)
     new_head.y = 0;
    else
     new_head.y++;
    *snake1dir='d';
    break;
  case 3: if (new_head.x==0)
     new_head.x = 79;
    else
     new_head.x--;
    *snake1dir='l';
    break;
 }
 s1 = queue_push(s1, new_head);
 int flag = 0;
  for (i=0; i<rew->rewnum; i++)
  {
   if ((rew->rewcoord[i].x==new_head.x)&&(rew->rewcoord[i].y==new_head.y))
   {
    rew = mk_reward(s1, s2, rew, i);
    p->s1_points++;
    flag=1;
    break;
   }
  }
  if (flag==0)
   s1 = queue_pop(s1);
 usleep(TIME*1000);
 return 0;
}

variable_types: struct Queue_ { struct Node_ { struct coord_ { int x; int y; } data; struct Node_ *next; } *head; struct Node_ *tail; } *

variable_types: struct bomb_ { int isactive; int isexploding; int duration; struct coord_ topleft; } *

variable_types: struct Points_ { int s1_points; int s2_points; } *

variable_types: TIME int

variable_types:
points
int [4]

variable_types: min int

variable_types: pos int

variable_types: flag int


original_code:
int play_one(Queue *s1, Queue *s2, coord *snake2, char *snake2dir, reward *r,Points* p)
{
  int ch;
  int set_dir2=0;
  ch=wgetch(stdscr);
  switch (ch)
  {
    case (int) 'q': return 1;
    case 259: if ((*snake2dir=='r')||(*snake2dir=='l'))
       {
        if (snake2->y==0)
         snake2->y = 21;
        else
         snake2->y--;
        *snake2dir = 'u';
        set_dir2=1;
       }
       break;
    case 258 : if ((*snake2dir=='r')||(*snake2dir=='l'))
       {
        if (snake2->y==21)
         snake2->y = 0;
        else
         snake2->y++;
        set_dir2=1;
        *snake2dir = 'd';
       }
       break;
    case 260 : if ((*snake2dir=='u')||(*snake2dir=='d'))
       {
        if (snake2->x==0)
         snake2->x = 79;
        else
         snake2->x--;
        set_dir2=1;
        *snake2dir = 'l';
       }
       break;
    case 261: if ((*snake2dir=='u')||(*snake2dir=='d'))
       {
        if (snake2->x==79)
         snake2->x = 0;
        else
         snake2->x++;
        set_dir2=1;
        *snake2dir = 'r';
       }
       break;
   }
  if (set_dir2==0)
  {
   switch(*snake2dir)
   {
    case 'l': if (snake2->x==0)
       snake2->x = 79;
      else
       snake2->x--;
      break;
    case 'r': if (snake2->x==79)
       snake2->x = 0;
      else
       snake2->x++;
      break;
    case 'u': if (snake2->y==0)
       snake2->y = 21;
      else
       snake2->y--;
      break;
    case 'd': if (snake2->y==21)
       snake2->y = 0;
      else
       snake2->y++;
      break;
   }
  }
  s2 = queue_push(s2, *snake2);
  int flag=0, i;
  for (i=0; i<r->rewnum; i++)
  {
   if ((r->rewcoord[i].x==snake2->x)&&(r->rewcoord[i].y==snake2->y))
   {
    r = mk_reward(s1, s2, r, i);
    p->s2_points++;
    flag=1;
    break;
   }
  }
  if (flag==0)
   s2 = queue_pop(s2);
 return 0;
}

canonical_original_code:
int play_one(struct Queue_ *s1, struct Queue_ *s2, struct coord_ *snake2, char *snake2dir, struct reward_ *r, struct Points_ *p)
{
  int ch;
  int set_dir2 = 0;
  ch=wgetch(stdscr);
  switch (ch)
  {
    case (int) 'q': return 1;
    case 259: if ((*snake2dir=='r')||(*snake2dir=='l'))
       {
        if (snake2->y==0)
         snake2->y = 21;
        else
         snake2->y--;
        *snake2dir = 'u';
        set_dir2=1;
       }
       break;
    case 258 : if ((*snake2dir=='r')||(*snake2dir=='l'))
       {
        if (snake2->y==21)
         snake2->y = 0;
        else
         snake2->y++;
        set_dir2=1;
        *snake2dir = 'd';
       }
       break;
    case 260 : if ((*snake2dir=='u')||(*snake2dir=='d'))
       {
        if (snake2->x==0)
         snake2->x = 79;
        else
         snake2->x--;
        set_dir2=1;
        *snake2dir = 'l';
       }
       break;
    case 261: if ((*snake2dir=='u')||(*snake2dir=='d'))
       {
        if (snake2->x==79)
         snake2->x = 0;
        else
         snake2->x++;
        set_dir2=1;
        *snake2dir = 'r';
       }
       break;
   }
  if (set_dir2==0)
  {
   switch(*snake2dir)
   {
    case 'l': if (snake2->x==0)
       snake2->x = 79;
      else
       snake2->x--;
      break;
    case 'r': if (snake2->x==79)
       snake2->x = 0;
      else
       snake2->x++;
      break;
    case 'u': if (snake2->y==0)
       snake2->y = 21;
      else
       snake2->y--;
      break;
    case 'd': if (snake2->y==21)
       snake2->y = 0;
      else
       snake2->y++;
      break;
   }
  }
  s2 = queue_push(s2, *snake2);
  int flag = 0; int i;
  for (i=0; i<r->rewnum; i++)
  {
   if ((r->rewcoord[i].x==snake2->x)&&(r->rewcoord[i].y==snake2->y))
   {
    r = mk_reward(s1, s2, r, i);
    p->s2_points++;
    flag=1;
    break;
   }
  }
  if (flag==0)
   s2 = queue_pop(s2);
 return 0;
}

variable_types: ch int

user_defined_types: struct Points_ { int s1_points; int s2_points; }


play

original_code:
int play(Queue *s1, Queue *s2, coord* snake1, coord *snake2, char *snake1dir, char *snake2dir, reward *r,Points* p )
{
  int ch;
  int set_dir1=0;
  int set_dir2=0;
  int iter;
 for (iter=0; iter<2; iter++)
 {
  ch=wgetch(stdscr);
  switch (ch)
  {
    case (int)'q': return 1;
    case (int)'w': if (((*snake1dir=='r')||(*snake1dir=='l'))&&(set_dir1==0))
       {
        if (snake1->y==0)
         snake1->y = 21;
        else
         snake1->y--;
        *snake1dir = 'u';
        set_dir1=1;
       }
       break;
    case (int)'s': if (((*snake1dir=='r')||(*snake1dir=='l'))&&(set_dir1==0))
       {
        if (snake1->y==21)
         snake1->y = 0;
        else
         snake1->y++;
        set_dir1=1;
        *snake1dir = 'd';
       }
       break;
    case (int)'a': if (((*snake1dir=='u')||(*snake1dir=='d'))&&(set_dir1==0))
       {
        if (snake1->x==0)
         snake1->x = 79;
        else
         snake1->x--;
        set_dir1=1;
        *snake1dir = 'l';
       }
       break;
    case (int)'d': if (((*snake1dir=='u')||(*snake1dir=='d'))&&(set_dir1==0))
       {
        if (snake1->x==79)
         snake1->x = 0;
        else
         snake1->x++;
        set_dir1=1;
        *snake1dir = 'r';
       }
       break;
    case 259: if (((*snake2dir=='r')||(*snake2dir=='l'))&&(set_dir2==0))
       {
        if (snake2->y==0)
         snake2->y = 21;
        else
         snake2->y--;
        *snake2dir = 'u';
        set_dir2=1;
       }
       break;
    case 258 : if (((*snake2dir=='r')||(*snake2dir=='l'))&&(set_dir2==0))
       {
        if (snake2->y==21)
         snake2->y = 0;
        else
         snake2->y++;
        set_dir2=1;
        *snake2dir = 'd';
       }
       break;
    case 260 : if (((*snake2dir=='u')||(*snake2dir=='d'))&&(set_dir2==0))
       {
        if (snake2->x==0)
         snake2->x = 79;
        else
         snake2->x--;
        set_dir2=1;
        *snake2dir = 'l';
       }
       break;
    case 261: if (((*snake2dir=='u')||(*snake2dir=='d'))&&(set_dir2==0))
       {
        if (snake2->x==79)
         snake2->x = 0;
        else
         snake2->x++;
        set_dir2=1;
        *snake2dir = 'r';
       }
       break;
   }
  }
  if (set_dir1==0)
  {
   switch(*snake1dir)
   {
    case 'l': if (snake1->x==0)
       snake1->x = 79;
      else
       snake1->x--;
      break;
    case 'r': if (snake1->x==79)
       snake1->x = 0;
      else
       snake1->x++;
      break;
    case 'u': if (snake1->y==0)
       snake1->y = 21;
      else
       snake1->y--;
      break;
    case 'd': if (snake1->y==21)
       snake1->y = 0;
      else
       snake1->y++;
      break;
   }
  }
  if (set_dir2==0)
  {
   switch(*snake2dir)
   {
    case 'l': if (snake2->x==0)
       snake2->x = 79;
      else
       snake2->x--;
      break;
    case 'r': if (snake2->x==79)
       snake2->x = 0;
      else
       snake2->x++;
      break;
    case 'u': if (snake2->y==0)
       snake2->y = 21;
      else
       snake2->y--;
      break;
    case 'd': if (snake2->y==21)
       snake2->y = 0;
      else
       snake2->y++;
      break;
   }
  }
  s1 = queue_push(s1, *snake1);
  s2 = queue_push(s2, *snake2);
  int flag=0, i, check=-1;
  for (i=0; i<r->rewnum; i++)
  {
   if ((r->rewcoord[i].x==snake2->x)&&(r->rewcoord[i].y==snake2->y))
   {
    r = mk_reward(s1, s2, r, i);
    p->s2_points++;
    flag=1;
    break;
   }
  }
  if (flag==0)
   s2 = queue_pop(s2);
  flag=0;
  coord s1_head = get_head(s1);
  for (i=0; i<r->rewnum; i++)
  {
   if ((r->rewcoord[i].x==snake1->x)&&(r->rewcoord[i].y==snake1->y))
   {
    r = mk_reward(s1, s2, r, i);
    p->s1_points++;
    flag=1;
    break;
   }
  }
  if (flag==0)
   s1 = queue_pop(s1);
 return 0;
}

canonical_original_code:
int play(struct Queue_ *s1, struct Queue_ *s2, struct coord_ *snake1, struct coord_ *snake2, char *snake1dir, char *snake2dir, struct reward_ *r, struct Points_ *p)
{
  int ch;
  int set_dir1 = 0;
  int set_dir2 = 0;
  int iter;
 for (iter=0; iter<2; iter++)
 {
  ch=wgetch(stdscr);
  switch (ch)
  {
    case (int)'q': return 1;
    case (int)'w': if (((*snake1dir=='r')||(*snake1dir=='l'))&&(set_dir1==0))
       {
        if (snake1->y==0)
         snake1->y = 21;
        else
         snake1->y--;
        *snake1dir = 'u';
        set_dir1=1;
       }
       break;
    case (int)'s': if (((*snake1dir=='r')||(*snake1dir=='l'))&&(set_dir1==0))
       {
        if (snake1->y==21)
         snake1->y = 0;
        else
         snake1->y++;
        set_dir1=1;
        *snake1dir = 'd';
       }
       break;
    case (int)'a': if (((*snake1dir=='u')||(*snake1dir=='d'))&&(set_dir1==0))
       {
        if (snake1->x==0)
         snake1->x = 79;
        else
         snake1->x--;
        set_dir1=1;
        *snake1dir = 'l';
       }
       break;
    case (int)'d': if (((*snake1dir=='u')||(*snake1dir=='d'))&&(set_dir1==0))
       {
        if (snake1->x==79)
         snake1->x = 0;
        else
         snake1->x++;
        set_dir1=1;
        *snake1dir = 'r';
       }
       break;
    case 259: if (((*snake2dir=='r')||(*snake2dir=='l'))&&(set_dir2==0))
       {
        if (snake2->y==0)
         snake2->y = 21;
        else
         snake2->y--;
        *snake2dir = 'u';
        set_dir2=1;
       }
       break;
    case 258 : if (((*snake2dir=='r')||(*snake2dir=='l'))&&(set_dir2==0))
       {
        if (snake2->y==21)
         snake2->y = 0;
        else
         snake2->y++;
        set_dir2=1;
        *snake2dir = 'd';
       }
       break;
    case 260 : if (((*snake2dir=='u')||(*snake2dir=='d'))&&(set_dir2==0))
       {
        if (snake2->x==0)
         snake2->x = 79;
        else
         snake2->x--;
        set_dir2=1;
        *snake2dir = 'l';
       }
       break;
    case 261: if (((*snake2dir=='u')||(*snake2dir=='d'))&&(set_dir2==0))
       {
        if (snake2->x==79)
         snake2->x = 0;
        else
         snake2->x++;
        set_dir2=1;
        *snake2dir = 'r';
       }
       break;
   }
  }
  if (set_dir1==0)
  {
   switch(*snake1dir)
   {
    case 'l': if (snake1->x==0)
       snake1->x = 79;
      else
       snake1->x--;
      break;
    case 'r': if (snake1->x==79)
       snake1->x = 0;
      else
       snake1->x++;
      break;
    case 'u': if (snake1->y==0)
       snake1->y = 21;
      else
       snake1->y--;
      break;
    case 'd': if (snake1->y==21)
       snake1->y = 0;
      else
       snake1->y++;
      break;
   }
  }
  if (set_dir2==0)
  {
   switch(*snake2dir)
   {
    case 'l': if (snake2->x==0)
       snake2->x = 79;
      else
       snake2->x--;
      break;
    case 'r': if (snake2->x==79)
       snake2->x = 0;
      else
       snake2->x++;
      break;
    case 'u': if (snake2->y==0)
       snake2->y = 21;
      else
       snake2->y--;
      break;
    case 'd': if (snake2->y==21)
       snake2->y = 0;
      else
       snake2->y++;
      break;
   }
  }
  s1 = queue_push(s1, *snake1);
  s2 = queue_push(s2, *snake2);
  int flag = 0; int i; int check = -1;
  for (i=0; i<r->rewnum; i++)
  {
   if ((r->rewcoord[i].x==snake2->x)&&(r->rewcoord[i].y==snake2->y))
   {
    r = mk_reward(s1, s2, r, i);
    p->s2_points++;
    flag=1;
    break;
   }
  }
  if (flag==0)
   s2 = queue_pop(s2);
  flag=0;
  struct coord_ s1_head = get_head(s1);
  for (i=0; i<r->rewnum; i++)
  {
   if ((r->rewcoord[i].x==snake1->x)&&(r->rewcoord[i].y==snake1->y))
   {
    r = mk_reward(s1, s2, r, i);
    p->s1_points++;
    flag=1;
    break;
   }
  }
  if (flag==0)
   s1 = queue_pop(s1);
 return 0;
}

variable_types: iter int

variable_types: check int