SendMessage

decompiled_code:
int SendMessage()
{
__int64 v0; // rax
char v1; // dl
int v2; // ebp
int v3; // er12
__int64 v4; // rbx
__int64 i; // rdx

v0 = 1LL;
v1 = -92;
v2 = BYTE1(txMessage);
LOBYTE(txMessage) = -92;
do
v1 ^= *((_BYTE *)&txMessage + v0++);
while ( v2 + 3 > (int)v0 );
v3 = v2 + 4;
*((_BYTE *)&txMessage + v2 + 3) = v1;
if ( (quarqd_config[20] & 4) != 0 )
{
v4 = 0LL;
for ( i = 164LL; ; i = *((unsigned __int8 *)&txMessage + v4) )
{
++v4;
fprintf(stderr, "0x%02x ", i);
if ( v3 <= (int)v4 )
break;
}
fputc(10, stderr);
}
*((_BYTE *)&txMessage + v3) = 0;
*((_BYTE *)&txMessage + v2 + 5) = 0;
*((_BYTE *)&txMessage + v2 + 6) = 0;
*((_BYTE *)&txMessage + v2 + 7) = 0;
*((_BYTE *)&txMessage + v2 + 8) = 0;
return Transmit_constprop_0(v2 + 9);
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rax
char v1; // dl
int v2; // ebp
int v3; // er12
__int64 v4; // rbx
__int64 i; // rdx

v0 = 1LL;
v1 = -92;
v2 = BYTE1(txMessage);
LOBYTE(txMessage) = -92;
do
v1 ^= *((_BYTE *)&txMessage + v0++);
while ( v2 + 3 > (int)v0 );
v3 = v2 + 4;
*((_BYTE *)&txMessage + v2 + 3) = v1;
if ( (quarqd_config[20] & 4) != 0 )
{
v4 = 0LL;
for ( i = 164LL; ; i = *((unsigned __int8 *)&txMessage + v4) )
{
++v4;
fprintf(stderr, "0x%02x ", i);
if ( v3 <= (int)v4 )
break;
}
fputc(10, stderr);
}
*((_BYTE *)&txMessage + v3) = 0;
*((_BYTE *)&txMessage + v2 + 5) = 0;
*((_BYTE *)&txMessage + v2 + 6) = 0;
*((_BYTE *)&txMessage + v2 + 7) = 0;
*((_BYTE *)&txMessage + v2 + 8) = 0;
return func1(v2 + 9);
}

original_code:
void SendMessage(void) {
        int i;
 const int length = txMessage[1] + 3;
 unsigned char checksum = 0xA4;
 txMessage[0] = 0xA4;
 for (i = 1; i < length; i++)
  checksum ^= txMessage[i];
 txMessage[i++] = checksum;
 if (quarqd_config.debug_level & DEBUG_LEVEL_ANT_MESSAGES) {
   int j;
   for (j=0; j<i; j++) {
     if (1) {
       fprintf(stderr, "0x%02x ",txMessage[j]);
     } else {
       fprintf(stderr, "0x.. ");
     }
   }
   fprintf(stderr,"\n");
 }
 txMessage[i++] = 0x0;
 txMessage[i++] = 0x0;
 txMessage[i++] = 0x0;
 txMessage[i++] = 0x0;
 txMessage[i++] = 0x0;
 Transmit(txMessage, i);
}

canonical_original_code:
void SendMessage() {
        int i;
 int length = txMessage[1] + 3;
 unsigned char checksum = 0xA4;
 txMessage[0] = 0xA4;
 for (i = 1; i < length; i++)
  checksum ^= txMessage[i];
 txMessage[i++] = checksum;
 if (quarqd_config.debug_level & DEBUG_LEVEL_ANT_MESSAGES) {
   int j;
   for (j=0; j<i; j++) {
     if (1) {
       fprintf(stderr, "0x%02x ",txMessage[j]);
     } else {
       fprintf(stderr, "0x.. ");
     }
   }
   fprintf(stderr,"\n");
 }
 txMessage[i++] = 0x0;
 txMessage[i++] = 0x0;
 txMessage[i++] = 0x0;
 txMessage[i++] = 0x0;
 txMessage[i++] = 0x0;
 Transmit(txMessage, i);
}

variable_types: length int

variable_types:
checksum
unsigned char


repo: ziransun/quarqd-ext

decompiled_code:
int ANT_ResetSystem()
{
*(_WORD *)((char *)&txMessage + 1) = 18945;
return SendMessage();
}

canonical_decompiled_code:
int func3()
{
*(_WORD *)((char *)&txMessage + 1) = 18945;
return func2();
}

original_code:
void ANT_ResetSystem(void){
 txMessage[1] = 1;
 txMessage[2] = 0x4A;
 SendMessage();
}

canonical_original_code:
void ANT_ResetSystem(){
 txMessage[1] = 1;
 txMessage[2] = 0x4A;
 SendMessage();
}

return_type: void


decompiled_code:
void __fastcall ANT_AssignChannelEventFunction(unsigned int a1, __int64 a2, __int64 a3)
{
if ( a1 <= 3 )
{
eventFuncs[a1] = a2;
privateData[a1] = a3;
}
}

canonical_decompiled_code:
void __fastcall func4(unsigned int a1, __int64 a2, __int64 a3)
{
if ( a1 <= 3 )
{
eventFuncs[a1] = a2;
privateData[a1] = a3;
}
}

original_code:
void ANT_AssignChannelEventFunction(int channel,
        void func(void *data, unsigned char* message),
        void *data) {
 if(channel >= 0 && channel < 4){
  eventFuncs[channel] = func;
  privateData[channel] = data;
 }
}

canonical_original_code:
void ANT_AssignChannelEventFunction(int channel, void func(void *data, unsigned char *message), void *data) {
 if(channel >= 0 && channel < 4){
  eventFuncs[channel] = func;
  privateData[channel] = data;
 }
}

variable_types: channel int

variable_types: void (void *data, unsigned char *message)

variable_types:
data
void *


decompiled_code:
int __fastcall ANT_AssignChannel(char a1, char a2, char a3)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 16899;
BYTE4(txMessage) = a2;
BYTE5(txMessage) = a3;
return SendMessage();
}

canonical_decompiled_code:
int __fastcall func5(char a1, char a2, char a3)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 16899;
BYTE4(txMessage) = a2;
BYTE5(txMessage) = a3;
return func2();
}

original_code:
void ANT_AssignChannel(const unsigned char channel, const unsigned char type, const unsigned char network) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 3;
 txMessage[2] = 0x42;
 *data++ = channel;
 *data++ = type;
 *data++ = network;
 SendMessage();
}

canonical_original_code:
void ANT_AssignChannel(unsigned char channel, unsigned char type, unsigned char network) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 3;
 txMessage[2] = 0x42;
 *data++ = channel;
 *data++ = type;
 *data++ = network;
 SendMessage();
}

variable_types:
channel
unsigned char

variable_types:
type
unsigned char

variable_types:
network
unsigned char

variable_types:
data
unsigned char *


decompiled_code:
int __fastcall ANT_UnassignChannel(char a1)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 16641;
return SendMessage();
}

canonical_decompiled_code:
int __fastcall func6(char a1)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 16641;
return func2();
}

original_code:
void ANT_UnassignChannel(const unsigned char channel) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 1;
 txMessage[2] = 0x41;
 *data = channel;
 SendMessage();
}

canonical_original_code:
void ANT_UnassignChannel(unsigned char channel) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 1;
 txMessage[2] = 0x41;
 *data = channel;
 SendMessage();
}


decompiled_code:
int __fastcall ANT_SetChannelSearchTimeout(char a1, char a2)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 17410;
BYTE4(txMessage) = a2;
return SendMessage();
}

canonical_decompiled_code:
int __fastcall func7(char a1, char a2)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 17410;
BYTE4(txMessage) = a2;
return func2();
}

original_code:
void ANT_SetChannelSearchTimeout(const unsigned char channel, const unsigned char search_timeout) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 2;
 txMessage[2] = 0x44;
 *data++ = channel;
 *data++ = search_timeout;
 SendMessage();
}

canonical_original_code:
void ANT_SetChannelSearchTimeout(unsigned char channel, unsigned char search_timeout) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 2;
 txMessage[2] = 0x44;
 *data++ = channel;
 *data++ = search_timeout;
 SendMessage();
}


decompiled_code:
int __fastcall ANT_RequestMessage(char a1, char a2)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 19714;
BYTE4(txMessage) = a2;
return SendMessage();
}

canonical_decompiled_code:
int __fastcall func8(char a1, char a2)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 19714;
BYTE4(txMessage) = a2;
return func2();
}

original_code:
void ANT_RequestMessage(const unsigned char channel, const unsigned char request) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 2;
 txMessage[2] = 0x4D;
 *data++ = channel;
 *data++ = request;
 SendMessage();
}

canonical_original_code:
void ANT_RequestMessage(unsigned char channel, unsigned char request) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 2;
 txMessage[2] = 0x4D;
 *data++ = channel;
 *data++ = request;
 SendMessage();
}

variable_types:
request
unsigned char


decompiled_code:
int __fastcall ANT_SetChannelID(char a1, __int16 a2, char a3, char a4)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 20741;
WORD2(txMessage) = a2;
BYTE6(txMessage) = a3;
HIBYTE(txMessage) = a4;
return SendMessage();
}

canonical_decompiled_code:
int __fastcall func9(char a1, __int16 a2, char a3, char a4)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 20741;
WORD2(txMessage) = a2;
BYTE6(txMessage) = a3;
HIBYTE(txMessage) = a4;
return func2();
}

original_code:
void ANT_SetChannelID(const unsigned char channel, const unsigned short device, const unsigned char deviceType, const unsigned char txType) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 5;
 txMessage[2] = 0x51;
 *data++ = channel;
 *data++ = device & 0xff;
 *data++ = (device >> 8) & 0xff;
 *data++ = deviceType;
 *data++ = txType;
 SendMessage();
}

canonical_original_code:
void ANT_SetChannelID(unsigned char channel, unsigned short device, unsigned char deviceType, unsigned char txType) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 5;
 txMessage[2] = 0x51;
 *data++ = channel;
 *data++ = device & 0xff;
 *data++ = (device >> 8) & 0xff;
 *data++ = deviceType;
 *data++ = txType;
 SendMessage();
}

variable_types:
device
unsigned short

variable_types:
deviceType
unsigned char

variable_types:
txType
unsigned char


decompiled_code:
int __fastcall ANT_SetChannelPeriod(char a1, __int16 a2)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 17155;
WORD2(txMessage) = a2;
return SendMessage();
}

canonical_decompiled_code:
int __fastcall func10(char a1, __int16 a2)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 17155;
WORD2(txMessage) = a2;
return func2();
}

original_code:
void ANT_SetChannelPeriod(const unsigned char channel, const unsigned short period) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 3;
 txMessage[2] = 0x43;
 *data++ = channel;
 *data++ = period & 0xff;
 *data++ = (period >> 8) & 0xff;
 SendMessage();
}

canonical_original_code:
void ANT_SetChannelPeriod(unsigned char channel, unsigned short period) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 3;
 txMessage[2] = 0x43;
 *data++ = channel;
 *data++ = period & 0xff;
 *data++ = (period >> 8) & 0xff;
 SendMessage();
}

variable_types:
period
unsigned short


decompiled_code:
int __fastcall ANT_SetChannelFreq(char a1, char a2)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 17666;
BYTE4(txMessage) = a2;
return SendMessage();
}

canonical_decompiled_code:
int __fastcall func11(char a1, char a2)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 17666;
BYTE4(txMessage) = a2;
return func2();
}

original_code:
void ANT_SetChannelFreq(const unsigned char channel, const unsigned char frequency) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 2;
 txMessage[2] = 0x45;
 *data++ = channel;
 *data++ = frequency;
 SendMessage();
}

canonical_original_code:
void ANT_SetChannelFreq(unsigned char channel, unsigned char frequency) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 2;
 txMessage[2] = 0x45;
 *data++ = channel;
 *data++ = frequency;
 SendMessage();
}

variable_types:
frequency
unsigned char


decompiled_code:
int __fastcall ANT_SetNetworkKey(char a1, __int64 a2)
{
__int64 i; // rax
char v3; // dl

BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 17929;
for ( i = 0LL; i != 8; *((_BYTE *)&txMessage + i + 3) = v3 )
v3 = *(_BYTE *)(a2 + i++);
return SendMessage();
}

canonical_decompiled_code:
int __fastcall func12(char a1, __int64 a2)
{
__int64 i; // rax
char v3; // dl

BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 17929;
for ( i = 0LL; i != 8; *((_BYTE *)&txMessage + i + 3) = v3 )
v3 = *(_BYTE *)(a2 + i++);
return func2();
}

