decompiled_code:
__int64 __fastcall json_checkValidPair(const char *a1)
{
int v1; // er13
int v2; // eax
unsigned int v3; // er12
char *v4; // rdx
char v5; // al
int v6; // eax

v1 = strlen(a1);
v2 = json_checkValidString(a1);
v3 = v2;
if ( v2 == -1 )
return v3;
v4 = (char *)&a1[v2];
if ( v1 <= v2 )
goto LABEL_6;
while ( 1 )
{
v5 = *v4;
if ( *v4 != 32 )
break;
LABEL_10:
++v3;
++v4;
if ( v1 <= (int)v3 || v3 == -1 )
goto LABEL_6;
}
if ( v5 <= 32 )
{
if ( (unsigned __int8)(v5 - 9) > 1u )
return 0xFFFFFFFFLL;
goto LABEL_10;
}
++v3;
if ( v5 == 58 )
{
LABEL_6:
v6 = json_checkValidValue(&a1[v3]);
if ( v6 != -1 )
{
v3 += v6;
return v3;
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
int v1; // er13
int v2; // eax
unsigned int v3; // er12
char *v4; // rdx
char v5; // al
int v6; // eax

v1 = strlen(a1);
v2 = func4(a1);
v3 = v2;
if ( v2 == -1 )
return v3;
v4 = (char *)&a1[v2];
if ( v1 <= v2 )
goto LABEL_6;
while ( 1 )
{
v5 = *v4;
if ( *v4 != 32 )
break;
LABEL_10:
++v3;
++v4;
if ( v1 <= (int)v3 || v3 == -1 )
goto LABEL_6;
}
if ( v5 <= 32 )
{
if ( (unsigned __int8)(v5 - 9) > 1u )
return 0xFFFFFFFFLL;
goto LABEL_10;
}
++v3;
if ( v5 == 58 )
{
LABEL_6:
v6 = func5(&a1[v3]);
if ( v6 != -1 )
{
v3 += v6;
return v3;
}
}
return 0xFFFFFFFFLL;
}

original_code:
int json_checkValidPair(char *JSON)
{
 int i, length, objlen, hasColon;
 char currentChar;
 hasColon = 0;
 objlen = strlen(JSON);
 i = json_checkValidString(JSON);
 if(i == -1)
  return -1;
 while(i < objlen && i != -1)
 {
  currentChar = *(JSON + i);
  switch(currentChar)
  {
   case ' ':
   case '\t':
   case '\n':
    i++;
    break;
   case ':':
    hasColon = 1;
    i++;
    break;
   default:
    return -1;
    break;
  }
  if(hasColon)
   break;
 }
 length = json_checkValidValue(JSON + i);
 if(length == -1)
  i = -1;
 else
  i += length;
 return i;
}

canonical_original_code:
int json_checkValidPair(char *JSON)
{
 int i; int length; int objlen; int hasColon;
 char currentChar;
 hasColon = 0;
 objlen = strlen(JSON);
 i = json_checkValidString(JSON);
 if(i == -1)
  return -1;
 while(i < objlen && i != -1)
 {
  currentChar = *(JSON + i);
  switch(currentChar)
  {
   case ' ':
   case '\t':
   case '\n':
    i++;
    break;
   case ':':
    hasColon = 1;
    i++;
    break;
   default:
    return -1;
    break;
  }
  if(hasColon)
   break;
 }
 length = json_checkValidValue(JSON + i);
 if(length == -1)
  i = -1;
 else
  i += length;
 return i;
}

variable_types: hasColon int


repo: ByzantineFailure/BSON-JSON-Utils

decompiled_code:
__int64 __fastcall json_checkValidJSON(const char *a1)
{
int v2; // eax
int v3; // er12
int v4; // edx
int v5; // ebx
const char *v6; // rdi
char v7; // al
__int64 result; // rax
unsigned int v9; // ebx
char v10; // dl

v2 = strlen(a1);
if ( *a1 != 123 )
return 0xFFFFFFFFLL;
if ( v2 <= 1 )
return 1LL;
v3 = v2;
v4 = 0;
v5 = 1;
while ( 1 )
{
v6 = &a1[v5];
v7 = *v6;
if ( *v6 == 34 )
{
result = json_checkValidPair(v6);
if ( (_DWORD)result == -1 )
return result;
LODWORD(result) = v5 + result;
if ( v3 <= (int)result )
return 0xFFFFFFFFLL;
result = (int)result;
while ( 1 )
{
v10 = a1[result];
v5 = result;
if ( v10 == 44 )
{
v5 = result + 1;
v4 = 1;
goto LABEL_12;
}
if ( v10 > 44 )
break;
if ( v10 > 10 )
{
if ( v10 != 32 )
return 0xFFFFFFFFLL;
}
else if ( v10 <= 8 )
{
return 0xFFFFFFFFLL;
}
if ( v3 <= (int)++result )
return 0xFFFFFFFFLL;
}
if ( v10 != 125 )
return 0xFFFFFFFFLL;
v4 = 2;
goto LABEL_12;
}
if ( v7 > 34 )
break;
if ( v7 > 10 )
{
if ( v7 != 32 )
return 0xFFFFFFFFLL;
}
else if ( v7 <= 8 )
{
return 0xFFFFFFFFLL;
}
++v5;
LABEL_12:
if ( v3 <= v5 )
return (unsigned int)v5;
}
if ( v7 != 125 )
return 0xFFFFFFFFLL;
v9 = v5 + 1;
result = 0xFFFFFFFFLL;
if ( v4 != 1 )
result = v9;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
int v2; // eax
int v3; // er12
int v4; // edx
int v5; // ebx
const char *v6; // rdi
char v7; // al
__int64 result; // rax
unsigned int v9; // ebx
char v10; // dl

v2 = strlen(a1);
if ( *a1 != 123 )
return 0xFFFFFFFFLL;
if ( v2 <= 1 )
return 1LL;
v3 = v2;
v4 = 0;
v5 = 1;
while ( 1 )
{
v6 = &a1[v5];
v7 = *v6;
if ( *v6 == 34 )
{
result = func6(v6);
if ( (_DWORD)result == -1 )
return result;
LODWORD(result) = v5 + result;
if ( v3 <= (int)result )
return 0xFFFFFFFFLL;
result = (int)result;
while ( 1 )
{
v10 = a1[result];
v5 = result;
if ( v10 == 44 )
{
v5 = result + 1;
v4 = 1;
goto LABEL_12;
}
if ( v10 > 44 )
break;
if ( v10 > 10 )
{
if ( v10 != 32 )
return 0xFFFFFFFFLL;
}
else if ( v10 <= 8 )
{
return 0xFFFFFFFFLL;
}
if ( v3 <= (int)++result )
return 0xFFFFFFFFLL;
}
if ( v10 != 125 )
return 0xFFFFFFFFLL;
v4 = 2;
goto LABEL_12;
}
if ( v7 > 34 )
break;
if ( v7 > 10 )
{
if ( v7 != 32 )
return 0xFFFFFFFFLL;
}
else if ( v7 <= 8 )
{
return 0xFFFFFFFFLL;
}
++v5;
LABEL_12:
if ( v3 <= v5 )
return (unsigned int)v5;
}
if ( v7 != 125 )
return 0xFFFFFFFFLL;
v9 = v5 + 1;
result = 0xFFFFFFFFLL;
if ( v4 != 1 )
result = v9;
return result;
}

original_code:
int json_checkValidJSON(char *JSON)
{
 int i, length, objlen, breakLoop, commaSuccess;
 char currentChar;
 objlen = strlen(JSON);
 i = 1;
 breakLoop = 0;
 commaSuccess = 0;
 if(*(JSON) != '{')
  return -1;
 while(i < objlen)
 {
  currentChar = *(JSON + i);
  switch(currentChar)
  {
   case ' ':
   case '\n':
   case '\t':
    i++;
    break;
   case '}':
    if(commaSuccess == 1)
     return -1;
    else
    {
     i++;
     breakLoop = 1;
     break;
    }
   case '\"':
    commaSuccess = 0;
    length = json_checkValidPair(JSON + i);
    if(length == -1)
    {
     breakLoop = 1;
     i = -1;
     break;
    }
    else
    {
     i += length;
     while(i < objlen)
     {
      currentChar = *(JSON + i);
      switch(currentChar)
      {
      case ',':
        i++;
        commaSuccess = 1;
        break;
      case '}':
        commaSuccess = 2;
        break;
      case ' ':
      case '\n':
      case '\t':
        i++;
        break;
       default:
        commaSuccess = -1;
        breakLoop = 1;
        i = -1;
        break;
      }
      if(commaSuccess != 0)
       break;
     }
     if(!(commaSuccess == 2 || commaSuccess == 1))
     {
      i = -1;
      breakLoop = 1;
     }
    }
    break;
   default:
    i = -1;
    breakLoop = 1;
    break;
  }
  if(breakLoop)
   break;
 }
 return i;
}

canonical_original_code:
int json_checkValidJSON(char *JSON)
{
 int i; int length; int objlen; int breakLoop; int commaSuccess;
 char currentChar;
 objlen = strlen(JSON);
 i = 1;
 breakLoop = 0;
 commaSuccess = 0;
 if(*(JSON) != '{')
  return -1;
 while(i < objlen)
 {
  currentChar = *(JSON + i);
  switch(currentChar)
  {
   case ' ':
   case '\n':
   case '\t':
    i++;
    break;
   case '}':
    if(commaSuccess == 1)
     return -1;
    else
    {
     i++;
     breakLoop = 1;
     break;
    }
   case '\"':
    commaSuccess = 0;
    length = json_checkValidPair(JSON + i);
    if(length == -1)
    {
     breakLoop = 1;
     i = -1;
     break;
    }
    else
    {
     i += length;
     while(i < objlen)
     {
      currentChar = *(JSON + i);
      switch(currentChar)
      {
      case ',':
        i++;
        commaSuccess = 1;
        break;
      case '}':
        commaSuccess = 2;
        break;
      case ' ':
      case '\n':
      case '\t':
        i++;
        break;
       default:
        commaSuccess = -1;
        breakLoop = 1;
        i = -1;
        break;
      }
      if(commaSuccess != 0)
       break;
     }
     if(!(commaSuccess == 2 || commaSuccess == 1))
     {
      i = -1;
      breakLoop = 1;
     }
    }
    break;
   default:
    i = -1;
    breakLoop = 1;
    break;
  }
  if(breakLoop)
   break;
 }
 return i;
}

variable_types:
JSON
char *

variable_types: i int

variable_types: length int

variable_types: objlen int

variable_types: breakLoop int

variable_types: commaSuccess int

variable_types: currentChar char

return_type: int


decompiled_code:
__int64 __fastcall json_checkValidArray(const char *a1)
{
int v3; // er13
int v4; // edx
int v5; // ebp
int v6; // er12
const char *v7; // rdi
char v8; // al

if ( *a1 != 91 )
return 0xFFFFFFFFLL;
v3 = strlen(a1);
if ( v3 <= 1 )
return 0xFFFFFFFFLL;
v4 = 0;
v5 = 0;
v6 = 1;
while ( 1 )
{
v7 = &a1[v6];
v8 = *v7;
if ( *v7 == 44 )
{
if ( v4 != 1 )
return 0xFFFFFFFFLL;
++v6;
v4 = 2;
goto LABEL_12;
}
if ( v8 <= 44 )
{
if ( v8 > 10 )
{
if ( v8 == 32 )
{
LABEL_19:
++v6;
goto LABEL_12;
}
}
else if ( v8 > 8 )
{
goto LABEL_19;
}
goto LABEL_9;
}
if ( v8 == 93 )
break;
LABEL_9:
if ( v4 == 1 )
return 0xFFFFFFFFLL;
v5 += json_checkValidValue(v7);
if ( v5 == -1 )
return 0xFFFFFFFFLL;
v6 += v5;
v4 = 1;
LABEL_12:
if ( v3 <= v6 )
return 0xFFFFFFFFLL;
}
if ( v4 != 1 )
v6 = -1;
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
int v3; // er13
int v4; // edx
int v5; // ebp
int v6; // er12
const char *v7; // rdi
char v8; // al

if ( *a1 != 91 )
return 0xFFFFFFFFLL;
v3 = strlen(a1);
if ( v3 <= 1 )
return 0xFFFFFFFFLL;
v4 = 0;
v5 = 0;
v6 = 1;
while ( 1 )
{
v7 = &a1[v6];
v8 = *v7;
if ( *v7 == 44 )
{
if ( v4 != 1 )
return 0xFFFFFFFFLL;
++v6;
v4 = 2;
goto LABEL_12;
}
if ( v8 <= 44 )
{
if ( v8 > 10 )
{
if ( v8 == 32 )
{
LABEL_19:
++v6;
goto LABEL_12;
}
}
else if ( v8 > 8 )
{
goto LABEL_19;
}
goto LABEL_9;
}
if ( v8 == 93 )
break;
LABEL_9:
if ( v4 == 1 )
return 0xFFFFFFFFLL;
v5 += func5(v7);
if ( v5 == -1 )
return 0xFFFFFFFFLL;
v6 += v5;
v4 = 1;
LABEL_12:
if ( v3 <= v6 )
return 0xFFFFFFFFLL;
}
if ( v4 != 1 )
v6 = -1;
return (unsigned int)v6;
}

original_code:
int json_checkValidArray(char *JSONArray)
{
 int i, length, objlen, needsComma;
 char currentChar;
 i = 1;
 needsComma = 0;
 objlen = strlen(JSONArray);
 length = 0;
 if(*(JSONArray) != '[')
  return -1;
 while(i < objlen)
 {
  currentChar = *(JSONArray + i);
  switch(currentChar)
  {
   case ' ':
   case '\n':
   case '\t':
    i++;
    break;
   case ',':
    if(needsComma == 1)
    {
     needsComma = 2;
     i++;
     break;
    }
    else
    {
     return -1;
    }
   case ']':
    if(needsComma == 1)
     return i++;
    else
     return -1;
   default:
    if(needsComma == 1)
     return -1;
    length += json_checkValidValue(JSONArray + i);
    if(length == -1)
     return length;
    else
     i += length;
     needsComma = 1;
  }
 }
 return -1;
}

canonical_original_code:
int json_checkValidArray(char *JSONArray)
{
 int i; int length; int objlen; int needsComma;
 char currentChar;
 i = 1;
 needsComma = 0;
 objlen = strlen(JSONArray);
 length = 0;
 if(*(JSONArray) != '[')
  return -1;
 while(i < objlen)
 {
  currentChar = *(JSONArray + i);
  switch(currentChar)
  {
   case ' ':
   case '\n':
   case '\t':
    i++;
    break;
   case ',':
    if(needsComma == 1)
    {
     needsComma = 2;
     i++;
     break;
    }
    else
    {
     return -1;
    }
   case ']':
    if(needsComma == 1)
     return i++;
    else
     return -1;
   default:
    if(needsComma == 1)
     return -1;
    length += json_checkValidValue(JSONArray + i);
    if(length == -1)
     return length;
    else
     i += length;
     needsComma = 1;
  }
 }
 return -1;
}

variable_types:
JSONArray
char *

variable_types: needsComma int


decompiled_code:
__int64 __fastcall parse_number(__int64 a1, int a2, _DWORD *a3)
{
int v5; // ecx
int v6; // edx
char *v7; // rdi
int v8; // er10
char v9; // al
char *v10; // rsi
int v11; // er9
int v12; // eax

if ( a2 == -1 )
return 0xFFFFFFFFLL;
*a3 = 0;
v5 = 0;
v6 = 0;
v7 = (char *)(a2 + a1);
v8 = ~(_DWORD)v7;
do
{
v9 = *v7;
v10 = v7;
v11 = v8 + (_DWORD)v7++;
v12 = (v9 & 0x7F) << v5;
v5 += 7;
v6 += v12;
*a3 = v6;
}
while ( *v10 < 0 );
return (unsigned int)(v11 + a2 + 2);
}

original_code:
extern int parse_number(uint8_t *buffer, int offset, int *value)
{
    if (offset == -1) {
        return -1;
    }
    int count = -1;
    *value=0;
    do {
        count++;
        (*value) += (1 << (7*count)) * (buffer[offset+count] & 0x7F);
    } while(buffer[offset+count] & 0x80);
    return count+1+offset;
}

canonical_original_code:
extern int parse_number(unsigned char *buffer, int offset, int *value)
{
    if (offset == -1) {
        return -1;
    }
    int count = -1;
    *value=0;
    do {
        count++;
        (*value) += (1 << (7*count)) * (buffer[offset+count] & 0x7F);
    } while(buffer[offset+count] & 0x80);
    return count+1+offset;
}

variable_types:
buffer
unsigned char *

variable_types: offset int

variable_types:
value
int *

variable_types: count int


parse

decompiled_code:
__int64 __fastcall parse(__int64 a1, int a2, int *a3, int *a4)
{
__int64 result; // rax
int v7; // edx
int v8[5]; // [rsp+Ch] [rbp-14h] BYREF

result = parse_number(a1, a2, v8);
if ( (_DWORD)result != -1 )
{
v7 = v8[0] >> 3;
*a4 = v8[0] & 7;
*a3 = v7;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int *a3, int *a4)
{
__int64 result; // rax
int v7; // edx
int v8[5]; // [rsp+Ch] [rbp-14h] BYREF

result = func0(a1, a2, v8);
if ( (_DWORD)result != -1 )
{
v7 = v8[0] >> 3;
*a4 = v8[0] & 7;
*a3 = v7;
}
return result;
}

original_code:
extern int parse(uint8_t *buffer, int offset, int* pId, int* pType)
{
    int in;
    offset = parse_number(buffer, offset, &in);
    if (offset == -1) {
        return -1;
    }
    *pType = (in & 0x7);
    *pId = in>>3;
    return offset;
}

canonical_original_code:
extern int parse(unsigned char *buffer, int offset, int *pId, int *pType)
{
    int in;
    offset = parse_number(buffer, offset, &in);
    if (offset == -1) {
        return -1;
    }
    *pType = (in & 0x7);
    *pId = in>>3;
    return offset;
}

variable_types:
pId
int *

variable_types:
pType
int *

variable_types: in int


decompiled_code:
__int64 __fastcall serialize_number(__int64 a1, int a2, int a3)
{
_BYTE *v3; // rdi
int v4; // esi
char v5; // al
_BYTE *v6; // r9
unsigned int v7; // er8
char v8; // al

if ( a2 == -1 )
return (unsigned int)-1;
v3 = (_BYTE *)(a2 + a1);
v4 = a2 + 1 - (_DWORD)v3;
do
{
v5 = a3;
a3 >>= 7;
v6 = v3;
v7 = v4 + (_DWORD)v3;
v8 = v5 & 0x7F;
*v3++ = v8 | 0x80;
}
while ( a3 > 0 );
*v6 = v8;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, int a3)
{
_BYTE *v3; // rdi
int v4; // esi
char v5; // al
_BYTE *v6; // r9
unsigned int v7; // er8
char v8; // al

if ( a2 == -1 )
return (unsigned int)-1;
v3 = (_BYTE *)(a2 + a1);
v4 = a2 + 1 - (_DWORD)v3;
do
{
v5 = a3;
a3 >>= 7;
v6 = v3;
v7 = v4 + (_DWORD)v3;
v8 = v5 & 0x7F;
*v3++ = v8 | 0x80;
}
while ( a3 > 0 );
*v6 = v8;
return v7;
}

original_code:
extern int serialize_number(uint8_t *buffer, int offset, int value)
{
    if (offset == -1) {
        return -1;
    }
    do {
        buffer[offset] = value & 0x7F;
        value = value>>7;
        buffer[offset] |= 0x80;
        offset++;
    } while (value > 0);
    buffer[offset - 1] = buffer[offset - 1] & 0x7F;
    return offset;
}

canonical_original_code:
extern int serialize_number(unsigned char *buffer, int offset, int value)
{
    if (offset == -1) {
        return -1;
    }
    do {
        buffer[offset] = value & 0x7F;
        value = value>>7;
        buffer[offset] |= 0x80;
        offset++;
    } while (value > 0);
    buffer[offset - 1] = buffer[offset - 1] & 0x7F;
    return offset;
}

variable_types: value int


serialize

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

if ( a2 == -1 )
result = 0xFFFFFFFFLL;
else
result = serialize_number(a1, a2, a4 & 7 | (unsigned int)(8 * a3));
return result;
}

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

if ( a2 == -1 )
result = 0xFFFFFFFFLL;
else
result = func2(a1, a2, a4 & 7 | (unsigned int)(8 * a3));
return result;
}

original_code:
extern int serialize(uint8_t *buffer, int offset, int id, int type)
{
    int out;
    if (offset == -1) {
        return -1;
    }
    out = type & 0x7;
    out = out | (id << 3);
    offset = serialize_number(buffer, offset, out);
    return offset;
}

canonical_original_code:
extern int serialize(unsigned char *buffer, int offset, int id, int type)
{
    int out;
    if (offset == -1) {
        return -1;
    }
    out = type & 0x7;
    out = out | (id << 3);
    offset = serialize_number(buffer, offset, out);
    return offset;
}

variable_types: id int

variable_types: type int

variable_types: out int


decompiled_code:
__int64 __fastcall hwal_fopen(const char *a1, const char *a2)
{
unsigned int v2; // er12
__int64 result; // rax
FILE *v4; // rax

v2 = fdNextFreecount;
if ( fdNextFreecount <= 10 && (++fdNextFreecount, v4 = fopen(a1, a2), (fd_mappingtable[v2 - 1] = (__int64)v4) != 0) )
result = v2;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
unsigned int v2; // er12
__int64 result; // rax
FILE *v4; // rax

v2 = fdNextFreecount;
if ( fdNextFreecount <= 10 && (++fdNextFreecount, v4 = fopen(a1, a2), (fd_mappingtable[v2 - 1] = (__int64)v4) != 0) )
result = v2;
else
result = 0LL;
return result;
}

original_code:
extern int hwal_fopen(char *filename, char* type)
{
 int usedMapIndex = fdNextFreecount;
 if (usedMapIndex > 10)
 {
  return 0;
 }
 fdNextFreecount++;
 fd_mappingtable[usedMapIndex - 1] = fopen(filename, type);
 if ( fd_mappingtable[usedMapIndex -1] == ((void *)0))
 {
  return 0;
 }
 return usedMapIndex;
}

canonical_original_code:
extern int hwal_fopen(char *filename, char *type)
{
 int usedMapIndex = fdNextFreecount;
 if (usedMapIndex > 10)
 {
  return 0;
 }
 fdNextFreecount++;
 fd_mappingtable[usedMapIndex - 1] = fopen(filename, type);
 if ( fd_mappingtable[usedMapIndex -1] == ((void *)0))
 {
  return 0;
 }
 return usedMapIndex;
}

variable_types:
filename
char *

variable_types:
type
char *

variable_types: usedMapIndex int


decompiled_code:
size_t __fastcall hwal_fread(void *a1, int a2, int a3)
{
return fread(a1, 1uLL, a2, (FILE *)fd_mappingtable[a3 - 1]);
}

canonical_decompiled_code:
size_t __fastcall func3(void *a1, int a2, int a3)
{
return fread(a1, 1uLL, a2, (FILE *)fd_mappingtable[a3 - 1]);
}

original_code:
extern int hwal_fread(void* buffer, int length, int filedescriptor)
{
 return fread(buffer, 1, length, fd_mappingtable[filedescriptor -1]);
}

canonical_original_code:
extern int hwal_fread(void *buffer, int length, int filedescriptor)
{
 return fread(buffer, 1, length, fd_mappingtable[filedescriptor -1]);
}

variable_types:
buffer
void *

variable_types: length int

variable_types: filedescriptor int


decompiled_code:
int __fastcall hwal_fclose(int a1)
{
return fclose((FILE *)fd_mappingtable[a1 - 1]);
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
return fclose((FILE *)fd_mappingtable[a1 - 1]);
}

original_code:
extern void hwal_fclose(int filedescriptor)
{
 fclose(fd_mappingtable[filedescriptor -1]);
}

return_type: void


decompiled_code:
void *__fastcall hwal_memset(void *a1, int a2, int a3)
{
return memset(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func5(void *a1, int a2, int a3)
{
return memset(a1, a2, a3);
}

original_code:
extern void hwal_memset(void *buffer, int item, int length)
{
 memset(buffer, item, length);
}

variable_types: item int


decompiled_code:
void *__fastcall hwal_memcpy(void *a1, const void *a2, int a3)
{
return memcpy(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func6(void *a1, const void *a2, int a3)
{
return memcpy(a1, a2, a3);
}

original_code:
extern void hwal_memcpy(void *s1, void* s2, int length)
{
 memcpy(s1, s2, length);
}

canonical_original_code:
extern void hwal_memcpy(void *s1, void *s2, int length)
{
 memcpy(s1, s2, length);
}


decompiled_code:
size_t __fastcall hwal_strlen(const char *a1)
{
return strlen(a1);
}

canonical_decompiled_code:
size_t __fastcall func7(const char *a1)
{
return strlen(a1);
}

original_code:
extern int hwal_strlen(char* text)
{
 return strlen(text);
}

canonical_original_code:
extern int hwal_strlen(char *text)
{
 return strlen(text);
}

variable_types:
text
char *


decompiled_code:
void *__fastcall hwal_malloc(int a1)
{
return malloc(a1);
}

canonical_decompiled_code:
void *__fastcall func8(int a1)
{
return malloc(a1);
}

original_code:
extern void* hwal_malloc(int size)
{
 return malloc(size);
}

canonical_original_code:
extern void *hwal_malloc(int size)
{
 return malloc(size);
}

variable_types: size int

return_type: void *


decompiled_code:
// attributes: thunk
void hwal_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func9(void *ptr)
{
free(ptr);
}

original_code:
extern void hwal_free(void* memory)
{
 return free(memory);
}

canonical_original_code:
extern void hwal_free(void *memory)
{
 return free(memory);
}

variable_types:
memory
void *


decompiled_code:
int hwal_debug(const char *a1, unsigned int a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a3);
printf("%s:%d ", a1, a2);
vprintf(a3, arg);
return putchar(10);
}

canonical_decompiled_code:
int func10(const char *a1, unsigned int a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a3);
printf("%s:%d ", a1, a2);
vprintf(a3, arg);
return putchar(10);
}

original_code:
extern void hwal_debug(char* codefile, int linenumber, char* text, ...)
{
 va_list ap;
 printf("%s:%d ", codefile, linenumber);
 __builtin_va_start(ap,text);
 vprintf(text, ap);
 __builtin_va_end(ap);
 printf("\n");
}

canonical_original_code:
extern void hwal_debug(char *codefile, int linenumber, char *text, ...)
{
 __builtin_va_list ap;
 printf("%s:%d ", codefile, linenumber);
 __builtin_va_start(ap,text);
 vprintf(text, ap);
 __builtin_va_end(ap);
 printf("\n");
}

variable_types:
codefile
char *

variable_types: linenumber int


decompiled_code:
__int64 __fastcall hwal_socket_tcp_new(unsigned __int16 a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
socklen_t v4; // edx
unsigned int v5; // eax
struct sockaddr v7[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
*(_QWORD *)&v7[0].sa_data[6] = 0LL;
v7[0].sa_family = 2;
*(_QWORD *)&v7[0].sa_data[2] = (unsigned int)_bswap_32_constprop_0(a1, v7, 16LL);
*(_WORD *)v7[0].sa_data = _bswap_16(a1);
if ( bind(v3, v7, v4) == -1 )
return (unsigned int)-2;
if ( listen(v3, a2) == -1 )
return (unsigned int)-3;
v5 = fcntl(v3, 3, 0LL);
if ( v5 == -1 )
return (unsigned int)-4;
BYTE1(v5) |= 8u;
fcntl(v3, 4, v5);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int16 a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
socklen_t v4; // edx
unsigned int v5; // eax
struct sockaddr v7[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
*(_QWORD *)&v7[0].sa_data[6] = 0LL;
v7[0].sa_family = 2;
*(_QWORD *)&v7[0].sa_data[2] = (unsigned int)func1(a1, v7, 16LL);
*(_WORD *)v7[0].sa_data = func0(a1);
if ( bind(v3, v7, v4) == -1 )
return (unsigned int)-2;
if ( listen(v3, a2) == -1 )
return (unsigned int)-3;
v5 = fcntl(v3, 3, 0LL);
if ( v5 == -1 )
return (unsigned int)-4;
BYTE1(v5) |= 8u;
fcntl(v3, 4, v5);
return v3;
}

original_code:
extern int hwal_socket_tcp_new(int port, int maximumClients)
{
 int sockfd = 0;
 struct sockaddr_in srcAddress;
 int flags;
    if((sockfd = socket(2, SOCK_STREAM, 0)) < 0)
    {
        ;;
        return -1;
    }
 memset((char *)&srcAddress, 0, sizeof(srcAddress));
    srcAddress.sin_family = 2;
    srcAddress.sin_addr.s_addr = htonl(0);
    srcAddress.sin_port = htons(port);
    if(-1 == bind(sockfd,(struct sockaddr *)&srcAddress, sizeof(srcAddress)))
    {
  ;;
  return -2;
    }
    if(-1 == listen(sockfd, maximumClients))
    {
  ;;
  return -3;
    }
 if (-1 == (flags = fcntl(sockfd, 3, 0)))
 {
  ;;
  return -4;
 }
 else
 {
  fcntl(sockfd, 4, flags | 04000);
 }
 return sockfd;
}

variable_types: port int

variable_types: maximumClients int

variable_types: sockfd int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: flags int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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


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

if ( a1 > 0 )
result = close(a1);
return result;
}

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

if ( a1 > 0 )
result = close(a1);
return result;
}

original_code:
extern void hwal_socket_tcp_close(int socketfd)
{
 if (socketfd > 0)
 {
  close(socketfd);
 }
}

variable_types: socketfd int


decompiled_code:
int __fastcall hwal_socket_tcp_accet(int a1)
{
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
return accept(a1, &addr, &addr_len);
}

canonical_decompiled_code:
int __fastcall func13(int a1)
{
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
return accept(a1, &addr, &addr_len);
}

original_code:
extern int hwal_socket_tcp_accet(int socketfd)
{
 struct sockaddr_in clientAddr;
 socklen_t sockLen = sizeof(clientAddr);
 int client;
 client = accept(socketfd, (struct sockaddr *) &clientAddr, &sockLen);
 if (client > 0)
 {
  ;;
 }
 return client;
}

canonical_original_code:
extern int hwal_socket_tcp_accet(int socketfd)
{
 struct sockaddr_in clientAddr;
 unsigned int sockLen = sizeof(clientAddr);
 int client;
 client = accept(socketfd, (struct sockaddr *) &clientAddr, &sockLen);
 if (client > 0)
 {
  ;;
 }
 return client;
}

variable_types:
sockLen
unsigned int

variable_types: client int


decompiled_code:
ssize_t __fastcall hwal_socket_tcp_read(int a1, void *a2, unsigned int a3)
{
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
return recvfrom(a1, a2, a3, 0, &addr, &addr_len);
}

canonical_decompiled_code:
ssize_t __fastcall func14(int a1, void *a2, unsigned int a3)
{
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
return recvfrom(a1, a2, a3, 0, &addr, &addr_len);
}

original_code:
extern int hwal_socket_tcp_read(int clientSocket, uint8_t* workingMem, uint32_t size)
{
 struct sockaddr_in srcAddr;
 socklen_t sockLen = sizeof(srcAddr);
 return recvfrom(clientSocket,
     (void *) workingMem,
     size,
     0,
     (struct sockaddr *) &srcAddr,
     &sockLen);
}

canonical_original_code:
extern int hwal_socket_tcp_read(int clientSocket, unsigned char *workingMem, unsigned int size)
{
 struct sockaddr_in srcAddr;
 unsigned int sockLen = sizeof(srcAddr);
 return recvfrom(clientSocket,
     (void *) workingMem,
     size,
     0,
     (struct sockaddr *) &srcAddr,
     &sockLen);
}

variable_types: clientSocket int

variable_types:
workingMem
unsigned char *

variable_types:
size
unsigned int


decompiled_code:
ssize_t __fastcall hwal_socket_tcp_write(int a1, const void *a2, unsigned int a3)
{
return write(a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func15(int a1, const void *a2, unsigned int a3)
{
return write(a1, a2, a3);
}

original_code:
extern int hwal_socket_tcp_write(int clientSocket, uint8_t* data, uint32_t size)
{
 return write(clientSocket, data, size);
}

canonical_original_code:
extern int hwal_socket_tcp_write(int clientSocket, unsigned char *data, unsigned int size)
{
 return write(clientSocket, data, size);
}

variable_types:
data
unsigned char *


decompiled_code:
void *fcclient_new()
{
return calloc(0x18uLL, 1uLL);
}

canonical_decompiled_code:
void *func1()
{
return calloc(0x18uLL, 1uLL);
}

original_code:
extern fcclient_t* fcclient_new()
{
 fcclient_t* tmp = malloc(sizeof(fcclient_t));
 memset(tmp, 0, sizeof(fcclient_t));
 return tmp;
}

canonical_original_code:
extern struct FCCLIENT *fcclient_new()
{
 struct FCCLIENT *tmp = malloc(sizeof(fcclient_t));
 memset(tmp, 0, sizeof(fcclient_t));
 return tmp;
}

variable_types: struct FCCLIENT { int width; int height; int fps; int connected; int sockfd; int frame_offset; } *


decompiled_code:
__int64 __fastcall fcclient_open(__int64 a1, const char *a2)
{
int v2; // eax
void *v3; // rdx
__int64 v4; // rbx
__int64 result; // rax
__m128i v6; // [rsp+0h] [rbp-1028h] BYREF
char v7[2048]; // [rsp+10h] [rbp-1018h] BYREF
char buf[2072]; // [rsp+810h] [rbp-818h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = socket(2, 1, 0);
*(_DWORD *)(a1 + 16) = v2;
if ( v2 < 0 )
{
puts("\n Error : Could not create socket ");
result = 4294967294LL;
}
else
{
v6 = _mm_load_si128((const __m128i *)&LC1);
v6.m128i_i16[0] = 2;
v6.m128i_i16[1] = _bswap_16_constprop_0(2LL, a2, (char *)v6.m128i_i64 + 4);
if ( inet_pton(2, a2, v3) <= 0 )
{
result = 4294967293LL;
}
else if ( connect(*(_DWORD *)(a1 + 16), (const struct sockaddr *)&v6, 0x10u) < 0 )
{
result = 4294967292LL;
}
else
{
v4 = (unsigned int)send_inforequest(v7, 0LL);
add_header(v7, buf, v4);
write(*(_DWORD *)(a1 + 16), buf, (int)v4 + 10);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
int v2; // eax
void *v3; // rdx
__int64 v4; // rbx
__int64 result; // rax
__m128i v6; // [rsp+0h] [rbp-1028h] BYREF
char v7[2048]; // [rsp+10h] [rbp-1018h] BYREF
char buf[2072]; // [rsp+810h] [rbp-818h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = socket(2, 1, 0);
*(_DWORD *)(a1 + 16) = v2;
if ( v2 < 0 )
{
puts("\n Error : Could not create socket ");
result = 4294967294LL;
}
else
{
v6 = _mm_load_si128((const __m128i *)&LC1);
v6.m128i_i16[0] = 2;
v6.m128i_i16[1] = func0(2LL, a2, (char *)v6.m128i_i64 + 4);
if ( inet_pton(2, a2, v3) <= 0 )
{
result = 4294967293LL;
}
else if ( connect(*(_DWORD *)(a1 + 16), (const struct sockaddr *)&v6, 0x10u) < 0 )
{
result = 4294967292LL;
}
else
{
v4 = (unsigned int)send_inforequest(v7, 0LL);
add_header(v7, buf, v4);
write(*(_DWORD *)(a1 + 16), buf, (int)v4 + 10);
result = 1LL;
}
}
return result;
}

original_code:
extern int fcclient_open(fcclient_t* fc, char* host)
{
 struct sockaddr_in serv_addr;
 uint8_t buffer[2048];
    uint8_t output[2048];
    int offset = 0;
 if (fc == ((void *)0))
  return -1;
    if((fc->sockfd = socket(2, SOCK_STREAM, 0)) < 0)
    {
        printf("\n Error : Could not create socket \n");
        return -2;
    }
    memset(&serv_addr, '0', sizeof(serv_addr));
    serv_addr.sin_family = 2;
    serv_addr.sin_port = htons(24567);
    if(inet_pton(2, host, &serv_addr.sin_addr)<=0)
    {
        return -3;
    }
 if( connect(fc->sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    {
        return -4;
    }
    offset = send_inforequest(buffer, offset);
 add_header(buffer, output, offset);
 write(fc->sockfd, output, offset+10);
 return 1;
}

canonical_original_code:
extern int fcclient_open(struct FCCLIENT *fc, char *host)
{
 struct sockaddr_in serv_addr;
 unsigned char buffer[2048];
    unsigned char output[2048];
    int offset = 0;
 if (fc == ((void *)0))
  return -1;
    if((fc->sockfd = socket(2, SOCK_STREAM, 0)) < 0)
    {
        printf("\n Error : Could not create socket \n");
        return -2;
    }
    memset(&serv_addr, '0', sizeof(serv_addr));
    serv_addr.sin_family = 2;
    serv_addr.sin_port = htons(24567);
    if(inet_pton(2, host, &serv_addr.sin_addr)<=0)
    {
        return -3;
    }
 if( connect(fc->sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    {
        return -4;
    }
    offset = send_inforequest(buffer, offset);
 add_header(buffer, output, offset);
 write(fc->sockfd, output, offset+10);
 return 1;
}

variable_types:
host
char *

variable_types:
buffer
unsigned char [2048]

variable_types:
output
unsigned char [2048]

variable_types: offset int

user_defined_types: struct FCCLIENT { int width; int height; int fps; int connected; int sockfd; int frame_offset; }


decompiled_code:
__int64 __fastcall fcclient_processNetwork(unsigned int *a1)
{
int v2; // edi
unsigned int v3; // eax
__int64 result; // rax
unsigned int v5; // [rsp+0h] [rbp-428h] BYREF
int v6; // [rsp+4h] [rbp-424h] BYREF
unsigned int v7; // [rsp+8h] [rbp-420h] BYREF
char v8[4]; // [rsp+Ch] [rbp-41Ch] BYREF
void *v9; // [rsp+10h] [rbp-418h] BYREF
void *ptr; // [rsp+18h] [rbp-410h] BYREF
char buf[1032]; // [rsp+20h] [rbp-408h] BYREF

v2 = a1[4];
v5 = -1;
v6 = 0;
if ( (int)read(v2, buf, 0x3FFuLL) <= 9 )
return 0xFFFFFFFFLL;
v3 = get_header(buf, 0LL, &v5, &v6);
if ( v3 == -1 )
return 4294967294LL;
switch ( v5 )
{
case 2u:
recv_pong(buf, v3, &ptr);
printf("Pong Counter: %d\n", (unsigned int)ptr);
result = 1LL;
break;
case 3u:
if ( (unsigned int)recv_error(buf, v3, &v9, &ptr) == -1 )
goto LABEL_19;
printf("Error errorcode: %d, description: %s \n", (unsigned int)v9, (const char *)ptr);
if ( (_DWORD)v9 == 1 )
{
puts("Errorcode: OK");
}
else if ( (_DWORD)v9 == 2 )
{
puts("Errorcode: Decoding Error");
}
else
{
puts("Errorcode: Unbekannt");
}
free(ptr);
result = 1LL;
break;
case 5u:
a1[3] = 1;
result = 1LL;
break;
case 7u:
if ( (unsigned int)recv_ack(buf, v3) == -1 )
{
LABEL_19:
puts("recv_error Faild!");
result = 1LL;
}
else
{
puts("Received ACK");
result = 1LL;
}
break;
case 9u:
puts("!!! Timeout !!!");
result = 1LL;
break;
case 0xDu:
if ( (unsigned int)recv_infoanswer(buf, v3, &v7, v8) == -1 )
puts("recv_infoanswer Faild!");
else
puts("Parse InfoAnswer");
if ( (unsigned int)parse_metadata(buf, v7, a1 + 2, a1, a1 + 1, &v9, &ptr) == -1 )
{
puts("parse Metadata Faild!");
result = 4294967293LL;
}
else
{
printf(
"Walls definition, fps: %d, width: %d, height: %d, gen._name: %s, gen._version: %s\n",
a1[2],
*a1,
a1[1],
(const char *)v9,
(const char *)ptr);
free(v9);
free(ptr);
result = 1LL;
}
break;
default:
printf("Unknown type: %d\n", v5);
result = 4294967291LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1)
{
int v2; // edi
unsigned int v3; // eax
__int64 result; // rax
unsigned int v5; // [rsp+0h] [rbp-428h] BYREF
int v6; // [rsp+4h] [rbp-424h] BYREF
unsigned int v7; // [rsp+8h] [rbp-420h] BYREF
char v8[4]; // [rsp+Ch] [rbp-41Ch] BYREF
void *v9; // [rsp+10h] [rbp-418h] BYREF
void *ptr; // [rsp+18h] [rbp-410h] BYREF
char buf[1032]; // [rsp+20h] [rbp-408h] BYREF

v2 = a1[4];
v5 = -1;
v6 = 0;
if ( (int)read(v2, buf, 0x3FFuLL) <= 9 )
return 0xFFFFFFFFLL;
v3 = get_header(buf, 0LL, &v5, &v6);
if ( v3 == -1 )
return 4294967294LL;
switch ( v5 )
{
case 2u:
recv_pong(buf, v3, &ptr);
printf("Pong Counter: %d\n", (unsigned int)ptr);
result = 1LL;
break;
case 3u:
if ( (unsigned int)recv_error(buf, v3, &v9, &ptr) == -1 )
goto LABEL_19;
printf("Error errorcode: %d, description: %s \n", (unsigned int)v9, (const char *)ptr);
if ( (_DWORD)v9 == 1 )
{
puts("Errorcode: OK");
}
else if ( (_DWORD)v9 == 2 )
{
puts("Errorcode: Decoding Error");
}
else
{
puts("Errorcode: Unbekannt");
}
free(ptr);
result = 1LL;
break;
case 5u:
a1[3] = 1;
result = 1LL;
break;
case 7u:
if ( (unsigned int)recv_ack(buf, v3) == -1 )
{
LABEL_19:
puts("recv_error Faild!");
result = 1LL;
}
else
{
puts("Received ACK");
result = 1LL;
}
break;
case 9u:
puts("!!! Timeout !!!");
result = 1LL;
break;
case 0xDu:
if ( (unsigned int)recv_infoanswer(buf, v3, &v7, v8) == -1 )
puts("recv_infoanswer Faild!");
else
puts("Parse InfoAnswer");
if ( (unsigned int)parse_metadata(buf, v7, a1 + 2, a1, a1 + 1, &v9, &ptr) == -1 )
{
puts("parse Metadata Faild!");
result = 4294967293LL;
}
else
{
printf(
"Walls definition, fps: %d, width: %d, height: %d, gen._name: %s, gen._version: %s\n",
a1[2],
*a1,
a1[1],
(const char *)v9,
(const char *)ptr);
free(v9);
free(ptr);
result = 1LL;
}
break;
default:
printf("Unknown type: %d\n", v5);
result = 4294967291LL;
break;
}
return result;
}

original_code:
extern int fcclient_processNetwork(fcclient_t* fc)
{
 int n;
 int offset = 0;
 int type = -1;
 int length = 0;
 uint8_t recvBuff[1024];
 int counter;
    int meta_offset;
    int meta_length;
 char *generator_name;
    char *generator_version;
 int errorcode;
 char *descr;
 n = read(fc->sockfd, recvBuff, sizeof(recvBuff)-1);
 if (n < 10) {
  return -1;
 }
 offset = get_header((uint8_t*)recvBuff, 0, &type, &length);
 if (offset == -1) {
  return -2;
 }
 switch (type) {
        case 2:
            recv_pong((uint8_t*)recvBuff, offset, &counter);
            printf("Pong Counter: %d\n",counter);
            break;
  case 13:
   offset = recv_infoanswer(recvBuff, offset, &meta_offset, &meta_length);
            if (offset == -1) {
                printf("recv_infoanswer Faild!\n");
            } else {
                printf("Parse InfoAnswer\n");
            }
            offset = parse_metadata(recvBuff,meta_offset,&(fc->fps), &(fc->width), &(fc->height), &generator_name, &generator_version);
            if (offset == -1) {
                printf("parse Metadata Faild!\n");
                return -3;
            } else {
                printf("Walls definition, fps: %d, width: %d, height: %d, gen._name: %s, gen._version: %s\n",fc->fps,fc->width,fc->height,generator_name,generator_version);
            }
            free(generator_name);
            free(generator_version);
            break;
  case 7:
            offset = recv_ack(recvBuff, offset);
            if (offset == -1) {
                printf("recv_error Faild!\n");
            } else {
                printf("Received ACK\n");
            }
            break;
  case 5:
   fc->connected = 1;
   break;
  case 9:
    printf("!!! Timeout !!!\n");
    break;
  case 3:
            offset = recv_error(recvBuff, offset, &errorcode, &descr);
            if (offset == -1) {
                printf("recv_error Faild!\n");
            } else {
                printf("Error errorcode: %d, description: %s \n",errorcode,descr);
                switch (errorcode) {
                    case 1:
                        printf("Errorcode: OK\n");
                        break;
                    case 2:
                        printf("Errorcode: Decoding Error\n");
                        break;
                    default:
                        printf("Errorcode: Unbekannt\n");
                        break;
                }
    free(descr);
            }
            break;
        default:
            printf("Unknown type: %d\n",type);
            return -5;
    }
 return 1;
}

canonical_original_code:
extern int fcclient_processNetwork(struct FCCLIENT *fc)
{
 int n;
 int offset = 0;
 int type = -1;
 int length = 0;
 unsigned char recvBuff[1024];
 int counter;
    int meta_offset;
    int meta_length;
 char *generator_name;
    char *generator_version;
 int errorcode;
 char *descr;
 n = read(fc->sockfd, recvBuff, sizeof(recvBuff)-1);
 if (n < 10) {
  return -1;
 }
 offset = get_header((unsigned char *)recvBuff, 0, &type, &length);
 if (offset == -1) {
  return -2;
 }
 switch (type) {
        case 2:
            recv_pong((unsigned char *)recvBuff, offset, &counter);
            printf("Pong Counter: %d\n",counter);
            break;
  case 13:
   offset = recv_infoanswer(recvBuff, offset, &meta_offset, &meta_length);
            if (offset == -1) {
                printf("recv_infoanswer Faild!\n");
            } else {
                printf("Parse InfoAnswer\n");
            }
            offset = parse_metadata(recvBuff,meta_offset,&(fc->fps), &(fc->width), &(fc->height), &generator_name, &generator_version);
            if (offset == -1) {
                printf("parse Metadata Faild!\n");
                return -3;
            } else {
                printf("Walls definition, fps: %d, width: %d, height: %d, gen._name: %s, gen._version: %s\n",fc->fps,fc->width,fc->height,generator_name,generator_version);
            }
            free(generator_name);
            free(generator_version);
            break;
  case 7:
            offset = recv_ack(recvBuff, offset);
            if (offset == -1) {
                printf("recv_error Faild!\n");
            } else {
                printf("Received ACK\n");
            }
            break;
  case 5:
   fc->connected = 1;
   break;
  case 9:
    printf("!!! Timeout !!!\n");
    break;
  case 3:
            offset = recv_error(recvBuff, offset, &errorcode, &descr);
            if (offset == -1) {
                printf("recv_error Faild!\n");
            } else {
                printf("Error errorcode: %d, description: %s \n",errorcode,descr);
                switch (errorcode) {
                    case 1:
                        printf("Errorcode: OK\n");
                        break;
                    case 2:
                        printf("Errorcode: Decoding Error\n");
                        break;
                    default:
                        printf("Errorcode: Unbekannt\n");
                        break;
                }
    free(descr);
            }
            break;
        default:
            printf("Unknown type: %d\n",type);
            return -5;
    }
 return 1;
}

variable_types: n int

variable_types: type int

variable_types: length int

variable_types:
recvBuff
unsigned char [1024]

variable_types: counter int

variable_types: errorcode int

variable_types:
descr
char *


decompiled_code:
__int64 __fastcall fcclient_start(unsigned int *a1)
{
__int64 v1; // rcx
__int64 v2; // r8
__int64 v3; // rdx
unsigned int v4; // eax
unsigned int v5; // ebx
int v7; // [rsp+1h] [rbp-1427h] BYREF
char v8[9]; // [rsp+5h] [rbp-1423h] BYREF
char v9[1024]; // [rsp+10h] [rbp-1418h] BYREF
char v10[2048]; // [rsp+410h] [rbp-1018h] BYREF
char buf[2072]; // [rsp+C10h] [rbp-818h] BYREF

v1 = *a1;
v2 = a1[1];
v3 = a1[2];
if ( !((unsigned int)v3 | (unsigned int)v2 | *a1) )
return 0xFFFFFFFFLL;
strcpy(v8, "fc_c");
v7 = 3747376;
strcpy(&v8[5], "black");
v4 = create_metadata(v9, 0LL, v3, v1, v2, v8, &v7);
v5 = send_request(v10, 0LL, &v8[5], 1LL, v9, v4);
add_header(v10, buf, v5);
write(a1[4], buf, (int)(v5 + 10));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
__int64 v1; // rcx
__int64 v2; // r8
__int64 v3; // rdx
unsigned int v4; // eax
unsigned int v5; // ebx
int v7; // [rsp+1h] [rbp-1427h] BYREF
char v8[9]; // [rsp+5h] [rbp-1423h] BYREF
char v9[1024]; // [rsp+10h] [rbp-1418h] BYREF
char v10[2048]; // [rsp+410h] [rbp-1018h] BYREF
char buf[2072]; // [rsp+C10h] [rbp-818h] BYREF

v1 = *a1;
v2 = a1[1];
v3 = a1[2];
if ( !((unsigned int)v3 | (unsigned int)v2 | *a1) )
return 0xFFFFFFFFLL;
strcpy(v8, "fc_c");
v7 = 3747376;
strcpy(&v8[5], "black");
v4 = create_metadata(v9, 0LL, v3, v1, v2, v8, &v7);
v5 = send_request(v10, 0LL, &v8[5], 1LL, v9, v4);
add_header(v10, buf, v5);
write(a1[4], buf, (int)(v5 + 10));
return 1LL;
}

original_code:
extern int fcclient_start(fcclient_t* fc)
{
 if (fc->width == 0 && fc->height == 0 && fc->fps == 0)
  return -1;
 uint8_t buffer[2048];
    uint8_t output[2048];
 int offset = 0;
 uint8_t meta[1024];
    int offset_meta;
    char gen_name[] = "fc_c";
    char gen_version[] = "0.9";
    char color[] = "black";
    offset_meta = create_metadata(meta, 0, fc->fps, fc->width, fc->height, gen_name, gen_version);
    offset = send_request(buffer, offset, color, 1, meta, offset_meta);
 add_header(buffer, output, offset);
 write(fc->sockfd, output, offset+10);
 return 1;
}

canonical_original_code:
extern int fcclient_start(struct FCCLIENT *fc)
{
 if (fc->width == 0 && fc->height == 0 && fc->fps == 0)
  return -1;
 unsigned char buffer[2048];
    unsigned char output[2048];
 int offset = 0;
 unsigned char meta[1024];
    int offset_meta;
    char gen_name[] = "fc_c";
    char gen_version[] = "0.9";
    char color[] = "black";
    offset_meta = create_metadata(meta, 0, fc->fps, fc->width, fc->height, gen_name, gen_version);
    offset = send_request(buffer, offset, color, 1, meta, offset_meta);
 add_header(buffer, output, offset);
 write(fc->sockfd, output, offset+10);
 return 1;
}

variable_types:
meta
unsigned char [1024]

variable_types:
color
char []


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

result = 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 12) )
{
*(_DWORD *)(a1 + 20) = frame_add_pixel(a2, *(unsigned int *)(a1 + 20));
result = 1LL;
}
return result;
}

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

result = 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 12) )
{
*(_DWORD *)(a1 + 20) = frame_add_pixel(a2, *(unsigned int *)(a1 + 20));
result = 1LL;
}
return result;
}

original_code:
extern int fcclient_addPixel(fcclient_t* fc, uint8_t* frame, int red, int green, int blue, int x, int y)
{
 if (!fc->connected)
  return -1;
 fc->frame_offset = frame_add_pixel(frame, fc->frame_offset, red, green, blue, x, y);
 return 1;
}

canonical_original_code:
extern int fcclient_addPixel(struct FCCLIENT *fc, unsigned char *frame, int red, int green, int blue, int x, int y)
{
 if (!fc->connected)
  return -1;
 fc->frame_offset = frame_add_pixel(frame, fc->frame_offset, red, green, blue, x, y);
 return 1;
}

variable_types:
frame
unsigned char *

variable_types: red int

variable_types: green int

variable_types: blue int

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall fcclient_sendFrame(_DWORD *a1, __int64 a2)
{
signed __int64 v3; // rax
void *v4; // rsp
void *v5; // rsp
unsigned int v6; // er12
_BYTE v7[40]; // [rsp-28h] [rbp-28h] BYREF

if ( !a1[3] )
return 0xFFFFFFFFLL;
v3 = 16 * ((unsigned __int64)(20 * a1[1] * *a1 + 15LL) >> 4);
v4 = alloca(v3);
v5 = alloca(v3);
v6 = send_frame(v7, 0LL, a2, (int)a1[5]);
add_header(v7, v7, v6);
write(a1[4], v7, (int)(v6 + 10));
a1[5] = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1, __int64 a2)
{
signed __int64 v3; // rax
void *v4; // rsp
void *v5; // rsp
unsigned int v6; // er12
_BYTE v7[40]; // [rsp-28h] [rbp-28h] BYREF

if ( !a1[3] )
return 0xFFFFFFFFLL;
v3 = 16 * ((unsigned __int64)(20 * a1[1] * *a1 + 15LL) >> 4);
v4 = alloca(v3);
v5 = alloca(v3);
v6 = send_frame(v7, 0LL, a2, (int)a1[5]);
add_header(v7, v7, v6);
write(a1[4], v7, (int)(v6 + 10));
a1[5] = 0;
return 1LL;
}

original_code:
extern int fcclient_sendFrame(fcclient_t* fc, uint8_t* frame)
{
 if (!fc->connected)
  return -1;
 uint8_t buffer[fc->width * fc->height * 20];
 uint8_t output[fc->width * fc->height * 20];
    int offset = 0;
 offset = send_frame(buffer, offset, frame, fc->frame_offset);
 add_header(buffer, output, offset);
 write(fc->sockfd, output, offset+10);
 fc->frame_offset = 0;
 return 1;
}

canonical_original_code:
extern int fcclient_sendFrame(struct FCCLIENT *fc, unsigned char *frame)
{
 if (!fc->connected)
  return -1;
 unsigned char buffer[-1];
 unsigned char output[-1];
    int offset = 0;
 offset = send_frame(buffer, offset, frame, fc->frame_offset);
 add_header(buffer, output, offset);
 write(fc->sockfd, output, offset+10);
 fc->frame_offset = 0;
 return 1;
}

variable_types: struct FCCLIENT { int width; int height; int fps; int connected; int sockfd; int frame_offset; } *

variable_types:
buffer
unsigned char [-1]

variable_types:
output
unsigned char [-1]


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

if ( a1 )
{
if ( *(_DWORD *)(a1 + 32) == 1 )
result = hwal_fclose(*(unsigned int *)(a1 + 16));
}
return result;
}

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

if ( a1 )
{
if ( *(_DWORD *)(a1 + 32) == 1 )
result = hwal_fclose(*(unsigned int *)(a1 + 16));
}
return result;
}

original_code:
void fcseq_close(fcsequence_t* seq)
{
 if (seq == 0)
 {
  return;
 }
 if (seq->type == FCSEQ_FILEDESCRIPTOR)
 {
  hwal_fclose(seq->intern.file.filedescriptor);
 }
}

canonical_original_code:
void fcseq_close(struct FCSEQ *seq)
{
 if (seq == 0)
 {
  return;
 }
 if (seq->type == FCSEQ_FILEDESCRIPTOR)
 {
  hwal_fclose(seq->intern.file.filedescriptor);
 }
}

variable_types: struct FCSEQ { int width; int height; int fps; union { struct FCSEQ_MEM { unsigned char *pBuffer; unsigned int bufferLength; unsigned int actOffset; } mem; struct FCSEQ_FILE { int filedescriptor; } file; } intern; enum FCSEQ_TYPE { FCSEQ_NONE=0, FCSEQ_FILEDESCRIPTOR=1, FCSEQ_MEMORY=2 } type; } *

user_defined_types: struct FCSEQ { int width; int height; int fps; union { struct FCSEQ_MEM mem; struct FCSEQ_FILE file; } intern; enum FCSEQ_TYPE type; }


original_code:
fcseq_ret_t fcseq_loadMemory(fcsequence_t* seqio, uint8_t *memory, uint32_t length)
{
 int offset = 0;
 int id, type, size;
 if (seqio == 0)
 {
  return FCSEQ_RET_PARAMERR;
 }
 if (seqio->type != FCSEQ_FILEDESCRIPTOR)
 {
  seqio->type = FCSEQ_MEMORY;
  seqio->intern.mem.bufferLength = length;
  seqio->intern.mem.pBuffer = memory;
  seqio->intern.mem.actOffset = 0;
 }
    offset = parse(memory, offset, &id, &type);
    if (id != 1 || type != 2)
        return FCSEQ_RET_INVALID_DATA;
    offset = parse_number(memory, offset, &size);
    if (seqio->type == FCSEQ_FILEDESCRIPTOR)
    {
 int restOfFirst = (length - offset);
 uint8_t metabuffer[size];
 hwal_memcpy(metabuffer, memory + offset, restOfFirst);
 int readBytes = hwal_fread(metabuffer+restOfFirst, size - restOfFirst, seqio->intern.file.filedescriptor);
 if ( readBytes != (size-restOfFirst) )
 {
  return FCSEQ_RET_IOERR;
 }
     (void) parse_metadata(metabuffer, 0, &(seqio->fps), &(seqio->width), &(seqio->height), 0, 0);
    }
    else
    {
     offset = parse_metadata(memory, offset,&(seqio->fps), &(seqio->width), &(seqio->height), 0, 0);
 if (offset == -1)
 {
    return FCSEQ_RET_INVALID_DATA;
 }
 seqio->intern.mem.actOffset = offset;
    }
 return FCSEQ_RET_OK;
}

canonical_original_code:
enum FCSEQ_RET fcseq_loadMemory(struct FCSEQ *seqio, unsigned char *memory, unsigned int length)
{
 int offset = 0;
 int id; int type; int size;
 if (seqio == 0)
 {
  return FCSEQ_RET_PARAMERR;
 }
 if (seqio->type != FCSEQ_FILEDESCRIPTOR)
 {
  seqio->type = FCSEQ_MEMORY;
  seqio->intern.mem.bufferLength = length;
  seqio->intern.mem.pBuffer = memory;
  seqio->intern.mem.actOffset = 0;
 }
    offset = parse(memory, offset, &id, &type);
    if (id != 1 || type != 2)
        return FCSEQ_RET_INVALID_DATA;
    offset = parse_number(memory, offset, &size);
    if (seqio->type == FCSEQ_FILEDESCRIPTOR)
    {
 int restOfFirst = (length - offset);
 unsigned char metabuffer[-1];
 hwal_memcpy(metabuffer, memory + offset, restOfFirst);
 int readBytes = hwal_fread(metabuffer+restOfFirst, size - restOfFirst, seqio->intern.file.filedescriptor);
 if ( readBytes != (size-restOfFirst) )
 {
  return FCSEQ_RET_IOERR;
 }
     (void) parse_metadata(metabuffer, 0, &(seqio->fps), &(seqio->width), &(seqio->height), 0, 0);
    }
    else
    {
     offset = parse_metadata(memory, offset,&(seqio->fps), &(seqio->width), &(seqio->height), 0, 0);
 if (offset == -1)
 {
    return FCSEQ_RET_INVALID_DATA;
 }
 seqio->intern.mem.actOffset = offset;
    }
 return FCSEQ_RET_OK;
}

variable_types:
memory
unsigned char *

variable_types:
length
unsigned int

variable_types: offset int

variable_types: id int

variable_types: type int

variable_types: size int

variable_types: restOfFirst int

variable_types:
metabuffer
unsigned char [-1]

variable_types: readBytes int

return_type: enum FCSEQ_RET { FCSEQ_RET_OK=1, FCSEQ_RET_IOERR=2, FCSEQ_RET_EOF=3, FCSEQ_RET_PARAMERR=4, FCSEQ_RET_NOTIMPL=5, FCSEQ_RET_INVALID_DATA=6, FCSEQ_RET_OUTOFMEMORY=7 }

user_defined_types: enum FCSEQ_TYPE { FCSEQ_NONE=0, FCSEQ_FILEDESCRIPTOR=1, FCSEQ_MEMORY=2 }

user_defined_types: struct FCSEQ_MEM { unsigned char *pBuffer; unsigned int bufferLength; unsigned int actOffset; }

user_defined_types: struct FCSEQ_FILE { int filedescriptor; }


decompiled_code:
__int64 __fastcall fcseq_load(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rdx
__int64 result; // rax
int v5; // er8
char v6[30]; // [rsp+0h] [rbp-1Eh] BYREF

if ( !a2 )
return 4LL;
hwal_memset(a2, 0LL, 40LL);
*(_DWORD *)(a2 + 32) = 1;
v2 = hwal_fopen(a1, &unk_490);
v3 = v2;
*(_DWORD *)(a2 + 16) = v2;
result = 2LL;
if ( (_DWORD)v3 )
{
v5 = hwal_fread(v6, 6LL, v3);
result = 6LL;
if ( v5 == 6 )
result = fcseq_loadMemory(a2, (__int64)v6, 6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rdx
__int64 result; // rax
int v5; // er8
char v6[30]; // [rsp+0h] [rbp-1Eh] BYREF

if ( !a2 )
return 4LL;
hwal_memset(a2, 0LL, 40LL);
*(_DWORD *)(a2 + 32) = 1;
v2 = hwal_fopen(a1, &unk_490);
v3 = v2;
*(_DWORD *)(a2 + 16) = v2;
result = 2LL;
if ( (_DWORD)v3 )
{
v5 = hwal_fread(v6, 6LL, v3);
result = 6LL;
if ( v5 == 6 )
result = func1(a2, (__int64)v6, 6);
}
return result;
}

original_code:
fcseq_ret_t fcseq_load(char *filename, fcsequence_t* seq)
{
 if (seq == 0)
 {
  return FCSEQ_RET_PARAMERR;
 }
 hwal_memset(seq, 0, sizeof(fcsequence_t));
 seq->type = FCSEQ_FILEDESCRIPTOR;
 seq->intern.file.filedescriptor = hwal_fopen(filename, "r");
 if ( seq->intern.file.filedescriptor == 0 )
 {
  return FCSEQ_RET_IOERR;
 }
 ;;
 uint8_t mem[6];
 int read = hwal_fread(mem, 6, seq->intern.file.filedescriptor);
 ;;
 if (read != 6)
 {
  return FCSEQ_RET_INVALID_DATA;
 }
 return fcseq_loadMemory(seq, mem, 6);
}

canonical_original_code:
enum FCSEQ_RET fcseq_load(char *filename, struct FCSEQ *seq)
{
 if (seq == 0)
 {
  return FCSEQ_RET_PARAMERR;
 }
 hwal_memset(seq, 0, sizeof(fcsequence_t));
 seq->type = FCSEQ_FILEDESCRIPTOR;
 seq->intern.file.filedescriptor = hwal_fopen(filename, "r");
 if ( seq->intern.file.filedescriptor == 0 )
 {
  return FCSEQ_RET_IOERR;
 }
 ;;
 unsigned char mem[6];
 int read = hwal_fread(mem, 6, seq->intern.file.filedescriptor);
 ;;
 if (read != 6)
 {
  return FCSEQ_RET_INVALID_DATA;
 }
 return fcseq_loadMemory(seq, mem, 6);
}

variable_types:
filename
char *

variable_types:
mem
unsigned char [6]

variable_types: read int

user_defined_types: enum FCSEQ_RET { FCSEQ_RET_OK=1, FCSEQ_RET_IOERR=2, FCSEQ_RET_EOF=3, FCSEQ_RET_PARAMERR=4, FCSEQ_RET_NOTIMPL=5, FCSEQ_RET_INVALID_DATA=6, FCSEQ_RET_OUTOFMEMORY=7 }


extractFrame

decompiled_code:
__int64 __fastcall extractFrame(__int64 a1, __int64 a2, int a3, unsigned int a4, int a5)
{
int v7; // ebx
__int64 v8; // rsi
__int64 v9; // rax
int v11; // [rsp+Ch] [rbp-3Ch] BYREF
int v12; // [rsp+10h] [rbp-38h] BYREF
int v13; // [rsp+14h] [rbp-34h] BYREF
int v14; // [rsp+18h] [rbp-30h] BYREF
int v15[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

if ( a2 == 0 || a1 == 0 || !a5 )
return 4LL;
v7 = a4 + a5;
v8 = a4;
do
{
LODWORD(v8) = frame_parse_pixel(a1, v8, &v11, &v12, &v13, &v14, v15);
if ( (_DWORD)v8 == -1 )
return 6LL;
v9 = 3 * (v14 + a3 * v15[0]);
*(_BYTE *)(a2 + v9) = v11;
*(_BYTE *)(a2 + v9 + 1) = v12;
*(_BYTE *)(a2 + v9 + 2) = v13;
}
while ( v7 > (int)v8 );
return 1LL;
}

original_code:
fcseq_ret_t extractFrame(uint8_t* memory, uint8_t* rgb24, int width, int offset, int length)
{
 int lastOffset = offset + length;
 int red, green, blue;
 int x,y, pos;
 if (memory == 0 || rgb24 == 0 || length == 0)
 {
  ;;
  return FCSEQ_RET_PARAMERR;
 }
 do {
  offset = frame_parse_pixel(memory, offset, &red, &green, &blue, &x, &y);
  if (offset == -1) {
   return FCSEQ_RET_INVALID_DATA;
  } else {
   pos = y*(width*3) + (3*x);
   rgb24[pos + 0] = red;
   rgb24[pos + 1] = green;
   rgb24[pos + 2] = blue;
  }
 } while (offset < lastOffset);
 return FCSEQ_RET_OK;
}

canonical_original_code:
enum FCSEQ_RET extractFrame(unsigned char *memory, unsigned char *rgb24, int width, int offset, int length)
{
 int lastOffset = offset + length;
 int red; int green; int blue;
 int x; int y; int pos;
 if (memory == 0 || rgb24 == 0 || length == 0)
 {
  ;;
  return FCSEQ_RET_PARAMERR;
 }
 do {
  offset = frame_parse_pixel(memory, offset, &red, &green, &blue, &x, &y);
  if (offset == -1) {
   return FCSEQ_RET_INVALID_DATA;
  } else {
   pos = y*(width*3) + (3*x);
   rgb24[pos + 0] = red;
   rgb24[pos + 1] = green;
   rgb24[pos + 2] = blue;
  }
 } while (offset < lastOffset);
 return FCSEQ_RET_OK;
}

variable_types: width int

variable_types: length int

variable_types: lastOffset int

variable_types: red int

variable_types: green int

variable_types: blue int

variable_types: x int

variable_types: y int

variable_types: pos int


decompiled_code:
__int64 __fastcall fcseq_nextFrame(__int64 a1, __int64 a2)
{
__int64 v3; // rsi
__int64 result; // rax
unsigned int v5; // eax
int v6; // er12
__int64 v7; // rsi
int v8; // er13
__int64 v9; // r14
int v10; // er9
unsigned int v11; // [rsp+Ch] [rbp-4Ch]
int v12; // [rsp+1Ch] [rbp-3Ch] BYREF
int v13; // [rsp+20h] [rbp-38h] BYREF
unsigned int v14; // [rsp+24h] [rbp-34h] BYREF
char v15[46]; // [rsp+2Ah] [rbp-2Eh] BYREF

if ( *(_DWORD *)(a1 + 32) != 1 )
{
v3 = (unsigned int)parse(*(_QWORD *)(a1 + 16), *(unsigned int *)(a1 + 28), &v12, &v13);
result = 3LL;
if ( v12 != 2 )
return result;
if ( v13 == 2 && (int)v3 >= 0 )
{
v5 = parse_number(*(_QWORD *)(a1 + 16), v3, &v14);
return extractFrame(*(_QWORD *)(a1 + 16), a2, *(_DWORD *)a1, v5, v14);
}
return 3LL;
}
v6 = hwal_fread(v15, 6LL, *(unsigned int *)(a1 + 16));
result = 6LL;
if ( v6 == 6 )
{
v7 = (unsigned int)parse(v15, 0LL, &v12, &v13);
result = 3LL;
if ( v12 == 2 )
{
if ( v13 != 2 || (int)v7 < 0 )
return 3LL;
v8 = parse_number(v15, v7, &v14);
v9 = hwal_malloc(v14);
result = 7LL;
if ( v9 )
{
hwal_memcpy(v9, &v15[v8], (unsigned int)(6 - v8));
v10 = hwal_fread(v9 + 6 - v8, v14 - (6 - v8), *(unsigned int *)(a1 + 16));
result = 2LL;
if ( v14 - (6 - v8) == v10 )
{
v11 = extractFrame(v9, a2, *(_DWORD *)a1, 0, v14);
hwal_free(v9);
result = v11;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v3; // rsi
__int64 result; // rax
unsigned int v5; // eax
int v6; // er12
__int64 v7; // rsi
int v8; // er13
__int64 v9; // r14
int v10; // er9
unsigned int v11; // [rsp+Ch] [rbp-4Ch]
int v12; // [rsp+1Ch] [rbp-3Ch] BYREF
int v13; // [rsp+20h] [rbp-38h] BYREF
unsigned int v14; // [rsp+24h] [rbp-34h] BYREF
char v15[46]; // [rsp+2Ah] [rbp-2Eh] BYREF

if ( *(_DWORD *)(a1 + 32) != 1 )
{
v3 = (unsigned int)parse(*(_QWORD *)(a1 + 16), *(unsigned int *)(a1 + 28), &v12, &v13);
result = 3LL;
if ( v12 != 2 )
return result;
if ( v13 == 2 && (int)v3 >= 0 )
{
v5 = parse_number(*(_QWORD *)(a1 + 16), v3, &v14);
return func3(*(_QWORD *)(a1 + 16), a2, *(_DWORD *)a1, v5, v14);
}
return 3LL;
}
v6 = hwal_fread(v15, 6LL, *(unsigned int *)(a1 + 16));
result = 6LL;
if ( v6 == 6 )
{
v7 = (unsigned int)parse(v15, 0LL, &v12, &v13);
result = 3LL;
if ( v12 == 2 )
{
if ( v13 != 2 || (int)v7 < 0 )
return 3LL;
v8 = parse_number(v15, v7, &v14);
v9 = hwal_malloc(v14);
result = 7LL;
if ( v9 )
{
hwal_memcpy(v9, &v15[v8], (unsigned int)(6 - v8));
v10 = hwal_fread(v9 + 6 - v8, v14 - (6 - v8), *(unsigned int *)(a1 + 16));
result = 2LL;
if ( v14 - (6 - v8) == v10 )
{
v11 = func3(v9, a2, *(_DWORD *)a1, 0, v14);
hwal_free(v9);
result = v11;
}
}
}
}
return result;
}

original_code:
fcseq_ret_t fcseq_nextFrame(fcsequence_t* seqio, uint8_t* rgb24)
{
 int offset = 0;
 int id, type, frame_length;
 fcseq_ret_t ret;
 if (seqio->type == FCSEQ_FILEDESCRIPTOR)
 {
  uint8_t* memFrame;
  uint8_t mem[6];
  int read = hwal_fread(mem, 6, seqio->intern.file.filedescriptor);
  ;;
  if (read != 6)
  {
   return FCSEQ_RET_INVALID_DATA;
  }
  offset = parse(mem, offset, &id, &type);
  ;;
  if (id == 2 && type == 2 && offset > -1)
  {
   offset = parse_number(mem, offset, &frame_length);
   ;;
  }
  else
  {
   ;;
   return FCSEQ_RET_EOF;
  }
  memFrame = (uint8_t*) hwal_malloc(frame_length);
  if (memFrame == 0)
  {
   ;;
   return FCSEQ_RET_OUTOFMEMORY;
  }
  int restOfFirst = (6 - offset);
  ;;
  hwal_memcpy(memFrame, mem + offset, restOfFirst);
  int readBytes = hwal_fread((uint8_t *) (memFrame + restOfFirst), frame_length - restOfFirst,
     seqio->intern.file.filedescriptor);
  if ( readBytes != (frame_length - restOfFirst) )
  {
   ;;
   return FCSEQ_RET_IOERR;
  }
  ;;
  ret = extractFrame(memFrame, rgb24, seqio->width, 0, frame_length);
  hwal_free(memFrame);
  return ret;
 }
 else
 {
  offset = seqio->intern.mem.actOffset;
  offset = parse(seqio->intern.mem.pBuffer, offset, &id, &type);
  if (id == 2 && type == 2 && offset > -1)
  {
   offset = parse_number(seqio->intern.mem.pBuffer, offset, &frame_length);
  }
  else
  {
   return FCSEQ_RET_EOF;
  }
  return extractFrame(seqio->intern.mem.pBuffer, rgb24, seqio->width, offset, frame_length);
  seqio->intern.mem.actOffset = offset + frame_length;
 }
}

canonical_original_code:
enum FCSEQ_RET fcseq_nextFrame(struct FCSEQ *seqio, unsigned char *rgb24)
{
 int offset = 0;
 int id; int type; int frame_length;
 enum FCSEQ_RET ret;
 if (seqio->type == FCSEQ_FILEDESCRIPTOR)
 {
  unsigned char *memFrame;
  unsigned char mem[6];
  int read = hwal_fread(mem, 6, seqio->intern.file.filedescriptor);
  ;;
  if (read != 6)
  {
   return FCSEQ_RET_INVALID_DATA;
  }
  offset = parse(mem, offset, &id, &type);
  ;;
  if (id == 2 && type == 2 && offset > -1)
  {
   offset = parse_number(mem, offset, &frame_length);
   ;;
  }
  else
  {
   ;;
   return FCSEQ_RET_EOF;
  }
  memFrame = (unsigned char *) hwal_malloc(frame_length);
  if (memFrame == 0)
  {
   ;;
   return FCSEQ_RET_OUTOFMEMORY;
  }
  int restOfFirst = (6 - offset);
  ;;
  hwal_memcpy(memFrame, mem + offset, restOfFirst);
  int readBytes = hwal_fread((uint8_t *) (memFrame + restOfFirst), frame_length - restOfFirst,
     seqio->intern.file.filedescriptor);
  if ( readBytes != (frame_length - restOfFirst) )
  {
   ;;
   return FCSEQ_RET_IOERR;
  }
  ;;
  ret = extractFrame(memFrame, rgb24, seqio->width, 0, frame_length);
  hwal_free(memFrame);
  return ret;
 }
 else
 {
  offset = seqio->intern.mem.actOffset;
  offset = parse(seqio->intern.mem.pBuffer, offset, &id, &type);
  if (id == 2 && type == 2 && offset > -1)
  {
   offset = parse_number(seqio->intern.mem.pBuffer, offset, &frame_length);
  }
  else
  {
   return FCSEQ_RET_EOF;
  }
  return extractFrame(seqio->intern.mem.pBuffer, rgb24, seqio->width, offset, frame_length);
  seqio->intern.mem.actOffset = offset + frame_length;
 }
}

variable_types: struct FCSEQ { int width; int height; int fps; union { struct FCSEQ_MEM { unsigned char *pBuffer; unsigned int bufferLength; unsigned int actOffset; } mem; struct FCSEQ_FILE { int filedescriptor; } file; } intern; enum FCSEQ_TYPE { FCSEQ_NONE=0, FCSEQ_FILEDESCRIPTOR=1, FCSEQ_MEMORY=2 } type; } *

variable_types: offset int

variable_types: id int

variable_types: type int

variable_types: enum FCSEQ_RET { FCSEQ_RET_OK=1, FCSEQ_RET_IOERR=2, FCSEQ_RET_EOF=3, FCSEQ_RET_PARAMERR=4, FCSEQ_RET_NOTIMPL=5, FCSEQ_RET_INVALID_DATA=6, FCSEQ_RET_OUTOFMEMORY=7 }

variable_types:
memFrame
unsigned char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm1_8
int v4; // ebx
double v6; // [rsp+0h] [rbp-18h]

v3 = 0.0;
v4 = 10;
v6 = 0.0;
do
{
v6 = testRuntime(argc, argv, envp) + v6;
v3 = v3 + testOneConnection();
--v4;
}
while ( v4 );
printf("\ndone %d tests\n", 100LL);
printf("done %d repeats\n", 10LL);
printf("runtime test - %.5lf seconds\n", v6 / 10.0);
printf("one connection test - %.5lf seconds\n", v3 / 10.0);
printf("result1 / result2 = %.5lf\n", v6 / 10.0 / (v3 / 10.0));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm1_8
int v4; // ebx
double v6; // [rsp+0h] [rbp-18h]

v3 = 0.0;
v4 = 10;
v6 = 0.0;
do
{
v6 = func7(argc, argv, envp) + v6;
v3 = v3 + func8();
--v4;
}
while ( v4 );
printf("\ndone %d tests\n", 100LL);
printf("done %d repeats\n", 10LL);
printf("runtime test - %.5lf seconds\n", v6 / 10.0);
printf("one connection test - %.5lf seconds\n", v3 / 10.0);
printf("result1 / result2 = %.5lf\n", v6 / 10.0 / (v3 / 10.0));
return 0;
}

original_code:
int main(int argc, char ** argv) {
 double result1, result2, sum1, sum2;
 int i;
 sum1 = sum2 = 0.0;
 for (i = 0; i < 10; ++i) {
  sum1 += testRuntime();
  sum2 += testOneConnection();
 }
 result1 = sum1 / 10;
 result2 = sum2 / 10;
 printf("\ndone %d tests\n", 100);
 printf("done %d repeats\n", 10);
 printf ("runtime test - %.5lf seconds\n", result1);
 printf ("one connection test - %.5lf seconds\n", result2);
 printf("result1 / result2 = %.5lf\n", result1 / result2);
}

canonical_original_code:
int main(int argc, char **argv) {
 double result1; double result2; double sum1; double sum2;
 int i;
 sum1 = sum2 = 0.0;
 for (i = 0; i < 10; ++i) {
  sum1 += testRuntime();
  sum2 += testOneConnection();
 }
 result1 = sum1 / 10;
 result2 = sum2 / 10;
 printf("\ndone %d tests\n", 100);
 printf("done %d repeats\n", 10);
 printf ("runtime test - %.5lf seconds\n", result1);
 printf ("one connection test - %.5lf seconds\n", result2);
 printf("result1 / result2 = %.5lf\n", result1 / result2);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int


testRuntime

decompiled_code:
double testRuntime()
{
int v0; // ebx
struct timeval v2; // [rsp+0h] [rbp-98h] BYREF
struct timeval tv; // [rsp+10h] [rbp-88h] BYREF
char s[120]; // [rsp+20h] [rbp-78h] BYREF

v0 = 100;
sprintf(s, "../pdfFox/pdfFox %s", "/opt/hsn2/hsn2svn/software/Razorback/test/resources/big.pdf");
gettimeofday(&v2, 0LL);
do
{
system(s);
--v0;
}
while ( v0 );
gettimeofday(&tv, 0LL);
return ((double)(LODWORD(tv.tv_usec) + 1000000 * LODWORD(tv.tv_sec))
- (double)(LODWORD(v2.tv_usec) + 1000000 * LODWORD(v2.tv_sec)))
/ 1000000.0;
}

canonical_decompiled_code:
double func7()
{
int v0; // ebx
struct timeval v2; // [rsp+0h] [rbp-98h] BYREF
struct timeval tv; // [rsp+10h] [rbp-88h] BYREF
char s[120]; // [rsp+20h] [rbp-78h] BYREF

v0 = 100;
sprintf(s, "../pdfFox/pdfFox %s", "/opt/hsn2/hsn2svn/software/Razorback/test/resources/big.pdf");
gettimeofday(&v2, 0LL);
do
{
system(s);
--v0;
}
while ( v0 );
gettimeofday(&tv, 0LL);
return ((double)(LODWORD(tv.tv_usec) + 1000000 * LODWORD(tv.tv_sec))
- (double)(LODWORD(v2.tv_usec) + 1000000 * LODWORD(v2.tv_sec)))
/ 1000000.0;
}

original_code:
double testRuntime() {
 int i;
 struct timeval startTime, endTime;
 char command[100];
 sprintf(command, "../pdfFox/pdfFox %s", "/opt/hsn2/hsn2svn/software/Razorback/test/resources/big.pdf");
 gettimeofday(&startTime, ((void *)0));
 for (i = 0; i < 100; ++i) {
  system(command);
 }
 gettimeofday(&endTime, ((void *)0));
 double tS = startTime.tv_sec * 1000000 + (startTime.tv_usec);
 double tE = endTime.tv_sec * 1000000 + (endTime.tv_usec);
 return (tE - tS) / 1000000;
}

canonical_original_code:
double testRuntime() {
 int i;
 struct timeval startTime; struct timeval endTime;
 char command[100];
 sprintf(command, "../pdfFox/pdfFox %s", "/opt/hsn2/hsn2svn/software/Razorback/test/resources/big.pdf");
 gettimeofday(&startTime, ((void *)0));
 for (i = 0; i < 100; ++i) {
  system(command);
 }
 gettimeofday(&endTime, ((void *)0));
 double tS = startTime.tv_sec * 1000000 + (startTime.tv_usec);
 double tE = endTime.tv_sec * 1000000 + (endTime.tv_usec);
 return (tE - tS) / 1000000;
}

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

variable_types:
command
char [100]

variable_types: tS double

variable_types: tE double

return_type: double


testOneConnection

decompiled_code:
double testOneConnection()
{
int v0; // ebx
__int8 *v1; // rax
__m128i v3; // [rsp+0h] [rbp-1850h] BYREF
__int16 v4; // [rsp+10h] [rbp-1840h]
struct timeval tv; // [rsp+1810h] [rbp-40h] BYREF
struct timeval v6; // [rsp+1820h] [rbp-30h] BYREF

v0 = 100;
v4 = 32;
v3 = _mm_load_si128((const __m128i *)&xmmword_4020F0);
do
{
v1 = &v3.m128i_i8[strlen(v3.m128i_i8)];
*(__m128i *)v1 = _mm_load_si128((const __m128i *)&xmmword_402100);
strcpy(v1 + 48, "ces/big.pdf");
*((__m128i *)v1 + 1) = _mm_load_si128((const __m128i *)&xmmword_402110);
*((__m128i *)v1 + 2) = _mm_load_si128((const __m128i *)&xmmword_402120);
*(_WORD *)(v1 + 59) = 32;
--v0;
}
while ( v0 );
gettimeofday(&tv, 0LL);
system(v3.m128i_i8);
gettimeofday(&v6, 0LL);
return ((double)(LODWORD(v6.tv_usec) + 1000000 * LODWORD(v6.tv_sec))
- (double)(LODWORD(tv.tv_usec) + 1000000 * LODWORD(tv.tv_sec)))
/ 1000000.0;
}

original_code:
double testOneConnection() {
 int i;
 struct timeval startTime, endTime;
 char command[100 * (strlen("/opt/hsn2/hsn2svn/software/Razorback/test/resources/big.pdf") + 2) + 50];
 strcpy(command, "../pdfFox/pdfFox ");
 for (i = 0; i < 100; ++i) {
  strcat(command, "/opt/hsn2/hsn2svn/software/Razorback/test/resources/big.pdf");
  strcat(command, " ");
 }
 gettimeofday(&startTime, ((void *)0));
 system(command);
 gettimeofday(&endTime, ((void *)0));
 double tS = startTime.tv_sec * 1000000 + (startTime.tv_usec);
 double tE = endTime.tv_sec * 1000000 + (endTime.tv_usec);
 return (tE - tS) / 1000000;
}

canonical_original_code:
double testOneConnection() {
 int i;
 struct timeval startTime; struct timeval endTime;
 char command[-1];
 strcpy(command, "../pdfFox/pdfFox ");
 for (i = 0; i < 100; ++i) {
  strcat(command, "/opt/hsn2/hsn2svn/software/Razorback/test/resources/big.pdf");
  strcat(command, " ");
 }
 gettimeofday(&startTime, ((void *)0));
 system(command);
 gettimeofday(&endTime, ((void *)0));
 double tS = startTime.tv_sec * 1000000 + (startTime.tv_usec);
 double tE = endTime.tv_sec * 1000000 + (endTime.tv_usec);
 return (tE - tS) / 1000000;
}

variable_types:
command
char [-1]

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


repo: CJLove/MqTap

decompiled_code:
void mq_tap_fini()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void mq_tap_fini(void)
{
}

canonical_original_code:
void mq_tap_fini()
{
}


decompiled_code:
void mq_tap_init()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void mq_tap_init(void)
{
}

canonical_original_code:
void mq_tap_init()
{
}


decompiled_code:
int __fastcall mq_tap_log(const char *a1, char *a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbx
int result; // eax

if ( a3 )
{
v4 = 1LL;
printf("%s() called with data:\n", a1);
printf(" 0x%02x", (unsigned int)*a2);
while ( a3 >= ++v4 )
{
while ( 1 )
{
printf(" 0x%02x", (unsigned int)a2[v4 - 1]);
if ( __ROR8__(0xCCCCCCCCCCCCCCCDLL * v4, 1) > 0x1999999999999999uLL )
break;
++v4;
putchar(10);
if ( a3 < v4 )
goto LABEL_6;
}
}
LABEL_6:
result = putchar(10);
}
return result;
}

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

if ( a3 )
{
v4 = 1LL;
printf("%s() called with data:\n", a1);
printf(" 0x%02x", (unsigned int)*a2);
while ( a3 >= ++v4 )
{
while ( 1 )
{
printf(" 0x%02x", (unsigned int)a2[v4 - 1]);
if ( __ROR8__(0xCCCCCCCCCCCCCCCDLL * v4, 1) > 0x1999999999999999uLL )
break;
++v4;
putchar(10);
if ( a3 < v4 )
goto LABEL_6;
}
}
LABEL_6:
result = putchar(10);
}
return result;
}

original_code:
static void mq_tap_log(const char *func, const char *data, const size_t len)
{
    size_t i = 0;
    if (len > 0) {
        printf("%s() called with data:\n",func);
        char *c = (char*)data;
        for (i = 1; i <= len; ++i) {
            printf("  0x%02x",*c);
            if ((i % 10) == 0) printf("\n");
            ++c;
        }
        printf("\n");
    }
}

canonical_original_code:
static void mq_tap_log(char *func, char *data, unsigned long len)
{
    unsigned long i = 0;
    if (len > 0) {
        printf("%s() called with data:\n",func);
        char *c = (char*)data;
        for (i = 1; i <= len; ++i) {
            printf("  0x%02x",*c);
            if ((i % 10) == 0) printf("\n");
            ++c;
        }
        printf("\n");
    }
}

variable_types:
func
char *

variable_types:
data
char *

variable_types:
len
unsigned long

variable_types:
i
unsigned long

variable_types:
c
char *


decompiled_code:
int print_usage()
{
return puts(
"usage: ./gameoflife [-c] [-p] [-v filename] [-g]\n"
" -c Runs a suite of correctness tests\n"
" -p Runs performance tests\n"
" -v Runs a configuration file in visual mode\n"
" -g Runs the CUDA version instead of the pthreads version");
}

canonical_decompiled_code:
int func0()
{
return puts(
"usage: ./gameoflife [-c] [-p] [-v filename] [-g]\n"
" -c Runs a suite of correctness tests\n"
" -p Runs performance tests\n"
" -v Runs a configuration file in visual mode\n"
" -g Runs the CUDA version instead of the pthreads version");
}

original_code:
void print_usage() {
printf("usage: ./gameoflife [-c] [-p] [-v filename] [-g]\n"
       "       -c Runs a suite of correctness tests\n"
       "       -p Runs performance tests\n"
       "       -v Runs a configuration file in visual mode\n"
       "       -g Runs the CUDA version instead of the pthreads version\n");
}


original_code:
void run_gol_cuda(bool* cells, int n, int m, int iterations, int threads) {
    if(threads == 0){
        int gx = (n / 16);
        int gy = (m / 16);
        if(n%16)
            gx++;
        if(m%16)
            gy++;
        gol_cuda(cells, n, m, iterations, gx, gy, 16, 16);
    }else{
        gol_cuda(cells, n, m, iterations, threads, 1, 16, 16);
    }
}

canonical_original_code:
void run_gol_cuda(char *cells, int n, int m, int iterations, int threads) {
    if(threads == 0){
        int gx = (n / 16);
        int gy = (m / 16);
        if(n%16)
            gx++;
        if(m%16)
            gy++;
        gol_cuda(cells, n, m, iterations, gx, gy, 16, 16);
    }else{
        gol_cuda(cells, n, m, iterations, threads, 1, 16, 16);
    }
}

variable_types:
cells
char *

variable_types: n int

variable_types: m int

variable_types: iterations int

variable_types: threads int

variable_types: gx int

variable_types: gy int


decompiled_code:
__int64 __fastcall ms_difference(int a1, int a2, int a3, int a4)
{
return (unsigned int)(1000 * (a3 - a1) + (a4 - a2) / 1000);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, int a3, int a4)
{
return (unsigned int)(1000 * (a3 - a1) + (a4 - a2) / 1000);
}

original_code:
int ms_difference(struct timeval start, struct timeval end) {
    int ms = (end.tv_sec - start.tv_sec) * 1000;
    ms += (end.tv_usec - start.tv_usec) / 1000;
    return ms;
}

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

variable_types:
end
struct timeval

variable_types: ms int


identical

decompiled_code:
__int64 __fastcall identical(__int64 a1, __int64 a2, int a3, int a4)
{
int v4; // edx
__int64 v5; // rax

v4 = a4 * a3;
if ( v4 <= 0 )
return 1LL;
v5 = 0LL;
while ( *(_BYTE *)(a1 + v5) == *(_BYTE *)(a2 + v5) )
{
if ( ++v5 == v4 )
return 1LL;
}
return 0LL;
}

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

v4 = a4 * a3;
if ( v4 <= 0 )
return 1LL;
v5 = 0LL;
while ( *(_BYTE *)(a1 + v5) == *(_BYTE *)(a2 + v5) )
{
if ( ++v5 == v4 )
return 1LL;
}
return 0LL;
}

original_code:
bool identical(bool* game1, bool* game2, int n, int m) {
    int i;
    for(i = 0; i < n * m; ++i) {
        if(game1[i] != game2[i]) {
            return (char)0;
        }
    }
    return (char)1;
}

canonical_original_code:
char identical(char *game1, char *game2, int n, int m) {
    int i;
    for(i = 0; i < n * m; ++i) {
        if(game1[i] != game2[i]) {
            return (char)0;
        }
    }
    return (char)1;
}

variable_types: i int

return_type: char


decompiled_code:
__int64 __fastcall correctness_test(const char *a1, int a2, unsigned int a3, unsigned int a4)
{
int v6; // ebx
unsigned int v7; // er13
unsigned int v9; // [rsp+8h] [rbp-50h] BYREF
unsigned int v10; // [rsp+Ch] [rbp-4Ch] BYREF
void *ptr; // [rsp+10h] [rbp-48h] BYREF
void *v12; // [rsp+18h] [rbp-40h] BYREF

input_game(&ptr, &v9, (int *)&v10, a1);
input_game(&v12, &v9, (int *)&v10, a1);
if ( a2 <= 0 )
{
LABEL_8:
v7 = 1;
printf(
"\rTesting %-25s (%d threads, %d step(s)) %d/%d iterations complete\n",
a1,
a3,
a4,
(unsigned int)a2,
(unsigned int)a2);
free(ptr);
free(v12);
}
else
{
v6 = 0;
while ( 1 )
{
printf(
"\rTesting %-25s (%d threads, %d step(s)) %d/%d iterations complete",
a1,
a3,
a4,
(unsigned int)v6,
(unsigned int)a2);
fflush(stdout);
gol_serial(ptr, v9, v10, a4);
if ( run_cuda )
run_gol_cuda((__int64)v12, v9, v10, a4, a3);
else
gol_parallel(v12, v9, v10, a4, a3);
v7 = identical((__int64)ptr, (__int64)v12, v9, v10);
if ( !(_BYTE)v7 )
break;
v6 += a4;
if ( a2 <= v6 )
goto LABEL_8;
}
printf("\nError at %s on iteration %d\n", a1, (unsigned int)(v6 + 1));
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, int a2, unsigned int a3, unsigned int a4)
{
int v6; // ebx
unsigned int v7; // er13
unsigned int v9; // [rsp+8h] [rbp-50h] BYREF
unsigned int v10; // [rsp+Ch] [rbp-4Ch] BYREF
void *ptr; // [rsp+10h] [rbp-48h] BYREF
void *v12; // [rsp+18h] [rbp-40h] BYREF

func4(&ptr, &v9, (int *)&v10, a1);
func4(&v12, &v9, (int *)&v10, a1);
if ( a2 <= 0 )
{
LABEL_8:
v7 = 1;
printf(
"\rTesting %-25s (%d threads, %d step(s)) %d/%d iterations complete\n",
a1,
a3,
a4,
(unsigned int)a2,
(unsigned int)a2);
free(ptr);
free(v12);
}
else
{
v6 = 0;
while ( 1 )
{
printf(
"\rTesting %-25s (%d threads, %d step(s)) %d/%d iterations complete",
a1,
a3,
a4,
(unsigned int)v6,
(unsigned int)a2);
fflush(stdout);
gol_serial(ptr, v9, v10, a4);
if ( run_cuda )
func1((__int64)v12, v9, v10, a4, a3);
else
gol_parallel(v12, v9, v10, a4, a3);
v7 = func3((__int64)ptr, (__int64)v12, v9, v10);
if ( !(_BYTE)v7 )
break;
v6 += a4;
if ( a2 <= v6 )
goto LABEL_8;
}
printf("\nError at %s on iteration %d\n", a1, (unsigned int)(v6 + 1));
}
return v7;
}

original_code:
bool correctness_test(const char* filename, int iterations, int threads, int step) {
    int i, n, m;
    bool* board1;
    bool* board2;
    input_game(&board1, &n, &m, filename);
    input_game(&board2, &n, &m, filename);
    for(i = 0; i < iterations; i += step) {
        printf("\rTesting %-25s (%d threads, %d step(s)) %d/%d iterations complete", filename, threads, step, i, iterations);
        fflush(stdout);
        gol_serial(board1, n, m, step);
        if(run_cuda){
            run_gol_cuda(board2, n, m, step, threads);
        }else{
            gol_parallel(board2, n, m, step, threads);
        }
        if(!identical(board1, board2, n, m)) {
            printf("\nError at %s on iteration %d\n", filename, i+1);
            return (char)0;
        }
    }
    printf("\rTesting %-25s (%d threads, %d step(s)) %d/%d iterations complete\n", filename, threads, step, iterations, iterations);
    free(board1);
    free(board2);
    return (char)1;
}

canonical_original_code:
char correctness_test(char *filename, int iterations, int threads, int step) {
    int i; int n; int m;
    char *board1;
    char *board2;
    input_game(&board1, &n, &m, filename);
    input_game(&board2, &n, &m, filename);
    for(i = 0; i < iterations; i += step) {
        printf("\rTesting %-25s (%d threads, %d step(s)) %d/%d iterations complete", filename, threads, step, i, iterations);
        fflush(stdout);
        gol_serial(board1, n, m, step);
        if(run_cuda){
            run_gol_cuda(board2, n, m, step, threads);
        }else{
            gol_parallel(board2, n, m, step, threads);
        }
        if(!identical(board1, board2, n, m)) {
            printf("\nError at %s on iteration %d\n", filename, i+1);
            return (char)0;
        }
    }
    printf("\rTesting %-25s (%d threads, %d step(s)) %d/%d iterations complete\n", filename, threads, step, iterations, iterations);
    free(board1);
    free(board2);
    return (char)1;
}

variable_types:
filename
char *

variable_types: step int


decompiled_code:
int correctness_tests()
{
unsigned int v0; // er12
unsigned int v1; // ebp
char *v2; // r13
unsigned int v3; // ebp
unsigned int v4; // ebp
unsigned int v5; // ebp
unsigned int v6; // ebp
unsigned int v7; // ebp
unsigned int v8; // ebp
unsigned int v9; // ebp
int v10; // ebp
int v11; // ebp
int v12; // ebp
int v13; // ebp
int v14; // ebp
int v15; // ebp
_BYTE v17[12]; // [rsp+0h] [rbp-38h] BYREF
int v18; // [rsp+Ch] [rbp-2Ch]
char v19[40]; // [rsp+10h] [rbp-28h] BYREF

v0 = 1;
v1 = 0;
puts("CORRECTNESS TESTS:");
v18 = 10;
v2 = v17;
*(_QWORD *)&v17[4] = 0x500000002LL;
while ( 1 )
{
v3 = v1 - (((unsigned __int8)correctness_test("config/glider", 50, 1u, v0) == 0) - 1);
v4 = v3 - (((unsigned __int8)correctness_test("config/glider", 50, 2u, v0) == 0) - 1);
v5 = v4 - (((unsigned __int8)correctness_test("config/glider", 50, 3u, v0) == 0) - 1);
v6 = v5 - (((unsigned __int8)correctness_test("config/pulsar", 50, 2u, v0) == 0) - 1);
v7 = v6 - (((unsigned __int8)correctness_test("config/pulsar", 50, 4u, v0) == 0) - 1);
v8 = v7 - (((unsigned __int8)correctness_test("config/pulsar", 50, 5u, v0) == 0) - 1);
v9 = v8 - (((unsigned __int8)correctness_test("config/tumbler", 50, 3u, v0) == 0) - 1);
v10 = v9 - (((unsigned __int8)correctness_test("config/tumbler", 50, 5u, v0) == 0) - 1);
v11 = v10 - (((unsigned __int8)correctness_test("config/tumbler", 50, 7u, v0) == 0) - 1);
v12 = v11 - (((unsigned __int8)correctness_test("config/large_glider", 50, 4u, v0) == 0) - 1);
v13 = v12 - (((unsigned __int8)correctness_test("config/large_glider", 50, 8u, v0) == 0) - 1);
v14 = v13 - (((unsigned __int8)correctness_test("config/large_glider", 50, 9u, v0) == 0) - 1);
v15 = v14 - (((unsigned __int8)correctness_test("config/xl_glider", 50, 4u, v0) == 0) - 1);
v1 = v15 - (((unsigned __int8)correctness_test("config/xl_glider", 50, 8u, v0) == 0) - 1);
if ( run_cuda )
break;
v2 += 4;
if ( v2 == v19 )
return printf("%d/%d tests passed\n", v1, run_cuda == 0 ? 56 : 60);
LABEL_4:
v0 = *(_DWORD *)v2;
}
v1 -= ((unsigned __int8)correctness_test("config/xxl_random", 50, 0, v0) == 0) - 1;
v2 += 4;
if ( v2 != v19 )
goto LABEL_4;
return printf("%d/%d tests passed\n", v1, run_cuda == 0 ? 56 : 60);
}

canonical_decompiled_code:
int func6()
{
unsigned int v0; // er12
unsigned int v1; // ebp
char *v2; // r13
unsigned int v3; // ebp
unsigned int v4; // ebp
unsigned int v5; // ebp
unsigned int v6; // ebp
unsigned int v7; // ebp
unsigned int v8; // ebp
unsigned int v9; // ebp
int v10; // ebp
int v11; // ebp
int v12; // ebp
int v13; // ebp
int v14; // ebp
int v15; // ebp
_BYTE v17[12]; // [rsp+0h] [rbp-38h] BYREF
int v18; // [rsp+Ch] [rbp-2Ch]
char v19[40]; // [rsp+10h] [rbp-28h] BYREF

v0 = 1;
v1 = 0;
puts("CORRECTNESS TESTS:");
v18 = 10;
v2 = v17;
*(_QWORD *)&v17[4] = 0x500000002LL;
while ( 1 )
{
v3 = v1 - (((unsigned __int8)func5("config/glider", 50, 1u, v0) == 0) - 1);
v4 = v3 - (((unsigned __int8)func5("config/glider", 50, 2u, v0) == 0) - 1);
v5 = v4 - (((unsigned __int8)func5("config/glider", 50, 3u, v0) == 0) - 1);
v6 = v5 - (((unsigned __int8)func5("config/pulsar", 50, 2u, v0) == 0) - 1);
v7 = v6 - (((unsigned __int8)func5("config/pulsar", 50, 4u, v0) == 0) - 1);
v8 = v7 - (((unsigned __int8)func5("config/pulsar", 50, 5u, v0) == 0) - 1);
v9 = v8 - (((unsigned __int8)func5("config/tumbler", 50, 3u, v0) == 0) - 1);
v10 = v9 - (((unsigned __int8)func5("config/tumbler", 50, 5u, v0) == 0) - 1);
v11 = v10 - (((unsigned __int8)func5("config/tumbler", 50, 7u, v0) == 0) - 1);
v12 = v11 - (((unsigned __int8)func5("config/large_glider", 50, 4u, v0) == 0) - 1);
v13 = v12 - (((unsigned __int8)func5("config/large_glider", 50, 8u, v0) == 0) - 1);
v14 = v13 - (((unsigned __int8)func5("config/large_glider", 50, 9u, v0) == 0) - 1);
v15 = v14 - (((unsigned __int8)func5("config/xl_glider", 50, 4u, v0) == 0) - 1);
v1 = v15 - (((unsigned __int8)func5("config/xl_glider", 50, 8u, v0) == 0) - 1);
if ( run_cuda )
break;
v2 += 4;
if ( v2 == v19 )
return printf("%d/%d tests passed\n", v1, run_cuda == 0 ? 56 : 60);
LABEL_4:
v0 = *(_DWORD *)v2;
}
v1 -= ((unsigned __int8)func5("config/xxl_random", 50, 0, v0) == 0) - 1;
v2 += 4;
if ( v2 != v19 )
goto LABEL_4;
return printf("%d/%d tests passed\n", v1, run_cuda == 0 ? 56 : 60);
}

original_code:
void correctness_tests() {
    printf("CORRECTNESS TESTS:\n");
    int steps[] = {1, 2, 5, 10};
    int i, passed = 0;
    for(i = 0; i < 4; ++i) {
        passed += correctness_test("config/glider", 50, 1, steps[i]) ? 1 : 0;
        passed += correctness_test("config/glider", 50, 2, steps[i]) ? 1 : 0;
        passed += correctness_test("config/glider", 50, 3, steps[i]) ? 1 : 0;
        passed += correctness_test("config/pulsar", 50, 2, steps[i]) ? 1 : 0;
        passed += correctness_test("config/pulsar", 50, 4, steps[i]) ? 1 : 0;
        passed += correctness_test("config/pulsar", 50, 5, steps[i]) ? 1 : 0;
        passed += correctness_test("config/tumbler", 50, 3, steps[i]) ? 1 : 0;
        passed += correctness_test("config/tumbler", 50, 5, steps[i]) ? 1 : 0;
        passed += correctness_test("config/tumbler", 50, 7, steps[i]) ? 1 : 0;
        passed += correctness_test("config/large_glider", 50, 4, steps[i]) ? 1 : 0;
        passed += correctness_test("config/large_glider", 50, 8, steps[i]) ? 1 : 0;
        passed += correctness_test("config/large_glider", 50, 9, steps[i]) ? 1 : 0;
        passed += correctness_test("config/xl_glider", 50, 4, steps[i]) ? 1 : 0;
        passed += correctness_test("config/xl_glider", 50, 8, steps[i]) ? 1 : 0;
        if(run_cuda){
            passed += correctness_test("config/xxl_random", 50, 0, steps[i]) ? 1 : 0;
        }
    }
    printf("%d/%d tests passed\n", passed, run_cuda ? 60 : 56);
}

canonical_original_code:
void correctness_tests() {
    printf("CORRECTNESS TESTS:\n");
    int steps[] = {1, 2, 5, 10};
    int i; int passed = 0;
    for(i = 0; i < 4; ++i) {
        passed += correctness_test("config/glider", 50, 1, steps[i]) ? 1 : 0;
        passed += correctness_test("config/glider", 50, 2, steps[i]) ? 1 : 0;
        passed += correctness_test("config/glider", 50, 3, steps[i]) ? 1 : 0;
        passed += correctness_test("config/pulsar", 50, 2, steps[i]) ? 1 : 0;
        passed += correctness_test("config/pulsar", 50, 4, steps[i]) ? 1 : 0;
        passed += correctness_test("config/pulsar", 50, 5, steps[i]) ? 1 : 0;
        passed += correctness_test("config/tumbler", 50, 3, steps[i]) ? 1 : 0;
        passed += correctness_test("config/tumbler", 50, 5, steps[i]) ? 1 : 0;
        passed += correctness_test("config/tumbler", 50, 7, steps[i]) ? 1 : 0;
        passed += correctness_test("config/large_glider", 50, 4, steps[i]) ? 1 : 0;
        passed += correctness_test("config/large_glider", 50, 8, steps[i]) ? 1 : 0;
        passed += correctness_test("config/large_glider", 50, 9, steps[i]) ? 1 : 0;
        passed += correctness_test("config/xl_glider", 50, 4, steps[i]) ? 1 : 0;
        passed += correctness_test("config/xl_glider", 50, 8, steps[i]) ? 1 : 0;
        if(run_cuda){
            passed += correctness_test("config/xxl_random", 50, 0, steps[i]) ? 1 : 0;
        }
    }
    printf("%d/%d tests passed\n", passed, run_cuda ? 60 : 56);
}

variable_types:
steps
int []

variable_types: passed int


decompiled_code:
void __fastcall performance_test(const char *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rbx
__int64 v5; // rbp
unsigned int v6; // [rsp+8h] [rbp-60h] BYREF
unsigned int v7; // [rsp+Ch] [rbp-5Ch] BYREF
void *ptr; // [rsp+10h] [rbp-58h] BYREF
void *v9; // [rsp+18h] [rbp-50h] BYREF
struct timeval tv; // [rsp+20h] [rbp-48h] BYREF
struct timeval v11; // [rsp+30h] [rbp-38h] BYREF

input_game(&ptr, &v6, (int *)&v7, a1);
input_game(&v9, &v6, (int *)&v7, a1);
printf("Running %s (%d iterations, %d threads)\n", a1, a2, a3);
printf("Serial time: ");
fflush(stdout);
gettimeofday(&tv, 0LL);
gol_serial(ptr, v6, v7, a2);
gettimeofday(&v11, 0LL);
v4 = (unsigned int)ms_difference(tv.tv_sec, tv.tv_usec, v11.tv_sec, v11.tv_usec);
printf("%d ms\n", v4);
printf("Parallel time: ");
fflush(stdout);
gettimeofday(&tv, 0LL);
if ( run_cuda )
run_gol_cuda((__int64)ptr, v6, v7, a2, a3);
else
gol_parallel(ptr, v6, v7, a2, a3);
gettimeofday(&v11, 0LL);
v5 = (unsigned int)ms_difference(tv.tv_sec, tv.tv_usec, v11.tv_sec, v11.tv_usec);
printf("%d ms\n", v5);
printf("Speedup: %.4f\n", (float)((float)(int)v4 / (float)(int)v5));
free(ptr);
free(v9);
}

canonical_decompiled_code:
void __fastcall func7(const char *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rbx
__int64 v5; // rbp
unsigned int v6; // [rsp+8h] [rbp-60h] BYREF
unsigned int v7; // [rsp+Ch] [rbp-5Ch] BYREF
void *ptr; // [rsp+10h] [rbp-58h] BYREF
void *v9; // [rsp+18h] [rbp-50h] BYREF
struct timeval tv; // [rsp+20h] [rbp-48h] BYREF
struct timeval v11; // [rsp+30h] [rbp-38h] BYREF

func4(&ptr, &v6, (int *)&v7, a1);
func4(&v9, &v6, (int *)&v7, a1);
printf("Running %s (%d iterations, %d threads)\n", a1, a2, a3);
printf("Serial time: ");
fflush(stdout);
gettimeofday(&tv, 0LL);
gol_serial(ptr, v6, v7, a2);
gettimeofday(&v11, 0LL);
v4 = (unsigned int)func2(tv.tv_sec, tv.tv_usec, v11.tv_sec, v11.tv_usec);
printf("%d ms\n", v4);
printf("Parallel time: ");
fflush(stdout);
gettimeofday(&tv, 0LL);
if ( run_cuda )
func1((__int64)ptr, v6, v7, a2, a3);
else
gol_parallel(ptr, v6, v7, a2, a3);
gettimeofday(&v11, 0LL);
v5 = (unsigned int)func2(tv.tv_sec, tv.tv_usec, v11.tv_sec, v11.tv_usec);
printf("%d ms\n", v5);
printf("Speedup: %.4f\n", (float)((float)(int)v4 / (float)(int)v5));
free(ptr);
free(v9);
}

original_code:
void performance_test(const char* filename, int iterations, int threads) {
    struct timeval start, end;
    int n, m, serial_time, parallel_time;
    bool* board1;
    bool* board2;
    input_game(&board1, &n, &m, filename);
    input_game(&board2, &n, &m, filename);
    printf("Running %s (%d iterations, %d threads)\n", filename, iterations, threads);
    printf("Serial time: ");
    fflush(stdout);
    gettimeofday(&start, ((void *)0));
    gol_serial(board1, n, m, iterations);
    gettimeofday(&end, ((void *)0));
    serial_time = ms_difference(start, end);
    printf("%d ms\n", serial_time);
    printf("Parallel time: ");
    fflush(stdout);
    gettimeofday(&start, ((void *)0));
    if(run_cuda){
        run_gol_cuda(board1, n, m, iterations, threads);
    }else{
        gol_parallel(board1, n, m, iterations, threads);
    }
    gettimeofday(&end, ((void *)0));
    parallel_time = ms_difference(start, end);
    printf("%d ms\n", parallel_time);
    printf("Speedup: %.4f\n", (float)serial_time/parallel_time);
    free(board1);
    free(board2);
}

canonical_original_code:
void performance_test(char *filename, int iterations, int threads) {
    struct timeval start; struct timeval end;
    int n; int m; int serial_time; int parallel_time;
    char *board1;
    char *board2;
    input_game(&board1, &n, &m, filename);
    input_game(&board2, &n, &m, filename);
    printf("Running %s (%d iterations, %d threads)\n", filename, iterations, threads);
    printf("Serial time: ");
    fflush(stdout);
    gettimeofday(&start, ((void *)0));
    gol_serial(board1, n, m, iterations);
    gettimeofday(&end, ((void *)0));
    serial_time = ms_difference(start, end);
    printf("%d ms\n", serial_time);
    printf("Parallel time: ");
    fflush(stdout);
    gettimeofday(&start, ((void *)0));
    if(run_cuda){
        run_gol_cuda(board1, n, m, iterations, threads);
    }else{
        gol_parallel(board1, n, m, iterations, threads);
    }
    gettimeofday(&end, ((void *)0));
    parallel_time = ms_difference(start, end);
    printf("%d ms\n", parallel_time);
    printf("Speedup: %.4f\n", (float)serial_time/parallel_time);
    free(board1);
    free(board2);
}


decompiled_code:
void performance_tests()
{
puts("PERFORMANCE TESTS:");
performance_test("config/xl_glider", 0x3E8u, 2u);
performance_test("config/xl_glider", 0x3E8u, 4u);
if ( run_cuda )
{
performance_test("config/xl_glider", 0x3E8u, 0);
performance_test("config/xxl_random", 0x3E8u, 0);
}
else
{
performance_test("config/xl_glider", 0x3E8u, 8u);
performance_test("config/xxl_random", 0x3E8u, 8u);
}
}

canonical_decompiled_code:
void func8()
{
puts("PERFORMANCE TESTS:");
func7("config/xl_glider", 0x3E8u, 2u);
func7("config/xl_glider", 0x3E8u, 4u);
if ( run_cuda )
{
func7("config/xl_glider", 0x3E8u, 0);
func7("config/xxl_random", 0x3E8u, 0);
}
else
{
func7("config/xl_glider", 0x3E8u, 8u);
func7("config/xxl_random", 0x3E8u, 8u);
}
}

original_code:
void performance_tests() {
    printf("PERFORMANCE TESTS:\n");
    performance_test("config/xl_glider", 1000, 2);
    performance_test("config/xl_glider", 1000, 4);
    if(run_cuda){
        performance_test("config/xl_glider", 1000, 0);
        performance_test("config/xxl_random", 1000, 0);
    }else{
        performance_test("config/xl_glider", 1000, 8);
        performance_test("config/xxl_random", 1000, 8);
    }
}


decompiled_code:
int __fastcall print_game(__int64 a1, int a2, int a3)
{
int v5; // ebx
int v6; // er13
int v7; // er12
_BYTE *v8; // r14
int v9; // edi
int v10; // ebx
__int64 v11; // rsi

putchar(43);
if ( a3 <= 0 )
{
puts("+");
if ( a2 <= 0 )
{
putchar(43);
goto LABEL_13;
}
}
else
{
v5 = 0;
do
{
++v5;
putchar(45);
}
while ( a3 != v5 );
puts("+");
if ( a2 <= 0 )
{
putchar(43);
LABEL_11:
v10 = 0;
do
{
++v10;
putchar(45);
}
while ( a3 != v10 );
goto LABEL_13;
}
}
v6 = 0;
v7 = 0;
do
{
putchar(124);
if ( a3 > 0 )
{
v8 = (_BYTE *)(a1 + v6);
do
{
v9 = -(*v8++ == 0);
putchar((v9 & 0xFFFFFFFD) + 35);
}
while ( v8 != (_BYTE *)(a1 + (unsigned int)(a3 - 1) + 1 + v6) );
}
++v7;
v6 += a3;
putchar(124);
putchar(10);
}
while ( a2 > v7 );
putchar(43);
if ( a3 > 0 )
goto LABEL_11;
LABEL_13:
puts("+");
v11 = (unsigned int)iteration_0++;
return printf("Iteration: %d\n", v11);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, int a2, int a3)
{
int v5; // ebx
int v6; // er13
int v7; // er12
_BYTE *v8; // r14
int v9; // edi
int v10; // ebx
__int64 v11; // rsi

putchar(43);
if ( a3 <= 0 )
{
puts("+");
if ( a2 <= 0 )
{
putchar(43);
goto LABEL_13;
}
}
else
{
v5 = 0;
do
{
++v5;
putchar(45);
}
while ( a3 != v5 );
puts("+");
if ( a2 <= 0 )
{
putchar(43);
LABEL_11:
v10 = 0;
do
{
++v10;
putchar(45);
}
while ( a3 != v10 );
goto LABEL_13;
}
}
v6 = 0;
v7 = 0;
do
{
putchar(124);
if ( a3 > 0 )
{
v8 = (_BYTE *)(a1 + v6);
do
{
v9 = -(*v8++ == 0);
putchar((v9 & 0xFFFFFFFD) + 35);
}
while ( v8 != (_BYTE *)(a1 + (unsigned int)(a3 - 1) + 1 + v6) );
}
++v7;
v6 += a3;
putchar(124);
putchar(10);
}
while ( a2 > v7 );
putchar(43);
if ( a3 > 0 )
goto LABEL_11;
LABEL_13:
puts("+");
v11 = (unsigned int)iteration_0++;
return printf("Iteration: %d\n", v11);
}

original_code:
void print_game(bool* cells, int n, int m) {
    static int iteration = 1;
    int i, j;
    printf("+");
    for(i = 0; i < m; ++i) printf("-");
    printf("+\n");
    for(i = 0; i < n; ++i) {
        printf("|");
        for(j = 0; j < m; ++j) {
            printf("%c", cells[i * m + j] ? '#' : ' ');
        }
        printf("|");
        printf("\n");
    }
    printf("+");
    for(i = 0; i < m; ++i) printf("-");
    printf("+\n");
    printf("Iteration: %d\n", iteration++);
}

canonical_original_code:
void print_game(char *cells, int n, int m) {
    static int iteration = 1;
    int i; int j;
    printf("+");
    for(i = 0; i < m; ++i) printf("-");
    printf("+\n");
    for(i = 0; i < n; ++i) {
        printf("|");
        for(j = 0; j < m; ++j) {
            printf("%c", cells[i * m + j] ? '#' : ' ');
        }
        printf("|");
        printf("\n");
    }
    printf("+");
    for(i = 0; i < m; ++i) printf("-");
    printf("+\n");
    printf("Iteration: %d\n", iteration++);
}

variable_types: iteration int

variable_types: j int


decompiled_code:
void __fastcall __noreturn visual_mode(const char *a1)
{
unsigned int v1; // [rsp+0h] [rbp-18h] BYREF
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

input_game((void **)&v3, &v1, (int *)&v2, a1);
while ( 1 )
{
system("clear");
print_game(v3, v1, v2);
if ( run_cuda )
run_gol_cuda(v3, v1, v2, 1LL, 4LL);
else
gol_parallel(v3, v1, v2, 1LL, 4LL);
usleep(0x4C4B40u);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func10(const char *a1)
{
unsigned int v1; // [rsp+0h] [rbp-18h] BYREF
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

func4((void **)&v3, &v1, (int *)&v2, a1);
while ( 1 )
{
system("clear");
func9(v3, v1, v2);
if ( run_cuda )
func1(v3, v1, v2, 1LL, 4LL);
else
gol_parallel(v3, v1, v2, 1LL, 4LL);
usleep(0x4C4B40u);
}
}

original_code:
void visual_mode(const char* filename) {
    bool* cells;
    int n, m;
    input_game(&cells, &n, &m, filename);
    while(1) {
        system("clear");
        print_game(cells, n, m);
        if(run_cuda)
            run_gol_cuda(cells, n, m, 1, 4);
        else
            gol_parallel(cells, n, m, 1, 4);
        usleep(5000000);
    }
}

canonical_original_code:
void visual_mode(char *filename) {
    char *cells;
    int n; int m;
    input_game(&cells, &n, &m, filename);
    while(1) {
        system("clear");
        print_game(cells, n, m);
        if(run_cuda)
            run_gol_cuda(cells, n, m, 1, 4);
        else
            gol_parallel(cells, n, m, 1, 4);
        usleep(5000000);
    }
}

variable_types:
cells
char *