decompiled_code:
void *__fastcall poster_thread(void *a1)
{
__int64 v1; // r13
__int64 v2; // rbp
__int64 v3; // rbx
int v4; // er12
int v5; // eax
int v6; // eax
size_t v7; // rax
void *v8; // r14
int v9; // er15
__int64 v10; // rsi
int v11; // eax
int v12; // er12
int v13; // er12
int v14; // eax
int v15; // er12
int v17; // [rsp+Ch] [rbp-7Ch]
struct timeval tv; // [rsp+10h] [rbp-78h] BYREF
struct timespec abstime; // [rsp+20h] [rbp-68h] BYREF
__int64 v20; // [rsp+30h] [rbp-58h] BYREF
unsigned int v21; // [rsp+38h] [rbp-50h]
_QWORD *v22; // [rsp+40h] [rbp-48h]

v1 = *(_QWORD *)a1;
v2 = *((_QWORD *)a1 + 1);
v3 = *((_QWORD *)a1 + 2);
*(_DWORD *)(v2 + 4) = -1;
v20 = 0LL;
v21 = -1;
v22 = 0LL;
pthread_rwlock_wrlock(*(pthread_rwlock_t **)(v2 + 8));
*(_DWORD *)(v2 + 16) = 1;
pthread_rwlock_unlock(*(pthread_rwlock_t **)(v2 + 8));
if ( *(int *)(v2 + 4) < 0 )
{
v4 = 5;
do
{
ui_socket_connect_start(v2, **(_QWORD **)(v1 + 32));
v5 = socket_create(**(_QWORD **)(v1 + 32), *(unsigned int *)(v1 + 40));
*(_DWORD *)(v2 + 4) = v5;
if ( v5 >= 0 )
break;
ui_socket_connect_failed(v2, (unsigned int)v5);
gettimeofday(&tv, 0LL);
abstime.tv_nsec = 1000 * tv.tv_usec;
abstime.tv_sec = tv.tv_sec + 120;
if ( !--v4 )
{
ui_connecting_too_many_failures(v2);
pthread_exit(0LL);
}
pthread_mutex_lock(*(pthread_mutex_t **)(v3 + 40));
do
{
if ( *(_BYTE *)(v3 + 34) )
goto LABEL_13;
v6 = pthread_cond_timedwait(*(pthread_cond_t **)(v3 + 64), *(pthread_mutex_t **)(v3 + 40), &abstime);
}
while ( v6 != 110 && v6 );
if ( *(_BYTE *)(v3 + 34) )
{
LABEL_13:
pthread_mutex_unlock(*(pthread_mutex_t **)(v3 + 40));
pthread_exit(0LL);
}
pthread_mutex_unlock(*(pthread_mutex_t **)(v3 + 40));
}
while ( *(int *)(v2 + 4) < 0 );
}
ui_socket_connect_done(v2);
pthread_rwlock_wrlock(*(pthread_rwlock_t **)(v2 + 8));
*(_DWORD *)(v2 + 16) = 3;
pthread_rwlock_unlock(*(pthread_rwlock_t **)(v2 + 8));
ui_nntp_logon_start(v2, **(_QWORD **)(v1 + 32));
if ( !(unsigned __int8)nntp_logon(v2, v1) )
{
socket_close(*(unsigned int *)(v2 + 4));
pthread_exit(0LL);
}
ui_nntp_logon_done(v2);
v7 = get_buffer_size_per_encoded_part(v1);
v8 = malloc(v7);
v17 = 0;
v9 = 0;
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock(*(pthread_mutex_t **)(v3 + 40));
while ( *(_BYTE *)(v3 + 33) )
{
if ( *(_BYTE *)(v3 + 34) )
break;
pthread_cond_wait(*(pthread_cond_t **)(v3 + 56), *(pthread_mutex_t **)(v3 + 40));
}
v12 = queue_item_del(v3, &v20);
pthread_mutex_unlock(*(pthread_mutex_t **)(v3 + 40));
if ( v12 == -1 )
{
pthread_cond_broadcast(*(pthread_cond_t **)(v3 + 72));
nntp_logoff(v2);
socket_close(*(unsigned int *)(v2 + 4));
buff_free(v22);
free(v8);
pthread_rwlock_wrlock(*(pthread_rwlock_t **)(v2 + 8));
*(_DWORD *)(v2 + 16) = 4;
pthread_rwlock_unlock(*(pthread_rwlock_t **)(v2 + 8));
pthread_exit(0LL);
}
pthread_cond_signal(*(pthread_cond_t **)(v3 + 48));
v13 = get_encoded_part(v1, v20, v21, v8);
if ( v21 == 1 )
ui_posting_file_start(v1, v20);
ui_posting_part_start(v2, v20, v21);
v14 = nntp_post(v2, *v22, v1, v8, v13, 0LL);
v15 = v14;
if ( v14 )
break;
ui_posting_part_done(v2, v20, v21);
pthread_rwlock_wrlock(*(pthread_rwlock_t **)(v20 + 176));
v10 = v20;
v11 = *(_DWORD *)(v20 + 188) + 1;
*(_DWORD *)(v20 + 188) = v11;
if ( v11 == *(_DWORD *)(v10 + 172) )
ui_posting_file_done(v1);
pthread_rwlock_unlock(*(pthread_rwlock_t **)(v20 + 176));
v17 = v15;
}
if ( v14 == -5 )
break;
if ( v17 <= 4 )
{
ui_nntp_posting_retry(v2);
sleep(5u);
++v17;
}
else
{
++v9;
v17 = 0;
if ( v9 == 5 )
{
nntp_logoff(v2);
socket_close(*(unsigned int *)(v2 + 4));
ui_posting_too_many_failures(v2);
v17 = 0;
}
}
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1)
{
__int64 v1; // r13
__int64 v2; // rbp
__int64 v3; // rbx
int v4; // er12
int v5; // eax
int v6; // eax
size_t v7; // rax
void *v8; // r14
int v9; // er15
__int64 v10; // rsi
int v11; // eax
int v12; // er12
int v13; // er12
int v14; // eax
int v15; // er12
int v17; // [rsp+Ch] [rbp-7Ch]
struct timeval tv; // [rsp+10h] [rbp-78h] BYREF
struct timespec abstime; // [rsp+20h] [rbp-68h] BYREF
__int64 v20; // [rsp+30h] [rbp-58h] BYREF
unsigned int v21; // [rsp+38h] [rbp-50h]
_QWORD *v22; // [rsp+40h] [rbp-48h]

v1 = *(_QWORD *)a1;
v2 = *((_QWORD *)a1 + 1);
v3 = *((_QWORD *)a1 + 2);
*(_DWORD *)(v2 + 4) = -1;
v20 = 0LL;
v21 = -1;
v22 = 0LL;
pthread_rwlock_wrlock(*(pthread_rwlock_t **)(v2 + 8));
*(_DWORD *)(v2 + 16) = 1;
pthread_rwlock_unlock(*(pthread_rwlock_t **)(v2 + 8));
if ( *(int *)(v2 + 4) < 0 )
{
v4 = 5;
do
{
ui_socket_connect_start(v2, **(_QWORD **)(v1 + 32));
v5 = socket_create(**(_QWORD **)(v1 + 32), *(unsigned int *)(v1 + 40));
*(_DWORD *)(v2 + 4) = v5;
if ( v5 >= 0 )
break;
ui_socket_connect_failed(v2, (unsigned int)v5);
gettimeofday(&tv, 0LL);
abstime.tv_nsec = 1000 * tv.tv_usec;
abstime.tv_sec = tv.tv_sec + 120;
if ( !--v4 )
{
ui_connecting_too_many_failures(v2);
pthread_exit(0LL);
}
pthread_mutex_lock(*(pthread_mutex_t **)(v3 + 40));
do
{
if ( *(_BYTE *)(v3 + 34) )
goto LABEL_13;
v6 = pthread_cond_timedwait(*(pthread_cond_t **)(v3 + 64), *(pthread_mutex_t **)(v3 + 40), &abstime);
}
while ( v6 != 110 && v6 );
if ( *(_BYTE *)(v3 + 34) )
{
LABEL_13:
pthread_mutex_unlock(*(pthread_mutex_t **)(v3 + 40));
pthread_exit(0LL);
}
pthread_mutex_unlock(*(pthread_mutex_t **)(v3 + 40));
}
while ( *(int *)(v2 + 4) < 0 );
}
ui_socket_connect_done(v2);
pthread_rwlock_wrlock(*(pthread_rwlock_t **)(v2 + 8));
*(_DWORD *)(v2 + 16) = 3;
pthread_rwlock_unlock(*(pthread_rwlock_t **)(v2 + 8));
ui_nntp_logon_start(v2, **(_QWORD **)(v1 + 32));
if ( !(unsigned __int8)nntp_logon(v2, v1) )
{
socket_close(*(unsigned int *)(v2 + 4));
pthread_exit(0LL);
}
ui_nntp_logon_done(v2);
v7 = get_buffer_size_per_encoded_part(v1);
v8 = malloc(v7);
v17 = 0;
v9 = 0;
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock(*(pthread_mutex_t **)(v3 + 40));
while ( *(_BYTE *)(v3 + 33) )
{
if ( *(_BYTE *)(v3 + 34) )
break;
pthread_cond_wait(*(pthread_cond_t **)(v3 + 56), *(pthread_mutex_t **)(v3 + 40));
}
v12 = queue_item_del(v3, &v20);
pthread_mutex_unlock(*(pthread_mutex_t **)(v3 + 40));
if ( v12 == -1 )
{
pthread_cond_broadcast(*(pthread_cond_t **)(v3 + 72));
nntp_logoff(v2);
socket_close(*(unsigned int *)(v2 + 4));
buff_free(v22);
free(v8);
pthread_rwlock_wrlock(*(pthread_rwlock_t **)(v2 + 8));
*(_DWORD *)(v2 + 16) = 4;
pthread_rwlock_unlock(*(pthread_rwlock_t **)(v2 + 8));
pthread_exit(0LL);
}
pthread_cond_signal(*(pthread_cond_t **)(v3 + 48));
v13 = get_encoded_part(v1, v20, v21, v8);
if ( v21 == 1 )
ui_posting_file_start(v1, v20);
ui_posting_part_start(v2, v20, v21);
v14 = nntp_post(v2, *v22, v1, v8, v13, 0LL);
v15 = v14;
if ( v14 )
break;
ui_posting_part_done(v2, v20, v21);
pthread_rwlock_wrlock(*(pthread_rwlock_t **)(v20 + 176));
v10 = v20;
v11 = *(_DWORD *)(v20 + 188) + 1;
*(_DWORD *)(v20 + 188) = v11;
if ( v11 == *(_DWORD *)(v10 + 172) )
ui_posting_file_done(v1);
pthread_rwlock_unlock(*(pthread_rwlock_t **)(v20 + 176));
v17 = v15;
}
if ( v14 == -5 )
break;
if ( v17 <= 4 )
{
ui_nntp_posting_retry(v2);
sleep(5u);
++v17;
}
else
{
++v9;
v17 = 0;
if ( v9 == 5 )
{
nntp_logoff(v2);
socket_close(*(unsigned int *)(v2 + 4));
ui_posting_too_many_failures(v2);
v17 = 0;
}
}
}
return 0LL;
}

