HTinsert

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

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

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;
}


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: 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:
key
void *

variable_types:
data
void **

variable_types: entry int

variable_types: result int

variable_types: resultComp int

return_type: 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; }


HTlookup

decompiled_code:
__int64 __fastcall HTlookup(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 result; // rax
int v5; // [rsp+4h] [rbp-24h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 result; // rax
int v5; // [rsp+4h] [rbp-24h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

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

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


lookup

decompiled_code:
__int64 __fastcall lookup(__int64 a1, __int64 a2, _QWORD *a3)
{
unsigned int v4; // eax
unsigned int v5; // er12
int v7; // [rsp+4h] [rbp-24h] BYREF
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

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

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 **

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


printInfo

decompiled_code:
int __fastcall printInfo(const char *a1, int a2, __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // r8
__int64 v6; // rcx

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

canonical_decompiled_code:
int __fastcall func0(const char *a1, int a2, __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // r8
__int64 v6; // rcx

fprintf(stdout, "Values for %s\n", a1);
if ( a2 > 0 )
{
v4 = 0LL;
do
{
v5 = *(unsigned int *)(a3 + 4 * v4);
v6 = (unsigned int)v4++;
fprintf(stdout, " %s[%d] = %d\n", a1, v6, v5);
}
while ( v4 != a2 );
}
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:
// attributes: thunk
__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:
// attributes: thunk
__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

decompiled_code:
__int64 __fastcall createLimCache(int a1, __int64 *a2)
{
__int64 result; // rax
__int64 v4; // rcx
__int64 v5; // rdx
__int64 v6; // rax
__int64 v7; // rdx
_QWORD *v8; // rdi
__int64 v9; // rdx
__int64 v10; // rdx

if ( (unsigned int)memAlloc(32LL) == 1 )
{
if ( (unsigned int)memAlloc((unsigned int)(56 * a1)) == 1 )
{
v4 = *a2;
if ( a1 > 0 )
{
v5 = *(_QWORD *)(v4 + 24);
v6 = 0LL;
do
{
v7 = v6 + v5;
*(_QWORD *)(v7 + 24) = 0LL;
*(_DWORD *)v7 = -1;
v8 = (_QWORD *)(v6 + *(_QWORD *)(*a2 + 24));
v8[4] = 0LL;
v9 = *a2;
v8[1] = 0LL;
v10 = *(_QWORD *)(v9 + 24);
v8[2] = 0LL;
*(_QWORD *)(v10 + v6 + 48) = 0LL;
v4 = *a2;
v5 = *(_QWORD *)(*a2 + 24);
*(_DWORD *)(v5 + v6 + 40) = 0;
v6 += 56LL;
}
while ( v6 != 56LL * a1 );
}
*(_DWORD *)v4 = a1;
result = 1LL;
*(_DWORD *)(v4 + 8) = 0;
}
else
{
fflush(stderr);
result = memAlloc((unsigned int)(56 * a1));
}
}
else
{
fflush(stderr);
result = memAlloc(32LL);
}
return result;
}

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; } **

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; }


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

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


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
__int64 result; // rax

v4 = 56LL * a2;
v5 = v4 + *(_QWORD *)(a1 + 24);
v6 = *(_QWORD **)(v5 + 32);
if ( !v6 )
{
if ( (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);
result = 1LL;
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 result;
}

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

v4 = 56LL * a2;
v5 = v4 + *(_QWORD *)(a1 + 24);
v6 = *(_QWORD **)(v5 + 32);
if ( !v6 )
{
if ( (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);
result = 1LL;
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 result;
}

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; // er10
__int64 v3; // r8
int v4; // er9
int v5; // er11
__int64 result; // rax
struct timeval v7; // [rsp+0h] [rbp-28h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int *a2)
{
int v2; // er10
__int64 v3; // r8
int v4; // er9
int v5; // er11
__int64 result; // rax
struct timeval v7; // [rsp+0h] [rbp-28h] BYREF

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

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
__int64 v8; // rax

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

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

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

decompiled_code:
__int64 __fastcall insertNewElement(__int64 a1, unsigned int a2, __int64 a3, char *a4)
{
__int64 v5; // rax

copyData(a1, a2, a4);
updateAccessTime(a1, a2);
v5 = *(_QWORD *)(a1 + 24) + 56LL * a2;
*(_DWORD *)v5 = 1;
*(_QWORD *)(v5 + 24) = a3;
*(_QWORD *)(v5 + 48) = 0LL;
*(_DWORD *)(v5 + 40) = 0;
return 1LL;
}

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);
result = 1LL;
*v2 = 0;
}
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);
result = 1LL;
*v2 = 0;
}
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);
result = 1LL;
*v2 = 1;
}
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);
result = 1LL;
*v2 = 1;
}
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

decompiled_code:
__int64 __fastcall destroyCache(int **a1)
{
int *v1; // rax
__int64 v2; // rbp
int v3; // ebx
__int64 result; // rax

v1 = *a1;
if ( **a1 > 0 )
{
v2 = 0LL;
v3 = 0;
do
{
if ( *(_QWORD *)(*((_QWORD *)v1 + 3) + v2 + 32) )
{
pageFree();
v1 = *a1;
}
++v3;
v2 += 56LL;
}
while ( *v1 > v3 );
}
memFree(*((_QWORD *)v1 + 3));
memFree(*a1);
result = 1LL;
*a1 = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(int **a1)
{
int *v1; // rax
__int64 v2; // rbp
int v3; // ebx
__int64 result; // rax

v1 = *a1;
if ( **a1 > 0 )
{
v2 = 0LL;
v3 = 0;
do
{
if ( *(_QWORD *)(*((_QWORD *)v1 + 3) + v2 + 32) )
{
pageFree();
v1 = *a1;
}
++v3;
v2 += 56LL;
}
while ( *v1 > v3 );
}
memFree(*((_QWORD *)v1 + 3));
memFree(*a1);
result = 1LL;
*a1 = 0LL;
return result;
}

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

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // edi
_BYTE *v4; // rax
_BYTE *v5; // rbp
_QWORD *v6; // rax
_DWORD *v7; // rax
char v9[4]; // [rsp+8h] [rbp-C0h] BYREF
char v10[4]; // [rsp+Ch] [rbp-BCh] BYREF
struct sigaction v11; // [rsp+10h] [rbp-B8h] BYREF

v11.sa_handler = signalCatch;
v11.sa_flags = 0;
sigaction(2, &v11, 0LL);
sigaction(3, &v11, 0LL);
sigaction(15, &v11, 0LL);
screen_init();
get_screen_size(v9, v10);
v3 = time(0LL);
srand(v3);
init_map();
player &= 0xFCu;
*((_QWORD *)&player + 4) = 0x100000001LL;
*((_DWORD *)&player + 10) = 0;
*((_QWORD *)&player + 6) = 0LL;
*((_DWORD *)&player + 1) = 1;
*(_QWORD *)(*(_QWORD *)(get_tile(0LL, 0LL, 0LL) + 16) + 2632LL) = &player;
v4 = malloc(4uLL);
*v4 &= 0xFEu;
v5 = v4;
v6 = malloc(0x10uLL);
*v6 = v5;
v6[1] = 0LL;
*(_QWORD *)(*(_QWORD *)(get_tile(0LL, 0LL, 0LL) + 16) + 5304LL) = v6;
v7 = malloc(0x48uLL);
*(_BYTE *)v7 &= 0xFCu;
v7[1] = 5;
v7[4] = 5;
*(_QWORD *)(*(_QWORD *)(get_tile(0LL, 0LL, 0LL) + 16) + 7832LL) = v7;
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)
{
int v2; // edx
__int64 result; // rax
unsigned __int16 v4; // [rsp+8h] [rbp-20h] BYREF
unsigned __int16 v5; // [rsp+Ah] [rbp-1Eh]

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

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

ioctl(1, 0x5413uLL, &v4);
v2 = v5;
if ( a1 )
*a1 = v5;
result = v4;
if ( a2 )
*a2 = v4;
screen_width = v2;
screen_height = result;
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
tcflag_t v5; // edx
unsigned int v6; // eax
int v7; // edx
struct termios v9; // [rsp+0h] [rbp-58h] BYREF

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

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

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

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);
v1.sa_handler = (__sighandler_t)resizeCatch;
v1.sa_flags = 0;
color = 0;
background = 1;
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);
v1.sa_handler = (__sighandler_t)resizeCatch;
v1.sa_flags = 0;
color = 0;
background = 1;
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;
    }
}


