main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
unsigned int v4; // er14
unsigned int v5; // er13
char *v6; // r12
int v7; // eax
struct passwd *v8; // rax
struct group *v9; // rax
int v10; // ebp
__int16 v11; // ax
int v13; // [rsp+Ch] [rbp-8Ch]
int v14; // [rsp+10h] [rbp-88h]
__int16 v15; // [rsp+14h] [rbp-84h]
const char *v16; // [rsp+18h] [rbp-80h]
char *endptr; // [rsp+28h] [rbp-70h] BYREF
char dest[16]; // [rsp+30h] [rbp-68h] BYREF
__int128 v19; // [rsp+40h] [rbp-58h]
__int64 v20; // [rsp+50h] [rbp-48h]

v3 = "/dev/net/tun";
v4 = -1;
v5 = -1;
v6 = (char *)&src;
v15 = 2;
v16 = *argv;
v14 = 0;
v13 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "bd:f:t:u:g:U");
if ( v7 <= 0 )
break;
switch ( v7 )
{
case 'U':
v15 = 1;
continue;
case 'b':
v14 = 1;
continue;
case 'd':
v13 = 1;
v6 = optarg;
continue;
case 'f':
v3 = optarg;
continue;
case 'g':
v9 = getgrnam(optarg);
if ( v9 )
{
v4 = v9->gr_gid;
}
else
{
v4 = strtol(optarg, &endptr, 0);
if ( *endptr )
{
fprintf(stderr, "'%s' is neither a groupname nor a numeric group.\n", optarg);
LABEL_30:
Usage(v16);
}
}
break;
case 't':
v6 = optarg;
continue;
case 'u':
v8 = getpwnam(optarg);
if ( v8 )
{
v5 = v8->pw_uid;
}
else
{
v5 = strtol(optarg, &endptr, 0);
if ( *endptr )
{
fprintf(stderr, "'%s' is neither a username nor a numeric uid.\n", optarg);
goto LABEL_30;
}
}
break;
default:
goto LABEL_30;
}
}
if ( argc - optind > 0 )
goto LABEL_30;
v10 = open(v3, 2);
if ( v10 < 0 )
{
fprintf(stderr, "Failed to open '%s' : ", v3);
perror(&src);
exit(1);
}
LOBYTE(v11) = v15;
v19 = 0LL;
HIBYTE(v11) = HIBYTE(v15) | 0x10;
*(_OWORD *)dest = 0LL;
v20 = 0LL;
LOWORD(v19) = v11;
strncpy(dest, v6, 0xFuLL);
if ( ioctl(v10, 0x400454CAuLL, dest) < 0 )
{
perror("TUNSETIFF");
exit(1);
}
if ( v13 )
{
if ( ioctl(v10, 0x400454CBuLL, 0LL) < 0 )
{
perror("disabling TUNSETPERSIST");
exit(1);
}
printf("Set '%s' nonpersistent\n", dest);
}
else
{
if ( (v4 & v5) == -1 )
v5 = geteuid();
if ( v5 != -1 && ioctl(v10, 0x400454CCuLL, v5) < 0 )
{
perror("TUNSETOWNER");
exit(1);
}
if ( v4 != -1 && ioctl(v10, 0x400454CEuLL, v4) < 0 )
{
perror("TUNSETGROUP");
exit(1);
}
if ( ioctl(v10, 0x400454CBuLL, 1LL) < 0 )
{
perror("enabling TUNSETPERSIST");
exit(1);
}
if ( v14 )
{
puts(dest);
}
else
{
printf("Set '%s' persistent and owned by", dest);
if ( v5 != -1 )
printf(" uid %d", v5);
if ( v4 != -1 )
printf(" gid %d", v4);
putchar(10);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
unsigned int v4; // er14
unsigned int v5; // er13
char *v6; // r12
int v7; // eax
struct passwd *v8; // rax
struct group *v9; // rax
int v10; // ebp
__int16 v11; // ax
int v13; // [rsp+Ch] [rbp-8Ch]
int v14; // [rsp+10h] [rbp-88h]
__int16 v15; // [rsp+14h] [rbp-84h]
const char *v16; // [rsp+18h] [rbp-80h]
char *endptr; // [rsp+28h] [rbp-70h] BYREF
char dest[16]; // [rsp+30h] [rbp-68h] BYREF
__int128 v19; // [rsp+40h] [rbp-58h]
__int64 v20; // [rsp+50h] [rbp-48h]

v3 = "/dev/net/tun";
v4 = -1;
v5 = -1;
v6 = (char *)&src;
v15 = 2;
v16 = *argv;
v14 = 0;
v13 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "bd:f:t:u:g:U");
if ( v7 <= 0 )
break;
switch ( v7 )
{
case 'U':
v15 = 1;
continue;
case 'b':
v14 = 1;
continue;
case 'd':
v13 = 1;
v6 = optarg;
continue;
case 'f':
v3 = optarg;
continue;
case 'g':
v9 = getgrnam(optarg);
if ( v9 )
{
v4 = v9->gr_gid;
}
else
{
v4 = strtol(optarg, &endptr, 0);
if ( *endptr )
{
fprintf(stderr, "'%s' is neither a groupname nor a numeric group.\n", optarg);
LABEL_30:
func0(v16);
}
}
break;
case 't':
v6 = optarg;
continue;
case 'u':
v8 = getpwnam(optarg);
if ( v8 )
{
v5 = v8->pw_uid;
}
else
{
v5 = strtol(optarg, &endptr, 0);
if ( *endptr )
{
fprintf(stderr, "'%s' is neither a username nor a numeric uid.\n", optarg);
goto LABEL_30;
}
}
break;
default:
goto LABEL_30;
}
}
if ( argc - optind > 0 )
goto LABEL_30;
v10 = open(v3, 2);
if ( v10 < 0 )
{
fprintf(stderr, "Failed to open '%s' : ", v3);
perror(&src);
exit(1);
}
LOBYTE(v11) = v15;
v19 = 0LL;
HIBYTE(v11) = HIBYTE(v15) | 0x10;
*(_OWORD *)dest = 0LL;
v20 = 0LL;
LOWORD(v19) = v11;
strncpy(dest, v6, 0xFuLL);
if ( ioctl(v10, 0x400454CAuLL, dest) < 0 )
{
perror("TUNSETIFF");
exit(1);
}
if ( v13 )
{
if ( ioctl(v10, 0x400454CBuLL, 0LL) < 0 )
{
perror("disabling TUNSETPERSIST");
exit(1);
}
printf("Set '%s' nonpersistent\n", dest);
}
else
{
if ( (v4 & v5) == -1 )
v5 = geteuid();
if ( v5 != -1 && ioctl(v10, 0x400454CCuLL, v5) < 0 )
{
perror("TUNSETOWNER");
exit(1);
}
if ( v4 != -1 && ioctl(v10, 0x400454CEuLL, v4) < 0 )
{
perror("TUNSETGROUP");
exit(1);
}
if ( ioctl(v10, 0x400454CBuLL, 1LL) < 0 )
{
perror("enabling TUNSETPERSIST");
exit(1);
}
if ( v14 )
{
puts(dest);
}
else
{
printf("Set '%s' persistent and owned by", dest);
if ( v5 != -1 )
printf(" uid %d", v5);
if ( v4 != -1 )
printf(" gid %d", v4);
putchar(10);
}
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
  struct ifreq ifr;
  struct passwd *pw;
  struct group *gr;
  uid_t owner = -1;
  gid_t group = -1;
  int tap_fd, opt, delete = 0, brief = 0;
  char *tun = "", *file = "/dev/net/tun", *name = argv[0], *end;
  unsigned int iff_type = 0x0002;
  while((opt = getopt(argc, argv, "bd:f:t:u:g:U")) > 0){
    switch(opt) {
      case 'b':
        brief = 1;
        break;
      case 'd':
        delete = 1;
 tun = optarg;
        break;
      case 'f':
 file = optarg;
 break;
      case 'u':
 pw = getpwnam(optarg);
 if(pw != ((void *)0)){
   owner = pw->pw_uid;
   break;
 }
        owner = strtol(optarg, &end, 0);
 if(*end != '\0'){
   fprintf(stderr, "'%s' is neither a username nor a numeric uid.\n",
    optarg);
   Usage(name);
 }
        break;
      case 'g':
 gr = getgrnam(optarg);
 if(gr != ((void *)0)){
   group = gr->gr_gid;
   break;
 }
        group = strtol(optarg, &end, 0);
 if(*end != '\0'){
   fprintf(stderr, "'%s' is neither a groupname nor a numeric group.\n",
    optarg);
   Usage(name);
 }
        break;
      case 't':
        tun = optarg;
        break;
      case 'U':
        iff_type = 0x0001;
        break;
      case 'h':
      default:
        Usage(name);
    }
  }
  argv += optind;
  argc -= optind;
  if(argc > 0)
    Usage(name);
  if((tap_fd = open(file, 02)) < 0){
    fprintf(stderr, "Failed to open '%s' : ", file);
    perror("");
    exit(1);
  }
  memset(&ifr, 0, sizeof(ifr));
  ifr.ifr_ifru.ifru_flags = iff_type | 0x1000;
  strncpy(ifr.ifr_ifrn.ifrn_name, tun, sizeof(ifr.ifr_ifrn.ifrn_name) - 1);
  if(ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), (void *) &ifr) < 0){
    perror("TUNSETIFF");
    exit(1);
  }
  if(delete){
    if(ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((203)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), 0) < 0){
      perror("disabling TUNSETPERSIST");
      exit(1);
    }
    printf("Set '%s' nonpersistent\n", ifr.ifr_ifrn.ifrn_name);
  }
  else {
    if(owner == -1 && group == -1) {
      owner = geteuid();
    }
    if(owner != -1) {
      if(ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((204)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), owner) < 0){
       perror("TUNSETOWNER");
       exit(1);
      }
    }
    if(group != -1) {
      if(ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((206)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), group) < 0){
       perror("TUNSETGROUP");
       exit(1);
      }
    }
    if(ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((203)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), 1) < 0){
      perror("enabling TUNSETPERSIST");
      exit(1);
    }
    if(brief)
      printf("%s\n", ifr.ifr_ifrn.ifrn_name);
    else {
      printf("Set '%s' persistent and owned by", ifr.ifr_ifrn.ifrn_name);
      if(owner != -1)
          printf(" uid %d", owner);
      if(group != -1)
          printf(" gid %d", group);
      printf("\n");
    }
  }
  return(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  struct ifreq ifr;
  struct passwd *pw;
  struct group *gr;
  unsigned int owner = -1;
  unsigned int group = -1;
  int tap_fd; int opt; int delete = 0; int brief = 0;
  char *tun = ""; char *file = "/dev/net/tun"; char *name = argv[0]; char *end;
  unsigned int iff_type = 0x0002;
  while((opt = getopt(argc, argv, "bd:f:t:u:g:U")) > 0){
    switch(opt) {
      case 'b':
        brief = 1;
        break;
      case 'd':
        delete = 1;
 tun = optarg;
        break;
      case 'f':
 file = optarg;
 break;
      case 'u':
 pw = getpwnam(optarg);
 if(pw != ((void *)0)){
   owner = pw->pw_uid;
   break;
 }
        owner = strtol(optarg, &end, 0);
 if(*end != '\0'){
   fprintf(stderr, "'%s' is neither a username nor a numeric uid.\n",
    optarg);
   Usage(name);
 }
        break;
      case 'g':
 gr = getgrnam(optarg);
 if(gr != ((void *)0)){
   group = gr->gr_gid;
   break;
 }
        group = strtol(optarg, &end, 0);
 if(*end != '\0'){
   fprintf(stderr, "'%s' is neither a groupname nor a numeric group.\n",
    optarg);
   Usage(name);
 }
        break;
      case 't':
        tun = optarg;
        break;
      case 'U':
        iff_type = 0x0001;
        break;
      case 'h':
      default:
        Usage(name);
    }
  }
  argv += optind;
  argc -= optind;
  if(argc > 0)
    Usage(name);
  if((tap_fd = open(file, 02)) < 0){
    fprintf(stderr, "Failed to open '%s' : ", file);
    perror("");
    exit(1);
  }
  memset(&ifr, 0, sizeof(ifr));
  ifr.ifr_ifru.ifru_flags = iff_type | 0x1000;
  strncpy(ifr.ifr_ifrn.ifrn_name, tun, sizeof(ifr.ifr_ifrn.ifrn_name) - 1);
  if(ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), (void *) &ifr) < 0){
    perror("TUNSETIFF");
    exit(1);
  }
  if(delete){
    if(ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((203)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), 0) < 0){
      perror("disabling TUNSETPERSIST");
      exit(1);
    }
    printf("Set '%s' nonpersistent\n", ifr.ifr_ifrn.ifrn_name);
  }
  else {
    if(owner == -1 && group == -1) {
      owner = geteuid();
    }
    if(owner != -1) {
      if(ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((204)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), owner) < 0){
       perror("TUNSETOWNER");
       exit(1);
      }
    }
    if(group != -1) {
      if(ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((206)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), group) < 0){
       perror("TUNSETGROUP");
       exit(1);
      }
    }
    if(ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((203)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), 1) < 0){
      perror("enabling TUNSETPERSIST");
      exit(1);
    }
    if(brief)
      printf("%s\n", ifr.ifr_ifrn.ifrn_name);
    else {
      printf("Set '%s' persistent and owned by", ifr.ifr_ifrn.ifrn_name);
      if(owner != -1)
          printf(" uid %d", owner);
      if(group != -1)
          printf(" gid %d", group);
      printf("\n");
    }
  }
  return(0);
}

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *

