rtspRequestAddHeaderField

decompiled_code:
__int64 __fastcall rtspRequestAddHeaderField(__int64 a1, const char *a2, const char *a3)
{
__int64 v3; // r14
size_t v5; // r12
size_t v6; // r15
unsigned int v7; // er12

v3 = a1 + 8;
if ( !*(_QWORD *)(a1 + 8) )
{
*(_QWORD *)(a1 + 24) = 1024LL;
v7 = voidBufferAllocate(a1 + 8, 1024LL, "RTSP request header buffer");
if ( !(_BYTE)v7 )
return v7;
**(_BYTE **)(a1 + 8) = 0;
*(_QWORD *)(a1 + 16) = 1LL;
}
v5 = strlen(a2);
v6 = v5 + strlen(a3) + 4;
v7 = voidBufferMakeRoom(v3, a1 + 24, *(_QWORD *)(a1 + 16), v6, 512LL);
if ( (_BYTE)v7 )
{
if ( v6 == snprintf(
(char *)(*(_QWORD *)(a1 + 8) + *(_QWORD *)(a1 + 16) - 1LL),
*(_QWORD *)(a1 + 24) + 1LL - *(_QWORD *)(a1 + 16),
"%s: %s\r\n",
a2,
a3) )
{
*(_QWORD *)(a1 + 16) += v6;
}
else
{
v7 = 0;
logWrite(1LL, "rtsprequest.c", "Cannot add field \"%s\" to RTSP Request header.", a2);
}
}
else
{
logWrite(1LL, "rtsprequest.c", "Cannot allocate memory to add field \"%s\" to RTSP Request header.", a2);
voidBufferFree(v3);
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, const char *a3)
{
__int64 v3; // r14
size_t v5; // r12
size_t v6; // r15
unsigned int v7; // er12

v3 = a1 + 8;
if ( !*(_QWORD *)(a1 + 8) )
{
*(_QWORD *)(a1 + 24) = 1024LL;
v7 = voidBufferAllocate(a1 + 8, 1024LL, "RTSP request header buffer");
if ( !(_BYTE)v7 )
return v7;
**(_BYTE **)(a1 + 8) = 0;
*(_QWORD *)(a1 + 16) = 1LL;
}
v5 = strlen(a2);
v6 = v5 + strlen(a3) + 4;
v7 = voidBufferMakeRoom(v3, a1 + 24, *(_QWORD *)(a1 + 16), v6, 512LL);
if ( (_BYTE)v7 )
{
if ( v6 == snprintf(
(char *)(*(_QWORD *)(a1 + 8) + *(_QWORD *)(a1 + 16) - 1LL),
*(_QWORD *)(a1 + 24) + 1LL - *(_QWORD *)(a1 + 16),
"%s: %s\r\n",
a2,
a3) )
{
*(_QWORD *)(a1 + 16) += v6;
}
else
{
v7 = 0;
logWrite(1LL, "rtsprequest.c", "Cannot add field \"%s\" to RTSP Request header.", a2);
}
}
else
{
logWrite(1LL, "rtsprequest.c", "Cannot allocate memory to add field \"%s\" to RTSP Request header.", a2);
voidBufferFree(v3);
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
return v7;
}

original_code:
_Bool rtspRequestAddHeaderField(RTSPRequest *rtspRequest, const char *fieldName, const char *fieldValue) {
 size_t fieldNameLength;
 size_t fieldValueLength;
 int charsWritten;
 if(rtspRequest->headerBuffer == ((void *)0)) {
  rtspRequest->maxHeaderBufferSize = 1024;
  if(!voidBufferAllocate((void **)&rtspRequest->headerBuffer, rtspRequest->maxHeaderBufferSize, "RTSP request header buffer")) {
   return 0;
  }
  rtspRequest->headerBuffer[0] = '\0';
  rtspRequest->headerBufferSize = 1;
 }
 fieldNameLength = strlen(fieldName);
 fieldValueLength = strlen(fieldValue);
 if(!voidBufferMakeRoom((void **)&rtspRequest->headerBuffer, &rtspRequest->maxHeaderBufferSize, rtspRequest->headerBufferSize, fieldNameLength + fieldValueLength + 4, 512)) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot allocate memory to add field \"%s\" to RTSP Request header.", fieldName);
  voidBufferFree((void **)&rtspRequest->headerBuffer);
  rtspRequest->headerBuffer = ((void *)0);
  rtspRequest->headerBufferSize = 0;
  return 0;
 }
 charsWritten = snprintf((char *)rtspRequest->headerBuffer + rtspRequest->headerBufferSize - 1, rtspRequest->maxHeaderBufferSize - (rtspRequest->headerBufferSize - 1), "%s: %s\r\n", fieldName, fieldValue);
 if(charsWritten != fieldNameLength + fieldValueLength + 4) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot add field \"%s\" to RTSP Request header.", fieldName);
  return 0;
 }
 rtspRequest->headerBufferSize += charsWritten;
 return 1;
}

canonical_original_code:
_Bool rtspRequestAddHeaderField(struct RTSPRequestStruct *rtspRequest, char *fieldName, char *fieldValue) {
 unsigned long fieldNameLength;
 unsigned long fieldValueLength;
 int charsWritten;
 if(rtspRequest->headerBuffer == ((void *)0)) {
  rtspRequest->maxHeaderBufferSize = 1024;
  if(!voidBufferAllocate((void **)&rtspRequest->headerBuffer, rtspRequest->maxHeaderBufferSize, "RTSP request header buffer")) {
   return 0;
  }
  rtspRequest->headerBuffer[0] = '\0';
  rtspRequest->headerBufferSize = 1;
 }
 fieldNameLength = strlen(fieldName);
 fieldValueLength = strlen(fieldValue);
 if(!voidBufferMakeRoom((void **)&rtspRequest->headerBuffer, &rtspRequest->maxHeaderBufferSize, rtspRequest->headerBufferSize, fieldNameLength + fieldValueLength + 4, 512)) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot allocate memory to add field \"%s\" to RTSP Request header.", fieldName);
  voidBufferFree((void **)&rtspRequest->headerBuffer);
  rtspRequest->headerBuffer = ((void *)0);
  rtspRequest->headerBufferSize = 0;
  return 0;
 }
 charsWritten = snprintf((char *)rtspRequest->headerBuffer + rtspRequest->headerBufferSize - 1, rtspRequest->maxHeaderBufferSize - (rtspRequest->headerBufferSize - 1), "%s: %s\r\n", fieldName, fieldValue);
 if(charsWritten != fieldNameLength + fieldValueLength + 4) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot add field \"%s\" to RTSP Request header.", fieldName);
  return 0;
 }
 rtspRequest->headerBufferSize += charsWritten;
 return 1;
}

variable_types:
fieldName
char *

variable_types:
fieldValue
char *

variable_types:
fieldNameLength
unsigned long

variable_types:
fieldValueLength
unsigned long

variable_types: charsWritten int


rtspRequestSetContent

repo: ErikOnBike/light-play

decompiled_code:
__int64 __fastcall rtspRequestSetContent(__int64 a1, const void *a2, size_t a3, const char *a4)
{
unsigned int v6; // er13
char s[51]; // [rsp+5h] [rbp-33h] BYREF

if ( !(unsigned __int8)rtspRequestAddHeaderField(a1, "Content-Type", a4) )
return 0LL;
sprintf(s, "%lu", a3);
if ( !(unsigned __int8)rtspRequestAddHeaderField(a1, "Content-Length", s)
|| *(_QWORD *)(a1 + 32) && !(unsigned __int8)voidBufferFree(a1 + 32) )
{
return 0LL;
}
v6 = voidBufferAllocate(a1 + 32, a3, "RTSP request content buffer");
if ( !(_BYTE)v6 )
return 0LL;
memcpy(*(void **)(a1 + 32), a2, a3);
*(_QWORD *)(a1 + 40) = a3;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const void *a2, size_t a3, const char *a4)
{
unsigned int v6; // er13
char s[51]; // [rsp+5h] [rbp-33h] BYREF

if ( !(unsigned __int8)func3(a1, "Content-Type", a4) )
return 0LL;
sprintf(s, "%lu", a3);
if ( !(unsigned __int8)func3(a1, "Content-Length", s)
|| *(_QWORD *)(a1 + 32) && !(unsigned __int8)voidBufferFree(a1 + 32) )
{
return 0LL;
}
v6 = voidBufferAllocate(a1 + 32, a3, "RTSP request content buffer");
if ( !(_BYTE)v6 )
return 0LL;
memcpy(*(void **)(a1 + 32), a2, a3);
*(_QWORD *)(a1 + 40) = a3;
return v6;
}

original_code:
_Bool rtspRequestSetContent(RTSPRequest *rtspRequest, uint8_t *content, size_t contentSize, char *contentType) {
 char contentSizeString[11];
 if(!rtspRequestAddHeaderField(rtspRequest, "Content-Type", contentType)) {
  return 0;
 }
 sprintf(contentSizeString, "%lu", (unsigned long)contentSize);
 if(!rtspRequestAddHeaderField(rtspRequest, "Content-Length", contentSizeString)) {
  return 0;
 }
 if(rtspRequest->contentBuffer != ((void *)0)) {
  if(!voidBufferFree((void **)&rtspRequest->contentBuffer)) {
   return 0;
  }
 }
 if(!voidBufferAllocate((void **)&rtspRequest->contentBuffer, contentSize, "RTSP request content buffer")) {
  return 0;
 }
 memcpy(rtspRequest->contentBuffer, content, contentSize);
 rtspRequest->contentBufferSize = contentSize;
 return 1;
}

canonical_original_code:
_Bool rtspRequestSetContent(struct RTSPRequestStruct *rtspRequest, unsigned char *content, unsigned long contentSize, char *contentType) {
 char contentSizeString[11];
 if(!rtspRequestAddHeaderField(rtspRequest, "Content-Type", contentType)) {
  return 0;
 }
 sprintf(contentSizeString, "%lu", (unsigned long)contentSize);
 if(!rtspRequestAddHeaderField(rtspRequest, "Content-Length", contentSizeString)) {
  return 0;
 }
 if(rtspRequest->contentBuffer != ((void *)0)) {
  if(!voidBufferFree((void **)&rtspRequest->contentBuffer)) {
   return 0;
  }
 }
 if(!voidBufferAllocate((void **)&rtspRequest->contentBuffer, contentSize, "RTSP request content buffer")) {
  return 0;
 }
 memcpy(rtspRequest->contentBuffer, content, contentSize);
 rtspRequest->contentBufferSize = contentSize;
 return 1;
}

variable_types: struct RTSPRequestStruct { enum RTSPRequestMethod { RTSP_METHOD_OPTIONS=0, RTSP_METHOD_ANNOUNCE=1, RTSP_METHOD_SETUP=2, RTSP_METHOD_RECORD=3, RTSP_METHOD_SET_PARAMETER=4, RTSP_METHOD_FLUSH=5, RTSP_METHOD_TEARDOWN=6 } requestMethod; unsigned char *headerBuffer; unsigned long headerBufferSize; unsigned long maxHeaderBufferSize; unsigned char *contentBuffer; unsigned long contentBufferSize; } *

variable_types:
content
unsigned char *

variable_types:
contentSize
unsigned long

variable_types:
contentType
char *

variable_types:
contentSizeString
char [11]

user_defined_types: struct RTSPRequestStruct { enum RTSPRequestMethod requestMethod; unsigned char *headerBuffer; unsigned long headerBufferSize; unsigned long maxHeaderBufferSize; unsigned char *contentBuffer; unsigned long contentBufferSize; }


rtspRequestFree