decompiled_code:
int __fastcall draw_square(__int64 a1, unsigned int a2, unsigned int a3)
{
char v4; // al
unsigned int v5; // eax
_BYTE *v6; // rax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax
int v14; // eax
int v15; // eax

srand(map + (*(_DWORD *)(a1 + 8) ^ (*(_DWORD *)(a1 + 16) << 6)));
set_cursor(a2, a3);
v4 = *(_BYTE *)a1 & 3;
if ( v4 == 2 )
{
v13 = grey(0);
set_background(v13);
if ( (rand() & 3) == 0 )
{
v14 = rand();
v11 = grey(v14 % 10 + 5);
goto LABEL_18;
}
LABEL_15:
LODWORD(v6) = putchar(32);
goto LABEL_5;
}
if ( v4 == 3 )
{
v12 = grey(15);
set_background(v12);
goto LABEL_15;
}
if ( v4 != 1 )
{
v5 = rgb(0, 2, 5);
set_background(v5);
LODWORD(v6) = putchar(32);
goto LABEL_5;
}
v9 = grey(0);
set_background(v9);
if ( (unsigned int)(-286331153 * rand() + 143165576) > 0x11111110 )
goto LABEL_15;
v10 = rand();
v11 = rgb(0, v10 % 5 + 1, 0);
LABEL_18:
set_color(v11);
v15 = rand();
LODWORD(v6) = putchar(byte_6D7[v15 % 2]);
LABEL_5:
if ( *(_QWORD *)(a1 + 32) )
{
set_cursor(a2, a3);
LODWORD(v6) = **(_BYTE **)(a1 + 32) & 3;
if ( (_BYTE)v6 != 3 )
{
v7 = rgb(5, 2, 0);
set_color(v7);
LODWORD(v6) = putchar(117);
}
}
else if ( *(_QWORD *)(a1 + 24) )
{
set_cursor(a2, a3);
v6 = **(_BYTE ***)(a1 + 24);
if ( (*v6 & 1) == 0 )
{
v8 = grey(20);
set_color(v8);
LODWORD(v6) = putchar(41);
}
}
return (int)v6;
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1, unsigned int a2, unsigned int a3)
{
char v4; // al
unsigned int v5; // eax
_BYTE *v6; // rax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax
int v14; // eax
int v15; // eax

srand(map + (*(_DWORD *)(a1 + 8) ^ (*(_DWORD *)(a1 + 16) << 6)));
func5(a2, a3);
v4 = *(_BYTE *)a1 & 3;
if ( v4 == 2 )
{
v13 = func1(0);
func11(v13);
if ( (rand() & 3) == 0 )
{
v14 = rand();
v11 = func1(v14 % 10 + 5);
goto LABEL_18;
}
LABEL_15:
LODWORD(v6) = putchar(32);
goto LABEL_5;
}
if ( v4 == 3 )
{
v12 = func1(15);
func11(v12);
goto LABEL_15;
}
if ( v4 != 1 )
{
v5 = func0(0, 2, 5);
func11(v5);
LODWORD(v6) = putchar(32);
goto LABEL_5;
}
v9 = func1(0);
func11(v9);
if ( (unsigned int)(-286331153 * rand() + 143165576) > 0x11111110 )
goto LABEL_15;
v10 = rand();
v11 = func0(0, v10 % 5 + 1, 0);
LABEL_18:
func10(v11);
v15 = rand();
LODWORD(v6) = putchar(byte_6D7[v15 % 2]);
LABEL_5:
if ( *(_QWORD *)(a1 + 32) )
{
func5(a2, a3);
LODWORD(v6) = **(_BYTE **)(a1 + 32) & 3;
if ( (_BYTE)v6 != 3 )
{
v7 = func0(5, 2, 0);
func10(v7);
LODWORD(v6) = putchar(117);
}
}
else if ( *(_QWORD *)(a1 + 24) )
{
func5(a2, a3);
v6 = **(_BYTE ***)(a1 + 24);
if ( (*v6 & 1) == 0 )
{
v8 = func1(20);
func10(v8);
LODWORD(v6) = putchar(41);
}
}
return (int)v6;
}

original_code:
void draw_square(struct square* sq, const int x, const int y){
    srand((unsigned int) (map.seed + (sq->x ^ (sq->y * 64))));
    set_cursor(x, y);
    switch(sq->terrain){
        case 0:
            set_background(rgb(0,2,5));
            putchar(' ');
            break;
        case 1:
            set_background(grey(0));
            if(rand() % 15 == 0){
                set_color(rgb(0,rand()%5+1,0));
                putchar(",."[rand()%2]);
            }
            else
                putchar(' ');
            break;
        case 2:
            set_background(grey(0));
            if(rand() % 4 == 0){
                set_color(grey(rand()%10 + 5));
                putchar(",."[rand()%2]);
            }
            else
                putchar(' ');
            break;
        case 3:
            set_background(grey(15));
            putchar(' ');
            break;
    }
    if(sq->c != 0){
        set_cursor(x, y);
        switch(sq->c->type){
            case 0:
            case 1:
            case 2:
                set_color(rgb(5, 2, 0));
                putchar('u');
                break;
        }
    }
    else if(sq->i){
        set_cursor(x, y);
        switch(sq->i->item->type){
            case 0:
                set_color(grey(20));
                putchar(')');
        }
    }
}

canonical_original_code:
void draw_square(struct square *sq, int x, int y){
    srand((unsigned int) (map.seed + (sq->x ^ (sq->y * 64))));
    set_cursor(x, y);
    switch(sq->terrain){
        case 0:
            set_background(rgb(0,2,5));
            putchar(' ');
            break;
        case 1:
            set_background(grey(0));
            if(rand() % 15 == 0){
                set_color(rgb(0,rand()%5+1,0));
                putchar(",."[rand()%2]);
            }
            else
                putchar(' ');
            break;
        case 2:
            set_background(grey(0));
            if(rand() % 4 == 0){
                set_color(grey(rand()%10 + 5));
                putchar(",."[rand()%2]);
            }
            else
                putchar(' ');
            break;
        case 3:
            set_background(grey(15));
            putchar(' ');
            break;
    }
    if(sq->c != 0){
        set_cursor(x, y);
        switch(sq->c->type){
            case 0:
            case 1:
            case 2:
                set_color(rgb(5, 2, 0));
                putchar('u');
                break;
        }
    }
    else if(sq->i){
        set_cursor(x, y);
        switch(sq->i->item->type){
            case 0:
                set_color(grey(20));
                putchar(')');
        }
    }
}

