main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r13
__int64 v4; // r12
unsigned int v5; // ebx
__int64 v6; // rsi
void *v7; // rbp
char v9[64]; // [rsp+0h] [rbp-1A8h] BYREF
struct sigaction v10; // [rsp+40h] [rbp-168h] BYREF
struct sigaction v11; // [rsp+E0h] [rbp-C8h] BYREF

v11.sa_handler = (__sighandler_t)handler;
v3 = readKey();
sigemptyset(&v11.sa_mask);
sigaddset(&v11.sa_mask, 13);
v11.sa_flags = 0x10000000;
sigaction(13, &v11, &v10);
v4 = swal_connect(2LL, v3);
if ( !v4 )
puts("Connection failed");
v5 = 3972300;
do
{
sprintf(v9, "Data/PlayerSummaries_Exhaustive/player_summaries_%08d.json", v5);
puts(v9);
v6 = v5;
v5 += 100;
v7 = (void *)generateIDs(1LL, v6);
swal_get_player_summaries(v4, v7, v9);
free(v7);
usleep(0xF4240u);
}
while ( v5 != 30000000 );
swal_disconnect(v4);
free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r13
__int64 v4; // r12
unsigned int v5; // ebx
__int64 v6; // rsi
void *v7; // rbp
char v9[64]; // [rsp+0h] [rbp-1A8h] BYREF
struct sigaction v10; // [rsp+40h] [rbp-168h] BYREF
struct sigaction v11; // [rsp+E0h] [rbp-C8h] BYREF

v11.sa_handler = (__sighandler_t)handler;
v3 = func1();
sigemptyset(&v11.sa_mask);
sigaddset(&v11.sa_mask, 13);
v11.sa_flags = 0x10000000;
sigaction(13, &v11, &v10);
v4 = swal_connect(2LL, v3);
if ( !v4 )
puts("Connection failed");
v5 = 3972300;
do
{
sprintf(v9, "Data/PlayerSummaries_Exhaustive/player_summaries_%08d.json", v5);
puts(v9);
v6 = v5;
v5 += 100;
v7 = (void *)generateIDs(1LL, v6);
swal_get_player_summaries(v4, v7, v9);
free(v7);
usleep(0xF4240u);
}
while ( v5 != 30000000 );
swal_disconnect(v4);
free(v3);
return 0;
}

original_code:
int main(int argc, char* argv[]) {
 int i;
 int index;
 char* buffer;
 char filename[sizeof("Data/PlayerSummaries_Exhaustive/player_summaries_10000000.json")];
 struct sigaction sigold, signew;
 char* key = readKey();
 signew.__sigaction_handler.sa_handler = handler;
 sigemptyset(&signew.sa_mask);
 sigaddset(&signew.sa_mask, 13);
 signew.sa_flags = 0x10000000;
 sigaction(13, &signew, &sigold);
 swal_con* conn = swal_connect(2, key);
 if (!conn) {
  printf("Connection failed\n");
 }
 for (i = 39723; i < 300000; i++) {
  index = i*100;
  sprintf(filename, "Data/PlayerSummaries_Exhaustive/player_summaries_%08d.json", index);
  printf("%s\n",filename);
  buffer = generateIDs(1, index);
  swal_get_player_summaries(conn, buffer, filename);
  free(buffer);
  usleep(1000000);
 }
 swal_disconnect(conn);
 free(key);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int i;
 int index;
 char *buffer;
 char filename[-1];
 struct sigaction sigold; struct sigaction signew;
 char *key = readKey();
 signew.__sigaction_handler.sa_handler = handler;
 sigemptyset(&signew.sa_mask);
 sigaddset(&signew.sa_mask, 13);
 signew.sa_flags = 0x10000000;
 sigaction(13, &signew, &sigold);
 struct swal_con *conn = swal_connect(2, key);
 if (!conn) {
  printf("Connection failed\n");
 }
 for (i = 39723; i < 300000; i++) {
  index = i*100;
  sprintf(filename, "Data/PlayerSummaries_Exhaustive/player_summaries_%08d.json", index);
  printf("%s\n",filename);
  buffer = generateIDs(1, index);
  swal_get_player_summaries(conn, buffer, filename);
  free(buffer);
  usleep(1000000);
 }
 swal_disconnect(conn);
 free(key);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: index int

variable_types:
buffer
char *

variable_types:
filename
char [-1]

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types:
key
char *

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


unistr

decompiled_code:
__int16 __fastcall unistr(char *a1, __int64 a2)
{
__int16 result; // ax

do
{
result = *a1++;
a2 += 2LL;
*(_WORD *)(a2 - 2) = result;
}
while ( *(a1 - 1) );
return result;
}

canonical_decompiled_code:
__int16 __fastcall func0(char *a1, __int64 a2)
{
__int16 result; // ax

do
{
result = *a1++;
a2 += 2LL;
*(_WORD *)(a2 - 2) = result;
}
while ( *(a1 - 1) );
return result;
}

original_code:
static void
unistr(const char *str, u16 *buf)
{
 do *buf++ = *str; while (*str++);
}

canonical_original_code:
static void unistr(char *str, unsigned short *buf)
{
 do *buf++ = *str; while (*str++);
}

variable_types:
str
char *

variable_types:
buf
unsigned short *

return_type: void


decompiled_code:
__int64 __fastcall make_uni_str(char *a1)
{
size_t v1; // rax
void *v2; // rax
__int64 v3; // r8

v1 = strlen(a1);
v2 = malloc(2 * v1 + 2);
unistr(a1, (__int64)v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
size_t v1; // rax
void *v2; // rax
__int64 v3; // r8

v1 = strlen(a1);
v2 = malloc(2 * v1 + 2);
func0(a1, (__int64)v2);
return v3;
}

original_code:
u16 *
make_uni_str(const char *str)
{
 u16 *uni;
 ((uni) = (malloc(sizeof(*(uni)) * (strlen(str) +1))));
 unistr(str, uni);
 return uni;
}

canonical_original_code:
unsigned short *make_uni_str(char *str)
{
 unsigned short *uni;
 ((uni) = (malloc(sizeof(*(uni)) * (strlen(str) +1))));
 unistr(str, uni);
 return uni;
}

variable_types:
uni
unsigned short *

return_type: unsigned short *


decompiled_code:
__int64 __fastcall uni_copy(_WORD *a1, __int16 *a2, __int64 a3)
{
__int16 v3; // cx
__int64 v5; // rsi
_WORD *v6; // rdx
__int64 result; // rax
_WORD *v8; // rdi

v3 = *a2;
if ( *a2 && (v5 = a3 - 1, a3 - 1 > 0) )
{
v6 = a1 + 1;
result = 0LL;
do
{
++result;
*(v6 - 1) = v3;
v8 = v6;
v3 = a2[result];
if ( !v3 )
break;
++v6;
}
while ( result != v5 );
*v8 = 0;
}
else
{
result = 0LL;
*a1 = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_WORD *a1, __int16 *a2, __int64 a3)
{
__int16 v3; // cx
__int64 v5; // rsi
_WORD *v6; // rdx
__int64 result; // rax
_WORD *v8; // rdi

v3 = *a2;
if ( *a2 && (v5 = a3 - 1, a3 - 1 > 0) )
{
v6 = a1 + 1;
result = 0LL;
do
{
++result;
*(v6 - 1) = v3;
v8 = v6;
v3 = a2[result];
if ( !v3 )
break;
++v6;
}
while ( result != v5 );
*v8 = 0;
}
else
{
result = 0LL;
*a1 = 0;
}
return result;
}

canonical_original_code:
long long uni_copy(unsigned short *dst, unsigned short *src, long long n)
{
 long long i;
 for (i = 0; src[i] && (i < (n - 1)); i++)
  dst[i] = src[i];
 dst[i] = 0;
 return i;
}

variable_types:
dst
unsigned short *

variable_types:
src
unsigned short *

variable_types:
n
long long

variable_types:
i
long long

return_type: long long


decompiled_code:
int __fastcall file_delete(__int16 *a1)
{
const char *v1; // rax

v1 = stuni(a1);
return remove(v1);
}

canonical_decompiled_code:
int __fastcall func7(__int16 *a1)
{
const char *v1; // rax

v1 = stuni(a1);
return remove(v1);
}

original_code:
int
file_delete(u16 *file)
{
 return remove(stuni(file));
}

canonical_original_code:
int file_delete(unsigned short *file)
{
 return remove(stuni(file));
}

variable_types:
file
unsigned short *

return_type: int


decompiled_code:
__int64 __fastcall complete_path(__int64 a1)
{
return a1;
}

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

original_code:
char *
complete_path(char *path)
{
 return path;
}

canonical_original_code:
char *complete_path(char *path)
{
 return path;
}

variable_types:
path
char *

return_type: char *


decompiled_code:
__int64 __fastcall socket_create(char *name, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
struct hostent *v5; // rax
int v6; // edi
struct in_addr inp; // [rsp+0h] [rbp-160h] BYREF
int optval; // [rsp+4h] [rbp-15Ch] BYREF
struct sockaddr addr; // [rsp+8h] [rbp-158h] BYREF
struct sigaction v10; // [rsp+18h] [rbp-148h] BYREF
struct sigaction v11; // [rsp+B8h] [rbp-A8h] BYREF

addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a2);
if ( inet_aton(name, &inp) )
{
*(struct in_addr *)&addr.sa_data[2] = inp;
}
else
{
v5 = gethostbyname(name);
if ( !v5 )
return (unsigned int)-2;
memcpy(&addr.sa_data[2], *(const void **)v5->h_addr_list, v5->h_length);
}
v2 = socket(2, 1, 0);
v3 = v2;
if ( v2 < 0 )
return (unsigned int)-3;
if ( connect(v2, &addr, 0x10u) < 0 || (optval = 1, setsockopt(v3, 1, 9, &optval, 4u) < 0) )
{
v6 = v3;
v3 = -3;
close(v6);
}
else
{
v10.sa_handler = (__sighandler_t)(_bswap_16 + 1);
sigemptyset(&v10.sa_mask);
v10.sa_flags = 0;
sigaction(13, &v10, &v11);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *name, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
struct hostent *v5; // rax
int v6; // edi
struct in_addr inp; // [rsp+0h] [rbp-160h] BYREF
int optval; // [rsp+4h] [rbp-15Ch] BYREF
struct sockaddr addr; // [rsp+8h] [rbp-158h] BYREF
struct sigaction v10; // [rsp+18h] [rbp-148h] BYREF
struct sigaction v11; // [rsp+B8h] [rbp-A8h] BYREF

addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(a2);
if ( inet_aton(name, &inp) )
{
*(struct in_addr *)&addr.sa_data[2] = inp;
}
else
{
v5 = gethostbyname(name);
if ( !v5 )
return (unsigned int)-2;
memcpy(&addr.sa_data[2], *(const void **)v5->h_addr_list, v5->h_length);
}
v2 = socket(2, 1, 0);
v3 = v2;
if ( v2 < 0 )
return (unsigned int)-3;
if ( connect(v2, &addr, 0x10u) < 0 || (optval = 1, setsockopt(v3, 1, 9, &optval, 4u) < 0) )
{
v6 = v3;
v3 = -3;
close(v6);
}
else
{
v10.sa_handler = (__sighandler_t)(_bswap_16 + 1);
sigemptyset(&v10.sa_mask);
v10.sa_flags = 0;
sigaction(13, &v10, &v11);
}
return v3;
}

original_code:
int socket_create(const char *address, int port) {
 struct sigaction act, oact;
 struct sockaddr_in serv_addr;
 struct in_addr inaddr;
 int on;
 struct hostent *hp;
 int sockfd = -1;
 memset ( &serv_addr, 0, sizeof(serv_addr) );
 serv_addr.sin_family = 2;
 serv_addr.sin_port = htons(port);
 if ( inet_aton(address, &inaddr) != 0 )
 {
  memcpy(&serv_addr.sin_addr, &inaddr, sizeof(inaddr));
 }
 else
 {
  if (((void *)0) == (hp = gethostbyname(address)))
   return -2;
  memcpy(&serv_addr.sin_addr, hp->h_addr_list[0], hp->h_length);
 }
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0)
  return -3;
 if (connect(sockfd, (struct sockaddr*) &serv_addr,
     sizeof(serv_addr)) < 0) {
  close (sockfd);
  return -3;
 }
 on = 1;
 if (setsockopt(sockfd, 1, 9,
     (char*) &on, sizeof(on)) < 0) {
  close(sockfd);
  return -3;
 }
 act.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 sigaction(13, &act, &oact);
        return sockfd;
}

canonical_original_code:
int socket_create(char *address, int port) {
 struct sigaction act; struct sigaction oact;
 struct sockaddr_in serv_addr;
 struct in_addr inaddr;
 int on;
 struct hostent *hp;
 int sockfd = -1;
 memset ( &serv_addr, 0, sizeof(serv_addr) );
 serv_addr.sin_family = 2;
 serv_addr.sin_port = htons(port);
 if ( inet_aton(address, &inaddr) != 0 )
 {
  memcpy(&serv_addr.sin_addr, &inaddr, sizeof(inaddr));
 }
 else
 {
  if (((void *)0) == (hp = gethostbyname(address)))
   return -2;
  memcpy(&serv_addr.sin_addr, hp->h_addr_list[0], hp->h_length);
 }
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0)
  return -3;
 if (connect(sockfd, (struct sockaddr *) &serv_addr,
     sizeof(serv_addr)) < 0) {
  close (sockfd);
  return -3;
 }
 on = 1;
 if (setsockopt(sockfd, 1, 9,
     (char *) &on, sizeof(on)) < 0) {
  close(sockfd);
  return -3;
 }
 act.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 sigaction(13, &act, &oact);
        return sockfd;
}

variable_types:
address
char *

variable_types: port int

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

variable_types:
inaddr
struct in_addr { unsigned int s_addr; }

variable_types: on int

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: sockfd int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

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


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

if ( a1 >= 0 )
result = close(a1);
return result;
}

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