variable_types:
owner
unsigned int

variable_types:
group
unsigned int

variable_types: delete int

variable_types: brief int

variable_types:
tun
char *

variable_types:
file
char *

variable_types:
end
char *

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


repo: ossguy/libbitconvert

decompiled_code:
// attributes: thunk
int print_error(const char *s)
{
return puts(s);
}

canonical_decompiled_code:
int func0(const char *s)
{
return puts(s);
}

original_code:
void print_error(const char* error)
{
 printf("%s\n", error);
}

canonical_original_code:
void print_error(char *error)
{
 printf("%s\n", error);
}

variable_types:
error
char *

return_type: void


decompiled_code:
const char *__fastcall encoding_to_str(int a1)
{
__int64 v1; // rdi
const char *result; // rax

v1 = (unsigned int)(a1 + 1);
result = "unknown";
if ( (unsigned int)v1 <= 8 )
result = CSWTCH_3[v1];
return result;
}

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

v1 = (unsigned int)(a1 + 1);
result = "unknown";
if ( (unsigned int)v1 <= 8 )
result = CSWTCH_3[v1];
return result;
}

original_code:
char* encoding_to_str(int track)
{
 switch (track) {
 case -1: return "none";
 case 1: return "binary";
 case 4: return "BCD";
 case 6: return "ALPHA";
 case 7: return "ASCII";
 default: return "unknown";
 }
}

canonical_original_code:
char *encoding_to_str(int track)
{
 switch (track) {
 case -1: return "none";
 case 1: return "binary";
 case 4: return "BCD";
 case 6: return "ALPHA";
 case 7: return "ASCII";
 default: return "unknown";
 }
}

variable_types: track int

return_type: char *


crondatefree

repo: osvaldsson/xymon

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

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

original_code:
void crondatefree(void *vcdate)
{
 c_bits_t *cdate = (c_bits_t *)vcdate;
 free(cdate);
}

canonical_original_code:
void crondatefree(void *vcdate)
{
 struct c_bits_t *cdate = (c_bits_t *)vcdate;
 free(cdate);
}

variable_types:
vcdate
void *

variable_types: struct c_bits_t { unsigned char minute[-1]; unsigned char hour[-1]; unsigned char dom[-1]; unsigned char month[-1]; unsigned char dow[-1]; int flags; } *


crongettime

decompiled_code:
__int64 crongettime()
{
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = time(0LL);
localtime_r(&timer, &tp);
minute = tp.tm_min;
hour = tp.tm_hour;
dom = tp.tm_mday - 1;
month = tp.tm_mon;
result = (unsigned int)tp.tm_wday;
dow = tp.tm_wday;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = time(0LL);
localtime_r(&timer, &tp);
minute = tp.tm_min;
hour = tp.tm_hour;
dom = tp.tm_mday - 1;
month = tp.tm_mon;
result = (unsigned int)tp.tm_wday;
dow = tp.tm_wday;
return result;
}

original_code:
void crongettime(void)
{
 time_t now;
 struct tm tt;
 now = time(((void *)0));
 localtime_r(&now, &tt);
 minute = tt.tm_min -0;
 hour = tt.tm_hour -0;
 dom = tt.tm_mday -1;
 month = tt.tm_mon +1 -1;
 dow = tt.tm_wday -0;
}

canonical_original_code:
void crongettime()
{
 long now;
 struct tm tt;
 now = time(((void *)0));
 localtime_r(&now, &tt);
 minute = tt.tm_min -0;
 hour = tt.tm_hour -0;
 dom = tt.tm_mday -1;
 month = tt.tm_mon +1 -1;
 dow = tt.tm_wday -0;
}

variable_types: now long

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


cronmatch

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

if ( minute == -1 )
crongettime();
result = 0LL;
if ( a1 )
{
result = ((int)*(unsigned __int8 *)(a1 + (minute >> 3)) >> (minute & 7)) & 1;
if ( (((int)*(unsigned __int8 *)(a1 + (minute >> 3)) >> (minute & 7)) & 1) != 0 )
{
result = ((int)*(unsigned __int8 *)(a1 + (hour >> 3) + 8) >> (hour & 7)) & 1;
if ( (((int)*(unsigned __int8 *)(a1 + (hour >> 3) + 8) >> (hour & 7)) & 1) != 0 )
{
result = ((int)*(unsigned __int8 *)(a1 + (month >> 3) + 15) >> (month & 7)) & 1;
if ( (((int)*(unsigned __int8 *)(a1 + (month >> 3) + 15) >> (month & 7)) & 1) != 0 )
{
result = ((int)*(unsigned __int8 *)(a1 + (dow >> 3) + 17) >> (dow & 7)) & 1;
if ( (*(_BYTE *)(a1 + 20) & 3) != 0 )
{
if ( !(_DWORD)result )
return result;
}
else if ( (_DWORD)result )
{
return result;
}
result = ((int)*(unsigned __int8 *)(a1 + (dom >> 3) + 11) >> (dom & 7)) & 1;
}
}
}
}
return result;
}

return_type: int

user_defined_types: struct c_bits_t { unsigned char minute[-1]; unsigned char hour[-1]; unsigned char dom[-1]; unsigned char month[-1]; unsigned char dow[-1]; int flags; }


decompiled_code:
__int64 __fastcall call_svc(void *buf)
{
char *v1; // rbp
int v2; // ebx
signed int v3; // eax
unsigned int v4; // er14
int v5; // edi
int v6; // eax
int *v8; // rax
char *v9; // rax
struct timeval v10; // [rsp+0h] [rbp-B8h] BYREF
fd_set writefds; // [rsp+10h] [rbp-A8h] BYREF

v1 = (char *)buf;
v2 = strlen((const char *)buf) + 1;
do
{
memset(&writefds, 0, sizeof(writefds));
v5 = ctlsocket;
v10.tv_sec = 5LL;
v10.tv_usec = 0LL;
writefds.fds_bits[ctlsocket / 64] |= 1LL << (ctlsocket % 64);
v6 = select(v5 + 1, 0LL, &writefds, 0LL, &v10);
v4 = v6;
if ( !v6 )
{
v4 = -1;
puts("Send failed: Timeout");
return v4;
}
if ( v6 == -1 || (v3 = send(ctlsocket, v1, v2, 0), v4 = v3, v3 == -1) )
{
v8 = _errno_location();
v9 = strerror(*v8);
printf("Send failed: %s\n", v9);
return v4;
}
v2 -= v3;
v1 += v3;
}
while ( v2 > 0 );
v4 = 0;
puts("Request sent");
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *buf)
{
char *v1; // rbp
int v2; // ebx
signed int v3; // eax
unsigned int v4; // er14
int v5; // edi
int v6; // eax
int *v8; // rax
char *v9; // rax
struct timeval v10; // [rsp+0h] [rbp-B8h] BYREF
fd_set writefds; // [rsp+10h] [rbp-A8h] BYREF

v1 = (char *)buf;
v2 = strlen((const char *)buf) + 1;
do
{
memset(&writefds, 0, sizeof(writefds));
v5 = ctlsocket;
v10.tv_sec = 5LL;
v10.tv_usec = 0LL;
writefds.fds_bits[ctlsocket / 64] |= 1LL << (ctlsocket % 64);
v6 = select(v5 + 1, 0LL, &writefds, 0LL, &v10);
v4 = v6;
if ( !v6 )
{
v4 = -1;
puts("Send failed: Timeout");
return v4;
}
if ( v6 == -1 || (v3 = send(ctlsocket, v1, v2, 0), v4 = v3, v3 == -1) )
{
v8 = _errno_location();
v9 = strerror(*v8);
printf("Send failed: %s\n", v9);
return v4;
}
v2 -= v3;
v1 += v3;
}
while ( v2 > 0 );
v4 = 0;
puts("Request sent");
return v4;
}

original_code:
static int call_svc(char *buf)
{
 int n, bytesleft;
 fd_set fds;
 struct timeval tmo;
 char *bufp;
 bufp = buf;
 bytesleft = strlen(buf)+1;
 do {
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&fds)->__fds_bits)[((ctlsocket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ctlsocket) % (8 * (int) sizeof (__fd_mask)))))));
  tmo.tv_sec = 5;
  tmo.tv_usec = 0;
  n = select(ctlsocket+1, ((void *)0), &fds, ((void *)0), &tmo);
  if (n == 0) {
   printf("Send failed: Timeout\n");
   return -1;
  }
  else if (n == -1) {
   printf("Send failed: %s\n", strerror((*__errno_location ())));
   return -1;
  }
  n = send(ctlsocket, bufp, bytesleft, 0);
  if (n == -1) {
   printf("Send failed: %s\n", strerror((*__errno_location ())));
   return -1;
  }
  else {
   bytesleft -= n;
   bufp += n;
  }
 } while (bytesleft > 0);
 printf("Request sent\n");
 return 0;
}

canonical_original_code:
static int call_svc(char *buf)
{
 int n; int bytesleft;
 struct fd_set fds;
 struct timeval tmo;
 char *bufp;
 bufp = buf;
 bytesleft = strlen(buf)+1;
 do {
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&fds)->__fds_bits)[((ctlsocket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ctlsocket) % (8 * (int) sizeof (__fd_mask)))))));
  tmo.tv_sec = 5;
  tmo.tv_usec = 0;
  n = select(ctlsocket+1, ((void *)0), &fds, ((void *)0), &tmo);
  if (n == 0) {
   printf("Send failed: Timeout\n");
   return -1;
  }
  else if (n == -1) {
   printf("Send failed: %s\n", strerror((*__errno_location ())));
   return -1;
  }
  n = send(ctlsocket, bufp, bytesleft, 0);
  if (n == -1) {
   printf("Send failed: %s\n", strerror((*__errno_location ())));
   return -1;
  }
  else {
   bytesleft -= n;
   bufp += n;
  }
 } while (bytesleft > 0);
 printf("Request sent\n");
 return 0;
}

variable_types:
buf
char *

variable_types: n int

variable_types: bytesleft int

variable_types:
fds
struct fd_set { long __fds_bits[-1]; }

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

variable_types:
bufp
char *


