decompiled_code:
unsigned __int64 init_hooks()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
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");
hook_register((__int64)"onchanneldel");
return v1 - __readfsqword(0x28u);
}

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

v1 = __readfsqword(0x28u);
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");
func0((__int64)"onchanneldel");
return v1 - __readfsqword(0x28u);
}

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


repo: thommey/plservices

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

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

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

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

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

variable_types:
f
void (*)()

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

return_type: void


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

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

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

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

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; // rbp
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; // rbp
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]; }

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

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


nextnum

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

if ( first_5 )
{
first_5 = 0;
maxnum = 1LL;
result = num;
}
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;
maxnum = 1LL;
result = num;
}
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

return_type: char *


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

v13 = __readfsqword(0x28u);
v2 = randomset(a1, maxnum);
v3 = getchanmode();
v4 = &s[sprintf(s, "%s B #fake_%d_%d %ld %s", "FB", (unsigned int)a1, a2, mylink, v3)];
v10 = v4;
if ( (int)a1 > 0 )
{
v5 = (unsigned int)(a1 - 1);
v6 = v4;
for ( i = 0LL; ; ++i )
{
*v6 = 70;
v6[1] = 66;
base64_encode_padded(v6 + 2, 4LL, *(_QWORD *)(v2 + 8 * i));
v8 = v6 + 5;
if ( v6 + 5 >= &v12 || (_DWORD)a1 - 1 == (_DWORD)i )
{
send_format("%.*s\r\n", v8 - s);
if ( i == v5 )
return v13 - __readfsqword(0x28u);
v6 = v10;
}
else
{
if ( i == v5 )
return v13 - __readfsqword(0x28u);
if ( v10 == v8 )
{
v6 = v10;
}
else
{
v6[5] = 44;
v6 += 6;
}
}
}
}
return v13 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, unsigned int a2)
{
__int64 v2; // r13
char *v3; // rax
char *v4; // rax
__int64 v5; // r15
char *v6; // rbx
__int64 i; // rbp
char *v8; // rsi
char *v10; // [rsp+8h] [rbp-250h]
char s[503]; // [rsp+10h] [rbp-248h] BYREF
char v12; // [rsp+207h] [rbp-51h] BYREF
unsigned __int64 v13; // [rsp+218h] [rbp-40h]

v13 = __readfsqword(0x28u);
v2 = randomset(a1, maxnum);
v3 = func1();
v4 = &s[sprintf(s, "%s B #fake_%d_%d %ld %s", "FB", (unsigned int)a1, a2, mylink, v3)];
v10 = v4;
if ( (int)a1 > 0 )
{
v5 = (unsigned int)(a1 - 1);
v6 = v4;
for ( i = 0LL; ; ++i )
{
*v6 = 70;
v6[1] = 66;
base64_encode_padded(v6 + 2, 4LL, *(_QWORD *)(v2 + 8 * i));
v8 = v6 + 5;
if ( v6 + 5 >= &v12 || (_DWORD)a1 - 1 == (_DWORD)i )
{
send_format("%.*s\r\n", v8 - s);
if ( i == v5 )
return v13 - __readfsqword(0x28u);
v6 = v10;
}
else
{
if ( i == v5 )
return v13 - __readfsqword(0x28u);
if ( v10 == v8 )
{
v6 = v10;
}
else
{
v6[5] = 44;
v6 += 6;
}
}
}
}
return v13 - __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: size int

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

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

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

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
func2(a1, i);
}
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

variable_types: i int

return_type: int


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

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 func4(unsigned int a1, int a2)
{
__int64 result; // rax
char v3; // dl

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: 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 func5(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:
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 func6(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 func7(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 burster_burst_clients(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r15
__int64 v3; // rbx
char v5[7]; // [rsp+29h] [rbp-CFh] BYREF
char v6[32]; // [rsp+30h] [rbp-C8h] BYREF
char v7[32]; // [rsp+50h] [rbp-A8h] BYREF
char v8[72]; // [rsp+70h] [rbp-88h] BYREF
unsigned __int64 v9; // [rsp+B8h] [rbp-40h]

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

canonical_decompiled_code:
unsigned __int64 __fastcall func9(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r15
__int64 v3; // rbx
char v5[7]; // [rsp+29h] [rbp-CFh] BYREF
char v6[32]; // [rsp+30h] [rbp-C8h] BYREF
char v7[32]; // [rsp+50h] [rbp-A8h] BYREF
char v8[72]; // [rsp+70h] [rbp-88h] BYREF
unsigned __int64 v9; // [rsp+B8h] [rbp-40h]

v9 = __readfsqword(0x28u);
v1 = randomset(a1, 800000LL);
if ( (int)a1 > 0 )
{
v2 = v1;
v3 = 0LL;
do
{
sprintf(v6, "fake%d", (unsigned int)v3);
sprintf(v7, "f%d", (unsigned int)v3);
sprintf(v8, "f%d:%ld:%d:0", (unsigned int)v3, now, (unsigned int)v3);
base64_encode_padded(v5, 7LL, *(_QWORD *)(v2 + 8 * v3) + 16843009LL);
func0();
func8(v3);
func5(v3);
func6(v3);
func7(v3);
send_format("%s N %s 2 %ld %s %s %s %s %s :fake user number %d\r\n", "FB");
++v3;
}
while ( v3 != (unsigned int)a1 );
}
return v9 - __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 v2; // ebp
unsigned int v3; // ebx
int v4; // eax
unsigned __int64 v6; // [rsp+8h] [rbp-30h]

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

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

v6 = __readfsqword(0x28u);
if ( a1 > 0 )
{
v2 = 0;
v3 = 1;
do
{
v4 = a2(v3, (unsigned int)a1);
v2 += func3(v3++, v4);
}
while ( a1 > v2 );
}
return v6 - __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:
unsigned __int64 burster_go()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

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

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

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

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:
unsigned __int64 init_burster()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
hook_hook("onregistered", burster_go);
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func12()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
hook_hook("onregistered", burster_go);
return v1 - __readfsqword(0x28u);
}

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, unsigned int a3, char a4)
{
__int64 result; // rax

if ( *a2 == 43065 )
{
if ( (_DWORD *)uplink == a2 && a4 == 110 )
{
if ( a3 )
{
uplink_with_opername();
result = 0LL;
}
else
{
uplink_without_opername();
result = a3;
}
}
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, unsigned int a3, char a4)
{
__int64 result; // rax

if ( *a2 == 43065 )
{
if ( (_DWORD *)uplink == a2 && a4 == 110 )
{
if ( a3 )
{
uplink_with_opername();
result = 0LL;
}
else
{
uplink_without_opername();
result = a3;
}
}
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; } *

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


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

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

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

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:
unsigned __int64 __fastcall server_del_user(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
jtableP_unset(a1 + 288);
return v2 - __readfsqword(0x28u);
}

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

v2 = __readfsqword(0x28u);
jtableP_unset(a1 + 288);
return v2 - __readfsqword(0x28u);
}

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

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:
unsigned __int64 __fastcall del_server(void *ptr)
{
__int64 v1; // rax
__int64 v2; // rdx
_BYTE v4[328]; // [rsp-150h] [rbp-2B8h] BYREF
_BYTE v5[328]; // [rsp+0h] [rbp-168h] BYREF
unsigned __int64 v6; // [rsp+148h] [rbp-20h]

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

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

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

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

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:
unsigned __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 )
mode_apply(a1, a2, a2 + 74, a3, a4, a5, server_modehook);
else
logtxt(256LL, "Mode change on non-channel\n");
return v6 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __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 )
mode_apply(a1, a2, a2 + 74, a3, a4, a5, server_modehook);
else
logtxt(256LL, "Mode change on non-channel\n");
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; // rbx
__int64 v2; // rax

v1 = a1[2];
do
{
v2 = a1[1] << 18;
if ( a1[12] + v2 != 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)
{
char v2; // al
__int64 v3; // rbp
__int64 v4; // rbx
char v6[2056]; // [rsp+0h] [rbp-828h] BYREF
unsigned __int64 v7; // [rsp+808h] [rbp-20h]

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

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

v7 = __readfsqword(0x28u);
rfc_split(v6, a1);
v2 = v6[0];
*a2 = v6[0];
if ( v2 )
{
v3 = (__int64)(a2 + 8);
v4 = 0LL;
do
{
func0(v3, *(const char **)&v6[8 * v4++ + 8]);
v3 += 16LL;
}
while ( (unsigned __int8)v6[0] > (int)v4 );
}
return v7 - __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:
unsigned __int64 __fastcall add_token(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v9; // rbx
unsigned __int64 v12; // [rsp+18h] [rbp-40h]

v12 = __readfsqword(0x28u);
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);
add_tokeninfo(a2, v9);
return v12 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v9; // rbx
unsigned __int64 v12; // [rsp+18h] [rbp-40h]

v12 = __readfsqword(0x28u);
v9 = zmalloc(672LL);
func1(a3, (_BYTE *)v9);
*(_QWORD *)(v9 + 656) = a5;
if ( a6 )
{
func1(a4, (_BYTE *)(v9 + 328));
*(_QWORD *)(v9 + 664) = a6;
}
if ( a1 )
add_tokeninfo(a1, v9);
add_tokeninfo(a2, v9);
return v12 - __readfsqword(0x28u);
}

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; // er12
__int64 v2; // r13
__int64 v3; // rdi
const char *v4; // rdx
__int64 v5; // r15
__int64 v6; // rbp
__int64 v7; // rbx
int v8; // er12
char v10[8]; // [rsp+0h] [rbp-848h] BYREF
const char *v11; // [rsp+8h] [rbp-840h] BYREF
const char *v12; // [rsp+10h] [rbp-838h]
unsigned __int64 v13; // [rsp+808h] [rbp-40h]

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

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

v13 = __readfsqword(0x28u);
v1 = registered;
rfc_split(v10, a1);
if ( v10[0] )
{
if ( v10[0] <= 1u && registered )
{
logfmt(256LL, "Input message '%s' has no token\n", a1);
}
else
{
if ( registered )
{
v2 = (__int64)v11;
v3 = (__int64)v12;
}
else
{
v3 = (__int64)v11;
v2 = 0LL;
}
v7 = get_tokeninfo(v3);
if ( v7 )
{
v8 = v1 + 1;
v6 = arrange_args((unsigned int)(unsigned __int8)v10[0] - v8, &(&v11)[v8], v7);
if ( v6 )
{
v5 = *(_QWORD *)(v7 + 656);
}
else
{
v5 = *(_QWORD *)(v7 + 664);
if ( !v5 || (v6 = arrange_args((unsigned int)(unsigned __int8)v10[0] - v8, &(&v11)[v8], v7 + 328)) == 0 )
{
logtxt(256LL, "Failed to deal with last input\n");
return v13 - __readfsqword(0x28u);
}
}
shift(v6, 1LL);
if ( v2 )
{
convert_num(v6 + 8, v2);
}
else
{
*(_DWORD *)(v6 + 8) = 10;
*(_QWORD *)(v6 + 16) = 0LL;
}
call_varargs(v5, v6);
}
else
{
if ( registered )
v4 = v12;
else
v4 = v11;
logfmt(256LL, "Unknown token: %s\n", v4);
}
}
}
return v13 - __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)
{
const char **v1; // rbp
int i; // ebx

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

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

v1 = (const char **)commands;
for ( i = 0; i != 32; ++i )
{
if ( *v1 && !strcasecmp(*v1, s2) )
return commands[4 * i + 3];
v1 += 4;
}
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 *); // r12
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 *); // r12
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 *v7; // rdx
int v8; // eax
_QWORD *v9; // rax
unsigned __int64 v11; // [rsp+8h] [rbp-10h]

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

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

v11 = __readfsqword(0x28u);
if ( commands[0] )
{
v7 = &commands[4];
v8 = 0;
do
{
++v8;
v7 += 4;
}
while ( *(v7 - 4) );
}
else
{
v8 = 0;
}
v9 = &commands[4 * v8];
*v9 = a1;
v9[1] = a2;
v9[2] = a3;
v9[3] = a4;
return v11 - __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:
unsigned __int64 __fastcall logfmtva(__int16 a1, const char *a2, void *a3)
{
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
if ( (a1 & 0x5511) != 0 )
vfprintf(stderr, a2, a3);
return v4 - __readfsqword(0x28u);
}

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

v4 = __readfsqword(0x28u);
if ( (a1 & 0x5511) != 0 )
vfprintf(stderr, a2, a3);
return v4 - __readfsqword(0x28u);
}

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:
unsigned __int64 __fastcall logtxt(__int16 a1, const char *a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
if ( (a1 & 0x5511) != 0 )
fprintf(stderr, a2);
return v3 - __readfsqword(0x28u);
}

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

v3 = __readfsqword(0x28u);
if ( (a1 & 0x5511) != 0 )
fprintf(stderr, a2);
return v3 - __readfsqword(0x28u);
}

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:
unsigned __int64 init()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
init_hooks();
init_base64();
init_stringutils();
init_tokens();
init_modes();
hook_hook("onregistered", &module_loadAll);
return v1 - __readfsqword(0x28u);
}

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

