decompiled_code:
__int64 __fastcall jtableP_check(_QWORD *a1, __int64 a2)
{
return Judy1Test(*a1, a2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, __int64 a2)
{
return Judy1Test(*a1, a2, 0LL);
}

original_code:
int jtableP_check(jtableP *table, void *key) {
 int ret;
 (ret) = Judy1Test((Pvoid_t)(table->t), (Word_t)key, ((PJError_t) ((void *)0)));
 return ret;
}

canonical_original_code:
int jtableP_check(struct jtableP *table, void *key) {
 int ret;
 (ret) = Judy1Test((Pvoid_t)(table->t), (unsigned long)key, ((PJError_t) ((void *)0)));
 return ret;
}


repo: thommey/plservices

decompiled_code:
__int64 __fastcall jtableP_unset(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3[10]; // [rsp+10h] [rbp-38h] BYREF
unsigned __int64 v4; // [rsp+38h] [rbp-10h]

v4 = __readfsqword(0x28u);
result = Judy1Unset(a1, a2, v3);
if ( (_DWORD)result == -1 )
{
fprintf(
stderr,
"File '%s', line %d: %s(), JU_ERRNO_* == %d, ID == %d\n",
"src/jtable.c",
150LL,
"Judy1Unset",
(unsigned int)v3[0],
(unsigned int)v3[1]);
exit(1);
}
if ( !(_DWORD)result )
{
logtxt(0x4000LL, "Deletion of non-existant element in jtableP\n");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3[10]; // [rsp+10h] [rbp-38h] BYREF
unsigned __int64 v4; // [rsp+38h] [rbp-10h]

v4 = __readfsqword(0x28u);
result = Judy1Unset(a1, a2, v3);
if ( (_DWORD)result == -1 )
{
fprintf(
stderr,
"File '%s', line %d: %s(), JU_ERRNO_* == %d, ID == %d\n",
"src/jtable.c",
150LL,
"Judy1Unset",
(unsigned int)v3[0],
(unsigned int)v3[1]);
exit(1);
}
if ( !(_DWORD)result )
{
logtxt(0x4000LL, "Deletion of non-existant element in jtableP\n");
result = 0LL;
}
return result;
}

original_code:
int jtableP_unset(jtableP *table, void *key) {
 int ret;
 { JError_t J_Error; if (((ret) = Judy1Unset((&(table->t)), (Word_t)key, &J_Error)) == (-1)) { (void) fprintf(stderr, "File '%s', line %d: %s(), " "JU_ERRNO_* == %d, ID == %d\n", "src/jtable.c", 150, "Judy1Unset", ((&J_Error)->je_Errno), ((&J_Error)->je_ErrID)); exit(1); }; };
 if (!ret)
  logtxt(0x4000, "Deletion of non-existant element in jtableP" "\n");
 return ret;
}

canonical_original_code:
int jtableP_unset(struct jtableP *table, void *key) {
 int ret;
 { struct J_UDY_ERROR_STRUCT J_Error; if (((ret) = Judy1Unset((&(table->t)), (unsigned long)key, &J_Error)) == (-1)) { (void) fprintf(stderr, "File '%s', line %d: %s(), " "JU_ERRNO_* == %d, ID == %d\n", "src/jtable.c", 150, "Judy1Unset", ((&J_Error)->je_Errno), ((&J_Error)->je_ErrID)); exit(1); }; };
 if (!ret)
  logtxt(0x4000, "Deletion of non-existant element in jtableP" "\n");
 return ret;
}

variable_types:
table
struct jtableP { void *t; } *

variable_types:
key
void *

variable_types: ret int

variable_types: struct J_UDY_ERROR_STRUCT { enum JU_Errno_t { JU_ERRNO_NONE=0, JU_ERRNO_FULL=1, JU_ERRNO_NFMAX=expr, JU_ERRNO_NOMEM=2, JU_ERRNO_NULLPPARRAY=3, JU_ERRNO_NONNULLPARRAY=10, JU_ERRNO_NULLPINDEX=4, JU_ERRNO_NULLPVALUE=11, JU_ERRNO_NOTJUDY1=5, JU_ERRNO_NOTJUDYL=6, JU_ERRNO_NOTJUDYSL=7, JU_ERRNO_UNSORTED=12, JU_ERRNO_OVERRUN=8, JU_ERRNO_CORRUPT=9 } je_Errno; int je_ErrID; unsigned long je_reserved[4]; }

return_type: int

user_defined_types: struct J_UDY_ERROR_STRUCT { enum JU_Errno_t je_Errno; int je_ErrID; unsigned long je_reserved[4]; }


decompiled_code:
__int64 __fastcall jtableP_free(__int64 a1)
{
__int64 result; // rax
int v2[10]; // [rsp+0h] [rbp-38h] BYREF
unsigned __int64 v3; // [rsp+28h] [rbp-10h]

v3 = __readfsqword(0x28u);
result = Judy1FreeArray(a1, v2);
if ( (_DWORD)result == -1 )
{
fprintf(
stderr,
"File '%s', line %d: %s(), JU_ERRNO_* == %d, ID == %d\n",
"src/jtable.c",
159LL,
"Judy1FreeArray",
(unsigned int)v2[0],
(unsigned int)v2[1]);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 result; // rax
int v2[10]; // [rsp+0h] [rbp-38h] BYREF
unsigned __int64 v3; // [rsp+28h] [rbp-10h]

v3 = __readfsqword(0x28u);
result = Judy1FreeArray(a1, v2);
if ( (_DWORD)result == -1 )
{
fprintf(
stderr,
"File '%s', line %d: %s(), JU_ERRNO_* == %d, ID == %d\n",
"src/jtable.c",
159LL,
"Judy1FreeArray",
(unsigned int)v2[0],
(unsigned int)v2[1]);
exit(1);
}
return result;
}

original_code:
int jtableP_free(jtableP *table) {
 int ret;
 { JError_t J_Error; if (((ret) = Judy1FreeArray((&(table->t)), &J_Error)) == (-1)) { (void) fprintf(stderr, "File '%s', line %d: %s(), " "JU_ERRNO_* == %d, ID == %d\n", "src/jtable.c", 159, "Judy1FreeArray", ((&J_Error)->je_Errno), ((&J_Error)->je_ErrID)); exit(1); }; };
 return ret;
}

canonical_original_code:
int jtableP_free(struct jtableP *table) {
 int ret;
 { struct J_UDY_ERROR_STRUCT J_Error; if (((ret) = Judy1FreeArray((&(table->t)), &J_Error)) == (-1)) { (void) fprintf(stderr, "File '%s', line %d: %s(), " "JU_ERRNO_* == %d, ID == %d\n", "src/jtable.c", 159, "Judy1FreeArray", ((&J_Error)->je_Errno), ((&J_Error)->je_ErrID)); exit(1); }; };
 return ret;
}

user_defined_types: enum JU_Errno_t { JU_ERRNO_NONE=0, JU_ERRNO_FULL=1, JU_ERRNO_NFMAX=expr, JU_ERRNO_NOMEM=2, JU_ERRNO_NULLPPARRAY=3, JU_ERRNO_NONNULLPARRAY=10, JU_ERRNO_NULLPINDEX=4, JU_ERRNO_NULLPVALUE=11, JU_ERRNO_NOTJUDY1=5, JU_ERRNO_NOTJUDYL=6, JU_ERRNO_NOTJUDYSL=7, JU_ERRNO_UNSORTED=12, JU_ERRNO_OVERRUN=8, JU_ERRNO_CORRUPT=9 }


decompiled_code:
__int64 __fastcall jtableP_count(__int64 *a1)
{
__int64 v1; // rdi
__int64 result; // rax
int v3[10]; // [rsp+0h] [rbp-38h] BYREF
unsigned __int64 v4; // [rsp+28h] [rbp-10h]

v1 = *a1;
v4 = __readfsqword(0x28u);
result = Judy1Count(v1, 0LL, -1LL, v3);
if ( !(_DWORD)result && v3[0] > 1u )
{
fprintf(
stderr,
"File '%s', line %d: %s(), JU_ERRNO_* == %d, ID == %d\n",
"src/jtable.c",
166LL,
"Judy1Count",
(unsigned int)v3[0],
(unsigned int)v3[1]);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 *a1)
{
__int64 v1; // rdi
__int64 result; // rax
int v3[10]; // [rsp+0h] [rbp-38h] BYREF
unsigned __int64 v4; // [rsp+28h] [rbp-10h]

v1 = *a1;
v4 = __readfsqword(0x28u);
result = Judy1Count(v1, 0LL, -1LL, v3);
if ( !(_DWORD)result && v3[0] > 1u )
{
fprintf(
stderr,
"File '%s', line %d: %s(), JU_ERRNO_* == %d, ID == %d\n",
"src/jtable.c",
166LL,
"Judy1Count",
(unsigned int)v3[0],
(unsigned int)v3[1]);
exit(1);
}
return result;
}

original_code:
int jtableP_count(jtableP *table) {
 int ret;
 { JError_t J_Error; if ((((ret) = Judy1Count(table->t, 0, -1, &J_Error)) == 0) && (((&J_Error)->je_Errno) > JU_ERRNO_NFMAX)) { { (void) fprintf(stderr, "File '%s', line %d: %s(), " "JU_ERRNO_* == %d, ID == %d\n", "src/jtable.c", 166, "Judy1Count", ((&J_Error)->je_Errno), ((&J_Error)->je_ErrID)); exit(1); }; } };
 return ret;
}

canonical_original_code:
int jtableP_count(struct jtableP *table) {
 int ret;
 { struct J_UDY_ERROR_STRUCT J_Error; if ((((ret) = Judy1Count(table->t, 0, -1, &J_Error)) == 0) && (((&J_Error)->je_Errno) > JU_ERRNO_NFMAX)) { { (void) fprintf(stderr, "File '%s', line %d: %s(), " "JU_ERRNO_* == %d, ID == %d\n", "src/jtable.c", 166, "Judy1Count", ((&J_Error)->je_Errno), ((&J_Error)->je_ErrID)); exit(1); }; } };
 return ret;
}


decompiled_code:
unsigned __int64 __fastcall jtableP_iterate(_QWORD *a1, void (__fastcall *a2)(__int64, __int64), __int64 a3)
{
__int64 v5; // rdi
int v6; // eax
__int64 v8; // [rsp+8h] [rbp-60h] BYREF
unsigned int v9; // [rsp+10h] [rbp-58h] BYREF
unsigned int v10; // [rsp+14h] [rbp-54h]
unsigned __int64 v11; // [rsp+38h] [rbp-30h]

v5 = *a1;
v11 = __readfsqword(0x28u);
v8 = 0LL;
v6 = Judy1First(v5, &v8, &v9);
if ( v6 == -1 )
{
fprintf(
stderr,
"File '%s', line %d: %s(), JU_ERRNO_* == %d, ID == %d\n",
"src/jtable.c",
174LL,
"Judy1First",
v9,
v10);
goto LABEL_7;
}
while ( v6 )
{
a2(v8, a3);
v6 = Judy1Next(*a1, &v8, &v9);
if ( v6 == -1 )
{
fprintf(
stderr,
"File '%s', line %d: %s(), JU_ERRNO_* == %d, ID == %d\n",
"src/jtable.c",
177LL,
"Judy1Next",
v9,
v10);
LABEL_7:
exit(1);
}
}
return v11 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func14(_QWORD *a1, void (__fastcall *a2)(__int64, __int64), __int64 a3)
{
__int64 v5; // rdi
int v6; // eax
__int64 v8; // [rsp+8h] [rbp-60h] BYREF
unsigned int v9; // [rsp+10h] [rbp-58h] BYREF
unsigned int v10; // [rsp+14h] [rbp-54h]
unsigned __int64 v11; // [rsp+38h] [rbp-30h]

v5 = *a1;
v11 = __readfsqword(0x28u);
v8 = 0LL;
v6 = Judy1First(v5, &v8, &v9);
if ( v6 == -1 )
{
fprintf(
stderr,
"File '%s', line %d: %s(), JU_ERRNO_* == %d, ID == %d\n",
"src/jtable.c",
174LL,
"Judy1First",
v9,
v10);
goto LABEL_7;
}
while ( v6 )
{
a2(v8, a3);
v6 = Judy1Next(*a1, &v8, &v9);
if ( v6 == -1 )
{
fprintf(
stderr,
"File '%s', line %d: %s(), JU_ERRNO_* == %d, ID == %d\n",
"src/jtable.c",
177LL,
"Judy1Next",
v9,
v10);
LABEL_7:
exit(1);
}
}
return v11 - __readfsqword(0x28u);
}

original_code:
void jtableP_iterate(jtableP *table, jtableP_cb f, void *param) {
 int ret;
 Word_t key = 0;
 { JError_t J_Error; if (((ret) = Judy1First(table->t, &(key), &J_Error)) == (-1)) { (void) fprintf(stderr, "File '%s', line %d: %s(), " "JU_ERRNO_* == %d, ID == %d\n", "src/jtable.c", 174, "Judy1First", ((&J_Error)->je_Errno), ((&J_Error)->je_ErrID)); exit(1); }; };
 while (ret) {
  f((void *)key, param);
  { JError_t J_Error; if (((ret) = Judy1Next(table->t, &(key), &J_Error)) == (-1)) { (void) fprintf(stderr, "File '%s', line %d: %s(), " "JU_ERRNO_* == %d, ID == %d\n", "src/jtable.c", 177, "Judy1Next", ((&J_Error)->je_Errno), ((&J_Error)->je_ErrID)); exit(1); }; };
 }
}

canonical_original_code:
void jtableP_iterate(struct jtableP *table, void (*f)(void *key, void *param), void *param) {
 int ret;
 unsigned long key = 0;
 { struct J_UDY_ERROR_STRUCT J_Error; if (((ret) = Judy1First(table->t, &(key), &J_Error)) == (-1)) { (void) fprintf(stderr, "File '%s', line %d: %s(), " "JU_ERRNO_* == %d, ID == %d\n", "src/jtable.c", 174, "Judy1First", ((&J_Error)->je_Errno), ((&J_Error)->je_ErrID)); exit(1); }; };
 while (ret) {
  f((void *)key, param);
  { struct J_UDY_ERROR_STRUCT J_Error; if (((ret) = Judy1Next(table->t, &(key), &J_Error)) == (-1)) { (void) fprintf(stderr, "File '%s', line %d: %s(), " "JU_ERRNO_* == %d, ID == %d\n", "src/jtable.c", 177, "Judy1Next", ((&J_Error)->je_Errno), ((&J_Error)->je_ErrID)); exit(1); }; };
 }
}

variable_types:
f
void (*)(void *key, void *param)

variable_types:
param
void *

variable_types:
key
unsigned long

return_type: void


sfree

decompiled_code:
void __fastcall sfree(void *ptr)
{
free(ptr);
}

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

original_code:
void sfree(void *p) {
 free(p);
}

canonical_original_code:
void sfree(void *p) {
 free(p);
}

variable_types:
p
void *


smalloc

decompiled_code:
void *__fastcall smalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
logfmt(1LL, "Out of memory. Could not allocate %zd bytes.\n", a1);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
logfmt(1LL, "Out of memory. Could not allocate %zd bytes.\n", a1);
exit(1);
}
return result;
}

original_code:
void *smalloc(size_t s) {
 void *p = malloc(s);
 if (!p) {
  logfmt(0x0001, "Out of memory. Could not allocate %zd bytes." "\n", s);
  exit(1);
 }
 return p;
}

canonical_original_code:
void *smalloc(unsigned long s) {
 void *p = malloc(s);
 if (!p) {
  logfmt(0x0001, "Out of memory. Could not allocate %zd bytes." "\n", s);
  exit(1);
 }
 return p;
}

variable_types:
s
unsigned long

return_type: void *


sstrdup

decompiled_code:
char *__fastcall sstrdup(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)smalloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func2(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)func1(v1 + 1);
return strcpy(v2, src);
}

original_code:
char *sstrdup(const char *str) {
 char *new;
 size_t s = strlen(str);
 new = smalloc(s+1);
 strcpy(new, str);
 return new;
}

canonical_original_code:
char *sstrdup(char *str) {
 char *new;
 unsigned long s = strlen(str);
 new = smalloc(s+1);
 strcpy(new, str);
 return new;
}

variable_types:
str
char *

variable_types:
new
char *

return_type: char *


zmalloc

decompiled_code:
void *__fastcall zmalloc(size_t n)
{
void *v1; // rax
void *v2; // r8

v1 = smalloc(n);
v2 = v1;
if ( v1 )
v2 = memset(v1, 0, n);
return v2;
}

canonical_decompiled_code:
void *__fastcall func3(size_t n)
{
void *v1; // rax
void *v2; // r8

v1 = func1(n);
v2 = v1;
if ( v1 )
v2 = memset(v1, 0, n);
return v2;
}

original_code:
void *zmalloc(size_t s) {
 void *p = smalloc(s);
 if (p)
  memset(p, 0, s);
 return p;
}

canonical_original_code:
void *zmalloc(unsigned long s) {
 void *p = smalloc(s);
 if (p)
  memset(p, 0, s);
 return p;
}


decompiled_code:
__int64 __fastcall debug_print_chanuser(__int64 a1)
{
return logfmt(
0x4000LL,
" '%s!%s@%s' (%s)\n",
(const char *)(a1 + 22),
(const char *)(a1 + 38),
(const char *)(a1 + 49),
*(const char **)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return logfmt(
0x4000LL,
" '%s!%s@%s' (%s)\n",
(const char *)(a1 + 22),
(const char *)(a1 + 38),
(const char *)(a1 + 49),
*(const char **)(a1 + 8));
}

original_code:
static void debug_print_chanuser(struct user *u, void *null) {
 logfmt(0x4000, "    '%s!%s@%s' (%s)" "\n", u->nick, u->user, u->host, u->numeric);
}

variable_types: struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP { void *t; } channels; struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP users; unsigned long mode; } *server; } *

user_defined_types: struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP channels; struct server *server; }


