anonymousfunction

decompiled_code:
__int64 __fastcall anonymousfunction(int a1, __int64 a2)
{
__int64 v2; // r8
__int64 v3; // rax
__int64 result; // rax
char v5[296]; // [rsp+0h] [rbp-128h] BYREF

do
{
do
{
v2 = (unsigned int)count_0++;
sprintf(v5, "%s%s%d", parsefunctionname, "_nn_", v2);
v3 = getdef(v5);
}
while ( *(_QWORD *)v3 );
}
while ( *(_QWORD *)(v3 + 8) );
*(_DWORD *)(v3 + 24) = a1;
*(_QWORD *)(v3 + 8) = a2;
*(_BYTE *)(v3 + 72) = 14;
result = *(_QWORD *)(v3 + 64);
*(_BYTE *)(result + 20) = 14;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(int a1, __int64 a2)
{
__int64 v2; // r8
__int64 v3; // rax
__int64 result; // rax
char v5[296]; // [rsp+0h] [rbp-128h] BYREF

do
{
do
{
v2 = (unsigned int)count_0++;
sprintf(v5, "%s%s%d", parsefunctionname, "_nn_", v2);
v3 = func3(v5);
}
while ( *(_QWORD *)v3 );
}
while ( *(_QWORD *)(v3 + 8) );
*(_DWORD *)(v3 + 24) = a1;
*(_QWORD *)(v3 + 8) = a2;
*(_BYTE *)(v3 + 72) = 14;
result = *(_QWORD *)(v3 + 64);
*(_BYTE *)(result + 20) = 14;
return result;
}

original_code:
Cell *anonymousfunction(int argcount, Cell *def)
{
  static int count = 0;
  char funname[256];
  FuncDef *fun;
  do
  {
    sprintf(funname, "%s%s%d", parsefunctionname, "_nn_", count++);
    fun = getdef(funname);
  }
  while(fun->code || fun->def);
  fun->argcount = argcount;
  fun->def = def;
  fun->template->tag = fun->tag = FUNC;
  return fun->template;
}

canonical_original_code:
struct CELL *anonymousfunction(int argcount, struct CELL *def)
{
  static int count = 0;
  char funname[256];
  struct FuncDef *fun;
  do
  {
    sprintf(funname, "%s%s%d", parsefunctionname, "_nn_", count++);
    fun = getdef(funname);
  }
  while(fun->code || fun->def);
  fun->argcount = argcount;
  fun->def = def;
  fun->template->tag = fun->tag = FUNC;
  return fun->template;
}

variable_types:
def
struct CELL *

variable_types:
funname
char [256]


inserttypeexpr

decompiled_code:
__int64 __fastcall inserttypeexpr(char *a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // er8

v2 = getdef(a1);
v3 = 0;
if ( !*(_QWORD *)(v2 + 40) )
{
*(_QWORD *)(v2 + 40) = a2;
v3 = 1;
}
return v3;
}

original_code:
bool inserttypeexpr(char name[], Cell *typeexpr)
{
  FuncDef *fun = getdef(name);
  if(fun->typeexpr) return 0;
  fun->typeexpr = typeexpr;
  return 1;
}

canonical_original_code:
int inserttypeexpr(char name[], struct CELL *typeexpr)
{
  struct FuncDef *fun = getdef(name);
  if(fun->typeexpr) return 0;
  fun->typeexpr = typeexpr;
  return 1;
}

variable_types:
name
char []

variable_types: struct FuncDef { void (*code)(); struct CELL { struct CELL *left; int value; unsigned char tag; } *def; char *name; int argcount; int sysfunc; int typechanged; int generic; struct CELL *typeexpr; struct CELL *abstype; int prio; enum Assoc { Left=0, Right=1 } assoc; struct CELL *template; unsigned char tag; } *

return_type: int

user_defined_types: struct FuncDef { void (*code)(); struct CELL *def; char *name; int argcount; int sysfunc; int typechanged; int generic; struct CELL *typeexpr; struct CELL *abstype; int prio; enum Assoc assoc; struct CELL *template; unsigned char tag; }


inserttypestring

decompiled_code:
__int64 __fastcall inserttypestring(char *a1, __int64 a2)
{
parsetypeexpr(a2);
return inserttypeexpr(a1, *(_QWORD *)(stack + 8LL * --stackpointer));
}

canonical_decompiled_code:
__int64 __fastcall func19(char *a1, __int64 a2)
{
parsetypeexpr(a2);
return func18(a1, *(_QWORD *)(stack + 8LL * --stackpointer));
}

original_code:
bool inserttypestring(char name[], char typestring[])
{
  parsetypeexpr(typestring);
  return inserttypeexpr(name, stack[--stackpointer]);
}

canonical_original_code:
int inserttypestring(char name[], char typestring[])
{
  parsetypeexpr(typestring);
  return inserttypeexpr(name, stack[--stackpointer]);
}

variable_types:
typestring
char []


insertabstype

decompiled_code:
__int64 __fastcall insertabstype(char *a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // er8

v2 = getdef(a1);
v3 = 0;
if ( !*(_QWORD *)(v2 + 48) )
{
*(_QWORD *)(v2 + 48) = a2;
v3 = 1;
}
return v3;
}

original_code:
bool insertabstype(char name[], Cell *abstype)
{
  FuncDef *fun = getdef(name);
  if(fun->abstype) return 0;
  fun->abstype = abstype;
  return 1;
}

canonical_original_code:
int insertabstype(char name[], struct CELL *abstype)
{
  struct FuncDef *fun = getdef(name);
  if(fun->abstype) return 0;
  fun->abstype = abstype;
  return 1;
}

variable_types: struct CELL { struct CELL *left; int value; unsigned char tag; } *


storeMessage

decompiled_code:
void __fastcall storeMessage(const char *a1)
{
int v1; // ebx
char *v2; // rax

v1 = messageStoreIndex[0];
if ( messageStoreIndex[0] <= 9999 )
{
if ( a1 )
{
v2 = strdup(a1);
messageStoreIndex[0] = v1 + 1;
stdoutMessages[v1] = v2;
}
}
}

canonical_decompiled_code:
void __fastcall func1(const char *a1)
{
int v1; // ebx
char *v2; // rax

v1 = messageStoreIndex[0];
if ( messageStoreIndex[0] <= 9999 )
{
if ( a1 )
{
v2 = strdup(a1);
messageStoreIndex[0] = v1 + 1;
stdoutMessages[v1] = v2;
}
}
}

original_code:
void storeMessage(char out[])
{
 if(messageStoreIndex < 10000 & out != ((void *)0))
 {
  stdoutMessages[messageStoreIndex] = strdup(out);
  messageStoreIndex++;
 }
}

variable_types:
out
char []

return_type: void


getMessages

decompiled_code:
_QWORD *getMessages()
{
_QWORD *result; // rax
__int64 v1; // rdx

result = 0LL;
v1 = messageStoreIndex[0];
if ( messageStoreIndex[0] > 0 )
{
result = stdoutMessages;
messageStoreIndex[0] = 0;
stdoutMessages[v1] = &LC0;
}
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *result; // rax
__int64 v1; // rdx

result = 0LL;
v1 = messageStoreIndex[0];
if ( messageStoreIndex[0] > 0 )
{
result = stdoutMessages;
messageStoreIndex[0] = 0;
stdoutMessages[v1] = &LC0;
}
return result;
}

original_code:
char** getMessages()
{
 if(messageStoreIndex > 0)
 {
  stdoutMessages[messageStoreIndex] = "\n\n\n";
  messageStoreIndex = 0;
  return stdoutMessages;
 }
 return 0;
}

canonical_original_code:
char **getMessages()
{
 if(messageStoreIndex > 0)
 {
  stdoutMessages[messageStoreIndex] = "\n\n\n";
  messageStoreIndex = 0;
  return stdoutMessages;
 }
 return 0;
}

return_type: char **


SetOutputCallback

decompiled_code:
__int64 __fastcall SetOutputCallback(__int64 a1)
{
writeStringCallback = a1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
writeStringCallback = a1;
return 1LL;
}

original_code:
bool SetOutputCallback(long pointerToWriteStringCallbackMethod)
{
 writeStringCallback = (WriteStringCallback)pointerToWriteStringCallbackMethod;
 return 1;
}

canonical_original_code:
int SetOutputCallback(long pointerToWriteStringCallbackMethod)
{
 writeStringCallback = (void (*)(char output[]))pointerToWriteStringCallbackMethod;
 return 1;
}

variable_types: pointerToWriteStringCallbackMethod long


getstring

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

WriteString();
result = fgets(a2, 256, stdin);
if ( !result )
exit(0);
return result;
}

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

WriteString();
result = fgets(a2, 256, stdin);
if ( !result )
exit(0);
return result;
}

original_code:
static void getstring(char prompt[], char string[])
{
    WriteString(prompt);
    if(fgets(string, 256, stdin) == ((void *)0)) exit(0);
}

variable_types:
prompt
char []

variable_types:
string
char []


amaproc

original_code:
static void amaproc(char path[])
{
  InitOptions(0, path);
  CreateInterpreter();
  for(;;)
  {
    char expr[256] = "";
    getstring(">> ", expr);
    WriteString("\n<\n");
    Interpret(expr);
    WriteString("\n>\n");
  }
}

variable_types:
path
char []

variable_types:
expr
char [256]


amaobj

decompiled_code:
char __fastcall amaobj(__int64 a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebp
int v4; // eax
int v5; // er13
bool v6; // cf
bool v7; // zf
bool v8; // cf
bool v9; // zf
const char *v10; // rax
__int64 v11; // rcx
const char *v12; // rdi
const char *v13; // rsi
char v14; // dl
const char *v15; // rsi
__int64 v16; // rcx
const char *v17; // rdi
char *v18; // r15
char *v19; // r13
__int64 v20; // rsi
int v22; // [rsp+4h] [rbp-A44h]
char v23[256]; // [rsp+10h] [rbp-A38h] BYREF
char v24[256]; // [rsp+110h] [rbp-938h] BYREF
const char *v25; // [rsp+210h] [rbp-838h] BYREF
__int64 v26; // [rsp+218h] [rbp-830h]
char v27[2088]; // [rsp+220h] [rbp-828h] BYREF

InitOptions(0LL, a1);
CreateInterpreter();
v2 = Load(a2);
if ( v2 )
{
v2 = InitRemote();
if ( v2 )
{
v3 = -1;
getstring((__int64)&LC1, v23);
v22 = 0;
while ( 1 )
{
WriteString();
v4 = FindWords_constprop_0(v23, (__int64)&v25);
v5 = v4;
v6 = (unsigned int)v4 < 2;
v7 = v4 == 2;
if ( v4 == 2 )
break;
v8 = v4 == 0;
v9 = v4 == 1;
if ( v4 > 1 )
{
v10 = v25;
LABEL_18:
v15 = v10;
v16 = 5LL;
v17 = "call";
do
{
if ( !v16 )
break;
v8 = *v15 < (unsigned int)*v17;
v9 = *v15++ == *v17++;
--v16;
}
while ( v9 );
if ( (!v8 && !v9) != v8 || (v3 & 0x80000000) != 0 )
goto LABEL_23;
starttiming(v17, v15);
if ( v5 > 2 )
{
v18 = v27;
v19 = &v27[8 * (v5 - 3) + 8];
do
{
v20 = *(_QWORD *)v18;
v18 += 8;
PutRemote(v3, v20);
}
while ( v18 != v19 );
}
CallRemote(v3, v26);
WriteString();
while ( (unsigned int)GetRemote(v3, v24, 256LL) )
{
WriteString();
WriteString();
}
WriteString();
stoptiming(">\n");
goto LABEL_10;
}
if ( v4 != 1 )
goto LABEL_23;
if ( strcmp(v25, "echo") )
{
if ( !strcmp(v25, "time") )
{
timing = timing == 0;
goto LABEL_10;
}
v7 = strcmp(v25, "exit") == 0;
LOBYTE(v2) = !v7;
if ( v7 )
return v2;
LABEL_23:
WriteString();
goto LABEL_10;
}
v22 ^= 1u;
LABEL_10:
WriteString();
getstring((__int64)&LC1, v23);
if ( v22 )
WriteString();
}
v10 = v25;
v11 = 7LL;
v12 = "object";
v13 = v25;
do
{
if ( !v11 )
break;
v6 = *v13 < (unsigned int)*v12;
v7 = *v13++ == *v12++;
--v11;
}
while ( v7 );
v14 = (!v6 && !v7) - v6;
v8 = 0;
v9 = v14 == 0;
if ( !v14 )
{
DropRemote(v3, v13);
v3 = CreateRemote(v26);
goto LABEL_10;
}
goto LABEL_18;
}
}
return v2;
}

canonical_decompiled_code:
char __fastcall func6(__int64 a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebp
int v4; // eax
int v5; // er13
bool v6; // cf
bool v7; // zf
bool v8; // cf
bool v9; // zf
const char *v10; // rax
__int64 v11; // rcx
const char *v12; // rdi
const char *v13; // rsi
char v14; // dl
const char *v15; // rsi
__int64 v16; // rcx
const char *v17; // rdi
char *v18; // r15
char *v19; // r13
__int64 v20; // rsi
int v22; // [rsp+4h] [rbp-A44h]
char v23[256]; // [rsp+10h] [rbp-A38h] BYREF
char v24[256]; // [rsp+110h] [rbp-938h] BYREF
const char *v25; // [rsp+210h] [rbp-838h] BYREF
__int64 v26; // [rsp+218h] [rbp-830h]
char v27[2088]; // [rsp+220h] [rbp-828h] BYREF

InitOptions(0LL, a1);
CreateInterpreter();
v2 = Load(a2);
if ( v2 )
{
v2 = InitRemote();
if ( v2 )
{
v3 = -1;
func4((__int64)&LC1, v23);
v22 = 0;
while ( 1 )
{
WriteString();
v4 = func0(v23, (__int64)&v25);
v5 = v4;
v6 = (unsigned int)v4 < 2;
v7 = v4 == 2;
if ( v4 == 2 )
break;
v8 = v4 == 0;
v9 = v4 == 1;
if ( v4 > 1 )
{
v10 = v25;
LABEL_18:
v15 = v10;
v16 = 5LL;
v17 = "call";
do
{
if ( !v16 )
break;
v8 = *v15 < (unsigned int)*v17;
v9 = *v15++ == *v17++;
--v16;
}
while ( v9 );
if ( (!v8 && !v9) != v8 || (v3 & 0x80000000) != 0 )
goto LABEL_23;
starttiming(v17, v15);
if ( v5 > 2 )
{
v18 = v27;
v19 = &v27[8 * (v5 - 3) + 8];
do
{
v20 = *(_QWORD *)v18;
v18 += 8;
PutRemote(v3, v20);
}
while ( v18 != v19 );
}
CallRemote(v3, v26);
WriteString();
while ( (unsigned int)GetRemote(v3, v24, 256LL) )
{
WriteString();
WriteString();
}
WriteString();
stoptiming(">\n");
goto LABEL_10;
}
if ( v4 != 1 )
goto LABEL_23;
if ( strcmp(v25, "echo") )
{
if ( !strcmp(v25, "time") )
{
timing = timing == 0;
goto LABEL_10;
}
v7 = strcmp(v25, "exit") == 0;
LOBYTE(v2) = !v7;
if ( v7 )
return v2;
LABEL_23:
WriteString();
goto LABEL_10;
}
v22 ^= 1u;
LABEL_10:
WriteString();
func4((__int64)&LC1, v23);
if ( v22 )
WriteString();
}
v10 = v25;
v11 = 7LL;
v12 = "object";
v13 = v25;
do
{
if ( !v11 )
break;
v6 = *v13 < (unsigned int)*v12;
v7 = *v13++ == *v12++;
--v11;
}
while ( v7 );
v14 = (!v6 && !v7) - v6;
v8 = 0;
v9 = v14 == 0;
if ( !v14 )
{
DropRemote(v3, v13);
v3 = CreateRemote(v26);
goto LABEL_10;
}
goto LABEL_18;
}
}
return v2;
}

