cacheLookup

decompiled_code:
__int64 __fastcall cacheLookup(_QWORD *a1, __int64 a2, _QWORD *a3)
{
unsigned int v4; // ebx
int v6[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v6) == 1 )
{
v4 = 1;
updateAccessTime(a1[1], (unsigned int)v6[0]);
*a3 = *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * v6[0] + 32);
}
else
{
fflush(stderr);
v4 = HTlookup(*a1, a2, v6);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, __int64 a2, _QWORD *a3)
{
unsigned int v4; // ebx
int v6[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v6) == 1 )
{
v4 = 1;
updateAccessTime(a1[1], (unsigned int)v6[0]);
*a3 = *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * v6[0] + 32);
}
else
{
fflush(stderr);
v4 = HTlookup(*a1, a2, v6);
}
return v4;
}

original_code:
errorCode cacheLookup(cache * c, void * key, void ** data){
  int slot;
  if(HTlookup(c -> ht, (void*)key, (void**)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void*)key, (void**)&slot); };
  updateAccessTime(c -> lsc, slot);
  *data = ((((c -> lsc) -> accntArray) + slot) -> data );
  return 1;
}

canonical_original_code:
int cacheLookup(struct cache_tag *c, void *key, void **data){
  int slot;
  if(HTlookup(c -> ht, (void *)key, (void **)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void *)key, (void **)&slot); };
  updateAccessTime(c -> lsc, slot);
  *data = ((((c -> lsc) -> accntArray) + slot) -> data );
  return 1;
}


cacheTouch

decompiled_code:
__int64 __fastcall cacheTouch(_QWORD *a1, __int64 a2)
{
unsigned int v2; // ebx
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v4) == 1 )
{
v2 = 1;
updateAccessTime(a1[1], (unsigned int)v4[0]);
}
else
{
fflush(stderr);
v2 = HTlookup(*a1, a2, v4);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2)
{
unsigned int v2; // ebx
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v4) == 1 )
{
v2 = 1;
updateAccessTime(a1[1], (unsigned int)v4[0]);
}
else
{
fflush(stderr);
v2 = HTlookup(*a1, a2, v4);
}
return v2;
}

original_code:
errorCode cacheTouch(cache * c, void * key){
  int slot;
  if(HTlookup(c -> ht, (void*)key, (void**)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void*)key, (void**)&slot); };
  updateAccessTime(c -> lsc, slot);
  return 1;
}

canonical_original_code:
int cacheTouch(struct cache_tag *c, void *key){
  int slot;
  if(HTlookup(c -> ht, (void *)key, (void **)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void *)key, (void **)&slot); };
  updateAccessTime(c -> lsc, slot);
  return 1;
}

variable_types: struct cache_tag { struct hashtable_tag { int size; int nr_rows; int busy; int maxsize; struct hashtableEntry_tag { unsigned int key; unsigned int data; int busy; struct hashtableEntry_tag *next; } *cur_entry; int scan_active; int cur_row; struct hashtableEntry_tag *free_pool; int next_free; struct hashtableEntry_tag **table; } *ht; struct limSizeCache_tag { int size; int pinpointed; int usage; void *dataSpace; struct accnt_tag { int used; int counter; struct timeval { long tv_sec; long tv_usec; } tv; void *key; void *data; int evict; void *bh; } *accntArray; } *lsc; } *

variable_types:
key
void *

variable_types: slot int

return_type: int

user_defined_types: struct cache_tag { struct hashtable_tag *ht; struct limSizeCache_tag *lsc; }

user_defined_types: struct hashtable_tag { int size; int nr_rows; int busy; int maxsize; struct hashtableEntry_tag *cur_entry; int scan_active; int cur_row; struct hashtableEntry_tag *free_pool; int next_free; struct hashtableEntry_tag **table; }

user_defined_types: struct limSizeCache_tag { int size; int pinpointed; int usage; void *dataSpace; struct accnt_tag *accntArray; }

user_defined_types: struct accnt_tag { int used; int counter; struct timeval tv; void *key; void *data; int evict; void *bh; }


cacheExtract

decompiled_code:
__int64 __fastcall cacheExtract(_QWORD *a1, __int64 a2)
{
unsigned int v2; // ebx
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTextract(*a1, a2, v4) == 1 )
{
v2 = 1;
cleanAccntInfo(a1[1], (unsigned int)v4[0]);
}
else
{
fflush(stderr);
v2 = HTextract(*a1, a2, v4);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int64 a2)
{
unsigned int v2; // ebx
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTextract(*a1, a2, v4) == 1 )
{
v2 = 1;
cleanAccntInfo(a1[1], (unsigned int)v4[0]);
}
else
{
fflush(stderr);
v2 = HTextract(*a1, a2, v4);
}
return v2;
}

original_code:
errorCode cacheExtract(cache * c, void * key){
  int slot;
  if(HTextract(c -> ht, (void*)key, (void**)&slot) != 1){ fflush(stderr); return HTextract(c -> ht, (void*)key, (void**)&slot); };
  cleanAccntInfo(c -> lsc, slot);
  return 1;
}

canonical_original_code:
int cacheExtract(struct cache_tag *c, void *key){
  int slot;
  if(HTextract(c -> ht, (void *)key, (void **)&slot) != 1){ fflush(stderr); return HTextract(c -> ht, (void *)key, (void **)&slot); };
  cleanAccntInfo(c -> lsc, slot);
  return 1;
}

user_defined_types: struct hashtableEntry_tag { unsigned int key; unsigned int data; int busy; struct hashtableEntry_tag *next; }

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


cacheProbe

decompiled_code:
__int64 __fastcall cacheProbe(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v5) == 1 )
{
result = getAccntInfo(a1[1], (unsigned int)v5[0], a3);
if ( (_DWORD)result != 1 )
{
fflush(stderr);
result = getAccntInfo(a1[1], (unsigned int)v5[0], a3);
}
}
else
{
fflush(stderr);
result = HTlookup(*a1, a2, v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v5) == 1 )
{
result = getAccntInfo(a1[1], (unsigned int)v5[0], a3);
if ( (_DWORD)result != 1 )
{
fflush(stderr);
result = getAccntInfo(a1[1], (unsigned int)v5[0], a3);
}
}
else
{
fflush(stderr);
result = HTlookup(*a1, a2, v5);
}
return result;
}

original_code:
errorCode cacheProbe(cache * c, void * key, accnt ** a){
  int slot;
  if(HTlookup(c -> ht, (void*)key, (void**)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void*)key, (void**)&slot); };
  if(getAccntInfo(c -> lsc, slot, a) != 1){ fflush(stderr); return getAccntInfo(c -> lsc, slot, a); };
  return 1;
}

canonical_original_code:
int cacheProbe(struct cache_tag *c, void *key, struct accnt_tag **a){
  int slot;
  if(HTlookup(c -> ht, (void *)key, (void **)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void *)key, (void **)&slot); };
  if(getAccntInfo(c -> lsc, slot, a) != 1){ fflush(stderr); return getAccntInfo(c -> lsc, slot, a); };
  return 1;
}

variable_types:
a
struct accnt_tag **


cacheCopy

decompiled_code:
__int64 __fastcall cacheCopy(_QWORD *a1, _QWORD *a2)
{
__int64 v3; // rdx
unsigned int v4; // er12
int v5; // eax
__int64 v6; // rdx
int v7; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v8; // [rsp+10h] [rbp-28h] BYREF
int v9[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

if ( !a1 || !a2 )
{
puts("Source or destination cache are null");
return 0xFFFFFFFFLL;
}
createHTscan(*a1);
while ( (unsigned int)HTadvanceScan(*a1, v9) != -1 )
{
if ( (unsigned int)HTextract(*a1, v9[0], &v8) != 1 )
{
fprintf(stderr, "%s\n", "Can not extract key in cacheCopy");
fflush(stderr);
}
v4 = v8;
v5 = HTlookup(*a2, v9[0], &v8);
v7 = v8;
if ( v5 == 1 )
{
pageFree(*(_QWORD *)(*(_QWORD *)(a2[1] + 24LL) + 56LL * (int)v8 + 32));
v3 = 56LL * (int)v4;
*(_QWORD *)(*(_QWORD *)(a2[1] + 24LL) + 56LL * v7 + 32) = *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + v3 + 32);
*(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + v3 + 32) = 0LL;
if ( (unsigned int)moveAttrib(a1[1], a2[1], v9[0], v4) != 1 )
goto LABEL_6;
}
else
{
if ( (unsigned int)cacheLookupFailedInsertSlot(a2, v9[0], (__int64)&v8, &v7) != 1 )
{
fprintf(stderr, "%s\n", "Error update in cacheCopy\n");
fflush(stderr);
}
v6 = 56LL * (int)v4;
*(_QWORD *)(*(_QWORD *)(a2[1] + 24LL) + 56LL * v7 + 32) = *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + v6 + 32);
*(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + v6 + 32) = 0LL;
if ( (unsigned int)moveAttrib(a1[1], a2[1], v9[0], v4) != 1 )
{
LABEL_6:
fprintf(stderr, "%s\n", "Error transferring attributes");
fflush(stderr);
}
}
}
destroyHTscan(*a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1, _QWORD *a2)
{
__int64 v3; // rdx
unsigned int v4; // er12
int v5; // eax
__int64 v6; // rdx
int v7; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v8; // [rsp+10h] [rbp-28h] BYREF
int v9[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

if ( !a1 || !a2 )
{
puts("Source or destination cache are null");
return 0xFFFFFFFFLL;
}
createHTscan(*a1);
while ( (unsigned int)HTadvanceScan(*a1, v9) != -1 )
{
if ( (unsigned int)HTextract(*a1, v9[0], &v8) != 1 )
{
fprintf(stderr, "%s\n", "Can not extract key in cacheCopy");
fflush(stderr);
}
v4 = v8;
v5 = HTlookup(*a2, v9[0], &v8);
v7 = v8;
if ( v5 == 1 )
{
pageFree(*(_QWORD *)(*(_QWORD *)(a2[1] + 24LL) + 56LL * (int)v8 + 32));
v3 = 56LL * (int)v4;
*(_QWORD *)(*(_QWORD *)(a2[1] + 24LL) + 56LL * v7 + 32) = *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + v3 + 32);
*(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + v3 + 32) = 0LL;
if ( (unsigned int)moveAttrib(a1[1], a2[1], v9[0], v4) != 1 )
goto LABEL_6;
}
else
{
if ( (unsigned int)func3(a2, v9[0], (__int64)&v8, &v7) != 1 )
{
fprintf(stderr, "%s\n", "Error update in cacheCopy\n");
fflush(stderr);
}
v6 = 56LL * (int)v4;
*(_QWORD *)(*(_QWORD *)(a2[1] + 24LL) + 56LL * v7 + 32) = *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + v6 + 32);
*(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + v6 + 32) = 0LL;
if ( (unsigned int)moveAttrib(a1[1], a2[1], v9[0], v4) != 1 )
{
LABEL_6:
fprintf(stderr, "%s\n", "Error transferring attributes");
fflush(stderr);
}
}
}
destroyHTscan(*a1);
return 1LL;
}

original_code:
errorCode cacheCopy(cache * src, cache * dest){
  int key;
  void * data;
  int res;
  int slotSrc, slotDest;
  if (!src || !dest){
    printf("Source or destination cache are null\n");
    return -1;
  }
  createHTscan(src -> ht);
  while (HTadvanceScan(src -> ht, (void *)&key) != -1){
    if(HTextract(src -> ht, (void*)key, (void **)&data) != 1){ fprintf(stderr, "%s\n", "Can not extract key in cacheCopy"); fflush(stderr); };
    slotSrc = (int)data;
    res = HTlookup(dest -> ht, (void*)key, (void **)&data);
    slotDest = (int)data;
    if (res == 1){
      pageFree((((dest -> lsc -> accntArray) + slotDest) -> data ));
      (((dest -> lsc -> accntArray) + slotDest) -> data ) = (((src -> lsc -> accntArray) + slotSrc) -> data );
      (((src -> lsc -> accntArray) + slotSrc) -> data ) = ((void *)0);
      if(moveAttrib(src -> lsc, dest -> lsc, (void*)key, slotSrc, slotDest) != 1){ fprintf(stderr, "%s\n", "Error transferring attributes"); fflush(stderr); };
    }
    else{
      if(cacheLookupFailedInsertSlot(dest, (void*)key, (void **)&data, &slotDest) != 1){ fprintf(stderr, "%s\n", "Error update in cacheCopy\n"); fflush(stderr); };
      (((dest -> lsc -> accntArray) + slotDest) -> data ) = (((src -> lsc -> accntArray) + slotSrc) -> data );
      (((src -> lsc -> accntArray) + slotSrc) -> data ) = ((void *)0);
      if(moveAttrib(src -> lsc, dest -> lsc, (void*)key, slotSrc, slotDest) != 1){ fprintf(stderr, "%s\n", "Error transferring attributes"); fflush(stderr); };
    }
  }
  destroyHTscan(src -> ht);
  return 1;
}

