decompiled_code:
__int64 __fastcall encode_and_post(__int64 a1, __int64 *a2, __int64 *a3)
{
__int64 *v3; // r14
__int64 v5; // r12
__int64 v6; // rbp
pthread_rwlock_t **v7; // r12
__int64 *v8; // r13
int v9; // er14
pthread_t *v10; // r15
pthread_rwlock_t *v11; // rax
__int64 *v12; // rcx
pthread_t *v13; // rdi
struct stat *v14; // r12
int v15; // er12
unsigned int i; // er15
unsigned int v17; // ecx
__int64 *v18; // r15
int v19; // er12
unsigned int j; // er14
const char ***v21; // r13
unsigned int v22; // ecx
__int64 v23; // r12
char *v24; // r14
pthread_rwlock_t *v25; // rdi
pthread_t v26; // rdi
int v27; // er12
pthread_rwlock_t **v28; // rbp
pthread_rwlock_t *v29; // rdi
int *v31; // rax
pthread_rwlock_t **ptr; // [rsp+8h] [rbp-60h]
pthread_t *newthread; // [rsp+10h] [rbp-58h]
__int64 *arg; // [rsp+20h] [rbp-48h]

v3 = a2;
v5 = *(int *)(a1 + 64);
newthread = (pthread_t *)malloc(8 * v5);
ptr = (pthread_rwlock_t **)malloc(32 * v5);
arg = (__int64 *)malloc(24 * v5);
v6 = queue_init((unsigned int)(2 * v5));
if ( *(int *)(a1 + 64) > 0 )
{
v7 = ptr;
v8 = arg;
v9 = 0;
v10 = newthread;
do
{
++v9;
*((_DWORD *)v7 + 4) = 0;
*(_DWORD *)v7 = v9;
v7[3] = 0LL;
v11 = (pthread_rwlock_t *)malloc(0x38uLL);
v7[1] = v11;
pthread_rwlock_init(v11, 0LL);
v8[1] = (__int64)v7;
v12 = v8;
v13 = v10;
*v8 = a1;
v7 += 4;
v8[2] = v6;
++v10;
v8 += 3;
pthread_create(v13, 0LL, poster_thread, v12);
}
while ( v9 < *(_DWORD *)(a1 + 64) );
v3 = a2;
}
if ( *(_QWORD *)(a1 + 80) )
{
v14 = (struct stat *)file_entry_alloc(0LL);
v14[1].st_dev = buff_create(v14[1].st_dev, "%s", **(_QWORD **)(a1 + 80));
if ( stat(**(const char ***)(a1 + 80), v14) == -1 )
{
v31 = _errno_location();
ui_sfv_gen_error(**(_QWORD **)(a1 + 80), (unsigned int)*v31);
}
else
{
post_file(a1, v6, (__int64)v14, 1u, 1u, (__int64)"SFV File");
unlink(**(const char ***)(a1 + 80));
}
free(v14);
}
v15 = 1;
for ( i = slist_length(v3); v3; v3 = (__int64 *)slist_next(v3) )
{
v17 = v15++;
post_file(a1, v6, *v3, v17, i, (__int64)"File");
}
v18 = a3;
v19 = 1;
for ( j = slist_length(a3); v18; v18 = (__int64 *)slist_next(v18) )
{
v21 = (const char ***)*v18;
v22 = v19++;
post_file(a1, v6, *v18, v22, j, (__int64)"PAR File");
unlink(*v21[18]);
buff_free(v21[18]);
free(v21);
}
v23 = 0LL;
slist_free(a3);
pthread_mutex_lock(*(pthread_mutex_t **)(v6 + 40));
*(_BYTE *)(v6 + 34) = 1;
pthread_mutex_unlock(*(pthread_mutex_t **)(v6 + 40));
pthread_cond_broadcast(*(pthread_cond_t **)(v6 + 64));
pthread_mutex_lock(*(pthread_mutex_t **)(v6 + 40));
pthread_cond_wait(*(pthread_cond_t **)(v6 + 72), *(pthread_mutex_t **)(v6 + 40));
pthread_mutex_unlock(*(pthread_mutex_t **)(v6 + 40));
pthread_cond_broadcast(*(pthread_cond_t **)(v6 + 56));
v24 = (char *)(ptr + 1);
if ( *(int *)(a1 + 64) > 0 )
{
do
{
pthread_rwlock_rdlock(*(pthread_rwlock_t **)v24);
if ( *((_DWORD *)v24 + 2) == 1 )
pthread_cancel(newthread[v23]);
v25 = *(pthread_rwlock_t **)v24;
v24 += 32;
pthread_rwlock_unlock(v25);
v26 = newthread[v23++];
pthread_join(v26, 0LL);
}
while ( *(_DWORD *)(a1 + 64) > (int)v23 );
}
v27 = 0;
queue_delete(v6);
v28 = ptr + 1;
if ( *(int *)(a1 + 64) > 0 )
{
do
{
v29 = *v28;
++v27;
v28 += 4;
pthread_rwlock_destroy(v29);
free(*(v28 - 4));
}
while ( *(_DWORD *)(a1 + 64) > v27 );
}
free(ptr);
free(arg);
free(newthread);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 *a2, __int64 *a3)
{
__int64 *v3; // r14
__int64 v5; // r12
__int64 v6; // rbp
pthread_rwlock_t **v7; // r12
__int64 *v8; // r13
int v9; // er14
pthread_t *v10; // r15
pthread_rwlock_t *v11; // rax
__int64 *v12; // rcx
pthread_t *v13; // rdi
struct stat *v14; // r12
int v15; // er12
unsigned int i; // er15
unsigned int v17; // ecx
__int64 *v18; // r15
int v19; // er12
unsigned int j; // er14
const char ***v21; // r13
unsigned int v22; // ecx
__int64 v23; // r12
char *v24; // r14
pthread_rwlock_t *v25; // rdi
pthread_t v26; // rdi
int v27; // er12
pthread_rwlock_t **v28; // rbp
pthread_rwlock_t *v29; // rdi
int *v31; // rax
pthread_rwlock_t **ptr; // [rsp+8h] [rbp-60h]
pthread_t *newthread; // [rsp+10h] [rbp-58h]
__int64 *arg; // [rsp+20h] [rbp-48h]

v3 = a2;
v5 = *(int *)(a1 + 64);
newthread = (pthread_t *)malloc(8 * v5);
ptr = (pthread_rwlock_t **)malloc(32 * v5);
arg = (__int64 *)malloc(24 * v5);
v6 = queue_init((unsigned int)(2 * v5));
if ( *(int *)(a1 + 64) > 0 )
{
v7 = ptr;
v8 = arg;
v9 = 0;
v10 = newthread;
do
{
++v9;
*((_DWORD *)v7 + 4) = 0;
*(_DWORD *)v7 = v9;
v7[3] = 0LL;
v11 = (pthread_rwlock_t *)malloc(0x38uLL);
v7[1] = v11;
pthread_rwlock_init(v11, 0LL);
v8[1] = (__int64)v7;
v12 = v8;
v13 = v10;
*v8 = a1;
v7 += 4;
v8[2] = v6;
++v10;
v8 += 3;
pthread_create(v13, 0LL, poster_thread, v12);
}
while ( v9 < *(_DWORD *)(a1 + 64) );
v3 = a2;
}
if ( *(_QWORD *)(a1 + 80) )
{
v14 = (struct stat *)file_entry_alloc(0LL);
v14[1].st_dev = buff_create(v14[1].st_dev, "%s", **(_QWORD **)(a1 + 80));
if ( stat(**(const char ***)(a1 + 80), v14) == -1 )
{
v31 = _errno_location();
ui_sfv_gen_error(**(_QWORD **)(a1 + 80), (unsigned int)*v31);
}
else
{
post_file(a1, v6, (__int64)v14, 1u, 1u, (__int64)"SFV File");
unlink(**(const char ***)(a1 + 80));
}
free(v14);
}
v15 = 1;
for ( i = slist_length(v3); v3; v3 = (__int64 *)slist_next(v3) )
{
v17 = v15++;
post_file(a1, v6, *v3, v17, i, (__int64)"File");
}
v18 = a3;
v19 = 1;
for ( j = slist_length(a3); v18; v18 = (__int64 *)slist_next(v18) )
{
v21 = (const char ***)*v18;
v22 = v19++;
post_file(a1, v6, *v18, v22, j, (__int64)"PAR File");
unlink(*v21[18]);
buff_free(v21[18]);
free(v21);
}
v23 = 0LL;
slist_free(a3);
pthread_mutex_lock(*(pthread_mutex_t **)(v6 + 40));
*(_BYTE *)(v6 + 34) = 1;
pthread_mutex_unlock(*(pthread_mutex_t **)(v6 + 40));
pthread_cond_broadcast(*(pthread_cond_t **)(v6 + 64));
pthread_mutex_lock(*(pthread_mutex_t **)(v6 + 40));
pthread_cond_wait(*(pthread_cond_t **)(v6 + 72), *(pthread_mutex_t **)(v6 + 40));
pthread_mutex_unlock(*(pthread_mutex_t **)(v6 + 40));
pthread_cond_broadcast(*(pthread_cond_t **)(v6 + 56));
v24 = (char *)(ptr + 1);
if ( *(int *)(a1 + 64) > 0 )
{
do
{
pthread_rwlock_rdlock(*(pthread_rwlock_t **)v24);
if ( *((_DWORD *)v24 + 2) == 1 )
pthread_cancel(newthread[v23]);
v25 = *(pthread_rwlock_t **)v24;
v24 += 32;
pthread_rwlock_unlock(v25);
v26 = newthread[v23++];
pthread_join(v26, 0LL);
}
while ( *(_DWORD *)(a1 + 64) > (int)v23 );
}
v27 = 0;
queue_delete(v6);
v28 = ptr + 1;
if ( *(int *)(a1 + 64) > 0 )
{
do
{
v29 = *v28;
++v27;
v28 += 4;
pthread_rwlock_destroy(v29);
free(*(v28 - 4));
}
while ( *(_DWORD *)(a1 + 64) > v27 );
}
free(ptr);
free(arg);
free(newthread);
return 0LL;
}

original_code:
static int encode_and_post(newspost_data *data, SList *file_list,
       SList *parfiles) {
 int number_of_files;
 int i, j;
 file_entry *file_data = ((void *)0);
 int retval = 0;
 pthread_t *thread_array =
  (pthread_t *) malloc(data->threads * sizeof(pthread_t));
 newspost_threadinfo *threadinfo_array =
  (newspost_threadinfo *) malloc(data->threads * sizeof(newspost_threadinfo));
 poster_thread_arg *poster_args =
  (poster_thread_arg *) malloc(data->threads * sizeof(poster_thread_arg));
 queue *fifo;
 fifo = queue_init(data->threads * 2);
 for(j = 0; j < data->threads; j++) {
  threadinfo_array[j].thread_id = j+1;
  threadinfo_array[j].status = 0;
  threadinfo_array[j].bytes_written = 0;
  threadinfo_array[j].rwlock = (pthread_rwlock_t *) malloc(sizeof(pthread_rwlock_t));
  pthread_rwlock_init(threadinfo_array[j].rwlock, ((void *)0));
  poster_args[j].data = data;
  poster_args[j].threadinfo = &threadinfo_array[j];
  poster_args[j].fifo = fifo;
  pthread_create(&thread_array[j], ((void *)0), poster_thread, &poster_args[j]);
 }
 if (data->sfv != ((void *)0)) {
  file_data = file_entry_alloc(file_data);
  file_data->filename =
   buff_create(file_data->filename, "%s", data->sfv->data);
  if (stat(data->sfv->data, &file_data->fileinfo) == -1)
   ui_sfv_gen_error(data->sfv->data, (*__errno_location ()));
  else {
   post_file(data, fifo, file_data, 1, 1, "SFV File");
   unlink(data->sfv->data);
  }
  free(file_data);
 }
 number_of_files = slist_length(file_list);
 i = 1;
 while (file_list != ((void *)0)) {
  file_data = (file_entry *) file_list->data;
  post_file(data, fifo, file_data, i, number_of_files, "File");
  i++;
  file_list = slist_next(file_list);
 }
 i = 1;
 file_list = parfiles;
 number_of_files = slist_length(parfiles);
 while (file_list != ((void *)0)) {
  file_data = (file_entry *) file_list->data;
  post_file(data, fifo, file_data, i, number_of_files, "PAR File");
  unlink(file_data->filename->data);
  buff_free(file_data->filename);
  free(file_data);
  i++;
  file_list = slist_next(file_list);
 }
 slist_free(parfiles);
 pthread_mutex_lock(fifo->mut);
 fifo->producer_done = 1;
 pthread_mutex_unlock(fifo->mut);
 pthread_cond_broadcast(fifo->cond_producer_done);
 pthread_mutex_lock(fifo->mut);
 pthread_cond_wait(fifo->cond_empty, fifo->mut);
 pthread_mutex_unlock(fifo->mut);
 pthread_cond_broadcast(fifo->cond_not_empty);
 for(j = 0; j < data->threads; j++) {
  pthread_rwlock_rdlock(threadinfo_array[j].rwlock);
  if (threadinfo_array[j].status == 1)
   pthread_cancel(thread_array[j]);
  pthread_rwlock_unlock(threadinfo_array[j].rwlock);
  pthread_join(thread_array[j], ((void *)0));
 }
 queue_delete(fifo);
 for(j = 0; j < data->threads; j++) {
  pthread_rwlock_destroy(threadinfo_array[j].rwlock);
  free(threadinfo_array[j].rwlock);
 }
 free(threadinfo_array);
 free(poster_args);
 free(thread_array);
 return retval;
}