original_code:
static void *poster_thread(void *arg)
{
 poster_thread_arg *arguments = (poster_thread_arg *) arg;
 newspost_data *data = arguments->data;
 newspost_threadinfo *tinfo = arguments->threadinfo;
 queue *fifo = arguments->fifo;
 post_article_t article;
 char *data_buffer;
 int total_failures = 0;
 int number_of_tries = 0;
 int retval;
 int number_of_bytes;
 struct timespec ts;
 struct timeval tp;
 tinfo->sockfd = -1;
 article.file_data = ((void *)0);
 article.partnumber = -1;
 article.subject = ((void *)0);
 pthread_rwlock_wrlock(tinfo->rwlock);
 tinfo->status = 1;
 pthread_rwlock_unlock(tinfo->rwlock);
 while (tinfo->sockfd < 0) {
  ui_socket_connect_start(tinfo, data->address->data);
  tinfo->sockfd = socket_create(data->address->data, data->port);
  if (tinfo->sockfd >= 0)
   break;
  ui_socket_connect_failed(tinfo, tinfo->sockfd);
  gettimeofday(&tp, ((void *)0));
  ts.tv_sec = tp.tv_sec;
  ts.tv_nsec = tp.tv_usec * 1000;
  ts.tv_sec += 120;
  number_of_tries++;
  if (number_of_tries >= 5) {
   ui_connecting_too_many_failures(tinfo);
   pthread_exit(((void *)0));
  }
  pthread_mutex_lock(fifo->mut);
  while(!fifo->producer_done) {
   retval = pthread_cond_timedwait(fifo->cond_producer_done, fifo->mut, &ts);
   if (retval == 110 || retval == 0)
    break;
  }
  if (fifo->producer_done) {
   pthread_mutex_unlock(fifo->mut);
   pthread_exit(((void *)0));
  }
  pthread_mutex_unlock(fifo->mut);
 }
 ui_socket_connect_done(tinfo);
 pthread_rwlock_wrlock(tinfo->rwlock);
 tinfo->status = 3;
 pthread_rwlock_unlock(tinfo->rwlock);
 number_of_tries = 0;
 ui_nntp_logon_start(tinfo, data->address->data);
 if (nntp_logon(tinfo, data) == 0) {
  socket_close(tinfo->sockfd);
  pthread_exit(((void *)0));
 }
 ui_nntp_logon_done(tinfo);
 data_buffer = (char *) malloc(get_buffer_size_per_encoded_part(data));
 while (1) {
  pthread_mutex_lock(fifo->mut);
  while (fifo->empty && !fifo->producer_done)
   pthread_cond_wait(fifo->cond_not_empty, fifo->mut);
  retval = queue_item_del(fifo, &article);
  pthread_mutex_unlock(fifo->mut);
  if (retval == -1) {
   pthread_cond_broadcast(fifo->cond_empty);
   break;
  }
  pthread_cond_signal(fifo->cond_not_full);
  number_of_bytes = get_encoded_part(data, article.file_data, article.partnumber, data_buffer);
  if (article.partnumber == 1)
   ui_posting_file_start(data, article.file_data);
  ui_posting_part_start(tinfo, article.file_data, article.partnumber);
  retval = nntp_post(tinfo, article.subject->data, data, data_buffer, number_of_bytes, 0);
  if (retval == 0) {
   ui_posting_part_done(tinfo, article.file_data, article.partnumber);
   pthread_rwlock_wrlock(article.file_data->rwlock);
   if (++article.file_data->parts_posted == article.file_data->parts_to_post)
    ui_posting_file_done(data, article.file_data);
   pthread_rwlock_unlock(article.file_data->rwlock);
  }
  else if (retval == -5)
   return ((void *)0);
  else {
   if (number_of_tries < 5) {
    ui_nntp_posting_retry(tinfo);
    sleep(5);
    number_of_tries++;
    continue;
   }
   else {
    total_failures++;
    if (total_failures == 5) {
     nntp_logoff(tinfo);
     socket_close(tinfo->sockfd);
     ui_posting_too_many_failures(tinfo);
    }
   }
  }
  number_of_tries = 0;
 }
 nntp_logoff(tinfo);
 socket_close(tinfo->sockfd);
 buff_free(article.subject);
 free(data_buffer);
 pthread_rwlock_wrlock(tinfo->rwlock);
 tinfo->status = 4;
 pthread_rwlock_unlock(tinfo->rwlock);
 pthread_exit(((void *)0));
 return ((void *)0);
}