decompiled_code:
__int64 __fastcall debug_print_ban(const char *a1, __int64 a2)
{
const char *v2; // r8

v2 = (const char *)(a2 + 91);
if ( !*(_BYTE *)(a2 + 91) )
v2 = "/unknown/";
return logfmt(0x4000LL, " '%s' == '%s' (from %s @ %ld)\n", a1, (const char *)a2, v2, *(_QWORD *)(a2 + 200));
}

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

v2 = (const char *)(a2 + 91);
if ( !*(_BYTE *)(a2 + 91) )
v2 = "/unknown/";
return logfmt(0x4000LL, " '%s' == '%s' (from %s @ %ld)\n", a1, (const char *)a2, v2, *(_QWORD *)(a2 + 200));
}

original_code:
static void debug_print_ban(const char *mask, struct mask *b, void *null) {
 logfmt(0x4000, "    '%s' == '%s' (from %s @ %ld)" "\n", mask, b->mask, b->from.nick[0] ? b->from.nick : "/unknown/", b->ts);
}

canonical_original_code:
static void debug_print_ban(char *mask, struct mask *b, void *null) {
 logfmt(0x4000, "    '%s' == '%s' (from %s @ %ld)" "\n", mask, b->mask, b->from.nick[0] ? b->from.nick : "/unknown/", b->ts);
}

variable_types:
mask
char *

variable_types: struct mask { char mask[-1]; struct maskfrom { char nick[-1]; char user[-1]; char host[-1]; char account[-1]; } from; long ts; } *

user_defined_types: struct mask { char mask[-1]; struct maskfrom from; long ts; }


decompiled_code:
__int64 __fastcall debug_print_channel(const char *a1, __int64 a2)
{
unsigned int v3; // ebx
__int64 v4; // rdx
unsigned int i; // ebx
__int64 v6; // rdx
__int64 v7; // rax

if ( *(_DWORD *)a2 != 11988 )
return logtxt(0x4000LL, "INVALID CHANNEL\n");
v3 = 97;
logfmt(0x4000LL, "Channel info for '%s' == '%s'\n", a1, (const char *)(a2 + 4));
logfmt(
0x4000LL,
" Key: '%s'. Limit: %ld. Creation: %ld\n",
(const char *)(a2 + 205),
*(_QWORD *)(a2 + 480),
*(_QWORD *)(a2 + 488));
t_1 = (__int64)modebuf_0;
do
{
if ( (unsigned int)mode_check1(a2 + 504, v3) )
{
v4 = t_1 + 1;
*(_BYTE *)t_1 = v3;
t_1 = v4;
}
++v3;
}
while ( v3 != 123 );
for ( i = 65; i != 91; ++i )
{
if ( (unsigned int)mode_check1(a2 + 504, i) )
{
v6 = t_1 + 1;
*(_BYTE *)t_1 = i;
t_1 = v6;
}
}
v7 = t_1;
*(_BYTE *)t_1 = 0;
t_1 = v7 + 1;
logfmt(0x4000LL, " Mode: +%s\n", modebuf_0);
logtxt(0x4000LL, " Bans:\n");
jtableS_iterate(a2 + 536, debug_print_ban, 0LL);
logtxt(0x4000LL, " Users:\n");
jtableP_iterate(a2 + 528, debug_print_chanuser, 0LL);
logtxt(0x4000LL, " Ops:\n");
jtableP_iterate(a2 + 512, debug_print_chanuser, 0LL);
logtxt(0x4000LL, " Voices:\n");
return jtableP_iterate(a2 + 520, debug_print_chanuser, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int64 a2)
{
unsigned int v3; // ebx
__int64 v4; // rdx
unsigned int i; // ebx
__int64 v6; // rdx
__int64 v7; // rax

if ( *(_DWORD *)a2 != 11988 )
return logtxt(0x4000LL, "INVALID CHANNEL\n");
v3 = 97;
logfmt(0x4000LL, "Channel info for '%s' == '%s'\n", a1, (const char *)(a2 + 4));
logfmt(
0x4000LL,
" Key: '%s'. Limit: %ld. Creation: %ld\n",
(const char *)(a2 + 205),
*(_QWORD *)(a2 + 480),
*(_QWORD *)(a2 + 488));
t_1 = (__int64)modebuf_0;
do
{
if ( (unsigned int)mode_check1(a2 + 504, v3) )
{
v4 = t_1 + 1;
*(_BYTE *)t_1 = v3;
t_1 = v4;
}
++v3;
}
while ( v3 != 123 );
for ( i = 65; i != 91; ++i )
{
if ( (unsigned int)mode_check1(a2 + 504, i) )
{
v6 = t_1 + 1;
*(_BYTE *)t_1 = i;
t_1 = v6;
}
}
v7 = t_1;
*(_BYTE *)t_1 = 0;
t_1 = v7 + 1;
logfmt(0x4000LL, " Mode: +%s\n", modebuf_0);
logtxt(0x4000LL, " Bans:\n");
jtableS_iterate(a2 + 536, debug_print_ban, 0LL);
logtxt(0x4000LL, " Users:\n");
jtableP_iterate(a2 + 528, debug_print_chanuser, 0LL);
logtxt(0x4000LL, " Ops:\n");
jtableP_iterate(a2 + 512, debug_print_chanuser, 0LL);
logtxt(0x4000LL, " Voices:\n");
return jtableP_iterate(a2 + 520, debug_print_chanuser, 0LL);
}

original_code:
static void debug_print_channel(const char *name, struct channel *c) {
 static char modebuf[64], *t;
 char i;
 if (!(((struct entity *)(c))->magic == 0x2ED4)) {
  logtxt(0x4000, "INVALID CHANNEL" "\n");
  return;
 }
 logfmt(0x4000, "Channel info for '%s' == '%s'" "\n", name, c->name);
 logfmt(0x4000, "  Key: '%s'. Limit: %ld. Creation: %ld" "\n", c->key, c->limit, c->ts);
 t = modebuf;
 for (i = 'a'; i <= 'z'; i++)
  if (mode_check1(&c->mode, i))
   *t++ = i;
 for (i = 'A'; i <= 'Z'; i++)
  if (mode_check1(&c->mode, i))
   *t++ = i;
 *t++ = '\0';
 logfmt(0x4000, "  Mode: +%s" "\n", modebuf);
 logtxt(0x4000, "  Bans:" "\n");
 jtableS_iterate(&c->bans, (jtableS_cb)debug_print_ban, ((void *)0));
 logtxt(0x4000, "  Users:" "\n");
 jtableP_iterate(&c->users, (jtableP_cb)debug_print_chanuser, ((void *)0));
 logtxt(0x4000, "  Ops:" "\n");
 jtableP_iterate(&c->ops, (jtableP_cb)debug_print_chanuser, ((void *)0));
 logtxt(0x4000, "  Voices:" "\n");
 jtableP_iterate(&c->voices, (jtableP_cb)debug_print_chanuser, ((void *)0));
}

canonical_original_code:
static void debug_print_channel(char *name, struct channel *c) {
 static char modebuf[64]; static char *t;
 char i;
 if (!(((struct entity *)(c))->magic == 0x2ED4)) {
  logtxt(0x4000, "INVALID CHANNEL" "\n");
  return;
 }
 logfmt(0x4000, "Channel info for '%s' == '%s'" "\n", name, c->name);
 logfmt(0x4000, "  Key: '%s'. Limit: %ld. Creation: %ld" "\n", c->key, c->limit, c->ts);
 t = modebuf;
 for (i = 'a'; i <= 'z'; i++)
  if (mode_check1(&c->mode, i))
   *t++ = i;
 for (i = 'A'; i <= 'Z'; i++)
  if (mode_check1(&c->mode, i))
   *t++ = i;
 *t++ = '\0';
 logfmt(0x4000, "  Mode: +%s" "\n", modebuf);
 logtxt(0x4000, "  Bans:" "\n");
 jtableS_iterate(&c->bans, (void (*)(char *key, void *data, void *param))debug_print_ban, ((void *)0));
 logtxt(0x4000, "  Users:" "\n");
 jtableP_iterate(&c->users, (void (*)(void *key, void *param))debug_print_chanuser, ((void *)0));
 logtxt(0x4000, "  Ops:" "\n");
 jtableP_iterate(&c->ops, (void (*)(void *key, void *param))debug_print_chanuser, ((void *)0));
 logtxt(0x4000, "  Voices:" "\n");
 jtableP_iterate(&c->voices, (void (*)(void *key, void *param))debug_print_chanuser, ((void *)0));
}

variable_types:
name
char *

variable_types: struct channel { unsigned int magic; char name[-1]; char key[-1]; char topic[-1]; long limit; long ts; int usercount; unsigned long mode; struct jtableP { void *t; } ops; struct jtableS { void *t; } bans; } *

variable_types:
modebuf
char [64]

variable_types:
t
char *

variable_types: i char

user_defined_types: struct channel { unsigned int magic; char name[-1]; char key[-1]; char topic[-1]; long limit; long ts; int usercount; unsigned long mode; struct jtableP ops; struct jtableS bans; }


decompiled_code:
__int64 __fastcall add_channel(__int64 a1, __int64 a2)
{
_DWORD *v2; // rax
_DWORD *v3; // r12
__int64 v4; // rsi

v2 = (_DWORD *)zmalloc(544LL);
*v2 = 11988;
v3 = v2;
strncpyz(v2 + 1, a1, 201LL);
*((_QWORD *)v3 + 61) = a2;
v4 = strconv(&rfc_tolower, 0LL, 0LL, a1);
return jtableS_insert(&channels, v4, v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
_DWORD *v2; // rax
_DWORD *v3; // r12
__int64 v4; // rsi

v2 = (_DWORD *)zmalloc(544LL);
*v2 = 11988;
v3 = v2;
strncpyz(v2 + 1, a1, 201LL);
*((_QWORD *)v3 + 61) = a2;
v4 = strconv(&rfc_tolower, 0LL, 0LL, a1);
return jtableS_insert(&channels, v4, v3);
}

original_code:
struct channel *add_channel(char *name, time_t ts) {
 struct channel *c;
 c = zmalloc(sizeof(*c));
 c->magic = 0x2ED4;
 strncpyz((c->name), (name), sizeof(c->name));
 c->ts = ts;
 return jtableS_insert(&channels, strconv(rfc_tolower, ((void *)0), 0, name), c);
}

canonical_original_code:
struct channel *add_channel(char *name, long ts) {
 struct channel *c;
 c = zmalloc(sizeof(*c));
 c->magic = 0x2ED4;
 strncpyz((c->name), (name), sizeof(c->name));
 c->ts = ts;
 return jtableS_insert(&channels, strconv(rfc_tolower, ((void *)0), 0, name), c);
}

variable_types: ts long

return_type: struct channel { unsigned int magic; char name[-1]; char key[-1]; char topic[-1]; long limit; long ts; int usercount; unsigned long mode; struct jtableP { void *t; } ops; struct jtableS { void *t; } bans; } *


decompiled_code:
void __fastcall del_channel(void *ptr)
{
__int64 v1; // rax
__int64 v2; // rdx
_BYTE v3[328]; // [rsp-148h] [rbp-2B8h] BYREF
_BYTE v4[328]; // [rsp+8h] [rbp-168h] BYREF
unsigned __int64 v5; // [rsp+150h] [rbp-20h]

v5 = __readfsqword(0x28u);
v1 = arg_ptr();
pack_args(v4, v1, v2, 0LL, 0LL);
qmemcpy(v3, v4, sizeof(v3));
hook_call("onchanneldel");
chanusers_del_channel(ptr);
jtableP_free((char *)ptr + 528);
jtableP_free((char *)ptr + 512);
jtableP_free((char *)ptr + 520);
jtableS_remove(&channels, (char *)ptr + 4);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
__int64 v1; // rax
__int64 v2; // rdx
_BYTE v3[328]; // [rsp-148h] [rbp-2B8h] BYREF
_BYTE v4[328]; // [rsp+8h] [rbp-168h] BYREF
unsigned __int64 v5; // [rsp+150h] [rbp-20h]

v5 = __readfsqword(0x28u);
v1 = arg_ptr();
pack_args(v4, v1, v2, 0LL, 0LL);
qmemcpy(v3, v4, sizeof(v3));
hook_call("onchanneldel");
chanusers_del_channel(ptr);
jtableP_free((char *)ptr + 528);
jtableP_free((char *)ptr + 512);
jtableP_free((char *)ptr + 520);
jtableS_remove(&channels, (char *)ptr + 4);
free(ptr);
}

original_code:
void del_channel(struct channel *c) {
 hook_call("onchanneldel", pack_args(arg_ptr(c), (struct funcarg) {.type = ARGTYPE_NONE}));
 chanusers_del_channel(c);
 jtableP_free(&c->users);
 jtableP_free(&c->ops);
 jtableP_free(&c->voices);
 jtableS_remove(&channels, c->name);
 free(c);
}

user_defined_types: struct funcarg { enum argtype type; union argdata data; }

user_defined_types: enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 }

user_defined_types: union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; }


