main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
int v4; // er13
int v5; // er14
int v6; // er15
unsigned int v7; // er12
int v8; // eax
int v9; // eax
int v10; // ebp
socklen_t v11; // edx
unsigned int v12; // er15
__pid_t v13; // eax
int v14; // eax
int v15; // ebp
char *v16; // rax
char *v17; // rax
int optval; // [rsp+8h] [rbp-150h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-14Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-148h] BYREF
char s[312]; // [rsp+20h] [rbp-138h] BYREF

me = (__int64)strrchr(*argv, 47);
v3 = (const char *)(me + 1);
if ( !me )
v3 = *argv;
me = (__int64)v3;
v4 = -1;
v5 = 0;
v6 = 0;
v7 = 5103;
while ( 1 )
{
v8 = getopt(argc, (char *const *)argv, "c:lLp:s:Dv");
if ( v8 == -1 )
break;
switch ( v8 )
{
case 'D':
v6 = 1;
break;
case 'L':
v5 = 0;
break;
case 'c':
v4 = atoi(optarg);
break;
case 'l':
v5 = 1;
break;
case 'p':
v7 = (unsigned __int16)atoi(optarg);
break;
case 's':
servers_allowed = atoi(optarg);
break;
case 'v':
++verbose;
break;
default:
usage();
exit(1);
}
}
if ( verbose )
printf("Address of sockaddr is %p\n", &addr);
if ( v6 )
{
v14 = open("/dev/tty", 0, 0LL);
v15 = v14;
if ( v14 != -1 )
{
ioctl(v14, 0x5422uLL, 0LL);
close(v15);
}
}
v9 = socket(2, 1, 0);
v10 = v9;
if ( v9 != -1 )
{
optval = 1;
if ( setsockopt(v9, 1, 2, &optval, 4u) != -1 )
{
addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(v7);
if ( bind(v10, &addr, v11) != -1 )
{
if ( listen(v10, 4) != -1 )
{
signal(17, (__sighandler_t)reaper);
while ( 1 )
{
while ( 1 )
{
addr_len = 16;
v12 = accept(v10, &addr, &addr_len);
if ( v12 == -1 )
break;
if ( verbose )
{
v16 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
fprintf(stderr, "[%s]\n", v16);
}
if ( v5 )
{
v17 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
sprintf(s, "rpc_server: Connect on port %d from %s", v7, v17);
syslog(30, s);
}
v13 = fork();
if ( v13 == -1 )
{
perror("fork");
exit(1);
}
if ( !v13 )
{
close(v10);
rpc_service(v12);
exit(0);
}
close(v12);
--servers_allowed;
if ( v4 > 0 && !--v4 )
exit(0);
while ( !servers_allowed )
{
if ( verbose )
fwrite("Pausing\n", 1uLL, 8uLL, stderr);
pause();
if ( verbose )
fprintf(stderr, "paused, servers_allowed %ld\n", servers_allowed);
}
}
if ( *_errno_location() != 4 )
{
perror("accept");
exit(1);
}
}
}
perror("listen");
exit(1);
}
perror("bind");
exit(1);
}
perror("setsockoopt");
exit(1);
}
perror("socket");
exit(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
int v4; // er13
int v5; // er14
int v6; // er15
unsigned int v7; // er12
int v8; // eax
int v9; // eax
int v10; // ebp
socklen_t v11; // edx
unsigned int v12; // er15
__pid_t v13; // eax
int v14; // eax
int v15; // ebp
char *v16; // rax
char *v17; // rax
int optval; // [rsp+8h] [rbp-150h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-14Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-148h] BYREF
char s[312]; // [rsp+20h] [rbp-138h] BYREF

me = (__int64)strrchr(*argv, 47);
v3 = (const char *)(me + 1);
if ( !me )
v3 = *argv;
me = (__int64)v3;
v4 = -1;
v5 = 0;
v6 = 0;
v7 = 5103;
while ( 1 )
{
v8 = getopt(argc, (char *const *)argv, "c:lLp:s:Dv");
if ( v8 == -1 )
break;
switch ( v8 )
{
case 'D':
v6 = 1;
break;
case 'L':
v5 = 0;
break;
case 'c':
v4 = atoi(optarg);
break;
case 'l':
v5 = 1;
break;
case 'p':
v7 = (unsigned __int16)atoi(optarg);
break;
case 's':
servers_allowed = atoi(optarg);
break;
case 'v':
++verbose;
break;
default:
func2();
exit(1);
}
}
if ( verbose )
printf("Address of sockaddr is %p\n", &addr);
if ( v6 )
{
v14 = open("/dev/tty", 0, 0LL);
v15 = v14;
if ( v14 != -1 )
{
ioctl(v14, 0x5422uLL, 0LL);
close(v15);
}
}
v9 = socket(2, 1, 0);
v10 = v9;
if ( v9 != -1 )
{
optval = 1;
if ( setsockopt(v9, 1, 2, &optval, 4u) != -1 )
{
addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func1(v7);
if ( bind(v10, &addr, v11) != -1 )
{
if ( listen(v10, 4) != -1 )
{
signal(17, (__sighandler_t)reaper);
while ( 1 )
{
while ( 1 )
{
addr_len = 16;
v12 = accept(v10, &addr, &addr_len);
if ( v12 == -1 )
break;
if ( verbose )
{
v16 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
fprintf(stderr, "[%s]\n", v16);
}
if ( v5 )
{
v17 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
sprintf(s, "rpc_server: Connect on port %d from %s", v7, v17);
syslog(30, s);
}
v13 = fork();
if ( v13 == -1 )
{
perror("fork");
exit(1);
}
if ( !v13 )
{
close(v10);
rpc_service(v12);
exit(0);
}
close(v12);
--servers_allowed;
if ( v4 > 0 && !--v4 )
exit(0);
while ( !servers_allowed )
{
if ( verbose )
fwrite("Pausing\n", 1uLL, 8uLL, stderr);
pause();
if ( verbose )
fprintf(stderr, "paused, servers_allowed %ld\n", servers_allowed);
}
}
if ( *_errno_location() != 4 )
{
perror("accept");
exit(1);
}
}
}
perror("listen");
exit(1);
}
perror("bind");
exit(1);
}
perror("setsockoopt");
exit(1);
}
perror("socket");
exit(1);
}

original_code:
int main(int ac,
  char **av)
{
 int s, ss;
 struct sockaddr_in name;
 int set,ch,namelen;
 int detach;
 u_short port = 5103;
 int log = 0, count = -1;
 extern int getopt(), optind;
 extern char *optarg;
 (void) copyright;
 me = strrchr(av[0],'/');
 if (!me) me = av[0]; else ++me;
 detach = 0;
 while ((ch = getopt(ac,av,"c:lLp:s:Dv")) != (-1)) switch (ch) {
 case 'c': count = atoi(optarg); break;
 case 'l': log = 1; break;
 case 'L': log = 0; break;
 case 'p': port = atoi(optarg); break;
 case 's': servers_allowed = atoi(optarg); break;
 case 'D': detach = 1; break;
 case 'v': verbose++; break;
 default: usage(); exit(1);
 }
 if (verbose) {
  printf("Address of sockaddr is %p\n",&name);
 }
 if (detach) {
  int i;
  i = open("/dev/tty",00,0);
  if (i != -1) {
   (void) ioctl(i,0x5422,(char *) 0);
   (void) close(i);
  }
 }
 if ((s = socket(2,SOCK_STREAM,0)) == -1) {
  perror("socket");
  exit(1);
 }
 set = 1;
 if (setsockopt(s,1,2,(const char *) &set, sizeof(set)) == -1) {
  perror("setsockoopt");
  exit(1);
 }
 memset((char *)&name,0,sizeof(name));
 name.sin_family = 2;
 name.sin_port = htons(port);
 if (bind(s,(struct sockaddr *) &name,sizeof(name)) == -1) {
  perror("bind");
  exit(1);
 }
 if (listen(s,4) == -1) {
  perror("listen");
  exit(1);
 }
 (void) signal(17,(void (*)(int)) reaper);
again:
 while ((namelen = sizeof name), ((ss = accept(s,(struct sockaddr *)&name,&namelen)) != -1)) {
  if (verbose) {
   fprintf(stderr,"[%s]\n",inet_ntoa(name.sin_addr));
  }
  if (log) {
   char buf[256];
   sprintf(buf,"rpc_server: Connect on port %d from %s",port,inet_ntoa(name.sin_addr));
   syslog(6 | (3<<3),buf);
  }
  switch (fork()) {
  case 0:
   (void) close(s);
   rpc_service(ss);
   exit(0);
  case -1:
   perror("fork");
   exit(1);
  default:
   (void) close(ss);
   --servers_allowed;
   break;
  }
  if (count > 0 && --count == 0) exit(0);
  while (!servers_allowed) {
   if (verbose) fprintf(stderr,"Pausing\n");
   pause();
   if (verbose) fprintf(stderr,"paused, servers_allowed %ld\n",servers_allowed);
  }
 }
 if ((*__errno_location ()) == 4) goto again;
 perror("accept");
 exit(1);
}

canonical_original_code:
int main(int ac, char **av)
{
 int s; int ss;
 struct sockaddr_in name;
 int set; int ch; int namelen;
 int detach;
 unsigned short port = 5103;
 int log = 0; int count = -1;
 extern int getopt(); extern int optind;
 extern char *optarg;
 (void) copyright;
 me = strrchr(av[0],'/');
 if (!me) me = av[0]; else ++me;
 detach = 0;
 while ((ch = getopt(ac,av,"c:lLp:s:Dv")) != (-1)) switch (ch) {
 case 'c': count = atoi(optarg); break;
 case 'l': log = 1; break;
 case 'L': log = 0; break;
 case 'p': port = atoi(optarg); break;
 case 's': servers_allowed = atoi(optarg); break;
 case 'D': detach = 1; break;
 case 'v': verbose++; break;
 default: usage(); exit(1);
 }
 if (verbose) {
  printf("Address of sockaddr is %p\n",&name);
 }
 if (detach) {
  int i;
  i = open("/dev/tty",00,0);
  if (i != -1) {
   (void) ioctl(i,0x5422,(char *) 0);
   (void) close(i);
  }
 }
 if ((s = socket(2,SOCK_STREAM,0)) == -1) {
  perror("socket");
  exit(1);
 }
 set = 1;
 if (setsockopt(s,1,2,(char *) &set, sizeof(set)) == -1) {
  perror("setsockoopt");
  exit(1);
 }
 memset((char *)&name,0,sizeof(name));
 name.sin_family = 2;
 name.sin_port = htons(port);
 if (bind(s,(struct sockaddr *) &name,sizeof(name)) == -1) {
  perror("bind");
  exit(1);
 }
 if (listen(s,4) == -1) {
  perror("listen");
  exit(1);
 }
 (void) signal(17,(void (*)(int)) reaper);
again:
 while ((namelen = sizeof name), ((ss = accept(s,(struct sockaddr *)&name,&namelen)) != -1)) {
  if (verbose) {
   fprintf(stderr,"[%s]\n",inet_ntoa(name.sin_addr));
  }
  if (log) {
   char buf[256];
   sprintf(buf,"rpc_server: Connect on port %d from %s",port,inet_ntoa(name.sin_addr));
   syslog(6 | (3<<3),buf);
  }
  switch (fork()) {
  case 0:
   (void) close(s);
   rpc_service(ss);
   exit(0);
  case -1:
   perror("fork");
   exit(1);
  default:
   (void) close(ss);
   --servers_allowed;
   break;
  }
  if (count > 0 && --count == 0) exit(0);
  while (!servers_allowed) {
   if (verbose) fprintf(stderr,"Pausing\n");
   pause();
   if (verbose) fprintf(stderr,"paused, servers_allowed %ld\n",servers_allowed);
  }
 }
 if ((*__errno_location ()) == 4) goto again;
 perror("accept");
 exit(1);
}

variable_types: ac int

variable_types:
av
char **

variable_types: s int

variable_types: ss int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: set int

variable_types: ch int

variable_types: namelen int

variable_types: detach int

variable_types:
port
unsigned short

variable_types: log int

variable_types: count int

variable_types:
getopt
int ()

variable_types: optind int

variable_types:
optarg
char *

variable_types:
buf
char [256]

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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


repo: beghbali/StackOverflowExploit

decompiled_code:
size_t __fastcall rpc_hndlr0(__int64 a1)
{
double v2; // xmm0_8
unsigned int v3; // [rsp+Ch] [rbp-24h] BYREF
unsigned int v4; // [rsp+10h] [rbp-20h] BYREF
unsigned int v5; // [rsp+14h] [rbp-1Ch] BYREF
double v6; // [rsp+18h] [rbp-18h] BYREF
double v7[2]; // [rsp+20h] [rbp-10h] BYREF

if ( (unsigned int)srss_unmarshall(a1, "dlfdlfd", &v3, &v6, &v4, v7, &v5) != 5 )
return fwrite("rpc_hndlr0: arg count wrong\n", 1uLL, 0x1CuLL, stderr);
if ( verbose )
{
puts("rpc_hndlr0: unmarshalled");
printf("i0 = %d\n", v3);
printf("i1 = %d\n", v4);
printf("i2 = %d\n", v5);
printf("d0 = %f\n", v6);
printf("d1 = %f\n", v7[0]);
v2 = (double)(int)v3 + v7[0] + (double)(int)v4 + (double)(int)v5 + v6;
v6 = v2;
if ( verbose )
printf("rpc_hndlr0: returning d0 = %f\n", v2);
}
else
{
v6 = (double)(int)v3 + v7[0] + (double)(int)v4 + (double)(int)v5 + v6;
}
return srss_marshall(a1, "lf");
}