original_code:
static void amaobj(char path[], char filename[])
{
  char command[256], s[256], *words[256];
  int k, handle = -1, count;
  bool echo = 0;
  InitOptions(0, path);
  CreateInterpreter();
  if(!Load(filename) || !InitRemote()) return;
  for(;;)
  {
    getstring(">> ", command);
    if(echo) WriteString(command);
    WriteString("\n");
    count = FindWords(command, words, 256);
    if(count == 2 && strcmp(words[0], "object") == 0)
    {
      DropRemote(handle);
      handle = CreateRemote(words[1]);
    }
    else if(count >= 2 && strcmp(words[0], "call") == 0)
    {
      if(handle < 0)
        WriteString("No object selected");
      else
      {
        starttiming();
        for(k=2; k < count; k++) PutRemote(handle, words[k]);
        CallRemote(handle, words[1]);
        WriteString("<\n");
        while(GetRemote(handle, s, 256))
        {
          WriteString(s);
          WriteString("\n");
        }
        WriteString(">\n");
        stoptiming();
      }
    }
    else if(count == 1 && strcmp(words[0], "echo") == 0)
      echo = !echo;
    else if(count == 1 && strcmp(words[0], "time") == 0)
      timing = !timing;
    else if(count == 1 && strcmp(words[0], "exit") == 0)
      break;
    else
      WriteString("???\n");
    WriteString("\n");
  }
}

canonical_original_code:
static void amaobj(char path[], char filename[])
{
  char command[256]; char s[256]; char *words[256];
  int k; int handle = -1; int count;
  int echo = 0;
  InitOptions(0, path);
  CreateInterpreter();
  if(!Load(filename) || !InitRemote()) return;
  for(;;)
  {
    getstring(">> ", command);
    if(echo) WriteString(command);
    WriteString("\n");
    count = FindWords(command, words, 256);
    if(count == 2 && strcmp(words[0], "object") == 0)
    {
      DropRemote(handle);
      handle = CreateRemote(words[1]);
    }
    else if(count >= 2 && strcmp(words[0], "call") == 0)
    {
      if(handle < 0)
        WriteString("No object selected");
      else
      {
        starttiming();
        for(k=2; k < count; k++) PutRemote(handle, words[k]);
        CallRemote(handle, words[1]);
        WriteString("<\n");
        while(GetRemote(handle, s, 256))
        {
          WriteString(s);
          WriteString("\n");
        }
        WriteString(">\n");
        stoptiming();
      }
    }
    else if(count == 1 && strcmp(words[0], "echo") == 0)
      echo = !echo;
    else if(count == 1 && strcmp(words[0], "time") == 0)
      timing = !timing;
    else if(count == 1 && strcmp(words[0], "exit") == 0)
      break;
    else
      WriteString("???\n");
    WriteString("\n");
  }
}

variable_types:
filename
char []

variable_types:
command
char [256]

variable_types:
s
char [256]

variable_types:
words
char *[256]

variable_types: k int

variable_types: handle int

variable_types: count int

variable_types: echo int


CheckIO

decompiled_code:
void CheckIO()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void CheckIO(void)
{
}

canonical_original_code:
void CheckIO()
{
}


GraphDisplay

decompiled_code:
void GraphDisplay()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void GraphDisplay(char string[])
{
}

canonical_original_code:
void GraphDisplay(char string[])
{
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
const char *v4; // r12
__int64 v5; // rax
int result; // eax
__int128 v7[18]; // [rsp+0h] [rbp-128h] BYREF

v3 = *argv;
if ( argc <= 1 )
{
InitOptions(1LL, *argv);
CreateInterpreter();
goto LABEL_7;
}
v4 = argv[1];
if ( !strcmp(v4, "-proc") )
amaproc((__int64)v3);
if ( argc == 2 || strcmp(v4, "-obj") )
{
InitOptions(1LL, v3);
CreateInterpreter();
if ( !(unsigned int)Load(argv[1]) )
WriteString();
while ( 1 )
{
LABEL_7:
v7[0] = 0LL;
v7[1] = 0LL;
v7[2] = 0LL;
v7[3] = 0LL;
v7[4] = 0LL;
v7[5] = 0LL;
v7[6] = 0LL;
v7[7] = 0LL;
v7[8] = 0LL;
v7[9] = 0LL;
v7[10] = 0LL;
v7[11] = 0LL;
v7[12] = 0LL;
v7[13] = 0LL;
v7[14] = 0LL;
v7[15] = 0LL;
v5 = GetOption("ConPrompt");
getstring(v5, (char *)v7);
Interpret(v7);
}
}
LOBYTE(result) = amaobj((__int64)v3, (__int64)argv[2]);
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
const char *v4; // r12
__int64 v5; // rax
int result; // eax
__int128 v7[18]; // [rsp+0h] [rbp-128h] BYREF

v3 = *argv;
if ( argc <= 1 )
{
InitOptions(1LL, *argv);
CreateInterpreter();
goto LABEL_7;
}
v4 = argv[1];
if ( !strcmp(v4, "-proc") )
func5((__int64)v3);
if ( argc == 2 || strcmp(v4, "-obj") )
{
InitOptions(1LL, v3);
CreateInterpreter();
if ( !(unsigned int)Load(argv[1]) )
WriteString();
while ( 1 )
{
LABEL_7:
v7[0] = 0LL;
v7[1] = 0LL;
v7[2] = 0LL;
v7[3] = 0LL;
v7[4] = 0LL;
v7[5] = 0LL;
v7[6] = 0LL;
v7[7] = 0LL;
v7[8] = 0LL;
v7[9] = 0LL;
v7[10] = 0LL;
v7[11] = 0LL;
v7[12] = 0LL;
v7[13] = 0LL;
v7[14] = 0LL;
v7[15] = 0LL;
v5 = GetOption("ConPrompt");
func4(v5, (char *)v7);
Interpret(v7);
}
}
LOBYTE(result) = func6((__int64)v3, (__int64)argv[2]);
return result;
}

original_code:
void main(int argc, char *argv[])
{
  initgetstring();
  if(argc > 1 && strcmp(argv[1], "-proc") == 0)
  {
    amaproc(argv[0]);
    return;
  }
  if(argc > 2 && strcmp(argv[1], "-obj") == 0)
  {
    amaobj(argv[0], argv[2]);
    return;
  }
  InitOptions(1, argv[0]);
  CreateInterpreter();
  if(argc > 1 && !Load(argv[1])) WriteString("\n");
  for(;;)
  {
    char expr[256] = "";
    getstring(GetOption("ConPrompt"), expr);
    Interpret(expr);
  }
}

variable_types: argc int

variable_types:
argv
char *[]


createstack

decompiled_code:
_DWORD *createstack()
{
_DWORD *result; // rax

if ( stack || (stack = malloc(0x27100uLL)) != 0LL )
{
result = &stackpointer;
stackpointer = 0;
}
else
{
systemerror(4LL);
result = &stackpointer;
stackpointer = 0;
}
return result;
}

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

if ( stack || (stack = malloc(0x27100uLL)) != 0LL )
{
result = &stackpointer;
stackpointer = 0;
}
else
{
systemerror(4LL);
result = &stackpointer;
stackpointer = 0;
}
return result;
}

original_code:
void createstack(void)
{
  if(stack == ((void *)0)) stack = malloc(20000 * sizeof(Cell *));
  if(stack == ((void *)0)) systemerror(4);
  stackpointer = 0;
}

canonical_original_code:
void createstack()
{
  if(stack == ((void *)0)) stack = malloc(20000 * sizeof(struct CELL *));
  if(stack == ((void *)0)) systemerror(4);
  stackpointer = 0;
}

user_defined_types: struct CELL { struct CELL *left; int value; unsigned char tag; }


forallstack