v1 = __readfsqword(0x28u);
init_hooks();
init_base64();
init_stringutils();
init_tokens();
init_modes();
hook_hook("onregistered", &module_loadAll);
return v1 - __readfsqword(0x28u);
}

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


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
time_t v4; // rbp
_BYTE v5[328]; // [rsp-150h] [rbp-308h] BYREF
_BYTE v6[336]; // [rsp+0h] [rbp-1B8h] BYREF
char v7[24]; // [rsp+150h] [rbp-68h] BYREF
__int64 v8; // [rsp+168h] [rbp-50h]
__int64 v9; // [rsp+170h] [rbp-48h]
__int64 v10; // [rsp+178h] [rbp-40h]
__int64 v11; // [rsp+180h] [rbp-38h]
__int64 v12; // [rsp+188h] [rbp-30h]
unsigned __int64 v13; // [rsp+198h] [rbp-20h]

v13 = __readfsqword(0x28u);
strcpy(v7, "./plservices.conf");
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
system_argv = *argv;
while ( 1 )
{
v3 = _posix_getopt((unsigned int)argc, argv, "c:");
if ( v3 == -1 )
break;
if ( v3 == 63 )
{
fprintf(stderr, "Usage: %s [-c config]\n", *argv);
exit(1);
}
if ( v3 == 99 )
strncpyz(v7, optarg, 64LL);
}
init();
load_config(v7);
now = time(0LL);
net_connect();
v4 = time(0LL);
for ( now = v4; ; v4 = now )
{
now = time(0LL);
if ( now != v4 )
{
pack_empty(v6);
qmemcpy(v5, v6, sizeof(v5));
hook_call("ontick");
}
net_read();
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
time_t v4; // rbp
_BYTE v5[328]; // [rsp-150h] [rbp-308h] BYREF
_BYTE v6[336]; // [rsp+0h] [rbp-1B8h] BYREF
char v7[24]; // [rsp+150h] [rbp-68h] BYREF
__int64 v8; // [rsp+168h] [rbp-50h]
__int64 v9; // [rsp+170h] [rbp-48h]
__int64 v10; // [rsp+178h] [rbp-40h]
__int64 v11; // [rsp+180h] [rbp-38h]
__int64 v12; // [rsp+188h] [rbp-30h]
unsigned __int64 v13; // [rsp+198h] [rbp-20h]

v13 = __readfsqword(0x28u);
strcpy(v7, "./plservices.conf");
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
system_argv = *argv;
while ( 1 )
{
v3 = _posix_getopt((unsigned int)argc, argv, "c:");
if ( v3 == -1 )
break;
if ( v3 == 63 )
{
fprintf(stderr, "Usage: %s [-c config]\n", *argv);
exit(1);
}
if ( v3 == 99 )
strncpyz(v7, optarg, 64LL);
}
func0();
load_config(v7);
now = time(0LL);
net_connect();
v4 = time(0LL);
for ( now = v4; ; v4 = now )
{
now = time(0LL);
if ( now != v4 )
{
pack_empty(v6);
qmemcpy(v5, v6, sizeof(v5));
hook_call("ontick");
}
net_read();
}
}