decompiled_code:
__int64 __fastcall rtspRequestFree(__int64 *a1)
{
unsigned int v1; // er12
__int64 v3; // rdi

v1 = 1;
v3 = *a1;
if ( v3 )
{
v1 = voidBufferFree(v3 + 8);
if ( !(unsigned __int8)voidBufferFree(*a1 + 32) )
v1 = 0;
if ( !(unsigned __int8)voidBufferFree(a1) )
v1 = 0;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1)
{
unsigned int v1; // er12
__int64 v3; // rdi

v1 = 1;
v3 = *a1;
if ( v3 )
{
v1 = voidBufferFree(v3 + 8);
if ( !(unsigned __int8)voidBufferFree(*a1 + 32) )
v1 = 0;
if ( !(unsigned __int8)voidBufferFree(a1) )
v1 = 0;
}
return v1;
}

original_code:
_Bool rtspRequestFree(RTSPRequest **rtspRequest) {
 _Bool result;
 result = 1;
 if(*rtspRequest != ((void *)0)) {
  if(!voidBufferFree((void **)&(*rtspRequest)->headerBuffer)) {
   result = 0;
  }
  if(!voidBufferFree((void **)&(*rtspRequest)->contentBuffer)) {
   result = 0;
  }
  if(!voidBufferFree((void **)rtspRequest)) {
   result = 0;
  }
 }
 return result;
}

canonical_original_code:
_Bool rtspRequestFree(struct RTSPRequestStruct **rtspRequest) {
 _Bool result;
 result = 1;
 if(*rtspRequest != ((void *)0)) {
  if(!voidBufferFree((void **)&(*rtspRequest)->headerBuffer)) {
   result = 0;
  }
  if(!voidBufferFree((void **)&(*rtspRequest)->contentBuffer)) {
   result = 0;
  }
  if(!voidBufferFree((void **)rtspRequest)) {
   result = 0;
  }
 }
 return result;
}

variable_types: struct RTSPRequestStruct { enum RTSPRequestMethod { RTSP_METHOD_OPTIONS=0, RTSP_METHOD_ANNOUNCE=1, RTSP_METHOD_SETUP=2, RTSP_METHOD_RECORD=3, RTSP_METHOD_SET_PARAMETER=4, RTSP_METHOD_FLUSH=5, RTSP_METHOD_TEARDOWN=6 } requestMethod; unsigned char *headerBuffer; unsigned long headerBufferSize; unsigned long maxHeaderBufferSize; unsigned char *contentBuffer; unsigned long contentBufferSize; } **


signalHandler

decompiled_code:
void __fastcall signalHandler(int a1)
{
unsigned int v1[6]; // [rsp+0h] [rbp-18h] BYREF

if ( a1 == 2 )
{
if ( (unsigned __int8)raopClientGetProgress(raopClient, v1) )
logWrite(3LL, "light-play.c", "Progress so far: %u seconds", v1[0]);
logWrite(2LL, "light-play.c", "Stop playing before end of file on user request.");
raopClientStopPlaying(raopClient);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
unsigned int v1[6]; // [rsp+0h] [rbp-18h] BYREF

if ( a1 == 2 )
{
if ( (unsigned __int8)raopClientGetProgress(raopClient, v1) )
logWrite(3LL, "light-play.c", "Progress so far: %u seconds", v1[0]);
logWrite(2LL, "light-play.c", "Stop playing before end of file on user request.");
raopClientStopPlaying(raopClient);
}
}

original_code:
void signalHandler(int signalNumber) {
 struct timespec progress;
 if(signalNumber == 2) {
  if(raopClientGetProgress(raopClient, &progress)) {
   logWrite(LOG_LEVEL_INFO, LOG_COMPONENT_NAME, "Progress so far: %" "u" " seconds", (uint32_t)(progress.tv_sec));
  }
  logWrite(LOG_LEVEL_WARNING, LOG_COMPONENT_NAME, "Stop playing before end of file on user request.");
  raopClientStopPlaying(raopClient);
 }
}

canonical_original_code:
void signalHandler(int signalNumber) {
 struct timespec progress;
 if(signalNumber == 2) {
  if(raopClientGetProgress(raopClient, &progress)) {
   logWrite(LOG_LEVEL_INFO, LOG_COMPONENT_NAME, "Progress so far: %" "u" " seconds", (unsigned int)(progress.tv_sec));
  }
  logWrite(LOG_LEVEL_WARNING, LOG_COMPONENT_NAME, "Stop playing before end of file on user request.");
  raopClientStopPlaying(raopClient);
 }
}

variable_types: signalNumber int

variable_types: struct timespec { long tv_sec; long tv_nsec; }

return_type: void


printUsage

decompiled_code:
int printUsage(char *s, char *format, ...)
{
char *v2; // r12
char *v3; // rax
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v2 = s;
v3 = strrchr(s, 47);
if ( v3 )
v2 = v3 + 1;
result = fprintf(
stderr,
"Usage: %s [-?hcpvlo] <url> <filename>\n"
"\n"
" -? | -h Print this usage message\n"
" -c[ ]<password> Set password for using AirPort Express\n"
" -p[ ]<portname> Set name/number of AirTunes port (default: 5000)\n"
" -v[e|w|i|d] Set logging verbosity (default: w)\n"
" e: only errors\n"
" w: errors and warnings (default)\n"
" i: errors, warnings and info\n"
" d: all (includes debug info)\n"
" -l[ ]<filename> Set logging to specified file\n"
" -o[ ]<offset> Set offset (in seconds) from begin of file where to start playing\n",
v2);
if ( format )
{
va_start(arg, format);
fwrite("\n\n", 1uLL, 2uLL, stderr);
vfprintf(stderr, format, arg);
result = fputc(10, stderr);
}
return result;
}

canonical_decompiled_code:
int func1(char *s, char *format, ...)
{
char *v2; // r12
char *v3; // rax
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v2 = s;
v3 = strrchr(s, 47);
if ( v3 )
v2 = v3 + 1;
result = fprintf(
stderr,
"Usage: %s [-?hcpvlo] <url> <filename>\n"
"\n"
" -? | -h Print this usage message\n"
" -c[ ]<password> Set password for using AirPort Express\n"
" -p[ ]<portname> Set name/number of AirTunes port (default: 5000)\n"
" -v[e|w|i|d] Set logging verbosity (default: w)\n"
" e: only errors\n"
" w: errors and warnings (default)\n"
" i: errors, warnings and info\n"
" d: all (includes debug info)\n"
" -l[ ]<filename> Set logging to specified file\n"
" -o[ ]<offset> Set offset (in seconds) from begin of file where to start playing\n",
v2);
if ( format )
{
va_start(arg, format);
fwrite("\n\n", 1uLL, 2uLL, stderr);
vfprintf(stderr, format, arg);
result = fputc(10, stderr);
}
return result;
}

original_code:
void printUsage(const char *appName, const char *printFormat, ...) {
 char *shortAppName;
 va_list argumentList;
 shortAppName = strrchr(appName, '/');
 if(shortAppName == ((void *)0)) {
  shortAppName = (char *)appName;
 } else {
  shortAppName++;
  if(shortAppName == '\0') {
   shortAppName = (char *)appName;
  }
 }
 fprintf(stderr, "Usage: %s [-?hcpvlo] <url> <filename>\n\n" "    -? | -h          Print this usage message\n" "    -c[ ]<password>  Set password for using AirPort Express\n" "    -p[ ]<portname>  Set name/number of AirTunes port (default: 5000)\n"
   "    -v[e|w|i|d]      Set logging verbosity (default: w)\n"
   "                         e: only errors\n"
   "                         w: errors and warnings (default)\n"
   "                         i: errors, warnings and info\n"
                        "                         d: all (includes debug info)\n"
   "    -l[ ]<filename>  Set logging to specified file\n"
   "    -o[ ]<offset>    Set offset (in seconds) from begin of file where to start playing\n", shortAppName);
 if(printFormat != ((void *)0)) {
  __builtin_va_start(argumentList,printFormat);
  fputs("\n\n", stderr);
  vfprintf(stderr, printFormat, argumentList);
  __builtin_va_end(argumentList);
  fputs("\n", stderr);
 }
}

canonical_original_code:
void printUsage(char *appName, char *printFormat, ...) {
 char *shortAppName;
 __builtin_va_list argumentList;
 shortAppName = strrchr(appName, '/');
 if(shortAppName == ((void *)0)) {
  shortAppName = (char *)appName;
 } else {
  shortAppName++;
  if(shortAppName == '\0') {
   shortAppName = (char *)appName;
  }
 }
 fprintf(stderr, "Usage: %s [-?hcpvlo] <url> <filename>\n\n" "    -? | -h          Print this usage message\n" "    -c[ ]<password>  Set password for using AirPort Express\n" "    -p[ ]<portname>  Set name/number of AirTunes port (default: 5000)\n"
   "    -v[e|w|i|d]      Set logging verbosity (default: w)\n"
   "                         e: only errors\n"
   "                         w: errors and warnings (default)\n"
   "                         i: errors, warnings and info\n"
                        "                         d: all (includes debug info)\n"
   "    -l[ ]<filename>  Set logging to specified file\n"
   "    -o[ ]<offset>    Set offset (in seconds) from begin of file where to start playing\n", shortAppName);
 if(printFormat != ((void *)0)) {
  __builtin_va_start(argumentList,printFormat);
  fputs("\n\n", stderr);
  vfprintf(stderr, printFormat, argumentList);
  __builtin_va_end(argumentList);
  fputs("\n", stderr);
 }
}

variable_types:
appName
char *

variable_types:
printFormat
char *

variable_types:
shortAppName
char *


voidBufferAllocate

decompiled_code:
__int64 __fastcall voidBufferAllocate(_QWORD *a1, size_t a2, const char *a3)
{
void *v4; // rax
__int64 result; // rax

v4 = malloc(a2);
if ( v4 )
{
++bufferAllocateCount;
*a1 = v4;
result = 1LL;
}
else
{
if ( !a3 )
a3 = "a buffer";
logWrite(1LL, "buffer.c", "Cannot allocate memory (%lu bytes) for %s.", a2, a3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, size_t a2, const char *a3)
{
void *v4; // rax
__int64 result; // rax

v4 = malloc(a2);
if ( v4 )
{
++bufferAllocateCount;
*a1 = v4;
result = 1LL;
}
else
{
if ( !a3 )
a3 = "a buffer";
logWrite(1LL, "buffer.c", "Cannot allocate memory (%lu bytes) for %s.", a2, a3);
result = 0LL;
}
return result;
}

original_code:
_Bool voidBufferAllocate(void **buffer, size_t bufferSize, const char *purpose) {
 void *newBuffer;
 newBuffer = malloc(bufferSize);
 if(newBuffer == ((void *)0)) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot allocate memory (%lu bytes) for %s.", (unsigned long)bufferSize, purpose == ((void *)0) ? "a buffer" : purpose);
  return 0;
 }
 *buffer = newBuffer;
 bufferAllocateCount++;
 return 1;
}

canonical_original_code:
_Bool voidBufferAllocate(void **buffer, unsigned long bufferSize, char *purpose) {
 void *newBuffer;
 newBuffer = malloc(bufferSize);
 if(newBuffer == ((void *)0)) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot allocate memory (%lu bytes) for %s.", (unsigned long)bufferSize, purpose == ((void *)0) ? "a buffer" : purpose);
  return 0;
 }
 *buffer = newBuffer;
 bufferAllocateCount++;
 return 1;
}

variable_types:
buffer
void **

variable_types:
bufferSize
unsigned long

variable_types:
purpose
char *

variable_types:
newBuffer
void *


voidBufferFree

decompiled_code:
__int64 __fastcall voidBufferFree(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
--bufferAllocateCount;
*a1 = 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
--bufferAllocateCount;
*a1 = 0LL;
}
return 1LL;
}

original_code:
_Bool voidBufferFree(void **buffer) {
 if(*buffer != ((void *)0)) {
  free(*buffer);
  *buffer = ((void *)0);
  bufferAllocateCount--;
 }
 return 1;
}


bufferGetBuffersInUse

decompiled_code:
__int64 bufferGetBuffersInUse()
{
return (unsigned int)bufferAllocateCount;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)bufferAllocateCount;
}

original_code:
int32_t bufferGetBuffersInUse() {
 return bufferAllocateCount;
}

canonical_original_code:
int bufferGetBuffersInUse() {
 return bufferAllocateCount;
}

return_type: int


voidBufferMakeRoom