decompiled_code:
__int64 __fastcall forallstack(__int64 (__fastcall *a1)(__int64))
{
__int64 result; // rax
__int64 v3; // rbx
unsigned __int64 v4; // r13
__int64 v5; // rdi

result = (int)stackpointer;
if ( (int)stackpointer > 0 )
{
v3 = 8LL * (stackpointer - 1);
v4 = 8 * ((int)stackpointer - (unsigned __int64)(unsigned int)(stackpointer - 1)) - 16;
do
{
v5 = *(_QWORD *)(stack + v3);
v3 -= 8LL;
result = a1(v5);
}
while ( v3 != v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 (__fastcall *a1)(__int64))
{
__int64 result; // rax
__int64 v3; // rbx
unsigned __int64 v4; // r13
__int64 v5; // rdi

result = (int)stackpointer;
if ( (int)stackpointer > 0 )
{
v3 = 8LL * (stackpointer - 1);
v4 = 8 * ((int)stackpointer - (unsigned __int64)(unsigned int)(stackpointer - 1)) - 16;
do
{
v5 = *(_QWORD *)(stack + v3);
v3 -= 8LL;
result = a1(v5);
}
while ( v3 != v4 );
}
return result;
}

original_code:
void forallstack(void (*fun)(Cell *))
{
  int sp = stackpointer;
  while(sp-- > 0) (fun)(stack[sp]);
}

canonical_original_code:
void forallstack(void (*fun)(struct CELL *))
{
  int sp = stackpointer;
  while(sp-- > 0) (fun)(stack[sp]);
}

variable_types: void (*)(struct CELL { struct CELL *left; int value; unsigned char tag; } *)

variable_types: sp int


squeeze

decompiled_code:
__int64 __fastcall squeeze(int a1, int a2)
{
int v3; // esi
int v4; // edx
int v5; // ecx
int v6; // eax
__int64 result; // rax
__int64 v8; // rsi
__int64 v9; // rdi

v3 = stackpointer;
v4 = stackpointer - a2;
v5 = stackpointer - a1;
v6 = stackpointer - a2;
stackpointer -= a1;
result = (unsigned int)(v6 - a1);
if ( v3 > v4 )
{
result = (int)result;
v8 = stack;
v9 = stack + 8 * (v4 - (__int64)(int)result);
do
{
*(_QWORD *)(v8 + 8 * result) = *(_QWORD *)(v9 + 8 * result);
++result;
}
while ( v5 > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
int v3; // esi
int v4; // edx
int v5; // ecx
int v6; // eax
__int64 result; // rax
__int64 v8; // rsi
__int64 v9; // rdi

v3 = stackpointer;
v4 = stackpointer - a2;
v5 = stackpointer - a1;
v6 = stackpointer - a2;
stackpointer -= a1;
result = (unsigned int)(v6 - a1);
if ( v3 > v4 )
{
result = (int)result;
v8 = stack;
v9 = stack + 8 * (v4 - (__int64)(int)result);
do
{
*(_QWORD *)(v8 + 8 * result) = *(_QWORD *)(v9 + 8 * result);
++result;
}
while ( v5 > (int)result );
}
return result;
}

original_code:
void squeeze(int between, int count)
{
  int k = stackpointer - count, l = k - between;
  stackpointer -= between;
  while(l < stackpointer)
    stack[l++] = stack[k++];
}

canonical_original_code:
void squeeze(int between, int count)
{
  int k = stackpointer - count; int l = k - between;
  stackpointer -= between;
  while(l < stackpointer)
    stack[l++] = stack[k++];
}

variable_types: between int

variable_types: l int


makeAPPLICATION

decompiled_code:
__int64 __fastcall makeAPPLICATION(int a1, int a2)
{
int v3; // ebx
_QWORD *v4; // rax
__int64 v5; // rcx
int v6; // edx
__int64 v7; // rsi
_QWORD *v8; // rdi
__int64 result; // rax
__int64 *v10; // r13
__int64 v11; // rax
__int64 v12; // rax
int v13; // edi
__int64 v14; // rsi
__int64 *v15; // r8

if ( a2 )
{
if ( a2 == 1 )
{
v12 = newcell(24LL);
v5 = stack;
v13 = stackpointer;
v14 = 8LL * (stackpointer - 1);
v15 = (__int64 *)(stack + v14);
v7 = v14 + 8;
*(_QWORD *)(v12 + 8) = *v15;
*v15 = v12;
stackpointer = v13;
}
else
{
v3 = a2 - 1;
if ( a2 <= 1 )
{
v5 = stack;
v7 = 8LL * (int)stackpointer;
}
else
{
do
{
v4 = (_QWORD *)newcell(24LL);
v5 = stack;
v6 = stackpointer - 1;
v7 = 8LL * (stackpointer - 1);
v4[1] = *(_QWORD *)(stack + v7);
v8 = (_QWORD *)(v5 + v7 - 8);
*v4 = *v8;
*v8 = v4;
stackpointer = v6;
--v3;
}
while ( v3 );
}
}
}
else
{
v10 = (__int64 *)(stack + 8LL * (int)stackpointer);
v11 = newcell(24LL);
v5 = stack;
*v10 = v11;
v7 = 8LL * (int)++stackpointer;
}
result = *(_QWORD *)(v5 + v7 - 8);
*(_DWORD *)(result + 16) = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2)
{
int v3; // ebx
_QWORD *v4; // rax
__int64 v5; // rcx
int v6; // edx
__int64 v7; // rsi
_QWORD *v8; // rdi
__int64 result; // rax
__int64 *v10; // r13
__int64 v11; // rax
__int64 v12; // rax
int v13; // edi
__int64 v14; // rsi
__int64 *v15; // r8

if ( a2 )
{
if ( a2 == 1 )
{
v12 = newcell(24LL);
v5 = stack;
v13 = stackpointer;
v14 = 8LL * (stackpointer - 1);
v15 = (__int64 *)(stack + v14);
v7 = v14 + 8;
*(_QWORD *)(v12 + 8) = *v15;
*v15 = v12;
stackpointer = v13;
}
else
{
v3 = a2 - 1;
if ( a2 <= 1 )
{
v5 = stack;
v7 = 8LL * (int)stackpointer;
}
else
{
do
{
v4 = (_QWORD *)newcell(24LL);
v5 = stack;
v6 = stackpointer - 1;
v7 = 8LL * (stackpointer - 1);
v4[1] = *(_QWORD *)(stack + v7);
v8 = (_QWORD *)(v5 + v7 - 8);
*v4 = *v8;
*v8 = v4;
stackpointer = v6;
--v3;
}
while ( v3 );
}
}
}
else
{
v10 = (__int64 *)(stack + 8LL * (int)stackpointer);
v11 = newcell(24LL);
v5 = stack;
*v10 = v11;
v7 = 8LL * (int)++stackpointer;
}
result = *(_QWORD *)(v5 + v7 - 8);
*(_DWORD *)(result + 16) = a1;
return result;
}

original_code:
void makeAPPLICATION(int value, int n)
{
  Cell *temp;
  if(n == 0)
    ( stack[stackpointer] = (newcell(APPLICATION)), stackpointer++ );
  else if(n == 1)
  {
    temp = newcell(APPLICATION);
    temp->right = stack[--stackpointer];
    ( stack[stackpointer] = (temp), stackpointer++ );
  }
  else
    while(n-- > 1)
    {
      temp = newcell(APPLICATION);
      temp->right = stack[--stackpointer];
      temp->left = stack[--stackpointer];
      ( stack[stackpointer] = (temp), stackpointer++ );
    }
  stack[stackpointer-1]->value = value;
}

canonical_original_code:
void makeAPPLICATION(int value, int n)
{
  struct CELL *temp;
  if(n == 0)
    ( stack[stackpointer] = (newcell(APPLICATION)), stackpointer++ );
  else if(n == 1)
  {
    temp = newcell(APPLICATION);
    temp->right = stack[--stackpointer];
    ( stack[stackpointer] = (temp), stackpointer++ );
  }
  else
    while(n-- > 1)
    {
      temp = newcell(APPLICATION);
      temp->right = stack[--stackpointer];
      temp->left = stack[--stackpointer];
      ( stack[stackpointer] = (temp), stackpointer++ );
    }
  stack[stackpointer-1]->value = value;
}

variable_types: value int

variable_types: n int

variable_types: struct CELL { struct CELL *left; int value; unsigned char tag; } *


decompiled_code:
__int64 make_IF()
{
_QWORD *v0; // rbx
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rsi
__int64 result; // rax
__int64 v5; // r8
_QWORD *v6; // rdx

v0 = (_QWORD *)newcell(23LL);
v1 = newcell(23LL);
v0[1] = v1;
v2 = v1;
v3 = stack;
result = (unsigned int)(stackpointer - 2);
v5 = 8LL * (stackpointer - 1);
*(_QWORD *)(v2 + 8) = *(_QWORD *)(stack + v5);
*(_QWORD *)v0[1] = *(_QWORD *)(v3 + v5 - 8);
v6 = (_QWORD *)(v3 + v5 - 16);
*v0 = *v6;
*v6 = v0;
stackpointer = result;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
_QWORD *v0; // rbx
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rsi
__int64 result; // rax
__int64 v5; // r8
_QWORD *v6; // rdx

v0 = (_QWORD *)newcell(23LL);
v1 = newcell(23LL);
v0[1] = v1;
v2 = v1;
v3 = stack;
result = (unsigned int)(stackpointer - 2);
v5 = 8LL * (stackpointer - 1);
*(_QWORD *)(v2 + 8) = *(_QWORD *)(stack + v5);
*(_QWORD *)v0[1] = *(_QWORD *)(v3 + v5 - 8);
v6 = (_QWORD *)(v3 + v5 - 16);
*v0 = *v6;
*v6 = v0;
stackpointer = result;
return result;
}

original_code:
void make_IF(void)
{
  Cell *temp = newcell(_IF);
  temp->right = newcell(_IF);
  temp->right->right = stack[--stackpointer];
  temp->right->left = stack[--stackpointer];
  temp->left = stack[--stackpointer];
  ( stack[stackpointer] = (temp), stackpointer++ );
}

canonical_original_code:
void make_IF()
{
  struct CELL *temp = newcell(_IF);
  temp->right = newcell(_IF);
  temp->right->right = stack[--stackpointer];
  temp->right->left = stack[--stackpointer];
  temp->left = stack[--stackpointer];
  ( stack[stackpointer] = (temp), stackpointer++ );
}


rotatestack

decompiled_code:
_QWORD *rotatestack()
{
int v0; // ecx
_QWORD *v1; // rsi
_QWORD *result; // rax
__int64 v3; // rdi

v0 = stackpointer;
v1 = (_QWORD *)(stack + 8LL * (stackpointer - 1));
result = v1 - 1;
v3 = *(v1 - 1);
*(v1 - 1) = *v1;
*v1 = v3;
stackpointer = v0;
return result;
}

canonical_decompiled_code:
_QWORD *func8()
{
int v0; // ecx
_QWORD *v1; // rsi
_QWORD *result; // rax
__int64 v3; // rdi

v0 = stackpointer;
v1 = (_QWORD *)(stack + 8LL * (stackpointer - 1));
result = v1 - 1;
v3 = *(v1 - 1);
*(v1 - 1) = *v1;
*v1 = v3;
stackpointer = v0;
return result;
}

original_code:
void rotatestack(void)
{
  Cell *s0 = stack[--stackpointer], *s1 = stack[--stackpointer];
  ( stack[stackpointer] = (s0), stackpointer++ );
  ( stack[stackpointer] = (s1), stackpointer++ );
}

canonical_original_code:
void rotatestack()
{
  struct CELL *s0 = stack[--stackpointer]; struct CELL *s1 = stack[--stackpointer];
  ( stack[stackpointer] = (s0), stackpointer++ );
  ( stack[stackpointer] = (s1), stackpointer++ );
}


TrapIntSignal

decompiled_code:
void TrapIntSignal()
{
interrupted = 1;
signal(2, TrapIntSignal);
}

canonical_decompiled_code:
void func0()
{
interrupted = 1;
signal(2, TrapIntSignal);
}

original_code:
static void TrapIntSignal(int sig)
{
  interrupted = 1;
  signal(2, TrapIntSignal);
}

variable_types: sig int


SetIntSignal

decompiled_code:
__sighandler_t __fastcall SetIntSignal(int a1)
{
void (*v1)(); // rsi

v1 = TrapIntSignal;
if ( !a1 )
v1 = 0LL;
return signal(2, (__sighandler_t)v1);
}

canonical_decompiled_code:
__sighandler_t __fastcall func1(int a1)
{
void (*v1)(); // rsi

v1 = TrapIntSignal;
if ( !a1 )
v1 = 0LL;
return signal(2, (__sighandler_t)v1);
}

original_code:
void SetIntSignal(bool enable)
{
  signal(2, enable ? TrapIntSignal : ((__sighandler_t) 0));
}

canonical_original_code:
void SetIntSignal(int enable)
{
  signal(2, enable ? TrapIntSignal : ((void (*)(int)) 0));
}

variable_types: enable int


CloseAllIOFiles

decompiled_code:
int CloseAllIOFiles()
{
unsigned int i; // ebx
unsigned int v1; // edi
int result; // eax

for ( i = 0; i != 10; ++i )
{
v1 = i;
result = CloseIOFile(v1);
}
return result;
}

canonical_decompiled_code:
int func7()
{
unsigned int i; // ebx
unsigned int v1; // edi
int result; // eax

for ( i = 0; i != 10; ++i )
{
v1 = i;
result = func2(v1);
}
return result;
}

original_code:
void CloseAllIOFiles(void)
{
  int k;
  for(k=0; k<10; k++) CloseIOFile(k);
}

canonical_original_code:
void CloseAllIOFiles()
{
  int k;
  for(k=0; k<10; k++) CloseIOFile(k);
}


MarkIOFile

decompiled_code:
void __fastcall MarkIOFile(unsigned int a1)
{
if ( a1 <= 9 )
*(_DWORD *)(fileDescriptors + 16LL * (int)a1 + 12) = 0;
}

canonical_decompiled_code:
void __fastcall func10(unsigned int a1)
{
if ( a1 <= 9 )
*(_DWORD *)(fileDescriptors + 16LL * (int)a1 + 12) = 0;
}

original_code:
void MarkIOFile(int filenr)
{
  if(filenr < 0 || filenr >= 10) return;
  fileDescriptors[filenr].garbage = 0;
}

variable_types: filenr int


createIO

decompiled_code:
_DWORD *createIO()
{
_DWORD *result; // rax
__int64 v1; // rdx
__int64 v2; // rdx
_DWORD *v3; // rdx

if ( fileDescriptors )
{
result = (_DWORD *)(fileDescriptors + 8);
v1 = fileDescriptors + 168;
do
{
*result = 2;
result += 4;
}
while ( result != (_DWORD *)v1 );
}
else
{
fileDescriptors = (__int64)malloc(0xA0uLL);
v2 = fileDescriptors;
if ( !fileDescriptors )
{
systemerror(4LL);
v2 = fileDescriptors;
}
result = (_DWORD *)(v2 + 8);
v3 = (_DWORD *)(v2 + 168);
do
{
*result = 2;
result += 4;
}
while ( result != v3 );
}
return result;
}

canonical_decompiled_code:
_DWORD *func11()
{
_DWORD *result; // rax
__int64 v1; // rdx
__int64 v2; // rdx
_DWORD *v3; // rdx

if ( fileDescriptors )
{
result = (_DWORD *)(fileDescriptors + 8);
v1 = fileDescriptors + 168;
do
{
*result = 2;
result += 4;
}
while ( result != (_DWORD *)v1 );
}
else
{
fileDescriptors = (__int64)malloc(0xA0uLL);
v2 = fileDescriptors;
if ( !fileDescriptors )
{
systemerror(4LL);
v2 = fileDescriptors;
}
result = (_DWORD *)(v2 + 8);
v3 = (_DWORD *)(v2 + 168);
do
{
*result = 2;
result += 4;
}
while ( result != v3 );
}
return result;
}

original_code:
void createIO(void)
{
  int k;
  if(fileDescriptors == ((void *)0)) fileDescriptors = malloc(sizeof(FileDescriptors));
  if(fileDescriptors == ((void *)0)) systemerror(4);
  for(k=0; k<10; k++) fileDescriptors[k].mode = CLOSED;
}

canonical_original_code:
void createIO()
{
  int k;
  if(fileDescriptors == ((void *)0)) fileDescriptors = malloc(sizeof(FileDescriptors));
  if(fileDescriptors == ((void *)0)) systemerror(4);
  for(k=0; k<10; k++) fileDescriptors[k].mode = CLOSED;
}


runtimeerrormessage

decompiled_code:
const char *__fastcall runtimeerrormessage(unsigned __int8 a1)
{
const char *result; // rax

result = "infinite loop or record field undefined or object undefined";
if ( a1 != 12 )
{
if ( a1 > 0xCu )
{
result = "run time error";
if ( a1 == 39 )
result = "list expected";
}
else
{
result = "int expected";
if ( a1 != 3 )
{
result = "run time error";
if ( a1 == 4 )
result = "number expected";
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(unsigned __int8 a1)
{
const char *result; // rax

result = "infinite loop or record field undefined or object undefined";
if ( a1 != 12 )
{
if ( a1 > 0xCu )
{
result = "run time error";
if ( a1 == 39 )
result = "list expected";
}
else
{
result = "int expected";
if ( a1 != 3 )
{
result = "run time error";
if ( a1 == 4 )
result = "number expected";
}
}
}
return result;
}

original_code:
static char *runtimeerrormessage(TagType tag)
{
  switch(tag)
  {
    case LIST:
      return "list expected";
    case INT:
      return "int expected";
    case REAL:
      return "number expected";
    case UNDEFINED:
      return "infinite loop or record field undefined or object undefined";
    default:
      return "run time error";
  }
}

canonical_original_code:
static char *runtimeerrormessage(unsigned char tag)
{
  switch(tag)
  {
    case LIST:
      return "list expected";
    case INT:
      return "int expected";
    case REAL:
      return "number expected";
    case UNDEFINED:
      return "infinite loop or record field undefined or object undefined";
    default:
      return "run time error";
  }
}

variable_types:
tag
unsigned char

return_type: char *


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
Write("\nERROR: %s", a1);
interrupted = 0;
longjmp(mainenv, 1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
Write("\nERROR: %s", a1);
interrupted = 0;
longjmp(mainenv, 1);
}

original_code:
static void error(char message[])
{
  Write("\nERROR: %s", message);
  interrupted = 0;
  longjmp(mainenv, 1);
}

variable_types:
message
char []


parseerror

decompiled_code:
void __fastcall __noreturn parseerror(int a1)
{
__int64 v1; // rbx
const char *v2; // rdi

v1 = a1;
lexerror();
v2 = "parse error";
if ( (unsigned int)(v1 - 1) <= 0x21 )
v2 = parseerrormessage[v1];
error(v2);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(int a1)
{
__int64 v1; // rbx
const char *v2; // rdi

v1 = a1;
lexerror();
v2 = "parse error";
if ( (unsigned int)(v1 - 1) <= 0x21 )
v2 = parseerrormessage[v1];
func1(v2);
}

original_code:
void parseerror(int messagenr)
{
  lexerror();
  if(messagenr < 1 || messagenr > 34) messagenr = 0;
  error(parseerrormessage[messagenr]);
}

variable_types: messagenr int


runtimeerror

decompiled_code:
void __fastcall __noreturn runtimeerror(unsigned __int8 a1, int a2)
{
const char *v2; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

v2 = runtimeerrormessage(a1);
if ( a2 < 0 )
strcpy(v3, v2);
else
sprintf(v3, "%s in function %s", v2, *(const char **)(hashtable + 80LL * a2 + 16));
error(v3);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(unsigned __int8 a1, int a2)
{
const char *v2; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

v2 = func0(a1);
if ( a2 < 0 )
strcpy(v3, v2);
else
sprintf(v3, "%s in function %s", v2, *(const char **)(hashtable + 80LL * a2 + 16));
func1(v3);
}

original_code:
void runtimeerror(TagType tag, int hashtablenr)
{
  char string[256];
  if(hashtablenr >= 0)
    sprintf(string, "%s in function %s", runtimeerrormessage(tag), (hashtable+(hashtablenr))->name);
  else
    sprintf(string, "%s", runtimeerrormessage(tag));
  error(string);
}

canonical_original_code:
void runtimeerror(unsigned char tag, int hashtablenr)
{
  char string[256];
  if(hashtablenr >= 0)
    sprintf(string, "%s in function %s", runtimeerrormessage(tag), (hashtable+(hashtablenr))->name);
  else
    sprintf(string, "%s", runtimeerrormessage(tag));
  error(string);
}

variable_types: hashtablenr int

variable_types:
string
char [256]


modifyerror

decompiled_code:
void __fastcall __noreturn modifyerror(int a1, const char *a2)
{
const char *v2; // rdx
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

v2 = "modify error";
if ( (unsigned int)(a1 - 1) <= 4 )
v2 = modifyerrormessage[a1];
if ( *a2 )
sprintf(v3, "%s in function: %s", v2, a2);
else
strcpy(v3, v2);
error(v3);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(int a1, const char *a2)
{
const char *v2; // rdx
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

v2 = "modify error";
if ( (unsigned int)(a1 - 1) <= 4 )
v2 = modifyerrormessage[a1];
if ( *a2 )
sprintf(v3, "%s in function: %s", v2, a2);
else
strcpy(v3, v2);
func1(v3);
}

original_code:
void modifyerror(int messagenr, char functionname[])
{
  char string[256];
  if(messagenr < 1 || messagenr > 5) messagenr = 0;
  if(strlen(functionname) > 0)
    sprintf(string, "%s in function: %s", modifyerrormessage[messagenr], functionname);
  else
    strcpy(string, modifyerrormessage[messagenr]);
  error(string);
}

variable_types:
functionname
char []


systemerror

decompiled_code:
void __fastcall __noreturn systemerror(int a1)
{
const char *v1; // r8

v1 = "internal error";
if ( (unsigned int)(a1 - 1) <= 0x12 )
v1 = systemerrormessage[a1];
error(v1);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(int a1)
{
const char *v1; // r8

v1 = "internal error";
if ( (unsigned int)(a1 - 1) <= 0x12 )
v1 = systemerrormessage[a1];
func1(v1);
}

original_code:
void systemerror(int messagenr)
{
  if(messagenr < 1 || messagenr > 19) messagenr = 0;
  error(systemerrormessage[messagenr]);
}


checkinterrupt

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

CheckIO();
interruptcount = 500;
result = interrupted;
if ( interrupted )
systemerror(1);
return result;
}

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

CheckIO();
interruptcount = 500;
result = interrupted;
if ( interrupted )
func5(1);
return result;
}

original_code:
void checkinterrupt(void)
{
  CheckIO();
  interruptcount = 500;
  if(interrupted) systemerror(1);
}

canonical_original_code:
void checkinterrupt()
{
  CheckIO();
  interruptcount = 500;
  if(interrupted) systemerror(1);
}


starttiming

decompiled_code:
clock_t starttiming()
{
clock_t result; // rax

result = clock();
starttime = result;
return result;
}

canonical_decompiled_code:
clock_t func7()
{
clock_t result; // rax

result = clock();
starttime = result;
return result;
}

original_code:
void starttiming(void)
{
  starttime = clock();
}

canonical_original_code:
void starttiming()
{
  starttime = clock();
}


stoptiming

decompiled_code:
__int64 stoptiming()
{
__int64 result; // rax
int v1; // eax

result = timing[0];
if ( timing[0] )
{
v1 = clock();
result = Write("\nElapsed time: %3.1f secs", (float)((float)(v1 - starttime) / 1000000.0));
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
int v1; // eax

result = timing[0];
if ( timing[0] )
{
v1 = clock();
result = Write("\nElapsed time: %3.1f secs", (float)((float)(v1 - starttime) / 1000000.0));
}
return result;
}

original_code:
void stoptiming(void)
{
  if(!timing) return;
  stoptime = clock();
  Write("\nElapsed time: %3.1f secs", (float)(stoptime-starttime) / ((__clock_t) 1000000));
}

canonical_original_code:
void stoptiming()
{
  if(!timing) return;
  stoptime = clock();
  Write("\nElapsed time: %3.1f secs", (float)(stoptime-starttime) / ((long) 1000000));
}


copy

original_code:
static Cell *copy(Cell *c)
{
  if(c == ((void *)0))
    return ((void *)0);
  else if(c->tag == ARG)
  {
    Cell *temp = newcell(ARG);
    temp->value = c->value;
    return temp;
  }
  else if(c->tag > compositetag)
  {
    Cell *temp = newcell(c->tag);
    temp->value = c->value;
    temp->left = copy(c->left);
    temp->right = copy(c->right);
    return temp;
  }
  else
    return c;
}

canonical_original_code:
static struct CELL *copy(struct CELL *c)
{
  if(c == ((void *)0))
    return ((void *)0);
  else if(c->tag == ARG)
  {
    struct CELL *temp = newcell(ARG);
    temp->value = c->value;
    return temp;
  }
  else if(c->tag > compositetag)
  {
    struct CELL *temp = newcell(c->tag);
    temp->value = c->value;
    temp->left = copy(c->left);
    temp->right = copy(c->right);
    return temp;
  }
  else
    return c;
}

variable_types:
c
struct CELL *

return_type: struct CELL { struct CELL *left; int value; unsigned char tag; } *


emptydirector

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

result = newcell(28LL);
*(_DWORD *)(result + 16) = 1;
*(_QWORD *)result = a1;
return result;
}

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

result = newcell(28LL);
*(_DWORD *)(result + 16) = 1;
*(_QWORD *)result = a1;
return result;
}

original_code:
Cell *emptydirector(Cell *c)
{
  Cell *director = newcell(LAZYDIRECTOR);
  director->value = 1;
  director->left = c;
  return director;
}

canonical_original_code:
struct CELL *emptydirector(struct CELL *c)
{
  struct CELL *director = newcell(LAZYDIRECTOR);
  director->value = 1;
  director->left = c;
  return director;
}


finddirector

original_code:
Cell *finddirector(Cell *directorlist, Cell *c)
{
  if(c == ((void *)0)) return ((void *)0);
  if(c->tag == VARIABLE)
    for(; directorlist->tag == LIST; directorlist = directorlist->right)
      if(directorlist->left->left->value == c->value) return directorlist->left->right;
  return ((void *)0);
}

canonical_original_code:
struct CELL *finddirector(struct CELL *directorlist, struct CELL *c)
{
  if(c == ((void *)0)) return ((void *)0);
  if(c->tag == VARIABLE)
    for(; directorlist->tag == LIST; directorlist = directorlist->right)
      if(directorlist->left->left->value == c->value) return directorlist->left->right;
  return ((void *)0);
}

variable_types:
directorlist
struct CELL *


initrename

decompiled_code:
void __fastcall initrename(__int64 a1)
{
renamecount = 0;
functionname = a1;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
renamecount = 0;
functionname = a1;
}

original_code:
void initrename(char *funname)
{
  renamecount = 0;
  functionname = funname;
}

variable_types:
funname
char *


markcellrec

decompiled_code:
__int64 __fastcall markcellrec(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
__int64 v3; // rdi
unsigned int v4; // er8
char v5; // al
bool v6; // cc
int v7; // eax
__int64 v8; // rax

v1 = a1;
result = *(unsigned __int8 *)(a1 + 20);
v3 = *(_QWORD *)a1;
while ( 2 )
{
if ( (_BYTE)result == 25 )
goto LABEL_11;
LABEL_3:
if ( (_BYTE)result == 28 )
{
while ( 1 )
{
v4 = *(_DWORD *)(v1 + 16);
v5 = *(_BYTE *)(v3 + 20);
if ( v4 != 1 )
break;
if ( v5 != 28 )
goto LABEL_6;
v7 = *(_DWORD *)(v3 + 16);
v3 = *(_QWORD *)v3;
*(_DWORD *)(v1 + 16) = v7;
*(_QWORD *)v1 = v3;
}
if ( (unsigned __int8)(v5 - 8) > 0x1Eu )
{
v8 = copydirector(v4, v3);
*(_DWORD *)(v1 + 16) = 1;
*(_QWORD *)v1 = v8;
v3 = v8;
result = *(unsigned __int8 *)(v1 + 20);
continue;
}
LABEL_6:
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v3 + 24) == freemark )
goto LABEL_15;
}
else
{
while ( v3 )
{
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v3 + 24) != freemark )
break;
LABEL_15:
result = (unsigned __int8)currentmark;
--freecount;
v6 = *(_BYTE *)(v3 + 20) <= 0x11u;
*(_BYTE *)(v3 + 24) = currentmark;
if ( v6 )
goto LABEL_7;
result = markcellrec();
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
return result;
LABEL_8:
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v1 + 24) != freemark )
return result;
--freecount;
*(_BYTE *)(v1 + 24) = currentmark;
result = *(unsigned __int8 *)(v1 + 20);
if ( (unsigned __int8)result <= 0x10u )
return result;
v3 = *(_QWORD *)v1;
if ( (_BYTE)result != 25 )
goto LABEL_3;
LABEL_11:
result = sysvalue_fread;
if ( *(_DWORD *)(v1 + 16) == sysvalue_fread )
{
result = MarkIOFile(*(_QWORD *)v3);
v3 = *(_QWORD *)v1;
}
}
}
break;
}
LABEL_7:
v1 = *(_QWORD *)(v1 + 8);
if ( v1 )
goto LABEL_8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
__int64 v3; // rdi
unsigned int v4; // er8
char v5; // al
bool v6; // cc
int v7; // eax
__int64 v8; // rax

v1 = a1;
result = *(unsigned __int8 *)(a1 + 20);
v3 = *(_QWORD *)a1;
while ( 2 )
{
if ( (_BYTE)result == 25 )
goto LABEL_11;
LABEL_3:
if ( (_BYTE)result == 28 )
{
while ( 1 )
{
v4 = *(_DWORD *)(v1 + 16);
v5 = *(_BYTE *)(v3 + 20);
if ( v4 != 1 )
break;
if ( v5 != 28 )
goto LABEL_6;
v7 = *(_DWORD *)(v3 + 16);
v3 = *(_QWORD *)v3;
*(_DWORD *)(v1 + 16) = v7;
*(_QWORD *)v1 = v3;
}
if ( (unsigned __int8)(v5 - 8) > 0x1Eu )
{
v8 = copydirector(v4, v3);
*(_DWORD *)(v1 + 16) = 1;
*(_QWORD *)v1 = v8;
v3 = v8;
result = *(unsigned __int8 *)(v1 + 20);
continue;
}
LABEL_6:
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v3 + 24) == freemark )
goto LABEL_15;
}
else
{
while ( v3 )
{
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v3 + 24) != freemark )
break;
LABEL_15:
result = (unsigned __int8)currentmark;
--freecount;
v6 = *(_BYTE *)(v3 + 20) <= 0x11u;
*(_BYTE *)(v3 + 24) = currentmark;
if ( v6 )
goto LABEL_7;
result = func0();
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
return result;
LABEL_8:
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v1 + 24) != freemark )
return result;
--freecount;
*(_BYTE *)(v1 + 24) = currentmark;
result = *(unsigned __int8 *)(v1 + 20);
if ( (unsigned __int8)result <= 0x10u )
return result;
v3 = *(_QWORD *)v1;
if ( (_BYTE)result != 25 )
goto LABEL_3;
LABEL_11:
result = sysvalue_fread;
if ( *(_DWORD *)(v1 + 16) == sysvalue_fread )
{
result = MarkIOFile(*(_QWORD *)v3);
v3 = *(_QWORD *)v1;
}
}
}
break;
}
LABEL_7:
v1 = *(_QWORD *)(v1 + 8);
if ( v1 )
goto LABEL_8;
return result;
}

