decompiled_code:
__int64 __fastcall oaddr_isbad(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
result = (unsigned int)(*a1 > 3) + 1;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
result = (unsigned int)(*a1 > 3) + 1;
else
result = 0LL;
return result;
}

original_code:
int
oaddr_isbad(struct oaddr_t *oa)
{
 if(oa == ((void *)0))
  return OADDR_NULL;
 if(oa->length < 4)
  return OADDR_TOOSMALL;
 if(oa->address_family != 10 || oa->address_family != 2)
  return OADDR_BADAF;
 if(oa->address == ((void *)0))
  return OADDR_NOADDR;
 if(oa->netmask == ((void *)0))
  return OADDR_NOMASK;
 return 0;
}


repo: twinshadow/progcee

decompiled_code:
__int64 __fastcall in_network(__int64 a1, __int64 a2)
{
unsigned int v3; // er8
__int64 v5; // rax
char v6; // dl
char v7; // si
unsigned __int8 v8; // cl

if ( (unsigned int)((__int64 (*)(void))oaddr_isbad)() || (v3 = oaddr_isbad(a2)) != 0 )
return (unsigned int)-1;
LODWORD(v5) = *(_DWORD *)a2 - 1;
if ( (int)v5 < 0 )
return 1;
v5 = (int)v5;
while ( 1 )
{
v6 = *(_BYTE *)(*(_QWORD *)(a2 + 16) + v5);
if ( v6 )
{
v7 = *(_BYTE *)(*(_QWORD *)(a2 + 8) + v5);
v8 = *(_BYTE *)(*(_QWORD *)(a1 + 8) + v5);
if ( v8 < (unsigned __int8)(v7 & v6) || v8 > (unsigned __int8)(v7 | ~v6) )
break;
}
if ( (_DWORD)--v5 == -1 )
return 1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
unsigned int v3; // er8
__int64 v5; // rax
char v6; // dl
char v7; // si
unsigned __int8 v8; // cl

if ( (unsigned int)((__int64 (*)(void))oaddr_isbad)() || (v3 = func8(a2)) != 0 )
return (unsigned int)-1;
LODWORD(v5) = *(_DWORD *)a2 - 1;
if ( (int)v5 < 0 )
return 1;
v5 = (int)v5;
while ( 1 )
{
v6 = *(_BYTE *)(*(_QWORD *)(a2 + 16) + v5);
if ( v6 )
{
v7 = *(_BYTE *)(*(_QWORD *)(a2 + 8) + v5);
v8 = *(_BYTE *)(*(_QWORD *)(a1 + 8) + v5);
if ( v8 < (unsigned __int8)(v7 & v6) || v8 > (unsigned __int8)(v7 | ~v6) )
break;
}
if ( (_DWORD)--v5 == -1 )
return 1;
}
return v3;
}

original_code:
int
in_network(struct oaddr_t *oa, struct oaddr_t *subnet)
{
 if(oaddr_isbad(oa) || oaddr_isbad(subnet))
  return -1;
 int i;
 for(i = subnet->length - 1; i >= 0; i--)
 {
  if(subnet->netmask[i] == '\0')
   continue;
  if(oa->address[i] >= (subnet->netmask[i] & subnet->address[i]) &&
     oa->address[i] <= (subnet->address[i] | ((~subnet->netmask[i]) & 0xFF)))
   continue;
  else
   return(0);
 }
 return(1);
}

variable_types: struct oaddr_t { int length; int address_family; unsigned char *address; unsigned char *netmask; } *

variable_types:
subnet
struct oaddr_t *

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall ipcalc_pton(__int64 a1, const char *a2, __int64 a3)
{
unsigned int v4; // er12
int v6; // eax

if ( !a2 || (v4 = oaddr_isbad(a3)) != 0 )
return (unsigned int)-1;
v6 = inet_pton(*(_DWORD *)(a3 + 4), a2, *(void **)(a3 + 8));
if ( v6 <= 0 )
{
v4 = 1;
if ( v6 )
perror("inet_pton");
else
fprintf(stderr, "Not in presentation format: %s", a2);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2, __int64 a3)
{
unsigned int v4; // er12
int v6; // eax

if ( !a2 || (v4 = func8(a3)) != 0 )
return (unsigned int)-1;
v6 = inet_pton(*(_DWORD *)(a3 + 4), a2, *(void **)(a3 + 8));
if ( v6 <= 0 )
{
v4 = 1;
if ( v6 )
perror("inet_pton");
else
fprintf(stderr, "Not in presentation format: %s", a2);
}
return v4;
}

original_code:
int
ipcalc_pton(int af, const char *str, struct oaddr_t *oa)
{
 if(str == ((void *)0))
  return -1;
 if(oaddr_isbad(oa))
  return -1;
 int s = inet_pton(oa->address_family, str, oa->address);
 if (s <= 0)
 {
  if (s == 0)
   fprintf(stderr, "Not in presentation format: %s", str);
  else
   perror("inet_pton");
  return(1);
 }
 return(0);
}

canonical_original_code:
int ipcalc_pton(int af, char *str, struct oaddr_t *oa)
{
 if(str == ((void *)0))
  return -1;
 if(oaddr_isbad(oa))
  return -1;
 int s = inet_pton(oa->address_family, str, oa->address);
 if (s <= 0)
 {
  if (s == 0)
   fprintf(stderr, "Not in presentation format: %s", str);
  else
   perror("inet_pton");
  return(1);
 }
 return(0);
}

variable_types: af int

variable_types:
str
char *

variable_types: s int

user_defined_types: struct oaddr_t { int length; int address_family; unsigned char *address; unsigned char *netmask; }


decompiled_code:
__int64 __fastcall oaddr_ntop(__int64 a1, char *a2)
{
unsigned int v2; // er12

if ( !a2 || (v2 = oaddr_isbad(a1)) != 0 )
return (unsigned int)-1;
if ( !inet_ntop(*(_DWORD *)(a1 + 4), *(const void **)(a1 + 8), a2, 0x2Eu) )
{
v2 = 1;
perror("oaddr_ntop");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, char *a2)
{
unsigned int v2; // er12

if ( !a2 || (v2 = func8(a1)) != 0 )
return (unsigned int)-1;
if ( !inet_ntop(*(_DWORD *)(a1 + 4), *(const void **)(a1 + 8), a2, 0x2Eu) )
{
v2 = 1;
perror("oaddr_ntop");
}
return v2;
}

original_code:
int
oaddr_ntop(struct oaddr_t *oa, char *str)
{
 if(str == ((void *)0))
  return -1;
 if(oaddr_isbad(oa))
  return -1;
 if (inet_ntop(oa->address_family, oa->address, str, 46) == ((void *)0))
 {
  perror("oaddr_ntop");
  return(1);
 }
 return(0);
}


decompiled_code:
__int64 __fastcall oaddr_decr(int *a1)
{
__int64 result; // rax
int v2; // esi
__int64 v3; // rdx
__int64 v4; // rcx

result = oaddr_isbad(a1);
if ( !(_DWORD)result )
{
v2 = *a1 - 1;
if ( v2 >= 0 )
{
result = v2;
v3 = *((_QWORD *)a1 + 1);
v4 = *a1 - 2LL - (unsigned int)v2;
do
{
--*(_BYTE *)(v3 + result);
v3 = *((_QWORD *)a1 + 1);
if ( *(_BYTE *)(v3 + result) )
break;
--result;
}
while ( result != v4 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int *a1)
{
__int64 result; // rax
int v2; // esi
__int64 v3; // rdx
__int64 v4; // rcx

result = func8(a1);
if ( !(_DWORD)result )
{
v2 = *a1 - 1;
if ( v2 >= 0 )
{
result = v2;
v3 = *((_QWORD *)a1 + 1);
v4 = *a1 - 2LL - (unsigned int)v2;
do
{
--*(_BYTE *)(v3 + result);
v3 = *((_QWORD *)a1 + 1);
if ( *(_BYTE *)(v3 + result) )
break;
--result;
}
while ( result != v4 );
}
}
return result;
}

original_code:
void
oaddr_decr(struct oaddr_t *oa)
{
 if(oaddr_isbad(oa))
  return;
 int i;
 for(i = oa->length - 1; i >= 0; i--)
 {
  oa->address[i]--;
  if(oa->address[i] != 0x0)
   break;
 }
}

return_type: void


decompiled_code:
__int64 __fastcall oaddr_incr(int *a1)
{
__int64 result; // rax
int v2; // esi
__int64 v3; // rdx
__int64 v4; // rcx

result = oaddr_isbad(a1);
if ( !(_DWORD)result )
{
v2 = *a1 - 1;
if ( v2 >= 0 )
{
result = v2;
v3 = *((_QWORD *)a1 + 1);
v4 = *a1 - 2LL - (unsigned int)v2;
do
{
++*(_BYTE *)(v3 + result);
v3 = *((_QWORD *)a1 + 1);
if ( *(_BYTE *)(v3 + result) != 0xFF )
break;
--result;
}
while ( result != v4 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int *a1)
{
__int64 result; // rax
int v2; // esi
__int64 v3; // rdx
__int64 v4; // rcx

result = func8(a1);
if ( !(_DWORD)result )
{
v2 = *a1 - 1;
if ( v2 >= 0 )
{
result = v2;
v3 = *((_QWORD *)a1 + 1);
v4 = *a1 - 2LL - (unsigned int)v2;
do
{
++*(_BYTE *)(v3 + result);
v3 = *((_QWORD *)a1 + 1);
if ( *(_BYTE *)(v3 + result) != 0xFF )
break;
--result;
}
while ( result != v4 );
}
}
return result;
}

original_code:
void
oaddr_incr(struct oaddr_t *oa)
{
 if(oaddr_isbad(oa))
  return;
 int i;
 for(i = oa->length - 1; i >= 0; i--)
 {
  oa->address[i]++;
  if(oa->address[i] != 0xFF)
   break;
 }
}


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall oaddr_copy(const __m128i *a1)
{
if ( !(unsigned int)oaddr_isbad(a1) )
{
*(__m128i *)&dword_0 = _mm_loadu_si128(a1);
*(_QWORD *)&word_10 = a1[1].m128i_i64[0];
}
return 0LL;
}

original_code:
struct oaddr_t *
oaddr_copy(struct oaddr_t *oa)
{
 if(oaddr_isbad(oa))
  return ((void *)0);
 struct oaddr_t *oax;
 memcpy(oax, oa, sizeof(struct oaddr_t));
 memcpy(oax->address, oa->address, oa->length);
 memcpy(oax->netmask, oa->netmask, oa->length);
 return oax;
}

canonical_original_code:
struct oaddr_t *oaddr_copy(struct oaddr_t *oa)
{
 if(oaddr_isbad(oa))
  return ((void *)0);
 struct oaddr_t *oax;
 memcpy(oax, oa, sizeof(struct oaddr_t));
 memcpy(oax->address, oa->address, oa->length);
 memcpy(oax->netmask, oa->netmask, oa->length);
 return oax;
}

variable_types:
oa
struct oaddr_t *

return_type: struct oaddr_t { int length; int address_family; unsigned char *address; unsigned char *netmask; } *


decompiled_code:
int *__fastcall oaddr_broadcast(int *a1)
{
int *v1; // r12
int v2; // edx
__int64 v3; // rax
__int64 v4; // rcx

if ( (unsigned int)oaddr_isbad(a1) )
return 0LL;
v1 = (int *)oaddr_copy(a1);
if ( !v1 )
return 0LL;
v2 = *a1 - 1;
if ( v2 >= 0 )
{
v3 = v2;
v4 = *a1 - 2LL - (unsigned int)v2;
do
{
*(_BYTE *)(*((_QWORD *)v1 + 1) + v3) = *(_BYTE *)(*((_QWORD *)a1 + 1) + v3) | ~*(_BYTE *)(*((_QWORD *)a1 + 2) + v3);
--v3;
}
while ( v4 != v3 );
}
memset(*((void **)v1 + 2), 255, *v1);
return v1;
}

original_code:
struct oaddr_t*
oaddr_broadcast(struct oaddr_t *oa)
{
 if(oaddr_isbad(oa))
  return ((void *)0);
 int i;
 struct oaddr_t *bcast;
 bcast = oaddr_copy(oa);
 if(bcast == ((void *)0))
  return ((void *)0);
 for(i = oa->length - 1; i >= 0; i--)
     bcast->address[i] = (oa->address[i] | ((~oa->netmask[i]) & 0xFF));
 memset(bcast->netmask, 0xFF, bcast->length);
 return bcast;
}

canonical_original_code:
struct oaddr_t *oaddr_broadcast(struct oaddr_t *oa)
{
 if(oaddr_isbad(oa))
  return ((void *)0);
 int i;
 struct oaddr_t *bcast;
 bcast = oaddr_copy(oa);
 if(bcast == ((void *)0))
  return ((void *)0);
 for(i = oa->length - 1; i >= 0; i--)
     bcast->address[i] = (oa->address[i] | ((~oa->netmask[i]) & 0xFF));
 memset(bcast->netmask, 0xFF, bcast->length);
 return bcast;
}


original_code:
struct oaddr_t *
oaddr_from_str(const char *addr)
{
 if(addr == ((void *)0))
  return ((void *)0);
 if(strlen(addr) > 128)
  return ((void *)0);
 char *addrbuf;
 char *maskbuf = ((void *)0);
 char *m;
 int i, s = 0;
 int div, mod;
 struct oaddr_t *oax;
 oax = oaddr_new();
 if(oax == ((void *)0))
  return ((void *)0);
 addrbuf = calloc(128, sizeof(char));
 strcpy(addrbuf, addr);
 if((m = strchr(addrbuf, '/')) != ((void *)0))
 {
  strtok(addrbuf, "/");
  maskbuf = strtok(((void *)0), "/");
 }
 oax->address_family = ((strchr(addr, ':') == ((void *)0)) ? 2 : 10);
 oax->length = ((oax->address_family == 2) ? 4 : 16);
 if(maskbuf != ((void *)0))
 {
  (*__errno_location ()) = 0;
  i = strtol(maskbuf, ((void *)0), 10);
  if((*__errno_location ()) != 0)
   perror("oaddr_from_str maskbuf");
  div = i / 8;
  mod = i % 8;
  for(i = 0; i < oax->length; i++)
  {
   if(i < div)
    oax->netmask[i] = 0xFF;
   else if(i == div)
   {
    if(mod)
     oax->netmask[i] = pow(2, mod);
    break;
   }
  }
 }
 else
 {
  memset(oax->netmask, 0xFF, oax->length);
 }
 s = inet_pton(oax->address_family, addrbuf, oax->address);
 free(addrbuf);
 if (s <= 0)
 {
  if (s == 0)
   fprintf(stderr, "Not in presentation format\n");
  else
   perror("inet_pton");
  return(((void *)0));
 }
 return(oax);
}

canonical_original_code:
struct oaddr_t *oaddr_from_str(char *addr)
{
 if(addr == ((void *)0))
  return ((void *)0);
 if(strlen(addr) > 128)
  return ((void *)0);
 char *addrbuf;
 char *maskbuf = ((void *)0);
 char *m;
 int i; int s = 0;
 int div; int mod;
 struct oaddr_t *oax;
 oax = oaddr_new();
 if(oax == ((void *)0))
  return ((void *)0);
 addrbuf = calloc(128, sizeof(char));
 strcpy(addrbuf, addr);
 if((m = strchr(addrbuf, '/')) != ((void *)0))
 {
  strtok(addrbuf, "/");
  maskbuf = strtok(((void *)0), "/");
 }
 oax->address_family = ((strchr(addr, ':') == ((void *)0)) ? 2 : 10);
 oax->length = ((oax->address_family == 2) ? 4 : 16);
 if(maskbuf != ((void *)0))
 {
  (*__errno_location ()) = 0;
  i = strtol(maskbuf, ((void *)0), 10);
  if((*__errno_location ()) != 0)
   perror("oaddr_from_str maskbuf");
  div = i / 8;
  mod = i % 8;
  for(i = 0; i < oax->length; i++)
  {
   if(i < div)
    oax->netmask[i] = 0xFF;
   else if(i == div)
   {
    if(mod)
     oax->netmask[i] = pow(2, mod);
    break;
   }
  }
 }
 else
 {
  memset(oax->netmask, 0xFF, oax->length);
 }
 s = inet_pton(oax->address_family, addrbuf, oax->address);
 free(addrbuf);
 if (s <= 0)
 {
  if (s == 0)
   fprintf(stderr, "Not in presentation format\n");
  else
   perror("inet_pton");
  return(((void *)0));
 }
 return(oax);
}

variable_types:
addr
char *

variable_types:
addrbuf
char *

variable_types:
maskbuf
char *

variable_types:
m
char *

variable_types: div int

variable_types: mod int


decompiled_code:
__int64 __fastcall oaddr_to_str(__int64 a1, __int64 a2)
{
const char *v2; // r8
__int64 result; // rax
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

v2 = inet_ntop(*(_DWORD *)(a2 + 4), *(const void **)(a2 + 8), v4, 0x2Eu);
result = 0LL;
if ( !v2 )
{
perror("oaddr_ntop");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2)
{
const char *v2; // r8
__int64 result; // rax
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

v2 = inet_ntop(*(_DWORD *)(a2 + 4), *(const void **)(a2 + 8), v4, 0x2Eu);
result = 0LL;
if ( !v2 )
{
perror("oaddr_ntop");
result = 1LL;
}
return result;
}

original_code:
int
oaddr_to_str(const char *addr, struct oaddr_t *oa)
{
 int i;
 char addrbuf[46];
 char maskbuf[33];
 if (inet_ntop(oa->address_family, oa->address, addrbuf, 46) == ((void *)0))
 {
  perror("oaddr_ntop");
  return(1);
 }
 if(maskbuf == ((void *)0))
  return(1);
 for(i = 0; i < oa->length; i++)
 {
 }
 return(0);
}

canonical_original_code:
int oaddr_to_str(char *addr, struct oaddr_t *oa)
{
 int i;
 char addrbuf[46];
 char maskbuf[33];
 if (inet_ntop(oa->address_family, oa->address, addrbuf, 46) == ((void *)0))
 {
  perror("oaddr_ntop");
  return(1);
 }
 if(maskbuf == ((void *)0))
  return(1);
 for(i = 0; i < oa->length; i++)
 {
 }
 return(0);
}

variable_types:
addrbuf
char [46]

variable_types:
maskbuf
char [33]


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
int v5; // er12
int v6; // ebp
const void *v7; // rax
int v8; // ebp
const char *v9; // rax
socklen_t addr_len; // [rsp+0h] [rbp-174h] BYREF
struct addrinfo *pai; // [rsp+4h] [rbp-170h] BYREF
char buf[48]; // [rsp+Ch] [rbp-168h] BYREF
struct addrinfo req; // [rsp+3Ch] [rbp-138h] BYREF
char v14[112]; // [rsp+6Ch] [rbp-108h] BYREF
struct sockaddr addr; // [rsp+DCh] [rbp-98h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
req.ai_flags = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
v3 = getaddrinfo(0LL, "1337", &req, &pai);
if ( v3 )
{
v8 = v3;
perror("getaddrinfo");
v9 = gai_strerror(v8);
perror(v9);
}
v4 = sobind(pai);
v5 = v4;
if ( v4 == -1 )
{
if ( pai->ai_next )
++pai;
}
else if ( v4 >= 0 )
{
freeaddrinfo(pai);
if ( listen(v5, 32) )
perror("listen");
while ( 1 )
{
while ( 1 )
{
addr_len = 128;
v6 = accept(v5, &addr, &addr_len);
if ( v6 >= 0 )
break;
perror("accept");
}
v7 = (const void *)get_in_addr(&addr);
inet_ntop(addr.sa_family, v7, buf, 0x2Eu);
printf("Connection from %s established on socket %d\n", buf, (unsigned int)v6);
if ( !fork() )
break;
close(v6);
}
close(v5);
if ( recv(v6, v14, 0x63uLL, 0) == -1 )
perror("recieve");
close(v6);
exit(0);
}
perror("No socket bound, exiting");
exit(2);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
int v5; // er12
int v6; // ebp
const void *v7; // rax
int v8; // ebp
const char *v9; // rax
socklen_t addr_len; // [rsp+0h] [rbp-174h] BYREF
struct addrinfo *pai; // [rsp+4h] [rbp-170h] BYREF
char buf[48]; // [rsp+Ch] [rbp-168h] BYREF
struct addrinfo req; // [rsp+3Ch] [rbp-138h] BYREF
char v14[112]; // [rsp+6Ch] [rbp-108h] BYREF
struct sockaddr addr; // [rsp+DCh] [rbp-98h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
req.ai_flags = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
v3 = getaddrinfo(0LL, "1337", &req, &pai);
if ( v3 )
{
v8 = v3;
perror("getaddrinfo");
v9 = gai_strerror(v8);
perror(v9);
}
v4 = func9(pai);
v5 = v4;
if ( v4 == -1 )
{
if ( pai->ai_next )
++pai;
}
else if ( v4 >= 0 )
{
freeaddrinfo(pai);
if ( listen(v5, 32) )
perror("listen");
while ( 1 )
{
while ( 1 )
{
addr_len = 128;
v6 = accept(v5, &addr, &addr_len);
if ( v6 >= 0 )
break;
perror("accept");
}
v7 = (const void *)get_in_addr(&addr);
inet_ntop(addr.sa_family, v7, buf, 0x2Eu);
printf("Connection from %s established on socket %d\n", buf, (unsigned int)v6);
if ( !fork() )
break;
close(v6);
}
close(v5);
if ( recv(v6, v14, 0x63uLL, 0) == -1 )
perror("recieve");
close(v6);
exit(0);
}
perror("No socket bound, exiting");
exit(2);
}

original_code:
int main(int argc, const char *argv[])
{
 char mbuf[100],
      raddr[46];
 int echeck,
     conn_fd,
     sock_fd;
 struct addrinfo hint,
   *adr;
 struct sockaddr_storage rc;
 socklen_t rclen;
 memset(&hint, 0, sizeof hint);
 hint.ai_family = 0;
 hint.ai_socktype = SOCK_STREAM;
 hint.ai_flags = 0x0001;
 echeck = getaddrinfo(((void *)0), "1337", &hint, &adr);
 if(echeck != 0){
  perror("getaddrinfo");
  perror(gai_strerror(echeck));
 }
 for(;;){
  if((sock_fd = sobind(adr)) == -1){
   if(adr->ai_next == ((void *)0)){
    sock_fd = -1;
    break;
   }
   adr++;
  }
  break;
 }
 if(sock_fd < 0){
  perror("No socket bound, exiting");
  exit(2);
 }
 freeaddrinfo(adr);
 if(listen(sock_fd, 32) != 0){
  perror("listen");
 }
 for(;;){
  rclen = sizeof rc;
  conn_fd = accept(sock_fd, (struct sockaddr *)&rc, &rclen);
  if(conn_fd < 0){
   perror("accept");
   continue;
  }
  inet_ntop(rc.ss_family, get_in_addr((struct sockaddr *)&rc), raddr, sizeof raddr);
  printf("Connection from %s established on socket %d\n", raddr, conn_fd);
  if(!fork()){
   close(sock_fd);
   if(recv(conn_fd, mbuf, 100 - 1, 0) == -1){
    perror("recieve");
   }
   close(conn_fd);
   exit(0);
  }
  close(conn_fd);
 }
 close(sock_fd);
 close(conn_fd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char mbuf[100]; char raddr[46];
 int echeck; int conn_fd; int sock_fd;
 struct addrinfo hint; struct addrinfo *adr;
 struct sockaddr_storage rc;
 unsigned int rclen;
 memset(&hint, 0, sizeof hint);
 hint.ai_family = 0;
 hint.ai_socktype = SOCK_STREAM;
 hint.ai_flags = 0x0001;
 echeck = getaddrinfo(((void *)0), "1337", &hint, &adr);
 if(echeck != 0){
  perror("getaddrinfo");
  perror(gai_strerror(echeck));
 }
 for(;;){
  if((sock_fd = sobind(adr)) == -1){
   if(adr->ai_next == ((void *)0)){
    sock_fd = -1;
    break;
   }
   adr++;
  }
  break;
 }
 if(sock_fd < 0){
  perror("No socket bound, exiting");
  exit(2);
 }
 freeaddrinfo(adr);
 if(listen(sock_fd, 32) != 0){
  perror("listen");
 }
 for(;;){
  rclen = sizeof rc;
  conn_fd = accept(sock_fd, (struct sockaddr *)&rc, &rclen);
  if(conn_fd < 0){
   perror("accept");
   continue;
  }
  inet_ntop(rc.ss_family, get_in_addr((struct sockaddr *)&rc), raddr, sizeof raddr);
  printf("Connection from %s established on socket %d\n", raddr, conn_fd);
  if(!fork()){
   close(sock_fd);
   if(recv(conn_fd, mbuf, 100 - 1, 0) == -1){
    perror("recieve");
   }
   close(conn_fd);
   exit(0);
  }
  close(conn_fd);
 }
 close(sock_fd);
 close(conn_fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
mbuf
char [100]

variable_types:
raddr
char [46]

variable_types: echeck int

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

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

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


run

decompiled_code:
void run()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void run(){
}

canonical_original_code:
void run(){
}


soconnect

decompiled_code:
__int64 __fastcall soconnect(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12

v1 = socket(*(_DWORD *)(a1 + 4), *(_DWORD *)(a1 + 8), *(_DWORD *)(a1 + 12));
if ( v1 < 0 || (v2 = v1, connect(v1, *(const struct sockaddr **)(a1 + 24), *(_DWORD *)(a1 + 16)) == -1) )
v2 = -1;
return v2;
}

original_code:
extern int soconnect(struct addrinfo *ad){
 int sock_fd = socket(ad->ai_family, ad->ai_socktype, ad->ai_protocol);
 if(sock_fd < 0){
  return -1;
 }
 else{
  if(connect(sock_fd, ad->ai_addr, ad->ai_addrlen) == -1){
   return -1;
  }
 }
 return sock_fd;
}

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


sobind

original_code:
extern int sobind(struct addrinfo *ad){
 int sock_fd = socket(ad->ai_family, ad->ai_socktype, ad->ai_protocol);
 if(sock_fd < 0){
  return -1;
 }
 else{
  if(bind(sock_fd, ad->ai_addr, ad->ai_addrlen) == -1){
   return -1;
  }
 }
 return sock_fd;
}


soconnect

repo: twinshadow/tslibc

decompiled_code:
__int64 __fastcall soconnect(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
__int64 result; // rax

v1 = socket(*(_DWORD *)(a1 + 4), *(_DWORD *)(a1 + 8), *(_DWORD *)(a1 + 12));
if ( v1 < 0 )
{
fprintf(stderr, "DEBUG: %s:%d: File Descriptor should be a non-negative integer\n", "socket.c", 36LL);
*_errno_location() = 0;
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
if ( connect(v1, *(const struct sockaddr **)(a1 + 24), *(_DWORD *)(a1 + 16)) == -1 )
{
perror("connect");
close(v2);
result = 0xFFFFFFFFLL;
}
else
{
result = v2;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
__int64 result; // rax

v1 = socket(*(_DWORD *)(a1 + 4), *(_DWORD *)(a1 + 8), *(_DWORD *)(a1 + 12));
if ( v1 < 0 )
{
fprintf(stderr, "DEBUG: %s:%d: File Descriptor should be a non-negative integer\n", "socket.c", 36LL);
*_errno_location() = 0;
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
if ( connect(v1, *(const struct sockaddr **)(a1 + 24), *(_DWORD *)(a1 + 16)) == -1 )
{
perror("connect");
close(v2);
result = 0xFFFFFFFFLL;
}
else
{
result = v2;
}
}
return result;
}

original_code:
int
soconnect(struct addrinfo *ad)
{
 int sock_fd = -1;
 do { sock_fd = socket((ad)->ai_family, (ad)->ai_socktype, (ad)->ai_protocol); if (!(sock_fd >= 0)) { fprintf(stderr, "DEBUG: %s:%d: " "File Descriptor should be a non-negative integer" "\n", "socket.c", 36); (*__errno_location ())=0; goto error; }; } while (0);
 do { if(connect(sock_fd, (ad)->ai_addr, (ad)->ai_addrlen) == -1) { perror("connect"); goto error; } } while (0);
 goto out;
error:
 do { if (sock_fd >= 0) { close(sock_fd); } sock_fd = -1; } while (0);
out:
 return sock_fd;
}


sobind

decompiled_code:
__int64 __fastcall sobind(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
__int64 result; // rax

v1 = socket(*(_DWORD *)(a1 + 4), *(_DWORD *)(a1 + 8), *(_DWORD *)(a1 + 12));
if ( v1 < 0 )
{
fprintf(stderr, "DEBUG: %s:%d: File Descriptor should be a non-negative integer\n", "socket.c", 54LL);
*_errno_location() = 0;
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
if ( bind(v1, *(const struct sockaddr **)(a1 + 24), *(_DWORD *)(a1 + 16)) == -1 )
{
perror("bind");
close(v2);
result = 0xFFFFFFFFLL;
}
else
{
result = v2;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
__int64 result; // rax

v1 = socket(*(_DWORD *)(a1 + 4), *(_DWORD *)(a1 + 8), *(_DWORD *)(a1 + 12));
if ( v1 < 0 )
{
fprintf(stderr, "DEBUG: %s:%d: File Descriptor should be a non-negative integer\n", "socket.c", 54LL);
*_errno_location() = 0;
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
if ( bind(v1, *(const struct sockaddr **)(a1 + 24), *(_DWORD *)(a1 + 16)) == -1 )
{
perror("bind");
close(v2);
result = 0xFFFFFFFFLL;
}
else
{
result = v2;
}
}
return result;
}

original_code:
int
sobind(struct addrinfo *ad)
{
 int sock_fd;
 do { sock_fd = socket((ad)->ai_family, (ad)->ai_socktype, (ad)->ai_protocol); if (!(sock_fd >= 0)) { fprintf(stderr, "DEBUG: %s:%d: " "File Descriptor should be a non-negative integer" "\n", "socket.c", 54); (*__errno_location ())=0; goto error; }; } while (0);
 do { if(bind(sock_fd, (ad)->ai_addr, (ad)->ai_addrlen) == -1) { perror("bind"); goto error; } } while (0);
 goto out;
error:
 do { if (sock_fd >= 0) { close(sock_fd); } sock_fd = -1; } while (0);
out:
 return sock_fd;
}


decompiled_code:
char *__fastcall ts_strrstrip(char *string, char *a2)
{
char *v2; // rbx
char *result; // rax
char *i; // rcx

v2 = &a2[strnlen(a2, 0xFFFFFFFFFFFFFFFFLL)];
result = (char *)strnlen(string, 0xFFFFFFFFFFFFFFFFLL);
for ( i = &result[(_QWORD)string - 1]; string <= i; --i )
{
result = a2;
if ( a2 < v2 )
{
result = a2;
while ( *i != *result )
{
if ( v2 == ++result )
return result;
}
*i = 0;
}
if ( v2 == result )
break;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *string, char *a2)
{
char *v2; // rbx
char *result; // rax
char *i; // rcx

v2 = &a2[strnlen(a2, 0xFFFFFFFFFFFFFFFFLL)];
result = (char *)strnlen(string, 0xFFFFFFFFFFFFFFFFLL);
for ( i = &result[(_QWORD)string - 1]; string <= i; --i )
{
result = a2;
if ( a2 < v2 )
{
result = a2;
while ( *i != *result )
{
if ( v2 == ++result )
return result;
}
*i = 0;
}
if ( v2 == result )
break;
}
return result;
}

original_code:
void
ts_strrstrip(char *str, const char *delim) {
 char *cptr;
 const char *dptr, *sentinal;
 sentinal = ((strnlen(delim, (18446744073709551615UL))) == 0 ? (delim) : (delim) + ((strnlen(delim, (18446744073709551615UL))) * (sizeof(char))));
 cptr = ((strnlen(str, (18446744073709551615UL)) - 1) == 0 ? (str) : (str) + ((strnlen(str, (18446744073709551615UL)) - 1) * (sizeof(char))));
 for (; cptr >= str; cptr--) {
  for (dptr = delim; dptr < sentinal; dptr++) {
   if (*cptr == *dptr) {
    *cptr = '\0';
    break;
   }
  }
  if (dptr == sentinal)
   break;
 }
 return;
}

canonical_original_code:
void ts_strrstrip(char *str, char *delim) {
 char *cptr;
 char *dptr; char *sentinal;
 sentinal = ((strnlen(delim, (18446744073709551615UL))) == 0 ? (delim) : (delim) + ((strnlen(delim, (18446744073709551615UL))) * (sizeof(char))));
 cptr = ((strnlen(str, (18446744073709551615UL)) - 1) == 0 ? (str) : (str) + ((strnlen(str, (18446744073709551615UL)) - 1) * (sizeof(char))));
 for (; cptr >= str; cptr--) {
  for (dptr = delim; dptr < sentinal; dptr++) {
   if (*cptr == *dptr) {
    *cptr = '\0';
    break;
   }
  }
  if (dptr == sentinal)
   break;
 }
 return;
}

variable_types:
str
char *

variable_types:
delim
char *

variable_types:
cptr
char *

variable_types:
dptr
char *

variable_types:
sentinal
char *


decompiled_code:
const char *__fastcall ts_strrtok_r(char *a1, char *a2, char **a3)
{
__int64 v4; // rcx
const char *v6; // rsi
const char *v7; // r12
const char *v8; // r14
char *v9; // rbx
const char *v10; // rcx
char *v11; // rax

if ( !a2 )
{
v4 = 54LL;
v6 = "DEBUG: %s:%d: Value should not be NULL\n";
goto LABEL_26;
}
v4 = 54LL;
if ( !*a2 )
goto LABEL_25;
v4 = 55LL;
v6 = "DEBUG: %s:%d: Value should not be NULL\n";
if ( a3 )
{
if ( a1 )
{
v4 = 57LL;
if ( !*a1 )
{
LABEL_25:
v6 = "DEBUG: %s:%d: String is empty\n";
goto LABEL_26;
}
*a3 = a1;
}
else
{
a1 = *a3;
v4 = 60LL;
v6 = "DEBUG: %s:%d: Value should not be NULL\n";
if ( !*a3 )
goto LABEL_26;
}
v4 = 60LL;
if ( *a1 )
{
ts_strrstrip(a1, a2);
v7 = *a3;
v8 = *a3;
if ( !*a3 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "strrtok.c", 62LL);
*_errno_location() = 0;
return v7;
}
if ( *v7 )
{
v9 = &a2[strnlen(a2, 0xFFFFFFFFFFFFFFFFLL)];
v10 = &v7[strnlen(v7, 0xFFFFFFFFFFFFFFFFLL) - 1];
if ( v7 > v10 )
{
*a3 = 0LL;
LABEL_22:
if ( !*v7 )
{
v7 = 0LL;
fprintf(stderr, "DEBUG: %s:%d: Whups\n", "strrtok.c", 89LL);
}
}
else
{
do
{
v11 = a2;
if ( a2 < v9 )
{
v11 = a2;
while ( *v10 != *v11 )
{
if ( v9 == ++v11 )
goto LABEL_18;
}
*v10 = 0;
}
if ( v11 != v9 )
{
v7 = v10 + 1;
goto LABEL_22;
}
v8 = *a3;
LABEL_18:
--v10;
v7 = v8;
}
while ( v8 <= v10 );
*a3 = 0LL;
if ( v8 )
goto LABEL_22;
}
return v7;
}
v4 = 62LL;
}
goto LABEL_25;
}
LABEL_26:
fprintf(stderr, v6, "strrtok.c", v4);
*_errno_location() = 0;
return 0LL;
}

canonical_decompiled_code:
const char *__fastcall func1(char *a1, char *a2, char **a3)
{
__int64 v4; // rcx
const char *v6; // rsi
const char *v7; // r12
const char *v8; // r14
char *v9; // rbx
const char *v10; // rcx
char *v11; // rax

if ( !a2 )
{
v4 = 54LL;
v6 = "DEBUG: %s:%d: Value should not be NULL\n";
goto LABEL_26;
}
v4 = 54LL;
if ( !*a2 )
goto LABEL_25;
v4 = 55LL;
v6 = "DEBUG: %s:%d: Value should not be NULL\n";
if ( a3 )
{
if ( a1 )
{
v4 = 57LL;
if ( !*a1 )
{
LABEL_25:
v6 = "DEBUG: %s:%d: String is empty\n";
goto LABEL_26;
}
*a3 = a1;
}
else
{
a1 = *a3;
v4 = 60LL;
v6 = "DEBUG: %s:%d: Value should not be NULL\n";
if ( !*a3 )
goto LABEL_26;
}
v4 = 60LL;
if ( *a1 )
{
func0(a1, a2);
v7 = *a3;
v8 = *a3;
if ( !*a3 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "strrtok.c", 62LL);
*_errno_location() = 0;
return v7;
}
if ( *v7 )
{
v9 = &a2[strnlen(a2, 0xFFFFFFFFFFFFFFFFLL)];
v10 = &v7[strnlen(v7, 0xFFFFFFFFFFFFFFFFLL) - 1];
if ( v7 > v10 )
{
*a3 = 0LL;
LABEL_22:
if ( !*v7 )
{
v7 = 0LL;
fprintf(stderr, "DEBUG: %s:%d: Whups\n", "strrtok.c", 89LL);
}
}
else
{
do
{
v11 = a2;
if ( a2 < v9 )
{
v11 = a2;
while ( *v10 != *v11 )
{
if ( v9 == ++v11 )
goto LABEL_18;
}
*v10 = 0;
}
if ( v11 != v9 )
{
v7 = v10 + 1;
goto LABEL_22;
}
v8 = *a3;
LABEL_18:
--v10;
v7 = v8;
}
while ( v8 <= v10 );
*a3 = 0LL;
if ( v8 )
goto LABEL_22;
}
return v7;
}
v4 = 62LL;
}
goto LABEL_25;
}
LABEL_26:
fprintf(stderr, v6, "strrtok.c", v4);
*_errno_location() = 0;
return 0LL;
}

original_code:
char*
ts_strrtok_r(char *str, const char *delim, char **saveptr)
{
 char *cptr = ((void *)0);
 const char *dptr, *sentinal;
 do { if (!(delim)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "strrtok.c", 54); (*__errno_location ())=0; goto error; }; if (!((delim)[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "String is empty" "\n", "strrtok.c", 54); (*__errno_location ())=0; goto error; }; } while (0);;
 if (!(saveptr)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "strrtok.c", 55); (*__errno_location ())=0; goto error; };
 if (str) {
  if (!((str)[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "String is empty" "\n", "strrtok.c", 57); (*__errno_location ())=0; goto error; };
  *saveptr = str;
 }
 do { if (!(*saveptr)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "strrtok.c", 60); (*__errno_location ())=0; goto error; }; if (!((*saveptr)[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "String is empty" "\n", "strrtok.c", 60); (*__errno_location ())=0; goto error; }; } while (0);;
 ts_strrstrip(*saveptr, delim);
 do { if (!(*saveptr)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "strrtok.c", 62); (*__errno_location ())=0; goto error; }; if (!((*saveptr)[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "String is empty" "\n", "strrtok.c", 62); (*__errno_location ())=0; goto error; }; } while (0);;
 sentinal = ((strnlen(delim, (18446744073709551615UL))) == 0 ? (delim) : (delim) + ((strnlen(delim, (18446744073709551615UL))) * (sizeof(char))));
 cptr = ((strnlen(*saveptr, (18446744073709551615UL)) - 1) == 0 ? (*saveptr) : (*saveptr) + ((strnlen(*saveptr, (18446744073709551615UL)) - 1) * (sizeof(char))));
 for (; cptr >= *saveptr; cptr--) {
  for (dptr = delim; dptr < sentinal; dptr++) {
   if (*cptr == *dptr) {
    *cptr = '\0';
    break;
   }
  }
  if (dptr != sentinal) {
   str = cptr + sizeof(char);
   goto out;
  }
 }
 str = *saveptr;
 *saveptr = ((void *)0);
 goto out;
error:
 str = ((void *)0);
out:
 if (str && str[0] == '\0') {
  fprintf(stderr, "DEBUG: %s:%d: " "Whups" "\n", "strrtok.c", 89);
  return (((void *)0));
 }
 return (str);
}

canonical_original_code:
char *ts_strrtok_r(char *str, char *delim, char **saveptr)
{
 char *cptr = ((void *)0);
 char *dptr; char *sentinal;
 do { if (!(delim)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "strrtok.c", 54); (*__errno_location ())=0; goto error; }; if (!((delim)[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "String is empty" "\n", "strrtok.c", 54); (*__errno_location ())=0; goto error; }; } while (0);;
 if (!(saveptr)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "strrtok.c", 55); (*__errno_location ())=0; goto error; };
 if (str) {
  if (!((str)[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "String is empty" "\n", "strrtok.c", 57); (*__errno_location ())=0; goto error; };
  *saveptr = str;
 }
 do { if (!(*saveptr)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "strrtok.c", 60); (*__errno_location ())=0; goto error; }; if (!((*saveptr)[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "String is empty" "\n", "strrtok.c", 60); (*__errno_location ())=0; goto error; }; } while (0);;
 ts_strrstrip(*saveptr, delim);
 do { if (!(*saveptr)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "strrtok.c", 62); (*__errno_location ())=0; goto error; }; if (!((*saveptr)[0] != '\0')) { fprintf(stderr, "DEBUG: %s:%d: " "String is empty" "\n", "strrtok.c", 62); (*__errno_location ())=0; goto error; }; } while (0);;
 sentinal = ((strnlen(delim, (18446744073709551615UL))) == 0 ? (delim) : (delim) + ((strnlen(delim, (18446744073709551615UL))) * (sizeof(char))));
 cptr = ((strnlen(*saveptr, (18446744073709551615UL)) - 1) == 0 ? (*saveptr) : (*saveptr) + ((strnlen(*saveptr, (18446744073709551615UL)) - 1) * (sizeof(char))));
 for (; cptr >= *saveptr; cptr--) {
  for (dptr = delim; dptr < sentinal; dptr++) {
   if (*cptr == *dptr) {
    *cptr = '\0';
    break;
   }
  }
  if (dptr != sentinal) {
   str = cptr + sizeof(char);
   goto out;
  }
 }
 str = *saveptr;
 *saveptr = ((void *)0);
 goto out;
error:
 str = ((void *)0);
out:
 if (str && str[0] == '\0') {
  fprintf(stderr, "DEBUG: %s:%d: " "Whups" "\n", "strrtok.c", 89);
  return (((void *)0));
 }
 return (str);
}

variable_types:
saveptr
char **

return_type: char *


decompiled_code:
const char *__fastcall ts_strrtok(char *a1, char *a2)
{
return ts_strrtok_r(a1, a2, &lastptr_0);
}

canonical_decompiled_code:
const char *__fastcall func2(char *a1, char *a2)
{
return func1(a1, a2, &lastptr_0);
}

original_code:
char*
ts_strrtok(char *str, const char *delim)
{
 static char *lastptr = ((void *)0);
 return (ts_strrtok_r(str, delim, &lastptr));
}

canonical_original_code:
char *ts_strrtok(char *str, char *delim)
{
 static char *lastptr = ((void *)0);
 return (ts_strrtok_r(str, delim, &lastptr));
}

variable_types:
lastptr
char *


decompiled_code:
void *__fastcall ts_memdup(void *src, size_t n)
{
void *v2; // rax
void *v3; // r12

if ( src )
{
v2 = malloc(n);
v3 = v2;
if ( v2 )
{
memcpy(v2, src, n);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Out of memory.\n", "strdup.c", 35LL);
*_errno_location() = 0;
}
}
else
{
v3 = 0LL;
fprintf(stderr, "DEBUG: %s:%d: A NULL pointer was passed in.\n", "strdup.c", 32LL);
*_errno_location() = 0;
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func0(void *src, size_t n)
{
void *v2; // rax
void *v3; // r12

if ( src )
{
v2 = malloc(n);
v3 = v2;
if ( v2 )
{
memcpy(v2, src, n);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Out of memory.\n", "strdup.c", 35LL);
*_errno_location() = 0;
}
}
else
{
v3 = 0LL;
fprintf(stderr, "DEBUG: %s:%d: A NULL pointer was passed in.\n", "strdup.c", 32LL);
*_errno_location() = 0;
}
return v3;
}

original_code:
void *
ts_memdup(const void *ptr, size_t size)
{
 void *buf = ((void *)0);
 if (!(ptr)) { fprintf(stderr, "DEBUG: %s:%d: " "A NULL pointer was passed in." "\n", "strdup.c", 32); (*__errno_location ())=0; goto error; };
 buf = malloc(size);
 if (!(buf)) { fprintf(stderr, "DEBUG: %s:%d: " "Out of memory." "\n", "strdup.c", 35); (*__errno_location ())=0; goto error; };
 memcpy(buf, ptr, size);
 goto out;
error:
out:
 return (buf);
}

canonical_original_code:
void *ts_memdup(void *ptr, unsigned long size)
{
 void *buf = ((void *)0);
 if (!(ptr)) { fprintf(stderr, "DEBUG: %s:%d: " "A NULL pointer was passed in." "\n", "strdup.c", 32); (*__errno_location ())=0; goto error; };
 buf = malloc(size);
 if (!(buf)) { fprintf(stderr, "DEBUG: %s:%d: " "Out of memory." "\n", "strdup.c", 35); (*__errno_location ())=0; goto error; };
 memcpy(buf, ptr, size);
 goto out;
error:
out:
 return (buf);
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
buf
void *

return_type: void *


decompiled_code:
// attributes: thunk
void *__fastcall ts_strndup(void *src, size_t n)
{
return ts_memdup(src, n);
}

canonical_decompiled_code:
void *__fastcall func1(void *src, size_t n)
{
return func0(src, n);
}

original_code:
char *
ts_strndup(const char *ptr, size_t count)
{
 return (ts_memdup(ptr, count * sizeof(char)));
}

canonical_original_code:
char *ts_strndup(char *ptr, unsigned long count)
{
 return (ts_memdup(ptr, count * sizeof(char)));
}

variable_types:
ptr
char *

variable_types:
count
unsigned long


decompiled_code:
void *__fastcall ts_strdup(void *src)
{
size_t v1; // rax

v1 = strnlen((const char *)src, 0xFFFFFFFFFFFFFFFFLL);
return ts_memdup(src, v1);
}

canonical_decompiled_code:
void *__fastcall func2(void *src)
{
size_t v1; // rax

v1 = strnlen((const char *)src, 0xFFFFFFFFFFFFFFFFLL);
return func0(src, v1);
}

original_code:
char *
ts_strdup(const char *ptr)
{
 return (ts_memdup(ptr, strnlen(ptr, (18446744073709551615UL))));
}

canonical_original_code:
char *ts_strdup(char *ptr)
{
 return (ts_memdup(ptr, strnlen(ptr, (18446744073709551615UL))));
}


decompiled_code:
void __fastcall ts_vector_init(__int64 a1, __int64 a2)
{
if ( a2 )
{
*(_QWORD *)(a1 + 40) = a2;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "vector.c", 5LL);
*_errno_location() = 0;
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2)
{
if ( a2 )
{
*(_QWORD *)(a1 + 40) = a2;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "vector.c", 5LL);
*_errno_location() = 0;
}
}

original_code:
void
ts_vector_init(struct ts_vector_s *head, size_t size) {
 if (!(size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "vector.c", 5); (*__errno_location ())=0; goto error; };
 head->size = size;
error:
 return;
}

canonical_original_code:
void ts_vector_init(struct ts_vector_s *head, unsigned long size) {
 if (!(size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "vector.c", 5); (*__errno_location ())=0; goto error; };
 head->size = size;
error:
 return;
}

variable_types: struct ts_vector_s { void *head; void *tail; void *array; unsigned long count; unsigned long length; unsigned long size; struct ts_vector_policy_s { enum _ts_vector_policy { TS_VECTOR_POLICY_IMMEDIATE=expr, TS_VECTOR_POLICY_EAGER=expr, TS_VECTOR_POLICY_SNAKE=expr, TS_VECTOR_POLICY_RESV0=expr, TS_VECTOR_POLICY_RESV1=expr } flags; } policy; } *

user_defined_types: struct ts_vector_s { void *head; void *tail; void *array; unsigned long count; unsigned long length; unsigned long size; struct ts_vector_policy_s policy; }

user_defined_types: struct ts_vector_policy_s { enum _ts_vector_policy flags; }


decompiled_code:
void __fastcall ts_vector_unset(__int64 a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = *(void **)(a1 + 16);
if ( v2 )
free(v2);
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 40) = 0LL;
*(_DWORD *)(a1 + 48) = 0;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 13LL);
*_errno_location() = 0;
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = *(void **)(a1 + 16);
if ( v2 )
free(v2);
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 40) = 0LL;
*(_DWORD *)(a1 + 48) = 0;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 13LL);
*_errno_location() = 0;
}
}

original_code:
void
ts_vector_unset(struct ts_vector_s *head) {
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 13); (*__errno_location ())=0; goto error; };
 if (head->array)
  free(head->array);
 head->array = ((void *)0);
 head->head = ((void *)0);
 head->tail = ((void *)0);
 head->count = 0;
 head->length = 0;
 head->size = 0;
 head->policy.flags = 0;
error:
 return;
}

user_defined_types: enum _ts_vector_policy { TS_VECTOR_POLICY_IMMEDIATE=expr, TS_VECTOR_POLICY_EAGER=expr, TS_VECTOR_POLICY_SNAKE=expr, TS_VECTOR_POLICY_RESV0=expr, TS_VECTOR_POLICY_RESV1=expr }


decompiled_code:
__int64 __fastcall ts_vector_init_data(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rcx

if ( !a1 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 29LL);
goto LABEL_10;
}
if ( !a4 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 30LL);
goto LABEL_10;
}
if ( !a3 )
{
v5 = 31LL;
LABEL_9:
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "vector.c", v5);
LABEL_10:
*_errno_location() = 0;
ts_vector_unset((__int64)a1);
return 1LL;
}
if ( !a2 )
{
v5 = 32LL;
goto LABEL_9;
}
a1[5] = a3;
a1[2] = a4;
*a1 = a4;
a1[3] = a2;
a1[4] = a2;
if ( a2 != 1 )
a4 += a3 * (a2 - 1);
a1[1] = a4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rcx

if ( !a1 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 29LL);
goto LABEL_10;
}
if ( !a4 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 30LL);
goto LABEL_10;
}
if ( !a3 )
{
v5 = 31LL;
LABEL_9:
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "vector.c", v5);
LABEL_10:
*_errno_location() = 0;
func1((__int64)a1);
return 1LL;
}
if ( !a2 )
{
v5 = 32LL;
goto LABEL_9;
}
a1[5] = a3;
a1[2] = a4;
*a1 = a4;
a1[3] = a2;
a1[4] = a2;
if ( a2 != 1 )
a4 += a3 * (a2 - 1);
a1[1] = a4;
return 0LL;
}

original_code:
int
ts_vector_init_data(struct ts_vector_s *head, size_t count, size_t size, void *data) {
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 29); (*__errno_location ())=0; goto error; };
 if (!(data)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 30); (*__errno_location ())=0; goto error; };
 if (!(size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "vector.c", 31); (*__errno_location ())=0; goto error; };
 if (!(count != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "vector.c", 32); (*__errno_location ())=0; goto error; };
 head->size = size;
 head->head = head->array = data;
 head->length = head->count = count;
 head->tail = head->count > 1 ? ((head->count - 1) == 0 ? (head->head) : (head->head) + ((head->count - 1) * (head->size))) : head->head;
 return (0);
error:
 ts_vector_unset(head);
 return (1);
}