decompiled_code:
__int64 __fastcall init_svc(const char *a1)
{
char *v1; // rax
unsigned int v2; // er12
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

ctlsocket = socket(1, 2, 0);
if ( ctlsocket == -1 )
{
v2 = -1;
v4 = _errno_location();
v5 = strerror(*v4);
printf("Cannot get socket: %s\n", v5);
}
else
{
memset(&myaddr, 0, 0x68uLL);
myaddr.sa_family = 1;
*((_DWORD *)&myaddr + 26) = 0;
word_2AC = 0;
v1 = getenv("XYMONTMP");
sprintf(myaddr.sa_data, "%s/%s", v1, a1);
v2 = connect(ctlsocket, &myaddr, 0x6Eu);
if ( v2 == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
printf("Cannot set target address: %s (%s)\n", a1, v7);
close(ctlsocket);
ctlsocket = -1;
}
else
{
v2 = 0;
fcntl(ctlsocket, 4, 2048LL);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
char *v1; // rax
unsigned int v2; // er12
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

ctlsocket = socket(1, 2, 0);
if ( ctlsocket == -1 )
{
v2 = -1;
v4 = _errno_location();
v5 = strerror(*v4);
printf("Cannot get socket: %s\n", v5);
}
else
{
memset(&myaddr, 0, 0x68uLL);
myaddr.sa_family = 1;
*((_DWORD *)&myaddr + 26) = 0;
word_2AC = 0;
v1 = getenv("XYMONTMP");
sprintf(myaddr.sa_data, "%s/%s", v1, a1);
v2 = connect(ctlsocket, &myaddr, 0x6Eu);
if ( v2 == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
printf("Cannot set target address: %s (%s)\n", a1, v7);
close(ctlsocket);
ctlsocket = -1;
}
else
{
v2 = 0;
fcntl(ctlsocket, 4, 2048LL);
}
}
return v2;
}

original_code:
int init_svc(char *sockfn)
{
 ctlsocket = socket(1, SOCK_DGRAM, 0);
 if (ctlsocket == -1) {
  printf("Cannot get socket: %s\n", strerror((*__errno_location ())));
  return -1;
 }
 memset(&myaddr, 0, sizeof(myaddr));
 myaddr.sun_family = 1;
 sprintf(myaddr.sun_path, "%s/%s", getenv("XYMONTMP"), sockfn);
 myaddrsz = sizeof(myaddr);
 if (connect(ctlsocket, (struct sockaddr *)&myaddr, myaddrsz) == -1) {
  printf("Cannot set target address: %s (%s)\n", sockfn, strerror((*__errno_location ())));
  close(ctlsocket);
  ctlsocket = -1;
  return -1;
 }
 fcntl(ctlsocket, 4, 04000);
 return 0;
}

variable_types:
sockfn
char *

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
char v4[1032]; // [rsp+0h] [rbp-408h] BYREF

if ( argc <= 1 )
{
printf("Usage: %s SOCKETFILE\n", *argv);
result = 1;
}
else if ( (unsigned int)init_svc(argv[1]) == -1 )
{
puts("Cannot get socket");
result = 1;
}
else
{
puts("Enter the hostname whose RRD cache should be flushed. One host per line");
while ( fgets(v4, 1024, stdin) && !(unsigned int)call_svc(v4) )
;
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
char v4[1032]; // [rsp+0h] [rbp-408h] BYREF

if ( argc <= 1 )
{
printf("Usage: %s SOCKETFILE\n", *argv);
result = 1;
}
else if ( (unsigned int)func1(argv[1]) == -1 )
{
puts("Cannot get socket");
result = 1;
}
else
{
puts("Enter the hostname whose RRD cache should be flushed. One host per line");
while ( fgets(v4, 1024, stdin) && !(unsigned int)func0(v4) )
;
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 char buf[1024];
 int done = 0;
 if (argc < 2) {
  printf("Usage: %s SOCKETFILE\n", argv[0]);
  return 1;
 }
 if (init_svc(argv[1]) == -1) {
  printf("Cannot get socket\n");
  return 1;
 }
 printf("Enter the hostname whose RRD cache should be flushed. One host per line\n");
 while (!done) {
  done = (fgets(buf, sizeof(buf), stdin) == ((void *)0)); if (done) continue;
  done = (call_svc(buf) != 0);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
buf
char [1024]

variable_types: done int


binsearch

original_code:
static xtreePos_t binsearch(xtree_t *mytree, char *key)
{
 xtreePos_t uplim, lowlim, n;
 lowlim = 0; uplim = mytree->treesz-1;
 do {
  xtreePos_t res;
  n = (uplim + lowlim) / 2;
  res = mytree->compare(key, mytree->entries[n].key);
  if (res == 0) {
   uplim = -1;
  }
  else if (res > 0) {
   lowlim = n+1;
  }
  else {
   uplim = n-1;
  }
 } while ((uplim >= 0) && (lowlim <= uplim));
 return n;
}

canonical_original_code:
static int binsearch(struct xtree_t *mytree, char *key)
{
 int uplim; int lowlim; int n;
 lowlim = 0; uplim = mytree->treesz-1;
 do {
  int res;
  n = (uplim + lowlim) / 2;
  res = mytree->compare(key, mytree->entries[n].key);
  if (res == 0) {
   uplim = -1;
  }
  else if (res > 0) {
   lowlim = n+1;
  }
  else {
   uplim = n-1;
  }
 } while ((uplim >= 0) && (lowlim <= uplim));
 return n;
}

variable_types: struct xtree_t { struct treerec_t { char *key; void *userdata; int deleted; } *entries; int treesz; int (*compare)(char *a, char *b); } *

variable_types:
key
char *

variable_types: uplim int

variable_types: lowlim int

variable_types: res int

user_defined_types: struct xtree_t { struct treerec_t *entries; int treesz; int (*compare)(char *a, char *b); }


xtreeDestroy

decompiled_code:
void __fastcall xtreeDestroy(void *ptr)
{
int v2; // ecx
char *v3; // rdi
__int64 v4; // rbx
char *v5; // rax

if ( ptr )
{
v2 = *((_DWORD *)ptr + 2);
v3 = *(char **)ptr;
if ( v2 > 0 )
{
v4 = 0LL;
do
{
while ( 1 )
{
v5 = &v3[24 * v4];
if ( *((_DWORD *)v5 + 4) )
break;
if ( *((_DWORD *)ptr + 2) <= (int)++v4 )
goto LABEL_7;
}
++v4;
free(*(void **)v5);
v3 = *(char **)ptr;
}
while ( *((_DWORD *)ptr + 2) > (int)v4 );
}
LABEL_7:
free(v3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
int v2; // ecx
char *v3; // rdi
__int64 v4; // rbx
char *v5; // rax

if ( ptr )
{
v2 = *((_DWORD *)ptr + 2);
v3 = *(char **)ptr;
if ( v2 > 0 )
{
v4 = 0LL;
do
{
while ( 1 )
{
v5 = &v3[24 * v4];
if ( *((_DWORD *)v5 + 4) )
break;
if ( *((_DWORD *)ptr + 2) <= (int)++v4 )
goto LABEL_7;
}
++v4;
free(*(void **)v5);
v3 = *(char **)ptr;
}
while ( *((_DWORD *)ptr + 2) > (int)v4 );
}
LABEL_7:
free(v3);
free(ptr);
}
}

original_code:
void xtreeDestroy(void *treehandle)
{
 xtree_t *mytree = (xtree_t *)treehandle;
 xtreePos_t i;
 if (treehandle == ((void *)0)) return;
 for (i = 0; (i < mytree->treesz); i++) {
  if (mytree->entries[i].deleted) free(mytree->entries[i].key);
 }
 free(mytree->entries);
 free(mytree);
}

canonical_original_code:
void xtreeDestroy(void *treehandle)
{
 struct xtree_t *mytree = (xtree_t *)treehandle;
 int i;
 if (treehandle == ((void *)0)) return;
 for (i = 0; (i < mytree->treesz); i++) {
  if (mytree->entries[i].deleted) free(mytree->entries[i].key);
 }
 free(mytree->entries);
 free(mytree);
}

variable_types:
treehandle
void *

variable_types: i int

user_defined_types: struct treerec_t { char *key; void *userdata; int deleted; }


xtreeFind

decompiled_code:
__int64 __fastcall xtreeFind(__int64 a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // er12
__int64 v4; // rax
__int64 result; // rax

if ( !a1
|| !*(_DWORD *)(a1 + 8)
|| (v2 = binsearch(a1, a2), v3 = v2, v2 < 0)
|| *(_DWORD *)(a1 + 8) <= v2
|| (v4 = *(_QWORD *)a1 + 24LL * v2, *(_DWORD *)(v4 + 16))
|| (*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 16))(a2, *(_QWORD *)v4) )
{
result = 0xFFFFFFFFLL;
}
else
{
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // er12
__int64 v4; // rax
__int64 result; // rax

if ( !a1
|| !*(_DWORD *)(a1 + 8)
|| (v2 = func0(a1, a2), v3 = v2, v2 < 0)
|| *(_DWORD *)(a1 + 8) <= v2
|| (v4 = *(_QWORD *)a1 + 24LL * v2, *(_DWORD *)(v4 + 16))
|| (*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 16))(a2, *(_QWORD *)v4) )
{
result = 0xFFFFFFFFLL;
}
else
{
result = v3;
}
return result;
}

original_code:
xtreePos_t xtreeFind(void *treehandle, char *key)
{
 xtree_t *mytree = (xtree_t *)treehandle;
 xtreePos_t n;
 if ((treehandle == ((void *)0)) || (mytree->treesz == 0)) return -1;
 n = binsearch(mytree, key);
 if ((n >= 0) && (n < mytree->treesz) && (mytree->entries[n].deleted == 0) && (mytree->compare(key, mytree->entries[n].key) == 0))
  return n;
 return -1;
}

canonical_original_code:
int xtreeFind(void *treehandle, char *key)
{
 struct xtree_t *mytree = (xtree_t *)treehandle;
 int n;
 if ((treehandle == ((void *)0)) || (mytree->treesz == 0)) return -1;
 n = binsearch(mytree, key);
 if ((n >= 0) && (n < mytree->treesz) && (mytree->entries[n].deleted == 0) && (mytree->compare(key, mytree->entries[n].key) == 0))
  return n;
 return -1;
}

variable_types: n int


xtreeFirst

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

if ( a1 )
result = (unsigned int)-(*(_DWORD *)(a1 + 8) == 0);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = (unsigned int)-(*(_DWORD *)(a1 + 8) == 0);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
xtreePos_t xtreeFirst(void *treehandle)
{
 xtree_t *mytree = (xtree_t *)treehandle;
 if ((treehandle == ((void *)0)) || (mytree->treesz == 0)) return -1;
 return 0;
}

canonical_original_code:
int xtreeFirst(void *treehandle)
{
 struct xtree_t *mytree = (xtree_t *)treehandle;
 if ((treehandle == ((void *)0)) || (mytree->treesz == 0)) return -1;
 return 0;
}


xtreeNext

decompiled_code:
__int64 __fastcall xtreeNext(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // esi
__int64 v4; // rdx
int v5; // ecx

LODWORD(result) = a2;
if ( !a1 )
return 0xFFFFFFFFLL;
v3 = *(_DWORD *)(a1 + 8);
if ( !v3 || v3 - 1 <= (int)result || (int)result < 0 )
return 0xFFFFFFFFLL;
v4 = 24LL * ((int)result + 1);
do
{
result = (unsigned int)(result + 1);
if ( v3 <= (int)result )
break;
v5 = *(_DWORD *)(*(_QWORD *)a1 + v4 + 16);
v4 += 24LL;
}
while ( v5 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // esi
__int64 v4; // rdx
int v5; // ecx

LODWORD(result) = a2;
if ( !a1 )
return 0xFFFFFFFFLL;
v3 = *(_DWORD *)(a1 + 8);
if ( !v3 || v3 - 1 <= (int)result || (int)result < 0 )
return 0xFFFFFFFFLL;
v4 = 24LL * ((int)result + 1);
do
{
result = (unsigned int)(result + 1);
if ( v3 <= (int)result )
break;
v5 = *(_DWORD *)(*(_QWORD *)a1 + v4 + 16);
v4 += 24LL;
}
while ( v5 );
return result;
}

original_code:
xtreePos_t xtreeNext(void *treehandle, xtreePos_t pos)
{
 xtree_t *mytree = (xtree_t *)treehandle;
 if ((treehandle == ((void *)0)) || (mytree->treesz == 0) || (pos >= (mytree->treesz - 1)) || (pos < 0)) return -1;
 do {
  pos++;
 } while ((pos < mytree->treesz) && (mytree->entries[pos].deleted != 0));
 return pos;
}

canonical_original_code:
int xtreeNext(void *treehandle, int pos)
{
 struct xtree_t *mytree = (xtree_t *)treehandle;
 if ((treehandle == ((void *)0)) || (mytree->treesz == 0) || (pos >= (mytree->treesz - 1)) || (pos < 0)) return -1;
 do {
  pos++;
 } while ((pos < mytree->treesz) && (mytree->entries[pos].deleted != 0));
 return pos;
}

variable_types: pos int


xtreeKey

decompiled_code:
__int64 __fastcall xtreeKey(__int64 a1, int a2)
{
__int64 result; // rax

if ( !a1 || *(_DWORD *)(a1 + 8) <= a2 || *(_DWORD *)(a1 + 8) == 0 || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 24LL * a2);
return result;
}

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

if ( !a1 || *(_DWORD *)(a1 + 8) <= a2 || *(_DWORD *)(a1 + 8) == 0 || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 24LL * a2);
return result;
}

original_code:
char *xtreeKey(void *treehandle, xtreePos_t pos)
{
 xtree_t *mytree = (xtree_t *)treehandle;
 if ((treehandle == ((void *)0)) || (mytree->treesz == 0) || (pos >= mytree->treesz) || (pos < 0)) return ((void *)0);
 return mytree->entries[pos].key;
}

canonical_original_code:
char *xtreeKey(void *treehandle, int pos)
{
 struct xtree_t *mytree = (xtree_t *)treehandle;
 if ((treehandle == ((void *)0)) || (mytree->treesz == 0) || (pos >= mytree->treesz) || (pos < 0)) return ((void *)0);
 return mytree->entries[pos].key;
}


xtreeData

decompiled_code:
__int64 __fastcall xtreeData(__int64 a1, int a2)
{
__int64 result; // rax

if ( !a1 || *(_DWORD *)(a1 + 8) <= a2 || *(_DWORD *)(a1 + 8) == 0 || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 24LL * a2 + 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
__int64 result; // rax

if ( !a1 || *(_DWORD *)(a1 + 8) <= a2 || *(_DWORD *)(a1 + 8) == 0 || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 24LL * a2 + 8);
return result;
}

original_code:
void *xtreeData(void *treehandle, xtreePos_t pos)
{
 xtree_t *mytree = (xtree_t *)treehandle;
 if ((treehandle == ((void *)0)) || (mytree->treesz == 0) || (pos >= mytree->treesz) || (pos < 0)) return ((void *)0);
 return mytree->entries[pos].userdata;
}

canonical_original_code:
void *xtreeData(void *treehandle, int pos)
{
 struct xtree_t *mytree = (xtree_t *)treehandle;
 if ((treehandle == ((void *)0)) || (mytree->treesz == 0) || (pos >= mytree->treesz) || (pos < 0)) return ((void *)0);
 return mytree->entries[pos].userdata;
}

return_type: void *


xtreeAdd

original_code:
xtreeStatus_t xtreeAdd(void *treehandle, char *key, void *userdata)
{
 xtree_t *mytree = (xtree_t *)treehandle;
 xtreePos_t n;
 if (treehandle == ((void *)0)) return XTREE_STATUS_NOTREE;
 if (mytree->treesz == 0) {
  mytree->entries = (treerec_t *)calloc(1, sizeof(treerec_t));
  mytree->entries[0].key = key;
  mytree->entries[0].userdata = userdata;
  mytree->entries[0].deleted = 0;
 }
 else {
  n = binsearch(mytree, key);
  if ((n >= 0) && (n < mytree->treesz) && (mytree->compare(key, mytree->entries[n].key) == 0)) {
   if (mytree->entries[n].deleted != 0) {
    free(mytree->entries[n].key);
    mytree->entries[n].key = key;
    mytree->entries[n].deleted = 0;
    mytree->entries[n].userdata = userdata;
    return XTREE_STATUS_OK;
   }
   else {
    return XTREE_STATUS_DUPLICATE_KEY;
   }
  }
  if (mytree->compare(key, mytree->entries[mytree->treesz - 1].key) > 0) {
   mytree->entries = (treerec_t *)realloc(mytree->entries, (1 + mytree->treesz)*sizeof(treerec_t));
   mytree->entries[mytree->treesz].key = key;
   mytree->entries[mytree->treesz].userdata = userdata;
   mytree->entries[mytree->treesz].deleted = 0;
  }
  else if (mytree->compare(key, mytree->entries[0].key) < 0) {
   treerec_t *newents = (treerec_t *)malloc((1 + mytree->treesz)*sizeof(treerec_t));
   newents[0].key = key;
   newents[0].userdata = userdata;
   newents[0].deleted = 0;
   memcpy(&(newents[1]), &(mytree->entries[0]), (mytree->treesz * sizeof(treerec_t)));
   free(mytree->entries);
   mytree->entries = newents;
  }
  else {
   treerec_t *newents;
   n = binsearch(mytree, key);
   if (mytree->compare(mytree->entries[n].key, key) < 0) n++;
   if (mytree->entries[n].deleted != 0) {
    free(mytree->entries[n].key);
    mytree->entries[n].key = key;
    mytree->entries[n].userdata = userdata;
    mytree->entries[n].deleted = 0;
    return XTREE_STATUS_OK;
   }
   newents = (treerec_t *)malloc((1 + mytree->treesz)*sizeof(treerec_t));
   memcpy(&(newents[0]), &(mytree->entries[0]), n*sizeof(treerec_t));
   newents[n].key = key;
   newents[n].userdata = userdata;
   newents[n].deleted = 0;
   memcpy(&(newents[n+1]), &(mytree->entries[n]), (mytree->treesz - n)*sizeof(treerec_t));
   free(mytree->entries);
   mytree->entries = newents;
  }
 }
 mytree->treesz += 1;
 return XTREE_STATUS_OK;
}

canonical_original_code:
enum xtreeStatus_t xtreeAdd(void *treehandle, char *key, void *userdata)
{
 struct xtree_t *mytree = (xtree_t *)treehandle;
 int n;
 if (treehandle == ((void *)0)) return XTREE_STATUS_NOTREE;
 if (mytree->treesz == 0) {
  mytree->entries = (struct treerec_t *)calloc(1, sizeof(treerec_t));
  mytree->entries[0].key = key;
  mytree->entries[0].userdata = userdata;
  mytree->entries[0].deleted = 0;
 }
 else {
  n = binsearch(mytree, key);
  if ((n >= 0) && (n < mytree->treesz) && (mytree->compare(key, mytree->entries[n].key) == 0)) {
   if (mytree->entries[n].deleted != 0) {
    free(mytree->entries[n].key);
    mytree->entries[n].key = key;
    mytree->entries[n].deleted = 0;
    mytree->entries[n].userdata = userdata;
    return XTREE_STATUS_OK;
   }
   else {
    return XTREE_STATUS_DUPLICATE_KEY;
   }
  }
  if (mytree->compare(key, mytree->entries[mytree->treesz - 1].key) > 0) {
   mytree->entries = (struct treerec_t *)realloc(mytree->entries, (1 + mytree->treesz)*sizeof(treerec_t));
   mytree->entries[mytree->treesz].key = key;
   mytree->entries[mytree->treesz].userdata = userdata;
   mytree->entries[mytree->treesz].deleted = 0;
  }
  else if (mytree->compare(key, mytree->entries[0].key) < 0) {
   struct treerec_t *newents = (treerec_t *)malloc((1 + mytree->treesz)*sizeof(treerec_t));
   newents[0].key = key;
   newents[0].userdata = userdata;
   newents[0].deleted = 0;
   memcpy(&(newents[1]), &(mytree->entries[0]), (mytree->treesz * sizeof(treerec_t)));
   free(mytree->entries);
   mytree->entries = newents;
  }
  else {
   struct treerec_t *newents;
   n = binsearch(mytree, key);
   if (mytree->compare(mytree->entries[n].key, key) < 0) n++;
   if (mytree->entries[n].deleted != 0) {
    free(mytree->entries[n].key);
    mytree->entries[n].key = key;
    mytree->entries[n].userdata = userdata;
    mytree->entries[n].deleted = 0;
    return XTREE_STATUS_OK;
   }
   newents = (struct treerec_t *)malloc((1 + mytree->treesz)*sizeof(treerec_t));
   memcpy(&(newents[0]), &(mytree->entries[0]), n*sizeof(treerec_t));
   newents[n].key = key;
   newents[n].userdata = userdata;
   newents[n].deleted = 0;
   memcpy(&(newents[n+1]), &(mytree->entries[n]), (mytree->treesz - n)*sizeof(treerec_t));
   free(mytree->entries);
   mytree->entries = newents;
  }
 }
 mytree->treesz += 1;
 return XTREE_STATUS_OK;
}

variable_types:
userdata
void *

variable_types: struct treerec_t { char *key; void *userdata; int deleted; } *

return_type: enum xtreeStatus_t { XTREE_STATUS_OK=0, XTREE_STATUS_MEM_EXHAUSTED=1, XTREE_STATUS_DUPLICATE_KEY=2, XTREE_STATUS_KEY_NOT_FOUND=3, XTREE_STATUS_NOTREE=4 }


xtreeDelete

decompiled_code:
__int64 __fastcall xtreeDelete(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // r12
__int64 v4; // rax
__int64 v6; // r12
char *v7; // rax

if ( !a1 )
return 0LL;
if ( !*(_DWORD *)(a1 + 8) )
return 0LL;
v2 = binsearch(a1, a2);
if ( v2 < 0 )
return 0LL;
if ( *(_DWORD *)(a1 + 8) <= v2 )
return 0LL;
v3 = 24LL * v2;
v4 = v3 + *(_QWORD *)a1;
if ( *(_DWORD *)(v4 + 16) || (*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 16))(a2, *(_QWORD *)v4) )
return 0LL;
v6 = *(_QWORD *)a1 + v3;
v7 = strdup(*(const char **)v6);
*(_DWORD *)(v6 + 16) = 1;
*(_QWORD *)v6 = v7;
return *(_QWORD *)(v6 + 8);
}

original_code:
void *xtreeDelete(void *treehandle, char *key)
{
 xtree_t *mytree = (xtree_t *)treehandle;
 xtreePos_t n;
 if (treehandle == ((void *)0)) return ((void *)0);
 if (mytree->treesz == 0) return ((void *)0);
 n = binsearch(mytree, key);
 if ((n >= 0) && (n < mytree->treesz) && (mytree->entries[n].deleted == 0) && (mytree->compare(key, mytree->entries[n].key) == 0)) {
  mytree->entries[n].key = strdup(mytree->entries[n].key);
  mytree->entries[n].deleted = 1;
  return mytree->entries[n].userdata;
 }
 return ((void *)0);
}

canonical_original_code:
void *xtreeDelete(void *treehandle, char *key)
{
 struct xtree_t *mytree = (xtree_t *)treehandle;
 int n;
 if (treehandle == ((void *)0)) return ((void *)0);
 if (mytree->treesz == 0) return ((void *)0);
 n = binsearch(mytree, key);
 if ((n >= 0) && (n < mytree->treesz) && (mytree->entries[n].deleted == 0) && (mytree->compare(key, mytree->entries[n].key) == 0)) {
  mytree->entries[n].key = strdup(mytree->entries[n].key);
  mytree->entries[n].deleted = 1;
  return mytree->entries[n].userdata;
 }
 return ((void *)0);
}


original_code:
static void
md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
{
    const md5_byte_t *p = data;
    int left = nbytes;
    int offset = (pms->count[0] >> 3) & 63;
    md5_word_t nbits = (md5_word_t)(nbytes << 3);
    if (nbytes <= 0)
 return;
    pms->count[1] += nbytes >> 29;
    pms->count[0] += nbits;
    if (pms->count[0] < nbits)
 pms->count[1]++;
    if (offset) {
 int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
 memcpy(pms->buf + offset, p, copy);
 if (offset + copy < 64)
     return;
 p += copy;
 left -= copy;
 md5_process(pms, pms->buf);
    }
    for (; left >= 64; p += 64, left -= 64)
 md5_process(pms, p);
    if (left)
 memcpy(pms->buf, p, left);
}

canonical_original_code:
static void md5_append(struct md5_state_s *pms, unsigned char *data, int nbytes)
{
    unsigned char *p = data;
    int left = nbytes;
    int offset = (pms->count[0] >> 3) & 63;
    unsigned int nbits = (md5_word_t)(nbytes << 3);
    if (nbytes <= 0)
 return;
    pms->count[1] += nbytes >> 29;
    pms->count[0] += nbits;
    if (pms->count[0] < nbits)
 pms->count[1]++;
    if (offset) {
 int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
 memcpy(pms->buf + offset, p, copy);
 if (offset + copy < 64)
     return;
 p += copy;
 left -= copy;
 md5_process(pms, pms->buf);
    }
    for (; left >= 64; p += 64, left -= 64)
 md5_process(pms, p);
    if (left)
 memcpy(pms->buf, p, left);
}

variable_types: struct md5_state_s { unsigned int count[2]; unsigned int abcd[4]; unsigned char buf[64]; } *

variable_types:
data
unsigned char *

variable_types: nbytes int

variable_types:
p
unsigned char *

variable_types: left int

variable_types: offset int

variable_types:
nbits
unsigned int

variable_types: copy int


decompiled_code:
__int64 myMD5_Size()
{
return 88LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 88LL;
}

original_code: int myMD5_Size(void) { return sizeof(md5_state_t); }

canonical_original_code: int myMD5_Size() { return sizeof(md5_state_t); }


decompiled_code:
// attributes: thunk
void __fastcall myMD5_Update(int *a1, char *a2, int a3)
{
md5_append(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func6(int *a1, char *a2, int a3)
{
func2(a1, a2, a3);
}

original_code: void myMD5_Update(void *pms, unsigned char *data, int nbytes) { md5_append((md5_state_t *)pms, (md5_byte_t *)data, nbytes); }

canonical_original_code: void myMD5_Update(void *pms, unsigned char *data, int nbytes) { md5_append((struct md5_state_s *)pms, (unsigned char *)data, nbytes); }

variable_types:
pms
void *

user_defined_types: struct md5_state_s { unsigned int count[2]; unsigned int abcd[4]; unsigned char buf[64]; }


intcompare

repo: othieno/programming-challenges

decompiled_code:
__int64 __fastcall intcompare(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

original_code:
int intcompare(const void* const a, const void* const b)
{
   return *((uint32_t*)a) - *((uint32_t*)b);
}

canonical_original_code:
int intcompare(void *a, void *b)
{
   return *((unsigned int *)a) - *((unsigned int *)b);
}

variable_types:
a
void *

variable_types:
b
void *


minimalSumOfDistances

decompiled_code:
__int64 __fastcall minimalSumOfDistances(_DWORD *a1, unsigned int a2)
{
unsigned int v2; // ecx
unsigned int v3; // er8
_DWORD *i; // r9
unsigned int v5; // eax

v2 = a1[a2 >> 1];
if ( (a2 & 1) == 0 )
v2 = (a1[(a2 >> 1) - 1] + v2) >> 1;
v3 = 0;
for ( i = &a1[a2]; a1 != i; v3 += v5 )
{
v5 = *a1 - v2;
if ( *a1 < v2 )
v5 = v2 - *a1;
++a1;
}
return v3;
}

original_code:
uint32_t minimalSumOfDistances(const uint32_t* const s, const uint32_t n)
{
   const uint32_t i = n >> 1;
   const uint32_t s_i = (n & 1) ? s[i] : ((s[i] + s[i - 1]) >> 1);
   const uint32_t* s_j = s;
   uint32_t distance = 0;
   for (; s_j != s + n; ++s_j)
      distance += s_i > *s_j ? s_i - *s_j : *s_j - s_i;
   return distance;
}

canonical_original_code:
unsigned int minimalSumOfDistances(unsigned int *s, unsigned int n)
{
   unsigned int i = n >> 1;
   unsigned int s_i = (n & 1) ? s[i] : ((s[i] + s[i - 1]) >> 1);
   unsigned int *s_j = s;
   unsigned int distance = 0;
   for (; s_j != s + n; ++s_j)
      distance += s_i > *s_j ? s_i - *s_j : *s_j - s_i;
   return distance;
}

variable_types:
s
unsigned int *

variable_types:
n
unsigned int

variable_types:
i
unsigned int

variable_types:
distance
unsigned int

return_type: unsigned int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
unsigned int v5; // er13
char *v6; // rbp
char *v7; // r12
char *v8; // rbx
unsigned int v9; // eax
int v11; // [rsp+Ch] [rbp-13BCh] BYREF
char base[2000]; // [rsp+10h] [rbp-13B8h] BYREF
char s[3048]; // [rsp+7E0h] [rbp-BE8h] BYREF

v11 = 0;
while ( fscanf(stdin, "%u\n", &v11) != -1 )
{
while ( 1 )
{
v3 = v11--;
if ( !v3 || !fgets(s, 3004, stdin) )
break;
v4 = atoi(s);
v5 = v4;
if ( v4 )
{
v6 = base;
v7 = &base[4 * (v4 - 1) + 4];
v8 = s;
do
{
v6 += 4;
v8 = strchr(v8 + 1, 32);
*((_DWORD *)v6 - 1) = atoi(v8);
}
while ( v6 != v7 );
}
qsort(base, v5, 4uLL, intcompare);
v9 = minimalSumOfDistances(base, v5);
printf("%d\n", v9);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
unsigned int v5; // er13
char *v6; // rbp
char *v7; // r12
char *v8; // rbx
unsigned int v9; // eax
int v11; // [rsp+Ch] [rbp-13BCh] BYREF
char base[2000]; // [rsp+10h] [rbp-13B8h] BYREF
char s[3048]; // [rsp+7E0h] [rbp-BE8h] BYREF

v11 = 0;
while ( fscanf(stdin, "%u\n", &v11) != -1 )
{
while ( 1 )
{
v3 = v11--;
if ( !v3 || !fgets(s, 3004, stdin) )
break;
v4 = atoi(s);
v5 = v4;
if ( v4 )
{
v6 = base;
v7 = &base[4 * (v4 - 1) + 4];
v8 = s;
do
{
v6 += 4;
v8 = strchr(v8 + 1, 32);
*((_DWORD *)v6 - 1) = atoi(v8);
}
while ( v6 != v7 );
}
qsort(base, v5, 4uLL, intcompare);
v9 = func8(base, v5);
printf("%d\n", v9);
}
}
return 0;
}

original_code:
int main(int argc, char** argv)
{
   uint32_t n = 0;
   uint32_t r = 0;
   uint32_t s[500];
   char buffer[3004];
   while (fscanf(stdin, "%u\n", &n) != (-1))
   {
      while (n-- && fgets(buffer, sizeof(buffer), stdin) != ((void *)0))
      {
         uint32_t i = 0;
         const char* token = buffer;
         r = atoi(token);
         for (; i < r; ++i)
         {
            token = strchr(++token, ' ');
            s[i] = atoi(token);
         }
         qsort(s, r, sizeof(s[0]), &intcompare);
         printf("%d\n", minimalSumOfDistances(s, r));
      }
   }
   return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
   unsigned int n = 0;
   unsigned int r = 0;
   unsigned int s[500];
   char buffer[3004];
   while (fscanf(stdin, "%u\n", &n) != (-1))
   {
      while (n-- && fgets(buffer, sizeof(buffer), stdin) != ((void *)0))
      {
         unsigned int i = 0;
         char *token = buffer;
         r = atoi(token);
         for (; i < r; ++i)
         {
            token = strchr(++token, ' ');
            s[i] = atoi(token);
         }
         qsort(s, r, sizeof(s[0]), &intcompare);
         printf("%d\n", minimalSumOfDistances(s, r));
      }
   }
   return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
r
unsigned int

variable_types:
s
unsigned int [500]

variable_types:
buffer
char [3004]

variable_types:
token
char *


usage

repo: ototsuyume/tinyscript

decompiled_code:
int usage()
{
puts("tinyscript usage:");
printf("ts [source file]\n;");
return printf("ts -b [binary file]\n;");
}

canonical_decompiled_code:
int func0()
{
puts("tinyscript usage:");
printf("ts [source file]\n;");
return printf("ts -b [binary file]\n;");
}

original_code:
void usage()
{
 printf("tinyscript usage:\n");
 printf("ts [source file]\n;");
 printf("ts -b [binary file]\n;");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rdi

if ( argc == 2 )
{
v4 = loadfile(argv[1]);
if ( v4 )
runvm(v4);
else
puts("input error.");
}
else
{
usage();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rdi

if ( argc == 2 )
{
v4 = loadfile(argv[1]);
if ( v4 )
runvm(v4);
else
puts("input error.");
}
else
{
func0();
}
return 0;
}

original_code:
int main(int argc,char *argv[])
{
 tsvm *vm;
 if(argc!=2)
 {
  usage();
  return 0;
 }
 vm = loadfile(argv[1]);
 if(vm==((void *)0))
 {
  printf("input error.\n");
  return 0;
 }
 runvm(vm);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct tsvm *vm;
 if(argc!=2)
 {
  usage();
  return 0;
 }
 vm = loadfile(argv[1]);
 if(vm==((void *)0))
 {
  printf("input error.\n");
  return 0;
 }
 runvm(vm);
 return 0;
}

variable_types:
argv
char *[]

variable_types: struct tsvm { struct envir { struct symtable { struct symnode { struct tsstr { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; unsigned int hash; unsigned char *buf; int len; } *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } strt; struct symtable funt; struct tsarray { struct tsgarbage gchead; struct tsval { unsigned char t; int reg; union { struct tstable { struct tsgarbage gchead; struct tnode { struct tsval key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; } *slot; struct tnode *head; int size; int used; } *tab; struct tsstr *str; struct tsarray *a; struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; } *func; double fnum; int inum; }; } *data; int enumptr; int size; int used; } funlist; struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } cstt; struct tsfunc global; } *e; int line; struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; } curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; } *

user_defined_types: struct tsvm { struct envir *e; int line; struct tsframe curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; }

user_defined_types: struct envir { struct symtable strt; struct symtable funt; struct tsarray funlist; struct csttable cstt; struct tsfunc global; }

user_defined_types: struct symtable { struct symnode *slot; struct symnode *head; int size; int used; }

user_defined_types: struct tsarray { struct tsgarbage gchead; struct tsval *data; int enumptr; int size; int used; }

user_defined_types: struct csttable { struct cstnode *slot; struct cstnode *head; int size; int used; }

user_defined_types: struct symnode { struct tsstr *key; int data; struct symnode *next; }

user_defined_types: struct tsval { unsigned char t; int reg; union { struct tstable *tab; struct tsstr *str; struct tsarray *a; struct tsfunc *func; double fnum; int inum; }; }

user_defined_types: struct tsstr { struct tsgarbage gchead; unsigned int hash; unsigned char *buf; int len; }

user_defined_types: struct tstable { struct tsgarbage gchead; struct tnode *slot; struct tnode *head; int size; int used; }


original_code:
int tsmath_abs(tsvm *vm,int pcount)
{
 tsval *pv;
 tsval ret;
 pv = &vm->dstack[vm->dsp-1];
 if(((pv)->t==type_int))
 {
  ret.t = type_int;
  ret.inum = abs((pv)->inum);
 }
 else if(((pv)->t==type_float))
 {
  ret.t = type_float;
  ret.fnum = abs((pv)->fnum);
 }
 else
  return rterr_obj_typeerror;
 {vm->retval = ret;vm->lastret = vm->curf.pc;};
 return 0;
}

canonical_original_code:
int tsmath_abs(struct tsvm *vm, int pcount)
{
 struct tsval *pv;
 struct tsval ret;
 pv = &vm->dstack[vm->dsp-1];
 if(((pv)->t==type_int))
 {
  ret.t = type_int;
  ret.inum = abs((pv)->inum);
 }
 else if(((pv)->t==type_float))
 {
  ret.t = type_float;
  ret.fnum = abs((pv)->fnum);
 }
 else
  return rterr_obj_typeerror;
 {vm->retval = ret;vm->lastret = vm->curf.pc;};
 return 0;
}

variable_types: pcount int

variable_types: struct tsval { unsigned char t; int reg; union { struct tstable { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; struct tnode { struct tsval key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; } *slot; struct tnode *head; int size; int used; } *tab; struct tsstr { struct tsgarbage gchead; unsigned int hash; unsigned char *buf; int len; } *str; struct tsarray { struct tsgarbage gchead; struct tsval *data; int enumptr; int size; int used; } *a; struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir { struct symtable { struct symnode { struct tsstr *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } strt; struct symtable funt; struct tsarray funlist; struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } cstt; struct tsfunc global; } *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm { struct envir *e; int line; struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; } curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; } *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; } *func; double fnum; int inum; }; } *

user_defined_types: struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; }


original_code:
int tsmath_pow(tsvm *vm,int pcount)
{
 tsval *pv1,*pv2;
 tsval ret;
 pv2 = &vm->dstack[vm->dsp-1];
 pv1 = &vm->dstack[vm->dsp-2];
 if(((pv1)->t==type_int||(pv1)->t==type_float)&&((pv2)->t==type_int||(pv2)->t==type_float))
 {
  ret.t = type_float;
  ret.fnum = pow((((pv1)->t==type_int)?(double)(pv1)->inum:(pv1)->fnum),(((pv2)->t==type_int)?(double)(pv2)->inum:(pv2)->fnum));
 }
 else
  return rterr_obj_typeerror;
 {vm->retval = ret;vm->lastret = vm->curf.pc;};
 return 0;
}

canonical_original_code:
int tsmath_pow(struct tsvm *vm, int pcount)
{
 struct tsval *pv1; struct tsval *pv2;
 struct tsval ret;
 pv2 = &vm->dstack[vm->dsp-1];
 pv1 = &vm->dstack[vm->dsp-2];
 if(((pv1)->t==type_int||(pv1)->t==type_float)&&((pv2)->t==type_int||(pv2)->t==type_float))
 {
  ret.t = type_float;
  ret.fnum = pow((((pv1)->t==type_int)?(double)(pv1)->inum:(pv1)->fnum),(((pv2)->t==type_int)?(double)(pv2)->inum:(pv2)->fnum));
 }
 else
  return rterr_obj_typeerror;
 {vm->retval = ret;vm->lastret = vm->curf.pc;};
 return 0;
}

variable_types: struct tsval { unsigned char t; int reg; union { struct tstable { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; struct tnode { struct tsval key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; } *slot; struct tnode *head; int size; int used; } *tab; struct tsstr { struct tsgarbage gchead; unsigned int hash; unsigned char *buf; int len; } *str; struct tsarray { struct tsgarbage gchead; struct tsval *data; int enumptr; int size; int used; } *a; struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir { struct symtable { struct symnode { struct tsstr *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } strt; struct symtable funt; struct tsarray funlist; struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } cstt; struct tsfunc global; } *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm { struct envir *e; int line; struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; } curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; } *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; } *func; double fnum; int inum; }; }


original_code:
int tsmath_sqrt(tsvm *vm,int pcount)
{
 tsval *pv;
 tsval ret;
 pv = &vm->dstack[vm->dsp-1];
 if(((pv)->t==type_int||(pv)->t==type_float))
 {
  ret.t = type_float;
  ret.fnum = sqrt((((pv)->t==type_int)?(double)(pv)->inum:(pv)->fnum));
 }
 else
  return rterr_obj_typeerror;
 {vm->retval = ret;vm->lastret = vm->curf.pc;};
 return 0;
}

canonical_original_code:
int tsmath_sqrt(struct tsvm *vm, int pcount)
{
 struct tsval *pv;
 struct tsval ret;
 pv = &vm->dstack[vm->dsp-1];
 if(((pv)->t==type_int||(pv)->t==type_float))
 {
  ret.t = type_float;
  ret.fnum = sqrt((((pv)->t==type_int)?(double)(pv)->inum:(pv)->fnum));
 }
 else
  return rterr_obj_typeerror;
 {vm->retval = ret;vm->lastret = vm->curf.pc;};
 return 0;
}

user_defined_types: struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; }

user_defined_types: struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; }

user_defined_types: struct tnode { struct tsval key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; }

user_defined_types: struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; }


decompiled_code:
__int64 __fastcall ts_init_mathlib(__int64 a1)
{
return addbuiltin(a1, &mathlib);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return addbuiltin(a1, &mathlib);
}

original_code:
void ts_init_mathlib(envir *e)
{
 addbuiltin(e,mathlib);
}

canonical_original_code:
void ts_init_mathlib(struct envir *e)
{
 addbuiltin(e,mathlib);
}

variable_types: struct envir { struct symtable { struct symnode { struct tsstr { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; unsigned int hash; unsigned char *buf; int len; } *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } strt; struct symtable funt; struct tsarray { struct tsgarbage gchead; struct tsval { unsigned char t; int reg; union { struct tstable { struct tsgarbage gchead; struct tnode { struct tsval key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; } *slot; struct tnode *head; int size; int used; } *tab; struct tsstr *str; struct tsarray *a; struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm { struct envir *e; int line; struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; } curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; } *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; } *func; double fnum; int inum; }; } *data; int enumptr; int size; int used; } funlist; struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } cstt; struct tsfunc global; } *