decompiled_code:
__int64 __fastcall get_channel_by_name(__int64 a1)
{
__int64 v1; // rsi

v1 = strconv(&rfc_tolower, 0LL, 0LL, a1);
return jtableS_get(&channels, v1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rsi

v1 = strconv(&rfc_tolower, 0LL, 0LL, a1);
return jtableS_get(&channels, v1);
}

original_code:
struct channel *get_channel_by_name(const char *name) {
 return jtableS_get(&channels, strconv(rfc_tolower, ((void *)0), 0, name));
}

canonical_original_code:
struct channel *get_channel_by_name(char *name) {
 return jtableS_get(&channels, strconv(rfc_tolower, ((void *)0), 0, name));
}


decompiled_code:
__int64 __fastcall channel_plsprefix(__int64 a1, __int64 a2, char a3)
{
if ( !(unsigned int)chanusers_ison(a2, a1) )
_assert_fail("chanusers_ison(u, c)", "src/channels.c", 0x45u, "channel_plsprefix");
if ( a3 == 111 )
return jtableP_set(a1 + 512, a2);
if ( a3 == 118 )
return jtableP_set(a1 + 520, a2);
return logfmt(256LL, "Invalid prefix mode change: %c\n", (unsigned int)a3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, char a3)
{
if ( !(unsigned int)chanusers_ison(a2, a1) )
_assert_fail("chanusers_ison(u, c)", "src/channels.c", 0x45u, "channel_plsprefix");
if ( a3 == 111 )
return jtableP_set(a1 + 512, a2);
if ( a3 == 118 )
return jtableP_set(a1 + 520, a2);
return logfmt(256LL, "Invalid prefix mode change: %c\n", (unsigned int)a3);
}

original_code:
void channel_plsprefix(struct channel *c, struct user *u, char mc) {
 ((chanusers_ison(u, c)) ? (void) (0) : __assert_fail ("chanusers_ison(u, c)", "src/channels.c", 69, __extension__ __PRETTY_FUNCTION__));
 if (mc == 'o')
  jtableP_set(&c->ops, u);
 else if (mc == 'v')
  jtableP_set(&c->voices, u);
 else
  logfmt(0x0100, "Invalid prefix mode change: %c" "\n", mc);
}

variable_types: struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP channels; struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP users; unsigned long mode; } *server; } *

variable_types: mc char


decompiled_code:
__int64 __fastcall channel_mnsprefix(__int64 a1, __int64 a2, char a3)
{
if ( !(unsigned int)chanusers_ison(a2, a1) )
_assert_fail("chanusers_ison(u, c)", "src/channels.c", 0x4Fu, "channel_mnsprefix");
if ( a3 == 111 )
return jtableP_unset(a1 + 512, a2);
if ( a3 == 118 )
return jtableP_unset(a1 + 520, a2);
return logfmt(256LL, "Invalid prefix mode change: %c\n", (unsigned int)a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, char a3)
{
if ( !(unsigned int)chanusers_ison(a2, a1) )
_assert_fail("chanusers_ison(u, c)", "src/channels.c", 0x4Fu, "channel_mnsprefix");
if ( a3 == 111 )
return jtableP_unset(a1 + 512, a2);
if ( a3 == 118 )
return jtableP_unset(a1 + 520, a2);
return logfmt(256LL, "Invalid prefix mode change: %c\n", (unsigned int)a3);
}

original_code:
void channel_mnsprefix(struct channel *c, struct user *u, char mc) {
 ((chanusers_ison(u, c)) ? (void) (0) : __assert_fail ("chanusers_ison(u, c)", "src/channels.c", 79, __extension__ __PRETTY_FUNCTION__));
 if (mc == 'o')
  jtableP_unset(&c->ops, u);
 else if (mc == 'v')
  jtableP_unset(&c->voices, u);
 else
  logfmt(0x0100, "Invalid prefix mode change: %c" "\n", mc);
}

user_defined_types: struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP users; unsigned long mode; }


original_code:
void channel_plsban(struct channel *c, struct entity *e, char *str) {
 struct mask *m;
 struct user *u;
 m = zmalloc(sizeof(*m));
 if (e && (((struct entity *)(e))->magic == 0x49F1)) {
  u = (struct user *)e;
  strncpyz((m->from.nick), (u->nick), sizeof(m->from.nick));
  strncpyz((m->from.user), (u->user), sizeof(m->from.user));
  strncpyz((m->from.host), (u->host), sizeof(m->from.host));
  strncpyz((m->from.account), (u->account), sizeof(m->from.account));
 }
 strncpyz((m->mask), (str), sizeof(m->mask));
 m->ts = now;
 jtableS_insert(&c->bans, str, m);
}

variable_types:
e
struct entity { unsigned int magic; } *

user_defined_types: struct maskfrom { char nick[-1]; char user[-1]; char host[-1]; char account[-1]; }


decompiled_code:
__int64 __fastcall channel_mnsban(__int64 a1, _DWORD *a2, __int64 a3)
{
__int64 v4; // r13

if ( *a2 != 18929 )
logtxt(256LL, "Ban unset by non-user.\n");
v4 = jtableS_get(a1 + 536, a3);
if ( !v4 )
return logtxt(256LL, "Non-existant ban removed.\n");
jtableS_remove(a1 + 536, a3);
return sfree(v4);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, _DWORD *a2, __int64 a3)
{
__int64 v4; // r13

if ( *a2 != 18929 )
logtxt(256LL, "Ban unset by non-user.\n");
v4 = jtableS_get(a1 + 536, a3);
if ( !v4 )
return logtxt(256LL, "Non-existant ban removed.\n");
jtableS_remove(a1 + 536, a3);
return sfree(v4);
}

original_code:
void channel_mnsban(struct channel *c, struct entity *e, char *str) {
 struct mask *m;
 if (!(((struct entity *)(e))->magic == 0x49F1))
  logtxt(0x0100, "Ban unset by non-user." "\n");
 m = jtableS_get(&c->bans, str);
 if (!m) {
  logtxt(0x0100, "Non-existant ban removed." "\n");
  return;
 }
 jtableS_remove(&c->bans, str);
 sfree(m);
}