decompiled_code:
__int64 __fastcall voidBufferMakeRoom(const void **a1, size_t *a2, size_t a3, __int64 a4, __int64 a5)
{
size_t v5; // rcx
__int64 result; // rax
size_t v7; // rbx
void *dest; // [rsp+0h] [rbp-38h] BYREF
void *v10; // [rsp+8h] [rbp-30h] BYREF

v5 = a3 + a4;
result = 1LL;
v7 = *a2;
if ( v5 > *a2 )
{
do
v7 += a5;
while ( v5 > v7 );
result = voidBufferAllocate(&dest, v7, "a larger buffer");
if ( (_BYTE)result )
{
memcpy(dest, *a1, a3);
v10 = (void *)*a1;
*a1 = dest;
*a2 = v7;
result = voidBufferFree(&v10);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const void **a1, size_t *a2, size_t a3, __int64 a4, __int64 a5)
{
size_t v5; // rcx
__int64 result; // rax
size_t v7; // rbx
void *dest; // [rsp+0h] [rbp-38h] BYREF
void *v10; // [rsp+8h] [rbp-30h] BYREF

v5 = a3 + a4;
result = 1LL;
v7 = *a2;
if ( v5 > *a2 )
{
do
v7 += a5;
while ( v5 > v7 );
result = func0(&dest, v7, "a larger buffer");
if ( (_BYTE)result )
{
memcpy(dest, *a1, a3);
v10 = (void *)*a1;
*a1 = dest;
*a2 = v7;
result = func1(&v10);
}
}
return result;
}

original_code:
_Bool voidBufferMakeRoom(void **buffer, size_t *maxBufferSize, size_t bufferSize, size_t requiredSize, size_t incrementSize) {
 void *newBuffer;
 void *tmpBuffer;
 size_t newSize;
 if(bufferSize + requiredSize <= *maxBufferSize) {
  return 1;
 }
 newSize = *maxBufferSize + incrementSize;
 while(bufferSize + requiredSize > newSize) {
  newSize += incrementSize;
 }
 if(!voidBufferAllocate((void **)&newBuffer, newSize, "a larger buffer")) {
  return 0;
 }
 memcpy(newBuffer, *buffer, bufferSize);
 tmpBuffer = *buffer;
 *buffer = newBuffer;
 *maxBufferSize = newSize;
 return voidBufferFree((void **)&tmpBuffer);
}

canonical_original_code:
_Bool voidBufferMakeRoom(void **buffer, unsigned long *maxBufferSize, unsigned long bufferSize, unsigned long requiredSize, unsigned long incrementSize) {
 void *newBuffer;
 void *tmpBuffer;
 unsigned long newSize;
 if(bufferSize + requiredSize <= *maxBufferSize) {
  return 1;
 }
 newSize = *maxBufferSize + incrementSize;
 while(bufferSize + requiredSize > newSize) {
  newSize += incrementSize;
 }
 if(!voidBufferAllocate((void **)&newBuffer, newSize, "a larger buffer")) {
  return 0;
 }
 memcpy(newBuffer, *buffer, bufferSize);
 tmpBuffer = *buffer;
 *buffer = newBuffer;
 *maxBufferSize = newSize;
 return voidBufferFree((void **)&tmpBuffer);
}

variable_types:
maxBufferSize
unsigned long *

variable_types:
requiredSize
unsigned long

variable_types:
incrementSize
unsigned long

variable_types:
tmpBuffer
void *

variable_types:
newSize
unsigned long


repo: ErikTraedal/MeleProxy

decompiled_code:
void signal_handler()
{
puts("Stopping application");
running = 0;
}

canonical_decompiled_code:
void func0()
{
puts("Stopping application");
running = 0;
}

original_code:
void signal_handler(int number) {
 printf("Stopping application\n");
 running = 0;
}

variable_types: number int


decompiled_code:
int __fastcall create_lookup_table(unsigned __int16 *a1)
{
__int16 *v1; // r12
__int16 *v2; // rbp
unsigned __int16 v3; // bx
unsigned __int16 v4; // ax
__int64 v5; // rsi
__int64 v6; // rax
__int16 v7; // dx
__int64 v8; // rbx
unsigned __int16 v9; // r13

v1 = &keymap_keys[2];
v2 = &keymap_keys[2];
puts("Creating lookup table");
v3 = *a1;
v4 = 115;
while ( 1 )
{
if ( v4 > v3 )
{
*a1 = v4;
v3 = v4;
}
if ( &unk_660 == (_UNKNOWN *)v2 )
break;
v4 = *v2;
v2 += 2;
}
*((_QWORD *)a1 + 1) = malloc(2LL * v3);
printf("Filling lookup table with data (number of items = %i\n", v3);
v5 = *((_QWORD *)a1 + 1);
v6 = 0LL;
do
{
v7 = 0;
if ( (unsigned int)(v6 - 1) <= 0x52 )
v7 = v6;
*(_WORD *)(v5 + 2 * v6++) = v7;
}
while ( *a1 >= (int)v6 );
v8 = 115LL;
v9 = 78;
while ( 1 )
{
printf("Replacing key %i with key %i\n", (unsigned __int16)v8, v9);
*(_WORD *)(*((_QWORD *)a1 + 1) + 2 * v8) = v9;
if ( v2 == v1 )
break;
v9 = v1[1];
v8 = (unsigned __int16)*v1;
v1 += 2;
}
return puts("Finished creating lookup table");
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int16 *a1)
{
__int16 *v1; // r12
__int16 *v2; // rbp
unsigned __int16 v3; // bx
unsigned __int16 v4; // ax
__int64 v5; // rsi
__int64 v6; // rax
__int16 v7; // dx
__int64 v8; // rbx
unsigned __int16 v9; // r13

v1 = &keymap_keys[2];
v2 = &keymap_keys[2];
puts("Creating lookup table");
v3 = *a1;
v4 = 115;
while ( 1 )
{
if ( v4 > v3 )
{
*a1 = v4;
v3 = v4;
}
if ( &unk_660 == (_UNKNOWN *)v2 )
break;
v4 = *v2;
v2 += 2;
}
*((_QWORD *)a1 + 1) = malloc(2LL * v3);
printf("Filling lookup table with data (number of items = %i\n", v3);
v5 = *((_QWORD *)a1 + 1);
v6 = 0LL;
do
{
v7 = 0;
if ( (unsigned int)(v6 - 1) <= 0x52 )
v7 = v6;
*(_WORD *)(v5 + 2 * v6++) = v7;
}
while ( *a1 >= (int)v6 );
v8 = 115LL;
v9 = 78;
while ( 1 )
{
printf("Replacing key %i with key %i\n", (unsigned __int16)v8, v9);
*(_WORD *)(*((_QWORD *)a1 + 1) + 2 * v8) = v9;
if ( v2 == v1 )
break;
v9 = v1[1];
v8 = (unsigned __int16)*v1;
v1 += 2;
}
return puts("Finished creating lookup table");
}

original_code:
void create_lookup_table(struct key_lookup_table *table) {
 int i, number_of_items;
 printf("Creating lookup table\n");
 number_of_items = sizeof(keymap_keys) / sizeof(keymap_keys[0]);
 for (i = 0; i < number_of_items; i++) {
  if (keymap_keys[i].key > table->max_value)
   table->max_value = keymap_keys[i].key;
 }
 table->key_table = malloc(table->max_value * sizeof(ushort));
 printf("Filling lookup table with data (number of items = %i\n",
   table->max_value);
 for (i = 0; i <= table->max_value; i++) {
  if (i > 0 && i <= 83) {
   *(table->key_table + i) = i;
  } else {
   *(table->key_table + i) = 0;
  }
 }
 for (i = 0; i < number_of_items; i++) {
  printf("Replacing key %i with key %i\n", keymap_keys[i].key,
    keymap_keys[i].new_key);
  *(table->key_table + keymap_keys[i].key) = keymap_keys[i].new_key;
 }
 printf("Finished creating lookup table\n");
}

canonical_original_code:
void create_lookup_table(struct key_lookup_table *table) {
 int i; int number_of_items;
 printf("Creating lookup table\n");
 number_of_items = sizeof(keymap_keys) / sizeof(keymap_keys[0]);
 for (i = 0; i < number_of_items; i++) {
  if (keymap_keys[i].key > table->max_value)
   table->max_value = keymap_keys[i].key;
 }
 table->key_table = malloc(table->max_value * sizeof(ushort));
 printf("Filling lookup table with data (number of items = %i\n",
   table->max_value);
 for (i = 0; i <= table->max_value; i++) {
  if (i > 0 && i <= 83) {
   *(table->key_table + i) = i;
  } else {
   *(table->key_table + i) = 0;
  }
 }
 for (i = 0; i < number_of_items; i++) {
  printf("Replacing key %i with key %i\n", keymap_keys[i].key,
    keymap_keys[i].new_key);
  *(table->key_table + keymap_keys[i].key) = keymap_keys[i].new_key;
 }
 printf("Finished creating lookup table\n");
}

variable_types: struct key_lookup_table { unsigned short max_value; unsigned short *key_table; } *

variable_types: i int


decompiled_code:
int __fastcall show_usage(__int64 a1, const char **a2)
{
printf("Usage: %s [OPTION]\n", *a2);
puts("Starts a proxy service for the Mele F10 remote control\n");
puts("Arguments:");
puts("\t-f\tRun in foreground (don't run in background)");
return puts("\t-d\tShow debug information");
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, const char **a2)
{
printf("Usage: %s [OPTION]\n", *a2);
puts("Starts a proxy service for the Mele F10 remote control\n");
puts("Arguments:");
puts("\t-f\tRun in foreground (don't run in background)");
return puts("\t-d\tShow debug information");
}

original_code:
void show_usage(int argc, char **argv) {
 printf("Usage: %s [OPTION]\n", *argv);
 printf("Starts a proxy service for the Mele F10 remote control\n\n");
 printf("Arguments:\n");
 printf("\t-f\tRun in foreground (don't run in background)\n");
 printf("\t-d\tShow debug information\n");
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
int __fastcall destroy_uinput_device(int fd)
{
int result; // eax

if ( ioctl(fd, 0x5502uLL) < 0 )
result = -1;
else
result = close(fd);
return result;
}

canonical_decompiled_code:
int __fastcall func2(int fd)
{
int result; // eax

if ( ioctl(fd, 0x5502uLL) < 0 )
result = -1;
else
result = close(fd);
return result;
}


DisplayHelp

repo: Ethanjfobrien/LanguageProcessorsProject

decompiled_code:
__int64 DisplayHelp()
{
WriteOut(" ?, HELP Display this message\n");
WriteOut(" EXIT Exit program\n");
WriteOut(" LOGGING Toggle logging to file \"%s\"\n", "sim.log");
WriteOut(" RUN [<c>] Run <c> instructions, starting from the\n");
WriteOut(" current PC\n");
WriteOut(" TRACE [<c>] Trace <c> instructions, starting from the\n");
WriteOut(" current PC\n");
WriteOut(" RESET PC = 0, SP = -1, FP = 0\n");
WriteOut(" Initialise stack to zeros\n");
WriteOut(" DR Display Registers\n");
WriteOut(" DDM [<a> [<c>]] Display data (stack) memory from <a>\n");
WriteOut(" displaying <c> words\n");
WriteOut(" DCM [<a> [<c>]] Display code (instruction) memory\n");
WriteOut(" from <a> displaying <c> words\n");
WriteOut(" SPC <n> Set Program Counter to <n>\n");
WriteOut(" SSP <n> Set Stack Pointer to <n>\n");
WriteOut(" SFP <n> Set Frame Pointer to <n>\n");
WriteOut(" SDM <a> <v> Set Data memory at <a> to <v>\n\n");
WriteOut(" SBP <a> Set Breakpoint at code address <a>\n");
WriteOut(" DBP Display all Breakpoints\n");
WriteOut(" CBP Clear all Breakpoints\n\n");
return WriteOut(" Commands may be abbreviated to shortest unique prefix\n");
}

canonical_decompiled_code:
__int64 func0()
{
WriteOut(" ?, HELP Display this message\n");
WriteOut(" EXIT Exit program\n");
WriteOut(" LOGGING Toggle logging to file \"%s\"\n", "sim.log");
WriteOut(" RUN [<c>] Run <c> instructions, starting from the\n");
WriteOut(" current PC\n");
WriteOut(" TRACE [<c>] Trace <c> instructions, starting from the\n");
WriteOut(" current PC\n");
WriteOut(" RESET PC = 0, SP = -1, FP = 0\n");
WriteOut(" Initialise stack to zeros\n");
WriteOut(" DR Display Registers\n");
WriteOut(" DDM [<a> [<c>]] Display data (stack) memory from <a>\n");
WriteOut(" displaying <c> words\n");
WriteOut(" DCM [<a> [<c>]] Display code (instruction) memory\n");
WriteOut(" from <a> displaying <c> words\n");
WriteOut(" SPC <n> Set Program Counter to <n>\n");
WriteOut(" SSP <n> Set Stack Pointer to <n>\n");
WriteOut(" SFP <n> Set Frame Pointer to <n>\n");
WriteOut(" SDM <a> <v> Set Data memory at <a> to <v>\n\n");
WriteOut(" SBP <a> Set Breakpoint at code address <a>\n");
WriteOut(" DBP Display all Breakpoints\n");
WriteOut(" CBP Clear all Breakpoints\n\n");
return WriteOut(" Commands may be abbreviated to shortest unique prefix\n");
}

original_code:
static void DisplayHelp( void )
{
    WriteOut( " ?, HELP          Display this message\n" );
    WriteOut( " EXIT             Exit program\n" );
    WriteOut( " LOGGING          Toggle logging to file \"%s\"\n", "sim.log" );
    WriteOut( " RUN [<c>]        Run <c> instructions, starting from the\n" );
    WriteOut( "                  current PC\n" );
    WriteOut( " TRACE [<c>]      Trace <c> instructions, starting from the\n" );
    WriteOut( "                  current PC\n" );
    WriteOut( " RESET            PC = 0, SP = -1, FP = 0\n" );
    WriteOut( "                  Initialise stack to zeros\n" );
    WriteOut( " DR               Display Registers\n" );
    WriteOut( " DDM [<a> [<c>]]  Display data (stack) memory from <a>\n");
    WriteOut( "                  displaying <c> words\n" );
    WriteOut( " DCM [<a> [<c>]]  Display code (instruction) memory\n" );
    WriteOut( "                  from <a> displaying <c> words\n" );
    WriteOut( " SPC <n>          Set Program Counter to <n>\n" );
    WriteOut( " SSP <n>          Set Stack Pointer to <n>\n" );
    WriteOut( " SFP <n>          Set Frame Pointer to <n>\n" );
    WriteOut( " SDM <a> <v>      Set Data memory at <a> to <v>\n\n" );
    WriteOut( " SBP <a>          Set Breakpoint at code address <a>\n" );
    WriteOut( " DBP              Display all Breakpoints\n" );
    WriteOut( " CBP              Clear all Breakpoints\n\n" );
    WriteOut( " Commands may be abbreviated to shortest unique prefix\n");
}

canonical_original_code:
static void DisplayHelp()
{
    WriteOut( " ?, HELP          Display this message\n" );
    WriteOut( " EXIT             Exit program\n" );
    WriteOut( " LOGGING          Toggle logging to file \"%s\"\n", "sim.log" );
    WriteOut( " RUN [<c>]        Run <c> instructions, starting from the\n" );
    WriteOut( "                  current PC\n" );
    WriteOut( " TRACE [<c>]      Trace <c> instructions, starting from the\n" );
    WriteOut( "                  current PC\n" );
    WriteOut( " RESET            PC = 0, SP = -1, FP = 0\n" );
    WriteOut( "                  Initialise stack to zeros\n" );
    WriteOut( " DR               Display Registers\n" );
    WriteOut( " DDM [<a> [<c>]]  Display data (stack) memory from <a>\n");
    WriteOut( "                  displaying <c> words\n" );
    WriteOut( " DCM [<a> [<c>]]  Display code (instruction) memory\n" );
    WriteOut( "                  from <a> displaying <c> words\n" );
    WriteOut( " SPC <n>          Set Program Counter to <n>\n" );
    WriteOut( " SSP <n>          Set Stack Pointer to <n>\n" );
    WriteOut( " SFP <n>          Set Frame Pointer to <n>\n" );
    WriteOut( " SDM <a> <v>      Set Data memory at <a> to <v>\n\n" );
    WriteOut( " SBP <a>          Set Breakpoint at code address <a>\n" );
    WriteOut( " DBP              Display all Breakpoints\n" );
    WriteOut( " CBP              Clear all Breakpoints\n\n" );
    WriteOut( " Commands may be abbreviated to shortest unique prefix\n");
}


ParseKeyword

original_code:
static int ParseKeyword( int *value )
{
    int keywordcode, state, len, quit;
    char keybuffer[40], *kptr;
    if ( feof(stdin) ) { WriteOut("\n"); return 0; }
    keywordcode = -3;
    len = 0;
    state = 0; quit = 0;
    kptr = keybuffer;
    while ( !quit ) {
        switch( state ) {
            case 0:
                if ( *lptr == '\n' || *lptr == '\0' ) {
                    keywordcode = -1; quit = 1;
                }
                else if ( *lptr == '?' ) {
                    keywordcode = -5; quit = 1;
                }
                else if ( ((*__ctype_b_loc ())[(int) ((*lptr))] & (unsigned short int) _ISspace) ) lptr++;
                else if ( ((*__ctype_b_loc ())[(int) ((*lptr))] & (unsigned short int) _ISalpha) ) {
                    *kptr = (char)toupper( *lptr ); kptr++; lptr++;
                    len = 1; state = 1;
                }
                else if ( ((*__ctype_b_loc ())[(int) ((*lptr))] & (unsigned short int) _ISdigit) ) {
                    *value = *lptr - '0'; lptr++;
                    state = 2;
                }
                else {
                    DisplayError( !1, "Illegal Character in input %c\n", *lptr );
                    keywordcode = -3; quit = 1;
                }
                break;
            case 1:
                if ( ((*__ctype_b_loc ())[(int) ((*lptr))] & (unsigned short int) _ISalpha) ) {
                    if ( len < 40 ) {
                        *kptr = (char)toupper( *lptr ); kptr++;
                    }
                    lptr++; len++;
                }
                else {
                    *kptr = '\0'; keywordcode = -4; quit = 1;
                }
                break;
            case 2:
                if ( ((*__ctype_b_loc ())[(int) ((*lptr))] & (unsigned short int) _ISdigit) ) {
                    if ( *value <= (32750/10) ) {
                        *value *= 10;
                        *value += ( *lptr - '0' );
                        lptr++;
                    }
                    else {
                        DisplayError( !1, "Integer value too large, max = %d\n",
                                      32750 );
                        keywordcode = -3; quit = 1;
                    }
                }
                else {
                    keywordcode = -2; quit = 1;
                }
                break;
            default:
                DisplayError( 1, "Command line scanner, unknown state %d\n",
                              state );
        }
    }
    if ( keywordcode == -4 ) {
        if ( *keybuffer == 'E' ) keywordcode = 0;
        else if ( *keybuffer == 'H' ) keywordcode = -5;
        else if ( *keybuffer == 'L' ) keywordcode = 14;
        else if ( *keybuffer == 'T' ) keywordcode = 5;
        else if ( *keybuffer == 'R' &&
                  *(keybuffer+1) == 'U' ) keywordcode = 4;
        else if ( *keybuffer == 'R' &&
                  *(keybuffer+1) == 'E' ) keywordcode = 13;
        else if ( *keybuffer == 'D' &&
                  *(keybuffer+1) == 'R' ) keywordcode = 1;
        else if ( *keybuffer == 'D' &&
                  *(keybuffer+1) == 'D' ) keywordcode = 2;
        else if ( *keybuffer == 'D' &&
                  *(keybuffer+1) == 'C' ) keywordcode = 3;
        else if ( *keybuffer == 'S' &&
                  *(keybuffer+1) == 'P' ) keywordcode = 6;
        else if ( *keybuffer == 'S' &&
                  *(keybuffer+1) == 'F' ) keywordcode = 8;
        else if ( *keybuffer == 'S' &&
                  *(keybuffer+1) == 'S' ) keywordcode = 7;
        else if ( *keybuffer == 'S' &&
                  *(keybuffer+1) == 'D' ) keywordcode = 9;
        else if ( *keybuffer == 'S' &&
                  *(keybuffer+1) == 'B' ) keywordcode = 10;
        else if ( *keybuffer == 'D' &&
                  *(keybuffer+1) == 'B' ) keywordcode = 11;
        else if ( *keybuffer == 'C' &&
                  *(keybuffer+1) == 'B' ) keywordcode = 12;
        else {
            DisplayError( !1, "Unknown Command \"%s\"\n", keybuffer );
            keywordcode = -3;
        }
    }
    return keywordcode;
}

canonical_original_code:
static int ParseKeyword(int *value)
{
    int keywordcode; int state; int len; int quit;
    char keybuffer[40]; char *kptr;
    if ( feof(stdin) ) { WriteOut("\n"); return 0; }
    keywordcode = -3;
    len = 0;
    state = 0; quit = 0;
    kptr = keybuffer;
    while ( !quit ) {
        switch( state ) {
            case 0:
                if ( *lptr == '\n' || *lptr == '\0' ) {
                    keywordcode = -1; quit = 1;
                }
                else if ( *lptr == '?' ) {
                    keywordcode = -5; quit = 1;
                }
                else if ( ((*__ctype_b_loc ())[(int) ((*lptr))] & (unsigned short) _ISspace) ) lptr++;
                else if ( ((*__ctype_b_loc ())[(int) ((*lptr))] & (unsigned short) _ISalpha) ) {
                    *kptr = (char)toupper( *lptr ); kptr++; lptr++;
                    len = 1; state = 1;
                }
                else if ( ((*__ctype_b_loc ())[(int) ((*lptr))] & (unsigned short) _ISdigit) ) {
                    *value = *lptr - '0'; lptr++;
                    state = 2;
                }
                else {
                    DisplayError( !1, "Illegal Character in input %c\n", *lptr );
                    keywordcode = -3; quit = 1;
                }
                break;
            case 1:
                if ( ((*__ctype_b_loc ())[(int) ((*lptr))] & (unsigned short) _ISalpha) ) {
                    if ( len < 40 ) {
                        *kptr = (char)toupper( *lptr ); kptr++;
                    }
                    lptr++; len++;
                }
                else {
                    *kptr = '\0'; keywordcode = -4; quit = 1;
                }
                break;
            case 2:
                if ( ((*__ctype_b_loc ())[(int) ((*lptr))] & (unsigned short) _ISdigit) ) {
                    if ( *value <= (32750/10) ) {
                        *value *= 10;
                        *value += ( *lptr - '0' );
                        lptr++;
                    }
                    else {
                        DisplayError( !1, "Integer value too large, max = %d\n",
                                      32750 );
                        keywordcode = -3; quit = 1;
                    }
                }
                else {
                    keywordcode = -2; quit = 1;
                }
                break;
            default:
                DisplayError( 1, "Command line scanner, unknown state %d\n",
                              state );
        }
    }
    if ( keywordcode == -4 ) {
        if ( *keybuffer == 'E' ) keywordcode = 0;
        else if ( *keybuffer == 'H' ) keywordcode = -5;
        else if ( *keybuffer == 'L' ) keywordcode = 14;
        else if ( *keybuffer == 'T' ) keywordcode = 5;
        else if ( *keybuffer == 'R' &&
                  *(keybuffer+1) == 'U' ) keywordcode = 4;
        else if ( *keybuffer == 'R' &&
                  *(keybuffer+1) == 'E' ) keywordcode = 13;
        else if ( *keybuffer == 'D' &&
                  *(keybuffer+1) == 'R' ) keywordcode = 1;
        else if ( *keybuffer == 'D' &&
                  *(keybuffer+1) == 'D' ) keywordcode = 2;
        else if ( *keybuffer == 'D' &&
                  *(keybuffer+1) == 'C' ) keywordcode = 3;
        else if ( *keybuffer == 'S' &&
                  *(keybuffer+1) == 'P' ) keywordcode = 6;
        else if ( *keybuffer == 'S' &&
                  *(keybuffer+1) == 'F' ) keywordcode = 8;
        else if ( *keybuffer == 'S' &&
                  *(keybuffer+1) == 'S' ) keywordcode = 7;
        else if ( *keybuffer == 'S' &&
                  *(keybuffer+1) == 'D' ) keywordcode = 9;
        else if ( *keybuffer == 'S' &&
                  *(keybuffer+1) == 'B' ) keywordcode = 10;
        else if ( *keybuffer == 'D' &&
                  *(keybuffer+1) == 'B' ) keywordcode = 11;
        else if ( *keybuffer == 'C' &&
                  *(keybuffer+1) == 'B' ) keywordcode = 12;
        else {
            DisplayError( !1, "Unknown Command \"%s\"\n", keybuffer );
            keywordcode = -3;
        }
    }
    return keywordcode;
}

variable_types:
value
int *

variable_types: keywordcode int

variable_types: state int

variable_types: len int

variable_types: quit int

variable_types:
keybuffer
char [40]

variable_types:
kptr
char *


ReadCommand

decompiled_code:
__int64 __fastcall ReadCommand(_DWORD *a1, _DWORD *a2)
{
unsigned int v2; // er12
int v4; // eax
int v5; // eax
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

while ( 2 )
{
WriteOut("==> ");
lptr = ReadString();
v2 = ParseKeyword(v6);
switch ( v2 )
{
case 0xFFFFFFFB:
DisplayHelp();
continue;
case 0xFFFFFFFD:
case 0xFFFFFFFF:
continue;
case 0xFFFFFFFE:
DisplayError(0LL, "Integer value not allowed here\n");
continue;
case 0u:
case 1u:
case 0xBu:
case 0xCu:
case 0xDu:
case 0xEu:
return v2;
case 2u:
case 3u:
v4 = ParseKeyword(v6);
if ( v4 != -2 )
goto LABEL_7;
*a1 = v6[0];
v5 = ParseKeyword(v6);
if ( v5 == -2 )
goto LABEL_19;
if ( v5 == -1 )
goto LABEL_12;
goto LABEL_8;
case 4u:
case 5u:
v4 = ParseKeyword(v6);
if ( v4 == -2 )
goto LABEL_2;
LABEL_7:
if ( v4 != -1 )
{
LABEL_8:
DisplayError(0LL, "Integer or end of line expected\n");
continue;
}
*a1 = -1;
LABEL_12:
*a2 = -1;
return v2;
case 6u:
case 7u:
case 8u:
case 0xAu:
if ( (unsigned int)ParseKeyword(v6) != -2 )
goto LABEL_5;
LABEL_2:
*a1 = v6[0];
*a2 = -1;
return v2;
case 9u:
if ( (unsigned int)ParseKeyword(v6) == -2 )
{
*a1 = v6[0];
if ( (unsigned int)ParseKeyword(v6) == -2 )
{
LABEL_19:
*a2 = v6[0];
return v2;
}
LABEL_5:
DisplayError(0LL, "Integer expected\n");
}
else
{
DisplayError(0LL, "Two integer values expected\n");
}
continue;
default:
DisplayError(1LL, "Error, unknown state in ReadCommand %d\n", v2);
continue;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _DWORD *a2)
{
unsigned int v2; // er12
int v4; // eax
int v5; // eax
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

while ( 2 )
{
WriteOut("==> ");
lptr = ReadString();
v2 = func1(v6);
switch ( v2 )
{
case 0xFFFFFFFB:
func0();
continue;
case 0xFFFFFFFD:
case 0xFFFFFFFF:
continue;
case 0xFFFFFFFE:
DisplayError(0LL, "Integer value not allowed here\n");
continue;
case 0u:
case 1u:
case 0xBu:
case 0xCu:
case 0xDu:
case 0xEu:
return v2;
case 2u:
case 3u:
v4 = func1(v6);
if ( v4 != -2 )
goto LABEL_7;
*a1 = v6[0];
v5 = func1(v6);
if ( v5 == -2 )
goto LABEL_19;
if ( v5 == -1 )
goto LABEL_12;
goto LABEL_8;
case 4u:
case 5u:
v4 = func1(v6);
if ( v4 == -2 )
goto LABEL_2;
LABEL_7:
if ( v4 != -1 )
{
LABEL_8:
DisplayError(0LL, "Integer or end of line expected\n");
continue;
}
*a1 = -1;
LABEL_12:
*a2 = -1;
return v2;
case 6u:
case 7u:
case 8u:
case 0xAu:
if ( (unsigned int)func1(v6) != -2 )
goto LABEL_5;
LABEL_2:
*a1 = v6[0];
*a2 = -1;
return v2;
case 9u:
if ( (unsigned int)func1(v6) == -2 )
{
*a1 = v6[0];
if ( (unsigned int)func1(v6) == -2 )
{
LABEL_19:
*a2 = v6[0];
return v2;
}
LABEL_5:
DisplayError(0LL, "Integer expected\n");
}
else
{
DisplayError(0LL, "Two integer values expected\n");
}
continue;
default:
DisplayError(1LL, "Error, unknown state in ReadCommand %d\n", v2);
continue;
}
}
}

original_code:
int ReadCommand( int *p1, int *p2 )
{
    int quit, command, keyword, value;
    quit = 0;
    command = -3;
    while ( !quit ) {
        WriteOut( "==> " );
        lptr = ReadString();
        command = ParseKeyword( &value );
        switch ( command ) {
            case -1: break;
            case -3: break;
            case -5:
                DisplayHelp();
                break;
            case -2:
                DisplayError( !1, "Integer value not allowed here\n" );
                break;
            case 0:
            case 14:
            case 13:
            case 1:
     case 11:
     case 12:
                quit = 1;
                break;
            case 4:
            case 5:
                if ( -2 == ( keyword = ParseKeyword( &value ) ) ) {
                    *p1 = value; *p2 = -1; quit = 1;
                }
                else if ( keyword == -1 ) {
                    *p1 = -1; *p2 = -1; quit = 1;
                }
                else DisplayError( !1, "Integer or end of line expected\n" );
                break;
            case 6:
            case 7:
            case 8:
     case 10:
                if ( -2 == ParseKeyword( &value ) ) {
                    *p1 = value; *p2 = -1; quit = 1;
                }
                else DisplayError( !1, "Integer expected\n" );
                break;
            case 2:
            case 3:
                if ( -2 == ( keyword = ParseKeyword( &value ) ) ) {
                    *p1 = value;
                    if ( -2 == ( keyword = ParseKeyword( &value ) ) ) {
                        *p2 = value; quit = 1;
                    }
                    else if ( keyword == -1 ) {
                        *p2 = -1; quit = 1;
                    }
                    else DisplayError( !1, "Integer or end of line expected\n" );
                }
                else if ( keyword == -1 ) {
                    *p1 = -1; *p2 = -1; quit = -1;
                }
                else DisplayError( !1, "Integer or end of line expected\n" );
                break;
            case 9:
                if ( -2 == ParseKeyword( &value ) ) {
                    *p1 = value;
                    if ( -2 == ParseKeyword( &value ) ) {
                        *p2 = value; quit = 1;
                    }
                    else DisplayError( !1, "Integer expected\n" );
                }
                else DisplayError( !1, "Two integer values expected\n" );
                break;
            default:
                DisplayError( 1, "Error, unknown state in ReadCommand %d\n",
                              command );
                break;
        }
    }
    return command;
}

canonical_original_code:
int ReadCommand(int *p1, int *p2)
{
    int quit; int command; int keyword; int value;
    quit = 0;
    command = -3;
    while ( !quit ) {
        WriteOut( "==> " );
        lptr = ReadString();
        command = ParseKeyword( &value );
        switch ( command ) {
            case -1: break;
            case -3: break;
            case -5:
                DisplayHelp();
                break;
            case -2:
                DisplayError( !1, "Integer value not allowed here\n" );
                break;
            case 0:
            case 14:
            case 13:
            case 1:
     case 11:
     case 12:
                quit = 1;
                break;
            case 4:
            case 5:
                if ( -2 == ( keyword = ParseKeyword( &value ) ) ) {
                    *p1 = value; *p2 = -1; quit = 1;
                }
                else if ( keyword == -1 ) {
                    *p1 = -1; *p2 = -1; quit = 1;
                }
                else DisplayError( !1, "Integer or end of line expected\n" );
                break;
            case 6:
            case 7:
            case 8:
     case 10:
                if ( -2 == ParseKeyword( &value ) ) {
                    *p1 = value; *p2 = -1; quit = 1;
                }
                else DisplayError( !1, "Integer expected\n" );
                break;
            case 2:
            case 3:
                if ( -2 == ( keyword = ParseKeyword( &value ) ) ) {
                    *p1 = value;
                    if ( -2 == ( keyword = ParseKeyword( &value ) ) ) {
                        *p2 = value; quit = 1;
                    }
                    else if ( keyword == -1 ) {
                        *p2 = -1; quit = 1;
                    }
                    else DisplayError( !1, "Integer or end of line expected\n" );
                }
                else if ( keyword == -1 ) {
                    *p1 = -1; *p2 = -1; quit = -1;
                }
                else DisplayError( !1, "Integer or end of line expected\n" );
                break;
            case 9:
                if ( -2 == ParseKeyword( &value ) ) {
                    *p1 = value;
                    if ( -2 == ParseKeyword( &value ) ) {
                        *p2 = value; quit = 1;
                    }
                    else DisplayError( !1, "Integer expected\n" );
                }
                else DisplayError( !1, "Two integer values expected\n" );
                break;
            default:
                DisplayError( 1, "Error, unknown state in ReadCommand %d\n",
                              command );
                break;
        }
    }
    return command;
}

variable_types: command int

variable_types: keyword int

variable_types: value int


AddressError

decompiled_code:
__int64 __fastcall AddressError(const char *a1)
{
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

Disassemble(&Pmem[2 * PC], v2);
DisplayError(
0LL,
"Error: %s, PC = %d, SP = %d, FP = %d\n",
a1,
(unsigned int)PC,
(unsigned int)dword_794,
(unsigned int)FP);
return DisplayError(0LL, " Instruction \"%s\"\n", v2);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

Disassemble(&Pmem[2 * PC], v2);
DisplayError(
0LL,
"Error: %s, PC = %d, SP = %d, FP = %d\n",
a1,
(unsigned int)PC,
(unsigned int)dword_794,
(unsigned int)FP);
return DisplayError(0LL, " Instruction \"%s\"\n", v2);
}

original_code:
static void AddressError( char *ErrorString )
{
    char buffer[80];
    Disassemble( Pmem+PC, buffer );
    DisplayError( !1, "Error: %s, PC = %d, SP = %d, FP = %d\n",
                  ErrorString, PC, SP, FP );
    DisplayError( !1, "       Instruction \"%s\"\n", buffer );
}

canonical_original_code:
static void AddressError(char *ErrorString)
{
    char buffer[80];
    Disassemble( Pmem+PC, buffer );
    DisplayError( !1, "Error: %s, PC = %d, SP = %d, FP = %d\n",
                  ErrorString, PC, SP, FP );
    DisplayError( !1, "       Instruction \"%s\"\n", buffer );
}

variable_types:
ErrorString
char *

variable_types:
buffer
char [80]


CodeAddr

decompiled_code:
__int64 __fastcall CodeAddr(unsigned int a1)
{
__int64 result; // rax
char v2[88]; // [rsp-58h] [rbp-58h] BYREF

result = a1;
if ( a1 > 0x400 )
{
sprintf(v2, "Illegal code address %d", a1);
AddressError(v2);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 result; // rax
char v2[88]; // [rsp-58h] [rbp-58h] BYREF

result = a1;
if ( a1 > 0x400 )
{
sprintf(v2, "Illegal code address %d", a1);
func0(v2);
exit(1);
}
return result;
}

original_code:
static int CodeAddr( int addr )
{
    char buffer[80];
    if ( addr < 0 || addr > 1024 ) {
        sprintf( buffer, "Illegal code address %d", addr );
        AddressError( buffer );
        exit( 1 );
    }
    return addr;
}

canonical_original_code:
static int CodeAddr(int addr)
{
    char buffer[80];
    if ( addr < 0 || addr > 1024 ) {
        sprintf( buffer, "Illegal code address %d", addr );
        AddressError( buffer );
        exit( 1 );
    }
    return addr;
}

variable_types: addr int


Decrement

decompiled_code:
__int64 __fastcall Decrement(int a1, int a2)
{
__int64 result; // rax
char v3[88]; // [rsp-58h] [rbp-58h] BYREF

result = (unsigned int)(a1 - a2);
if ( (int)result < -1 )
{
sprintf(v3, "Illegal stack pointer address %d", (unsigned int)result);
AddressError(v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
__int64 result; // rax
char v3[88]; // [rsp-58h] [rbp-58h] BYREF

result = (unsigned int)(a1 - a2);
if ( (int)result < -1 )
{
sprintf(v3, "Illegal stack pointer address %d", (unsigned int)result);
func0(v3);
exit(1);
}
return result;
}

original_code:
static int Decrement( int currentSP, int amount )
{
    int newSP;
    char buffer[80];
    newSP = currentSP - amount;
    if ( newSP < -1 ) {
        sprintf( buffer, "Illegal stack pointer address %d", newSP );
        AddressError( buffer );
        exit( 1 );
    }
    return newSP;
}

canonical_original_code:
static int Decrement(int currentSP, int amount)
{
    int newSP;
    char buffer[80];
    newSP = currentSP - amount;
    if ( newSP < -1 ) {
        sprintf( buffer, "Illegal stack pointer address %d", newSP );
        AddressError( buffer );
        exit( 1 );
    }
    return newSP;
}

variable_types: currentSP int

variable_types: amount int

variable_types: newSP int


Push

decompiled_code:
__int64 __fastcall Push(int a1)
{
int v1; // eax
__int64 result; // rax

v1 = dword_794;
if ( dword_794 > 1022 )
{
AddressError("Stack Overflow");
exit(1);
}
++dword_794;
result = v1 + 1;
Dmem[result] = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // eax
__int64 result; // rax

v1 = dword_794;
if ( dword_794 > 1022 )
{
func0("Stack Overflow");
exit(1);
}
++dword_794;
result = v1 + 1;
Dmem[result] = a1;
return result;
}

original_code:
static void Push( int value )
{
    if ( SP >= 1024 -1 ) {
        AddressError( "Stack Overflow" );
        exit( 1 );
    }
    else {
        SP++;
        Dmem[SP] = value;
    }
}

canonical_original_code:
static void Push(int value)
{
    if ( SP >= 1024 -1 ) {
        AddressError( "Stack Overflow" );
        exit( 1 );
    }
    else {
        SP++;
        Dmem[SP] = value;
    }
}


BuildStackFrame

decompiled_code:
__int64 BuildStackFrame()
{
int v0; // ebx
__int64 result; // rax

v0 = dword_794;
result = Push(FP);
FP = v0;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebx
__int64 result; // rax

v0 = dword_794;
result = func3(FP);
FP = v0;
return result;
}

original_code:
static void BuildStackFrame( void )
{
    int temp, oldsp;
    temp = FP;
    oldsp = SP;
    Push( temp );
    FP = oldsp;
}

canonical_original_code:
static void BuildStackFrame()
{
    int temp; int oldsp;
    temp = FP;
    oldsp = SP;
    Push( temp );
    FP = oldsp;
}

variable_types: temp int

variable_types: oldsp int


DataAddr

decompiled_code:
__int64 __fastcall DataAddr(unsigned int a1)
{
__int64 result; // rax
char v2[88]; // [rsp-58h] [rbp-58h] BYREF

result = a1;
if ( a1 > 0x400 )
{
sprintf(v2, "Illegal data address %d", a1);
AddressError(v2);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
__int64 result; // rax
char v2[88]; // [rsp-58h] [rbp-58h] BYREF

result = a1;
if ( a1 > 0x400 )
{
sprintf(v2, "Illegal data address %d", a1);
func0(v2);
exit(1);
}
return result;
}

original_code:
static int DataAddr( int addr )
{
    char buffer[80];
    if ( addr < 0 || addr > 1024 ) {
        sprintf( buffer, "Illegal data address %d", addr );
        AddressError( buffer );
        exit( 1 );
    }
    return addr;
}

canonical_original_code:
static int DataAddr(int addr)
{
    char buffer[80];
    if ( addr < 0 || addr > 1024 ) {
        sprintf( buffer, "Illegal data address %d", addr );
        AddressError( buffer );
        exit( 1 );
    }
    return addr;
}


RemoveStackFrame

decompiled_code:
__int64 RemoveStackFrame()
{
int v0; // eax
__int64 result; // rax

dword_794 = DataAddr(FP) - 1;
v0 = DataAddr(FP + 1);
result = DataAddr(Dmem[v0]);
FP = result;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax
__int64 result; // rax

dword_794 = func5(FP) - 1;
v0 = func5(FP + 1);
result = func5(Dmem[v0]);
FP = result;
return result;
}

original_code:
static void RemoveStackFrame( void )
{
    int addr;
    addr = DataAddr( FP );
    SP = addr - 1;
    addr = DataAddr( FP + 1 );
    FP = DataAddr( Dmem[ addr ] );
}

canonical_original_code:
static void RemoveStackFrame()
{
    int addr;
    addr = DataAddr( FP );
    SP = addr - 1;
    addr = DataAddr( FP + 1 );
    FP = DataAddr( Dmem[ addr ] );
}


LoadDisplayPointer

decompiled_code:
__int64 LoadDisplayPointer()
{
__int64 v0; // rbx
int v1; // ebp
__int64 result; // rax

v0 = (int)DataAddr(Pmem[2 * PC + 1]);
v1 = Dmem[v0];
Dmem[(int)DataAddr(FP)] = v1;
result = (unsigned int)FP;
Dmem[v0] = FP;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rbx
int v1; // ebp
__int64 result; // rax

v0 = (int)func5(Pmem[2 * PC + 1]);
v1 = Dmem[v0];
Dmem[(int)func5(FP)] = v1;
result = (unsigned int)FP;
Dmem[v0] = FP;
return result;
}

original_code:
static void LoadDisplayPointer( void )
{
    int addr, temp;
    addr = DataAddr( Pmem[PC].offset );
    temp = Dmem[ addr ];
    Dmem[ DataAddr( FP ) ] = temp;
    Dmem[ addr ] = FP;
}

canonical_original_code:
static void LoadDisplayPointer()
{
    int addr; int temp;
    addr = DataAddr( Pmem[PC].offset );
    temp = Dmem[ addr ];
    Dmem[ DataAddr( FP ) ] = temp;
    Dmem[ addr ] = FP;
}


RestoreDisplayPointer

decompiled_code:
__int64 RestoreDisplayPointer()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = (int)DataAddr(Pmem[2 * PC + 1]);
result = (unsigned int)Dmem[(int)DataAddr(FP)];
Dmem[v0] = result;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = (int)func5(Pmem[2 * PC + 1]);
result = (unsigned int)Dmem[(int)func5(FP)];
Dmem[v0] = result;
return result;
}

original_code:
static void RestoreDisplayPointer( void )
{
    int addr;
    addr = DataAddr( Pmem[PC].offset );
    Dmem[ addr ] = Dmem[ DataAddr( FP ) ];
}

canonical_original_code:
static void RestoreDisplayPointer()
{
    int addr;
    addr = DataAddr( Pmem[PC].offset );
    Dmem[ addr ] = Dmem[ DataAddr( FP ) ];
}


Pop

decompiled_code:
__int64 Pop()
{
if ( dword_794 < 0 )
{
AddressError("Stack Underflow");
exit(1);
}
return (unsigned int)Dmem[dword_794--];
}

canonical_decompiled_code:
__int64 func9()
{
if ( dword_794 < 0 )
{
func0("Stack Underflow");
exit(1);
}
return (unsigned int)Dmem[dword_794--];
}

original_code:
static int Pop( void )
{
    int temp;
    if ( SP < 0 ) {
        AddressError( "Stack Underflow" );
        exit( 1 );
    }
    else {
        temp = Dmem[SP];
        SP--;
    }
    return temp;
}

canonical_original_code:
static int Pop()
{
    int temp;
    if ( SP < 0 ) {
        AddressError( "Stack Underflow" );
        exit( 1 );
    }
    else {
        temp = Dmem[SP];
        SP--;
    }
    return temp;
}


BinaryOp

decompiled_code:
__int64 __fastcall BinaryOp(int a1)
{
int v2; // ebp
int v3; // eax
int v4; // edi
int v5; // eax

v2 = Pop();
v3 = Pop();
if ( a1 == 3 )
return Push(v3 * v2);
if ( a1 == 4 )
return Push(v3 / v2);
v4 = v2 + v3;
v5 = v3 - v2;
if ( a1 == 2 )
v4 = v5;
return Push(v4);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
int v2; // ebp
int v3; // eax
int v4; // edi
int v5; // eax

v2 = func9();
v3 = func9();
if ( a1 == 3 )
return func3(v3 * v2);
if ( a1 == 4 )
return func3(v3 / v2);
v4 = v2 + v3;
v5 = v3 - v2;
if ( a1 == 2 )
v4 = v5;
return func3(v4);
}

original_code:
static void BinaryOp( int opcode )
{
    int tos, tos_m1;
    tos = Pop(); tos_m1 = Pop();
    switch ( opcode ) {
        case 1 : tos_m1 += tos; break;
        case 2 : tos_m1 -= tos; break;
        case 3 : tos_m1 *= tos; break;
        case 4 : tos_m1 /= tos; break;
        default:
            DisplayError( !1, "Error, illegal opcode in BinaryOp, %d\n",
                          opcode );
            break;
    }
    Push( tos_m1 );
}

canonical_original_code:
static void BinaryOp(int opcode)
{
    int tos; int tos_m1;
    tos = Pop(); tos_m1 = Pop();
    switch ( opcode ) {
        case 1 : tos_m1 += tos; break;
        case 2 : tos_m1 -= tos; break;
        case 3 : tos_m1 *= tos; break;
        case 4 : tos_m1 /= tos; break;
        default:
            DisplayError( !1, "Error, illegal opcode in BinaryOp, %d\n",
                          opcode );
            break;
    }
    Push( tos_m1 );
}

variable_types: opcode int

variable_types: tos int


Branch

decompiled_code:
__int64 __fastcall Branch(int a1)
{
unsigned int v1; // er12
int v3; // eax

v1 = Pmem[2 * PC + 1];
if ( a1 == 6 )
return v1;
v3 = Pop();
switch ( a1 )
{
case 8:
if ( v3 > 0 )
return v1;
break;
case 9:
if ( v3 <= 0 )
return v1;
break;
case 10:
if ( v3 < 0 )
return v1;
break;
case 11:
if ( !v3 )
return v1;
break;
case 12:
if ( v3 )
return v1;
break;
default:
if ( v3 >= 0 )
return v1;
break;
}
return (unsigned int)(PC + 1);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
unsigned int v1; // er12
int v3; // eax

v1 = Pmem[2 * PC + 1];
if ( a1 == 6 )
return v1;
v3 = func9();
switch ( a1 )
{
case 8:
if ( v3 > 0 )
return v1;
break;
case 9:
if ( v3 <= 0 )
return v1;
break;
case 10:
if ( v3 < 0 )
return v1;
break;
case 11:
if ( !v3 )
return v1;
break;
case 12:
if ( v3 )
return v1;
break;
default:
if ( v3 >= 0 )
return v1;
break;
}
return (unsigned int)(PC + 1);
}

original_code:
static int Branch( int opcode )
{
    int flag = 0,
        nextaddr;
    nextaddr = Pmem[PC].offset;
    if ( opcode != 6 ) flag = Pop();
    switch ( opcode ) {
        case 6 : break;
        case 7 : if ( flag < 0 ) nextaddr = PC+1; break;
        case 8 : if ( flag <= 0 ) nextaddr = PC+1; break;
        case 9 : if ( flag > 0 ) nextaddr = PC+1; break;
        case 10 : if ( flag >= 0 ) nextaddr = PC+1; break;
        case 11 : if ( flag != 0 ) nextaddr = PC+1; break;
        case 12 : if ( flag == 0 ) nextaddr = PC+1; break;
        default:
            DisplayError( !1, "Error, illegal opcode in Branch, %d\n",
                          opcode );
            break;
    }
    return nextaddr;
}

canonical_original_code:
static int Branch(int opcode)
{
    int flag = 0; int nextaddr;
    nextaddr = Pmem[PC].offset;
    if ( opcode != 6 ) flag = Pop();
    switch ( opcode ) {
        case 6 : break;
        case 7 : if ( flag < 0 ) nextaddr = PC+1; break;
        case 8 : if ( flag <= 0 ) nextaddr = PC+1; break;
        case 9 : if ( flag > 0 ) nextaddr = PC+1; break;
        case 10 : if ( flag >= 0 ) nextaddr = PC+1; break;
        case 11 : if ( flag != 0 ) nextaddr = PC+1; break;
        case 12 : if ( flag == 0 ) nextaddr = PC+1; break;
        default:
            DisplayError( !1, "Error, illegal opcode in Branch, %d\n",
                          opcode );
            break;
    }
    return nextaddr;
}

variable_types: flag int

variable_types: nextaddr int


WriteInteger

decompiled_code:
__int64 WriteInteger()
{
unsigned int v0; // eax

v0 = Pop();
return WriteOut("\n!! Write instruction, Top of Stack --> \"%d\"\n\n", v0);
}

canonical_decompiled_code:
__int64 func12()
{
unsigned int v0; // eax

v0 = func9();
return WriteOut("\n!! Write instruction, Top of Stack --> \"%d\"\n\n", v0);
}

original_code:
static void WriteInteger( void )
{
    WriteOut( "\n!! Write instruction, Top of Stack --> \"%d\"\n\n", Pop() );
}

canonical_original_code:
static void WriteInteger()
{
    WriteOut( "\n!! Write instruction, Top of Stack --> \"%d\"\n\n", Pop() );
}


ReadInteger

decompiled_code:
__int64 ReadInteger()
{
const char *i; // rdi
int v2; // [rsp+Ch] [rbp-Ch] BYREF

WriteOut("\n!! Read instruction, Enter integer --> ");
for ( i = (const char *)ReadString(); sscanf(i, " %d", &v2) != 1; i = (const char *)ReadString() )
WriteOut(" Invalid integer, try again --> ");
return Push(v2);
}

canonical_decompiled_code:
__int64 func13()
{
const char *i; // rdi
int v2; // [rsp+Ch] [rbp-Ch] BYREF

WriteOut("\n!! Read instruction, Enter integer --> ");
for ( i = (const char *)ReadString(); sscanf(i, " %d", &v2) != 1; i = (const char *)ReadString() )
WriteOut(" Invalid integer, try again --> ");
return func3(v2);
}

original_code:
static void ReadInteger( void )
{
    char *buffer;
    int value;
    WriteOut( "\n!! Read instruction, Enter integer --> " );
    buffer = ReadString();
    while ( 1 != sscanf( buffer, " %d", &value ) ) {
        WriteOut( "   Invalid integer, try again --> " );
        buffer = ReadString();
    }
    Push( value );
}

canonical_original_code:
static void ReadInteger()
{
    char *buffer;
    int value;
    WriteOut( "\n!! Read instruction, Enter integer --> " );
    buffer = ReadString();
    while ( 1 != sscanf( buffer, " %d", &value ) ) {
        WriteOut( "   Invalid integer, try again --> " );
        buffer = ReadString();
    }
    Push( value );
}

variable_types:
buffer
char *


Interpret

decompiled_code:
__int64 Interpret()
{
unsigned int v0; // ebx
int v1; // ebp
int v2; // er12
__int64 result; // rax
unsigned int v4; // eax
int v5; // eax
__int64 v6; // rbx
__int64 v7; // rbx
__int64 v8; // rbx
int v9; // edx
int v10; // eax
int v11; // eax
unsigned int v12; // eax

v0 = Pmem[2 * PC];
v1 = PC + 1;
v2 = Pmem[2 * PC + 1];
switch ( v0 )
{
case 0u:
result = WriteOut("!! HALT encountered\n\n");
Running = 0;
break;
case 1u:
result = BinaryOp(1);
break;
case 2u:
result = BinaryOp(2);
break;
case 3u:
result = BinaryOp(3);
break;
case 4u:
result = BinaryOp(4);
break;
case 5u:
result = dword_794;
Dmem[dword_794] = -Dmem[dword_794];
break;
case 6u:
result = Branch(6);
v1 = result;
break;
case 7u:
result = Branch(7);
v1 = result;
break;
case 8u:
result = Branch(8);
v1 = result;
break;
case 9u:
result = Branch(9);
v1 = result;
break;
case 0xAu:
result = Branch(10);
v1 = result;
break;
case 0xBu:
result = Branch(11);
v1 = result;
break;
case 0xCu:
result = Branch(12);
v1 = result;
break;
case 0xDu:
Push(v1);
result = CodeAddr(v2);
v1 = result;
break;
case 0xEu:
v12 = Pop();
result = CodeAddr(v12);
v1 = result;
break;
case 0xFu:
result = BuildStackFrame();
break;
case 0x10u:
result = RemoveStackFrame();
break;
case 0x11u:
result = LoadDisplayPointer();
break;
case 0x12u:
result = RestoreDisplayPointer();
break;
case 0x13u:
result = DataAddr(v2 + dword_794);
dword_794 = result;
break;
case 0x14u:
result = Decrement(dword_794, v2);
dword_794 = result;
break;
case 0x15u:
result = Push(FP);
break;
case 0x16u:
result = Push(v2);
break;
case 0x17u:
v11 = DataAddr(v2);
result = Push(Dmem[v11]);
break;
case 0x18u:
v10 = DataAddr(v2 + FP);
result = Push(Dmem[v10]);
break;
case 0x19u:
v9 = Dmem[(int)DataAddr(v2 + Dmem[dword_794])];
result = dword_794;
Dmem[dword_794] = v9;
break;
case 0x1Au:
v8 = (int)DataAddr(v2);
result = Pop();
Dmem[v8] = result;
break;
case 0x1Bu:
v7 = (int)DataAddr(v2 + FP);
result = Pop();
Dmem[v7] = result;
break;
case 0x1Cu:
v4 = Pop();
v5 = DataAddr(v4);
v6 = (int)DataAddr(v5 + v2);
result = Pop();
Dmem[v6] = result;
break;
case 0x1Du:
result = ReadInteger();
break;
case 0x1Eu:
result = WriteInteger();
break;
default:
DisplayError(0LL, "Error, unknown opcode encountered\n");
result = DisplayError(
1LL,
"PC = %d, SP = %d, FP = %d, opcode = %d\n",
(unsigned int)PC,
(unsigned int)dword_794,
(unsigned int)FP,
v0);
break;
}
PC = v1;
return result;
}

canonical_decompiled_code:
__int64 func14()
{
unsigned int v0; // ebx
int v1; // ebp
int v2; // er12
__int64 result; // rax
unsigned int v4; // eax
int v5; // eax
__int64 v6; // rbx
__int64 v7; // rbx
__int64 v8; // rbx
int v9; // edx
int v10; // eax
int v11; // eax
unsigned int v12; // eax

v0 = Pmem[2 * PC];
v1 = PC + 1;
v2 = Pmem[2 * PC + 1];
switch ( v0 )
{
case 0u:
result = WriteOut("!! HALT encountered\n\n");
Running = 0;
break;
case 1u:
result = func10(1);
break;
case 2u:
result = func10(2);
break;
case 3u:
result = func10(3);
break;
case 4u:
result = func10(4);
break;
case 5u:
result = dword_794;
Dmem[dword_794] = -Dmem[dword_794];
break;
case 6u:
result = func11(6);
v1 = result;
break;
case 7u:
result = func11(7);
v1 = result;
break;
case 8u:
result = func11(8);
v1 = result;
break;
case 9u:
result = func11(9);
v1 = result;
break;
case 0xAu:
result = func11(10);
v1 = result;
break;
case 0xBu:
result = func11(11);
v1 = result;
break;
case 0xCu:
result = func11(12);
v1 = result;
break;
case 0xDu:
func3(v1);
result = func1(v2);
v1 = result;
break;
case 0xEu:
v12 = func9();
result = func1(v12);
v1 = result;
break;
case 0xFu:
result = func4();
break;
case 0x10u:
result = func6();
break;
case 0x11u:
result = func7();
break;
case 0x12u:
result = func8();
break;
case 0x13u:
result = func5(v2 + dword_794);
dword_794 = result;
break;
case 0x14u:
result = func2(dword_794, v2);
dword_794 = result;
break;
case 0x15u:
result = func3(FP);
break;
case 0x16u:
result = func3(v2);
break;
case 0x17u:
v11 = func5(v2);
result = func3(Dmem[v11]);
break;
case 0x18u:
v10 = func5(v2 + FP);
result = func3(Dmem[v10]);
break;
case 0x19u:
v9 = Dmem[(int)func5(v2 + Dmem[dword_794])];
result = dword_794;
Dmem[dword_794] = v9;
break;
case 0x1Au:
v8 = (int)func5(v2);
result = func9();
Dmem[v8] = result;
break;
case 0x1Bu:
v7 = (int)func5(v2 + FP);
result = func9();
Dmem[v7] = result;
break;
case 0x1Cu:
v4 = func9();
v5 = func5(v4);
v6 = (int)func5(v5 + v2);
result = func9();
Dmem[v6] = result;
break;
case 0x1Du:
result = func13();
break;
case 0x1Eu:
result = func12();
break;
default:
DisplayError(0LL, "Error, unknown opcode encountered\n");
result = DisplayError(
1LL,
"PC = %d, SP = %d, FP = %d, opcode = %d\n",
(unsigned int)PC,
(unsigned int)dword_794,
(unsigned int)FP,
v0);
break;
}
PC = v1;
return result;
}

original_code:
void Interpret( void )
{
    INSTRUCTION current;
    int addr, nextaddr;
    current = Pmem[PC];
    nextaddr = PC+1;
    switch ( current.opcode ) {
        case 0: WriteOut( "!! HALT encountered\n\n" );
                       Running = 0; break;
        case 1: BinaryOp( 1 ); break;
        case 2: BinaryOp( 2 ); break;
        case 3: BinaryOp( 3 ); break;
        case 4: BinaryOp( 4 ); break;
        case 5: Dmem[SP] = -Dmem[SP]; break;
        case 6: nextaddr = Branch( 6 ); break;
        case 7: nextaddr = Branch( 7 ); break;
        case 8: nextaddr = Branch( 8 ); break;
        case 9: nextaddr = Branch( 9 ); break;
        case 10: nextaddr = Branch( 10 ); break;
        case 11: nextaddr = Branch( 11 ); break;
        case 12: nextaddr = Branch( 12 ); break;
        case 13: Push( nextaddr );
                       nextaddr = CodeAddr( current.offset ); break;
        case 14: nextaddr = CodeAddr( Pop() ); break;
        case 15: BuildStackFrame(); break;
        case 16: RemoveStackFrame(); break;
        case 17: LoadDisplayPointer(); break;
        case 18: RestoreDisplayPointer(); break;
        case 19: SP = DataAddr( SP + current.offset ); break;
        case 20: SP = Decrement( SP, current.offset ); break;
        case 21: Push( FP ); break;
        case 22: Push( current.offset ); break;
        case 23: addr = DataAddr( current.offset );
                       Push( Dmem[addr] ); break;
        case 24: addr = DataAddr( FP + current.offset );
                       Push( Dmem[addr] ); break;
        case 25: addr = DataAddr( Dmem[SP] + current.offset );
                       Dmem[SP] = Dmem[addr]; break;
        case 26: addr = DataAddr( current.offset );
                       Dmem[addr] = Pop(); break;
        case 27: addr = DataAddr( FP + current.offset );
                       Dmem[addr] = Pop(); break;
        case 28: addr = DataAddr( Pop() );
                       addr = DataAddr( addr + current.offset );
                       Dmem[addr] = Pop(); break;
        case 29: ReadInteger(); break;
        case 30: WriteInteger(); break;
        default:
            DisplayError( !1, "Error, unknown opcode encountered\n" );
            DisplayError( 1, "PC = %d, SP = %d, FP = %d, opcode = %d\n",
                          PC, SP, FP, current.opcode );
            break;
    }
    PC = nextaddr;
}

canonical_original_code:
void Interpret()
{
    struct INSTRUCTION current;
    int addr; int nextaddr;
    current = Pmem[PC];
    nextaddr = PC+1;
    switch ( current.opcode ) {
        case 0: WriteOut( "!! HALT encountered\n\n" );
                       Running = 0; break;
        case 1: BinaryOp( 1 ); break;
        case 2: BinaryOp( 2 ); break;
        case 3: BinaryOp( 3 ); break;
        case 4: BinaryOp( 4 ); break;
        case 5: Dmem[SP] = -Dmem[SP]; break;
        case 6: nextaddr = Branch( 6 ); break;
        case 7: nextaddr = Branch( 7 ); break;
        case 8: nextaddr = Branch( 8 ); break;
        case 9: nextaddr = Branch( 9 ); break;
        case 10: nextaddr = Branch( 10 ); break;
        case 11: nextaddr = Branch( 11 ); break;
        case 12: nextaddr = Branch( 12 ); break;
        case 13: Push( nextaddr );
                       nextaddr = CodeAddr( current.offset ); break;
        case 14: nextaddr = CodeAddr( Pop() ); break;
        case 15: BuildStackFrame(); break;
        case 16: RemoveStackFrame(); break;
        case 17: LoadDisplayPointer(); break;
        case 18: RestoreDisplayPointer(); break;
        case 19: SP = DataAddr( SP + current.offset ); break;
        case 20: SP = Decrement( SP, current.offset ); break;
        case 21: Push( FP ); break;
        case 22: Push( current.offset ); break;
        case 23: addr = DataAddr( current.offset );
                       Push( Dmem[addr] ); break;
        case 24: addr = DataAddr( FP + current.offset );
                       Push( Dmem[addr] ); break;
        case 25: addr = DataAddr( Dmem[SP] + current.offset );
                       Dmem[SP] = Dmem[addr]; break;
        case 26: addr = DataAddr( current.offset );
                       Dmem[addr] = Pop(); break;
        case 27: addr = DataAddr( FP + current.offset );
                       Dmem[addr] = Pop(); break;
        case 28: addr = DataAddr( Pop() );
                       addr = DataAddr( addr + current.offset );
                       Dmem[addr] = Pop(); break;
        case 29: ReadInteger(); break;
        case 30: WriteInteger(); break;
        default:
            DisplayError( !1, "Error, unknown opcode encountered\n" );
            DisplayError( 1, "PC = %d, SP = %d, FP = %d, opcode = %d\n",
                          PC, SP, FP, current.opcode );
            break;
    }
    PC = nextaddr;
}

variable_types: struct INSTRUCTION { int opcode; int offset; }


UnGetToken

decompiled_code:
void __fastcall UnGetToken(int a1, int a2)
{
pbtoken = a1;
pboffset = a2;
pushback = 1;
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2)
{
pbtoken = a1;
pboffset = a2;
pushback = 1;
}

original_code:
static void UnGetToken( int token, int offset )
{
    pbtoken = token;
    pboffset = offset;
    pushback = 1;
}

canonical_original_code:
static void UnGetToken(int token, int offset)
{
    pbtoken = token;
    pboffset = offset;
    pushback = 1;
}

variable_types: token int

variable_types: offset int


GetToken

decompiled_code:
__int64 __fastcall GetToken(int *a1)
{
int v2; // ebx
int v3; // eax
int v4; // ebp
const unsigned __int16 **v5; // r13
unsigned __int16 v6; // ax
__int64 result; // rax
int v8; // edx
int v9; // eax
int v10; // edi
int v11; // ebp
int v12; // eax
__int64 v13; // rcx
int i; // edi
FILE *v15; // r14
char *v16; // r15
int v17; // eax
int v18; // ebp
int v19; // eax
int v20; // eax
FILE *v21; // rdi
int v22; // eax
int v23; // eax
__int64 v24; // [rsp+8h] [rbp-60h]
char s1[4]; // [rsp+10h] [rbp-58h] BYREF
char v26; // [rsp+14h] [rbp-54h]

v2 = pushback;
if ( pushback )
{
pushback = 0;
*a1 = pboffset;
result = (unsigned int)pbtoken;
}
else
{
while ( 1 )
{
v3 = fgetc(InputFile);
v4 = v3;
if ( v3 == 10 )
goto LABEL_17;
if ( v3 == 59 )
break;
v5 = _ctype_b_loc();
v6 = (*v5)[v4];
if ( (v6 & 0x2000) == 0 )
{
if ( (v6 & 0x400) != 0 )
{
v10 = v4;
v11 = 1;
s1[0] = toupper(v10);
v12 = fgetc(InputFile);
v13 = 1LL;
for ( i = v12; ; i = v17 )
{
v15 = InputFile;
v16 = &s1[v13];
if ( ((*v5)[i] & 0x400) == 0 )
break;
if ( v11 > 28 )
{
v24 = v13;
v17 = fgetc(InputFile);
v13 = v24;
}
else
{
++v11;
*v16 = toupper(i);
v17 = fgetc(v15);
v13 = v11;
}
}
ungetc(i, InputFile);
*v16 = 0;
if ( *(_DWORD *)s1 != 1414283592 || v26 )
{
if ( *(_DWORD *)s1 == 4473921 )
{
v2 = 0;
result = 1LL;
}
else if ( *(_DWORD *)s1 == 4347219 )
{
v2 = 0;
result = 2LL;
}
else if ( *(_DWORD *)s1 != 1414288717 || v26 )
{
if ( *(_DWORD *)s1 == 5654852 )
{
v2 = 0;
result = 4LL;
}
else if ( *(_DWORD *)s1 == 4670798 )
{
v2 = 0;
result = 5LL;
}
else if ( *(_WORD *)s1 != 21058 || s1[2] )
{
if ( *(_DWORD *)s1 == 5916482 )
{
v2 = 0;
result = 7LL;
}
else if ( !strcmp(s1, "BG") )
{
v2 = 0;
result = 8LL;
}
else if ( !strcmp(s1, "BLZ") )
{
v2 = 0;
result = 9LL;
}
else if ( !strcmp(s1, "BL") )
{
v2 = 0;
result = 10LL;
}
else if ( !strcmp(s1, "BZ") )
{
v2 = 0;
result = 11LL;
}
else if ( !strcmp(s1, "BNZ") )
{
v2 = 0;
result = 12LL;
}
else if ( !strcmp(s1, "CALL") )
{
v2 = 0;
result = 13LL;
}
else if ( !strcmp(s1, "RET") )
{
v2 = 0;
result = 14LL;
}
else if ( !strcmp(s1, "BSF") )
{
v2 = 0;
result = 15LL;
}
else if ( !strcmp(s1, "RSF") )
{
v2 = 0;
result = 16LL;
}
else if ( !strcmp(s1, "LDP") )
{
v2 = 0;
result = 17LL;
}
else if ( !strcmp(s1, "RDP") )
{
v2 = 0;
result = 18LL;
}
else if ( !strcmp(s1, "INC") )
{
v2 = 0;
result = 19LL;
}
else if ( !strcmp(s1, "DEC") )
{
v2 = 0;
result = 20LL;
}
else if ( !strcmp(s1, "PUSH") )
{
v2 = 0;
result = 21LL;
}
else if ( !strcmp(s1, "LOAD") )
{
v2 = 0;
result = 4294967291LL;
}
else if ( !strcmp(s1, "STORE") )
{
v2 = 0;
result = 4294967290LL;
}
else if ( !strcmp(s1, "READ") )
{
v2 = 0;
result = 29LL;
}
else if ( !strcmp(s1, "WRITE") )
{
v2 = 0;
result = 30LL;
}
else if ( !strcmp(s1, "FP") )
{
v2 = 0;
result = 4294967285LL;
}
else
{
DisplayError(1LL, "Unknown string \"%s\"\n", s1);
result = 4294967286LL;
}
}
else
{
v2 = 0;
result = 6LL;
}
}
else
{
v2 = 0;
result = 3LL;
}
}
else
{
result = 0LL;
v2 = 0;
}
}
else if ( (v6 & 0x800) != 0 )
{
v2 = v4 - 48;
v18 = fgetc(InputFile);
if ( ((*v5)[v18] & 0x800) != 0 )
{
do
{
v2 = v18 + 10 * v2 - 48;
v18 = fgetc(InputFile);
}
while ( ((*_ctype_b_loc())[v18] & 0x800) != 0 );
}
ungetc(v18, InputFile);
result = 0xFFFFFFFFLL;
}
else
{
switch ( v4 )
{
case '+':
result = 4294967289LL;
break;
case '-':
result = 4294967288LL;
break;
case '#':
result = 4294967287LL;
break;
case '[':
v19 = fgetc(InputFile);
v20 = toupper(v19);
v21 = InputFile;
if ( v20 != 83 )
goto LABEL_61;
v22 = fgetc(InputFile);
v23 = toupper(v22);
v21 = InputFile;
if ( v23 != 80 )
goto LABEL_61;
if ( fgetc(InputFile) != 93 )
{
while ( 1 )
{
v21 = InputFile;
LABEL_61:
fgetc(v21);
DisplayError(1LL, "Error, illegal token scanned\n");
}
}
result = 4294967284LL;
break;
default:
result = 2 * (unsigned int)(v4 != -1) - 4;
break;
}
}
goto LABEL_18;
}
}
v8 = fgetc(InputFile);
result = 4294967293LL;
if ( v8 != 10 )
{
result = 4294967292LL;
if ( v8 != -1 )
{
while ( 1 )
{
v9 = fgetc(InputFile);
if ( v9 == 10 )
break;
if ( v9 == -1 )
{
result = 4294967292LL;
goto LABEL_18;
}
}
LABEL_17:
result = 4294967293LL;
goto LABEL_18;
}
}
LABEL_18:
*a1 = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1)
{
int v2; // ebx
int v3; // eax
int v4; // ebp
const unsigned __int16 **v5; // r13
unsigned __int16 v6; // ax
__int64 result; // rax
int v8; // edx
int v9; // eax
int v10; // edi
int v11; // ebp
int v12; // eax
__int64 v13; // rcx
int i; // edi
FILE *v15; // r14
char *v16; // r15
int v17; // eax
int v18; // ebp
int v19; // eax
int v20; // eax
FILE *v21; // rdi
int v22; // eax
int v23; // eax
__int64 v24; // [rsp+8h] [rbp-60h]
char s1[4]; // [rsp+10h] [rbp-58h] BYREF
char v26; // [rsp+14h] [rbp-54h]

v2 = pushback;
if ( pushback )
{
pushback = 0;
*a1 = pboffset;
result = (unsigned int)pbtoken;
}
else
{
while ( 1 )
{
v3 = fgetc(InputFile);
v4 = v3;
if ( v3 == 10 )
goto LABEL_17;
if ( v3 == 59 )
break;
v5 = _ctype_b_loc();
v6 = (*v5)[v4];
if ( (v6 & 0x2000) == 0 )
{
if ( (v6 & 0x400) != 0 )
{
v10 = v4;
v11 = 1;
s1[0] = toupper(v10);
v12 = fgetc(InputFile);
v13 = 1LL;
for ( i = v12; ; i = v17 )
{
v15 = InputFile;
v16 = &s1[v13];
if ( ((*v5)[i] & 0x400) == 0 )
break;
if ( v11 > 28 )
{
v24 = v13;
v17 = fgetc(InputFile);
v13 = v24;
}
else
{
++v11;
*v16 = toupper(i);
v17 = fgetc(v15);
v13 = v11;
}
}
ungetc(i, InputFile);
*v16 = 0;
if ( *(_DWORD *)s1 != 1414283592 || v26 )
{
if ( *(_DWORD *)s1 == 4473921 )
{
v2 = 0;
result = 1LL;
}
else if ( *(_DWORD *)s1 == 4347219 )
{
v2 = 0;
result = 2LL;
}
else if ( *(_DWORD *)s1 != 1414288717 || v26 )
{
if ( *(_DWORD *)s1 == 5654852 )
{
v2 = 0;
result = 4LL;
}
else if ( *(_DWORD *)s1 == 4670798 )
{
v2 = 0;
result = 5LL;
}
else if ( *(_WORD *)s1 != 21058 || s1[2] )
{
if ( *(_DWORD *)s1 == 5916482 )
{
v2 = 0;
result = 7LL;
}
else if ( !strcmp(s1, "BG") )
{
v2 = 0;
result = 8LL;
}
else if ( !strcmp(s1, "BLZ") )
{
v2 = 0;
result = 9LL;
}
else if ( !strcmp(s1, "BL") )
{
v2 = 0;
result = 10LL;
}
else if ( !strcmp(s1, "BZ") )
{
v2 = 0;
result = 11LL;
}
else if ( !strcmp(s1, "BNZ") )
{
v2 = 0;
result = 12LL;
}
else if ( !strcmp(s1, "CALL") )
{
v2 = 0;
result = 13LL;
}
else if ( !strcmp(s1, "RET") )
{
v2 = 0;
result = 14LL;
}
else if ( !strcmp(s1, "BSF") )
{
v2 = 0;
result = 15LL;
}
else if ( !strcmp(s1, "RSF") )
{
v2 = 0;
result = 16LL;
}
else if ( !strcmp(s1, "LDP") )
{
v2 = 0;
result = 17LL;
}
else if ( !strcmp(s1, "RDP") )
{
v2 = 0;
result = 18LL;
}
else if ( !strcmp(s1, "INC") )
{
v2 = 0;
result = 19LL;
}
else if ( !strcmp(s1, "DEC") )
{
v2 = 0;
result = 20LL;
}
else if ( !strcmp(s1, "PUSH") )
{
v2 = 0;
result = 21LL;
}
else if ( !strcmp(s1, "LOAD") )
{
v2 = 0;
result = 4294967291LL;
}
else if ( !strcmp(s1, "STORE") )
{
v2 = 0;
result = 4294967290LL;
}
else if ( !strcmp(s1, "READ") )
{
v2 = 0;
result = 29LL;
}
else if ( !strcmp(s1, "WRITE") )
{
v2 = 0;
result = 30LL;
}
else if ( !strcmp(s1, "FP") )
{
v2 = 0;
result = 4294967285LL;
}
else
{
DisplayError(1LL, "Unknown string \"%s\"\n", s1);
result = 4294967286LL;
}
}
else
{
v2 = 0;
result = 6LL;
}
}
else
{
v2 = 0;
result = 3LL;
}
}
else
{
result = 0LL;
v2 = 0;
}
}
else if ( (v6 & 0x800) != 0 )
{
v2 = v4 - 48;
v18 = fgetc(InputFile);
if ( ((*v5)[v18] & 0x800) != 0 )
{
do
{
v2 = v18 + 10 * v2 - 48;
v18 = fgetc(InputFile);
}
while ( ((*_ctype_b_loc())[v18] & 0x800) != 0 );
}
ungetc(v18, InputFile);
result = 0xFFFFFFFFLL;
}
else
{
switch ( v4 )
{
case '+':
result = 4294967289LL;
break;
case '-':
result = 4294967288LL;
break;
case '#':
result = 4294967287LL;
break;
case '[':
v19 = fgetc(InputFile);
v20 = toupper(v19);
v21 = InputFile;
if ( v20 != 83 )
goto LABEL_61;
v22 = fgetc(InputFile);
v23 = toupper(v22);
v21 = InputFile;
if ( v23 != 80 )
goto LABEL_61;
if ( fgetc(InputFile) != 93 )
{
while ( 1 )
{
v21 = InputFile;
LABEL_61:
fgetc(v21);
DisplayError(1LL, "Error, illegal token scanned\n");
}
}
result = 4294967284LL;
break;
default:
result = 2 * (unsigned int)(v4 != -1) - 4;
break;
}
}
goto LABEL_18;
}
}
v8 = fgetc(InputFile);
result = 4294967293LL;
if ( v8 != 10 )
{
result = 4294967292LL;
if ( v8 != -1 )
{
while ( 1 )
{
v9 = fgetc(InputFile);
if ( v9 == 10 )
break;
if ( v9 == -1 )
{
result = 4294967292LL;
goto LABEL_18;
}
}
LABEL_17:
result = 4294967293LL;
goto LABEL_18;
}
}
LABEL_18:
*a1 = v2;
}
return result;
}

original_code:
static int GetToken( int *offset )
{
    int ch, token = 0, i = 0, state = 0, quit = 0, intvalue = 0;
    char buffer[30];
    if ( pushback ) {
        *offset = pboffset; pushback = 0; return pbtoken;
    }
    while ( !quit ) {
        ch = fgetc( InputFile );
        switch ( state ) {
            case 0 :
                if ( ch == '\n' ) {
                    quit = 1; token = -3;
                }
                else if ( ch == ';' ) state = 7;
                else if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISspace) ) state = 0;
                else if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISalpha) ) {
                    *(buffer+i) = (char)toupper( ch ); i++;
                    state = 1;
                }
                else if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISdigit) ) {
                    intvalue *= 10; intvalue += ( ch - '0' );
                    state = 2;
                }
                else if ( ch == '+' ) {
                    quit = 1; token = -7;
                }
                else if ( ch == '-' ) {
                    quit = 1; token = -8;
                }
                else if ( ch == '#' ) {
                    quit = 1; token = -9;
                }
                else if ( ch == '[' ) {
                    state = 3;
                }
                else if ( ch == (-1) ) {
                    quit = 1; token = -4;
                }
                else {
                    quit = 1; token = -2;
                }
                break;
            case 1 :
                if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISalpha) ) {
                    if ( i < 29 ) {
                        *(buffer+i) = (char)toupper( ch ); i++;
                    }
                }
                else {
                    ungetc( ch, InputFile );
                    *(buffer+i) = '\0';
                    token = -10;
                    quit = 1;
                }
                break;
            case 2 :
                if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISdigit) ) {
                    intvalue *= 10; intvalue += ( ch - '0' );
                }
                else {
                    ungetc( ch, InputFile );
                    token = -1;
                    quit = 1;
                }
                break;
            case 3 :
                ch = toupper( ch );
                if ( ch == 'S' ) state = 4; else state = 6;
                break;
            case 4 :
                ch = toupper( ch );
                if ( ch == 'P' ) state = 5; else state = 6;
                break;
            case 5 :
                if ( ch == ']' ) {
                    token = -12;
                    quit = 1;
                }
                else state = 6;
                break;
            case 6 :
                DisplayError( 1, "Error, illegal token scanned\n" );
                break;
            case 7 :
                if ( ch == '\n' ) {
                    token = -3;
                    quit = 1;
                }
                else if ( ch == (-1) ) {
                    token = -4;
                    quit = 1;
                }
                else state = 7;
                break;
            default :
                DisplayError( 1, "Error, illegal scanner state\n" );
                break;
        }
    }
    if ( token == -10 ) {
        if ( 0 == strcmp( buffer, "HALT" ) ) token = 0;
        else if ( 0 == strcmp( buffer, "ADD" ) ) token = 1;
        else if ( 0 == strcmp( buffer, "SUB" ) ) token = 2;
        else if ( 0 == strcmp( buffer, "MULT" ) ) token = 3;
        else if ( 0 == strcmp( buffer, "DIV" ) ) token = 4;
        else if ( 0 == strcmp( buffer, "NEG" ) ) token = 5;
        else if ( 0 == strcmp( buffer, "BR" ) ) token = 6;
        else if ( 0 == strcmp( buffer, "BGZ" ) ) token = 7;
        else if ( 0 == strcmp( buffer, "BG" ) ) token = 8;
        else if ( 0 == strcmp( buffer, "BLZ" ) ) token = 9;
        else if ( 0 == strcmp( buffer, "BL" ) ) token = 10;
        else if ( 0 == strcmp( buffer, "BZ" ) ) token = 11;
        else if ( 0 == strcmp( buffer, "BNZ" ) ) token = 12;
        else if ( 0 == strcmp( buffer, "CALL" ) ) token = 13;
        else if ( 0 == strcmp( buffer, "RET" ) ) token = 14;
        else if ( 0 == strcmp( buffer, "BSF" ) ) token = 15;
        else if ( 0 == strcmp( buffer, "RSF" ) ) token = 16;
        else if ( 0 == strcmp( buffer, "LDP" ) ) token = 17;
        else if ( 0 == strcmp( buffer, "RDP" ) ) token = 18;
        else if ( 0 == strcmp( buffer, "INC" ) ) token = 19;
        else if ( 0 == strcmp( buffer, "DEC" ) ) token = 20;
        else if ( 0 == strcmp( buffer, "PUSH" ) ) token = 21;
        else if ( 0 == strcmp( buffer, "LOAD" ) ) token = -5;
        else if ( 0 == strcmp( buffer, "STORE" ) ) token = -6;
        else if ( 0 == strcmp( buffer, "READ" ) ) token = 29;
        else if ( 0 == strcmp( buffer, "WRITE" ) ) token = 30;
        else if ( 0 == strcmp( buffer, "FP" ) ) token = -11;
        else DisplayError( 1, "Unknown string \"%s\"\n", buffer );
    }
    *offset = intvalue;
    return token;
}

