main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
int v4; // eax
unsigned int v5; // ebx
int v6; // eax

initOpts(argc, (char **)argv);
if ( !foreground )
{
v3 = fork();
if ( v3 < 0 )
exit(1);
if ( v3 )
exit(0);
umask(0);
if ( setsid() < 0 )
fatal("setsid failed (%m)");
if ( chdir("/") < 0 )
fatal("chdir failed (%m)");
fclose(stdin);
fclose(stdout);
}
gpioCfgBufferSize((unsigned int)bufferSizeMilliseconds);
gpioCfgClock((unsigned int)clockMicros, (unsigned int)clockPeripheral, 0LL);
gpioCfgInterfaces((unsigned int)ifFlags);
gpioCfgDMAchannels((unsigned int)DMAprimaryChannel, (unsigned int)DMAsecondaryChannel);
gpioCfgSocketPort((unsigned int)socketPort);
gpioCfgMemAlloc((unsigned int)memAllocMode);
if ( updateMaskSet )
gpioCfgPermissions(updateMask);
gpioCfgNetAddr((unsigned int)numSockNetAddr, sockNetAddr);
gpioCfgSetInternals((unsigned int)cfgInternals);
if ( (int)gpioInitialise() < 0 )
fatal("Can't initialise pigpio library");
unlink("/dev/pigerr");
mkfifo("/dev/pigerr", 0x1B4u);
if ( chmod("/dev/pigerr", 0x1B4u) < 0 )
fatal("chmod %s failed (%m)", "/dev/pigerr");
errFifo = freopen("/dev/pigerr", "w+", stderr);
if ( errFifo )
{
v4 = fileno(errFifo);
v5 = fcntl(v4, 3, 0LL);
v6 = fileno(errFifo);
BYTE1(v5) |= 8u;
fcntl(v6, 4, v5);
gpioSetSignalFunc(1LL, terminate);
gpioSetSignalFunc(15LL, terminate);
while ( 1 )
{
sleep(5u);
fflush(errFifo);
}
}
fprintf(stderr, "freopen failed (%m)");
gpioTerminate();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
int v4; // eax
unsigned int v5; // ebx
int v6; // eax

func5(argc, (char **)argv);
if ( !foreground )
{
v3 = fork();
if ( v3 < 0 )
exit(1);
if ( v3 )
exit(0);
umask(0);
if ( setsid() < 0 )
func3("setsid failed (%m)");
if ( chdir("/") < 0 )
func3("chdir failed (%m)");
fclose(stdin);
fclose(stdout);
}
gpioCfgBufferSize((unsigned int)bufferSizeMilliseconds);
gpioCfgClock((unsigned int)clockMicros, (unsigned int)clockPeripheral, 0LL);
gpioCfgInterfaces((unsigned int)ifFlags);
gpioCfgDMAchannels((unsigned int)DMAprimaryChannel, (unsigned int)DMAsecondaryChannel);
gpioCfgSocketPort((unsigned int)socketPort);
gpioCfgMemAlloc((unsigned int)memAllocMode);
if ( updateMaskSet )
gpioCfgPermissions(updateMask);
gpioCfgNetAddr((unsigned int)numSockNetAddr, sockNetAddr);
gpioCfgSetInternals((unsigned int)cfgInternals);
if ( (int)gpioInitialise() < 0 )
func3("Can't initialise pigpio library");
unlink("/dev/pigerr");
mkfifo("/dev/pigerr", 0x1B4u);
if ( chmod("/dev/pigerr", 0x1B4u) < 0 )
func3("chmod %s failed (%m)", "/dev/pigerr");
errFifo = freopen("/dev/pigerr", "w+", stderr);
if ( errFifo )
{
v4 = fileno(errFifo);
v5 = fcntl(v4, 3, 0LL);
v6 = fileno(errFifo);
BYTE1(v5) |= 8u;
fcntl(v6, 4, v5);
gpioSetSignalFunc(1LL, terminate);
gpioSetSignalFunc(15LL, terminate);
while ( 1 )
{
sleep(5u);
fflush(errFifo);
}
}
fprintf(stderr, "freopen failed (%m)");
gpioTerminate();
return 0;
}

original_code:
int main(int argc, char **argv)
{
   pid_t pid;
   int flags;
   initOpts(argc, argv);
   if (!foreground) {
      pid = fork();
      if (pid < 0) { exit(1); }
      if (pid > 0) { exit(0); }
      umask(0);
      if (setsid() < 0) fatal("setsid failed (%m)");
      if ((chdir("/")) < 0) fatal("chdir failed (%m)");
      fclose(stdin);
      fclose(stdout);
   }
   gpioCfgBufferSize(bufferSizeMilliseconds);
   gpioCfgClock(clockMicros, clockPeripheral, 0);
   gpioCfgInterfaces(ifFlags);
   gpioCfgDMAchannels(DMAprimaryChannel, DMAsecondaryChannel);
   gpioCfgSocketPort(socketPort);
   gpioCfgMemAlloc(memAllocMode);
   if (updateMaskSet) gpioCfgPermissions(updateMask);
   gpioCfgNetAddr(numSockNetAddr, sockNetAddr);
   gpioCfgSetInternals(cfgInternals);
   if (gpioInitialise()< 0) fatal("Can't initialise pigpio library");
   unlink("/dev/pigerr");
   mkfifo("/dev/pigerr", 0664);
   if (chmod("/dev/pigerr", 0664) < 0)
      fatal("chmod %s failed (%m)", "/dev/pigerr");
   errFifo = freopen("/dev/pigerr", "w+", stderr);
   if (errFifo)
   {
      flags = fcntl(fileno(errFifo), 3, 0);
      fcntl(fileno(errFifo), 4, flags | 04000);
      gpioSetSignalFunc(1, terminate);
      gpioSetSignalFunc(15, terminate);
      while (1)
      {
         sleep(5);
         fflush(errFifo);
      }
   }
   else
   {
      fprintf(stderr, "freopen failed (%m)");
      gpioTerminate();
   }
   return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
   int pid;
   int flags;
   initOpts(argc, argv);
   if (!foreground) {
      pid = fork();
      if (pid < 0) { exit(1); }
      if (pid > 0) { exit(0); }
      umask(0);
      if (setsid() < 0) fatal("setsid failed (%m)");
      if ((chdir("/")) < 0) fatal("chdir failed (%m)");
      fclose(stdin);
      fclose(stdout);
   }
   gpioCfgBufferSize(bufferSizeMilliseconds);
   gpioCfgClock(clockMicros, clockPeripheral, 0);
   gpioCfgInterfaces(ifFlags);
   gpioCfgDMAchannels(DMAprimaryChannel, DMAsecondaryChannel);
   gpioCfgSocketPort(socketPort);
   gpioCfgMemAlloc(memAllocMode);
   if (updateMaskSet) gpioCfgPermissions(updateMask);
   gpioCfgNetAddr(numSockNetAddr, sockNetAddr);
   gpioCfgSetInternals(cfgInternals);
   if (gpioInitialise()< 0) fatal("Can't initialise pigpio library");
   unlink("/dev/pigerr");
   mkfifo("/dev/pigerr", 0664);
   if (chmod("/dev/pigerr", 0664) < 0)
      fatal("chmod %s failed (%m)", "/dev/pigerr");
   errFifo = freopen("/dev/pigerr", "w+", stderr);
   if (errFifo)
   {
      flags = fcntl(fileno(errFifo), 3, 0);
      fcntl(fileno(errFifo), 4, flags | 04000);
      gpioSetSignalFunc(1, terminate);
      gpioSetSignalFunc(15, terminate);
      while (1)
      {
         sleep(5);
         fflush(errFifo);
      }
   }
   else
   {
      fprintf(stderr, "freopen failed (%m)");
      gpioTerminate();
   }
   return 0;
}

variable_types:
argv
char **

variable_types: pid int

variable_types: flags int


openSocket

decompiled_code:
__int64 openSocket()
{
char *v0; // r12
char *v1; // rdi
struct addrinfo *v2; // rdi
struct addrinfo *v3; // rbx
int v4; // eax
unsigned int v5; // er12
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

v0 = getenv("PIGPIO_PORT");
if ( !v0 )
v0 = "8888";
v1 = getenv("PIGPIO_ADDR");
if ( !v1 )
v1 = "localhost";
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
req.ai_flags = 2;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(v1, v0, &req, &pai) )
return (unsigned int)-1;
v2 = pai;
v3 = pai;
if ( !pai )
{
LABEL_11:
freeaddrinfo(v2);
return (unsigned int)-1;
}
while ( 1 )
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v5 = v4;
if ( v4 != -1 && connect(v4, v3->ai_addr, v3->ai_addrlen) != -1 )
break;
v3 = v3->ai_next;
if ( !v3 )
{
v2 = pai;
goto LABEL_11;
}
}
freeaddrinfo(pai);
return v5;
}

canonical_decompiled_code:
__int64 func0()
{
char *v0; // r12
char *v1; // rdi
struct addrinfo *v2; // rdi
struct addrinfo *v3; // rbx
int v4; // eax
unsigned int v5; // er12
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

v0 = getenv("PIGPIO_PORT");
if ( !v0 )
v0 = "8888";
v1 = getenv("PIGPIO_ADDR");
if ( !v1 )
v1 = "localhost";
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
req.ai_flags = 2;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(v1, v0, &req, &pai) )
return (unsigned int)-1;
v2 = pai;
v3 = pai;
if ( !pai )
{
LABEL_11:
freeaddrinfo(v2);
return (unsigned int)-1;
}
while ( 1 )
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v5 = v4;
if ( v4 != -1 && connect(v4, v3->ai_addr, v3->ai_addrlen) != -1 )
break;
v3 = v3->ai_next;
if ( !v3 )
{
v2 = pai;
goto LABEL_11;
}
}
freeaddrinfo(pai);
return v5;
}

original_code:
static int openSocket(void)
{
   int sock, err;
   struct addrinfo hints, *res, *rp;
   const char *addrStr, *portStr;
   portStr = getenv("PIGPIO_PORT");
   if (!portStr) portStr = "8888";
   addrStr = getenv("PIGPIO_ADDR");
   if (!addrStr) addrStr = "localhost";
   memset (&hints, 0, sizeof (hints));
   hints.ai_family = 0;
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_flags |= 0x0002;
   err = getaddrinfo(addrStr, portStr, &hints, &res);
   if (err) return -1;
   for (rp=res; rp!=((void *)0); rp=rp->ai_next)
   {
      sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
      if (sock == -1) continue;
      if (connect(sock, rp->ai_addr, rp->ai_addrlen) != -1) break;
   }
   freeaddrinfo(res);
   if (rp == ((void *)0)) return -1;
   return sock;
}

canonical_original_code:
static int openSocket()
{
   int sock; int err;
   struct addrinfo hints; struct addrinfo *res; struct addrinfo *rp;
   char *addrStr; char *portStr;
   portStr = getenv("PIGPIO_PORT");
   if (!portStr) portStr = "8888";
   addrStr = getenv("PIGPIO_ADDR");
   if (!addrStr) addrStr = "localhost";
   memset (&hints, 0, sizeof (hints));
   hints.ai_family = 0;
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_flags |= 0x0002;
   err = getaddrinfo(addrStr, portStr, &hints, &res);
   if (err) return -1;
   for (rp=res; rp!=((void *)0); rp=rp->ai_next)
   {
      sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
      if (sock == -1) continue;
      if (connect(sock, rp->ai_addr, rp->ai_addrlen) != -1) break;
   }
   freeaddrinfo(res);
   if (rp == ((void *)0)) return -1;
   return sock;
}

variable_types: sock int

variable_types: err int

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

variable_types:
addrStr
char *

variable_types:
portStr
char *

return_type: int

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


report

decompiled_code:
int report(int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-150h] BYREF
char s[128]; // [rsp+20h] [rbp-138h] BYREF

if ( status < a1 )
status = a1;
va_start(arg, a2);
vsnprintf(s, 0x80uLL, a2, arg);
fprintf(stderr, "%s\n", s);
return fflush(stderr);
}

canonical_decompiled_code:
int func1(int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-150h] BYREF
char s[128]; // [rsp+20h] [rbp-138h] BYREF

if ( status < a1 )
status = a1;
va_start(arg, a2);
vsnprintf(s, 0x80uLL, a2, arg);
fprintf(stderr, "%s\n", s);
return fflush(stderr);
}

original_code:
void report(int err, char *fmt, ...)
{
   char buf[128];
   va_list ap;
   if (err > status) status = err;
   __builtin_va_start(ap,fmt);
   vsnprintf(buf, sizeof(buf), fmt, ap);
   __builtin_va_end(ap);
   fprintf(stderr, "%s\n", buf);
   fflush(stderr);
}

canonical_original_code:
void report(int err, char *fmt, ...)
{
   char buf[128];
   __builtin_va_list ap;
   if (err > status) status = err;
   __builtin_va_start(ap,fmt);
   vsnprintf(buf, sizeof(buf), fmt, ap);
   __builtin_va_end(ap);
   fprintf(stderr, "%s\n", buf);
   fflush(stderr);
}

variable_types:
fmt
char *

variable_types:
buf
char [128]

return_type: void


