decompiled_code:
__int64 __fastcall close_child(char a1)
{
__int64 v1; // rax
__int64 v2; // rdx
int v3; // eax
__int64 v4; // rax
__int64 v5; // rax
void (__fastcall *v7)(_QWORD, _DWORD *, __int64); // rcx

if ( a1 == 1 )
{
client_log_statistics();
if ( (unsigned int)nullstr(client + 392LL) )
strcpy((char *)(client + 392LL), (const char *)(client + 64LL));
if ( (unsigned int)nullstr(client + 456LL) )
strcpy((char *)(client + 456LL), (const char *)(client + 392LL));
v7 = (void (__fastcall *)(_QWORD, _DWORD *, __int64))find_acct_mod(*(_QWORD *)(*(_QWORD *)(client + 368LL) + 2672LL) + 256LL);
if ( v7 )
{
v7(client, cfg, *(_QWORD *)(*(_QWORD *)(client + 368LL) + 2672LL) + 512LL);
syslog_open("nntpswitchd", 1LL, 56LL);
}
else
{
syslog(3, "Can't find acctmap: %s", (const char *)(*(_QWORD *)(*(_QWORD *)(client + 368LL) + 2672LL) + 256LL));
syslog(5, "%s: accounting vanished", (const char *)(client + 64LL));
}
if ( *(__int64 *)(*(_QWORD *)(client + 376LL) + 136LL) < 0 )
sleep(cfg[50]);
}
if ( *(_DWORD *)(client + 4LL) && *(_QWORD *)(client + 8LL) )
ssl_close();
v1 = *(_QWORD *)(client + 368LL);
if ( (*(int *)(v1 + 560) > 0 || *(int *)(v1 + 564) > 0) && (*(_BYTE *)(client + 712LL) & 2) != 0 )
http_accountsharing_dropuser(client + 392LL, client + 64LL);
if ( cfg[72] )
freehttpacl(*(_QWORD *)(client + 344LL));
semlock_lock(*(unsigned int *)(master + 16953360LL));
v2 = *(_QWORD *)(client + 368LL);
v3 = *(_DWORD *)(v2 + 3328);
if ( v3 )
*(_DWORD *)(v2 + 3328) = v3 - 1;
else
syslog(3, "Trying to drop 0 connections profile: %s", (const char *)v2);
v4 = *(_QWORD *)(client + 376LL);
if ( v4 )
drop_user(*(_DWORD *)(v4 + 128), *(_QWORD *)(client + 368LL));
else
syslog(3, "close_child: user == NULL");
free_client(*(_DWORD *)(client + 584LL));
v5 = master;
--*(_DWORD *)(master + 96LL);
return semlock_unlock(*(unsigned int *)(v5 + 16953360));
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
__int64 v1; // rax
__int64 v2; // rdx
int v3; // eax
__int64 v4; // rax
__int64 v5; // rax
void (__fastcall *v7)(_QWORD, _DWORD *, __int64); // rcx

if ( a1 == 1 )
{
client_log_statistics();
if ( (unsigned int)nullstr(client + 392LL) )
strcpy((char *)(client + 392LL), (const char *)(client + 64LL));
if ( (unsigned int)nullstr(client + 456LL) )
strcpy((char *)(client + 456LL), (const char *)(client + 392LL));
v7 = (void (__fastcall *)(_QWORD, _DWORD *, __int64))find_acct_mod(*(_QWORD *)(*(_QWORD *)(client + 368LL) + 2672LL) + 256LL);
if ( v7 )
{
v7(client, cfg, *(_QWORD *)(*(_QWORD *)(client + 368LL) + 2672LL) + 512LL);
syslog_open("nntpswitchd", 1LL, 56LL);
}
else
{
syslog(3, "Can't find acctmap: %s", (const char *)(*(_QWORD *)(*(_QWORD *)(client + 368LL) + 2672LL) + 256LL));
syslog(5, "%s: accounting vanished", (const char *)(client + 64LL));
}
if ( *(__int64 *)(*(_QWORD *)(client + 376LL) + 136LL) < 0 )
sleep(cfg[50]);
}
if ( *(_DWORD *)(client + 4LL) && *(_QWORD *)(client + 8LL) )
ssl_close();
v1 = *(_QWORD *)(client + 368LL);
if ( (*(int *)(v1 + 560) > 0 || *(int *)(v1 + 564) > 0) && (*(_BYTE *)(client + 712LL) & 2) != 0 )
http_accountsharing_dropuser(client + 392LL, client + 64LL);
if ( cfg[72] )
freehttpacl(*(_QWORD *)(client + 344LL));
semlock_lock(*(unsigned int *)(master + 16953360LL));
v2 = *(_QWORD *)(client + 368LL);
v3 = *(_DWORD *)(v2 + 3328);
if ( v3 )
*(_DWORD *)(v2 + 3328) = v3 - 1;
else
syslog(3, "Trying to drop 0 connections profile: %s", (const char *)v2);
v4 = *(_QWORD *)(client + 376LL);
if ( v4 )
func4(*(_DWORD *)(v4 + 128), *(_QWORD *)(client + 368LL));
else
syslog(3, "close_child: user == NULL");
func0(*(_DWORD *)(client + 584LL));
v5 = master;
--*(_DWORD *)(master + 96LL);
return semlock_unlock(*(unsigned int *)(v5 + 16953360));
}

original_code:
void close_child(unsigned char doacct)
{
 if ( doacct == 1 )
 {
  client_log_statistics();
  if ( nullstr(client->username) )
   strcpy(client->username, client->hostname);
  if ( nullstr(client->logname) )
   strcpy(client->logname, client->username);
  void (*acctmod)() = find_acct_mod(client->profile->Accounting->lib);
  if ( acctmod != ((void *)0) ) {
   (*acctmod)(client, &cfg, client->profile->Accounting->args);
   syslog_open("nntpswitchd", 0x01, (7<<3));
  } else {
   syslog(3, "Can't find acctmap: %s"
     , client->profile->Accounting->lib);
   syslog(5,"%s: accounting vanished", client->hostname);
  }
  if (client->user->bytesleft < 0) {
      sleep(cfg.AccountingDelay);
  }
 }
 if (client->useSSL) {
  if (client->ssl) {
   ssl_close(client->ssl);
  }
 }
 if ( (client->profile->ASMaxConns > 0 || client->profile->ASMaxHosts > 0) && client->authenticated > 0 ) {
  http_accountsharing_dropuser(client->username, client->hostname);
 }
 if ( cfg.JSONACL ) {
     freehttpacl(client->acl);
 }
 semlock_lock(master->semid);
 if ( client->profile->connections > 0 )
  client->profile->connections--;
 else
  syslog(3, "Trying to drop 0 connections profile: %s", client->profile->Name);
 if ( client->user != ((void *)0) )
  drop_user(client->user->id, client->profile);
 else
  syslog(3, "close_child: user == NULL");
 free_client(client->id);
 master->connections--;
 semlock_unlock(master->semid);
 return;
}

variable_types:
doacct
unsigned char

variable_types:
acctmod
void (*)()


repo: tomarus/nntpswitch

decompiled_code:
__int64 __fastcall find_user_profile(char *s2)
{
__int64 v1; // r14
const char *v2; // rbp
__int64 v3; // r15
__int64 v4; // r12
__int64 v6; // rax

v1 = master;
v2 = (const char *)(master + 5898352LL);
v3 = master + 11731056LL;
v4 = master + 5898344LL;
while ( strcmp(v2, s2) )
{
LABEL_3:
v2 += 712;
if ( v2 == (const char *)v3 )
return 0LL;
}
v6 = v1 + 104;
while ( v2 != *(const char **)(v6 + 376) )
{
v6 += 720LL;
if ( v6 == v4 )
goto LABEL_3;
}
return *(_QWORD *)(v6 + 368);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s2)
{
__int64 v1; // r14
const char *v2; // rbp
__int64 v3; // r15
__int64 v4; // r12
__int64 v6; // rax

v1 = master;
v2 = (const char *)(master + 5898352LL);
v3 = master + 11731056LL;
v4 = master + 5898344LL;
while ( strcmp(v2, s2) )
{
LABEL_3:
v2 += 712;
if ( v2 == (const char *)v3 )
return 0LL;
}
v6 = v1 + 104;
while ( v2 != *(const char **)(v6 + 376) )
{
v6 += 720LL;
if ( v6 == v4 )
goto LABEL_3;
}
return *(_QWORD *)(v6 + 368);
}