canonical_original_code:
static int GetToken(int *offset)
{
    int ch; int token = 0; int i = 0; int state = 0; int quit = 0; int intvalue = 0;
    char buffer[30];
    if ( pushback ) {
        *offset = pboffset; pushback = 0; return pbtoken;
    }
    while ( !quit ) {
        ch = fgetc( InputFile );
        switch ( state ) {
            case 0 :
                if ( ch == '\n' ) {
                    quit = 1; token = -3;
                }
                else if ( ch == ';' ) state = 7;
                else if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISspace) ) state = 0;
                else if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISalpha) ) {
                    *(buffer+i) = (char)toupper( ch ); i++;
                    state = 1;
                }
                else if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISdigit) ) {
                    intvalue *= 10; intvalue += ( ch - '0' );
                    state = 2;
                }
                else if ( ch == '+' ) {
                    quit = 1; token = -7;
                }
                else if ( ch == '-' ) {
                    quit = 1; token = -8;
                }
                else if ( ch == '#' ) {
                    quit = 1; token = -9;
                }
                else if ( ch == '[' ) {
                    state = 3;
                }
                else if ( ch == (-1) ) {
                    quit = 1; token = -4;
                }
                else {
                    quit = 1; token = -2;
                }
                break;
            case 1 :
                if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISalpha) ) {
                    if ( i < 29 ) {
                        *(buffer+i) = (char)toupper( ch ); i++;
                    }
                }
                else {
                    ungetc( ch, InputFile );
                    *(buffer+i) = '\0';
                    token = -10;
                    quit = 1;
                }
                break;
            case 2 :
                if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISdigit) ) {
                    intvalue *= 10; intvalue += ( ch - '0' );
                }
                else {
                    ungetc( ch, InputFile );
                    token = -1;
                    quit = 1;
                }
                break;
            case 3 :
                ch = toupper( ch );
                if ( ch == 'S' ) state = 4; else state = 6;
                break;
            case 4 :
                ch = toupper( ch );
                if ( ch == 'P' ) state = 5; else state = 6;
                break;
            case 5 :
                if ( ch == ']' ) {
                    token = -12;
                    quit = 1;
                }
                else state = 6;
                break;
            case 6 :
                DisplayError( 1, "Error, illegal token scanned\n" );
                break;
            case 7 :
                if ( ch == '\n' ) {
                    token = -3;
                    quit = 1;
                }
                else if ( ch == (-1) ) {
                    token = -4;
                    quit = 1;
                }
                else state = 7;
                break;
            default :
                DisplayError( 1, "Error, illegal scanner state\n" );
                break;
        }
    }
    if ( token == -10 ) {
        if ( 0 == strcmp( buffer, "HALT" ) ) token = 0;
        else if ( 0 == strcmp( buffer, "ADD" ) ) token = 1;
        else if ( 0 == strcmp( buffer, "SUB" ) ) token = 2;
        else if ( 0 == strcmp( buffer, "MULT" ) ) token = 3;
        else if ( 0 == strcmp( buffer, "DIV" ) ) token = 4;
        else if ( 0 == strcmp( buffer, "NEG" ) ) token = 5;
        else if ( 0 == strcmp( buffer, "BR" ) ) token = 6;
        else if ( 0 == strcmp( buffer, "BGZ" ) ) token = 7;
        else if ( 0 == strcmp( buffer, "BG" ) ) token = 8;
        else if ( 0 == strcmp( buffer, "BLZ" ) ) token = 9;
        else if ( 0 == strcmp( buffer, "BL" ) ) token = 10;
        else if ( 0 == strcmp( buffer, "BZ" ) ) token = 11;
        else if ( 0 == strcmp( buffer, "BNZ" ) ) token = 12;
        else if ( 0 == strcmp( buffer, "CALL" ) ) token = 13;
        else if ( 0 == strcmp( buffer, "RET" ) ) token = 14;
        else if ( 0 == strcmp( buffer, "BSF" ) ) token = 15;
        else if ( 0 == strcmp( buffer, "RSF" ) ) token = 16;
        else if ( 0 == strcmp( buffer, "LDP" ) ) token = 17;
        else if ( 0 == strcmp( buffer, "RDP" ) ) token = 18;
        else if ( 0 == strcmp( buffer, "INC" ) ) token = 19;
        else if ( 0 == strcmp( buffer, "DEC" ) ) token = 20;
        else if ( 0 == strcmp( buffer, "PUSH" ) ) token = 21;
        else if ( 0 == strcmp( buffer, "LOAD" ) ) token = -5;
        else if ( 0 == strcmp( buffer, "STORE" ) ) token = -6;
        else if ( 0 == strcmp( buffer, "READ" ) ) token = 29;
        else if ( 0 == strcmp( buffer, "WRITE" ) ) token = 30;
        else if ( 0 == strcmp( buffer, "FP" ) ) token = -11;
        else DisplayError( 1, "Unknown string \"%s\"\n", buffer );
    }
    *offset = intvalue;
    return token;
}

