decompiled_code:
void __fastcall hashtab_destroy(void *ptr)
{
int v2; // eax
char *v3; // rdi
unsigned int v4; // er12
__int64 v5; // rbp
char *v6; // rax
_QWORD *v7; // rbx
void *v8; // rdi

if ( ptr )
{
v2 = *((_DWORD *)ptr + 2);
v3 = *(char **)ptr;
if ( v2 )
{
v4 = 0;
do
{
v5 = 8LL * v4;
v6 = &v3[v5];
v7 = *(_QWORD **)&v3[v5];
if ( v7 )
{
do
{
v8 = v7;
v7 = (_QWORD *)v7[2];
free(v8);
}
while ( v7 );
v3 = *(char **)ptr;
v6 = (char *)(*(_QWORD *)ptr + v5);
}
*(_QWORD *)v6 = 0LL;
++v4;
}
while ( *((_DWORD *)ptr + 2) > v4 );
}
free(v3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
int v2; // eax
char *v3; // rdi
unsigned int v4; // er12
__int64 v5; // rbp
char *v6; // rax
_QWORD *v7; // rbx
void *v8; // rdi

if ( ptr )
{
v2 = *((_DWORD *)ptr + 2);
v3 = *(char **)ptr;
if ( v2 )
{
v4 = 0;
do
{
v5 = 8LL * v4;
v6 = &v3[v5];
v7 = *(_QWORD **)&v3[v5];
if ( v7 )
{
do
{
v8 = v7;
v7 = (_QWORD *)v7[2];
free(v8);
}
while ( v7 );
v3 = *(char **)ptr;
v6 = (char *)(*(_QWORD *)ptr + v5);
}
*(_QWORD *)v6 = 0LL;
++v4;
}
while ( *((_DWORD *)ptr + 2) > v4 );
}
free(v3);
free(ptr);
}
}

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

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

variable_types:
i
unsigned int


repo: pmer/yak

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

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

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

variable_types:
data
void *

variable_types:
str
char *

return_type: unsigned int

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


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

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

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

variable_types:
a
void *

variable_types:
b
void *

return_type: int

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


make

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

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

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

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

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

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

variable_types:
usr
char *

variable_types:
src
char *

variable_types:
msg
char *

variable_types: pid int

variable_types: status int

return_type: void


init

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

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

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


finish

decompiled_code:
void finish()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void finish()
{
}

canonical_original_code:
void finish()
{
}


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

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

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


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

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

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

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

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

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

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

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

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

variable_types: matches int

variable_types: ncap int

variable_types: i int

variable_types:
caps
char *[10]

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

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


decompiled_code:
void __fastcall handle_privmsg(char *s, __int64 a2, const char *a3)
{
char *v4; // rax
const char *v5; // r14
__int64 v6; // r13
size_t v7; // rax
__int64 v8; // rdx
char *v9; // rsi
char *v10; // rbp

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

canonical_decompiled_code:
void __fastcall func4(char *s, __int64 a2, const char *a3)
{
char *v4; // rax
const char *v5; // r14
__int64 v6; // r13
size_t v7; // rax
__int64 v8; // rdx
char *v9; // rsi
char *v10; // rbp

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

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

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

variable_types:
cmd
char *

variable_types:
spc
char *


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

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

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

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

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

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

variable_types:
str
char *


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

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

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


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

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

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

user_defined_types: struct list_head { struct list_head *next; }


decompiled_code:
__int64 __fastcall presence_del(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // r9
void *v3; // r9
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 40);
list_del_isra_0(*(_QWORD *)a1, *(_QWORD **)(a1 + 8));
list_del_isra_0(*(_QWORD *)(v2 + 16), *(_QWORD **)(v2 + 24));
free(v3);
result = list_empty((_QWORD *)(v1 + 2048));
if ( (_DWORD)result )
result = user_del(v1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // r9
void *v3; // r9
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 40);
func4(*(_QWORD *)a1, *(_QWORD **)(a1 + 8));
func4(*(_QWORD *)(v2 + 16), *(_QWORD **)(v2 + 24));
free(v3);
result = func3((_QWORD *)(v1 + 2048));
if ( (_DWORD)result )
result = user_del(v1);
return result;
}

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

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

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

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


info

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

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

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

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

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

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

variable_types:
format
char *


err

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

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

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

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

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

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


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

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

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

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

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

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

variable_types: err int


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

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

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

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

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

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

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


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

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

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

variable_types: code int


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

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

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

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

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


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

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

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

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

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


ping

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

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

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

variable_types:
usr
char *

variable_types:
src
char *

variable_types:
msg
char *

variable_types:
caps
char **

variable_types: ncaps int


init

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

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

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


finish

decompiled_code:
void finish()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void finish()
{
}


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

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

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

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

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

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

variable_types:
prefix
char *

variable_types: ncmd int

variable_types:
params
char *

variable_types:
len
unsigned long


init

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

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

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


version

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

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

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

variable_types:
version
char *


init

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


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

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

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

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

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


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


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

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

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

variable_types:
lib
char *


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

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

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


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

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

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

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

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

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

variable_types:
param
char *

variable_types:
value
char *

variable_types:
modes
char *

variable_types:
prefixes
char *

variable_types:
paren
char *


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

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

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

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

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


decompiled_code:
__int64 __fastcall isupport_token(const char *a1)
{
char v1; // bl
char *v2; // rax
bool v3; // zf
char *v4; // rsi

v1 = *a1;
v2 = strchr(a1, 61);
if ( !v2 || (v3 = v2[1] == 0, *v2 = 0, v4 = v2 + 1, v3) )
{
v4 = 0LL;
if ( v1 != 45 )
return isupport_set();
}
else if ( v1 != 45 )
{
return isupport_set();
}
return isupport_unset(a1, v4);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
char v1; // bl
char *v2; // rax
bool v3; // zf
char *v4; // rsi

v1 = *a1;
v2 = strchr(a1, 61);
if ( !v2 || (v3 = v2[1] == 0, *v2 = 0, v4 = v2 + 1, v3) )
{
v4 = 0LL;
if ( v1 != 45 )
return func6();
}
else if ( v1 != 45 )
{
return func6();
}
return func7(a1, v4);
}

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

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

variable_types:
tok
char *

variable_types:
equals
char *


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

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

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

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

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

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

variable_types:
save
char *


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

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


finish

canonical_decompiled_code:
void func11()
{
;
}


login

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

user_defined_types: struct evalctx { struct list_head events; }


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

v1 = *(_QWORD ***)ptr;
v2 = **(_QWORD ***)ptr;
if ( *(void **)ptr != ptr )
{
do
{
list_del_isra_0((__int64)v2, v1[1]);
free(v3);
v1 = (_QWORD **)v2;
v2 = (_QWORD *)*v2;
}
while ( ptr != v1 );
}
free(ptr);
}

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

v1 = *(_QWORD ***)ptr;
v2 = **(_QWORD ***)ptr;
if ( *(void **)ptr != ptr )
{
do
{
func9((__int64)v2, v1[1]);
free(v3);
v1 = (_QWORD **)v2;
v2 = (_QWORD *)*v2;
}
while ( ptr != v1 );
}
free(ptr);
}

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

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

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

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


original_code:
_Bool eval_emit(struct evalctx *ctx, char *line)
{
 eval_callback call;
 struct list_head *node;
 struct re_event *rev;
 int matches, ncap, i;
 _Bool called = 0;
 static char *caps[10];
 static char caps_buf[512 * 10];
 static _Bool need_init = 1;
 if (need_init) {
  need_init = 0;
  for (i = 0; i < 10; i++)
   caps[i] = &caps_buf[512 * i];
 }
 for (node = (&ctx->events)->next; node != (&ctx->events); node = node->next) {
  rev = ((struct re_event *)((char *)(node)-(unsigned long)(&((struct re_event *)0)->link)));
  matches = regex_match(&rev->match, line, caps);
  ncap = matches - 1;
  if (ncap >= 0) {
   rev->call(line, caps, ncap);
   called = 1;
  }
 }
 return called;
}

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

variable_types:
line
char *

variable_types: void (*)(char *line, char **caps, int ncap)

variable_types: matches int

variable_types: ncap int

variable_types: i int

variable_types:
caps
char *[10]

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


decompiled_code:
char *pref_find_yakrc()
{
char *result; // rax
char *v1; // rax
int v2; // er8

strcpy(buf_0, "./yakrc");
if ( !access(buf_0, 4)
|| (v1 = getenv("HOME"), strcpy(stpcpy(buf_0, v1), "/.yak/yakrc"), v2 = access(buf_0, 4), result = 0LL, !v2) )
{
result = buf_0;
}
return result;
}

canonical_decompiled_code:
char *func0()
{
char *result; // rax
char *v1; // rax
int v2; // er8

strcpy(buf_0, "./yakrc");
if ( !access(buf_0, 4)
|| (v1 = getenv("HOME"), strcpy(stpcpy(buf_0, v1), "/.yak/yakrc"), v2 = access(buf_0, 4), result = 0LL, !v2) )
{
result = buf_0;
}
return result;
}

original_code:
static char *pref_find_yakrc()
{
 static char buf[256];
 strcpy(buf, "./yakrc");
 if (access(buf, 4) == 0)
  return buf;
 strcpy(buf, getenv("HOME"));
 strcat(buf, "/.yak/yakrc");
 if (access(buf, 4) == 0)
  return buf;
 return ((void *)0);
}

variable_types:
buf
char [256]

return_type: char *


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

v0 = (void **)prefs;
v1 = *(void ***)prefs;
if ( prefs != &prefs )
{
do
{
free(v0);
v0 = v1;
v1 = (void **)*v1;
}
while ( v0 != &prefs );
}
}

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

v0 = (void **)prefs;
v1 = *(void ***)prefs;
if ( prefs != &prefs )
{
do
{
free(v0);
v0 = v1;
v1 = (void **)*v1;
}
while ( v0 != &prefs );
}
}

