original_code:
char ** cstr_split(char *s, size_t len, const char *b, size_t slen, size_t *l) {
 char * *array = ((void *)0);
 size_t i, j, cap = 0, size = 0, beg = 0;
 array = jmalloc(sizeof(char *)*cap);
 for(i = 0; i < len - (slen - 1); i++) {
  if(size + 1 >= cap ) {
   cap += 5;
   array = jrealloc(array, sizeof(char *)*cap);
  }
  if(s[i] == b[0] && memcmp(s + i, b, slen) == 0) {
   array[size] = cstr_new(s + beg, i - beg);
   beg = i + slen;
   size++;
  }
 }
 array[size++] = cstr_new(s + beg, len - beg);
 *l = size;
 return array;
}

canonical_original_code:
char **cstr_split(char *s, unsigned long len, char *b, unsigned long slen, unsigned long *l) {
 char **array = ((void *)0);
 unsigned long i; unsigned long j; unsigned long cap = 0; unsigned long size = 0; unsigned long beg = 0;
 array = jmalloc(sizeof(char *)*cap);
 for(i = 0; i < len - (slen - 1); i++) {
  if(size + 1 >= cap ) {
   cap += 5;
   array = jrealloc(array, sizeof(char *)*cap);
  }
  if(s[i] == b[0] && memcmp(s + i, b, slen) == 0) {
   array[size] = cstr_new(s + beg, i - beg);
   beg = i + slen;
   size++;
  }
 }
 array[size++] = cstr_new(s + beg, len - beg);
 *l = size;
 return array;
}

variable_types:
len
unsigned long

variable_types:
b
char *

variable_types:
slen
unsigned long

variable_types:
l
unsigned long *

variable_types:
array
char **

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types:
cap
unsigned long

variable_types:
beg
unsigned long

return_type: char **


