PrintTable

original_code:
void PrintTable(MacroTable* macroTable){
    int i = 0;
    int j = 0;
    for(i=0;i<macroTable->last_; i++){
        for(j=0;j<macroTable->macros_[i]->last_; j++){
            printf("name: %s parameter: %s info: %s %s parametro:%d\n", macroTable->macros_[i]->name_ ,
  macroTable->macros_[i]->parameter_ ,macroTable->macros_[i]->instruc_[j],
   macroTable->macros_[i]->oper_[j],macroTable->macros_[i]->has_parameter_);
        }
    }
}

canonical_original_code:
void PrintTable(struct macroTable *macroTable){
    int i = 0;
    int j = 0;
    for(i=0;i<macroTable->last_; i++){
        for(j=0;j<macroTable->macros_[i]->last_; j++){
            printf("name: %s parameter: %s info: %s %s parametro:%d\n", macroTable->macros_[i]->name_ ,
  macroTable->macros_[i]->parameter_ ,macroTable->macros_[i]->instruc_[j],
   macroTable->macros_[i]->oper_[j],macroTable->macros_[i]->has_parameter_);
        }
    }
}

variable_types: j int


IsLabel

repo: thaliacampolina/sb

decompiled_code:
__int64 __fastcall IsLabel(char *a1)
{
char v1; // al
char *v2; // rdi

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
while ( v1 != 58 )
{
v1 = *v2++;
if ( !v1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
char v1; // al
char *v2; // rdi

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
while ( v1 != 58 )
{
v1 = *v2++;
if ( !v1 )
return 0LL;
}
return 1LL;
}

original_code:
int IsLabel(char* str){
    int i = 0;
    while(str[i]){
        if(str[i] == ':'){
            return 1;
        }
        i++;
    }
    return 0;
}

canonical_original_code:
int IsLabel(char *str){
    int i = 0;
    while(str[i]){
        if(str[i] == ':'){
            return 1;
        }
        i++;
    }
    return 0;
}

variable_types:
str
char *

variable_types: i int

return_type: int


IsKeyword

decompiled_code:
__int64 __fastcall IsKeyword(char *s1)
{
unsigned int v1; // er9
__int64 result; // rax

v1 = 2;
if ( !strcmp(s1, "LOAD")
|| !strcmp(s1, "STORE")
|| !strcmp(s1, "PUSH")
|| !strcmp(s1, "POP")
|| !strcmp(s1, "JMP")
|| !strcmp(s1, "JPG")
|| !strcmp(s1, "JPGE")
|| !strcmp(s1, "JPL")
|| !strcmp(s1, "JPLE")
|| !strcmp(s1, "JPE")
|| !strcmp(s1, "JPNE")
|| !strcmp(s1, "XOR")
|| !strcmp(s1, "AND")
|| *s1 == 79 && s1[1] == 82 && !s1[2]
|| (v1 = 1, !strcmp(s1, "NOT"))
|| (v1 = 2, !strcmp(s1, "ADD"))
|| !strcmp(s1, "SUB")
|| !strcmp(s1, "READ")
|| !strcmp(s1, "WRITE")
|| !strcmp(s1, "CALL")
|| (v1 = 1, !strcmp(s1, "RET"))
|| !strcmp(s1, "HALT")
|| (v1 = 2, !strcmp(s1, "WORD"))
|| (v1 = 1, !strcmp(s1, "END"))
|| !strcmp(s1, "ENDMACRO") )
{
result = v1;
}
else
{
result = strcmp(s1, "BEGINMACRO") == 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *s1)
{
unsigned int v1; // er9
__int64 result; // rax

v1 = 2;
if ( !strcmp(s1, "LOAD")
|| !strcmp(s1, "STORE")
|| !strcmp(s1, "PUSH")
|| !strcmp(s1, "POP")
|| !strcmp(s1, "JMP")
|| !strcmp(s1, "JPG")
|| !strcmp(s1, "JPGE")
|| !strcmp(s1, "JPL")
|| !strcmp(s1, "JPLE")
|| !strcmp(s1, "JPE")
|| !strcmp(s1, "JPNE")
|| !strcmp(s1, "XOR")
|| !strcmp(s1, "AND")
|| *s1 == 79 && s1[1] == 82 && !s1[2]
|| (v1 = 1, !strcmp(s1, "NOT"))
|| (v1 = 2, !strcmp(s1, "ADD"))
|| !strcmp(s1, "SUB")
|| !strcmp(s1, "READ")
|| !strcmp(s1, "WRITE")
|| !strcmp(s1, "CALL")
|| (v1 = 1, !strcmp(s1, "RET"))
|| !strcmp(s1, "HALT")
|| (v1 = 2, !strcmp(s1, "WORD"))
|| (v1 = 1, !strcmp(s1, "END"))
|| !strcmp(s1, "ENDMACRO") )
{
result = v1;
}
else
{
result = strcmp(s1, "BEGINMACRO") == 0;
}
return result;
}

original_code:
int IsKeyword(char* instruc){
    if(strcmp(instruc,"LOAD")==0) return 2;
    if(strcmp(instruc,"STORE")==0) return 2;
    if(strcmp(instruc,"PUSH")==0) return 2;
    if(strcmp(instruc,"POP")==0) return 2;
    if(strcmp(instruc,"JMP")==0) return 2;
    if(strcmp(instruc,"JPG")==0) return 2;
    if(strcmp(instruc,"JPGE")==0) return 2;
    if(strcmp(instruc,"JPL")==0) return 2;
    if(strcmp(instruc,"JPLE")==0) return 2;
    if(strcmp(instruc,"JPE")==0) return 2;
    if(strcmp(instruc,"JPNE")==0) return 2;
    if(strcmp(instruc,"XOR")==0) return 2;
    if(strcmp(instruc,"AND")==0) return 2;
    if(strcmp(instruc,"OR")==0) return 2;
    if(strcmp(instruc,"NOT")==0) return 1;
    if(strcmp(instruc,"ADD")==0) return 2;
    if(strcmp(instruc,"SUB")==0) return 2;
    if(strcmp(instruc,"READ")==0) return 2;
    if(strcmp(instruc,"WRITE")==0) return 2;
    if(strcmp(instruc,"CALL")==0) return 2;
    if(strcmp(instruc,"RET")==0) return 1;
    if(strcmp(instruc,"HALT")==0) return 1;
    if(strcmp(instruc,"WORD")==0) return 2;
    if(strcmp(instruc,"END")==0) return 1;
    if(strcmp(instruc,"ENDMACRO")==0) return 1;
    if(strcmp(instruc,"BEGINMACRO")==0) return 1;
    return 0;
}

canonical_original_code:
int IsKeyword(char *instruc){
    if(strcmp(instruc,"LOAD")==0) return 2;
    if(strcmp(instruc,"STORE")==0) return 2;
    if(strcmp(instruc,"PUSH")==0) return 2;
    if(strcmp(instruc,"POP")==0) return 2;
    if(strcmp(instruc,"JMP")==0) return 2;
    if(strcmp(instruc,"JPG")==0) return 2;
    if(strcmp(instruc,"JPGE")==0) return 2;
    if(strcmp(instruc,"JPL")==0) return 2;
    if(strcmp(instruc,"JPLE")==0) return 2;
    if(strcmp(instruc,"JPE")==0) return 2;
    if(strcmp(instruc,"JPNE")==0) return 2;
    if(strcmp(instruc,"XOR")==0) return 2;
    if(strcmp(instruc,"AND")==0) return 2;
    if(strcmp(instruc,"OR")==0) return 2;
    if(strcmp(instruc,"NOT")==0) return 1;
    if(strcmp(instruc,"ADD")==0) return 2;
    if(strcmp(instruc,"SUB")==0) return 2;
    if(strcmp(instruc,"READ")==0) return 2;
    if(strcmp(instruc,"WRITE")==0) return 2;
    if(strcmp(instruc,"CALL")==0) return 2;
    if(strcmp(instruc,"RET")==0) return 1;
    if(strcmp(instruc,"HALT")==0) return 1;
    if(strcmp(instruc,"WORD")==0) return 2;
    if(strcmp(instruc,"END")==0) return 1;
    if(strcmp(instruc,"ENDMACRO")==0) return 1;
    if(strcmp(instruc,"BEGINMACRO")==0) return 1;
    return 0;
}

variable_types:
instruc
char *


CreateSymbol

decompiled_code:
char *__fastcall CreateSymbol(__int64 a1, const char *a2, int a3)
{
char *v4; // rax
char *result; // rax

v4 = (char *)calloc(0x64uLL, 1uLL);
*(_QWORD *)a1 = v4;
result = strcpy(v4, a2);
*(_DWORD *)(a1 + 8) = a3;
return result;
}

canonical_decompiled_code:
char *__fastcall func8(__int64 a1, const char *a2, int a3)
{
char *v4; // rax
char *result; // rax

v4 = (char *)calloc(0x64uLL, 1uLL);
*(_QWORD *)a1 = v4;
result = strcpy(v4, a2);
*(_DWORD *)(a1 + 8) = a3;
return result;
}

original_code:
void CreateSymbol(Symbol* symbol,char* name, int ILC){
    symbol->name_=(char*)calloc(100,sizeof(char));
    strcpy(symbol->name_,name);
    symbol->value_=ILC;
}

canonical_original_code:
void CreateSymbol(struct symbol *symbol, char *name, int ILC){
    symbol->name_=(char *)calloc(100,sizeof(char));
    strcpy(symbol->name_,name);
    symbol->value_=ILC;
}

variable_types: struct symbol { char *name_; int value_; } *

variable_types:
name
char *

variable_types: ILC int

return_type: void


InsertSymbolInTable

decompiled_code:
__int64 __fastcall InsertSymbolInTable(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 800);
*(_QWORD *)(a1 + 8LL * v2) = a2;
result = (unsigned int)(v2 + 1);
*(_DWORD *)(a1 + 800) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 800);
*(_QWORD *)(a1 + 8LL * v2) = a2;
result = (unsigned int)(v2 + 1);
*(_DWORD *)(a1 + 800) = result;
return result;
}

original_code:
void InsertSymbolInTable(Table* table, Symbol* symbol){
    table->symbol_[table->last_]=symbol;
    table->last_++;
}

canonical_original_code:
void InsertSymbolInTable(struct table *table, struct symbol *symbol){
    table->symbol_[table->last_]=symbol;
    table->last_++;
}

variable_types: struct table { struct symbol { char *name_; int value_; } *symbol_[100]; int last_; } *

variable_types:
symbol
struct symbol *

user_defined_types: struct table { struct symbol *symbol_[100]; int last_; }


IncreaseILC

decompiled_code:
__int64 __fastcall IncreaseILC(int a1, __int64 a2)
{
int v2; // eax
int v3; // eax
_BOOL4 v4; // ett
int v5; // eax
_BOOL4 v6; // ett
_BOOL4 v7; // ett

v2 = a1;
if ( !strcmp((const char *)a2, "LOAD") )
v2 = a1 + 2;
if ( !strcmp((const char *)a2, "STORE") )
v2 += 2;
if ( !strcmp((const char *)a2, "PUSH") )
v2 += 2;
if ( !strcmp((const char *)a2, "POP") )
v2 += 2;
if ( !strcmp((const char *)a2, "JMP") )
v2 += 2;
if ( !strcmp((const char *)a2, "JPG") )
v2 += 2;
if ( !strcmp((const char *)a2, "JPGE") )
v2 += 2;
if ( !strcmp((const char *)a2, "JPL") )
v2 += 2;
if ( !strcmp((const char *)a2, "JPLE") )
v2 += 2;
if ( !strcmp((const char *)a2, "JPE") )
v2 += 2;
if ( !strcmp((const char *)a2, "JPNE") )
v2 += 2;
if ( !strcmp((const char *)a2, "XOR") )
v2 += 2;
if ( !strcmp((const char *)a2, "AND") )
v2 += 2;
if ( *(_BYTE *)a2 == 79 && *(_BYTE *)(a2 + 1) == 82 && !*(_BYTE *)(a2 + 2) )
v2 += 2;
v4 = strcmp((const char *)a2, "NOT") == 0;
v3 = v4 + v2;
if ( !strcmp((const char *)a2, "ADD") )
v3 += 2;
if ( !strcmp((const char *)a2, "SUB") )
v3 += 2;
if ( !strcmp((const char *)a2, "READ") )
v3 += 2;
if ( !strcmp((const char *)a2, "WRITE") )
v3 += 2;
if ( !strcmp((const char *)a2, "CALL") )
v3 += 2;
v6 = strcmp((const char *)a2, "RET") == 0;
v5 = v6 + v3;
v7 = strcmp((const char *)a2, "HALT") == 0;
return (unsigned int)(strcmp((const char *)a2, "WORD") == 0) + v7 + v5;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, __int64 a2)
{
int v2; // eax
int v3; // eax
_BOOL4 v4; // ett
int v5; // eax
_BOOL4 v6; // ett
_BOOL4 v7; // ett

v2 = a1;
if ( !strcmp((const char *)a2, "LOAD") )
v2 = a1 + 2;
if ( !strcmp((const char *)a2, "STORE") )
v2 += 2;
if ( !strcmp((const char *)a2, "PUSH") )
v2 += 2;
if ( !strcmp((const char *)a2, "POP") )
v2 += 2;
if ( !strcmp((const char *)a2, "JMP") )
v2 += 2;
if ( !strcmp((const char *)a2, "JPG") )
v2 += 2;
if ( !strcmp((const char *)a2, "JPGE") )
v2 += 2;
if ( !strcmp((const char *)a2, "JPL") )
v2 += 2;
if ( !strcmp((const char *)a2, "JPLE") )
v2 += 2;
if ( !strcmp((const char *)a2, "JPE") )
v2 += 2;
if ( !strcmp((const char *)a2, "JPNE") )
v2 += 2;
if ( !strcmp((const char *)a2, "XOR") )
v2 += 2;
if ( !strcmp((const char *)a2, "AND") )
v2 += 2;
if ( *(_BYTE *)a2 == 79 && *(_BYTE *)(a2 + 1) == 82 && !*(_BYTE *)(a2 + 2) )
v2 += 2;
v4 = strcmp((const char *)a2, "NOT") == 0;
v3 = v4 + v2;
if ( !strcmp((const char *)a2, "ADD") )
v3 += 2;
if ( !strcmp((const char *)a2, "SUB") )
v3 += 2;
if ( !strcmp((const char *)a2, "READ") )
v3 += 2;
if ( !strcmp((const char *)a2, "WRITE") )
v3 += 2;
if ( !strcmp((const char *)a2, "CALL") )
v3 += 2;
v6 = strcmp((const char *)a2, "RET") == 0;
v5 = v6 + v3;
v7 = strcmp((const char *)a2, "HALT") == 0;
return (unsigned int)(strcmp((const char *)a2, "WORD") == 0) + v7 + v5;
}

original_code:
int IncreaseILC(int ILC, char* instruc){
    if(strcmp(instruc,"LOAD")==0)ILC=ILC+2;
    if(strcmp(instruc,"STORE")==0)ILC=ILC+2;
    if(strcmp(instruc,"PUSH")==0)ILC=ILC+2;
    if(strcmp(instruc,"POP")==0)ILC=ILC+2;
    if(strcmp(instruc,"JMP")==0)ILC=ILC+2;
    if(strcmp(instruc,"JPG")==0)ILC=ILC+2;
    if(strcmp(instruc,"JPGE")==0)ILC=ILC+2;
    if(strcmp(instruc,"JPL")==0)ILC=ILC+2;
    if(strcmp(instruc,"JPLE")==0)ILC=ILC+2;
    if(strcmp(instruc,"JPE")==0)ILC=ILC+2;
    if(strcmp(instruc,"JPNE")==0)ILC=ILC+2;
    if(strcmp(instruc,"XOR")==0)ILC=ILC+2;
    if(strcmp(instruc,"AND")==0)ILC=ILC+2;
    if(strcmp(instruc,"OR")==0)ILC=ILC+2;
    if(strcmp(instruc,"NOT")==0)ILC=ILC+1;
    if(strcmp(instruc,"ADD")==0)ILC=ILC+2;
    if(strcmp(instruc,"SUB")==0)ILC=ILC+2;
    if(strcmp(instruc,"READ")==0)ILC=ILC+2;
    if(strcmp(instruc,"WRITE")==0)ILC=ILC+2;
    if(strcmp(instruc,"CALL")==0)ILC=ILC+2;
    if(strcmp(instruc,"RET")==0)ILC=ILC+1;
    if(strcmp(instruc,"HALT")==0)ILC=ILC+1;
    if(strcmp(instruc,"WORD")==0)ILC=ILC+1;
    return(ILC);
}

canonical_original_code:
int IncreaseILC(int ILC, char *instruc){
    if(strcmp(instruc,"LOAD")==0)ILC=ILC+2;
    if(strcmp(instruc,"STORE")==0)ILC=ILC+2;
    if(strcmp(instruc,"PUSH")==0)ILC=ILC+2;
    if(strcmp(instruc,"POP")==0)ILC=ILC+2;
    if(strcmp(instruc,"JMP")==0)ILC=ILC+2;
    if(strcmp(instruc,"JPG")==0)ILC=ILC+2;
    if(strcmp(instruc,"JPGE")==0)ILC=ILC+2;
    if(strcmp(instruc,"JPL")==0)ILC=ILC+2;
    if(strcmp(instruc,"JPLE")==0)ILC=ILC+2;
    if(strcmp(instruc,"JPE")==0)ILC=ILC+2;
    if(strcmp(instruc,"JPNE")==0)ILC=ILC+2;
    if(strcmp(instruc,"XOR")==0)ILC=ILC+2;
    if(strcmp(instruc,"AND")==0)ILC=ILC+2;
    if(strcmp(instruc,"OR")==0)ILC=ILC+2;
    if(strcmp(instruc,"NOT")==0)ILC=ILC+1;
    if(strcmp(instruc,"ADD")==0)ILC=ILC+2;
    if(strcmp(instruc,"SUB")==0)ILC=ILC+2;
    if(strcmp(instruc,"READ")==0)ILC=ILC+2;
    if(strcmp(instruc,"WRITE")==0)ILC=ILC+2;
    if(strcmp(instruc,"CALL")==0)ILC=ILC+2;
    if(strcmp(instruc,"RET")==0)ILC=ILC+1;
    if(strcmp(instruc,"HALT")==0)ILC=ILC+1;
    if(strcmp(instruc,"WORD")==0)ILC=ILC+1;
    return(ILC);
}


decompiled_code:
char *__fastcall Remove2P(char *a1)
{
return strtok(a1, ":");
}

canonical_decompiled_code:
char *__fastcall func11(char *a1)
{
return strtok(a1, ":");
}

original_code:
char* Remove2P(char* str){
    return strtok(str,":");
}

canonical_original_code:
char *Remove2P(char *str){
    return strtok(str,":");
}

return_type: char *


isCommentary

decompiled_code:
__int64 __fastcall isCommentary(_BYTE *a1)
{
while ( 1 )
{
if ( !*a1 )
return 0LL;
if ( *a1 == 59 )
break;
++a1;
}
*a1 = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(_BYTE *a1)
{
while ( 1 )
{
if ( !*a1 )
return 0LL;
if ( *a1 == 59 )
break;
++a1;
}
*a1 = 0;
return 1LL;
}

original_code:
int isCommentary(char* str) {
    int i = 0;
    while((str[i] != '\0') ){
        if(str[i] == ';'){
            str[i]='\0';
            return 1;
        }
        i++;
    }
    return 0;
}

canonical_original_code:
int isCommentary(char *str) {
    int i = 0;
    while((str[i] != '\0') ){
        if(str[i] == ';'){
            str[i]='\0';
            return 1;
        }
        i++;
    }
    return 0;
}


SearchLabelValue

decompiled_code:
__int64 __fastcall SearchLabelValue(__int64 a1, const char *a2)
{
int v2; // eax
__int64 v3; // r13
const char ***v4; // rbx
const char **v5; // rbp

v2 = *(_DWORD *)(a1 + 800);
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = a1 + 8LL * (unsigned int)(v2 - 1) + 8;
v4 = (const char ***)a1;
do
{
v5 = *v4;
if ( !strcmp(**v4, a2) )
return *((unsigned int *)v5 + 2);
++v4;
}
while ( v4 != (const char ***)v3 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, const char *a2)
{
int v2; // eax
__int64 v3; // r13
const char ***v4; // rbx
const char **v5; // rbp

v2 = *(_DWORD *)(a1 + 800);
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = a1 + 8LL * (unsigned int)(v2 - 1) + 8;
v4 = (const char ***)a1;
do
{
v5 = *v4;
if ( !strcmp(**v4, a2) )
return *((unsigned int *)v5 + 2);
++v4;
}
while ( v4 != (const char ***)v3 );
return 0xFFFFFFFFLL;
}

original_code:
int SearchLabelValue(Table* table, char* label){
    int i=0;
    for(i=0;i<table->last_;i++){
        if(strcmp(table->symbol_[i]->name_,label) == 0)
            return table->symbol_[i]->value_;
    }
 return -1;
}

canonical_original_code:
int SearchLabelValue(struct table *table, char *label){
    int i = 0;
    for(i=0;i<table->last_;i++){
        if(strcmp(table->symbol_[i]->name_,label) == 0)
            return table->symbol_[i]->value_;
    }
 return -1;
}

variable_types:
label
char *

user_defined_types: struct symbol { char *name_; int value_; }


Decode

decompiled_code:
__int64 __fastcall Decode(__int64 a1)
{
unsigned int v1; // er8

v1 = 1;
if ( strcmp((const char *)a1, "LOAD") )
{
v1 = 2;
if ( strcmp((const char *)a1, "STORE") )
{
v1 = 3;
if ( strcmp((const char *)a1, "PUSH") )
{
v1 = 4;
if ( strcmp((const char *)a1, "POP") )
{
v1 = 5;
if ( strcmp((const char *)a1, "JMP") )
{
v1 = 6;
if ( strcmp((const char *)a1, "JPG") )
{
v1 = 7;
if ( strcmp((const char *)a1, "JPGE") )
{
v1 = 8;
if ( strcmp((const char *)a1, "JPL") )
{
v1 = 9;
if ( strcmp((const char *)a1, "JPLE") )
{
v1 = 10;
if ( strcmp((const char *)a1, "JPE") )
{
v1 = 11;
if ( strcmp((const char *)a1, "JPNE") )
{
v1 = 12;
if ( strcmp((const char *)a1, "XOR") )
{
v1 = 13;
if ( strcmp((const char *)a1, "AND") )
{
if ( *(_BYTE *)a1 != 79 || *(_BYTE *)(a1 + 1) != 82 || (v1 = 14, *(_BYTE *)(a1 + 2)) )
{
v1 = 15;
if ( strcmp((const char *)a1, "NOT") )
{
v1 = 16;
if ( strcmp((const char *)a1, "ADD") )
{
v1 = 17;
if ( strcmp((const char *)a1, "SUB") )
{
v1 = 18;
if ( strcmp((const char *)a1, "READ") )
{
v1 = 19;
if ( strcmp((const char *)a1, "WRITE") )
{
v1 = 20;
if ( strcmp((const char *)a1, "CALL") )
{
v1 = 21;
if ( strcmp((const char *)a1, "RET") )
v1 = strcmp((const char *)a1, "HALT") == 0 ? 22 : -1;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
unsigned int v1; // er8

v1 = 1;
if ( strcmp((const char *)a1, "LOAD") )
{
v1 = 2;
if ( strcmp((const char *)a1, "STORE") )
{
v1 = 3;
if ( strcmp((const char *)a1, "PUSH") )
{
v1 = 4;
if ( strcmp((const char *)a1, "POP") )
{
v1 = 5;
if ( strcmp((const char *)a1, "JMP") )
{
v1 = 6;
if ( strcmp((const char *)a1, "JPG") )
{
v1 = 7;
if ( strcmp((const char *)a1, "JPGE") )
{
v1 = 8;
if ( strcmp((const char *)a1, "JPL") )
{
v1 = 9;
if ( strcmp((const char *)a1, "JPLE") )
{
v1 = 10;
if ( strcmp((const char *)a1, "JPE") )
{
v1 = 11;
if ( strcmp((const char *)a1, "JPNE") )
{
v1 = 12;
if ( strcmp((const char *)a1, "XOR") )
{
v1 = 13;
if ( strcmp((const char *)a1, "AND") )
{
if ( *(_BYTE *)a1 != 79 || *(_BYTE *)(a1 + 1) != 82 || (v1 = 14, *(_BYTE *)(a1 + 2)) )
{
v1 = 15;
if ( strcmp((const char *)a1, "NOT") )
{
v1 = 16;
if ( strcmp((const char *)a1, "ADD") )
{
v1 = 17;
if ( strcmp((const char *)a1, "SUB") )
{
v1 = 18;
if ( strcmp((const char *)a1, "READ") )
{
v1 = 19;
if ( strcmp((const char *)a1, "WRITE") )
{
v1 = 20;
if ( strcmp((const char *)a1, "CALL") )
{
v1 = 21;
if ( strcmp((const char *)a1, "RET") )
v1 = strcmp((const char *)a1, "HALT") == 0 ? 22 : -1;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return v1;
}

original_code:
int Decode(char* instruc){
    if(strcmp(instruc,"LOAD")==0) return 1;
    if(strcmp(instruc,"STORE")==0) return 2;
    if(strcmp(instruc,"PUSH")==0) return 3;
    if(strcmp(instruc,"POP")==0) return 4;
    if(strcmp(instruc,"JMP")==0) return 5;
    if(strcmp(instruc,"JPG")==0) return 6;
    if(strcmp(instruc,"JPGE")==0) return 7;
    if(strcmp(instruc,"JPL")==0) return 8;
    if(strcmp(instruc,"JPLE")==0) return 9;
    if(strcmp(instruc,"JPE")==0) return 10;
    if(strcmp(instruc,"JPNE")==0) return 11;
    if(strcmp(instruc,"XOR")==0) return 12;
    if(strcmp(instruc,"AND")==0) return 13;
    if(strcmp(instruc,"OR")==0) return 14;
    if(strcmp(instruc,"NOT")==0) return 15;
    if(strcmp(instruc,"ADD")==0) return 16;
    if(strcmp(instruc,"SUB")==0) return 17;
    if(strcmp(instruc,"READ")==0) return 18;
    if(strcmp(instruc,"WRITE")==0) return 19;
    if(strcmp(instruc,"CALL")==0) return 20;
    if(strcmp(instruc,"RET")==0) return 21;
    if(strcmp(instruc,"HALT")==0) return 22;
    return -1;
}

canonical_original_code:
int Decode(char *instruc){
    if(strcmp(instruc,"LOAD")==0) return 1;
    if(strcmp(instruc,"STORE")==0) return 2;
    if(strcmp(instruc,"PUSH")==0) return 3;
    if(strcmp(instruc,"POP")==0) return 4;
    if(strcmp(instruc,"JMP")==0) return 5;
    if(strcmp(instruc,"JPG")==0) return 6;
    if(strcmp(instruc,"JPGE")==0) return 7;
    if(strcmp(instruc,"JPL")==0) return 8;
    if(strcmp(instruc,"JPLE")==0) return 9;
    if(strcmp(instruc,"JPE")==0) return 10;
    if(strcmp(instruc,"JPNE")==0) return 11;
    if(strcmp(instruc,"XOR")==0) return 12;
    if(strcmp(instruc,"AND")==0) return 13;
    if(strcmp(instruc,"OR")==0) return 14;
    if(strcmp(instruc,"NOT")==0) return 15;
    if(strcmp(instruc,"ADD")==0) return 16;
    if(strcmp(instruc,"SUB")==0) return 17;
    if(strcmp(instruc,"READ")==0) return 18;
    if(strcmp(instruc,"WRITE")==0) return 19;
    if(strcmp(instruc,"CALL")==0) return 20;
    if(strcmp(instruc,"RET")==0) return 21;
    if(strcmp(instruc,"HALT")==0) return 22;
    return -1;
}


executaOperacoes

decompiled_code:
void __fastcall __noreturn executaOperacoes(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
unsigned int v8; // er14
unsigned int v9; // ebx
unsigned int v10; // er13
int v11; // eax
const char *v12; // rdi
_BYTE v13[4012]; // [rsp-FB0h] [rbp-FB0h] BYREF
_BYTE savedregs[4056]; // [rsp+0h] [rbp+0h] BYREF

v8 = STACK[0x1F84];
v9 = STACK[0x1F88];
v10 = LODWORD(STACK[0x1F80]) - 1;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v11 = *((_DWORD *)&a7 + (int)++v10);
if ( v11 != 1 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
LOAD(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o LOAD \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 2 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
STORE(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o STORE \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 3 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
PUSH(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o PUSH \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 4 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
POP(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o POP \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 5 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JMP(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JMP \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 6 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JPG(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JPG \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 7 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JPGE(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JPGE \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 8 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JPL(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JPL \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 9 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JPLE(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JPLE \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 10 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JPE(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JPE \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 11 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JPNE(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JPNE \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 12 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
XOR(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o XOR \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 13 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
AND(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o AND \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 14 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
OR(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o OR \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 15 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
NOT(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o NOT \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 16 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
ADD(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o ADD \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 17 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
SUB(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o SUB \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 18 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
READ(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o READ \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 19 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
WRITE(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o WRITE \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
switch ( v11 )
{
case 20:
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
CALL(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o CALL \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
break;
case 21:
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
RET(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o RET \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
{
LABEL_7:
printf(v12);
goto LABEL_8;
}
break;
case 22:
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
HALT(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
{
printf("Executando o HALT \n ");
LABEL_8:
printf("PC_=%d, SP_=%d, AC_=%d\n", v10, v9, v8);
printf("\n ");
}
break;
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
unsigned int v8; // er14
unsigned int v9; // ebx
unsigned int v10; // er13
int v11; // eax
const char *v12; // rdi
_BYTE v13[4012]; // [rsp-FB0h] [rbp-FB0h] BYREF
_BYTE savedregs[4056]; // [rsp+0h] [rbp+0h] BYREF

v8 = STACK[0x1F84];
v9 = STACK[0x1F88];
v10 = LODWORD(STACK[0x1F80]) - 1;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v11 = *((_DWORD *)&a7 + (int)++v10);
if ( v11 != 1 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
LOAD(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o LOAD \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 2 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
STORE(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o STORE \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 3 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
PUSH(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o PUSH \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 4 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
POP(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o POP \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 5 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JMP(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JMP \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 6 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JPG(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JPG \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 7 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JPGE(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JPGE \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 8 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JPL(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JPL \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 9 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JPLE(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JPLE \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 10 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JPE(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JPE \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 11 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
JPNE(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o JPNE \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 12 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
XOR(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o XOR \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 13 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
AND(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o AND \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 14 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
OR(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o OR \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 15 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
NOT(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o NOT \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 16 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
ADD(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o ADD \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 17 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
SUB(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o SUB \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 18 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
READ(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o READ \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
if ( v11 != 19 )
break;
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
WRITE(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o WRITE \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
}
switch ( v11 )
{
case 20:
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
CALL(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o CALL \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
goto LABEL_7;
break;
case 21:
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
RET(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v12 = "Executando o RET \n ";
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
{
LABEL_7:
printf(v12);
goto LABEL_8;
}
break;
case 22:
LODWORD(STACK[0x1F88]) = v9;
LODWORD(STACK[0x1F80]) = v10;
LODWORD(STACK[0x1F84]) = v8;
qmemcpy(v13, &a7, sizeof(v13));
HALT(savedregs);
qmemcpy(&a7, savedregs, 0xFA8uLL);
v8 = STACK[0x1F84];
v9 = *(_DWORD *)&savedregs[4008];
LODWORD(STACK[0x1F88]) = *(_DWORD *)&savedregs[4008];
v10 = STACK[0x1F80];
if ( a1 == 1 )
{
printf("Executando o HALT \n ");
LABEL_8:
printf("PC_=%d, SP_=%d, AC_=%d\n", v10, v9, v8);
printf("\n ");
}
break;
}
}
}

original_code:
void executaOperacoes(MaquinaVirtual MV, int verbose){
    MV.PC_--;
    int instrucao;
    while(1) {
        MV.PC_++;
 instrucao=MV.RAM_[MV.PC_];
    if(instrucao==1){
        MV=LOAD(MV);
        if(verbose==1){
            printf("Executando o LOAD \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==2){
        MV=STORE(MV);
        if(verbose==1){
            printf("Executando o STORE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==3){
        MV=PUSH(MV);
        if(verbose==1){
            printf("Executando o PUSH \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==4){
        MV=POP(MV);
        if(verbose==1){
            printf("Executando o POP \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==5){
        MV=JMP(MV);
        if(verbose==1){
            printf("Executando o JMP \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==6){
        MV=JPG(MV);
        if(verbose==1){
            printf("Executando o JPG \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==7){
        MV=JPGE(MV);
        if(verbose==1){
            printf("Executando o JPGE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==8){
        MV=JPL(MV);
        if(verbose==1){
            printf("Executando o JPL \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==9){
        MV=JPLE(MV);
        if(verbose==1){
            printf("Executando o JPLE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==10){
        MV=JPE(MV);
        if(verbose==1){
            printf("Executando o JPE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==11){
        MV=JPNE(MV);
        if(verbose==1){
            printf("Executando o JPNE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==12){
        MV=XOR(MV);
        if(verbose==1){
            printf("Executando o XOR \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==13){
        MV=AND(MV);
        if(verbose==1){
            printf("Executando o AND \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==14){
        MV=OR(MV);
        if(verbose==1){
            printf("Executando o OR \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==15){
        MV=NOT(MV);
        if(verbose==1){
            printf("Executando o NOT \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==16){
        MV=ADD(MV);
        if(verbose==1){
            printf("Executando o ADD \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==17){
        MV=SUB(MV);
        if(verbose==1){
            printf("Executando o SUB \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==18){
        MV=READ(MV);
        if(verbose==1){
            printf("Executando o READ \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==19){
        MV=WRITE(MV);
        if(verbose==1){
            printf("Executando o WRITE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==20){
        MV=CALL(MV);
        if(verbose==1){
            printf("Executando o CALL \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==21){
        MV=RET(MV);
        if(verbose==1){
            printf("Executando o RET \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==22){
        MV=HALT(MV);
        if(verbose==1){
            printf("Executando o HALT \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    }
}

canonical_original_code:
void executaOperacoes(struct maquinavirtual MV, int verbose){
    MV.PC_--;
    int instrucao;
    while(1) {
        MV.PC_++;
 instrucao=MV.RAM_[MV.PC_];
    if(instrucao==1){
        MV=LOAD(MV);
        if(verbose==1){
            printf("Executando o LOAD \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==2){
        MV=STORE(MV);
        if(verbose==1){
            printf("Executando o STORE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==3){
        MV=PUSH(MV);
        if(verbose==1){
            printf("Executando o PUSH \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==4){
        MV=POP(MV);
        if(verbose==1){
            printf("Executando o POP \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==5){
        MV=JMP(MV);
        if(verbose==1){
            printf("Executando o JMP \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==6){
        MV=JPG(MV);
        if(verbose==1){
            printf("Executando o JPG \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==7){
        MV=JPGE(MV);
        if(verbose==1){
            printf("Executando o JPGE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==8){
        MV=JPL(MV);
        if(verbose==1){
            printf("Executando o JPL \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==9){
        MV=JPLE(MV);
        if(verbose==1){
            printf("Executando o JPLE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==10){
        MV=JPE(MV);
        if(verbose==1){
            printf("Executando o JPE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==11){
        MV=JPNE(MV);
        if(verbose==1){
            printf("Executando o JPNE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==12){
        MV=XOR(MV);
        if(verbose==1){
            printf("Executando o XOR \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==13){
        MV=AND(MV);
        if(verbose==1){
            printf("Executando o AND \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==14){
        MV=OR(MV);
        if(verbose==1){
            printf("Executando o OR \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==15){
        MV=NOT(MV);
        if(verbose==1){
            printf("Executando o NOT \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==16){
        MV=ADD(MV);
        if(verbose==1){
            printf("Executando o ADD \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==17){
        MV=SUB(MV);
        if(verbose==1){
            printf("Executando o SUB \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==18){
        MV=READ(MV);
        if(verbose==1){
            printf("Executando o READ \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==19){
        MV=WRITE(MV);
        if(verbose==1){
            printf("Executando o WRITE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==20){
        MV=CALL(MV);
        if(verbose==1){
            printf("Executando o CALL \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==21){
        MV=RET(MV);
        if(verbose==1){
            printf("Executando o RET \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==22){
        MV=HALT(MV);
        if(verbose==1){
            printf("Executando o HALT \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    }
}

variable_types: struct maquinavirtual { int RAM_[1000]; int PC_; int AC_; int SP_; }

variable_types: verbose int

variable_types: instrucao int


main

canonical_name: main

repo: thammi/epa

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4; // rdi

v3 = 49;
puts("n;matrix;list");
benchmark(1LL, argv);
do
{
v4 = v3;
v3 += 50;
benchmark(v4, argv);
}
while ( v3 != 2049 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4; // rdi

v3 = 49;
puts("n;matrix;list");
func12(1LL, argv);
do
{
v4 = v3;
v3 += 50;
func12(v4, argv);
}
while ( v3 != 2049 );
return 0;
}

original_code:
int main(int argc, char *args[]) {
 printf("n;matrix;list\n");
 benchmark(1);
 for(int i = 49; i < 2000; i += 50) {
  benchmark(i);
 }
 return 0;
}

variable_types: argc int

variable_types:
args
char *[]


decompiled_code:
__int64 __fastcall list_add_edge(__int64 *a1, int a2, int a3)
{
_QWORD *v4; // rax
__int64 v5; // rdx
_QWORD *v6; // rdx

v4 = malloc(0x10uLL);
v5 = *a1;
*(_DWORD *)v4 = a3;
v6 = (_QWORD *)(v5 + 8LL * a2);
v4[1] = *v6;
*v6 = v4;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, int a2, int a3)
{
_QWORD *v4; // rax
__int64 v5; // rdx
_QWORD *v6; // rdx

v4 = malloc(0x10uLL);
v5 = *a1;
*(_DWORD *)v4 = a3;
v6 = (_QWORD *)(v5 + 8LL * a2);
v4[1] = *v6;
*v6 = v4;
return 1LL;
}

original_code:
int list_add_edge(adj_list *lists, int from, int to) {
 adj_node *new_node = malloc(sizeof(adj_node));
 new_node->neighbour = to;
 new_node->next = lists->nodes[from];
 lists->nodes[from] = new_node;
 return 1;
}

canonical_original_code:
int list_add_edge(struct adj_list *lists, int from, int to) {
 struct adj_node *new_node = malloc(sizeof(adj_node));
 new_node->neighbour = to;
 new_node->next = lists->nodes[from];
 lists->nodes[from] = new_node;
 return 1;
}

variable_types: struct adj_list { struct adj_node { int neighbour; struct adj_node *next; } **nodes; unsigned long size; } *

variable_types: from int

variable_types: to int

user_defined_types: struct adj_list { struct adj_node **nodes; unsigned long size; }


decompiled_code:
__int64 __fastcall list_remove_edge(_QWORD *a1, int a2, int a3)
{
__int64 *v3; // rsi
__int64 result; // rax
int v6; // edx
__int64 *v7; // rdi

v3 = (__int64 *)(*a1 + 8LL * a2);
result = *v3;
if ( !*v3 )
return 0LL;
while ( 1 )
{
v6 = *(_DWORD *)result;
v7 = (__int64 *)result;
result = *(_QWORD *)(result + 8);
if ( v6 == a3 )
break;
v3 = v7 + 1;
if ( !result )
return result;
}
*v3 = result;
free(v7);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, int a2, int a3)
{
__int64 *v3; // rsi
__int64 result; // rax
int v6; // edx
__int64 *v7; // rdi

v3 = (__int64 *)(*a1 + 8LL * a2);
result = *v3;
if ( !*v3 )
return 0LL;
while ( 1 )
{
v6 = *(_DWORD *)result;
v7 = (__int64 *)result;
result = *(_QWORD *)(result + 8);
if ( v6 == a3 )
break;
v3 = v7 + 1;
if ( !result )
return result;
}
*v3 = result;
free(v7);
return 1LL;
}

original_code:
int list_remove_edge(adj_list *lists, int from, int to) {
 adj_node **cur_ptr = &lists->nodes[from];
 while(*cur_ptr) {
  adj_node *cur = *cur_ptr;
  if(cur->neighbour == to) {
   *cur_ptr = cur->next;
   free(cur);
   return 1;
  }
  cur_ptr = &cur->next;
 }
 return 0;
}

canonical_original_code:
int list_remove_edge(struct adj_list *lists, int from, int to) {
 struct adj_node **cur_ptr = &lists->nodes[from];
 while(*cur_ptr) {
  struct adj_node *cur = *cur_ptr;
  if(cur->neighbour == to) {
   *cur_ptr = cur->next;
   free(cur);
   return 1;
  }
  cur_ptr = &cur->next;
 }
 return 0;
}

variable_types: struct adj_node { int neighbour; struct adj_node *next; } **


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

result = *(_QWORD *)(*a1 + 8LL * a2);
if ( !result )
return 0LL;
while ( *(_DWORD *)result != a3 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return 1LL;
}

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

result = *(_QWORD *)(*a1 + 8LL * a2);
if ( !result )
return 0LL;
while ( *(_DWORD *)result != a3 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return 1LL;
}

original_code:
int list_test_edge(adj_list *lists, int from, int to) {
 adj_node *cur = lists->nodes[from];
 while(cur) {
  if(cur->neighbour == to) {
   return 1;
  }
  cur = cur->next;
 }
 return 0;
}

canonical_original_code:
int list_test_edge(struct adj_list *lists, int from, int to) {
 struct adj_node *cur = lists->nodes[from];
 while(cur) {
  if(cur->neighbour == to) {
   return 1;
  }
  cur = cur->next;
 }
 return 0;
}

variable_types: struct adj_node { int neighbour; struct adj_node *next; } *


decompiled_code:
void __fastcall free_adj_list(void *ptr)
{
bool v2; // zf
_QWORD *v3; // rdi
unsigned __int64 v4; // rbp
_QWORD *v5; // rbx
void *v6; // rdi

v2 = *((_QWORD *)ptr + 1) == 0LL;
v3 = *(_QWORD **)ptr;
if ( !v2 )
{
v4 = 0LL;
do
{
v5 = (_QWORD *)v3[v4];
if ( v5 )
{
do
{
v6 = v5;
v5 = (_QWORD *)v5[1];
free(v6);
}
while ( v5 );
v3 = *(_QWORD **)ptr;
}
++v4;
}
while ( *((_QWORD *)ptr + 1) > v4 );
}
free(v3);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
bool v2; // zf
_QWORD *v3; // rdi
unsigned __int64 v4; // rbp
_QWORD *v5; // rbx
void *v6; // rdi

v2 = *((_QWORD *)ptr + 1) == 0LL;
v3 = *(_QWORD **)ptr;
if ( !v2 )
{
v4 = 0LL;
do
{
v5 = (_QWORD *)v3[v4];
if ( v5 )
{
do
{
v6 = v5;
v5 = (_QWORD *)v5[1];
free(v6);
}
while ( v5 );
v3 = *(_QWORD **)ptr;
}
++v4;
}
while ( *((_QWORD *)ptr + 1) > v4 );
}
free(v3);
free(ptr);
}

original_code:
void free_adj_list(adj_list *list) {
 for(int i = 0; i < list->size; ++i) {
  adj_node *cur = list->nodes[i];
  while(cur) {
   adj_node *next = cur->next;
   free(cur);
   cur = next;
  }
 }
 free(list->nodes);
 free(list);
}

canonical_original_code:
void free_adj_list(struct adj_list *list) {
 for(int i = 0; i < list->size; ++i) {
  struct adj_node *cur = list->nodes[i];
  while(cur) {
   struct adj_node *next = cur->next;
   free(cur);
   cur = next;
  }
 }
 free(list->nodes);
 free(list);
}

variable_types: i int

user_defined_types: struct adj_node { int neighbour; struct adj_node *next; }


original_code:
size_t list_mem(adj_list *list) {
 int count = 0;
 for(int x = 0; x < list->size; ++x) {
  for(int y = 0; y < list->size; ++y) {
   if(list_test_edge(list, x, y)) {
    ++count;
   }
  }
 }
 return sizeof(*list) + list->size * sizeof(list->nodes) + count * sizeof(**list->nodes);
}

canonical_original_code:
unsigned long list_mem(struct adj_list *list) {
 int count = 0;
 for(int x = 0; x < list->size; ++x) {
  for(int y = 0; y < list->size; ++y) {
   if(list_test_edge(list, x, y)) {
    ++count;
   }
  }
 }
 return sizeof(*list) + list->size * sizeof(list->nodes) + count * sizeof(**list->nodes);
}

variable_types: count int

variable_types: x int

variable_types: y int

return_type: unsigned long


benchmark

original_code:
void benchmark(int n) {
 clock_t matrix_start = clock();
 adj_matrix *matrix[50];
 for(int i = 0; i < 50; ++i) {
  matrix[i] = create_adj_matrix(1000, n);
 }
 double matrix_time = (clock() - matrix_start) / (double) ((__clock_t) 1000000) / 50;
 for(int i = 0; i < 50; ++i) {
  free_adj_matrix(matrix[i]);
 }
 clock_t list_start = clock();
 adj_list *list[50];
 for(int i = 0; i < 50; ++i) {
  list[i] = create_adj_list(1000, n);
 }
 double list_time = (clock() - list_start) / (double) ((__clock_t) 1000000) / 50;
 for(int i = 0; i < 50; ++i) {
  free_adj_list(list[i]);
 }
 printf("%d;%.4f;%.4f\n", n, matrix_time, list_time);
}

canonical_original_code:
void benchmark(int n) {
 long matrix_start = clock();
 struct adj_matrix *matrix[50];
 for(int i = 0; i < 50; ++i) {
  matrix[i] = create_adj_matrix(1000, n);
 }
 double matrix_time = (clock() - matrix_start) / (double) ((__clock_t) 1000000) / 50;
 for(int i = 0; i < 50; ++i) {
  free_adj_matrix(matrix[i]);
 }
 long list_start = clock();
 struct adj_list *list[50];
 for(int i = 0; i < 50; ++i) {
  list[i] = create_adj_list(1000, n);
 }
 double list_time = (clock() - list_start) / (double) ((__clock_t) 1000000) / 50;
 for(int i = 0; i < 50; ++i) {
  free_adj_list(list[i]);
 }
 printf("%d;%.4f;%.4f\n", n, matrix_time, list_time);
}

variable_types: n int

variable_types: struct adj_matrix { char *data; unsigned long size; } *[50]

variable_types: struct adj_list { struct adj_node { int neighbour; struct adj_node *next; } **nodes; unsigned long size; } *[50]


original_code:
int matrix_add_edge(adj_matrix *matrix, int from, int to) {
 const size_t i = from * matrix->size + to;
 matrix->data[i/8] |= 1 << i % 8;
 return 1;
}

canonical_original_code:
int matrix_add_edge(struct adj_matrix *matrix, int from, int to) {
 unsigned long i = from * matrix->size + to;
 matrix->data[i/8] |= 1 << i % 8;
 return 1;
}

variable_types: struct adj_matrix { char *data; unsigned long size; } *

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall matrix_remove_edge(_QWORD *a1, int a2, int a3)
{
unsigned __int64 v3; // rdx

v3 = a1[1] * a2 + a3;
*(_BYTE *)(*a1 + (v3 >> 3)) &= ~(unsigned __int8)(1 << (v3 & 7));
return 1LL;
}

original_code:
int matrix_remove_edge(adj_matrix *matrix, int from, int to) {
 const size_t i = from * matrix->size + to;
 matrix->data[i/8] &= ~(1 << i % 8);
 return 1;
}

canonical_original_code:
int matrix_remove_edge(struct adj_matrix *matrix, int from, int to) {
 unsigned long i = from * matrix->size + to;
 matrix->data[i/8] &= ~(1 << i % 8);
 return 1;
}

user_defined_types: struct adj_matrix { char *data; unsigned long size; }


decompiled_code:
__int64 __fastcall matrix_test_edge(__int64 a1, int a2, int a3)
{
return (1 << ((*(_BYTE *)(a1 + 8) * a2 + a3) & 7)) & (unsigned int)*(char *)(*(_QWORD *)a1
+ ((unsigned __int64)(*(_QWORD *)(a1 + 8)
* a2
+ a3) >> 3));
}

original_code:
int matrix_test_edge(adj_matrix *matrix, int from, int to) {
 const size_t i = from * matrix->size + to;
 return matrix->data[i/8] & (1 << i % 8);
}

canonical_original_code:
int matrix_test_edge(struct adj_matrix *matrix, int from, int to) {
 unsigned long i = from * matrix->size + to;
 return matrix->data[i/8] & (1 << i % 8);
}


decompiled_code:
void __fastcall free_adj_matrix(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func16(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_adj_matrix(adj_matrix *matrix) {
 free(matrix->data);
 free(matrix);
}

canonical_original_code:
void free_adj_matrix(struct adj_matrix *matrix) {
 free(matrix->data);
 free(matrix);
}


repo: tharvey/gst-httpd

original_code:
unsigned long
avg_add_samples(struct avg* pavg, unsigned long val)
{
 int i;
 time_t now = time(((void *)0));
 if (pavg->lastupdate > now
  || now - pavg->lastupdate > 0
  || pavg->_idx == 0)
 {
  pavg->idx++;
  pavg->lastupdate = now;
  if (pavg->_idx < 1 +1)
   pavg->_idx++;
  if (pavg->idx >= 1 +1)
   pavg->idx = 0;
  pavg->window[pavg->idx] = 0;
 }
 pavg->window[pavg->idx] += val;
 pavg->total += val;
 pavg->avg = 0;
 if (pavg->_idx > 1) {
  for (i = 0; i < 1 +1; i++) {
   if (i != pavg->idx)
    pavg->avg += pavg->window[i];
  }
  if (pavg->_idx > 2)
   pavg->avg /= (pavg->_idx - 1);
 }
 return pavg->avg;
}

canonical_original_code:
unsigned long avg_add_samples(struct avg *pavg, unsigned long val)
{
 int i;
 long now = time(((void *)0));
 if (pavg->lastupdate > now
  || now - pavg->lastupdate > 0
  || pavg->_idx == 0)
 {
  pavg->idx++;
  pavg->lastupdate = now;
  if (pavg->_idx < 1 +1)
   pavg->_idx++;
  if (pavg->idx >= 1 +1)
   pavg->idx = 0;
  pavg->window[pavg->idx] = 0;
 }
 pavg->window[pavg->idx] += val;
 pavg->total += val;
 pavg->avg = 0;
 if (pavg->_idx > 1) {
  for (i = 0; i < 1 +1; i++) {
   if (i != pavg->idx)
    pavg->avg += pavg->window[i];
  }
  if (pavg->_idx > 2)
   pavg->avg /= (pavg->_idx - 1);
 }
 return pavg->avg;
}

variable_types: struct avg { unsigned long total; unsigned long avg; unsigned int idx; unsigned int _idx; unsigned long window[-1]; long lastupdate; } *

variable_types:
val
unsigned long

variable_types: now long


decompiled_code:
__int64 __fastcall avg_get_avg(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
unsigned long
avg_get_avg(struct avg *pavg)
{
 return pavg->avg;
}

user_defined_types: struct avg { unsigned long total; unsigned long avg; unsigned int idx; unsigned int _idx; unsigned long window[-1]; long lastupdate; }


repo: thasmin/apocscientist

decompiled_code:
_BOOL8 __fastcall point_is_valid(float *a1)
{
_BOOL8 result; // rax

if ( -1.0 == *a1 )
result = 0LL;
else
result = -1.0 != a1[1];
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(float *a1)
{
_BOOL8 result; // rax

if ( -1.0 == *a1 )
result = 0LL;
else
result = -1.0 != a1[1];
return result;
}

original_code:
int point_is_valid(point *p)
{
 return p->x != -1 && p->y != -1;
}

canonical_original_code:
int point_is_valid(struct _point *p)
{
 return p->x != -1 && p->y != -1;
}

variable_types:
p
struct _point { float x; float y; } *


decompiled_code:
double __fastcall point_dist(float *a1, float *a2)
{
double v2; // xmm1_8
int v3; // eax
double result; // xmm0_8

if ( a1 == a2 || !a1 || !a2 )
return 0.0;
v2 = (double)((int)*a1 - (int)*a2);
v3 = (int)a1[1] - (int)a2[1];
result = (double)v3 * (double)v3 + v2 * v2;
*(float *)&result = result;
return result;
}

canonical_decompiled_code:
double __fastcall func2(float *a1, float *a2)
{
double v2; // xmm1_8
int v3; // eax
double result; // xmm0_8

if ( a1 == a2 || !a1 || !a2 )
return 0.0;
v2 = (double)((int)*a1 - (int)*a2);
v3 = (int)a1[1] - (int)a2[1];
result = (double)v3 * (double)v3 + v2 * v2;
*(float *)&result = result;
return result;
}

original_code:
float point_dist(point *p1, point *p2)
{
 if (p1 == p2)
  return 0;
 if (p1 == ((void *)0) || p2 == ((void *)0))
  return 0;
 return pow((int)p1->x - (int)p2->x, 2) + pow((int)p1->y - (int)p2->y, 2);
}

canonical_original_code:
float point_dist(struct _point *p1, struct _point *p2)
{
 if (p1 == p2)
  return 0;
 if (p1 == ((void *)0) || p2 == ((void *)0))
  return 0;
 return pow((int)p1->x - (int)p2->x, 2) + pow((int)p1->y - (int)p2->y, 2);
}

return_type: float


decompiled_code:
_BOOL8 __fastcall point_equals(float *a1, float *a2)
{
if ( a1 == a2 )
return 1LL;
if ( a1 && a2 && *a1 == *a2 )
return a1[1] == a2[1];
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(float *a1, float *a2)
{
if ( a1 == a2 )
return 1LL;
if ( a1 && a2 && *a1 == *a2 )
return a1[1] == a2[1];
return 0LL;
}

original_code:
int point_equals(point *p1, point *p2)
{
 if (p1 == p2)
  return 1;
 if (p1 == ((void *)0) || p2 == ((void *)0))
  return 0;
 return p1->x == p2->x && p1->y == p2->y;
}

canonical_original_code:
int point_equals(struct _point *p1, struct _point *p2)
{
 if (p1 == p2)
  return 1;
 if (p1 == ((void *)0) || p2 == ((void *)0))
  return 0;
 return p1->x == p2->x && p1->y == p2->y;
}


original_code:
void point_moveto(point *mover, point *target, float dist)
{
 if (point_equals(mover, target))
  return;
 float movex = (int)target->x - (int)mover->x;
 float movey = (int)target->y - (int)mover->y;
 float angle = atan2(movey, movex) * 180 / 3.14159265;
 if (angle < 0)
  angle += 360;
 float step = 360.0f / 16;
 if (angle > 360 - step || angle < 0 + step)
  mover->x += dist;
 else if (angle > 45 - step && angle < 45 + step)
  mover->x += dist, mover->y += dist;
 else if (angle > 90 - step && angle < 90 + step)
  mover->y += dist;
 else if (angle > 135 - step && angle < 135 + step)
  mover->x -= dist, mover->y += dist;
 else if (angle > 180 - step && angle < 180 + step)
  mover->x -= dist;
 else if (angle > 225 - step && angle < 225 + step)
  mover->x -= dist, mover->y -= dist;
 else if (angle > 270 - step && angle < 270 + step)
  mover->y -= dist;
 else if (angle > 315 - step && angle < 315 + step)
  mover->x += dist, mover->y -= dist;
 else
  printf("bad angle: %f\n", angle);
}

canonical_original_code:
void point_moveto(struct _point *mover, struct _point *target, float dist)
{
 if (point_equals(mover, target))
  return;
 float movex = (int)target->x - (int)mover->x;
 float movey = (int)target->y - (int)mover->y;
 float angle = atan2(movey, movex) * 180 / 3.14159265;
 if (angle < 0)
  angle += 360;
 float step = 360.0f / 16;
 if (angle > 360 - step || angle < 0 + step)
  mover->x += dist;
 else if (angle > 45 - step && angle < 45 + step)
  mover->x += dist, mover->y += dist;
 else if (angle > 90 - step && angle < 90 + step)
  mover->y += dist;
 else if (angle > 135 - step && angle < 135 + step)
  mover->x -= dist, mover->y += dist;
 else if (angle > 180 - step && angle < 180 + step)
  mover->x -= dist;
 else if (angle > 225 - step && angle < 225 + step)
  mover->x -= dist, mover->y -= dist;
 else if (angle > 270 - step && angle < 270 + step)
  mover->y -= dist;
 else if (angle > 315 - step && angle < 315 + step)
  mover->x += dist, mover->y -= dist;
 else
  printf("bad angle: %f\n", angle);
}

variable_types:
mover
struct _point { float x; float y; } *

variable_types:
target
struct _point *

variable_types: dist float

variable_types: movex float

variable_types: movey float

variable_types: angle float

variable_types: step float


decompiled_code:
int __fastcall debug_print_point(float *a1)
{
return printf("%f, %f\n", *a1, a1[1]);
}

canonical_decompiled_code:
int __fastcall func5(float *a1)
{
return printf("%f, %f\n", *a1, a1[1]);
}

original_code:
void debug_print_point(point *p)
{
 printf("%f, %f\n", p->x, p->y);
}

canonical_original_code:
void debug_print_point(struct _point *p)
{
 printf("%f, %f\n", p->x, p->y);
}


decompiled_code:
int __fastcall debug_print_point_node_list(__int64 a1)
{
unsigned int v1; // ebp
__int64 v2; // rbx
__int64 v3; // rsi
int result; // eax

if ( a1 )
{
v1 = 0;
v2 = a1;
do
{
v3 = v1++;
result = printf("%d: %f, %f\n", v3, *(float *)v2, *(float *)(v2 + 4));
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
unsigned int v1; // ebp
__int64 v2; // rbx
__int64 v3; // rsi
int result; // eax

if ( a1 )
{
v1 = 0;
v2 = a1;
do
{
v3 = v1++;
result = printf("%d: %f, %f\n", v3, *(float *)v2, *(float *)(v2 + 4));
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
}
return result;
}

original_code:
void debug_print_point_node_list(point_node *node)
{
 int i = 0;
 while (node) {
  printf("%d: %f, %f\n", i, node->p.x, node->p.y);
  ++i;
  node = node->next;
 }
}

canonical_original_code:
void debug_print_point_node_list(struct _point_node *node)
{
 int i = 0;
 while (node) {
  printf("%d: %f, %f\n", i, node->p.x, node->p.y);
  ++i;
  node = node->next;
 }
}

variable_types: struct _point_node { struct _point { float x; float y; } p; struct _point_node *next; } *

variable_types: i int

user_defined_types: struct _point_node { struct _point p; struct _point_node *next; }


decompiled_code:
void orders_init()
{
pending = 0LL;
}

canonical_decompiled_code:
void func0()
{
pending = 0LL;
}

original_code:
void orders_init()
{
 pending = ((void *)0);
}


main

repo: thayton/ptrie

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
test_1(argc, argv, envp);
test_2();
test_3();
test_4();
test_5();
test_6();
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func0(argc, argv, envp);
func1();
func2();
func3();
func4();
func5();
exit(0);
}

original_code:
int main(int argc, char **argv)
{
    test_1();
    test_2();
    test_3();
    test_4();
    test_5();
    test_6();
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **


getbit

decompiled_code:
__int64 __fastcall getbit(__int64 a1, unsigned __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned __int64 v4; // rdx

result = a3;
if ( a3 )
{
v4 = (int)(a3 - 1) >> 3;
if ( v4 <= a2 )
result = ((int)*(unsigned __int8 *)(a1 + v4) >> (-(char)result & 7)) & 1;
else
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned __int64 v4; // rdx

result = a3;
if ( a3 )
{
v4 = (int)(a3 - 1) >> 3;
if ( v4 <= a2 )
result = ((int)*(unsigned __int8 *)(a1 + v4) >> (-(char)result & 7)) & 1;
else
result = 0LL;
}
return result;
}

original_code:
static inline int getbit(void *key, size_t keysz, int bit)
{
    uint8_t *ptr = (uint8_t *)key;
    if (bit) {
        bit--;
        if ((bit >> 3) > keysz)
            return 0;
        return ptr[bit >> 3] & 1<<(7 - (bit & 7)) ? 1 : 0;
    }
    return 0;
}

canonical_original_code:
static inline int getbit(void *key, unsigned long keysz, int bit)
{
    unsigned char *ptr = (uint8_t *)key;
    if (bit) {
        bit--;
        if ((bit >> 3) > keysz)
            return 0;
        return ptr[bit >> 3] & 1<<(7 - (bit & 7)) ? 1 : 0;
    }
    return 0;
}

variable_types:
key
void *

variable_types:
keysz
unsigned long

variable_types: bit int

variable_types:
ptr
unsigned char *


keycmp

original_code:
static inline int keycmp(void *key1, size_t key1sz, void *key2, size_t key2sz)
{
    int i;
    int j;
    uint8_t *ptr1 = (uint8_t *)key1;
    uint8_t *ptr2 = (uint8_t *)key2;
    for (i = 0; *ptr1 == *ptr2; ptr1++, ptr2++, i++) {
        if (key1sz == key2sz) {
            if (i+1 == key1sz)
                return 0;
        }
    }
    i = i*8 + 1;
    for (j = 1<<7; (*ptr1 & j) == (*ptr2 & j); i++, j >>= 1)
            ;
    return (*ptr1 & j) ? i : -i;
}

canonical_original_code:
static inline int keycmp(void *key1, unsigned long key1sz, void *key2, unsigned long key2sz)
{
    int i;
    int j;
    unsigned char *ptr1 = (uint8_t *)key1;
    unsigned char *ptr2 = (uint8_t *)key2;
    for (i = 0; *ptr1 == *ptr2; ptr1++, ptr2++, i++) {
        if (key1sz == key2sz) {
            if (i+1 == key1sz)
                return 0;
        }
    }
    i = i*8 + 1;
    for (j = 1<<7; (*ptr1 & j) == (*ptr2 & j); i++, j >>= 1)
            ;
    return (*ptr1 & j) ? i : -i;
}

variable_types: j int


decompiled_code:
__int64 __fastcall pnode_new(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // ebp
__int64 v4; // rdx

result = *(_QWORD *)(a1 + 8);
if ( result )
{
*(_QWORD *)(a1 + 8) = *(_QWORD *)(result + 24);
*(_DWORD *)result = a2;
}
else
{
v3 = 1024;
do
{
result = (*(__int64 (__fastcall **)(__int64))(a1 + 48))(48LL);
v4 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 24) = v4;
*(_QWORD *)(a1 + 8) = result;
--v3;
}
while ( v3 );
*(_QWORD *)(a1 + 8) = v4;
*(_DWORD *)result = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // ebp
__int64 v4; // rdx

result = *(_QWORD *)(a1 + 8);
if ( result )
{
*(_QWORD *)(a1 + 8) = *(_QWORD *)(result + 24);
*(_DWORD *)result = a2;
}
else
{
v3 = 1024;
do
{
result = (*(__int64 (__fastcall **)(__int64))(a1 + 48))(48LL);
v4 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 24) = v4;
*(_QWORD *)(a1 + 8) = result;
--v3;
}
while ( v3 );
*(_QWORD *)(a1 + 8) = v4;
*(_DWORD *)result = a2;
}
return result;
}

original_code:
static pnode_t *
pnode_new(ptrie_t *pt, pn_type_t type)
{
    pnode_t *pn;
    if (pt->pt_list == ((void *)0)) {
        int i;
        for (i = 0; i < 1024; i++) {
            pn = pt->pt_malloc_func(sizeof(*pn));
            pn->pn_u.pn_node.pn_Cld[0] = pt->pt_list;
            pt->pt_list = pn;
        }
    }
    pn = pt->pt_list;
    pt->pt_list = pn->pn_u.pn_node.pn_Cld[0];
    pn->pn_type = type;
    return pn;
}

canonical_original_code:
static struct pnode *pnode_new(struct ptrie *pt, enum pn_type_t type)
{
    struct pnode *pn;
    if (pt->pt_list == ((void *)0)) {
        int i;
        for (i = 0; i < 1024; i++) {
            pn = pt->pt_malloc_func(sizeof(*pn));
            pn->pn_u.pn_node.pn_Cld[0] = pt->pt_list;
            pt->pt_list = pn;
        }
    }
    pn = pt->pt_list;
    pt->pt_list = pn->pn_u.pn_node.pn_Cld[0];
    pn->pn_type = type;
    return pn;
}

variable_types: struct ptrie { struct pnode *pt_root; struct pnode *pt_list; unsigned long pt_size; unsigned int pt_parms; struct ptrie_iter { void *pn; void *root; } pt_iter; void *(*pt_malloc_func)(unsigned long); void (*pt_free_func)(void *); unsigned long pt_keysz; unsigned long (*pt_keysz_func)(void *key); } *

variable_types:
type
enum pn_type_t { PN_LEAF=0, PN_NODE=1 }

variable_types: struct pnode { enum pn_type_t { PN_LEAF=0, PN_NODE=1 } pn_type; struct pnode *pn_up; union { struct { void *pn_Key; unsigned long pn_Keysz; void *pn_Val; unsigned long pn_Valsz; } pn_leaf; struct { int pn_Bit; struct pnode *pn_Cld[2]; } pn_node; } pn_u; } *

user_defined_types: struct ptrie { struct pnode *pt_root; struct pnode *pt_list; unsigned long pt_size; unsigned int pt_parms; struct ptrie_iter pt_iter; void *(*pt_malloc_func)(unsigned long); void (*pt_free_func)(void *); unsigned long pt_keysz; unsigned long (*pt_keysz_func)(void *key); }

user_defined_types: struct pnode { enum pn_type_t pn_type; struct pnode *pn_up; union { struct { void *pn_Key; unsigned long pn_Keysz; void *pn_Val; unsigned long pn_Valsz; } pn_leaf; struct { int pn_Bit; struct pnode *pn_Cld[2]; } pn_node; } pn_u; }


newpar

decompiled_code:
__int64 __fastcall newpar(__int64 a1, int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = pnode_new(a1, 1);
*(_DWORD *)(result + 16) = a2 ^ (a2 >> 31);
*(_DWORD *)(result + 16) -= a2 >> 31;
if ( a2 < 0 )
{
*(_QWORD *)(result + 24) = a3;
*(_QWORD *)(result + 32) = a4;
}
else
{
*(_QWORD *)(result + 24) = a4;
*(_QWORD *)(result + 32) = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = func2(a1, 1);
*(_DWORD *)(result + 16) = a2 ^ (a2 >> 31);
*(_DWORD *)(result + 16) -= a2 >> 31;
if ( a2 < 0 )
{
*(_QWORD *)(result + 24) = a3;
*(_QWORD *)(result + 32) = a4;
}
else
{
*(_QWORD *)(result + 24) = a4;
*(_QWORD *)(result + 32) = a3;
}
return result;
}

original_code:
static pnode_t *
newpar(ptrie_t *pt, int diffbit, pnode_t *cld1, pnode_t *cld2)
{
    pnode_t *pn = pnode_new(pt, PN_NODE);
    pn->pn_u.pn_node.pn_Bit = ((diffbit) < 0 ? -(diffbit) : (diffbit));
    if (diffbit < 0) {
        pn->pn_u.pn_node.pn_Cld[0] = cld1;
        pn->pn_u.pn_node.pn_Cld[1] = cld2;
    } else {
        pn->pn_u.pn_node.pn_Cld[0] = cld2;
        pn->pn_u.pn_node.pn_Cld[1] = cld1;
    }
    return pn;
}

canonical_original_code:
static struct pnode *newpar(struct ptrie *pt, int diffbit, struct pnode *cld1, struct pnode *cld2)
{
    struct pnode *pn = pnode_new(pt, PN_NODE);
    pn->pn_u.pn_node.pn_Bit = ((diffbit) < 0 ? -(diffbit) : (diffbit));
    if (diffbit < 0) {
        pn->pn_u.pn_node.pn_Cld[0] = cld1;
        pn->pn_u.pn_node.pn_Cld[1] = cld2;
    } else {
        pn->pn_u.pn_node.pn_Cld[0] = cld2;
        pn->pn_u.pn_node.pn_Cld[1] = cld1;
    }
    return pn;
}

variable_types: diffbit int

return_type: struct pnode { enum pn_type_t { PN_LEAF=0, PN_NODE=1 } pn_type; struct pnode *pn_up; union { struct { void *pn_Key; unsigned long pn_Keysz; void *pn_Val; unsigned long pn_Valsz; } pn_leaf; struct { int pn_Bit; struct pnode *pn_Cld[2]; } pn_node; } pn_u; } *

user_defined_types: struct ptrie_iter { void *pn; void *root; }


decompiled_code:
__int64 __fastcall pnode_free(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a2 + 24) = result;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a2 + 24) = result;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

original_code:
static void
pnode_free(ptrie_t *pt, pnode_t *pn)
{
    pn->pn_u.pn_node.pn_Cld[0] = pt->pt_list;
    pt->pt_list = pn;
}

canonical_original_code:
static void pnode_free(struct ptrie *pt, struct pnode *pn)
{
    pn->pn_u.pn_node.pn_Cld[0] = pt->pt_list;
    pt->pt_list = pn;
}

variable_types: struct ptrie { struct pnode { enum pn_type_t { PN_LEAF=0, PN_NODE=1 } pn_type; struct pnode *pn_up; union { struct { void *pn_Key; unsigned long pn_Keysz; void *pn_Val; unsigned long pn_Valsz; } pn_leaf; struct { int pn_Bit; struct pnode *pn_Cld[2]; } pn_node; } pn_u; } *pt_root; struct pnode *pt_list; unsigned long pt_size; unsigned int pt_parms; struct ptrie_iter { void *pn; void *root; } pt_iter; void *(*pt_malloc_func)(unsigned long); void (*pt_free_func)(void *); unsigned long pt_keysz; unsigned long (*pt_keysz_func)(void *key); } *

variable_types:
pn
struct pnode *


fmalloc

decompiled_code:
void *__fastcall fmalloc(size_t a1)
{
void *result; // rax
int *v2; // rax
char *v3; // rax

result = malloc(a1);
if ( !result )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "fmalloc - malloc failed: %s\n", v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func5(size_t a1)
{
void *result; // rax
int *v2; // rax
char *v3; // rax

result = malloc(a1);
if ( !result )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "fmalloc - malloc failed: %s\n", v3);
exit(1);
}
return result;
}

original_code:
static void *
fmalloc(size_t size)
{
    void *data = malloc(size);
    if (data == ((void *)0)) {
        fprintf(stderr, "fmalloc - malloc failed: %s\n", strerror((*__errno_location ())));
        exit(1);
    }
    return data;
}

canonical_original_code:
static void *fmalloc(unsigned long size)
{
    void *data = malloc(size);
    if (data == ((void *)0)) {
        fprintf(stderr, "fmalloc - malloc failed: %s\n", strerror((*__errno_location ())));
        exit(1);
    }
    return data;
}

variable_types:
size
unsigned long

variable_types:
data
void *

return_type: void *


keysize

decompiled_code:
__int64 __fastcall keysize(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 (__fastcall *v3)(__int64); // rax

result = *(_QWORD *)(a1 + 64);
if ( !result )
{
v3 = *(__int64 (__fastcall **)(__int64))(a1 + 72);
if ( !v3 )
{
fwrite("Error: unable to determine key size\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
result = v3(a2);
}
return result;
}

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

result = *(_QWORD *)(a1 + 64);
if ( !result )
{
v3 = *(__int64 (__fastcall **)(__int64))(a1 + 72);
if ( !v3 )
{
fwrite("Error: unable to determine key size\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
result = v3(a2);
}
return result;
}

original_code:
static size_t
keysize(ptrie_t *pt, void *key)
{
    if (pt->pt_keysz)
        return pt->pt_keysz;
    else if (pt->pt_keysz_func)
        return (*pt->pt_keysz_func)(key);
    else {
        fprintf(stderr, "Error: unable to determine key size\n");
        exit(1);
    }
}

canonical_original_code:
static unsigned long keysize(struct ptrie *pt, void *key)
{
    if (pt->pt_keysz)
        return pt->pt_keysz;
    else if (pt->pt_keysz_func)
        return (*pt->pt_keysz_func)(key);
    else {
        fprintf(stderr, "Error: unable to determine key size\n");
        exit(1);
    }
}


keyseq

decompiled_code:
_BOOL8 __fastcall keyseq(const void *a1, size_t a2, const void *a3, __int64 a4)
{
_BOOL8 result; // rax

if ( a2 == a4 )
result = memcmp(a1, a3, a2) == 0;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(const void *a1, size_t a2, const void *a3, __int64 a4)
{
_BOOL8 result; // rax

if ( a2 == a4 )
result = memcmp(a1, a3, a2) == 0;
else
result = 0LL;
return result;
}

original_code:
static inline int keyseq(void *key1, size_t key1sz, void *key2, size_t key2sz)
{
    return key1sz == key2sz && memcmp(key1, key2, key1sz) == 0;
}

canonical_original_code:
static inline int keyseq(void *key1, unsigned long key1sz, void *key2, unsigned long key2sz)
{
    return key1sz == key2sz && memcmp(key1, key2, key1sz) == 0;
}


original_code:
static pnode_t *
ptrie_del0(ptrie_t *pt, void *key, size_t keysz, pnode_t *pn)
{
    int i;
    if (pn->pn_type == PN_NODE) {
        i = getbit(key, keysz, pn->pn_u.pn_node.pn_Bit);
        pn->pn_u.pn_node.pn_Cld[i] = ptrie_del0(pt, key, keysz, pn->pn_u.pn_node.pn_Cld[i]);
        if (pn->pn_u.pn_node.pn_Cld[i] == ((void *)0)) {
            pnode_t *fn;
            pn->pn_u.pn_node.pn_Cld[((i) ^ 1)]->pn_up = pn->pn_up;
            fn = pn;
            pn = pn->pn_u.pn_node.pn_Cld[((i) ^ 1)];
            pnode_free(pt, fn);
        }
    } else if (keyseq(key, keysz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz)) {
        pnode_free(pt, pn);
        pn = ((void *)0);
        pt->pt_size--;
    }
    return pn;
}

canonical_original_code:
static struct pnode *ptrie_del0(struct ptrie *pt, void *key, unsigned long keysz, struct pnode *pn)
{
    int i;
    if (pn->pn_type == PN_NODE) {
        i = getbit(key, keysz, pn->pn_u.pn_node.pn_Bit);
        pn->pn_u.pn_node.pn_Cld[i] = ptrie_del0(pt, key, keysz, pn->pn_u.pn_node.pn_Cld[i]);
        if (pn->pn_u.pn_node.pn_Cld[i] == ((void *)0)) {
            struct pnode *fn;
            pn->pn_u.pn_node.pn_Cld[((i) ^ 1)]->pn_up = pn->pn_up;
            fn = pn;
            pn = pn->pn_u.pn_node.pn_Cld[((i) ^ 1)];
            pnode_free(pt, fn);
        }
    } else if (keyseq(key, keysz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz)) {
        pnode_free(pt, pn);
        pn = ((void *)0);
        pt->pt_size--;
    }
    return pn;
}


original_code:
ptrie_t *
ptrie_new(void)
{
    int i;
    ptrie_t *pt;
    pnode_t *pn;
    pt = fmalloc(sizeof(*pt));
    pt->pt_root = ((void *)0);
    pt->pt_list = ((void *)0);
    pt->pt_size = 0;
    pt->pt_keysz = 0;
    pt->pt_keysz_func = (size_t (*)(void *))strlen;
    pt->pt_malloc_func = fmalloc;
    pt->pt_free_func = free;
    for (i = 0; i < 1024; i++) {
        pn = pt->pt_malloc_func(sizeof(*pn));
        pn->pn_u.pn_node.pn_Cld[0] = pt->pt_list;
        pt->pt_list = pn;
    }
    return pt;
}

canonical_original_code:
struct ptrie *ptrie_new()
{
    int i;
    struct ptrie *pt;
    struct pnode *pn;
    pt = fmalloc(sizeof(*pt));
    pt->pt_root = ((void *)0);
    pt->pt_list = ((void *)0);
    pt->pt_size = 0;
    pt->pt_keysz = 0;
    pt->pt_keysz_func = (unsigned long (*)(void *))strlen;
    pt->pt_malloc_func = fmalloc;
    pt->pt_free_func = free;
    for (i = 0; i < 1024; i++) {
        pn = pt->pt_malloc_func(sizeof(*pn));
        pn->pn_u.pn_node.pn_Cld[0] = pt->pt_list;
        pt->pt_list = pn;
    }
    return pt;
}

return_type: struct ptrie { struct pnode { enum pn_type_t { PN_LEAF=0, PN_NODE=1 } pn_type; struct pnode *pn_up; union { struct { void *pn_Key; unsigned long pn_Keysz; void *pn_Val; unsigned long pn_Valsz; } pn_leaf; struct { int pn_Bit; struct pnode *pn_Cld[2]; } pn_node; } pn_u; } *pt_root; struct pnode *pt_list; unsigned long pt_size; unsigned int pt_parms; struct ptrie_iter { void *pn; void *root; } pt_iter; void *(*pt_malloc_func)(unsigned long); void (*pt_free_func)(void *); unsigned long pt_keysz; unsigned long (*pt_keysz_func)(void *key); } *


decompiled_code:
void ptrie_free()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void
ptrie_free(ptrie_t *ptrie)
{
    return;
}

canonical_original_code:
void ptrie_free(struct ptrie *ptrie)
{
    return;
}


original_code:
void
ptrie_add2(ptrie_t *pt, void *key, void *val, void **pnode)
{
    pnode_t *pn;
    pnode_t **lk;
    pnode_t *nnode;
    pnode_t *nleaf;
    size_t keysz;
    int diffbit;
    keysz = keysize(pt, key);
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        pt->pt_root = newcld(pt, key, keysz, val);
        pt->pt_root->pn_up = ((void *)0);
        pt->pt_size++;
        if (pnode)
            *pnode = pt->pt_root;
        return;
    }
    for (pn = pt->pt_root; pn->pn_type == PN_NODE; )
        pn = pn->pn_u.pn_node.pn_Cld[getbit(key, keysz, pn->pn_u.pn_node.pn_Bit)];
    diffbit = keycmp(key, keysz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz);
    if (diffbit == 0) {
        return;
    }
    lk = &pt->pt_root;
    pn = pt->pt_root;
    while (pn->pn_type == PN_NODE) {
        if (pn->pn_u.pn_node.pn_Bit > ((diffbit) < 0 ? -(diffbit) : (diffbit))) {
            break;
        } else {
            lk = &pn->pn_u.pn_node.pn_Cld[getbit(key, keysz, pn->pn_u.pn_node.pn_Bit)];
            pn = *lk;
        }
    }
    nleaf = newcld(pt, key, keysz, val);
    nnode = newpar(pt, diffbit, nleaf, pn);
    nleaf->pn_up = nnode;
    nnode->pn_up = pn->pn_up;
    pn->pn_up = nnode;
    *lk = nnode;
    pt->pt_size++;
    if (pnode)
        *pnode = nleaf;
    return;
}

canonical_original_code:
void ptrie_add2(struct ptrie *pt, void *key, void *val, void **pnode)
{
    struct pnode *pn;
    struct pnode **lk;
    struct pnode *nnode;
    struct pnode *nleaf;
    unsigned long keysz;
    int diffbit;
    keysz = keysize(pt, key);
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        pt->pt_root = newcld(pt, key, keysz, val);
        pt->pt_root->pn_up = ((void *)0);
        pt->pt_size++;
        if (pnode)
            *pnode = pt->pt_root;
        return;
    }
    for (pn = pt->pt_root; pn->pn_type == PN_NODE; )
        pn = pn->pn_u.pn_node.pn_Cld[getbit(key, keysz, pn->pn_u.pn_node.pn_Bit)];
    diffbit = keycmp(key, keysz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz);
    if (diffbit == 0) {
        return;
    }
    lk = &pt->pt_root;
    pn = pt->pt_root;
    while (pn->pn_type == PN_NODE) {
        if (pn->pn_u.pn_node.pn_Bit > ((diffbit) < 0 ? -(diffbit) : (diffbit))) {
            break;
        } else {
            lk = &pn->pn_u.pn_node.pn_Cld[getbit(key, keysz, pn->pn_u.pn_node.pn_Bit)];
            pn = *lk;
        }
    }
    nleaf = newcld(pt, key, keysz, val);
    nnode = newpar(pt, diffbit, nleaf, pn);
    nleaf->pn_up = nnode;
    nnode->pn_up = pn->pn_up;
    pn->pn_up = nnode;
    *lk = nnode;
    pt->pt_size++;
    if (pnode)
        *pnode = nleaf;
    return;
}

variable_types:
val
void *

variable_types:
pnode
void **

variable_types: struct pnode { enum pn_type_t { PN_LEAF=0, PN_NODE=1 } pn_type; struct pnode *pn_up; union { struct { void *pn_Key; unsigned long pn_Keysz; void *pn_Val; unsigned long pn_Valsz; } pn_leaf; struct { int pn_Bit; struct pnode *pn_Cld[2]; } pn_node; } pn_u; } **


decompiled_code:
__int64 __fastcall ptrie_add(__int64 *a1, unsigned __int8 *a2, __int64 a3)
{
return ptrie_add2(a1, a2, a3, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1, unsigned __int8 *a2, __int64 a3)
{
return func11(a1, a2, a3, 0LL);
}

original_code:
void
ptrie_add(ptrie_t *pt, void *key, void *val)
{
    ptrie_add2(pt, key, val, ((void *)0));
}

canonical_original_code:
void ptrie_add(struct ptrie *pt, void *key, void *val)
{
    ptrie_add2(pt, key, val, ((void *)0));
}


original_code:
void *
ptrie_get(ptrie_t *pt, void *key)
{
    pnode_t *pn;
    size_t keysz;
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        return ((void *)0);
    }
    keysz = keysize(pt, key);
    for (pn = pt->pt_root; pn->pn_type == PN_NODE; )
        pn = pn->pn_u.pn_node.pn_Cld[getbit(key, keysz, pn->pn_u.pn_node.pn_Bit)];
    if (keyseq(key, keysz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz)) {
        return pn->pn_u.pn_leaf.pn_Val;
    }
    return ((void *)0);
}

canonical_original_code:
void *ptrie_get(struct ptrie *pt, void *key)
{
    struct pnode *pn;
    unsigned long keysz;
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        return ((void *)0);
    }
    keysz = keysize(pt, key);
    for (pn = pt->pt_root; pn->pn_type == PN_NODE; )
        pn = pn->pn_u.pn_node.pn_Cld[getbit(key, keysz, pn->pn_u.pn_node.pn_Bit)];
    if (keyseq(key, keysz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz)) {
        return pn->pn_u.pn_leaf.pn_Val;
    }
    return ((void *)0);
}


decompiled_code:
_BOOL8 __fastcall ptrie_haskey(__int64 *a1, const void *a2)
{
return ptrie_get(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(__int64 *a1, const void *a2)
{
return func13(a1, a2) != 0;
}

original_code:
int
ptrie_haskey(ptrie_t *pt, void *key)
{
    return ptrie_get(pt, key) != ((void *)0);
}

canonical_original_code:
int ptrie_haskey(struct ptrie *pt, void *key)
{
    return ptrie_get(pt, key) != ((void *)0);
}


original_code:
void *
ptrie_get_prefix(ptrie_t *pt, void *prefix, size_t nbits)
{
    pnode_t *pn;
    pnode_t *in;
    size_t pfxsz;
    int diffbit;
    pfxsz = keysize(pt, prefix);
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        return ((void *)0);
    }
    for (pn = pt->pt_root; pn->pn_type == PN_NODE; )
        pn = pn->pn_u.pn_node.pn_Cld[getbit(prefix, pfxsz, pn->pn_u.pn_node.pn_Bit)];
    diffbit = keycmp(prefix, pfxsz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz);
    if (diffbit == 0 || nbits < diffbit) {
        for (in = pn->pn_up; in && nbits < in->pn_u.pn_node.pn_Bit; in = pn->pn_up)
            pn = in;
    }
    return pn;
}

canonical_original_code:
void *ptrie_get_prefix(struct ptrie *pt, void *prefix, unsigned long nbits)
{
    struct pnode *pn;
    struct pnode *in;
    unsigned long pfxsz;
    int diffbit;
    pfxsz = keysize(pt, prefix);
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        return ((void *)0);
    }
    for (pn = pt->pt_root; pn->pn_type == PN_NODE; )
        pn = pn->pn_u.pn_node.pn_Cld[getbit(prefix, pfxsz, pn->pn_u.pn_node.pn_Bit)];
    diffbit = keycmp(prefix, pfxsz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz);
    if (diffbit == 0 || nbits < diffbit) {
        for (in = pn->pn_up; in && nbits < in->pn_u.pn_node.pn_Bit; in = pn->pn_up)
            pn = in;
    }
    return pn;
}

variable_types:
prefix
void *

variable_types:
nbits
unsigned long

variable_types:
pfxsz
unsigned long


original_code:
void
ptrie_del(ptrie_t *pt, void *key)
{
    size_t keysz;
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        return;
    }
    keysz = keysize(pt, key);
    pt->pt_root = ptrie_del0(pt, key, keysz, pt->pt_root);
}

canonical_original_code:
void ptrie_del(struct ptrie *pt, void *key)
{
    unsigned long keysz;
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        return;
    }
    keysz = keysize(pt, key);
    pt->pt_root = ptrie_del0(pt, key, keysz, pt->pt_root);
}

variable_types:
key
void *

variable_types:
keysz
unsigned long


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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 16);
return result;
}

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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 16);
return result;
}

original_code:
int
ptrie_size(ptrie_t *pt)
{
    return pt ? pt->pt_size : 0;
}

canonical_original_code:
int ptrie_size(struct ptrie *pt)
{
    return pt ? pt->pt_size : 0;
}


original_code:
int
ptrie_iter_next(ptrie_t *pt, ptrie_iter_t *ptit, void **key, void **val)
{
    pnode_t *pn;
    if (! ptit)
        ptit = &pt->pt_iter;
    if (! ptit->pn)
        return 0;
    pn = ptit->pn;
    if (key) *key = pn->pn_u.pn_leaf.pn_Key;
    if (val) *val = pn->pn_u.pn_leaf.pn_Val;
    if (pn != ptit->root && ((pn) == (pn)->pn_up->pn_u.pn_node.pn_Cld[1])) {
        for (pn = pn->pn_up; pn != ptit->root; pn = pn->pn_up)
            if (((pn) == (pn)->pn_up->pn_u.pn_node.pn_Cld[0]))
                break;
    }
    if (pn == ptit->root) {
        ptit->pn = ((void *)0);
        return 1;
    }
    pn = pn->pn_up->pn_u.pn_node.pn_Cld[1];
    while (pn->pn_type == PN_NODE)
        pn = pn->pn_u.pn_node.pn_Cld[0];
    ptit->pn = pn;
    return 1;
}

canonical_original_code:
int ptrie_iter_next(struct ptrie *pt, struct ptrie_iter *ptit, void **key, void **val)
{
    struct pnode *pn;
    if (! ptit)
        ptit = &pt->pt_iter;
    if (! ptit->pn)
        return 0;
    pn = ptit->pn;
    if (key) *key = pn->pn_u.pn_leaf.pn_Key;
    if (val) *val = pn->pn_u.pn_leaf.pn_Val;
    if (pn != ptit->root && ((pn) == (pn)->pn_up->pn_u.pn_node.pn_Cld[1])) {
        for (pn = pn->pn_up; pn != ptit->root; pn = pn->pn_up)
            if (((pn) == (pn)->pn_up->pn_u.pn_node.pn_Cld[0]))
                break;
    }
    if (pn == ptit->root) {
        ptit->pn = ((void *)0);
        return 1;
    }
    pn = pn->pn_up->pn_u.pn_node.pn_Cld[1];
    while (pn->pn_type == PN_NODE)
        pn = pn->pn_u.pn_node.pn_Cld[0];
    ptit->pn = pn;
    return 1;
}

variable_types:
ptit
struct ptrie_iter *

variable_types:
key
void **

variable_types:
val
void **


main

repo: thborges/datecmd

original_code:
int main(int argc, char *argv[]) {
 char *format = "%Y.%m.%d %H:%M:%S";
 short date_only = 0;
 short time_only = 0;
 short crlf = 0;
    short i = 0;
 time_t rawtime;
 struct tm *ct;
 char buffer[80];
 if ((argc == 2) && (strcmp(argv[1], "/?") == 0)) {
  goto usage;
 }
 i=0;
 while (++i < argc) {
  if (strcmp(argv[i], "/e") == 0) {
   crlf = 1;
   continue;
  }
  if (strcmp(argv[i], "/d") == 0) {
   date_only = 1;
   continue;
  }
  if (strcmp(argv[i], "/t") == 0) {
   time_only = 1;
   continue;
  }
  if (strcmp(argv[i], "/f") == 0) {
   if (argc <= i+1)
    goto usage;
   format = argv[++i];
   continue;
  }
 };
 time(&rawtime);
 ct = localtime(&rawtime);
 if (date_only)
  strftime(buffer, 80, "%Y%m%d", ct);
 else if (time_only)
  strftime(buffer, 80, "%H%M%S", ct);
 else
  strftime(buffer, 80, format, ct);
 printf(buffer);
 if (crlf)
  printf("\r\n");
 return 0;
usage:
 printf(usage);
 return 1;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 char *format = "%Y.%m.%d %H:%M:%S";
 short date_only = 0;
 short time_only = 0;
 short crlf = 0;
    short i = 0;
 long rawtime;
 struct tm *ct;
 char buffer[80];
 if ((argc == 2) && (strcmp(argv[1], "/?") == 0)) {
  goto usage;
 }
 i=0;
 while (++i < argc) {
  if (strcmp(argv[i], "/e") == 0) {
   crlf = 1;
   continue;
  }
  if (strcmp(argv[i], "/d") == 0) {
   date_only = 1;
   continue;
  }
  if (strcmp(argv[i], "/t") == 0) {
   time_only = 1;
   continue;
  }
  if (strcmp(argv[i], "/f") == 0) {
   if (argc <= i+1)
    goto usage;
   format = argv[++i];
   continue;
  }
 };
 time(&rawtime);
 ct = localtime(&rawtime);
 if (date_only)
  strftime(buffer, 80, "%Y%m%d", ct);
 else if (time_only)
  strftime(buffer, 80, "%H%M%S", ct);
 else
  strftime(buffer, 80, format, ct);
 printf(buffer);
 if (crlf)
  printf("\r\n");
 return 0;
usage:
 printf(usage);
 return 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
format
char *

variable_types: crlf short

variable_types: i short

variable_types: rawtime 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:
buffer
char [80]


xmalloc

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

result = malloc(a1);
if ( !a1 )
_assert_fail("size != 0", "common.h", 0x11u, "xmalloc");
if ( !result )
{
fwrite("malloc call failed - this is pretty bad\n", 1uLL, 0x28uLL, stderr);
exit(-2);
}
return result;
}

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

result = malloc(a1);
if ( !a1 )
_assert_fail("size != 0", "common.h", 0x11u, "xmalloc");
if ( !result )
{
fwrite("malloc call failed - this is pretty bad\n", 1uLL, 0x28uLL, stderr);
exit(-2);
}
return result;
}

original_code:
inline static void *xmalloc(size_t size) {
    void *ptr = malloc(size);
    ((void) sizeof ((size != 0) ? 1 : 0), __extension__ ({ if (size != 0) ; else __assert_fail ("size != 0", "common.h", 17, __extension__ __PRETTY_FUNCTION__); }));
    if(!ptr) {
        fprintf(stderr, "malloc call failed - this is pretty bad\n");
        exit(-2);
    }
    return ptr;
}

canonical_original_code:
inline static void *xmalloc(unsigned long size) {
    void *ptr = malloc(size);
    ((void) sizeof ((size != 0) ? 1 : 0), __extension__ ({ if (size != 0) ; else __assert_fail ("size != 0", "common.h", 17, __extension__ __PRETTY_FUNCTION__); }));
    if(!ptr) {
        fprintf(stderr, "malloc call failed - this is pretty bad\n");
        exit(-2);
    }
    return ptr;
}

variable_types:
size
unsigned long

variable_types:
ptr
void *


decompiled_code:
void __fastcall aio_buffer_free(void *ptr)
{
int v2; // edi

v2 = *((_DWORD *)ptr + 10);
if ( v2 != -1 )
close(v2);
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
int v2; // edi

v2 = *((_DWORD *)ptr + 10);
if ( v2 != -1 )
close(v2);
free(*(void **)ptr);
free(ptr);
}

original_code:
void aio_buffer_free(aio_buffer *buffer) {
  if(buffer->fd != -1)
    close(buffer->fd);
  free(buffer->data);
  free(buffer);
}

canonical_original_code:
void aio_buffer_free(struct aio_buffer *buffer) {
  if(buffer->fd != -1)
    close(buffer->fd);
  free(buffer->data);
  free(buffer);
}

variable_types: struct aio_buffer { char *data; unsigned long size; char *start; char *end; unsigned long limit; int fd; char *linestart; char *linelimit; } *


decompiled_code:
int __fastcall aio_buffer_close(__int64 a1)
{
int v2; // edi
int result; // eax

v2 = *(_DWORD *)(a1 + 40);
if ( v2 != -1 )
result = close(v2);
*(_DWORD *)(a1 + 40) = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
int v2; // edi
int result; // eax

v2 = *(_DWORD *)(a1 + 40);
if ( v2 != -1 )
result = close(v2);
*(_DWORD *)(a1 + 40) = -1;
return result;
}

original_code:
void aio_buffer_close(aio_buffer *buffer) {
  if(buffer->fd != -1)
    close(buffer->fd);
  buffer->fd = -1;
}

canonical_original_code:
void aio_buffer_close(struct aio_buffer *buffer) {
  if(buffer->fd != -1)
    close(buffer->fd);
  buffer->fd = -1;
}

user_defined_types: struct aio_buffer { char *data; unsigned long size; char *start; char *end; unsigned long limit; int fd; char *linestart; char *linelimit; }