variable_types: struct square { unsigned int terrain; unsigned int elevation; long x; struct itemlist { struct item { unsigned int type; } *item; struct itemlist *next; } *i; struct creature { unsigned int type; int health; unsigned int str; int x; struct itemlist *inv; struct item *wielded; struct skill_list { struct skill { unsigned int type; unsigned int level; } *skill; struct skill_list *next; } *skills; } *c; } *

user_defined_types: struct square { unsigned int terrain; unsigned int elevation; long x; struct itemlist *i; struct creature *c; }


decompiled_code:
int __fastcall draw_tile(__int64 a1, unsigned int a2, signed int a3)
{
__int64 v3; // r15
__int64 v5; // rbp
signed int v6; // ebx
int result; // eax

if ( *(_DWORD *)a1 != 1 )
{
v3 = 2560LL;
get_screen_size(0LL, 0LL);
do
{
v5 = v3 - 2560;
v6 = a2;
result = set_cursor(a2, (unsigned int)a3);
do
{
if ( v6 > 0 && v6 <= screen_width && a3 > 0 && a3 <= screen_height )
result = draw_square(v5 + *(_QWORD *)(a1 + 16), v6, a3);
v5 += 40LL;
++v6;
}
while ( v5 != v3 );
v3 += 2560LL;
++a3;
}
while ( v3 != 166400 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, unsigned int a2, signed int a3)
{
__int64 v3; // r15
__int64 v5; // rbp
signed int v6; // ebx
int result; // eax

if ( *(_DWORD *)a1 != 1 )
{
v3 = 2560LL;
func2(0LL, 0LL);
do
{
v5 = v3 - 2560;
v6 = a2;
result = func5(a2, (unsigned int)a3);
do
{
if ( v6 > 0 && v6 <= screen_width && a3 > 0 && a3 <= screen_height )
result = func12(v5 + *(_QWORD *)(a1 + 16), v6, a3);
v5 += 40LL;
++v6;
}
while ( v5 != v3 );
v3 += 2560LL;
++a3;
}
while ( v3 != 166400 );
}
return result;
}

original_code:
void draw_tile(struct tile* t, const int x, const int y){
    if(t->type == Fill)
        return;
    int xx, yy;
    get_screen_size(0, 0);
    for(yy = 0; yy < 64; yy++){
        set_cursor(x, y+yy);
        for(xx = 0; xx < 64; xx++){
            if(x + xx < 1 || x + xx > screen_width ||
                    y + yy < 1 || y + yy > screen_height){
                continue;
            }
            draw_square(((t->tile.sq) + (yy) * 64 + (xx)), x + xx, y + yy);
        }
    }
}

canonical_original_code:
void draw_tile(struct tile *t, int x, int y){
    if(t->type == Fill)
        return;
    int xx; int yy;
    get_screen_size(0, 0);
    for(yy = 0; yy < 64; yy++){
        set_cursor(x, y+yy);
        for(xx = 0; xx < 64; xx++){
            if(x + xx < 1 || x + xx > screen_width ||
                    y + yy < 1 || y + yy > screen_height){
                continue;
            }
            draw_square(((t->tile.sq) + (yy) * 64 + (xx)), x + xx, y + yy);
        }
    }
}

variable_types: struct tile { enum { Array=0, Fill=1 } type; int x; union { struct square { unsigned int terrain; unsigned int elevation; long x; struct itemlist { struct item { unsigned int type; } *item; struct itemlist *next; } *i; struct creature { unsigned int type; int health; unsigned int str; int x; struct itemlist *inv; struct item *wielded; struct skill_list { struct skill { unsigned int type; unsigned int level; } *skill; struct skill_list *next; } *skills; } *c; } *fill; struct square *sq; } tile; } *

variable_types: xx int

variable_types: yy int

user_defined_types: struct tile { enum { Array=0, Fill=1 } type; int x; union { struct square *fill; struct square *sq; } tile; }


decompiled_code:
__int64 __fastcall draw_map(int a1, int a2, unsigned int a3)
{
int v5; // edx
__int64 result; // rax
int v7; // esi
int v8; // er13
signed int v9; // er13
int v10; // ecx
int v11; // ecx
signed int v12; // ecx
int v13; // er13
int v14; // eax
int v15; // esi
signed int v16; // er15
unsigned int v17; // ebp
__int64 v18; // rax
int i; // [rsp+8h] [rbp-40h]

v5 = screen_width;
result = (unsigned int)(a1 + screen_width / 2 + 63);
v7 = screen_height;
v8 = a1 - screen_width / 2 + 63;
if ( a1 - screen_width / 2 >= 0 )
v8 = a1 - screen_width / 2;
v9 = v8 & 0xFFFFFFC0;
v10 = v9 - 64;
if ( v9 > 0 )
v10 = v9;
for ( i = v10; (int)result >= i; result = (unsigned int)(a1 + v5 / 2 + 63) )
{
v11 = a2 - v7 / 2 + 63;
if ( a2 - v7 / 2 >= 0 )
v11 = a2 - v7 / 2;
v12 = v11 & 0xFFFFFFC0;
v13 = v12;
if ( v12 <= 0 )
v13 = v12 - 64;
v14 = v7 / 2;
if ( v13 <= v7 / 2 + a2 + 63 )
{
do
{
v15 = v13 + 63;
v16 = v14 + v13 - a2;
if ( v13 >= 0 )
v15 = v13;
v17 = v5 / 2 + i - a1;
v13 += 64;
v18 = get_tile((unsigned int)(i / 64), (unsigned int)(v15 >> 6), a3);
draw_tile(v18, v17, v16);
v7 = screen_height;
v14 = screen_height / 2;
v5 = screen_width;
}
while ( screen_height / 2 + a2 + 63 >= v13 );
}
i += 64;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, int a2, unsigned int a3)
{
int v5; // edx
__int64 result; // rax
int v7; // esi
int v8; // er13
signed int v9; // er13
int v10; // ecx
int v11; // ecx
signed int v12; // ecx
int v13; // er13
int v14; // eax
int v15; // esi
signed int v16; // er15
unsigned int v17; // ebp
__int64 v18; // rax
int i; // [rsp+8h] [rbp-40h]

v5 = screen_width;
result = (unsigned int)(a1 + screen_width / 2 + 63);
v7 = screen_height;
v8 = a1 - screen_width / 2 + 63;
if ( a1 - screen_width / 2 >= 0 )
v8 = a1 - screen_width / 2;
v9 = v8 & 0xFFFFFFC0;
v10 = v9 - 64;
if ( v9 > 0 )
v10 = v9;
for ( i = v10; (int)result >= i; result = (unsigned int)(a1 + v5 / 2 + 63) )
{
v11 = a2 - v7 / 2 + 63;
if ( a2 - v7 / 2 >= 0 )
v11 = a2 - v7 / 2;
v12 = v11 & 0xFFFFFFC0;
v13 = v12;
if ( v12 <= 0 )
v13 = v12 - 64;
v14 = v7 / 2;
if ( v13 <= v7 / 2 + a2 + 63 )
{
do
{
v15 = v13 + 63;
v16 = v14 + v13 - a2;
if ( v13 >= 0 )
v15 = v13;
v17 = v5 / 2 + i - a1;
v13 += 64;
v18 = get_tile((unsigned int)(i / 64), (unsigned int)(v15 >> 6), a3);
func13(v18, v17, v16);
v7 = screen_height;
v14 = screen_height / 2;
v5 = screen_width;
}
while ( screen_height / 2 + a2 + 63 >= v13 );
}
i += 64;
}
return result;
}

original_code:
void draw_map(const int centerx, const int centery, const int ele){
    int x, y;
    x = (centerx - screen_width/2)/64*64;
    if(x <= 0) x -= 64;
    for(; x < centerx + screen_width/2 + 64; x+=64){
        y = (centery - screen_height/2)/64*64;
        if(y <= 0) y -= 64;
        for(; y < centery + screen_height/2 + 64; y+=64){
            draw_tile(get_tile(x/64, y/64, ele), x - centerx + screen_width/2, y - centery + screen_height/2);
        }
    }
}

canonical_original_code:
void draw_map(int centerx, int centery, int ele){
    int x; int y;
    x = (centerx - screen_width/2)/64*64;
    if(x <= 0) x -= 64;
    for(; x < centerx + screen_width/2 + 64; x+=64){
        y = (centery - screen_height/2)/64*64;
        if(y <= 0) y -= 64;
        for(; y < centery + screen_height/2 + 64; y+=64){
            draw_tile(get_tile(x/64, y/64, ele), x - centerx + screen_width/2, y - centery + screen_height/2);
        }
    }
}

variable_types: centerx int

variable_types: centery int

variable_types: ele int


putmsg

decompiled_code:
int __fastcall putmsg(char *s)
{
unsigned int v1; // eax
unsigned int v2; // eax

set_cursor(1u, 1LL);
v1 = grey(0);
set_background(v1);
v2 = grey(25);
set_color(v2);
return puts(s);
}

canonical_decompiled_code:
int __fastcall func15(char *s)
{
unsigned int v1; // eax
unsigned int v2; // eax

func5(1u, 1LL);
v1 = func1(0);
func11(v1);
v2 = func1(25);
func10(v2);
return puts(s);
}

original_code:
void putmsg(const char* msg){
    set_cursor(1,1);
    set_background(grey(0));
    set_color(grey(25));
    puts(msg);
}

canonical_original_code:
void putmsg(char *msg){
    set_cursor(1,1);
    set_background(grey(0));
    set_color(grey(25));
    puts(msg);
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall move_player(int a1)
{
unsigned int v1; // er12
unsigned int v2; // er13
unsigned int v3; // er15
unsigned int v4; // er14
unsigned int v5; // ebp
unsigned int v6; // eax
__int64 v7; // rbx
int v8; // ebp
unsigned int v9; // ebp
unsigned int v10; // eax
__int64 v11; // rsi
__int64 v12; // rax
__int64 v13; // rdx
__int64 v14; // rbp
__int64 v15; // r12
__int64 v16; // rdi
int v18; // ebp
int v19; // ebx
int v20; // eax
int v21; // ebx
int v22; // eax
unsigned int v23; // [rsp+4h] [rbp-44h]
__int64 v24; // [rsp+8h] [rbp-40h]
__int64 v25; // [rsp+8h] [rbp-40h]

v1 = player[8];
v2 = player[9];
v23 = player[10];
switch ( a1 )
{
case 0:
v4 = player[8];
goto LABEL_10;
case 1:
v3 = v2 - 1;
goto LABEL_12;
case 2:
v3 = player[9];
LABEL_12:
v4 = v1 + 1;
break;
case 3:
v4 = v1 + 1;
goto LABEL_14;
case 4:
v4 = player[8];
LABEL_14:
v3 = v2 + 1;
break;
case 5:
v3 = v2 + 1;
goto LABEL_3;
case 6:
v3 = player[9];
LABEL_3:
v4 = v1 - 1;
break;
case 7:
v4 = v1 - 1;
LABEL_10:
v3 = v2 - 1;
break;
default:
JUMPOUT(0x376LL);
}
v5 = pos_div(v2, 64LL);
v6 = pos_div(v1, 64LL);
v7 = get_tile(v6, v5, 0LL);
v8 = pos_div(v1, 64LL);
if ( v8 == (unsigned int)pos_div(v4, 64LL)
&& (v11 = 64LL, v18 = pos_div(v2, 64LL), v18 == (unsigned int)pos_div(v3, 64LL)) )
{
v13 = *(_QWORD *)(v7 + 16);
v14 = v7;
if ( !*(_DWORD *)v7 )
{
LABEL_23:
v24 = v13;
v11 = 64LL;
v19 = pos_mod(v2, 64LL);
v20 = pos_mod(v1, 64LL);
v15 = *(_QWORD *)(v14 + 16);
v13 = v24 + 40 * (v20 + (__int64)(v19 << 6));
if ( *(_DWORD *)v14 )
goto LABEL_7;
goto LABEL_24;
}
}
else
{
v9 = pos_div(v3, 64LL);
v10 = pos_div(v4, 64LL);
v11 = v9;
v12 = get_tile(v10, v9, 0LL);
v13 = *(_QWORD *)(v7 + 16);
v14 = v12;
if ( !*(_DWORD *)v7 )
goto LABEL_23;
}
v15 = *(_QWORD *)(v14 + 16);
if ( *(_DWORD *)v14 )
goto LABEL_7;
LABEL_24:
v25 = v13;
v11 = 64LL;
v21 = pos_mod(v3, 64LL);
v22 = pos_mod(v4, 64LL);
v13 = v25;
v15 += 40 * (v22 + (__int64)(v21 << 6));
LABEL_7:
v16 = *(_QWORD *)(v15 + 32);
if ( v16 )
return hit(v16, player, v13);
if ( (*(_BYTE *)v15 & 3) == 3 )
return putmsg("You bump into a wall.", v11, v13);
*(_QWORD *)(v13 + 32) = 0LL;
player[8] = v4;
player[9] = v3;
*(_QWORD *)(v15 + 32) = player;
return draw_map(v4, v3, v23);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // er12
unsigned int v2; // er13
unsigned int v3; // er15
unsigned int v4; // er14
unsigned int v5; // ebp
unsigned int v6; // eax
__int64 v7; // rbx
int v8; // ebp
unsigned int v9; // ebp
unsigned int v10; // eax
__int64 v11; // rsi
__int64 v12; // rax
__int64 v13; // rdx
__int64 v14; // rbp
__int64 v15; // r12
__int64 v16; // rdi
int v18; // ebp
int v19; // ebx
int v20; // eax
int v21; // ebx
int v22; // eax
unsigned int v23; // [rsp+4h] [rbp-44h]
__int64 v24; // [rsp+8h] [rbp-40h]
__int64 v25; // [rsp+8h] [rbp-40h]

v1 = player[8];
v2 = player[9];
v23 = player[10];
switch ( a1 )
{
case 0:
v4 = player[8];
goto LABEL_10;
case 1:
v3 = v2 - 1;
goto LABEL_12;
case 2:
v3 = player[9];
LABEL_12:
v4 = v1 + 1;
break;
case 3:
v4 = v1 + 1;
goto LABEL_14;
case 4:
v4 = player[8];
LABEL_14:
v3 = v2 + 1;
break;
case 5:
v3 = v2 + 1;
goto LABEL_3;
case 6:
v3 = player[9];
LABEL_3:
v4 = v1 - 1;
break;
case 7:
v4 = v1 - 1;
LABEL_10:
v3 = v2 - 1;
break;
default:
JUMPOUT(0x376LL);
}
v5 = pos_div(v2, 64LL);
v6 = pos_div(v1, 64LL);
v7 = get_tile(v6, v5, 0LL);
v8 = pos_div(v1, 64LL);
if ( v8 == (unsigned int)pos_div(v4, 64LL)
&& (v11 = 64LL, v18 = pos_div(v2, 64LL), v18 == (unsigned int)pos_div(v3, 64LL)) )
{
v13 = *(_QWORD *)(v7 + 16);
v14 = v7;
if ( !*(_DWORD *)v7 )
{
LABEL_23:
v24 = v13;
v11 = 64LL;
v19 = pos_mod(v2, 64LL);
v20 = pos_mod(v1, 64LL);
v15 = *(_QWORD *)(v14 + 16);
v13 = v24 + 40 * (v20 + (__int64)(v19 << 6));
if ( *(_DWORD *)v14 )
goto LABEL_7;
goto LABEL_24;
}
}
else
{
v9 = pos_div(v3, 64LL);
v10 = pos_div(v4, 64LL);
v11 = v9;
v12 = get_tile(v10, v9, 0LL);
v13 = *(_QWORD *)(v7 + 16);
v14 = v12;
if ( !*(_DWORD *)v7 )
goto LABEL_23;
}
v15 = *(_QWORD *)(v14 + 16);
if ( *(_DWORD *)v14 )
goto LABEL_7;
LABEL_24:
v25 = v13;
v11 = 64LL;
v21 = pos_mod(v3, 64LL);
v22 = pos_mod(v4, 64LL);
v13 = v25;
v15 += 40 * (v22 + (__int64)(v21 << 6));
LABEL_7:
v16 = *(_QWORD *)(v15 + 32);
if ( v16 )
return hit(v16, player, v13);
if ( (*(_BYTE *)v15 & 3) == 3 )
return putmsg("You bump into a wall.", v11, v13);
*(_QWORD *)(v13 + 32) = 0LL;
player[8] = v4;
player[9] = v3;
*(_QWORD *)(v15 + 32) = player;
return draw_map(v4, v3, v23);
}

original_code:
void move_player(enum direction direction){
    int x, y, ele;
    int xx, yy;
    struct square *from, *to;
    struct tile *tilefrom, *tileto;
    x = xx = player.x;
    y = yy = player.y;
    ele = player.ele;
    switch(direction){
        case(NW):
            xx = x - 1;
        case(N):
            yy = y - 1;
            break;
        case(SW):
            yy = y + 1;
        case(W):
            xx = x - 1;
            break;
        case(SE):
            xx = x + 1;
        case(S):
            yy = y + 1;
            break;
        case(NE):
            yy = y - 1;
        case(E):
            xx = x + 1;
            break;
    }
    tilefrom = get_tile(pos_div(x, 64), pos_div(y, 64), 0);
    if(pos_div(x, 64) == pos_div(xx, 64) && pos_div(y, 64) == pos_div(yy, 64))
        tileto = tilefrom;
    else
        tileto = get_tile(pos_div(xx, 64), pos_div(yy, 64), 0);
    from = tilefrom->type == Array? ((tilefrom->tile.sq) + (pos_mod(y, 64)) * 64 + (pos_mod(x, 64))) : tilefrom->tile.fill;
    to = tileto->type == Array? ((tileto->tile.sq) + (pos_mod(yy, 64)) * 64 + (pos_mod(xx, 64))) : tileto->tile.fill;
    if(to->c){
        hit(to->c,&player);
    }
    else {
        switch(to->terrain){
            case(3):
                putmsg("You bump into a wall.");
                break;
            default:
                from->c = 0;
                player.x = xx;
                player.y = yy;
                to->c = &player;
                draw_map(xx, yy, ele);
        }
    }
}

canonical_original_code:
void move_player(enum direction direction){
    int x; int y; int ele;
    int xx; int yy;
    struct square *from; struct square *to;
    struct tile *tilefrom; struct tile *tileto;
    x = xx = player.x;
    y = yy = player.y;
    ele = player.ele;
    switch(direction){
        case(NW):
            xx = x - 1;
        case(N):
            yy = y - 1;
            break;
        case(SW):
            yy = y + 1;
        case(W):
            xx = x - 1;
            break;
        case(SE):
            xx = x + 1;
        case(S):
            yy = y + 1;
            break;
        case(NE):
            yy = y - 1;
        case(E):
            xx = x + 1;
            break;
    }
    tilefrom = get_tile(pos_div(x, 64), pos_div(y, 64), 0);
    if(pos_div(x, 64) == pos_div(xx, 64) && pos_div(y, 64) == pos_div(yy, 64))
        tileto = tilefrom;
    else
        tileto = get_tile(pos_div(xx, 64), pos_div(yy, 64), 0);
    from = tilefrom->type == Array? ((tilefrom->tile.sq) + (pos_mod(y, 64)) * 64 + (pos_mod(x, 64))) : tilefrom->tile.fill;
    to = tileto->type == Array? ((tileto->tile.sq) + (pos_mod(yy, 64)) * 64 + (pos_mod(xx, 64))) : tileto->tile.fill;
    if(to->c){
        hit(to->c,&player);
    }
    else {
        switch(to->terrain){
            case(3):
                putmsg("You bump into a wall.");
                break;
            default:
                from->c = 0;
                player.x = xx;
                player.y = yy;
                to->c = &player;
                draw_map(xx, yy, ele);
        }
    }
}

variable_types: enum direction { N=0, NE=1, E=2, SE=3, S=4, SW=5, W=6, NW=7 }

user_defined_types: struct skill { unsigned int type; unsigned int level; }


decompiled_code:
__int64 pick_up()
{
__int64 v0; // rsi
__int64 result; // rax
__int64 v2; // rdx

v0 = (unsigned int)player[9];
result = get_square((unsigned int)player[8], v0, (unsigned int)player[10]);
if ( !*(_QWORD *)(result + 24) )
result = putmsg("There is nothing to pick up here.", v0, v2);
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rsi
__int64 result; // rax
__int64 v2; // rdx

v0 = (unsigned int)player[9];
result = get_square((unsigned int)player[8], v0, (unsigned int)player[10]);
if ( !*(_QWORD *)(result + 24) )
result = putmsg("There is nothing to pick up here.", v0, v2);
return result;
}

original_code:
void pick_up(void){
    struct itemlist* i = get_square(player.x, player.y, player.ele)->i;
    if(!i){
        putmsg("There is nothing to pick up here.");
    }
    else {
    }
}

canonical_original_code:
void pick_up(){
    struct itemlist *i = get_square(player.x, player.y, player.ele)->i;
    if(!i){
        putmsg("There is nothing to pick up here.");
    }
    else {
    }
}

variable_types: struct itemlist { struct item { unsigned int type; } *item; struct itemlist *next; } *


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

result = rand();
*((_QWORD *)&map + 1) = 0LL;
map = result;
return result;
}

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

result = rand();
*((_QWORD *)&map + 1) = 0LL;
map = result;
return result;
}

original_code:
void init_map(void){
    map.seed = rand();
    map.tiles = ((void *)0);
}

canonical_original_code:
void init_map(){
    map.seed = rand();
    map.tiles = ((void *)0);
}


decompiled_code:
void __fastcall free_tile(void *ptr)
{
if ( !*(_DWORD *)ptr )
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( !*(_DWORD *)ptr )
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void free_tile(struct tile* t){
    if(t->type == Array){
        free(t->tile.sq);
    }
    free(t);
}

canonical_original_code:
void free_tile(struct tile *t){
    if(t->type == Array){
        free(t->tile.sq);
    }
    free(t);
}


original_code:
void gc_map(void){
    int counter = 0;
    struct tilelist* list = map.tiles;
    struct tilelist* next;
    while(list){
        counter++;
        next = list->next;
        if(counter == 100){
            list->next = ((void *)0);
        }
        else if (counter > 100) {
            free_tile(list->tile);
            free(list);
        }
        list = next;
    }
}

canonical_original_code:
void gc_map(){
    int counter = 0;
    struct tilelist *list = map.tiles;
    struct tilelist *next;
    while(list){
        counter++;
        next = list->next;
        if(counter == 100){
            list->next = ((void *)0);
        }
        else if (counter > 100) {
            free_tile(list->tile);
            free(list);
        }
        list = next;
    }
}

variable_types: counter int

variable_types: struct tilelist { struct tile { enum { Array=0, Fill=1 } type; int x; union { struct square { unsigned int terrain; unsigned int elevation; long x; struct itemlist { struct item { unsigned int type; } *item; struct itemlist *next; } *i; struct creature { unsigned int type; int health; unsigned int str; int x; struct itemlist *inv; struct item *wielded; struct skill_list { struct skill { unsigned int type; unsigned int level; } *skill; struct skill_list *next; } *skills; } *c; } *fill; struct square *sq; } tile; } *tile; struct tilelist *next; } *

user_defined_types: struct tilelist { struct tile *tile; struct tilelist *next; }


decompiled_code:
__int64 __fastcall get_square(unsigned int a1, unsigned int a2, int a3)
{
int v4; // er13
int v5; // eax
__int64 v6; // r13
int v7; // ebx

v4 = pos_div(a2, 64LL);
v5 = pos_div(a1, 64LL);
v6 = *((_QWORD *)get_tile(v5, v4, a3) + 2);
v7 = pos_mod(a2, 64LL);
return v6 + 40 * ((int)pos_mod(a1, 64LL) + (__int64)(v7 << 6));
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2, int a3)
{
int v4; // er13
int v5; // eax
__int64 v6; // r13
int v7; // ebx

v4 = pos_div(a2, 64LL);
v5 = pos_div(a1, 64LL);
v6 = *((_QWORD *)get_tile(v5, v4, a3) + 2);
v7 = pos_mod(a2, 64LL);
return v6 + 40 * ((int)pos_mod(a1, 64LL) + (__int64)(v7 << 6));
}

original_code:
struct square* get_square(int x, int y, int ele){
    return ((get_tile(pos_div(x, 64), pos_div(y, 64), ele)->tile.sq) + (pos_mod(y, 64)) * 64 + (pos_mod(x, 64)));
}

canonical_original_code:
struct square *get_square(int x, int y, int ele){
    return ((get_tile(pos_div(x, 64), pos_div(y, 64), ele)->tile.sq) + (pos_mod(y, 64)) * 64 + (pos_mod(x, 64)));
}

variable_types: x int

variable_types: y int

return_type: struct square { unsigned int terrain; unsigned int elevation; long x; struct itemlist { struct item { unsigned int type; } *item; struct itemlist *next; } *i; struct creature { unsigned int type; int health; unsigned int str; int x; struct itemlist *inv; struct item *wielded; struct skill_list { struct skill { unsigned int type; unsigned int level; } *skill; struct skill_list *next; } *skills; } *c; } *


roll

decompiled_code:
__int64 __fastcall roll(int a1, int a2)
{
unsigned int v2; // er12
int i; // ebx

if ( a1 <= 0 )
return 0LL;
v2 = 0;
for ( i = 0; i != a1; ++i )
v2 += rand() % a2 + 1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
unsigned int v2; // er12
int i; // ebx

if ( a1 <= 0 )
return 0LL;
v2 = 0;
for ( i = 0; i != a1; ++i )
v2 += rand() % a2 + 1;
return v2;
}

original_code:
int roll(int times, int sides) {
    int i;
    int sum = 0;
    for(i = 0; i < times; i++) {
        sum = sum + (rand() % sides + 1);
    }
    return sum;
}

variable_types: times int

variable_types: sides int

variable_types: i int

variable_types: sum int


repo: codyharrington/ircbot

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

v2 = *((_DWORD *)ptr + 12);
if ( v2 > 0 )
close(v2);
free_msg(*((_QWORD *)ptr + 7));
free(ptr);
}

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

v2 = *((_DWORD *)ptr + 12);
if ( v2 > 0 )
close(v2);
free_msg(*((_QWORD *)ptr + 7));
free(ptr);
}

original_code:
void free_context(struct IRC_CTX *ctx) {
 if (ctx->sockfd && ctx->sockfd >= 0)
  close(ctx->sockfd);
 free_msg(ctx->msg);
 free(ctx);
}

variable_types: struct IRC_CTX { struct sockaddr { unsigned short sa_family; char sa_data[14]; } servaddr; unsigned int servaddr_len; char *servaddr_str; char *channel; char *nick; int sockfd; int port; struct IRC_MSG { char *_raw; unsigned long _raw_len; struct IRC_SRC { char *server_name; char *nick; char *user; char *host; } *src; char *command; int argc; char **argv; char *text; int valid; } *msg; union sem_t { char __size[32]; long __align; } msg_mutex; } *

user_defined_types: struct IRC_CTX { struct sockaddr servaddr; unsigned int servaddr_len; char *servaddr_str; char *channel; char *nick; int sockfd; int port; struct IRC_MSG *msg; union sem_t msg_mutex; }

user_defined_types: struct IRC_MSG { char *_raw; unsigned long _raw_len; struct IRC_SRC *src; char *command; int argc; char **argv; char *text; int valid; }


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

*(_QWORD *)(a1 + 24) = "irc.rizon.net";
*(_QWORD *)(a1 + 32) = "#/g/spam";
*(_DWORD *)(a1 + 52) = 6667;
*(_QWORD *)(a1 + 40) = "chchjesus_bot_two";
*(_OWORD *)a1 = 0LL;
result = calloc(1uLL, 0x40uLL);
*(_QWORD *)(a1 + 56) = result;
return result;
}

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