original_code:
int main(int argc, char **argv) {
 char configfile[64] = "./plservices.conf";
 time_t last;
 int opt;
 system_argv = argv[0];
 while ((opt = getopt(argc, argv, "c:")) != -1) {
  switch (opt) {
   case 'c':
    strncpyz((configfile), (optarg), sizeof(configfile));
    break;
   case '?':
    fprintf(stderr, "Usage: %s [-c config]\n", argv[0]);
    exit(1);
  }
 }
 init();
 load_config(configfile);
 now = time(((void *)0));
 net_connect();
 last = now = time(((void *)0));
 while (1) {
  now = time(((void *)0));
  if (last != now) {
   hook_call("ontick", pack_empty());
  }
  net_read();
  last = now;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 char configfile[64] = "./plservices.conf";
 long last;
 int opt;
 system_argv = argv[0];
 while ((opt = getopt(argc, argv, "c:")) != -1) {
  switch (opt) {
   case 'c':
    strncpyz((configfile), (optarg), sizeof(configfile));
    break;
   case '?':
    fprintf(stderr, "Usage: %s [-c config]\n", argv[0]);
    exit(1);
  }
 }
 init();
 load_config(configfile);
 now = time(((void *)0));
 net_connect();
 last = now = time(((void *)0));
 while (1) {
  now = time(((void *)0));
  if (last != now) {
   hook_call("ontick", pack_empty());
  }
  net_read();
  last = now;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
configfile
char [64]

variable_types: last long

variable_types: opt int


decompiled_code:
unsigned __int64 __fastcall send_raw(void *buf)
{
size_t v1; // rbx
ssize_t v2; // rax
int *v4; // rax
char *v5; // rax
_BYTE v6[520]; // [rsp+0h] [rbp-228h] BYREF
unsigned __int64 v7; // [rsp+208h] [rbp-20h]

v7 = __readfsqword(0x28u);
v1 = strlen((const char *)buf);
logfmt(1024LL, "-> %s", (const char *)buf);
strncpyz(v6, buf, 513LL);
for ( ; v1; v1 -= v2 )
{
v2 = send(conn, buf, v1, 0);
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logfmt(1LL, "POSIX error: %s", v5);
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 103LL, "Error in sending data");
exit(1);
}
}
handle_input(v6);
return v7 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(void *buf)
{
size_t v1; // rbx
ssize_t v2; // rax
int *v4; // rax
char *v5; // rax
_BYTE v6[520]; // [rsp+0h] [rbp-228h] BYREF
unsigned __int64 v7; // [rsp+208h] [rbp-20h]

v7 = __readfsqword(0x28u);
v1 = strlen((const char *)buf);
logfmt(1024LL, "-> %s", (const char *)buf);
strncpyz(v6, buf, 513LL);
for ( ; v1; v1 -= v2 )
{
v2 = send(conn, buf, v1, 0);
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logfmt(1LL, "POSIX error: %s", v5);
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 103LL, "Error in sending data");
exit(1);
}
}
handle_input(v6);
return v7 - __readfsqword(0x28u);
}

original_code:
void send_raw(char *str) {
 char buf[513];
 ssize_t tosend, sent;
 tosend = strlen(str);
 logfmt(0x0400, "-> %s", str);
 strncpyz((buf), (str), sizeof(buf));
 while (tosend) {
  sent = send(conn, str, tosend, 0);
  if (sent < 0)
   do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 103, "Error in sending data"); exit(1); } while (0); } while(0);
  tosend -= sent;
 }
 handle_input(buf);
}

canonical_original_code:
void send_raw(char *str) {
 char buf[513];
 long tosend; long sent;
 tosend = strlen(str);
 logfmt(0x0400, "-> %s", str);
 strncpyz((buf), (str), sizeof(buf));
 while (tosend) {
  sent = send(conn, str, tosend, 0);
  if (sent < 0)
   do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 103, "Error in sending data"); exit(1); } while (0); } while(0);
  tosend -= sent;
 }
 handle_input(buf);
}

variable_types:
str
char *

variable_types:
buf
char [513]

variable_types: tosend long

variable_types: sent long


decompiled_code:
unsigned __int64 send_format(char *format, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-D8h] BYREF
unsigned __int64 v3; // [rsp+18h] [rbp-C0h]

va_start(va, format);
v3 = __readfsqword(0x28u);
if ( vsnprintf(buf_1, 0x200uLL, format, va) == 512 )
byte_115E0 = 0;
send_raw(buf_1);
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func3(char *format, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-D8h] BYREF
unsigned __int64 v3; // [rsp+18h] [rbp-C0h]

va_start(va, format);
v3 = __readfsqword(0x28u);
if ( vsnprintf(buf_1, 0x200uLL, format, va) == 512 )
byte_115E0 = 0;
func1(buf_1);
return v3 - __readfsqword(0x28u);
}

original_code:
void send_format(const char *fmt, ...) {
 static char buf[513];
 va_list ap;
 __builtin_va_start(ap,fmt);
 if (vsnprintf(buf, sizeof(buf)-1, fmt, ap) == sizeof(buf)-1)
  buf[sizeof(buf)-1] = '\0';
 __builtin_va_end(ap);
 send_raw(buf);
}

canonical_original_code:
void send_format(char *fmt, ...) {
 static char buf[513];
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 if (vsnprintf(buf, sizeof(buf)-1, fmt, ap) == sizeof(buf)-1)
  buf[sizeof(buf)-1] = '\0';
 __builtin_va_end(ap);
 send_raw(buf);
}