decompiled_code:
__int64 __fastcall channel_modehook(char *a1, __int64 a2, int a3, char a4, const char *a5)
{
__int64 result; // rax
_DWORD *v9; // rax
__int64 v10; // rax
__int64 v11; // rbx
const char *v12; // r14

if ( *(_DWORD *)a2 == 11988 )
{
switch ( a4 )
{
case 'b':
if ( a5 && *a5 )
{
if ( a3 )
channel_plsban(a2, a1, (__int64)a5);
else
channel_mnsban(a2, a1, (__int64)a5);
goto LABEL_8;
}
logtxt(256LL, "Invalid ban mode change or non-existant ban.\n");
result = 0LL;
break;
case 'k':
v12 = (const char *)(a2 + 205);
if ( a3 )
{
strncpyz(v12, a5, 24LL);
result = 0LL;
}
else
{
if ( strcmp(v12, a5) )
logfmt(256LL, "Unset key that wasn't set. Mine: '%s', theirs: '%s'.\n", v12, a5);
*(_BYTE *)(a2 + 205) = 0;
result = 0LL;
}
break;
case 'l':
v10 = strtol(a5, 0LL, 10);
v11 = v10;
if ( a3 && v10 <= 0 )
logfmt(256LL, "Invalid limit setting: '%s' (=> %ld)\n", a5, v10);
*(_QWORD *)(a2 + 480) = v11;
result = 0LL;
break;
case 'o':
case 'v':
LABEL_8:
v9 = (_DWORD *)get_user_by_numericstr(a5);
if ( v9 && *v9 == 18929 )
{
if ( a3 )
channel_plsprefix(a2, (__int64)v9, a4);
else
channel_mnsprefix(a2, (__int64)v9, a4);
result = 0LL;
}
else
{
logtxt(256LL, "Op/voice for non-existant/invalid user!\n");
result = 0LL;
}
break;
default:
result = 0LL;
break;
}
}
else
{
logtxt(16LL, "Mode change for not-a-channel!\n");
result = 4294967293LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1, __int64 a2, int a3, char a4, const char *a5)
{
__int64 result; // rax
_DWORD *v9; // rax
__int64 v10; // rax
__int64 v11; // rbx
const char *v12; // r14

if ( *(_DWORD *)a2 == 11988 )
{
switch ( a4 )
{
case 'b':
if ( a5 && *a5 )
{
if ( a3 )
func8(a2, a1, (__int64)a5);
else
func9(a2, a1, (__int64)a5);
goto LABEL_8;
}
logtxt(256LL, "Invalid ban mode change or non-existant ban.\n");
result = 0LL;
break;
case 'k':
v12 = (const char *)(a2 + 205);
if ( a3 )
{
strncpyz(v12, a5, 24LL);
result = 0LL;
}
else
{
if ( strcmp(v12, a5) )
logfmt(256LL, "Unset key that wasn't set. Mine: '%s', theirs: '%s'.\n", v12, a5);
*(_BYTE *)(a2 + 205) = 0;
result = 0LL;
}
break;
case 'l':
v10 = strtol(a5, 0LL, 10);
v11 = v10;
if ( a3 && v10 <= 0 )
logfmt(256LL, "Invalid limit setting: '%s' (=> %ld)\n", a5, v10);
*(_QWORD *)(a2 + 480) = v11;
result = 0LL;
break;
case 'o':
case 'v':
LABEL_8:
v9 = (_DWORD *)get_user_by_numericstr(a5);
if ( v9 && *v9 == 18929 )
{
if ( a3 )
func6(a2, (__int64)v9, a4);
else
func7(a2, (__int64)v9, a4);
result = 0LL;
}
else
{
logtxt(256LL, "Op/voice for non-existant/invalid user!\n");
result = 0LL;
}
break;
default:
result = 0LL;
break;
}
}
else
{
logtxt(16LL, "Mode change for not-a-channel!\n");
result = 4294967293LL;
}
return result;
}

original_code:
static int channel_modehook(struct entity *from, struct entity *target, int pls, char modechange, char *param) {
 struct channel *c;
 struct user *u;
 long tmp;
 c = (struct channel *)target;
 if (!(((struct entity *)(c))->magic == 0x2ED4)) {
  logtxt(0x0010, "Mode change for not-a-channel!" "\n");
  return -3;
 }
 switch (modechange) {
  case 'k':
   if (!pls) {
    if (strcmp(c->key, param))
     logfmt(0x0100, "Unset key that wasn't set. Mine: '%s', theirs: '%s'." "\n", c->key, param);
    c->key[0] = '\0';
   } else
    strncpyz((c->key), (param), sizeof(c->key));
   break;
  case 'l':
   tmp = strtol(param, ((void *)0), 10);
   if (pls && tmp <= 0) {
    logfmt(0x0100, "Invalid limit setting: '%s' (=> %ld)" "\n", param, tmp);
   }
   c->limit = tmp;
   break;
  case 'b':
   if (!param || !param[0]) {
    logtxt(0x0100, "Invalid ban mode change or non-existant ban." "\n");
    return 0;
   }
   pls ? channel_plsban(c, from, param) : channel_mnsban(c, from, param);
  case 'o':
  case 'v':
   u = get_user_by_numericstr(param);
   if (!u || !(((struct entity *)(u))->magic == 0x49F1)) {
    logtxt(0x0100, "Op/voice for non-existant/invalid user!" "\n");
    return 0;
   }
   pls ? channel_plsprefix(c, u, modechange) : channel_mnsprefix(c, u, modechange);
   break;
 }
 return 0;
}

variable_types:
from
struct entity { unsigned int magic; } *

variable_types:
target
struct entity *

variable_types: pls int

variable_types: modechange char

variable_types:
param
char *

variable_types: tmp long


decompiled_code:
__int64 __fastcall channel_isop(__int64 a1)
{
return jtableP_check(a1 + 512);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return jtableP_check(a1 + 512);
}

original_code:
int channel_isop(struct channel *c, struct user *u) {
 return jtableP_check(&c->ops, u);
}


decompiled_code:
__int64 __fastcall channel_isvoice(__int64 a1)
{
return jtableP_check(a1 + 520);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return jtableP_check(a1 + 520);
}

original_code:
int channel_isvoice(struct channel *c, struct user *u) {
 return jtableP_check(&c->voices, u);
}


decompiled_code:
_BOOL8 __fastcall channel_isoporvoice(__int64 a1)
{
int v1; // er8
_BOOL8 result; // rax

v1 = channel_isop(a1);
result = 1LL;
if ( !v1 )
result = (unsigned int)channel_isvoice(a1) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(__int64 a1)
{
int v1; // er8
_BOOL8 result; // rax

v1 = func11(a1);
result = 1LL;
if ( !v1 )
result = (unsigned int)func12(a1) != 0;
return result;
}

original_code:
int channel_isoporvoice(struct channel *c, struct user *u) {
 return channel_isop(c, u) || channel_isvoice(c, u);
}


decompiled_code:
_BOOL8 __fastcall channel_isregular(__int64 a1)
{
return !channel_isoporvoice(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(__int64 a1)
{
return !func13(a1);
}

original_code:
int channel_isregular(struct channel *c, struct user *u) {
 return !channel_isoporvoice(c, u);
}


decompiled_code:
unsigned __int64 __fastcall channel_burstmode(__int64 a1, __int64 a2, char *a3)
{
char *v3; // rbx
char v4; // dl
unsigned __int64 v6; // [rsp+8h] [rbp-20h]

v3 = a3;
v4 = *a3;
v6 = __readfsqword(0x28u);
if ( (v4 & 0xDF) != 0 )
{
do
{
++v3;
channel_plsprefix(a1, a2, v4);
v4 = *v3;
}
while ( (*v3 & 0xDF) != 0 );
}
return v6 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func15(__int64 a1, __int64 a2, char *a3)
{
char *v3; // rbx
char v4; // dl
unsigned __int64 v6; // [rsp+8h] [rbp-20h]

v3 = a3;
v4 = *a3;
v6 = __readfsqword(0x28u);
if ( (v4 & 0xDF) != 0 )
{
do
{
++v3;
func6(a1, a2, v4);
v4 = *v3;
}
while ( (*v3 & 0xDF) != 0 );
}
return v6 - __readfsqword(0x28u);
}

original_code:
void channel_burstmode(struct channel *chan, struct user *user, char *modes) {
 while (*modes && *modes != ' ')
  channel_plsprefix(chan, user, *modes++);
}

variable_types:
modes
char *


decompiled_code:
__int64 __fastcall channel_apply_mode(__int64 a1, _DWORD *a2, __int64 a3, __int64 a4, unsigned int a5)
{
if ( *a2 == 11988 )
return mode_apply(a1, a2, a2 + 126, a3, a4, a5, channel_modehook);
logtxt(256LL, "Mode change on non-channel\n");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, _DWORD *a2, __int64 a3, __int64 a4, unsigned int a5)
{
if ( *a2 == 11988 )
return mode_apply(a1, a2, a2 + 126, a3, a4, a5, channel_modehook);
logtxt(256LL, "Mode change on non-channel\n");
return 0LL;
}

original_code:
int channel_apply_mode(struct entity *from, struct channel *target, char *modechanges, struct manyargs *arg, int skip) {
 if (!(((struct entity *)(target))->magic == 0x2ED4)) {
  logtxt(0x0100, "Mode change on non-channel" "\n");
  return 0;
 }
 return mode_apply(from, (struct entity *)target, &target->mode, modechanges, arg, skip, channel_modehook);
}

variable_types:
modechanges
char *

variable_types: struct manyargs { unsigned char c; char *v[256]; } *

variable_types: skip int


decompiled_code:
__int64 __fastcall channel_apply_clearmode(__int64 a1, __int64 a2, char *a3)
{
__int64 v4; // rsi
char *v5; // rbx

if ( *(_DWORD *)a2 == 11988 )
{
v4 = (unsigned int)*a3;
v5 = a3;
if ( *a3 )
{
do
{
switch ( (char)v4 )
{
case 'b':
jtableS_free(a2 + 536);
break;
case 'k':
*(_BYTE *)(a2 + 205) = 0;
mode_unset1(a2 + 504, (unsigned int)*v5);
break;
case 'l':
*(_QWORD *)(a2 + 480) = 0LL;
mode_unset1(a2 + 504, (unsigned int)*v5);
break;
case 'o':
jtableP_free(a2 + 512);
break;
case 'v':
jtableP_free(a2 + 520);
break;
default:
mode_unset1(a2 + 504, v4);
break;
}
v4 = (unsigned int)*++v5;
}
while ( (_BYTE)v4 );
}
}
else
{
logtxt(256LL, "Clearmode on non-channel\n");
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2, char *a3)
{
__int64 v4; // rsi
char *v5; // rbx

if ( *(_DWORD *)a2 == 11988 )
{
v4 = (unsigned int)*a3;
v5 = a3;
if ( *a3 )
{
do
{
switch ( (char)v4 )
{
case 'b':
jtableS_free(a2 + 536);
break;
case 'k':
*(_BYTE *)(a2 + 205) = 0;
mode_unset1(a2 + 504, (unsigned int)*v5);
break;
case 'l':
*(_QWORD *)(a2 + 480) = 0LL;
mode_unset1(a2 + 504, (unsigned int)*v5);
break;
case 'o':
jtableP_free(a2 + 512);
break;
case 'v':
jtableP_free(a2 + 520);
break;
default:
mode_unset1(a2 + 504, v4);
break;
}
v4 = (unsigned int)*++v5;
}
while ( (_BYTE)v4 );
}
}
else
{
logtxt(256LL, "Clearmode on non-channel\n");
}
return 0LL;
}

original_code:
int channel_apply_clearmode(struct entity *from, struct entity *target, char *modes) {
 struct channel *channel = (struct channel *)target;
 if (!(((struct entity *)(channel))->magic == 0x2ED4)) {
  logtxt(0x0100, "Clearmode on non-channel" "\n");
  return 0;
 }
 while (*modes) {
  switch (*modes) {
   case 'o':
    jtableP_free(&channel->ops);
    break;
   case 'v':
    jtableP_free(&channel->voices);
    break;
   case 'b':
    jtableS_free(&channel->bans);
    break;
   case 'l':
    channel->limit = 0;
    mode_unset1(&channel->mode, *modes);
    break;
   case 'k':
    channel->key[0] = 0;
    mode_unset1(&channel->mode, *modes);
    break;
   default:
    mode_unset1(&channel->mode, *modes);
  }
  modes++;
 }
 return 0;
}

variable_types: struct channel { unsigned int magic; char name[-1]; char key[-1]; char topic[-1]; long limit; long ts; int usercount; unsigned long mode; struct jtableP { void *t; } ops; struct jtableS { void *t; } bans; } *


decompiled_code:
__int64 debug_print_users()
{
logtxt(0x4000LL, "------------- Channel -------------\n");
return jtableS_iterate(&channels, debug_print_channel, 0LL);
}

canonical_decompiled_code:
__int64 func18()
{
logtxt(0x4000LL, "------------- Channel -------------\n");
return jtableS_iterate(&channels, debug_print_channel, 0LL);
}

original_code:
void debug_print_users(void) {
 logtxt(0x4000, "------------- Channel -------------" "\n");
 jtableS_iterate(&channels, (jtableS_cb)debug_print_channel, ((void *)0));
}

canonical_original_code:
void debug_print_users() {
 logtxt(0x4000, "------------- Channel -------------" "\n");
 jtableS_iterate(&channels, (void (*)(char *key, void *data, void *param))debug_print_channel, ((void *)0));
}


decompiled_code:
unsigned __int64 __fastcall user_del_channel(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
*(_DWORD *)(a1 + 480) -= jtableP_unset(a1 + 488);
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
*(_DWORD *)(a1 + 480) -= jtableP_unset(a1 + 488);
return v2 - __readfsqword(0x28u);
}

original_code:
static void user_del_channel(struct user *u, struct channel *c) {
 u->channelcount -= jtableP_unset(&u->channels, c);
}

variable_types: struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP { void *t; } channels; struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP users; unsigned long mode; } *server; } *

variable_types: struct channel { unsigned int magic; char name[-1]; char key[-1]; char topic[-1]; long limit; long ts; int usercount; unsigned long mode; struct jtableP ops; struct jtableS { void *t; } bans; } *


decompiled_code:
unsigned __int64 __fastcall channel_del_user(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-20h]

v2 = __readfsqword(0x28u);
jtableP_unset(a1 + 512);
jtableP_unset(a1 + 520);
*(_DWORD *)(a1 + 496) -= jtableP_unset(a1 + 528);
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-20h]

v2 = __readfsqword(0x28u);
jtableP_unset(a1 + 512);
jtableP_unset(a1 + 520);
*(_DWORD *)(a1 + 496) -= jtableP_unset(a1 + 528);
return v2 - __readfsqword(0x28u);
}

original_code:
static void channel_del_user(struct channel *c, struct user *u) {
 jtableP_unset(&c->ops, u);
 jtableP_unset(&c->voices, u);
 c->usercount -= jtableP_unset(&c->users, u);
}


decompiled_code:
unsigned __int64 __fastcall channel_add_user(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
*(_DWORD *)(a1 + 496) += jtableP_set(a1 + 528);
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
*(_DWORD *)(a1 + 496) += jtableP_set(a1 + 528);
return v2 - __readfsqword(0x28u);
}

original_code:
static void channel_add_user(struct channel *c, struct user *u) {
 c->usercount += jtableP_set(&c->users, u);
}


decompiled_code:
unsigned __int64 __fastcall user_add_channel(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
*(_DWORD *)(a1 + 480) += jtableP_set(a1 + 488);
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
*(_DWORD *)(a1 + 480) += jtableP_set(a1 + 488);
return v2 - __readfsqword(0x28u);
}

original_code:
static void user_add_channel(struct user *u, struct channel *c) {
 u->channelcount += jtableP_set(&u->channels, c);
}


decompiled_code:
__int64 __fastcall user_ison(__int64 a1)
{
return jtableP_check(a1 + 488);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return jtableP_check(a1 + 488);
}

original_code:
static int user_ison(struct user *u, struct channel *c) {
 return jtableP_check(&u->channels, c);
}


decompiled_code:
__int64 __fastcall channel_ison(__int64 a1)
{
return jtableP_check(a1 + 528);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return jtableP_check(a1 + 528);
}

original_code:
static int channel_ison(struct channel *c, struct user *u) {
 return jtableP_check(&c->users, u);
}


decompiled_code:
__int64 __fastcall chanusers_del_channel(__int64 a1)
{
return jtableP_iterate(a1 + 528, user_del_channel, a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return jtableP_iterate(a1 + 528, user_del_channel, a1);
}

original_code:
void chanusers_del_channel(struct channel *c) {
 jtableP_iterate(&c->users, (jtableP_cb)user_del_channel, c);
}

canonical_original_code:
void chanusers_del_channel(struct channel *c) {
 jtableP_iterate(&c->users, (void (*)(void *key, void *param))user_del_channel, c);
}


decompiled_code:
__int64 __fastcall chanusers_del_user(__int64 a1)
{
return jtableP_iterate(a1 + 488, channel_del_user, a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return jtableP_iterate(a1 + 488, channel_del_user, a1);
}

original_code:
void chanusers_del_user(struct user *u) {
 jtableP_iterate(&u->channels, (jtableP_cb)channel_del_user, u);
}

canonical_original_code:
void chanusers_del_user(struct user *u) {
 jtableP_iterate(&u->channels, (void (*)(void *key, void *param))channel_del_user, u);
}


decompiled_code:
unsigned __int64 __fastcall chanusers_join(__int64 a1, __int64 a2)
{
channel_add_user(a2);
return user_add_channel(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 a1, __int64 a2)
{
func2(a2);
return func3(a1);
}

original_code:
void chanusers_join(struct user *u, struct channel *c) {
 channel_add_user(c, u);
 user_add_channel(u, c);
}


decompiled_code:
unsigned __int64 __fastcall chanusers_leave(__int64 a1, __int64 a2)
{
channel_del_user(a2);
return user_del_channel(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(__int64 a1, __int64 a2)
{
func1(a2);
return func0(a1);
}

original_code:
void chanusers_leave(struct user *u, struct channel *c) {
 channel_del_user(c, u);
 user_del_channel(u, c);
}


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

if ( *(_DWORD *)(a1 + 480) >= *(_DWORD *)(a2 + 496) )
result = channel_ison(a2);
else
result = user_ison(a1);
return result;
}

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

if ( *(_DWORD *)(a1 + 480) >= *(_DWORD *)(a2 + 496) )
result = func5(a2);
else
result = func4(a1);
return result;
}

original_code:
int chanusers_ison(struct user *u, struct channel *c) {
 if (u->channelcount < c->usercount)
  return user_ison(u, c);
 else
  return channel_ison(c, u);
}


decompiled_code:
unsigned __int64 __fastcall chanusers_join0(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
chanusers_del_user(a1);
jtableP_free(a1 + 488);
if ( *(_DWORD *)(a1 + 480) )
_assert_fail("u->channelcount == 0", "src/chanusers.c", 0x5Au, "chanusers_join0");
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
func7(a1);
jtableP_free(a1 + 488);
if ( *(_DWORD *)(a1 + 480) )
_assert_fail("u->channelcount == 0", "src/chanusers.c", 0x5Au, "chanusers_join0");
return v2 - __readfsqword(0x28u);
}

original_code:
void chanusers_join0(struct user *u) {
 chanusers_del_user(u);
 jtableP_free(&u->channels);
 ((u->channelcount == 0) ? (void) (0) : __assert_fail ("u->channelcount == 0", "src/chanusers.c", 90, __extension__ __PRETTY_FUNCTION__));
}


decompiled_code:
__int64 __fastcall hook_register(__int64 a1)
{
__int64 v1; // rdx

v1 = zmalloc(8LL);
return jtableS_insert(&hooks, a1, v1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rdx

v1 = zmalloc(8LL);
return jtableS_insert(&hooks, a1, v1);
}

original_code:
static void hook_register(char *name) {
 jtableP *t = zmalloc(sizeof(*t));
 jtableS_insert(&hooks, name, t);
}

canonical_original_code:
static void hook_register(char *name) {
 struct jtableP *t = zmalloc(sizeof(*t));
 jtableS_insert(&hooks, name, t);
}

variable_types:
name
char *

variable_types:
t
struct jtableP { void *t; } *


decompiled_code:
__int64 __fastcall get_funcs(const char *a1)
{
__int64 v1; // r12

v1 = jtableS_get(&hooks, a1);
if ( !v1 )
logfmt(256LL, "Invalid hook '%s'\n", a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
__int64 v1; // r12

v1 = jtableS_get(&hooks, a1);
if ( !v1 )
logfmt(256LL, "Invalid hook '%s'\n", a1);
return v1;
}

original_code:
static jtableP *get_funcs(const char *name) {
 jtableP *funcs = jtableS_get(&hooks, name);
 if (!funcs) {
  logfmt(0x0100, "Invalid hook '%s'" "\n", name);
  return ((void *)0);
 }
 return funcs;
}

canonical_original_code:
static struct jtableP *get_funcs(char *name) {
 struct jtableP *funcs = jtableS_get(&hooks, name);
 if (!funcs) {
  logfmt(0x0100, "Invalid hook '%s'" "\n", name);
  return ((void *)0);
 }
 return funcs;
}

variable_types:
funcs
struct jtableP { void *t; } *

return_type: struct jtableP { void *t; } *


decompiled_code:
__int64 hook_call1()
{
return call_varargs();
}

canonical_decompiled_code:
__int64 func2()
{
return call_varargs();
}

original_code:
static void hook_call1(void (*func)(), struct args *arg) {
 call_varargs(func, arg);
}

variable_types:
func
void (*)()

variable_types: struct args { unsigned char c; struct funcarg { enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 } type; union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; } data; } v[20]; } *

user_defined_types: struct args { unsigned char c; struct funcarg v[20]; }


decompiled_code:
__int64 init_hooks()
{
hook_register((__int64)"ontick");
hook_register((__int64)"onregistered");
hook_register((__int64)"onchanmsg");
hook_register((__int64)"onprivmsg");
hook_register((__int64)"onprivnotc");
hook_register((__int64)"onpart");
hook_register((__int64)"onquit");
hook_register((__int64)"onuserdel");
hook_register((__int64)"onserverdel");
return hook_register((__int64)"onchanneldel");
}

canonical_decompiled_code:
__int64 func3()
{
func0((__int64)"ontick");
func0((__int64)"onregistered");
func0((__int64)"onchanmsg");
func0((__int64)"onprivmsg");
func0((__int64)"onprivnotc");
func0((__int64)"onpart");
func0((__int64)"onquit");
func0((__int64)"onuserdel");
func0((__int64)"onserverdel");
return func0((__int64)"onchanneldel");
}

original_code:
void init_hooks(void) {
 hook_register("ontick");
 hook_register("onregistered");
 hook_register("onchanmsg");
 hook_register("onprivmsg");
 hook_register("onprivnotc");
 hook_register("onpart");
 hook_register("onquit");
 hook_register("onuserdel");
 hook_register("onserverdel");
 hook_register("onchanneldel");
}

canonical_original_code:
void init_hooks() {
 hook_register("ontick");
 hook_register("onregistered");
 hook_register("onchanmsg");
 hook_register("onprivmsg");
 hook_register("onprivnotc");
 hook_register("onpart");
 hook_register("onquit");
 hook_register("onuserdel");
 hook_register("onserverdel");
 hook_register("onchanneldel");
}


decompiled_code:
__int64 __fastcall hook_hook(const char *a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_funcs(a1);
if ( v2 )
result = jtableP_set(v2, a2);
else
result = v4 - __readfsqword(0x28u);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = func1(a1);
if ( v2 )
result = jtableP_set(v2, a2);
else
result = v4 - __readfsqword(0x28u);
return result;
}

original_code:
void hook_hook(const char *name, void (*f)()) {
 jtableP *funcs = get_funcs(name);
 if (!funcs)
  return;
 jtableP_set(funcs, f);
}

canonical_original_code:
void hook_hook(char *name, void (*f)()) {
 struct jtableP *funcs = get_funcs(name);
 if (!funcs)
  return;
 jtableP_set(funcs, f);
}

variable_types:
f
void (*)()


decompiled_code:
__int64 __fastcall hook_unhook(const char *a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_funcs(a1);
if ( v2 )
result = jtableP_unset(v2, a2);
else
result = v4 - __readfsqword(0x28u);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = func1(a1);
if ( v2 )
result = jtableP_unset(v2, a2);
else
result = v4 - __readfsqword(0x28u);
return result;
}

original_code:
void hook_unhook(const char *name, void (*f)()) {
 jtableP *funcs = get_funcs(name);
 if (!funcs)
  return;
 jtableP_unset(funcs, f);
}

canonical_original_code:
void hook_unhook(char *name, void (*f)()) {
 struct jtableP *funcs = get_funcs(name);
 if (!funcs)
  return;
 jtableP_unset(funcs, f);
}


decompiled_code:
unsigned __int64 __fastcall hook_call(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
__int64 v7; // rax
__int64 v8; // r12
char v10[336]; // [rsp+8h] [rbp-170h] BYREF
unsigned __int64 v11; // [rsp+158h] [rbp-20h]

qmemcpy(v10, &a7, 0x148uLL);
v11 = __readfsqword(0x28u);
v7 = get_funcs(a1);
if ( v7 )
{
v8 = v7;
if ( !strcmp(a1, "hook_ontick") )
logfmt(0x4000LL, "Calling hook %s\n", a1);
jtableP_iterate(v8, hook_call1, v10);
}
return v11 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
__int64 v7; // rax
__int64 v8; // r12
char v10[336]; // [rsp+8h] [rbp-170h] BYREF
unsigned __int64 v11; // [rsp+158h] [rbp-20h]

qmemcpy(v10, &a7, 0x148uLL);
v11 = __readfsqword(0x28u);
v7 = func1(a1);
if ( v7 )
{
v8 = v7;
if ( !strcmp(a1, "hook_ontick") )
logfmt(0x4000LL, "Calling hook %s\n", a1);
jtableP_iterate(v8, hook_call1, v10);
}
return v11 - __readfsqword(0x28u);
}

original_code:
void hook_call(const char *name, struct args arg) {
 jtableP *funcs = get_funcs(name);
 if (!funcs)
  return;
 if (!strncmp(name, "hook_ontick", 12)) {
  logfmt(0x4000, "Calling hook %s" "\n", name);
 }
 jtableP_iterate(funcs, (jtableP_cb)hook_call1, &arg);
}

canonical_original_code:
void hook_call(char *name, struct args arg) {
 struct jtableP *funcs = get_funcs(name);
 if (!funcs)
  return;
 if (!strncmp(name, "hook_ontick", 12)) {
  logfmt(0x4000, "Calling hook %s" "\n", name);
 }
 jtableP_iterate(funcs, (void (*)(void *key, void *param))hook_call1, &arg);
}

variable_types: struct args { unsigned char c; struct funcarg { enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 } type; union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; } data; } v[20]; }


nextnum

decompiled_code:
char *nextnum()
{
char *result; // rax

if ( first_5 )
{
first_5 = 0;
result = num;
maxnum = 1LL;
}
else if ( (unsigned int)base64_incr(&num[2], 4LL) )
{
logtxt(16LL, "Numerics exhausted\n");
result = 0LL;
}
else
{
++maxnum;
result = num;
}
return result;
}

canonical_decompiled_code:
char *func0()
{
char *result; // rax

if ( first_5 )
{
first_5 = 0;
result = num;
maxnum = 1LL;
}
else if ( (unsigned int)base64_incr(&num[2], 4LL) )
{
logtxt(16LL, "Numerics exhausted\n");
result = 0LL;
}
else
{
++maxnum;
result = num;
}
return result;
}

original_code:
static char *nextnum(void) {
 static int first = 1;
 if (first) {
  first = 0;
  maxnum = 1;
  return num;
 }
 if (base64_incr(num + 2, 4)) {
  logtxt(0x0010, "Numerics exhausted" "\n");
  return ((void *)0);
 }
 maxnum++;
 return num;
}

canonical_original_code:
static char *nextnum() {
 static int first = 1;
 if (first) {
  first = 0;
  maxnum = 1;
  return num;
 }
 if (base64_incr(num + 2, 4)) {
  logtxt(0x0010, "Numerics exhausted" "\n");
  return ((void *)0);
 }
 maxnum++;
 return num;
}

variable_types: first int


decompiled_code:
__int64 __fastcall chancount_quakenet(unsigned int a1, int a2)
{
__int64 result; // rax
char v3; // r8

if ( a1 <= 0x14 )
return (unsigned int)(int)((double)a2 * data_quakenet[a1] / 29000.0);
v3 = rand();
result = 0LL;
if ( (v3 & 1) != 0 )
result = (unsigned int)(rand() % 25);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2)
{
__int64 result; // rax
char v3; // r8

if ( a1 <= 0x14 )
return (unsigned int)(int)((double)a2 * data_quakenet[a1] / 29000.0);
v3 = rand();
result = 0LL;
if ( (v3 & 1) != 0 )
result = (unsigned int)(rand() % 25);
return result;
}

original_code:
static int chancount_quakenet(int size, int total) {
 int chancount;
 if (size < sizeof(data_quakenet)/sizeof(*data_quakenet))
  chancount = (int)((total*data_quakenet[size]/(double)29000));
 else
  chancount = rand()%2 ? rand()%25 : 0;
 return chancount;
}

variable_types: size int

variable_types: total int

variable_types: chancount int


gethost

decompiled_code:
char *__fastcall gethost(unsigned int a1)
{
snprintf(host_3, 0x40uLL, "fake%d.fake.com", a1);
return host_3;
}

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1)
{
snprintf(host_3, 0x40uLL, "fake%d.fake.com", a1);
return host_3;
}

original_code:
static char *gethost(int i) {
 static char host[63 +1];
 snprintf(host, sizeof(host), "fake%d.fake.com", i);
 return host;
}

canonical_original_code:
static char *gethost(int i) {
 static char host[-1];
 snprintf(host, sizeof(host), "fake%d.fake.com", i);
 return host;
}

variable_types: i int

variable_types:
host
char [-1]


getident

decompiled_code:
char *__fastcall getident(unsigned int a1)
{
snprintf(ident_2, 0xBuLL, "f%d", a1);
return ident_2;
}

canonical_decompiled_code:
char *__fastcall func3(unsigned int a1)
{
snprintf(ident_2, 0xBuLL, "f%d", a1);
return ident_2;
}

original_code:
static char *getident(int i) {
 static char ident[10 +1];
 snprintf(ident, sizeof(ident), "f%d", i);
 return ident;
}

canonical_original_code:
static char *getident(int i) {
 static char ident[-1];
 snprintf(ident, sizeof(ident), "f%d", i);
 return ident;
}

variable_types:
ident
char [-1]


getnick

decompiled_code:
char *__fastcall getnick(unsigned int a1)
{
snprintf(nick_1, 0x10uLL, "fake%d", a1);
return nick_1;
}

canonical_decompiled_code:
char *__fastcall func4(unsigned int a1)
{
snprintf(nick_1, 0x10uLL, "fake%d", a1);
return nick_1;
}

original_code:
static char *getnick(int i) {
 static char nick[15 +1];
 snprintf(nick, sizeof(nick), "fake%d", i);
 return nick;
}

canonical_original_code:
static char *getnick(int i) {
 static char nick[-1];
 snprintf(nick, sizeof(nick), "fake%d", i);
 return nick;
}

variable_types:
nick
char [-1]


decompiled_code:
unsigned __int64 __fastcall burst_chanusers(__int64 a1, unsigned int a2)
{
__int64 v2; // r15
__int64 v3; // r13
char *v4; // rax
__int64 v5; // rbx
char *v6; // rbp
char *v7; // rsi
char *v9; // [rsp+0h] [rbp-258h]
char s[503]; // [rsp+10h] [rbp-248h] BYREF
char v11; // [rsp+207h] [rbp-51h] BYREF
unsigned __int64 v12; // [rsp+218h] [rbp-40h]

v2 = (unsigned int)(a1 - 1);
v12 = __readfsqword(0x28u);
v3 = randomset(a1, maxnum);
v4 = getchanmode_constprop_0();
v5 = 0LL;
v6 = &s[sprintf(s, "%s B #fake_%d_%d %ld %s", "FB", (unsigned int)a1, a2, mylink, v4)];
v9 = v6;
while ( 1 )
{
*(_WORD *)v6 = 16966;
base64_encode_padded(v6 + 2, 4LL, *(_QWORD *)(v3 + 8 * v5));
v7 = v6 + 5;
if ( v6 + 5 >= &v11 || (_DWORD)a1 - 1 == (_DWORD)v5 )
break;
if ( v2 == v5 )
return v12 - __readfsqword(0x28u);
if ( v9 != v7 )
{
v6[5] = 44;
v6 += 6;
goto LABEL_6;
}
LABEL_10:
v6 = v9;
LABEL_6:
++v5;
}
send_format("%.*s\r\n", v7 - s, s);
if ( v2 != v5 )
goto LABEL_10;
return v12 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1, unsigned int a2)
{
__int64 v2; // r15
__int64 v3; // r13
char *v4; // rax
__int64 v5; // rbx
char *v6; // rbp
char *v7; // rsi
char *v9; // [rsp+0h] [rbp-258h]
char s[503]; // [rsp+10h] [rbp-248h] BYREF
char v11; // [rsp+207h] [rbp-51h] BYREF
unsigned __int64 v12; // [rsp+218h] [rbp-40h]

v2 = (unsigned int)(a1 - 1);
v12 = __readfsqword(0x28u);
v3 = randomset(a1, maxnum);
v4 = func5();
v5 = 0LL;
v6 = &s[sprintf(s, "%s B #fake_%d_%d %ld %s", "FB", (unsigned int)a1, a2, mylink, v4)];
v9 = v6;
while ( 1 )
{
*(_WORD *)v6 = 16966;
base64_encode_padded(v6 + 2, 4LL, *(_QWORD *)(v3 + 8 * v5));
v7 = v6 + 5;
if ( v6 + 5 >= &v11 || (_DWORD)a1 - 1 == (_DWORD)v5 )
break;
if ( v2 == v5 )
return v12 - __readfsqword(0x28u);
if ( v9 != v7 )
{
v6[5] = 44;
v6 += 6;
goto LABEL_6;
}
LABEL_10:
v6 = v9;
LABEL_6:
++v5;
}
send_format("%.*s\r\n", v7 - s, s);
if ( v2 != v5 )
goto LABEL_10;
return v12 - __readfsqword(0x28u);
}

original_code:
static void burst_chanusers(int size, int id) {
 int j;
 long *rands;
 char buf[513], *t, *c;
 rands = randomset(size, maxnum);
 t = buf + sprintf(buf, "%s B #fake_%d_%d %ld %s", "FB", size, id, mylink, getchanmode(id));
 for (c = t, j = 0; j < size; j++) {
  if (c != t)
   *c++ = ',';
  *c++ = "FB"[0];
  *c++ = "FB"[1];
  base64_encode_padded(c, 4, rands[j]);
  c += 3;
  if (c >= buf + sizeof(buf) - 10 || j == size - 1) {
   send_format("%.*s" "\r\n", c-buf, buf);
   c = t;
  }
 }
}

canonical_original_code:
static void burst_chanusers(int size, int id) {
 int j;
 long *rands;
 char buf[513]; char *t; char *c;
 rands = randomset(size, maxnum);
 t = buf + sprintf(buf, "%s B #fake_%d_%d %ld %s", "FB", size, id, mylink, getchanmode(id));
 for (c = t, j = 0; j < size; j++) {
  if (c != t)
   *c++ = ',';
  *c++ = "FB"[0];
  *c++ = "FB"[1];
  base64_encode_padded(c, 4, rands[j]);
  c += 3;
  if (c >= buf + sizeof(buf) - 10 || j == size - 1) {
   send_format("%.*s" "\r\n", c-buf, buf);
   c = t;
  }
 }
}

variable_types: id int

variable_types: j int

variable_types:
rands
long *

variable_types:
buf
char [513]

variable_types:
t
char *

variable_types:
c
char *


decompiled_code:
__int64 __fastcall burst_channels(unsigned int a1, int a2)
{
unsigned int i; // ebx
unsigned int v4; // esi

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
v4 = i;
burst_chanusers(a1, v4);
}
}
return (unsigned int)a2;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, int a2)
{
unsigned int i; // ebx
unsigned int v4; // esi

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
v4 = i;
func6(a1, v4);
}
}
return (unsigned int)a2;
}

