decompiled_code:
__int64 __fastcall ircproto_nick(const char *a1)
{
return sock_sendline("NICK %s", a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
return sock_sendline("NICK %s", a1);
}

original_code:
void ircproto_nick(char *nick)
{
 sock_sendline("NICK %s", nick);
}

variable_types:
nick
char *


repo: pmer/yak

decompiled_code:
__int64 __fastcall ircproto_user(const char *a1, const char *a2)
{
return sock_sendline("USER %s 0 * :%s", a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, const char *a2)
{
return sock_sendline("USER %s 0 * :%s", a1, a2);
}

original_code:
void ircproto_user(char *username, char *real_name)
{
 sock_sendline("USER %s 0 * :%s", username, real_name);
}

variable_types:
username
char *

return_type: void


decompiled_code:
__int64 __fastcall ircproto_identify(const char *a1, const char *a2)
{
return sock_sendline("PRIVMSG %s IDENTIFY %s", a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, const char *a2)
{
return sock_sendline("PRIVMSG %s IDENTIFY %s", a1, a2);
}

original_code:
void ircproto_identify(char *nickserv_nick, char *password)
{
 sock_sendline("PRIVMSG %s IDENTIFY %s", nickserv_nick, password);
}

variable_types:
password
char *


decompiled_code:
__int64 __fastcall ircproto_oper(const char *a1, const char *a2)
{
return sock_sendline("OPER %s %s", a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, const char *a2)
{
return sock_sendline("OPER %s %s", a1, a2);
}

original_code:
void ircproto_oper(char *oper_username, char *password)
{
 sock_sendline("OPER %s %s", oper_username, password);
}


decompiled_code:
__int64 __fastcall ircproto_join(const char *a1)
{
return sock_sendline("JOIN %s", a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
return sock_sendline("JOIN %s", a1);
}

original_code:
void ircproto_join(char *chan_name)
{
 sock_sendline("JOIN %s", chan_name);
}


decompiled_code:
__int64 __fastcall ircproto_part(const char *a1)
{
return sock_sendline("PART %s", a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
return sock_sendline("PART %s", a1);
}

original_code:
void ircproto_part(char *chan_name)
{
 sock_sendline("PART %s", chan_name);
}


decompiled_code:
__int64 ircproto_privmsg(const char *a1, const char *a2, ...)
{
char v3[520]; // [rsp+0h] [rbp-2D8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-D0h] BYREF

va_start(arg, a2);
vsnprintf(v3, 0x200uLL, a2, arg);
return sock_sendline("PRIVMSG %s :%s", a1, v3);
}

canonical_decompiled_code:
__int64 func10(const char *a1, const char *a2, ...)
{
char v3[520]; // [rsp+0h] [rbp-2D8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-D0h] BYREF

va_start(arg, a2);
vsnprintf(v3, 0x200uLL, a2, arg);
return sock_sendline("PRIVMSG %s :%s", a1, v3);
}

original_code:
void ircproto_privmsg(char *recipient, char *format, ...)
{
 va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("PRIVMSG %s :%s", recipient, message);
}

canonical_original_code:
void ircproto_privmsg(char *recipient, char *format, ...)
{
 __builtin_va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("PRIVMSG %s :%s", recipient, message);
}

variable_types:
recipient
char *

variable_types:
format
char *

variable_types:
message
char [512]


decompiled_code:
__int64 ircproto_privmsg_errno(const char *a1, const char *a2, ...)
{
int *v2; // rax
char *v3; // rax
char v5[520]; // [rsp+0h] [rbp-2D8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-D0h] BYREF

va_start(arg, a2);
vsnprintf(v5, 0x200uLL, a2, arg);
v2 = _errno_location();
v3 = strerror(*v2);
return sock_sendline("PRIVMSG %s :err: %s: %s", a1, v5, v3);
}

canonical_decompiled_code:
__int64 func11(const char *a1, const char *a2, ...)
{
int *v2; // rax
char *v3; // rax
char v5[520]; // [rsp+0h] [rbp-2D8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-D0h] BYREF

va_start(arg, a2);
vsnprintf(v5, 0x200uLL, a2, arg);
v2 = _errno_location();
v3 = strerror(*v2);
return sock_sendline("PRIVMSG %s :err: %s: %s", a1, v5, v3);
}

original_code:
void ircproto_privmsg_errno(char *recipient, char *format, ...)
{
 va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("PRIVMSG %s :err: %s: %s", recipient, message, strerror((*__errno_location ())));
}

canonical_original_code:
void ircproto_privmsg_errno(char *recipient, char *format, ...)
{
 __builtin_va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("PRIVMSG %s :err: %s: %s", recipient, message, strerror((*__errno_location ())));
}


decompiled_code:
__int64 ircproto_notice(const char *a1, const char *a2, ...)
{
char v3[520]; // [rsp+0h] [rbp-2D8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-D0h] BYREF

va_start(arg, a2);
vsnprintf(v3, 0x200uLL, a2, arg);
return sock_sendline("NOTICE %s :%s", a1, v3);
}

canonical_decompiled_code:
__int64 func12(const char *a1, const char *a2, ...)
{
char v3[520]; // [rsp+0h] [rbp-2D8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-D0h] BYREF

va_start(arg, a2);
vsnprintf(v3, 0x200uLL, a2, arg);
return sock_sendline("NOTICE %s :%s", a1, v3);
}

original_code:
void ircproto_notice(char *recipient, char *format, ...)
{
 va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("NOTICE %s :%s", recipient, message);
}

canonical_original_code:
void ircproto_notice(char *recipient, char *format, ...)
{
 __builtin_va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("NOTICE %s :%s", recipient, message);
}


decompiled_code:
__int64 ircproto_topic(const char *a1, const char *a2, ...)
{
char v3[520]; // [rsp+0h] [rbp-2D8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-D0h] BYREF

va_start(arg, a2);
vsnprintf(v3, 0x200uLL, a2, arg);
return sock_sendline("TOPIC %s :%s", a1, v3);
}

canonical_decompiled_code:
__int64 func13(const char *a1, const char *a2, ...)
{
char v3[520]; // [rsp+0h] [rbp-2D8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-D0h] BYREF

va_start(arg, a2);
vsnprintf(v3, 0x200uLL, a2, arg);
return sock_sendline("TOPIC %s :%s", a1, v3);
}

original_code:
void ircproto_topic(char *chan_name, char *format, ...)
{
 va_list args;
 char topic[512];
 __builtin_va_start(args,format);
 vsnprintf(topic, sizeof(topic), format, args);
 __builtin_va_end(args);
 sock_sendline("TOPIC %s :%s", chan_name, topic);
}

canonical_original_code:
void ircproto_topic(char *chan_name, char *format, ...)
{
 __builtin_va_list args;
 char topic[512];
 __builtin_va_start(args,format);
 vsnprintf(topic, sizeof(topic), format, args);
 __builtin_va_end(args);
 sock_sendline("TOPIC %s :%s", chan_name, topic);
}

variable_types:
topic
char [512]


decompiled_code:
__int64 ircproto_kick(const char *a1, const char *a2, const char *a3, ...)
{
char v4[520]; // [rsp+0h] [rbp-2E8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-E0h] BYREF

va_start(arg, a3);
vsnprintf(v4, 0x200uLL, a3, arg);
return sock_sendline("KICK %s %s :%s", a1, a2, v4);
}

canonical_decompiled_code:
__int64 func14(const char *a1, const char *a2, const char *a3, ...)
{
char v4[520]; // [rsp+0h] [rbp-2E8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-E0h] BYREF

va_start(arg, a3);
vsnprintf(v4, 0x200uLL, a3, arg);
return sock_sendline("KICK %s %s :%s", a1, a2, v4);
}

original_code:
void ircproto_kick(char *chan_name, char *nick, char *format, ...)
{
 va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("KICK %s %s :%s", chan_name, nick, message);
}

canonical_original_code:
void ircproto_kick(char *chan_name, char *nick, char *format, ...)
{
 __builtin_va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("KICK %s %s :%s", chan_name, nick, message);
}


decompiled_code:
__int64 __fastcall ircproto_mode(const char *a1, const char *a2)
{
return sock_sendline("MODE %s %s", a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(const char *a1, const char *a2)
{
return sock_sendline("MODE %s %s", a1, a2);
}

original_code:
void ircproto_mode(char *chan_name, char *modes)
{
 sock_sendline("MODE %s %s", chan_name, modes);
}

variable_types:
modes
char *


decompiled_code:
void handle_names_end()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
static void handle_names_end(char *prefix, int ncmd, char *params)
{
}

variable_types:
prefix
char *

variable_types: ncmd int

variable_types:
params
char *


decompiled_code:
const char *__fastcall chan_find(char *s2)
{
const char *v1; // rbx

v1 = (const char *)chans;
if ( chans == &chans )
return 0LL;
while ( strcasecmp(v1 + 32, s2) )
{
v1 = *(const char **)v1;
if ( v1 == (const char *)&chans )
return 0LL;
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func3(char *s2)
{
const char *v1; // rbx

v1 = (const char *)chans;
if ( chans == &chans )
return 0LL;
while ( strcasecmp(v1 + 32, s2) )
{
v1 = *(const char **)v1;
if ( v1 == (const char *)&chans )
return 0LL;
}
return v1;
}

original_code:
static struct chan *chan_find(char *chan_name)
{
 struct list_head *node;
 struct chan *chan;
 for (node = (&chans)->next; node != (&chans); node = node->next) {
  chan = ((struct chan *)((char *)(node)-(unsigned long)(&((struct chan *)0)->link)));
  if (!strcasecmp(chan->name, chan_name))
   return chan;
 }
 return ((void *)0);
}

variable_types: struct list_head { struct list_head *next; } *

variable_types: struct chan { struct list_head { struct list_head *next; } link; struct list_head presences; char name[512]; } *

user_defined_types: struct chan { struct list_head link; struct list_head presences; char name[512]; }


decompiled_code:
char *__fastcall handle_names(__int64 a1, __int64 a2, const char *a3)
{
char *v3; // rbp
char *v4; // r12
char *v5; // rbx
const char *v6; // r12
char *result; // rax
char *i; // rbx
int v9; // ebp
__int64 v10; // rax
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = strpbrk(a3, chantypes);
v4 = strchr(v3, 32);
v5 = strchr(v4, 58);
*v4 = 0;
v6 = chan_find(v3);
result = strtok_r(v5 + 1, " ", save_ptr);
for ( i = result; result; i = result )
{
v9 = prefix2priv((unsigned int)*i);
v10 = user_get(&i[-(v9 == 0) + 1]);
*(_DWORD *)(presence_get(v6, v10) + 48) = v9;
result = strtok_r(0LL, " ", save_ptr);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1, __int64 a2, const char *a3)
{
char *v3; // rbp
char *v4; // r12
char *v5; // rbx
const char *v6; // r12
char *result; // rax
char *i; // rbx
int v9; // ebp
__int64 v10; // rax
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = strpbrk(a3, chantypes);
v4 = strchr(v3, 32);
v5 = strchr(v4, 58);
*v4 = 0;
v6 = func3(v3);
result = strtok_r(v5 + 1, " ", save_ptr);
for ( i = result; result; i = result )
{
v9 = prefix2priv((unsigned int)*i);
v10 = user_get(&i[-(v9 == 0) + 1]);
*(_DWORD *)(presence_get(v6, v10) + 48) = v9;
result = strtok_r(0LL, " ", save_ptr);
}
return result;
}

original_code:
static void handle_names(char *prefix, int ncmd, char *params)
{
 struct chan *chan;
 struct user *user;
 struct presence *pres;
 char *chan_name, *space, *nicks, *nick, *save;
 enum priv priv;
 chan_name = strpbrk(params, chantypes);
 space = strchr(chan_name, ' ');
 nicks = strchr(space, ':') + 1;
 *space = '\0';
 chan = chan_find(chan_name);
 for (nick = strtok_r(nicks, " ", &save); nick;
   nick = strtok_r(((void *)0), " ", &save)) {
  priv = prefix2priv(nick[0]);
  if (priv != PRIV_NONE)
   nick++;
  user = user_get(nick);
  pres = presence_get(chan, user);
  pres->priv = priv;
 }
}

canonical_original_code:
static void handle_names(char *prefix, int ncmd, char *params)
{
 struct chan *chan;
 struct user *user;
 struct presence *pres;
 char *chan_name; char *space; char *nicks; char *nick; char *save;
 enum priv priv;
 chan_name = strpbrk(params, chantypes);
 space = strchr(chan_name, ' ');
 nicks = strchr(space, ':') + 1;
 *space = '\0';
 chan = chan_find(chan_name);
 for (nick = strtok_r(nicks, " ", &save); nick;
   nick = strtok_r(((void *)0), " ", &save)) {
  priv = prefix2priv(nick[0]);
  if (priv != PRIV_NONE)
   nick++;
  user = user_get(nick);
  pres = presence_get(chan, user);
  pres->priv = priv;
 }
}

variable_types: struct user { char nick[512]; char host[512]; char uname[512]; char rname[512]; struct list_head { struct list_head *next; } presences; _Bool reg; } *

variable_types: struct presence { struct list_head { struct list_head *next; } clink; struct chan { struct list_head link; struct list_head presences; char name[512]; } *chan; struct user { char nick[512]; char host[512]; char uname[512]; char rname[512]; struct list_head presences; _Bool reg; } *user; enum priv { PRIV_NONE=0, PRIV_OPERATOR=10, PRIV_HIGHEST=20 } priv; } *

variable_types:
space
char *

variable_types:
nicks
char *

variable_types:
save
char *

user_defined_types: struct presence { struct list_head clink; struct chan *chan; struct user *user; enum priv priv; }


decompiled_code:
__int64 __fastcall handle_kick(__int64 a1, __int64 a2, char *a3)
{
char *v3; // rbx
char *v4; // rbp
const char *v5; // r13
__int64 v6; // rax
const char *v7; // r12
__int64 v8; // r13
char *save_ptr[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = strtok_r(a3, " ", save_ptr);
v4 = strtok_r(0LL, " ", save_ptr);
v5 = chan_find(v3);
v6 = user_find(v4);
if ( !v5 )
return info("user %s/%s kicked: wasn't aware of presence", v3, v4);
v7 = (const char *)v6;
if ( !v6 )
return info("user %s/%s kicked: wasn't aware of presence", v3, v4);
v8 = presence_find(v5, v6);
if ( !v8 )
return info("user %s/%s kicked: wasn't aware of presence", v3, v4);
info("user %s/%s kicked", v3, v7);
return presence_del(v8);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, char *a3)
{
char *v3; // rbx
char *v4; // rbp
const char *v5; // r13
__int64 v6; // rax
const char *v7; // r12
__int64 v8; // r13
char *save_ptr[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = strtok_r(a3, " ", save_ptr);
v4 = strtok_r(0LL, " ", save_ptr);
v5 = func3(v3);
v6 = user_find(v4);
if ( !v5 )
return info("user %s/%s kicked: wasn't aware of presence", v3, v4);
v7 = (const char *)v6;
if ( !v6 )
return info("user %s/%s kicked: wasn't aware of presence", v3, v4);
v8 = presence_find(v5, v6);
if ( !v8 )
return info("user %s/%s kicked: wasn't aware of presence", v3, v4);
info("user %s/%s kicked", v3, v7);
return presence_del(v8);
}

original_code:
static void handle_kick(char *prefix, char *cmd, char *params)
{
 struct chan *chan;
 struct user *user;
 struct presence *pres;
 char *chan_name, *victim_prefix, *save;
 chan_name = strtok_r(params, " ", &save);
 victim_prefix = strtok_r(((void *)0), " ", &save);
 chan = chan_find(chan_name);
 user = user_find(victim_prefix);
 pres = chan && user ? presence_find(chan, user) : ((void *)0);
 if (pres) {
  info("user %s/%s kicked", chan_name, user->nick);
  presence_del(pres);
 }
 else {
  info("user %s/%s kicked: wasn't aware of presence",
   chan_name, victim_prefix);
 }
}

canonical_original_code:
static void handle_kick(char *prefix, char *cmd, char *params)
{
 struct chan *chan;
 struct user *user;
 struct presence *pres;
 char *chan_name; char *victim_prefix; char *save;
 chan_name = strtok_r(params, " ", &save);
 victim_prefix = strtok_r(((void *)0), " ", &save);
 chan = chan_find(chan_name);
 user = user_find(victim_prefix);
 pres = chan && user ? presence_find(chan, user) : ((void *)0);
 if (pres) {
  info("user %s/%s kicked", chan_name, user->nick);
  presence_del(pres);
 }
 else {
  info("user %s/%s kicked: wasn't aware of presence",
   chan_name, victim_prefix);
 }
}

variable_types:
cmd
char *

user_defined_types: struct user { char nick[512]; char host[512]; char uname[512]; char rname[512]; struct list_head presences; _Bool reg; }

user_defined_types: struct list_head { struct list_head *next; }

user_defined_types: enum priv { PRIV_NONE=0, PRIV_OPERATOR=10, PRIV_HIGHEST=20 }


decompiled_code:
__int64 __fastcall handle_part(const char *a1, __int64 a2, const char *a3)
{
char *v3; // rbx
const char *v4; // rax
const char *v5; // rbp
const char *v6; // r12
__int64 v7; // rax

v3 = strpbrk(a3, chantypes);
v4 = chan_find(v3);
if ( !v4 )
return info("user %s/%s left: wasn't aware of presence", v3, a1);
v5 = v4;
v6 = (const char *)user_find(a1);
info("user %s/%s left", v3, v6);
v7 = presence_find(v5, v6);
return presence_del(v7);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2, const char *a3)
{
char *v3; // rbx
const char *v4; // rax
const char *v5; // rbp
const char *v6; // r12
__int64 v7; // rax

v3 = strpbrk(a3, chantypes);
v4 = func3(v3);
if ( !v4 )
return info("user %s/%s left: wasn't aware of presence", v3, a1);
v5 = v4;
v6 = (const char *)user_find(a1);
info("user %s/%s left", v3, v6);
v7 = presence_find(v5, v6);
return presence_del(v7);
}

original_code:
static void handle_part(char *prefix, char *cmd, char *params)
{
 struct chan *chan;
 struct user *user;
 char *chan_name;
 chan_name = strpbrk(params, chantypes);
 chan = chan_find(chan_name);
 if (chan) {
  user = user_find(prefix);
  info("user %s/%s left", chan_name, user->nick);
  presence_del(presence_find(chan, user));
 }
 else {
  info("user %s/%s left: wasn't aware of presence",
   chan_name, prefix);
 }
}


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

v1 = (const char *)user_find(a1);
if ( !v1 )
return info("user %s quit: wasn't aware of user", a1);
v2 = v1;
info("user %s quit", v1);
return user_del(v2);
}

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

v1 = (const char *)user_find(a1);
if ( !v1 )
return info("user %s quit: wasn't aware of user", a1);
v2 = v1;
info("user %s quit", v1);
return user_del(v2);
}

original_code:
static void handle_quit(char *prefix, char *cmd, char *params)
{
 struct user *user;
 user = user_find(prefix);
 if (user) {
  info("user %s quit", user->nick);
  user_del(user);
 }
 if (!user) {
  info("user %s quit: wasn't aware of user", prefix);
 }
}


decompiled_code:
__int64 __fastcall handle_join_other(char *a1, __int64 a2)
{
const char *v2; // r12
const char *v3; // rbp
__int64 result; // rax
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = chan_find(a1);
v3 = (const char *)user_get(a2);
*(_DWORD *)(presence_get3(v2, v3, v5) + 48) = 0;
if ( v5[0] || (result = info("user %s/%s joined", a1, v3), v5[0]) )
result = info("user %s/%s joined: thought already present", a1, v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1, __int64 a2)
{
const char *v2; // r12
const char *v3; // rbp
__int64 result; // rax
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = func3(a1);
v3 = (const char *)user_get(a2);
*(_DWORD *)(presence_get3(v2, v3, v5) + 48) = 0;
if ( v5[0] || (result = info("user %s/%s joined", a1, v3), v5[0]) )
result = info("user %s/%s joined: thought already present", a1, v3);
return result;
}

original_code:
static void handle_join_other(char *chan_name, char *prefix)
{
 struct chan *chan;
 struct user *user;
 struct presence *pres;
 _Bool existed;
 chan = chan_find(chan_name);
 user = user_get(prefix);
 pres = presence_get3(chan, user, &existed);
 pres->priv = PRIV_NONE;
 if (!existed)
  info("user %s/%s joined", chan_name, user->nick);
 if (existed)
  info("user %s/%s joined: thought already present",
   chan_name, user->nick);
}


decompiled_code:
void __fastcall handle_join(__int64 a1, __int64 a2, const char *a3)
{
char *v3; // rbp

v3 = strpbrk(a3, chantypes);
if ( (unsigned __int8)isme(a1) )
handle_join_me(v3);
else
handle_join_other(v3, a1);
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, __int64 a2, const char *a3)
{
char *v3; // rbp

v3 = strpbrk(a3, chantypes);
if ( (unsigned __int8)isme(a1) )
func9(v3);
else
func10(v3, a1);
}

original_code:
static void handle_join(char *prefix, char *cmd, char *params)
{
 char *chan_name;
 chan_name = strpbrk(params, chantypes);
 if (isme(prefix))
  handle_join_me(chan_name);
 else
  handle_join_other(chan_name, prefix);
}


decompiled_code:
char *__fastcall chan_set_prefix(char *src)
{
return strcpy(chantypes, src);
}

canonical_decompiled_code:
char *__fastcall func12(char *src)
{
return strcpy(chantypes, src);
}

original_code:
void chan_set_prefix(char *prefixes)
{
 strcpy(chantypes, prefixes);
}

variable_types:
prefixes
char *


decompiled_code:
bool __fastcall chan_is_prefix(char a1)
{
return strchr(chantypes, a1) != 0LL;
}

canonical_decompiled_code:
bool __fastcall func13(char a1)
{
return strchr(chantypes, a1) != 0LL;
}

original_code:
_Bool chan_is_prefix(char c)
{
 return strchr(chantypes, c) != ((void *)0);
}

variable_types: c char


decompiled_code:
__int64 chan_init()
{
callback_register_str(handle_join, "JOIN");
callback_register_str(handle_part, "PART");
callback_register_str(handle_quit, "QUIT");
callback_register_str(handle_kick, "KICK");
callback_register_numeric(handle_names, 353LL);
return callback_register_numeric(handle_names_end, 366LL);
}

canonical_decompiled_code:
__int64 func14()
{
callback_register_str(handle_join, "JOIN");
callback_register_str(handle_part, "PART");
callback_register_str(handle_quit, "QUIT");
callback_register_str(handle_kick, "KICK");
callback_register_numeric(handle_names, 353LL);
return callback_register_numeric(handle_names_end, 366LL);
}

original_code:
void chan_init()
{
 callback_register_str(handle_join, "JOIN");
 callback_register_str(handle_part, "PART");
 callback_register_str(handle_quit, "QUIT");
 callback_register_str(handle_kick, "KICK");
 callback_register_numeric(handle_names, 353);
 callback_register_numeric(handle_names_end, 366);
}


chomp

decompiled_code:
const char *__fastcall chomp(const char *a1)
{
const char *v1; // rax

v1 = &a1[(int)(strlen(a1) - 1)];
if ( *v1 == 10 )
*v1 = 0;
return a1;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1)
{
const char *v1; // rax

v1 = &a1[(int)(strlen(a1) - 1)];
if ( *v1 == 10 )
*v1 = 0;
return a1;
}

original_code:
char *chomp(char *str)
{
 int last = strlen(str) - 1;
 if (str[last] == '\n')
  str[last] = '\0';
 return str;
}

variable_types:
str
char *

variable_types: last int

return_type: char *


pdlerror

decompiled_code:
__int64 pdlerror()
{
char *v0; // rax

v0 = dlerror();
if ( v0 )
err((int)"dlerror: %s", v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
char *v0; // rax

v0 = dlerror();
if ( v0 )
err((int)"dlerror: %s", v0);
return 0LL;
}

original_code:
static _Bool pdlerror()
{
 char *errmsg = dlerror();
 if (errmsg)
  err("dlerror: %s", errmsg);
 return errmsg != ((void *)0);
}

variable_types:
errmsg
char *


decompiled_code:
const char *__fastcall plg_find(char *s1)
{
const char *v1; // rbx

v1 = (const char *)plgs;
if ( plgs == &plgs )
LABEL_4:
err((int)"plg_find: %s: not found", s1);
while ( strncmp(s1, v1 + 16, 0x100uLL) )
{
v1 = *(const char **)v1;
if ( v1 == (const char *)&plgs )
goto LABEL_4;
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func3(char *s1)
{
const char *v1; // rbx

v1 = (const char *)plgs;
if ( plgs == &plgs )
LABEL_4:
err((int)"plg_find: %s: not found", s1);
while ( strncmp(s1, v1 + 16, 0x100uLL) )
{
v1 = *(const char **)v1;
if ( v1 == (const char *)&plgs )
goto LABEL_4;
}
return v1;
}

original_code:
static struct plg *plg_find(char *plg_name)
{
 struct list_head *node;
 struct plg *plg;
 for (node = (&plgs)->next; node != (&plgs); node = node->next) {
  plg = ((struct plg *)((char *)(node)-(unsigned long)(&((struct plg *)0)->link)));
  if (!strncmp(plg_name, plg->name, sizeof(plg->name)))
   return plg;
 }
 err("plg_find: %s: not found", plg_name);
 return ((void *)0);
}

variable_types: struct plg { struct list_head { struct list_head *next; } link; char name[256]; char file[256]; void *so; int (*init)(); void (*finish)(); } *

user_defined_types: struct plg { struct list_head link; char name[256]; char file[256]; void *so; int (*init)(); void (*finish)(); }


decompiled_code:
void plg_free_all()
{
void **v0; // rbx
void **v1; // rbp

v0 = (void **)plgs;
v1 = *(void ***)plgs;
if ( plgs != &plgs )
{
do
{
((void (*)(void))v0[68])();
dlclose(v0[66]);
pdlerror();
free(v0);
v0 = v1;
v1 = (void **)*v1;
}
while ( v0 != &plgs );
}
}

canonical_decompiled_code:
void func4()
{
void **v0; // rbx
void **v1; // rbp

v0 = (void **)plgs;
v1 = *(void ***)plgs;
if ( plgs != &plgs )
{
do
{
((void (*)(void))v0[68])();
dlclose(v0[66]);
func2();
free(v0);
v0 = v1;
v1 = (void **)*v1;
}
while ( v0 != &plgs );
}
}

original_code:
void plg_free_all()
{
 struct list_head *node, *next;
 struct plg *plg;
 for (node = (&plgs)->next, next = node->next; node != (&plgs); node = next, next = node->next) {
  plg = ((struct plg *)((char *)(node)-(unsigned long)(&((struct plg *)0)->link)));
  plg->finish();
  dlclose(plg->so);
  pdlerror();
  free(plg);
 }
}

canonical_original_code:
void plg_free_all()
{
 struct list_head *node; struct list_head *next;
 struct plg *plg;
 for (node = (&plgs)->next, next = node->next; node != (&plgs); node = next, next = node->next) {
  plg = ((struct plg *)((char *)(node)-(unsigned long)(&((struct plg *)0)->link)));
  plg->finish();
  dlclose(plg->so);
  pdlerror();
  free(plg);
 }
}


decompiled_code:
void __fastcall plg_load(char *src)
{
char *v1; // rbx

v1 = (char *)malloc(0x228uLL);
strncpy(v1 + 16, src, 0x100uLL);
snprintf(v1 + 272, 0x100uLL, "plg/%s/%s.so", src, src);
*((_QWORD *)v1 + 66) = dlopen(v1 + 272, 258);
if ( (unsigned __int8)pdlerror()
|| (*((_QWORD *)v1 + 67) = dlsym(*((void **)v1 + 66), "init"), (unsigned __int8)pdlerror())
|| (*((_QWORD *)v1 + 68) = dlsym(*((void **)v1 + 66), "finish"), (unsigned __int8)pdlerror()) )
{
free(v1);
}
else
{
if ( (*((unsigned int (**)(void))v1 + 67))() )
err((int)"plg->init(): failed: %s", src);
list_add(v1, (__int64 *)&plgs);
}
}

canonical_decompiled_code:
void __fastcall func5(char *src)
{
char *v1; // rbx

v1 = (char *)malloc(0x228uLL);
strncpy(v1 + 16, src, 0x100uLL);
snprintf(v1 + 272, 0x100uLL, "plg/%s/%s.so", src, src);
*((_QWORD *)v1 + 66) = dlopen(v1 + 272, 258);
if ( (unsigned __int8)func2()
|| (*((_QWORD *)v1 + 67) = dlsym(*((void **)v1 + 66), "init"), (unsigned __int8)func2())
|| (*((_QWORD *)v1 + 68) = dlsym(*((void **)v1 + 66), "finish"), (unsigned __int8)func2()) )
{
free(v1);
}
else
{
if ( (*((unsigned int (**)(void))v1 + 67))() )
err((int)"plg->init(): failed: %s", src);
func1(v1, (__int64 *)&plgs);
}
}

original_code:
void plg_load(char *plg_name)
{
 struct plg *plg = malloc(sizeof(struct plg));
 strncpy(plg->name, plg_name, sizeof(plg->name));
 snprintf(plg->file, sizeof(plg->file), "plg/%s/%s.so",
  plg_name, plg_name);
 plg->so = dlopen(plg->file, 0x00002 | 0x00100);
 if (pdlerror())
  goto err;
 plg->init = dlsym(plg->so, "init");
 if (pdlerror())
  goto err;
 plg->finish = dlsym(plg->so, "finish");
 if (pdlerror())
  goto err;
 if (plg->init()) {
  err("plg->init(): failed: %s", plg_name);
  goto err;
 }
 list_add(&plg->link, &plgs);
 return;
err:
 free(plg);
}


decompiled_code:
void *__fastcall plg_sym(char *a1, const char *a2)
{
const char *v2; // rax
void *v3; // rbx

v2 = plg_find(a1);
v3 = (void *)v2;
if ( v2 )
{
v3 = dlsym(*((void **)v2 + 66), a2);
pdlerror();
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func7(char *a1, const char *a2)
{
const char *v2; // rax
void *v3; // rbx

v2 = func3(a1);
v3 = (void *)v2;
if ( v2 )
{
v3 = dlsym(*((void **)v2 + 66), a2);
func2();
}
return v3;
}

original_code:
void *plg_sym(char *plg_name, char *symbol)
{
 struct plg *plg;
 void *addr;
 plg = plg_find(plg_name);
 if (plg) {
  addr = dlsym(plg->so, symbol);
  pdlerror();
  return addr;
 }
 else {
  return ((void *)0);
 }
}

variable_types:
symbol
char *

variable_types:
addr
void *

return_type: void *


decompiled_code:
__int64 free_str_events()
{
return hashtab_destroy(str_events);
}

canonical_decompiled_code:
__int64 func0()
{
return hashtab_destroy(str_events);
}

original_code:
static void free_str_events()
{
 hashtab_destroy(str_events);
}


decompiled_code:
__int64 __fastcall callback_register_numeric(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( (int)a2 > 549 )
_assert_fail("ncmd < MAX_NUMERIC", "callback.c", 0x2Eu, "callback_register_numeric");
result = (int)a2;
if ( num_events[(int)a2] )
result = info("callback_register_numeric: %d: overwriting event", a2);
num_events[(int)a2] = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( (int)a2 > 549 )
_assert_fail("ncmd < MAX_NUMERIC", "callback.c", 0x2Eu, "callback_register_numeric");
result = (int)a2;
if ( num_events[(int)a2] )
result = info("callback_register_numeric: %d: overwriting event", a2);
num_events[(int)a2] = a1;
return result;
}

original_code:
void callback_register_numeric(callback_numeric call, int ncmd)
{
 ((void) sizeof ((ncmd < 550) ? 1 : 0), __extension__ ({ if (ncmd < 550) ; else __assert_fail ("ncmd < MAX_NUMERIC", "callback.c", 46, __extension__ __PRETTY_FUNCTION__); }));
 if (num_events[ncmd])
  info("callback_register_numeric: %d: overwriting event", ncmd);
 num_events[ncmd] = call;
}

canonical_original_code:
void callback_register_numeric(void (*call)(char *prefix, int ncmd, char *params), int ncmd)
{
 ((void) sizeof ((ncmd < 550) ? 1 : 0), __extension__ ({ if (ncmd < 550) ; else __assert_fail ("ncmd < MAX_NUMERIC", "callback.c", 46, __extension__ __PRETTY_FUNCTION__); }));
 if (num_events[ncmd])
  info("callback_register_numeric: %d: overwriting event", ncmd);
 num_events[ncmd] = call;
}

variable_types: void (*)(char *prefix, int ncmd, char *params)

variable_types: ncmd int


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

result = hashtab_insert(str_events, a2, a1);
if ( (_DWORD)result == -1 )
err((int)"callback_register_str: %s: event already exists", a2);
return result;
}

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

result = hashtab_insert(str_events, a2, a1);
if ( (_DWORD)result == -1 )
err((int)"callback_register_str: %s: event already exists", a2);
return result;
}

original_code:
void callback_register_str(callback_str call, char *cmd)
{
 if (hashtab_insert(str_events, cmd, call) == -1)
  err("callback_register_str: %s: event already exists", cmd);
}

canonical_original_code:
void callback_register_str(void (*call)(char *prefix, char *cmd, char *params), char *cmd)
{
 if (hashtab_insert(str_events, cmd, call) == -1)
  err("callback_register_str: %s: event already exists", cmd);
}

variable_types: void (*)(char *prefix, char *cmd, char *params)


decompiled_code:
__int64 callback_init()
{
memset(num_events, 0, sizeof(num_events));
str_events = hashtab_create(&str_hash, &strcmp_hash, 31LL);
return add_shutdown_fn(free_str_events);
}

canonical_decompiled_code:
__int64 func3()
{
memset(num_events, 0, sizeof(num_events));
str_events = hashtab_create(&str_hash, &strcmp_hash, 31LL);
return add_shutdown_fn(free_str_events);
}

original_code:
void callback_init()
{
 memset(num_events, 0, sizeof(num_events));
 str_events = hashtab_create(str_hash, strcmp_hash, 31);
 add_shutdown_fn(free_str_events);
}


isme

decompiled_code:
bool __fastcall isme(char *s1)
{
char *v1; // rax
size_t v2; // rbx
const char *v3; // r12
int v4; // edx
bool v5; // al

v1 = strchr(s1, 33);
if ( !v1 )
return strcasecmp(s1, bot_nick) == 0;
v2 = (int)v1 - (int)s1;
v3 = bot_nick;
v4 = strncasecmp(s1, bot_nick, v2);
v5 = 0;
if ( !v4 )
v5 = v2 == strlen(v3);
return v5;
}

canonical_decompiled_code:
bool __fastcall func0(char *s1)
{
char *v1; // rax
size_t v2; // rbx
const char *v3; // r12
int v4; // edx
bool v5; // al

v1 = strchr(s1, 33);
if ( !v1 )
return strcasecmp(s1, bot_nick) == 0;
v2 = (int)v1 - (int)s1;
v3 = bot_nick;
v4 = strncasecmp(s1, bot_nick, v2);
v5 = 0;
if ( !v4 )
v5 = v2 == strlen(v3);
return v5;
}

original_code:
_Bool isme(char *prefix)
{
 char *bang;
 int len;
 bang = strchr(prefix, '!');
 if (bang) {
  len = bang - prefix;
  return !strncasecmp(prefix, bot_nick, len) &&
   strlen(bot_nick) == len;
 }
 else {
  return !strcasecmp(prefix, bot_nick);
 }
}

variable_types:
prefix
char *

variable_types:
bang
char *

variable_types: len int


decompiled_code:
void __fastcall user_del(void *ptr)
{
hashtab_remove(users, ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
hashtab_remove(users, ptr);
free(ptr);
}

original_code:
void user_del(struct user *user)
{
 hashtab_remove(users, user->nick);
 free(user);
}

variable_types: struct user { char nick[512]; char host[512]; char uname[512]; char rname[512]; struct list_head { struct list_head *next; } presences; _Bool reg; } *


decompiled_code:
__int64 __fastcall user_find(__int64 a1)
{
char v2[520]; // [rsp+8h] [rbp-208h] BYREF

ircproto_parse_prefix(a1, v2, 512LL, 0LL, 0LL, 0LL, 0LL);
return hashtab_search(users, v2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
char v2[520]; // [rsp+8h] [rbp-208h] BYREF

ircproto_parse_prefix(a1, v2, 512LL, 0LL, 0LL, 0LL, 0LL);
return hashtab_search(users, v2);
}

original_code:
struct user *user_find(char *prefix)
{
 struct user *user;
 char nick[512];
 ircproto_parse_prefix(prefix, nick, sizeof(nick), ((void *)0), 0, ((void *)0), 0);
 user = hashtab_search(users, nick);
 return user;
}

variable_types:
nick
char [512]

return_type: struct user { char nick[512]; char host[512]; char uname[512]; char rname[512]; struct list_head { struct list_head *next; } presences; _Bool reg; } *


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

result = user_find(a1);
if ( !result )
result = (__int64)user_new(a1);
return result;
}

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

result = func2(a1);
if ( !result )
result = (__int64)user_new(a1);
return result;
}

original_code:
struct user *user_get(char *prefix)
{
 struct user *user;
 user = user_find(prefix);
 return user ? user : user_new(prefix);
}


decompiled_code:
__int64 __fastcall user_get2(__int64 a1, bool *a2)
{
__int64 result; // rax

result = user_find(a1);
*a2 = result != 0;
if ( !result )
result = (__int64)user_new(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, bool *a2)
{
__int64 result; // rax

result = func2(a1);
*a2 = result != 0;
if ( !result )
result = (__int64)user_new(a1);
return result;
}

original_code:
struct user *user_get2(char *prefix, _Bool *existed)
{
 struct user *user;
 user = user_find(prefix);
 *existed = user != ((void *)0);
 return user ? user : user_new(prefix);
}

variable_types:
existed
_Bool *


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

result = hashtab_create(&str_hash, &strcmp_hash, 101LL);
users = result;
return result;
}

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

result = hashtab_create(&str_hash, &strcmp_hash, 101LL);
users = result;
return result;
}

original_code:
void usr_init()
{
 users = hashtab_create(str_hash, strcmp_hash, 101);
}


decompiled_code:
__int64 __fastcall regex_compile(const char **a1)
{
__int64 result; // rax
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

result = pcre_compile(*a1, 0LL, &v3, &v2, 0LL);
a1[2] = (const char *)result;
if ( result )
{
*((_DWORD *)a1 + 2) = 2;
}
else
{
*((_DWORD *)a1 + 2) = 1;
result = info("regex '%s':%d: %s", *a1, v2, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1)
{
__int64 result; // rax
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

result = pcre_compile(*a1, 0LL, &v3, &v2, 0LL);
a1[2] = (const char *)result;
if ( result )
{
*((_DWORD *)a1 + 2) = 2;
}
else
{
*((_DWORD *)a1 + 2) = 1;
result = info("regex '%s':%d: %s", *a1, v2, v3);
}
return result;
}

original_code:
static void regex_compile(struct regex *re)
{
 const char* err;
 int erroff;
 re->re_detail = pcre_compile(re->pattern, 0, &err, &erroff, ((void *)0));
 if (re->re_detail) {
  re->state = RCS_COMPILED;
 }
 else {
  re->state = RCS_ERROR;
  info("regex '%s':%d: %s", re->pattern, erroff, err);
 }
}

canonical_original_code:
static void regex_compile(struct regex *re)
{
 char *err;
 int erroff;
 re->re_detail = pcre_compile(re->pattern, 0, &err, &erroff, ((void *)0));
 if (re->re_detail) {
  re->state = RCS_COMPILED;
 }
 else {
  re->state = RCS_ERROR;
  info("regex '%s':%d: %s", re->pattern, erroff, err);
 }
}

variable_types: struct regex { char *pattern; enum regex_compiled_state { RCS_UNINIT=0, RCS_ERROR=1, RCS_COMPILED=2 } state; void *re_detail; } *

variable_types:
err
char *

variable_types: erroff int

user_defined_types: struct regex { char *pattern; enum regex_compiled_state state; void *re_detail; }


original_code:
static int regex_match_exec(struct regex *re, char *str, char **caps)
{
 int vec[(3*(10 +1))];
 int matches, beg, end, len, i;
 char* cap;
 matches = pcre_exec(re->re_detail, ((void *)0), str, strlen(str),
  0, 0, vec, (3*(10 +1)));
 if (matches < (-1)) {
  info("pcre_exec failed: code=%d, re=%s, str=%s",
   matches, re->pattern, str);
 }
 if (caps) {
  for (i = 0; i < matches - 1; i++) {
   cap = caps[i];
   beg = vec[2*i + 2];
   end = vec[2*i + 3];
   len = end - beg;
   memcpy(cap, &str[beg], len);
   cap[len] = '\0';
  }
 }
 return matches;
}

canonical_original_code:
static int regex_match_exec(struct regex *re, char *str, char **caps)
{
 int vec[-1];
 int matches; int beg; int end; int len; int i;
 char *cap;
 matches = pcre_exec(re->re_detail, ((void *)0), str, strlen(str),
  0, 0, vec, (3*(10 +1)));
 if (matches < (-1)) {
  info("pcre_exec failed: code=%d, re=%s, str=%s",
   matches, re->pattern, str);
 }
 if (caps) {
  for (i = 0; i < matches - 1; i++) {
   cap = caps[i];
   beg = vec[2*i + 2];
   end = vec[2*i + 3];
   len = end - beg;
   memcpy(cap, &str[beg], len);
   cap[len] = '\0';
  }
 }
 return matches;
}

variable_types:
str
char *

variable_types:
caps
char **

variable_types:
vec
int [-1]

variable_types: matches int

variable_types: beg int

variable_types: end int

variable_types: i int

variable_types:
cap
char *

return_type: int

user_defined_types: enum regex_compiled_state { RCS_UNINIT=0, RCS_ERROR=1, RCS_COMPILED=2 }


decompiled_code:
__int64 __fastcall regex_match(__int64 a1, const char *a2, __int64 a3)
{
int v4; // eax
__int64 result; // rax

v4 = *(_DWORD *)(a1 + 8);
if ( v4 )
{
if ( v4 == 2 )
result = regex_match_exec(a1, a2, a3);
else
result = 0LL;
}
else
{
regex_compile((const char **)a1);
result = regex_match(a1, a2, a3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, __int64 a3)
{
int v4; // eax
__int64 result; // rax

v4 = *(_DWORD *)(a1 + 8);
if ( v4 )
{
if ( v4 == 2 )
result = func1(a1, a2, a3);
else
result = 0LL;
}
else
{
func0((const char **)a1);
result = func2(a1, a2, a3);
}
return result;
}

original_code:
int regex_match(struct regex *re, char *str, char **caps)
{
 switch (re->state) {
 case RCS_UNINIT:
  regex_compile(re);
  return regex_match(re, str, caps);
 case RCS_COMPILED:
  return regex_match_exec(re, str, caps);
 case RCS_ERROR:
  return 0;
 }
 return 0;
}


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

if ( *(_DWORD *)(a1 + 8) == 2 )
result = pcre_free(*(_QWORD *)(a1 + 16));
return result;
}

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

if ( *(_DWORD *)(a1 + 8) == 2 )
result = pcre_free(*(_QWORD *)(a1 + 16));
return result;
}

original_code:
void regex_free(struct regex *re)
{
 if (re->state == RCS_COMPILED)
  pcre_free(re->re_detail);
}


decompiled_code:
__int64 __fastcall mode2priv(char a1)
{
return (unsigned int)modetab[a1];
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return (unsigned int)modetab[a1];
}

original_code:
enum priv mode2priv(char mode)
{
 return modetab[mode];
}

variable_types: mode char

return_type: enum priv { PRIV_NONE=0, PRIV_OPERATOR=10, PRIV_HIGHEST=20 }


decompiled_code:
__int64 __fastcall prefix2priv(char a1)
{
return (unsigned int)prefixtab[a1];
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
return (unsigned int)prefixtab[a1];
}

original_code:
enum priv prefix2priv(char prefix)
{
 return prefixtab[prefix];
}

variable_types: prefix char


decompiled_code:
__int64 __fastcall auth_isowner(char *s1)
{
char *v1; // rax
int v2; // eax
const char **v3; // rbp
const char *v4; // rbx
size_t v5; // r12

v1 = strchr(s1, 33);
if ( v1 )
v2 = (_DWORD)v1 - (_DWORD)s1;
else
v2 = strlen(s1);
v3 = (const char **)bot_owners;
v4 = (const char *)*bot_owners;
if ( !*bot_owners )
return 0LL;
v5 = v2;
do
{
if ( !strncasecmp(s1, v4, v5) && v5 == strlen(v4) )
return 1LL;
v4 = *++v3;
}
while ( *v3 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
char *v1; // rax
int v2; // eax
const char **v3; // rbp
const char *v4; // rbx
size_t v5; // r12

v1 = strchr(s1, 33);
if ( v1 )
v2 = (_DWORD)v1 - (_DWORD)s1;
else
v2 = strlen(s1);
v3 = (const char **)bot_owners;
v4 = (const char *)*bot_owners;
if ( !*bot_owners )
return 0LL;
v5 = v2;
do
{
if ( !strncasecmp(s1, v4, v5) && v5 == strlen(v4) )
return 1LL;
v4 = *++v3;
}
while ( *v3 );
return 0LL;
}

original_code:
_Bool auth_isowner(char *usr)
{
 int i;
 int len;
 char *bang, *owner, **owners;
 bang = strchr(usr, '!');
 len = bang ? bang - usr : strlen(usr);
 for (owners = bot_owners; *owners; owners++) {
  owner = *owners;
  if (!strncasecmp(usr, owner, len) && strlen(owner) == len)
   return 1;
 }
 return 0;
}

canonical_original_code:
_Bool auth_isowner(char *usr)
{
 int i;
 int len;
 char *bang; char *owner; char **owners;
 bang = strchr(usr, '!');
 len = bang ? bang - usr : strlen(usr);
 for (owners = bot_owners; *owners; owners++) {
  owner = *owners;
  if (!strncasecmp(usr, owner, len) && strlen(owner) == len)
   return 1;
 }
 return 0;
}

variable_types:
usr
char *

variable_types: len int

variable_types:
bang
char *

variable_types:
owner
char *

variable_types:
owners
char **


decompiled_code:
__int64 __fastcall auth_set_prefix(_BYTE *a1, _BYTE *a2)
{
_BYTE *v2; // r8
__int64 result; // rax

v2 = a1;
result = 0LL;
memset(modetab, 0, sizeof(modetab));
memset(prefixtab, 0, sizeof(prefixtab));
if ( *a1 )
{
LODWORD(result) = 20;
do
{
result = (unsigned int)(result - 1);
if ( *a2 == 64 )
result = 10LL;
prefixtab[(char)*a2] = result;
modetab[(char)*v2++] = result;
++a2;
}
while ( *v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1, _BYTE *a2)
{
_BYTE *v2; // r8
__int64 result; // rax

v2 = a1;
result = 0LL;
memset(modetab, 0, sizeof(modetab));
memset(prefixtab, 0, sizeof(prefixtab));
if ( *a1 )
{
LODWORD(result) = 20;
do
{
result = (unsigned int)(result - 1);
if ( *a2 == 64 )
result = 10LL;
prefixtab[(char)*a2] = result;
modetab[(char)*v2++] = result;
++a2;
}
while ( *v2 );
}
return result;
}

original_code:
void auth_set_prefix(char *modes, char *prefixes)
{
 char *mode, *prefix;
 enum priv priv;
 memset(modetab, 0, sizeof(modetab));
 memset(prefixtab, 0, sizeof(modetab));
 priv = PRIV_HIGHEST;
 for (mode = modes, prefix = prefixes; *mode; mode++, prefix++) {
  if (*prefix == '@')
   priv = PRIV_OPERATOR;
  else
   priv--;
  modetab[*mode] = prefixtab[*prefix] = priv;
 }
}

canonical_original_code:
void auth_set_prefix(char *modes, char *prefixes)
{
 char *mode; char *prefix;
 enum priv priv;
 memset(modetab, 0, sizeof(modetab));
 memset(prefixtab, 0, sizeof(modetab));
 priv = PRIV_HIGHEST;
 for (mode = modes, prefix = prefixes; *mode; mode++, prefix++) {
  if (*prefix == '@')
   priv = PRIV_OPERATOR;
  else
   priv--;
  modetab[*mode] = prefixtab[*prefix] = priv;
 }
}

variable_types:
modes
char *

variable_types:
prefixes
char *

variable_types:
mode
char *

variable_types:
prefix
char *

variable_types: enum priv { PRIV_NONE=0, PRIV_OPERATOR=10, PRIV_HIGHEST=20 }


decompiled_code:
__int64 auth_init()
{
return auth_set_prefix(byte_923, byte_920);
}

canonical_decompiled_code:
__int64 func4()
{
return func3(byte_923, byte_920);
}

original_code:
void auth_init()
{
 auth_set_prefix("ov", "@+");
}


decompiled_code:
int close_connection()
{
int result; // eax

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0x79u, "close_connection");
if ( ssl )
{
if ( (unsigned int)SSL_shutdown() == -1 )
ERR_print_errors_fp(stderr);
SSL_free(ssl);
}
result = close(sock);
if ( result == -1 )
result = err_errno("close");
sock = -1;
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0x79u, "close_connection");
if ( ssl )
{
if ( (unsigned int)SSL_shutdown() == -1 )
ERR_print_errors_fp(stderr);
SSL_free(ssl);
}
result = close(sock);
if ( result == -1 )
result = err_errno("close");
sock = -1;
return result;
}

original_code:
void close_connection()
{
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 121, __extension__ __PRETTY_FUNCTION__); }));
 if (ssl != ((void *)0)) {
  if (SSL_shutdown(ssl) == -1)
   ERR_print_errors_fp(stderr);
  SSL_free(ssl);
 }
 if (close(sock) == -1)
  err_errno("close");
 sock = -1;
}


decompiled_code:
ssize_t __fastcall sock_send(void *buf, size_t n)
{
ssize_t result; // rax

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0x88u, "sock_send");
if ( ssl )
{
result = SSL_write(ssl, buf, n);
if ( (int)result <= 0 )
{
ERR_print_errors_fp(stderr);
result = safe_shutdown_and_die(1LL);
}
}
else
{
result = send(sock, buf, n, 0);
if ( result == -1 )
{
err_errno("send");
result = safe_shutdown_and_die(1LL);
}
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(void *buf, size_t n)
{
ssize_t result; // rax

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0x88u, "sock_send");
if ( ssl )
{
result = SSL_write(ssl, buf, n);
if ( (int)result <= 0 )
{
ERR_print_errors_fp(stderr);
result = safe_shutdown_and_die(1LL);
}
}
else
{
result = send(sock, buf, n, 0);
if ( result == -1 )
{
err_errno("send");
result = safe_shutdown_and_die(1LL);
}
}
return result;
}

original_code:
void sock_send(const void *buffer, size_t length)
{
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 136, __extension__ __PRETTY_FUNCTION__); }));
 if (ssl == ((void *)0)) {
  if (send(sock, buffer, length, 0) == -1) {
   err_errno("send");
   safe_shutdown_and_die(1);
  }
 }
 else {
  if (SSL_write(ssl, buffer, length) <= 0) {
   ERR_print_errors_fp(stderr);
   safe_shutdown_and_die(1);
  }
 }
}

canonical_original_code:
void sock_send(void *buffer, unsigned long length)
{
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 136, __extension__ __PRETTY_FUNCTION__); }));
 if (ssl == ((void *)0)) {
  if (send(sock, buffer, length, 0) == -1) {
   err_errno("send");
   safe_shutdown_and_die(1);
  }
 }
 else {
  if (SSL_write(ssl, buffer, length) <= 0) {
   ERR_print_errors_fp(stderr);
   safe_shutdown_and_die(1);
  }
 }
}

variable_types:
buffer
void *

variable_types:
length
unsigned long


decompiled_code:
ssize_t __fastcall sock_recv(void *buf, size_t n)
{
ssize_t result; // rax

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0x9Au, "sock_recv");
if ( ssl )
result = (int)SSL_read(ssl, buf, n);
else
result = recv(sock, buf, n, 0);
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(void *buf, size_t n)
{
ssize_t result; // rax

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0x9Au, "sock_recv");
if ( ssl )
result = (int)SSL_read(ssl, buf, n);
else
result = recv(sock, buf, n, 0);
return result;
}

original_code:
ssize_t sock_recv(void *buffer, size_t length)
{
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 154, __extension__ __PRETTY_FUNCTION__); }));
 if (ssl == ((void *)0))
  return recv(sock, buffer, length, 0);
 else
  return SSL_read(ssl, buffer, length);
}