canonical_original_code:
static int encode_and_post(struct newspost_data *data, struct Newspost_SList *file_list, struct Newspost_SList *parfiles) {
 int number_of_files;
 int i; int j;
 struct file_entry *file_data = ((void *)0);
 int retval = 0;
 unsigned long *thread_array = (pthread_t *) malloc(data->threads * sizeof(pthread_t));
 struct newspost_threadinfo *threadinfo_array = (newspost_threadinfo *) malloc(data->threads * sizeof(newspost_threadinfo));
 struct poster_thread_arg *poster_args = (poster_thread_arg *) malloc(data->threads * sizeof(poster_thread_arg));
 struct queue *fifo;
 fifo = queue_init(data->threads * 2);
 for(j = 0; j < data->threads; j++) {
  threadinfo_array[j].thread_id = j+1;
  threadinfo_array[j].status = 0;
  threadinfo_array[j].bytes_written = 0;
  threadinfo_array[j].rwlock = (union pthread_rwlock_t *) malloc(sizeof(pthread_rwlock_t));
  pthread_rwlock_init(threadinfo_array[j].rwlock, ((void *)0));
  poster_args[j].data = data;
  poster_args[j].threadinfo = &threadinfo_array[j];
  poster_args[j].fifo = fifo;
  pthread_create(&thread_array[j], ((void *)0), poster_thread, &poster_args[j]);
 }
 if (data->sfv != ((void *)0)) {
  file_data = file_entry_alloc(file_data);
  file_data->filename =
   buff_create(file_data->filename, "%s", data->sfv->data);
  if (stat(data->sfv->data, &file_data->fileinfo) == -1)
   ui_sfv_gen_error(data->sfv->data, (*__errno_location ()));
  else {
   post_file(data, fifo, file_data, 1, 1, "SFV File");
   unlink(data->sfv->data);
  }
  free(file_data);
 }
 number_of_files = slist_length(file_list);
 i = 1;
 while (file_list != ((void *)0)) {
  file_data = (struct file_entry *) file_list->data;
  post_file(data, fifo, file_data, i, number_of_files, "File");
  i++;
  file_list = slist_next(file_list);
 }
 i = 1;
 file_list = parfiles;
 number_of_files = slist_length(parfiles);
 while (file_list != ((void *)0)) {
  file_data = (struct file_entry *) file_list->data;
  post_file(data, fifo, file_data, i, number_of_files, "PAR File");
  unlink(file_data->filename->data);
  buff_free(file_data->filename);
  free(file_data);
  i++;
  file_list = slist_next(file_list);
 }
 slist_free(parfiles);
 pthread_mutex_lock(fifo->mut);
 fifo->producer_done = 1;
 pthread_mutex_unlock(fifo->mut);
 pthread_cond_broadcast(fifo->cond_producer_done);
 pthread_mutex_lock(fifo->mut);
 pthread_cond_wait(fifo->cond_empty, fifo->mut);
 pthread_mutex_unlock(fifo->mut);
 pthread_cond_broadcast(fifo->cond_not_empty);
 for(j = 0; j < data->threads; j++) {
  pthread_rwlock_rdlock(threadinfo_array[j].rwlock);
  if (threadinfo_array[j].status == 1)
   pthread_cancel(thread_array[j]);
  pthread_rwlock_unlock(threadinfo_array[j].rwlock);
  pthread_join(thread_array[j], ((void *)0));
 }
 queue_delete(fifo);
 for(j = 0; j < data->threads; j++) {
  pthread_rwlock_destroy(threadinfo_array[j].rwlock);
  free(threadinfo_array[j].rwlock);
 }
 free(threadinfo_array);
 free(poster_args);
 free(thread_array);
 return retval;
}

variable_types: struct newspost_data { struct Buff { char *data; long length; long real_length; } *subject; struct Buff *newsgroup; struct Buff *from; struct Buff *organization; struct Buff *address; int port; struct Buff *user; struct Buff *password; int threads; int lines; unsigned char uuenc; struct Buff *sfv; struct Buff *par; int parnum; int filesperpar; struct Buff *reference; unsigned char filenumber; struct Buff *tmpdir; unsigned char noarchive; struct Buff *followupto; struct Buff *replyto; struct Buff *name; unsigned char text; struct Newspost_SList { void *data; struct Newspost_SList *next; } *extra_headers; } *

variable_types:
parfiles
struct Newspost_SList *

variable_types: j int

variable_types: struct file_entry { struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } fileinfo; struct Buff { char *data; long length; long real_length; } *filename; unsigned int crc; unsigned char *parts; int number_enc_parts; int parts_to_post; union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } *rwlock; unsigned char post_started; int parts_posted; } *

variable_types: struct newspost_threadinfo { int thread_id; int sockfd; union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } *rwlock; int status; long bytes_written; } *

user_defined_types: struct queue { struct post_article_t *article_list; long length; long head; unsigned char full; union pthread_mutex_t *mut; union pthread_cond_t *cond_not_full; }


decompiled_code:
__int64 __fastcall post_text_file(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
unsigned int v3; // er13
_QWORD *v4; // rbp
int v6; // [rsp+0h] [rbp-48h] BYREF
unsigned int v7; // [rsp+4h] [rbp-44h]
pthread_rwlock_t *rwlock; // [rsp+8h] [rbp-40h]
__int64 v9; // [rsp+18h] [rbp-30h]

v9 = 0LL;
rwlock = (pthread_rwlock_t *)malloc(0x38uLL);
pthread_rwlock_init(rwlock, 0LL);
v2 = *(_QWORD **)(a1 + 32);
v6 = 1;
ui_socket_connect_start(&v6, *v2);
v7 = socket_create(**(_QWORD **)(a1 + 32), *(unsigned int *)(a1 + 40));
v3 = v7;
if ( (v7 & 0x80000000) == 0 )
{
ui_socket_connect_done(&v6);
ui_nntp_logon_start(&v6, **(_QWORD **)(a1 + 32));
if ( (unsigned __int8)nntp_logon(&v6, a1) )
{
ui_nntp_logon_done(&v6);
v4 = (_QWORD *)read_text_file_constprop_0(**(char ***)(*(_QWORD *)a2 + 144LL));
if ( v4 )
v3 = nntp_post(&v6, **(_QWORD **)a1, a1, *v4, v4[1], 1LL);
pthread_rwlock_destroy(rwlock);
free(rwlock);
buff_free(v4);
}
else
{
v3 = -4;
socket_close(v7);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
unsigned int v3; // er13
_QWORD *v4; // rbp
int v6; // [rsp+0h] [rbp-48h] BYREF
unsigned int v7; // [rsp+4h] [rbp-44h]
pthread_rwlock_t *rwlock; // [rsp+8h] [rbp-40h]
__int64 v9; // [rsp+18h] [rbp-30h]

v9 = 0LL;
rwlock = (pthread_rwlock_t *)malloc(0x38uLL);
pthread_rwlock_init(rwlock, 0LL);
v2 = *(_QWORD **)(a1 + 32);
v6 = 1;
ui_socket_connect_start(&v6, *v2);
v7 = socket_create(**(_QWORD **)(a1 + 32), *(unsigned int *)(a1 + 40));
v3 = v7;
if ( (v7 & 0x80000000) == 0 )
{
ui_socket_connect_done(&v6);
ui_nntp_logon_start(&v6, **(_QWORD **)(a1 + 32));
if ( (unsigned __int8)nntp_logon(&v6, a1) )
{
ui_nntp_logon_done(&v6);
v4 = (_QWORD *)func4(**(char ***)(*(_QWORD *)a2 + 144LL));
if ( v4 )
v3 = nntp_post(&v6, **(_QWORD **)a1, a1, *v4, v4[1], 1LL);
pthread_rwlock_destroy(rwlock);
free(rwlock);
buff_free(v4);
}
else
{
v3 = -4;
socket_close(v7);
}
}
return v3;
}

original_code:
static int post_text_file(newspost_data *data, SList *file_list) {
 file_entry *file_data = ((void *)0);
 int retval = 0;
 Buff *text_buffer = ((void *)0);
 newspost_threadinfo tinfo;
 tinfo.bytes_written = 0;
 tinfo.rwlock = (pthread_rwlock_t *) malloc(sizeof(pthread_rwlock_t));
 pthread_rwlock_init(tinfo.rwlock, ((void *)0));
 tinfo.thread_id = 1;
 ui_socket_connect_start(&tinfo, data->address->data);
 tinfo.sockfd = socket_create(data->address->data, data->port);
 retval = tinfo.sockfd;
 if (retval < 0)
  return retval;
 ui_socket_connect_done(&tinfo);
 ui_nntp_logon_start(&tinfo, data->address->data);
 if (nntp_logon(&tinfo, data) == 0) {
  socket_close(tinfo.sockfd);
  return -4;
 }
 ui_nntp_logon_done(&tinfo);
 file_data = file_list->data;
 text_buffer = read_text_file(text_buffer, file_data->filename->data);
 if(text_buffer != ((void *)0))
  retval = nntp_post(&tinfo, data->subject->data, data, text_buffer->data,
     text_buffer->length, 1);
 pthread_rwlock_destroy(tinfo.rwlock);
 free(tinfo.rwlock);
 buff_free(text_buffer);
 return retval;
}

canonical_original_code:
static int post_text_file(struct newspost_data *data, struct Newspost_SList *file_list) {
 struct file_entry *file_data = ((void *)0);
 int retval = 0;
 struct Buff *text_buffer = ((void *)0);
 struct newspost_threadinfo tinfo;
 tinfo.bytes_written = 0;
 tinfo.rwlock = (union pthread_rwlock_t *) malloc(sizeof(pthread_rwlock_t));
 pthread_rwlock_init(tinfo.rwlock, ((void *)0));
 tinfo.thread_id = 1;
 ui_socket_connect_start(&tinfo, data->address->data);
 tinfo.sockfd = socket_create(data->address->data, data->port);
 retval = tinfo.sockfd;
 if (retval < 0)
  return retval;
 ui_socket_connect_done(&tinfo);
 ui_nntp_logon_start(&tinfo, data->address->data);
 if (nntp_logon(&tinfo, data) == 0) {
  socket_close(tinfo.sockfd);
  return -4;
 }
 ui_nntp_logon_done(&tinfo);
 file_data = file_list->data;
 text_buffer = read_text_file(text_buffer, file_data->filename->data);
 if(text_buffer != ((void *)0))
  retval = nntp_post(&tinfo, data->subject->data, data, text_buffer->data,
     text_buffer->length, 1);
 pthread_rwlock_destroy(tinfo.rwlock);
 free(tinfo.rwlock);
 buff_free(text_buffer);
 return retval;
}

variable_types: retval int

variable_types: struct Buff { char *data; long length; long real_length; } *

variable_types: struct newspost_threadinfo { int thread_id; int sockfd; union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } *rwlock; int status; long bytes_written; }

return_type: int

user_defined_types: struct newspost_threadinfo { int thread_id; int sockfd; union pthread_rwlock_t *rwlock; int status; long bytes_written; }

user_defined_types: struct newspost_data { struct Buff *subject; struct Buff *newsgroup; struct Buff *from; struct Buff *organization; struct Buff *address; int port; struct Buff *user; struct Buff *password; int threads; int lines; unsigned char uuenc; struct Buff *sfv; struct Buff *par; int parnum; int filesperpar; struct Buff *reference; unsigned char filenumber; struct Buff *tmpdir; unsigned char noarchive; struct Buff *followupto; struct Buff *replyto; struct Buff *name; unsigned char text; struct Newspost_SList *extra_headers; }

user_defined_types: struct file_entry { struct stat fileinfo; struct Buff *filename; unsigned int crc; unsigned char *parts; int number_enc_parts; int parts_to_post; union pthread_rwlock_t *rwlock; unsigned char post_started; int parts_posted; }

user_defined_types: union pthread_rwlock_t { struct __pthread_rwlock_arch_t __data; char __size[56]; long __align; }

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

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

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


newspost

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

v2 = 0LL;
if ( !*(_BYTE *)(a1 + 160) )
v2 = (__int64 *)preprocess(a1, (__int64)a2);
ui_post_start(a1, a2, v2);
if ( *(_BYTE *)(a1 + 160) == 1 )
result = post_text_file(a1, (__int64)a2);
else
result = encode_and_post(a1, a2, v2);
return result;
}

original_code:
int newspost(newspost_data *data, SList *file_list) {
 int retval;
 SList *parfiles = ((void *)0);
 if (data->text == 0)
  parfiles = preprocess(data, file_list);
 ui_post_start(data, file_list, parfiles);
 if (data->text == 1)
  retval = post_text_file(data, file_list);
 else
  retval = encode_and_post(data, file_list, parfiles);
 return retval;
}

canonical_original_code:
int newspost(struct newspost_data *data, struct Newspost_SList *file_list) {
 int retval;
 struct Newspost_SList *parfiles = ((void *)0);
 if (data->text == 0)
  parfiles = preprocess(data, file_list);
 ui_post_start(data, file_list, parfiles);
 if (data->text == 1)
  retval = post_text_file(data, file_list);
 else
  retval = encode_and_post(data, file_list, parfiles);
 return retval;
}

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

user_defined_types: struct Buff { char *data; long length; long real_length; }


decompiled_code:
__int64 __fastcall p_basename(_WORD *a1)
{
__int16 v1; // ax
_WORD *v2; // r8
bool v3; // zf

v1 = *a1;
v2 = a1;
while ( v1 )
{
++a1;
v3 = v1 == 47;
v1 = *a1;
if ( v3 )
v2 = a1;
}
return stuni(v2);
}

original_code:
char *
p_basename(u16 *path)
{
 u16 *ret;
 for (ret = path; *path; path++)
  if (*path == '/')
   ret = path + 1;
 return stuni(ret);
}

canonical_original_code:
char *p_basename(unsigned short *path)
{
 unsigned short *ret;
 for (ret = path; *path; path++)
  if (*path == '/')
   ret = path + 1;
 return stuni(ret);
}

variable_types:
path
unsigned short *

variable_types:
ret
unsigned short *

return_type: char *


