decompiled_code:
__int64 __fastcall adm_add(char *s, __int64 a2, int a3)
{
__int64 v4; // rdx
__int64 result; // rax
size_t v6; // rdx
__int64 v7; // rbp
_QWORD *v8; // rax
_QWORD *v9; // rdx

v4 = findAdmin((__int64)s);
result = 0LL;
if ( !v4 )
{
v6 = strlen(s);
result = 0LL;
if ( v6 <= 0x80 )
{
v7 = myalloc(120LL);
*(_QWORD *)(v7 + 104) = 0LL;
*(_BYTE *)(v7 + 67) = 0;
mystrncpy(v7, s, 33LL);
mystrncpy(v7 + 33, a2, 34LL);
*(_DWORD *)(v7 + 100) = a3;
v8 = admins;
do
{
v9 = v8;
v8 = (_QWORD *)v8[13];
}
while ( v8 );
v9[13] = v7;
*(_QWORD *)(v7 + 112) = v9;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s, __int64 a2, int a3)
{
__int64 v4; // rdx
__int64 result; // rax
size_t v6; // rdx
__int64 v7; // rbp
_QWORD *v8; // rax
_QWORD *v9; // rdx

v4 = func6((__int64)s);
result = 0LL;
if ( !v4 )
{
v6 = strlen(s);
result = 0LL;
if ( v6 <= 0x80 )
{
v7 = myalloc(120LL);
*(_QWORD *)(v7 + 104) = 0LL;
*(_BYTE *)(v7 + 67) = 0;
mystrncpy(v7, s, 33LL);
mystrncpy(v7 + 33, a2, 34LL);
*(_DWORD *)(v7 + 100) = a3;
v8 = admins;
do
{
v9 = v8;
v8 = (_QWORD *)v8[13];
}
while ( v8 );
v9[13] = v7;
*(_QWORD *)(v7 + 112) = v9;
result = 1LL;
}
}
return result;
}

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


repo: ipacker/fireclaw

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

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) = v1[13];
free(v1);
result = 1LL;
}
return result;
}

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

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) = v1[13];
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; } *

return_type: int


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

return_type: void

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


giveAdminStatus

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

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

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

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

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:
nick
char *

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

*(_BYTE *)(a2 + 33) = 0;
*(_BYTE *)(a3 + 34) = 0;
v6 = findAdmin(a2);
v7 = v6;
if ( v6 )
{
if ( passCheck((const char *)a3, (const char *)(v6 + 33)) )
{
if ( !a4 )
{
mystrncpy(v7 + 67, a1, 33LL);
giveAdminStatus(a1, (int *)(v7 + 100));
}
}
else
{
v7 = 0LL;
}
}
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; } *

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


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