canonical_original_code:
static void *poster_thread(void *arg)
{
 struct poster_thread_arg *arguments = (poster_thread_arg *) arg;
 struct newspost_data *data = arguments->data;
 struct newspost_threadinfo *tinfo = arguments->threadinfo;
 struct queue *fifo = arguments->fifo;
 struct post_article_t article;
 char *data_buffer;
 int total_failures = 0;
 int number_of_tries = 0;
 int retval;
 int number_of_bytes;
 struct timespec ts;
 struct timeval tp;
 tinfo->sockfd = -1;
 article.file_data = ((void *)0);
 article.partnumber = -1;
 article.subject = ((void *)0);
 pthread_rwlock_wrlock(tinfo->rwlock);
 tinfo->status = 1;
 pthread_rwlock_unlock(tinfo->rwlock);
 while (tinfo->sockfd < 0) {
  ui_socket_connect_start(tinfo, data->address->data);
  tinfo->sockfd = socket_create(data->address->data, data->port);
  if (tinfo->sockfd >= 0)
   break;
  ui_socket_connect_failed(tinfo, tinfo->sockfd);
  gettimeofday(&tp, ((void *)0));
  ts.tv_sec = tp.tv_sec;
  ts.tv_nsec = tp.tv_usec * 1000;
  ts.tv_sec += 120;
  number_of_tries++;
  if (number_of_tries >= 5) {
   ui_connecting_too_many_failures(tinfo);
   pthread_exit(((void *)0));
  }
  pthread_mutex_lock(fifo->mut);
  while(!fifo->producer_done) {
   retval = pthread_cond_timedwait(fifo->cond_producer_done, fifo->mut, &ts);
   if (retval == 110 || retval == 0)
    break;
  }
  if (fifo->producer_done) {
   pthread_mutex_unlock(fifo->mut);
   pthread_exit(((void *)0));
  }
  pthread_mutex_unlock(fifo->mut);
 }
 ui_socket_connect_done(tinfo);
 pthread_rwlock_wrlock(tinfo->rwlock);
 tinfo->status = 3;
 pthread_rwlock_unlock(tinfo->rwlock);
 number_of_tries = 0;
 ui_nntp_logon_start(tinfo, data->address->data);
 if (nntp_logon(tinfo, data) == 0) {
  socket_close(tinfo->sockfd);
  pthread_exit(((void *)0));
 }
 ui_nntp_logon_done(tinfo);
 data_buffer = (char *) malloc(get_buffer_size_per_encoded_part(data));
 while (1) {
  pthread_mutex_lock(fifo->mut);
  while (fifo->empty && !fifo->producer_done)
   pthread_cond_wait(fifo->cond_not_empty, fifo->mut);
  retval = queue_item_del(fifo, &article);
  pthread_mutex_unlock(fifo->mut);
  if (retval == -1) {
   pthread_cond_broadcast(fifo->cond_empty);
   break;
  }
  pthread_cond_signal(fifo->cond_not_full);
  number_of_bytes = get_encoded_part(data, article.file_data, article.partnumber, data_buffer);
  if (article.partnumber == 1)
   ui_posting_file_start(data, article.file_data);
  ui_posting_part_start(tinfo, article.file_data, article.partnumber);
  retval = nntp_post(tinfo, article.subject->data, data, data_buffer, number_of_bytes, 0);
  if (retval == 0) {
   ui_posting_part_done(tinfo, article.file_data, article.partnumber);
   pthread_rwlock_wrlock(article.file_data->rwlock);
   if (++article.file_data->parts_posted == article.file_data->parts_to_post)
    ui_posting_file_done(data, article.file_data);
   pthread_rwlock_unlock(article.file_data->rwlock);
  }
  else if (retval == -5)
   return ((void *)0);
  else {
   if (number_of_tries < 5) {
    ui_nntp_posting_retry(tinfo);
    sleep(5);
    number_of_tries++;
    continue;
   }
   else {
    total_failures++;
    if (total_failures == 5) {
     nntp_logoff(tinfo);
     socket_close(tinfo->sockfd);
     ui_posting_too_many_failures(tinfo);
    }
   }
  }
  number_of_tries = 0;
 }
 nntp_logoff(tinfo);
 socket_close(tinfo->sockfd);
 buff_free(article.subject);
 free(data_buffer);
 pthread_rwlock_wrlock(tinfo->rwlock);
 tinfo->status = 4;
 pthread_rwlock_unlock(tinfo->rwlock);
 pthread_exit(((void *)0));
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct poster_thread_arg { 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; } *data; 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; } *threadinfo; struct queue { struct post_article_t { 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 *rwlock; unsigned char post_started; int parts_posted; } *file_data; int partnumber; struct Buff *subject; } *article_list; long length; long head; unsigned char full; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *mut; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } *cond_not_full; } *fifo; } *