original_code:
void pref_finish()
{
 struct list_head *node, *next;
 struct pref *pref;
 for (node = (&prefs)->next, next = node->next; node != (&prefs); node = next, next = node->next) {
  pref = ((struct pref *)((char *)(node)-(unsigned long)(&((struct pref *)0)->link)));
  free(pref);
 }
}

canonical_original_code:
void pref_finish()
{
 struct list_head *node; struct list_head *next;
 struct pref *pref;
 for (node = (&prefs)->next, next = node->next; node != (&prefs); node = next, next = node->next) {
  pref = ((struct pref *)((char *)(node)-(unsigned long)(&((struct pref *)0)->link)));
  free(pref);
 }
}

variable_types: struct pref { struct list_head { struct list_head *next; } link; char value[-1]; } *

user_defined_types: struct pref { struct list_head link; char value[-1]; }


decompiled_code:
const char *__fastcall pref_get(char *s1)
{
int v1; // eax
const char *v2; // rbx
size_t v3; // r12
__int64 v4; // r14

v1 = strlen(s1);
v2 = (const char *)prefs;
if ( prefs == &prefs )
return 0LL;
v3 = v1;
v4 = v1;
while ( strncmp(s1, v2 + 16, v3) || v2[v4 + 16] != 32 )
{
v2 = *(const char **)v2;
if ( v2 == (const char *)&prefs )
return 0LL;
}
return &v2[v3 + 17];
}

canonical_decompiled_code:
const char *__fastcall func4(char *s1)
{
int v1; // eax
const char *v2; // rbx
size_t v3; // r12
__int64 v4; // r14

v1 = strlen(s1);
v2 = (const char *)prefs;
if ( prefs == &prefs )
return 0LL;
v3 = v1;
v4 = v1;
while ( strncmp(s1, v2 + 16, v3) || v2[v4 + 16] != 32 )
{
v2 = *(const char **)v2;
if ( v2 == (const char *)&prefs )
return 0LL;
}
return &v2[v3 + 17];
}

original_code:
char *pref_get(char *name)
{
 struct list_head *node;
 struct pref *pref;
 int len;
 len = strlen(name);
 for (node = (&prefs)->next; node != (&prefs); node = node->next) {
  pref = ((struct pref *)((char *)(node)-(unsigned long)(&((struct pref *)0)->link)));
  if (!strncmp(name, pref->value, len) && pref->value[len] == ' ')
   return pref->value + len + 1;
 }
 return ((void *)0);
}

variable_types:
name
char *

variable_types: len int


decompiled_code:
__int64 load_whoiam()
{
const char *v0; // rax
char *v1; // r12
__int64 v2; // rax
char *v3; // rbp
char *v4; // rax
char *v5; // rbx
size_t v6; // r13
int v7; // er12
char *v8; // rbx
size_t v9; // rbp
int v10; // er12

host = pref_get("host");
port = pref_get("port");
ssl = pref_get("secure");
v0 = (const char *)pref_get("nick");
bot_nick = strdup(v0);
bot_user = pref_get("user");
bot_real = pref_get("real");
nickservnick = pref_get("nickserv-nick");
bot_identify = pref_get("identify-pw");
bot_oper_name = pref_get("oper-name");
bot_oper_pw = pref_get("oper-pw");
v1 = (char *)pref_get("owners");
v2 = pref_get("channels");
bot_owners = 0LL;
v3 = (char *)v2;
v4 = strtok(v1, " ");
if ( v4 )
{
v5 = v4;
v6 = 16LL;
v7 = 0;
do
{
++v7;
bot_owners = realloc(bot_owners, v6);
*(_QWORD *)((char *)bot_owners + v6 - 16) = v5;
v6 += 8LL;
v5 = strtok(0LL, " ");
}
while ( v5 );
}
else
{
v7 = 0;
}
*((_QWORD *)bot_owners + v7) = 0LL;
bot_channels = 0LL;
v8 = strtok(v3, " ");
if ( v8 )
{
v9 = 16LL;
v10 = 0;
do
{
++v10;
bot_channels = realloc(bot_channels, v9);
*(_QWORD *)((char *)bot_channels + v9 - 16) = v8;
v9 += 8LL;
v8 = strtok(0LL, " ");
}
while ( v8 );
}
else
{
v10 = 0;
}
*((_QWORD *)bot_channels + v10) = 0LL;
return add_shutdown_fn(free_nick_owners_channels);
}

canonical_decompiled_code:
__int64 func0()
{
const char *v0; // rax
char *v1; // r12
__int64 v2; // rax
char *v3; // rbp
char *v4; // rax
char *v5; // rbx
size_t v6; // r13
int v7; // er12
char *v8; // rbx
size_t v9; // rbp
int v10; // er12

host = pref_get("host");
port = pref_get("port");
ssl = pref_get("secure");
v0 = (const char *)pref_get("nick");
bot_nick = strdup(v0);
bot_user = pref_get("user");
bot_real = pref_get("real");
nickservnick = pref_get("nickserv-nick");
bot_identify = pref_get("identify-pw");
bot_oper_name = pref_get("oper-name");
bot_oper_pw = pref_get("oper-pw");
v1 = (char *)pref_get("owners");
v2 = pref_get("channels");
bot_owners = 0LL;
v3 = (char *)v2;
v4 = strtok(v1, " ");
if ( v4 )
{
v5 = v4;
v6 = 16LL;
v7 = 0;
do
{
++v7;
bot_owners = realloc(bot_owners, v6);
*(_QWORD *)((char *)bot_owners + v6 - 16) = v5;
v6 += 8LL;
v5 = strtok(0LL, " ");
}
while ( v5 );
}
else
{
v7 = 0;
}
*((_QWORD *)bot_owners + v7) = 0LL;
bot_channels = 0LL;
v8 = strtok(v3, " ");
if ( v8 )
{
v9 = 16LL;
v10 = 0;
do
{
++v10;
bot_channels = realloc(bot_channels, v9);
*(_QWORD *)((char *)bot_channels + v9 - 16) = v8;
v9 += 8LL;
v8 = strtok(0LL, " ");
}
while ( v8 );
}
else
{
v10 = 0;
}
*((_QWORD *)bot_channels + v10) = 0LL;
return add_shutdown_fn(free_nick_owners_channels);
}

original_code:
static void load_whoiam()
{
 char *owners_str, *chan_str, *tok;
 int i;
 host = pref_get("host");
 port = pref_get("port");
 ssl = pref_get("secure");
 bot_nick = strdup(pref_get("nick"));
 bot_user = pref_get("user");
 bot_real = pref_get("real");
 nickservnick = pref_get("nickserv-nick");
 bot_identify = pref_get("identify-pw");
 bot_oper_name = pref_get("oper-name");
 bot_oper_pw = pref_get("oper-pw");
 owners_str = pref_get("owners");
 chan_str = pref_get("channels");
 bot_owners = ((void *)0);
 for (i = 0, tok = strtok(owners_str, " "); tok; i++, tok = strtok(((void *)0), " ")) {
  bot_owners = realloc(bot_owners, sizeof(char*) * (i + 2));
  bot_owners[i] = tok;
 }
 bot_owners[i] = ((void *)0);
 bot_channels = ((void *)0);
 for (i = 0, tok = strtok(chan_str, " "); tok; i++, tok = strtok(((void *)0), " ")) {
  bot_channels = realloc(bot_channels, sizeof(char*) * (i + 2));
  bot_channels[i] = tok;
 }
 bot_channels[i] = ((void *)0);
 add_shutdown_fn(free_nick_owners_channels);
}

canonical_original_code:
static void load_whoiam()
{
 char *owners_str; char *chan_str; char *tok;
 int i;
 host = pref_get("host");
 port = pref_get("port");
 ssl = pref_get("secure");
 bot_nick = strdup(pref_get("nick"));
 bot_user = pref_get("user");
 bot_real = pref_get("real");
 nickservnick = pref_get("nickserv-nick");
 bot_identify = pref_get("identify-pw");
 bot_oper_name = pref_get("oper-name");
 bot_oper_pw = pref_get("oper-pw");
 owners_str = pref_get("owners");
 chan_str = pref_get("channels");
 bot_owners = ((void *)0);
 for (i = 0, tok = strtok(owners_str, " "); tok; i++, tok = strtok(((void *)0), " ")) {
  bot_owners = realloc(bot_owners, sizeof(char *) * (i + 2));
  bot_owners[i] = tok;
 }
 bot_owners[i] = ((void *)0);
 bot_channels = ((void *)0);
 for (i = 0, tok = strtok(chan_str, " "); tok; i++, tok = strtok(((void *)0), " ")) {
  bot_channels = realloc(bot_channels, sizeof(char *) * (i + 2));
  bot_channels[i] = tok;
 }
 bot_channels[i] = ((void *)0);
 add_shutdown_fn(free_nick_owners_channels);
}

variable_types:
tok
char *


canonical_decompiled_code:
void func1()
{
free(bot_nick);
free(bot_owners);
free(bot_channels);
}

