process

decompiled_code:
void __fastcall __noreturn process(void *a1)
{
__int64 v1; // rsi
__int64 v2; // rcx
const char *v3; // rdx
const char *v4; // r8
char *v5; // r13
unsigned int i; // er14
int v7; // er12
__int16 v8; // di
__int16 v9; // ax
__int64 v10; // rcx
const char *v11; // rdi
unsigned int v12; // ebp
unsigned int v13; // er15
size_t v14; // rax
__useconds_t v15; // ebx
int v16; // eax
__useconds_t v17; // edi
__int64 v18; // rdx
__int64 v19; // rbx
int v20; // eax
__int64 v21; // rbx
int v22; // ebx
char *v23; // r15
char *v24; // rax
int v25; // edx
int v26; // ecx
int v27; // edx
char *v28; // rax
char *v29; // rax
__int64 v30; // rdx
const char *v31; // rdi
__int64 v32; // rsi
int v33; // [rsp+8h] [rbp-90h]
int v34; // [rsp+8h] [rbp-90h]
unsigned int v36; // [rsp+18h] [rbp-80h]
int v37; // [rsp+1Ch] [rbp-7Ch]
int v38; // [rsp+20h] [rbp-78h]
int v39; // [rsp+20h] [rbp-78h]
int v40; // [rsp+20h] [rbp-78h]
int v41; // [rsp+28h] [rbp-70h]
struct sockaddr addr; // [rsp+30h] [rbp-68h] BYREF
struct timespec requested_time; // [rsp+40h] [rbp-58h] BYREF
struct timespec remaining; // [rsp+50h] [rbp-48h] BYREF

v1 = *(unsigned int *)a1;
v2 = *((unsigned int *)a1 + 4);
v3 = (const char *)*((_QWORD *)a1 + 1);
v4 = (const char *)*((_QWORD *)a1 + 3);
v36 = *(_DWORD *)a1;
requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 100000LL;
printf("thread %d starts, ip %s portnr %d url %s \n", v1, v3, v2, v4);
v5 = (char *)malloc(0x3E8uLL);
v37 = *((_DWORD *)a1 + 1);
if ( v37 > 0 )
{
for ( i = 0; i != v37; ++i )
{
v7 = socket(2, 1, 0);
if ( v7 < 0 )
errhalt("Socket", (const char *)1);
addr = 0LL;
v8 = *((_WORD *)a1 + 8);
addr.sa_family = 2;
v9 = _bswap_16(v8);
v11 = *(const char **)(v10 + 8);
*(_WORD *)addr.sa_data = v9;
if ( !inet_addr(v11) )
errhalt("inet_addr problem", &addr.sa_data[2]);
v12 = 0;
while ( 1 )
{
v13 = connect(v7, &addr, 0x10u);
if ( !v13 )
break;
++v12;
nanosleep(&requested_time, &remaining);
if ( v12 == 100 )
errhalt("connect problem", (const char *)&remaining);
}
sprintf(v5, "GET /%s HTTP/1.0\n\n", *((const char **)a1 + 3));
v14 = strlen(v5);
send(v7, v5, v14, 0);
if ( *((_QWORD *)a1 + 4) )
{
v15 = 0;
while ( 1 )
{
v16 = readn(v7, v5, 0x3DEuLL);
v33 = v16;
if ( v16 > 0 )
break;
v17 = v15;
v15 += 100;
usleep(v17);
v18 = v13++;
printf("thread %d read try %d at iter %d\n", v36, v18, i);
if ( v13 == 10 )
{
if ( !v33 )
{
v19 = 0LL;
goto LABEL_14;
}
v22 = v36;
v30 = i;
v31 = "thread %d did not succeed to read at all at iter %d, exiting\n";
v32 = v36;
LABEL_38:
printf(v31, v32, v30);
LABEL_39:
err_exit(v7, v5, v22);
}
}
v19 = v16;
v38 = v16;
v23 = &v5[v16];
if ( v16 <= 989 )
{
LABEL_14:
v5[v19] = 0;
}
else
{
*v23 = 0;
v24 = strstr(v5, "Content-Length: ");
v25 = v38;
if ( !v24 )
{
v24 = strstr(v5, "content-length: ");
v25 = v38;
if ( !v24 )
{
v22 = v36;
printf("thread %d did not find Content-Length at iter %d, exiting\n", v36, i);
goto LABEL_39;
}
}
v41 = v25;
v39 = atoi(v24 + 16);
printf("len %d\n", (unsigned int)v39);
v26 = v39;
v27 = v41;
if ( v39 <= 0 )
{
v22 = v36;
v30 = i;
v31 = "thread %d got a zero or less Content-Length at iter %d, exiting\n";
v32 = v36;
goto LABEL_38;
}
if ( v39 > 99999500 )
{
v22 = v36;
v30 = i;
v31 = "thread %d got a too big Content-Length at iter %d, exiting\n";
v32 = v36;
goto LABEL_38;
}
if ( v39 > 500 )
{
v29 = (char *)realloc(v5, v39 + 500);
v26 = v39;
v27 = v41;
v5 = v29;
if ( !v29 )
{
printf("thread %d failed to alloc enough memory at iter %d, exiting\n", v36, i);
err_exit(v7, 0LL, v36);
}
v12 = v33;
v23 = &v29[v33];
}
v40 = v26;
v34 = v27;
v28 = strstr(v5, "\r\n\r\n");
if ( !v28 )
{
v22 = v36;
printf("thread %d did not find empty line at iter %d, exiting\n", v36, i);
goto LABEL_39;
}
v23[(int)readn(v7, v23, v40 - v34 + (int)v28 - (int)v5 + 4)] = 0;
}
if ( !strstr(v5, "200") )
{
printf("thread %d received a non-200 http result at iter %d, exiting\n", v36, i);
printf("j %d buffer:\n----\n%s\n----\n", v12, v5);
err_exit(v7, v5, v36);
}
if ( !strstr(v5, *((const char **)a1 + 4)) )
{
v22 = v36;
printf("thread %d received a non-verified http result at iter %d, exiting\n", v36, i);
goto LABEL_39;
}
}
else
{
do
{
v20 = read(v7, v5, 0x14uLL);
v21 = v20;
}
while ( v20 < 0 && *__errno_location() == 4 );
v5[v21] = 0;
if ( !strstr(v5, "200") )
{
v22 = v36;
printf("thread %d received a non-200 http result at iter %d, exiting\n", v36, i);
goto LABEL_39;
}
}
shutdown(v7, 2);
close(v7);
}
}
*((_DWORD *)a1 + 10) = 0;
free(v5);
pthread_exit((void *)(int)v36);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(void *a1)
{
__int64 v1; // rsi
__int64 v2; // rcx
const char *v3; // rdx
const char *v4; // r8
char *v5; // r13
unsigned int i; // er14
int v7; // er12
__int16 v8; // di
__int16 v9; // ax
__int64 v10; // rcx
const char *v11; // rdi
unsigned int v12; // ebp
unsigned int v13; // er15
size_t v14; // rax
__useconds_t v15; // ebx
int v16; // eax
__useconds_t v17; // edi
__int64 v18; // rdx
__int64 v19; // rbx
int v20; // eax
__int64 v21; // rbx
int v22; // ebx
char *v23; // r15
char *v24; // rax
int v25; // edx
int v26; // ecx
int v27; // edx
char *v28; // rax
char *v29; // rax
__int64 v30; // rdx
const char *v31; // rdi
__int64 v32; // rsi
int v33; // [rsp+8h] [rbp-90h]
int v34; // [rsp+8h] [rbp-90h]
unsigned int v36; // [rsp+18h] [rbp-80h]
int v37; // [rsp+1Ch] [rbp-7Ch]
int v38; // [rsp+20h] [rbp-78h]
int v39; // [rsp+20h] [rbp-78h]
int v40; // [rsp+20h] [rbp-78h]
int v41; // [rsp+28h] [rbp-70h]
struct sockaddr addr; // [rsp+30h] [rbp-68h] BYREF
struct timespec requested_time; // [rsp+40h] [rbp-58h] BYREF
struct timespec remaining; // [rsp+50h] [rbp-48h] BYREF

v1 = *(unsigned int *)a1;
v2 = *((unsigned int *)a1 + 4);
v3 = (const char *)*((_QWORD *)a1 + 1);
v4 = (const char *)*((_QWORD *)a1 + 3);
v36 = *(_DWORD *)a1;
requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 100000LL;
printf("thread %d starts, ip %s portnr %d url %s \n", v1, v3, v2, v4);
v5 = (char *)malloc(0x3E8uLL);
v37 = *((_DWORD *)a1 + 1);
if ( v37 > 0 )
{
for ( i = 0; i != v37; ++i )
{
v7 = socket(2, 1, 0);
if ( v7 < 0 )
func10("Socket", (const char *)1);
addr = 0LL;
v8 = *((_WORD *)a1 + 8);
addr.sa_family = 2;
v9 = func7(v8);
v11 = *(const char **)(v10 + 8);
*(_WORD *)addr.sa_data = v9;
if ( !inet_addr(v11) )
func10("inet_addr problem", &addr.sa_data[2]);
v12 = 0;
while ( 1 )
{
v13 = connect(v7, &addr, 0x10u);
if ( !v13 )
break;
++v12;
nanosleep(&requested_time, &remaining);
if ( v12 == 100 )
func10("connect problem", (const char *)&remaining);
}
sprintf(v5, "GET /%s HTTP/1.0\n\n", *((const char **)a1 + 3));
v14 = strlen(v5);
send(v7, v5, v14, 0);
if ( *((_QWORD *)a1 + 4) )
{
v15 = 0;
while ( 1 )
{
v16 = func8(v7, v5, 0x3DEuLL);
v33 = v16;
if ( v16 > 0 )
break;
v17 = v15;
v15 += 100;
usleep(v17);
v18 = v13++;
printf("thread %d read try %d at iter %d\n", v36, v18, i);
if ( v13 == 10 )
{
if ( !v33 )
{
v19 = 0LL;
goto LABEL_14;
}
v22 = v36;
v30 = i;
v31 = "thread %d did not succeed to read at all at iter %d, exiting\n";
v32 = v36;
LABEL_38:
printf(v31, v32, v30);
LABEL_39:
func9(v7, v5, v22);
}
}
v19 = v16;
v38 = v16;
v23 = &v5[v16];
if ( v16 <= 989 )
{
LABEL_14:
v5[v19] = 0;
}
else
{
*v23 = 0;
v24 = strstr(v5, "Content-Length: ");
v25 = v38;
if ( !v24 )
{
v24 = strstr(v5, "content-length: ");
v25 = v38;
if ( !v24 )
{
v22 = v36;
printf("thread %d did not find Content-Length at iter %d, exiting\n", v36, i);
goto LABEL_39;
}
}
v41 = v25;
v39 = atoi(v24 + 16);
printf("len %d\n", (unsigned int)v39);
v26 = v39;
v27 = v41;
if ( v39 <= 0 )
{
v22 = v36;
v30 = i;
v31 = "thread %d got a zero or less Content-Length at iter %d, exiting\n";
v32 = v36;
goto LABEL_38;
}
if ( v39 > 99999500 )
{
v22 = v36;
v30 = i;
v31 = "thread %d got a too big Content-Length at iter %d, exiting\n";
v32 = v36;
goto LABEL_38;
}
if ( v39 > 500 )
{
v29 = (char *)realloc(v5, v39 + 500);
v26 = v39;
v27 = v41;
v5 = v29;
if ( !v29 )
{
printf("thread %d failed to alloc enough memory at iter %d, exiting\n", v36, i);
func9(v7, 0LL, v36);
}
v12 = v33;
v23 = &v29[v33];
}
v40 = v26;
v34 = v27;
v28 = strstr(v5, "\r\n\r\n");
if ( !v28 )
{
v22 = v36;
printf("thread %d did not find empty line at iter %d, exiting\n", v36, i);
goto LABEL_39;
}
v23[(int)func8(v7, v23, v40 - v34 + (int)v28 - (int)v5 + 4)] = 0;
}
if ( !strstr(v5, "200") )
{
printf("thread %d received a non-200 http result at iter %d, exiting\n", v36, i);
printf("j %d buffer:\n----\n%s\n----\n", v12, v5);
func9(v7, v5, v36);
}
if ( !strstr(v5, *((const char **)a1 + 4)) )
{
v22 = v36;
printf("thread %d received a non-verified http result at iter %d, exiting\n", v36, i);
goto LABEL_39;
}
}
else
{
do
{
v20 = read(v7, v5, 0x14uLL);
v21 = v20;
}
while ( v20 < 0 && *__errno_location() == 4 );
v5[v21] = 0;
if ( !strstr(v5, "200") )
{
v22 = v36;
printf("thread %d received a non-200 http result at iter %d, exiting\n", v36, i);
goto LABEL_39;
}
}
shutdown(v7, 2);
close(v7);
}
}
*((_DWORD *)a1 + 10) = 0;
free(v5);
pthread_exit((void *)(int)v36);
}

original_code:
void *process(void *targ) {
  struct thread_data *tdata;
  int i,j,k,tid,iter,maxiter,len,clenheader_len,toread,nread;
  int sockfd, bytes_read, ok;
  struct sockaddr_in dest;
  char *buffer, *bufp, *tp;
  char *loc,*clenheader;
  struct timespec tim, tim2;
  tim.tv_sec = 0;
  tim.tv_nsec = 100000;
  tdata=(struct thread_data *) targ;
  tid=tdata->thread_id;
  printf("thread %d starts, ip %s portnr %d url %s \n",tid,tdata->ip,tdata->port,tdata->urlpart);
  buffer=malloc(1000);
  maxiter=tdata->maxiter;
  clenheader="Content-Length:";
  clenheader_len=strlen(clenheader);
  for(iter=0; iter<maxiter; iter++) {
    i=0;
    if ( (sockfd = socket(2, SOCK_STREAM, 0)) < 0 ) {
      errhalt("Socket");
    }
    memset(&dest,0,sizeof(dest));
    dest.sin_family = 2;
    dest.sin_port = htons(tdata->port);
    if (inet_addr(tdata->ip, &dest.sin_addr.s_addr)==0)
        errhalt("inet_addr problem");
    ok=0;
    for(j=0;j<100;j++) {
      if ( connect(sockfd, (struct sockaddr*)&dest, sizeof(dest)) != 0 ) {
        nanosleep(&tim , &tim2);
      } else {
        ok=1;
        break;
      }
    }
    if (!ok) { errhalt("connect problem"); }
    sprintf(buffer, "GET /%s HTTP/1.0\n\n", tdata->urlpart);
    send(sockfd, buffer, strlen(buffer),0);
    len=0;
    if (tdata->verify==((void *)0)) {
      bufp=buffer;
      while (1) {
        if ((nread=read(sockfd, bufp, 20)) < 0) {
          if ((*__errno_location ())==4) nread=0;
          else break;
        } else {
          break;
        }
      }
      *(bufp+nread)='\0';
      if (strstr(buffer,"200")==((void *)0)) {
        printf("thread %d received a non-200 http result at iter %d, exiting\n",tid,iter);
        err_exit(sockfd,buffer,tid);
      }
    } else {
      bufp=buffer;
      toread=1000 -10;
      for(k=0;k<10;k++) {
        nread=readn(sockfd, bufp, toread);
        if (nread>0) break;
        usleep(k*100);
        printf("thread %d read try %d at iter %d\n",tid,k,iter);
      }
      if (nread<0) {
        printf("thread %d did not succeed to read at all at iter %d, exiting\n",tid,iter);
        err_exit(sockfd,buffer,tid);
      } else if (nread<toread) {
        bufp+=nread;
        *bufp='\0';
      } else {
        bufp+=nread;
        *bufp='\0';
        loc=strstr(buffer,"Content-Length: ");
        if (loc==((void *)0)) loc=strstr(buffer,"content-length: ");
        if (loc==((void *)0)) {
          printf("thread %d did not find Content-Length at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        tp=loc+strlen("Content-length: ");
        len=atoi(tp);
        printf("len %d\n",len);
        if (len<=0) {
          printf("thread %d got a zero or less Content-Length at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        if (len+500>100000000) {
          printf("thread %d got a too big Content-Length at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        if (len>(1000 -500)) {
          j=bufp-buffer;
          buffer=realloc(buffer,len+500);
          if (buffer==((void *)0)) {
            printf("thread %d failed to alloc enough memory at iter %d, exiting\n",tid,iter);
            err_exit(sockfd,buffer,tid);
          }
          bufp=buffer+j;
        }
        loc=strstr(buffer,"\r\n\r\n");
        if (loc==((void *)0)) {
          printf("thread %d did not find empty line at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        toread=len+((loc-buffer)+4)-nread;
        nread=readn(sockfd, bufp, toread);
        *(bufp+nread)='\0';
      }
      if (strstr(buffer,"200")==((void *)0)) {
        printf("thread %d received a non-200 http result at iter %d, exiting\n",tid,iter);
        printf("j %d buffer:\n----\n%s\n----\n",j,buffer);
        err_exit(sockfd,buffer,tid);
      }
      if (strstr(buffer,tdata->verify)==((void *)0)) {
        printf("thread %d received a non-verified http result at iter %d, exiting\n",tid,iter);
        err_exit(sockfd,buffer,tid);
      }
    }
    shutdown(sockfd,SHUT_RDWR);
    close(sockfd);
  }
  tdata->res=i;
  free(buffer);
  pthread_exit((void*) tid);
  return ((void *)0);
}

canonical_original_code:
void *process(void *targ) {
  struct thread_data *tdata;
  int i; int j; int k; int tid; int iter; int maxiter; int len; int clenheader_len; int toread; int nread;
  int sockfd; int bytes_read; int ok;
  struct sockaddr_in dest;
  char *buffer; char *bufp; char *tp;
  char *loc; char *clenheader;
  struct timespec tim; struct timespec tim2;
  tim.tv_sec = 0;
  tim.tv_nsec = 100000;
  tdata=(struct thread_data *) targ;
  tid=tdata->thread_id;
  printf("thread %d starts, ip %s portnr %d url %s \n",tid,tdata->ip,tdata->port,tdata->urlpart);
  buffer=malloc(1000);
  maxiter=tdata->maxiter;
  clenheader="Content-Length:";
  clenheader_len=strlen(clenheader);
  for(iter=0; iter<maxiter; iter++) {
    i=0;
    if ( (sockfd = socket(2, SOCK_STREAM, 0)) < 0 ) {
      errhalt("Socket");
    }
    memset(&dest,0,sizeof(dest));
    dest.sin_family = 2;
    dest.sin_port = htons(tdata->port);
    if (inet_addr(tdata->ip, &dest.sin_addr.s_addr)==0)
        errhalt("inet_addr problem");
    ok=0;
    for(j=0;j<100;j++) {
      if ( connect(sockfd, (struct sockaddr *)&dest, sizeof(dest)) != 0 ) {
        nanosleep(&tim , &tim2);
      } else {
        ok=1;
        break;
      }
    }
    if (!ok) { errhalt("connect problem"); }
    sprintf(buffer, "GET /%s HTTP/1.0\n\n", tdata->urlpart);
    send(sockfd, buffer, strlen(buffer),0);
    len=0;
    if (tdata->verify==((void *)0)) {
      bufp=buffer;
      while (1) {
        if ((nread=read(sockfd, bufp, 20)) < 0) {
          if ((*__errno_location ())==4) nread=0;
          else break;
        } else {
          break;
        }
      }
      *(bufp+nread)='\0';
      if (strstr(buffer,"200")==((void *)0)) {
        printf("thread %d received a non-200 http result at iter %d, exiting\n",tid,iter);
        err_exit(sockfd,buffer,tid);
      }
    } else {
      bufp=buffer;
      toread=1000 -10;
      for(k=0;k<10;k++) {
        nread=readn(sockfd, bufp, toread);
        if (nread>0) break;
        usleep(k*100);
        printf("thread %d read try %d at iter %d\n",tid,k,iter);
      }
      if (nread<0) {
        printf("thread %d did not succeed to read at all at iter %d, exiting\n",tid,iter);
        err_exit(sockfd,buffer,tid);
      } else if (nread<toread) {
        bufp+=nread;
        *bufp='\0';
      } else {
        bufp+=nread;
        *bufp='\0';
        loc=strstr(buffer,"Content-Length: ");
        if (loc==((void *)0)) loc=strstr(buffer,"content-length: ");
        if (loc==((void *)0)) {
          printf("thread %d did not find Content-Length at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        tp=loc+strlen("Content-length: ");
        len=atoi(tp);
        printf("len %d\n",len);
        if (len<=0) {
          printf("thread %d got a zero or less Content-Length at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        if (len+500>100000000) {
          printf("thread %d got a too big Content-Length at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        if (len>(1000 -500)) {
          j=bufp-buffer;
          buffer=realloc(buffer,len+500);
          if (buffer==((void *)0)) {
            printf("thread %d failed to alloc enough memory at iter %d, exiting\n",tid,iter);
            err_exit(sockfd,buffer,tid);
          }
          bufp=buffer+j;
        }
        loc=strstr(buffer,"\r\n\r\n");
        if (loc==((void *)0)) {
          printf("thread %d did not find empty line at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        toread=len+((loc-buffer)+4)-nread;
        nread=readn(sockfd, bufp, toread);
        *(bufp+nread)='\0';
      }
      if (strstr(buffer,"200")==((void *)0)) {
        printf("thread %d received a non-200 http result at iter %d, exiting\n",tid,iter);
        printf("j %d buffer:\n----\n%s\n----\n",j,buffer);
        err_exit(sockfd,buffer,tid);
      }
      if (strstr(buffer,tdata->verify)==((void *)0)) {
        printf("thread %d received a non-verified http result at iter %d, exiting\n",tid,iter);
        err_exit(sockfd,buffer,tid);
      }
    }
    shutdown(sockfd,SHUT_RDWR);
    close(sockfd);
  }
  tdata->res=i;
  free(buffer);
  pthread_exit((void *) tid);
  return ((void *)0);
}

variable_types:
targ
void *

variable_types: struct thread_data { int thread_id; int maxiter; char *ip; int port; char *urlpart; char *verify; int res; } *

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: iter int

variable_types: maxiter int

variable_types: len int

variable_types: toread int

variable_types: nread int

variable_types: ok 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:
tp
char *

variable_types:
loc
char *

variable_types:
clenheader
char *

variable_types: struct timespec { long tv_sec; long tv_nsec; }

return_type: void *

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]; }


dropq

repo: println/scheduler

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

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

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

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void dropq(TQueue * q){
  TNode * acc = q->begin, * temp;
  while(acc){
    temp = acc;
    acc = acc->next;
    temp->info = ((void *)0);
    free(temp);
  }
  free(q);
}

canonical_original_code:
void dropq(struct queue *q){
  struct node *acc = q->begin; struct node *temp;
  while(acc){
    temp = acc;
    acc = acc->next;
    temp->info = ((void *)0);
    free(temp);
  }
  free(q);
}

variable_types: struct queue { struct node { struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *

variable_types: struct node { struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *

return_type: void

user_defined_types: struct node { struct task *info; struct node *next; }

user_defined_types: struct task { struct user *owner; unsigned int pid; int priority; char cmd[80]; }

user_defined_types: struct user { char id[80]; struct prioritylist *waiting; struct queue *done; struct user *next; }

user_defined_types: struct prioritylist { struct prio *priorities; }


releaseq

decompiled_code:
void __fastcall releaseq(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp

v1 = *(_QWORD *)ptr;
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 8);
free(*v2);
free(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp

v1 = *(_QWORD *)ptr;
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 8);
free(*v2);
free(v2);
}
free(ptr);
}

original_code:
void releaseq(TQueue * q){
  TNode * acc = q->begin, * temp;
  while(acc){
    temp = acc;
    acc = acc->next;
    free(temp->info);
    free(temp);
  }
  free(q);
}

canonical_original_code:
void releaseq(struct queue *q){
  struct node *acc = q->begin; struct node *temp;
  while(acc){
    temp = acc;
    acc = acc->next;
    free(temp->info);
    free(temp);
  }
  free(q);
}

user_defined_types: struct queue { struct node *begin; struct node *end; }

user_defined_types: struct prio { int priority; struct queue *tasks; struct prio *next; }


initializeq

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

result = malloc(0x10uLL);
result[1] = 0LL;
*result = 0LL;
return result;
}

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

result = malloc(0x10uLL);
result[1] = 0LL;
*result = 0LL;
return result;
}

original_code:
TQueue * initializeq(void){
  TQueue * q = (TQueue *)malloc(sizeof(TQueue));
  q->begin = q->end = ((void *)0);
  return q;
}

canonical_original_code:
struct queue *initializeq(){
  struct queue *q = (TQueue *)malloc(sizeof(TQueue));
  q->begin = q->end = ((void *)0);
  return q;
}

return_type: struct queue { struct node { struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *


emptyq

decompiled_code:
_BOOL8 __fastcall emptyq(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
int emptyq(TQueue * q){
  return (q->begin == ((void *)0));
}

canonical_original_code:
int emptyq(struct queue *q){
  return (q->begin == ((void *)0));
}

return_type: int


printq

decompiled_code:
int __fastcall printq(_QWORD *a1)
{
int result; // eax
_QWORD *v2; // rbx

result = emptyq(a1);
if ( !result )
{
v2 = (_QWORD *)*a1;
if ( *a1 )
{
while ( 1 )
{
result = printf(
"%d:%d:%s",
*(unsigned int *)(*v2 + 8LL),
*(unsigned int *)(*v2 + 12LL),
(const char *)(*v2 + 16LL));
v2 = (_QWORD *)v2[1];
if ( !v2 )
break;
printf(" - ");
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(_QWORD *a1)
{
int result; // eax
_QWORD *v2; // rbx

result = func3(a1);
if ( !result )
{
v2 = (_QWORD *)*a1;
if ( *a1 )
{
while ( 1 )
{
result = printf(
"%d:%d:%s",
*(unsigned int *)(*v2 + 8LL),
*(unsigned int *)(*v2 + 12LL),
(const char *)(*v2 + 16LL));
v2 = (_QWORD *)v2[1];
if ( !v2 )
break;
printf(" - ");
}
}
}
return result;
}

original_code:
void printq(TQueue * q){
  if(emptyq(q))
    return;
  TNode * acc = q->begin;
  while(acc){
    Task * task = acc->info;
    printf("%d:%d:%s", task->pid,task->priority,task->cmd);
    acc = acc->next;
    if(acc)
      printf(" - ");
  }
}

canonical_original_code:
void printq(struct queue *q){
  if(emptyq(q))
    return;
  struct node *acc = q->begin;
  while(acc){
    struct task *task = acc->info;
    printf("%d:%d:%s", task->pid,task->priority,task->cmd);
    acc = acc->next;
    if(acc)
      printf(" - ");
  }
}

variable_types: struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *


pop

original_code:
Task * pop(TQueue * q){
  if(emptyq(q))
    exit(1);
  TNode * n = q->begin;
  q->begin = n->next;
  if(!q->begin)
    q->end = ((void *)0);
  Task * t = n->info;
  free(n);
  return t;
}

canonical_original_code:
struct task *pop(struct queue *q){
  if(emptyq(q))
    exit(1);
  struct node *n = q->begin;
  q->begin = n->next;
  if(!q->begin)
    q->end = ((void *)0);
  struct task *t = n->info;
  free(n);
  return t;
}

variable_types:
q
struct queue *

return_type: struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *


decompiled_code:
int run_help()
{
system("clear");
puts("+++ HELP +++");
puts("[usuario:prioridade:comando]\t\tcria nova tarefa");
puts("file nome_arquivo\t\t\tcarrega arquivo de tarefas");
puts("print [fu,fe,ftr,user [nome],users]\timprime");
puts("make\t\t\t\t\tcarrega FU e FTR de FE");
puts("run\t\t\t\t\texecuta UMA tarefa de FTR ou FU");
puts("runall\t\t\t\t\texecuta TODAS as tarefas de FTR e FU");
puts("clear\t\t\t\t\tlimpa a tela");
puts("exit\t\t\t\t\tsai do programa");
return puts("+++ end +++\n");
}

canonical_decompiled_code:
int func0()
{
system("clear");
puts("+++ HELP +++");
puts("[usuario:prioridade:comando]\t\tcria nova tarefa");
puts("file nome_arquivo\t\t\tcarrega arquivo de tarefas");
puts("print [fu,fe,ftr,user [nome],users]\timprime");
puts("make\t\t\t\t\tcarrega FU e FTR de FE");
puts("run\t\t\t\t\texecuta UMA tarefa de FTR ou FU");
puts("runall\t\t\t\t\texecuta TODAS as tarefas de FTR e FU");
puts("clear\t\t\t\t\tlimpa a tela");
puts("exit\t\t\t\t\tsai do programa");
return puts("+++ end +++\n");
}

original_code:
void run_help(){
    system("clear");
    printf("+++ HELP +++\n");
    printf("[usuario:prioridade:comando]\t\tcria nova tarefa\n");
    printf("file nome_arquivo\t\t\tcarrega arquivo de tarefas\n");
    printf("print [fu,fe,ftr,user [nome],users]\timprime\n");
    printf("make\t\t\t\t\tcarrega FU e FTR de FE\n");
    printf("run\t\t\t\t\texecuta UMA tarefa de FTR ou FU\n");
    printf("runall\t\t\t\t\texecuta TODAS as tarefas de FTR e FU\n");
    printf("clear\t\t\t\t\tlimpa a tela\n");
    printf("exit\t\t\t\t\tsai do programa\n");
    printf("+++ end +++\n\n");
}


decompiled_code:
__int64 __fastcall run_print(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // [rsp+0h] [rbp-188h] BYREF
__int16 v4; // [rsp+4h] [rbp-184h]
char v5[128]; // [rsp+80h] [rbp-108h] BYREF
char v6; // [rsp+100h] [rbp-88h] BYREF

result = _isoc99_sscanf(a2, "%[^ ] %[^ ] %[^ ] ", &v6, &v3, v5);
if ( v3 == 7500902 )
return print_ftr(a1);
if ( (_WORD)v3 == 30054 && !BYTE2(v3) )
return print_fu(a1);
if ( v3 == 1869836390 && !(_BYTE)v4 )
return print_fpso(a1);
if ( (_WORD)v3 == 25958 && !BYTE2(v3) )
return print_fe(a1);
if ( v3 == 1919251317 && v4 == 115 )
return print_users(a1);
if ( v3 == 1919251317 && !(_BYTE)v4 )
{
result = finduser(*(_QWORD *)(a1 + 8), v5);
if ( result )
result = print_user(result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // [rsp+0h] [rbp-188h] BYREF
__int16 v4; // [rsp+4h] [rbp-184h]
char v5[128]; // [rsp+80h] [rbp-108h] BYREF
char v6; // [rsp+100h] [rbp-88h] BYREF

result = _isoc99_sscanf(a2, "%[^ ] %[^ ] %[^ ] ", &v6, &v3, v5);
if ( v3 == 7500902 )
return print_ftr(a1);
if ( (_WORD)v3 == 30054 && !BYTE2(v3) )
return print_fu(a1);
if ( v3 == 1869836390 && !(_BYTE)v4 )
return print_fpso(a1);
if ( (_WORD)v3 == 25958 && !BYTE2(v3) )
return print_fe(a1);
if ( v3 == 1919251317 && v4 == 115 )
return print_users(a1);
if ( v3 == 1919251317 && !(_BYTE)v4 )
{
result = finduser(*(_QWORD *)(a1 + 8), v5);
if ( result )
result = print_user(result);
}
return result;
}

original_code:
void run_print(TBase * base, char * cmd) {
    char command[120];
    char arg[120];
    char ex[120];
    sscanf(cmd, "%[^ ] %[^ ] %[^ ] ", ex, command, arg);
    if (!strcmp("ftr", command))
        print_ftr(base);
    else if (!strcmp("fu", command))
        print_fu(base);
    else if (!strcmp("fpso", command))
        print_fpso(base);
    else if (!strcmp("fe", command))
        print_fe(base);
    else if (!strcmp("users", command))
        print_users(base);
    else if (!strcmp("user", command)) {
        TUser * user = finduser(base->users, arg);
        if (user)
            print_user(user);
    }
}

canonical_original_code:
void run_print(struct base *base, char *cmd) {
    char command[120];
    char arg[120];
    char ex[120];
    sscanf(cmd, "%[^ ] %[^ ] %[^ ] ", ex, command, arg);
    if (!strcmp("ftr", command))
        print_ftr(base);
    else if (!strcmp("fu", command))
        print_fu(base);
    else if (!strcmp("fpso", command))
        print_fpso(base);
    else if (!strcmp("fe", command))
        print_fe(base);
    else if (!strcmp("users", command))
        print_users(base);
    else if (!strcmp("user", command)) {
        struct user *user = finduser(base->users, arg);
        if (user)
            print_user(user);
    }
}

variable_types: struct base { unsigned int pid; struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task { struct user *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *users; struct queue *FE; struct prioritylist *FU; struct queue *FTR; struct queue *FPSO; } *

variable_types:
cmd
char *

variable_types:
command
char [120]

variable_types:
arg
char [120]

variable_types:
ex
char [120]

user_defined_types: struct base { unsigned int pid; struct user *users; struct queue *FE; struct prioritylist *FU; struct queue *FTR; struct queue *FPSO; }


decompiled_code:
__int64 __fastcall run_exec(_QWORD *a1)
{
__int64 v1; // rbp

if ( (unsigned int)emptyq(a1[4]) )
{
if ( (unsigned int)emptyp(a1[3]) )
return 0LL;
v1 = toptask(a1[3]);
if ( !v1 )
return 0LL;
}
else
{
v1 = pop(a1[4]);
if ( !v1 )
return 0LL;
}
push(a1[5], v1);
return execute(v1);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 v1; // rbp

if ( (unsigned int)emptyq(a1[4]) )
{
if ( (unsigned int)emptyp(a1[3]) )
return 0LL;
v1 = toptask(a1[3]);
if ( !v1 )
return 0LL;
}
else
{
v1 = pop(a1[4]);
if ( !v1 )
return 0LL;
}
push(a1[5], v1);
return execute(v1);
}

original_code:
int run_exec(TBase * base) {
    Task * task = ((void *)0);
    if (!emptyq(base->FTR))
        task = pop(base->FTR);
    else if (!emptyp(base->FU))
        task = toptask(base->FU);
    if (task){
        push(base->FPSO,task);
        return execute(task);
    }
    return 0;
}

canonical_original_code:
int run_exec(struct base *base) {
    struct task *task = ((void *)0);
    if (!emptyq(base->FTR))
        task = pop(base->FTR);
    else if (!emptyp(base->FU))
        task = toptask(base->FU);
    if (task){
        push(base->FPSO,task);
        return execute(task);
    }
    return 0;
}


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

while ( 1 )
{
if ( (unsigned int)emptyq(a1[4]) )
{
result = emptyp(a1[3]);
if ( (_DWORD)result )
break;
}
run_exec(a1);
}
return result;
}

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

while ( 1 )
{
if ( (unsigned int)emptyq(a1[4]) )
{
result = emptyp(a1[3]);
if ( (_DWORD)result )
break;
}
func2(a1);
}
return result;
}

original_code:
void run_execall(TBase * base) {
    while (!emptyq(base->FTR) || !emptyp(base->FU))
        run_exec(base);
}

canonical_original_code:
void run_execall(struct base *base) {
    while (!emptyq(base->FTR) || !emptyp(base->FU))
        run_exec(base);
}


decompiled_code:
// attributes: thunk
__int64 run_prepare()
{
return arrange();
}

canonical_decompiled_code:
__int64 func4()
{
return arrange();
}

original_code:
void run_prepare(TBase * base) {
    arrange(base);
}

canonical_original_code:
void run_prepare(struct base *base) {
    arrange(base);
}


original_code:
int run_usercmd(TBase * base, char * cmd) {
    int i, j, value = 0;
    char end = '\0';
    char u[120] = "", p[120] = "", c[120] = "";
    for (i = 0, j = 0; cmd[i] != end; i++, j++) {
        if (cmd[i] == ':' && value < 2) {
            value++;
            j = -1;
        } else {
            if (value == 0) {
                u[j] = cmd[i];
                u[j + 1] = end;
            }
            if (value == 1) {
                p[j] = cmd[i];
                p[j + 1] = end;
            }
            if (value == 2) {
                c[j] = cmd[i];
                c[j + 1] = end;
            }
        }
    }
    if (value != 2 || u[0] == '\0' || p[0] == '\0' || c[0] == '\0')
        return 0;
    for (j = 0; p[j] != end; j++) {
        if (p[j] == '-' || p[j] < '0' || p[j] > '9') {
            printf("somente prioridade inteira positiva!\n");
            return 0;
        }
    }
    if (!base)
        return 1;
    int priority;
    sscanf(p, "%i", &priority);
    unsigned int pid = newtask(base, u, priority, c);
    printf("ID: %d\n", pid);
    return 1;
}

canonical_original_code:
int run_usercmd(struct base *base, char *cmd) {
    int i; int j; int value = 0;
    char end = '\0';
    char u[120] = ""; char p[120] = ""; char c[120] = "";
    for (i = 0, j = 0; cmd[i] != end; i++, j++) {
        if (cmd[i] == ':' && value < 2) {
            value++;
            j = -1;
        } else {
            if (value == 0) {
                u[j] = cmd[i];
                u[j + 1] = end;
            }
            if (value == 1) {
                p[j] = cmd[i];
                p[j + 1] = end;
            }
            if (value == 2) {
                c[j] = cmd[i];
                c[j + 1] = end;
            }
        }
    }
    if (value != 2 || u[0] == '\0' || p[0] == '\0' || c[0] == '\0')
        return 0;
    for (j = 0; p[j] != end; j++) {
        if (p[j] == '-' || p[j] < '0' || p[j] > '9') {
            printf("somente prioridade inteira positiva!\n");
            return 0;
        }
    }
    if (!base)
        return 1;
    int priority;
    sscanf(p, "%i", &priority);
    unsigned int pid = newtask(base, u, priority, c);
    printf("ID: %d\n", pid);
    return 1;
}

variable_types: i int

variable_types: j int

variable_types: value int

variable_types: end char

variable_types:
u
char [120]

variable_types:
p
char [120]

variable_types:
c
char [120]

variable_types: priority int

variable_types:
pid
unsigned int


decompiled_code:
__int64 __fastcall check_user_cmd(__int64 a1)
{
return run_usercmd(0LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return func5(0LL, a1);
}

original_code:
int check_user_cmd(char * cmd) {
    return run_usercmd(((void *)0), cmd);
}

canonical_original_code:
int check_user_cmd(char *cmd) {
    return run_usercmd(((void *)0), cmd);
}


command

decompiled_code:
__int64 __fastcall command(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
int v3; // [rsp+0h] [rbp-118h] BYREF
__int16 v4; // [rsp+4h] [rbp-114h]
char v5; // [rsp+6h] [rbp-112h]
char v6[152]; // [rsp+80h] [rbp-98h] BYREF

_isoc99_sscanf(a1, "%[^ ] %s", &v3, v6);
if ( v3 != 1701603686 || (_BYTE)v4 )
{
if ( v3 != 1701536109 || (_BYTE)v4 )
{
if ( v3 == 7239026 )
{
run_exec(a2);
result = 1LL;
}
else if ( v3 == 1634628978 && v4 == 27756 && !v5 )
{
run_execall(a2);
result = 1LL;
}
else if ( v3 != 1953069157 || (result = 0LL, (_BYTE)v4) )
{
if ( v3 != 1886152040 || (_BYTE)v4 )
{
if ( v3 == 1634036835 && v4 == 114 )
{
system("clear");
result = 1LL;
}
else if ( v3 == 1852404336 && v4 == 116 )
{
run_print((__int64)a2, a1);
result = 1LL;
}
else
{
if ( (unsigned int)check_user_cmd(a1) )
run_usercmd((__int64)a2, a1);
else
puts("comando inexistente");
result = 1LL;
}
}
else
{
run_help();
result = 1LL;
}
}
}
else
{
run_prepare(a2);
result = 1LL;
}
}
else
{
run_file((__int64)a2, v6);
result = 1LL;
}
return result;
}

original_code:
int command(char * cmd, TBase * base) {
    char command[120];
    char arg[120];
    sscanf(cmd, "%[^ ] %s", command, arg);
    if (!strcmp("file", command))
        run_file(base,arg);
    else if (!strcmp("make", command)) {
        run_prepare(base);
    } else if (!strcmp("run", command)) {
        run_exec(base);
    } else if (!strcmp("runall", command)) {
        run_execall(base);
    } else if (!strcmp("exit", command)) {
        return 0;
    } else if (!strcmp("help", command)) {
        run_help();
    } else if (!strcmp("clear", command)) {
        system("clear");
    } else if (!strcmp("print", command)) {
        run_print(base, cmd);
    } else if (check_user_cmd(cmd))
        run_usercmd(base, cmd);
    else
        printf("comando inexistente\n");
    return 1;
}

canonical_original_code:
int command(char *cmd, struct base *base) {
    char command[120];
    char arg[120];
    sscanf(cmd, "%[^ ] %s", command, arg);
    if (!strcmp("file", command))
        run_file(base,arg);
    else if (!strcmp("make", command)) {
        run_prepare(base);
    } else if (!strcmp("run", command)) {
        run_exec(base);
    } else if (!strcmp("runall", command)) {
        run_execall(base);
    } else if (!strcmp("exit", command)) {
        return 0;
    } else if (!strcmp("help", command)) {
        run_help();
    } else if (!strcmp("clear", command)) {
        system("clear");
    } else if (!strcmp("print", command)) {
        run_print(base, cmd);
    } else if (check_user_cmd(cmd))
        run_usercmd(base, cmd);
    else
        printf("comando inexistente\n");
    return 1;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbp
_BYTE v5[136]; // [rsp+0h] [rbp-88h] BYREF

v3 = (_QWORD *)start_base(argc, argv, envp);
run_help();
do
_isoc99_scanf(" %[^\n]s", v5);
while ( (unsigned int)command((__int64)v5, v3) );
putchar(10);
print_users(v3);
print_fe(v3);
print_ftr(v3);
print_fu(v3);
print_fpso(v3);
freebase(v3);
free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbp
_BYTE v5[136]; // [rsp+0h] [rbp-88h] BYREF

v3 = (_QWORD *)start_base(argc, argv, envp);
func0();
do
_isoc99_scanf(" %[^\n]s", v5);
while ( (unsigned int)func8((__int64)v5, v3) );
putchar(10);
print_users(v3);
print_fe(v3);
print_ftr(v3);
print_fu(v3);
print_fpso(v3);
freebase(v3);
free(v3);
return 0;
}

original_code:
int main(void) {
    TBase * base = start_base();
    char input[120];
    int loop = 1;
    run_help();
    while (loop) {
        scanf(" %[^\n]s", input);
        loop = command(input, base);
    }
    printf("\n");
    print_users(base);
    print_fe(base);
    print_ftr(base);
    print_fu(base);
    print_fpso(base);
    freebase(base);
    free(base);
    return (0);
}

canonical_original_code:
int main() {
    struct base *base = start_base();
    char input[120];
    int loop = 1;
    run_help();
    while (loop) {
        scanf(" %[^\n]s", input);
        loop = command(input, base);
    }
    printf("\n");
    print_users(base);
    print_fe(base);
    print_ftr(base);
    print_fu(base);
    print_fpso(base);
    freebase(base);
    free(base);
    return (0);
}

variable_types:
input
char [120]

variable_types: loop int


initializep

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

result = malloc(8uLL);
*result = 0LL;
return result;
}

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

result = malloc(8uLL);
*result = 0LL;
return result;
}

original_code:
PriorityList * initializep(void) {
    PriorityList * pl = (PriorityList*) malloc(sizeof (PriorityList));
    pl->priorities = ((void *)0);
    return pl;
}

canonical_original_code:
struct prioritylist *initializep() {
    struct prioritylist *pl = (PriorityList*) malloc(sizeof (PriorityList));
    pl->priorities = ((void *)0);
    return pl;
}

variable_types: struct prioritylist { struct prio { int priority; struct queue { struct node { struct task { struct user { char id[80]; struct prioritylist *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *


emptyp

decompiled_code:
_BOOL8 __fastcall emptyp(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
int emptyp(PriorityList * plist) {
    return (plist->priorities == ((void *)0));
}

canonical_original_code:
int emptyp(struct prioritylist *plist) {
    return (plist->priorities == ((void *)0));
}


addtask

decompiled_code:
// attributes: thunk
__int64 __fastcall addtask(__int64 *a1, __int64 a2)
{
return insert(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, __int64 a2)
{
return func1(a1, a2);
}

original_code:
void addtask(PriorityList * plist, Task * task) {
    _insert(plist, task);
}

canonical_original_code:
void addtask(struct prioritylist *plist, struct task *task) {
    _insert(plist, task);
}

variable_types:
task
struct task *


toptask

decompiled_code:
__int64 __fastcall toptask(char *filename)
{
__int64 v2; // r12

if ( !filename || !*(_QWORD *)filename || (unsigned int)emptyq(*(_QWORD *)(*(_QWORD *)filename + 8LL)) )
return 0LL;
v2 = pop(*(_QWORD *)(*(_QWORD *)filename + 8LL));
remove(filename);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *filename)
{
__int64 v2; // r12

if ( !filename || !*(_QWORD *)filename || (unsigned int)emptyq(*(_QWORD *)(*(_QWORD *)filename + 8LL)) )
return 0LL;
v2 = pop(*(_QWORD *)(*(_QWORD *)filename + 8LL));
func4(filename);
return v2;
}

original_code:
Task * toptask(PriorityList * plist) {
    if (plist && plist->priorities && !emptyq(plist->priorities->tasks)) {
        Task * task = pop(plist->priorities->tasks);
        _remove(plist, task);
        return task;
    }
    return ((void *)0);
}

canonical_original_code:
struct task *toptask(struct prioritylist *plist) {
    if (plist && plist->priorities && !emptyq(plist->priorities->tasks)) {
        struct task *task = pop(plist->priorities->tasks);
        _remove(plist, task);
        return task;
    }
    return ((void *)0);
}

variable_types:
plist
struct prioritylist *

variable_types: struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *


dropp

decompiled_code:
void __fastcall dropp(void *a1)
{
destroy(a1, 0);
}

canonical_decompiled_code:
void __fastcall func9(void *a1)
{
func2(a1, 0);
}

original_code:
void dropp(PriorityList * plist) {
    _destroy(plist,0);
}

canonical_original_code:
void dropp(struct prioritylist *plist) {
    _destroy(plist,0);
}


releasep

decompiled_code:
void __fastcall releasep(void *a1)
{
destroy(a1, 1);
}

canonical_decompiled_code:
void __fastcall func10(void *a1)
{
func2(a1, 1);
}

original_code:
void releasep(PriorityList * plist) {
    _destroy(plist,1);
}

canonical_original_code:
void releasep(struct prioritylist *plist) {
    _destroy(plist,1);
}


finduser

decompiled_code:
char *__fastcall finduser(char *s2, char *s1)
{
char *v2; // rbx

if ( !s1 )
return 0LL;
v2 = s2;
if ( !s2 )
return 0LL;
while ( strcmp(s1, v2) )
{
v2 = (char *)*((_QWORD *)v2 + 12);
if ( !v2 )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(char *s2, char *s1)
{
char *v2; // rbx

if ( !s1 )
return 0LL;
v2 = s2;
if ( !s2 )
return 0LL;
while ( strcmp(s1, v2) )
{
v2 = (char *)*((_QWORD *)v2 + 12);
if ( !v2 )
return 0LL;
}
return v2;
}

original_code:
TUser * finduser( TUser *ulist, char *name){
  if(!name)
    return ((void *)0);
  TUser * tmp = ulist;
  while(tmp){
    if(!strcmp(name,tmp->id))
      return tmp;
    tmp = tmp->next;
  }
  return ((void *)0);
}

canonical_original_code:
struct user *finduser(struct user *ulist, char *name){
  if(!name)
    return ((void *)0);
  struct user *tmp = ulist;
  while(tmp){
    if(!strcmp(name,tmp->id))
      return tmp;
    tmp = tmp->next;
  }
  return ((void *)0);
}

variable_types:
ulist
struct user *

variable_types:
name
char *

variable_types: struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task { struct user *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *


adduser

decompiled_code:
char *__fastcall adduser(char *a1, char *a2)
{
char *result; // rax

if ( !a2 )
return 0LL;
result = finduser(a1, a2);
if ( !result )
result = createu((__int64)a1, a2);
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *a1, char *a2)
{
char *result; // rax

if ( !a2 )
return 0LL;
result = func1(a1, a2);
if ( !result )
result = func0((__int64)a1, a2);
return result;
}

original_code:
TUser * adduser(TUser * ulist, char * name){
  if(!name)
    return ((void *)0);
  TUser * user = finduser(ulist,name);
  if(!user)
    user = _createu(ulist,name);
  return user;
}

canonical_original_code:
struct user *adduser(struct user *ulist, char *name){
  if(!name)
    return ((void *)0);
  struct user *user = finduser(ulist,name);
  if(!user)
    user = _createu(ulist,name);
  return user;
}

return_type: struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task { struct user *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *


initializeuser

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

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

original_code:
TUser * initializeuser(void){
  return ((void *)0);
}

canonical_original_code:
struct user *initializeuser(){
  return ((void *)0);
}


releaseu

decompiled_code:
void __fastcall releaseu(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)v1[12];
releasep(v2[10]);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)v1[12];
releasep(v2[10]);
free(v2);
}
while ( v1 );
}
}

original_code:
void releaseu(TUser * user){
    while(user){
       TUser * u = user;
       user = user->next;
       releasep(u->waiting);
       free(u);
    }
}

canonical_original_code:
void releaseu(struct user *user){
    while(user){
       struct user *u = user;
       user = user->next;
       releasep(u->waiting);
       free(u);
    }
}


decompiled_code:
_QWORD *start_base()
{
_QWORD *v0; // r12
__int64 v1; // rax

v0 = malloc(0x30uLL);
v0[2] = initializeq();
v0[5] = initializeq();
v0[4] = initializeq();
v0[3] = initializep();
v1 = initializeuser();
*(_DWORD *)v0 = 1;
v0[1] = v1;
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12
__int64 v1; // rax

v0 = malloc(0x30uLL);
v0[2] = initializeq();
v0[5] = initializeq();
v0[4] = initializeq();
v0[3] = initializep();
v1 = initializeuser();
*(_DWORD *)v0 = 1;
v0[1] = v1;
return v0;
}

original_code:
TBase * start_base(void) {
    TBase * base = (TBase*) malloc(sizeof (TBase));
    base->FE = initializeq();
    base->FPSO = initializeq();
    base->FTR = initializeq();
    base->FU = initializep();
    base->users = initializeuser();
    base->pid = 1;
    return base;
}

canonical_original_code:
struct base *start_base() {
    struct base *base = (TBase*) malloc(sizeof (TBase));
    base->FE = initializeq();
    base->FPSO = initializeq();
    base->FTR = initializeq();
    base->FU = initializep();
    base->users = initializeuser();
    base->pid = 1;
    return base;
}

variable_types: struct base { unsigned int pid; struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task { struct user *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *users; struct queue *FE; struct prioritylist *FU; struct queue *FTR; struct queue *FPSO; } *


arrange

decompiled_code:
__int64 __fastcall arrange(_QWORD *a1)
{
__int64 result; // rax
__int64 v2; // rsi

while ( 1 )
{
result = emptyq(a1[2]);
if ( (_DWORD)result )
break;
while ( 1 )
{
v2 = pop(a1[2]);
if ( *(_DWORD *)(v2 + 12) )
break;
push(a1[4], v2);
result = emptyq(a1[2]);
if ( (_DWORD)result )
return result;
}
addtask(a1[3], v2);
}
return result;
}

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

while ( 1 )
{
result = emptyq(a1[2]);
if ( (_DWORD)result )
break;
while ( 1 )
{
v2 = pop(a1[2]);
if ( *(_DWORD *)(v2 + 12) )
break;
push(a1[4], v2);
result = emptyq(a1[2]);
if ( (_DWORD)result )
return result;
}
addtask(a1[3], v2);
}
return result;
}

original_code:
void arrange(TBase * base) {
    while (!emptyq(base->FE)) {
        Task * task = pop(base->FE);
        if (task->priority == 0)
            push(base->FTR, task);
        else
            addtask(base->FU, task);
    }
}

canonical_original_code:
void arrange(struct base *base) {
    while (!emptyq(base->FE)) {
        struct task *task = pop(base->FE);
        if (task->priority == 0)
            push(base->FTR, task);
        else
            addtask(base->FU, task);
    }
}


decompiled_code:
int __fastcall printform_tasks(__int64 a1)
{
int result; // eax

result = emptyq(a1);
if ( !result )
{
printf(" -> ");
printq(a1);
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
int result; // eax

result = emptyq(a1);
if ( !result )
{
printf(" -> ");
printq(a1);
result = putchar(10);
}
return result;
}

original_code:
void printform_tasks(TQueue * q) {
    if (!emptyq(q)) {
        printf(" -> ");
        printq(q);
        printf("\n");
    }
}

canonical_original_code:
void printform_tasks(struct queue *q) {
    if (!emptyq(q)) {
        printf(" -> ");
        printq(q);
        printf("\n");
    }
}

variable_types: struct queue { struct node { struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *


decompiled_code:
int __fastcall printform_user(const char *a1, __int64 a2)
{
printf("%s", a1);
return printform_tasks(a2);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1, __int64 a2)
{
printf("%s", a1);
return func2(a2);
}

original_code:
void printform_user(char * name, TQueue * q) {
    printf("%s", name);
    printform_tasks(q);
}

canonical_original_code:
void printform_user(char *name, struct queue *q) {
    printf("%s", name);
    printform_tasks(q);
}


decompiled_code:
int __fastcall printform_priority(unsigned int a1, __int64 a2)
{
printf("|-%i", a1);
return printform_tasks(a2);
}

canonical_decompiled_code:
int __fastcall func4(unsigned int a1, __int64 a2)
{
printf("|-%i", a1);
return func2(a2);
}

original_code:
void printform_priority(int priority, TQueue * q) {
    printf("|-%i", priority);
    printform_tasks(q);
}

canonical_original_code:
void printform_priority(int priority, struct queue *q) {
    printf("|-%i", priority);
    printform_tasks(q);
}


decompiled_code:
int __fastcall printform_prioritylist(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
result = printform_priority(*(_DWORD *)i, *(_QWORD *)(i + 8));
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
result = func4(*(_DWORD *)i, *(_QWORD *)(i + 8));
return result;
}

original_code:
void printform_prioritylist(PriorityList * plist) {
    TPriority * tmp = plist->priorities;
    while (tmp) {
        printform_priority(tmp->priority, tmp->tasks);
        tmp = tmp->next;
    }
}

canonical_original_code:
void printform_prioritylist(struct prioritylist *plist) {
    struct prio *tmp = plist->priorities;
    while (tmp) {
        printform_priority(tmp->priority, tmp->tasks);
        tmp = tmp->next;
    }
}

variable_types: struct prio { int priority; struct queue { struct node { struct task { struct user { char id[80]; struct prioritylist { struct prio *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *


decompiled_code:
int __fastcall print_user(__int64 a1)
{
printf("*%s\n", (const char *)a1);
if ( (unsigned int)emptyp(*(_QWORD *)(a1 + 80)) )
{
if ( (unsigned int)emptyq(*(_QWORD *)(a1 + 88)) )
return puts("-----------------");
}
else
{
puts("Nao executados:");
printform_prioritylist(*(__int64 **)(a1 + 80));
if ( (unsigned int)emptyq(*(_QWORD *)(a1 + 88)) )
return puts("-----------------");
}
printf("Executados:");
printform_tasks(*(_QWORD *)(a1 + 88));
return puts("-----------------");
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
printf("*%s\n", (const char *)a1);
if ( (unsigned int)emptyp(*(_QWORD *)(a1 + 80)) )
{
if ( (unsigned int)emptyq(*(_QWORD *)(a1 + 88)) )
return puts("-----------------");
}
else
{
puts("Nao executados:");
func5(*(__int64 **)(a1 + 80));
if ( (unsigned int)emptyq(*(_QWORD *)(a1 + 88)) )
return puts("-----------------");
}
printf("Executados:");
func2(*(_QWORD *)(a1 + 88));
return puts("-----------------");
}

original_code:
void print_user(TUser * user) {
    printf("*%s\n", user->id);
    if (!emptyp(user->waiting)) {
        printf("Nao executados:\n");
        printform_prioritylist(user->waiting);
    }
    if (!emptyq(user->done)) {
        printf("Executados:");
        printform_tasks( user->done);
    }
    printf("-----------------\n");
}

canonical_original_code:
void print_user(struct user *user) {
    printf("*%s\n", user->id);
    if (!emptyp(user->waiting)) {
        printf("Nao executados:\n");
        printform_prioritylist(user->waiting);
    }
    if (!emptyq(user->done)) {
        printf("Executados:");
        printform_tasks( user->done);
    }
    printf("-----------------\n");
}


decompiled_code:
int __fastcall print_users(__int64 a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *(_QWORD *)(a1 + 8); i; i = *(_QWORD *)(i + 96) )
result = print_user(i);
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *(_QWORD *)(a1 + 8); i; i = *(_QWORD *)(i + 96) )
result = func6(i);
return result;
}

original_code:
void print_users(TBase * base) {
    TUser * user = base->users;
    while (user) {
        print_user(user);
        user = user->next;
    }
}

canonical_original_code:
void print_users(struct base *base) {
    struct user *user = base->users;
    while (user) {
        print_user(user);
        user = user->next;
    }
}


decompiled_code:
int __fastcall print_fe(__int64 a1)
{
printf("FE -> ");
printq(*(_QWORD *)(a1 + 16));
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
printf("FE -> ");
printq(*(_QWORD *)(a1 + 16));
return putchar(10);
}

original_code:
void print_fe(TBase * base) {
    printf("FE -> ");
    printq(base->FE);
    printf("\n");
}

canonical_original_code:
void print_fe(struct base *base) {
    printf("FE -> ");
    printq(base->FE);
    printf("\n");
}


decompiled_code:
int __fastcall print_ftr(__int64 a1)
{
printf("FTR -> ");
printq(*(_QWORD *)(a1 + 32));
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
printf("FTR -> ");
printq(*(_QWORD *)(a1 + 32));
return putchar(10);
}

original_code:
void print_ftr(TBase * base) {
    printf("FTR -> ");
    printq(base->FTR);
    printf("\n");
}

canonical_original_code:
void print_ftr(struct base *base) {
    printf("FTR -> ");
    printq(base->FTR);
    printf("\n");
}


decompiled_code:
int __fastcall print_fpso(__int64 a1)
{
printf("FPSO -> ");
printq(*(_QWORD *)(a1 + 40));
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
printf("FPSO -> ");
printq(*(_QWORD *)(a1 + 40));
return putchar(10);
}

original_code:
void print_fpso(TBase * base) {
    printf("FPSO -> ");
    printq(base->FPSO);
    printf("\n");
}

canonical_original_code:
void print_fpso(struct base *base) {
    printf("FPSO -> ");
    printq(base->FPSO);
    printf("\n");
}


decompiled_code:
int __fastcall print_fu(__int64 a1)
{
printf("FU");
if ( !(unsigned int)emptyp(*(_QWORD *)(a1 + 24)) )
putchar(10);
printform_prioritylist(*(__int64 **)(a1 + 24));
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
printf("FU");
if ( !(unsigned int)emptyp(*(_QWORD *)(a1 + 24)) )
putchar(10);
func5(*(__int64 **)(a1 + 24));
return putchar(10);
}

original_code:
void print_fu(TBase * base) {
    printf("FU");
    if(!emptyp(base->FU))
        printf("\n");
    printform_prioritylist(base->FU);
    printf("\n");
}

canonical_original_code:
void print_fu(struct base *base) {
    printf("FU");
    if(!emptyp(base->FU))
        printf("\n");
    printform_prioritylist(base->FU);
    printf("\n");
}


freebase

decompiled_code:
__int64 __fastcall freebase(_QWORD *a1)
{
dropq(a1[2]);
dropq(a1[5]);
dropq(a1[4]);
dropp(a1[3]);
return releaseu(a1[1]);
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
dropq(a1[2]);
dropq(a1[5]);
dropq(a1[4]);
dropp(a1[3]);
return releaseu(a1[1]);
}

original_code:
void freebase(TBase * base){
    dropq(base->FE);
    dropq(base->FPSO);
    dropq(base->FTR);
    dropp(base->FU);
    releaseu(base->users);
}

canonical_original_code:
void freebase(struct base *base){
    dropq(base->FE);
    dropq(base->FPSO);
    dropq(base->FTR);
    dropp(base->FU);
    releaseu(base->users);
}


newtask

decompiled_code:
__int64 __fastcall newtask(__int64 a1, __int64 a2, int a3, const char *a4)
{
__int64 v6; // rax
int v7; // esi
__int64 v8; // r12
unsigned int *v9; // rbp

v6 = adduser(*(_QWORD *)(a1 + 8));
v7 = *(_DWORD *)a1;
v8 = v6;
++*(_DWORD *)a1;
v9 = (unsigned int *)createtask(v6, v7, a3, a4);
waitingfor((__int64)v9);
push(*(_QWORD *)(a1 + 16), v9);
if ( !*(_QWORD *)(a1 + 8) )
*(_QWORD *)(a1 + 8) = v8;
return v9[2];
}

original_code:
int newtask(TBase * base, char * username, int priority, char * cmd){
  TUser * user = adduser(base->users,username);
  Task * newtask = _createtask(user,base->pid++,priority,cmd);
  _waitingfor(newtask);
  push(base->FE,newtask);
  if(!base->users)
      base->users = user;
  return newtask->pid;
}

canonical_original_code:
int newtask(struct base *base, char *username, int priority, char *cmd){
  struct user *user = adduser(base->users,username);
  struct task *newtask = _createtask(user,base->pid++,priority,cmd);
  _waitingfor(newtask);
  push(base->FE,newtask);
  if(!base->users)
      base->users = user;
  return newtask->pid;
}

variable_types:
username
char *

variable_types:
cmd
char *


execute

decompiled_code:
__int64 __fastcall execute(__int64 a1)
{
unsigned int v1; // er12

v1 = system((const char *)(a1 + 16));
done((__int64 *)a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v1; // er12

v1 = system((const char *)(a1 + 16));
func2((__int64 *)a1);
return v1;
}

original_code:
int execute(Task * task){
    int exec = system(task->cmd);
    _done(task);
    return exec;
}

canonical_original_code:
int execute(struct task *task){
    int exec = system(task->cmd);
    _done(task);
    return exec;
}

variable_types: exec int


sgn

repo: prinzhf/avprg

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

result = 1LL;
if ( a1 <= 0.0 )
result = (unsigned int)-(a1 < 0.0);
return result;
}

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

result = 1LL;
if ( a1 <= 0.0 )
result = (unsigned int)-(a1 < 0.0);
return result;
}

original_code:
int sgn(double x) {
   if (x > 0.0L)
     return 1.0L;
   else if (x < 0.0L)
     return -1.0L;
   else
     return 0.0L;
}

variable_types: x double


decompiled_code:
int sfx_init()
{
if ( (int)SDL_Init(16LL) < 0 )
{
puts("failed to initialize SDL Audio");
exit(1);
}
puts("SDL Audio sucessfully initialized");
if ( (int)Mix_OpenAudio(22050LL, 32784LL, 2LL, 512LL) < 0 )
puts("failed to Mix OpenAudio");
else
puts("successfully opened Audio");
if ( (int)Mix_AllocateChannels(5LL) < 0 )
{
puts("failed to allocate channel");
exit(1);
}
return puts("succesfully allocated 4 channels");
}

canonical_decompiled_code:
int func1()
{
if ( (int)SDL_Init(16LL) < 0 )
{
puts("failed to initialize SDL Audio");
exit(1);
}
puts("SDL Audio sucessfully initialized");
if ( (int)Mix_OpenAudio(22050LL, 32784LL, 2LL, 512LL) < 0 )
puts("failed to Mix OpenAudio");
else
puts("successfully opened Audio");
if ( (int)Mix_AllocateChannels(5LL) < 0 )
{
puts("failed to allocate channel");
exit(1);
}
return puts("succesfully allocated 4 channels");
}

original_code:
void sfx_init() {
 if(SDL_Init(0x00000010) < 0) {
  printf("failed to initialize SDL Audio\n");
  exit(1);
 } else {
  printf("SDL Audio sucessfully initialized\n");
 }
 if(Mix_OpenAudio(22050, 0x8010, 2, 512) < 0) {
  printf("failed to Mix OpenAudio\n");
 } else {
  printf("successfully opened Audio\n");
 }
 int channels = Mix_AllocateChannels(5);
 if(channels < 0) {
  printf("failed to allocate channel\n");
  exit(1);
 } else {
  printf("succesfully allocated 4 channels\n");
 }
}

variable_types: channels int


resetChannels

decompiled_code:
__int64 resetChannels()
{
__int64 result; // rax

result = Mix_HaltChannel(0xFFFFFFFFLL);
songpos = 0;
return result;
}

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

result = Mix_HaltChannel(0xFFFFFFFFLL);
songpos = 0;
return result;
}

original_code:
void resetChannels() {
 Mix_HaltChannel(-1);
 songpos = 0;
}


setPan

decompiled_code:
int __fastcall setPan(__int64 a1)
{
__int64 i; // rbx
float v3; // xmm0_4
__int64 v4; // rdi
int result; // eax
const char *v6; // rax

for ( i = 0LL; i != 4; ++i )
{
v3 = *(float *)(a1 + i * 4);
v4 = (unsigned int)channels[i];
if ( v3 < 0.0 && v3 >= -1.0 )
{
result = Mix_SetPanning(
v4,
(unsigned __int8)(int)(float)(COERCE_FLOAT(LODWORD(v3) ^ LC11) * 255.0),
(unsigned __int8)(int)(float)((float)(v3 + 1.0) * 255.0));
if ( result )
continue;
goto LABEL_10;
}
if ( v3 <= 0.0 || v3 > 1.0 )
{
result = Mix_SetPanning(v4, 255LL, 255LL);
if ( result )
continue;
LABEL_10:
v6 = (const char *)SDL_GetError();
result = printf("Mix_SetPanning: %s\n", v6);
continue;
}
result = Mix_SetPanning(
v4,
(unsigned __int8)(int)(float)((float)(1.0 - v3) * 255.0),
(unsigned __int8)(int)(float)(v3 * 255.0));
if ( !result )
goto LABEL_10;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
__int64 i; // rbx
float v3; // xmm0_4
__int64 v4; // rdi
int result; // eax
const char *v6; // rax

for ( i = 0LL; i != 4; ++i )
{
v3 = *(float *)(a1 + i * 4);
v4 = (unsigned int)channels[i];
if ( v3 < 0.0 && v3 >= -1.0 )
{
result = Mix_SetPanning(
v4,
(unsigned __int8)(int)(float)(COERCE_FLOAT(LODWORD(v3) ^ LC11) * 255.0),
(unsigned __int8)(int)(float)((float)(v3 + 1.0) * 255.0));
if ( result )
continue;
goto LABEL_10;
}
if ( v3 <= 0.0 || v3 > 1.0 )
{
result = Mix_SetPanning(v4, 255LL, 255LL);
if ( result )
continue;
LABEL_10:
v6 = (const char *)SDL_GetError();
result = printf("Mix_SetPanning: %s\n", v6);
continue;
}
result = Mix_SetPanning(
v4,
(unsigned __int8)(int)(float)((float)(1.0 - v3) * 255.0),
(unsigned __int8)(int)(float)(v3 * 255.0));
if ( !result )
goto LABEL_10;
}
return result;
}

original_code:
void setPan(float* pans) {
 int i;
 for(i = 0; i < 4; i++) {
  if(pans[i] < 0.0 && pans[i] >= -1.0) {
   if(!Mix_SetPanning(channels[i], (int)(255*(pans[i]*(-1))), (int)(255*(1-(pans[i]*(-1)))))) {
       printf("Mix_SetPanning: %s\n", SDL_GetError());
      }
     } else if(pans[i] > 0.0 && pans[i] <= 1.0){
      if(!Mix_SetPanning(channels[i], (int) (255*(1-pans[i])), 255*pans[i])) {
       printf("Mix_SetPanning: %s\n", SDL_GetError());
      }
     } else {
      if(!Mix_SetPanning(channels[i], 255, 255)) {
       printf("Mix_SetPanning: %s\n", SDL_GetError());
      }
     }
 }
}

canonical_original_code:
void setPan(float *pans) {
 int i;
 for(i = 0; i < 4; i++) {
  if(pans[i] < 0.0 && pans[i] >= -1.0) {
   if(!Mix_SetPanning(channels[i], (int)(255*(pans[i]*(-1))), (int)(255*(1-(pans[i]*(-1)))))) {
       printf("Mix_SetPanning: %s\n", SDL_GetError());
      }
     } else if(pans[i] > 0.0 && pans[i] <= 1.0){
      if(!Mix_SetPanning(channels[i], (int) (255*(1-pans[i])), 255*pans[i])) {
       printf("Mix_SetPanning: %s\n", SDL_GetError());
      }
     } else {
      if(!Mix_SetPanning(channels[i], 255, 255)) {
       printf("Mix_SetPanning: %s\n", SDL_GetError());
      }
     }
 }
}

variable_types:
pans
float *

variable_types: i int


handleADSR

original_code:
float handleADSR(int i, int num, float amp, float finalAmp, int atc, int dec, int sus, int rel) {
 if(atc == 1 && rel == 1)
  return finalAmp;
 if(i == 0)
  amp = 0.001f;
 float adsr = 0.0f;
 if(atc != 1 && atc != 0 && amp <= finalAmp && i <= (int)(chunks[num]->alen/atc)) {
  amp += (float)((chunks[num]->alen/atc)*0.00000001);
  return amp;
 } else if(rel != 1 && rel != 0 && i > (chunks[num]->alen/rel)) {
  amp -= (float)((chunks[num]->alen/rel)*0.00000001);
  return amp;
 } else {
   return finalAmp;
 }
}

variable_types: num int

variable_types: amp float

variable_types: finalAmp float

variable_types: atc int

variable_types: dec int

variable_types: sus int

variable_types: rel int

variable_types: adsr float

return_type: float


generateSineChunk

original_code:
Uint8* generateSineChunk(float freq, int num, float amp, int atc, int rel, int sus, int dec) {
 int i;
 double generated;
 float finalAmp = amp;
 for(i = 0; i < 44100; i++) {
  amp = handleADSR(i, num, amp, finalAmp, atc, decs[num], sus, rels[num]);
  generated = (32767*amp)*sin((3.14159265358979323846*2.0)*freq*i/44100);
  ((Sint16*) streams[num])[i] = ((Sint16) generated);
 }
 return (Uint8*) streams[num];
}

canonical_original_code:
unsigned char *generateSineChunk(float freq, int num, float amp, int atc, int rel, int sus, int dec) {
 int i;
 double generated;
 float finalAmp = amp;
 for(i = 0; i < 44100; i++) {
  amp = handleADSR(i, num, amp, finalAmp, atc, decs[num], sus, rels[num]);
  generated = (32767*amp)*sin((3.14159265358979323846*2.0)*freq*i/44100);
  ((short *) streams[num])[i] = ((short) generated);
 }
 return (unsigned char *) streams[num];
}

variable_types: freq float

variable_types: generated double

return_type: unsigned char *


playChannels

decompiled_code:
__int64 __fastcall playChannels(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v6; // rbx
float v7; // xmm0_4
int v8; // eax
unsigned int v9; // er8
unsigned int v10; // ecx
__int64 v11; // rdx
unsigned int v12; // esi
__m128 v13; // xmm1
__int64 v14; // r15
__int64 v15; // rsi
__int64 v16; // rdi
int v17; // eax
__int64 result; // rax

v6 = 0LL;
setPan((__int64)&pans);
do
{
v7 = *(float *)(a1 + 4 * v6);
if ( v7 == -1.0 )
{
result = Mix_ExpireChannel((unsigned int)channels[v6], 0xFFFFFFFFLL);
goto LABEL_11;
}
v8 = *(_DWORD *)(a3 + 4 * v6);
v9 = decs[v6];
v10 = suss[v6];
v11 = (unsigned int)rels[v6];
v12 = atcs[v6];
v13 = (__m128)*(unsigned int *)(a2 + 4 * v6);
v14 = chunks[v6];
if ( v8 == 4 )
{
*(_QWORD *)(v14 + 8) = generateSawChunk(v6, v12, v11, v10, v9, v7, v13);
goto LABEL_8;
}
if ( v8 > 4 )
{
if ( v8 != 5 )
goto LABEL_16;
*(_QWORD *)(v14 + 8) = generateNoiseChunk(v6, v12, v11, v10, v9, v7, v13);
}
else
{
if ( v8 == 1 )
{
*(_QWORD *)(v14 + 8) = generateSineChunk(v6, v12, v7, v13, v11, v10);
goto LABEL_8;
}
if ( v8 != 3 )
{
LABEL_16:
*(_QWORD *)(v14 + 8) = generateSquareChunk(v6, v12, v11, v10, v9, v7, v13);
goto LABEL_8;
}
*(_QWORD *)(v14 + 8) = generateTriangleChunk(v6, v12, v11, v10, v9, v7, v13);
}
LABEL_8:
v15 = chunks[v6];
v16 = (unsigned int)channels[v6];
v17 = suss[v6] << 12;
if ( suss[v6] == 1 )
v17 = 44100;
*(_DWORD *)(v15 + 16) = v17;
result = Mix_PlayChannelTimed(v16, v15, 0LL, 0xFFFFFFFFLL);
LABEL_11:
++v6;
}
while ( v6 != 4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v6; // rbx
float v7; // xmm0_4
int v8; // eax
unsigned int v9; // er8
unsigned int v10; // ecx
__int64 v11; // rdx
unsigned int v12; // esi
__m128 v13; // xmm1
__int64 v14; // r15
__int64 v15; // rsi
__int64 v16; // rdi
int v17; // eax
__int64 result; // rax

v6 = 0LL;
func4((__int64)&pans);
do
{
v7 = *(float *)(a1 + 4 * v6);
if ( v7 == -1.0 )
{
result = Mix_ExpireChannel((unsigned int)channels[v6], 0xFFFFFFFFLL);
goto LABEL_11;
}
v8 = *(_DWORD *)(a3 + 4 * v6);
v9 = decs[v6];
v10 = suss[v6];
v11 = (unsigned int)rels[v6];
v12 = atcs[v6];
v13 = (__m128)*(unsigned int *)(a2 + 4 * v6);
v14 = chunks[v6];
if ( v8 == 4 )
{
*(_QWORD *)(v14 + 8) = generateSawChunk(v6, v12, v11, v10, v9, v7, v13);
goto LABEL_8;
}
if ( v8 > 4 )
{
if ( v8 != 5 )
goto LABEL_16;
*(_QWORD *)(v14 + 8) = generateNoiseChunk(v6, v12, v11, v10, v9, v7, v13);
}
else
{
if ( v8 == 1 )
{
*(_QWORD *)(v14 + 8) = func6(v6, v12, v7, v13, v11, v10);
goto LABEL_8;
}
if ( v8 != 3 )
{
LABEL_16:
*(_QWORD *)(v14 + 8) = generateSquareChunk(v6, v12, v11, v10, v9, v7, v13);
goto LABEL_8;
}
*(_QWORD *)(v14 + 8) = generateTriangleChunk(v6, v12, v11, v10, v9, v7, v13);
}
LABEL_8:
v15 = chunks[v6];
v16 = (unsigned int)channels[v6];
v17 = suss[v6] << 12;
if ( suss[v6] == 1 )
v17 = 44100;
*(_DWORD *)(v15 + 16) = v17;
result = Mix_PlayChannelTimed(v16, v15, 0LL, 0xFFFFFFFFLL);
LABEL_11:
++v6;
}
while ( v6 != 4 );
return result;
}

original_code:
void playChannels(float* freqs, float* amps, int* waveforms, CHANNEL* chan) {
 int i;
 setPan(pans);
 for(i = 0; i < 4; i++){
  if(freqs[i] != -1.0) {
   switch(waveforms[i]) {
    case 1: chunks[i]->abuf = generateSineChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 2: chunks[i]->abuf = generateSquareChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 3: chunks[i]->abuf = generateTriangleChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 4: chunks[i]->abuf = generateSawChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 5: chunks[i]->abuf = generateNoiseChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    default: chunks[i]->abuf = generateSquareChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
   }
   if(suss[i] != 1)
    chunks[i]->alen = (4096*suss[i]);
   else
    chunks[i]->alen = 44100;
   Mix_PlayChannelTimed(channels[i],chunks[i],0,-1);
  } else {
   Mix_ExpireChannel(channels[i], -1);
  }
 }
}

canonical_original_code:
void playChannels(float *freqs, float *amps, int *waveforms, struct channel *chan) {
 int i;
 setPan(pans);
 for(i = 0; i < 4; i++){
  if(freqs[i] != -1.0) {
   switch(waveforms[i]) {
    case 1: chunks[i]->abuf = generateSineChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 2: chunks[i]->abuf = generateSquareChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 3: chunks[i]->abuf = generateTriangleChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 4: chunks[i]->abuf = generateSawChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 5: chunks[i]->abuf = generateNoiseChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    default: chunks[i]->abuf = generateSquareChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
   }
   if(suss[i] != 1)
    chunks[i]->alen = (4096*suss[i]);
   else
    chunks[i]->alen = 44100;
   Mix_PlayChannelTimed(channels[i],chunks[i],0,-1);
  } else {
   Mix_ExpireChannel(channels[i], -1);
  }
 }
}

variable_types:
freqs
float *

variable_types:
amps
float *

variable_types:
waveforms
int *

variable_types: struct channel { unsigned char line; int tempo; char name[128]; char description[128]; struct channel_values { unsigned int waveform; float amp; float pan; char tone[3]; float freq; int atc; int dec; int sus; int rel; char wholeChan[128]; } *chanval[4]; int lines; } *

user_defined_types: struct channel { unsigned char line; int tempo; char name[128]; char description[128]; struct channel_values *chanval[4]; int lines; }


timerCallback

decompiled_code:
__int64 __fastcall timerCallback(unsigned int a1)
{
__int64 v1; // rcx
__int64 v3; // rsi
unsigned __int64 i; // rax
__int64 v5; // rdx
int *v6; // rdx
int v7; // edi
int v8; // xmm0_4
int v9; // edi
int v10; // xmm0_4
int v11; // edi
int v12; // edi

v1 = chan;
if ( *(_DWORD *)(chan + 296) <= songpos )
{
songpos = 0;
v3 = 0LL;
}
else
{
v3 = 164LL * songpos;
}
for ( i = 0LL; i != 16; decs[i / 4 - 1] = (int)v6 )
{
v5 = *(_QWORD *)(v1 + 2 * i + 264);
i += 4LL;
v6 = (int *)(v3 + v5);
v7 = *v6;
freqs[i / 4 - 1] = v6[4];
v8 = v6[1];
waveforms[i / 4 - 1] = v7;
v9 = v6[5];
amps[i / 4 - 1] = v8;
v10 = v6[2];
atcs[i / 4 - 1] = v9;
v11 = v6[7];
pans[i / 4 - 1] = v10;
suss[i / 4 - 1] = v11;
v12 = v6[8];
LODWORD(v6) = v6[6];
rels[i / 4 - 1] = v12;
}
playChannels((__int64)freqs, (__int64)amps, (__int64)waveforms);
++songpos;
moveSong(window, chan);
return a1;
}

original_code:
Uint32 timerCallback(Uint32 intervall, void *parameter) {
 int i;
 if(songpos >= chan->lines)
  songpos = 0;
 for(i = 0; i < 4; i++) {
  freqs[i] = chan->chanval[i][songpos].freq;
  amps[i] = chan->chanval[i][songpos].amp;
  waveforms[i] = chan->chanval[i][songpos].waveform;
  pans[i] = chan->chanval[i][songpos].pan;
  atcs[i] = chan->chanval[i][songpos].atc;
  suss[i] = chan->chanval[i][songpos].sus;
  rels[i] = chan->chanval[i][songpos].rel;
  decs[i] = chan->chanval[i][songpos].dec;
 }
 playChannels(freqs, amps, waveforms, chan);
 songpos++;
 moveSong(window, chan, songpos);
 return intervall;
}

canonical_original_code:
unsigned int timerCallback(unsigned int intervall, void *parameter) {
 int i;
 if(songpos >= chan->lines)
  songpos = 0;
 for(i = 0; i < 4; i++) {
  freqs[i] = chan->chanval[i][songpos].freq;
  amps[i] = chan->chanval[i][songpos].amp;
  waveforms[i] = chan->chanval[i][songpos].waveform;
  pans[i] = chan->chanval[i][songpos].pan;
  atcs[i] = chan->chanval[i][songpos].atc;
  suss[i] = chan->chanval[i][songpos].sus;
  rels[i] = chan->chanval[i][songpos].rel;
  decs[i] = chan->chanval[i][songpos].dec;
 }
 playChannels(freqs, amps, waveforms, chan);
 songpos++;
 moveSong(window, chan, songpos);
 return intervall;
}

variable_types:
intervall
unsigned int

variable_types:
parameter
void *

return_type: unsigned int


getNoteFrequency

decompiled_code:
double __fastcall getNoteFrequency(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx
double result; // xmm0_8

v2 = (const char *)&unk_4DA;
v3 = 0LL;
do
{
if ( !strcmp(v2, s2) )
{
*(_QWORD *)&result = (unsigned int)frequencedNotes[(int)v3];
return result;
}
++v3;
v2 = (const char *)*(&namedNotes + v3);
}
while ( v2 );
return 0.0;
}

canonical_decompiled_code:
double __fastcall func0(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx
double result; // xmm0_8

v2 = (const char *)&unk_4DA;
v3 = 0LL;
do
{
if ( !strcmp(v2, s2) )
{
*(_QWORD *)&result = (unsigned int)frequencedNotes[(int)v3];
return result;
}
++v3;
v2 = (const char *)*(&namedNotes + v3);
}
while ( v2 );
return 0.0;
}

original_code:
float getNoteFrequency(char noteName[]) {
     int i;
     float frequency = 0.0;
     for(i = 0; namedNotes[i]; i++) {
             if(strcmp(namedNotes[i], noteName) == 0) {
             frequency = frequencedNotes[i];
             return frequency;
         }
     }
     return 0.0;
}

variable_types:
noteName
char []

variable_types: i int

variable_types: frequency float


nrerror

repo: prjemian/lake

decompiled_code:
void __fastcall __noreturn nrerror(const char *a1)
{
fwrite("Numerical Recipes run-time error...\n", 1uLL, 0x24uLL, stderr);
fprintf(stderr, "%s\n", a1);
fwrite("...now exiting to system...\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fwrite("Numerical Recipes run-time error...\n", 1uLL, 0x24uLL, stderr);
fprintf(stderr, "%s\n", a1);
fwrite("...now exiting to system...\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}

original_code:
void nrerror(char error_text[])
{
    fprintf(stderr,"Numerical Recipes run-time error...\n");
    fprintf(stderr,"%s\n",error_text);
    fprintf(stderr,"...now exiting to system...\n");
    exit(1);
}


vector

decompiled_code:
char *__fastcall vector(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(4 * (a2 - a1) + 8);
if ( !v2 )
nrerror("allocation failure in vector()");
return &v2[4 * (1 - a1)];
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(4 * (a2 - a1) + 8);
if ( !v2 )
func0("allocation failure in vector()");
return &v2[4 * (1 - a1)];
}

original_code:
float *vector(long nl, long nh)
{
    float *v;
    v=(float *)malloc((size_t) ((nh-nl+1+1)*sizeof(float)));
    if (!v) nrerror("allocation failure in vector()");
    return v-nl+1;
}

canonical_original_code:
float *vector(long nl, long nh)
{
    float *v;
    v=(float *)malloc((unsigned long) ((nh-nl+1+1)*sizeof(float)));
    if (!v) nrerror("allocation failure in vector()");
    return v-nl+1;
}

variable_types: nl long

variable_types: nh long

variable_types:
v
float *

return_type: float *


ivector

decompiled_code:
char *__fastcall ivector(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(4 * (a2 - a1) + 8);
if ( !v2 )
nrerror("allocation failure in ivector()");
return &v2[4 * (1 - a1)];
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(4 * (a2 - a1) + 8);
if ( !v2 )
func0("allocation failure in ivector()");
return &v2[4 * (1 - a1)];
}

original_code:
int *ivector(long nl, long nh)
{
    int *v;
    v=(int *)malloc((size_t) ((nh-nl+1+1)*sizeof(int)));
    if (!v) nrerror("allocation failure in ivector()");
    return v-nl+1;
}

canonical_original_code:
int *ivector(long nl, long nh)
{
    int *v;
    v=(int *)malloc((unsigned long) ((nh-nl+1+1)*sizeof(int)));
    if (!v) nrerror("allocation failure in ivector()");
    return v-nl+1;
}

variable_types:
v
int *

return_type: int *


cvector

decompiled_code:
__int64 __fastcall cvector(__int64 a1, __int64 a2)
{
void *v2; // rax

v2 = malloc(a2 - a1 + 2);
if ( !v2 )
nrerror("allocation failure in cvector()");
return (__int64)v2 - a1 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
void *v2; // rax

v2 = malloc(a2 - a1 + 2);
if ( !v2 )
func0("allocation failure in cvector()");
return (__int64)v2 - a1 + 1;
}

original_code:
unsigned char *cvector(long nl, long nh)
{
    unsigned char *v;
    v=(unsigned char *)malloc((size_t) ((nh-nl+1+1)*sizeof(unsigned char)));
    if (!v) nrerror("allocation failure in cvector()");
    return v-nl+1;
}

canonical_original_code:
unsigned char *cvector(long nl, long nh)
{
    unsigned char *v;
    v=(unsigned char *)malloc((unsigned long) ((nh-nl+1+1)*sizeof(unsigned char)));
    if (!v) nrerror("allocation failure in cvector()");
    return v-nl+1;
}

variable_types:
v
unsigned char *


lvector

decompiled_code:
char *__fastcall lvector(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(8 * (a2 - a1) + 16);
if ( !v2 )
nrerror("allocation failure in lvector()");
return &v2[8 * (1 - a1)];
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(8 * (a2 - a1) + 16);
if ( !v2 )
func0("allocation failure in lvector()");
return &v2[8 * (1 - a1)];
}

original_code:
unsigned long *lvector(long nl, long nh)
{
    unsigned long *v;
    v=(unsigned long *)malloc((size_t) ((nh-nl+1+1)*sizeof(long)));
    if (!v) nrerror("allocation failure in lvector()");
    return v-nl+1;
}

canonical_original_code:
unsigned long *lvector(long nl, long nh)
{
    unsigned long *v;
    v=(unsigned long *)malloc((unsigned long) ((nh-nl+1+1)*sizeof(long)));
    if (!v) nrerror("allocation failure in lvector()");
    return v-nl+1;
}

variable_types:
v
unsigned long *

return_type: unsigned long *


dvector

decompiled_code:
char *__fastcall dvector(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(8 * (a2 - a1) + 16);
if ( !v2 )
nrerror("allocation failure in dvector()");
return &v2[8 * (1 - a1)];
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(8 * (a2 - a1) + 16);
if ( !v2 )
func0("allocation failure in dvector()");
return &v2[8 * (1 - a1)];
}

original_code:
double *dvector(long nl, long nh)
{
    double *v;
    v=(double *)malloc((size_t) ((nh-nl+1+1)*sizeof(double)));
    if (!v) nrerror("allocation failure in dvector()");
    return v-nl+1;
}

canonical_original_code:
double *dvector(long nl, long nh)
{
    double *v;
    v=(double *)malloc((unsigned long) ((nh-nl+1+1)*sizeof(double)));
    if (!v) nrerror("allocation failure in dvector()");
    return v-nl+1;
}

variable_types:
v
double *

return_type: double *


matrix

original_code:
float **matrix(long nrl, long nrh, long ncl, long nch)
{
    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    float **m;
    m=(float **) malloc((size_t)((nrow+1)*sizeof(float*)));
    if (!m) nrerror("allocation failure 1 in matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=(float *) malloc((size_t)((nrow*ncol+1)*sizeof(float)));
    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
    m[nrl] += 1;
    m[nrl] -= ncl;
    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    return m;
}

canonical_original_code:
float **matrix(long nrl, long nrh, long ncl, long nch)
{
    long i; long nrow = nrh-nrl+1; long ncol = nch-ncl+1;
    float **m;
    m=(float **) malloc((unsigned long)((nrow+1)*sizeof(float *)));
    if (!m) nrerror("allocation failure 1 in matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=(float *) malloc((unsigned long)((nrow*ncol+1)*sizeof(float)));
    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
    m[nrl] += 1;
    m[nrl] -= ncl;
    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    return m;
}

variable_types: nrl long

variable_types: nrh long

variable_types: ncl long

variable_types: nch long

variable_types: i long

variable_types: nrow long

variable_types: ncol long

variable_types:
m
float **

return_type: float **


dmatrix

original_code:
double **dmatrix(long nrl, long nrh, long ncl, long nch)
{
    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    double **m;
    m=(double **) malloc((size_t)((nrow+1)*sizeof(double*)));
    if (!m) nrerror("allocation failure 1 in matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=(double *) malloc((size_t)((nrow*ncol+1)*sizeof(double)));
    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
    m[nrl] += 1;
    m[nrl] -= ncl;
    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    return m;
}

canonical_original_code:
double **dmatrix(long nrl, long nrh, long ncl, long nch)
{
    long i; long nrow = nrh-nrl+1; long ncol = nch-ncl+1;
    double **m;
    m=(double **) malloc((unsigned long)((nrow+1)*sizeof(double *)));
    if (!m) nrerror("allocation failure 1 in matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=(double *) malloc((unsigned long)((nrow*ncol+1)*sizeof(double)));
    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
    m[nrl] += 1;
    m[nrl] -= ncl;
    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    return m;
}

variable_types:
m
double **

return_type: double **


imatrix

original_code:
int **imatrix(long nrl, long nrh, long ncl, long nch)
{
    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    int **m;
    m=(int **) malloc((size_t)((nrow+1)*sizeof(int*)));
    if (!m) nrerror("allocation failure 1 in matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=(int *) malloc((size_t)((nrow*ncol+1)*sizeof(int)));
    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
    m[nrl] += 1;
    m[nrl] -= ncl;
    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    return m;
}

canonical_original_code:
int **imatrix(long nrl, long nrh, long ncl, long nch)
{
    long i; long nrow = nrh-nrl+1; long ncol = nch-ncl+1;
    int **m;
    m=(int **) malloc((unsigned long)((nrow+1)*sizeof(int *)));
    if (!m) nrerror("allocation failure 1 in matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=(int *) malloc((unsigned long)((nrow*ncol+1)*sizeof(int)));
    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
    m[nrl] += 1;
    m[nrl] -= ncl;
    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    return m;
}

variable_types:
m
int **

return_type: int **


submatrix

original_code:
float **submatrix(float **a, long oldrl, long oldrh, long oldcl, long oldch,
    long newrl, long newcl)
{
    long i,j,nrow=oldrh-oldrl+1,ncol=oldcl-newcl;
    float **m;
    m=(float **) malloc((size_t) ((nrow+1)*sizeof(float*)));
    if (!m) nrerror("allocation failure in submatrix()");
    m += 1;
    m -= newrl;
    for(i=oldrl,j=newrl;i<=oldrh;i++,j++) m[j]=a[i]+ncol;
    return m;
}

canonical_original_code:
float **submatrix(float **a, long oldrl, long oldrh, long oldcl, long oldch, long newrl, long newcl)
{
    long i; long j; long nrow = oldrh-oldrl+1; long ncol = oldcl-newcl;
    float **m;
    m=(float **) malloc((unsigned long) ((nrow+1)*sizeof(float *)));
    if (!m) nrerror("allocation failure in submatrix()");
    m += 1;
    m -= newrl;
    for(i=oldrl,j=newrl;i<=oldrh;i++,j++) m[j]=a[i]+ncol;
    return m;
}

variable_types:
a
float **

variable_types: oldrl long

variable_types: oldrh long

variable_types: oldcl long

variable_types: oldch long

variable_types: newrl long

variable_types: newcl long

variable_types: j long


original_code:
float **convert_matrix(float *a, long nrl, long nrh, long ncl, long nch)
{
    long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1;
    float **m;
    m=(float **) malloc((size_t) ((nrow+1)*sizeof(float*)));
    if (!m) nrerror("allocation failure in convert_matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=a-ncl;
    for(i=1,j=nrl+1;i<nrow;i++,j++) m[j]=m[j-1]+ncol;
    return m;
}

canonical_original_code:
float **convert_matrix(float *a, long nrl, long nrh, long ncl, long nch)
{
    long i; long j; long nrow = nrh-nrl+1; long ncol = nch-ncl+1;
    float **m;
    m=(float **) malloc((unsigned long) ((nrow+1)*sizeof(float *)));
    if (!m) nrerror("allocation failure in convert_matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=a-ncl;
    for(i=1,j=nrl+1;i<nrow;i++,j++) m[j]=m[j-1]+ncol;
    return m;
}

variable_types:
a
float *

variable_types: nrl long

variable_types: nrh long


original_code:
float ***f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
{
    long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
    float ***t;
    t=(float ***) malloc((size_t)((nrow+1)*sizeof(float**)));
    if (!t) nrerror("allocation failure 1 in f3tensor()");
    t += 1;
    t -= nrl;
    t[nrl]=(float **) malloc((size_t)((nrow*ncol+1)*sizeof(float*)));
    if (!t[nrl]) nrerror("allocation failure 2 in f3tensor()");
    t[nrl] += 1;
    t[nrl] -= ncl;
    t[nrl][ncl]=(float *) malloc((size_t)((nrow*ncol*ndep+1)*sizeof(float)));
    if (!t[nrl][ncl]) nrerror("allocation failure 3 in f3tensor()");
    t[nrl][ncl] += 1;
    t[nrl][ncl] -= ndl;
    for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
    for(i=nrl+1;i<=nrh;i++) {
        t[i]=t[i-1]+ncol;
        t[i][ncl]=t[i-1][ncl]+ncol*ndep;
        for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
    }
    return t;
}

canonical_original_code:
float ***f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
{
    long i; long j; long nrow = nrh-nrl+1; long ncol = nch-ncl+1; long ndep = ndh-ndl+1;
    float ***t;
    t=(float ***) malloc((unsigned long)((nrow+1)*sizeof(float **)));
    if (!t) nrerror("allocation failure 1 in f3tensor()");
    t += 1;
    t -= nrl;
    t[nrl]=(float **) malloc((unsigned long)((nrow*ncol+1)*sizeof(float *)));
    if (!t[nrl]) nrerror("allocation failure 2 in f3tensor()");
    t[nrl] += 1;
    t[nrl] -= ncl;
    t[nrl][ncl]=(float *) malloc((unsigned long)((nrow*ncol*ndep+1)*sizeof(float)));
    if (!t[nrl][ncl]) nrerror("allocation failure 3 in f3tensor()");
    t[nrl][ncl] += 1;
    t[nrl][ncl] -= ndl;
    for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
    for(i=nrl+1;i<=nrh;i++) {
        t[i]=t[i-1]+ncol;
        t[i][ncl]=t[i-1][ncl]+ncol*ndep;
        for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
    }
    return t;
}

variable_types: ncl long

variable_types: nch long

variable_types: ndl long

variable_types: ndh long

variable_types: i long

variable_types: ndep long

variable_types:
t
float ***

return_type: float ***


decompiled_code:
void __fastcall free_vector(__int64 a1, __int64 a2)
{
free((void *)(a1 + 4 * a2 - 4));
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, __int64 a2)
{
free((void *)(a1 + 4 * a2 - 4));
}

original_code:
void free_vector(float *v, long nl, long nh)
{
    free((char*) (v+nl-1));
}

canonical_original_code:
void free_vector(float *v, long nl, long nh)
{
    free((char *) (v+nl-1));
}

variable_types:
v
float *

variable_types: nl long

variable_types: nh long


decompiled_code:
// attributes: thunk
void __fastcall free_ivector(__int64 a1, __int64 a2)
{
free_vector(a1, a2);
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, __int64 a2)
{
func12(a1, a2);
}

original_code:
void free_ivector(int *v, long nl, long nh)
{
    free((char*) (v+nl-1));
}

canonical_original_code:
void free_ivector(int *v, long nl, long nh)
{
    free((char *) (v+nl-1));
}

variable_types:
v
int *


decompiled_code:
void __fastcall free_cvector(__int64 a1, __int64 a2)
{
free((void *)(a1 + a2 - 1));
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, __int64 a2)
{
free((void *)(a1 + a2 - 1));
}

original_code:
void free_cvector(unsigned char *v, long nl, long nh)
{
    free((char*) (v+nl-1));
}

canonical_original_code:
void free_cvector(unsigned char *v, long nl, long nh)
{
    free((char *) (v+nl-1));
}

variable_types:
v
unsigned char *


decompiled_code:
void __fastcall free_lvector(__int64 a1, __int64 a2)
{
free((void *)(a1 + 8 * a2 - 8));
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, __int64 a2)
{
free((void *)(a1 + 8 * a2 - 8));
}

original_code:
void free_lvector(unsigned long *v, long nl, long nh)
{
    free((char*) (v+nl-1));
}

canonical_original_code:
void free_lvector(unsigned long *v, long nl, long nh)
{
    free((char *) (v+nl-1));
}

variable_types:
v
unsigned long *


decompiled_code:
// attributes: thunk
void __fastcall free_dvector(__int64 a1, __int64 a2)
{
free_lvector(a1, a2);
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1, __int64 a2)
{
func15(a1, a2);
}

original_code:
void free_dvector(double *v, long nl, long nh)
{
    free((char*) (v+nl-1));
}

canonical_original_code:
void free_dvector(double *v, long nl, long nh)
{
    free((char *) (v+nl-1));
}

variable_types:
v
double *


original_code:
void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
{
    free((char*) (m[nrl]+ncl-1));
    free((char*) (m+nrl-1));
}

canonical_original_code:
void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
{
    free((char *) (m[nrl]+ncl-1));
    free((char *) (m+nrl-1));
}

variable_types:
m
float **


original_code:
void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch)
{
    free((char*) (m[nrl]+ncl-1));
    free((char*) (m+nrl-1));
}

canonical_original_code:
void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch)
{
    free((char *) (m[nrl]+ncl-1));
    free((char *) (m+nrl-1));
}

variable_types:
m
double **

variable_types: nrl long


original_code:
void free_imatrix(int **m, long nrl, long nrh, long ncl, long nch)
{
    free((char*) (m[nrl]+ncl-1));
    free((char*) (m+nrl-1));
}

canonical_original_code:
void free_imatrix(int **m, long nrl, long nrh, long ncl, long nch)
{
    free((char *) (m[nrl]+ncl-1));
    free((char *) (m+nrl-1));
}

variable_types:
m
int **

variable_types: nrh long

variable_types: ncl long


decompiled_code:
void __fastcall free_submatrix(__int64 a1, __int64 a2)
{
free((void *)(a1 + 8 * a2 - 8));
}

canonical_decompiled_code:
void __fastcall func20(__int64 a1, __int64 a2)
{
free((void *)(a1 + 8 * a2 - 8));
}

original_code:
void free_submatrix(float **b, long nrl, long nrh, long ncl, long nch)
{
    free((char*) (b+nrl-1));
}

canonical_original_code:
void free_submatrix(float **b, long nrl, long nrh, long ncl, long nch)
{
    free((char *) (b+nrl-1));
}

variable_types:
b
float **

variable_types: nch long


decompiled_code:
// attributes: thunk
void __fastcall free_convert_matrix(__int64 a1, __int64 a2)
{
free_submatrix(a1, a2);
}

canonical_decompiled_code:
void __fastcall func21(__int64 a1, __int64 a2)
{
func20(a1, a2);
}

original_code:
void free_convert_matrix(float **b, long nrl, long nrh, long ncl, long nch)
{
    free((char*) (b+nrl-1));
}

canonical_original_code:
void free_convert_matrix(float **b, long nrl, long nrh, long ncl, long nch)
{
    free((char *) (b+nrl-1));
}


original_code:
void free_f3tensor(float ***t, long nrl, long nrh, long ncl, long nch,
    long ndl, long ndh)
{
    free((char*) (t[nrl][ncl]+ndl-1));
    free((char*) (t[nrl]+ncl-1));
    free((char*) (t+nrl-1));
}

canonical_original_code:
void free_f3tensor(float ***t, long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
{
    free((char *) (t[nrl][ncl]+ndl-1));
    free((char *) (t[nrl]+ncl-1));
    free((char *) (t+nrl-1));
}

variable_types: ndl long

variable_types: ndh long


SumClr

decompiled_code:
void SumClr()
{
sum_weight = 0LL;
sum_x = 0LL;
sum_x2 = 0LL;
sum_y = 0LL;
sum_y2 = 0LL;
sum_xy = 0LL;
}

canonical_decompiled_code:
void func0()
{
sum_weight = 0LL;
sum_x = 0LL;
sum_x2 = 0LL;
sum_y = 0LL;
sum_y2 = 0LL;
sum_xy = 0LL;
}


SwtAdd

decompiled_code:
void __fastcall SwtAdd(double a1, double a2, double a3)
{
double v3; // xmm3_8
double v4; // xmm0_8
double v5; // xmm1_8

v3 = 1.0 / (a3 * a3);
v4 = a1 * v3;
v5 = a2 * v3;
*(double *)&sum_weight = v3 + *(double *)&sum_weight;
*(double *)&sum_x = *(double *)&sum_x + v4;
*(double *)&sum_x2 = v4 * v4 + *(double *)&sum_x2;
*(double *)&sum_xy = v4 * v5 + *(double *)&sum_xy;
*(double *)&sum_y = *(double *)&sum_y + v5;
*(double *)&sum_y2 = v5 * v5 + *(double *)&sum_y2;
}

canonical_decompiled_code:
void __fastcall func1(double a1, double a2, double a3)
{
double v3; // xmm3_8
double v4; // xmm0_8
double v5; // xmm1_8

v3 = 1.0 / (a3 * a3);
v4 = a1 * v3;
v5 = a2 * v3;
*(double *)&sum_weight = v3 + *(double *)&sum_weight;
*(double *)&sum_x = *(double *)&sum_x + v4;
*(double *)&sum_x2 = v4 * v4 + *(double *)&sum_x2;
*(double *)&sum_xy = v4 * v5 + *(double *)&sum_xy;
*(double *)&sum_y = *(double *)&sum_y + v5;
*(double *)&sum_y2 = v5 * v5 + *(double *)&sum_y2;
}

original_code:
void SwtAdd (double x, double y, double z)
{
    double weight = 1/(z*z);
    double xWt = x * weight;
    double yWt = y * weight;
    sum_weight += weight;
    sum_x += xWt;
    sum_x2 += xWt*xWt;
    sum_y += yWt;
    sum_y2 += yWt*yWt;
    sum_xy += xWt*yWt;
}

canonical_original_code:
void SwtAdd(double x, double y, double z)
{
    double weight = 1/(z*z);
    double xWt = x * weight;
    double yWt = y * weight;
    sum_weight += weight;
    sum_x += xWt;
    sum_x2 += xWt*xWt;
    sum_y += yWt;
    sum_y2 += yWt*yWt;
    sum_xy += xWt*yWt;
}

variable_types: x double

variable_types: y double

variable_types: z double

variable_types: weight double

variable_types: xWt double

variable_types: yWt double


SumAdd

decompiled_code:
void __fastcall SumAdd(double a1, double a2)
{
SwtAdd(a1, a2, 1.0);
}

canonical_decompiled_code:
void __fastcall func2(double a1, double a2)
{
func1(a1, a2, 1.0);
}

original_code:
void SumAdd (double x, double y)
{
    SwtAdd (x, y, (double) 1.0);
}

canonical_original_code:
void SumAdd(double x, double y)
{
    SwtAdd (x, y, (double) 1.0);
}


SwtSub

decompiled_code:
void __fastcall SwtSub(double a1, double a2, double a3)
{
double v3; // xmm3_8
double v4; // xmm0_8
double v5; // xmm1_8

v3 = 1.0 / (a3 * a3);
v4 = a1 * v3;
v5 = a2 * v3;
*(double *)&sum_weight = *(double *)&sum_weight - v3;
*(double *)&sum_x = *(double *)&sum_x - v4;
*(double *)&sum_x2 = *(double *)&sum_x2 - v4 * v4;
*(double *)&sum_y = *(double *)&sum_y - v5;
*(double *)&sum_xy = *(double *)&sum_xy - v4 * v5;
*(double *)&sum_y2 = *(double *)&sum_y2 - v5 * v5;
}

canonical_decompiled_code:
void __fastcall func3(double a1, double a2, double a3)
{
double v3; // xmm3_8
double v4; // xmm0_8
double v5; // xmm1_8

v3 = 1.0 / (a3 * a3);
v4 = a1 * v3;
v5 = a2 * v3;
*(double *)&sum_weight = *(double *)&sum_weight - v3;
*(double *)&sum_x = *(double *)&sum_x - v4;
*(double *)&sum_x2 = *(double *)&sum_x2 - v4 * v4;
*(double *)&sum_y = *(double *)&sum_y - v5;
*(double *)&sum_xy = *(double *)&sum_xy - v4 * v5;
*(double *)&sum_y2 = *(double *)&sum_y2 - v5 * v5;
}

original_code:
void SwtSub (double x, double y, double z)
{
    double weight = 1/(z*z);
    double xWt = x * weight;
    double yWt = y * weight;
    sum_weight -= weight;
    sum_x -= xWt;
    sum_x2 -= xWt*xWt;
    sum_y -= yWt;
    sum_y2 -= yWt*yWt;
    sum_xy -= xWt*yWt;
}

canonical_original_code:
void SwtSub(double x, double y, double z)
{
    double weight = 1/(z*z);
    double xWt = x * weight;
    double yWt = y * weight;
    sum_weight -= weight;
    sum_x -= xWt;
    sum_x2 -= xWt*xWt;
    sum_y -= yWt;
    sum_y2 -= yWt*yWt;
    sum_xy -= xWt*yWt;
}


SumSub

decompiled_code:
void __fastcall SumSub(double a1, double a2)
{
SwtSub(a1, a2, 1.0);
}

canonical_decompiled_code:
void __fastcall func4(double a1, double a2)
{
func3(a1, a2, 1.0);
}

original_code:
void SumSub (double x, double y)
{
    SwtSub (x, y, (double) 1.0);
}

canonical_original_code:
void SumSub(double x, double y)
{
    SwtSub (x, y, (double) 1.0);
}