original_code:
void ANT_SetNetworkKey(const unsigned char net, const unsigned char *key) {
 unsigned char *data = txMessage + 3;
 int i;
 txMessage[1] = 9;
 txMessage[2] = 0x46;
 *data++ = net;
 for (i = 0; i < 8; i++)
  *data++ = key[i];
 SendMessage();
}

canonical_original_code:
void ANT_SetNetworkKey(unsigned char net, unsigned char *key) {
 unsigned char *data = txMessage + 3;
 int i;
 txMessage[1] = 9;
 txMessage[2] = 0x46;
 *data++ = net;
 for (i = 0; i < 8; i++)
  *data++ = key[i];
 SendMessage();
}

variable_types:
net
unsigned char

variable_types:
key
unsigned char *

variable_types: i int


SendAckMessage

decompiled_code:
int SendAckMessage()
{
txMessage = txAckMessage;
*((_DWORD *)&txMessage + 2) = *((_DWORD *)&txAckMessage + 2);
return SendMessage();
}

canonical_decompiled_code:
int func13()
{
txMessage = txAckMessage;
*((_DWORD *)&txMessage + 2) = *((_DWORD *)&txAckMessage + 2);
return func2();
}

original_code:
void SendAckMessage( void ) {
        memcpy(txMessage, txAckMessage, 12);
 SendMessage();
}

canonical_original_code:
void SendAckMessage() {
        memcpy(txMessage, txAckMessage, 12);
 SendMessage();
}


ProcessMessage

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

if ( byte_65A == 64 )
{
if ( byte_65D == 5 )
{
fwrite("\nAck sent.\n", 1uLL, 0xBuLL, stderr);
return HandleChannelEvent();
}
if ( byte_65D != 6 )
return HandleChannelEvent();
fwrite("\nResending ack.\n", 1uLL, 0x10uLL, stderr);
result = SendAckMessage();
}
else
{
result = (unsigned __int8)byte_65A - 78;
if ( (unsigned __int8)(byte_65A - 78) <= 4u )
return HandleChannelEvent();
}
return result;
}

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

if ( byte_65A == 64 )
{
if ( byte_65D == 5 )
{
fwrite("\nAck sent.\n", 1uLL, 0xBuLL, stderr);
return func0();
}
if ( byte_65D != 6 )
return func0();
fwrite("\nResending ack.\n", 1uLL, 0x10uLL, stderr);
result = func13();
}
else
{
result = (unsigned __int8)byte_65A - 78;
if ( (unsigned __int8)(byte_65A - 78) <= 4u )
return func0();
}
return result;
}

original_code:
static void ProcessMessage(void) {
 switch (rxMessage[2]) {
  case 0x4F:
  case 0x4E:
  case 0x52:
  case 0x51:
  case 0x50:
   HandleChannelEvent();
   break;
  case 0x40:
    switch (rxMessage[5]) {
    case 6:
      fprintf(stderr, "\nResending ack.\n");
      SendAckMessage();
      break;
    case 5:
      fprintf(stderr, "\nAck sent.\n");
    default:
      HandleChannelEvent();
    }
    break;
  case 0x3E:
   break;
  case 0x54:
   break;
  case 0x61:
   break;
  default:
   break;
 }
}

canonical_original_code:
static void ProcessMessage() {
 switch (rxMessage[2]) {
  case 0x4F:
  case 0x4E:
  case 0x52:
  case 0x51:
  case 0x50:
   HandleChannelEvent();
   break;
  case 0x40:
    switch (rxMessage[5]) {
    case 6:
      fprintf(stderr, "\nResending ack.\n");
      SendAckMessage();
      break;
    case 5:
      fprintf(stderr, "\nAck sent.\n");
    default:
      HandleChannelEvent();
    }
    break;
  case 0x3E:
   break;
  case 0x54:
   break;
  case 0x61:
   break;
  default:
   break;
 }
}


decompiled_code:
int __fastcall ANT_SetAutoCalibrate(char a1, int a2)
{
BYTE3(txAckMessage) = a1;
*(_WORD *)((char *)&txAckMessage + 1) = 20228;
WORD2(txAckMessage) = -21759;
BYTE6(txAckMessage) = a2 != 0;
return SendAckMessage();
}

canonical_decompiled_code:
int __fastcall func15(char a1, int a2)
{
BYTE3(txAckMessage) = a1;
*(_WORD *)((char *)&txAckMessage + 1) = 20228;
WORD2(txAckMessage) = -21759;
BYTE6(txAckMessage) = a2 != 0;
return func13();
}

original_code:
void ANT_SetAutoCalibrate(const unsigned char channel, const int autozero) {
 unsigned char *data = txAckMessage + 3;
 txAckMessage[1] = 4;
 txAckMessage[2] = 0x4F;
 *data++ = channel;
 *data++ = 0x01;
 *data++ = 0xAB;
 *data++ = autozero ? 0x01 : 0x00;
 SendAckMessage();
}

canonical_original_code:
void ANT_SetAutoCalibrate(unsigned char channel, int autozero) {
 unsigned char *data = txAckMessage + 3;
 txAckMessage[1] = 4;
 txAckMessage[2] = 0x4F;
 *data++ = channel;
 *data++ = 0x01;
 *data++ = 0xAB;
 *data++ = autozero ? 0x01 : 0x00;
 SendAckMessage();
}

variable_types: autozero int


decompiled_code:
int __fastcall ANT_RequestCalibrate(char a1)
{
BYTE3(txAckMessage) = a1;
*(_WORD *)((char *)&txAckMessage + 1) = 20228;
WORD2(txAckMessage) = -22015;
BYTE6(txAckMessage) = 0;
return SendAckMessage();
}

canonical_decompiled_code:
int __fastcall func16(char a1)
{
BYTE3(txAckMessage) = a1;
*(_WORD *)((char *)&txAckMessage + 1) = 20228;
WORD2(txAckMessage) = -22015;
BYTE6(txAckMessage) = 0;
return func13();
}

original_code:
void ANT_RequestCalibrate(const unsigned char channel) {
 unsigned char *data = txAckMessage + 3;
 txAckMessage[1] = 4;
 txAckMessage[2] = 0x4F;
 *data++ = channel;
 *data++ = 0x01;
 *data++ = 0xAA;
 *data++ = 0;
 SendAckMessage();
}

canonical_original_code:
void ANT_RequestCalibrate(unsigned char channel) {
 unsigned char *data = txAckMessage + 3;
 txAckMessage[1] = 4;
 txAckMessage[2] = 0x4F;
 *data++ = channel;
 *data++ = 0x01;
 *data++ = 0xAA;
 *data++ = 0;
 SendAckMessage();
}


decompiled_code:
int __fastcall ANT_Open(char a1)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 19201;
return SendMessage();
}

canonical_decompiled_code:
int __fastcall func17(char a1)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 19201;
return func2();
}

original_code:
void ANT_Open(const unsigned char channel) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 1;
 txMessage[2] = 0x4B;
 *data++ = channel;
 SendMessage();
}

canonical_original_code:
void ANT_Open(unsigned char channel) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 1;
 txMessage[2] = 0x4B;
 *data++ = channel;
 SendMessage();
}


decompiled_code:
int __fastcall ANT_Close(char a1)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 19457;
return SendMessage();
}

canonical_decompiled_code:
int __fastcall func18(char a1)
{
BYTE3(txMessage) = a1;
*(_WORD *)((char *)&txMessage + 1) = 19457;
return func2();
}

original_code:
void ANT_Close(const unsigned char channel) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 1;
 txMessage[2] = 0x4C;
 *data++ = channel;
 SendMessage();
}

canonical_original_code:
void ANT_Close(unsigned char channel) {
 unsigned char *data = txMessage + 3;
 txMessage[1] = 1;
 txMessage[2] = 0x4C;
 *data++ = channel;
 SendMessage();
}


main

canonical_name: main

repo: zizhengwu/Linux-C-Programming

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
size_t v3; // rax
FILE *v4; // rdi
size_t v5; // rax
__int64 v6; // r15
__int64 v7; // rbp
int v8; // eax
size_t v9; // rax
int v10; // eax
int fd; // [rsp+Ch] [rbp-4DCh]
struct sockaddr addr; // [rsp+10h] [rbp-4D8h] BYREF
struct timeval timeout; // [rsp+20h] [rbp-4C8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-4B8h] BYREF
fd_set writefds; // [rsp+B0h] [rbp-438h] BYREF
fd_set exceptfds; // [rsp+130h] [rbp-3B8h] BYREF
char v17[256]; // [rsp+1B0h] [rbp-338h] BYREF
char s[256]; // [rsp+2B0h] [rbp-238h] BYREF
char buf[312]; // [rsp+3B0h] [rbp-138h] BYREF

fd = socket(2, 1, 0);
if ( fd == -1 )
{
perror("socket");
exit(1);
}
addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16_constprop_0("127.0.0.1", &addr.sa_data[2]);
inet_aton("127.0.0.1", (struct in_addr *)&addr.sa_data[2]);
if ( connect(fd, &addr, 0x10u) == -1 )
{
perror("connect");
exit(1);
}
fcntl(fd, 2, 2048LL);
puts("Let others' know your name to start chat!");
__isoc99_scanf();
v3 = strlen(s);
v4 = stdout;
s[v3] = 0;
fflush(v4);
v5 = strlen(s);
send(fd, s, v5, 0);
v6 = fd / 64;
v7 = 1LL << (fd % 64);
while ( 1 )
{
do
{
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
memset(&exceptfds, 0, sizeof(exceptfds));
readfds.fds_bits[0] |= 1uLL;
exceptfds.fds_bits[v6] |= v7;
readfds.fds_bits[v6] |= v7;
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
v8 = select(fd + 1, &readfds, &writefds, &exceptfds, &timeout);
}
while ( !v8 );
if ( v8 < 0 )
{
perror("select error:");
exit(-1);
}
if ( (readfds.fds_bits[0] & 1) != 0 )
{
fgets(buf, 256, stdin);
s[strlen(buf) + 255] = 0;
if ( !memcmp("quit", buf, 4uLL) )
goto LABEL_9;
v9 = strlen(buf);
send(fd, buf, v9, 0);
if ( (readfds.fds_bits[v6] & v7) == 0 )
goto LABEL_8;
}
else if ( (readfds.fds_bits[v6] & v7) == 0 )
{
goto LABEL_8;
}
v10 = recv(fd, v17, 0x100uLL, 0);
if ( !v10 )
{
LABEL_9:
close(fd);
exit(0);
}
v17[v10] = 0;
printf("Server: %s\n", v17);
printf("%s: \n", s);
fflush(stdout);
LABEL_8:
if ( (exceptfds.fds_bits[v6] & v7) != 0 )
goto LABEL_9;
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
size_t v3; // rax
FILE *v4; // rdi
size_t v5; // rax
__int64 v6; // r15
__int64 v7; // rbp
int v8; // eax
size_t v9; // rax
int v10; // eax
int fd; // [rsp+Ch] [rbp-4DCh]
struct sockaddr addr; // [rsp+10h] [rbp-4D8h] BYREF
struct timeval timeout; // [rsp+20h] [rbp-4C8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-4B8h] BYREF
fd_set writefds; // [rsp+B0h] [rbp-438h] BYREF
fd_set exceptfds; // [rsp+130h] [rbp-3B8h] BYREF
char v17[256]; // [rsp+1B0h] [rbp-338h] BYREF
char s[256]; // [rsp+2B0h] [rbp-238h] BYREF
char buf[312]; // [rsp+3B0h] [rbp-138h] BYREF

fd = socket(2, 1, 0);
if ( fd == -1 )
{
perror("socket");
exit(1);
}
addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func7("127.0.0.1", &addr.sa_data[2]);
inet_aton("127.0.0.1", (struct in_addr *)&addr.sa_data[2]);
if ( connect(fd, &addr, 0x10u) == -1 )
{
perror("connect");
exit(1);
}
fcntl(fd, 2, 2048LL);
puts("Let others' know your name to start chat!");
__isoc99_scanf();
v3 = strlen(s);
v4 = stdout;
s[v3] = 0;
fflush(v4);
v5 = strlen(s);
send(fd, s, v5, 0);
v6 = fd / 64;
v7 = 1LL << (fd % 64);
while ( 1 )
{
do
{
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
memset(&exceptfds, 0, sizeof(exceptfds));
readfds.fds_bits[0] |= 1uLL;
exceptfds.fds_bits[v6] |= v7;
readfds.fds_bits[v6] |= v7;
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
v8 = select(fd + 1, &readfds, &writefds, &exceptfds, &timeout);
}
while ( !v8 );
if ( v8 < 0 )
{
perror("select error:");
exit(-1);
}
if ( (readfds.fds_bits[0] & 1) != 0 )
{
fgets(buf, 256, stdin);
s[strlen(buf) + 255] = 0;
if ( !memcmp("quit", buf, 4uLL) )
goto LABEL_9;
v9 = strlen(buf);
send(fd, buf, v9, 0);
if ( (readfds.fds_bits[v6] & v7) == 0 )
goto LABEL_8;
}
else if ( (readfds.fds_bits[v6] & v7) == 0 )
{
goto LABEL_8;
}
v10 = recv(fd, v17, 0x100uLL, 0);
if ( !v10 )
{
LABEL_9:
close(fd);
exit(0);
}
v17[v10] = 0;
printf("Server: %s\n", v17);
printf("%s: \n", s);
fflush(stdout);
LABEL_8:
if ( (exceptfds.fds_bits[v6] & v7) != 0 )
goto LABEL_9;
}
}