original_code:
static void free_nick_owners_channels()
{
 free(bot_nick);
 free(bot_owners);
 free(bot_channels);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
__int64 v4; // rdx
__int64 v6; // rdx
char *v7; // rbx
unsigned int v8; // [rsp+4h] [rbp-24h] BYREF
const char *v9; // [rsp+8h] [rbp-20h] BYREF
const char **v10; // [rsp+10h] [rbp-18h] BYREF
__int64 v11; // [rsp+18h] [rbp-10h] BYREF

::argv = (__int64)argv;
++nthreads;
mutex_on(argc, argv, envp);
pref_init();
load_whoiam();
callback_init();
sock_init();
usr_init();
chan_init();
auth_init();
privmsg_init();
info("loading plugins from plugins.txt");
v3 = "plugins.txt";
plg_load_plgs_from("plugins.txt");
mutex_off();
--nthreads;
if ( !want_quit )
{
establish_connection(host, port, ssl);
ircproto_nick(bot_nick);
ircproto_user(bot_user, bot_real);
argv = (const char **)bot_identify;
if ( bot_identify )
ircproto_identify(nickservnick);
v3 = (const char *)bot_oper_name;
if ( bot_oper_name )
{
argv = (const char **)bot_oper_pw;
if ( bot_oper_pw )
ircproto_oper();
}
while ( !want_quit )
{
ircproto_read_message(&v9, &v10, &v8, &v11);
mutex_on(&v9, &v10, v6);
argv = (const char **)v8;
if ( v8 )
{
v3 = v9;
callback_emit_numeric(v9, v8, v11);
if ( v8 != 1 )
goto LABEL_9;
}
else
{
argv = v10;
v3 = v9;
callback_emit_str(v9, v10, v11);
if ( v8 != 1 )
goto LABEL_9;
}
v7 = (char *)bot_channels;
v3 = *(const char **)bot_channels;
if ( *(_QWORD *)bot_channels )
{
do
{
ircproto_join();
v3 = (const char *)*((_QWORD *)v7 + 1);
v7 += 8;
}
while ( v3 );
}
LABEL_9:
mutex_off();
}
}
mutex_on(v3, argv, v4);
safe_shutdown();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
__int64 v4; // rdx
__int64 v6; // rdx
char *v7; // rbx
unsigned int v8; // [rsp+4h] [rbp-24h] BYREF
const char *v9; // [rsp+8h] [rbp-20h] BYREF
const char **v10; // [rsp+10h] [rbp-18h] BYREF
__int64 v11; // [rsp+18h] [rbp-10h] BYREF

::argv = (__int64)argv;
++nthreads;
mutex_on(argc, argv, envp);
pref_init();
func0();
callback_init();
sock_init();
usr_init();
chan_init();
auth_init();
privmsg_init();
info("loading plugins from plugins.txt");
v3 = "plugins.txt";
plg_load_plgs_from("plugins.txt");
mutex_off();
--nthreads;
if ( !want_quit )
{
establish_connection(host, port, ssl);
ircproto_nick(bot_nick);
ircproto_user(bot_user, bot_real);
argv = (const char **)bot_identify;
if ( bot_identify )
ircproto_identify(nickservnick);
v3 = (const char *)bot_oper_name;
if ( bot_oper_name )
{
argv = (const char **)bot_oper_pw;
if ( bot_oper_pw )
ircproto_oper();
}
while ( !want_quit )
{
ircproto_read_message(&v9, &v10, &v8, &v11);
mutex_on(&v9, &v10, v6);
argv = (const char **)v8;
if ( v8 )
{
v3 = v9;
callback_emit_numeric(v9, v8, v11);
if ( v8 != 1 )
goto LABEL_9;
}
else
{
argv = v10;
v3 = v9;
callback_emit_str(v9, v10, v11);
if ( v8 != 1 )
goto LABEL_9;
}
v7 = (char *)bot_channels;
v3 = *(const char **)bot_channels;
if ( *(_QWORD *)bot_channels )
{
do
{
ircproto_join();
v3 = (const char *)*((_QWORD *)v7 + 1);
v7 += 8;
}
while ( v3 );
}
LABEL_9:
mutex_off();
}
}
mutex_on(v3, argv, v4);
safe_shutdown();
return 0;
}

original_code:
int main(int argc, char **_argv)
{
 char *prefix, *cmd, *params;
 char **chans;
 int ncmd, i;
 argv = _argv;
 nthreads++;
 mutex_on();
 pref_init();
 load_whoiam();
 callback_init();
 sock_init();
 usr_init();
 chan_init();
 auth_init();
 privmsg_init();
 info("loading plugins from plugins.txt");
 plg_load_plgs_from("plugins.txt");
 mutex_off();
 nthreads--;
 if (want_quit)
  goto shutdown;
 establish_connection(host, port, ssl);
 ircproto_nick(bot_nick);
 ircproto_user(bot_user, bot_real);
 if (bot_identify)
  ircproto_identify(nickservnick, bot_identify);
 if (bot_oper_name && bot_oper_pw)
  ircproto_oper(bot_oper_name, bot_oper_pw);
 while (!want_quit) {
  ircproto_read_message(&prefix, &cmd, &ncmd, &params);
  mutex_on();
  if (ncmd)
   callback_emit_numeric(prefix, ncmd, params);
  else
   callback_emit_str(prefix, cmd, params);
  if (ncmd == 1) {
   for (chans = bot_channels; *chans; chans++)
    ircproto_join(*chans);
  }
  mutex_off();
 }
shutdown:
 mutex_on();
 safe_shutdown();
 return 0;
}

canonical_original_code:
int main(int argc, char **_argv)
{
 char *prefix; char *cmd; char *params;
 char **chans;
 int ncmd; int i;
 argv = _argv;
 nthreads++;
 mutex_on();
 pref_init();
 load_whoiam();
 callback_init();
 sock_init();
 usr_init();
 chan_init();
 auth_init();
 privmsg_init();
 info("loading plugins from plugins.txt");
 plg_load_plgs_from("plugins.txt");
 mutex_off();
 nthreads--;
 if (want_quit)
  goto shutdown;
 establish_connection(host, port, ssl);
 ircproto_nick(bot_nick);
 ircproto_user(bot_user, bot_real);
 if (bot_identify)
  ircproto_identify(nickservnick, bot_identify);
 if (bot_oper_name && bot_oper_pw)
  ircproto_oper(bot_oper_name, bot_oper_pw);
 while (!want_quit) {
  ircproto_read_message(&prefix, &cmd, &ncmd, &params);
  mutex_on();
  if (ncmd)
   callback_emit_numeric(prefix, ncmd, params);
  else
   callback_emit_str(prefix, cmd, params);
  if (ncmd == 1) {
   for (chans = bot_channels; *chans; chans++)
    ircproto_join(*chans);
  }
  mutex_off();
 }
shutdown:
 mutex_on();
 safe_shutdown();
 return 0;
}

variable_types: argc int

variable_types:
prefix
char *

variable_types:
cmd
char *

variable_types:
params
char *

variable_types:
chans
char **

variable_types: ncmd int


decompiled_code:
__int64 handle_ping()
{
return ircproto_pong();
}

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

original_code:
static void handle_ping(char *prefix, char *cmd, char *params)
{
 ircproto_pong(params);
}


init

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

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

original_code:
int init()
{
 callback_register_str(handle_ping, "PING");
 return 0;
}


finish

decompiled_code:
void finish()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void finish()
{
}

canonical_original_code:
void finish()
{
}


repo: pmkenned/monopoly

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

result = *(_QWORD *)(a1 + 8);
++*(_DWORD *)(result + 216LL * *(int *)(a1 + 24) + 208);
return result;
}

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

result = *(_QWORD *)(a1 + 8);
++*(_DWORD *)(result + 216LL * *(int *)(a1 + 24) + 208);
return result;
}

original_code:
void cc_get_out_of_jail(Game_state_t * gs_p) {
    int p_i = gs_p->turn.player_index;
    Player_t * p_p = &(gs_p->players[p_i]);
    p_p->num_get_out_of_jail_free++;
}

canonical_original_code:
void cc_get_out_of_jail(struct game_state_s *gs_p) {
    int p_i = gs_p->turn.player_index;
    struct player_s *p_p = &(gs_p->players[p_i]);
    p_p->num_get_out_of_jail_free++;
}

variable_types: struct game_state_s { int num_players; int num_active_players; struct player_s { int index; char *name; enum piece_type_e { SHOE=0, HORSE=1, DOG=2, BATTLE=3, IRON=4, SPINNING=5, TOPHAT=6, THIMBLE=7, WHEELBARROW=8 } piece_type; int cash; int liquid_assets; int taxable_assets; int location_index; int bankrupt; int property[40]; int in_jail; int rolls_in_jail; int num_get_out_of_jail_free; } *players; struct player_s *winner; struct turn_s { int player_index; int die1; int doubles; int roll_double_count; int has_rolled; int on_unowned; int in_debt; int debt_total; int *debts; } turn; int game_over; } *

user_defined_types: struct game_state_s { int num_players; int num_active_players; struct player_s *players; struct player_s *winner; struct turn_s turn; int game_over; }

user_defined_types: struct player_s { int index; char *name; enum piece_type_e piece_type; int cash; int liquid_assets; int taxable_assets; int location_index; int bankrupt; int property[40]; int in_jail; int rolls_in_jail; int num_get_out_of_jail_free; }


birthday

decompiled_code:
void birthday()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void birthday(Game_state_t * gs_p) {
}

canonical_original_code:
void birthday(struct game_state_s *gs_p) {
}

user_defined_types: struct turn_s { int player_index; int die1; int doubles; int roll_double_count; int has_rolled; int on_unowned; int in_debt; int debt_total; int *debts; }

user_defined_types: enum piece_type_e { SHOE=0, HORSE=1, DOG=2, BATTLE=3, IRON=4, SPINNING=5, TOPHAT=6, THIMBLE=7, WHEELBARROW=8 }


original_code:
void cc_advance_to_go(Game_state_t * gs_p) {
    int p_i = gs_p->turn.player_index;
    Player_t * p_p = &(gs_p->players[p_i]);
    p_p->location_index = GO_L;
    credit_player(p_p, 200);
}

canonical_original_code:
void cc_advance_to_go(struct game_state_s *gs_p) {
    int p_i = gs_p->turn.player_index;
    struct player_s *p_p = &(gs_p->players[p_i]);
    p_p->location_index = GO_L;
    credit_player(p_p, 200);
}

variable_types: struct player_s { int index; char *name; enum piece_type_e { SHOE=0, HORSE=1, DOG=2, BATTLE=3, IRON=4, SPINNING=5, TOPHAT=6, THIMBLE=7, WHEELBARROW=8 } piece_type; int cash; int liquid_assets; int taxable_assets; int location_index; int bankrupt; int property[40]; int in_jail; int rolls_in_jail; int num_get_out_of_jail_free; } *