original_code:
static void markcellrec(Cell *c)
{
  for(;;)
  {
    switch(c->tag)
    {
      case SYSFUNC1:
        if(c->value == sysvalue_fread) MarkIOFile((((IntCell *)(c->left))->value));
        break;
      case LAZYDIRECTOR:
        if(c->value == 1)
        {
          if(c->left->tag == LAZYDIRECTOR)
          {
            c->value = c->left->value;
            c->left = c->left->left;
            continue;
          }
        }
        else
        {
          if(c->left->tag < nonevaltag || c->left->tag > evaltag)
          {
            c->left = copydirector(c->value, c->left);
            c->value = 1;
            continue;
          }
        }
        break;
    }
    if(c->left && (((MarkCell *)(c->left))->mark) == freemark)
    {
      (((MarkCell *)(c->left))->mark) = currentmark;
      freecount--;
      if(c->left->tag > compositetag) markcellrec(c->left);
    }
    c = c->right;
    if(c == ((void *)0) || (((MarkCell *)(c))->mark) != freemark) return;
    (((MarkCell *)(c))->mark) = currentmark;
    freecount--;
    if(c->tag < compositetag) return;
  }
}

canonical_original_code:
static void markcellrec(struct CELL *c)
{
  for(;;)
  {
    switch(c->tag)
    {
      case SYSFUNC1:
        if(c->value == sysvalue_fread) MarkIOFile((((struct IntCell *)(c->left))->value));
        break;
      case LAZYDIRECTOR:
        if(c->value == 1)
        {
          if(c->left->tag == LAZYDIRECTOR)
          {
            c->value = c->left->value;
            c->left = c->left->left;
            continue;
          }
        }
        else
        {
          if(c->left->tag < nonevaltag || c->left->tag > evaltag)
          {
            c->left = copydirector(c->value, c->left);
            c->value = 1;
            continue;
          }
        }
        break;
    }
    if(c->left && (((struct MarkCell *)(c->left))->mark) == freemark)
    {
      (((struct MarkCell *)(c->left))->mark) = currentmark;
      freecount--;
      if(c->left->tag > compositetag) markcellrec(c->left);
    }
    c = c->right;
    if(c == ((void *)0) || (((struct MarkCell *)(c))->mark) != freemark) return;
    (((struct MarkCell *)(c))->mark) = currentmark;
    freecount--;
    if(c->tag < compositetag) return;
  }
}

user_defined_types: struct MarkCell { struct CELL cell; unsigned char mark; }


markcell

