decompiled_code:
__int64 __fastcall print_filename(const char *a1)
{
int v1; // eax
int v2; // ebp

v1 = open(a1, 0, 0LL);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
v2 = v1;
print_fd(v1);
close(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
int v1; // eax
int v2; // ebp

v1 = open(a1, 0, 0LL);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
v2 = v1;
func7(v1);
close(v2);
return 0LL;
}

original_code:
int
print_filename (char *filename)
{
  int fd = open (filename, 0, 00);
  if (fd < 0) return -1;
  print_fd (fd);
  close (fd);
  return 0;
}

canonical_original_code:
int print_filename(char *filename)
{
  int fd = open (filename, 0, 00);
  if (fd < 0) return -1;
  print_fd (fd);
  close (fd);
  return 0;
}

variable_types:
filename
char *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
int v5; // eax
int v6; // eax
char *v7; // rax
char *v8; // rbx
signed __int64 v9; // r13
int v10; // eax
int v11; // eax
int v12; // eax
FILE *v13; // rdi
int v14; // eax
unsigned int v15; // ebx
FILE *v16; // rdi
int v17; // eax
_DWORD v18[7]; // [rsp+0h] [rbp-1458h] BYREF
unsigned int v19; // [rsp+1Ch] [rbp-143Ch]
char buf; // [rsp+30h] [rbp-1428h] BYREF
char v21[1023]; // [rsp+31h] [rbp-1427h] BYREF
char v22; // [rsp+430h] [rbp-1028h] BYREF
char v23[4135]; // [rsp+431h] [rbp-1027h] BYREF

v3 = open("/usr/local/share/skk/SKK-JISYO.L.cdb", 0, 256LL);
if ( v3 < 0 )
exit(78);
v4 = v3;
cdb_init(v18, (unsigned int)v3);
while ( 1 )
{
v5 = fileno(stdin);
v6 = read(v5, &buf, 0x3FFuLL);
if ( v6 < 0 )
exit(66);
if ( !v6 )
break;
if ( buf == 50 )
{
v12 = fileno(stdout);
if ( write(v12, "dbskkd-cdb-3.00 ", 0x10uLL) < 0 )
goto LABEL_20;
}
else if ( buf > 50 )
{
if ( buf != 51 )
goto LABEL_21;
v11 = fileno(stdout);
if ( write(v11, "novalue: ", 9uLL) < 0 )
goto LABEL_20;
}
else
{
if ( buf == 48 )
break;
if ( buf != 49 )
goto LABEL_21;
if ( v21[0] == 32 )
goto LABEL_21;
v7 = &buf + v6 - 1;
if ( v7 == v21 )
goto LABEL_21;
v8 = v21;
do
++v8;
while ( *v8 != 32 && v8 != v7 );
v9 = v8 - v21;
if ( (_DWORD)v8 == (unsigned int)v21 )
goto LABEL_21;
v10 = cdb_find(v18, v21, (unsigned int)v9);
if ( v10 )
{
if ( v10 != 1 )
goto LABEL_17;
v15 = v19;
if ( v19 > 0xFFD )
LABEL_21:
exit(76);
v22 = 49;
if ( (int)cdb_read(v18, v23, v19, v18[6]) < 0 )
LABEL_17:
exit(70);
v16 = stdout;
v23[v15] = 10;
v17 = fileno(v16);
if ( write(v17, &v22, v15 + 2) < 0 )
goto LABEL_20;
}
else
{
buf = 52;
v13 = stdout;
*v8 = 10;
v14 = fileno(v13);
if ( write(v14, &buf, (unsigned int)(v9 + 2)) < 0 )
goto LABEL_20;
}
}
}
cdb_free(v18);
if ( !close(v4) )
exit(0);
LABEL_20:
exit(74);
}

original_code:
int main(int argc, char *argv[]) {
  char combuf[(1024)], data[(4096)];
  char *pbuf, *key, *p;
  struct cdb diccdb;
  int dicfd, ex, length;
  unsigned int keylen, datalen;
  if ((dicfd = open("/usr/local/share/skk/SKK-JISYO.L.cdb", 00, 0400)) < 0) {
    exit(78);
  }
  cdb_init(&diccdb, dicfd);
  ex = 0;
  while (!ex) {
    length = read((fileno(stdin)), &combuf[0], (1024) - 1);
    if (length < 0) {
      exit(66);
    } else if (length == 0) {
      ex = 1;
      break;
    }
    switch (combuf[0]) {
    case '0':
      ex = 1;
      break;
    case '2':
      if (write((fileno(stdout)), "dbskkd-cdb-3.00 ", sizeof("dbskkd-cdb-3.00 ") - 1) < 0) {
        exit(74);
      }
      break;
    case '3':
      if (write((fileno(stdout)), "novalue: ", sizeof("novalue: ") - 1) < 0) {
        exit(74);
      }
      break;
    case '1':
      key = &combuf[1];
      for (pbuf = &combuf[1]; *pbuf != ' ' && pbuf != &combuf[length - 1];
           pbuf++) {
      }
      keylen = pbuf - &combuf[1];
      if (keylen <= 0) {
        exit(76);
      }
      switch (cdb_find(&diccdb, key, keylen)) {
      case -1:
        exit(70);
        break;
      case 1:
        if ((datalen = ((&diccdb)->cdb_vlen)) >= (4096) - 2) {
          exit(76);
        }
        p = data;
        *p++ = '1';
        if (cdb_read(&diccdb, p, datalen, ((&diccdb)->cdb_vpos)) < 0) {
          exit(70);
        }
        p += datalen;
        *p = '\n';
        if (write((fileno(stdout)), data, datalen + 2) < 0) {
          exit(74);
        }
        break;
      case 0:
        combuf[0] = '4';
        *pbuf = '\n';
        if (write((fileno(stdout)), combuf, keylen + 2) < 0) {
          exit(74);
        }
        break;
      default:
        exit(70);
        break;
      }
      break;
    default:
      exit(76);
    }
  }
  cdb_free(&diccdb);
  if (close(dicfd) != 0) {
    exit(74);
  }
  exit(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
  char combuf[-1]; char data[-1];
  char *pbuf; char *key; char *p;
  struct cdb diccdb;
  int dicfd; int ex; int length;
  unsigned int keylen; unsigned int datalen;
  if ((dicfd = open("/usr/local/share/skk/SKK-JISYO.L.cdb", 00, 0400)) < 0) {
    exit(78);
  }
  cdb_init(&diccdb, dicfd);
  ex = 0;
  while (!ex) {
    length = read((fileno(stdin)), &combuf[0], (1024) - 1);
    if (length < 0) {
      exit(66);
    } else if (length == 0) {
      ex = 1;
      break;
    }
    switch (combuf[0]) {
    case '0':
      ex = 1;
      break;
    case '2':
      if (write((fileno(stdout)), "dbskkd-cdb-3.00 ", sizeof("dbskkd-cdb-3.00 ") - 1) < 0) {
        exit(74);
      }
      break;
    case '3':
      if (write((fileno(stdout)), "novalue: ", sizeof("novalue: ") - 1) < 0) {
        exit(74);
      }
      break;
    case '1':
      key = &combuf[1];
      for (pbuf = &combuf[1]; *pbuf != ' ' && pbuf != &combuf[length - 1];
           pbuf++) {
      }
      keylen = pbuf - &combuf[1];
      if (keylen <= 0) {
        exit(76);
      }
      switch (cdb_find(&diccdb, key, keylen)) {
      case -1:
        exit(70);
        break;
      case 1:
        if ((datalen = ((&diccdb)->cdb_vlen)) >= (4096) - 2) {
          exit(76);
        }
        p = data;
        *p++ = '1';
        if (cdb_read(&diccdb, p, datalen, ((&diccdb)->cdb_vpos)) < 0) {
          exit(70);
        }
        p += datalen;
        *p = '\n';
        if (write((fileno(stdout)), data, datalen + 2) < 0) {
          exit(74);
        }
        break;
      case 0:
        combuf[0] = '4';
        *pbuf = '\n';
        if (write((fileno(stdout)), combuf, keylen + 2) < 0) {
          exit(74);
        }
        break;
      default:
        exit(70);
        break;
      }
      break;
    default:
      exit(76);
    }
  }
  cdb_free(&diccdb);
  if (close(dicfd) != 0) {
    exit(74);
  }
  exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
combuf
char [-1]

variable_types:
data
char [-1]

variable_types:
pbuf
char *

variable_types:
key
char *

variable_types:
p
char *

variable_types: struct cdb { int cdb_fd; unsigned int cdb_fsize; unsigned int cdb_dend; unsigned char *cdb_mem; unsigned int cdb_vpos; unsigned int cdb_kpos; }

variable_types: dicfd int

variable_types: ex int

variable_types: length int

variable_types:
keylen
unsigned int

variable_types:
datalen
unsigned int

return_type: int


repo: jmahler/socket-examples

decompiled_code:
__int64 __fastcall mac_lookup(char *s2, char *s1, char *dest)
{
char *v4; // rbx

if ( !s2 )
return 0LL;
v4 = s2;
do
{
if ( !strcmp(s1, v4) )
{
strcpy(dest, v4 + 46);
return 1LL;
}
v4 = (char *)*((_QWORD *)v4 + 12);
}
while ( v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s2, char *s1, char *dest)
{
char *v4; // rbx

if ( !s2 )
return 0LL;
v4 = s2;
do
{
if ( !strcmp(s1, v4) )
{
strcpy(dest, v4 + 46);
return 1LL;
}
v4 = (char *)*((_QWORD *)v4 + 12);
}
while ( v4 );
return 0LL;
}

original_code:
int mac_lookup(struct arptable *p, char *ip, char *mac)
{
 if (((void *)0) == p)
  return 0;
 if (0 == strcmp(ip, p->ip)) {
  strcpy(mac, p->mac);
  return 1;
 }
 return mac_lookup(p->next, ip, mac);
}

variable_types: struct arptable { char ip[46]; char mac[46]; struct arptable *next; } *

variable_types:
ip
char *

variable_types:
mac
char *


decompiled_code:
void __fastcall free_arptable(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 12);
free(v2);
}
while ( v1 );
}
}

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

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 12);
free(v2);
}
while ( v1 );
}
}

original_code:
void free_arptable(struct arptable *p)
{
 struct arptable *pn;
 if (((void *)0) == p)
  return;
 pn = p->next;
 free(p);
 free_arptable(pn);
}

return_type: void

user_defined_types: struct arptable { char ip[46]; char mac[46]; struct arptable *next; }