canonical_original_code:
int ts_vector_init_data(struct ts_vector_s *head, unsigned long count, unsigned long size, void *data) {
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 29); (*__errno_location ())=0; goto error; };
 if (!(data)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 30); (*__errno_location ())=0; goto error; };
 if (!(size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "vector.c", 31); (*__errno_location ())=0; goto error; };
 if (!(count != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "vector.c", 32); (*__errno_location ())=0; goto error; };
 head->size = size;
 head->head = head->array = data;
 head->length = head->count = count;
 head->tail = head->count > 1 ? ((head->count - 1) == 0 ? (head->head) : (head->head) + ((head->count - 1) * (head->size))) : head->head;
 return (0);
error:
 ts_vector_unset(head);
 return (1);
}

variable_types:
data
void *


decompiled_code:
void *__fastcall ts_vector_new(__int64 a1)
{
void *v1; // rax
void *v2; // r12

v1 = calloc(1uLL, 0x38uLL);
v2 = v1;
if ( v1 )
{
ts_vector_init((__int64)v1, a1);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 47LL);
*_errno_location() = 0;
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
void *v1; // rax
void *v2; // r12

v1 = calloc(1uLL, 0x38uLL);
v2 = v1;
if ( v1 )
{
func0((__int64)v1, a1);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 47LL);
*_errno_location() = 0;
}
return v2;
}

