decompiled_code:
void __fastcall oj_line(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
bool v5; // al
bool v6; // cf
bool v7; // zf
const char *v8; // rdi
__int64 v9; // rcx
char *v10; // rsi
char *v11; // rbp
__int64 i; // rbx
__int64 v13; // rbp
__int64 v14; // rsi
_BYTE v15[528]; // [rsp+0h] [rbp-D98h] BYREF
char v16[880]; // [rsp+210h] [rbp-B88h] BYREF
char *s[259]; // [rsp+580h] [rbp-818h] BYREF

mystrncpy(v15, a1, 513LL, a4);
memset(s, 0, 0x800uLL);
if ( (int)tokenize(v15, " ", s, 256LL) > 1 )
{
v5 = strcmp(s[0], "PING") != 0;
v6 = 0;
v7 = !v5;
if ( v5 )
{
v8 = "005";
v9 = 4LL;
v10 = s[1];
do
{
if ( !v9 )
break;
v6 = (unsigned __int8)*v10 < (unsigned int)*v8;
v7 = *v10++ == *v8++;
--v9;
}
while ( v7 );
if ( ojiscon | (char)((!v6 && !v7) - v6) )
{
if ( (!strcmp(s[1], "PRIVMSG") || !strcmp(s[1], "NOTICE"))
&& !strcmp(s[2], ojNick)
&& time(0LL) - ojConnect < *((int *)&config + 300) )
{
v11 = s[0];
if ( strchr(s[0], 33) )
{
make_user_struct(v11, v16);
sprintf(ojbuf, "[onjoin] <%s> %s", v16, a1 + s[3] - s[0] + 1);
sRelay(ojbuf);
for ( i = chans[24]; i; i = *(_QWORD *)(i + 192) )
{
v13 = *(_QWORD *)(i + 176);
if ( v13 && strchr((const char *)(i + 8), 100) )
{
v14 = findUser(v13, v16);
if ( v14 )
punish_user(i, v14, 100LL, 0LL, 0LL);
}
}
}
}
}
else
{
mystrncpy(ojNick, s[2], 33LL, v9);
sprintf(ojbuf, "On-join detector connected with nick: %s", ojNick);
sRelay(ojbuf);
oj_burst();
ojiscon = 1;
}
}
else
{
sprintf(ojbuf, "PONG %s", s[1]);
sockwrite(ojsock, ojbuf);
}
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
bool v5; // al
bool v6; // cf
bool v7; // zf
const char *v8; // rdi
__int64 v9; // rcx
char *v10; // rsi
char *v11; // rbp
__int64 i; // rbx
__int64 v13; // rbp
__int64 v14; // rsi
_BYTE v15[528]; // [rsp+0h] [rbp-D98h] BYREF
char v16[880]; // [rsp+210h] [rbp-B88h] BYREF
char *s[259]; // [rsp+580h] [rbp-818h] BYREF

mystrncpy(v15, a1, 513LL, a4);
memset(s, 0, 0x800uLL);
if ( (int)tokenize(v15, " ", s, 256LL) > 1 )
{
v5 = strcmp(s[0], "PING") != 0;
v6 = 0;
v7 = !v5;
if ( v5 )
{
v8 = "005";
v9 = 4LL;
v10 = s[1];
do
{
if ( !v9 )
break;
v6 = (unsigned __int8)*v10 < (unsigned int)*v8;
v7 = *v10++ == *v8++;
--v9;
}
while ( v7 );
if ( ojiscon | (char)((!v6 && !v7) - v6) )
{
if ( (!strcmp(s[1], "PRIVMSG") || !strcmp(s[1], "NOTICE"))
&& !strcmp(s[2], ojNick)
&& time(0LL) - ojConnect < *((int *)&config + 300) )
{
v11 = s[0];
if ( strchr(s[0], 33) )
{
make_user_struct(v11, v16);
sprintf(ojbuf, "[onjoin] <%s> %s", v16, a1 + s[3] - s[0] + 1);
sRelay(ojbuf);
for ( i = chans[24]; i; i = *(_QWORD *)(i + 192) )
{
v13 = *(_QWORD *)(i + 176);
if ( v13 && strchr((const char *)(i + 8), 100) )
{
v14 = findUser(v13, v16);
if ( v14 )
punish_user(i, v14, 100LL, 0LL, 0LL);
}
}
}
}
}
else
{
mystrncpy(ojNick, s[2], 33LL, v9);
sprintf(ojbuf, "On-join detector connected with nick: %s", ojNick);
sRelay(ojbuf);
func8();
ojiscon = 1;
}
}
else
{
sprintf(ojbuf, "PONG %s", s[1]);
sockwrite(ojsock, ojbuf);
}
}
}

original_code:
void oj_line(char *message)
{
 char tokenline[513];
 char *tokens[256];
 sUser theUser;
 int numtok;
 mystrncpy(tokenline, message, 513);
 memset(tokens, 0, sizeof(tokens) );
 numtok = tokenize(tokenline, " ", tokens, 256);
 if(numtok < 2)
  return;
 if(strcmp(tokens[0], "PING") == 0) {
  sprintf(ojbuf, "PONG %s", tokens[1]);
  sockwrite(ojsock, ojbuf);
  return;
 } else if(!strcmp(tokens[1], "005") && ojiscon == 0) {
  mystrncpy(ojNick, tokens[2], 33);
  sprintf(ojbuf, "On-join detector connected with nick: %s", ojNick);
  sRelay(ojbuf);
  oj_burst();
  ojiscon = 1;
 } else if(
    (!strcmp(tokens[1], "PRIVMSG") || !strcmp(tokens[1], "NOTICE")) &&
    !strcmp(tokens[2], ojNick) &&
    (time(0) - ojConnect < config.oj_listenperiod) &&
    strchr(tokens[0], '!')
  ) {
  struct chanRec *i;
  struct suser *fuser;
  make_user_struct(tokens[0], &theUser);
  sprintf(ojbuf, "[onjoin] <%s> %s", theUser.nick, message + (tokens[3]-tokens[0]) + 1);
  sRelay(ojbuf);
  i = chans.next;
  while(i) {
   if(i->physical && strchr(i->flags, 'd')) {
    fuser = findUser(i->physical, theUser.nick);
    if(fuser)
     punish_user(i, fuser, 'd', 0, 0);
   }
   i = i->next;
  }
 }
}

canonical_original_code:
void oj_line(char *message)
{
 char tokenline[513];
 char *tokens[256];
 struct ircUser theUser;
 int numtok;
 mystrncpy(tokenline, message, 513);
 memset(tokens, 0, sizeof(tokens) );
 numtok = tokenize(tokenline, " ", tokens, 256);
 if(numtok < 2)
  return;
 if(strcmp(tokens[0], "PING") == 0) {
  sprintf(ojbuf, "PONG %s", tokens[1]);
  sockwrite(ojsock, ojbuf);
  return;
 } else if(!strcmp(tokens[1], "005") && ojiscon == 0) {
  mystrncpy(ojNick, tokens[2], 33);
  sprintf(ojbuf, "On-join detector connected with nick: %s", ojNick);
  sRelay(ojbuf);
  oj_burst();
  ojiscon = 1;
 } else if(
    (!strcmp(tokens[1], "PRIVMSG") || !strcmp(tokens[1], "NOTICE")) &&
    !strcmp(tokens[2], ojNick) &&
    (time(0) - ojConnect < config.oj_listenperiod) &&
    strchr(tokens[0], '!')
  ) {
  struct chanRec *i;
  struct suser *fuser;
  make_user_struct(tokens[0], &theUser);
  sprintf(ojbuf, "[onjoin] <%s> %s", theUser.nick, message + (tokens[3]-tokens[0]) + 1);
  sRelay(ojbuf);
  i = chans.next;
  while(i) {
   if(i->physical && strchr(i->flags, 'd')) {
    fuser = findUser(i->physical, theUser.nick);
    if(fuser)
     punish_user(i, fuser, 'd', 0, 0);
   }
   i = i->next;
  }
 }
}

variable_types:
message
char *

variable_types:
tokenline
char [513]

variable_types:
tokens
char *[256]

variable_types: struct ircUser { char nick[33]; char ident[33]; char host[256]; char mask[512]; char gnuUser[32]; }

variable_types: numtok int

variable_types: struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; } *


checkNeedCon

repo: ipacker/fireclaw

decompiled_code:
time_t checkNeedCon()
{
__int64 v0; // rbp
time_t result; // rax
char *v2; // rax

v0 = ojsock;
if ( ojsock && *(_BYTE *)(ojsock + 1) == 1 )
{
result = time(0LL) - ojConnect;
if ( result > 180 )
{
sockwrite(v0, "QUIT");
*(_BYTE *)(ojsock + 1) = 2;
result = fixBrokenSocks();
}
}
else
{
result = isChanWithJ();
if ( (_DWORD)result )
{
result = time(0LL) - ojConnect;
if ( result > *((int *)&config + 299) )
{
v2 = get_random_vhost();
ojsock = add_socket(74LL, 2LL, *serv, *(unsigned int *)(serv + 8LL), v2, 0LL);
result = time(0LL);
ojConnect = result;
}
}
}
return result;
}

canonical_decompiled_code:
time_t func10()
{
__int64 v0; // rbp
time_t result; // rax
char *v2; // rax

v0 = ojsock;
if ( ojsock && *(_BYTE *)(ojsock + 1) == 1 )
{
result = time(0LL) - ojConnect;
if ( result > 180 )
{
sockwrite(v0, "QUIT");
*(_BYTE *)(ojsock + 1) = 2;
result = fixBrokenSocks();
}
}
else
{
result = isChanWithJ();
if ( (_DWORD)result )
{
result = time(0LL) - ojConnect;
if ( result > *((int *)&config + 299) )
{
v2 = func4();
ojsock = add_socket(74LL, 2LL, *serv, *(unsigned int *)(serv + 8LL), v2, 0LL);
result = time(0LL);
ojConnect = result;
}
}
}
return result;
}

original_code:
void checkNeedCon()
{
 if(ojsock && ojsock->status == 1) {
  if(time(0) - ojConnect > 180) {
   sockwrite(ojsock, "QUIT");
   ojsock->status = 2;
   fixBrokenSocks();
  }
 } else {
  if(isChanWithJ() && (time(0) - ojConnect > config.oj_period)) {
   ojsock = add_socket('J', 2, serv->hostname, serv->port, get_random_vhost(), 0);
   ojConnect = time(0);
  }
 }
}

return_type: void


decompiled_code:
__int64 get_next_dcc_id()
{
return (unsigned int)dccpos;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)dccpos;
}

original_code: int get_next_dcc_id() { return dccpos; }

return_type: int


decompiled_code:
__int64 __fastcall dcc_close_user(int a1)
{
__int64 *v1; // rbx

v1 = &dcclist[5 * a1];
sockwrite(v1[3]);
*(_BYTE *)(v1[3] + 1) = 2;
return fixBrokenSocks();
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 *v1; // rbx

v1 = &dcclist[5 * a1];
sockwrite(v1[3]);
*(_BYTE *)(v1[3] + 1) = 2;
return fixBrokenSocks();
}

original_code:
void dcc_close_user(int did, char *msg)
{
 sockwrite(dcclist[did].con, msg);
 dcclist[did].con->status = 2;
 fixBrokenSocks();
}

variable_types: did int

variable_types:
msg
char *