printtable

decompiled_code:
int __fastcall printtable(__int64 a1)
{
char *v1; // rbx
char v2; // al

v1 = *(char **)(a1 + 24);
putchar(123);
for ( ; v1; v1 = (char *)*((_QWORD *)v1 + 4) )
{
v2 = *v1;
if ( *v1 == 3 )
{
printf("%.06f", *((double *)v1 + 1));
}
else if ( v2 == 4 )
{
printf("'%s'", *(const char **)(*((_QWORD *)v1 + 1) + 24LL));
}
else if ( v2 == 2 )
{
printf("%d", *((unsigned int *)v1 + 2));
}
putchar(58);
switch ( v1[16] )
{
case 2:
printf("%d", *((unsigned int *)v1 + 6));
break;
case 3:
printf("%.06f", *((double *)v1 + 3));
break;
case 4:
printf("'%s'", *(const char **)(*((_QWORD *)v1 + 3) + 24LL));
break;
case 5:
printtable(*((_QWORD *)v1 + 3));
break;
case 6:
printarray(*((_QWORD *)v1 + 3));
break;
case 7:
printf("function object at:0x%08x", *((unsigned int *)v1 + 6));
break;
default:
break;
}
if ( !*((_QWORD *)v1 + 4) )
break;
putchar(44);
}
return putchar(125);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
char *v1; // rbx
char v2; // al

v1 = *(char **)(a1 + 24);
putchar(123);
for ( ; v1; v1 = (char *)*((_QWORD *)v1 + 4) )
{
v2 = *v1;
if ( *v1 == 3 )
{
printf("%.06f", *((double *)v1 + 1));
}
else if ( v2 == 4 )
{
printf("'%s'", *(const char **)(*((_QWORD *)v1 + 1) + 24LL));
}
else if ( v2 == 2 )
{
printf("%d", *((unsigned int *)v1 + 2));
}
putchar(58);
switch ( v1[16] )
{
case 2:
printf("%d", *((unsigned int *)v1 + 6));
break;
case 3:
printf("%.06f", *((double *)v1 + 3));
break;
case 4:
printf("'%s'", *(const char **)(*((_QWORD *)v1 + 3) + 24LL));
break;
case 5:
func0(*((_QWORD *)v1 + 3));
break;
case 6:
func1(*((_QWORD *)v1 + 3));
break;
case 7:
printf("function object at:0x%08x", *((unsigned int *)v1 + 6));
break;
default:
break;
}
if ( !*((_QWORD *)v1 + 4) )
break;
putchar(44);
}
return putchar(125);
}