original_code:
struct _profile * find_user_profile(char *key)
{
 int i,j;
 for ( i=0; i<8192; i++) {
  if ( strcmp((master->users+i)->key, key) == 0 ) {
   for ( j=0; j<8192; j++ ) {
    if ( (master->clients+j)->user == master->users+i ) {
     return (master->clients+j)->profile;
    }
   }
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct _profile *find_user_profile(char *key)
{
 int i; int j;
 for ( i=0; i<8192; i++) {
  if ( strcmp((master->users+i)->key, key) == 0 ) {
   for ( j=0; j<8192; j++ ) {
    if ( (master->clients+j)->user == master->users+i ) {
     return (master->clients+j)->profile;
    }
   }
  }
 }
 return ((void *)0);
}

variable_types:
key
char *

variable_types: i int

variable_types: j int

return_type: struct _profile { char Name[32]; char ReadPat[256]; char PostPat[256]; int MaxConnections; int MaxUserConcurrent; int MaxHostConcurrent; int Slave; int ASMaxConns; int ASMaxHosts; int MaxUsers; int MaxSessionTime; unsigned long long MaxSessionBytes; unsigned int MaxUserBPS; unsigned int MaxProfileBPS; char XComplaintsTo[256]; char Organization[256]; int ForceOrganization; int AddNNTPPostingHost; int MaxCross; char Hostname[256]; char FooterFile[256]; char Footer[1024]; int FooterSize; int NoControl; int ArticleSearch; int ClientReadTimeout; struct ALIAS { char name[256]; char lib[256]; char args[256]; } *Accounting; char AccountingPrefix[256]; struct LIMITS { int gb; int kbit; } Limits[16]; int NumLimits; char Disabled[256]; int AllowSSL; unsigned int connections; unsigned int numusers; unsigned int realusers; unsigned long long bytes; unsigned long long rbytes; unsigned long articles; unsigned long long postbytes; unsigned long postarticles; unsigned int rl_curbytes; unsigned int rl_lastbytes; double rl_sleep; struct timeval { long tv_sec; long tv_usec; } rl_start; double rl_curbps; double UserRLFactorU; double UserRLFactorD; double ProfileRLFactorU; double ProfileRLFactorD; unsigned int Retention; char XHeaderSSLUpload[1024]; struct PFXMAP { char name[32]; char map[4194303]; } *PrefixMap; struct _profile *FailProfile; } *

user_defined_types: struct _profile { char Name[32]; char ReadPat[256]; char PostPat[256]; int MaxConnections; int MaxUserConcurrent; int MaxHostConcurrent; int Slave; int ASMaxConns; int ASMaxHosts; int MaxUsers; int MaxSessionTime; unsigned long long MaxSessionBytes; unsigned int MaxUserBPS; unsigned int MaxProfileBPS; char XComplaintsTo[256]; char Organization[256]; int ForceOrganization; int AddNNTPPostingHost; int MaxCross; char Hostname[256]; char FooterFile[256]; char Footer[1024]; int FooterSize; int NoControl; int ArticleSearch; int ClientReadTimeout; struct ALIAS *Accounting; char AccountingPrefix[256]; struct LIMITS Limits[16]; int NumLimits; char Disabled[256]; int AllowSSL; unsigned int connections; unsigned int numusers; unsigned int realusers; unsigned long long bytes; unsigned long long rbytes; unsigned long articles; unsigned long long postbytes; unsigned long postarticles; unsigned int rl_curbytes; unsigned int rl_lastbytes; double rl_sleep; struct timeval rl_start; double rl_curbps; double UserRLFactorU; double UserRLFactorD; double ProfileRLFactorU; double ProfileRLFactorD; unsigned int Retention; char XHeaderSSLUpload[1024]; struct PFXMAP *PrefixMap; struct _profile *FailProfile; }


decompiled_code:
int __fastcall cmp_active(const void *a1, const void *a2)
{
return strcmp((const char *)a1 + 33, (const char *)a2 + 33);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, const void *a2)
{
return strcmp((const char *)a1 + 33, (const char *)a2 + 33);
}

original_code:
int cmp_active(const void *a, const void *b)
{
 const ACTIVE *s1 = (const ACTIVE *) a;
 const ACTIVE *s2 = (const ACTIVE *) b;
 return strcmp(s1->newsgroup, s2->newsgroup);
}

canonical_original_code:
int cmp_active(void *a, void *b)
{
 struct ACTIVE *s1 = (const ACTIVE *) a;
 struct ACTIVE *s2 = (const ACTIVE *) b;
 return strcmp(s1->newsgroup, s2->newsgroup);
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct ACTIVE { unsigned long hi; unsigned long lo; unsigned long times; unsigned long id; char mode; char newsgroup[160]; char server[32]; } *

return_type: int


gg

decompiled_code:
void *__fastcall gg(char *src, int a2)
{
int v2; // ebx
char v4[264]; // [rsp+0h] [rbp-108h] BYREF

v2 = a2;
if ( !a2 )
v2 = *master;
memset(v4, 0, 0xE8uLL);
strncpy(&v4[33], src, 0xA0uLL);
return bsearch(v4, groups, v2, 0xE8uLL, cmp_active);
}

canonical_decompiled_code:
void *__fastcall func1(char *src, int a2)
{
int v2; // ebx
char v4[264]; // [rsp+0h] [rbp-108h] BYREF

v2 = a2;
if ( !a2 )
v2 = *master;
memset(v4, 0, 0xE8uLL);
strncpy(&v4[33], src, 0xA0uLL);
return bsearch(v4, groups, v2, 0xE8uLL, cmp_active);
}

original_code:
ACTIVE* gg(const char *groupname, int max)
{
 ACTIVE ng;
 if ( max == 0 )
  max = master->numgroups;
 memset(&ng, 0, sizeof(ACTIVE));
 strncpy(ng.newsgroup, groupname, 160);
 return bsearch(&ng, groups, max, sizeof(ACTIVE), cmp_active);
}

canonical_original_code:
struct ACTIVE *gg(char *groupname, int max)
{
 struct ACTIVE ng;
 if ( max == 0 )
  max = master->numgroups;
 memset(&ng, 0, sizeof(ACTIVE));
 strncpy(ng.newsgroup, groupname, 160);
 return bsearch(&ng, groups, max, sizeof(ACTIVE), cmp_active);
}

variable_types:
groupname
char *

variable_types: max int

return_type: struct ACTIVE { unsigned long hi; unsigned long lo; unsigned long times; unsigned long id; char mode; char newsgroup[160]; char server[32]; } *


decompiled_code:
int __fastcall getlist_active(char *src, unsigned int a2, const char *a3)
{
size_t v4; // rax
size_t v5; // rax
int v6; // ebp
unsigned int v7; // er13
__int64 v8; // r14
char *v9; // r15
__int64 v10; // rdx
char *v11; // rax
char v13; // [rsp+8h] [rbp-250h] BYREF
char v14[11]; // [rsp+Ah] [rbp-24Eh] BYREF
char nptr[11]; // [rsp+15h] [rbp-243h] BYREF
char s[568]; // [rsp+20h] [rbp-238h] BYREF

strcpy(buf, "MODE READER\r\n");
v4 = strlen(buf);
if ( write_socket(a2, buf, v4, *((unsigned int *)src + 4201)) == -1 )
die("Cant write to server");
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read mode reader response");
sprintf(buf, "LIST active %s\r\n", a3);
v5 = strlen(buf);
if ( write_socket(a2, buf, v5, *((unsigned int *)src + 4201)) == -1 )
die("Cant write to server");
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read list active response");
if ( atoi(buf) != 215 )
die("Invalid response from server: %s", buf);
v6 = *master;
v7 = 0;
while ( 1 )
{
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read active file");
if ( buf[0] == 46 && buf[1] == 13 )
break;
if ( (unsigned int)_isoc99_sscanf(buf, "%511s %10s %10s %2s", s, nptr, v14, &v13) == 4 )
{
if ( strlen(s) > 0x9F )
{
info("Skipping too long groupname: %s", s);
}
else if ( !gg(s, v6) )
{
if ( *master == (_DWORD)&unk_1F400 )
die("Too many newsgroups, increase MAX_GROUPS in nntpd.h");
v8 = 232LL * (int)*master;
v9 = (char *)groups + v8;
strncpy((char *)groups + v8 + 33, s, 0xBFuLL);
strncpy(v9 + 193, src, 0x1FuLL);
*(_QWORD *)v9 = atol(nptr);
v10 = atol(v14);
v11 = (char *)groups + v8;
*((_QWORD *)v11 + 1) = v10;
v11[32] = v13;
*((_QWORD *)v11 + 2) = 0LL;
++*master;
++v7;
}
}
else
{
info("Invalid active entry: %s %d %d", buf, (unsigned int)buf[0], (unsigned int)buf[1]);
}
}
qsort(groups, (int)*master, 0xE8uLL, cmp_active);
return printf("Loaded %d groups, %d total\n", v7, (unsigned int)*master);
}

canonical_decompiled_code:
int __fastcall func3(char *src, unsigned int a2, const char *a3)
{
size_t v4; // rax
size_t v5; // rax
int v6; // ebp
unsigned int v7; // er13
__int64 v8; // r14
char *v9; // r15
__int64 v10; // rdx
char *v11; // rax
char v13; // [rsp+8h] [rbp-250h] BYREF
char v14[11]; // [rsp+Ah] [rbp-24Eh] BYREF
char nptr[11]; // [rsp+15h] [rbp-243h] BYREF
char s[568]; // [rsp+20h] [rbp-238h] BYREF

strcpy(buf, "MODE READER\r\n");
v4 = strlen(buf);
if ( write_socket(a2, buf, v4, *((unsigned int *)src + 4201)) == -1 )
die("Cant write to server");
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read mode reader response");
sprintf(buf, "LIST active %s\r\n", a3);
v5 = strlen(buf);
if ( write_socket(a2, buf, v5, *((unsigned int *)src + 4201)) == -1 )
die("Cant write to server");
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read list active response");
if ( atoi(buf) != 215 )
die("Invalid response from server: %s", buf);
v6 = *master;
v7 = 0;
while ( 1 )
{
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read active file");
if ( buf[0] == 46 && buf[1] == 13 )
break;
if ( (unsigned int)_isoc99_sscanf(buf, "%511s %10s %10s %2s", s, nptr, v14, &v13) == 4 )
{
if ( strlen(s) > 0x9F )
{
info("Skipping too long groupname: %s", s);
}
else if ( !func1(s, v6) )
{
if ( *master == (_DWORD)&unk_1F400 )
die("Too many newsgroups, increase MAX_GROUPS in nntpd.h");
v8 = 232LL * (int)*master;
v9 = (char *)groups + v8;
strncpy((char *)groups + v8 + 33, s, 0xBFuLL);
strncpy(v9 + 193, src, 0x1FuLL);
*(_QWORD *)v9 = atol(nptr);
v10 = atol(v14);
v11 = (char *)groups + v8;
*((_QWORD *)v11 + 1) = v10;
v11[32] = v13;
*((_QWORD *)v11 + 2) = 0LL;
++*master;
++v7;
}
}
else
{
info("Invalid active entry: %s %d %d", buf, (unsigned int)buf[0], (unsigned int)buf[1]);
}
}
qsort(groups, (int)*master, 0xE8uLL, cmp_active);
return printf("Loaded %d groups, %d total\n", v7, (unsigned int)*master);
}

original_code:
void getlist_active(SERVER *server, int sock, char *glist)
{
 char group[512], end[11], begin[11], mode[2];
 int num = 0;
 int i;
 int ng;
 sprintf(buf, "MODE READER\r\n");
 if ( write_socket(sock, buf, strlen(buf), server->Timeout) == -1 )
  die("Cant write to server");
 if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
  die("Cant read mode reader response");
 sprintf(buf, "LIST active %s\r\n", glist);
 if ( write_socket(sock, buf, strlen(buf), server->Timeout) == -1 )
  die("Cant write to server");
 if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
  die("Cant read list active response");
 if ( atoi(buf) != 215 )
  die("Invalid response from server: %s", buf);
 ng = master->numgroups;
 while ( 1 )
 {
  if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
   die("Cant read active file");
  if ( buf[0] == '.' && buf[1] == '\r' )
   break;
  if ( sscanf(buf, "%511s %10s %10s %2s", group, end, begin, mode) != 4 )
  {
   info("Invalid active entry: %s %d %d", buf, buf[0], buf[1]);
  }
  else
  {
   if ( strlen(group) >= 160 )
   {
    info("Skipping too long groupname: %s", group);
    continue;
   }
   if ( gg(group, ng) == ((void *)0) )
   {
    if ( master->numgroups == 128000 )
     die("Too many newsgroups, increase MAX_GROUPS in nntpd.h");
    i=master->numgroups;
    strncpy((groups+i)->newsgroup, group, 191);
    strncpy((groups+i)->server, server->Name, 31);
    (groups+i)->hi = atol(end);
    (groups+i)->lo = atol(begin);
    (groups+i)->mode = mode[0];
    (groups+i)->times = 0;
    master->numgroups++;
    num++;
   }
  }
 }
 qsort(groups, master->numgroups, sizeof(ACTIVE), cmp_active);
 printf("Loaded %d groups, %d total\n", num, master->numgroups);
}

canonical_original_code:
void getlist_active(struct SERVER *server, int sock, char *glist)
{
 char group[512]; char end[11]; char begin[11]; char mode[2];
 int num = 0;
 int i;
 int ng;
 sprintf(buf, "MODE READER\r\n");
 if ( write_socket(sock, buf, strlen(buf), server->Timeout) == -1 )
  die("Cant write to server");
 if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
  die("Cant read mode reader response");
 sprintf(buf, "LIST active %s\r\n", glist);
 if ( write_socket(sock, buf, strlen(buf), server->Timeout) == -1 )
  die("Cant write to server");
 if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
  die("Cant read list active response");
 if ( atoi(buf) != 215 )
  die("Invalid response from server: %s", buf);
 ng = master->numgroups;
 while ( 1 )
 {
  if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
   die("Cant read active file");
  if ( buf[0] == '.' && buf[1] == '\r' )
   break;
  if ( sscanf(buf, "%511s %10s %10s %2s", group, end, begin, mode) != 4 )
  {
   info("Invalid active entry: %s %d %d", buf, buf[0], buf[1]);
  }
  else
  {
   if ( strlen(group) >= 160 )
   {
    info("Skipping too long groupname: %s", group);
    continue;
   }
   if ( gg(group, ng) == ((void *)0) )
   {
    if ( master->numgroups == 128000 )
     die("Too many newsgroups, increase MAX_GROUPS in nntpd.h");
    i=master->numgroups;
    strncpy((groups+i)->newsgroup, group, 191);
    strncpy((groups+i)->server, server->Name, 31);
    (groups+i)->hi = atol(end);
    (groups+i)->lo = atol(begin);
    (groups+i)->mode = mode[0];
    (groups+i)->times = 0;
    master->numgroups++;
    num++;
   }
  }
 }
 qsort(groups, master->numgroups, sizeof(ACTIVE), cmp_active);
 printf("Loaded %d groups, %d total\n", num, master->numgroups);
}

variable_types: struct SERVER { char Name[32]; char Hostname[256]; char Groups[16384]; char Username[64]; char Password[64]; unsigned int Port; unsigned int Timeout; unsigned int Level; enum servertype { type_spool=0, type_xover=1, type_post=2 } ServerType; enum serverpol { policy_single=0, policy_backup=1, policy_balance=2 } Policy; unsigned char ActiveTimes; unsigned char Descriptions; unsigned char SplitList; unsigned int MaxConnections; unsigned int connections; } *

variable_types: sock int

variable_types:
glist
char *

variable_types:
group
char [512]

variable_types:
end
char [11]

variable_types:
begin
char [11]

variable_types:
mode
char [2]

variable_types: num int

variable_types: ng int

return_type: void

user_defined_types: struct SERVER { char Name[32]; char Hostname[256]; char Groups[16384]; char Username[64]; char Password[64]; unsigned int Port; unsigned int Timeout; unsigned int Level; enum servertype ServerType; enum serverpol Policy; unsigned char ActiveTimes; unsigned char Descriptions; unsigned char SplitList; unsigned int MaxConnections; unsigned int connections; }


decompiled_code:
int __fastcall getlist_activetimes(__int64 a1, unsigned int a2)
{
size_t v2; // rax
unsigned int v3; // er12
_QWORD *v5; // rax
char v6; // [rsp+0h] [rbp-328h] BYREF
char nptr[16]; // [rsp+100h] [rbp-228h] BYREF
char src[536]; // [rsp+110h] [rbp-218h] BYREF

qmemcpy(buf, "LIST active.time", 16);
*(_DWORD *)&buf[16] = (_DWORD)&unk_A0D73;
v2 = strlen(buf);
if ( write_socket(a2, buf, v2, *(unsigned int *)(a1 + 16804)) == -1 )
die("Cant write to server");
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read list active.times response");
if ( atoi(buf) != 215 )
die("Invalid response from server: %s", buf);
v3 = 0;
while ( 1 )
{
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read active.times file");
if ( buf[0] == 46 && buf[1] == 13 )
break;
if ( (unsigned int)_isoc99_sscanf(buf, "%511s %15s %255s", src, nptr, &v6) == 3 )
{
v5 = gg(src, 0);
if ( v5 && !v5[2] )
{
v5[2] = atol(nptr);
++v3;
}
}
else
{
info("Invalid active.times entry: %s %d %d", buf, (unsigned int)buf[0], (unsigned int)buf[1]);
}
}
return printf("Loaded active.times for %d groups\n", v3);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, unsigned int a2)
{
size_t v2; // rax
unsigned int v3; // er12
_QWORD *v5; // rax
char v6; // [rsp+0h] [rbp-328h] BYREF
char nptr[16]; // [rsp+100h] [rbp-228h] BYREF
char src[536]; // [rsp+110h] [rbp-218h] BYREF

qmemcpy(buf, "LIST active.time", 16);
*(_DWORD *)&buf[16] = (_DWORD)&unk_A0D73;
v2 = strlen(buf);
if ( write_socket(a2, buf, v2, *(unsigned int *)(a1 + 16804)) == -1 )
die("Cant write to server");
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read list active.times response");
if ( atoi(buf) != 215 )
die("Invalid response from server: %s", buf);
v3 = 0;
while ( 1 )
{
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read active.times file");
if ( buf[0] == 46 && buf[1] == 13 )
break;
if ( (unsigned int)_isoc99_sscanf(buf, "%511s %15s %255s", src, nptr, &v6) == 3 )
{
v5 = func1(src, 0);
if ( v5 && !v5[2] )
{
v5[2] = atol(nptr);
++v3;
}
}
else
{
info("Invalid active.times entry: %s %d %d", buf, (unsigned int)buf[0], (unsigned int)buf[1]);
}
}
return printf("Loaded active.times for %d groups\n", v3);
}

original_code:
void getlist_activetimes(SERVER *server, int sock)
{
 char group[512], time[16], creator[256];
 int num = 0;
 ACTIVE *gr;
 sprintf(buf, "LIST active.times\r\n");
 if ( write_socket(sock, buf, strlen(buf), server->Timeout) == -1 )
  die("Cant write to server");
 if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
  die("Cant read list active.times response");
 if ( atoi(buf) != 215 )
  die("Invalid response from server: %s", buf);
 while ( 1 )
 {
  if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
   die("Cant read active.times file");
  if ( buf[0] == '.' && buf[1] == '\r' )
   break;
  if ( sscanf(buf, "%511s %15s %255s", group, time, creator) != 3 )
  {
   info("Invalid active.times entry: %s %d %d", buf, buf[0], buf[1]);
  }
  else
  {
   if ( (gr=gg(group, 0)) != ((void *)0) )
   {
    if ( gr->times == 0 )
    {
     gr->times = atol(time);
     num++;
    }
   }
  }
 }
 printf("Loaded active.times for %d groups\n", num);
}

canonical_original_code:
void getlist_activetimes(struct SERVER *server, int sock)
{
 char group[512]; char time[16]; char creator[256];
 int num = 0;
 struct ACTIVE *gr;
 sprintf(buf, "LIST active.times\r\n");
 if ( write_socket(sock, buf, strlen(buf), server->Timeout) == -1 )
  die("Cant write to server");
 if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
  die("Cant read list active.times response");
 if ( atoi(buf) != 215 )
  die("Invalid response from server: %s", buf);
 while ( 1 )
 {
  if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
   die("Cant read active.times file");
  if ( buf[0] == '.' && buf[1] == '\r' )
   break;
  if ( sscanf(buf, "%511s %15s %255s", group, time, creator) != 3 )
  {
   info("Invalid active.times entry: %s %d %d", buf, buf[0], buf[1]);
  }
  else
  {
   if ( (gr=gg(group, 0)) != ((void *)0) )
   {
    if ( gr->times == 0 )
    {
     gr->times = atol(time);
     num++;
    }
   }
  }
 }
 printf("Loaded active.times for %d groups\n", num);
}

variable_types:
time
char [16]

variable_types:
creator
char [256]

user_defined_types: struct ACTIVE { unsigned long hi; unsigned long lo; unsigned long times; unsigned long id; char mode; char newsgroup[160]; char server[32]; }

user_defined_types: enum servertype { type_spool=0, type_xover=1, type_post=2 }

user_defined_types: enum serverpol { policy_single=0, policy_backup=1, policy_balance=2 }


decompiled_code:
int __fastcall getlist_newsgroups(__int64 a1, unsigned int a2, const char *a3)
{
size_t v3; // rax
int v4; // er12
unsigned int v5; // ebp
int v7; // er13
__int64 v8; // r14
char v9[512]; // [rsp+0h] [rbp-438h] BYREF
char s[568]; // [rsp+200h] [rbp-238h] BYREF

sprintf(buf, "LIST newsgroups %s\r\n", a3);
v3 = strlen(buf);
if ( write_socket(a2, buf, v3, *(unsigned int *)(a1 + 16804)) == -1 )
die("Cant write to server");
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read list newsgroups response");
if ( atoi(buf) != 215 )
die("Invalid response from server: %s", buf);
v4 = numdescrs;
v5 = 0;
while ( 1 )
{
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read newsgroups file");
if ( buf[0] == 46 && buf[1] == 13 )
break;
if ( (unsigned int)_isoc99_sscanf(buf, "%510s %510[^\r\n]", s, v9) == 2
&& v9[0] != 63
&& !strstr(v9, "Description")
&& !strstr(v9, "description")
&& !getdescr(s, v4) )
{
v7 = numdescrs;
v8 = 2LL * numdescrs;
descriptions[v8] = (__int64)strdup(s);
descriptions[v8 + 1] = (__int64)strdup(v9);
++v5;
numdescrs = v7 + 1;
}
}
return printf("Loaded newsgroups for %d groups\n", v5);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, unsigned int a2, const char *a3)
{
size_t v3; // rax
int v4; // er12
unsigned int v5; // ebp
int v7; // er13
__int64 v8; // r14
char v9[512]; // [rsp+0h] [rbp-438h] BYREF
char s[568]; // [rsp+200h] [rbp-238h] BYREF

sprintf(buf, "LIST newsgroups %s\r\n", a3);
v3 = strlen(buf);
if ( write_socket(a2, buf, v3, *(unsigned int *)(a1 + 16804)) == -1 )
die("Cant write to server");
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read list newsgroups response");
if ( atoi(buf) != 215 )
die("Invalid response from server: %s", buf);
v4 = numdescrs;
v5 = 0;
while ( 1 )
{
if ( !fgetsrn(buf, 0x4000LL, a2) )
die("Cant read newsgroups file");
if ( buf[0] == 46 && buf[1] == 13 )
break;
if ( (unsigned int)_isoc99_sscanf(buf, "%510s %510[^\r\n]", s, v9) == 2
&& v9[0] != 63
&& !strstr(v9, "Description")
&& !strstr(v9, "description")
&& !func2(s, v4) )
{
v7 = numdescrs;
v8 = 2LL * numdescrs;
descriptions[v8] = (__int64)strdup(s);
descriptions[v8 + 1] = (__int64)strdup(v9);
++v5;
numdescrs = v7 + 1;
}
}
return printf("Loaded newsgroups for %d groups\n", v5);
}

original_code:
void getlist_newsgroups(SERVER *server, int sock, char *glist)
{
 char group[512], descr[512];
 int num = 0, nd;
 struct DESCR *dsc;
 sprintf(buf, "LIST newsgroups %s\r\n", glist);
 if ( write_socket(sock, buf, strlen(buf), server->Timeout) == -1 )
  die("Cant write to server");
 if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
  die("Cant read list newsgroups response");
 if ( atoi(buf) != 215 )
  die("Invalid response from server: %s", buf);
 nd = numdescrs;
 while ( 1 )
 {
  if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
   die("Cant read newsgroups file");
  if ( buf[0] == '.' && buf[1] == '\r' )
   break;
  if ( sscanf(buf, "%510s %510[^\r\n]", group, descr) == 2 )
  {
   if ( descr[0] != '?' && strstr(descr, "Description") == ((void *)0) && strstr(descr, "description") == ((void *)0) )
   {
    if ( (dsc=getdescr(group, nd)) == ((void *)0) )
    {
     (descriptions+numdescrs)->newsgroup = strdup(group);
     (descriptions+numdescrs)->description = strdup(descr);
     num++;
     numdescrs++;
    }
   }
  }
 }
 printf("Loaded newsgroups for %d groups\n", num);
}

canonical_original_code:
void getlist_newsgroups(struct SERVER *server, int sock, char *glist)
{
 char group[512]; char descr[512];
 int num = 0; int nd;
 struct DESCR *dsc;
 sprintf(buf, "LIST newsgroups %s\r\n", glist);
 if ( write_socket(sock, buf, strlen(buf), server->Timeout) == -1 )
  die("Cant write to server");
 if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
  die("Cant read list newsgroups response");
 if ( atoi(buf) != 215 )
  die("Invalid response from server: %s", buf);
 nd = numdescrs;
 while ( 1 )
 {
  if ( fgetsrn(buf, 16384, sock) == ((void *)0) )
   die("Cant read newsgroups file");
  if ( buf[0] == '.' && buf[1] == '\r' )
   break;
  if ( sscanf(buf, "%510s %510[^\r\n]", group, descr) == 2 )
  {
   if ( descr[0] != '?' && strstr(descr, "Description") == ((void *)0) && strstr(descr, "description") == ((void *)0) )
   {
    if ( (dsc=getdescr(group, nd)) == ((void *)0) )
    {
     (descriptions+numdescrs)->newsgroup = strdup(group);
     (descriptions+numdescrs)->description = strdup(descr);
     num++;
     numdescrs++;
    }
   }
  }
 }
 printf("Loaded newsgroups for %d groups\n", num);
}

variable_types:
descr
char [512]

variable_types: nd int

variable_types: struct DESCR { char *newsgroup; char *description; } *


decompiled_code:
int __fastcall update_server(const char *a1)
{
__int64 v1; // rbp
unsigned int v2; // er12
size_t v3; // rax
char *v5; // rbx
char v6[16408]; // [rsp+0h] [rbp-4018h] BYREF

if ( (unsigned int)connect_groupserver(&uclient, a1) - 1 <= 1 )
die("Failed to connect to server %s", a1);
v1 = *((_QWORD *)&uclient + 5);
v2 = *((_DWORD *)&uclient + 8);
info("Connected to server: %s:%d", (const char *)(v1 + 32), *(unsigned int *)(v1 + 16800));
if ( *(_BYTE *)(v1 + 16822) == 1 )
{
strncpy(v6, (const char *)(v1 + 288), 0x4000uLL);
v5 = strtok(v6, ",");
do
{
getlist_active((char *)v1, v2, v5);
if ( *(_BYTE *)(v1 + 16821) )
getlist_newsgroups(v1, v2, v5);
v5 = strtok(0LL, ",");
}
while ( v5 );
}
else
{
getlist_active((char *)v1, v2, (const char *)(v1 + 288));
if ( *(_BYTE *)(v1 + 16821) )
getlist_newsgroups(v1, v2, (const char *)(v1 + 288));
}
if ( *(_BYTE *)(v1 + 16820) )
getlist_activetimes(v1, v2);
strcpy(buf, "QUIT\r\n");
v3 = strlen(buf);
if ( write_socket(v2, buf, v3, *(unsigned int *)(v1 + 16804)) == -1 )
die("Cant write to server");
*((_BYTE *)&uclient + 712) &= 0xFEu;
return close(v2);
}

canonical_decompiled_code:
int __fastcall func6(const char *a1)
{
__int64 v1; // rbp
unsigned int v2; // er12
size_t v3; // rax
char *v5; // rbx
char v6[16408]; // [rsp+0h] [rbp-4018h] BYREF

if ( (unsigned int)connect_groupserver(&uclient, a1) - 1 <= 1 )
die("Failed to connect to server %s", a1);
v1 = *((_QWORD *)&uclient + 5);
v2 = *((_DWORD *)&uclient + 8);
info("Connected to server: %s:%d", (const char *)(v1 + 32), *(unsigned int *)(v1 + 16800));
if ( *(_BYTE *)(v1 + 16822) == 1 )
{
strncpy(v6, (const char *)(v1 + 288), 0x4000uLL);
v5 = strtok(v6, ",");
do
{
func3((char *)v1, v2, v5);
if ( *(_BYTE *)(v1 + 16821) )
func5(v1, v2, v5);
v5 = strtok(0LL, ",");
}
while ( v5 );
}
else
{
func3((char *)v1, v2, (const char *)(v1 + 288));
if ( *(_BYTE *)(v1 + 16821) )
func5(v1, v2, (const char *)(v1 + 288));
}
if ( *(_BYTE *)(v1 + 16820) )
func4(v1, v2);
strcpy(buf, "QUIT\r\n");
v3 = strlen(buf);
if ( write_socket(v2, buf, v3, *(unsigned int *)(v1 + 16804)) == -1 )
die("Cant write to server");
*((_BYTE *)&uclient + 712) &= 0xFEu;
return close(v2);
}

original_code:
void update_server(SERVER *svr)
{
 int sock;
 char *p;
 char gbuf[16384];
 SERVER *server;
 server = svr;
 int c = connect_groupserver(&uclient, server->Name);
 if ( c == CONNECT_DOWN || c == CONNECT_ERR )
  die("Failed to connect to server %s", server->Name);
 server = uclient.groupserver;
 sock = uclient.serversock;
 info("Connected to server: %s:%d", server->Hostname, server->Port);
 if ( server->SplitList == 1 )
 {
  strncpy(gbuf, server->Groups, 16384);
  p = strtok(gbuf, ",");
  do {
   getlist_active(server, sock, p);
   if ( server->Descriptions )
    getlist_newsgroups(server, sock, p);
  }
  while( (p = strtok(((void *)0), ",")) );
 }
 else
 {
  getlist_active(server, sock, server->Groups);
  if ( server->Descriptions )
   getlist_newsgroups(server, sock, server->Groups);
 }
 if ( server->ActiveTimes )
  getlist_activetimes(server, sock);
 sprintf(buf, "QUIT\r\n");
 if ( write_socket(sock, buf, strlen(buf), server->Timeout) == -1 )
  die("Cant write to server");
 uclient.connected = 0;
 close(sock);
}

canonical_original_code:
void update_server(struct SERVER *svr)
{
 int sock;
 char *p;
 char gbuf[16384];
 struct SERVER *server;
 server = svr;
 int c = connect_groupserver(&uclient, server->Name);
 if ( c == CONNECT_DOWN || c == CONNECT_ERR )
  die("Failed to connect to server %s", server->Name);
 server = uclient.groupserver;
 sock = uclient.serversock;
 info("Connected to server: %s:%d", server->Hostname, server->Port);
 if ( server->SplitList == 1 )
 {
  strncpy(gbuf, server->Groups, 16384);
  p = strtok(gbuf, ",");
  do {
   getlist_active(server, sock, p);
   if ( server->Descriptions )
    getlist_newsgroups(server, sock, p);
  }
  while( (p = strtok(((void *)0), ",")) );
 }
 else
 {
  getlist_active(server, sock, server->Groups);
  if ( server->Descriptions )
   getlist_newsgroups(server, sock, server->Groups);
 }
 if ( server->ActiveTimes )
  getlist_activetimes(server, sock);
 sprintf(buf, "QUIT\r\n");
 if ( write_socket(sock, buf, strlen(buf), server->Timeout) == -1 )
  die("Cant write to server");
 uclient.connected = 0;
 close(sock);
}

variable_types:
p
char *

variable_types:
gbuf
char [16384]

variable_types: c int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // ebp
__int64 v5; // rdi
__int64 v6; // [rsp+0h] [rbp-38h] BYREF

tgetopt(argc, argv, envp);
if ( (unsigned int)toptset(104LL) )
{
printf(
"Usage: %s [options]\n"
" -c, --config CONFIGFILE\tSpecify configfile instead of searching for it.\n"
" -h, --help \tCommand usage.\n",
*argv);
exit(0);
}
if ( (unsigned int)toptset(99LL) )
config_file = (char *)((__int64 (__fastcall *)(__int64))toptargs)(99LL);
syslog_open("updategroups", 1LL, 56LL);
master = memmap(33730968LL);
if ( !master )
die("Can't allocate master memory");
groups = (void *)memmap(29696000LL);
if ( !groups )
die("Can't allocate groups memory");
loadconfig();
load_servers();
v3 = *(_DWORD *)(master + 28LL) - 2;
if ( v3 >= 0 )
{
v4 = -1;
do
{
v5 = *(_QWORD *)(master + 8LL * v3 + 11731056);
if ( *(_DWORD *)(v5 + 16808) != v4 )
{
v4 = *(_DWORD *)(v5 + 16808);
update_server((const char *)v5);
}
--v3;
}
while ( v3 != -1 );
}
write_active();
write_newsgroups();
memunmap(master, 33730968LL);
memunmap(groups, 29696000LL);
syslog_close(&v6);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // ebp
__int64 v5; // rdi
__int64 v6; // [rsp+0h] [rbp-38h] BYREF

tgetopt(argc, argv, envp);
if ( (unsigned int)toptset(104LL) )
{
printf(
"Usage: %s [options]\n"
" -c, --config CONFIGFILE\tSpecify configfile instead of searching for it.\n"
" -h, --help \tCommand usage.\n",
*argv);
exit(0);
}
if ( (unsigned int)toptset(99LL) )
config_file = (char *)((__int64 (__fastcall *)(__int64))toptargs)(99LL);
syslog_open("updategroups", 1LL, 56LL);
master = memmap(33730968LL);
if ( !master )
die("Can't allocate master memory");
groups = (void *)memmap(29696000LL);
if ( !groups )
die("Can't allocate groups memory");
loadconfig();
load_servers();
v3 = *(_DWORD *)(master + 28LL) - 2;
if ( v3 >= 0 )
{
v4 = -1;
do
{
v5 = *(_QWORD *)(master + 8LL * v3 + 11731056);
if ( *(_DWORD *)(v5 + 16808) != v4 )
{
v4 = *(_DWORD *)(v5 + 16808);
func6((const char *)v5);
}
--v3;
}
while ( v3 != -1 );
}
func7();
func8();
memunmap(master, 33730968LL);
memunmap(groups, 29696000LL);
syslog_close(&v6);
exit(0);
}

original_code:
int main(int argc, char **argv)
{
 int i, cur;
 tgetopt(argc, argv);
 if ( toptset('h') )
 {
  printf(usage, argv[0]);
  exit(0);
 }
 if ( toptset('c') )
  config_file = toptargs('c');
 syslog_open("updategroups", 0x01, (7<<3));
 if ( (master = memmap(sizeof(MASTER))) == ((void *)0) )
  die("Can't allocate master memory");
 if ( (groups = memmap(sizeof(ACTIVE) * 128000)) == ((void *)0) )
  die("Can't allocate groups memory");
 loadconfig();
 load_servers();
 cur = -1;
 for (i=master->numservers-2; i>=0; i-- )
  if ( (master->lservers[i])->Level != cur )
  {
   cur = (master->lservers[i])->Level;
   update_server( master->lservers[i] );
  }
 write_active();
 write_newsgroups();
 memunmap(master, sizeof(MASTER));
 memunmap(groups, sizeof(ACTIVE) * 128000);
 syslog_close();
 exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i; int cur;
 tgetopt(argc, argv);
 if ( toptset('h') )
 {
  printf(usage, argv[0]);
  exit(0);
 }
 if ( toptset('c') )
  config_file = toptargs('c');
 syslog_open("updategroups", 0x01, (7<<3));
 if ( (master = memmap(sizeof(MASTER))) == ((void *)0) )
  die("Can't allocate master memory");
 if ( (groups = memmap(sizeof(ACTIVE) * 128000)) == ((void *)0) )
  die("Can't allocate groups memory");
 loadconfig();
 load_servers();
 cur = -1;
 for (i=master->numservers-2; i>=0; i-- )
  if ( (master->lservers[i])->Level != cur )
  {
   cur = (master->lservers[i])->Level;
   update_server( master->lservers[i] );
  }
 write_active();
 write_newsgroups();
 memunmap(master, sizeof(MASTER));
 memunmap(groups, sizeof(ACTIVE) * 128000);
 syslog_close();
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: cur int


decompiled_code:
__int64 __fastcall get_facility(char *s1)
{
const char *v1; // rsi
char **v2; // rbx

v1 = facilitynames;
if ( !facilitynames )
return 0xFFFFFFFFLL;
v2 = &facilitynames;
while ( strcasecmp(s1, v1) )
{
v2 += 2;
v1 = *v2;
if ( !*v2 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)v2 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
const char *v1; // rsi
char **v2; // rbx

v1 = facilitynames;
if ( !facilitynames )
return 0xFFFFFFFFLL;
v2 = &facilitynames;
while ( strcasecmp(s1, v1) )
{
v2 += 2;
v1 = *v2;
if ( !*v2 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)v2 + 2);
}

original_code:
int get_facility(char *name) {
    CODE *f;
    for (f = facilitynames; f->c_name; f++)
 if ( strcasecmp(name, f->c_name) == 0 )
        return (f->c_val);
    return (-1);
}

canonical_original_code:
int get_facility(char *name) {
    struct _code *f;
    for (f = facilitynames; f->c_name; f++)
 if ( strcasecmp(name, f->c_name) == 0 )
        return (f->c_val);
    return (-1);
}

variable_types:
name
char *

variable_types: struct _code { char *c_name; int c_val; } *


decompiled_code:
__int64 __fastcall get_priority(char *s1)
{
const char *v1; // rsi
char **v2; // rbx

v1 = prioritynames;
if ( !prioritynames )
return 0xFFFFFFFFLL;
v2 = &prioritynames;
while ( strcasecmp(s1, v1) )
{
v2 += 2;
v1 = *v2;
if ( !*v2 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)v2 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
const char *v1; // rsi
char **v2; // rbx

v1 = prioritynames;
if ( !prioritynames )
return 0xFFFFFFFFLL;
v2 = &prioritynames;
while ( strcasecmp(s1, v1) )
{
v2 += 2;
v1 = *v2;
if ( !*v2 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)v2 + 2);
}

original_code:
int get_priority(char *name) {
    CODE *p;
    for (p = prioritynames; p->c_name; p++)
 if ( strcasecmp(name, p->c_name) == 0 )
        return (p->c_val);
    return (-1);
}

canonical_original_code:
int get_priority(char *name) {
    struct _code *p;
    for (p = prioritynames; p->c_name; p++)
 if ( strcasecmp(name, p->c_name) == 0 )
        return (p->c_val);
    return (-1);
}

user_defined_types: struct _code { char *c_name; int c_val; }


memmap

decompiled_code:
void *__fastcall memmap(int a1)
{
void *result; // rax

result = mmap(0LL, a1, 3, 33, -1, 0LL);
if ( result == (void *)-1LL )
result = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
void *result; // rax

result = mmap(0LL, a1, 3, 33, -1, 0LL);
if ( result == (void *)-1LL )
result = 0LL;
return result;
}

original_code:
void *memmap(int size)
{
    caddr_t ptr;
    int fd = -1;
    ptr = mmap(((void *)0), size, 0x1 | 0x2,
                           0x20 | 0x01,
                           fd, 0);
    if (ptr == ((void *) -1))
        return ((void *)0);
    return ptr;
}

canonical_original_code:
void *memmap(int size)
{
    char *ptr;
    int fd = -1;
    ptr = mmap(((void *)0), size, 0x1 | 0x2,
                           0x20 | 0x01,
                           fd, 0);
    if (ptr == ((void *) -1))
        return ((void *)0);
    return ptr;
}

variable_types: size int

variable_types:
ptr
char *

variable_types: fd int

return_type: void *


memunmap

decompiled_code:
int __fastcall memunmap(void *a1, int a2)
{
return munmap(a1, a2);
}

canonical_decompiled_code:
int __fastcall func1(void *a1, int a2)
{
return munmap(a1, a2);
}

original_code:
int memunmap(void *ptr, int size) {
    return munmap(ptr,size);
}

variable_types:
ptr
void *


decompiled_code:
int __fastcall semlock_init(key_t a1)
{
return semget(a1, 1, 950);
}

canonical_decompiled_code:
int __fastcall func0(key_t a1)
{
return semget(a1, 1, 950);
}

original_code:
int semlock_init (key_t SEMKEY)
{
 return semget (SEMKEY, 1, 01000 | 0666);
}

canonical_original_code:
int semlock_init(int SEMKEY)
{
 return semget (SEMKEY, 1, 01000 | 0666);
}

variable_types: SEMKEY int


decompiled_code:
__int64 __fastcall semlock_lock(int semid)
{
__int64 result; // rax
struct sembuf sops; // [rsp+4h] [rbp-14h] BYREF
__int16 v3; // [rsp+Ah] [rbp-Eh]
__int16 v4; // [rsp+Ch] [rbp-Ch]
__int16 v5; // [rsp+Eh] [rbp-Ah]

sops.sem_num = 0;
sops.sem_op = 0;
sops.sem_flg = 4096;
v3 = 0;
v4 = 1;
v5 = 4096;
while ( semop(semid, &sops, 2uLL) < 0 && *_errno_location() == 4 )
;
result = master;
++*(_QWORD *)(master + 72LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int semid)
{
__int64 result; // rax
struct sembuf sops; // [rsp+4h] [rbp-14h] BYREF
__int16 v3; // [rsp+Ah] [rbp-Eh]
__int16 v4; // [rsp+Ch] [rbp-Ch]
__int16 v5; // [rsp+Eh] [rbp-Ah]

sops.sem_num = 0;
sops.sem_op = 0;
sops.sem_flg = 4096;
v3 = 0;
v4 = 1;
v5 = 4096;
while ( semop(semid, &sops, 2uLL) < 0 && *_errno_location() == 4 )
;
result = master;
++*(_QWORD *)(master + 72LL);
return result;
}

original_code:
void semlock_lock(int semid)
{
 struct sembuf sops[2];
 sops[0].sem_num = 0;
 sops[0].sem_op = 0;
 sops[0].sem_flg = 0x1000;
 sops[1].sem_num = 0;
 sops[1].sem_op = 1;
 sops[1].sem_flg = 0x1000;
 int r;
 do {
  r = semop(semid, sops, 2);
 } while ( r < 0 && (*__errno_location ()) == 4 );
        master->nrlocks++;
}

variable_types: semid int

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; } [2]

variable_types: r int


decompiled_code:
__int64 __fastcall semlock_unlock(int semid)
{
__int64 result; // rax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = -1;
sops.sem_flg = 4096;
while ( semop(semid, &sops, 1uLL) < 0 && *_errno_location() == 4 )
;
result = master;
++*(_QWORD *)(master + 80LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int semid)
{
__int64 result; // rax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = -1;
sops.sem_flg = 4096;
while ( semop(semid, &sops, 1uLL) < 0 && *_errno_location() == 4 )
;
result = master;
++*(_QWORD *)(master + 80LL);
return result;
}

original_code:
void semlock_unlock(int semid)
{
 struct sembuf sops[1];
 sops[0].sem_num = 0;
 sops[0].sem_op = -1;
 sops[0].sem_flg = 0x1000;
 int r;
 do {
  r = semop(semid, sops, 1);
 } while ( r < 0 && (*__errno_location ()) == 4 );
        master->nrunlocks++;
}

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; } [1]


decompiled_code:
int __fastcall semlock_close(int a1)
{
return semctl(a1, 0, 0);
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
return semctl(a1, 0, 0);
}

original_code:
void semlock_close(int semid)
{
 semctl(semid, 0, 0);
}


decompiled_code:
void __fastcall free_authresult(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi

free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 4));
v2 = (void *)*((_QWORD *)ptr + 13);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 9);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 8);
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 14);
if ( v5 )
free(v5);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi

free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 4));
v2 = (void *)*((_QWORD *)ptr + 13);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 9);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 8);
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 14);
if ( v5 )
free(v5);
free(ptr);
}