*(_QWORD *)(a1 + 24) = "irc.rizon.net";
*(_QWORD *)(a1 + 32) = "#/g/spam";
*(_DWORD *)(a1 + 52) = 6667;
*(_QWORD *)(a1 + 40) = "chchjesus_bot_two";
*(_OWORD *)a1 = 0LL;
result = calloc(1uLL, 0x40uLL);
*(_QWORD *)(a1 + 56) = result;
return result;
}

original_code:
void init_context(struct IRC_CTX *ctx) {
 memset(&(ctx->servaddr), 0, sizeof(ctx->servaddr));
 ctx->servaddr_str = "irc.rizon.net";
 ctx->channel = "#/g/spam";
 ctx->port = 6667;
 ctx->nick = "chchjesus_bot_two";
 ctx->msg = (struct IRC_MSG *) calloc(1, sizeof(struct IRC_MSG));
}

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

user_defined_types: union sem_t { char __size[32]; long __align; }

user_defined_types: struct IRC_SRC { char *server_name; char *nick; char *user; char *host; }


decompiled_code:
__int64 __fastcall init_connection(struct sockaddr *addr)
{
__int64 v2; // rdx
const char *v3; // rdi
const char *v4; // rdx
struct addrinfo *v5; // rbx
int v6; // edx
int v7; // esi
int v8; // edi
int v9; // eax
const char *v10; // rdx
const char *v11; // rdx
char s[4]; // [rsp+1h] [rbp-55h] BYREF
char v14; // [rsp+5h] [rbp-51h]
struct addrinfo *pai; // [rsp+6h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+Eh] [rbp-48h] BYREF

v2 = *(unsigned int *)&addr[3].sa_data[2];
v14 = 0;
*(_DWORD *)s = 0;
pai = 0LL;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
sprintf(s, "%d", v2);
v3 = *(const char **)&addr[1].sa_data[6];
*(_QWORD *)&req.ai_family = 0x100000002LL;
if ( getaddrinfo(v3, s, &req, &pai) < 0 )
error((int)"getaddrinfo", (int)s, v4);
v5 = pai;
memcpy(addr, pai->ai_addr, pai->ai_addrlen);
v6 = v5->ai_protocol;
v7 = v5->ai_socktype;
v8 = v5->ai_family;
*(_DWORD *)&addr[1].sa_family = v5->ai_addrlen;
v9 = socket(v8, v7, v6);
*(_DWORD *)&addr[3].sa_family = v9;
if ( v9 < 0 )
error((int)"socket", v7, v10);
freeaddrinfo(pai);
if ( connect(*(_DWORD *)&addr[3].sa_family, addr, *(_DWORD *)&addr[1].sa_family) < 0 )
error((int)"connect", (int)addr, v11);
write_to_socket(addr, "USER %s 0 0 :%s\r\n", *(const char **)&addr[2].sa_data[6], *(const char **)&addr[2].sa_data[6]);
return write_to_socket(addr, "NICK %s\r\n", *(const char **)&addr[2].sa_data[6]);
}