variable_types:
offset
int *

variable_types: ch int

variable_types: i int

variable_types: state int

variable_types: quit int

variable_types: intvalue int

variable_types:
buffer
char [30]


ReadAddress

decompiled_code:
__int64 __fastcall ReadAddress(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)GetToken((int *)v2) != -1 )
return DisplayError(1LL, "Positve integer expected as address\n");
result = v2[0];
if ( v2[0] > 0x3FF )
return DisplayError(1LL, "Target address out of range in branch or call\n");
*(_DWORD *)(a1 + 4) = v2[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)func1((int *)v2) != -1 )
return DisplayError(1LL, "Positve integer expected as address\n");
result = v2[0];
if ( v2[0] > 0x3FF )
return DisplayError(1LL, "Target address out of range in branch or call\n");
*(_DWORD *)(a1 + 4) = v2[0];
return result;
}

original_code:
static void ReadAddress( INSTRUCTION *instruction )
{
    int token, address;
    token = GetToken( &address );
    if ( token != -1 ) {
        DisplayError( 1, "Positve integer expected as address\n" );
    }
    else if ( address < 0 || address >= 1024 ) {
        DisplayError( 1, "Target address out of range in branch or call\n" );
    }
    else instruction->offset = address;
}

canonical_original_code:
static void ReadAddress(struct INSTRUCTION *instruction)
{
    int token; int address;
    token = GetToken( &address );
    if ( token != -1 ) {
        DisplayError( 1, "Positve integer expected as address\n" );
    }
    else if ( address < 0 || address >= 1024 ) {
        DisplayError( 1, "Target address out of range in branch or call\n" );
    }
    else instruction->offset = address;
}