original_code:
void free_authresult(AUTHRESULT *a)
{
 free(a->username);
 free(a->password);
 free(a->hostname);
 if ( a->logname != ((void *)0) ) free(a->logname);
 if ( a->profile != ((void *)0) ) free(a->profile);
 if ( a->message != ((void *)0) ) free(a->message);
 if ( a->readpat != ((void *)0) ) free(a->readpat);
 free(a);
}

canonical_original_code:
void free_authresult(struct AUTHRESULT *a)
{
 free(a->username);
 free(a->password);
 free(a->hostname);
 if ( a->logname != ((void *)0) ) free(a->logname);
 if ( a->profile != ((void *)0) ) free(a->profile);
 if ( a->message != ((void *)0) ) free(a->message);
 if ( a->readpat != ((void *)0) ) free(a->readpat);
 free(a);
}

variable_types: struct AUTHRESULT { char *username; char *password; char *username_s; int port; char *hostname; struct in_addr { unsigned int s_addr; } in_addr; struct ARGS { char name[256]; char args[256]; } *args; int numargs; unsigned char authenticated; char *message; char *profile; unsigned char posting; unsigned long long bytes; int userkbit; char *logname; char *readpat; char *postpat; int timeleft; unsigned char overquota; unsigned char disabled; char *posthost; char *postabuse; char *postorg; } *