decompiled_code:
__int64 __fastcall unicode_gt(unsigned __int16 *a1, _WORD *a2)
{
int v4; // edi
int v5; // ebx
int v6; // eax

while ( 1 )
{
v4 = *a1;
if ( !(_WORD)v4 && !*a2 )
break;
v5 = tolower(v4);
v6 = tolower((unsigned __int16)*a2);
if ( v6 < v5 )
return 1LL;
if ( v6 > v5 )
break;
++a1;
++a2;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 *a1, _WORD *a2)
{
int v4; // edi
int v5; // ebx
int v6; // eax

while ( 1 )
{
v4 = *a1;
if ( !(_WORD)v4 && !*a2 )
break;
v5 = tolower(v4);
v6 = tolower((unsigned __int16)*a2);
if ( v6 < v5 )
return 1LL;
if ( v6 > v5 )
break;
++a1;
++a2;
}
return 0LL;
}

original_code:
int
unicode_gt(u16 *a, u16 *b)
{
 for (; *a || *b; a++, b++) {
  if (tolower(*a) > tolower(*b)) return 1;
  if (tolower(*a) < tolower(*b)) return 0;
 }
 return 0;
}

canonical_original_code:
int unicode_gt(unsigned short *a, unsigned short *b)
{
 for (; *a || *b; a++, b++) {
  if (tolower(*a) > tolower(*b)) return 1;
  if (tolower(*a) < tolower(*b)) return 0;
 }
 return 0;
}

variable_types:
a
unsigned short *

variable_types:
b
unsigned short *


decompiled_code:
__int64 __fastcall unicode_cmp(unsigned __int16 *a1, _WORD *a2)
{
_WORD *v2; // rbp
unsigned __int16 *v3; // rbx
unsigned __int16 v4; // ax
__int64 result; // rax
__int16 v6; // r13
int v7; // er12

v2 = a2;
v3 = a1;
v4 = *a1;
if ( *a1 == *a2 )
{
while ( v4 )
{
++v2;
v4 = *++v3;
if ( *v3 != *v2 )
goto LABEL_6;
}
result = 0LL;
}
else
{
LABEL_6:
if ( (cmd[12] & 0x10) == 0 )
{
while ( 1 )
{
v6 = *v3;
v7 = tolower(*v3);
if ( v7 != tolower((unsigned __int16)*v2) )
break;
if ( !v6 )
return 1LL;
++v3;
++v2;
}
}
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 *a1, _WORD *a2)
{
_WORD *v2; // rbp
unsigned __int16 *v3; // rbx
unsigned __int16 v4; // ax
__int64 result; // rax
__int16 v6; // r13
int v7; // er12

v2 = a2;
v3 = a1;
v4 = *a1;
if ( *a1 == *a2 )
{
while ( v4 )
{
++v2;
v4 = *++v3;
if ( *v3 != *v2 )
goto LABEL_6;
}
result = 0LL;
}
else
{
LABEL_6:
if ( (cmd[12] & 0x10) == 0 )
{
while ( 1 )
{
v6 = *v3;
v7 = tolower(*v3);
if ( v7 != tolower((unsigned __int16)*v2) )
break;
if ( !v6 )
return 1LL;
++v3;
++v2;
}
}
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
unicode_cmp(u16 *a, u16 *b)
{
 for (; *a == *b; a++, b++)
  if (!*a) return 0;
 if (!cmd.usecase)
  for (; tolower(*a) == tolower(*b); a++, b++)
   if (!*a) return 1;
 return -1;
}

canonical_original_code:
int unicode_cmp(unsigned short *a, unsigned short *b)
{
 for (; *a == *b; a++, b++)
  if (!*a) return 0;
 if (!cmd.usecase)
  for (; tolower(*a) == tolower(*b); a++, b++)
   if (!*a) return 1;
 return -1;
}


decompiled_code:
__int64 __fastcall hfile_add(__int64 a1)
{
__int64 *v1; // rax
__int64 *v2; // rdx
__int64 *v3; // rbx
_QWORD *v4; // rax

v1 = (__int64 *)hfile;
if ( hfile )
{
do
{
v2 = v1;
v1 = (__int64 *)*v1;
}
while ( v1 );
v3 = v2;
}
else
{
v3 = &hfile;
}
v4 = calloc(0x48uLL, 1uLL);
*v3 = (__int64)v4;
v4[6] = unicode_copy(a1);
return *v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 *v1; // rax
__int64 *v2; // rdx
__int64 *v3; // rbx
_QWORD *v4; // rax

v1 = (__int64 *)hfile;
if ( hfile )
{
do
{
v2 = v1;
v1 = (__int64 *)*v1;
}
while ( v1 );
v3 = v2;
}
else
{
v3 = &hfile;
}
v4 = calloc(0x48uLL, 1uLL);
*v3 = (__int64)v4;
v4[6] = unicode_copy(a1);
return *v3;
}

original_code:
hfile_t *
hfile_add(u16 *filename)
{
 hfile_t **pp;
 for (pp = &hfile; *pp; pp = &((*pp)->next))
  ;
 ((*pp) = (calloc(sizeof(*(*pp)), (1))));
 (*pp)->filename = unicode_copy(filename);
 return (*pp);
}

canonical_original_code:
struct hfile_s *hfile_add(unsigned short *filename)
{
 struct hfile_s **pp;
 for (pp = &hfile; *pp; pp = &((*pp)->next))
  ;
 ((*pp) = (calloc(sizeof(*(*pp)), (1))));
 (*pp)->filename = unicode_copy(filename);
 return (*pp);
}

variable_types:
filename
unsigned short *

variable_types: struct hfile_s { struct hfile_s *next; unsigned char hash_16k[16]; unsigned char hash[16]; long long file_size; unsigned short *filename; char *dir; unsigned char hashed; } **


decompiled_code:
void hash_directory()
{
_QWORD *v0; // rbp
__int64 *v1; // rbx
unsigned __int16 *v2; // r12
_QWORD *v3; // rbx
_QWORD *v4; // rax

v0 = (_QWORD *)read_dir();
while ( v0 )
{
v1 = (__int64 *)hfile;
if ( hfile )
{
v2 = (unsigned __int16 *)v0[6];
while ( (unsigned int)unicode_cmp(v2, (_WORD *)v1[6]) )
{
if ( !*v1 )
goto LABEL_11;
v1 = (__int64 *)*v1;
}
v3 = (_QWORD *)*v0;
free(v0);
v0 = v3;
}
else
{
v1 = &hfile;
LABEL_11:
*v1 = (__int64)v0;
v4 = (_QWORD *)*v0;
*v0 = 0LL;
v0 = v4;
}
}
}

canonical_decompiled_code:
void func4()
{
_QWORD *v0; // rbp
__int64 *v1; // rbx
unsigned __int16 *v2; // r12
_QWORD *v3; // rbx
_QWORD *v4; // rax

v0 = (_QWORD *)read_dir();
while ( v0 )
{
v1 = (__int64 *)hfile;
if ( hfile )
{
v2 = (unsigned __int16 *)v0[6];
while ( (unsigned int)func2(v2, (_WORD *)v1[6]) )
{
if ( !*v1 )
goto LABEL_11;
v1 = (__int64 *)*v1;
}
v3 = (_QWORD *)*v0;
free(v0);
v0 = v3;
}
else
{
v1 = &hfile;
LABEL_11:
*v1 = (__int64)v0;
v4 = (_QWORD *)*v0;
*v0 = 0LL;
v0 = v4;
}
}
}

original_code:
void
hash_directory(char *dir)
{
 hfile_t *p, *q, **pp;
 for (p = read_dir(dir); p; ) {
  for (pp = &hfile; *pp; pp = &((*pp)->next))
   if (!unicode_cmp(p->filename, (*pp)->filename))
    break;
  if (*pp) {
   q = p;
   p = p->next;
   free(q);
  } else {
   *pp = p;
   p = p->next;
   (*pp)->next = 0;
  }
 }
}

canonical_original_code:
void hash_directory(char *dir)
{
 struct hfile_s *p; struct hfile_s *q; struct hfile_s **pp;
 for (p = read_dir(dir); p; ) {
  for (pp = &hfile; *pp; pp = &((*pp)->next))
   if (!unicode_cmp(p->filename, (*pp)->filename))
    break;
  if (*pp) {
   q = p;
   p = p->next;
   free(q);
  } else {
   *pp = p;
   p = p->next;
   (*pp)->next = 0;
  }
 }
}

variable_types:
dir
char *

variable_types: struct hfile_s { struct hfile_s *next; unsigned char hash_16k[16]; unsigned char hash[16]; long long file_size; unsigned short *filename; char *dir; unsigned char hashed; } *

return_type: void


original_code:
int
hash_file(hfile_t *file, char type)
{
 i64 s;
 u8 buf[16384];
 if (type < 1) return 1;
 if (file->hashed < 1) {
  if (!file_md5_buffer(file->filename, file->hash_16k,
     buf, sizeof(buf)))
   return 0;
  file->hashed = 1;
 }
 if (type < 2) return 1;
 if (file->hashed < 2) {
  s = file_md5(file->filename, file->hash);
  if (s >= 0) {
   file->hashed = 2;
   if (!file->file_size)
    file->file_size = s;
  }
 }
 return 1;
}

canonical_original_code:
int hash_file(struct hfile_s *file, char type)
{
 long long s;
 unsigned char buf[16384];
 if (type < 1) return 1;
 if (file->hashed < 1) {
  if (!file_md5_buffer(file->filename, file->hash_16k,
     buf, sizeof(buf)))
   return 0;
  file->hashed = 1;
 }
 if (type < 2) return 1;
 if (file->hashed < 2) {
  s = file_md5(file->filename, file->hash);
  if (s >= 0) {
   file->hashed = 2;
   if (!file->file_size)
    file->file_size = s;
  }
 }
 return 1;
}

variable_types: type char

variable_types:
s
long long

variable_types:
buf
unsigned char [16384]

user_defined_types: struct hfile_s { struct hfile_s *next; unsigned char hash_16k[16]; unsigned char hash[16]; long long file_size; unsigned short *filename; char *dir; unsigned char hashed; }


decompiled_code:
__int64 __fastcall find_file_name(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rbx
_WORD *v5; // rbp
__int64 v6; // r12
int v7; // eax

stuni(a1);
hash_directory();
v1 = stuni(a1);
v2 = complete_path(v1);
v3 = unist(v2);
v4 = hfile;
if ( !hfile )
return 0LL;
v5 = (_WORD *)v3;
v6 = 0LL;
do
{
while ( 1 )
{
v7 = unicode_cmp(*(unsigned __int16 **)(v4 + 48), v5);
if ( v7 )
break;
v6 = v4;
v4 = *(_QWORD *)v4;
if ( !v4 )
return v6;
}
if ( v7 == 1 && !v6 )
v6 = v4;
v4 = *(_QWORD *)v4;
}
while ( v4 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rbx
_WORD *v5; // rbp
__int64 v6; // r12
int v7; // eax

stuni(a1);
func4();
v1 = stuni(a1);
v2 = complete_path(v1);
v3 = unist(v2);
v4 = hfile;
if ( !hfile )
return 0LL;
v5 = (_WORD *)v3;
v6 = 0LL;
do
{
while ( 1 )
{
v7 = func2(*(unsigned __int16 **)(v4 + 48), v5);
if ( v7 )
break;
v6 = v4;
v4 = *(_QWORD *)v4;
if ( !v4 )
return v6;
}
if ( v7 == 1 && !v6 )
v6 = v4;
v4 = *(_QWORD *)v4;
}
while ( v4 );
return v6;
}

original_code:
hfile_t *
find_file_name(u16 *path, int displ)
{
 hfile_t *p, *ret = 0;
 hash_directory(stuni(path));
 path = unist(complete_path(stuni(path)));
 for (p = hfile; p; p = p->next) {
  switch (unicode_cmp(p->filename, path)) {
  case 1:
   if (ret) break;
  case 0:
   ret = p;
  }
 }
 return ret;
}

canonical_original_code:
struct hfile_s *find_file_name(unsigned short *path, int displ)
{
 struct hfile_s *p; struct hfile_s *ret = 0;
 hash_directory(stuni(path));
 path = unist(complete_path(stuni(path)));
 for (p = hfile; p; p = p->next) {
  switch (unicode_cmp(p->filename, path)) {
  case 1:
   if (ret) break;
  case 0:
   ret = p;
  }
 }
 return ret;
}

variable_types: displ int

return_type: struct hfile_s { struct hfile_s *next; unsigned char hash_16k[16]; unsigned char hash[16]; long long file_size; unsigned short *filename; char *dir; unsigned char hashed; } *


original_code:
hfile_t *
find_volume(u16 *name, i64 vol)
{
 u16 *filename;
 i64 i;
 hfile_t *p, *ret = 0;
 int nd, v;
 if (vol < 1)
  return 0;
 nd = 2;
 for (v = 100; vol >= v; v *= 10)
  nd++;
 for (i = 0; name[i]; i++)
  ;
 if ((name[i-1] < '0') || (name[i-1] > '9')) {
  i = i - 2;
 } else {
  while ((name[i-1] >= '0') && (name[i-1] <= '9'))
   i--;
 }
 i += nd;
 ((filename) = (malloc(sizeof(*(filename)) * (i + 1))));
 uni_copy(filename, name, i);
 filename[i] = 0;
 v = vol;
 while (--nd >= 0) {
  filename[--i] = '0' + v % 10;
  v /= 10;
 }
 for (p = hfile; p; p = p->next) {
  switch (unicode_cmp(p->filename, filename)) {
  case 1:
   if (ret) break;
  case 0:
   ret = p;
  }
 }
 if (!ret)
  ret = hfile_add(filename);
 free(filename);
 return ret;
}

canonical_original_code:
struct hfile_s *find_volume(unsigned short *name, long long vol)
{
 unsigned short *filename;
 long long i;
 struct hfile_s *p; struct hfile_s *ret = 0;
 int nd; int v;
 if (vol < 1)
  return 0;
 nd = 2;
 for (v = 100; vol >= v; v *= 10)
  nd++;
 for (i = 0; name[i]; i++)
  ;
 if ((name[i-1] < '0') || (name[i-1] > '9')) {
  i = i - 2;
 } else {
  while ((name[i-1] >= '0') && (name[i-1] <= '9'))
   i--;
 }
 i += nd;
 ((filename) = (malloc(sizeof(*(filename)) * (i + 1))));
 uni_copy(filename, name, i);
 filename[i] = 0;
 v = vol;
 while (--nd >= 0) {
  filename[--i] = '0' + v % 10;
  v /= 10;
 }
 for (p = hfile; p; p = p->next) {
  switch (unicode_cmp(p->filename, filename)) {
  case 1:
   if (ret) break;
  case 0:
   ret = p;
  }
 }
 if (!ret)
  ret = hfile_add(filename);
 free(filename);
 return ret;
}

variable_types:
name
unsigned short *

variable_types:
vol
long long

variable_types:
i
long long

variable_types: nd int

variable_types: v int


original_code:
int get_number_of_encoded_parts(newspost_data *data, file_entry *file) {
 long blocksize = 128 * data->lines;
 return ( (file->fileinfo.st_size / blocksize) +
  ((file->fileinfo.st_size % blocksize) != 0) );
}

canonical_original_code:
int get_number_of_encoded_parts(struct newspost_data *data, struct file_entry *file) {
 long blocksize = 128 * data->lines;
 return ( (file->fileinfo.st_size / blocksize) +
  ((file->fileinfo.st_size % blocksize) != 0) );
}

variable_types: struct newspost_data { struct Buff { char *data; long length; long real_length; } *subject; struct Buff *newsgroup; struct Buff *from; struct Buff *organization; struct Buff *address; int port; struct Buff *user; struct Buff *password; int threads; int lines; unsigned char uuenc; struct Buff *sfv; struct Buff *par; int parnum; int filesperpar; struct Buff *reference; unsigned char filenumber; struct Buff *tmpdir; unsigned char noarchive; struct Buff *followupto; struct Buff *replyto; struct Buff *name; unsigned char text; struct Newspost_SList { void *data; struct Newspost_SList *next; } *extra_headers; } *

variable_types: struct file_entry { struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } fileinfo; struct Buff *filename; unsigned int crc; unsigned char *parts; int number_enc_parts; int parts_to_post; union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } *rwlock; unsigned char post_started; int parts_posted; } *

variable_types: blocksize long


decompiled_code:
__int64 __fastcall get_buffer_size_per_encoded_part(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 68);
if ( *(_BYTE *)(a1 + 72) )
result = (v1 + 8) << 6;
else
result = 2 * ((v1 << 7) + 2 * ((v1 << 7) / 128LL) + 256);
return result;
}

original_code:
long get_buffer_size_per_encoded_part(newspost_data *data) {
 if (data->uuenc == 0) {
  long blocksize = 128 * data->lines;
  return ((blocksize * 2) +
   ((blocksize / 128) * 4) + 512);
 }
 else {
  return ((data->lines * 64) + 512);
 }
}

canonical_original_code:
long get_buffer_size_per_encoded_part(struct newspost_data *data) {
 if (data->uuenc == 0) {
  long blocksize = 128 * data->lines;
  return ((blocksize * 2) +
   ((blocksize / 128) * 4) + 512);
 }
 else {
  return ((data->lines * 64) + 512);
 }
}

return_type: long


decompiled_code:
__int64 __fastcall crc32(_BYTE *a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // eax
_BYTE *v4; // rsi

v3 = ~a3;
if ( !a2 )
return a3;
v4 = &a1[a2];
do
v3 = crctable[(unsigned __int8)(*a1++ ^ v3)] ^ (v3 >> 8);
while ( a1 != v4 );
return ~v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // eax
_BYTE *v4; // rsi

v3 = ~a3;
if ( !a2 )
return a3;
v4 = &a1[a2];
do
v3 = crctable[(unsigned __int8)(*a1++ ^ v3)] ^ (v3 >> 8);
while ( a1 != v4 );
return ~v3;
}

original_code:
n_uint32 crc32(const char *buf, size_t len, n_uint32 crc)
{
 crc ^= 0xffffffffU;
 for (; len; len--)
  crc = (crc >> 8) ^ crctable[(crc ^ *buf++) & 0xff];
 crc ^= 0xffffffffU;
 return crc;
}

canonical_original_code:
unsigned int crc32(char *buf, unsigned long len, unsigned int crc)
{
 crc ^= 0xffffffffU;
 for (; len; len--)
  crc = (crc >> 8) ^ crctable[(crc ^ *buf++) & 0xff];
 crc ^= 0xffffffffU;
 return crc;
}

variable_types:
buf
char *

variable_types:
len
unsigned long

variable_types:
crc
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall calculate_crcs(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rsi
__int64 v3; // rbx
unsigned int v4; // er14
const char *v5; // r13
int v6; // ebp
__int64 v7; // rax
__int64 v8; // rsi
_BYTE v10[16424]; // [rsp+0h] [rbp-4028h] BYREF

v1 = a1;
ui_crc_start();
if ( a1 )
{
do
{
while ( 1 )
{
v3 = *(_QWORD *)v1;
v4 = 0;
v5 = **(const char ***)(*(_QWORD *)v1 + 144LL);
v6 = open(v5, 0, 0LL);
if ( v6 >= 0 )
break;
v2 = (unsigned int)*_errno_location();
ui_crc_error(v5, v2);
v1 = slist_next(v1, v2);
if ( !v1 )
return ui_crc_done();
}
while ( 1 )
{
v7 = read(v6, v10, 0x4000uLL);
v8 = v7;
if ( v7 <= 0 )
break;
v4 = crc32(v10, v7, v4);
}
if ( v7 )
{
v8 = (unsigned int)*_errno_location();
ui_crc_error(v5, v8);
}
else
{
*(_DWORD *)(v3 + 152) = v4;
}
close(v6);
v1 = slist_next(v1, v8);
}
while ( v1 );
}
return ui_crc_done();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rsi
__int64 v3; // rbx
unsigned int v4; // er14
const char *v5; // r13
int v6; // ebp
__int64 v7; // rax
__int64 v8; // rsi
_BYTE v10[16424]; // [rsp+0h] [rbp-4028h] BYREF

v1 = a1;
ui_crc_start();
if ( a1 )
{
do
{
while ( 1 )
{
v3 = *(_QWORD *)v1;
v4 = 0;
v5 = **(const char ***)(*(_QWORD *)v1 + 144LL);
v6 = open(v5, 0, 0LL);
if ( v6 >= 0 )
break;
v2 = (unsigned int)*_errno_location();
ui_crc_error(v5, v2);
v1 = slist_next(v1, v2);
if ( !v1 )
return ui_crc_done();
}
while ( 1 )
{
v7 = read(v6, v10, 0x4000uLL);
v8 = v7;
if ( v7 <= 0 )
break;
v4 = func0(v10, v7, v4);
}
if ( v7 )
{
v8 = (unsigned int)*_errno_location();
ui_crc_error(v5, v8);
}
else
{
*(_DWORD *)(v3 + 152) = v4;
}
close(v6);
v1 = slist_next(v1, v8);
}
while ( v1 );
}
return ui_crc_done();
}

original_code:
void calculate_crcs(SList *file_list)
{
 char buf[16384];
 long nr;
 n_uint32 crc;
 int fd;
 char *fn;
 file_entry *data;
 ui_crc_start();
 while (file_list != ((void *)0)) {
  data = (file_entry *) file_list->data;
  fn = data->filename->data;
  if ((fd = open(fn, 00, 0)) < 0)
   ui_crc_error(fn, (*__errno_location ()));
  else {
   crc = 0;
   while ((nr = read(fd, buf, sizeof(buf))) > 0)
    crc = crc32(buf, nr, crc);
   if (nr < 0)
    ui_crc_error(fn, (*__errno_location ()));
   else
    data->crc = crc;
   close(fd);
  }
  file_list = slist_next(file_list);
 }
 ui_crc_done();
}

canonical_original_code:
void calculate_crcs(struct Newspost_SList *file_list)
{
 char buf[16384];
 long nr;
 unsigned int crc;
 int fd;
 char *fn;
 struct file_entry *data;
 ui_crc_start();
 while (file_list != ((void *)0)) {
  data = (struct file_entry *) file_list->data;
  fn = data->filename->data;
  if ((fd = open(fn, 00, 0)) < 0)
   ui_crc_error(fn, (*__errno_location ()));
  else {
   crc = 0;
   while ((nr = read(fd, buf, sizeof(buf))) > 0)
    crc = crc32(buf, nr, crc);
   if (nr < 0)
    ui_crc_error(fn, (*__errno_location ()));
   else
    data->crc = crc;
   close(fd);
  }
  file_list = slist_next(file_list);
 }
 ui_crc_done();
}

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

variable_types:
buf
char [16384]

variable_types: nr long

variable_types: fd int

variable_types:
fn
char *

variable_types: struct file_entry { struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } fileinfo; struct Buff { char *data; long length; long real_length; } *filename; unsigned int crc; unsigned char *parts; int number_enc_parts; int parts_to_post; union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } *rwlock; unsigned char post_started; int parts_posted; } *