decompiled_code:
void __fastcall print_result(__int64 a1, int a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // rcx
int v5; // ebx
const char *v6; // rax
__int64 v7; // rsi
const char *v8; // rdi
const char *v9; // rax
char v10; // al
__int64 v11; // rbp
__int64 v12; // r13
char v13; // al
__int64 v14; // rbp
__int64 v15; // r13
unsigned __int64 v16; // rbx
__int64 v17; // rsi

v4 = HIDWORD(a4);
v5 = v4;
switch ( a2 )
{
case 0:
case 1:
if ( (v4 & 0x80000000) != 0LL )
goto LABEL_44;
return;
case 2:
printf("%d\n", (unsigned int)v4);
if ( v5 < 0 )
goto LABEL_5;
return;
case 3:
v7 = (unsigned int)v4;
v8 = "%08X\n";
goto LABEL_8;
case 4:
v7 = (unsigned int)v4;
v8 = "%u\n";
LABEL_8:
printf(v8, v7);
return;
case 5:
printf("%s", cmdUsage);
return;
case 6:
printf("%d", (unsigned int)v4);
if ( v5 < 0 )
goto LABEL_12;
if ( v5 )
{
v13 = printFlags;
if ( printFlags == 2 )
{
putchar(32);
v13 = printFlags;
}
v14 = 0LL;
while ( 1 )
{
v15 = *((char *)&response_buf + v14);
if ( (v13 & 1) != 0 )
{
printf(" %hhx", (unsigned int)v15);
}
else if ( (v13 & 2) != 0 )
{
if ( ((*_ctype_b_loc())[v15] & 0x4000) != 0 || (_DWORD)v15 == 10 || (_DWORD)v15 == 13 )
putchar(v15);
else
printf("\\x%02hhx", (unsigned int)v15);
}
else
{
printf(" %hhu", (unsigned int)v15);
}
if ( v5 == ++v14 )
break;
v13 = printFlags;
}
}
goto LABEL_13;
case 7:
if ( (_DWORD)v4 == 44 )
{
v16 = (unsigned int)((_DWORD)&response_buf + 4);
printf("%d", (unsigned int)response_buf);
do
{
v17 = *(unsigned int *)v16;
v16 += 4LL;
printf(" %d", v17);
}
while ( (_DWORD)&response_buf + 44 != v16 );
}
else
{
printf("%d", (unsigned int)v4);
LABEL_12:
v9 = (const char *)cmdErrStr((unsigned int)v5);
report(253, "ERROR: %s", v9);
}
goto LABEL_13;
case 8:
if ( (v4 & 0x80000000) != 0LL )
{
LABEL_44:
printf("%d\n", (unsigned int)v4);
LABEL_5:
v6 = (const char *)cmdErrStr((unsigned int)v5);
report(253, "ERROR: %s", v6);
}
else
{
printf("%d %d", (unsigned int)(v4 - 3), (unsigned int)response_buf);
if ( v5 > 4 )
{
v10 = printFlags;
if ( printFlags == 2 )
{
putchar(32);
v10 = printFlags;
}
v11 = 4LL;
while ( 1 )
{
v12 = *((char *)&response_buf + v11);
if ( (v10 & 1) != 0 )
{
printf(" %hhx", (unsigned int)v12);
}
else if ( (v10 & 2) != 0 )
{
if ( ((*_ctype_b_loc())[v12] & 0x4000) != 0 || (_DWORD)v12 == 10 || (_DWORD)v12 == 13 )
putchar(v12);
else
printf("\\x%02hhx", (unsigned int)v12);
}
else
{
printf(" %hhu", (unsigned int)v12);
}
if ( v5 == ++v11 )
break;
v10 = printFlags;
}
}
LABEL_13:
putchar(10);
}
return;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // rcx
int v5; // ebx
const char *v6; // rax
__int64 v7; // rsi
const char *v8; // rdi
const char *v9; // rax
char v10; // al
__int64 v11; // rbp
__int64 v12; // r13
char v13; // al
__int64 v14; // rbp
__int64 v15; // r13
unsigned __int64 v16; // rbx
__int64 v17; // rsi

v4 = HIDWORD(a4);
v5 = v4;
switch ( a2 )
{
case 0:
case 1:
if ( (v4 & 0x80000000) != 0LL )
goto LABEL_44;
return;
case 2:
printf("%d\n", (unsigned int)v4);
if ( v5 < 0 )
goto LABEL_5;
return;
case 3:
v7 = (unsigned int)v4;
v8 = "%08X\n";
goto LABEL_8;
case 4:
v7 = (unsigned int)v4;
v8 = "%u\n";
LABEL_8:
printf(v8, v7);
return;
case 5:
printf("%s", cmdUsage);
return;
case 6:
printf("%d", (unsigned int)v4);
if ( v5 < 0 )
goto LABEL_12;
if ( v5 )
{
v13 = printFlags;
if ( printFlags == 2 )
{
putchar(32);
v13 = printFlags;
}
v14 = 0LL;
while ( 1 )
{
v15 = *((char *)&response_buf + v14);
if ( (v13 & 1) != 0 )
{
printf(" %hhx", (unsigned int)v15);
}
else if ( (v13 & 2) != 0 )
{
if ( ((*_ctype_b_loc())[v15] & 0x4000) != 0 || (_DWORD)v15 == 10 || (_DWORD)v15 == 13 )
putchar(v15);
else
printf("\\x%02hhx", (unsigned int)v15);
}
else
{
printf(" %hhu", (unsigned int)v15);
}
if ( v5 == ++v14 )
break;
v13 = printFlags;
}
}
goto LABEL_13;
case 7:
if ( (_DWORD)v4 == 44 )
{
v16 = (unsigned int)((_DWORD)&response_buf + 4);
printf("%d", (unsigned int)response_buf);
do
{
v17 = *(unsigned int *)v16;
v16 += 4LL;
printf(" %d", v17);
}
while ( (_DWORD)&response_buf + 44 != v16 );
}
else
{
printf("%d", (unsigned int)v4);
LABEL_12:
v9 = (const char *)cmdErrStr((unsigned int)v5);
func1(253, "ERROR: %s", v9);
}
goto LABEL_13;
case 8:
if ( (v4 & 0x80000000) != 0LL )
{
LABEL_44:
printf("%d\n", (unsigned int)v4);
LABEL_5:
v6 = (const char *)cmdErrStr((unsigned int)v5);
func1(253, "ERROR: %s", v6);
}
else
{
printf("%d %d", (unsigned int)(v4 - 3), (unsigned int)response_buf);
if ( v5 > 4 )
{
v10 = printFlags;
if ( printFlags == 2 )
{
putchar(32);
v10 = printFlags;
}
v11 = 4LL;
while ( 1 )
{
v12 = *((char *)&response_buf + v11);
if ( (v10 & 1) != 0 )
{
printf(" %hhx", (unsigned int)v12);
}
else if ( (v10 & 2) != 0 )
{
if ( ((*_ctype_b_loc())[v12] & 0x4000) != 0 || (_DWORD)v12 == 10 || (_DWORD)v12 == 13 )
putchar(v12);
else
printf("\\x%02hhx", (unsigned int)v12);
}
else
{
printf(" %hhu", (unsigned int)v12);
}
if ( v5 == ++v11 )
break;
v10 = printFlags;
}
}
LABEL_13:
putchar(10);
}
return;
default:
return;
}
}

original_code:
void print_result(int sock, int rv, cmdCmd_t cmd)
{
   int i, r, ch;
   uint32_t *p;
   r = cmd.res;
   switch (rv)
   {
      case 0:
      case 1:
         if (r < 0)
         {
            printf("%d\n", r);
            report(253, "ERROR: %s", cmdErrStr(r));
         }
         break;
      case 2:
         printf("%d\n", r);
         if (r < 0) report(253, "ERROR: %s", cmdErrStr(r));
         break;
      case 3:
         printf("%08X\n", cmd.res);
         break;
      case 4:
         printf("%u\n", cmd.res);
         break;
      case 5:
         printf("%s", cmdUsage);
         break;
      case 6:
         printf("%d", r);
         if (r < 0) report(253, "ERROR: %s", cmdErrStr(r));
         if (r > 0)
         {
            if (printFlags == 2) printf(" ");
            for (i=0; i<r; i++)
            {
               ch = response_buf[i];
               if (printFlags & 1) printf(" %hhx", ch);
               else if (printFlags & 2)
               {
                  if (((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISprint) || (ch == '\n') || (ch == '\r'))
                     printf("%c", ch);
                  else printf("\\x%02hhx", ch);
               }
               else printf(" %hhu", response_buf[i]);
            }
         }
         printf("\n");
         break;
      case 7:
         if (r != (4 + (4*10)))
         {
            printf("%d", r);
            report(253, "ERROR: %s", cmdErrStr(r));
         }
         else
         {
            p = (uint32_t *)response_buf;
            printf("%d", p[0]);
            for (i=0; i<10; i++)
            {
               printf(" %d", p[i+1]);
            }
         }
         printf("\n");
         break;
      case 8:
         if (r < 0)
         {
            printf("%d\n", r);
            report(253, "ERROR: %s", cmdErrStr(r));
            break;
         }
         p = (uint32_t *)response_buf;
         printf("%d %d", r-3, p[0]);
         if (r > 4)
         {
            if (printFlags == 2) printf(" ");
            for (i=4; i<r; i++)
            {
               ch = response_buf[i];
               if (printFlags & 1) printf(" %hhx", ch);
               else if (printFlags & 2)
               {
                  if (((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISprint) || (ch == '\n') || (ch == '\r'))
                     printf("%c", ch);
                  else printf("\\x%02hhx", ch);
               }
               else printf(" %hhu", response_buf[i]);
            }
         }
         printf("\n");
         break;
   }
}

canonical_original_code:
void print_result(int sock, int rv, struct cmdCmd_t cmd)
{
   int i; int r; int ch;
   unsigned int *p;
   r = cmd.res;
   switch (rv)
   {
      case 0:
      case 1:
         if (r < 0)
         {
            printf("%d\n", r);
            report(253, "ERROR: %s", cmdErrStr(r));
         }
         break;
      case 2:
         printf("%d\n", r);
         if (r < 0) report(253, "ERROR: %s", cmdErrStr(r));
         break;
      case 3:
         printf("%08X\n", cmd.res);
         break;
      case 4:
         printf("%u\n", cmd.res);
         break;
      case 5:
         printf("%s", cmdUsage);
         break;
      case 6:
         printf("%d", r);
         if (r < 0) report(253, "ERROR: %s", cmdErrStr(r));
         if (r > 0)
         {
            if (printFlags == 2) printf(" ");
            for (i=0; i<r; i++)
            {
               ch = response_buf[i];
               if (printFlags & 1) printf(" %hhx", ch);
               else if (printFlags & 2)
               {
                  if (((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISprint) || (ch == '\n') || (ch == '\r'))
                     printf("%c", ch);
                  else printf("\\x%02hhx", ch);
               }
               else printf(" %hhu", response_buf[i]);
            }
         }
         printf("\n");
         break;
      case 7:
         if (r != (4 + (4*10)))
         {
            printf("%d", r);
            report(253, "ERROR: %s", cmdErrStr(r));
         }
         else
         {
            p = (unsigned int *)response_buf;
            printf("%d", p[0]);
            for (i=0; i<10; i++)
            {
               printf(" %d", p[i+1]);
            }
         }
         printf("\n");
         break;
      case 8:
         if (r < 0)
         {
            printf("%d\n", r);
            report(253, "ERROR: %s", cmdErrStr(r));
            break;
         }
         p = (unsigned int *)response_buf;
         printf("%d %d", r-3, p[0]);
         if (r > 4)
         {
            if (printFlags == 2) printf(" ");
            for (i=4; i<r; i++)
            {
               ch = response_buf[i];
               if (printFlags & 1) printf(" %hhx", ch);
               else if (printFlags & 2)
               {
                  if (((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISprint) || (ch == '\n') || (ch == '\r'))
                     printf("%c", ch);
                  else printf("\\x%02hhx", ch);
               }
               else printf(" %hhu", response_buf[i]);
            }
         }
         printf("\n");
         break;
   }
}

variable_types: rv int

variable_types: struct cmdCmd_t { unsigned int cmd; unsigned int p1; unsigned int p2; union { unsigned int p3; unsigned int ext_len; unsigned int res; }; }

variable_types: i int

variable_types: r int

variable_types: ch int

variable_types:
p
unsigned int *


decompiled_code:
ssize_t __fastcall get_extensions(int a1, int a2, int a3)
{
__int64 v3; // rbx
ssize_t result; // rax

switch ( a2 )
{
case '+':
case '-':
case '8':
case 'A':
case 'C':
case 'F':
case 'I':
case 'K':
case 'P':
case 'X':
case '[':
case '\\':
case 'j':
case 'm':
case 'q':
case 'r':
if ( a3 > 0 )
{
v3 = a3;
result = recv(a1, &response_buf, a3, 256);
*((_BYTE *)&response_buf + v3) = 0;
}
break;
default:
return result;
}
return result;
}

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

switch ( a2 )
{
case '+':
case '-':
case '8':
case 'A':
case 'C':
case 'F':
case 'I':
case 'K':
case 'P':
case 'X':
case '[':
case '\\':
case 'j':
case 'm':
case 'q':
case 'r':
if ( a3 > 0 )
{
v3 = a3;
result = recv(a1, &response_buf, a3, 256);
*((_BYTE *)&response_buf + v3) = 0;
}
break;
default:
return result;
}
return result;
}

original_code:
void get_extensions(int sock, int command, int res)
{
   switch (command)
   {
      case 91:
      case 114:
      case 113:
      case 88:
      case 109:
      case 106:
      case 70:
      case 56:
      case 67:
      case 65:
      case 92:
      case 45:
      case 80:
      case 43:
      case 75:
      case 73:
         if (res > 0)
         {
            recv(sock, response_buf, res, MSG_WAITALL);
            response_buf[res] = 0;
         }
         break;
   }
}

variable_types: command int

variable_types: res int


initOpts

decompiled_code:
__int64 __fastcall initOpts(int argc, char **argv)
{
unsigned int i; // er12
int v3; // eax

opterr = 0;
for ( i = 1; ; ++i )
{
v3 = getopt(argc, argv, "ax");
if ( v3 == -1 )
break;
if ( v3 == 97 )
{
printFlags |= 2u;
}
else if ( v3 == 120 )
{
printFlags |= 1u;
}
else
{
report(254, "ERROR: bad option %c", (unsigned int)optopt);
}
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(int argc, char **argv)
{
unsigned int i; // er12
int v3; // eax

opterr = 0;
for ( i = 1; ; ++i )
{
v3 = getopt(argc, argv, "ax");
if ( v3 == -1 )
break;
if ( v3 == 97 )
{
printFlags |= 2u;
}
else if ( v3 == 120 )
{
printFlags |= 1u;
}
else
{
func1(254, "ERROR: bad option %c", (unsigned int)optopt);
}
}
return i;
}

original_code:
static int initOpts(int argc, char *argv[])
{
   int opt, args;
   opterr = 0;
   args = 1;
   while ((opt = getopt(argc, argv, "ax")) != -1)
   {
      switch (opt)
      {
         case 'a':
            printFlags |= 2;
            args++;
            break;
         case 'x':
            printFlags |= 1;
            args++;
            break;
         default:
            args++;
            report(254, "ERROR: bad option %c", optopt);
      }
    }
   return args;
}

canonical_original_code:
static int initOpts(int argc, char *argv[])
{
   int opt; int args;
   opterr = 0;
   args = 1;
   while ((opt = getopt(argc, argv, "ax")) != -1)
   {
      switch (opt)
      {
         case 'a':
            printFlags |= 2;
            args++;
            break;
         case 'x':
            printFlags |= 1;
            args++;
            break;
         default:
            args++;
            report(254, "ERROR: bad option %c", optopt);
      }
    }
   return args;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: args int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
const char **v5; // rbx
const char **v6; // r15
unsigned int v7; // ebp
signed int v8; // er13
const char *v9; // r14
char *v10; // rdi
int v11; // ebp
int i; // eax
int v13; // eax
__int64 v14; // rbx
int v15; // er13
const char *v16; // rax
int v18; // [rsp+8h] [rbp-100D0h] BYREF
__int64 buf; // [rsp+10h] [rbp-100C8h] BYREF
unsigned __int64 v20; // [rsp+18h] [rbp-100C0h]
void *ptr; // [rsp+20h] [rbp-100B8h] BYREF
__int64 v22; // [rsp+50h] [rbp-10088h] BYREF
__int64 v23; // [rsp+58h] [rbp-10080h]
__int64 v24; // [rsp+60h] [rbp-10078h]
size_t n; // [rsp+68h] [rbp-10070h]
char v26[65592]; // [rsp+A0h] [rbp-10038h] BYREF

v3 = openSocket(argc, argv, envp);
v4 = initOpts(argc, (char **)argv);
command_buf[0] = 0;
if ( argc > v4 )
{
v5 = &argv[v4];
v6 = &(&argv[v4])[(unsigned __int64)(unsigned int)(argc - 1 - v4) + 1];
v7 = 0;
v8 = 0;
do
{
while ( 1 )
{
v9 = *v5;
v7 += strlen(*v5) + 1;
if ( v7 <= 0xFFFF )
break;
if ( ++v5 == v6 )
goto LABEL_6;
}
v10 = &command_buf[v8];
++v5;
v8 = v7;
sprintf(v10, "%s ", v9);
}
while ( v5 != v6 );
LABEL_6:
if ( v8 )
command_buf[v8 - 1] = 0;
}
v18 = 0;
v11 = strlen(command_buf);
for ( i = 0; v11 > i; i = v18 )
{
v13 = cmdParse(command_buf, &v22, &unk_10000, v26, &v18);
v14 = v13;
if ( v13 < 0 )
{
v16 = (const char *)cmdStr();
if ( (_DWORD)v14 == -1 )
report(253, "%s? unknown command, pigs h for help", v16);
else
report(253, "%s: bad parameter, pigs h for help", v16);
break;
}
v15 = v22;
if ( (int)v22 > 799 )
{
report(253, "%s only allowed within a script", *((const char **)&cmdInfo + 4 * v13 + 1));
}
else if ( (_DWORD)v22 == 25 )
{
printf("%s", cmdUsage);
}
else if ( (_DWORD)v22 == 48 )
{
cmdParseScript(v26, &ptr, 1LL);
if ( ptr )
free(ptr);
}
else
{
buf = __PAIR64__(v23, v22);
v20 = __PAIR64__(n, v24);
if ( v3 == -1 )
{
report(255, "socket connect failed");
}
else if ( send(v3, &buf, 0x10uLL, 0) == 16 )
{
if ( n )
send(v3, v26, n, 0);
if ( recv(v3, &buf, 0x10uLL, 256) == 16 )
{
get_extensions(v3, v15, SHIDWORD(v20));
print_result((unsigned int)v3, *((_DWORD *)&cmdInfo + 8 * v14 + 5), buf, v20);
}
else
{
report(255, "socket receive failed");
}
}
else
{
report(255, "socket send failed");
}
}
}
if ( v3 >= 0 )
close(v3);
return status;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
const char **v5; // rbx
const char **v6; // r15
unsigned int v7; // ebp
signed int v8; // er13
const char *v9; // r14
char *v10; // rdi
int v11; // ebp
int i; // eax
int v13; // eax
__int64 v14; // rbx
int v15; // er13
const char *v16; // rax
int v18; // [rsp+8h] [rbp-100D0h] BYREF
__int64 buf; // [rsp+10h] [rbp-100C8h] BYREF
unsigned __int64 v20; // [rsp+18h] [rbp-100C0h]
void *ptr; // [rsp+20h] [rbp-100B8h] BYREF
__int64 v22; // [rsp+50h] [rbp-10088h] BYREF
__int64 v23; // [rsp+58h] [rbp-10080h]
__int64 v24; // [rsp+60h] [rbp-10078h]
size_t n; // [rsp+68h] [rbp-10070h]
char v26[65592]; // [rsp+A0h] [rbp-10038h] BYREF

v3 = func0(argc, argv, envp);
v4 = func2(argc, (char **)argv);
command_buf[0] = 0;
if ( argc > v4 )
{
v5 = &argv[v4];
v6 = &(&argv[v4])[(unsigned __int64)(unsigned int)(argc - 1 - v4) + 1];
v7 = 0;
v8 = 0;
do
{
while ( 1 )
{
v9 = *v5;
v7 += strlen(*v5) + 1;
if ( v7 <= 0xFFFF )
break;
if ( ++v5 == v6 )
goto LABEL_6;
}
v10 = &command_buf[v8];
++v5;
v8 = v7;
sprintf(v10, "%s ", v9);
}
while ( v5 != v6 );
LABEL_6:
if ( v8 )
command_buf[v8 - 1] = 0;
}
v18 = 0;
v11 = strlen(command_buf);
for ( i = 0; v11 > i; i = v18 )
{
v13 = cmdParse(command_buf, &v22, &unk_10000, v26, &v18);
v14 = v13;
if ( v13 < 0 )
{
v16 = (const char *)cmdStr();
if ( (_DWORD)v14 == -1 )
func1(253, "%s? unknown command, pigs h for help", v16);
else
func1(253, "%s: bad parameter, pigs h for help", v16);
break;
}
v15 = v22;
if ( (int)v22 > 799 )
{
func1(253, "%s only allowed within a script", *((const char **)&cmdInfo + 4 * v13 + 1));
}
else if ( (_DWORD)v22 == 25 )
{
printf("%s", cmdUsage);
}
else if ( (_DWORD)v22 == 48 )
{
cmdParseScript(v26, &ptr, 1LL);
if ( ptr )
free(ptr);
}
else
{
buf = __PAIR64__(v23, v22);
v20 = __PAIR64__(n, v24);
if ( v3 == -1 )
{
func1(255, "socket connect failed");
}
else if ( send(v3, &buf, 0x10uLL, 0) == 16 )
{
if ( n )
send(v3, v26, n, 0);
if ( recv(v3, &buf, 0x10uLL, 256) == 16 )
{
func4(v3, v15, SHIDWORD(v20));
func3((unsigned int)v3, *((_DWORD *)&cmdInfo + 8 * v14 + 5), buf, v20);
}
else
{
func1(255, "socket receive failed");
}
}
else
{
func1(255, "socket send failed");
}
}
}
if ( v3 >= 0 )
close(v3);
return status;
}

original_code:
int main(int argc , char *argv[])
{
   int sock, command;
   int args, idx, i, pp, l, len;
   cmdCmd_t cmd;
   uintptr_t p[10];
   cmdCtlParse_t ctl;
   cmdScript_t s;
   char v[(1<<16)];
   sock = openSocket();
   args = initOpts(argc, argv);
   command_buf[0] = 0;
   l = 0;
   pp = 0;
   for (i=args; i<argc; i++)
   {
      l += (strlen(argv[i]) + 1);
      if (l < sizeof(command_buf))
         {sprintf(command_buf+pp, "%s ", argv[i]); pp=l;}
   }
   if (pp) {command_buf[--pp] = 0;}
   ctl.eaten = 0;
   len = strlen(command_buf);
   idx = 0;
   while ((idx >= 0) && (ctl.eaten < len))
   {
      if ((idx=cmdParse(command_buf, p, (1<<16), v, &ctl)) >= 0)
      {
         command = p[0];
         if (command < 800)
         {
            if (command == 25)
            {
               printf("%s", cmdUsage);
            }
            else if (command == 48)
            {
               cmdParseScript(v, &s, 1);
               if (s.par) free (s.par);
            }
            else
            {
               cmd.cmd = command;
               cmd.p1 = p[1];
               cmd.p2 = p[2];
               cmd.p3 = p[3];
               if (sock != -1)
               {
                  if (send(sock, &cmd, sizeof(cmdCmd_t), 0) ==
                     sizeof(cmdCmd_t))
                  {
                     if (p[3]) send(sock, v, p[3], 0);
                     if (recv(sock, &cmd, sizeof(cmdCmd_t), MSG_WAITALL) ==
                        sizeof(cmdCmd_t))
                     {
                        get_extensions(sock, command, cmd.res);
                        print_result(sock, cmdInfo[idx].rv, cmd);
                     }
                     else report(255, "socket receive failed");
                  }
                  else report(255, "socket send failed");
               }
               else report(255, "socket connect failed");
            }
         }
         else report(253,
                 "%s only allowed within a script", cmdInfo[idx].name);
      }
      else
      {
         if (idx == -1)
            report(253,
               "%s? unknown command, pigs h for help", cmdStr());
         else
            report(253,
               "%s: bad parameter, pigs h for help", cmdStr());
      }
   }
   if (sock >= 0) close(sock);
   return status;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int sock; int command;
   int args; int idx; int i; int pp; int l; int len;
   struct cmdCmd_t cmd;
   unsigned long p[10];
   struct cmdCtlParse_t ctl;
   struct cmdScript_t s;
   char v[-1];
   sock = openSocket();
   args = initOpts(argc, argv);
   command_buf[0] = 0;
   l = 0;
   pp = 0;
   for (i=args; i<argc; i++)
   {
      l += (strlen(argv[i]) + 1);
      if (l < sizeof(command_buf))
         {sprintf(command_buf+pp, "%s ", argv[i]); pp=l;}
   }
   if (pp) {command_buf[--pp] = 0;}
   ctl.eaten = 0;
   len = strlen(command_buf);
   idx = 0;
   while ((idx >= 0) && (ctl.eaten < len))
   {
      if ((idx=cmdParse(command_buf, p, (1<<16), v, &ctl)) >= 0)
      {
         command = p[0];
         if (command < 800)
         {
            if (command == 25)
            {
               printf("%s", cmdUsage);
            }
            else if (command == 48)
            {
               cmdParseScript(v, &s, 1);
               if (s.par) free (s.par);
            }
            else
            {
               cmd.cmd = command;
               cmd.p1 = p[1];
               cmd.p2 = p[2];
               cmd.p3 = p[3];
               if (sock != -1)
               {
                  if (send(sock, &cmd, sizeof(cmdCmd_t), 0) ==
                     sizeof(cmdCmd_t))
                  {
                     if (p[3]) send(sock, v, p[3], 0);
                     if (recv(sock, &cmd, sizeof(cmdCmd_t), MSG_WAITALL) ==
                        sizeof(cmdCmd_t))
                     {
                        get_extensions(sock, command, cmd.res);
                        print_result(sock, cmdInfo[idx].rv, cmd);
                     }
                     else report(255, "socket receive failed");
                  }
                  else report(255, "socket send failed");
               }
               else report(255, "socket connect failed");
            }
         }
         else report(253,
                 "%s only allowed within a script", cmdInfo[idx].name);
      }
      else
      {
         if (idx == -1)
            report(253,
               "%s? unknown command, pigs h for help", cmdStr());
         else
            report(253,
               "%s: bad parameter, pigs h for help", cmdStr());
      }
   }
   if (sock >= 0) close(sock);
   return status;
}

variable_types: sock int

variable_types: idx int

variable_types: pp int

variable_types: l int

variable_types: len int

variable_types:
p
unsigned long [10]

variable_types: struct cmdCtlParse_t { int eaten; char opt[4]; }

variable_types: struct cmdScript_t { int *par; int *var; struct cmdInstr_t { unsigned long p[5]; char opt[4]; } *instr; int instrs; char *str_area; int str_area_len; int str_area_pos; }

variable_types:
v
char [-1]

user_defined_types: struct cmdCmd_t { unsigned int cmd; unsigned int p1; unsigned int p2; union { unsigned int p3; unsigned int ext_len; unsigned int res; }; }

user_defined_types: struct cmdScript_t { int *par; int *var; struct cmdInstr_t *instr; int instrs; char *str_area; int str_area_len; int str_area_pos; }


timeStamp

decompiled_code:
char *timeStamp()
{
struct timeval v1; // [rsp+0h] [rbp-58h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

gettimeofday(&v1, 0LL);
localtime_r(&v1.tv_sec, &tp);
strftime(buf_0, 0x20uLL, "%F %T", &tp);
return buf_0;
}

canonical_decompiled_code:
char *func0()
{
struct timeval v1; // [rsp+0h] [rbp-58h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

gettimeofday(&v1, 0LL);
localtime_r(&v1.tv_sec, &tp);
strftime(buf_0, 0x20uLL, "%F %T", &tp);
return buf_0;
}

original_code:
static char * timeStamp()
{
   static char buf[32];
   struct timeval now;
   struct tm tmp;
   gettimeofday(&now, ((void *)0));
   localtime_r(&now.tv_sec, &tmp);
   strftime(buf, sizeof(buf), "%F %T", &tmp);
   return buf;
}

canonical_original_code:
static char *timeStamp()
{
   static char buf[32];
   struct timeval now;
   struct tm tmp;
   gettimeofday(&now, ((void *)0));
   localtime_r(&now.tv_sec, &tmp);
   strftime(buf, sizeof(buf), "%F %T", &tmp);
   return buf;
}

variable_types:
buf
char [32]

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

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

return_type: char *


symbol

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

result = (unsigned int)(a1 + 71);
if ( a1 <= 25 )
result = (unsigned int)(a1 + 65);
return result;
}

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

result = (unsigned int)(a1 + 71);
if ( a1 <= 25 )
result = (unsigned int)(a1 + 65);
return result;
}

original_code:
int symbol(int bit)
{
   if (bit < 26) return ('A' + bit);
   else return ('a' + bit - 26);
}

variable_types: bit int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
char *v4; // rax
unsigned int v5; // eax
__int64 v6; // rdx
int v7; // ebx
int v8; // er14
int v10; // er12
int v11; // er13
int v12; // ebx
__int64 v13; // rsi
unsigned int v14; // eax
char buf[4]; // [rsp+4h] [rbp-34h] BYREF
int v16; // [rsp+8h] [rbp-30h]
int v17; // [rsp+Ch] [rbp-2Ch]

if ( (unsigned int)read(0, buf, 0xCuLL) != 12 )
exit(-1);
v3 = 0;
v4 = timeStamp();
printf("$date %s $end\n", v4);
puts("$version pig2vcd V1 $end");
puts("$timescale 1 us $end");
puts("$scope module top $end");
do
{
v5 = symbol(v3);
v6 = v3++;
printf("$var wire 1 %c %d $end\n", v5, v6);
}
while ( v3 != 32 );
v7 = 0;
puts("$upscope $end");
puts("$enddefinitions $end");
v8 = v16;
while ( (unsigned int)read(0, buf, 0xCuLL) == 12 )
{
if ( v17 != v7 )
{
v10 = 0;
printf("#%u\n", (unsigned int)(v16 - v8));
v11 = v17;
v12 = v17 ^ v7;
do
{
if ( (v12 & (1 << v10)) != 0 )
{
v13 = 48 - ((unsigned int)((v17 & (1 << v10)) == 0) - 1);
v14 = symbol(v10);
printf("%c%c\n", v13, v14);
}
++v10;
}
while ( v10 != 32 );
v7 = v11;
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
char *v4; // rax
unsigned int v5; // eax
__int64 v6; // rdx
int v7; // ebx
int v8; // er14
int v10; // er12
int v11; // er13
int v12; // ebx
__int64 v13; // rsi
unsigned int v14; // eax
char buf[4]; // [rsp+4h] [rbp-34h] BYREF
int v16; // [rsp+8h] [rbp-30h]
int v17; // [rsp+Ch] [rbp-2Ch]

if ( (unsigned int)read(0, buf, 0xCuLL) != 12 )
exit(-1);
v3 = 0;
v4 = func0();
printf("$date %s $end\n", v4);
puts("$version pig2vcd V1 $end");
puts("$timescale 1 us $end");
puts("$scope module top $end");
do
{
v5 = func1(v3);
v6 = v3++;
printf("$var wire 1 %c %d $end\n", v5, v6);
}
while ( v3 != 32 );
v7 = 0;
puts("$upscope $end");
puts("$enddefinitions $end");
v8 = v16;
while ( (unsigned int)read(0, buf, 0xCuLL) == 12 )
{
if ( v17 != v7 )
{
v10 = 0;
printf("#%u\n", (unsigned int)(v16 - v8));
v11 = v17;
v12 = v17 ^ v7;
do
{
if ( (v12 & (1 << v10)) != 0 )
{
v13 = 48 - ((unsigned int)((v17 & (1 << v10)) == 0) - 1);
v14 = func1(v10);
printf("%c%c\n", v13, v14);
}
++v10;
}
while ( v10 != 32 );
v7 = v11;
}
}
return 0;
}

original_code:
int main(int argc, char * argv[])
{
   int b, r, v;
   uint32_t t0;
   uint32_t lastLevel, changed;
   gpioReport_t report;
   r=read(0, &report, (sizeof(gpioReport_t)));
   if (r != (sizeof(gpioReport_t))) exit(-1);
   printf("$date %s $end\n", timeStamp());
   printf("$version pig2vcd V1 $end\n");
   printf("$timescale 1 us $end\n");
   printf("$scope module top $end\n");
   for (b=0; b<32; b++)
      printf("$var wire 1 %c %d $end\n", symbol(b), b);
   printf("$upscope $end\n");
   printf("$enddefinitions $end\n");
   t0 = report.tick;
   lastLevel =0;
   while ((r=read(0, &report, (sizeof(gpioReport_t)))) == (sizeof(gpioReport_t)))
   {
      if (report.level != lastLevel)
      {
         printf("#%u\n", report.tick - t0);
         changed = report.level ^ lastLevel;
         lastLevel = report.level;
         for (b=0; b<32; b++)
         {
            if (changed & (1<<b))
            {
               if (report.level & (1<<b)) v='1'; else v='0';
               printf("%c%c\n", v, symbol(b));
            }
         }
      }
   }
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int b; int r; int v;
   unsigned int t0;
   unsigned int lastLevel; unsigned int changed;
   struct gpioReport_t report;
   r=read(0, &report, (sizeof(gpioReport_t)));
   if (r != (sizeof(gpioReport_t))) exit(-1);
   printf("$date %s $end\n", timeStamp());
   printf("$version pig2vcd V1 $end\n");
   printf("$timescale 1 us $end\n");
   printf("$scope module top $end\n");
   for (b=0; b<32; b++)
      printf("$var wire 1 %c %d $end\n", symbol(b), b);
   printf("$upscope $end\n");
   printf("$enddefinitions $end\n");
   t0 = report.tick;
   lastLevel =0;
   while ((r=read(0, &report, (sizeof(gpioReport_t)))) == (sizeof(gpioReport_t)))
   {
      if (report.level != lastLevel)
      {
         printf("#%u\n", report.tick - t0);
         changed = report.level ^ lastLevel;
         lastLevel = report.level;
         for (b=0; b<32; b++)
         {
            if (changed & (1<<b))
            {
               if (report.level & (1<<b)) v='1'; else v='0';
               printf("%c%c\n", v, symbol(b));
            }
         }
      }
   }
   return 0;
}

variable_types: argc int

variable_types: b int

variable_types: r int

variable_types: v int

variable_types:
lastLevel
unsigned int

variable_types:
changed
unsigned int

variable_types: struct gpioReport_t { unsigned short seqno; unsigned short flags; unsigned int tick; unsigned int level; }


dsign

repo: joao-o/prjprog

decompiled_code:
double __fastcall dsign(double a1)
{
return (double)((a1 > 0.0) - (a1 < 0.0));
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
return (double)((a1 > 0.0) - (a1 < 0.0));
}

original_code:
double
dsign (double x)
{
  return (x > 0) - (x < 0);
}

canonical_original_code:
double dsign(double x)
{
  return (x > 0) - (x < 0);
}

variable_types: x double

return_type: double


min

decompiled_code:
__m128 __fastcall min(double a1, __m128 a2)
{
*(double *)a2.m128_u64 = fmin(*(double *)a2.m128_u64, a1);
return a2;
}

canonical_decompiled_code:
__m128 __fastcall func1(double a1, __m128 a2)
{
*(double *)a2.m128_u64 = fmin(*(double *)a2.m128_u64, a1);
return a2;
}

original_code:
double
min (double x, double y)
{
  return x > y ? y : x;
}

canonical_original_code:
double min(double x, double y)
{
  return x > y ? y : x;
}

variable_types: y double


main

repo: joaomlneto/asa-jobs

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

v3 = (_QWORD *)read_input(argc, argv, envp);
hopcroft_karp(v3);
printf("%lu\n", v3[7]);
testcase_destroy(v3);
return 0;
}

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

v3 = (_QWORD *)func7(argc, argv, envp);
func15(v3);
printf("%lu\n", v3[7]);
func10(v3);
return 0;
}

original_code:
int main() {
 testcase t = read_input();
 hopcroft_karp(t);
 printf("%lu\n", t->matching);
 testcase_destroy(t);
 return 0;
}

canonical_original_code:
int main() {
 struct testcase *t = read_input();
 hopcroft_karp(t);
 printf("%lu\n", t->matching);
 testcase_destroy(t);
 return 0;
}

variable_types: struct testcase { unsigned long num_students; unsigned long num_jobs; unsigned long num_vertices; struct fifo { int size; struct fifo_item { struct fifo_item *next; unsigned long value; } *first; struct fifo_item *last; } **adjacencies; unsigned long *pair_g1; unsigned long *pair_g2; unsigned long *dist; unsigned long matching; } *

user_defined_types: struct testcase { unsigned long num_students; unsigned long num_jobs; unsigned long num_vertices; struct fifo **adjacencies; unsigned long *pair_g1; unsigned long *pair_g2; unsigned long *dist; unsigned long matching; }

user_defined_types: struct fifo { int size; struct fifo_item *first; struct fifo_item *last; }


decompiled_code:
__int64 read_input()
{
__int64 v0; // r12
unsigned __int64 i; // rbp
unsigned __int64 j; // rbx
unsigned __int64 v4; // [rsp+0h] [rbp-38h] BYREF
__int64 v5; // [rsp+8h] [rbp-30h] BYREF
unsigned __int64 v6; // [rsp+10h] [rbp-28h] BYREF
__int64 v7[4]; // [rsp+18h] [rbp-20h] BYREF

scanf("%lu", &v4);
scanf("%lu", &v5);
v0 = testcase_create(v4, v5);
if ( v4 )
{
for ( i = 0LL; i < v4; ++i )
{
scanf("%lu", &v6);
if ( v6 )
{
for ( j = 0LL; j < v6; ++j )
{
scanf("%lu", v7);
testcase_add_application(v0, i, v7[0]);
}
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // r12
unsigned __int64 i; // rbp
unsigned __int64 j; // rbx
unsigned __int64 v4; // [rsp+0h] [rbp-38h] BYREF
__int64 v5; // [rsp+8h] [rbp-30h] BYREF
unsigned __int64 v6; // [rsp+10h] [rbp-28h] BYREF
__int64 v7[4]; // [rsp+18h] [rbp-20h] BYREF

scanf("%lu", &v4);
scanf("%lu", &v5);
v0 = testcase_create(v4, v5);
if ( v4 )
{
for ( i = 0LL; i < v4; ++i )
{
scanf("%lu", &v6);
if ( v6 )
{
for ( j = 0LL; j < v6; ++j )
{
scanf("%lu", v7);
func11(v0, i, v7[0]);
}
}
}
}
return v0;
}

original_code:
testcase read_input() {
 testcase t;
 long unsigned int num_students, num_jobs;
 long unsigned int student, application, num_applications, job;
 scanf("%lu", &num_students);
 scanf("%lu", &num_jobs);
 t = testcase_create(num_students, num_jobs);
 for(student=0; student<num_students; student++) {
  scanf("%lu", &num_applications);
  for(application=0; application<num_applications; application++) {
   scanf("%lu", &job);
   testcase_add_application(t, student, job);
  }
 }
 return t;
}

canonical_original_code:
struct testcase *read_input() {
 struct testcase *t;
 unsigned long num_students; unsigned long num_jobs;
 unsigned long student; unsigned long application; unsigned long num_applications; unsigned long job;
 scanf("%lu", &num_students);
 scanf("%lu", &num_jobs);
 t = testcase_create(num_students, num_jobs);
 for(student=0; student<num_students; student++) {
  scanf("%lu", &num_applications);
  for(application=0; application<num_applications; application++) {
   scanf("%lu", &job);
   testcase_add_application(t, student, job);
  }
 }
 return t;
}

variable_types:
student
unsigned long

variable_types:
application
unsigned long

variable_types:
job
unsigned long

return_type: struct testcase { unsigned long num_students; unsigned long num_jobs; unsigned long num_vertices; struct fifo { int size; struct fifo_item { struct fifo_item *next; unsigned long value; } *first; struct fifo_item *last; } **adjacencies; unsigned long *pair_g1; unsigned long *pair_g2; unsigned long *dist; unsigned long matching; } *


decompiled_code:
__int64 __fastcall job_index(_QWORD *a1, __int64 a2)
{
return *a1 + a2 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2)
{
return *a1 + a2 + 1;
}

original_code:
long unsigned int job_index(testcase t, long unsigned int job) {
 return t->num_students + job + 1;
}

canonical_original_code:
unsigned long job_index(struct testcase *t, unsigned long job) {
 return t->num_students + job + 1;
}

return_type: unsigned long

user_defined_types: struct fifo_item { struct fifo_item *next; unsigned long value; }


decompiled_code:
__int64 __fastcall student_index(__int64 a1, __int64 a2)
{
return a2 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
return a2 + 1;
}

original_code:
long unsigned int student_index(testcase t, long unsigned int student) {
 return student + 1;
}

canonical_original_code:
unsigned long student_index(struct testcase *t, unsigned long student) {
 return student + 1;
}


decompiled_code:
void __fastcall testcase_destroy(void *ptr)
{
unsigned __int64 v2; // rbx
void *v3; // rdi

if ( *((_QWORD *)ptr + 2) )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 3) + 8 * v2++);
fifo_destroy(v3);
}
while ( *((_QWORD *)ptr + 2) > v2 );
}
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
unsigned __int64 v2; // rbx
void *v3; // rdi

if ( *((_QWORD *)ptr + 2) )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 3) + 8 * v2++);
func18(v3);
}
while ( *((_QWORD *)ptr + 2) > v2 );
}
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(ptr);
}