v2 = findAdmin((__int64)a1);
v3 = v2;
if ( v2 )
{
if ( *(_BYTE *)(v2 + 67) )
{
v3 = 0LL;
}
else
{
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; // rbx
char v5[552]; // [rsp+0h] [rbp-228h] BYREF

v2 = func6((__int64)a1);
v3 = v2;
if ( v2 )
{
if ( *(_BYTE *)(v2 + 67) )
{
v3 = 0LL;
}
else
{
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; // r13
__int64 v3; // r12
__int64 v4; // rbx
char v6[440]; // [rsp+0h] [rbp-1B8h] BYREF

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

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

v1 = func3(s1);
if ( v1 )
{
v2 = v1;
v3 = ial;
if ( ial )
{
while ( 1 )
{
v4 = *(_QWORD *)(v3 + 632);
if ( v4 )
break;
LABEL_6:
v3 = *(_QWORD *)(v3 + 656);
if ( !v3 )
goto LABEL_7;
}
while ( 1 )
{
LODWORD(v1) = strcmp(s1, (const char *)v4);
if ( !(_DWORD)v1 )
break;
v4 = *(_QWORD *)(v4 + 104);
if ( !v4 )
goto LABEL_6;
}
}
else
{
LABEL_7:
sprintf(v6, "%s (admin) is no longer in any common channels with me.", s1);
LODWORD(v1) = sRelay(v6);
*(_BYTE *)(v2 + 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) )
{
if ( *(_BYTE *)(i + 67) )
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) )
{
if ( *(_BYTE *)(i + 67) )
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:
char *__fastcall make_user_struct(__int64 a1, _BYTE *a2)
{
char *v2; // r12
char *v3; // rax
char *result; // rax
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

mystrncpy(a2 + 322, a1, 512LL);
v2 = strchr((const char *)(a1 + 1), 33);
v3 = strchr((const char *)(a1 + 1), 64);
if ( v3 )
{
*v3 = 0;
mystrncpy(a2 + 66, v3 + 1, 256LL);
}
else
{
a2[66] = 0;
}
if ( v2 )
{
*v2 = 0;
mystrncpy(a2 + 33, v2 + 1, 33LL);
}
else
{
a2[33] = 0;
}
mystrncpy(a2, a1 + 1, 33LL);
mystrncpy(v5, a2 + 66, 100LL);
result = strchr(v5, 46);
if ( result && !strcmp(result, ".users.netgamers.org") )
{
*result = 0;
result = (char *)mystrncpy(a2 + 834, v5, 32LL);
}
else
{
strcpy(a2 + 834, "~None~");
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, _BYTE *a2)
{
char *v2; // r12
char *v3; // rax
char *result; // rax
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

mystrncpy(a2 + 322, a1, 512LL);
v2 = strchr((const char *)(a1 + 1), 33);
v3 = strchr((const char *)(a1 + 1), 64);
if ( v3 )
{
*v3 = 0;
mystrncpy(a2 + 66, v3 + 1, 256LL);
}
else
{
a2[66] = 0;
}
if ( v2 )
{
*v2 = 0;
mystrncpy(a2 + 33, v2 + 1, 33LL);
}
else
{
a2[33] = 0;
}
mystrncpy(a2, a1 + 1, 33LL);
mystrncpy(v5, a2 + 66, 100LL);
result = strchr(v5, 46);
if ( result && !strcmp(result, ".users.netgamers.org") )
{
*result = 0;
result = (char *)mystrncpy(a2 + 834, v5, 32LL);
}
else
{
strcpy(a2 + 834, "~None~");
}
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
int v2; // ebx
const char *v3; // rbp
int v4; // er12
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
char *v9; // rsi
char v10; // al
bool v11; // cf
bool v12; // zf
const char *v13; // rdi
__int64 v14; // rcx
char *v15; // rsi
bool v16; // al
bool v17; // cf
bool v18; // zf
const char *v19; // rdi
__int64 v20; // rcx
char *v21; // rsi
size_t v22; // rax
char *v23; // rdx
char *v24; // rax
char *v25; // rax
char v26; // r13
size_t v27; // rbp
char *v28; // rbx
char v29; // al
unsigned int v30; // ebx
int v31; // er12
_BYTE v33[880]; // [rsp+0h] [rbp-11B8h] BYREF
char *s[256]; // [rsp+370h] [rbp-E48h] BYREF
char v35; // [rsp+B70h] [rbp-648h] BYREF
char v36[527]; // [rsp+B71h] [rbp-647h] BYREF
char dest[1032]; // [rsp+D80h] [rbp-438h] BYREF
int v38; // [rsp+1188h] [rbp-30h] BYREF
int v39[11]; // [rsp+118Ch] [rbp-2Ch] BYREF

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

canonical_decompiled_code:
char __fastcall func2(__int64 a1)
{
size_t v1; // rax
int v2; // ebx
const char *v3; // rbp
int v4; // er12
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
char *v9; // rsi
char v10; // al
bool v11; // cf
bool v12; // zf
const char *v13; // rdi
__int64 v14; // rcx
char *v15; // rsi
bool v16; // al
bool v17; // cf
bool v18; // zf
const char *v19; // rdi
__int64 v20; // rcx
char *v21; // rsi
size_t v22; // rax
char *v23; // rdx
char *v24; // rax
char *v25; // rax
char v26; // r13
size_t v27; // rbp
char *v28; // rbx
char v29; // al
unsigned int v30; // ebx
int v31; // er12
_BYTE v33[880]; // [rsp+0h] [rbp-11B8h] BYREF
char *s[256]; // [rsp+370h] [rbp-E48h] BYREF
char v35; // [rsp+B70h] [rbp-648h] BYREF
char v36[527]; // [rsp+B71h] [rbp-647h] BYREF
char dest[1032]; // [rsp+D80h] [rbp-438h] BYREF
int v38; // [rsp+1188h] [rbp-30h] BYREF
int v39[11]; // [rsp+118Ch] [rbp-2Ch] BYREF

mystrncpy(&v35, a1, 513LL);
memset(s, 0, sizeof(s));
LODWORD(v1) = tokenize(a1, " ", s, 256LL);
v39[0] = v1;
if ( (int)v1 > 1 )
{
v2 = v1;
v3 = s[0];
v6 = strcmp(s[0], "PING") == 0;
LOBYTE(v1) = !v6;
if ( v6 )
{
strcpy(dest, "PONG ");
strcat(dest, s[1]);
LOBYTE(v1) = irc_write(dest);
}
else if ( *s[0] == 58 )
{
v4 = atoi(s[1]);
v38 = v4;
v1 = (size_t)strchr(v3, 33);
if ( v4 <= 0 || v1 )
{
if ( v2 > 2 )
{
func1((__int64)v3, v33);
v7 = "JOIN";
v8 = 5LL;
v9 = s[1];
do
{
if ( !v8 )
break;
v5 = (unsigned __int8)*v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
v10 = (!v5 && !v6) - v5;
v11 = 0;
v12 = v10 == 0;
if ( v10 )
{
v13 = "PART";
v14 = 5LL;
v15 = s[1];
do
{
if ( !v14 )
break;
v11 = (unsigned __int8)*v15 < (unsigned int)*v13;
v12 = *v15++ == *v13++;
--v14;
}
while ( v12 );
if ( (!v11 && !v12) == v11 )
{
LOBYTE(v1) = on_part(v33, &s[2][*s[2] != 35], s[1], v14);
}
else
{
v16 = strcmp(s[1], "QUIT") != 0;
v17 = 0;
v18 = !v16;
if ( v16 )
{
v19 = "NICK";
v20 = 5LL;
v21 = s[1];
do
{
if ( !v20 )
break;
v17 = (unsigned __int8)*v21 < (unsigned int)*v19;
v18 = *v21++ == *v19++;
--v20;
}
while ( v18 );
LOBYTE(v1) = (!v17 && !v18) - v17;
if ( (_BYTE)v1 )
{
if ( v39[0] > 3 )
{
if ( !strcmp(s[1], "PRIVMSG") )
{
LOBYTE(v1) = on_privmsg(v33, s[2], &v36[s[3] - s[0]], s, v39);
}
else if ( !strcmp(s[1], "MODE") )
{
v27 = 0LL;
v26 = 43;
v31 = 4;
while ( 1 )
{
v28 = s[3];
v1 = strlen(s[3]);
if ( v1 <= v27 )
break;
v29 = v28[v27];
if ( ((v29 - 43) & 0xFD) != 0 )
{
if ( v26 == 45 && v29 == 108 )
{
on_mode(v33, s[2], 45LL, 108LL, 0LL);
}
else
{
v30 = v29;
if ( strchr(&argmodes, v29) )
on_mode(v33, s[2], (unsigned int)v26, v30, s[v31++]);
else
on_mode(v33, s[2], (unsigned int)v26, v30, 0LL);
}
}
else
{
v26 = v28[v27];
}
++v27;
}
}
else
{
v6 = strcmp(s[1], "NOTICE") == 0;
LOBYTE(v1) = !v6;
if ( v6 )
{
if ( *s[2] == 35 )
LOBYTE(v1) = chan_msg(v33, s[2], &v36[s[3] - s[0]], s, v39, 1LL);
}
else if ( !strcmp(s[1], "INVITE") )
{
LODWORD(v1) = strcmp(s[2], &cNick);
if ( !(_DWORD)v1 )
LOBYTE(v1) = on_invite(v33, s[3] + 1);
}
else if ( !strcmp(s[1], "KICK") )
{
LOBYTE(v1) = on_kick(v33, s[2], s[3], &v36[s[4] - s[0]]);
}
else
{
v6 = strcmp(s[1], "TOPIC") == 0;
LOBYTE(v1) = !v6;
if ( v6 )
{
v22 = strlen(s[3]);
v23 = 0LL;
if ( v22 != 1 )
v23 = strchr(v36, 58) + 1;
LOBYTE(v1) = on_topic(v33, s[2], v23);
}
}
}
}
}
else
{
LOBYTE(v1) = on_nick(v33, &s[2][*s[2] == 58], s[1], v20);
}
}
else
{
v25 = strchr(v36, 58);
LOBYTE(v1) = on_quit(v33, v25 + 1);
}
}
}
else
{
LOBYTE(v1) = on_join(v33, &s[2][*s[2] != 35], s[1], v8);
}
}
}
else
{
v24 = strchr(v36, 58);
LOBYTE(v1) = func3(s, &v38, v24);
}
}
}
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 v5; // eax
const char **v6; // rbp
const char *v7; // rdi
__int64 v8; // rsi
int v9; // eax
char *v10; // rax
const char *v11; // r12
const char *v12; // rbx
int v13; // eax
int v14; // er12
_QWORD *v15; // rbp
const char *v16; // r15
const char *v17; // r9
const char *v18; // rcx
__int64 v19; // rdi
__int64 v20; // rax
__int64 v21; // rax
__int64 v22; // rbp
const char *v23; // r12
__int64 v24; // rbx
__int64 v25; // rax
char *v26; // rax
const char *v27; // r12
__int64 v28; // r12
_BYTE *v29; // rax
_BYTE *v30; // rax
_BYTE *v31; // rax
_BYTE *v32; // rax
__int64 v33; // rax
__int64 v34; // rbx
size_t v35; // rax
void *v36; // r13
const char *v37; // rbp
size_t v38; // rax
__int64 v39; // rdx
_QWORD *v40; // rax
__int64 v41; // r13
size_t v42; // rax
void *v43; // rbx
const char *v44; // rbp
size_t v45; // rax
_BYTE *v46; // rdi
__int64 v47; // rax
__int64 v48; // rbp
const char *v49; // rdi
unsigned int v50; // eax
__int64 v51; // rsi
time_t v52; // rbx
char v53; // bl
char src[5]; // [rsp+1h] [rbp-43Dh] BYREF
char s[1080]; // [rsp+6h] [rbp-438h] BYREF

if ( !main_irc )
return;
v5 = *a2;
if ( *a2 > 376 )
{
if ( v5 == 433 )
{
sRelay("My nickname is taken!");
v52 = *(int *)(main_irc + 16LL);
if ( v52 >= time(0LL) - 120 )
{
v53 = time(0LL);
strcpy(cNick, &config);
cNick[10] = 0;
sprintf(src, "%d", (unsigned int)v53);
strcat(cNick, 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 ( v5 <= 433 )
{
if ( v5 == 422 )
{
LABEL_15:
lastPointer = 0LL;
lastChan = 0;
on_connect();
}
}
else if ( (v5 & 0xFFFFFFFD) == 473 || v5 == 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 ( v5 <= 316 )
{
if ( v5 == 4 )
{
v8 = *(_QWORD *)(a1 + 56);
if ( v8 )
{
mystrncpy(&argmodes, v8, 32LL);
sprintf(s, "[from server] Modes with arguments set to: %s.", &argmodes);
sRelay(s);
}
return;
}
if ( v5 != 5 )
return;
mystrncpy(cNick, *(_QWORD *)(a1 + 16), 33LL);
v6 = (const char **)(a1 + 24);
v7 = *(const char **)(a1 + 24);
if ( !v7 )
return;
while ( 1 )
{
v10 = strchr(v7, 61);
if ( v10 )
{
v11 = v10 + 1;
*v10 = 0;
v12 = *v6;
if ( !strcmp(*v6, "MODES") )
{
v13 = atoi(v11);
if ( v13 <= 0 )
goto LABEL_29;
override_config("MODES", (unsigned int)((_DWORD)&config + 1004), (unsigned int)v13);
}
else
{
if ( strcmp(*v6, "MAXBANS") || (v9 = atoi(v11), v9 <= 0) )
{
LABEL_29:
if ( !strcmp(v12, "NICKLEN") && atoi(v11) > 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(v12, "NETWORK") )
{
mystrncpy(&myNetwork, v11, 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_25;
}
override_config("MAXBANS", (unsigned int)((_DWORD)&config + 1008), (unsigned int)v9);
}
}
LABEL_25:
v7 = *++v6;
if ( !*v6 )
return;
}
}
switch ( v5 )
{
case 317:
v14 = atoi(*(const char **)(a1 + 32));
v15 = (_QWORD *)ial;
if ( !ial )
return;
while ( 1 )
{
v19 = v15[84];
if ( !v19 )
goto LABEL_37;
if ( !strchr((const char *)(v19 + 8), 73) )
goto LABEL_37;
v20 = findUser(v15, *(_QWORD *)(a1 + 24));
if ( !v20 )
goto LABEL_37;
if ( *((_DWORD *)&config + 293) >= v14 )
{
*(_DWORD *)(v20 + 96) = time(0LL) - v14;
goto LABEL_37;
}
if ( !*(_BYTE *)(v20 + 73) )
break;
if ( *(_BYTE *)(v20 + 72) )
{
v16 = (const char *)v20;
v17 = (const char *)&unk_10B6;
v18 = (const char *)&unk_10B6;
if ( *((_DWORD *)&config + 294) != 1 )
goto LABEL_36;
goto LABEL_45;
}
v16 = (const char *)v20;
v17 = (const char *)&unk_10B6;
v18 = (const char *)&unk_10B6;
LABEL_36:
sprintf(s, "MODE %s -o%s %s %s", (const char *)*v15, v18, v16, v17);
highMsg(s);
sprintf(s, asc_11E0, *v15, v16, (unsigned int)v14);
sRelay(s);
LABEL_37:
v15 = (_QWORD *)v15[82];
if ( !v15 )
return;
}
if ( !*(_BYTE *)(v20 + 72) || *((_DWORD *)&config + 294) != 1 )
goto LABEL_37;
LABEL_45:
v17 = (const char *)v20;
v16 = (const char *)v20;
v18 = "v";
goto LABEL_36;
case 324:
v21 = findChan(*(_QWORD *)(a1 + 24));
v22 = v21;
if ( v21 )
{
v23 = (const char *)(v21 + 509);
mystrncpy(v21 + 509, *(_QWORD *)(a1 + 32), 32LL);
if ( strchr(v23, 108) )
{
*(_DWORD *)(v22 + 608) = atoi(*(const char **)(a1 + 40));
if ( strchr(v23, 107) )
mystrncpy(v22 + 542, *(_QWORD *)(a1 + 48), 64LL);
}
else if ( strchr(v23, 107) )
{
mystrncpy(v22 + 542, *(_QWORD *)(a1 + 40), 64LL);
}
}
return;
case 330:
if ( (unsigned int)userExists(*(_QWORD *)(a1 + 24)) )
{
if ( automagic_login(*(_QWORD *)(a1 + 32), *(_QWORD *)(a1 + 24)) )
{
v24 = redoAdmTs;
if ( v24 - time(0LL) <= 9 )
parseLine((__int64)&redoAdm);
}
}
return;
case 332:
v25 = findChan(*(_QWORD *)(a1 + 24));
if ( v25 )
mystrncpy(v25 + 8, a3, 500LL);
return;
case 340:
v26 = strchr(*(const char **)(a1 + 24), 64);
if ( !v26 )
return;
mystrncpy(&myip, v26 + 1, 16LL);
LABEL_63:
if ( a3 )
a3 = strchr(a3, 32);
LABEL_65:
v27 = *(const char **)(a1 + 24);
if ( !strcmp(v27, &lastChan) )
{
v28 = lastPointer;
}
else
{
v28 = findChan(v27);
strcpy(&lastChan, *(const char **)(a1 + 24));
lastPointer = v28;
}
if ( !v28 )
return;
v29 = *(_BYTE **)(a1 + 72);
if ( v29 )
{
if ( *v29 == 58 )
{
v39 = *(_QWORD *)(a1 + 56);
if ( v39 )
{
v40 = (_QWORD *)(a1 + 48);
do
{
*v40++ = v39;
v39 = v40[1];
}
while ( v39 );
}
}
}
v30 = *(_BYTE **)(a1 + 64);
if ( v30 && *v30 == 58 )
{
v41 = findUser(v28, *(_QWORD *)(a1 + 48));
if ( !v41 )
{
v41 = u_add(v28, *(_QWORD *)(a1 + 48), *(_QWORD *)(a1 + 32), *(_QWORD *)(a1 + 40));
if ( strchr(*(const char **)(a1 + 56), 43) )
*(_BYTE *)(v41 + 72) = 1;
if ( strchr(*(const char **)(a1 + 56), 64) )
*(_BYTE *)(v41 + 73) = 1;
}
if ( !*(_QWORD *)(v41 + 64) && a3 )
goto LABEL_88;
}
else
{
v31 = *(_BYTE **)(a1 + 48);
if ( !v31 || *v31 != 58 )
{
v32 = *(_BYTE **)(a1 + 40);
if ( v32 )
{
if ( *v32 == 58 )
{
v33 = findUser(v28, *(_QWORD *)(a1 + 32));
v34 = v33;
if ( v33 )
{
if ( !*(_QWORD *)(v33 + 64) && a3 )
{
v35 = strlen(a3);
v36 = (void *)myalloc(v35);
*(_QWORD *)(v34 + 64) = v36;
v37 = a3 + 1;
v38 = strlen(v37);
memcpy(v36, v37, v38 + 1);
chkfor_rn_ban(v28, v34);
}
}
}
}
return;
}
v41 = findUser(v28, *(_QWORD *)(a1 + 32));
v46 = *(_BYTE **)(a1 + 40);
if ( *v46 != 48 )
automagic_login(v46, *(_QWORD *)(a1 + 32));
if ( v41 && !*(_QWORD *)(v41 + 64) && a3 )
{
LABEL_88:
v42 = strlen(a3);
v43 = (void *)myalloc(v42);
*(_QWORD *)(v41 + 64) = v43;
v44 = a3 + 1;
v45 = strlen(v44);
memcpy(v43, v44, v45 + 1);
chkfor_rn_ban(v28, v41);
return;
}
}
break;
case 352:
goto LABEL_63;
case 354:
goto LABEL_65;
case 367:
v47 = findChan(*(_QWORD *)(a1 + 24));
v48 = v47;
if ( v47 )
{
v49 = *(const char **)(a1 + 48);
if ( v49 )
{
v50 = atoi(v49);
bl_add(v48, *(_QWORD *)(a1 + 32), *(_QWORD *)(a1 + 40), v50);
}
else
{
v51 = *(_QWORD *)(a1 + 32);
if ( v51 )
bl_add(v47, v51, "Unknown", 0LL);
}
}
return;
case 376:
goto LABEL_15;
default:
return;
}
}

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

if ( !main_irc )
return;
v5 = *a2;
if ( *a2 > 376 )
{
if ( v5 == 433 )
{
sRelay("My nickname is taken!");
v52 = *(int *)(main_irc + 16LL);
if ( v52 >= time(0LL) - 120 )
{
v53 = time(0LL);
strcpy(cNick, &config);
cNick[10] = 0;
sprintf(src, "%d", (unsigned int)v53);
strcat(cNick, 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 ( v5 <= 433 )
{
if ( v5 == 422 )
{
LABEL_15:
lastPointer = 0LL;
lastChan = 0;
on_connect();
}
}
else if ( (v5 & 0xFFFFFFFD) == 473 || v5 == 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 ( v5 <= 316 )
{
if ( v5 == 4 )
{
v8 = *(_QWORD *)(a1 + 56);
if ( v8 )
{
mystrncpy(&argmodes, v8, 32LL);
sprintf(s, "[from server] Modes with arguments set to: %s.", &argmodes);
sRelay(s);
}
return;
}
if ( v5 != 5 )
return;
mystrncpy(cNick, *(_QWORD *)(a1 + 16), 33LL);
v6 = (const char **)(a1 + 24);
v7 = *(const char **)(a1 + 24);
if ( !v7 )
return;
while ( 1 )
{
v10 = strchr(v7, 61);
if ( v10 )
{
v11 = v10 + 1;
*v10 = 0;
v12 = *v6;
if ( !strcmp(*v6, "MODES") )
{
v13 = atoi(v11);
if ( v13 <= 0 )
goto LABEL_29;
override_config("MODES", (unsigned int)((_DWORD)&config + 1004), (unsigned int)v13);
}
else
{
if ( strcmp(*v6, "MAXBANS") || (v9 = atoi(v11), v9 <= 0) )
{
LABEL_29:
if ( !strcmp(v12, "NICKLEN") && atoi(v11) > 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(v12, "NETWORK") )
{
mystrncpy(&myNetwork, v11, 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_25;
}
override_config("MAXBANS", (unsigned int)((_DWORD)&config + 1008), (unsigned int)v9);
}
}
LABEL_25:
v7 = *++v6;
if ( !*v6 )
return;
}
}
switch ( v5 )
{
case 317:
v14 = atoi(*(const char **)(a1 + 32));
v15 = (_QWORD *)ial;
if ( !ial )
return;
while ( 1 )
{
v19 = v15[84];
if ( !v19 )
goto LABEL_37;
if ( !strchr((const char *)(v19 + 8), 73) )
goto LABEL_37;
v20 = findUser(v15, *(_QWORD *)(a1 + 24));
if ( !v20 )
goto LABEL_37;
if ( *((_DWORD *)&config + 293) >= v14 )
{
*(_DWORD *)(v20 + 96) = time(0LL) - v14;
goto LABEL_37;
}
if ( !*(_BYTE *)(v20 + 73) )
break;
if ( *(_BYTE *)(v20 + 72) )
{
v16 = (const char *)v20;
v17 = (const char *)&unk_10B6;
v18 = (const char *)&unk_10B6;
if ( *((_DWORD *)&config + 294) != 1 )
goto LABEL_36;
goto LABEL_45;
}
v16 = (const char *)v20;
v17 = (const char *)&unk_10B6;
v18 = (const char *)&unk_10B6;
LABEL_36:
sprintf(s, "MODE %s -o%s %s %s", (const char *)*v15, v18, v16, v17);
highMsg(s);
sprintf(s, asc_11E0, *v15, v16, (unsigned int)v14);
sRelay(s);
LABEL_37:
v15 = (_QWORD *)v15[82];
if ( !v15 )
return;
}
if ( !*(_BYTE *)(v20 + 72) || *((_DWORD *)&config + 294) != 1 )
goto LABEL_37;
LABEL_45:
v17 = (const char *)v20;
v16 = (const char *)v20;
v18 = "v";
goto LABEL_36;
case 324:
v21 = findChan(*(_QWORD *)(a1 + 24));
v22 = v21;
if ( v21 )
{
v23 = (const char *)(v21 + 509);
mystrncpy(v21 + 509, *(_QWORD *)(a1 + 32), 32LL);
if ( strchr(v23, 108) )
{
*(_DWORD *)(v22 + 608) = atoi(*(const char **)(a1 + 40));
if ( strchr(v23, 107) )
mystrncpy(v22 + 542, *(_QWORD *)(a1 + 48), 64LL);
}
else if ( strchr(v23, 107) )
{
mystrncpy(v22 + 542, *(_QWORD *)(a1 + 40), 64LL);
}
}
return;
case 330:
if ( (unsigned int)userExists(*(_QWORD *)(a1 + 24)) )
{
if ( automagic_login(*(_QWORD *)(a1 + 32), *(_QWORD *)(a1 + 24)) )
{
v24 = redoAdmTs;
if ( v24 - time(0LL) <= 9 )
func2((__int64)&redoAdm);
}
}
return;
case 332:
v25 = findChan(*(_QWORD *)(a1 + 24));
if ( v25 )
mystrncpy(v25 + 8, a3, 500LL);
return;
case 340:
v26 = strchr(*(const char **)(a1 + 24), 64);
if ( !v26 )
return;
mystrncpy(&myip, v26 + 1, 16LL);
LABEL_63:
if ( a3 )
a3 = strchr(a3, 32);
LABEL_65:
v27 = *(const char **)(a1 + 24);
if ( !strcmp(v27, &lastChan) )
{
v28 = lastPointer;
}
else
{
v28 = findChan(v27);
strcpy(&lastChan, *(const char **)(a1 + 24));
lastPointer = v28;
}
if ( !v28 )
return;
v29 = *(_BYTE **)(a1 + 72);
if ( v29 )
{
if ( *v29 == 58 )
{
v39 = *(_QWORD *)(a1 + 56);
if ( v39 )
{
v40 = (_QWORD *)(a1 + 48);
do
{
*v40++ = v39;
v39 = v40[1];
}
while ( v39 );
}
}
}
v30 = *(_BYTE **)(a1 + 64);
if ( v30 && *v30 == 58 )
{
v41 = findUser(v28, *(_QWORD *)(a1 + 48));
if ( !v41 )
{
v41 = u_add(v28, *(_QWORD *)(a1 + 48), *(_QWORD *)(a1 + 32), *(_QWORD *)(a1 + 40));
if ( strchr(*(const char **)(a1 + 56), 43) )
*(_BYTE *)(v41 + 72) = 1;
if ( strchr(*(const char **)(a1 + 56), 64) )
*(_BYTE *)(v41 + 73) = 1;
}
if ( !*(_QWORD *)(v41 + 64) && a3 )
goto LABEL_88;
}
else
{
v31 = *(_BYTE **)(a1 + 48);
if ( !v31 || *v31 != 58 )
{
v32 = *(_BYTE **)(a1 + 40);
if ( v32 )
{
if ( *v32 == 58 )
{
v33 = findUser(v28, *(_QWORD *)(a1 + 32));
v34 = v33;
if ( v33 )
{
if ( !*(_QWORD *)(v33 + 64) && a3 )
{
v35 = strlen(a3);
v36 = (void *)myalloc(v35);
*(_QWORD *)(v34 + 64) = v36;
v37 = a3 + 1;
v38 = strlen(v37);
memcpy(v36, v37, v38 + 1);
chkfor_rn_ban(v28, v34);
}
}
}
}
return;
}
v41 = findUser(v28, *(_QWORD *)(a1 + 32));
v46 = *(_BYTE **)(a1 + 40);
if ( *v46 != 48 )
automagic_login(v46, *(_QWORD *)(a1 + 32));
if ( v41 && !*(_QWORD *)(v41 + 64) && a3 )
{
LABEL_88:
v42 = strlen(a3);
v43 = (void *)myalloc(v42);
*(_QWORD *)(v41 + 64) = v43;
v44 = a3 + 1;
v45 = strlen(v44);
memcpy(v43, v44, v45 + 1);
chkfor_rn_ban(v28, v41);
return;
}
}
break;
case 352:
goto LABEL_63;
case 354:
goto LABEL_65;
case 367:
v47 = findChan(*(_QWORD *)(a1 + 24));
v48 = v47;
if ( v47 )
{
v49 = *(const char **)(a1 + 48);
if ( v49 )
{
v50 = atoi(v49);
bl_add(v48, *(_QWORD *)(a1 + 32), *(_QWORD *)(a1 + 40), v50);
}
else
{
v51 = *(_QWORD *)(a1 + 32);
if ( v51 )
bl_add(v47, v51, "Unknown", 0LL);
}
}
return;
case 376:
goto LABEL_15;
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 __int8 *v2; // rbx
unsigned int i; // ebp

v2 = a1;
for ( i = *a1; (_BYTE)i; i = *++v2 )
{
if ( !strchr(a2, (char)i) )
break;
}
return i;
}

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

v2 = a1;
for ( i = *a1; (_BYTE)i; i = *++v2 )
{
if ( !strchr(a2, (char)i) )
break;
}
return i;
}

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;
do
{
if ( *(_QWORD *)(v0 + 176) && strchr((const char *)(v0 + 8), 100) )
return 1LL;
v0 = *(_QWORD *)(v0 + 192);
}
while ( v0 );
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx

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

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


decompiled_code:
__int64 __fastcall cr_add(char *src, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
_QWORD *v8; // rdx
__int64 result; // rax
size_t v10; // rdx
char **v11; // r14
size_t v12; // rax
char *v13; // rax
char *v14; // rax
char *v15; // rdx

v8 = fetchChanRec((__int64)src);
result = 0LL;
if ( !v8 )
{
v10 = strlen(src);
result = 0LL;
if ( v10 <= 0x40 )
{
v11 = (char **)myalloc(208LL);
result = 0LL;
if ( v11 )
{
v11[24] = 0LL;
v11[22] = 0LL;
v11[23] = 0LL;
v12 = strlen(src);
v13 = (char *)myalloc(v12 + 1);
*v11 = v13;
strcpy(v13, src);
mystrncpy(v11 + 1, a2, 33LL);
mystrncpy((char *)v11 + 41, a3, 65LL);
mystrncpy((char *)v11 + 106, a4, 33LL);
mystrncpy((char *)v11 + 139, a5, 33LL);
v14 = (char *)chans;
do
{
v15 = v14;
v14 = (char *)*((_QWORD *)v14 + 24);
}
while ( v14 );
*((_QWORD *)v15 + 24) = v11;
v11[25] = v15;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
_QWORD *v8; // rdx
__int64 result; // rax
size_t v10; // rdx
char **v11; // r14
size_t v12; // rax
char *v13; // rax
char *v14; // rax
char *v15; // rdx

v8 = fetchChanRec((__int64)src);
result = 0LL;
if ( !v8 )
{
v10 = strlen(src);
result = 0LL;
if ( v10 <= 0x40 )
{
v11 = (char **)myalloc(208LL);
result = 0LL;
if ( v11 )
{
v11[24] = 0LL;
v11[22] = 0LL;
v11[23] = 0LL;
v12 = strlen(src);
v13 = (char *)myalloc(v12 + 1);
*v11 = v13;
strcpy(v13, src);
mystrncpy(v11 + 1, a2, 33LL);
mystrncpy((char *)v11 + 41, a3, 65LL);
mystrncpy((char *)v11 + 106, a4, 33LL);
mystrncpy((char *)v11 + 139, a5, 33LL);
v14 = (char *)chans;
do
{
v15 = v14;
v14 = (char *)*((_QWORD *)v14 + 24);
}
while ( v14 );
*((_QWORD *)v15 + 24) = v11;
v11[25] = v15;
result = 1LL;
}
}
}
return result;
}

original_code:
int cr_add(char *name, char *flags, char *key, char *gModes, char *bModes)
{
 struct chanRec *temp, *i;
 if(fetchChanRec(name))
  return 0;
 if(strlen(name) > 64)
  return 0;
 temp = (struct chanRec *)myalloc(sizeof(struct chanRec));
 if(!temp)
  return 0;
 temp->next = ((void *)0);
 temp->physical = ((void *)0);
 temp->softbans = ((void *)0);
 temp->name = (char *)myalloc(strlen(name)+1);
 strcpy(temp->name, name);
 mystrncpy(temp->flags, flags, 32 +1);
 mystrncpy(temp->key, key, 64 +1);
 mystrncpy(temp->goodModes, gModes, 32 +1);
 mystrncpy(temp->badModes, bModes, 32 +1);
 i = &chans;
 while(i->next != ((void *)0))
  i = i->next;
 i->next = temp;
 temp->prev = i;
 return 1;
}

canonical_original_code:
int cr_add(char *name, char *flags, char *key, char *gModes, char *bModes)
{
 struct chanRec *temp; struct chanRec *i;
 if(fetchChanRec(name))
  return 0;
 if(strlen(name) > 64)
  return 0;
 temp = (struct chanRec *)myalloc(sizeof(struct chanRec));
 if(!temp)
  return 0;
 temp->next = ((void *)0);
 temp->physical = ((void *)0);
 temp->softbans = ((void *)0);
 temp->name = (char *)myalloc(strlen(name)+1);
 strcpy(temp->name, name);
 mystrncpy(temp->flags, flags, 32 +1);
 mystrncpy(temp->key, key, 64 +1);
 mystrncpy(temp->goodModes, gModes, 32 +1);
 mystrncpy(temp->badModes, bModes, 32 +1);
 i = &chans;
 while(i->next != ((void *)0))
  i = i->next;
 i->next = temp;
 temp->prev = i;
 return 1;
}

variable_types:
name
char *

variable_types:
flags
char *

variable_types:
key
char *

variable_types:
gModes
char *

variable_types:
bModes
char *


original_code:
int br_add(char *channel, char *banmask, char *reason, char type, char *setby, int expires)
{
 struct chanRec *theChan;
 struct softBan *temp, *i;
 if(!(theChan = fetchChanRec(channel)))
  return 0;
 if(fetchSoftBan(theChan, banmask))
  return 0;
 if(strlen(banmask) > 256)
  return 0;
 temp = (struct softBan *)myalloc(sizeof(struct softBan));
 if(!temp)
  return 0;
 temp->next = ((void *)0);
 temp->type = type;
 temp->expires = expires;
 temp->banmask = (char*)myalloc(strlen(banmask)+1);
 temp->reason = (char*)myalloc(strlen(reason)+1);
 temp->setby = (char*)myalloc(strlen(setby)+1);
 strcpy(temp->banmask, banmask);
 strcpy(temp->reason, reason);
 strcpy(temp->setby, setby);
 i = theChan->softbans;
 if(!i) {
  theChan->softbans = temp;
  temp->prev = ((void *)0);
 } else {
  while(i->next != ((void *)0))
   i = i->next;
  i->next = temp;
  temp->prev = i;
 }
 return 1;
}

canonical_original_code:
int br_add(char *channel, char *banmask, char *reason, char type, char *setby, int expires)
{
 struct chanRec *theChan;
 struct softBan *temp; struct softBan *i;
 if(!(theChan = fetchChanRec(channel)))
  return 0;
 if(fetchSoftBan(theChan, banmask))
  return 0;
 if(strlen(banmask) > 256)
  return 0;
 temp = (struct softBan *)myalloc(sizeof(struct softBan));
 if(!temp)
  return 0;
 temp->next = ((void *)0);
 temp->type = type;
 temp->expires = expires;
 temp->banmask = (char *)myalloc(strlen(banmask)+1);
 temp->reason = (char *)myalloc(strlen(reason)+1);
 temp->setby = (char *)myalloc(strlen(setby)+1);
 strcpy(temp->banmask, banmask);
 strcpy(temp->reason, reason);
 strcpy(temp->setby, setby);
 i = theChan->softbans;
 if(!i) {
  theChan->softbans = temp;
  temp->prev = ((void *)0);
 } else {
  while(i->next != ((void *)0))
   i = i->next;
  i->next = temp;
  temp->prev = i;
 }
 return 1;
}

variable_types:
channel
char *

variable_types:
banmask
char *

variable_types:
reason
char *

variable_types: type char

variable_types:
setby
char *

variable_types: expires int

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


decompiled_code:
__int64 __fastcall br_del(__int64 a1, __int64 a2)
{
void **v2; // rbx
__int64 result; // rax
_QWORD *v4; // rax
_QWORD *v5; // rax

v2 = (void **)fetchSoftBan(a1, a2);
result = 0LL;
if ( v2 )
{
free(*v2);
free(v2[1]);
free(v2[3]);
v4 = v2[6];
if ( v4 )
v4[5] = v2[5];
else
*(_QWORD *)(a1 + 184) = v2[5];
v5 = v2[5];
if ( v5 )
v5[6] = v2[6];
free(v2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
void **v2; // rbx
__int64 result; // rax
_QWORD *v4; // rax
_QWORD *v5; // rax

v2 = (void **)fetchSoftBan(a1, a2);
result = 0LL;
if ( v2 )
{
free(*v2);
free(v2[1]);
free(v2[3]);
v4 = v2[6];
if ( v4 )
v4[5] = v2[5];
else
*(_QWORD *)(a1 + 184) = v2[5];
v5 = v2[5];
if ( v5 )
v5[6] = v2[6];
free(v2);
result = 1LL;
}
return result;
}

original_code:
int br_del(struct chanRec *theChan, char *banmask)
{
 struct softBan *i = fetchSoftBan(theChan, banmask);
 if(!i)
  return 0;
 free(i->banmask); free(i->reason); free(i->setby);
 if(i->prev)
  i->prev->next = i->next;
 else
  theChan->softbans = i->next;
 if(i->next)
  i->next->prev = i->prev;
 free(i);
 return 1;
}


original_code:
void clear_softbans(struct chanRec *cr)
{
 struct softBan *i, *fr;
 i = cr->softbans;
 while(i)
 {
  fr = i;
  free(i->banmask);
  free(i->reason);
  free(i->setby);
  i = i->next;
  free(fr);
 }
 cr->softbans = ((void *)0);
 return;
}

canonical_original_code:
void clear_softbans(struct chanRec *cr)
{
 struct softBan *i; struct softBan *fr;
 i = cr->softbans;
 while(i)
 {
  fr = i;
  free(i->banmask);
  free(i->reason);
  free(i->setby);
  i = i->next;
  free(fr);
 }
 cr->softbans = ((void *)0);
 return;
}


decompiled_code:
__int64 __fastcall cr_del(__int64 a1)
{
void **v1; // rbx
__int64 result; // rax
_QWORD *v3; // rax
_QWORD *v4; // rax

v1 = (void **)fetchChanRec(a1);
result = 0LL;
if ( v1 )
{
clear_softbans((__int64)v1);
v3 = v1[24];
if ( v3 )
v3[25] = v1[25];
v4 = v1[25];
if ( v4 )
v4[24] = v1[24];
free(*v1);
free(v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
void **v1; // rbx
__int64 result; // rax
_QWORD *v3; // rax
_QWORD *v4; // rax

v1 = (void **)fetchChanRec(a1);
result = 0LL;
if ( v1 )
{
func7((__int64)v1);
v3 = v1[24];
if ( v3 )
v3[25] = v1[25];
v4 = v1[25];
if ( v4 )
v4[24] = v1[24];
free(*v1);
free(v1);
result = 1LL;
}
return result;
}

original_code:
int cr_del(char *name)
{
 struct chanRec *d = fetchChanRec(name);
 if(!d)
  return 0;
 clear_softbans(d);
 if(d->next)
  d->next->prev = d->prev;
 if(d->prev)
  d->prev->next = d->next;
 free(d->name);
 free(d);
 return 1;
}


decompiled_code:
__int64 clear_chans()
{
__int64 *i; // rbx
__int64 *v1; // rax
__int64 result; // rax

for ( i = (__int64 *)chans[24]; i; result = cr_del(*v1) )
{
v1 = i;
i = (__int64 *)i[24];
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 *i; // rbx
__int64 *v1; // rax
__int64 result; // rax

for ( i = (__int64 *)chans[24]; i; result = func8(*v1) )
{
v1 = i;
i = (__int64 *)i[24];
}
return result;
}

original_code:
void clear_chans()
{
 struct chanRec *i, *fr;
 i = chans.next;
 while(i)
 {
  fr = i->next;
  cr_del(i->name);
  i = fr;
 }
 return;
}

canonical_original_code:
void clear_chans()
{
 struct chanRec *i; struct chanRec *fr;
 i = chans.next;
 while(i)
 {
  fr = i->next;
  cr_del(i->name);
  i = fr;
 }
 return;
}


decompiled_code:
__int64 count_chans()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = chans[24];
if ( !v0 )
return 0;
v1 = 0;
do
{
++v1;
v0 = *(_QWORD *)(v0 + 192);
}
while ( v0 );
return v1;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = chans[24];
if ( !v0 )
return 0;
v1 = 0;
do
{
++v1;
v0 = *(_QWORD *)(v0 + 192);
}
while ( v0 );
return v1;
}

original_code:
int count_chans()
{
 struct chanRec *i;
 int count = 0;
 i = chans.next;
 while(i)
 {
  count++;
  i = i->next;
 }
 return count;
}

variable_types: count int


decompiled_code:
__int64 __fastcall count_softBansOn(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *(_QWORD *)(a1 + 184);
if ( !v1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 40);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *(_QWORD *)(a1 + 184);
if ( !v1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 40);
}
while ( v1 );
return v2;
}

original_code:
int count_softBansOn(struct chanRec *c)
{
 struct softBan *i;
 int count = 0;
 i = c->softbans;
 while(i)
 {
  count++;
  i = i->next;
 }
 return count;
}


findChan

decompiled_code:
__int64 __fastcall findChan(char *s1)
{
__int64 i; // rbx

for ( i = ial; i; i = *(_QWORD *)(i + 656) )
{
if ( !strcmp(s1, *(const char **)i) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
__int64 i; // rbx

for ( i = ial; i; i = *(_QWORD *)(i + 656) )
{
if ( !strcmp(s1, *(const char **)i) )
break;
}
return i;
}

original_code:
struct schan *findChan(char *name)
{
 struct schan *i;
 i = ial.channel;
 while(i != ((void *)0))
 {
  if(strcmp(name, i->name) == 0)
   return i;
  i = i->next;
 }
 return ((void *)0);
}

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


decompiled_code:
__int64 __fastcall count_criminals(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *(_QWORD *)(a1 + 616);
if ( !v1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 432);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *(_QWORD *)(a1 + 616);
if ( !v1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 432);
}
while ( v1 );
return v2;
}

original_code:
int count_criminals(struct schan *c)
{
 struct criminalRecord *i;
 int count = 0;
 i = c->nortyusers;
 while(i != ((void *)0))
 {
  count++;
  i = i->next;
 }
 return count;
}

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


original_code:
void cl_add(char *name)
{
 struct schan *temp, *i;
 int size;
 if(findChan(name))
 {
  sRelay("Debug: SYNC Error trying to add channel twice");
  return;
 }
 temp = (struct schan *)myalloc(sizeof(struct schan));
 size = strlen(name) + 1;
 temp->userSize = 0;
 temp->flood_last = 0;
 temp->flood_lines = 0;
 temp->banSize = 0;
 temp->limit = 0;
 temp->tsLim = 0;
 temp->next = ((void *)0);
 temp->user = ((void *)0);
 temp->nortyusers = ((void *)0);
 temp->bans = ((void *)0);
 temp->record = fetchChanRec(name);
 temp->name = (char *)myalloc(size);
 memcpy(temp->name, name, size);
 memset(temp->topic, 0, 500);
 memset(temp->modes, 0, 32);
 memset(temp->key, 0, 64);
 i = ial.channel;
 if(i == ((void *)0))
 {
  ial.channel = temp;
  temp->prev = ((void *)0);
 }
 else
 {
  while(i->next != ((void *)0))
   i = i->next;
  i->next = temp;
  temp->prev = i;
 }
 if(temp->record)
  temp->record->physical = temp;
 return;
}

canonical_original_code:
void cl_add(char *name)
{
 struct schan *temp; struct schan *i;
 int size;
 if(findChan(name))
 {
  sRelay("Debug: SYNC Error trying to add channel twice");
  return;
 }
 temp = (struct schan *)myalloc(sizeof(struct schan));
 size = strlen(name) + 1;
 temp->userSize = 0;
 temp->flood_last = 0;
 temp->flood_lines = 0;
 temp->banSize = 0;
 temp->limit = 0;
 temp->tsLim = 0;
 temp->next = ((void *)0);
 temp->user = ((void *)0);
 temp->nortyusers = ((void *)0);
 temp->bans = ((void *)0);
 temp->record = fetchChanRec(name);
 temp->name = (char *)myalloc(size);
 memcpy(temp->name, name, size);
 memset(temp->topic, 0, 500);
 memset(temp->modes, 0, 32);
 memset(temp->key, 0, 64);
 i = ial.channel;
 if(i == ((void *)0))
 {
  ial.channel = temp;
  temp->prev = ((void *)0);
 }
 else
 {
  while(i->next != ((void *)0))
   i = i->next;
  i->next = temp;
  temp->prev = i;
 }
 if(temp->record)
  temp->record->physical = temp;
 return;
}

variable_types: size int


findiUser

decompiled_code:
__int64 __fastcall findiUser(__int64 a1, __int64 a2)
{
__int64 i; // rbx

for ( i = *(_QWORD *)(a1 + 632); i; i = *(_QWORD *)(i + 104) )
{
if ( (unsigned int)strmi(a2, i) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 i; // rbx

for ( i = *(_QWORD *)(a1 + 632); i; i = *(_QWORD *)(i + 104) )
{
if ( (unsigned int)strmi(a2, i) )
break;
}
return i;
}

original_code:
struct suser *findiUser(struct schan *channel, char *nick)
{
 struct suser *i;
 i = channel->user;
 while(i != ((void *)0))
 {
  if(strmi(nick, i->nick))
   return i;
  i = i->next;
 }
 return ((void *)0);
}

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 *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:
nick
char *

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


findUser

decompiled_code:
__int64 __fastcall findUser(__int64 a1, const char *a2)
{
__int64 i; // rbx

for ( i = *(_QWORD *)(a1 + 632); i; i = *(_QWORD *)(i + 104) )
{
if ( !strcmp(a2, (const char *)i) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
__int64 i; // rbx

for ( i = *(_QWORD *)(a1 + 632); i; i = *(_QWORD *)(i + 104) )
{
if ( !strcmp(a2, (const char *)i) )
break;
}
return i;
}

original_code:
struct suser *findUser(struct schan *channel, char *nick)
{
 struct suser *i;
 i = channel->user;
 while(i != ((void *)0))
 {
  if(!strcmp(nick, i->nick))
   return i;
  i = i->next;
 }
 return ((void *)0);
}

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


userExists

decompiled_code:
__int64 __fastcall userExists(const char *a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = ial;
if ( !ial )
return 0LL;
while ( 1 )
{
result = findUser(v1, a1);
if ( result )
break;
v1 = *(_QWORD *)(v1 + 656);
if ( !v1 )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = ial;
if ( !ial )
return 0LL;
while ( 1 )
{
result = func4(v1, a1);
if ( result )
break;
v1 = *(_QWORD *)(v1 + 656);
if ( !v1 )
return result;
}
return 1LL;
}

original_code:
int userExists(char *nick)
{
 struct schan *c;
 c = ial.channel;
 while(c != ((void *)0))
 {
  if(findUser(c, nick))
   return 1;
  c = c->next;
 }
 return 0;
}


findCriminal

decompiled_code:
__int64 __fastcall findCriminal(__int64 a1, const char *a2)
{
__int64 i; // rbx

for ( i = *(_QWORD *)(a1 + 616); i; i = *(_QWORD *)(i + 432) )
{
if ( !strcmp(a2, (const char *)i) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
__int64 i; // rbx

for ( i = *(_QWORD *)(a1 + 616); i; i = *(_QWORD *)(i + 432) )
{
if ( !strcmp(a2, (const char *)i) )
break;
}
return i;
}

original_code:
struct criminalRecord *findCriminal(struct schan *channel, char *nick)
{
 struct criminalRecord *i;
 i = channel->nortyusers;
 while(i != ((void *)0))
 {
  if(!strcmp(nick, i->nick))
   return i;
  i = i->next;
 }
 return ((void *)0);
}

variable_types: struct schan { char *name; char topic[-1]; char modes[-1]; char key[-1]; int limit; int tsLim; struct criminalRecord *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; } *

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


original_code:
struct suser *u_add(struct schan *channel, char *nick, char *ident, char *host)
{
 struct suser *temp, *i;
 int si, sh, sm;
 if(findUser(channel, nick))
  return ((void *)0);
 si = strlen(ident) + 1;
 sh = strlen(host) + 1;
 sm = strlen(nick) + strlen(ident) + strlen(host) + 3;
 temp = (struct suser *)myalloc(sizeof(struct suser));
 temp->isVoice = 0;
 temp->isOp = 0;
 temp->flines = 0;
 temp->nickchanges = 0;
 temp->joinTime = (int)time(0);
 temp->idleMsg = 0;
 temp->lastMsg = 0;
 temp->lastNick = 0;
 temp->next = ((void *)0);
 temp->realname = ((void *)0);
 temp->ident = (char *)myalloc(si);
 temp->host = (char *)myalloc(sh);
 temp->mask = (char*)myalloc(sm);
 memcpy(temp->ident, ident, si);
 memcpy(temp->host, host, sh);
 mystrncpy(temp->nick, nick, 33);
 sprintf(temp->mask, "%s!%s@%s", nick, ident, host);
 i = channel->user;
 if(i == ((void *)0))
 {
  channel->user = temp;
  temp->prev = ((void *)0);
 } else
 {
  while(i->next != ((void *)0))
   i = i->next;
  i->next = temp;
  temp->prev = i;
 }
 channel->userSize++;
 return temp;
}

canonical_original_code:
struct suser *u_add(struct schan *channel, char *nick, char *ident, char *host)
{
 struct suser *temp; struct suser *i;
 int si; int sh; int sm;
 if(findUser(channel, nick))
  return ((void *)0);
 si = strlen(ident) + 1;
 sh = strlen(host) + 1;
 sm = strlen(nick) + strlen(ident) + strlen(host) + 3;
 temp = (struct suser *)myalloc(sizeof(struct suser));
 temp->isVoice = 0;
 temp->isOp = 0;
 temp->flines = 0;
 temp->nickchanges = 0;
 temp->joinTime = (int)time(0);
 temp->idleMsg = 0;
 temp->lastMsg = 0;
 temp->lastNick = 0;
 temp->next = ((void *)0);
 temp->realname = ((void *)0);
 temp->ident = (char *)myalloc(si);
 temp->host = (char *)myalloc(sh);
 temp->mask = (char *)myalloc(sm);
 memcpy(temp->ident, ident, si);
 memcpy(temp->host, host, sh);
 mystrncpy(temp->nick, nick, 33);
 sprintf(temp->mask, "%s!%s@%s", nick, ident, host);
 i = channel->user;
 if(i == ((void *)0))
 {
  channel->user = temp;
  temp->prev = ((void *)0);
 } else
 {
  while(i->next != ((void *)0))
   i = i->next;
  i->next = temp;
  temp->prev = i;
 }
 channel->userSize++;
 return temp;
}

variable_types:
ident
char *

variable_types:
host
char *

variable_types: si int

variable_types: sh int

variable_types: sm int


original_code:
void u_del(struct schan *theChan, struct suser *theUser)
{
 if(theUser->realname)
  free(theUser->realname);
 free(theUser->ident);
 free(theUser->host);
 free(theUser->mask);
 if(!theUser->prev)
  theChan->user = theUser->next;
 else
  theUser->prev->next = theUser->next;
 if(theUser->next)
  theUser->next->prev = theUser->prev;
 free(theUser);
 theChan->userSize--;
 return;
}

variable_types:
theUser
struct suser *


original_code:
void clear_users(struct schan *c)
{
 struct suser *fr, *i;
 i = c->user;
 while(i != ((void *)0))
 {
  fr = i;
  i = i->next;
  u_del(c, fr);
 }
}

canonical_original_code:
void clear_users(struct schan *c)
{
 struct suser *fr; struct suser *i;
 i = c->user;
 while(i != ((void *)0))
 {
  fr = i;
  i = i->next;
  u_del(c, fr);
 }
}


addMode

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

v2 = (_BYTE *)(a1 + 509);
result = strchr((const char *)(a1 + 509), a2);
if ( !result )
{
if ( *(_BYTE *)(a1 + 509) )
{
do
++v2;
while ( *v2 );
}
*v2 = a2;
v2[1] = 0;
}
return result;
}

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

v2 = (_BYTE *)(a1 + 509);
result = strchr((const char *)(a1 + 509), a2);
if ( !result )
{
if ( *(_BYTE *)(a1 + 509) )
{
do
++v2;
while ( *v2 );
}
*v2 = a2;
v2[1] = 0;
}
return result;
}

original_code:
void addMode(struct schan *theChan, char mode)
{
 char *pch = theChan->modes;
 if(!strchr(pch, mode))
 {
  for(; (*pch); pch++);
  *(pch++) = mode;
  *pch = '\0';
 }
 return;
}

variable_types: mode char

variable_types:
pch
char *


removeMode

decompiled_code:
char *__fastcall removeMode(__int64 a1, char a2)
{
char *result; // rax
char v3; // dl

result = strchr((const char *)(a1 + 509), a2);
if ( result && *result )
{
do
{
v3 = result[1];
*result++ = v3;
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func11(__int64 a1, char a2)
{
char *result; // rax
char v3; // dl

result = strchr((const char *)(a1 + 509), a2);
if ( result && *result )
{
do
{
v3 = result[1];
*result++ = v3;
}
while ( v3 );
}
return result;
}

original_code:
void removeMode(struct schan *theChan, char mode)
{
 char *pch = strchr(theChan->modes, mode);
 if(pch)
  for(; (*pch); pch++)
   *pch = *(pch + 1);
 return;
}


findBan

decompiled_code:
__int64 __fastcall findBan(__int64 a1, const char *a2)
{
__int64 i; // rbx

for ( i = *(_QWORD *)(a1 + 624); i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(a2, *(const char **)i) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const char *a2)
{
__int64 i; // rbx

for ( i = *(_QWORD *)(a1 + 624); i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(a2, *(const char **)i) )
break;
}
return i;
}

original_code:
struct sban *findBan(struct schan *channel, char *mask)
{
 struct sban *i;
 i = channel->bans;
 while(i != ((void *)0))
 {
  if(!strcmp(mask, i->mask))
   return i;
  i = i->next;
 }
 return ((void *)0);
}

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 *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:
mask
char *

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


original_code:
struct criminalRecord *nu_add(struct schan *channel, char *nick, char *ident, char *host)
{
 struct criminalRecord *temp, *i;
 int sih;
 if(findCriminal(channel, nick))
  return ((void *)0);
 sih = strlen(ident) + strlen(host) + 2;
 temp = (struct criminalRecord *)myalloc(sizeof(struct criminalRecord));
 temp->shortTerm = temp->longTerm = 0;
 temp->lastJoin = 0;
 temp->njoins = 0;
 temp->laststamp = time(((void *)0));
 temp->identhost = (char *)myalloc(sih);
 sprintf(temp->identhost, "%s@%s", ident, host);
 mystrncpy(temp->nick, nick, 33);
 temp->next = ((void *)0);
 for(sih = 0; sih < 30; sih++)
  temp->trackrepeat[sih].id = 0;
 i = channel->nortyusers;
 if(i == ((void *)0))
 {
  channel->nortyusers = temp;
  temp->prev = ((void *)0);
 } else
 {
  while(i->next != ((void *)0))
   i = i->next;
  i->next = temp;
  temp->prev = i;
 }
 return temp;
}

canonical_original_code:
struct criminalRecord *nu_add(struct schan *channel, char *nick, char *ident, char *host)
{
 struct criminalRecord *temp; struct criminalRecord *i;
 int sih;
 if(findCriminal(channel, nick))
  return ((void *)0);
 sih = strlen(ident) + strlen(host) + 2;
 temp = (struct criminalRecord *)myalloc(sizeof(struct criminalRecord));
 temp->shortTerm = temp->longTerm = 0;
 temp->lastJoin = 0;
 temp->njoins = 0;
 temp->laststamp = time(((void *)0));
 temp->identhost = (char *)myalloc(sih);
 sprintf(temp->identhost, "%s@%s", ident, host);
 mystrncpy(temp->nick, nick, 33);
 temp->next = ((void *)0);
 for(sih = 0; sih < 30; sih++)
  temp->trackrepeat[sih].id = 0;
 i = channel->nortyusers;
 if(i == ((void *)0))
 {
  channel->nortyusers = temp;
  temp->prev = ((void *)0);
 } else
 {
  while(i->next != ((void *)0))
   i = i->next;
  i->next = temp;
  temp->prev = i;
 }
 return temp;
}

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

variable_types: sih int


original_code:
void nu_del(struct schan *theChan, struct criminalRecord *criminal)
{
 free(criminal->identhost);
 if(!criminal->prev)
  theChan->nortyusers = criminal->next;
 else
  criminal->prev->next = criminal->next;
 if(criminal->next)
  criminal->next->prev = criminal->prev;
 free(criminal);
 return;
}

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:
criminal
struct criminalRecord *


decompiled_code:
void __fastcall clear_nortyusers(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rsi

v1 = *(_QWORD *)(a1 + 616);
while ( v1 )
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 432);
nu_del(a1, v2);
}
}

original_code:
void clear_nortyusers(struct schan *c)
{
 struct criminalRecord *fr, *i;
 i = c->nortyusers;
 while(i != ((void *)0))
 {
  fr = i;
  i = i->next;
  nu_del(c, fr);
 }
}

canonical_original_code:
void clear_nortyusers(struct schan *c)
{
 struct criminalRecord *fr; struct criminalRecord *i;
 i = c->nortyusers;
 while(i != ((void *)0))
 {
  fr = i;
  i = i->next;
  nu_del(c, fr);
 }
}


original_code:
struct sban *bl_add(struct schan *channel, char *mask, char *setby, int ts)
{
 struct sban *temp, *i;
 int sm, ss;
 if(findBan(channel, mask))
  return ((void *)0);
 sm = strlen(mask) + 1;
 ss = strlen(setby) + 1;
 temp = (struct sban *)myalloc(sizeof(struct sban));
 temp->ts = ts;
 temp->mask = (char *)myalloc(sm);
 temp->setby = (char *)myalloc(ss);
 temp->next = ((void *)0);
 memcpy(temp->mask, mask, sm);
 memcpy(temp->setby, setby, ss);
 i = channel->bans;
 if(i == ((void *)0))
 {
  channel->bans = temp;
  temp->prev = ((void *)0);
 } else
 {
  while(i->next != ((void *)0))
   i = i->next;
  i->next = temp;
  temp->prev = i;
 }
 channel->banSize++;
 return temp;
}

canonical_original_code:
struct sban *bl_add(struct schan *channel, char *mask, char *setby, int ts)
{
 struct sban *temp; struct sban *i;
 int sm; int ss;
 if(findBan(channel, mask))
  return ((void *)0);
 sm = strlen(mask) + 1;
 ss = strlen(setby) + 1;
 temp = (struct sban *)myalloc(sizeof(struct sban));
 temp->ts = ts;
 temp->mask = (char *)myalloc(sm);
 temp->setby = (char *)myalloc(ss);
 temp->next = ((void *)0);
 memcpy(temp->mask, mask, sm);
 memcpy(temp->setby, setby, ss);
 i = channel->bans;
 if(i == ((void *)0))
 {
  channel->bans = temp;
  temp->prev = ((void *)0);
 } else
 {
  while(i->next != ((void *)0))
   i = i->next;
  i->next = temp;
  temp->prev = i;
 }
 channel->banSize++;
 return temp;
}

variable_types:
setby
char *

variable_types: ts int

variable_types: ss int

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


original_code:
void bl_del(struct schan *theChan, struct sban *theBan)
{
 free(theBan->mask);
 free(theBan->setby);
 if(!theBan->prev)
  theChan->bans = theBan->next;
 else
  theBan->prev->next = theBan->next;
 if(theBan->next)
  theBan->next->prev = theBan->prev;
 free(theBan);
 theChan->banSize--;
 return;
}

variable_types:
theBan
struct sban *


original_code:
void clear_bans(struct schan *c)
{
 struct sban *fr, *i;
 i = c->bans;
 while(i != ((void *)0))
 {
  fr = i;
  i = i->next;
  bl_del(c, fr);
 }
}

canonical_original_code:
void clear_bans(struct schan *c)
{
 struct sban *fr; struct sban *i;
 i = c->bans;
 while(i != ((void *)0))
 {
  fr = i;
  i = i->next;
  bl_del(c, fr);
 }
}


decompiled_code:
void __fastcall cl_del(char *a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax

v1 = findChan(a1);
if ( v1 )
{
v2 = v1;
v3 = *(_QWORD *)(v1 + 672);
if ( v3 )
*(_QWORD *)(v3 + 176) = 0LL;
checkLastPointer(v2);
free(*(void **)v2);
clear_users(v2);
clear_bans(v2);
clear_nortyusers(v2);
v4 = *(_QWORD *)(v2 + 664);
if ( v4 )
*(_QWORD *)(v4 + 656) = *(_QWORD *)(v2 + 656);
else
ial = *(_QWORD *)(v2 + 656);
v5 = *(_QWORD *)(v2 + 656);
if ( v5 )
*(_QWORD *)(v5 + 664) = *(_QWORD *)(v2 + 664);
free((void *)v2);
}
else
{
sRelay("Debug: SYNC Error trying to delete channel that doesn't exist.");
}
}

canonical_decompiled_code:
void __fastcall func19(char *a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax

v1 = func0(a1);
if ( v1 )
{
v2 = v1;
v3 = *(_QWORD *)(v1 + 672);
if ( v3 )
*(_QWORD *)(v3 + 176) = 0LL;
checkLastPointer(v2);
free(*(void **)v2);
func9(v2);
func18(v2);
func15(v2);
v4 = *(_QWORD *)(v2 + 664);
if ( v4 )
*(_QWORD *)(v4 + 656) = *(_QWORD *)(v2 + 656);
else
ial = *(_QWORD *)(v2 + 656);
v5 = *(_QWORD *)(v2 + 656);
if ( v5 )
*(_QWORD *)(v5 + 664) = *(_QWORD *)(v2 + 664);
free((void *)v2);
}
else
{
sRelay("Debug: SYNC Error trying to delete channel that doesn't exist.");
}
}

original_code:
void cl_del(char *name)
{
 struct schan *theChan = findChan(name);
 if(!theChan)
 {
  sRelay("Debug: SYNC Error trying to delete channel that doesn't exist.");
  return;
 }
 if(theChan->record)
  theChan->record->physical = ((void *)0);
 checkLastPointer(theChan);
 free(theChan->name);
 clear_users(theChan);
 clear_bans(theChan);
 clear_nortyusers(theChan);
 if(theChan->prev == ((void *)0))
  ial.channel = theChan->next;
 else
  theChan->prev->next = theChan->next;
 if(theChan->next != ((void *)0))
  theChan->next->prev = theChan->prev;
 free(theChan);
 return;
}

variable_types:
name
char *


decompiled_code:
void clear_ial()
{
__int64 v0; // rbx
char **v1; // rax

v0 = ial;
while ( v0 )
{
v1 = (char **)v0;
v0 = *(_QWORD *)(v0 + 656);
cl_del(*v1);
}
ial = 0LL;
}

original_code:
void clear_ial()
{
 struct schan *c, *n;
 c = ial.channel;
 while(c != ((void *)0))
 {
  n = c;
  c = c->next;
  cl_del(n->name);
 }
 ial.channel = ((void *)0);
}

canonical_original_code:
void clear_ial()
{
 struct schan *c; struct schan *n;
 c = ial.channel;
 while(c != ((void *)0))
 {
  n = c;
  c = c->next;
  cl_del(n->name);
 }
 ial.channel = ((void *)0);
}


modifyFlags

decompiled_code:
void __fastcall modifyFlags(char *dest, char *a2)
{
char v2; // bl
char *v3; // rbp
char v4; // r12
char *v5; // rax
char v6; // dl
char src[42]; // [rsp+Eh] [rbp-2Ah] BYREF

src[1] = 0;
v2 = *a2;
if ( *a2 )
{
v3 = a2;
v4 = 43;
do
{
if ( ((v2 - 43) & 0xFD) != 0 )
{
if ( strchr("ABIOVabcdefhijklmnoprstxyz", v2) )
{
if ( v4 == 43 )
{
if ( !strchr(dest, v2) )
{
src[0] = v2;
strcat(dest, src);
}
}
else if ( v4 == 45 )
{
v5 = strchr(dest, v2);
if ( v5 )
{
if ( *v5 )
{
do
{
v6 = *++v5;
*(v5 - 1) = *v5;
}
while ( v6 );
}
}
}
}
}
else
{
v4 = v2;
}
v2 = *++v3;
}
while ( *v3 );
}
}

canonical_decompiled_code:
void __fastcall func0(char *dest, char *a2)
{
char v2; // bl
char *v3; // rbp
char v4; // r12
char *v5; // rax
char v6; // dl
char src[42]; // [rsp+Eh] [rbp-2Ah] BYREF

src[1] = 0;
v2 = *a2;
if ( *a2 )
{
v3 = a2;
v4 = 43;
do
{
if ( ((v2 - 43) & 0xFD) != 0 )
{
if ( strchr("ABIOVabcdefhijklmnoprstxyz", v2) )
{
if ( v4 == 43 )
{
if ( !strchr(dest, v2) )
{
src[0] = v2;
strcat(dest, src);
}
}
else if ( v4 == 45 )
{
v5 = strchr(dest, v2);
if ( v5 )
{
if ( *v5 )
{
do
{
v6 = *++v5;
*(v5 - 1) = *v5;
}
while ( v6 );
}
}
}
}
}
else
{
v4 = v2;
}
v2 = *++v3;
}
while ( *v3 );
}
}

original_code:
void modifyFlags(char *flags, char *changes)
{
 char ptt[2];
 char *pch, *set;
 char sign = '+';
 for(ptt[1] = 0; *changes; changes++)
 {
  if(*changes == '+' || *changes == '-') {
   sign = *changes;
  } else if(strchr("ABIOVabcdefhijklmnoprstxyz", *changes)) {
   if(sign == '+' && !strchr(flags, *changes)) {
    ptt[0] = *changes;
    strcat(flags, ptt);
   } else if(sign == '-') {
    pch = strchr(flags, *changes);
    if(pch) {
     set = pch + 1;
     while(*pch)
      *pch++ = *set++;
    }
   }
  }
 }
 return;
}

canonical_original_code:
void modifyFlags(char *flags, char *changes)
{
 char ptt[2];
 char *pch; char *set;
 char sign = '+';
 for(ptt[1] = 0; *changes; changes++)
 {
  if(*changes == '+' || *changes == '-') {
   sign = *changes;
  } else if(strchr("ABIOVabcdefhijklmnoprstxyz", *changes)) {
   if(sign == '+' && !strchr(flags, *changes)) {
    ptt[0] = *changes;
    strcat(flags, ptt);
   } else if(sign == '-') {
    pch = strchr(flags, *changes);
    if(pch) {
     set = pch + 1;
     while(*pch)
      *pch++ = *set++;
    }
   }
  }
 }
 return;
}

variable_types:
flags
char *

variable_types:
changes
char *

variable_types:
ptt
char [2]

variable_types:
set
char *

variable_types: sign char


decompiled_code:
char *__fastcall str_remove(char *haystack, char *needle)
{
int v2; // er12
char *result; // rax
char *v4; // rbx

v2 = strlen(needle);
result = strstr(haystack, needle);
if ( result )
{
v4 = result;
do
{
memcpy(v4, &v4[v2], v2 + 1);
result = strstr(v4, needle);
v4 = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *haystack, char *needle)
{
int v2; // er12
char *result; // rax
char *v4; // rbx

v2 = strlen(needle);
result = strstr(haystack, needle);
if ( result )
{
v4 = result;
do
{
memcpy(v4, &v4[v2], v2 + 1);
result = strstr(v4, needle);
v4 = result;
}
while ( result );
}
return result;
}

original_code:
void str_remove(char *str, char *remove)
{
 int len, rlen;
 char *pch;
 len = strlen(str);
 rlen = strlen(remove);
 pch = strstr(str, remove);
 while(pch)
 {
  memcpy(pch, pch + rlen, rlen + 1);
  pch = strstr(pch, remove);
 }
 return;
}

canonical_original_code:
void str_remove(char *str, char *remove)
{
 int len; int rlen;
 char *pch;
 len = strlen(str);
 rlen = strlen(remove);
 pch = strstr(str, remove);
 while(pch)
 {
  memcpy(pch, pch + rlen, rlen + 1);
  pch = strstr(pch, remove);
 }
 return;
}

variable_types:
str
char *

variable_types:
remove
char *

variable_types: len int

variable_types: rlen int

variable_types:
pch
char *


strmi

decompiled_code:
__int64 __fastcall strmi(__int64 a1, __int64 a2)
{
const __int32_t *v2; // rcx
__int64 i; // rax
char v4; // dl

v2 = *_ctype_tolower_loc();
for ( i = 0LL; ; ++i )
{
v4 = *(_BYTE *)(a1 + i);
if ( v2[v4] != v2[*(char *)(a2 + i)] )
break;
if ( !v4 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
const __int32_t *v2; // rcx
__int64 i; // rax
char v4; // dl

v2 = *_ctype_tolower_loc();
for ( i = 0LL; ; ++i )
{
v4 = *(_BYTE *)(a1 + i);
if ( v2[v4] != v2[*(char *)(a2 + i)] )
break;
if ( !v4 )
return 1LL;
}
return 0LL;
}

original_code:
int strmi(char *str1, char *str2)
{
 int i = 0;
 for(;;i++) {
  if(tolower(str1[i]) != tolower(str2[i]))
   return 0;
  if(str1[i] == '\0')
   return 1;
 }
 return 1;
}

variable_types: i int


tokenize

decompiled_code:
__int64 __fastcall tokenize(char *a1, const char *a2, char **a3, int a4)
{
char *v6; // rax
unsigned int v7; // ebx

v6 = strtok(a1, a2);
if ( !v6 )
return 0;
v7 = 0;
do
{
if ( a4 > (int)v7 )
*a3 = v6;
v6 = strtok(0LL, a2);
++v7;
++a3;
}
while ( v6 );
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, const char *a2, char **a3, int a4)
{
char *v6; // rax
unsigned int v7; // ebx

v6 = strtok(a1, a2);
if ( !v6 )
return 0;
v7 = 0;
do
{
if ( a4 > (int)v7 )
*a3 = v6;
v6 = strtok(0LL, a2);
++v7;
++a3;
}
while ( v6 );
return v7;
}

original_code:
int tokenize( char *line, char *separators, char *tokens[], int max )
{
   int i = 0;
   char *pch;
   pch = (char*)strtok( line, separators );
   while(pch != ((void *)0))
   {
      if ( i < max )
         tokens[i] =pch;
      pch = (char*)strtok( ((void *)0), separators );
      i++;
   }
   return( i );
}

canonical_original_code:
int tokenize(char *line, char *separators, char *tokens[], int max)
{
   int i = 0;
   char *pch;
   pch = (char *)strtok( line, separators );
   while(pch != ((void *)0))
   {
      if ( i < max )
         tokens[i] =pch;
      pch = (char *)strtok( ((void *)0), separators );
      i++;
   }
   return( i );
}

variable_types:
line
char *

variable_types:
separators
char *

variable_types:
tokens
char *[]

variable_types: max int


decompiled_code:
_BOOL8 __fastcall write_memory(const char *a1, const void *a2, unsigned int a3)
{
int v4; // ebx
_BOOL8 result; // rax
int v6; // er12

v4 = open(a1, 65, 0LL);
result = 0LL;
if ( v4 != -1 )
{
v6 = write(v4, a2, a3);
close(v4);
result = a3 == v6;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1, const void *a2, unsigned int a3)
{
int v4; // ebx
_BOOL8 result; // rax
int v6; // er12

v4 = open(a1, 65, 0LL);
result = 0LL;
if ( v4 != -1 )
{
v6 = write(v4, a2, a3);
close(v4);
result = a3 == v6;
}
return result;
}

original_code:
int write_memory(char *file, char *begin, unsigned size)
{
 int handle, bytes;
 handle = open(file, 0100 | 01, 0);
 if(handle == -1)
  return 0;
 bytes = write(handle, begin, size);
 close(handle);
 if(bytes != size)
  return 0;
 return 1;
}

canonical_original_code:
int write_memory(char *file, char *begin, unsigned int size)
{
 int handle; int bytes;
 handle = open(file, 0100 | 01, 0);
 if(handle == -1)
  return 0;
 bytes = write(handle, begin, size);
 close(handle);
 if(bytes != size)
  return 0;
 return 1;
}

variable_types:
file
char *

variable_types:
begin
char *

variable_types:
size
unsigned int

variable_types: handle int

variable_types: bytes int


decompiled_code:
_BOOL8 __fastcall read_memory(const char *a1, void *a2, unsigned int a3)
{
int v4; // ebx
_BOOL8 result; // rax
int v6; // er12

v4 = open(a1, 0, 0LL);
result = 0LL;
if ( v4 != -1 )
{
v6 = read(v4, a2, a3);
close(v4);
result = a3 == v6;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(const char *a1, void *a2, unsigned int a3)
{
int v4; // ebx
_BOOL8 result; // rax
int v6; // er12

v4 = open(a1, 0, 0LL);
result = 0LL;
if ( v4 != -1 )
{
v6 = read(v4, a2, a3);
close(v4);
result = a3 == v6;
}
return result;
}

original_code:
int read_memory(char *file, char *begin, unsigned size)
{
 int handle, bytes;
 handle = open(file, 00, 0);
 if(handle == -1)
  return 0;
 bytes = read(handle, begin, size);
 close(handle);
 if(bytes != size)
  return 0;
 return 1;
}

canonical_original_code:
int read_memory(char *file, char *begin, unsigned int size)
{
 int handle; int bytes;
 handle = open(file, 00, 0);
 if(handle == -1)
  return 0;
 bytes = read(handle, begin, size);
 close(handle);
 if(bytes != size)
  return 0;
 return 1;
}