repo: Pilen/ubertex

decompiled_code:
__int64 __fastcall pcg32x2_srandom_r(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v5; // r12

v5 = a5;
if ( ((a5 ^ a4) & 0x7FFFFFFFFFFFFFFFLL) == 0 )
v5 = ~a5;
pcg32_srandom_r(a1, a2, a4);
return pcg32_srandom_r(a1 + 16, a3, v5);
}

original_code:
void pcg32x2_srandom_r(pcg32x2_random_t* rng, uint64_t seed1, uint64_t seed2,
                       uint64_t seq1, uint64_t seq2)
{
    uint64_t mask = ~0ull >> 1;
    if ((seq1 & mask) == (seq2 & mask))
        seq2 = ~seq2;
    pcg32_srandom_r(rng->gen, seed1, seq1);
    pcg32_srandom_r(rng->gen+1, seed2, seq2);
}

canonical_original_code:
void pcg32x2_srandom_r(struct pcg32x2_random_t *rng, unsigned long seed1, unsigned long seed2, unsigned long seq1, unsigned long seq2)
{
    unsigned long mask = ~0ull >> 1;
    if ((seq1 & mask) == (seq2 & mask))
        seq2 = ~seq2;
    pcg32_srandom_r(rng->gen, seed1, seq1);
    pcg32_srandom_r(rng->gen+1, seed2, seq2);
}

variable_types: struct pcg32x2_random_t { struct pcg_state_setseq_64 { unsigned long state; unsigned long inc; } gen[2]; } *

variable_types:
mask
unsigned long

user_defined_types: struct pcg32x2_random_t { struct pcg_state_setseq_64 gen[2]; }


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

v1 = (unsigned int)((__int64 (*)(void))pcg32_random_r)();
return (v1 << 32) | (unsigned int)pcg32_random_r(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rbx

v1 = (unsigned int)((__int64 (*)(void))pcg32_random_r)();
return (v1 << 32) | (unsigned int)func10(a1 + 16);
}

original_code:
uint64_t pcg32x2_random_r(pcg32x2_random_t* rng)
{
    return ((uint64_t)(pcg32_random_r(rng->gen)) << 32)
           | pcg32_random_r(rng->gen+1);
}

canonical_original_code:
unsigned long pcg32x2_random_r(struct pcg32x2_random_t *rng)
{
    return ((unsigned long)(pcg32_random_r(rng->gen)) << 32)
           | pcg32_random_r(rng->gen+1);
}

return_type: unsigned long

user_defined_types: struct pcg_state_setseq_64 { unsigned long state; unsigned long inc; }


decompiled_code:
unsigned __int64 __fastcall pcg32x2_boundedrand_r(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax

do
v2 = pcg32x2_random_r(a1);
while ( -(__int64)a2 % a2 > v2 );
return v2 % a2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax

do
v2 = func8(a1);
while ( -(__int64)a2 % a2 > v2 );
return v2 % a2;
}

original_code:
uint64_t pcg32x2_boundedrand_r(pcg32x2_random_t* rng, uint64_t bound)
{
    uint64_t threshold = -bound % bound;
    for (;;) {
        uint64_t r = pcg32x2_random_r(rng);
        if (r >= threshold)
            return r % bound;
    }
}

canonical_original_code:
unsigned long pcg32x2_boundedrand_r(struct pcg32x2_random_t *rng, unsigned long bound)
{
    unsigned long threshold = -bound % bound;
    for (;;) {
        unsigned long r = pcg32x2_random_r(rng);
        if (r >= threshold)
            return r % bound;
    }
}

variable_types:
bound
unsigned long

variable_types:
threshold
unsigned long

variable_types:
r
unsigned long