original_code:
struct ts_vector_s *
ts_vector_new(size_t size) {
 struct ts_vector_s *head;
 head = calloc(1, sizeof(struct ts_vector_s));
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 47); (*__errno_location ())=0; goto error; };
 ts_vector_init(head, size);
 return head;
error:
 if (head)
  free(head);
 return ((void *)0);
}

canonical_original_code:
struct ts_vector_s *ts_vector_new(unsigned long size) {
 struct ts_vector_s *head;
 head = calloc(1, sizeof(struct ts_vector_s));
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 47); (*__errno_location ())=0; goto error; };
 ts_vector_init(head, size);
 return head;
error:
 if (head)
  free(head);
 return ((void *)0);
}

return_type: struct ts_vector_s { void *head; void *tail; void *array; unsigned long count; unsigned long length; unsigned long size; struct ts_vector_policy_s { enum _ts_vector_policy { TS_VECTOR_POLICY_IMMEDIATE=expr, TS_VECTOR_POLICY_EAGER=expr, TS_VECTOR_POLICY_SNAKE=expr, TS_VECTOR_POLICY_RESV0=expr, TS_VECTOR_POLICY_RESV1=expr } flags; } policy; } *


decompiled_code:
void __fastcall ts_vector_free(void *ptr)
{
if ( ptr )
{
ts_vector_unset((__int64)ptr);
free(ptr);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 58LL);
*_errno_location() = 0;
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
if ( ptr )
{
func1((__int64)ptr);
free(ptr);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 58LL);
*_errno_location() = 0;
}
}

