dealrecvfile

decompiled_code:
__int64 __fastcall dealrecvfile(unsigned int a1)
{
int v1; // eax
char *v2; // rbp
size_t v3; // rax
char *v4; // rbp
size_t v5; // rax
int v6; // eax
unsigned int v7; // ebp
__int64 result; // rax
char v9[152]; // [rsp+0h] [rbp-98h] BYREF

while ( 1 )
{
v1 = Readline(a1, v9, 128LL);
if ( v1 <= 0 )
{
log_msg("client terminated early");
Close(a1);
exit(1);
}
v9[v1 - 1] = 0;
if ( access(v9, 0) )
break;
v2 = error;
v3 = strlen(error);
Writen(a1, v2, v3);
}
v4 = right;
v5 = strlen(right);
Writen(a1, v4, v5);
v6 = open(v9, 65, 448LL);
v7 = v6;
if ( v6 < 0 )
{
log_err("connot open file %s", v9);
log_msg("receive file %s failed", v9);
result = 0xFFFFFFFFLL;
}
else
{
recvfile(a1, v6);
log_msg("receive file %s completed", v9);
Close(v7);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
int v1; // eax
char *v2; // rbp
size_t v3; // rax
char *v4; // rbp
size_t v5; // rax
int v6; // eax
unsigned int v7; // ebp
__int64 result; // rax
char v9[152]; // [rsp+0h] [rbp-98h] BYREF

while ( 1 )
{
v1 = Readline(a1, v9, 128LL);
if ( v1 <= 0 )
{
log_msg("client terminated early");
Close(a1);
exit(1);
}
v9[v1 - 1] = 0;
if ( access(v9, 0) )
break;
v2 = error;
v3 = strlen(error);
Writen(a1, v2, v3);
}
v4 = right;
v5 = strlen(right);
Writen(a1, v4, v5);
v6 = open(v9, 65, 448LL);
v7 = v6;
if ( v6 < 0 )
{
log_err("connot open file %s", v9);
log_msg("receive file %s failed", v9);
result = 0xFFFFFFFFLL;
}
else
{
func2(a1, v6);
log_msg("receive file %s completed", v9);
Close(v7);
result = 0LL;
}
return result;
}

original_code:
int dealrecvfile(int sockfd)
{
 char name[128];
 int nread,fd;
again:
    if((nread=Readline(sockfd,name,sizeof(name)))>0)
        name[nread-1]='\0';
 else
 {
        log_msg("client terminated early");
        Close(sockfd);
  exit(1);
 }
    if(access(name,0)==0)
 {
        Writen(sockfd,error,strlen(error));
  goto again;
 }
    Writen(sockfd,right,strlen(right));
 fd=open(name,0100|01,(0400|0200|0100));
 if(fd<0)
 {
        log_err("connot open file %s",name);
        log_msg("receive file %s failed",name);
  return -1;
 }
 recvfile(sockfd,fd);
    log_msg("receive file %s completed",name);
 Close(fd);
 return 0;
}

canonical_original_code:
int dealrecvfile(int sockfd)
{
 char name[128];
 int nread; int fd;
again:
    if((nread=Readline(sockfd,name,sizeof(name)))>0)
        name[nread-1]='\0';
 else
 {
        log_msg("client terminated early");
        Close(sockfd);
  exit(1);
 }
    if(access(name,0)==0)
 {
        Writen(sockfd,error,strlen(error));
  goto again;
 }
    Writen(sockfd,right,strlen(right));
 fd=open(name,0100|01,(0400|0200|0100));
 if(fd<0)
 {
        log_err("connot open file %s",name);
        log_msg("receive file %s failed",name);
  return -1;
 }
 recvfile(sockfd,fd);
    log_msg("receive file %s completed",name);
 Close(fd);
 return 0;
}

variable_types:
name
char [128]


dealsendfile

decompiled_code:
__int64 __fastcall dealsendfile(unsigned int a1, __int64 a2)
{
const char *v2; // rax
size_t v3; // rax
size_t v4; // rax
int v5; // eax
unsigned int v6; // er12
unsigned int v7; // ebp
char v9; // [rsp+1h] [rbp-A9h]
char v10[136]; // [rsp+2h] [rbp-A8h] BYREF
char s1[32]; // [rsp+8Ah] [rbp-20h] BYREF

v2 = (const char *)filename(a2);
strcpy(v10, v2);
*(_WORD *)&v10[strlen(v10)] = 10;
v3 = strlen(v10);
Writen(a1, v10, v3);
while ( 1 )
{
v5 = Readline(a1, s1, 8LL);
if ( !v5 )
{
log_msg("server terminated");
Close(a1);
exit(1);
}
s1[v5] = 0;
if ( strcmp(s1, error) )
break;
*(&v9 + strlen(v10)) = 0;
fprintf(stderr, "file %s have existed in server,please input new name:", v10);
while ( 1 )
{
fgets(v10, 128, stdin);
if ( v10[0] != 10 )
break;
fwrite("input is empty,please try again:\n", 1uLL, 0x21uLL, stderr);
}
v4 = strlen(v10);
Writen(a1, v10, v4);
}
v6 = strcmp(s1, right);
if ( v6 )
{
fwrite("protocal error\n", 1uLL, 0xFuLL, stderr);
v6 = -1;
}
else
{
v7 = Open(a2, 0LL);
sendfile(a1, v7);
Close(v7);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2)
{
const char *v2; // rax
size_t v3; // rax
size_t v4; // rax
int v5; // eax
unsigned int v6; // er12
unsigned int v7; // ebp
char v9; // [rsp+1h] [rbp-A9h]
char v10[136]; // [rsp+2h] [rbp-A8h] BYREF
char s1[32]; // [rsp+8Ah] [rbp-20h] BYREF

v2 = (const char *)filename(a2);
strcpy(v10, v2);
*(_WORD *)&v10[strlen(v10)] = 10;
v3 = strlen(v10);
Writen(a1, v10, v3);
while ( 1 )
{
v5 = Readline(a1, s1, 8LL);
if ( !v5 )
{
log_msg("server terminated");
Close(a1);
exit(1);
}
s1[v5] = 0;
if ( strcmp(s1, error) )
break;
*(&v9 + strlen(v10)) = 0;
fprintf(stderr, "file %s have existed in server,please input new name:", v10);
while ( 1 )
{
fgets(v10, 128, stdin);
if ( v10[0] != 10 )
break;
fwrite("input is empty,please try again:\n", 1uLL, 0x21uLL, stderr);
}
v4 = strlen(v10);
Writen(a1, v10, v4);
}
v6 = strcmp(s1, right);
if ( v6 )
{
fwrite("protocal error\n", 1uLL, 0xFuLL, stderr);
v6 = -1;
}
else
{
v7 = Open(a2, 0LL);
func1(a1, v7);
Close(v7);
}
return v6;
}

original_code:
int dealsendfile(int sockfd,const char* file)
{
 int fd,nread;
 char stat[8],newname[128];
 const char *name=filename(file);
 strcpy(newname,name);
    strcat(newname,"\n");
    Writen(sockfd,newname,strlen(newname));
again:
    nread=Readline(sockfd,stat,sizeof(stat));
    if(nread == 0)
    {
        log_msg("server terminated");
        Close(sockfd);
        exit(1);
    }
 stat[nread]=0;
    if(strcmp(stat,error)==0)
 {
        newname[strlen(newname)-1]='\0';
        fprintf(stderr,"file %s have existed in server,please input new name:",newname);
        while(1)
        {
            fgets(newname,sizeof(newname),stdin);
            if(newname[0] != '\n')
                break;
            else
            {
                fprintf(stderr,"input is empty,please try again:\n");
            }
        }
  Writen(sockfd,newname,strlen(newname));
  goto again;
 }
 else
        if(strcmp(stat,right)==0)
  {
   fd=Open(file,00);
   sendfile(sockfd,fd);
   Close(fd);
   return 0;
  }
  else
  {
   fprintf(stderr,"protocal error\n");
   return -1;
  }
}

canonical_original_code:
int dealsendfile(int sockfd, char *file)
{
 int fd; int nread;
 char stat[8]; char newname[128];
 char *name = filename(file);
 strcpy(newname,name);
    strcat(newname,"\n");
    Writen(sockfd,newname,strlen(newname));
again:
    nread=Readline(sockfd,stat,sizeof(stat));
    if(nread == 0)
    {
        log_msg("server terminated");
        Close(sockfd);
        exit(1);
    }
 stat[nread]=0;
    if(strcmp(stat,error)==0)
 {
        newname[strlen(newname)-1]='\0';
        fprintf(stderr,"file %s have existed in server,please input new name:",newname);
        while(1)
        {
            fgets(newname,sizeof(newname),stdin);
            if(newname[0] != '\n')
                break;
            else
            {
                fprintf(stderr,"input is empty,please try again:\n");
            }
        }
  Writen(sockfd,newname,strlen(newname));
  goto again;
 }
 else
        if(strcmp(stat,right)==0)
  {
   fd=Open(file,00);
   sendfile(sockfd,fd);
   Close(fd);
   return 0;
  }
  else
  {
   fprintf(stderr,"protocal error\n");
   return -1;
  }
}

variable_types: sockfd int

variable_types:
file
char *

variable_types: fd int

variable_types: nread int

variable_types:
stat
char [8]

variable_types:
newname
char [128]

variable_types:
name
char *

return_type: int


decompiled_code:
int __fastcall check_passwd_inclient(unsigned int a1)
{
size_t v1; // rax
int v2; // eax
int result; // eax
char s1[8]; // [rsp+8h] [rbp-90h] BYREF
char s[136]; // [rsp+10h] [rbp-88h] BYREF

fwrite("enter your passwd:", 1uLL, 0x12uLL, stderr);
while ( 1 )
{
while ( 1 )
{
close_echo();
fgets(s, 128, stdin);
open_echo();
fputc(10, stderr);
if ( s[0] != 10 )
break;
fwrite("passwd is empty,please input again:", 1uLL, 0x23uLL, stderr);
}
v1 = strlen(s);
Writen(a1, s, v1);
v2 = Readline(a1, s1, 8LL);
if ( !v2 )
{
fwrite("verify passwd too many times\n,please try again later.\n", 1uLL, 0x36uLL, stderr);
return -1;
}
s1[v2] = 0;
if ( strcmp(s1, error) )
break;
fwrite("passwd error,please input again:", 1uLL, 0x20uLL, stderr);
}
result = strcmp(s1, right);
if ( result )
{
fwrite("protocal error", 1uLL, 0xEuLL, stderr);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1)
{
size_t v1; // rax
int v2; // eax
int result; // eax
char s1[8]; // [rsp+8h] [rbp-90h] BYREF
char s[136]; // [rsp+10h] [rbp-88h] BYREF

fwrite("enter your passwd:", 1uLL, 0x12uLL, stderr);
while ( 1 )
{
while ( 1 )
{
close_echo();
fgets(s, 128, stdin);
open_echo();
fputc(10, stderr);
if ( s[0] != 10 )
break;
fwrite("passwd is empty,please input again:", 1uLL, 0x23uLL, stderr);
}
v1 = strlen(s);
Writen(a1, s, v1);
v2 = Readline(a1, s1, 8LL);
if ( !v2 )
{
fwrite("verify passwd too many times\n,please try again later.\n", 1uLL, 0x36uLL, stderr);
return -1;
}
s1[v2] = 0;
if ( strcmp(s1, error) )
break;
fwrite("passwd error,please input again:", 1uLL, 0x20uLL, stderr);
}
result = strcmp(s1, right);
if ( result )
{
fwrite("protocal error", 1uLL, 0xEuLL, stderr);
result = -1;
}
return result;
}

original_code:
int check_passwd_inclient(int sockfd)
{
 int nread;
    char passwd[128],stat[8];
    fprintf(stderr,"enter your passwd:");
    while(1)
    {
        while(1)
        {
            close_echo();
            fgets(passwd,sizeof(passwd),stdin);
            open_echo();
            fprintf(stderr,"\n");
            if (passwd[0] == '\n')
            {
                fprintf(stderr,"passwd is empty,please input again:");
            }
            else
                break;
        }
        Writen(sockfd,passwd,strlen(passwd));
        nread=Readline(sockfd,stat,sizeof(stat));
        if(nread == 0)
        {
            fprintf(stderr,"verify passwd too many times\n,please try again later.\n");
            return -1;
        }
        stat[nread]='\0';
        if(strcmp(stat,error)==0)
        {
            fprintf(stderr,"passwd error,please input again:");
            continue;
        }
        else
            if(strcmp(stat,right)==0)
            {
                return 0;
            }
            else
            {
                fprintf(stderr,"protocal error");
                return -1;
            }
    }
 return -1;
}

canonical_original_code:
int check_passwd_inclient(int sockfd)
{
 int nread;
    char passwd[128]; char stat[8];
    fprintf(stderr,"enter your passwd:");
    while(1)
    {
        while(1)
        {
            close_echo();
            fgets(passwd,sizeof(passwd),stdin);
            open_echo();
            fprintf(stderr,"\n");
            if (passwd[0] == '\n')
            {
                fprintf(stderr,"passwd is empty,please input again:");
            }
            else
                break;
        }
        Writen(sockfd,passwd,strlen(passwd));
        nread=Readline(sockfd,stat,sizeof(stat));
        if(nread == 0)
        {
            fprintf(stderr,"verify passwd too many times\n,please try again later.\n");
            return -1;
        }
        stat[nread]='\0';
        if(strcmp(stat,error)==0)
        {
            fprintf(stderr,"passwd error,please input again:");
            continue;
        }
        else
            if(strcmp(stat,right)==0)
            {
                return 0;
            }
            else
            {
                fprintf(stderr,"protocal error");
                return -1;
            }
    }
 return -1;
}

variable_types:
passwd
char [128]


decompiled_code:
__int64 __fastcall check_passwd_inserver(unsigned int a1, const char *a2)
{
int v2; // er12
int v3; // eax
unsigned int v4; // er13
char *v5; // rbp
size_t v6; // rax
char *v8; // r13
size_t v9; // rax
char v10[168]; // [rsp+0h] [rbp-A8h] BYREF

v2 = 5;
do
{
v3 = Readline(a1, v10, 128LL);
if ( !v3 )
{
log_msg("client terminated early");
Close(a1);
exit(1);
}
v10[v3 - 1] = 0;
v4 = strcmp(v10, a2);
if ( !v4 )
{
v5 = right;
v6 = strlen(right);
Writen(a1, v5, v6);
return v4;
}
v8 = error;
v9 = strlen(error);
Writen(a1, v8, v9);
--v2;
}
while ( v2 );
log_msg("vefified too many times");
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, const char *a2)
{
int v2; // er12
int v3; // eax
unsigned int v4; // er13
char *v5; // rbp
size_t v6; // rax
char *v8; // r13
size_t v9; // rax
char v10[168]; // [rsp+0h] [rbp-A8h] BYREF

v2 = 5;
do
{
v3 = Readline(a1, v10, 128LL);
if ( !v3 )
{
log_msg("client terminated early");
Close(a1);
exit(1);
}
v10[v3 - 1] = 0;
v4 = strcmp(v10, a2);
if ( !v4 )
{
v5 = right;
v6 = strlen(right);
Writen(a1, v5, v6);
return v4;
}
v8 = error;
v9 = strlen(error);
Writen(a1, v8, v9);
--v2;
}
while ( v2 );
log_msg("vefified too many times");
return (unsigned int)-1;
}

original_code:
int check_passwd_inserver(int sockfd,const char* secret)
{
    int nread;
    int count=0;
    char passwd[128];
    while(count<5)
    {
        count++;
        nread=Readline(sockfd,passwd,sizeof(passwd));
        if(nread == 0)
        {
            log_msg("client terminated early");
            Close(sockfd);
            exit(1);
        }
        passwd[nread-1]='\0';
        if(strcmp(passwd,secret) != 0)
        {
            Writen(sockfd,error,strlen(error));
            continue;
        }
        else
        {
            Writen(sockfd,right,strlen(right));
            return 0;
        }
    }
    log_msg("vefified too many times");
    return -1;
}

canonical_original_code:
int check_passwd_inserver(int sockfd, char *secret)
{
    int nread;
    int count = 0;
    char passwd[128];
    while(count<5)
    {
        count++;
        nread=Readline(sockfd,passwd,sizeof(passwd));
        if(nread == 0)
        {
            log_msg("client terminated early");
            Close(sockfd);
            exit(1);
        }
        passwd[nread-1]='\0';
        if(strcmp(passwd,secret) != 0)
        {
            Writen(sockfd,error,strlen(error));
            continue;
        }
        else
        {
            Writen(sockfd,right,strlen(right));
            return 0;
        }
    }
    log_msg("vefified too many times");
    return -1;
}

variable_types:
secret
char *

variable_types: count int


decompiled_code:
__int64 __fastcall daemon_init(__int64 a1)
{
__pid_t v1; // eax
__pid_t v2; // eax
unsigned int v3; // er12
int v4; // ebx

v1 = fork();
if ( v1 < 0 )
return (unsigned int)-1;
if ( v1 )
exit(0);
if ( setsid() < 0 )
return (unsigned int)-1;
signal(1, (__sighandler_t)((char *)daemon_init + 1));
v2 = fork();
v3 = v2;
if ( v2 < 0 )
return (unsigned int)-1;
v4 = v2;
if ( v2 )
exit(0);
do
close(v4++);
while ( v4 != 64 );
open("dev/null", 0);
open("dev/null", 2);
open("dev/null", 2);
if ( a1 )
log_open(a1, 1LL, 8LL);
log_to_stderr = 0;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__pid_t v1; // eax
__pid_t v2; // eax
unsigned int v3; // er12
int v4; // ebx

v1 = fork();
if ( v1 < 0 )
return (unsigned int)-1;
if ( v1 )
exit(0);
if ( setsid() < 0 )
return (unsigned int)-1;
signal(1, (__sighandler_t)((char *)daemon_init + 1));
v2 = fork();
v3 = v2;
if ( v2 < 0 )
return (unsigned int)-1;
v4 = v2;
if ( v2 )
exit(0);
do
close(v4++);
while ( v4 != 64 );
open("dev/null", 0);
open("dev/null", 2);
open("dev/null", 2);
if ( a1 )
log_open(a1, 1LL, 8LL);
log_to_stderr = 0;
return v3;
}

original_code:
int daemon_init(const char *pname)
{
 int i;
 pid_t pid;
 if((pid=fork())<0)
  return -1;
 else
  if(pid)
            exit(0);
 if(setsid()<0)
  return -1;
 signal(1,((__sighandler_t) 1));
 if((pid=fork())<0)
  return -1;
 else
  if(pid)
            exit(0);
 for(i=0;i<64;i++)
  close(i);
 open("dev/null",00);
 open("dev/null",02);
 open("dev/null",02);
 if(pname!=((void *)0))
        log_open(pname,0x01,(1<<3));
    log_to_stderr=0;
 return 0;
}

canonical_original_code:
int daemon_init(char *pname)
{
 int i;
 int pid;
 if((pid=fork())<0)
  return -1;
 else
  if(pid)
            exit(0);
 if(setsid()<0)
  return -1;
 signal(1,((void (*)(int)) 1));
 if((pid=fork())<0)
  return -1;
 else
  if(pid)
            exit(0);
 for(i=0;i<64;i++)
  close(i);
 open("dev/null",00);
 open("dev/null",02);
 open("dev/null",02);
 if(pname!=((void *)0))
        log_open(pname,0x01,(1<<3));
    log_to_stderr=0;
 return 0;
}

variable_types:
pname
char *

variable_types: i int

variable_types: pid int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // r13
int v4; // eax
_QWORD *v5; // rax
unsigned int i; // ebp
__int64 v7; // r14
unsigned __int64 v8; // rdi
__int64 v9; // rbx
__int64 v10; // rax
_QWORD *v11; // r12
__int64 v12; // rax
_BYTE *v13; // r8
_BYTE *v14; // rdi
unsigned __int64 v15; // rdi
unsigned int v16; // edx
__int64 v17; // r9
_QWORD *v18; // rbx
__int64 v19; // rax
int v20; // ecx
unsigned int v21; // eax
std::ostream *v22; // rax
clock_t v23; // rbx
std::ostream *v24; // rax
std::ostream *v26; // rbp
std::ostream *v27; // rbp
__int64 v28; // rbp
__int64 v29; // rbp
std::ostream *v30; // rax
clock_t v31; // [rsp+8h] [rbp-F0h]
_QWORD *v32; // [rsp+10h] [rbp-E8h] BYREF
int v33; // [rsp+18h] [rbp-E0h]
char v34[32]; // [rsp+20h] [rbp-D8h] BYREF
void *v35[2]; // [rsp+40h] [rbp-B8h] BYREF
__int64 v36; // [rsp+50h] [rbp-A8h]
char v37[152]; // [rsp+60h] [rbp-98h] BYREF

if ( argc != 1 )
strtol(argv[1], 0LL, 10);
CreateGraph::CreateGraph(v34, "test.graph", 0LL);
v3 = (_QWORD *)CreateGraph::instance((CreateGraph *)v34);
DeCompress::DeCompress((DeCompress *)v37, "test.comp");
DeCompress::init((DeCompress *)v37, "test.degree", "test.node", "test.pos");
WebGraph::WebGraph((WebGraph *)&v32);
v4 = DeCompress::size((DeCompress *)v37);
v32 = (_QWORD *)operator new[](16LL * (unsigned int)(v4 + 1));
v33 = DeCompress::size((DeCompress *)v37) + 1;
v5 = v32;
v32[1] = 0LL;
*v5 = 0LL;
*(_OWORD *)v35 = 0LL;
v36 = 0LL;
v31 = clock();
DeCompress::setparameter((DeCompress *)v37, 0x64u, 0.2);
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "start decode node", 17LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cerr);
for ( i = 1; i <= (unsigned int)DeCompress::size((DeCompress *)v37); ++i )
{
DeCompress::getlinks(v37, i, v35);
v7 = i;
v8 = v35[1] - v35[0];
v9 = 16LL * i;
v10 = *(unsigned int *)(*v3 + v9 + 4);
if ( v10 != (v35[1] - v35[0]) >> 2 )
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "decode node =", 13LL);
v27 = (std::ostream *)std::ostream::_M_insert<unsigned long>(&std::cerr, i);
std::__ostream_insert<char,std::char_traits<char>>(v27, " error!", 7LL);
std::endl<char,std::char_traits<char>>(v27);
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "links.size()=", 13LL);
v28 = std::ostream::_M_insert<unsigned long>(&std::cerr, (v35[1] - v35[0]) >> 2);
std::__ostream_insert<char,std::char_traits<char>>(v28, ",node[", 6LL);
v29 = std::ostream::_M_insert<unsigned long>(v28, v7);
std::__ostream_insert<char,std::char_traits<char>>(v29, "].linkscount=", 13LL);
v30 = (std::ostream *)std::ostream::_M_insert<unsigned long>(v29, *(unsigned int *)(*v3 + v9 + 4));
std::endl<char,std::char_traits<char>>(v30);
goto LABEL_16;
}
v11 = &v32[(unsigned __int64)v9 / 8];
*(_DWORD *)v11 = i;
*((_DWORD *)v11 + 1) = v10;
if ( v8 > 0x7FFFFFFFFFFFFFF8LL )
main_cold();
v12 = operator new[](v8);
v13 = v35[0];
v14 = v35[1];
v11[1] = v12;
v15 = (v14 - v13) >> 2;
if ( v15 )
{
v16 = 0;
v17 = *(_QWORD *)(*v3 + v9 + 8);
v18 = &v32[(unsigned __int64)v9 / 8];
v19 = 0LL;
while ( 1 )
{
v20 = *(_DWORD *)&v13[4 * v19];
if ( v20 != *(_DWORD *)(v17 + 4 * v19) )
break;
*(_DWORD *)(v18[1] + 4 * v19) = v20;
v19 = ++v16;
if ( v16 >= v15 )
goto LABEL_11;
}
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "pageid=", 7LL);
v26 = (std::ostream *)std::ostream::_M_insert<unsigned long>(&std::cerr, i);
std::__ostream_insert<char,std::char_traits<char>>(v26, ",link can't match", 17LL);
std::endl<char,std::char_traits<char>>(v26);
LABEL_16:
exit(1);
}
LABEL_11:
;
}
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "decompress.nodecount= ", 22LL);
v21 = DeCompress::size((DeCompress *)v37);
v22 = (std::ostream *)std::ostream::_M_insert<unsigned long>(&std::cerr, v21);
std::endl<char,std::char_traits<char>>(v22);
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "decode right", 12LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cerr);
v23 = clock();
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "time of decompress graph= ", 26LL);
v24 = (std::ostream *)std::ostream::_M_insert<long>(&std::cerr, v23 - v31);
std::endl<char,std::char_traits<char>>(v24);
write_graph_to_file("test2.graph", (const WebGraph *)&v32);
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "write decompressed graph completed", 34LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cerr);
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "completed", 9LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cout);
if ( v35[0] )
operator delete(v35[0], v36 - (unsigned __int64)v35[0]);
WebGraph::~WebGraph((WebGraph *)&v32);
DeCompress::~DeCompress((DeCompress *)v37);
CreateGraph::~CreateGraph((CreateGraph *)v34);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // r13
int v4; // eax
_QWORD *v5; // rax
unsigned int i; // ebp
__int64 v7; // r14
unsigned __int64 v8; // rdi
__int64 v9; // rbx
__int64 v10; // rax
_QWORD *v11; // r12
__int64 v12; // rax
_BYTE *v13; // r8
_BYTE *v14; // rdi
unsigned __int64 v15; // rdi
unsigned int v16; // edx
__int64 v17; // r9
_QWORD *v18; // rbx
__int64 v19; // rax
int v20; // ecx
unsigned int v21; // eax
std::ostream *v22; // rax
clock_t v23; // rbx
std::ostream *v24; // rax
std::ostream *v26; // rbp
std::ostream *v27; // rbp
__int64 v28; // rbp
__int64 v29; // rbp
std::ostream *v30; // rax
clock_t v31; // [rsp+8h] [rbp-F0h]
_QWORD *v32; // [rsp+10h] [rbp-E8h] BYREF
int v33; // [rsp+18h] [rbp-E0h]
char v34[32]; // [rsp+20h] [rbp-D8h] BYREF
void *v35[2]; // [rsp+40h] [rbp-B8h] BYREF
__int64 v36; // [rsp+50h] [rbp-A8h]
char v37[152]; // [rsp+60h] [rbp-98h] BYREF

