main

canonical_name: main

repo: piwai/qmail-helo-check-plugin

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
char *v4; // rbp
__int64 v5; // rcx
struct addrinfo *v6; // rdi
int v7; // eax
struct addrinfo *v8; // rbx
const char *v10; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
char buf[16]; // [rsp+10h] [rbp-58h] BYREF
struct addrinfo req; // [rsp+20h] [rbp-48h] BYREF

v3 = getenv("SMTPHELOHOST");
v4 = getenv("TCPREMOTEIP");
openlog("qmail-helo", 1, 128);
if ( v3 )
{
if ( (unsigned int)check_whitelisted(v3) )
{
allow(v4, v3, "Whitelisted");
}
else
{
v5 = 12LL;
v6 = &req;
while ( v5 )
{
v6->ai_flags = 0;
v6 = (struct addrinfo *)((char *)v6 + 4);
--v5;
}
*(_QWORD *)&req.ai_family = 0x100000002LL;
v7 = getaddrinfo(v3, 0LL, &req, &pai);
if ( v7 )
{
if ( v7 == -3 )
{
allow(v4, v3, "temporary DNS failure");
}
else
{
v10 = gai_strerror(v7);
block(v4, v3, v10);
}
}
else
{
v8 = pai;
if ( pai )
{
while ( 1 )
{
inet_ntop(v8->ai_family, &v8->ai_addr->sa_data[2], buf, 0x10u);
if ( !strncmp(buf, v4, 0x10uLL) )
break;
v8 = v8->ai_next;
if ( !v8 )
goto LABEL_16;
}
allow(v4, v3, "DNS record match");
}
else
{
LABEL_16:
add_header(v4, v3, "DNS mismatch");
}
}
}
}
else
{
block(v4, 0LL, "no HELO/EHLO hostname has been sent");
}
closelog();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
char *v4; // rbp
__int64 v5; // rcx
struct addrinfo *v6; // rdi
int v7; // eax
struct addrinfo *v8; // rbx
const char *v10; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
char buf[16]; // [rsp+10h] [rbp-58h] BYREF
struct addrinfo req; // [rsp+20h] [rbp-48h] BYREF

v3 = getenv("SMTPHELOHOST");
v4 = getenv("TCPREMOTEIP");
openlog("qmail-helo", 1, 128);
if ( v3 )
{
if ( (unsigned int)func10(v3) )
{
func9(v4, v3, "Whitelisted");
}
else
{
v5 = 12LL;
v6 = &req;
while ( v5 )
{
v6->ai_flags = 0;
v6 = (struct addrinfo *)((char *)v6 + 4);
--v5;
}
*(_QWORD *)&req.ai_family = 0x100000002LL;
v7 = getaddrinfo(v3, 0LL, &req, &pai);
if ( v7 )
{
if ( v7 == -3 )
{
func9(v4, v3, "temporary DNS failure");
}
else
{
v10 = gai_strerror(v7);
func7(v4, v3, v10);
}
}
else
{
v8 = pai;
if ( pai )
{
while ( 1 )
{
inet_ntop(v8->ai_family, &v8->ai_addr->sa_data[2], buf, 0x10u);
if ( !strncmp(buf, v4, 0x10uLL) )
break;
v8 = v8->ai_next;
if ( !v8 )
goto LABEL_16;
}
func9(v4, v3, "DNS record match");
}
else
{
LABEL_16:
func8(v4, v3, "DNS mismatch");
}
}
}
}
else
{
func7(v4, 0LL, "no HELO/EHLO hostname has been sent");
}
closelog();
return 0;
}

original_code:
int main(void) {
  char *helo_domain = getenv("SMTPHELOHOST");
  char *remote_ip = getenv("TCPREMOTEIP");
  struct addrinfo hints, *res, *result;
  char ipstr[16];
  int ret = 0;
  openlog("qmail-helo", 0x01, (16<<3));
  if (!helo_domain) {
    block(remote_ip, helo_domain, "no HELO/EHLO hostname has been sent");
    goto _end;
  }
  if (check_whitelisted(helo_domain)) {
    allow(remote_ip, helo_domain, "Whitelisted");
    goto _end;
  }
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = 2;
  hints.ai_socktype = SOCK_STREAM;
  ret = getaddrinfo(helo_domain, ((void *)0), &hints, &result);
  if (ret) {
    if (ret == -3) {
      allow(remote_ip, helo_domain, "temporary DNS failure");
    } else {
      block(remote_ip, helo_domain, gai_strerror(ret));
    }
    goto _end;
  }
  for (res = result; res != ((void *)0); res = res->ai_next) {
    struct sockaddr_in *ipv4 = (struct sockaddr_in *)res->ai_addr;
    void * addr = &(ipv4->sin_addr);
    inet_ntop(res->ai_family, addr, ipstr, sizeof(ipstr));
    if (!strncmp(ipstr, remote_ip, 16)) {
      allow(remote_ip, helo_domain, "DNS record match");
      goto _end;
    }
  }
  add_header(remote_ip, helo_domain, "DNS mismatch");
_end:
  closelog();
  return 0;
}

canonical_original_code:
int main() {
  char *helo_domain = getenv("SMTPHELOHOST");
  char *remote_ip = getenv("TCPREMOTEIP");
  struct addrinfo hints; struct addrinfo *res; struct addrinfo *result;
  char ipstr[16];
  int ret = 0;
  openlog("qmail-helo", 0x01, (16<<3));
  if (!helo_domain) {
    block(remote_ip, helo_domain, "no HELO/EHLO hostname has been sent");
    goto _end;
  }
  if (check_whitelisted(helo_domain)) {
    allow(remote_ip, helo_domain, "Whitelisted");
    goto _end;
  }
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = 2;
  hints.ai_socktype = SOCK_STREAM;
  ret = getaddrinfo(helo_domain, ((void *)0), &hints, &result);
  if (ret) {
    if (ret == -3) {
      allow(remote_ip, helo_domain, "temporary DNS failure");
    } else {
      block(remote_ip, helo_domain, gai_strerror(ret));
    }
    goto _end;
  }
  for (res = result; res != ((void *)0); res = res->ai_next) {
    struct sockaddr_in *ipv4 = (struct sockaddr_in *)res->ai_addr;
    void *addr = &(ipv4->sin_addr);
    inet_ntop(res->ai_family, addr, ipstr, sizeof(ipstr));
    if (!strncmp(ipstr, remote_ip, 16)) {
      allow(remote_ip, helo_domain, "DNS record match");
      goto _end;
    }
  }
  add_header(remote_ip, helo_domain, "DNS mismatch");
_end:
  closelog();
  return 0;
}

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
ipstr
char [16]

variable_types: ret int

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

variable_types:
addr
void *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


block