original_code:
void
ts_vector_free(struct ts_vector_s *head) {
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 58); (*__errno_location ())=0; goto error; };
 ts_vector_unset(head);
 free(head);
error:
 return;
}


decompiled_code:
__int64 __fastcall ts_vector_resize(__int64 a1)
{
char *v1; // rax
unsigned __int64 v2; // rdx
__int64 result; // rax

v1 = (char *)realloc(*(void **)(a1 + 16), *(_QWORD *)(a1 + 40) * *(_QWORD *)(a1 + 32));
if ( v1 )
{
v2 = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 16) = v1;
*(_QWORD *)a1 = v1;
if ( v2 > 1 )
v1 += *(_QWORD *)(a1 + 40) * (v2 - 1);
*(_QWORD *)(a1 + 8) = v1;
result = 0LL;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 72LL);
*_errno_location() = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
char *v1; // rax
unsigned __int64 v2; // rdx
__int64 result; // rax

v1 = (char *)realloc(*(void **)(a1 + 16), *(_QWORD *)(a1 + 40) * *(_QWORD *)(a1 + 32));
if ( v1 )
{
v2 = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 16) = v1;
*(_QWORD *)a1 = v1;
if ( v2 > 1 )
v1 += *(_QWORD *)(a1 + 40) * (v2 - 1);
*(_QWORD *)(a1 + 8) = v1;
result = 0LL;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 72LL);
*_errno_location() = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
ts_vector_resize(struct ts_vector_s *head) {
 void *buf;
 size_t head_offset = 0;
 if (head->head && head->array != head->array)
  head_offset = ((head->head) > (head->array) ? ((head->head) - (head->array)) / (head->size) : 0);
 buf = realloc(head->array, head->length * head->size);
 if (!(buf)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 72); (*__errno_location ())=0; goto error; };
 head->array = buf;
 head->head = (head_offset) ? ((head_offset) == 0 ? (head->array) : (head->array) + ((head_offset) * (head->size))) : buf;
 head->tail = ((head->count > 1 ? head->count - 1 : 0) == 0 ? (head->head) : (head->head) + ((head->count > 1 ? head->count - 1 : 0) * (head->size)));
 return (0);