user_defined_types: struct AUTHRESULT { char *username; char *password; char *username_s; int port; char *hostname; struct in_addr in_addr; struct ARGS *args; int numargs; unsigned char authenticated; char *message; char *profile; unsigned char posting; unsigned long long bytes; int userkbit; char *logname; char *readpat; char *postpat; int timeleft; unsigned char overquota; unsigned char disabled; char *posthost; char *postabuse; char *postorg; }


decompiled_code:
char *__fastcall find_auth_mod(char *s1)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcmp(s1, (&authmap)[2 * v1]) )
{
if ( ++v1 == 11 )
return 0LL;
}
return (&authmap)[2 * (int)v1 + 1];
}

canonical_decompiled_code:
char *__fastcall func1(char *s1)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcmp(s1, (&authmap)[2 * v1]) )
{
if ( ++v1 == 11 )
return 0LL;
}
return (&authmap)[2 * (int)v1 + 1];
}

original_code:
void (*find_auth_mod(char *name))()
{
 int i;
 for(i = 0; i < sizeof(authmap) / sizeof(authmap[0]); i++)
 {
  if (strcmp(name, authmap[i].name) == 0)
   return authmap[i].ptr;
 }
 return ((void *)0);
}


decompiled_code:
char *__fastcall find_acct_mod(char *s1)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcmp(s1, (&acctmap)[2 * v1]) )
{
if ( ++v1 == 10 )
return 0LL;
}
return (&acctmap)[2 * (int)v1 + 1];
}