decompiled_code:
__int64 __fastcall markcell(__int64 a1)
{
__int64 result; // rax
bool v2; // cc

if ( a1 )
{
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(a1 + 24) == freemark )
{
result = (unsigned __int8)currentmark;
--freecount;
v2 = *(_BYTE *)(a1 + 20) <= 0x11u;
*(_BYTE *)(a1 + 24) = currentmark;
if ( !v2 )
result = markcellrec(a1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
bool v2; // cc

if ( a1 )
{
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(a1 + 24) == freemark )
{
result = (unsigned __int8)currentmark;
--freecount;
v2 = *(_BYTE *)(a1 + 20) <= 0x11u;
*(_BYTE *)(a1 + 24) = currentmark;
if ( !v2 )
result = func0(a1);
}
}
return result;
}

original_code:
static void markcell(Cell *c)
{
  if(c && (((MarkCell *)(c))->mark) == freemark)
  {
    (((MarkCell *)(c))->mark) = currentmark;
    freecount--;
    if(c->tag > compositetag) markcellrec(c);
  }
}

canonical_original_code:
static void markcell(struct CELL *c)
{
  if(c && (((struct MarkCell *)(c))->mark) == freemark)
  {
    (((struct MarkCell *)(c))->mark) = currentmark;
    freecount--;
    if(c->tag > compositetag) markcellrec(c);
  }
}


markfuncdef

decompiled_code:
__int64 __fastcall markfuncdef(_QWORD *a1)
{
__int64 v2; // rdi
__int64 result; // rax
__int64 v4; // rdi
__int64 v5; // rdi
__int64 v6; // rdi

v2 = a1[8];
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v2 + 24) == freemark )
result = markcell(v2);
v4 = a1[1];
if ( v4 )
{
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v4 + 24) == freemark )
result = markcell(v4);
}
v5 = a1[5];
if ( v5 )
{
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v5 + 24) == freemark )
result = markcell(v5);
}
v6 = a1[6];
if ( v6 )
{
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v6 + 24) == freemark )
result = markcell(v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 v2; // rdi
__int64 result; // rax
__int64 v4; // rdi
__int64 v5; // rdi
__int64 v6; // rdi

v2 = a1[8];
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v2 + 24) == freemark )
result = func1(v2);
v4 = a1[1];
if ( v4 )
{
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v4 + 24) == freemark )
result = func1(v4);
}
v5 = a1[5];
if ( v5 )
{
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v5 + 24) == freemark )
result = func1(v5);
}
v6 = a1[6];
if ( v6 )
{
result = (unsigned __int8)freemark;
if ( *(_BYTE *)(v6 + 24) == freemark )
result = func1(v6);
}
return result;
}

original_code:
static void markfuncdef(FuncDef *fun)
{
  if( (((MarkCell *)(fun->template))->mark) == freemark) markcell(fun->template);
  if(fun->def && (((MarkCell *)(fun->def))->mark) == freemark) markcell(fun->def);
  if(fun->typeexpr && (((MarkCell *)(fun->typeexpr))->mark) == freemark) markcell(fun->typeexpr);
  if(fun->abstype && (((MarkCell *)(fun->abstype))->mark) == freemark) markcell(fun->abstype);
}

canonical_original_code:
static void markfuncdef(struct FuncDef *fun)
{
  if( (((struct MarkCell *)(fun->template))->mark) == freemark) markcell(fun->template);
  if(fun->def && (((struct MarkCell *)(fun->def))->mark) == freemark) markcell(fun->def);
  if(fun->typeexpr && (((struct MarkCell *)(fun->typeexpr))->mark) == freemark) markcell(fun->typeexpr);
  if(fun->abstype && (((struct MarkCell *)(fun->abstype))->mark) == freemark) markcell(fun->abstype);
}

variable_types: struct FuncDef { void (*code)(); struct CELL { struct CELL *left; int value; unsigned char tag; } *def; char *name; int argcount; int sysfunc; int typechanged; int generic; struct CELL *typeexpr; struct CELL *abstype; int prio; enum Assoc { Left=0, Right=1 } assoc; struct CELL *template; unsigned char tag; } *


createmem

decompiled_code:
void *__fastcall createmem(__int64 a1)
{
signed __int64 v1; // rbx
void *result; // rax

v1 = a1;
if ( a1 > 10000000 )
v1 = 10000000LL;
if ( v1 < 10000 )
v1 = 10000LL;
memcount = v1;
result = calloc(v1, 0x20uLL);
freecount = v1;
memblock = (__int64)result;
lockcount = 0LL;
freemark = 0;
currentmark = 1;
newindex = 0LL;
reclaimcount = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
signed __int64 v1; // rbx
void *result; // rax

v1 = a1;
if ( a1 > 10000000 )
v1 = 10000000LL;
if ( v1 < 10000 )
v1 = 10000LL;
memcount = v1;
result = calloc(v1, 0x20uLL);
freecount = v1;
memblock = (__int64)result;
lockcount = 0LL;
freemark = 0;
currentmark = 1;
newindex = 0LL;
reclaimcount = 0LL;
return result;
}

original_code:
void createmem(long size)
{
  if(size < 10000) size = 10000;
  if(size > 10000000) size = 10000000;
  memcount = size;
  memblock = calloc(memcount, sizeof(MarkCell));
  lockcount = 0;
  freecount = memcount - lockcount;
  freemark = 0;
  currentmark = 1 - freemark;
  newindex = 0;
  reclaimcount = 0;
}

variable_types: size long


reclaim

decompiled_code:
__int64 reclaim()
{
__int64 v0; // rsi
char v1; // di
char v2; // cl
__int64 v3; // rax
__int64 v4; // rdx
__int64 result; // rax

v0 = memcount;
v1 = currentmark;
if ( newindex < memcount )
{
v2 = freemark;
v3 = memblock + 32 * newindex;
v4 = memblock + 32 * memcount;
do
{
if ( *(_BYTE *)(v3 + 24) == v2 )
*(_BYTE *)(v3 + 24) = v1;
v3 += 32LL;
}
while ( v3 != v4 );
}
freemark = v1;
freecount = v0 - lockcount;
currentmark = 1 - v1;
forallhashtable(markfuncdef);
result = forallstack(markcell);
++reclaimcount;
newindex = 0LL;
if ( freecount <= 999 )
result = systemerror(2LL);
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rsi
char v1; // di
char v2; // cl
__int64 v3; // rax
__int64 v4; // rdx
__int64 result; // rax

v0 = memcount;
v1 = currentmark;
if ( newindex < memcount )
{
v2 = freemark;
v3 = memblock + 32 * newindex;
v4 = memblock + 32 * memcount;
do
{
if ( *(_BYTE *)(v3 + 24) == v2 )
*(_BYTE *)(v3 + 24) = v1;
v3 += 32LL;
}
while ( v3 != v4 );
}
freemark = v1;
freecount = v0 - lockcount;
currentmark = 1 - v1;
forallhashtable(markfuncdef);
result = forallstack(markcell);
++reclaimcount;
newindex = 0LL;
if ( freecount <= 999 )
result = systemerror(2LL);
return result;
}

original_code:
void reclaim(void)
{
  long int k = newindex;
  for(; k < memcount; k++)
  {
    MarkCell *c = memblock+k;
    if((((MarkCell *)(c))->mark) == freemark) (((MarkCell *)(c))->mark) = currentmark;
  }
  freecount = memcount - lockcount;
  freemark = currentmark;
  currentmark = 1 - freemark;
  forallhashtable(markfuncdef);
  forallstack(markcell);
  newindex = 0;
  reclaimcount++;
  if(freecount < 1000) systemerror(2);
}

canonical_original_code:
void reclaim()
{
  long k = newindex;
  for(; k < memcount; k++)
  {
    struct MarkCell *c = memblock+k;
    if((((struct MarkCell *)(c))->mark) == freemark) (((struct MarkCell *)(c))->mark) = currentmark;
  }
  freecount = memcount - lockcount;
  freemark = currentmark;
  currentmark = 1 - freemark;
  forallhashtable(markfuncdef);
  forallstack(markcell);
  newindex = 0;
  reclaimcount++;
  if(freecount < 1000) systemerror(2);
}

variable_types: k long

variable_types: struct MarkCell { struct CELL { struct CELL *left; int value; unsigned char tag; } cell; unsigned char mark; } *


unlockmem

decompiled_code:
__int64 unlockmem()
{
__int64 v0; // rax
char v1; // cl
__int64 v2; // rdx

if ( memcount > 0 )
{
v0 = memblock;
v1 = currentmark;
v2 = memblock + 32 * memcount;
do
{
if ( *(_BYTE *)(v0 + 24) == 2 )
*(_BYTE *)(v0 + 24) = v1;
v0 += 32LL;
}
while ( v0 != v2 );
}
lockcount = 0LL;
return reclaim();
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rax
char v1; // cl
__int64 v2; // rdx

if ( memcount > 0 )
{
v0 = memblock;
v1 = currentmark;
v2 = memblock + 32 * memcount;
do
{
if ( *(_BYTE *)(v0 + 24) == 2 )
*(_BYTE *)(v0 + 24) = v1;
v0 += 32LL;
}
while ( v0 != v2 );
}
lockcount = 0LL;
return func4();
}

original_code:
void unlockmem(void)
{
  long int k = 0;
  for(; k < memcount; k++)
  {
    MarkCell *c = memblock+k;
    if((((MarkCell *)(c))->mark) == 2) (((MarkCell *)(c))->mark) = currentmark;
  }
  lockcount = 0;
  reclaim();
}

canonical_original_code:
void unlockmem()
{
  long k = 0;
  for(; k < memcount; k++)
  {
    struct MarkCell *c = memblock+k;
    if((((struct MarkCell *)(c))->mark) == 2) (((struct MarkCell *)(c))->mark) = currentmark;
  }
  lockcount = 0;
  reclaim();
}


lockmem

decompiled_code:
__int64 lockmem()
{
char v0; // al
__int64 result; // rax

unlockmem();
freecount = memcount;
v0 = currentmark;
currentmark = 2;
freemark = v0;
forallhashtable(markfuncdef);
forallstack(markcell);
currentmark = freemark;
freemark = 1 - freemark;
result = memcount - freecount;
lockcount = memcount - freecount;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
char v0; // al
__int64 result; // rax

func5();
freecount = memcount;
v0 = currentmark;
currentmark = 2;
freemark = v0;
forallhashtable(markfuncdef);
forallstack(markcell);
currentmark = freemark;
freemark = 1 - freemark;
result = memcount - freecount;
lockcount = memcount - freecount;
return result;
}

original_code:
void lockmem(void)
{
  unlockmem();
  freecount = memcount;
  freemark = currentmark;
  currentmark = 2;
  forallhashtable(markfuncdef);
  forallstack(markcell);
  currentmark = freemark;
  freemark = 1 - currentmark;
  lockcount = memcount - freecount;
}

canonical_original_code:
void lockmem()
{
  unlockmem();
  freecount = memcount;
  freemark = currentmark;
  currentmark = 2;
  forallhashtable(markfuncdef);
  forallstack(markcell);
  currentmark = freemark;
  freemark = 1 - currentmark;
  lockcount = memcount - freecount;
}


checkmem

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

if ( freecount <= 999 )
{
result = reclaim();
if ( freecount <= 999 )
result = systemerror(2LL);
}
return result;
}

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

if ( freecount <= 999 )
{
result = func4();
if ( freecount <= 999 )
result = systemerror(2LL);
}
return result;
}

original_code:
void checkmem(void)
{
  if(freecount < 1000)
  {
    reclaim();
    if(freecount < 1000) systemerror(2);
  }
}

canonical_original_code:
void checkmem()
{
  if(freecount < 1000)
  {
    reclaim();
    if(freecount < 1000) systemerror(2);
  }
}


checkmemlarge

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

if ( freecount <= 4999 )
{
result = reclaim();
if ( freecount <= 4999 )
result = systemerror(2LL);
}
return result;
}

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

if ( freecount <= 4999 )
{
result = func4();
if ( freecount <= 4999 )
result = systemerror(2LL);
}
return result;
}

original_code:
void checkmemlarge(void)
{
  if(freecount < 5000)
  {
    reclaim();
    if(freecount < 5000) systemerror(2);
  }
}

canonical_original_code:
void checkmemlarge()
{
  if(freecount < 5000)
  {
    reclaim();
    if(freecount < 5000) systemerror(2);
  }
}


printmeminfo

decompiled_code:
__int64 printmeminfo()
{
return Write(
"MemorySize : %ld\nFree : %ld\nReclamations: %ld\n",
memcount,
memcount - lockcount,
reclaimcount);
}

canonical_decompiled_code:
__int64 func9()
{
return Write(
"MemorySize : %ld\nFree : %ld\nReclamations: %ld\n",
memcount,
memcount - lockcount,
reclaimcount);
}

original_code:
void printmeminfo(void)
{
  Write("MemorySize  : %ld\nFree        : %ld\nReclamations: %ld\n", memcount, memcount-lockcount, reclaimcount);
}

canonical_original_code:
void printmeminfo()
{
  Write("MemorySize  : %ld\nFree        : %ld\nReclamations: %ld\n", memcount, memcount-lockcount, reclaimcount);
}


newcell

decompiled_code:
__int64 __fastcall newcell(char a1)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rax
__int64 v4; // r8
char v5; // al
__int64 result; // rax

v1 = freecount;
if ( !freecount )
{
reclaim();
v1 = freecount;
}
v2 = newindex;
freecount = v1 - 1;
v3 = memblock + 32 * newindex;
do
{
v4 = v3;
v3 += 32LL;
++v2;
}
while ( *(_BYTE *)(v3 - 8) != freemark );
v5 = currentmark;
*(_BYTE *)(v4 + 20) = a1;
*(_QWORD *)(v4 + 8) = 0LL;
*(_BYTE *)(v4 + 24) = v5;
result = v4;
*(_QWORD *)v4 = 0LL;
newindex = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char a1)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rax
__int64 v4; // r8
char v5; // al
__int64 result; // rax

v1 = freecount;
if ( !freecount )
{
func4();
v1 = freecount;
}
v2 = newindex;
freecount = v1 - 1;
v3 = memblock + 32 * newindex;
do
{
v4 = v3;
v3 += 32LL;
++v2;
}
while ( *(_BYTE *)(v3 - 8) != freemark );
v5 = currentmark;
*(_BYTE *)(v4 + 20) = a1;
*(_QWORD *)(v4 + 8) = 0LL;
*(_BYTE *)(v4 + 24) = v5;
result = v4;
*(_QWORD *)v4 = 0LL;
newindex = v2;
return result;
}

original_code:
Cell *newcell(TagType tag)
{
  Cell *temp;
  if(freecount == 0) reclaim();
  freecount--;
  do
  {
    temp = (Cell *)(memblock + newindex);
    newindex++;
  }
  while((((MarkCell *)(temp))->mark) != freemark);
  (((MarkCell *)(temp))->mark) = currentmark;
  temp->tag = tag;
  temp->left = temp->right = ((void *)0);
  return temp;
}

canonical_original_code:
struct CELL *newcell(unsigned char tag)
{
  struct CELL *temp;
  if(freecount == 0) reclaim();
  freecount--;
  do
  {
    temp = (struct CELL *)(memblock + newindex);
    newindex++;
  }
  while((((struct MarkCell *)(temp))->mark) != freemark);
  (((struct MarkCell *)(temp))->mark) = currentmark;
  temp->tag = tag;
  temp->left = temp->right = ((void *)0);
  return temp;
}