original_code:
uint32_t pcg32_random_r(pcg32_random_t* rng)
{
    uint64_t oldstate = rng->state;
    rng->state = oldstate * 6364136223846793005ULL + rng->inc;
    uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
    uint32_t rot = oldstate >> 59u;
    return (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
}

canonical_original_code:
unsigned int pcg32_random_r(struct pcg_state_setseq_64 *rng)
{
    unsigned long oldstate = rng->state;
    rng->state = oldstate * 6364136223846793005ULL + rng->inc;
    unsigned int xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
    unsigned int rot = oldstate >> 59u;
    return (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
}

variable_types: struct pcg_state_setseq_64 { unsigned long state; unsigned long inc; } *

variable_types:
oldstate
unsigned long

variable_types:
xorshifted
unsigned int

variable_types:
rot
unsigned int


decompiled_code:
__int64 __fastcall pcg32_srandom_r(unsigned __int64 *a1, __int64 a2, __int64 a3)
{
*a1 = 0LL;
a1[1] = 2 * a3 + 1;
pcg32_random_r(a1);
*a1 += a2;
return pcg32_random_r(a1);
}

original_code:
void pcg32_srandom_r(pcg32_random_t* rng, uint64_t initstate, uint64_t initseq)
{
    rng->state = 0U;
    rng->inc = (initseq << 1u) | 1u;
    pcg32_random_r(rng);
    rng->state += initstate;
    pcg32_random_r(rng);
}

canonical_original_code:
void pcg32_srandom_r(struct pcg_state_setseq_64 *rng, unsigned long initstate, unsigned long initseq)
{
    rng->state = 0U;
    rng->inc = (initseq << 1u) | 1u;
    pcg32_random_r(rng);
    rng->state += initstate;
    pcg32_random_r(rng);
}

variable_types:
initstate
unsigned long

variable_types:
initseq
unsigned long


decompiled_code:
__int64 __fastcall pcg32_srandom(__int64 a1, __int64 a2)
{
return pcg32_srandom_r((unsigned __int64 *)&pcg32_global, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
return func11((unsigned __int64 *)&pcg32_global, a1, a2);
}

original_code:
void pcg32_srandom(uint64_t seed, uint64_t seq)
{
    pcg32_srandom_r(&pcg32_global, seed, seq);
}

canonical_original_code:
void pcg32_srandom(unsigned long seed, unsigned long seq)
{
    pcg32_srandom_r(&pcg32_global, seed, seq);
}

variable_types:
seed
unsigned long

variable_types:
seq
unsigned long


decompiled_code:
__int64 pcg32_random()
{
return pcg32_random_r((unsigned __int64 *)&pcg32_global);
}

canonical_decompiled_code:
__int64 func13()
{
return func10((unsigned __int64 *)&pcg32_global);
}

original_code:
uint32_t pcg32_random()
{
    return pcg32_random_r(&pcg32_global);
}

canonical_original_code:
unsigned int pcg32_random()
{
    return pcg32_random_r(&pcg32_global);
}


decompiled_code:
__int64 __fastcall pcg32_boundedrand_r(unsigned __int64 *a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // edx

do
v2 = pcg32_random_r(a1);
while ( v3 > v2 );
return v2 % a2;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int64 *a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // edx

do
v2 = func10(a1);
while ( v3 > v2 );
return v2 % a2;
}

original_code:
uint32_t pcg32_boundedrand_r(pcg32_random_t* rng, uint32_t bound)
{
    uint32_t threshold = -bound % bound;
    for (;;) {
        uint32_t r = pcg32_random_r(rng);
        if (r >= threshold)
            return r % bound;
    }
}

canonical_original_code:
unsigned int pcg32_boundedrand_r(struct pcg_state_setseq_64 *rng, unsigned int bound)
{
    unsigned int threshold = -bound % bound;
    for (;;) {
        unsigned int r = pcg32_random_r(rng);
        if (r >= threshold)
            return r % bound;
    }
}

variable_types:
bound
unsigned int

variable_types:
threshold
unsigned int

variable_types:
r
unsigned int


decompiled_code:
__int64 __fastcall pcg32_boundedrand(unsigned int a1)
{
return pcg32_boundedrand_r((unsigned __int64 *)&pcg32_global, a1);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1)
{
return func14((unsigned __int64 *)&pcg32_global, a1);
}

original_code:
uint32_t pcg32_boundedrand(uint32_t bound)
{
    return pcg32_boundedrand_r(&pcg32_global, bound);
}

canonical_original_code:
unsigned int pcg32_boundedrand(unsigned int bound)
{
    return pcg32_boundedrand_r(&pcg32_global, bound);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v4; // er12
int v5; // ebx
__int64 v6; // rax
int i; // eax
__int64 v8; // rax
int v9; // ebx
__int64 v10; // rax
int v11; // ebx
int v12; // eax
__int64 v13; // rbx
int v14; // eax
char *v15; // rdx
char v16; // cl
__int64 v17; // rbx
time_t v19; // rbx
time_t v20; // rax
int v21; // [rsp+Ch] [rbp-7Ch] BYREF
char v22[32]; // [rsp+10h] [rbp-78h] BYREF
char v23[88]; // [rsp+30h] [rbp-58h]

v21 = 5;
if ( argc <= 1 )
goto LABEL_4;
v3 = argv[1];
if ( strcmp(v3, "-r") )
{
v21 = atoi(v3);
LABEL_4:
pcg32x2_srandom_r(v22, 42LL, 42LL, 54LL, 54LL);
goto LABEL_5;
}
if ( argc != 2 )
v21 = atoi(argv[2]);
v19 = time(0LL);
v20 = time(0LL);
pcg32x2_srandom_r(v22, v20 ^ 0x401040, ~(v19 ^ 0x401570), &v21, &dummy_global);
LABEL_5:
v4 = 1;
printf(
"pcg32x2_random_r:\n"
" - result: 64-bit unsigned int (uint64_t)\n"
" - period: 2^64 (* ~2^126 streams)\n"
" - state space: ~2^254\n"
" - state type: pcg32x2_random_t (%zu bytes)\n"
" - output func: XSH-RR (x 2)\n"
"\n",
0x20uLL);
if ( v21 > 0 )
{
do
{
printf("Round %d:\n", (unsigned int)v4);
printf(" 64bit:");
v5 = 1;
LABEL_12:
v8 = pcg32x2_random_r(v22);
printf(" 0x%016llx", v8);
for ( i = v5; ; i = v5 )
{
v5 = i + 1;
if ( !i )
goto LABEL_12;
if ( (unsigned int)(-1431655765 * i) <= 0x55555555 )
printf("\n\t");
v6 = pcg32x2_random_r(v22);
printf(" 0x%016llx", v6);
if ( v5 == 6 )
break;
}
v9 = 65;
putchar(10);
printf(" Coins: ");
do
{
v10 = pcg32x2_boundedrand_r(v22, 2LL);
putchar(v10 == 0 ? 84 : 72);
--v9;
}
while ( v9 );
v11 = 33;
putchar(10);
printf(" Rolls:");
do
{
v12 = pcg32x2_boundedrand_r(v22, 6LL);
printf(" %d", (unsigned int)(v12 + 1));
--v11;
}
while ( v11 );
v13 = 0LL;
putchar(10);
do
{
v23[v13] = v13;
++v13;
}
while ( v13 != 52 );
do
{
v14 = pcg32x2_boundedrand_r(v22, v13);
v15 = &v22[v13-- + 31];
v16 = v23[v14];
v23[v14] = *v15;
*v15 = v16;
}
while ( v13 != 1 );
v17 = 2LL;
printf(" Cards:");
printf(" %c%c", (unsigned int)number_0[v23[0] / 4], (unsigned int)suit_1[v23[0] % 4]);
do
{
printf(" %c%c", (unsigned int)number_0[v22[v17 + 31] / 4], (unsigned int)suit_1[v22[v17 + 31] % 4]);
if ( __ROR4__(-1171354717 * v17, 1) <= 0xBA2E8BAu )
printf("\n\t");
++v17;
}
while ( v17 != 53 );
++v4;
putchar(10);
putchar(10);
}
while ( v21 >= v4 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v4; // er12
int v5; // ebx
__int64 v6; // rax
int i; // eax
__int64 v8; // rax
int v9; // ebx
__int64 v10; // rax
int v11; // ebx
int v12; // eax
__int64 v13; // rbx
int v14; // eax
char *v15; // rdx
char v16; // cl
__int64 v17; // rbx
time_t v19; // rbx
time_t v20; // rax
int v21; // [rsp+Ch] [rbp-7Ch] BYREF
char v22[32]; // [rsp+10h] [rbp-78h] BYREF
char v23[88]; // [rsp+30h] [rbp-58h]

v21 = 5;
if ( argc <= 1 )
goto LABEL_4;
v3 = argv[1];
if ( strcmp(v3, "-r") )
{
v21 = atoi(v3);
LABEL_4:
func7(v22, 42LL, 42LL, 54LL, 54LL);
goto LABEL_5;
}
if ( argc != 2 )
v21 = atoi(argv[2]);
v19 = time(0LL);
v20 = time(0LL);
func7(v22, v20 ^ 0x401040, ~(v19 ^ 0x401570), &v21, &dummy_global);
LABEL_5:
v4 = 1;
printf(
"pcg32x2_random_r:\n"
" - result: 64-bit unsigned int (uint64_t)\n"
" - period: 2^64 (* ~2^126 streams)\n"
" - state space: ~2^254\n"
" - state type: pcg32x2_random_t (%zu bytes)\n"
" - output func: XSH-RR (x 2)\n"
"\n",
0x20uLL);
if ( v21 > 0 )
{
do
{
printf("Round %d:\n", (unsigned int)v4);
printf(" 64bit:");
v5 = 1;
LABEL_12:
v8 = func8(v22);
printf(" 0x%016llx", v8);
for ( i = v5; ; i = v5 )
{
v5 = i + 1;
if ( !i )
goto LABEL_12;
if ( (unsigned int)(-1431655765 * i) <= 0x55555555 )
printf("\n\t");
v6 = func8(v22);
printf(" 0x%016llx", v6);
if ( v5 == 6 )
break;
}
v9 = 65;
putchar(10);
printf(" Coins: ");
do
{
v10 = func9(v22, 2LL);
putchar(v10 == 0 ? 84 : 72);
--v9;
}
while ( v9 );
v11 = 33;
putchar(10);
printf(" Rolls:");
do
{
v12 = func9(v22, 6LL);
printf(" %d", (unsigned int)(v12 + 1));
--v11;
}
while ( v11 );
v13 = 0LL;
putchar(10);
do
{
v23[v13] = v13;
++v13;
}
while ( v13 != 52 );
do
{
v14 = func9(v22, v13);
v15 = &v22[v13-- + 31];
v16 = v23[v14];
v23[v14] = *v15;
*v15 = v16;
}
while ( v13 != 1 );
v17 = 2LL;
printf(" Cards:");
printf(" %c%c", (unsigned int)number_0[v23[0] / 4], (unsigned int)suit_1[v23[0] % 4]);
do
{
printf(" %c%c", (unsigned int)number_0[v22[v17 + 31] / 4], (unsigned int)suit_1[v22[v17 + 31] % 4]);
if ( __ROR4__(-1171354717 * v17, 1) <= 0xBA2E8BAu )
printf("\n\t");
++v17;
}
while ( v17 != 53 );
++v4;
putchar(10);
putchar(10);
}
while ( v21 >= v4 );
}
return 0;
}

original_code:
int main(int argc, char** argv)
{
    int rounds = 5;
    _Bool nondeterministic_seed = 0;
    int round, i;
    ++argv;
    --argc;
    if (argc > 0 && strcmp(argv[0], "-r") == 0) {
        nondeterministic_seed = 1;
        ++argv;
        --argc;
    }
    if (argc > 0) {
        rounds = atoi(argv[0]);
    }
    pcg32x2_random_t rng;
    if (nondeterministic_seed) {
        pcg32x2_srandom_r(&rng, time(((void *)0)) ^ (intptr_t)&printf,
                               ~time(((void *)0)) ^ (intptr_t)&pcg32_random_r,
                                (intptr_t)&rounds,
                                (intptr_t)&dummy_global);
    } else {
        pcg32x2_srandom_r(&rng, 42u, 42u, 54u, 54u);
    }
    printf("pcg32x2_random_r:\n"
           "      -  result:      64-bit unsigned int (uint64_t)\n"
           "      -  period:      2^64   (* ~2^126 streams)\n"
           "      -  state space: ~2^254\n"
           "      -  state type:  pcg32x2_random_t (%zu bytes)\n"
           "      -  output func: XSH-RR (x 2)\n"
           "\n",
           sizeof(pcg32x2_random_t));
    for (round = 1; round <= rounds; ++round) {
        printf("Round %d:\n", round);
        printf("  64bit:");
        for (i = 0; i < 6; ++i) {
            if (i > 0 && i % 3 == 0)
                printf("\n\t");
            printf(" 0x%016llx", pcg32x2_random_r(&rng));
        }
        printf("\n");
        printf("  Coins: ");
        for (i = 0; i < 65; ++i)
            printf("%c", pcg32x2_boundedrand_r(&rng, 2) ? 'H' : 'T');
        printf("\n");
        printf("  Rolls:");
        for (i = 0; i < 33; ++i) {
            printf(" %d", (int)pcg32x2_boundedrand_r(&rng, 6) + 1);
        }
        printf("\n");
        enum { SUITS = 4, NUMBERS = 13, CARDS = 52 };
        char cards[CARDS];
        for (i = 0; i < CARDS; ++i)
            cards[i] = i;
        for (i = CARDS; i > 1; --i) {
            int chosen = pcg32x2_boundedrand_r(&rng, i);
            char card = cards[chosen];
            cards[chosen] = cards[i - 1];
            cards[i - 1] = card;
        }
        printf("  Cards:");
        static const char number[] = {'A', '2', '3', '4', '5', '6', '7',
                                      '8', '9', 'T', 'J', 'Q', 'K'};
        static const char suit[] = {'h', 'c', 'd', 's'};
        for (i = 0; i < CARDS; ++i) {
            printf(" %c%c", number[cards[i] / SUITS], suit[cards[i] % SUITS]);
            if ((i + 1) % 22 == 0)
                printf("\n\t");
        }
        printf("\n");
        printf("\n");
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int rounds = 5;
    _Bool nondeterministic_seed = 0;
    int round; int i;
    ++argv;
    --argc;
    if (argc > 0 && strcmp(argv[0], "-r") == 0) {
        nondeterministic_seed = 1;
        ++argv;
        --argc;
    }
    if (argc > 0) {
        rounds = atoi(argv[0]);
    }
    struct pcg32x2_random_t rng;
    if (nondeterministic_seed) {
        pcg32x2_srandom_r(&rng, time(((void *)0)) ^ (long)&printf,
                               ~time(((void *)0)) ^ (long)&pcg32_random_r,
                                (long)&rounds,
                                (long)&dummy_global);
    } else {
        pcg32x2_srandom_r(&rng, 42u, 42u, 54u, 54u);
    }
    printf("pcg32x2_random_r:\n"
           "      -  result:      64-bit unsigned int (uint64_t)\n"
           "      -  period:      2^64   (* ~2^126 streams)\n"
           "      -  state space: ~2^254\n"
           "      -  state type:  pcg32x2_random_t (%zu bytes)\n"
           "      -  output func: XSH-RR (x 2)\n"
           "\n",
           sizeof(pcg32x2_random_t));
    for (round = 1; round <= rounds; ++round) {
        printf("Round %d:\n", round);
        printf("  64bit:");
        for (i = 0; i < 6; ++i) {
            if (i > 0 && i % 3 == 0)
                printf("\n\t");
            printf(" 0x%016llx", pcg32x2_random_r(&rng));
        }
        printf("\n");
        printf("  Coins: ");
        for (i = 0; i < 65; ++i)
            printf("%c", pcg32x2_boundedrand_r(&rng, 2) ? 'H' : 'T');
        printf("\n");
        printf("  Rolls:");
        for (i = 0; i < 33; ++i) {
            printf(" %d", (int)pcg32x2_boundedrand_r(&rng, 6) + 1);
        }
        printf("\n");
        enum { SUITS = 4, NUMBERS = 13, CARDS = 52 };
        char cards[-1];
        for (i = 0; i < CARDS; ++i)
            cards[i] = i;
        for (i = CARDS; i > 1; --i) {
            int chosen = pcg32x2_boundedrand_r(&rng, i);
            char card = cards[chosen];
            cards[chosen] = cards[i - 1];
            cards[i - 1] = card;
        }
        printf("  Cards:");
        static char number[] = {'A', '2', '3', '4', '5', '6', '7',
                                      '8', '9', 'T', 'J', 'Q', 'K'};
        static char suit[] = {'h', 'c', 'd', 's'};
        for (i = 0; i < CARDS; ++i) {
            printf(" %c%c", number[cards[i] / SUITS], suit[cards[i] % SUITS]);
            if ((i + 1) % 22 == 0)
                printf("\n\t");
        }
        printf("\n");
        printf("\n");
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: rounds int

variable_types: round int

variable_types: i int

variable_types: struct pcg32x2_random_t { struct pcg_state_setseq_64 { unsigned long state; unsigned long inc; } gen[2]; }

variable_types:
cards
char [-1]

variable_types: chosen int

variable_types: card char

variable_types:
number
char []

variable_types:
suit
char []


decompiled_code:
int __fastcall i2c_open(const char *a1)
{
int result; // eax

result = open(a1, 2);
if ( result < 0 )
result = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func6(const char *a1)
{
int result; // eax

result = open(a1, 2);
if ( result < 0 )
result = -1;
return result;
}

original_code:
int i2c_open(char* interface_name)
{
        int file_handle = open((const char*) interface_name, 02);
        if(file_handle < 0)
        {
            return -1;
        }
        else return file_handle;
}

canonical_original_code:
int i2c_open(char *interface_name)
{
        int file_handle = open((const char*) interface_name, 02);
        if(file_handle < 0)
        {
            return -1;
        }
        else return file_handle;
}


decompiled_code:
__int64 __fastcall i2c_close(int a1)
{
return (unsigned int)(close(a1) >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return (unsigned int)(close(a1) >> 31);
}

original_code:
int i2c_close(int file_handle)
{
        if(close(file_handle) < 0)
        {
            return -1;
        }
        else return 0;
}


decompiled_code:
__int64 __fastcall i2c_select_address(int a1, unsigned __int8 a2)
{
return (unsigned int)(ioctl(a1, 0x703uLL, a2) >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, unsigned __int8 a2)
{
return (unsigned int)(ioctl(a1, 0x703uLL, a2) >> 31);
}

original_code:
int i2c_select_address(int file_handle, uint8_t address)
{
        if(ioctl(file_handle, 0x0703, address) < 0)
        {
            return -1;
        }
        else return 0;
}

canonical_original_code:
int i2c_select_address(int file_handle, unsigned char address)
{
        if(ioctl(file_handle, 0x0703, address) < 0)
        {
            return -1;
        }
        else return 0;
}

variable_types:
address
unsigned char


decompiled_code:
ssize_t __fastcall i2c_read(int a1, void *a2, unsigned __int8 a3)
{
return read(a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func9(int a1, void *a2, unsigned __int8 a3)
{
return read(a1, a2, a3);
}

original_code:
int i2c_read(int file_handle, uint8_t* destination, uint8_t amount)
{
        return read(file_handle, destination, amount);
}

canonical_original_code:
int i2c_read(int file_handle, unsigned char *destination, unsigned char amount)
{
        return read(file_handle, destination, amount);
}

variable_types:
destination
unsigned char *

variable_types:
amount
unsigned char


decompiled_code:
__int64 __fastcall i2c_read_byte(__int64 a1, __int64 a2)
{
return (unsigned int)-((unsigned int)i2c_read(a1, a2, 1LL) != 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
return (unsigned int)-((unsigned int)func9(a1, a2, 1LL) != 1);
}

original_code:
int i2c_read_byte(int file_handle, uint8_t* destination)
{
        int return_value = i2c_read(file_handle, destination, 1);
        if(return_value < 0) return -1;
        else if(return_value != 1) return -1;
        else return 0;
}

canonical_original_code:
int i2c_read_byte(int file_handle, unsigned char *destination)
{
        int return_value = i2c_read(file_handle, destination, 1);
        if(return_value < 0) return -1;
        else if(return_value != 1) return -1;
        else return 0;
}


decompiled_code:
__int64 __fastcall i2c_read_word(__int64 a1, _WORD *a2)
{
char v3[10]; // [rsp+Eh] [rbp-Ah] BYREF

if ( (unsigned __int16)i2c_read(a1, v3, 2LL) != 2 )
return 0xFFFFFFFFLL;
*a2 = (unsigned __int8)v3[1] + ((unsigned __int8)v3[0] << 8);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, _WORD *a2)
{
char v3[10]; // [rsp+Eh] [rbp-Ah] BYREF

if ( (unsigned __int16)func9(a1, v3, 2LL) != 2 )
return 0xFFFFFFFFLL;
*a2 = (unsigned __int8)v3[1] + ((unsigned __int8)v3[0] << 8);
return 0LL;
}

original_code:
int i2c_read_word(int file_handle, uint16_t* destination)
{
        uint8_t bytes_received[2];
        int16_t return_value = i2c_read(file_handle, bytes_received, 2);
        if(return_value < 0) return -1;
        else if(return_value != 2) return -1;
        else
        {
            *destination = ((bytes_received[0] << 8) + bytes_received[1]);
            return 0;
        }
}

canonical_original_code:
int i2c_read_word(int file_handle, unsigned short *destination)
{
        unsigned char bytes_received[2];
        short return_value = i2c_read(file_handle, bytes_received, 2);
        if(return_value < 0) return -1;
        else if(return_value != 2) return -1;
        else
        {
            *destination = ((bytes_received[0] << 8) + bytes_received[1]);
            return 0;
        }
}

variable_types:
destination
unsigned short *


decompiled_code:
ssize_t __fastcall i2c_write(int a1, const void *a2, unsigned __int8 a3)
{
return write(a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func12(int a1, const void *a2, unsigned __int8 a3)
{
return write(a1, a2, a3);
}

original_code:
int i2c_write(int file_handle, uint8_t* source, uint8_t amount)
{
        return write(file_handle, source, amount);
}

canonical_original_code:
int i2c_write(int file_handle, unsigned char *source, unsigned char amount)
{
        return write(file_handle, source, amount);
}

variable_types:
source
unsigned char *


decompiled_code:
__int64 __fastcall i2c_write_byte(__int64 a1, char a2)
{
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return (unsigned int)-((unsigned int)i2c_write(a1, v3, 1LL) != 1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, char a2)
{
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return (unsigned int)-((unsigned int)func12(a1, v3, 1LL) != 1);
}

original_code:
int i2c_write_byte(int file_handle, uint8_t value)
{
        int return_value = i2c_write(file_handle, &value, 1);
        if(return_value < 0) return -1;
        else if(return_value != 1) return -1;
        else return 0;
}

canonical_original_code:
int i2c_write_byte(int file_handle, unsigned char value)
{
        int return_value = i2c_write(file_handle, &value, 1);
        if(return_value < 0) return -1;
        else if(return_value != 1) return -1;
        else return 0;
}

variable_types:
value
unsigned char


decompiled_code:
__int64 __fastcall i2c_write_word(__int64 a1, __int16 a2)
{
__int16 v3[5]; // [rsp+Eh] [rbp-Ah] BYREF

v3[0] = __ROL2__(a2, 8);
return (unsigned int)-((unsigned __int16)i2c_write(a1, v3, 2LL) != 2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int16 a2)
{
__int16 v3[5]; // [rsp+Eh] [rbp-Ah] BYREF

v3[0] = __ROL2__(a2, 8);
return (unsigned int)-((unsigned __int16)func12(a1, v3, 2LL) != 2);
}

original_code:
int i2c_write_word(int file_handle, uint16_t word_value)
{
        uint8_t byte_value[2];
        byte_value[0] = ((word_value & 0xFF00) >> 8);
        byte_value[1] = (word_value & 0x00FF);
        int16_t return_value = i2c_write(file_handle, byte_value, 2);
        if(return_value < 0) return -1;
        else if(return_value != 2) return -1;
        else return 0;
}

canonical_original_code:
int i2c_write_word(int file_handle, unsigned short word_value)
{
        unsigned char byte_value[2];
        byte_value[0] = ((word_value & 0xFF00) >> 8);
        byte_value[1] = (word_value & 0x00FF);
        short return_value = i2c_write(file_handle, byte_value, 2);
        if(return_value < 0) return -1;
        else if(return_value != 2) return -1;
        else return 0;
}


hash

repo: Pluies/DataStructures

decompiled_code:
__int64 __fastcall hash(const char *a1)
{
int v1; // eax
__int64 v2; // rcx
__int64 result; // rax

if ( !a1 )
_assert_fail("key != NULL", "HashTable.c", 0xDu, "hash");
v1 = strlen(a1);
if ( !v1 )
return 0LL;
v2 = (__int64)&a1[v1 - 1 + 1];
LODWORD(result) = 0;
do
{
result = (unsigned int)(*a1 + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = (((unsigned int)result & 0xF0000000) >> 24) ^ result & 0xFFFFFFF;
++a1;
}
while ( a1 != (const char *)v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v1; // eax
__int64 v2; // rcx
__int64 result; // rax

if ( !a1 )
_assert_fail("key != NULL", "HashTable.c", 0xDu, "hash");
v1 = strlen(a1);
if ( !v1 )
return 0LL;
v2 = (__int64)&a1[v1 - 1 + 1];
LODWORD(result) = 0;
do
{
result = (unsigned int)(*a1 + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = (((unsigned int)result & 0xF0000000) >> 24) ^ result & 0xFFFFFFF;
++a1;
}
while ( a1 != (const char *)v2 );
return result;
}

original_code:
int hash(const char* key) {
 ((void) sizeof ((key != ((void *)0)) ? 1 : 0), __extension__ ({ if (key != ((void *)0)) ; else __assert_fail ("key != NULL", "HashTable.c", 13, __extension__ __PRETTY_FUNCTION__); }));
 unsigned int g = 0,
      h = 0,
      i = 0,
      keyLen = strlen(key);
 for(i = 0; i < keyLen; i++) {
  h = (h << 4) + key[i];
  g = h & 0xf0000000;
  if (g != 0){
   h = h ^ (g >> 24);
   h = h ^ g;
  }
 }
 return h;
}

canonical_original_code:
int hash(char *key) {
 ((void) sizeof ((key != ((void *)0)) ? 1 : 0), __extension__ ({ if (key != ((void *)0)) ; else __assert_fail ("key != NULL", "HashTable.c", 13, __extension__ __PRETTY_FUNCTION__); }));
 unsigned int g = 0; unsigned int h = 0; unsigned int i = 0; unsigned int keyLen = strlen(key);
 for(i = 0; i < keyLen; i++) {
  h = (h << 4) + key[i];
  g = h & 0xf0000000;
  if (g != 0){
   h = h ^ (g >> 24);
   h = h ^ g;
  }
 }
 return h;
}

variable_types:
key
char *

variable_types:
g
unsigned int

variable_types:
h
unsigned int

variable_types:
i
unsigned int

variable_types:
keyLen
unsigned int


fillWithNulls

decompiled_code:
void *__fastcall fillWithNulls(void *a1, int a2)
{
void *result; // rax

if ( a2 > 0 )
result = memset(a1, 0, 8LL * a2);
return result;
}

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

if ( a2 > 0 )
result = memset(a1, 0, 8LL * a2);
return result;
}

original_code:
void fillWithNulls(void** array, int c){
 int i;
 for (i=0; i<c; i++)
  array[i] = ((void *)0);
}

canonical_original_code:
void fillWithNulls(void **array, int c){
 int i;
 for (i=0; i<c; i++)
  array[i] = ((void *)0);
}

variable_types:
array
void **

variable_types: c int

variable_types: i int


freeRecord

decompiled_code:
void __fastcall freeRecord(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void freeRecord(record* r){
 if (r == ((void *)0)) return;
 free(r->key);
 free(r);
}

canonical_original_code:
void freeRecord(struct record *r){
 if (r == ((void *)0)) return;
 free(r->key);
 free(r);
}

variable_types: struct record { char *key; void *value; } *


setInBucket

decompiled_code:
__int64 __fastcall setInBucket(int *a1, void *a2, __int64 a3)
{
__int64 v4; // rax
int v5; // esi
_QWORD *v8; // r13
__int64 result; // rax
int v10; // esi
void *v11; // rdi
char *v12; // rax
__int64 v13; // rdx
int v14; // esi

if ( !a1 )
_assert_fail("b != NULL", "HashTable.c", 0x36u, "setInBucket");
v4 = *a1;
v5 = a1[1];
if ( (int)v4 >= v5 )
{
v10 = 2 * v5;
v11 = (void *)*((_QWORD *)a1 + 1);
a1[1] = v10;
v12 = (char *)realloc(v11, 8LL * v10);
v13 = *a1;
v14 = a1[1];
*((_QWORD *)a1 + 1) = v12;
fillWithNulls(&v12[8 * v13], v14 - v13);
v4 = *a1;
}
v8 = (_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v4);
*v8 = createRecord(a2, a3);
result = 0LL;
++*a1;
return result;
}

original_code:
int setInBucket(bucket* b, const char* key, void* value) {
 ((void) sizeof ((b != ((void *)0)) ? 1 : 0), __extension__ ({ if (b != ((void *)0)) ; else __assert_fail ("b != NULL", "HashTable.c", 54, __extension__ __PRETTY_FUNCTION__); }));
 if (b->size >= b->capacity){
  b->capacity *= 2;
  b->records = realloc(b->records, b->capacity * sizeof(record*));
  fillWithNulls((void**)&(b->records[b->size]), b->capacity - b->size);
 }
 b->records[b->size] = createRecord(key, value);
 b->size += 1;
 return 0;
}

canonical_original_code:
int setInBucket(struct bucket *b, char *key, void *value) {
 ((void) sizeof ((b != ((void *)0)) ? 1 : 0), __extension__ ({ if (b != ((void *)0)) ; else __assert_fail ("b != NULL", "HashTable.c", 54, __extension__ __PRETTY_FUNCTION__); }));
 if (b->size >= b->capacity){
  b->capacity *= 2;
  b->records = realloc(b->records, b->capacity * sizeof(struct record *));
  fillWithNulls((void **)&(b->records[b->size]), b->capacity - b->size);
 }
 b->records[b->size] = createRecord(key, value);
 b->size += 1;
 return 0;
}

variable_types: struct bucket { int size; int capacity; struct record { char *key; void *value; } **records; } *

variable_types:
value
void *

user_defined_types: struct bucket { int size; int capacity; struct record **records; }


unsetInBucket

original_code:
int unsetInBucket(bucket* b, const char* key){
 if(b == ((void *)0)) return 1;
 int i = 0;
 for (i=0; i < b->size; i++) {
  record* r = b->records[i];
  if (strcmp(key,r->key) == 0) {
   freeRecord(r);
   for(; (i+1) < b->size; i++)
    b->records[i] = b->records[i+1];
   b->records[b->size-1] = ((void *)0);
   b->size -= 1;
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
int unsetInBucket(struct bucket *b, char *key){
 if(b == ((void *)0)) return 1;
 int i = 0;
 for (i=0; i < b->size; i++) {
  struct record *r = b->records[i];
  if (strcmp(key,r->key) == 0) {
   freeRecord(r);
   for(; (i+1) < b->size; i++)
    b->records[i] = b->records[i+1];
   b->records[b->size-1] = ((void *)0);
   b->size -= 1;
   return 0;
  }
 }
 return 1;
}

user_defined_types: struct record { char *key; void *value; }


createBucket

decompiled_code:
_QWORD *createBucket()
{
_QWORD *v0; // r12
void *v1; // rax

v0 = malloc(0x10uLL);
*v0 = 0x100000000LL;
v1 = malloc(8uLL);
v0[1] = v1;
fillWithNulls(v1, 1);
return v0;
}

original_code:
bucket* createBucket() {
 bucket* b = malloc(sizeof(bucket));
 b->size = 0;
 b->capacity = 1;
 b->records = malloc(1 * sizeof(record*));
 fillWithNulls((void**)b->records, b->capacity);
 return b;
}

canonical_original_code:
struct bucket *createBucket() {
 struct bucket *b = malloc(sizeof(bucket));
 b->size = 0;
 b->capacity = 1;
 b->records = malloc(1 * sizeof(struct record *));
 fillWithNulls((void **)b->records, b->capacity);
 return b;
}

return_type: struct bucket { int size; int capacity; struct record { char *key; void *value; } **records; } *


freeBucket

decompiled_code:
void __fastcall freeBucket(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( ptr )
{
if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
freeRecord(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( ptr )
{
if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
func3(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void freeBucket(bucket* b){
 if (b == ((void *)0)) return;
 int i;
 for (i = 0; i<b->size; i++){
  freeRecord(b->records[i]);
 }
 free(b->records);
 free(b);
}

canonical_original_code:
void freeBucket(struct bucket *b){
 if (b == ((void *)0)) return;
 int i;
 for (i = 0; i<b->size; i++){
  freeRecord(b->records[i]);
 }
 free(b->records);
 free(b);
}


checkOrCreateBucket

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

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0x68u, "checkOrCreateBucket");
v2 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
if ( !*v2 )
*v2 = createBucket();
return 0LL;
}

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

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0x68u, "checkOrCreateBucket");
v2 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
if ( !*v2 )
*v2 = func6();
return 0LL;
}

original_code:
int checkOrCreateBucket(HashTable* h, int b) {
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 104, __extension__ __PRETTY_FUNCTION__); }));
 if (h->buckets[b] == ((void *)0))
  h->buckets[b] = createBucket();
 return 0;
}

canonical_original_code:
int checkOrCreateBucket(struct HashTable *h, int b) {
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 104, __extension__ __PRETTY_FUNCTION__); }));
 if (h->buckets[b] == ((void *)0))
  h->buckets[b] = createBucket();
 return 0;
}

variable_types: struct HashTable { int size; int capacity; struct bucket { int size; int capacity; struct record { char *key; void *value; } **records; } **buckets; } *

variable_types: b int

user_defined_types: struct HashTable { int size; int capacity; struct bucket **buckets; }


resize

original_code:
int resize(HashTable* h, int newCapacity){
 int oldCapacity = h->capacity,
     newElements = newCapacity - oldCapacity;
 h->buckets = realloc(h->buckets, newCapacity * sizeof(record*));
 fillWithNulls((void**)(&h->buckets[oldCapacity]), newElements);
 int bi, i, oldHash;
 for(bi = 0; bi < oldCapacity; bi++) {
  bucket* b = h->buckets[bi];
  if (b == ((void *)0)) continue;
  oldHash = bi;
  i = 0;
  while(i < b->size) {
   record* r = b->records[i];
   int newHash = hash(r->key) % newCapacity;
   if (newHash != oldHash) {
    checkOrCreateBucket(h, newHash);
    setInBucket(h->buckets[newHash], r->key, r->value);
    unsetInBucket(b, r->key);
   } else {
    i++;
   }
  }
  if (b->size == 0) {
   freeBucket(b);
   h->buckets[bi] = ((void *)0);
  }
 }
 h->capacity = newCapacity;
 return 0;
}

canonical_original_code:
int resize(struct HashTable *h, int newCapacity){
 int oldCapacity = h->capacity; int newElements = newCapacity - oldCapacity;
 h->buckets = realloc(h->buckets, newCapacity * sizeof(struct record *));
 fillWithNulls((void **)(&h->buckets[oldCapacity]), newElements);
 int bi; int i; int oldHash;
 for(bi = 0; bi < oldCapacity; bi++) {
  struct bucket *b = h->buckets[bi];
  if (b == ((void *)0)) continue;
  oldHash = bi;
  i = 0;
  while(i < b->size) {
   struct record *r = b->records[i];
   int newHash = hash(r->key) % newCapacity;
   if (newHash != oldHash) {
    checkOrCreateBucket(h, newHash);
    setInBucket(h->buckets[newHash], r->key, r->value);
    unsetInBucket(b, r->key);
   } else {
    i++;
   }
  }
  if (b->size == 0) {
   freeBucket(b);
   h->buckets[bi] = ((void *)0);
  }
 }
 h->capacity = newCapacity;
 return 0;
}

variable_types: newCapacity int

variable_types: oldCapacity int

variable_types: newElements int

variable_types: bi int

variable_types: oldHash int

variable_types: newHash int


unset

decompiled_code:
__int64 __fastcall unset(__int64 a1, const char *a2)
{
int v2; // eax
__int64 result; // rax

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0xBEu, "unset");
if ( !a2 )
_assert_fail("key != NULL", "HashTable.c", 0xBFu, "unset");
v2 = hash(a2);
result = unsetInBucket(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (v2 % *(_DWORD *)(a1 + 4))), a2);
if ( !(_DWORD)result )
--*(_DWORD *)a1;
return result;
}

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

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0xBEu, "unset");
if ( !a2 )
_assert_fail("key != NULL", "HashTable.c", 0xBFu, "unset");
v2 = func1(a2);
result = func5(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (v2 % *(_DWORD *)(a1 + 4))), a2);
if ( !(_DWORD)result )
--*(_DWORD *)a1;
return result;
}

original_code:
int unset(HashTable* h, const char* key) {
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 190, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((key != ((void *)0)) ? 1 : 0), __extension__ ({ if (key != ((void *)0)) ; else __assert_fail ("key != NULL", "HashTable.c", 191, __extension__ __PRETTY_FUNCTION__); }));
 int r = unsetInBucket(h->buckets[hash(key) % h->capacity], key);
 if (r == 0) {
  h->size -= 1;
 }
 return r;
}

canonical_original_code:
int unset(struct HashTable *h, char *key) {
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 190, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((key != ((void *)0)) ? 1 : 0), __extension__ ({ if (key != ((void *)0)) ; else __assert_fail ("key != NULL", "HashTable.c", 191, __extension__ __PRETTY_FUNCTION__); }));
 int r = unsetInBucket(h->buckets[hash(key) % h->capacity], key);
 if (r == 0) {
  h->size -= 1;
 }
 return r;
}

variable_types:
key
char *

variable_types: r int


set

decompiled_code:
__int64 __fastcall set(__int64 a1, char *a2, __int64 a3)
{
int v4; // edx
__int64 v5; // r13
unsigned int v6; // er12
int v8; // edx
int v9; // eax

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0xA9u, "set");
if ( !a2 )
_assert_fail("key != NULL", "HashTable.c", 0xAAu, "set");
unset(a1, a2);
v4 = (int)hash(a2) % *(_DWORD *)(a1 + 4);
v5 = v4;
checkOrCreateBucket(a1, v4);
v6 = setInBucket(*(int **)(*(_QWORD *)(a1 + 8) + 8 * v5), a2, a3);
if ( v6 )
return 1;
v8 = *(_DWORD *)(a1 + 4);
v9 = *(_DWORD *)a1 + 1;
*(_DWORD *)a1 = v9;
if ( (double)v9 < (double)v8 * 0.75 )
return v6;
resize(a1, 2 * v8 + 1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, char *a2, __int64 a3)
{
int v4; // edx
__int64 v5; // r13
unsigned int v6; // er12
int v8; // edx
int v9; // eax

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0xA9u, "set");
if ( !a2 )
_assert_fail("key != NULL", "HashTable.c", 0xAAu, "set");
func11(a1, a2);
v4 = (int)func1(a2) % *(_DWORD *)(a1 + 4);
v5 = v4;
func8(a1, v4);
v6 = func4(*(int **)(*(_QWORD *)(a1 + 8) + 8 * v5), a2, a3);
if ( v6 )
return 1;
v8 = *(_DWORD *)(a1 + 4);
v9 = *(_DWORD *)a1 + 1;
*(_DWORD *)a1 = v9;
if ( (double)v9 < (double)v8 * 0.75 )
return v6;
func9(a1, 2 * v8 + 1);
return 0LL;
}

original_code:
int set(HashTable* h, const char* key, void* value){
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 169, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((key != ((void *)0)) ? 1 : 0), __extension__ ({ if (key != ((void *)0)) ; else __assert_fail ("key != NULL", "HashTable.c", 170, __extension__ __PRETTY_FUNCTION__); }));
 unset(h, key);
 int b = hash(key) % h->capacity;
 checkOrCreateBucket(h, b);
 if (setInBucket(h->buckets[b], key, value) == 0) {
  h->size += 1;
  if (h->size >= (0.75 * h->capacity))
   resize(h, (2*h->capacity)+1);
  return 0;
 } else {
  return 1;
 }
}

canonical_original_code:
int set(struct HashTable *h, char *key, void *value){
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 169, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((key != ((void *)0)) ? 1 : 0), __extension__ ({ if (key != ((void *)0)) ; else __assert_fail ("key != NULL", "HashTable.c", 170, __extension__ __PRETTY_FUNCTION__); }));
 unset(h, key);
 int b = hash(key) % h->capacity;
 checkOrCreateBucket(h, b);
 if (setInBucket(h->buckets[b], key, value) == 0) {
  h->size += 1;
  if (h->size >= (0.75 * h->capacity))
   resize(h, (2*h->capacity)+1);
  return 0;
 } else {
  return 1;
 }
}


lookup

decompiled_code:
const char *__fastcall lookup(__int64 a1, const char *a2)
{
const char *result; // rax
const char ***v3; // rbx
__int64 v4; // r13
const char **v5; // rbp

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0xC8u, "lookup");
result = *(const char **)(*(_QWORD *)(a1 + 8) + 8LL * ((int)hash(a2) % *(_DWORD *)(a1 + 4)));
if ( result )
{
if ( *(int *)result <= 0 )
{
LABEL_9:
result = 0LL;
}
else
{
v3 = (const char ***)*((_QWORD *)result + 1);
v4 = (__int64)&v3[(unsigned int)(*(_DWORD *)result - 1) + 1];
while ( 1 )
{
v5 = *v3;
if ( !strcmp(a2, **v3) )
break;
if ( ++v3 == (const char ***)v4 )
goto LABEL_9;
}
result = v5[1];
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func13(__int64 a1, const char *a2)
{
const char *result; // rax
const char ***v3; // rbx
__int64 v4; // r13
const char **v5; // rbp

if ( !a1 )
_assert_fail("h != NULL", "HashTable.c", 0xC8u, "lookup");
result = *(const char **)(*(_QWORD *)(a1 + 8) + 8LL * ((int)func1(a2) % *(_DWORD *)(a1 + 4)));
if ( result )
{
if ( *(int *)result <= 0 )
{
LABEL_9:
result = 0LL;
}
else
{
v3 = (const char ***)*((_QWORD *)result + 1);
v4 = (__int64)&v3[(unsigned int)(*(_DWORD *)result - 1) + 1];
while ( 1 )
{
v5 = *v3;
if ( !strcmp(a2, **v3) )
break;
if ( ++v3 == (const char ***)v4 )
goto LABEL_9;
}
result = v5[1];
}
}
return result;
}

original_code:
void* lookup(HashTable* h, const char* key){
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 200, __extension__ __PRETTY_FUNCTION__); }));
 int bi = hash(key) % h->capacity;
 bucket* b = h->buckets[bi];
 if (b == ((void *)0)) return ((void *)0);
 int i = 0;
 for (i=0; i < b->size; i++) {
  record* r = b->records[i];
  if (strcmp(key,r->key) == 0)
   return r->value;
 }
 return ((void *)0);
}

canonical_original_code:
void *lookup(struct HashTable *h, char *key){
 ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "HashTable.c", 200, __extension__ __PRETTY_FUNCTION__); }));
 int bi = hash(key) % h->capacity;
 struct bucket *b = h->buckets[bi];
 if (b == ((void *)0)) return ((void *)0);
 int i = 0;
 for (i=0; i < b->size; i++) {
  struct record *r = b->records[i];
  if (strcmp(key,r->key) == 0)
   return r->value;
 }
 return ((void *)0);
}

return_type: void *


displayRecord

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

if ( a1 )
result = printf("(k: %s, v: %p)", *(const char **)a1, *(const void **)(a1 + 8));
return result;
}

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