decompiled_code:
__int64 __fastcall bank_error(__int64 a1)
{
return credit_player(*(_QWORD *)(a1 + 8) + 216LL * *(int *)(a1 + 24), 75LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return credit_player(*(_QWORD *)(a1 + 8) + 216LL * *(int *)(a1 + 24), 75LL);
}

original_code:
void bank_error(Game_state_t * gs_p) {
    int p_i = gs_p->turn.player_index;
    Player_t * p_p = &(gs_p->players[p_i]);
    credit_player(p_p,75);
}

canonical_original_code:
void bank_error(struct game_state_s *gs_p) {
    int p_i = gs_p->turn.player_index;
    struct player_s *p_p = &(gs_p->players[p_i]);
    credit_player(p_p,75);
}


doctor

decompiled_code:
__int64 __fastcall doctor(unsigned int *a1)
{
return indebt_current_player(a1 + 6, *a1, 50LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
return indebt_current_player(a1 + 6, *a1, 50LL);
}

original_code:
void doctor(Game_state_t * gs_p) {
    int bank = gs_p->num_players;
    indebt_current_player(&(gs_p->turn),bank,50);
}

canonical_original_code:
void doctor(struct game_state_s *gs_p) {
    int bank = gs_p->num_players;
    indebt_current_player(&(gs_p->turn),bank,50);
}

variable_types: bank int


decompiled_code:
__int64 __fastcall cc_go_to_jail(__int64 a1)
{
return enter_jail(*(_QWORD *)(a1 + 8) + 216LL * *(int *)(a1 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return enter_jail(*(_QWORD *)(a1 + 8) + 216LL * *(int *)(a1 + 24));
}

original_code:
void cc_go_to_jail(Game_state_t * gs_p) {
    int p_i = gs_p->turn.player_index;
    Player_t * p_p = &(gs_p->players[p_i]);
    enter_jail(p_p);
}

canonical_original_code:
void cc_go_to_jail(struct game_state_s *gs_p) {
    int p_i = gs_p->turn.player_index;
    struct player_s *p_p = &(gs_p->players[p_i]);
    enter_jail(p_p);
}


decompiled_code:
void holiday_fund()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void holiday_fund(Game_state_t * gs_p) {
}

canonical_original_code:
void holiday_fund(struct game_state_s *gs_p) {
}


decompiled_code:
void sale_of_stock()
{
;
}

original_code:
void sale_of_stock(Game_state_t * gs_p) {
}

canonical_original_code:
void sale_of_stock(struct game_state_s *gs_p) {
}


inherit

decompiled_code:
void inherit()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void inherit(Game_state_t * gs_p) {
}

canonical_original_code:
void inherit(struct game_state_s *gs_p) {
}


decompiled_code:
void beauty_contest()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void beauty_contest(Game_state_t * gs_p) {
}

canonical_original_code:
void beauty_contest(struct game_state_s *gs_p) {
}


decompiled_code:
void street_repairs()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
void street_repairs(Game_state_t * gs_p) {
}

canonical_original_code:
void street_repairs(struct game_state_s *gs_p) {
}


decompiled_code:
void consultancy_fee()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void consultancy_fee(Game_state_t * gs_p) {
}

canonical_original_code:
void consultancy_fee(struct game_state_s *gs_p) {
}


decompiled_code:
void school_fee()
{
;
}

canonical_decompiled_code:
void func13()
{
;
}

original_code:
void school_fee(Game_state_t * gs_p) {
}

canonical_original_code:
void school_fee(struct game_state_s *gs_p) {
}


decompiled_code:
void hospital_fee()
{
;
}

canonical_decompiled_code:
void func14()
{
;
}

original_code:
void hospital_fee(Game_state_t * gs_p) {
}

canonical_original_code:
void hospital_fee(struct game_state_s *gs_p) {
}


decompiled_code:
void life_insurance()
{
;
}

canonical_decompiled_code:
void func15()
{
;
}

original_code:
void life_insurance(Game_state_t * gs_p) {
}

canonical_original_code:
void life_insurance(struct game_state_s *gs_p) {
}


decompiled_code:
void income_tax_refund()
{
;
}

canonical_decompiled_code:
void func16()
{
;
}

original_code:
void income_tax_refund(Game_state_t * gs_p) {
}

canonical_original_code:
void income_tax_refund(struct game_state_s *gs_p) {
}


opera

decompiled_code:
void opera()
{
;
}

canonical_decompiled_code:
void func17()
{
;
}

original_code:
void opera(Game_state_t * gs_p) {
}

canonical_original_code:
void opera(struct game_state_s *gs_p) {
}


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

result = *(_QWORD *)(a1 + 8) + 216LL * *(int *)(a1 + 24);
*(_DWORD *)(result + 32) = 24;
return result;
}

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

result = *(_QWORD *)(a1 + 8) + 216LL * *(int *)(a1 + 24);
*(_DWORD *)(result + 32) = 24;
return result;
}

original_code:
void advance_to_illinois(Game_state_t * gs_p) {
    int p_i = gs_p->turn.player_index;
    Player_t * p_p = &(gs_p->players[p_i]);
    p_p->location_index = ILL_L;
}

canonical_original_code:
void advance_to_illinois(struct game_state_s *gs_p) {
    int p_i = gs_p->turn.player_index;
    struct player_s *p_p = &(gs_p->players[p_i]);
    p_p->location_index = ILL_L;
}


decompiled_code:
void advance_to_railroad()
{
;
}

original_code:
void advance_to_railroad(Game_state_t * gs_p) {
}

canonical_original_code:
void advance_to_railroad(struct game_state_s *gs_p) {
}


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

result = *(_QWORD *)(a1 + 8) + 216LL * *(int *)(a1 + 24);
*(_DWORD *)(result + 32) = 11;
return result;
}

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

result = *(_QWORD *)(a1 + 8) + 216LL * *(int *)(a1 + 24);
*(_DWORD *)(result + 32) = 11;
return result;
}

original_code:
void advance_to_stcharles(Game_state_t * gs_p) {
    int p_i = gs_p->turn.player_index;
    Player_t * p_p = &(gs_p->players[p_i]);
    p_p->location_index = STC_L;
}

canonical_original_code:
void advance_to_stcharles(struct game_state_s *gs_p) {
    int p_i = gs_p->turn.player_index;
    struct player_s *p_p = &(gs_p->players[p_i]);
    p_p->location_index = STC_L;
}


original_code:
void c_advance_to_go(Game_state_t * gs_p) {
    int p_i = gs_p->turn.player_index;
    Player_t * p_p = &(gs_p->players[p_i]);
    p_p->location_index = GO_L;
    credit_player(p_p, 200);
}

canonical_original_code:
void c_advance_to_go(struct game_state_s *gs_p) {
    int p_i = gs_p->turn.player_index;
    struct player_s *p_p = &(gs_p->players[p_i]);
    p_p->location_index = GO_L;
    credit_player(p_p, 200);
}