decompiled_code:
unsigned __int64 __fastcall net_greet(const char *a1, const char *a2, __int64 a3, const char *a4)
{
char v6[3]; // [rsp+5h] [rbp-33h] BYREF
unsigned __int64 v7; // [rsp+8h] [rbp-30h]

v7 = __readfsqword(0x28u);
base64_encode_padded(v6, 3LL);
send_format("PASS :%s\r\n", a1);
send_format("SERVER %s 1 %ld %ld J10 %s]]] +hsn :%s\r\n", a2, now, now, v6, a4);
return v7 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(const char *a1, const char *a2, __int64 a3, const char *a4)
{
char v6[3]; // [rsp+5h] [rbp-33h] BYREF
unsigned __int64 v7; // [rsp+8h] [rbp-30h]

v7 = __readfsqword(0x28u);
base64_encode_padded(v6, 3LL);
func3("PASS :%s\r\n", a1);
func3("SERVER %s 1 %ld %ld J10 %s]]] +hsn :%s\r\n", a2, now, now, v6, a4);
return v7 - __readfsqword(0x28u);
}

original_code:
static void net_greet(const char *pass, const char *name, unsigned long numeric, const char *descr) {
 char numericstr[2 +1];
 base64_encode_padded(numericstr, sizeof(numericstr), numeric);
 send_format("PASS :%s\r\n", pass);
 send_format("SERVER %s 1 %ld %ld J10 %s]]] +hsn :%s\r\n", name, now, now, numericstr, descr);
}

canonical_original_code:
static void net_greet(char *pass, char *name, unsigned long numeric, char *descr) {
 char numericstr[-1];
 base64_encode_padded(numericstr, sizeof(numericstr), numeric);
 send_format("PASS :%s\r\n", pass);
 send_format("SERVER %s 1 %ld %ld J10 %s]]] +hsn :%s\r\n", name, now, now, numericstr, descr);
}

variable_types:
pass
char *

variable_types:
name
char *

variable_types:
numeric
unsigned long

variable_types:
descr
char *

variable_types:
numericstr
char [-1]


decompiled_code:
unsigned __int64 net_connect()
{
const char *v0; // r15
const char *v1; // rbx
const char *v2; // rbp
const char *v3; // r14
const char *v4; // r12
const char *v5; // r13
__int64 v6; // r14
struct hostent *v7; // rax
int v8; // er15
char *v9; // rax
__int16 v10; // ax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
struct in_addr in; // [rsp+4h] [rbp-74h]
int optval; // [rsp+1Ch] [rbp-5Ch] BYREF
struct sockaddr v20; // [rsp+20h] [rbp-58h] BYREF
unsigned __int64 v21; // [rsp+38h] [rbp-40h]

v21 = __readfsqword(0x28u);
v0 = (const char *)config_get("core.uplink", "host");
v1 = (const char *)config_get("core.uplink", "port");
v2 = (const char *)config_get("core.uplink", "pass");
v3 = (const char *)config_get("core.server", "numeric");
v4 = (const char *)config_get("core.server", "name");
v5 = (const char *)config_get("core.server", "description");
optval = 1;
v6 = strtol(v3, 0LL, 10);
if ( v1 == 0LL || v0 == 0LL || !v2 )
{
logfmt(
1LL,
"Fatal error at %s (line %d): %s\n",
"src/net.c",
70LL,
"Invalid uplink specified in configfile. Need [core.uplink] host, port, pass");
exit(1);
}
if ( v5 == 0LL || v4 == 0LL || !v6 )
{
logfmt(
1LL,
"Fatal error at %s (line %d): %s\n",
"src/net.c",
73LL,
"Invalid uplink specified in configfile. Need [core.server] numeric (1-4096), servername, descr");
exit(1);
}
conn = socket(2, 1, 6);
if ( conn < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
logfmt(1LL, "POSIX error: %s", v13);
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 76LL, "Could not create socket");
exit(1);
}
v7 = gethostbyname(v0);
if ( !v7 )
{
v14 = _errno_location();
v15 = strerror(*v14);
logfmt(1LL, "POSIX error: %s", v15);
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 80LL, "Could not resolve hostname.");
exit(1);
}
in.s_addr = **(_DWORD **)v7->h_addr_list;
v8 = conn;
setsockopt(conn, 6, 1, &optval, 4u);
*(_QWORD *)&v20.sa_family = 2LL;
*(_QWORD *)&v20.sa_data[6] = 0LL;
v9 = inet_ntoa(in);
*(_DWORD *)&v20.sa_data[2] = inet_addr(v9);
v10 = atoi(v1);
*(_WORD *)v20.sa_data = _bswap_16(v10);
if ( connect(v8, &v20, 0x10u) < 0 )
{
v16 = _errno_location();
v17 = strerror(*v16);
logfmt(1LL, "POSIX error: %s", v17);
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 89LL, "Failed to connect to server");
exit(1);
}
net_greet(v2, v4, v6, v5);
return v21 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func5()
{
const char *v0; // r15
const char *v1; // rbx
const char *v2; // rbp
const char *v3; // r14
const char *v4; // r12
const char *v5; // r13
__int64 v6; // r14
struct hostent *v7; // rax
int v8; // er15
char *v9; // rax
__int16 v10; // ax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
struct in_addr in; // [rsp+4h] [rbp-74h]
int optval; // [rsp+1Ch] [rbp-5Ch] BYREF
struct sockaddr v20; // [rsp+20h] [rbp-58h] BYREF
unsigned __int64 v21; // [rsp+38h] [rbp-40h]

v21 = __readfsqword(0x28u);
v0 = (const char *)config_get("core.uplink", "host");
v1 = (const char *)config_get("core.uplink", "port");
v2 = (const char *)config_get("core.uplink", "pass");
v3 = (const char *)config_get("core.server", "numeric");
v4 = (const char *)config_get("core.server", "name");
v5 = (const char *)config_get("core.server", "description");
optval = 1;
v6 = strtol(v3, 0LL, 10);
if ( v1 == 0LL || v0 == 0LL || !v2 )
{
logfmt(
1LL,
"Fatal error at %s (line %d): %s\n",
"src/net.c",
70LL,
"Invalid uplink specified in configfile. Need [core.uplink] host, port, pass");
exit(1);
}
if ( v5 == 0LL || v4 == 0LL || !v6 )
{
logfmt(
1LL,
"Fatal error at %s (line %d): %s\n",
"src/net.c",
73LL,
"Invalid uplink specified in configfile. Need [core.server] numeric (1-4096), servername, descr");
exit(1);
}
conn = socket(2, 1, 6);
if ( conn < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
logfmt(1LL, "POSIX error: %s", v13);
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 76LL, "Could not create socket");
exit(1);
}
v7 = gethostbyname(v0);
if ( !v7 )
{
v14 = _errno_location();
v15 = strerror(*v14);
logfmt(1LL, "POSIX error: %s", v15);
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 80LL, "Could not resolve hostname.");
exit(1);
}
in.s_addr = **(_DWORD **)v7->h_addr_list;
v8 = conn;
setsockopt(conn, 6, 1, &optval, 4u);
*(_QWORD *)&v20.sa_family = 2LL;
*(_QWORD *)&v20.sa_data[6] = 0LL;
v9 = inet_ntoa(in);
*(_DWORD *)&v20.sa_data[2] = inet_addr(v9);
v10 = atoi(v1);
*(_WORD *)v20.sa_data = func0(v10);
if ( connect(v8, &v20, 0x10u) < 0 )
{
v16 = _errno_location();
v17 = strerror(*v16);
logfmt(1LL, "POSIX error: %s", v17);
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 89LL, "Failed to connect to server");
exit(1);
}
func4(v2, v4, v6, v5);
return v21 - __readfsqword(0x28u);
}

original_code:
void net_connect(void) {
 char *uplink = config_get("core.uplink", "host");
 const char *port = config_get("core.uplink", "port");
 const char *pass = config_get("core.uplink", "pass");
 const char *numericstr = config_get("core.server", "numeric");
 const char *servername= config_get("core.server", "name");
 const char *descr = config_get("core.server", "description");
 unsigned long numeric;
 struct sockaddr_in server;
 struct hostent *hostname;
 struct in_addr ip_addr;
 int flag_set = 1;
 numeric = strtol(numericstr, ((void *)0), 10);
 if (!uplink || !port || !pass)
  do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 70, "Invalid uplink specified in configfile. Need [core.uplink] host, port, pass"); exit(1); } while (0);
 if (!servername || !descr || !numeric || !numeric)
  do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 73, "Invalid uplink specified in configfile. Need [core.server] numeric (1-4096), servername, descr"); exit(1); } while (0);
 if ((conn = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
  do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 76, "Could not create socket"); exit(1); } while (0); } while(0);
 hostname = gethostbyname(uplink);
 if (!hostname)
  do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 80, "Could not resolve hostname."); exit(1); } while (0); } while(0);
 ip_addr = *(struct in_addr *)(hostname->h_addr_list[0]);
 setsockopt(conn, IPPROTO_TCP, 1, &flag_set, sizeof(flag_set));
 memset(&server, 0, sizeof(server));
 server.sin_family = 2;
 server.sin_addr.s_addr = inet_addr(inet_ntoa(ip_addr));
 server.sin_port = htons(atoi(port));
 if (connect(conn, (struct sockaddr *) &server, sizeof(server)) < 0)
  do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 89, "Failed to connect to server"); exit(1); } while (0); } while(0);
 net_greet(pass, servername, numeric, descr);
}

canonical_original_code:
void net_connect() {
 char *uplink = config_get("core.uplink", "host");
 char *port = config_get("core.uplink", "port");
 char *pass = config_get("core.uplink", "pass");
 char *numericstr = config_get("core.server", "numeric");
 char *servername = config_get("core.server", "name");
 char *descr = config_get("core.server", "description");
 unsigned long numeric;
 struct sockaddr_in server;
 struct hostent *hostname;
 struct in_addr ip_addr;
 int flag_set = 1;
 numeric = strtol(numericstr, ((void *)0), 10);
 if (!uplink || !port || !pass)
  do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 70, "Invalid uplink specified in configfile. Need [core.uplink] host, port, pass"); exit(1); } while (0);
 if (!servername || !descr || !numeric || !numeric)
  do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 73, "Invalid uplink specified in configfile. Need [core.server] numeric (1-4096), servername, descr"); exit(1); } while (0);
 if ((conn = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
  do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 76, "Could not create socket"); exit(1); } while (0); } while(0);
 hostname = gethostbyname(uplink);
 if (!hostname)
  do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 80, "Could not resolve hostname."); exit(1); } while (0); } while(0);
 ip_addr = *(struct in_addr *)(hostname->h_addr_list[0]);
 setsockopt(conn, IPPROTO_TCP, 1, &flag_set, sizeof(flag_set));
 memset(&server, 0, sizeof(server));
 server.sin_family = 2;
 server.sin_addr.s_addr = inet_addr(inet_ntoa(ip_addr));
 server.sin_port = htons(atoi(port));
 if (connect(conn, (struct sockaddr *) &server, sizeof(server)) < 0)
  do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 89, "Failed to connect to server"); exit(1); } while (0); } while(0);
 net_greet(pass, servername, numeric, descr);
}

variable_types:
uplink
char *

variable_types:
port
char *

variable_types:
numericstr
char *