variable_types: struct queue { struct post_article_t { 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; } *file_data; int partnumber; struct Buff *subject; } *article_list; long length; long head; unsigned char full; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *mut; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } *cond_not_full; } *

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

return_type: void *

user_defined_types: struct poster_thread_arg { struct newspost_data *data; struct newspost_threadinfo *threadinfo; struct queue *fifo; }


decompiled_code:
__int64 __fastcall make_subject(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5, __int64 a6, unsigned int a7, __int64 a8)
{
__int64 v11; // rbp
const char *v12; // rsi
size_t v14; // rax
char s[88]; // [rsp+10h] [rbp-58h] BYREF

if ( *(_QWORD *)a2 )
v11 = buff_create(a1, "%s - ", **(const char ***)a2);
else
v11 = buff_create(a1, (const char *)&unk_C7C);
if ( *(_BYTE *)(a2 + 112) == 1 )
{
sprintf(s, "%i", a4);
v14 = strlen(s);
v11 = buff_add(v11, "%s %0*i of %i: ", a8, v14, a3, a4);
}
sprintf(s, "%i", a7);
strlen(s);
n_basename(a5);
v12 = "\"%s\" yEnc (%0*i/%i)";
if ( *(_BYTE *)(a2 + 72) )
v12 = "%s (%0*i/%i)";
return buff_add(v11, v12);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5, __int64 a6, unsigned int a7, __int64 a8)
{
__int64 v11; // rbp
const char *v12; // rsi
size_t v14; // rax
char s[88]; // [rsp+10h] [rbp-58h] BYREF

if ( *(_QWORD *)a2 )
v11 = buff_create(a1, "%s - ", **(const char ***)a2);
else
v11 = buff_create(a1, (const char *)&unk_C7C);
if ( *(_BYTE *)(a2 + 112) == 1 )
{
sprintf(s, "%i", a4);
v14 = strlen(s);
v11 = buff_add(v11, "%s %0*i of %i: ", a8, v14, a3, a4);
}
sprintf(s, "%i", a7);
strlen(s);
n_basename(a5);
v12 = "\"%s\" yEnc (%0*i/%i)";
if ( *(_BYTE *)(a2 + 72) )
v12 = "%s (%0*i/%i)";
return buff_add(v11, v12);
}