if ( argc != 1 )
strtol(argv[1], 0LL, 10);
CreateGraph::CreateGraph(v34, "test.graph", 0LL);
v3 = (_QWORD *)CreateGraph::instance((CreateGraph *)v34);
DeCompress::func4((DeCompress *)v37, "test.comp");
DeCompress::init((DeCompress *)v37, "test.degree", "test.node", "test.pos");
WebGraph::WebGraph((WebGraph *)&v32);
v4 = DeCompress::size((DeCompress *)v37);
v32 = (_QWORD *)operator new[](16LL * (unsigned int)(v4 + 1));
v33 = DeCompress::size((DeCompress *)v37) + 1;
v5 = v32;
v32[1] = 0LL;
*v5 = 0LL;
*(_OWORD *)v35 = 0LL;
v36 = 0LL;
v31 = clock();
DeCompress::setparameter((DeCompress *)v37, 0x64u, 0.2);
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "start decode node", 17LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cerr);
for ( i = 1; i <= (unsigned int)DeCompress::size((DeCompress *)v37); ++i )
{
DeCompress::getlinks(v37, i, v35);
v7 = i;
v8 = v35[1] - v35[0];
v9 = 16LL * i;
v10 = *(unsigned int *)(*v3 + v9 + 4);
if ( v10 != (v35[1] - v35[0]) >> 2 )
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "decode node =", 13LL);
v27 = (std::ostream *)std::ostream::_M_insert<unsigned long>(&std::cerr, i);
std::__ostream_insert<char,std::char_traits<char>>(v27, " error!", 7LL);
std::endl<char,std::char_traits<char>>(v27);
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "links.size()=", 13LL);
v28 = std::ostream::_M_insert<unsigned long>(&std::cerr, (v35[1] - v35[0]) >> 2);
std::__ostream_insert<char,std::char_traits<char>>(v28, ",node[", 6LL);
v29 = std::ostream::_M_insert<unsigned long>(v28, v7);
std::__ostream_insert<char,std::char_traits<char>>(v29, "].linkscount=", 13LL);
v30 = (std::ostream *)std::ostream::_M_insert<unsigned long>(v29, *(unsigned int *)(*v3 + v9 + 4));
std::endl<char,std::char_traits<char>>(v30);
goto LABEL_16;
}
v11 = &v32[(unsigned __int64)v9 / 8];
*(_DWORD *)v11 = i;
*((_DWORD *)v11 + 1) = v10;
if ( v8 > 0x7FFFFFFFFFFFFFF8LL )
func3();
v12 = operator new[](v8);
v13 = v35[0];
v14 = v35[1];
v11[1] = v12;
v15 = (v14 - v13) >> 2;
if ( v15 )
{
v16 = 0;
v17 = *(_QWORD *)(*v3 + v9 + 8);
v18 = &v32[(unsigned __int64)v9 / 8];
v19 = 0LL;
while ( 1 )
{
v20 = *(_DWORD *)&v13[4 * v19];
if ( v20 != *(_DWORD *)(v17 + 4 * v19) )
break;
*(_DWORD *)(v18[1] + 4 * v19) = v20;
v19 = ++v16;
if ( v16 >= v15 )
goto LABEL_11;
}
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "pageid=", 7LL);
v26 = (std::ostream *)std::ostream::_M_insert<unsigned long>(&std::cerr, i);
std::__ostream_insert<char,std::char_traits<char>>(v26, ",link can't match", 17LL);
std::endl<char,std::char_traits<char>>(v26);
LABEL_16:
exit(1);
}
LABEL_11:
;
}
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "decompress.nodecount= ", 22LL);
v21 = DeCompress::size((DeCompress *)v37);
v22 = (std::ostream *)std::ostream::_M_insert<unsigned long>(&std::cerr, v21);
std::endl<char,std::char_traits<char>>(v22);
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "decode right", 12LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cerr);
v23 = clock();
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "time of decompress graph= ", 26LL);
v24 = (std::ostream *)std::ostream::_M_insert<long>(&std::cerr, v23 - v31);
std::endl<char,std::char_traits<char>>(v24);
write_graph_to_file("test2.graph", (const WebGraph *)&v32);
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "write decompressed graph completed", 34LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cerr);
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "completed", 9LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cout);
if ( v35[0] )
operator delete(v35[0], v36 - (unsigned __int64)v35[0]);
WebGraph::~WebGraph((WebGraph *)&v32);
DeCompress::~func4((DeCompress *)v37);
CreateGraph::~CreateGraph((CreateGraph *)v34);
return 0;
}