canonical_original_code:
long sock_recv(void *buffer, unsigned long length)
{
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 154, __extension__ __PRETTY_FUNCTION__); }));
 if (ssl == ((void *)0))
  return recv(sock, buffer, length, 0);
 else
  return SSL_read(ssl, buffer, length);
}

return_type: long


decompiled_code:
ssize_t sock_drainline()
{
ssize_t result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 0;
if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0xC2u, "sock_drainline");
do
{
result = sock_recv(buf, 1uLL);
if ( (_DWORD)result == -1 )
{
err_errno("recv");
result = safe_shutdown_and_die(1LL);
}
else if ( !(_DWORD)result )
{
info("server closed the socket, quitting");
result = safe_shutdown_and_die(0LL);
}
}
while ( buf[0] != 10 );
return result;
}

canonical_decompiled_code:
ssize_t func4()
{
ssize_t result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 0;
if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0xC2u, "sock_drainline");
do
{
result = func3(buf, 1uLL);
if ( (_DWORD)result == -1 )
{
err_errno("recv");
result = safe_shutdown_and_die(1LL);
}
else if ( !(_DWORD)result )
{
info("server closed the socket, quitting");
result = safe_shutdown_and_die(0LL);
}
}
while ( buf[0] != 10 );
return result;
}

original_code:
static void sock_drainline()
{
 int ret;
 char c = 0;
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 194, __extension__ __PRETTY_FUNCTION__); }));
 while (c != '\n') {
  ret = sock_recv(&c, 1);
  if (ret == -1) {
   err_errno("recv");
   safe_shutdown_and_die(1);
  }
  else if (ret == 0) {
   info("server closed the socket, quitting");
   safe_shutdown_and_die(0);
  }
 }
}