canonical_decompiled_code:
char *__fastcall func2(char *s1)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcmp(s1, (&acctmap)[2 * v1]) )
{
if ( ++v1 == 10 )
return 0LL;
}
return (&acctmap)[2 * (int)v1 + 1];
}

original_code:
void (*find_acct_mod(char *name))()
{
 int i;
 for(i = 0; i < sizeof(acctmap) / sizeof(acctmap[0]); i++)
 {
  if (strcmp(name, acctmap[i].name) == 0)
   return acctmap[i].ptr;
 }
 return ((void *)0);
}


decompiled_code:
void __fastcall syslog_open(char *ident, int option, int facility)
{
__m128i v4[3]; // [rsp+0h] [rbp-38h] BYREF

syslog_close(v4);
openlog(ident, option, facility);
syslog_status_current = 1;
off_E8 = ident;
LODWORD(qword_F0) = option;
HIDWORD(qword_F0) = facility;
}

canonical_decompiled_code:
void __fastcall func0(char *ident, int option, int facility)
{
__m128i v4[3]; // [rsp+0h] [rbp-38h] BYREF

syslog_close(v4);
openlog(ident, option, facility);
syslog_status_current = 1;
off_E8 = ident;
LODWORD(qword_F0) = option;
HIDWORD(qword_F0) = facility;
}

original_code:
void syslog_open (const char *prefix, int option, int default_facility)
{
 syslog_close ();
 openlog (prefix, option, default_facility);
 syslog_status_current.is_open = 1;
 syslog_status_current.prefix = prefix;
 syslog_status_current.option = option;
 syslog_status_current.default_facility = default_facility;
}

canonical_original_code:
void syslog_open(char *prefix, int option, int default_facility)
{
 syslog_close ();
 openlog (prefix, option, default_facility);
 syslog_status_current.is_open = 1;
 syslog_status_current.prefix = prefix;
 syslog_status_current.option = option;
 syslog_status_current.default_facility = default_facility;
}

variable_types:
prefix
char *

variable_types: option int