original_code:
void printtable(tstable *tab)
{
 tnode *h;
 h = tab->head;
 printf("{");
 while(h)
 {
  switch(h->key.t)
  {
  case type_int:
   printf("%d",h->key.inum);
   break;
  case type_float:
   printf("%.06f",h->key.fnum);
   break;
  case type_str:
   printf("\'%s\'",h->key.str->buf);
   break;
  }
  printf(":");
  switch(h->data.t)
  {
  case type_int:
   printf("%d",h->data.inum);
   break;
  case type_float:
   printf("%.06f",h->data.fnum);
   break;
  case type_str:
   printf("\'%s\'",h->data.str->buf);
   break;
  case type_func:
   printf("function object at:0x%08x",(uint)h->data.func);
   break;
  case type_table:
   printtable(h->data.tab);
   break;
  case type_array:
   printarray(h->data.a);
  }
  if(h->next)
   printf(",");
  h = h->next;
 }
 printf("}");
}

canonical_original_code:
void printtable(struct tstable *tab)
{
 struct tnode *h;
 h = tab->head;
 printf("{");
 while(h)
 {
  switch(h->key.t)
  {
  case type_int:
   printf("%d",h->key.inum);
   break;
  case type_float:
   printf("%.06f",h->key.fnum);
   break;
  case type_str:
   printf("\'%s\'",h->key.str->buf);
   break;
  }
  printf(":");
  switch(h->data.t)
  {
  case type_int:
   printf("%d",h->data.inum);
   break;
  case type_float:
   printf("%.06f",h->data.fnum);
   break;
  case type_str:
   printf("\'%s\'",h->data.str->buf);
   break;
  case type_func:
   printf("function object at:0x%08x",(unsigned int)h->data.func);
   break;
  case type_table:
   printtable(h->data.tab);
   break;
  case type_array:
   printarray(h->data.a);
  }
  if(h->next)
   printf(",");
  h = h->next;
 }
 printf("}");
}