original_code:
int main(void)
{
 int sockfd;
 int recvbytes;
 char buf[256];
 char *str;
 char name[256];
 char send_str[256];
 struct sockaddr_in serv_addr;
 fd_set rfd_set, wfd_set, efd_set;
 struct timeval timeout;
 int ret;
 if ((sockfd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("socket");
  exit(1);
 }
 bzero(&serv_addr, sizeof(struct sockaddr_in));
 serv_addr.sin_family = 2;
 serv_addr.sin_port = htons(4444);
 inet_aton("127.0.0.1", &serv_addr.sin_addr);
 if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) == -1)
 {
  perror("connect");
  exit(1);
 }
 fcntl(sockfd, 2, 04000);
 printf("Let others' know your name to start chat!\n");
 scanf("%s", name);
 name[strlen(name)] = '\0';
 fflush(stdout);
 send(sockfd, name, strlen(name), 0);
 while(1)
 {
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfd_set)->__fds_bits)[0]) : "memory"); } while (0);
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wfd_set)->__fds_bits)[0]) : "memory"); } while (0);
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&efd_set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rfd_set)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&rfd_set)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&efd_set)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
  timeout.tv_sec = 10;
  timeout.tv_usec = 0;
  ret = select(sockfd + 1, &rfd_set, &wfd_set, &efd_set, &timeout);
  if (ret == 0)
  {
   continue;
  }
  if (ret < 0)
  {
   perror("select error:");
   exit(-1);
  }
  if (((((&rfd_set)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   fgets(send_str, 256, stdin);
   send_str[strlen(send_str)-1]='\0';
   if (strncmp("quit", send_str, 4) == 0)
   {
    close(sockfd);
    exit(0);
   }
   send(sockfd, send_str, strlen(send_str), 0);
  }
  if (((((&rfd_set)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   recvbytes = recv(sockfd, buf, 256, 0);
   if (recvbytes == 0)
   {
    close(sockfd);
    exit(0);
   }
   buf[recvbytes] = '\0';
   printf("Server: %s\n", buf);
   printf("%s: \n", name);
   fflush(stdout);
  }
  if (((((&efd_set)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   close(sockfd);
   exit(0);
  }
 }
}

canonical_original_code:
int main()
{
 int sockfd;
 int recvbytes;
 char buf[256];
 char *str;
 char name[256];
 char send_str[256];
 struct sockaddr_in serv_addr;
 struct fd_set rfd_set; struct fd_set wfd_set; struct fd_set efd_set;
 struct timeval timeout;
 int ret;
 if ((sockfd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("socket");
  exit(1);
 }
 bzero(&serv_addr, sizeof(struct sockaddr_in));
 serv_addr.sin_family = 2;
 serv_addr.sin_port = htons(4444);
 inet_aton("127.0.0.1", &serv_addr.sin_addr);
 if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) == -1)
 {
  perror("connect");
  exit(1);
 }
 fcntl(sockfd, 2, 04000);
 printf("Let others' know your name to start chat!\n");
 scanf("%s", name);
 name[strlen(name)] = '\0';
 fflush(stdout);
 send(sockfd, name, strlen(name), 0);
 while(1)
 {
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfd_set)->__fds_bits)[0]) : "memory"); } while (0);
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wfd_set)->__fds_bits)[0]) : "memory"); } while (0);
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&efd_set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rfd_set)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&rfd_set)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&efd_set)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
  timeout.tv_sec = 10;
  timeout.tv_usec = 0;
  ret = select(sockfd + 1, &rfd_set, &wfd_set, &efd_set, &timeout);
  if (ret == 0)
  {
   continue;
  }
  if (ret < 0)
  {
   perror("select error:");
   exit(-1);
  }
  if (((((&rfd_set)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   fgets(send_str, 256, stdin);
   send_str[strlen(send_str)-1]='\0';
   if (strncmp("quit", send_str, 4) == 0)
   {
    close(sockfd);
    exit(0);
   }
   send(sockfd, send_str, strlen(send_str), 0);
  }
  if (((((&rfd_set)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   recvbytes = recv(sockfd, buf, 256, 0);
   if (recvbytes == 0)
   {
    close(sockfd);
    exit(0);
   }
   buf[recvbytes] = '\0';
   printf("Server: %s\n", buf);
   printf("%s: \n", name);
   fflush(stdout);
  }
  if (((((&efd_set)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   close(sockfd);
   exit(0);
  }
 }
}

variable_types: sockfd int

variable_types: recvbytes int

variable_types:
buf
char [256]

variable_types:
str
char *

variable_types:
name
char [256]

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: struct timeval { long tv_sec; long tv_usec; }

variable_types: ret int

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


addField

repo: zjentohlauedy/MBA

decompiled_code:
_BOOL8 __fastcall addField(__int64 a1, const char *a2, int a3)
{
__int128 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+10h] [rbp-18h]
int v6; // [rsp+18h] [rbp-10h]
__int16 v7; // [rsp+1Ch] [rbp-Ch]

v7 = 0;
v4 = 0LL;
v5 = 0LL;
v6 = 0;
snprintf((char *)&v4, 0x1EuLL, "%.*s", a3 - (_DWORD)a2, a2);
return (int)add_to_data_list(a1, &v4, 30LL, 50LL) >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1, const char *a2, int a3)
{
__int128 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+10h] [rbp-18h]
int v6; // [rsp+18h] [rbp-10h]
__int16 v7; // [rsp+1Ch] [rbp-Ch]

v7 = 0;
v4 = 0LL;
v5 = 0LL;
v6 = 0;
snprintf((char *)&v4, 0x1EuLL, "%.*s", a3 - (_DWORD)a2, a2);
return (int)add_to_data_list(a1, &v4, 30LL, 50LL) >= 0;
}

original_code:
static boolean_e addField( data_list_s *list, const char *start, const char *end )
{
     data_field_s field = { 0 };
     snprintf( field.value, sizeof(field.value), "%.*s", end - start, start );
     if ( add_to_data_list( list, &field, sizeof(data_field_s), 50 ) < 0 ) return bl_False;
     return bl_True;
}

canonical_original_code:
static enum boolean_e addField(struct data_list_s *list, char *start, char *end)
{
     struct data_field_s field = { 0 };
     snprintf( field.value, sizeof(field.value), "%.*s", end - start, start );
     if ( add_to_data_list( list, &field, sizeof(data_field_s), 50 ) < 0 ) return bl_False;
     return bl_True;
}

variable_types: struct data_list_s { int __max; int count; void *data; } *

variable_types:
start
char *

variable_types:
end
char *

variable_types:
field
struct data_field_s { char value[30]; }

return_type: enum boolean_e { bl_False=0, bl_True=1 }


parseCSV

decompiled_code:
__int64 __fastcall parseCSV(__int64 a1, const char *a2)
{
char v2; // al
const char *i; // rbx
__int64 result; // rax
int v5; // edx

v2 = *a2;
if ( !*a2 || v2 == 10 )
return addField(a1, a2, (int)a2);
while ( 1 )
{
for ( i = a2; v2 != 44; v2 = *++i )
{
if ( !v2 )
break;
if ( v2 == 10 )
break;
}
result = addField(a1, a2, (int)i);
if ( !(_DWORD)result )
break;
v2 = *i;
a2 = i;
v5 = 0;
if ( *i == 44 )
{
v2 = i[1];
a2 = i + 1;
v5 = 1;
}
if ( !v2 || v2 == 10 )
{
result = 1LL;
if ( v5 )
return addField(a1, a2, (int)a2);
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
char v2; // al
const char *i; // rbx
__int64 result; // rax
int v5; // edx

v2 = *a2;
if ( !*a2 || v2 == 10 )
return func0(a1, a2, (int)a2);
while ( 1 )
{
for ( i = a2; v2 != 44; v2 = *++i )
{
if ( !v2 )
break;
if ( v2 == 10 )
break;
}
result = func0(a1, a2, (int)i);
if ( !(_DWORD)result )
break;
v2 = *i;
a2 = i;
v5 = 0;
if ( *i == 44 )
{
v2 = i[1];
a2 = i + 1;
v5 = 1;
}
if ( !v2 || v2 == 10 )
{
result = 1LL;
if ( v5 )
return func0(a1, a2, (int)a2);
return result;
}
}
return result;
}

original_code:
boolean_e parseCSV( data_list_s *list, const char *csv )
{
     const char *start;
     const char *end;
     boolean_e another_field = bl_True;
     for ( start = csv, end = csv; ! ((*start) == '\0' || (*start) == '\n'); start = end )
     {
          another_field = bl_False;
          while ( *end != ',' && ! ((*end) == '\0' || (*end) == '\n') ) end++;
          if ( ! addField( list, start, end ) ) return bl_False;
          if ( *end == ',' )
          {
               another_field = bl_True;
               end++;
          }
     }
     if ( another_field )
     {
          if ( ! addField( list, start, end ) ) return bl_False;
     }
     return bl_True;
}

canonical_original_code:
enum boolean_e parseCSV(struct data_list_s *list, char *csv)
{
     char *start;
     char *end;
     enum boolean_e another_field = bl_True;
     for ( start = csv, end = csv; ! ((*start) == '\0' || (*start) == '\n'); start = end )
     {
          another_field = bl_False;
          while ( *end != ',' && ! ((*end) == '\0' || (*end) == '\n') ) end++;
          if ( ! addField( list, start, end ) ) return bl_False;
          if ( *end == ',' )
          {
               another_field = bl_True;
               end++;
          }
     }
     if ( another_field )
     {
          if ( ! addField( list, start, end ) ) return bl_False;
     }
     return bl_True;
}

variable_types:
csv
char *

variable_types: enum boolean_e { bl_False=0, bl_True=1 }

user_defined_types: struct data_list_s { int __max; int count; void *data; }


clearErrorMessage

decompiled_code:
void clearErrorMessage()
{
error_message = 0;
}

canonical_decompiled_code:
void func0()
{
error_message = 0;
}

original_code:
static void clearErrorMessage( void )
{
     error_message[0] = '\0';
}

canonical_original_code:
static void clearErrorMessage()
{
     error_message[0] = '\0';
}


getCopyPlayerIdsError

decompiled_code:
char *getCopyPlayerIdsError()
{
return &error_message;
}

canonical_decompiled_code:
char *func1()
{
return &error_message;
}

original_code:
char *getCopyPlayerIdsError( void )
{
     return error_message;
}

canonical_original_code:
char *getCopyPlayerIdsError()
{
     return error_message;
}

return_type: char *


copyPlayerIds

decompiled_code:
__int64 __fastcall copyPlayerIds(const char *a1, __int64 a2)
{
const char *v2; // r12
unsigned int v3; // eax
unsigned int v4; // eax
__int64 v5; // rbx

v2 = a1;
clearErrorMessage();
do
{
if ( *v2 )
{
v5 = findMatchingPlayer(v2, a2);
if ( !v5 )
{
sprintf(&error_message, "Player <%.*s, %.*s> not found!", 10, v2, 8, v2 + 10);
return 0LL;
}
if ( (unsigned int)word2int(v2 + 84) )
{
sprintf(&error_message, "Player ID field for <%.*s, %.*s> already contains a number!", 10, v2, 8, v2 + 10);
return 0LL;
}
if ( (unsigned int)byte2int(v2 + 86) )
{
sprintf(&error_message, "Checksum field for <%.*s, %.*s> already contains a number!", 10, v2, 8, v2 + 10);
return 0LL;
}
v3 = word2int(v5 + 84);
int2word(v2 + 84, v3);
v4 = byte2int(v5 + 86);
int2byte(v2 + 86, v4);
}
v2 += 112;
}
while ( v2 != a1 + 89600 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int64 a2)
{
const char *v2; // r12
unsigned int v3; // eax
unsigned int v4; // eax
__int64 v5; // rbx

v2 = a1;
func0();
do
{
if ( *v2 )
{
v5 = findMatchingPlayer(v2, a2);
if ( !v5 )
{
sprintf(&error_message, "Player <%.*s, %.*s> not found!", 10, v2, 8, v2 + 10);
return 0LL;
}
if ( (unsigned int)word2int(v2 + 84) )
{
sprintf(&error_message, "Player ID field for <%.*s, %.*s> already contains a number!", 10, v2, 8, v2 + 10);
return 0LL;
}
if ( (unsigned int)byte2int(v2 + 86) )
{
sprintf(&error_message, "Checksum field for <%.*s, %.*s> already contains a number!", 10, v2, 8, v2 + 10);
return 0LL;
}
v3 = word2int(v5 + 84);
int2word(v2 + 84, v3);
v4 = byte2int(v5 + 86);
int2byte(v2 + 86, v4);
}
v2 += 112;
}
while ( v2 != a1 + 89600 );
return 1LL;
}

original_code:
boolean_e copyPlayerIds( fileplayer_s *players_file1, fileplayer_s *players_file2 )
{
     fileplayer_s *matchingPlayer;
     clearErrorMessage();
     for ( int i = 0; i < (((25 * 8) * 2) * 2); ++i )
     {
          if ( (players_file1[i].last_name)[0] == '\0' ) continue;
          if ( (matchingPlayer = findMatchingPlayer( &players_file1[i], players_file2 )) == ((void *)0) )
          {
               sprintf( error_message, "Player <%.*s, %.*s> not found!",
                       sizeof(players_file1[i].last_name), players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );
               return bl_False;
          }
          acc_player_id_s *id_info1 = &(players_file1[i].acc_stats.action.id_info);
          acc_player_id_s *id_info2 = &(matchingPlayer->acc_stats.action.id_info);
          if ( word2int( id_info1->player_id ) != 0 )
          {
               sprintf( error_message, "Player ID field for <%.*s, %.*s> already contains a number!",
                       sizeof(players_file1[i].last_name), players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );
               return bl_False;
          }
          if ( byte2int( id_info1->checksum ) != 0 )
          {
               sprintf( error_message, "Checksum field for <%.*s, %.*s> already contains a number!",
                       sizeof(players_file1[i].last_name), players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );
               return bl_False;
          }
          int2word( id_info1->player_id, word2int( id_info2->player_id ) );
          int2byte( id_info1->checksum, byte2int( id_info2->checksum ) );
     }
     return bl_True;
}

canonical_original_code:
enum boolean_e copyPlayerIds(struct fileplayer_s *players_file1, struct fileplayer_s *players_file2)
{
     struct fileplayer_s *matchingPlayer;
     clearErrorMessage();
     for ( int i = 0; i < (((25 * 8) * 2) * 2); ++i )
     {
          if ( (players_file1[i].last_name)[0] == '\0' ) continue;
          if ( (matchingPlayer = findMatchingPlayer( &players_file1[i], players_file2 )) == ((void *)0) )
          {
               sprintf( error_message, "Player <%.*s, %.*s> not found!",
                       sizeof(players_file1[i].last_name), players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );
               return bl_False;
          }
          struct acc_player_id_s *id_info1 = &(players_file1[i].acc_stats.action.id_info);
          struct acc_player_id_s *id_info2 = &(matchingPlayer->acc_stats.action.id_info);
          if ( word2int( id_info1->player_id ) != 0 )
          {
               sprintf( error_message, "Player ID field for <%.*s, %.*s> already contains a number!",
                       sizeof(players_file1[i].last_name), players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );
               return bl_False;
          }
          if ( byte2int( id_info1->checksum ) != 0 )
          {
               sprintf( error_message, "Checksum field for <%.*s, %.*s> already contains a number!",
                       sizeof(players_file1[i].last_name), players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );
               return bl_False;
          }
          int2word( id_info1->player_id, word2int( id_info2->player_id ) );
          int2byte( id_info1->checksum, byte2int( id_info2->checksum ) );
     }
     return bl_True;
}

variable_types: struct fileplayer_s { char last_name[10]; char first_name[8]; char last_phoen[14]; char first_phoen[12]; unsigned char real_avg[2]; unsigned char year[1]; unsigned char position[1]; union { struct filebatting_s { unsigned char ratings[4]; unsigned char real_games[1]; unsigned char real_runs[1]; unsigned char real_rbi[1]; unsigned char real_sb[1]; unsigned char real_cs[1]; unsigned char real_sh[1]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_2b[1]; unsigned char vl_3b[1]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[1]; unsigned char real_fa2[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_2b[1]; unsigned char vr_3b[1]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[1]; unsigned char real_err[1]; unsigned char real_po[2]; unsigned char real_as[2]; unsigned char injury_days[1]; unsigned char color[1]; } filebatting; struct filepitching_s { unsigned char ratings[2]; unsigned char real_wins[1]; unsigned char real_losses[1]; unsigned char real_games[1]; unsigned char real_starts[1]; unsigned char real_cg[1]; unsigned char real_saves[1]; unsigned char real_inn[2]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[2]; unsigned char real_er[1]; unsigned char real_fa[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[2]; unsigned char real_hb[1]; unsigned char real_balk[1]; unsigned char real_ab[1]; unsigned char real_hits[1]; unsigned char real_hr[1]; unsigned char real_sh[1]; unsigned char injury_days[1]; unsigned char color[1]; } filepitching; } filestats; struct acc_stats_s { union acc_stats_u { struct acc_pch_stats_s { unsigned char acc_wins[1]; unsigned char acc_losses[1]; unsigned char acc_starts[1]; unsigned char acc_saves[1]; unsigned char acc_innings[2]; unsigned char acc_hits[2]; unsigned char acc_er[2]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[2]; } pitching; struct acc_bat_stats_s { unsigned char acc_ab[2]; unsigned char acc_hits[2]; unsigned char acc_2b[1]; unsigned char acc_3b[1]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[1]; unsigned char acc_games[1]; unsigned char acc_runs[1]; unsigned char acc_rbi[1]; unsigned char acc_sb[1]; unsigned char acc_err[1]; } batting; struct acc_player_id_s { unsigned char player_id[2]; unsigned char checksum[1]; unsigned char filler[11]; } id_info; } action; union acc_stats_u simulated; } acc_stats; } *

variable_types: struct acc_player_id_s { unsigned char player_id[2]; unsigned char checksum[1]; unsigned char filler[11]; } *

user_defined_types: enum boolean_e { bl_False=0, bl_True=1 }

user_defined_types: struct fileplayer_s { char last_name[10]; char first_name[8]; char last_phoen[14]; char first_phoen[12]; unsigned char real_avg[2]; unsigned char year[1]; unsigned char position[1]; union { struct filebatting_s filebatting; struct filepitching_s filepitching; } filestats; struct acc_stats_s acc_stats; }

user_defined_types: struct acc_stats_s { union acc_stats_u action; union acc_stats_u simulated; }

user_defined_types: union acc_stats_u { struct acc_pch_stats_s pitching; struct acc_bat_stats_s batting; struct acc_player_id_s id_info; }


teamExcluded

decompiled_code:
__int64 __fastcall teamExcluded(char *s1, const char **a2, int a3)
{
__int64 v3; // r12
const char **v4; // rbx

if ( a3 <= 0 )
return 0LL;
v3 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
v4 = a2;
do
{
if ( !strncmp(s1, *v4, 0xCuLL) )
return 1LL;
++v4;
}
while ( v4 != (const char **)v3 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1, const char **a2, int a3)
{
__int64 v3; // r12
const char **v4; // rbx

if ( a3 <= 0 )
return 0LL;
v3 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
v4 = a2;
do
{
if ( !strncmp(s1, *v4, 0xCuLL) )
return 1LL;
++v4;
}
while ( v4 != (const char **)v3 );
return 0LL;
}

original_code:
static int teamExcluded( const char *team, const char *excluded_teams[], const int num_excluded )
{
     for ( int i = 0; i < num_excluded; ++i )
     {
          if ( strncmp( team, excluded_teams[i], 12 ) == 0 ) return 1;
     }
     return 0;
}

canonical_original_code:
static int teamExcluded(char *team, char *excluded_teams[], int num_excluded)
{
     for ( int i = 0; i < num_excluded; ++i )
     {
          if ( strncmp( team, excluded_teams[i], 12 ) == 0 ) return 1;
     }
     return 0;
}

variable_types:
team
char *

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
_BYTE *v4; // r15
unsigned int i; // er14
int result; // eax
_BYTE *ptr; // [rsp+8h] [rbp-40h]

if ( argc <= 3 )
{
printf("Usage: %s <leaguefile> <input playerfile> <output playerfile> [exclude team]...\n", *argv);
result = 0;
}
else
{
v3 = (char *)readLeagueFile(argv[1]);
if ( v3 )
{
ptr = (_BYTE *)readPlayersFile(argv[2]);
if ( ptr )
{
v4 = ptr;
for ( i = 0; i != 800; ++i )
{
if ( *v4 && !(unsigned int)teamExcluded(&v3[16 * (i / 0x19uLL) + 124], argv + 4, argc - 4) )
v4[82] = (v4[82] == 0) + v4[82] - 1;
v4 += 112;
}
if ( (unsigned int)writePlayersFile(argv[3], ptr) )
{
free(v3);
free(ptr);
result = 0;
}
else
{
puts("Cannot save player changes.");
free(v3);
free(ptr);
result = 1;
}
}
else
{
printf("Cannot load players file.");
free(v3);
result = 1;
}
}
else
{
printf("Cannot load league file.");
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
_BYTE *v4; // r15
unsigned int i; // er14
int result; // eax
_BYTE *ptr; // [rsp+8h] [rbp-40h]

if ( argc <= 3 )
{
printf("Usage: %s <leaguefile> <input playerfile> <output playerfile> [exclude team]...\n", *argv);
result = 0;
}
else
{
v3 = (char *)readLeagueFile(argv[1]);
if ( v3 )
{
ptr = (_BYTE *)readPlayersFile(argv[2]);
if ( ptr )
{
v4 = ptr;
for ( i = 0; i != 800; ++i )
{
if ( *v4 && !(unsigned int)func0(&v3[16 * (i / 0x19uLL) + 124], argv + 4, argc - 4) )
v4[82] = (v4[82] == 0) + v4[82] - 1;
v4 += 112;
}
if ( (unsigned int)writePlayersFile(argv[3], ptr) )
{
free(v3);
free(ptr);
result = 0;
}
else
{
puts("Cannot save player changes.");
free(v3);
free(ptr);
result = 1;
}
}
else
{
printf("Cannot load players file.");
free(v3);
result = 1;
}
}
else
{
printf("Cannot load league file.");
result = 1;
}
}
return result;
}

original_code:
int main( const int argc, const char *argv[] )
{
     fileplayer_s *playerFile;
     fileleague_s *leagueFile;
     if ( argc < 4 )
     {
   printf( "Usage: %s <leaguefile> <input playerfile> <output playerfile> [exclude team]...\n", argv[0] );
   return 0;
     }
     if ( (leagueFile = readLeagueFile( argv[1] )) == ((void *)0) )
     {
          printf( "Cannot load league file." );
          return 1;
     }
     if ( (playerFile = readPlayersFile( argv[2] )) == ((void *)0) )
     {
          printf( "Cannot load players file." );
          free( leagueFile );
          return 1;
     }
     const char **excluded_teams = &(argv[4]);
     const int num_excluded = argc - 4;
     for ( int idx = 0; idx < (((25 * 8) * 2) * 2); ++idx )
     {
   if ( playerFile[idx].last_name[0] == '\0' ) continue;
          int team = idx / 25;
          char *teamName = leagueFile->teams[team].name;
          if ( teamExcluded( teamName, excluded_teams, num_excluded ) ) continue;
          unsigned int pos = playerFile[idx].position[0] / 0x10;
          if ( pos != pos_Pitcher )
          {
               struct batting_s *batting = &(playerFile[idx].filestats.filebatting);
               batting->injury_days[0] = (batting->injury_days[0] > 0) ? batting->injury_days[0] - 1 : 0;
          }
          else
          {
               struct pitching_s *pitching = &(playerFile[idx].filestats.filepitching);
               pitching->injury_days[0] = (pitching->injury_days[0] > 0) ? pitching->injury_days[0] - 1 : 0;
          }
     }
     if ( ! writePlayersFile( argv[3], playerFile ) )
     {
          printf( "Cannot save player changes.\n" );
          free( leagueFile );
          free( playerFile );
          return 1;
     }
     free( leagueFile );
     free( playerFile );
     return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
     struct fileplayer_s *playerFile;
     struct fileleague_s *leagueFile;
     if ( argc < 4 )
     {
   printf( "Usage: %s <leaguefile> <input playerfile> <output playerfile> [exclude team]...\n", argv[0] );
   return 0;
     }
     if ( (leagueFile = readLeagueFile( argv[1] )) == ((void *)0) )
     {
          printf( "Cannot load league file." );
          return 1;
     }
     if ( (playerFile = readPlayersFile( argv[2] )) == ((void *)0) )
     {
          printf( "Cannot load players file." );
          free( leagueFile );
          return 1;
     }
     char **excluded_teams = &(argv[4]);
     int num_excluded = argc - 4;
     for ( int idx = 0; idx < (((25 * 8) * 2) * 2); ++idx )
     {
   if ( playerFile[idx].last_name[0] == '\0' ) continue;
          int team = idx / 25;
          char *teamName = leagueFile->teams[team].name;
          if ( teamExcluded( teamName, excluded_teams, num_excluded ) ) continue;
          unsigned int pos = playerFile[idx].position[0] / 0x10;
          if ( pos != pos_Pitcher )
          {
               struct batting_s *batting = &(playerFile[idx].filestats.filebatting);
               batting->injury_days[0] = (batting->injury_days[0] > 0) ? batting->injury_days[0] - 1 : 0;
          }
          else
          {
               struct pitching_s *pitching = &(playerFile[idx].filestats.filepitching);
               pitching->injury_days[0] = (pitching->injury_days[0] > 0) ? pitching->injury_days[0] - 1 : 0;
          }
     }
     if ( ! writePlayersFile( argv[3], playerFile ) )
     {
          printf( "Cannot save player changes.\n" );
          free( leagueFile );
          free( playerFile );
          return 1;
     }
     free( leagueFile );
     free( playerFile );
     return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct fileplayer_s { char last_name[10]; char first_name[8]; char last_phoen[14]; char first_phoen[12]; unsigned char real_avg[2]; unsigned char year[1]; unsigned char position[1]; union { struct batting_s { unsigned char ratings[4]; unsigned char real_games[1]; unsigned char real_runs[1]; unsigned char real_rbi[1]; unsigned char real_sb[1]; unsigned char real_cs[1]; unsigned char real_sh[1]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_2b[1]; unsigned char vl_3b[1]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[1]; unsigned char real_fa2[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_2b[1]; unsigned char vr_3b[1]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[1]; unsigned char real_err[1]; unsigned char real_po[2]; unsigned char real_as[2]; unsigned char injury_days[1]; unsigned char color[1]; struct acc_bat_stats_s { unsigned char acc_ab[2]; unsigned char acc_hits[2]; unsigned char acc_2b[1]; unsigned char acc_3b[1]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[1]; unsigned char acc_games[1]; unsigned char acc_runs[1]; unsigned char acc_rbi[1]; unsigned char acc_sb[1]; unsigned char acc_err[1]; } action; struct acc_bat_stats_s simulated; } filebatting; struct pitching_s { unsigned char ratings[2]; unsigned char real_wins[1]; unsigned char real_losses[1]; unsigned char real_games[1]; unsigned char real_starts[1]; unsigned char real_cg[1]; unsigned char real_saves[1]; unsigned char real_inn[2]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[2]; unsigned char real_er[1]; unsigned char real_fa[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[2]; unsigned char real_hb[1]; unsigned char real_balk[1]; unsigned char real_ab[1]; unsigned char real_hits[1]; unsigned char real_hr[1]; unsigned char real_sh[1]; unsigned char injury_days[1]; unsigned char color[1]; struct acc_pch_stats_s { unsigned char acc_wins[1]; unsigned char acc_losses[1]; unsigned char acc_starts[1]; unsigned char acc_saves[1]; unsigned char acc_innings[2]; unsigned char acc_hits[2]; unsigned char acc_er[2]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[2]; } action; struct acc_pch_stats_s simulated; } filepitching; } filestats; } *

variable_types: struct fileleague_s { unsigned char header[52]; unsigned char league1[12]; unsigned char league2[12]; unsigned char division1[12]; unsigned char division2[12]; unsigned char division3[12]; unsigned char division4[12]; struct fileteam_s { unsigned char name[12]; unsigned char color[1]; unsigned char wins[1]; unsigned char losses[1]; unsigned char term[1]; } teams[32]; } *

variable_types: idx int

variable_types: team int

variable_types:
teamName
char *

variable_types:
pos
unsigned int

variable_types: struct batting_s { unsigned char ratings[4]; unsigned char real_games[1]; unsigned char real_runs[1]; unsigned char real_rbi[1]; unsigned char real_sb[1]; unsigned char real_cs[1]; unsigned char real_sh[1]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_2b[1]; unsigned char vl_3b[1]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[1]; unsigned char real_fa2[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_2b[1]; unsigned char vr_3b[1]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[1]; unsigned char real_err[1]; unsigned char real_po[2]; unsigned char real_as[2]; unsigned char injury_days[1]; unsigned char color[1]; struct acc_bat_stats_s { unsigned char acc_ab[2]; unsigned char acc_hits[2]; unsigned char acc_2b[1]; unsigned char acc_3b[1]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[1]; unsigned char acc_games[1]; unsigned char acc_runs[1]; unsigned char acc_rbi[1]; unsigned char acc_sb[1]; unsigned char acc_err[1]; } action; struct acc_bat_stats_s simulated; } *

variable_types: struct pitching_s { unsigned char ratings[2]; unsigned char real_wins[1]; unsigned char real_losses[1]; unsigned char real_games[1]; unsigned char real_starts[1]; unsigned char real_cg[1]; unsigned char real_saves[1]; unsigned char real_inn[2]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[2]; unsigned char real_er[1]; unsigned char real_fa[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[2]; unsigned char real_hb[1]; unsigned char real_balk[1]; unsigned char real_ab[1]; unsigned char real_hits[1]; unsigned char real_hr[1]; unsigned char real_sh[1]; unsigned char injury_days[1]; unsigned char color[1]; struct acc_pch_stats_s { unsigned char acc_wins[1]; unsigned char acc_losses[1]; unsigned char acc_starts[1]; unsigned char acc_saves[1]; unsigned char acc_innings[2]; unsigned char acc_hits[2]; unsigned char acc_er[2]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[2]; } action; struct acc_pch_stats_s simulated; } *

user_defined_types: struct fileplayer_s { char last_name[10]; char first_name[8]; char last_phoen[14]; char first_phoen[12]; unsigned char real_avg[2]; unsigned char year[1]; unsigned char position[1]; union { struct batting_s filebatting; struct pitching_s filepitching; } filestats; }

user_defined_types: struct fileleague_s { unsigned char header[52]; unsigned char league1[12]; unsigned char league2[12]; unsigned char division1[12]; unsigned char division2[12]; unsigned char division3[12]; unsigned char division4[12]; struct fileteam_s teams[32]; }

user_defined_types: struct batting_s { unsigned char ratings[4]; unsigned char real_games[1]; unsigned char real_runs[1]; unsigned char real_rbi[1]; unsigned char real_sb[1]; unsigned char real_cs[1]; unsigned char real_sh[1]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_2b[1]; unsigned char vl_3b[1]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[1]; unsigned char real_fa2[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_2b[1]; unsigned char vr_3b[1]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[1]; unsigned char real_err[1]; unsigned char real_po[2]; unsigned char real_as[2]; unsigned char injury_days[1]; unsigned char color[1]; struct acc_bat_stats_s action; struct acc_bat_stats_s simulated; }

user_defined_types: struct pitching_s { unsigned char ratings[2]; unsigned char real_wins[1]; unsigned char real_losses[1]; unsigned char real_games[1]; unsigned char real_starts[1]; unsigned char real_cg[1]; unsigned char real_saves[1]; unsigned char real_inn[2]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[2]; unsigned char real_er[1]; unsigned char real_fa[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[2]; unsigned char real_hb[1]; unsigned char real_balk[1]; unsigned char real_ab[1]; unsigned char real_hits[1]; unsigned char real_hr[1]; unsigned char real_sh[1]; unsigned char injury_days[1]; unsigned char color[1]; struct acc_pch_stats_s action; struct acc_pch_stats_s simulated; }


decompiled_code:
void __fastcall free_batter(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 5);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 6);
if ( v3 )
free(v3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 5);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 6);
if ( v3 )
free(v3);
free(ptr);
}
}

original_code:
static void free_batter( batter_s *batter )
{
     if ( batter == ((void *)0) ) return;
     if ( batter->stats != ((void *)0) ) free( batter->stats );
     if ( batter->accolades != ((void *)0) ) free( batter->accolades );
     free( batter );
}

canonical_original_code:
static void free_batter(struct batter_s *batter)
{
     if ( batter == ((void *)0) ) return;
     if ( batter->stats != ((void *)0) ) free( batter->stats );
     if ( batter->accolades != ((void *)0) ) free( batter->accolades );
     free( batter );
}

variable_types: struct batter_s { int player_id; int power; int hit_n_run; int bunt; int running; int range; int arm; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } primary_position; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } secondary_position; struct batter_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; } *stats; struct batter_accolade_s { int player_id; int season; enum batting_accolade_e { bacc_None=0, bacc_Batter_of_the_Year=1, bacc_Global_Batter_of_the_Year=2, bacc_World_Batter_of_the_Year=3, bacc_Atlantic_Batter_of_the_Year=4, bacc_North_Batter_of_the_Year=5, bacc_Pacific_Batter_of_the_Year=6, bacc_South_Batter_of_the_Year=7, bacc_Best_Batting_Average=8, bacc_Most_Doubles=9, bacc_Most_Triples=10, bacc_Most_Home_Runs=11, bacc_Most_Runs=12, bacc_Most_Runs_Batted_In=13, bacc_Most_Stolen_Bases=14, bacc_Most_Walks=15, bacc_Best_Slugging_Average=16, bacc_Best_On_Base_Percentage=17, bacc_Best_Strike_Out_Average=18, bacc_Best_Runs_per_Game=19, bacc_Batting_Rookie_of_the_Year=20 } accolade; } *accolades; } *

user_defined_types: struct batter_s { int player_id; int power; int hit_n_run; int bunt; int running; int range; int arm; enum position_e primary_position; enum position_e secondary_position; struct batter_stats_s *stats; struct batter_accolade_s *accolades; }

user_defined_types: struct batter_stats_s { int player_id; int season; enum season_phase_e season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; }

user_defined_types: struct batter_accolade_s { int player_id; int season; enum batting_accolade_e accolade; }


decompiled_code:
void __fastcall free_pitcher(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 4);
if ( v3 )
free(v3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 4);
if ( v3 )
free(v3);
free(ptr);
}
}

original_code:
static void free_pitcher( pitcher_s *pitcher )
{
     if ( pitcher == ((void *)0) ) return;
     if ( pitcher->stats != ((void *)0) ) free( pitcher->stats );
     if ( pitcher->accolades != ((void *)0) ) free( pitcher->accolades );
     free( pitcher );
}

canonical_original_code:
static void free_pitcher(struct pitcher_s *pitcher)
{
     if ( pitcher == ((void *)0) ) return;
     if ( pitcher->stats != ((void *)0) ) free( pitcher->stats );
     if ( pitcher->accolades != ((void *)0) ) free( pitcher->accolades );
     free( pitcher );
}

variable_types: struct pitcher_s { int player_id; int speed; int control; int bunt; int fatigue; struct pitcher_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int games; int saves; struct innings_s { int innings; int outs; } innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } *stats; struct pitcher_accolade_s { int player_id; int season; enum pitching_accolade_e { pacc_None=0, pacc_Pitcher_of_the_Year=1, pacc_Global_Pitcher_of_the_Year=2, pacc_World_Pitcher_of_the_Year=3, pacc_Atlantic_Pitcher_of_the_Year=4, pacc_North_Pitcher_of_the_Year=5, pacc_Pacific_Pitcher_of_the_Year=6, pacc_South_Pitcher_of_the_Year=7, pacc_Most_Wins=8, pacc_Best_Win_Loss_Ratio=9, pacc_Best_Win_Percentage=10, pacc_Best_Earned_Run_Average=11, pacc_Best_vs_Batting_Average=12, pacc_Most_Saves=13, pacc_Most_Strike_Outs=14, pacc_Most_Innings_per_Game=15, pacc_Best_Walks_Hits_Per_Inning=16, pacc_Most_Strike_Outs_per_Nine=17, pacc_Best_Home_Runs_per_Nine=18, pacc_Best_Efficiency=19, pacc_Pitching_Rookie_of_the_Year=20 } accolade; } *accolades; } *

user_defined_types: struct pitcher_s { int player_id; int speed; int control; int bunt; int fatigue; struct pitcher_stats_s *stats; struct pitcher_accolade_s *accolades; }

user_defined_types: struct pitcher_stats_s { int player_id; int season; enum season_phase_e season_phase; int wins; int losses; int games; int saves; struct innings_s innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; }

user_defined_types: struct pitcher_accolade_s { int player_id; int season; enum pitching_accolade_e accolade; }


decompiled_code:
void __fastcall free_player(void *ptr)
{
int v1; // eax
void *v3; // rdi

v1 = *((_DWORD *)ptr + 24);
if ( v1 == 2 )
{
free_batter(*((void **)ptr + 15));
if ( *((_DWORD *)ptr + 24) != 1 )
goto LABEL_3;
}
else if ( v1 != 1 )
{
goto LABEL_3;
}
free_pitcher(*((void **)ptr + 15));
LABEL_3:
v3 = (void *)*((_QWORD *)ptr + 14);
if ( v3 )
free(v3);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
int v1; // eax
void *v3; // rdi

v1 = *((_DWORD *)ptr + 24);
if ( v1 == 2 )
{
func0(*((void **)ptr + 15));
if ( *((_DWORD *)ptr + 24) != 1 )
goto LABEL_3;
}
else if ( v1 != 1 )
{
goto LABEL_3;
}
func1(*((void **)ptr + 15));
LABEL_3:
v3 = (void *)*((_QWORD *)ptr + 14);
if ( v3 )
free(v3);
free(ptr);
}

original_code:
void free_player( player_s *player )
{
     if ( player->player_type == pt_Batter ) free_batter( player->details.batting );
     if ( player->player_type == pt_Pitcher ) free_pitcher( player->details.pitching );
     if ( player->accolades != ((void *)0) ) free( player->accolades );
     free( player );
}

canonical_original_code:
void free_player(struct player_s *player)
{
     if ( player->player_type == pt_Batter ) free_batter( player->details.batting );
     if ( player->player_type == pt_Pitcher ) free_pitcher( player->details.pitching );
     if ( player->accolades != ((void *)0) ) free( player->accolades );
     free( player );
}

variable_types: struct player_s { int player_id; char first_name[-1]; char last_name[-1]; char first_phoenetic[-1]; char last_phoenetic[-1]; enum skin_tone_e { st_None=0, st_Light=1, st_Dark=2 } skin_tone; enum handedness_e { hnd_None=0, hnd_Right=1, hnd_Left=2, hnd_Switch=3 } handedness; enum playertype_e { pt_None=0, pt_Pitcher=1, pt_Batter=2 } player_type; int rookie_season; int longevity; struct player_accolade_s { int player_id; int season; enum accolade_e { acc_None=0, acc_All_Star=1, acc_World_Title=2, acc_League_Title=3, acc_Division_Title=4, acc_Best_Record=5, acc_World_Series_MVP=6, acc_All_Star_Champion=7, acc_All_Star_MVP=8 } accolade; } *accolades; union { struct pitcher_s { int player_id; int speed; int control; int bunt; int fatigue; struct pitcher_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int games; int saves; struct innings_s { int innings; int outs; } innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } *stats; struct pitcher_accolade_s { int player_id; int season; enum pitching_accolade_e { pacc_None=0, pacc_Pitcher_of_the_Year=1, pacc_Global_Pitcher_of_the_Year=2, pacc_World_Pitcher_of_the_Year=3, pacc_Atlantic_Pitcher_of_the_Year=4, pacc_North_Pitcher_of_the_Year=5, pacc_Pacific_Pitcher_of_the_Year=6, pacc_South_Pitcher_of_the_Year=7, pacc_Most_Wins=8, pacc_Best_Win_Loss_Ratio=9, pacc_Best_Win_Percentage=10, pacc_Best_Earned_Run_Average=11, pacc_Best_vs_Batting_Average=12, pacc_Most_Saves=13, pacc_Most_Strike_Outs=14, pacc_Most_Innings_per_Game=15, pacc_Best_Walks_Hits_Per_Inning=16, pacc_Most_Strike_Outs_per_Nine=17, pacc_Best_Home_Runs_per_Nine=18, pacc_Best_Efficiency=19, pacc_Pitching_Rookie_of_the_Year=20 } accolade; } *accolades; } *pitching; struct batter_s { int player_id; int power; int hit_n_run; int bunt; int running; int range; int arm; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } primary_position; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } secondary_position; struct batter_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; } *stats; struct batter_accolade_s { int player_id; int season; enum batting_accolade_e { bacc_None=0, bacc_Batter_of_the_Year=1, bacc_Global_Batter_of_the_Year=2, bacc_World_Batter_of_the_Year=3, bacc_Atlantic_Batter_of_the_Year=4, bacc_North_Batter_of_the_Year=5, bacc_Pacific_Batter_of_the_Year=6, bacc_South_Batter_of_the_Year=7, bacc_Best_Batting_Average=8, bacc_Most_Doubles=9, bacc_Most_Triples=10, bacc_Most_Home_Runs=11, bacc_Most_Runs=12, bacc_Most_Runs_Batted_In=13, bacc_Most_Stolen_Bases=14, bacc_Most_Walks=15, bacc_Best_Slugging_Average=16, bacc_Best_On_Base_Percentage=17, bacc_Best_Strike_Out_Average=18, bacc_Best_Runs_per_Game=19, bacc_Batting_Rookie_of_the_Year=20 } accolade; } *accolades; } *batting; } details; } *

user_defined_types: struct player_s { int player_id; char first_name[-1]; char last_name[-1]; char first_phoenetic[-1]; char last_phoenetic[-1]; enum skin_tone_e skin_tone; enum handedness_e handedness; enum playertype_e player_type; int rookie_season; int longevity; struct player_accolade_s *accolades; union { struct pitcher_s *pitching; struct batter_s *batting; } details; }

user_defined_types: struct player_accolade_s { int player_id; int season; enum accolade_e accolade; }


clearErrorMessage

decompiled_code:
void clearErrorMessage()
{
LOBYTE(error_message) = 0;
}

canonical_decompiled_code:
void func0()
{
LOBYTE(error_message) = 0;
}


getGenPlayerIdsError

decompiled_code:
__int128 *getGenPlayerIdsError()
{
return &error_message;
}

canonical_decompiled_code:
__int128 *func1()
{
return &error_message;
}

original_code:
char *getGenPlayerIdsError( void )
{
     return error_message;
}

canonical_original_code:
char *getGenPlayerIdsError()
{
     return error_message;
}


genPlayerIds

decompiled_code:
__int64 __fastcall genPlayerIds(__int64 a1)
{
__int64 v1; // r13
unsigned int v2; // ebp
__int64 v3; // rbx
__int64 v4; // rdi
unsigned __int8 v5; // al
__int64 result; // rax

v1 = a1 + 89684;
v2 = 1;
v3 = a1 + 84;
clearErrorMessage();
do
{
if ( *(_BYTE *)(v3 - 84) )
{
if ( (unsigned int)word2int(v3) )
{
strcpy((char *)&qword_180, " a number!");
result = 0LL;
error_message = (__int128)_mm_load_si128((const __m128i *)&LC0);
xmmword_170 = (__int128)_mm_load_si128((const __m128i *)&LC1);
return result;
}
if ( (unsigned int)byte2int(v3 + 2) )
{
strcpy((char *)&qword_180, "a number!");
error_message = (__int128)_mm_load_si128((const __m128i *)&LC2);
result = 0LL;
xmmword_170 = (__int128)_mm_load_si128((const __m128i *)&LC3);
return result;
}
int2word(v3, v2);
v4 = v2++;
v5 = calcChecksum(v4);
int2byte(v3 + 2, v5);
}
v3 += 112LL;
}
while ( v3 != v1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // r13
unsigned int v2; // ebp
__int64 v3; // rbx
__int64 v4; // rdi
unsigned __int8 v5; // al
__int64 result; // rax

v1 = a1 + 89684;
v2 = 1;
v3 = a1 + 84;
func0();
do
{
if ( *(_BYTE *)(v3 - 84) )
{
if ( (unsigned int)word2int(v3) )
{
strcpy((char *)&qword_180, " a number!");
result = 0LL;
error_message = (__int128)_mm_load_si128((const __m128i *)&LC0);
xmmword_170 = (__int128)_mm_load_si128((const __m128i *)&LC1);
return result;
}
if ( (unsigned int)byte2int(v3 + 2) )
{
strcpy((char *)&qword_180, "a number!");
error_message = (__int128)_mm_load_si128((const __m128i *)&LC2);
result = 0LL;
xmmword_170 = (__int128)_mm_load_si128((const __m128i *)&LC3);
return result;
}
int2word(v3, v2);
v4 = v2++;
v5 = calcChecksum(v4);
int2byte(v3 + 2, v5);
}
v3 += 112LL;
}
while ( v3 != v1 );
return 1LL;
}

original_code:
boolean_e genPlayerIds( fileplayer_s *players_file )
{
     clearErrorMessage();
     for ( int player_id = 1, idx = 0; idx < (((25 * 8) * 2) * 2); ++idx )
     {
          if ( (players_file[idx].last_name)[0] == '\0' ) continue;
          acc_player_id_s *id_info = &(players_file[idx].acc_stats.action.id_info);
          if ( word2int( id_info->player_id ) != 0 )
          {
               sprintf( error_message, "Player ID field already contains a number!" );
               return bl_False;
          }
          if ( byte2int( id_info->checksum ) != 0 )
          {
               sprintf( error_message, "Checksum field already contains a number!" );
               return bl_False;
          }
          int2word( id_info->player_id, player_id );
          int2byte( id_info->checksum, calcChecksum( player_id ) );
          player_id++;
     }
     return bl_True;
}

canonical_original_code:
enum boolean_e genPlayerIds(struct fileplayer_s *players_file)
{
     clearErrorMessage();
     for ( int player_id = 1; int idx = 0; idx < (((25 * 8) * 2) * 2); ++idx )
     {
          if ( (players_file[idx].last_name)[0] == '\0' ) continue;
          struct acc_player_id_s *id_info = &(players_file[idx].acc_stats.action.id_info);
          if ( word2int( id_info->player_id ) != 0 )
          {
               sprintf( error_message, "Player ID field already contains a number!" );
               return bl_False;
          }
          if ( byte2int( id_info->checksum ) != 0 )
          {
               sprintf( error_message, "Checksum field already contains a number!" );
               return bl_False;
          }
          int2word( id_info->player_id, player_id );
          int2byte( id_info->checksum, calcChecksum( player_id ) );
          player_id++;
     }
     return bl_True;
}

variable_types: struct fileplayer_s { char last_name[10]; char first_name[8]; char last_phoen[14]; char first_phoen[12]; unsigned char real_avg[2]; unsigned char year[1]; unsigned char position[1]; union { struct filebatting_s { unsigned char ratings[4]; unsigned char real_games[1]; unsigned char real_runs[1]; unsigned char real_rbi[1]; unsigned char real_sb[1]; unsigned char real_cs[1]; unsigned char real_sh[1]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_2b[1]; unsigned char vl_3b[1]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[1]; unsigned char real_fa2[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_2b[1]; unsigned char vr_3b[1]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[1]; unsigned char real_err[1]; unsigned char real_po[2]; unsigned char real_as[2]; unsigned char injury_days[1]; unsigned char color[1]; } filebatting; struct filepitching_s { unsigned char ratings[2]; unsigned char real_wins[1]; unsigned char real_losses[1]; unsigned char real_games[1]; unsigned char real_starts[1]; unsigned char real_cg[1]; unsigned char real_saves[1]; unsigned char real_inn[2]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[2]; unsigned char real_er[1]; unsigned char real_fa[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[2]; unsigned char real_hb[1]; unsigned char real_balk[1]; unsigned char real_ab[1]; unsigned char real_hits[1]; unsigned char real_hr[1]; unsigned char real_sh[1]; unsigned char injury_days[1]; unsigned char color[1]; } filepitching; } filestats; struct acc_stats_s { union acc_stats_u { struct acc_pch_stats_s { unsigned char acc_wins[1]; unsigned char acc_losses[1]; unsigned char acc_starts[1]; unsigned char acc_saves[1]; unsigned char acc_innings[2]; unsigned char acc_hits[2]; unsigned char acc_er[2]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[2]; } pitching; struct acc_bat_stats_s { unsigned char acc_ab[2]; unsigned char acc_hits[2]; unsigned char acc_2b[1]; unsigned char acc_3b[1]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[1]; unsigned char acc_games[1]; unsigned char acc_runs[1]; unsigned char acc_rbi[1]; unsigned char acc_sb[1]; unsigned char acc_err[1]; } batting; struct acc_player_id_s { unsigned char player_id[2]; unsigned char checksum[1]; unsigned char filler[11]; } id_info; } action; union acc_stats_u simulated; } acc_stats; } *


clearErrorMessage

decompiled_code:
void clearErrorMessage()
{
error_message[0] = 0;
}

canonical_decompiled_code:
void func0()
{
error_message[0] = 0;
}


emptyGame

decompiled_code:
_BOOL8 __fastcall emptyGame(_BYTE *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( !*a1 )
result = a1[24] == 0;
return result;
}

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

result = 0LL;
if ( !*a1 )
result = a1[24] == 0;
return result;
}

original_code:
static boolean_e emptyGame( const schedule_game_s *game )
{
     if ( (game->road.name)[0] == '\0' && (game->home.name)[0] == '\0' ) return bl_True;
     return bl_False;
}

canonical_original_code:
static enum boolean_e emptyGame(struct schedule_game_s *game)
{
     if ( (game->road.name)[0] == '\0' && (game->home.name)[0] == '\0' ) return bl_True;
     return bl_False;
}

variable_types: struct schedule_game_s { struct schedule_team_s { char name[20]; int score; } road; struct schedule_team_s home; enum boolean_e { bl_False=0, bl_True=1 } played; } *

user_defined_types: struct schedule_game_s { struct schedule_team_s road; struct schedule_team_s home; enum boolean_e played; }


validGame

decompiled_code:
_BOOL8 __fastcall validGame(_BYTE *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 )
result = a1[24] != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_BYTE *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 )
result = a1[24] != 0;
return result;
}

original_code:
static boolean_e validGame( const schedule_game_s *game )
{
     if ( (game->road.name)[0] == '\0' || (game->home.name)[0] == '\0' ) return bl_False;
     return bl_True;
}

canonical_original_code:
static enum boolean_e validGame(struct schedule_game_s *game)
{
     if ( (game->road.name)[0] == '\0' || (game->home.name)[0] == '\0' ) return bl_False;
     return bl_True;
}

user_defined_types: enum boolean_e { bl_False=0, bl_True=1 }

user_defined_types: struct schedule_team_s { char name[20]; int score; }


readFile

decompiled_code:
void *__fastcall readFile(char *file, size_t nbytes)
{
void *v3; // r12
int v4; // eax
int v5; // ebp
void *v7; // rdi
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax

clearErrorMessage();
v3 = malloc(nbytes);
if ( !v3 )
{
sprintf(error_message, "Cannot allocate memory for reading file <%s>.", file);
return v3;
}
v4 = open(file, 0);
v5 = v4;
if ( v4 < 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
sprintf(error_message, "Cannot open file <%s>: %s", file, v11);
}
else
{
if ( read(v4, v3, nbytes) < nbytes )
{
sprintf(error_message, "Unexpected end of file <%s>.", file);
v7 = v3;
v3 = 0LL;
free(v7);
if ( close(v5) < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
sprintf(error_message, "Error closing file <%s>: %s", file, v9);
}
return v3;
}
if ( close(v5) >= 0 )
return v3;
v12 = _errno_location();
v13 = strerror(*v12);
sprintf(error_message, "Error closing file <%s>: %s", file, v13);
}
free(v3);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func3(char *file, size_t nbytes)
{
void *v3; // r12
int v4; // eax
int v5; // ebp
void *v7; // rdi
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax

func0();
v3 = malloc(nbytes);
if ( !v3 )
{
sprintf(error_message, "Cannot allocate memory for reading file <%s>.", file);
return v3;
}
v4 = open(file, 0);
v5 = v4;
if ( v4 < 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
sprintf(error_message, "Cannot open file <%s>: %s", file, v11);
}
else
{
if ( read(v4, v3, nbytes) < nbytes )
{
sprintf(error_message, "Unexpected end of file <%s>.", file);
v7 = v3;
v3 = 0LL;
free(v7);
if ( close(v5) < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
sprintf(error_message, "Error closing file <%s>: %s", file, v9);
}
return v3;
}
if ( close(v5) >= 0 )
return v3;
v12 = _errno_location();
v13 = strerror(*v12);
sprintf(error_message, "Error closing file <%s>: %s", file, v13);
}
free(v3);
return 0LL;
}

original_code:
static void *readFile( const char *filename, const size_t filesize )
{
     void *filedata;
     int fd;
     clearErrorMessage();
     if ( (filedata = malloc( filesize )) == ((void *)0) )
     {
   sprintf( error_message, "Cannot allocate memory for reading file <%s>.", filename );
   return ((void *)0);
     }
     if ( (fd = open( filename, 00 )) < 0 )
     {
   sprintf( error_message, "Cannot open file <%s>: %s", filename, strerror((*__errno_location ())) );
   free( filedata );
   return ((void *)0);
     }
     if ( read( fd, filedata, filesize ) < filesize )
     {
   sprintf( error_message, "Unexpected end of file <%s>.", filename );
   free( filedata );
   if ( close( fd ) < 0 )
   {
        sprintf( error_message, "Error closing file <%s>: %s", filename, strerror((*__errno_location ())) );
   }
   return ((void *)0);
     }
     if ( close( fd ) < 0 )
     {
   sprintf( error_message, "Error closing file <%s>: %s", filename, strerror((*__errno_location ())) );
          free( filedata );
   return ((void *)0);
     }
     return filedata;
}

canonical_original_code:
static void *readFile(char *filename, unsigned long filesize)
{
     void *filedata;
     int fd;
     clearErrorMessage();
     if ( (filedata = malloc( filesize )) == ((void *)0) )
     {
   sprintf( error_message, "Cannot allocate memory for reading file <%s>.", filename );
   return ((void *)0);
     }
     if ( (fd = open( filename, 00 )) < 0 )
     {
   sprintf( error_message, "Cannot open file <%s>: %s", filename, strerror((*__errno_location ())) );
   free( filedata );
   return ((void *)0);
     }
     if ( read( fd, filedata, filesize ) < filesize )
     {
   sprintf( error_message, "Unexpected end of file <%s>.", filename );
   free( filedata );
   if ( close( fd ) < 0 )
   {
        sprintf( error_message, "Error closing file <%s>: %s", filename, strerror((*__errno_location ())) );
   }
   return ((void *)0);
     }
     if ( close( fd ) < 0 )
     {
   sprintf( error_message, "Error closing file <%s>: %s", filename, strerror((*__errno_location ())) );
          free( filedata );
   return ((void *)0);
     }
     return filedata;
}

variable_types:
filename
char *

variable_types:
filesize
unsigned long

variable_types:
filedata
void *

variable_types: fd int

return_type: void *


writeFile

decompiled_code:
__int64 __fastcall writeFile(const char *a1, const void *a2, size_t a3)
{
int v4; // eax
int v5; // ebp
int v6; // eax
unsigned int v7; // er13
int *v9; // rax
char *v10; // rax
int *v11; // rbx
char *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax

clearErrorMessage();
v4 = creat(a1, 0x180u);
if ( v4 >= 0 )
{
v5 = v4;
v6 = write(v4, a2, a3);
if ( v6 < a3 )
{
if ( v6 < 0 )
{
v7 = 0;
v11 = _errno_location();
v12 = strerror(*v11);
sprintf(error_message, "Error writing to output file: %s", v12);
if ( close(v5) < 0 )
{
v13 = strerror(*v11);
sprintf(error_message, "Error closing output file: %s", v13);
}
return v7;
}
strcpy((char *)&word_950, "e!");
*(__m128i *)error_message = _mm_load_si128((const __m128i *)&LC6);
xmmword_930 = (__int128)_mm_load_si128((const __m128i *)&LC7);
xmmword_940 = (__int128)_mm_load_si128((const __m128i *)&LC8);
}
v7 = 1;
if ( close(v5) < 0 )
{
v14 = _errno_location();
v7 = 0;
v15 = strerror(*v14);
sprintf(error_message, "Error closing file <%s>: %s", a1, v15);
}
return v7;
}
v9 = _errno_location();
v10 = strerror(*v9);
sprintf(error_message, "Cannot open file <%s>: %s", a1, v10);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, const void *a2, size_t a3)
{
int v4; // eax
int v5; // ebp
int v6; // eax
unsigned int v7; // er13
int *v9; // rax
char *v10; // rax
int *v11; // rbx
char *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax

func0();
v4 = creat(a1, 0x180u);
if ( v4 >= 0 )
{
v5 = v4;
v6 = write(v4, a2, a3);
if ( v6 < a3 )
{
if ( v6 < 0 )
{
v7 = 0;
v11 = _errno_location();
v12 = strerror(*v11);
sprintf(error_message, "Error writing to output file: %s", v12);
if ( close(v5) < 0 )
{
v13 = strerror(*v11);
sprintf(error_message, "Error closing output file: %s", v13);
}
return v7;
}
strcpy((char *)&word_950, "e!");
*(__m128i *)error_message = _mm_load_si128((const __m128i *)&LC6);
xmmword_930 = (__int128)_mm_load_si128((const __m128i *)&LC7);
xmmword_940 = (__int128)_mm_load_si128((const __m128i *)&LC8);
}
v7 = 1;
if ( close(v5) < 0 )
{
v14 = _errno_location();
v7 = 0;
v15 = strerror(*v14);
sprintf(error_message, "Error closing file <%s>: %s", a1, v15);
}
return v7;
}
v9 = _errno_location();
v10 = strerror(*v9);
sprintf(error_message, "Cannot open file <%s>: %s", a1, v10);
return 0LL;
}

original_code:
static boolean_e writeFile( const char *filename, const void *filedata, const size_t filesize )
{
     int bytes_written;
     int fd;
     clearErrorMessage();
     if ( (fd = creat( filename, 0400 | 0200 )) < 0 )
     {
   sprintf( error_message, "Cannot open file <%s>: %s", filename, strerror((*__errno_location ())) );
   return bl_False;
     }
     if ( (bytes_written = write( fd, filedata, filesize )) < filesize )
     {
          if ( bytes_written < 0 )
          {
               sprintf( error_message, "Error writing to output file: %s", strerror( (*__errno_location ()) ) );
               if ( close( fd ) < 0 )
               {
                    sprintf( error_message, "Error closing output file: %s", strerror((*__errno_location ())) );
               }
               return bl_False;
          }
          sprintf( error_message, "Warning: incomplete buffer written to output file!" );
     }
     if ( close( fd ) < 0 )
     {
   sprintf( error_message, "Error closing file <%s>: %s", filename, strerror((*__errno_location ())) );
   return bl_False;
     }
     return bl_True;
}

canonical_original_code:
static enum boolean_e writeFile(char *filename, void *filedata, unsigned long filesize)
{
     int bytes_written;
     int fd;
     clearErrorMessage();
     if ( (fd = creat( filename, 0400 | 0200 )) < 0 )
     {
   sprintf( error_message, "Cannot open file <%s>: %s", filename, strerror((*__errno_location ())) );
   return bl_False;
     }
     if ( (bytes_written = write( fd, filedata, filesize )) < filesize )
     {
          if ( bytes_written < 0 )
          {
               sprintf( error_message, "Error writing to output file: %s", strerror( (*__errno_location ()) ) );
               if ( close( fd ) < 0 )
               {
                    sprintf( error_message, "Error closing output file: %s", strerror((*__errno_location ())) );
               }
               return bl_False;
          }
          sprintf( error_message, "Warning: incomplete buffer written to output file!" );
     }
     if ( close( fd ) < 0 )
     {
   sprintf( error_message, "Error closing file <%s>: %s", filename, strerror((*__errno_location ())) );
   return bl_False;
     }
     return bl_True;
}


cleanupLists

decompiled_code:
__int64 __fastcall cleanupLists(__int64 a1, __int64 a2, __int64 a3)
{
((void (*)(void))clear_data_list)();
clear_data_list(a2);
return clear_data_list(a3);
}

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

original_code:
static void cleanupLists( data_list_s *days, data_list_s *road, data_list_s *home )
{
     clear_data_list( days );
     clear_data_list( road );
     clear_data_list( home );
}

canonical_original_code:
static void cleanupLists(struct data_list_s *days, struct data_list_s *road, struct data_list_s *home)
{
     clear_data_list( days );
     clear_data_list( road );
     clear_data_list( home );
}

variable_types: struct data_list_s { int __max; int count; void *data; } *

variable_types:
road
struct data_list_s *

variable_types:
home
struct data_list_s *


loadGames

decompiled_code:
_BOOL8 __fastcall loadGames(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
int v4; // eax
int v5; // er13
const char *v6; // r12
const char *v7; // rbp
int v8; // ebx
_BOOL4 v9; // ebx
char dest[16]; // [rsp+10h] [rbp-78h] BYREF
char v12[16]; // [rsp+20h] [rbp-68h] BYREF
__int128 v13; // [rsp+30h] [rbp-58h]
int v14; // [rsp+40h] [rbp-48h]

v4 = *(_DWORD *)(a2 + 4);
if ( v4 == *(_DWORD *)(a3 + 4) )
{
v5 = v4 % 2;
if ( v4 % 2 == 1 )
{
if ( v4 > 1 )
{
v6 = (const char *)(*(_QWORD *)(a2 + 8) + 30LL);
v7 = (const char *)(*(_QWORD *)(a3 + 8) + 30LL);
do
{
*(_OWORD *)dest = 0LL;
*(_OWORD *)v12 = 0LL;
v13 = 0LL;
v14 = 0;
strncpy(dest, v6, 0x14uLL);
strncpy(&v12[8], v7, 0x14uLL);
v8 = atoi(v6 + 30);
*(_DWORD *)&v12[4] = v8;
HIDWORD(v13) = atoi(v7 + 30);
v14 = HIDWORD(v13) + v8 > 0;
v9 = emptyGame(dest);
if ( !v9 )
{
if ( !validGame(dest) )
{
clear_data_list(a1);
return v9;
}
if ( (int)add_to_data_list(a1, dest, 52LL, 20LL) < 0 )
return v9;
}
v5 += 2;
v6 += 60;
v7 += 60;
}
while ( *(_DWORD *)(a2 + 4) > v5 );
}
v14 = -1;
*(_OWORD *)dest = 0LL;
*(_OWORD *)v12 = 0LL;
v13 = 0LL;
v9 = (int)add_to_data_list(a1, dest, 52LL, 20LL) >= 0;
}
else
{
sprintf(error_message, "Incorrect Number of Fields for home/road on day %d", a4);
v9 = 0;
}
}
else
{
sprintf(error_message, "Field Count Mismatch between road/home lines on day %d", a4);
v9 = 0;
}
return v9;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
int v4; // eax
int v5; // er13
const char *v6; // r12
const char *v7; // rbp
int v8; // ebx
_BOOL4 v9; // ebx
char dest[16]; // [rsp+10h] [rbp-78h] BYREF
char v12[16]; // [rsp+20h] [rbp-68h] BYREF
__int128 v13; // [rsp+30h] [rbp-58h]
int v14; // [rsp+40h] [rbp-48h]

v4 = *(_DWORD *)(a2 + 4);
if ( v4 == *(_DWORD *)(a3 + 4) )
{
v5 = v4 % 2;
if ( v4 % 2 == 1 )
{
if ( v4 > 1 )
{
v6 = (const char *)(*(_QWORD *)(a2 + 8) + 30LL);
v7 = (const char *)(*(_QWORD *)(a3 + 8) + 30LL);
do
{
*(_OWORD *)dest = 0LL;
*(_OWORD *)v12 = 0LL;
v13 = 0LL;
v14 = 0;
strncpy(dest, v6, 0x14uLL);
strncpy(&v12[8], v7, 0x14uLL);
v8 = atoi(v6 + 30);
*(_DWORD *)&v12[4] = v8;
HIDWORD(v13) = atoi(v7 + 30);
v14 = HIDWORD(v13) + v8 > 0;
v9 = func1(dest);
if ( !v9 )
{
if ( !func2(dest) )
{
clear_data_list(a1);
return v9;
}
if ( (int)add_to_data_list(a1, dest, 52LL, 20LL) < 0 )
return v9;
}
v5 += 2;
v6 += 60;
v7 += 60;
}
while ( *(_DWORD *)(a2 + 4) > v5 );
}
v14 = -1;
*(_OWORD *)dest = 0LL;
*(_OWORD *)v12 = 0LL;
v13 = 0LL;
v9 = (int)add_to_data_list(a1, dest, 52LL, 20LL) >= 0;
}
else
{
sprintf(error_message, "Incorrect Number of Fields for home/road on day %d", a4);
v9 = 0;
}
}
else
{
sprintf(error_message, "Field Count Mismatch between road/home lines on day %d", a4);
v9 = 0;
}
return v9;
}

original_code:
static boolean_e loadGames( data_list_s *games, const data_list_s *road, const data_list_s *home, const int day )
{
     if ( road->count != home->count )
     {
          sprintf( error_message, "Field Count Mismatch between road/home lines on day %d", day );
          return bl_False;
     }
     if ( home->count % 2 != 1 )
     {
          sprintf( error_message, "Incorrect Number of Fields for home/road on day %d", day );
          return bl_False;
     }
     const data_field_s *road_fields = road->data;
     const data_field_s *home_fields = home->data;
     for ( int i = 1; i < road->count; i += 2 )
     {
          schedule_game_s game = { 0 };
          strncpy( game.road.name, road_fields[i].value, sizeof(game.road.name) );
          strncpy( game.home.name, home_fields[i].value, sizeof(game.home.name) );
          game.road.score = atoi( road_fields[i + 1].value );
          game.home.score = atoi( home_fields[i + 1].value );
          game.played = (game.road.score + game.home.score > 0);
          if ( emptyGame( &game ) ) continue;
          if ( ! validGame( &game ) )
          {
               clear_data_list( games );
               return bl_False;
          }
          if ( add_to_data_list( games, &game, sizeof(schedule_game_s), 20 ) < 0 ) return bl_False;
     }
     schedule_game_s game_sentinel = { 0 };
                     game_sentinel.played = -1;
     if ( add_to_data_list( games, &game_sentinel, sizeof(schedule_game_s), 20 ) < 0 ) return bl_False;
     return bl_True;
}

canonical_original_code:
static enum boolean_e loadGames(struct data_list_s *games, struct data_list_s *road, struct data_list_s *home, int day)
{
     if ( road->count != home->count )
     {
          sprintf( error_message, "Field Count Mismatch between road/home lines on day %d", day );
          return bl_False;
     }
     if ( home->count % 2 != 1 )
     {
          sprintf( error_message, "Incorrect Number of Fields for home/road on day %d", day );
          return bl_False;
     }
     struct data_field_s *road_fields = road->data;
     struct data_field_s *home_fields = home->data;
     for ( int i = 1; i < road->count; i += 2 )
     {
          struct schedule_game_s game = { 0 };
          strncpy( game.road.name, road_fields[i].value, sizeof(game.road.name) );
          strncpy( game.home.name, home_fields[i].value, sizeof(game.home.name) );
          game.road.score = atoi( road_fields[i + 1].value );
          game.home.score = atoi( home_fields[i + 1].value );
          game.played = (game.road.score + game.home.score > 0);
          if ( emptyGame( &game ) ) continue;
          if ( ! validGame( &game ) )
          {
               clear_data_list( games );
               return bl_False;
          }
          if ( add_to_data_list( games, &game, sizeof(schedule_game_s), 20 ) < 0 ) return bl_False;
     }
     struct schedule_game_s game_sentinel = { 0 };
                     game_sentinel.played = -1;
     if ( add_to_data_list( games, &game_sentinel, sizeof(schedule_game_s), 20 ) < 0 ) return bl_False;
     return bl_True;
}

variable_types: day int

variable_types: struct data_field_s { char value[30]; } *

variable_types: i int

variable_types: struct schedule_game_s { struct schedule_team_s { char name[20]; int score; } road; struct schedule_team_s home; enum boolean_e { bl_False=0, bl_True=1 } played; }

user_defined_types: struct data_list_s { int __max; int count; void *data; }


getFileUtilsError

decompiled_code:
char *getFileUtilsError()
{
return error_message;
}

canonical_decompiled_code:
char *func7()
{
return error_message;
}

original_code:
char *getFileUtilsError( void )
{
     return error_message;
}


decompiled_code:
__int64 __fastcall word2int(unsigned __int8 *a1)
{
return a1[1] + (*a1 << 8);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 *a1)
{
return a1[1] + (*a1 << 8);
}

original_code:
int word2int( const unsigned char *word )
{
     return (word[0]<<8) + word[1];
}

canonical_original_code:
int word2int(unsigned char *word)
{
     return (word[0]<<8) + word[1];
}

variable_types:
word
unsigned char *


decompiled_code:
__int64 __fastcall byte2int(unsigned __int8 *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1)
{
return *a1;
}

original_code:
int byte2int( const unsigned char *byte )
{
     return byte[0];
}

canonical_original_code:
int byte2int(unsigned char *byte)
{
     return byte[0];
}

variable_types:
byte
unsigned char *


nibble

decompiled_code:
__int64 __fastcall nibble(unsigned __int8 a1, int a2)
{
__int64 result; // rax
unsigned int v3; // edi

result = a1 & 0xF;
v3 = a1 >> 4;
if ( a2 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int8 a1, int a2)
{
__int64 result; // rax
unsigned int v3; // edi

result = a1 & 0xF;
v3 = a1 >> 4;
if ( a2 )
result = v3;
return result;
}

original_code:
int nibble( const unsigned char byte, const nibble_e position )
{
     if ( position == n_Low ) return byte & 0x0F;
     else return byte >> 4;
}

canonical_original_code:
int nibble(unsigned char byte, enum nibble_e position)
{
     if ( position == n_Low ) return byte & 0x0F;
     else return byte >> 4;
}

variable_types:
byte
unsigned char

variable_types:
position
enum nibble_e { n_Low=0, n_High=1 }


capStat

decompiled_code:
__int64 __fastcall capStat(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax

result = (unsigned __int8)*a1;
if ( (unsigned __int8)result > 0xE0u )
{
result = (unsigned int)(result + 31);
*a2 += result;
*a1 -= result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax

result = (unsigned __int8)*a1;
if ( (unsigned __int8)result > 0xE0u )
{
result = (unsigned int)(result + 31);
*a2 += result;
*a1 -= result;
}
return result;
}

original_code:
void capStat( unsigned char *stat, unsigned char *overflow )
{
     if ( *stat < 225 ) return;
     unsigned char x = *stat - 225;
     *overflow += x;
     *stat -= x;
}

canonical_original_code:
void capStat(unsigned char *stat, unsigned char *overflow)
{
     if ( *stat < 225 ) return;
     unsigned char x = *stat - 225;
     *overflow += x;
     *stat -= x;
}

variable_types:
stat
unsigned char *

variable_types:
overflow
unsigned char *

variable_types:
x
unsigned char


getPlayerId

decompiled_code:
__int64 __fastcall getPlayerId(__int64 a1)
{
return word2int((unsigned __int8 *)(a1 + 84));
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
return func8((unsigned __int8 *)(a1 + 84));
}

original_code:
int getPlayerId( const fileplayer_s *player )
{
     return word2int( player->acc_stats.action.id_info.player_id );
}

canonical_original_code:
int getPlayerId(struct fileplayer_s *player)
{
     return word2int( player->acc_stats.action.id_info.player_id );
}

variable_types: struct fileplayer_s { char last_name[10]; char first_name[8]; char last_phoen[14]; char first_phoen[12]; unsigned char real_avg[2]; unsigned char year[1]; unsigned char position[1]; union { struct filebatting_s { unsigned char ratings[4]; unsigned char real_games[1]; unsigned char real_runs[1]; unsigned char real_rbi[1]; unsigned char real_sb[1]; unsigned char real_cs[1]; unsigned char real_sh[1]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_2b[1]; unsigned char vl_3b[1]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[1]; unsigned char real_fa2[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_2b[1]; unsigned char vr_3b[1]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[1]; unsigned char real_err[1]; unsigned char real_po[2]; unsigned char real_as[2]; unsigned char injury_days[1]; unsigned char color[1]; } filebatting; struct filepitching_s { unsigned char ratings[2]; unsigned char real_wins[1]; unsigned char real_losses[1]; unsigned char real_games[1]; unsigned char real_starts[1]; unsigned char real_cg[1]; unsigned char real_saves[1]; unsigned char real_inn[2]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[2]; unsigned char real_er[1]; unsigned char real_fa[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[2]; unsigned char real_hb[1]; unsigned char real_balk[1]; unsigned char real_ab[1]; unsigned char real_hits[1]; unsigned char real_hr[1]; unsigned char real_sh[1]; unsigned char injury_days[1]; unsigned char color[1]; } filepitching; } filestats; struct acc_stats_s { union acc_stats_u { struct acc_pch_stats_s { unsigned char acc_wins[1]; unsigned char acc_losses[1]; unsigned char acc_starts[1]; unsigned char acc_saves[1]; unsigned char acc_innings[2]; unsigned char acc_hits[2]; unsigned char acc_er[2]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[2]; } pitching; struct acc_bat_stats_s { unsigned char acc_ab[2]; unsigned char acc_hits[2]; unsigned char acc_2b[1]; unsigned char acc_3b[1]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[1]; unsigned char acc_games[1]; unsigned char acc_runs[1]; unsigned char acc_rbi[1]; unsigned char acc_sb[1]; unsigned char acc_err[1]; } batting; struct acc_player_id_s { unsigned char player_id[2]; unsigned char checksum[1]; unsigned char filler[11]; } id_info; } action; union acc_stats_u simulated; } acc_stats; } *

user_defined_types: struct fileplayer_s { char last_name[10]; char first_name[8]; char last_phoen[14]; char first_phoen[12]; unsigned char real_avg[2]; unsigned char year[1]; unsigned char position[1]; union { struct filebatting_s filebatting; struct filepitching_s filepitching; } filestats; struct acc_stats_s acc_stats; }

user_defined_types: struct acc_stats_s { union acc_stats_u action; union acc_stats_u simulated; }

user_defined_types: union acc_stats_u { struct acc_pch_stats_s pitching; struct acc_bat_stats_s batting; struct acc_player_id_s id_info; }