canonical_original_code:
int cacheCopy(struct cache_tag *src, struct cache_tag *dest){
  int key;
  void *data;
  int res;
  int slotSrc; int slotDest;
  if (!src || !dest){
    printf("Source or destination cache are null\n");
    return -1;
  }
  createHTscan(src -> ht);
  while (HTadvanceScan(src -> ht, (void *)&key) != -1){
    if(HTextract(src -> ht, (void *)key, (void **)&data) != 1){ fprintf(stderr, "%s\n", "Can not extract key in cacheCopy"); fflush(stderr); };
    slotSrc = (int)data;
    res = HTlookup(dest -> ht, (void *)key, (void **)&data);
    slotDest = (int)data;
    if (res == 1){
      pageFree((((dest -> lsc -> accntArray) + slotDest) -> data ));
      (((dest -> lsc -> accntArray) + slotDest) -> data ) = (((src -> lsc -> accntArray) + slotSrc) -> data );
      (((src -> lsc -> accntArray) + slotSrc) -> data ) = ((void *)0);
      if(moveAttrib(src -> lsc, dest -> lsc, (void *)key, slotSrc, slotDest) != 1){ fprintf(stderr, "%s\n", "Error transferring attributes"); fflush(stderr); };
    }
    else{
      if(cacheLookupFailedInsertSlot(dest, (void *)key, (void **)&data, &slotDest) != 1){ fprintf(stderr, "%s\n", "Error update in cacheCopy\n"); fflush(stderr); };
      (((dest -> lsc -> accntArray) + slotDest) -> data ) = (((src -> lsc -> accntArray) + slotSrc) -> data );
      (((src -> lsc -> accntArray) + slotSrc) -> data ) = ((void *)0);
      if(moveAttrib(src -> lsc, dest -> lsc, (void *)key, slotSrc, slotDest) != 1){ fprintf(stderr, "%s\n", "Error transferring attributes"); fflush(stderr); };
    }
  }
  destroyHTscan(src -> ht);
  return 1;
}

variable_types:
dest
struct cache_tag *

variable_types: key int

variable_types:
data
void *

variable_types: res int

variable_types: slotSrc int

variable_types: slotDest int


cacheDestroy

decompiled_code:
__int64 __fastcall cacheDestroy(_QWORD *a1)
{
destroyCache(*a1 + 8LL);
deleteHashtable(*a1);
memFree(*a1);
*a1 = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
destroyCache(*a1 + 8LL);
deleteHashtable(*a1);
memFree(*a1);
*a1 = 0LL;
return 1LL;
}

original_code:
errorCode cacheDestroy(cache ** c){
  destroyCache(& ((*c) -> lsc));
  deleteHashtable(& ((*c) -> ht ));
  memFree(*c);
  *c = ((void *)0);
  return 1;
}

canonical_original_code:
int cacheDestroy(struct cache_tag **c){
  destroyCache(& ((*c) -> lsc));
  deleteHashtable(& ((*c) -> ht ));
  memFree(*c);
  *c = ((void *)0);
  return 1;
}

variable_types: struct cache_tag { struct hashtable_tag { int size; int nr_rows; int busy; int maxsize; struct hashtableEntry_tag { unsigned int key; unsigned int data; int busy; struct hashtableEntry_tag *next; } *cur_entry; int scan_active; int cur_row; struct hashtableEntry_tag *free_pool; int next_free; struct hashtableEntry_tag **table; } *ht; struct limSizeCache_tag { int size; int pinpointed; int usage; void *dataSpace; struct accnt_tag { int used; int counter; struct timeval { long tv_sec; long tv_usec; } tv; void *key; void *data; int evict; void *bh; } *accntArray; } *lsc; } **


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rbp
__int64 i; // rbx
char v7[4]; // [rsp+4h] [rbp-24h] BYREF
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v8[0] = 0LL;
if ( (unsigned int)createHashtable(1024LL, &compareBlockNumberNoPointer, 0LL, 0LL, v8) == -1 )
{
fprintf(stderr, "%s\n", "Error allocating hashtable");
fflush(stderr);
exit(1);
}
if ( (unsigned int)HTinsert(v8[0], 100LL, 0LL) == -1 )
{
fprintf(stderr, "%s\n", "Error inserting");
fflush(stderr);
exit(1);
}
printHashtableContent(stdout, v8[0], &unk_219);
if ( (unsigned int)HTextract(v8[0], 100LL, v7) == -1 )
{
fprintf(stderr, "%s\n", "Error deleting");
fflush(stderr);
exit(1);
}
v3 = 0LL;
v4 = 0LL;
do
{
if ( (unsigned int)HTinsert(v8[0], v4, v3) == -1 )
{
fprintf(stderr, "%s\n", "Error inserting");
fflush(stderr);
exit(1);
}
v4 += 100LL;
v3 += 10LL;
}
while ( v3 != 50000 );
for ( i = 0LL; i != 500000; i += 100LL )
{
if ( (unsigned int)HTextract(v8[0], i, v7) == -1 )
{
fprintf(stderr, "%s\n", "Error deleting");
fflush(stderr);
exit(1);
}
}
return 0;
}

original_code:
int main(void){
  hashtable * ht = ((void *)0);
  int numberEntries = 1024;
  errorCode result;
  int values = 100;
  int i = 0;
  int data;
  int key, empty;
  result = createHashtable(numberEntries, compareBlockNumberNoPointer, ((void *)0), ((void *)0), &ht);
  if(result == -1){ fprintf(stderr, "%s\n", "Error allocating hashtable"); fflush(stderr); exit(1); };
  result = HTinsert(ht, 100, i * 10);
  if(result == -1){ fprintf(stderr, "%s\n", "Error inserting"); fflush(stderr); exit(1); };
  printHashtableContent(stdout, ht, "");
  result = HTextract(ht, 100, &data);
  if(result == -1){ fprintf(stderr, "%s\n", "Error deleting"); fflush(stderr); exit(1); };
  for (i = 0 ; i < 5000; i++){
    result = HTinsert(ht, i * 100, i * 10);
    if(result == -1){ fprintf(stderr, "%s\n", "Error inserting"); fflush(stderr); exit(1); };
  }
  for (i = 0 ; i < 5000; i++){
    result = HTextract(ht, i * 100, &data);
    if(result == -1){ fprintf(stderr, "%s\n", "Error deleting"); fflush(stderr); exit(1); };
  }
  return 0;
  printf("Data extracted %d\n", data);
  printHashtableContent(stdout, ht, "");
  result = HTlookup(ht, 100, &data);
  printf("return of lookup %d\n", result);
  fflush(stdout);
  createHTscan(ht);
  while (HTadvanceScan(ht, &key) != -1){
    HTlookup(ht, key, &data);
    printf("Lookup %d\n", data);
    HTextract(ht, key, &data);
    printf("Extracted %d\n", data);
  }
  printHashtableContent(stdout, ht, "");
  destroyHTscan(ht);
  HTempty(ht, &empty);
  printf("creating scan again %d\n", empty);
  createHTscan(ht);
  while (HTadvanceScan(ht, &key) != -1){
    result = HTlookup(ht, key, &data);
    printf("Lookup %d %d\n", data, result);
    fflush(stdout);
    result = HTextract(ht, key, &data);
    printf("Extracted %d %d\n", data, result);
    fflush(stdout);
  }
  destroyHTscan(ht);
  printf("destroying scan again\n");
  fflush(stdout);
  if (ht == ((void *)0)){
    printf("ht null \n");
    fflush(stdout);
  }
  deleteHashtable(&ht);
  return 0;
}

canonical_original_code:
int main(){
  struct hashtable_tag *ht = ((void *)0);
  int numberEntries = 1024;
  int result;
  int values = 100;
  int i = 0;
  int data;
  int key; int empty;
  result = createHashtable(numberEntries, compareBlockNumberNoPointer, ((void *)0), ((void *)0), &ht);
  if(result == -1){ fprintf(stderr, "%s\n", "Error allocating hashtable"); fflush(stderr); exit(1); };
  result = HTinsert(ht, 100, i * 10);
  if(result == -1){ fprintf(stderr, "%s\n", "Error inserting"); fflush(stderr); exit(1); };
  printHashtableContent(stdout, ht, "");
  result = HTextract(ht, 100, &data);
  if(result == -1){ fprintf(stderr, "%s\n", "Error deleting"); fflush(stderr); exit(1); };
  for (i = 0 ; i < 5000; i++){
    result = HTinsert(ht, i * 100, i * 10);
    if(result == -1){ fprintf(stderr, "%s\n", "Error inserting"); fflush(stderr); exit(1); };
  }
  for (i = 0 ; i < 5000; i++){
    result = HTextract(ht, i * 100, &data);
    if(result == -1){ fprintf(stderr, "%s\n", "Error deleting"); fflush(stderr); exit(1); };
  }
  return 0;
  printf("Data extracted %d\n", data);
  printHashtableContent(stdout, ht, "");
  result = HTlookup(ht, 100, &data);
  printf("return of lookup %d\n", result);
  fflush(stdout);
  createHTscan(ht);
  while (HTadvanceScan(ht, &key) != -1){
    HTlookup(ht, key, &data);
    printf("Lookup %d\n", data);
    HTextract(ht, key, &data);
    printf("Extracted %d\n", data);
  }
  printHashtableContent(stdout, ht, "");
  destroyHTscan(ht);
  HTempty(ht, &empty);
  printf("creating scan again %d\n", empty);
  createHTscan(ht);
  while (HTadvanceScan(ht, &key) != -1){
    result = HTlookup(ht, key, &data);
    printf("Lookup %d %d\n", data, result);
    fflush(stdout);
    result = HTextract(ht, key, &data);
    printf("Extracted %d %d\n", data, result);
    fflush(stdout);
  }
  destroyHTscan(ht);
  printf("destroying scan again\n");
  fflush(stdout);
  if (ht == ((void *)0)){
    printf("ht null \n");
    fflush(stdout);
  }
  deleteHashtable(&ht);
  return 0;
}

variable_types: struct hashtable_tag { int size; int numberEntries; struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; } *table; int (*compare)(void *, void *, int *); int (*deallocKey)(void *); int (*deallocData)(void *); int scanActive; int crtEntryNr; struct hashtableEntry_tag *crtEntry; int advance; } *

variable_types: numberEntries int

variable_types: result int

variable_types: values int

variable_types: i int

variable_types: data int

variable_types: empty int

user_defined_types: struct hashtable_tag { int size; int numberEntries; struct hashtableEntry_tag *table; int (*compare)(void *, void *, int *); int (*deallocKey)(void *); int (*deallocData)(void *); int scanActive; int crtEntryNr; struct hashtableEntry_tag *crtEntry; int advance; }


allocHashtableEntry

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

*(_QWORD *)a3 = 0LL;
result = memAlloc(24LL, a3);
if ( (_DWORD)result == 1 )
{
**(_QWORD **)a3 = a1;
*(_QWORD *)(*(_QWORD *)a3 + 8LL) = a2;
*(_QWORD *)(*(_QWORD *)a3 + 16LL) = 0LL;
}
else
{
fflush(stderr);
result = memAlloc(24LL, a3);
}
return result;
}

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

*(_QWORD *)a3 = 0LL;
result = memAlloc(24LL, a3);
if ( (_DWORD)result == 1 )
{
**(_QWORD **)a3 = a1;
*(_QWORD *)(*(_QWORD *)a3 + 8LL) = a2;
*(_QWORD *)(*(_QWORD *)a3 + 16LL) = 0LL;
}
else
{
fflush(stderr);
result = memAlloc(24LL, a3);
}
return result;
}

original_code:
errorCode allocHashtableEntry(void * key, void * data, hashtableEntry ** hte){
  * hte = ((void *)0);
  if(memAlloc(sizeof(hashtableEntry), (void **)hte) != 1){ fflush(stderr); return memAlloc(sizeof(hashtableEntry), (void **)hte); };
  (*hte) -> key = key;
  (*hte) -> data = data;
  (*hte) -> next = ((void *)0);
  return 1;
}

canonical_original_code:
int allocHashtableEntry(void *key, void *data, struct hashtableEntry_tag **hte){
  * hte = ((void *)0);
  if(memAlloc(sizeof(hashtableEntry), (void **)hte) != 1){ fflush(stderr); return memAlloc(sizeof(hashtableEntry), (void **)hte); };
  (*hte) -> key = key;
  (*hte) -> data = data;
  (*hte) -> next = ((void *)0);
  return 1;
}

variable_types:
key
void *

variable_types: struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; } **


deallocHashtableEntry

decompiled_code:
__int64 __fastcall deallocHashtableEntry(__int64 a1)
{
if ( a1 )
memFree();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( a1 )
memFree();
return 1LL;
}

original_code:
errorCode deallocHashtableEntry(void * entry){
  if (entry == ((void *)0))
    return 1;
  memFree(entry);
  return 1;
}

canonical_original_code:
int deallocHashtableEntry(void *entry){
  if (entry == ((void *)0))
    return 1;
  memFree(entry);
  return 1;
}

variable_types:
entry
void *


deallocHashtableEntryFreeKeyAndData

decompiled_code:
__int64 __fastcall deallocHashtableEntryFreeKeyAndData(__int64 a1, _QWORD *a2)
{
void (*v2)(void); // rax
void (__fastcall *v3)(_QWORD); // rax

if ( !a2 )
return 1LL;
if ( *a2 )
{
v2 = *(void (**)(void))(a1 + 24);
if ( !v2 || (v2(), *a2) )
{
v3 = *(void (__fastcall **)(_QWORD))(a1 + 32);
if ( v3 )
v3(a2[1]);
}
}
memFree(a2);
return 1LL;
}

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