original_code:
void testcase_destroy(testcase t) {
 long unsigned int i;
 for(i=0; i<t->num_vertices; i++) {
  fifo_destroy(t->adjacencies[i]);
 }
 free(t->adjacencies);
 free(t->pair_g1);
 free(t->pair_g2);
 free(t->dist);
 free(t);
}

canonical_original_code:
void testcase_destroy(struct testcase *t) {
 unsigned long i;
 for(i=0; i<t->num_vertices; i++) {
  fifo_destroy(t->adjacencies[i]);
 }
 free(t->adjacencies);
 free(t->pair_g1);
 free(t->pair_g2);
 free(t->dist);
 free(t);
}

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall testcase_add_application(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v4; // r9
__int64 v5; // rbp
__int64 v6; // r8
__int64 v7; // rax

job_index(a1, a3);
v5 = student_index((__int64)a1, v4);
fifo_queue(*(_QWORD *)(a1[3] + 8 * v5), v6);
v7 = job_index(a1, a3);
return fifo_queue(*(_QWORD *)(a1[3] + 8 * v7), v5);
}

original_code:
void testcase_add_application(testcase t, long unsigned int student, long unsigned int job) {
 fifo_queue(t->adjacencies[student_index(t, student)], job_index(t, job));
 fifo_queue(t->adjacencies[job_index(t, job)], student_index(t, student));
}