canonical_decompiled_code:
__int64 __fastcall func2(struct sockaddr *addr)
{
__int64 v2; // rdx
const char *v3; // rdi
const char *v4; // rdx
struct addrinfo *v5; // rbx
int v6; // edx
int v7; // esi
int v8; // edi
int v9; // eax
const char *v10; // rdx
const char *v11; // rdx
char s[4]; // [rsp+1h] [rbp-55h] BYREF
char v14; // [rsp+5h] [rbp-51h]
struct addrinfo *pai; // [rsp+6h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+Eh] [rbp-48h] BYREF

v2 = *(unsigned int *)&addr[3].sa_data[2];
v14 = 0;
*(_DWORD *)s = 0;
pai = 0LL;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
sprintf(s, "%d", v2);
v3 = *(const char **)&addr[1].sa_data[6];
*(_QWORD *)&req.ai_family = 0x100000002LL;
if ( getaddrinfo(v3, s, &req, &pai) < 0 )
error((int)"getaddrinfo", (int)s, v4);
v5 = pai;
memcpy(addr, pai->ai_addr, pai->ai_addrlen);
v6 = v5->ai_protocol;
v7 = v5->ai_socktype;
v8 = v5->ai_family;
*(_DWORD *)&addr[1].sa_family = v5->ai_addrlen;
v9 = socket(v8, v7, v6);
*(_DWORD *)&addr[3].sa_family = v9;
if ( v9 < 0 )
error((int)"socket", v7, v10);
freeaddrinfo(pai);
if ( connect(*(_DWORD *)&addr[3].sa_family, addr, *(_DWORD *)&addr[1].sa_family) < 0 )
error((int)"connect", (int)addr, v11);
write_to_socket(addr, "USER %s 0 0 :%s\r\n", *(const char **)&addr[2].sa_data[6], *(const char **)&addr[2].sa_data[6]);
return write_to_socket(addr, "NICK %s\r\n", *(const char **)&addr[2].sa_data[6]);
}