if ( !a2 )
return 1LL;
if ( *a2 )
{
v2 = *(void (**)(void))(a1 + 24);
if ( !v2 || (v2(), *a2) )
{
v3 = *(void (__fastcall **)(_QWORD))(a1 + 32);
if ( v3 )
v3(a2[1]);
}
}
memFree(a2);
return 1LL;
}

original_code:
errorCode deallocHashtableEntryFreeKeyAndData(hashtable * ht, void * entry){
  hashtableEntry * hte = (hashtableEntry *) entry;
  if (entry == ((void *)0))
    return 1;
  if (hte -> key != ((void *)0) && ht -> deallocKey)
    (ht -> deallocKey)(hte -> key);
  if (hte -> key != ((void *)0) && ht -> deallocData)
    (ht -> deallocData)(hte -> data);
  memFree(entry);
  return 1;
}

canonical_original_code:
int deallocHashtableEntryFreeKeyAndData(struct hashtable_tag *ht, void *entry){
  struct hashtableEntry_tag *hte = (hashtableEntry *) entry;
  if (entry == ((void *)0))
    return 1;
  if (hte -> key != ((void *)0) && ht -> deallocKey)
    (ht -> deallocKey)(hte -> key);
  if (hte -> key != ((void *)0) && ht -> deallocData)
    (ht -> deallocData)(hte -> data);
  memFree(entry);
  return 1;
}

variable_types: struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; } *


HTempty

decompiled_code:
__int64 __fastcall HTempty(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( a1 )
{
*a2 = *a1 == 0;
result = 1LL;
}
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a1 )
{
*a2 = *a1 == 0;
result = 1LL;
}
return result;
}

original_code:
errorCode HTempty(hashtable * ht, int * res){
  if (ht == ((void *)0))
    return -1;
  else {
    *res = (ht -> size == 0);
    return 1;
  }
}

canonical_original_code:
int HTempty(struct hashtable_tag *ht, int *res){
  if (ht == ((void *)0))
    return -1;
  else {
    *res = (ht -> size == 0);
    return 1;
  }
}

variable_types:
res
int *

user_defined_types: struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; }


HTsize

decompiled_code:
__int64 __fastcall HTsize(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int HTsize(hashtable * ht)
{
  if (ht == ((void *)0))
    return -1;
  else
    return ht->size;
}

canonical_original_code:
int HTsize(struct hashtable_tag *ht)
{
  if (ht == ((void *)0))
    return -1;
  else
    return ht->size;
}


scanForNonNullEntry

original_code:
errorCode scanForNonNullEntry(hashtable * ht){
  int notFound = 1;
  if (ht -> advance ||
      (!(ht -> advance) &&
       (ht -> crtEntry == ((void *)0)))){
    while (notFound){
      if (ht -> crtEntry == ((void *)0)){
 ht -> crtEntryNr ++;
 if (ht -> crtEntryNr >= ht -> numberEntries){
   return -1;
 }
 ht -> crtEntry = ht -> table[ht-> crtEntryNr].next;
      }
      else
 ht -> crtEntry = ht -> crtEntry -> next;
      notFound = (ht -> crtEntry == ((void *)0));
    }
    ht -> advance = 1;
    return 1;
  }
  else{
    ht -> advance = 1;
    if(ht -> crtEntry == ((void *)0))
      return -1;
    else
      return 1;
  }
}

canonical_original_code:
int scanForNonNullEntry(struct hashtable_tag *ht){
  int notFound = 1;
  if (ht -> advance ||
      (!(ht -> advance) &&
       (ht -> crtEntry == ((void *)0)))){
    while (notFound){
      if (ht -> crtEntry == ((void *)0)){
 ht -> crtEntryNr ++;
 if (ht -> crtEntryNr >= ht -> numberEntries){
   return -1;
 }
 ht -> crtEntry = ht -> table[ht-> crtEntryNr].next;
      }
      else
 ht -> crtEntry = ht -> crtEntry -> next;
      notFound = (ht -> crtEntry == ((void *)0));
    }
    ht -> advance = 1;
    return 1;
  }
  else{
    ht -> advance = 1;
    if(ht -> crtEntry == ((void *)0))
      return -1;
    else
      return 1;
  }
}

variable_types: notFound int


createHTscan

original_code:
errorCode createHTscan(hashtable * ht){
  (ht) -> scanActive = 1;
  (ht) -> crtEntryNr = -1;
  (ht) -> crtEntry = ((void *)0);
  (ht) -> advance = 1;
  return 1;
}

canonical_original_code:
int createHTscan(struct hashtable_tag *ht){
  (ht) -> scanActive = 1;
  (ht) -> crtEntryNr = -1;
  (ht) -> crtEntry = ((void *)0);
  (ht) -> advance = 1;
  return 1;
}


HTadvanceScan

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

result = scanForNonNullEntry(a1);
v3 = 0LL;
if ( (_DWORD)result == 1 )
v3 = **(_QWORD **)(a1 + 48);
*a2 = v3;
return result;
}

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

result = func5(a1);
v3 = 0LL;
if ( (_DWORD)result == 1 )
v3 = **(_QWORD **)(a1 + 48);
*a2 = v3;
return result;
}

original_code:
errorCode HTadvanceScan(hashtable * ht, void ** key){
  int res = -1;
  res = scanForNonNullEntry(ht);
  if (res == 1)
    *key = ht -> crtEntry -> key;
  else
    *key = ((void *)0);
  return res;
}

canonical_original_code:
int HTadvanceScan(struct hashtable_tag *ht, void **key){
  int res = -1;
  res = scanForNonNullEntry(ht);
  if (res == 1)
    *key = ht -> crtEntry -> key;
  else
    *key = ((void *)0);
  return res;
}

variable_types:
key
void **

variable_types: res int


destroyHTscan

original_code:
errorCode destroyHTscan(hashtable * ht){
  (ht) -> scanActive = 0;
  (ht) -> crtEntryNr = -1;
  (ht) -> crtEntry = ((void *)0);
  (ht) -> advance = 1;
  return 1;
}

canonical_original_code:
int destroyHTscan(struct hashtable_tag *ht){
  (ht) -> scanActive = 0;
  (ht) -> crtEntryNr = -1;
  (ht) -> crtEntry = ((void *)0);
  (ht) -> advance = 1;
  return 1;
}


compareBlockNumberNoPointer

decompiled_code:
__int64 __fastcall compareBlockNumberNoPointer(int a1, int a2, _DWORD *a3)
{
*a3 = a1 != a2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2, _DWORD *a3)
{
*a3 = a1 != a2;
return 1LL;
}

original_code:
errorCode compareBlockNumberNoPointer(void * k1, void * k2, int * result){
  unsigned int key1 = (int)k1;
  unsigned int key2 = (int)k2;
  if (key1 == key2)
    *result = 0;
  else
    *result = 1;
  return 1;
}

canonical_original_code:
int compareBlockNumberNoPointer(void *k1, void *k2, int *result){
  unsigned int key1 = (int)k1;
  unsigned int key2 = (int)k2;
  if (key1 == key2)
    *result = 0;
  else
    *result = 1;
  return 1;
}

variable_types:
result
int *


createHashtable

decompiled_code:
__int64 __fastcall createHashtable(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned int v8; // ecx
__int64 v10; // rax

if ( (unsigned int)memAlloc(64LL, a5) == 1 )
{
*(_DWORD *)(*(_QWORD *)a5 + 40LL) = 0;
*(_QWORD *)(*(_QWORD *)a5 + 48LL) = 0LL;
*(_DWORD *)(*(_QWORD *)a5 + 44LL) = -1;
*(_DWORD *)(*(_QWORD *)a5 + 56LL) = 1;
**(_DWORD **)a5 = 0;
*(_DWORD *)(*(_QWORD *)a5 + 4LL) = a1;
v8 = memAlloc((unsigned int)(24 * a1), *(_QWORD *)a5 + 8LL);
if ( v8 == 1 )
{
if ( a1 > 0 )
{
v10 = 0LL;
do
{
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)a5 + 8LL) + v10 + 16) = 0LL;
v10 += 24LL;
}
while ( v10 != 24LL * (unsigned int)a1 );
}
*(_QWORD *)(*(_QWORD *)a5 + 16LL) = a2;
*(_QWORD *)(*(_QWORD *)a5 + 24LL) = a3;
*(_QWORD *)(*(_QWORD *)a5 + 32LL) = a4;
}
else
{
fflush(stderr);
v8 = memAlloc((unsigned int)(24 * a1), *(_QWORD *)a5 + 8LL);
}
}
else
{
fflush(stderr);
v8 = memAlloc(64LL, a5);
}
return v8;
}

original_code:
errorCode createHashtable(int numberEntries, keyCompareFunction compare, deallocKeyFunction deallocK, deallocDataFunction deallocD, hashtable ** ht ){
  int i = 0;
  if(memAlloc(sizeof(hashtable), (void**)ht) != 1){ fflush(stderr); return memAlloc(sizeof(hashtable), (void**)ht); };
  (*ht) -> scanActive = 0;
  (*ht) -> crtEntry = ((void *)0);
  (*ht) -> crtEntryNr = -1;
  (*ht) -> advance = 1;
  (*ht) -> size = 0;
  (*ht) -> numberEntries = numberEntries;
  if(memAlloc(numberEntries * sizeof(hashtableEntry), (void **)&((*ht) -> table)) != 1){ fflush(stderr); return memAlloc(numberEntries * sizeof(hashtableEntry), (void **)&((*ht) -> table)); };
  for(i = 0; i < numberEntries; i++){
    (((*ht) -> table)[i]).next = ((void *)0);
  }
  (*ht) -> compare = compare;
  (*ht) -> deallocKey = deallocK;
  (*ht) -> deallocData = deallocD;
  return 1;
}

canonical_original_code:
int createHashtable(int numberEntries, int (*compare)(void *, void *, int *), int (*deallocK)(void *), int (*deallocD)(void *), struct hashtable_tag **ht){
  int i = 0;
  if(memAlloc(sizeof(hashtable), (void **)ht) != 1){ fflush(stderr); return memAlloc(sizeof(hashtable), (void **)ht); };
  (*ht) -> scanActive = 0;
  (*ht) -> crtEntry = ((void *)0);
  (*ht) -> crtEntryNr = -1;
  (*ht) -> advance = 1;
  (*ht) -> size = 0;
  (*ht) -> numberEntries = numberEntries;
  if(memAlloc(numberEntries * sizeof(hashtableEntry), (void **)&((*ht) -> table)) != 1){ fflush(stderr); return memAlloc(numberEntries * sizeof(hashtableEntry), (void **)&((*ht) -> table)); };
  for(i = 0; i < numberEntries; i++){
    (((*ht) -> table)[i]).next = ((void *)0);
  }
  (*ht) -> compare = compare;
  (*ht) -> deallocKey = deallocK;
  (*ht) -> deallocData = deallocD;
  return 1;
}

variable_types:
compare
int (*)(void *, void *, int *)

variable_types:
deallocK
int (*)(void *)

variable_types:
deallocD
int (*)(void *)

variable_types: struct hashtable_tag { int size; int numberEntries; struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; } *table; int (*compare)(void *, void *, int *); int (*deallocKey)(void *); int (*deallocData)(void *); int scanActive; int crtEntryNr; struct hashtableEntry_tag *crtEntry; int advance; } **


deleteHashtable

decompiled_code:
__int64 __fastcall deleteHashtable(_QWORD *a1)
{
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // rbx
__int64 v5; // rdi

printf("%d\n", *(unsigned int *)(*a1 + 4LL));
v2 = *a1;
if ( *(int *)(*a1 + 4LL) > 0 )
{
v3 = 0LL;
do
{
printf("Deallocating %d\n", (unsigned int)v3);
v4 = *(_QWORD *)(*(_QWORD *)(*a1 + 8LL) + 24 * v3 + 16);
while ( v4 )
{
v5 = v4;
v4 = *(_QWORD *)(v4 + 16);
deallocHashtableEntry(v5);
}
v2 = *a1;
++v3;
}
while ( *(_DWORD *)(*a1 + 4LL) > (int)v3 );
}
memFree(*(_QWORD *)(v2 + 8));
memFree(*a1);
*a1 = 0LL;
return 1LL;
}

original_code:
errorCode deleteHashtable(hashtable ** ht){
  int i;
  hashtableEntry * temp, *successor;;
  printf("%d\n", (*ht) -> numberEntries);
  for(i = 0; i < (*ht) -> numberEntries; i++){
    printf("Deallocating %d\n", i);
    temp = (((*ht) -> table)[i]).next;
    successor = ((void *)0);
    while(temp != ((void *)0)){
      successor = temp -> next;
      deallocHashtableEntry(temp);
      temp = successor;
    }
  }
  memFree((*ht) -> table);
  memFree(*ht);
  *ht = ((void *)0);
  return 1;
}

canonical_original_code:
int deleteHashtable(struct hashtable_tag **ht){
  int i;
  struct hashtableEntry_tag *temp; struct hashtableEntry_tag *successor;;
  printf("%d\n", (*ht) -> numberEntries);
  for(i = 0; i < (*ht) -> numberEntries; i++){
    printf("Deallocating %d\n", i);
    temp = (((*ht) -> table)[i]).next;
    successor = ((void *)0);
    while(temp != ((void *)0)){
      successor = temp -> next;
      deallocHashtableEntry(temp);
      temp = successor;
    }
  }
  memFree((*ht) -> table);
  memFree(*ht);
  *ht = ((void *)0);
  return 1;
}