original_code:
int main()
{
    const char *conf_file="./filetransfer.conf";
    int listenfd,connfd,passwdstat;
 struct sockaddr_in servaddr,cliaddr;
    socklen_t clilen;
    pid_t pid;
    uint32_t host;
    uint16_t port;
    if(!filetransfer_conf_read(&conf,conf_file))
    {
        log_quit("read configure file error");
    }
    print_conf_option(&conf);
    if(set_work_dir(conf.workdir)<0)
    {
       log_quit("change workdir to %s failed",conf.workdir);
    }
    if(strcmp(conf.host,"all"))
        host=inet_addr(conf.host);
    else
        host=htonl(((in_addr_t) 0x00000000));
    port=(uint16_t)atoi(conf.port);
    if(daemon_init("filetransfer")!=0)
    {
        log_quit("daemon error");
    }
 signal(17,sig_chld);
    listenfd=Socket(2,SOCK_STREAM,0);
 bzero(&servaddr,sizeof(servaddr));
 servaddr.sin_family=2;
    servaddr.sin_addr.s_addr=host;
    servaddr.sin_port=htons(port);
    Bind(listenfd,(struct sockaddr*)&servaddr,sizeof(servaddr));
    Listen(listenfd,10);
    clilen=sizeof(cliaddr);
 while(1)
 {
        connfd=Accept(listenfd,(struct sockaddr*)&cliaddr,&clilen);
  if((pid=fork())==0)
  {
            Close(listenfd);
            if((passwdstat=check_passwd_inserver(connfd,conf.passwd))<0)
   {
    Close(connfd);
    exit(1);
   }
            if(set_work_dir(conf.workdir)<0)
            {
                log_msg("recheck workdir %s failed",conf.workdir);
                Close(connfd);
                exit(1);
            }
   dealrecvfile(connfd);
   Close(connfd);
   return 0;
  }
  else
            Close(connfd);
 }
}

canonical_original_code:
int main()
{
    char *conf_file = "./filetransfer.conf";
    int listenfd; int connfd; int passwdstat;
 struct sockaddr_in servaddr; struct sockaddr_in cliaddr;
    unsigned int clilen;
    int pid;
    unsigned int host;
    unsigned short port;
    if(!filetransfer_conf_read(&conf,conf_file))
    {
        log_quit("read configure file error");
    }
    print_conf_option(&conf);
    if(set_work_dir(conf.workdir)<0)
    {
       log_quit("change workdir to %s failed",conf.workdir);
    }
    if(strcmp(conf.host,"all"))
        host=inet_addr(conf.host);
    else
        host=htonl(((unsigned int) 0x00000000));
    port=(unsigned short)atoi(conf.port);
    if(daemon_init("filetransfer")!=0)
    {
        log_quit("daemon error");
    }
 signal(17,sig_chld);
    listenfd=Socket(2,SOCK_STREAM,0);
 bzero(&servaddr,sizeof(servaddr));
 servaddr.sin_family=2;
    servaddr.sin_addr.s_addr=host;
    servaddr.sin_port=htons(port);
    Bind(listenfd,(struct sockaddr *)&servaddr,sizeof(servaddr));
    Listen(listenfd,10);
    clilen=sizeof(cliaddr);
 while(1)
 {
        connfd=Accept(listenfd,(struct sockaddr *)&cliaddr,&clilen);
  if((pid=fork())==0)
  {
            Close(listenfd);
            if((passwdstat=check_passwd_inserver(connfd,conf.passwd))<0)
   {
    Close(connfd);
    exit(1);
   }
            if(set_work_dir(conf.workdir)<0)
            {
                log_msg("recheck workdir %s failed",conf.workdir);
                Close(connfd);
                exit(1);
            }
   dealrecvfile(connfd);
   Close(connfd);
   return 0;
  }
  else
            Close(connfd);
 }
}

variable_types: listenfd int

variable_types: connfd int

variable_types: passwdstat 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:
clilen
unsigned int

variable_types:
host
unsigned int

variable_types:
port
unsigned short

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


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
std::ostream *v7; // rbp
__int64 v8; // rax
_BYTE *v9; // r12
char v10; // si
std::ostream *v11; // rax
_BYTE v12[56]; // [rsp+0h] [rbp-38h] BYREF

if ( argc != 1 )
{
if ( argc == 3 )
{
CreateGraph::CreateGraph(v12, argv[1], 1LL);
v4 = CreateGraph::instance((CreateGraph *)v12);
write_graph_to_file(argv[2], v4);
v5 = CreateGraph::instance((CreateGraph *)v12);
print_graph_info(v5);
}
else
{
result = 0;
if ( argc != 2 )
return result;
CreateGraph::CreateGraph(v12, argv[1], 0LL);
v6 = CreateGraph::instance((CreateGraph *)v12);
print_graph_info(v6);
}
CreateGraph::~CreateGraph((CreateGraph *)v12);
return 0;
}
v7 = (std::ostream *)std::operator<<<std::char_traits<char>>(&std::cerr, *argv, envp);
std::__ostream_insert<char,std::char_traits<char>>(v7, " graph.txt graph.graph", 22LL);
v8 = *(_QWORD *)(*(_QWORD *)v7 - 24LL);
v9 = *(_BYTE **)((char *)v7 + v8 + 240);
if ( !v9 )
std::__throw_bad_cast();
if ( v9[56] )
{
v10 = v9[67];
}
else
{
std::ctype<char>::_M_widen_init(*(_QWORD *)((char *)v7 + v8 + 240));
v10 = (*(__int64 (__fastcall **)(_BYTE *, __int64))(*(_QWORD *)v9 + 48LL))(v9, 10LL);
}
v11 = (std::ostream *)std::ostream::put(v7, v10);
std::ostream::flush(v11);
return -1;
}


repo: niclasberg/clbm

variable_types: struct Node { double f[9]; double u[2]; double rho; int coord[2]; double force[2]; } *

return_type: void


user_defined_types: struct Node { double f[9]; double u[2]; double rho; int coord[2]; double force[2]; }


decompiled_code:
__int64 __fastcall perm4(unsigned int a1, char a2)
{
__int64 result; // rax

if ( a1 > 4 )
result = (((_BYTE)a1 + a2 - 5) & 3u) + 5;
else
result = (((_BYTE)a1 + a2 - 1) & 3u) + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, char a2)
{
__int64 result; // rax

if ( a1 > 4 )
result = (((_BYTE)a1 + a2 - 5) & 3u) + 5;
else
result = (((_BYTE)a1 + a2 - 1) & 3u) + 1;
return result;
}

original_code:
unsigned int perm4(unsigned int i, unsigned int j)
{
 if(i <= 4)
  return 1 + (i+j-1)%4;
 else
  return 5 + (i+j-5)%4;
}

variable_types:
i
unsigned int

variable_types:
j
unsigned int

return_type: unsigned int


original_code:
void bc_regularized_straight(double * f, double rho, double u, double v, int dir)
{
 unsigned int k;
 double fneq[9];
 double Pi_xx, Pi_yy, Pi_xy, Q_xx, Q_xy, Q_yy;
 for(k=0; k < 9; ++k)
  fneq[k] = f[k] - feq(k, rho, u, v);
 fneq[perm4(3, dir)] = fneq[perm4(1, dir)];
 fneq[perm4(6, dir)] = fneq[perm4(8, dir)];
 fneq[perm4(7, dir)] = fneq[perm4(5, dir)];
 Pi_xx = Pi_xy = Pi_yy = 0;
 for(k=0; k < 9; ++k) {
  Pi_xx += cx[k]*cx[k]*fneq[k];
  Pi_xy += cx[k]*cy[k]*fneq[k];
  Pi_yy += cy[k]*cy[k]*fneq[k];
 }
 for(k=0; k < 9; ++k) {
  Q_xx = cx[k]*cx[k] - cs2;
  Q_xy = cx[k]*cy[k];
  Q_yy = cy[k]*cy[k] - cs2;
  f[k] = feq(k, rho, u, v) +
   weight[k]/(2*cs2*cs2) * (Q_xx*Pi_xx + 2*Q_xy*Pi_xy + Q_yy*Pi_yy);
 }
}

canonical_original_code:
void bc_regularized_straight(double *f, double rho, double u, double v, int dir)
{
 unsigned int k;
 double fneq[9];
 double Pi_xx; double Pi_yy; double Pi_xy; double Q_xx; double Q_xy; double Q_yy;
 for(k=0; k < 9; ++k)
  fneq[k] = f[k] - feq(k, rho, u, v);
 fneq[perm4(3, dir)] = fneq[perm4(1, dir)];
 fneq[perm4(6, dir)] = fneq[perm4(8, dir)];
 fneq[perm4(7, dir)] = fneq[perm4(5, dir)];
 Pi_xx = Pi_xy = Pi_yy = 0;
 for(k=0; k < 9; ++k) {
  Pi_xx += cx[k]*cx[k]*fneq[k];
  Pi_xy += cx[k]*cy[k]*fneq[k];
  Pi_yy += cy[k]*cy[k]*fneq[k];
 }
 for(k=0; k < 9; ++k) {
  Q_xx = cx[k]*cx[k] - cs2;
  Q_xy = cx[k]*cy[k];
  Q_yy = cy[k]*cy[k] - cs2;
  f[k] = feq(k, rho, u, v) +
   weight[k]/(2*cs2*cs2) * (Q_xx*Pi_xx + 2*Q_xy*Pi_xy + Q_yy*Pi_yy);
 }
}

variable_types:
f
double *

variable_types: rho double

variable_types: u double

variable_types: v double

variable_types: dir int

variable_types:
k
unsigned int

variable_types:
fneq
double [9]


decompiled_code:
void __fastcall micro_bc(double *a1, __int64 a2)
{
if ( bc_zou_he_east == (_DWORD)a2 )
{
zou_he_east(a1);
}
else if ( bc_zou_he_north == (_DWORD)a2 )
{
zou_he_north(a1);
}
else if ( bc_zou_he_west == (_DWORD)a2 )
{
zou_he_west(a1);
}
else if ( bc_zou_he_south == (_DWORD)a2 )
{
zou_he_south(a1);
}
else if ( bc_zou_he_north_east == (_DWORD)a2 )
{
zou_he_north_east(a1);
}
else if ( bc_zou_he_north_west == (_DWORD)a2 )
{
zou_he_north_west(a1);
}
else if ( bc_zou_he_south_west == (_DWORD)a2 )
{
zou_he_south_west(a1);
}
else if ( bc_zou_he_south_east == (_DWORD)a2 )
{
zou_he_south_east(a1);
}
else if ( bc_regularized_east == (_DWORD)a2 )
{
bc_regularized_straight((__int64)a1, 0, a1[11], a1[9], a1[10]);
}
else if ( bc_regularized_north == (_DWORD)a2 )
{
bc_regularized_straight((__int64)a1, 1, a1[11], a1[9], a1[10]);
}
else if ( bc_regularized_west == (_DWORD)a2 )
{
bc_regularized_straight((__int64)a1, 2, a1[11], a1[9], a1[10]);
}
else if ( bc_regularized_south == (_DWORD)a2 )
{
bc_regularized_straight((__int64)a1, 3, a1[11], a1[9], a1[10]);
}
else
{
printf("Unknown micro_bc type: %d\n", a2);
}
}