if ( a1 >= 0 )
result = close(a1);
return result;
}

original_code:
void socket_close(int sockfd) {
 if (sockfd >= 0)
  close(sockfd);
}


decompiled_code:
ssize_t __fastcall socket_write(int a1, const void *a2, size_t a3)
{
ssize_t result; // rax
ssize_t v4; // r12
int *v5; // rax

result = write(a1, a2, a3);
v4 = result;
if ( result < 0 )
{
v5 = _errno_location();
ui_socket_error((unsigned int)*v5);
result = v4;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(int a1, const void *a2, size_t a3)
{
ssize_t result; // rax
ssize_t v4; // r12
int *v5; // rax

result = write(a1, a2, a3);
v4 = result;
if ( result < 0 )
{
v5 = _errno_location();
ui_socket_error((unsigned int)*v5);
result = v4;
}
return result;
}

original_code:
long socket_write(int sockfd, const char *buffer, long length) {
 long retval;
 retval = write(sockfd, buffer, length);
 if(retval < 0){
  ui_socket_error((*__errno_location ()));
  return retval;
 }
 else{
  return retval;
 }
}

canonical_original_code:
long socket_write(int sockfd, char *buffer, long length) {
 long retval;
 retval = write(sockfd, buffer, length);
 if(retval < 0){
  ui_socket_error((*__errno_location ()));
  return retval;
 }
 else{
  return retval;
 }
}

variable_types:
buffer
char *

variable_types: length long

variable_types: retval long

return_type: long


decompiled_code:
__int64 __fastcall socket_getline(int fd, void *buf)
{
__int64 v2; // r12
ssize_t v4; // rax
ssize_t v5; // rbx
int *v6; // rax

v2 = 0LL;
do
{
while ( 1 )
{
v4 = read(fd, buf, 1uLL);
v5 = v4;
if ( v4 < 0 )
break;
buf = (char *)buf + 1;
v2 += v4;
if ( *((char *)buf - 1) == 10 )
goto LABEL_5;
}
v6 = _errno_location();
buf = (char *)buf + 1;
v2 += v5;
ui_socket_error((unsigned int)*v6);
}
while ( *((char *)buf - 1) != 10 );
LABEL_5:
*(_BYTE *)buf = 0;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, void *buf)
{
__int64 v2; // r12
ssize_t v4; // rax
ssize_t v5; // rbx
int *v6; // rax

v2 = 0LL;
do
{
while ( 1 )
{
v4 = read(fd, buf, 1uLL);
v5 = v4;
if ( v4 < 0 )
break;
buf = (char *)buf + 1;
v2 += v4;
if ( *((char *)buf - 1) == 10 )
goto LABEL_5;
}
v6 = _errno_location();
buf = (char *)buf + 1;
v2 += v5;
ui_socket_error((unsigned int)*v6);
}
while ( *((char *)buf - 1) != 10 );
LABEL_5:
*(_BYTE *)buf = 0;
return v2;
}

original_code:
long socket_getline(int sockfd, char *buffer) {
 long retval;
 char *pi;
 long i;
 long read_count = 0;
 i = 0;
 pi = buffer;
 while (1) {
  retval = read(sockfd, pi, 1);
  if(retval < 0)
   ui_socket_error((*__errno_location ()));
  read_count += retval;
  pi++;
  if (buffer[i] == '\n')
   break;
  i++;
 }
 *pi = '\0';
 return read_count;
}

variable_types:
pi
char *

variable_types: i long


decompiled_code:
void __fastcall queue_delete(void *ptr)
{
__int64 v1; // rbx
__int64 v2; // rax

if ( *((__int64 *)ptr + 1) > 0 )
{
v1 = 0LL;
do
{
v2 = 3 * v1++;
buff_free(*(_QWORD *)(*(_QWORD *)ptr + 8 * v2 + 16));
}
while ( *((_QWORD *)ptr + 1) > v1 );
}
free(*(void **)ptr);
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 5));
free(*((void **)ptr + 5));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 6));
free(*((void **)ptr + 6));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 7));
free(*((void **)ptr + 7));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 8));
free(*((void **)ptr + 8));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 9));
free(*((void **)ptr + 9));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
__int64 v1; // rbx
__int64 v2; // rax