decompiled_code:
__int64 __fastcall bank_pays_dividend(__int64 a1)
{
return credit_player(*(_QWORD *)(a1 + 8) + 216LL * *(int *)(a1 + 24), 50LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return credit_player(*(_QWORD *)(a1 + 8) + 216LL * *(int *)(a1 + 24), 50LL);
}

original_code:
void bank_pays_dividend(Game_state_t * gs_p) {
    int p_i = gs_p->turn.player_index;
    Player_t * p_p = &(gs_p->players[p_i]);
    credit_player(p_p,50);
}

canonical_original_code:
void bank_pays_dividend(struct game_state_s *gs_p) {
    int p_i = gs_p->turn.player_index;
    struct player_s *p_p = &(gs_p->players[p_i]);
    credit_player(p_p,50);
}


decompiled_code:
int __fastcall advance_to_utility(__int64 a1)
{
__int64 v1; // rbp
int result; // eax

v1 = *(_QWORD *)(a1 + 8) + 216LL * *(int *)(a1 + 24);
if ( *(int *)(v1 + 32) > 11 )
{
puts("Advancing to Water Works");
*(_DWORD *)(v1 + 32) = 28;
if ( (locations[13440] & 1) != 0 )
goto LABEL_3;
}
else
{
puts("Advancing to the Electric Company");
*(_DWORD *)(v1 + 32) = 12;
if ( (locations[6016] & 1) != 0 )
{
LABEL_3:
roll_dice(a1);
return debit_player(v1, (unsigned int)(10 * (*(_DWORD *)(a1 + 28) + *(_DWORD *)(a1 + 32))));
}
}
printf("Would you like to buy the utility? ");
result = (unsigned int)fgets(&buffer, 400, stdin);
if ( buffer == 121 )
result = puts("TODO");
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
__int64 v1; // rbp
int result; // eax

v1 = *(_QWORD *)(a1 + 8) + 216LL * *(int *)(a1 + 24);
if ( *(int *)(v1 + 32) > 11 )
{
puts("Advancing to Water Works");
*(_DWORD *)(v1 + 32) = 28;
if ( (locations[13440] & 1) != 0 )
goto LABEL_3;
}
else
{
puts("Advancing to the Electric Company");
*(_DWORD *)(v1 + 32) = 12;
if ( (locations[6016] & 1) != 0 )
{
LABEL_3:
roll_dice(a1);
return debit_player(v1, (unsigned int)(10 * (*(_DWORD *)(a1 + 28) + *(_DWORD *)(a1 + 32))));
}
}
printf("Would you like to buy the utility? ");
result = (unsigned int)fgets(&buffer, 400, stdin);
if ( buffer == 121 )
result = puts("TODO");
return result;
}

original_code:
void advance_to_utility(Game_state_t * gs_p) {
    int p_i = gs_p->turn.player_index;
    Player_t * p_p = &(gs_p->players[p_i]);
    int l_i;
    int owned;
    int dice_sum;
    if(p_p->location_index < ELE_L) {
        printf("Advancing to the Electric Company\n");
        l_i = p_p->location_index = ELE_L;
    }
    else {
        printf("Advancing to Water Works\n");
        l_i = p_p->location_index = H2O_L;
    }
    owned = locations[l_i].ownership.owned;
    if(owned) {
        roll_dice(gs_p);
        dice_sum = gs_p->turn.die1 + gs_p->turn.die2;
        debit_player(p_p, 10*dice_sum);
    }
    else {
        printf("Would you like to buy the utility? ");
        fgets(buffer,400, stdin);
        if(strncmp(buffer,"y",1) == 0) {
            printf("TODO\n");
        }
    }
}

canonical_original_code:
void advance_to_utility(struct game_state_s *gs_p) {
    int p_i = gs_p->turn.player_index;
    struct player_s *p_p = &(gs_p->players[p_i]);
    int l_i;
    int owned;
    int dice_sum;
    if(p_p->location_index < ELE_L) {
        printf("Advancing to the Electric Company\n");
        l_i = p_p->location_index = ELE_L;
    }
    else {
        printf("Advancing to Water Works\n");
        l_i = p_p->location_index = H2O_L;
    }
    owned = locations[l_i].ownership.owned;
    if(owned) {
        roll_dice(gs_p);
        dice_sum = gs_p->turn.die1 + gs_p->turn.die2;
        debit_player(p_p, 10*dice_sum);
    }
    else {
        printf("Would you like to buy the utility? ");
        fgets(buffer,400, stdin);
        if(strncmp(buffer,"y",1) == 0) {
            printf("TODO\n");
        }
    }
}

variable_types: owned int


crossword

decompiled_code:
void crossword()
{
;
}

original_code:
void crossword(Game_state_t * gs_p) {
}

canonical_original_code:
void crossword(struct game_state_s *gs_p) {
}


decompiled_code:
void building_loan()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void building_loan(Game_state_t * gs_p) {
}

canonical_original_code:
void building_loan(struct game_state_s *gs_p) {
}


chairman

decompiled_code:
void chairman()
{
;
}

original_code:
void chairman(Game_state_t * gs_p) {
}

canonical_original_code:
void chairman(struct game_state_s *gs_p) {
}


decompiled_code:
void advance_to_boardwalk()
{
;
}

original_code:
void advance_to_boardwalk(Game_state_t * gs_p) {
}

canonical_original_code:
void advance_to_boardwalk(struct game_state_s *gs_p) {
}


decompiled_code:
void reading_railroad()
{
;
}

original_code:
void reading_railroad(Game_state_t * gs_p) {
}

canonical_original_code:
void reading_railroad(struct game_state_s *gs_p) {
}


decompiled_code:
void poor_tax()
{
;
}

original_code:
void poor_tax(Game_state_t * gs_p) {
}

canonical_original_code:
void poor_tax(struct game_state_s *gs_p) {
}


decompiled_code:
void general_repairs()
{
;
}

original_code:
void general_repairs(Game_state_t * gs_p) {
}

canonical_original_code:
void general_repairs(struct game_state_s *gs_p) {
}


decompiled_code:
void c_go_to_jail()
{
;
}

original_code:
void c_go_to_jail(Game_state_t * gs_p) {
}

canonical_original_code:
void c_go_to_jail(struct game_state_s *gs_p) {
}


decompiled_code:
void go_back_three()
{
;
}

original_code:
void go_back_three(Game_state_t * gs_p) {
}

canonical_original_code:
void go_back_three(struct game_state_s *gs_p) {
}


decompiled_code:
void c_get_out_of_jail()
{
;
}

original_code:
void c_get_out_of_jail(Game_state_t * gs_p) {
}

canonical_original_code:
void c_get_out_of_jail(struct game_state_s *gs_p) {
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
_BYTE v5[88]; // [rsp+0h] [rbp-58h] BYREF

while ( 1 )
{
puts("Choose an option:");
puts("1. New game");
puts("2. Load game");
fgets(&buffer, 400, stdin);
v3 = atoi(&buffer);
if ( v3 == 1 )
{
new_game(v5);
goto LABEL_6;
}
if ( v3 == 2 )
break;
puts("Invalid input");
}
load_game(v5);
LABEL_6:
game_loop(v5);
end_game(v5);
return 0;
}

original_code:
int main(int argc, char ** argv) {
    Game_state_t gs;
    int choice;
    while(1) {
        printf("Choose an option:\n");
        printf("1. New game\n");
        printf("2. Load game\n");
        fgets(buffer,400,stdin);
        choice = atoi(buffer);
        if(choice == 1) {
            new_game(&gs);
            break;
        }
        else if(choice == 2) {
            load_game(&gs);
            break;
        }
        else
            printf("Invalid input\n");
    }
    game_loop(&gs);
    end_game(&gs);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    struct game_state_s gs;
    int choice;
    while(1) {
        printf("Choose an option:\n");
        printf("1. New game\n");
        printf("2. Load game\n");
        fgets(buffer,400,stdin);
        choice = atoi(buffer);
        if(choice == 1) {
            new_game(&gs);
            break;
        }
        else if(choice == 2) {
            load_game(&gs);
            break;
        }
        else
            printf("Invalid input\n");
    }
    game_loop(&gs);
    end_game(&gs);
    return 0;
}

variable_types:
argv
char **

variable_types: struct game_state_s { int num_players; int num_active_players; struct player_s { int index; char *name; enum piece_type_e { SHOE=0, HORSE=1, DOG=2, BATTLE=3, IRON=4, SPINNING=5, TOPHAT=6, THIMBLE=7, WHEELBARROW=8 } piece_type; int cash; int liquid_assets; int taxable_assets; int location_index; int bankrupt; int property[40]; int in_jail; int rolls_in_jail; int num_get_out_of_jail_free; } *players; struct player_s *winner; struct turn_s { int player_index; int die1; int doubles; int roll_double_count; int has_rolled; int on_unowned; int in_debt; int debt_total; int *debts; } turn; int game_over; }

variable_types: choice int


repo: pmnair/zwave-remote

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct _IO_FILE *v3; // rdi
int v4; // er13
unsigned int v6; // [rsp+0h] [rbp-38h] BYREF
int v7; // [rsp+4h] [rbp-34h] BYREF
char v8[48]; // [rsp+8h] [rbp-30h] BYREF

puts("In main");
v3 = stdout;
fflush(stdout);
print_cmd_classes(v3, argv);
if ( (unsigned int)zw_api_init("/dev/ttyUSB0", v8) )
{
v4 = 1;
puts("zWave API Init failed");
}
else
{
v4 = 0;
sleep(3u);
zw_list_nodes();
do
{
puts("\n=== MENU ===");
puts("1. List Nodes");
puts("2. Switch state ON");
puts("3. Switch state OFF");
puts("4. SWitch State Get");
puts("5. Get Sensor State");
puts("6. Get Sensor Battery Level");
puts("7. Set sensor interval");
puts("8. Get sensor interval");
puts("9. Exit");
_isoc99_scanf("%d", &v7);
switch ( v7 )
{
case 1:
zw_list_nodes();
break;
case 2:
v6 = 255;
zw_node_set_value(v8, 3LL, &v6);
break;
case 3:
v6 = 0;
zw_node_set_value(v8, 3LL, &v6);
break;
case 4:
zw_node_get_value(v8, 3LL, &v6);
printf("\n$$$$$$ Switch Value: %d\n", v6);
break;
case 5:
zw_node_get_value(v8, 4LL, &v6);
printf("\n$$$$$$ Sensor State Value: %d\n", v6);
break;
case 6:
zw_node_get_battery_status(v8, 4LL, &v6);
printf("\n$$$$$$ Sensor battery Value: %d\n", v6);
break;
case 7:
zw_node_set_wakeup_interval(v8, 4LL, 61LL);
break;
case 8:
zw_node_get_wakeup_interval(v8, 4LL, &v6);
printf("Wake up interval: %d\n", v6);
break;
case 9:
break;
default:
puts("Not Implemented");
break;
}
}
while ( v7 != 9 );
}
return v4;
}

original_code:
int main( )
{
 zw_api_ctx_S ctx;
 int rc;
 int val;
 int opt;
 printf( "In main\n" );
 fflush(stdout);
 print_cmd_classes();
 rc = zw_api_init( "/dev/ttyUSB0", &ctx );
 if ( rc ) {
  printf("zWave API Init failed\n");
  return 1;
 }
 sleep(3);
 zw_list_nodes();
        do {
                printf("\n=== MENU ===\n");
                printf("1. List Nodes\n");
                printf("2. Switch state ON\n");
                printf("3. Switch state OFF\n");
                printf("4. SWitch State Get\n");
                printf("5. Get Sensor State\n");
                printf("6. Get Sensor Battery Level\n");
  printf("7. Set sensor interval\n");
  printf("8. Get sensor interval\n");
                printf("9. Exit\n");
                scanf( "%d", &opt );
                switch( opt ) {
                case 1:
                        zw_list_nodes();
                        break;
                case 2:
   val = 255;
   zw_node_set_value( &ctx, 3, (void *)&val );
                        break;
                case 3:
   val = 0;
   zw_node_set_value( &ctx, 3, (void *)&val );
                        break;
                case 4:
          zw_node_get_value( &ctx, 3, (void *)&val );
   printf("\n$$$$$$ Switch Value: %d\n", val);
                        break;
                case 5:
          zw_node_get_value( &ctx, 4, (void *)&val );
   printf("\n$$$$$$ Sensor State Value: %d\n", val);
                        break;
                case 6:
   zw_node_get_battery_status( &ctx, 4, (void *)&val );
   printf("\n$$$$$$ Sensor battery Value: %d\n", val);
                        break;
  case 7:
   zw_node_set_wakeup_interval( &ctx, 4, 61 );
   break;
  case 8:
   zw_node_get_wakeup_interval( &ctx, 4, (void *)&val );
   printf( "Wake up interval: %d\n", val );
   break;
                case 9:
                        break;
                default:
                        printf("Not Implemented\n");
                        break;
                }
        } while(opt != 9);
 return 0;
}