canonical_decompiled_code:
void __fastcall func10(double *a1, __int64 a2)
{
if ( bc_zou_he_east == (_DWORD)a2 )
{
func0(a1);
}
else if ( bc_zou_he_north == (_DWORD)a2 )
{
func2(a1);
}
else if ( bc_zou_he_west == (_DWORD)a2 )
{
func1(a1);
}
else if ( bc_zou_he_south == (_DWORD)a2 )
{
func3(a1);
}
else if ( bc_zou_he_north_east == (_DWORD)a2 )
{
func4(a1);
}
else if ( bc_zou_he_north_west == (_DWORD)a2 )
{
func5(a1);
}
else if ( bc_zou_he_south_west == (_DWORD)a2 )
{
func7(a1);
}
else if ( bc_zou_he_south_east == (_DWORD)a2 )
{
func6(a1);
}
else if ( bc_regularized_east == (_DWORD)a2 )
{
func9((__int64)a1, 0, a1[11], a1[9], a1[10]);
}
else if ( bc_regularized_north == (_DWORD)a2 )
{
func9((__int64)a1, 1, a1[11], a1[9], a1[10]);
}
else if ( bc_regularized_west == (_DWORD)a2 )
{
func9((__int64)a1, 2, a1[11], a1[9], a1[10]);
}
else if ( bc_regularized_south == (_DWORD)a2 )
{
func9((__int64)a1, 3, a1[11], a1[9], a1[10]);
}
else
{
printf("Unknown micro_bc type: %d\n", a2);
}
}

original_code:
void micro_bc(Node * node, unsigned int type)
{
 if(type == bc_zou_he_east)
  zou_he_east(node);
 else if(type == bc_zou_he_north)
  zou_he_north(node);
 else if(type == bc_zou_he_west)
  zou_he_west(node);
 else if(type == bc_zou_he_south)
  zou_he_south(node);
 else if(type == bc_zou_he_north_east)
  zou_he_north_east(node);
 else if(type == bc_zou_he_north_west)
  zou_he_north_west(node);
 else if(type == bc_zou_he_south_west)
  zou_he_south_west(node);
 else if(type == bc_zou_he_south_east)
  zou_he_south_east(node);
 else if(type == bc_regularized_east)
  bc_regularized_straight(node->f, node->rho, node->u[0], node->u[1], 0);
 else if(type == bc_regularized_north)
  bc_regularized_straight(node->f, node->rho, node->u[0], node->u[1], 1);
 else if(type == bc_regularized_west)
  bc_regularized_straight(node->f, node->rho, node->u[0], node->u[1], 2);
 else if(type == bc_regularized_south)
  bc_regularized_straight(node->f, node->rho, node->u[0], node->u[1], 3);
 else
  printf("Unknown micro_bc type: %d\n", type);
}

canonical_original_code:
void micro_bc(struct Node *node, unsigned int type)
{
 if(type == bc_zou_he_east)
  zou_he_east(node);
 else if(type == bc_zou_he_north)
  zou_he_north(node);
 else if(type == bc_zou_he_west)
  zou_he_west(node);
 else if(type == bc_zou_he_south)
  zou_he_south(node);
 else if(type == bc_zou_he_north_east)
  zou_he_north_east(node);
 else if(type == bc_zou_he_north_west)
  zou_he_north_west(node);
 else if(type == bc_zou_he_south_west)
  zou_he_south_west(node);
 else if(type == bc_zou_he_south_east)
  zou_he_south_east(node);
 else if(type == bc_regularized_east)
  bc_regularized_straight(node->f, node->rho, node->u[0], node->u[1], 0);
 else if(type == bc_regularized_north)
  bc_regularized_straight(node->f, node->rho, node->u[0], node->u[1], 1);
 else if(type == bc_regularized_west)
  bc_regularized_straight(node->f, node->rho, node->u[0], node->u[1], 2);
 else if(type == bc_regularized_south)
  bc_regularized_straight(node->f, node->rho, node->u[0], node->u[1], 3);
 else
  printf("Unknown micro_bc type: %d\n", type);
}

variable_types:
type
unsigned int


decompiled_code:
void __fastcall __noreturn do_work(void *a1)
{
_QWORD *v1; // rbx

while ( 1 )
{
pthread_mutex_lock(&job_mutex);
v1 = head_job;
if ( !head_job )
break;
--remaining_jobs;
head_job = (void *)*((_QWORD *)head_job + 2);
pthread_mutex_unlock(&job_mutex);
((void (__fastcall *)(_QWORD))*v1)(v1[1]);
free(v1);
}
pthread_mutex_unlock(&job_mutex);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
_QWORD *v1; // rbx

while ( 1 )
{
pthread_mutex_lock(&job_mutex);
v1 = head_job;
if ( !head_job )
break;
--remaining_jobs;
head_job = (void *)*((_QWORD *)head_job + 2);
pthread_mutex_unlock(&job_mutex);
((void (__fastcall *)(_QWORD))*v1)(v1[1]);
free(v1);
}
pthread_mutex_unlock(&job_mutex);
pthread_exit(0LL);
}

original_code:
void * do_work(void * arg)
{
 struct job_node * current_job;
 while(1) {
  pthread_mutex_lock(&job_mutex);
  if(head_job) {
   --remaining_jobs;
   current_job = head_job;
   head_job = head_job->next;
  } else {
   pthread_mutex_unlock(&job_mutex);
   break;
  }
  pthread_mutex_unlock(&job_mutex);
  current_job->predicate(current_job->arg);
  free(current_job);
 }
 pthread_exit(((void *)0));
}

canonical_original_code:
void *do_work(void *arg)
{
 struct job_node *current_job;
 while(1) {
  pthread_mutex_lock(&job_mutex);
  if(head_job) {
   --remaining_jobs;
   current_job = head_job;
   head_job = head_job->next;
  } else {
   pthread_mutex_unlock(&job_mutex);
   break;
  }
  pthread_mutex_unlock(&job_mutex);
  current_job->predicate(current_job->arg);
  free(current_job);
 }
 pthread_exit(((void *)0));
}

variable_types:
arg
void *

variable_types: struct job_node { void (*predicate)(void *); void *arg; struct job_node *next; } *

return_type: void *


decompiled_code:
int __fastcall workerpool_push_job(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx

v2 = malloc(0x18uLL);
v2[2] = 0LL;
*v2 = a1;
v2[1] = a2;
pthread_mutex_lock(&job_mutex);
if ( head_job )
*(_QWORD *)(tail_job + 16) = v2;
else
head_job = v2;
tail_job = (__int64)v2;
++remaining_jobs;
return pthread_mutex_unlock(&job_mutex);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx

v2 = malloc(0x18uLL);
v2[2] = 0LL;
*v2 = a1;
v2[1] = a2;
pthread_mutex_lock(&job_mutex);
if ( head_job )
*(_QWORD *)(tail_job + 16) = v2;
else
head_job = v2;
tail_job = (__int64)v2;
++remaining_jobs;
return pthread_mutex_unlock(&job_mutex);
}

original_code:
void workerpool_push_job(job_predicate_t pred, void * arg)
{
 struct job_node * new_node = (struct job_node *) malloc(sizeof(struct job_node));
 new_node->next = ((void *)0);
 new_node->predicate = pred;
 new_node->arg = arg;
 pthread_mutex_lock(&job_mutex);
 if( ! head_job) {
  head_job = new_node;
  tail_job = new_node;
 } else {
  tail_job->next = new_node;
  tail_job = new_node;
 }
 ++remaining_jobs;
 pthread_mutex_unlock(&job_mutex);
}

canonical_original_code:
void workerpool_push_job(void (*pred)(void *), void *arg)
{
 struct job_node *new_node = (struct job_node *) malloc(sizeof(struct job_node));
 new_node->next = ((void *)0);
 new_node->predicate = pred;
 new_node->arg = arg;
 pthread_mutex_lock(&job_mutex);
 if( ! head_job) {
  head_job = new_node;
  tail_job = new_node;
 } else {
  tail_job->next = new_node;
  tail_job = new_node;
 }
 ++remaining_jobs;
 pthread_mutex_unlock(&job_mutex);
}

variable_types:
pred
void (*)(void *)

user_defined_types: struct job_node { void (*predicate)(void *); void *arg; struct job_node *next; }


decompiled_code:
int workerpool_run()
{
unsigned __int64 v0; // rbx
unsigned int v1; // eax
int result; // eax
unsigned __int64 v3; // rbx
pthread_attr_t v4; // [rsp+0h] [rbp-48h] BYREF

pthread_attr_init(&v4);
pthread_attr_setdetachstate(&v4, 0);
if ( num_threads )
{
v0 = 0LL;
do
{
v1 = pthread_create((pthread_t *)threads + v0, &v4, (void *(*)(void *))do_work, 0LL);
if ( v1 )
{
printf("ERROR: pthread_create, error code: %d\n", v1);
exit(-1);
}
++v0;
}
while ( num_threads > v0 );
}
result = pthread_attr_destroy(&v4);
if ( num_threads )
{
v3 = 0LL;
do
result = pthread_join(*((_QWORD *)threads + v3++), 0LL);
while ( num_threads > v3 );
}
return result;
}

canonical_decompiled_code:
int func2()
{
unsigned __int64 v0; // rbx
unsigned int v1; // eax
int result; // eax
unsigned __int64 v3; // rbx
pthread_attr_t v4; // [rsp+0h] [rbp-48h] BYREF

pthread_attr_init(&v4);
pthread_attr_setdetachstate(&v4, 0);
if ( num_threads )
{
v0 = 0LL;
do
{
v1 = pthread_create((pthread_t *)threads + v0, &v4, (void *(*)(void *))do_work, 0LL);
if ( v1 )
{
printf("ERROR: pthread_create, error code: %d\n", v1);
exit(-1);
}
++v0;
}
while ( num_threads > v0 );
}
result = pthread_attr_destroy(&v4);
if ( num_threads )
{
v3 = 0LL;
do
result = pthread_join(*((_QWORD *)threads + v3++), 0LL);
while ( num_threads > v3 );
}
return result;
}

original_code:
void workerpool_run()
{
 size_t i;
 int rc;
 pthread_attr_t attr;
 pthread_attr_init(&attr);
 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
 for(i = 0; i < num_threads; ++i) {
  rc = pthread_create(&threads[i], &attr, do_work, ((void *)0));
  if(rc) {
   printf("ERROR: pthread_create, error code: %d\n", rc);
   exit(-1);
  }
 }
 pthread_attr_destroy(&attr);
 for(i = 0; i < num_threads; ++i) {
  rc = pthread_join(threads[i], ((void *)0));
 }
}

canonical_original_code:
void workerpool_run()
{
 unsigned long i;
 int rc;
 union pthread_attr_t attr;
 pthread_attr_init(&attr);
 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
 for(i = 0; i < num_threads; ++i) {
  rc = pthread_create(&threads[i], &attr, do_work, ((void *)0));
  if(rc) {
   printf("ERROR: pthread_create, error code: %d\n", rc);
   exit(-1);
  }
 }
 pthread_attr_destroy(&attr);
 for(i = 0; i < num_threads; ++i) {
  rc = pthread_join(threads[i], ((void *)0));
 }
}

variable_types:
i
unsigned long

variable_types: rc int

variable_types: union pthread_attr_t { char __size[56]; long __align; }


decompiled_code:
void *__fastcall workerpool_init(__int64 a1)
{
void *result; // rax

head_job = 0LL;
tail_job = 0LL;
remaining_jobs = 0LL;
pthread_mutex_init(&job_mutex, 0LL);
num_threads = a1;
result = malloc(8 * a1);
threads = result;
return result;
}

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

head_job = 0LL;
tail_job = 0LL;
remaining_jobs = 0LL;
pthread_mutex_init(&job_mutex, 0LL);
num_threads = a1;
result = malloc(8 * a1);
threads = result;
return result;
}

original_code:
void workerpool_init(size_t thread_count)
{
 head_job = ((void *)0);
 tail_job = ((void *)0);
 remaining_jobs = 0;
 pthread_mutex_init(&job_mutex, ((void *)0));
 num_threads = thread_count;
 threads = (pthread_t *) malloc(num_threads * sizeof(pthread_t));
}

canonical_original_code:
void workerpool_init(unsigned long thread_count)
{
 head_job = ((void *)0);
 tail_job = ((void *)0);
 remaining_jobs = 0;
 pthread_mutex_init(&job_mutex, ((void *)0));
 num_threads = thread_count;
 threads = (unsigned long *) malloc(num_threads * sizeof(pthread_t));
}


decompiled_code:
void workerpool_destroy()
{
_QWORD *v0; // rbx
void *v1; // rdi

pthread_mutex_destroy(&job_mutex);
free(threads);
threads = 0LL;
num_threads = 0LL;
v0 = head_job;
if ( head_job )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[2];
free(v1);
head_job = v0;
}
while ( v0 );
}
head_job = 0LL;
tail_job = 0LL;
remaining_jobs = 0LL;
}

canonical_decompiled_code:
void func4()
{
_QWORD *v0; // rbx
void *v1; // rdi

pthread_mutex_destroy(&job_mutex);
free(threads);
threads = 0LL;
num_threads = 0LL;
v0 = head_job;
if ( head_job )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[2];
free(v1);
head_job = v0;
}
while ( v0 );
}
head_job = 0LL;
tail_job = 0LL;
remaining_jobs = 0LL;
}

original_code:
void workerpool_destroy()
{
 pthread_mutex_destroy(&job_mutex);
 free(threads);
 threads = ((void *)0);
 num_threads = 0;
 struct job_node * next_job;
 while(head_job) {
  next_job = head_job->next;
  free(head_job);
  head_job = next_job;
 }
 head_job = ((void *)0);
 tail_job = ((void *)0);
 remaining_jobs = 0;
}

canonical_original_code:
void workerpool_destroy()
{
 pthread_mutex_destroy(&job_mutex);
 free(threads);
 threads = ((void *)0);
 num_threads = 0;
 struct job_node *next_job;
 while(head_job) {
  next_job = head_job->next;
  free(head_job);
  head_job = next_job;
 }
 head_job = ((void *)0);
 tail_job = ((void *)0);
 remaining_jobs = 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
__int64 v4; // rbp
unsigned __int64 i; // rbx
unsigned __int64 v7; // [rsp+0h] [rbp-28h] BYREF
void *ptr; // [rsp+8h] [rbp-20h] BYREF

if ( argc <= 1 || (v3 = argv[1], strlen(v3) <= 1) )
{
fwrite("Missing parameter file. Usage: ./lbm parameterfile\n", 1uLL, 0x33uLL, stderr);
exit(-1);
}
input_read_param_file(v3, &ptr, &v7);
workerpool_init(1LL);
if ( v7 )
{
v4 = 0LL;
for ( i = 0LL; i < v7; ++i )
{
workerpool_push_job(solve, (char *)ptr + v4);
v4 += 112LL;
}
}
workerpool_run();
workerpool_destroy();
free(ptr);
return 0;
}