if ( *((__int64 *)ptr + 1) > 0 )
{
v1 = 0LL;
do
{
v2 = 3 * v1++;
buff_free(*(_QWORD *)(*(_QWORD *)ptr + 8 * v2 + 16));
}
while ( *((_QWORD *)ptr + 1) > v1 );
}
free(*(void **)ptr);
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 5));
free(*((void **)ptr + 5));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 6));
free(*((void **)ptr + 6));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 7));
free(*((void **)ptr + 7));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 8));
free(*((void **)ptr + 8));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 9));
free(*((void **)ptr + 9));
free(ptr);
}

original_code:
void queue_delete(queue *q) {
 int i;
 for (i = 0; i < q->length; i++)
  buff_free(q->article_list[i].subject);
 free(q->article_list);
 pthread_mutex_destroy(q->mut);
 free(q->mut);
 pthread_cond_destroy(q->cond_not_full);
 free(q->cond_not_full);
 pthread_cond_destroy(q->cond_not_empty);
 free(q->cond_not_empty);
 pthread_cond_destroy(q->cond_producer_done);
 free(q->cond_producer_done);
 pthread_cond_destroy(q->cond_empty);
 free(q->cond_empty);
 free(q);
}

canonical_original_code:
void queue_delete(struct queue *q) {
 int i;
 for (i = 0; i < q->length; i++)
  buff_free(q->article_list[i].subject);
 free(q->article_list);
 pthread_mutex_destroy(q->mut);
 free(q->mut);
 pthread_cond_destroy(q->cond_not_full);
 free(q->cond_not_full);
 pthread_cond_destroy(q->cond_not_empty);
 free(q->cond_not_empty);
 pthread_cond_destroy(q->cond_producer_done);
 free(q->cond_producer_done);
 pthread_cond_destroy(q->cond_empty);
 free(q->cond_empty);
 free(q);
}

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

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: 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 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 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: union pthread_rwlock_t { struct __pthread_rwlock_arch_t __data; char __size[56]; long __align; }


original_code:
void queue_item_add(queue *q, post_article_t *in) {
 post_article_t *item = &q->article_list[q->tail];
 item->file_data = in->file_data;
 item->partnumber = in->partnumber;
 item->subject = buff_create(item->subject, "%s", in->subject->data);
 q->tail++;
 if (q->tail == q->length)
  q->tail = 0;
 if (q->tail == q->head)
  q->full = 1;
 q->empty = 0;
 return;
}

canonical_original_code:
void queue_item_add(struct queue *q, struct post_article_t *in) {
 struct post_article_t *item = &q->article_list[q->tail];
 item->file_data = in->file_data;
 item->partnumber = in->partnumber;
 item->subject = buff_create(item->subject, "%s", in->subject->data);
 q->tail++;
 if (q->tail == q->length)
  q->tail = 0;
 if (q->tail == q->head)
  q->full = 1;
 q->empty = 0;
 return;
}

variable_types:
in
struct post_article_t *

variable_types: 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; } *

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


original_code:
int queue_item_del(queue *q, post_article_t *out) {
 if (q->empty && q->producer_done)
  return -1;
 else if (q->empty)
  return 0;
 post_article_t *item = &q->article_list[q->head];
 out->file_data = item->file_data;
 out->partnumber = item->partnumber;
 out->subject = buff_create(out->subject, "%s", item->subject->data);
 q->head++;
 if (q->head == q->length)
  q->head = 0;
 if (q->head == q->tail)
  q->empty = 1;
 q->full = 0;
 int n = q->tail - q->head;
 if (n < 0)
  n += q->length;
 return n;
}

canonical_original_code:
int queue_item_del(struct queue *q, struct post_article_t *out) {
 if (q->empty && q->producer_done)
  return -1;
 else if (q->empty)
  return 0;
 struct post_article_t *item = &q->article_list[q->head];
 out->file_data = item->file_data;
 out->partnumber = item->partnumber;
 out->subject = buff_create(out->subject, "%s", item->subject->data);
 q->head++;
 if (q->head == q->length)
  q->head = 0;
 if (q->head == q->tail)
  q->empty = 1;
 q->full = 0;
 int n = q->tail - q->head;
 if (n < 0)
  n += q->length;
 return n;
}

variable_types:
out
struct post_article_t *

variable_types: n int

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

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

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


decompiled_code:
void __noreturn signal_handler()
{
const char **v0; // rax

fwrite("\nSignal received", 1uLL, 0x10uLL, stderr);
if ( tmpdir_ptr )
{
fwrite("\nDeleting temporary files... ", 1uLL, 0x1DuLL, stderr);
if ( rmdir((const char *)*tmpdir_ptr) == -1 )
{
v0 = (const char **)buff_create(0LL, "rm -rf %s", (const char *)*tmpdir_ptr);
system(*v0);
}
fwrite("done.", 1uLL, 5uLL, stderr);
}
fputc(10, stderr);
exit(-13);
}

canonical_decompiled_code:
void __noreturn func0()
{
const char **v0; // rax

fwrite("\nSignal received", 1uLL, 0x10uLL, stderr);
if ( tmpdir_ptr )
{
fwrite("\nDeleting temporary files... ", 1uLL, 0x1DuLL, stderr);
if ( rmdir((const char *)*tmpdir_ptr) == -1 )
{
v0 = (const char **)buff_create(0LL, "rm -rf %s", (const char *)*tmpdir_ptr);
system(*v0);
}
fwrite("done.", 1uLL, 5uLL, stderr);
}
fputc(10, stderr);
exit(-13);
}

original_code:
static void signal_handler() {
 Buff *command = ((void *)0);
 fprintf(stderr, "\nSignal received");
 if (tmpdir_ptr != ((void *)0)) {
  fprintf(stderr, "\nDeleting temporary files... ");
  if (rmdir(tmpdir_ptr->data) == -1) {
   command = buff_create(command,
     "rm -rf %s", tmpdir_ptr->data);
   system(command->data);
  }
  fprintf(stderr, "done.");
 }
 fprintf(stderr, "\n");
 exit(-13);
}

canonical_original_code:
static void signal_handler() {
 struct Buff *command = ((void *)0);
 fprintf(stderr, "\nSignal received");
 if (tmpdir_ptr != ((void *)0)) {
  fprintf(stderr, "\nDeleting temporary files... ");
  if (rmdir(tmpdir_ptr->data) == -1) {
   command = buff_create(command,
     "rm -rf %s", tmpdir_ptr->data);
   system(command->data);
  }
  fprintf(stderr, "done.");
 }
 fprintf(stderr, "\n");
 exit(-13);
}

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // r12
__int64 v5; // rbp
char **v6; // rax
char *v7; // rdi
int v8; // edi
const char **v9; // rbp
char v10; // r13
int v11; // ebx
const char *v12; // rdi
const char **v13; // rax
_QWORD *i; // r12
__int64 v15; // rdi
int *v16; // rax
const char *v17; // rdi
__int64 j; // rdi
_BYTE *v19; // rax
__int64 v20; // r12
const char **v21; // rax
const char *v22; // rdx
FILE *v23; // rax
int *v24; // rax
char *v25; // rax
__int64 v26; // r13
const char **v27; // rax
struct sigaction v29; // [rsp+0h] [rbp-178h] BYREF
__int64 v30; // [rsp+A0h] [rbp-D8h] BYREF
__int64 v31; // [rsp+A8h] [rbp-D0h]
__int64 v32; // [rsp+B0h] [rbp-C8h]
__int64 v33; // [rsp+B8h] [rbp-C0h]
__int64 v34; // [rsp+C0h] [rbp-B8h]
int v35; // [rsp+C8h] [rbp-B0h]
__int64 v36; // [rsp+D0h] [rbp-A8h]
__int64 v37; // [rsp+D8h] [rbp-A0h]
__int64 v38; // [rsp+E0h] [rbp-98h]
char v39; // [rsp+E8h] [rbp-90h]
__int64 v40; // [rsp+F0h] [rbp-88h]
__int64 v41; // [rsp+F8h] [rbp-80h]
__int64 v42; // [rsp+100h] [rbp-78h]
__int64 v43; // [rsp+108h] [rbp-70h]
char v44; // [rsp+110h] [rbp-68h]
const char **v45; // [rsp+118h] [rbp-60h]
char v46; // [rsp+120h] [rbp-58h]
__int64 v47; // [rsp+128h] [rbp-50h]
__int64 v48; // [rsp+130h] [rbp-48h]
__int64 v49; // [rsp+138h] [rbp-40h]
char v50; // [rsp+140h] [rbp-38h]
_QWORD *v51; // [rsp+148h] [rbp-30h]