variable_types: struct CELL { struct CELL *left; int value; unsigned char tag; } *


cleanup

repo: remotestorage/fuse

decompiled_code:
void cleanup(void)
{
cleanup_remote();
free(RS_CONFIG);
free(*(&RS_CONFIG + 1));
free(*(&RS_CONFIG + 3));
}

canonical_decompiled_code:
void func0(void)
{
cleanup_remote();
free(RS_CONFIG);
free(*(&RS_CONFIG + 1));
free(*(&RS_CONFIG + 3));
}

original_code:
void cleanup() {
  cleanup_remote();
  free(RS_CONFIG.base_url);
  free(RS_CONFIG.token);
  free(RS_CONFIG.auth_header);
}


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = calloc(a1, 1uLL);
if ( !result )
{
perror("malloc() failed");
abort();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1)
{
void *result; // rax

result = calloc(a1, 1uLL);
if ( !result )
{
perror("malloc() failed");
abort();
}
return result;
}

original_code:
static void *xmalloc(size_t count) {
  void *ptr = malloc(count);
  if(! ptr) {
    perror("malloc() failed");
    abort();
  }
  memset(ptr, 0, count);
  return ptr;
}

canonical_original_code:
static void *xmalloc(unsigned long count) {
  void *ptr = malloc(count);
  if(! ptr) {
    perror("malloc() failed");
    abort();
  }
  memset(ptr, 0, count);
  return ptr;
}

variable_types:
count
unsigned long

variable_types:
ptr
void *

return_type: void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
struct tm *v4; // rax
const char *v5; // rbp
size_t v6; // rax
char *v7; // rax
const char *v8; // rdx
time_t timer; // [rsp+8h] [rbp-40h] BYREF
unsigned int v11; // [rsp+10h] [rbp-38h] BYREF
const char **v12; // [rsp+18h] [rbp-30h]
int v13; // [rsp+20h] [rbp-28h]

open_log(argc, argv, envp);
v3 = (char *)xmalloc(0x64uLL);
timer = time(0LL);
v4 = localtime(&timer);
strftime(v3, 0x63uLL, "%c", v4);
log_msg("BEGIN LOG rs-mount %s", v3);
free(v3);
v11 = argc;
v12 = argv;
v13 = 0;
*(_OWORD *)&RS_CONFIG = 0LL;
*((_OWORD *)&RS_CONFIG + 1) = 0LL;
fuse_opt_parse(&v11, &RS_CONFIG, &rs_opts, 0LL);
if ( !RS_CONFIG )
{
fwrite("ERROR: Required option 'base_url' not given!\n", 1uLL, 0x2DuLL, stderr);
abort();
}
v5 = *(&RS_CONFIG + 1);
if ( !v5 )
{
fwrite("ERROR: Required option 'token' not given!\n", 1uLL, 0x2AuLL, stderr);
abort();
}
*(&RS_CONFIG + 2) = (char *)strlen(RS_CONFIG);
v6 = strlen(v5);
v7 = (char *)xmalloc(v6 + 23);
v8 = *(&RS_CONFIG + 1);
*(&RS_CONFIG + 3) = v7;
sprintf(v7, "Authorization: Bearer %s", v8);
curl_global_init(3LL);
init_remote();
atexit(cleanup);
return fuse_main_real(v11, v12, &rs_ops, 360LL, 0LL);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
struct tm *v4; // rax
const char *v5; // rbp
size_t v6; // rax
char *v7; // rax
const char *v8; // rdx
time_t timer; // [rsp+8h] [rbp-40h] BYREF
unsigned int v11; // [rsp+10h] [rbp-38h] BYREF
const char **v12; // [rsp+18h] [rbp-30h]
int v13; // [rsp+20h] [rbp-28h]

open_log(argc, argv, envp);
v3 = (char *)func1(0x64uLL);
timer = time(0LL);
v4 = localtime(&timer);
strftime(v3, 0x63uLL, "%c", v4);
log_msg("BEGIN LOG rs-mount %s", v3);
free(v3);
v11 = argc;
v12 = argv;
v13 = 0;
*(_OWORD *)&RS_CONFIG = 0LL;
*((_OWORD *)&RS_CONFIG + 1) = 0LL;
fuse_opt_parse(&v11, &RS_CONFIG, &rs_opts, 0LL);
if ( !RS_CONFIG )
{
fwrite("ERROR: Required option 'base_url' not given!\n", 1uLL, 0x2DuLL, stderr);
abort();
}
v5 = *(&RS_CONFIG + 1);
if ( !v5 )
{
fwrite("ERROR: Required option 'token' not given!\n", 1uLL, 0x2AuLL, stderr);
abort();
}
*(&RS_CONFIG + 2) = (char *)strlen(RS_CONFIG);
v6 = strlen(v5);
v7 = (char *)func1(v6 + 23);
v8 = *(&RS_CONFIG + 1);
*(&RS_CONFIG + 3) = v7;
sprintf(v7, "Authorization: Bearer %s", v8);
curl_global_init(3LL);
init_remote();
atexit(cleanup);
return fuse_main_real(v11, v12, &rs_ops, 360LL, 0LL);
}

original_code:
int main(int argc, char **argv)
{
  open_log();
  char *d = xmalloc(100);
  time_t t = time(((void *)0));
  struct tm *tmp = localtime(&t);
  strftime(d, 99, "%c", tmp);
  log_msg("BEGIN LOG rs-mount %s", d);
  free(d);
  struct fuse_args args = { argc, argv, 0 };
  memset(&RS_CONFIG, 0, sizeof(struct rs_config));
  fuse_opt_parse(&args, &RS_CONFIG, rs_opts, ((void *)0));
  if(! RS_CONFIG. base_url) { fprintf(stderr, "ERROR: Required option '" "base_url" "' not given!\n"); abort(); };
  if(! RS_CONFIG. token) { fprintf(stderr, "ERROR: Required option '" "token" "' not given!\n"); abort(); };
  RS_CONFIG.base_url_len = strlen(RS_CONFIG.base_url);
  RS_CONFIG.auth_header = xmalloc(strlen(RS_CONFIG.token) + 23);
  sprintf(RS_CONFIG.auth_header, "Authorization: Bearer %s", RS_CONFIG.token);
  curl_global_init(((1<<0)|(1<<1)));
  init_remote();
  atexit(cleanup);
  return fuse_main_real(args.argc, args.argv, &rs_ops, sizeof(*(&rs_ops)), ((void *)0));
}

canonical_original_code:
int main(int argc, char **argv)
{
  open_log();
  char *d = xmalloc(100);
  long t = time(((void *)0));
  struct tm *tmp = localtime(&t);
  strftime(d, 99, "%c", tmp);
  log_msg("BEGIN LOG rs-mount %s", d);
  free(d);
  struct fuse_args args = { argc, argv, 0 };
  memset(&RS_CONFIG, 0, sizeof(struct rs_config));
  fuse_opt_parse(&args, &RS_CONFIG, rs_opts, ((void *)0));
  if(! RS_CONFIG. base_url) { fprintf(stderr, "ERROR: Required option '" "base_url" "' not given!\n"); abort(); };
  if(! RS_CONFIG. token) { fprintf(stderr, "ERROR: Required option '" "token" "' not given!\n"); abort(); };
  RS_CONFIG.base_url_len = strlen(RS_CONFIG.base_url);
  RS_CONFIG.auth_header = xmalloc(strlen(RS_CONFIG.token) + 23);
  sprintf(RS_CONFIG.auth_header, "Authorization: Bearer %s", RS_CONFIG.token);
  curl_global_init(((1<<0)|(1<<1)));
  init_remote();
  atexit(cleanup);
  return fuse_main_real(args.argc, args.argv, &rs_ops, sizeof(*(&rs_ops)), ((void *)0));
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
d
char *

variable_types: t long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: struct fuse_args { int argc; char **argv; int allocated; }

user_defined_types: struct rs_config { char *base_url; char *token; unsigned long base_url_len; char *auth_header; }


xmalloc

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = calloc(a1, 1uLL);
if ( !result )
{
perror("malloc() failed");
abort();
}
return result;
}


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

result = new_trie();
trie_root = result;
return result;
}

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

result = new_trie();
trie_root = result;
return result;
}

original_code:
void rs_init_cache() {
  trie_root = new_trie();
}


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
perror("realloc() failed");
abort();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
perror("realloc() failed");
abort();
}
return result;
}

original_code:
static void *xrealloc(void *inptr, size_t count) {
  void *ptr = realloc(inptr, count);
  if(! ptr) {
    perror("realloc() failed");
    abort();
  }
  return ptr;
}

canonical_original_code:
static void *xrealloc(void *inptr, unsigned long count) {
  void *ptr = realloc(inptr, count);
  if(! ptr) {
    perror("realloc() failed");
    abort();
  }
  return ptr;
}

variable_types:
inptr
void *


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

result = curl_easy_init();
curl_handle = result;
return result;
}

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

result = curl_easy_init();
curl_handle = result;
return result;
}

original_code:
void init_remote() {
  curl_handle = curl_easy_init();
}


decompiled_code:
__int64 cleanup_remote()
{
return curl_easy_cleanup(curl_handle);
}

canonical_decompiled_code:
__int64 func6()
{
return curl_easy_cleanup(curl_handle);
}

original_code:
void cleanup_remote() {
  curl_easy_cleanup(curl_handle);
}