original_code:
int main(int argc, char ** argv)
{
 size_t i;
 InputParameters * params;
 size_t params_count;
 if(argc < 2 || strlen(argv[1]) < 2) {
  fprintf(stderr, "Missing parameter file. Usage: ./lbm parameterfile\n");
  exit(-1);
 }
 input_read_param_file(argv[1], &params, &params_count);
 workerpool_init(1);
 for(i = 0; i < params_count; ++i)
  workerpool_push_job(solve, (void *) &params[i]);
 workerpool_run();
 workerpool_destroy();
 free(params);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned long i;
 struct InputParameters *params;
 unsigned long params_count;
 if(argc < 2 || strlen(argv[1]) < 2) {
  fprintf(stderr, "Missing parameter file. Usage: ./lbm parameterfile\n");
  exit(-1);
 }
 input_read_param_file(argv[1], &params, &params_count);
 workerpool_init(1);
 for(i = 0; i < params_count; ++i)
  workerpool_push_job(solve, (void *) &params[i]);
 workerpool_run();
 workerpool_destroy();
 free(params);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct InputParameters { double conf; double kb; double alpha; double init_angle; double init_ang_vel; double freq; double Re_p; double u_max; double tau; unsigned int lx; unsigned int output_step; unsigned int timesteps; int print_ux; int print_uy; int print_rho; int print_particle_state; int print_lyapunov; unsigned int lyapunov_calc_step; } *


original_code:
int lbm_ebf_step(unsigned int it, FlowParams * flow_params, FlowState * flow_state, ParticleState * particle_state, LbmState * lbm_state)
{
 if(flow_params->f < 1.0e-8)
  flow_state->u_ref = flow_params->u_max;
 else
  flow_state->u_ref = flow_params->u_max * sin(flow_params->f * it);
 fsi_run(flow_state, particle_state);
 lbm_run(flow_state, lbm_state);
 if(particle_state->ang_vel != particle_state->ang_vel) {
  fprintf(stderr, "ERROR: Solution has diverged.\n");
  return 0;
 }
 return 1;
}

canonical_original_code:
int lbm_ebf_step(unsigned int it, struct FlowParams *flow_params, struct FlowState *flow_state, struct ParticleState *particle_state, struct LbmState *lbm_state)
{
 if(flow_params->f < 1.0e-8)
  flow_state->u_ref = flow_params->u_max;
 else
  flow_state->u_ref = flow_params->u_max * sin(flow_params->f * it);
 fsi_run(flow_state, particle_state);
 lbm_run(flow_state, lbm_state);
 if(particle_state->ang_vel != particle_state->ang_vel) {
  fprintf(stderr, "ERROR: Solution has diverged.\n");
  return 0;
 }
 return 1;
}

variable_types:
it
unsigned int

variable_types: struct FlowParams { double G; unsigned int lx; } *

variable_types: struct FlowState { unsigned int lx; int *macro_bc; int *micro_bc; int *is_corner; double *force[2]; double *rho; double *u[2]; double tau; double u_ref; double G; } *

variable_types: struct ParticleState { double angle; double *volume; double *coord_p[2]; double *coord_a[2]; unsigned int nodes; double coord_c[2]; double inertia; double torque; double *force_fsi[2]; double width; } *

variable_types: struct LbmState { unsigned int lx; double *f[9]; } *


decompiled_code:
int __fastcall print_info(__int64 a1, double *a2)
{
double v2; // xmm0_8
double v3; // xmm3_8
double v5; // [rsp+8h] [rbp-30h]
double v6; // [rsp+10h] [rbp-28h]
double v7; // [rsp+18h] [rbp-20h]

v2 = ((double)*(int *)(a1 + 44) - 1.0) * 0.5;
v3 = v2 * *(double *)(a1 + 24) / ((*(double *)(a1 + 16) - 0.5) * 0.3333333333333333);
v5 = *a2 / v2;
v6 = v3 * v5 * v5;
v7 = a2[2] / *(double *)(a1 + 32) * v6;
printf("Domain dimensions = %d x %d\n", *(unsigned int *)(a1 + 40), *(unsigned int *)(a1 + 44));
printf("Confinement = %f\n", v5);
printf("tau = %f\n", *(double *)(a1 + 16));
printf("Re_d = %f\n", v3);
printf("Re_p = %f\n", v6);
printf("St = %f\n", v7);
printf("Particle major axis length = %f\n", *a2);
return printf("Particle minor axis length = %f\n", a2[1]);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, double *a2)
{
double v2; // xmm0_8
double v3; // xmm3_8
double v5; // [rsp+8h] [rbp-30h]
double v6; // [rsp+10h] [rbp-28h]
double v7; // [rsp+18h] [rbp-20h]

v2 = ((double)*(int *)(a1 + 44) - 1.0) * 0.5;
v3 = v2 * *(double *)(a1 + 24) / ((*(double *)(a1 + 16) - 0.5) * 0.3333333333333333);
v5 = *a2 / v2;
v6 = v3 * v5 * v5;
v7 = a2[2] / *(double *)(a1 + 32) * v6;
printf("Domain dimensions = %d x %d\n", *(unsigned int *)(a1 + 40), *(unsigned int *)(a1 + 44));
printf("Confinement = %f\n", v5);
printf("tau = %f\n", *(double *)(a1 + 16));
printf("Re_d = %f\n", v3);
printf("Re_p = %f\n", v6);
printf("St = %f\n", v7);
printf("Particle major axis length = %f\n", *a2);
return printf("Particle minor axis length = %f\n", a2[1]);
}

original_code:
void print_info(FlowParams * flow_params, FsiParams * fsi_params)
{
 double visc = (1.0/3.0) * (flow_params->tau - 0.5);
 double Re = flow_params->u_max * ((flow_params->ly - 1.0)/2.0) / visc;
 double conf = (fsi_params->a / ((flow_params->ly - 1.0)/2.0));
 double Re_p = Re * conf * conf;
 double St = fsi_params->rho / flow_params->rho * Re_p;
 printf("Domain dimensions = %d x %d\n", flow_params->lx, flow_params->ly);
 printf("Confinement = %f\n", conf);
 printf("tau = %f\n", flow_params->tau);
 printf("Re_d = %f\n", Re);
 printf("Re_p = %f\n", Re_p);
 printf("St = %f\n", St);
 printf("Particle major axis length = %f\n", fsi_params->a);
 printf("Particle minor axis length = %f\n", fsi_params->b);
}

canonical_original_code:
void print_info(struct FlowParams *flow_params, struct FsiParams *fsi_params)
{
 double visc = (1.0/3.0) * (flow_params->tau - 0.5);
 double Re = flow_params->u_max * ((flow_params->ly - 1.0)/2.0) / visc;
 double conf = (fsi_params->a / ((flow_params->ly - 1.0)/2.0));
 double Re_p = Re * conf * conf;
 double St = fsi_params->rho / flow_params->rho * Re_p;
 printf("Domain dimensions = %d x %d\n", flow_params->lx, flow_params->ly);
 printf("Confinement = %f\n", conf);
 printf("tau = %f\n", flow_params->tau);
 printf("Re_d = %f\n", Re);
 printf("Re_p = %f\n", Re_p);
 printf("St = %f\n", St);
 printf("Particle major axis length = %f\n", fsi_params->a);
 printf("Particle minor axis length = %f\n", fsi_params->b);
}

variable_types: struct FsiParams { double a; double coord_c[2]; unsigned int nodes; } *

variable_types: visc double

variable_types: Re double

variable_types: conf double

variable_types: St double

user_defined_types: struct FlowParams { double G; unsigned int lx; }


original_code:
void input_init_params(InputParameters * params)
{
 params->kb = 0.5;
 params->alpha = 1;
 params->freq = 0.1;
 params->Re_p = 1;
 params->u_max = 0.01;
 params->tau = ((double)1.79769313486231570814527423731704357e+308L);
 params->lx = 100;
 params->ly = 100;
 params->conf = 0.2;
 params->init_angle = 0;
 params->init_ang_vel = 0;
 params->output_step = 400;
 params->print_particle_state = 1;
 params->print_rho = 0;
 params->print_ux = 0;
 params->print_uy = 0;
 params->timesteps = (unsigned int)-1;
 params->print_lyapunov = 0;
 params->lyapunov_calc_step = 100;
}

canonical_original_code:
void input_init_params(struct InputParameters *params)
{
 params->kb = 0.5;
 params->alpha = 1;
 params->freq = 0.1;
 params->Re_p = 1;
 params->u_max = 0.01;
 params->tau = ((double)1.79769313486231570814527423731704357e+308L);
 params->lx = 100;
 params->ly = 100;
 params->conf = 0.2;
 params->init_angle = 0;
 params->init_ang_vel = 0;
 params->output_step = 400;
 params->print_particle_state = 1;
 params->print_rho = 0;
 params->print_ux = 0;
 params->print_uy = 0;
 params->timesteps = (unsigned int)-1;
 params->print_lyapunov = 0;
 params->lyapunov_calc_step = 100;
}

user_defined_types: struct InputParameters { double conf; double kb; double alpha; double init_angle; double init_ang_vel; double freq; double Re_p; double u_max; double tau; unsigned int lx; unsigned int output_step; unsigned int timesteps; int print_ux; int print_uy; int print_rho; int print_particle_state; int print_lyapunov; unsigned int lyapunov_calc_step; }


decompiled_code:
__int64 __fastcall input_set_parameter(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax

if ( !strcmp(a2, "Re_p") )
{
*(double *)(a1 + 48) = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "conf") )
{
*(double *)a1 = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "kb") )
{
*(double *)(a1 + 8) = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "alpha") )
{
*(double *)(a1 + 16) = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "freq") )
{
*(double *)(a1 + 40) = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "umax") )
{
*(double *)(a1 + 56) = atof(a3);
*(_QWORD *)(a1 + 64) = LC2;
result = 1LL;
}
else if ( !strcmp(a2, "tau") )
{
*(double *)(a1 + 64) = atof(a3);
*(_QWORD *)(a1 + 56) = LC2;
result = 1LL;
}
else if ( !strcmp(a2, "lx") )
{
*(_DWORD *)(a1 + 72) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "ly") )
{
*(_DWORD *)(a1 + 76) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "angle") )
{
*(double *)(a1 + 24) = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "ang_vel") )
{
*(double *)(a1 + 32) = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "output_step") )
{
*(_DWORD *)(a1 + 80) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "print_particle") )
{
*(_DWORD *)(a1 + 100) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "print_rho") )
{
*(_DWORD *)(a1 + 96) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "print_ux") )
{
*(_DWORD *)(a1 + 88) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "print_uy") )
{
*(_DWORD *)(a1 + 92) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "print_lyapunov") )
{
*(_DWORD *)(a1 + 104) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "lyapunov_calc_step") )
{
*(_DWORD *)(a1 + 108) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "timesteps") )
{
*(_DWORD *)(a1 + 84) = atoi(a3);
result = 1LL;
}
else
{
result = 0LL;
}
return result;
}

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