if ( argc == 1 )
print_help(argc, argv, envp);
v30 = 0LL;
v38 = 0x138800000001LL;
v42 = 0xA00000000LL;
v31 = 0LL;
v32 = 0LL;
v33 = 0LL;
v34 = 0LL;
v35 = 119;
v36 = 0LL;
v37 = 0LL;
v39 = 0;
v40 = 0LL;
v41 = 0LL;
v43 = 0LL;
v44 = 1;
v45 = 0LL;
v46 = 1;
v47 = 0LL;
v48 = 0LL;
v49 = 0LL;
v51 = 0LL;
v50 = 0;
parse_environment(&v30, argv, envp);
parse_defaults(&v30);
v3 = parse_options((unsigned int)argc, argv, &v30);
v4 = parse_input_files((unsigned int)argc, argv, v3, &v30);
if ( writedefaults == 1 )
{
v17 = "\nDefaults written.";
if ( (unsigned __int8)set_defaults(&v30) != 1 )
v17 = "\nDefaults NOT written.";
printf(v17);
fflush(stdout);
}
check_options(&v30);
if ( v50 )
{
if ( v50 != 1 )
goto LABEL_28;
if ( (int)slist_length(v4) > 1 )
{
fwrite("\nOnly one text file may be posted.\n", 1uLL, 0x23uLL, stderr);
exit(-12);
}
if ( v50 )
{
LABEL_28:
v5 = 0LL;
LABEL_29:
if ( !v40 && !v41 && (v50 != 1 || v4) )
goto LABEL_14;
goto LABEL_8;
}
}
else if ( !v4 )
{
goto LABEL_47;
}
v5 = v40;
if ( v40 )
{
v5 = 0LL;
goto LABEL_8;
}
if ( v41 )
{
LABEL_8:
if ( !v45 )
v45 = (const char **)buff_create(0LL, "%s", "/tmp");
v6 = (char **)buff_add(v45, "/newspost-XXXXXX");
v7 = *v6;
v45 = (const char **)v6;
v8 = mkstemp(v7);
if ( v8 == -1 || (close(v8), unlink(*v45), mkdir(*v45, 0x1C0u) == -1) )
{
v16 = _errno_location();
ui_tmpdir_create_failed(*v45, (unsigned int)*v16);
exit(-4);
}
v29.sa_handler = (__sighandler_t)signal_handler;
sigemptyset(&v29.sa_mask);
v29.sa_flags = 0;
sigaction(1, &v29, 0LL);
sigaction(2, &v29, 0LL);
sigaction(15, &v29, 0LL);
tmpdir_ptr = v45;
if ( v50 == 1 && !v4 )
{
v20 = file_entry_alloc(v5);
v21 = (const char **)buff_create(*(_QWORD *)(v20 + 144), "%s/message", *v45);
v22 = (const char *)EDITOR;
*(_QWORD *)(v20 + 144) = v21;
if ( !v22 )
v22 = "vi";
v9 = (const char **)buff_create(0LL, "%s %s", v22, *v21);
system(*v9);
v23 = fopen(**(const char ***)(v20 + 144), "rb");
if ( !v23 )
{
buff_free(*(_QWORD *)(v20 + 144));
free((void *)v20);
if ( rmdir(*v45) == -1 )
{
v27 = (const char **)buff_create(v9, "rm -rf %s", *v45);
system(*v27);
}
v24 = _errno_location();
v25 = strerror(*v24);
fprintf(stderr, "\nCannot open message: %s\nNothing to post!\n", v25);
exit(-3);
}
fclose(v23);
chmod(**(const char ***)(v20 + 144), 0x180u);
stat(**(const char ***)(v20 + 144), (struct stat *)v20);
*(_QWORD *)(v20 + 160) = 0LL;
v4 = slist_prepend(0LL, v20);
v11 = newspost(&v30, v4);
if ( v4 )
{
v26 = *(_QWORD *)v4;
unlink(**(const char ***)(*(_QWORD *)v4 + 144LL));
file_entry_free(v26);
}
v10 = 1;
LABEL_19:
slist_free(v4);
for ( i = v51; i; i = (_QWORD *)slist_next(i) )
buff_free(*i);
if ( (v40 || v41 || v10) && rmdir(*v45) == -1 )
{
v9 = (const char **)buff_create(v9, "rm -rf %s", *v45);
system(*v9);
}
buff_free(v9);
buff_free(v30);
buff_free(v31);
buff_free(v32);
buff_free(v33);
buff_free(v34);
buff_free(v36);
buff_free(v37);
buff_free(v40);
buff_free(v41);
buff_free(v43);
buff_free(v45);
buff_free(v47);
buff_free(v48);
buff_free(v49);
v15 = (__int64)v51;
if ( v51 )
slist_free(v51);
switch ( v11 )
{
case -5:
fwrite("\nPosting is not allowed\n", 1uLL, 0x18uLL, stderr);
exit(-8);
case -4:
fwrite("\nFailed to logon to the server\n", 1uLL, 0x1FuLL, stderr);
exit(-7);
case -3:
fwrite("\nFailed to connect to the server\n", 1uLL, 0x21uLL, stderr);
exit(-6);
case -2:
fwrite("\nFailed to resolve the server name\n", 1uLL, 0x23uLL, stderr);
exit(-5);
case -1:
fwrite("\nFailed to create temporary directory\n", 1uLL, 0x26uLL, stderr);
exit(-4);
case 0:
if ( v50 == 1 )
puts("\nFile posted as text.");
else
ui_post_done(v15);
exit(0);
default:
fwrite("\nInternal error. Please contact the author.\n", 1uLL, 0x2DuLL, stderr);
exit(-10);
}
}
LABEL_14:
v9 = 0LL;
v10 = 0;
v11 = newspost(&v30, v4);
if ( v4 )
{
v12 = *(const char **)v4;
v9 = (const char **)v4;
while ( 1 )
{
file_entry_free(v12);
v13 = (const char **)slist_next(v9);
v9 = v13;
if ( !v13 )
break;
v12 = *v13;
}
v10 = 0;
}
goto LABEL_19;
}
for ( j = v4; j; j = ((__int64 (*)(void))slist_next)() )
{
v5 = *(_QWORD *)j;
v19 = *(_BYTE **)(*(_QWORD *)j + 160LL);
if ( !v19 || !*v19 )
goto LABEL_29;
}
LABEL_47:
fwrite("\nNo files to post!\n", 1uLL, 0x13uLL, stderr);
exit(-3);
}

original_code:
int main(int argc, char ** argv){
 boolean error = 0;
 if(sizeof(n_uint8) != 1){
  error = 1;
  fprintf(stderr, "\nYour unsigned chars are not 1 byte.");
 }
 if(sizeof(n_uint16) != 2){
  error = 1;
  fprintf(stderr, "\nYour unsigned short ints are not 2 bytes.");
 }
 if(sizeof(n_uint32) != 4){
  error = 1;
  fprintf(stderr, "\nYour unsigned ints are not 4 bytes.");
 }
 if(sizeof(n_int64) != 8){
  error = 1;
  fprintf(stderr, "\nYour long longs are not 8 bytes.");
 }
 if(error == 1){
  fprintf(stderr, "\nPlease edit base/newspost.h");
                fprintf(stderr, "\nThen run \"make clean\" and \"make\" again");
                fprintf(stderr, "\n\n");
  return -1;
 }
 else{
  return 0;
 }
}