if ( a1 )
result = printf("(k: %s, v: %p)", *(const char **)a1, *(const void **)(a1 + 8));
return result;
}

original_code:
void displayRecord(record* r){
 if (r == ((void *)0)) return;
 printf("(k: %s, v: %p)", r->key, r->value);
}

canonical_original_code:
void displayRecord(struct record *r){
 if (r == ((void *)0)) return;
 printf("(k: %s, v: %p)", r->key, r->value);
}


displayBucket

decompiled_code:
int __fastcall displayBucket(_DWORD *a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rbp
__int64 v5; // rdi
int result; // eax

printf("Bucket %d at %p, ", a2, a1);
if ( a1 )
{
printf("capacity %d, ", (unsigned int)a1[1]);
v3 = (unsigned int)*a1;
if ( (_DWORD)v3 )
{
printf("size %d: ", v3);
if ( (int)*a1 > 0 )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v4++);
displayRecord(v5);
}
while ( *a1 > (int)v4 );
}
}
else
{
printf("empty.");
}
result = putchar(10);
}
else
{
printf("not initialised.");
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(_DWORD *a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rbp
__int64 v5; // rdi
int result; // eax

printf("Bucket %d at %p, ", a2, a1);
if ( a1 )
{
printf("capacity %d, ", (unsigned int)a1[1]);
v3 = (unsigned int)*a1;
if ( (_DWORD)v3 )
{
printf("size %d: ", v3);
if ( (int)*a1 > 0 )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v4++);
func14(v5);
}
while ( *a1 > (int)v4 );
}
}
else
{
printf("empty.");
}
result = putchar(10);
}
else
{
printf("not initialised.");
result = putchar(10);
}
return result;
}