variable_types:
servername
char *

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
unsigned __int64 net_read()
{
size_t v0; // rbp
int v1; // eax
int *v3; // rax
char *v4; // rax
ssize_t v5; // rbx
const char *v6; // rbp
const char *v7; // rbx
char *v8; // rax
char v9; // al
size_t v10; // rax
size_t v11; // rax
struct timeval v12; // [rsp+0h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-A8h] BYREF
unsigned __int64 v14; // [rsp+98h] [rbp-20h]

v14 = __readfsqword(0x28u);
v12.tv_sec = 1LL;
v12.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[conn / 64] |= 1LL << (conn % 64);
v0 = strlen(buf_0);
logfmt(0x2000LL, "---- Old (%d): '%s' ----\n", v0, buf_0);
logtxt(0x2000LL, "Reading/Waiting...");
v1 = select(conn + 1, &readfds, 0LL, 0LL, &v12);
if ( v1 > 0 )
{
v5 = read(conn, &buf_0[v0], 0xFFFF - v0);
logfmt(0x2000LL, "%d bytes...\n", v5);
if ( !v5 )
{
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 165LL, "EOF");
exit(1);
}
buf_0[v0 + v5] = 0;
logfmt(0x2000LL, "---- New (%d) buf[%d] ----\n", v5, v0 + v5);
logfmt(0x2000LL, "%s\n", &buf_0[v0]);
logtxt(0x2000LL, "------------------\n");
v6 = buf_0;
if ( buf_0[0] )
{
while ( 1 )
{
v8 = strpbrk(v6, "\r\n");
v7 = v8;
if ( !v8 )
break;
v9 = *v8;
if ( v9 == 13 || v9 == 10 )
{
do
{
do
*v7++ = 0;
while ( *v7 == 13 );
}
while ( *v7 == 10 );
}
logfmt(1024LL, "<- %s\n", v6);
handle_input(v6);
logfmt(0x2000LL, "line = buf[%td], lineend = buf[%td]\n", v6 - buf_0, v7 - buf_0);
logfmt(0x2000LL, "line = '%s', lineend = '%s'\n", v6, v7);
if ( !*v7 )
{
v6 = v7;
break;
}
v6 = v7;
}
}
v10 = strlen(v6);
logfmt(
0x2000LL,
"---- NewOld (%zd): '%s' '%2X %2X %2X'----\n",
v10,
v6,
(unsigned __int8)v6[v10 - 3],
(unsigned __int8)v6[v10 - 2],
(unsigned __int8)v6[v10 - 1]);
v11 = strlen(v6);
memmove(buf_0, v6, v11 + 1);
}
else if ( v1 < 0LL )
{
v3 = _errno_location();
v4 = strerror(*v3);
logfmt(1LL, "POSIX error: %s", v4);
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 159LL, "select() error");
exit(1);
}
return v14 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func6()
{
size_t v0; // rbp
int v1; // eax
int *v3; // rax
char *v4; // rax
ssize_t v5; // rbx
const char *v6; // rbp
const char *v7; // rbx
char *v8; // rax
char v9; // al
size_t v10; // rax
size_t v11; // rax
struct timeval v12; // [rsp+0h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-A8h] BYREF
unsigned __int64 v14; // [rsp+98h] [rbp-20h]

v14 = __readfsqword(0x28u);
v12.tv_sec = 1LL;
v12.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[conn / 64] |= 1LL << (conn % 64);
v0 = strlen(buf_0);
logfmt(0x2000LL, "---- Old (%d): '%s' ----\n", v0, buf_0);
logtxt(0x2000LL, "Reading/Waiting...");
v1 = select(conn + 1, &readfds, 0LL, 0LL, &v12);
if ( v1 > 0 )
{
v5 = read(conn, &buf_0[v0], 0xFFFF - v0);
logfmt(0x2000LL, "%d bytes...\n", v5);
if ( !v5 )
{
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 165LL, "EOF");
exit(1);
}
buf_0[v0 + v5] = 0;
logfmt(0x2000LL, "---- New (%d) buf[%d] ----\n", v5, v0 + v5);
logfmt(0x2000LL, "%s\n", &buf_0[v0]);
logtxt(0x2000LL, "------------------\n");
v6 = buf_0;
if ( buf_0[0] )
{
while ( 1 )
{
v8 = strpbrk(v6, "\r\n");
v7 = v8;
if ( !v8 )
break;
v9 = *v8;
if ( v9 == 13 || v9 == 10 )
{
do
{
do
*v7++ = 0;
while ( *v7 == 13 );
}
while ( *v7 == 10 );
}
logfmt(1024LL, "<- %s\n", v6);
handle_input(v6);
logfmt(0x2000LL, "line = buf[%td], lineend = buf[%td]\n", v6 - buf_0, v7 - buf_0);
logfmt(0x2000LL, "line = '%s', lineend = '%s'\n", v6, v7);
if ( !*v7 )
{
v6 = v7;
break;
}
v6 = v7;
}
}
v10 = strlen(v6);
logfmt(
0x2000LL,
"---- NewOld (%zd): '%s' '%2X %2X %2X'----\n",
v10,
v6,
(unsigned __int8)v6[v10 - 3],
(unsigned __int8)v6[v10 - 2],
(unsigned __int8)v6[v10 - 1]);
v11 = strlen(v6);
memmove(buf_0, v6, v11 + 1);
}
else if ( v1 < 0LL )
{
v3 = _errno_location();
v4 = strerror(*v3);
logfmt(1LL, "POSIX error: %s", v4);
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 159LL, "select() error");
exit(1);
}
return v14 - __readfsqword(0x28u);
}

original_code:
void net_read(void) {
 static char buf[65536] = { 0 };
 ssize_t oldlen, r;
 char *line, *lineend;
 struct timeval tv = { 1, 0 };
 fd_set fds;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fds)->__fds_bits)[((conn) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((conn) % (8 * (int) sizeof (__fd_mask)))))));
 oldlen = strlen(buf);
 logfmt(0x2000, "---- Old (%d): '%s' ----\n", oldlen, buf);
 logtxt(0x2000, "Reading/Waiting...");
 r = select(conn+1, &fds, ((void *)0), ((void *)0), &tv);
 if (r <= 0) {
  if (r < 0)
   do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 159, "select() error"); exit(1); } while (0); } while(0);
  return;
 }
 r = read(conn, buf+oldlen, sizeof(buf)-oldlen-1);
 logfmt(0x2000, "%d bytes...\n", r);
 if (r == 0) {
  do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 165, "EOF"); exit(1); } while (0);
  return;
 }
 buf[oldlen+r] = '\0';
 logfmt(0x2000, "---- New (%d) buf[%d] ----\n", r, oldlen+r);
 logfmt(0x2000, "%s\n", buf+oldlen);
 logtxt(0x2000, "------------------\n");
 line = buf;
 while (*line && (lineend = strpbrk(line, "\r\n"))) {
  while (*lineend == '\r' || *lineend == '\n')
   *lineend++ = '\0';
  logfmt(0x0400, "<- %s\n", line);
  handle_input(line);
  logfmt(0x2000, "line = buf[%td], lineend = buf[%td]\n", line-buf, lineend-buf);
  logfmt(0x2000, "line = '%s', lineend = '%s'\n", line, lineend);
  line = lineend;
 }
 logfmt(0x2000, "---- NewOld (%zd): '%s' '%2X %2X %2X'----\n", strlen(line), line,
     (unsigned char)line[strlen(line)-3], (unsigned char)line[strlen(line)-2], (unsigned char)line[strlen(line)-1]);
 memmove(buf, line, strlen(line)+1);
}

canonical_original_code:
void net_read() {
 static char buf[65536] = { 0 };
 long oldlen; long r;
 char *line; char *lineend;
 struct timeval tv = { 1, 0 };
 struct fd_set fds;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fds)->__fds_bits)[((conn) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((conn) % (8 * (int) sizeof (__fd_mask)))))));
 oldlen = strlen(buf);
 logfmt(0x2000, "---- Old (%d): '%s' ----\n", oldlen, buf);
 logtxt(0x2000, "Reading/Waiting...");
 r = select(conn+1, &fds, ((void *)0), ((void *)0), &tv);
 if (r <= 0) {
  if (r < 0)
   do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 159, "select() error"); exit(1); } while (0); } while(0);
  return;
 }
 r = read(conn, buf+oldlen, sizeof(buf)-oldlen-1);
 logfmt(0x2000, "%d bytes...\n", r);
 if (r == 0) {
  do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 165, "EOF"); exit(1); } while (0);
  return;
 }
 buf[oldlen+r] = '\0';
 logfmt(0x2000, "---- New (%d) buf[%d] ----\n", r, oldlen+r);
 logfmt(0x2000, "%s\n", buf+oldlen);
 logtxt(0x2000, "------------------\n");
 line = buf;
 while (*line && (lineend = strpbrk(line, "\r\n"))) {
  while (*lineend == '\r' || *lineend == '\n')
   *lineend++ = '\0';
  logfmt(0x0400, "<- %s\n", line);
  handle_input(line);
  logfmt(0x2000, "line = buf[%td], lineend = buf[%td]\n", line-buf, lineend-buf);
  logfmt(0x2000, "line = '%s', lineend = '%s'\n", line, lineend);
  line = lineend;
 }
 logfmt(0x2000, "---- NewOld (%zd): '%s' '%2X %2X %2X'----\n", strlen(line), line,
     (unsigned char)line[strlen(line)-3], (unsigned char)line[strlen(line)-2], (unsigned char)line[strlen(line)-1]);
 memmove(buf, line, strlen(line)+1);
}