canonical_decompiled_code:
size_t __fastcall func0(__int64 a1)
{
double v2; // xmm0_8
unsigned int v3; // [rsp+Ch] [rbp-24h] BYREF
unsigned int v4; // [rsp+10h] [rbp-20h] BYREF
unsigned int v5; // [rsp+14h] [rbp-1Ch] BYREF
double v6; // [rsp+18h] [rbp-18h] BYREF
double v7[2]; // [rsp+20h] [rbp-10h] BYREF

if ( (unsigned int)srss_unmarshall(a1, "dlfdlfd", &v3, &v6, &v4, v7, &v5) != 5 )
return fwrite("rpc_hndlr0: arg count wrong\n", 1uLL, 0x1CuLL, stderr);
if ( verbose )
{
puts("rpc_hndlr0: unmarshalled");
printf("i0 = %d\n", v3);
printf("i1 = %d\n", v4);
printf("i2 = %d\n", v5);
printf("d0 = %f\n", v6);
printf("d1 = %f\n", v7[0]);
v2 = (double)(int)v3 + v7[0] + (double)(int)v4 + (double)(int)v5 + v6;
v6 = v2;
if ( verbose )
printf("rpc_hndlr0: returning d0 = %f\n", v2);
}
else
{
v6 = (double)(int)v3 + v7[0] + (double)(int)v4 + (double)(int)v5 + v6;
}
return srss_marshall(a1, "lf");
}

original_code:
void rpc_hndlr0(struct srss_state *sp) {
 int i0, i1, i2;
 double d0, d1;
 if (srss_unmarshall(sp,"dlfdlfd",&i0,&d0,&i1,&d1,&i2) != 5) {
  fprintf(stderr,"rpc_hndlr0: arg count wrong\n");
  return;
 }
 if (verbose) {
  printf("rpc_hndlr0: unmarshalled\n");
  printf("i0 = %d\n",i0);
  printf("i1 = %d\n",i1);
  printf("i2 = %d\n",i2);
  printf("d0 = %f\n",d0);
  printf("d1 = %f\n",d1);
 }
 d0 += d1 + i0 + i1 + i2;
 if (verbose) {
  printf("rpc_hndlr0: returning d0 = %f\n",d0);
 }
 srss_marshall(sp,"lf",d0);
}

canonical_original_code:
void rpc_hndlr0(struct srss_state *sp) {
 int i0; int i1; int i2;
 double d0; double d1;
 if (srss_unmarshall(sp,"dlfdlfd",&i0,&d0,&i1,&d1,&i2) != 5) {
  fprintf(stderr,"rpc_hndlr0: arg count wrong\n");
  return;
 }
 if (verbose) {
  printf("rpc_hndlr0: unmarshalled\n");
  printf("i0 = %d\n",i0);
  printf("i1 = %d\n",i1);
  printf("i2 = %d\n",i2);
  printf("d0 = %f\n",d0);
  printf("d1 = %f\n",d1);
 }
 d0 += d1 + i0 + i1 + i2;
 if (verbose) {
  printf("rpc_hndlr0: returning d0 = %f\n",d0);
 }
 srss_marshall(sp,"lf",d0);
}

variable_types: struct srss_state { int sock; int num_entries; struct srss_entry { char *rpc_name; void (*rpc_handler)(struct srss_state *); } *entry_pts; int in_ix; char in_buf[-1]; void (*fn)(struct srss_entry *); } *

return_type: void

user_defined_types: struct srss_state { int sock; int num_entries; struct srss_entry *entry_pts; int in_ix; char in_buf[-1]; void (*fn)(struct srss_entry *); }


decompiled_code:
size_t __fastcall rpc_hndlr1(__int64 a1)
{
double v2; // xmm0_8
unsigned int v3; // [rsp+8h] [rbp-20h] BYREF
unsigned int v4; // [rsp+Ch] [rbp-1Ch] BYREF
double v5; // [rsp+10h] [rbp-18h] BYREF
double v6[2]; // [rsp+18h] [rbp-10h] BYREF

if ( (unsigned int)srss_unmarshall(a1, "dlfdlf", &v3, &v5, &v4, v6) != 4 )
return fwrite("rpc_hndlr1: arg count wrong\n", 1uLL, 0x1CuLL, stderr);
if ( verbose )
{
puts("rpc_hndlr1: unmarshalled");
printf("i0 = %d\n", v3);
printf("i1 = %d\n", v4);
printf("d0 = %f\n", v5);
printf("d1 = %f\n", v6[0]);
v2 = v6[0] - (double)(int)v3 - (double)(int)v4 + v5;
v5 = v2;
if ( verbose )
printf("rpc_hndlr1: returning d0 = %f\n", v2);
}
else
{
v5 = v6[0] - (double)(int)v3 - (double)(int)v4 + v5;
}
return srss_marshall(a1, "lf");
}

canonical_decompiled_code:
size_t __fastcall func1(__int64 a1)
{
double v2; // xmm0_8
unsigned int v3; // [rsp+8h] [rbp-20h] BYREF
unsigned int v4; // [rsp+Ch] [rbp-1Ch] BYREF
double v5; // [rsp+10h] [rbp-18h] BYREF
double v6[2]; // [rsp+18h] [rbp-10h] BYREF

if ( (unsigned int)srss_unmarshall(a1, "dlfdlf", &v3, &v5, &v4, v6) != 4 )
return fwrite("rpc_hndlr1: arg count wrong\n", 1uLL, 0x1CuLL, stderr);
if ( verbose )
{
puts("rpc_hndlr1: unmarshalled");
printf("i0 = %d\n", v3);
printf("i1 = %d\n", v4);
printf("d0 = %f\n", v5);
printf("d1 = %f\n", v6[0]);
v2 = v6[0] - (double)(int)v3 - (double)(int)v4 + v5;
v5 = v2;
if ( verbose )
printf("rpc_hndlr1: returning d0 = %f\n", v2);
}
else
{
v5 = v6[0] - (double)(int)v3 - (double)(int)v4 + v5;
}
return srss_marshall(a1, "lf");
}

original_code:
void rpc_hndlr1(struct srss_state *sp) {
 int i0, i1;
 double d0, d1;
 if (srss_unmarshall(sp,"dlfdlf",&i0,&d0,&i1,&d1) != 4) {
  fprintf(stderr,"rpc_hndlr1: arg count wrong\n");
  return;
 }
 if (verbose) {
  printf("rpc_hndlr1: unmarshalled\n");
  printf("i0 = %d\n",i0);
  printf("i1 = %d\n",i1);
  printf("d0 = %f\n",d0);
  printf("d1 = %f\n",d1);
 }
 d0 += d1 - i0 - i1;
 if (verbose) {
  printf("rpc_hndlr1: returning d0 = %f\n",d0);
 }
 srss_marshall(sp,"lf",d0);
}

canonical_original_code:
void rpc_hndlr1(struct srss_state *sp) {
 int i0; int i1;
 double d0; double d1;
 if (srss_unmarshall(sp,"dlfdlf",&i0,&d0,&i1,&d1) != 4) {
  fprintf(stderr,"rpc_hndlr1: arg count wrong\n");
  return;
 }
 if (verbose) {
  printf("rpc_hndlr1: unmarshalled\n");
  printf("i0 = %d\n",i0);
  printf("i1 = %d\n",i1);
  printf("d0 = %f\n",d0);
  printf("d1 = %f\n",d1);
 }
 d0 += d1 - i0 - i1;
 if (verbose) {
  printf("rpc_hndlr1: returning d0 = %f\n",d0);
 }
 srss_marshall(sp,"lf",d0);
}

user_defined_types: struct srss_entry { char *rpc_name; void (*rpc_handler)(struct srss_state *); }