canonical_original_code:
void testcase_add_application(struct testcase *t, unsigned long student, unsigned long job) {
 fifo_queue(t->adjacencies[student_index(t, student)], job_index(t, job));
 fifo_queue(t->adjacencies[job_index(t, job)], student_index(t, student));
}


decompiled_code:
int __fastcall testcase_print(_QWORD *a1)
{
unsigned __int64 v2; // rbx
__int64 v3; // rdi
int result; // eax
unsigned __int64 v5; // rbx
__int64 v6; // rsi
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // rdx

puts("==========[TESTCASE]==========");
printf("num_students = %lu\n", *a1);
printf("num_jobs = %lu\n", a1[1]);
printf("matching = %lu\n", a1[7]);
puts("=========[ADJACENCIES]=========");
if ( a1[2] )
{
v2 = 0LL;
do
{
printf("Adjacencies for vertex %lu: ", v2);
v3 = *(_QWORD *)(a1[3] + 8 * v2++);
fifo_print(v3);
putchar(10);
}
while ( a1[2] > v2 );
}
result = puts("====[OTHERS]==== (pair_g1, pair_g2, dist)");
if ( a1[2] )
{
v5 = 0LL;
do
{
v6 = v5;
v7 = *(_QWORD *)(a1[5] + 8 * v5);
v8 = *(_QWORD *)(a1[6] + 8 * v5);
v9 = *(_QWORD *)(a1[4] + 8 * v5++);
result = printf("Vertex %lu: pair_g1=%lu pair_g2=%lu dist=%lu\n", v6, v9, v7, v8);
}
while ( a1[2] > v5 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(_QWORD *a1)
{
unsigned __int64 v2; // rbx
__int64 v3; // rdi
int result; // eax
unsigned __int64 v5; // rbx
__int64 v6; // rsi
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // rdx

puts("==========[TESTCASE]==========");
printf("num_students = %lu\n", *a1);
printf("num_jobs = %lu\n", a1[1]);
printf("matching = %lu\n", a1[7]);
puts("=========[ADJACENCIES]=========");
if ( a1[2] )
{
v2 = 0LL;
do
{
printf("Adjacencies for vertex %lu: ", v2);
v3 = *(_QWORD *)(a1[3] + 8 * v2++);
func21(v3);
putchar(10);
}
while ( a1[2] > v2 );
}
result = puts("====[OTHERS]==== (pair_g1, pair_g2, dist)");
if ( a1[2] )
{
v5 = 0LL;
do
{
v6 = v5;
v7 = *(_QWORD *)(a1[5] + 8 * v5);
v8 = *(_QWORD *)(a1[6] + 8 * v5);
v9 = *(_QWORD *)(a1[4] + 8 * v5++);
result = printf("Vertex %lu: pair_g1=%lu pair_g2=%lu dist=%lu\n", v6, v9, v7, v8);
}
while ( a1[2] > v5 );
}
return result;
}

original_code:
void testcase_print(testcase t) {
 long unsigned int i;
 printf("==========[TESTCASE]==========\n");
 printf("num_students = %lu\n", t->num_students);
 printf("num_jobs = %lu\n", t->num_jobs);
 printf("matching = %lu\n", t->matching);
 printf("=========[ADJACENCIES]=========\n");
 for(i=0; i<t->num_vertices; i++) {
  printf("Adjacencies for vertex %lu: ", i);
  fifo_print(t->adjacencies[i]);
  printf("\n");
 }
 printf("====[OTHERS]==== (pair_g1, pair_g2, dist)\n");
 for(i=0; i<t->num_vertices; i++) {
  printf("Vertex %lu: pair_g1=%lu pair_g2=%lu dist=%lu\n", i, t->pair_g1[i], t->pair_g2[i], t->dist[i]);
 }
}

canonical_original_code:
void testcase_print(struct testcase *t) {
 unsigned long i;
 printf("==========[TESTCASE]==========\n");
 printf("num_students = %lu\n", t->num_students);
 printf("num_jobs = %lu\n", t->num_jobs);
 printf("matching = %lu\n", t->matching);
 printf("=========[ADJACENCIES]=========\n");
 for(i=0; i<t->num_vertices; i++) {
  printf("Adjacencies for vertex %lu: ", i);
  fifo_print(t->adjacencies[i]);
  printf("\n");
 }
 printf("====[OTHERS]==== (pair_g1, pair_g2, dist)\n");
 for(i=0; i<t->num_vertices; i++) {
  printf("Vertex %lu: pair_g1=%lu pair_g2=%lu dist=%lu\n", i, t->pair_g1[i], t->pair_g2[i], t->dist[i]);
 }
}


original_code:
_Bool hopcroft_karp_bfs(testcase t) {
 fifo q = fifo_create();
 fifo_item item;
 long unsigned int v, u;
 for(v=1; v<t->num_students+1; v++) {
  if(t->pair_g1[v] == 0) {
   t->dist[v] = 0;
   fifo_queue(q, v);
  }
  else {
   t->dist[v] = 1000000000;
  }
 }
 t->dist[0] = 1000000000;
 while(q->size != 0) {
  v = fifo_dequeue(q);
  if(t->dist[v] < t->dist[0]) {
   for(item = t->adjacencies[v]->first; item != ((void *)0); item = item->next) {
    u = item->value;
    if(t->dist[t->pair_g2[u]] == 1000000000) {
     t->dist[t->pair_g2[u]] = t->dist[v] + 1;
     fifo_queue(q, t->pair_g2[u]);
    }
   }
  }
 }
 fifo_destroy(q);
 return (t->dist[0] != 1000000000);
}

canonical_original_code:
_Bool hopcroft_karp_bfs(struct testcase *t) {
 struct fifo *q = fifo_create();
 struct fifo_item *item;
 unsigned long v; unsigned long u;
 for(v=1; v<t->num_students+1; v++) {
  if(t->pair_g1[v] == 0) {
   t->dist[v] = 0;
   fifo_queue(q, v);
  }
  else {
   t->dist[v] = 1000000000;
  }
 }
 t->dist[0] = 1000000000;
 while(q->size != 0) {
  v = fifo_dequeue(q);
  if(t->dist[v] < t->dist[0]) {
   for(item = t->adjacencies[v]->first; item != ((void *)0); item = item->next) {
    u = item->value;
    if(t->dist[t->pair_g2[u]] == 1000000000) {
     t->dist[t->pair_g2[u]] = t->dist[v] + 1;
     fifo_queue(q, t->pair_g2[u]);
    }
   }
  }
 }
 fifo_destroy(q);
 return (t->dist[0] != 1000000000);
}

variable_types: struct fifo { int size; struct fifo_item { struct fifo_item *next; unsigned long value; } *first; struct fifo_item *last; } *

variable_types:
v
unsigned long

variable_types:
u
unsigned long


original_code:
_Bool hopcroft_karp_dfs(testcase t, long unsigned int v) {
 fifo_item item;
 long unsigned int u;
 if(v == 0) {
  return 1;
 }
 for(item = t->adjacencies[v]->first; item != ((void *)0); item = item->next) {
  u = item->value;
  if(t->dist[t->pair_g2[u]] == t->dist[v] + 1) {
   if(hopcroft_karp_dfs(t, t->pair_g2[u])) {
    t->pair_g2[u] = v;
    t->pair_g1[v] = u;
    return 1;
   }
  }
 }
 t->dist[v] = 1000000000;
 return 0;
}

canonical_original_code:
_Bool hopcroft_karp_dfs(struct testcase *t, unsigned long v) {
 struct fifo_item *item;
 unsigned long u;
 if(v == 0) {
  return 1;
 }
 for(item = t->adjacencies[v]->first; item != ((void *)0); item = item->next) {
  u = item->value;
  if(t->dist[t->pair_g2[u]] == t->dist[v] + 1) {
   if(hopcroft_karp_dfs(t, t->pair_g2[u])) {
    t->pair_g2[u] = v;
    t->pair_g1[v] = u;
    return 1;
   }
  }
 }
 t->dist[v] = 1000000000;
 return 0;
}

variable_types: struct fifo_item { struct fifo_item *next; unsigned long value; } *


original_code:
long unsigned int hopcroft_karp(testcase t) {
 long unsigned int v;
 for(v=0; v<t->num_vertices; v++) {
  t->pair_g1[v] = 0;
  t->pair_g2[v] = 0;
 }
 t->matching = 0;
 while(hopcroft_karp_bfs(t)) {
  for(v=1; v<t->num_students+1; v++) {
   if(t->pair_g1[v] == 0) {
    if(hopcroft_karp_dfs(t, v)) {
     t->matching++;
    }
   }
  }
 }
 return t->matching;
}

canonical_original_code:
unsigned long hopcroft_karp(struct testcase *t) {
 unsigned long v;
 for(v=0; v<t->num_vertices; v++) {
  t->pair_g1[v] = 0;
  t->pair_g2[v] = 0;
 }
 t->matching = 0;
 while(hopcroft_karp_bfs(t)) {
  for(v=1; v<t->num_students+1; v++) {
   if(t->pair_g1[v] == 0) {
    if(hopcroft_karp_dfs(t, v)) {
     t->matching++;
    }
   }
  }
 }
 return t->matching;
}


decompiled_code:
_QWORD *fifo_create()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func16()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
fifo fifo_create() {
 fifo f = malloc(sizeof(fifo_t));
 f->size = 0;
 f->first = ((void *)0);
 f->last = ((void *)0);
 return f;
}

canonical_original_code:
struct fifo *fifo_create() {
 struct fifo *f = malloc(sizeof(fifo_t));
 f->size = 0;
 f->first = ((void *)0);
 f->last = ((void *)0);
 return f;
}

return_type: struct fifo { int size; struct fifo_item { struct fifo_item *next; unsigned long value; } *first; struct fifo_item *last; } *


decompiled_code:
__int64 __fastcall fifo_item_destroy(_QWORD *a1)
{
__int64 v1; // r12

v1 = a1[1];
free(a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func17(_QWORD *a1)
{
__int64 v1; // r12

v1 = a1[1];
free(a1);
return v1;
}

original_code:
long unsigned int fifo_item_destroy(fifo_item item) {
 long unsigned int value = item->value;
 free(item);
 return value;
}

canonical_original_code:
unsigned long fifo_item_destroy(struct fifo_item *item) {
 unsigned long value = item->value;
 free(item);
 return value;
}

variable_types:
value
unsigned long


decompiled_code:
void __fastcall fifo_destroy(void *ptr)
{
_QWORD *v2; // rbx
_QWORD *v3; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)*v2;
fifo_item_destroy(v3);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func18(void *ptr)
{
_QWORD *v2; // rbx
_QWORD *v3; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)*v2;
func17(v3);
}
free(ptr);
}

original_code:
void fifo_destroy(fifo f) {
 fifo_item item = f->first;
 fifo_item aux;
 while(item != ((void *)0)) {
  aux = item->next;
  fifo_item_destroy(item);
  item = aux;
 }
 free(f);
}

canonical_original_code:
void fifo_destroy(struct fifo *f) {
 struct fifo_item *item = f->first;
 struct fifo_item *aux;
 while(item != ((void *)0)) {
  aux = item->next;
  fifo_item_destroy(item);
  item = aux;
 }
 free(f);
}


decompiled_code:
__int64 __fastcall fifo_dequeue(__int64 a1)
{
__int64 *v1; // r8
__int64 v2; // rax

v1 = *(__int64 **)(a1 + 8);
if ( !v1 )
return -1LL;
v2 = *v1;
--*(_DWORD *)a1;
*(_QWORD *)(a1 + 8) = v2;
return fifo_item_destroy(v1);
}

original_code:
long unsigned int fifo_dequeue(fifo f) {
 fifo_item item = f->first;
 if(f->first == ((void *)0)) {
  return -1;
 }
 f->first = item->next;
 f->size--;
 return fifo_item_destroy(item);
}

canonical_original_code:
unsigned long fifo_dequeue(struct fifo *f) {
 struct fifo_item *item = f->first;
 if(f->first == ((void *)0)) {
  return -1;
 }
 f->first = item->next;
 f->size--;
 return fifo_item_destroy(item);
}


decompiled_code:
int __fastcall fifo_item_print(__int64 a1)
{
return printf("%lu", *(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func20(__int64 a1)
{
return printf("%lu", *(_QWORD *)(a1 + 8));
}

original_code:
void fifo_item_print(fifo_item item) {
 printf("%lu", item->value);
}

canonical_original_code:
void fifo_item_print(struct fifo_item *item) {
 printf("%lu", item->value);
}


decompiled_code:
int __fastcall fifo_print(unsigned int *a1)
{
_QWORD *v1; // rbx

v1 = (_QWORD *)*((_QWORD *)a1 + 1);
printf("[FIFO size=%d] ", *a1);
for ( ; v1; v1 = (_QWORD *)*v1 )
{
fifo_item_print((__int64)v1);
putchar(32);
}
return printf("[/FIFO]");
}

canonical_decompiled_code:
int __fastcall func21(unsigned int *a1)
{
_QWORD *v1; // rbx

v1 = (_QWORD *)*((_QWORD *)a1 + 1);
printf("[FIFO size=%d] ", *a1);
for ( ; v1; v1 = (_QWORD *)*v1 )
{
func20((__int64)v1);
putchar(32);
}
return printf("[/FIFO]");
}

original_code:
void fifo_print(fifo f) {
 fifo_item p = f->first;
 printf("[FIFO size=%d] ", f->size);
 while(p != ((void *)0)) {
  fifo_item_print(p);
  printf(" ");
  p = p->next;
 }
 printf("[/FIFO]");
}

canonical_original_code:
void fifo_print(struct fifo *f) {
 struct fifo_item *p = f->first;
 printf("[FIFO size=%d] ", f->size);
 while(p != ((void *)0)) {
  fifo_item_print(p);
  printf(" ");
  p = p->next;
 }
 printf("[/FIFO]");
}


deleteHeightMap

repo: joaomlneto/iaed-tetraminos

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

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

original_code:
void deleteHeightMap(HeightMap *heightMap) {
 free(heightMap);
 return;
}

canonical_original_code:
void deleteHeightMap(struct HeightMap *heightMap) {
 free(heightMap);
 return;
}

variable_types:
heightMap
struct HeightMap { int columns[10]; } *


resetHeightMap

decompiled_code:
__int64 __fastcall resetHeightMap(__int64 a1)
{
return vectorInit(a1, 10LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return vectorInit(a1, 10LL, 0LL);
}

original_code:
void resetHeightMap(HeightMap *heightMap) {
 vectorInit(heightMap->columns, 10, 0);
}

canonical_original_code:
void resetHeightMap(struct HeightMap *heightMap) {
 vectorInit(heightMap->columns, 10, 0);
}


newHeightMap

decompiled_code:
void *newHeightMap()
{
void *v0; // r12

v0 = malloc(0x28uLL);
resetHeightMap((__int64)v0);
return v0;
}

canonical_decompiled_code:
void *func2()
{
void *v0; // r12

v0 = malloc(0x28uLL);
func1((__int64)v0);
return v0;
}

original_code:
HeightMap* newHeightMap() {
 HeightMap *heightMap = malloc(sizeof(HeightMap));
 resetHeightMap(heightMap);
 return heightMap;
}

canonical_original_code:
struct HeightMap *newHeightMap() {
 struct HeightMap *heightMap = malloc(sizeof(HeightMap));
 resetHeightMap(heightMap);
 return heightMap;
}

return_type: struct HeightMap { int columns[10]; } *


getHeightMapMax

decompiled_code:
__int64 __fastcall getHeightMapMax(__int64 a1)
{
return vectorMax(a1, 10LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return vectorMax(a1, 10LL);
}

original_code:
int getHeightMapMax(HeightMap *heightMap) {
 return vectorMax(heightMap->columns, 10);
}

canonical_original_code:
int getHeightMapMax(struct HeightMap *heightMap) {
 return vectorMax(heightMap->columns, 10);
}


getColumnHeight

decompiled_code:
__int64 __fastcall getColumnHeight(__int64 a1, int a2)
{
return *(unsigned int *)(a1 + 4LL * (a2 - 1));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
return *(unsigned int *)(a1 + 4LL * (a2 - 1));
}

original_code:
int getColumnHeight(HeightMap *heightMap, int column) {
 return (heightMap->columns)[column-1];
}

canonical_original_code:
int getColumnHeight(struct HeightMap *heightMap, int column) {
 return (heightMap->columns)[column-1];
}

variable_types: column int


setColumnHeight

decompiled_code:
void __fastcall setColumnHeight(__int64 a1, int a2, int a3)
{
*(_DWORD *)(a1 + 4LL * (a2 - 1)) = a3;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, int a2, int a3)
{
*(_DWORD *)(a1 + 4LL * (a2 - 1)) = a3;
}

original_code:
void setColumnHeight(HeightMap *heightMap, int column, int height) {
 (heightMap->columns)[column-1] = height;
 return;
}

canonical_original_code:
void setColumnHeight(struct HeightMap *heightMap, int column, int height) {
 (heightMap->columns)[column-1] = height;
 return;
}

variable_types: height int


getGameAreaFirst

decompiled_code:
__int64 __fastcall getGameAreaFirst(__int64 a1)
{
return *(_QWORD *)a1;
}

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

original_code:
Line* getGameAreaFirst(GameArea *g) {
 return g->gameLineFirst;
}

canonical_original_code:
struct Line *getGameAreaFirst(struct GameArea *g) {
 return g->gameLineFirst;
}

variable_types: struct GameArea { struct Line *gameLineFirst; struct Line *gameLineLast; int num_lines; struct HeightMap { int columns[10]; } *heightMap; struct Line *deletedLinesFirst; struct Line *deletedLinesLast; int num_deleted_lines; int score; int *piece_count; } *

return_type: struct Line { struct Line *previous; struct Line *next; char column[10]; struct t_location { int hash_pos; int num_lines; struct Line **lines; } **pieces; int num_t_locations; } *

user_defined_types: struct GameArea { struct Line *gameLineFirst; struct Line *gameLineLast; int num_lines; struct HeightMap *heightMap; struct Line *deletedLinesFirst; struct Line *deletedLinesLast; int num_deleted_lines; int score; int *piece_count; }

user_defined_types: struct Line { struct Line *previous; struct Line *next; char column[10]; struct t_location **pieces; int num_t_locations; }


getGameAreaLast

decompiled_code:
__int64 __fastcall getGameAreaLast(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
Line* getGameAreaLast(GameArea *g) {
 return g->gameLineLast;
}

canonical_original_code:
struct Line *getGameAreaLast(struct GameArea *g) {
 return g->gameLineLast;
}

user_defined_types: struct t_location { int hash_pos; int num_lines; struct Line **lines; }


getGameAreaNumLines

decompiled_code:
__int64 __fastcall getGameAreaNumLines(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int getGameAreaNumLines(GameArea *g) {
 return g->num_lines;
}

canonical_original_code:
int getGameAreaNumLines(struct GameArea *g) {
 return g->num_lines;
}

variable_types: struct GameArea { struct Line { struct Line *previous; struct Line *next; char column[10]; struct t_location { int hash_pos; int num_lines; struct Line **lines; } **pieces; int num_t_locations; } *gameLineFirst; struct Line *gameLineLast; int num_lines; struct HeightMap { int columns[10]; } *heightMap; struct Line *deletedLinesFirst; struct Line *deletedLinesLast; int num_deleted_lines; int score; int *piece_count; } *


getGameAreaHeightMap

decompiled_code:
__int64 __fastcall getGameAreaHeightMap(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
HeightMap* getGameAreaHeightMap(GameArea *g) {
 return g->heightMap;
}

canonical_original_code:
struct HeightMap *getGameAreaHeightMap(struct GameArea *g) {
 return g->heightMap;
}

variable_types: struct GameArea { struct Line { struct Line *previous; struct Line *next; char column[10]; struct t_location { int hash_pos; int num_lines; struct Line **lines; } **pieces; int num_t_locations; } *gameLineFirst; struct Line *gameLineLast; int num_lines; struct HeightMap *heightMap; struct Line *deletedLinesFirst; struct Line *deletedLinesLast; int num_deleted_lines; int score; int *piece_count; } *


getGameAreaDeletedFirst

decompiled_code:
__int64 __fastcall getGameAreaDeletedFirst(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

original_code:
Line* getGameAreaDeletedFirst(GameArea *g) {
 return g->deletedLinesFirst;
}

canonical_original_code:
struct Line *getGameAreaDeletedFirst(struct GameArea *g) {
 return g->deletedLinesFirst;
}


getGameAreaDeletedLast

decompiled_code:
__int64 __fastcall getGameAreaDeletedLast(__int64 a1)
{
return *(_QWORD *)(a1 + 40);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(_QWORD *)(a1 + 40);
}

original_code:
Line* getGameAreaDeletedLast(GameArea *g) {
 return g->deletedLinesLast;
}

canonical_original_code:
struct Line *getGameAreaDeletedLast(struct GameArea *g) {
 return g->deletedLinesLast;
}


getGameAreaNumDeletedLines

decompiled_code:
__int64 __fastcall getGameAreaNumDeletedLines(__int64 a1)
{
return *(unsigned int *)(a1 + 48);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(unsigned int *)(a1 + 48);
}

original_code:
int getGameAreaNumDeletedLines(GameArea *g) {
 return g->num_deleted_lines;
}

canonical_original_code:
int getGameAreaNumDeletedLines(struct GameArea *g) {
 return g->num_deleted_lines;
}


getGameAreaScore

decompiled_code:
__int64 __fastcall getGameAreaScore(__int64 a1)
{
return *(unsigned int *)(a1 + 52);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(unsigned int *)(a1 + 52);
}

original_code:
int getGameAreaScore(GameArea *g) {
 return g->score;
}

canonical_original_code:
int getGameAreaScore(struct GameArea *g) {
 return g->score;
}


getGameAreaPieceCounts

decompiled_code:
__int64 __fastcall getGameAreaPieceCounts(__int64 a1)
{
return *(_QWORD *)(a1 + 56);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(_QWORD *)(a1 + 56);
}

original_code:
int* getGameAreaPieceCounts(GameArea *g) {
 return g->piece_count;
}

canonical_original_code:
int *getGameAreaPieceCounts(struct GameArea *g) {
 return g->piece_count;
}

return_type: int *


clearGameArea

decompiled_code:
void __fastcall clearGameArea(void *ptr)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // rsi
void *v6; // rax
__int64 v7; // rbx
__int64 v8; // rdi
void *v9; // rax

v2 = getGameAreaFirst((__int64)ptr);
if ( v2 )
{
v3 = v2;
do
{
v4 = v3;
v5 = v3;
v3 = getNextLine(v3);
eraseTLocations(ptr, v5);
deleteLine(v4);
}
while ( v3 );
}
v6 = (void *)getGameAreaHeightMap((__int64)ptr);
free(v6);
v7 = getGameAreaDeletedFirst((__int64)ptr);
while ( v7 )
{
v8 = v7;
v7 = getNextLine(v7);
deleteLine(v8);
}
v9 = (void *)getGameAreaPieceCounts((__int64)ptr);
free(v9);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // rsi
void *v6; // rax
__int64 v7; // rbx
__int64 v8; // rdi
void *v9; // rax

v2 = func0((__int64)ptr);
if ( v2 )
{
v3 = v2;
do
{
v4 = v3;
v5 = v3;
v3 = getNextLine(v3);
eraseTLocations(ptr, v5);
deleteLine(v4);
}
while ( v3 );
}
v6 = (void *)func3((__int64)ptr);
free(v6);
v7 = func4((__int64)ptr);
while ( v7 )
{
v8 = v7;
v7 = getNextLine(v7);
deleteLine(v8);
}
v9 = (void *)func8((__int64)ptr);
free(v9);
free(ptr);
}

original_code:
void clearGameArea(GameArea *gameArea) {
 Line *line, *aux;
 line = getGameAreaFirst(gameArea);
 while(line != ((void *)0)) {
  aux = getNextLine(line);
  eraseTLocations(gameArea, line);
  deleteLine(line);
  line = aux;
 }
 free(getGameAreaHeightMap(gameArea));
 line = getGameAreaDeletedFirst(gameArea);
 while(line != ((void *)0)) {
  aux = getNextLine(line);
  deleteLine(line);
  line = aux;
 }
 free(getGameAreaPieceCounts(gameArea));
 free(gameArea);
 return;
}

canonical_original_code:
void clearGameArea(struct GameArea *gameArea) {
 struct Line *line; struct Line *aux;
 line = getGameAreaFirst(gameArea);
 while(line != ((void *)0)) {
  aux = getNextLine(line);
  eraseTLocations(gameArea, line);
  deleteLine(line);
  line = aux;
 }
 free(getGameAreaHeightMap(gameArea));
 line = getGameAreaDeletedFirst(gameArea);
 while(line != ((void *)0)) {
  aux = getNextLine(line);
  deleteLine(line);
  line = aux;
 }
 free(getGameAreaPieceCounts(gameArea));
 free(gameArea);
 return;
}

variable_types: struct Line { struct Line *previous; struct Line *next; char column[10]; struct t_location { int hash_pos; int num_lines; struct Line **lines; } **pieces; int num_t_locations; } *


setGameAreaLast

decompiled_code:
void __fastcall setGameAreaLast(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

original_code:
void setGameAreaLast(GameArea *g, Line *l) {
 g->gameLineLast = l;
 return;
}

canonical_original_code:
void setGameAreaLast(struct GameArea *g, struct Line *l) {
 g->gameLineLast = l;
 return;
}

variable_types:
l
struct Line *


setGameAreaNumLines

decompiled_code:
void __fastcall setGameAreaNumLines(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
}

original_code:
void setGameAreaNumLines(GameArea *g, int n) {
 g->num_lines = n;
 return;
}

canonical_original_code:
void setGameAreaNumLines(struct GameArea *g, int n) {
 g->num_lines = n;
 return;
}

variable_types: n int


setGameAreaHeightMap

decompiled_code:
void __fastcall setGameAreaHeightMap(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 24) = a2;
}

original_code:
void setGameAreaHeightMap(GameArea *gameArea, HeightMap *heightMap) {
 gameArea->heightMap = heightMap;
 return;
}

canonical_original_code:
void setGameAreaHeightMap(struct GameArea *gameArea, struct HeightMap *heightMap) {
 gameArea->heightMap = heightMap;
 return;
}

variable_types:
heightMap
struct HeightMap *


setGameAreaDeletedFirst

decompiled_code:
void __fastcall setGameAreaDeletedFirst(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 32) = a2;
}

original_code:
void setGameAreaDeletedFirst(GameArea *gameArea, Line *l) {
 gameArea->deletedLinesFirst = l;
 return;
}

canonical_original_code:
void setGameAreaDeletedFirst(struct GameArea *gameArea, struct Line *l) {
 gameArea->deletedLinesFirst = l;
 return;
}


setGameAreaDeletedLast

decompiled_code:
void __fastcall setGameAreaDeletedLast(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 40) = a2;
}

original_code:
void setGameAreaDeletedLast(GameArea *gameArea, Line *l) {
 gameArea->deletedLinesLast = l;
 return;
}

canonical_original_code:
void setGameAreaDeletedLast(struct GameArea *gameArea, struct Line *l) {
 gameArea->deletedLinesLast = l;
 return;
}


setGameAreaNumDeletedLines

decompiled_code:
void __fastcall setGameAreaNumDeletedLines(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 48) = a2;
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 48) = a2;
}

original_code:
void setGameAreaNumDeletedLines(GameArea *gameArea, int n) {
 gameArea->num_deleted_lines = n;
 return;
}

canonical_original_code:
void setGameAreaNumDeletedLines(struct GameArea *gameArea, int n) {
 gameArea->num_deleted_lines = n;
 return;
}


setGameAreaScore

decompiled_code:
void __fastcall setGameAreaScore(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 52) = a2;
}

canonical_decompiled_code:
void __fastcall func17(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 52) = a2;
}

original_code:
void setGameAreaScore(GameArea *g, int score) {
 g->score = score;
 return;
}

canonical_original_code:
void setGameAreaScore(struct GameArea *g, int score) {
 g->score = score;
 return;
}

variable_types: score int


setGameAreaPieceCounts

decompiled_code:
void __fastcall setGameAreaPieceCounts(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 56) = a2;
}

original_code:
void setGameAreaPieceCounts(GameArea *g, int* piece_counts) {
 g->piece_count = piece_counts;
 return;
}

canonical_original_code:
void setGameAreaPieceCounts(struct GameArea *g, int *piece_counts) {
 g->piece_count = piece_counts;
 return;
}


newGameArea

decompiled_code:
void newGameArea()
{
_QWORD *v0; // r12
__int64 v1; // rax
__int64 v2; // rax

v0 = malloc(0x40uLL);
setGameAreaFirst(v0, 0LL);
setGameAreaLast((__int64)v0, 0LL);
setGameAreaNumLines((__int64)v0, 0);
v1 = newHeightMap();
setGameAreaHeightMap((__int64)v0, v1);
setGameAreaDeletedFirst((__int64)v0, 0LL);
setGameAreaDeletedLast((__int64)v0, 0LL);
setGameAreaNumDeletedLines((__int64)v0, 0);
setGameAreaScore((__int64)v0, 0);
v2 = newTHash();
setGameAreaPieceCounts((__int64)v0, v2);
}

original_code:
GameArea* newGameArea() {
 GameArea *g = malloc(sizeof(GameArea));
 setGameAreaFirst(g, ((void *)0));
 setGameAreaLast(g, ((void *)0));
 setGameAreaNumLines(g, 0);
 setGameAreaHeightMap(g, newHeightMap());
 setGameAreaDeletedFirst(g, ((void *)0));
 setGameAreaDeletedLast(g, ((void *)0));
 setGameAreaNumDeletedLines(g, 0);
 setGameAreaScore(g, 0);
 setGameAreaPieceCounts(g, newTHash());
 return g;
}

canonical_original_code:
struct GameArea *newGameArea() {
 struct GameArea *g = malloc(sizeof(GameArea));
 setGameAreaFirst(g, ((void *)0));
 setGameAreaLast(g, ((void *)0));
 setGameAreaNumLines(g, 0);
 setGameAreaHeightMap(g, newHeightMap());
 setGameAreaDeletedFirst(g, ((void *)0));
 setGameAreaDeletedLast(g, ((void *)0));
 setGameAreaNumDeletedLines(g, 0);
 setGameAreaScore(g, 0);
 setGameAreaPieceCounts(g, newTHash());
 return g;
}

return_type: struct GameArea { struct Line { struct Line *previous; struct Line *next; char column[10]; struct t_location { int hash_pos; int num_lines; struct Line **lines; } **pieces; int num_t_locations; } *gameLineFirst; struct Line *gameLineLast; int num_lines; struct HeightMap { int columns[10]; } *heightMap; struct Line *deletedLinesFirst; struct Line *deletedLinesLast; int num_deleted_lines; int score; int *piece_count; } *


getGameLine

decompiled_code:
__int64 __fastcall getGameLine(__int64 a1, int a2)
{
int v2; // eax
int v3; // ebp
__int64 v4; // rdi
int v5; // ebp
__int64 v6; // rax

v2 = getGameAreaNumLines(a1);
if ( v2 < a2 || a2 <= 0 )
return 0LL;
v3 = v2;
if ( v2 / 2 >= a2 )
{
v4 = getGameAreaFirst(a1);
if ( v4 && a2 > 1 )
{
v5 = 1;
do
{
v6 = getNextLine(v4);
++v5;
v4 = v6;
}
while ( a2 > v5 && v6 );
}
return v4;
}
v4 = getGameAreaLast(a1);
if ( v3 <= a2 )
return v4;
while ( v4 )
{
--v3;
v4 = getPreviousLine();
if ( a2 >= v3 )
return v4;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, int a2)
{
int v2; // eax
int v3; // ebp
__int64 v4; // rdi
int v5; // ebp
__int64 v6; // rax

v2 = func2(a1);
if ( v2 < a2 || a2 <= 0 )
return 0LL;
v3 = v2;
if ( v2 / 2 >= a2 )
{
v4 = func0(a1);
if ( v4 && a2 > 1 )
{
v5 = 1;
do
{
v6 = getNextLine(v4);
++v5;
v4 = v6;
}
while ( a2 > v5 && v6 );
}
return v4;
}
v4 = func1(a1);
if ( v3 <= a2 )
return v4;
while ( v4 )
{
--v3;
v4 = getPreviousLine();
if ( a2 >= v3 )
return v4;
}
return 0LL;
}

original_code:
Line* getGameLine(GameArea *g, int line_num) {
 int i;
 int num_lines = getGameAreaNumLines(g);
 Line *line;
 if (line_num > num_lines || line_num < 1) {
  return ((void *)0);
 }
 if((line_num <= (num_lines/2))) {
  line = getGameAreaFirst(g);
  for (i=1; (i<line_num && line != ((void *)0)); i++) {
   line = getNextLine(line);
  }
 }
 else {
  line = getGameAreaLast(g);
  for (i=num_lines; i>line_num && line != ((void *)0); i--) {
   line = getPreviousLine(line);
  }
 }
 return line;
}

canonical_original_code:
struct Line *getGameLine(struct GameArea *g, int line_num) {
 int i;
 int num_lines = getGameAreaNumLines(g);
 struct Line *line;
 if (line_num > num_lines || line_num < 1) {
  return ((void *)0);
 }
 if((line_num <= (num_lines/2))) {
  line = getGameAreaFirst(g);
  for (i=1; (i<line_num && line != ((void *)0)); i++) {
   line = getNextLine(line);
  }
 }
 else {
  line = getGameAreaLast(g);
  for (i=num_lines; i>line_num && line != ((void *)0); i--) {
   line = getPreviousLine(line);
  }
 }
 return line;
}

variable_types: i int


getGameAreaColumnHeight

decompiled_code:
__int64 __fastcall getGameAreaColumnHeight(__int64 a1)
{
__int64 v1; // rax

v1 = getGameAreaHeightMap(a1);
return getColumnHeight(v1);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
__int64 v1; // rax

v1 = func3(a1);
return getColumnHeight(v1);
}

original_code:
int getGameAreaColumnHeight(GameArea *gameArea, int column) {
 HeightMap *heightMap = getGameAreaHeightMap(gameArea);
 return getColumnHeight(heightMap, column);
}

canonical_original_code:
int getGameAreaColumnHeight(struct GameArea *gameArea, int column) {
 struct HeightMap *heightMap = getGameAreaHeightMap(gameArea);
 return getColumnHeight(heightMap, column);
}


setGameAreaColumnHeight

decompiled_code:
__int64 __fastcall setGameAreaColumnHeight(__int64 a1)
{
__int64 v1; // rax

v1 = getGameAreaHeightMap(a1);
return setColumnHeight(v1);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
__int64 v1; // rax

v1 = func3(a1);
return setColumnHeight(v1);
}

original_code:
void setGameAreaColumnHeight(GameArea *gameArea, int column, int height) {
 HeightMap *heightMap = getGameAreaHeightMap(gameArea);
 setColumnHeight(heightMap, column, height);
 return ;
}

canonical_original_code:
void setGameAreaColumnHeight(struct GameArea *gameArea, int column, int height) {
 struct HeightMap *heightMap = getGameAreaHeightMap(gameArea);
 setColumnHeight(heightMap, column, height);
 return ;
}


decompiled_code:
__int64 __fastcall getPosition2(__int64 a1, int a2, int a3)
{
__int64 v4; // rax

v4 = getGameLine(a1, a2);
if ( a2 <= 0 )
return 88LL;
if ( v4 )
return *(unsigned __int8 *)(a3 + getLineColumn(v4) - 1);
return 32LL;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, int a2, int a3)
{
__int64 v4; // rax

v4 = func20(a1, a2);
if ( a2 <= 0 )
return 88LL;
if ( v4 )
return *(unsigned __int8 *)(a3 + getLineColumn(v4) - 1);
return 32LL;
}

original_code:
char getPosition2(GameArea *g, int line, int column) {
 Line *l = getGameLine(g, line);
 if (line < 1) {
  return 'X';
 }
 if (l == ((void *)0)) {
  return ' ';
 }
 return ((getLineColumn(l))[column-1]);
}

canonical_original_code:
char getPosition2(struct GameArea *g, int line, int column) {
 struct Line *l = getGameLine(g, line);
 if (line < 1) {
  return 'X';
 }
 if (l == ((void *)0)) {
  return ' ';
 }
 return ((getLineColumn(l))[column-1]);
}

variable_types: line int

return_type: char


getPosition

decompiled_code:
__int64 __fastcall getPosition(__int64 a1, __int64 a2)
{
int v2; // er13
int v3; // eax

v2 = getColumn(a2);
v3 = getLine(a2);
return getPosition2(a1, v3, v2);
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, __int64 a2)
{
int v2; // er13
int v3; // eax

v2 = getColumn(a2);
v3 = getLine(a2);
return func23(a1, v3, v2);
}

original_code:
char getPosition(GameArea *g, position *position) {
 return getPosition2(g, getLine(position), getColumn(position));
}

canonical_original_code:
char getPosition(struct GameArea *g, struct position *position) {
 return getPosition2(g, getLine(position), getColumn(position));
}

variable_types: struct position { int line; int column; } *


increaseScore

decompiled_code:
void __fastcall increaseScore(__int64 a1, int a2)
{
int v2; // eax

v2 = getGameAreaScore(a1);
setGameAreaScore(a1, v2 + a2);
}

canonical_decompiled_code:
void __fastcall func25(__int64 a1, int a2)
{
int v2; // eax

v2 = func7(a1);
func17(a1, v2 + a2);
}

original_code:
void increaseScore(GameArea *gameArea, int increment) {
 int score = getGameAreaScore(gameArea);
 setGameAreaScore(gameArea, score + increment);
 return;
}

canonical_original_code:
void increaseScore(struct GameArea *gameArea, int increment) {
 int score = getGameAreaScore(gameArea);
 setGameAreaScore(gameArea, score + increment);
 return;
}

variable_types: increment int


addLine

decompiled_code:
void __fastcall addLine(_QWORD *a1)
{
__int64 v1; // r12
__int64 v2; // r13
int v3; // ebx

v1 = newLine();
v2 = getGameAreaLast((__int64)a1);
v3 = getGameAreaNumLines((__int64)a1);
if ( v2 )
{
setNextLine(v2, v1);
setPreviousLine(v1, v2);
}
else
{
setGameAreaFirst(a1, v1);
setGameAreaLast((__int64)a1, v1);
}
setGameAreaLast((__int64)a1, v1);
setGameAreaNumLines((__int64)a1, v3 + 1);
}

original_code:
void addLine(GameArea *g) {
 Line *l = newLine();
 Line *last = getGameAreaLast(g);
 int num_lines = getGameAreaNumLines(g);
 if (last == ((void *)0)) {
  setGameAreaFirst(g, l);
  setGameAreaLast(g, l);
 }
 else {
  setNextLine(last, l);
  setPreviousLine(l, last);
 }
 setGameAreaLast(g, l);
 setGameAreaNumLines(g, ++num_lines);
 return;
}

canonical_original_code:
void addLine(struct GameArea *g) {
 struct Line *l = newLine();
 struct Line *last = getGameAreaLast(g);
 int num_lines = getGameAreaNumLines(g);
 if (last == ((void *)0)) {
  setGameAreaFirst(g, l);
  setGameAreaLast(g, l);
 }
 else {
  setNextLine(last, l);
  setPreviousLine(l, last);
 }
 setGameAreaLast(g, l);
 setGameAreaNumLines(g, ++num_lines);
 return;
}


decompiled_code:
__int64 __fastcall setPosition2(_QWORD *a1, int a2, unsigned int a3, char a4)
{
int v6; // eax
int v7; // ebx
__int64 v8; // rax

v6 = getGameAreaNumLines((__int64)a1);
if ( v6 < a2 )
{
v7 = v6;
do
{
++v7;
addLine(a1);
}
while ( a2 != v7 );
}
v8 = getGameLine((__int64)a1, a2);
return setLineColumn(v8, a3, (unsigned int)a4);
}

canonical_decompiled_code:
__int64 __fastcall func27(_QWORD *a1, int a2, unsigned int a3, char a4)
{
int v6; // eax
int v7; // ebx
__int64 v8; // rax

v6 = func2((__int64)a1);
if ( v6 < a2 )
{
v7 = v6;
do
{
++v7;
func26(a1);
}
while ( a2 != v7 );
}
v8 = func20((__int64)a1, a2);
return setLineColumn(v8, a3, (unsigned int)a4);
}

original_code:
void setPosition2(GameArea *g, int line, int column, char contents) {
 int i, num_lines;
 Line *l;
 num_lines = getGameAreaNumLines(g);
 for(i=num_lines; i<line; i++) {
  addLine(g);
 }
 l = getGameLine(g, line);
 setLineColumn(l, column, contents);
 return;
}

canonical_original_code:
void setPosition2(struct GameArea *g, int line, int column, char contents) {
 int i; int num_lines;
 struct Line *l;
 num_lines = getGameAreaNumLines(g);
 for(i=num_lines; i<line; i++) {
  addLine(g);
 }
 l = getGameLine(g, line);
 setLineColumn(l, column, contents);
 return;
}

variable_types: contents char


setPosition

decompiled_code:
__int64 __fastcall setPosition(_QWORD *a1, __int64 a2, char a3)
{
unsigned int v4; // er13
int v5; // eax

v4 = getColumn(a2);
v5 = getLine(a2);
return setPosition2(a1, v5, v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func28(_QWORD *a1, __int64 a2, char a3)
{
unsigned int v4; // er13
int v5; // eax

v4 = getColumn(a2);
v5 = getLine(a2);
return func27(a1, v5, v4, a3);
}

original_code:
void setPosition(GameArea *gameArea, position *position, char contents) {
 setPosition2(gameArea, getLine(position), getColumn(position), contents);
 return;
}

canonical_original_code:
void setPosition(struct GameArea *gameArea, struct position *position, char contents) {
 setPosition2(gameArea, getLine(position), getColumn(position), contents);
 return;
}

user_defined_types: struct position { int line; int column; }


fixHeightMap

decompiled_code:
__int64 __fastcall fixHeightMap(__int64 a1)
{
int i; // ebx
int j; // er12
__int64 result; // rax

for ( i = 1; i != 11; ++i )
{
for ( j = getGameAreaColumnHeight(a1); (unsigned __int8)getPosition2(a1, j, i) == 32; --j )
;
result = setGameAreaColumnHeight(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func29(__int64 a1)
{
int i; // ebx
int j; // er12
__int64 result; // rax

for ( i = 1; i != 11; ++i )
{
for ( j = func21(a1); (unsigned __int8)func23(a1, j, i) == 32; --j )
;
result = func22(a1);
}
return result;
}

original_code:
void fixHeightMap(GameArea *gameArea) {
 int i, height;
 for (i=1; i<=10; i++) {
  height = getGameAreaColumnHeight(gameArea, i);
  while(getPosition2(gameArea, height, i) == ' ') {
   height--;
  }
  setGameAreaColumnHeight(gameArea, i, height);
 }
 return;
}

canonical_original_code:
void fixHeightMap(struct GameArea *gameArea) {
 int i; int height;
 for (i=1; i<=10; i++) {
  height = getGameAreaColumnHeight(gameArea, i);
  while(getPosition2(gameArea, height, i) == ' ') {
   height--;
  }
  setGameAreaColumnHeight(gameArea, i, height);
 }
 return;
}


insertPiece

decompiled_code:
void __fastcall insertPiece(_QWORD *a1, __int64 a2)
{
char *v2; // r14
__int64 v3; // rbx
char v4; // al
int v5; // er15
__int64 v6; // rbx
__int64 v7; // r8
int v8; // eax

v2 = (char *)getPositions(a2);
v3 = (__int64)v2;
do
{
v4 = getPieceColor(a2);
setPosition(a1, v3, v4);
v5 = getLine(v3);
getColumn(v3);
if ( (int)getGameAreaColumnHeight((__int64)a1) < v5 )
setGameAreaColumnHeight((__int64)a1);
v3 += 8LL;
}
while ( v2 + 32 != (char *)v3 );
createTLocation(a1, a2);
v6 = getGameAreaPieceCounts((__int64)a1);
v8 = getTLocationHashPos(v7);
++*(_DWORD *)(v6 + 4LL * v8);
free(v2);
}

canonical_decompiled_code:
void __fastcall func30(_QWORD *a1, __int64 a2)
{
char *v2; // r14
__int64 v3; // rbx
char v4; // al
int v5; // er15
__int64 v6; // rbx
__int64 v7; // r8
int v8; // eax

v2 = (char *)getPositions(a2);
v3 = (__int64)v2;
do
{
v4 = getPieceColor(a2);
func28(a1, v3, v4);
v5 = getLine(v3);
getColumn(v3);
if ( (int)func21((__int64)a1) < v5 )
func22((__int64)a1);
v3 += 8LL;
}
while ( v2 + 32 != (char *)v3 );
createTLocation(a1, a2);
v6 = func8((__int64)a1);
v8 = getTLocationHashPos(v7);
++*(_DWORD *)(v6 + 4LL * v8);
free(v2);
}

original_code:
void insertPiece(GameArea *g, tetromino *piece) {
 position *pos;
 t_location *tl;
 int i;
 int line;
 int column;
 pos = getPositions(piece);
 for (i=0; i<4; i++) {
  setPosition(g, &pos[i], getPieceColor(piece));
  line = getLine(&pos[i]);
  column = getColumn(&pos[i]);
  if(getGameAreaColumnHeight(g, column) < line)
   setGameAreaColumnHeight(g, column, line);
 }
 tl = createTLocation(g, piece);
 getGameAreaPieceCounts(g)[getTLocationHashPos(tl)] += 1;
 free(pos);
 return;
}

canonical_original_code:
void insertPiece(struct GameArea *g, struct tetromino *piece) {
 struct position *pos;
 struct t_location *tl;
 int i;
 int line;
 int column;
 pos = getPositions(piece);
 for (i=0; i<4; i++) {
  setPosition(g, &pos[i], getPieceColor(piece));
  line = getLine(&pos[i]);
  column = getColumn(&pos[i]);
  if(getGameAreaColumnHeight(g, column) < line)
   setGameAreaColumnHeight(g, column, line);
 }
 tl = createTLocation(g, piece);
 getGameAreaPieceCounts(g)[getTLocationHashPos(tl)] += 1;
 free(pos);
 return;
}

variable_types: struct tetromino { struct position { int line; int column; } position; int type; char color; } *

variable_types: struct t_location { int hash_pos; int num_lines; struct Line { struct Line *previous; struct Line *next; char column[10]; struct t_location **pieces; int num_t_locations; } **lines; } *

user_defined_types: struct tetromino { struct position position; int type; char color; }


minDiversityLine

decompiled_code:
__int64 __fastcall minDiversityLine(__int64 a1)
{
__int64 v1; // r12
char *v2; // r13
__int64 v3; // rax
__int64 v4; // rbp
char *v5; // rbx

v1 = (int)getGameAreaNumLines(a1);
v2 = (char *)malloc(4 * v1);
v3 = getGameAreaFirst(a1);
if ( (int)v1 > 0 )
{
v4 = v3;
v5 = v2;
do
{
v5 += 4;
*((_DWORD *)v5 - 1) = lineDiversity(v4);
v4 = getNextLine(v4);
}
while ( v5 != &v2[4 * (unsigned int)(v1 - 1) + 4] );
}
return (unsigned int)vectorMaxPos(v2, (unsigned int)v1) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func31(__int64 a1)
{
__int64 v1; // r12
char *v2; // r13
__int64 v3; // rax
__int64 v4; // rbp
char *v5; // rbx

v1 = (int)func2(a1);
v2 = (char *)malloc(4 * v1);
v3 = func0(a1);
if ( (int)v1 > 0 )
{
v4 = v3;
v5 = v2;
do
{
v5 += 4;
*((_DWORD *)v5 - 1) = lineDiversity(v4);
v4 = getNextLine(v4);
}
while ( v5 != &v2[4 * (unsigned int)(v1 - 1) + 4] );
}
return (unsigned int)vectorMaxPos(v2, (unsigned int)v1) + 1;
}

original_code:
int minDiversityLine(GameArea *gameArea) {
 int i, num_lines, *line_diversity;
 Line *line;
 num_lines = getGameAreaNumLines(gameArea);
 line_diversity = malloc(num_lines*sizeof(int));
 line = getGameAreaFirst(gameArea);
 for (i=0; i < num_lines; i++) {
  line_diversity[i] = lineDiversity(line);
  line = getNextLine(line);
 }
 return vectorMaxPos(line_diversity, num_lines) + 1;
}

canonical_original_code:
int minDiversityLine(struct GameArea *gameArea) {
 int i; int num_lines; int *line_diversity;
 struct Line *line;
 num_lines = getGameAreaNumLines(gameArea);
 line_diversity = malloc(num_lines*sizeof(int));
 line = getGameAreaFirst(gameArea);
 for (i=0; i < num_lines; i++) {
  line_diversity[i] = lineDiversity(line);
  line = getNextLine(line);
 }
 return vectorMaxPos(line_diversity, num_lines) + 1;
}


insertSortDeletedLine

decompiled_code:
void __fastcall insertSortDeletedLine(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
char *v3; // r14
char *v4; // rax
int v5; // eax
__int64 v6; // rbp
const char *v7; // r14
const char *v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
char src[50]; // [rsp+6h] [rbp-32h] BYREF

v2 = 0LL;
setPreviousLine(a2, 0LL);
v3 = src;
setNextLine(a2, 0LL);
vectorCharInit(src, 10LL, 32LL);
do
{
if ( *(_BYTE *)(getLineColumn(a2) + v2) != 32 )
*v3++ = *(_BYTE *)(getLineColumn(a2) + v2);
++v2;
}
while ( v2 != 10 );
v4 = (char *)getLineColumn(a2);
strncpy(v4, src, 0xAuLL);
v5 = getGameAreaNumDeletedLines(a1);
setGameAreaNumDeletedLines(a1, v5 + 1);
v6 = getGameAreaDeletedFirst(a1);
if ( v6 )
{
while ( 1 )
{
v7 = (const char *)getLineColumn(a2);
v8 = (const char *)getLineColumn(v6);
if ( strncmp(v8, v7, 0xAuLL) >= 0 )
break;
v6 = getNextLine(v6);
if ( !v6 )
{
v9 = getGameAreaDeletedLast(a1);
setNextLine(v9, a2);
v10 = getGameAreaDeletedLast(a1);
setPreviousLine(a2, v10);
setGameAreaDeletedLast(a1, a2);
return;
}
}
if ( getPreviousLine(v6) )
{
v11 = getPreviousLine(v6);
setNextLine(v11, a2);
v12 = getPreviousLine(v6);
setPreviousLine(a2, v12);
setNextLine(a2, v6);
setPreviousLine(v6, a2);
}
else
{
v13 = getGameAreaDeletedFirst(a1);
setPreviousLine(v13, a2);
v14 = getGameAreaDeletedFirst(a1);
setNextLine(a2, v14);
setGameAreaDeletedFirst(a1, a2);
}
}
else
{
setGameAreaDeletedFirst(a1, a2);
setGameAreaDeletedLast(a1, a2);
}
}

canonical_decompiled_code:
void __fastcall func32(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
char *v3; // r14
char *v4; // rax
int v5; // eax
__int64 v6; // rbp
const char *v7; // r14
const char *v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
char src[50]; // [rsp+6h] [rbp-32h] BYREF

v2 = 0LL;
setPreviousLine(a2, 0LL);
v3 = src;
setNextLine(a2, 0LL);
vectorCharInit(src, 10LL, 32LL);
do
{
if ( *(_BYTE *)(getLineColumn(a2) + v2) != 32 )
*v3++ = *(_BYTE *)(getLineColumn(a2) + v2);
++v2;
}
while ( v2 != 10 );
v4 = (char *)getLineColumn(a2);
strncpy(v4, src, 0xAuLL);
v5 = func6(a1);
func16(a1, v5 + 1);
v6 = func4(a1);
if ( v6 )
{
while ( 1 )
{
v7 = (const char *)getLineColumn(a2);
v8 = (const char *)getLineColumn(v6);
if ( strncmp(v8, v7, 0xAuLL) >= 0 )
break;
v6 = getNextLine(v6);
if ( !v6 )
{
v9 = func5(a1);
setNextLine(v9, a2);
v10 = func5(a1);
setPreviousLine(a2, v10);
func15(a1, a2);
return;
}
}
if ( getPreviousLine(v6) )
{
v11 = getPreviousLine(v6);
setNextLine(v11, a2);
v12 = getPreviousLine(v6);
setPreviousLine(a2, v12);
setNextLine(a2, v6);
setPreviousLine(v6, a2);
}
else
{
v13 = func4(a1);
setPreviousLine(v13, a2);
v14 = func4(a1);
setNextLine(a2, v14);
func14(a1, a2);
}
}
else
{
func14(a1, a2);
func15(a1, a2);
}
}

original_code:
void insertSortDeletedLine(GameArea *gameArea, Line* line) {
 char columns[10], *ptr;
 int i;
 Line* aux;
 setPreviousLine(line, ((void *)0));
 setNextLine(line, ((void *)0));
 vectorCharInit(columns, 10, ' ');
 ptr = columns;
 for(i=0; i<10; i++) {
  if(getLineColumn(line)[i] != ' ') {
   *(ptr++) = getLineColumn(line)[i];
  }
 }
 strncpy(getLineColumn(line), columns, 10);
 i = getGameAreaNumDeletedLines(gameArea) + 1;
 setGameAreaNumDeletedLines(gameArea, i);
 if(getGameAreaDeletedFirst(gameArea) == ((void *)0)) {
  setGameAreaDeletedFirst(gameArea, line);
  setGameAreaDeletedLast(gameArea, line);
  return;
 }
 aux = getGameAreaDeletedFirst(gameArea);
 while(aux != ((void *)0) && strncmp(getLineColumn(aux), getLineColumn(line), 10) < 0) {
  aux = getNextLine(aux);
 }
 if(aux == ((void *)0)) {
  setNextLine(getGameAreaDeletedLast(gameArea), line);
  setPreviousLine(line, getGameAreaDeletedLast(gameArea));
  setGameAreaDeletedLast(gameArea, line);
  return;
 }
 if(getPreviousLine(aux) == ((void *)0)) {
  setPreviousLine(getGameAreaDeletedFirst(gameArea), line);
  setNextLine(line, getGameAreaDeletedFirst(gameArea));
  setGameAreaDeletedFirst(gameArea, line);
  return;
 }
 setNextLine(getPreviousLine(aux), line);
 setPreviousLine(line, getPreviousLine(aux));
 setNextLine(line, aux);
 setPreviousLine(aux, line);
 return;
}

canonical_original_code:
void insertSortDeletedLine(struct GameArea *gameArea, struct Line *line) {
 char columns[10]; char *ptr;
 int i;
 struct Line *aux;
 setPreviousLine(line, ((void *)0));
 setNextLine(line, ((void *)0));
 vectorCharInit(columns, 10, ' ');
 ptr = columns;
 for(i=0; i<10; i++) {
  if(getLineColumn(line)[i] != ' ') {
   *(ptr++) = getLineColumn(line)[i];
  }
 }
 strncpy(getLineColumn(line), columns, 10);
 i = getGameAreaNumDeletedLines(gameArea) + 1;
 setGameAreaNumDeletedLines(gameArea, i);
 if(getGameAreaDeletedFirst(gameArea) == ((void *)0)) {
  setGameAreaDeletedFirst(gameArea, line);
  setGameAreaDeletedLast(gameArea, line);
  return;
 }
 aux = getGameAreaDeletedFirst(gameArea);
 while(aux != ((void *)0) && strncmp(getLineColumn(aux), getLineColumn(line), 10) < 0) {
  aux = getNextLine(aux);
 }
 if(aux == ((void *)0)) {
  setNextLine(getGameAreaDeletedLast(gameArea), line);
  setPreviousLine(line, getGameAreaDeletedLast(gameArea));
  setGameAreaDeletedLast(gameArea, line);
  return;
 }
 if(getPreviousLine(aux) == ((void *)0)) {
  setPreviousLine(getGameAreaDeletedFirst(gameArea), line);
  setNextLine(line, getGameAreaDeletedFirst(gameArea));
  setGameAreaDeletedFirst(gameArea, line);
  return;
 }
 setNextLine(getPreviousLine(aux), line);
 setPreviousLine(line, getPreviousLine(aux));
 setNextLine(line, aux);
 setPreviousLine(aux, line);
 return;
}

variable_types:
line
struct Line *

variable_types:
columns
char [10]

variable_types:
ptr
char *