variable_types:
buf
char [65536]

variable_types: oldlen long

variable_types: r long

variable_types:
line
char *

variable_types:
lineend
char *

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
fds
struct fd_set { long __fds_bits[-1]; }


decompiled_code:
__int64 __fastcall command_help(__int64 a1, __int64 a2, __int64 a3)
{
const char **v4; // rbp
int i; // ebx
const char *v6; // r12
const char *v7; // rax
const char **v8; // rbx

if ( *(_BYTE *)a3 == 1 )
{
module_notice(bot, a1 + 16, "Usage: HELP <command>");
module_notice(bot, a1 + 16, "Shows help such as syntax and descriptions for commands.");
}
else
{
v4 = (const char **)&commands;
for ( i = 0; i != 32; ++i )
{
if ( *v4 )
{
v6 = *(const char **)(a3 + 16);
if ( !strcasecmp(*v4, v6) )
{
v7 = (const char *)strconv(&toupper, 0LL, 0LL, v6);
module_notice(bot, a1 + 16, "Showing help for command %s", v7);
v8 = (const char **)((char *)&commands + 32 * i);
module_notice(bot, a1 + 16, "Usage: %s", v8[1]);
module_notice(bot, a1 + 16, "%s", v8[2]);
return 0LL;
}
}
v4 += 4;
}
module_notice(bot, a1 + 16, "No help available for %s.", *(const char **)(a3 + 8));
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
const char **v4; // rbp
int i; // ebx
const char *v6; // r12
const char *v7; // rax
const char **v8; // rbx

if ( *(_BYTE *)a3 == 1 )
{
module_notice(bot, a1 + 16, "Usage: HELP <command>");
module_notice(bot, a1 + 16, "Shows help such as syntax and descriptions for commands.");
}
else
{
v4 = (const char **)&commands;
for ( i = 0; i != 32; ++i )
{
if ( *v4 )
{
v6 = *(const char **)(a3 + 16);
if ( !strcasecmp(*v4, v6) )
{
v7 = (const char *)strconv(&toupper, 0LL, 0LL, v6);
module_notice(bot, a1 + 16, "Showing help for command %s", v7);
v8 = (const char **)((char *)&commands + 32 * i);
module_notice(bot, a1 + 16, "Usage: %s", v8[1]);
module_notice(bot, a1 + 16, "%s", v8[2]);
return 0LL;
}
}
v4 += 4;
}
module_notice(bot, a1 + 16, "No help available for %s.", *(const char **)(a3 + 8));
}
return 0LL;
}

original_code:
int command_help (struct user *from, struct user *to, struct manyargs *args) {
 if (args->c == 1) {
  module_notice(bot, from->numericstr, "Usage: HELP <command>");
  module_notice(bot, from->numericstr, "Shows help such as syntax and descriptions for commands.");
  return 0;
 }
 for (int x = 0; x<32; x++) {
  if (commands[x].trigger != ((void *)0) && !strcasecmp(commands[x].trigger, args->v[1])) {
   module_notice(bot, from->numericstr, "Showing help for command %s", strconv(toupper, ((void *)0), 0, args->v[1]));
   module_notice(bot, from->numericstr, "Usage: %s", commands[x].syntax);
   module_notice(bot, from->numericstr, "%s", commands[x].description);
   return 0;
  }
 }
 module_notice(bot, from->numericstr, "No help available for %s.", args->v[0]);
 return 0;
}

canonical_original_code:
int command_help(struct user *from, struct user *to, struct manyargs *args) {
 if (args->c == 1) {
  module_notice(bot, from->numericstr, "Usage: HELP <command>");
  module_notice(bot, from->numericstr, "Shows help such as syntax and descriptions for commands.");
  return 0;
 }
 for (int x = 0; x<32; x++) {
  if (commands[x].trigger != ((void *)0) && !strcasecmp(commands[x].trigger, args->v[1])) {
   module_notice(bot, from->numericstr, "Showing help for command %s", strconv(toupper, ((void *)0), 0, args->v[1]));
   module_notice(bot, from->numericstr, "Usage: %s", commands[x].syntax);
   module_notice(bot, from->numericstr, "%s", commands[x].description);
   return 0;
  }
 }
 module_notice(bot, from->numericstr, "No help available for %s.", args->v[0]);
 return 0;
}

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:
to
struct user *

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

variable_types: x int


child

decompiled_code:
__int64 __fastcall child(int a1)
{
return (unsigned int)(2 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned int)(2 * a1);
}

original_code:
uint16_t child(uint16_t p) {
 return p << 1;
}

canonical_original_code:
unsigned short child(unsigned short p) {
 return p << 1;
}

variable_types:
p
unsigned short

return_type: unsigned short


pop

original_code:
void pop(struct heap *heap, struct tbl *tbl, struct maze *maze) {
 heap->h[0] = heap->h[1];
 uint16_t p = 1;
 uint16_t c = 2;
 uint16_t c_min = 1;
 while (c + 1 <= heap->n_heap) {
  c_min = ((heap->h[c])->time < (heap->h[c + 1])->time) ? c : c + 1;
  heap->h[p] = heap->h[c_min];
  p = c_min;
  c = child(p);
 }
 heap->h[c_min] = heap->h[heap->n_heap--];
 return;
}

canonical_original_code:
void pop(struct heap *heap, struct tbl *tbl, struct maze *maze) {
 heap->h[0] = heap->h[1];
 unsigned short p = 1;
 unsigned short c = 2;
 unsigned short c_min = 1;
 while (c + 1 <= heap->n_heap) {
  c_min = ((heap->h[c])->time < (heap->h[c + 1])->time) ? c : c + 1;
  heap->h[p] = heap->h[c_min];
  p = c_min;
  c = child(p);
 }
 heap->h[c_min] = heap->h[heap->n_heap--];
 return;
}

variable_types: struct heap { struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } *h[258]; unsigned short n_heap; } *

variable_types: struct tbl { struct node *t[-1]; unsigned short n_tbl; } *

variable_types: struct maze { unsigned short start_id; unsigned short end_id; struct square { _Bool w[4]; } *m; } *

variable_types:
c
unsigned short

user_defined_types: struct heap { struct node *h[258]; unsigned short n_heap; }

user_defined_types: struct maze { unsigned short start_id; unsigned short end_id; struct square *m; }


decompiled_code:
__int64 __fastcall time_straight(int a1)
{
return (unsigned int)(2 * a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return (unsigned int)(2 * a1 + 1);
}

original_code:
uint16_t time_straight(uint16_t n, struct node *p, struct node nb) {
 return (1 + (2 * n));
}

canonical_original_code:
unsigned short time_straight(unsigned short n, struct node *p, struct node nb) {
 return (1 + (2 * n));
}

variable_types:
n
unsigned short

variable_types: struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } *

variable_types:
nb
struct node


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

result = a1;
if ( (unsigned __int16)a1 <= 0x18u )
{
switch ( a2 )
{
case 0:
result = a1 - 3;
break;
case 1:
result = a1 - 12;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 14;
break;
case 2:
result = a1 + 3;
break;
case 3:
result = a1 - 9;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 15;
break;
case 4:
result = a1 + 3;
break;
case 5:
result = a1 - 10;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 12;
break;
case 6:
result = a1 - 3;
break;
case 7:
result = a1 - 13;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 9;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
}
return result;
}

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

result = a1;
if ( (unsigned __int16)a1 <= 0x18u )
{
switch ( a2 )
{
case 0:
result = a1 - 3;
break;
case 1:
result = a1 - 12;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 14;
break;
case 2:
result = a1 + 3;
break;
case 3:
result = a1 - 9;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 15;
break;
case 4:
result = a1 + 3;
break;
case 5:
result = a1 - 10;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 12;
break;
case 6:
result = a1 - 3;
break;
case 7:
result = a1 - 13;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 9;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
}
return result;
}