if ( !strcmp(a2, "Re_p") )
{
*(double *)(a1 + 48) = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "conf") )
{
*(double *)a1 = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "kb") )
{
*(double *)(a1 + 8) = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "alpha") )
{
*(double *)(a1 + 16) = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "freq") )
{
*(double *)(a1 + 40) = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "umax") )
{
*(double *)(a1 + 56) = atof(a3);
*(_QWORD *)(a1 + 64) = LC2;
result = 1LL;
}
else if ( !strcmp(a2, "tau") )
{
*(double *)(a1 + 64) = atof(a3);
*(_QWORD *)(a1 + 56) = LC2;
result = 1LL;
}
else if ( !strcmp(a2, "lx") )
{
*(_DWORD *)(a1 + 72) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "ly") )
{
*(_DWORD *)(a1 + 76) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "angle") )
{
*(double *)(a1 + 24) = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "ang_vel") )
{
*(double *)(a1 + 32) = atof(a3);
result = 1LL;
}
else if ( !strcmp(a2, "output_step") )
{
*(_DWORD *)(a1 + 80) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "print_particle") )
{
*(_DWORD *)(a1 + 100) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "print_rho") )
{
*(_DWORD *)(a1 + 96) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "print_ux") )
{
*(_DWORD *)(a1 + 88) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "print_uy") )
{
*(_DWORD *)(a1 + 92) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "print_lyapunov") )
{
*(_DWORD *)(a1 + 104) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "lyapunov_calc_step") )
{
*(_DWORD *)(a1 + 108) = atoi(a3);
result = 1LL;
}
else if ( !strcmp(a2, "timesteps") )
{
*(_DWORD *)(a1 + 84) = atoi(a3);
result = 1LL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int input_set_parameter(InputParameters * params, char * key, char * value)
{
 if(strcmp(key, "Re_p") == 0)
  params->Re_p = atof(value);
 else if(strcmp(key, "conf") == 0)
  params->conf = atof(value);
 else if(strcmp(key, "kb") == 0)
  params->kb = atof(value);
 else if(strcmp(key, "alpha") == 0)
  params->alpha = atof(value);
 else if(strcmp(key, "freq") == 0)
  params->freq = atof(value);
 else if(strcmp(key, "umax") == 0) {
  params->u_max = atof(value);
  params->tau = ((double)1.79769313486231570814527423731704357e+308L);
 } else if(strcmp(key, "tau") == 0) {
  params->tau = atof(value);
  params->u_max = ((double)1.79769313486231570814527423731704357e+308L);
 } else if(strcmp(key, "lx") == 0)
  params->lx = atoi(value);
 else if(strcmp(key, "ly") == 0)
  params->ly = atoi(value);
 else if(strcmp(key, "angle") == 0)
  params->init_angle = atof(value);
 else if(strcmp(key, "ang_vel") == 0)
  params->init_ang_vel = atof(value);
 else if(strcmp(key, "output_step") == 0)
  params->output_step = atoi(value);
 else if(strcmp(key, "print_particle") == 0)
  params->print_particle_state = atoi(value);
 else if(strcmp(key, "print_rho") == 0)
  params->print_rho = atoi(value);
 else if(strcmp(key, "print_ux") == 0)
  params->print_ux = atoi(value);
 else if(strcmp(key, "print_uy") == 0)
  params->print_uy = atoi(value);
 else if(strcmp(key, "print_lyapunov") == 0)
  params->print_lyapunov = atoi(value);
 else if(strcmp(key, "lyapunov_calc_step") == 0)
  params->lyapunov_calc_step = atoi(value);
 else if(strcmp(key, "timesteps") == 0)
  params->timesteps = atoi(value);
 else
  return 0;
 return 1;
}

canonical_original_code:
int input_set_parameter(struct InputParameters *params, char *key, char *value)
{
 if(strcmp(key, "Re_p") == 0)
  params->Re_p = atof(value);
 else if(strcmp(key, "conf") == 0)
  params->conf = atof(value);
 else if(strcmp(key, "kb") == 0)
  params->kb = atof(value);
 else if(strcmp(key, "alpha") == 0)
  params->alpha = atof(value);
 else if(strcmp(key, "freq") == 0)
  params->freq = atof(value);
 else if(strcmp(key, "umax") == 0) {
  params->u_max = atof(value);
  params->tau = ((double)1.79769313486231570814527423731704357e+308L);
 } else if(strcmp(key, "tau") == 0) {
  params->tau = atof(value);
  params->u_max = ((double)1.79769313486231570814527423731704357e+308L);
 } else if(strcmp(key, "lx") == 0)
  params->lx = atoi(value);
 else if(strcmp(key, "ly") == 0)
  params->ly = atoi(value);
 else if(strcmp(key, "angle") == 0)
  params->init_angle = atof(value);
 else if(strcmp(key, "ang_vel") == 0)
  params->init_ang_vel = atof(value);
 else if(strcmp(key, "output_step") == 0)
  params->output_step = atoi(value);
 else if(strcmp(key, "print_particle") == 0)
  params->print_particle_state = atoi(value);
 else if(strcmp(key, "print_rho") == 0)
  params->print_rho = atoi(value);
 else if(strcmp(key, "print_ux") == 0)
  params->print_ux = atoi(value);
 else if(strcmp(key, "print_uy") == 0)
  params->print_uy = atoi(value);
 else if(strcmp(key, "print_lyapunov") == 0)
  params->print_lyapunov = atoi(value);
 else if(strcmp(key, "lyapunov_calc_step") == 0)
  params->lyapunov_calc_step = atoi(value);
 else if(strcmp(key, "timesteps") == 0)
  params->timesteps = atoi(value);
 else
  return 0;
 return 1;
}

variable_types:
key
char *

variable_types:
value
char *


original_code:
void macro_bc_north_east(Node * node, FlowState * f_state)
{
 node->u[0] = f_state->u_ref;
 node->u[1] = 0.0;
 node->rho = f_state->rho[(node->coord[0]-1)*f_state->ly + node->coord[1] ] +
    f_state->rho[(node->coord[0] )*f_state->ly + node->coord[1]-1] -
    f_state->rho[(node->coord[0]-1)*f_state->ly + node->coord[1]-1];
}

canonical_original_code:
void macro_bc_north_east(struct Node *node, struct FlowState *f_state)
{
 node->u[0] = f_state->u_ref;
 node->u[1] = 0.0;
 node->rho = f_state->rho[(node->coord[0]-1)*f_state->ly + node->coord[1] ] +
    f_state->rho[(node->coord[0] )*f_state->ly + node->coord[1]-1] -
    f_state->rho[(node->coord[0]-1)*f_state->ly + node->coord[1]-1];
}

variable_types: struct Node { double f[9]; double u[2]; double rho; int coord[2]; double force[2]; } *

user_defined_types: struct FlowState { unsigned int lx; int *macro_bc; int *micro_bc; int *is_corner; double *force[2]; double *rho; double *u[2]; double tau; double u_ref; double G; }


original_code:
void macro_bc_north_west(Node * node, FlowState * f_state)
{
 node->u[0] = f_state->u_ref;
 node->u[1] = 0.0;
 node->rho = f_state->rho[(node->coord[0]+1)*f_state->ly + node->coord[1] ] +
    f_state->rho[(node->coord[0] )*f_state->ly + node->coord[1]-1] -
    f_state->rho[(node->coord[0]+1)*f_state->ly + node->coord[1]-1];
}

canonical_original_code:
void macro_bc_north_west(struct Node *node, struct FlowState *f_state)
{
 node->u[0] = f_state->u_ref;
 node->u[1] = 0.0;
 node->rho = f_state->rho[(node->coord[0]+1)*f_state->ly + node->coord[1] ] +
    f_state->rho[(node->coord[0] )*f_state->ly + node->coord[1]-1] -
    f_state->rho[(node->coord[0]+1)*f_state->ly + node->coord[1]-1];
}


original_code:
void macro_bc_south_west(Node * node, FlowState * f_state)
{
 node->u[0] = -f_state->u_ref;
 node->u[1] = 0.0;
 node->rho = f_state->rho[(node->coord[0]+1)*f_state->ly + node->coord[1] ] +
    f_state->rho[(node->coord[0] )*f_state->ly + node->coord[1]+1] -
    f_state->rho[(node->coord[0]+1)*f_state->ly + node->coord[1]+1];
}

canonical_original_code:
void macro_bc_south_west(struct Node *node, struct FlowState *f_state)
{
 node->u[0] = -f_state->u_ref;
 node->u[1] = 0.0;
 node->rho = f_state->rho[(node->coord[0]+1)*f_state->ly + node->coord[1] ] +
    f_state->rho[(node->coord[0] )*f_state->ly + node->coord[1]+1] -
    f_state->rho[(node->coord[0]+1)*f_state->ly + node->coord[1]+1];
}


original_code:
void macro_bc_south_east(Node * node, FlowState * f_state)
{
 node->u[0] = -f_state->u_ref;
 node->u[1] = 0.0;
 node->rho = f_state->rho[(node->coord[0]-1)*f_state->ly + node->coord[1] ] +
    f_state->rho[(node->coord[0] )*f_state->ly + node->coord[1]+1] -
    f_state->rho[(node->coord[0]-1)*f_state->ly + node->coord[1]+1];
}

canonical_original_code:
void macro_bc_south_east(struct Node *node, struct FlowState *f_state)
{
 node->u[0] = -f_state->u_ref;
 node->u[1] = 0.0;
 node->rho = f_state->rho[(node->coord[0]-1)*f_state->ly + node->coord[1] ] +
    f_state->rho[(node->coord[0] )*f_state->ly + node->coord[1]+1] -
    f_state->rho[(node->coord[0]-1)*f_state->ly + node->coord[1]+1];
}


decompiled_code:
void __fastcall macro_bc(__int64 a1, __int64 a2, unsigned int a3)
{
if ( bc_east == a3 )
{
macro_bc_east(a1, a2);
}
else if ( bc_north == a3 )
{
macro_bc_north(a1, a2);
}
else if ( bc_west == a3 )
{
macro_bc_west(a1, a2);
}
else if ( bc_south == a3 )
{
macro_bc_south(a1, a2);
}
else if ( bc_north_east == a3 )
{
macro_bc_north_east(a1, a2);
}
else if ( bc_north_west == a3 )
{
macro_bc_north_west(a1, a2);
}
else if ( bc_south_west == a3 )
{
macro_bc_south_west(a1, a2);
}
else if ( bc_south_east == a3 )
{
macro_bc_south_east(a1, a2);
}
else
{
printf("Unknown bc type: %d\n", a3);
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, __int64 a2, unsigned int a3)
{
if ( bc_east == a3 )
{
func0(a1, a2);
}
else if ( bc_north == a3 )
{
func2(a1, a2);
}
else if ( bc_west == a3 )
{
func1(a1, a2);
}
else if ( bc_south == a3 )
{
func3(a1, a2);
}
else if ( bc_north_east == a3 )
{
func4(a1, a2);
}
else if ( bc_north_west == a3 )
{
func5(a1, a2);
}
else if ( bc_south_west == a3 )
{
func6(a1, a2);
}
else if ( bc_south_east == a3 )
{
func7(a1, a2);
}
else
{
printf("Unknown bc type: %d\n", a3);
}
}

original_code:
void macro_bc(Node * node, FlowState * f_state, unsigned int type)
{
 if(type == bc_east)
  macro_bc_east(node, f_state);
 else if(type == bc_north)
  macro_bc_north(node, f_state);
 else if(type == bc_west)
  macro_bc_west(node, f_state);
 else if(type == bc_south)
  macro_bc_south(node, f_state);
 else if(type == bc_north_east)
  macro_bc_north_east(node, f_state);
 else if(type == bc_north_west)
  macro_bc_north_west(node, f_state);
 else if(type == bc_south_west)
  macro_bc_south_west(node, f_state);
 else if(type == bc_south_east)
  macro_bc_south_east(node, f_state);
 else
  printf("Unknown bc type: %d\n", type);
}

canonical_original_code:
void macro_bc(struct Node *node, struct FlowState *f_state, unsigned int type)
{
 if(type == bc_east)
  macro_bc_east(node, f_state);
 else if(type == bc_north)
  macro_bc_north(node, f_state);
 else if(type == bc_west)
  macro_bc_west(node, f_state);
 else if(type == bc_south)
  macro_bc_south(node, f_state);
 else if(type == bc_north_east)
  macro_bc_north_east(node, f_state);
 else if(type == bc_north_west)
  macro_bc_north_west(node, f_state);
 else if(type == bc_south_west)
  macro_bc_south_west(node, f_state);
 else if(type == bc_south_east)
  macro_bc_south_east(node, f_state);
 else
  printf("Unknown bc type: %d\n", type);
}

variable_types:
type
unsigned int


decompiled_code:
int __fastcall do_mkdir(char *path, __mode_t mode)
{
int result; // eax
struct stat v3; // [rsp+0h] [rbp-A8h] BYREF

result = stat(path, &v3);
if ( result )
{
result = mkdir(path, mode);
if ( result )
result = -(*_errno_location() != 17);
}
else if ( (v3.st_mode & 0xF000) != 0x4000 )
{
*_errno_location() = 20;
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *path, __mode_t mode)
{
int result; // eax
struct stat v3; // [rsp+0h] [rbp-A8h] BYREF

result = stat(path, &v3);
if ( result )
{
result = mkdir(path, mode);
if ( result )
result = -(*_errno_location() != 17);
}
else if ( (v3.st_mode & 0xF000) != 0x4000 )
{
*_errno_location() = 20;
result = -1;
}
return result;
}

original_code:
int do_mkdir(char * path, mode_t mode)
{
 struct stat st;
 int status = 0;
 if (stat(path, &st) != 0) {
  if (mkdir(path, mode) != 0 && (*__errno_location ()) != 17)
   status = -1;
 } else if (!((((st.st_mode)) & 0170000) == (0040000))) {
  (*__errno_location ()) = 20;
  status = -1;
 }
 return status;
}

canonical_original_code:
int do_mkdir(char *path, unsigned int mode)
{
 struct stat st;
 int status = 0;
 if (stat(path, &st) != 0) {
  if (mkdir(path, mode) != 0 && (*__errno_location ()) != 17)
   status = -1;
 } else if (!((((st.st_mode)) & 0170000) == (0040000))) {
  (*__errno_location ()) = 20;
  status = -1;
 }
 return status;
}

variable_types:
path
char *

variable_types:
mode
unsigned int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: status int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


original_code:
void flow_init_state(FlowParams * f_params, FlowState * f_state)
{
 unsigned int i, j, k, nx, ny, idx;
 nx = f_params->lx;
 ny = f_params->ly;
 f_state->G = f_params->G;
 f_state->u_ref = f_params->u_max;
 f_state->tau = f_params->tau;
 for(i = 0; i < nx; ++i) {
  for(j=0; j < ny; ++j) {
   idx = i*ny + j;
   for(k = 0; k < 2; ++k) {
    f_state->force[k][idx] = 0;
    f_state->u[k][idx] = 0;
   }
   if(f_params->f < 1e-8)
    f_state->u[0][idx] = f_state->u_ref * (-1.0 + 2.0*((double)j / (ny - 1.0)));
   f_state->rho[idx] = f_params->rho;
   f_state->macro_bc[idx] = 0;
   f_state->micro_bc[idx] = 0;
   f_state->is_corner[idx] = 0;
  }
 }
 for(i = 0; i < nx; ++i) {
  f_state->macro_bc[i*ny + ny-1] = bc_north;
  f_state->macro_bc[i*ny + 0 ] = bc_south;
  f_state->micro_bc[i*ny + ny-1] = bc_regularized_north;
  f_state->micro_bc[i*ny + 0 ] = bc_regularized_south;
 }
}

canonical_original_code:
void flow_init_state(struct FlowParams *f_params, struct FlowState *f_state)
{
 unsigned int i; unsigned int j; unsigned int k; unsigned int nx; unsigned int ny; unsigned int idx;
 nx = f_params->lx;
 ny = f_params->ly;
 f_state->G = f_params->G;
 f_state->u_ref = f_params->u_max;
 f_state->tau = f_params->tau;
 for(i = 0; i < nx; ++i) {
  for(j=0; j < ny; ++j) {
   idx = i*ny + j;
   for(k = 0; k < 2; ++k) {
    f_state->force[k][idx] = 0;
    f_state->u[k][idx] = 0;
   }
   if(f_params->f < 1e-8)
    f_state->u[0][idx] = f_state->u_ref * (-1.0 + 2.0*((double)j / (ny - 1.0)));
   f_state->rho[idx] = f_params->rho;
   f_state->macro_bc[idx] = 0;
   f_state->micro_bc[idx] = 0;
   f_state->is_corner[idx] = 0;
  }
 }
 for(i = 0; i < nx; ++i) {
  f_state->macro_bc[i*ny + ny-1] = bc_north;
  f_state->macro_bc[i*ny + 0 ] = bc_south;
  f_state->micro_bc[i*ny + ny-1] = bc_regularized_north;
  f_state->micro_bc[i*ny + 0 ] = bc_regularized_south;
 }
}

variable_types: struct FlowParams { double G; unsigned int lx; } *

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
k
unsigned int

variable_types:
nx
unsigned int

variable_types:
ny
unsigned int

variable_types:
idx
unsigned int


original_code:
void flow_copy_state(const FlowState * src, FlowState * dest)
{
 unsigned int i, j, k, nx, ny, idx;
 nx = src->lx;
 ny = src->ly;
 dest->G = src->G;
 dest->u_ref = src->u_ref;
 dest->tau = src->tau;

#pragma omp for
 for(i = 0; i < nx*ny; ++i) {
  dest->macro_bc[i] = src->macro_bc[i];
  dest->micro_bc[i] = src->micro_bc[i];
  dest->is_corner[i] = src->is_corner[i];
  dest->rho[i] = src->rho[i];
  for(k = 0; k < 2; ++k) {
   dest->force[k][i] = src->force[k][i];
   dest->u[k][i] = src->u[k][i];
  }
 }
}

canonical_original_code:
void flow_copy_state(struct FlowState *src, struct FlowState *dest)
{
 unsigned int i; unsigned int j; unsigned int k; unsigned int nx; unsigned int ny; unsigned int idx;
 nx = src->lx;
 ny = src->ly;
 dest->G = src->G;
 dest->u_ref = src->u_ref;
 dest->tau = src->tau;

#pragma omp for
 for(i = 0; i < nx*ny; ++i) {
  dest->macro_bc[i] = src->macro_bc[i];
  dest->micro_bc[i] = src->micro_bc[i];
  dest->is_corner[i] = src->is_corner[i];
  dest->rho[i] = src->rho[i];
  for(k = 0; k < 2; ++k) {
   dest->force[k][i] = src->force[k][i];
   dest->u[k][i] = src->u[k][i];
  }
 }
}

variable_types: struct FlowState { unsigned int lx; int *macro_bc; int *micro_bc; int *is_corner; double *force[2]; double *rho; double *u[2]; double tau; double u_ref; double G; } *

variable_types:
dest
struct FlowState *


decompiled_code:
void __fastcall flow_free_state(void *ptr)
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 7));
free(*((void **)ptr + 5));
free(*((void **)ptr + 8));
free(*((void **)ptr + 6));
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 7));
free(*((void **)ptr + 5));
free(*((void **)ptr + 8));
free(*((void **)ptr + 6));
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
void flow_free_state(FlowState * f_state)
{
 unsigned int k;
 for(k = 0; k < 2; ++k) {
  free(f_state->force[k]);
  free(f_state->u[k]);
 }
 free(f_state->rho);
 free(f_state->macro_bc);
 free(f_state->micro_bc);
 free(f_state->is_corner);
 free(f_state);
}