canonical_original_code:
int main(int argc, char **argv){
 unsigned char error = 0;
 if(sizeof(n_uint8) != 1){
  error = 1;
  fprintf(stderr, "\nYour unsigned chars are not 1 byte.");
 }
 if(sizeof(n_uint16) != 2){
  error = 1;
  fprintf(stderr, "\nYour unsigned short ints are not 2 bytes.");
 }
 if(sizeof(n_uint32) != 4){
  error = 1;
  fprintf(stderr, "\nYour unsigned ints are not 4 bytes.");
 }
 if(sizeof(n_int64) != 8){
  error = 1;
  fprintf(stderr, "\nYour long longs are not 8 bytes.");
 }
 if(error == 1){
  fprintf(stderr, "\nPlease edit base/newspost.h");
                fprintf(stderr, "\nThen run \"make clean\" and \"make\" again");
                fprintf(stderr, "\n\n");
  return -1;
 }
 else{
  return 0;
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
error
unsigned char


decompiled_code:
__int64 __fastcall nntp_issue_command(__int64 a1, const char *a2)
{
unsigned int v2; // er13
size_t v3; // rax
int v4; // er14

v2 = *(_DWORD *)(a1 + 4);
v3 = strlen(a2);
v4 = socket_write(v2, a2, v3);
if ( v4 > 0 )
{
v4 += socket_write(v2, &unk_531, 2LL);
ui_nntp_command_issued(a1, a2);
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
unsigned int v2; // er13
size_t v3; // rax
int v4; // er14

v2 = *(_DWORD *)(a1 + 4);
v3 = strlen(a2);
v4 = socket_write(v2, a2, v3);
if ( v4 > 0 )
{
v4 += socket_write(v2, &unk_531, 2LL);
ui_nntp_command_issued(a1, a2);
}
return (unsigned int)v4;
}

original_code:
int nntp_issue_command(newspost_threadinfo *tinfo, const char *command) {
 int bytes_written;
 int sockfd = tinfo->sockfd;
 bytes_written = socket_write(sockfd, command, strlen(command));
 if (bytes_written > 0) {
  bytes_written += socket_write(sockfd, "\r\n", 2);
  ui_nntp_command_issued(tinfo, command);
 }
 return bytes_written;
}

canonical_original_code:
int nntp_issue_command(struct newspost_threadinfo *tinfo, char *command) {
 int bytes_written;
 int sockfd = tinfo->sockfd;
 bytes_written = socket_write(sockfd, command, strlen(command));
 if (bytes_written > 0) {
  bytes_written += socket_write(sockfd, "\r\n", 2);
  ui_nntp_command_issued(tinfo, command);
 }
 return bytes_written;
}

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

variable_types:
command
char *

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


decompiled_code:
__int64 __fastcall nntp_get_response(__int64 a1, __int64 a2)
{
int v2; // ebx

v2 = socket_getline(*(unsigned int *)(a1 + 4));
if ( v2 > 0 )
ui_nntp_server_response(a1, a2);
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
int v2; // ebx

v2 = socket_getline(*(unsigned int *)(a1 + 4));
if ( v2 > 0 )
ui_nntp_server_response(a1, a2);
return (unsigned int)v2;
}

original_code:
int nntp_get_response(newspost_threadinfo *tinfo, char *response) {
 int bytes_read;
 bytes_read = socket_getline(tinfo->sockfd, response);
 if (bytes_read > 0)
  ui_nntp_server_response(tinfo, response);
 return bytes_read;
}

canonical_original_code:
int nntp_get_response(struct newspost_threadinfo *tinfo, char *response) {
 int bytes_read;
 bytes_read = socket_getline(tinfo->sockfd, response);
 if (bytes_read > 0)
  ui_nntp_server_response(tinfo, response);
 return bytes_read;
}

variable_types:
response
char *


decompiled_code:
__int64 __fastcall nntp_logon(__int64 a1, __int64 a2)
{
const char **v2; // rax
__int16 v4; // [rsp+0h] [rbp-418h] BYREF
char v5; // [rsp+2h] [rbp-416h]

if ( (int)nntp_get_response(a1, (__int64)&v4) < 0 )
return 0LL;
v2 = *(const char ***)(a2 + 48);
if ( !v2 )
return 1LL;
sprintf((char *)&v4, "AUTHINFO USER %s", *v2);
if ( (int)nntp_issue_command(a1, (const char *)&v4) < 0 || (int)nntp_get_response(a1, (__int64)&v4) < 0 )
return 0LL;
if ( v4 != 14387 || v5 != 49 )
{
if ( (v4 != 14386 || v5 != 49) && (v4 != 12341 || v5 != 48) )
ui_nntp_unknown_response(a1, &v4);
return 1LL;
}
sprintf((char *)&v4, "AUTHINFO PASS %s", **(const char ***)(a2 + 56));
if ( (int)nntp_issue_command(a1, (const char *)&v4) < 0 || (int)nntp_get_response(a1, (__int64)&v4) < 0 )
return 0LL;
if ( v4 != 12341 || v5 != 50 )
return 1LL;
ui_nntp_authentication_failed(a1, &v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
const char **v2; // rax
__int16 v4; // [rsp+0h] [rbp-418h] BYREF
char v5; // [rsp+2h] [rbp-416h]

if ( (int)func1(a1, (__int64)&v4) < 0 )
return 0LL;
v2 = *(const char ***)(a2 + 48);
if ( !v2 )
return 1LL;
sprintf((char *)&v4, "AUTHINFO USER %s", *v2);
if ( (int)func0(a1, (const char *)&v4) < 0 || (int)func1(a1, (__int64)&v4) < 0 )
return 0LL;
if ( v4 != 14387 || v5 != 49 )
{
if ( (v4 != 14386 || v5 != 49) && (v4 != 12341 || v5 != 48) )
ui_nntp_unknown_response(a1, &v4);
return 1LL;
}
sprintf((char *)&v4, "AUTHINFO PASS %s", **(const char ***)(a2 + 56));
if ( (int)func0(a1, (const char *)&v4) < 0 || (int)func1(a1, (__int64)&v4) < 0 )
return 0LL;
if ( v4 != 12341 || v5 != 50 )
return 1LL;
ui_nntp_authentication_failed(a1, &v4);
return 0LL;
}

original_code:
boolean nntp_logon(newspost_threadinfo *tinfo, newspost_data *data) {
 char buffer[1024];
 if (nntp_get_response(tinfo, buffer) < 0)
  return 0;
 if (data->user != ((void *)0)) {
  sprintf(buffer, "AUTHINFO USER %s", data->user->data);
  if (nntp_issue_command(tinfo, buffer) < 0)
   return 0;
  if (nntp_get_response(tinfo, buffer) < 0)
   return 0;
  if (strncmp(buffer,
      "381", 3) == 0) {
   sprintf(buffer, "AUTHINFO PASS %s", data->password->data);
   if (nntp_issue_command(tinfo, buffer) < 0)
    return 0;
   if (nntp_get_response(tinfo, buffer) < 0)
    return 0;
   if (strncmp(buffer,
       "502", 3) == 0) {
    ui_nntp_authentication_failed(tinfo, buffer);
    return 0;
   }
  }
  else if (strncmp(buffer,
    "281", 3) == 0) {
   return 1;
  }
  else if (strncmp(buffer, "500", 3) == 0) {
  }
  else
   ui_nntp_unknown_response(tinfo, buffer);
 }
 return 1;
}

canonical_original_code:
unsigned char nntp_logon(struct newspost_threadinfo *tinfo, struct newspost_data *data) {
 char buffer[1024];
 if (nntp_get_response(tinfo, buffer) < 0)
  return 0;
 if (data->user != ((void *)0)) {
  sprintf(buffer, "AUTHINFO USER %s", data->user->data);
  if (nntp_issue_command(tinfo, buffer) < 0)
   return 0;
  if (nntp_get_response(tinfo, buffer) < 0)
   return 0;
  if (strncmp(buffer,
      "381", 3) == 0) {
   sprintf(buffer, "AUTHINFO PASS %s", data->password->data);
   if (nntp_issue_command(tinfo, buffer) < 0)
    return 0;
   if (nntp_get_response(tinfo, buffer) < 0)
    return 0;
   if (strncmp(buffer,
       "502", 3) == 0) {
    ui_nntp_authentication_failed(tinfo, buffer);
    return 0;
   }
  }
  else if (strncmp(buffer,
    "281", 3) == 0) {
   return 1;
  }
  else if (strncmp(buffer, "500", 3) == 0) {
  }
  else
   ui_nntp_unknown_response(tinfo, buffer);
 }
 return 1;
}

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:
buffer
char [1024]

return_type: unsigned char

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 nntp_logoff(__int64 a1)
{
__int64 v2; // [rsp+0h] [rbp-408h] BYREF

nntp_issue_command(a1, "QUIT");
return nntp_get_response(a1, (__int64)&v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v2; // [rsp+0h] [rbp-408h] BYREF

func0(a1, "QUIT");
return func1(a1, (__int64)&v2);
}

original_code:
void nntp_logoff(newspost_threadinfo *tinfo) {
 char tmpbuffer[1024];
 nntp_issue_command(tinfo, "QUIT");
 nntp_get_response(tinfo, tmpbuffer);
}

canonical_original_code:
void nntp_logoff(struct newspost_threadinfo *tinfo) {
 char tmpbuffer[1024];
 nntp_issue_command(tinfo, "QUIT");
 nntp_get_response(tinfo, tmpbuffer);
}

variable_types:
tmpbuffer
char [1024]


decompiled_code:
__int64 __fastcall nntp_post(__int64 a1, const char *a2, __int64 a3, __int64 a4, __int64 a5, char a6)
{
unsigned int v9; // er14
unsigned int v10; // er12
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // r15
const char **v16; // rax
const char **v17; // rax
const char **v18; // rax
const char **v19; // rax
const char ***i; // rbx
__int64 v21; // r15
__int64 v22; // rbx
__int64 v23; // rdx
char v25; // [rsp+4h] [rbp-444h]
_QWORD *v26; // [rsp+8h] [rbp-440h]
__int16 v27; // [rsp+10h] [rbp-438h] BYREF
char v28; // [rsp+12h] [rbp-436h]

v9 = *(_DWORD *)(a1 + 4);
v25 = a6;
nntp_issue_command(a1, "POST");
nntp_get_response(a1, (__int64)&v27);
if ( v27 == 13364 && v28 == 48 )
return (unsigned int)-5;
if ( v27 == 13363 && v28 == 48 )
{
v12 = buff_add(0LL, "From: %s\r\n", **(const char ***)(a3 + 16));
v13 = buff_add(v12, "Newsgroups: %s\r\n", **(const char ***)(a3 + 8));
v14 = buff_add(v13, "Subject: %s\r\n", a2);
v15 = buff_add(v14, "User-Agent: %s\r\n", "Newspost/2.2.1 (http://github.com/PietjeBell88/newspost)");
v16 = *(const char ***)(a3 + 144);
if ( v16 )
v15 = buff_add(v15, "Reply-To: %s\r\n", *v16);
v17 = *(const char ***)(a3 + 136);
if ( v17 )
v15 = buff_add(v15, "Followup-To: %s\r\n", *v17);
v18 = *(const char ***)(a3 + 24);
if ( v18 )
v15 = buff_add(v15, "Organization: %s\r\n", *v18);
v19 = *(const char ***)(a3 + 104);
if ( v19 )
v15 = buff_add(v15, "References: %s\r\n", *v19);
if ( *(_BYTE *)(a3 + 128) == 1 )
v15 = buff_add(v15, "X-No-Archive: yes\r\n");
for ( i = *(const char ****)(a3 + 168); i; i = (const char ***)slist_next(i) )
v15 = buff_add(v15, "%s\r\n", **i);
v26 = (_QWORD *)buff_add(v15, "\r\n");
socket_write(v9, *v26, v26[1]);
if ( v25 )
{
if ( a5 > 0x8000 )
goto LABEL_22;
}
else
{
ui_chunk_posted(a1, 0LL, 0LL);
if ( a5 > 0x8000 )
{
LABEL_22:
v21 = 0x8000LL;
v22 = 0LL;
do
{
while ( 1 )
{
v22 += v21;
socket_write(v9, a4, v21);
a4 += v21;
pthread_rwlock_wrlock(*(pthread_rwlock_t **)(a1 + 8));
*(_QWORD *)(a1 + 24) += v21;
pthread_rwlock_unlock(*(pthread_rwlock_t **)(a1 + 8));
if ( !a6 )
break;
v23 = a5 - v22;
if ( v21 >= a5 - v22 )
goto LABEL_26;
}
v21 = (int)ui_chunk_posted(a1, v21, v22);
v23 = a5 - v22;
}
while ( v21 < a5 - v22 );
LABEL_26:
socket_write(v9, a4, v23);
socket_write(v9, "\r\n.\r\n", 5LL);
nntp_get_response(a1, (__int64)&v27);
pthread_rwlock_wrlock(*(pthread_rwlock_t **)(a1 + 8));
pthread_rwlock_unlock(*(pthread_rwlock_t **)(a1 + 8));
if ( !v25 )
ui_chunk_posted(a1, 0LL, a5);
if ( v27 == 13364 && v28 == 49 )
{
v10 = -6;
ui_nntp_posting_failed(a1, &v27);
return v10;
}
if ( v27 == 13362 && v28 == 48 )
{
v10 = 0;
buff_free(v26);
return v10;
}
goto LABEL_3;
}
}
v23 = a5;
goto LABEL_26;
}
LABEL_3:
v10 = -6;
ui_nntp_unknown_response(a1, &v27);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, __int64 a3, __int64 a4, __int64 a5, char a6)
{
unsigned int v9; // er14
unsigned int v10; // er12
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // r15
const char **v16; // rax
const char **v17; // rax
const char **v18; // rax
const char **v19; // rax
const char ***i; // rbx
__int64 v21; // r15
__int64 v22; // rbx
__int64 v23; // rdx
char v25; // [rsp+4h] [rbp-444h]
_QWORD *v26; // [rsp+8h] [rbp-440h]
__int16 v27; // [rsp+10h] [rbp-438h] BYREF
char v28; // [rsp+12h] [rbp-436h]

v9 = *(_DWORD *)(a1 + 4);
v25 = a6;
func0(a1, "POST");
func1(a1, (__int64)&v27);
if ( v27 == 13364 && v28 == 48 )
return (unsigned int)-5;
if ( v27 == 13363 && v28 == 48 )
{
v12 = buff_add(0LL, "From: %s\r\n", **(const char ***)(a3 + 16));
v13 = buff_add(v12, "Newsgroups: %s\r\n", **(const char ***)(a3 + 8));
v14 = buff_add(v13, "Subject: %s\r\n", a2);
v15 = buff_add(v14, "User-Agent: %s\r\n", "Newspost/2.2.1 (http://github.com/PietjeBell88/newspost)");
v16 = *(const char ***)(a3 + 144);
if ( v16 )
v15 = buff_add(v15, "Reply-To: %s\r\n", *v16);
v17 = *(const char ***)(a3 + 136);
if ( v17 )
v15 = buff_add(v15, "Followup-To: %s\r\n", *v17);
v18 = *(const char ***)(a3 + 24);
if ( v18 )
v15 = buff_add(v15, "Organization: %s\r\n", *v18);
v19 = *(const char ***)(a3 + 104);
if ( v19 )
v15 = buff_add(v15, "References: %s\r\n", *v19);
if ( *(_BYTE *)(a3 + 128) == 1 )
v15 = buff_add(v15, "X-No-Archive: yes\r\n");
for ( i = *(const char ****)(a3 + 168); i; i = (const char ***)slist_next(i) )
v15 = buff_add(v15, "%s\r\n", **i);
v26 = (_QWORD *)buff_add(v15, "\r\n");
socket_write(v9, *v26, v26[1]);
if ( v25 )
{
if ( a5 > 0x8000 )
goto LABEL_22;
}
else
{
ui_chunk_posted(a1, 0LL, 0LL);
if ( a5 > 0x8000 )
{
LABEL_22:
v21 = 0x8000LL;
v22 = 0LL;
do
{
while ( 1 )
{
v22 += v21;
socket_write(v9, a4, v21);
a4 += v21;
pthread_rwlock_wrlock(*(pthread_rwlock_t **)(a1 + 8));
*(_QWORD *)(a1 + 24) += v21;
pthread_rwlock_unlock(*(pthread_rwlock_t **)(a1 + 8));
if ( !a6 )
break;
v23 = a5 - v22;
if ( v21 >= a5 - v22 )
goto LABEL_26;
}
v21 = (int)ui_chunk_posted(a1, v21, v22);
v23 = a5 - v22;
}
while ( v21 < a5 - v22 );
LABEL_26:
socket_write(v9, a4, v23);
socket_write(v9, "\r\n.\r\n", 5LL);
func1(a1, (__int64)&v27);
pthread_rwlock_wrlock(*(pthread_rwlock_t **)(a1 + 8));
pthread_rwlock_unlock(*(pthread_rwlock_t **)(a1 + 8));
if ( !v25 )
ui_chunk_posted(a1, 0LL, a5);
if ( v27 == 13364 && v28 == 49 )
{
v10 = -6;
ui_nntp_posting_failed(a1, &v27);
return v10;
}
if ( v27 == 13362 && v28 == 48 )
{
v10 = 0;
buff_free(v26);
return v10;
}
goto LABEL_3;
}
}
v23 = a5;
goto LABEL_26;
}
LABEL_3:
v10 = -6;
ui_nntp_unknown_response(a1, &v27);
return v10;
}

original_code:
int nntp_post(newspost_threadinfo *tinfo, const char *subject, newspost_data *data,
       const char *buffer, long length,
       boolean no_ui_updates) {
 char response[1024];
 const char *pi;
 long i, chunksize;
 SList * listptr;
 Buff * buff = ((void *)0);
 Buff * tmpbuff = ((void *)0);
 int sockfd = tinfo->sockfd;
 nntp_issue_command(tinfo, "POST");
 nntp_get_response(tinfo, response);
 if (strncmp(response, "440", 3) == 0)
  return -5;
 if (strncmp(response, "340", 3) != 0) {
  ui_nntp_unknown_response(tinfo, response);
  return -6;
 }
 buff = buff_add(buff, "From: %s\r\n", data->from->data);
 buff = buff_add(buff, "Newsgroups: %s\r\n", data->newsgroup->data);
 buff = buff_add(buff, "Subject: %s\r\n", subject);
 buff = buff_add(buff, "User-Agent: %s\r\n", "Newspost" "/" "2.2.1" " (" "http://github.com/PietjeBell88/newspost" ")");
 if (data->replyto != ((void *)0)) {
  buff = buff_add(buff, "Reply-To: %s\r\n", data->replyto->data);
 }
 if (data->followupto != ((void *)0)) {
  buff = buff_add(buff, "Followup-To: %s\r\n", data->followupto->data);
 }
 if (data->organization != ((void *)0)) {
  buff = buff_add(buff,"Organization: %s\r\n",data->organization->data);
 }
 if (data->reference != ((void *)0)) {
  buff = buff_add(buff, "References: %s\r\n", data->reference->data);
 }
 if (data->noarchive == 1)
  buff = buff_add(buff, "X-No-Archive: yes\r\n");
 listptr = data->extra_headers;
 while (listptr != ((void *)0)) {
  tmpbuff = (Buff *) listptr->data;
  buff = buff_add(buff, "%s\r\n", tmpbuff->data);
  listptr = slist_next(listptr);
 }
 buff = buff_add(buff,"\r\n");
 socket_write(sockfd, buff->data, buff->length);
 if (!no_ui_updates)
  ui_chunk_posted(tinfo, 0, 0);
 pi = buffer;
 i = 0;
 chunksize = 32768;
 while ((length - i) > chunksize) {
  socket_write(sockfd, pi, chunksize);
  i += chunksize;
  pi += chunksize;
  pthread_rwlock_wrlock(tinfo->rwlock);
  tinfo->bytes_written += chunksize;
  pthread_rwlock_unlock(tinfo->rwlock);
  if (!no_ui_updates)
   chunksize = ui_chunk_posted(tinfo, chunksize, i);
 }
 socket_write(sockfd, pi, (length - i));
 i += (length - i);
 socket_write(sockfd, "\r\n.\r\n", 5);
 nntp_get_response(tinfo, response);
 pthread_rwlock_wrlock(tinfo->rwlock);
 tinfo->bytes_written += (length - i);
 pthread_rwlock_unlock(tinfo->rwlock);
 if (!no_ui_updates)
  ui_chunk_posted(tinfo, (length - i), i);
 if (strncmp(response, "441", 3) == 0) {
  ui_nntp_posting_failed(tinfo, response);
  return -6;
 }
 else if (strncmp(response, "240", 3) != 0) {
  ui_nntp_unknown_response(tinfo, response);
  return -6;
 }
 buff_free(buff);
 return 0;
}

canonical_original_code:
int nntp_post(struct newspost_threadinfo *tinfo, char *subject, struct newspost_data *data, char *buffer, long length, unsigned char no_ui_updates) {
 char response[1024];
 char *pi;
 long i; long chunksize;
 struct Newspost_SList *listptr;
 struct Buff *buff = ((void *)0);
 struct Buff *tmpbuff = ((void *)0);
 int sockfd = tinfo->sockfd;
 nntp_issue_command(tinfo, "POST");
 nntp_get_response(tinfo, response);
 if (strncmp(response, "440", 3) == 0)
  return -5;
 if (strncmp(response, "340", 3) != 0) {
  ui_nntp_unknown_response(tinfo, response);
  return -6;
 }
 buff = buff_add(buff, "From: %s\r\n", data->from->data);
 buff = buff_add(buff, "Newsgroups: %s\r\n", data->newsgroup->data);
 buff = buff_add(buff, "Subject: %s\r\n", subject);
 buff = buff_add(buff, "User-Agent: %s\r\n", "Newspost" "/" "2.2.1" " (" "http://github.com/PietjeBell88/newspost" ")");
 if (data->replyto != ((void *)0)) {
  buff = buff_add(buff, "Reply-To: %s\r\n", data->replyto->data);
 }
 if (data->followupto != ((void *)0)) {
  buff = buff_add(buff, "Followup-To: %s\r\n", data->followupto->data);
 }
 if (data->organization != ((void *)0)) {
  buff = buff_add(buff,"Organization: %s\r\n",data->organization->data);
 }
 if (data->reference != ((void *)0)) {
  buff = buff_add(buff, "References: %s\r\n", data->reference->data);
 }
 if (data->noarchive == 1)
  buff = buff_add(buff, "X-No-Archive: yes\r\n");
 listptr = data->extra_headers;
 while (listptr != ((void *)0)) {
  tmpbuff = (struct Buff *) listptr->data;
  buff = buff_add(buff, "%s\r\n", tmpbuff->data);
  listptr = slist_next(listptr);
 }
 buff = buff_add(buff,"\r\n");
 socket_write(sockfd, buff->data, buff->length);
 if (!no_ui_updates)
  ui_chunk_posted(tinfo, 0, 0);
 pi = buffer;
 i = 0;
 chunksize = 32768;
 while ((length - i) > chunksize) {
  socket_write(sockfd, pi, chunksize);
  i += chunksize;
  pi += chunksize;
  pthread_rwlock_wrlock(tinfo->rwlock);
  tinfo->bytes_written += chunksize;
  pthread_rwlock_unlock(tinfo->rwlock);
  if (!no_ui_updates)
   chunksize = ui_chunk_posted(tinfo, chunksize, i);
 }
 socket_write(sockfd, pi, (length - i));
 i += (length - i);
 socket_write(sockfd, "\r\n.\r\n", 5);
 nntp_get_response(tinfo, response);
 pthread_rwlock_wrlock(tinfo->rwlock);
 tinfo->bytes_written += (length - i);
 pthread_rwlock_unlock(tinfo->rwlock);
 if (!no_ui_updates)
  ui_chunk_posted(tinfo, (length - i), i);
 if (strncmp(response, "441", 3) == 0) {
  ui_nntp_posting_failed(tinfo, response);
  return -6;
 }
 else if (strncmp(response, "240", 3) != 0) {
  ui_nntp_unknown_response(tinfo, response);
  return -6;
 }
 buff_free(buff);
 return 0;
}

variable_types:
subject
char *

variable_types:
buffer
char *

variable_types: length long

variable_types:
response
char [1024]

variable_types:
pi
char *

variable_types: i long

variable_types: chunksize long

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

variable_types: sockfd int


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

result = malloc(0xC0uLL);
result[20] = 0LL;
result[18] = 0LL;
result[22] = 0LL;
*((_DWORD *)result + 47) = 0;
*((_BYTE *)result + 184) = 0;
return result;
}

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

result = malloc(0xC0uLL);
result[20] = 0LL;
result[18] = 0LL;
result[22] = 0LL;
*((_DWORD *)result + 47) = 0;
*((_BYTE *)result + 184) = 0;
return result;
}

original_code:
file_entry * file_entry_alloc(){
 file_entry * fe = malloc(sizeof(file_entry));
 fe->parts = ((void *)0);
 fe->filename = ((void *)0);
 fe->rwlock = ((void *)0);
 fe->parts_posted = 0;
 fe->post_started = 0;
 return fe;
}

canonical_original_code:
struct file_entry *file_entry_alloc(){
 struct file_entry *fe = malloc(sizeof(file_entry));
 fe->parts = ((void *)0);
 fe->filename = ((void *)0);
 fe->rwlock = ((void *)0);
 fe->parts_posted = 0;
 fe->post_started = 0;
 return fe;
}

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


original_code:
Buff *buff_add(Buff *buff, char *data, ... ){
 va_list ap;
 long datalength;
 __builtin_va_start(ap,data);
 datalength = buff_data_length(data, ap);
 __builtin_va_end(ap);
 __builtin_va_start(ap,data);
 if(buff == ((void *)0)){
  if(datalength == 0) return ((void *)0);
  buff = malloc(sizeof(Buff));
  buff->length = datalength;
  for(buff->real_length = 2 ;
      buff->real_length <= datalength;
      buff->real_length = buff->real_length * 2){}
  buff->data = malloc(buff->real_length);
  vsprintf(buff->data,data,ap);
 }
 else{
  int oldlength = buff->length;
  buff->length += datalength;
  if(buff->length >= buff->real_length){
   for(;
       buff->real_length <= buff->length;
       buff->real_length = buff->real_length * 2){}
   buff->data = realloc(buff->data, buff->real_length);
  }
  vsprintf((buff->data + oldlength), data, ap);
 }
 __builtin_va_end(ap);
 buff->data[buff->length] = '\0';
 return buff;
}

canonical_original_code:
struct Buff *buff_add(struct Buff *buff, char *data, ...){
 __builtin_va_list ap;
 long datalength;
 __builtin_va_start(ap,data);
 datalength = buff_data_length(data, ap);
 __builtin_va_end(ap);
 __builtin_va_start(ap,data);
 if(buff == ((void *)0)){
  if(datalength == 0) return ((void *)0);
  buff = malloc(sizeof(Buff));
  buff->length = datalength;
  for(buff->real_length = 2 ;
      buff->real_length <= datalength;
      buff->real_length = buff->real_length * 2){}
  buff->data = malloc(buff->real_length);
  vsprintf(buff->data,data,ap);
 }
 else{
  int oldlength = buff->length;
  buff->length += datalength;
  if(buff->length >= buff->real_length){
   for(;
       buff->real_length <= buff->length;
       buff->real_length = buff->real_length * 2){}
   buff->data = realloc(buff->data, buff->real_length);
  }
  vsprintf((buff->data + oldlength), data, ap);
 }
 __builtin_va_end(ap);
 buff->data[buff->length] = '\0';
 return buff;
}

variable_types:
buff
struct Buff *

variable_types:
data
char *

variable_types: datalength long

variable_types: oldlength int

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


decompiled_code:
__int64 __fastcall buff_free(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(ptr);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(ptr);
}
return 0LL;
}

original_code:
Buff * buff_free(Buff *buff){
 if(buff != ((void *)0)){
  free(buff->data);
  free(buff);
 }
 return ((void *)0);
}

canonical_original_code:
struct Buff *buff_free(struct Buff *buff){
 if(buff != ((void *)0)){
  free(buff->data);
  free(buff);
 }
 return ((void *)0);
}


decompiled_code:
__int64 __fastcall file_entry_free(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
pthread_rwlock_t *v4; // rdi

if ( !ptr )
return 0LL;
v2 = (void *)*((_QWORD *)ptr + 20);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 18);
if ( v3 )
buff_free(v3);
v4 = (pthread_rwlock_t *)*((_QWORD *)ptr + 22);
if ( v4 )
{
pthread_rwlock_destroy(v4);
free(*((void **)ptr + 22));
}
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
pthread_rwlock_t *v4; // rdi

if ( !ptr )
return 0LL;
v2 = (void *)*((_QWORD *)ptr + 20);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 18);
if ( v3 )
func3(v3);
v4 = (pthread_rwlock_t *)*((_QWORD *)ptr + 22);
if ( v4 )
{
pthread_rwlock_destroy(v4);
free(*((void **)ptr + 22));
}
free(ptr);
return 0LL;
}