canonical_original_code:
int main()
{
 struct zw_api_ctx ctx;
 int rc;
 int val;
 int opt;
 printf( "In main\n" );
 fflush(stdout);
 print_cmd_classes();
 rc = zw_api_init( "/dev/ttyUSB0", &ctx );
 if ( rc ) {
  printf("zWave API Init failed\n");
  return 1;
 }
 sleep(3);
 zw_list_nodes();
        do {
                printf("\n=== MENU ===\n");
                printf("1. List Nodes\n");
                printf("2. Switch state ON\n");
                printf("3. Switch state OFF\n");
                printf("4. SWitch State Get\n");
                printf("5. Get Sensor State\n");
                printf("6. Get Sensor Battery Level\n");
  printf("7. Set sensor interval\n");
  printf("8. Get sensor interval\n");
                printf("9. Exit\n");
                scanf( "%d", &opt );
                switch( opt ) {
                case 1:
                        zw_list_nodes();
                        break;
                case 2:
   val = 255;
   zw_node_set_value( &ctx, 3, (void *)&val );
                        break;
                case 3:
   val = 0;
   zw_node_set_value( &ctx, 3, (void *)&val );
                        break;
                case 4:
          zw_node_get_value( &ctx, 3, (void *)&val );
   printf("\n$$$$$$ Switch Value: %d\n", val);
                        break;
                case 5:
          zw_node_get_value( &ctx, 4, (void *)&val );
   printf("\n$$$$$$ Sensor State Value: %d\n", val);
                        break;
                case 6:
   zw_node_get_battery_status( &ctx, 4, (void *)&val );
   printf("\n$$$$$$ Sensor battery Value: %d\n", val);
                        break;
  case 7:
   zw_node_set_wakeup_interval( &ctx, 4, 61 );
   break;
  case 8:
   zw_node_get_wakeup_interval( &ctx, 4, (void *)&val );
   printf( "Wake up interval: %d\n", val );
   break;
                case 9:
                        break;
                default:
                        printf("Not Implemented\n");
                        break;
                }
        } while(opt != 9);
 return 0;
}

variable_types: struct zw_api_ctx { int port; int node_id; }

variable_types: rc int

variable_types: val int

variable_types: opt int


original_code:
static int
wake_up_set( zw_api_ctx_S *ctx, u8 nodeid, void *value )
{
        u8 buff[1024];
 int interval = *(int *)value;
        buff[0] = 0x13;
        buff[1] = nodeid;
        buff[2] = 6;
        buff[3] = 0x84;
        buff[4] = 0x04;
        buff[5] = (u8)( (interval >> 16) & 0xff );
        buff[6] = (u8)( (interval >> 8) & 0xff );
        buff[7] = (u8)( interval & 0xff );
        buff[8] = ctx->node_id;
        buff[9] = 0x01 | 0x04;
 buff[10] = 3;
 syslog( 7, "wake_up_set: %d %x %x %x", interval, buff[5], buff[6], buff[7] );;
        return zw_send_request( ctx, buff, 11, nodeid, 1, 0x13 );
}

canonical_original_code:
static int wake_up_set(struct zw_api_ctx *ctx, unsigned char nodeid, void *value)
{
        unsigned char buff[1024];
 int interval = *(int *)value;
        buff[0] = 0x13;
        buff[1] = nodeid;
        buff[2] = 6;
        buff[3] = 0x84;
        buff[4] = 0x04;
        buff[5] = (u8)( (interval >> 16) & 0xff );
        buff[6] = (u8)( (interval >> 8) & 0xff );
        buff[7] = (u8)( interval & 0xff );
        buff[8] = ctx->node_id;
        buff[9] = 0x01 | 0x04;
 buff[10] = 3;
 syslog( 7, "wake_up_set: %d %x %x %x", interval, buff[5], buff[6], buff[7] );;
        return zw_send_request( ctx, buff, 11, nodeid, 1, 0x13 );
}

variable_types: struct zw_api_ctx { int port; int node_id; } *

variable_types:
nodeid
unsigned char

variable_types:
value
void *

variable_types:
buff
unsigned char [1024]

variable_types: interval int


original_code:
static int
wake_up_get( zw_api_ctx_S *ctx, u8 nodeid, void *value )
{
        u8 buff[1024];
        buff[0] = 0x13;
        buff[1] = nodeid;
        buff[2] = 2;
        buff[3] = 0x84;
        buff[4] = 0x05;
        buff[5] = 0x01 | 0x04;
        buff[6] = 3;
        return zw_send_request( ctx, buff, 6, nodeid, 1, 0x13 );
}

canonical_original_code:
static int wake_up_get(struct zw_api_ctx *ctx, unsigned char nodeid, void *value)
{
        unsigned char buff[1024];
        buff[0] = 0x13;
        buff[1] = nodeid;
        buff[2] = 2;
        buff[3] = 0x84;
        buff[4] = 0x05;
        buff[5] = 0x01 | 0x04;
        buff[6] = 3;
        return zw_send_request( ctx, buff, 6, nodeid, 1, 0x13 );
}

user_defined_types: struct zw_api_ctx { int port; int node_id; }


decompiled_code:
__int64 __fastcall wake_up_proc_msg(__int64 a1, _BYTE *a2, unsigned __int8 a3)
{
__int64 v4; // rdx
__int64 v5; // rdx
char v6; // al
char v8[2]; // [rsp+0h] [rbp-418h] BYREF
int v9; // [rsp+2h] [rbp-416h]

syslog(7, "COMMAND_CLASS_WAKE_UP - processing message");
v4 = (unsigned __int8)a2[6];
if ( (_BYTE)v4 == 7 )
{
v5 = (unsigned __int8)a2[3];
if ( (a2[2] & 4) != 0 )
{
syslog(7, "Got broadcast wakeup from node %i, doing WAKE_UP_INTERVAL_SET", v5);
}
else
{
syslog(7, "Got unicast wakeup from node %i, doing WAKE_UP_NO_MORE_INFORMATION", v5);
v6 = a2[3];
v8[0] = 19;
v8[1] = v6;
v9 = 84444162;
zw_send_request(a1, v8, 6LL, a3, 1LL, 19LL);
}
}
else
{
syslog(7, "%i received from node %d", v4, a3);
}
fflush(stdout);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _BYTE *a2, unsigned __int8 a3)
{
__int64 v4; // rdx
__int64 v5; // rdx
char v6; // al
char v8[2]; // [rsp+0h] [rbp-418h] BYREF
int v9; // [rsp+2h] [rbp-416h]

syslog(7, "COMMAND_CLASS_WAKE_UP - processing message");
v4 = (unsigned __int8)a2[6];
if ( (_BYTE)v4 == 7 )
{
v5 = (unsigned __int8)a2[3];
if ( (a2[2] & 4) != 0 )
{
syslog(7, "Got broadcast wakeup from node %i, doing WAKE_UP_INTERVAL_SET", v5);
}
else
{
syslog(7, "Got unicast wakeup from node %i, doing WAKE_UP_NO_MORE_INFORMATION", v5);
v6 = a2[3];
v8[0] = 19;
v8[1] = v6;
v9 = 84444162;
zw_send_request(a1, v8, 6LL, a3, 1LL, 19LL);
}
}
else
{
syslog(7, "%i received from node %d", v4, a3);
}
fflush(stdout);
return 0LL;
}

original_code:
static int
wake_up_proc_msg( zw_api_ctx_S *ctx, const u8* frame, u8 nodeid )
{
        u8 buff[1024];
 syslog( 7, "COMMAND_CLASS_WAKE_UP - processing message" );;
 if (frame[6] == 0x07) {
  if (frame[2] & 0x04 ) {
   syslog( 7, "Got broadcast wakeup from node %i, doing WAKE_UP_INTERVAL_SET",frame[3] );;
  } else {
   syslog( 7, "Got unicast wakeup from node %i, doing WAKE_UP_NO_MORE_INFORMATION",frame[3] );;
   buff[0]=0x13;
   buff[1]=frame[3];
   buff[2]=2;
   buff[3]=0x84;
   buff[4]=0x08;
   buff[5]=0x01 | 0x04;
   zw_send_request( ctx, buff, 6, nodeid, 1, 0x13 );
  }
 } else {
  syslog( 7, "%i received from node %d", frame[6], nodeid );;
 }
 fflush(stdout);
 return 0;
}

canonical_original_code:
static int wake_up_proc_msg(struct zw_api_ctx *ctx, unsigned char *frame, unsigned char nodeid)
{
        unsigned char buff[1024];
 syslog( 7, "COMMAND_CLASS_WAKE_UP - processing message" );;
 if (frame[6] == 0x07) {
  if (frame[2] & 0x04 ) {
   syslog( 7, "Got broadcast wakeup from node %i, doing WAKE_UP_INTERVAL_SET",frame[3] );;
  } else {
   syslog( 7, "Got unicast wakeup from node %i, doing WAKE_UP_NO_MORE_INFORMATION",frame[3] );;
   buff[0]=0x13;
   buff[1]=frame[3];
   buff[2]=2;
   buff[3]=0x84;
   buff[4]=0x08;
   buff[5]=0x01 | 0x04;
   zw_send_request( ctx, buff, 6, nodeid, 1, 0x13 );
  }
 } else {
  syslog( 7, "%i received from node %d", frame[6], nodeid );;
 }
 fflush(stdout);
 return 0;
}

variable_types:
frame
unsigned char *


decompiled_code:
__int64 wake_up_init()
{
return register_cmd_class(&wake_up);
}

canonical_decompiled_code:
__int64 func3()
{
return register_cmd_class(&wake_up);
}

original_code:
static void __attribute__ ((constructor)) wake_up_init( void )
{
 register_cmd_class( &wake_up );
}