error:
 return (-1);
}

canonical_original_code:
int ts_vector_resize(struct ts_vector_s *head) {
 void *buf;
 unsigned long head_offset = 0;
 if (head->head && head->array != head->array)
  head_offset = ((head->head) > (head->array) ? ((head->head) - (head->array)) / (head->size) : 0);
 buf = realloc(head->array, head->length * head->size);
 if (!(buf)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 72); (*__errno_location ())=0; goto error; };
 head->array = buf;
 head->head = (head_offset) ? ((head_offset) == 0 ? (head->array) : (head->array) + ((head_offset) * (head->size))) : buf;
 head->tail = ((head->count > 1 ? head->count - 1 : 0) == 0 ? (head->head) : (head->head) + ((head->count > 1 ? head->count - 1 : 0) * (head->size)));
 return (0);
error:
 return (-1);
}


decompiled_code:
__int64 __fastcall ts_vector_grow(__int64 a1)
{
if ( a1 )
{
if ( *(_QWORD *)(a1 + 40) )
{
++*(_QWORD *)(a1 + 32);
return ts_vector_resize(a1);
}
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "vector.c", 83LL);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 83LL);
}
*_errno_location() = 0;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
if ( a1 )
{
if ( *(_QWORD *)(a1 + 40) )
{
++*(_QWORD *)(a1 + 32);
return func5(a1);
}
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "vector.c", 83LL);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 83LL);
}
*_errno_location() = 0;
return 0xFFFFFFFFLL;
}

original_code:
int
ts_vector_grow(struct ts_vector_s *head, size_t count) {
 do { if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 83); (*__errno_location ())=0; goto error; }; if (!((head)->size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "vector.c", 83); (*__errno_location ())=0; goto error; }; } while (0);
 head->length++;
 return (ts_vector_resize(head));
error:
 return (-1);
}

canonical_original_code:
int ts_vector_grow(struct ts_vector_s *head, unsigned long count) {
 do { if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 83); (*__errno_location ())=0; goto error; }; if (!((head)->size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "vector.c", 83); (*__errno_location ())=0; goto error; }; } while (0);
 head->length++;
 return (ts_vector_resize(head));
error:
 return (-1);
}


decompiled_code:
__int64 __fastcall ts_vector_shrink(__int64 a1)
{
if ( a1 )
{
if ( *(_QWORD *)(a1 + 40) )
return 0LL;
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "vector.c", 92LL);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 92LL);
}
*_errno_location() = 0;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
if ( a1 )
{
if ( *(_QWORD *)(a1 + 40) )
return 0LL;
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "vector.c", 92LL);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", 92LL);
}
*_errno_location() = 0;
return 0xFFFFFFFFLL;
}

original_code:
int
ts_vector_shrink(struct ts_vector_s *head, size_t count) {
 do { if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 92); (*__errno_location ())=0; goto error; }; if (!((head)->size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "vector.c", 92); (*__errno_location ())=0; goto error; }; } while (0);
 return (0);
error:
 return (-1);
}

canonical_original_code:
int ts_vector_shrink(struct ts_vector_s *head, unsigned long count) {
 do { if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 92); (*__errno_location ())=0; goto error; }; if (!((head)->size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "vector.c", 92); (*__errno_location ())=0; goto error; }; } while (0);
 return (0);
error:
 return (-1);
}


decompiled_code:
__int64 __fastcall ts_vector_operate(char **a1, void *a2, __int64 a3, int a4, unsigned __int64 a5)
{
__int64 result; // rax
unsigned __int64 v9; // rdx
char *v10; // r13
char *v11; // rsi
char *v12; // rsi
unsigned __int64 v13; // rdx
char *v14; // rdi
char *v15; // r13
size_t v16; // r8
int *v17; // rax
const char *v18; // r9
__int64 v19; // r8
int *v20; // rbx
int *v21; // rax
const char *v22; // r9
__int64 v23; // r8
__int64 v24; // rcx
int *v25; // rax
__int64 v26; // rcx
char *v27; // rax
char *v28; // rax
char *v29; // rax

if ( !a1 )
{
v26 = 107LL;
goto LABEL_49;
}
if ( !a4 )
{
v9 = (unsigned __int64)a1[3];
if ( !v9 )
{
v17 = _errno_location();
v18 = "None";
v19 = (unsigned int)*v17;
v20 = v17;
if ( (_DWORD)v19 )
{
v27 = strerror(v19);
v19 = (unsigned int)*v20;
v18 = v27;
}
fprintf(stderr, "ERROR: %s:%u: errno %d, %s: No items to remove\n", "vector.c", 111LL, v19, v18);
goto LABEL_40;
}
if ( a5 + 1 <= 1 )
{
if ( (unsigned int)ts_vector_shrink((__int64)a1) )
return 0xFFFFFFFFLL;
if ( a5 == -1LL )
{
v11 = a1[1];
if ( a2 )
{
memcpy(a2, v11, (size_t)a1[5]);
v11 = a1[1];
}
goto LABEL_18;
}
v10 = *a1;
}
else
{
if ( v9 <= abs64(a5) )
{
v21 = _errno_location();
v22 = "None";
v23 = (unsigned int)*v21;
v20 = v21;
if ( (_DWORD)v23 )
{
v28 = strerror(v23);
v23 = (unsigned int)*v20;
v22 = v28;
}
v24 = 112LL;
LABEL_44:
fprintf(stderr, "ERROR: %s:%u: errno %d, %s: Index outside of vector items.\n", "vector.c", v24, v23, v22);
LABEL_40:
*v20 = 0;
return 0xFFFFFFFFLL;
}
if ( (unsigned int)ts_vector_shrink((__int64)a1) )
return 0xFFFFFFFFLL;
v10 = 0LL;
if ( a5 < (unsigned __int64)a1[3] )
v10 = &(*a1)[a5 * (_QWORD)a1[5]];
}
if ( a2 )
memcpy(a2, v10, (size_t)a1[5]);
memmove(v10, &a1[5][(_QWORD)v10], (_QWORD)a1[5] * (_QWORD)&a1[3][~a5]);
v11 = a1[1];
LABEL_18:
v12 = (char *)(v11 - a1[5]);
--a1[3];
result = 0LL;
a1[1] = v12;
return result;
}
if ( a4 != 1 )
return 0xFFFFFFFFLL;
if ( a2 )
{
if ( a5 + 1 <= 1 )
{
if ( (unsigned int)ts_vector_grow((__int64)a1) )
return 0xFFFFFFFFLL;
v13 = (unsigned __int64)a1[3];
if ( a5 == -1LL )
{
v15 = a1[1];
v16 = (size_t)a1[5];
if ( v13 )
{
v15 += v16;
a1[1] = v15;
}
goto LABEL_22;
}
v15 = *a1;
goto LABEL_28;
}
if ( abs64(a5) < (unsigned __int64)a1[3] )
{
if ( (unsigned int)ts_vector_grow((__int64)a1) )
return 0xFFFFFFFFLL;
v13 = (unsigned __int64)a1[3];
if ( a5 < v13 )
{
v14 = a1[5];
v15 = &(*a1)[(_QWORD)v14 * a5];
goto LABEL_21;
}
v15 = 0LL;
LABEL_28:
if ( !v13 )
{
v16 = (size_t)a1[5];
goto LABEL_22;
}
v14 = a1[5];
LABEL_21:
a1[1] = &a1[1][(_QWORD)v14];
memmove(&v14[(_QWORD)v15], v15, (_QWORD)v14 * (v13 - a5));
v16 = (size_t)a1[5];
LABEL_22:
memcpy(v15, a2, v16);
++a1[3];
return 0LL;
}
v25 = _errno_location();
v22 = "None";
v23 = (unsigned int)*v25;
v20 = v25;
if ( (_DWORD)v23 )
{
v29 = strerror(v23);
v23 = (unsigned int)*v20;
v22 = v29;
}
v24 = 128LL;
goto LABEL_44;
}
v26 = 127LL;
LABEL_49:
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", v26);
*_errno_location() = 0;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char **a1, void *a2, __int64 a3, int a4, unsigned __int64 a5)
{
__int64 result; // rax
unsigned __int64 v9; // rdx
char *v10; // r13
char *v11; // rsi
char *v12; // rsi
unsigned __int64 v13; // rdx
char *v14; // rdi
char *v15; // r13
size_t v16; // r8
int *v17; // rax
const char *v18; // r9
__int64 v19; // r8
int *v20; // rbx
int *v21; // rax
const char *v22; // r9
__int64 v23; // r8
__int64 v24; // rcx
int *v25; // rax
__int64 v26; // rcx
char *v27; // rax
char *v28; // rax
char *v29; // rax

if ( !a1 )
{
v26 = 107LL;
goto LABEL_49;
}
if ( !a4 )
{
v9 = (unsigned __int64)a1[3];
if ( !v9 )
{
v17 = _errno_location();
v18 = "None";
v19 = (unsigned int)*v17;
v20 = v17;
if ( (_DWORD)v19 )
{
v27 = strerror(v19);
v19 = (unsigned int)*v20;
v18 = v27;
}
fprintf(stderr, "ERROR: %s:%u: errno %d, %s: No items to remove\n", "vector.c", 111LL, v19, v18);
goto LABEL_40;
}
if ( a5 + 1 <= 1 )
{
if ( (unsigned int)func7((__int64)a1) )
return 0xFFFFFFFFLL;
if ( a5 == -1LL )
{
v11 = a1[1];
if ( a2 )
{
memcpy(a2, v11, (size_t)a1[5]);
v11 = a1[1];
}
goto LABEL_18;
}
v10 = *a1;
}
else
{
if ( v9 <= abs64(a5) )
{
v21 = _errno_location();
v22 = "None";
v23 = (unsigned int)*v21;
v20 = v21;
if ( (_DWORD)v23 )
{
v28 = strerror(v23);
v23 = (unsigned int)*v20;
v22 = v28;
}
v24 = 112LL;
LABEL_44:
fprintf(stderr, "ERROR: %s:%u: errno %d, %s: Index outside of vector items.\n", "vector.c", v24, v23, v22);
LABEL_40:
*v20 = 0;
return 0xFFFFFFFFLL;
}
if ( (unsigned int)func7((__int64)a1) )
return 0xFFFFFFFFLL;
v10 = 0LL;
if ( a5 < (unsigned __int64)a1[3] )
v10 = &(*a1)[a5 * (_QWORD)a1[5]];
}
if ( a2 )
memcpy(a2, v10, (size_t)a1[5]);
memmove(v10, &a1[5][(_QWORD)v10], (_QWORD)a1[5] * (_QWORD)&a1[3][~a5]);
v11 = a1[1];
LABEL_18:
v12 = (char *)(v11 - a1[5]);
--a1[3];
result = 0LL;
a1[1] = v12;
return result;
}
if ( a4 != 1 )
return 0xFFFFFFFFLL;
if ( a2 )
{
if ( a5 + 1 <= 1 )
{
if ( (unsigned int)func6((__int64)a1) )
return 0xFFFFFFFFLL;
v13 = (unsigned __int64)a1[3];
if ( a5 == -1LL )
{
v15 = a1[1];
v16 = (size_t)a1[5];
if ( v13 )
{
v15 += v16;
a1[1] = v15;
}
goto LABEL_22;
}
v15 = *a1;
goto LABEL_28;
}
if ( abs64(a5) < (unsigned __int64)a1[3] )
{
if ( (unsigned int)func6((__int64)a1) )
return 0xFFFFFFFFLL;
v13 = (unsigned __int64)a1[3];
if ( a5 < v13 )
{
v14 = a1[5];
v15 = &(*a1)[(_QWORD)v14 * a5];
goto LABEL_21;
}
v15 = 0LL;
LABEL_28:
if ( !v13 )
{
v16 = (size_t)a1[5];
goto LABEL_22;
}
v14 = a1[5];
LABEL_21:
a1[1] = &a1[1][(_QWORD)v14];
memmove(&v14[(_QWORD)v15], v15, (_QWORD)v14 * (v13 - a5));
v16 = (size_t)a1[5];
LABEL_22:
memcpy(v15, a2, v16);
++a1[3];
return 0LL;
}
v25 = _errno_location();
v22 = "None";
v23 = (unsigned int)*v25;
v20 = v25;
if ( (_DWORD)v23 )
{
v29 = strerror(v23);
v23 = (unsigned int)*v20;
v22 = v29;
}
v24 = 128LL;
goto LABEL_44;
}
v26 = 127LL;
LABEL_49:
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "vector.c", v26);
*_errno_location() = 0;
return 0xFFFFFFFFLL;
}