decompiled_code:
__int64 __fastcall start_service(unsigned int a1)
{
srss_server_init(&ifc, 2LL, &entries, a1);
return srss_service(&ifc, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
srss_server_init(&ifc, 2LL, &entries, a1);
return srss_service(&ifc, 1LL);
}

original_code:
int start_service(int sock)
{
 srss_server_init(&ifc,sizeof entries/sizeof entries[0],entries,sock);
 return srss_service(&ifc,1);
}

variable_types: sock int

return_type: int


decompiled_code:
unsigned int __fastcall rpc_service(unsigned int a1)
{
unsigned int result; // eax
__pid_t v2; // eax

if ( verbose )
{
v2 = getpid();
fprintf(stderr, "child starting service, pid %lu\n", v2);
}
result = start_service(a1);
if ( verbose )
result = fprintf(stderr, "child service routine returned %d\n", result);
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func3(unsigned int a1)
{
unsigned int result; // eax
__pid_t v2; // eax

if ( verbose )
{
v2 = getpid();
fprintf(stderr, "child starting service, pid %lu\n", v2);
}
result = func2(a1);
if ( verbose )
result = fprintf(stderr, "child service routine returned %d\n", result);
return result;
}

original_code:
void rpc_service(int sock)
{
 int rv;
 if (verbose)
  fprintf(stderr,"child starting service, pid %lu\n",(unsigned long) getpid());
 rv = start_service(sock);
 if (verbose)
  fprintf(stderr,"child service routine returned %d\n",rv);
}

variable_types: rv int


parseDate

repo: behrat/fah-stats

decompiled_code:
char *__fastcall parseDate(const char *a1, struct tm *a2)
{
return strptime(a1, "%A%t%B %d %T PST %Y\n", a2);
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1, struct tm *a2)
{
return strptime(a1, "%A%t%B %d %T PST %Y\n", a2);
}

original_code:
char * parseDate(char* buffer, struct tm * time) {
 return strptime(buffer, "%A%t%B %d %T PST %Y\n", time);
}

canonical_original_code:
char *parseDate(char *buffer, struct tm *time) {
 return strptime(buffer, "%A%t%B %d %T PST %Y\n", time);
}

variable_types:
buffer
char *

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

return_type: char *


signalHandler

repo: bejayoharen/guitartuner

decompiled_code:
void signalHandler()
{
running = 0;
}

canonical_decompiled_code:
void func0()
{
running = 0;
}

original_code: void signalHandler( int signum ) { running = 0; }

canonical_original_code: void signalHandler(int signum) { running = 0; }

variable_types: signum int


buildHammingWindow

original_code:
void buildHammingWindow( float *window, int size )
{
   for( int i=0; i<size; ++i )
      window[i] = .54 - .46 * cos( 2 * 3.14159265358979323846 * i / (float) size );
}

canonical_original_code:
void buildHammingWindow(float *window, int size)
{
   for( int i = 0; i<size; ++i )
      window[i] = .54 - .46 * cos( 2 * 3.14159265358979323846 * i / (float) size );
}

variable_types:
window
float *

variable_types: size int

variable_types: i int


buildHanWindow

original_code:
void buildHanWindow( float *window, int size )
{
   for( int i=0; i<size; ++i )
      window[i] = .5 * ( 1 - cos( 2 * 3.14159265358979323846 * i / (size-1.0) ) );
}

canonical_original_code:
void buildHanWindow(float *window, int size)
{
   for( int i = 0; i<size; ++i )
      window[i] = .5 * ( 1 - cos( 2 * 3.14159265358979323846 * i / (size-1.0) ) );
}


applyWindow

original_code:
void applyWindow( float *window, float *data, int size )
{
   for( int i=0; i<size; ++i )
      data[i] *= window[i] ;
}

canonical_original_code:
void applyWindow(float *window, float *data, int size)
{
   for( int i = 0; i<size; ++i )
      data[i] *= window[i] ;
}

variable_types:
data
float *


computeSecondOrderLowPassParameters

original_code:
void computeSecondOrderLowPassParameters( float srate, float f, float *a, float *b )
{
   float a0;
   float w0 = 2 * 3.14159265358979323846 * f/srate;
   float cosw0 = cos(w0);
   float sinw0 = sin(w0);
   float alpha = sinw0/2 * sqrt(2);
   a0 = 1 + alpha;
   a[0] = (-2*cosw0) / a0;
   a[1] = (1 - alpha) / a0;
   b[0] = ((1-cosw0)/2) / a0;
   b[1] = ( 1-cosw0) / a0;
   b[2] = b[0];
}

canonical_original_code:
void computeSecondOrderLowPassParameters(float srate, float f, float *a, float *b)
{
   float a0;
   float w0 = 2 * 3.14159265358979323846 * f/srate;
   float cosw0 = cos(w0);
   float sinw0 = sin(w0);
   float alpha = sinw0/2 * sqrt(2);
   a0 = 1 + alpha;
   a[0] = (-2*cosw0) / a0;
   a[1] = (1 - alpha) / a0;
   b[0] = ((1-cosw0)/2) / a0;
   b[1] = ( 1-cosw0) / a0;
   b[2] = b[0];
}

variable_types: srate float

variable_types: f float

variable_types:
a
float *

variable_types:
b
float *

variable_types: alpha float


processSecondOrderFilter

decompiled_code:
void __fastcall processSecondOrderFilter(float *a1, float *a2, float *a3, float a4)
{
float v5; // xmm3_4
float v6; // xmm0_4
float v7; // xmm1_4

v5 = a1[2];
v6 = (float)((float)(a3[2] * a1[1]) + (float)((float)(*a3 * a4) + (float)(a3[1] * *a1))) - (float)(*a2 * v5);
v7 = a2[1] * a1[3];
a1[1] = *a1;
*a1 = a4;
a1[3] = v5;
a1[2] = v6 - v7;
}

original_code:
float processSecondOrderFilter( float x, float *mem, float *a, float *b )
{
    float ret = b[0] * x + b[1] * mem[0] + b[2] * mem[1]
                         - a[0] * mem[2] - a[1] * mem[3] ;
  mem[1] = mem[0];
  mem[0] = x;
  mem[3] = mem[2];
  mem[2] = ret;
  return ret;
}

canonical_original_code:
float processSecondOrderFilter(float x, float *mem, float *a, float *b)
{
    float ret = b[0] * x + b[1] * mem[0] + b[2] * mem[1]
                         - a[0] * mem[2] - a[1] * mem[3];
  mem[1] = mem[0];
  mem[0] = x;
  mem[3] = mem[2];
  mem[2] = ret;
  return ret;
}

variable_types: x float

variable_types:
mem
float *

variable_types: ret float

return_type: float


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
int *v4; // rdx
int v5; // eax
float v6; // xmm0_4
__int64 *v7; // rax
double v8; // xmm2_8
void *v9; // rcx
int v10; // er13
double v11; // xmm3_8
double v12; // xmm1_8
__int64 v13; // rax
int v14; // edx
__int64 v15; // xmm0_8
bool v16; // cc
double v17; // xmm0_8
unsigned int v18; // er13
__int64 v19; // rdi
const char *v20; // rax
unsigned int v22; // eax
__int64 v23; // rax
__int64 v24; // rax
__int64 v25; // rax
float *v26; // rax
float v27; // xmm0_4
__int64 v28; // rax
float *v29; // rdx
float v30; // xmm2_4
__int64 v31; // rax
int v32; // edx
float v33; // xmm1_4
float v34; // xmm1_4
int v35; // er15
float v36; // xmm2_4
__int64 *v37; // rdi
__int64 i; // rax
const char *v39; // rbp
int v40; // er14
__int64 v41; // rcx
float v42; // xmm4_4
int v43; // er13
int v44; // er14
float v45; // xmm0_4
int v46; // ebp
float v47; // [rsp+4h] [rbp-38144h]
__int64 v48; // [rsp+10h] [rbp-38138h] BYREF
float v49[2]; // [rsp+1Ch] [rbp-3812Ch] BYREF
float v50[3]; // [rsp+24h] [rbp-38124h] BYREF
__int64 v51[2]; // [rsp+30h] [rbp-38118h] BYREF
__int64 v52[2]; // [rsp+40h] [rbp-38108h] BYREF
int v53[2]; // [rsp+50h] [rbp-380F8h] BYREF
__int64 v54; // [rsp+58h] [rbp-380F0h]
__int64 v55; // [rsp+60h] [rbp-380E8h]
__int64 v56; // [rsp+68h] [rbp-380E0h]
struct sigaction v57; // [rsp+70h] [rbp-380D8h] BYREF
float v58[8192]; // [rsp+110h] [rbp-38038h] BYREF
float v59[8192]; // [rsp+8110h] [rbp-30038h] BYREF
char v60[32768]; // [rsp+10110h] [rbp-28038h] BYREF
float v61[8192]; // [rsp+18110h] [rbp-20038h] BYREF
float v62[8192]; // [rsp+20110h] [rbp-18038h] BYREF
__int64 s[8199]; // [rsp+28110h] [rbp-10038h] BYREF

v48 = 0LL;
v57.sa_handler = (__sighandler_t)signalHandler;
sigemptyset(&v57.sa_mask);
v57.sa_flags = 0;
sigaction(2, &v57, 0LL);
sigaction(1, &v57, 0LL);
sigaction(15, &v57, 0LL);
buildHanWindow((__int64)v60, 0x2000);
v3 = initfft(13LL);
computeSecondOrderLowPassParameters(v49, v50, 8000.0, 330.0);
v4 = (int *)v61;
v5 = 0;
v51[0] = 0LL;
v51[1] = 0LL;
v52[0] = 0LL;
v52[1] = 0LL;
do
{
++v4;
v6 = (float)v5;
v5 += 8000;
*((float *)v4 - 1) = v6 * 0.00012207031;
}
while ( v5 != 65536000 );
memset(s, 0, 0x10000uLL);
v7 = (__int64 *)v62;
do
{
*(_DWORD *)v7 = -1082130432;
v7 = (__int64 *)((char *)v7 + 4);
}
while ( v7 != s );
*(_QWORD *)&v8 = (unsigned int)LC10;
v9 = &unk_28F;
v10 = 0;
*(_QWORD *)&v11 = (unsigned int)LC21;
while ( 1 )
{
LODWORD(v12) = LC11;
v13 = 0LL;
v14 = -1;
do
{
v15 = LODWORD(v61[v13]);
*(float *)&v15 = *(float *)&v15 - *(float *)&v8;
*(_QWORD *)&v17 = v15 & *(_QWORD *)&v11;
v16 = *(float *)&v12 <= *(float *)&v17;
*(float *)&v17 = fminf(*(float *)&v17, *(float *)&v12);
if ( !v16 )
v14 = v13;
++v13;
v12 = v17;
}
while ( v13 != 0x2000 );
++v10;
s[v14] = (__int64)v9;
v62[v14] = *(float *)&v8;
if ( v10 == 127 )
break;
v12 = ((double)v10 - 9.0) / 12.0;
v17 = pow(2.0, v12) * 13.75;
HIDWORD(v8) = 0;
*(_QWORD *)&v11 = (unsigned int)LC21;
*(float *)&v8 = v17;
if ( *(float *)&v8 > 4000.0 )
break;
v9 = *(&NOTES + v10 % 0xCu);
}
v18 = Pa_Initialize(v17, v12, v8, v11);
if ( v18 )
goto LABEL_14;
v22 = Pa_GetDefaultInputDevice();
v53[1] = 1;
v53[0] = v22;
v54 = 1LL;
v23 = Pa_GetDeviceInfo(v22);
v56 = 0LL;
v55 = *(_QWORD *)(v23 + 48);
v24 = Pa_GetDeviceInfo((unsigned int)v53[0]);
LODWORD(v25) = printf("Opening %s\n", *(const char **)(v24 + 8));
v18 = Pa_OpenStream(&v48, v53, 0LL, 0x2000LL, 1LL, 0LL, 8000.0, 0LL, v25);
if ( v18 )
goto LABEL_14;
v18 = Pa_StartStream(v48);
if ( v18 )
goto LABEL_14;
while ( running )
{
v18 = Pa_ReadStream(v48, v58, 0x2000LL);
if ( v18 )
goto LABEL_14;
v26 = v58;
do
{
v27 = *v26;
processSecondOrderFilter((float *)v51, v49, v50, *v26);
*(float *)(v28 - 4) = v27;
processSecondOrderFilter((float *)v52, v49, v29, v27);
*(v26 - 1) = v27;
}
while ( v59 != v26 );
applyWindow((__int64)v60, (__int64)v58, 0x2000);
memset(v59, 0, sizeof(v59));
applyfft(v3, v58, v59, 0LL);
v30 = *(float *)&LC12;
v31 = 0LL;
v32 = -1;
do
{
v33 = (float)(v58[v31] * v58[v31]) + (float)(v59[v31] * v59[v31]);
v16 = v33 <= v30;
v34 = fmaxf(v33, v30);
if ( !v16 )
v32 = v31;
++v31;
v30 = v34;
v35 = v32;
}
while ( v31 != 4096 );
v36 = v61[v32];
v37 = &s[v32];
for ( i = 0LL; ; ++i )
{
v40 = i;
if ( v35 > (int)i )
{
v41 = v35 - (int)i;
v39 = (const char *)s[v41];
if ( v39 )
{
v40 = -(int)i;
goto LABEL_35;
}
}
if ( v32 <= 0x1FFF )
{
v39 = (const char *)v37[i];
if ( v39 )
break;
}
++v32;
}
v41 = v32;
LABEL_35:
v42 = log((float)(v36 / v62[v41])) * 1200.0 / 0.6931471805599453;
v47 = v42;
printf("\x1B[2J\x1B[1;1H");
fflush(stdout);
puts("Tuner listening. Control-C to exit.");
printf("%f Hz, %d : %f\n", v36, (unsigned int)v35, (float)(v34 * 1000.0));
printf("Nearest Note: %s\n", v39);
if ( !v40 )
{
puts("in tune!");
putchar(10);
LABEL_41:
v43 = 30;
do
{
putchar(32);
--v43;
}
while ( v43 );
printf(" %2s ", v39);
if ( !v40 )
goto LABEL_44;
goto LABEL_53;
}
if ( v47 > 0.0 )
printf("%f cents sharp.\n", v47);
if ( v47 < 0.0 )
printf("%f cents flat.\n", COERCE_FLOAT(LODWORD(v47) ^ LC33));
putchar(10);
if ( v47 >= 0.0 )
goto LABEL_41;
v44 = 0;
v45 = v47 + 30.0;
if ( (float)(v47 + 30.0) > 0.0 )
{
do
{
++v44;
putchar(32);
v45 = v47 + 30.0;
}
while ( (float)(v47 + 30.0) > (float)v44 );
}
if ( v45 < 0.0 || (v18 = (int)v45, (int)v45 <= 29) )
{
do
{
++v18;
putchar(61);
}
while ( v18 != 30 );
}
printf(" %2s ", v39);
LABEL_53:
if ( v47 > 0.0 )
{
v46 = 1;
putchar(61);
do
{
if ( v47 <= (float)v46 )
break;
++v46;
putchar(61);
}
while ( v46 != 30 );
}
LABEL_44:
putchar(10);
}
v18 = Pa_StopStream(v48);
if ( !v18 )
{
destroyfft(v3);
Pa_Terminate();
return v18;
}
LABEL_14:
if ( v48 )
{
Pa_AbortStream();
Pa_CloseStream(v48);
}
destroyfft(v3);
Pa_Terminate();
fwrite("An error occured while using the portaudio stream\n", 1uLL, 0x32uLL, stderr);
fprintf(stderr, "Error number: %d\n", v18);
v19 = v18;
v18 = 1;
v20 = (const char *)Pa_GetErrorText(v19);
fprintf(stderr, "Error message: %s\n", v20);
return v18;
}

original_code:
int main( int argc, char **argv ) {
   PaStreamParameters inputParameters;
   float a[2], b[3], mem1[4], mem2[4];
   float data[(8192)];
   float datai[(8192)];
   float window[(8192)];
   float freqTable[(8192)];
   char * noteNameTable[(8192)];
   float notePitchTable[(8192)];
   void * fft = ((void *)0);
   PaStream *stream = ((void *)0);
   PaError err = 0;
   struct sigaction action;
   action.__sigaction_handler.sa_handler = signalHandler;
   sigemptyset (&action.sa_mask);
   action.sa_flags = 0;
   sigaction (2, &action, ((void *)0));
   sigaction (1, &action, ((void *)0));
   sigaction (15, &action, ((void *)0));
   buildHanWindow( window, (8192) );
   fft = initfft( (13) );
   computeSecondOrderLowPassParameters( (8000), 330, a, b );
   mem1[0] = 0; mem1[1] = 0; mem1[2] = 0; mem1[3] = 0;
   mem2[0] = 0; mem2[1] = 0; mem2[2] = 0; mem2[3] = 0;
   for( int i=0; i<(8192); ++i ) {
      freqTable[i] = ( (8000) * i ) / (float) ( (8192) );
   }
   for( int i=0; i<(8192); ++i ) {
      noteNameTable[i] = ((void *)0);
      notePitchTable[i] = -1;
   }
   for( int i=0; i<127; ++i ) {
      float pitch = ( 440.0 / 32.0 ) * pow( 2, (i-9.0)/12.0 ) ;
      if( pitch > (8000) / 2.0 )
         break;
      float min = 1000000000.0;
      int index = -1;
      for( int j=0; j<(8192); ++j ) {
         if( fabsf( freqTable[j]-pitch ) < min ) {
             min = fabsf( freqTable[j]-pitch );
             index = j;
         }
      }
      noteNameTable[index] = NOTES[i%12];
      notePitchTable[index] = pitch;
   }
   err = Pa_Initialize();
   if( err != paNoError ) goto error;
   inputParameters.device = Pa_GetDefaultInputDevice();
   inputParameters.channelCount = 1;
   inputParameters.sampleFormat = ((PaSampleFormat) 0x00000001);
   inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultHighInputLatency ;
   inputParameters.hostApiSpecificStreamInfo = ((void *)0);
   printf( "Opening %s\n",
           Pa_GetDeviceInfo( inputParameters.device )->name );
   err = Pa_OpenStream( &stream,
                        &inputParameters,
                        ((void *)0),
                        (8000),
                        (8192),
                        ((PaStreamFlags) 0x00000001),
                        ((void *)0),
                        ((void *)0) );
   if( err != paNoError ) goto error;
   err = Pa_StartStream( stream );
   if( err != paNoError ) goto error;
   while( running )
   {
      err = Pa_ReadStream( stream, data, (8192) );
      if( err ) goto error;
      for( int j=0; j<(8192); ++j ) {
         data[j] = processSecondOrderFilter( data[j], mem1, a, b );
         data[j] = processSecondOrderFilter( data[j], mem2, a, b );
      }
      applyWindow( window, data, (8192) );
      for( int j=0; j<(8192); ++j )
         datai[j] = 0;
      applyfft( fft, data, datai, 0 );
      float maxVal = -1;
      int maxIndex = -1;
      for( int j=0; j<(8192)/2; ++j ) {
         float v = data[j] * data[j] + datai[j] * datai[j] ;
         if( v > maxVal ) {
            maxVal = v;
            maxIndex = j;
         }
      }
      float freq = freqTable[maxIndex];
      int nearestNoteDelta=0;
      while( 1 ) {
         if( nearestNoteDelta < maxIndex && noteNameTable[maxIndex-nearestNoteDelta] != ((void *)0) ) {
            nearestNoteDelta = -nearestNoteDelta;
            break;
         } else if( nearestNoteDelta + maxIndex < (8192) && noteNameTable[maxIndex+nearestNoteDelta] != ((void *)0) ) {
            break;
         }
         ++nearestNoteDelta;
      }
      char * nearestNoteName = noteNameTable[maxIndex+nearestNoteDelta];
      float nearestNotePitch = notePitchTable[maxIndex+nearestNoteDelta];
      float centsSharp = 1200 * log( freq / nearestNotePitch ) / log( 2.0 );
      printf("\033[2J\033[1;1H");
      fflush(stdout);
      printf( "Tuner listening. Control-C to exit.\n" );
      printf( "%f Hz, %d : %f\n", freq, maxIndex, maxVal*1000 );
      printf( "Nearest Note: %s\n", nearestNoteName );
      if( nearestNoteDelta != 0 ) {
         if( centsSharp > 0 )
            printf( "%f cents sharp.\n", centsSharp );
         if( centsSharp < 0 )
            printf( "%f cents flat.\n", -centsSharp );
      } else {
         printf( "in tune!\n" );
      }
      printf( "\n" );
      int chars = 30;
      if( nearestNoteDelta == 0 || centsSharp >= 0 ) {
         for( int i=0; i<chars; ++i )
            printf( " " );
      } else {
         for( int i=0; i<chars+centsSharp; ++i )
            printf( " " );
         for( int i=chars+centsSharp<0?0:chars+centsSharp; i<chars; ++i )
            printf( "=" );
      }
      printf( " %2s ", nearestNoteName );
      if( nearestNoteDelta != 0 )
         for( int i=0; i<chars && i<centsSharp; ++i )
           printf( "=" );
      printf("\n");
   }
   err = Pa_StopStream( stream );
   if( err != paNoError ) goto error;
   destroyfft( fft );
   Pa_Terminate();
   return 0;
 error:
   if( stream ) {
      Pa_AbortStream( stream );
      Pa_CloseStream( stream );
   }
   destroyfft( fft );
   Pa_Terminate();
   fprintf( stderr, "An error occured while using the portaudio stream\n" );
   fprintf( stderr, "Error number: %d\n", err );
   fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
   return 1;
}

canonical_original_code:
int main(int argc, char **argv) {
   struct PaStreamParameters inputParameters;
   float a[2]; float b[3]; float mem1[4]; float mem2[4];
   float data[-1];
   float datai[-1];
   float window[-1];
   float freqTable[-1];
   char *noteNameTable[-1];
   float notePitchTable[-1];
   void *fft = ((void *)0);
   void *stream = ((void *)0);
   int err = 0;
   struct sigaction action;
   action.__sigaction_handler.sa_handler = signalHandler;
   sigemptyset (&action.sa_mask);
   action.sa_flags = 0;
   sigaction (2, &action, ((void *)0));
   sigaction (1, &action, ((void *)0));
   sigaction (15, &action, ((void *)0));
   buildHanWindow( window, (8192) );
   fft = initfft( (13) );
   computeSecondOrderLowPassParameters( (8000), 330, a, b );
   mem1[0] = 0; mem1[1] = 0; mem1[2] = 0; mem1[3] = 0;
   mem2[0] = 0; mem2[1] = 0; mem2[2] = 0; mem2[3] = 0;
   for( int i = 0; i<(8192); ++i ) {
      freqTable[i] = ( (8000) * i ) / (float) ( (8192) );
   }
   for( int i = 0; i<(8192); ++i ) {
      noteNameTable[i] = ((void *)0);
      notePitchTable[i] = -1;
   }
   for( int i = 0; i<127; ++i ) {
      float pitch = ( 440.0 / 32.0 ) * pow( 2, (i-9.0)/12.0 );
      if( pitch > (8000) / 2.0 )
         break;
      float min = 1000000000.0;
      int index = -1;
      for( int j = 0; j<(8192); ++j ) {
         if( fabsf( freqTable[j]-pitch ) < min ) {
             min = fabsf( freqTable[j]-pitch );
             index = j;
         }
      }
      noteNameTable[index] = NOTES[i%12];
      notePitchTable[index] = pitch;
   }
   err = Pa_Initialize();
   if( err != paNoError ) goto error;
   inputParameters.device = Pa_GetDefaultInputDevice();
   inputParameters.channelCount = 1;
   inputParameters.sampleFormat = ((unsigned long) 0x00000001);
   inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultHighInputLatency ;
   inputParameters.hostApiSpecificStreamInfo = ((void *)0);
   printf( "Opening %s\n",
           Pa_GetDeviceInfo( inputParameters.device )->name );
   err = Pa_OpenStream( &stream,
                        &inputParameters,
                        ((void *)0),
                        (8000),
                        (8192),
                        ((unsigned long) 0x00000001),
                        ((void *)0),
                        ((void *)0) );
   if( err != paNoError ) goto error;
   err = Pa_StartStream( stream );
   if( err != paNoError ) goto error;
   while( running )
   {
      err = Pa_ReadStream( stream, data, (8192) );
      if( err ) goto error;
      for( int j = 0; j<(8192); ++j ) {
         data[j] = processSecondOrderFilter( data[j], mem1, a, b );
         data[j] = processSecondOrderFilter( data[j], mem2, a, b );
      }
      applyWindow( window, data, (8192) );
      for( int j = 0; j<(8192); ++j )
         datai[j] = 0;
      applyfft( fft, data, datai, 0 );
      float maxVal = -1;
      int maxIndex = -1;
      for( int j = 0; j<(8192)/2; ++j ) {
         float v = data[j] * data[j] + datai[j] * datai[j];
         if( v > maxVal ) {
            maxVal = v;
            maxIndex = j;
         }
      }
      float freq = freqTable[maxIndex];
      int nearestNoteDelta = 0;
      while( 1 ) {
         if( nearestNoteDelta < maxIndex && noteNameTable[maxIndex-nearestNoteDelta] != ((void *)0) ) {
            nearestNoteDelta = -nearestNoteDelta;
            break;
         } else if( nearestNoteDelta + maxIndex < (8192) && noteNameTable[maxIndex+nearestNoteDelta] != ((void *)0) ) {
            break;
         }
         ++nearestNoteDelta;
      }
      char *nearestNoteName = noteNameTable[maxIndex+nearestNoteDelta];
      float nearestNotePitch = notePitchTable[maxIndex+nearestNoteDelta];
      float centsSharp = 1200 * log( freq / nearestNotePitch ) / log( 2.0 );
      printf("\033[2J\033[1;1H");
      fflush(stdout);
      printf( "Tuner listening. Control-C to exit.\n" );
      printf( "%f Hz, %d : %f\n", freq, maxIndex, maxVal*1000 );
      printf( "Nearest Note: %s\n", nearestNoteName );
      if( nearestNoteDelta != 0 ) {
         if( centsSharp > 0 )
            printf( "%f cents sharp.\n", centsSharp );
         if( centsSharp < 0 )
            printf( "%f cents flat.\n", -centsSharp );
      } else {
         printf( "in tune!\n" );
      }
      printf( "\n" );
      int chars = 30;
      if( nearestNoteDelta == 0 || centsSharp >= 0 ) {
         for( int i = 0; i<chars; ++i )
            printf( " " );
      } else {
         for( int i = 0; i<chars+centsSharp; ++i )
            printf( " " );
         for( int i = chars+centsSharp<0?0:chars+centsSharp; i<chars; ++i )
            printf( "=" );
      }
      printf( " %2s ", nearestNoteName );
      if( nearestNoteDelta != 0 )
         for( int i = 0; i<chars && i<centsSharp; ++i )
           printf( "=" );
      printf("\n");
   }
   err = Pa_StopStream( stream );
   if( err != paNoError ) goto error;
   destroyfft( fft );
   Pa_Terminate();
   return 0;
 error:
   if( stream ) {
      Pa_AbortStream( stream );
      Pa_CloseStream( stream );
   }
   destroyfft( fft );
   Pa_Terminate();
   fprintf( stderr, "An error occured while using the portaudio stream\n" );
   fprintf( stderr, "Error number: %d\n", err );
   fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
   return 1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct PaStreamParameters { int device; int channelCount; unsigned long sampleFormat; double suggestedLatency; void *hostApiSpecificStreamInfo; }

variable_types:
a
float [2]

variable_types:
b
float [3]

variable_types:
data
float [-1]

variable_types:
datai
float [-1]

variable_types:
window
float [-1]

variable_types:
freqTable
float [-1]

variable_types:
noteNameTable
char *[-1]

variable_types:
notePitchTable
float [-1]

variable_types:
fft
void *

variable_types:
stream
void *

variable_types: err int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: pitch float

variable_types: min float

variable_types: index int

variable_types: j int

variable_types: maxVal float

variable_types: maxIndex int

variable_types: v float

variable_types: freq float

variable_types: nearestNoteDelta int

variable_types:
nearestNoteName
char *

variable_types: nearestNotePitch float

variable_types: centsSharp float

variable_types: chars int

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


destroyfft

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

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

original_code:
void destroyfft( void *fft ) {
    free( fft );
}

canonical_original_code:
void destroyfft(void *fft) {
    free( fft );
}

variable_types:
fft
void *


applyfft

original_code:
void applyfft( void * fft, float *xr, float *xi, _Bool inv ) {
    int n, n2, i, k, kn2, l, p;
    float ang, s, c, tr, ti;
    struct fft_s *mfft = (struct fft_s *) fft ;
    n = 1 << mfft->bits;
    n2 = n / 2;
    for ( l = 0; l < mfft->bits; ++l ) {
        for ( k = 0; k < n; k += n2 ) {
            for( i = 0; i < n2; ++i, ++k ) {
                p = mfft->bitreverse[k / n2];
                ang = 6.283185 * p / n;
                c = cos( ang );
                s = sin( ang );
                kn2 = k + n2;
                if ( inv )
                    s = -s;
                tr = xr[kn2] * c + xi[kn2] * s;
                ti = xi[kn2] * c - xr[kn2] * s;
                xr[kn2] = xr[k] - tr;
                xi[kn2] = xi[k] - ti;
                xr[k] += tr;
                xi[k] += ti;
            }
        }
        n2 /= 2;
    }
    for ( k = 0; k < n; ++k ) {
        i = mfft->bitreverse[k];
        if ( i <= k )
            continue;
        tr = xr[k];
        ti = xi[k];
        xr[k] = xr[i];
        xi[k] = xi[i];
        xr[i] = tr;
        xi[i] = ti;
    }
    if ( ! inv ) {
        float f;
        f = 1.0 / n;
        for( i = 0; i < n ; ++i ) {
            xr[i] *= f;
            xi[i] *= f;
        }
    }
}

canonical_original_code:
void applyfft(void *fft, float *xr, float *xi, _Bool inv) {
    int n; int n2; int i; int k; int kn2; int l; int p;
    float ang; float s; float c; float tr; float ti;
    struct fft_s *mfft = (struct fft_s *) fft;
    n = 1 << mfft->bits;
    n2 = n / 2;
    for ( l = 0; l < mfft->bits; ++l ) {
        for ( k = 0; k < n; k += n2 ) {
            for( i = 0; i < n2; ++i, ++k ) {
                p = mfft->bitreverse[k / n2];
                ang = 6.283185 * p / n;
                c = cos( ang );
                s = sin( ang );
                kn2 = k + n2;
                if ( inv )
                    s = -s;
                tr = xr[kn2] * c + xi[kn2] * s;
                ti = xi[kn2] * c - xr[kn2] * s;
                xr[kn2] = xr[k] - tr;
                xi[kn2] = xi[k] - ti;
                xr[k] += tr;
                xi[k] += ti;
            }
        }
        n2 /= 2;
    }
    for ( k = 0; k < n; ++k ) {
        i = mfft->bitreverse[k];
        if ( i <= k )
            continue;
        tr = xr[k];
        ti = xi[k];
        xr[k] = xr[i];
        xi[k] = xi[i];
        xr[i] = tr;
        xi[i] = ti;
    }
    if ( ! inv ) {
        float f;
        f = 1.0 / n;
        for( i = 0; i < n ; ++i ) {
            xr[i] *= f;
            xi[i] *= f;
        }
    }
}

variable_types:
xr
float *

variable_types:
xi
float *

variable_types: n int

variable_types: i int

variable_types: k int

variable_types: l int

variable_types: p int

variable_types: ang float

variable_types: s float

variable_types: c float

variable_types: tr float

variable_types: ti float

variable_types: struct fft_s { int bitreverse[32768]; int bits; } *

variable_types: f float


main

repo: bekars/NginB

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

if ( (unsigned int)(argc - 2) <= 2 )
{
v3 = argv[1];
if ( argc == 3 )
{
cache_header_show(argv[1], 0LL, envp);
cache_header_expired_modify(argv[2], &cache_header);
update_cache_file(argv[1], &cache_header);
v3 = argv[1];
}
else if ( argc == 4 )
{
cache_header_show(argv[1], 0LL, envp);
cache_header_expired_modify(argv[2], &cache_header);
cache_header_bodyoffset_modify(argv[3], &cache_header);
update_cache_file(argv[1], &cache_header);
v3 = argv[1];
}
cache_header_show(v3, 1LL, envp);
exit(0);
}
printf("Usage: %s <cache_file_name> +<expired_seconds(optinal)> <body_offset>\n", *argv);
exit(-1);
}

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

if ( (unsigned int)(argc - 2) <= 2 )
{
v3 = argv[1];
if ( argc == 3 )
{
func8(argv[1], 0LL, envp);
func10(argv[2], &cache_header);
func11(argv[1], &cache_header);
v3 = argv[1];
}
else if ( argc == 4 )
{
func8(argv[1], 0LL, envp);
func10(argv[2], &cache_header);
func9(argv[3], &cache_header);
func11(argv[1], &cache_header);
v3 = argv[1];
}
func8(v3, 1LL, envp);
exit(0);
}
printf("Usage: %s <cache_file_name> +<expired_seconds(optinal)> <body_offset>\n", *argv);
exit(-1);
}