decompiled_code:
void __fastcall syslog_status_set(int a1, int a2, int a3, int a4, int a5, int a6, __int128 a7, __int64 option)
{
if ( (_DWORD)a7 )
{
syslog_open(*((char **)&a7 + 1), option, SHIDWORD(option));
}
else
{
*(__m128i *)&syslog_status_current = _mm_loadu_si128((const __m128i *)&a7);
qword_F0 = option;
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2, int a3, int a4, int a5, int a6, __int128 a7, __int64 option)
{
if ( (_DWORD)a7 )
{
func0(*((char **)&a7 + 1), option, SHIDWORD(option));
}
else
{
*(__m128i *)&syslog_status_current = _mm_loadu_si128((const __m128i *)&a7);
qword_F0 = option;
}
}

original_code:
void syslog_status_set (syslog_status sst)
{
 if (sst.is_open)
  syslog_open (sst.prefix, sst.option, sst.default_facility);
 else
  syslog_status_current = sst;
}

canonical_original_code:
void syslog_status_set(struct syslog_status sst)
{
 if (sst.is_open)
  syslog_open (sst.prefix, sst.option, sst.default_facility);
 else
  syslog_status_current = sst;
}

variable_types: struct syslog_status { int is_open; char *prefix; int option; int default_facility; }


timeformatok

decompiled_code:
_BOOL8 __fastcall timeformatok(_BYTE *a1)
{
_BOOL8 result; // rax
char v2; // dl

result = 0LL;
if ( a1[2] == 58 )
{
v2 = a1[3];
if ( v2 < 0 )
result = 0LL;
else
result = !((v2 > 9) & (a1[4] >> 7));
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_BYTE *a1)
{
_BOOL8 result; // rax
char v2; // dl

result = 0LL;
if ( a1[2] == 58 )
{
v2 = a1[3];
if ( v2 < 0 )
result = 0LL;
else
result = !((v2 > 9) & (a1[4] >> 7));
}
return result;
}

original_code:
static unsigned char timeformatok(const char *time)
{
    if (
        (time[0]<0 && time[0]>2) ||
        (time[1]<0 && time[1]>9) ||
        (time[2] != ':') ||
        (time[3]<0 && time[2]>5) ||
        (time[4]<0 && time[3]>9)
       ) return 0;
    return 1;
}

canonical_original_code:
static unsigned char timeformatok(char *time)
{
    if (
        (time[0]<0 && time[0]>2) ||
        (time[1]<0 && time[1]>9) ||
        (time[2] != ':') ||
        (time[3]<0 && time[2]>5) ||
        (time[4]<0 && time[3]>9)
       ) return 0;
    return 1;
}

variable_types:
time
char *

return_type: unsigned char


timebetweenms

original_code:
static unsigned char timebetweenms(char *starttime, char *endtime, int nowhr, int nowmin, int *timeleft)
{
    int starthr = atoi(starttime);
    int startmin = atoi(starttime+3);
    int startsec = (starthr*60) + startmin;
    int endhr = atoi(endtime);
    int endmin = atoi(endtime+3);
    int endsec = (endhr*60) + endmin;
    int nowsec = (nowhr*60) + nowmin;
    if ( startsec > endsec ) {
        endsec += daylen;
        if ( nowsec < startsec ) {
            nowsec += daylen;
        }
    }
    if ( startsec <= nowsec && endsec >= nowsec ) {
        *timeleft = (endsec - nowsec) * 60;
        if ( *timeleft == 0 ) *timeleft = 1;
        return 1;
    } else {
        if ( startsec >= nowsec ) {
            *timeleft = (startsec - nowsec) * 60;
        } else {
            *timeleft = (daylen - nowsec + startsec) * 60;
        }
        if ( *timeleft == 0 ) *timeleft = 1;
        return 0;
    }
}

variable_types:
starttime
char *

variable_types:
endtime
char *

variable_types: nowhr int

variable_types: nowmin int

variable_types:
timeleft
int *

variable_types: starthr int

variable_types: startmin int

variable_types: startsec int

variable_types: endhr int

variable_types: endmin int

variable_types: endsec int

variable_types: nowsec int


timebetween

decompiled_code:
__int64 __fastcall timebetween(char *a1, char *a2, time_t a3, int *a4)
{
__int64 result; // rax
struct tm *v6; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = a3;
result = timeformatok(a1);
if ( (_BYTE)result )
{
result = timeformatok(a2);
if ( (_BYTE)result )
{
v6 = localtime(&timer);
if ( v6 )
{
result = timebetweenms(a1, a2, v6->tm_hour, v6->tm_min, a4);
}
else
{
syslog(3, "Can't localtime()");
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, char *a2, time_t a3, int *a4)
{
__int64 result; // rax
struct tm *v6; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = a3;
result = func0(a1);
if ( (_BYTE)result )
{
result = func0(a2);
if ( (_BYTE)result )
{
v6 = localtime(&timer);
if ( v6 )
{
result = func1(a1, a2, v6->tm_hour, v6->tm_min, a4);
}
else
{
syslog(3, "Can't localtime()");
result = 0LL;
}
}
}
return result;
}

original_code:
unsigned char timebetween(char *starttime, char *endtime, time_t now, int *timeleft)
{
    if ( ! (timeformatok(starttime) && timeformatok(endtime)) )
        return 0;
    struct tm *tmp;
    tmp = localtime(&now);
    if ( tmp == ((void *)0) ) {
        syslog(3, "Can't localtime()");
        return 0;
    }
    return timebetweenms(starttime, endtime, tmp->tm_hour, tmp->tm_min, timeleft);
}

canonical_original_code:
unsigned char timebetween(char *starttime, char *endtime, long now, int *timeleft)
{
    if ( ! (timeformatok(starttime) && timeformatok(endtime)) )
        return 0;
    struct tm *tmp;
    tmp = localtime(&now);
    if ( tmp == ((void *)0) ) {
        syslog(3, "Can't localtime()");
        return 0;
    }
    return timebetweenms(starttime, endtime, tmp->tm_hour, tmp->tm_min, timeleft);
}

variable_types: now long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
int test_timebetween()
{
unsigned int i; // ebp
unsigned int j; // ebx
unsigned int k; // ebp
unsigned int l; // ebx
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

puts("Starting timebetween test.");
if ( !timeformatok("00:00") )
puts("00:00 NOT OK");
if ( !timeformatok("23:59") )
puts("23:59 NOT OK");
if ( timeformatok("53:92") )
puts("53:92 NOT OK");
puts("Testing between 03:00-19:00");
for ( i = 0; i != 24; ++i )
{
for ( j = 0; j != 60; j += 5 )
{
if ( (unsigned __int8)timebetweenms("03:00", "19:00", i, j, v5) )
printf("hour: %.2d:%.2d BETWEEN left %d\n", i, j, (unsigned int)v5[0]);
else
printf("hour: %.2d:%.2d OUTSIDE left %d\n", i, j, (unsigned int)v5[0]);
}
}
puts("Testing between 20:00-07:00");
for ( k = 0; k != 24; ++k )
{
for ( l = 0; l != 60; l += 5 )
{
if ( (unsigned __int8)timebetweenms("10:25", "10:45", k, l, v5) )
printf("hour: %.2d:%.2d BETWEEN left %d\n", k, l, (unsigned int)v5[0]);
else
printf("hour: %.2d:%.2d OUTSIDE left %d\n", k, l, (unsigned int)v5[0]);
}
}
return puts("Timebetween test finished.");
}

canonical_decompiled_code:
int func3()
{
unsigned int i; // ebp
unsigned int j; // ebx
unsigned int k; // ebp
unsigned int l; // ebx
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

puts("Starting timebetween test.");
if ( !func0("00:00") )
puts("00:00 NOT OK");
if ( !func0("23:59") )
puts("23:59 NOT OK");
if ( func0("53:92") )
puts("53:92 NOT OK");
puts("Testing between 03:00-19:00");
for ( i = 0; i != 24; ++i )
{
for ( j = 0; j != 60; j += 5 )
{
if ( (unsigned __int8)func1("03:00", "19:00", i, j, v5) )
printf("hour: %.2d:%.2d BETWEEN left %d\n", i, j, (unsigned int)v5[0]);
else
printf("hour: %.2d:%.2d OUTSIDE left %d\n", i, j, (unsigned int)v5[0]);
}
}
puts("Testing between 20:00-07:00");
for ( k = 0; k != 24; ++k )
{
for ( l = 0; l != 60; l += 5 )
{
if ( (unsigned __int8)func1("10:25", "10:45", k, l, v5) )
printf("hour: %.2d:%.2d BETWEEN left %d\n", k, l, (unsigned int)v5[0]);
else
printf("hour: %.2d:%.2d OUTSIDE left %d\n", k, l, (unsigned int)v5[0]);
}
}
return puts("Timebetween test finished.");
}

original_code:
void test_timebetween(void)
{
    printf("Starting timebetween test.\n");
    if ( ! timeformatok("00:00") )
        printf("00:00 NOT OK\n");
    if ( ! timeformatok("23:59") )
        printf("23:59 NOT OK\n");
    if ( timeformatok("53:92") )
        printf("53:92 NOT OK\n");
    int left;
    char * start1 = "03:00";
    char * end1 = "19:00";
    printf("Testing between 03:00-19:00\n");
    for(int i=0; i<24; i++) {
      for(int j=0; j<60; j+=5) {
        if ( timebetweenms(start1, end1, i, j, &left) )
            printf("hour: %.2d:%.2d BETWEEN left %d\n", i, j, left);
        else
            printf("hour: %.2d:%.2d OUTSIDE left %d\n", i, j, left);
      }
    }
    char * start2 = "10:25";
    char * end2 = "10:45";
    printf("Testing between 20:00-07:00\n");
    for(int i=0; i<24; i++) {
      for(int j=0; j<60; j+=5) {
        if ( timebetweenms(start2, end2, i, j, &left) )
            printf("hour: %.2d:%.2d BETWEEN left %d\n", i, j, left);
        else
            printf("hour: %.2d:%.2d OUTSIDE left %d\n", i, j, left);
      }
    }
    printf("Timebetween test finished.\n");
}

canonical_original_code:
void test_timebetween()
{
    printf("Starting timebetween test.\n");
    if ( ! timeformatok("00:00") )
        printf("00:00 NOT OK\n");
    if ( ! timeformatok("23:59") )
        printf("23:59 NOT OK\n");
    if ( timeformatok("53:92") )
        printf("53:92 NOT OK\n");
    int left;
    char *start1 = "03:00";
    char *end1 = "19:00";
    printf("Testing between 03:00-19:00\n");
    for(int i = 0; i<24; i++) {
      for(int j = 0; j<60; j+=5) {
        if ( timebetweenms(start1, end1, i, j, &left) )
            printf("hour: %.2d:%.2d BETWEEN left %d\n", i, j, left);
        else
            printf("hour: %.2d:%.2d OUTSIDE left %d\n", i, j, left);
      }
    }
    char *start2 = "10:25";
    char *end2 = "10:45";
    printf("Testing between 20:00-07:00\n");
    for(int i = 0; i<24; i++) {
      for(int j = 0; j<60; j+=5) {
        if ( timebetweenms(start2, end2, i, j, &left) )
            printf("hour: %.2d:%.2d BETWEEN left %d\n", i, j, left);
        else
            printf("hour: %.2d:%.2d OUTSIDE left %d\n", i, j, left);
      }
    }
    printf("Timebetween test finished.\n");
}

variable_types: left int

variable_types: i int

variable_types: j int


decompiled_code:
void __fastcall free_hlist(void *ptr)
{
void *v2; // rdi

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

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi

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

original_code:
void free_hlist(struct _hlist *h)
{
        struct _hlist *h2 = h;
        struct _hlist *h3 = ((void *)0);
        do
        {
                free(h2->val);
                free(h2->hdr);
                h3 = h2;
                h2 = h2->next;
                free(h3);
        }
        while( h2 != ((void *)0) );
}

variable_types: struct _hlist { char *hdr; char *val; struct _hlist *next; } *


decompiled_code:
__int64 __fastcall hlist_get_value(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = a1;
result = a1;
if ( a1 )
{
while ( strcasecmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return 0LL;
}
result = *(_QWORD *)(v2 + 8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = a1;
result = a1;
if ( a1 )
{
while ( strcasecmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return 0LL;
}
result = *(_QWORD *)(v2 + 8);
}
return result;
}

original_code:
char * hlist_get_value(struct _hlist *first, char *hdr)
{
 struct _hlist *i = first;
 while ( i != ((void *)0) && strcasecmp(i->hdr, hdr) )
  i = i->next;
 if ( i == ((void *)0) )
  return ((void *)0);
 return i->val;
}

canonical_original_code:
char *hlist_get_value(struct _hlist *first, char *hdr)
{
 struct _hlist *i = first;
 while ( i != ((void *)0) && strcasecmp(i->hdr, hdr) )
  i = i->next;
 if ( i == ((void *)0) )
  return ((void *)0);
 return i->val;
}

variable_types:
hdr
char *

return_type: char *

user_defined_types: struct _hlist { char *hdr; char *val; struct _hlist *next; }


decompiled_code:
__int64 __fastcall hlist_replace_value(__int64 a1, const char *a2, const char *a3)
{
__int64 v3; // rbx
__int64 result; // rax
char *v6; // rax

v3 = a1;
result = a1;
if ( a1 )
{
while ( strcasecmp(*(const char **)v3, a2) )
{
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
return 0LL;
}
free(*(void **)(v3 + 8));
v6 = strdup(a3);
*(_QWORD *)(v3 + 8) = v6;
if ( !v6 )
syslog(3, "Out of memory for hlist replace");
result = *(_QWORD *)(v3 + 8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, const char *a3)
{
__int64 v3; // rbx
__int64 result; // rax
char *v6; // rax

v3 = a1;
result = a1;
if ( a1 )
{
while ( strcasecmp(*(const char **)v3, a2) )
{
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
return 0LL;
}
free(*(void **)(v3 + 8));
v6 = strdup(a3);
*(_QWORD *)(v3 + 8) = v6;
if ( !v6 )
syslog(3, "Out of memory for hlist replace");
result = *(_QWORD *)(v3 + 8);
}
return result;
}

original_code:
char * hlist_replace_value(struct _hlist *first, char *hdr, char *replace)
{
 struct _hlist *i = first;
 while ( i != ((void *)0) && strcasecmp(i->hdr, hdr) )
  i = i->next;
 if ( i == ((void *)0) )
  return ((void *)0);
 free(i->val);
 i->val = strdup(replace);
 if ( i->val == ((void *)0) )
  syslog(3, "Out of memory for hlist replace");
 return i->val;
}

canonical_original_code:
char *hlist_replace_value(struct _hlist *first, char *hdr, char *replace)
{
 struct _hlist *i = first;
 while ( i != ((void *)0) && strcasecmp(i->hdr, hdr) )
  i = i->next;
 if ( i == ((void *)0) )
  return ((void *)0);
 free(i->val);
 i->val = strdup(replace);
 if ( i->val == ((void *)0) )
  syslog(3, "Out of memory for hlist replace");
 return i->val;
}

variable_types:
replace
char *


decompiled_code:
__int64 __fastcall password_callback(char *dest, int a2)
{
size_t v2; // rax
unsigned int v3; // edx

v2 = strlen(ssl_password);
v3 = 0;
if ( a2 >= v2 + 1 )
{
strcpy(dest, ssl_password);
v3 = strlen(ssl_password);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *dest, int a2)
{
size_t v2; // rax
unsigned int v3; // edx

v2 = strlen(ssl_password);
v3 = 0;
if ( a2 >= v2 + 1 )
{
strcpy(dest, ssl_password);
v3 = strlen(ssl_password);
}
return v3;
}

original_code:
static int password_callback(char *buf, int num, int rwflag, void *userdata)
{
    if(num < strlen(ssl_password)+1)
        return(0);
    strcpy(buf, ssl_password);
    return(strlen(ssl_password));
}

variable_types:
buf
char *

variable_types: num int

variable_types: rwflag int

variable_types:
userdata
void *


decompiled_code:
__int64 ssl_init()
{
OPENSSL_init_ssl(2097154LL, 0LL);
return OPENSSL_init_ssl(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func3()
{
OPENSSL_init_ssl(2097154LL, 0LL);
return OPENSSL_init_ssl(0LL, 0LL);
}

original_code:
void ssl_init(void)
{
    OPENSSL_init_ssl(0x00200000L | 0x00000002L, ((void *)0));
    OPENSSL_init_ssl(0, ((void *)0));
}

canonical_original_code:
void ssl_init()
{
    OPENSSL_init_ssl(0x00200000L | 0x00000002L, ((void *)0));
    OPENSSL_init_ssl(0, ((void *)0));
}


toptargs

decompiled_code:
__int64 __fastcall toptargs(int a1)
{
unsigned __int64 v1; // rax
int i; // edx
char *v3; // rsi
__int64 v4; // rcx

v1 = (unsigned int)((_DWORD)opts + 24);
for ( i = 0; ; ++i )
{
v3 = (char *)v1;
v4 = *(_QWORD *)(v1 - 24);
if ( !v4 && !*(_BYTE *)v1 )
break;
v1 += 32LL;
if ( *v3 == a1 )
return opts[4 * i + 2];
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned __int64 v1; // rax
int i; // edx
char *v3; // rsi
__int64 v4; // rcx

v1 = (unsigned int)((_DWORD)opts + 24);
for ( i = 0; ; ++i )
{
v3 = (char *)v1;
v4 = *(_QWORD *)(v1 - 24);
if ( !v4 && !*(_BYTE *)v1 )
break;
v1 += 32LL;
if ( *v3 == a1 )
return opts[4 * i + 2];
}
return v4;
}

original_code:
char * toptargs(int opt) {
 int j;
 for( j=0; ;j++ ) {
  if ( opts[j].longname == ((void *)0) && opts[j].shortname == 0 )
   break;
  if ( opts[j].shortname == opt )
   return opts[j].args;
 }
 return ((void *)0);
}

canonical_original_code:
char *toptargs(int opt) {
 int j;
 for( j=0; ;j++ ) {
  if ( opts[j].longname == ((void *)0) && opts[j].shortname == 0 )
   break;
  if ( opts[j].shortname == opt )
   return opts[j].args;
 }
 return ((void *)0);
}

variable_types: opt int


toptset

decompiled_code:
__int64 __fastcall toptset(int a1)
{
unsigned __int64 v1; // rax
int i; // edx
char *v3; // rcx

v1 = (unsigned int)((_DWORD)opts + 24);
for ( i = 0; ; ++i )
{
v3 = (char *)v1;
if ( !*(_QWORD *)(v1 - 24) && !*(_BYTE *)v1 )
return 0LL;
v1 += 32LL;
if ( *v3 == a1 )
break;
}
return HIDWORD(opts[4 * i + 3]);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned __int64 v1; // rax
int i; // edx
char *v3; // rcx

v1 = (unsigned int)((_DWORD)opts + 24);
for ( i = 0; ; ++i )
{
v3 = (char *)v1;
if ( !*(_QWORD *)(v1 - 24) && !*(_BYTE *)v1 )
return 0LL;
v1 += 32LL;
if ( *v3 == a1 )
break;
}
return HIDWORD(opts[4 * i + 3]);
}

original_code:
int toptset(int opt) {
 int j;
 for( j=0; ;j++ ) {
  if ( opts[j].longname == ((void *)0) && opts[j].shortname == 0 )
   break;
  if ( opts[j].shortname == opt )
   return opts[j].isset;
 }
 return 0;
}


tgetopt

decompiled_code:
void __fastcall tgetopt(int a1, __int64 a2)
{
int i; // ebp
const char **v3; // rbx
const char *v4; // r12
const char *v5; // rdi
char v6; // al
__int64 v7; // rdi
const char *v8; // rdi
__int64 v9; // rdx
char v10; // r13
const char *v11; // r14

if ( a1 > 1 )
{
for ( i = 1; i < a1; ++i )
{
v9 = *(_QWORD *)(a2 + 8LL * i);
if ( *(_BYTE *)v9 == 45 )
{
v10 = *(_BYTE *)(v9 + 1);
v3 = (const char **)opts;
if ( v10 == 45 )
{
v11 = (const char *)(v9 + 2);
while ( 1 )
{
v4 = *v3;
if ( !*v3 && !*((_BYTE *)v3 + 24) )
break;
if ( !strcasecmp(*v3, v11) )
{
if ( *((_DWORD *)v3 + 2) == 1 )
{
v5 = *(const char **)(a2 + 8LL * i + 8);
if ( !v5 || *v5 == 45 )
{
fprintf(stderr, "Argument for option %s missing\n", v4);
exit(0);
}
++i;
v3[2] = strdup(v5);
}
++*((_DWORD *)v3 + 7);
}
v3 += 4;
}
}
else
{
while ( *v3 || *((_BYTE *)v3 + 24) )
{
v6 = *((_BYTE *)v3 + 24);
if ( v10 == v6 )
{
if ( *((_DWORD *)v3 + 2) == 1 )
{
v7 = *(_QWORD *)(a2 + 8LL * i);
if ( *(_BYTE *)(v7 + 2) )
{
v3[2] = strdup((const char *)(v7 + 2));
}
else
{
v8 = *(const char **)(a2 + 8LL * i + 8);
if ( !v8 || *v8 == 45 )
{
fprintf(stderr, "Argument for option %c missing\n", (unsigned int)v6);
exit(0);
}
++i;
v3[2] = strdup(v8);
}
}
++*((_DWORD *)v3 + 7);
}
v3 += 4;
}
}
}
else
{
fprintf(stderr, "getopt: Skipping unknown option %s\n", (const char *)v9);
}
}
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, __int64 a2)
{
int i; // ebp
const char **v3; // rbx
const char *v4; // r12
const char *v5; // rdi
char v6; // al
__int64 v7; // rdi
const char *v8; // rdi
__int64 v9; // rdx
char v10; // r13
const char *v11; // r14

if ( a1 > 1 )
{
for ( i = 1; i < a1; ++i )
{
v9 = *(_QWORD *)(a2 + 8LL * i);
if ( *(_BYTE *)v9 == 45 )
{
v10 = *(_BYTE *)(v9 + 1);
v3 = (const char **)opts;
if ( v10 == 45 )
{
v11 = (const char *)(v9 + 2);
while ( 1 )
{
v4 = *v3;
if ( !*v3 && !*((_BYTE *)v3 + 24) )
break;
if ( !strcasecmp(*v3, v11) )
{
if ( *((_DWORD *)v3 + 2) == 1 )
{
v5 = *(const char **)(a2 + 8LL * i + 8);
if ( !v5 || *v5 == 45 )
{
fprintf(stderr, "Argument for option %s missing\n", v4);
exit(0);
}
++i;
v3[2] = strdup(v5);
}
++*((_DWORD *)v3 + 7);
}
v3 += 4;
}
}
else
{
while ( *v3 || *((_BYTE *)v3 + 24) )
{
v6 = *((_BYTE *)v3 + 24);
if ( v10 == v6 )
{
if ( *((_DWORD *)v3 + 2) == 1 )
{
v7 = *(_QWORD *)(a2 + 8LL * i);
if ( *(_BYTE *)(v7 + 2) )
{
v3[2] = strdup((const char *)(v7 + 2));
}
else
{
v8 = *(const char **)(a2 + 8LL * i + 8);
if ( !v8 || *v8 == 45 )
{
fprintf(stderr, "Argument for option %c missing\n", (unsigned int)v6);
exit(0);
}
++i;
v3[2] = strdup(v8);
}
}
++*((_DWORD *)v3 + 7);
}
v3 += 4;
}
}
}
else
{
fprintf(stderr, "getopt: Skipping unknown option %s\n", (const char *)v9);
}
}
}
}

original_code:
void tgetopt(int argc, char **argv) {
 int i,j;
 char c;
 char *p;
 for(i=1; i<argc; i++) {
  if ( argv[i][0] == '-' && argv[i][1] == '-' ) {
   p = argv[i]+2;
   for( j=0; ;j++ ) {
    if ( opts[j].longname == ((void *)0) && opts[j].shortname == 0 )
     break;
    if ( strcasecmp(opts[j].longname, p) == 0 ) {
     if ( opts[j].hasargs == 1 ) {
      if ( argv[i+1] == ((void *)0) || argv[i+1][0] == '-' ) {
       fprintf(stderr,"Argument for option %s missing\n",
         opts[j].longname);
       exit(0);
      }
      opts[j].args = strdup(argv[++i]);
     }
     opts[j].isset++;
    }
   }
  }else if ( argv[i][0] == '-' ) {
   c = argv[i][1];
   for( j=0; ;j++ ) {
    if ( opts[j].longname == ((void *)0) && opts[j].shortname == 0 )
     break;
    if ( opts[j].shortname == c ) {
     if ( opts[j].hasargs == 1 ) {
      if ( argv[i][2] != 0 ) {
       opts[j].args = strdup(argv[i]+2);
      }else
      if ( argv[i+1] != ((void *)0) && argv[i+1][0] != '-' ) {
       opts[j].args = strdup(argv[++i]);
      }else{
       fprintf(stderr,"Argument for option %c missing\n",
         opts[j].shortname);
       exit(0);
      }
     }
     opts[j].isset++;
    }
   }
  }else {
   fprintf(stderr, "getopt: Skipping unknown option %s\n", argv[i]);
  }
 }
}

canonical_original_code:
void tgetopt(int argc, char **argv) {
 int i; int j;
 char c;
 char *p;
 for(i=1; i<argc; i++) {
  if ( argv[i][0] == '-' && argv[i][1] == '-' ) {
   p = argv[i]+2;
   for( j=0; ;j++ ) {
    if ( opts[j].longname == ((void *)0) && opts[j].shortname == 0 )
     break;
    if ( strcasecmp(opts[j].longname, p) == 0 ) {
     if ( opts[j].hasargs == 1 ) {
      if ( argv[i+1] == ((void *)0) || argv[i+1][0] == '-' ) {
       fprintf(stderr,"Argument for option %s missing\n",
         opts[j].longname);
       exit(0);
      }
      opts[j].args = strdup(argv[++i]);
     }
     opts[j].isset++;
    }
   }
  }else if ( argv[i][0] == '-' ) {
   c = argv[i][1];
   for( j=0; ;j++ ) {
    if ( opts[j].longname == ((void *)0) && opts[j].shortname == 0 )
     break;
    if ( opts[j].shortname == c ) {
     if ( opts[j].hasargs == 1 ) {
      if ( argv[i][2] != 0 ) {
       opts[j].args = strdup(argv[i]+2);
      }else
      if ( argv[i+1] != ((void *)0) && argv[i+1][0] != '-' ) {
       opts[j].args = strdup(argv[++i]);
      }else{
       fprintf(stderr,"Argument for option %c missing\n",
         opts[j].shortname);
       exit(0);
      }
     }
     opts[j].isset++;
    }
   }
  }else {
   fprintf(stderr, "getopt: Skipping unknown option %s\n", argv[i]);
  }
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c char

variable_types:
p
char *


tfreeopt

decompiled_code:
_QWORD *tfreeopt()
{
_QWORD *i; // rbx
_QWORD *result; // rax
void *v2; // rdi

for ( i = opts; ; i += 4 )
{
result = i;
if ( !*i && !*((_BYTE *)i + 24) )
break;
v2 = (void *)i[2];
if ( v2 )
free(v2);
}
return result;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *i; // rbx
_QWORD *result; // rax
void *v2; // rdi

for ( i = opts; ; i += 4 )
{
result = i;
if ( !*i && !*((_BYTE *)i + 24) )
break;
v2 = (void *)i[2];
if ( v2 )
free(v2);
}
return result;
}

original_code:
void tfreeopt(void) {
 int j;
 for( j=0; ;j++ ) {
  if ( opts[j].longname == ((void *)0) && opts[j].shortname == 0 )
   break;
  if ( opts[j].args != ((void *)0) )
   free(opts[j].args);
 }
}

canonical_original_code:
void tfreeopt() {
 int j;
 for( j=0; ;j++ ) {
  if ( opts[j].longname == ((void *)0) && opts[j].shortname == 0 )
   break;
  if ( opts[j].args != ((void *)0) )
   free(opts[j].args);
 }
}


curlNullWriteCallback

decompiled_code:
__int64 __fastcall curlNullWriteCallback(__int64 a1, __int64 a2, __int64 a3)
{
return a3 * a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
return a3 * a2;
}

original_code:
static size_t curlNullWriteCallback(void *ptr, size_t size, size_t nmemb, void *data)
{
        size_t realsize = size * nmemb;
 return realsize;
}

canonical_original_code:
static unsigned long curlNullWriteCallback(void *ptr, unsigned long size, unsigned long nmemb, void *data)
{
        unsigned long realsize = size * nmemb;
 return realsize;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
data
void *

variable_types:
realsize
unsigned long

return_type: unsigned long


decompiled_code:
char *__fastcall auth_ignore(__int64 a1, __int64 a2, const char *a3)
{
char *result; // rax

if ( !strcasecmp(a3, "true") )
{
*(_BYTE *)(a1 + 60) = 1;
result = strdup("281 Authentication Accepted\r\n");
}
else
{
result = strdup("482 Authentication Rejected\r\n");
}
*(_QWORD *)(a1 + 64) = result;
return result;
}

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

if ( !strcasecmp(a3, "true") )
{
*(_BYTE *)(a1 + 60) = 1;
result = strdup("281 Authentication Accepted\r\n");
}
else
{
result = strdup("482 Authentication Rejected\r\n");
}
*(_QWORD *)(a1 + 64) = result;
return result;
}

original_code:
void auth_ignore(AUTHRESULT *authres, struct config *cf, char *args)
{
 if ( strcasecmp(args, "true") == 0 )
 {
  authres->authenticated = 1;
  authres->message = strdup("281 Authentication Accepted\r\n");
  return;
 }
 authres->message = strdup("482 Authentication Rejected\r\n");
 return;
}

canonical_original_code:
void auth_ignore(struct AUTHRESULT *authres, struct config *cf, char *args)
{
 if ( strcasecmp(args, "true") == 0 )
 {
  authres->authenticated = 1;
  authres->message = strdup("281 Authentication Accepted\r\n");
  return;
 }
 authres->message = strdup("482 Authentication Rejected\r\n");
 return;
}

variable_types: struct AUTHRESULT { char *username; char *password; char *username_s; int port; char *hostname; struct in_addr { unsigned int s_addr; } in_addr; struct ARGS { char name[256]; char args[256]; } *args; int numargs; unsigned char authenticated; char *message; char *profile; unsigned char posting; unsigned long long bytes; int userkbit; char *logname; char *readpat; char *postpat; int timeleft; unsigned char overquota; unsigned char disabled; char *posthost; char *postabuse; char *postorg; } *

variable_types: struct config { char *ListenPorts; char *BindAddress; char *RunAsUser; char *PidFile; char *StatsFile; int StatsFilePeriod; char *ConnDumpFile; char *BasePath; char *AccessFile; char *ServerFile; char *OverviewFmtFile; char *ActiveFile; char *NewsgroupsFile; int ServerReadTimeout; int ServerConnectTimeout; int ClientReadTimeout; int MaxConnections; int LogWriteclient; int LogReadserver; int LogWriteserver; int LogCommands; int LogMissing; int LogAuthInfo; char *PostServer; int PostServerPort; int PostXTraceHeader; char *ModeratorDomain; char *MailerPath; int BufSize; int SockBufSize; int ListenBackLog; int DenyNoIndexField; int DownDelay; int RetryDelay; int AccountingDelay; int RatePeriod; int DNSLookups; int DropUnknown; char *DisableFile; char *DisableText; int NoSuchArticleRetries; int LocalDreader; int CoreBind; int EnableSSL; char *ListenSSLPorts; char *AsLoginURL; char *AsLogoutURL; int RemoteConfig; char *WildmatURL; int JSONACL; char *ACLURL; int JSONRL; char *RLURL; char *null; } *

variable_types:
args
char *


decompiled_code:
char *__fastcall check_path(char *dest)
{
char *result; // rax
char v2[264]; // [rsp-108h] [rbp-108h] BYREF

if ( *dest != 47 )
{
sprintf(v2, "%s/%s", *((const char **)&cfg + 7), dest);
result = strncpy(dest, v2, 0x100uLL);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *dest)
{
char *result; // rax
char v2[264]; // [rsp-108h] [rbp-108h] BYREF

if ( *dest != 47 )
{
sprintf(v2, "%s/%s", *((const char **)&cfg + 7), dest);
result = strncpy(dest, v2, 0x100uLL);
}
return result;
}

original_code:
void check_path(char *filename)
{
 char tmp[256];
 if ( filename[0] == '/' )
  return;
 sprintf(tmp, "%s/%s", cfg.BasePath, filename);
 strncpy(filename, tmp, 256);
}

variable_types:
filename
char *

variable_types:
tmp
char [256]


decompiled_code:
char *__fastcall replace_path(const char *a1)
{
char *result; // rax
char v2[264]; // [rsp-108h] [rbp-108h] BYREF

result = (char *)a1;
if ( *a1 != 47 )
{
sprintf(v2, "%s/%s", *((const char **)&cfg + 7), a1);
result = strdup(v2);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1)
{
char *result; // rax
char v2[264]; // [rsp-108h] [rbp-108h] BYREF

result = (char *)a1;
if ( *a1 != 47 )
{
sprintf(v2, "%s/%s", *((const char **)&cfg + 7), a1);
result = strdup(v2);
}
return result;
}

original_code:
char* replace_path(char *filename)
{
 char tmp[256];
 if ( filename[0] == '/' )
  return filename;
 sprintf(tmp, "%s/%s", cfg.BasePath, filename);
 return strdup(tmp);
}

canonical_original_code:
char *replace_path(char *filename)
{
 char tmp[256];
 if ( filename[0] == '/' )
  return filename;
 sprintf(tmp, "%s/%s", cfg.BasePath, filename);
 return strdup(tmp);
}


decompiled_code:
__int64 __fastcall connect_to_server(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // ebx
void *v5; // rsp
__int64 v7; // [rsp+0h] [rbp-10h] BYREF

v4 = connect_socket();
if ( v4 != -1 )
{
v5 = alloca(cfg[44]);
if ( handshake_nntp(v4, &v7, a3) )
{
close(v4);
v4 = -1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // ebx
void *v5; // rsp
__int64 v7; // [rsp+0h] [rbp-10h] BYREF

v4 = connect_socket();
if ( v4 != -1 )
{
v5 = alloca(cfg[44]);
if ( handshake_nntp(v4, &v7, a3) )
{
close(v4);
v4 = -1;
}
}
return v4;
}

original_code:
int connect_to_server (char *server, int port, int timeout)
{
 int sock;
 if ((sock = connect_socket (server, port)) == -1)
  return -1;
 char response[cfg.BufSize];
 if (handshake_nntp (sock, response, timeout) != ((void *)0)) {
  close (sock);
  return -1;
 }
 return sock;
}

canonical_original_code:
int connect_to_server(char *server, int port, int timeout)
{
 int sock;
 if ((sock = connect_socket (server, port)) == -1)
  return -1;
 char response[-1];
 if (handshake_nntp (sock, response, timeout) != ((void *)0)) {
  close (sock);
  return -1;
 }
 return sock;
}

variable_types:
server
char *

variable_types: port int

variable_types: timeout int

variable_types: sock int

variable_types:
response
char [-1]


decompiled_code:
char *__fastcall auth_remote(__int64 a1, __int64 a2, const char *a3)
{
char *result; // rax
unsigned int v5; // er12
size_t v6; // rax
size_t v7; // rax
unsigned int v8; // [rsp+Ch] [rbp-19Ch] BYREF
char v9[128]; // [rsp+10h] [rbp-198h] BYREF
char s[280]; // [rsp+90h] [rbp-118h] BYREF

if ( (unsigned int)_isoc99_sscanf(a3, "%128[^:]:%d", v9, &v8) == 2 )
{
v5 = connect_to_server((__int64)v9, v8, *(_DWORD *)(a2 + 104));
if ( v5 == -1 )
{
syslog(3, "auth_remote: Error connecting to authentication server");
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
else
{
sprintf(s, "AUTHINFO USER %s\r\n", *(const char **)(a1 + 16));
v6 = strlen(s);
write_socket(v5, s, v6, *(unsigned int *)(a2 + 104));
if ( read_socket(v5, s, 256LL, *(unsigned int *)(a2 + 104)) <= 0
|| (sprintf(s, "AUTHINFO PASS %s\r\n", *(const char **)(a1 + 8)),
v7 = strlen(s),
write_socket(v5, s, v7, *(unsigned int *)(a2 + 104)),
read_socket(v5, s, 256LL, *(unsigned int *)(a2 + 104)) <= 0) )
{
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
else
{
if ( atoi(s) == 281 )
{
*(_BYTE *)(a1 + 60) = 1;
result = strdup("281 Authentication Accepted\r\n");
}
else
{
result = strdup("482 Authentication Rejected\r\n");
}
*(_QWORD *)(a1 + 64) = result;
}
}
}
else
{
syslog(3, "auth_remote: Wrong argument syntax \"%s\"", a3);
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, __int64 a2, const char *a3)
{
char *result; // rax
unsigned int v5; // er12
size_t v6; // rax
size_t v7; // rax
unsigned int v8; // [rsp+Ch] [rbp-19Ch] BYREF
char v9[128]; // [rsp+10h] [rbp-198h] BYREF
char s[280]; // [rsp+90h] [rbp-118h] BYREF

if ( (unsigned int)_isoc99_sscanf(a3, "%128[^:]:%d", v9, &v8) == 2 )
{
v5 = func0((__int64)v9, v8, *(_DWORD *)(a2 + 104));
if ( v5 == -1 )
{
syslog(3, "auth_remote: Error connecting to authentication server");
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
else
{
sprintf(s, "AUTHINFO USER %s\r\n", *(const char **)(a1 + 16));
v6 = strlen(s);
write_socket(v5, s, v6, *(unsigned int *)(a2 + 104));
if ( read_socket(v5, s, 256LL, *(unsigned int *)(a2 + 104)) <= 0
|| (sprintf(s, "AUTHINFO PASS %s\r\n", *(const char **)(a1 + 8)),
v7 = strlen(s),
write_socket(v5, s, v7, *(unsigned int *)(a2 + 104)),
read_socket(v5, s, 256LL, *(unsigned int *)(a2 + 104)) <= 0) )
{
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
else
{
if ( atoi(s) == 281 )
{
*(_BYTE *)(a1 + 60) = 1;
result = strdup("281 Authentication Accepted\r\n");
}
else
{
result = strdup("482 Authentication Rejected\r\n");
}
*(_QWORD *)(a1 + 64) = result;
}
}
}
else
{
syslog(3, "auth_remote: Wrong argument syntax \"%s\"", a3);
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
return result;
}

original_code:
void auth_remote(AUTHRESULT *authres, struct config *cf, char *args)
{
 char tmp[256];
 char server[128];
 int port;
 int sock;
 if ( sscanf(args, "%128[^:]:%d", server, &port) != 2 )
 {
  syslog(3, "auth_remote: Wrong argument syntax \"%s\"", args);
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 if ( (sock=connect_to_server(server, port, cf->ServerReadTimeout)) == -1 )
 {
  syslog(3, "auth_remote: Error connecting to authentication server");
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 sprintf(tmp, "AUTHINFO USER %s\r\n", authres->username_s);
 write_socket(sock, tmp, strlen(tmp), cf->ServerReadTimeout);
 if ( read_socket(sock, tmp, 256, cf->ServerReadTimeout) <= 0 )
 {
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 sprintf(tmp, "AUTHINFO PASS %s\r\n", authres->password);
 write_socket(sock, tmp, strlen(tmp), cf->ServerReadTimeout);
 if ( read_socket(sock, tmp, 256, cf->ServerReadTimeout) <= 0 )
 {
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 if ( atoi(tmp) == 281 )
 {
  authres->authenticated = 1;
  authres->message = strdup("281 Authentication Accepted\r\n");
  return;
 }
 authres->message = strdup("482 Authentication Rejected\r\n");
 return;
}

canonical_original_code:
void auth_remote(struct AUTHRESULT *authres, struct config *cf, char *args)
{
 char tmp[256];
 char server[128];
 int port;
 int sock;
 if ( sscanf(args, "%128[^:]:%d", server, &port) != 2 )
 {
  syslog(3, "auth_remote: Wrong argument syntax \"%s\"", args);
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 if ( (sock=connect_to_server(server, port, cf->ServerReadTimeout)) == -1 )
 {
  syslog(3, "auth_remote: Error connecting to authentication server");
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 sprintf(tmp, "AUTHINFO USER %s\r\n", authres->username_s);
 write_socket(sock, tmp, strlen(tmp), cf->ServerReadTimeout);
 if ( read_socket(sock, tmp, 256, cf->ServerReadTimeout) <= 0 )
 {
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 sprintf(tmp, "AUTHINFO PASS %s\r\n", authres->password);
 write_socket(sock, tmp, strlen(tmp), cf->ServerReadTimeout);
 if ( read_socket(sock, tmp, 256, cf->ServerReadTimeout) <= 0 )
 {
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 if ( atoi(tmp) == 281 )
 {
  authres->authenticated = 1;
  authres->message = strdup("281 Authentication Accepted\r\n");
  return;
 }
 authres->message = strdup("482 Authentication Rejected\r\n");
 return;
}

variable_types:
server
char [128]

user_defined_types: struct config { char *ListenPorts; char *BindAddress; char *RunAsUser; char *PidFile; char *StatsFile; int StatsFilePeriod; char *ConnDumpFile; char *BasePath; char *AccessFile; char *ServerFile; char *OverviewFmtFile; char *ActiveFile; char *NewsgroupsFile; int ServerReadTimeout; int ServerConnectTimeout; int ClientReadTimeout; int MaxConnections; int LogWriteclient; int LogReadserver; int LogWriteserver; int LogCommands; int LogMissing; int LogAuthInfo; char *PostServer; int PostServerPort; int PostXTraceHeader; char *ModeratorDomain; char *MailerPath; int BufSize; int SockBufSize; int ListenBackLog; int DenyNoIndexField; int DownDelay; int RetryDelay; int AccountingDelay; int RatePeriod; int DNSLookups; int DropUnknown; char *DisableFile; char *DisableText; int NoSuchArticleRetries; int LocalDreader; int CoreBind; int EnableSSL; char *ListenSSLPorts; char *AsLoginURL; char *AsLogoutURL; int RemoteConfig; char *WildmatURL; int JSONACL; char *ACLURL; int JSONRL; char *RLURL; char *null; }

user_defined_types: struct ARGS { char name[256]; char args[256]; }


initproctitle

decompiled_code:
char **__fastcall initproctitle(int a1, _DWORD *a2)
{
char **v3; // r13
int v4; // eax
__int64 v5; // rdx
char **result; // rax
const char *v7; // rdi
int v8; // ebp
__int64 i; // rbx
char **v10; // r12
const char *v11; // rbx
const char *v12; // rbx

v3 = environ;
v4 = 0;
if ( *environ )
{
v5 = 1LL;
do
v4 = v5++;
while ( environ[v5 - 1] );
}
result = (char **)malloc(8LL * (v4 + 1));
environ = result;
if ( result )
{
v7 = *v3;
if ( *v3 )
{
v8 = 0;
for ( i = 0LL; ; ++i )
{
v10 = &environ[i];
result = (char **)strdup(v7);
*v10 = (char *)result;
if ( !result )
break;
++v8;
v7 = v3[i + 1];
if ( !v7 )
{
environ[i + 1] = 0LL;
argv0 = (__int64)a2;
if ( v8 <= 0 )
goto LABEL_14;
v11 = v3[i];
result = (char **)strlen(v11);
argv_lth = (_DWORD)result + (_DWORD)v11 - *a2;
return result;
}
}
}
else
{
*result = 0LL;
argv0 = (__int64)a2;
LABEL_14:
v12 = *(const char **)&a2[2 * a1 - 2];
result = (char **)strlen(v12);
argv_lth = (_DWORD)result + (_DWORD)v12 - *a2;
}
}
return result;
}

canonical_decompiled_code:
char **__fastcall func0(int a1, _DWORD *a2)
{
char **v3; // r13
int v4; // eax
__int64 v5; // rdx
char **result; // rax
const char *v7; // rdi
int v8; // ebp
__int64 i; // rbx
char **v10; // r12
const char *v11; // rbx
const char *v12; // rbx

v3 = environ;
v4 = 0;
if ( *environ )
{
v5 = 1LL;
do
v4 = v5++;
while ( environ[v5 - 1] );
}
result = (char **)malloc(8LL * (v4 + 1));
environ = result;
if ( result )
{
v7 = *v3;
if ( *v3 )
{
v8 = 0;
for ( i = 0LL; ; ++i )
{
v10 = &environ[i];
result = (char **)strdup(v7);
*v10 = (char *)result;
if ( !result )
break;
++v8;
v7 = v3[i + 1];
if ( !v7 )
{
environ[i + 1] = 0LL;
argv0 = (__int64)a2;
if ( v8 <= 0 )
goto LABEL_14;
v11 = v3[i];
result = (char **)strlen(v11);
argv_lth = (_DWORD)result + (_DWORD)v11 - *a2;
return result;
}
}
}
else
{
*result = 0LL;
argv0 = (__int64)a2;
LABEL_14:
v12 = *(const char **)&a2[2 * a1 - 2];
result = (char **)strlen(v12);
argv_lth = (_DWORD)result + (_DWORD)v12 - *a2;
}
}
return result;
}

original_code:
void
initproctitle (int argc, char **argv) {
 int i;
 char **envp = environ;
 for (i = 0; envp[i] != ((void *)0); i++)
  continue;
 environ = (char **) malloc(sizeof(char *) * (i + 1));
 if (environ == ((void *)0))
  return;
 for (i = 0; envp[i] != ((void *)0); i++)
  if ((environ[i] = strdup(envp[i])) == ((void *)0))
   return;
 environ[i] = ((void *)0);
 argv0 = argv;
 if (i > 0)
  argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0];
 else
  argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0];
}

canonical_original_code:
void initproctitle(int argc, char **argv) {
 int i;
 char **envp = environ;
 for (i = 0; envp[i] != ((void *)0); i++)
  continue;
 environ = (char **) malloc(sizeof(char *) * (i + 1));
 if (environ == ((void *)0))
  return;
 for (i = 0; envp[i] != ((void *)0); i++)
  if ((environ[i] = strdup(envp[i])) == ((void *)0))
   return;
 environ[i] = ((void *)0);
 argv0 = argv;
 if (i > 0)
  argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0];
 else
  argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0];
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types:
envp
char **


setproctitle

decompiled_code:
void setproctitle(char *format, ...)
{
int v1; // eax
int v2; // edx
__int64 v3; // rbx
gcc_va_list arg; // [rsp+8h] [rbp-8D0h] BYREF
char s[2048]; // [rsp+20h] [rbp-8B8h] BYREF

if ( argv0 )
{
va_start(arg, format);
vsnprintf(s, 0x800uLL, format, arg);
v1 = strlen(s);
v2 = argv_lth;
if ( argv_lth - 1 <= v1 )
s[argv_lth - 2] = 0;
v3 = argv0;
memset(*(void **)argv0, 0, v2);
strcpy(*(char **)v3, s);
*(_QWORD *)(v3 + 8) = 0LL;
}
}

canonical_decompiled_code:
void func1(char *format, ...)
{
int v1; // eax
int v2; // edx
__int64 v3; // rbx
gcc_va_list arg; // [rsp+8h] [rbp-8D0h] BYREF
char s[2048]; // [rsp+20h] [rbp-8B8h] BYREF

if ( argv0 )
{
va_start(arg, format);
vsnprintf(s, 0x800uLL, format, arg);
v1 = strlen(s);
v2 = argv_lth;
if ( argv_lth - 1 <= v1 )
s[argv_lth - 2] = 0;
v3 = argv0;
memset(*(void **)argv0, 0, v2);
strcpy(*(char **)v3, s);
*(_QWORD *)(v3 + 8) = 0LL;
}
}

original_code:
void
setproctitle (const char *fmt,...) {
 int i;
 char buf[2048];
 va_list ap;
 if (!argv0)
  return;
 __builtin_va_start(ap,fmt);
 (void) vsnprintf(buf, 2048, fmt, ap);
 __builtin_va_end(ap);
 i = strlen (buf);
 if (i > argv_lth - 2) {
  i = argv_lth - 2;
  buf[i] = '\0';
 }
 memset(argv0[0], '\0', argv_lth);
 (void) strcpy (argv0[0], buf);
 argv0[1] = ((void *)0);
}

canonical_original_code:
void setproctitle(char *fmt, ...) {
 int i;
 char buf[2048];
 __builtin_va_list ap;
 if (!argv0)
  return;
 __builtin_va_start(ap,fmt);
 (void) vsnprintf(buf, 2048, fmt, ap);
 __builtin_va_end(ap);
 i = strlen (buf);
 if (i > argv_lth - 2) {
  i = argv_lth - 2;
  buf[i] = '\0';
 }
 memset(argv0[0], '\0', argv_lth);
 (void) strcpy (argv0[0], buf);
 argv0[1] = ((void *)0);
}

variable_types:
fmt
char *

variable_types:
buf
char [2048]


freehttpacl

decompiled_code:
void __fastcall freehttpacl(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void freehttpacl(ACL * acl)
{
    if ( acl != ((void *)0) )
        free(acl);
}

canonical_original_code:
void freehttpacl(struct ACL *acl)
{
    if ( acl != ((void *)0) )
        free(acl);
}

variable_types: struct ACL { unsigned long start; unsigned long end; unsigned long size; struct _profile { char Name[32]; char ReadPat[256]; char PostPat[256]; int MaxConnections; int MaxUserConcurrent; int MaxHostConcurrent; int Slave; int ASMaxConns; int ASMaxHosts; int MaxUsers; int MaxSessionTime; unsigned long long MaxSessionBytes; unsigned int MaxUserBPS; unsigned int MaxProfileBPS; char XComplaintsTo[256]; char Organization[256]; int ForceOrganization; int AddNNTPPostingHost; int MaxCross; char Hostname[256]; char FooterFile[256]; char Footer[1024]; int FooterSize; int NoControl; int ArticleSearch; int ClientReadTimeout; struct ALIAS { char name[256]; char lib[256]; char args[256]; } *Accounting; char AccountingPrefix[256]; struct LIMITS { int gb; int kbit; } Limits[16]; int NumLimits; char Disabled[256]; int AllowSSL; unsigned int connections; unsigned int numusers; unsigned int realusers; unsigned long long bytes; unsigned long long rbytes; unsigned long articles; unsigned long long postbytes; unsigned long postarticles; unsigned int rl_curbytes; unsigned int rl_lastbytes; double rl_sleep; struct timeval { long tv_sec; long tv_usec; } rl_start; double rl_curbps; double UserRLFactorU; double UserRLFactorD; double ProfileRLFactorU; double ProfileRLFactorD; unsigned int Retention; char XHeaderSSLUpload[1024]; struct PFXMAP { char name[32]; char map[4194303]; } *PrefixMap; struct _profile *FailProfile; } *profile; unsigned int read; unsigned int post; unsigned int apost; unsigned int deny; unsigned int auth; unsigned int stats; unsigned int unlimit; } *

user_defined_types: struct ACL { unsigned long start; unsigned long end; unsigned long size; struct _profile *profile; unsigned int read; unsigned int post; unsigned int apost; unsigned int deny; unsigned int auth; unsigned int stats; unsigned int unlimit; }