original_code:
uint16_t just_ahead(uint16_t id, uint8_t dir) {
 if (id > 2*4*(4 -1))
  return id;
 _Bool vertical = (id <= 4*(4 -1));
 switch (dir) {
  case 0:
   return (id - (4 -1));
  case 4:
   return (id + 4 -1);
  case 2:
   return (id + 4 -1);
  case 6:
   return (id - (4 -1));
  case 1:
   if (vertical)
    return ((id + 4*(4 -1)) + 4 -2);
   else
    return (id - 4*(4 -1));
  case 3:
   if (vertical)
    return ((id + 4*(4 -1)) + 4 -1);
   else
    return ((id - 4*(4 -1)) + 4 -1);
  case 5:
   if (vertical)
    return (id + 4*(4 -1));
   else
    return ((id - 4*(4 -1)) + 4 -2);
  case 7:
   if (vertical)
    return ((id + 4*(4 -1)) - (4 -1));
   else
    return ((id - 4*(4 -1)) - 1);
  default:
   return 0xffff;
 }
}

canonical_original_code:
unsigned short just_ahead(unsigned short id, unsigned char dir) {
 if (id > 2*4*(4 -1))
  return id;
 _Bool vertical = (id <= 4*(4 -1));
 switch (dir) {
  case 0:
   return (id - (4 -1));
  case 4:
   return (id + 4 -1);
  case 2:
   return (id + 4 -1);
  case 6:
   return (id - (4 -1));
  case 1:
   if (vertical)
    return ((id + 4*(4 -1)) + 4 -2);
   else
    return (id - 4*(4 -1));
  case 3:
   if (vertical)
    return ((id + 4*(4 -1)) + 4 -1);
   else
    return ((id - 4*(4 -1)) + 4 -1);
  case 5:
   if (vertical)
    return (id + 4*(4 -1));
   else
    return ((id - 4*(4 -1)) + 4 -2);
  case 7:
   if (vertical)
    return ((id + 4*(4 -1)) - (4 -1));
   else
    return ((id - 4*(4 -1)) - 1);
  default:
   return 0xffff;
 }
}

variable_types:
id
unsigned short

variable_types:
dir
unsigned char


decompiled_code:
__int64 __fastcall node_at(unsigned __int16 a1, __int64 a2)
{
__int64 result; // rax

result = 0LL;
if ( a1 <= 0x18u )
{
if ( a1 <= 0xCu )
result = *(unsigned __int8 *)(a2 + 4LL * ((a1 & 3) + 4 * (unsigned __int8)(a1 >> 2)) + 1);
else
result = *(unsigned __int8 *)(a2 + 4LL * ((unsigned __int8)(a1 >> 2) + 4 * (a1 & 3)) + 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 a1, __int64 a2)
{
__int64 result; // rax

result = 0LL;
if ( a1 <= 0x18u )
{
if ( a1 <= 0xCu )
result = *(unsigned __int8 *)(a2 + 4LL * ((a1 & 3) + 4 * (unsigned __int8)(a1 >> 2)) + 1);
else
result = *(unsigned __int8 *)(a2 + 4LL * ((unsigned __int8)(a1 >> 2) + 4 * (a1 & 3)) + 2);
}
return result;
}

original_code:
_Bool node_at(uint16_t id, struct square *m) {
 if (id > 2*4*(4 -1))
  return 0;
 uint8_t i,j;
 if (id <= 4*(4 -1)) {
  i = id / 4;
  j = id % 4;
  return m[ 4 * i + j].w[1];
 }
 j = id / 4;
 i = id % 4;
 return m[ 4 * i + j].w[2];
}

canonical_original_code:
_Bool node_at(unsigned short id, struct square *m) {
 if (id > 2*4*(4 -1))
  return 0;
 unsigned char i; unsigned char j;
 if (id <= 4*(4 -1)) {
  i = id / 4;
  j = id % 4;
  return m[ 4 * i + j].w[1];
 }
 j = id / 4;
 i = id % 4;
 return m[ 4 * i + j].w[2];
}

variable_types:
m
struct square { _Bool w[4]; } *

variable_types:
i
unsigned char

variable_types:
j
unsigned char


hash

decompiled_code:
__int64 __fastcall hash(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
unsigned __int16 v3; // si

printf("hash: nd->id=%u\n", *(_WORD *)(a1 + 2) % 6u);
v2 = *(_QWORD *)(a2 + 8LL * (*(_WORD *)(a1 + 2) % 6u));
printf("nxt_in_tbl=NULL? %d\n", *(_QWORD *)(v2 + 8) == 0LL);
while ( 1 )
{
v3 = *(_WORD *)(v2 + 2);
if ( v3 == *(_WORD *)(a1 + 2) )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
{
puts("hash: returning NULL");
return v2;
}
}
printf("hash: returned p->id= %u\n", v3);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
unsigned __int16 v3; // si

printf("hash: nd->id=%u\n", *(_WORD *)(a1 + 2) % 6u);
v2 = *(_QWORD *)(a2 + 8LL * (*(_WORD *)(a1 + 2) % 6u));
printf("nxt_in_tbl=NULL? %d\n", *(_QWORD *)(v2 + 8) == 0LL);
while ( 1 )
{
v3 = *(_WORD *)(v2 + 2);
if ( v3 == *(_WORD *)(a1 + 2) )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
{
puts("hash: returning NULL");
return v2;
}
}
printf("hash: returned p->id= %u\n", v3);
return v2;
}

original_code:
struct node* hash(struct node *nd, struct tbl *tbl) {
 struct node *p;
 printf("hash: nd->id=%u\n",nd->id % (4 * (4 - 1) / 2));
    p = tbl->t[nd->id % (4 * (4 - 1) / 2)];
 printf("nxt_in_tbl=NULL? %d\n",(p->nxt_in_tbl==((void *)0)) ? 1:0);
 while (p != ((void *)0)) {
  if (p->id == nd->id) break;
  else p = p->nxt_in_tbl;
 }
 if (p != ((void *)0))
  printf("hash: returned p->id= %u\n",p->id);
 else
  printf("hash: returning NULL\n");
 return p;
}

canonical_original_code:
struct node *hash(struct node *nd, struct tbl *tbl) {
 struct node *p;
 printf("hash: nd->id=%u\n",nd->id % (4 * (4 - 1) / 2));
    p = tbl->t[nd->id % (4 * (4 - 1) / 2)];
 printf("nxt_in_tbl=NULL? %d\n",(p->nxt_in_tbl==((void *)0)) ? 1:0);
 while (p != ((void *)0)) {
  if (p->id == nd->id) break;
  else p = p->nxt_in_tbl;
 }
 if (p != ((void *)0))
  printf("hash: returned p->id= %u\n",p->id);
 else
  printf("hash: returning NULL\n");
 return p;
}

variable_types:
nd
struct node *

return_type: struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } *

user_defined_types: struct tbl { struct node *t[-1]; unsigned short n_tbl; }


original_code:
void update_tbl(struct nbhs *nbhs, struct tbl *tbl) {
 uint16_t k;
 struct node *c;
 _Bool added = 0;
 for (uint8_t i = 1; i <= nbhs->n_nbhs; ++i) {
  k = nbhs->n[i].id % (4 * (4 - 1) / 2);
  printf("update_tbl: index = %u\n",k);
  c = tbl->t[k];
  if (c == ((void *)0)) {
   c = malloc(sizeof(struct node));
   c->id = nbhs->n[i].id;
   c->time = nbhs->n[i].time;
   c->pre = nbhs->n[0].id;
   c->nxt_in_tbl = ((void *)0);
   tbl->t[k] = c;
  }
  while (c != ((void *)0)) {
   if (c->id == nbhs->n[i].id) {
    if (nbhs->n[i].time < c->time) {
     c->time = nbhs->n[i].time;
     c->pre = nbhs->n[0].id;
    }
    added = 1;
    break;
   }
   if (c->nxt_in_tbl == ((void *)0)) break;
   else c = c->nxt_in_tbl;
  }
  if (!added && c->nxt_in_tbl == ((void *)0)) {
   c->nxt_in_tbl = malloc(sizeof(struct node));
   c = c->nxt_in_tbl;
   c->id = nbhs->n[i].id;
   c->time = nbhs->n[i].time;
   c->pre = nbhs->n[0].id;
   c->nxt_in_tbl = ((void *)0);
  }
 }
 return;
}

canonical_original_code:
void update_tbl(struct nbhs *nbhs, struct tbl *tbl) {
 unsigned short k;
 struct node *c;
 _Bool added = 0;
 for (unsigned char i = 1; i <= nbhs->n_nbhs; ++i) {
  k = nbhs->n[i].id % (4 * (4 - 1) / 2);
  printf("update_tbl: index = %u\n",k);
  c = tbl->t[k];
  if (c == ((void *)0)) {
   c = malloc(sizeof(struct node));
   c->id = nbhs->n[i].id;
   c->time = nbhs->n[i].time;
   c->pre = nbhs->n[0].id;
   c->nxt_in_tbl = ((void *)0);
   tbl->t[k] = c;
  }
  while (c != ((void *)0)) {
   if (c->id == nbhs->n[i].id) {
    if (nbhs->n[i].time < c->time) {
     c->time = nbhs->n[i].time;
     c->pre = nbhs->n[0].id;
    }
    added = 1;
    break;
   }
   if (c->nxt_in_tbl == ((void *)0)) break;
   else c = c->nxt_in_tbl;
  }
  if (!added && c->nxt_in_tbl == ((void *)0)) {
   c->nxt_in_tbl = malloc(sizeof(struct node));
   c = c->nxt_in_tbl;
   c->id = nbhs->n[i].id;
   c->time = nbhs->n[i].time;
   c->pre = nbhs->n[0].id;
   c->nxt_in_tbl = ((void *)0);
  }
 }
 return;
}

variable_types: struct nbhs { struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } n[-1]; unsigned short n_nbhs; } *