original_code:
int
ts_vector_operate(
    struct ts_vector_s *head,
    void *data,
    size_t count,
    ts_vector_operation_t operation,
    ts_vector_idx_t idx) {
 void *ptr = ((void *)0);
 int result = 0;
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 107); (*__errno_location ())=0; goto error; };
 switch (operation) {
  case TS_VECTOR_OP_REMOVE:
   if (!(head->count > 0)) { fprintf(stderr, "ERROR: %s:%u: errno %d, %s: " "No items to remove" "\n", "vector.c", 111, (*__errno_location ()), ((*__errno_location ()) ? strerror((*__errno_location ())) : "None")); (*__errno_location ())=0; goto error; };
   if (!((idx) == 0 || (idx) == -1 || (((idx) > 0) ? (idx) : -(idx)) < (head)->count)) { fprintf(stderr, "ERROR: %s:%u: errno %d, %s: " "Index outside of vector items." "\n", "vector.c", 112, (*__errno_location ()), ((*__errno_location ()) ? strerror((*__errno_location ())) : "None")); (*__errno_location ())=0; goto error; };
   if(ts_vector_shrink(head, 1))
    goto error;
   ptr = ( (idx) == -1 ? (head)->tail : (idx) == 0 ? (head)->head : (idx) < (head)->count ? (((idx)) == 0 ? ((head)->head) : ((head)->head) + (((idx)) * ((head)->size))) : ((void *)0));
   if (data != ((void *)0))
    memcpy(data, ptr, head->size);
   if (idx != -1)
    memmove(ptr, ptr + head->size, (head->count - idx - 1) * head->size);
   ptr = ((void *)0);
   head->count--;
   head->tail -= head->size;
   break;
  case TS_VECTOR_OP_INSERT:
   if (!(data)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 127); (*__errno_location ())=0; goto error; };
   if (!((idx) == 0 || (idx) == -1 || (((idx) > 0) ? (idx) : -(idx)) < (head)->count)) { fprintf(stderr, "ERROR: %s:%u: errno %d, %s: " "Index outside of vector items." "\n", "vector.c", 128, (*__errno_location ()), ((*__errno_location ()) ? strerror((*__errno_location ())) : "None")); (*__errno_location ())=0; goto error; };
   if(ts_vector_grow(head, 1))
    goto error;
   ptr = ( (idx) == -1 ? (head)->tail : (idx) == 0 ? (head)->head : (idx) < (head)->count ? (((idx)) == 0 ? ((head)->head) : ((head)->head) + (((idx)) * ((head)->size))) : ((void *)0));
   if (head->count) {
    head->tail += head->size;
    if (idx != -1)
     memmove(ptr + head->size, ptr, (head->count - idx) * head->size);
    if (idx == -1)
     ptr = head->tail;
   }
   memcpy(ptr, data, head->size);
   head->count++;
   break;
  default:
   goto error;
 }
 goto out;
error:
 result = -1;
out:
 return (result);
}

canonical_original_code:
int ts_vector_operate(struct ts_vector_s *head, void *data, unsigned long count, enum _ts_vector_operation operation, long idx) {
 void *ptr = ((void *)0);
 int result = 0;
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 107); (*__errno_location ())=0; goto error; };
 switch (operation) {
  case TS_VECTOR_OP_REMOVE:
   if (!(head->count > 0)) { fprintf(stderr, "ERROR: %s:%u: errno %d, %s: " "No items to remove" "\n", "vector.c", 111, (*__errno_location ()), ((*__errno_location ()) ? strerror((*__errno_location ())) : "None")); (*__errno_location ())=0; goto error; };
   if (!((idx) == 0 || (idx) == -1 || (((idx) > 0) ? (idx) : -(idx)) < (head)->count)) { fprintf(stderr, "ERROR: %s:%u: errno %d, %s: " "Index outside of vector items." "\n", "vector.c", 112, (*__errno_location ()), ((*__errno_location ()) ? strerror((*__errno_location ())) : "None")); (*__errno_location ())=0; goto error; };
   if(ts_vector_shrink(head, 1))
    goto error;
   ptr = ( (idx) == -1 ? (head)->tail : (idx) == 0 ? (head)->head : (idx) < (head)->count ? (((idx)) == 0 ? ((head)->head) : ((head)->head) + (((idx)) * ((head)->size))) : ((void *)0));
   if (data != ((void *)0))
    memcpy(data, ptr, head->size);
   if (idx != -1)
    memmove(ptr, ptr + head->size, (head->count - idx - 1) * head->size);
   ptr = ((void *)0);
   head->count--;
   head->tail -= head->size;
   break;
  case TS_VECTOR_OP_INSERT:
   if (!(data)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "vector.c", 127); (*__errno_location ())=0; goto error; };
   if (!((idx) == 0 || (idx) == -1 || (((idx) > 0) ? (idx) : -(idx)) < (head)->count)) { fprintf(stderr, "ERROR: %s:%u: errno %d, %s: " "Index outside of vector items." "\n", "vector.c", 128, (*__errno_location ()), ((*__errno_location ()) ? strerror((*__errno_location ())) : "None")); (*__errno_location ())=0; goto error; };
   if(ts_vector_grow(head, 1))
    goto error;
   ptr = ( (idx) == -1 ? (head)->tail : (idx) == 0 ? (head)->head : (idx) < (head)->count ? (((idx)) == 0 ? ((head)->head) : ((head)->head) + (((idx)) * ((head)->size))) : ((void *)0));
   if (head->count) {
    head->tail += head->size;
    if (idx != -1)
     memmove(ptr + head->size, ptr, (head->count - idx) * head->size);
    if (idx == -1)
     ptr = head->tail;
   }
   memcpy(ptr, data, head->size);
   head->count++;
   break;
  default:
   goto error;
 }
 goto out;
error:
 result = -1;
out:
 return (result);
}

variable_types: enum _ts_vector_operation { TS_VECTOR_OP_REMOVE=0, TS_VECTOR_OP_INSERT=1 }

variable_types: idx long

variable_types: result int


decompiled_code:
__int64 __fastcall ts_vector_get(_QWORD *a1, unsigned __int64 a2)
{
__int64 result; // rax

if ( a2 == -1LL )
return a1[1];
if ( !a2 )
return *a1;
result = 0LL;
if ( a1[3] > a2 )
result = a1[5] * a2 + *a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, unsigned __int64 a2)
{
__int64 result; // rax

if ( a2 == -1LL )
return a1[1];
if ( !a2 )
return *a1;
result = 0LL;
if ( a1[3] > a2 )
result = a1[5] * a2 + *a1;
return result;
}

original_code:
void *
ts_vector_get(struct ts_vector_s *head, ts_vector_idx_t idx) {
 return ( (idx) == -1 ? (head)->tail : (idx) == 0 ? (head)->head : (idx) < (head)->count ? (((idx)) == 0 ? ((head)->head) : ((head)->head) + (((idx)) * ((head)->size))) : ((void *)0));
}

canonical_original_code:
void *ts_vector_get(struct ts_vector_s *head, long idx) {
 return ( (idx) == -1 ? (head)->tail : (idx) == 0 ? (head)->head : (idx) < (head)->count ? (((idx)) == 0 ? ((head)->head) : ((head)->head) + (((idx)) * ((head)->size))) : ((void *)0));
}


decompiled_code:
__int64 ts_vector_find()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
return 0LL;
}

original_code:
void *
ts_vector_find(struct ts_vector_s *head, void *data) {
 return (((void *)0));
}

canonical_original_code:
void *ts_vector_find(struct ts_vector_s *head, void *data) {
 return (((void *)0));
}


decompiled_code:
__int64 __fastcall ts_vector_push(char **a1, void *a2)
{
return ts_vector_operate(a1, a2, 1LL, 1, 0xFFFFFFFFFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func11(char **a1, void *a2)
{
return func8(a1, a2, 1LL, 1, 0xFFFFFFFFFFFFFFFFLL);
}

original_code:
int
ts_vector_push(struct ts_vector_s *head, void *data) {
 return (ts_vector_operate(head, data, 1, TS_VECTOR_OP_INSERT, -1));
}


decompiled_code:
__int64 __fastcall ts_vector_unshift(char **a1, void *a2)
{
return ts_vector_operate(a1, a2, 1LL, 1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(char **a1, void *a2)
{
return func8(a1, a2, 1LL, 1, 0LL);
}

original_code:
int
ts_vector_unshift(struct ts_vector_s *head, void *data) {
 return ts_vector_operate(head, data, 1, TS_VECTOR_OP_INSERT, 0);
}


decompiled_code:
__int64 __fastcall ts_vector_insert(char **a1, void *a2, unsigned __int64 a3)
{
return ts_vector_operate(a1, a2, 1LL, 1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func13(char **a1, void *a2, unsigned __int64 a3)
{
return func8(a1, a2, 1LL, 1, a3);
}

original_code:
int
ts_vector_insert(struct ts_vector_s *head, void *data, ts_vector_idx_t idx) {
 return ts_vector_operate(head, data, 1, TS_VECTOR_OP_INSERT, idx);
}

canonical_original_code:
int ts_vector_insert(struct ts_vector_s *head, void *data, long idx) {
 return ts_vector_operate(head, data, 1, TS_VECTOR_OP_INSERT, idx);
}


decompiled_code:
__int64 __fastcall ts_vector_pop(char **a1, void *a2)
{
return ts_vector_operate(a1, a2, 1LL, 0, 0xFFFFFFFFFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func14(char **a1, void *a2)
{
return func8(a1, a2, 1LL, 0, 0xFFFFFFFFFFFFFFFFLL);
}

original_code:
int
ts_vector_pop(struct ts_vector_s *head, void *data) {
 return ts_vector_operate(head, data, 1, TS_VECTOR_OP_REMOVE, -1);
}


decompiled_code:
__int64 __fastcall ts_vector_shift(char **a1, void *a2)
{
return ts_vector_operate(a1, a2, 1LL, 0, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func15(char **a1, void *a2)
{
return func8(a1, a2, 1LL, 0, 0LL);
}

original_code:
int
ts_vector_shift(struct ts_vector_s *head, void *data) {
 return ts_vector_operate(head, data, 1, TS_VECTOR_OP_REMOVE, 0);
}


decompiled_code:
__int64 __fastcall ts_vector_remove(char **a1, void *a2, unsigned __int64 a3)
{
return ts_vector_operate(a1, a2, 1LL, 0, a3);
}

canonical_decompiled_code:
__int64 __fastcall func16(char **a1, void *a2, unsigned __int64 a3)
{
return func8(a1, a2, 1LL, 0, a3);
}

original_code:
int
ts_vector_remove(struct ts_vector_s *head, void* data, ts_vector_idx_t idx) {
 return ts_vector_operate(head, data, 1, TS_VECTOR_OP_REMOVE, idx);
}

canonical_original_code:
int ts_vector_remove(struct ts_vector_s *head, void *data, long idx) {
 return ts_vector_operate(head, data, 1, TS_VECTOR_OP_REMOVE, idx);
}


decompiled_code:
__int64 __fastcall ts_array_init(size_t *a1, size_t a2, size_t a3, char *a4)
{
char *v5; // rax
__int64 v6; // rcx
size_t v7; // [rsp+8h] [rbp-20h]

if ( !a1 )
{
v6 = 5LL;
LABEL_11:
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "array.c", v6);
LABEL_12:
*_errno_location() = 0;
return 1LL;
}
if ( !a2 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "array.c", 6LL);
goto LABEL_12;
}
if ( !a3 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "array.c", 7LL);
goto LABEL_12;
}
if ( !a4 )
{
v7 = a3;
v5 = (char *)calloc(a2, a3);
a3 = v7;
a1[1] = (size_t)v5;
a4 = v5;
if ( v5 )
goto LABEL_6;
v6 = 12LL;
goto LABEL_11;
}
a1[1] = (size_t)a4;
LABEL_6:
*a1 = a3;
if ( a2 != 1 )
a4 += a3 * (a2 - 1);
a1[2] = (size_t)a4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(size_t *a1, size_t a2, size_t a3, char *a4)
{
char *v5; // rax
__int64 v6; // rcx
size_t v7; // [rsp+8h] [rbp-20h]

if ( !a1 )
{
v6 = 5LL;
LABEL_11:
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "array.c", v6);
LABEL_12:
*_errno_location() = 0;
return 1LL;
}
if ( !a2 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "array.c", 6LL);
goto LABEL_12;
}
if ( !a3 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be zero\n", "array.c", 7LL);
goto LABEL_12;
}
if ( !a4 )
{
v7 = a3;
v5 = (char *)calloc(a2, a3);
a3 = v7;
a1[1] = (size_t)v5;
a4 = v5;
if ( v5 )
goto LABEL_6;
v6 = 12LL;
goto LABEL_11;
}
a1[1] = (size_t)a4;
LABEL_6:
*a1 = a3;
if ( a2 != 1 )
a4 += a3 * (a2 - 1);
a1[2] = (size_t)a4;
return 0LL;
}

original_code:
int
ts_array_init(struct ts_array_s *head, size_t count, size_t size, void *data) {
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 5); (*__errno_location ())=0; goto error; };
 if (!(count != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "array.c", 6); (*__errno_location ())=0; goto error; };
 if (!(size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "array.c", 7); (*__errno_location ())=0; goto error; };
 if (data == ((void *)0))
  head->head = calloc(count, size);
 else
  head->head = data;
 if (!(head->head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 12); (*__errno_location ())=0; goto error; };
 head->size = size;
 head->tail = ( count > 1 ? ((count - 1) == 0 ? ((head)->head) : ((head)->head) + ((count - 1) * ((head)->size))) : (head)->head);
 return (0);
error:
 return (1);
}

canonical_original_code:
int ts_array_init(struct ts_array_s *head, unsigned long count, unsigned long size, void *data) {
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 5); (*__errno_location ())=0; goto error; };
 if (!(count != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "array.c", 6); (*__errno_location ())=0; goto error; };
 if (!(size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "array.c", 7); (*__errno_location ())=0; goto error; };
 if (data == ((void *)0))
  head->head = calloc(count, size);
 else
  head->head = data;
 if (!(head->head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 12); (*__errno_location ())=0; goto error; };
 head->size = size;
 head->tail = ( count > 1 ? ((count - 1) == 0 ? ((head)->head) : ((head)->head) + ((count - 1) * ((head)->size))) : (head)->head);
 return (0);
error:
 return (1);
}

variable_types: struct ts_array_s { unsigned long size; void *head; void *tail; } *


decompiled_code:
__int64 __fastcall ts_array_unset(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
a1[1] = 0LL;
result = 0LL;
a1[2] = 0LL;
*a1 = 0LL;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "array.c", 22LL);
*_errno_location() = 0;
result = 1LL;
}
return result;
}

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