original_code:
void displayBucket(bucket* b, int in){
 int i = 0;
 printf("Bucket %d at %p, ", in, b);
 if (b == ((void *)0)) {
  printf("not initialised.");
 } else {
  printf("capacity %d, ", b->capacity);
  if (b->size == 0) {
   printf("empty.");
  } else {
   printf("size %d: ", b->size);
   for (i=0; i<b->size; i++)
    displayRecord(b->records[i]);
  }
 }
 printf("\n");
}

canonical_original_code:
void displayBucket(struct bucket *b, int in){
 int i = 0;
 printf("Bucket %d at %p, ", in, b);
 if (b == ((void *)0)) {
  printf("not initialised.");
 } else {
  printf("capacity %d, ", b->capacity);
  if (b->size == 0) {
   printf("empty.");
  } else {
   printf("size %d: ", b->size);
   for (i=0; i<b->size; i++)
    displayRecord(b->records[i]);
  }
 }
 printf("\n");
}

variable_types: in int


isEmpty

decompiled_code:
_BOOL8 __fastcall isEmpty(_DWORD *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_DWORD *a1)
{
return *a1 == 0;
}

original_code:
int isEmpty(HashTable* h){
 return h->size == 0;
}

canonical_original_code:
int isEmpty(struct HashTable *h){
 return h->size == 0;
}