variable_types: struct INSTRUCTION { int opcode; int offset; } *

variable_types: address int


ReadNatural

decompiled_code:
__int64 __fastcall ReadNatural(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)GetToken((int *)v2) != -1 )
return DisplayError(1LL, "Positve integer expected as argument of INC or DEC\n");
result = v2[0];
if ( v2[0] > 0x3FF )
return DisplayError(1LL, "Argument of INC or DEC out of range\n");
*(_DWORD *)(a1 + 4) = v2[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)func1((int *)v2) != -1 )
return DisplayError(1LL, "Positve integer expected as argument of INC or DEC\n");
result = v2[0];
if ( v2[0] > 0x3FF )
return DisplayError(1LL, "Argument of INC or DEC out of range\n");
*(_DWORD *)(a1 + 4) = v2[0];
return result;
}

original_code:
static void ReadNatural( INSTRUCTION *instruction )
{
    int token, natural;
    token = GetToken( &natural );
    if ( token != -1 ) {
        DisplayError( 1, "Positve integer expected as argument of INC or DEC\n" );
    }
    else if ( natural < 0 || natural >= 1024 ) {
        DisplayError( 1, "Argument of INC or DEC out of range\n" );
    }
    else instruction->offset = natural;
}

canonical_original_code:
static void ReadNatural(struct INSTRUCTION *instruction)
{
    int token; int natural;
    token = GetToken( &natural );
    if ( token != -1 ) {
        DisplayError( 1, "Positve integer expected as argument of INC or DEC\n" );
    }
    else if ( natural < 0 || natural >= 1024 ) {
        DisplayError( 1, "Argument of INC or DEC out of range\n" );
    }
    else instruction->offset = natural;
}

variable_types: natural int

user_defined_types: struct INSTRUCTION { int opcode; int offset; }