decompiled_code:
__int64 __fastcall delete_node_remote(const char *a1)
{
__int64 result; // rax

result = perform_request(3u, a1, 0LL);
if ( result == 200 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
__int64 result; // rax

result = func7(3u, a1, 0LL);
if ( result == 200 )
result = 0LL;
return result;
}

original_code:
int delete_node_remote(const char *path) {
  long status = perform_request(DELETE, path, ((void *)0));
  return status == 200 ? 0 : status;
}

canonical_original_code:
int delete_node_remote(char *path) {
  long status = perform_request(DELETE, path, ((void *)0));
  return status == 200 ? 0 : status;
}

variable_types:
path
char *

variable_types: status long


decompiled_code:
FILE *open_log()
{
FILE *result; // rax

result = fopen64("rs-fuse.log", "a+");
logfile = result;
if ( !result )
{
perror("Failed to open log");
abort();
}
return result;
}

canonical_decompiled_code:
FILE *func1()
{
FILE *result; // rax

result = fopen64("rs-fuse.log", "a+");
logfile = result;
if ( !result )
{
perror("Failed to open log");
abort();
}
return result;
}

original_code:
void open_log() {
  logfile = fopen("rs-fuse.log", "a+");
  if(! logfile) {
    perror("Failed to open log");
    abort();
  }
}


decompiled_code:
int log_msg(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(logfile, format, arg);
fputc(10, logfile);
return fflush(logfile);
}

canonical_decompiled_code:
int func2(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(logfile, format, arg);
fputc(10, logfile);
return fflush(logfile);
}

original_code:
void log_msg(char *format, ...) {
  va_list ap;
  __builtin_va_start(ap,format);
  vfprintf(logfile, format, ap);
  __builtin_va_end(ap);
  fprintf(logfile, "\n");
  fflush(logfile);
}

canonical_original_code:
void log_msg(char *format, ...) {
  __builtin_va_list ap;
  __builtin_va_start(ap,format);
  vfprintf(logfile, format, ap);
  __builtin_va_end(ap);
  fprintf(logfile, "\n");
  fflush(logfile);
}

variable_types:
format
char *


decompiled_code:
char *__fastcall strip_slash(char *src)
{
int v1; // ebx
char *v2; // rax

v1 = strlen(src);
v2 = (char *)xmalloc(v1);
return strncpy(v2, src, v1 - 1);
}

canonical_decompiled_code:
char *__fastcall func4(char *src)
{
int v1; // ebx
char *v2; // rax

v1 = strlen(src);
v2 = (char *)func0(v1);
return strncpy(v2, src, v1 - 1);
}

original_code:
char *strip_slash(const char *path) {
  int len = strlen(path);
  char *ret = xmalloc(len);
  strncpy(ret, path, len - 1);
  return ret;
}

canonical_original_code:
char *strip_slash(char *path) {
  int len = strlen(path);
  char *ret = xmalloc(len);
  strncpy(ret, path, len - 1);
  return ret;
}

variable_types: len int

variable_types:
ret
char *


decompiled_code:
char *__fastcall get_parrent_path(const char *a1)
{
char *v1; // rbp
char *v2; // rax
char *v3; // r12

v1 = strdup(a1);
v2 = dirname(v1);
v3 = adjust_path(v2, 1);
free(v1);
return v3;
}

canonical_decompiled_code:
char *__fastcall func5(const char *a1)
{
char *v1; // rbp
char *v2; // rax
char *v3; // r12

v1 = strdup(a1);
v2 = dirname(v1);
v3 = func3(v2, 1);
free(v1);
return v3;
}

original_code:
char* get_parrent_path(const char* path){
  char* tmp = strdup(path);
  char* ret = adjust_path(dirname(tmp), true);
  free(tmp);
  return ret;
}

canonical_original_code:
char *get_parrent_path(char *path){
  char *tmp = strdup(path);
  char *ret = adjust_path(dirname(tmp), true);
  free(tmp);
  return ret;
}

variable_types:
tmp
char *


decompiled_code:
char *__fastcall rs_dirname(char *src)
{
__int64 v2; // rax
int v3; // edx
size_t v4; // rdi
size_t v5; // r12
char *v6; // rax

if ( src[1] )
{
v2 = 0LL;
v3 = 0;
do
{
if ( src[v2] == 47 )
v3 = v2;
++v2;
}
while ( src[v2 + 1] );
v4 = v3 + 2;
v5 = v3 + 1;
}
else
{
v5 = 1LL;
v4 = 2LL;
}
v6 = (char *)xmalloc(v4);
return strncpy(v6, src, v5);
}

canonical_decompiled_code:
char *__fastcall func7(char *src)
{
__int64 v2; // rax
int v3; // edx
size_t v4; // rdi
size_t v5; // r12
char *v6; // rax

if ( src[1] )
{
v2 = 0LL;
v3 = 0;
do
{
if ( src[v2] == 47 )
v3 = v2;
++v2;
}
while ( src[v2 + 1] );
v4 = v3 + 2;
v5 = v3 + 1;
}
else
{
v5 = 1LL;
v4 = 2LL;
}
v6 = (char *)func0(v4);
return strncpy(v6, src, v5);
}

original_code:
char *rs_dirname(const char *path) {
  int last_slash = 0, i;
  for(i=0;path[i+1] != 0; i++) {
    if(path[i] == '/') {
      last_slash = i;
    }
  }
  int dname_len = last_slash + 1;
  char *dname = xmalloc(dname_len + 1);
  strncpy(dname, path, dname_len);
  return dname;
}

canonical_original_code:
char *rs_dirname(char *path) {
  int last_slash = 0; int i;
  for(i=0;path[i+1] != 0; i++) {
    if(path[i] == '/') {
      last_slash = i;
    }
  }
  int dname_len = last_slash + 1;
  char *dname = xmalloc(dname_len + 1);
  strncpy(dname, path, dname_len);
  return dname;
}

variable_types: i int

variable_types:
dname
char *


decompiled_code:
char *__fastcall rs_basename(__int64 a1)
{
const char *v1; // rbp
__int64 v2; // rax
int v3; // edx
int v4; // ecx
int v5; // edx
size_t v6; // r12
size_t v7; // rdi
char *v8; // rax

v1 = (const char *)a1;
if ( *(_BYTE *)(a1 + 1) )
{
v2 = a1 + 2;
v3 = 0;
v4 = 0;
do
{
if ( *(_BYTE *)(v2 - 2) == 47 )
v4 = v3;
++v2;
++v3;
}
while ( *(_BYTE *)(v2 - 1) );
v5 = v3 - v4;
v6 = v5;
v7 = v5 + 1;
v1 += v4 + 1;
}
else
{
v6 = 1LL;
v7 = 2LL;
}
v8 = (char *)xmalloc(v7);
return strncpy(v8, v1, v6);
}

original_code:
char *rs_basename(const char *path) {
  int last_slash = 0, i;
  for(i=0;path[i+1] != 0; i++) {
    if(path[i] == '/') {
      last_slash = i;
    }
  }
  if(last_slash == 0 && i == 0) {
    last_slash--;
  }
  int bname_len = i - last_slash;
  char *bname = xmalloc(bname_len + 1);
  strncpy(bname, path + last_slash + 1, bname_len);
  return bname;
}

canonical_original_code:
char *rs_basename(char *path) {
  int last_slash = 0; int i;
  for(i=0;path[i+1] != 0; i++) {
    if(path[i] == '/') {
      last_slash = i;
    }
  }
  if(last_slash == 0 && i == 0) {
    last_slash--;
  }
  int bname_len = i - last_slash;
  char *bname = xmalloc(bname_len + 1);
  strncpy(bname, path + last_slash + 1, bname_len);
  return bname;
}

variable_types:
bname
char *


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

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

original_code: int rs_mkdir(const char *path, mode_t mode) { return 0; }

canonical_original_code: int rs_mkdir(char *path, unsigned int mode) { return 0; }

variable_types:
mode
unsigned int


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

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

original_code: int rs_rmdir(const char *path) { return 0; }

canonical_original_code: int rs_rmdir(char *path) { return 0; }


decompiled_code:
__int64 __fastcall rs_flush(const char *a1)
{
log_msg("OP FLUSH %s", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
log_msg("OP FLUSH %s", a1);
return 0LL;
}

original_code:
int rs_flush(const char *path, struct fuse_file_info *fi) {
  log_msg("OP FLUSH %s", path);
  return 0;
}

canonical_original_code:
int rs_flush(char *path, struct fuse_file_info *fi) {
  log_msg("OP FLUSH %s", path);
  return 0;
}

variable_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *


decompiled_code:
__int64 __fastcall rs_create(const char *a1)
{
return rs_truncate(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
return func1(a1, 0LL);
}

original_code:
int rs_create(const char *path, mode_t mode, struct fuse_file_info *fi) {
  return rs_truncate(path, 0);
}

canonical_original_code:
int rs_create(char *path, unsigned int mode, struct fuse_file_info *fi) {
  return rs_truncate(path, 0);
}

user_defined_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; }


decompiled_code:
// attributes: thunk
__int64 rs_unlink()
{
return delete_node_remote();
}

canonical_decompiled_code:
__int64 func10()
{
return delete_node_remote();
}

original_code:
int rs_unlink(const char *path) {
  return delete_node_remote(path);
}

canonical_original_code:
int rs_unlink(char *path) {
  return delete_node_remote(path);
}


decompiled_code:
_QWORD *new_trie()
{
return new_node(0, 0LL);
}

canonical_decompiled_code:
_QWORD *func0()
{
return new_node(0, 0LL);
}

original_code:
TrieNode *new_trie() {
  return new_node(0, ((void *)0));
}

canonical_original_code:
struct trie_node *new_trie() {
  return new_node(0, ((void *)0));
}

return_type: struct trie_node { char key; char *childkeys; struct trie_node **children; void *value; } *


append

original_code:
int append(TrieNode *parent, TrieNode *child) {
  int len = strlen(parent->childkeys);
  parent->children = realloc(parent->children, (len + 1) * sizeof(TrieNode*));
  if(parent->children == ((void *)0)) {
    return -1;
  }
  parent->childkeys = realloc(parent->childkeys, len + 1);
  if(parent->childkeys == ((void *)0)) {
    return -1;
  }
  parent->children[len] = child;
  parent->childkeys[len] = child->key;
  parent->childkeys[++len] = 0;
  return 0;
}

canonical_original_code:
int append(struct trie_node *parent, struct trie_node *child) {
  int len = strlen(parent->childkeys);
  parent->children = realloc(parent->children, (len + 1) * sizeof(struct trie_node *));
  if(parent->children == ((void *)0)) {
    return -1;
  }
  parent->childkeys = realloc(parent->childkeys, len + 1);
  if(parent->childkeys == ((void *)0)) {
    return -1;
  }
  parent->children[len] = child;
  parent->childkeys[len] = child->key;
  parent->childkeys[++len] = 0;
  return 0;
}

variable_types: struct trie_node { char key; char *childkeys; struct trie_node **children; void *value; } *

variable_types:
child
struct trie_node *


decompiled_code:
__int64 __fastcall find_child(__int64 a1, char a2)
{
char *v2; // rcx
char v3; // al
__int64 v4; // rdx

v2 = *(char **)(a1 + 8);
v3 = *v2;
if ( !*v2 )
return 0LL;
v4 = 0LL;
while ( a2 != v3 )
{
v3 = v2[++v4];
if ( !v3 )
return 0LL;
}
return *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v4);
}

original_code:
TrieNode *find_child(TrieNode *node, char key) {
  char c;
  int i;
  for(i = 0; (c = node->childkeys[i]) != 0; i++) {
    if(c == key) {
      return node->children[i];
    }
  }
  return ((void *)0);
}

canonical_original_code:
struct trie_node *find_child(struct trie_node *node, char key) {
  char c;
  int i;
  for(i = 0; (c = node->childkeys[i]) != 0; i++) {
    if(c == key) {
      return node->children[i];
    }
  }
  return ((void *)0);
}

variable_types:
node
struct trie_node *

variable_types: key char

variable_types: c char

user_defined_types: struct trie_node { char key; char *childkeys; struct trie_node **children; void *value; }


decompiled_code:
__int64 __fastcall trie_insert(__int64 a1, char *a2, __int64 a3, _QWORD *a4)
{
char v5; // r8
__int64 v6; // r12
__int64 result; // rax
_BYTE *v8; // rax
unsigned int v9; // [rsp+Ch] [rbp-3Ch]
void *ptr; // [rsp+18h] [rbp-30h] BYREF

if ( *a2 )
{
v6 = find_child(a1, *a2);
if ( v6 || (v8 = new_node(v5, 0LL), (v6 = (__int64)v8) != 0) && !(unsigned int)append(a1, v8) )
{
ptr = 0LL;
result = trie_insert(v6, a2 + 1, a3, &ptr);
if ( ptr )
{
v9 = result;
free(ptr);
result = v9;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
*a4 = *(_QWORD *)(a1 + 24);
result = 0LL;
*(_QWORD *)(a1 + 24) = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char *a2, __int64 a3, _QWORD *a4)
{
char v5; // r8
__int64 v6; // r12
__int64 result; // rax
_BYTE *v8; // rax
unsigned int v9; // [rsp+Ch] [rbp-3Ch]
void *ptr; // [rsp+18h] [rbp-30h] BYREF

if ( *a2 )
{
v6 = func2(a1, *a2);
if ( v6 || (v8 = new_node(v5, 0LL), (v6 = (__int64)v8) != 0) && !(unsigned int)func1(a1, v8) )
{
ptr = 0LL;
result = func3(v6, a2 + 1, a3, &ptr);
if ( ptr )
{
v9 = result;
free(ptr);
result = v9;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
*a4 = *(_QWORD *)(a1 + 24);
result = 0LL;
*(_QWORD *)(a1 + 24) = a3;
}
return result;
}

original_code:
int trie_insert(TrieNode *parent, const char *key, void *value, void **old_value_ptr) {
  TrieNode *child;
  if(*key) {
    child = find_child(parent, *key);
    if(! child) {
      child = new_node(*key, ((void *)0));
      if(child == ((void *)0)) {
        return -1;
      }
      if(append(parent, child) != 0) {
        return -1;
      }
    }
    void *old_ptr = ((void *)0);
    int result = trie_insert(child, ++key, value, &old_ptr);
    if(old_ptr) free(old_ptr);
    return result;
  } else {
    *old_value_ptr = parent->value;
    parent->value = value;
    return 0;
  }
}

canonical_original_code:
int trie_insert(struct trie_node *parent, char *key, void *value, void **old_value_ptr) {
  struct trie_node *child;
  if(*key) {
    child = find_child(parent, *key);
    if(! child) {
      child = new_node(*key, ((void *)0));
      if(child == ((void *)0)) {
        return -1;
      }
      if(append(parent, child) != 0) {
        return -1;
      }
    }
    void *old_ptr = ((void *)0);
    int result = trie_insert(child, ++key, value, &old_ptr);
    if(old_ptr) free(old_ptr);
    return result;
  } else {
    *old_value_ptr = parent->value;
    parent->value = value;
    return 0;
  }
}

variable_types:
key
char *

variable_types:
value
void *

variable_types: result int


decompiled_code:
__int64 __fastcall trie_search(__int64 a1, char *a2)
{
char v2; // si
__int64 v3; // r8

v2 = *a2;
if ( !v2 )
return *(_QWORD *)(a1 + 24);
while ( 1 )
{
a1 = find_child(a1, v2);
if ( !a1 )
break;
v2 = *(_BYTE *)(v3 + 1);
if ( !v2 )
return *(_QWORD *)(a1 + 24);
}
return 0LL;
}

original_code:
void *trie_search(TrieNode *parent, const char *key) {
  TrieNode *child;
  if(*key) {
    child = find_child(parent, *key);
    if(child) {
      return trie_search(child, ++key);
    } else {
      return ((void *)0);
    }
  } else {
    return parent->value;
  }
}

canonical_original_code:
void *trie_search(struct trie_node *parent, char *key) {
  struct trie_node *child;
  if(*key) {
    child = find_child(parent, *key);
    if(child) {
      return trie_search(child, ++key);
    } else {
      return ((void *)0);
    }
  } else {
    return parent->value;
  }
}


decompiled_code:
void __fastcall destroy_trie(void *ptr)
{
char *v2; // r12
int v3; // eax
__int64 v4; // rbx
__int64 v5; // r12
void *v6; // rdi
void *v7; // rdi

v2 = (char *)*((_QWORD *)ptr + 1);
v3 = strlen(v2);
if ( v3 <= 0 )
goto LABEL_8;
v4 = 0LL;
v5 = 8LL * (unsigned int)(v3 - 1) + 8;
do
{
v6 = *(void **)(*((_QWORD *)ptr + 2) + v4);
v4 += 8LL;
destroy_trie(v6);
}
while ( v4 != v5 );
v2 = (char *)*((_QWORD *)ptr + 1);
if ( v2 )
LABEL_8:
free(v2);
v7 = (void *)*((_QWORD *)ptr + 2);
if ( v7 )
free(v7);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
char *v2; // r12
int v3; // eax
__int64 v4; // rbx
__int64 v5; // r12
void *v6; // rdi
void *v7; // rdi

v2 = (char *)*((_QWORD *)ptr + 1);
v3 = strlen(v2);
if ( v3 <= 0 )
goto LABEL_8;
v4 = 0LL;
v5 = 8LL * (unsigned int)(v3 - 1) + 8;
do
{
v6 = *(void **)(*((_QWORD *)ptr + 2) + v4);
v4 += 8LL;
func5(v6);
}
while ( v4 != v5 );
v2 = (char *)*((_QWORD *)ptr + 1);
if ( v2 )
LABEL_8:
free(v2);
v7 = (void *)*((_QWORD *)ptr + 2);
if ( v7 )
free(v7);
free(ptr);
}

original_code:
void destroy_trie(TrieNode *root) {
  int len = strlen(root->childkeys);
  int i;
  for(i=0;i<len;i++) {
    destroy_trie(root->children[i]);
  }
  if(root->childkeys) {
    free(root->childkeys);
  }
  if(root->children) {
    free(root->children);
  }
  free(root);
}

canonical_original_code:
void destroy_trie(struct trie_node *root) {
  int len = strlen(root->childkeys);
  int i;
  for(i=0;i<len;i++) {
    destroy_trie(root->children[i]);
  }
  if(root->childkeys) {
    free(root->childkeys);
  }
  if(root->children) {
    free(root->children);
  }
  free(root);
}


repo: remotestorage/rs-serve

decompiled_code:
int test_pack_unpack()
{
const char *v1; // [rsp+0h] [rbp-A8h] BYREF
char v2; // [rsp+8h] [rbp-A0h]
void *v3; // [rsp+10h] [rbp-98h] BYREF
char v4; // [rsp+18h] [rbp-90h]
__int64 v5[2]; // [rsp+20h] [rbp-88h] BYREF
__int64 v6[2]; // [rsp+30h] [rbp-78h] BYREF
int v7; // [rsp+40h] [rbp-68h]
__int64 *v8; // [rsp+48h] [rbp-60h]
const char *v9[2]; // [rsp+50h] [rbp-58h] BYREF
int v10; // [rsp+60h] [rbp-48h]
__int64 v11; // [rsp+68h] [rbp-40h]
__int128 v12[2]; // [rsp+70h] [rbp-38h] BYREF
__int64 v13; // [rsp+90h] [rbp-18h]

v12[0] = 0LL;
v5[1] = (__int64)&v3;
v8 = v5;
v12[1] = 0LL;
v1 = "contacts";
v2 = 1;
v3 = &unk_29C;
v4 = 0;
v5[0] = (__int64)&v1;
v6[0] = (__int64)"foo";
v6[1] = (__int64)"bar";
v7 = 2;
v13 = 0LL;
pack_authorization(v12, v6);
unpack_authorization(v9, v12);
if ( strcmp(v9[0], "foo") )
{
printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.username", "\"foo\"", "test/unit/common/auth.c", 57LL);
abort();
}
putchar(46);
if ( strcmp(v9[1], "bar") )
{
printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.token", "\"bar\"", "test/unit/common/auth.c", 58LL);
abort();
}
putchar(46);
if ( v10 != 2 )
{
printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.scopes.count", "2", "test/unit/common/auth.c", 59LL);
abort();
}
putchar(46);
if ( strcmp(**(const char ***)v11, "contacts") )
{
printf(
"\nAssertion failed: %s != %s (%s:%d)\n",
"dest_auth.scopes.ptr[0]->name",
"\"contacts\"",
"test/unit/common/auth.c",
60LL);
abort();
}
putchar(46);
if ( *(_BYTE *)(*(_QWORD *)v11 + 8LL) != 1 )
{
printf(
"\nAssertion failed: %s != %s (%s:%d)\n",
"dest_auth.scopes.ptr[0]->write",
"1",
"test/unit/common/auth.c",
61LL);
abort();
}
putchar(46);
if ( ***(_BYTE ***)(v11 + 8) )
{
printf(
"\nAssertion failed: %s != %s (%s:%d)\n",
"dest_auth.scopes.ptr[1]->name",
"\"\"",
"test/unit/common/auth.c",
62LL);
abort();
}
putchar(46);
if ( *(_BYTE *)(*(_QWORD *)(v11 + 8) + 8LL) )
{
printf(
"\nAssertion failed: %s != %s (%s:%d)\n",
"dest_auth.scopes.ptr[1]->write",
"0",
"test/unit/common/auth.c",
63LL);
abort();
}
return putchar(46);
}

canonical_decompiled_code:
int func0()
{
const char *v1; // [rsp+0h] [rbp-A8h] BYREF
char v2; // [rsp+8h] [rbp-A0h]
void *v3; // [rsp+10h] [rbp-98h] BYREF
char v4; // [rsp+18h] [rbp-90h]
__int64 v5[2]; // [rsp+20h] [rbp-88h] BYREF
__int64 v6[2]; // [rsp+30h] [rbp-78h] BYREF
int v7; // [rsp+40h] [rbp-68h]
__int64 *v8; // [rsp+48h] [rbp-60h]
const char *v9[2]; // [rsp+50h] [rbp-58h] BYREF
int v10; // [rsp+60h] [rbp-48h]
__int64 v11; // [rsp+68h] [rbp-40h]
__int128 v12[2]; // [rsp+70h] [rbp-38h] BYREF
__int64 v13; // [rsp+90h] [rbp-18h]

v12[0] = 0LL;
v5[1] = (__int64)&v3;
v8 = v5;
v12[1] = 0LL;
v1 = "contacts";
v2 = 1;
v3 = &unk_29C;
v4 = 0;
v5[0] = (__int64)&v1;
v6[0] = (__int64)"foo";
v6[1] = (__int64)"bar";
v7 = 2;
v13 = 0LL;
pack_authorization(v12, v6);
unpack_authorization(v9, v12);
if ( strcmp(v9[0], "foo") )
{
printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.username", "\"foo\"", "test/unit/common/auth.c", 57LL);
abort();
}
putchar(46);
if ( strcmp(v9[1], "bar") )
{
printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.token", "\"bar\"", "test/unit/common/auth.c", 58LL);
abort();
}
putchar(46);
if ( v10 != 2 )
{
printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.scopes.count", "2", "test/unit/common/auth.c", 59LL);
abort();
}
putchar(46);
if ( strcmp(**(const char ***)v11, "contacts") )
{
printf(
"\nAssertion failed: %s != %s (%s:%d)\n",
"dest_auth.scopes.ptr[0]->name",
"\"contacts\"",
"test/unit/common/auth.c",
60LL);
abort();
}
putchar(46);
if ( *(_BYTE *)(*(_QWORD *)v11 + 8LL) != 1 )
{
printf(
"\nAssertion failed: %s != %s (%s:%d)\n",
"dest_auth.scopes.ptr[0]->write",
"1",
"test/unit/common/auth.c",
61LL);
abort();
}
putchar(46);
if ( ***(_BYTE ***)(v11 + 8) )
{
printf(
"\nAssertion failed: %s != %s (%s:%d)\n",
"dest_auth.scopes.ptr[1]->name",
"\"\"",
"test/unit/common/auth.c",
62LL);
abort();
}
putchar(46);
if ( *(_BYTE *)(*(_QWORD *)(v11 + 8) + 8LL) )
{
printf(
"\nAssertion failed: %s != %s (%s:%d)\n",
"dest_auth.scopes.ptr[1]->write",
"0",
"test/unit/common/auth.c",
63LL);
abort();
}
return putchar(46);
}

original_code:
void test_pack_unpack() {
  struct rs_scope contacts = { .name = "contacts", .write = 1 };
  struct rs_scope root = { .name = "", .write = 0 };
  struct rs_scope *scope_ptr[2] = { &contacts, &root };
  struct rs_authorization src_auth = {
    .username = "foo",
    .token = "bar",
    .scopes = {
      .count = 2,
      .ptr = scope_ptr
    }
  };
  DBT dbt;
  memset(&dbt, 0, sizeof(DBT));
  pack_authorization(&dbt, &src_auth);
  struct rs_authorization dest_auth;
  unpack_authorization(&dest_auth, &dbt);
  if(strcmp((dest_auth.username), ("foo")) == 0) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.username", "\"foo\"", "test/unit/common/auth.c", 57); abort(); }; };
  if(strcmp((dest_auth.token), ("bar")) == 0) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.token", "\"bar\"", "test/unit/common/auth.c", 58); abort(); }; };
  if((dest_auth.scopes.count) == (2)) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.scopes.count", "2", "test/unit/common/auth.c", 59); abort(); }; };
  if(strcmp((dest_auth.scopes.ptr[0]->name), ("contacts")) == 0) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.scopes.ptr[0]->name", "\"contacts\"", "test/unit/common/auth.c", 60); abort(); }; };
  if((dest_auth.scopes.ptr[0]->write) == (1)) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.scopes.ptr[0]->write", "1", "test/unit/common/auth.c", 61); abort(); }; };
  if(strcmp((dest_auth.scopes.ptr[1]->name), ("")) == 0) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.scopes.ptr[1]->name", "\"\"", "test/unit/common/auth.c", 62); abort(); }; };
  if((dest_auth.scopes.ptr[1]->write) == (0)) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.scopes.ptr[1]->write", "0", "test/unit/common/auth.c", 63); abort(); }; };
}