canonical_original_code:
static void wake_up_init()
{
 register_cmd_class( &wake_up );
}


decompiled_code:
__int64 wake_up_exit()
{
return unregister_cmd_class(&wake_up);
}

canonical_decompiled_code:
__int64 func4()
{
return unregister_cmd_class(&wake_up);
}

original_code:
static void __attribute__ ((destructor)) wake_up_exit( void )
{
 unregister_cmd_class( &wake_up );
}

canonical_original_code:
static void wake_up_exit()
{
 unregister_cmd_class( &wake_up );
}


original_code:
static int
bin_sw_set( zw_api_ctx_S *ctx, u8 nodeid, void *value )
{
        u8 buff[1024];
 int level = *(int *)value;
        buff[0] = 0x13;
        buff[1] = nodeid;
        buff[2] = 3;
        buff[3] = 0x25;
        buff[4] = 0x01;
        buff[5] = level;
        buff[6] = 0x01 | 0x04;
        return zw_send_request( ctx, buff, 7, 3, 1, 0x13 );
}

canonical_original_code:
static int bin_sw_set(struct zw_api_ctx *ctx, unsigned char nodeid, void *value)
{
        unsigned char buff[1024];
 int level = *(int *)value;
        buff[0] = 0x13;
        buff[1] = nodeid;
        buff[2] = 3;
        buff[3] = 0x25;
        buff[4] = 0x01;
        buff[5] = level;
        buff[6] = 0x01 | 0x04;
        return zw_send_request( ctx, buff, 7, 3, 1, 0x13 );
}

variable_types: level int


decompiled_code:
__int64 __fastcall bin_sw_get(__int64 a1, char a2, _DWORD *a3)
{
unsigned int v4; // er12
struct timespec v6; // [rsp+0h] [rbp-428h] BYREF
char v7[2]; // [rsp+10h] [rbp-418h] BYREF
int v8; // [rsp+12h] [rbp-416h]
char v9; // [rsp+16h] [rbp-412h]

v7[1] = a2;
v7[0] = 19;
v8 = 84026626;
v9 = 3;
zw_send_request(a1, v7, 7LL, 3LL, 1LL, 19LL, v6.tv_sec);
pthread_mutex_lock(&val_lock);
clock_gettime(0, &v6);
v6.tv_sec += 5LL;
v4 = pthread_cond_timedwait(&sw_value, &val_lock, &v6);
*a3 = sw_val;
pthread_mutex_unlock(&val_lock);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2, _DWORD *a3)
{
unsigned int v4; // er12
struct timespec v6; // [rsp+0h] [rbp-428h] BYREF
char v7[2]; // [rsp+10h] [rbp-418h] BYREF
int v8; // [rsp+12h] [rbp-416h]
char v9; // [rsp+16h] [rbp-412h]

v7[1] = a2;
v7[0] = 19;
v8 = 84026626;
v9 = 3;
zw_send_request(a1, v7, 7LL, 3LL, 1LL, 19LL, v6.tv_sec);
pthread_mutex_lock(&val_lock);
clock_gettime(0, &v6);
v6.tv_sec += 5LL;
v4 = pthread_cond_timedwait(&sw_value, &val_lock, &v6);
*a3 = sw_val;
pthread_mutex_unlock(&val_lock);
return v4;
}

original_code:
static int
bin_sw_get( zw_api_ctx_S *ctx, u8 nodeid, void *resp )
{
        u8 buff[1024];
 int rc;
 int *value = (int *)resp;
 struct timespec ts;
        buff[0] = 0x13;
        buff[1] = nodeid;
        buff[2] = 2;
        buff[3] = 0x25;
        buff[4] = 0x2;
        buff[5] = 0x01 | 0x04;
        buff[6] = 3;
        rc = zw_send_request( ctx, buff, 7, 3, 1, 0x13 );
 pthread_mutex_lock( &val_lock );
 clock_gettime(0, &ts);
 ts.tv_sec += 5;
        rc = pthread_cond_timedwait(&sw_value, &val_lock, &ts);
 *value = sw_val;
 pthread_mutex_unlock( &val_lock );
 return rc;
}

canonical_original_code:
static int bin_sw_get(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp)
{
        unsigned char buff[1024];
 int rc;
 int *value = (int *)resp;
 struct timespec ts;
        buff[0] = 0x13;
        buff[1] = nodeid;
        buff[2] = 2;
        buff[3] = 0x25;
        buff[4] = 0x2;
        buff[5] = 0x01 | 0x04;
        buff[6] = 3;
        rc = zw_send_request( ctx, buff, 7, 3, 1, 0x13 );
 pthread_mutex_lock( &val_lock );
 clock_gettime(0, &ts);
 ts.tv_sec += 5;
        rc = pthread_cond_timedwait(&sw_value, &val_lock, &ts);
 *value = sw_val;
 pthread_mutex_unlock( &val_lock );
 return rc;
}

variable_types:
resp
void *

