decompiled_code:
__int64 __fastcall swal_get_socket(int a1)
{
bool v1; // zf
const char *v2; // rdi
int v3; // eax
int v4; // ebx
const char *v6; // rax
struct addrinfo v7; // [rsp+0h] [rbp-48h] BYREF
struct addrinfo *pai; // [rsp+38h] [rbp-10h] BYREF

*(_QWORD *)&v7.ai_flags = 0LL;
*(_QWORD *)&v7.ai_addrlen = 0LL;
v7.ai_addr = 0LL;
v7.ai_canonname = 0LL;
v7.ai_next = 0LL;
v7.ai_socktype = 1;
v7.ai_protocol = 6;
v1 = a1 == 1;
v2 = "api.steampowered.com";
if ( !v1 )
v2 = "steamcommunity.com";
v3 = getaddrinfo(v2, "http", &v7, &pai);
if ( v3 )
{
v6 = gai_strerror(v3);
fprintf(stderr, "Error in getaddrinfo: %s\n", v6);
v4 = -1;
}
else
{
v4 = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
if ( v4 < 0 )
{
fwrite("Failed to create socket.\n", 1uLL, 0x19uLL, stderr);
v4 = -1;
}
else if ( connect(v4, pai->ai_addr, pai->ai_addrlen) )
{
close(v4);
fwrite("Failed to connect.\n", 1uLL, 0x13uLL, stderr);
v4 = -1;
}
else
{
freeaddrinfo(pai);
}
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
bool v1; // zf
const char *v2; // rdi
int v3; // eax
int v4; // ebx
const char *v6; // rax
struct addrinfo v7; // [rsp+0h] [rbp-48h] BYREF
struct addrinfo *pai; // [rsp+38h] [rbp-10h] BYREF

*(_QWORD *)&v7.ai_flags = 0LL;
*(_QWORD *)&v7.ai_addrlen = 0LL;
v7.ai_addr = 0LL;
v7.ai_canonname = 0LL;
v7.ai_next = 0LL;
v7.ai_socktype = 1;
v7.ai_protocol = 6;
v1 = a1 == 1;
v2 = "api.steampowered.com";
if ( !v1 )
v2 = "steamcommunity.com";
v3 = getaddrinfo(v2, "http", &v7, &pai);
if ( v3 )
{
v6 = gai_strerror(v3);
fprintf(stderr, "Error in getaddrinfo: %s\n", v6);
v4 = -1;
}
else
{
v4 = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
if ( v4 < 0 )
{
fwrite("Failed to create socket.\n", 1uLL, 0x19uLL, stderr);
v4 = -1;
}
else if ( connect(v4, pai->ai_addr, pai->ai_addrlen) )
{
close(v4);
fwrite("Failed to connect.\n", 1uLL, 0x13uLL, stderr);
v4 = -1;
}
else
{
freeaddrinfo(pai);
}
}
return (unsigned int)v4;
}

original_code:
int swal_get_socket(int type) {
 int tcpSocket;
 int error;
 struct addrinfo* steamAddressInfo;
 struct addrinfo hints;
 memset(&hints, 0, sizeof(struct addrinfo));
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_protocol = IPPROTO_TCP;
 error = getaddrinfo(type == 1 ? "api.steampowered.com" : "steamcommunity.com", "http", &hints, &steamAddressInfo);
 if (error != 0) {
  fprintf(stderr, "Error in getaddrinfo: %s\n", gai_strerror(error));
  return -1;
 }
 tcpSocket = socket(steamAddressInfo->ai_family, steamAddressInfo->ai_socktype, steamAddressInfo->ai_protocol);
 if (tcpSocket < 0) {
  fprintf(stderr, "Failed to create socket.\n");
  return -1;
 }
 if (connect(tcpSocket, steamAddressInfo->ai_addr, steamAddressInfo->ai_addrlen) != 0) {
  close(tcpSocket);
  fprintf(stderr, "Failed to connect.\n");
  return -1;
 }
 freeaddrinfo(steamAddressInfo);
 return tcpSocket;
}

canonical_original_code:
int swal_get_socket(int type) {
 int tcpSocket;
 int error;
 struct addrinfo *steamAddressInfo;
 struct addrinfo hints;
 memset(&hints, 0, sizeof(struct addrinfo));
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_protocol = IPPROTO_TCP;
 error = getaddrinfo(type == 1 ? "api.steampowered.com" : "steamcommunity.com", "http", &hints, &steamAddressInfo);
 if (error != 0) {
  fprintf(stderr, "Error in getaddrinfo: %s\n", gai_strerror(error));
  return -1;
 }
 tcpSocket = socket(steamAddressInfo->ai_family, steamAddressInfo->ai_socktype, steamAddressInfo->ai_protocol);
 if (tcpSocket < 0) {
  fprintf(stderr, "Failed to create socket.\n");
  return -1;
 }
 if (connect(tcpSocket, steamAddressInfo->ai_addr, steamAddressInfo->ai_addrlen) != 0) {
  close(tcpSocket);
  fprintf(stderr, "Failed to connect.\n");
  return -1;
 }
 freeaddrinfo(steamAddressInfo);
 return tcpSocket;
}

variable_types: type int

variable_types: tcpSocket int

variable_types: error int

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

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


decompiled_code:
char *__fastcall swal_connect(int a1, const char *a2)
{
char *v2; // rax
char *v3; // rbp

v2 = (char *)malloc(0x48uLL);
v3 = v2;
if ( (a1 & 0xFFFFFFFD) != 0 )
*(_DWORD *)v2 = -1;
else
*(_DWORD *)v2 = swal_get_socket(0);
if ( (unsigned int)(a1 - 1) <= 1 )
{
if ( a2 && strlen(a2) > 1 )
{
*((_DWORD *)v3 + 1) = swal_get_socket(1);
strncpy(v3 + 8, a2, 0x20uLL);
}
else
{
fwrite("Please specify an API Key for modern API.\n", 1uLL, 0x2AuLL, stderr);
v3 = 0LL;
}
}
else
{
*((_DWORD *)v3 + 1) = -1;
v3[8] = 0;
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func13(int a1, const char *a2)
{
char *v2; // rax
char *v3; // rbp

v2 = (char *)malloc(0x48uLL);
v3 = v2;
if ( (a1 & 0xFFFFFFFD) != 0 )
*(_DWORD *)v2 = -1;
else
*(_DWORD *)v2 = func12(0);
if ( (unsigned int)(a1 - 1) <= 1 )
{
if ( a2 && strlen(a2) > 1 )
{
*((_DWORD *)v3 + 1) = func12(1);
strncpy(v3 + 8, a2, 0x20uLL);
}
else
{
fwrite("Please specify an API Key for modern API.\n", 1uLL, 0x2AuLL, stderr);
v3 = 0LL;
}
}
else
{
*((_DWORD *)v3 + 1) = -1;
v3[8] = 0;
}
return v3;
}

original_code:
swal_con* swal_connect(int type, char* apiKey) {
 swal_con* connection = (swal_con*)malloc(sizeof(swal_con));
 if (type == 0 || type == 2) {
  connection->legacy_sock = swal_get_socket(0);
 }
 else {
  connection->legacy_sock = -1;
 }
 if (type == 1 || type == 2) {
  if (apiKey == 0 || strlen(apiKey) <= 1) {
   fprintf(stderr, "Please specify an API Key for modern API.\n");
   return 0;
  }
  connection->modern_sock = swal_get_socket(1);
  strncpy(connection->apiKey, apiKey, 32);
 }
 else {
  connection->modern_sock = -1;
  connection->apiKey[0] = '\0';
 }
 return connection;
}

canonical_original_code:
struct swal_con *swal_connect(int type, char *apiKey) {
 struct swal_con *connection = (swal_con*)malloc(sizeof(swal_con));
 if (type == 0 || type == 2) {
  connection->legacy_sock = swal_get_socket(0);
 }
 else {
  connection->legacy_sock = -1;
 }
 if (type == 1 || type == 2) {
  if (apiKey == 0 || strlen(apiKey) <= 1) {
   fprintf(stderr, "Please specify an API Key for modern API.\n");
   return 0;
  }
  connection->modern_sock = swal_get_socket(1);
  strncpy(connection->apiKey, apiKey, 32);
 }
 else {
  connection->modern_sock = -1;
  connection->apiKey[0] = '\0';
 }
 return connection;
}

variable_types:
apiKey
char *

variable_types: struct swal_con { int legacy_sock; int modern_sock; char apiKey[64]; } *


handler

decompiled_code:
int __fastcall handler(unsigned int a1)
{
return printf("Recieved signal: %d\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
return printf("Recieved signal: %d\n", a1);
}

original_code:
void handler(int status) {
 printf("Recieved signal: %d\n", status);
}

variable_types: status int

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r13
__int64 v4; // r12
unsigned int i; // ebx
void *v6; // rbp
struct sigaction v8; // [rsp+0h] [rbp-1A8h] BYREF
struct sigaction v9; // [rsp+A0h] [rbp-108h] BYREF
char s[104]; // [rsp+140h] [rbp-68h] BYREF

v3 = readKey();
v8.sa_handler = (__sighandler_t)handler;
sigemptyset(&v8.sa_mask);
sigaddset(&v8.sa_mask, 13);
v8.sa_flags = 0x10000000;
sigaction(13, &v8, &v9);
v4 = swal_connect(2LL, v3);
if ( !v4 )
puts("Connection failed");
for ( i = 3972300; i != 30000000; i += 100 )
{
sprintf(s, "Data/PlayerSummaries_Exhaustive/player_summaries_%08d.json", i);
puts(s);
v6 = (void *)generateIDs(1LL, i);
swal_get_player_summaries(v4, v6, s);
free(v6);
usleep(0xF4240u);
}
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 i; // ebx
void *v6; // rbp
struct sigaction v8; // [rsp+0h] [rbp-1A8h] BYREF
struct sigaction v9; // [rsp+A0h] [rbp-108h] BYREF
char s[104]; // [rsp+140h] [rbp-68h] BYREF

v3 = func1();
v8.sa_handler = (__sighandler_t)handler;
sigemptyset(&v8.sa_mask);
sigaddset(&v8.sa_mask, 13);
v8.sa_flags = 0x10000000;
sigaction(13, &v8, &v9);
v4 = swal_connect(2LL, v3);
if ( !v4 )
puts("Connection failed");
for ( i = 3972300; i != 30000000; i += 100 )
{
sprintf(s, "Data/PlayerSummaries_Exhaustive/player_summaries_%08d.json", i);
puts(s);
v6 = (void *)generateIDs(1LL, i);
swal_get_player_summaries(v4, v6, s);
free(v6);
usleep(0xF4240u);
}
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 *

return_type: int

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 swal_con { int legacy_sock; int modern_sock; char apiKey[64]; }

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
{
a2 += 2LL;
result = *a1;
*(_WORD *)(a2 - 2) = result;
++a1;
}
while ( *(a1 - 1) );
return result;
}

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

do
{
a2 += 2LL;
result = *a1;
*(_WORD *)(a2 - 2) = result;
++a1;
}
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 *


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

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

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

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

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(__int64 a1, __int16 *a2, __int64 a3)
{
__int16 v4; // dx
__int64 v5; // rcx
__int64 result; // rax
__int64 v7; // r8

v4 = *a2;
if ( *a2 )
{
if ( a3 <= 1 )
{
result = 0LL;
v7 = 0LL;
}
else
{
v5 = a3 - 1;
result = 0LL;
while ( 1 )
{
*(_WORD *)(a1 + 2 * result++) = v4;
v7 = 2 * result;
v4 = a2[result];
if ( !v4 )
break;
if ( result == v5 )
{
result = v5;
break;
}
}
}
}
else
{
result = 0LL;
v7 = 0LL;
}
*(_WORD *)(a1 + v7) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int16 *a2, __int64 a3)
{
__int16 v4; // dx
__int64 v5; // rcx
__int64 result; // rax
__int64 v7; // r8

v4 = *a2;
if ( *a2 )
{
if ( a3 <= 1 )
{
result = 0LL;
v7 = 0LL;
}
else
{
v5 = a3 - 1;
result = 0LL;
while ( 1 )
{
*(_WORD *)(a1 + 2 * result++) = v4;
v7 = 2 * result;
v4 = a2[result];
if ( !v4 )
break;
if ( result == v5 )
{
result = v5;
break;
}
}
}
}
else
{
result = 0LL;
v7 = 0LL;
}
*(_WORD *)(a1 + v7) = 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 = (const char *)stuni(a1);
return remove(v1);
}

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

v1 = (const char *)func5(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 *


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

canonical_decompiled_code:
__int64 __fastcall func11(__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; // ebx
struct hostent *v5; // rax
int optval; // [rsp+8h] [rbp-160h] BYREF
struct in_addr inp; // [rsp+Ch] [rbp-15Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-158h] BYREF
struct sigaction v9; // [rsp+20h] [rbp-148h] BYREF
struct sigaction v10; // [rsp+C0h] [rbp-A8h] BYREF

*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_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 )
{
close(v3);
v3 = -3;
}
else
{
optval = 1;
if ( setsockopt(v3, 1, 9, &optval, 4u) < 0 )
{
close(v3);
v3 = -3;
}
else
{
v10.sa_handler = (__sighandler_t)(_bswap_16 + 1);
sigemptyset(&v10.sa_mask);
v10.sa_flags = 0;
sigaction(13, &v10, &v9);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *name, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
struct hostent *v5; // rax
int optval; // [rsp+8h] [rbp-160h] BYREF
struct in_addr inp; // [rsp+Ch] [rbp-15Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-158h] BYREF
struct sigaction v9; // [rsp+20h] [rbp-148h] BYREF
struct sigaction v10; // [rsp+C0h] [rbp-A8h] BYREF

*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_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 )
{
close(v3);
v3 = -3;
}
else
{
optval = 1;
if ( setsockopt(v3, 1, 9, &optval, 4u) < 0 )
{
close(v3);
v3 = -3;
}
else
{
v10.sa_handler = (__sighandler_t)(_bswap_16 + 1);
sigemptyset(&v10.sa_mask);
v10.sa_flags = 0;
sigaction(13, &v10, &v9);
}
}
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 v3; // rbx
int *v5; // rax

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

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

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

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 v3; // r12
ssize_t v4; // rbx
int *v5; // rax

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

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

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

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

if ( *((__int64 *)ptr + 1) > 0 )
{
v1 = 0LL;
do
buff_free(*(_QWORD *)(*(_QWORD *)ptr + 24 * v1++ + 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 func1(void *ptr)
{
__int64 v1; // rbx

if ( *((__int64 *)ptr + 1) > 0 )
{
v1 = 0LL;
do
buff_free(*(_QWORD *)(*(_QWORD *)ptr + 24 * v1++ + 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

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

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

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_57C, 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_57C, 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)
{
int v4; // edx
__int64 result; // rax
const char **v6; // rdx
int v7; // edx
int v8; // edx
int v9; // edx
int v10; // edx
char v11[1048]; // [rsp+0h] [rbp-418h] BYREF

v4 = nntp_get_response(a1, (__int64)v11);
result = 0LL;
if ( v4 >= 0 )
{
v6 = *(const char ***)(a2 + 48);
result = 1LL;
if ( v6 )
{
sprintf(v11, "AUTHINFO USER %s", *v6);
v7 = nntp_issue_command(a1, v11);
result = 0LL;
if ( v7 >= 0 )
{
v8 = nntp_get_response(a1, (__int64)v11);
result = 0LL;
if ( v8 >= 0 )
{
if ( !memcmp(v11, "381", 3uLL) )
{
sprintf(v11, "AUTHINFO PASS %s", **(const char ***)(a2 + 56));
v9 = nntp_issue_command(a1, v11);
result = 0LL;
if ( v9 >= 0 )
{
v10 = nntp_get_response(a1, (__int64)v11);
result = 0LL;
if ( v10 >= 0 )
{
result = 1LL;
if ( !memcmp(v11, "502", 3uLL) )
{
ui_nntp_authentication_failed(a1, v11);
result = 0LL;
}
}
}
}
else
{
result = 1LL;
if ( memcmp(v11, "281", 3uLL) )
{
if ( memcmp(v11, "500", 3uLL) )
{
ui_nntp_unknown_response(a1, v11);
result = 1LL;
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v4; // edx
__int64 result; // rax
const char **v6; // rdx
int v7; // edx
int v8; // edx
int v9; // edx
int v10; // edx
char v11[1048]; // [rsp+0h] [rbp-418h] BYREF

v4 = func1(a1, (__int64)v11);
result = 0LL;
if ( v4 >= 0 )
{
v6 = *(const char ***)(a2 + 48);
result = 1LL;
if ( v6 )
{
sprintf(v11, "AUTHINFO USER %s", *v6);
v7 = func0(a1, v11);
result = 0LL;
if ( v7 >= 0 )
{
v8 = func1(a1, (__int64)v11);
result = 0LL;
if ( v8 >= 0 )
{
if ( !memcmp(v11, "381", 3uLL) )
{
sprintf(v11, "AUTHINFO PASS %s", **(const char ***)(a2 + 56));
v9 = func0(a1, v11);
result = 0LL;
if ( v9 >= 0 )
{
v10 = func1(a1, (__int64)v11);
result = 0LL;
if ( v10 >= 0 )
{
result = 1LL;
if ( !memcmp(v11, "502", 3uLL) )
{
ui_nntp_authentication_failed(a1, v11);
result = 0LL;
}
}
}
}
else
{
result = 1LL;
if ( memcmp(v11, "281", 3uLL) )
{
if ( memcmp(v11, "500", 3uLL) )
{
ui_nntp_unknown_response(a1, v11);
result = 1LL;
}
}
}
}
}
}
}
return result;
}

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 v10; // er14
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // r15
const char **v15; // rax
const char **v16; // rax
const char **v17; // rax
const char **v18; // rax
const char ***i; // rbx
__int64 v20; // rbx
__int64 v21; // r15
unsigned int v22; // ebx
__int64 v23; // rdx
bool v24; // al
bool v25; // cf
bool v26; // zf
char *v27; // rsi
const char *v28; // rdi
__int64 v29; // rcx
char v32; // [rsp+4h] [rbp-444h]
_QWORD *v34; // [rsp+8h] [rbp-440h]
char v35[1080]; // [rsp+10h] [rbp-438h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, __int64 a3, __int64 a4, __int64 a5, char a6)
{
unsigned int v10; // er14
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // r15
const char **v15; // rax
const char **v16; // rax
const char **v17; // rax
const char **v18; // rax
const char ***i; // rbx
__int64 v20; // rbx
__int64 v21; // r15
unsigned int v22; // ebx
__int64 v23; // rdx
bool v24; // al
bool v25; // cf
bool v26; // zf
char *v27; // rsi
const char *v28; // rdi
__int64 v29; // rcx
char v32; // [rsp+4h] [rbp-444h]
_QWORD *v34; // [rsp+8h] [rbp-440h]
char v35[1080]; // [rsp+10h] [rbp-438h] BYREF

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

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


decompiled_code:
char **buff_add(void **a1, char *a2, ...)
{
char **v2; // rbx
__int64 v4; // rbp
char *v5; // r13
signed __int64 v6; // rsi
char **v8; // rax
signed __int64 i; // rdi
char *v10; // rax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
v2 = (char **)a1;
v4 = buff_data_length(a2, (int *)arg);
va_end(arg);
va_start(arg, a2);
if ( a1 )
{
v5 = (char *)a1[1];
a1[1] = &v5[v4];
v6 = (signed __int64)a1[2];
if ( (__int64)&v5[v4] >= v6 )
{
do
v6 *= 2LL;
while ( (__int64)&v5[v4] >= v6 );
a1[2] = (void *)v6;
*a1 = realloc(*a1, v6);
}
vsprintf((char *)*a1 + (int)v5, a2, arg);
}
else
{
if ( !v4 )
return v2;
v8 = (char **)malloc(0x18uLL);
v2 = v8;
v8[1] = (char *)v4;
v8[2] = (_BYTE *)&loc_2;
if ( v4 <= 1 )
{
i = 2LL;
}
else
{
for ( i = 2LL; i <= v4; i *= 2LL )
;
v8[2] = (char *)i;
}
v10 = (char *)malloc(i);
*v2 = v10;
vsprintf(v10, a2, arg);
}
v2[1][(_QWORD)*v2] = 0;
return v2;
}

canonical_decompiled_code:
char **func2(void **a1, char *a2, ...)
{
char **v2; // rbx
__int64 v4; // rbp
char *v5; // r13
signed __int64 v6; // rsi
char **v8; // rax
signed __int64 i; // rdi
char *v10; // rax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
v2 = (char **)a1;
v4 = func0(a2, (int *)arg);
va_end(arg);
va_start(arg, a2);
if ( a1 )
{
v5 = (char *)a1[1];
a1[1] = &v5[v4];
v6 = (signed __int64)a1[2];
if ( (__int64)&v5[v4] >= v6 )
{
do
v6 *= 2LL;
while ( (__int64)&v5[v4] >= v6 );
a1[2] = (void *)v6;
*a1 = realloc(*a1, v6);
}
vsprintf((char *)*a1 + (int)v5, a2, arg);
}
else
{
if ( !v4 )
return v2;
v8 = (char **)malloc(0x18uLL);
v2 = v8;
v8[1] = (char *)v4;
v8[2] = (_BYTE *)&loc_2;
if ( v4 <= 1 )
{
i = 2LL;
}
else
{
for ( i = 2LL; i <= v4; i *= 2LL )
;
v8[2] = (char *)i;
}
v10 = (char *)malloc(i);
*v2 = v10;
vsprintf(v10, a2, arg);
}
v2[1][(_QWORD)*v2] = 0;
return v2;
}

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; // rbp
char **v4; // rax
signed __int64 i; // 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);
v3 = v4;
v4[1] = (char *)v2;
v4[2] = (_BYTE *)&loc_2;
if ( v2 <= 1 )
{
i = 2LL;
}
else
{
for ( i = 2LL; i <= v2; i *= 2LL )
;
v4[2] = (char *)i;
}
v6 = (char *)malloc(i);
*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; // rbp
char **v4; // rax
signed __int64 i; // 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);
v3 = v4;
v4[1] = (char *)v2;
v4[2] = (_BYTE *)&loc_2;
if ( v2 <= 1 )
{
i = 2LL;
}
else
{
for ( i = 2LL; i <= v2; i *= 2LL )
;
v4[2] = (char *)i;
}
v6 = (char *)malloc(i);
*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 func8(__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

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

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

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

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
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

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:
__int64 __fastcall post_text_file(__int64 a1, __int64 a2)
{
int v2; // ebp
_QWORD *v3; // r12
int v5; // [rsp+0h] [rbp-38h] BYREF
unsigned int v6; // [rsp+4h] [rbp-34h]
pthread_rwlock_t *rwlock; // [rsp+8h] [rbp-30h]
__int64 v8; // [rsp+18h] [rbp-20h]

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v2; // ebp
_QWORD *v3; // r12
int v5; // [rsp+0h] [rbp-38h] BYREF
unsigned int v6; // [rsp+4h] [rbp-34h]
pthread_rwlock_t *rwlock; // [rsp+8h] [rbp-30h]
__int64 v8; // [rsp+18h] [rbp-20h]

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

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

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

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

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