canonical_original_code:
void test_pack_unpack() {
  struct rs_scope contacts = { .name = "contacts", .write = 1 };
  struct rs_scope root = { .name = "", .write = 0 };
  struct rs_scope *scope_ptr[2] = { &contacts, &root };
  struct rs_authorization src_auth = {
    .username = "foo",
    .token = "bar",
    .scopes = {
      .count = 2,
      .ptr = scope_ptr
    }
  };
  struct __db_dbt dbt;
  memset(&dbt, 0, sizeof(DBT));
  pack_authorization(&dbt, &src_auth);
  struct rs_authorization dest_auth;
  unpack_authorization(&dest_auth, &dbt);
  if(strcmp((dest_auth.username), ("foo")) == 0) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.username", "\"foo\"", "test/unit/common/auth.c", 57); abort(); }; };
  if(strcmp((dest_auth.token), ("bar")) == 0) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.token", "\"bar\"", "test/unit/common/auth.c", 58); abort(); }; };
  if((dest_auth.scopes.count) == (2)) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.scopes.count", "2", "test/unit/common/auth.c", 59); abort(); }; };
  if(strcmp((dest_auth.scopes.ptr[0]->name), ("contacts")) == 0) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.scopes.ptr[0]->name", "\"contacts\"", "test/unit/common/auth.c", 60); abort(); }; };
  if((dest_auth.scopes.ptr[0]->write) == (1)) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.scopes.ptr[0]->write", "1", "test/unit/common/auth.c", 61); abort(); }; };
  if(strcmp((dest_auth.scopes.ptr[1]->name), ("")) == 0) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.scopes.ptr[1]->name", "\"\"", "test/unit/common/auth.c", 62); abort(); }; };
  if((dest_auth.scopes.ptr[1]->write) == (0)) { printf("."); } else { { printf("\nAssertion failed: %s != %s (%s:%d)\n", "dest_auth.scopes.ptr[1]->write", "0", "test/unit/common/auth.c", 63); abort(); }; };
}

variable_types: struct rs_scope { char *name; char write; } *[2]

variable_types: struct rs_authorization { char *username; char *token; struct rs_scopes { unsigned int count; struct rs_scope { char *name; char write; } **ptr; } scopes; }

variable_types: struct __db_dbt { void *data; unsigned int size; unsigned int ulen; unsigned int dlen; unsigned int doff; void *app_data; unsigned int flags; }

user_defined_types: struct rs_authorization { char *username; char *token; struct rs_scopes scopes; }

user_defined_types: struct rs_scopes { unsigned int count; struct rs_scope **ptr; }


decompiled_code:
void test_store_lookup()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void test_store_lookup() {
}

canonical_original_code:
void test_store_lookup() {
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("\nSuite: %s\n", "Authorization model");
printf(" Test: %s ", "packing / unpacking");
test_pack_unpack();
puts(" OK.\n");
printf(" Test: %s ", "store / lookup");
puts(" OK.\n");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("\nSuite: %s\n", "Authorization model");
printf(" Test: %s ", "packing / unpacking");
func0();
puts(" OK.\n");
printf(" Test: %s ", "store / lookup");
puts(" OK.\n");
return 0;
}

original_code:
int main(int argc, char **argv) {
  { printf("\nSuite: %s\n", "Authorization model"); };
  { printf("  Test: %s ", "packing / unpacking"); test_pack_unpack(); printf(" OK.\n\n"); };
  { printf("  Test: %s ", "store / lookup"); test_store_lookup(); printf(" OK.\n\n"); };
}

variable_types: argc int

variable_types:
argv
char **


DecideMethod

decompiled_code:
__int64 __fastcall DecideMethod(char *a1, int a2, __int64 a3, __int64 a4, unsigned int a5)
{
char v5; // dl
__int64 v6; // rax
int v7; // ecx

v5 = *a1;
if ( *a1 == 32 || a2 <= 0 )
return a5;
v6 = 0LL;
do
{
if ( v6 )
{
if ( a5 == 1 )
{
if ( byte_90D[v6] != v5 )
goto LABEL_14;
goto LABEL_8;
}
if ( a5 == 2 )
{
if ( byte_911[v6] != v5 )
goto LABEL_14;
goto LABEL_8;
}
if ( byte_916[v6] != v5 )
goto LABEL_14;
goto LABEL_7;
}
if ( v5 != 71 )
{
if ( v5 == 80 )
{
a5 = 2;
LABEL_8:
v7 = ++v6;
v5 = a1[v6];
if ( a2 <= (int)v6 )
break;
continue;
}
if ( v5 != 79 )
goto LABEL_14;
LABEL_7:
a5 = 3;
goto LABEL_8;
}
v7 = 1;
v6 = 1LL;
a5 = 1;
v5 = a1[1];
if ( a2 <= 1 )
break;
}
while ( v5 != 32 );
if ( v7 > 7 )
{
LABEL_14:
puts("Non-recognized method");
return 0xFFFFFFFFLL;
}
return a5;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, int a2, __int64 a3, __int64 a4, unsigned int a5)
{
char v5; // dl
__int64 v6; // rax
int v7; // ecx

v5 = *a1;
if ( *a1 == 32 || a2 <= 0 )
return a5;
v6 = 0LL;
do
{
if ( v6 )
{
if ( a5 == 1 )
{
if ( byte_90D[v6] != v5 )
goto LABEL_14;
goto LABEL_8;
}
if ( a5 == 2 )
{
if ( byte_911[v6] != v5 )
goto LABEL_14;
goto LABEL_8;
}
if ( byte_916[v6] != v5 )
goto LABEL_14;
goto LABEL_7;
}
if ( v5 != 71 )
{
if ( v5 == 80 )
{
a5 = 2;
LABEL_8:
v7 = ++v6;
v5 = a1[v6];
if ( a2 <= (int)v6 )
break;
continue;
}
if ( v5 != 79 )
goto LABEL_14;
LABEL_7:
a5 = 3;
goto LABEL_8;
}
v7 = 1;
v6 = 1LL;
a5 = 1;
v5 = a1[1];
if ( a2 <= 1 )
break;
}
while ( v5 != 32 );
if ( v7 > 7 )
{
LABEL_14:
puts("Non-recognized method");
return 0xFFFFFFFFLL;
}
return a5;
}

original_code:
int DecideMethod (char * firstLine, int l)
{
 int method;
 int i = 0;
 char *p, *g, *o;
 p = "POST";
 g = "GET";
 o = "OPTIONS";
 while(firstLine[i] != ' ' && i < l)
 {
  if(i == 0)
  {
   if(firstLine[i] == 'G')
   {
    method = 1;
   }
   else
    if(firstLine[i] == 'P')
    {
     method = 2;
    }
   else
    if(firstLine[i] == 'O')
    {
     method = 3;
    }
   else
   {
    printf("Non-recognized method\n");
    return -1;
   }
  }
  else
  {
   if(method == 1 && firstLine[i] != g[i])
   {
    printf("Non-recognized method\n");
    return -1;
   }
   if(method == 2 && firstLine[i] != p[i])
   {
    printf("Non-recognized method\n");
    return -1;
   }
   if(method == 3 && firstLine[i] != o[i])
   {
    printf("Non-recognized method\n");
    return -1;
   }
  }
  i++;
 }
 if (i > 7)
 {
  printf("Non-recognized method\n");
  return -1;
 }
 return method;
}

canonical_original_code:
int DecideMethod(char *firstLine, int l)
{
 int method;
 int i = 0;
 char *p; char *g; char *o;
 p = "POST";
 g = "GET";
 o = "OPTIONS";
 while(firstLine[i] != ' ' && i < l)
 {
  if(i == 0)
  {
   if(firstLine[i] == 'G')
   {
    method = 1;
   }
   else
    if(firstLine[i] == 'P')
    {
     method = 2;
    }
   else
    if(firstLine[i] == 'O')
    {
     method = 3;
    }
   else
   {
    printf("Non-recognized method\n");
    return -1;
   }
  }
  else
  {
   if(method == 1 && firstLine[i] != g[i])
   {
    printf("Non-recognized method\n");
    return -1;
   }
   if(method == 2 && firstLine[i] != p[i])
   {
    printf("Non-recognized method\n");
    return -1;
   }
   if(method == 3 && firstLine[i] != o[i])
   {
    printf("Non-recognized method\n");
    return -1;
   }
  }
  i++;
 }
 if (i > 7)
 {
  printf("Non-recognized method\n");
  return -1;
 }
 return method;
}

variable_types:
firstLine
char *

variable_types: l int

variable_types: method int

variable_types: i int

variable_types:
p
char *

variable_types:
g
char *

variable_types:
o
char *