variable_types: ret int

variable_types: c char


decompiled_code:
ssize_t sock_sendline(char *format, ...)
{
size_t v1; // rax
char v3[520]; // [rsp+0h] [rbp-2D8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-D0h] BYREF

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0xA7u, "sock_sendline");
fwrite("> ", 1uLL, 2uLL, socklog);
va_start(arg, format);
vfprintf(socklog, format, arg);
putc(10, socklog);
fflush(socklog);
va_end(arg);
va_start(arg, format);
vsprintf(v3, format, arg);
v1 = strlen(v3);
sock_send(v3, v1);
return sock_send("\n", 1uLL);
}

canonical_decompiled_code:
ssize_t func5(char *format, ...)
{
size_t v1; // rax
char v3[520]; // [rsp+0h] [rbp-2D8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-D0h] BYREF

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0xA7u, "sock_sendline");
fwrite("> ", 1uLL, 2uLL, socklog);
va_start(arg, format);
vfprintf(socklog, format, arg);
putc(10, socklog);
fflush(socklog);
va_end(arg);
va_start(arg, format);
vsprintf(v3, format, arg);
v1 = strlen(v3);
func2(v3, v1);
return func2("\n", 1uLL);
}

original_code:
void sock_sendline(char *format, ...)
{
 va_list args;
 char buffer[512];
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 167, __extension__ __PRETTY_FUNCTION__); }));
 fprintf(socklog, "> ");
 __builtin_va_start(args,format);
 vfprintf(socklog, format, args);
 __builtin_va_end(args);
 putc('\n', socklog);
 fflush(socklog);
 __builtin_va_start(args,format);
 vsprintf(buffer, format, args);
 __builtin_va_end(args);
 sock_send(buffer, strlen(buffer));
 sock_send("\n", 1);
}