if ( a1 )
{
a1[1] = 0LL;
result = 0LL;
a1[2] = 0LL;
*a1 = 0LL;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "array.c", 22LL);
*_errno_location() = 0;
result = 1LL;
}
return result;
}

original_code:
ts_return_t
ts_array_unset(struct ts_array_s *head) {
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 22); (*__errno_location ())=0; goto error; };
 head->head = ((void *)0);
 head->tail = ((void *)0);
 head->size = 0;
 return TS_RETURN_OK;
error:
 return TS_RETURN_ERROR;
}

canonical_original_code:
int ts_array_unset(struct ts_array_s *head) {
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 22); (*__errno_location ())=0; goto error; };
 head->head = ((void *)0);
 head->tail = ((void *)0);
 head->size = 0;
 return TS_RETURN_OK;
error:
 return TS_RETURN_ERROR;
}

user_defined_types: struct ts_array_s { unsigned long size; void *head; void *tail; }


decompiled_code:
size_t *__fastcall ts_array_new(size_t a1, size_t a2)
{
size_t *v2; // rax
size_t *v3; // r12
size_t *v4; // rdi

v2 = (size_t *)calloc(1uLL, 0x18uLL);
v3 = v2;
if ( v2 )
{
if ( (unsigned int)ts_array_init(v2, a1, a2, 0LL) )
{
v4 = v3;
v3 = 0LL;
free(v4);
}
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "array.c", 35LL);
*_errno_location() = 0;
}
return v3;
}

canonical_decompiled_code:
size_t *__fastcall func2(size_t a1, size_t a2)
{
size_t *v2; // rax
size_t *v3; // r12
size_t *v4; // rdi

v2 = (size_t *)calloc(1uLL, 0x18uLL);
v3 = v2;
if ( v2 )
{
if ( (unsigned int)func0(v2, a1, a2, 0LL) )
{
v4 = v3;
v3 = 0LL;
free(v4);
}
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "array.c", 35LL);
*_errno_location() = 0;
}
return v3;
}

original_code:
struct ts_array_s *
ts_array_new(size_t count, size_t size) {
 struct ts_array_s *head;
 head = calloc(1, sizeof(struct ts_array_s));
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 35); (*__errno_location ())=0; goto error; };
 if (ts_array_init(head, count, size, ((void *)0)))
  goto error;
 return (head);
error:
 if (head)
  free(head);
 return (((void *)0));
}

canonical_original_code:
struct ts_array_s *ts_array_new(unsigned long count, unsigned long size) {
 struct ts_array_s *head;
 head = calloc(1, sizeof(struct ts_array_s));
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 35); (*__errno_location ())=0; goto error; };
 if (ts_array_init(head, count, size, ((void *)0)))
  goto error;
 return (head);
error:
 if (head)
  free(head);
 return (((void *)0));
}

return_type: struct ts_array_s { unsigned long size; void *head; void *tail; } *


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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
ts_array_unset(ptr);
free(ptr);
}
}

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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
func1(ptr);
free(ptr);
}
}

original_code:
void
ts_array_free(struct ts_array_s *head) {
 if (head == ((void *)0))
  return;
 if (head->head)
  free(head->head);
 ts_array_unset(head);
 free(head);
}


original_code:
void
ts_array_resize(struct ts_array_s *head, size_t count, size_t size) {
 size_t oldcount;
 void *map;
 size_t idx;
 do { if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 62); (*__errno_location ())=0; goto error; }; if (!((head)->head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 62); (*__errno_location ())=0; goto error; }; if (!((head)->tail)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 62); (*__errno_location ())=0; goto error; }; if (!((head)->size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "array.c", 62); (*__errno_location ())=0; goto error; }; } while (0);
 oldcount = ( (head)->tail == (head)->head ? 1 : (((head)->tail) > ((head)->head) ? (((head)->tail) - ((head)->head)) / ((head)->size) : 0) + 1);
 if (count == 0)
  count = oldcount;
 if (size == 0)
  size = head->size;
 if (size == head->size && count == oldcount)
  return;
 if (!(size >= head->size && count >= oldcount)) { fprintf(stderr, "ERROR: %s:%u: errno %d, %s: " "Shrinking arrays is not supported." "\n", "array.c", 74, (*__errno_location ()), ((*__errno_location ()) ? strerror((*__errno_location ())) : "None")); (*__errno_location ())=0; goto error; }
 if (size > head->size && count >= oldcount) {
  map = calloc(count, size);
  if (!(map)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 80); (*__errno_location ())=0; goto error; };
  for (idx = 0; idx < oldcount; idx++) {
   memcpy(((idx) == 0 ? (map) : (map) + ((idx) * (size))), ((idx) == 0 ? (head->head) : (head->head) + ((idx) * (head->size))), head->size);
  }
  head->size = size;
  free(head->head);
 }
 else {
  map = realloc(head->head, count * size);
  if (!(map)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 89); (*__errno_location ())=0; goto error; };
 }
 head->head = map;
 if (oldcount < count) {
  memset(((oldcount) == 0 ? (head->head) : (head->head) + ((oldcount) * (head->size))), '\0',
      count - oldcount);
 }
 head->tail = ( count > 1 ? ((count - 1) == 0 ? ((head)->head) : ((head)->head) + ((count - 1) * ((head)->size))) : (head)->head);
 return;
error:
 if (map != ((void *)0))
  free(map);
 return;
}

canonical_original_code:
void ts_array_resize(struct ts_array_s *head, unsigned long count, unsigned long size) {
 unsigned long oldcount;
 void *map;
 unsigned long idx;
 do { if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 62); (*__errno_location ())=0; goto error; }; if (!((head)->head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 62); (*__errno_location ())=0; goto error; }; if (!((head)->tail)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 62); (*__errno_location ())=0; goto error; }; if (!((head)->size != 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be zero" "\n", "array.c", 62); (*__errno_location ())=0; goto error; }; } while (0);
 oldcount = ( (head)->tail == (head)->head ? 1 : (((head)->tail) > ((head)->head) ? (((head)->tail) - ((head)->head)) / ((head)->size) : 0) + 1);
 if (count == 0)
  count = oldcount;
 if (size == 0)
  size = head->size;
 if (size == head->size && count == oldcount)
  return;
 if (!(size >= head->size && count >= oldcount)) { fprintf(stderr, "ERROR: %s:%u: errno %d, %s: " "Shrinking arrays is not supported." "\n", "array.c", 74, (*__errno_location ()), ((*__errno_location ()) ? strerror((*__errno_location ())) : "None")); (*__errno_location ())=0; goto error; }
 if (size > head->size && count >= oldcount) {
  map = calloc(count, size);
  if (!(map)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 80); (*__errno_location ())=0; goto error; };
  for (idx = 0; idx < oldcount; idx++) {
   memcpy(((idx) == 0 ? (map) : (map) + ((idx) * (size))), ((idx) == 0 ? (head->head) : (head->head) + ((idx) * (head->size))), head->size);
  }
  head->size = size;
  free(head->head);
 }
 else {
  map = realloc(head->head, count * size);
  if (!(map)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 89); (*__errno_location ())=0; goto error; };
 }
 head->head = map;
 if (oldcount < count) {
  memset(((oldcount) == 0 ? (head->head) : (head->head) + ((oldcount) * (head->size))), '\0',
      count - oldcount);
 }
 head->tail = ( count > 1 ? ((count - 1) == 0 ? ((head)->head) : ((head)->head) + ((count - 1) * ((head)->size))) : (head)->head);
 return;
error:
 if (map != ((void *)0))
  free(map);
 return;
}

variable_types:
oldcount
unsigned long

variable_types:
map
void *

variable_types:
idx
unsigned long


decompiled_code:
__int64 __fastcall ts_array_get(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
{
result = a1[1];
if ( a2 )
result += *a1 * a2;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "array.c", 109LL);
*_errno_location() = 0;
result = 0LL;
}
return result;
}

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

if ( a1 )
{
result = a1[1];
if ( a2 )
result += *a1 * a2;
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "array.c", 109LL);
*_errno_location() = 0;
result = 0LL;
}
return result;
}

original_code:
void *
ts_array_get(struct ts_array_s *head, size_t offset) {
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 109); (*__errno_location ())=0; goto error; };
 return ((offset) == 0 ? (head->head) : (head->head) + ((offset) * (head->size)));
error:
 return (((void *)0));
}

canonical_original_code:
void *ts_array_get(struct ts_array_s *head, unsigned long offset) {
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 109); (*__errno_location ())=0; goto error; };
 return ((offset) == 0 ? (head->head) : (head->head) + ((offset) * (head->size)));
error:
 return (((void *)0));
}

variable_types:
offset
unsigned long


decompiled_code:
size_t *__fastcall ts_mem_to_array(void *src, size_t a2, size_t a3)
{
size_t *v4; // r12
void *v5; // rax
void *v6; // rbp
size_t *v8; // rdi
size_t *v9; // rdi

v4 = (size_t *)calloc(1uLL, 0x18uLL);
if ( v4 )
{
v5 = malloc(a3 * a2);
v6 = v5;
if ( v5 )
{
memcpy(v5, src, a3 * a2);
if ( (unsigned int)ts_array_init(v4, a2, a3, (char *)v6) )
{
fprintf(stderr, "DEBUG: %s:%d: Value should be zero\n", "array.c", 124LL);
v8 = v4;
v4 = 0LL;
*_errno_location() = 0;
ts_array_free(v8);
free(v6);
}
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "array.c", 122LL);
v9 = v4;
v4 = 0LL;
*_errno_location() = 0;
ts_array_free(v9);
}
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "array.c", 120LL);
*_errno_location() = 0;
}
return v4;
}

canonical_decompiled_code:
size_t *__fastcall func6(void *src, size_t a2, size_t a3)
{
size_t *v4; // r12
void *v5; // rax
void *v6; // rbp
size_t *v8; // rdi
size_t *v9; // rdi

v4 = (size_t *)calloc(1uLL, 0x18uLL);
if ( v4 )
{
v5 = malloc(a3 * a2);
v6 = v5;
if ( v5 )
{
memcpy(v5, src, a3 * a2);
if ( (unsigned int)func0(v4, a2, a3, (char *)v6) )
{
fprintf(stderr, "DEBUG: %s:%d: Value should be zero\n", "array.c", 124LL);
v8 = v4;
v4 = 0LL;
*_errno_location() = 0;
func3(v8);
free(v6);
}
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "array.c", 122LL);
v9 = v4;
v4 = 0LL;
*_errno_location() = 0;
func3(v9);
}
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "array.c", 120LL);
*_errno_location() = 0;
}
return v4;
}