decompiled_code:
unsigned __int64 __fastcall cstr_tolower(__int64 a1)
{
unsigned __int64 result; // rax
const __int32_t **v2; // rsi

result = *(unsigned int *)(a1 - 4);
if ( *(_DWORD *)(a1 - 8) != (_DWORD)result )
{
v2 = _ctype_tolower_loc();
result = 0LL;
do
{
*(_BYTE *)(a1 + result) = (*v2)[*(char *)(a1 + result)];
++result;
}
while ( result < (unsigned int)(*(_DWORD *)(a1 - 8) - *(_DWORD *)(a1 - 4)) );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1)
{
unsigned __int64 result; // rax
const __int32_t **v2; // rsi

result = *(unsigned int *)(a1 - 4);
if ( *(_DWORD *)(a1 - 8) != (_DWORD)result )
{
v2 = _ctype_tolower_loc();
result = 0LL;
do
{
*(_BYTE *)(a1 + result) = (*v2)[*(char *)(a1 + result)];
++result;
}
while ( result < (unsigned int)(*(_DWORD *)(a1 - 8) - *(_DWORD *)(a1 - 4)) );
}
return result;
}

original_code:
void cstr_tolower(char * s) {
 size_t i;
 for(i = 0; i < ((((cstrhdr*)(s - sizeof(cstrhdr)))->len - ((cstrhdr*)(s - sizeof(cstrhdr)))->free)); i++) s[i] = tolower(s[i]);
}

canonical_original_code:
void cstr_tolower(char *s) {
 unsigned long i;
 for(i = 0; i < ((((struct cstrhdr *)(s - sizeof(cstrhdr)))->len - ((struct cstrhdr *)(s - sizeof(cstrhdr)))->free)); i++) s[i] = tolower(s[i]);
}

variable_types:
s
char *

return_type: void

user_defined_types: struct cstrhdr { unsigned int len; unsigned int free; char buf[]; }


decompiled_code:
unsigned __int64 __fastcall cstr_toupper(__int64 a1)
{
unsigned __int64 result; // rax
const __int32_t **v2; // rsi

result = *(unsigned int *)(a1 - 4);
if ( *(_DWORD *)(a1 - 8) != (_DWORD)result )
{
v2 = _ctype_toupper_loc();
result = 0LL;
do
{
*(_BYTE *)(a1 + result) = (*v2)[*(char *)(a1 + result)];
++result;
}
while ( result < (unsigned int)(*(_DWORD *)(a1 - 8) - *(_DWORD *)(a1 - 4)) );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(__int64 a1)
{
unsigned __int64 result; // rax
const __int32_t **v2; // rsi

result = *(unsigned int *)(a1 - 4);
if ( *(_DWORD *)(a1 - 8) != (_DWORD)result )
{
v2 = _ctype_toupper_loc();
result = 0LL;
do
{
*(_BYTE *)(a1 + result) = (*v2)[*(char *)(a1 + result)];
++result;
}
while ( result < (unsigned int)(*(_DWORD *)(a1 - 8) - *(_DWORD *)(a1 - 4)) );
}
return result;
}

original_code:
void cstr_toupper(char * s) {
 size_t i;
 for(i = 0; i < ((((cstrhdr*)(s - sizeof(cstrhdr)))->len - ((cstrhdr*)(s - sizeof(cstrhdr)))->free)); i++) s[i] = toupper(s[i]);
}

canonical_original_code:
void cstr_toupper(char *s) {
 unsigned long i;
 for(i = 0; i < ((((struct cstrhdr *)(s - sizeof(cstrhdr)))->len - ((struct cstrhdr *)(s - sizeof(cstrhdr)))->free)); i++) s[i] = toupper(s[i]);
}


decompiled_code:
__int64 __fastcall str2ll(char *a1, __int64 a2, __int64 *a3)
{
char v3; // al
char *v6; // rsi
int v7; // er9
__int64 v8; // rdx
unsigned __int64 v9; // rdx
unsigned __int8 v10; // al
__int64 v12; // rax

v3 = *a1;
v6 = &a1[a2];
if ( *a1 == 45 )
{
if ( a1 + 1 != v6 )
{
v3 = a1[1];
v7 = 1;
++a1;
goto LABEL_3;
}
LABEL_16:
v12 = 0LL;
goto LABEL_13;
}
v7 = 0;
if ( !a2 )
goto LABEL_16;
LABEL_3:
v8 = 0LL;
while ( 1 )
{
v10 = v3 - 48;
if ( v10 > 9u )
return 0xFFFFFFFFLL;
v9 = 10 * v8;
if ( ~(__int64)(char)v10 < v9 )
return 0xFFFFFFFFLL;
++a1;
v8 = (char)v10 + v9;
if ( a1 == v6 )
break;
v3 = *a1;
}
if ( !v7 )
{
v12 = v8;
if ( v8 >= 0 )
{
LABEL_13:
*a3 = v12;
return 0LL;
}
return 0xFFFFFFFFLL;
}
if ( (unsigned __int64)v8 > 0x8000000000000000LL )
return 0xFFFFFFFFLL;
*a3 = -v8;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, __int64 a2, __int64 *a3)
{
char v3; // al
char *v6; // rsi
int v7; // er9
__int64 v8; // rdx
unsigned __int64 v9; // rdx
unsigned __int8 v10; // al
__int64 v12; // rax

v3 = *a1;
v6 = &a1[a2];
if ( *a1 == 45 )
{
if ( a1 + 1 != v6 )
{
v3 = a1[1];
v7 = 1;
++a1;
goto LABEL_3;
}
LABEL_16:
v12 = 0LL;
goto LABEL_13;
}
v7 = 0;
if ( !a2 )
goto LABEL_16;
LABEL_3:
v8 = 0LL;
while ( 1 )
{
v10 = v3 - 48;
if ( v10 > 9u )
return 0xFFFFFFFFLL;
v9 = 10 * v8;
if ( ~(__int64)(char)v10 < v9 )
return 0xFFFFFFFFLL;
++a1;
v8 = (char)v10 + v9;
if ( a1 == v6 )
break;
v3 = *a1;
}
if ( !v7 )
{
v12 = v8;
if ( v8 >= 0 )
{
LABEL_13:
*a3 = v12;
return 0LL;
}
return 0xFFFFFFFFLL;
}
if ( (unsigned __int64)v8 > 0x8000000000000000LL )
return 0xFFFFFFFFLL;
*a3 = -v8;
return 0LL;
}

original_code:
int str2ll(char *p, size_t len, long long *l) {
 unsigned long long v = 0;
 char *ptr = p, c;
 int negtive = 0, i;
 if(ptr[0] == '-') {
  ptr++;
  negtive = 1;
 }
 while(ptr != p + len) {
  c = ptr[0];
  if(c < '0' || c > '9')
   return -1;
  v *= 10;
  i = ptr[0] - '0';
  if(v > (0x7fffffffffffffffLL * 2ULL + 1ULL) - i)
   return -1;
  v += i;
  ptr++;
 }
 if(negtive) {
  if(v > (unsigned long long)(-0x7fffffffffffffffLL - 1LL))
   return -1;
  *l = -v;
 } else {
  if(v > 0x7fffffffffffffffLL)
   return -1;
  *l = v;
 }
 return 0;
}

canonical_original_code:
int str2ll(char *p, unsigned long len, long long *l) {
 unsigned long long v = 0;
 char *ptr = p; char c;
 int negtive = 0; int i;
 if(ptr[0] == '-') {
  ptr++;
  negtive = 1;
 }
 while(ptr != p + len) {
  c = ptr[0];
  if(c < '0' || c > '9')
   return -1;
  v *= 10;
  i = ptr[0] - '0';
  if(v > (0x7fffffffffffffffLL * 2ULL + 1ULL) - i)
   return -1;
  v += i;
  ptr++;
 }
 if(negtive) {
  if(v > (unsigned long long)(-0x7fffffffffffffffLL - 1LL))
   return -1;
  *l = -v;
 } else {
  if(v > 0x7fffffffffffffffLL)
   return -1;
  *l = v;
 }
 return 0;
}

variable_types:
p
char *

variable_types:
l
long long *

variable_types:
v
unsigned long long

variable_types:
ptr
char *

variable_types: c char

variable_types: negtive int

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall str2l(char *a1, __int64 a2, _QWORD *a3)
{
__int64 result; // rax
__int64 v5; // [rsp+8h] [rbp-10h] BYREF

result = str2ll(a1, a2, &v5);
if ( (int)result >= 0 )
{
*a3 = v5;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, __int64 a2, _QWORD *a3)
{
__int64 result; // rax
__int64 v5; // [rsp+8h] [rbp-10h] BYREF

result = func1(a1, a2, &v5);
if ( (int)result >= 0 )
{
*a3 = v5;
result = 0LL;
}
return result;
}

original_code:
int str2l(char *p, size_t len, long *l) {
 int rs;
 long long ll;
 rs = str2ll(p, len, &ll);
 if(rs < 0) return rs;
 if(ll > (long long)0x7fffffffffffffffL) return -1;
 if(ll < (long long)(-0x7fffffffffffffffL - 1L)) return -1;
 *l = ll;
 return 0;
}

canonical_original_code:
int str2l(char *p, unsigned long len, long *l) {
 int rs;
 long long ll;
 rs = str2ll(p, len, &ll);
 if(rs < 0) return rs;
 if(ll > (long long)0x7fffffffffffffffL) return -1;
 if(ll < (long long)(-0x7fffffffffffffffL - 1L)) return -1;
 *l = ll;
 return 0;
}

variable_types:
len
unsigned long

variable_types:
l
long *

variable_types: rs int

variable_types:
ll
long long


lltostr

decompiled_code:
__int64 __fastcall lltostr(__int64 a1, _BYTE *a2, unsigned __int64 a3)
{
void *v3; // r10
unsigned __int64 v5; // rcx
char *v6; // r8
unsigned __int64 v7; // rax
signed int v8; // er12
size_t v9; // rdx
__int128 v11; // [rsp+30h] [rbp-18h]
char v12[8]; // [rsp+40h] [rbp-8h] BYREF

v3 = a2;
v5 = abs64(a1);
v6 = v12;
v11 = 0LL;
do
{
*--v6 = v5 % 0xA + 48;
v7 = v5;
v5 /= 0xAuLL;
}
while ( v7 > 9 );
v8 = v12 - v6;
v9 = v8;
if ( a1 < 0 )
{
if ( a3 - 1 >= v8 )
{
*a2 = 45;
v8 = v12 - v6 + 1;
v3 = a2 + 1;
goto LABEL_5;
}
return (unsigned int)-1;
}
if ( a3 < v8 )
return (unsigned int)-1;
LABEL_5:
memcpy(v3, v6, v9);
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _BYTE *a2, unsigned __int64 a3)
{
void *v3; // r10
unsigned __int64 v5; // rcx
char *v6; // r8
unsigned __int64 v7; // rax
signed int v8; // er12
size_t v9; // rdx
__int128 v11; // [rsp+30h] [rbp-18h]
char v12[8]; // [rsp+40h] [rbp-8h] BYREF

v3 = a2;
v5 = abs64(a1);
v6 = v12;
v11 = 0LL;
do
{
*--v6 = v5 % 0xA + 48;
v7 = v5;
v5 /= 0xAuLL;
}
while ( v7 > 9 );
v8 = v12 - v6;
v9 = v8;
if ( a1 < 0 )
{
if ( a3 - 1 >= v8 )
{
*a2 = 45;
v8 = v12 - v6 + 1;
v3 = a2 + 1;
goto LABEL_5;
}
return (unsigned int)-1;
}
if ( a3 < v8 )
return (unsigned int)-1;
LABEL_5:
memcpy(v3, v6, v9);
return (unsigned int)v8;
}

original_code:
int lltostr(long long l, char *p, size_t size) {
 char *ptr, buf[64];
 int len = 0, bs, offset;
 unsigned long long ll;
 bs = sizeof(buf);
 memset(buf, 0, bs);
 ptr = buf + bs;
 ll = l < 0?-l:l;
 do {
  *(--ptr) = '0' + ll%10;
  ll /= 10;
 } while(ll);
 offset = (buf + bs) - ptr;
 len = offset;
 if(l < 0) {
  if(offset > size - 1) return -1;
  p[0] = '-';
  p++;
  len++;
 } else {
  if(offset > size) return -1;
 }
 memcpy(p, ptr, offset);
 return len;
}

canonical_original_code:
int lltostr(long long l, char *p, unsigned long size) {
 char *ptr; char buf[64];
 int len = 0; int bs; int offset;
 unsigned long long ll;
 bs = sizeof(buf);
 memset(buf, 0, bs);
 ptr = buf + bs;
 ll = l < 0?-l:l;
 do {
  *(--ptr) = '0' + ll%10;
  ll /= 10;
 } while(ll);
 offset = (buf + bs) - ptr;
 len = offset;
 if(l < 0) {
  if(offset > size - 1) return -1;
  p[0] = '-';
  p++;
  len++;
 } else {
  if(offset > size) return -1;
 }
 memcpy(p, ptr, offset);
 return len;
}

variable_types:
l
long long

variable_types:
size
unsigned long

variable_types:
buf
char [64]

variable_types: len int

variable_types: bs int

variable_types: offset int

variable_types:
ll
unsigned long long


decompiled_code:
_BOOL8 __fastcall spinlock_lock(volatile signed __int32 *a1)
{
_BOOL8 result; // rax

while ( 1 )
{
if ( !*a1 )
{
result = atomic_cmp_set_uint32_constprop_0(a1);
if ( result )
break;
}
_mm_pause();
if ( !*a1 )
{
result = atomic_cmp_set_uint32_constprop_0(a1);
if ( result )
break;
}
_mm_pause();
if ( !*a1 )
{
result = atomic_cmp_set_uint32_constprop_0(a1);
if ( result )
break;
}
usleep(1u);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(volatile signed __int32 *a1)
{
_BOOL8 result; // rax

while ( 1 )
{
if ( !*a1 )
{
result = func0(a1);
if ( result )
break;
}
_mm_pause();
if ( !*a1 )
{
result = func0(a1);
if ( result )
break;
}
_mm_pause();
if ( !*a1 )
{
result = func0(a1);
if ( result )
break;
}
usleep(1u);
}
return result;
}

original_code:
void spinlock_lock(spinlock_t *lock) {
 int i, n;
 while(1) {
  if(*lock == 0 && atomic_cmp_set_uint32(lock, 0, 1)) {
   return;
  }
  if(2 > 1) {
   for(i = 0; i < 2; i++) {
    for(n = 1; n < 2; n++)
     __asm__("pause");
    if(*lock == 0 && atomic_cmp_set_uint32(lock, 0, 1)) {
     return;
    }
   }
  }
  usleep(1);
 }
}

canonical_original_code:
void spinlock_lock(unsigned int *lock) {
 int i; int n;
 while(1) {
  if(*lock == 0 && atomic_cmp_set_uint32(lock, 0, 1)) {
   return;
  }
  if(2 > 1) {
   for(i = 0; i < 2; i++) {
    for(n = 1; n < 2; n++)
     __asm__("pause");
    if(*lock == 0 && atomic_cmp_set_uint32(lock, 0, 1)) {
     return;
    }
   }
  }
  usleep(1);
 }
}

variable_types:
lock
unsigned int *

variable_types: n int


DictionaryAdd

decompiled_code:
__int64 __fastcall DictionaryAdd(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
bool v3; // zf
__int64 v4; // rbx
__int64 v5; // rax
__int64 result; // rax

v2 = malloc(0x20uLL);
v3 = headerNode == 0LL;
*v2 = a1;
v4 = (__int64)v2;
v2[1] = a2;
v2[2] = 0LL;
v2[3] = 0LL;
if ( v3 )
{
headerNode = v2;
lastNode = (__int64)v2;
result = a1;
}
else
{
v5 = lastNode;
if ( !lastNode )
{
puts("LastNode is NULL");
v5 = lastNode;
}
*(_QWORD *)(v5 + 16) = v4;
lastNode = v4;
*(_QWORD *)(v4 + 24) = v5;
result = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
bool v3; // zf
__int64 v4; // rbx
__int64 v5; // rax
__int64 result; // rax

v2 = malloc(0x20uLL);
v3 = headerNode == 0LL;
*v2 = a1;
v4 = (__int64)v2;
v2[1] = a2;
v2[2] = 0LL;
v2[3] = 0LL;
if ( v3 )
{
headerNode = v2;
lastNode = (__int64)v2;
result = a1;
}
else
{
v5 = lastNode;
if ( !lastNode )
{
puts("LastNode is NULL");
v5 = lastNode;
}
*(_QWORD *)(v5 + 16) = v4;
lastNode = v4;
*(_QWORD *)(v4 + 24) = v5;
result = a1;
}
return result;
}

original_code:
void* DictionaryAdd(void* key, void* value)
{
  KeyValuePair *node = (KeyValuePair*)malloc(sizeof(KeyValuePair));
  node->Key = key;
  node->Value = value;
  node->NextNode = ((void *)0);
  node->PrevNode = ((void *)0);
  if(headerNode == ((void *)0))
  {
    headerNode = node;
    lastNode = node;
  }else{
    if(lastNode == ((void *)0))
    {
      printf("LastNode is NULL\n");
    }
    lastNode->NextNode = node;
    node->PrevNode = lastNode;
    lastNode = node;
  }
  return key;
}

canonical_original_code:
void *DictionaryAdd(void *key, void *value)
{
  struct KeyValuePair_item *node = (KeyValuePair*)malloc(sizeof(KeyValuePair));
  node->Key = key;
  node->Value = value;
  node->NextNode = ((void *)0);
  node->PrevNode = ((void *)0);
  if(headerNode == ((void *)0))
  {
    headerNode = node;
    lastNode = node;
  }else{
    if(lastNode == ((void *)0))
    {
      printf("LastNode is NULL\n");
    }
    lastNode->NextNode = node;
    node->PrevNode = lastNode;
    lastNode = node;
  }
  return key;
}

variable_types:
key
void *

variable_types:
value
void *

variable_types: struct KeyValuePair_item { void *Key; void *Value; struct KeyValuePair_item *NextNode; struct KeyValuePair_item *PrevNode; } *

return_type: void *


DictionaryTest

decompiled_code:
int DictionaryTest()
{
__int64 v0; // rbp
__int64 v1; // r12
__int64 v2; // r13
__int64 v3; // rax
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
const char *v7; // rax

v0 = DictionaryAdd(1LL, (__int64)"Jones");
v1 = DictionaryAdd(2LL, (__int64)"Quinn");
v2 = DictionaryAdd(3LL, (__int64)"Michael");
v3 = DictionaryAdd(4LL, (__int64)"Hello");
v4 = (const char *)DictionaryRemove(v3);
puts(v4);
v5 = (const char *)DictionaryRemove(v2);
puts(v5);
v6 = (const char *)DictionaryRemove(v1);
puts(v6);
v7 = (const char *)DictionaryRemove(v0);
return puts(v7);
}

canonical_decompiled_code:
int func1()
{
__int64 v0; // rbp
__int64 v1; // r12
__int64 v2; // r13
__int64 v3; // rax
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
const char *v7; // rax

v0 = func0(1LL, (__int64)"Jones");
v1 = func0(2LL, (__int64)"Quinn");
v2 = func0(3LL, (__int64)"Michael");
v3 = func0(4LL, (__int64)"Hello");
v4 = (const char *)DictionaryRemove(v3);
puts(v4);
v5 = (const char *)DictionaryRemove(v2);
puts(v5);
v6 = (const char *)DictionaryRemove(v1);
puts(v6);
v7 = (const char *)DictionaryRemove(v0);
return puts(v7);
}

original_code:
void DictionaryTest()
{
  char* buf4 = "Hello";
  char* buf3 = "Michael";
  char* buf2 = "Quinn";
  char* buf1 = "Jones";
  int* int1 = (int*)DictionaryAdd((void*)1, buf1);
  int* int2 = (int*)DictionaryAdd((void*)2, buf2);
  int* int3 = (int*)DictionaryAdd((void*)3, buf3);
  int* int4 = (int*)DictionaryAdd((void*)4, buf4);
  printf("%s\n", (char*)DictionaryRemove(int4));
  printf("%s\n", (char*)DictionaryRemove(int3));
  printf("%s\n", (char*)DictionaryRemove(int2));
  printf("%s\n", (char*)DictionaryRemove(int1));
}

canonical_original_code:
void DictionaryTest()
{
  char *buf4 = "Hello";
  char *buf3 = "Michael";
  char *buf2 = "Quinn";
  char *buf1 = "Jones";
  int *int1 = (int*)DictionaryAdd((void*)1, buf1);
  int *int2 = (int*)DictionaryAdd((void*)2, buf2);
  int *int3 = (int*)DictionaryAdd((void*)3, buf3);
  int *int4 = (int*)DictionaryAdd((void*)4, buf4);
  printf("%s\n", (char *)DictionaryRemove(int4));
  printf("%s\n", (char *)DictionaryRemove(int3));
  printf("%s\n", (char *)DictionaryRemove(int2));
  printf("%s\n", (char *)DictionaryRemove(int1));
}


SendIdData

decompiled_code:
ssize_t __fastcall SendIdData(int fd, unsigned int a2, unsigned int a3)
{
__int64 v3; // r14
char *v4; // rbp
int v5; // ebx
ssize_t result; // rax
char v7[248]; // [rsp+0h] [rbp-F8h] BYREF

v3 = a3;
v4 = (char *)calloc(0x64uLL, 1uLL);
gethostname(v4, 0x64uLL);
memset(v7, 0, 0xC8uLL);
v5 = sprintf(v7, "%c%s%c%d%c%d%c%s%c", 1LL, "NODE ID", 124LL, a2, 124LL, v3, 124LL, v4, 4LL);
free(v4);
result = write(fd, v7, v5);
if ( result < 0 )
exit(0);
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(int fd, unsigned int a2, unsigned int a3)
{
__int64 v3; // r14
char *v4; // rbp
int v5; // ebx
ssize_t result; // rax
char v7[248]; // [rsp+0h] [rbp-F8h] BYREF

v3 = a3;
v4 = (char *)calloc(0x64uLL, 1uLL);
gethostname(v4, 0x64uLL);
memset(v7, 0, 0xC8uLL);
v5 = sprintf(v7, "%c%s%c%d%c%d%c%s%c", 1LL, "NODE ID", 124LL, a2, 124LL, v3, 124LL, v4, 4LL);
free(v4);
result = write(fd, v7, v5);
if ( result < 0 )
exit(0);
return result;
}

original_code:
void SendIdData(int writeSocket, int nodeId, int processId)
{
 int nameSize = 100;
 char* name = (char*)malloc(nameSize * sizeof(char));
 memset(name, '\0', nameSize);
 gethostname(name, nameSize);
  char ackBuffer[200];
 memset(ackBuffer, '\0', 200);
  int ackBufferLen = sprintf(ackBuffer, "%c%s%c%d%c%d%c%s%c",
   '\x01', "NODE ID",'|', nodeId,
   '|', processId, '|', name, '\x04');
  free(name);
  if(write (writeSocket, ackBuffer, ackBufferLen) < 0)
  {
   exit(0);
 }
}

canonical_original_code:
void SendIdData(int writeSocket, int nodeId, int processId)
{
 int nameSize = 100;
 char *name = (char*)malloc(nameSize * sizeof(char));
 memset(name, '\0', nameSize);
 gethostname(name, nameSize);
  char ackBuffer[200];
 memset(ackBuffer, '\0', 200);
  int ackBufferLen = sprintf(ackBuffer, "%c%s%c%d%c%d%c%s%c",
   '\x01', "NODE ID",'|', nodeId,
   '|', processId, '|', name, '\x04');
  free(name);
  if(write (writeSocket, ackBuffer, ackBufferLen) < 0)
  {
   exit(0);
 }
}

variable_types: writeSocket int

variable_types: nodeId int

variable_types: processId int

variable_types: nameSize int

variable_types:
name
char *

variable_types:
ackBuffer
char [200]

variable_types: ackBufferLen int


xmlPrint

decompiled_code:
char __fastcall xmlPrint(const char **a1)
{
return xmlPrintXMLHelper(a1, 0, stdout);
}

canonical_decompiled_code:
char __fastcall func1(const char **a1)
{
return func0(a1, 0, stdout);
}

original_code:
void xmlPrint(XMLNode *node)
{
  xmlPrintXMLHelper(node, 0, stdout);
}

canonical_original_code:
void xmlPrint(struct XMLNode_item *node)
{
  xmlPrintXMLHelper(node, 0, stdout);
}

variable_types: struct XMLNode_item { char *Name; char *NodeType; char *Value; int ChildrenCount; int ChildrenArraySize; int AttributesCount; int AttributesArraySize; struct XMLNode_item **ChildNodes; struct Attribute_item { char *Name; char *Value; } **Attributes; } *

user_defined_types: struct XMLNode_item { char *Name; char *NodeType; char *Value; int ChildrenCount; int ChildrenArraySize; int AttributesCount; int AttributesArraySize; struct XMLNode_item **ChildNodes; struct Attribute_item **Attributes; }


repo: mjradwin/stubgen

decompiled_code:
void *init_tables()
{
void *result; // rax

result = memset(&etable, 0, 0x8CA0uLL);
eindex = 0;
return result;
}

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

result = memset(&etable, 0, 0x8CA0uLL);
eindex = 0;
return result;
}

original_code:
void init_tables()
{
  memset(etable, 0, sizeof(syntaxelem_t) * 500);
  eindex = 0;
}


decompiled_code:
void __fastcall free_args(void *ptr)
{
void **v1; // rbx
void **v2; // rbp
void *v3; // rdi
void *v4; // rdi

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[3];
free(*v2);
v3 = v2[1];
if ( v3 )
free(v3);
v4 = v2[2];
if ( v4 )
free(v4);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void **v1; // rbx
void **v2; // rbp
void *v3; // rdi
void *v4; // rdi

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[3];
free(*v2);
v3 = v2[1];
if ( v3 )
free(v3);
v4 = v2[2];
if ( v4 )
free(v4);
free(v2);
}
while ( v1 );
}
}

original_code:
void free_args(arg_t *args)
{
  arg_t *a;
  for (a = args; a != ((void *)0); ) {
    arg_t *next_arg = a->next;
    free(a->type);
    if (a->name)
      free(a->name);
    if (a->array)
      free(a->array);
    free(a);
    a = next_arg;
  }
}

canonical_original_code:
void free_args(struct arg *args)
{
  struct arg *a;
  for (a = args; a != ((void *)0); ) {
    struct arg *next_arg = a->next;
    free(a->type);
    if (a->name)
      free(a->name);
    if (a->array)
      free(a->array);
    free(a);
    a = next_arg;
  }
}

variable_types: struct arg { char *type; char *name; char *array; struct arg *next; } *


original_code:
void free_tables()
{
  syntaxelem_t *elt;
  for (elt = etable; elt < &etable[500]; elt++) {
    if (elt->name) {
      free(elt->name);
      free(elt->ret_type);
      free_args(elt->args);
      if (elt->throw_decl) free(elt->throw_decl);
      if (elt->tmpl) free(elt->tmpl);
    }
  }
}

canonical_original_code:
void free_tables()
{
  struct syntaxelem *elt;
  for (elt = etable; elt < &etable[500]; elt++) {
    if (elt->name) {
      free(elt->name);
      free(elt->ret_type);
      free_args(elt->args);
      if (elt->throw_decl) free(elt->throw_decl);
      if (elt->tmpl) free(elt->tmpl);
    }
  }
}

variable_types: struct syntaxelem { char *name; char *ret_type; struct arg { char *type; char *name; char *array; struct arg *next; } *args; struct str_pair { char *first; char *second; } *tmpl; struct syntaxelem *parent; struct syntaxelem *next; struct syntaxelem *children; char *throw_decl; int const_flag; int kind; } *

user_defined_types: struct syntaxelem { char *name; char *ret_type; struct arg *args; struct str_pair *tmpl; struct syntaxelem *parent; struct syntaxelem *next; struct syntaxelem *children; char *throw_decl; int const_flag; int kind; }


decompiled_code:
_BOOL8 __fastcall arg_cmp(const char **a1, const char **a2)
{
int v2; // er8
_BOOL8 result; // rax
const char *v4; // rdi
const char *v5; // rsi

v2 = strcmp(*a1, *a2);
result = 1LL;
if ( !v2 )
{
v4 = a1[2];
v5 = a2[2];
if ( v4 )
{
if ( v5 )
result = strcmp(v4, v5) != 0;
}
else
{
result = v5 != 0LL;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char **a1, const char **a2)
{
int v2; // er8
_BOOL8 result; // rax
const char *v4; // rdi
const char *v5; // rsi

v2 = strcmp(*a1, *a2);
result = 1LL;
if ( !v2 )
{
v4 = a1[2];
v5 = a2[2];
if ( v4 )
{
if ( v5 )
result = strcmp(v4, v5) != 0;
}
else
{
result = v5 != 0LL;
}
}
return result;
}

original_code:
int arg_cmp(arg_t *a1, arg_t *a2)
{
  if (strcmp(a1->type, a2->type) != 0)
    return 1;
  if (a1->array) {
    if (a2->array) {
      if (strcmp(a1->array, a2->array) != 0)
 return 1;
    } else {
      return 1;
    }
  } else if (a2->array) {
    return 1;
  }
  return 0;
}

canonical_original_code:
int arg_cmp(struct arg *a1, struct arg *a2)
{
  if (strcmp(a1->type, a2->type) != 0)
    return 1;
  if (a1->array) {
    if (a2->array) {
      if (strcmp(a1->array, a2->array) != 0)
 return 1;
    } else {
      return 1;
    }
  } else if (a2->array) {
    return 1;
  }
  return 0;
}

user_defined_types: struct arg { char *type; char *name; char *array; struct arg *next; }


decompiled_code:
__int64 __fastcall args_cmp(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rbp

v2 = a2;
if ( !a1 )
return v2 != 0;
v3 = a1;
if ( a2 )
{
do
{
if ( arg_cmp((const char **)v3, (const char **)v2) )
break;
v3 = *(_QWORD *)(v3 + 24);
v2 = *(_QWORD *)(v2 + 24);
if ( !v3 )
return v2 != 0;
}
while ( v2 );
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rbp

v2 = a2;
if ( !a1 )
return v2 != 0;
v3 = a1;
if ( a2 )
{
do
{
if ( func3((const char **)v3, (const char **)v2) )
break;
v3 = *(_QWORD *)(v3 + 24);
v2 = *(_QWORD *)(v2 + 24);
if ( !v3 )
return v2 != 0;
}
while ( v2 );
}
return 1LL;
}

original_code:
int args_cmp(arg_t *a1, arg_t *a2)
{
  while (a1 != ((void *)0)) {
    if (a2 == ((void *)0))
      return 1;
    if (arg_cmp(a1, a2) != 0)
      return 1;
    a1 = a1->next;
    a2 = a2->next;
  }
  if (a2 != ((void *)0))
    return 1;
  return 0;
}

canonical_original_code:
int args_cmp(struct arg *a1, struct arg *a2)
{
  while (a1 != ((void *)0)) {
    if (a2 == ((void *)0))
      return 1;
    if (arg_cmp(a1, a2) != 0)
      return 1;
    a1 = a1->next;
    a2 = a2->next;
  }
  if (a2 != ((void *)0))
    return 1;
  return 0;
}


original_code:
char * args_to_string(arg_t *args, int indent_length)
{
  arg_t *a;
  int len = 0;
  char *str;
  char *indent_str;
  if (indent_length <= 0) {
    indent_str = strdup(", ");
    indent_length = 2;
  } else {
    indent_length += 2;
    indent_str = (char *) malloc(indent_length + 1);
    memset(indent_str, ' ', indent_length);
    indent_str[0] = ',';
    indent_str[1] = '\n';
    indent_str[indent_length] = '\0';
  }
  for (a = args; a != ((void *)0); a = a->next) {
    len += strlen(a->type);
    if (a->name)
      len += (1 + strlen(a->name));
    if (a->array)
      len += strlen(a->array);
    if (a != args)
      len += indent_length;
  }
  str = (char *) malloc(len + 1);
  str[0] = '\0';
  for (a = args; a != ((void *)0); a = a->next) {
    if (a != args)
      strcat(str, indent_str);
    strcat(str, a->type);
    if (a->name) {
      if (((a->type)[strlen(a->type)-1] != '*') &&
   ((a->type)[strlen(a->type)-1] != '&'))
 strcat(str, " ");
      strcat(str, a->name);
      if (a->array)
 strcat(str, a->array);
    } else {
      if (a->array)
 strcat(str, a->array);
    }
  }
  free(indent_str);
  return str;
}

canonical_original_code:
char *args_to_string(struct arg *args, int indent_length)
{
  struct arg *a;
  int len = 0;
  char *str;
  char *indent_str;
  if (indent_length <= 0) {
    indent_str = strdup(", ");
    indent_length = 2;
  } else {
    indent_length += 2;
    indent_str = (char *) malloc(indent_length + 1);
    memset(indent_str, ' ', indent_length);
    indent_str[0] = ',';
    indent_str[1] = '\n';
    indent_str[indent_length] = '\0';
  }
  for (a = args; a != ((void *)0); a = a->next) {
    len += strlen(a->type);
    if (a->name)
      len += (1 + strlen(a->name));
    if (a->array)
      len += strlen(a->array);
    if (a != args)
      len += indent_length;
  }
  str = (char *) malloc(len + 1);
  str[0] = '\0';
  for (a = args; a != ((void *)0); a = a->next) {
    if (a != args)
      strcat(str, indent_str);
    strcat(str, a->type);
    if (a->name) {
      if (((a->type)[strlen(a->type)-1] != '*') &&
   ((a->type)[strlen(a->type)-1] != '&'))
 strcat(str, " ");
      strcat(str, a->name);
      if (a->array)
 strcat(str, a->array);
    } else {
      if (a->array)
 strcat(str, a->array);
    }
  }
  free(indent_str);
  return str;
}

variable_types: len int

variable_types:
str
char *

return_type: char *


decompiled_code:
__int64 __fastcall skel_elemcmp(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v4; // r13
__int64 v6; // rax
__int64 v7; // rdx
const char *v8; // rdi
const char *v9; // rsi
const char *v10; // r14
__int64 v11; // r15
size_t v12; // r12
const char *v13; // r15
size_t v14; // rax
const char *v15; // rbx
size_t v16; // r13
size_t v17; // rax
char *v18; // r13
const char *v20; // r15
size_t v21; // rax

v2 = *(_DWORD *)(a2 + 68);
if ( v2 != 1 )
_assert_fail("hdr_elem->kind == FUNC_KIND", "table.c", 0xDEu, "skel_elemcmp");
if ( *(_DWORD *)(a1 + 68) != 4 )
_assert_fail("skel_elem->kind == SKEL_KIND", "table.c", 0xDFu, "skel_elemcmp");
v4 = *(_QWORD *)(a2 + 32);
if ( !v4 )
_assert_fail("hdr_elem->parent != NULL", "table.c", 0xE0u, "skel_elemcmp");
if ( *(_DWORD *)(a1 + 64) == *(_DWORD *)(a2 + 64) )
{
v6 = *(_QWORD *)(a1 + 24);
v7 = *(_QWORD *)(a2 + 24);
if ( v6 )
{
if ( !v7 || strcmp(*(const char **)(v6 + 8), *(const char **)(v7 + 8)) )
return v2;
}
else if ( v7 )
{
return v2;
}
v8 = *(const char **)(a1 + 56);
v9 = *(const char **)(a2 + 56);
if ( v8 )
{
if ( !v9 || strcmp(v8, v9) )
return v2;
}
else if ( v9 )
{
return v2;
}
if ( !strcmp(*(const char **)(a1 + 8), *(const char **)(a2 + 8))
&& !(unsigned int)args_cmp(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16)) )
{
v10 = *(const char **)v4;
v11 = *(_QWORD *)(v4 + 24);
v12 = strlen(*(const char **)v4);
if ( v11 )
{
v13 = *(const char **)(v11 + 8);
v14 = strlen(v13);
v15 = *(const char **)a2;
v16 = v14;
v17 = strlen(v15);
v18 = (char *)malloc(v17 + v12 + v16 + 3);
sprintf(v18, "%s%s::%s", v10, v13, v15);
}
else
{
v20 = *(const char **)a2;
v21 = strlen(*(const char **)a2);
v18 = (char *)malloc(v12 + v21 + 3);
sprintf(v18, "%s::%s", v10, v20);
}
v2 = strcmp(*(const char **)a1, v18);
free(v18);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v4; // r13
__int64 v6; // rax
__int64 v7; // rdx
const char *v8; // rdi
const char *v9; // rsi
const char *v10; // r14
__int64 v11; // r15
size_t v12; // r12
const char *v13; // r15
size_t v14; // rax
const char *v15; // rbx
size_t v16; // r13
size_t v17; // rax
char *v18; // r13
const char *v20; // r15
size_t v21; // rax

v2 = *(_DWORD *)(a2 + 68);
if ( v2 != 1 )
_assert_fail("hdr_elem->kind == FUNC_KIND", "table.c", 0xDEu, "skel_elemcmp");
if ( *(_DWORD *)(a1 + 68) != 4 )
_assert_fail("skel_elem->kind == SKEL_KIND", "table.c", 0xDFu, "skel_elemcmp");
v4 = *(_QWORD *)(a2 + 32);
if ( !v4 )
_assert_fail("hdr_elem->parent != NULL", "table.c", 0xE0u, "skel_elemcmp");
if ( *(_DWORD *)(a1 + 64) == *(_DWORD *)(a2 + 64) )
{
v6 = *(_QWORD *)(a1 + 24);
v7 = *(_QWORD *)(a2 + 24);
if ( v6 )
{
if ( !v7 || strcmp(*(const char **)(v6 + 8), *(const char **)(v7 + 8)) )
return v2;
}
else if ( v7 )
{
return v2;
}
v8 = *(const char **)(a1 + 56);
v9 = *(const char **)(a2 + 56);
if ( v8 )
{
if ( !v9 || strcmp(v8, v9) )
return v2;
}
else if ( v9 )
{
return v2;
}
if ( !strcmp(*(const char **)(a1 + 8), *(const char **)(a2 + 8))
&& !(unsigned int)func4(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16)) )
{
v10 = *(const char **)v4;
v11 = *(_QWORD *)(v4 + 24);
v12 = strlen(*(const char **)v4);
if ( v11 )
{
v13 = *(const char **)(v11 + 8);
v14 = strlen(v13);
v15 = *(const char **)a2;
v16 = v14;
v17 = strlen(v15);
v18 = (char *)malloc(v17 + v12 + v16 + 3);
sprintf(v18, "%s%s::%s", v10, v13, v15);
}
else
{
v20 = *(const char **)a2;
v21 = strlen(*(const char **)a2);
v18 = (char *)malloc(v12 + v21 + 3);
sprintf(v18, "%s::%s", v10, v20);
}
v2 = strcmp(*(const char **)a1, v18);
free(v18);
}
}
return v2;
}

original_code:
int skel_elemcmp(syntaxelem_t *skel_elem, syntaxelem_t *hdr_elem)
{
  char *tmp_str;
  int result;
  ((void) sizeof ((hdr_elem->kind == 1) ? 1 : 0), __extension__ ({ if (hdr_elem->kind == 1) ; else __assert_fail ("hdr_elem->kind == FUNC_KIND", "table.c", 222, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((skel_elem->kind == 4) ? 1 : 0), __extension__ ({ if (skel_elem->kind == 4) ; else __assert_fail ("skel_elem->kind == SKEL_KIND", "table.c", 223, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((hdr_elem->parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (hdr_elem->parent != ((void *)0)) ; else __assert_fail ("hdr_elem->parent != NULL", "table.c", 224, __extension__ __PRETTY_FUNCTION__); }));
  if (skel_elem->const_flag != hdr_elem->const_flag)
    return 1;
  if (skel_elem->tmpl != ((void *)0)) {
    if (hdr_elem->tmpl == ((void *)0))
      return 1;
    else if (strcmp(skel_elem->tmpl->second, hdr_elem->tmpl->second) != 0)
      return 1;
  } else if (hdr_elem->tmpl != ((void *)0)) {
    return 1;
  }
  if (skel_elem->throw_decl != ((void *)0)) {
    if (hdr_elem->throw_decl == ((void *)0))
      return 1;
    else if (strcmp(skel_elem->throw_decl, hdr_elem->throw_decl) != 0)
      return 1;
  } else if (hdr_elem->throw_decl != ((void *)0)) {
    return 1;
  }
  if (strcmp(skel_elem->ret_type, hdr_elem->ret_type) != 0)
    return 1;
  if (args_cmp(skel_elem->args, hdr_elem->args) != 0)
    return 1;
  if (hdr_elem->parent->tmpl)
  {
   tmp_str = (char *)malloc(strlen(hdr_elem->parent->name) +
    strlen(hdr_elem->parent->tmpl->second) +
    strlen(hdr_elem->name) + 3);
   sprintf(tmp_str, "%s%s::%s", hdr_elem->parent->name, hdr_elem->parent->tmpl->second, hdr_elem->name);
  }
  else
  {
   tmp_str = (char *)malloc(strlen(hdr_elem->parent->name) +
    strlen(hdr_elem->name) + 3);
   sprintf(tmp_str, "%s::%s", hdr_elem->parent->name, hdr_elem->name);
  }
  result = strcmp(skel_elem->name, tmp_str);
  free(tmp_str);
  return result;
}

canonical_original_code:
int skel_elemcmp(struct syntaxelem *skel_elem, struct syntaxelem *hdr_elem)
{
  char *tmp_str;
  int result;
  ((void) sizeof ((hdr_elem->kind == 1) ? 1 : 0), __extension__ ({ if (hdr_elem->kind == 1) ; else __assert_fail ("hdr_elem->kind == FUNC_KIND", "table.c", 222, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((skel_elem->kind == 4) ? 1 : 0), __extension__ ({ if (skel_elem->kind == 4) ; else __assert_fail ("skel_elem->kind == SKEL_KIND", "table.c", 223, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((hdr_elem->parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (hdr_elem->parent != ((void *)0)) ; else __assert_fail ("hdr_elem->parent != NULL", "table.c", 224, __extension__ __PRETTY_FUNCTION__); }));
  if (skel_elem->const_flag != hdr_elem->const_flag)
    return 1;
  if (skel_elem->tmpl != ((void *)0)) {
    if (hdr_elem->tmpl == ((void *)0))
      return 1;
    else if (strcmp(skel_elem->tmpl->second, hdr_elem->tmpl->second) != 0)
      return 1;
  } else if (hdr_elem->tmpl != ((void *)0)) {
    return 1;
  }
  if (skel_elem->throw_decl != ((void *)0)) {
    if (hdr_elem->throw_decl == ((void *)0))
      return 1;
    else if (strcmp(skel_elem->throw_decl, hdr_elem->throw_decl) != 0)
      return 1;
  } else if (hdr_elem->throw_decl != ((void *)0)) {
    return 1;
  }
  if (strcmp(skel_elem->ret_type, hdr_elem->ret_type) != 0)
    return 1;
  if (args_cmp(skel_elem->args, hdr_elem->args) != 0)
    return 1;
  if (hdr_elem->parent->tmpl)
  {
   tmp_str = (char *)malloc(strlen(hdr_elem->parent->name) +
    strlen(hdr_elem->parent->tmpl->second) +
    strlen(hdr_elem->name) + 3);
   sprintf(tmp_str, "%s%s::%s", hdr_elem->parent->name, hdr_elem->parent->tmpl->second, hdr_elem->name);
  }
  else
  {
   tmp_str = (char *)malloc(strlen(hdr_elem->parent->name) +
    strlen(hdr_elem->name) + 3);
   sprintf(tmp_str, "%s::%s", hdr_elem->parent->name, hdr_elem->name);
  }
  result = strcmp(skel_elem->name, tmp_str);
  free(tmp_str);
  return result;
}

variable_types: result int

user_defined_types: struct str_pair { char *first; char *second; }


decompiled_code:
__int64 __fastcall reverse_list(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx

result = a1;
if ( a1 )
{
v2 = 0LL;
while ( 1 )
{
v3 = *(_QWORD *)(result + 40);
*(_QWORD *)(result + 40) = v2;
v2 = result;
if ( !v3 )
break;
result = v3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx

result = a1;
if ( a1 )
{
v2 = 0LL;
while ( 1 )
{
v3 = *(_QWORD *)(result + 40);
*(_QWORD *)(result + 40) = v2;
v2 = result;
if ( !v3 )
break;
result = v3;
}
}
return result;
}

original_code:
syntaxelem_t * reverse_list(syntaxelem_t *head)
{
    syntaxelem_t *elt = head;
    syntaxelem_t *prev = ((void *)0);
    syntaxelem_t *next;
    while (elt != ((void *)0)) {
 next = elt->next;
 elt->next = prev;
 prev = elt;
 elt = next;
    }
    return prev;
}

canonical_original_code:
struct syntaxelem *reverse_list(struct syntaxelem *head)
{
    struct syntaxelem *elt = head;
    struct syntaxelem *prev = ((void *)0);
    struct syntaxelem *next;
    while (elt != ((void *)0)) {
 next = elt->next;
 elt->next = prev;
 prev = elt;
 elt = next;
    }
    return prev;
}

variable_types:
head
struct syntaxelem *

return_type: struct syntaxelem { char *name; char *ret_type; struct arg { char *type; char *name; char *array; struct arg *next; } *args; struct str_pair { char *first; char *second; } *tmpl; struct syntaxelem *parent; struct syntaxelem *next; struct syntaxelem *children; char *throw_decl; int const_flag; int kind; } *


decompiled_code:
__int64 __fastcall reverse_arg_list(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx

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

original_code:
arg_t * reverse_arg_list(arg_t *head)
{
  arg_t *a = head;
  arg_t *prev = ((void *)0);
  arg_t *next;
  while (a != ((void *)0)) {
    next = a->next;
    a->next = prev;
    prev = a;
    a = next;
  }
  return prev;
}

canonical_original_code:
struct arg *reverse_arg_list(struct arg *head)
{
  struct arg *a = head;
  struct arg *prev = ((void *)0);
  struct arg *next;
  while (a != ((void *)0)) {
    next = a->next;
    a->next = prev;
    prev = a;
    a = next;
  }
  return prev;
}

variable_types:
head
struct arg *

return_type: struct arg { char *type; char *name; char *array; struct arg *next; } *


decompiled_code:
const char *__fastcall string_kind(unsigned int a1)
{
const char *result; // rax

result = "BAD KIND!";
if ( a1 <= 0xC )
result = CSWTCH_34[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func9(unsigned int a1)
{
const char *result; // rax

result = "BAD KIND!";
if ( a1 <= 0xC )
result = CSWTCH_34[a1];
return result;
}

original_code:
const char * string_kind(int some_KIND)
{
  switch(some_KIND) {
  case 0:
    return "IGNORE_KIND";
  case 1:
    return "FUNC_KIND";
  case 2:
    return "CLASS_KIND";
  case 5:
    return "STRUCT_KIND";
  case 3:
    return "INLINED_KIND";
  case 4:
    return "SKEL_KIND";
  case 11:
    return "DONE_FUNC_KIND";
  case 12:
    return "DONE_CLASS_KIND";
  default:
    return "BAD KIND!";
  }
}

canonical_original_code:
char *string_kind(int some_KIND)
{
  switch(some_KIND) {
  case 0:
    return "IGNORE_KIND";
  case 1:
    return "FUNC_KIND";
  case 2:
    return "CLASS_KIND";
  case 5:
    return "STRUCT_KIND";
  case 3:
    return "INLINED_KIND";
  case 4:
    return "SKEL_KIND";
  case 11:
    return "DONE_FUNC_KIND";
  case 12:
    return "DONE_CLASS_KIND";
  default:
    return "BAD KIND!";
  }
}


decompiled_code:
void __fastcall print_se(__int64 a1)
{
char *v1; // rbp
const char **v2; // rax
const char *v3; // rsi
const char **v4; // rax
const char *v5; // rsi
const char *v6; // rax
const char *v7; // rsi
const char **v8; // rax
const char *v9; // rsi

v1 = args_to_string(*(_QWORD *)(a1 + 16), 0);
log_printf("\nSTUBELEM name: %s\n", *(const char **)a1);
log_printf(" ret_typ: %s\n", *(const char **)(a1 + 8));
log_printf(" args: %s\n", v1);
v2 = *(const char ***)(a1 + 32);
v3 = "NULL";
if ( v2 )
v3 = *v2;
log_printf(" parent: %s\n", v3);
v4 = *(const char ***)(a1 + 40);
v5 = "NULL";
if ( v4 )
v5 = *v4;
log_printf(" next: %s\n", v5);
log_printf(" const: %d\n", *(unsigned int *)(a1 + 64));
v6 = string_kind(*(_DWORD *)(a1 + 68));
log_printf(" kind: %s\n", v6);
v7 = *(const char **)(a1 + 56);
if ( !v7 )
v7 = "NULL";
log_printf(" throw: %s\n", v7);
v8 = *(const char ***)(a1 + 24);
v9 = "NULL";
if ( v8 )
v9 = *v8;
log_printf(" tmpl: %s\n\n", v9);
free(v1);
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
char *v1; // rbp
const char **v2; // rax
const char *v3; // rsi
const char **v4; // rax
const char *v5; // rsi
const char *v6; // rax
const char *v7; // rsi
const char **v8; // rax
const char *v9; // rsi

v1 = func5(*(_QWORD *)(a1 + 16), 0);
log_printf("\nSTUBELEM name: %s\n", *(const char **)a1);
log_printf(" ret_typ: %s\n", *(const char **)(a1 + 8));
log_printf(" args: %s\n", v1);
v2 = *(const char ***)(a1 + 32);
v3 = "NULL";
if ( v2 )
v3 = *v2;
log_printf(" parent: %s\n", v3);
v4 = *(const char ***)(a1 + 40);
v5 = "NULL";
if ( v4 )
v5 = *v4;
log_printf(" next: %s\n", v5);
log_printf(" const: %d\n", *(unsigned int *)(a1 + 64));
v6 = func9(*(_DWORD *)(a1 + 68));
log_printf(" kind: %s\n", v6);
v7 = *(const char **)(a1 + 56);
if ( !v7 )
v7 = "NULL";
log_printf(" throw: %s\n", v7);
v8 = *(const char ***)(a1 + 24);
v9 = "NULL";
if ( v8 )
v9 = *v8;
log_printf(" tmpl: %s\n\n", v9);
free(v1);
}

original_code:
void print_se(syntaxelem_t *elt)
{
  char *arg_str = args_to_string(elt->args, 0);
  log_printf("\nSTUBELEM name: %s\n", elt->name);
  log_printf("      ret_typ: %s\n", elt->ret_type);
  log_printf("         args: %s\n", arg_str);
  log_printf("       parent: %s\n", (elt->parent) ? elt->parent->name : "NULL");
  log_printf("         next: %s\n", (elt->next) ? elt->next->name : "NULL");
  log_printf("        const: %d\n", elt->const_flag);
  log_printf("         kind: %s\n", string_kind(elt->kind));
  log_printf("        throw: %s\n", (elt->throw_decl)? elt->throw_decl : "NULL");
  log_printf("         tmpl: %s\n\n", (elt->tmpl)? elt->tmpl->first : "NULL");
  free(arg_str);
}

canonical_original_code:
void print_se(struct syntaxelem *elt)
{
  char *arg_str = args_to_string(elt->args, 0);
  log_printf("\nSTUBELEM name: %s\n", elt->name);
  log_printf("      ret_typ: %s\n", elt->ret_type);
  log_printf("         args: %s\n", arg_str);
  log_printf("       parent: %s\n", (elt->parent) ? elt->parent->name : "NULL");
  log_printf("         next: %s\n", (elt->next) ? elt->next->name : "NULL");
  log_printf("        const: %d\n", elt->const_flag);
  log_printf("         kind: %s\n", string_kind(elt->kind));
  log_printf("        throw: %s\n", (elt->throw_decl)? elt->throw_decl : "NULL");
  log_printf("         tmpl: %s\n\n", (elt->tmpl)? elt->tmpl->first : "NULL");
  free(arg_str);
}


decompiled_code:
__int64 dequeue_class()
{
void *v0; // rdi
__int64 v1; // r12

v0 = exp_head;
v1 = *(_QWORD *)exp_head;
exp_head = (void *)*((_QWORD *)exp_head + 1);
free(v0);
return v1;
}

canonical_decompiled_code:
__int64 func11()
{
void *v0; // rdi
__int64 v1; // r12

v0 = exp_head;
v1 = *(_QWORD *)exp_head;
exp_head = (void *)*((_QWORD *)exp_head + 1);
free(v0);
return v1;
}

original_code:
syntaxelem_t * dequeue_class()
{
    skelnode_t *old_head = exp_head;
    syntaxelem_t *to_return = exp_head->elt;
    ((void) sizeof ((exp_head != ((void *)0)) ? 1 : 0), __extension__ ({ if (exp_head != ((void *)0)) ; else __assert_fail ("exp_head != NULL", "table.c", 418, __extension__ __PRETTY_FUNCTION__); }));
    exp_head = exp_head->next;
    free(old_head);
    return to_return;
}

canonical_original_code:
struct syntaxelem *dequeue_class()
{
    struct _skelnode *old_head = exp_head;
    struct syntaxelem *to_return = exp_head->elt;
    ((void) sizeof ((exp_head != ((void *)0)) ? 1 : 0), __extension__ ({ if (exp_head != ((void *)0)) ; else __assert_fail ("exp_head != NULL", "table.c", 418, __extension__ __PRETTY_FUNCTION__); }));
    exp_head = exp_head->next;
    free(old_head);
    return to_return;
}

variable_types: struct _skelnode { struct syntaxelem { char *name; char *ret_type; struct arg { char *type; char *name; char *array; struct arg *next; } *args; struct str_pair { char *first; char *second; } *tmpl; struct syntaxelem *parent; struct syntaxelem *next; struct syntaxelem *children; char *throw_decl; int const_flag; int kind; } *elt; struct _skelnode *next; } *

user_defined_types: struct _skelnode { struct syntaxelem *elt; struct _skelnode *next; }


decompiled_code:
_BOOL8 class_queue_empty()
{
return exp_head == 0LL;
}

canonical_decompiled_code:
_BOOL8 func12()
{
return exp_head == 0LL;
}

original_code:
int class_queue_empty()
{
    return exp_head == ((void *)0);
}


decompiled_code:
void clear_skeleton_queue()
{
void *v0; // rbx
void *v1; // rdi

v0 = skel_head;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 1);
free(v1);
}
skel_head = 0LL;
}

canonical_decompiled_code:
void func14()
{
void *v0; // rbx
void *v1; // rdi

v0 = skel_head;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 1);
free(v1);
}
skel_head = 0LL;
}

original_code:
void clear_skeleton_queue()
{
  skelnode_t *node = skel_head;
  while (node != ((void *)0)) {
    skelnode_t *next_node = node->next;
    free(node);
    node = next_node;
  }
  skel_head = ((void *)0);
}

canonical_original_code:
void clear_skeleton_queue()
{
  struct _skelnode *node = skel_head;
  while (node != ((void *)0)) {
    struct _skelnode *next_node = node->next;
    free(node);
    node = next_node;
  }
  skel_head = ((void *)0);
}


decompiled_code:
__int64 dequeue_non_member_function()
{
void *v0; // rdi
__int64 v1; // r12

v0 = fn_head;
v1 = *(_QWORD *)fn_head;
fn_head = (void *)*((_QWORD *)fn_head + 1);
free(v0);
return v1;
}

canonical_decompiled_code:
__int64 func15()
{
void *v0; // rdi
__int64 v1; // r12

v0 = fn_head;
v1 = *(_QWORD *)fn_head;
fn_head = (void *)*((_QWORD *)fn_head + 1);
free(v0);
return v1;
}

original_code:
syntaxelem_t * dequeue_non_member_function()
{
    skelnode_t *old_head = fn_head;
    syntaxelem_t *to_return = fn_head->elt;
    ((void) sizeof ((fn_head != ((void *)0)) ? 1 : 0), __extension__ ({ if (fn_head != ((void *)0)) ; else __assert_fail ("fn_head != NULL", "table.c", 492, __extension__ __PRETTY_FUNCTION__); }));
    fn_head = fn_head->next;
    free(old_head);
    return to_return;
}

canonical_original_code:
struct syntaxelem *dequeue_non_member_function()
{
    struct _skelnode *old_head = fn_head;
    struct syntaxelem *to_return = fn_head->elt;
    ((void) sizeof ((fn_head != ((void *)0)) ? 1 : 0), __extension__ ({ if (fn_head != ((void *)0)) ; else __assert_fail ("fn_head != NULL", "table.c", 492, __extension__ __PRETTY_FUNCTION__); }));
    fn_head = fn_head->next;
    free(old_head);
    return to_return;
}


decompiled_code:
_BOOL8 non_member_function_queue_empty()
{
return fn_head == 0LL;
}

canonical_decompiled_code:
_BOOL8 func16()
{
return fn_head == 0LL;
}

original_code:
int non_member_function_queue_empty()
{
    return fn_head == ((void *)0);
}


decompiled_code:
_BOOL8 __fastcall log_open(const char *a1)
{
logfile = fopen(a1, "w");
return logfile != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
logfile = fopen(a1, "w");
return logfile != 0LL;
}

original_code:
int log_open(const char *logfilename)
{
  logfile = fopen(logfilename, "w");
  return (logfile != ((void *)0));
}

canonical_original_code:
int log_open(char *logfilename)
{
  logfile = fopen(logfilename, "w");
  return (logfile != ((void *)0));
}

variable_types:
logfilename
char *


decompiled_code:
int log_flush()
{
return fflush(logfile);
}

canonical_decompiled_code:
int func1()
{
return fflush(logfile);
}

original_code:
void log_flush()
{
  fflush(logfile);
}

canonical_original_code:
void log_flush()
{
  fflush(logfile);
}


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

result = fclose(logfile);
logfile = 0LL;
return result;
}

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

result = fclose(logfile);
logfile = 0LL;
return result;
}

original_code:
void log_close()
{
  fclose(logfile);
  logfile = ((void *)0);
}


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

va_start(arg, format);
return vfprintf(logfile, format, arg);
}

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

va_start(arg, format);
return vfprintf(logfile, format, arg);
}

original_code:
int log_printf(const char *format, ...)
{
  int retval;
  va_list ap;
  __builtin_va_start(ap,format);
  retval = vfprintf(logfile, format, ap);
  __builtin_va_end(ap);
  return retval;
}

canonical_original_code:
int log_printf(char *format, ...)
{
  int retval;
  __builtin_va_list ap;
  __builtin_va_start(ap,format);
  retval = vfprintf(logfile, format, ap);
  __builtin_va_end(ap);
  return retval;
}

variable_types:
format
char *

variable_types: retval int


decompiled_code:
int __fastcall log_vprintf(char *format, __gnuc_va_list arg)
{
return vfprintf(logfile, format, arg);
}

canonical_decompiled_code:
int __fastcall func4(char *format, __gnuc_va_list arg)
{
return vfprintf(logfile, format, arg);
}

original_code:
int log_vprintf(const char *format, va_list ap)
{
  return vfprintf(logfile, format, ap);
}

canonical_original_code:
int log_vprintf(char *format, __builtin_va_list ap)
{
  return vfprintf(logfile, format, ap);
}


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

result = 0;
if ( !opt_q )
{
va_start(arg, format);
result = vfprintf(stderr, format, arg);
}
return result;
}

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

result = 0;
if ( !opt_q )
{
va_start(arg, format);
result = vfprintf(stderr, format, arg);
}
return result;
}

original_code:
int inform_user(const char *format, ...)
{
  extern int opt_q;
  int retval = 0;
  va_list ap;
  if (!opt_q) {
    __builtin_va_start(ap,format);
    retval = vfprintf(stderr, format, ap);
    __builtin_va_end(ap);
  }
  return retval;
}

canonical_original_code:
int inform_user(char *format, ...)
{
  extern int opt_q;
  int retval = 0;
  __builtin_va_list ap;
  if (!opt_q) {
    __builtin_va_start(ap,format);
    retval = vfprintf(stderr, format, ap);
    __builtin_va_end(ap);
  }
  return retval;
}


fatal

decompiled_code:
void __noreturn fatal(int status, char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
log_vprintf(format, arg);
log_flush();
log_close();
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(status);
}

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

va_start(arg, format);
func4(format, arg);
func1();
func2();
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(status);
}

original_code:
void fatal(int status, const char *format, ...)
{
  va_list ap;
  __builtin_va_start(ap,format);
  log_vprintf(format, ap);
  log_flush();
  log_close();
  (void) vfprintf(stderr, format, ap);
  __builtin_va_end(ap);
  fprintf(stderr, "\n");
  exit(status);
}

canonical_original_code:
void fatal(int status, char *format, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,format);
  log_vprintf(format, ap);
  log_flush();
  log_close();
  (void) vfprintf(stderr, format, ap);
  __builtin_va_end(ap);
  fprintf(stderr, "\n");
  exit(status);
}

variable_types: status int


main

canonical_name: main

repo: mjsottile/microbench

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
char v5; // cl
int v6; // ebp
unsigned __int64 v7; // rbx
unsigned __int64 v8; // rsi
size_t v9; // rax
int v10; // ebp
unsigned __int64 v11; // r12
char *v12; // rdx
size_t v13; // rax
unsigned __int64 i; // rbx
unsigned __int64 v15; // r8
int result; // eax
char v17[32]; // [rsp+0h] [rbp-938h] BYREF
char dest[4]; // [rsp+20h] [rbp-918h] BYREF
char s[1024]; // [rsp+120h] [rbp-818h] BYREF
int longind[262]; // [rsp+520h] [rbp-418h] BYREF

v3 = 0;
strcpy(dest, "ftq");
while ( 1 )
{
longind[0] = 0;
v4 = getopt_long(argc, (char *const *)argv, "n:hsi:o:t:", &long_options_1, longind);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'i':
interval_bits = atoi(optarg);
break;
case 'n':
numsamples = atoi(optarg);
break;
case 'o':
strcpy(dest, optarg);
break;
case 's':
v3 = 1;
break;
case 't':
fwrite("ERROR: ftq not compiled with pthreads support.\n", 1uLL, 0x2FuLL, stderr);
exit(1);
default:
usage(*argv);
return result;
}
}
if ( (unsigned __int64)numsamples > 0x1E8480 )
{
fwrite("WARNING: sample count exceeds maximum.\n", 1uLL, 0x27uLL, stderr);
fwrite(" setting count to maximum.\n", 1uLL, 0x23uLL, stderr);
numsamples = 2000000LL;
}
samples = malloc(16 * numsamples);
if ( samples )
{
v5 = interval_bits;
if ( (unsigned int)(interval_bits - 3) > 0x1B )
{
fprintf(stderr, "WARNING: interval bits invalid. set to %d.\n", 30LL);
v5 = 30;
interval_bits = 30;
}
interval_length = 1 << v5;
ftq_core(0LL);
if ( v3 == 1 )
{
for ( i = 0LL; numsamples > i; ++i )
{
v15 = i;
fprintf(stdout, "%lld %lld\n", *((_QWORD *)samples + 2 * v15), *((_QWORD *)samples + 2 * v15 + 1));
}
}
else
{
sprintf(s, "%s_%d_times.dat", dest, 0LL);
sprintf((char *)longind, "%s_%d_counts.dat", dest, 0LL);
v6 = open(s, 577, 420LL);
if ( v6 < 0 )
goto LABEL_30;
v7 = 0LL;
while ( v7 < numsamples )
{
v8 = v7++;
sprintf(v17, "%lld\n", *((_QWORD *)samples + 2 * v8));
v9 = strlen(v17);
write(v6, v17, v9);
}
close(v6);
v10 = open((const char *)longind, 577, 420LL);
if ( v10 < 0 )
{
LABEL_30:
perror("can not create file");
exit(1);
}
v11 = 0LL;
while ( numsamples > v11 )
{
v12 = (char *)samples + 16 * v11++;
sprintf(v17, "%lld\n", *((_QWORD *)v12 + 1));
v13 = strlen(v17);
write(v10, v17, v13);
}
close(v10);
}
free(samples);
exit(0);
}
__assert_fail("samples != NULL", "ftq.c", 0x116u, "main");
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
char v5; // cl
int v6; // ebp
unsigned __int64 v7; // rbx
unsigned __int64 v8; // rsi
size_t v9; // rax
int v10; // ebp
unsigned __int64 v11; // r12
char *v12; // rdx
size_t v13; // rax
unsigned __int64 i; // rbx
unsigned __int64 v15; // r8
int result; // eax
char v17[32]; // [rsp+0h] [rbp-938h] BYREF
char dest[4]; // [rsp+20h] [rbp-918h] BYREF
char s[1024]; // [rsp+120h] [rbp-818h] BYREF
int longind[262]; // [rsp+520h] [rbp-418h] BYREF

v3 = 0;
strcpy(dest, "ftq");
while ( 1 )
{
longind[0] = 0;
v4 = getopt_long(argc, (char *const *)argv, "n:hsi:o:t:", &long_options_1, longind);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'i':
interval_bits = atoi(optarg);
break;
case 'n':
numsamples = atoi(optarg);
break;
case 'o':
strcpy(dest, optarg);
break;
case 's':
v3 = 1;
break;
case 't':
fwrite("ERROR: ftq not compiled with pthreads support.\n", 1uLL, 0x2FuLL, stderr);
exit(1);
default:
func8(*argv);
return result;
}
}
if ( (unsigned __int64)numsamples > 0x1E8480 )
{
fwrite("WARNING: sample count exceeds maximum.\n", 1uLL, 0x27uLL, stderr);
fwrite(" setting count to maximum.\n", 1uLL, 0x23uLL, stderr);
numsamples = 2000000LL;
}
samples = malloc(16 * numsamples);
if ( samples )
{
v5 = interval_bits;
if ( (unsigned int)(interval_bits - 3) > 0x1B )
{
fprintf(stderr, "WARNING: interval bits invalid. set to %d.\n", 30LL);
v5 = 30;
interval_bits = 30;
}
interval_length = 1 << v5;
func9(0LL);
if ( v3 == 1 )
{
for ( i = 0LL; numsamples > i; ++i )
{
v15 = i;
fprintf(stdout, "%lld %lld\n", *((_QWORD *)samples + 2 * v15), *((_QWORD *)samples + 2 * v15 + 1));
}
}
else
{
sprintf(s, "%s_%d_times.dat", dest, 0LL);
sprintf((char *)longind, "%s_%d_counts.dat", dest, 0LL);
v6 = open(s, 577, 420LL);
if ( v6 < 0 )
goto LABEL_30;
v7 = 0LL;
while ( v7 < numsamples )
{
v8 = v7++;
sprintf(v17, "%lld\n", *((_QWORD *)samples + 2 * v8));
v9 = strlen(v17);
write(v6, v17, v9);
}
close(v6);
v10 = open((const char *)longind, 577, 420LL);
if ( v10 < 0 )
{
LABEL_30:
perror("can not create file");
exit(1);
}
v11 = 0LL;
while ( numsamples > v11 )
{
v12 = (char *)samples + 16 * v11++;
sprintf(v17, "%lld\n", *((_QWORD *)v12 + 1));
v13 = strlen(v17);
write(v10, v17, v13);
}
close(v10);
}
free(samples);
exit(0);
}
__assert_fail("samples != NULL", "ftq.c", 0x116u, "main");
}

original_code:
int main(int argc, char **argv) {
  char fname_times[1024], fname_counts[1024], buf[32], outname[255];
  int i,j;
  int numthreads = 1, use_threads = 0;
  int fp;
  int use_stdout = 0;
  sprintf(outname,"ftq");
  while (1) {
    int c;
    int option_index = 0;
    static struct option long_options[] = {
      {"help",0,0,'h'},
      {"numsamples",0,0,'n'},
      {"interval",0,0,'i'},
      {"outname",0,0,'o'},
      {"stdout",0,0,'s'},
      {"threads",0,0,'t'},
      {0,0,0,0}
    };
    c = getopt_long(argc, argv, "n:hsi:o:t:",
      long_options, &option_index);
    if (c == -1)
      break;
    switch (c) {
    case 't':
      fprintf(stderr,"ERROR: ftq not compiled with pthreads support.\n");
      exit(1);
      numthreads = atoi(optarg);
      use_threads = 1;
      break;
    case 's':
      use_stdout = 1;
      break;
    case 'o':
      sprintf(outname,"%s",optarg);
      break;
    case 'i':
      interval_bits = atoi(optarg);
      break;
    case 'n':
      numsamples = atoi(optarg);
      break;
    case 'h':
    default:
      usage(argv[0]);
      break;
    }
  }
  if (numsamples > 2000000) {
    fprintf(stderr,"WARNING: sample count exceeds maximum.\n");
    fprintf(stderr,"         setting count to maximum.\n");
    numsamples = 2000000;
  }
  samples = malloc(sizeof(unsigned long long)*numsamples*2*numthreads);
  ((void) sizeof ((samples != ((void *)0)) ? 1 : 0), __extension__ ({ if (samples != ((void *)0)) ; else __assert_fail ("samples != NULL", "ftq.c", 278, __extension__ __PRETTY_FUNCTION__); }));
  if (interval_bits > 30 || interval_bits < 3) {
    fprintf(stderr,"WARNING: interval bits invalid.  set to %d.\n",
     30);
    interval_bits = 30;
  }
  if (use_threads == 1 && numthreads < 2) {
    fprintf(stderr,"ERROR: >1 threads required for multithread mode.\n");
    exit(1);
  }
  if (use_threads == 1 && use_stdout == 1) {
    fprintf(stderr,"ERROR: cannot output to stdout for multithread mode.\n");
    exit(1);
  }
  interval_length = 1 << interval_bits;
  if (use_threads == 1) {
  } else {
    ftq_core(0);
  }
  if (use_stdout == 1) {
    for (i=0;i<numsamples;i++) {
      fprintf(stdout,"%lld %lld\n",samples[i*2],samples[i*2 + 1]);
    }
  } else {
    for (j=0;j<numthreads;j++) {
      sprintf(fname_times,"%s_%d_times.dat",outname,j);
      sprintf(fname_counts,"%s_%d_counts.dat",outname,j);
      fp = open(fname_times, 0100|01000|01, 0644);
      if(fp < 0) {
 perror("can not create file");
 exit(1);
      }
      for (i=0;i<numsamples;i++) {
 sprintf(buf, "%lld\n", samples[(i*2)+(numsamples*j)]);
 write(fp, buf, strlen(buf));
      }
      close(fp);
      fp = open(fname_counts, 0100|01000|01, 0644);
      if(fp < 0) {
 perror("can not create file");
 exit(1);
      }
      for (i=0;i<numsamples;i++) {
 sprintf(buf, "%lld\n", samples[i*2 + 1 + (numsamples*j)]);
 write(fp, buf, strlen(buf));
      }
      close(fp);
    }
  }
  free(samples);
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv) {
  char fname_times[1024]; char fname_counts[1024]; char buf[32]; char outname[255];
  int i; int j;
  int numthreads = 1; int use_threads = 0;
  int fp;
  int use_stdout = 0;
  sprintf(outname,"ftq");
  while (1) {
    int c;
    int option_index = 0;
    static struct option long_options[] = {
      {"help",0,0,'h'},
      {"numsamples",0,0,'n'},
      {"interval",0,0,'i'},
      {"outname",0,0,'o'},
      {"stdout",0,0,'s'},
      {"threads",0,0,'t'},
      {0,0,0,0}
    };
    c = getopt_long(argc, argv, "n:hsi:o:t:",
      long_options, &option_index);
    if (c == -1)
      break;
    switch (c) {
    case 't':
      fprintf(stderr,"ERROR: ftq not compiled with pthreads support.\n");
      exit(1);
      numthreads = atoi(optarg);
      use_threads = 1;
      break;
    case 's':
      use_stdout = 1;
      break;
    case 'o':
      sprintf(outname,"%s",optarg);
      break;
    case 'i':
      interval_bits = atoi(optarg);
      break;
    case 'n':
      numsamples = atoi(optarg);
      break;
    case 'h':
    default:
      usage(argv[0]);
      break;
    }
  }
  if (numsamples > 2000000) {
    fprintf(stderr,"WARNING: sample count exceeds maximum.\n");
    fprintf(stderr,"         setting count to maximum.\n");
    numsamples = 2000000;
  }
  samples = malloc(sizeof(unsigned long long)*numsamples*2*numthreads);
  ((void) sizeof ((samples != ((void *)0)) ? 1 : 0), __extension__ ({ if (samples != ((void *)0)) ; else __assert_fail ("samples != NULL", "ftq.c", 278, __extension__ __PRETTY_FUNCTION__); }));
  if (interval_bits > 30 || interval_bits < 3) {
    fprintf(stderr,"WARNING: interval bits invalid.  set to %d.\n",
     30);
    interval_bits = 30;
  }
  if (use_threads == 1 && numthreads < 2) {
    fprintf(stderr,"ERROR: >1 threads required for multithread mode.\n");
    exit(1);
  }
  if (use_threads == 1 && use_stdout == 1) {
    fprintf(stderr,"ERROR: cannot output to stdout for multithread mode.\n");
    exit(1);
  }
  interval_length = 1 << interval_bits;
  if (use_threads == 1) {
  } else {
    ftq_core(0);
  }
  if (use_stdout == 1) {
    for (i=0;i<numsamples;i++) {
      fprintf(stdout,"%lld %lld\n",samples[i*2],samples[i*2 + 1]);
    }
  } else {
    for (j=0;j<numthreads;j++) {
      sprintf(fname_times,"%s_%d_times.dat",outname,j);
      sprintf(fname_counts,"%s_%d_counts.dat",outname,j);
      fp = open(fname_times, 0100|01000|01, 0644);
      if(fp < 0) {
 perror("can not create file");
 exit(1);
      }
      for (i=0;i<numsamples;i++) {
 sprintf(buf, "%lld\n", samples[(i*2)+(numsamples*j)]);
 write(fp, buf, strlen(buf));
      }
      close(fp);
      fp = open(fname_counts, 0100|01000|01, 0644);
      if(fp < 0) {
 perror("can not create file");
 exit(1);
      }
      for (i=0;i<numsamples;i++) {
 sprintf(buf, "%lld\n", samples[i*2 + 1 + (numsamples*j)]);
 write(fp, buf, strlen(buf));
      }
      close(fp);
    }
  }
  free(samples);
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
buf
char [32]

variable_types:
outname
char [255]

variable_types: i int

variable_types: j int

variable_types: numthreads int

variable_types: fp int

variable_types: c int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


getticks

decompiled_code:
unsigned __int64 getticks()
{
return __rdtsc();
}

canonical_decompiled_code:
unsigned __int64 func7()
{
return __rdtsc();
}

original_code:
static __inline__ ticks getticks(void)
{
     unsigned a, d;
     asm volatile("rdtsc" : "=a" (a), "=d" (d));
     return ((ticks)a) | (((ticks)d) << 32);
}

canonical_original_code:
static __inline__ unsigned long long getticks()
{
     unsigned int a; unsigned int d;
     asm volatile("rdtsc" : "=a" (a), "=d" (d));
     return ((unsigned long long)a) | (((unsigned long long)d) << 32);
}

variable_types:
a
unsigned int

variable_types:
d
unsigned int

return_type: unsigned long long


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "usage: %s [-n samples] [-i bits] [-h] [-o outname] [-s]\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
fprintf(stderr, "usage: %s [-n samples] [-i bits] [-h] [-o outname] [-s]\n", a1);
exit(1);
}

original_code:
void usage(char *av0) {
  fprintf(stderr,"usage: %s [-n samples] [-i bits] [-h] [-o outname] [-s]\n",
   av0);
  exit(1);
}


createGameResult

decompiled_code:
__int64 createGameResult()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0xFFFFFFFFLL;
}

original_code:
struct GameResult createGameResult()
{
 struct GameResult result;
 result.winner = noPlayer;
 return result;
}

variable_types: struct GameResult { enum Players { noPlayer=-1, circle=0, cross=1 } winner; enum CellLine { r0=0, r1=1, r2=2, c0=3, c1=4, c2=5, d0=6, d1=7 } winningLine; }

user_defined_types: struct GameResult { enum Players winner; enum CellLine winningLine; }


deleteGameResult

decompiled_code:
void deleteGameResult()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void deleteGameResult(struct GameResult result)
{
}

user_defined_types: enum Players { noPlayer=-1, circle=0, cross=1 }


copyGameResult

decompiled_code:
__int64 __fastcall copyGameResult(__int64 a1)
{
createGameResult();
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
func0();
return a1;
}

original_code:
struct GameResult copyGameResult(struct GameResult result)
{
 struct GameResult newResult = createGameResult();
 newResult.winner = result.winner;
 newResult.winningLine = result.winningLine;
 return newResult;
}

variable_types:
result
struct GameResult

return_type: struct GameResult { enum Players { noPlayer=-1, circle=0, cross=1 } winner; enum CellLine { r0=0, r1=1, r2=2, c0=3, c1=4, c2=5, d0=6, d1=7 } winningLine; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v4[8]; // [rsp+8h] [rbp-10h] BYREF

initscr();
cbreak();
noecho();
nodelay(stdscr, 1);
scrollok(stdscr, 1);
curs_set(0);
ioctl(0, 0x5413uLL, v4);
initializeTrisGame((unsigned __int16)v4[1], (unsigned __int16)v4[0], 0LL);
while ( !(unsigned int)updateTrisGame(33LL) )
{
drawTrisGame();
usleep(0x80E8u);
}
destroyTrisGame();
endwin();
return 0;
}

original_code:
int main()
{
 int cycleDeltaT = (int)(1000/30);
 int consoleBase, consoleHigh;
 void *consoleHandle = 0;
 initscr();
 cbreak();
    noecho();
    nodelay(stdscr, 1);
    scrollok(stdscr, 1);
 curs_set(0);
    struct winsize ts;
    ioctl(0, 0x5413, &ts);
    consoleBase = ts.ws_col;
    consoleHigh = ts.ws_row;
 initializeTrisGame(consoleBase, consoleHigh, consoleHandle);
 while(!updateTrisGame(cycleDeltaT))
 {
  drawTrisGame();
  usleep(cycleDeltaT*1000);
 };
 destroyTrisGame();
 endwin();
 return 0;
}

canonical_original_code:
int main()
{
 int cycleDeltaT = (int)(1000/30);
 int consoleBase; int consoleHigh;
 void *consoleHandle = 0;
 initscr();
 cbreak();
    noecho();
    nodelay(stdscr, 1);
    scrollok(stdscr, 1);
 curs_set(0);
    struct winsize ts;
    ioctl(0, 0x5413, &ts);
    consoleBase = ts.ws_col;
    consoleHigh = ts.ws_row;
 initializeTrisGame(consoleBase, consoleHigh, consoleHandle);
 while(!updateTrisGame(cycleDeltaT))
 {
  drawTrisGame();
  usleep(cycleDeltaT*1000);
 };
 destroyTrisGame();
 endwin();
 return 0;
}

variable_types: cycleDeltaT int

variable_types: consoleBase int

variable_types: consoleHigh int

variable_types:
consoleHandle
void *

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


createGrid

decompiled_code:
char *createGrid()
{
char *v0; // r12
char *v1; // rbx
_DWORD *v2; // rax

v0 = (char *)malloc(0x18uLL);
v1 = v0;
do
{
v1 += 8;
v2 = malloc(0xCuLL);
*((_QWORD *)v1 - 1) = v2;
*(_QWORD *)v2 = -1LL;
v2[2] = -1;
}
while ( v0 + 24 != v1 );
return v0;
}

original_code:
Grid createGrid()
{
 Grid grid = (CellState**) malloc(sizeof(CellState*)*3);
 int i, j;
 for(i = 0; i < 3; i++)
 {
  grid[i] = (CellState*) malloc(sizeof(CellState)*3);
  for(j = 0; j < 3; j++)
   grid[i][j] = (CellState)noPlayer;
 }
 return grid;
}

canonical_original_code:
enum Players **createGrid()
{
 enum Players **grid = (CellState**) malloc(sizeof(CellState*)*3);
 int i; int j;
 for(i = 0; i < 3; i++)
 {
  grid[i] = (enum Players *) malloc(sizeof(CellState)*3);
  for(j = 0; j < 3; j++)
   grid[i][j] = (enum Players)noPlayer;
 }
 return grid;
}

variable_types: enum Players { noPlayer=-1, circle=0, cross=1 } **


deleteGrid

decompiled_code:
void __fastcall deleteGrid(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}

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

original_code:
void deleteGrid(Grid grid)
{
 int i;
 for(i = 0; i < 3; i++)
  free(grid[i]);
 free(grid);
}

canonical_original_code:
void deleteGrid(enum Players **grid)
{
 int i;
 for(i = 0; i < 3; i++)
  free(grid[i]);
 free(grid);
}


getCell

decompiled_code:
__int64 __fastcall getCell(__int64 a1, int a2)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 8LL * (a2 / 3)) + 4LL * (a2 % 3));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 8LL * (a2 / 3)) + 4LL * (a2 % 3));
}

original_code:
CellState getCell(Grid grid, enum Cell cell)
{
 return grid[(int)cell/3][(int)cell%3];
}

canonical_original_code:
enum Players getCell(enum Players **grid, enum Cell cell)
{
 return grid[(int)cell/3][(int)cell%3];
}

variable_types: enum Cell { cellA1=0, cellA2=1, cellA3=2, cellB1=3, cellB2=4, cellB3=5, cellC1=6, cellC2=7, cellC3=8 }

return_type: enum Players { noPlayer=-1, circle=0, cross=1 }


setCell

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

result = *(_QWORD *)(a1 + 8LL * (a2 / 3));
*(_DWORD *)(result + 4LL * (a2 % 3)) = a3;
return result;
}

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

result = *(_QWORD *)(a1 + 8LL * (a2 / 3));
*(_DWORD *)(result + 4LL * (a2 % 3)) = a3;
return result;
}

original_code:
void setCell(Grid grid, enum Cell cell, CellState value)
{
 grid[(int)cell/3][(int)cell%3] = value;
}

canonical_original_code:
void setCell(enum Players **grid, enum Cell cell, enum Players value)
{
 grid[(int)cell/3][(int)cell%3] = value;
}

variable_types: enum Players { noPlayer=-1, circle=0, cross=1 }

user_defined_types: enum Cell { cellA1=0, cellA2=1, cellA3=2, cellB1=3, cellB2=4, cellB3=5, cellC1=6, cellC2=7, cellC3=8 }


emptyGrid

decompiled_code:
__int64 __fastcall emptyGrid(_QWORD *a1)
{
_QWORD *v1; // rdx
_DWORD *v2; // rax

v1 = a1 + 3;
while ( 1 )
{
v2 = (_DWORD *)*a1;
if ( *(_DWORD *)*a1 != -1 || v2[1] != -1 || v2[2] != -1 )
break;
if ( ++a1 == v1 )
return 1LL;
}
return 0LL;
}

original_code:
int emptyGrid(Grid grid)
{
 int i, j;
 for(i = 0; i < 3; i++)
  for(j = 0; j < 3; j++)
   if(grid[i][j] != noPlayer)
    return 0;
 return 1;
}

canonical_original_code:
int emptyGrid(enum Players **grid)
{
 int i; int j;
 for(i = 0; i < 3; i++)
  for(j = 0; j < 3; j++)
   if(grid[i][j] != noPlayer)
    return 0;
 return 1;
}

variable_types: i int

variable_types: j int


fullGrid

decompiled_code:
__int64 __fastcall fullGrid(_QWORD *a1)
{
_QWORD *v1; // rdx
_DWORD *v2; // rax

v1 = a1 + 3;
while ( 1 )
{
v2 = (_DWORD *)*a1;
if ( *(_DWORD *)*a1 == -1 || v2[1] == -1 || v2[2] == -1 )
break;
if ( ++a1 == v1 )
return 1LL;
}
return 0LL;
}

original_code:
int fullGrid(Grid grid)
{
 int i, j;
 for(i = 0; i < 3; i++)
  for(j = 0; j < 3; j++)
   if(grid[i][j] == noPlayer)
    return 0;
 return 1;
}

canonical_original_code:
int fullGrid(enum Players **grid)
{
 int i; int j;
 for(i = 0; i < 3; i++)
  for(j = 0; j < 3; j++)
   if(grid[i][j] == noPlayer)
    return 0;
 return 1;
}


won

decompiled_code:
__int64 __fastcall won(__int64 a1, __int64 a2)
{
unsigned int i; // er8
int v3; // ecx
int v4; // eax
int v5; // ecx
unsigned int v6; // er8
int v7; // er9
int j; // ecx
int v9; // er9
int v10; // eax
int v11; // ecx
int v12; // er8
int v13; // eax
int v14; // er9
int v15; // er9
__int64 result; // rax
int v17; // er8
int v18; // eax
unsigned int v19; // er9
int v20; // eax
unsigned int v21; // er8
unsigned int v22; // er9
int v23; // eax
unsigned int v24; // er9
int v25; // eax
unsigned int v26; // er8

if ( a2 )
setGameResultState(a2, 0xFFFFFFFFLL, 0LL);
for ( i = 0; i != 3; i = v6 + 1 )
{
getCell(a1, 3 * i);
v4 = getCell(a1, v3 + 1);
if ( v7 == v4 )
{
v18 = getCell(a1, v5 + 2);
if ( v19 == v18 && v19 != -1 )
{
result = 1LL;
if ( a2 )
{
setGameResultState(a2, v19, v6);
result = 1LL;
}
return result;
}
}
}
for ( j = 0; j != 3; j = v11 + 1 )
{
getCell(a1, j);
v10 = getCell(a1, v9);
if ( v12 == v10 )
{
v20 = getCell(a1, v11 + 6);
if ( v21 != -1 && v21 == v20 )
{
result = 1LL;
if ( a2 )
{
setGameResultState(a2, v21, v22);
result = 1LL;
}
return result;
}
}
}
getCell(a1, 0);
v13 = getCell(a1, 4);
if ( v14 == v13 && (v23 = getCell(a1, 8), v24 == v23) && v24 != -1 )
{
result = 1LL;
if ( a2 )
{
setGameResultState(a2, v24, 6LL);
result = 1LL;
}
}
else
{
v15 = getCell(a1, 2);
result = 0LL;
if ( v17 == v15 )
{
v25 = getCell(a1, 6);
if ( v26 != v25 || v26 == -1 )
{
result = 0LL;
}
else
{
result = 1LL;
if ( a2 )
{
setGameResultState(a2, v26, 7LL);
result = 1LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
unsigned int i; // er8
int v3; // ecx
int v4; // eax
int v5; // ecx
unsigned int v6; // er8
int v7; // er9
int j; // ecx
int v9; // er9
int v10; // eax
int v11; // ecx
int v12; // er8
int v13; // eax
int v14; // er9
int v15; // er9
__int64 result; // rax
int v17; // er8
int v18; // eax
unsigned int v19; // er9
int v20; // eax
unsigned int v21; // er8
unsigned int v22; // er9
int v23; // eax
unsigned int v24; // er9
int v25; // eax
unsigned int v26; // er8

if ( a2 )
setGameResultState(a2, 0xFFFFFFFFLL, 0LL);
for ( i = 0; i != 3; i = v6 + 1 )
{
func3(a1, 3 * i);
v4 = func3(a1, v3 + 1);
if ( v7 == v4 )
{
v18 = func3(a1, v5 + 2);
if ( v19 == v18 && v19 != -1 )
{
result = 1LL;
if ( a2 )
{
setGameResultState(a2, v19, v6);
result = 1LL;
}
return result;
}
}
}
for ( j = 0; j != 3; j = v11 + 1 )
{
func3(a1, j);
v10 = func3(a1, v9);
if ( v12 == v10 )
{
v20 = func3(a1, v11 + 6);
if ( v21 != -1 && v21 == v20 )
{
result = 1LL;
if ( a2 )
{
setGameResultState(a2, v21, v22);
result = 1LL;
}
return result;
}
}
}
func3(a1, 0);
v13 = func3(a1, 4);
if ( v14 == v13 && (v23 = func3(a1, 8), v24 == v23) && v24 != -1 )
{
result = 1LL;
if ( a2 )
{
setGameResultState(a2, v24, 6LL);
result = 1LL;
}
}
else
{
v15 = func3(a1, 2);
result = 0LL;
if ( v17 == v15 )
{
v25 = func3(a1, 6);
if ( v26 != v25 || v26 == -1 )
{
result = 0LL;
}
else
{
result = 1LL;
if ( a2 )
{
setGameResultState(a2, v26, 7LL);
result = 1LL;
}
}
}
}
return result;
}

original_code:
int won(Grid grid, struct GameResult *result)
{
 int i;
 if(result != ((void *)0))
  setGameResultState(result, noPlayer, (enum CellLine)0);
 for(i = 0; i < 3; i++)
  if( getCell(grid, (enum Cell)(i*3 )) == getCell(grid, (enum Cell)(i*3 + 1)) &&
   getCell(grid, (enum Cell)(i*3 + 1)) == getCell(grid, (enum Cell)(i*3 + 2)) &&
   getCell(grid, (enum Cell)(i*3 )) != noPlayer)
  {
   if(result != ((void *)0))
    setGameResultState(result, getCell(grid, (enum Cell)(i*3)), (enum CellLine)i);
   return 1;
  }
 for(i = 0; i < 3; i++)
  if( getCell(grid, (enum Cell)(i )) == getCell(grid, (enum Cell)(i+3)) &&
   getCell(grid, (enum Cell)(i+3)) == getCell(grid, (enum Cell)(i+6)) &&
   getCell(grid, (enum Cell)(i )) != noPlayer)
  {
   if(result != ((void *)0))
    setGameResultState(result, getCell(grid, (enum Cell)(i)), (enum CellLine)(i+3));
   return 1;
  }
 if(getCell(grid, cellA1) == getCell(grid, cellB2) &&
  getCell(grid, cellB2) == getCell(grid, cellC3) &&
  getCell(grid, cellA1) != noPlayer)
 {
  if(result != ((void *)0))
   setGameResultState(result, getCell(grid, cellA1), d0);
  return 1;
 }
 if(getCell(grid, cellA3) == getCell(grid, cellB2) &&
  getCell(grid, cellB2) == getCell(grid, cellC1) &&
  getCell(grid, cellA3) != noPlayer)
 {
  if(result != ((void *)0))
   setGameResultState(result, getCell(grid, cellA3), d1);
  return 1;
 }
 return 0;
}

canonical_original_code:
int won(enum Players **grid, struct GameResult *result)
{
 int i;
 if(result != ((void *)0))
  setGameResultState(result, noPlayer, (enum CellLine)0);
 for(i = 0; i < 3; i++)
  if( getCell(grid, (enum Cell)(i*3 )) == getCell(grid, (enum Cell)(i*3 + 1)) &&
   getCell(grid, (enum Cell)(i*3 + 1)) == getCell(grid, (enum Cell)(i*3 + 2)) &&
   getCell(grid, (enum Cell)(i*3 )) != noPlayer)
  {
   if(result != ((void *)0))
    setGameResultState(result, getCell(grid, (enum Cell)(i*3)), (enum CellLine)i);
   return 1;
  }
 for(i = 0; i < 3; i++)
  if( getCell(grid, (enum Cell)(i )) == getCell(grid, (enum Cell)(i+3)) &&
   getCell(grid, (enum Cell)(i+3)) == getCell(grid, (enum Cell)(i+6)) &&
   getCell(grid, (enum Cell)(i )) != noPlayer)
  {
   if(result != ((void *)0))
    setGameResultState(result, getCell(grid, (enum Cell)(i)), (enum CellLine)(i+3));
   return 1;
  }
 if(getCell(grid, cellA1) == getCell(grid, cellB2) &&
  getCell(grid, cellB2) == getCell(grid, cellC3) &&
  getCell(grid, cellA1) != noPlayer)
 {
  if(result != ((void *)0))
   setGameResultState(result, getCell(grid, cellA1), d0);
  return 1;
 }
 if(getCell(grid, cellA3) == getCell(grid, cellB2) &&
  getCell(grid, cellB2) == getCell(grid, cellC1) &&
  getCell(grid, cellA3) != noPlayer)
 {
  if(result != ((void *)0))
   setGameResultState(result, getCell(grid, cellA3), d1);
  return 1;
 }
 return 0;
}

variable_types: struct GameResult { enum Players { noPlayer=-1, circle=0, cross=1 } winner; enum CellLine { r0=0, r1=1, r2=2, c0=3, c1=4, c2=5, d0=6, d1=7 } winningLine; } *


printGrid

original_code:
void printGrid(Grid grid, enum Cell lastMove, int timeFromLastMove, int animTime, char** imageGrid)
{
 int i, j;
 for(i = 0; i < 22; i++)
 {
  if(i % 7 == 0)
  {
   char *line;
   switch(i)
   {
   case 0: line = "/------+------+------\\"; break;
   case 21: line = "\\------+------+------/"; break;
   default: line = "+------+------+------+";
   }
   for(j = 0; j < 22; j++)
    imageGrid[i][j] = line[j];
  }
  else
  {
   for(j = 0; j < 22; j++)
    if(j % 7 == 0)
     imageGrid[i][j] = '|';
    else
    {
     int row = (i / 7), column = (j / 7);
     enum Cell currentCell = (enum Cell)(row*3+column);
     int limitTimeForDraw;
     char charToDraw;
     switch(getCell(grid, currentCell))
     {
     case noPlayer:
      imageGrid[i][j] = imageEmptyCell[(i-1)%7][(j-1)%7];
      break;
     case circle:
      if(currentCell != lastMove || animTime == 0 ||
       drawTimeCircleCell[(i-1)%7][(j-1)%7] <= totalDrawTimeCircleCell * timeFromLastMove / animTime)
       imageGrid[i][j] = imageCircleCell[(i-1)%7][(j-1)%7];
      else
       imageGrid[i][j] = ' ';
      break;
     case cross:
      if(currentCell != lastMove || animTime == 0 ||
       drawTimeCrossCell[(i-1)%7][(j-1)%7] <= totalDrawTimeCrossCell * timeFromLastMove / animTime)
       imageGrid[i][j] = imageCrossCell[(i-1)%7][(j-1)%7];
      else
       imageGrid[i][j] = ' ';
     }
    }
  }
 }
}

canonical_original_code:
void printGrid(enum Players **grid, enum Cell lastMove, int timeFromLastMove, int animTime, char **imageGrid)
{
 int i; int j;
 for(i = 0; i < 22; i++)
 {
  if(i % 7 == 0)
  {
   char *line;
   switch(i)
   {
   case 0: line = "/------+------+------\\"; break;
   case 21: line = "\\------+------+------/"; break;
   default: line = "+------+------+------+";
   }
   for(j = 0; j < 22; j++)
    imageGrid[i][j] = line[j];
  }
  else
  {
   for(j = 0; j < 22; j++)
    if(j % 7 == 0)
     imageGrid[i][j] = '|';
    else
    {
     int row = (i / 7); int column = (j / 7);
     enum Cell currentCell = (enum Cell)(row*3+column);
     int limitTimeForDraw;
     char charToDraw;
     switch(getCell(grid, currentCell))
     {
     case noPlayer:
      imageGrid[i][j] = imageEmptyCell[(i-1)%7][(j-1)%7];
      break;
     case circle:
      if(currentCell != lastMove || animTime == 0 ||
       drawTimeCircleCell[(i-1)%7][(j-1)%7] <= totalDrawTimeCircleCell * timeFromLastMove / animTime)
       imageGrid[i][j] = imageCircleCell[(i-1)%7][(j-1)%7];
      else
       imageGrid[i][j] = ' ';
      break;
     case cross:
      if(currentCell != lastMove || animTime == 0 ||
       drawTimeCrossCell[(i-1)%7][(j-1)%7] <= totalDrawTimeCrossCell * timeFromLastMove / animTime)
       imageGrid[i][j] = imageCrossCell[(i-1)%7][(j-1)%7];
      else
       imageGrid[i][j] = ' ';
     }
    }
  }
 }
}

variable_types: timeFromLastMove int

variable_types: animTime int

variable_types:
imageGrid
char **

variable_types:
line
char *

variable_types: row int

variable_types: column int

variable_types: limitTimeForDraw int

variable_types: charToDraw char


countIntegerDigits

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

v1 = 0;
do
{
++v1;
a1 /= 10;
}
while ( a1 );
return v1;
}

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

v1 = 0;
do
{
++v1;
a1 /= 10;
}
while ( a1 );
return v1;
}

original_code:
int countIntegerDigits(int n)
{
 int digits = 0;
 do
 {
  digits++;
  n/=10;
 }while(n != 0);
 return digits;
}

variable_types: n int

variable_types: digits int


integerToString

decompiled_code:
__int64 __fastcall integerToString(int a1)
{
int v1; // eax
int v2; // ecx
int v3; // er9
__int64 v4; // r10
int v5; // edx
int v6; // esi
int v7; // edx
__int64 result; // rax
__int64 v9; // rdx

v1 = countIntegerDigits(a1);
v5 = v3;
v6 = v1 - (((unsigned int)v2 < 0x80000000) - 1);
if ( v6 >= v3 )
v5 = v1 - (((unsigned int)v2 < 0x80000000) - 1);
v7 = v5 - 1;
result = v7;
if ( v7 >= 0 )
{
do
{
while ( (int)result < v3 )
{
if ( (int)result >= v6 )
{
*(_BYTE *)(v4 + result) = 0;
goto LABEL_10;
}
if ( v2 || v6 <= 1 )
{
v9 = v2;
*(_BYTE *)(v4 + result) = v2 % 10 + 48;
}
else
{
*(_BYTE *)(v4 + result) = 45;
v9 = 0LL;
}
LABEL_9:
v2 = ((int)((unsigned __int64)(1717986919 * v9) >> 32) >> 2) - (v2 >> 31);
LABEL_10:
if ( (int)--result < 0 )
return result;
}
v9 = v2;
if ( (int)result < v6 )
goto LABEL_9;
--result;
}
while ( (int)result >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // eax
int v2; // ecx
int v3; // er9
__int64 v4; // r10
int v5; // edx
int v6; // esi
int v7; // edx
__int64 result; // rax
__int64 v9; // rdx

v1 = func0(a1);
v5 = v3;
v6 = v1 - (((unsigned int)v2 < 0x80000000) - 1);
if ( v6 >= v3 )
v5 = v1 - (((unsigned int)v2 < 0x80000000) - 1);
v7 = v5 - 1;
result = v7;
if ( v7 >= 0 )
{
do
{
while ( (int)result < v3 )
{
if ( (int)result >= v6 )
{
*(_BYTE *)(v4 + result) = 0;
goto LABEL_10;
}
if ( v2 || v6 <= 1 )
{
v9 = v2;
*(_BYTE *)(v4 + result) = v2 % 10 + 48;
}
else
{
*(_BYTE *)(v4 + result) = 45;
v9 = 0LL;
}
LABEL_9:
v2 = ((int)((unsigned __int64)(1717986919 * v9) >> 32) >> 2) - (v2 >> 31);
LABEL_10:
if ( (int)--result < 0 )
return result;
}
v9 = v2;
if ( (int)result < v6 )
goto LABEL_9;
--result;
}
while ( (int)result >= 0 );
}
return result;
}

original_code:
void integerToString(int n, char *str, int strLen)
{
 int i, numLength;
 numLength = countIntegerDigits(n);
 if(n < 0)
  numLength++;
 for(i = (numLength > strLen ? numLength : strLen) - 1; i >= 0; i--)
 {
  if(i < strLen)
  {
   if(i < numLength)
   {
    if(n == 0 && numLength > 1)
     str[i] = '-';
    else
     str[i] = (n % 10) + '0';
   }
   else
    str[i] = '\0';
  }
  if(i < numLength)
   n /= 10;
 }
}

canonical_original_code:
void integerToString(int n, char *str, int strLen)
{
 int i; int numLength;
 numLength = countIntegerDigits(n);
 if(n < 0)
  numLength++;
 for(i = (numLength > strLen ? numLength : strLen) - 1; i >= 0; i--)
 {
  if(i < strLen)
  {
   if(i < numLength)
   {
    if(n == 0 && numLength > 1)
     str[i] = '-';
    else
     str[i] = (n % 10) + '0';
   }
   else
    str[i] = '\0';
  }
  if(i < numLength)
   n /= 10;
 }
}

variable_types:
str
char *

variable_types: strLen int

variable_types: numLength int


initializeTrisGame

decompiled_code:
void __fastcall initializeTrisGame(int a1, int a2)
{
size_t v2; // r12
int v3; // ebp
_BYTE *v4; // rbx
__int64 v5; // rax
unsigned int v6; // eax

consoleBase = a1;
consoleHigh = a2;
wclear(stdscr);
state = 0;
mainMenuInitialize((unsigned int)consoleBase, (unsigned int)consoleHigh, 0LL, 0LL);
v2 = consoleHigh * (__int64)consoleBase;
v3 = consoleHigh * consoleBase;
videoBuffer0 = malloc(v2);
v4 = videoBuffer0;
videoBuffer1 = malloc(v2);
if ( v3 > 0 )
{
v5 = 0LL;
while ( 1 )
{
v4[v5] = 32;
*((_BYTE *)videoBuffer1 + v5++) = 32;
if ( consoleHigh * consoleBase <= (int)v5 )
break;
v4 = videoBuffer0;
}
}
v6 = time(0LL);
srand(v6);
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2)
{
size_t v2; // r12
int v3; // ebp
_BYTE *v4; // rbx
__int64 v5; // rax
unsigned int v6; // eax

consoleBase = a1;
consoleHigh = a2;
wclear(stdscr);
state = 0;
mainMenuInitialize((unsigned int)consoleBase, (unsigned int)consoleHigh, 0LL, 0LL);
v2 = consoleHigh * (__int64)consoleBase;
v3 = consoleHigh * consoleBase;
videoBuffer0 = malloc(v2);
v4 = videoBuffer0;
videoBuffer1 = malloc(v2);
if ( v3 > 0 )
{
v5 = 0LL;
while ( 1 )
{
v4[v5] = 32;
*((_BYTE *)videoBuffer1 + v5++) = 32;
if ( consoleHigh * consoleBase <= (int)v5 )
break;
v4 = videoBuffer0;
}
}
v6 = time(0LL);
srand(v6);
}

original_code:
void initializeTrisGame(int consoleB, int consoleH, void *consoleHandle)
{
 int i;
 consoleBase = consoleB;
 consoleHigh = consoleH;
 wclear(stdscr);
 state = mainMenu;
 mainMenuInitialize(consoleBase, consoleHigh, 0, 0);
 videoBuffer0 = (char*)malloc(sizeof(char)*consoleBase*consoleHigh);
 videoBuffer1 = (char*)malloc(sizeof(char)*consoleBase*consoleHigh);
 for(i = 0; i < consoleBase*consoleHigh; i++)
 {
  videoBuffer0[i] = ' ';
  videoBuffer1[i] = ' ';
 }
 srand((unsigned int)time(0));
}

canonical_original_code:
void initializeTrisGame(int consoleB, int consoleH, void *consoleHandle)
{
 int i;
 consoleBase = consoleB;
 consoleHigh = consoleH;
 wclear(stdscr);
 state = mainMenu;
 mainMenuInitialize(consoleBase, consoleHigh, 0, 0);
 videoBuffer0 = (char *)malloc(sizeof(char)*consoleBase*consoleHigh);
 videoBuffer1 = (char *)malloc(sizeof(char)*consoleBase*consoleHigh);
 for(i = 0; i < consoleBase*consoleHigh; i++)
 {
  videoBuffer0[i] = ' ';
  videoBuffer1[i] = ' ';
 }
 srand((unsigned int)time(0));
}

variable_types: consoleB int

variable_types: consoleH int

variable_types:
consoleHandle
void *


destroyTrisGame

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

free(videoBuffer0);
free(videoBuffer1);
if ( state )
result = playTrisDestroy();
else
result = mainMenuDestroy();
return result;
}

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

free(videoBuffer0);
free(videoBuffer1);
if ( state )
result = playTrisDestroy();
else
result = mainMenuDestroy();
return result;
}

original_code:
void destroyTrisGame()
{
 free(videoBuffer0);
 free(videoBuffer1);
 if(state == mainMenu)
  mainMenuDestroy();
 else
  playTrisDestroy();
}


updateTrisGame

decompiled_code:
__int64 updateTrisGame()
{
unsigned int v0; // er12
int v2; // eax
int v3; // ebx

if ( state )
{
if ( state == 1 )
{
v0 = 0;
if ( (unsigned int)playTrisUpdate() == -1 )
{
playTrisDestroy();
state = 0;
mainMenuInitialize((unsigned int)consoleBase, (unsigned int)consoleHigh, videoBuffer0, 1LL);
}
return v0;
}
}
else
{
v2 = mainMenuUpdate();
v0 = 1;
v3 = v2;
if ( v2 == -1 )
return v0;
if ( (unsigned int)(v2 - 1) <= 1 )
{
mainMenuDestroy();
state = 1;
playTrisInitialize((unsigned int)consoleBase, (unsigned int)consoleHigh, videoBuffer0, 0LL, v3 == 1, 0LL);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // er12
int v2; // eax
int v3; // ebx

if ( state )
{
if ( state == 1 )
{
v0 = 0;
if ( (unsigned int)playTrisUpdate() == -1 )
{
playTrisDestroy();
state = 0;
mainMenuInitialize((unsigned int)consoleBase, (unsigned int)consoleHigh, videoBuffer0, 1LL);
}
return v0;
}
}
else
{
v2 = mainMenuUpdate();
v0 = 1;
v3 = v2;
if ( v2 == -1 )
return v0;
if ( (unsigned int)(v2 - 1) <= 1 )
{
mainMenuDestroy();
state = 1;
playTrisInitialize((unsigned int)consoleBase, (unsigned int)consoleHigh, videoBuffer0, 0LL, v3 == 1, 0LL);
}
}
return 0LL;
}

original_code:
int updateTrisGame(int deltaT)
{
 int exit = 0;
 int command;
 switch(state)
 {
 case mainMenu:
  command = mainMenuUpdate(deltaT);
  switch(command)
  {
  case -1:
   exit = 1;
   break;
  case 1:
  case 2:
   mainMenuDestroy();
   state = inGame;
   playTrisInitialize(consoleBase, consoleHigh, videoBuffer0, local, (command == 1 ? AI : human), human);
   break;
  }
  break;
 case inGame:
  command = playTrisUpdate(deltaT);
  if(command == -1)
  {
   playTrisDestroy();
   state = mainMenu;
   mainMenuInitialize(consoleBase, consoleHigh, videoBuffer0, 1);
  }
  break;
 }
 return exit;
}

variable_types: deltaT int

variable_types: exit int

variable_types: command int


swapVideoBuffer

decompiled_code:
void *swapVideoBuffer()
{
void *result; // rax
void *v1; // rdx

result = videoBuffer0;
v1 = videoBuffer1;
videoBuffer1 = videoBuffer0;
videoBuffer0 = v1;
return result;
}

canonical_decompiled_code:
void *func3()
{
void *result; // rax
void *v1; // rdx

result = videoBuffer0;
v1 = videoBuffer1;
videoBuffer1 = videoBuffer0;
videoBuffer0 = v1;
return result;
}

original_code:
void swapVideoBuffer()
{
 char *tempVideoBuffer = videoBuffer0;
 videoBuffer0 = videoBuffer1;
 videoBuffer1 = tempVideoBuffer;
}

variable_types:
tempVideoBuffer
char *


drawTrisGame

decompiled_code:
int drawTrisGame()
{
__int64 v0; // rbx
chtype v1; // rsi

if ( state )
{
if ( state == 1 )
playTrisDraw(videoBuffer0);
}
else
{
mainMenuDraw(videoBuffer0);
}
wmove(stdscr, 0, 0);
if ( consoleHigh * consoleBase > 1 )
{
v0 = 0LL;
do
{
v1 = (unsigned int)*((char *)videoBuffer0 + v0++);
waddch(stdscr, v1);
}
while ( consoleHigh * consoleBase - 1 > (int)v0 );
}
swapVideoBuffer();
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func4()
{
__int64 v0; // rbx
chtype v1; // rsi

if ( state )
{
if ( state == 1 )
playTrisDraw(videoBuffer0);
}
else
{
mainMenuDraw(videoBuffer0);
}
wmove(stdscr, 0, 0);
if ( consoleHigh * consoleBase > 1 )
{
v0 = 0LL;
do
{
v1 = (unsigned int)*((char *)videoBuffer0 + v0++);
waddch(stdscr, v1);
}
while ( consoleHigh * consoleBase - 1 > (int)v0 );
}
func3();
return wrefresh(stdscr);
}

original_code:
void drawTrisGame()
{
 int i;
 switch(state)
 {
 case mainMenu:
  mainMenuDraw(videoBuffer0);
  break;
 case inGame:
  playTrisDraw(videoBuffer0);
  break;
 }
 wmove(stdscr,(0),(0));
 for(i = 0; i < consoleBase*consoleHigh-1; i++)
 {
  waddch(stdscr,(*(videoBuffer0 + i)));
 }
 swapVideoBuffer();
 wrefresh(stdscr);
}

variable_types: i int


mainMenuInitialize

decompiled_code:
char *__fastcall mainMenuInitialize(int a1, int a2, __int64 a3, int a4)
{
char *v6; // rbx
char *v7; // r13
char v8; // al
char *result; // rax
int v10; // ebx
void *v11; // rdx

consoleBase = a1;
consoleHigh = a2;
mainMenuTimeLastMovement = 0LL;
mainMenuTotalTimeElapsed = 0LL;
mainMenuGrid = createGrid();
mainMenuGridImage = malloc(0xB0uLL);
v6 = (char *)mainMenuGridImage;
v7 = (char *)mainMenuGridImage + 176;
do
{
v6 += 8;
*((_QWORD *)v6 - 1) = malloc(0x16uLL);
}
while ( v7 != v6 );
v8 = rand();
skIntro = a4;
mainMenuPlayTurn = v8 & 1;
result = (char *)((a3 != 0) & (unsigned __int8)(a4 != 0));
mainMenuEnterScrAnim = (unsigned __int8)result;
if ( (_BYTE)result )
{
v10 = consoleHigh * consoleBase;
result = (char *)malloc(consoleHigh * (__int64)consoleBase);
mainMenuPreviousScreen = result;
v11 = result;
if ( v10 > 0 )
{
result = 0LL;
while ( 1 )
{
result[(_QWORD)v11] = result[a3];
if ( consoleHigh * consoleBase <= (int)++result )
break;
v11 = mainMenuPreviousScreen;
}
}
}
exitQuest = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(int a1, int a2, __int64 a3, int a4)
{
char *v6; // rbx
char *v7; // r13
char v8; // al
char *result; // rax
int v10; // ebx
void *v11; // rdx

consoleBase = a1;
consoleHigh = a2;
mainMenuTimeLastMovement = 0LL;
mainMenuTotalTimeElapsed = 0LL;
mainMenuGrid = createGrid();
mainMenuGridImage = malloc(0xB0uLL);
v6 = (char *)mainMenuGridImage;
v7 = (char *)mainMenuGridImage + 176;
do
{
v6 += 8;
*((_QWORD *)v6 - 1) = malloc(0x16uLL);
}
while ( v7 != v6 );
v8 = rand();
skIntro = a4;
mainMenuPlayTurn = v8 & 1;
result = (char *)((a3 != 0) & (unsigned __int8)(a4 != 0));
mainMenuEnterScrAnim = (unsigned __int8)result;
if ( (_BYTE)result )
{
v10 = consoleHigh * consoleBase;
result = (char *)malloc(consoleHigh * (__int64)consoleBase);
mainMenuPreviousScreen = result;
v11 = result;
if ( v10 > 0 )
{
result = 0LL;
while ( 1 )
{
result[(_QWORD)v11] = result[a3];
if ( consoleHigh * consoleBase <= (int)++result )
break;
v11 = mainMenuPreviousScreen;
}
}
}
exitQuest = 0;
return result;
}

original_code:
void mainMenuInitialize(int consoleB, int consoleH, char *prevScreen, int skipIntro)
{
 int i;
 consoleBase = consoleB;
 consoleHigh = consoleH;
 mainMenuTotalTimeElapsed = mainMenuTimeLastMovement = 0;
 mainMenuGrid = createGrid();
 mainMenuGridImage = (char**)malloc(sizeof(char*)*22);
 for(i = 0; i < 22; i++)
  mainMenuGridImage[i] = (char*)malloc(sizeof(char)*(22));
 mainMenuPlayTurn = (rand() % 2 == 0 ? circle : cross);
 skIntro = skipIntro;
 mainMenuEnterScrAnim = skipIntro && prevScreen != 0;
 if(mainMenuEnterScrAnim)
 {
  mainMenuPreviousScreen = (char*)malloc(sizeof(char)*consoleBase*consoleHigh);
  for(i = 0; i < consoleBase*consoleHigh; i++)
   mainMenuPreviousScreen[i] = prevScreen[i];
 }
 exitQuest = 0;
}

canonical_original_code:
void mainMenuInitialize(int consoleB, int consoleH, char *prevScreen, int skipIntro)
{
 int i;
 consoleBase = consoleB;
 consoleHigh = consoleH;
 mainMenuTotalTimeElapsed = mainMenuTimeLastMovement = 0;
 mainMenuGrid = createGrid();
 mainMenuGridImage = (char **)malloc(sizeof(char *)*22);
 for(i = 0; i < 22; i++)
  mainMenuGridImage[i] = (char *)malloc(sizeof(char)*(22));
 mainMenuPlayTurn = (rand() % 2 == 0 ? circle : cross);
 skIntro = skipIntro;
 mainMenuEnterScrAnim = skipIntro && prevScreen != 0;
 if(mainMenuEnterScrAnim)
 {
  mainMenuPreviousScreen = (char *)malloc(sizeof(char)*consoleBase*consoleHigh);
  for(i = 0; i < consoleBase*consoleHigh; i++)
   mainMenuPreviousScreen[i] = prevScreen[i];
 }
 exitQuest = 0;
}

variable_types:
prevScreen
char *

variable_types: skipIntro int


mainMenuDestroy

decompiled_code:
void mainMenuDestroy()
{
__int64 i; // rbx
void *v1; // rdi

for ( i = 0LL; i != 176; i += 8LL )
{
v1 = *(void **)((char *)mainMenuGridImage + i);
free(v1);
}
free(mainMenuGridImage);
if ( mainMenuEnterScrAnim )
free(mainMenuPreviousScreen);
}

canonical_decompiled_code:
void func1()
{
__int64 i; // rbx
void *v1; // rdi

for ( i = 0LL; i != 176; i += 8LL )
{
v1 = *(void **)((char *)mainMenuGridImage + i);
free(v1);
}
free(mainMenuGridImage);
if ( mainMenuEnterScrAnim )
free(mainMenuPreviousScreen);
}

original_code:
void mainMenuDestroy()
{
 int i;
 for(i = 0; i < 22; i++)
  free(mainMenuGridImage[i]);
 free(mainMenuGridImage);
 if(mainMenuEnterScrAnim)
  free(mainMenuPreviousScreen);
}