original_code:
file_entry * file_entry_free(file_entry *fe){
 if(fe != ((void *)0)){
  if(fe->parts != ((void *)0))
   free(fe->parts);
  if(fe->filename != ((void *)0))
   buff_free(fe->filename);
  if(fe->rwlock != ((void *)0)) {
   pthread_rwlock_destroy(fe->rwlock);
   free(fe->rwlock);
  }
  free(fe);
 }
 return ((void *)0);
}

canonical_original_code:
struct file_entry *file_entry_free(struct file_entry *fe){
 if(fe != ((void *)0)){
  if(fe->parts != ((void *)0))
   free(fe->parts);
  if(fe->filename != ((void *)0))
   buff_free(fe->filename);
  if(fe->rwlock != ((void *)0)) {
   pthread_rwlock_destroy(fe->rwlock);
   free(fe->rwlock);
  }
  free(fe);
 }
 return ((void *)0);
}

variable_types:
fe
struct file_entry *

return_type: 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; } *


decompiled_code:
char **buff_create(void *ptr, char *format, ...)
{
__int64 v2; // rbx
char **v3; // r12
char **v4; // rax
signed __int64 v5; // rdi
char *v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
v2 = buff_data_length(format, (int *)arg);
if ( ptr )
buff_free(ptr);
v3 = 0LL;
if ( v2 )
{
v4 = (char **)malloc(0x18uLL);
v5 = 2LL;
v4[1] = (char *)v2;
v3 = v4;
v4[2] = (_BYTE *)&loc_2;
if ( v2 > 1 )
{
do
v5 *= 2LL;
while ( v5 <= v2 );
v4[2] = (char *)v5;
}
v6 = (char *)malloc(v5);
*v3 = v6;
va_end(arg);
va_start(arg, format);
vsprintf(v6, format, arg);
v3[1][(_QWORD)*v3] = 0;
}
return v3;
}