decompiled_code:
void __fastcall set_dcc_adm(int a1, const char *a2)
{
unsigned int v2; // ebp
__int64 *v3; // r13
const char *v4; // rdx
size_t v5; // rax
__int64 v6; // rax

v2 = a1 - 1000;
if ( dccpos > a1 - 1000 )
{
v3 = &dcclist[5 * (int)v2];
v4 = (const char *)v3[1];
v3[4] = (__int64)a2;
if ( v4 )
{
sprintf(dccbuf, "%s(guest)", v4);
send_diepartyliner(v2, dccbuf, "Authenticated.");
}
else
{
v5 = strlen(a2);
v6 = myalloc(v5 + 1);
v3[1] = v6;
mystrncpy(v6, a2, 32LL);
}
send_newpartyliner(v2, dcclist[5 * (int)v2 + 4]);
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, const char *a2)
{
unsigned int v2; // ebp
__int64 *v3; // r13
const char *v4; // rdx
size_t v5; // rax
__int64 v6; // rax

v2 = a1 - 1000;
if ( dccpos > a1 - 1000 )
{
v3 = &dcclist[5 * (int)v2];
v4 = (const char *)v3[1];
v3[4] = (__int64)a2;
if ( v4 )
{
sprintf(dccbuf, "%s(guest)", v4);
send_diepartyliner(v2, dccbuf, "Authenticated.");
}
else
{
v5 = strlen(a2);
v6 = myalloc(v5 + 1);
v3[1] = v6;
mystrncpy(v6, a2, 32LL);
}
send_newpartyliner(v2, dcclist[5 * (int)v2 + 4]);
}
}

original_code:
void set_dcc_adm(int id, struct sadmin *adm)
{
 id -= 1000;
 if(id >= dccpos)
  return;
 dcclist[id].adm = adm;
 if(!dcclist[id].user) {
  dcclist[id].user = (char*)myalloc(strlen(adm->nick)+1);
  mystrncpy(dcclist[id].user, adm->nick, 32);
 } else {
  sprintf(dccbuf, "%s(guest)", dcclist[id].user);
  send_diepartyliner(id, dccbuf, "Authenticated.");
 }
 send_newpartyliner(id, dcclist[id].adm->nick);
}

canonical_original_code:
void set_dcc_adm(int id, struct sadmin *adm)
{
 id -= 1000;
 if(id >= dccpos)
  return;
 dcclist[id].adm = adm;
 if(!dcclist[id].user) {
  dcclist[id].user = (char *)myalloc(strlen(adm->nick)+1);
  mystrncpy(dcclist[id].user, adm->nick, 32);
 } else {
  sprintf(dccbuf, "%s(guest)", dcclist[id].user);
  send_diepartyliner(id, dccbuf, "Authenticated.");
 }
 send_newpartyliner(id, dcclist[id].adm->nick);
}

variable_types: id int

variable_types: struct sadmin { char nick[33]; char pass[-1]; char actualNick[33]; int level; struct sadmin *next; struct sadmin *prev; } *


decompiled_code:
__int64 __fastcall admin_deleted(__int64 a1)
{
int v2; // ebp
unsigned __int64 v3; // rbx
__int64 v4; // rdi
bool v5; // cc

if ( dccpos > 0 )
{
v2 = 0;
v3 = (unsigned int)((_DWORD)dcclist + 24);
do
{
while ( *(_QWORD *)(v3 + 8) != a1 )
{
++v2;
v3 += 40LL;
if ( dccpos <= v2 )
return fixBrokenSocks();
}
v4 = *(_QWORD *)v3;
++v2;
v3 += 40LL;
sockwrite(v4);
v5 = dccpos <= v2;
*(_BYTE *)(*(_QWORD *)(v3 - 40) + 1LL) = 2;
}
while ( !v5 );
}
return fixBrokenSocks();
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v2; // ebp
unsigned __int64 v3; // rbx
__int64 v4; // rdi
bool v5; // cc

if ( dccpos > 0 )
{
v2 = 0;
v3 = (unsigned int)((_DWORD)dcclist + 24);
do
{
while ( *(_QWORD *)(v3 + 8) != a1 )
{
++v2;
v3 += 40LL;
if ( dccpos <= v2 )
return fixBrokenSocks();
}
v4 = *(_QWORD *)v3;
++v2;
v3 += 40LL;
sockwrite(v4);
v5 = dccpos <= v2;
*(_BYTE *)(*(_QWORD *)(v3 - 40) + 1LL) = 2;
}
while ( !v5 );
}
return fixBrokenSocks();
}

original_code:
void admin_deleted(struct sadmin *admin)
{
 int i;
 for(i = 0; i < dccpos; i++) {
  if(dcclist[i].adm == admin) {
   sockwrite(dcclist[i].con, "Your admin account has been removed, dcc chat terminated.");
   dcclist[i].con->status = 2;
  }
 }
 fixBrokenSocks();
}

variable_types: i int

user_defined_types: struct sadmin { char nick[33]; char pass[-1]; char actualNick[33]; int level; struct sadmin *next; struct sadmin *prev; }


decompiled_code:
void *__fastcall get_dcc_user(int a1)
{
int v1; // edi
void *result; // rax
__int64 *v3; // rdx

v1 = a1 - 1000;
result = &unk_43F9;
if ( dccpos > v1 )
{
v3 = &dcclist[5 * v1];
result = (void *)v3[4];
if ( !result )
result = (void *)v3[1];
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(int a1)
{
int v1; // edi
void *result; // rax
__int64 *v3; // rdx

v1 = a1 - 1000;
result = &unk_43F9;
if ( dccpos > v1 )
{
v3 = &dcclist[5 * v1];
result = (void *)v3[4];
if ( !result )
result = (void *)v3[1];
}
return result;
}

original_code:
char *get_dcc_user(int id)
{
 id -= 1000;
 if(id >= dccpos)
  return "";
 if(dcclist[id].adm)
  return dcclist[id].adm->nick;
 return dcclist[id].user;
}

return_type: char *


decompiled_code:
void *__fastcall get_dcc_host(int a1)
{
int v1; // edi
void *result; // rax

v1 = a1 - 1000;
result = &unk_43F9;
if ( dccpos > v1 )
result = (void *)dcclist[5 * v1 + 2];
return result;
}

canonical_decompiled_code:
void *__fastcall func5(int a1)
{
int v1; // edi
void *result; // rax

v1 = a1 - 1000;
result = &unk_43F9;
if ( dccpos > v1 )
result = (void *)dcclist[5 * v1 + 2];
return result;
}

original_code:
char *get_dcc_host(int id)
{
 id -= 1000;
 if(id >= dccpos)
  return "";
 return dcclist[id].host;
}


decompiled_code:
__int64 __fastcall dcc_closeall(__int64 a1)
{
int v2; // ebp
unsigned __int64 v3; // rbx
__int64 v4; // rdi
bool v5; // cc

if ( dccpos <= 0 )
return ((__int64 (*)(void))fixBrokenSocks)();
v2 = 0;
v3 = (unsigned int)((_DWORD)dcclist + 24);
do
{
v4 = *(_QWORD *)v3;
++v2;
v3 += 40LL;
sockwrite(v4);
v5 = dccpos <= v2;
*(_BYTE *)(*(_QWORD *)(v3 - 40) + 1LL) = 2;
}
while ( !v5 );
return fixBrokenSocks(v4, a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v2; // ebp
unsigned __int64 v3; // rbx
__int64 v4; // rdi
bool v5; // cc

if ( dccpos <= 0 )
return ((__int64 (*)(void))fixBrokenSocks)();
v2 = 0;
v3 = (unsigned int)((_DWORD)dcclist + 24);
do
{
v4 = *(_QWORD *)v3;
++v2;
v3 += 40LL;
sockwrite(v4);
v5 = dccpos <= v2;
*(_BYTE *)(*(_QWORD *)(v3 - 40) + 1LL) = 2;
}
while ( !v5 );
return fixBrokenSocks(v4, a1);
}

original_code:
void dcc_closeall(char *msg)
{
 int i;
 for(i = 0; i < dccpos; i++) {
  sockwrite(dcclist[i].con, msg);
  dcclist[i].con->status = 2;
 }
 fixBrokenSocks();
}


decompiled_code:
__int64 __fastcall dcc_connected(int a1)
{
unsigned int v1; // ebp
__int64 *v2; // rbx
const char *v3; // rdx
__int64 result; // rax
__int64 v5; // rdi
__int64 v6; // rdi

v1 = a1 - 1000;
if ( dccpos > a1 - 1000 )
{
v2 = &dcclist[5 * (int)v1];
v3 = (const char *)v2[1];
if ( v3 )
{
if ( v2[4] )
{
sprintf(dccbuf, "%s is making a dcc connection with us.", (const char *)v2[4]);
sRelay_butone(dccbuf, v2[3]);
sprintf(
dccbuf,
"Welcome sweetypie, you are admin \"%s\" with level %d access.",
(const char *)v2[4],
*(unsigned int *)(v2[4] + 100));
sockwrite(v2[3]);
result = send_newpartyliner(v1, v2[4]);
}
else
{
sprintf(dccbuf, "%s(guest) is making a dcc connection with us.", v3);
sRelay_butone(dccbuf, v2[3]);
v5 = v2[3];
*(__m128i *)dccbuf = _mm_load_si128((const __m128i *)&LC11);
strcpy((char *)&qword_3420, "commands.");
xmmword_33F0 = (__int128)_mm_load_si128((const __m128i *)&LC12);
xmmword_3400 = (__int128)_mm_load_si128((const __m128i *)&LC13);
xmmword_3410 = (__int128)_mm_load_si128((const __m128i *)&LC14);
sockwrite(v5);
sprintf(dccbuf, "%s(guest)", (const char *)v2[1]);
result = send_newpartyliner(v1, dccbuf);
}
}
else
{
sprintf(dccbuf, "New user connected via telnet/reverse dcc. (%s)", (const char *)v2[2]);
sRelay(dccbuf);
v6 = v2[3];
strcpy((char *)&xmmword_3410, "nue...");
*(__m128i *)dccbuf = _mm_load_si128((const __m128i *)&LC8);
xmmword_33F0 = (__int128)_mm_load_si128((const __m128i *)&LC9);
xmmword_3400 = (__int128)_mm_load_si128((const __m128i *)&LC10);
result = sockwrite(v6);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
unsigned int v1; // ebp
__int64 *v2; // rbx
const char *v3; // rdx
__int64 result; // rax
__int64 v5; // rdi
__int64 v6; // rdi

v1 = a1 - 1000;
if ( dccpos > a1 - 1000 )
{
v2 = &dcclist[5 * (int)v1];
v3 = (const char *)v2[1];
if ( v3 )
{
if ( v2[4] )
{
sprintf(dccbuf, "%s is making a dcc connection with us.", (const char *)v2[4]);
sRelay_butone(dccbuf, v2[3]);
sprintf(
dccbuf,
"Welcome sweetypie, you are admin \"%s\" with level %d access.",
(const char *)v2[4],
*(unsigned int *)(v2[4] + 100));
sockwrite(v2[3]);
result = send_newpartyliner(v1, v2[4]);
}
else
{
sprintf(dccbuf, "%s(guest) is making a dcc connection with us.", v3);
sRelay_butone(dccbuf, v2[3]);
v5 = v2[3];
*(__m128i *)dccbuf = _mm_load_si128((const __m128i *)&LC11);
strcpy((char *)&qword_3420, "commands.");
xmmword_33F0 = (__int128)_mm_load_si128((const __m128i *)&LC12);
xmmword_3400 = (__int128)_mm_load_si128((const __m128i *)&LC13);
xmmword_3410 = (__int128)_mm_load_si128((const __m128i *)&LC14);
sockwrite(v5);
sprintf(dccbuf, "%s(guest)", (const char *)v2[1]);
result = send_newpartyliner(v1, dccbuf);
}
}
else
{
sprintf(dccbuf, "New user connected via telnet/reverse dcc. (%s)", (const char *)v2[2]);
sRelay(dccbuf);
v6 = v2[3];
strcpy((char *)&xmmword_3410, "nue...");
*(__m128i *)dccbuf = _mm_load_si128((const __m128i *)&LC8);
xmmword_33F0 = (__int128)_mm_load_si128((const __m128i *)&LC9);
xmmword_3400 = (__int128)_mm_load_si128((const __m128i *)&LC10);
result = sockwrite(v6);
}
}
return result;
}

original_code:
void dcc_connected(int id)
{
 id -= 1000;
 if(id >= dccpos)
  return;
 if(!dcclist[id].user) {
  sprintf(dccbuf, "New user connected via telnet/reverse dcc. (%s)", dcclist[id].host);
  sRelay(dccbuf);
  sprintf(dccbuf, "You need to auth (.login <user> <pass>) to continue...");
  sockwrite(dcclist[id].con, dccbuf);
 } else if(dcclist[id].adm) {
  sprintf(dccbuf, "%s is making a dcc connection with us.", dcclist[id].adm->nick);
  sRelay_butone(dccbuf, dcclist[id].con);
  sprintf(dccbuf, "Welcome sweetypie, you are admin \"%s\" with level %d access.", dcclist[id].adm->nick, dcclist[id].adm->level);
  sockwrite(dcclist[id].con, dccbuf);
  send_newpartyliner(id, dcclist[id].adm->nick);
 } else {
  sprintf(dccbuf, "%s(guest) is making a dcc connection with us.", dcclist[id].user);
  sRelay_butone(dccbuf, dcclist[id].con);
  sprintf(dccbuf, "Welcome. You are a guest here, therefore you cannot execute any commands.");
  sockwrite(dcclist[id].con, dccbuf);
  sprintf(dccbuf, "%s(guest)", dcclist[id].user);
  send_newpartyliner(id, dccbuf);
 }
}


decompiled_code:
__int64 __fastcall send_to_dcc_butone(int a1)
{
unsigned __int64 v2; // rbp
unsigned int v3; // er14
int v4; // ebx
__int64 v5; // rdi

if ( dccpos <= 0 )
return 0LL;
v2 = (unsigned int)((_DWORD)dcclist + 8);
v3 = 0;
v4 = 0;
do
{
if ( *(_QWORD *)v2 )
{
if ( a1 != v4 )
{
v5 = *(_QWORD *)(v2 + 16);
if ( v5 )
{
if ( *(_BYTE *)(v5 + 1) == 1 )
{
++v3;
sockwrite(v5);
}
}
}
}
++v4;
v2 += 40LL;
}
while ( dccpos > v4 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
unsigned __int64 v2; // rbp
unsigned int v3; // er14
int v4; // ebx
__int64 v5; // rdi

if ( dccpos <= 0 )
return 0LL;
v2 = (unsigned int)((_DWORD)dcclist + 8);
v3 = 0;
v4 = 0;
do
{
if ( *(_QWORD *)v2 )
{
if ( a1 != v4 )
{
v5 = *(_QWORD *)(v2 + 16);
if ( v5 )
{
if ( *(_BYTE *)(v5 + 1) == 1 )
{
++v3;
sockwrite(v5);
}
}
}
}
++v4;
v2 += 40LL;
}
while ( dccpos > v4 );
return v3;
}

original_code:
int send_to_dcc_butone(int did, char *line)
{
 int i, ret;
 for(i = ret = 0; i < dccpos; i++) {
  if(dcclist[i].user && (i != did) && dcclist[i].con && (dcclist[i].con->status == 1)) {
   sockwrite(dcclist[i].con, line);
   ret++;
  }
 }
 return ret;
}

canonical_original_code:
int send_to_dcc_butone(int did, char *line)
{
 int i; int ret;
 for(i = ret = 0; i < dccpos; i++) {
  if(dcclist[i].user && (i != did) && dcclist[i].con && (dcclist[i].con->status == 1)) {
   sockwrite(dcclist[i].con, line);
   ret++;
  }
 }
 return ret;
}

variable_types:
line
char *

variable_types: ret int


decompiled_code:
__int64 __fastcall send_to_dcc_butonesock(__int64 a1, __int64 a2, int a3)
{
unsigned __int64 v4; // rbx
unsigned int v5; // er14
int v6; // ebp
__int64 v7; // rdi

if ( dccpos <= 0 )
return 0;
v4 = (unsigned int)((_DWORD)dcclist + 8);
v5 = 0;
v6 = 0;
do
{
while ( 1 )
{
if ( *(_QWORD *)v4 )
{
v7 = *(_QWORD *)(v4 + 16);
if ( v7 != a2 && *(_BYTE *)(v7 + 1) == 1 && (a3 || *(_QWORD *)(v4 + 24)) )
break;
}
++v6;
v4 += 40LL;
if ( dccpos <= v6 )
return v5;
}
++v5;
++v6;
v4 += 40LL;
sockwrite(v7);
}
while ( dccpos > v6 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, int a3)
{
unsigned __int64 v4; // rbx
unsigned int v5; // er14
int v6; // ebp
__int64 v7; // rdi

if ( dccpos <= 0 )
return 0;
v4 = (unsigned int)((_DWORD)dcclist + 8);
v5 = 0;
v6 = 0;
do
{
while ( 1 )
{
if ( *(_QWORD *)v4 )
{
v7 = *(_QWORD *)(v4 + 16);
if ( v7 != a2 && *(_BYTE *)(v7 + 1) == 1 && (a3 || *(_QWORD *)(v4 + 24)) )
break;
}
++v6;
v4 += 40LL;
if ( dccpos <= v6 )
return v5;
}
++v5;
++v6;
v4 += 40LL;
sockwrite(v7);
}
while ( dccpos > v6 );
return v5;
}

original_code:
int send_to_dcc_butonesock(char *line, struct socket *sock, int for_guest)
{
 int i, ret;
 for(i = ret = 0; i < dccpos; i++) {
  if(dcclist[i].user && dcclist[i].con != sock && (dcclist[i].con->status == 1) && (for_guest || dcclist[i].adm)) {
   sockwrite(dcclist[i].con, line);
   ret++;
  }
 }
 return ret;
}

canonical_original_code:
int send_to_dcc_butonesock(char *line, struct socket *sock, int for_guest)
{
 int i; int ret;
 for(i = ret = 0; i < dccpos; i++) {
  if(dcclist[i].user && dcclist[i].con != sock && (dcclist[i].con->status == 1) && (for_guest || dcclist[i].adm)) {
   sockwrite(dcclist[i].con, line);
   ret++;
  }
 }
 return ret;
}

variable_types: struct socket { char type; char status; int id; int fd; int last_ts; int con_ts; char checkLink; char buffer[4096]; struct socket *next; } *


decompiled_code:
__int64 __fastcall send_to_all_dcc(__int64 a1, int a2)
{
unsigned __int64 v2; // rbx
unsigned int v3; // er13
int v4; // ebp
__int64 v5; // rdi

if ( dccpos <= 0 )
return 0LL;
v2 = (unsigned int)((_DWORD)dcclist + 8);
v3 = 0;
v4 = 0;
do
{
while ( 1 )
{
if ( *(_QWORD *)v2 )
{
v5 = *(_QWORD *)(v2 + 16);
if ( v5 )
{
if ( *(_BYTE *)(v5 + 1) == 1 && (a2 || *(_QWORD *)(v2 + 24)) )
break;
}
}
++v4;
v2 += 40LL;
if ( dccpos <= v4 )
return v3;
}
++v3;
++v4;
v2 += 40LL;
sockwrite(v5);
}
while ( dccpos > v4 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
unsigned __int64 v2; // rbx
unsigned int v3; // er13
int v4; // ebp
__int64 v5; // rdi

if ( dccpos <= 0 )
return 0LL;
v2 = (unsigned int)((_DWORD)dcclist + 8);
v3 = 0;
v4 = 0;
do
{
while ( 1 )
{
if ( *(_QWORD *)v2 )
{
v5 = *(_QWORD *)(v2 + 16);
if ( v5 )
{
if ( *(_BYTE *)(v5 + 1) == 1 && (a2 || *(_QWORD *)(v2 + 24)) )
break;
}
}
++v4;
v2 += 40LL;
if ( dccpos <= v4 )
return v3;
}
++v3;
++v4;
v2 += 40LL;
sockwrite(v5);
}
while ( dccpos > v4 );
return v3;
}

original_code:
int send_to_all_dcc(char *line, int for_guest)
{
 int i, ret;
 for(i = ret = 0; i < dccpos; i++) {
  if(dcclist[i].user && dcclist[i].con && (dcclist[i].con->status == 1) && (for_guest || dcclist[i].adm)) {
   sockwrite(dcclist[i].con, line);
   ret++;
  }
 }
 return ret;
}

canonical_original_code:
int send_to_all_dcc(char *line, int for_guest)
{
 int i; int ret;
 for(i = ret = 0; i < dccpos; i++) {
  if(dcclist[i].user && dcclist[i].con && (dcclist[i].con->status == 1) && (for_guest || dcclist[i].adm)) {
   sockwrite(dcclist[i].con, line);
   ret++;
  }
 }
 return ret;
}


parseDCC

decompiled_code:
void __fastcall parseDCC(int a1, const char *a2)
{
int v2; // ebp
__int64 v4; // rsi
__int64 *v5; // rbx
int v6; // eax
bool v7; // zf
const char *v8; // rdx
__int64 v9; // rdi
const char *v10; // rdi
const char *v11; // r12
__int64 v12; // rdi
int v13; // [rsp+Ch] [rbp-DACh] BYREF
char v14[528]; // [rsp+10h] [rbp-DA8h] BYREF
char v15[66]; // [rsp+220h] [rbp-B98h] BYREF
char v16[814]; // [rsp+262h] [rbp-B56h] BYREF
__int64 v17[261]; // [rsp+590h] [rbp-828h] BYREF

v2 = a1 - 1000;
if ( dccpos > a1 - 1000 && *a2 )
{
v4 = dcclist[5 * v2 + 1];
if ( v4 )
mystrncpy(v15, v4, 33LL);
else
v15[0] = 0;
v5 = &dcclist[5 * v2];
mystrncpy(v16, v5[2], 256LL);
v15[33] = 0;
v16[256] = 0;
mystrncpy(v14, a2, 513LL);
memset(v17, 0, 0x800uLL);
v6 = tokenize(v14, " ", &v17[3], 253LL);
v7 = *a2 == 46;
v13 = v6 + 3;
if ( v7 )
{
if ( v5[4] || !strcmp((const char *)v17[3], ".login") || !strcmp((const char *)v17[3], ".who") )
admin_msg(v15, a2 + 1, v17, &v13, v5[3]);
else
sockwrite(v5[3]);
}
else
{
v8 = (const char *)v5[1];
if ( v8 )
{
if ( !memcmp((const void *)v17[3], &unk_4456, 8uLL) )
{
v10 = a2;
v11 = a2 + 8;
v11[strlen(v10) - 9] = 0;
v12 = v5[4];
if ( v12 )
{
send_partylineaction(v12, v11);
sprintf(dccbuf, "* %s %s", (const char *)v5[4], v11);
}
else
{
sprintf(dccbuf, "%s(guest)", (const char *)v5[1]);
send_partylineaction(dccbuf, v11);
sprintf(dccbuf, "* %s(guest) %s", (const char *)v5[1], v11);
}
}
else
{
v9 = v5[4];
if ( v9 )
{
send_partylinemsg(v9, a2);
sprintf(dccbuf, "<%s> %s", (const char *)v5[4], a2);
}
else
{
sprintf(dccbuf, "%s(guest)", v8);
send_partylinemsg(dccbuf, a2);
sprintf(dccbuf, "<%s(guest)> %s", (const char *)v5[1], a2);
}
}
send_to_dcc_butone(v2);
}
}
}
}

canonical_decompiled_code:
void __fastcall func12(int a1, const char *a2)
{
int v2; // ebp
__int64 v4; // rsi
__int64 *v5; // rbx
int v6; // eax
bool v7; // zf
const char *v8; // rdx
__int64 v9; // rdi
const char *v10; // rdi
const char *v11; // r12
__int64 v12; // rdi
int v13; // [rsp+Ch] [rbp-DACh] BYREF
char v14[528]; // [rsp+10h] [rbp-DA8h] BYREF
char v15[66]; // [rsp+220h] [rbp-B98h] BYREF
char v16[814]; // [rsp+262h] [rbp-B56h] BYREF
__int64 v17[261]; // [rsp+590h] [rbp-828h] BYREF

v2 = a1 - 1000;
if ( dccpos > a1 - 1000 && *a2 )
{
v4 = dcclist[5 * v2 + 1];
if ( v4 )
mystrncpy(v15, v4, 33LL);
else
v15[0] = 0;
v5 = &dcclist[5 * v2];
mystrncpy(v16, v5[2], 256LL);
v15[33] = 0;
v16[256] = 0;
mystrncpy(v14, a2, 513LL);
memset(v17, 0, 0x800uLL);
v6 = tokenize(v14, " ", &v17[3], 253LL);
v7 = *a2 == 46;
v13 = v6 + 3;
if ( v7 )
{
if ( v5[4] || !strcmp((const char *)v17[3], ".login") || !strcmp((const char *)v17[3], ".who") )
admin_msg(v15, a2 + 1, v17, &v13, v5[3]);
else
sockwrite(v5[3]);
}
else
{
v8 = (const char *)v5[1];
if ( v8 )
{
if ( !memcmp((const void *)v17[3], &unk_4456, 8uLL) )
{
v10 = a2;
v11 = a2 + 8;
v11[strlen(v10) - 9] = 0;
v12 = v5[4];
if ( v12 )
{
send_partylineaction(v12, v11);
sprintf(dccbuf, "* %s %s", (const char *)v5[4], v11);
}
else
{
sprintf(dccbuf, "%s(guest)", (const char *)v5[1]);
send_partylineaction(dccbuf, v11);
sprintf(dccbuf, "* %s(guest) %s", (const char *)v5[1], v11);
}
}
else
{
v9 = v5[4];
if ( v9 )
{
send_partylinemsg(v9, a2);
sprintf(dccbuf, "<%s> %s", (const char *)v5[4], a2);
}
else
{
sprintf(dccbuf, "%s(guest)", v8);
send_partylinemsg(dccbuf, a2);
sprintf(dccbuf, "<%s(guest)> %s", (const char *)v5[1], a2);
}
}
func8(v2);
}
}
}
}

original_code:
void parseDCC(int id, char *line)
{
 char tokenline[513];
 char *tokens[256];
 int numtok;
 sUser theUser;
 id -= 1000;
 if(id >= dccpos)
  return;
 if(!*line)
  return;
 if(dcclist[id].user)
  mystrncpy(theUser.nick, dcclist[id].user, 33);
 else
  strcpy(theUser.nick, "");
 mystrncpy(theUser.host, dcclist[id].host, 256);
 theUser.ident[0] = 0;
 theUser.mask[0] = 0;
 mystrncpy(tokenline, line, 513);
 memset(tokens, 0, sizeof(tokens) );
 numtok = tokenize(tokenline, " ", &tokens[3], 256 -3) + 3;
 if(*line == '.') {
  if(dcclist[id].adm || !strcmp(tokens[3], ".login") || !strcmp(tokens[3], ".who"))
   admin_msg(&theUser, line + 1, tokens, &numtok, dcclist[id].con, dcclist[id].adm);
  else
   sockwrite(dcclist[id].con, "You are a guest, you may not execute commands here.");
 } else if(dcclist[id].user) {
  if(!strcmp(tokens[3], "\001ACTION")) {
   line[strlen(line)-1] = 0;
   if(dcclist[id].adm) {
    send_partylineaction(dcclist[id].adm->nick, line + 8);
    sprintf(dccbuf, "* %s %s", dcclist[id].adm->nick, line + 8);
   } else {
    sprintf(dccbuf, "%s(guest)", dcclist[id].user);
    send_partylineaction(dccbuf, line + 8);
    sprintf(dccbuf, "* %s(guest) %s", dcclist[id].user, line + 8);
   }
  } else {
   if(dcclist[id].adm) {
    send_partylinemsg(dcclist[id].adm->nick, line);
    sprintf(dccbuf, "<%s> %s", dcclist[id].adm->nick, line);
   } else {
    sprintf(dccbuf, "%s(guest)", dcclist[id].user);
    send_partylinemsg(dccbuf, line);
    sprintf(dccbuf, "<%s(guest)> %s", dcclist[id].user, line);
   }
  }
  send_to_dcc_butone(id, dccbuf);
 }
}

canonical_original_code:
void parseDCC(int id, char *line)
{
 char tokenline[513];
 char *tokens[256];
 int numtok;
 struct ircUser theUser;
 id -= 1000;
 if(id >= dccpos)
  return;
 if(!*line)
  return;
 if(dcclist[id].user)
  mystrncpy(theUser.nick, dcclist[id].user, 33);
 else
  strcpy(theUser.nick, "");
 mystrncpy(theUser.host, dcclist[id].host, 256);
 theUser.ident[0] = 0;
 theUser.mask[0] = 0;
 mystrncpy(tokenline, line, 513);
 memset(tokens, 0, sizeof(tokens) );
 numtok = tokenize(tokenline, " ", &tokens[3], 256 -3) + 3;
 if(*line == '.') {
  if(dcclist[id].adm || !strcmp(tokens[3], ".login") || !strcmp(tokens[3], ".who"))
   admin_msg(&theUser, line + 1, tokens, &numtok, dcclist[id].con, dcclist[id].adm);
  else
   sockwrite(dcclist[id].con, "You are a guest, you may not execute commands here.");
 } else if(dcclist[id].user) {
  if(!strcmp(tokens[3], "\001ACTION")) {
   line[strlen(line)-1] = 0;
   if(dcclist[id].adm) {
    send_partylineaction(dcclist[id].adm->nick, line + 8);
    sprintf(dccbuf, "* %s %s", dcclist[id].adm->nick, line + 8);
   } else {
    sprintf(dccbuf, "%s(guest)", dcclist[id].user);
    send_partylineaction(dccbuf, line + 8);
    sprintf(dccbuf, "* %s(guest) %s", dcclist[id].user, line + 8);
   }
  } else {
   if(dcclist[id].adm) {
    send_partylinemsg(dcclist[id].adm->nick, line);
    sprintf(dccbuf, "<%s> %s", dcclist[id].adm->nick, line);
   } else {
    sprintf(dccbuf, "%s(guest)", dcclist[id].user);
    send_partylinemsg(dccbuf, line);
    sprintf(dccbuf, "<%s(guest)> %s", dcclist[id].user, line);
   }
  }
  send_to_dcc_butone(id, dccbuf);
 }
}

user_defined_types: struct ircUser { char nick[33]; char ident[33]; char host[256]; char mask[512]; char gnuUser[32]; }


decompiled_code:
void setup_queue()
{
qword_1B40 = 0LL;
bper = 0;
bytets = 0;
}

canonical_decompiled_code:
void func0()
{
qword_1B40 = 0LL;
bper = 0;
bytets = 0;
}

original_code:
void setup_queue()
{
 sendQ.highSize = sendQ.lowSize = 0;
 bytets = bper = 0;
 return;
}


decompiled_code:
void reset_queue()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rax

if ( (int)qword_1B40 > 0 )
{
v0 = 0LL;
do
{
v1 = v0++;
free((&sendQ)[2 * v1]);
}
while ( (int)qword_1B40 > (int)v0 );
}
if ( SHIDWORD(qword_1B40) > 0 )
{
v2 = 0LL;
do
{
v3 = v2++;
free((&dest)[2 * v3]);
}
while ( SHIDWORD(qword_1B40) > (int)v2 );
}
setup_queue();
}

canonical_decompiled_code:
void func1()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rax

if ( (int)qword_1B40 > 0 )
{
v0 = 0LL;
do
{
v1 = v0++;
free((&sendQ)[2 * v1]);
}
while ( (int)qword_1B40 > (int)v0 );
}
if ( SHIDWORD(qword_1B40) > 0 )
{
v2 = 0LL;
do
{
v3 = v2++;
free((&dest)[2 * v3]);
}
while ( SHIDWORD(qword_1B40) > (int)v2 );
}
func0();
}

original_code:
void reset_queue()
{
 int i;
 for(i = 0; i < sendQ.highSize; i++)
  free(sendQ.high[i].message);
 for(i = 0; i < sendQ.lowSize; i++)
  free(sendQ.low[i].message);
 setup_queue();
}


highMsg

decompiled_code:
__int64 __fastcall highMsg(void *src)
{
__int64 v1; // rbx
unsigned __int64 v2; // rbx
size_t v3; // r12
char *v4; // rax
__int64 result; // rax

v1 = (int)qword_1B40;
LODWORD(qword_1B40) = qword_1B40 + 1;
if ( (int)v1 > 127 )
{
LODWORD(qword_1B40) = v1;
result = fwrite("Max sendQ exceeded (high).\n", 1uLL, 0x1BuLL, out);
}
else
{
v2 = 16 * v1;
v3 = (int)(strlen((const char *)src) + 1);
dword_348[v2 / 4] = time(0LL);
v4 = (char *)myalloc(v3);
(&sendQ)[v2 / 8] = v4;
result = (__int64)memcpy(v4, src, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *src)
{
__int64 v1; // rbx
unsigned __int64 v2; // rbx
size_t v3; // r12
char *v4; // rax
__int64 result; // rax

v1 = (int)qword_1B40;
LODWORD(qword_1B40) = qword_1B40 + 1;
if ( (int)v1 > 127 )
{
LODWORD(qword_1B40) = v1;
result = fwrite("Max sendQ exceeded (high).\n", 1uLL, 0x1BuLL, out);
}
else
{
v2 = 16 * v1;
v3 = (int)(strlen((const char *)src) + 1);
dword_348[v2 / 4] = time(0LL);
v4 = (char *)myalloc(v3);
(&sendQ)[v2 / 8] = v4;
result = (__int64)memcpy(v4, src, v3);
}
return result;
}

original_code:
void highMsg(char *message)
{
 int size;
 int pos = sendQ.highSize++;
 if(pos >= 128)
 {
  sendQ.highSize--;
  fprintf(out, "Max sendQ exceeded (high).\n");
  return;
 }
 size = strlen(message) + 1;
 sendQ.high[pos].ts = (int)time(0);
 sendQ.high[pos].message = myalloc(size * sizeof(char));
 memcpy(sendQ.high[pos].message, message, size);
 return;
}

variable_types: size int

variable_types: pos int


lowMsg

decompiled_code:
__int64 __fastcall lowMsg(void *src)
{
__int64 v1; // rbx
unsigned __int64 v2; // rbx
size_t v3; // r12
char *v4; // rax
__int64 result; // rax

v1 = SHIDWORD(qword_1B40);
++HIDWORD(qword_1B40);
if ( (int)v1 > 255 )
{
HIDWORD(qword_1B40) = v1;
result = fwrite("Max sendQ exceeded (low).\n", 1uLL, 0x1AuLL, out);
}
else
{
v2 = 16 * (v1 + 128);
v3 = (int)(strlen((const char *)src) + 1);
dword_348[v2 / 4] = time(0LL);
v4 = (char *)myalloc(v3);
(&sendQ)[v2 / 8] = v4;
result = (__int64)memcpy(v4, src, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *src)
{
__int64 v1; // rbx
unsigned __int64 v2; // rbx
size_t v3; // r12
char *v4; // rax
__int64 result; // rax

v1 = SHIDWORD(qword_1B40);
++HIDWORD(qword_1B40);
if ( (int)v1 > 255 )
{
HIDWORD(qword_1B40) = v1;
result = fwrite("Max sendQ exceeded (low).\n", 1uLL, 0x1AuLL, out);
}
else
{
v2 = 16 * (v1 + 128);
v3 = (int)(strlen((const char *)src) + 1);
dword_348[v2 / 4] = time(0LL);
v4 = (char *)myalloc(v3);
(&sendQ)[v2 / 8] = v4;
result = (__int64)memcpy(v4, src, v3);
}
return result;
}

original_code:
void lowMsg(char *message)
{
 int size;
 int pos = sendQ.lowSize++;
 if(pos >= 256)
 {
  sendQ.lowSize--;
  fprintf(out, "Max sendQ exceeded (low).\n");
  return;
 }
 size = strlen(message) + 1;
 sendQ.low[pos].ts = (int)time(0);
 sendQ.low[pos].message = myalloc(size * sizeof(char));
 memcpy(sendQ.low[pos].message, message, size);
 return;
}


popMsg

decompiled_code:
time_t popMsg()
{
time_t v0; // rbx
time_t result; // rax
time_t v2; // rbx
bool v3; // cc
int v4; // ebx
char *v5; // rbp
time_t v6; // rbx
char *v7; // rbp

v0 = bytets;
if ( v0 >= time(0LL) - 1 )
{
result = bper;
goto LABEL_3;
}
bytets = time(0LL);
if ( bper > 74 )
{
result = (unsigned int)(bper - 75);
bper -= 75;
LABEL_3:
if ( (int)result > 1000 )
return result;
}
if ( (_DWORD)qword_1B40 )
{
v2 = lastMsg;
result = time(0LL) - 1;
v3 = v2 < result;
v4 = bper;
if ( v3 || bper <= 599 )
{
v5 = sendQ;
bper = strlen(sendQ) + v4;
irc_write(v5);
free(sendQ);
LODWORD(qword_1B40) = qword_1B40 - 1;
result = (time_t)memcpy(&sendQ, &unk_350, 16LL * (int)qword_1B40);
}
}
else
{
result = HIDWORD(qword_1B40);
if ( SHIDWORD(qword_1B40) > 0 )
{
v6 = lastMsg;
result = time(0LL) - 2;
if ( v6 < result )
{
v7 = dest;
bper += strlen(dest);
irc_write(v7);
free(dest);
--HIDWORD(qword_1B40);
result = (time_t)memcpy(&dest, &unk_B50, 16LL * SHIDWORD(qword_1B40));
}
}
}
return result;
}

canonical_decompiled_code:
time_t func4()
{
time_t v0; // rbx
time_t result; // rax
time_t v2; // rbx
bool v3; // cc
int v4; // ebx
char *v5; // rbp
time_t v6; // rbx
char *v7; // rbp

v0 = bytets;
if ( v0 >= time(0LL) - 1 )
{
result = bper;
goto LABEL_3;
}
bytets = time(0LL);
if ( bper > 74 )
{
result = (unsigned int)(bper - 75);
bper -= 75;
LABEL_3:
if ( (int)result > 1000 )
return result;
}
if ( (_DWORD)qword_1B40 )
{
v2 = lastMsg;
result = time(0LL) - 1;
v3 = v2 < result;
v4 = bper;
if ( v3 || bper <= 599 )
{
v5 = sendQ;
bper = strlen(sendQ) + v4;
irc_write(v5);
free(sendQ);
LODWORD(qword_1B40) = qword_1B40 - 1;
result = (time_t)memcpy(&sendQ, &unk_350, 16LL * (int)qword_1B40);
}
}
else
{
result = HIDWORD(qword_1B40);
if ( SHIDWORD(qword_1B40) > 0 )
{
v6 = lastMsg;
result = time(0LL) - 2;
if ( v6 < result )
{
v7 = dest;
bper += strlen(dest);
irc_write(v7);
free(dest);
--HIDWORD(qword_1B40);
result = (time_t)memcpy(&dest, &unk_B50, 16LL * SHIDWORD(qword_1B40));
}
}
}
return result;
}

original_code:
void popMsg()
{
 if(bytets < time(((void *)0)) - 1)
 {
  bytets = time(((void *)0));
  if(bper >= 75)
   bper -= 75;
 }
 if(bper > 1000)
  return;
 if(sendQ.highSize == 0)
 {
  if((sendQ.lowSize > 0) && (lastMsg < time(0) - 2))
  {
   bper += strlen(sendQ.low[0].message);
   irc_write(sendQ.low[0].message);
   free(sendQ.low[0].message);
   memcpy(sendQ.low, &sendQ.low[1], --sendQ.lowSize * sizeof(struct nodeQ) );
  }
 } else if( (lastMsg < time(0) - 1) || (bper < 600) ) {
  bper += strlen(sendQ.high[0].message);
  irc_write(sendQ.high[0].message);
  free(sendQ.high[0].message);
  memcpy(sendQ.high, &sendQ.high[1], --sendQ.highSize * sizeof(struct nodeQ) );
 }
 return;
}


quickMsg

decompiled_code:
__int64 __fastcall quickMsg(void *a1)
{
__int64 result; // rax

if ( bper <= 800 )
result = irc_write(a1);
else
result = highMsg(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *a1)
{
__int64 result; // rax

if ( bper <= 800 )
result = irc_write(a1);
else
result = func2(a1);
return result;
}

original_code:
void quickMsg(char *message)
{
 if(bper > 800)
  highMsg(message);
 else
  irc_write(message);
 return;
}


decompiled_code:
__int64 logout_all_admins()
{
__int64 result; // rax

for ( result = admins[13]; result; result = *(_QWORD *)(result + 104) )
*(_BYTE *)(result + 67) = 0;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

for ( result = admins[13]; result; result = *(_QWORD *)(result + 104) )
*(_BYTE *)(result + 67) = 0;
return result;
}

original_code:
void logout_all_admins()
{
 struct sadmin *i;
 i = admins.next;
 while(i)
 {
  i->actualNick[0] = 0;
  i = i->next;
 }
 return;
}


decompiled_code:
__int64 count_admins()
{
__int64 v0; // rax
unsigned int i; // er8

v0 = admins[13];
for ( i = 0; v0; ++i )
v0 = *(_QWORD *)(v0 + 104);
return i;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
unsigned int i; // er8

v0 = admins[13];
for ( i = 0; v0; ++i )
v0 = *(_QWORD *)(v0 + 104);
return i;
}

original_code:
int count_admins()
{
 struct sadmin *i;
 int count = 0;
 i = &admins;
 while(i->next)
 {
  count++;
  i = i->next;
 }
 return count;
}

variable_types: count int


findActualAdmin

decompiled_code:
__int64 __fastcall findActualAdmin(char *s2)
{
__int64 i; // r12

for ( i = admins[13]; i; i = *(_QWORD *)(i + 104) )
{
if ( !strcmp((const char *)(i + 67), s2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2)
{
__int64 i; // r12

for ( i = admins[13]; i; i = *(_QWORD *)(i + 104) )
{
if ( !strcmp((const char *)(i + 67), s2) )
break;
}
return i;
}

original_code:
struct sadmin *findActualAdmin(char *name)
{
 struct sadmin *i;
 i = admins.next;
 while(i != ((void *)0))
 {
  if(!strcmp(i->actualNick, name))
   return i;
  i = i->next;
 }
 return ((void *)0);
}

variable_types:
name
char *

return_type: struct sadmin { char nick[33]; char pass[-1]; char actualNick[33]; int level; struct sadmin *next; struct sadmin *prev; } *


passCheck

decompiled_code:
_BOOL8 __fastcall passCheck(const char *a1, const char *a2)
{
char *v2; // r12
size_t v3; // rax

v2 = crypt(a1, a2);
v3 = strlen(a2);
return strncmp(v2, a2, v3) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1, const char *a2)
{
char *v2; // r12
size_t v3; // rax

v2 = crypt(a1, a2);
v3 = strlen(a2);
return strncmp(v2, a2, v3) == 0;
}

original_code:
int passCheck(char *supplied, char *hash)
{
 char *hash2 = crypt(supplied, hash);
 return !strncmp(hash2, hash, strlen(hash));
}

variable_types:
supplied
char *

variable_types:
hash
char *


passCrypt

decompiled_code:
char *__fastcall passCrypt(char *key)
{
unsigned __int64 v1; // rbx
__pid_t v2; // eax
char *v3; // rsi
unsigned int v4; // edx
unsigned int v5; // eax
unsigned int v6; // ecx
char v7; // al
char salt[12]; // [rsp+4h] [rbp-34h] BYREF
__int64 v10[5]; // [rsp+10h] [rbp-28h]

strcpy(salt, "$1$........");
v1 = time(0LL);
v10[0] = v1;
v2 = getpid();
v3 = &salt[3];
v4 = 0;
v10[1] = v2 ^ (v1 >> 14) & 0x30000;
v5 = 0;
while ( 1 )
{
++v3;
v6 = 5 * (v5 / 5);
v7 = v4++;
*(v3 - 1) = byte_7C8[(v1 >> (6 * (v7 - (unsigned __int8)v6))) & 0x3F];
if ( v4 == 8 )
break;
v5 = v4;
v1 = v10[v4 / 5uLL];
}
return crypt(key, salt);
}

canonical_decompiled_code:
char *__fastcall func5(char *key)
{
unsigned __int64 v1; // rbx
__pid_t v2; // eax
char *v3; // rsi
unsigned int v4; // edx
unsigned int v5; // eax
unsigned int v6; // ecx
char v7; // al
char salt[12]; // [rsp+4h] [rbp-34h] BYREF
__int64 v10[5]; // [rsp+10h] [rbp-28h]

strcpy(salt, "$1$........");
v1 = time(0LL);
v10[0] = v1;
v2 = getpid();
v3 = &salt[3];
v4 = 0;
v10[1] = v2 ^ (v1 >> 14) & 0x30000;
v5 = 0;
while ( 1 )
{
++v3;
v6 = 5 * (v5 / 5);
v7 = v4++;
*(v3 - 1) = byte_7C8[(v1 >> (6 * (v7 - (unsigned __int8)v6))) & 0x3F];
if ( v4 == 8 )
break;
v5 = v4;
v1 = v10[v4 / 5uLL];
}
return crypt(key, salt);
}

original_code:
char *passCrypt(char *in)
{
 unsigned long seed[2];
 char salt[] = "$1$........";
 const char *seedchars = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 int i;
 seed[0] = time(((void *)0));
 seed[1] = getpid() ^ (seed[0] >> 14 & 0x30000);
 for (i = 0; i < 8; i++)
  salt[3+i] = seedchars[(seed[i/5] >> (i%5)*6) & 0x3f];
 return crypt(in, salt);
}

canonical_original_code:
char *passCrypt(char *in)
{
 unsigned long seed[2];
 char salt[] = "$1$........";
 char *seedchars = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 int i;
 seed[0] = time(((void *)0));
 seed[1] = getpid() ^ (seed[0] >> 14 & 0x30000);
 for (i = 0; i < 8; i++)
  salt[3+i] = seedchars[(seed[i/5] >> (i%5)*6) & 0x3f];
 return crypt(in, salt);
}

variable_types:
in
char *

variable_types:
seed
unsigned long [2]

variable_types:
salt
char []

variable_types:
seedchars
char *


findAdmin

decompiled_code:
__int64 __fastcall findAdmin(__int64 a1)
{
__int64 v1; // r12

v1 = admins[13];
if ( !v1 )
return 0LL;
while ( !(unsigned int)strmi(a1, v1) )
{
v1 = *(_QWORD *)(v1 + 104);
if ( !v1 )
return 0LL;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // r12

v1 = admins[13];
if ( !v1 )
return 0LL;
while ( !(unsigned int)strmi(a1, v1) )
{
v1 = *(_QWORD *)(v1 + 104);
if ( !v1 )
return 0LL;
}
return v1;
}

original_code:
struct sadmin *findAdmin(char *nick)
{
 struct sadmin *i;
 i = admins.next;
 while(i != ((void *)0))
 {
  if(strmi(nick, i->nick))
   return i;
  i = i->next;
 }
 return ((void *)0);
}

variable_types:
nick
char *


original_code:
int adm_add(char *user, char *pass, int level)
{
 struct sadmin *temp, *i;
 if(findAdmin(user))
  return 0;
 if(strlen(user) > 128)
  return 0;
 temp = (struct sadmin *)myalloc(sizeof(struct sadmin));
 temp->next = ((void *)0);
 temp->actualNick[0] = 0;
 mystrncpy(temp->nick, user, 33);
 mystrncpy(temp->pass, pass, 33 +1);
 temp->level = level;
 i = &admins;
 while(i->next != ((void *)0))
  i = i->next;
 i->next = temp;
 temp->prev = i;
 return 1;
}

canonical_original_code:
int adm_add(char *user, char *pass, int level)
{
 struct sadmin *temp; struct sadmin *i;
 if(findAdmin(user))
  return 0;
 if(strlen(user) > 128)
  return 0;
 temp = (struct sadmin *)myalloc(sizeof(struct sadmin));
 temp->next = ((void *)0);
 temp->actualNick[0] = 0;
 mystrncpy(temp->nick, user, 33);
 mystrncpy(temp->pass, pass, 33 +1);
 temp->level = level;
 i = &admins;
 while(i->next != ((void *)0))
  i = i->next;
 i->next = temp;
 temp->prev = i;
 return 1;
}

variable_types:
user
char *

variable_types:
pass
char *

variable_types: level int


decompiled_code:
__int64 __fastcall adm_del(__int64 a1)
{
_QWORD *v1; // rbp
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rdx

v1 = (_QWORD *)findAdmin(a1);
result = 0LL;
if ( v1 )
{
admin_deleted(v1);
v3 = v1[13];
if ( v3 )
*(_QWORD *)(v3 + 112) = v1[14];
v4 = v1[14];
if ( v4 )
*(_QWORD *)(v4 + 104) = v3;
free(v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
_QWORD *v1; // rbp
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rdx

v1 = (_QWORD *)func6(a1);
result = 0LL;
if ( v1 )
{
admin_deleted(v1);
v3 = v1[13];
if ( v3 )
*(_QWORD *)(v3 + 112) = v1[14];
v4 = v1[14];
if ( v4 )
*(_QWORD *)(v4 + 104) = v3;
free(v1);
result = 1LL;
}
return result;
}

original_code:
int adm_del(char *admin)
{
 struct sadmin *d = findAdmin(admin);
 if(!d)
  return 0;
 admin_deleted(d);
 if(d->next)
  d->next->prev = d->prev;
 if(d->prev)
  d->prev->next = d->next;
 free(d);
 return 1;
}

variable_types:
admin
char *

variable_types: struct sadmin { char nick[33]; char pass[-1]; char actualNick[33]; int level; struct sadmin *next; struct sadmin *prev; } *


decompiled_code:
__int64 clear_admins()
{
__int64 i; // rbx
__int64 result; // rax

for ( i = admins[13]; i; i = *(_QWORD *)(i + 104) )
result = adm_del(i);
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 i; // rbx
__int64 result; // rax

for ( i = admins[13]; i; i = *(_QWORD *)(i + 104) )
result = func9(i);
return result;
}

original_code:
void clear_admins()
{
 struct sadmin *i, *fr;
 i = &admins;
 while(i->next)
 {
  fr = i->next;
  adm_del(fr->nick);
  i = fr;
 }
 return;
}

canonical_original_code:
void clear_admins()
{
 struct sadmin *i; struct sadmin *fr;
 i = &admins;
 while(i->next)
 {
  fr = i->next;
  adm_del(fr->nick);
  i = fr;
 }
 return;
}


giveAdminStatus

decompiled_code:
void __fastcall giveAdminStatus(const char *a1, int *a2)
{
__int64 i; // rbx
const char *v3; // rdx
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

for ( i = chans[24]; i; i = *(_QWORD *)(i + 192) )
{
if ( *(_QWORD *)(i + 176) && strchr((const char *)(i + 8), 65) )
{
v3 = *(const char **)i;
if ( *a2 > 99 )
sprintf(v4, "MODE %s +o %s", v3, a1);
else
sprintf(v4, "MODE %s +v %s", v3, a1);
lowMsg(v4);
}
}
}

canonical_decompiled_code:
void __fastcall func11(const char *a1, int *a2)
{
__int64 i; // rbx
const char *v3; // rdx
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

for ( i = chans[24]; i; i = *(_QWORD *)(i + 192) )
{
if ( *(_QWORD *)(i + 176) && strchr((const char *)(i + 8), 65) )
{
v3 = *(const char **)i;
if ( *a2 > 99 )
sprintf(v4, "MODE %s +o %s", v3, a1);
else
sprintf(v4, "MODE %s +v %s", v3, a1);
lowMsg(v4);
}
}
}

original_code:
void giveAdminStatus(char *nick, int *level)
{
 char modeBuf[256];
 struct chanRec *i = chans.next;
 while(i)
 {
  if(i->physical && strchr(i->flags, 'A'))
  {
   if(*level >= 100)
    sprintf(modeBuf, "MODE %s +o %s", i->name, nick);
   else
    sprintf(modeBuf, "MODE %s +v %s", i->name, nick);
   lowMsg(modeBuf);
  }
  i = i->next;
 }
 return;
}

variable_types:
level
int *

variable_types:
modeBuf
char [256]

variable_types: struct chanRec { char *name; char flags[-1]; char key[-1]; char goodModes[-1]; char badModes[-1]; struct schan { char *name; char topic[-1]; char modes[-1]; char key[-1]; int limit; int tsLim; struct criminalRecord { char nick[33]; char *identhost; char longTerm; char shortTerm; int laststamp; int lastJoin; int njoins; struct repeat { int id; int ts; char count; } trackrepeat[30]; struct criminalRecord *prev; struct criminalRecord *next; } *nortyusers; struct sban { char *mask; char *setby; int ts; struct sban *next; struct sban *prev; } *bans; struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; } *user; int userSize; int banSize; int flood_last; int flood_lines; struct schan *next; struct schan *prev; struct chanRec *record; } *physical; struct softBan { char *banmask; char *reason; char type; char *setby; int expires; struct softBan *next; struct softBan *prev; } *softbans; struct chanRec *next; struct chanRec *prev; } *

user_defined_types: struct chanRec { char *name; char flags[-1]; char key[-1]; char goodModes[-1]; char badModes[-1]; struct schan *physical; struct softBan *softbans; struct chanRec *next; struct chanRec *prev; }

user_defined_types: struct schan { char *name; char topic[-1]; char modes[-1]; char key[-1]; int limit; int tsLim; struct criminalRecord *nortyusers; struct sban *bans; struct suser *user; int userSize; int banSize; int flood_last; int flood_lines; struct schan *next; struct schan *prev; struct chanRec *record; }

user_defined_types: struct criminalRecord { char nick[33]; char *identhost; char longTerm; char shortTerm; int laststamp; int lastJoin; int njoins; struct repeat trackrepeat[30]; struct criminalRecord *prev; struct criminalRecord *next; }


checkLogin

decompiled_code:
__int64 __fastcall checkLogin(const char *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rax
__int64 v7; // r12

*(_BYTE *)(a2 + 33) = 0;
*(_BYTE *)(a3 + 34) = 0;
v6 = findAdmin(a2);
if ( !v6 )
return 0LL;
v7 = v6;
if ( !passCheck((const char *)a3, (const char *)(v6 + 33)) )
return 0LL;
if ( !a4 )
{
mystrncpy(v7 + 67, a1, 33LL);
giveAdminStatus(a1, (int *)(v7 + 100));
}
return v7;
}

original_code:
struct sadmin *checkLogin(char *nick, char *user, char *pass, struct socket *dcc)
{
 struct sadmin *i;
 user[33] = 0;
 pass[33 +1] = 0;
 i = findAdmin(user);
 if(i)
 {
  if(passCheck(pass, i->pass))
  {
   if(!dcc) {
    mystrncpy(i->actualNick, nick, 33);
    giveAdminStatus(nick, &i->level);
   }
   return i;
  }
 }
 return ((void *)0);
}

variable_types: struct socket { char type; char status; int id; int fd; int last_ts; int con_ts; char checkLink; char buffer[4096]; struct socket *next; } *


decompiled_code:
__int64 __fastcall automagic_login(const char *a1, const char *a2)
{
__int64 v2; // rax
__int64 v3; // r12
char v5[552]; // [rsp+0h] [rbp-228h] BYREF

v2 = findAdmin((__int64)a1);
v3 = v2;
if ( !v2 )
return v3;
if ( *(_BYTE *)(v2 + 67) )
return 0LL;
mystrncpy(v2 + 67, a2, 33LL);
sprintf(
v5,
"NOTICE %s :You have been automagically logged in via service account '%s'. Access level: %d",
a2,
a1,
*(unsigned int *)(v3 + 100));
lowMsg(v5);
sprintf(
v5,
"%s has been automagically logged in via server account '%s'. Level: %d.",
a2,
a1,
*(unsigned int *)(v3 + 100));
sRelay(v5);
giveAdminStatus(a2, (int *)(v3 + 100));
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func13(const char *a1, const char *a2)
{
__int64 v2; // rax
__int64 v3; // r12
char v5[552]; // [rsp+0h] [rbp-228h] BYREF

v2 = func6((__int64)a1);
v3 = v2;
if ( !v2 )
return v3;
if ( *(_BYTE *)(v2 + 67) )
return 0LL;
mystrncpy(v2 + 67, a2, 33LL);
sprintf(
v5,
"NOTICE %s :You have been automagically logged in via service account '%s'. Access level: %d",
a2,
a1,
*(unsigned int *)(v3 + 100));
lowMsg(v5);
sprintf(
v5,
"%s has been automagically logged in via server account '%s'. Level: %d.",
a2,
a1,
*(unsigned int *)(v3 + 100));
sRelay(v5);
func11(a2, (int *)(v3 + 100));
return v3;
}

original_code:
struct sadmin *automagic_login(char *account, char *nick)
{
 char notify[513];
 struct sadmin *theAdmin;
 theAdmin = findAdmin(account);
 if(theAdmin && ((theAdmin->actualNick)[0] == 0))
 {
  mystrncpy(theAdmin->actualNick, nick, 33);
  sprintf(notify, "NOTICE %s :You have been automagically logged in via service account '%s'. Access level: %d",
   nick, account, theAdmin->level);
  lowMsg(notify);
  sprintf(notify, "%s has been automagically logged in via server account '%s'. Level: %d.",
   nick, account, theAdmin->level);
  sRelay(notify);
  giveAdminStatus(nick, &theAdmin->level);
  return theAdmin;
 }
 return ((void *)0);
}

variable_types:
account
char *

variable_types:
notify
char [513]


checkCommonAdmin

decompiled_code:
int __fastcall checkCommonAdmin(char *s1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // r13
__int64 v4; // rbx
char v6[440]; // [rsp+0h] [rbp-1B8h] BYREF

v1 = findActualAdmin(s1);
if ( v1 )
{
v2 = ial;
v3 = v1;
if ( ial )
{
while ( 1 )
{
v4 = *(_QWORD *)(v2 + 632);
if ( v4 )
break;
LABEL_8:
v2 = *(_QWORD *)(v2 + 656);
if ( !v2 )
goto LABEL_9;
}
while ( 1 )
{
LODWORD(v1) = strcmp(s1, (const char *)v4);
if ( !(_DWORD)v1 )
break;
v4 = *(_QWORD *)(v4 + 104);
if ( !v4 )
goto LABEL_8;
}
}
else
{
LABEL_9:
sprintf(v6, "%s (admin) is no longer in any common channels with me.", s1);
LODWORD(v1) = sRelay(v6);
*(_BYTE *)(v3 + 67) = 0;
}
}
return v1;
}

canonical_decompiled_code:
int __fastcall func14(char *s1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // r13
__int64 v4; // rbx
char v6[440]; // [rsp+0h] [rbp-1B8h] BYREF

v1 = func3(s1);
if ( v1 )
{
v2 = ial;
v3 = v1;
if ( ial )
{
while ( 1 )
{
v4 = *(_QWORD *)(v2 + 632);
if ( v4 )
break;
LABEL_8:
v2 = *(_QWORD *)(v2 + 656);
if ( !v2 )
goto LABEL_9;
}
while ( 1 )
{
LODWORD(v1) = strcmp(s1, (const char *)v4);
if ( !(_DWORD)v1 )
break;
v4 = *(_QWORD *)(v4 + 104);
if ( !v4 )
goto LABEL_8;
}
}
else
{
LABEL_9:
sprintf(v6, "%s (admin) is no longer in any common channels with me.", s1);
LODWORD(v1) = sRelay(v6);
*(_BYTE *)(v3 + 67) = 0;
}
}
return v1;
}

original_code:
void checkCommonAdmin(char *nick)
{
 char sendR[400];
 struct sadmin *theAdmin;
 struct schan *c;
 struct suser *u;
 theAdmin = findActualAdmin(nick);
 if(!theAdmin)
  return;
 c = ial.channel;
 while(c != ((void *)0))
 {
  u = c->user;
  while(u != ((void *)0))
  {
   if(!strcmp(nick, u->nick))
    return;
   u = u->next;
  }
  c = c->next;
 }
 sprintf(sendR, "%s (admin) is no longer in any common channels with me.", nick);
 sRelay(sendR);
 theAdmin->actualNick[0] = 0;
 return;
}

variable_types:
sendR
char [400]

variable_types: struct schan { char *name; char topic[-1]; char modes[-1]; char key[-1]; int limit; int tsLim; struct criminalRecord { char nick[33]; char *identhost; char longTerm; char shortTerm; int laststamp; int lastJoin; int njoins; struct repeat { int id; int ts; char count; } trackrepeat[30]; struct criminalRecord *prev; struct criminalRecord *next; } *nortyusers; struct sban { char *mask; char *setby; int ts; struct sban *next; struct sban *prev; } *bans; struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; } *user; int userSize; int banSize; int flood_last; int flood_lines; struct schan *next; struct schan *prev; struct chanRec { char *name; char flags[-1]; char key[-1]; char goodModes[-1]; char badModes[-1]; struct schan *physical; struct softBan { char *banmask; char *reason; char type; char *setby; int expires; struct softBan *next; struct softBan *prev; } *softbans; struct chanRec *next; struct chanRec *prev; } *record; } *


checkAllAdmins

decompiled_code:
int checkAllAdmins()
{
__int64 i; // rbx
int result; // eax

for ( i = admins[13]; i; i = *(_QWORD *)(i + 104) )
{
while ( !*(_BYTE *)(i + 67) )
{
i = *(_QWORD *)(i + 104);
if ( !i )
return result;
}
result = checkCommonAdmin((char *)(i + 67));
}
return result;
}

canonical_decompiled_code:
int func15()
{
__int64 i; // rbx
int result; // eax

for ( i = admins[13]; i; i = *(_QWORD *)(i + 104) )
{
while ( !*(_BYTE *)(i + 67) )
{
i = *(_QWORD *)(i + 104);
if ( !i )
return result;
}
result = func14((char *)(i + 67));
}
return result;
}

original_code:
void checkAllAdmins()
{
 struct sadmin *i;
 i = admins.next;
 while(i)
 {
  if(i->actualNick[0])
   checkCommonAdmin(i->actualNick);
  i = i->next;
 }
 return;
}


chPass

decompiled_code:
__int64 __fastcall chPass(__int64 a1, char *a2)
{
char *v2; // rax

v2 = passCrypt(a2);
mystrncpy(a1 + 33, v2, 34LL);
return save_admins("admins.txt");
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, char *a2)
{
char *v2; // rax

v2 = func5(a2);
mystrncpy(a1 + 33, v2, 34LL);
return func0("admins.txt");
}

original_code:
int chPass(struct sadmin *theAdmin, char *newpass)
{
 char *hashed;
 hashed = passCrypt(newpass);
 mystrncpy(theAdmin->pass, hashed, 33 +1);
 return save_admins("admins.txt");
}

variable_types:
newpass
char *

variable_types:
hashed
char *


checkLastPointer

decompiled_code:
void __fastcall checkLastPointer(__int64 a1)
{
if ( lastPointer == a1 )
lastPointer = 0LL;
lastChan = 0;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
if ( lastPointer == a1 )
lastPointer = 0LL;
lastChan = 0;
}

original_code:
void checkLastPointer(struct schan *removal)
{
 if(lastPointer == removal)
  lastPointer = ((void *)0);
 lastChan[0] = 0;
 return;
}

user_defined_types: struct sban { char *mask; char *setby; int ts; struct sban *next; struct sban *prev; }

user_defined_types: struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; }

user_defined_types: struct repeat { int id; int ts; char count; }

user_defined_types: struct softBan { char *banmask; char *reason; char type; char *setby; int expires; struct softBan *next; struct softBan *prev; }


decompiled_code:
__int64 __fastcall make_user_struct(__int64 a1, _BYTE *a2)
{
_BYTE *v3; // rdi
__int64 v5; // rsi
const char *v6; // rbp
char *v7; // r12
char *v8; // rax
_BYTE *v9; // rdi
char *v10; // rax
__int64 result; // rax
char v12[152]; // [rsp-78h] [rbp-98h] BYREF

v3 = a2 + 322;
v5 = a1;
v6 = (const char *)(a1 + 1);
mystrncpy(v3, v5, 512LL);
v7 = strchr(v6, 33);
v8 = strchr(v6, 64);
if ( !v8 )
{
a2[66] = 0;
v9 = a2 + 33;
if ( v7 )
goto LABEL_3;
LABEL_8:
a2[33] = 0;
goto LABEL_4;
}
*v8 = 0;
mystrncpy(a2 + 66, v8 + 1, 256LL);
v9 = a2 + 33;
if ( !v7 )
goto LABEL_8;
LABEL_3:
*v7 = 0;
mystrncpy(v9, v7 + 1, 33LL);
LABEL_4:
mystrncpy(a2, v6, 33LL);
mystrncpy(v12, a2 + 66, 100LL);
v10 = strchr(v12, 46);
if ( v10 && !strcmp(v10, ".users.netgamers.org") )
{
*v10 = 0;
result = mystrncpy(a2 + 834, v12, 32LL);
}
else
{
strcpy(a2 + 834, "~None~");
result = 32357LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _BYTE *a2)
{
_BYTE *v3; // rdi
__int64 v5; // rsi
const char *v6; // rbp
char *v7; // r12
char *v8; // rax
_BYTE *v9; // rdi
char *v10; // rax
__int64 result; // rax
char v12[152]; // [rsp-78h] [rbp-98h] BYREF

v3 = a2 + 322;
v5 = a1;
v6 = (const char *)(a1 + 1);
mystrncpy(v3, v5, 512LL);
v7 = strchr(v6, 33);
v8 = strchr(v6, 64);
if ( !v8 )
{
a2[66] = 0;
v9 = a2 + 33;
if ( v7 )
goto LABEL_3;
LABEL_8:
a2[33] = 0;
goto LABEL_4;
}
*v8 = 0;
mystrncpy(a2 + 66, v8 + 1, 256LL);
v9 = a2 + 33;
if ( !v7 )
goto LABEL_8;
LABEL_3:
*v7 = 0;
mystrncpy(v9, v7 + 1, 33LL);
LABEL_4:
mystrncpy(a2, v6, 33LL);
mystrncpy(v12, a2 + 66, 100LL);
v10 = strchr(v12, 46);
if ( v10 && !strcmp(v10, ".users.netgamers.org") )
{
*v10 = 0;
result = mystrncpy(a2 + 834, v12, 32LL);
}
else
{
strcpy(a2 + 834, "~None~");
result = 32357LL;
}
return result;
}

original_code:
void make_user_struct(char *mask, sUser *usr)
{
 char *p, *c;
 char hostbuf[100];
 mystrncpy(usr->mask, mask, 512);
 c = strchr(mask + 1, '!');
 p = strchr(mask + 1, '@');
 if(p) {
  *p = '\0';
  mystrncpy(usr->host, p + 1, 256);
 } else
  strcpy(usr->host, "");
 if(c) {
  *c = '\0';
  mystrncpy(usr->ident, c + 1, 33);
 } else
  strcpy(usr->ident, "");
 mystrncpy(usr->nick, mask + 1, 33);
 mystrncpy(hostbuf, usr->host, 100);
 p = strchr(hostbuf, '.');
 if(p != ((void *)0) && strcmp(p, ".users.netgamers.org") == 0)
 {
  *p = '\0';
  mystrncpy(usr->gnuUser, hostbuf, 32);
 } else
  strcpy(usr->gnuUser, "~None~");
 return;
}

canonical_original_code:
void make_user_struct(char *mask, struct ircUser *usr)
{
 char *p; char *c;
 char hostbuf[100];
 mystrncpy(usr->mask, mask, 512);
 c = strchr(mask + 1, '!');
 p = strchr(mask + 1, '@');
 if(p) {
  *p = '\0';
  mystrncpy(usr->host, p + 1, 256);
 } else
  strcpy(usr->host, "");
 if(c) {
  *c = '\0';
  mystrncpy(usr->ident, c + 1, 33);
 } else
  strcpy(usr->ident, "");
 mystrncpy(usr->nick, mask + 1, 33);
 mystrncpy(hostbuf, usr->host, 100);
 p = strchr(hostbuf, '.');
 if(p != ((void *)0) && strcmp(p, ".users.netgamers.org") == 0)
 {
  *p = '\0';
  mystrncpy(usr->gnuUser, hostbuf, 32);
 } else
  strcpy(usr->gnuUser, "~None~");
 return;
}

variable_types:
mask
char *

variable_types: struct ircUser { char nick[33]; char ident[33]; char host[256]; char mask[512]; char gnuUser[32]; } *

variable_types:
p
char *

variable_types:
c
char *

variable_types:
hostbuf
char [100]


parseLine

decompiled_code:
char __fastcall parseLine(__int64 a1)
{
size_t v1; // rax
const char *v2; // rbp
int v3; // ebx
bool v4; // cf
bool v5; // zf
const char *v6; // rdi
__int64 v7; // rcx
char *v8; // rsi
char v9; // al
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
char *v14; // rsi
bool v15; // al
bool v16; // cf
bool v17; // zf
const char *v18; // rdi
__int64 v19; // rcx
char *v20; // rsi
size_t v21; // rax
char *v22; // rdx
char *v23; // rax
char *v24; // rax
char *v25; // r12
size_t v26; // rbx
char v27; // r13
__int64 v28; // rbp
char *v29; // r15
unsigned int v30; // er12
char *v31; // rax
__int64 v32; // rdx
char v33; // cl
__int64 v34; // rcx
int v36; // [rsp+8h] [rbp-E50h] BYREF
int v37; // [rsp+Ch] [rbp-E4Ch] BYREF
char v38; // [rsp+10h] [rbp-E48h] BYREF
char v39[527]; // [rsp+11h] [rbp-E47h] BYREF
char v40[1024]; // [rsp+220h] [rbp-C38h] BYREF
char *s[263]; // [rsp+620h] [rbp-838h] BYREF

mystrncpy(&v38, a1, 513LL);
memset(s, 0, 0x800uLL);
LODWORD(v1) = tokenize(a1, " ", s, 256LL);
v36 = v1;
if ( (int)v1 <= 1 )
return v1;
v2 = s[0];
v3 = v1;
v5 = strcmp(s[0], "PING") == 0;
LOBYTE(v1) = !v5;
if ( v5 )
{
strcpy(v40, "PONG ");
strcpy(&v40[5], s[1]);
LOBYTE(v1) = irc_write(v40);
return v1;
}
if ( *s[0] != 58 )
return v1;
v37 = atoi(s[1]);
v1 = (size_t)strchr(v2, 33);
if ( !v1 && v37 > 0 )
{
v23 = strchr(v39, 58);
LOBYTE(v1) = handleNumeric(s, &v37, v23);
return v1;
}
if ( v3 == 2 )
return v1;
make_user_struct((__int64)v2, v40);
v6 = "JOIN";
v7 = 5LL;
v8 = s[1];
do
{
if ( !v7 )
break;
v4 = (unsigned __int8)*v8 < (unsigned int)*v6;
v5 = *v8++ == *v6++;
--v7;
}
while ( v5 );
v9 = (!v4 && !v5) - v4;
v10 = 0;
v11 = v9 == 0;
if ( !v9 )
{
LOBYTE(v1) = on_join(v40, &s[2][*s[2] != 35], s[1], v7);
return v1;
}
v12 = "PART";
v13 = 5LL;
v14 = s[1];
do
{
if ( !v13 )
break;
v10 = (unsigned __int8)*v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
if ( (!v10 && !v11) == v10 )
{
LOBYTE(v1) = on_part(v40, &s[2][*s[2] != 35], s[1], v13);
return v1;
}
v15 = strcmp(s[1], "QUIT") != 0;
v16 = 0;
v17 = !v15;
if ( !v15 )
{
v24 = strchr(v39, 58);
LOBYTE(v1) = on_quit(v40, v24 + 1);
return v1;
}
v18 = "NICK";
v19 = 5LL;
v20 = s[1];
do
{
if ( !v19 )
break;
v16 = (unsigned __int8)*v20 < (unsigned int)*v18;
v17 = *v20++ == *v18++;
--v19;
}
while ( v17 );
LOBYTE(v1) = (!v16 && !v17) - v16;
if ( !(_BYTE)v1 )
{
LOBYTE(v1) = on_nick(v40, &s[2][*s[2] == 58], s[1], v19);
return v1;
}
if ( v36 <= 3 )
return v1;
if ( !strcmp(s[1], "PRIVMSG") )
{
LOBYTE(v1) = on_privmsg(v40, s[2], &v39[s[3] - s[0]], s, &v36);
return v1;
}
if ( !strcmp(s[1], "MODE") )
{
v25 = s[3];
v26 = 0LL;
v27 = 43;
v28 = 4LL;
v1 = strlen(s[3]);
while ( 1 )
{
if ( v26 >= v1 )
return v1;
v33 = v25[v26];
if ( ((v33 - 43) & 0xFD) != 0 )
{
v29 = s[2];
if ( v27 == 45 && v33 == 108 )
{
v34 = 108LL;
v32 = 45LL;
}
else
{
v30 = v33;
v31 = strchr(&argmodes, v33);
v32 = (unsigned int)v27;
if ( v31 )
{
on_mode(v40, v29, v32, v30, s[v28]);
v25 = s[3];
v28 = (int)v28 + 1;
v1 = strlen(s[3]);
goto LABEL_42;
}
v34 = v30;
}
on_mode(v40, v29, v32, v34, 0LL);
v25 = s[3];
v1 = strlen(s[3]);
}
else
{
v27 = v25[v26];
}
LABEL_42:
++v26;
}
}
v5 = strcmp(s[1], "NOTICE") == 0;
LOBYTE(v1) = !v5;
if ( v5 )
{
if ( *s[2] == 35 )
LOBYTE(v1) = chan_msg(v40, s[2], &v39[s[3] - s[0]], s, &v36, 1LL);
}
else if ( !strcmp(s[1], "INVITE") )
{
LODWORD(v1) = strcmp(s[2], &cNick);
if ( !(_DWORD)v1 )
LOBYTE(v1) = on_invite(v40, s[3] + 1);
}
else if ( !strcmp(s[1], "KICK") )
{
LOBYTE(v1) = on_kick(v40, s[2], s[3], &v39[s[4] - s[0]]);
}
else
{
v5 = strcmp(s[1], "TOPIC") == 0;
LOBYTE(v1) = !v5;
if ( v5 )
{
v21 = strlen(s[3]);
v22 = 0LL;
if ( v21 != 1 )
v22 = strchr(v39, 58) + 1;
LOBYTE(v1) = on_topic(v40, s[2], v22);
}
}
return v1;
}

canonical_decompiled_code:
char __fastcall func2(__int64 a1)
{
size_t v1; // rax
const char *v2; // rbp
int v3; // ebx
bool v4; // cf
bool v5; // zf
const char *v6; // rdi
__int64 v7; // rcx
char *v8; // rsi
char v9; // al
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
char *v14; // rsi
bool v15; // al
bool v16; // cf
bool v17; // zf
const char *v18; // rdi
__int64 v19; // rcx
char *v20; // rsi
size_t v21; // rax
char *v22; // rdx
char *v23; // rax
char *v24; // rax
char *v25; // r12
size_t v26; // rbx
char v27; // r13
__int64 v28; // rbp
char *v29; // r15
unsigned int v30; // er12
char *v31; // rax
__int64 v32; // rdx
char v33; // cl
__int64 v34; // rcx
int v36; // [rsp+8h] [rbp-E50h] BYREF
int v37; // [rsp+Ch] [rbp-E4Ch] BYREF
char v38; // [rsp+10h] [rbp-E48h] BYREF
char v39[527]; // [rsp+11h] [rbp-E47h] BYREF
char v40[1024]; // [rsp+220h] [rbp-C38h] BYREF
char *s[263]; // [rsp+620h] [rbp-838h] BYREF

mystrncpy(&v38, a1, 513LL);
memset(s, 0, 0x800uLL);
LODWORD(v1) = tokenize(a1, " ", s, 256LL);
v36 = v1;
if ( (int)v1 <= 1 )
return v1;
v2 = s[0];
v3 = v1;
v5 = strcmp(s[0], "PING") == 0;
LOBYTE(v1) = !v5;
if ( v5 )
{
strcpy(v40, "PONG ");
strcpy(&v40[5], s[1]);
LOBYTE(v1) = irc_write(v40);
return v1;
}
if ( *s[0] != 58 )
return v1;
v37 = atoi(s[1]);
v1 = (size_t)strchr(v2, 33);
if ( !v1 && v37 > 0 )
{
v23 = strchr(v39, 58);
LOBYTE(v1) = func3(s, &v37, v23);
return v1;
}
if ( v3 == 2 )
return v1;
func1((__int64)v2, v40);
v6 = "JOIN";
v7 = 5LL;
v8 = s[1];
do
{
if ( !v7 )
break;
v4 = (unsigned __int8)*v8 < (unsigned int)*v6;
v5 = *v8++ == *v6++;
--v7;
}
while ( v5 );
v9 = (!v4 && !v5) - v4;
v10 = 0;
v11 = v9 == 0;
if ( !v9 )
{
LOBYTE(v1) = on_join(v40, &s[2][*s[2] != 35], s[1], v7);
return v1;
}
v12 = "PART";
v13 = 5LL;
v14 = s[1];
do
{
if ( !v13 )
break;
v10 = (unsigned __int8)*v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
if ( (!v10 && !v11) == v10 )
{
LOBYTE(v1) = on_part(v40, &s[2][*s[2] != 35], s[1], v13);
return v1;
}
v15 = strcmp(s[1], "QUIT") != 0;
v16 = 0;
v17 = !v15;
if ( !v15 )
{
v24 = strchr(v39, 58);
LOBYTE(v1) = on_quit(v40, v24 + 1);
return v1;
}
v18 = "NICK";
v19 = 5LL;
v20 = s[1];
do
{
if ( !v19 )
break;
v16 = (unsigned __int8)*v20 < (unsigned int)*v18;
v17 = *v20++ == *v18++;
--v19;
}
while ( v17 );
LOBYTE(v1) = (!v16 && !v17) - v16;
if ( !(_BYTE)v1 )
{
LOBYTE(v1) = on_nick(v40, &s[2][*s[2] == 58], s[1], v19);
return v1;
}
if ( v36 <= 3 )
return v1;
if ( !strcmp(s[1], "PRIVMSG") )
{
LOBYTE(v1) = on_privmsg(v40, s[2], &v39[s[3] - s[0]], s, &v36);
return v1;
}
if ( !strcmp(s[1], "MODE") )
{
v25 = s[3];
v26 = 0LL;
v27 = 43;
v28 = 4LL;
v1 = strlen(s[3]);
while ( 1 )
{
if ( v26 >= v1 )
return v1;
v33 = v25[v26];
if ( ((v33 - 43) & 0xFD) != 0 )
{
v29 = s[2];
if ( v27 == 45 && v33 == 108 )
{
v34 = 108LL;
v32 = 45LL;
}
else
{
v30 = v33;
v31 = strchr(&argmodes, v33);
v32 = (unsigned int)v27;
if ( v31 )
{
on_mode(v40, v29, v32, v30, s[v28]);
v25 = s[3];
v28 = (int)v28 + 1;
v1 = strlen(s[3]);
goto LABEL_42;
}
v34 = v30;
}
on_mode(v40, v29, v32, v34, 0LL);
v25 = s[3];
v1 = strlen(s[3]);
}
else
{
v27 = v25[v26];
}
LABEL_42:
++v26;
}
}
v5 = strcmp(s[1], "NOTICE") == 0;
LOBYTE(v1) = !v5;
if ( v5 )
{
if ( *s[2] == 35 )
LOBYTE(v1) = chan_msg(v40, s[2], &v39[s[3] - s[0]], s, &v36, 1LL);
}
else if ( !strcmp(s[1], "INVITE") )
{
LODWORD(v1) = strcmp(s[2], &cNick);
if ( !(_DWORD)v1 )
LOBYTE(v1) = on_invite(v40, s[3] + 1);
}
else if ( !strcmp(s[1], "KICK") )
{
LOBYTE(v1) = on_kick(v40, s[2], s[3], &v39[s[4] - s[0]]);
}
else
{
v5 = strcmp(s[1], "TOPIC") == 0;
LOBYTE(v1) = !v5;
if ( v5 )
{
v21 = strlen(s[3]);
v22 = 0LL;
if ( v21 != 1 )
v22 = strchr(v39, 58) + 1;
LOBYTE(v1) = on_topic(v40, s[2], v22);
}
}
return v1;
}

original_code:
void parseLine(char *in)
{
 int numtok, numeric;
 char poutbuf[1024];
 char line[513];
 char *message;
 char *tokens[256];
 sUser theUser;
 mystrncpy(line, in, 513);
 memset(tokens, 0, sizeof(tokens) );
 numtok = tokenize(in, " ", tokens, 256);
 if(numtok < 2)
  return;
 if(strcmp(tokens[0], "PING") == 0) {
  strcpy(poutbuf, "PONG ");
  strcat(poutbuf, tokens[1]);
  irc_write(poutbuf);
  return;
 }
 if(tokens[0][0] != ':')
  return;
 numeric = atoi(tokens[1]);
 if(strchr(tokens[0], '!') == ((void *)0) && numeric > 0) {
   handleNumeric(tokens, &numeric, strchr(&line[1], ':'));
 } else {
  if(numtok < 3)
  {
   return;
  }
  make_user_struct(tokens[0], &theUser);
  if(strcmp(tokens[1], "JOIN") == 0)
  {
   on_join( &theUser, ((tokens[2][0] == '#') ? tokens[2] : (tokens[2]+1)) );
   return;
  }
  if(strcmp(tokens[1], "PART") == 0)
  {
   on_part( &theUser, ((tokens[2][0] == '#') ? tokens[2] : (tokens[2]+1)) );
   return;
  }
  if(strcmp(tokens[1], "QUIT") == 0)
  {
   message = strchr(&line[1], ':') + 1;
   on_quit(&theUser, message);
   return;
  }
  if(strcmp(tokens[1], "NICK") == 0)
  {
   on_nick(&theUser, ((tokens[2][0] != ':') ? tokens[2] : (tokens[2]+1)) );
   return;
  }
  if(numtok < 4)
   return;
  if(strcmp(tokens[1], "PRIVMSG") == 0)
  {
   message = line + (tokens[3] - tokens[0]) + 1;
   on_privmsg(&theUser, tokens[2], message, tokens, &numtok);
   return;
  }
  if(strcmp(tokens[1], "MODE") == 0)
  {
   int argpos, pos;
   char sign = '+';
   argpos = 4;
   for(pos = 0; pos < strlen(tokens[3]); pos++)
   {
    if(tokens[3][pos] == '+' || tokens[3][pos] == '-')
     sign = tokens[3][pos];
    else if( (tokens[3][pos] == 'l') && (sign == '-') )
     on_mode(&theUser, tokens[2], sign, tokens[3][pos], ((void *)0));
    else if(strchr(argmodes, tokens[3][pos]))
     on_mode(&theUser, tokens[2], sign, tokens[3][pos], tokens[argpos++]);
    else
     on_mode(&theUser, tokens[2], sign, tokens[3][pos], ((void *)0));
   }
   return;
  }
  if(strcmp(tokens[1], "NOTICE") == 0)
  {
   if(tokens[2][0] == '#') {
    message = line + (tokens[3] - tokens[0]) + 1;
    chan_msg(&theUser, tokens[2], message, tokens, &numtok, 1);
   }
   return;
  }
  if(strcmp(tokens[1], "INVITE") == 0)
  {
   if(!strcmp(tokens[2], cNick))
    on_invite(&theUser, &tokens[3][1]);
   return;
  }
  if(strcmp(tokens[1], "KICK") == 0)
  {
   message = line + (tokens[4] - tokens[0]) + 1;
   on_kick(&theUser, tokens[2], tokens[3], message);
   return;
  }
  if(strcmp(tokens[1], "TOPIC") == 0)
  {
   message = ((strlen(tokens[3]) == 1) ? ((void *)0) : strchr(&line[1], ':') + 1);
   on_topic(&theUser, tokens[2], message);
   return;
  }
 }
 return;
}

canonical_original_code:
void parseLine(char *in)
{
 int numtok; int numeric;
 char poutbuf[1024];
 char line[513];
 char *message;
 char *tokens[256];
 struct ircUser theUser;
 mystrncpy(line, in, 513);
 memset(tokens, 0, sizeof(tokens) );
 numtok = tokenize(in, " ", tokens, 256);
 if(numtok < 2)
  return;
 if(strcmp(tokens[0], "PING") == 0) {
  strcpy(poutbuf, "PONG ");
  strcat(poutbuf, tokens[1]);
  irc_write(poutbuf);
  return;
 }
 if(tokens[0][0] != ':')
  return;
 numeric = atoi(tokens[1]);
 if(strchr(tokens[0], '!') == ((void *)0) && numeric > 0) {
   handleNumeric(tokens, &numeric, strchr(&line[1], ':'));
 } else {
  if(numtok < 3)
  {
   return;
  }
  make_user_struct(tokens[0], &theUser);
  if(strcmp(tokens[1], "JOIN") == 0)
  {
   on_join( &theUser, ((tokens[2][0] == '#') ? tokens[2] : (tokens[2]+1)) );
   return;
  }
  if(strcmp(tokens[1], "PART") == 0)
  {
   on_part( &theUser, ((tokens[2][0] == '#') ? tokens[2] : (tokens[2]+1)) );
   return;
  }
  if(strcmp(tokens[1], "QUIT") == 0)
  {
   message = strchr(&line[1], ':') + 1;
   on_quit(&theUser, message);
   return;
  }
  if(strcmp(tokens[1], "NICK") == 0)
  {
   on_nick(&theUser, ((tokens[2][0] != ':') ? tokens[2] : (tokens[2]+1)) );
   return;
  }
  if(numtok < 4)
   return;
  if(strcmp(tokens[1], "PRIVMSG") == 0)
  {
   message = line + (tokens[3] - tokens[0]) + 1;
   on_privmsg(&theUser, tokens[2], message, tokens, &numtok);
   return;
  }
  if(strcmp(tokens[1], "MODE") == 0)
  {
   int argpos; int pos;
   char sign = '+';
   argpos = 4;
   for(pos = 0; pos < strlen(tokens[3]); pos++)
   {
    if(tokens[3][pos] == '+' || tokens[3][pos] == '-')
     sign = tokens[3][pos];
    else if( (tokens[3][pos] == 'l') && (sign == '-') )
     on_mode(&theUser, tokens[2], sign, tokens[3][pos], ((void *)0));
    else if(strchr(argmodes, tokens[3][pos]))
     on_mode(&theUser, tokens[2], sign, tokens[3][pos], tokens[argpos++]);
    else
     on_mode(&theUser, tokens[2], sign, tokens[3][pos], ((void *)0));
   }
   return;
  }
  if(strcmp(tokens[1], "NOTICE") == 0)
  {
   if(tokens[2][0] == '#') {
    message = line + (tokens[3] - tokens[0]) + 1;
    chan_msg(&theUser, tokens[2], message, tokens, &numtok, 1);
   }
   return;
  }
  if(strcmp(tokens[1], "INVITE") == 0)
  {
   if(!strcmp(tokens[2], cNick))
    on_invite(&theUser, &tokens[3][1]);
   return;
  }
  if(strcmp(tokens[1], "KICK") == 0)
  {
   message = line + (tokens[4] - tokens[0]) + 1;
   on_kick(&theUser, tokens[2], tokens[3], message);
   return;
  }
  if(strcmp(tokens[1], "TOPIC") == 0)
  {
   message = ((strlen(tokens[3]) == 1) ? ((void *)0) : strchr(&line[1], ':') + 1);
   on_topic(&theUser, tokens[2], message);
   return;
  }
 }
 return;
}

variable_types:
in
char *

variable_types: numtok int

variable_types: numeric int

variable_types:
poutbuf
char [1024]

variable_types:
line
char [513]

variable_types:
message
char *

variable_types:
tokens
char *[256]

variable_types: struct ircUser { char nick[33]; char ident[33]; char host[256]; char mask[512]; char gnuUser[32]; }

variable_types: argpos int

variable_types: pos int

variable_types: sign char


handleNumeric

decompiled_code:
void __fastcall handleNumeric(__int64 a1, int *a2, char *a3)
{
int v4; // eax
const char **v6; // rbp
const char *v7; // rdi
char *v8; // rax
const char *v9; // rbx
const char *v10; // r12
int v11; // eax
__int64 v12; // rsi
int v13; // eax
char *v14; // rax
const char *v15; // r12
__int64 v16; // r12
_BYTE *v17; // rax
_BYTE *v18; // rax
_BYTE *v19; // rsi
_BYTE *v20; // rax
__int64 v21; // r13
const char *v22; // rdi
const char *v23; // rbp
size_t v24; // rax
__int64 v25; // rax
void *v26; // r14
size_t v27; // rax
__int64 v28; // rbp
const char *v29; // rdi
unsigned int v30; // eax
const char *v31; // rdx
__int64 v32; // rsi
__int64 v33; // rcx
__int64 v34; // rax
__int64 v35; // rbx
__int64 v36; // rax
__int64 v37; // rbp
const char *v38; // r12
__int64 v39; // rsi
int v40; // eax
_QWORD *v41; // rbp
int v42; // er13
__int64 v43; // rdi
__int64 v44; // rax
__int64 v45; // r12
char v46; // al
const char *v47; // r9
const char *v48; // rcx
time_t v49; // rbx
char v50; // bl
size_t v51; // rax
__int64 v52; // rdx
_QWORD *v53; // rax
__int64 v54; // rax
const char *v55; // r14
__int64 v56; // rax
_BYTE *v57; // rdi
char src[5]; // [rsp+1h] [rbp-42Dh] BYREF
char s[1064]; // [rsp+6h] [rbp-428h] BYREF

if ( !main_irc )
return;
v4 = *a2;
if ( *a2 > 376 )
{
if ( v4 == 433 )
{
sRelay("My nickname is taken!");
v49 = *(int *)(main_irc + 16LL);
if ( v49 >= time(0LL) - 120 )
{
v50 = time(0LL);
strcpy(cNick, &config);
cNick[10] = 0;
sprintf(src, "%d", (unsigned int)v50);
v51 = strlen(cNick);
strcpy(&cNick[v51], src);
sprintf(s, "NICK %s", cNick);
irc_write(s);
}
else
{
sprintf(
s,
"PRIVMSG %s :%s",
(const char *)(unsigned int)((_DWORD)&config + 197),
(const char *)(unsigned int)((_DWORD)&config + 453));
highMsg(s);
}
}
else if ( v4 <= 433 )
{
if ( v4 == 422 )
{
LABEL_24:
lastPointer = 0LL;
lastChan = 0;
on_connect();
}
}
else if ( (v4 & 0xFFFFFFFD) == 473 || v4 == 471 )
{
sprintf(s, "INV %s %s %s", (const char *)(unsigned int)((_DWORD)&config + 1100), cNick, *(const char **)(a1 + 24));
send_to_all_links(s);
}
return;
}
if ( v4 <= 316 )
{
if ( v4 == 4 )
{
v12 = *(_QWORD *)(a1 + 56);
if ( v12 )
{
mystrncpy(&argmodes, v12, 32LL);
sprintf(s, "[from server] Modes with arguments set to: %s.", &argmodes);
sRelay(s);
}
return;
}
if ( v4 != 5 )
return;
v6 = (const char **)(a1 + 24);
mystrncpy(cNick, *(_QWORD *)(a1 + 16), 33LL);
v7 = *(const char **)(a1 + 24);
if ( !v7 )
return;
while ( 1 )
{
v8 = strchr(v7, 61);
if ( v8 )
{
*v8 = 0;
v9 = *v6;
v10 = v8 + 1;
if ( !strcmp(*v6, "MODES") )
{
v11 = atoi(v10);
if ( v11 <= 0 )
goto LABEL_17;
override_config("MODES", (unsigned int)((_DWORD)&config + 1004), (unsigned int)v11);
}
else
{
if ( strcmp(*v6, "MAXBANS") || (v13 = atoi(v10), v13 <= 0) )
{
LABEL_17:
if ( !strcmp(v9, "NICKLEN") && atoi(v10) > 32 )
{
fwrite("Server NICKLEN is longer than our allocated nicklen (cfg.h).\n", 1uLL, 0x3DuLL, out);
fwrite("Aborting.\n", 1uLL, 0xAuLL, out);
stop_running();
irc_disconnect();
}
else if ( !strcmp(v9, "NETWORK") )
{
mystrncpy(&myNetwork, v10, 32LL);
sprintf(s, "[from server] Network is: %s", (const char *)&myNetwork);
sRelay(s);
sprintf(
s,
"SET %s NETWORK %s",
(const char *)(unsigned int)((_DWORD)&config + 1100),
(const char *)&myNetwork);
send_to_all_links(s);
}
goto LABEL_21;
}
override_config("MAXBANS", (unsigned int)((_DWORD)&config + 1008), (unsigned int)v13);
}
}
LABEL_21:
v7 = v6[1];
++v6;
if ( !v7 )
return;
}
}
switch ( v4 )
{
case 317:
v40 = atoi(*(const char **)(a1 + 32));
v41 = (_QWORD *)ial;
v42 = v40;
if ( !ial )
return;
while ( 1 )
{
v43 = v41[84];
if ( !v43 )
goto LABEL_75;
if ( !strchr((const char *)(v43 + 8), 73) )
goto LABEL_75;
v44 = findUser(v41, *(_QWORD *)(a1 + 24));
v45 = v44;
if ( !v44 )
goto LABEL_75;
if ( *((_DWORD *)&config + 293) >= v42 )
{
*(_DWORD *)(v44 + 96) = time(0LL) - v42;
}
else
{
v46 = *(_BYTE *)(v44 + 72);
if ( *(_BYTE *)(v45 + 73) )
{
if ( v46 )
{
v48 = (const char *)&unk_1136;
v47 = (const char *)&unk_1136;
if ( *((_DWORD *)&config + 294) == 1 )
v48 = "v";
if ( *((_DWORD *)&config + 294) == 1 )
v47 = (const char *)v45;
}
else
{
v47 = (const char *)&unk_1136;
v48 = (const char *)&unk_1136;
}
}
else
{
if ( !v46 || *((_DWORD *)&config + 294) != 1 )
goto LABEL_75;
v47 = (const char *)v45;
v48 = "v";
}
sprintf(s, "MODE %s -o%s %s %s", (const char *)*v41, v48, (const char *)v45, v47);
highMsg(s);
sprintf(s, asc_1260, *v41, v45, (unsigned int)v42);
sRelay(s);
}
LABEL_75:
v41 = (_QWORD *)v41[82];
if ( !v41 )
return;
}
case 324:
v36 = findChan(*(_QWORD *)(a1 + 24));
v37 = v36;
if ( !v36 )
return;
v38 = (const char *)(v36 + 509);
mystrncpy(v36 + 509, *(_QWORD *)(a1 + 32), 32LL);
if ( strchr(v38, 108) )
{
*(_DWORD *)(v37 + 608) = atoi(*(const char **)(a1 + 40));
if ( !strchr(v38, 107) )
return;
v39 = *(_QWORD *)(a1 + 48);
goto LABEL_64;
}
if ( strchr(v38, 107) )
{
v39 = *(_QWORD *)(a1 + 40);
LABEL_64:
mystrncpy(v37 + 542, v39, 64LL);
return;
}
return;
case 330:
if ( (unsigned int)userExists(*(_QWORD *)(a1 + 24)) )
{
if ( automagic_login(*(_QWORD *)(a1 + 32), *(_QWORD *)(a1 + 24)) )
{
v35 = redoAdmTs;
if ( v35 - time(0LL) <= 9 )
parseLine((__int64)&redoAdm);
}
}
return;
case 332:
v34 = findChan(*(_QWORD *)(a1 + 24));
if ( v34 )
mystrncpy(v34 + 8, a3, 500LL);
return;
case 340:
v14 = strchr(*(const char **)(a1 + 24), 64);
if ( !v14 )
return;
mystrncpy(&myip, v14 + 1, 16LL);
LABEL_32:
if ( a3 )
a3 = strchr(a3, 32);
LABEL_34:
v15 = *(const char **)(a1 + 24);
if ( !strcmp(v15, &lastChan) )
{
v16 = lastPointer;
}
else
{
v16 = findChan(v15);
strcpy(&lastChan, *(const char **)(a1 + 24));
lastPointer = v16;
}
if ( !v16 )
return;
v17 = *(_BYTE **)(a1 + 72);
if ( v17 )
{
if ( *v17 == 58 )
{
v52 = *(_QWORD *)(a1 + 56);
if ( v52 )
{
v53 = (_QWORD *)(a1 + 48);
do
{
*v53 = v52;
v52 = v53[2];
++v53;
}
while ( v52 );
}
}
}
v18 = *(_BYTE **)(a1 + 64);
v19 = *(_BYTE **)(a1 + 48);
if ( v18 && *v18 == 58 )
{
v21 = findUser(v16, v19);
if ( !v21 )
{
v54 = u_add(v16, *(_QWORD *)(a1 + 48), *(_QWORD *)(a1 + 32), *(_QWORD *)(a1 + 40));
v55 = *(const char **)(a1 + 56);
v21 = v54;
if ( strchr(v55, 43) )
*(_BYTE *)(v21 + 72) = 1;
if ( strchr(v55, 64) )
*(_BYTE *)(v21 + 73) = 1;
}
}
else
{
if ( v19 && *v19 == 58 )
{
v56 = findUser(v16, *(_QWORD *)(a1 + 32));
v57 = *(_BYTE **)(a1 + 40);
v21 = v56;
if ( *v57 != 48 )
automagic_login(v57, *(_QWORD *)(a1 + 32));
}
else
{
v20 = *(_BYTE **)(a1 + 40);
if ( !v20 || *v20 != 58 )
return;
v21 = findUser(v16, *(_QWORD *)(a1 + 32));
}
if ( !v21 )
return;
}
if ( !*(_QWORD *)(v21 + 64) && a3 )
{
v22 = a3;
v23 = a3 + 1;
v24 = strlen(v22);
v25 = myalloc(v24);
*(_QWORD *)(v21 + 64) = v25;
v26 = (void *)v25;
v27 = strlen(v23);
memcpy(v26, v23, v27 + 1);
chkfor_rn_ban(v16, v21);
}
return;
case 352:
goto LABEL_32;
case 354:
goto LABEL_34;
case 367:
v28 = findChan(*(_QWORD *)(a1 + 24));
if ( !v28 )
return;
v29 = *(const char **)(a1 + 48);
if ( v29 )
{
v30 = atoi(v29);
v31 = *(const char **)(a1 + 40);
v32 = *(_QWORD *)(a1 + 32);
v33 = v30;
LABEL_53:
bl_add(v28, v32, v31, v33);
return;
}
v32 = *(_QWORD *)(a1 + 32);
if ( v32 )
{
v33 = 0LL;
v31 = "Unknown";
goto LABEL_53;
}
break;
case 376:
goto LABEL_24;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int *a2, char *a3)
{
int v4; // eax
const char **v6; // rbp
const char *v7; // rdi
char *v8; // rax
const char *v9; // rbx
const char *v10; // r12
int v11; // eax
__int64 v12; // rsi
int v13; // eax
char *v14; // rax
const char *v15; // r12
__int64 v16; // r12
_BYTE *v17; // rax
_BYTE *v18; // rax
_BYTE *v19; // rsi
_BYTE *v20; // rax
__int64 v21; // r13
const char *v22; // rdi
const char *v23; // rbp
size_t v24; // rax
__int64 v25; // rax
void *v26; // r14
size_t v27; // rax
__int64 v28; // rbp
const char *v29; // rdi
unsigned int v30; // eax
const char *v31; // rdx
__int64 v32; // rsi
__int64 v33; // rcx
__int64 v34; // rax
__int64 v35; // rbx
__int64 v36; // rax
__int64 v37; // rbp
const char *v38; // r12
__int64 v39; // rsi
int v40; // eax
_QWORD *v41; // rbp
int v42; // er13
__int64 v43; // rdi
__int64 v44; // rax
__int64 v45; // r12
char v46; // al
const char *v47; // r9
const char *v48; // rcx
time_t v49; // rbx
char v50; // bl
size_t v51; // rax
__int64 v52; // rdx
_QWORD *v53; // rax
__int64 v54; // rax
const char *v55; // r14
__int64 v56; // rax
_BYTE *v57; // rdi
char src[5]; // [rsp+1h] [rbp-42Dh] BYREF
char s[1064]; // [rsp+6h] [rbp-428h] BYREF

if ( !main_irc )
return;
v4 = *a2;
if ( *a2 > 376 )
{
if ( v4 == 433 )
{
sRelay("My nickname is taken!");
v49 = *(int *)(main_irc + 16LL);
if ( v49 >= time(0LL) - 120 )
{
v50 = time(0LL);
strcpy(cNick, &config);
cNick[10] = 0;
sprintf(src, "%d", (unsigned int)v50);
v51 = strlen(cNick);
strcpy(&cNick[v51], src);
sprintf(s, "NICK %s", cNick);
irc_write(s);
}
else
{
sprintf(
s,
"PRIVMSG %s :%s",
(const char *)(unsigned int)((_DWORD)&config + 197),
(const char *)(unsigned int)((_DWORD)&config + 453));
highMsg(s);
}
}
else if ( v4 <= 433 )
{
if ( v4 == 422 )
{
LABEL_24:
lastPointer = 0LL;
lastChan = 0;
on_connect();
}
}
else if ( (v4 & 0xFFFFFFFD) == 473 || v4 == 471 )
{
sprintf(s, "INV %s %s %s", (const char *)(unsigned int)((_DWORD)&config + 1100), cNick, *(const char **)(a1 + 24));
send_to_all_links(s);
}
return;
}
if ( v4 <= 316 )
{
if ( v4 == 4 )
{
v12 = *(_QWORD *)(a1 + 56);
if ( v12 )
{
mystrncpy(&argmodes, v12, 32LL);
sprintf(s, "[from server] Modes with arguments set to: %s.", &argmodes);
sRelay(s);
}
return;
}
if ( v4 != 5 )
return;
v6 = (const char **)(a1 + 24);
mystrncpy(cNick, *(_QWORD *)(a1 + 16), 33LL);
v7 = *(const char **)(a1 + 24);
if ( !v7 )
return;
while ( 1 )
{
v8 = strchr(v7, 61);
if ( v8 )
{
*v8 = 0;
v9 = *v6;
v10 = v8 + 1;
if ( !strcmp(*v6, "MODES") )
{
v11 = atoi(v10);
if ( v11 <= 0 )
goto LABEL_17;
override_config("MODES", (unsigned int)((_DWORD)&config + 1004), (unsigned int)v11);
}
else
{
if ( strcmp(*v6, "MAXBANS") || (v13 = atoi(v10), v13 <= 0) )
{
LABEL_17:
if ( !strcmp(v9, "NICKLEN") && atoi(v10) > 32 )
{
fwrite("Server NICKLEN is longer than our allocated nicklen (cfg.h).\n", 1uLL, 0x3DuLL, out);
fwrite("Aborting.\n", 1uLL, 0xAuLL, out);
stop_running();
irc_disconnect();
}
else if ( !strcmp(v9, "NETWORK") )
{
mystrncpy(&myNetwork, v10, 32LL);
sprintf(s, "[from server] Network is: %s", (const char *)&myNetwork);
sRelay(s);
sprintf(
s,
"SET %s NETWORK %s",
(const char *)(unsigned int)((_DWORD)&config + 1100),
(const char *)&myNetwork);
send_to_all_links(s);
}
goto LABEL_21;
}
override_config("MAXBANS", (unsigned int)((_DWORD)&config + 1008), (unsigned int)v13);
}
}
LABEL_21:
v7 = v6[1];
++v6;
if ( !v7 )
return;
}
}
switch ( v4 )
{
case 317:
v40 = atoi(*(const char **)(a1 + 32));
v41 = (_QWORD *)ial;
v42 = v40;
if ( !ial )
return;
while ( 1 )
{
v43 = v41[84];
if ( !v43 )
goto LABEL_75;
if ( !strchr((const char *)(v43 + 8), 73) )
goto LABEL_75;
v44 = findUser(v41, *(_QWORD *)(a1 + 24));
v45 = v44;
if ( !v44 )
goto LABEL_75;
if ( *((_DWORD *)&config + 293) >= v42 )
{
*(_DWORD *)(v44 + 96) = time(0LL) - v42;
}
else
{
v46 = *(_BYTE *)(v44 + 72);
if ( *(_BYTE *)(v45 + 73) )
{
if ( v46 )
{
v48 = (const char *)&unk_1136;
v47 = (const char *)&unk_1136;
if ( *((_DWORD *)&config + 294) == 1 )
v48 = "v";
if ( *((_DWORD *)&config + 294) == 1 )
v47 = (const char *)v45;
}
else
{
v47 = (const char *)&unk_1136;
v48 = (const char *)&unk_1136;
}
}
else
{
if ( !v46 || *((_DWORD *)&config + 294) != 1 )
goto LABEL_75;
v47 = (const char *)v45;
v48 = "v";
}
sprintf(s, "MODE %s -o%s %s %s", (const char *)*v41, v48, (const char *)v45, v47);
highMsg(s);
sprintf(s, asc_1260, *v41, v45, (unsigned int)v42);
sRelay(s);
}
LABEL_75:
v41 = (_QWORD *)v41[82];
if ( !v41 )
return;
}
case 324:
v36 = findChan(*(_QWORD *)(a1 + 24));
v37 = v36;
if ( !v36 )
return;
v38 = (const char *)(v36 + 509);
mystrncpy(v36 + 509, *(_QWORD *)(a1 + 32), 32LL);
if ( strchr(v38, 108) )
{
*(_DWORD *)(v37 + 608) = atoi(*(const char **)(a1 + 40));
if ( !strchr(v38, 107) )
return;
v39 = *(_QWORD *)(a1 + 48);
goto LABEL_64;
}
if ( strchr(v38, 107) )
{
v39 = *(_QWORD *)(a1 + 40);
LABEL_64:
mystrncpy(v37 + 542, v39, 64LL);
return;
}
return;
case 330:
if ( (unsigned int)userExists(*(_QWORD *)(a1 + 24)) )
{
if ( automagic_login(*(_QWORD *)(a1 + 32), *(_QWORD *)(a1 + 24)) )
{
v35 = redoAdmTs;
if ( v35 - time(0LL) <= 9 )
func2((__int64)&redoAdm);
}
}
return;
case 332:
v34 = findChan(*(_QWORD *)(a1 + 24));
if ( v34 )
mystrncpy(v34 + 8, a3, 500LL);
return;
case 340:
v14 = strchr(*(const char **)(a1 + 24), 64);
if ( !v14 )
return;
mystrncpy(&myip, v14 + 1, 16LL);
LABEL_32:
if ( a3 )
a3 = strchr(a3, 32);
LABEL_34:
v15 = *(const char **)(a1 + 24);
if ( !strcmp(v15, &lastChan) )
{
v16 = lastPointer;
}
else
{
v16 = findChan(v15);
strcpy(&lastChan, *(const char **)(a1 + 24));
lastPointer = v16;
}
if ( !v16 )
return;
v17 = *(_BYTE **)(a1 + 72);
if ( v17 )
{
if ( *v17 == 58 )
{
v52 = *(_QWORD *)(a1 + 56);
if ( v52 )
{
v53 = (_QWORD *)(a1 + 48);
do
{
*v53 = v52;
v52 = v53[2];
++v53;
}
while ( v52 );
}
}
}
v18 = *(_BYTE **)(a1 + 64);
v19 = *(_BYTE **)(a1 + 48);
if ( v18 && *v18 == 58 )
{
v21 = findUser(v16, v19);
if ( !v21 )
{
v54 = u_add(v16, *(_QWORD *)(a1 + 48), *(_QWORD *)(a1 + 32), *(_QWORD *)(a1 + 40));
v55 = *(const char **)(a1 + 56);
v21 = v54;
if ( strchr(v55, 43) )
*(_BYTE *)(v21 + 72) = 1;
if ( strchr(v55, 64) )
*(_BYTE *)(v21 + 73) = 1;
}
}
else
{
if ( v19 && *v19 == 58 )
{
v56 = findUser(v16, *(_QWORD *)(a1 + 32));
v57 = *(_BYTE **)(a1 + 40);
v21 = v56;
if ( *v57 != 48 )
automagic_login(v57, *(_QWORD *)(a1 + 32));
}
else
{
v20 = *(_BYTE **)(a1 + 40);
if ( !v20 || *v20 != 58 )
return;
v21 = findUser(v16, *(_QWORD *)(a1 + 32));
}
if ( !v21 )
return;
}
if ( !*(_QWORD *)(v21 + 64) && a3 )
{
v22 = a3;
v23 = a3 + 1;
v24 = strlen(v22);
v25 = myalloc(v24);
*(_QWORD *)(v21 + 64) = v25;
v26 = (void *)v25;
v27 = strlen(v23);
memcpy(v26, v23, v27 + 1);
chkfor_rn_ban(v16, v21);
}
return;
case 352:
goto LABEL_32;
case 354:
goto LABEL_34;
case 367:
v28 = findChan(*(_QWORD *)(a1 + 24));
if ( !v28 )
return;
v29 = *(const char **)(a1 + 48);
if ( v29 )
{
v30 = atoi(v29);
v31 = *(const char **)(a1 + 40);
v32 = *(_QWORD *)(a1 + 32);
v33 = v30;
LABEL_53:
bl_add(v28, v32, v31, v33);
return;
}
v32 = *(_QWORD *)(a1 + 32);
if ( v32 )
{
v33 = 0LL;
v31 = "Unknown";
goto LABEL_53;
}
break;
case 376:
goto LABEL_24;
default:
return;
}
}

original_code:
void handleNumeric(char *tokens[], int *numeric, char *end)
{
 char c;
 char outbuf[1024];
 struct schan *theChan;
 struct suser *theUser;
 if(!main_irc)
  return;
 switch(*numeric)
 {
  case 004:
  {
   if(tokens[7]) {
    mystrncpy(argmodes, tokens[7], 32);
    sprintf(outbuf, "[from server] Modes with arguments set to: %s.", argmodes);
    sRelay(outbuf);
   }
   break;
  }
  case 005:
  {
   char *pch;
   int i = 3;
   mystrncpy(cNick, tokens[2], 33);
   while(tokens[i])
   {
    pch = strchr(tokens[i], '=');
    if(pch) {
     *pch++ = '\0';
     if(!strcmp(tokens[i], "MODES") && atoi(pch) > 0) {
      override_config("MODES", &config.maxmodes, atoi(pch));
     } else if(!strcmp(tokens[i], "MAXBANS") && atoi(pch) > 0) {
      override_config("MAXBANS", &config.banlim, atoi(pch));
     } else if(!strcmp(tokens[i], "NICKLEN") && atoi(pch) > 33 -1) {
      fprintf(out, "Server NICKLEN is longer than our allocated nicklen (cfg.h).\n");
      fprintf(out, "Aborting.\n");
      stop_running();
      irc_disconnect();
     } else if(!strcmp(tokens[i], "NETWORK")) {
      mystrncpy(myNetwork, pch, 32);
      sprintf(outbuf, "[from server] Network is: %s", myNetwork);
      sRelay(outbuf);
      sprintf(outbuf, "SET %s NETWORK %s", config.linkname, myNetwork);
      send_to_all_links(outbuf);
     }
    }
    i++;
   }
   break;
  }
  case 317:
  {
   struct suser *ur;
   int isecs = atoi(tokens[4]);
   theChan = ial.channel;
   while(theChan)
   {
    if(theChan->record && strchr(theChan->record->flags, 'I')) {
     if((ur = findUser(theChan, tokens[3]))) {
      if(isecs > config.idle_limit) {
       if(ur->isOp || (ur->isVoice && config.idlevoice == 1)) {
        sprintf(outbuf, "MODE %s -o%s %s %s", theChan->name,
         (ur->isVoice && config.idlevoice == 1) ? "v" : "", ur->nick,
         (ur->isVoice && config.idlevoice == 1) ? ur->nick : "");
        highMsg(outbuf);
        sprintf(outbuf, "[\002%s\002] %s deoped/devoiced (%d seconds idle).", theChan->name, ur->nick, isecs);
        sRelay(outbuf);
       }
      } else {
       ur->idleMsg = time(0) - isecs;
      }
     }
    }
    theChan = theChan->next;
   }
   break;
  }
  case 324:
  {
   theChan = findChan(tokens[3]);
   if(!theChan)
    return;
   mystrncpy(theChan->modes, tokens[4], 32);
   if(strchr(theChan->modes, 'l'))
   {
    theChan->limit = atoi(tokens[5]);
    if(strchr(theChan->modes, 'k'))
     mystrncpy(theChan->key, tokens[6], 64);
   } else if(strchr(theChan->modes, 'k'))
    mystrncpy(theChan->key, tokens[5], 64);
   break;
  }
  case 330:
  {
   if(!userExists(tokens[3]))
    return;
   if(automagic_login(tokens[4], tokens[3]) && (redoAdmTs - time(0) < 10))
    parseLine(redoAdm);
   break;
  }
  case 332:
  {
   theChan = findChan(tokens[3]);
   if(!theChan)
    return;
   mystrncpy(theChan->topic, end, 500);
   break;
  }
  case 340:
  {
   char *pch = strchr(tokens[3], '@');
   if(!pch)
    return;
   mystrncpy(myip, pch+1, 16);
  }
  case 352:
  {
   if(end) {
    end = strchr(end, ' ');
   }
  }
  case 354:
  {
   int ti = 0;
   if(!strcmp(tokens[3], lastChan))
    theChan = lastPointer;
   else
   {
    theChan = findChan(tokens[3]);
    strcpy(lastChan, tokens[3]);
    lastPointer = theChan;
   }
   if(!theChan)
    return;
   if(tokens[9] && tokens[9][0] == ':') {
    for(ti = 6; tokens[ti+1]; ti++)
     tokens[ti] = tokens[ti+1];
   }
   if(tokens[8] && tokens[8][0] == ':')
   {
    theUser = findUser(theChan, tokens[6]);
    if(!theUser)
    {
     theUser = u_add(theChan, tokens[6], tokens[4], tokens[5]);
     if(strchr(tokens[7], '+'))
      theUser->isVoice = 1;
     if(strchr(tokens[7], '@'))
      theUser->isOp = 1;
    }
    if(!theUser->realname)
    {
     if(end)
     {
      theUser->realname = (char *)myalloc(strlen(end));
      end++;
      memcpy(theUser->realname, end, strlen(end) + 1);
      chkfor_rn_ban(theChan, theUser);
     }
    }
   } else if(tokens[6] && tokens[6][0] == ':') {
    theUser = findUser(theChan, tokens[4]);
    if(tokens[5][0] != '0')
     automagic_login(tokens[5], tokens[4]);
    if(theUser && !theUser->realname)
    {
     if(end)
     {
      theUser->realname = (char *)myalloc(strlen(end));
      end++;
      memcpy(theUser->realname, end, strlen(end) + 1);
      chkfor_rn_ban(theChan, theUser);
     }
    }
   } else if(tokens[5] && tokens[5][0] == ':') {
    theUser = findUser(theChan, tokens[4]);
    if(theUser && !theUser->realname)
    {
     if(end)
     {
      theUser->realname = (char *)myalloc(strlen(end));
      end++;
      memcpy(theUser->realname, end, strlen(end) + 1);
      chkfor_rn_ban(theChan, theUser);
     }
    }
   }
   break;
  }
  case 367:
  {
   theChan = findChan(tokens[3]);
   if(!theChan)
    return;
   if(tokens[6])
    bl_add(theChan, tokens[4], tokens[5], atoi(tokens[6]));
   else if(tokens[4])
    bl_add(theChan, tokens[4], "Unknown", 0);
   break;
  }
  case 376:
  case 422:
  {
   lastPointer = ((void *)0);
   lastChan[0] = 0;
   on_connect();
   break;
  }
  case 433:
  {
   sRelay("My nickname is taken!");
   if(main_irc->con_ts < time(0) - 120)
   {
    sprintf(outbuf, "PRIVMSG %s :%s", config.servicePrefix, config.serviceGhost);
    highMsg(outbuf);
   } else {
    char mbuf[5];
    c = (char)time(((void *)0));
    strcpy(cNick, config.nick);
    cNick[10] = '\0';
    sprintf(mbuf, "%d", c);
    strcat(cNick, mbuf);
    sprintf(outbuf, "NICK %s", cNick);
    irc_write(outbuf);
   }
   break;
  }
  case 471:
  case 473:
  case 475:
  {
   sprintf(outbuf, "INV %s %s %s", config.linkname, cNick, tokens[3]);
   send_to_all_links(outbuf);
   break;
  }
  case 474:
  {
   break;
  }
 }
 return;
}

variable_types:
tokens
char *[]

variable_types:
numeric
int *

variable_types:
end
char *

variable_types: c char

variable_types:
outbuf
char [1024]

variable_types: struct schan { char *name; char topic[-1]; char modes[-1]; char key[-1]; int limit; int tsLim; struct criminalRecord { char nick[33]; char *identhost; char longTerm; char shortTerm; int laststamp; int lastJoin; int njoins; struct repeat { int id; int ts; char count; } trackrepeat[30]; struct criminalRecord *prev; struct criminalRecord *next; } *nortyusers; struct sban { char *mask; char *setby; int ts; struct sban *next; struct sban *prev; } *bans; struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; } *user; int userSize; int banSize; int flood_last; int flood_lines; struct schan *next; struct schan *prev; struct chanRec { char *name; char flags[-1]; char key[-1]; char goodModes[-1]; char badModes[-1]; struct schan *physical; struct softBan { char *banmask; char *reason; char type; char *setby; int expires; struct softBan *next; struct softBan *prev; } *softbans; struct chanRec *next; struct chanRec *prev; } *record; } *

variable_types:
pch
char *

variable_types: i int

variable_types: isecs int

variable_types: ti int

variable_types:
mbuf
char [5]


validFlags

decompiled_code:
__int64 __fastcall validFlags(unsigned __int8 *a1, const char *a2)
{
unsigned int v2; // er12
unsigned __int8 *v3; // rbx

v2 = *a1;
if ( (_BYTE)v2 )
{
v3 = a1;
do
{
if ( !strchr(a2, (char)v2) )
break;
v2 = *++v3;
}
while ( (_BYTE)v2 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, const char *a2)
{
unsigned int v2; // er12
unsigned __int8 *v3; // rbx

v2 = *a1;
if ( (_BYTE)v2 )
{
v3 = a1;
do
{
if ( !strchr(a2, (char)v2) )
break;
v2 = *++v3;
}
while ( (_BYTE)v2 );
}
return v2;
}

original_code:
char validFlags(char *str, char *valid)
{
 for(; *str; str++)
  if(!strchr(valid, *str))
   return *str;
 return 0;
}

variable_types:
str
char *

variable_types:
valid
char *

return_type: char


isChanWithJ

decompiled_code:
__int64 isChanWithJ()
{
__int64 v0; // rbx

v0 = chans[24];
if ( !v0 )
return 0LL;
while ( !*(_QWORD *)(v0 + 176) || !strchr((const char *)(v0 + 8), 100) )
{
v0 = *(_QWORD *)(v0 + 192);
if ( !v0 )
return 0LL;
}
return 1LL;
}

original_code:
int isChanWithJ()
{
 struct chanRec *i;
 i = chans.next;
 while(i != ((void *)0))
 {
  if(i->physical && strchr(i->flags, 'd'))
   return 1;
  i = i->next;
 }
 return 0;
}

variable_types: struct chanRec { char *name; char flags[-1]; char key[-1]; char goodModes[-1]; char badModes[-1]; struct schan { char *name; char topic[-1]; char modes[-1]; char key[-1]; int limit; int tsLim; struct criminalRecord { char nick[33]; char *identhost; char longTerm; char shortTerm; int laststamp; int lastJoin; int njoins; struct repeat { int id; int ts; char count; } trackrepeat[30]; struct criminalRecord *prev; struct criminalRecord *next; } *nortyusers; struct sban { char *mask; char *setby; int ts; struct sban *next; struct sban *prev; } *bans; struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; } *user; int userSize; int banSize; int flood_last; int flood_lines; struct schan *next; struct schan *prev; struct chanRec *record; } *physical; struct softBan { char *banmask; char *reason; char type; char *setby; int expires; struct softBan *next; struct softBan *prev; } *softbans; struct chanRec *next; struct chanRec *prev; } *