decompiled_code:
__int64 __fastcall process_calculations(int fd)
{
ssize_t v2; // rax
int v3; // er12
double v4; // xmm0_8
signed __int64 v5; // rbx
ssize_t v6; // rax
const char *v7; // rdi
float v8; // xmm0_4
char v10; // [rsp+7h] [rbp-7F1h]
float v11; // [rsp+8h] [rbp-7F0h]
float v12; // [rsp+Ch] [rbp-7ECh]
char buf[2024]; // [rsp+10h] [rbp-7E8h] BYREF

LABEL_1:
v2 = recv(fd, buf, 0x7D0uLL, 0);
if ( v2 < 0 )
{
v7 = "recv";
goto LABEL_14;
}
if ( v2 )
{
v3 = __isoc99_sscanf();
v4 = NAN;
v5 = strlen(buf) + 1;
if ( v3 > 2 )
{
if ( v10 == 45 )
{
v4 = (float)(v11 - v12);
}
else if ( v10 > 45 )
{
if ( v10 == 47 )
{
v4 = (float)(v11 / v12);
}
else if ( v10 == 94 )
{
v8 = pow(v11, v12);
v4 = v8;
}
}
else if ( v10 == 42 )
{
v4 = (float)(v11 * v12);
}
else if ( v10 == 43 )
{
v4 = (float)(v11 + v12);
}
}
sprintf(buf, "%g", v4);
if ( (unsigned __int64)v5 <= 0x14 )
{
buf[19] = 0;
v5 = 20LL;
}
while ( 1 )
{
v6 = send(fd, buf, v5, 0);
if ( v6 < 0 )
break;
v5 -= v6;
if ( v5 <= 0 )
goto LABEL_1;
}
v7 = "send";
LABEL_14:
perror(v7);
if ( close(fd) >= 0 )
goto LABEL_15;
goto LABEL_24;
}
if ( close(fd) < 0 )
{
LABEL_24:
perror("close");
LABEL_15:
exit(-1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd)
{
ssize_t v2; // rax
int v3; // er12
double v4; // xmm0_8
signed __int64 v5; // rbx
ssize_t v6; // rax
const char *v7; // rdi
float v8; // xmm0_4
char v10; // [rsp+7h] [rbp-7F1h]
float v11; // [rsp+8h] [rbp-7F0h]
float v12; // [rsp+Ch] [rbp-7ECh]
char buf[2024]; // [rsp+10h] [rbp-7E8h] BYREF

LABEL_1:
v2 = recv(fd, buf, 0x7D0uLL, 0);
if ( v2 < 0 )
{
v7 = "recv";
goto LABEL_14;
}
if ( v2 )
{
v3 = __isoc99_sscanf();
v4 = NAN;
v5 = strlen(buf) + 1;
if ( v3 > 2 )
{
if ( v10 == 45 )
{
v4 = (float)(v11 - v12);
}
else if ( v10 > 45 )
{
if ( v10 == 47 )
{
v4 = (float)(v11 / v12);
}
else if ( v10 == 94 )
{
v8 = pow(v11, v12);
v4 = v8;
}
}
else if ( v10 == 42 )
{
v4 = (float)(v11 * v12);
}
else if ( v10 == 43 )
{
v4 = (float)(v11 + v12);
}
}
sprintf(buf, "%g", v4);
if ( (unsigned __int64)v5 <= 0x14 )
{
buf[19] = 0;
v5 = 20LL;
}
while ( 1 )
{
v6 = send(fd, buf, v5, 0);
if ( v6 < 0 )
break;
v5 -= v6;
if ( v5 <= 0 )
goto LABEL_1;
}
v7 = "send";
LABEL_14:
perror(v7);
if ( close(fd) >= 0 )
goto LABEL_15;
goto LABEL_24;
}
if ( close(fd) < 0 )
{
LABEL_24:
perror("close");
LABEL_15:
exit(-1);
}
return 0LL;
}

original_code:
int process_calculations(int sockfd) {
 char expression[2000];
 ssize_t expression_len = 0;
 char done = 0;
 while (!done) {
  if ( (expression_len = recv(sockfd, expression, 2000, 0)) < 0 ) {
   perror("recv");
   if (close(sockfd) < 0) {
    perror("close");
   }
   exit(-1);
  } else if (0 == expression_len) {
   if (close(sockfd) < 0) {
    perror("close"); exit(-1);
   }
   done = 1;
  } else {
   float a, b, answer;
   char op;
   int ret = sscanf(expression, "%g%c%g", &a, &op, &b);
   ssize_t exp_len = strlen(expression) + 1, len, sent_len = 0;
   if ( (ret == (-1)) || (ret < 3) ) {
    answer = (__builtin_nanf (""));
   } else {
    switch(op) {
     case '*': answer = a * b; break;
     case '/': answer = a / b; break;
     case '+': answer = a + b; break;
     case '-': answer = a - b; break;
     case '^': answer = pow(a,b); break;
     default: answer = (__builtin_nanf ("")); break;
    }
   }
   sprintf(expression, "%g", answer);
   if (exp_len > 20) {
    len = exp_len;
   } else {
    len = 20;
    expression[20 -1] = '\0';
   }
   while (len > 0) {
    if ( (sent_len = send(sockfd, expression, len, 0)) < 0) {
     perror("send");
     if (close(sockfd) < 0) {
      perror("close");
     }
     exit(-1);
    }
    len -= sent_len;
   }
  }
 }
 return 0;
}

canonical_original_code:
int process_calculations(int sockfd) {
 char expression[2000];
 long expression_len = 0;
 char done = 0;
 while (!done) {
  if ( (expression_len = recv(sockfd, expression, 2000, 0)) < 0 ) {
   perror("recv");
   if (close(sockfd) < 0) {
    perror("close");
   }
   exit(-1);
  } else if (0 == expression_len) {
   if (close(sockfd) < 0) {
    perror("close"); exit(-1);
   }
   done = 1;
  } else {
   float a; float b; float answer;
   char op;
   int ret = sscanf(expression, "%g%c%g", &a, &op, &b);
   long exp_len = strlen(expression) + 1; long len; long sent_len = 0;
   if ( (ret == (-1)) || (ret < 3) ) {
    answer = (__builtin_nanf (""));
   } else {
    switch(op) {
     case '*': answer = a * b; break;
     case '/': answer = a / b; break;
     case '+': answer = a + b; break;
     case '-': answer = a - b; break;
     case '^': answer = pow(a,b); break;
     default: answer = (__builtin_nanf ("")); break;
    }
   }
   sprintf(expression, "%g", answer);
   if (exp_len > 20) {
    len = exp_len;
   } else {
    len = 20;
    expression[20 -1] = '\0';
   }
   while (len > 0) {
    if ( (sent_len = send(sockfd, expression, len, 0)) < 0) {
     perror("send");
     if (close(sockfd) < 0) {
      perror("close");
     }
     exit(-1);
    }
    len -= sent_len;
   }
  }
 }
 return 0;
}

variable_types: sockfd int

variable_types:
expression
char [2000]

variable_types: done char

variable_types: a float

variable_types: b float

variable_types: answer float

variable_types: op char

variable_types: ret int

variable_types: len long


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rsi
int v4; // eax
int v5; // er12
int v6; // eax
int v7; // ebp
const char *v9; // rdx
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

if ( argc != 2 )
{
fprintf(stderr, "Usage: %s <listen port>\n", *argv);
LABEL_19:
exit(1);
}
v3 = argv[1];
*(_OWORD *)&req.ai_socktype = 0LL;
req.ai_next = 0LL;
*(_QWORD *)&req.ai_flags = 0x200000001LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_addr = 0LL;
v4 = getaddrinfo(0LL, v3, &req, &pai);
if ( v4 )
{
v9 = gai_strerror(v4);
fprintf(stderr, "%s\n", v9);
goto LABEL_19;
}
if ( pai->ai_next )
{
fwrite("ERROR: Multiple addresses to choose from", 1uLL, 0x28uLL, stderr);
exit(1);
}
v5 = socket(2, 1, 0);
if ( v5 < 0 )
{
perror("socket");
exit(1);
}
if ( bind(v5, pai->ai_addr, pai->ai_addrlen) < 0 )
{
perror("bind");
exit(1);
}
freeaddrinfo(pai);
pai = 0LL;
if ( listen(v5, 10) < 0 )
{
perror("listen");
exit(1);
}
while ( 1 )
{
v6 = accept(v5, 0LL, 0LL);
v7 = v6;
if ( v6 < 0 )
break;
if ( (unsigned int)process_calculations(v6) )
goto LABEL_12;
close(v7);
}
perror("accept");
LABEL_12:
if ( close(v5) < 0 )
perror("close");
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rsi
int v4; // eax
int v5; // er12
int v6; // eax
int v7; // ebp
const char *v9; // rdx
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

if ( argc != 2 )
{
fprintf(stderr, "Usage: %s <listen port>\n", *argv);
LABEL_19:
exit(1);
}
v3 = argv[1];
*(_OWORD *)&req.ai_socktype = 0LL;
req.ai_next = 0LL;
*(_QWORD *)&req.ai_flags = 0x200000001LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_addr = 0LL;
v4 = getaddrinfo(0LL, v3, &req, &pai);
if ( v4 )
{
v9 = gai_strerror(v4);
fprintf(stderr, "%s\n", v9);
goto LABEL_19;
}
if ( pai->ai_next )
{
fwrite("ERROR: Multiple addresses to choose from", 1uLL, 0x28uLL, stderr);
exit(1);
}
v5 = socket(2, 1, 0);
if ( v5 < 0 )
{
perror("socket");
exit(1);
}
if ( bind(v5, pai->ai_addr, pai->ai_addrlen) < 0 )
{
perror("bind");
exit(1);
}
freeaddrinfo(pai);
pai = 0LL;
if ( listen(v5, 10) < 0 )
{
perror("listen");
exit(1);
}
while ( 1 )
{
v6 = accept(v5, 0LL, 0LL);
v7 = v6;
if ( v6 < 0 )
break;
if ( (unsigned int)func7(v6) )
goto LABEL_12;
close(v7);
}
perror("accept");
LABEL_12:
if ( close(v5) < 0 )
perror("close");
return -1;
}

original_code:
int main(int argc, char *argv[]) {
 struct addrinfo hints;
 struct addrinfo *results;
 int res = 0;
 int sockfd = -1;
 if (argc != 2) {
  fprintf(stderr, "Usage: %s <listen port>\n", argv[0]);
  exit(1);
 }
 memset(&hints, 0, sizeof(struct addrinfo));
 hints.ai_family = 2;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_flags = 0x0001;
 if ( (res = getaddrinfo(((void *)0), argv[1], &hints, &results)) != 0 ) {
  fprintf(stderr, "%s\n", gai_strerror(res));
  exit(1);
 }
 if (results->ai_next != ((void *)0)) {
  fprintf(stderr, "ERROR: Multiple addresses to choose from");
  exit(1);
 }
 if ( (sockfd = socket(2, SOCK_STREAM, 0)) < 0) {
  perror("socket");
  exit(1);
 }
 if (bind(sockfd, results->ai_addr, results->ai_addrlen) < 0) {
  perror("bind");
  exit(1);
 }
 freeaddrinfo(results);
 results = 0;
 if (listen(sockfd, 10) < 0) {
  perror("listen");
  exit(1);
 }
 while(1) {
  int new_conn;
  int err;
  new_conn = accept(sockfd, ((void *)0), ((void *)0));
  if (new_conn < 0) {
   perror("accept");
   if (close(sockfd) < 0) { perror("close"); }
   return -1;
  }
  err = process_calculations(new_conn);
  if (err) {
   if (close(sockfd) < 0) { perror("close"); }
   return -1;
  }
  close(new_conn);
 }
 if (close(sockfd) < 0) {
  perror("close");
  return -1;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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: res int

variable_types: err 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; }


decompiled_code:
void int_handler()
{
quit = 1;
}

canonical_decompiled_code:
void func7()
{
quit = 1;
}

original_code:
void int_handler() {
 quit = 1;
}

canonical_original_code:
void int_handler() {
 quit = 1;
}


decompiled_code:
void reset_seq()
{
recv_seq = -1;
}

canonical_decompiled_code:
void func8()
{
recv_seq = -1;
}

original_code:
void reset_seq() {
 recv_seq = -1;
}

canonical_original_code:
void reset_seq() {
 recv_seq = -1;
}


decompiled_code:
int __fastcall arq_sendto(int fd, __int64 *a2, unsigned __int64 a3, unsigned int a4, __int64 a5, unsigned int a6)
{
unsigned __int64 v9; // r15
int result; // eax
int v11; // eax
char v12; // [rsp+7h] [rbp-B11h]
int v13; // [rsp+Ch] [rbp-B0Ch]
struct timeval timeout; // [rsp+10h] [rbp-B08h] BYREF
fd_set readfds; // [rsp+20h] [rbp-AF8h] BYREF
char buf; // [rsp+A0h] [rbp-A78h] BYREF
unsigned __int8 v17; // [rsp+A1h] [rbp-A77h]
char v18[2]; // [rsp+5C0h] [rbp-558h] BYREF
__int64 v19[170]; // [rsp+5C2h] [rbp-556h] BYREF

if ( a3 > 0x512 )
a3 = 1298LL;
v9 = a3 + 2;
if ( (unsigned int)a3 >= 8 )
{
v19[0] = *a2;
*(__int64 *)((char *)&v19[-1] + (unsigned int)a3) = *(__int64 *)((char *)a2 + (unsigned int)a3 - 8);
qmemcpy(
(char *)v19 + 6,
(char *)a2 - ((char *)v19 - ((char *)v19 + 6)),
8LL * (((unsigned int)a3 + (unsigned int)((char *)v19 - ((char *)v19 + 6))) >> 3));
}
else if ( (a3 & 4) != 0 )
{
LODWORD(v19[0]) = *(_DWORD *)a2;
*(_DWORD *)((char *)v19 + (unsigned int)a3 - 4) = *(_DWORD *)((char *)a2 + (unsigned int)a3 - 4);
}
else if ( (_DWORD)a3 )
{
LOBYTE(v19[0]) = *(_BYTE *)a2;
if ( (a3 & 2) != 0 )
*(_WORD *)&v18[(unsigned int)a3] = *(_WORD *)((char *)a2 + (unsigned int)a3 - 2);
}
v12 = 0;
v18[0] = 1;
v18[1] = seq;
while ( 1 )
{
v13 = unreliable_sendto((unsigned int)fd, v18, v9, a4, a5, a6);
if ( v13 == -1 )
break;
memset(&readfds, 0, sizeof(readfds));
timeout.tv_sec = 0LL;
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
timeout.tv_usec = 500LL;
result = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( result == -1 )
break;
if ( result )
{
v11 = recvfrom(fd, &buf, 2uLL, 0, 0LL, 0LL);
if ( v11 == -1 )
return -1;
if ( v11 > 1 && !buf && v17 == seq )
{
result = v13 - 2;
seq = v17 == 0;
return result;
}
}
else if ( (unsigned __int8)++v12 > 3u )
{
return result;
}
}
return -1;
}

canonical_decompiled_code:
int __fastcall func9(int fd, __int64 *a2, unsigned __int64 a3, unsigned int a4, __int64 a5, unsigned int a6)
{
unsigned __int64 v9; // r15
int result; // eax
int v11; // eax
char v12; // [rsp+7h] [rbp-B11h]
int v13; // [rsp+Ch] [rbp-B0Ch]
struct timeval timeout; // [rsp+10h] [rbp-B08h] BYREF
fd_set readfds; // [rsp+20h] [rbp-AF8h] BYREF
char buf; // [rsp+A0h] [rbp-A78h] BYREF
unsigned __int8 v17; // [rsp+A1h] [rbp-A77h]
char v18[2]; // [rsp+5C0h] [rbp-558h] BYREF
__int64 v19[170]; // [rsp+5C2h] [rbp-556h] BYREF

if ( a3 > 0x512 )
a3 = 1298LL;
v9 = a3 + 2;
if ( (unsigned int)a3 >= 8 )
{
v19[0] = *a2;
*(__int64 *)((char *)&v19[-1] + (unsigned int)a3) = *(__int64 *)((char *)a2 + (unsigned int)a3 - 8);
qmemcpy(
(char *)v19 + 6,
(char *)a2 - ((char *)v19 - ((char *)v19 + 6)),
8LL * (((unsigned int)a3 + (unsigned int)((char *)v19 - ((char *)v19 + 6))) >> 3));
}
else if ( (a3 & 4) != 0 )
{
LODWORD(v19[0]) = *(_DWORD *)a2;
*(_DWORD *)((char *)v19 + (unsigned int)a3 - 4) = *(_DWORD *)((char *)a2 + (unsigned int)a3 - 4);
}
else if ( (_DWORD)a3 )
{
LOBYTE(v19[0]) = *(_BYTE *)a2;
if ( (a3 & 2) != 0 )
*(_WORD *)&v18[(unsigned int)a3] = *(_WORD *)((char *)a2 + (unsigned int)a3 - 2);
}
v12 = 0;
v18[0] = 1;
v18[1] = seq;
while ( 1 )
{
v13 = func11((unsigned int)fd, v18, v9, a4, a5, a6);
if ( v13 == -1 )
break;
memset(&readfds, 0, sizeof(readfds));
timeout.tv_sec = 0LL;
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
timeout.tv_usec = 500LL;
result = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( result == -1 )
break;
if ( result )
{
v11 = recvfrom(fd, &buf, 2uLL, 0, 0LL, 0LL);
if ( v11 == -1 )
return -1;
if ( v11 > 1 && !buf && v17 == seq )
{
result = v13 - 2;
seq = v17 == 0;
return result;
}
}
else if ( (unsigned __int8)++v12 > 3u )
{
return result;
}
}
return -1;
}

original_code:
int arq_sendto(int sockfd, const void *buf, size_t len,
  int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
{
 int n;
 struct timeval tv;
 fd_set rd_set;
 struct arq_packet ack_buf;
 struct arq_packet sbuf;
 size_t send_len, data_len;
 unsigned char ack_recvd;
 unsigned char num_resend;
 send_len = 2 + ( ((len) < (1300 - 2)) ? (len) : (1300 - 2));
 memcpy(&sbuf.data, buf, ( ((len) < (1300 - 2)) ? (len) : (1300 - 2)));
 sbuf.seq = seq;
 sbuf.type = TYPE_DATA;
 ack_recvd = 0;
 num_resend = 0;
 while (!ack_recvd) {
  n = unreliable_sendto(sockfd, &sbuf, send_len, flags,
    dest_addr, addrlen);
  if (-1 == n) {
   return -1;
  }
  data_len = n - 2;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd_set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rd_set)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
  tv.tv_sec = 0;
  tv.tv_usec = 0.5*1000;
  n = select(sockfd+1, &rd_set, ((void *)0), ((void *)0), &tv);
  if (-1 == n) {
   return -1;
  } else if (0 == n) {
   if (++num_resend > 3)
    return 0;
   continue;
  }
  n = recvfrom(sockfd, (void *) &ack_buf, 2, 0, ((void *)0), ((void *)0));
  if (-1 == n) {
   return -1;
  }
  if (n >= 2 && ack_buf.type == TYPE_ACK
    && ack_buf.seq == seq) {
   seq = (seq) ? 0 : 1;
   ack_recvd = 1;
  }
 }
 return data_len;
}

canonical_original_code:
int arq_sendto(int sockfd, void *buf, unsigned long len, int flags, struct sockaddr *dest_addr, unsigned int addrlen)
{
 int n;
 struct timeval tv;
 struct fd_set rd_set;
 struct arq_packet ack_buf;
 struct arq_packet sbuf;
 unsigned long send_len; unsigned long data_len;
 unsigned char ack_recvd;
 unsigned char num_resend;
 send_len = 2 + ( ((len) < (1300 - 2)) ? (len) : (1300 - 2));
 memcpy(&sbuf.data, buf, ( ((len) < (1300 - 2)) ? (len) : (1300 - 2)));
 sbuf.seq = seq;
 sbuf.type = TYPE_DATA;
 ack_recvd = 0;
 num_resend = 0;
 while (!ack_recvd) {
  n = unreliable_sendto(sockfd, &sbuf, send_len, flags,
    dest_addr, addrlen);
  if (-1 == n) {
   return -1;
  }
  data_len = n - 2;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd_set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rd_set)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
  tv.tv_sec = 0;
  tv.tv_usec = 0.5*1000;
  n = select(sockfd+1, &rd_set, ((void *)0), ((void *)0), &tv);
  if (-1 == n) {
   return -1;
  } else if (0 == n) {
   if (++num_resend > 3)
    return 0;
   continue;
  }
  n = recvfrom(sockfd, (void *) &ack_buf, 2, 0, ((void *)0), ((void *)0));
  if (-1 == n) {
   return -1;
  }
  if (n >= 2 && ack_buf.type == TYPE_ACK
    && ack_buf.seq == seq) {
   seq = (seq) ? 0 : 1;
   ack_recvd = 1;
  }
 }
 return data_len;
}

variable_types:
buf
void *

variable_types:
len
unsigned long

variable_types: flags int

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

variable_types:
addrlen
unsigned int

variable_types: n int

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

variable_types: struct arq_packet { unsigned char type; unsigned char seq; char data[-1]; }


decompiled_code:
__int64 __fastcall arq_recvfrom(int fd, void *a2, unsigned __int64 a3, int a4, __m128i *a5, socklen_t *a6)
{
size_t v9; // r12
socklen_t v10; // er15
int v11; // eax
unsigned int v12; // er12
socklen_t v14; // eax
unsigned __int8 v15; // [rsp+Fh] [rbp-A99h]
socklen_t addr_len; // [rsp+1Ch] [rbp-A8Ch] BYREF
struct sockaddr dest; // [rsp+20h] [rbp-A88h] BYREF
char v18; // [rsp+30h] [rbp-A78h] BYREF
unsigned __int8 v19; // [rsp+31h] [rbp-A77h]
char buf; // [rsp+550h] [rbp-558h] BYREF
unsigned __int8 v21; // [rsp+551h] [rbp-557h]
char src[1366]; // [rsp+552h] [rbp-556h] BYREF

if ( a3 > 0x512 )
a3 = 1298LL;
v9 = a3 + 2;
while ( 1 )
{
if ( a5 )
{
v10 = *a6;
memcpy(&dest, a5, *a6);
addr_len = v10;
}
else
{
addr_len = 16;
}
v11 = recvfrom(fd, &buf, v9, a4, &dest, &addr_len);
if ( v11 == -1 )
return (unsigned int)-1;
if ( recv_seq == -1 )
recv_seq = v21 == 0;
if ( v11 > 1 && buf == 1 && v21 != recv_seq )
break;
v19 = v21;
v18 = 0;
if ( (unsigned int)unreliable_sendto((unsigned int)fd, &v18, 2LL, 0LL, &dest, addr_len) == -1 )
return (unsigned int)-1;
}
v12 = v11 - 2;
v15 = v21;
memcpy(a2, src, v11 - 2);
v18 = 0;
v19 = v15;
recv_seq = recv_seq == 0;
if ( (unsigned int)unreliable_sendto((unsigned int)fd, &v18, 2LL, 0LL, &dest, addr_len) == -1 )
return (unsigned int)-1;
if ( a5 )
{
v14 = addr_len;
*a5 = _mm_loadu_si128((const __m128i *)&dest);
*a6 = v14;
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, void *a2, unsigned __int64 a3, int a4, __m128i *a5, socklen_t *a6)
{
size_t v9; // r12
socklen_t v10; // er15
int v11; // eax
unsigned int v12; // er12
socklen_t v14; // eax
unsigned __int8 v15; // [rsp+Fh] [rbp-A99h]
socklen_t addr_len; // [rsp+1Ch] [rbp-A8Ch] BYREF
struct sockaddr dest; // [rsp+20h] [rbp-A88h] BYREF
char v18; // [rsp+30h] [rbp-A78h] BYREF
unsigned __int8 v19; // [rsp+31h] [rbp-A77h]
char buf; // [rsp+550h] [rbp-558h] BYREF
unsigned __int8 v21; // [rsp+551h] [rbp-557h]
char src[1366]; // [rsp+552h] [rbp-556h] BYREF

if ( a3 > 0x512 )
a3 = 1298LL;
v9 = a3 + 2;
while ( 1 )
{
if ( a5 )
{
v10 = *a6;
memcpy(&dest, a5, *a6);
addr_len = v10;
}
else
{
addr_len = 16;
}
v11 = recvfrom(fd, &buf, v9, a4, &dest, &addr_len);
if ( v11 == -1 )
return (unsigned int)-1;
if ( recv_seq == -1 )
recv_seq = v21 == 0;
if ( v11 > 1 && buf == 1 && v21 != recv_seq )
break;
v19 = v21;
v18 = 0;
if ( (unsigned int)func11((unsigned int)fd, &v18, 2LL, 0LL, &dest, addr_len) == -1 )
return (unsigned int)-1;
}
v12 = v11 - 2;
v15 = v21;
memcpy(a2, src, v11 - 2);
v18 = 0;
v19 = v15;
recv_seq = recv_seq == 0;
if ( (unsigned int)func11((unsigned int)fd, &v18, 2LL, 0LL, &dest, addr_len) == -1 )
return (unsigned int)-1;
if ( a5 )
{
v14 = addr_len;
*a5 = _mm_loadu_si128((const __m128i *)&dest);
*a6 = v14;
}
return v12;
}

original_code:
int arq_recvfrom(int sockfd, void *buf, size_t len,
  int flags, struct sockaddr *src_addr, socklen_t *addrlen)
{
 int n;
 struct arq_packet ack_buf;
 struct sockaddr cliaddr;
 socklen_t cliaddr_len;
 struct arq_packet rbuf;
 size_t recv_len, data_len;
 unsigned char data_recvd;
 recv_len = 0;
 data_len = 0;
 data_recvd = 0;
 while (!data_recvd) {
  if (src_addr != ((void *)0)) {
   memcpy(&cliaddr, src_addr, *addrlen);
   cliaddr_len = *addrlen;
  } else {
   cliaddr_len = sizeof(cliaddr);
  }
  recv_len = 2 + ( ((len) < (1300 - 2)) ? (len) : (1300 - 2));
  n = recvfrom(sockfd, &rbuf, recv_len, flags,
    &cliaddr, &cliaddr_len);
  if (-1 == n) {
   return -1;
  }
  if (-1 == recv_seq) {
   recv_seq = rbuf.seq ? 0 : 1;
  }
  if (n >= 2 && rbuf.type == TYPE_DATA
    && rbuf.seq != recv_seq) {
   data_len = n - 2;
   memcpy(buf, rbuf.data, data_len);
   recv_seq = recv_seq ? 0 : 1;
   data_recvd = 1;
  }
  ack_buf.seq = rbuf.seq;
  ack_buf.type = TYPE_ACK;
  n = unreliable_sendto(sockfd, &ack_buf, 2, 0,
    &cliaddr, cliaddr_len);
  if (-1 == n) {
   return -1;
  }
 }
 if (src_addr != ((void *)0)) {
  memcpy(src_addr, &cliaddr, sizeof(cliaddr));
  *addrlen = cliaddr_len;
 }
 return data_len;
}

canonical_original_code:
int arq_recvfrom(int sockfd, void *buf, unsigned long len, int flags, struct sockaddr *src_addr, unsigned int *addrlen)
{
 int n;
 struct arq_packet ack_buf;
 struct sockaddr cliaddr;
 unsigned int cliaddr_len;
 struct arq_packet rbuf;
 unsigned long recv_len; unsigned long data_len;
 unsigned char data_recvd;
 recv_len = 0;
 data_len = 0;
 data_recvd = 0;
 while (!data_recvd) {
  if (src_addr != ((void *)0)) {
   memcpy(&cliaddr, src_addr, *addrlen);
   cliaddr_len = *addrlen;
  } else {
   cliaddr_len = sizeof(cliaddr);
  }
  recv_len = 2 + ( ((len) < (1300 - 2)) ? (len) : (1300 - 2));
  n = recvfrom(sockfd, &rbuf, recv_len, flags,
    &cliaddr, &cliaddr_len);
  if (-1 == n) {
   return -1;
  }
  if (-1 == recv_seq) {
   recv_seq = rbuf.seq ? 0 : 1;
  }
  if (n >= 2 && rbuf.type == TYPE_DATA
    && rbuf.seq != recv_seq) {
   data_len = n - 2;
   memcpy(buf, rbuf.data, data_len);
   recv_seq = recv_seq ? 0 : 1;
   data_recvd = 1;
  }
  ack_buf.seq = rbuf.seq;
  ack_buf.type = TYPE_ACK;
  n = unreliable_sendto(sockfd, &ack_buf, 2, 0,
    &cliaddr, cliaddr_len);
  if (-1 == n) {
   return -1;
  }
 }
 if (src_addr != ((void *)0)) {
  memcpy(src_addr, &cliaddr, sizeof(cliaddr));
  *addrlen = cliaddr_len;
 }
 return data_len;
}

variable_types: sockfd int

variable_types:
addrlen
unsigned int *

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

user_defined_types: struct arq_packet { unsigned char type; unsigned char seq; char data[-1]; }


decompiled_code:
ssize_t __fastcall unreliable_sendto(int a1, const void *a2, size_t a3, int a4, const struct sockaddr *a5, socklen_t a6)
{
ssize_t result; // rax

if ( (++rand & 6) == 6 )
result = a3;
else
result = sendto(a1, a2, a3, a4, a5, a6);
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func11(int a1, const void *a2, size_t a3, int a4, const struct sockaddr *a5, socklen_t a6)
{
ssize_t result; // rax

if ( (++rand & 6) == 6 )
result = a3;
else
result = sendto(a1, a2, a3, a4, a5, a6);
return result;
}

original_code:
ssize_t unreliable_sendto(int sockfd, const void *buf, size_t len, int flags,
   const struct sockaddr *dest_addr, socklen_t addrlen)
{
 rand++;
 if (rand & 0x4 && rand & 0x2)
  return len;
 else
  return sendto(sockfd, buf, len, flags, dest_addr, addrlen);
}

canonical_original_code:
long unreliable_sendto(int sockfd, void *buf, unsigned long len, int flags, struct sockaddr *dest_addr, unsigned int addrlen)
{
 rand++;
 if (rand & 0x4 && rand & 0x2)
  return len;
 else
  return sendto(sockfd, buf, len, flags, dest_addr, addrlen);
}

return_type: long

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


repo: jwerle/slylang

decompiled_code:
int __fastcall sly_token_inspect(int *a1)
{
char *v1; // rax

v1 = sly_token_name_isra_0(*a1);
printf("[%s] =>\n", v1);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func1(int *a1)
{
char *v1; // rax

v1 = func0(*a1);
printf("[%s] =>\n", v1);
return putchar(10);
}

original_code:
void
sly_token_inspect (sly_token_t *token) {
  printf("[%s] =>\n", sly_token_name(token));
  switch (token->type) {
  }
  printf("\n");
}

canonical_original_code:
void sly_token_inspect(struct sly_token_s *token) {
  printf("[%s] =>\n", sly_token_name(token));
  switch (token->type) {
  }
  printf("\n");
}

variable_types: struct sly_token_s { enum sly_token_type_t { SLY_TOKEN_ILLEGAL=0, SLY_TOKEN_EOF=1, SLY_TOKEN_IDENTIFIER=2, SLY_TOKEN_UNDEFINED=3, SLY_TOKEN_NULL=4, SLY_TOKEN_UNDEFINE=5, SLY_TOKEN_DEFINE=6, SLY_TOKEN_LET=7, SLY_TOKEN_VAR=8, SLY_TOKEN_IMPORT=9, SLY_TOKEN_EXPORT=10, SLY_TOKEN_IN=11, SLY_TOKEN_FOR=12, SLY_TOKEN_WHILE=13, SLY_TOKEN_SWITCH=14, SLY_TOKEN_CASE=15, SLY_TOKEN_BREAK=16, SLY_TOKEN_DEFAULT=17, SLY_TOKEN_IF=18, SLY_TOKEN_ELSE=19, SLY_TOKEN_RETURN=20, SLY_TOKEN_FREE=21, SLY_TOKEN_DELETE=22, SLY_TOKEN_TYPEDEF=23, SLY_TOKEN_TYPEOF=24, SLY_TOKEN_STRING=25, SLY_TOKEN_INT=26, SLY_TOKEN_FLOAT=27, SLY_TOKEN_HEX=28, SLY_TOKEN_UNICODE=29, SLY_TOKEN_LBRACE=30, SLY_TOKEN_RBRACE=31, SLY_TOKEN_LBRACKET=32, SLY_TOKEN_RBRACKET=33, SLY_TOKEN_LPAREN=34, SLY_TOKEN_RPAREN=35, SLY_TOKEN_SEMICOLON=36, SLY_TOKEN_COLON=37, SLY_TOKEN_QMARK=38, SLY_TOKEN_COMMA=39, SLY_TOKEN_OP_DOT=40, SLY_TOKEN_OP_NEGATE=41, SLY_TOKEN_OP_PLUS=42, SLY_TOKEN_OP_INCREMENT=43, SLY_TOKEN_OP_MINUS=44, SLY_TOKEN_OP_DECREMENT=45, SLY_TOKEN_OP_MULTIPLY=46, SLY_TOKEN_OP_DIVIDE=47, SLY_TOKEN_OP_MODULO=48, SLY_TOKEN_OP_GT=49, SLY_TOKEN_OP_LT=50, SLY_TOKEN_OP_GTE=51, SLY_TOKEN_OP_LTE=52, SLY_TOKEN_OP_EQ=53, SLY_TOKEN_OP_NEQ=54, SLY_TOKEN_OP_AND=55, SLY_TOKEN_OP_OR=56, SLY_TOKEN_OP_ASSIGN=57, SLY_TOKEN_OP_PLUS_ASSIGN=58, SLY_TOKEN_OP_MINUS_ASSIGN=59, SLY_TOKEN_OP_MULTIPLY_ASSIGN=60, SLY_TOKEN_OP_DIVIDE_ASSIGN=61, SLY_TOKEN_OP_BITWISE_AND=62, SLY_TOKEN_OP_BITWISE_AND_ASSIGN=63, SLY_TOKEN_OP_BITWISE_OR=64, SLY_TOKEN_OP_BITWISE_OR_ASSIGN=65, SLY_TOKEN_OP_BITWISE_XOR=66, SLY_TOKEN_OP_BITWISE_XOR_ASSIGN=67, SLY_TOKEN_OP_BITWISE_NOT=68, SLY_TOKEN_OP_BITWISE_SHIFT_LEFT=69, SLY_TOKEN_OP_BITWISE_SHIFT_LEFT_ASSIGN=70, SLY_TOKEN_OP_BITWISE_SHIFT_RIGHT=71, SLY_TOKEN_OP_BITWISE_SHIFT_RIGHT_ASSIGN=72, SLY_TOKEN_OP_BITWISE_UNSIGNED_SHIFT_RIGHT=73, SLY_TOKEN_OP_BITWISE_UNSIGNED_SHIFT_RIGHT_ASSIGN=74 } type; int length; struct sly_token_coerce_s { char *as_string; float as_float; int as_int; } value; } *

user_defined_types: struct sly_token_s { enum sly_token_type_t type; int length; struct sly_token_coerce_s value; }


decompiled_code:
_QWORD *buffer_new()
{
return buffer_new_with_size(64LL);
}

canonical_decompiled_code:
_QWORD *func0()
{
return buffer_new_with_size(64LL);
}

original_code:
buffer_t *
buffer_new() {
  return buffer_new_with_size(64);
}

canonical_original_code:
struct buffer_t *buffer_new() {
  return buffer_new_with_size(64);
}

return_type: struct buffer_t { unsigned long len; char *alloc; char *data; } *


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

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

original_code:
void
buffer_free(buffer_t *self) {
  free(self->alloc);
  free(self);
}

canonical_original_code:
void buffer_free(struct buffer_t *self) {
  free(self->alloc);
  free(self);
}

variable_types: struct buffer_t { unsigned long len; char *alloc; char *data; } *


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

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

original_code:
size_t
buffer_size(buffer_t *self) {
  return self->len;
}

canonical_original_code:
unsigned long buffer_size(struct buffer_t *self) {
  return self->len;
}

return_type: unsigned long

user_defined_types: struct buffer_t { unsigned long len; char *alloc; char *data; }


decompiled_code:
size_t __fastcall buffer_length(__int64 a1)
{
return strlen(*(const char **)(a1 + 16));
}

canonical_decompiled_code:
size_t __fastcall func3(__int64 a1)
{
return strlen(*(const char **)(a1 + 16));
}

original_code:
size_t
buffer_length(buffer_t *self) {
  return strlen(self->data);
}

canonical_original_code:
unsigned long buffer_length(struct buffer_t *self) {
  return strlen(self->data);
}


decompiled_code:
__int64 __fastcall buffer_compact(__int64 a1)
{
size_t v1; // rbp
__int64 v2; // r13
void *v3; // rax
void *v4; // r12
__int64 result; // rax

v1 = buffer_length(a1);
v2 = *(_QWORD *)a1 - v1;
v3 = calloc(v1 + 1, 1uLL);
if ( !v3 )
return -1LL;
v4 = v3;
memcpy(v3, *(const void **)(a1 + 16), v1);
free(*(void **)(a1 + 8));
*(_QWORD *)a1 = v1;
result = v2;
*(_QWORD *)(a1 + 8) = v4;
*(_QWORD *)(a1 + 16) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
size_t v1; // rbp
__int64 v2; // r13
void *v3; // rax
void *v4; // r12
__int64 result; // rax

v1 = func3(a1);
v2 = *(_QWORD *)a1 - v1;
v3 = calloc(v1 + 1, 1uLL);
if ( !v3 )
return -1LL;
v4 = v3;
memcpy(v3, *(const void **)(a1 + 16), v1);
free(*(void **)(a1 + 8));
*(_QWORD *)a1 = v1;
result = v2;
*(_QWORD *)(a1 + 8) = v4;
*(_QWORD *)(a1 + 16) = v4;
return result;
}

original_code:
ssize_t
buffer_compact(buffer_t *self) {
  size_t len = buffer_length(self);
  size_t rem = self->len - len;
  char *buf = calloc(len + 1, 1);
  if (!buf) return -1;
  memcpy(buf, self->data, len);
  free(self->alloc);
  self->len = len;
  self->data = self->alloc = buf;
  return rem;
}

canonical_original_code:
long buffer_compact(struct buffer_t *self) {
  unsigned long len = buffer_length(self);
  unsigned long rem = self->len - len;
  char *buf = calloc(len + 1, 1);
  if (!buf) return -1;
  memcpy(buf, self->data, len);
  free(self->alloc);
  self->len = len;
  self->data = self->alloc = buf;
  return rem;
}

variable_types:
rem
unsigned long

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall buffer_resize(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rbx
_BYTE *v3; // rax

v2 = (a2 + 1023) & 0xFFFFFFFFFFFFFC00LL;
*(_QWORD *)a1 = v2;
v3 = realloc(*(void **)(a1 + 8), v2 + 1);
*(_QWORD *)(a1 + 16) = v3;
*(_QWORD *)(a1 + 8) = v3;
if ( !v3 )
return 0xFFFFFFFFLL;
v3[v2] = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rbx
_BYTE *v3; // rax

v2 = (a2 + 1023) & 0xFFFFFFFFFFFFFC00LL;
*(_QWORD *)a1 = v2;
v3 = realloc(*(void **)(a1 + 8), v2 + 1);
*(_QWORD *)(a1 + 16) = v3;
*(_QWORD *)(a1 + 8) = v3;
if ( !v3 )
return 0xFFFFFFFFLL;
v3[v2] = 0;
return 0LL;
}

original_code:
int
buffer_resize(buffer_t *self, size_t n) {
  n = (((n) + ((1024) - 1)) & ~((1024) - 1));
  self->len = n;
  self->alloc = self->data = realloc(self->alloc, n + 1);
  if (!self->alloc) return -1;
  self->alloc[n] = '\0';
  return 0;
}

canonical_original_code:
int buffer_resize(struct buffer_t *self, unsigned long n) {
  n = (((n) + ((1024) - 1)) & ~((1024) - 1));
  self->len = n;
  self->alloc = self->data = realloc(self->alloc, n + 1);
  if (!self->alloc) return -1;
  self->alloc[n] = '\0';
  return 0;
}

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall buffer_append(__int64 a1, const char *a2)
{
size_t v2; // rax
const char *v3; // r13
size_t v4; // rbp
size_t v5; // rax
__int64 result; // rax

v2 = strlen(a2);
v3 = *(const char **)(a1 + 16);
v4 = v2;
v5 = strlen(v3);
if ( *(_QWORD *)a1 > v4 + v5 )
{
memcpy((void *)&v3[v5], a2, v4 + 1);
result = 0LL;
}
else
{
result = buffer_resize(a1, v4 + v5);
if ( (_DWORD)result != -1 )
{
strcat(*(char **)(a1 + 16), a2);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
size_t v2; // rax
const char *v3; // r13
size_t v4; // rbp
size_t v5; // rax
__int64 result; // rax

v2 = strlen(a2);
v3 = *(const char **)(a1 + 16);
v4 = v2;
v5 = strlen(v3);
if ( *(_QWORD *)a1 > v4 + v5 )
{
memcpy((void *)&v3[v5], a2, v4 + 1);
result = 0LL;
}
else
{
result = func5(a1, v4 + v5);
if ( (_DWORD)result != -1 )
{
strcat(*(char **)(a1 + 16), a2);
result = 0LL;
}
}
return result;
}

original_code:
int
buffer_append(buffer_t *self, char *str) {
  size_t len = strlen(str);
  size_t prev = strlen(self->data);
  size_t needed = len + prev;
  if (self->len > needed) {
    strcat(self->data, str);
    return 0;
  }
  int ret = buffer_resize(self, needed);
  if (-1 == ret) return -1;
  strcat(self->data, str);
  return 0;
}

canonical_original_code:
int buffer_append(struct buffer_t *self, char *str) {
  unsigned long len = strlen(str);
  unsigned long prev = strlen(self->data);
  unsigned long needed = len + prev;
  if (self->len > needed) {
    strcat(self->data, str);
    return 0;
  }
  int ret = buffer_resize(self, needed);
  if (-1 == ret) return -1;
  strcat(self->data, str);
  return 0;
}

variable_types:
str
char *

variable_types:
prev
unsigned long

variable_types:
needed
unsigned long

variable_types: ret int


decompiled_code:
__int64 __fastcall buffer_prepend(__int64 a1, const char *a2)
{
size_t v3; // rax
const char *v4; // r13
size_t v5; // r12
unsigned __int64 v6; // rsi
__int64 result; // rax

v3 = strlen(a2);
v4 = *(const char **)(a1 + 16);
v5 = v3;
v6 = v3 + strlen(v4);
if ( *(_QWORD *)a1 > v6 )
goto LABEL_2;
result = buffer_resize(a1, v6);
if ( (_DWORD)result != -1 )
{
v4 = *(const char **)(a1 + 16);
LABEL_2:
memmove((void *)&v4[v5], v4, v5 + 1);
memcpy(*(void **)(a1 + 16), a2, v5);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
size_t v3; // rax
const char *v4; // r13
size_t v5; // r12
unsigned __int64 v6; // rsi
__int64 result; // rax

v3 = strlen(a2);
v4 = *(const char **)(a1 + 16);
v5 = v3;
v6 = v3 + strlen(v4);
if ( *(_QWORD *)a1 > v6 )
goto LABEL_2;
result = func5(a1, v6);
if ( (_DWORD)result != -1 )
{
v4 = *(const char **)(a1 + 16);
LABEL_2:
memmove((void *)&v4[v5], v4, v5 + 1);
memcpy(*(void **)(a1 + 16), a2, v5);
result = 0LL;
}
return result;
}

original_code:
int
buffer_prepend(buffer_t *self, char *str) {
  size_t len = strlen(str);
  size_t prev = strlen(self->data);
  size_t needed = len + prev;
  if (self->len > needed) goto move;
  int ret = buffer_resize(self, needed);
  if (-1 == ret) return -1;
  move:
  memmove(self->data + len, self->data, len + 1);
  memcpy(self->data, str, len);
  return 0;
}

canonical_original_code:
int buffer_prepend(struct buffer_t *self, char *str) {
  unsigned long len = strlen(str);
  unsigned long prev = strlen(self->data);
  unsigned long needed = len + prev;
  if (self->len > needed) goto move;
  int ret = buffer_resize(self, needed);
  if (-1 == ret) return -1;
  move:
  memmove(self->data + len, self->data, len + 1);
  memcpy(self->data, str, len);
  return 0;
}

variable_types:
len
unsigned long


decompiled_code:
_BOOL8 __fastcall buffer_equals(__int64 a1, __int64 a2)
{
return strcmp(*(const char **)(a1 + 16), *(const char **)(a2 + 16)) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1, __int64 a2)
{
return strcmp(*(const char **)(a1 + 16), *(const char **)(a2 + 16)) == 0;
}

original_code:
int
buffer_equals(buffer_t *self, buffer_t *other) {
  return 0 == strcmp(self->data, other->data);
}

canonical_original_code:
int buffer_equals(struct buffer_t *self, struct buffer_t *other) {
  return 0 == strcmp(self->data, other->data);
}

variable_types:
other
struct buffer_t *


decompiled_code:
__int64 __fastcall buffer_indexof(__int64 a1, const char *a2)
{
const char *v2; // rbx
char *v3; // rax
__int64 result; // rax

v2 = *(const char **)(a1 + 16);
v3 = strstr(v2, a2);
if ( v3 )
result = v3 - v2;
else
result = -1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const char *a2)
{
const char *v2; // rbx
char *v3; // rax
__int64 result; // rax

v2 = *(const char **)(a1 + 16);
v3 = strstr(v2, a2);
if ( v3 )
result = v3 - v2;
else
result = -1LL;
return result;
}

original_code:
ssize_t
buffer_indexof(buffer_t *self, char *str) {
  char *sub = strstr(self->data, str);
  if (!sub) return -1;
  return sub - self->data;
}

canonical_original_code:
long buffer_indexof(struct buffer_t *self, char *str) {
  char *sub = strstr(self->data, str);
  if (!sub) return -1;
  return sub - self->data;
}

variable_types:
sub
char *


decompiled_code:
void __fastcall buffer_trim_left(__int64 a1)
{
char *v1; // rbp
__int64 v2; // rbx
const unsigned __int16 *v3; // rdx
char *v4; // rax

v1 = *(char **)(a1 + 16);
v2 = *v1;
if ( (_BYTE)v2 )
{
v3 = *_ctype_b_loc();
v4 = v1 + 1;
do
{
if ( (v3[v2] & 0x2000) == 0 )
break;
*(_QWORD *)(a1 + 16) = v4;
v2 = *v4++;
}
while ( (_BYTE)v2 );
}
}

original_code:
void
buffer_trim_left(buffer_t *self) {
  int c;
  while ((c = *self->data) && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
    ++self->data;
  }
}

canonical_original_code:
void buffer_trim_left(struct buffer_t *self) {
  int c;
  while ((c = *self->data) && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
    ++self->data;
  }
}

variable_types: c int


decompiled_code:
size_t __fastcall buffer_trim_right(__int64 a1)
{
size_t result; // rax
size_t v2; // rbp
_BYTE *v3; // r12
__int64 v4; // rbx
const unsigned __int16 **v5; // rdx

result = buffer_length(a1);
v2 = result - 1;
v3 = (_BYTE *)(result - 1 + *(_QWORD *)(a1 + 16));
v4 = (char)*v3;
if ( (_BYTE)v4 )
{
v5 = _ctype_b_loc();
do
{
result = (size_t)*v5;
if ( ((*v5)[v4] & 0x2000) == 0 )
break;
*v3 = 0;
v3 = (_BYTE *)(--v2 + *(_QWORD *)(a1 + 16));
v4 = (char)*v3;
}
while ( (_BYTE)v4 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func11(__int64 a1)
{
size_t result; // rax
size_t v2; // rbp
_BYTE *v3; // r12
__int64 v4; // rbx
const unsigned __int16 **v5; // rdx

result = func3(a1);
v2 = result - 1;
v3 = (_BYTE *)(result - 1 + *(_QWORD *)(a1 + 16));
v4 = (char)*v3;
if ( (_BYTE)v4 )
{
v5 = _ctype_b_loc();
do
{
result = (size_t)*v5;
if ( ((*v5)[v4] & 0x2000) == 0 )
break;
*v3 = 0;
v3 = (_BYTE *)(--v2 + *(_QWORD *)(a1 + 16));
v4 = (char)*v3;
}
while ( (_BYTE)v4 );
}
return result;
}

original_code:
void
buffer_trim_right(buffer_t *self) {
  int c;
  size_t i = buffer_length(self) - 1;
  while ((c = self->data[i]) && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
    self->data[i--] = 0;
  }
}

canonical_original_code:
void buffer_trim_right(struct buffer_t *self) {
  int c;
  unsigned long i = buffer_length(self) - 1;
  while ((c = self->data[i]) && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
    self->data[i--] = 0;
  }
}

variable_types:
i
unsigned long


decompiled_code:
size_t __fastcall buffer_trim(__int64 a1)
{
buffer_trim_left(a1);
return buffer_trim_right(a1);
}

canonical_decompiled_code:
size_t __fastcall func12(__int64 a1)
{
func10(a1);
return func11(a1);
}

original_code:
void
buffer_trim(buffer_t *self) {
  buffer_trim_left(self);
  buffer_trim_right(self);
}

canonical_original_code:
void buffer_trim(struct buffer_t *self) {
  buffer_trim_left(self);
  buffer_trim_right(self);
}


decompiled_code:
void *__fastcall buffer_fill(__int64 a1, int a2)
{
return memset(*(void **)(a1 + 16), a2, *(_QWORD *)a1);
}

canonical_decompiled_code:
void *__fastcall func13(__int64 a1, int a2)
{
return memset(*(void **)(a1 + 16), a2, *(_QWORD *)a1);
}

original_code:
void
buffer_fill(buffer_t *self, int c) {
  memset(self->data, c, self->len);
}

canonical_original_code:
void buffer_fill(struct buffer_t *self, int c) {
  memset(self->data, c, self->len);
}


decompiled_code:
void *__fastcall buffer_clear(__int64 a1)
{
return buffer_fill(a1, 0);
}

canonical_decompiled_code:
void *__fastcall func14(__int64 a1)
{
return func13(a1, 0);
}

original_code:
void
buffer_clear(buffer_t *self) {
  buffer_fill(self, 0);
}

canonical_original_code:
void buffer_clear(struct buffer_t *self) {
  buffer_fill(self, 0);
}


decompiled_code:
int __fastcall buffer_print(__int64 *a1)
{
__int64 v1; // r12
__int64 v2; // rbx

v1 = *a1;
printf("\n ");
if ( v1 )
{
v2 = 1LL;
printf(" %02x", (unsigned int)*(char *)a1[1]);
while ( v1 != v2 )
{
printf(" %02x", (unsigned int)*(char *)(a1[1] + v2));
if ( (((_BYTE)v2 + 1) & 7) == 0 )
printf("\n ");
++v2;
}
}
return putchar(10);
}

original_code:
void
buffer_print(buffer_t *self) {
  size_t len = self->len;
  printf("\n ");
  for (int i = 0; i < len; ++i) {
    printf(" %02x", self->alloc[i]);
    if ((i + 1) % 8 == 0) printf("\n ");
  }
  printf("\n");
}

canonical_original_code:
void buffer_print(struct buffer_t *self) {
  unsigned long len = self->len;
  printf("\n ");
  for (int i = 0; i < len; ++i) {
    printf(" %02x", self->alloc[i]);
    if ((i + 1) % 8 == 0) printf("\n ");
  }
  printf("\n");
}

variable_types: i int


ok

decompiled_code:
int __fastcall ok(const char *a1)
{
const char *v1; // rdx

v1 = a1;
if ( !a1 )
v1 = (const char *)&LC0;
return printf("ok %d %s\n", (unsigned int)++ok_count_, v1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
const char *v1; // rdx

v1 = a1;
if ( !a1 )
v1 = (const char *)&LC0;
return printf("ok %d %s\n", (unsigned int)++ok_count_, v1);
}

original_code:
void
ok (char *message) {
  if (((void *)0) == message) {
    message = "";
  }
  printf("ok %d %s\n", ++ok_count_, message);
}

canonical_original_code:
void ok(char *message) {
  if (((void *)0) == message) {
    message = "";
  }
  printf("ok %d %s\n", ++ok_count_, message);
}

variable_types:
message
char *


decompiled_code:
int ok_done()
{
if ( ok_expected_ && ok_expected_ != ok_count_ )
{
fwrite("expected number of success conditions not met.\n", 1uLL, 0x2FuLL, stderr);
exit(1);
}
return printf("1..%d\n", (unsigned int)ok_count_);
}

canonical_decompiled_code:
int func1()
{
if ( ok_expected_ && ok_expected_ != ok_count_ )
{
fwrite("expected number of success conditions not met.\n", 1uLL, 0x2FuLL, stderr);
exit(1);
}
return printf("1..%d\n", (unsigned int)ok_count_);
}

original_code:
void
ok_done (void) {
  if (0 != ok_expected_ &&
      ok_count_ != ok_expected_) {
    fprintf(stderr, "expected number of success conditions not met.\n");
    exit(1);
  }
  printf("1..%d\n", ok_count_);
}

canonical_original_code:
void ok_done() {
  if (0 != ok_expected_ &&
      ok_count_ != ok_expected_) {
    fprintf(stderr, "expected number of success conditions not met.\n");
    exit(1);
  }
  printf("1..%d\n", ok_count_);
}


decompiled_code:
void __fastcall ok_expect(int a1)
{
ok_expected_ = a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
ok_expected_ = a1;
}

original_code:
void
ok_expect (int expected) {
  ok_expected_ = expected;
}

canonical_original_code:
void ok_expect(int expected) {
  ok_expected_ = expected;
}

variable_types: expected int


decompiled_code:
__int64 ok_expected()
{
return (unsigned int)ok_expected_;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)ok_expected_;
}

original_code:
int
ok_expected () {
  return ok_expected_;
}

canonical_original_code:
int ok_expected() {
  return ok_expected_;
}


decompiled_code:
__int64 ok_count()
{
return (unsigned int)ok_count_;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)ok_count_;
}

original_code:
int
ok_count () {
  return ok_count_;
}

canonical_original_code:
int ok_count() {
  return ok_count_;
}


decompiled_code:
void ok_reset()
{
ok_count_ = 0;
ok_expected_ = 0;
}

canonical_decompiled_code:
void func5()
{
ok_count_ = 0;
ok_expected_ = 0;
}

original_code:
void
ok_reset () {
  ok_count_ = 0;
  ok_expected_ = 0;
}


decompiled_code:
void *__fastcall trim_left(void *dest)
{
int v1; // eax
__int64 v2; // rbx
int v3; // ebp
char *v4; // rsi
const unsigned __int16 *v5; // rax

v1 = strlen((const char *)dest);
v2 = *(char *)dest;
if ( (_BYTE)v2 )
{
v3 = v1;
v4 = (char *)dest;
v5 = *_ctype_b_loc();
do
{
if ( (v5[v2] & 0x2000) == 0 )
break;
v2 = *++v4;
--v3;
}
while ( (_BYTE)v2 );
if ( dest != v4 )
memmove(dest, v4, v3 + 1);
}
return dest;
}

canonical_decompiled_code:
void *__fastcall func0(void *dest)
{
int v1; // eax
__int64 v2; // rbx
int v3; // ebp
char *v4; // rsi
const unsigned __int16 *v5; // rax

v1 = strlen((const char *)dest);
v2 = *(char *)dest;
if ( (_BYTE)v2 )
{
v3 = v1;
v4 = (char *)dest;
v5 = *_ctype_b_loc();
do
{
if ( (v5[v2] & 0x2000) == 0 )
break;
v2 = *++v4;
--v3;
}
while ( (_BYTE)v2 );
if ( dest != v4 )
memmove(dest, v4, v3 + 1);
}
return dest;
}

original_code:
char *
trim_left(char *str) {
  int len = strlen(str);
  char *cur = str;
  while (*cur && ((*__ctype_b_loc ())[(int) ((*cur))] & (unsigned short int) _ISspace)) {
    ++cur;
    --len;
  }
  if (str != cur) memmove(str, cur, len + 1);
  return str;
}

canonical_original_code:
char *trim_left(char *str) {
  int len = strlen(str);
  char *cur = str;
  while (*cur && ((*__ctype_b_loc ())[(int) ((*cur))] & (unsigned short) _ISspace)) {
    ++cur;
    --len;
  }
  if (str != cur) memmove(str, cur, len + 1);
  return str;
}

variable_types: len int

variable_types:
cur
char *

return_type: char *


original_code:
char *
trim_right(char *str) {
  int len = strlen(str);
  char *cur = str + len - 1;
  while (cur != str && ((*__ctype_b_loc ())[(int) ((*cur))] & (unsigned short int) _ISspace)) --cur;
  cur[((*__ctype_b_loc ())[(int) ((*cur))] & (unsigned short int) _ISspace) ? 0 : 1] = '\0';
  return str;
}

canonical_original_code:
char *trim_right(char *str) {
  int len = strlen(str);
  char *cur = str + len - 1;
  while (cur != str && ((*__ctype_b_loc ())[(int) ((*cur))] & (unsigned short) _ISspace)) --cur;
  cur[((*__ctype_b_loc ())[(int) ((*cur))] & (unsigned short) _ISspace) ? 0 : 1] = '\0';
  return str;
}


trim

decompiled_code:
void *__fastcall trim(void *dest)
{
trim_right((const char *)dest);
trim_left(dest);
return dest;
}

canonical_decompiled_code:
void *__fastcall func2(void *dest)
{
func1((const char *)dest);
func0(dest);
return dest;
}

original_code:
char *
trim(char *str) {
  trim_right(str);
  trim_left(str);
  return str;
}

canonical_original_code:
char *trim(char *str) {
  trim_right(str);
  trim_left(str);
  return str;
}


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

result = malloc(0x28uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

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

result = malloc(0x28uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

original_code:
list_t *
list_new() {
  list_t *self;
  if (!(self = malloc(sizeof(list_t))))
    return ((void *)0);
  self->head = ((void *)0);
  self->tail = ((void *)0);
  self->free = ((void *)0);
  self->match = ((void *)0);
  self->len = 0;
  return self;
}

canonical_original_code:
struct list_t *list_new() {
  struct list_t *self;
  if (!(self = malloc(sizeof(list_t))))
    return ((void *)0);
  self->head = ((void *)0);
  self->tail = ((void *)0);
  self->free = ((void *)0);
  self->match = ((void *)0);
  self->len = 0;
  return self;
}

variable_types: struct list_t { struct list_node { struct list_node *prev; struct list_node *next; void *val; } *head; struct list_node *tail; unsigned int len; void (*free)(void *val); int (*match)(void *a, void *b); } *

user_defined_types: struct list_t { struct list_node *head; struct list_node *tail; unsigned int len; void (*free)(void *val); int (*match)(void *a, void *b); }


decompiled_code:
void __fastcall list_destroy(void *ptr)
{
int v1; // eax
_QWORD *v2; // rbp
int v3; // ebx
void (__fastcall *v4)(_QWORD); // rax
_QWORD *v5; // r12

v1 = *((_DWORD *)ptr + 4);
v2 = *(_QWORD **)ptr;
if ( v1 )
{
v3 = v1 - 1;
do
{
v4 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 3);
v5 = v2;
v2 = (_QWORD *)v2[1];
if ( v4 )
v4(v5[2]);
free(v5);
}
while ( v3-- != 0 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
int v1; // eax
_QWORD *v2; // rbp
int v3; // ebx
void (__fastcall *v4)(_QWORD); // rax
_QWORD *v5; // r12

v1 = *((_DWORD *)ptr + 4);
v2 = *(_QWORD **)ptr;
if ( v1 )
{
v3 = v1 - 1;
do
{
v4 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 3);
v5 = v2;
v2 = (_QWORD *)v2[1];
if ( v4 )
v4(v5[2]);
free(v5);
}
while ( v3-- != 0 );
}
free(ptr);
}

original_code:
void
list_destroy(list_t *self) {
  unsigned int len = self->len;
  list_node_t *next;
  list_node_t *curr = self->head;
  while (len--) {
    next = curr->next;
    if (self->free) self->free(curr->val);
    free(curr);
    curr = next;
  }
  free(self);
}

canonical_original_code:
void list_destroy(struct list_t *self) {
  unsigned int len = self->len;
  struct list_node *next;
  struct list_node *curr = self->head;
  while (len--) {
    next = curr->next;
    if (self->free) self->free(curr->val);
    free(curr);
    curr = next;
  }
  free(self);
}

variable_types:
len
unsigned int

variable_types: struct list_node { struct list_node *prev; struct list_node *next; void *val; } *


decompiled_code:
__int64 __fastcall list_find(__int64 a1, __int64 a2)
{
__int64 v3; // rbp
__int64 v4; // r12
unsigned int (__fastcall *v5)(__int64, __int64); // rax
__int64 v6; // rsi

v3 = list_iterator_new(a1, 0LL);
while ( 1 )
{
v4 = list_iterator_next(v3);
if ( !v4 )
break;
v5 = *(unsigned int (__fastcall **)(__int64, __int64))(a1 + 32);
v6 = *(_QWORD *)(v4 + 16);
if ( v5 )
{
if ( v5(a2, v6) )
break;
}
else if ( v6 == a2 )
{
break;
}
}
list_iterator_destroy(v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v3; // rbp
__int64 v4; // r12
unsigned int (__fastcall *v5)(__int64, __int64); // rax
__int64 v6; // rsi

v3 = list_iterator_new(a1, 0LL);
while ( 1 )
{
v4 = list_iterator_next(v3);
if ( !v4 )
break;
v5 = *(unsigned int (__fastcall **)(__int64, __int64))(a1 + 32);
v6 = *(_QWORD *)(v4 + 16);
if ( v5 )
{
if ( v5(a2, v6) )
break;
}
else if ( v6 == a2 )
{
break;
}
}
list_iterator_destroy(v3);
return v4;
}

original_code:
list_node_t *
list_find(list_t *self, void *val) {
  list_iterator_t *it = list_iterator_new(self, LIST_HEAD);
  list_node_t *node;
  while ((node = list_iterator_next(it))) {
    if (self->match) {
      if (self->match(val, node->val)) {
        list_iterator_destroy(it);
        return node;
      }
    } else {
      if (val == node->val) {
        list_iterator_destroy(it);
        return node;
      }
    }
  }
  list_iterator_destroy(it);
  return ((void *)0);
}

canonical_original_code:
struct list_node *list_find(struct list_t *self, void *val) {
  struct list_iterator_t *it = list_iterator_new(self, LIST_HEAD);
  struct list_node *node;
  while ((node = list_iterator_next(it))) {
    if (self->match) {
      if (self->match(val, node->val)) {
        list_iterator_destroy(it);
        return node;
      }
    } else {
      if (val == node->val) {
        list_iterator_destroy(it);
        return node;
      }
    }
  }
  list_iterator_destroy(it);
  return ((void *)0);
}

variable_types: struct list_t { struct list_node *head; struct list_node *tail; unsigned int len; void (*free)(void *val); int (*match)(void *a, void *b); } *

variable_types:
val
void *

variable_types: struct list_iterator_t { struct list_node { struct list_node *prev; struct list_node *next; void *val; } *next; enum list_direction_t { LIST_HEAD=0, LIST_TAIL=1 } direction; } *

user_defined_types: struct list_iterator_t { struct list_node *next; enum list_direction_t direction; }


decompiled_code:
__int64 __fastcall list_at(__int64 a1, int a2)
{
__int64 v3; // rsi
__int64 result; // rax
int v5; // ebx
__int64 v6; // r12
__int64 v7; // rax
__int64 v9; // [rsp+8h] [rbp-20h]

v3 = 0LL;
if ( a2 < 0 )
{
a2 = ~a2;
v3 = 1LL;
}
result = 0LL;
if ( *(_DWORD *)(a1 + 16) > (unsigned int)a2 )
{
v5 = a2 - 1;
v6 = list_iterator_new(a1, v3);
v7 = list_iterator_next(v6);
if ( a2 )
{
do
v7 = list_iterator_next(v6);
while ( v5-- != 0 );
}
v9 = v7;
list_iterator_destroy(v6);
result = v9;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
__int64 v3; // rsi
__int64 result; // rax
int v5; // ebx
__int64 v6; // r12
__int64 v7; // rax
__int64 v9; // [rsp+8h] [rbp-20h]

v3 = 0LL;
if ( a2 < 0 )
{
a2 = ~a2;
v3 = 1LL;
}
result = 0LL;
if ( *(_DWORD *)(a1 + 16) > (unsigned int)a2 )
{
v5 = a2 - 1;
v6 = list_iterator_new(a1, v3);
v7 = list_iterator_next(v6);
if ( a2 )
{
do
v7 = list_iterator_next(v6);
while ( v5-- != 0 );
}
v9 = v7;
list_iterator_destroy(v6);
result = v9;
}
return result;
}

original_code:
list_node_t *
list_at(list_t *self, int index) {
  list_direction_t direction = LIST_HEAD;
  if (index < 0) {
    direction = LIST_TAIL;
    index = ~index;
  }
  if (index < self->len) {
    list_iterator_t *it = list_iterator_new(self, direction);
    list_node_t *node = list_iterator_next(it);
    while (index--) node = list_iterator_next(it);
    list_iterator_destroy(it);
    return node;
  }
  return ((void *)0);
}

canonical_original_code:
struct list_node *list_at(struct list_t *self, int index) {
  enum list_direction_t direction = LIST_HEAD;
  if (index < 0) {
    direction = LIST_TAIL;
    index = ~index;
  }
  if (index < self->len) {
    struct list_iterator_t *it = list_iterator_new(self, direction);
    struct list_node *node = list_iterator_next(it);
    while (index--) node = list_iterator_next(it);
    list_iterator_destroy(it);
    return node;
  }
  return ((void *)0);
}

variable_types: index int

variable_types: enum list_direction_t { LIST_HEAD=0, LIST_TAIL=1 }

return_type: struct list_node { struct list_node *prev; struct list_node *next; void *val; } *


original_code:
void
list_remove(list_t *self, list_node_t *node) {
  node->prev
    ? (node->prev->next = node->next)
    : (self->head = node->next);
  node->next
    ? (node->next->prev = node->prev)
    : (self->tail = node->prev);
  if (self->free) self->free(node->val);
  free(node);
  --self->len;
}

canonical_original_code:
void list_remove(struct list_t *self, struct list_node *node) {
  node->prev
    ? (node->prev->next = node->next)
    : (self->head = node->next);
  node->next
    ? (node->next->prev = node->prev)
    : (self->tail = node->prev);
  if (self->free) self->free(node->val);
  free(node);
  --self->len;
}

variable_types:
node
struct list_node *

user_defined_types: struct list_node { struct list_node *prev; struct list_node *next; void *val; }


original_code: static inline void kh_del_ptr(kh_ptr_t *h, khint_t x) { if (x != h->n_buckets && !((h->flags[x>>4]>>((x&0xfU)<<1))&3)) { (h->flags[x>>4]|=1ul<<((x&0xfU)<<1)); --h->size; } }

canonical_original_code: static inline void kh_del_ptr(struct kh_ptr_t *h, unsigned int x) { if (x != h->n_buckets && !((h->flags[x>>4]>>((x&0xfU)<<1))&3)) { (h->flags[x>>4]|=1ul<<((x&0xfU)<<1)); --h->size; } }

variable_types: struct kh_ptr_t { unsigned int n_buckets; unsigned int *flags; char **keys; void **vals; } *

variable_types:
x
unsigned int


original_code: static inline khint_t kh_get_ptr(kh_ptr_t *h, kh_cstr_t key) { if (h->n_buckets) { khint_t inc, k, i, last; k = __ac_X31_hash_string(key); i = k % h->n_buckets; inc = 1 + k % (h->n_buckets - 1); last = i; while (!((h->flags[i>>4]>>((i&0xfU)<<1))&2) && (((h->flags[i>>4]>>((i&0xfU)<<1))&1) || !(strcmp(h->keys[i], key) == 0))) { if (i + inc >= h->n_buckets) i = i + inc - h->n_buckets; else i += inc; if (i == last) return h->n_buckets; } return ((h->flags[i>>4]>>((i&0xfU)<<1))&3)? h->n_buckets : i; } else return 0; }

canonical_original_code: static inline unsigned int kh_get_ptr(struct kh_ptr_t *h, char *key) { if (h->n_buckets) { unsigned int inc; unsigned int k; unsigned int i; unsigned int last; k = __ac_X31_hash_string(key); i = k % h->n_buckets; inc = 1 + k % (h->n_buckets - 1); last = i; while (!((h->flags[i>>4]>>((i&0xfU)<<1))&2) && (((h->flags[i>>4]>>((i&0xfU)<<1))&1) || !(strcmp(h->keys[i], key) == 0))) { if (i + inc >= h->n_buckets) i = i + inc - h->n_buckets; else i += inc; if (i == last) return h->n_buckets; } return ((h->flags[i>>4]>>((i&0xfU)<<1))&3)? h->n_buckets : i; } else return 0; }

variable_types:
key
char *

variable_types:
inc
unsigned int

variable_types:
k
unsigned int

variable_types:
i
unsigned int

variable_types:
last
unsigned int

return_type: unsigned int

user_defined_types: struct kh_ptr_t { unsigned int n_buckets; unsigned int *flags; char **keys; void **vals; }


original_code: static inline khint_t kh_put_ptr(kh_ptr_t *h, kh_cstr_t key, int *ret) { khint_t x; if (h->n_occupied >= h->upper_bound) { if (h->n_buckets > (h->size<<1)) kh_resize_ptr(h, h->n_buckets - 1); else kh_resize_ptr(h, h->n_buckets + 1); } { khint_t inc, k, i, site, last; x = site = h->n_buckets; k = __ac_X31_hash_string(key); i = k % h->n_buckets; if (((h->flags[i>>4]>>((i&0xfU)<<1))&2)) x = i; else { inc = 1 + k % (h->n_buckets - 1); last = i; while (!((h->flags[i>>4]>>((i&0xfU)<<1))&2) && (((h->flags[i>>4]>>((i&0xfU)<<1))&1) || !(strcmp(h->keys[i], key) == 0))) { if (((h->flags[i>>4]>>((i&0xfU)<<1))&1)) site = i; if (i + inc >= h->n_buckets) i = i + inc - h->n_buckets; else i += inc; if (i == last) { x = site; break; } } if (x == h->n_buckets) { if (((h->flags[i>>4]>>((i&0xfU)<<1))&2) && site != h->n_buckets) x = site; else x = i; } } } if (((h->flags[x>>4]>>((x&0xfU)<<1))&2)) { h->keys[x] = key; (h->flags[x>>4]&=~(3ul<<((x&0xfU)<<1))); ++h->size; ++h->n_occupied; *ret = 1; } else if (((h->flags[x>>4]>>((x&0xfU)<<1))&1)) { h->keys[x] = key; (h->flags[x>>4]&=~(3ul<<((x&0xfU)<<1))); ++h->size; *ret = 2; } else *ret = 0; return x; }

canonical_original_code: static inline unsigned int kh_put_ptr(struct kh_ptr_t *h, char *key, int *ret) { unsigned int x; if (h->n_occupied >= h->upper_bound) { if (h->n_buckets > (h->size<<1)) kh_resize_ptr(h, h->n_buckets - 1); else kh_resize_ptr(h, h->n_buckets + 1); } { unsigned int inc; unsigned int k; unsigned int i; unsigned int site; unsigned int last; x = site = h->n_buckets; k = __ac_X31_hash_string(key); i = k % h->n_buckets; if (((h->flags[i>>4]>>((i&0xfU)<<1))&2)) x = i; else { inc = 1 + k % (h->n_buckets - 1); last = i; while (!((h->flags[i>>4]>>((i&0xfU)<<1))&2) && (((h->flags[i>>4]>>((i&0xfU)<<1))&1) || !(strcmp(h->keys[i], key) == 0))) { if (((h->flags[i>>4]>>((i&0xfU)<<1))&1)) site = i; if (i + inc >= h->n_buckets) i = i + inc - h->n_buckets; else i += inc; if (i == last) { x = site; break; } } if (x == h->n_buckets) { if (((h->flags[i>>4]>>((i&0xfU)<<1))&2) && site != h->n_buckets) x = site; else x = i; } } } if (((h->flags[x>>4]>>((x&0xfU)<<1))&2)) { h->keys[x] = key; (h->flags[x>>4]&=~(3ul<<((x&0xfU)<<1))); ++h->size; ++h->n_occupied; *ret = 1; } else if (((h->flags[x>>4]>>((x&0xfU)<<1))&1)) { h->keys[x] = key; (h->flags[x>>4]&=~(3ul<<((x&0xfU)<<1))); ++h->size; *ret = 2; } else *ret = 0; return x; }

variable_types:
ret
int *

variable_types:
site
unsigned int


decompiled_code:
__int64 __fastcall hash_set(__int64 a1, char *a2, __int64 a3)
{
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

result = (unsigned int)kh_put_ptr((void **)a1, a2, v5);
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL * (unsigned int)result) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char *a2, __int64 a3)
{
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

result = (unsigned int)func4((void **)a1, a2, v5);
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL * (unsigned int)result) = a3;
return result;
}

original_code:
inline void
hash_set(hash_t *self, char *key, void *val) {
  int ret;
  khiter_t k = kh_put_ptr(self, key, &ret);
  ((self)->vals[k]) = val;
}

canonical_original_code:
inline void hash_set(struct kh_ptr_t *self, char *key, void *val) {
  int ret;
  unsigned int k = kh_put_ptr(self, key, &ret);
  ((self)->vals[k]) = val;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall hash_get(__int64 a1, char *a2)
{
unsigned int v2; // eax
__int64 result; // rax

v2 = kh_get_ptr(a1, a2);
if ( *(_DWORD *)a1 == v2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL * v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char *a2)
{
unsigned int v2; // eax
__int64 result; // rax

v2 = func2(a1, a2);
if ( *(_DWORD *)a1 == v2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL * v2);
return result;
}

original_code:
inline void *
hash_get(hash_t *self, char *key) {
  khiter_t k = kh_get_ptr(self, key);
  return k == ((self)->n_buckets) ? ((void *)0) : ((self)->vals[k]);
}

canonical_original_code:
inline void *hash_get(struct kh_ptr_t *self, char *key) {
  unsigned int k = kh_get_ptr(self, key);
  return k == ((self)->n_buckets) ? ((void *)0) : ((self)->vals[k]);
}

return_type: void *


original_code:
inline int
hash_has(hash_t *self, char *key) {
  khiter_t k = kh_get_ptr(self, key);
  return (!(((self)->flags[(k)>>4]>>(((k)&0xfU)<<1))&3));
}

canonical_original_code:
inline int hash_has(struct kh_ptr_t *self, char *key) {
  unsigned int k = kh_get_ptr(self, key);
  return (!(((self)->flags[(k)>>4]>>(((k)&0xfU)<<1))&3));
}


decompiled_code:
void __fastcall hash_del(__int64 a1, char *a2)
{
unsigned int v2; // eax

v2 = kh_get_ptr(a1, a2);
kh_del_ptr(a1, v2);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, char *a2)
{
unsigned int v2; // eax

v2 = func2(a1, a2);
func1(a1, v2);
}

original_code:
void
hash_del(hash_t *self, char *key) {
  khiter_t k = kh_get_ptr(self, key);
  kh_del_ptr(self, k);
}

canonical_original_code:
void hash_del(struct kh_ptr_t *self, char *key) {
  unsigned int k = kh_get_ptr(self, key);
  kh_del_ptr(self, k);
}


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

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

original_code:
void
list_iterator_destroy(list_iterator_t *self) {
  free(self);
}

canonical_original_code:
void list_iterator_destroy(struct list_iterator_t *self) {
  free(self);
}

user_defined_types: enum list_direction_t { LIST_HEAD=0, LIST_TAIL=1 }


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

result = malloc(0x18uLL);
if ( result )
*result = &LC0;
return result;
}

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

result = malloc(0x18uLL);
if ( result )
*result = &LC0;
return result;
}

original_code:
__attribute__((visibility("default"))) sly_let_t *
sly_let_new () {
  sly_let_t *self = (sly_let_t *) malloc(sizeof(sly_let_t));
  if (((void *)0) == self) return ((void *)0);
  self->class = "Let";
  return self;
}

canonical_original_code:
struct sly_let_s *sly_let_new() {
  struct sly_let_s *self = (sly_let_t *) malloc(sizeof(sly_let_t));
  if (((void *)0) == self) return ((void *)0);
  self->class = "Let";
  return self;
}

variable_types: struct sly_let_s { char *class; enum sly_node_type_t { SLY_NODE_IDENTIFIER=0, SLY_NODE_UNDEFINED=1, SLY_NODE_GENERIC=2, SLY_NODE_LET=3, SLY_NODE_DEFINE=4, SLY_NODE_UNDEFINE=5, SLY_NODE_VAR=6, SLY_NODE_IMPORT=7, SLY_NODE_EXPORT=8, SLY_NODE_IN=9, SLY_NODE_NULL=10, SLY_NODE_FOR=11, SLY_NODE_WHILE=12, SLY_NODE_SWITCH=13, SLY_NODE_CASE=14, SLY_NODE_CASEDEFAULT=15, SLY_NODE_IF=16, SLY_NODE_ELSEIF=17, SLY_NODE_ELSE=18, SLY_NODE_RETURN=19, SLY_NODE_FREE=20, SLY_NODE_TYPEDEF=21, SLY_NODE_TYPEOF=22, SLY_NODE_BLOCK=23, SLY_NODE_EXPRESSION=24 } type; union { void *as_self; void *as_pointer; int as_int; char as_char; } value; } *

user_defined_types: struct sly_let_s { char *class; enum sly_node_type_t type; union { void *as_self; void *as_pointer; int as_int; char as_char; } value; }


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

original_code:
void
sly_value_free (void *_) {
  sly_value_t *self = (sly_value_t *) _;
  free(self);
}

canonical_original_code:
void sly_value_free(void *_) {
  struct sly_value_s *self = (sly_value_t *) _;
  free(self);
}

variable_types: struct sly_value_s { char *class; enum sly_node_type_t { SLY_NODE_IDENTIFIER=0, SLY_NODE_UNDEFINED=1, SLY_NODE_GENERIC=2, SLY_NODE_LET=3, SLY_NODE_DEFINE=4, SLY_NODE_UNDEFINE=5, SLY_NODE_VAR=6, SLY_NODE_IMPORT=7, SLY_NODE_EXPORT=8, SLY_NODE_IN=9, SLY_NODE_NULL=10, SLY_NODE_FOR=11, SLY_NODE_WHILE=12, SLY_NODE_SWITCH=13, SLY_NODE_CASE=14, SLY_NODE_CASEDEFAULT=15, SLY_NODE_IF=16, SLY_NODE_ELSEIF=17, SLY_NODE_ELSE=18, SLY_NODE_RETURN=19, SLY_NODE_FREE=20, SLY_NODE_TYPEDEF=21, SLY_NODE_TYPEOF=22, SLY_NODE_BLOCK=23, SLY_NODE_EXPRESSION=24 } type; union { void *as_self; void *as_pointer; int as_int; char as_char; } value; } *

user_defined_types: struct sly_value_s { char *class; enum sly_node_type_t type; union { void *as_self; void *as_pointer; int as_int; char as_char; } value; }


decompiled_code:
__int64 __fastcall sly_var_value(__int64 a1)
{
return *(_QWORD *)(a1 + 16) + 16LL;
}

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

original_code:
sly_value_conv_t *
sly_var_value (sly_var_t *self) {
  sly_value_t *value = (sly_value_t *) self->value.as_pointer;
  return (sly_value_conv_t *) &value->value;
}

canonical_original_code:
union sly_value_conv *sly_var_value(struct sly_var_s *self) {
  struct sly_value_s *value = (sly_value_t *) self->value.as_pointer;
  return (union sly_value_conv *) &value->value;
}

variable_types: struct sly_var_s { char *class; enum sly_node_type_t { SLY_NODE_IDENTIFIER=0, SLY_NODE_UNDEFINED=1, SLY_NODE_GENERIC=2, SLY_NODE_LET=3, SLY_NODE_DEFINE=4, SLY_NODE_UNDEFINE=5, SLY_NODE_VAR=6, SLY_NODE_IMPORT=7, SLY_NODE_EXPORT=8, SLY_NODE_IN=9, SLY_NODE_NULL=10, SLY_NODE_FOR=11, SLY_NODE_WHILE=12, SLY_NODE_SWITCH=13, SLY_NODE_CASE=14, SLY_NODE_CASEDEFAULT=15, SLY_NODE_IF=16, SLY_NODE_ELSEIF=17, SLY_NODE_ELSE=18, SLY_NODE_RETURN=19, SLY_NODE_FREE=20, SLY_NODE_TYPEDEF=21, SLY_NODE_TYPEOF=22, SLY_NODE_BLOCK=23, SLY_NODE_EXPRESSION=24 } type; union { struct sly_value_s { char *class; enum sly_node_type_t { SLY_NODE_IDENTIFIER=0, SLY_NODE_UNDEFINED=1, SLY_NODE_GENERIC=2, SLY_NODE_LET=3, SLY_NODE_DEFINE=4, SLY_NODE_UNDEFINE=5, SLY_NODE_VAR=6, SLY_NODE_IMPORT=7, SLY_NODE_EXPORT=8, SLY_NODE_IN=9, SLY_NODE_NULL=10, SLY_NODE_FOR=11, SLY_NODE_WHILE=12, SLY_NODE_SWITCH=13, SLY_NODE_CASE=14, SLY_NODE_CASEDEFAULT=15, SLY_NODE_IF=16, SLY_NODE_ELSEIF=17, SLY_NODE_ELSE=18, SLY_NODE_RETURN=19, SLY_NODE_FREE=20, SLY_NODE_TYPEDEF=21, SLY_NODE_TYPEOF=22, SLY_NODE_BLOCK=23, SLY_NODE_EXPRESSION=24 } type; union { void *as_self; void *as_pointer; int as_int; char as_char; } value; } *as_self; void *as_pointer; int as_int; char as_char; } value; } *

return_type: union sly_value_conv { void *as_pointer; int as_int; char as_char; } *

user_defined_types: struct sly_var_s { char *class; enum sly_node_type_t type; union { struct sly_value_s *as_self; void *as_pointer; int as_int; char as_char; } value; }


main

repo: knielsen/libmysql-coroutine

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rsi
unsigned int v5; // eax
unsigned int v7; // [rsp+Ch] [rbp-ACh] BYREF
char v8[16]; // [rsp+10h] [rbp-A8h] BYREF
__int64 v9; // [rsp+20h] [rbp-98h]

if ( (unsigned int)state_init(v8, argv, envp) )
{
fwrite("Error: failed to state_init()\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
puts("Sync:");
v7 = foo(v8, 4LL);
printf("Sync done: %d\n", v7);
puts("\nAsync:");
v3 = foo_start_constprop_0(&v7, v8);
v4 = v3;
if ( v3 )
{
do
{
printf("...again, stata=%d\n", v4);
sleep(1u);
v5 = foo_cont(&v7, v8);
v4 = v5;
}
while ( v5 );
}
printf("Async done: %d\n", v7);
state_deinit_isra_0(v9);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rsi
unsigned int v5; // eax
unsigned int v7; // [rsp+Ch] [rbp-ACh] BYREF
char v8[16]; // [rsp+10h] [rbp-A8h] BYREF
__int64 v9; // [rsp+20h] [rbp-98h]

if ( (unsigned int)func7(v8, argv, envp) )
{
fwrite("Error: failed to state_init()\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
puts("Sync:");
v7 = func12(v8, 4LL);
printf("Sync done: %d\n", v7);
puts("\nAsync:");
v3 = func9(&v7, v8);
v4 = v3;
if ( v3 )
{
do
{
printf("...again, stata=%d\n", v4);
sleep(1u);
v5 = func8(&v7, v8);
v4 = v5;
}
while ( v5 );
}
printf("Async done: %d\n", v7);
func14(v9);
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
  int err;
  err= mysql_server_init(argc, argv, my_groups);
  if (err)
  {
    fprintf(stderr, "Fatal: mysql_library_init() returns error: %d\n", err);
    exit(1);
  }
  doit();
  mysql_server_end();
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: err int


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

v3 = mysql_server_init();
if ( v3 )
{
fprintf(stderr, "Fatal: mysql_library_init() returns error: %d\n", v3);
exit(1);
}
doit(argc, argv);
mysql_server_end();
return 0;
}

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

v3 = mysql_server_init();
if ( v3 )
{
fprintf(stderr, "Fatal: mysql_library_init() returns error: %d\n", v3);
exit(1);
}
func7(argc, argv);
mysql_server_end();
return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int err;
  err= mysql_server_init(argc, argv, my_groups);
  if (err)
  {
    fprintf(stderr, "Fatal: mysql_library_init() returns error: %d\n", err);
    exit(1);
  }
  doit();
  mysql_server_end();
  return 0;
}


uharmonicToNote

repo: kninnug/Hark

decompiled_code:
char *__fastcall uharmonicToNote(unsigned __int64 a1, _DWORD *a2)
{
char *result; // rax

result = (char *)&unk_618;
if ( a1 <= 0x83 )
{
if ( a2 )
*a2 = a1 / 0xC;
result = notes[a1 % 0xC];
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned __int64 a1, _DWORD *a2)
{
char *result; // rax

result = (char *)&unk_618;
if ( a1 <= 0x83 )
{
if ( a2 )
*a2 = a1 / 0xC;
result = notes[a1 % 0xC];
}
return result;
}

original_code:
const char * uharmonicToNote(size_t harmonic, int * octave){
 if(harmonic > 83 + 48) return "";
 if(octave != ((void *)0)) *octave = harmonic / 12;
 return notes[harmonic % (sizeof notes / sizeof notes[0])];
}

canonical_original_code:
char *uharmonicToNote(unsigned long harmonic, int *octave){
 if(harmonic > 83 + 48) return "";
 if(octave != ((void *)0)) *octave = harmonic / 12;
 return notes[harmonic % (sizeof notes / sizeof notes[0])];
}

variable_types:
harmonic
unsigned long

variable_types:
octave
int *


harmonicToNote

decompiled_code:
char *__fastcall harmonicToNote(int a1, _DWORD *a2)
{
char *result; // rax

if ( (unsigned int)(a1 + 48) > 0x83 )
result = (char *)&unk_618;
else
result = uharmonicToNote(a1 + (a1 < 0 ? 0x30 : 0), a2);
return result;
}

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

if ( (unsigned int)(a1 + 48) > 0x83 )
result = (char *)&unk_618;
else
result = func0(a1 + (a1 < 0 ? 0x30 : 0), a2);
return result;
}

original_code:
const char * harmonicToNote(int harmonic, int * octave){
 if(harmonic < -48 || harmonic > 83) return "";
 if(harmonic < 0) harmonic = 48 + harmonic;
 return uharmonicToNote(harmonic, octave);
}

canonical_original_code:
char *harmonicToNote(int harmonic, int *octave){
 if(harmonic < -48 || harmonic > 83) return "";
 if(harmonic < 0) harmonic = 48 + harmonic;
 return uharmonicToNote(harmonic, octave);
}

variable_types: harmonic int


harmonicToLine

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

result = " | | | | | ";
if ( a1 <= 0x15 )
result = lines[a1 + 1];
return result;
}

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

result = " | | | | | ";
if ( a1 <= 0x15 )
result = lines[a1 + 1];
return result;
}

original_code:
const char * harmonicToLine(int harmonic){
 if(harmonic < 0 || harmonic > 21) return lines[0];
 return lines[1 + harmonic];
}

canonical_original_code:
char *harmonicToLine(int harmonic){
 if(harmonic < 0 || harmonic > 21) return lines[0];
 return lines[1 + harmonic];
}


harmonicToFreq

decompiled_code:
double __fastcall harmonicToFreq(int a1)
{
unsigned int v1; // edi
double result; // xmm0_8

v1 = a1 + 48;
result = 0.0;
if ( v1 <= 0x83 )
result = harmonics[v1];
return result;
}

canonical_decompiled_code:
double __fastcall func3(int a1)
{
unsigned int v1; // edi
double result; // xmm0_8

v1 = a1 + 48;
result = 0.0;
if ( v1 <= 0x83 )
result = harmonics[v1];
return result;
}

original_code:
double harmonicToFreq(int harmonic){
 if(harmonic < -48 || harmonic > 83){
  return 0.0;
 }
 harmonic += 48;
 return harmonics[harmonic];
}

return_type: double


freqToHarmonic

decompiled_code:
void __fastcall freqToHarmonic(double *a1, double a2)
{
double *v2; // rbx
double v3; // xmm0_8
double v4; // xmm0_8
int v5; // eax
int v6; // ecx
double v7; // xmm4_8
double v8; // xmm5_8
double v9; // xmm6_8
double v10; // xmm0_8
double v11; // xmm2_8
double v12; // xmm3_8
char v14; // [rsp+18h] [rbp-10h] BYREF

v2 = a1;
v3 = log2(a2 / 440.0);
v4 = round(v3 * 12.0 + 9.0);
harmonicToFreq((int)v4 - 1);
harmonicToFreq(v5);
v9 = harmonicToFreq(v6);
if ( !a1 )
v2 = (double *)&v14;
*(_QWORD *)&v10 = COERCE_UNSIGNED_INT64(v8 - a2) & LC6;
*(_QWORD *)&v11 = COERCE_UNSIGNED_INT64(v7 - a2) & LC6;
*(_QWORD *)&v12 = COERCE_UNSIGNED_INT64(v9 - a2) & LC6;
if ( v11 > v10 && v12 > v10 )
{
*v2 = v8;
}
else if ( v10 > v11 && v12 > v11 || v10 <= v12 || v11 <= v12 )
{
*v2 = v7;
}
else
{
*v2 = v9;
}
}

canonical_decompiled_code:
void __fastcall func4(double *a1, double a2)
{
double *v2; // rbx
double v3; // xmm0_8
double v4; // xmm0_8
int v5; // eax
int v6; // ecx
double v7; // xmm4_8
double v8; // xmm5_8
double v9; // xmm6_8
double v10; // xmm0_8
double v11; // xmm2_8
double v12; // xmm3_8
char v14; // [rsp+18h] [rbp-10h] BYREF

v2 = a1;
v3 = log2(a2 / 440.0);
v4 = round(v3 * 12.0 + 9.0);
func3((int)v4 - 1);
func3(v5);
v9 = func3(v6);
if ( !a1 )
v2 = (double *)&v14;
*(_QWORD *)&v10 = COERCE_UNSIGNED_INT64(v8 - a2) & LC6;
*(_QWORD *)&v11 = COERCE_UNSIGNED_INT64(v7 - a2) & LC6;
*(_QWORD *)&v12 = COERCE_UNSIGNED_INT64(v9 - a2) & LC6;
if ( v11 > v10 && v12 > v10 )
{
*v2 = v8;
}
else if ( v10 > v11 && v12 > v11 || v10 <= v12 || v11 <= v12 )
{
*v2 = v7;
}
else
{
*v2 = v9;
}
}

original_code:
int freqToHarmonic(double freq, double * diff){
 double harm = (double)12*log2(freq/(double)440) + (double)9;
 int x = round(harm);
 double freq0 = harmonicToFreq(x-1),
  freq1 = harmonicToFreq(x),
  freq2 = harmonicToFreq(x+1),
  diff0 = fabs(freq0 - freq),
  diff1 = fabs(freq1 - freq),
  diff2 = fabs(freq2 - freq),
  nodiff = 0.0;
 if(diff == ((void *)0)) diff = &nodiff;
 *diff = freq0;
 if(diff0 < diff1 && diff0 < diff2) return x - 1;
 *diff = freq1;
 if(diff1 < diff0 && diff1 < diff2) return x;
 *diff = freq2;
 if(diff2 < diff0 && diff2 < diff1) return x + 1;
 *diff = freq1;
 return x;
}

canonical_original_code:
int freqToHarmonic(double freq, double *diff){
 double harm = (double)12*log2(freq/(double)440) + (double)9;
 int x = round(harm);
 double freq0 = harmonicToFreq(x-1); double freq1 = harmonicToFreq(x); double freq2 = harmonicToFreq(x+1); double diff0 = fabs(freq0 - freq); double diff1 = fabs(freq1 - freq); double diff2 = fabs(freq2 - freq); double nodiff = 0.0;
 if(diff == ((void *)0)) diff = &nodiff;
 *diff = freq0;
 if(diff0 < diff1 && diff0 < diff2) return x - 1;
 *diff = freq1;
 if(diff1 < diff0 && diff1 < diff2) return x;
 *diff = freq2;
 if(diff2 < diff0 && diff2 < diff1) return x + 1;
 *diff = freq1;
 return x;
}

variable_types: freq double

variable_types:
diff
double *

variable_types: harm double

variable_types: x int

variable_types: nodiff double


genHarmonics

decompiled_code:
void genHarmonics()
{
__int64 i; // rbx

for ( i = 0LL; i != 132; ++i )
harmonics[i] = pow(2.0, (double)((int)i - 57) / 12.0) * 440.0;
}


original_code:
static int heap_removeMin(struct heap * h){
 if(h->front < 1){
  return 0.0;
 }
 int addon = h->addons[1];
 h->front--;
 h->items[1] = h->items[h->front];
 h->addons[1] = h->addons[h->front];
 heap_downheap(h, 1);
 return addon;
}

canonical_original_code:
static int heap_removeMin(struct heap *h){
 if(h->front < 1){
  return 0.0;
 }
 int addon = h->addons[1];
 h->front--;
 h->items[1] = h->items[h->front];
 h->addons[1] = h->addons[h->front];
 heap_downheap(h, 1);
 return addon;
}

variable_types: struct heap { unsigned long length; unsigned long front; double *items; int *addons; } *

variable_types: addon int


decompiled_code:
// attributes: thunk
__int64 __fastcall heap_full(_QWORD *a1)
{
return heap_removeMin(a1);
}

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

original_code:
static void heap_full(struct heap * h){
 heap_removeMin(h);
}

canonical_original_code:
static void heap_full(struct heap *h){
 heap_removeMin(h);
}

user_defined_types: struct heap { unsigned long length; unsigned long front; double *items; int *addons; }


decompiled_code:
int *__fastcall heap_upheap(__int64 a1, int a2)
{
__int64 v4; // r11
int *result; // rax
__int64 v6; // rdi
int v7; // edx
int v8; // er10

if ( a2 > 1 )
{
v4 = a2;
do
{
v6 = *(_QWORD *)(a1 + 16);
v7 = a2;
v8 = a2 >> 1;
if ( *(double *)(v6 + 8LL * v8) <= *(double *)(v6 + 8 * v4) )
break;
result = heap_swap_isra_0(v6, *(_QWORD *)(a1 + 24), v7, v8);
}
while ( a2 != 1 );
}
return result;
}

original_code:
static void heap_upheap(struct heap * h, int n){
 if(n > 1){
  if(h->items[n] < h->items[n / 2]){
   heap_swap(h, n, n / 2);
   heap_upheap(h, n / 2);
  }
 }
}

canonical_original_code:
static void heap_upheap(struct heap *h, int n){
 if(n > 1){
  if(h->items[n] < h->items[n / 2]){
   heap_swap(h, n, n / 2);
   heap_upheap(h, n / 2);
  }
 }
}

variable_types: n int


fmalloc

decompiled_code:
void *__fastcall fmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "! malloc failed (%zu)\n", a1);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "! malloc failed (%zu)\n", a1);
exit(1);
}
return result;
}

original_code:
void * fmalloc(size_t n){
 void * p = malloc(n);
 if(p == ((void *)0)){
  fprintf(stderr, "! malloc failed (%zu)\n", n);
  exit(1);
 }
 return p;
}

canonical_original_code:
void *fmalloc(unsigned long n){
 void *p = malloc(n);
 if(p == ((void *)0)){
  fprintf(stderr, "! malloc failed (%zu)\n", n);
  exit(1);
 }
 return p;
}

variable_types:
n
unsigned long

variable_types:
p
void *


highFreq

original_code:
size_t highFreq(fftw_complex * fftOut, int fftSize, double * intens){
 size_t i, idx;
 double high = 0, amp = 0;
 for(i = 1; i < fftSize/2 + 1; i++){
  amp = fftOut[i][0]*fftOut[i][0] + fftOut[i][1]*fftOut[i][1];
  if(amp > high){
   high = amp;
   idx = i;
  }
 }
 if(intens != ((void *)0)) *intens = high;
 return idx;
}

canonical_original_code:
unsigned long highFreq(double (*fftOut)[2], int fftSize, double *intens){
 unsigned long i; unsigned long idx;
 double high = 0; double amp = 0;
 for(i = 1; i < fftSize/2 + 1; i++){
  amp = fftOut[i][0]*fftOut[i][0] + fftOut[i][1]*fftOut[i][1];
  if(amp > high){
   high = amp;
   idx = i;
  }
 }
 if(intens != ((void *)0)) *intens = high;
 return idx;
}

variable_types:
fftOut
double (*)[2]

variable_types: fftSize int

variable_types:
intens
double *

variable_types:
i
unsigned long

variable_types:
idx
unsigned long

variable_types: high double

variable_types: amp double


threshFreq

original_code:
int * threshFreq(fftw_complex * fftOut, int fftSize, int threshold, int * in, size_t len, struct heap * hin){
 size_t i;
 double amp, ampLeft, ampRight;
 struct heap * h = heap_new(len);
 for(i = 1; i < fftSize / 2 + 1; i++){
  amp = fftOut[i][0]*fftOut[i][0] + fftOut[i][1]*fftOut[i][1];
  ampLeft = i > 1 ? fftOut[i - 1][0]*fftOut[i - 1][0] + fftOut[i - 1][1]*fftOut[i - 1][1] : 0.0;
  ampRight = i <= fftSize / 2 ? fftOut[i + 1][0]*fftOut[i + 1][0] + fftOut[i + 1][1]*fftOut[i + 1][1] : 0.0;
  if(amp > threshold && amp > ampLeft && amp > ampRight){
   heap_enqueue(h, amp, i);
  }
 }
 for(i = 0; i < h->length; i++){
  in[i] = heap_removeMin(h);
 }
 return in;
}

canonical_original_code:
int *threshFreq(double (*fftOut)[2], int fftSize, int threshold, int *in, unsigned long len, struct heap *hin){
 unsigned long i;
 double amp; double ampLeft; double ampRight;
 struct heap *h = heap_new(len);
 for(i = 1; i < fftSize / 2 + 1; i++){
  amp = fftOut[i][0]*fftOut[i][0] + fftOut[i][1]*fftOut[i][1];
  ampLeft = i > 1 ? fftOut[i - 1][0]*fftOut[i - 1][0] + fftOut[i - 1][1]*fftOut[i - 1][1] : 0.0;
  ampRight = i <= fftSize / 2 ? fftOut[i + 1][0]*fftOut[i + 1][0] + fftOut[i + 1][1]*fftOut[i + 1][1] : 0.0;
  if(amp > threshold && amp > ampLeft && amp > ampRight){
   heap_enqueue(h, amp, i);
  }
 }
 for(i = 0; i < h->length; i++){
  in[i] = heap_removeMin(h);
 }
 return in;
}

variable_types: threshold int

variable_types:
in
int *

variable_types:
len
unsigned long

variable_types: ampLeft double

variable_types: ampRight double

return_type: int *


sipdump

repo: kreeze/sipdump

decompiled_code:
void __fastcall sipdump(__int64 a1, __int64 a2, __int64 a3)
{
puts((const char *)(a3 + 4 * (*(_BYTE *)(a3 + 14) & 0xFu) + 22));
if ( !osip_parse() )
perror("Error parsing SIP");
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
puts((const char *)(a3 + 4 * (*(_BYTE *)(a3 + 14) & 0xFu) + 22));
if ( !osip_parse() )
perror("Error parsing SIP");
}

original_code:
void sipdump(u_char *args, const struct pcap_pkthdr *header, const u_char *frame) {
  struct iphdr *ip_header = (struct iphdr *) (frame + sizeof(struct ether_header));
  int ip_header_length = ip_header->ihl * 4;
  struct udphdr *udp_header = (struct udphdr *) (frame + sizeof(struct ether_header) + ip_header_length);
  unsigned int header_length = (sizeof(struct ether_header) + ip_header_length + sizeof(struct udphdr));
  unsigned char *payload = (u_char *) (frame + header_length);
  unsigned int payload_length = header->len - header_length;
  printf("%s\n", payload);
  osip_event_t *oe = osip_parse(payload, payload_length);
  if(oe == ((void *)0)) {
    perror("Error parsing SIP");
    return;
  }
}

canonical_original_code:
void sipdump(unsigned char *args, struct pcap_pkthdr *header, unsigned char *frame) {
  struct iphdr *ip_header = (struct iphdr *) (frame + sizeof(struct ether_header));
  int ip_header_length = ip_header->ihl * 4;
  struct udphdr *udp_header = (struct udphdr *) (frame + sizeof(struct ether_header) + ip_header_length);
  unsigned int header_length = (sizeof(struct ether_header) + ip_header_length + sizeof(struct udphdr));
  unsigned char *payload = (u_char *) (frame + header_length);
  unsigned int payload_length = header->len - header_length;
  printf("%s\n", payload);
  struct osip_event *oe = osip_parse(payload, payload_length);
  if(oe == ((void *)0)) {
    perror("Error parsing SIP");
    return;
  }
}

variable_types:
args
unsigned char *

variable_types: struct pcap_pkthdr { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int caplen; unsigned int len; } *

variable_types:
frame
unsigned char *

variable_types: struct iphdr { unsigned char ihl; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *

variable_types: struct udphdr { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; } *

variable_types:
payload
unsigned char *

variable_types: struct osip_event { enum type_t { TIMEOUT_A=0, TIMEOUT_B=1, TIMEOUT_D=2, TIMEOUT_E=3, TIMEOUT_F=4, TIMEOUT_K=5, TIMEOUT_G=6, TIMEOUT_H=7, TIMEOUT_I=8, TIMEOUT_J=9, RCV_REQINVITE=10, RCV_REQACK=11, RCV_REQUEST=12, RCV_STATUS_1XX=13, RCV_STATUS_2XX=14, RCV_STATUS_3456XX=15, SND_REQINVITE=16, SND_REQACK=17, SND_REQUEST=18, SND_STATUS_1XX=19, SND_STATUS_2XX=20, SND_STATUS_3456XX=21, KILL_TRANSACTION=22, UNKNOWN_EVT=23 } type; int transactionid; struct osip_message { char *sip_version; struct osip_uri { char *scheme; char *username; char *password; char *host; char *port; struct osip_list { int nb_elt; struct __node { struct __node *next; void *element; } *node; } url_params; struct osip_list url_headers; char *string; } *req_uri; char *sip_method; int status_code; char *reason_phrase; struct osip_list accepts; struct osip_list accept_encodings; struct osip_list accept_languages; struct osip_list alert_infos; struct osip_list allows; struct osip_list authentication_infos; struct osip_list authorizations; struct osip_call_id { char *number; char *host; } *call_id; struct osip_list call_infos; struct osip_list contacts; struct osip_list content_encodings; struct osip_content_length { char *value; } *content_length; struct osip_content_type { char *type; char *subtype; struct osip_list gen_params; } *content_type; struct osip_cseq { char *method; char *number; } *cseq; struct osip_list error_infos; struct osip_from { char *displayname; struct osip_uri *url; struct osip_list gen_params; } *from; struct osip_content_length *mime_version; struct osip_list proxy_authenticates; struct osip_list proxy_authentication_infos; struct osip_list proxy_authorizations; struct osip_list record_routes; struct osip_list routes; struct osip_from *to; struct osip_list vias; struct osip_list www_authenticates; struct osip_list headers; struct osip_list bodies; int message_property; char *message; unsigned long message_length; void *application_data; } *sip; } *

user_defined_types: struct pcap_pkthdr { struct timeval ts; unsigned int caplen; unsigned int len; }

user_defined_types: struct osip_event { enum type_t type; int transactionid; struct osip_message *sip; }

user_defined_types: struct osip_message { char *sip_version; struct osip_uri *req_uri; char *sip_method; int status_code; char *reason_phrase; struct osip_list accepts; struct osip_list accept_encodings; struct osip_list accept_languages; struct osip_list alert_infos; struct osip_list allows; struct osip_list authentication_infos; struct osip_list authorizations; struct osip_call_id *call_id; struct osip_list call_infos; struct osip_list contacts; struct osip_list content_encodings; struct osip_content_length *content_length; struct osip_content_type *content_type; struct osip_cseq *cseq; struct osip_list error_infos; struct osip_from *from; struct osip_content_length *mime_version; struct osip_list proxy_authenticates; struct osip_list proxy_authentication_infos; struct osip_list proxy_authorizations; struct osip_list record_routes; struct osip_list routes; struct osip_from *to; struct osip_list vias; struct osip_list www_authenticates; struct osip_list headers; struct osip_list bodies; int message_property; char *message; unsigned long message_length; void *application_data; }

user_defined_types: struct osip_uri { char *scheme; char *username; char *password; char *host; char *port; struct osip_list url_params; struct osip_list url_headers; char *string; }

user_defined_types: struct osip_list { int nb_elt; struct __node *node; }


repo: kuebler/enum

decompiled_code:
_BOOL8 __fastcall not_newline(int a1)
{
return a1 != 10;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1)
{
return a1 != 10;
}

original_code:
int not_newline(int c) {
  return c!='\n';
}

variable_types: c int


decompiled_code:
__int64 __fastcall handle_bound(__int64 (__fastcall **a1)(_QWORD), int a2, int a3, int a4)
{
return (*a1)(((a3 >> 31) | 1u) * (a2 + 2 * a4));
}

original_code:
void handle_bound(solver *s, int var, int lit, int nfree) {
  s->add((lit<0 ? -1 : 1)*((nfree*3)+(var-nfree)));
}

canonical_original_code:
void handle_bound(struct solver *s, int var, int lit, int nfree) {
  s->add((lit<0 ? -1 : 1)*((nfree*3)+(var-nfree)));
}

variable_types: struct solver { void (*add)(int lit); enum sat_state { ST_UNKNOWN=0, ST_SAT=10, ST_UNSAT=20 } (*sat)(); enum sat_state { ST_UNKNOWN=0, ST_SAT=10, ST_UNSAT=20 } (*sat_assum)(int *, int); enum lit_value { L_FALSE=-1, L_UNKNOWN=0, L_TRUE=1 } (*lit_deref)(int); void (*assume)(int); } *

variable_types: var int

variable_types: lit int

variable_types: nfree int

user_defined_types: struct solver { void (*add)(int lit); enum sat_state (*sat)(); enum sat_state (*sat_assum)(int *, int); enum lit_value (*lit_deref)(int); void (*assume)(int); }


decompiled_code:
__int64 __fastcall handle_free(__int64 (__fastcall **a1)(_QWORD), int a2, unsigned int a3)
{
return (*a1)((a3 >> 31) + 3 * a2 - 3 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 (__fastcall **a1)(_QWORD), int a2, unsigned int a3)
{
return (*a1)((a3 >> 31) + 3 * a2 - 3 + 1);
}

original_code:
void handle_free(solver *s, int var, int lit, int nfree) {
  s->add(lit<0 ? ((var-1)*3+2) : ((var-1)*3+1));
}

canonical_original_code:
void handle_free(struct solver *s, int var, int lit, int nfree) {
  s->add(lit<0 ? ((var-1)*3+2) : ((var-1)*3+1));
}

user_defined_types: enum sat_state { ST_UNKNOWN=0, ST_SAT=10, ST_UNSAT=20 }

user_defined_types: enum lit_value { L_FALSE=-1, L_UNKNOWN=0, L_TRUE=1 }


die

decompiled_code:
void __noreturn die(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, a1, arg);
fflush(stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func11(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, a1, arg);
fflush(stderr);
exit(1);
}

original_code:
void die(char *fmt, ...) {
  va_list v;
  __builtin_va_start(v,fmt);
  vfprintf(stderr, fmt, v);
  fflush(stderr);
  __builtin_va_end(v);
  exit(1);
}

canonical_original_code:
void die(char *fmt, ...) {
  __builtin_va_list v;
  __builtin_va_start(v,fmt);
  vfprintf(stderr, fmt, v);
  fflush(stderr);
  __builtin_va_end(v);
  exit(1);
}

variable_types:
fmt
char *


decompiled_code:
__int64 __fastcall phase_relaxation_clauses(__int64 a1, int a2)
{
int v2; // er14
unsigned int v4; // ebx
__int64 v5; // rcx
__int64 v6; // rsi
__int64 v7; // rdx
__int64 result; // rax

if ( a2 > 0 )
{
v2 = 1;
v4 = -1;
do
{
++v2;
add_clause(a1, v4, v4 - 1, 0LL);
add_clause(a1, v4 - 2, v4, 0LL);
add_clause(a1, v4 - 2, v4 - 1, 0LL);
v5 = 2 - v4;
v6 = -v4;
v7 = 1 - v4;
v4 -= 3;
result = add_clause(a1, v6, v7, v5);
}
while ( a2 >= v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
int v2; // er14
unsigned int v4; // ebx
__int64 v5; // rcx
__int64 v6; // rsi
__int64 v7; // rdx
__int64 result; // rax

if ( a2 > 0 )
{
v2 = 1;
v4 = -1;
do
{
++v2;
add_clause(a1, v4, v4 - 1, 0LL);
add_clause(a1, v4 - 2, v4, 0LL);
add_clause(a1, v4 - 2, v4 - 1, 0LL);
v5 = 2 - v4;
v6 = -v4;
v7 = 1 - v4;
v4 -= 3;
result = add_clause(a1, v6, v7, v5);
}
while ( a2 >= v2 );
}
return result;
}

variable_types: freevars int

variable_types: vars int

variable_types: i int