original_code:
void init_connection(struct IRC_CTX *ctx) {
 struct addrinfo hints;
 struct addrinfo *res;
 char port_str[5] = {'\0'};
 memset(&hints, 0, sizeof(hints));
 memset(&res, 0, sizeof(res));
 sprintf(port_str, "%d", ctx->port);
 hints.ai_family = 2;
 hints.ai_socktype = SOCK_STREAM;
 if (getaddrinfo(ctx->servaddr_str, port_str, &hints, &res) < 0) {
  error("getaddrinfo");
 }
 memcpy(&(ctx->servaddr), res->ai_addr, res->ai_addrlen);
 ctx->servaddr_len = res->ai_addrlen;
 ctx->sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
 if (ctx->sockfd < 0) {
  error("socket");
 }
 freeaddrinfo(res);
 if (connect(ctx->sockfd, &(ctx->servaddr), ctx->servaddr_len) < 0) {
  error("connect");
 }
 write_to_socket(ctx, "USER %s 0 0 :%s\r\n", ctx->nick, ctx->nick);
 write_to_socket(ctx, "NICK %s\r\n", ctx->nick);
}

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct sockaddr *v3; // rbp

signal(2, (__sighandler_t)&sigint_handler);
signal(13, (__sighandler_t)&sigpipe_handler);
v3 = (struct sockaddr *)malloc(0x60uLL);
init_context((__int64)v3);
init_connection(v3);
return listen_server(v3);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct sockaddr *v3; // rbp