original_code:
static Buff *make_subject(Buff *subject, newspost_data *data, int filenumber,
    int number_of_files, const char *filename,
    int partnumber, int number_of_parts,
    const char *filestring) {
 char numbuf[32];
 int numsize;
 if (data->subject != ((void *)0))
  subject = buff_create(subject, "%s - ", data->subject->data);
 else
  subject = buff_create(subject, "");
 if (data->filenumber == 1){
  sprintf(numbuf, "%i", number_of_files);
  numsize = strlen(numbuf);
  subject = buff_add(subject, "%s %0*i of %i: ", filestring,
       numsize, filenumber, number_of_files);
 }
 sprintf(numbuf, "%i", number_of_parts);
 numsize = strlen(numbuf);
 subject = buff_add(subject, (data->uuenc == 0) ? "\"%s\" yEnc (%0*i/%i)" :
  "%s (%0*i/%i)", n_basename(filename), numsize,
  partnumber, number_of_parts);
 return subject;
}

canonical_original_code:
static struct Buff *make_subject(struct Buff *subject, struct newspost_data *data, int filenumber, int number_of_files, char *filename, int partnumber, int number_of_parts, char *filestring) {
 char numbuf[32];
 int numsize;
 if (data->subject != ((void *)0))
  subject = buff_create(subject, "%s - ", data->subject->data);
 else
  subject = buff_create(subject, "");
 if (data->filenumber == 1){
  sprintf(numbuf, "%i", number_of_files);
  numsize = strlen(numbuf);
  subject = buff_add(subject, "%s %0*i of %i: ", filestring,
       numsize, filenumber, number_of_files);
 }
 sprintf(numbuf, "%i", number_of_parts);
 numsize = strlen(numbuf);
 subject = buff_add(subject, (data->uuenc == 0) ? "\"%s\" yEnc (%0*i/%i)" :
  "%s (%0*i/%i)", n_basename(filename), numsize,
  partnumber, number_of_parts);
 return subject;
}

variable_types:
subject
struct Buff *

variable_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 { void *data; struct Newspost_SList *next; } *extra_headers; } *

variable_types: filenumber int

variable_types:
filename
char *

variable_types: partnumber int

variable_types:
filestring
char *

variable_types:
numbuf
char [32]

variable_types: numsize int

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

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