original_code:
static int burst_channels(int size, int count) {
 int i;
 for (i = 0; i < count; i++)
  burst_chanusers(size, i);
 return count;
}

variable_types: count int


decompiled_code:
unsigned __int64 __fastcall burster_burst_clients(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r13
__int64 v3; // rbx
char *v4; // r15
__int16 *v5; // r14
char *v6; // rax
__int64 v8; // [rsp-8h] [rbp-120h]
__int64 v9; // [rsp+8h] [rbp-110h]
char *v10; // [rsp+10h] [rbp-108h]
char *v11; // [rsp+18h] [rbp-100h]
char v12[7]; // [rsp+49h] [rbp-CFh] BYREF
char v13[32]; // [rsp+50h] [rbp-C8h] BYREF
char v14[32]; // [rsp+70h] [rbp-A8h] BYREF
char v15[72]; // [rsp+90h] [rbp-88h] BYREF
unsigned __int64 v16; // [rsp+D8h] [rbp-40h]

v16 = __readfsqword(0x28u);
v1 = randomset(a1, 800000LL);
if ( (int)a1 > 0 )
{
v2 = v1;
v3 = 0LL;
do
{
sprintf(v13, "fake%d", (unsigned int)v3);
sprintf(v14, "f%d", (unsigned int)v3);
sprintf(v15, "f%d:%ld:%d:0", (unsigned int)v3, now, (unsigned int)v3);
base64_encode_padded(v12, 7LL, *(_QWORD *)(v2 + 8 * v3) + 16843009LL);
v4 = nextnum();
v5 = getumode(v3);
v11 = gethost(v3);
v10 = getident(v3);
v9 = now;
v6 = getnick(v3);
v8 = v3++;
send_format(
"%s N %s 2 %ld %s %s %s %s %s :fake user number %d\r\n",
"FB",
v6,
v9,
v10,
v11,
(const char *)v5,
v12,
v4,
v8);
}
while ( v3 != (int)a1 );
}
return v16 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r13
__int64 v3; // rbx
char *v4; // r15
__int16 *v5; // r14
char *v6; // rax
__int64 v8; // [rsp-8h] [rbp-120h]
__int64 v9; // [rsp+8h] [rbp-110h]
char *v10; // [rsp+10h] [rbp-108h]
char *v11; // [rsp+18h] [rbp-100h]
char v12[7]; // [rsp+49h] [rbp-CFh] BYREF
char v13[32]; // [rsp+50h] [rbp-C8h] BYREF
char v14[32]; // [rsp+70h] [rbp-A8h] BYREF
char v15[72]; // [rsp+90h] [rbp-88h] BYREF
unsigned __int64 v16; // [rsp+D8h] [rbp-40h]

v16 = __readfsqword(0x28u);
v1 = randomset(a1, 800000LL);
if ( (int)a1 > 0 )
{
v2 = v1;
v3 = 0LL;
do
{
sprintf(v13, "fake%d", (unsigned int)v3);
sprintf(v14, "f%d", (unsigned int)v3);
sprintf(v15, "f%d:%ld:%d:0", (unsigned int)v3, now, (unsigned int)v3);
base64_encode_padded(v12, 7LL, *(_QWORD *)(v2 + 8 * v3) + 16843009LL);
v4 = func0();
v5 = getumode(v3);
v11 = func2(v3);
v10 = func3(v3);
v9 = now;
v6 = func4(v3);
v8 = v3++;
send_format(
"%s N %s 2 %ld %s %s %s %s %s :fake user number %d\r\n",
"FB",
v6,
v9,
v10,
v11,
(const char *)v5,
v12,
v4,
v8);
}
while ( v3 != (int)a1 );
}
return v16 - __readfsqword(0x28u);
}