deleteHashtableAndData

decompiled_code:
__int64 __fastcall deleteHashtableAndData(__int64 *a1)
{
__int64 v1; // rdx
__int64 v2; // r12
_QWORD *v3; // rbx
_QWORD *v4; // rsi

v1 = *a1;
if ( *(int *)(*a1 + 4) > 0 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD **)(*(_QWORD *)(v1 + 8) + 24 * v2 + 16);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[2];
deallocHashtableEntryFreeKeyAndData(*a1, v4);
}
v1 = *a1;
++v2;
}
while ( *(_DWORD *)(*a1 + 4) > (int)v2 );
}
memFree(*(_QWORD *)(v1 + 8));
memFree(*a1);
*a1 = 0LL;
return 1LL;
}

original_code:
errorCode deleteHashtableAndData(hashtable ** ht){
  int i;
  for(i = 0; i < (*ht) -> numberEntries; i++){
    hashtableEntry * temp = (((*ht) -> table)[i]).next, * successor = ((void *)0);
    while(temp != ((void *)0)){
      successor = temp -> next;
      deallocHashtableEntryFreeKeyAndData(*ht, temp);
      temp = successor;
    }
  }
  memFree((*ht) -> table);
  memFree(*ht);
  *ht = ((void *)0);
  return 1;
}

canonical_original_code:
int deleteHashtableAndData(struct hashtable_tag **ht){
  int i;
  for(i = 0; i < (*ht) -> numberEntries; i++){
    struct hashtableEntry_tag *temp = (((*ht) -> table)[i]).next; struct hashtableEntry_tag *successor = ((void *)0);
    while(temp != ((void *)0)){
      successor = temp -> next;
      deallocHashtableEntryFreeKeyAndData(*ht, temp);
      temp = successor;
    }
  }
  memFree((*ht) -> table);
  memFree(*ht);
  *ht = ((void *)0);
  return 1;
}


hashFunction

decompiled_code:
__int64 __fastcall hashFunction(__int64 a1, int a2, int *a3)
{
*a3 = a2 % *(_DWORD *)(a1 + 4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2, int *a3)
{
*a3 = a2 % *(_DWORD *)(a1 + 4);
return 1LL;
}

original_code:
errorCode hashFunction(hashtable * ht, void * key, int * entry){
  *entry = (((int)key) % (ht -> numberEntries));
 return 1;
}

canonical_original_code:
int hashFunction(struct hashtable_tag *ht, void *key, int *entry){
  *entry = (((int)key) % (ht -> numberEntries));
 return 1;
}

variable_types: struct hashtable_tag { int size; int numberEntries; struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; } *table; int (*compare)(void *, void *, int *); int (*deallocKey)(void *); int (*deallocData)(void *); int scanActive; int crtEntryNr; struct hashtableEntry_tag *crtEntry; int advance; } *

variable_types:
entry
int *


listLookup

decompiled_code:
__int64 __fastcall listLookup(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(__int64, _QWORD, int *), _QWORD *a4)
{
_QWORD *v6; // rbx
__int64 result; // rax
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

*a4 = a1;
v6 = *(_QWORD **)(a1 + 16);
if ( !v6 )
return 0xFFFFFFFFLL;
while ( 1 )
{
result = a3(a2, *v6, v8);
if ( (_DWORD)result != 1 )
break;
if ( !v8[0] )
return result;
*a4 = v6;
v6 = (_QWORD *)v6[2];
if ( !v6 )
return 0xFFFFFFFFLL;
}
fflush(stderr);
return a3(a2, *v6, v8);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(__int64, _QWORD, int *), _QWORD *a4)
{
_QWORD *v6; // rbx
__int64 result; // rax
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

*a4 = a1;
v6 = *(_QWORD **)(a1 + 16);
if ( !v6 )
return 0xFFFFFFFFLL;
while ( 1 )
{
result = a3(a2, *v6, v8);
if ( (_DWORD)result != 1 )
break;
if ( !v8[0] )
return result;
*a4 = v6;
v6 = (_QWORD *)v6[2];
if ( !v6 )
return 0xFFFFFFFFLL;
}
fflush(stderr);
return a3(a2, *v6, v8);
}

original_code:
errorCode listLookup(hashtableEntry * start, void * key, keyCompareFunction
    compare, hashtableEntry ** predecessor){
  errorCode result = -1;
  int resultCompare;
  *predecessor = start;
  start = start -> next;
  while(start != ((void *)0)){
    if(compare(key, start -> key, &resultCompare) != 1){ fflush(stderr); return compare(key, start -> key, &resultCompare); };
    if (resultCompare == 0){
      result = 1;
      return result;
    }
    *predecessor = start;
    start = start -> next;
  }
  return -1;
}

canonical_original_code:
int listLookup(struct hashtableEntry_tag *start, void *key, int (*compare)(void *, void *, int *), struct hashtableEntry_tag **predecessor){
  int result = -1;
  int resultCompare;
  *predecessor = start;
  start = start -> next;
  while(start != ((void *)0)){
    if(compare(key, start -> key, &resultCompare) != 1){ fflush(stderr); return compare(key, start -> key, &resultCompare); };
    if (resultCompare == 0){
      result = 1;
      return result;
    }
    *predecessor = start;
    start = start -> next;
  }
  return -1;
}

variable_types:
predecessor
struct hashtableEntry_tag **

variable_types: result int

variable_types: resultCompare int


HTupdate

original_code:
errorCode HTupdate(hashtable * ht, void * key, void * data, void ** old_data){
  errorCode result = -1;
  hashtableEntry * predecessor = ((void *)0);
  hashtableEntry * hte;
  int position;
  allocHashtableEntry(key, data, &hte);
  result = hashFunction(ht, hte -> key, &position);
  if(result != 1){ fflush(stderr); return result; };
  result = listLookup((ht -> table) + position, hte -> key, ht -> compare, &predecessor);
  if (result == 1){
    * old_data = predecessor -> next -> data;
    deallocHashtableEntry(hte);
    return -2;
  }
  hte -> next = (ht -> table)[position].next;
  (ht -> table)[position].next = hte;
  (ht -> size) ++;
  return 1;
}

canonical_original_code:
int HTupdate(struct hashtable_tag *ht, void *key, void *data, void **old_data){
  int result = -1;
  struct hashtableEntry_tag *predecessor = ((void *)0);
  struct hashtableEntry_tag *hte;
  int position;
  allocHashtableEntry(key, data, &hte);
  result = hashFunction(ht, hte -> key, &position);
  if(result != 1){ fflush(stderr); return result; };
  result = listLookup((ht -> table) + position, hte -> key, ht -> compare, &predecessor);
  if (result == 1){
    * old_data = predecessor -> next -> data;
    deallocHashtableEntry(hte);
    return -2;
  }
  hte -> next = (ht -> table)[position].next;
  (ht -> table)[position].next = hte;
  (ht -> size) ++;
  return 1;
}

variable_types:
key
void *

variable_types:
data
void *

variable_types: position int


HTinsert

decompiled_code:
__int64 __fastcall HTinsert(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v3; // ebp
__int64 v5; // rax
__int64 *v6; // rdx
int v7; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 *v8; // [rsp+10h] [rbp-28h] BYREF
__int64 v9[4]; // [rsp+18h] [rbp-20h] BYREF

v9[0] = 0LL;
allocHashtableEntry(a2, a3, (__int64)&v8);
v3 = hashFunction(a1, *v8, &v7);
if ( v3 == 1 )
{
if ( (unsigned int)listLookup(
*(_QWORD *)(a1 + 8) + 24LL * v7,
*v8,
*(__int64 (__fastcall **)(__int64, _QWORD, int *))(a1 + 16),
v9) == 1 )
{
deallocHashtableEntry((__int64)v8);
v3 = -2;
}
else
{
v5 = 24LL * v7;
v6 = v8;
v8[2] = *(_QWORD *)(*(_QWORD *)(a1 + 8) + v5 + 16);
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v5 + 16) = v6;
++*(_DWORD *)a1;
}
}
else
{
fflush(stderr);
}
return v3;
}

original_code:
errorCode HTinsert(hashtable * ht, void * key, void * data){
  errorCode result = -1;
  hashtableEntry * predecessor = ((void *)0);
  hashtableEntry * hte;
  int position;
  allocHashtableEntry(key, data, &hte);
  result = hashFunction(ht, hte -> key, &position);
  if(result != 1){ fflush(stderr); return result; };
  result = listLookup((ht -> table) + position, hte -> key, ht -> compare, &predecessor);
  if (result == 1){
    deallocHashtableEntry(hte);
    return -2;
  }
  hte -> next = (ht -> table)[position].next;
  (ht -> table)[position].next = hte;
  (ht -> size) ++;
  return 1;
}

canonical_original_code:
int HTinsert(struct hashtable_tag *ht, void *key, void *data){
  int result = -1;
  struct hashtableEntry_tag *predecessor = ((void *)0);
  struct hashtableEntry_tag *hte;
  int position;
  allocHashtableEntry(key, data, &hte);
  result = hashFunction(ht, hte -> key, &position);
  if(result != 1){ fflush(stderr); return result; };
  result = listLookup((ht -> table) + position, hte -> key, ht -> compare, &predecessor);
  if (result == 1){
    deallocHashtableEntry(hte);
    return -2;
  }
  hte -> next = (ht -> table)[position].next;
  (ht -> table)[position].next = hte;
  (ht -> size) ++;
  return 1;
}

variable_types: struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; } *


HTextract

original_code:
errorCode HTextract(hashtable * ht, void * key, void ** data){
  int entry = -1;
  errorCode result = -1;
  hashtableEntry * predecessor = ((void *)0), * deletedEntry;
  errorCode resultComp = -1;
  result = hashFunction(ht, key, &entry);
  if(result != 1){ fflush(stderr); return result; };
  result = listLookup((ht -> table) + entry, key, ht -> compare, &predecessor);
  if (result == 1){
    if (ht -> scanActive && ht -> crtEntry){
      if(ht -> compare(ht -> crtEntry -> key, key, &resultComp) != 1){ fflush(stderr); return ht -> compare(ht -> crtEntry -> key, key, &resultComp); };
      if (!resultComp){
 ht -> advance = 0;
 ht -> crtEntry = predecessor -> next -> next;
      }
    }
    deletedEntry = predecessor -> next;
    * data = deletedEntry -> data;
    predecessor -> next = deletedEntry -> next;
    (ht -> size) --;
    deallocHashtableEntry(deletedEntry);
  }
  return result;
}

canonical_original_code:
int HTextract(struct hashtable_tag *ht, void *key, void **data){
  int entry = -1;
  int result = -1;
  struct hashtableEntry_tag *predecessor = ((void *)0); struct hashtableEntry_tag *deletedEntry;
  int resultComp = -1;
  result = hashFunction(ht, key, &entry);
  if(result != 1){ fflush(stderr); return result; };
  result = listLookup((ht -> table) + entry, key, ht -> compare, &predecessor);
  if (result == 1){
    if (ht -> scanActive && ht -> crtEntry){
      if(ht -> compare(ht -> crtEntry -> key, key, &resultComp) != 1){ fflush(stderr); return ht -> compare(ht -> crtEntry -> key, key, &resultComp); };
      if (!resultComp){
 ht -> advance = 0;
 ht -> crtEntry = predecessor -> next -> next;
      }
    }
    deletedEntry = predecessor -> next;
    * data = deletedEntry -> data;
    predecessor -> next = deletedEntry -> next;
    (ht -> size) --;
    deallocHashtableEntry(deletedEntry);
  }
  return result;
}

variable_types:
data
void **

variable_types: entry int

variable_types: resultComp int


HTlookup