original_code:
int
main(int argc, char **argv)
{
    if ((argc < 2) || (argc > 4)) {
        printf("Usage: %s <cache_file_name> +<expired_seconds(optinal)> <body_offset>\n", argv[0]);
        exit(-1);
    }
    if (argc == 3) {
        cache_header_show(argv[1], 0);
        cache_header_expired_modify(argv[2], &cache_header);
        update_cache_file(argv[1], &cache_header);
    }
    if (argc == 4) {
        cache_header_show(argv[1], 0);
        cache_header_expired_modify(argv[2], &cache_header);
        cache_header_bodyoffset_modify(argv[3], &cache_header);
        update_cache_file(argv[1], &cache_header);
    }
    cache_header_show(argv[1], 1);
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
int __fastcall cache_header_dump(__int64 a1)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax

v1 = ctime((const time_t *)a1);
printf("valid: %s", v1);
v2 = ctime((const time_t *)(a1 + 8));
printf("last_modify: %s", v2);
v3 = ctime((const time_t *)(a1 + 16));
printf("date: %s", v3);
printf("crc32: %x\n", *(unsigned int *)(a1 + 24));
printf("msec: %d\n", *(unsigned __int16 *)(a1 + 28));
printf("header: %d\n", *(unsigned __int16 *)(a1 + 30));
return printf("body: %d\n", *(unsigned __int16 *)(a1 + 32));
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax

v1 = ctime((const time_t *)a1);
printf("valid: %s", v1);
v2 = ctime((const time_t *)(a1 + 8));
printf("last_modify: %s", v2);
v3 = ctime((const time_t *)(a1 + 16));
printf("date: %s", v3);
printf("crc32: %x\n", *(unsigned int *)(a1 + 24));
printf("msec: %d\n", *(unsigned __int16 *)(a1 + 28));
printf("header: %d\n", *(unsigned __int16 *)(a1 + 30));
return printf("body: %d\n", *(unsigned __int16 *)(a1 + 32));
}