canonical_decompiled_code:
char **func6(void *ptr, char *format, ...)
{
__int64 v2; // rbx
char **v3; // r12
char **v4; // rax
signed __int64 v5; // rdi
char *v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
v2 = func0(format, (int *)arg);
if ( ptr )
func3(ptr);
v3 = 0LL;
if ( v2 )
{
v4 = (char **)malloc(0x18uLL);
v5 = 2LL;
v4[1] = (char *)v2;
v3 = v4;
v4[2] = (_BYTE *)&loc_2;
if ( v2 > 1 )
{
do
v5 *= 2LL;
while ( v5 <= v2 );
v4[2] = (char *)v5;
}
v6 = (char *)malloc(v5);
*v3 = v6;
va_end(arg);
va_start(arg, format);
vsprintf(v6, format, arg);
v3[1][(_QWORD)*v3] = 0;
}
return v3;
}

original_code:
Buff *buff_create(Buff *buff, char *data, ... ){
 va_list ap;
 long datalength;
 __builtin_va_start(ap,data);
 datalength = buff_data_length(data, ap);
 __builtin_va_end(ap);
 if(buff != ((void *)0))
  buff = buff_free(buff);
 if(datalength == 0) return ((void *)0);
 buff = malloc(sizeof(Buff));
 buff->length = datalength;
 for(buff->real_length = 2 ;
     buff->real_length <= datalength;
     buff->real_length = buff->real_length * 2){}
 buff->data = malloc(buff->real_length);
 __builtin_va_start(ap,data);
 vsprintf(buff->data,data,ap);
 __builtin_va_end(ap);
 buff->data[buff->length] = '\0';
 return buff;
}