original_code:
void burster_burst_clients(int max) {
 char ip[7], nick[32], ident[32], auth[64];
 int i;
 long *rands;
 rands = randomset(max, 800000);
 for (i = 0; i < max; i++) {
  sprintf(nick, "fake%d", i);
  sprintf(ident, "f%d", i);
  sprintf(auth, "f%d:%ld:%d:0", i, now, i);
  base64_encode_padded(ip, 7, 16843009+rands[i]);
  send_format("%s N %s 2 %ld %s %s %s %s %s :fake user number %d" "\r\n", "FB", getnick(i), now, getident(i), gethost(i), getumode(i), ip, nextnum(), i);
 }
}

canonical_original_code:
void burster_burst_clients(int max) {
 char ip[7]; char nick[32]; char ident[32]; char auth[64];
 int i;
 long *rands;
 rands = randomset(max, 800000);
 for (i = 0; i < max; i++) {
  sprintf(nick, "fake%d", i);
  sprintf(ident, "f%d", i);
  sprintf(auth, "f%d:%ld:%d:0", i, now, i);
  base64_encode_padded(ip, 7, 16843009+rands[i]);
  send_format("%s N %s 2 %ld %s %s %s %s %s :fake user number %d" "\r\n", "FB", getnick(i), now, getident(i), gethost(i), getumode(i), ip, nextnum(), i);
 }
}

variable_types: max int

variable_types:
ip
char [7]

variable_types:
nick
char [32]

variable_types:
ident
char [32]

variable_types:
auth
char [64]


decompiled_code:
unsigned __int64 __fastcall burster_burst_channels(int a1, __int64 (__fastcall *a2)(_QWORD, _QWORD))
{
int v3; // ebp
unsigned int v4; // ebx
int v5; // eax
unsigned int v6; // edi
unsigned __int64 v8; // [rsp+8h] [rbp-30h]

v8 = __readfsqword(0x28u);
if ( a1 > 0 )
{
v3 = 0;
v4 = 1;
do
{
v5 = a2(v4, (unsigned int)a1);
v6 = v4++;
v3 += burst_channels(v6, v5);
}
while ( a1 > v3 );
}
return v8 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(int a1, __int64 (__fastcall *a2)(_QWORD, _QWORD))
{
int v3; // ebp
unsigned int v4; // ebx
int v5; // eax
unsigned int v6; // edi
unsigned __int64 v8; // [rsp+8h] [rbp-30h]

v8 = __readfsqword(0x28u);
if ( a1 > 0 )
{
v3 = 0;
v4 = 1;
do
{
v5 = a2(v4, (unsigned int)a1);
v6 = v4++;
v3 += func7(v6, v5);
}
while ( a1 > v3 );
}
return v8 - __readfsqword(0x28u);
}

original_code:
void burster_burst_channels(int max, int (*count_by_size)(int size, int total)) {
 int size, i;
 for (i = 0, size = 1; i < max; size++) {
  i += burst_channels(size, count_by_size(size, max));
 }
}

canonical_original_code:
void burster_burst_channels(int max, int (*count_by_size)(int size, int total)) {
 int size; int i;
 for (i = 0, size = 1; i < max; size++) {
  i += burst_channels(size, count_by_size(size, max));
 }
}

variable_types: size int


decompiled_code:
__int64 burster_go()
{
mylink = now;
send_format(
"%s S burster.metairc.net 2 0 %ld J10 %s]]] +sn :Mass fake server\r\n",
(const char *)(me + 24LL),
now,
"FB");
burster_burst_clients(100000LL);
burster_burst_channels(40000, (__int64 (__fastcall *)(_QWORD, _QWORD))chancount_quakenet);
send_format("%s EB\r\n", "FB");
return send_format("%s EA\r\n", "FB");
}

canonical_decompiled_code:
__int64 func10()
{
mylink = now;
send_format(
"%s S burster.metairc.net 2 0 %ld J10 %s]]] +sn :Mass fake server\r\n",
(const char *)(me + 24LL),
now,
"FB");
func8(100000LL);
func9(40000, (__int64 (__fastcall *)(_QWORD, _QWORD))chancount_quakenet);
send_format("%s EB\r\n", "FB");
return send_format("%s EA\r\n", "FB");
}

original_code:
void burster_go(void) {
 mylink = now;
 send_format("%s S burster.metairc.net 2 0 %ld J10 %s]]] +sn :Mass fake server" "\r\n", (me->numericstr), mylink, "FB");
 burster_burst_clients(100000);
 burster_burst_channels(40000, chancount_quakenet);
 send_format("%s EB" "\r\n", "FB");
 send_format("%s EA" "\r\n", "FB");
}

canonical_original_code:
void burster_go() {
 mylink = now;
 send_format("%s S burster.metairc.net 2 0 %ld J10 %s]]] +sn :Mass fake server" "\r\n", (me->numericstr), mylink, "FB");
 burster_burst_clients(100000);
 burster_burst_channels(40000, chancount_quakenet);
 send_format("%s EB" "\r\n", "FB");
 send_format("%s EA" "\r\n", "FB");
}


decompiled_code:
__int64 init_burster()
{
return hook_hook("onregistered", burster_go);
}

canonical_decompiled_code:
__int64 func11()
{
return hook_hook("onregistered", burster_go);
}

original_code:
void init_burster(void) {
 hook_hook("onregistered", burster_go);
 return;
}

canonical_original_code:
void init_burster() {
 hook_hook("onregistered", burster_go);
 return;
}


decompiled_code:
__int64 __fastcall server_modehook(__int64 a1, _DWORD *a2, int a3, char a4)
{
__int64 result; // rax

if ( *a2 == 43065 )
{
if ( (_DWORD *)uplink == a2 && a4 == 110 )
{
if ( a3 )
uplink_with_opername();
else
uplink_without_opername();
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
logtxt(16LL, "Mode change for not-a-server!\n");
result = 4294967293LL;
}
return result;
}

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

if ( *a2 == 43065 )
{
if ( (_DWORD *)uplink == a2 && a4 == 110 )
{
if ( a3 )
uplink_with_opername();
else
uplink_without_opername();
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
logtxt(16LL, "Mode change for not-a-server!\n");
result = 4294967293LL;
}
return result;
}

original_code:
static int server_modehook(struct entity *from, struct entity *target, int pls, char modechange, char *param) {
 struct server *s;
 s = (struct server *)target;
 if (!(((struct entity *)(s))->magic == 0xA839)) {
  logtxt(0x0010, "Mode change for not-a-server!" "\n");
  return -3;
 }
 if (s != uplink)
  return 0;
 if (modechange == 'n')
  pls ? uplink_with_opername() : uplink_without_opername();
 return 0;
}

variable_types:
from
struct entity { unsigned int magic; } *

variable_types:
target
struct entity *

variable_types: pls int

variable_types: modechange char

variable_types:
param
char *

variable_types: struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP { void *t; } users; unsigned long mode; } *


decompiled_code:
__int64 __fastcall get_server_by_numeric(__int64 a1)
{
return jtableL_get(&serverlist, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return jtableL_get(&serverlist, a1);
}

original_code:
struct server *get_server_by_numeric(unsigned long numeric) {
 return jtableL_get(&serverlist, numeric);
}

variable_types:
numeric
unsigned long

return_type: struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP { void *t; } users; unsigned long mode; } *


decompiled_code:
__int64 get_server_by_numericstr()
{
__int64 v0; // rdi

v0 = str2snum();
return get_server_by_numeric(v0);
}

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

v0 = str2snum();
return func1(v0);
}

original_code:
struct server *get_server_by_numericstr(const char *numeric) {
 return get_server_by_numeric(str2snum(numeric));
}

canonical_original_code:
struct server *get_server_by_numericstr(char *numeric) {
 return get_server_by_numeric(str2snum(numeric));
}

variable_types:
numeric
char *