canonical_original_code:
void flow_free_state(struct FlowState *f_state)
{
 unsigned int k;
 for(k = 0; k < 2; ++k) {
  free(f_state->force[k]);
  free(f_state->u[k]);
 }
 free(f_state->rho);
 free(f_state->macro_bc);
 free(f_state->micro_bc);
 free(f_state->is_corner);
 free(f_state);
}


feq

decompiled_code:
double __fastcall feq(int a1, double a2, double a3, double a4)
{
double v4; // xmm3_8

v4 = (a3 * qword_160[a1] + a4 * cy[a1]) * 3.0;
return (v4 * 0.5 * v4 + v4 + 1.0 - (a3 * a3 + a4 * a4) * 1.5) * (a2 * weight[a1]);
}

canonical_decompiled_code:
double __fastcall func0(int a1, double a2, double a3, double a4)
{
double v4; // xmm3_8

v4 = (a3 * qword_160[a1] + a4 * cy[a1]) * 3.0;
return (v4 * 0.5 * v4 + v4 + 1.0 - (a3 * a3 + a4 * a4) * 1.5) * (a2 * weight[a1]);
}

original_code:
double feq(unsigned int k, double rho0, double ux0, double uy0)
 {
  double cu = 3*(cx[k]*ux0 + cy[k]*uy0);
  return rho0 * weight[k] *
    (1 + cu + 0.5*cu*cu - (3.0/2.0)*(ux0*ux0 + uy0*uy0));
 }

variable_types: cu double

return_type: double


repo: nicogarcia/sd

decompiled_code:
void __noreturn server_listen()
{
pthread_t v0; // [rsp+0h] [rbp-38h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF
int arg[3]; // [rsp+2Ch] [rbp-Ch] BYREF

addr_len = 16;
while ( 1 )
{
arg[0] = accept(sockfd, &addr, &addr_len);
if ( arg[0] < 0 )
break;
pthread_create(&v0, 0LL, (void *(*)(void *))server_task, arg);
}
error("server> ERROR accepting\n");
}

canonical_decompiled_code:
void __noreturn func10()
{
pthread_t v0; // [rsp+0h] [rbp-38h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF
int arg[3]; // [rsp+2Ch] [rbp-Ch] BYREF

addr_len = 16;
while ( 1 )
{
arg[0] = accept(sockfd, &addr, &addr_len);
if ( arg[0] < 0 )
break;
pthread_create(&v0, 0LL, (void *(*)(void *))server_task, arg);
}
func8("server> ERROR accepting\n");
}

original_code:
void server_listen()
{
 double et;
 struct timeval t1, t2;
 int newsockfd;
 struct sockaddr_in cli_addr;
 socklen_t clilen = sizeof(cli_addr);
 pthread_t worker;
 while(1)
 {
  newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  if (newsockfd < 0) error("server> ERROR accepting\n");
  pthread_create(&worker, ((void *)0), server_task, &newsockfd);
 }
}

canonical_original_code:
void server_listen()
{
 double et;
 struct timeval t1; struct timeval t2;
 int newsockfd;
 struct sockaddr_in cli_addr;
 unsigned int clilen = sizeof(cli_addr);
 unsigned long worker;
 while(1)
 {
  newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  if (newsockfd < 0) error("server> ERROR accepting\n");
  pthread_create(&worker, ((void *)0), server_task, &newsockfd);
 }
}

variable_types: et double

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

variable_types: newsockfd 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:
clilen
unsigned int

variable_types:
worker
unsigned long


decompiled_code:
int __fastcall server_init(int a1)
{
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

portno = a1;
sockfd = socket(2, 1, 0);
if ( sockfd < 0 )
error("server> ERROR opening socket");
*(_QWORD *)&v2.sa_family = 2LL;
*(_QWORD *)&v2.sa_data[6] = 0LL;
*(_WORD *)v2.sa_data = _bswap_16(portno);
puts("server> Socket startup ...");
if ( bind(sockfd, &v2, 0x10u) < 0 )
error("server> ERROR binding socket");
return listen(sockfd, 5);
}

canonical_decompiled_code:
int __fastcall func11(int a1)
{
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

portno = a1;
sockfd = socket(2, 1, 0);
if ( sockfd < 0 )
func8("server> ERROR opening socket");
*(_QWORD *)&v2.sa_family = 2LL;
*(_QWORD *)&v2.sa_data[6] = 0LL;
*(_WORD *)v2.sa_data = func7(portno);
puts("server> Socket startup ...");
if ( bind(sockfd, &v2, 0x10u) < 0 )
func8("server> ERROR binding socket");
return listen(sockfd, 5);
}

original_code:
void server_init(int port)
{
 struct sockaddr_in serv_addr;
 portno = port;
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0) error("server> ERROR opening socket");
 bzero((char *) &serv_addr, sizeof(serv_addr));
 serv_addr.sin_family = 2;
 serv_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 serv_addr.sin_port = htons(portno);
 printf("server> Socket startup ...\n");
 if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
  error("server> ERROR binding socket");
 listen(sockfd, 5);
}

canonical_original_code:
void server_init(int port)
{
 struct sockaddr_in serv_addr;
 portno = port;
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0) error("server> ERROR opening socket");
 bzero((char *) &serv_addr, sizeof(serv_addr));
 serv_addr.sin_family = 2;
 serv_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 serv_addr.sin_port = htons(portno);
 printf("server> Socket startup ...\n");
 if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
  error("server> ERROR binding socket");
 listen(sockfd, 5);
}

variable_types: port int


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void error(const char *msg)
{
    perror(msg);
    exit(1);
}

canonical_original_code:
void error(char *msg)
{
    perror(msg);
    exit(1);
}

variable_types:
msg
char *


decompiled_code:
void __fastcall __noreturn server_task(void *a1)
{
char buf; // [rsp+Fh] [rbp-19h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

if ( recv(*(_DWORD *)a1, &buf, 1uLL, 0) >= 0 )
{
gettimeofday(&tv, 0LL);
if ( send(*(_DWORD *)a1, &tv, 0x10uLL, 0) >= 0 )
{
close(*(_DWORD *)a1);
pthread_exit(0LL);
}
error("server> ERROR writing socket");
}
error("server> ERROR reading socket");
}

canonical_decompiled_code:
void __fastcall __noreturn func9(void *a1)
{
char buf; // [rsp+Fh] [rbp-19h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

if ( recv(*(_DWORD *)a1, &buf, 1uLL, 0) >= 0 )
{
gettimeofday(&tv, 0LL);
if ( send(*(_DWORD *)a1, &tv, 0x10uLL, 0) >= 0 )
{
close(*(_DWORD *)a1);
pthread_exit(0LL);
}
func8("server> ERROR writing socket");
}
func8("server> ERROR reading socket");
}

original_code:
void *server_task(int *newsockfd)
{
    struct timeval time;
    char buffer;
    if (recv(*newsockfd, &buffer, sizeof(char), 0) < 0)
     error("server> ERROR reading socket");
    gettimeofday(&time, ((void *)0));
    if (send(*newsockfd, &time, sizeof(struct timeval), 0) < 0)
     error("server> ERROR writing socket");
    close(*newsockfd);
    pthread_exit(0);
}

variable_types:
newsockfd
int *

variable_types: buffer char

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


decompiled_code:
int server_exit()
{
close(sockfd);
return puts("server> Connection end");
}

canonical_decompiled_code:
int func12()
{
close(sockfd);
return puts("server> Connection end");
}

original_code:
void server_exit() {
 close(sockfd);
 printf("server> Connection end\n");
}


decompiled_code:
void __fastcall sig_handler(int a1)
{
if ( a1 == 2 )
{
puts("\nreceived SIGINT");
server_exit();
exit(0);
}
}

canonical_decompiled_code:
void __fastcall func13(int a1)
{
if ( a1 == 2 )
{
puts("\nreceived SIGINT");
func12();
exit(0);
}
}

original_code:
void sig_handler(int signo)
{
  if (signo == 2){
    printf("\nreceived SIGINT\n");
    server_exit();
    exit(0);
  }
}

variable_types: signo int


main

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

if ( argc > 1 )
{
signal(2, sig_handler);
v3 = atoi(argv[1]);
server_init(v3);
server_listen();
}
fprintf(stderr, "usage: %s port\n", *argv);
exit(1);
}

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

if ( argc > 1 )
{
signal(2, sig_handler);
v3 = atoi(argv[1]);
func11(v3);
func10();
}
fprintf(stderr, "usage: %s port\n", *argv);
exit(1);
}