original_code:
struct ts_array_s*
ts_mem_to_array(void *ptr, size_t count, size_t size) {
 struct ts_array_s *head;
 void *buf;
 head = calloc(1, sizeof(struct ts_array_s));
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 120); (*__errno_location ())=0; goto error; };
 buf = malloc(count * size);
 if (!(buf)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 122); (*__errno_location ())=0; goto error; };
 if (!(memcpy(buf, ptr, count * size))) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 123); (*__errno_location ())=0; goto error; };
 if (!(ts_array_init(head, count, size, buf) == 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should be zero" "\n", "array.c", 124); (*__errno_location ())=0; goto error; };
 return (head);
error:
 if (head)
  ts_array_free(head);
 if (buf)
  free(buf);
 return (((void *)0));
}

canonical_original_code:
struct ts_array_s *ts_mem_to_array(void *ptr, unsigned long count, unsigned long size) {
 struct ts_array_s *head;
 void *buf;
 head = calloc(1, sizeof(struct ts_array_s));
 if (!(head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 120); (*__errno_location ())=0; goto error; };
 buf = malloc(count * size);
 if (!(buf)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 122); (*__errno_location ())=0; goto error; };
 if (!(memcpy(buf, ptr, count * size))) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "array.c", 123); (*__errno_location ())=0; goto error; };
 if (!(ts_array_init(head, count, size, buf) == 0)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should be zero" "\n", "array.c", 124); (*__errno_location ())=0; goto error; };
 return (head);
error:
 if (head)
  ts_array_free(head);
 if (buf)
  free(buf);
 return (((void *)0));
}


decompiled_code:
void __fastcall ts_snode_free(void *a1)
{
if ( a1 )
{
free(a1);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "slist.c", 16LL);
*_errno_location() = 0;
}
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
if ( a1 )
{
free(a1);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "slist.c", 16LL);
*_errno_location() = 0;
}
}

original_code:
void
ts_snode_free(struct ts_snode_s *node) {
 if (!(node)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "slist.c", 16); (*__errno_location ())=0; goto error; };
 memset(node, '\0', sizeof(struct ts_snode_s));
 free(node);
error:
 return;
}

variable_types: struct ts_snode_s { void *key; struct ts_snode_s *next; } *


decompiled_code:
__int64 __fastcall ts_snode_operation(__int64 *a1, __int64 a2, char a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = 26LL;
if ( !a1 )
goto LABEL_15;
if ( (a3 & 9) != 0 && !a2 )
{
v3 = 28LL;
LABEL_15:
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "slist.c", v3);
*_errno_location() = 0;
return 0LL;
}
if ( (a3 & 1) != 0 )
{
*(_QWORD *)(a2 + 8) = *a1;
result = a2;
*a1 = a2;
}
else if ( (a3 & 8) != 0 )
{
if ( *a1 )
{
*(_QWORD *)(a2 + 8) = *(_QWORD *)(*a1 + 8);
*(_QWORD *)(*a1 + 8) = a2;
}
*a1 = a2;
result = a2;
}
else if ( (a3 & 2) != 0 )
{
result = *a1;
if ( *a1 )
{
*a1 = *(_QWORD *)(result + 8);
*(_QWORD *)(result + 8) = 0LL;
}
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, __int64 a2, char a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = 26LL;
if ( !a1 )
goto LABEL_15;
if ( (a3 & 9) != 0 && !a2 )
{
v3 = 28LL;
LABEL_15:
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "slist.c", v3);
*_errno_location() = 0;
return 0LL;
}
if ( (a3 & 1) != 0 )
{
*(_QWORD *)(a2 + 8) = *a1;
result = a2;
*a1 = a2;
}
else if ( (a3 & 8) != 0 )
{
if ( *a1 )
{
*(_QWORD *)(a2 + 8) = *(_QWORD *)(*a1 + 8);
*(_QWORD *)(*a1 + 8) = a2;
}
*a1 = a2;
result = a2;
}
else if ( (a3 & 2) != 0 )
{
result = *a1;
if ( *a1 )
{
*a1 = *(_QWORD *)(result + 8);
*(_QWORD *)(result + 8) = 0LL;
}
}
else
{
result = 0LL;
}
return result;
}

original_code:
struct ts_snode_s *
ts_snode_operation(struct ts_snode_s **node, struct ts_snode_s *link, ts_snode_op_t operation)
{
 if (!(node)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "slist.c", 26); (*__errno_location ())=0; goto error; };
 if (operation & (TS_SNODE_OP_PUSH + TS_SNODE_OP_UNSHIFT))
  if (!(link)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "slist.c", 28); (*__errno_location ())=0; goto error; };
 if (operation & TS_SNODE_OP_PUSH) {
  link->next = *node;
  *node = link;
 }
 else if (operation & TS_SNODE_OP_UNSHIFT) {
  if (*node) {
   link->next = (*node)->next;
   (*node)->next = link;
  }
  *node = link;
 }
 else if (operation & TS_SNODE_OP_POP) {
  link = *node;
  if (link) {
   *node = link->next;
   link->next = ((void *)0);
  }
 }
 else
  goto error;
 return (link);
error:
 return (((void *)0));
}

canonical_original_code:
struct ts_snode_s *ts_snode_operation(struct ts_snode_s **node, struct ts_snode_s *link, char operation)
{
 if (!(node)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "slist.c", 26); (*__errno_location ())=0; goto error; };
 if (operation & (TS_SNODE_OP_PUSH + TS_SNODE_OP_UNSHIFT))
  if (!(link)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "slist.c", 28); (*__errno_location ())=0; goto error; };
 if (operation & TS_SNODE_OP_PUSH) {
  link->next = *node;
  *node = link;
 }
 else if (operation & TS_SNODE_OP_UNSHIFT) {
  if (*node) {
   link->next = (*node)->next;
   (*node)->next = link;
  }
  *node = link;
 }
 else if (operation & TS_SNODE_OP_POP) {
  link = *node;
  if (link) {
   *node = link->next;
   link->next = ((void *)0);
  }
 }
 else
  goto error;
 return (link);
error:
 return (((void *)0));
}

variable_types:
node
struct ts_snode_s **

variable_types:
link
struct ts_snode_s *

variable_types: operation char

return_type: struct ts_snode_s { void *key; struct ts_snode_s *next; } *


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

v0 = calloc(1uLL, 0x18uLL);
if ( !v0 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "slist.c", 67LL);
*_errno_location() = 0;
}
return v0;
}

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

v0 = calloc(1uLL, 0x18uLL);
if ( !v0 )
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "slist.c", 67LL);
*_errno_location() = 0;
}
return v0;
}

original_code:
struct ts_slist_s *
ts_slist_new(void) {
 struct ts_slist_s *list;
 list = calloc(1, sizeof(struct ts_slist_s));
 if (!(list)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "slist.c", 67); (*__errno_location ())=0; goto error; };
 return (list);
error:
 return (((void *)0));
}

canonical_original_code:
struct ts_slist_s *ts_slist_new() {
 struct ts_slist_s *list;
 list = calloc(1, sizeof(struct ts_slist_s));
 if (!(list)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "slist.c", 67); (*__errno_location ())=0; goto error; };
 return (list);
error:
 return (((void *)0));
}

variable_types: struct ts_slist_s { struct ts_snode_s { void *key; struct ts_snode_s *next; } *head; struct ts_snode_s *tail; unsigned long count; } *

user_defined_types: struct ts_slist_s { struct ts_snode_s *head; struct ts_snode_s *tail; unsigned long count; }


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

if ( ptr )
{
while ( 1 )
{
v2 = (void *)ts_snode_operation((__int64 *)ptr, 0LL, 2);
if ( !v2 )
break;
ts_snode_free(v2);
}
free(*(void **)ptr);
free(ptr);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "slist.c", 76LL);
*_errno_location() = 0;
}
}

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

if ( ptr )
{
while ( 1 )
{
v2 = (void *)func1((__int64 *)ptr, 0LL, 2);
if ( !v2 )
break;
func0(v2);
}
free(*(void **)ptr);
free(ptr);
}
else
{
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "slist.c", 76LL);
*_errno_location() = 0;
}
}

original_code:
void
ts_slist_free(struct ts_slist_s *list) {
 struct ts_snode_s *node = ((void *)0);
 if (!(list)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "slist.c", 76); (*__errno_location ())=0; goto error; };
 while ((node = ts_snode_operation(&list->head, ((void *)0), TS_SNODE_OP_POP)) != ((void *)0))
  ts_snode_free(node);
 free(list->head);
 memset(list, '\0', sizeof(struct ts_slist_s));
 free(list);
error:
 return;
}

user_defined_types: struct ts_snode_s { void *key; struct ts_snode_s *next; }


decompiled_code:
int *__fastcall ts_slist_reverse(__int64 *a1)
{
__int64 v1; // rcx
__int64 v2; // rsi
int *result; // rax
int *v4; // [rsp+8h] [rbp-20h] BYREF

v1 = 145LL;
if ( !a1 )
goto LABEL_8;
if ( !*a1 )
{
v1 = 146LL;
LABEL_8:
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "slist.c", v1);
result = _errno_location();
*result = 0;
return result;
}
v4 = (int *)ts_snode_operation(a1, 0LL, 2);
a1[1] = (__int64)v4;
while ( 1 )
{
v2 = ts_snode_operation(a1, 0LL, 2);
if ( !v2 )
break;
ts_snode_operation((__int64 *)&v4, v2, 1);
}
result = v4;
*a1 = (__int64)v4;
return result;
}

canonical_decompiled_code:
int *__fastcall func5(__int64 *a1)
{
__int64 v1; // rcx
__int64 v2; // rsi
int *result; // rax
int *v4; // [rsp+8h] [rbp-20h] BYREF

v1 = 145LL;
if ( !a1 )
goto LABEL_8;
if ( !*a1 )
{
v1 = 146LL;
LABEL_8:
fprintf(stderr, "DEBUG: %s:%d: Value should not be NULL\n", "slist.c", v1);
result = _errno_location();
*result = 0;
return result;
}
v4 = (int *)func1(a1, 0LL, 2);
a1[1] = (__int64)v4;
while ( 1 )
{
v2 = func1(a1, 0LL, 2);
if ( !v2 )
break;
func1((__int64 *)&v4, v2, 1);
}
result = v4;
*a1 = (__int64)v4;
return result;
}

original_code:
void
ts_slist_reverse(struct ts_slist_s *list) {
 struct ts_snode_s *buf, *next;
 if (!(list)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "slist.c", 145); (*__errno_location ())=0; goto error; };
 if (!(list->head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "slist.c", 146); (*__errno_location ())=0; goto error; };
 buf = ts_snode_operation(&list->head, ((void *)0), TS_SNODE_OP_POP);
 list->tail = buf;
 while ((next = ts_snode_operation(&list->head, ((void *)0), TS_SNODE_OP_POP)) != ((void *)0))
  ts_snode_operation(&buf, next, TS_SNODE_OP_PUSH);
 list->head = buf;
error:
 return;
}

canonical_original_code:
void ts_slist_reverse(struct ts_slist_s *list) {
 struct ts_snode_s *buf; struct ts_snode_s *next;
 if (!(list)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "slist.c", 145); (*__errno_location ())=0; goto error; };
 if (!(list->head)) { fprintf(stderr, "DEBUG: %s:%d: " "Value should not be NULL" "\n", "slist.c", 146); (*__errno_location ())=0; goto error; };
 buf = ts_snode_operation(&list->head, ((void *)0), TS_SNODE_OP_POP);
 list->tail = buf;
 while ((next = ts_snode_operation(&list->head, ((void *)0), TS_SNODE_OP_POP)) != ((void *)0))
  ts_snode_operation(&buf, next, TS_SNODE_OP_PUSH);
 list->head = buf;
error:
 return;
}


argmatch

decompiled_code:
__int64 argmatch()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
int
argmatch(Argopt opt, char *optstr)
{
 return (0);
}

canonical_original_code:
int argmatch(struct argopt_t *opt, char *optstr)
{
 return (0);
}

variable_types: struct argopt_t { char **case_values; int case_count; char *name; int type; } *

variable_types:
optstr
char *


argmatches

decompiled_code:
__int64 argmatches()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
Argopt
argmatches(struct argopt_t **opts, char *optstr)
{
 return (((void *)0));
}

canonical_original_code:
struct argopt_t *argmatches(struct argopt_t **opts, char *optstr)
{
 return (((void *)0));
}

variable_types:
opts
struct argopt_t **

return_type: struct argopt_t { char **case_values; int case_count; char *name; int type; } *


argparse

decompiled_code:
__int64 argparse()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0LL;
}

original_code:
int
argparse(int argc, char **argv, struct argopt_t **opts)
{
 return (0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct argopt_t { char **case_values; int case_count; char *name; int type; } **


printbits

decompiled_code:
int printbits()
{
return puts(&LC0);
}

canonical_decompiled_code:
int func0()
{
return puts(&LC0);
}

original_code:
void
printbits(void *ptr, size_t len)
{
 unsigned char *buf = ptr;
 for (len *= 8; len > -1; len--)
  printf("%u", !!((*buf >> len) & 1));
 puts("");
}

canonical_original_code:
void printbits(void *ptr, unsigned long len)
{
 unsigned char *buf = ptr;
 for (len *= 8; len > -1; len--)
  printf("%u", !!((*buf >> len) & 1));
 puts("");
}

variable_types:
ptr
void *

variable_types:
len
unsigned long

variable_types:
buf
unsigned char *