main

repo: zizhengwu/Linux-C-Programming

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er13
size_t v5; // rax
int v6; // er12
__int64 v7; // rbp
size_t v8; // rax
int v9; // eax
int v10; // eax
struct timeval v11; // [rsp+0h] [rbp-4C8h] BYREF
fd_set exceptfds; // [rsp+10h] [rbp-4B8h] BYREF
fd_set writefds; // [rsp+90h] [rbp-438h] BYREF
fd_set readfds; // [rsp+110h] [rbp-3B8h] BYREF
struct sockaddr inp; // [rsp+190h] [rbp-338h] BYREF
char buf[256]; // [rsp+1A0h] [rbp-328h] BYREF
char s[256]; // [rsp+2A0h] [rbp-228h] BYREF
char v18[296]; // [rsp+3A0h] [rbp-128h] BYREF

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

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er13
size_t v5; // rax
int v6; // er12
__int64 v7; // rbp
size_t v8; // rax
int v9; // eax
int v10; // eax
struct timeval v11; // [rsp+0h] [rbp-4C8h] BYREF
fd_set exceptfds; // [rsp+10h] [rbp-4B8h] BYREF
fd_set writefds; // [rsp+90h] [rbp-438h] BYREF
fd_set readfds; // [rsp+110h] [rbp-3B8h] BYREF
struct sockaddr inp; // [rsp+190h] [rbp-338h] BYREF
char buf[256]; // [rsp+1A0h] [rbp-328h] BYREF
char s[256]; // [rsp+2A0h] [rbp-228h] BYREF
char v18[296]; // [rsp+3A0h] [rbp-128h] BYREF

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

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

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)
{
__int64 v4[3]; // [rsp+0h] [rbp-28h] BYREF
int v5; // [rsp+18h] [rbp-10h]
__int16 v6; // [rsp+1Ch] [rbp-Ch]

v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v5 = 0;
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)
{
__int64 v4[3]; // [rsp+0h] [rbp-28h] BYREF
int v5; // [rsp+18h] [rbp-10h]
__int16 v6; // [rsp+1Ch] [rbp-Ch]

v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v5 = 0;
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)
{
__int64 result; // rax
int v3; // edx
char v4; // al
const char *i; // rbx

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

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

if ( !*a2 || *a2 == 10 )
return func0(a1, a2, (int)a2);
while ( 1 )
{
v4 = *a2;
for ( i = a2; *i != 44; v4 = *++i )
{
if ( !v4 )
break;
if ( v4 == 10 )
break;
}
result = func0(a1, a2, (int)i);
if ( !(_DWORD)result )
break;
a2 = i;
v3 = 0;
if ( *i == 44 )
{
a2 = i + 1;
v3 = 1;
}
if ( !*a2 || *a2 == 10 )
{
result = 1LL;
if ( v3 )
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';
}

return_type: void


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; // rbx
__int64 v4; // rbp
unsigned int v5; // eax
unsigned int v6; // eax

clearErrorMessage();
v2 = a1;
do
{
if ( *v2 )
{
v4 = findMatchingPlayer(v2, a2);
if ( !v4 )
{
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;
}
v5 = word2int(v4 + 84);
int2word(v2 + 84, v5);
v6 = byte2int(v4 + 86);
int2byte(v2 + 86, v6);
}
v2 += 112;
}
while ( v2 != a1 + 89600 );
return 1LL;
}

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

func0();
v2 = a1;
do
{
if ( *v2 )
{
v4 = findMatchingPlayer(v2, a2);
if ( !v4 )
{
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;
}
v5 = word2int(v4 + 84);
int2word(v2 + 84, v5);
v6 = byte2int(v4 + 86);
int2byte(v2 + 86, v6);
}
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: i int

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)
{
const char **v3; // rbx
__int64 v4; // r12

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

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

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

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 *

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
_BYTE *v4; // rbp
int i; // ebx
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], argv, envp);
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 / 25) + 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; // r14
_BYTE *v4; // rbp
int i; // ebx
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], argv, envp);
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 / 25) + 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)
{
void *v2; // rdi

if ( *((_DWORD *)ptr + 24) == 2 )
free_batter(*((void **)ptr + 15));
if ( *((_DWORD *)ptr + 24) == 1 )
free_pitcher(*((void **)ptr + 15));
v2 = (void *)*((_QWORD *)ptr + 14);
if ( v2 )
free(v2);
free(ptr);
}

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