original_code:
int main(int argc, char *argv[])
{
 if (argc < 2) {
  fprintf(stderr,"usage: %s port\n", argv[0]);
  exit(1);
 }
 signal(2, sig_handler);
 server_init(atoi(argv[1]));
 server_listen();
 server_exit();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
_BOOL8 __fastcall xdr_ls(XDR *a1, char *a2)
{
return xdr_vector(a1, a2, 0x800u, 1u, (xdrproc_t)xdr_char) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(XDR *a1, char *a2)
{
return xdr_vector(a1, a2, 0x800u, 1u, (xdrproc_t)xdr_char) != 0;
}

original_code:
bool_t
xdr_ls (XDR *xdrs, ls *objp)
{
 register int32_t *buf;
 int i;
  if (!xdr_vector (xdrs, (char *)objp->str, 2048,
  sizeof (char), (xdrproc_t) xdr_char))
   return (0);
 return (1);
}

canonical_original_code:
int xdr_ls(struct XDR *xdrs, struct ls *objp)
{
 register int *buf;
 int i;
  if (!xdr_vector (xdrs, (char *)objp->str, 2048,
  sizeof (char), (int (*)(struct XDR *, void *, ...)) xdr_char))
   return (0);
 return (1);
}

variable_types: struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *

variable_types:
objp
struct ls { char str[2048]; } *

variable_types:
buf
int *

variable_types: i int

user_defined_types: struct XDR { enum xdr_op x_op; struct xdr_ops *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; }


decompiled_code:
_BOOL8 __fastcall xdr_long_string(XDR *a1, char *a2)
{
return xdr_ls(a1, a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(XDR *a1, char *a2)
{
return func10(a1, a2);
}

original_code:
bool_t
xdr_long_string (XDR *xdrs, long_string *objp)
{
 register int32_t *buf;
  if (!xdr_ls (xdrs, objp))
   return (0);
 return (1);
}

canonical_original_code:
int xdr_long_string(struct XDR *xdrs, struct ls *objp)
{
 register int *buf;
  if (!xdr_ls (xdrs, objp))
   return (0);
 return (1);
}

user_defined_types: enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 }

user_defined_types: struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); }


decompiled_code:
bool_t __fastcall xdr_hls(XDR *xdrs, char *a2)
{
bool_t result; // eax

result = xdr_vector(xdrs, a2, 0x400u, 1u, (xdrproc_t)xdr_char);
if ( result )
result = xdr_vector(xdrs, a2 + 1024, 0x400u, 1u, (xdrproc_t)xdr_char) != 0;
return result;
}

canonical_decompiled_code:
bool_t __fastcall func12(XDR *xdrs, char *a2)
{
bool_t result; // eax

result = xdr_vector(xdrs, a2, 0x400u, 1u, (xdrproc_t)xdr_char);
if ( result )
result = xdr_vector(xdrs, a2 + 1024, 0x400u, 1u, (xdrproc_t)xdr_char) != 0;
return result;
}

original_code:
bool_t
xdr_hls (XDR *xdrs, hls *objp)
{
 register int32_t *buf;
 int i;
  if (!xdr_vector (xdrs, (char *)objp->str1, 1024,
  sizeof (char), (xdrproc_t) xdr_char))
   return (0);
  if (!xdr_vector (xdrs, (char *)objp->str2, 1024,
  sizeof (char), (xdrproc_t) xdr_char))
   return (0);
 return (1);
}

canonical_original_code:
int xdr_hls(struct XDR *xdrs, struct hls *objp)
{
 register int *buf;
 int i;
  if (!xdr_vector (xdrs, (char *)objp->str1, 1024,
  sizeof (char), (int (*)(struct XDR *, void *, ...)) xdr_char))
   return (0);
  if (!xdr_vector (xdrs, (char *)objp->str2, 1024,
  sizeof (char), (int (*)(struct XDR *, void *, ...)) xdr_char))
   return (0);
 return (1);
}

variable_types: struct hls { char str1[1024]; char str2[1024]; } *


decompiled_code:
_BOOL8 __fastcall xdr_half_long_string(XDR *a1, char *a2)
{
return xdr_hls(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(XDR *a1, char *a2)
{
return func12(a1, a2) != 0;
}

original_code:
bool_t
xdr_half_long_string (XDR *xdrs, half_long_string *objp)
{
 register int32_t *buf;
  if (!xdr_hls (xdrs, objp))
   return (0);
 return (1);
}

canonical_original_code:
int xdr_half_long_string(struct XDR *xdrs, struct hls *objp)
{
 register int *buf;
  if (!xdr_hls (xdrs, objp))
   return (0);
 return (1);
}

user_defined_types: struct hls { char str1[1024]; char str2[1024]; }


decompiled_code:
_BOOL8 __fastcall xdr_long_string(__int64 a1, __int64 a2)
{
return (unsigned int)xdr_ls(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1, __int64 a2)
{
return (unsigned int)func11(a1, a2) != 0;
}


decompiled_code:
_BOOL8 __fastcall xdr_half_long_string(__int64 a1, __int64 a2)
{
return (unsigned int)xdr_hls(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1, __int64 a2)
{
return (unsigned int)func12(a1, a2) != 0;
}


canonical_decompiled_code:
_BOOL8 __fastcall func11(XDR *a1, char *a2)
{
return xdr_vector(a1, a2, 0x800u, 1u, (xdrproc_t)xdr_char) != 0;
}


decompiled_code:
_BOOL8 __fastcall xdr_hls(XDR *a1, char *a2)
{
_BOOL8 result; // rax

if ( xdr_vector(a1, a2, 0x400u, 1u, (xdrproc_t)xdr_char) )
result = xdr_vector(a1, a2 + 1024, 0x400u, 1u, (xdrproc_t)xdr_char) != 0;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(XDR *a1, char *a2)
{
_BOOL8 result; // rax

if ( xdr_vector(a1, a2, 0x400u, 1u, (xdrproc_t)xdr_char) )
result = xdr_vector(a1, a2 + 1024, 0x400u, 1u, (xdrproc_t)xdr_char) != 0;
else
result = 0LL;
return result;
}


decompiled_code:
void __fastcall pc_decode_construction_step(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, _QWORD *a7)
{
__int64 v10; // r15
double *v11; // rbp

v10 = a6;
v11 = (double *)malloc(8LL * (1 << (a4 - a5)));
pc_decode_calc_f(v11, v10, a5, a4);
if ( a4 == a5 )
{
pc_decode_construction_update_Z(a1, a2, a7, *v11);
pc_decode_calc_g(v11, a6, a5, a4, a3, *a7);
pc_decode_construction_update_Z(a1, a2, a7, *v11);
}
else
{
pc_decode_construction_step(a1, a2, a3, a4, a5 + 1, (_DWORD)v11, (__int64)a7);
pc_decode_calc_g(v11, a6, a5, a4, a3, *a7);
pc_decode_construction_step(a1, a2, a3, a4, a5 + 1, (_DWORD)v11, (__int64)a7);
}
free(v11);
}

original_code:
void pc_decode_construction_step(double *Z, double *Zvar, Bit *u, u_int64_t n, u_int64_t step, double *val, u_int64_t *uindex){
    u_int64_t D = 1 << (n-step);
    double *new_val = malloc(D*sizeof(double));
    pc_decode_calc_f(new_val, val, step, n);
    if(step == n){
        pc_decode_construction_update_Z(Z, Zvar, new_val[0], uindex);
    }else{
        pc_decode_construction_step(Z, Zvar, u, n, step+1, new_val, uindex);
    }
    pc_decode_calc_g(new_val, val, step, n, u, *uindex);
    if(step == n){
        pc_decode_construction_update_Z(Z, Zvar, new_val[0], uindex);
    }else{
        pc_decode_construction_step(Z, Zvar, u, n, step+1, new_val, uindex);
    }
    free(new_val);
}

canonical_original_code:
void pc_decode_construction_step(double *Z, double *Zvar, unsigned int *u, unsigned int n, unsigned int step, double *val, unsigned int *uindex){
    unsigned int D = 1 << (n-step);
    double *new_val = malloc(D*sizeof(double));
    pc_decode_calc_f(new_val, val, step, n);
    if(step == n){
        pc_decode_construction_update_Z(Z, Zvar, new_val[0], uindex);
    }else{
        pc_decode_construction_step(Z, Zvar, u, n, step+1, new_val, uindex);
    }
    pc_decode_calc_g(new_val, val, step, n, u, *uindex);
    if(step == n){
        pc_decode_construction_update_Z(Z, Zvar, new_val[0], uindex);
    }else{
        pc_decode_construction_step(Z, Zvar, u, n, step+1, new_val, uindex);
    }
    free(new_val);
}

variable_types:
Z
double *

variable_types:
Zvar
double *

variable_types:
u
unsigned int *

variable_types:
n
unsigned int

variable_types:
step
unsigned int

variable_types:
val
double *

variable_types:
uindex
unsigned int *

variable_types:
D
unsigned int


original_code:
void pc_decode_construction(double *Z, double *Zvar, Bit *y, const Channel *channel, Bit *u, u_int64_t n) {
    u_int64_t N = 1 << n;
    u_int64_t uindex = 0;
    double *delta = malloc(N*sizeof(double));
    u_int64_t i;
    for(i = 0; i < N; i++){
        u_int64_t i2 = bit_reverse_index(i, n);
        double n_,d_,v;
        n_ = channel_probability(channel, y[i2], 0);
        d_ = channel_probability(channel, y[i2], 1);
        if(d_ == 0){
            v = ((double)(1 << 30));
        }else{
            v = n_/d_;
            if(v < (1.0 / (double)(1 << 30))){
                v = (1.0 / (double)(1 << 30));
            }else if(v > ((double)(1 << 30))){
                v = ((double)(1 << 30));
            }
        }
        delta[i] = v;
    }
    pc_decode_construction_step(Z, Zvar, u, n, 1, delta, &uindex);
    free(delta);
}

canonical_original_code:
void pc_decode_construction(double *Z, double *Zvar, unsigned int *y, struct Channel *channel, unsigned int *u, unsigned int n) {
    unsigned int N = 1 << n;
    unsigned int uindex = 0;
    double *delta = malloc(N*sizeof(double));
    unsigned int i;
    for(i = 0; i < N; i++){
        unsigned int i2 = bit_reverse_index(i, n);
        double n_; double d_; double v;
        n_ = channel_probability(channel, y[i2], 0);
        d_ = channel_probability(channel, y[i2], 1);
        if(d_ == 0){
            v = ((double)(1 << 30));
        }else{
            v = n_/d_;
            if(v < (1.0 / (double)(1 << 30))){
                v = (1.0 / (double)(1 << 30));
            }else if(v > ((double)(1 << 30))){
                v = ((double)(1 << 30));
            }
        }
        delta[i] = v;
    }
    pc_decode_construction_step(Z, Zvar, u, n, 1, delta, &uindex);
    free(delta);
}

variable_types:
y
unsigned int *

variable_types: struct Channel { enum ChannelType { ChannelType_BSC=1, ChannelType_BEC=2 } channel_type; double par; } *

variable_types:
N
unsigned int

variable_types:
uindex
unsigned int

variable_types:
delta
double *

variable_types:
i
unsigned int

variable_types: v double

user_defined_types: struct Channel { enum ChannelType channel_type; double par; }


decompiled_code:
void __fastcall pc_construction(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
size_t v8; // rbx
void *v9; // rbp
void *v10; // rbx
__int64 v11; // r13
size_t v12; // [rsp+8h] [rbp-50h]

v8 = 1 << a3;
v12 = v8;
v9 = malloc(v8);
v10 = malloc(v8);
if ( a5 )
{
v11 = 0LL;
do
{
random_bits(v9, v12);
pc_encode(v10, v9, a3);
apply_channel(v10, v10, a4, a3);
pc_decode_construction(a1, a2, (__int64)v10, a4, (__int64)v9, a3);
++v11;
}
while ( a5 != v11 );
}
free(v9);
free(v10);
}

original_code:
void pc_construction(double *Z, double *Zvar, u_int64_t n, const Channel *channel, u_int64_t n_samples) {
    u_int64_t N = 1 << n;
    u_int64_t i;
    Bit *u = malloc(N*sizeof(Bit));
    Bit *x = malloc(N*sizeof(Bit));
    for(i = 0; i < n_samples; i++){
        random_bits(u, N);
        pc_encode(x, u, n);
        Bit *y = x;
        apply_channel(y, x, channel, n);
        pc_decode_construction(Z, Zvar, y, channel, u, n);
    }
    free(u);
    free(x);
}

canonical_original_code:
void pc_construction(double *Z, double *Zvar, unsigned int n, struct Channel *channel, unsigned int n_samples) {
    unsigned int N = 1 << n;
    unsigned int i;
    unsigned int *u = malloc(N*sizeof(Bit));
    unsigned int *x = malloc(N*sizeof(Bit));
    for(i = 0; i < n_samples; i++){
        random_bits(u, N);
        pc_encode(x, u, n);
        unsigned int *y = x;
        apply_channel(y, x, channel, n);
        pc_decode_construction(Z, Zvar, y, channel, u, n);
    }
    free(u);
    free(x);
}

variable_types:
x
unsigned int *

user_defined_types: enum ChannelType { ChannelType_BSC=1, ChannelType_BEC=2 }


decompiled_code:
void __fastcall random_bits(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbx

if ( a2 )
{
v2 = a1;
do
*v2++ = rand() & 1;
while ( v2 != &a1[a2] );
}
}

canonical_decompiled_code:
void __fastcall func0(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbx

if ( a2 )
{
v2 = a1;
do
*v2++ = rand() & 1;
while ( v2 != &a1[a2] );
}
}

original_code:
void random_bits(Bit *bits, u_int64_t N) {
    u_int64_t i;
    for(i=0; i<N; i++){
        bits[i] = rand() & 1;
    }
}

canonical_original_code:
void random_bits(unsigned int *bits, unsigned int N) {
    unsigned int i;
    for(i=0; i<N; i++){
        bits[i] = rand() & 1;
    }
}

variable_types:
bits
unsigned int *


original_code:
void random_bits_f(Bit *bits, Bit *A, u_int64_t N) {
    u_int64_t i;
    for(i=0; i<N; i++){
        if(A[i] == 0)
            bits[i] = 0;
        else
            bits[i] = rand() & 1;
    }
}

canonical_original_code:
void random_bits_f(unsigned int *bits, unsigned int *A, unsigned int N) {
    unsigned int i;
    for(i=0; i<N; i++){
        if(A[i] == 0)
            bits[i] = 0;
        else
            bits[i] = rand() & 1;
    }
}

variable_types:
A
unsigned int *


decompiled_code:
int __fastcall print_bits(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbx

if ( a2 )
{
v2 = a1;
do
{
if ( *v2 )
{
if ( *v2 == 1 )
putchar(49);
else
putchar(63);
}
else
{
putchar(48);
}
putchar(32);
++v2;
}
while ( v2 != &a1[a2] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbx

if ( a2 )
{
v2 = a1;
do
{
if ( *v2 )
{
if ( *v2 == 1 )
putchar(49);
else
putchar(63);
}
else
{
putchar(48);
}
putchar(32);
++v2;
}
while ( v2 != &a1[a2] );
}
return putchar(10);
}

original_code:
void print_bits(Bit *bits, u_int64_t N) {
    u_int64_t i;
    for(i=0; i<N; printf(" "), i++){
        if(bits[i] == 0)
            printf("0");
        else if(bits[i] == 1)
            printf("1");
        else
            printf("?");
    }
    printf("\n");
}

canonical_original_code:
void print_bits(unsigned int *bits, unsigned int N) {
    unsigned int i;
    for(i=0; i<N; printf(" "), i++){
        if(bits[i] == 0)
            printf("0");
        else if(bits[i] == 1)
            printf("1");
        else
            printf("?");
    }
    printf("\n");
}


decompiled_code:
int __fastcall print_doubles(__int64 a1, __int64 a2)
{
__int64 i; // rbx

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
printf("%f", *(double *)(a1 + 8 * i));
putchar(32);
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2)
{
__int64 i; // rbx

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
printf("%f", *(double *)(a1 + 8 * i));
putchar(32);
}
}
return putchar(10);
}

original_code:
void print_doubles(double *doubles, u_int64_t N) {
    u_int64_t i;
    for(i=0; i<N; printf(" "), i++){
        printf("%f", doubles[i]);
    }
    printf("\n");
}

canonical_original_code:
void print_doubles(double *doubles, unsigned int N) {
    unsigned int i;
    for(i=0; i<N; printf(" "), i++){
        printf("%f", doubles[i]);
    }
    printf("\n");
}

variable_types:
doubles
double *


decompiled_code:
__int64 __fastcall bit_reverse_index(unsigned __int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rdx

v3 = a2;
if ( a2 )
{
v4 = 0LL;
a2 = 0LL;
do
{
a2 |= ((a1 >> v4) & 1) << ((unsigned __int8)v3 - 1 - (unsigned __int8)v4);
++v4;
}
while ( v3 != v4 );
}
return a2;
}

original_code:
u_int64_t bit_reverse_index(u_int64_t index, u_int64_t n) {
    u_int64_t index2 = 0;
    u_int64_t i;
    for(i=0; i < n; i++){
        index2 |= ((index >> i) & 1) << (n-i-1);
    }
    return index2;
}

canonical_original_code:
unsigned int bit_reverse_index(unsigned int index, unsigned int n) {
    unsigned int index2 = 0;
    unsigned int i;
    for(i=0; i < n; i++){
        index2 |= ((index >> i) & 1) << (n-i-1);
    }
    return index2;
}

variable_types:
index
unsigned int