canonical_original_code:
void sock_sendline(char *format, ...)
{
 __builtin_va_list args;
 char buffer[512];
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 167, __extension__ __PRETTY_FUNCTION__); }));
 fprintf(socklog, "> ");
 __builtin_va_start(args,format);
 vfprintf(socklog, format, args);
 __builtin_va_end(args);
 putc('\n', socklog);
 fflush(socklog);
 __builtin_va_start(args,format);
 vsprintf(buffer, format, args);
 __builtin_va_end(args);
 sock_send(buffer, strlen(buffer));
 sock_send("\n", 1);
}

variable_types:
format
char *

variable_types:
buffer
char [512]


decompiled_code:
char *sock_readline()
{
int v0; // ebx
int v1; // eax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 0;
if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0xD7u, "sock_readline");
v0 = 0;
while ( 1 )
{
v1 = sock_recv(buf, 1uLL);
if ( v1 == -1 )
{
err_errno("recv");
safe_shutdown_and_die(1LL);
goto LABEL_6;
}
if ( !v1 )
{
info("server closed the socket, quitting");
safe_shutdown_and_die(0LL);
goto LABEL_6;
}
if ( buf[0] != 13 )
{
line_1[v0++] = buf[0];
LABEL_6:
if ( v0 == 512 )
err((int)"server sent line >%d chars, forbidden by RFC, ignoring excess", (const char *)&loc_1FF + 1);
if ( buf[0] == 10 )
break;
}
}
line_1[v0 - 1] = 0;
fprintf(socklog, "< %s\n", line_1);
fflush(socklog);
return line_1;
}