decompiled_code:
__int64 __fastcall HTlookup(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 result; // rax
__int64 v5; // [rsp+0h] [rbp-28h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = -1;
v5 = 0LL;
*a3 = 0LL;
if ( (unsigned int)hashFunction(a1, a2, v6) != 1 )
{
fprintf(stderr, "%s\n", "Error hash");
fflush(stderr);
}
result = listLookup(
*(_QWORD *)(a1 + 8) + 24LL * v6[0],
a2,
*(__int64 (__fastcall **)(__int64, _QWORD, int *))(a1 + 16),
&v5);
if ( (_DWORD)result == 1 )
*a3 = *(_QWORD *)(*(_QWORD *)(v5 + 16) + 8LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 result; // rax
__int64 v5; // [rsp+0h] [rbp-28h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = -1;
v5 = 0LL;
*a3 = 0LL;
if ( (unsigned int)func13(a1, a2, v6) != 1 )
{
fprintf(stderr, "%s\n", "Error hash");
fflush(stderr);
}
result = func14(
*(_QWORD *)(a1 + 8) + 24LL * v6[0],
a2,
*(__int64 (__fastcall **)(__int64, _QWORD, int *))(a1 + 16),
&v5);
if ( (_DWORD)result == 1 )
*a3 = *(_QWORD *)(*(_QWORD *)(v5 + 16) + 8LL);
return result;
}

original_code:
errorCode HTlookup(hashtable * ht, void * key, void ** data){
  int entry = -1;
  errorCode result = -1;
  hashtableEntry * predecessor = ((void *)0), * lookupEntry;
  *data = ((void *)0);
  result = hashFunction(ht, key, &entry);
  if(result != 1){ fprintf(stderr, "%s\n", "Error hash"); fflush(stderr); };
  result = listLookup((ht -> table) + entry, key, ht -> compare, &predecessor);
  if (result == 1){
    lookupEntry = predecessor -> next;
    * data = lookupEntry -> data;
  }
  return result;
}

canonical_original_code:
int HTlookup(struct hashtable_tag *ht, void *key, void **data){
  int entry = -1;
  int result = -1;
  struct hashtableEntry_tag *predecessor = ((void *)0); struct hashtableEntry_tag *lookupEntry;
  *data = ((void *)0);
  result = hashFunction(ht, key, &entry);
  if(result != 1){ fprintf(stderr, "%s\n", "Error hash"); fflush(stderr); };
  result = listLookup((ht -> table) + entry, key, ht -> compare, &predecessor);
  if (result == 1){
    lookupEntry = predecessor -> next;
    * data = lookupEntry -> data;
  }
  return result;
}


lookup

decompiled_code:
__int64 __fastcall lookup(__int64 a1, __int64 a2, _QWORD *a3)
{
unsigned int v4; // eax
unsigned int v5; // ebx
__int64 v7; // [rsp+0h] [rbp-38h] BYREF
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v8[0] = -1;
v7 = 0LL;
*a3 = 0LL;
v4 = hashFunction(a1, a2, v8);
if ( v4 == 1 )
{
v5 = listLookup(
*(_QWORD *)(a1 + 8) + 24LL * v8[0],
a2,
*(__int64 (__fastcall **)(__int64, _QWORD, int *))(a1 + 16),
&v7);
if ( v5 == 1 )
*a3 = *(_QWORD *)(v7 + 16);
}
else
{
v5 = v4;
fflush(stderr);
}
return v5;
}

original_code:
errorCode lookup(hashtable * ht, void * key, hashtableEntry ** hte){
  int entry = -1;
  errorCode result = -1;
  hashtableEntry * predecessor = ((void *)0);
  *hte = ((void *)0);
  result = hashFunction(ht, key, &entry);
  if(result != 1){ fflush(stderr); return result; };
  result = listLookup((ht -> table) + entry, key, ht -> compare, &predecessor);
  if (result == 1)
    *hte = predecessor -> next;
  return result;
}

canonical_original_code:
int lookup(struct hashtable_tag *ht, void *key, struct hashtableEntry_tag **hte){
  int entry = -1;
  int result = -1;
  struct hashtableEntry_tag *predecessor = ((void *)0);
  *hte = ((void *)0);
  result = hashFunction(ht, key, &entry);
  if(result != 1){ fflush(stderr); return result; };
  result = listLookup((ht -> table) + entry, key, ht -> compare, &predecessor);
  if (result == 1)
    *hte = predecessor -> next;
  return result;
}

variable_types:
hte
struct hashtableEntry_tag **


printInfo

decompiled_code:
int __fastcall printInfo(const char *a1, int a2, __int64 a3)
{
__int64 i; // rbx

fprintf(stdout, "Values for %s\n", a1);
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
fprintf(stdout, " %s[%d] = %d\n", a1, (unsigned int)i, *(unsigned int *)(a3 + 4 * i));
}
fputc(10, stdout);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, int a2, __int64 a3)
{
__int64 i; // rbx

fprintf(stdout, "Values for %s\n", a1);
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
fprintf(stdout, " %s[%d] = %d\n", a1, (unsigned int)i, *(unsigned int *)(a3 + 4 * i));
}
fputc(10, stdout);
return fflush(stdout);
}

original_code:
void printInfo(char * name, int count, int * values){
  int i;
  fprintf(stdout, "Values for %s\n", name);
  for(i = 0; i < count; i++){
    fprintf(stdout, "  %s[%d] = %d\n", name, i, values[i]);
  }
  fprintf(stdout,"\n");
  fflush(stdout);
}

canonical_original_code:
void printInfo(char *name, int count, int *values){
  int i;
  fprintf(stdout, "Values for %s\n", name);
  for(i = 0; i < count; i++){
    fprintf(stdout, "  %s[%d] = %d\n", name, i, values[i]);
  }
  fprintf(stdout,"\n");
  fflush(stdout);
}

variable_types:
name
char *

variable_types: count int

variable_types:
values
int *

variable_types: i int

return_type: void


memAlloc

decompiled_code:
__int64 __fastcall memAlloc(int a1, _QWORD *a2)
{
void *v2; // rax

v2 = malloc(a1);
*a2 = v2;
return v2 == 0LL ? -1 : 1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, _QWORD *a2)
{
void *v2; // rax

v2 = malloc(a1);
*a2 = v2;
return v2 == 0LL ? -1 : 1;
}

original_code:
errorCode memAlloc(int size, void ** ptr){
  * ptr = ((void *)0);
  * ptr = malloc(size);
  if (*ptr == ((void *)0)){
    return -1;
  }
  return 1;
}

canonical_original_code:
int memAlloc(int size, void **ptr){
  * ptr = ((void *)0);
  * ptr = malloc(size);
  if (*ptr == ((void *)0)){
    return -1;
  }
  return 1;
}

variable_types: size int

variable_types:
ptr
void **


pageAlloc

decompiled_code:
__int64 __fastcall pageAlloc(int a1, _QWORD *a2)
{
return memAlloc(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, _QWORD *a2)
{
return func1(a1, a2);
}

original_code:
errorCode pageAlloc(int size, void ** ptr){
  return memAlloc(size, ptr);
}

canonical_original_code:
int pageAlloc(int size, void **ptr){
  return memAlloc(size, ptr);
}


printError

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

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
return fflush(stderr);
}

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

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
return fflush(stderr);
}

original_code:
void printError(const char *format, ...){
  int rc;
  va_list args;
  __builtin_va_start(args,format);
  rc = fprintf(stderr, "ERROR: ");
  vfprintf(stderr, format, args);
  fflush(stderr);
  __builtin_va_end(args);
}

canonical_original_code:
void printError(char *format, ...){
  int rc;
  __builtin_va_list args;
  __builtin_va_start(args,format);
  rc = fprintf(stderr, "ERROR: ");
  vfprintf(stderr, format, args);
  fflush(stderr);
  __builtin_va_end(args);
}

variable_types:
format
char *

variable_types: rc int


memFree

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

if ( a1 )
{
free(a1);
result = 1LL;
}
else
{
printError("%s\n", "trying to deallocate a NULL pointer");
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
free(a1);
result = 1LL;
}
else
{
func3("%s\n", "trying to deallocate a NULL pointer");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
errorCode memFree(void * ptr){
  if (ptr == ((void *)0)){
    printError("%s\n", "trying to deallocate a NULL pointer");
    return -1;
  }
  free(ptr);
  return 1;
}

canonical_original_code:
int memFree(void *ptr){
  if (ptr == ((void *)0)){
    printError("%s\n", "trying to deallocate a NULL pointer");
    return -1;
  }
  free(ptr);
  return 1;
}

variable_types:
ptr
void *


pageFree

decompiled_code:
__int64 __fastcall pageFree(void *a1)
{
return memFree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(void *a1)
{
return func4(a1);
}

original_code:
errorCode pageFree(void * p){
  return memFree(p);
}

canonical_original_code:
int pageFree(void *p){
  return memFree(p);
}

variable_types:
p
void *


printWarning

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

va_start(arg, format);
fwrite("WARNING: ", 1uLL, 9uLL, stderr);
vfprintf(stderr, format, arg);
return fflush(stderr);
}

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

va_start(arg, format);
fwrite("WARNING: ", 1uLL, 9uLL, stderr);
vfprintf(stderr, format, arg);
return fflush(stderr);
}

original_code:
void printWarning(const char *format, ...){
  int rc;
  va_list args;
  __builtin_va_start(args,format);
  fprintf(stderr, "WARNING: ");
  rc = vfprintf(stderr, format, args);
  fflush(stderr);
  __builtin_va_end(args);
}

canonical_original_code:
void printWarning(char *format, ...){
  int rc;
  __builtin_va_list args;
  __builtin_va_start(args,format);
  fprintf(stderr, "WARNING: ");
  rc = vfprintf(stderr, format, args);
  fflush(stderr);
  __builtin_va_end(args);
}


createLimCache

original_code:
errorCode createLimCache(int size, limSizeCache ** lsc){
  int i = 0;
  if(memAlloc(sizeof(limSizeCache), (void **)lsc) != 1){ fflush(stderr); return memAlloc(sizeof(limSizeCache), (void **)lsc); };
  if(memAlloc(size * sizeof(accnt), (void **)&((*lsc) -> accntArray)) != 1){ fflush(stderr); return memAlloc(size * sizeof(accnt), (void **)&((*lsc) -> accntArray)); };
  for (i = 0; i < size; i++){
    ((*lsc) -> accntArray)[i].used = -1;
    ((*lsc) -> accntArray)[i].key = ((void *)0);
    ((*lsc) -> accntArray)[i].tv.tv_sec = 0;
    ((*lsc) -> accntArray)[i].tv.tv_usec = 0;
    ((*lsc) -> accntArray)[i].data = ((void *)0);
    ((*lsc) -> accntArray)[i].bh = ((void *)0);
    ((*lsc) -> accntArray)[i].evict = 0;
  }
  (*lsc) -> size = size;
  (*lsc) -> usage = 0;
  return 1;
}

canonical_original_code:
int createLimCache(int size, struct limSizeCache_tag **lsc){
  int i = 0;
  if(memAlloc(sizeof(limSizeCache), (void **)lsc) != 1){ fflush(stderr); return memAlloc(sizeof(limSizeCache), (void **)lsc); };
  if(memAlloc(size * sizeof(accnt), (void **)&((*lsc) -> accntArray)) != 1){ fflush(stderr); return memAlloc(size * sizeof(accnt), (void **)&((*lsc) -> accntArray)); };
  for (i = 0; i < size; i++){
    ((*lsc) -> accntArray)[i].used = -1;
    ((*lsc) -> accntArray)[i].key = ((void *)0);
    ((*lsc) -> accntArray)[i].tv.tv_sec = 0;
    ((*lsc) -> accntArray)[i].tv.tv_usec = 0;
    ((*lsc) -> accntArray)[i].data = ((void *)0);
    ((*lsc) -> accntArray)[i].bh = ((void *)0);
    ((*lsc) -> accntArray)[i].evict = 0;
  }
  (*lsc) -> size = size;
  (*lsc) -> usage = 0;
  return 1;
}

variable_types: struct limSizeCache_tag { int size; int pinpointed; int usage; void *dataSpace; struct accnt_tag { int used; int counter; struct timeval { long tv_sec; long tv_usec; } tv; void *key; void *data; int evict; void *bh; } *accntArray; } **


findEmptySlot

decompiled_code:
__int64 __fastcall findEmptySlot(__int64 a1, _DWORD *a2)
{
_DWORD *v2; // rdx
int v3; // eax

if ( *(int *)a1 <= 0 )
return 0xFFFFFFFFLL;
v2 = *(_DWORD **)(a1 + 24);
v3 = 0;
while ( *v2 != -1 )
{
++v3;
v2 += 14;
if ( v3 == *(_DWORD *)a1 )
return 0xFFFFFFFFLL;
}
*a2 = v3;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _DWORD *a2)
{
_DWORD *v2; // rdx
int v3; // eax

if ( *(int *)a1 <= 0 )
return 0xFFFFFFFFLL;
v2 = *(_DWORD **)(a1 + 24);
v3 = 0;
while ( *v2 != -1 )
{
++v3;
v2 += 14;
if ( v3 == *(_DWORD *)a1 )
return 0xFFFFFFFFLL;
}
*a2 = v3;
return 1LL;
}

original_code:
errorCode findEmptySlot(limSizeCache * lsc, unsigned int * slot){
  int i = 0;
  for (i = 0; i < lsc -> size; i++){
    if ((((lsc -> accntArray) + i) -> used ) == -1){
      *slot = i;
      return 1;
    }
  }
  return -1;
}

canonical_original_code:
int findEmptySlot(struct limSizeCache_tag *lsc, unsigned int *slot){
  int i = 0;
  for (i = 0; i < lsc -> size; i++){
    if ((((lsc -> accntArray) + i) -> used ) == -1){
      *slot = i;
      return 1;
    }
  }
  return -1;
}

variable_types: struct limSizeCache_tag { int size; int pinpointed; int usage; void *dataSpace; struct accnt_tag { int used; int counter; struct timeval { long tv_sec; long tv_usec; } tv; void *key; void *data; int evict; void *bh; } *accntArray; } *

variable_types:
slot
unsigned int *


cleanAccntInfo

original_code:
errorCode cleanAccntInfo(limSizeCache * lsc, unsigned int slot){
  (((lsc -> accntArray) + slot) -> used ) = -1;
  (((lsc -> accntArray) + slot) -> key ) = ((void *)0);
  (((lsc -> accntArray) + slot) -> evict ) = 0;
  (((lsc -> accntArray) + slot) -> bh ) = ((void *)0);
  return 1;
}

canonical_original_code:
int cleanAccntInfo(struct limSizeCache_tag *lsc, unsigned int slot){
  (((lsc -> accntArray) + slot) -> used ) = -1;
  (((lsc -> accntArray) + slot) -> key ) = ((void *)0);
  (((lsc -> accntArray) + slot) -> evict ) = 0;
  (((lsc -> accntArray) + slot) -> bh ) = ((void *)0);
  return 1;
}