decompiled_code:
void __fastcall block(const char *a1, const char *a2, const char *a3)
{
printf("R553 sorry, %s (#5.7.1)\n", a3);
syslog(7, "ip=%s:helo=%s:block (%s)\n", a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func7(const char *a1, const char *a2, const char *a3)
{
printf("R553 sorry, %s (#5.7.1)\n", a3);
syslog(7, "ip=%s:helo=%s:block (%s)\n", a1, a2, a3);
}

original_code:
void block(const char *ip, const char *domain, const char *message) {
  printf("R553 sorry, %s (#5.7.1)\n", message);
  syslog(7, "ip=%s:helo=%s:block (%s)\n", ip, domain, message);
}

canonical_original_code:
void block(char *ip, char *domain, char *message) {
  printf("R553 sorry, %s (#5.7.1)\n", message);
  syslog(7, "ip=%s:helo=%s:block (%s)\n", ip, domain, message);
}

variable_types:
ip
char *

variable_types:
domain
char *

variable_types:
message
char *

return_type: void


decompiled_code:
void __fastcall add_header(const char *a1, const char *a2, const char *a3)
{
puts("HX-Spam-Flag: YES");
syslog(7, "ip=%s:helo=%s:allow,add_header (%s)\n", a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func8(const char *a1, const char *a2, const char *a3)
{
puts("HX-Spam-Flag: YES");
syslog(7, "ip=%s:helo=%s:allow,add_header (%s)\n", a1, a2, a3);
}

original_code:
void add_header(const char *ip, const char *domain, const char *message) {
  printf("HX-Spam-Flag: YES\n");
  syslog(7, "ip=%s:helo=%s:allow,add_header (%s)\n", ip, domain, message);
}

canonical_original_code:
void add_header(char *ip, char *domain, char *message) {
  printf("HX-Spam-Flag: YES\n");
  syslog(7, "ip=%s:helo=%s:allow,add_header (%s)\n", ip, domain, message);
}


allow

decompiled_code:
void __fastcall allow(const char *a1, const char *a2, const char *a3)
{
syslog(7, "ip=%s:helo=%s:allow (%s)\n", a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func9(const char *a1, const char *a2, const char *a3)
{
syslog(7, "ip=%s:helo=%s:allow (%s)\n", a1, a2, a3);
}

original_code:
void allow(const char *ip, const char *domain, const char *message) {
  syslog(7, "ip=%s:helo=%s:allow (%s)\n", ip, domain, message);
}

canonical_original_code:
void allow(char *ip, char *domain, char *message) {
  syslog(7, "ip=%s:helo=%s:allow (%s)\n", ip, domain, message);
}


usage

repo: piyus/btkernel

decompiled_code:
void __noreturn usage()
{
puts("Usage: launch_bt [<mode>]. mode=0 (none), 1 (inc_icount), 2 (shadowmem)");
exit(1);
}

canonical_decompiled_code:
void __noreturn func8()
{
puts("Usage: launch_bt [<mode>]. mode=0 (none), 1 (inc_icount), 2 (shadowmem)");
exit(1);
}

original_code:
static void
usage(void)
{
  printf("Usage: launch_bt [<mode>]. mode=0 (none), 1 (inc_icount), 2 (shadowmem)\n");
  exit(1);
}

canonical_original_code:
static void usage()
{
  printf("Usage: launch_bt [<mode>]. mode=0 (none), 1 (inc_icount), 2 (shadowmem)\n");
  exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
int v5; // er14
const char *v6; // rbp
unsigned int v7; // er12
__int64 v8; // rax
unsigned __int64 v9; // rbx
unsigned __int64 v10; // rax
_DWORD *v11; // r12
pthread_attr_t *v12; // rax
pthread_attr_t *v13; // r15
pthread_t *v14; // r13
pthread_t *v15; // rbp
pthread_t *v16; // rbx
pthread_t v17; // rdi
__int64 v19; // [rsp+8h] [rbp-930h]
char s[112]; // [rsp+10h] [rbp-928h] BYREF
cpu_set_t cpuset; // [rsp+80h] [rbp-8B8h] BYREF
char v22[2104]; // [rsp+100h] [rbp-838h] BYREF
_QWORD v23[262]; // [rsp+108h] [rbp-830h] BYREF

snprintf(s, 0x64uLL, "/dev/%s", "bt");
v3 = sysconf(84);
v4 = open(s, 0);
if ( v4 < 0 )
{
perror("unable to open dev");
return 0;
}
v5 = v4;
if ( ioctl(v4, 0x80046401uLL, (unsigned int)v3) )
{
perror("ioctl INIT_BT error");
return 0;
}
if ( argc > 1 )
{
if ( argc != 2 || (v6 = argv[1], (v7 = atoi(v6)) == 0) && strcmp(v6, "0") )
usage();
if ( ioctl(v5, 0x80046406uLL, v7) )
{
perror("ioctl BT_SET_MODE");
return 0;
}
}
if ( v3 <= 0 )
goto LABEL_21;
v8 = (unsigned int)(v3 - 1);
v9 = 0LL;
v19 = v8;
while ( 1 )
{
v11 = malloc(8uLL);
v12 = (pthread_attr_t *)malloc(0x38uLL);
v13 = v12;
if ( !v11 )
__assert_fail("arg", "launch_bt.c", 0x4Fu, "main");
*v11 = v5;
v11[1] = v9;
if ( !v12 )
__assert_fail("tattr", "launch_bt.c", 0x52u, "main");
pthread_attr_init(v12);
memset(&cpuset, 0, sizeof(cpuset));
if ( v9 <= 0x3FF )
cpuset.__bits[v9 >> 6] |= 1LL << v9;
pthread_attr_setaffinity_np(v13, 0x80uLL, &cpuset);
v14 = (pthread_t *)v22;
if ( pthread_create((pthread_t *)&v22[8 * v9], v13, start_bt, v11) )
break;
v10 = v9 + 1;
if ( v9 == v19 )
goto LABEL_18;
LABEL_11:
v9 = v10;
}
fwrite("ERROR: Creating Pthread\n", 1uLL, 0x18uLL, stderr);
v10 = v9 + 1;
if ( v9 != v19 )
goto LABEL_11;
LABEL_18:
v15 = v23;
v16 = &v23[v9];
while ( 1 )
{
v17 = *v14;
v14 = v15;
pthread_join(v17, 0LL);
if ( v15 == v16 )
break;
++v15;
}
LABEL_21:
close(v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
int v5; // er14
const char *v6; // rbp
unsigned int v7; // er12
__int64 v8; // rax
unsigned __int64 v9; // rbx
unsigned __int64 v10; // rax
_DWORD *v11; // r12
pthread_attr_t *v12; // rax
pthread_attr_t *v13; // r15
pthread_t *v14; // r13
pthread_t *v15; // rbp
pthread_t *v16; // rbx
pthread_t v17; // rdi
__int64 v19; // [rsp+8h] [rbp-930h]
char s[112]; // [rsp+10h] [rbp-928h] BYREF
cpu_set_t cpuset; // [rsp+80h] [rbp-8B8h] BYREF
char v22[2104]; // [rsp+100h] [rbp-838h] BYREF
_QWORD v23[262]; // [rsp+108h] [rbp-830h] BYREF

snprintf(s, 0x64uLL, "/dev/%s", "bt");
v3 = sysconf(84);
v4 = open(s, 0);
if ( v4 < 0 )
{
perror("unable to open dev");
return 0;
}
v5 = v4;
if ( ioctl(v4, 0x80046401uLL, (unsigned int)v3) )
{
perror("ioctl INIT_BT error");
return 0;
}
if ( argc > 1 )
{
if ( argc != 2 || (v6 = argv[1], (v7 = atoi(v6)) == 0) && strcmp(v6, "0") )
func8();
if ( ioctl(v5, 0x80046406uLL, v7) )
{
perror("ioctl BT_SET_MODE");
return 0;
}
}
if ( v3 <= 0 )
goto LABEL_21;
v8 = (unsigned int)(v3 - 1);
v9 = 0LL;
v19 = v8;
while ( 1 )
{
v11 = malloc(8uLL);
v12 = (pthread_attr_t *)malloc(0x38uLL);
v13 = v12;
if ( !v11 )
__assert_fail("arg", "launch_bt.c", 0x4Fu, "main");
*v11 = v5;
v11[1] = v9;
if ( !v12 )
__assert_fail("tattr", "launch_bt.c", 0x52u, "main");
pthread_attr_init(v12);
memset(&cpuset, 0, sizeof(cpuset));
if ( v9 <= 0x3FF )
cpuset.__bits[v9 >> 6] |= 1LL << v9;
pthread_attr_setaffinity_np(v13, 0x80uLL, &cpuset);
v14 = (pthread_t *)v22;
if ( pthread_create((pthread_t *)&v22[8 * v9], v13, start_bt, v11) )
break;
v10 = v9 + 1;
if ( v9 == v19 )
goto LABEL_18;
LABEL_11:
v9 = v10;
}
fwrite("ERROR: Creating Pthread\n", 1uLL, 0x18uLL, stderr);
v10 = v9 + 1;
if ( v9 != v19 )
goto LABEL_11;
LABEL_18:
v15 = v23;
v16 = &v23[v9];
while ( 1 )
{
v17 = *v14;
v14 = v15;
pthread_join(v17, 0LL);
if ( v15 == v16 )
break;
++v15;
}
LABEL_21:
close(v5);
return 0;
}

original_code:
int
main(int argc, char **argv)
{
  pthread_t threads[255];
  char name[100];
  int fd;
  int n_procs;
  int i;
  snprintf(name, sizeof(name), "/dev/%s", "bt");
  n_procs = sysconf(_SC_NPROCESSORS_ONLN);
  fd = open(name, 00);
  if (fd < 0) {
    perror("unable to open dev");
    return 0;
  }
  if (ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (((100)) << (0 +8)) | (((1)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), n_procs) != 0) {
    perror("ioctl INIT_BT error");
    return 0;
  }
  if (argc > 1) {
    int mode;
    if (argc != 2) {
      usage();
    }
    mode = atoi(argv[1]);
    if (mode == 0 && strcmp(argv[1], "0")) {
      usage();
    }
    if (ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (((100)) << (0 +8)) | (((6)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), mode) != 0) {
      perror("ioctl BT_SET_MODE");
      return 0;
    }
  }
  for (i = 0; i < n_procs; i++) {
    int *arg = malloc(sizeof(int)*2);
    pthread_attr_t *tattr = (pthread_attr_t *)malloc(sizeof(pthread_attr_t));
    cpu_set_t cpuset;
    ((void) sizeof ((arg) ? 1 : 0), __extension__ ({ if (arg) ; else __assert_fail ("arg", "launch_bt.c", 79, __extension__ __PRETTY_FUNCTION__); }));
    *arg = fd;
    *(arg + 1) = i;
    ((void) sizeof ((tattr) ? 1 : 0), __extension__ ({ if (tattr) ; else __assert_fail ("tattr", "launch_bt.c", 82, __extension__ __PRETTY_FUNCTION__); }));
    pthread_attr_init(tattr);
    do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
    (__extension__ ({ size_t __cpu = (i); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
    pthread_attr_setaffinity_np (tattr, sizeof(cpuset), &cpuset);
    if (pthread_create(&threads[i], tattr, start_bt, arg)) {
      fprintf(stderr, "ERROR: Creating Pthread\n");
    }
  }
  for (i = 0; i < n_procs; i++) {
    pthread_join(threads[i], ((void *)0));
  }
  close(fd);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  unsigned long threads[255];
  char name[100];
  int fd;
  int n_procs;
  int i;
  snprintf(name, sizeof(name), "/dev/%s", "bt");
  n_procs = sysconf(_SC_NPROCESSORS_ONLN);
  fd = open(name, 00);
  if (fd < 0) {
    perror("unable to open dev");
    return 0;
  }
  if (ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (((100)) << (0 +8)) | (((1)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), n_procs) != 0) {
    perror("ioctl INIT_BT error");
    return 0;
  }
  if (argc > 1) {
    int mode;
    if (argc != 2) {
      usage();
    }
    mode = atoi(argv[1]);
    if (mode == 0 && strcmp(argv[1], "0")) {
      usage();
    }
    if (ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (((100)) << (0 +8)) | (((6)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), mode) != 0) {
      perror("ioctl BT_SET_MODE");
      return 0;
    }
  }
  for (i = 0; i < n_procs; i++) {
    int *arg = malloc(sizeof(int)*2);
    union pthread_attr_t *tattr = (pthread_attr_t *)malloc(sizeof(pthread_attr_t));
    struct cpu_set_t cpuset;
    ((void) sizeof ((arg) ? 1 : 0), __extension__ ({ if (arg) ; else __assert_fail ("arg", "launch_bt.c", 79, __extension__ __PRETTY_FUNCTION__); }));
    *arg = fd;
    *(arg + 1) = i;
    ((void) sizeof ((tattr) ? 1 : 0), __extension__ ({ if (tattr) ; else __assert_fail ("tattr", "launch_bt.c", 82, __extension__ __PRETTY_FUNCTION__); }));
    pthread_attr_init(tattr);
    do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
    (__extension__ ({ unsigned long __cpu = (i); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
    pthread_attr_setaffinity_np (tattr, sizeof(cpuset), &cpuset);
    if (pthread_create(&threads[i], tattr, start_bt, arg)) {
      fprintf(stderr, "ERROR: Creating Pthread\n");
    }
  }
  for (i = 0; i < n_procs; i++) {
    pthread_join(threads[i], ((void *)0));
  }
  close(fd);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
threads
unsigned long [255]

variable_types:
name
char [100]

variable_types: fd int

variable_types: i int

variable_types: mode int

variable_types:
arg
int *

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

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }

return_type: int


decompiled_code:
void *__fastcall start_bt(void *a1)
{
if ( ioctl(*(_DWORD *)a1, 0x80046403uLL, *((unsigned int *)a1 + 1)) )
{
perror("ioctl TRANSLATE_IDT error");
abort();
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
if ( ioctl(*(_DWORD *)a1, 0x80046403uLL, *((unsigned int *)a1 + 1)) )
{
perror("ioctl TRANSLATE_IDT error");
abort();
}
return 0LL;
}

variable_types:
arg
void *

variable_types: id int

return_type: void *


decompiled_code:
void *__fastcall load_native_idt(void *a1)
{
if ( ioctl(*(_DWORD *)a1, 0x80046404uLL, *((unsigned int *)a1 + 1)) )
perror("ioctl LOAD_NATIVE_IDT");
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
if ( ioctl(*(_DWORD *)a1, 0x80046404uLL, *((unsigned int *)a1 + 1)) )
perror("ioctl LOAD_NATIVE_IDT");
return 0LL;
}

variable_types: idx int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rbx
_DWORD *v4; // r12
pthread_attr_t *v5; // r14
char *v6; // r13
pthread_t v8; // rdi
int fd; // [rsp+Ch] [rbp-93Ch]
int v10; // [rsp+18h] [rbp-930h]
char s[112]; // [rsp+20h] [rbp-928h] BYREF
cpu_set_t cpuset; // [rsp+90h] [rbp-8B8h] BYREF
char v13[2104]; // [rsp+110h] [rbp-838h] BYREF

snprintf(s, 0x64uLL, "/dev/%s", "bt");
v10 = sysconf(84);
fd = open(s, 0);
if ( fd < 0 )
{
perror("unable to open dev");
}
else
{
v3 = 0LL;
if ( v10 > 0 )
{
while ( 1 )
{
v4 = malloc(8uLL);
v5 = (pthread_attr_t *)malloc(0x38uLL);
if ( !v4 )
__assert_fail("arg", "terminate_bt.c", 0x30u, "main");
v4[1] = v3;
*v4 = fd;
if ( !v5 )
__assert_fail("tattr", "terminate_bt.c", 0x33u, "main");
pthread_attr_init(v5);
memset(&cpuset, 0, sizeof(cpuset));
if ( v3 <= 0x3FF )
cpuset.__bits[v3 >> 6] |= 1LL << v3;
v6 = v13;
pthread_attr_setaffinity_np(v5, 0x80uLL, &cpuset);
if ( pthread_create((pthread_t *)&v13[8 * v3], v5, load_native_idt, v4) )
{
fwrite("ERROR: Creating Pthread\n", 1uLL, 0x18uLL, stderr);
close(fd);
return 0;
}
if ( v3 == v10 - 1 )
break;
++v3;
}
do
{
v8 = *(_QWORD *)v6;
v6 += 8;
pthread_join(v8, 0LL);
}
while ( v6 != &v13[8 * v3 + 8] );
}
if ( ioctl(fd, 0x80046402uLL, (unsigned int)v10) )
perror("ioctl STOP_BT");
close(fd);
}
return 0;
}

original_code:
int
main(void)
{
  pthread_t threads[255];
  char name[100];
  int fd;
  int n_procs;
  int i;
  snprintf(name, sizeof(name), "/dev/%s", "bt");
  n_procs = sysconf(_SC_NPROCESSORS_ONLN);
  fd = open(name, 00);
  if (fd < 0) {
    perror("unable to open dev");
    return 0;
  }
  for (i = 0; i < n_procs; i++) {
    int *arg = malloc(sizeof(int)*2);
    pthread_attr_t *tattr = (pthread_attr_t *)malloc(sizeof(pthread_attr_t));
    cpu_set_t cpuset;
    ((void) sizeof ((arg) ? 1 : 0), __extension__ ({ if (arg) ; else __assert_fail ("arg", "terminate_bt.c", 48, __extension__ __PRETTY_FUNCTION__); }));
    *arg = fd;
    *(arg + 1) = i;
    ((void) sizeof ((tattr) ? 1 : 0), __extension__ ({ if (tattr) ; else __assert_fail ("tattr", "terminate_bt.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    pthread_attr_init(tattr);
    do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
    (__extension__ ({ size_t __cpu = (i); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
    pthread_attr_setaffinity_np (tattr, sizeof(cpuset), &cpuset);
    if (pthread_create(&threads[i], tattr, load_native_idt, arg)) {
      fprintf(stderr, "ERROR: Creating Pthread\n");
      close(fd);
      return 0;
    }
  }
  for (i = 0; i < n_procs; i++) {
    pthread_join(threads[i], ((void *)0));
  }
  if (ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (((100)) << (0 +8)) | (((2)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), n_procs) != 0) {
    perror("ioctl STOP_BT");
  }
  close(fd);
  return 0;
}

canonical_original_code:
int main()
{
  unsigned long threads[255];
  char name[100];
  int fd;
  int n_procs;
  int i;
  snprintf(name, sizeof(name), "/dev/%s", "bt");
  n_procs = sysconf(_SC_NPROCESSORS_ONLN);
  fd = open(name, 00);
  if (fd < 0) {
    perror("unable to open dev");
    return 0;
  }
  for (i = 0; i < n_procs; i++) {
    int *arg = malloc(sizeof(int)*2);
    union pthread_attr_t *tattr = (pthread_attr_t *)malloc(sizeof(pthread_attr_t));
    struct cpu_set_t cpuset;
    ((void) sizeof ((arg) ? 1 : 0), __extension__ ({ if (arg) ; else __assert_fail ("arg", "terminate_bt.c", 48, __extension__ __PRETTY_FUNCTION__); }));
    *arg = fd;
    *(arg + 1) = i;
    ((void) sizeof ((tattr) ? 1 : 0), __extension__ ({ if (tattr) ; else __assert_fail ("tattr", "terminate_bt.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    pthread_attr_init(tattr);
    do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
    (__extension__ ({ unsigned long __cpu = (i); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
    pthread_attr_setaffinity_np (tattr, sizeof(cpuset), &cpuset);
    if (pthread_create(&threads[i], tattr, load_native_idt, arg)) {
      fprintf(stderr, "ERROR: Creating Pthread\n");
      close(fd);
      return 0;
    }
  }
  for (i = 0; i < n_procs; i++) {
    pthread_join(threads[i], ((void *)0));
  }
  if (ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (((100)) << (0 +8)) | (((2)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), n_procs) != 0) {
    perror("ioctl STOP_BT");
  }
  close(fd);
  return 0;
}

user_defined_types: struct cpu_set_t { unsigned long __bits[-1]; }

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


repo: pizzamig/gdb-test-suite

decompiled_code:
int __fastcall timer_thread(const void *a1)
{
int v1; // eax
int v2; // eax
int v4; // eax
char *v5; // rax
__int64 v6; // r8
const char *v7; // rdx
const char *v8; // r9
char *v9; // rax
char *v10; // rax

v1 = pthread_mutex_lock(&mutex);
if ( v1 )
{
v9 = strerror(v1);
v6 = 38LL;
v7 = "Lock mutex";
v8 = v9;
goto LABEL_7;
}
if ( ++counter > 4 )
{
v4 = pthread_cond_signal(&cond);
if ( v4 )
{
v5 = strerror(v4);
v6 = 42LL;
v7 = "Signal condition";
v8 = v5;
goto LABEL_7;
}
}
v2 = pthread_mutex_unlock(&mutex);
if ( v2 )
{
v10 = strerror(v2);
v6 = 46LL;
v7 = "Unlock mutex";
v8 = v10;
LABEL_7:
fprintf(stderr, "%s at \"%s\":%d: %s\n", v7, "sigev_thread.c", v6, v8);
abort();
}
return printf("Timer (0x%p) %d\n", a1, (unsigned int)counter);
}

canonical_decompiled_code:
int __fastcall func7(const void *a1)
{
int v1; // eax
int v2; // eax
int v4; // eax
char *v5; // rax
__int64 v6; // r8
const char *v7; // rdx
const char *v8; // r9
char *v9; // rax
char *v10; // rax

v1 = pthread_mutex_lock(&mutex);
if ( v1 )
{
v9 = strerror(v1);
v6 = 38LL;
v7 = "Lock mutex";
v8 = v9;
goto LABEL_7;
}
if ( ++counter > 4 )
{
v4 = pthread_cond_signal(&cond);
if ( v4 )
{
v5 = strerror(v4);
v6 = 42LL;
v7 = "Signal condition";
v8 = v5;
goto LABEL_7;
}
}
v2 = pthread_mutex_unlock(&mutex);
if ( v2 )
{
v10 = strerror(v2);
v6 = 46LL;
v7 = "Unlock mutex";
v8 = v10;
LABEL_7:
fprintf(stderr, "%s at \"%s\":%d: %s\n", v7, "sigev_thread.c", v6, v8);
abort();
}
return printf("Timer (0x%p) %d\n", a1, (unsigned int)counter);
}

original_code:
void
timer_thread (union sigval si)
{
    int status;
    status = pthread_mutex_lock (&mutex);
    if (status != 0)
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "sigev_thread.c", 38, strerror (status)); abort (); } while (0);
    if (++counter >= 5) {
        status = pthread_cond_signal (&cond);
        if (status != 0)
            do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Signal condition", "sigev_thread.c", 42, strerror (status)); abort (); } while (0);
    }
    status = pthread_mutex_unlock (&mutex);
    if (status != 0)
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Unlock mutex", "sigev_thread.c", 46, strerror (status)); abort (); } while (0);
    printf ("Timer (0x%p) %d\n", si.sival_ptr, counter);
}

canonical_original_code:
void timer_thread(union sigval si)
{
    int status;
    status = pthread_mutex_lock (&mutex);
    if (status != 0)
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "sigev_thread.c", 38, strerror (status)); abort (); } while (0);
    if (++counter >= 5) {
        status = pthread_cond_signal (&cond);
        if (status != 0)
            do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Signal condition", "sigev_thread.c", 42, strerror (status)); abort (); } while (0);
    }
    status = pthread_mutex_unlock (&mutex);
    if (status != 0)
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Unlock mutex", "sigev_thread.c", 46, strerror (status)); abort (); } while (0);
    printf ("Timer (0x%p) %d\n", si.sival_ptr, counter);
}

variable_types: union sigval { int sival_int; void *sival_ptr; }

variable_types: status int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
int v5; // eax
char *v7; // rax
char *v8; // rax
__int64 v9; // r8
const char *v10; // rdx
const char *v11; // r9
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
char *v16; // rax
struct itimerspec v17; // [rsp+0h] [rbp-68h] BYREF
struct sigevent evp; // [rsp+20h] [rbp-48h] BYREF

evp.sigev_notify = 2;
evp.sigev_value.sival_ptr = &timer_id;
evp._sigev_un._sigev_thread._function = (void (*)(sigval_t))timer_thread;
evp._sigev_un._sigev_thread._attribute = 0LL;
v17.it_value.tv_sec = 5LL;
v17.it_value.tv_nsec = 0LL;
v17.it_interval.tv_sec = 5LL;
v17.it_interval.tv_nsec = 0LL;
puts("Creating timer");
if ( timer_create(0, &evp, &timer_id) == -1 )
{
v14 = __errno_location();
v15 = strerror(*v14);
v9 = 77LL;
v10 = "Create timer";
v11 = v15;
goto LABEL_10;
}
printf("Setting timer %p for 5-second expiration...\n", timer_id);
if ( timer_settime(timer_id, 0, &v17, 0LL) == -1 )
{
v12 = __errno_location();
v13 = strerror(*v12);
v9 = 83LL;
v10 = "Set timer";
v11 = v13;
goto LABEL_10;
}
v3 = pthread_mutex_lock(&mutex);
if ( v3 )
{
v8 = strerror(v3);
v9 = 87LL;
v10 = "Lock mutex";
v11 = v8;
goto LABEL_10;
}
while ( counter <= 4 )
{
v4 = pthread_cond_wait(&cond, &mutex);
if ( v4 )
{
v7 = strerror(v4);
v9 = 91LL;
v10 = "Wait on condition";
v11 = v7;
goto LABEL_10;
}
}
v5 = pthread_mutex_unlock(&mutex);
if ( v5 )
{
v16 = strerror(v5);
v9 = 95LL;
v10 = "Unlock mutex";
v11 = v16;
LABEL_10:
fprintf(stderr, "%s at \"%s\":%d: %s\n", v10, "sigev_thread.c", v9, v11);
abort();
}
return 0;
}

original_code:
int main()
{
    int status;
    struct itimerspec ts;
    struct sigevent se;
    se.sigev_notify = SIGEV_THREAD;
    se.sigev_value.sival_ptr = &timer_id;
    se._sigev_un._sigev_thread._function = timer_thread;
    se._sigev_un._sigev_thread._attribute = ((void *)0);
    ts.it_value.tv_sec = 5;
    ts.it_value.tv_nsec = 0;
    ts.it_interval.tv_sec = 5;
    ts.it_interval.tv_nsec = 0;
    printf("Creating timer\n");
    status = timer_create(0, &se, &timer_id);
    if (status == -1)
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Create timer", "sigev_thread.c", 77, strerror ((*__errno_location ()))); abort (); } while (0);
    printf(
        "Setting timer %p for 5-second expiration...\n", timer_id);
    status = timer_settime(timer_id, 0, &ts, 0);
    if (status == -1)
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Set timer", "sigev_thread.c", 83, strerror ((*__errno_location ()))); abort (); } while (0);
    status = pthread_mutex_lock (&mutex);
    if (status != 0)
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "sigev_thread.c", 87, strerror (status)); abort (); } while (0);
    while (counter < 5) {
        status = pthread_cond_wait (&cond, &mutex);
        if (status != 0)
            do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Wait on condition", "sigev_thread.c", 91, strerror (status)); abort (); } while (0);
    }
    status = pthread_mutex_unlock (&mutex);
    if (status != 0)
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Unlock mutex", "sigev_thread.c", 95, strerror (status)); abort (); } while (0);
    return 0;
}

variable_types: struct itimerspec { struct timespec { long tv_sec; long tv_nsec; } it_interval; struct timespec it_value; }

variable_types: struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; }

user_defined_types: struct itimerspec { struct timespec it_interval; struct timespec it_value; }

user_defined_types: struct sigevent { union sigval sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; }


repo: pjantrania/perfect-hashing

decompiled_code:
void *__fastcall table_init(size_t *a1, size_t a2, __int64 a3)
{
void *result; // rax

*a1 = a2;
_gmpz_init(a1 + 1);
_gmpz_set(a1 + 1, a3);
hash_fn_init(a1 + 3, a2);
hash_fn_generate(a1 + 3, a3);
result = calloc(a2, 0x78uLL);
a1[15] = (size_t)result;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t *a1, size_t a2, __int64 a3)
{
void *result; // rax

*a1 = a2;
_gmpz_init(a1 + 1);
_gmpz_set(a1 + 1, a3);
hash_fn_init(a1 + 3, a2);
hash_fn_generate(a1 + 3, a3);
result = calloc(a2, 0x78uLL);
a1[15] = (size_t)result;
return result;
}

original_code:
void table_init(table *t, ulint size, mpz_t universe_size) {
  t->size = size;
  __gmpz_init(t->universe_size);
  __gmpz_set(t->universe_size, universe_size);
  hash_fn_init(&t->primary_hash_function, size);
  hash_fn_generate(&t->primary_hash_function, universe_size);
  t->primary_table = (table_node *) calloc( size, sizeof(table_node) );
}

canonical_original_code:
void table_init(struct table_t *t, unsigned long size, struct __mpz_struct universe_size[1]) {
  t->size = size;
  __gmpz_init(t->universe_size);
  __gmpz_set(t->universe_size, universe_size);
  hash_fn_init(&t->primary_hash_function, size);
  hash_fn_generate(&t->primary_hash_function, universe_size);
  t->primary_table = (struct table_node_t *) calloc( size, sizeof(table_node) );
}

variable_types: struct table_t { unsigned long size; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } universe_size[1]; struct hash_fn_t { struct __mpz_struct p[1]; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct m[1]; struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } state[1]; } primary_hash_function; struct table_node_t { unsigned long count; struct bucket_node_t { unsigned long long value; struct bucket_node_t *next; } *bucket_head; struct hash_fn_t secondary_hash_function; unsigned long long *secondary_table; } *primary_table; } *

variable_types:
size
unsigned long

user_defined_types: struct table_t { unsigned long size; struct __mpz_struct universe_size[1]; struct hash_fn_t primary_hash_function; struct table_node_t *primary_table; }

user_defined_types: struct table_node_t { unsigned long count; struct bucket_node_t *bucket_head; struct hash_fn_t secondary_hash_function; unsigned long long *secondary_table; }

user_defined_types: struct hash_fn_t { struct __mpz_struct p[1]; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct m[1]; struct __gmp_randstate_struct state[1]; }

user_defined_types: struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t _mp_alg; union { void *_mp_lc; } _mp_algdata; }


decompiled_code:
__int64 __fastcall table_insert(__int64 a1, __int64 a2)
{
__int64 v2; // rax
_BYTE v4[16]; // [rsp+0h] [rbp-38h] BYREF
char v5[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v4);
_gmpz_init(v5);
_gmpz_set_ui(v4, a2);
hash_integer(a1 + 24, v5, v4);
v2 = _gmpz_get_ui(v5);
add_to_bucket((_QWORD *)(*(_QWORD *)(a1 + 120) + 120 * v2), a2);
_gmpz_clear(v4);
return _gmpz_clear(v5);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rax
_BYTE v4[16]; // [rsp+0h] [rbp-38h] BYREF
char v5[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v4);
_gmpz_init(v5);
_gmpz_set_ui(v4, a2);
hash_integer(a1 + 24, v5, v4);
v2 = _gmpz_get_ui(v5);
add_to_bucket((_QWORD *)(*(_QWORD *)(a1 + 120) + 120 * v2), a2);
_gmpz_clear(v4);
return _gmpz_clear(v5);
}

original_code:
void table_insert(table *t, unsigned long long v) {
  mpz_t value, position;
  ulint p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((const hash_fn *) &t->primary_hash_function, position, value);
  add_to_bucket(&t->primary_table[__gmpz_get_ui(position)], v);
  __gmpz_clear(value);
  __gmpz_clear(position);
}

canonical_original_code:
void table_insert(struct table_t *t, unsigned long long v) {
  struct __mpz_struct value[1]; struct __mpz_struct position[1];
  unsigned long p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((struct hash_fn_t *) &t->primary_hash_function, position, value);
  add_to_bucket(&t->primary_table[__gmpz_get_ui(position)], v);
  __gmpz_clear(value);
  __gmpz_clear(position);
}

variable_types:
v
unsigned long long

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
p
unsigned long

user_defined_types: enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr }

user_defined_types: struct bucket_node_t { unsigned long long value; struct bucket_node_t *next; }


original_code:
unsigned long long pop_bucket(table_node *node) {
  unsigned long long value;
  bucket_node *temp;
  value = node->bucket_head->value;
  temp = node->bucket_head;
  node->bucket_head = node->bucket_head->next;
  free(temp);
  return value;
}

canonical_original_code:
unsigned long long pop_bucket(struct table_node_t *node) {
  unsigned long long value;
  struct bucket_node_t *temp;
  value = node->bucket_head->value;
  temp = node->bucket_head;
  node->bucket_head = node->bucket_head->next;
  free(temp);
  return value;
}

variable_types: struct table_node_t { unsigned long count; struct bucket_node_t { unsigned long long value; struct bucket_node_t *next; } *bucket_head; struct hash_fn_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } p[1]; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct m[1]; struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } state[1]; } secondary_hash_function; unsigned long long *secondary_table; } *

variable_types:
value
unsigned long long

return_type: unsigned long long


decompiled_code:
__int64 __fastcall table_node_insert(__int64 a1, __int64 a2)
{
__int64 v2; // r12
_QWORD *v3; // rcx
__int64 result; // rax
_BYTE v5[16]; // [rsp+0h] [rbp-38h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v5);
_gmpz_init(v6);
_gmpz_set_ui(v5, a2);
hash_integer(a1 + 16, v6, v5);
v2 = _gmpz_get_ui(v6);
_gmpz_clear(v5);
_gmpz_clear(v6);
v3 = (_QWORD *)(*(_QWORD *)(a1 + 112) + 8 * v2);
result = 0LL;
if ( *v3 != a2 )
{
result = 1LL;
if ( !*v3 )
{
*v3 = a2;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // r12
_QWORD *v3; // rcx
__int64 result; // rax
_BYTE v5[16]; // [rsp+0h] [rbp-38h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v5);
_gmpz_init(v6);
_gmpz_set_ui(v5, a2);
hash_integer(a1 + 16, v6, v5);
v2 = _gmpz_get_ui(v6);
_gmpz_clear(v5);
_gmpz_clear(v6);
v3 = (_QWORD *)(*(_QWORD *)(a1 + 112) + 8 * v2);
result = 0LL;
if ( *v3 != a2 )
{
result = 1LL;
if ( !*v3 )
{
*v3 = a2;
result = 0LL;
}
}
return result;
}

original_code:
int table_node_insert(table_node *node, unsigned long long v) {
  mpz_t value, position;
  ulint p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((const hash_fn *) &node->secondary_hash_function, position, value);
  p = __gmpz_get_ui(position);
  __gmpz_clear(value);
  __gmpz_clear(position);
  if ( node->secondary_table[p] == v ) {
    return 0;
  } else if ( node->secondary_table[p] != 0 ) {
    return 1;
  } else {
    node->secondary_table[p] = v;
    return 0;
  }
}

canonical_original_code:
int table_node_insert(struct table_node_t *node, unsigned long long v) {
  struct __mpz_struct value[1]; struct __mpz_struct position[1];
  unsigned long p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((struct hash_fn_t *) &node->secondary_hash_function, position, value);
  p = __gmpz_get_ui(position);
  __gmpz_clear(value);
  __gmpz_clear(position);
  if ( node->secondary_table[p] == v ) {
    return 0;
  } else if ( node->secondary_table[p] != 0 ) {
    return 1;
  } else {
    node->secondary_table[p] = v;
    return 0;
  }
}

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }


decompiled_code:
_BOOL8 __fastcall table_node_find(__int64 a1, __int64 a2)
{
__int64 v2; // r12
_BYTE v4[16]; // [rsp+0h] [rbp-38h] BYREF
char v5[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v4);
_gmpz_init(v5);
_gmpz_set_ui(v4, a2);
hash_integer(a1 + 16, v5, v4);
v2 = _gmpz_get_ui(v5);
_gmpz_clear(v4);
_gmpz_clear(v5);
return *(_QWORD *)(*(_QWORD *)(a1 + 112) + 8 * v2) == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // r12
_BYTE v4[16]; // [rsp+0h] [rbp-38h] BYREF
char v5[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v4);
_gmpz_init(v5);
_gmpz_set_ui(v4, a2);
hash_integer(a1 + 16, v5, v4);
v2 = _gmpz_get_ui(v5);
_gmpz_clear(v4);
_gmpz_clear(v5);
return *(_QWORD *)(*(_QWORD *)(a1 + 112) + 8 * v2) == a2;
}

original_code:
int table_node_find(table_node *node, unsigned long long v) {
  mpz_t value, position;
  ulint p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((const hash_fn *) &node->secondary_hash_function, position, value);
  p = __gmpz_get_ui(position);
  __gmpz_clear(value);
  __gmpz_clear(position);
  return (node->secondary_table[p] == v ? 1 : 0);
}

canonical_original_code:
int table_node_find(struct table_node_t *node, unsigned long long v) {
  struct __mpz_struct value[1]; struct __mpz_struct position[1];
  unsigned long p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((struct hash_fn_t *) &node->secondary_hash_function, position, value);
  p = __gmpz_get_ui(position);
  __gmpz_clear(value);
  __gmpz_clear(position);
  return (node->secondary_table[p] == v ? 1 : 0);
}


decompiled_code:
_BOOL8 __fastcall table_find(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
_QWORD *v3; // rdi
_BOOL8 result; // rax
_BYTE v5[16]; // [rsp+0h] [rbp-38h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v5);
_gmpz_init(v6);
_gmpz_set_ui(v5, a2);
hash_integer(a1 + 24, v6, v5);
v2 = _gmpz_get_ui(v6);
_gmpz_clear(v5);
_gmpz_clear(v6);
v3 = (_QWORD *)(*(_QWORD *)(a1 + 120) + 120 * v2);
result = 0LL;
if ( *v3 )
result = table_node_find((__int64)v3, a2);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
_QWORD *v3; // rdi
_BOOL8 result; // rax
_BYTE v5[16]; // [rsp+0h] [rbp-38h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v5);
_gmpz_init(v6);
_gmpz_set_ui(v5, a2);
hash_integer(a1 + 24, v6, v5);
v2 = _gmpz_get_ui(v6);
_gmpz_clear(v5);
_gmpz_clear(v6);
v3 = (_QWORD *)(*(_QWORD *)(a1 + 120) + 120 * v2);
result = 0LL;
if ( *v3 )
result = func4((__int64)v3, a2);
return result;
}

original_code:
int table_find(table *t, unsigned long long v) {
  mpz_t value, position;
  ulint p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((const hash_fn *) &t->primary_hash_function, position, value);
  p = __gmpz_get_ui(position);
  __gmpz_clear(value);
  __gmpz_clear(position);
  return (t->primary_table[p].count == 0 ? 0 : table_node_find(&t->primary_table[p], v));
}

canonical_original_code:
int table_find(struct table_t *t, unsigned long long v) {
  struct __mpz_struct value[1]; struct __mpz_struct position[1];
  unsigned long p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((struct hash_fn_t *) &t->primary_hash_function, position, value);
  p = __gmpz_get_ui(position);
  __gmpz_clear(value);
  __gmpz_clear(position);
  return (t->primary_table[p].count == 0 ? 0 : table_node_find(&t->primary_table[p], v));
}


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

if ( *(_QWORD *)a1 )
{
v1 = 0LL;
do
{
++v1;
pop_bucket(a1);
}
while ( *(_QWORD *)a1 > v1 );
}
hash_fn_destroy(a1 + 16);
free(*(void **)(a1 + 112));
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
unsigned __int64 v1; // rbx

if ( *(_QWORD *)a1 )
{
v1 = 0LL;
do
{
++v1;
func2(a1);
}
while ( *(_QWORD *)a1 > v1 );
}
hash_fn_destroy(a1 + 16);
free(*(void **)(a1 + 112));
}

original_code:
void destroy_bucket(table_node *node) {
  ulint i;
  for ( i = 0; i < node->count; i++ ) {
    pop_bucket(node);
  }
  hash_fn_destroy(&node->secondary_hash_function);
  free(node->secondary_table);
}

canonical_original_code:
void destroy_bucket(struct table_node_t *node) {
  unsigned long i;
  for ( i = 0; i < node->count; i++ ) {
    pop_bucket(node);
  }
  hash_fn_destroy(&node->secondary_hash_function);
  free(node->secondary_table);
}

variable_types:
i
unsigned long


decompiled_code:
void __fastcall table_destroy(unsigned __int64 *a1)
{
char *v2; // r8
__int64 v3; // rbx
unsigned __int64 v4; // rbp
char *v5; // rdi
void *v6; // rdi

hash_fn_destroy(a1 + 3);
_gmpz_clear(a1 + 1);
v2 = (char *)a1[15];
if ( *a1 )
{
v3 = 0LL;
v4 = 0LL;
do
{
while ( 1 )
{
v5 = &v2[v3];
if ( !*(_QWORD *)&v2[v3 + 8] )
break;
destroy_bucket((__int64)v5);
v2 = (char *)a1[15];
LABEL_4:
++v4;
v3 += 120LL;
if ( *a1 <= v4 )
goto LABEL_8;
}
if ( !*(_QWORD *)v5 )
goto LABEL_4;
++v4;
hash_fn_destroy(v5 + 16);
v6 = *(void **)(a1[15] + v3 + 112);
v3 += 120LL;
free(v6);
v2 = (char *)a1[15];
}
while ( *a1 > v4 );
}
LABEL_8:
free(v2);
}

original_code:
void table_destroy(table *t) {
  ulint i;
  hash_fn_destroy(&t->primary_hash_function);
  __gmpz_clear(t->universe_size);
  for ( i = 0; i < t->size; i++ ) {
    if ( t->primary_table[i].bucket_head != ((void *)0) )
      destroy_bucket(&t->primary_table[i]);
    else if ( t->primary_table[i].count > 0 ) {
      hash_fn_destroy(&t->primary_table[i].secondary_hash_function);
      free(t->primary_table[i].secondary_table);
    }
  }
  free(t->primary_table);
}

canonical_original_code:
void table_destroy(struct table_t *t) {
  unsigned long i;
  hash_fn_destroy(&t->primary_hash_function);
  __gmpz_clear(t->universe_size);
  for ( i = 0; i < t->size; i++ ) {
    if ( t->primary_table[i].bucket_head != ((void *)0) )
      destroy_bucket(&t->primary_table[i]);
    else if ( t->primary_table[i].count > 0 ) {
      hash_fn_destroy(&t->primary_table[i].secondary_hash_function);
      free(t->primary_table[i].secondary_table);
    }
  }
  free(t->primary_table);
}


decompiled_code:
size_t *__fastcall table_rehash(void *ptr)
{
size_t *v2; // r12
__int64 v3; // rax
__int64 v4; // r14
unsigned __int64 v5; // rbx
_QWORD *v6; // rdi
unsigned __int64 v7; // r13
__int64 v8; // rax

v2 = (size_t *)calloc(1uLL, 0x80uLL);
table_init(v2, *(_QWORD *)ptr, (__int64)ptr + 8);
if ( *(_QWORD *)ptr )
{
v3 = *((_QWORD *)ptr + 15);
v4 = 0LL;
v5 = 0LL;
do
{
while ( 1 )
{
v6 = (_QWORD *)(v3 + v4);
if ( *(_QWORD *)(v3 + v4) )
break;
++v5;
v4 += 120LL;
if ( *(_QWORD *)ptr <= v5 )
goto LABEL_8;
}
v7 = 0LL;
do
{
v8 = pop_bucket((__int64)v6);
++v7;
table_insert((__int64)v2, v8);
v3 = *((_QWORD *)ptr + 15);
v6 = (_QWORD *)(v3 + v4);
}
while ( *(_QWORD *)(v3 + v4) > v7 );
*v6 = 0LL;
++v5;
v4 += 120LL;
}
while ( *(_QWORD *)ptr > v5 );
}
LABEL_8:
table_destroy((unsigned __int64 *)ptr);
free(ptr);
return v2;
}

canonical_decompiled_code:
size_t *__fastcall func8(void *ptr)
{
size_t *v2; // r12
__int64 v3; // rax
__int64 v4; // r14
unsigned __int64 v5; // rbx
_QWORD *v6; // rdi
unsigned __int64 v7; // r13
__int64 v8; // rax

v2 = (size_t *)calloc(1uLL, 0x80uLL);
func0(v2, *(_QWORD *)ptr, (__int64)ptr + 8);
if ( *(_QWORD *)ptr )
{
v3 = *((_QWORD *)ptr + 15);
v4 = 0LL;
v5 = 0LL;
do
{
while ( 1 )
{
v6 = (_QWORD *)(v3 + v4);
if ( *(_QWORD *)(v3 + v4) )
break;
++v5;
v4 += 120LL;
if ( *(_QWORD *)ptr <= v5 )
goto LABEL_8;
}
v7 = 0LL;
do
{
v8 = func2((__int64)v6);
++v7;
func1((__int64)v2, v8);
v3 = *((_QWORD *)ptr + 15);
v6 = (_QWORD *)(v3 + v4);
}
while ( *(_QWORD *)(v3 + v4) > v7 );
*v6 = 0LL;
++v5;
v4 += 120LL;
}
while ( *(_QWORD *)ptr > v5 );
}
LABEL_8:
func7((unsigned __int64 *)ptr);
free(ptr);
return v2;
}

original_code:
table * table_rehash(table *t) {
  table *new_table;
  ulint i, j;
  new_table = (table *) calloc( 1, sizeof(table) );
  table_init(new_table, t->size, t->universe_size);
  for ( i = 0; i < t->size; i++ ) {
    if ( t->primary_table[i].count > 0 ) {
      for ( j = 0; j < t->primary_table[i].count; j++ ) {
 table_insert(new_table, pop_bucket(&t->primary_table[i]));
      }
      t->primary_table[i].count = 0;
    }
  }
  table_destroy(t);
  free(t);
  return new_table;
}

canonical_original_code:
struct table_t *table_rehash(struct table_t *t) {
  struct table_t *new_table;
  unsigned long i; unsigned long j;
  new_table = (struct table_t *) calloc( 1, sizeof(table) );
  table_init(new_table, t->size, t->universe_size);
  for ( i = 0; i < t->size; i++ ) {
    if ( t->primary_table[i].count > 0 ) {
      for ( j = 0; j < t->primary_table[i].count; j++ ) {
 table_insert(new_table, pop_bucket(&t->primary_table[i]));
      }
      t->primary_table[i].count = 0;
    }
  }
  table_destroy(t);
  free(t);
  return new_table;
}

variable_types:
t
struct table_t *

variable_types:
j
unsigned long

return_type: struct table_t { unsigned long size; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } universe_size[1]; struct hash_fn_t { struct __mpz_struct p[1]; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct m[1]; struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } state[1]; } primary_hash_function; struct table_node_t { unsigned long count; struct bucket_node_t { unsigned long long value; struct bucket_node_t *next; } *bucket_head; struct hash_fn_t secondary_hash_function; unsigned long long *secondary_table; } *primary_table; } *


decompiled_code:
__int64 __fastcall table_build(void *ptr)
{
__int64 v2; // rbp
unsigned __int64 v3; // rbx
__int64 v4; // rax
unsigned __int64 v5; // rbp
unsigned __int64 v7; // r13
__int64 v8; // rbx
size_t v9; // rax
__int64 v10; // rax
__int64 *v11; // r14
unsigned __int64 v12; // r13
unsigned __int64 v13; // rax
size_t v14; // rax
void *v15; // rax
char *v16; // [rsp+8h] [rbp-60h]
char v17[16]; // [rsp+10h] [rbp-58h] BYREF
char v18[72]; // [rsp+20h] [rbp-48h] BYREF

v2 = 21LL;
_gmpz_init(v17);
_gmpz_set_ui(v17, 0LL);
puts("Checking space constraint...");
while ( 1 )
{
if ( *(_QWORD *)ptr )
{
v3 = 0LL;
do
{
v4 = 15 * v3++;
_gmpz_add_ui(
v17,
v17,
*(_QWORD *)(*((_QWORD *)ptr + 15) + 8 * v4) * *(_QWORD *)(*((_QWORD *)ptr + 15) + 8 * v4));
}
while ( *(_QWORD *)ptr > v3 );
}
if ( (int)_gmpz_cmp_ui(v17) <= 0 )
break;
if ( !--v2 )
{
puts("Too many iterations of size control loop");
exit(1);
}
ptr = table_rehash(ptr);
}
v5 = 0LL;
_gmpz_clear(v17);
_gmpz_init(v18);
puts("Constructing secondary tables...");
v16 = (char *)ptr + 8;
if ( *(_QWORD *)ptr )
{
do
{
v8 = *((_QWORD *)ptr + 15) + 120 * v5;
if ( *(_QWORD *)v8 )
{
_gmpz_set_ui(v18, *(_QWORD *)v8 * *(_QWORD *)v8);
_gmpz_nextprime(v18);
v9 = _gmpz_get_ui(v18);
*(_QWORD *)(v8 + 112) = calloc(v9, 8uLL);
v10 = _gmpz_get_ui(v18);
hash_fn_init(v8 + 16, v10);
hash_fn_generate(v8 + 16, v16);
v11 = *(__int64 **)(v8 + 8);
if ( *(_QWORD *)v8 )
{
v12 = 0LL;
do
{
if ( (unsigned int)table_node_insert(v8, *v11) == 1 )
{
v12 = 0LL;
hash_fn_generate(v8 + 16, v16);
free(*(void **)(v8 + 112));
v14 = _gmpz_get_ui(v18);
v15 = calloc(v14, 8uLL);
v11 = *(__int64 **)(v8 + 8);
*(_QWORD *)(v8 + 112) = v15;
v13 = *(_QWORD *)v8;
}
else
{
v13 = *(_QWORD *)v8;
if ( *(_QWORD *)v8 - 1LL > v12 )
v11 = (__int64 *)v11[1];
++v12;
}
}
while ( v12 < v13 );
if ( v13 )
{
v7 = 0LL;
do
{
++v7;
pop_bucket(v8);
}
while ( *(_QWORD *)v8 > v7 );
}
}
}
++v5;
}
while ( *(_QWORD *)ptr > v5 );
}
return _gmpz_clear(v18);
}

canonical_decompiled_code:
__int64 __fastcall func9(void *ptr)
{
__int64 v2; // rbp
unsigned __int64 v3; // rbx
__int64 v4; // rax
unsigned __int64 v5; // rbp
unsigned __int64 v7; // r13
__int64 v8; // rbx
size_t v9; // rax
__int64 v10; // rax
__int64 *v11; // r14
unsigned __int64 v12; // r13
unsigned __int64 v13; // rax
size_t v14; // rax
void *v15; // rax
char *v16; // [rsp+8h] [rbp-60h]
char v17[16]; // [rsp+10h] [rbp-58h] BYREF
char v18[72]; // [rsp+20h] [rbp-48h] BYREF

v2 = 21LL;
_gmpz_init(v17);
_gmpz_set_ui(v17, 0LL);
puts("Checking space constraint...");
while ( 1 )
{
if ( *(_QWORD *)ptr )
{
v3 = 0LL;
do
{
v4 = 15 * v3++;
_gmpz_add_ui(
v17,
v17,
*(_QWORD *)(*((_QWORD *)ptr + 15) + 8 * v4) * *(_QWORD *)(*((_QWORD *)ptr + 15) + 8 * v4));
}
while ( *(_QWORD *)ptr > v3 );
}
if ( (int)_gmpz_cmp_ui(v17) <= 0 )
break;
if ( !--v2 )
{
puts("Too many iterations of size control loop");
exit(1);
}
ptr = func8(ptr);
}
v5 = 0LL;
_gmpz_clear(v17);
_gmpz_init(v18);
puts("Constructing secondary tables...");
v16 = (char *)ptr + 8;
if ( *(_QWORD *)ptr )
{
do
{
v8 = *((_QWORD *)ptr + 15) + 120 * v5;
if ( *(_QWORD *)v8 )
{
_gmpz_set_ui(v18, *(_QWORD *)v8 * *(_QWORD *)v8);
_gmpz_nextprime(v18);
v9 = _gmpz_get_ui(v18);
*(_QWORD *)(v8 + 112) = calloc(v9, 8uLL);
v10 = _gmpz_get_ui(v18);
hash_fn_init(v8 + 16, v10);
hash_fn_generate(v8 + 16, v16);
v11 = *(__int64 **)(v8 + 8);
if ( *(_QWORD *)v8 )
{
v12 = 0LL;
do
{
if ( (unsigned int)func3(v8, *v11) == 1 )
{
v12 = 0LL;
hash_fn_generate(v8 + 16, v16);
free(*(void **)(v8 + 112));
v14 = _gmpz_get_ui(v18);
v15 = calloc(v14, 8uLL);
v11 = *(__int64 **)(v8 + 8);
*(_QWORD *)(v8 + 112) = v15;
v13 = *(_QWORD *)v8;
}
else
{
v13 = *(_QWORD *)v8;
if ( *(_QWORD *)v8 - 1LL > v12 )
v11 = (__int64 *)v11[1];
++v12;
}
}
while ( v12 < v13 );
if ( v13 )
{
v7 = 0LL;
do
{
++v7;
func2(v8);
}
while ( *(_QWORD *)v8 > v7 );
}
}
}
++v5;
}
while ( *(_QWORD *)ptr > v5 );
}
return _gmpz_clear(v18);
}

original_code:
void table_build(table *t) {
  ulint i, j, r, bucket_size, count_iter;
  mpz_t total_size, node_size;
  table_node *n;
  bucket_node *iter;
  __gmpz_init(total_size);
  __gmpz_set_ui(total_size, 0);
  count_iter = 0;
  printf("Checking space constraint...\n");
  for ( ;; ) {
    for ( i = 0; i < t->size; i++ ) {
      bucket_size = t->primary_table[i].count;
      bucket_size *= bucket_size;
      __gmpz_add_ui(total_size, total_size, bucket_size);
    }
    count_iter++;
    if ( (__builtin_constant_p ((t->size * 6)) && ((t->size * 6)) == 0 ? ((total_size)->_mp_size < 0 ? -1 : (total_size)->_mp_size > 0) : __gmpz_cmp_ui (total_size,(t->size * 6))) > 0 ) {
      if ( count_iter > 20 ) {
 printf("Too many iterations of size control loop\n");
 exit(1);
      }
      t = table_rehash(t);
    } else
      break;
  }
  __gmpz_clear(total_size);
  __gmpz_init(node_size);
  printf("Constructing secondary tables...\n");
  count_iter = 0;
  for ( i = 0; i < t->size; i++ ) {
    if ( t->primary_table[i].count > 0 ) {
      n = &t->primary_table[i];
      __gmpz_set_ui(node_size, n->count * n->count);
      __gmpz_nextprime(node_size, node_size);
      n->secondary_table = (unsigned long long*) calloc(__gmpz_get_ui(node_size), sizeof(unsigned long long));
      hash_fn_init(&n->secondary_hash_function, __gmpz_get_ui(node_size));
      hash_fn_generate(&n->secondary_hash_function, t->universe_size);
      j = 0;
      iter = n->bucket_head;
      while ( j < n->count ) {
 r = table_node_insert(n, iter->value);
 if ( r == 1 ) {
   hash_fn_generate(&n->secondary_hash_function, t->universe_size);
   free(n->secondary_table);
   n->secondary_table = (unsigned long long*) calloc(__gmpz_get_ui(node_size), sizeof(unsigned long long));
   iter = n->bucket_head;
   j = 0;
   continue;
 } else if ( j < n->count - 1 ) {
   iter = iter->next;
 }
 j++;
      }
      for ( j = 0; j < n->count; j++ )
 pop_bucket(n);
    }
  }
  __gmpz_clear(node_size);
}

canonical_original_code:
void table_build(struct table_t *t) {
  unsigned long i; unsigned long j; unsigned long r; unsigned long bucket_size; unsigned long count_iter;
  struct __mpz_struct total_size[1]; struct __mpz_struct node_size[1];
  struct table_node_t *n;
  struct bucket_node_t *iter;
  __gmpz_init(total_size);
  __gmpz_set_ui(total_size, 0);
  count_iter = 0;
  printf("Checking space constraint...\n");
  for ( ;; ) {
    for ( i = 0; i < t->size; i++ ) {
      bucket_size = t->primary_table[i].count;
      bucket_size *= bucket_size;
      __gmpz_add_ui(total_size, total_size, bucket_size);
    }
    count_iter++;
    if ( (__builtin_constant_p ((t->size * 6)) && ((t->size * 6)) == 0 ? ((total_size)->_mp_size < 0 ? -1 : (total_size)->_mp_size > 0) : __gmpz_cmp_ui (total_size,(t->size * 6))) > 0 ) {
      if ( count_iter > 20 ) {
 printf("Too many iterations of size control loop\n");
 exit(1);
      }
      t = table_rehash(t);
    } else
      break;
  }
  __gmpz_clear(total_size);
  __gmpz_init(node_size);
  printf("Constructing secondary tables...\n");
  count_iter = 0;
  for ( i = 0; i < t->size; i++ ) {
    if ( t->primary_table[i].count > 0 ) {
      n = &t->primary_table[i];
      __gmpz_set_ui(node_size, n->count * n->count);
      __gmpz_nextprime(node_size, node_size);
      n->secondary_table = (unsigned long long *) calloc(__gmpz_get_ui(node_size), sizeof(unsigned long long));
      hash_fn_init(&n->secondary_hash_function, __gmpz_get_ui(node_size));
      hash_fn_generate(&n->secondary_hash_function, t->universe_size);
      j = 0;
      iter = n->bucket_head;
      while ( j < n->count ) {
 r = table_node_insert(n, iter->value);
 if ( r == 1 ) {
   hash_fn_generate(&n->secondary_hash_function, t->universe_size);
   free(n->secondary_table);
   n->secondary_table = (unsigned long long *) calloc(__gmpz_get_ui(node_size), sizeof(unsigned long long));
   iter = n->bucket_head;
   j = 0;
   continue;
 } else if ( j < n->count - 1 ) {
   iter = iter->next;
 }
 j++;
      }
      for ( j = 0; j < n->count; j++ )
 pop_bucket(n);
    }
  }
  __gmpz_clear(node_size);
}

variable_types:
r
unsigned long

variable_types: struct bucket_node_t { unsigned long long value; struct bucket_node_t *next; } *


decompiled_code:
__int64 __fastcall hash_fn_init(__int64 a1, __int64 a2)
{
_gmpz_init(a1 + 16);
_gmpz_init(a1 + 32);
_gmpz_init(a1);
_gmpz_init(a1 + 48);
_gmp_randinit_default(a1 + 64);
return _gmpz_set_ui(a1 + 48, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
_gmpz_init(a1 + 16);
_gmpz_init(a1 + 32);
_gmpz_init(a1);
_gmpz_init(a1 + 48);
_gmp_randinit_default(a1 + 64);
return _gmpz_set_ui(a1 + 48, a2);
}

original_code:
void hash_fn_init(hash_fn *f, ulint table_size) {
  __gmpz_init(f->a);
  __gmpz_init(f->b);
  __gmpz_init(f->p);
  __gmpz_init(f->m);
  __gmp_randinit_default(f->state);
  __gmpz_set_ui(f->m, table_size);
}

canonical_original_code:
void hash_fn_init(struct hash_fn_t *f, unsigned long table_size) {
  __gmpz_init(f->a);
  __gmpz_init(f->b);
  __gmpz_init(f->p);
  __gmpz_init(f->m);
  __gmp_randinit_default(f->state);
  __gmpz_set_ui(f->m, table_size);
}

variable_types: struct hash_fn_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } p[1]; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct m[1]; struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } state[1]; } *


decompiled_code:
__int64 __fastcall hash_fn_generate(__int64 a1, __int64 a2)
{
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v4, 0LL);
_gmp_randseed_ui(a1 + 64, v4.tv_usec + 1000000 * v4.tv_sec);
_gmpz_nextprime(a1, a2);
_gmpz_urandomm(a1 + 16, a1 + 64, a1);
return _gmpz_urandomm(a1 + 32, a1 + 64, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v4, 0LL);
_gmp_randseed_ui(a1 + 64, v4.tv_usec + 1000000 * v4.tv_sec);
_gmpz_nextprime(a1, a2);
_gmpz_urandomm(a1 + 16, a1 + 64, a1);
return _gmpz_urandomm(a1 + 32, a1 + 64, a1);
}

original_code:
void hash_fn_generate(hash_fn *f, mpz_t u) {
  struct timeval time;
  ulint microtime;
  gettimeofday(&time, ((void *)0));
  microtime = (ulint)time.tv_sec*1000000 + (ulint)time.tv_usec;
  __gmp_randseed_ui(f->state, microtime);
  __gmpz_nextprime(f->p, u);
  __gmpz_urandomm(f->a, f->state, f->p);
  __gmpz_urandomm(f->b, f->state, f->p);
}

canonical_original_code:
void hash_fn_generate(struct hash_fn_t *f, struct __mpz_struct u[1]) {
  struct timeval time;
  unsigned long microtime;
  gettimeofday(&time, ((void *)0));
  microtime = (unsigned long)time.tv_sec*1000000 + (unsigned long)time.tv_usec;
  __gmp_randseed_ui(f->state, microtime);
  __gmpz_nextprime(f->p, u);
  __gmpz_urandomm(f->a, f->state, f->p);
  __gmpz_urandomm(f->b, f->state, f->p);
}

variable_types:
u
struct __mpz_struct [1]

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

variable_types:
microtime
unsigned long


decompiled_code:
__int64 __fastcall hash_integer(__int64 a1, __int64 a2, __int64 a3)
{
_gmpz_set_ui(a2, 0LL);
_gmpz_mul(a2, a1 + 16, a3);
_gmpz_add(a2, a2, a1 + 32);
_gmpz_mod(a2, a2, a1);
return _gmpz_mod(a2, a2, a1 + 48);
}

original_code:
void hash_integer(const hash_fn *f, mpz_t out, mpz_t integer) {
  __gmpz_set_ui(out, 0);
  __gmpz_mul(out, f->a, integer);
  __gmpz_add(out, out, f->b);
  __gmpz_mod(out, out, f->p);
  __gmpz_mod(out, out, f->m);
}

canonical_original_code:
void hash_integer(struct hash_fn_t *f, struct __mpz_struct out[1], struct __mpz_struct integer[1]) {
  __gmpz_set_ui(out, 0);
  __gmpz_mul(out, f->a, integer);
  __gmpz_add(out, out, f->b);
  __gmpz_mod(out, out, f->p);
  __gmpz_mod(out, out, f->m);
}

variable_types:
out
struct __mpz_struct [1]

variable_types:
integer
struct __mpz_struct [1]


decompiled_code:
__int64 __fastcall hash_string(__int64 a1, __int64 a2, const char *a3)
{
size_t v5; // rax
unsigned __int64 v6; // r12
unsigned int v7; // er15
__int64 v8; // r14
__int64 v9; // rsi
int v10; // esi
_BYTE v12[16]; // [rsp+0h] [rbp-C8h] BYREF
char v13[16]; // [rsp+10h] [rbp-B8h] BYREF
char v14[16]; // [rsp+20h] [rbp-A8h] BYREF
char v15[16]; // [rsp+30h] [rbp-98h] BYREF
char v16[136]; // [rsp+40h] [rbp-88h] BYREF

_gmpz_init(v12);
_gmpz_init(v13);
_gmpz_init(v14);
_gmpz_set_ui(v12, 26LL);
_gmpz_set_ui(a2, 0LL);
hash_fn_init((__int64)v15, 26LL);
hash_fn_generate((__int64)v15, a1 + 48);
v5 = strlen(a3);
if ( v5 )
{
v6 = v5;
v7 = 0;
v8 = 0LL;
do
{
v10 = a3[v8];
if ( a3[v8] <= 122 )
v9 = v10 - 97;
else
v9 = (char)(v10 - 65);
_gmpz_set_ui(v13, v9);
_gmpz_powm_ui(v14, v16, v8, v15);
v8 = ++v7;
_gmpz_addmul(a2, v14, v13);
}
while ( v7 < v6 );
}
_gmpz_mod(a2, a2, v15);
return hash_integer(a1, a2, a2);
}

original_code:
void hash_string(const hash_fn *f, mpz_t out, const char *string) {
  hash_fn inner_hash;
  mpz_t u, xi, ai;
  size_t l;
  unsigned int i;
  __gmpz_init(u);
  __gmpz_init(xi);
  __gmpz_init(ai);
  __gmpz_set_ui(u, 26);
  __gmpz_set_ui(out, 0);
  hash_fn_init(&inner_hash, 26);
  hash_fn_generate(&inner_hash, f->m);
  l = strlen(string);
  for ( i = 0; i < l; i++ ) {
    ulint x = ( string[i] <= 'z' ?
  string[i] - 'a' :
  string[i] - 'A' );
    __gmpz_set_ui(xi, x);
    __gmpz_powm_ui(ai, inner_hash.a, (ulint)i, inner_hash.p);
    __gmpz_addmul(out, ai, xi);
  }
  __gmpz_mod(out, out, inner_hash.p);
  hash_integer(f, out, out);
}

canonical_original_code:
void hash_string(struct hash_fn_t *f, struct __mpz_struct out[1], char *string) {
  struct hash_fn_t inner_hash;
  struct __mpz_struct u[1]; struct __mpz_struct xi[1]; struct __mpz_struct ai[1];
  unsigned long l;
  unsigned int i;
  __gmpz_init(u);
  __gmpz_init(xi);
  __gmpz_init(ai);
  __gmpz_set_ui(u, 26);
  __gmpz_set_ui(out, 0);
  hash_fn_init(&inner_hash, 26);
  hash_fn_generate(&inner_hash, f->m);
  l = strlen(string);
  for ( i = 0; i < l; i++ ) {
    unsigned long x = ( string[i] <= 'z' ?
  string[i] - 'a' :
  string[i] - 'A' );
    __gmpz_set_ui(xi, x);
    __gmpz_powm_ui(ai, inner_hash.a, (unsigned long)i, inner_hash.p);
    __gmpz_addmul(out, ai, xi);
  }
  __gmpz_mod(out, out, inner_hash.p);
  hash_integer(f, out, out);
}

variable_types:
string
char *

variable_types: struct hash_fn_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } p[1]; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct m[1]; struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } state[1]; }

variable_types:
l
unsigned long

variable_types:
i
unsigned int

variable_types:
x
unsigned long


decompiled_code:
__int64 __fastcall hash_fn_destroy(__int64 a1)
{
_gmpz_clear(a1 + 16);
_gmpz_clear(a1 + 32);
_gmpz_clear(a1);
_gmpz_clear(a1 + 48);
return _gmp_randclear(a1 + 64);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
_gmpz_clear(a1 + 16);
_gmpz_clear(a1 + 32);
_gmpz_clear(a1);
_gmpz_clear(a1 + 48);
return _gmp_randclear(a1 + 64);
}

original_code:
void hash_fn_destroy(hash_fn *f) {
  __gmpz_clear(f->a);
  __gmpz_clear(f->b);
  __gmpz_clear(f->p);
  __gmpz_clear(f->m);
  __gmp_randclear(f->state);
}

canonical_original_code:
void hash_fn_destroy(struct hash_fn_t *f) {
  __gmpz_clear(f->a);
  __gmpz_clear(f->b);
  __gmpz_clear(f->p);
  __gmpz_clear(f->m);
  __gmp_randclear(f->state);
}


repo: pjherring/task

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

result = a1;
if ( a1 )
{
if ( *(_QWORD *)(a1 + 8) != -1LL )
_InterlockedAdd64((volatile signed __int64 *)(a1 + 8), 1uLL);
}
return result;
}

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

result = a1;
if ( a1 )
{
if ( *(_QWORD *)(a1 + 8) != -1LL )
_InterlockedAdd64((volatile signed __int64 *)(a1 + 8), 1uLL);
}
return result;
}

original_code:
static inline
json_t *json_incref(json_t *json)
{
    if(json && json->refcount != (size_t)-1)
        __atomic_add_fetch(&json->refcount, 1, 2);
    return json;
}

canonical_original_code:
static inline struct json_t *json_incref(struct json_t *json)
{
    if(json && json->refcount != (unsigned long)-1)
        __atomic_add_fetch(&json->refcount, 1, 2);
    return json;
}

variable_types:
json
struct json_t *

return_type: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *

user_defined_types: struct json_t { enum json_type type; unsigned long refcount; }


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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 && !_InterlockedSub64((volatile signed __int64 *)(a1 + 8), 1uLL) )
result = json_delete();
}
return result;
}

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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 && !_InterlockedSub64((volatile signed __int64 *)(a1 + 8), 1uLL) )
result = json_delete();
}
return result;
}