variable_types: struct tstable { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; struct tnode { struct tsval { unsigned char t; int reg; union { struct tstable *tab; struct tsstr { struct tsgarbage gchead; unsigned int hash; unsigned char *buf; int len; } *str; struct tsarray { struct tsgarbage gchead; struct tsval *data; int enumptr; int size; int used; } *a; struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir { struct symtable { struct symnode { struct tsstr *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } strt; struct symtable funt; struct tsarray funlist; struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } cstt; struct tsfunc global; } *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm { struct envir *e; int line; struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; } curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; } *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; } *func; double fnum; int inum; }; } key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; } *slot; struct tnode *head; int size; int used; } *

variable_types: struct tnode { struct tsval { unsigned char t; int reg; union { struct tstable { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; struct tnode *slot; struct tnode *head; int size; int used; } *tab; struct tsstr { struct tsgarbage gchead; unsigned int hash; unsigned char *buf; int len; } *str; struct tsarray { struct tsgarbage gchead; struct tsval *data; int enumptr; int size; int used; } *a; struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir { struct symtable { struct symnode { struct tsstr *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } strt; struct symtable funt; struct tsarray funlist; struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } cstt; struct tsfunc global; } *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm { struct envir *e; int line; struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; } curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; } *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; } *func; double fnum; int inum; }; } key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; } *


printarray

decompiled_code:
int __fastcall printarray(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax
int v3; // eax

v1 = 0LL;
putchar(91);
if ( *(int *)(a1 + 32) > 0 )
{
do
{
v2 = *(_QWORD *)(a1 + 16) + 16 * v1;
switch ( *(_BYTE *)v2 )
{
case 1:
printf("null");
break;
case 2:
printf("%d", *(unsigned int *)(v2 + 8));
break;
case 3:
printf("%.06f", *(double *)(v2 + 8));
break;
case 4:
printf("'%s'", *(const char **)(*(_QWORD *)(v2 + 8) + 24LL));
break;
case 5:
printtable(*(_QWORD *)(v2 + 8));
break;
case 6:
printarray(*(_QWORD *)(v2 + 8));
break;
case 7:
printf("function object at:0x%08x", *(_QWORD *)(v2 + 8));
break;
default:
break;
}
v3 = *(_DWORD *)(a1 + 32);
if ( v3 - 1 > (int)v1 )
{
putchar(44);
v3 = *(_DWORD *)(a1 + 32);
}
++v1;
}
while ( v3 > (int)v1 );
}
return putchar(93);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax
int v3; // eax

v1 = 0LL;
putchar(91);
if ( *(int *)(a1 + 32) > 0 )
{
do
{
v2 = *(_QWORD *)(a1 + 16) + 16 * v1;
switch ( *(_BYTE *)v2 )
{
case 1:
printf("null");
break;
case 2:
printf("%d", *(unsigned int *)(v2 + 8));
break;
case 3:
printf("%.06f", *(double *)(v2 + 8));
break;
case 4:
printf("'%s'", *(const char **)(*(_QWORD *)(v2 + 8) + 24LL));
break;
case 5:
func0(*(_QWORD *)(v2 + 8));
break;
case 6:
func1(*(_QWORD *)(v2 + 8));
break;
case 7:
printf("function object at:0x%08x", *(_QWORD *)(v2 + 8));
break;
default:
break;
}
v3 = *(_DWORD *)(a1 + 32);
if ( v3 - 1 > (int)v1 )
{
putchar(44);
v3 = *(_DWORD *)(a1 + 32);
}
++v1;
}
while ( v3 > (int)v1 );
}
return putchar(93);
}

original_code:
void printarray(tsarray *arr)
{
 int i;
 tsval *pv;
 printf("[");
 for(i=0;i<arr->used;++i)
 {
  pv = &arr->data[i];
  switch(pv->t)
  {
  case type_null:
   printf("null");
   break;
  case type_int:
   printf("%d",(pv)->inum);
   break;
  case type_float:
   printf("%.06f",(pv)->fnum);
   break;
  case type_str:
   printf("\'%s\'",(pv)->str->buf);
   break;
  case type_func:
   printf("function object at:0x%08x",(uint)(pv)->func);
   break;
  case type_array:
   printarray((pv)->a);
   break;
  case type_table:
   printtable((pv)->tab);
   break;
  }
  if(i<arr->used-1)
   printf(",");
 }
 printf("]");
}

canonical_original_code:
void printarray(struct tsarray *arr)
{
 int i;
 struct tsval *pv;
 printf("[");
 for(i=0;i<arr->used;++i)
 {
  pv = &arr->data[i];
  switch(pv->t)
  {
  case type_null:
   printf("null");
   break;
  case type_int:
   printf("%d",(pv)->inum);
   break;
  case type_float:
   printf("%.06f",(pv)->fnum);
   break;
  case type_str:
   printf("\'%s\'",(pv)->str->buf);
   break;
  case type_func:
   printf("function object at:0x%08x",(uint)(pv)->func);
   break;
  case type_array:
   printarray((pv)->a);
   break;
  case type_table:
   printtable((pv)->tab);
   break;
  }
  if(i<arr->used-1)
   printf(",");
 }
 printf("]");
}

variable_types: struct tsarray { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; struct tsval { unsigned char t; int reg; union { struct tstable { struct tsgarbage gchead; struct tnode { struct tsval key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; } *slot; struct tnode *head; int size; int used; } *tab; struct tsstr { struct tsgarbage gchead; unsigned int hash; unsigned char *buf; int len; } *str; struct tsarray *a; struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir { struct symtable { struct symnode { struct tsstr *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } strt; struct symtable funt; struct tsarray funlist; struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } cstt; struct tsfunc global; } *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm { struct envir *e; int line; struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; } curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; } *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; } *func; double fnum; int inum; }; } *data; int enumptr; int size; int used; } *

variable_types: i int


decompiled_code:
__int64 __fastcall tslib_print(__int64 a1, int a2)
{
int v2; // edx
int v3; // ebx
__int64 v4; // rbp
__int64 v5; // rax

v2 = *(_DWORD *)(a1 + 124);
v3 = v2 - a2;
v4 = 16LL * (v2 - a2);
if ( v2 > v2 - a2 )
{
while ( 2 )
{
v5 = v4 + *(_QWORD *)(a1 + 48);
switch ( *(_BYTE *)v5 )
{
case 1:
printf("null");
v2 = *(_DWORD *)(a1 + 124);
goto LABEL_4;
case 2:
printf("%d", *(unsigned int *)(v5 + 8));
v2 = *(_DWORD *)(a1 + 124);
goto LABEL_4;
case 3:
printf("%.06f", *(double *)(v5 + 8));
v2 = *(_DWORD *)(a1 + 124);
goto LABEL_4;
case 4:
printf("'%s'", *(const char **)(*(_QWORD *)(v5 + 8) + 24LL));
v2 = *(_DWORD *)(a1 + 124);
goto LABEL_4;
case 5:
printtable(*(_QWORD *)(v5 + 8));
v2 = *(_DWORD *)(a1 + 124);
goto LABEL_4;
case 6:
printarray(*(_QWORD *)(v5 + 8));
v2 = *(_DWORD *)(a1 + 124);
if ( v2 - 1 > v3 )
goto LABEL_8;
goto LABEL_5;
case 7:
printf("function object at:0x%08x", *(_QWORD *)(v5 + 8));
v2 = *(_DWORD *)(a1 + 124);
goto LABEL_4;
default:
LABEL_4:
if ( v2 - 1 > v3 )
{
LABEL_8:
putchar(44);
v2 = *(_DWORD *)(a1 + 124);
}
LABEL_5:
++v3;
v4 += 16LL;
if ( v3 >= v2 )
break;
continue;
}
}
}
putchar(10);
return 0LL;
}

original_code:
int tslib_print(tsvm *vm,int pcount)
{
 int i;
 tsval *pv;
 for(i=vm->dsp-pcount;i<vm->dsp;++i)
 {
  pv = &vm->dstack[i];
  switch(pv->t)
  {
  case type_null:
   printf("null");
   break;
  case type_int:
   printf("%d",(pv)->inum);
   break;
  case type_float:
   printf("%.06f",(pv)->fnum);
   break;
  case type_str:
   printf("\'%s\'",(pv)->str->buf);
   break;
  case type_func:
   printf("function object at:0x%08x",(pv)->func);
   break;
  case type_array:
   printarray((pv)->a);
   break;
  case type_table:
   printtable((pv)->tab);
   break;
  }
  if(i<vm->dsp-1)
  {
   printf(",");
  }
 }
 printf("\n");
 return 0;
}