variable_types:
slot
unsigned int


getAccntInfo

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

result = 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 >= a2 )
{
*a3 = *(_QWORD *)(a1 + 24) + 56LL * a2;
result = 1LL;
}
return result;
}

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

result = 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 >= a2 )
{
*a3 = *(_QWORD *)(a1 + 24) + 56LL * a2;
result = 1LL;
}
return result;
}

original_code:
errorCode getAccntInfo(limSizeCache * lsc, unsigned int slot, accnt ** a){
  if (slot > lsc -> size || slot < 0)
    return -1;
  *a = ((((lsc) -> accntArray) + slot));
  return 1;
}

canonical_original_code:
int getAccntInfo(struct limSizeCache_tag *lsc, unsigned int slot, struct accnt_tag **a){
  if (slot > lsc -> size || slot < 0)
    return -1;
  *a = ((((lsc) -> accntArray) + slot));
  return 1;
}

variable_types:
a
struct accnt_tag **


copyData

decompiled_code:
__int64 __fastcall copyData(__int64 a1, unsigned int a2, char *a3)
{
__int64 v4; // rbp
__int64 v5; // rsi
_QWORD *v6; // rcx

v4 = 56LL * a2;
v5 = *(_QWORD *)(a1 + 24) + v4;
if ( !*(_QWORD *)(v5 + 32) && (unsigned int)pageAlloc(4096LL, v5 + 32) != 1 )
{
fprintf(stderr, "%s\n", "insertNewElementNoDataCopy: CAn not allocate memory for data");
fflush(stderr);
}
v6 = *(_QWORD **)(*(_QWORD *)(a1 + 24) + v4 + 32);
*v6 = *(_QWORD *)a3;
v6[511] = *((_QWORD *)a3 + 511);
qmemcpy(
(void *)((unsigned __int64)(v6 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a3 - ((char *)v6 - ((unsigned __int64)(v6 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v6 - (((_DWORD)v6 + 8) & 0xFFFFFFF8) + 4096) >> 3));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, char *a3)
{
__int64 v4; // rbp
__int64 v5; // rsi
_QWORD *v6; // rcx

v4 = 56LL * a2;
v5 = *(_QWORD *)(a1 + 24) + v4;
if ( !*(_QWORD *)(v5 + 32) && (unsigned int)pageAlloc(4096LL, v5 + 32) != 1 )
{
fprintf(stderr, "%s\n", "insertNewElementNoDataCopy: CAn not allocate memory for data");
fflush(stderr);
}
v6 = *(_QWORD **)(*(_QWORD *)(a1 + 24) + v4 + 32);
*v6 = *(_QWORD *)a3;
v6[511] = *((_QWORD *)a3 + 511);
qmemcpy(
(void *)((unsigned __int64)(v6 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a3 - ((char *)v6 - ((unsigned __int64)(v6 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v6 - (((_DWORD)v6 + 8) & 0xFFFFFFF8) + 4096) >> 3));
return 1LL;
}

original_code:
errorCode copyData(limSizeCache * lsc, unsigned int slot, void * data){
  if (!(((lsc -> accntArray) + slot) -> data )){
    if(pageAlloc(4096, &((((lsc -> accntArray) + slot) -> data ))) != 1){ fprintf(stderr, "%s\n", "insertNewElementNoDataCopy: CAn not allocate memory for data"); fflush(stderr); };
  }
  memcpy((((lsc -> accntArray) + slot) -> data ), data, 4096);
  return 1;
}

canonical_original_code:
int copyData(struct limSizeCache_tag *lsc, unsigned int slot, void *data){
  if (!(((lsc -> accntArray) + slot) -> data )){
    if(pageAlloc(4096, &((((lsc -> accntArray) + slot) -> data ))) != 1){ fprintf(stderr, "%s\n", "insertNewElementNoDataCopy: CAn not allocate memory for data"); fflush(stderr); };
  }
  memcpy((((lsc -> accntArray) + slot) -> data ), data, 4096);
  return 1;
}

variable_types:
data
void *


furtherInTime

decompiled_code:
_BOOL8 __fastcall furtherInTime(int a1, int a2, int a3, int a4)
{
return (float)((float)((float)a4 / 1000000.0) + (float)a3) > (float)((float)((float)a2 / 1000000.0) + (float)a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(int a1, int a2, int a3, int a4)
{
return (float)((float)((float)a4 / 1000000.0) + (float)a3) > (float)((float)((float)a2 / 1000000.0) + (float)a1);
}

original_code:
int furtherInTime(struct timeval tv1, struct timeval tv2){
  float t1, t2;
  t1 = tv1.tv_sec + (float)(tv1.tv_usec) / (float)1000000;
  t2 = tv2.tv_sec + (float)(tv2.tv_usec) / (float)1000000;
  if (t1 < t2)
    return 1;
  else
    return 0;
}

canonical_original_code:
int furtherInTime(struct timeval tv1, struct timeval tv2){
  float t1; float t2;
  t1 = tv1.tv_sec + (float)(tv1.tv_usec) / (float)1000000;
  t2 = tv2.tv_sec + (float)(tv2.tv_usec) / (float)1000000;
  if (t1 < t2)
    return 1;
  else
    return 0;
}

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


findEvictionCandidate

decompiled_code:
__int64 __fastcall findEvictionCandidate(__int64 a1, int *a2)
{
int v2; // er14
__int64 v3; // r12
unsigned int v4; // ebp
unsigned int v5; // er15
__int64 v6; // rbx
int v7; // eax
struct timeval tv; // [rsp+10h] [rbp-48h] BYREF

gettimeofday(&tv, 0LL);
v2 = *(_DWORD *)a1;
if ( *(int *)a1 <= 0 )
{
v7 = -1;
v5 = -1;
}
else
{
v3 = 0LL;
v4 = 0;
v5 = -1;
do
{
v6 = *(_QWORD *)(a1 + 24) + v3;
if ( *(_DWORD *)v6 && furtherInTime(*(_QWORD *)(v6 + 8), *(_QWORD *)(v6 + 16), tv.tv_sec, tv.tv_usec) )
{
tv = (struct timeval)_mm_loadu_si128((const __m128i *)(v6 + 8));
v5 = v4;
}
++v4;
v3 += 56LL;
}
while ( v4 != v2 );
v7 = -1;
if ( v5 != -1 )
{
v7 = v5;
v5 = 1;
}
}
*a2 = v7;
return v5;
}

original_code:
errorCode findEvictionCandidate(limSizeCache * lsc, unsigned int * slot){
  int tempSlot = -1;
  int i;
  struct timeval crtFurther;
  gettimeofday(&crtFurther, ((void *)0));
  for (i = 0; i < lsc -> size; i++){
    if ((((lsc -> accntArray) + i) -> used ) == 0)
      continue;
    if (furtherInTime((((lsc -> accntArray) + i) -> tv ), crtFurther)){
      tempSlot = i;
      crtFurther = (((lsc -> accntArray) + i) -> tv );
    }
  }
  if (tempSlot != -1){
    *slot = tempSlot;
    return 1;
  }
  else {
    *slot = -1;
    return -1;
  }
}

canonical_original_code:
int findEvictionCandidate(struct limSizeCache_tag *lsc, unsigned int *slot){
  int tempSlot = -1;
  int i;
  struct timeval crtFurther;
  gettimeofday(&crtFurther, ((void *)0));
  for (i = 0; i < lsc -> size; i++){
    if ((((lsc -> accntArray) + i) -> used ) == 0)
      continue;
    if (furtherInTime((((lsc -> accntArray) + i) -> tv ), crtFurther)){
      tempSlot = i;
      crtFurther = (((lsc -> accntArray) + i) -> tv );
    }
  }
  if (tempSlot != -1){
    *slot = tempSlot;
    return 1;
  }
  else {
    *slot = -1;
    return -1;
  }
}

variable_types: tempSlot int


moveAttrib

original_code:
errorCode moveAttrib(limSizeCache * src, limSizeCache * dest, void * key, int slotSrc, int slotDest){
  (((dest -> accntArray) + slotDest) -> tv ) = (((src -> accntArray) + slotSrc) -> tv );
  (((dest -> accntArray) + slotDest) -> used ) = (((src -> accntArray) + slotSrc) -> used );
  (((dest -> accntArray) + slotDest) -> key ) = (((src -> accntArray) + slotSrc) -> key );
  (((src -> accntArray) + slotSrc) -> used ) = -1;
  (((src -> accntArray) + slotSrc) -> key ) = ((void *)0);
  (((dest -> accntArray) + slotDest) -> bh ) = (((src -> accntArray) + slotSrc) -> bh );
  (((dest -> accntArray) + slotDest) -> evict ) = (((src -> accntArray) + slotSrc) -> evict );
  return 1;
}

canonical_original_code:
int moveAttrib(struct limSizeCache_tag *src, struct limSizeCache_tag *dest, void *key, int slotSrc, int slotDest){
  (((dest -> accntArray) + slotDest) -> tv ) = (((src -> accntArray) + slotSrc) -> tv );
  (((dest -> accntArray) + slotDest) -> used ) = (((src -> accntArray) + slotSrc) -> used );
  (((dest -> accntArray) + slotDest) -> key ) = (((src -> accntArray) + slotSrc) -> key );
  (((src -> accntArray) + slotSrc) -> used ) = -1;
  (((src -> accntArray) + slotSrc) -> key ) = ((void *)0);
  (((dest -> accntArray) + slotDest) -> bh ) = (((src -> accntArray) + slotSrc) -> bh );
  (((dest -> accntArray) + slotDest) -> evict ) = (((src -> accntArray) + slotSrc) -> evict );
  return 1;
}

variable_types:
dest
struct limSizeCache_tag *

variable_types:
key
void *

variable_types: slotSrc int

variable_types: slotDest int


updateAccessTime

decompiled_code:
__int64 __fastcall updateAccessTime(__int64 a1, unsigned int a2)
{
gettimeofday((struct timeval *)(*(_QWORD *)(a1 + 24) + 56LL * a2 + 8), 0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
gettimeofday((struct timeval *)(*(_QWORD *)(a1 + 24) + 56LL * a2 + 8), 0LL);
return 1LL;
}

original_code:
errorCode updateAccessTime(limSizeCache * lsc, unsigned int slot){
  gettimeofday(&((((lsc -> accntArray) + slot) -> tv )), ((void *)0));
  return 1;
}

canonical_original_code:
int updateAccessTime(struct limSizeCache_tag *lsc, unsigned int slot){
  gettimeofday(&((((lsc -> accntArray) + slot) -> tv )), ((void *)0));
  return 1;
}


insertNewElementNoDataCopy

decompiled_code:
__int64 __fastcall insertNewElementNoDataCopy(__int64 a1, unsigned int a2, __int64 a3, _QWORD *a4)
{
__int64 v6; // rbx
__int64 v7; // rsi

updateAccessTime(a1, a2);
v6 = 56LL * a2;
*(_DWORD *)(*(_QWORD *)(a1 + 24) + v6) = 1;
*(_QWORD *)(*(_QWORD *)(a1 + 24) + v6 + 24) = a3;
*(_DWORD *)(*(_QWORD *)(a1 + 24) + v6 + 40) = 0;
*(_QWORD *)(*(_QWORD *)(a1 + 24) + v6 + 48) = 0LL;
v7 = *(_QWORD *)(a1 + 24) + v6;
if ( !*(_QWORD *)(v7 + 32) && (unsigned int)pageAlloc(4096LL, v7 + 32) != 1 )
{
fprintf(stderr, "%s\n", "insertNewElementNoDataCopy: CAn not allocate memory for data");
fflush(stderr);
}
*a4 = *(_QWORD *)(*(_QWORD *)(a1 + 24) + v6 + 32);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2, __int64 a3, _QWORD *a4)
{
__int64 v6; // rbx
__int64 v7; // rsi

func8(a1, a2);
v6 = 56LL * a2;
*(_DWORD *)(*(_QWORD *)(a1 + 24) + v6) = 1;
*(_QWORD *)(*(_QWORD *)(a1 + 24) + v6 + 24) = a3;
*(_DWORD *)(*(_QWORD *)(a1 + 24) + v6 + 40) = 0;
*(_QWORD *)(*(_QWORD *)(a1 + 24) + v6 + 48) = 0LL;
v7 = *(_QWORD *)(a1 + 24) + v6;
if ( !*(_QWORD *)(v7 + 32) && (unsigned int)pageAlloc(4096LL, v7 + 32) != 1 )
{
fprintf(stderr, "%s\n", "insertNewElementNoDataCopy: CAn not allocate memory for data");
fflush(stderr);
}
*a4 = *(_QWORD *)(*(_QWORD *)(a1 + 24) + v6 + 32);
return 1LL;
}

original_code:
errorCode insertNewElementNoDataCopy(limSizeCache * lsc, unsigned int slot, void * key, void ** address){
  updateAccessTime(lsc, slot);
  (((lsc -> accntArray) + slot) -> used ) = 1;
  (((lsc -> accntArray) + slot) -> key ) = key;
  (((lsc -> accntArray) + slot) -> evict ) = 0;
  (((lsc -> accntArray) + slot) -> bh ) = ((void *)0);
  if ((((lsc -> accntArray) + slot) -> data ) == ((void *)0)){
   if(pageAlloc(4096, &((((lsc -> accntArray) + slot) -> data ))) != 1){ fprintf(stderr, "%s\n", "insertNewElementNoDataCopy: CAn not allocate memory for data"); fflush(stderr); };
  }
  *address = (((lsc -> accntArray) + slot) -> data );
  return 1;
}

canonical_original_code:
int insertNewElementNoDataCopy(struct limSizeCache_tag *lsc, unsigned int slot, void *key, void **address){
  updateAccessTime(lsc, slot);
  (((lsc -> accntArray) + slot) -> used ) = 1;
  (((lsc -> accntArray) + slot) -> key ) = key;
  (((lsc -> accntArray) + slot) -> evict ) = 0;
  (((lsc -> accntArray) + slot) -> bh ) = ((void *)0);
  if ((((lsc -> accntArray) + slot) -> data ) == ((void *)0)){
   if(pageAlloc(4096, &((((lsc -> accntArray) + slot) -> data ))) != 1){ fprintf(stderr, "%s\n", "insertNewElementNoDataCopy: CAn not allocate memory for data"); fflush(stderr); };
  }
  *address = (((lsc -> accntArray) + slot) -> data );
  return 1;
}

variable_types:
address
void **


insertNewElement

original_code:
errorCode insertNewElement(limSizeCache * lsc, unsigned int slot, void * key, void * data){
  copyData(lsc, slot, data);
  updateAccessTime(lsc, slot);
  (((lsc -> accntArray) + slot) -> used ) = 1;
  (((lsc -> accntArray) + slot) -> key ) = key;
  (((lsc -> accntArray) + slot) -> bh ) = ((void *)0);
  (((lsc -> accntArray) + slot) -> evict ) = 0;
  return 1;
}

canonical_original_code:
int insertNewElement(struct limSizeCache_tag *lsc, unsigned int slot, void *key, void *data){
  copyData(lsc, slot, data);
  updateAccessTime(lsc, slot);
  (((lsc -> accntArray) + slot) -> used ) = 1;
  (((lsc -> accntArray) + slot) -> key ) = key;
  (((lsc -> accntArray) + slot) -> bh ) = ((void *)0);
  (((lsc -> accntArray) + slot) -> evict ) = 0;
  return 1;
}


pinpoint

decompiled_code:
__int64 __fastcall pinpoint(__int64 a1, unsigned int a2)
{
_DWORD *v2; // rdx
__int64 result; // rax

v2 = (_DWORD *)(*(_QWORD *)(a1 + 24) + 56LL * a2);
result = (unsigned int)*v2;
if ( (_DWORD)result != -1 )
{
++*(_DWORD *)(a1 + 4);
*v2 = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2)
{
_DWORD *v2; // rdx
__int64 result; // rax

v2 = (_DWORD *)(*(_QWORD *)(a1 + 24) + 56LL * a2);
result = (unsigned int)*v2;
if ( (_DWORD)result != -1 )
{
++*(_DWORD *)(a1 + 4);
*v2 = 0;
result = 1LL;
}
return result;
}

original_code:
errorCode pinpoint(limSizeCache * lsc, unsigned int slot){
  if ((((lsc -> accntArray) + slot) -> used ) == -1)
    return -1;
  lsc -> pinpointed ++;
  (((lsc -> accntArray) + slot) -> used ) = 0;
  return 1;
}

canonical_original_code:
int pinpoint(struct limSizeCache_tag *lsc, unsigned int slot){
  if ((((lsc -> accntArray) + slot) -> used ) == -1)
    return -1;
  lsc -> pinpointed ++;
  (((lsc -> accntArray) + slot) -> used ) = 0;
  return 1;
}


unPinpoint

decompiled_code:
__int64 __fastcall unPinpoint(__int64 a1, unsigned int a2)
{
_DWORD *v2; // rdx
__int64 result; // rax

v2 = (_DWORD *)(*(_QWORD *)(a1 + 24) + 56LL * a2);
result = 0xFFFFFFFFLL;
if ( !*v2 )
{
--*(_DWORD *)(a1 + 4);
*v2 = 1;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2)
{
_DWORD *v2; // rdx
__int64 result; // rax

v2 = (_DWORD *)(*(_QWORD *)(a1 + 24) + 56LL * a2);
result = 0xFFFFFFFFLL;
if ( !*v2 )
{
--*(_DWORD *)(a1 + 4);
*v2 = 1;
result = 1LL;
}
return result;
}

original_code:
errorCode unPinpoint(limSizeCache * lsc, unsigned int slot){
  if ((((lsc -> accntArray) + slot) -> used ) != 0)
    return -1;
  lsc -> pinpointed --;
  (((lsc -> accntArray) + slot) -> used ) = 1;
  return 1;
}

canonical_original_code:
int unPinpoint(struct limSizeCache_tag *lsc, unsigned int slot){
  if ((((lsc -> accntArray) + slot) -> used ) != 0)
    return -1;
  lsc -> pinpointed --;
  (((lsc -> accntArray) + slot) -> used ) = 1;
  return 1;
}


allPinpointed

decompiled_code:
__int64 __fastcall allPinpointed(_DWORD *a1)
{
return 2 * (unsigned int)(*a1 == a1[1]) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func13(_DWORD *a1)
{
return 2 * (unsigned int)(*a1 == a1[1]) - 1;
}

original_code:
errorCode allPinpointed(limSizeCache * lsc){
  if (lsc -> size == lsc -> pinpointed)
    return 1;
  else
    return -1;
}

canonical_original_code:
int allPinpointed(struct limSizeCache_tag *lsc){
  if (lsc -> size == lsc -> pinpointed)
    return 1;
  else
    return -1;
}


updateCnt

decompiled_code:
__int64 __fastcall updateCnt(__int64 a1, unsigned int a2)
{
++*(_DWORD *)(*(_QWORD *)(a1 + 24) + 56LL * a2 + 4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned int a2)
{
++*(_DWORD *)(*(_QWORD *)(a1 + 24) + 56LL * a2 + 4);
return 1LL;
}

original_code:
errorCode updateCnt(limSizeCache * lsc, unsigned int slot){
  (((lsc -> accntArray) + slot) -> counter ) ++;
  return 1;
}

canonical_original_code:
int updateCnt(struct limSizeCache_tag *lsc, unsigned int slot){
  (((lsc -> accntArray) + slot) -> counter ) ++;
  return 1;
}


setCnt

decompiled_code:
__int64 __fastcall setCnt(__int64 a1, unsigned int a2, int a3)
{
*(_DWORD *)(*(_QWORD *)(a1 + 24) + 56LL * a2 + 4) = a3;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned int a2, int a3)
{
*(_DWORD *)(*(_QWORD *)(a1 + 24) + 56LL * a2 + 4) = a3;
return 1LL;
}

original_code:
errorCode setCnt(limSizeCache * lsc, unsigned int slot, int value){
  (((lsc -> accntArray) + slot) -> counter ) = value;
  return 1;
}

canonical_original_code:
int setCnt(struct limSizeCache_tag *lsc, unsigned int slot, int value){
  (((lsc -> accntArray) + slot) -> counter ) = value;
  return 1;
}

variable_types: value int


getCnt

decompiled_code:
__int64 __fastcall getCnt(__int64 a1, unsigned int a2, _DWORD *a3)
{
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 24) + 56LL * a2 + 4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, unsigned int a2, _DWORD *a3)
{
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 24) + 56LL * a2 + 4);
return 1LL;
}

original_code:
errorCode getCnt(limSizeCache * lsc, unsigned int slot, int * value){
  * value = (((lsc -> accntArray) + slot) -> counter );
  return 1;
}

canonical_original_code:
int getCnt(struct limSizeCache_tag *lsc, unsigned int slot, int *value){
  * value = (((lsc -> accntArray) + slot) -> counter );
  return 1;
}

variable_types:
value
int *


destroyCache

original_code:
errorCode destroyCache(limSizeCache ** lsc){
  int i = 0;
  for(i = 0; i < (*lsc) -> size; i++){
    if ((*lsc) -> accntArray[i].data)
      pageFree((*lsc) -> accntArray[i].data);
  }
  memFree((*lsc) -> accntArray);
  memFree(*lsc);
  *lsc = ((void *)0);
  return 1;
}

canonical_original_code:
int destroyCache(struct limSizeCache_tag **lsc){
  int i = 0;
  for(i = 0; i < (*lsc) -> size; i++){
    if ((*lsc) -> accntArray[i].data)
      pageFree((*lsc) -> accntArray[i].data);
  }
  memFree((*lsc) -> accntArray);
  memFree(*lsc);
  *lsc = ((void *)0);
  return 1;
}

variable_types: i int


signalCatch

repo: codl/ponyrl

decompiled_code:
void __fastcall signalCatch(int a1)
{
if ( a1 )
{
screen_free();
exit(0);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 )
{
screen_free();
exit(0);
}
}

original_code:
void signalCatch(int s){
    if(s){
        screen_free();
        exit(0);
    }
}

variable_types: s int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // edi
_BYTE *v4; // rbp
_QWORD *v5; // rbx
_DWORD *v6; // rbx
struct sigaction v8; // [rsp+0h] [rbp-B8h] BYREF
char v9[4]; // [rsp+98h] [rbp-20h] BYREF
char v10[28]; // [rsp+9Ch] [rbp-1Ch] BYREF

v8.sa_handler = signalCatch;
v8.sa_flags = 0;
sigaction(2, &v8, 0LL);
sigaction(3, &v8, 0LL);
sigaction(15, &v8, 0LL);
screen_init();
get_screen_size(v10, v9);
v3 = time(0LL);
srand(v3);
init_map();
*((_DWORD *)&player + 8) = 1;
*((_DWORD *)&player + 9) = 1;
*((_DWORD *)&player + 10) = 0;
player &= 0xFCu;
*((_QWORD *)&player + 6) = 0LL;
*((_DWORD *)&player + 1) = 1;
*(_QWORD *)(*(_QWORD *)(get_tile(0LL, 0LL, 0LL) + 16) + 2632LL) = &player;
v4 = malloc(4uLL);
*v4 &= 0xFEu;
v5 = malloc(0x10uLL);
*v5 = v4;
v5[1] = 0LL;
*(_QWORD *)(*(_QWORD *)(get_tile(0LL, 0LL, 0LL) + 16) + 5304LL) = v5;
v6 = malloc(0x48uLL);
*(_BYTE *)v6 &= 0xFCu;
v6[1] = 5;
v6[4] = 5;
*(_QWORD *)(*(_QWORD *)(get_tile(0LL, 0LL, 0LL) + 16) + 7832LL) = v6;
draw_map(1LL, 1LL, 0LL);
while ( 1 )
{
switch ( getchar() )
{
case ',':
pick_up();
break;
case 'b':
move_player(5LL);
break;
case 'h':
move_player(6LL);
break;
case 'j':
move_player(4LL);
break;
case 'k':
move_player(0LL);
break;
case 'l':
move_player(2LL);
break;
case 'n':
move_player(3LL);
break;
case 'q':
screen_free();
return 0;
case 'u':
move_player(1LL);
break;
case 'y':
move_player(7LL);
break;
default:
continue;
}
}
}

original_code:
int main(void){
    int input;
    int width, height;
    struct sigaction sa;
    sa.__sigaction_handler.sa_handler = &signalCatch;
    sa.sa_flags = 0;
    sigaction(2, &sa, ((void *)0));
    sigaction(3, &sa, ((void *)0));
    sigaction(15, &sa, ((void *)0));
    screen_init();
    get_screen_size(&width, &height);
    srand((unsigned int)time(((void *)0)));
    init_map();
    player.x = 1;
    player.y = 1;
    player.ele = 0;
    player.type = 0;
    player.inv = 0;
    player.health = 1;
    ((get_tile(0,0,0)->tile.sq) + (1) * 64 + (1))->c = &player;
    struct item* spikes = malloc(sizeof(struct item));
    spikes->type = 0;
    struct itemlist* a_list = malloc(sizeof(struct itemlist));
    a_list->item = spikes;
    a_list->next = 0;
    ((get_tile(0,0,0)->tile.sq) + (2) * 64 + (4))->i = a_list;
    struct creature *earth_pony = malloc(sizeof(struct creature));
    earth_pony->type = 0;
    earth_pony->health = 5;
    earth_pony->dex = 5;
    ((get_tile(0,0,0)->tile.sq) + (3) * 64 + (3))->c = earth_pony;
    draw_map(1,1,0);
    while(1){
        input = getchar();
        switch(input){
            case 'h':
                move_player(W);
                break;
            case 'j':
                move_player(S);
                break;
            case 'k':
                move_player(N);
                break;
            case 'l':
                move_player(E);
                break;
            case 'y':
                move_player(NW);
                break;
            case 'u':
                move_player(NE);
                break;
            case 'n':
                move_player(SE);
                break;
            case 'b':
                move_player(SW);
                break;
            case ',':
                pick_up();
                break;
            case 'q':
                screen_free();
                return 0;
        }
    }
}

canonical_original_code:
int main(){
    int input;
    int width; int height;
    struct sigaction sa;
    sa.__sigaction_handler.sa_handler = &signalCatch;
    sa.sa_flags = 0;
    sigaction(2, &sa, ((void *)0));
    sigaction(3, &sa, ((void *)0));
    sigaction(15, &sa, ((void *)0));
    screen_init();
    get_screen_size(&width, &height);
    srand((unsigned int)time(((void *)0)));
    init_map();
    player.x = 1;
    player.y = 1;
    player.ele = 0;
    player.type = 0;
    player.inv = 0;
    player.health = 1;
    ((get_tile(0,0,0)->tile.sq) + (1) * 64 + (1))->c = &player;
    struct item *spikes = malloc(sizeof(struct item));
    spikes->type = 0;
    struct itemlist *a_list = malloc(sizeof(struct itemlist));
    a_list->item = spikes;
    a_list->next = 0;
    ((get_tile(0,0,0)->tile.sq) + (2) * 64 + (4))->i = a_list;
    struct creature *earth_pony = malloc(sizeof(struct creature));
    earth_pony->type = 0;
    earth_pony->health = 5;
    earth_pony->dex = 5;
    ((get_tile(0,0,0)->tile.sq) + (3) * 64 + (3))->c = earth_pony;
    draw_map(1,1,0);
    while(1){
        input = getchar();
        switch(input){
            case 'h':
                move_player(W);
                break;
            case 'j':
                move_player(S);
                break;
            case 'k':
                move_player(N);
                break;
            case 'l':
                move_player(E);
                break;
            case 'y':
                move_player(NW);
                break;
            case 'u':
                move_player(NE);
                break;
            case 'n':
                move_player(SE);
                break;
            case 'b':
                move_player(SW);
                break;
            case ',':
                pick_up();
                break;
            case 'q':
                screen_free();
                return 0;
        }
    }
}

variable_types: input int

variable_types: width int

variable_types: height int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types:
spikes
struct item { unsigned int type; } *

variable_types: struct creature { unsigned int type; int health; unsigned int str; int x; struct itemlist { struct item { unsigned int type; } *item; struct itemlist *next; } *inv; struct item *wielded; struct skill_list { struct skill { unsigned int type; unsigned int level; } *skill; struct skill_list *next; } *skills; } *

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct itemlist { struct item *item; struct itemlist *next; }

user_defined_types: struct creature { unsigned int type; int health; unsigned int str; int x; struct itemlist *inv; struct item *wielded; struct skill_list *skills; }

user_defined_types: struct skill_list { struct skill *skill; struct skill_list *next; }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


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

result = *(_QWORD *)(a1 + 64);
if ( !result )
return 0LL;
while ( (**(_BYTE **)result & 1) != a2 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return (**(_BYTE **)result >> 1) & 7;
}

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

result = *(_QWORD *)(a1 + 64);
if ( !result )
return 0LL;
while ( (**(_BYTE **)result & 1) != a2 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return (**(_BYTE **)result >> 1) & 7;
}

original_code:
int skill_check(struct creature *subject, unsigned int type) {
    struct skill_list* list = subject->skills;
    while(list != 0) {
        if (list->skill->type == type) {
            return list->skill->level;
        }
        list = list->next;
    }
    return 0;
}

canonical_original_code:
int skill_check(struct creature *subject, unsigned int type) {
    struct skill_list *list = subject->skills;
    while(list != 0) {
        if (list->skill->type == type) {
            return list->skill->level;
        }
        list = list->next;
    }
    return 0;
}

variable_types:
type
unsigned int

variable_types: struct skill_list { struct skill { unsigned int type; unsigned int level; } *skill; struct skill_list *next; } *


rgb

decompiled_code:
__int64 __fastcall rgb(int a1, int a2, int a3)
{
return (unsigned int)(a3 + 6 * a2 + 36 * a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3)
{
return (unsigned int)(a3 + 6 * a2 + 36 * a1 + 16);
}

original_code:
static int rgb(const int r, const int g, const int b){
    return 16 + 36*r + 6*g + b;
}

canonical_original_code:
static int rgb(int r, int g, int b){
    return 16 + 36*r + 6*g + b;
}

variable_types: r int

variable_types: g int

variable_types: b int


grey

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

result = 16LL;
if ( a1 )
{
result = (unsigned int)(a1 + 231);
if ( a1 == 25 )
result = 231LL;
}
return result;
}

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

result = 16LL;
if ( a1 )
{
result = (unsigned int)(a1 + 231);
if ( a1 == 25 )
result = 231LL;
}
return result;
}

original_code:
static int grey(const int b){
    if(b==0) return 16;
    if(b==25) return 231;
    return 232 + b - 1;
}

canonical_original_code:
static int grey(int b){
    if(b==0) return 16;
    if(b==25) return 231;
    return 232 + b - 1;
}


decompiled_code:
__int64 __fastcall get_screen_size(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax
unsigned __int16 v3; // [rsp+8h] [rbp-20h] BYREF
unsigned __int16 v4; // [rsp+Ah] [rbp-1Eh]

ioctl(1, 0x5413uLL, &v3);
if ( a1 )
*a1 = v4;
if ( a2 )
*a2 = v3;
screen_width = v4;
result = v3;
screen_height = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax
unsigned __int16 v3; // [rsp+8h] [rbp-20h] BYREF
unsigned __int16 v4; // [rsp+Ah] [rbp-1Eh]

ioctl(1, 0x5413uLL, &v3);
if ( a1 )
*a1 = v4;
if ( a2 )
*a2 = v3;
screen_width = v4;
result = v3;
screen_height = v3;
return result;
}

original_code:
void get_screen_size(int* w, int* h){
    struct winsize ws;
    ioctl(1, 0x5413, &ws);
    if(w) *w = ws.ws_col;
    if(h) *h = ws.ws_row;
    screen_width = ws.ws_col;
    screen_height = ws.ws_row;
}

canonical_original_code:
void get_screen_size(int *w, int *h){
    struct winsize ws;
    ioctl(1, 0x5413, &ws);
    if(w) *w = ws.ws_col;
    if(h) *h = ws.ws_row;
    screen_width = ws.ws_col;
    screen_height = ws.ws_row;
}

variable_types:
w
int *

variable_types:
h
int *

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


resizeCatch

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

if ( a1 == 28 )
result = get_screen_size(0LL, 0LL);
return result;
}

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

if ( a1 == 28 )
result = func2(0LL, 0LL);
return result;
}

original_code:
void resizeCatch(const int sig){
    if(sig == 28){
        get_screen_size(0,0);
        redraw();
    }
}

canonical_original_code:
void resizeCatch(int sig){
    if(sig == 28){
        get_screen_size(0,0);
        redraw();
    }
}

variable_types: sig int


decompiled_code:
int clear_screen()
{
return puts("\x1B[2J");
}

canonical_decompiled_code:
int func4()
{
return puts("\x1B[2J");
}

original_code:
void clear_screen(void){
    puts("\033[2J");
}

canonical_original_code:
void clear_screen(){
    puts("\033[2J");
}


decompiled_code:
int __fastcall set_cursor(unsigned int a1, __int64 a2)
{
return printf("\x1B[%d;%dH", a2, a1);
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1, __int64 a2)
{
return printf("\x1B[%d;%dH", a2, a1);
}

original_code:
void set_cursor(const int x, const int y){
    printf("\033[%d;%dH", y, x);
}

canonical_original_code:
void set_cursor(int x, int y){
    printf("\033[%d;%dH", y, x);
}

variable_types: x int

variable_types: y int


decompiled_code:
int __fastcall set_term_opts(int a1, int a2, int a3)
{
tcflag_t v4; // eax
struct termios v6; // [rsp+0h] [rbp-58h] BYREF

tcgetattr(0, &v6);
if ( a1 )
{
v6.c_lflag |= 2u;
}
else
{
v6.c_lflag &= 0xFFFFFFFD;
v6.c_cc[6] = 1;
v6.c_cc[5] = 0;
}
if ( a2 )
v4 = v6.c_lflag | 8;
else
v4 = v6.c_lflag & 0xFFFFFFF7;
v6.c_lflag = v4;
if ( a3 )
puts("\x1B[?25h");
else
puts("\x1B[?25l");
return tcsetattr(0, 0, &v6);
}

canonical_decompiled_code:
int __fastcall func6(int a1, int a2, int a3)
{
tcflag_t v4; // eax
struct termios v6; // [rsp+0h] [rbp-58h] BYREF

tcgetattr(0, &v6);
if ( a1 )
{
v6.c_lflag |= 2u;
}
else
{
v6.c_lflag &= 0xFFFFFFFD;
v6.c_cc[6] = 1;
v6.c_cc[5] = 0;
}
if ( a2 )
v4 = v6.c_lflag | 8;
else
v4 = v6.c_lflag & 0xFFFFFFF7;
v6.c_lflag = v4;
if ( a3 )
puts("\x1B[?25h");
else
puts("\x1B[?25l");
return tcsetattr(0, 0, &v6);
}

original_code:
void set_term_opts(int buffer, int echo, int visible){
    struct termios t;
    tcgetattr(0, &t);
    if(buffer){
        t.c_lflag |= 0000002;
    } else {
        t.c_lflag &= (unsigned) ~0000002;
        t.c_cc[6] = 1;
        t.c_cc[5] = 0;
    }
    if(echo){
        t.c_lflag |= 0000010;
    } else {
        t.c_lflag &= (unsigned) ~0000010;
    }
    if(visible){
        puts("\033[?25h");
    } else {
        puts("\033[?25l");
    }
    tcsetattr(0, 0, &t);
}

canonical_original_code:
void set_term_opts(int buffer, int echo, int visible){
    struct termios t;
    tcgetattr(0, &t);
    if(buffer){
        t.c_lflag |= 0000002;
    } else {
        t.c_lflag &= (unsigned int) ~0000002;
        t.c_cc[6] = 1;
        t.c_cc[5] = 0;
    }
    if(echo){
        t.c_lflag |= 0000010;
    } else {
        t.c_lflag &= (unsigned int) ~0000010;
    }
    if(visible){
        puts("\033[?25h");
    } else {
        puts("\033[?25l");
    }
    tcsetattr(0, 0, &t);
}

variable_types: buffer int

variable_types: echo int

variable_types: visible int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


redraw

decompiled_code:
void redraw()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void redraw(void){
}

canonical_original_code:
void redraw(){
}


decompiled_code:
int screen_init()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

set_term_opts(0, 0, 0);
clear_screen();
get_screen_size(0LL, 0LL);
color = 0;
background = 1;
v1.sa_handler = (__sighandler_t)resizeCatch;
v1.sa_flags = 0;
return sigaction(28, &v1, 0LL);
}

canonical_decompiled_code:
int func8()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

func6(0, 0, 0);
func4();
func2(0LL, 0LL);
color = 0;
background = 1;
v1.sa_handler = (__sighandler_t)resizeCatch;
v1.sa_flags = 0;
return sigaction(28, &v1, 0LL);
}

original_code:
void screen_init(void){
    set_term_opts(0, 0, 0);
    clear_screen();
    get_screen_size(((void *)0), ((void *)0));
    color = 0;
    background = 1;
    struct sigaction sa;
    sa.__sigaction_handler.sa_handler = &resizeCatch;
    sa.sa_flags = 0;
    sigaction(28, &sa, ((void *)0));
}

canonical_original_code:
void screen_init(){
    set_term_opts(0, 0, 0);
    clear_screen();
    get_screen_size(((void *)0), ((void *)0));
    color = 0;
    background = 1;
    struct sigaction sa;
    sa.__sigaction_handler.sa_handler = &resizeCatch;
    sa.sa_flags = 0;
    sigaction(28, &sa, ((void *)0));
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }


decompiled_code:
int screen_free()
{
set_term_opts(1, 1, 1);
set_cursor(1u, (unsigned int)screen_height);
return puts("\x1B[0m");
}

canonical_decompiled_code:
int func9()
{
func6(1, 1, 1);
func5(1u, (unsigned int)screen_height);
return puts("\x1B[0m");
}

original_code:
void screen_free(void){
    set_term_opts(1, 1, 1);
    set_cursor(1, screen_height);
    puts("\033[0m");
}

canonical_original_code:
void screen_free(){
    set_term_opts(1, 1, 1);
    set_cursor(1, screen_height);
    puts("\033[0m");
}


decompiled_code:
int __fastcall set_color(unsigned int a1)
{
int result; // eax

if ( color != a1 )
{
result = printf("\x1B[38;5;%dm", a1);
color = a1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1)
{
int result; // eax

if ( color != a1 )
{
result = printf("\x1B[38;5;%dm", a1);
color = a1;
}
return result;
}

original_code:
void set_color(const int c){
    if(color != c){
        printf("\033[38;5;%dm", c);
        color = c;
    }
}

canonical_original_code:
void set_color(int c){
    if(color != c){
        printf("\033[38;5;%dm", c);
        color = c;
    }
}

variable_types: c int


decompiled_code:
int __fastcall set_background(unsigned int a1)
{
int result; // eax

if ( background != a1 )
{
result = printf("\x1B[48;5;%dm", a1);
background = a1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(unsigned int a1)
{
int result; // eax

if ( background != a1 )
{
result = printf("\x1B[48;5;%dm", a1);
background = a1;
}
return result;
}

original_code:
void set_background(const int c){
    if(background != c){
        printf("\033[48;5;%dm", c);
        background = c;
    }
}

canonical_original_code:
void set_background(int c){
    if(background != c){
        printf("\033[48;5;%dm", c);
        background = c;
    }
}