original_code:
static inline
void json_decref(json_t *json)
{
    if(json && json->refcount != (size_t)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

canonical_original_code:
static inline void json_decref(struct json_t *json)
{
    if(json && json->refcount != (unsigned long)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

variable_types: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *


decompiled_code:
void __fastcall print_notes(__int64 a1)
{
int v1; // ebx
char *v2; // rbp
char *v3; // rsi

if ( a1 && *(int *)(a1 + 16) > 0 )
{
v1 = 0;
puts("Notes:");
while ( 1 )
{
v2 = (char *)list_iterate(a1);
if ( !v2 )
break;
printf("%d)\n", (unsigned int)++v1);
while ( 1 )
{
v3 = strtok(v2, "\n");
if ( !v3 )
break;
v2 = 0LL;
printf(" %s\n", v3);
}
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
int v1; // ebx
char *v2; // rbp
char *v3; // rsi

if ( a1 && *(int *)(a1 + 16) > 0 )
{
v1 = 0;
puts("Notes:");
while ( 1 )
{
v2 = (char *)list_iterate(a1);
if ( !v2 )
break;
printf("%d)\n", (unsigned int)++v1);
while ( 1 )
{
v3 = strtok(v2, "\n");
if ( !v3 )
break;
v2 = 0LL;
printf(" %s\n", v3);
}
}
}
}

original_code:
void print_notes(ListT* notes) {
    if (notes != ((void *)0) && notes->size > 0) {
        char* note;
        int note_idx = 0;
        printf("Notes:\n");
        while ((note = list_iterate(notes)) != ((void *)0)) {
            char* token;
            printf("%d)\n", note_idx++ + 1);
            while ((token = strtok(note, "\n")) != ((void *)0)) {
                printf("  %s\n", token);
                note = ((void *)0);
            }
        }
    }
}

canonical_original_code:
void print_notes(struct ListT *notes) {
    if (notes != ((void *)0) && notes->size > 0) {
        char *note;
        int note_idx = 0;
        printf("Notes:\n");
        while ((note = list_iterate(notes)) != ((void *)0)) {
            char *token;
            printf("%d)\n", note_idx++ + 1);
            while ((token = strtok(note, "\n")) != ((void *)0)) {
                printf("  %s\n", token);
                note = ((void *)0);
            }
        }
    }
}

variable_types: struct ListT { void **values; void **last_value; int size; int capacity; } *

variable_types:
note
char *

variable_types:
token
char *


decompiled_code:
__int64 __fastcall write_task(__int64 a1, __int64 a2)
{
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rax
__int64 v8; // rax
__int64 v9; // rdi
__int64 v10; // r13
unsigned int v11; // ebx
__int64 v12; // rsi
__int64 v13; // rax
__int64 v14; // rax

v4 = json_string(*(_QWORD *)a2);
json_object_set_new(a1, kTaskJsonTextKey, v4);
if ( *(_DWORD *)(a2 + 24) == 1 )
v5 = json_true();
else
v5 = json_false();
json_object_set_new(a1, kTaskJsonIsCompleteKey, v5);
v6 = *(_QWORD *)(a2 + 8);
if ( v6 && *(int *)(v6 + 16) > 0 )
{
v8 = json_array();
v9 = *(_QWORD *)(a2 + 8);
v10 = v8;
if ( *(int *)(v9 + 16) > 0 )
{
v11 = 0;
do
{
v12 = v11++;
v13 = list_obj_at_idx(v9, v12);
v14 = json_string(v13);
json_array_append_new(v10, v14);
v9 = *(_QWORD *)(a2 + 8);
}
while ( *(_DWORD *)(v9 + 16) > (signed int)v11 );
}
json_object_set_isra_0(a1, (__int64)kTaskJsonNotesKey, v10);
json_decref(v10);
}
return write_children_to_task(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rax
__int64 v8; // rax
__int64 v9; // rdi
__int64 v10; // r13
unsigned int v11; // ebx
__int64 v12; // rsi
__int64 v13; // rax
__int64 v14; // rax

v4 = json_string(*(_QWORD *)a2);
json_object_set_new(a1, kTaskJsonTextKey, v4);
if ( *(_DWORD *)(a2 + 24) == 1 )
v5 = json_true();
else
v5 = json_false();
json_object_set_new(a1, kTaskJsonIsCompleteKey, v5);
v6 = *(_QWORD *)(a2 + 8);
if ( v6 && *(int *)(v6 + 16) > 0 )
{
v8 = json_array();
v9 = *(_QWORD *)(a2 + 8);
v10 = v8;
if ( *(int *)(v9 + 16) > 0 )
{
v11 = 0;
do
{
v12 = v11++;
v13 = list_obj_at_idx(v9, v12);
v14 = json_string(v13);
json_array_append_new(v10, v14);
v9 = *(_QWORD *)(a2 + 8);
}
while ( *(_DWORD *)(v9 + 16) > (signed int)v11 );
}
func4(a1, (__int64)kTaskJsonNotesKey, v10);
func1(v10);
}
return func6(a1, a2);
}

original_code:
static void write_task(json_t* json_obj, TaskT* task) {
    json_object_set_new(json_obj, kTaskJsonTextKey, json_string(task->text));
    json_object_set_new(
        json_obj,
        kTaskJsonIsCompleteKey,
        (task->is_complete == 1 ? json_true() : json_false())
    );
    if (task->notes != ((void *)0) && task->notes->size > 0) {
        json_t *notes_json_arr;
        int note_idx;
        notes_json_arr = json_array();
        for (note_idx = 0; note_idx < task->notes->size; note_idx++) {
            char *note;
            note = list_obj_at_idx(task->notes, note_idx);
            json_array_append_new(notes_json_arr, json_string(note));
        }
        json_object_set(json_obj, kTaskJsonNotesKey, notes_json_arr);
        json_decref(notes_json_arr);
    }
    write_children_to_task(json_obj, task);
}

canonical_original_code:
static void write_task(struct json_t *json_obj, struct TaskT *task) {
    json_object_set_new(json_obj, kTaskJsonTextKey, json_string(task->text));
    json_object_set_new(
        json_obj,
        kTaskJsonIsCompleteKey,
        (task->is_complete == 1 ? json_true() : json_false())
    );
    if (task->notes != ((void *)0) && task->notes->size > 0) {
        struct json_t *notes_json_arr;
        int note_idx;
        notes_json_arr = json_array();
        for (note_idx = 0; note_idx < task->notes->size; note_idx++) {
            char *note;
            note = list_obj_at_idx(task->notes, note_idx);
            json_array_append_new(notes_json_arr, json_string(note));
        }
        json_object_set(json_obj, kTaskJsonNotesKey, notes_json_arr);
        json_decref(notes_json_arr);
    }
    write_children_to_task(json_obj, task);
}

variable_types: struct TaskT { char *text; struct ListT { void **values; void **last_value; int size; int capacity; } *notes; struct ListT *children; int is_complete; struct TaskT *parent; } *

user_defined_types: struct TaskT { char *text; struct ListT *notes; struct ListT *children; int is_complete; struct TaskT *parent; }

user_defined_types: enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 }


decompiled_code:
__int64 __fastcall write_children_to_task(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v4; // r12
unsigned int v5; // ebx
__int64 v6; // rsi
__int64 v7; // rbp
__int64 v8; // rax

result = *(_QWORD *)(a2 + 16);
if ( result && *(int *)(result + 16) > 0 )
{
v4 = json_array();
if ( *(int *)(*(_QWORD *)(a2 + 16) + 16LL) > 0 )
{
v5 = 0;
do
{
v6 = v5++;
v7 = json_object();
v8 = list_obj_at_idx(*(_QWORD *)(a2 + 16), v6);
write_task(v7, v8);
json_array_append_isra_0(v4, v7);
json_decref(v7);
}
while ( *(_DWORD *)(*(_QWORD *)(a2 + 16) + 16LL) > (signed int)v5 );
}
json_object_set_isra_0(a1, (__int64)kTaskJsonChildrenKey, v4);
result = json_decref(v4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v4; // r12
unsigned int v5; // ebx
__int64 v6; // rsi
__int64 v7; // rbp
__int64 v8; // rax

result = *(_QWORD *)(a2 + 16);
if ( result && *(int *)(result + 16) > 0 )
{
v4 = json_array();
if ( *(int *)(*(_QWORD *)(a2 + 16) + 16LL) > 0 )
{
v5 = 0;
do
{
v6 = v5++;
v7 = json_object();
v8 = list_obj_at_idx(*(_QWORD *)(a2 + 16), v6);
func5(v7, v8);
func3(v4, v7);
func1(v7);
}
while ( *(_DWORD *)(*(_QWORD *)(a2 + 16) + 16LL) > (signed int)v5 );
}
func4(a1, (__int64)kTaskJsonChildrenKey, v4);
result = func1(v4);
}
return result;
}

original_code:
static void write_children_to_task(json_t* json_obj, TaskT* task) {
    if (task->children != ((void *)0) && task->children->size > 0) {
        json_t * children_json_arr;
        int child_idx;
        children_json_arr = json_array();
        for (child_idx = 0; child_idx < task->children->size; child_idx++) {
            json_t *child_json_obj;
            TaskT* child_task;
            child_json_obj = json_object();
            child_task = list_obj_at_idx(task->children, child_idx);
            write_task(child_json_obj, child_task);
            json_array_append(children_json_arr, child_json_obj);
            json_decref(child_json_obj);
        }
        json_object_set(json_obj, kTaskJsonChildrenKey, children_json_arr);
        json_decref(children_json_arr);
    }
}

canonical_original_code:
static void write_children_to_task(struct json_t *json_obj, struct TaskT *task) {
    if (task->children != ((void *)0) && task->children->size > 0) {
        struct json_t *children_json_arr;
        int child_idx;
        children_json_arr = json_array();
        for (child_idx = 0; child_idx < task->children->size; child_idx++) {
            struct json_t *child_json_obj;
            struct TaskT *child_task;
            child_json_obj = json_object();
            child_task = list_obj_at_idx(task->children, child_idx);
            write_task(child_json_obj, child_task);
            json_array_append(children_json_arr, child_json_obj);
            json_decref(child_json_obj);
        }
        json_object_set(json_obj, kTaskJsonChildrenKey, children_json_arr);
        json_decref(children_json_arr);
    }
}

user_defined_types: struct ListT { void **values; void **last_value; int size; int capacity; }


decompiled_code:
void __fastcall task_destroy(void *ptr)
{
__int64 v2; // rdi
unsigned int i; // ebx
__int64 v4; // rsi
void *v5; // rax

if ( !ptr )
_assert_fail("self != NULL", "src/task.c", 0x2Cu, "task_destroy");
v2 = *((_QWORD *)ptr + 1);
for ( i = 0; *(_DWORD *)(v2 + 16) > (signed int)i; v2 = *((_QWORD *)ptr + 1) )
{
v4 = i++;
v5 = (void *)list_obj_at_idx(v2, v4);
free(v5);
}
((void (*)(void))list_destroy)();
list_destroy(*((_QWORD *)ptr + 2));
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
__int64 v2; // rdi
unsigned int i; // ebx
__int64 v4; // rsi
void *v5; // rax

if ( !ptr )
_assert_fail("self != NULL", "src/task.c", 0x2Cu, "task_destroy");
v2 = *((_QWORD *)ptr + 1);
for ( i = 0; *(_DWORD *)(v2 + 16) > (signed int)i; v2 = *((_QWORD *)ptr + 1) )
{
v4 = i++;
v5 = (void *)list_obj_at_idx(v2, v4);
free(v5);
}
((void (*)(void))list_destroy)();
list_destroy(*((_QWORD *)ptr + 2));
free(*(void **)ptr);
free(ptr);
}

original_code:
void task_destroy(TaskT* self) {
    ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "src/task.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    int note_idx;
    int child_idx;
    for (note_idx = 0; note_idx < self->notes->size; note_idx++) {
        free(list_obj_at_idx(self->notes, note_idx));
    }
    list_destroy(self->notes);
    list_destroy(self->children);
    free(self->text);
    free(self);
}

canonical_original_code:
void task_destroy(struct TaskT *self) {
    ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "src/task.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    int note_idx;
    int child_idx;
    for (note_idx = 0; note_idx < self->notes->size; note_idx++) {
        free(list_obj_at_idx(self->notes, note_idx));
    }
    list_destroy(self->notes);
    list_destroy(self->children);
    free(self->text);
    free(self);
}


decompiled_code:
__int64 __fastcall task_add_note(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("self != NULL", "src/task.c", 0x3Du, "task_add_note");
if ( !a2 )
_assert_fail("note != NULL", "src/task.c", 0x3Eu, "task_add_note");
return list_append(*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("self != NULL", "src/task.c", 0x3Du, "task_add_note");
if ( !a2 )
_assert_fail("note != NULL", "src/task.c", 0x3Eu, "task_add_note");
return list_append(*(_QWORD *)(a1 + 8));
}

original_code:
void task_add_note(TaskT* self, char* note) {
    ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "src/task.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((note != ((void *)0)) ? 1 : 0), __extension__ ({ if (note != ((void *)0)) ; else __assert_fail ("note != NULL", "src/task.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    list_append(self->notes, note);
}

canonical_original_code:
void task_add_note(struct TaskT *self, char *note) {
    ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "src/task.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((note != ((void *)0)) ? 1 : 0), __extension__ ({ if (note != ((void *)0)) ; else __assert_fail ("note != NULL", "src/task.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    list_append(self->notes, note);
}


decompiled_code:
void __fastcall task_complete(__int64 a1)
{
*(_DWORD *)(a1 + 24) = 1;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
*(_DWORD *)(a1 + 24) = 1;
}

original_code:
void task_complete(TaskT* self) {
    self->is_complete = 1;
}

canonical_original_code:
void task_complete(struct TaskT *self) {
    self->is_complete = 1;
}


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

if ( !a1 || !a2 )
_assert_fail("self != NULL && child != NULL", "src/task.c", 0x48u, "task_add_child");
result = list_append(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a2 + 32) = a1;
return result;
}

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

if ( !a1 || !a2 )
_assert_fail("self != NULL && child != NULL", "src/task.c", 0x48u, "task_add_child");
result = list_append(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a2 + 32) = a1;
return result;
}

original_code:
void task_add_child(TaskT* self, TaskT* child) {
    ((void) sizeof ((self != ((void *)0) && child != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0) && child != ((void *)0)) ; else __assert_fail ("self != NULL && child != NULL", "src/task.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    list_append(self->children, child);
    child->parent = self;
}

canonical_original_code:
void task_add_child(struct TaskT *self, struct TaskT *child) {
    ((void) sizeof ((self != ((void *)0) && child != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0) && child != ((void *)0)) ; else __assert_fail ("self != NULL && child != NULL", "src/task.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    list_append(self->children, child);
    child->parent = self;
}

variable_types:
child
struct TaskT *


decompiled_code:
void __fastcall task_print(__int64 a1)
{
const char *v1; // rdx

v1 = "COMPLTED";
if ( !*(_DWORD *)(a1 + 24) )
v1 = "NOT COMPLETED";
printf("%s (%s)\n", *(_QWORD *)a1, v1);
print_notes(*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
const char *v1; // rdx

v1 = "COMPLTED";
if ( !*(_DWORD *)(a1 + 24) )
v1 = "NOT COMPLETED";
printf("%s (%s)\n", *(_QWORD *)a1, v1);
func2(*(_QWORD *)(a1 + 8));
}

original_code:
void task_print(TaskT* task) {
    printf("%s (%s)\n", task->text, (task->is_complete ? "COMPLTED" : "NOT COMPLETED"));
    print_notes(task->notes);
}

canonical_original_code:
void task_print(struct TaskT *task) {
    printf("%s (%s)\n", task->text, (task->is_complete ? "COMPLTED" : "NOT COMPLETED"));
    print_notes(task->notes);
}


decompiled_code:
void __fastcall get_user_input(_QWORD *a1)
{
size_t v1; // r12
__int64 v2; // rbx
_BYTE *v3; // rax
_BYTE *v4; // rbp
char i; // al

v1 = 100LL;
v2 = 0LL;
v3 = calloc(0x64uLL, 1uLL);
*a1 = v3;
v4 = v3;
LABEL_2:
for ( i = getchar(); i != 10; i = getchar() )
{
if ( i == -1 )
break;
v4[v2++] = i;
if ( v1 != v2 )
goto LABEL_2;
v1 += 100LL;
v4 = realloc(v4, v1);
}
*a1 = trim(v4);
free(v4);
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1)
{
size_t v1; // r12
__int64 v2; // rbx
_BYTE *v3; // rax
_BYTE *v4; // rbp
char i; // al

v1 = 100LL;
v2 = 0LL;
v3 = calloc(0x64uLL, 1uLL);
*a1 = v3;
v4 = v3;
LABEL_2:
for ( i = getchar(); i != 10; i = getchar() )
{
if ( i == -1 )
break;
v4[v2++] = i;
if ( v1 != v2 )
goto LABEL_2;
v1 += 100LL;
v4 = realloc(v4, v1);
}
*a1 = trim(v4);
free(v4);
}

original_code:
void get_user_input(char** command) {
    char* _command;
    char c;
    int user_input_idx;
    size_t current_command_size;
    *command = calloc(kUserInputInitSize, sizeof(char));
    _command = *command;
    c = (-1);
    user_input_idx = 0;
    current_command_size = kUserInputInitSize;
    while ((c = getchar()) != (-1) && c != '\n') {
        _command[user_input_idx++] = c;
        if (user_input_idx == current_command_size) {
            current_command_size += kUserInputInitSize;
            _command = realloc(_command, sizeof(char) * current_command_size);
        }
    }
    *command = trim(_command);
    free(_command);
}

canonical_original_code:
void get_user_input(char **command) {
    char *_command;
    char c;
    int user_input_idx;
    unsigned long current_command_size;
    *command = calloc(kUserInputInitSize, sizeof(char));
    _command = *command;
    c = (-1);
    user_input_idx = 0;
    current_command_size = kUserInputInitSize;
    while ((c = getchar()) != (-1) && c != '\n') {
        _command[user_input_idx++] = c;
        if (user_input_idx == current_command_size) {
            current_command_size += kUserInputInitSize;
            _command = realloc(_command, sizeof(char) * current_command_size);
        }
    }
    *command = trim(_command);
    free(_command);
}

variable_types:
command
char **

variable_types: c char


decompiled_code:
void __fastcall get_user_input_msg(_QWORD *a1, const char *a2)
{
printf("%s", a2);
get_user_input(a1);
}

canonical_decompiled_code:
void __fastcall func1(_QWORD *a1, const char *a2)
{
printf("%s", a2);
func0(a1);
}

original_code:
void get_user_input_msg(char** command, const char* message) {
    printf("%s", message);
    get_user_input(command);
}

canonical_original_code:
void get_user_input_msg(char **command, char *message) {
    printf("%s", message);
    get_user_input(command);
}

variable_types:
message
char *


decompiled_code:
__int64 __fastcall get_numeric_input(const char *a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( a1 )
printf("%s", a1);
do
get_user_input(&v2);
while ( !v2 );
return strtodigit();
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( a1 )
printf("%s", a1);
do
func0(&v2);
while ( !v2 );
return strtodigit();
}

original_code:
int get_numeric_input(char* msg) {
    char* user_input_str = ((void *)0);
    int numeric;
    if (msg != ((void *)0)) {
        printf("%s", msg);
    }
    while (user_input_str == ((void *)0)) {
        get_user_input(&user_input_str);
    }
    numeric = strtodigit(user_input_str);
    return numeric;
}

canonical_original_code:
int get_numeric_input(char *msg) {
    char *user_input_str = ((void *)0);
    int numeric;
    if (msg != ((void *)0)) {
        printf("%s", msg);
    }
    while (user_input_str == ((void *)0)) {
        get_user_input(&user_input_str);
    }
    numeric = strtodigit(user_input_str);
    return numeric;
}

variable_types:
msg
char *

variable_types: numeric int


decompiled_code:
void __fastcall get_multiline_input(_QWORD *a1, const char *a2)
{
size_t v2; // r13
__int64 v3; // rbp
char *v4; // r12
char i; // bl

v2 = 100LL;
v3 = 0LL;
printf(a2, 0LL);
v4 = (char *)calloc(0x64uLL, 1uLL);
LABEL_2:
for ( i = getchar(); i != -1; i = getchar() )
{
if ( strstr(v4, "\n\n") )
break;
v4[v3++] = i;
if ( v2 != v3 )
goto LABEL_2;
v2 += 100LL;
v4 = (char *)realloc(v4, v2);
}
*a1 = trim(v4);
free(v4);
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1, const char *a2)
{
size_t v2; // r13
__int64 v3; // rbp
char *v4; // r12
char i; // bl

v2 = 100LL;
v3 = 0LL;
printf(a2, 0LL);
v4 = (char *)calloc(0x64uLL, 1uLL);
LABEL_2:
for ( i = getchar(); i != -1; i = getchar() )
{
if ( strstr(v4, "\n\n") )
break;
v4[v3++] = i;
if ( v2 != v3 )
goto LABEL_2;
v2 += 100LL;
v4 = (char *)realloc(v4, v2);
}
*a1 = trim(v4);
free(v4);
}

original_code:
void get_multiline_input(char** input, const char* msg) {
    char* _input;
    char c;
    int input_idx;
    size_t current_size;
    printf(msg, ((void *)0));
    _input = calloc(kUserInputInitSize, 1);
    c = (-1);
    input_idx = 0;
    current_size = kUserInputInitSize;
    while ((c = getchar()) != (-1) && strstr(_input, "\n\n") == ((void *)0)) {
        _input[input_idx++] = c;
        if (input_idx == current_size) {
            current_size += kUserInputInitSize;
            _input = realloc(_input, current_size);
        }
    }
    *input = trim(_input);
    free(_input);
}

canonical_original_code:
void get_multiline_input(char **input, char *msg) {
    char *_input;
    char c;
    int input_idx;
    unsigned long current_size;
    printf(msg, ((void *)0));
    _input = calloc(kUserInputInitSize, 1);
    c = (-1);
    input_idx = 0;
    current_size = kUserInputInitSize;
    while ((c = getchar()) != (-1) && strstr(_input, "\n\n") == ((void *)0)) {
        _input[input_idx++] = c;
        if (input_idx == current_size) {
            current_size += kUserInputInitSize;
            _input = realloc(_input, current_size);
        }
    }
    *input = trim(_input);
    free(_input);
}

variable_types:
input
char **


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

result = command_dict_1;
if ( !command_dict_1 )
{
command_dict_1 = Dict();
dict_add(command_dict_1, "n", &execute_new);
dict_add(command_dict_1, "new", &execute_new);
dict_add(command_dict_1, "f", &execute_finish);
dict_add(command_dict_1, "finish", &execute_finish);
dict_add(command_dict_1, "s", &execute_show);
dict_add(command_dict_1, "show", &execute_show);
dict_add(command_dict_1, "a", &execute_add_note);
dict_add(command_dict_1, "add", &execute_add_note);
dict_add(command_dict_1, "l", &execute_load);
dict_add(command_dict_1, "load", &execute_load);
dict_add(command_dict_1, "w", &execute_save);
dict_add(command_dict_1, "write", &execute_save);
dict_add(command_dict_1, "print", &execute_print);
dict_add(command_dict_1, "p", &execute_print);
dict_add(command_dict_1, "c", &execute_change);
dict_add(command_dict_1, "change", &execute_change);
result = command_dict_1;
}
return result;
}

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

result = command_dict_1;
if ( !command_dict_1 )
{
command_dict_1 = Dict();
dict_add(command_dict_1, "n", &execute_new);
dict_add(command_dict_1, "new", &execute_new);
dict_add(command_dict_1, "f", &execute_finish);
dict_add(command_dict_1, "finish", &execute_finish);
dict_add(command_dict_1, "s", &execute_show);
dict_add(command_dict_1, "show", &execute_show);
dict_add(command_dict_1, "a", &execute_add_note);
dict_add(command_dict_1, "add", &execute_add_note);
dict_add(command_dict_1, "l", &execute_load);
dict_add(command_dict_1, "load", &execute_load);
dict_add(command_dict_1, "w", &execute_save);
dict_add(command_dict_1, "write", &execute_save);
dict_add(command_dict_1, "print", &execute_print);
dict_add(command_dict_1, "p", &execute_print);
dict_add(command_dict_1, "c", &execute_change);
dict_add(command_dict_1, "change", &execute_change);
result = command_dict_1;
}
return result;
}

original_code:
DictionaryT* get_command_dict() {
    static DictionaryT* command_dict = ((void *)0);
    if (command_dict == ((void *)0)) {
        command_dict = Dict();
        dict_add(command_dict, "n", &execute_new);
        dict_add(command_dict, "new", &execute_new);
        dict_add(command_dict, "f", &execute_finish);
        dict_add(command_dict, "finish", &execute_finish);
        dict_add(command_dict, "s", &execute_show);
        dict_add(command_dict, "show", &execute_show);
        dict_add(command_dict, "a", &execute_add_note);
        dict_add(command_dict, "add", &execute_add_note);
        dict_add(command_dict, "l", &execute_load);
        dict_add(command_dict, "load", &execute_load);
        dict_add(command_dict, "w", &execute_save);
        dict_add(command_dict, "write", &execute_save);
        dict_add(command_dict, "print", &execute_print);
        dict_add(command_dict, "p", &execute_print);
        dict_add(command_dict, "c", &execute_change);
        dict_add(command_dict, "change", &execute_change);
    }
    return command_dict;
}

canonical_original_code:
struct DictionaryT *get_command_dict() {
    static struct DictionaryT *command_dict = ((void *)0);
    if (command_dict == ((void *)0)) {
        command_dict = Dict();
        dict_add(command_dict, "n", &execute_new);
        dict_add(command_dict, "new", &execute_new);
        dict_add(command_dict, "f", &execute_finish);
        dict_add(command_dict, "finish", &execute_finish);
        dict_add(command_dict, "s", &execute_show);
        dict_add(command_dict, "show", &execute_show);
        dict_add(command_dict, "a", &execute_add_note);
        dict_add(command_dict, "add", &execute_add_note);
        dict_add(command_dict, "l", &execute_load);
        dict_add(command_dict, "load", &execute_load);
        dict_add(command_dict, "w", &execute_save);
        dict_add(command_dict, "write", &execute_save);
        dict_add(command_dict, "print", &execute_print);
        dict_add(command_dict, "p", &execute_print);
        dict_add(command_dict, "c", &execute_change);
        dict_add(command_dict, "change", &execute_change);
    }
    return command_dict;
}

variable_types: struct DictionaryT { struct DictionaryNodeT { char *key; void *value; unsigned int hash; struct DictionaryNodeT *next; } **list; int capacity; int size; } *

user_defined_types: struct DictionaryT { struct DictionaryNodeT **list; int capacity; int size; }


decompiled_code:
int __fastcall execute_command(char *src, __int64 a2, __int64 a3)
{
signed __int64 v4; // rax
int v5; // ebx
__int64 v6; // rax
__int64 (__fastcall *v7)(char *, __int64, __int64); // rbx
char *v9; // r14
__int64 v10; // rax

if ( !src || !*src )
_assert_fail("command != NULL && strlen(command) != 0", "src/main.c", 0x5Au, "execute_command");
v4 = strchr(src, 32) - src;
v5 = v4;
if ( (int)v4 > 0 )
{
v9 = (char *)malloc((int)v4 + 1);
strncpy(v9, src, v5);
v10 = get_command_dict();
v7 = (__int64 (__fastcall *)(char *, __int64, __int64))dict_obj_at(v10, v9);
if ( v7 )
{
free(v9);
return v7(src, a2, a3);
}
}
else
{
v6 = get_command_dict();
v7 = (__int64 (__fastcall *)(char *, __int64, __int64))dict_obj_at(v6, src);
if ( v7 )
return v7(src, a2, a3);
}
return puts("Invalid command");
}

canonical_decompiled_code:
int __fastcall func1(char *src, __int64 a2, __int64 a3)
{
signed __int64 v4; // rax
int v5; // ebx
__int64 v6; // rax
__int64 (__fastcall *v7)(char *, __int64, __int64); // rbx
char *v9; // r14
__int64 v10; // rax

if ( !src || !*src )
_assert_fail("command != NULL && strlen(command) != 0", "src/main.c", 0x5Au, "execute_command");
v4 = strchr(src, 32) - src;
v5 = v4;
if ( (int)v4 > 0 )
{
v9 = (char *)malloc((int)v4 + 1);
strncpy(v9, src, v5);
v10 = func0();
v7 = (__int64 (__fastcall *)(char *, __int64, __int64))dict_obj_at(v10, v9);
if ( v7 )
{
free(v9);
return v7(src, a2, a3);
}
}
else
{
v6 = func0();
v7 = (__int64 (__fastcall *)(char *, __int64, __int64))dict_obj_at(v6, src);
if ( v7 )
return v7(src, a2, a3);
}
return puts("Invalid command");
}

original_code:
void execute_command(char* command, ListT* tasks, TaskT** current) {
    ((void) sizeof ((command != ((void *)0) && strlen(command) != 0) ? 1 : 0), __extension__ ({ if (command != ((void *)0) && strlen(command) != 0) ; else __assert_fail ("command != NULL && strlen(command) != 0", "src/main.c", 90, __extension__ __PRETTY_FUNCTION__); }));
    char* command_token = command;
    void (*command_executor)(char*, ListT*, TaskT**) = ((void *)0);
    int space_idx = -1;
    space_idx = strstr(command, " ") - command;
    if (space_idx > 0) {
        command_token = malloc(sizeof(char) * (space_idx + 1));
        strncpy(command_token, command, space_idx);
    }
    command_executor = dict_obj_at(get_command_dict(), command_token);
    if (command_executor == ((void *)0)) {
        puts("Invalid command");
        return;
    }
    if (space_idx > 0) {
        free(command_token);
    }
    command_executor(command, tasks, current);
}

canonical_original_code:
void execute_command(char *command, struct ListT *tasks, struct TaskT **current) {
    ((void) sizeof ((command != ((void *)0) && strlen(command) != 0) ? 1 : 0), __extension__ ({ if (command != ((void *)0) && strlen(command) != 0) ; else __assert_fail ("command != NULL && strlen(command) != 0", "src/main.c", 90, __extension__ __PRETTY_FUNCTION__); }));
    char *command_token = command;
    void (*command_executor)(char *, struct ListT *, struct TaskT **) = ((void *)0);
    int space_idx = -1;
    space_idx = strstr(command, " ") - command;
    if (space_idx > 0) {
        command_token = malloc(sizeof(char) * (space_idx + 1));
        strncpy(command_token, command, space_idx);
    }
    command_executor = dict_obj_at(get_command_dict(), command_token);
    if (command_executor == ((void *)0)) {
        puts("Invalid command");
        return;
    }
    if (space_idx > 0) {
        free(command_token);
    }
    command_executor(command, tasks, current);
}

variable_types:
command
char *

variable_types: void (*)(char *, struct ListT { void **values; void **last_value; int size; int capacity; } *, struct TaskT { char *text; struct ListT *notes; struct ListT *children; int is_complete; struct TaskT *parent; } **)


decompiled_code:
__int64 __fastcall do_quit(char *a1)
{
char *v1; // rax
__int64 result; // rax

v1 = strstr(a1, "quit");
if ( *a1 != 113 || a1[1] )
result = (v1 != 0LL) & (unsigned __int8)(a1 == v1);
else
result = 1LL;
return result;
}

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

v1 = strstr(a1, "quit");
if ( *a1 != 113 || a1[1] )
result = (v1 != 0LL) & (unsigned __int8)(a1 == v1);
else
result = 1LL;
return result;
}

original_code:
int do_quit(char* command) {
    char* substr = strstr(command, kQuitString);
    return strcmp(command, kQuitStringAbbr) == 0
        || (substr != ((void *)0) && ((substr - command) == 0));
}

canonical_original_code:
int do_quit(char *command) {
    char *substr = strstr(command, kQuitString);
    return strcmp(command, kQuitStringAbbr) == 0
        || (substr != ((void *)0) && ((substr - command) == 0));
}

variable_types:
substr
char *