canonical_decompiled_code:
char *func6()
{
int v0; // ebx
int v1; // eax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 0;
if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0xD7u, "sock_readline");
v0 = 0;
while ( 1 )
{
v1 = func3(buf, 1uLL);
if ( v1 == -1 )
{
err_errno("recv");
safe_shutdown_and_die(1LL);
goto LABEL_6;
}
if ( !v1 )
{
info("server closed the socket, quitting");
safe_shutdown_and_die(0LL);
goto LABEL_6;
}
if ( buf[0] != 13 )
{
line_1[v0++] = buf[0];
LABEL_6:
if ( v0 == 512 )
err((int)"server sent line >%d chars, forbidden by RFC, ignoring excess", (const char *)&loc_1FF + 1);
if ( buf[0] == 10 )
break;
}
}
line_1[v0 - 1] = 0;
fprintf(socklog, "< %s\n", line_1);
fflush(socklog);
return line_1;
}

original_code:
char *sock_readline()
{
 static char line[512];
 int ret, i = 0;
 char c = 0;
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 215, __extension__ __PRETTY_FUNCTION__); }));
 while (c != '\n') {
  ret = sock_recv(&c, 1);
  if (ret == -1) {
   err_errno("recv");
   safe_shutdown_and_die(1);
  }
  else if (ret == 0) {
   info("server closed the socket, quitting");
   safe_shutdown_and_die(0);
  }
  else if (c == '\r')
   ;
  else
   line[i++] = c;
  if (i == 512) {
   err("server sent line >%d chars, forbidden by RFC, "
    "ignoring excess", 512);
   sock_drainline();
  }
 }
 line[i-1] = '\0';
 fprintf(socklog, "< %s\n", line);
 fflush(socklog);
 return line;
}

canonical_original_code:
char *sock_readline()
{
 static char line[512];
 int ret; int i = 0;
 char c = 0;
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 215, __extension__ __PRETTY_FUNCTION__); }));
 while (c != '\n') {
  ret = sock_recv(&c, 1);
  if (ret == -1) {
   err_errno("recv");
   safe_shutdown_and_die(1);
  }
  else if (ret == 0) {
   info("server closed the socket, quitting");
   safe_shutdown_and_die(0);
  }
  else if (c == '\r')
   ;
  else
   line[i++] = c;
  if (i == 512) {
   err("server sent line >%d chars, forbidden by RFC, "
    "ignoring excess", 512);
   sock_drainline();
  }
 }
 line[i-1] = '\0';
 fprintf(socklog, "< %s\n", line);
 fflush(socklog);
 return line;
}

variable_types:
line
char [512]

variable_types: i int


decompiled_code:
struct _IO_FILE *sock_init()
{
struct _IO_FILE *result; // rax

result = stdout;
socklog = stdout;
return result;
}

canonical_decompiled_code:
struct _IO_FILE *func7()
{
struct _IO_FILE *result; // rax

result = stdout;
socklog = stdout;
return result;
}

original_code:
void sock_init()
{
 socklog = stdout;
}

canonical_original_code:
void sock_init()
{
 socklog = stdout;
}


decompiled_code:
void **__fastcall ctcp_emit(__int64 a1, __int64 a2, __int64 a3)
{
char *v4; // rax
_QWORD *v5; // rdx
void **v6; // rbx
void **result; // rax

if ( need_init_3 )
{
need_init_3 = 0;
v4 = (char *)&caps_buf_2;
v5 = &caps_1;
do
{
*v5 = v4;
v4 += 512;
++v5;
}
while ( v4 != (char *)&caps_buf_2 + 5120 );
}
v6 = (void **)events;
result = &events;
if ( events != &events )
{
do
{
result = (void **)((unsigned int)regex_match() - 1);
if ( (int)result >= 0 )
result = (void **)((__int64 (__fastcall *)(__int64, __int64, __int64, void *, _QWORD))v6[2])(
a1,
a2,
a3,
&caps_1,
(unsigned int)result);
v6 = (void **)*v6;
}
while ( v6 != &events );
}
return result;
}

canonical_decompiled_code:
void **__fastcall func10(__int64 a1, __int64 a2, __int64 a3)
{
char *v4; // rax
_QWORD *v5; // rdx
void **v6; // rbx
void **result; // rax

if ( need_init_3 )
{
need_init_3 = 0;
v4 = (char *)&caps_buf_2;
v5 = &caps_1;
do
{
*v5 = v4;
v4 += 512;
++v5;
}
while ( v4 != (char *)&caps_buf_2 + 5120 );
}
v6 = (void **)events;
result = &events;
if ( events != &events )
{
do
{
result = (void **)((unsigned int)regex_match() - 1);
if ( (int)result >= 0 )
result = (void **)((__int64 (__fastcall *)(__int64, __int64, __int64, void *, _QWORD))v6[2])(
a1,
a2,
a3,
&caps_1,
(unsigned int)result);
v6 = (void **)*v6;
}
while ( v6 != &events );
}
return result;
}

original_code:
void ctcp_emit(char *usr, char *src, char *msg)
{
 ctcp_callback call;
 struct list_head *node;
 struct re_event *rev;
 int matches, ncap, i;
 static char *caps[10];
 static char caps_buf[512 * 10];
 static _Bool need_init = 1;
 if (need_init) {
  need_init = 0;
  for (i = 0; i < 10; i++)
   caps[i] = &caps_buf[512 * i];
 }
 for (node = (&events)->next; node != (&events); node = node->next) {
  rev = ((struct re_event *)((char *)(node)-(unsigned long)(&((struct re_event *)0)->link)));
  matches = regex_match(&rev->match, msg, caps);
  ncap = matches - 1;
  if (ncap >= 0)
   rev->call(usr, src, msg, caps, ncap);
 }
}

canonical_original_code:
void ctcp_emit(char *usr, char *src, char *msg)
{
 void (*call)(char *usr, char *src, char *msg, char **caps, int ncap);
 struct list_head *node;
 struct re_event *rev;
 int matches; int ncap; int i;
 static char *caps[10];
 static char caps_buf[-1];
 static _Bool need_init = 1;
 if (need_init) {
  need_init = 0;
  for (i = 0; i < 10; i++)
   caps[i] = &caps_buf[512 * i];
 }
 for (node = (&events)->next; node != (&events); node = node->next) {
  rev = ((struct re_event *)((char *)(node)-(unsigned long)(&((struct re_event *)0)->link)));
  matches = regex_match(&rev->match, msg, caps);
  ncap = matches - 1;
  if (ncap >= 0)
   rev->call(usr, src, msg, caps, ncap);
 }
}

variable_types:
usr
char *

variable_types:
src
char *

variable_types:
msg
char *

variable_types: void (*)(char *usr, char *src, char *msg, char **caps, int ncap)

variable_types: struct list_head { struct list_head *next; } *

variable_types: struct re_event { struct list_head { struct list_head *next; } link; void (*call)(char *usr, char *src, char *msg, char **caps, int ncap); struct regex { char *pattern; enum regex_compiled_state { RCS_UNINIT=0, RCS_ERROR=1, RCS_COMPILED=2 } state; void *re_detail; } match; } *

variable_types: matches int

variable_types: ncap int

variable_types:
caps
char *[10]

user_defined_types: struct re_event { struct list_head link; void (*call)(char *usr, char *src, char *msg, char **caps, int ncap); struct regex match; }


decompiled_code:
__int64 __fastcall handle_ctcp(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4, int a5)
{
if ( a5 <= 0 )
__assert_fail("ncaps >= 1", "ctcp.c", 0x3Fu, "handle_ctcp");
return ctcp_emit(a1, a2, *a4);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4, int a5)
{
if ( a5 <= 0 )
__assert_fail("ncaps >= 1", "ctcp.c", 0x3Fu, "handle_ctcp");
return func10(a1, a2, *a4);
}

original_code:
static void handle_ctcp(char *usr, char *src, char *msg,
  char **caps, int ncaps)
{
 char *message;
 ((void) sizeof ((ncaps >= 1) ? 1 : 0), __extension__ ({ if (ncaps >= 1) ; else __assert_fail ("ncaps >= 1", "ctcp.c", 63, __extension__ __PRETTY_FUNCTION__); }));
 message = caps[0];
 ctcp_emit(usr, src, message);
}

variable_types:
caps
char **

variable_types: ncaps int

variable_types:
message
char *


original_code:
int hashtab_insert(struct hashtab *h, void *key, void *datum)
{
 unsigned hvalue;
 struct hashtab_node *prev, *cur, *newnode;
 hvalue = h->hash_value(h, key);
 prev = ((void *)0);
 cur = h->htable[hvalue];
 while (cur && h->keycmp(h, key, cur->key) > 0) {
  prev = cur;
  cur = cur->next;
 }
 if (cur && (h->keycmp(h, key, cur->key) == 0))
  return -1;
 newnode = malloc(sizeof(*newnode));
 newnode->key = key;
 newnode->datum = datum;
 if (prev) {
  newnode->next = prev->next;
  prev->next = newnode;
 }
 else {
  newnode->next = h->htable[hvalue];
  h->htable[hvalue] = newnode;
 }
 h->nel++;
 return 0;
}

canonical_original_code:
int hashtab_insert(struct hashtab *h, void *key, void *datum)
{
 unsigned int hvalue;
 struct hashtab_node *prev; struct hashtab_node *cur; struct hashtab_node *newnode;
 hvalue = h->hash_value(h, key);
 prev = ((void *)0);
 cur = h->htable[hvalue];
 while (cur && h->keycmp(h, key, cur->key) > 0) {
  prev = cur;
  cur = cur->next;
 }
 if (cur && (h->keycmp(h, key, cur->key) == 0))
  return -1;
 newnode = malloc(sizeof(*newnode));
 newnode->key = key;
 newnode->datum = datum;
 if (prev) {
  newnode->next = prev->next;
  prev->next = newnode;
 }
 else {
  newnode->next = h->htable[hvalue];
  h->htable[hvalue] = newnode;
 }
 h->nel++;
 return 0;
}

variable_types: struct hashtab { struct hashtab_node { void *key; void *datum; struct hashtab_node *next; } **htable; unsigned int size; unsigned int nel; unsigned int (*hash_value)(struct hashtab *h, void *key); int (*keycmp)(struct hashtab *h, void *key1, void *key2); } *

variable_types:
key
void *

variable_types:
datum
void *

variable_types:
hvalue
unsigned int

user_defined_types: struct hashtab { struct hashtab_node **htable; unsigned int size; unsigned int nel; unsigned int (*hash_value)(struct hashtab *h, void *key); int (*keycmp)(struct hashtab *h, void *key1, void *key2); }


original_code:
int hashtab_remove(struct hashtab *h, void *key)
{
 unsigned hvalue;
 struct hashtab_node *prev, *cur;
 hvalue = h->hash_value(h, key);
 prev = ((void *)0);
 cur = h->htable[hvalue];
 while (cur && h->keycmp(h, key, cur->key) > 0) {
  prev = cur;
  cur = cur->next;
 }
 if (!cur || (h->keycmp(h, key, cur->key) != 0))
  return -1;
 if (prev)
  prev->next = cur->next;
 else
  h->htable[hvalue] = ((void *)0);
 free(cur);
 h->nel--;
 return 0;
}