canonical_original_code:
int tslib_print(struct tsvm *vm, int pcount)
{
 int i;
 struct tsval *pv;
 for(i=vm->dsp-pcount;i<vm->dsp;++i)
 {
  pv = &vm->dstack[i];
  switch(pv->t)
  {
  case type_null:
   printf("null");
   break;
  case type_int:
   printf("%d",(pv)->inum);
   break;
  case type_float:
   printf("%.06f",(pv)->fnum);
   break;
  case type_str:
   printf("\'%s\'",(pv)->str->buf);
   break;
  case type_func:
   printf("function object at:0x%08x",(pv)->func);
   break;
  case type_array:
   printarray((pv)->a);
   break;
  case type_table:
   printtable((pv)->tab);
   break;
  }
  if(i<vm->dsp-1)
  {
   printf(",");
  }
 }
 printf("\n");
 return 0;
}


decompiled_code:
__int64 __fastcall ts_init_iolib(__int64 a1)
{
return addbuiltin(a1, &iolib);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return addbuiltin(a1, &iolib);
}

original_code:
void ts_init_iolib(envir *e)
{
 addbuiltin(e,iolib);
}

canonical_original_code:
void ts_init_iolib(struct envir *e)
{
 addbuiltin(e,iolib);
}


marktable

decompiled_code:
__int64 __fastcall marktable(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int8 *v3; // rbx
unsigned __int8 v4; // al

result = *(unsigned __int8 *)(a1 + 153);
v3 = *(unsigned __int8 **)(a2 + 24);
for ( *(_BYTE *)(a2 + 8) = result; v3; v3 = (unsigned __int8 *)*((_QWORD *)v3 + 4) )
{
v4 = v3[16];
if ( v4 == 6 )
{
markarray(a1, *((_QWORD *)v3 + 3));
}
else if ( v4 == 5 )
{
marktable(a1, *((_QWORD *)v3 + 3));
}
result = *v3;
if ( (_BYTE)result == 6 )
{
result = markarray(a1, *((_QWORD *)v3 + 1));
}
else if ( (_BYTE)result == 5 )
{
result = marktable(a1, *((_QWORD *)v3 + 1));
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int8 *v3; // rbx
unsigned __int8 v4; // al

result = *(unsigned __int8 *)(a1 + 153);
v3 = *(unsigned __int8 **)(a2 + 24);
for ( *(_BYTE *)(a2 + 8) = result; v3; v3 = (unsigned __int8 *)*((_QWORD *)v3 + 4) )
{
v4 = v3[16];
if ( v4 == 6 )
{
func1(a1, *((_QWORD *)v3 + 3));
}
else if ( v4 == 5 )
{
func0(a1, *((_QWORD *)v3 + 3));
}
result = *v3;
if ( (_BYTE)result == 6 )
{
result = func1(a1, *((_QWORD *)v3 + 1));
}
else if ( (_BYTE)result == 5 )
{
result = func0(a1, *((_QWORD *)v3 + 1));
}
}
return result;
}

original_code:
static void marktable(tsvm *vm,tstable *tab)
{
 tnode *tmp;
 tab->gchead.color = vm->gcflag;
 tmp = tab->head;
 while(tmp)
 {
  if(((&tmp->data)->t==type_array))
   markarray(vm,tmp->data.a);
  else if(((&tmp->data)->t==type_table))
   marktable(vm,tmp->data.tab);
  if(((&tmp->key)->t==type_array))
   markarray(vm,tmp->key.a);
  else if(((&tmp->key)->t==type_table))
   marktable(vm,tmp->key.tab);
  tmp = tmp->next;
 }
}

canonical_original_code:
static void marktable(struct tsvm *vm, struct tstable *tab)
{
 struct tnode *tmp;
 tab->gchead.color = vm->gcflag;
 tmp = tab->head;
 while(tmp)
 {
  if(((&tmp->data)->t==type_array))
   markarray(vm,tmp->data.a);
  else if(((&tmp->data)->t==type_table))
   marktable(vm,tmp->data.tab);
  if(((&tmp->key)->t==type_array))
   markarray(vm,tmp->key.a);
  else if(((&tmp->key)->t==type_table))
   marktable(vm,tmp->key.tab);
  tmp = tmp->next;
 }
}

variable_types:
tab
struct tstable *


markarray

decompiled_code:
__int64 __fastcall markarray(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbx
char v4; // dl

*(_BYTE *)(a2 + 8) = *(_BYTE *)(a1 + 153);
result = *(unsigned int *)(a2 + 32);
if ( (int)result > 0 )
{
v3 = 0LL;
do
{
result = *(_QWORD *)(a2 + 16) + 16 * v3;
v4 = *(_BYTE *)result;
if ( *(_BYTE *)result == 6 )
{
result = markarray(a1, *(_QWORD *)(result + 8));
}
else if ( v4 == 5 )
{
result = marktable(a1, *(_QWORD *)(result + 8));
}
else if ( v4 == 4 )
{
result = *(_QWORD *)(result + 8);
*(_BYTE *)(result + 8) = *(_BYTE *)(a1 + 153);
}
++v3;
}
while ( *(_DWORD *)(a2 + 32) > (int)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbx
char v4; // dl

*(_BYTE *)(a2 + 8) = *(_BYTE *)(a1 + 153);
result = *(unsigned int *)(a2 + 32);
if ( (int)result > 0 )
{
v3 = 0LL;
do
{
result = *(_QWORD *)(a2 + 16) + 16 * v3;
v4 = *(_BYTE *)result;
if ( *(_BYTE *)result == 6 )
{
result = func1(a1, *(_QWORD *)(result + 8));
}
else if ( v4 == 5 )
{
result = func0(a1, *(_QWORD *)(result + 8));
}
else if ( v4 == 4 )
{
result = *(_QWORD *)(result + 8);
*(_BYTE *)(result + 8) = *(_BYTE *)(a1 + 153);
}
++v3;
}
while ( *(_DWORD *)(a2 + 32) > (int)v3 );
}
return result;
}

original_code:
static void markarray(tsvm *vm,tsarray *arr)
{
 int i;
 tsval *pv;
 arr->gchead.color = vm->gcflag;
 for(i=0;i<arr->used;++i)
 {
  pv = &arr->data[i];
  if(((pv)->t==type_array))
   markarray(vm,pv->a);
  else if(((pv)->t==type_table))
   marktable(vm,pv->tab);
  else if(((pv)->t==type_str))
   pv->str->gchead.color = vm->gcflag;
 }
}

canonical_original_code:
static void markarray(struct tsvm *vm, struct tsarray *arr)
{
 int i;
 struct tsval *pv;
 arr->gchead.color = vm->gcflag;
 for(i=0;i<arr->used;++i)
 {
  pv = &arr->data[i];
  if(((pv)->t==type_array))
   markarray(vm,pv->a);
  else if(((pv)->t==type_table))
   marktable(vm,pv->tab);
  else if(((pv)->t==type_str))
   pv->str->gchead.color = vm->gcflag;
 }
}

variable_types:
arr
struct tsarray *


markframe

original_code:
static void markframe(tsvm *vm,tsframe *frame)
{
 int i;
 tsval *tmpobj;
 for(i=frame->varbase;i<frame->regbase;++i)
 {
  tmpobj = &vm->dstack[i];
  if(((tmpobj)->t==type_array))
   markarray(vm,tmpobj->a);
  else if(((tmpobj)->t==type_table))
   marktable(vm,tmpobj->tab);
  else if(((tmpobj)->t==type_str))
   tmpobj->str->gchead.color = vm->gcflag;
 }
 for(i=frame->regbase;i<frame->regbase+256;++i)
 {
  tmpobj = &vm->dstack[i];
  if(((tmpobj)->t==type_array))
   markarray(vm,tmpobj->a);
  else if(((tmpobj)->t==type_table))
   marktable(vm,tmpobj->tab);
  else if(((tmpobj)->t==type_str))
   tmpobj->str->gchead.color = vm->gcflag;
 }
}

canonical_original_code:
static void markframe(struct tsvm *vm, struct tsframe *frame)
{
 int i;
 struct tsval *tmpobj;
 for(i=frame->varbase;i<frame->regbase;++i)
 {
  tmpobj = &vm->dstack[i];
  if(((tmpobj)->t==type_array))
   markarray(vm,tmpobj->a);
  else if(((tmpobj)->t==type_table))
   marktable(vm,tmpobj->tab);
  else if(((tmpobj)->t==type_str))
   tmpobj->str->gchead.color = vm->gcflag;
 }
 for(i=frame->regbase;i<frame->regbase+256;++i)
 {
  tmpobj = &vm->dstack[i];
  if(((tmpobj)->t==type_array))
   markarray(vm,tmpobj->a);
  else if(((tmpobj)->t==type_table))
   marktable(vm,tmpobj->tab);
  else if(((tmpobj)->t==type_str))
   tmpobj->str->gchead.color = vm->gcflag;
 }
}

variable_types:
frame
struct tsframe *


scangcobj

decompiled_code:
__int64 __fastcall scangcobj(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rsi

markframe(a1, a1 + 16);
result = *(int *)(a1 + 80);
if ( (int)result > 0 )
{
v2 = 0LL;
v3 = 24 * result;
do
{
v4 = v2 + *(_QWORD *)(a1 + 40);
v2 += 24LL;
result = markframe(a1, v4);
}
while ( v2 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rsi

func2(a1, a1 + 16);
result = *(int *)(a1 + 80);
if ( (int)result > 0 )
{
v2 = 0LL;
v3 = 24 * result;
do
{
v4 = v2 + *(_QWORD *)(a1 + 40);
v2 += 24LL;
result = func2(a1, v4);
}
while ( v2 != v3 );
}
return result;
}

original_code:
static void scangcobj(tsvm *vm)
{
 int clen,i;
 markframe(vm,&vm->curf);
 clen = vm->cstsize;
 for(i=0;i<clen;++i)
  markframe(vm,&vm->cstack[i]);
}

canonical_original_code:
static void scangcobj(struct tsvm *vm)
{
 int clen; int i;
 markframe(vm,&vm->curf);
 clen = vm->cstsize;
 for(i=0;i<clen;++i)
  markframe(vm,&vm->cstack[i]);
}

variable_types: clen int


freestr

decompiled_code:
void __fastcall freestr(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
static void freestr(tsstr *str)
{
 free(str->buf);
 free(str);
}

canonical_original_code:
static void freestr(struct tsstr *str)
{
 free(str->buf);
 free(str);
}

variable_types: struct tsstr { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; unsigned int hash; unsigned char *buf; int len; } *


freearray

decompiled_code:
void __fastcall freearray(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
static void freearray(tsarray *arr)
{
 free(arr->data);
 free(arr);
}

canonical_original_code:
static void freearray(struct tsarray *arr)
{
 free(arr->data);
 free(arr);
}


freetable

decompiled_code:
void __fastcall freetable(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
static void freetable(tstable *tab)
{
 free(tab->slot);
 free(tab);
}

canonical_original_code:
static void freetable(struct tstable *tab)
{
 free(tab->slot);
 free(tab);
}


collectgcobj

decompiled_code:
void __fastcall collectgcobj(__int64 a1)
{
_BYTE *v2; // rbp
_BYTE *v3; // rbx
_QWORD *v4; // r13
char v5; // al
char v6; // al
_BYTE *v7; // rdi

v2 = 0LL;
v3 = *(_BYTE **)(a1 + 136);
if ( v3 )
{
v4 = 0LL;
do
{
while ( 1 )
{
v6 = v3[8];
v7 = v3;
v3 = *(_BYTE **)v3;
if ( *(_BYTE *)(a1 + 153) == v6 || v6 == -1 )
break;
if ( v4 )
*v4 = v3;
v5 = v7[9];
switch ( v5 )
{
case 4:
freestr(v7);
break;
case 6:
freearray(v7);
break;
case 5:
freetable(v7);
break;
}
--*(_DWORD *)(a1 + 148);
if ( !v3 )
goto LABEL_15;
}
v4 = v7;
if ( !v2 )
v2 = v7;
}
while ( v3 );
}
LABEL_15:
*(_QWORD *)(a1 + 136) = v2;
}

original_code:
static void collectgcobj(tsvm *vm)
{
 tsgarbage *gb,*last,*head,*tmp;
 gb = vm->gclist;
 last = head = ((void *)0);
 while(gb)
 {
  if(gb->color!=vm->gcflag&&gb->color!=0xff)
  {
   tmp = gb->next;
   if(last)
    last->next = tmp;
   if(gb->type==type_str)
    freestr((tsstr*)gb);
   else if(gb->type==type_array)
    freearray((tsarray*)gb);
   else if(gb->type==type_table)
    freetable((tstable*)gb);
   gb = tmp;
   --vm->gcobj_count;
  }
  else
  {
   last = gb;
   gb = gb->next;
   if(head==((void *)0))
    head = last;
  }
 }
 vm->gclist = head;
}

canonical_original_code:
static void collectgcobj(struct tsvm *vm)
{
 struct tsgarbage *gb; struct tsgarbage *last; struct tsgarbage *head; struct tsgarbage *tmp;
 gb = vm->gclist;
 last = head = ((void *)0);
 while(gb)
 {
  if(gb->color!=vm->gcflag&&gb->color!=0xff)
  {
   tmp = gb->next;
   if(last)
    last->next = tmp;
   if(gb->type==type_str)
    freestr((struct tsstr *)gb);
   else if(gb->type==type_array)
    freearray((struct tsarray *)gb);
   else if(gb->type==type_table)
    freetable((struct tstable *)gb);
   gb = tmp;
   --vm->gcobj_count;
  }
  else
  {
   last = gb;
   gb = gb->next;
   if(head==((void *)0))
    head = last;
  }
 }
 vm->gclist = head;
}

variable_types: struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } *


gchandler

original_code:
void gchandler(tsvm *vm)
{
 if(vm->gcstate == state_mark)
 {
  scangcobj(vm);
  vm->gcstate = state_collect;
 }
 else
 {
  collectgcobj(vm);
  vm->gcflag = !vm->gcflag;
  vm->gcstate = state_mark;
 }
}

canonical_original_code:
void gchandler(struct tsvm *vm)
{
 if(vm->gcstate == state_mark)
 {
  scangcobj(vm);
  vm->gcstate = state_collect;
 }
 else
 {
  collectgcobj(vm);
  vm->gcflag = !vm->gcflag;
  vm->gcstate = state_mark;
 }
}


rehashcst

original_code:
static void rehashcst(csttable* table)
{
 uint size = table->size*2;
 cstnode *n = (cstnode*)malloc(sizeof(cstnode)*size);
 cstnode *tmp = table->slot;
 memset(n,0,size*sizeof(cstnode));
 table->slot = n;
 n = table->tail;
 table->head = table->tail = ((void *)0);
 while(n)
 {
  setcst(table,n->key,n->data);
  n=n->next;
 }
 free(tmp);
}

canonical_original_code:
static void rehashcst(struct csttable *table)
{
 unsigned int size = table->size*2;
 struct cstnode *n = (cstnode*)malloc(sizeof(cstnode)*size);
 struct cstnode *tmp = table->slot;
 memset(n,0,size*sizeof(cstnode));
 table->slot = n;
 n = table->tail;
 table->head = table->tail = ((void *)0);
 while(n)
 {
  setcst(table,n->key,n->data);
  n=n->next;
 }
 free(tmp);
}

variable_types: struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } *

variable_types:
size
unsigned int


rawgetstr

decompiled_code:
__int64 __fastcall rawgetstr(__int64 *a1, const char *a2, unsigned int a3)
{
unsigned int v3; // ebp
unsigned int v4; // eax
__int64 v5; // r14
unsigned int i; // ebx
__int64 v7; // r12

v3 = *((_DWORD *)a1 + 6);
v4 = genhash(a2, a3);
v5 = *a1;
for ( i = v4; ; v4 = i )
{
v7 = *(_QWORD *)(v5 + 24LL * (v4 % v3));
if ( !v7 || !strcmp(a2, *(const char **)(v7 + 24)) )
break;
++i;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, const char *a2, unsigned int a3)
{
unsigned int v3; // ebp
unsigned int v4; // eax
__int64 v5; // r14
unsigned int i; // ebx
__int64 v7; // r12

v3 = *((_DWORD *)a1 + 6);
v4 = genhash(a2, a3);
v5 = *a1;
for ( i = v4; ; v4 = i )
{
v7 = *(_QWORD *)(v5 + 24LL * (v4 % v3));
if ( !v7 || !strcmp(a2, *(const char **)(v7 + 24)) )
break;
++i;
}
return v7;
}

original_code:
tsstr* rawgetstr(symtable *table,const byte *data,uint len)
{
 uint x;
 uint size = table->size;
 x = genhash(data,len);
 while(table->slot[x%size].key)
 {
  if(strcmp((char*)data,(char*)table->slot[x%size].key->buf)==0)
  {
   return table->slot[x%size].key;
  }
  ++x;
 }
 return ((void *)0);
}

canonical_original_code:
struct tsstr *rawgetstr(struct symtable *table, unsigned char *data, unsigned int len)
{
 unsigned int x;
 unsigned int size = table->size;
 x = genhash(data,len);
 while(table->slot[x%size].key)
 {
  if(strcmp((char *)data,(char *)table->slot[x%size].key->buf)==0)
  {
   return table->slot[x%size].key;
  }
  ++x;
 }
 return ((void *)0);
}

variable_types: struct symtable { struct symnode { struct tsstr *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } *

variable_types:
data
unsigned char *

variable_types:
len
unsigned int

variable_types:
x
unsigned int

return_type: struct tsstr { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; unsigned int hash; unsigned char *buf; int len; } *


findsymbol

decompiled_code:
__int64 __fastcall findsymbol(__int64 *a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // eax
__int64 v4; // r12
unsigned int v5; // ebx
__int64 v6; // r14
__int64 v7; // rax
const char *v8; // r13

v2 = *((_DWORD *)a1 + 6);
v3 = genhash(*(_QWORD *)(a2 + 24), *(unsigned int *)(a2 + 32));
v4 = *a1;
v5 = v3;
v6 = *a1 + 24LL * (v3 % v2);
v7 = *(_QWORD *)v6;
if ( !*(_QWORD *)v6 )
return 0xFFFFFFFFLL;
v8 = *(const char **)(a2 + 24);
while ( strcmp(v8, *(const char **)(v7 + 24)) )
{
v6 = v4 + 24LL * (++v5 % v2);
v7 = *(_QWORD *)v6;
if ( !*(_QWORD *)v6 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v6 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // eax
__int64 v4; // r12
unsigned int v5; // ebx
__int64 v6; // r14
__int64 v7; // rax
const char *v8; // r13

v2 = *((_DWORD *)a1 + 6);
v3 = genhash(*(_QWORD *)(a2 + 24), *(unsigned int *)(a2 + 32));
v4 = *a1;
v5 = v3;
v6 = *a1 + 24LL * (v3 % v2);
v7 = *(_QWORD *)v6;
if ( !*(_QWORD *)v6 )
return 0xFFFFFFFFLL;
v8 = *(const char **)(a2 + 24);
while ( strcmp(v8, *(const char **)(v7 + 24)) )
{
v6 = v4 + 24LL * (++v5 % v2);
v7 = *(_QWORD *)v6;
if ( !*(_QWORD *)v6 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v6 + 8);
}

original_code:
int findsymbol(symtable *table,tsstr *key)
{
 uint size = table->size;
 int x;
 x = genhash(key->buf,key->len);
 while(table->slot[x%size].key)
 {
  if(strcmp((char*)key->buf,(char*)table->slot[x%size].key->buf)==0)
   return table->slot[x%size].data;
  ++x;
 }
 return -1;
}

canonical_original_code:
int findsymbol(struct symtable *table, struct tsstr *key)
{
 unsigned int size = table->size;
 int x;
 x = genhash(key->buf,key->len);
 while(table->slot[x%size].key)
 {
  if(strcmp((char *)key->buf,(char *)table->slot[x%size].key->buf)==0)
   return table->slot[x%size].data;
  ++x;
 }
 return -1;
}

variable_types: struct symtable { struct symnode { struct tsstr { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; unsigned int hash; unsigned char *buf; int len; } *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } *

variable_types:
key
struct tsstr *

variable_types: x int


setsymbol

original_code:
void setsymbol(symtable* table,tsstr* key,int data)
{
 symnode *n;
 uint x;
 uint size = table->size;
 if(table->used*2>table->size)
  rehashsymbol(table);
 x = genhash(key->buf,key->len);
 while(table->slot[x%size].key)
 {
  if(strcmp((char*)(key->buf),(char*)(table->slot[x%size].key->buf))==0)
  {
   table->slot[x%size].data = data;
   return;
  }
  ++x;
 }
 n = &table->slot[x%size];
 n->key = key;
 if(data == -1)
  n->data = table->used;
 else
  n->data = data;
 ++table->used;
 if(table->head==((void *)0))
 {
  table->head = table->tail = n;
  n->next = ((void *)0);
 }
 else
 {
  table->tail->next = n;
  n->next = ((void *)0);
  table->tail = n;
 }
}

canonical_original_code:
void setsymbol(struct symtable *table, struct tsstr *key, int data)
{
 struct symnode *n;
 unsigned int x;
 unsigned int size = table->size;
 if(table->used*2>table->size)
  rehashsymbol(table);
 x = genhash(key->buf,key->len);
 while(table->slot[x%size].key)
 {
  if(strcmp((char *)(key->buf),(char *)(table->slot[x%size].key->buf))==0)
  {
   table->slot[x%size].data = data;
   return;
  }
  ++x;
 }
 n = &table->slot[x%size];
 n->key = key;
 if(data == -1)
  n->data = table->used;
 else
  n->data = data;
 ++table->used;
 if(table->head==((void *)0))
 {
  table->head = table->tail = n;
  n->next = ((void *)0);
 }
 else
 {
  table->tail->next = n;
  n->next = ((void *)0);
  table->tail = n;
 }
}

variable_types: data int

variable_types: struct symnode { struct tsstr { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; unsigned int hash; unsigned char *buf; int len; } *key; int data; struct symnode *next; } *


rehashsymbol

original_code:
void rehashsymbol(symtable* table)
{
 uint size = table->size*2;
 symnode *n = (symnode*)malloc(sizeof(symnode)*size);
 symnode *tmp = table->slot;
 memset(n,0,size*sizeof(symnode));
 table->slot = n;
 n = table->tail;
 table->head = table->tail = ((void *)0);
 while(n)
 {
  setsymbol(table,n->key,n->data);
  n=n->next;
 }
 free(tmp);
}

canonical_original_code:
void rehashsymbol(struct symtable *table)
{
 unsigned int size = table->size*2;
 struct symnode *n = (symnode*)malloc(sizeof(symnode)*size);
 struct symnode *tmp = table->slot;
 memset(n,0,size*sizeof(symnode));
 table->slot = n;
 n = table->tail;
 table->head = table->tail = ((void *)0);
 while(n)
 {
  setsymbol(table,n->key,n->data);
  n=n->next;
 }
 free(tmp);
}


initsymbol

decompiled_code:
void *__fastcall initsymbol(_QWORD *a1)
{
void *result; // rax

a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 256LL;
result = calloc(0x1800uLL, 1uLL);
*a1 = result;
return result;
}

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

a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 256LL;
result = calloc(0x1800uLL, 1uLL);
*a1 = result;
return result;
}

original_code:
void initsymbol(symtable *table)
{
 table->size = 256;
 table->used = 0;
 table->tail = table->head = ((void *)0);
 table->slot = (symnode*)malloc(sizeof(symnode)*256);
 memset(table->slot,0,sizeof(symnode)*256);
}

canonical_original_code:
void initsymbol(struct symtable *table)
{
 table->size = 256;
 table->used = 0;
 table->tail = table->head = ((void *)0);
 table->slot = (struct symnode *)malloc(sizeof(symnode)*256);
 memset(table->slot,0,sizeof(symnode)*256);
}


initcst

decompiled_code:
void *__fastcall initcst(_QWORD *a1)
{
void *result; // rax

a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 256LL;
result = calloc(0x1800uLL, 1uLL);
*a1 = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func7(_QWORD *a1)
{
void *result; // rax

a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 256LL;
result = calloc(0x1800uLL, 1uLL);
*a1 = result;
return result;
}

original_code:
void initcst(csttable *table)
{
 table->size = 256;
 table->used = 0;
 table->tail = table->head = ((void *)0);
 table->slot = (cstnode*)malloc(sizeof(cstnode)*256);
 memset(table->slot,0,sizeof(cstnode)*256);
}

canonical_original_code:
void initcst(struct csttable *table)
{
 table->size = 256;
 table->used = 0;
 table->tail = table->head = ((void *)0);
 table->slot = (struct cstnode *)malloc(sizeof(cstnode)*256);
 memset(table->slot,0,sizeof(cstnode)*256);
}


getconstant

original_code:
word getconstant(csttable *table,uint64 key)
{
 uint size;
 uint x;
 cstnode *n;
 size = table->size;
 x = genhash((byte*)&key,sizeof(key));
 while(table->slot[x%size].key!=0)
 {
  if(table->slot[x%size].key==key)
  {
   return table->slot[x%size].data;
  }
  ++x;
 }
 if(table->used*2>table->size)
  rehashcst(table);
 table->slot[x%size].key = key;
 table->slot[x%size].data = table->used;
 n = &table->slot[x%size];
 if(table->head==((void *)0))
 {
  table->head = table->tail = n;
  n->next = ((void *)0);
 }
 else
 {
  table->tail->next = n;
  n->next = ((void *)0);
  table->tail = n;
 }
 return table->used++;
}

canonical_original_code:
unsigned short getconstant(struct csttable *table, unsigned long long key)
{
 unsigned int size;
 unsigned int x;
 struct cstnode *n;
 size = table->size;
 x = genhash((unsigned char *)&key,sizeof(key));
 while(table->slot[x%size].key!=0)
 {
  if(table->slot[x%size].key==key)
  {
   return table->slot[x%size].data;
  }
  ++x;
 }
 if(table->used*2>table->size)
  rehashcst(table);
 table->slot[x%size].key = key;
 table->slot[x%size].data = table->used;
 n = &table->slot[x%size];
 if(table->head==((void *)0))
 {
  table->head = table->tail = n;
  n->next = ((void *)0);
 }
 else
 {
  table->tail->next = n;
  n->next = ((void *)0);
  table->tail = n;
 }
 return table->used++;
}

variable_types:
key
unsigned long long

variable_types: struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *

return_type: unsigned short