original_code:
struct server *add_server(char *numeric, char *maxusers, char *name, int hops, time_t boot, time_t link, char *protocol, char *description) {
 struct server *s;
 s = zmalloc(sizeof(*s));
 s->magic = 0xA839;
 strncpyz((s->numericstr), (numeric), sizeof(s->numericstr));
 s->numeric = str2snum(numeric);
 s->maxusers = base64_decode_long(maxusers, 3);
 strncpyz((s->name), (name), sizeof(s->name));
 s->hops = hops;
 s->boot = boot;
 s->link = link;
 s->lastnumeric = s->numeric * 64 * 64 * 64 + s->maxusers;
 strncpyz((s->protocol), (protocol), sizeof(s->protocol));
 strncpyz((s->description), (description), sizeof(s->description));
 if (!me)
  me = s;
 else if (!uplink) {
  uplink = s;
  set_registered(1);
 }
 return jtableL_insert(&serverlist, s->numeric, s);
}

canonical_original_code:
struct server *add_server(char *numeric, char *maxusers, char *name, int hops, long boot, long link, char *protocol, char *description) {
 struct server *s;
 s = zmalloc(sizeof(*s));
 s->magic = 0xA839;
 strncpyz((s->numericstr), (numeric), sizeof(s->numericstr));
 s->numeric = str2snum(numeric);
 s->maxusers = base64_decode_long(maxusers, 3);
 strncpyz((s->name), (name), sizeof(s->name));
 s->hops = hops;
 s->boot = boot;
 s->link = link;
 s->lastnumeric = s->numeric * 64 * 64 * 64 + s->maxusers;
 strncpyz((s->protocol), (protocol), sizeof(s->protocol));
 strncpyz((s->description), (description), sizeof(s->description));
 if (!me)
  me = s;
 else if (!uplink) {
  uplink = s;
  set_registered(1);
 }
 return jtableL_insert(&serverlist, s->numeric, s);
}

variable_types:
maxusers
char *

variable_types:
name
char *

variable_types: hops int

variable_types: boot long

variable_types: link long

variable_types:
protocol
char *

variable_types:
description
char *


decompiled_code:
unsigned __int64 __fastcall server_add_user(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
jtableP_set(a1 + 288);
*(_QWORD *)(a1 + 16) = *(_QWORD *)(a2 + 8);
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
jtableP_set(a1 + 288);
*(_QWORD *)(a1 + 16) = *(_QWORD *)(a2 + 8);
return v3 - __readfsqword(0x28u);
}

original_code:
void server_add_user(struct server *s, struct user *u) {
 jtableP_set(&s->users, u);
 s->lastnumeric = u->numeric;
}

variable_types: struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP channels; struct server *server; } *


decompiled_code:
__int64 __fastcall server_del_user(__int64 a1)
{
return jtableP_unset(a1 + 288);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return jtableP_unset(a1 + 288);
}

original_code:
void server_del_user(struct server *s, struct user *u) {
 jtableP_unset(&s->users, u);
}


decompiled_code:
void __fastcall del_server(void *ptr)
{
__int64 v1; // rax
__int64 v2; // rdx
_BYTE v3[328]; // [rsp-148h] [rbp-2B8h] BYREF
_BYTE v4[328]; // [rsp+8h] [rbp-168h] BYREF
unsigned __int64 v5; // [rsp+150h] [rbp-20h]

v5 = __readfsqword(0x28u);
v1 = arg_ptr();
pack_args(v4, v1, v2, 0LL, 0LL);
qmemcpy(v3, v4, sizeof(v3));
hook_call("onserverdel");
jtableP_iterate((char *)ptr + 288, &del_user_iter, 0LL);
jtableL_remove(&serverlist, *((_QWORD *)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
__int64 v1; // rax
__int64 v2; // rdx
_BYTE v3[328]; // [rsp-148h] [rbp-2B8h] BYREF
_BYTE v4[328]; // [rsp+8h] [rbp-168h] BYREF
unsigned __int64 v5; // [rsp+150h] [rbp-20h]

v5 = __readfsqword(0x28u);
v1 = arg_ptr();
pack_args(v4, v1, v2, 0LL, 0LL);
qmemcpy(v3, v4, sizeof(v3));
hook_call("onserverdel");
jtableP_iterate((char *)ptr + 288, &del_user_iter, 0LL);
jtableL_remove(&serverlist, *((_QWORD *)ptr + 1));
free(ptr);
}

original_code:
void del_server(struct server *server) {
 hook_call("onserverdel", pack_args(arg_ptr(server), (struct funcarg) {.type = ARGTYPE_NONE}));
 jtableP_iterate(&server->users, del_user_iter, ((void *)0));
 jtableL_remove(&serverlist, server->numeric);
 free(server);
}


decompiled_code:
__int64 __fastcall server_apply_mode(__int64 a1, _DWORD *a2, __int64 a3, __int64 a4, unsigned int a5)
{
unsigned __int64 v6; // [rsp+8h] [rbp-10h]

v6 = __readfsqword(0x28u);
if ( *a2 != 43065 )
return logtxt(256LL, "Mode change on non-channel\n");
mode_apply(a1, a2, a2 + 74, a3, a4, a5, server_modehook);
return v6 - __readfsqword(0x28u);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _DWORD *a2, __int64 a3, __int64 a4, unsigned int a5)
{
unsigned __int64 v6; // [rsp+8h] [rbp-10h]

v6 = __readfsqword(0x28u);
if ( *a2 != 43065 )
return logtxt(256LL, "Mode change on non-channel\n");
mode_apply(a1, a2, a2 + 74, a3, a4, a5, server_modehook);
return v6 - __readfsqword(0x28u);
}

original_code:
void server_apply_mode(struct entity *from, struct entity *target, char *modechanges, struct manyargs *arg, int skip) {
 if (!(((struct entity *)(target))->magic == 0xA839)) {
  logtxt(0x0100, "Mode change on non-channel" "\n");
  return;
 }
 mode_apply(from, target, &((struct server *)target)->mode, modechanges, arg, skip, server_modehook);
}

variable_types:
modechanges
char *

variable_types: struct manyargs { unsigned char c; char *v[256]; } *

variable_types: skip int


decompiled_code:
__int64 __fastcall server_freenum(_QWORD *a1)
{
__int64 v1; // r12
__int64 v2; // rax

v1 = a1[2];
do
{
v2 = a1[1] << 18;
if ( v2 + a1[12] != v1 )
v2 = v1 + 1;
v1 = v2;
}
while ( get_user_by_numeric(v2) );
return v1;
}

original_code:
unsigned long server_freenum(struct server *s) {
 unsigned long numeric = s->lastnumeric;
 do {
  if (numeric == s->numeric * 64 * 64 * 64 + s->maxusers)
   numeric = s->numeric * 64 * 64 * 64;
  else
   numeric++;
 } while (get_user_by_numeric(numeric));
 return numeric;
}

return_type: unsigned long


decompiled_code:
unsigned __int64 __fastcall add_token_rule(__int64 a1, _BYTE *a2)
{
_BYTE *v2; // rbp
unsigned __int8 v3; // al
__int64 v4; // rbx
const char *v5; // rsi
__int64 v6; // rdi
unsigned __int8 v8[2056]; // [rsp+0h] [rbp-828h] BYREF
unsigned __int64 v9; // [rsp+808h] [rbp-20h]

v2 = a2 + 8;
v9 = __readfsqword(0x28u);
rfc_split(v8, a1);
v3 = v8[0];
*a2 = v8[0];
if ( v3 )
{
v4 = 0LL;
do
{
v5 = *(const char **)&v8[8 * v4 + 8];
v6 = (__int64)v2;
++v4;
v2 += 16;
parse_argrule(v6, v5);
}
while ( v8[0] > (int)v4 );
}
return v9 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, _BYTE *a2)
{
_BYTE *v2; // rbp
unsigned __int8 v3; // al
__int64 v4; // rbx
const char *v5; // rsi
__int64 v6; // rdi
unsigned __int8 v8[2056]; // [rsp+0h] [rbp-828h] BYREF
unsigned __int64 v9; // [rsp+808h] [rbp-20h]

v2 = a2 + 8;
v9 = __readfsqword(0x28u);
rfc_split(v8, a1);
v3 = v8[0];
*a2 = v8[0];
if ( v3 )
{
v4 = 0LL;
do
{
v5 = *(const char **)&v8[8 * v4 + 8];
v6 = (__int64)v2;
++v4;
v2 += 16;
func0(v6, v5);
}
while ( v8[0] > (int)v4 );
}
return v9 - __readfsqword(0x28u);
}

original_code:
void add_token_rule(char *rulestr, struct parserule *r) {
 struct manyargs arg;
 int i;
 rfc_split(&arg, rulestr);
 r->c = arg.c;
 for (i = 0; i < arg.c; i++)
  parse_argrule(r->r + i, arg.v[i]);
}

variable_types:
rulestr
char *

variable_types: struct parserule { unsigned char c; struct argrule { char offset; unsigned char flags; void (*convert)(struct funcarg { enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 } type; union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; } data; } *dest, char *str); } r[20]; } *

variable_types: struct manyargs { unsigned char c; char *v[256]; }

variable_types: i int

user_defined_types: struct parserule { unsigned char c; struct argrule r[20]; }

user_defined_types: struct argrule { char offset; unsigned char flags; void (*convert)(struct funcarg *dest, char *str); }


decompiled_code:
__int64 __fastcall add_token(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v9; // rbp

v9 = zmalloc(672LL);
add_token_rule(a3, (_BYTE *)v9);
*(_QWORD *)(v9 + 656) = a5;
if ( a6 )
{
add_token_rule(a4, (_BYTE *)(v9 + 328));
*(_QWORD *)(v9 + 664) = a6;
}
if ( a1 )
add_tokeninfo(a1, v9);
return add_tokeninfo(a2, v9);
}

original_code:
void add_token(char *shortname, char *name, char *rulestr1, char *rulestr2, void (*handler1)(void), void (*handler2)(void)) {
 struct tokeninfo *t;
 t = zmalloc(sizeof(*t));
 add_token_rule(rulestr1, &t->rules[0]);
 t->handlers[0] = handler1;
 if (handler2) {
  add_token_rule(rulestr2, &t->rules[1]);
  t->handlers[1] = handler2;
 }
 if (shortname)
  add_tokeninfo(shortname, t);
 add_tokeninfo(name, t);
}

canonical_original_code:
void add_token(char *shortname, char *name, char *rulestr1, char *rulestr2, void (*handler1)(), void (*handler2)()) {
 struct tokeninfo *t;
 t = zmalloc(sizeof(*t));
 add_token_rule(rulestr1, &t->rules[0]);
 t->handlers[0] = handler1;
 if (handler2) {
  add_token_rule(rulestr2, &t->rules[1]);
  t->handlers[1] = handler2;
 }
 if (shortname)
  add_tokeninfo(shortname, t);
 add_tokeninfo(name, t);
}

variable_types:
shortname
char *

variable_types: struct tokeninfo { struct parserule { unsigned char c; struct argrule { char offset; unsigned char flags; void (*convert)(struct funcarg { enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 } type; union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; } data; } *dest, char *str); } r[20]; } rules[2]; void (*handlers[2])(); } *

user_defined_types: struct tokeninfo { struct parserule rules[2]; void (*handlers[2])(); }


original_code:
void init_tokens(void) {
 int i = -1;
 while (rawrules[++i].name)
  add_token(rawrules[i].shortname, rawrules[i].name, rawrules[i].rule1, rawrules[i].rule2, rawrules[i].handler1, rawrules[i].handler2);
}

canonical_original_code:
void init_tokens() {
 int i = -1;
 while (rawrules[++i].name)
  add_token(rawrules[i].shortname, rawrules[i].name, rawrules[i].rule1, rawrules[i].rule2, rawrules[i].handler1, rawrules[i].handler2);
}