variable_types:
value
int *

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
__int64 __fastcall bin_sw_report(__int64 a1, char a2, _DWORD *a3)
{
return bin_sw_get(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char a2, _DWORD *a3)
{
return func1(a1, a2, a3);
}

original_code:
static int
bin_sw_report( zw_api_ctx_S *ctx, u8 nodeid, void *resp )
{
 return bin_sw_get( ctx, nodeid, resp );
}

canonical_original_code:
static int bin_sw_report(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp)
{
 return bin_sw_get( ctx, nodeid, resp );
}


decompiled_code:
__int64 __fastcall bin_sw_proc_msg(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned int v3; // ebp
__int64 v4; // rdx
unsigned int v5; // ebx

v3 = a3;
syslog(7, "COMMAND_CLASS_SWITCH_BINARY - processing message");
v4 = *(unsigned __int8 *)(a2 + 6);
switch ( (_BYTE)v4 )
{
case 1:
syslog(7, "SWITCH_BINARY_SET received from node %d value %d", v3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
case 2:
syslog(7, "SWITCH_BINARY_GET received from node %d value %d", v3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
case 3:
syslog(7, "SWITCH_BINARY_REPORT received from node %d value %d", v3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
default:
syslog(5, "%i received from node %d", v4, v3);
return 0LL;
}
pthread_mutex_lock(&val_lock);
if ( (unsigned int)zw_node_set_state(v3, v5) )
syslog(7, "Setting node bin switch state failed");
sw_val = v5;
pthread_cond_broadcast(&sw_value);
pthread_mutex_unlock(&val_lock);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned int v3; // ebp
__int64 v4; // rdx
unsigned int v5; // ebx

v3 = a3;
syslog(7, "COMMAND_CLASS_SWITCH_BINARY - processing message");
v4 = *(unsigned __int8 *)(a2 + 6);
switch ( (_BYTE)v4 )
{
case 1:
syslog(7, "SWITCH_BINARY_SET received from node %d value %d", v3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
case 2:
syslog(7, "SWITCH_BINARY_GET received from node %d value %d", v3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
case 3:
syslog(7, "SWITCH_BINARY_REPORT received from node %d value %d", v3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
default:
syslog(5, "%i received from node %d", v4, v3);
return 0LL;
}
pthread_mutex_lock(&val_lock);
if ( (unsigned int)zw_node_set_state(v3, v5) )
syslog(7, "Setting node bin switch state failed");
sw_val = v5;
pthread_cond_broadcast(&sw_value);
pthread_mutex_unlock(&val_lock);
return 0LL;
}

original_code:
static int
bin_sw_proc_msg( zw_api_ctx_S *ctx, const u8* frame, u8 nodeid )
{
 int val = -1;
 syslog( 7, "COMMAND_CLASS_SWITCH_BINARY - processing message" );;
 if ((unsigned char)frame[6] == 0x01) {
  syslog( 7, "SWITCH_BINARY_SET received from node %d value %d", nodeid,(unsigned char)frame[7] );;
  val = frame[7];
 }
 else if ((unsigned char)frame[6] == 0x2) {
  syslog( 7, "SWITCH_BINARY_GET received from node %d value %d", nodeid,(unsigned char)frame[7] );;
  val = frame[7];
 }
 else if ((unsigned char)frame[6] == 0x3) {
  syslog( 7, "SWITCH_BINARY_REPORT received from node %d value %d", nodeid,(unsigned char)frame[7] );;
  val = frame[7];
 }
 else {
  syslog( 5, "%i received from node %d", frame[6], nodeid );;
  goto out;
 }
 pthread_mutex_lock( &val_lock );
 if ( 0 != zw_node_set_state( nodeid, val ) )
  syslog( 7, "Setting node bin switch state failed" );;
 sw_val = val;
 pthread_cond_broadcast( &sw_value );
 pthread_mutex_unlock( &val_lock );
out:
 return 0;
}

canonical_original_code:
static int bin_sw_proc_msg(struct zw_api_ctx *ctx, unsigned char *frame, unsigned char nodeid)
{
 int val = -1;
 syslog( 7, "COMMAND_CLASS_SWITCH_BINARY - processing message" );;
 if ((unsigned char)frame[6] == 0x01) {
  syslog( 7, "SWITCH_BINARY_SET received from node %d value %d", nodeid,(unsigned char)frame[7] );;
  val = frame[7];
 }
 else if ((unsigned char)frame[6] == 0x2) {
  syslog( 7, "SWITCH_BINARY_GET received from node %d value %d", nodeid,(unsigned char)frame[7] );;
  val = frame[7];
 }
 else if ((unsigned char)frame[6] == 0x3) {
  syslog( 7, "SWITCH_BINARY_REPORT received from node %d value %d", nodeid,(unsigned char)frame[7] );;
  val = frame[7];
 }
 else {
  syslog( 5, "%i received from node %d", frame[6], nodeid );;
  goto out;
 }
 pthread_mutex_lock( &val_lock );
 if ( 0 != zw_node_set_state( nodeid, val ) )
  syslog( 7, "Setting node bin switch state failed" );;
 sw_val = val;
 pthread_cond_broadcast( &sw_value );
 pthread_mutex_unlock( &val_lock );
out:
 return 0;
}


decompiled_code:
__int64 bin_sw_init()
{
return register_cmd_class(&bin_sw);
}

canonical_decompiled_code:
__int64 func4()
{
return register_cmd_class(&bin_sw);
}

original_code:
static void __attribute__ ((constructor)) bin_sw_init( void )
{
 register_cmd_class( &bin_sw );
}

canonical_original_code:
static void bin_sw_init()
{
 register_cmd_class( &bin_sw );
}


decompiled_code:
int bin_sw_exit()
{
unregister_cmd_class(&bin_sw);
pthread_cond_destroy(&sw_value);
return pthread_mutex_destroy(&val_lock);
}

canonical_decompiled_code:
int func5()
{
unregister_cmd_class(&bin_sw);
pthread_cond_destroy(&sw_value);
return pthread_mutex_destroy(&val_lock);
}

original_code:
static void __attribute__ ((destructor)) bin_sw_exit( void )
{
 unregister_cmd_class( &bin_sw );
 pthread_cond_destroy( &sw_value );
 pthread_mutex_destroy( &val_lock );
}

canonical_original_code:
static void bin_sw_exit()
{
 unregister_cmd_class( &bin_sw );
 pthread_cond_destroy( &sw_value );
 pthread_mutex_destroy( &val_lock );
}


decompiled_code:
int log_init()
{
openlog("homezremote", 1, 24);
return setlogmask(127);
}

canonical_decompiled_code:
int func0()
{
openlog("homezremote", 1, 24);
return setlogmask(127);
}

original_code:
static void __attribute__ ((constructor)) log_init( void )
{
 openlog( "homezremote", 0x01, (3<<3) );
 setlogmask( ((1 << ((6)+1)) - 1) );
}

canonical_original_code:
static void log_init()
{
 openlog( "homezremote", 0x01, (3<<3) );
 setlogmask( ((1 << ((6)+1)) - 1) );
}


decompiled_code:
// attributes: thunk
void log_exit(void)
{
closelog();
}

canonical_decompiled_code:
void func1(void)
{
closelog();
}

original_code:
static void __attribute__ ((destructor)) log_exit( void )
{
 closelog();
}

canonical_original_code:
static void log_exit()
{
 closelog();
}


decompiled_code:
__int64 __fastcall get_cmd_class(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 16;
result = 32LL;
if ( v1 <= 0x10u )
result = CSWTCH_5[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 16;
result = 32LL;
if ( v1 <= 0x10u )
result = CSWTCH_5[v1];
return result;
}

original_code:
static u8
get_cmd_class( const u8 gtype )
{
 u8 cmd_cls = 0x20;
 switch ( gtype )
 {
 case 0x10:
  cmd_cls = 0x25;
  break;
 case 0x13:
  cmd_cls = 0x28;
  break;
 case 0x20:
  cmd_cls = 0x30;
  break;
 default:
  break;
 }
 return cmd_cls;
}

canonical_original_code:
static unsigned char get_cmd_class(unsigned char gtype)
{
 unsigned char cmd_cls = 0x20;
 switch ( gtype )
 {
 case 0x10:
  cmd_cls = 0x25;
  break;
 case 0x13:
  cmd_cls = 0x28;
  break;
 case 0x20:
  cmd_cls = 0x30;
  break;
 default:
  break;
 }
 return cmd_cls;
}

variable_types:
gtype
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall zw_node_set_batt_level(unsigned __int8 a1, char a2)
{
void **v2; // rbx

v2 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
while ( *((_DWORD *)v2 + 12) != a1 )
{
v2 = (void **)*v2;
if ( v2 == &zw_nodes )
return 0xFFFFFFFFLL;
}
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
*((_BYTE *)v2 + 58) = a2;
pthread_mutex_unlock((pthread_mutex_t *)(v2 + 8));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1, char a2)
{
void **v2; // rbx

v2 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
while ( *((_DWORD *)v2 + 12) != a1 )
{
v2 = (void **)*v2;
if ( v2 == &zw_nodes )
return 0xFFFFFFFFLL;
}
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
*((_BYTE *)v2 + 58) = a2;
pthread_mutex_unlock((pthread_mutex_t *)(v2 + 8));
return 0LL;
}

original_code:
int
zw_node_set_batt_level( u8 id, u8 level )
{
 list_node *node = ((void *)0);
 struct zw_node *zwnode;
 int rc = -1;
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  if ( zwnode->id == id ) {
   pthread_mutex_lock( &zwnode->lock );
   zwnode->batt_level = level;
   pthread_mutex_unlock( &zwnode->lock );
   rc = 0;
   break;
  }
 }
 return rc;
}

canonical_original_code:
int zw_node_set_batt_level(unsigned char id, unsigned char level)
{
 struct _node *node = ((void *)0);
 struct zw_node *zwnode;
 int rc = -1;
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  if ( zwnode->id == id ) {
   pthread_mutex_lock( &zwnode->lock );
   zwnode->batt_level = level;
   pthread_mutex_unlock( &zwnode->lock );
   rc = 0;
   break;
  }
 }
 return rc;
}

variable_types:
id
unsigned char

variable_types:
level
unsigned char

variable_types: struct _node { struct _node *next; struct _node *prev; } *

variable_types: struct zw_node { struct _node { struct _node *next; struct _node *prev; } list; char name[32]; int id; unsigned char mode; unsigned char func; unsigned char btype; unsigned char gtype; unsigned char stype; unsigned char cclass; unsigned char batt_level; unsigned char state; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; } *

user_defined_types: struct zw_node { struct _node list; char name[32]; int id; unsigned char mode; unsigned char func; unsigned char btype; unsigned char gtype; unsigned char stype; unsigned char cclass; unsigned char batt_level; unsigned char state; union pthread_mutex_t lock; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall zw_node_set_state(unsigned __int8 a1, unsigned __int8 a2)
{
void **v2; // rbx

v2 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
while ( *((_DWORD *)v2 + 12) != a1 )
{
v2 = (void **)*v2;
if ( v2 == &zw_nodes )
return 0xFFFFFFFFLL;
}
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
if ( *((_BYTE *)v2 + 59) != a2 )
syslog(5, "State Change on node(%d): %d", a1, a2);
*((_BYTE *)v2 + 59) = a2;
pthread_mutex_unlock((pthread_mutex_t *)(v2 + 8));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1, unsigned __int8 a2)
{
void **v2; // rbx

v2 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
while ( *((_DWORD *)v2 + 12) != a1 )
{
v2 = (void **)*v2;
if ( v2 == &zw_nodes )
return 0xFFFFFFFFLL;
}
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
if ( *((_BYTE *)v2 + 59) != a2 )
syslog(5, "State Change on node(%d): %d", a1, a2);
*((_BYTE *)v2 + 59) = a2;
pthread_mutex_unlock((pthread_mutex_t *)(v2 + 8));
return 0LL;
}

original_code:
int
zw_node_set_state( u8 id, u8 state )
{
 list_node *node = ((void *)0);
 struct zw_node *zwnode;
 int rc = -1;
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  if ( zwnode->id == id ) {
   pthread_mutex_lock( &zwnode->lock );
   if ( zwnode->state != state )
    syslog( 5, "State Change on node(%d): %d", id, state );;
   zwnode->state = state;
   pthread_mutex_unlock( &zwnode->lock );
   rc = 0;
   break;
  }
 }
 return rc;
}

canonical_original_code:
int zw_node_set_state(unsigned char id, unsigned char state)
{
 struct _node *node = ((void *)0);
 struct zw_node *zwnode;
 int rc = -1;
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  if ( zwnode->id == id ) {
   pthread_mutex_lock( &zwnode->lock );
   if ( zwnode->state != state )
    syslog( 5, "State Change on node(%d): %d", id, state );;
   zwnode->state = state;
   pthread_mutex_unlock( &zwnode->lock );
   rc = 0;
   break;
  }
 }
 return rc;
}

variable_types:
state
unsigned char

variable_types: rc int

user_defined_types: struct _node { struct _node *next; struct _node *prev; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall zw_node_set_label(unsigned __int8 a1, const char *a2)
{
void **v2; // rbx

v2 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
while ( *((_DWORD *)v2 + 12) != a1 )
{
v2 = (void **)*v2;
if ( v2 == &zw_nodes )
return 0xFFFFFFFFLL;
}
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
snprintf((char *)v2 + 16, 0x20uLL, "%s", a2);
pthread_mutex_unlock((pthread_mutex_t *)(v2 + 8));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1, const char *a2)
{
void **v2; // rbx

v2 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
while ( *((_DWORD *)v2 + 12) != a1 )
{
v2 = (void **)*v2;
if ( v2 == &zw_nodes )
return 0xFFFFFFFFLL;
}
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
snprintf((char *)v2 + 16, 0x20uLL, "%s", a2);
pthread_mutex_unlock((pthread_mutex_t *)(v2 + 8));
return 0LL;
}

original_code:
int
zw_node_set_label( u8 id, char *label )
{
 list_node *node = ((void *)0);
 struct zw_node *zwnode;
 int rc = -1;
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  if ( zwnode->id == id ) {
   pthread_mutex_lock( &zwnode->lock );
   snprintf( zwnode->name, 32, "%s", label );
   pthread_mutex_unlock( &zwnode->lock );
   rc = 0;
   break;
  }
 }
 return rc;
}

canonical_original_code:
int zw_node_set_label(unsigned char id, char *label)
{
 struct _node *node = ((void *)0);
 struct zw_node *zwnode;
 int rc = -1;
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  if ( zwnode->id == id ) {
   pthread_mutex_lock( &zwnode->lock );
   snprintf( zwnode->name, 32, "%s", label );
   pthread_mutex_unlock( &zwnode->lock );
   rc = 0;
   break;
  }
 }
 return rc;
}

variable_types:
label
char *