create

decompiled_code:
_QWORD *create()
{
_QWORD *v0; // r12
void *v1; // rax

v0 = malloc(0x10uLL);
*v0 = 0x100000000LL;
v1 = malloc(8uLL);
v0[1] = v1;
fillWithNulls(v1, 1);
return v0;
}

original_code:
HashTable* create(){
 HashTable* h = malloc(sizeof(HashTable));
 h->size = 0;
 h->capacity = 1;
 h->buckets = malloc(1 * sizeof(bucket*));
 fillWithNulls((void**)h->buckets, h->capacity);
 return h;
}

canonical_original_code:
struct HashTable *create(){
 struct HashTable *h = malloc(sizeof(HashTable));
 h->size = 0;
 h->capacity = 1;
 h->buckets = malloc(1 * sizeof(struct bucket *));
 fillWithNulls((void **)h->buckets, h->capacity);
 return h;
}

return_type: struct HashTable { int size; int capacity; struct bucket { int size; int capacity; struct record { char *key; void *value; } **records; } **buckets; } *


display

decompiled_code:
int __fastcall display(unsigned int *a1)
{
__int64 v3; // rbx
__int64 v4; // rsi
_DWORD *v5; // rdi

if ( isEmpty(a1) )
return puts("HashTable is empty.");
printf("HashTable has %d element(s).\n", *a1);
if ( (int)a1[1] > 0 )
{
v3 = 0LL;
do
{
v4 = (unsigned int)v3;
v5 = *(_DWORD **)(*((_QWORD *)a1 + 1) + 8 * v3++);
displayBucket(v5, v4);
}
while ( (int)a1[1] > (int)v3 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func16(unsigned int *a1)
{
__int64 v3; // rbx
__int64 v4; // rsi
_DWORD *v5; // rdi

if ( func0(a1) )
return puts("HashTable is empty.");
printf("HashTable has %d element(s).\n", *a1);
if ( (int)a1[1] > 0 )
{
v3 = 0LL;
do
{
v4 = (unsigned int)v3;
v5 = *(_DWORD **)(*((_QWORD *)a1 + 1) + 8 * v3++);
func15(v5, v4);
}
while ( (int)a1[1] > (int)v3 );
}
return putchar(10);
}

original_code:
void display(HashTable* h){
 int i = 0;
 if (isEmpty(h)) {
  printf("HashTable is empty.\n");
 } else {
  printf("HashTable has %d element(s).\n", h->size);
  for (i=0; i<h->capacity; i++)
   displayBucket(h->buckets[i], i);
  printf("\n");
 }
}

canonical_original_code:
void display(struct HashTable *h){
 int i = 0;
 if (isEmpty(h)) {
  printf("HashTable is empty.\n");
 } else {
  printf("HashTable has %d element(s).\n", h->size);
  for (i=0; i<h->capacity; i++)
   displayBucket(h->buckets[i], i);
  printf("\n");
 }
}


cleanup

decompiled_code:
__int64 __fastcall cleanup(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *((int *)ptr + 1) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
freeBucket(v3);
}
while ( *((_DWORD *)ptr + 1) > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *((int *)ptr + 1) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
func7(v3);
}
while ( *((_DWORD *)ptr + 1) > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

original_code:
int cleanup(HashTable* h){
 int i = 0;
 for (i=0; i<h->capacity; i++) {
  freeBucket(h->buckets[i]);
 }
 free(h->buckets);
 free(h);
 return 0;
}

canonical_original_code:
int cleanup(struct HashTable *h){
 int i = 0;
 for (i=0; i<h->capacity; i++) {
  freeBucket(h->buckets[i]);
 }
 free(h->buckets);
 free(h);
 return 0;
}


cleanupNodes

decompiled_code:
__int64 __fastcall cleanupNodes(void *ptr)
{
if ( ptr )
{
cleanupNodes(*((void **)ptr + 2));
cleanupNodes(*((void **)ptr + 3));
free(ptr);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(void *ptr)
{
if ( ptr )
{
func9(*((void **)ptr + 2));
func9(*((void **)ptr + 3));
free(ptr);
}
return 0LL;
}

original_code:
int cleanupNodes(node* n){
 if (n != ((void *)0)){
  cleanupNodes(n->rhc);
  cleanupNodes(n->lhc);
  free(n);
 }
 return 0;
}

canonical_original_code:
int cleanupNodes(struct node *n){
 if (n != ((void *)0)){
  cleanupNodes(n->rhc);
  cleanupNodes(n->lhc);
  free(n);
 }
 return 0;
}

variable_types: struct node { void *value; struct node *parent; struct node *rhc; struct node *lhc; } *


max

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

original_code: int max(int a, int b){ return (a>b) ? a : b; }

variable_types: a int


maxDepth

decompiled_code:
__int64 __fastcall maxDepth(__int64 a1)
{
unsigned int v1; // ebp
unsigned int v2; // eax

if ( !a1 )
return 0LL;
v1 = maxDepth(*(_QWORD *)(a1 + 24));
v2 = maxDepth(*(_QWORD *)(a1 + 16));
return (unsigned int)max(v2, v1) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
unsigned int v1; // ebp
unsigned int v2; // eax

if ( !a1 )
return 0LL;
v1 = func19(*(_QWORD *)(a1 + 24));
v2 = func19(*(_QWORD *)(a1 + 16));
return (unsigned int)func18(v2, v1) + 1;
}

original_code:
int maxDepth(node* n) {
 if (n == ((void *)0)) return 0;
 return max(maxDepth(n->rhc), maxDepth(n->lhc)) + 1;
}

canonical_original_code:
int maxDepth(struct node *n) {
 if (n == ((void *)0)) return 0;
 return max(maxDepth(n->rhc), maxDepth(n->lhc)) + 1;
}

user_defined_types: struct node { void *value; struct node *parent; struct node *rhc; struct node *lhc; }


min

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

original_code: int min(int a, int b){ return (a<b) ? a : b; }


minDepth

decompiled_code:
__int64 __fastcall minDepth(__int64 a1)
{
unsigned int v1; // ebp
unsigned int v2; // eax

if ( !a1 )
return 0LL;
v1 = minDepth(*(_QWORD *)(a1 + 24));
v2 = minDepth(*(_QWORD *)(a1 + 16));
return (unsigned int)min(v2, v1) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
unsigned int v1; // ebp
unsigned int v2; // eax

if ( !a1 )
return 0LL;
v1 = func21(*(_QWORD *)(a1 + 24));
v2 = func21(*(_QWORD *)(a1 + 16));
return (unsigned int)func20(v2, v1) + 1;
}

original_code:
int minDepth(node* n) {
 if (n == ((void *)0)) return 0;
 return min(minDepth(n->rhc), minDepth(n->lhc)) + 1;
}

canonical_original_code:
int minDepth(struct node *n) {
 if (n == ((void *)0)) return 0;
 return min(minDepth(n->rhc), minDepth(n->lhc)) + 1;
}


newRecord

decompiled_code:
__int64 __fastcall newRecord(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
return a1;
}

original_code:
CatalogueRecord newRecord(int nCopies, int val)
{
 CatalogueRecord record;
 record.addr = nCopies;
 record.val = 0;
 return record;
}

canonical_original_code:
struct tagCatalogueRecord newRecord(int nCopies, int val)
{
 struct tagCatalogueRecord record;
 record.addr = nCopies;
 record.val = 0;
 return record;
}

variable_types: nCopies int

variable_types: val int

variable_types: struct tagCatalogueRecord { unsigned int addr; unsigned short val; }


printRecord

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

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

original_code:
int printRecord(CatalogueRecord record)
{
 return 0;
}

canonical_original_code:
int printRecord(struct tagCatalogueRecord record)
{
 return 0;
}

user_defined_types: struct tagCatalogueRecord { unsigned int addr; unsigned short val; }


repo: PonderingGrower/netdev

decompiled_code:
void parent_sig_chld()
{
__pid_t v0; // eax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

puts("sig_chld: received signal");
while ( 1 )
{
v0 = waitpid(-1, stat_loc, 1);
if ( v0 <= 0 )
break;
printf("ALERT: child %d terminated\n", (unsigned int)v0);
}
}

canonical_decompiled_code:
void func0()
{
__pid_t v0; // eax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

puts("sig_chld: received signal");
while ( 1 )
{
v0 = waitpid(-1, stat_loc, 1);
if ( v0 <= 0 )
break;
printf("ALERT: child %d terminated\n", (unsigned int)v0);
}
}

original_code:
void parent_sig_chld(int signo) {
    pid_t pid;
    int stat;
    printf("sig_chld: received signal\n");
    while ( (pid = waitpid(-1, &stat, 1)) > 0 ) {
        printf("ALERT: child %d terminated\n", pid);
    }
    return;
}

canonical_original_code:
void parent_sig_chld(int signo) {
    int pid;
    int stat;
    printf("sig_chld: received signal\n");
    while ( (pid = waitpid(-1, &stat, 1)) > 0 ) {
        printf("ALERT: child %d terminated\n", pid);
    }
    return;
}

variable_types: signo int

variable_types: pid int

variable_types: stat int