decompiled_code:
void __fastcall __noreturn daemon_root_threadproc(void *a1)
{
unsigned int v1; // ebx
pthread_t v2; // rax
const char *v3; // rdi
__int64 v4; // rax
bool v5; // cf
bool v6; // zf
const char *v7; // rsi
__int64 v8; // rcx
int v9; // eax
unsigned int v10; // ebp
const char *v11; // rax
unsigned int v12; // eax
int v13; // er12
char *v14; // r13
const char *v15; // rdi
int v16; // eax
const char *v17; // rax
const char *v18; // rbp
char *v19; // rax
char v20[2088]; // [rsp+0h] [rbp-828h] BYREF

v1 = (unsigned int)a1;
signal(13, handler);
v2 = pthread_self();
pthread_detach(v2);
v3 = (const char *)cfg;
v4 = hashtable_lookup(cfg, "http-analyzer");
v5 = 0;
v6 = v4 == 0;
if ( !v4 )
goto LABEL_6;
v7 = (const char *)v4;
v3 = "on";
v8 = 3LL;
do
{
if ( !v8 )
break;
v5 = *v7 < (unsigned int)*v3;
v6 = *v7++ == *v3++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
v12 = proxy_get_iotimeout(v3, v7);
v13 = async_read(v1, v20, 2048LL, v12);
if ( v13 < 0 )
{
close(v1);
pthread_exit(0LL);
}
v14 = (char *)http_get_url(v20);
if ( !v14 )
{
lprintf("[http/error] bad/corrupted http chunk:\n\n%s\n", v20);
close(v1);
pthread_exit(0LL);
}
v15 = (const char *)hashtable_lookup(cfg, "http-admin-mode");
if ( v15 )
{
if ( !strcmp(v15, "on") )
{
v18 = (const char *)hashtable_lookup(cfg, "http-admin-url");
if ( !strcmp(v14, v18) || (v15 = v14, strstr(v14, v18)) )
{
v19 = rindex(v14, 47);
httpd_handler(v1, v19, v20);
free(v14);
close(v1);
pthread_exit(0LL);
}
}
}
v16 = proxy_getrandproxy(v15);
v10 = v16;
if ( v16 < 0 )
{
httpd_www_noproxies_msg(v1);
free(v14);
close(v1);
pthread_exit(0LL);
}
v17 = (const char *)net_getpeeraddr((unsigned int)v16);
lprintf("[proxy/notice] %s <--> %s\n", v14, v17);
free(v14);
async_duplex_bridge(v1, v10, daemon_to_client, daemon_to_proxy, v20, (unsigned int)v13);
}
else
{
LABEL_6:
v9 = proxy_getrandproxy(v3);
v10 = v9;
if ( v9 < 0 )
{
httpd_www_noproxies_msg(v1);
close(v1);
pthread_exit(0LL);
}
v11 = (const char *)net_getpeeraddr((unsigned int)v9);
lprintf("[proxy/notice] Surfing through %s\n", v11);
async_duplex_bridge(v1, v10, 0LL, 0LL, 0LL, 0xFFFFFFFFLL);
}
close(v1);
close(v10);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(void *a1)
{
unsigned int v1; // ebx
pthread_t v2; // rax
const char *v3; // rdi
__int64 v4; // rax
bool v5; // cf
bool v6; // zf
const char *v7; // rsi
__int64 v8; // rcx
int v9; // eax
unsigned int v10; // ebp
const char *v11; // rax
unsigned int v12; // eax
int v13; // er12
char *v14; // r13
const char *v15; // rdi
int v16; // eax
const char *v17; // rax
const char *v18; // rbp
char *v19; // rax
char v20[2088]; // [rsp+0h] [rbp-828h] BYREF

v1 = (unsigned int)a1;
signal(13, handler);
v2 = pthread_self();
pthread_detach(v2);
v3 = (const char *)cfg;
v4 = hashtable_lookup(cfg, "http-analyzer");
v5 = 0;
v6 = v4 == 0;
if ( !v4 )
goto LABEL_6;
v7 = (const char *)v4;
v3 = "on";
v8 = 3LL;
do
{
if ( !v8 )
break;
v5 = *v7 < (unsigned int)*v3;
v6 = *v7++ == *v3++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
v12 = proxy_get_iotimeout(v3, v7);
v13 = async_read(v1, v20, 2048LL, v12);
if ( v13 < 0 )
{
close(v1);
pthread_exit(0LL);
}
v14 = (char *)http_get_url(v20);
if ( !v14 )
{
lprintf("[http/error] bad/corrupted http chunk:\n\n%s\n", v20);
close(v1);
pthread_exit(0LL);
}
v15 = (const char *)hashtable_lookup(cfg, "http-admin-mode");
if ( v15 )
{
if ( !strcmp(v15, "on") )
{
v18 = (const char *)hashtable_lookup(cfg, "http-admin-url");
if ( !strcmp(v14, v18) || (v15 = v14, strstr(v14, v18)) )
{
v19 = rindex(v14, 47);
httpd_handler(v1, v19, v20);
free(v14);
close(v1);
pthread_exit(0LL);
}
}
}
v16 = proxy_getrandproxy(v15);
v10 = v16;
if ( v16 < 0 )
{
httpd_www_noproxies_msg(v1);
free(v14);
close(v1);
pthread_exit(0LL);
}
v17 = (const char *)net_getpeeraddr((unsigned int)v16);
lprintf("[proxy/notice] %s <--> %s\n", v14, v17);
free(v14);
async_duplex_bridge(v1, v10, daemon_to_client, daemon_to_proxy, v20, (unsigned int)v13);
}
else
{
LABEL_6:
v9 = proxy_getrandproxy(v3);
v10 = v9;
if ( v9 < 0 )
{
httpd_www_noproxies_msg(v1);
close(v1);
pthread_exit(0LL);
}
v11 = (const char *)net_getpeeraddr((unsigned int)v9);
lprintf("[proxy/notice] Surfing through %s\n", v11);
async_duplex_bridge(v1, v10, 0LL, 0LL, 0LL, 0xFFFFFFFFLL);
}
close(v1);
close(v10);
pthread_exit(0LL);
}

original_code:
void *daemon_root_threadproc(void *args) {
 int fd, proxy_fd, rval;
 char virgin_chunk[2048], *retval, *url, *v_url;
 signal(13, ((__sighandler_t) 1));
 pthread_detach(pthread_self());
 fd = (int) args;
 retval = hashtable_lookup(cfg, "http-analyzer");
 if (retval && !strcmp(retval, "on")) {
  rval = async_read(fd, virgin_chunk, sizeof(virgin_chunk), proxy_get_iotimeout());
  if (rval < 0){
   close(fd);
   pthread_exit(((void *)0));
  }
  url = http_get_url(virgin_chunk);
  if (!url) {
   lprintf("[http/error] bad/corrupted http chunk:\n\n%s\n", virgin_chunk);
   close(fd);
   pthread_exit(((void *)0));
  }
  retval = hashtable_lookup(cfg, "http-admin-mode");
  if (retval && !strcmp(retval, "on")) {
   v_url = hashtable_lookup(cfg, "http-admin-url");
   if (!strcmp(url, v_url) || strstr(url, v_url)) {
    httpd_handler(fd, rindex(url, '/'), virgin_chunk);
    free(url);
    close(fd);
    pthread_exit(((void *)0));
   }
  }
  proxy_fd = proxy_getrandproxy();
  if (proxy_fd < 0) {
   httpd_www_noproxies_msg(fd);
   free(url);
   close(fd);
   pthread_exit(((void *)0));
  }
  lprintf("[proxy/notice] %s <--> %s\n", url, net_getpeeraddr(proxy_fd));
  free(url);
  async_duplex_bridge(fd, proxy_fd, daemon_to_client, daemon_to_proxy, virgin_chunk, rval);
 } else {
  proxy_fd = proxy_getrandproxy();
  if (proxy_fd < 0) {
   httpd_www_noproxies_msg(fd);
   close(fd);
   pthread_exit(((void *)0));
  }
  lprintf("[proxy/notice] Surfing through %s\n", net_getpeeraddr(proxy_fd));
  async_duplex_bridge(fd, proxy_fd, ((void *)0), ((void *)0), ((void *)0), -1);
 }
        close(fd);
        close(proxy_fd);
 pthread_exit(((void *)0));
}

canonical_original_code:
void *daemon_root_threadproc(void *args) {
 int fd; int proxy_fd; int rval;
 char virgin_chunk[2048]; char *retval; char *url; char *v_url;
 signal(13, ((void (*)(int)) 1));
 pthread_detach(pthread_self());
 fd = (int) args;
 retval = hashtable_lookup(cfg, "http-analyzer");
 if (retval && !strcmp(retval, "on")) {
  rval = async_read(fd, virgin_chunk, sizeof(virgin_chunk), proxy_get_iotimeout());
  if (rval < 0){
   close(fd);
   pthread_exit(((void *)0));
  }
  url = http_get_url(virgin_chunk);
  if (!url) {
   lprintf("[http/error] bad/corrupted http chunk:\n\n%s\n", virgin_chunk);
   close(fd);
   pthread_exit(((void *)0));
  }
  retval = hashtable_lookup(cfg, "http-admin-mode");
  if (retval && !strcmp(retval, "on")) {
   v_url = hashtable_lookup(cfg, "http-admin-url");
   if (!strcmp(url, v_url) || strstr(url, v_url)) {
    httpd_handler(fd, rindex(url, '/'), virgin_chunk);
    free(url);
    close(fd);
    pthread_exit(((void *)0));
   }
  }
  proxy_fd = proxy_getrandproxy();
  if (proxy_fd < 0) {
   httpd_www_noproxies_msg(fd);
   free(url);
   close(fd);
   pthread_exit(((void *)0));
  }
  lprintf("[proxy/notice] %s <--> %s\n", url, net_getpeeraddr(proxy_fd));
  free(url);
  async_duplex_bridge(fd, proxy_fd, daemon_to_client, daemon_to_proxy, virgin_chunk, rval);
 } else {
  proxy_fd = proxy_getrandproxy();
  if (proxy_fd < 0) {
   httpd_www_noproxies_msg(fd);
   close(fd);
   pthread_exit(((void *)0));
  }
  lprintf("[proxy/notice] Surfing through %s\n", net_getpeeraddr(proxy_fd));
  async_duplex_bridge(fd, proxy_fd, ((void *)0), ((void *)0), ((void *)0), -1);
 }
        close(fd);
        close(proxy_fd);
 pthread_exit(((void *)0));
}

variable_types:
args
void *

variable_types: fd int

variable_types: rval int

variable_types:
retval
char *


decompiled_code:
__int64 daemon_start()
{
__int64 v0; // rbx
__int64 v1; // rax
int v2; // ebp
__int64 result; // rax
int v4; // eax
int v5; // ebx
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

signal(13, handler);
v0 = hashtable_lookup(cfg, "net-bindport");
v1 = hashtable_lookup(cfg, "net-bindip");
v2 = net_mastersocket(v1, v0);
result = daemon_writepid();
if ( (_DWORD)result && v2 > 0 )
{
while ( 1 )
{
v4 = net_acceptsocket((unsigned int)v2);
v5 = v4;
if ( v4 < 0 )
{
lerror("accept");
}
else if ( (int)net_setononblock((unsigned int)v4) < 0 )
{
lerror("fcntl");
close(v5);
}
else if ( pthread_create(newthread, 0LL, (void *(*)(void *))daemon_root_threadproc, (void *)v5) < 0 )
{
lerror("pthread_create");
close(v5);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx
__int64 v1; // rax
int v2; // ebp
__int64 result; // rax
int v4; // eax
int v5; // ebx
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

signal(13, handler);
v0 = hashtable_lookup(cfg, "net-bindport");
v1 = hashtable_lookup(cfg, "net-bindip");
v2 = net_mastersocket(v1, v0);
result = func3();
if ( (_DWORD)result && v2 > 0 )
{
while ( 1 )
{
v4 = net_acceptsocket((unsigned int)v2);
v5 = v4;
if ( v4 < 0 )
{
lerror("accept");
}
else if ( (int)net_setononblock((unsigned int)v4) < 0 )
{
lerror("fcntl");
close(v5);
}
else if ( pthread_create(newthread, 0LL, (void *(*)(void *))daemon_root_threadproc, (void *)v5) < 0 )
{
lerror("pthread_create");
close(v5);
}
}
}
return result;
}

original_code:
void daemon_start(void) {
 int srv_fd, new_fd;
 pthread_t thread;
 signal(13, ((__sighandler_t) 1));
 srv_fd = net_mastersocket(hashtable_lookup(cfg, "net-bindip"), hashtable_lookup(cfg, "net-bindport"));
 if (!daemon_writepid()) {
  return ;
 }
 while (srv_fd > 0) {
  new_fd = net_acceptsocket(srv_fd);
  if (new_fd < 0) {
   lerror("accept");
   continue;
  }
  if (net_setononblock(new_fd) < 0) {
   lerror("fcntl");
   close(new_fd);
   continue;
  }
  if (pthread_create(&thread, ((void *)0), daemon_root_threadproc, (int *)new_fd) < 0) {
   lerror("pthread_create");
   close(new_fd);
  }
 }
 return ;
}

canonical_original_code:
void daemon_start() {
 int srv_fd; int new_fd;
 unsigned long thread;
 signal(13, ((void (*)(int)) 1));
 srv_fd = net_mastersocket(hashtable_lookup(cfg, "net-bindip"), hashtable_lookup(cfg, "net-bindport"));
 if (!daemon_writepid()) {
  return ;
 }
 while (srv_fd > 0) {
  new_fd = net_acceptsocket(srv_fd);
  if (new_fd < 0) {
   lerror("accept");
   continue;
  }
  if (net_setononblock(new_fd) < 0) {
   lerror("fcntl");
   close(new_fd);
   continue;
  }
  if (pthread_create(&thread, ((void *)0), daemon_root_threadproc, (int *)new_fd) < 0) {
   lerror("pthread_create");
   close(new_fd);
  }
 }
 return ;
}

variable_types:
thread
unsigned long

return_type: void


decompiled_code:
int __fastcall procfs_pexename(unsigned int a1)
{
int *v2; // rax
char *v3; // rax
char v4[1024]; // [rsp+0h] [rbp-508h] BYREF
char s[264]; // [rsp+400h] [rbp-108h] BYREF

snprintf(s, 0x100uLL, "/proc/%d/exe", a1);
if ( readlink(s, v4, 0x400uLL) >= 0 )
return printf("* Executable: %s\n", v4);
v2 = _errno_location();
v3 = strerror(*v2);
return fprintf(stderr, "*** %s: %s\n", s, v3);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
int *v2; // rax
char *v3; // rax
char v4[1024]; // [rsp+0h] [rbp-508h] BYREF
char s[264]; // [rsp+400h] [rbp-108h] BYREF

snprintf(s, 0x100uLL, "/proc/%d/exe", a1);
if ( readlink(s, v4, 0x400uLL) >= 0 )
return printf("* Executable: %s\n", v4);
v2 = _errno_location();
v3 = strerror(*v2);
return fprintf(stderr, "*** %s: %s\n", s, v3);
}

original_code:
void procfs_pexename(int pid) {
 char path[256], buf[1024];
 snprintf(path, sizeof(path), "/proc/%d/exe", pid);
 if (readlink(path, buf, sizeof(buf)) < 0) {
  fprintf(stderr, "*** %s: %s\n", path, strerror((*__errno_location ())));
  return ;
 }
 printf("* Executable: %s\n", buf);
 return ;
}

canonical_original_code:
void procfs_pexename(int pid) {
 char path[256]; char buf[1024];
 snprintf(path, sizeof(path), "/proc/%d/exe", pid);
 if (readlink(path, buf, sizeof(buf)) < 0) {
  fprintf(stderr, "*** %s: %s\n", path, strerror((*__errno_location ())));
  return ;
 }
 printf("* Executable: %s\n", buf);
 return ;
}

variable_types: pid int

variable_types:
path
char [256]

variable_types:
buf
char [1024]


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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void shbuf_free(shbuf *buf) {
 if (buf) {
  if (buf->buf) {
   free(buf->buf);
  }
  free(buf);
 }
 return ;
}

canonical_original_code:
void shbuf_free(struct shbuf *buf) {
 if (buf) {
  if (buf->buf) {
   free(buf->buf);
  }
  free(buf);
 }
 return ;
}

variable_types: struct shbuf { char *buf; int index; } *


decompiled_code:
__int64 __fastcall shbuf_append(__int64 *a1, const void *a2, int a3)
{
__int64 v5; // rdi
__int64 result; // rax

if ( !a1 )
return 0LL;
v5 = *a1;
result = 0LL;
if ( v5 )
{
memcpy((void *)(*((int *)a1 + 2) + v5), a2, a3);
result = (unsigned int)(*((_DWORD *)a1 + 2) + a3);
*((_DWORD *)a1 + 2) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, const void *a2, int a3)
{
__int64 v5; // rdi
__int64 result; // rax

if ( !a1 )
return 0LL;
v5 = *a1;
result = 0LL;
if ( v5 )
{
memcpy((void *)(*((int *)a1 + 2) + v5), a2, a3);
result = (unsigned int)(*((_DWORD *)a1 + 2) + a3);
*((_DWORD *)a1 + 2) = result;
}
return result;
}

original_code:
int shbuf_append(shbuf *buf, char *data, int len) {
 char *ptr;
 if (!buf || !buf->buf) {
  return 0;
 }
 ptr = (char *)&buf->buf[buf->index];
 memcpy(ptr, data, len);
 buf->index += len;
 return buf->index;
}

canonical_original_code:
int shbuf_append(struct shbuf *buf, char *data, int len) {
 char *ptr;
 if (!buf || !buf->buf) {
  return 0;
 }
 ptr = (char *)&buf->buf[buf->index];
 memcpy(ptr, data, len);
 buf->index += len;
 return buf->index;
}

variable_types:
data
char *

variable_types: len int

variable_types:
ptr
char *

return_type: int


decompiled_code:
int __fastcall gfx_hr(int a1)
{
int i; // ebx

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
fputc(45, stdout);
}
return fputc(10, stdout);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int i; // ebx

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
fputc(45, stdout);
}
return fputc(10, stdout);
}

original_code:
void gfx_hr(int len) {
 int j;
 for (j = 0; j < len; j++) {
  fputc('-', stdout);
 }
 fputc('\n', stdout);
 return ;
}

variable_types: j int


help

repo: ilanschnell/filebin

decompiled_code:
int help()
{
return puts(
"\n"
"Calculates the frequency of bytes of file(s) or stdin.\n"
"Options:\n"
" -f display full table (including zero counts, implies -t)\n"
" -n show names when displaying table (implies -t)\n"
" -t show table\n"
" -h display this help and exit\n"
" -v display version number and exit");
}

canonical_decompiled_code:
int func7()
{
return puts(
"\n"
"Calculates the frequency of bytes of file(s) or stdin.\n"
"Options:\n"
" -f display full table (including zero counts, implies -t)\n"
" -n show names when displaying table (implies -t)\n"
" -t show table\n"
" -h display this help and exit\n"
" -v display version number and exit");
}

original_code:
void help(void)
{
    printf("\nCalculates the frequency of bytes of file(s) or stdin.\nOptions:\n  -f   display full table (including zero counts, implies -t)\n  -n   show names when displaying table (implies -t)\n  -t   show table\n  -h   display this help and exit\n  -v   display version number and exit\n");
}

canonical_original_code:
void help()
{
    printf("\nCalculates the frequency of bytes of file(s) or stdin.\nOptions:\n  -f   display full table (including zero counts, implies -t)\n  -n   show names when displaying table (implies -t)\n  -t   show table\n  -h   display this help and exit\n  -v   display version number and exit\n");
}


decompiled_code:
int __fastcall process_options(int argc, char **argv)
{
int result; // eax

full = 0;
names = 0;
table = 0;
while ( 1 )
{
result = getopt(argc, argv, "nfthv");
if ( result == -1 )
break;
switch ( result )
{
case 'f':
table = 1;
full = 1;
break;
case 'h':
printf("usage: %s [-fnthv] [file] ...\n", *argv);
help();
exit(0);
case 'n':
table = 1;
names = 1;
break;
case 't':
table = 1;
break;
case 'v':
puts("filebin 1.0.3");
exit(0);
default:
printf("usage: %s [-fnthv] [file] ...\n", *argv);
exit(1);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int argc, char **argv)
{
int result; // eax

full = 0;
names = 0;
table = 0;
while ( 1 )
{
result = getopt(argc, argv, "nfthv");
if ( result == -1 )
break;
switch ( result )
{
case 'f':
table = 1;
full = 1;
break;
case 'h':
printf("usage: %s [-fnthv] [file] ...\n", *argv);
func7();
exit(0);
case 'n':
table = 1;
names = 1;
break;
case 't':
table = 1;
break;
case 'v':
puts("filebin 1.0.3");
exit(0);
default:
printf("usage: %s [-fnthv] [file] ...\n", *argv);
exit(1);
}
}
return result;
}

original_code:
void process_options(int argc, char *argv[])
{
    int op;
    table = names = full = 0;
    while ((op = getopt(argc, argv, "nfthv")) != -1)
        switch(op) {
        case 'h':
            printf("usage: %s [-fnthv] [file] ...\n", argv[0]);
            help();
            exit(0);
        case 'f':
            full = table = 1;
            break;
        case 'n':
            names = table = 1;
            break;
        case 't':
            table = 1;
            break;
        case 'v':
            printf("filebin " "1.0.3" "\n");
            exit(0);
        default:
            printf("usage: %s [-fnthv] [file] ...\n", argv[0]);
            exit(1);
        }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: op int


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

if ( a2 > 32 )
{
if ( a2 == 127 )
{
strcpy(a1, "<Del>");
return result;
}
LABEL_12:
result = (unsigned int)(a2 - 33);
if ( (unsigned int)result <= 0x5D )
{
*a1 = a2;
a1[1] = 0;
return result;
}
goto LABEL_14;
}
if ( a2 < 0 )
{
LABEL_14:
*(_WORD *)a1 = 46;
return result;
}
result = (unsigned int)a2;
switch ( a2 )
{
case 0:
strcpy(a1, "<NUL>");
break;
case 9:
strcpy(a1, "<Tab>");
break;
case 10:
strcpy(a1, "<LF>");
break;
case 11:
strcpy(a1, "<VTab>");
break;
case 13:
strcpy(a1, "<CR>");
break;
case 32:
result = 0x3E65636170533CLL;
*(_QWORD *)a1 = 0x3E65636170533CLL;
break;
default:
goto LABEL_12;
}
return result;
}

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

if ( a2 > 32 )
{
if ( a2 == 127 )
{
strcpy(a1, "<Del>");
return result;
}
LABEL_12:
result = (unsigned int)(a2 - 33);
if ( (unsigned int)result <= 0x5D )
{
*a1 = a2;
a1[1] = 0;
return result;
}
goto LABEL_14;
}
if ( a2 < 0 )
{
LABEL_14:
*(_WORD *)a1 = 46;
return result;
}
result = (unsigned int)a2;
switch ( a2 )
{
case 0:
strcpy(a1, "<NUL>");
break;
case 9:
strcpy(a1, "<Tab>");
break;
case 10:
strcpy(a1, "<LF>");
break;
case 11:
strcpy(a1, "<VTab>");
break;
case 13:
strcpy(a1, "<CR>");
break;
case 32:
result = 0x3E65636170533CLL;
*(_QWORD *)a1 = 0x3E65636170533CLL;
break;
default:
goto LABEL_12;
}
return result;
}

original_code:
void char_name(char *buff, int c)
{
    switch (c) {
        case '\0': strcpy(buff, "<" "NUL" ">"); break;
        case '\t': strcpy(buff, "<" "Tab" ">"); break;
        case '\n': strcpy(buff, "<" "LF" ">"); break;
        case '\v': strcpy(buff, "<" "VTab" ">"); break;
        case '\r': strcpy(buff, "<" "CR" ">"); break;
        case ' ': strcpy(buff, "<" "Space" ">"); break;
        case 127: strcpy(buff, "<" "Del" ">"); break;
    default:
        if (c >= 33 && c <= 126) {
            buff[0] = (char) c;
            buff[1] = '\0';
        }
        else
            strcpy(buff, ".");
    }
}

variable_types:
buff
char *

variable_types: c int


decompiled_code:
int show_table()
{
__int64 i; // rbx
int result; // eax
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

if ( names )
result = puts("Char Count\n------------------------");
for ( i = 0LL; i != 256; ++i )
{
if ( full || bin[i] )
{
if ( names )
{
char_name(v2, i);
result = printf("%4d %8s %10lld\n", (unsigned int)i, v2, bin[i]);
}
else
{
result = printf("%4d %10lld\n", (unsigned int)i, bin[i]);
}
}
}
return result;
}

canonical_decompiled_code:
int func12()
{
__int64 i; // rbx
int result; // eax
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

if ( names )
result = puts("Char Count\n------------------------");
for ( i = 0LL; i != 256; ++i )
{
if ( full || bin[i] )
{
if ( names )
{
func11(v2, i);
result = printf("%4d %8s %10lld\n", (unsigned int)i, v2, bin[i]);
}
else
{
result = printf("%4d %10lld\n", (unsigned int)i, bin[i]);
}
}
}
return result;
}

original_code:
void show_table(void)
{
    char buff[16];
    int c;
    if (names)
        printf("Char               Count\n"
               "------------------------\n");
    for (c = 0; c < 256; c++)
        if (full || bin[c]) {
            if (names) {
                char_name(buff, c);
                printf("%4d %8s %10lld\n", c, buff, bin[c]);
            }
            else
                printf("%4d %10lld\n", c, bin[c]);
        }
}

canonical_original_code:
void show_table()
{
    char buff[16];
    int c;
    if (names)
        printf("Char               Count\n"
               "------------------------\n");
    for (c = 0; c < 256; c++)
        if (full || bin[c]) {
            if (names) {
                char_name(buff, c);
                printf("%4d %8s %10lld\n", c, buff, bin[c]);
            }
            else
                printf("%4d %10lld\n", c, bin[c]);
        }
}

variable_types:
buff
char [16]


variable_types:
a
long long

variable_types:
n
long long


main

canonical_name: main

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

process_options(argc, (char **)argv);
v3 = (int *)bin;
do
{
*(_QWORD *)v3 = 0LL;
v3 += 2;
}
while ( v3 != &full );
v4 = optind;
if ( optind == argc )
{
process_fp(_bss_start);
}
else
{
for ( ; optind < argc; v4 = optind )
{
optind = v4 + 1;
process_file(argv[v4]);
}
}
if ( table )
show_table();
else
show_sum();
return 0;
}

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

func8(argc, (char **)argv);
v3 = (int *)bin;
do
{
*(_QWORD *)v3 = 0LL;
v3 += 2;
}
while ( v3 != &full );
v4 = optind;
if ( optind == argc )
{
func9(_bss_start);
}
else
{
for ( ; optind < argc; v4 = optind )
{
optind = v4 + 1;
func10(argv[v4]);
}
}
if ( table )
func12();
else
func13();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int c;
    process_options(argc, argv);
    for (c = 0; c < 256; c++)
        bin[c] = 0;
    if (argc == optind)
        process_fp(stdin);
    else
        while (optind < argc)
            process_file(argv[optind++]);
    if (table)
        show_table();
    else
        show_sum();
    return 0;
}


repo: ilhooq/byak

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

bitboard_init(argc, argv, envp);
prng_init(73LL);
tt_init(144000000LL);
position_init();
eval_init();
puts("Chess Engine By Sylvain Philip");
setvbuf(stdin, 0LL, 2, 0LL);
setvbuf(stdout, 0LL, 2, 0LL);
while ( 1 )
{
while ( !fgets(v5, 1024, stdin) )
;
v3 = strlen(v5);
if ( v3 > 1 )
{
v4 = v3 - 1;
if ( v5[v4] == 10 )
v5[v4] = 0;
}
uci_exec(v5);
}
}

original_code:
int main (int argc, char ** argv) {
 bitboard_init();
 prng_init(73);
 tt_init(144000000);
 position_init();
 eval_init();
 printf("Chess Engine By Sylvain Philip\n");
 setvbuf(stdin, ((void *)0), 2, 0);
 setvbuf(stdout, ((void *)0), 2, 0);
 char input[1024];
 while(1) {
  if (fgets(input, 1024, stdin) != ((void *)0)) {
   int s = strlen(input);
   if (s > 1 && input[s-1] == '\n') {
    input[s-1] = '\0';
   }
   uci_exec(input);
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 bitboard_init();
 prng_init(73);
 tt_init(144000000);
 position_init();
 eval_init();
 printf("Chess Engine By Sylvain Philip\n");
 setvbuf(stdin, ((void *)0), 2, 0);
 setvbuf(stdout, ((void *)0), 2, 0);
 char input[1024];
 while(1) {
  if (fgets(input, 1024, stdin) != ((void *)0)) {
   int s = strlen(input);
   if (s > 1 && input[s-1] == '\n') {
    input[s-1] = '\0';
   }
   uci_exec(input);
  }
 }
 return 0;
}

variable_types:
argv
char **

variable_types:
input
char [1024]

variable_types: s int


decompiled_code:
__int64 __fastcall initmagicmoves_occ(__int64 a1, int a2, __int64 a3)
{
unsigned __int64 v4; // rax
__int64 v5; // rdi

if ( a2 <= 0 )
return 0LL;
v4 = 0LL;
v5 = 0LL;
do
{
if ( _bittest64(&a3, v4) )
v5 |= 1LL << *(_DWORD *)(a1 + 4 * v4);
++v4;
}
while ( v4 != a2 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3)
{
unsigned __int64 v4; // rax
__int64 v5; // rdi

if ( a2 <= 0 )
return 0LL;
v4 = 0LL;
v5 = 0LL;
do
{
if ( _bittest64(&a3, v4) )
v5 |= 1LL << *(_DWORD *)(a1 + 4 * v4);
++v4;
}
while ( v4 != a2 );
return v5;
}

original_code:
U64 initmagicmoves_occ(const int* squares, const int numSquares, const U64 linocc)
{
 int i;
 U64 ret=0;
 for(i=0;i<numSquares;i++)
  if(linocc&(((U64)(1))<<i)) ret|=(((U64)(1))<<squares[i]);
 return ret;
}

canonical_original_code:
unsigned long initmagicmoves_occ(int *squares, int numSquares, unsigned long linocc)
{
 int i;
 unsigned long ret = 0;
 for(i=0;i<numSquares;i++)
  if(linocc&(((U64)(1))<<i)) ret|=(((U64)(1))<<squares[i]);
 return ret;
}

variable_types:
squares
int *

variable_types: numSquares int

variable_types:
linocc
unsigned long

variable_types: i int

variable_types:
ret
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall initmagicmoves_Rmoves(int a1, __int64 a2)
{
char v2; // al
char v3; // cl
__int64 v4; // rdi
unsigned __int64 v5; // rdx
__int64 v6; // rcx
__int64 result; // rax
unsigned __int64 v8; // rcx
unsigned __int64 v9; // rcx

v2 = a1;
v3 = a1 + 7;
if ( a1 >= 0 )
v3 = a1;
v4 = 255LL << (v3 & 0xF8);
v5 = 1LL << v2;
v6 = 1LL << v2;
result = 0LL;
while ( 1 )
{
v6 <<= 8;
result |= v6;
if ( !v6 )
break;
if ( (a2 & v6) != 0 )
{
v8 = v5;
goto LABEL_8;
}
}
v8 = v5;
LABEL_8:
while ( 1 )
{
v8 >>= 8;
result |= v8;
if ( !v8 )
break;
if ( (v8 & a2) != 0 )
{
v9 = v5;
goto LABEL_12;
}
}
v9 = v5;
do
{
LABEL_12:
v9 *= 2LL;
if ( (v9 & v4) == 0 )
break;
result |= v9;
}
while ( (v9 & a2) == 0 );
do
{
v5 >>= 1;
if ( (v5 & v4) == 0 )
break;
result |= v5;
}
while ( (v5 & a2) == 0 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2)
{
char v2; // al
char v3; // cl
__int64 v4; // rdi
unsigned __int64 v5; // rdx
__int64 v6; // rcx
__int64 result; // rax
unsigned __int64 v8; // rcx
unsigned __int64 v9; // rcx

v2 = a1;
v3 = a1 + 7;
if ( a1 >= 0 )
v3 = a1;
v4 = 255LL << (v3 & 0xF8);
v5 = 1LL << v2;
v6 = 1LL << v2;
result = 0LL;
while ( 1 )
{
v6 <<= 8;
result |= v6;
if ( !v6 )
break;
if ( (a2 & v6) != 0 )
{
v8 = v5;
goto LABEL_8;
}
}
v8 = v5;
LABEL_8:
while ( 1 )
{
v8 >>= 8;
result |= v8;
if ( !v8 )
break;
if ( (v8 & a2) != 0 )
{
v9 = v5;
goto LABEL_12;
}
}
v9 = v5;
do
{
LABEL_12:
v9 *= 2LL;
if ( (v9 & v4) == 0 )
break;
result |= v9;
}
while ( (v9 & a2) == 0 );
do
{
v5 >>= 1;
if ( (v5 & v4) == 0 )
break;
result |= v5;
}
while ( (v5 & a2) == 0 );
return result;
}

original_code:
U64 initmagicmoves_Rmoves(const int square, const U64 occ)
{
 U64 ret=0;
 U64 bit;
 U64 rowbits=(((U64)0xFF)<<(8*(square/8)));
 bit=(((U64)(1))<<square);
 do
 {
  bit<<=8;
  ret|=bit;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 do
 {
  bit>>=8;
  ret|=bit;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 do
 {
  bit<<=1;
  if(bit&rowbits) ret|=bit;
  else break;
 }while(!(bit&occ));
 bit=(((U64)(1))<<square);
 do
 {
  bit>>=1;
  if(bit&rowbits) ret|=bit;
  else break;
 }while(!(bit&occ));
 return ret;
}

canonical_original_code:
unsigned long initmagicmoves_Rmoves(int square, unsigned long occ)
{
 unsigned long ret = 0;
 unsigned long bit;
 unsigned long rowbits = (((U64)0xFF)<<(8*(square/8)));
 bit=(((U64)(1))<<square);
 do
 {
  bit<<=8;
  ret|=bit;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 do
 {
  bit>>=8;
  ret|=bit;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 do
 {
  bit<<=1;
  if(bit&rowbits) ret|=bit;
  else break;
 }while(!(bit&occ));
 bit=(((U64)(1))<<square);
 do
 {
  bit>>=1;
  if(bit&rowbits) ret|=bit;
  else break;
 }while(!(bit&occ));
 return ret;
}

variable_types: square int

variable_types:
occ
unsigned long

variable_types:
bit
unsigned long

variable_types:
rowbits
unsigned long


original_code:
U64 initmagicmoves_Bmoves(const int square, const U64 occ)
{
 U64 ret=0;
 U64 bit;
 U64 bit2;
 U64 rowbits=(((U64)0xFF)<<(8*(square/8)));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit<<=8-1;
  bit2>>=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit<<=8+1;
  bit2<<=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit>>=8-1;
  bit2<<=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit>>=8+1;
  bit2>>=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 return ret;
}

canonical_original_code:
unsigned long initmagicmoves_Bmoves(int square, unsigned long occ)
{
 unsigned long ret = 0;
 unsigned long bit;
 unsigned long bit2;
 unsigned long rowbits = (((U64)0xFF)<<(8*(square/8)));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit<<=8-1;
  bit2>>=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit<<=8+1;
  bit2<<=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit>>=8-1;
  bit2<<=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 bit=(((U64)(1))<<square);
 bit2=bit;
 do
 {
  bit>>=8+1;
  bit2>>=1;
  if(bit2&rowbits) ret|=bit;
  else break;
 }while(bit && !(bit&occ));
 return ret;
}


initmagicmoves

original_code:
void initmagicmoves(void)
{
 int i;
 int initmagicmoves_bitpos64_database[64]={
 63, 0, 58, 1, 59, 47, 53, 2,
 60, 39, 48, 27, 54, 33, 42, 3,
 61, 51, 37, 40, 49, 18, 28, 20,
 55, 30, 34, 11, 43, 14, 22, 4,
 62, 57, 46, 52, 38, 26, 32, 41,
 50, 36, 17, 19, 29, 10, 13, 21,
 56, 45, 25, 31, 35, 16, 9, 12,
 44, 24, 15, 8, 23, 7, 6, 5};
 for(i=0;i<64;i++)
 {
  int squares[64];
  int numsquares=0;
  U64 temp=magicmoves_b_mask[i];
  while(temp)
  {
   U64 bit=temp&-temp;
   squares[numsquares++]=initmagicmoves_bitpos64_database[(bit*0x07EDD5E59A4E28C2UL)>>58];
   temp^=bit;
  }
  for(temp=0;temp<(((U64)(1))<<numsquares);temp++)
  {
   U64 tempocc=initmagicmoves_occ(squares,numsquares,temp);
    magicmovesbdb[i][((tempocc)*magicmoves_b_magics[i])>>55]=initmagicmoves_Bmoves(i,tempocc);
  }
 }
 for(i=0;i<64;i++)
 {
  int squares[64];
  int numsquares=0;
  U64 temp=magicmoves_r_mask[i];
  while(temp)
  {
   U64 bit=temp&-temp;
   squares[numsquares++]=initmagicmoves_bitpos64_database[(bit*0x07EDD5E59A4E28C2UL)>>58];
   temp^=bit;
  }
  for(temp=0;temp<(((U64)(1))<<numsquares);temp++)
  {
   U64 tempocc=initmagicmoves_occ(squares,numsquares,temp);
    magicmovesrdb[i][((tempocc)*magicmoves_r_magics[i])>>52]=initmagicmoves_Rmoves(i,tempocc);
  }
 }
}

canonical_original_code:
void initmagicmoves()
{
 int i;
 int initmagicmoves_bitpos64_database[64] = {
 63, 0, 58, 1, 59, 47, 53, 2,
 60, 39, 48, 27, 54, 33, 42, 3,
 61, 51, 37, 40, 49, 18, 28, 20,
 55, 30, 34, 11, 43, 14, 22, 4,
 62, 57, 46, 52, 38, 26, 32, 41,
 50, 36, 17, 19, 29, 10, 13, 21,
 56, 45, 25, 31, 35, 16, 9, 12,
 44, 24, 15, 8, 23, 7, 6, 5};
 for(i=0;i<64;i++)
 {
  int squares[64];
  int numsquares = 0;
  unsigned long temp = magicmoves_b_mask[i];
  while(temp)
  {
   unsigned long bit = temp&-temp;
   squares[numsquares++]=initmagicmoves_bitpos64_database[(bit*0x07EDD5E59A4E28C2UL)>>58];
   temp^=bit;
  }
  for(temp=0;temp<(((U64)(1))<<numsquares);temp++)
  {
   unsigned long tempocc = initmagicmoves_occ(squares,numsquares,temp);
    magicmovesbdb[i][((tempocc)*magicmoves_b_magics[i])>>55]=initmagicmoves_Bmoves(i,tempocc);
  }
 }
 for(i=0;i<64;i++)
 {
  int squares[64];
  int numsquares = 0;
  unsigned long temp = magicmoves_r_mask[i];
  while(temp)
  {
   unsigned long bit = temp&-temp;
   squares[numsquares++]=initmagicmoves_bitpos64_database[(bit*0x07EDD5E59A4E28C2UL)>>58];
   temp^=bit;
  }
  for(temp=0;temp<(((U64)(1))<<numsquares);temp++)
  {
   unsigned long tempocc = initmagicmoves_occ(squares,numsquares,temp);
    magicmovesrdb[i][((tempocc)*magicmoves_r_magics[i])>>52]=initmagicmoves_Rmoves(i,tempocc);
  }
 }
}

variable_types:
squares
int [64]

variable_types: numsquares int

variable_types:
temp
unsigned long

variable_types:
tempocc
unsigned long


decompiled_code:
unsigned __int64 __fastcall bitboard_swap(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

original_code:
static inline U64 bitboard_swap (U64 bb) {
 return __builtin_bswap64(bb);
}

canonical_original_code:
static inline unsigned long bitboard_swap(unsigned long bb) {
 return __builtin_bswap64(bb);
}

variable_types:
bb
unsigned long


decompiled_code:
__int64 bitboard_popCount()
{
return _popcountdi2();
}

canonical_decompiled_code:
__int64 func1()
{
return _popcountdi2();
}

original_code:
static inline int bitboard_popCount(U64 bb) {
 return __builtin_popcountll(bb);
}

canonical_original_code:
static inline int bitboard_popCount(unsigned long bb) {
 return __builtin_popcountll(bb);
}


decompiled_code:
__int64 eval_init()
{
unsigned __int64 i; // rbx
__int64 result; // rax

for ( i = 0LL; i != 76; i += 4LL )
{
b_opening[i / 2] = bitboard_swap(w_opening[i / 2]);
dword_268[i] = dword_688[i];
result = (unsigned int)(dword_68C[i] + 1);
dword_26C[i] = result;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned __int64 i; // rbx
__int64 result; // rax

for ( i = 0LL; i != 76; i += 4LL )
{
b_opening[i / 2] = func0(w_opening[i / 2]);
dword_268[i] = dword_688[i];
result = (unsigned int)(dword_68C[i] + 1);
dword_26C[i] = result;
}
return result;
}

original_code:
void eval_init()
{
 U32 i;
 for (i=0; i < sizeof(w_opening) / sizeof(Eval); i++) {
  b_opening[i].mask = bitboard_swap(w_opening[i].mask);
  b_opening[i].score = w_opening[i].score;
  b_opening[i].piece = w_opening[i].piece + 1;
 }
}

canonical_original_code:
void eval_init()
{
 unsigned int i;
 for (i=0; i < sizeof(w_opening) / sizeof(Eval); i++) {
  b_opening[i].mask = bitboard_swap(w_opening[i].mask);
  b_opening[i].score = w_opening[i].score;
  b_opening[i].piece = w_opening[i].piece + 1;
 }
}

variable_types:
i
unsigned int


original_code:
int eval_position()
{
 int who2move = (pos.side == 0) ? 1 : -1;
 if (pos.checkmated) {
  return 10000 * who2move;
 }
 int score = 0;
 int popCnt[NONE_PIECE] = {0};
 int i, popCntTotal = 0;
 U64 bb_pieces;
 for (i=P ; i < NONE_PIECE ; i++) {
  popCntTotal += popCnt[i] = bitboard_popCount(pos.bb_pieces[i]);
 }
 score += 100 * (popCnt[P] - popCnt[p]);
 score += 900 * (popCnt[Q] - popCnt[q]);
 score += 300 * (popCnt[N] - popCnt[n]);
 score += 300 * (popCnt[B] - popCnt[b]);
 score += 600 * (popCnt[R] - popCnt[r]);
 if (pos.castling_rights && (popCntTotal - (popCnt[P] + popCnt[p])) > 10) {
  for (i=0; i < sizeof(w_opening) / sizeof(Eval); i++) {
   bb_pieces = pos.bb_pieces[w_opening[i].piece];
   if (w_opening[i].mask & bb_pieces) {
    score += bitboard_popCount(w_opening[i].mask & bb_pieces) * w_opening[i].score;
   }
   bb_pieces = pos.bb_pieces[b_opening[i].piece];
   if (b_opening[i].mask & bb_pieces) {
    score -= bitboard_popCount(b_opening[i].mask & bb_pieces) * b_opening[i].score;
   }
  }
 }
 else if ((popCntTotal - (popCnt[P] + popCnt[p])) < 7) {
  for (i=0; i < sizeof(w_endgame) / sizeof(Eval); i++) {
   bb_pieces = pos.bb_pieces[w_endgame[i].piece];
   if (w_endgame[i].mask & bb_pieces) {
    score += bitboard_popCount(w_endgame[i].mask & bb_pieces) * w_endgame[i].score;
   }
   bb_pieces = pos.bb_pieces[b_endgame[i].piece];
   if (b_endgame[i].mask & bb_pieces) {
    score -= bitboard_popCount(b_endgame[i].mask & bb_pieces) * b_endgame[i].score;
   }
  }
 }
 else {
  for (i=0; i < sizeof(w_middlegame) / sizeof(Eval); i++) {
   bb_pieces = pos.bb_pieces[w_middlegame[i].piece];
   if (w_middlegame[i].mask & bb_pieces) {
    score += bitboard_popCount(w_middlegame[i].mask & bb_pieces) * w_middlegame[i].score;
   }
   bb_pieces = pos.bb_pieces[b_middlegame[i].piece];
   if (b_middlegame[i].mask & bb_pieces) {
    score -= bitboard_popCount(b_middlegame[i].mask & bb_pieces) * b_middlegame[i].score;
   }
  }
 }
 return score * who2move;
}

canonical_original_code:
int eval_position()
{
 int who2move = (pos.side == 0) ? 1 : -1;
 if (pos.checkmated) {
  return 10000 * who2move;
 }
 int score = 0;
 int popCnt[-1] = {0};
 int i; int popCntTotal = 0;
 unsigned long bb_pieces;
 for (i=P ; i < NONE_PIECE ; i++) {
  popCntTotal += popCnt[i] = bitboard_popCount(pos.bb_pieces[i]);
 }
 score += 100 * (popCnt[P] - popCnt[p]);
 score += 900 * (popCnt[Q] - popCnt[q]);
 score += 300 * (popCnt[N] - popCnt[n]);
 score += 300 * (popCnt[B] - popCnt[b]);
 score += 600 * (popCnt[R] - popCnt[r]);
 if (pos.castling_rights && (popCntTotal - (popCnt[P] + popCnt[p])) > 10) {
  for (i=0; i < sizeof(w_opening) / sizeof(Eval); i++) {
   bb_pieces = pos.bb_pieces[w_opening[i].piece];
   if (w_opening[i].mask & bb_pieces) {
    score += bitboard_popCount(w_opening[i].mask & bb_pieces) * w_opening[i].score;
   }
   bb_pieces = pos.bb_pieces[b_opening[i].piece];
   if (b_opening[i].mask & bb_pieces) {
    score -= bitboard_popCount(b_opening[i].mask & bb_pieces) * b_opening[i].score;
   }
  }
 }
 else if ((popCntTotal - (popCnt[P] + popCnt[p])) < 7) {
  for (i=0; i < sizeof(w_endgame) / sizeof(Eval); i++) {
   bb_pieces = pos.bb_pieces[w_endgame[i].piece];
   if (w_endgame[i].mask & bb_pieces) {
    score += bitboard_popCount(w_endgame[i].mask & bb_pieces) * w_endgame[i].score;
   }
   bb_pieces = pos.bb_pieces[b_endgame[i].piece];
   if (b_endgame[i].mask & bb_pieces) {
    score -= bitboard_popCount(b_endgame[i].mask & bb_pieces) * b_endgame[i].score;
   }
  }
 }
 else {
  for (i=0; i < sizeof(w_middlegame) / sizeof(Eval); i++) {
   bb_pieces = pos.bb_pieces[w_middlegame[i].piece];
   if (w_middlegame[i].mask & bb_pieces) {
    score += bitboard_popCount(w_middlegame[i].mask & bb_pieces) * w_middlegame[i].score;
   }
   bb_pieces = pos.bb_pieces[b_middlegame[i].piece];
   if (b_middlegame[i].mask & bb_pieces) {
    score -= bitboard_popCount(b_middlegame[i].mask & bb_pieces) * b_middlegame[i].score;
   }
  }
 }
 return score * who2move;
}

variable_types: score int

variable_types:
popCnt
int [-1]

variable_types: popCntTotal int


decompiled_code:
__int64 eval_move()
{
return 1LL;
}

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

original_code:
int eval_move(Move * move)
{
 return 1;
}

canonical_original_code:
int eval_move(struct Move *move)
{
 return 1;
}

variable_types: struct Move { unsigned int score; unsigned int padding; unsigned short flags; unsigned char from; unsigned char to; unsigned char captured_piece; unsigned char ep; unsigned char castling_rights; } *


decompiled_code:
__int64 __fastcall uci_prepare_move(__int64 a1, __int64 a2)
{
lsb(a1);
lsb(a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
func0(a1);
func0(a2);
return 0LL;
}

original_code:
static Move uci_prepare_move(U64 from, U64 to, Piece promotion )
{
 Move move;
 move.from = lsb(from);
 move.to = lsb(to);
 move.flags = 0x1;
 move.captured_piece = NONE_PIECE;
 move.castling_rights = 0;
 move.ep = NONE_SQUARE;
 if ((from & pos.bb_pieces[K]) &&
  (move.from == e1 && (move.to == g1 || move.to == c1))) {
  move.flags = 0x200;
 }
 if ((from & pos.bb_pieces[k]) &&
  (move.from == e8 && (move.to == g8 || move.to == c8))) {
  move.flags = 0x200;
 }
 if (promotion != NONE_PIECE) {
  move.flags = 0x8;
  switch(promotion) {
   case Q : move.flags |= 0x10; break;
   case R : move.flags |= 0x80; break;
   case B : move.flags |= 0x20; break;
   case K : move.flags |= 0x40; break;
   default: break;
  }
 }
 if (pos.bb_occupied & to) {
  move.flags |= 0x4;
 }
 if (from & pos.bb_pieces[P + pos.side]) {
  if (abs(move.from - move.to) == 16) {
   move.flags = 0x2;
  }
  if (!(move.flags & 0x4) &&
   (abs(move.from - move.to) == 9 || abs(move.from - move.to) == 7)) {
   move.flags = (0x4|0x100);
  }
 }
 return move;
}

canonical_original_code:
static struct Move uci_prepare_move(unsigned long from, unsigned long to, enum enumPiece promotion)
{
 struct Move move;
 move.from = lsb(from);
 move.to = lsb(to);
 move.flags = 0x1;
 move.captured_piece = NONE_PIECE;
 move.castling_rights = 0;
 move.ep = NONE_SQUARE;
 if ((from & pos.bb_pieces[K]) &&
  (move.from == e1 && (move.to == g1 || move.to == c1))) {
  move.flags = 0x200;
 }
 if ((from & pos.bb_pieces[k]) &&
  (move.from == e8 && (move.to == g8 || move.to == c8))) {
  move.flags = 0x200;
 }
 if (promotion != NONE_PIECE) {
  move.flags = 0x8;
  switch(promotion) {
   case Q : move.flags |= 0x10; break;
   case R : move.flags |= 0x80; break;
   case B : move.flags |= 0x20; break;
   case K : move.flags |= 0x40; break;
   default: break;
  }
 }
 if (pos.bb_occupied & to) {
  move.flags |= 0x4;
 }
 if (from & pos.bb_pieces[P + pos.side]) {
  if (abs(move.from - move.to) == 16) {
   move.flags = 0x2;
  }
  if (!(move.flags & 0x4) &&
   (abs(move.from - move.to) == 9 || abs(move.from - move.to) == 7)) {
   move.flags = (0x4|0x100);
  }
 }
 return move;
}

variable_types:
from
unsigned long

variable_types:
to
unsigned long

variable_types: struct Move { unsigned int score; unsigned int padding; unsigned short flags; unsigned char from; unsigned char to; unsigned char captured_piece; unsigned char ep; unsigned char castling_rights; }


decompiled_code:
__int64 __fastcall uci_parse_moves(unsigned __int8 *a1)
{
__int64 result; // rax
unsigned __int8 *v2; // rbx
__int64 v3; // rdx
__int64 v4; // rbp
__int64 v5; // rsi
char v6; // al
__int64 v7[5]; // [rsp+0h] [rbp-28h] BYREF

result = *a1;
if ( (_BYTE)result )
{
v2 = a1;
do
{
if ( (unsigned __int8)(result - 97) > 7u )
{
++v2;
}
else
{
v4 = bitboard_algToBin(v2);
v5 = bitboard_algToBin(v2 + 2);
v6 = v2[4];
if ( (v6 & 0xDF) != 0 )
{
if ( v6 == 113 )
{
++v2;
}
else if ( v6 > 113 )
{
if ( v6 == 114 )
++v2;
}
else if ( v6 == 98 )
{
++v2;
}
else if ( v6 == 110 )
{
++v2;
}
}
v7[0] = uci_prepare_move(v4, v5);
v7[1] = v3;
position_makeMove(v7);
v2 += 4;
}
result = *v2;
}
while ( (_BYTE)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1)
{
__int64 result; // rax
unsigned __int8 *v2; // rbx
__int64 v3; // rdx
__int64 v4; // rbp
__int64 v5; // rsi
char v6; // al
__int64 v7[5]; // [rsp+0h] [rbp-28h] BYREF

result = *a1;
if ( (_BYTE)result )
{
v2 = a1;
do
{
if ( (unsigned __int8)(result - 97) > 7u )
{
++v2;
}
else
{
v4 = bitboard_algToBin(v2);
v5 = bitboard_algToBin(v2 + 2);
v6 = v2[4];
if ( (v6 & 0xDF) != 0 )
{
if ( v6 == 113 )
{
++v2;
}
else if ( v6 > 113 )
{
if ( v6 == 114 )
++v2;
}
else if ( v6 == 98 )
{
++v2;
}
else if ( v6 == 110 )
{
++v2;
}
}
v7[0] = func1(v4, v5);
v7[1] = v3;
position_makeMove(v7);
v2 += 4;
}
result = *v2;
}
while ( (_BYTE)result );
}
return result;
}

original_code:
static void uci_parse_moves(const char * moves)
{
 U64 from = 0x0000000000000000UL;
 U64 to = 0x0000000000000000UL;
 Square promotion = NONE_PIECE;
 while (moves[0]) {
  if ((moves[0] >= 'a') && (moves[0] <= 'h')) {
   from = bitboard_algToBin(moves);
   to = bitboard_algToBin(moves+2);
   promotion = NONE_PIECE;
   if (moves[4] && moves[4] != ' ') {
    switch(moves[4]) {
     case 'q': promotion = Q; moves++; break;
     case 'r': promotion = R; moves++; break;
     case 'b': promotion = B; moves++; break;
     case 'n': promotion = N; moves++; break;
    }
   }
   Move move = uci_prepare_move(from, to, promotion);
   position_makeMove(&move);
   moves += 4;
  } else {
   moves++;
  }
 }
}

canonical_original_code:
static void uci_parse_moves(char *moves)
{
 unsigned long from = 0x0000000000000000UL;
 unsigned long to = 0x0000000000000000UL;
 enum enumSquare promotion = NONE_PIECE;
 while (moves[0]) {
  if ((moves[0] >= 'a') && (moves[0] <= 'h')) {
   from = bitboard_algToBin(moves);
   to = bitboard_algToBin(moves+2);
   promotion = NONE_PIECE;
   if (moves[4] && moves[4] != ' ') {
    switch(moves[4]) {
     case 'q': promotion = Q; moves++; break;
     case 'r': promotion = R; moves++; break;
     case 'b': promotion = B; moves++; break;
     case 'n': promotion = N; moves++; break;
    }
   }
   struct Move move = uci_prepare_move(from, to, promotion);
   position_makeMove(&move);
   moves += 4;
  } else {
   moves++;
  }
 }
}

variable_types:
moves
char *

user_defined_types: struct Move { unsigned int score; unsigned int padding; unsigned short flags; unsigned char from; unsigned char to; unsigned char captured_piece; unsigned char ep; unsigned char castling_rights; }


decompiled_code:
int __fastcall uci_go(char *haystack)
{
char *v1; // rax
char *v2; // rax
pthread_t newthread; // [rsp+8h] [rbp-40C0h] BYREF
int s[4142]; // [rsp+10h] [rbp-40B8h] BYREF

memset(s, 0, 0x40A4uLL);
v1 = strstr(haystack, "wtime");
if ( v1 )
s[2] = atoi(v1 + 6);
v2 = strstr(haystack, "btime");
if ( v2 )
s[3] = atoi(v2 + 6);
if ( strstr(haystack, "infinite") )
s[8] = 32;
return pthread_create(&newthread, 0LL, (void *(*)(void *))&search_start, s);
}

canonical_decompiled_code:
int __fastcall func3(char *haystack)
{
char *v1; // rax
char *v2; // rax
pthread_t newthread; // [rsp+8h] [rbp-40C0h] BYREF
int s[4142]; // [rsp+10h] [rbp-40B8h] BYREF

memset(s, 0, 0x40A4uLL);
v1 = strstr(haystack, "wtime");
if ( v1 )
s[2] = atoi(v1 + 6);
v2 = strstr(haystack, "btime");
if ( v2 )
s[3] = atoi(v2 + 6);
if ( strstr(haystack, "infinite") )
s[8] = 32;
return pthread_create(&newthread, 0LL, (void *(*)(void *))&search_start, s);
}

original_code:
static void uci_go(char * command)
{
 char * subcommand = ((void *)0);
 SearchInfos infos = {0};
 infos.time[0] = 0;
 infos.time[1] = 0;
 if ((subcommand = strstr(command, "wtime"))) {
  infos.time[0] = atoi(subcommand+6);
 }
 if ((subcommand = strstr(command, "btime"))) {
  infos.time[1] = atoi(subcommand+6);
 }
 if ((subcommand = strstr(command, "infinite"))) {
  infos.depth = 32;
 }
 pthread_t SearchThread;
 pthread_create(&SearchThread, ((void *)0), search_start, &infos);
}

canonical_original_code:
static void uci_go(char *command)
{
 char *subcommand = ((void *)0);
 struct SearchInfos infos = {0};
 infos.time[0] = 0;
 infos.time[1] = 0;
 if ((subcommand = strstr(command, "wtime"))) {
  infos.time[0] = atoi(subcommand+6);
 }
 if ((subcommand = strstr(command, "btime"))) {
  infos.time[1] = atoi(subcommand+6);
 }
 if ((subcommand = strstr(command, "infinite"))) {
  infos.depth = 32;
 }
 unsigned long SearchThread;
 pthread_create(&SearchThread, ((void *)0), search_start, &infos);
}

variable_types:
command
char *

variable_types:
subcommand
char *

variable_types: struct SearchInfos { int time_start; int time_used; int time[2]; int movetime; int my_side; int stop; int nodes; int depth; struct Move { unsigned int score; unsigned int padding; unsigned short flags; unsigned char from; unsigned char to; unsigned char captured_piece; unsigned char ep; unsigned char castling_rights; } pv[32][32]; int pv_length[32]; }

variable_types:
SearchThread
unsigned long

user_defined_types: struct SearchInfos { int time_start; int time_used; int time[2]; int movetime; int my_side; int stop; int nodes; int depth; struct Move pv[32][32]; int pv_length[32]; }


GetTickCount

decompiled_code:
__int64 GetTickCount()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * LODWORD(v1.tv_sec) + (unsigned int)(v1.tv_usec / 1000);
}

canonical_decompiled_code:
__int64 func4()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * LODWORD(v1.tv_sec) + (unsigned int)(v1.tv_usec / 1000);
}

original_code:
static int GetTickCount()
{
 struct timeval t;
 gettimeofday(&t, ((void *)0));
 return t.tv_sec * 1000 + t.tv_usec / 1000;
}

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


decompiled_code:
int __fastcall uci_ext_perft(unsigned int a1, int a2)
{
int v2; // er12
__int64 v3; // rbx
__int64 v4; // rdx
float v5; // xmm0_4

v2 = GetTickCount();
if ( a2 )
{
puts("Use tt: yes");
v3 = search_perft_tt(a1);
}
else
{
puts("Use tt: no");
v3 = search_perft(a1);
}
v4 = (unsigned int)GetTickCount() - v2;
if ( v3 < 0 )
v5 = (float)(v3 & 1 | (unsigned int)((unsigned __int64)v3 >> 1))
+ (float)(v3 & 1 | (unsigned int)((unsigned __int64)v3 >> 1));
else
v5 = (float)(int)v3;
return printf("depth:%i;time:%i;nodes:%llu;nps:%.0f\n", a1, v4, v3, (float)(v5 / (float)((float)(int)v4 / 1000.0)));
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1, int a2)
{
int v2; // er12
__int64 v3; // rbx
__int64 v4; // rdx
float v5; // xmm0_4

v2 = func4();
if ( a2 )
{
puts("Use tt: yes");
v3 = search_perft_tt(a1);
}
else
{
puts("Use tt: no");
v3 = search_perft(a1);
}
v4 = (unsigned int)func4() - v2;
if ( v3 < 0 )
v5 = (float)(v3 & 1 | (unsigned int)((unsigned __int64)v3 >> 1))
+ (float)(v3 & 1 | (unsigned int)((unsigned __int64)v3 >> 1));
else
v5 = (float)(int)v3;
return printf("depth:%i;time:%i;nodes:%llu;nps:%.0f\n", a1, v4, v3, (float)(v5 / (float)((float)(int)v4 / 1000.0)));
}

original_code:
static void uci_ext_perft(int depth, int use_tt)
{
 int start, timeused;
 float nps;
 U64 nodes;
 start = ((int)(GetTickCount()));
 if (!use_tt) {
  printf("Use tt: no\n");
  nodes = search_perft(depth);
 } else {
  printf("Use tt: yes\n");
  nodes = search_perft_tt(depth);
 }
 timeused = ((int)(GetTickCount())) - start;
 nps = (float) nodes / ((float) timeused /1000);
 printf("depth:%i;time:%i;nodes:%llu;nps:%.0f\n", depth, timeused, ((unsigned long long int) nodes), nps);
}

canonical_original_code:
static void uci_ext_perft(int depth, int use_tt)
{
 int start; int timeused;
 float nps;
 unsigned long nodes;
 start = ((int)(GetTickCount()));
 if (!use_tt) {
  printf("Use tt: no\n");
  nodes = search_perft(depth);
 } else {
  printf("Use tt: yes\n");
  nodes = search_perft_tt(depth);
 }
 timeused = ((int)(GetTickCount())) - start;
 nps = (float) nodes / ((float) timeused /1000);
 printf("depth:%i;time:%i;nodes:%llu;nps:%.0f\n", depth, timeused, ((unsigned long long) nodes), nps);
}

variable_types: depth int

variable_types: start int

variable_types: timeused int

variable_types: nps float

variable_types:
nodes
unsigned long


decompiled_code:
int __fastcall uci_ext_divide(int a1)
{
unsigned int v1; // er13
char v2; // al
_BYTE *v3; // rbx
_BYTE *v4; // r14
__int64 v5; // r12
__int64 v6; // rbp
_BYTE v8[4136]; // [rsp+0h] [rbp-1028h] BYREF

v1 = a1 - 1;
if ( a1 <= 1 )
v1 = 0;
v2 = position_generateMoves(v8);
if ( v2 )
{
v3 = v8;
v4 = &v8[16 * (unsigned __int8)(v2 - 1) + 16];
v5 = 0LL;
do
{
position_makeMove(v3);
v6 = search_perft(v1);
move_displayAlg(v3);
printf(" : %llu\n", v6);
position_undoMove(v3);
v5 += v6;
v3 += 16;
}
while ( v3 != v4 );
}
else
{
v5 = 0LL;
}
return printf("\n\nNodes : %llu\n", v5);
}

canonical_decompiled_code:
int __fastcall func6(int a1)
{
unsigned int v1; // er13
char v2; // al
_BYTE *v3; // rbx
_BYTE *v4; // r14
__int64 v5; // r12
__int64 v6; // rbp
_BYTE v8[4136]; // [rsp+0h] [rbp-1028h] BYREF

v1 = a1 - 1;
if ( a1 <= 1 )
v1 = 0;
v2 = position_generateMoves(v8);
if ( v2 )
{
v3 = v8;
v4 = &v8[16 * (unsigned __int8)(v2 - 1) + 16];
v5 = 0LL;
do
{
position_makeMove(v3);
v6 = search_perft(v1);
move_displayAlg(v3);
printf(" : %llu\n", v6);
position_undoMove(v3);
v5 += v6;
v3 += 16;
}
while ( v3 != v4 );
}
else
{
v5 = 0LL;
}
return printf("\n\nNodes : %llu\n", v5);
}

original_code:
void uci_ext_divide(int depth)
{
 U64 nodes = 0;
 U64 count = 0;
 U8 i, listlen;
 if (depth > 1) depth--;
 else depth = 0;
 Move movelist[256];
 listlen = position_generateMoves(movelist);
 for (i=0; i < listlen; i++) {
  position_makeMove(&movelist[i]);
  count = search_perft(depth);
  move_displayAlg(&movelist[i]);
  printf(" : %llu\n", ((unsigned long long int) count));
  position_undoMove(&movelist[i]);
  nodes += count;
 }
 printf("\n\nNodes : %llu\n", ((unsigned long long int) nodes));
}

canonical_original_code:
void uci_ext_divide(int depth)
{
 unsigned long nodes = 0;
 unsigned long count = 0;
 unsigned char i; unsigned char listlen;
 if (depth > 1) depth--;
 else depth = 0;
 struct Move movelist[256];
 listlen = position_generateMoves(movelist);
 for (i=0; i < listlen; i++) {
  position_makeMove(&movelist[i]);
  count = search_perft(depth);
  move_displayAlg(&movelist[i]);
  printf(" : %llu\n", ((unsigned long long) count));
  position_undoMove(&movelist[i]);
  nodes += count;
 }
 printf("\n\nNodes : %llu\n", ((unsigned long long) nodes));
}

variable_types:
count
unsigned long

variable_types:
i
unsigned char

variable_types:
listlen
unsigned char

variable_types: struct Move { unsigned int score; unsigned int padding; unsigned short flags; unsigned char from; unsigned char to; unsigned char captured_piece; unsigned char ep; unsigned char castling_rights; } [256]


decompiled_code:
char __fastcall uci_exec(char *haystack)
{
bool v2; // al
bool v3; // cf
bool v4; // zf
const char *v5; // rdi
__int64 v6; // rcx
char *v7; // rsi
bool v8; // al
bool v9; // cf
bool v10; // zf
const char *v11; // rdi
__int64 v12; // rcx
char *v13; // rsi
bool v14; // al
bool v15; // cf
bool v16; // zf
const char *v17; // rdi
__int64 v18; // rcx
char *v19; // rsi
char *v20; // rbp
int v21; // eax
bool v22; // al
bool v23; // cf
bool v24; // zf
const char *v25; // rdi
__int64 v26; // rcx
char *v27; // rsi
char result; // al
bool v29; // al
bool v30; // cf
bool v31; // zf
const char *v32; // rdi
__int64 v33; // rcx
char *v34; // rsi
char *v35; // rax
int v36; // eax
unsigned int v37; // eax
int v38; // [rsp+Ch] [rbp-21Ch] BYREF
char v39[256]; // [rsp+10h] [rbp-218h] BYREF
char v40[280]; // [rsp+110h] [rbp-118h] BYREF

if ( !strcmp(haystack, "uci") )
{
puts("id name chess_engine");
puts("id author Sylvain Philip");
puts("option name Hash type spin default 64 min 1 max 1024");
puts("uciok");
}
if ( !strcmp(haystack, "isready") )
puts("readyok");
v2 = memcmp(haystack, "setoption", 9uLL) != 0;
v3 = 0;
v4 = !v2;
if ( !v2 )
{
_isoc99_sscanf(haystack, "setoption name %255s value %255s", v39, v40);
v29 = strcmp(v39, "Hash") != 0;
v3 = 0;
v4 = !v29;
if ( !v29 )
{
_isoc99_sscanf(v40, "%4u", &v38);
tt_setsize((unsigned int)(v38 << 20));
}
}
v5 = "position";
v6 = 8LL;
v7 = haystack;
do
{
if ( !v6 )
break;
v3 = (unsigned __int8)*v7 < (unsigned int)*v5;
v4 = *v7++ == *v5++;
--v6;
}
while ( v4 );
if ( (!v3 && !v4) == v3 )
{
position_init(v5, v7);
v32 = "position fen";
v33 = 12LL;
v34 = haystack;
do
{
if ( !v33 )
break;
v30 = (unsigned __int8)*v34 < (unsigned int)*v32;
v31 = *v34++ == *v32++;
--v33;
}
while ( v31 );
if ( (!v30 && !v31) == v30 )
position_fromFen(haystack + 13, v34);
else
position_fromFen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", v34);
v35 = strstr(haystack, "moves");
if ( v35 )
uci_parse_moves((unsigned __int8 *)v35 + 6);
}
v8 = memcmp(haystack, "go", 2uLL) != 0;
v9 = 0;
v10 = !v8;
if ( !v8 )
uci_go(haystack);
v11 = "stop";
v12 = 5LL;
v13 = haystack;
do
{
if ( !v12 )
break;
v9 = (unsigned __int8)*v13 < (unsigned int)*v11;
v10 = *v13++ == *v11++;
--v12;
}
while ( v10 );
if ( (!v9 && !v10) == v9 )
search_stop(v11, v13);
v14 = strcmp(haystack, "quit") != 0;
v15 = 0;
v16 = !v14;
if ( !v14 )
exit(0);
v17 = "display";
v18 = 8LL;
v19 = haystack;
do
{
if ( !v18 )
break;
v15 = (unsigned __int8)*v19 < (unsigned int)*v17;
v16 = *v19++ == *v17++;
--v18;
}
while ( v16 );
if ( (!v15 && !v16) == v15 )
position_display(v17, v19);
if ( !memcmp(haystack, "perft", 5uLL) )
{
v20 = strstr(haystack, "tt");
v21 = atoi(haystack + 6);
uci_ext_perft(v21, v20 != 0LL);
}
v22 = memcmp(haystack, "divide", 6uLL) != 0;
v23 = 0;
v24 = !v22;
if ( !v22 )
{
v36 = atoi(haystack + 7);
uci_ext_divide(v36);
}
v25 = "eval";
v26 = 4LL;
v27 = haystack;
do
{
if ( !v26 )
break;
v23 = (unsigned __int8)*v27 < (unsigned int)*v25;
v24 = *v27++ == *v25++;
--v26;
}
while ( v24 );
result = (!v23 && !v24) - v23;
if ( !result )
{
v37 = eval_position(v25, v27);
result = printf("score: %i \n", v37);
}
return result;
}

canonical_decompiled_code:
char __fastcall func7(char *haystack)
{
bool v2; // al
bool v3; // cf
bool v4; // zf
const char *v5; // rdi
__int64 v6; // rcx
char *v7; // rsi
bool v8; // al
bool v9; // cf
bool v10; // zf
const char *v11; // rdi
__int64 v12; // rcx
char *v13; // rsi
bool v14; // al
bool v15; // cf
bool v16; // zf
const char *v17; // rdi
__int64 v18; // rcx
char *v19; // rsi
char *v20; // rbp
int v21; // eax
bool v22; // al
bool v23; // cf
bool v24; // zf
const char *v25; // rdi
__int64 v26; // rcx
char *v27; // rsi
char result; // al
bool v29; // al
bool v30; // cf
bool v31; // zf
const char *v32; // rdi
__int64 v33; // rcx
char *v34; // rsi
char *v35; // rax
int v36; // eax
unsigned int v37; // eax
int v38; // [rsp+Ch] [rbp-21Ch] BYREF
char v39[256]; // [rsp+10h] [rbp-218h] BYREF
char v40[280]; // [rsp+110h] [rbp-118h] BYREF

if ( !strcmp(haystack, "uci") )
{
puts("id name chess_engine");
puts("id author Sylvain Philip");
puts("option name Hash type spin default 64 min 1 max 1024");
puts("uciok");
}
if ( !strcmp(haystack, "isready") )
puts("readyok");
v2 = memcmp(haystack, "setoption", 9uLL) != 0;
v3 = 0;
v4 = !v2;
if ( !v2 )
{
_isoc99_sscanf(haystack, "setoption name %255s value %255s", v39, v40);
v29 = strcmp(v39, "Hash") != 0;
v3 = 0;
v4 = !v29;
if ( !v29 )
{
_isoc99_sscanf(v40, "%4u", &v38);
tt_setsize((unsigned int)(v38 << 20));
}
}
v5 = "position";
v6 = 8LL;
v7 = haystack;
do
{
if ( !v6 )
break;
v3 = (unsigned __int8)*v7 < (unsigned int)*v5;
v4 = *v7++ == *v5++;
--v6;
}
while ( v4 );
if ( (!v3 && !v4) == v3 )
{
position_init(v5, v7);
v32 = "position fen";
v33 = 12LL;
v34 = haystack;
do
{
if ( !v33 )
break;
v30 = (unsigned __int8)*v34 < (unsigned int)*v32;
v31 = *v34++ == *v32++;
--v33;
}
while ( v31 );
if ( (!v30 && !v31) == v30 )
position_fromFen(haystack + 13, v34);
else
position_fromFen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", v34);
v35 = strstr(haystack, "moves");
if ( v35 )
func2((unsigned __int8 *)v35 + 6);
}
v8 = memcmp(haystack, "go", 2uLL) != 0;
v9 = 0;
v10 = !v8;
if ( !v8 )
func3(haystack);
v11 = "stop";
v12 = 5LL;
v13 = haystack;
do
{
if ( !v12 )
break;
v9 = (unsigned __int8)*v13 < (unsigned int)*v11;
v10 = *v13++ == *v11++;
--v12;
}
while ( v10 );
if ( (!v9 && !v10) == v9 )
search_stop(v11, v13);
v14 = strcmp(haystack, "quit") != 0;
v15 = 0;
v16 = !v14;
if ( !v14 )
exit(0);
v17 = "display";
v18 = 8LL;
v19 = haystack;
do
{
if ( !v18 )
break;
v15 = (unsigned __int8)*v19 < (unsigned int)*v17;
v16 = *v19++ == *v17++;
--v18;
}
while ( v16 );
if ( (!v15 && !v16) == v15 )
position_display(v17, v19);
if ( !memcmp(haystack, "perft", 5uLL) )
{
v20 = strstr(haystack, "tt");
v21 = atoi(haystack + 6);
func5(v21, v20 != 0LL);
}
v22 = memcmp(haystack, "divide", 6uLL) != 0;
v23 = 0;
v24 = !v22;
if ( !v22 )
{
v36 = atoi(haystack + 7);
func6(v36);
}
v25 = "eval";
v26 = 4LL;
v27 = haystack;
do
{
if ( !v26 )
break;
v23 = (unsigned __int8)*v27 < (unsigned int)*v25;
v24 = *v27++ == *v25++;
--v26;
}
while ( v24 );
result = (!v23 && !v24) - v23;
if ( !result )
{
v37 = eval_position(v25, v27);
result = printf("score: %i \n", v37);
}
return result;
}

original_code:
void uci_exec(char * command)
{
 if (!strcmp(command, "uci")) {
  printf("id name chess_engine\n");
  printf("id author Sylvain Philip\n");
  printf("option name Hash type spin default 64 min 1 max 1024\n");
  printf("uciok\n");
 }
 if (!strcmp(command, "isready")) {
  printf("readyok\n");
 }
 if (!strncmp(command, "setoption", 9)) {
  char name[256];
  char value[256];
  sscanf(command, "setoption name %255s value %255s", name, value);
  if (!strcmp(name, "Hash")) {
   int val;
   sscanf(value, "%4u", &val);
   tt_setsize(val << 20);
  }
 }
 if (!strcmp(command, "ucinewgame")) {
 }
 if (!strncmp(command, "position", 8)) {
  position_init();
  if (!strncmp(command,"position fen",12)) {
   position_fromFen(command + 13);
  } else {
   position_fromFen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
  }
  char * moves = strstr(command, "moves");
  if (moves) {
   uci_parse_moves(moves+6);
  }
 }
 if (!strncmp(command, "go", 2)) {
  uci_go(command);
 }
 if (!strncmp(command, "debug", 5)) {
 }
 if (!strcmp(command, "ponderhit")) {
 }
 if (!strcmp(command, "stop")) {
  search_stop();
 }
 if (!strcmp(command, "quit")) {
  exit(0);
 }
 if (!strcmp(command, "help")) {
 }
 if (!strcmp(command, "display")) {
  position_display();
 }
 if (!strncmp(command, "perft", 5)) {
  int use_tt = 0;
  if (strstr(command, "tt")) {
   use_tt = 1;
  }
  uci_ext_perft(atoi(command + 6), use_tt);
 }
 if (!strncmp(command, "divide", 6)) {
  uci_ext_divide(atoi(command + 7));
 }
 if (!strncmp(command, "eval", 4)) {
  printf("score: %i \n", eval_position());
 }
}

canonical_original_code:
void uci_exec(char *command)
{
 if (!strcmp(command, "uci")) {
  printf("id name chess_engine\n");
  printf("id author Sylvain Philip\n");
  printf("option name Hash type spin default 64 min 1 max 1024\n");
  printf("uciok\n");
 }
 if (!strcmp(command, "isready")) {
  printf("readyok\n");
 }
 if (!strncmp(command, "setoption", 9)) {
  char name[256];
  char value[256];
  sscanf(command, "setoption name %255s value %255s", name, value);
  if (!strcmp(name, "Hash")) {
   int val;
   sscanf(value, "%4u", &val);
   tt_setsize(val << 20);
  }
 }
 if (!strcmp(command, "ucinewgame")) {
 }
 if (!strncmp(command, "position", 8)) {
  position_init();
  if (!strncmp(command,"position fen",12)) {
   position_fromFen(command + 13);
  } else {
   position_fromFen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
  }
  char *moves = strstr(command, "moves");
  if (moves) {
   uci_parse_moves(moves+6);
  }
 }
 if (!strncmp(command, "go", 2)) {
  uci_go(command);
 }
 if (!strncmp(command, "debug", 5)) {
 }
 if (!strcmp(command, "ponderhit")) {
 }
 if (!strcmp(command, "stop")) {
  search_stop();
 }
 if (!strcmp(command, "quit")) {
  exit(0);
 }
 if (!strcmp(command, "help")) {
 }
 if (!strcmp(command, "display")) {
  position_display();
 }
 if (!strncmp(command, "perft", 5)) {
  int use_tt = 0;
  if (strstr(command, "tt")) {
   use_tt = 1;
  }
  uci_ext_perft(atoi(command + 6), use_tt);
 }
 if (!strncmp(command, "divide", 6)) {
  uci_ext_divide(atoi(command + 7));
 }
 if (!strncmp(command, "eval", 4)) {
  printf("score: %i \n", eval_position());
 }
}

variable_types:
name
char [256]

variable_types:
value
char [256]

variable_types: val int


decompiled_code:
int __fastcall uci_print_move(unsigned __int8 *a1)
{
char v1; // bl
const char *v2; // r13
const char *v3; // rax

v1 = move_getPromotionPieceChar(a1[8]);
v2 = (const char *)bitboard_binToAlg(1LL << a1[11]);
v3 = (const char *)bitboard_binToAlg(1LL << a1[10]);
return printf("%s%s%c", v3, v2, (unsigned int)v1);
}

canonical_decompiled_code:
int __fastcall func8(unsigned __int8 *a1)
{
char v1; // bl
const char *v2; // r13
const char *v3; // rax

v1 = move_getPromotionPieceChar(a1[8]);
v2 = (const char *)bitboard_binToAlg(1LL << a1[11]);
v3 = (const char *)bitboard_binToAlg(1LL << a1[10]);
return printf("%s%s%c", v3, v2, (unsigned int)v1);
}

original_code:
void uci_print_move(Move *move)
{
 printf("%s%s%c", bitboard_binToAlg(((1UL) << (move->from))),
      bitboard_binToAlg(((1UL) << (move->to))),
      move_getPromotionPieceChar(move->flags));
}

canonical_original_code:
void uci_print_move(struct Move *move)
{
 printf("%s%s%c", bitboard_binToAlg(((1UL) << (move->from))),
      bitboard_binToAlg(((1UL) << (move->to))),
      move_getPromotionPieceChar(move->flags));
}

variable_types: struct Move { unsigned int score; unsigned int padding; unsigned short flags; unsigned char from; unsigned char to; unsigned char captured_piece; unsigned char ep; unsigned char castling_rights; } *


decompiled_code:
int __fastcall uci_print_currmove(unsigned __int8 *a1, __int64 a2, unsigned int a3)
{
printf("info depth %d currmove ", a2);
uci_print_move(a1);
return printf(" currmovenumber %d\n", a3);
}

canonical_decompiled_code:
int __fastcall func9(unsigned __int8 *a1, __int64 a2, unsigned int a3)
{
printf("info depth %d currmove ", a2);
func8(a1);
return printf(" currmovenumber %d\n", a3);
}

original_code:
void uci_print_currmove(Move * move, int depth, int mvNbr)
{
 printf("info depth %d currmove ", depth);
 uci_print_move(move);
 printf(" currmovenumber %d\n", mvNbr);
}

canonical_original_code:
void uci_print_currmove(struct Move *move, int depth, int mvNbr)
{
 printf("info depth %d currmove ", depth);
 uci_print_move(move);
 printf(" currmovenumber %d\n", mvNbr);
}

variable_types: mvNbr int


decompiled_code:
int __fastcall uci_print_pv(unsigned int a1, unsigned int a2, _DWORD *a3)
{
int v4; // eax
unsigned __int8 *v5; // rbp
int v6; // ebx

v4 = GetTickCount();
printf("info depth %i score cp %i nodes %i time %i", a2, a1, (unsigned int)a3[7], (unsigned int)(v4 - *a3));
printf(" pv ");
if ( (int)a3[4105] > 0 )
{
v5 = (unsigned __int8 *)(a3 + 9);
v6 = 0;
do
{
uci_print_move(v5);
putchar(32);
++v6;
v5 += 16;
}
while ( a3[4105] > v6 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1, unsigned int a2, _DWORD *a3)
{
int v4; // eax
unsigned __int8 *v5; // rbp
int v6; // ebx

v4 = func4();
printf("info depth %i score cp %i nodes %i time %i", a2, a1, (unsigned int)a3[7], (unsigned int)(v4 - *a3));
printf(" pv ");
if ( (int)a3[4105] > 0 )
{
v5 = (unsigned __int8 *)(a3 + 9);
v6 = 0;
do
{
func8(v5);
putchar(32);
++v6;
v5 += 16;
}
while ( a3[4105] > v6 );
}
return putchar(10);
}

original_code:
void uci_print_pv(int score, int depth, SearchInfos * infos)
{
 int timeused = ((int)(GetTickCount())) - infos->time_start;
 printf("info depth %i score cp %i nodes %i time %i", depth, score, infos->nodes, timeused);
 printf(" pv ");
 int j;
 for (j = 0; j < infos->pv_length[0]; ++j) {
  uci_print_move(&infos->pv[0][j]);
  printf(" ");
 }
 printf("\n");
}

canonical_original_code:
void uci_print_pv(int score, int depth, struct SearchInfos *infos)
{
 int timeused = ((int)(GetTickCount())) - infos->time_start;
 printf("info depth %i score cp %i nodes %i time %i", depth, score, infos->nodes, timeused);
 printf(" pv ");
 int j;
 for (j = 0; j < infos->pv_length[0]; ++j) {
  uci_print_move(&infos->pv[0][j]);
  printf(" ");
 }
 printf("\n");
}

variable_types: score int

variable_types: struct SearchInfos { int time_start; int time_used; int time[2]; int movetime; int my_side; int stop; int nodes; int depth; struct Move { unsigned int score; unsigned int padding; unsigned short flags; unsigned char from; unsigned char to; unsigned char captured_piece; unsigned char ep; unsigned char castling_rights; } pv[32][32]; int pv_length[32]; } *

variable_types: j int


decompiled_code:
void __fastcall uci_print_nps(int a1, int a2)
{
float v2; // xmm0_4

if ( a2 )
{
v2 = (float)(int)(GetTickCount() - a1) / 1000.0;
if ( v2 != 0.0 )
printf("info nps %.0f\n", (float)((float)a2 / v2));
}
}

canonical_decompiled_code:
void __fastcall func11(int a1, int a2)
{
float v2; // xmm0_4

if ( a2 )
{
v2 = (float)(int)(func4() - a1) / 1000.0;
if ( v2 != 0.0 )
printf("info nps %.0f\n", (float)((float)a2 / v2));
}
}

original_code:
void uci_print_nps(int time_start, int nodes)
{
 if (!nodes) return;
 float time_used_in_sec, nps;
 time_used_in_sec = (float) (((int)(GetTickCount())) - time_start) / 1000;
 if (!time_used_in_sec) return;
 nps = (float) nodes / time_used_in_sec;
 printf("info nps %.0f\n", nps);
}

canonical_original_code:
void uci_print_nps(int time_start, int nodes)
{
 if (!nodes) return;
 float time_used_in_sec; float nps;
 time_used_in_sec = (float) (((int)(GetTickCount())) - time_start) / 1000;
 if (!time_used_in_sec) return;
 nps = (float) nodes / time_used_in_sec;
 printf("info nps %.0f\n", nps);
}

variable_types: nodes int


decompiled_code:
int __fastcall uci_print_bestmove(unsigned __int8 *a1)
{
printf("bestmove ");
uci_print_move(a1);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func12(unsigned __int8 *a1)
{
printf("bestmove ");
func8(a1);
return putchar(10);
}

original_code:
void uci_print_bestmove(Move * move)
{
 printf("bestmove ");
 uci_print_move(move);
 printf("\n");
}

canonical_original_code:
void uci_print_bestmove(struct Move *move)
{
 printf("bestmove ");
 uci_print_move(move);
 printf("\n");
}


decompiled_code:
__int64 __fastcall tt_setsize(int a1)
{
int v1; // ebx
int v2; // eax
int v3; // edx
int v4; // ecx
__int64 result; // rax

v1 = a1;
free(tt);
v2 = a1 - 1;
if ( (v1 & (v1 - 1)) != 0 )
{
v3 = 5;
v4 = 1;
do
{
v2 |= v2 >> v4;
v4 *= 2;
--v3;
}
while ( v3 );
v1 = (v2 + 1) >> 1;
}
if ( v1 > 15 )
{
tt_size = ((unsigned __int64)v1 >> 4) - 1;
tt = malloc(v1);
result = 1LL;
}
else
{
tt_size = 0;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // ebx
int v2; // eax
int v3; // edx
int v4; // ecx
__int64 result; // rax

v1 = a1;
free(tt);
v2 = a1 - 1;
if ( (v1 & (v1 - 1)) != 0 )
{
v3 = 5;
v4 = 1;
do
{
v2 |= v2 >> v4;
v4 *= 2;
--v3;
}
while ( v3 );
v1 = (v2 + 1) >> 1;
}
if ( v1 > 15 )
{
tt_size = ((unsigned __int64)v1 >> 4) - 1;
tt = malloc(v1);
result = 1LL;
}
else
{
tt_size = 0;
result = 0LL;
}
return result;
}

original_code:
int tt_setsize(int size)
{
 free(tt);
 if (size & (size - 1)) {
  int i;
  size--;
  for (i=1; i < 32; i=i*2) {
   size |= size >> i;
  }
  size++;
  size >>= 1;
 }
 if (size < 16) {
  tt_size = 0;
  return 0;
 }
 tt_size = (size / sizeof(TranspositionTable)) -1;
 tt = (TranspositionTable *) malloc(size);
 return 1;
}

canonical_original_code:
int tt_setsize(int size)
{
 free(tt);
 if (size & (size - 1)) {
  int i;
  size--;
  for (i=1; i < 32; i=i*2) {
   size |= size >> i;
  }
  size++;
  size >>= 1;
 }
 if (size < 16) {
  tt_size = 0;
  return 0;
 }
 tt_size = (size / sizeof(TranspositionTable)) -1;
 tt = (struct TranspositionTable *) malloc(size);
 return 1;
}

variable_types: size int

variable_types: i int

user_defined_types: struct TranspositionTable { unsigned long hash; int val; unsigned short depth; unsigned short flag; }


decompiled_code:
__int64 __fastcall tt_init(int a1)
{
unsigned __int64 v1; // rbp
_QWORD *v2; // rbx
unsigned __int64 v3; // rbx
unsigned __int64 v4; // rbx
__int64 result; // rax

v1 = (unsigned int)((_DWORD)zobrist + 512);
do
{
v2 = (_QWORD *)(v1 - 512);
do
*v2++ = rand64();
while ( v2 != (_QWORD *)v1 );
v1 += 512LL;
}
while ( v1 != (_DWORD)zobrist + 6656 );
zobrist[768] = rand64();
v3 = (unsigned int)((_DWORD)zobrist + 6152);
do
{
*(_QWORD *)v3 = rand64();
v3 += 8LL;
}
while ( v3 != (_DWORD)zobrist + 6280 );
v4 = (unsigned int)((_DWORD)zobrist + 6280);
do
{
*(_QWORD *)v4 = rand64();
v4 += 8LL;
}
while ( (_DWORD)zobrist + 6792 != v4 );
result = tt_setsize(a1);
if ( !(_DWORD)result )
{
puts("Transpostion Table not initialized");
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned __int64 v1; // rbp
_QWORD *v2; // rbx
unsigned __int64 v3; // rbx
unsigned __int64 v4; // rbx
__int64 result; // rax

v1 = (unsigned int)((_DWORD)zobrist + 512);
do
{
v2 = (_QWORD *)(v1 - 512);
do
*v2++ = rand64();
while ( v2 != (_QWORD *)v1 );
v1 += 512LL;
}
while ( v1 != (_DWORD)zobrist + 6656 );
zobrist[768] = rand64();
v3 = (unsigned int)((_DWORD)zobrist + 6152);
do
{
*(_QWORD *)v3 = rand64();
v3 += 8LL;
}
while ( v3 != (_DWORD)zobrist + 6280 );
v4 = (unsigned int)((_DWORD)zobrist + 6280);
do
{
*(_QWORD *)v4 = rand64();
v4 += 8LL;
}
while ( (_DWORD)zobrist + 6792 != v4 );
result = func0(a1);
if ( !(_DWORD)result )
{
puts("Transpostion Table not initialized");
exit(1);
}
return result;
}

original_code:
void tt_init(int size)
{
 int p, s, castling, ep = 0;
 for (p = 0; p <= 11; p++) {
  for (s = 0; s <= 63; s++) {
   zobrist.piecesquare[p][s] = rand64();
  }
 }
 zobrist.side = rand64();
 for (castling = 0; castling <= 15; castling++) {
  zobrist.castling[castling] = rand64();
 }
 for (ep = 0; ep <= 63; ep++) {
  zobrist.ep[ep] = rand64();
 }
 if (!tt_setsize(size)) {
  printf("Transpostion Table not initialized\n");
  exit(1);
 }
}

canonical_original_code:
void tt_init(int size)
{
 int p; int s; int castling; int ep = 0;
 for (p = 0; p <= 11; p++) {
  for (s = 0; s <= 63; s++) {
   zobrist.piecesquare[p][s] = rand64();
  }
 }
 zobrist.side = rand64();
 for (castling = 0; castling <= 15; castling++) {
  zobrist.castling[castling] = rand64();
 }
 for (ep = 0; ep <= 63; ep++) {
  zobrist.ep[ep] = rand64();
 }
 if (!tt_setsize(size)) {
  printf("Transpostion Table not initialized\n");
  exit(1);
 }
}

variable_types: p int

variable_types: s int

variable_types: castling int

variable_types: ep int


decompiled_code:
unsigned __int64 __fastcall tt_save(__int64 a1, int a2, unsigned __int16 a3, __int16 a4)
{
unsigned __int64 result; // rax

result = (unsigned int)tt_size;
if ( tt_size )
{
result = (unsigned __int64)tt + 16 * (a1 & tt_size);
if ( *(_QWORD *)result != a1 || *(_WORD *)(result + 12) <= a3 )
{
*(_QWORD *)result = a1;
*(_DWORD *)(result + 8) = a2;
*(_WORD *)(result + 12) = a3;
*(_WORD *)(result + 14) = a4;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, int a2, unsigned __int16 a3, __int16 a4)
{
unsigned __int64 result; // rax

result = (unsigned int)tt_size;
if ( tt_size )
{
result = (unsigned __int64)tt + 16 * (a1 & tt_size);
if ( *(_QWORD *)result != a1 || *(_WORD *)(result + 12) <= a3 )
{
*(_QWORD *)result = a1;
*(_DWORD *)(result + 8) = a2;
*(_WORD *)(result + 12) = a3;
*(_WORD *)(result + 14) = a4;
}
}
return result;
}

original_code:
void tt_save(U64 hash, int val, U16 depth, U16 flag)
{
 if (!tt_size) return;
 TranspositionTable * entry = &tt[hash & tt_size];
 if ((entry->hash == hash) && (entry->depth > depth)) return;
 entry->hash = hash;
 entry->val = val;
 entry->depth = depth;
 entry->flag = flag;
}

canonical_original_code:
void tt_save(unsigned long hash, int val, unsigned short depth, unsigned short flag)
{
 if (!tt_size) return;
 struct TranspositionTable *entry = &tt[hash & tt_size];
 if ((entry->hash == hash) && (entry->depth > depth)) return;
 entry->hash = hash;
 entry->val = val;
 entry->depth = depth;
 entry->flag = flag;
}

variable_types:
hash
unsigned long

variable_types:
depth
unsigned short

variable_types:
flag
unsigned short

variable_types: struct TranspositionTable { unsigned long hash; int val; unsigned short depth; unsigned short flag; } *


original_code:
int tt_probe(U64 hash, int alpha, int beta, U16 depth)
{
 if (!tt_size) return 0;
 TranspositionTable * entry = &tt[hash & tt_size];
 if ((hash == entry->hash) && (entry->depth >= depth)) {
  if (entry->flag == TT_EXACT) {
   return entry->val;
  }
  if ((entry->flag == TT_ALPHA) && (entry->val <= alpha)) {
   return alpha;
  }
  if ((entry->flag == TT_BETA) && (entry->val >= beta)) {
   return beta;
  }
 }
 return 0;
}

canonical_original_code:
int tt_probe(unsigned long hash, int alpha, int beta, unsigned short depth)
{
 if (!tt_size) return 0;
 struct TranspositionTable *entry = &tt[hash & tt_size];
 if ((hash == entry->hash) && (entry->depth >= depth)) {
  if (entry->flag == TT_EXACT) {
   return entry->val;
  }
  if ((entry->flag == TT_ALPHA) && (entry->val <= alpha)) {
   return alpha;
  }
  if ((entry->flag == TT_BETA) && (entry->val >= beta)) {
   return beta;
  }
 }
 return 0;
}

variable_types: alpha int

variable_types: beta int


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

result = (unsigned int)tt_size;
if ( tt_size )
{
result = (unsigned __int64)tt + 16 * (a1 & tt_size);
if ( *(_QWORD *)result != a1 || *(unsigned __int16 *)(result + 12) == a3 )
{
*(_QWORD *)result = a1;
*(_DWORD *)(result + 8) = a2;
*(_WORD *)(result + 12) = a3;
}
}
return result;
}

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

result = (unsigned int)tt_size;
if ( tt_size )
{
result = (unsigned __int64)tt + 16 * (a1 & tt_size);
if ( *(_QWORD *)result != a1 || *(unsigned __int16 *)(result + 12) == a3 )
{
*(_QWORD *)result = a1;
*(_DWORD *)(result + 8) = a2;
*(_WORD *)(result + 12) = a3;
}
}
return result;
}

original_code:
void tt_perft_save(U64 hash, int data, int depth)
{
 if (!tt_size) return;
 TranspositionTable * entry = &tt[hash & tt_size];
 if ((entry->hash == hash) && (entry->depth != depth)) return;
 entry->hash = hash;
 entry->val = data;
 entry->depth = depth;
}

canonical_original_code:
void tt_perft_save(unsigned long hash, int data, int depth)
{
 if (!tt_size) return;
 struct TranspositionTable *entry = &tt[hash & tt_size];
 if ((entry->hash == hash) && (entry->depth != depth)) return;
 entry->hash = hash;
 entry->val = data;
 entry->depth = depth;
}

variable_types: data int

variable_types: depth int


decompiled_code:
__int64 __fastcall tt_perft_probe(__int64 a1, int a2)
{
unsigned int v2; // edx
char *v3; // rax

v2 = tt_size;
if ( tt_size )
{
v3 = (char *)tt + 16 * (a1 & tt_size);
v2 = 0;
if ( *(_QWORD *)v3 == a1 && *((unsigned __int16 *)v3 + 6) == a2 )
v2 = *((_DWORD *)v3 + 2);
}
return v2;
}

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

v2 = tt_size;
if ( tt_size )
{
v3 = (char *)tt + 16 * (a1 & tt_size);
v2 = 0;
if ( *(_QWORD *)v3 == a1 && *((unsigned __int16 *)v3 + 6) == a2 )
v2 = *((_DWORD *)v3 + 2);
}
return v2;
}

original_code:
int tt_perft_probe(U64 hash, int depth)
{
 if (!tt_size) return 0;
 TranspositionTable * entry = &tt[hash & tt_size];
 if (hash == entry->hash && (entry->depth == depth)) {
  return entry->val;
 }
 return 0;
}

canonical_original_code:
int tt_perft_probe(unsigned long hash, int depth)
{
 if (!tt_size) return 0;
 struct TranspositionTable *entry = &tt[hash & tt_size];
 if (hash == entry->hash && (entry->depth == depth)) {
  return entry->val;
 }
 return 0;
}


charToInt

decompiled_code:
__int64 __fastcall charToInt(char a1)
{
char nptr[10]; // [rsp+Eh] [rbp-Ah] BYREF

nptr[0] = a1;
nptr[1] = 0;
return strtol(nptr, 0LL, 10);
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
char nptr[10]; // [rsp+Eh] [rbp-Ah] BYREF

nptr[0] = a1;
nptr[1] = 0;
return strtol(nptr, 0LL, 10);
}

original_code:
int charToInt(char d)
{
 char str[2];
 str[0] = d;
 str[1] = '\0';
 return (int) strtol(str, ((void *)0), 10);
}

variable_types: d char

variable_types:
str
char [2]


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

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

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

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

original_code:
List * list_init()
{
 List *list = malloc(sizeof(List));
 list->first = ((void *)0);
 return list;
}

canonical_original_code:
struct List *list_init()
{
 struct List *list = malloc(sizeof(List));
 list->first = ((void *)0);
 return list;
}

variable_types: struct List { int sizeOfData; struct s_ListItem { void *data; struct s_ListItem *next; } *first; } *

user_defined_types: struct List { int sizeOfData; struct s_ListItem *first; }


decompiled_code:
__int64 __fastcall list_append(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
_QWORD *v3; // rax
_QWORD *v4; // rdx
__int64 result; // rax

if ( !a1 )
_assert_fail("list != NULL", "src/util.c", 0x36u, "list_append");
v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
{
v3 = malloc(0x10uLL);
v4 = v3;
if ( !v3 )
exit(1);
*v3 = a2;
v3[1] = 0LL;
do
{
result = v2;
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
*(_QWORD *)(result + 8) = v4;
}
else
{
list_prepend(a1, a2);
result = *(_QWORD *)(a1 + 8);
if ( *(_QWORD *)(result + 8) )
_assert_fail("list->first->next == NULL", "src/util.c", 0x39u, "list_append");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
_QWORD *v3; // rax
_QWORD *v4; // rdx
__int64 result; // rax

if ( !a1 )
_assert_fail("list != NULL", "src/util.c", 0x36u, "list_append");
v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
{
v3 = malloc(0x10uLL);
v4 = v3;
if ( !v3 )
exit(1);
*v3 = a2;
v3[1] = 0LL;
do
{
result = v2;
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
*(_QWORD *)(result + 8) = v4;
}
else
{
list_prepend(a1, a2);
result = *(_QWORD *)(a1 + 8);
if ( *(_QWORD *)(result + 8) )
_assert_fail("list->first->next == NULL", "src/util.c", 0x39u, "list_append");
}
return result;
}

original_code:
void list_append(List *list, void *data)
{
 ((list != ((void *)0)) ? (void) (0) : __assert_fail ("list != NULL", "src/util.c", 54, __extension__ __PRETTY_FUNCTION__));
 if (!list->first) {
  list_prepend(list, data);
  ((list->first->next == ((void *)0)) ? (void) (0) : __assert_fail ("list->first->next == NULL", "src/util.c", 57, __extension__ __PRETTY_FUNCTION__));
  return;
 }
 ListItem *item = malloc(sizeof(ListItem));
 ListItem *current = list->first;
 ListItem *last = ((void *)0);
 if (item == ((void *)0)) {
  exit(1);
 }
 item->data = data;
 item->next = ((void *)0);
 while (current != ((void *)0)){
  if (!current->next) {
   last = current;
  }
  current = current->next;
 }
 last->next = item;
}

canonical_original_code:
void list_append(struct List *list, void *data)
{
 ((list != ((void *)0)) ? (void) (0) : __assert_fail ("list != NULL", "src/util.c", 54, __extension__ __PRETTY_FUNCTION__));
 if (!list->first) {
  list_prepend(list, data);
  ((list->first->next == ((void *)0)) ? (void) (0) : __assert_fail ("list->first->next == NULL", "src/util.c", 57, __extension__ __PRETTY_FUNCTION__));
  return;
 }
 struct s_ListItem *item = malloc(sizeof(ListItem));
 struct s_ListItem *current = list->first;
 struct s_ListItem *last = ((void *)0);
 if (item == ((void *)0)) {
  exit(1);
 }
 item->data = data;
 item->next = ((void *)0);
 while (current != ((void *)0)){
  if (!current->next) {
   last = current;
  }
  current = current->next;
 }
 last->next = item;
}

variable_types:
data
void *

variable_types: struct s_ListItem { void *data; struct s_ListItem *next; } *


decompiled_code:
__int64 __fastcall list_len(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
return v2;
}

original_code:
int list_len(List *list) {
 int count = 0;
 ListItem *item = list->first;
 while (item != ((void *)0)){
  count++;
  item = item->next;
 }
 return count;
}

canonical_original_code:
int list_len(struct List *list) {
 int count = 0;
 struct s_ListItem *item = list->first;
 while (item != ((void *)0)){
  count++;
  item = item->next;
 }
 return count;
}

variable_types: count int

user_defined_types: struct s_ListItem { void *data; struct s_ListItem *next; }


decompiled_code:
void __fastcall list_destroy(void *ptr)
{
__int64 i; // rbx

if ( !ptr )
exit(1);
for ( i = *((_QWORD *)ptr + 1); i; i = *((_QWORD *)ptr + 1) )
{
*((_QWORD *)ptr + 1) = *(_QWORD *)(i + 8);
free(*(void **)i);
free((void *)i);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
__int64 i; // rbx

if ( !ptr )
exit(1);
for ( i = *((_QWORD *)ptr + 1); i; i = *((_QWORD *)ptr + 1) )
{
*((_QWORD *)ptr + 1) = *(_QWORD *)(i + 8);
free(*(void **)i);
free((void *)i);
}
free(ptr);
}

original_code:
void list_destroy(List *list)
{
 if (list == ((void *)0)) {
  exit(1);
 }
 while (list->first != ((void *)0)){
  ListItem *first = list->first;
  list->first = list->first->next;
  free(first->data);
  free(first);
 }
 free(list);
}

canonical_original_code:
void list_destroy(struct List *list)
{
 if (list == ((void *)0)) {
  exit(1);
 }
 while (list->first != ((void *)0)){
  struct s_ListItem *first = list->first;
  list->first = list->first->next;
  free(first->data);
  free(first);
 }
 free(list);
}


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

result = 113LL;
if ( (a1 & 0x10) == 0 )
{
result = 98LL;
if ( (a1 & 0x20) == 0 )
{
result = 114LL;
if ( a1 >= 0 )
result = (a1 & 0x40) == 0 ? 32 : 110;
}
}
return result;
}

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

result = 113LL;
if ( (a1 & 0x10) == 0 )
{
result = 98LL;
if ( (a1 & 0x20) == 0 )
{
result = 114LL;
if ( a1 >= 0 )
result = (a1 & 0x40) == 0 ? 32 : 110;
}
}
return result;
}

original_code:
char move_getPromotionPieceChar(U8 flags)
{
 if (flags & 0x10) {
  return 'q';
 }
 if (flags & 0x20) {
  return 'b';
 }
 if (flags & 0x80) {
  return 'r';
 }
 if (flags & 0x40) {
  return 'n';
 }
 return ' ';
}

canonical_original_code:
char move_getPromotionPieceChar(unsigned char flags)
{
 if (flags & 0x10) {
  return 'q';
 }
 if (flags & 0x20) {
  return 'b';
 }
 if (flags & 0x80) {
  return 'r';
 }
 if (flags & 0x40) {
  return 'n';
 }
 return ' ';
}

variable_types:
flags
unsigned char

return_type: char


decompiled_code:
int __fastcall move_displayAlg(char *a1)
{
unsigned int v1; // er13
const char *v2; // r12
unsigned int v3; // ebp
const char *v4; // rax

v1 = (char)move_getPromotionPieceChar(a1[8]);
v2 = (const char *)bitboard_binToAlg(1LL << a1[11]);
v3 = (*((_WORD *)a1 + 4) & 4) == 0 ? 45 : 120;
v4 = (const char *)bitboard_binToAlg(1LL << a1[10]);
return printf("%s%c%s%c", v4, v3, v2, v1);
}

canonical_decompiled_code:
int __fastcall func1(char *a1)
{
unsigned int v1; // er13
const char *v2; // r12
unsigned int v3; // ebp
const char *v4; // rax

v1 = (char)func0(a1[8]);
v2 = (const char *)bitboard_binToAlg(1LL << a1[11]);
v3 = (*((_WORD *)a1 + 4) & 4) == 0 ? 45 : 120;
v4 = (const char *)bitboard_binToAlg(1LL << a1[10]);
return printf("%s%c%s%c", v4, v3, v2, v1);
}

original_code:
void move_displayAlg(Move *move)
{
 printf("%s%c%s%c", bitboard_binToAlg(((1UL) << (move->from))),
      (move->flags & 0x4) ? 'x' : '-',
      bitboard_binToAlg(((1UL) << (move->to))),
      move_getPromotionPieceChar(move->flags));
}

canonical_original_code:
void move_displayAlg(struct Move *move)
{
 printf("%s%c%s%c", bitboard_binToAlg(((1UL) << (move->from))),
      (move->flags & 0x4) ? 'x' : '-',
      bitboard_binToAlg(((1UL) << (move->to))),
      move_getPromotionPieceChar(move->flags));
}

variable_types: struct Move { unsigned int score; unsigned int padding; unsigned short flags; unsigned char from; unsigned char to; unsigned char captured_piece; unsigned char ep; unsigned char castling_rights; } *


repo: iliastsi/fibheap

decompiled_code:
__int64 __fastcall my_compare(_DWORD *a1, _DWORD *a2)
{
return 2 * (unsigned int)(*a2 < *a1) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _DWORD *a2)
{
return 2 * (unsigned int)(*a2 < *a1) - 1;
}

original_code:
int my_compare(struct fib_heap_data *old, struct fib_heap_data *new)
{
 if(new->key < old->key)
  return 1;
 else
  return -1;
}

variable_types:
old
struct fib_heap_data { int key; } *

variable_types:
new
struct fib_heap_data *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbp
_DWORD *v4; // r15
_DWORD *v5; // r14
_DWORD *v6; // r13
_DWORD *v7; // r12
__int64 v8; // rbx
_DWORD **v9; // rbp
unsigned int *v10; // r14
unsigned int *v11; // rbp
unsigned int *v12; // rbp
unsigned int *v13; // rbp
_DWORD *v15; // [rsp+0h] [rbp-48h]
_DWORD *v16; // [rsp+8h] [rbp-40h]

v3 = construct(7);
v4 = construct(15);
v5 = construct(5);
v6 = construct(20);
v7 = construct(2);
v15 = construct(7);
v16 = construct(10);
v8 = fibheap_init(7LL, my_compare);
v9 = (_DWORD **)fibheap_insert(v8, v3);
fibheap_insert(v8, v4);
fibheap_insert(v8, v5);
v10 = (unsigned int *)fibheap_extract(v8);
printf("%d\n", *v10);
free(v10);
fibheap_insert(v8, v6);
fibheap_insert(v8, v7);
fibheap_insert(v8, v15);
fibheap_insert(v8, v16);
**v9 = 8;
fibheap_decrease(v8, v9);
v11 = (unsigned int *)fibheap_extract(v8);
printf("%d\n", *v11);
free(v11);
v12 = (unsigned int *)fibheap_extract(v8);
printf("%d\n", *v12);
free(v12);
v13 = (unsigned int *)fibheap_extract(v8);
printf("%d\n", *v13);
free(v13);
fibheap_destroy(v8);
return 0;
}

original_code:
int main()
{
 struct fib_heap_data *fdata[10];
 struct fib_heap_data *ret;
 struct fib_heap *H;
 struct fib_heap_node *node;
 fdata[0] = construct(7);
 fdata[1] = construct(15);
 fdata[2] = construct(5);
 fdata[3] = construct(20);
 fdata[4] = construct(2);
 fdata[5] = construct(7);
 fdata[6] = construct(10);
 H = fibheap_init(7, my_compare);
 node = fibheap_insert(H, fdata[0]);
 fibheap_insert(H, fdata[1]);
 fibheap_insert(H, fdata[2]);
 ret = fibheap_extract(H);
 printf("%d\n", ret->key);
 free(ret);
 fibheap_insert(H, fdata[3]);
 fibheap_insert(H, fdata[4]);
 fibheap_insert(H, fdata[5]);
 fibheap_insert(H, fdata[6]);
 node->data->key = 8;
 fibheap_decrease(H, node);
 ret = fibheap_extract(H);
 printf("%d\n", ret->key);
 free(ret);
 ret = fibheap_extract(H);
 printf("%d\n", ret->key);
 free(ret);
 ret = fibheap_extract(H);
 printf("%d\n", ret->key);
 free(ret);
 fibheap_destroy(H);
 return 0;
}

variable_types:
fdata
struct fib_heap_data { int key; } *[10]

variable_types:
ret
struct fib_heap_data { int key; } *

variable_types: struct fib_heap { struct fib_heap_node { struct fib_heap_data { int key; } *data; unsigned int degree; char marked; struct fib_heap_node *parent; struct fib_heap_node *child; struct fib_heap_node *left; struct fib_heap_node *right; } *the_one; struct fib_heap_node **cons_array; int (*compr)(struct fib_heap_data *, struct fib_heap_data *); unsigned int total_nodes; unsigned int max_nodes; } *

user_defined_types: struct fib_heap { struct fib_heap_node *the_one; struct fib_heap_node **cons_array; int (*compr)(struct fib_heap_data *, struct fib_heap_data *); unsigned int total_nodes; unsigned int max_nodes; }

user_defined_types: struct fib_heap_node { struct fib_heap_data *data; unsigned int degree; char marked; struct fib_heap_node *parent; struct fib_heap_node *child; struct fib_heap_node *left; struct fib_heap_node *right; }


original_code:
static void
fibheap_link(struct fib_heap_node *y, struct fib_heap_node *x)
{
 struct fib_heap_node *temp;
 y->left->right = y->right;
 y->right->left = y->left;
 y->parent = x;
 if(x->child == ((void *)0)) {
  x->child = y;
  y->left = y;
  y->right = y;
 } else {
  temp = x->child->right;
  x->child->right = y;
  y->left = x->child;
  temp->left = y;
  y->right = temp;
 }
 (x->degree)++;
 y->marked = 0;
}

variable_types: struct fib_heap_node { struct fib_heap_data { int key; } *data; unsigned int degree; char marked; struct fib_heap_node *parent; struct fib_heap_node *child; struct fib_heap_node *left; struct fib_heap_node *right; } *

variable_types:
x
struct fib_heap_node *


decompiled_code:
__int64 __fastcall dblink_list_concat(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

if ( !a1 )
{
fprintf(stderr, "fib_heap.c: %s\n", "dblink_list_concat: a==NULL");
exit(1);
}
if ( !a2 )
{
fprintf(stderr, "fib_heap.c: %s\n", "dblink_list_concat: b==NULL");
exit(1);
}
result = *(_QWORD *)(a1 + 40);
v3 = *(_QWORD *)(a2 + 40);
*(_QWORD *)(a1 + 40) = v3;
*(_QWORD *)(v3 + 32) = a1;
*(_QWORD *)(a2 + 40) = result;
*(_QWORD *)(result + 32) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

if ( !a1 )
{
fprintf(stderr, "fib_heap.c: %s\n", "dblink_list_concat: a==NULL");
exit(1);
}
if ( !a2 )
{
fprintf(stderr, "fib_heap.c: %s\n", "dblink_list_concat: b==NULL");
exit(1);
}
result = *(_QWORD *)(a1 + 40);
v3 = *(_QWORD *)(a2 + 40);
*(_QWORD *)(a1 + 40) = v3;
*(_QWORD *)(v3 + 32) = a1;
*(_QWORD *)(a2 + 40) = result;
*(_QWORD *)(result + 32) = a2;
return result;
}

original_code:
static void
dblink_list_concat(struct fib_heap_node *a, struct fib_heap_node *b)
{
 struct fib_heap_node *temp;
 ({ if(!(a != ((void *)0))) { fprintf(stderr, "fib_heap.c: %s\n", ("dblink_list_concat: a==NULL")); exit(1); }; });
 ({ if(!(b != ((void *)0))) { fprintf(stderr, "fib_heap.c: %s\n", ("dblink_list_concat: b==NULL")); exit(1); }; });
 temp = a->right;
 a->right = b->right;
 b->right->left = a;
 b->right = temp;
 temp->left = b;
}

variable_types:
b
struct fib_heap_node *


decompiled_code:
__int64 __fastcall fibheap_casc_cut(__int64 *a1, __int64 a2)
{
__int64 v2; // rbp
__int64 result; // rax

v2 = *(_QWORD *)(a2 + 16);
if ( v2 )
{
if ( *(_BYTE *)(a2 + 12) )
{
fibheap_cut(a1, a2, *(_QWORD *)(a2 + 16));
result = fibheap_casc_cut(a1, v2);
}
else
{
*(_BYTE *)(a2 + 12) = 1;
}
}
return result;
}

original_code:
static void
fibheap_casc_cut(struct fib_heap *H, struct fib_heap_node *y)
{
 struct fib_heap_node *z = y->parent;
 if(z == ((void *)0))
  return;
 if(!(y->marked)) {
  y->marked = 1;
  return;
 }
 fibheap_cut(H, y, z);
 return fibheap_casc_cut(H, z);
}

variable_types:
y
struct fib_heap_node *


original_code:
static void
fibheap_consolidate(struct fib_heap *H)
{
 unsigned int D;
 unsigned int i, d;
 struct fib_heap_node *x, *w, *y, *temp, *new_one;
 if(H->total_nodes == 0U) {
  free(H->the_one);
  H->the_one = ((void *)0);
  return;
 }
 D = ({ unsigned int _i = 0; __asm__("bsr %1, %0" : "=r" (_i) : "r" ((H->total_nodes))); _i; });
 for(i=0U;i<=D;i++)
  H->cons_array[i] = ((void *)0);
 w = H->the_one->right;
 new_one = w;
 while(w != H->the_one) {
  x = w;
  d = x->degree;
  while((d<=D) && (H->cons_array[d]!=((void *)0))) {
   y = H->cons_array[d];
   if((H->compr)(x->data, y->data) > 0) {
    temp = x;
    x = y;
    y = temp;
   }
   if(w == y)
    w = w->left;
   fibheap_link(y, x);
   H->cons_array[d] = ((void *)0);
   d++;
  }
  H->cons_array[d] = x;
  if((H->compr)(x->data, new_one->data) <= 0)
   new_one = x;
  w = w->right;
 }
 H->the_one->left->right = H->the_one->right;
 H->the_one->right->left = H->the_one->left;
 free(H->the_one);
 H->the_one = new_one;
}

canonical_original_code:
static void fibheap_consolidate(struct fib_heap *H)
{
 unsigned int D;
 unsigned int i; unsigned int d;
 struct fib_heap_node *x; struct fib_heap_node *w; struct fib_heap_node *y; struct fib_heap_node *temp; struct fib_heap_node *new_one;
 if(H->total_nodes == 0U) {
  free(H->the_one);
  H->the_one = ((void *)0);
  return;
 }
 D = ({ unsigned int _i = 0; __asm__("bsr %1, %0" : "=r" (_i) : "r" ((H->total_nodes))); _i; });
 for(i=0U;i<=D;i++)
  H->cons_array[i] = ((void *)0);
 w = H->the_one->right;
 new_one = w;
 while(w != H->the_one) {
  x = w;
  d = x->degree;
  while((d<=D) && (H->cons_array[d]!=((void *)0))) {
   y = H->cons_array[d];
   if((H->compr)(x->data, y->data) > 0) {
    temp = x;
    x = y;
    y = temp;
   }
   if(w == y)
    w = w->left;
   fibheap_link(y, x);
   H->cons_array[d] = ((void *)0);
   d++;
  }
  H->cons_array[d] = x;
  if((H->compr)(x->data, new_one->data) <= 0)
   new_one = x;
  w = w->right;
 }
 H->the_one->left->right = H->the_one->right;
 H->the_one->right->left = H->the_one->left;
 free(H->the_one);
 H->the_one = new_one;
}

variable_types:
D
unsigned int

variable_types:
i
unsigned int

variable_types:
d
unsigned int


decompiled_code:
void __fastcall fibheap_destroy_rec(__int64 a1)
{
__int64 v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
fibheap_destroy_rec(*(_QWORD *)(v1 + 24));
v1 = *(_QWORD *)(v1 + 40);
free(**(void ***)(v1 + 32));
free(*(void **)(v1 + 32));
}
while ( a1 != v1 );
}
}

original_code:
static void
fibheap_destroy_rec(struct fib_heap_node *node)
{
 struct fib_heap_node *start = node;
 if(node == ((void *)0))
  return;
 do {
  fibheap_destroy_rec(node->child);
  node = node->right;
  free(node->left->data);
  free(node->left);
 } while(node != start);
}


decompiled_code:
__int64 __fastcall fibheap_read(__int64 a1)
{
if ( !a1 )
{
fprintf(stderr, "fib_heap.c: %s\n", "fibheap_read: H==NULL");
exit(1);
}
return **(_QWORD **)a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
if ( !a1 )
{
fprintf(stderr, "fib_heap.c: %s\n", "fibheap_read: H==NULL");
exit(1);
}
return **(_QWORD **)a1;
}

original_code:
struct fib_heap_data *
fibheap_read(struct fib_heap *H)
{
 ({ if(!(H != ((void *)0))) { fprintf(stderr, "fib_heap.c: %s\n", ("fibheap_read: H==NULL")); exit(1); }; });
 return (H->the_one->data);
}

canonical_original_code:
struct fib_heap_data *fibheap_read(struct fib_heap *H)
{
 ({ if(!(H != ((void *)0))) { fprintf(stderr, "fib_heap.c: %s\n", ("fibheap_read: H==NULL")); exit(1); }; });
 return (H->the_one->data);
}

variable_types: struct fib_heap { struct fib_heap_node { struct fib_heap_data *data; unsigned int degree; char marked; struct fib_heap_node *parent; struct fib_heap_node *child; struct fib_heap_node *left; struct fib_heap_node *right; } *the_one; struct fib_heap_node **cons_array; int (*compr)(struct fib_heap_data *, struct fib_heap_data *); unsigned int total_nodes; unsigned int max_nodes; } *

return_type: struct fib_heap_data { int key; } *


decompiled_code:
__int64 __fastcall fibheap_extract(void **a1)
{
__int64 v2; // rdi
__int64 v3; // rbp
unsigned int v4; // eax
__int64 v5; // rsi

if ( !a1 )
{
fprintf(stderr, "fib_heap.c: %s\n", "fibheap_extract: H==NULL");
exit(1);
}
v2 = (__int64)*a1;
if ( !v2 )
return 0LL;
v3 = *(_QWORD *)v2;
if ( *(_DWORD *)(v2 + 8) )
{
v4 = 0;
do
{
*(_QWORD *)(*(_QWORD *)(v2 + 24) + 16LL) = 0LL;
*((_QWORD *)*a1 + 3) = *(_QWORD *)(*((_QWORD *)*a1 + 3) + 40LL);
++v4;
v2 = (__int64)*a1;
}
while ( *((_DWORD *)*a1 + 2) > v4 );
}
v5 = *(_QWORD *)(v2 + 24);
if ( v5 )
dblink_list_concat(v2, v5);
--*((_DWORD *)a1 + 6);
fibheap_consolidate(a1);
return v3;
}

original_code:
struct fib_heap_data *
fibheap_extract(struct fib_heap *H)
{
 struct fib_heap_data *ret;
 unsigned int i;
 ({ if(!(H != ((void *)0))) { fprintf(stderr, "fib_heap.c: %s\n", ("fibheap_extract: H==NULL")); exit(1); }; });
 if(H->the_one == ((void *)0))
  return ((void *)0);
 ret = H->the_one->data;
 for(i=0U;i<H->the_one->degree;i++) {
  H->the_one->child->parent = ((void *)0);
  H->the_one->child = H->the_one->child->right;
 }
 if(H->the_one->child != ((void *)0))
  dblink_list_concat(H->the_one, H->the_one->child);
 (H->total_nodes)--;
 fibheap_consolidate(H);
 return ret;
}

canonical_original_code:
struct fib_heap_data *fibheap_extract(struct fib_heap *H)
{
 struct fib_heap_data *ret;
 unsigned int i;
 ({ if(!(H != ((void *)0))) { fprintf(stderr, "fib_heap.c: %s\n", ("fibheap_extract: H==NULL")); exit(1); }; });
 if(H->the_one == ((void *)0))
  return ((void *)0);
 ret = H->the_one->data;
 for(i=0U;i<H->the_one->degree;i++) {
  H->the_one->child->parent = ((void *)0);
  H->the_one->child = H->the_one->child->right;
 }
 if(H->the_one->child != ((void *)0))
  dblink_list_concat(H->the_one, H->the_one->child);
 (H->total_nodes)--;
 fibheap_consolidate(H);
 return ret;
}