signal(2, (__sighandler_t)&sigint_handler);
signal(13, (__sighandler_t)&sigpipe_handler);
v3 = (struct sockaddr *)malloc(0x60uLL);
func1((__int64)v3);
func2(v3);
return listen_server(v3);
}

original_code:
int main() {
 signal(2, sigint_handler);
 signal(13, sigpipe_handler);
 int exit_status = 0;
 struct IRC_CTX *ctx = (struct IRC_CTX *) malloc(sizeof(struct IRC_CTX));
 init_context(ctx);
 init_connection(ctx);
 exit_status = listen_server(ctx);
 return exit_status;
}


decompiled_code:
int __fastcall print_buf(char *a1, __int64 a2)
{
char *v2; // rbp
char *i; // rbx
int result; // eax
int v5; // edi

if ( a2 )
{
v2 = &a1[a2];
for ( i = a1; i != v2; ++i )
{
while ( 1 )
{
v5 = *i;
if ( *i == 10 )
{
result = fwrite(&unk_254, 1uLL, 2uLL, stdout);
goto LABEL_5;
}
if ( *i <= 10 )
break;
if ( (_BYTE)v5 != 13 )
{
LABEL_14:
result = putchar(v5);
goto LABEL_5;
}
result = fwrite(&unk_257, 1uLL, 2uLL, stdout);
LABEL_5:
if ( ++i == v2 )
return result;
}
if ( (_BYTE)v5 )
{
if ( (_BYTE)v5 != 9 )
goto LABEL_14;
result = fwrite(&unk_25D, 1uLL, 2uLL, stdout);
goto LABEL_5;
}
result = fwrite(&unk_25A, 1uLL, 2uLL, stdout);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *a1, __int64 a2)
{
char *v2; // rbp
char *i; // rbx
int result; // eax
int v5; // edi

if ( a2 )
{
v2 = &a1[a2];
for ( i = a1; i != v2; ++i )
{
while ( 1 )
{
v5 = *i;
if ( *i == 10 )
{
result = fwrite(&unk_254, 1uLL, 2uLL, stdout);
goto LABEL_5;
}
if ( *i <= 10 )
break;
if ( (_BYTE)v5 != 13 )
{
LABEL_14:
result = putchar(v5);
goto LABEL_5;
}
result = fwrite(&unk_257, 1uLL, 2uLL, stdout);
LABEL_5:
if ( ++i == v2 )
return result;
}
if ( (_BYTE)v5 )
{
if ( (_BYTE)v5 != 9 )
goto LABEL_14;
result = fwrite(&unk_25D, 1uLL, 2uLL, stdout);
goto LABEL_5;
}
result = fwrite(&unk_25A, 1uLL, 2uLL, stdout);
}
}
return result;
}

original_code:
void print_buf(char *buf, size_t len) {
   for (int i = 0; i < len; i++) {
        switch (buf[i]) {
         case '\n':
                fputs("\\n", stdout);
                break;
         case '\r':
                fputs("\\r", stdout);
                break;
         case '\0':
                fputs("\\0", stdout);
                break;
         case '\t':
                fputs("\\t", stdout);
                break;
         default:
                putchar(buf[i]);
        }
   }
}

canonical_original_code:
void print_buf(char *buf, unsigned long len) {
   for (int i = 0; i < len; i++) {
        switch (buf[i]) {
         case '\n':
                fputs("\\n", stdout);
                break;
         case '\r':
                fputs("\\r", stdout);
                break;
         case '\0':
                fputs("\\0", stdout);
                break;
         case '\t':
                fputs("\\t", stdout);
                break;
         default:
                putchar(buf[i]);
        }
   }
}

variable_types:
buf
char *

variable_types:
len
unsigned long


original_code:
void debug_print_msg(struct IRC_MSG *msg) {
    printf("IRC_MSG: {\n\t %s: ", "_raw");
    print_buf(msg->_raw, msg->_raw_len);
    printf(",\n\t%s: %lu,\n\t",
    "_raw_len", msg->_raw_len);
    printf("IRC_SRC: {\n\t\t%s: %s,\n\t\t%s: %s,\n\t\t%s: %s,\n\t\t%s: %s\n\t},\n\t",
    "server_name", msg->src->server_name,
    "nick", msg->src->nick,
    "user", msg->src->user,
    "host", msg->src->host);
    printf("%s: %s,\n\t%s: %d,\n\t",
    "command", msg->command,
    "argc", msg->argc);
    printf("argv: [");
    for (int i = 0; i < msg->argc; i++) {
      printf("%s", msg->argv[i]);
      if (i != (msg->argc - 1))
 printf(", ");
    }
    printf("],\n\t");
    printf("%s: %s,\n\t%s: %d\n}\n",
    "text", msg->text,
    "valid", msg->valid
 );
}

variable_types: struct IRC_MSG { char *_raw; unsigned long _raw_len; struct IRC_SRC { char *server_name; char *nick; char *user; char *host; } *src; char *command; int argc; char **argv; char *text; int valid; } *


error

decompiled_code:
int __fastcall error(const char *format)
{
return printf(format);
}

canonical_decompiled_code:
int __fastcall func2(const char *format)
{
return printf(format);
}

original_code:
void error(char *msg) {
  printf(msg);
}

canonical_original_code:
void error(char *msg) {
  printf(msg);
}


decompiled_code:
int sigint_handler()
{
return error("sigint");
}

canonical_decompiled_code:
int func3()
{
return func2("sigint");
}

original_code:
void sigint_handler(int signo) {
    error("sigint");
}

variable_types: signo int


decompiled_code:
int sigpipe_handler()
{
return error("sigpipe");
}

canonical_decompiled_code:
int func4()
{
return func2("sigpipe");
}

original_code:
void sigpipe_handler(int signo) {
    error("sigpipe");
}


success

decompiled_code:
// attributes: thunk
int __fastcall success(const char *format)
{
return error(format);
}

canonical_decompiled_code:
int __fastcall func5(const char *format)
{
return func2(format);
}

original_code:
void success(char *msg) {
  printf(msg);
}

variable_types:
msg
char *


original_code:
struct IRC_MSG *init_msg() {
    struct IRC_MSG *msg = (struct IRC_MSG *) calloc(1, sizeof(struct IRC_MSG));
    msg->_raw = ((void *)0);
    msg->_raw_len = 0;
    msg->src = (struct IRC_SRC *) calloc(1, sizeof(struct IRC_SRC));
    msg->src->server_name = ((void *)0);
    msg->src->nick = ((void *)0);
    msg->src->user = ((void *)0);
    msg->src->host = ((void *)0);
    msg->command = ((void *)0);
    msg->argc = 0;
    msg->argv = ((void *)0);
    msg->text = ((void *)0);
    msg->valid = 0;
    return msg;
}

return_type: struct IRC_MSG { char *_raw; unsigned long _raw_len; struct IRC_SRC { char *server_name; char *nick; char *user; char *host; } *src; char *command; int argc; char **argv; char *text; int valid; } *


decompiled_code:
void __fastcall free_msg(void *ptr)
{
free(*((void **)ptr + 2));
free(*((void **)ptr + 5));
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*((void **)ptr + 2));
free(*((void **)ptr + 5));
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_msg(struct IRC_MSG *msg) {
 free(msg->src);
 free(msg->argv);
 free(msg->_raw);
 free(msg);
}


decompiled_code:
_BOOL8 __fastcall msg_is_valid(__int64 a1)
{
return *(_QWORD *)(a1 + 24) != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 24) != 0LL;
}

original_code:
int msg_is_valid(struct IRC_MSG *msg) {
    if (msg->command == ((void *)0))
      return 0;
    return 1;
}


decompiled_code:
char __fastcall handle_irc_command(__int64 a1)
{
__int64 v1; // rdx
bool v2; // zf
char result; // al

v1 = *(_QWORD *)(a1 + 56);
v2 = strcmp(*(const char **)(v1 + 24), "PING") == 0;
result = !v2;
if ( v2 )
result = write_to_socket(a1, "PONG :%s\r\n", *(const char **)(*(_QWORD *)(v1 + 16) + 24LL));
return result;
}

canonical_decompiled_code:
char __fastcall func3(__int64 a1)
{
__int64 v1; // rdx
bool v2; // zf
char result; // al

v1 = *(_QWORD *)(a1 + 56);
v2 = strcmp(*(const char **)(v1 + 24), "PING") == 0;
result = !v2;
if ( v2 )
result = write_to_socket(a1, "PONG :%s\r\n", *(const char **)(*(_QWORD *)(v1 + 16) + 24LL));
return result;
}

original_code:
void handle_irc_command(struct IRC_CTX *ctx) {
 if (!strcmp(ctx->msg->command, "PING"))
  write_to_socket(ctx, "PONG :%s\r\n", ctx->msg->src->host);
}