canonical_original_code:
struct Buff *buff_create(struct Buff *buff, char *data, ...){
 __builtin_va_list ap;
 long datalength;
 __builtin_va_start(ap,data);
 datalength = buff_data_length(data, ap);
 __builtin_va_end(ap);
 if(buff != ((void *)0))
  buff = buff_free(buff);
 if(datalength == 0) return ((void *)0);
 buff = malloc(sizeof(Buff));
 buff->length = datalength;
 for(buff->real_length = 2 ;
     buff->real_length <= datalength;
     buff->real_length = buff->real_length * 2){}
 buff->data = malloc(buff->real_length);
 __builtin_va_start(ap,data);
 vsprintf(buff->data,data,ap);
 __builtin_va_end(ap);
 buff->data[buff->length] = '\0';
 return buff;
}


decompiled_code:
__int64 __fastcall slist_next(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
SList *slist_next(SList *slist) {
 return slist->next;
}

canonical_original_code:
struct Newspost_SList *slist_next(struct Newspost_SList *slist) {
 return slist->next;
}

variable_types:
slist
struct Newspost_SList *

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


decompiled_code:
void __fastcall slist_free(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 1);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 1);
free(v2);
}
while ( v1 );
}
}

original_code:
void slist_free(SList *slist) {
 SList *si;
 while (slist != ((void *)0)) {
  si = slist;
  slist = slist->next;
  free(si);
 }
}

canonical_original_code:
void slist_free(struct Newspost_SList *slist) {
 struct Newspost_SList *si;
 while (slist != ((void *)0)) {
  si = slist;
  slist = slist->next;
  free(si);
 }
}

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


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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 8);
return result;
}

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 8);
return result;
}

original_code:
int slist_length(SList *slist) {
 int i = 0;
 while (slist != ((void *)0)) {
  i++;
  slist = slist->next;
 }
 return i;
}

canonical_original_code:
int slist_length(struct Newspost_SList *slist) {
 int i = 0;
 while (slist != ((void *)0)) {
  i++;
  slist = slist->next;
 }
 return i;
}

variable_types: i int


preprocess

decompiled_code:
__int64 __fastcall preprocess(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 result; // rax
__int64 v4; // [rsp+8h] [rbp-20h]

if ( *(_QWORD *)(a1 + 152) )
{
v2 = buff_create(0LL, &unk_CBC, **(_QWORD **)(a1 + 16));
*(_QWORD *)(a1 + 16) = buff_create(*(_QWORD *)(a1 + 16), "%s <%s>", **(_QWORD **)(a1 + 152));
buff_free(v2);
}
if ( !*(_BYTE *)(a1 + 72) || *(_QWORD *)(a1 + 80) )
{
calculate_crcs(a2);
if ( *(_QWORD *)(a1 + 80) )
newsfv(a2, a1);
}
result = *(_QWORD *)(a1 + 88);
if ( result )
{
result = par_newspost_interface(a1, a2);
if ( !*(_BYTE *)(a1 + 72) )
{
v4 = result;
calculate_crcs(result);
result = v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 result; // rax
__int64 v4; // [rsp+8h] [rbp-20h]

if ( *(_QWORD *)(a1 + 152) )
{
v2 = buff_create(0LL, &unk_CBC, **(_QWORD **)(a1 + 16));
*(_QWORD *)(a1 + 16) = buff_create(*(_QWORD *)(a1 + 16), "%s <%s>", **(_QWORD **)(a1 + 152));
buff_free(v2);
}
if ( !*(_BYTE *)(a1 + 72) || *(_QWORD *)(a1 + 80) )
{
calculate_crcs(a2);
if ( *(_QWORD *)(a1 + 80) )
newsfv(a2, a1);
}
result = *(_QWORD *)(a1 + 88);
if ( result )
{
result = par_newspost_interface(a1, a2);
if ( !*(_BYTE *)(a1 + 72) )
{
v4 = result;
calculate_crcs(result);
result = v4;
}
}
return result;
}

original_code:
static SList *preprocess(newspost_data *data, SList *file_list) {
 Buff *tmpstring = ((void *)0);
 SList *parfiles = ((void *)0);
 if (data->name != ((void *)0)) {
  tmpstring = buff_create(tmpstring, "%s", data->from->data);
  data->from = buff_create(data->from, "%s <%s>",
      data->name->data, tmpstring->data);
  buff_free(tmpstring);
 }
 if ((data->uuenc == 0) || (data->sfv != ((void *)0))) {
  calculate_crcs(file_list);
  if (data->sfv != ((void *)0))
   newsfv(file_list, data);
 }
 if (data->par != ((void *)0)) {
  parfiles = par_newspost_interface(data, file_list);
  if (data->uuenc == 0)
   calculate_crcs(parfiles);
 }
 return parfiles;
}

canonical_original_code:
static struct Newspost_SList *preprocess(struct newspost_data *data, struct Newspost_SList *file_list) {
 struct Buff *tmpstring = ((void *)0);
 struct Newspost_SList *parfiles = ((void *)0);
 if (data->name != ((void *)0)) {
  tmpstring = buff_create(tmpstring, "%s", data->from->data);
  data->from = buff_create(data->from, "%s <%s>",
      data->name->data, tmpstring->data);
  buff_free(tmpstring);
 }
 if ((data->uuenc == 0) || (data->sfv != ((void *)0))) {
  calculate_crcs(file_list);
  if (data->sfv != ((void *)0))
   newsfv(file_list, data);
 }
 if (data->par != ((void *)0)) {
  parfiles = par_newspost_interface(data, file_list);
  if (data->uuenc == 0)
   calculate_crcs(parfiles);
 }
 return parfiles;
}

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


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

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

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

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

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, unsigned int a6, unsigned int a7, __int64 a8)
{
__int64 v12; // r14
unsigned int v13; // er13
__int64 v14; // rax
const char *v15; // rsi
size_t v17; // rax
char s[88]; // [rsp+10h] [rbp-58h] BYREF

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

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

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

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