variable_types:
k
unsigned short

user_defined_types: struct nbhs { struct node n[-1]; unsigned short n_nbhs; }


parent

decompiled_code:
__int16 __fastcall parent(unsigned __int16 a1)
{
__int16 result; // ax

result = a1 >> 1;
if ( a1 == 1 )
result = 1;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func8(unsigned __int16 a1)
{
__int16 result; // ax

result = a1 >> 1;
if ( a1 == 1 )
result = 1;
return result;
}

canonical_original_code:
unsigned short parent(unsigned short c) {
 return ((c == 1) ? 1 : (c >> 1));
}


original_code:
void update_heap(struct nbhs *nbhs, struct heap *heap, struct maze *maze, struct tbl *tbl) {
 uint16_t nc, np;
 struct node *temp;
 for (int8_t i = 1; i <= nbhs->n_nbhs; ++i) {
  nc = ++heap->n_heap;
  heap->h[nc] = hash(&(nbhs->n[i]),tbl);
  if (heap->h[nc] != ((void *)0))
   printf("hash: returned p->id= %u\n",heap->h[nc]->id);
  else
   printf("hash: returning NULL\n");
  np = parent(nc);
  while (heap->h[np]->time > heap->h[nc]->time) {
   temp = heap->h[np];
   heap->h[np] = heap->h[nc];
   heap->h[nc] = temp;
   nc = np;
   np = parent(nc);
  }
  if (heap->n_heap == 258)
   --heap->n_heap;
 }
 return;
}

canonical_original_code:
void update_heap(struct nbhs *nbhs, struct heap *heap, struct maze *maze, struct tbl *tbl) {
 unsigned short nc; unsigned short np;
 struct node *temp;
 for (char i = 1; i <= nbhs->n_nbhs; ++i) {
  nc = ++heap->n_heap;
  heap->h[nc] = hash(&(nbhs->n[i]),tbl);
  if (heap->h[nc] != ((void *)0))
   printf("hash: returned p->id= %u\n",heap->h[nc]->id);
  else
   printf("hash: returning NULL\n");
  np = parent(nc);
  while (heap->h[np]->time > heap->h[nc]->time) {
   temp = heap->h[np];
   heap->h[np] = heap->h[nc];
   heap->h[nc] = temp;
   nc = np;
   np = parent(nc);
  }
  if (heap->n_heap == 258)
   --heap->n_heap;
 }
 return;
}

variable_types: struct heap { struct node *h[258]; unsigned short n_heap; } *

variable_types:
nc
unsigned short

variable_types:
np
unsigned short

variable_types: i char

user_defined_types: struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; }


original_code:
void fastest_path(struct maze *maze, struct tbl *tbl) {
 tbl->n_tbl = 0;
 for (uint16_t i = 0; i < (4 * (4 - 1) / 2); ++i)
  tbl->t[i] = ((void *)0);
 struct heap *heap = malloc(sizeof(struct heap));
 struct nbhs *nbhs = malloc(sizeof(struct nbhs));
 nbhs->n_nbhs = 1;
 nbhs->n[0].id = 0xffff;
 nbhs->n[0].time = 87;
 nbhs->n[1].id = maze->start_id;
 nbhs->n[1].time = 0;
 update_tbl(nbhs,tbl);
 heap->h[1] = hash(&(nbhs->n[1]),tbl);
 heap->n_heap = 1;
 do {
  pop(heap,tbl,maze);
  get_nbhs(heap->h[0],nbhs,maze);
  printf("nnb=%u\n",nbhs->n_nbhs);
  update_tbl(nbhs,tbl);
  update_heap(nbhs,heap,maze,tbl);
  printf("nhp=%u\n",heap->n_heap);
 } while (heap->h[0]->id != maze->end_id);
 free(heap);
 free(nbhs);
 return;
}

canonical_original_code:
void fastest_path(struct maze *maze, struct tbl *tbl) {
 tbl->n_tbl = 0;
 for (unsigned short i = 0; i < (4 * (4 - 1) / 2); ++i)
  tbl->t[i] = ((void *)0);
 struct heap *heap = malloc(sizeof(struct heap));
 struct nbhs *nbhs = malloc(sizeof(struct nbhs));
 nbhs->n_nbhs = 1;
 nbhs->n[0].id = 0xffff;
 nbhs->n[0].time = 87;
 nbhs->n[1].id = maze->start_id;
 nbhs->n[1].time = 0;
 update_tbl(nbhs,tbl);
 heap->h[1] = hash(&(nbhs->n[1]),tbl);
 heap->n_heap = 1;
 do {
  pop(heap,tbl,maze);
  get_nbhs(heap->h[0],nbhs,maze);
  printf("nnb=%u\n",nbhs->n_nbhs);
  update_tbl(nbhs,tbl);
  update_heap(nbhs,heap,maze,tbl);
  printf("nhp=%u\n",heap->n_heap);
 } while (heap->h[0]->id != maze->end_id);
 free(heap);
 free(nbhs);
 return;
}

variable_types: struct maze { unsigned short start_id; unsigned short end_id; struct square { _Bool w[4]; } *m; } *

variable_types: struct tbl { struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } *t[-1]; unsigned short n_tbl; } *

variable_types:
i
unsigned short

variable_types: struct heap { struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } *h[258]; unsigned short n_heap; } *


decompiled_code:
__int64 __fastcall id_to_draw_pos(unsigned __int16 a1)
{
unsigned __int8 v1; // cl

if ( a1 > 0xCu )
v1 = 2 * (a1 % 3u);
else
v1 = 2 * (a1 / 3u) + 1;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1)
{
unsigned __int8 v1; // cl

if ( a1 > 0xCu )
v1 = 2 * (a1 % 3u);
else
v1 = 2 * (a1 / 3u) + 1;
return v1;
}

original_code:
struct pos id_to_draw_pos(uint16_t id) {
 struct pos ij;
 uint8_t row,col;
 if (id <= 4 * (4 - 1)) {
  row = id / (4 - 1);
  col = id % (4 - 1);
  ij.i = 2 * row + 1;
  ij.j = 3 * col;
 } else {
  col = id / (4 - 1);
  row = id % (4 - 1);
  ij.i = 2 * row;
  ij.j = 3 * col + 1;
 }
 return ij;
}

canonical_original_code:
struct pos id_to_draw_pos(unsigned short id) {
 struct pos ij;
 unsigned char row; unsigned char col;
 if (id <= 4 * (4 - 1)) {
  row = id / (4 - 1);
  col = id % (4 - 1);
  ij.i = 2 * row + 1;
  ij.j = 3 * col;
 } else {
  col = id / (4 - 1);
  row = id % (4 - 1);
  ij.i = 2 * row;
  ij.j = 3 * col + 1;
 }
 return ij;
}

variable_types: struct pos { unsigned char i; unsigned char j; }

variable_types:
row
unsigned char

variable_types:
col
unsigned char