canonical_original_code:
int hashtab_remove(struct hashtab *h, void *key)
{
 unsigned int hvalue;
 struct hashtab_node *prev; struct hashtab_node *cur;
 hvalue = h->hash_value(h, key);
 prev = ((void *)0);
 cur = h->htable[hvalue];
 while (cur && h->keycmp(h, key, cur->key) > 0) {
  prev = cur;
  cur = cur->next;
 }
 if (!cur || (h->keycmp(h, key, cur->key) != 0))
  return -1;
 if (prev)
  prev->next = cur->next;
 else
  h->htable[hvalue] = ((void *)0);
 free(cur);
 h->nel--;
 return 0;
}

variable_types: struct hashtab_node { void *key; void *datum; struct hashtab_node *next; } *


decompiled_code:
__int64 __fastcall hashtab_search(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
__int64 result; // rax

if ( !a1 )
return 0LL;
v2 = *(_QWORD **)(*(_QWORD *)a1 + 8LL * (*(unsigned int (**)(void))(a1 + 16))());
if ( !v2 )
return 0LL;
while ( (*(int (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24))(a1, a2, *v2) > 0 )
{
v2 = (_QWORD *)v2[2];
if ( !v2 )
return 0LL;
}
if ( (*(unsigned int (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24))(a1, a2, *v2) )
result = 0LL;
else
result = v2[1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
__int64 result; // rax

if ( !a1 )
return 0LL;
v2 = *(_QWORD **)(*(_QWORD *)a1 + 8LL * (*(unsigned int (**)(void))(a1 + 16))());
if ( !v2 )
return 0LL;
while ( (*(int (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24))(a1, a2, *v2) > 0 )
{
v2 = (_QWORD *)v2[2];
if ( !v2 )
return 0LL;
}
if ( (*(unsigned int (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24))(a1, a2, *v2) )
result = 0LL;
else
result = v2[1];
return result;
}

original_code:
void *hashtab_search(struct hashtab *h, void *key)
{
 unsigned hvalue;
 struct hashtab_node *cur;
 if (!h)
  return ((void *)0);
 hvalue = h->hash_value(h, key);
 cur = h->htable[hvalue];
 while (cur && h->keycmp(h, key, cur->key) > 0)
  cur = cur->next;
 if (cur == ((void *)0) || (h->keycmp(h, key, cur->key) != 0))
  return ((void *)0);
 return cur->datum;
}

canonical_original_code:
void *hashtab_search(struct hashtab *h, void *key)
{
 unsigned int hvalue;
 struct hashtab_node *cur;
 if (!h)
  return ((void *)0);
 hvalue = h->hash_value(h, key);
 cur = h->htable[hvalue];
 while (cur && h->keycmp(h, key, cur->key) > 0)
  cur = cur->next;
 if (cur == ((void *)0) || (h->keycmp(h, key, cur->key) != 0))
  return ((void *)0);
 return cur->datum;
}

user_defined_types: struct hashtab_node { void *key; void *datum; struct hashtab_node *next; }


decompiled_code:
void __fastcall hashtab_destroy(void *ptr)
{
unsigned int v2; // ebp
_QWORD *v3; // rbx
void *v4; // rdi

if ( ptr )
{
if ( *((_DWORD *)ptr + 2) )
{
v2 = 0;
do
{
v3 = *(_QWORD **)(*(_QWORD *)ptr + 8LL * v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
*(_QWORD *)(*(_QWORD *)ptr + 8LL * v2++) = 0LL;
}
while ( *((_DWORD *)ptr + 2) > v2 );
}
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
unsigned int v2; // ebp
_QWORD *v3; // rbx
void *v4; // rdi

if ( ptr )
{
if ( *((_DWORD *)ptr + 2) )
{
v2 = 0;
do
{
v3 = *(_QWORD **)(*(_QWORD *)ptr + 8LL * v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
*(_QWORD *)(*(_QWORD *)ptr + 8LL * v2++) = 0LL;
}
while ( *((_DWORD *)ptr + 2) > v2 );
}
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void hashtab_destroy(struct hashtab *h)
{
 unsigned i;
 struct hashtab_node *cur, *temp;
 if (!h)
  return;
 for (i = 0; i < h->size; i++) {
  cur = h->htable[i];
  while (cur) {
   temp = cur;
   cur = cur->next;
   free(temp);
  }
  h->htable[i] = ((void *)0);
 }
 free(h->htable);
 h->htable = ((void *)0);
 free(h);
}

canonical_original_code:
void hashtab_destroy(struct hashtab *h)
{
 unsigned int i;
 struct hashtab_node *cur; struct hashtab_node *temp;
 if (!h)
  return;
 for (i = 0; i < h->size; i++) {
  cur = h->htable[i];
  while (cur) {
   temp = cur;
   cur = cur->next;
   free(temp);
  }
  h->htable[i] = ((void *)0);
 }
 free(h->htable);
 h->htable = ((void *)0);
 free(h);
}

variable_types:
i
unsigned int


original_code:
unsigned str_hash(struct hashtab *h, void *data)
{
 char *str = data;
 unsigned i = 2166136261;
 for (i; *str; str++) {
  i ^= *str;
  i *= 16777619;
 }
 return i % h->size;
}

canonical_original_code:
unsigned int str_hash(struct hashtab *h, void *data)
{
 char *str = data;
 unsigned int i = 2166136261;
 for (i; *str; str++) {
  i ^= *str;
  i *= 16777619;
 }
 return i % h->size;
}

variable_types:
data
void *

variable_types:
str
char *

return_type: unsigned int


decompiled_code:
int __fastcall strcmp_hash(__int64 a1, const char *a2, const char *a3)
{
return strcmp(a2, a3);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, const char *a2, const char *a3)
{
return strcmp(a2, a3);
}

original_code:
int strcmp_hash(struct hashtab *h, void *a, void *b)
{
 return strcmp(a, b);
}

variable_types:
a
void *

variable_types:
b
void *


make

decompiled_code:
__int64 make()
{
__pid_t v0; // eax
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

if ( !(unsigned __int8)auth_isowner() )
return ircproto_privmsg();
v0 = fork();
if ( v0 == -1 )
return ircproto_privmsg_errno();
if ( !v0 )
{
execlp("make", "make", 0LL);
ircproto_privmsg_errno();
exit(1);
}
waitpid(v0, &stat_loc, 0);
if ( !(stat_loc & 0x7F | BYTE1(stat_loc)) )
{
close_connection();
execvp(*(const char **)argv, argv);
err_errno();
exit(1);
}
return ircproto_privmsg();
}

canonical_decompiled_code:
__int64 func6()
{
__pid_t v0; // eax
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

if ( !(unsigned __int8)auth_isowner() )
return ircproto_privmsg();
v0 = fork();
if ( v0 == -1 )
return ircproto_privmsg_errno();
if ( !v0 )
{
execlp("make", "make", 0LL);
ircproto_privmsg_errno();
exit(1);
}
waitpid(v0, &stat_loc, 0);
if ( !(stat_loc & 0x7F | BYTE1(stat_loc)) )
{
close_connection();
execvp(*(const char **)argv, argv);
err_errno();
exit(1);
}
return ircproto_privmsg();
}

original_code:
static void make(char *usr, char *src, char *msg)
{
 pid_t pid;
 int status;
 if (!auth_isowner(usr)) {
  ircproto_privmsg(src, "err: not owner");
  return;
 }
 pid = fork();
 if (pid == -1) {
  ircproto_privmsg_errno(src, "fork");
 }
 else if (pid == 0) {
  execlp("make", "make", (char *)((void *)0));
  ircproto_privmsg_errno(src, "exec(make)");
  exit(1);
 }
 else {
  waitpid(pid, &status, 0);
  if ((((status) & 0x7f) == 0) && (((status) & 0xff00) >> 8) == 0) {
   close_connection();
   execvp(argv[0], argv);
   err_errno("exec(myself)");
   exit(1);
  }
  else {
   ircproto_privmsg(src, "err: build failed");
  }
 }
}

canonical_original_code:
static void make(char *usr, char *src, char *msg)
{
 int pid;
 int status;
 if (!auth_isowner(usr)) {
  ircproto_privmsg(src, "err: not owner");
  return;
 }
 pid = fork();
 if (pid == -1) {
  ircproto_privmsg_errno(src, "fork");
 }
 else if (pid == 0) {
  execlp("make", "make", (char *)((void *)0));
  ircproto_privmsg_errno(src, "exec(make)");
  exit(1);
 }
 else {
  waitpid(pid, &status, 0);
  if ((((status) & 0x7f) == 0) && (((status) & 0xff00) >> 8) == 0) {
   close_connection();
   execvp(argv[0], argv);
   err_errno("exec(myself)");
   exit(1);
  }
  else {
   ircproto_privmsg(src, "err: build failed");
  }
 }
}

variable_types:
usr
char *

variable_types:
src
char *

variable_types:
msg
char *

variable_types: pid int

variable_types: status int


init

decompiled_code:
__int64 init()
{
callback_register_privmsg_str();
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
callback_register_privmsg_str();
return 0LL;
}

original_code:
int init()
{
 callback_register_privmsg_str(make, "make");
 return 0;
}


finish

decompiled_code:
void finish()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void finish()
{
}

canonical_original_code:
void finish()
{
}


decompiled_code:
__int64 free_str_events()
{
return hashtab_destroy(str_events);
}

canonical_decompiled_code:
__int64 func2()
{
return hashtab_destroy(str_events);
}

original_code:
static void free_str_events()
{
 hashtab_destroy(str_events);
}


decompiled_code:
__int64 __fastcall callback_emit_privmsg(__int64 a1, __int64 a2, __int64 a3)
{
__int64 *v4; // rax
__int64 **v5; // rdx
__int64 result; // rax
void **v7; // rbx

if ( need_init_2 )
{
need_init_2 = 0;
v4 = (__int64 *)&caps_buf_1;
v5 = (__int64 **)&caps_0;
do
{
*v5 = v4;
v4 += 64;
++v5;
}
while ( v4 != &str_events );
}
result = hashtab_search(str_events, a3);
if ( result )
result = ((__int64 (__fastcall *)(__int64, __int64, __int64))result)(a1, a2, a3);
v7 = (void **)re_events;
if ( re_events != &re_events )
{
do
{
result = (unsigned int)regex_match(v7 + 3, a3, &caps_0) - 1;
if ( (int)result >= 0 )
result = ((__int64 (__fastcall *)(__int64, __int64, __int64, void *, _QWORD))v7[2])(
a1,
a2,
a3,
&caps_0,
(unsigned int)result);
v7 = (void **)*v7;
}
while ( v7 != &re_events );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
__int64 *v4; // rax
__int64 **v5; // rdx
__int64 result; // rax
void **v7; // rbx

if ( need_init_2 )
{
need_init_2 = 0;
v4 = (__int64 *)&caps_buf_1;
v5 = (__int64 **)&caps_0;
do
{
*v5 = v4;
v4 += 64;
++v5;
}
while ( v4 != &str_events );
}
result = hashtab_search(str_events, a3);
if ( result )
result = ((__int64 (__fastcall *)(__int64, __int64, __int64))result)(a1, a2, a3);
v7 = (void **)re_events;
if ( re_events != &re_events )
{
do
{
result = (unsigned int)regex_match(v7 + 3, a3, &caps_0) - 1;
if ( (int)result >= 0 )
result = ((__int64 (__fastcall *)(__int64, __int64, __int64, void *, _QWORD))v7[2])(
a1,
a2,
a3,
&caps_0,
(unsigned int)result);
v7 = (void **)*v7;
}
while ( v7 != &re_events );
}
return result;
}

original_code:
void callback_emit_privmsg(char *usr, char *src, char *msg)
{
 callback_privmsg_str call;
 struct list_head *node;
 struct re_event *rev;
 int matches, ncap, i;
 static char *caps[10];
 static char caps_buf[512 * 10];
 static _Bool need_init = 1;
 if (need_init) {
  need_init = 0;
  for (i = 0; i < 10; i++)
   caps[i] = &caps_buf[512 * i];
 }
 call = hashtab_search(str_events, msg);
 if (call)
  call(usr, src, msg);
 for (node = (&re_events)->next; node != (&re_events); node = node->next) {
  rev = ((struct re_event *)((char *)(node)-(unsigned long)(&((struct re_event *)0)->link)));
  matches = regex_match(&rev->match, msg, caps);
  ncap = matches - 1;
  if (ncap >= 0)
   rev->call(usr, src, msg, caps, ncap);
 }
}

canonical_original_code:
void callback_emit_privmsg(char *usr, char *src, char *msg)
{
 void (*call)(char *usr, char *src, char *msg);
 struct list_head *node;
 struct re_event *rev;
 int matches; int ncap; int i;
 static char *caps[10];
 static char caps_buf[-1];
 static _Bool need_init = 1;
 if (need_init) {
  need_init = 0;
  for (i = 0; i < 10; i++)
   caps[i] = &caps_buf[512 * i];
 }
 call = hashtab_search(str_events, msg);
 if (call)
  call(usr, src, msg);
 for (node = (&re_events)->next; node != (&re_events); node = node->next) {
  rev = ((struct re_event *)((char *)(node)-(unsigned long)(&((struct re_event *)0)->link)));
  matches = regex_match(&rev->match, msg, caps);
  ncap = matches - 1;
  if (ncap >= 0)
   rev->call(usr, src, msg, caps, ncap);
 }
}

variable_types: void (*)(char *usr, char *src, char *msg)

variable_types: struct list_head { struct list_head *next; } *

variable_types: struct re_event { struct list_head { struct list_head *next; } link; void (*call)(char *usr, char *src, char *msg, char **caps, int ncap); struct regex { char *pattern; enum regex_compiled_state { RCS_UNINIT=0, RCS_ERROR=1, RCS_COMPILED=2 } state; void *re_detail; } match; } *

variable_types: matches int

variable_types: ncap int

variable_types: i int

variable_types:
caps
char *[10]


decompiled_code:
void __fastcall handle_privmsg(char *s, __int64 a2, const char *a3)
{
char *v3; // rbp
char *v4; // rax
__int64 v5; // rbx
const char *v6; // r13
size_t v7; // rax
char *v8; // rbp

v3 = (char *)a3;
v4 = strchr(a3, 32);
*v4 = 0;
v5 = (__int64)(v4 + 2);
v6 = bot_nick;
v7 = strlen(bot_nick);
if ( !strncasecmp(v3, v6, v7) )
{
if ( strchr(s, 33) )
{
v8 = strdup(s);
*strchr(v8, 33) = 0;
callback_emit_privmsg((__int64)s, (__int64)v8, v5);
free(v8);
return;
}
v3 = s;
}
callback_emit_privmsg((__int64)s, (__int64)v3, v5);
}

canonical_decompiled_code:
void __fastcall func4(char *s, __int64 a2, const char *a3)
{
char *v3; // rbp
char *v4; // rax
__int64 v5; // rbx
const char *v6; // r13
size_t v7; // rax
char *v8; // rbp

v3 = (char *)a3;
v4 = strchr(a3, 32);
*v4 = 0;
v5 = (__int64)(v4 + 2);
v6 = bot_nick;
v7 = strlen(bot_nick);
if ( !strncasecmp(v3, v6, v7) )
{
if ( strchr(s, 33) )
{
v8 = strdup(s);
*strchr(v8, 33) = 0;
func3((__int64)s, (__int64)v8, v5);
free(v8);
return;
}
v3 = s;
}
func3((__int64)s, (__int64)v3, v5);
}

original_code:
static void handle_privmsg(char *usr, char *cmd, char *src_and_msg)
{
 char *src, *msg, *spc;
 _Bool src_on_heap = 0;
 spc = strchr(src_and_msg, ' ');
 *spc = '\0';
 src = src_and_msg;
 msg = spc + 2;
 if (!strncasecmp(src, bot_nick, strlen(bot_nick))) {
  if (strchr(usr, '!')) {
   src = strdup(usr);
   *strchr(src, '!') = '\0';
   src_on_heap = 1;
  }
  else {
   src = usr;
  }
 }
 callback_emit_privmsg(usr, src, msg);
 if (src_on_heap)
  free(src);
}

canonical_original_code:
static void handle_privmsg(char *usr, char *cmd, char *src_and_msg)
{
 char *src; char *msg; char *spc;
 _Bool src_on_heap = 0;
 spc = strchr(src_and_msg, ' ');
 *spc = '\0';
 src = src_and_msg;
 msg = spc + 2;
 if (!strncasecmp(src, bot_nick, strlen(bot_nick))) {
  if (strchr(usr, '!')) {
   src = strdup(usr);
   *strchr(src, '!') = '\0';
   src_on_heap = 1;
  }
  else {
   src = usr;
  }
 }
 callback_emit_privmsg(usr, src, msg);
 if (src_on_heap)
  free(src);
}

variable_types:
cmd
char *

variable_types:
spc
char *


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

result = hashtab_insert(str_events, a2, a1);
if ( (_DWORD)result == -1 )
err((int)"str event '%s' already exists", a2);
return result;
}

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

result = hashtab_insert(str_events, a2, a1);
if ( (_DWORD)result == -1 )
err((int)"str event '%s' already exists", a2);
return result;
}

original_code:
void callback_register_privmsg_str(callback_privmsg_str call, char *str)
{
 if (hashtab_insert(str_events, str, call) == -1)
  err("str event '%s' already exists", str);
}

canonical_original_code:
void callback_register_privmsg_str(void (*call)(char *usr, char *src, char *msg), char *str)
{
 if (hashtab_insert(str_events, str, call) == -1)
  err("str event '%s' already exists", str);
}

variable_types:
str
char *


decompiled_code:
__int64 privmsg_init()
{
str_events = hashtab_create(&str_hash, &strcmp_hash, 31LL);
callback_register_str(handle_privmsg, "PRIVMSG");
return add_shutdown_fn(free_str_events);
}

canonical_decompiled_code:
__int64 func7()
{
str_events = hashtab_create(&str_hash, &strcmp_hash, 31LL);
callback_register_str(handle_privmsg, "PRIVMSG");
return add_shutdown_fn(free_str_events);
}

original_code:
void privmsg_init()
{
 str_events = hashtab_create(str_hash, strcmp_hash,
  31);
 callback_register_str(handle_privmsg, "PRIVMSG");
 add_shutdown_fn(free_str_events);
}


decompiled_code:
_BOOL8 __fastcall list_empty(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

original_code:
static int list_empty(struct list_head *head)
{
 return head->next == head;
}


decompiled_code:
__int64 __fastcall presence_del(void *ptr)
{
__int64 v1; // rbp
__int64 result; // rax

v1 = *((_QWORD *)ptr + 5);
list_del((__int64)ptr);
list_del((__int64)ptr + 16);
free(ptr);
result = list_empty((_QWORD *)(v1 + 2048));
if ( (_DWORD)result )
result = user_del(v1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *ptr)
{
__int64 v1; // rbp
__int64 result; // rax

v1 = *((_QWORD *)ptr + 5);
func3((__int64)ptr);
func3((__int64)ptr + 16);
free(ptr);
result = func4((_QWORD *)(v1 + 2048));
if ( (_DWORD)result )
result = user_del(v1);
return result;
}

original_code:
void presence_del(struct presence *pres)
{
 struct user *user = pres->user;
 list_del(&pres->clink);
 list_del(&pres->ulink);
 free(pres);
 if (list_empty(&user->presences))
  user_del(user);
}

variable_types: struct presence { struct list_head { struct list_head *next; } clink; struct chan { struct list_head link; struct list_head presences; char name[512]; } *chan; struct user { char nick[512]; char host[512]; char uname[512]; char rname[512]; struct list_head presences; _Bool reg; } *user; enum priv { PRIV_NONE=0, PRIV_OPERATOR=10, PRIV_HIGHEST=20 } priv; } *

variable_types: struct user { char nick[512]; char host[512]; char uname[512]; char rname[512]; struct list_head { struct list_head *next; } presences; _Bool reg; } *


info

decompiled_code:
int info(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
txtattr(stdout, 1u);
printf("? ");
vprintf(format, arg);
putchar(10);
return txtattr(stdout, 0);
}

canonical_decompiled_code:
int func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
func0(stdout, 1u);
printf("? ");
vprintf(format, arg);
putchar(10);
return func0(stdout, 0);
}

original_code:
void info(char* format, ...)
{
 va_list args;
 txtattr(stdout, BOLD);
 printf("? ");
 __builtin_va_start(args,format);
 vprintf(format, args);
 __builtin_va_end(args);
 putchar('\n');
 txtattr(stdout, CLEAR);
}

canonical_original_code:
void info(char *format, ...)
{
 __builtin_va_list args;
 txtattr(stdout, BOLD);
 printf("? ");
 __builtin_va_start(args,format);
 vprintf(format, args);
 __builtin_va_end(args);
 putchar('\n');
 txtattr(stdout, CLEAR);
}

variable_types:
format
char *


err

decompiled_code:
void __noreturn err(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
txtattr(stderr, 7u);
fwrite("! ", 1uLL, 2uLL, stderr);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
txtattr(stderr, 0);
}

canonical_decompiled_code:
void __noreturn func2(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
func0(stderr, 7u);
fwrite("! ", 1uLL, 2uLL, stderr);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
func0(stderr, 0);
}

original_code:
void err(char* format, ...)
{
 va_list args;
 txtattr(stderr, REVERSE_VIDEO);
 fprintf(stderr, "! ");
 __builtin_va_start(args,format);
 vfprintf(stderr, format, args);
 __builtin_va_end(args);
 fputc('\n', stderr);
 txtattr(stderr, CLEAR);
}

canonical_original_code:
void err(char *format, ...)
{
 __builtin_va_list args;
 txtattr(stderr, REVERSE_VIDEO);
 fprintf(stderr, "! ");
 __builtin_va_start(args,format);
 vfprintf(stderr, format, args);
 __builtin_va_end(args);
 fputc('\n', stderr);
 txtattr(stderr, CLEAR);
}


decompiled_code:
int err_errno(char *format, ...)
{
int v1; // ebp
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
v1 = *_errno_location();
txtattr(stderr, 7u);
fwrite("! ", 1uLL, 2uLL, stderr);
vfprintf(stderr, format, arg);
v2 = strerror(v1);
fprintf(stderr, ": %s", v2);
fputc(10, stderr);
return txtattr(stderr, 0);
}

canonical_decompiled_code:
int func3(char *format, ...)
{
int v1; // ebp
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
v1 = *_errno_location();
func0(stderr, 7u);
fwrite("! ", 1uLL, 2uLL, stderr);
vfprintf(stderr, format, arg);
v2 = strerror(v1);
fprintf(stderr, ": %s", v2);
fputc(10, stderr);
return func0(stderr, 0);
}

original_code:
void err_errno(char* format, ...)
{
 va_list args;
 int err = (*__errno_location ());
 txtattr(stderr, REVERSE_VIDEO);
 fprintf(stderr, "! ");
 __builtin_va_start(args,format);
 vfprintf(stderr, format, args);
 __builtin_va_end(args);
 fprintf(stderr, ": %s", strerror(err));
 fputc('\n', stderr);
 txtattr(stderr, CLEAR);
}

canonical_original_code:
void err_errno(char *format, ...)
{
 __builtin_va_list args;
 int err = (*__errno_location ());
 txtattr(stderr, REVERSE_VIDEO);
 fprintf(stderr, "! ");
 __builtin_va_start(args,format);
 vfprintf(stderr, format, args);
 __builtin_va_end(args);
 fprintf(stderr, ": %s", strerror(err));
 fputc('\n', stderr);
 txtattr(stderr, CLEAR);
}

variable_types: err int


decompiled_code:
void safe_shutdown()
{
void (*v0)(void); // rbx
void (*v1)(void); // rdi

v0 = (void (*)(void))stack_head;
if ( stack_head != &stack_tail )
{
do
{
(*((void (**)(void))v0 + 1))();
v1 = v0;
v0 = *(void (**)(void))v0;
free(v1);
}
while ( (char *)v0 != (char *)&stack_tail );
}
}

canonical_decompiled_code:
void func4()
{
void (*v0)(void); // rbx
void (*v1)(void); // rdi

v0 = (void (*)(void))stack_head;
if ( stack_head != &stack_tail )
{
do
{
(*((void (**)(void))v0 + 1))();
v1 = v0;
v0 = *(void (**)(void))v0;
free(v1);
}
while ( (char *)v0 != (char *)&stack_tail );
}
}

original_code:
void safe_shutdown()
{
 struct fn_stack *prev, *st = stack_head;
 while (st != &stack_tail) {
  st->fn();
  prev = st;
  st = st->next;
  free(prev);
 }
}

canonical_original_code:
void safe_shutdown()
{
 struct fn_stack *prev; struct fn_stack *st = stack_head;
 while (st != &stack_tail) {
  st->fn();
  prev = st;
  st = st->next;
  free(prev);
 }
}

variable_types: struct fn_stack { struct fn_stack *next; void (*fn)(); } *


decompiled_code:
void __fastcall __noreturn safe_shutdown_and_die(int status)
{
safe_shutdown();
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(int status)
{
func4();
exit(status);
}

original_code:
void safe_shutdown_and_die(int code)
{
 safe_shutdown();
 exit(code);
}

variable_types: code int


decompiled_code:
int mutex_on()
{
int result; // eax

if ( nthreads > 1 )
result = pthread_mutex_lock(&mut);
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

if ( nthreads > 1 )
result = pthread_mutex_lock(&mut);
return result;
}

original_code:
void mutex_on()
{
 if (nthreads > 1)
  pthread_mutex_lock(&mut);
}


decompiled_code:
int mutex_off()
{
int result; // eax

if ( nthreads > 1 )
result = pthread_mutex_unlock(&mut);
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax

if ( nthreads > 1 )
result = pthread_mutex_unlock(&mut);
return result;
}

original_code:
void mutex_off()
{
 if (nthreads > 1)
  pthread_mutex_unlock(&mut);
}


ping

decompiled_code:
__int64 ping()
{
return ircproto_notice();
}

canonical_decompiled_code:
__int64 func6()
{
return ircproto_notice();
}

original_code:
static void ping(char *usr, char *src, char *msg,
  char **caps, int ncaps)
{
 ircproto_notice(src, "\001PING %s\001", caps[0]);
}

variable_types:
usr
char *

variable_types:
src
char *

variable_types:
msg
char *

variable_types:
caps
char **

variable_types: ncaps int


init

decompiled_code:
__int64 init()
{
ctcp_register();
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
ctcp_register();
return 0LL;
}

original_code:
int init()
{
 ctcp_register(ping, "^PING ?(.*)");
 return 0;
}


finish

decompiled_code:
void finish()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void finish()
{
}


decompiled_code:
__int64 handle_nicknameinuse()
{
char *v0; // r12
size_t v1; // rbx

v0 = (char *)bot_nick;
v1 = strlen(bot_nick);
bot_nick = (const char *)realloc(v0, v1 + 2);
bot_nick[v1] = 95;
bot_nick[v1 + 1] = 0;
return ircproto_nick();
}

canonical_decompiled_code:
__int64 func6()
{
char *v0; // r12
size_t v1; // rbx

v0 = (char *)bot_nick;
v1 = strlen(bot_nick);
bot_nick = (const char *)realloc(v0, v1 + 2);
bot_nick[v1] = 95;
bot_nick[v1 + 1] = 0;
return ircproto_nick();
}

original_code:
static void handle_nicknameinuse(char *prefix, int ncmd, char *params)
{
 size_t len = strlen(bot_nick);
 bot_nick = realloc(bot_nick, len + 2);
 bot_nick[len++] = '_';
 bot_nick[len] = '\0';
 ircproto_nick(bot_nick);
}

canonical_original_code:
static void handle_nicknameinuse(char *prefix, int ncmd, char *params)
{
 unsigned long len = strlen(bot_nick);
 bot_nick = realloc(bot_nick, len + 2);
 bot_nick[len++] = '_';
 bot_nick[len] = '\0';
 ircproto_nick(bot_nick);
}

variable_types:
prefix
char *

variable_types: ncmd int

variable_types:
params
char *

variable_types:
len
unsigned long


init

decompiled_code:
__int64 init()
{
callback_register_numeric();
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
callback_register_numeric();
return 0LL;
}

original_code:
int init()
{
 callback_register_numeric(handle_nicknameinuse, 433);
 return 0;
}


version

decompiled_code:
__int64 version()
{
pref_get();
return ircproto_notice();
}

canonical_decompiled_code:
__int64 func6()
{
pref_get();
return ircproto_notice();
}

original_code:
static void version(char *usr, char *src, char *msg,
  char **caps, int ncaps)
{
 char *version = pref_get("version");
 if (version != ((void *)0))
  ircproto_notice(src, "\001VERSION %s\001", version);
 else
  ircproto_notice(src, "\001VERSION yak %s\001", "0.2.6");
}

variable_types:
version
char *


init

original_code:
int init()
{
 ctcp_register(version, "^VERSION$");
 return 0;
}


decompiled_code:
void *handle_yourebanned()
{
void *result; // rax

info();
result = &want_quit;
want_quit = 1;
return result;
}

canonical_decompiled_code:
void *func6()
{
void *result; // rax

info();
result = &want_quit;
want_quit = 1;
return result;
}

original_code:
static void handle_yourebanned(char *prefix, int ncmd, char *params)
{
 info("banned from the server");
 want_quit = 1;
}


original_code:
int init()
{
 callback_register_numeric(handle_yourebanned, 465);
 return 0;
}


decompiled_code:
__int64 __fastcall load_lib(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
if ( !(unsigned __int8)auth_isowner() || a5 != 1 )
return ircproto_privmsg();
ircproto_privmsg();
return plg_load();
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
if ( !(unsigned __int8)auth_isowner() || a5 != 1 )
return ircproto_privmsg();
ircproto_privmsg();
return plg_load();
}

original_code:
static void load_lib(char *usr, char *src, char *msg,
  char **caps, int ncaps)
{
 char *lib;
 if (!auth_isowner(usr)) {
  ircproto_privmsg(src, "err: not owner");
  return;
 }
 if (ncaps != 1) {
  ircproto_privmsg(src, "usage: load_lib <lib>");
  return;
 }
 lib = caps[0];
 ircproto_privmsg(src, "loading: %s", lib);
 plg_load(lib);
}

variable_types:
lib
char *


decompiled_code:
__int64 init()
{
callback_register_privmsg_re();
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
callback_register_privmsg_re();
return 0LL;
}

original_code:
int init()
{
 callback_register_privmsg_re(load_lib,
  "^load_lib ?(\\w+)?(.+)?$");
 return 0;
}


decompiled_code:
char __fastcall isupport_set(const char *a1, const char *a2)
{
bool v2; // zf
char result; // al

if ( !strcmp(a1, "CHANTYPES") )
return chan_set_prefix();
v2 = strcmp(a1, "PREFIX") == 0;
result = !v2;
if ( v2 )
{
if ( a2 )
*strchr(a2, 41) = 0;
result = auth_set_prefix();
}
return result;
}

canonical_decompiled_code:
char __fastcall func6(const char *a1, const char *a2)
{
bool v2; // zf
char result; // al

if ( !strcmp(a1, "CHANTYPES") )
return chan_set_prefix();
v2 = strcmp(a1, "PREFIX") == 0;
result = !v2;
if ( v2 )
{
if ( a2 )
*strchr(a2, 41) = 0;
result = auth_set_prefix();
}
return result;
}

original_code:
void isupport_set(char *param, char *value)
{
 char *modes, *prefixes, *paren;
 if (!strcmp(param, "CHANTYPES")) {
  chan_set_prefix(value);
 }
 else if (!strcmp(param, "PREFIX")) {
  if (value) {
   paren = strchr(value, ')');
   *paren = '\0';
   modes = value + 1;
   prefixes = paren + 1;
   auth_set_prefix(modes, prefixes);
  }
  else {
   auth_set_prefix("", "");
  }
 }
}

canonical_original_code:
void isupport_set(char *param, char *value)
{
 char *modes; char *prefixes; char *paren;
 if (!strcmp(param, "CHANTYPES")) {
  chan_set_prefix(value);
 }
 else if (!strcmp(param, "PREFIX")) {
  if (value) {
   paren = strchr(value, ')');
   *paren = '\0';
   modes = value + 1;
   prefixes = paren + 1;
   auth_set_prefix(modes, prefixes);
  }
  else {
   auth_set_prefix("", "");
  }
 }
}

variable_types:
param
char *

variable_types:
value
char *

variable_types:
modes
char *

variable_types:
prefixes
char *

variable_types:
paren
char *


decompiled_code:
char __fastcall isupport_unset(const char *a1)
{
bool v1; // zf
char result; // al

if ( !strcmp(a1, "CHANTYPES") )
return chan_set_prefix();
v1 = strcmp(a1, "PREFIX") == 0;
result = !v1;
if ( v1 )
result = auth_set_prefix();
return result;
}

canonical_decompiled_code:
char __fastcall func7(const char *a1)
{
bool v1; // zf
char result; // al

if ( !strcmp(a1, "CHANTYPES") )
return chan_set_prefix();
v1 = strcmp(a1, "PREFIX") == 0;
result = !v1;
if ( v1 )
result = auth_set_prefix();
return result;
}

original_code:
void isupport_unset(char *param)
{
 if (!strcmp(param, "CHANTYPES"))
  chan_set_prefix("#&");
 else if (!strcmp(param, "PREFIX"))
  auth_set_prefix("ov", "@+");
}


decompiled_code:
__int64 __fastcall isupport_token(const char *a1)
{
char v1; // bp
char *v2; // rax
__int64 result; // rax

v1 = *a1;
v2 = strchr(a1, 61);
if ( v2 )
*v2 = 0;
if ( v1 == 45 )
result = isupport_unset(a1);
else
result = isupport_set();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
char v1; // bp
char *v2; // rax
__int64 result; // rax

v1 = *a1;
v2 = strchr(a1, 61);
if ( v2 )
*v2 = 0;
if ( v1 == 45 )
result = func7(a1);
else
result = func6();
return result;
}

original_code:
void isupport_token(char *tok)
{
 char *param = tok, *value = ((void *)0), *equals;
 _Bool set;
 set = tok[0] != '-';
 if (tok[0] == '-')
  tok++;
 equals = strchr(param, '=');
 if (equals) {
  *equals = '\0';
  value = equals + 1;
 }
 if (value && *value == '\0')
  value = ((void *)0);
 if (set)
  isupport_set(param, value);
 else
  isupport_unset(param);
}

canonical_original_code:
void isupport_token(char *tok)
{
 char *param = tok; char *value = ((void *)0); char *equals;
 _Bool set;
 set = tok[0] != '-';
 if (tok[0] == '-')
  tok++;
 equals = strchr(param, '=');
 if (equals) {
  *equals = '\0';
  value = equals + 1;
 }
 if (value && *value == '\0')
  value = ((void *)0);
 if (set)
  isupport_set(param, value);
 else
  isupport_unset(param);
}

variable_types:
tok
char *

variable_types:
equals
char *


decompiled_code:
char *__fastcall handle_isupport(__int64 a1, __int64 a2, char *a3)
{
char *result; // rax
char *save_ptr[2]; // [rsp+8h] [rbp-10h] BYREF

strtok_r(a3, " ", save_ptr);
while ( 1 )
{
result = strtok_r(0LL, " ", save_ptr);
if ( !result || *result == 58 )
break;
isupport_token();
}
return result;
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1, __int64 a2, char *a3)
{
char *result; // rax
char *save_ptr[2]; // [rsp+8h] [rbp-10h] BYREF

strtok_r(a3, " ", save_ptr);
while ( 1 )
{
result = strtok_r(0LL, " ", save_ptr);
if ( !result || *result == 58 )
break;
func8();
}
return result;
}

original_code:
void handle_isupport(char *prefix, int ncmd, char *params)
{
 char *tok, *save;
 tok = strtok_r(params, " ", &save);
 while ((tok = strtok_r(((void *)0), " ", &save)) && tok[0] != ':')
  isupport_token(tok);
}

canonical_original_code:
void handle_isupport(char *prefix, int ncmd, char *params)
{
 char *tok; char *save;
 tok = strtok_r(params, " ", &save);
 while ((tok = strtok_r(((void *)0), " ", &save)) && tok[0] != ':')
  isupport_token(tok);
}

variable_types:
save
char *


canonical_decompiled_code:
__int64 func10()
{
callback_register_numeric();
return 0LL;
}

original_code:
int init()
{
 callback_register_numeric(handle_isupport, 5);
 return 0;
}


finish

canonical_decompiled_code:
void func11()
{
;
}


login

decompiled_code:
void login()
{
void (**v0)(void); // rbx
void (*v1)(void); // rbp

loggedin = 1;
v0 = (void (**)(void))calls;
v1 = *(void (**)(void))calls;
if ( calls != &calls )
{
do
{
v0[2]();
list_del((__int64)v0);
free(v0);
v0 = (void (**)(void))v1;
v1 = *(void (**)(void))v1;
}
while ( v0 != (void (**)(void))&calls );
}
}

canonical_decompiled_code:
void func10()
{
void (**v0)(void); // rbx
void (*v1)(void); // rbp

loggedin = 1;
v0 = (void (**)(void))calls;
v1 = *(void (**)(void))calls;
if ( calls != &calls )
{
do
{
v0[2]();
func9((__int64)v0);
free(v0);
v0 = (void (**)(void))v1;
v1 = *(void (**)(void))v1;
}
while ( v0 != (void (**)(void))&calls );
}
}

original_code:
static void login(char *prefix, int ncmd, char *params)
{
 struct list_head *node, *next;
 struct callnode *call;
 loggedin = 1;
 for (node = (&calls)->next, next = node->next; node != (&calls); node = next, next = node->next) {
  call = ((struct callnode *)((char *)(node)-(unsigned long)(&((struct callnode *)0)->link)));
  call->call();
  list_del(node);
  free(call);
 }
}

canonical_original_code:
static void login(char *prefix, int ncmd, char *params)
{
 struct list_head *node; struct list_head *next;
 struct callnode *call;
 loggedin = 1;
 for (node = (&calls)->next, next = node->next; node != (&calls); node = next, next = node->next) {
  call = ((struct callnode *)((char *)(node)-(unsigned long)(&((struct callnode *)0)->link)));
  call->call();
  list_del(node);
  free(call);
 }
}

variable_types: struct list_head { struct list_head *next; } *

variable_types: struct callnode { struct list_head { struct list_head *next; } link; void (*call)(); } *

user_defined_types: struct callnode { struct list_head link; void (*call)(); }


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

result = malloc(0x10uLL);
*result = result;
result[1] = result;
return result;
}

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

result = malloc(0x10uLL);
*result = result;
result[1] = result;
return result;
}

original_code:
struct evalctx *eval_create()
{
 struct evalctx *ctx;
 ctx = malloc(sizeof(struct evalctx));
 do { (&ctx->events)->next = (&ctx->events); (&ctx->events)->prev = (&ctx->events); } while (0);
 return ctx;
}

variable_types: struct evalctx { struct list_head { struct list_head *next; } events; } *

user_defined_types: struct evalctx { struct list_head events; }


decompiled_code:
void __fastcall eval_destroy(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

v1 = *(_QWORD **)ptr;
v2 = **(_QWORD ***)ptr;
if ( *(void **)ptr != ptr )
{
do
{
list_del((__int64)v1);
free(v1);
v1 = v2;
v2 = (_QWORD *)*v2;
}
while ( ptr != v1 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

v1 = *(_QWORD **)ptr;
v2 = **(_QWORD ***)ptr;
if ( *(void **)ptr != ptr )
{
do
{
func9((__int64)v1);
free(v1);
v1 = v2;
v2 = (_QWORD *)*v2;
}
while ( ptr != v1 );
}
free(ptr);
}

original_code:
void eval_destroy(struct evalctx *ctx)
{
 struct list_head *node, *next;
 struct re_event *e;
 for (node = (&ctx->events)->next, next = node->next; node != (&ctx->events); node = next, next = node->next) {
  e = ((struct re_event *)((char *)(node)-(unsigned long)(&((struct re_event *)0)->link)));
  list_del(node);
  free(e);
 }
 free(ctx);
}

canonical_original_code:
void eval_destroy(struct evalctx *ctx)
{
 struct list_head *node; struct list_head *next;
 struct re_event *e;
 for (node = (&ctx->events)->next, next = node->next; node != (&ctx->events); node = next, next = node->next) {
  e = ((struct re_event *)((char *)(node)-(unsigned long)(&((struct re_event *)0)->link)));
  list_del(node);
  free(e);
 }
 free(ctx);
}

variable_types: struct re_event { struct list_head { struct list_head *next; } link; void (*call)(char *line, char **caps, int ncap); struct regex { char *pattern; enum regex_compiled_state { RCS_UNINIT=0, RCS_ERROR=1, RCS_COMPILED=2 } state; void *re_detail; } match; } *

user_defined_types: struct re_event { struct list_head link; void (*call)(char *line, char **caps, int ncap); struct regex match; }