decompiled_code:
__int64 __fastcall encode_and_post(__int64 a1, __int64 *a2, __int64 *a3)
{
__int64 *v3; // r12
int v4; // ebp
_QWORD *v5; // r14
_QWORD *v6; // r13
__int64 v7; // r15
pthread_rwlock_t **v8; // rbp
pthread_t *v9; // rax
int v10; // er14
pthread_t *v11; // r12
pthread_rwlock_t *v12; // rax
struct stat *v13; // rbp
unsigned int v14; // er13
unsigned int v15; // ebp
__int64 *v16; // rbp
unsigned int v17; // er14
unsigned int v18; // er13
const char ***v19; // r12
char *v20; // rbp
__int64 v21; // r12
int *v22; // rax
pthread_rwlock_t **v23; // rbp
int v24; // er12
pthread_rwlock_t **ptr; // [rsp+8h] [rbp-60h]
_QWORD *v28; // [rsp+18h] [rbp-50h]
void *v29; // [rsp+20h] [rbp-48h]

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 *a2, __int64 *a3)
{
__int64 *v3; // r12
int v4; // ebp
_QWORD *v5; // r14
_QWORD *v6; // r13
__int64 v7; // r15
pthread_rwlock_t **v8; // rbp
pthread_t *v9; // rax
int v10; // er14
pthread_t *v11; // r12
pthread_rwlock_t *v12; // rax
struct stat *v13; // rbp
unsigned int v14; // er13
unsigned int v15; // ebp
__int64 *v16; // rbp
unsigned int v17; // er14
unsigned int v18; // er13
const char ***v19; // r12
char *v20; // rbp
__int64 v21; // r12
int *v22; // rax
pthread_rwlock_t **v23; // rbp
int v24; // er12
pthread_rwlock_t **ptr; // [rsp+8h] [rbp-60h]
_QWORD *v28; // [rsp+18h] [rbp-50h]
void *v29; // [rsp+20h] [rbp-48h]

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

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: retval int

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 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: struct newspost_threadinfo { int thread_id; int sockfd; union pthread_rwlock_t *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; }

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 post_article_t { struct file_entry *file_data; int partnumber; struct Buff *subject; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


newspost

decompiled_code:
__int64 __fastcall newspost(__int64 a1, __int64 *a2)
{
__int64 *v2; // r12
__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)
{
_WORD *v1; // rax

if ( *a1 )
{
v1 = a1 + 1;
do
++v1;
while ( *(v1 - 1) );
}
return stuni();
}

canonical_decompiled_code:
__int64 __fastcall func0(_WORD *a1)
{
_WORD *v1; // rax

if ( *a1 )
{
v1 = a1 + 1;
do
++v1;
while ( *(v1 - 1) );
}
return stuni();
}

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(_WORD *a1, _WORD *a2)
{
int v4; // ebx
int v5; // eax

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

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

while ( 1 )
{
if ( !*a1 && !*a2 )
return 0LL;
v4 = tolower((unsigned __int16)*a1);
v5 = tolower((unsigned __int16)*a2);
if ( v5 < v4 )
return 1LL;
if ( v5 > v4 )
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)
{
unsigned __int16 *v2; // rbx
_WORD *v3; // rbp
unsigned __int16 v4; // ax
__int64 result; // rax
unsigned __int16 v6; // r13
int v7; // er12

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

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

v2 = a1;
v3 = a2;
v4 = *a1;
if ( *a1 == *a2 )
{
while ( v4 )
{
++v2;
++v3;
v4 = *v2;
if ( *v2 != *v3 )
goto LABEL_4;
}
result = 0LL;
}
else
{
LABEL_4:
result = 0xFFFFFFFFLL;
if ( (cmd[12] & 0x10) == 0 )
{
while ( 1 )
{
v6 = *v2;
v7 = tolower(*v2);
if ( v7 != tolower((unsigned __int16)*v3) )
break;
if ( !v6 )
return 1LL;
++v2;
++v3;
}
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; // rbp

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; // rbp

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
_QWORD *v2; // rax
_QWORD *v3; // rbx
unsigned __int16 *v4; // r13

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

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

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

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


decompiled_code:
__int64 __fastcall hash_file(__int64 a1, char a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl
__int64 v4; // rdx
__int64 v5; // [rsp-4018h] [rbp-4018h] BYREF

result = 1LL;
if ( a2 > 0 )
{
v3 = *(_BYTE *)(a1 + 64);
if ( v3 )
{
result = 1LL;
if ( a2 <= 1 )
return result;
if ( v3 > 1u )
return 1LL;
}
else
{
result = file_md5_buffer(*(_QWORD *)(a1 + 48), a1 + 8, &v5, 0x4000LL);
if ( !(_DWORD)result )
return result;
*(_BYTE *)(a1 + 64) = 1;
result = 1LL;
if ( a2 <= 1 )
return result;
}
v4 = file_md5(*(_QWORD *)(a1 + 48), a1 + 24);
result = 1LL;
if ( v4 >= 0 )
{
*(_BYTE *)(a1 + 64) = 2;
if ( !*(_QWORD *)(a1 + 40) )
*(_QWORD *)(a1 + 40) = v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl
__int64 v4; // rdx
__int64 v5; // [rsp-4018h] [rbp-4018h] BYREF

result = 1LL;
if ( a2 > 0 )
{
v3 = *(_BYTE *)(a1 + 64);
if ( v3 )
{
result = 1LL;
if ( a2 <= 1 )
return result;
if ( v3 > 1u )
return 1LL;
}
else
{
result = file_md5_buffer(*(_QWORD *)(a1 + 48), a1 + 8, &v5, 0x4000LL);
if ( !(_DWORD)result )
return result;
*(_BYTE *)(a1 + 64) = 1;
result = 1LL;
if ( a2 <= 1 )
return result;
}
v4 = file_md5(*(_QWORD *)(a1 + 48), a1 + 24);
result = 1LL;
if ( v4 >= 0 )
{
*(_BYTE *)(a1 + 64) = 2;
if ( !*(_QWORD *)(a1 + 40) )
*(_QWORD *)(a1 + 40) = v4;
}
}
return result;
}

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; // r12
__int64 v6; // rbp
int v7; // eax

((void (*)(void))stuni)();
hash_directory();
v1 = stuni(a1);
v2 = complete_path(v1);
v3 = unist(v2);
v4 = hfile;
if ( !hfile )
return hfile;
v5 = (_WORD *)v3;
v6 = 0LL;
do
{
v7 = unicode_cmp(*(unsigned __int16 **)(v4 + 48), v5);
if ( v7 )
{
if ( v7 == 1 && !v6 )
v6 = v4;
}
else
{
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; // r12
__int64 v6; // rbp
int v7; // eax

((void (*)(void))stuni)();
func4();
v1 = stuni(a1);
v2 = complete_path(v1);
v3 = unist(v2);
v4 = hfile;
if ( !hfile )
return hfile;
v5 = (_WORD *)v3;
v6 = 0LL;
do
{
v7 = func2(*(unsigned __int16 **)(v4 + 48), v5);
if ( v7 )
{
if ( v7 == 1 && !v6 )
v6 = v4;
}
else
{
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


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

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


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

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

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

v3 = ~a3;
if ( a2 )
{
v4 = &a1[a2];
do
v3 = crctable[(unsigned __int8)(*a1++ ^ v3)] ^ (v3 >> 8);
while ( v4 != a1 );
}
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
int v3; // ebx
__int64 v4; // rax
__int64 v5; // rsi
__int64 v6; // r14
const char *v7; // r13
int v8; // ebp
_BYTE v9[16424]; // [rsp+0h] [rbp-4028h] BYREF

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

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

v1 = a1;
ui_crc_start();
if ( a1 )
{
do
{
v6 = *(_QWORD *)v1;
v7 = **(const char ***)(*(_QWORD *)v1 + 144LL);
v8 = open(v7, 0, 0LL);
v3 = 0;
if ( v8 >= 0 )
{
while ( 1 )
{
v4 = read(v8, v9, 0x4000uLL);
v5 = v4;
if ( v4 <= 0 )
break;
v3 = func0(v9, v4, v3);
}
if ( v4 < 0 )
{
v5 = (unsigned int)*_errno_location();
ui_crc_error(v7, v5);
}
else
{
*(_DWORD *)(v6 + 152) = v3;
}
close(v8);
}
else
{
v5 = (unsigned int)*_errno_location();
ui_crc_error(v7, v5);
}
v1 = slist_next(v1, v5);
}
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 v6; // rbx

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

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

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

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

do
v2 = func10(a1);
while ( -a2 % a2 > 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; // rbx
char v4; // bp
time_t v5; // rbx
time_t v6; // rax
int v7; // ebp
int v8; // ebx
unsigned __int64 v9; // rax
int v10; // ebx
int v11; // eax
unsigned __int64 i; // rbx
int v13; // eax
char v14; // cl
__int64 j; // rbx
int v16; // ebx
__int64 v17; // rax
char v19; // [rsp+1h] [rbp-89h] BYREF
char v20[64]; // [rsp+2h] [rbp-88h]
char v21[44]; // [rsp+42h] [rbp-48h] BYREF
int v22[7]; // [rsp+6Eh] [rbp-1Ch] BYREF

v22[0] = 5;
if ( argc > 1 )
{
if ( !strcmp(argv[1], "-r") )
{
v3 = argv + 2;
if ( argc <= 2 )
goto LABEL_5;
v4 = 1;
}
else
{
v3 = argv + 1;
v4 = 0;
}
v22[0] = atoi(*v3);
if ( v4 )
{
LABEL_5:
v5 = time(0LL);
v6 = time(0LL);
pcg32x2_srandom_r((__int64)v21, v6 ^ 0x401040, ~(v5 ^ 0x401540), (__int64)v22, (__int64)&dummy_global);
goto LABEL_6;
}
}
pcg32x2_srandom_r((__int64)v21, 42LL, 42LL, 54LL, 54LL);
LABEL_6:
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 ( v22[0] > 0 )
{
v7 = 1;
do
{
printf("Round %d:\n", (unsigned int)v7);
printf(" 64bit:");
v16 = 0;
while ( 1 )
{
v17 = pcg32x2_random_r((__int64)v21);
printf(" 0x%016llx", v17);
if ( ++v16 == 6 )
break;
if ( v16 > 0 && v16 == 3 * (v16 / 3) )
printf("\n\t");
}
putchar(10);
printf(" Coins: ");
v8 = 65;
do
{
v9 = pcg32x2_boundedrand_r((__int64)v21, 2uLL);
putchar(v9 == 0 ? 84 : 72);
--v8;
}
while ( v8 );
putchar(10);
printf(" Rolls:");
v10 = 33;
do
{
v11 = pcg32x2_boundedrand_r((__int64)v21, 6uLL);
printf(" %d", (unsigned int)(v11 + 1));
--v10;
}
while ( v10 );
putchar(10);
for ( i = 0LL; i != 52; ++i )
v20[i] = i;
do
{
v13 = pcg32x2_boundedrand_r((__int64)v21, i);
v14 = v20[v13];
v20[v13] = *(&v19 + i);
*(&v19 + i--) = v14;
}
while ( i != 1 );
printf(" Cards:");
printf(" %c%c", (unsigned int)number_0[v20[0] / 4], (unsigned int)suit_1[v20[0] % 4]);
for ( j = 2LL; j != 53; ++j )
{
printf(" %c%c", (unsigned int)number_0[*(&v19 + j) / 4], (unsigned int)suit_1[*(&v19 + j) % 4]);
if ( 22 * ((int)j / 22) == (_DWORD)j )
printf("\n\t");
}
putchar(10);
putchar(10);
++v7;
}
while ( v22[0] >= v7 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
char v4; // bp
time_t v5; // rbx
time_t v6; // rax
int v7; // ebp
int v8; // ebx
unsigned __int64 v9; // rax
int v10; // ebx
int v11; // eax
unsigned __int64 i; // rbx
int v13; // eax
char v14; // cl
__int64 j; // rbx
int v16; // ebx
__int64 v17; // rax
char v19; // [rsp+1h] [rbp-89h] BYREF
char v20[64]; // [rsp+2h] [rbp-88h]
char v21[44]; // [rsp+42h] [rbp-48h] BYREF
int v22[7]; // [rsp+6Eh] [rbp-1Ch] BYREF

v22[0] = 5;
if ( argc > 1 )
{
if ( !strcmp(argv[1], "-r") )
{
v3 = argv + 2;
if ( argc <= 2 )
goto LABEL_5;
v4 = 1;
}
else
{
v3 = argv + 1;
v4 = 0;
}
v22[0] = atoi(*v3);
if ( v4 )
{
LABEL_5:
v5 = time(0LL);
v6 = time(0LL);
func7((__int64)v21, v6 ^ 0x401040, ~(v5 ^ 0x401540), (__int64)v22, (__int64)&dummy_global);
goto LABEL_6;
}
}
func7((__int64)v21, 42LL, 42LL, 54LL, 54LL);
LABEL_6:
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 ( v22[0] > 0 )
{
v7 = 1;
do
{
printf("Round %d:\n", (unsigned int)v7);
printf(" 64bit:");
v16 = 0;
while ( 1 )
{
v17 = func8((__int64)v21);
printf(" 0x%016llx", v17);
if ( ++v16 == 6 )
break;
if ( v16 > 0 && v16 == 3 * (v16 / 3) )
printf("\n\t");
}
putchar(10);
printf(" Coins: ");
v8 = 65;
do
{
v9 = func9((__int64)v21, 2uLL);
putchar(v9 == 0 ? 84 : 72);
--v8;
}
while ( v8 );
putchar(10);
printf(" Rolls:");
v10 = 33;
do
{
v11 = func9((__int64)v21, 6uLL);
printf(" %d", (unsigned int)(v11 + 1));
--v10;
}
while ( v10 );
putchar(10);
for ( i = 0LL; i != 52; ++i )
v20[i] = i;
do
{
v13 = func9((__int64)v21, i);
v14 = v20[v13];
v20[v13] = *(&v19 + i);
*(&v19 + i--) = v14;
}
while ( i != 1 );
printf(" Cards:");
printf(" %c%c", (unsigned int)number_0[v20[0] / 4], (unsigned int)suit_1[v20[0] % 4]);
for ( j = 2LL; j != 53; ++j )
{
printf(" %c%c", (unsigned int)number_0[*(&v19 + j) / 4], (unsigned int)suit_1[*(&v19 + j) % 4]);
if ( 22 * ((int)j / 22) == (_DWORD)j )
printf("\n\t");
}
putchar(10);
putchar(10);
++v7;
}
while ( v22[0] >= v7 );
}
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)
{
char v3[10]; // [rsp+Eh] [rbp-Ah] BYREF

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

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

v3[0] = HIBYTE(a2);
v3[1] = a2;
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:
size_t __fastcall hash(const char *a1)
{
size_t result; // rax
const char *v2; // rdx
__int64 v3; // rsi

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

canonical_decompiled_code:
size_t __fastcall func1(const char *a1)
{
size_t result; // rax
const char *v2; // rdx
__int64 v3; // rsi

if ( !a1 )
_assert_fail("key != NULL", "HashTable.c", 0xDu, "hash");
result = strlen(a1);
if ( (_DWORD)result )
{
v2 = a1;
v3 = (__int64)&a1[(unsigned int)(result - 1) + 1];
LODWORD(result) = 0;
do
{
result = (unsigned int)(*v2 + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = ((result & 0xF0000000) >> 24) ^ result & 0xFFFFFFF;
++v2;
}
while ( v2 != (const char *)v3 );
}
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(_QWORD *a1, int a2)
{
_QWORD *v2; // rax

if ( a2 > 0 )
{
v2 = a1;
do
*v2++ = 0LL;
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

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

if ( a2 > 0 )
{
v2 = a1;
do
*v2++ = 0LL;
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

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, char *a2, __int64 a3)
{
int v5; // esi
_QWORD *v6; // r13
int v8; // esi
_QWORD *v9; // rax

if ( !a1 )
_assert_fail("b != NULL", "HashTable.c", 0x36u, "setInBucket");
v5 = a1[1];
if ( *a1 >= v5 )
{
v8 = 2 * v5;
a1[1] = v8;
v9 = realloc(*((void **)a1 + 1), 8LL * v8);
*((_QWORD *)a1 + 1) = v9;
fillWithNulls(&v9[*a1], a1[1] - *a1);
}
v6 = (_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1);
*v6 = createRecord(a2, a3);
++*a1;
return 0LL;
}

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:
_DWORD *createBucket()
{
_DWORD *v0; // rbx
_QWORD *v1; // rax

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

canonical_decompiled_code:
_DWORD *func6()
{
_DWORD *v0; // rbx
_QWORD *v1; // rax

v0 = malloc(0x10uLL);
*v0 = 0;
v0[1] = 1;
v1 = malloc(8uLL);
*((_QWORD *)v0 + 1) = v1;
func2(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 v1; // rbx

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

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
__int64 v1; // rbx

if ( ptr )
{
if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
func3(*(void **)(*((_QWORD *)ptr + 1) + 8 * v1++));
while ( *(_DWORD *)ptr > (int)v1 );
}
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