original_code:
void
cache_header_dump(ngx_http_file_cache_header_t *cache_header)
{
    printf("valid: %s", ctime(&cache_header->valid_sec));
    printf("last_modify: %s", ctime(&cache_header->last_modified));
    printf("date: %s", ctime(&cache_header->date));
    printf("crc32: %x\n", cache_header->crc32);
    printf("msec: %d\n", cache_header->valid_msec);
    printf("header: %d\n", cache_header->header_start);
    printf("body: %d\n", cache_header->body_start);
}

canonical_original_code:
void cache_header_dump(struct ngx_http_file_cache_header_t *cache_header)
{
    printf("valid: %s", ctime(&cache_header->valid_sec));
    printf("last_modify: %s", ctime(&cache_header->last_modified));
    printf("date: %s", ctime(&cache_header->date));
    printf("crc32: %x\n", cache_header->crc32);
    printf("msec: %d\n", cache_header->valid_msec);
    printf("header: %d\n", cache_header->header_start);
    printf("body: %d\n", cache_header->body_start);
}

variable_types: struct ngx_http_file_cache_header_t { long valid_sec; long last_modified; long date; unsigned int crc32; unsigned short valid_msec; unsigned short header_start; unsigned short body_start; } *


decompiled_code:
__int64 __fastcall cache_header_bodyoffset_modify(const char *a1, __int64 a2)
{
*(_WORD *)(a2 + 32) = atoi(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, __int64 a2)
{
*(_WORD *)(a2 + 32) = atoi(a1);
return 0LL;
}

original_code:
int
cache_header_bodyoffset_modify(char *bodyoffset, ngx_http_file_cache_header_t *cache_header)
{
    cache_header->body_start = atoi(bodyoffset);
    return 0;
}

canonical_original_code:
int cache_header_bodyoffset_modify(char *bodyoffset, struct ngx_http_file_cache_header_t *cache_header)
{
    cache_header->body_start = atoi(bodyoffset);
    return 0;
}

variable_types:
bodyoffset
char *

user_defined_types: struct ngx_http_file_cache_header_t { long valid_sec; long last_modified; long date; unsigned int crc32; unsigned short valid_msec; unsigned short header_start; unsigned short body_start; }


decompiled_code:
__int64 __fastcall cache_header_expired_modify(const char *a1, _QWORD *a2)
{
__int64 result; // rax
char v3; // [rsp+Bh] [rbp-1Dh] BYREF
unsigned int v4; // [rsp+Ch] [rbp-1Ch] BYREF

if ( sscanf(a1, "%c%d", &v3, &v4) == 2 )
{
printf("add %c%d secs to expired...\n", (unsigned int)v3, v4);
if ( v3 == 43 )
*a2 += (int)v4;
else
*a2 -= (int)v4;
result = 0LL;
}
else
{
printf("arg %s error!\n", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, _QWORD *a2)
{
__int64 result; // rax
char v3; // [rsp+Bh] [rbp-1Dh] BYREF
unsigned int v4; // [rsp+Ch] [rbp-1Ch] BYREF

if ( sscanf(a1, "%c%d", &v3, &v4) == 2 )
{
printf("add %c%d secs to expired...\n", (unsigned int)v3, v4);
if ( v3 == 43 )
*a2 += (int)v4;
else
*a2 -= (int)v4;
result = 0LL;
}
else
{
printf("arg %s error!\n", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
cache_header_expired_modify(char *expired, ngx_http_file_cache_header_t *cache_header)
{
    int secs;
    char ope;
    if (sscanf(expired, "%c%d", &ope, &secs) != 2) {
        printf("arg %s error!\n", expired);
        return -1;
    }
    printf("add %c%d secs to expired...\n", ope, secs);
    if (ope == '+') {
        cache_header->valid_sec += secs;
    } else {
        cache_header->valid_sec -= secs;
    }
    return 0;
}

canonical_original_code:
int cache_header_expired_modify(char *expired, struct ngx_http_file_cache_header_t *cache_header)
{
    int secs;
    char ope;
    if (sscanf(expired, "%c%d", &ope, &secs) != 2) {
        printf("arg %s error!\n", expired);
        return -1;
    }
    printf("add %c%d secs to expired...\n", ope, secs);
    if (ope == '+') {
        cache_header->valid_sec += secs;
    } else {
        cache_header->valid_sec -= secs;
    }
    return 0;
}

variable_types:
expired
char *

variable_types: secs int

variable_types: ope char


isPrime

decompiled_code:
__int64 __fastcall isPrime(__int64 a1)
{
__int64 v1; // rcx

if ( a1 <= 2 )
return 1LL;
if ( (a1 & 1) != 0 )
{
v1 = 2LL;
while ( a1 != ++v1 )
{
if ( !(a1 % v1) )
return 0LL;
}
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rcx

if ( a1 <= 2 )
return 1LL;
if ( (a1 & 1) != 0 )
{
v1 = 2LL;
while ( a1 != ++v1 )
{
if ( !(a1 % v1) )
return 0LL;
}
return 1LL;
}
return 0LL;
}

original_code:
int isPrime(long x) {
    long i = 0;
    for(i = 2; i < x; i++) {
        if((x % i) == 0)return 0;
    }
    return 1;
}

variable_types: x long

variable_types: i long


totient

original_code:
long totient( long n) {
    long *primeList = ( long *)malloc(n * sizeof( long));
    primeList[0] = 2;
    long j = 0;
    long p;
    long q;
    long index = 1;
    long i = 2;
    for(i = 3; i < n; i +=2) {
        if(isPrime(i) == 1) {
            primeList[index] = i;
            index++;
        }
    }
    for(i = 0; i < index; i++) {
        for (j = 0 ; j <index; j++) {
            if(primeList[i] * primeList[j] == n) {
                p = primeList[i];
                q = primeList[j];
                free(primeList);
                return (p - 1) * (q - 1);
            }
        }
    }
    free(primeList);
    return -1;
}

canonical_original_code:
long totient(long n) {
    long *primeList = ( long *)malloc(n * sizeof( long));
    primeList[0] = 2;
    long j = 0;
    long p;
    long q;
    long index = 1;
    long i = 2;
    for(i = 3; i < n; i +=2) {
        if(isPrime(i) == 1) {
            primeList[index] = i;
            index++;
        }
    }
    for(i = 0; i < index; i++) {
        for (j = 0 ; j <index; j++) {
            if(primeList[i] * primeList[j] == n) {
                p = primeList[i];
                q = primeList[j];
                free(primeList);
                return (p - 1) * (q - 1);
            }
        }
    }
    free(primeList);
    return -1;
}

variable_types: n long

variable_types:
primeList
long *

variable_types: j long

variable_types: p long

variable_types: q long

variable_types: index long

return_type: long


getM

original_code:
long getM(long a, long b) {
  return (a - 1) * (b - 1);
}

variable_types: a long

variable_types: b long


gcd

original_code:
long gcd(long a, long b) {
  long remainder = 0;
  if((a != 0) && (b != 0)) {
    if(a < b) {
      long temp = a;
      a = b;
      b = temp;
    }
    while(a % b > 0) {
      remainder = a % b;
      a = b;
      b = remainder;
    }
  } else {
    return 0;
  }
  return b;
}

variable_types: remainder long

variable_types: temp long


modulo

original_code:
long modulo(long a, long b, long c) {
  long solution = 1;
  long length = 0;
  while(b > 0) {
    long index = b % 2;
    if(index == 1) {
      b = (b - 1) / 2;
    } else {
      b = b / 2;
    }
    if(index == 1) {
      long term = (long)a;
      long counter = 1;
      while(counter <= length) {
 if(length != 0) {
   term = (term * term) % c;
 }
 counter += 1;
      }
      solution = (solution * term) % c;
    }
    length++;
  }
  if(solution < 0) {
    solution = solution + c;
  }
  return solution;
}

variable_types: c long

variable_types: solution long

variable_types: length long

variable_types: term long

variable_types: counter long


coprime

original_code:
long coprime(long x) {
  long value = rand() % x;
  while((gcd(value, x) != 1) || (value < 0)) {
    value++;
  }
  return value;
}

variable_types: x long

variable_types: value long


encrypt

decompiled_code:
// attributes: thunk
__int64 __fastcall encrypt(__int64 a1, __int64 a2, __int64 a3)
{
return modulo(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, __int64 a3)
{
return func12(a1, a2, a3);
}

original_code:
long encrypt(long msg, long key, long c) {
  return modulo(msg, key, c);
}

variable_types: msg long

variable_types: key long


decrypt

decompiled_code:
__int64 __fastcall decrypt(__int64 a1, __int64 a2, int a3)
{
return modulo(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, int a3)
{
return func12(a1, a2, a3);
}

original_code:
char decrypt(long msg, long key, int c) {
    return modulo(msg, key, c);
}

variable_types: c int

return_type: char


original_code:
long mod_inverse(long base, long m) {
  long mod = m;
  if(gcd(base, m) != 1) {
    return 0;
  }
  long preA = 1, preB = 0;
  long quotient[1000];
  long remainder = 0, counter = 0, A = 0, B = 0;
  while(base % m != 0) {
    remainder = base % m;
    base = m;
    m = remainder;
    quotient[counter] = base / m;
    counter++;
  }
  if(counter > 2) {
    while(counter >= 0) {
      B = preA;
      A = preB - quotient[counter] * preA;
      preB = B;
      preA = A;
      counter--;
    }
  } else {
    return 0;
  }
  if(A % mod < 0) {
    return A % mod + mod;
  }
  return A % mod;
}

canonical_original_code:
long mod_inverse(long base, long m) {
  long mod = m;
  if(gcd(base, m) != 1) {
    return 0;
  }
  long preA = 1; long preB = 0;
  long quotient[1000];
  long remainder = 0; long counter = 0; long A = 0; long B = 0;
  while(base % m != 0) {
    remainder = base % m;
    base = m;
    m = remainder;
    quotient[counter] = base / m;
    counter++;
  }
  if(counter > 2) {
    while(counter >= 0) {
      B = preA;
      A = preB - quotient[counter] * preA;
      preB = B;
      preA = A;
      counter--;
    }
  } else {
    return 0;
  }
  if(A % mod < 0) {
    return A % mod + mod;
  }
  return A % mod;
}

variable_types: base long

variable_types: m long

variable_types: mod long

variable_types: preA long

variable_types: preB long

variable_types:
quotient
long [1000]

variable_types: A long

variable_types: B long


generateKeys

decompiled_code:
unsigned __int64 __fastcall generateKeys(__int64 a1, __int64 a2, __int64 *a3, __int64 *a4, _QWORD *a5)
{
__int64 i; // rbx
__int64 v9; // rax
unsigned __int64 result; // rax

for ( i = (a2 - 1) * (a1 - 1); ; *a4 = mod_inverse(v9, i) )
{
if ( (unsigned __int64)(*a5 - 2LL) <= 0x270E && (unsigned __int64)(*a3 - 2) <= 0x270E )
{
result = *a4 - 2;
if ( result <= 0x270E )
break;
}
*a5 = a2 * a1;
v9 = coprime(i);
*a3 = v9;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func17(__int64 a1, __int64 a2, __int64 *a3, __int64 *a4, _QWORD *a5)
{
__int64 i; // rbx
__int64 v9; // rax
unsigned __int64 result; // rax

for ( i = (a2 - 1) * (a1 - 1); ; *a4 = func16(v9, i) )
{
if ( (unsigned __int64)(*a5 - 2LL) <= 0x270E && (unsigned __int64)(*a3 - 2) <= 0x270E )
{
result = *a4 - 2;
if ( result <= 0x270E )
break;
}
*a5 = a2 * a1;
v9 = func13(i);
*a3 = v9;
}
return result;
}

variable_types: a long

variable_types: b long

variable_types:
e
long *

variable_types:
d
long *

variable_types:
c
long *


repo: bemk/AVL

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

if ( !a1 )
return 0LL;
result = tree_find_leftmost(*(_QWORD *)(a1 + 8));
if ( !result )
result = a1;
return result;
}

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

if ( !a1 )
return 0LL;
result = func0(*(_QWORD *)(a1 + 8));
if ( !result )
result = a1;
return result;
}

original_code:
static struct tree* tree_find_leftmost(struct tree* tree)
{
        if (tree == ((void *)0))
                return ((void *)0);
        struct tree* tmp = tree_find_leftmost(tree->left);
        if (tmp == ((void *)0))
                return tree;
        return tmp;
}

canonical_original_code:
static struct tree *tree_find_leftmost(struct tree *tree)
{
        if (tree == ((void *)0))
                return ((void *)0);
        struct tree *tmp = tree_find_leftmost(tree->left);
        if (tmp == ((void *)0))
                return tree;
        return tmp;
}

variable_types:
tree
struct tree *

variable_types: struct tree { struct tree *parent; struct tree *left; struct tree *right; struct tree_root { struct tree *tree; unsigned int nodes; struct tree *(*add)(int key, void *data, struct tree_root *root); void *(*find)(int key, struct tree_root *root); int (*delete)(int, struct tree_root *, int (*dtor)(void *, void *), void *); int (*flush)(struct tree_root *, int (*dtor)(void *, void *), void *); union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *root; struct tree *next; struct tree *prev; int rdepth; int ldepth; int key; void *data; } *

user_defined_types: struct tree { struct tree *parent; struct tree *left; struct tree *right; struct tree_root *root; struct tree *next; struct tree *prev; int rdepth; int ldepth; int key; void *data; }

user_defined_types: struct tree_root { struct tree *tree; unsigned int nodes; struct tree *(*add)(int key, void *data, struct tree_root *root); void *(*find)(int key, struct tree_root *root); int (*delete)(int, struct tree_root *, int (*dtor)(void *, void *), void *); int (*flush)(struct tree_root *, int (*dtor)(void *, void *), void *); union pthread_mutex_t mutex; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


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

if ( !a1 )
return 0LL;
result = tree_find_rightmost(*(_QWORD *)(a1 + 16));
if ( !result )
result = a1;
return result;
}

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

if ( !a1 )
return 0LL;
result = func1(*(_QWORD *)(a1 + 16));
if ( !result )
result = a1;
return result;
}

original_code:
static struct tree* tree_find_rightmost(struct tree* tree)
{
        if (tree == ((void *)0))
                return ((void *)0);
        struct tree* tmp = tree_find_rightmost(tree->right);
        if (tmp == ((void *)0))
                return tree;
        return tmp;
}

canonical_original_code:
static struct tree *tree_find_rightmost(struct tree *tree)
{
        if (tree == ((void *)0))
                return ((void *)0);
        struct tree *tmp = tree_find_rightmost(tree->right);
        if (tmp == ((void *)0))
                return tree;
        return tmp;
}

return_type: struct tree { struct tree *parent; struct tree *left; struct tree *right; struct tree_root { struct tree *tree; unsigned int nodes; struct tree *(*add)(int key, void *data, struct tree_root *root); void *(*find)(int key, struct tree_root *root); int (*delete)(int, struct tree_root *, int (*dtor)(void *, void *), void *); int (*flush)(struct tree_root *, int (*dtor)(void *, void *), void *); union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *root; struct tree *next; struct tree *prev; int rdepth; int ldepth; int key; void *data; } *


original_code:
static struct tree* tree_find_node(int key, struct tree* tree)
{
        if (tree == ((void *)0))
                return ((void *)0);
        if (tree->key == key)
                return tree;
        if (key < tree->key)
                return tree_find_node(key, tree->left);
        else
                return tree_find_node(key, tree->right);
}

canonical_original_code:
static struct tree *tree_find_node(int key, struct tree *tree)
{
        if (tree == ((void *)0))
                return ((void *)0);
        if (tree->key == key)
                return tree;
        if (key < tree->key)
                return tree_find_node(key, tree->left);
        else
                return tree_find_node(key, tree->right);
}

variable_types: key int

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall tree_find(int a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r12

if ( !a2 )
return 0LL;
pthread_mutex_lock((pthread_mutex_t *)(a2 + 48));
v2 = tree_find_node(a1, *(_QWORD *)a2);
v3 = v2;
if ( v2 )
v3 = *(_QWORD *)(v2 + 64);
pthread_mutex_unlock((pthread_mutex_t *)(a2 + 48));
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r12

if ( !a2 )
return 0LL;
pthread_mutex_lock((pthread_mutex_t *)(a2 + 48));
v2 = func2(a1, *(_QWORD *)a2);
v3 = v2;
if ( v2 )
v3 = *(_QWORD *)(v2 + 64);
pthread_mutex_unlock((pthread_mutex_t *)(a2 + 48));
return v3;
}

original_code:
static void* tree_find(int key, struct tree_root* t)
{
        if (t == ((void *)0))
                return ((void *)0);
        void* ret = ((void *)0);
        pthread_mutex_lock(&t->mutex);
        struct tree* node = tree_find_node(key, t->tree);
        if (node == ((void *)0))
                goto err;
        ret = node->data;
err:
        pthread_mutex_unlock(&t->mutex);
        return ret;
}

canonical_original_code:
static void *tree_find(int key, struct tree_root *t)
{
        if (t == ((void *)0))
                return ((void *)0);
        void *ret = ((void *)0);
        pthread_mutex_lock(&t->mutex);
        struct tree *node = tree_find_node(key, t->tree);
        if (node == ((void *)0))
                goto err;
        ret = node->data;
err:
        pthread_mutex_unlock(&t->mutex);
        return ret;
}

variable_types: struct tree_root { struct tree { struct tree *parent; struct tree *left; struct tree *right; struct tree_root *root; struct tree *next; struct tree *prev; int rdepth; int ldepth; int key; void *data; } *tree; unsigned int nodes; struct tree *(*add)(int key, void *data, struct tree_root *root); void *(*find)(int key, struct tree_root *root); int (*delete)(int, struct tree_root *, int (*dtor)(void *, void *), void *); int (*flush)(struct tree_root *, int (*dtor)(void *, void *), void *); union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *

variable_types:
ret
void *

return_type: void *


cleanup

decompiled_code:
__int64 __fastcall cleanup(void *a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
free(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
free(a1);
return 0LL;
}

original_code:
static int cleanup(void* ptr, void* args)
{
        if (ptr == ((void *)0))
                return -1;
        free(ptr);
        return 0;
}

canonical_original_code:
static int cleanup(void *ptr, void *args)
{
        if (ptr == ((void *)0))
                return -1;
        free(ptr);
        return 0;
}

variable_types:
ptr
void *

variable_types:
args
void *


decompiled_code:
__int64 __fastcall tree_flush(void *ptr, void (__fastcall *a2)(_QWORD, __int64), __int64 a3)
{
if ( !ptr )
return 0xFFFFFFFFLL;
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 48));
tree_flush_node_isra_0(*(void **)ptr, a2, a3);
pthread_mutex_unlock((pthread_mutex_t *)((char *)ptr + 48));
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 48));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *ptr, void (__fastcall *a2)(_QWORD, __int64), __int64 a3)
{
if ( !ptr )
return 0xFFFFFFFFLL;
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 48));
func6(*(void **)ptr, a2, a3);
pthread_mutex_unlock((pthread_mutex_t *)((char *)ptr + 48));
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 48));
free(ptr);
return 0LL;
}

original_code:
int tree_flush(struct tree_root* root, int(*dtor)(void*,void*), void* dtor_args)
{
        if (root == ((void *)0))
                return -1;
        pthread_mutex_lock(&root->mutex);
        tree_flush_node(root->tree, dtor, dtor_args);
        pthread_mutex_unlock(&root->mutex);
        pthread_mutex_destroy(&root->mutex);
        memset(root, 0, sizeof(*root));
        free(root);
        return 0;
}

canonical_original_code:
int tree_flush(struct tree_root *root, int (*dtor)(void *, void *), void *dtor_args)
{
        if (root == ((void *)0))
                return -1;
        pthread_mutex_lock(&root->mutex);
        tree_flush_node(root->tree, dtor, dtor_args);
        pthread_mutex_unlock(&root->mutex);
        pthread_mutex_destroy(&root->mutex);
        memset(root, 0, sizeof(*root));
        free(root);
        return 0;
}

variable_types:
dtor
int (*)(void *, void *)


original_code:
static int
tree_delete_node(int key, struct tree* tree, int(*dtor)(void*, void*), void* dtor_args)
{
        if (tree == ((void *)0))
                return -1;
        struct tree* t = tree;
        if (tree->key != key)
        {
                if (key < tree->key)
                {
                        key = tree_delete_node(key, tree->left, dtor, dtor_args);
                        tree_depth(tree);
                        return key;
                }
                else
                {
                        key = tree_delete_node(key, tree->right, dtor, dtor_args);
                        tree_depth(tree);
                        return key;
                }
        }
        printf("Found the damn basterd!\n");
        if (t == ((void *)0))
                return -3;
        if (t->ldepth == 0 && t->rdepth == 0)
        {
                if (t->key < t->parent->key)
                        t->parent->left = ((void *)0);
                else
                        t->parent->right = ((void *)0);
        }
        else if (t->right == ((void *)0) && t->left != ((void *)0))
        {
                if (t->key < t->parent->key)
                        t->parent->left = t->left;
                else
                        t->parent->right = t->left;
                t->left->parent = t->parent;
        }
        else if (t->right != ((void *)0) && t->left == ((void *)0))
        {
                if (t->key < t->parent->key)
                        t->parent->left = t->right;
                else
                        t->parent->right = t->right;
                t->right->parent = t->parent;
        }
        else
        {
                struct tree* successor = tree_find_leftmost(t->right);
                if (successor == ((void *)0))
                        return -1;
                struct tree* walker = successor->parent;
                successor->parent->left = successor->right;
                if (successor->right != ((void *)0))
                        successor->right->parent = successor->parent;
                tree_depth(successor->parent);
                successor->parent = t->parent;
                if (t->right == successor)
                        successor->right = ((void *)0);
                else
                        successor->right = t->right;
                successor->left = t->left;
                if (successor->parent == ((void *)0))
                        successor->root->tree = successor;
                else if (successor->key < successor->parent->key)
                        successor->parent->left = successor;
                else
                        successor->parent->right = successor;
                if (successor->right != ((void *)0))
                        successor->right->parent = successor;
                successor->left->parent = successor;
                tree_depth(successor);
                tree_depth(successor->parent);
                if (walker != t)
                {
                        while(walker != ((void *)0) && walker != successor)
                        {
                                tree_depth(walker);
                                tree_balance(walker);
                                walker = walker->parent;
                        }
                }
        }
        tree_update_list(t->prev);
        tree_update_list(t->next);
        tree_depth(t->parent);
        tree_balance(t->parent);
        t->root->nodes--;
        if (dtor != ((void *)0))
                dtor(t->data, dtor_args);
        memset(t, 0, sizeof(*t));
        free(t);
        return 0;
}

canonical_original_code:
static int tree_delete_node(int key, struct tree *tree, int (*dtor)(void *, void *), void *dtor_args)
{
        if (tree == ((void *)0))
                return -1;
        struct tree *t = tree;
        if (tree->key != key)
        {
                if (key < tree->key)
                {
                        key = tree_delete_node(key, tree->left, dtor, dtor_args);
                        tree_depth(tree);
                        return key;
                }
                else
                {
                        key = tree_delete_node(key, tree->right, dtor, dtor_args);
                        tree_depth(tree);
                        return key;
                }
        }
        printf("Found the damn basterd!\n");
        if (t == ((void *)0))
                return -3;
        if (t->ldepth == 0 && t->rdepth == 0)
        {
                if (t->key < t->parent->key)
                        t->parent->left = ((void *)0);
                else
                        t->parent->right = ((void *)0);
        }
        else if (t->right == ((void *)0) && t->left != ((void *)0))
        {
                if (t->key < t->parent->key)
                        t->parent->left = t->left;
                else
                        t->parent->right = t->left;
                t->left->parent = t->parent;
        }
        else if (t->right != ((void *)0) && t->left == ((void *)0))
        {
                if (t->key < t->parent->key)
                        t->parent->left = t->right;
                else
                        t->parent->right = t->right;
                t->right->parent = t->parent;
        }
        else
        {
                struct tree *successor = tree_find_leftmost(t->right);
                if (successor == ((void *)0))
                        return -1;
                struct tree *walker = successor->parent;
                successor->parent->left = successor->right;
                if (successor->right != ((void *)0))
                        successor->right->parent = successor->parent;
                tree_depth(successor->parent);
                successor->parent = t->parent;
                if (t->right == successor)
                        successor->right = ((void *)0);
                else
                        successor->right = t->right;
                successor->left = t->left;
                if (successor->parent == ((void *)0))
                        successor->root->tree = successor;
                else if (successor->key < successor->parent->key)
                        successor->parent->left = successor;
                else
                        successor->parent->right = successor;
                if (successor->right != ((void *)0))
                        successor->right->parent = successor;
                successor->left->parent = successor;
                tree_depth(successor);
                tree_depth(successor->parent);
                if (walker != t)
                {
                        while(walker != ((void *)0) && walker != successor)
                        {
                                tree_depth(walker);
                                tree_balance(walker);
                                walker = walker->parent;
                        }
                }
        }
        tree_update_list(t->prev);
        tree_update_list(t->next);
        tree_depth(t->parent);
        tree_balance(t->parent);
        t->root->nodes--;
        if (dtor != ((void *)0))
                dtor(t->data, dtor_args);
        memset(t, 0, sizeof(*t));
        free(t);
        return 0;
}


decompiled_code:
__int64 __fastcall tree_delete(unsigned int a1, __int64 a2, void (__fastcall *a3)(__int64, __int64), __int64 a4)
{
unsigned int v6; // er12

if ( !a2 )
return (unsigned int)-1;
pthread_mutex_lock((pthread_mutex_t *)(a2 + 48));
v6 = tree_delete_node(a1, *(__int64 **)a2, a3, a4);
pthread_mutex_unlock((pthread_mutex_t *)(a2 + 48));
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1, __int64 a2, void (__fastcall *a3)(__int64, __int64), __int64 a4)
{
unsigned int v6; // er12

if ( !a2 )
return (unsigned int)-1;
pthread_mutex_lock((pthread_mutex_t *)(a2 + 48));
v6 = func13(a1, *(__int64 **)a2, a3, a4);
pthread_mutex_unlock((pthread_mutex_t *)(a2 + 48));
return v6;
}

original_code:
static int
tree_delete(int key, struct tree_root* root, int (*dtor)(void*,void*), void* dtor_args)
{
        if (root == ((void *)0))
                return -1;
        pthread_mutex_lock(&root->mutex);
        int ret = tree_delete_node(key, root->tree, dtor, dtor_args);
        pthread_mutex_unlock(&root->mutex);
        return ret;
}

canonical_original_code:
static int tree_delete(int key, struct tree_root *root, int (*dtor)(void *, void *), void *dtor_args)
{
        if (root == ((void *)0))
                return -1;
        pthread_mutex_lock(&root->mutex);
        int ret = tree_delete_node(key, root->tree, dtor, dtor_args);
        pthread_mutex_unlock(&root->mutex);
        return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall tree_add_node(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax
__int64 v4; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v2 = *(_DWORD *)(a1 + 56);
if ( *(_DWORD *)(a2 + 56) < v2 )
{
result = tree_add_node(*(_QWORD *)(a1 + 8));
if ( (_DWORD)result != -1 )
goto LABEL_6;
*(_QWORD *)(a1 + 8) = a2;
LABEL_9:
v4 = *(_QWORD *)(a2 + 24);
*(_QWORD *)a2 = a1;
++*(_DWORD *)(v4 + 8);
tree_update_list_isra_0((_QWORD *)a2);
tree_update_list_isra_0(*(_QWORD **)(a2 + 40));
tree_update_list_isra_0(*(_QWORD **)(a2 + 32));
goto LABEL_10;
}
if ( *(_DWORD *)(a2 + 56) <= v2 )
return 4294967294LL;
result = tree_add_node(*(_QWORD *)(a1 + 16));
if ( (_DWORD)result == -1 )
{
*(_QWORD *)(a1 + 16) = a2;
goto LABEL_9;
}
LABEL_6:
if ( !(_DWORD)result )
{
LABEL_10:
tree_depth_isra_0(a1);
tree_balance_isra_0(a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax
__int64 v4; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v2 = *(_DWORD *)(a1 + 56);
if ( *(_DWORD *)(a2 + 56) < v2 )
{
result = func15(*(_QWORD *)(a1 + 8));
if ( (_DWORD)result != -1 )
goto LABEL_6;
*(_QWORD *)(a1 + 8) = a2;
LABEL_9:
v4 = *(_QWORD *)(a2 + 24);
*(_QWORD *)a2 = a1;
++*(_DWORD *)(v4 + 8);
func8((_QWORD *)a2);
func8(*(_QWORD **)(a2 + 40));
func8(*(_QWORD **)(a2 + 32));
goto LABEL_10;
}
if ( *(_DWORD *)(a2 + 56) <= v2 )
return 4294967294LL;
result = func15(*(_QWORD *)(a1 + 16));
if ( (_DWORD)result == -1 )
{
*(_QWORD *)(a1 + 16) = a2;
goto LABEL_9;
}
LABEL_6:
if ( !(_DWORD)result )
{
LABEL_10:
func9(a1);
func12(a1);
result = 0LL;
}
return result;
}

original_code:
static int tree_add_node(struct tree* parent, struct tree* t)
{
        if (parent == ((void *)0) || t == ((void *)0))
                return -1;
        if (t->key < parent->key)
        {
                int s = tree_add_node(parent->left, t);
                switch (s) {
                case -1:
                        parent->left = t;
                        t->parent = parent;
                        t->root->nodes++;
                        tree_update_list(t);
                        tree_update_list(t->prev);
                        tree_update_list(t->next);
                case 0:
                        break;
                default:
                        return s;
                }
        }
        else if(t->key > parent->key)
        {
                int s = tree_add_node(parent->right, t);
                switch (s)
                {
                case -1:
                        parent->right = t;
                        t->parent = parent;
                        t->root->nodes++;
                        tree_update_list(t);
                        tree_update_list(t->prev);
                        tree_update_list(t->next);
                case 0:
                        break;
                default:
                        return s;
                }
        }
        else
                return -2;
        tree_depth(parent);
        tree_balance(parent);
        return 0;
}

canonical_original_code:
static int tree_add_node(struct tree *parent, struct tree *t)
{
        if (parent == ((void *)0) || t == ((void *)0))
                return -1;
        if (t->key < parent->key)
        {
                int s = tree_add_node(parent->left, t);
                switch (s) {
                case -1:
                        parent->left = t;
                        t->parent = parent;
                        t->root->nodes++;
                        tree_update_list(t);
                        tree_update_list(t->prev);
                        tree_update_list(t->next);
                case 0:
                        break;
                default:
                        return s;
                }
        }
        else if(t->key > parent->key)
        {
                int s = tree_add_node(parent->right, t);
                switch (s)
                {
                case -1:
                        parent->right = t;
                        t->parent = parent;
                        t->root->nodes++;
                        tree_update_list(t);
                        tree_update_list(t->prev);
                        tree_update_list(t->next);
                case 0:
                        break;
                default:
                        return s;
                }
        }
        else
                return -2;
        tree_depth(parent);
        tree_balance(parent);
        return 0;
}

variable_types:
t
struct tree *

variable_types: s int


decompiled_code:
__int64 __fastcall tree_add(__int64 a1, __int64 a2)
{
pthread_mutex_t *v2; // r12
__int64 v4; // rdi
unsigned int v5; // er13

if ( !a1 || !a2 )
return (unsigned int)-1;
v2 = (pthread_mutex_t *)(a1 + 48);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
v4 = *(_QWORD *)a1;
if ( v4 )
{
v5 = tree_add_node(v4, a2);
}
else
{
*(_QWORD *)a1 = a2;
v5 = 4;
}
pthread_mutex_unlock(v2);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2)
{
pthread_mutex_t *v2; // r12
__int64 v4; // rdi
unsigned int v5; // er13

if ( !a1 || !a2 )
return (unsigned int)-1;
v2 = (pthread_mutex_t *)(a1 + 48);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
v4 = *(_QWORD *)a1;
if ( v4 )
{
v5 = func15(v4, a2);
}
else
{
*(_QWORD *)a1 = a2;
v5 = 4;
}
pthread_mutex_unlock(v2);
return v5;
}

original_code:
static int tree_add(struct tree_root* root, struct tree* tree)
{
        if (root == ((void *)0) || tree == ((void *)0))
                return -1;
        int ret = 4;
        pthread_mutex_lock(&root->mutex);
        if (root->tree != ((void *)0))
        {
                ret = tree_add_node(root->tree, tree);
                goto success;
        }
        root->tree = tree;
success:
        pthread_mutex_unlock(&root->mutex);
        return ret;
}

canonical_original_code:
static int tree_add(struct tree_root *root, struct tree *tree)
{
        if (root == ((void *)0) || tree == ((void *)0))
                return -1;
        int ret = 4;
        pthread_mutex_lock(&root->mutex);
        if (root->tree != ((void *)0))
        {
                ret = tree_add_node(root->tree, tree);
                goto success;
        }
        root->tree = tree;
success:
        pthread_mutex_unlock(&root->mutex);
        return ret;
}


decompiled_code:
char *tree_new_avl()
{
char *v0; // rax
char *v1; // r12

v0 = (char *)calloc(0x58uLL, 1uLL);
*((_QWORD *)v0 + 2) = tree_new_node;
v1 = v0;
*((_QWORD *)v0 + 3) = tree_find;
*((_QWORD *)v0 + 4) = tree_delete;
*((_QWORD *)v0 + 5) = tree_flush;
pthread_mutex_init((pthread_mutex_t *)(v0 + 48), 0LL);
return v1;
}

canonical_decompiled_code:
char *func17()
{
char *v0; // rax
char *v1; // r12

v0 = (char *)calloc(0x58uLL, 1uLL);
*((_QWORD *)v0 + 2) = tree_new_node;
v1 = v0;
*((_QWORD *)v0 + 3) = tree_find;
*((_QWORD *)v0 + 4) = tree_delete;
*((_QWORD *)v0 + 5) = tree_flush;
pthread_mutex_init((pthread_mutex_t *)(v0 + 48), 0LL);
return v1;
}

original_code:
struct tree_root* tree_new_avl()
{
        struct tree_root* t = malloc(sizeof(*t));
        if (t != ((void *)0))
                memset(t, 0, sizeof(*t));
        t->add = tree_new_node;
        t->find = tree_find;
        t->delete = tree_delete;
        t->flush = tree_flush;
        pthread_mutex_init(&t->mutex, ((void *)0));
        return t;
}

canonical_original_code:
struct tree_root *tree_new_avl()
{
        struct tree_root *t = malloc(sizeof(*t));
        if (t != ((void *)0))
                memset(t, 0, sizeof(*t));
        t->add = tree_new_node;
        t->find = tree_find;
        t->delete = tree_delete;
        t->flush = tree_flush;
        pthread_mutex_init(&t->mutex, ((void *)0));
        return t;
}

return_type: struct tree_root { struct tree { struct tree *parent; struct tree *left; struct tree *right; struct tree_root *root; struct tree *next; struct tree *prev; int rdepth; int ldepth; int key; void *data; } *tree; unsigned int nodes; struct tree *(*add)(int key, void *data, struct tree_root *root); void *(*find)(int key, struct tree_root *root); int (*delete)(int, struct tree_root *, int (*dtor)(void *, void *), void *); int (*flush)(struct tree_root *, int (*dtor)(void *, void *), void *); union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *


decompiled_code:
__int64 __fastcall tree_dump(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
puts("Dumping tree!");
pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
tree_dump_node_isra_0(*(_QWORD *)a1);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 48));
puts("\nDone dumping tree!");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
puts("Dumping tree!");
pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
func5(*(_QWORD *)a1);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 48));
puts("\nDone dumping tree!");
return 0LL;
}

original_code:
int tree_dump(struct tree_root* root)
{
        if (root == ((void *)0))
                return -1;
        printf("Dumping tree!\n");
        pthread_mutex_lock(&root->mutex);
        tree_dump_node(root->tree);
        pthread_mutex_unlock(&root->mutex);
        printf("\nDone dumping tree!\n");
        return 0;
}

canonical_original_code:
int tree_dump(struct tree_root *root)
{
        if (root == ((void *)0))
                return -1;
        printf("Dumping tree!\n");
        pthread_mutex_lock(&root->mutex);
        tree_dump_node(root->tree);
        pthread_mutex_unlock(&root->mutex);
        printf("\nDone dumping tree!\n");
        return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
__int64 v4; // rbp
int i; // ebx
int v6; // edi
int v7; // edi
__int64 v8; // r12
_QWORD *v9; // rbx
_QWORD *v10; // r13
unsigned int v11; // eax
__int64 j; // r12
_QWORD *v13; // r12
_QWORD *v14; // rbx
int result; // eax

v3 = tree_new_avl();
if ( v3 )
{
v4 = (__int64)v3;
for ( i = 0; i != 17; ++i )
{
v6 = i;
tree_new_node(v6, 0LL, (_QWORD *)v4);
tree_dump(v4);
}
tree_delete(8u, v4, (void (__fastcall *)(__int64, __int64))cleanup, 0LL);
tree_delete(9u, v4, (void (__fastcall *)(__int64, __int64))cleanup, 0LL);
tree_dump(v4);
do
{
v7 = i++;
tree_new_node(v7, 0LL, (_QWORD *)v4);
tree_dump(v4);
}
while ( i != 33 );
v8 = tree_find_node(4, *(_QWORD *)v4);
v9 = tree_find_prev((_QWORD *)v8);
v10 = tree_find_next((_QWORD *)v8);
printf("ptr: %X - %X - %X\n", v9, v8, v10);
printf("key: %X - %X - %X\n", *((unsigned int *)v9 + 14), *(unsigned int *)(v8 + 56), *((unsigned int *)v10 + 14));
v11 = pthread_mutex_trylock((pthread_mutex_t *)(v4 + 48));
printf("%X\n", v11);
pthread_mutex_unlock((pthread_mutex_t *)(v4 + 48));
for ( j = tree_find(0, v4); j; j = (__int64)tree_find_next((_QWORD *)j) )
{
v9 = (_QWORD *)j;
printf("%X ", *(unsigned int *)(j + 56));
}
putchar(10);
do
{
v13 = v9;
printf("%X ", *((unsigned int *)v9 + 14));
v9 = tree_find_prev(v9);
}
while ( v9 );
putchar(10);
do
{
v14 = v13;
printf("%X ", *((unsigned int *)v13 + 14));
v13 = (_QWORD *)v13[4];
}
while ( v13 );
putchar(10);
do
{
printf("%X ", *((unsigned int *)v14 + 14));
v14 = (_QWORD *)v14[5];
}
while ( v14 );
putchar(10);
tree_flush((void *)v4, (void (__fastcall *)(_QWORD, __int64))cleanup, 0LL);
result = 0;
}
else
{
fwrite("An error occured, no memory!\n", 1uLL, 0x1DuLL, stderr);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
__int64 v4; // rbp
int i; // ebx
int v6; // edi
int v7; // edi
__int64 v8; // r12
_QWORD *v9; // rbx
_QWORD *v10; // r13
unsigned int v11; // eax
__int64 j; // r12
_QWORD *v13; // r12
_QWORD *v14; // rbx
int result; // eax

v3 = func17();
if ( v3 )
{
v4 = (__int64)v3;
for ( i = 0; i != 17; ++i )
{
v6 = i;
tree_new_node(v6, 0LL, (_QWORD *)v4);
func18(v4);
}
func14(8u, v4, (void (__fastcall *)(__int64, __int64))cleanup, 0LL);
func14(9u, v4, (void (__fastcall *)(__int64, __int64))cleanup, 0LL);
func18(v4);
do
{
v7 = i++;
tree_new_node(v7, 0LL, (_QWORD *)v4);
func18(v4);
}
while ( i != 33 );
v8 = func2(4, *(_QWORD *)v4);
v9 = tree_find_prev((_QWORD *)v8);
v10 = tree_find_next((_QWORD *)v8);
printf("ptr: %X - %X - %X\n", v9, v8, v10);
printf("key: %X - %X - %X\n", *((unsigned int *)v9 + 14), *(unsigned int *)(v8 + 56), *((unsigned int *)v10 + 14));
v11 = pthread_mutex_trylock((pthread_mutex_t *)(v4 + 48));
printf("%X\n", v11);
pthread_mutex_unlock((pthread_mutex_t *)(v4 + 48));
for ( j = func3(0, v4); j; j = (__int64)tree_find_next((_QWORD *)j) )
{
v9 = (_QWORD *)j;
printf("%X ", *(unsigned int *)(j + 56));
}
putchar(10);
do
{
v13 = v9;
printf("%X ", *((unsigned int *)v9 + 14));
v9 = tree_find_prev(v9);
}
while ( v9 );
putchar(10);
do
{
v14 = v13;
printf("%X ", *((unsigned int *)v13 + 14));
v13 = (_QWORD *)v13[4];
}
while ( v13 );
putchar(10);
do
{
printf("%X ", *((unsigned int *)v14 + 14));
v14 = (_QWORD *)v14[5];
}
while ( v14 );
putchar(10);
func7((void *)v4, (void (__fastcall *)(_QWORD, __int64))cleanup, 0LL);
result = 0;
}
else
{
fwrite("An error occured, no memory!\n", 1uLL, 0x1DuLL, stderr);
result = -1;
}
return result;
}

original_code:
int main()
{
        struct tree_root* t = tree_new_avl();
        if (t == ((void *)0))
        {
                fprintf(stderr, "An error occured, no memory!\n");
                return -1;
        }
        int i = 0;
        for (; i <= 16; i++)
        {
                tree_new_node(i, ((void *)0), t);
                tree_dump(t);
        }
        tree_delete(8, t, &cleanup, ((void *)0));
        tree_delete(9, t, &cleanup, ((void *)0));
        tree_dump(t);
        for (; i <= 32; i++)
        {
                tree_new_node(i, ((void *)0), t);
                tree_dump(t);
        }
        struct tree* a = tree_find_node(4, t->tree);
        struct tree* b = tree_find_prev(a);
        struct tree* c = tree_find_next(a);
        printf("ptr: %X - %X - %X\n", b, a, c);
        printf("key: %X - %X - %X\n", b->key, a->key, c->key);
        i = pthread_mutex_trylock(&t->mutex);
        printf("%X\n", i);
        pthread_mutex_unlock(&t->mutex);
        a = tree_find(0, t);
        while (a != ((void *)0))
        {
                printf("%X ", a->key);
                b = a;
                a = tree_find_next(a);
        }
        printf("\n");
        a = b;
        while (a != ((void *)0))
        {
                printf("%X ", a->key);
                b = a;
                a = tree_find_prev(a);
        }
        printf("\n");
        a = b;
        while (a != ((void *)0))
        {
                printf("%X ", a->key);
                b = a;
                a = a->next;
        }
        printf("\n");
        a = b;
        while (a != ((void *)0))
        {
                printf("%X ", a->key);
                b = a;
                a = a->prev;
        }
        printf("\n");
        tree_flush(t, cleanup, ((void *)0));
        t = ((void *)0);
        return 0;
}

canonical_original_code:
int main()
{
        struct tree_root *t = tree_new_avl();
        if (t == ((void *)0))
        {
                fprintf(stderr, "An error occured, no memory!\n");
                return -1;
        }
        int i = 0;
        for (; i <= 16; i++)
        {
                tree_new_node(i, ((void *)0), t);
                tree_dump(t);
        }
        tree_delete(8, t, &cleanup, ((void *)0));
        tree_delete(9, t, &cleanup, ((void *)0));
        tree_dump(t);
        for (; i <= 32; i++)
        {
                tree_new_node(i, ((void *)0), t);
                tree_dump(t);
        }
        struct tree *a = tree_find_node(4, t->tree);
        struct tree *b = tree_find_prev(a);
        struct tree *c = tree_find_next(a);
        printf("ptr: %X - %X - %X\n", b, a, c);
        printf("key: %X - %X - %X\n", b->key, a->key, c->key);
        i = pthread_mutex_trylock(&t->mutex);
        printf("%X\n", i);
        pthread_mutex_unlock(&t->mutex);
        a = tree_find(0, t);
        while (a != ((void *)0))
        {
                printf("%X ", a->key);
                b = a;
                a = tree_find_next(a);
        }
        printf("\n");
        a = b;
        while (a != ((void *)0))
        {
                printf("%X ", a->key);
                b = a;
                a = tree_find_prev(a);
        }
        printf("\n");
        a = b;
        while (a != ((void *)0))
        {
                printf("%X ", a->key);
                b = a;
                a = a->next;
        }
        printf("\n");
        a = b;
        while (a != ((void *)0))
        {
                printf("%X ", a->key);
                b = a;
                a = a->prev;
        }
        printf("\n");
        tree_flush(t, cleanup, ((void *)0));
        t = ((void *)0);
        return 0;
}

variable_types: i int


repo: bemk/xorll

original_code:
int main(int argc, char** argv)
{
        struct list* lst = list_init();
        struct list* lst2 = list_init();
        struct node* n1 = node_init(lst);
        struct node* n2 = node_init(lst);
        struct node* n3 = node_init(lst);
        memset(n1, 0, sizeof(*n1));
        memset(n2, 0, sizeof(*n2));
        memset(n3, 0, sizeof(*n3));
        n1->ptr = n2;
        n2->ptr = n1;
        n1->lst = lst;
        n2->lst = lst;
        n3->lst = lst;
        n1->data = 0xC0DEBABE;
        n2->data = 0xDEADBEEF;
        n3->data = 0xCAFEBEA8;
        lst->head = n1;
        lst->tail = n2;
        debug_list(lst);
        node_add_tail(lst, n3);
        debug_list(lst);
        list_copy_list(lst, lst2);
        debug_list(lst2);
        node_purge(n3, n2);
        debug_list(lst);
        list_clean(lst);
        return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
        struct list *lst = list_init();
        struct list *lst2 = list_init();
        struct node *n1 = node_init(lst);
        struct node *n2 = node_init(lst);
        struct node *n3 = node_init(lst);
        memset(n1, 0, sizeof(*n1));
        memset(n2, 0, sizeof(*n2));
        memset(n3, 0, sizeof(*n3));
        n1->ptr = n2;
        n2->ptr = n1;
        n1->lst = lst;
        n2->lst = lst;
        n3->lst = lst;
        n1->data = 0xC0DEBABE;
        n2->data = 0xDEADBEEF;
        n3->data = 0xCAFEBEA8;
        lst->head = n1;
        lst->tail = n2;
        debug_list(lst);
        node_add_tail(lst, n3);
        debug_list(lst);
        list_copy_list(lst, lst2);
        debug_list(lst2);
        node_purge(n3, n2);
        debug_list(lst);
        list_clean(lst);
        return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct list { struct node { void *ptr; int data; struct list *lst; } *head; struct node *tail; } *

variable_types: struct node { void *ptr; int data; struct list { struct node *head; struct node *tail; } *lst; } *


decompiled_code:
void *list_init()
{
void *result; // rax

result = calloc(0x10uLL, 1uLL);
if ( !result )
{
fwrite("OUT OF MEMORY!\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
return result;
}

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

result = calloc(0x10uLL, 1uLL);
if ( !result )
{
fwrite("OUT OF MEMORY!\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
return result;
}

original_code:
struct list*
list_init()
{
        struct list* lst = malloc(sizeof(*lst));
        if (lst == ((void *)0))
        {
                fprintf(stderr, "OUT OF MEMORY!\n");
                exit(1);
        }
        memset(lst, 0, sizeof(*lst));
        return lst;
}

canonical_original_code:
struct list *list_init()
{
        struct list *lst = malloc(sizeof(*lst));
        if (lst == ((void *)0))
        {
                fprintf(stderr, "OUT OF MEMORY!\n");
                exit(1);
        }
        memset(lst, 0, sizeof(*lst));
        return lst;
}

return_type: struct list { struct node { void *ptr; int data; struct list *lst; } *head; struct node *tail; } *

user_defined_types: struct list { struct node *head; struct node *tail; }


decompiled_code:
__int64 __fastcall list_clean(void *ptr)
{
unsigned __int64 v2; // rdi

v2 = *(_QWORD *)ptr;
if ( v2 )
{
do
{
node_purge(v2, 0LL);
v2 = *(_QWORD *)ptr;
}
while ( *(_QWORD *)ptr );
}
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(void *ptr)
{
unsigned __int64 v2; // rdi

v2 = *(_QWORD *)ptr;
if ( v2 )
{
do
{
func8(v2, 0LL);
v2 = *(_QWORD *)ptr;
}
while ( *(_QWORD *)ptr );
}
free(ptr);
return 0LL;
}

original_code:
int
list_clean(struct list* lst)
{
        while (lst->head != ((void *)0))
                node_purge(lst->head, ((void *)0));
        free(lst);
        return 0;
}

canonical_original_code:
int list_clean(struct list *lst)
{
        while (lst->head != ((void *)0))
                node_purge(lst->head, ((void *)0));
        free(lst);
        return 0;
}

user_defined_types: struct node { void *ptr; int data; struct list *lst; }