if ( *((_DWORD *)ptr + 24) == 2 )
func0(*((void **)ptr + 15));
if ( *((_DWORD *)ptr + 24) == 1 )
func1(*((void **)ptr + 15));
v2 = (void *)*((_QWORD *)ptr + 14);
if ( v2 )
free(v2);
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:
__int64 *getGenPlayerIdsError()
{
return &error_message;
}

canonical_decompiled_code:
__int64 *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; // rbx
unsigned int v2; // ebp
unsigned __int8 v4; // al

clearErrorMessage();
v1 = a1 + 84;
v2 = 1;
do
{
if ( *(_BYTE *)(v1 - 84) )
{
if ( (unsigned int)word2int(v1) )
{
strcpy((char *)&error_message, "Player ID field already contains a number!");
return 0LL;
}
if ( (unsigned int)byte2int(v1 + 2) )
{
strcpy((char *)&error_message, "Checksum field already contains a number!");
return 0LL;
}
int2word(v1, v2);
v4 = calcChecksum(v2);
int2byte(v1 + 2, v4);
++v2;
}
v1 += 112LL;
}
while ( v1 != a1 + 89684 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
unsigned __int8 v4; // al

func0();
v1 = a1 + 84;
v2 = 1;
do
{
if ( *(_BYTE *)(v1 - 84) )
{
if ( (unsigned int)word2int(v1) )
{
strcpy((char *)&error_message, "Player ID field already contains a number!");
return 0LL;
}
if ( (unsigned int)byte2int(v1 + 2) )
{
strcpy((char *)&error_message, "Checksum field already contains a number!");
return 0LL;
}
int2word(v1, v2);
v4 = calcChecksum(v2);
int2byte(v1 + 2, v4);
++v2;
}
v1 += 112LL;
}
while ( v1 != a1 + 89684 );
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 *v2; // rbx
int v3; // eax
int v4; // ebp
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax

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

canonical_decompiled_code:
void *__fastcall func3(char *file, size_t nbytes)
{
void *v2; // rbx
int v3; // eax
int v4; // ebp
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax

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

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(char *file, void *buf, size_t n)
{
int v4; // eax
int v5; // ebx
int v6; // eax
int v7; // edx
__int64 result; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rbp
char *v12; // rax
int v13; // edx
char *v14; // rax
int *v15; // rax
char *v16; // rax

clearErrorMessage();
v4 = creat(file, 0x180u);
if ( v4 < 0 )
{
v9 = _errno_location();
v10 = strerror(*v9);
sprintf(error_message, "Cannot open file <%s>: %s", file, v10);
return 0LL;
}
v5 = v4;
v6 = write(v4, buf, n);
if ( v6 >= n )
goto LABEL_5;
if ( v6 >= 0 )
{
strcpy(error_message, "Warning: incomplete buffer written to output file!");
LABEL_5:
v7 = close(v5);
result = 1LL;
if ( v7 < 0 )
{
v15 = _errno_location();
v16 = strerror(*v15);
sprintf(error_message, "Error closing file <%s>: %s", file, v16);
result = 0LL;
}
return result;
}
v11 = _errno_location();
v12 = strerror(*v11);
sprintf(error_message, "Error writing to output file: %s", v12);
v13 = close(v5);
result = 0LL;
if ( v13 < 0 )
{
v14 = strerror(*v11);
sprintf(error_message, "Error closing output file: %s", v14);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *file, void *buf, size_t n)
{
int v4; // eax
int v5; // ebx
int v6; // eax
int v7; // edx
__int64 result; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rbp
char *v12; // rax
int v13; // edx
char *v14; // rax
int *v15; // rax
char *v16; // rax

func0();
v4 = creat(file, 0x180u);
if ( v4 < 0 )
{
v9 = _errno_location();
v10 = strerror(*v9);
sprintf(error_message, "Cannot open file <%s>: %s", file, v10);
return 0LL;
}
v5 = v4;
v6 = write(v4, buf, n);
if ( v6 >= n )
goto LABEL_5;
if ( v6 >= 0 )
{
strcpy(error_message, "Warning: incomplete buffer written to output file!");
LABEL_5:
v7 = close(v5);
result = 1LL;
if ( v7 < 0 )
{
v15 = _errno_location();
v16 = strerror(*v15);
sprintf(error_message, "Error closing file <%s>: %s", file, v16);
result = 0LL;
}
return result;
}
v11 = _errno_location();
v12 = strerror(*v11);
sprintf(error_message, "Error writing to output file: %s", v12);
v13 = close(v5);
result = 0LL;
if ( v13 < 0 )
{
v14 = strerror(*v11);
sprintf(error_message, "Error closing output file: %s", v14);
result = 0LL;
}
return result;
}

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 v5; // esi
int v6; // eax
int v7; // er13
const char *v8; // r12
const char *v9; // rbp
_BOOL4 v10; // ebx
int v12; // ebx
__int64 v13[2]; // [rsp+0h] [rbp-B8h] BYREF
__int64 v14; // [rsp+10h] [rbp-A8h]
char dest[8]; // [rsp+18h] [rbp-A0h] BYREF
__int64 v16; // [rsp+20h] [rbp-98h]
__int64 v17; // [rsp+28h] [rbp-90h]
_BOOL4 v18; // [rsp+30h] [rbp-88h]
__int64 v19[6]; // [rsp+40h] [rbp-78h] BYREF
int v20; // [rsp+70h] [rbp-48h]

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

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
int v5; // esi
int v6; // eax
int v7; // er13
const char *v8; // r12
const char *v9; // rbp
_BOOL4 v10; // ebx
int v12; // ebx
__int64 v13[2]; // [rsp+0h] [rbp-B8h] BYREF
__int64 v14; // [rsp+10h] [rbp-A8h]
char dest[8]; // [rsp+18h] [rbp-A0h] BYREF
__int64 v16; // [rsp+20h] [rbp-98h]
__int64 v17; // [rsp+28h] [rbp-90h]
_BOOL4 v18; // [rsp+30h] [rbp-88h]
__int64 v19[6]; // [rsp+40h] [rbp-78h] BYREF
int v20; // [rsp+70h] [rbp-48h]

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

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 func14(_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 func15(__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; }


calcChecksum

decompiled_code:
__int64 __fastcall calcChecksum(int a1)
{
int v1; // ecx
int v2; // edx

if ( a1 <= 0 )
{
v1 = 0;
}
else
{
v1 = 0;
do
{
v1 += a1 % 10;
v2 = a1;
a1 /= 10;
}
while ( v2 > 9 );
}
return (unsigned int)(3 * v1);
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
int v1; // ecx
int v2; // edx

if ( a1 <= 0 )
{
v1 = 0;
}
else
{
v1 = 0;
do
{
v1 += a1 % 10;
v2 = a1;
a1 /= 10;
}
while ( v2 > 9 );
}
return (unsigned int)(3 * v1);
}

original_code:
unsigned char calcChecksum( int value )
{
     unsigned char checksum = 0;
     while ( value > 0 )
     {
          checksum += value % 10;
          value /= 10;
     }
     return checksum * 3;
}

canonical_original_code:
unsigned char calcChecksum(int value)
{
     unsigned char checksum = 0;
     while ( value > 0 )
     {
          checksum += value % 10;
          value /= 10;
     }
     return checksum * 3;
}

variable_types: value int

variable_types:
checksum
unsigned char

return_type: unsigned char


findMatchingPlayer

decompiled_code:
char *__fastcall findMatchingPlayer(void *s1, void *s2)
{
char *v2; // rbx
char *v3; // rbp

v2 = (char *)s2;
while ( 1 )
{
v3 = v2;
if ( !memcmp((char *)s1 + 10, v2 + 10, 8uLL) && !memcmp(s1, v2, 0xAuLL) )
break;
v2 += 112;
if ( v2 == (char *)s2 + 89600 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func17(void *s1, void *s2)
{
char *v2; // rbx
char *v3; // rbp

v2 = (char *)s2;
while ( 1 )
{
v3 = v2;
if ( !memcmp((char *)s1 + 10, v2 + 10, 8uLL) && !memcmp(s1, v2, 0xAuLL) )
break;
v2 += 112;
if ( v2 == (char *)s2 + 89600 )
return 0LL;
}
return v3;
}

original_code:
fileplayer_s *findMatchingPlayer( const fileplayer_s *player, fileplayer_s *players )
{
     for ( int i = 0; i < (((25 * 8) * 2) * 2); ++i )
     {
          if ( memcmp( player->first_name, players[i].first_name, sizeof(player->first_name) ) == 0 &&
               memcmp( player->last_name, players[i].last_name, sizeof(player->last_name) ) == 0 )
          {
               return &players[i];
          }
     }
     return ((void *)0);
}

canonical_original_code:
struct fileplayer_s *findMatchingPlayer(struct fileplayer_s *player, struct fileplayer_s *players)
{
     for ( int i = 0; i < (((25 * 8) * 2) * 2); ++i )
     {
          if ( memcmp( player->first_name, players[i].first_name, sizeof(player->first_name) ) == 0 &&
               memcmp( player->last_name, players[i].last_name, sizeof(player->last_name) ) == 0 )
          {
               return &players[i];
          }
     }
     return ((void *)0);
}

variable_types:
player
struct fileplayer_s *

variable_types:
players
struct fileplayer_s *

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


freeSchedule

decompiled_code:
void __fastcall freeSchedule(void *ptr)
{
void **v2; // rax
void *v3; // rdi
__int64 v4; // rbx

v2 = *(void ***)ptr;
if ( *(_QWORD *)ptr )
{
v3 = *v2;
if ( *v2 )
{
v4 = 8LL;
do
{
free(v3);
v2 = *(void ***)ptr;
v3 = *(void **)(*(_QWORD *)ptr + v4);
v4 += 8LL;
}
while ( v3 );
}
free(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func24(void *ptr)
{
void **v2; // rax
void *v3; // rdi
__int64 v4; // rbx

v2 = *(void ***)ptr;
if ( *(_QWORD *)ptr )
{
v3 = *v2;
if ( *v2 )
{
v4 = 8LL;
do
{
free(v3);
v2 = *(void ***)ptr;
v3 = *(void **)(*(_QWORD *)ptr + v4);
v4 += 8LL;
}
while ( v3 );
}
free(v2);
}
free(ptr);
}

original_code:
void freeSchedule( schedule_s *schedule )
{
     if ( schedule->days != ((void *)0) )
     {
          for ( int i = 0; schedule->days[i].games != ((void *)0); ++i )
          {
               free( schedule->days[i].games );
          }
          free( schedule->days );
     }
     free( schedule );
}

canonical_original_code:
void freeSchedule(struct schedule_s *schedule)
{
     if ( schedule->days != ((void *)0) )
     {
          for ( int i = 0; schedule->days[i].games != ((void *)0); ++i )
          {
               free( schedule->days[i].games );
          }
          free( schedule->days );
     }
     free( schedule );
}

variable_types: struct schedule_s { struct schedule_day_s { 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; } *games; } *days; } *

user_defined_types: struct schedule_s { struct schedule_day_s *days; }

user_defined_types: struct schedule_day_s { struct schedule_game_s *games; }


clearErrorMessage

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

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


isAllstarTeam

decompiled_code:
_BOOL8 __fastcall isAllstarTeam(const char *a1, const char *a2)
{
_BOOL8 result; // rax

if ( !strcmp(a1, a2) )
result = 1LL;
else
result = strcmp(a1 + 20, a2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1, const char *a2)
{
_BOOL8 result; // rax

if ( !strcmp(a1, a2) )
result = 1LL;
else
result = strcmp(a1 + 20, a2) == 0;
return result;
}

original_code:
static boolean_e isAllstarTeam( struct league *leagues, char *team )
{
     for ( int i = 0; i < 2; ++i )
     {
          if ( strcmp( leagues[i].name, team ) == 0 ) return bl_True;
     }
     return bl_False;
}

canonical_original_code:
static enum boolean_e isAllstarTeam(struct league *leagues, char *team)
{
     for ( int i = 0; i < 2; ++i )
     {
          if ( strcmp( leagues[i].name, team ) == 0 ) return bl_True;
     }
     return bl_False;
}

variable_types:
leagues
struct league { char name[20]; } *

variable_types:
team
char *


findTeam

decompiled_code:
__int64 __fastcall findTeam(char *s1, char *s2)
{
unsigned int v3; // ebp

v3 = 0;
while ( strcmp(s1, s2) )
{
++v3;
s1 += 28;
if ( v3 == 32 )
return (unsigned int)-1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1, char *s2)
{
unsigned int v3; // ebp

v3 = 0;
while ( strcmp(s1, s2) )
{
++v3;
s1 += 28;
if ( v3 == 32 )
return (unsigned int)-1;
}
return v3;
}

original_code:
static int findTeam( struct team *teams, char *team )
{
     for ( int i = 0; i < ((8 * 2) * 2); ++i )
     {
          if ( strcmp( teams[i].name, team ) == 0 ) return i;
     }
     return -1;
}

canonical_original_code:
static int findTeam(struct team *teams, char *team)
{
     for ( int i = 0; i < ((8 * 2) * 2); ++i )
     {
          if ( strcmp( teams[i].name, team ) == 0 ) return i;
     }
     return -1;
}

variable_types: struct team { char name[20]; int league; int division; } *

variable_types: i int


getCalculateRecordsError

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

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

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


freeRecords

decompiled_code:
void __fastcall freeRecords(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void **v5; // rbx

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 )
free(v4);
v5 = (void **)((char *)ptr + 24);
do
{
if ( *v5 )
free(*v5);
++v5;
}
while ( v5 != (void **)((char *)ptr + 280) );
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void **v5; // rbx

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 )
free(v4);
v5 = (void **)((char *)ptr + 24);
do
{
if ( *v5 )
free(*v5);
++v5;
}
while ( v5 != (void **)((char *)ptr + 280) );
free(ptr);
}

original_code:
void freeRecords( records_s *records )
{
     if ( records->leagues != ((void *)0) ) free( records->leagues );
     if ( records->divisions != ((void *)0) ) free( records->divisions );
     if ( records->teams != ((void *)0) ) free( records->teams );
     for ( int i = 0; i < ((8 * 2) * 2); ++i )
     {
          if ( records->versus[i] != ((void *)0) ) free( records->versus[i] );
     }
     free( records );
}

canonical_original_code:
void freeRecords(struct records_s *records)
{
     if ( records->leagues != ((void *)0) ) free( records->leagues );
     if ( records->divisions != ((void *)0) ) free( records->divisions );
     if ( records->teams != ((void *)0) ) free( records->teams );
     for ( int i = 0; i < ((8 * 2) * 2); ++i )
     {
          if ( records->versus[i] != ((void *)0) ) free( records->versus[i] );
     }
     free( records );
}

variable_types: struct records_s { struct league_stats_s { int league_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 home_wins; int home_losses; int road_wins; int road_losses; int runs_scored; int runs_allowed; } *leagues; struct division_stats_s { int division_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 home_wins; int home_losses; int road_wins; int road_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; } *divisions; struct team_stats_s { int team_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 home_wins; int home_losses; int road_wins; int road_losses; int division_wins; int division_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; } *teams; struct team_versus_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int opponent; int wins; int losses; int runs_scored; int runs_allowed; } *versus[-1]; } *

user_defined_types: struct records_s { struct league_stats_s *leagues; struct division_stats_s *divisions; struct team_stats_s *teams; struct team_versus_stats_s *versus[-1]; }

user_defined_types: struct league_stats_s { int league_id; int season; enum season_phase_e season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int runs_scored; int runs_allowed; }

user_defined_types: struct division_stats_s { int division_id; int season; enum season_phase_e season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; }

user_defined_types: struct team_stats_s { int team_id; int season; enum season_phase_e season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int division_wins; int division_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; }

user_defined_types: struct team_versus_stats_s { int team_id; int season; enum season_phase_e season_phase; int opponent; int wins; int losses; int runs_scored; int runs_allowed; }