decompiled_code:
unsigned __int64 __fastcall set_registered(int a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
registered = a1;
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(int a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
registered = a1;
return v2 - __readfsqword(0x28u);
}

original_code:
void set_registered(int reg) {
 registered = reg;
}

variable_types: reg int


decompiled_code:
unsigned __int64 __fastcall handle_input(const char *a1)
{
int v1; // ebx
__int64 v2; // r13
__int64 v3; // r12
int v4; // ebx
__int64 v5; // rbp
__int64 v6; // r14
const char *v8; // rdx
char v9[8]; // [rsp+0h] [rbp-848h] BYREF
const char *v10; // [rsp+8h] [rbp-840h] BYREF
const char *v11; // [rsp+10h] [rbp-838h]
unsigned __int64 v12; // [rsp+808h] [rbp-40h]

v1 = registered;
v12 = __readfsqword(0x28u);
rfc_split(v9, a1);
if ( !v9[0] )
return v12 - __readfsqword(0x28u);
if ( registered )
{
if ( v9[0] == 1 )
{
logfmt(256LL, "Input message '%s' has no token\n", a1);
return v12 - __readfsqword(0x28u);
}
v2 = (__int64)v10;
v3 = get_tokeninfo(v11);
if ( v3 )
goto LABEL_5;
LABEL_12:
if ( registered )
v8 = v11;
else
v8 = v10;
logfmt(256LL, "Unknown token: %s\n", v8);
return v12 - __readfsqword(0x28u);
}
v2 = 0LL;
v3 = get_tokeninfo(v10);
if ( !v3 )
goto LABEL_12;
LABEL_5:
v4 = v1 + 1;
v5 = arrange_args((unsigned int)(unsigned __int8)v9[0] - v4, &(&v10)[v4], v3);
if ( v5 )
{
v6 = *(_QWORD *)(v3 + 656);
}
else
{
v6 = *(_QWORD *)(v3 + 664);
if ( !v6 || (v5 = arrange_args((unsigned int)(unsigned __int8)v9[0] - v4, &(&v10)[v4], v3 + 328)) == 0 )
{
logtxt(256LL, "Failed to deal with last input\n");
return v12 - __readfsqword(0x28u);
}
}
shift(v5, 1LL);
if ( v2 )
{
convert_num(v5 + 8, v2);
}
else
{
*(_DWORD *)(v5 + 8) = 10;
*(_QWORD *)(v5 + 16) = 0LL;
}
call_varargs(v6, v5);
return v12 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(const char *a1)
{
int v1; // ebx
__int64 v2; // r13
__int64 v3; // r12
int v4; // ebx
__int64 v5; // rbp
__int64 v6; // r14
const char *v8; // rdx
char v9[8]; // [rsp+0h] [rbp-848h] BYREF
const char *v10; // [rsp+8h] [rbp-840h] BYREF
const char *v11; // [rsp+10h] [rbp-838h]
unsigned __int64 v12; // [rsp+808h] [rbp-40h]

v1 = registered;
v12 = __readfsqword(0x28u);
rfc_split(v9, a1);
if ( !v9[0] )
return v12 - __readfsqword(0x28u);
if ( registered )
{
if ( v9[0] == 1 )
{
logfmt(256LL, "Input message '%s' has no token\n", a1);
return v12 - __readfsqword(0x28u);
}
v2 = (__int64)v10;
v3 = get_tokeninfo(v11);
if ( v3 )
goto LABEL_5;
LABEL_12:
if ( registered )
v8 = v11;
else
v8 = v10;
logfmt(256LL, "Unknown token: %s\n", v8);
return v12 - __readfsqword(0x28u);
}
v2 = 0LL;
v3 = get_tokeninfo(v10);
if ( !v3 )
goto LABEL_12;
LABEL_5:
v4 = v1 + 1;
v5 = arrange_args((unsigned int)(unsigned __int8)v9[0] - v4, &(&v10)[v4], v3);
if ( v5 )
{
v6 = *(_QWORD *)(v3 + 656);
}
else
{
v6 = *(_QWORD *)(v3 + 664);
if ( !v6 || (v5 = arrange_args((unsigned int)(unsigned __int8)v9[0] - v4, &(&v10)[v4], v3 + 328)) == 0 )
{
logtxt(256LL, "Failed to deal with last input\n");
return v12 - __readfsqword(0x28u);
}
}
shift(v5, 1LL);
if ( v2 )
{
convert_num(v5 + 8, v2);
}
else
{
*(_DWORD *)(v5 + 8) = 10;
*(_QWORD *)(v5 + 16) = 0LL;
}
call_varargs(v6, v5);
return v12 - __readfsqword(0x28u);
}

original_code:
void handle_input(char *str) {
 struct manyargs raw;
 struct args *arg;
 struct tokeninfo *info;
 char *from;
 void (*handler)();
 int skipargs = 1 + registered;
 rfc_split(&raw, str);
 if (!raw.c)
  return;
 if (registered && raw.c < 2) {
  logfmt(0x0100, "Input message '%s' has no token" "\n", str);
  return;
 }
 from = registered ? raw.v[0] : ((void *)0);
 info = get_tokeninfo(registered ? raw.v[1] : raw.v[0]);
 if (!info) {
  logfmt(0x0100, "Unknown token: %s" "\n", registered ? raw.v[1] : raw.v[0]);
  return;
 }
 arg = arrange_args(raw.c - skipargs, raw.v + skipargs, &info->rules[0]);
 handler = info->handlers[0];
 if (!arg) {
  handler = info->handlers[1];
  if (handler)
   arg = arrange_args(raw.c - skipargs, raw.v + skipargs, &info->rules[1]);
 }
 if (!arg) {
  logtxt(0x0100, "Failed to deal with last input" "\n");
  return;
 }
 shift(arg, 1);
 if (from)
  convert_num(&arg->v[0], from);
 else {
  arg->v[0].type = ARGTYPE_PTR;
  arg->v[0].data.p = ((void *)0);
 }
 call_varargs(handler, arg);
}

variable_types:
str
char *

variable_types: struct args { unsigned char c; struct funcarg { enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 } type; union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; } data; } v[20]; } *

variable_types:
from
char *

variable_types:
handler
void (*)()

variable_types: skipargs int

user_defined_types: struct manyargs { unsigned char c; char *v[256]; }


decompiled_code:
__int64 __fastcall command_find(char *s2)
{
int v1; // ebx
const char **v2; // rbp

v1 = 0;
v2 = (const char **)commands;
do
{
if ( *v2 && !strcasecmp(*v2, s2) )
return commands[4 * v1 + 3];
++v1;
v2 += 4;
}
while ( v1 != 32 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s2)
{
int v1; // ebx
const char **v2; // rbp

v1 = 0;
v2 = (const char **)commands;
do
{
if ( *v2 && !strcasecmp(*v2, s2) )
return commands[4 * v1 + 3];
++v1;
v2 += 4;
}
while ( v1 != 32 );
return 0LL;
}

original_code:
cmdfunc command_find(char *trigger) {
 for (int x = 0; x < 32; x++) {
  if (commands[x].trigger != ((void *)0) && !strcasecmp(commands[x].trigger, trigger)) {
   return commands[x].cmdptr;
  }
 }
 return ((void *)0);
}

canonical_original_code:
int (*command_find(char *trigger))(struct user *, struct user *, struct manyargs *) {
 for (int x = 0; x < 32; x++) {
  if (commands[x].trigger != ((void *)0) && !strcasecmp(commands[x].trigger, trigger)) {
   return commands[x].cmdptr;
  }
 }
 return ((void *)0);
}

variable_types:
trigger
char *

variable_types: x int

return_type: int (*)(struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP { void *t; } channels; struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP users; unsigned long mode; } *server; } *, struct user *, struct manyargs { unsigned char c; char *v[256]; } *)


onprivmsg

decompiled_code:
unsigned __int64 __fastcall onprivmsg(__int64 a1, __int64 a2, __int64 a3)
{
void (__fastcall *v5)(__int64, __int64, char *); // r14
char v6[8]; // [rsp+0h] [rbp-A48h] BYREF
char *s2; // [rsp+8h] [rbp-A40h]
char v8[520]; // [rsp+810h] [rbp-238h] BYREF
unsigned __int64 v9; // [rsp+A18h] [rbp-30h]

v9 = __readfsqword(0x28u);
if ( !strcmp((const char *)(a2 + 16), (const char *)(bot + 16LL)) )
{
strncpyz(v8, a3, 513LL);
split(v6, v8, 32LL);
if ( v6[0] && (v5 = (void (__fastcall *)(__int64, __int64, char *))command_find(s2), v6[0]) && command_find(s2) )
v5(a1, a2, v6);
else
module_notice(bot, a1 + 16, "Unknown command %s. Use SHOWCOMMANDS to view all commands.", s2);
}
return v9 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
void (__fastcall *v5)(__int64, __int64, char *); // r14
char v6[8]; // [rsp+0h] [rbp-A48h] BYREF
char *s2; // [rsp+8h] [rbp-A40h]
char v8[520]; // [rsp+810h] [rbp-238h] BYREF
unsigned __int64 v9; // [rsp+A18h] [rbp-30h]

v9 = __readfsqword(0x28u);
if ( !strcmp((const char *)(a2 + 16), (const char *)(bot + 16LL)) )
{
strncpyz(v8, a3, 513LL);
split(v6, v8, 32LL);
if ( v6[0] && (v5 = (void (__fastcall *)(__int64, __int64, char *))func1(s2), v6[0]) && func1(s2) )
v5(a1, a2, v6);
else
module_notice(bot, a1 + 16, "Unknown command %s. Use SHOWCOMMANDS to view all commands.", s2);
}
return v9 - __readfsqword(0x28u);
}

original_code:
void onprivmsg(struct user *from, struct user *to, char *msg) {
 if (!strcmp(to->numericstr, bot->numericstr)) {
  char message[513];
  struct manyargs arg;
  strncpyz((message), (msg), sizeof(message));
  split(&arg, message, ' ');
  cmdfunc cmd = (arg.c == 0 ? ((void *)0) : command_find(arg.v[0]));
  if (arg.c == 0 || !command_find(arg.v[0])) {
   module_notice(bot, from->numericstr, "Unknown command %s. Use SHOWCOMMANDS to view all commands.", arg.v[0]);
  } else {
   cmd(from, to, &arg);
  }
 }
}

canonical_original_code:
void onprivmsg(struct user *from, struct user *to, char *msg) {
 if (!strcmp(to->numericstr, bot->numericstr)) {
  char message[513];
  struct manyargs arg;
  strncpyz((message), (msg), sizeof(message));
  split(&arg, message, ' ');
  int (*cmd)(struct user *, struct user *, struct manyargs *) = (arg.c == 0 ? ((void *)0) : command_find(arg.v[0]));
  if (arg.c == 0 || !command_find(arg.v[0])) {
   module_notice(bot, from->numericstr, "Unknown command %s. Use SHOWCOMMANDS to view all commands.", arg.v[0]);
  } else {
   cmd(from, to, &arg);
  }
 }
}

variable_types:
to
struct user *

variable_types:
msg
char *

variable_types:
message
char [513]

variable_types: int (*)(struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP { void *t; } channels; struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP users; unsigned long mode; } *server; } *, struct user *, struct manyargs { unsigned char c; char *v[256]; } *)


decompiled_code:
unsigned __int64 __fastcall command_register(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_QWORD *v6; // rax
int v7; // edx
_QWORD *v8; // rdx
unsigned __int64 v10; // [rsp+8h] [rbp-10h]

v10 = __readfsqword(0x28u);
if ( commands[0] )
{
v6 = &commands[4];
v7 = 0;
do
{
v6 += 4;
++v7;
}
while ( *(v6 - 4) );
}
else
{
v7 = 0;
}
v8 = &commands[4 * v7];
*v8 = a1;
v8[1] = a2;
v8[2] = a3;
v8[3] = a4;
return v10 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_QWORD *v6; // rax
int v7; // edx
_QWORD *v8; // rdx
unsigned __int64 v10; // [rsp+8h] [rbp-10h]

v10 = __readfsqword(0x28u);
if ( commands[0] )
{
v6 = &commands[4];
v7 = 0;
do
{
v6 += 4;
++v7;
}
while ( *(v6 - 4) );
}
else
{
v7 = 0;
}
v8 = &commands[4 * v7];
*v8 = a1;
v8[1] = a2;
v8[2] = a3;
v8[3] = a4;
return v10 - __readfsqword(0x28u);
}

original_code:
void command_register(char *trigger, char *syntax, char *description, cmdfunc command) {
 int x = 0;
 for (; commands[x].trigger != ((void *)0); x++);
 commands[x].trigger = trigger;
 commands[x].syntax = syntax;
 commands[x].description = description;
 commands[x].cmdptr = command;
}

canonical_original_code:
void command_register(char *trigger, char *syntax, char *description, int (*command)(struct user *, struct user *, struct manyargs *)) {
 int x = 0;
 for (; commands[x].trigger != ((void *)0); x++);
 commands[x].trigger = trigger;
 commands[x].syntax = syntax;
 commands[x].description = description;
 commands[x].cmdptr = command;
}

variable_types:
syntax
char *

variable_types:
description
char *


logfmtva

decompiled_code:
int __fastcall logfmtva(__int16 a1, const char *a2, void *a3)
{
__int64 v3; // rax
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

v5 = __readfsqword(0x28u);
if ( (a1 & 0x5511) == 0 )
return v5 - __readfsqword(0x28u);
LODWORD(v3) = vfprintf(stderr, a2, a3);
return v3;
}

canonical_decompiled_code:
int __fastcall func0(__int16 a1, const char *a2, void *a3)
{
__int64 v3; // rax
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

v5 = __readfsqword(0x28u);
if ( (a1 & 0x5511) == 0 )
return v5 - __readfsqword(0x28u);
LODWORD(v3) = vfprintf(stderr, a2, a3);
return v3;
}

original_code:
void logfmtva(int loglevel, const char *fmt, va_list ap) {
 if (!(debuglvl & loglevel))
  return;
 vfprintf(stderr, fmt, ap);
}

canonical_original_code:
void logfmtva(int loglevel, char *fmt, __builtin_va_list ap) {
 if (!(debuglvl & loglevel))
  return;
 vfprintf(stderr, fmt, ap);
}

variable_types: loglevel int

variable_types:
fmt
char *


logfmt

decompiled_code:
unsigned __int64 logfmt(__int16 a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-D8h] BYREF
unsigned __int64 v4; // [rsp+18h] [rbp-C0h]

va_start(va, a2);
v4 = __readfsqword(0x28u);
logfmtva(a1, a2, va);
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func1(__int16 a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-D8h] BYREF
unsigned __int64 v4; // [rsp+18h] [rbp-C0h]

va_start(va, a2);
v4 = __readfsqword(0x28u);
func0(a1, a2, va);
return v4 - __readfsqword(0x28u);
}

original_code:
void logfmt(int loglevel, const char *fmt, ...) {
 va_list ap;
 __builtin_va_start(ap,fmt);
 logfmtva(loglevel, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void logfmt(int loglevel, char *fmt, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 logfmtva(loglevel, fmt, ap);
 __builtin_va_end(ap);
}


logtxt

decompiled_code:
int __fastcall logtxt(__int16 a1, const char *a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
if ( (a1 & 0x5511) == 0 )
return v4 - __readfsqword(0x28u);
LODWORD(v2) = fprintf(stderr, a2);
return v2;
}

canonical_decompiled_code:
int __fastcall func2(__int16 a1, const char *a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
if ( (a1 & 0x5511) == 0 )
return v4 - __readfsqword(0x28u);
LODWORD(v2) = fprintf(stderr, a2);
return v2;
}

original_code:
void logtxt(int loglevel, const char *text) {
 if (!(debuglvl & loglevel))
  return;
 fprintf(stderr, text);
}

canonical_original_code:
void logtxt(int loglevel, char *text) {
 if (!(debuglvl & loglevel))
  return;
 fprintf(stderr, text);
}

variable_types:
text
char *


init

decompiled_code:
__int64 init()
{
init_hooks();
init_base64();
init_stringutils();
init_tokens();
init_modes();
return hook_hook("onregistered", &module_loadAll);
}

canonical_decompiled_code:
__int64 func0()
{
init_hooks();
init_base64();
init_stringutils();
init_tokens();
init_modes();
return hook_hook("onregistered", &module_loadAll);
}

original_code:
static void init(void) {
 init_hooks();
 init_base64();
 init_stringutils();
 init_tokens();
 init_modes();
 hook_hook("onregistered", module_loadAll);
}

canonical_original_code:
static void init() {
 init_hooks();
 init_base64();
 init_stringutils();
 init_tokens();
 init_modes();
 hook_hook("onregistered", module_loadAll);
}