decompiled_code:
__int64 __fastcall eval_emit(_QWORD *a1, __int64 a2)
{
char *v2; // rax
_QWORD *v3; // rdx
_QWORD *v4; // rbx
unsigned int v5; // er13
int v6; // eax

if ( need_init_2 )
{
need_init_2 = 0;
v2 = (char *)&caps_buf_1;
v3 = &caps_0;
do
{
*v3 = v2;
v2 += 512;
++v3;
}
while ( v2 != (char *)&caps_buf_1 + 5120 );
}
v4 = (_QWORD *)*a1;
if ( (_QWORD *)*a1 == a1 )
return 0;
v5 = 0;
do
{
v6 = regex_match() - 1;
if ( v6 >= 0 )
{
((void (__fastcall *)(__int64, void *, _QWORD))v4[2])(a2, &caps_0, (unsigned int)v6);
v5 = 1;
}
v4 = (_QWORD *)*v4;
}
while ( v4 != a1 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1, __int64 a2)
{
char *v2; // rax
_QWORD *v3; // rdx
_QWORD *v4; // rbx
unsigned int v5; // er13
int v6; // eax

if ( need_init_2 )
{
need_init_2 = 0;
v2 = (char *)&caps_buf_1;
v3 = &caps_0;
do
{
*v3 = v2;
v2 += 512;
++v3;
}
while ( v2 != (char *)&caps_buf_1 + 5120 );
}
v4 = (_QWORD *)*a1;
if ( (_QWORD *)*a1 == a1 )
return 0;
v5 = 0;
do
{
v6 = regex_match() - 1;
if ( v6 >= 0 )
{
((void (__fastcall *)(__int64, void *, _QWORD))v4[2])(a2, &caps_0, (unsigned int)v6);
v5 = 1;
}
v4 = (_QWORD *)*v4;
}
while ( v4 != a1 );
return v5;
}

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]


repo: pmer/yak

decompiled_code:
char *pref_find_yakrc()
{
int v0; // edx
char *result; // rax
char *v2; // rax
size_t v3; // rax
bool v4; // zf

strcpy(buf_0, "./yakrc");
v0 = access(buf_0, 4);
result = buf_0;
if ( v0 )
{
v2 = getenv("HOME");
strcpy(buf_0, v2);
v3 = strlen(buf_0);
*(_QWORD *)&buf_0[v3] = 0x61792F6B61792E2FLL;
*(int *)((char *)&dword_268 + v3) = 6517355;
v4 = access(buf_0, 4) == 0;
result = buf_0;
if ( !v4 )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
char *func2()
{
int v0; // edx
char *result; // rax
char *v2; // rax
size_t v3; // rax
bool v4; // zf

strcpy(buf_0, "./yakrc");
v0 = access(buf_0, 4);
result = buf_0;
if ( v0 )
{
v2 = getenv("HOME");
strcpy(buf_0, v2);
v3 = strlen(buf_0);
*(_QWORD *)&buf_0[v3] = 0x61792F6B61792E2FLL;
*(int *)((char *)&dword_268 + v3) = 6517355;
v4 = access(buf_0, 4) == 0;
result = buf_0;
if ( !v4 )
result = 0LL;
}
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 func3()
{
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 list_head { struct list_head *next; } *

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

return_type: void

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

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

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

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

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

user_defined_types: struct list_head { struct list_head *next; }


decompiled_code:
__int64 load_whoiam()
{
const char *v0; // rax
char *v1; // rbx
char *v2; // r12
char *v3; // rax
char *v4; // rbx
size_t v5; // rbp
int v6; // er13
char *v7; // rbx
size_t v8; // rbp
int v9; // 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 = (char *)pref_get("channels");
bot_owners = 0LL;
v3 = strtok(v1, " ");
if ( v3 )
{
v4 = v3;
v5 = 16LL;
v6 = 0;
do
{
bot_owners = realloc(bot_owners, v5);
*(_QWORD *)((char *)bot_owners + v5 - 16) = v4;
++v6;
v4 = strtok(0LL, " ");
v5 += 8LL;
}
while ( v4 );
}
else
{
v6 = 0;
}
*((_QWORD *)bot_owners + v6) = 0LL;
bot_channels = 0LL;
v7 = strtok(v2, " ");
if ( v7 )
{
v8 = 16LL;
v9 = 0;
do
{
bot_channels = realloc(bot_channels, v8);
*(_QWORD *)((char *)bot_channels + v8 - 16) = v7;
++v9;
v7 = strtok(0LL, " ");
v8 += 8LL;
}
while ( v7 );
}
else
{
v9 = 0;
}
*((_QWORD *)bot_channels + v9) = 0LL;
return add_shutdown_fn(free_nick_owners_channels);
}

canonical_decompiled_code:
__int64 func0()
{
const char *v0; // rax
char *v1; // rbx
char *v2; // r12
char *v3; // rax
char *v4; // rbx
size_t v5; // rbp
int v6; // er13
char *v7; // rbx
size_t v8; // rbp
int v9; // 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 = (char *)pref_get("channels");
bot_owners = 0LL;
v3 = strtok(v1, " ");
if ( v3 )
{
v4 = v3;
v5 = 16LL;
v6 = 0;
do
{
bot_owners = realloc(bot_owners, v5);
*(_QWORD *)((char *)bot_owners + v5 - 16) = v4;
++v6;
v4 = strtok(0LL, " ");
v5 += 8LL;
}
while ( v4 );
}
else
{
v6 = 0;
}
*((_QWORD *)bot_owners + v6) = 0LL;
bot_channels = 0LL;
v7 = strtok(v2, " ");
if ( v7 )
{
v8 = 16LL;
v9 = 0;
do
{
bot_channels = realloc(bot_channels, v8);
*(_QWORD *)((char *)bot_channels + v8 - 16) = v7;
++v9;
v7 = strtok(0LL, " ");
v8 += 8LL;
}
while ( v7 );
}
else
{
v9 = 0;
}
*((_QWORD *)bot_channels + v9) = 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 *i; // rdi
__int64 v4; // rdx
__int64 v6; // rdx
const char **v7; // rbx
unsigned int v8; // [rsp+4h] [rbp-24h] BYREF
__int64 v9; // [rsp+8h] [rbp-20h] BYREF
const char **v10; // [rsp+10h] [rbp-18h] BYREF
__int64 v11[2]; // [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");
i = "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);
i = (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(v11, &v10, &v8, &v9);
mutex_on(v11, &v10, v6);
argv = (const char **)v8;
if ( v8 )
{
i = (const char *)v11[0];
callback_emit_numeric(v11[0], v8, v9);
}
else
{
argv = v10;
i = (const char *)v11[0];
callback_emit_str(v11[0], v10, v9);
}
if ( v8 == 1 )
{
v7 = (const char **)bot_channels;
for ( i = *(const char **)bot_channels; *v7; i = *v7 )
{
ircproto_join();
++v7;
}
}
mutex_off();
}
}
mutex_on(i, argv, v4);
safe_shutdown();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *i; // rdi
__int64 v4; // rdx
__int64 v6; // rdx
const char **v7; // rbx
unsigned int v8; // [rsp+4h] [rbp-24h] BYREF
__int64 v9; // [rsp+8h] [rbp-20h] BYREF
const char **v10; // [rsp+10h] [rbp-18h] BYREF
__int64 v11[2]; // [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");
i = "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);
i = (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(v11, &v10, &v8, &v9);
mutex_on(v11, &v10, v6);
argv = (const char **)v8;
if ( v8 )
{
i = (const char *)v11[0];
callback_emit_numeric(v11[0], v8, v9);
}
else
{
argv = v10;
i = (const char *)v11[0];
callback_emit_str(v11[0], v10, v9);
}
if ( v8 == 1 )
{
v7 = (const char **)bot_channels;
for ( i = *(const char **)bot_channels; *v7; i = *v7 )
{
ircproto_join();
++v7;
}
}
mutex_off();
}
}
mutex_on(i, 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

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


opera

decompiled_code:
void opera()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void opera(Game_state_t * gs_p) {
}

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


decompiled_code:
void income_tax_refund()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void income_tax_refund(Game_state_t * gs_p) {
}

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


decompiled_code:
void life_insurance()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

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 hospital_fee()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

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 school_fee()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

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 consultancy_fee()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

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 street_repairs()
{
;
}

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 beauty_contest()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void beauty_contest(Game_state_t * gs_p) {
}

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


inherit

decompiled_code:
void inherit()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void inherit(Game_state_t * gs_p) {
}

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


decompiled_code:
void sale_of_stock()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
void sale_of_stock(Game_state_t * gs_p) {
}

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


decompiled_code:
void holiday_fund()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void holiday_fund(Game_state_t * gs_p) {
}

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


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 func14(__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 func15(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 func16(__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:
__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;
}


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


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_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 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 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 reading_railroad()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

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


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 building_loan()
{
;
}

original_code:
void building_loan(Game_state_t * gs_p) {
}

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


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


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 func14(__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 v2; // eax
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;
v2 = 28;
}
else
{
puts("Advancing to the Electric Company");
*(_DWORD *)(v1 + 32) = 12;
v2 = 12;
}
if ( (locations[464 * v2 + 448] & 1) != 0 )
{
roll_dice(a1);
result = debit_player(v1, (unsigned int)(10 * (*(_DWORD *)(a1 + 28) + *(_DWORD *)(a1 + 32))));
}
else
{
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 func15(__int64 a1)
{
__int64 v1; // rbp
int v2; // eax
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;
v2 = 28;
}
else
{
puts("Advancing to the Electric Company");
*(_DWORD *)(v1 + 32) = 12;
v2 = 12;
}
if ( (locations[464 * v2 + 448] & 1) != 0 )
{
roll_dice(a1);
result = debit_player(v1, (unsigned int)(10 * (*(_DWORD *)(a1 + 28) + *(_DWORD *)(a1 + 32))));
}
else
{
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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // 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);
v4 = atoi(&buffer);
if ( v4 == 1 )
{
new_game(v5);
goto LABEL_3;
}
if ( v4 == 2 )
break;
puts("Invalid input");
}
load_game(v5);
LABEL_3:
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; // ebp
int v6; // [rsp+0h] [rbp-28h] BYREF
unsigned int v7; // [rsp+4h] [rbp-24h] BYREF
char v8[32]; // [rsp+8h] [rbp-20h] BYREF

puts("In main");
v3 = stdout;
fflush(stdout);
print_cmd_classes(v3, argv);
if ( (unsigned int)zw_api_init("/dev/ttyUSB0", v8) )
{
puts("zWave API Init failed");
v4 = 1;
}
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", &v6);
switch ( v6 )
{
case 1:
zw_list_nodes();
break;
case 2:
v7 = 255;
zw_node_set_value(v8, 3LL, &v7);
break;
case 3:
v7 = 0;
zw_node_set_value(v8, 3LL, &v7);
break;
case 4:
zw_node_get_value(v8, 3LL, &v7);
printf("\n$$$$$$ Switch Value: %d\n", v7);
break;
case 5:
zw_node_get_value(v8, 4LL, &v7);
printf("\n$$$$$$ Sensor State Value: %d\n", v7);
break;
case 6:
zw_node_get_battery_status(v8, 4LL, &v7);
printf("\n$$$$$$ Sensor battery Value: %d\n", v7);
break;
case 7:
zw_node_set_wakeup_interval(v8, 4LL, 61LL);
break;
case 8:
zw_node_get_wakeup_interval(v8, 4LL, &v7);
printf("Wake up interval: %d\n", v7);
break;
case 9:
break;
default:
puts("Not Implemented");
break;
}
}
while ( v6 != 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)
{
unsigned __int8 v4; // dl
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

syslog(7, "COMMAND_CLASS_WAKE_UP - processing message");
v4 = a2[6];
if ( v4 == 7 )
{
if ( (a2[2] & 4) != 0 )
{
syslog(7, "Got broadcast wakeup from node %i, doing WAKE_UP_INTERVAL_SET", (unsigned __int8)a2[3]);
}
else
{
syslog(7, "Got unicast wakeup from node %i, doing WAKE_UP_NO_MORE_INFORMATION", (unsigned __int8)a2[3]);
v6[0] = 19;
v6[1] = a2[3];
v6[2] = 2;
v6[3] = -124;
v6[4] = 8;
v6[5] = 5;
zw_send_request(a1, v6, 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)
{
unsigned __int8 v4; // dl
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

syslog(7, "COMMAND_CLASS_WAKE_UP - processing message");
v4 = a2[6];
if ( v4 == 7 )
{
if ( (a2[2] & 4) != 0 )
{
syslog(7, "Got broadcast wakeup from node %i, doing WAKE_UP_INTERVAL_SET", (unsigned __int8)a2[3]);
}
else
{
syslog(7, "Got unicast wakeup from node %i, doing WAKE_UP_NO_MORE_INFORMATION", (unsigned __int8)a2[3]);
v6[0] = 19;
v6[1] = a2[3];
v6[2] = 2;
v6[3] = -124;
v6[4] = 8;
v6[5] = 5;
zw_send_request(a1, v6, 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; // ebx
struct timespec v6; // [rsp+0h] [rbp-428h] BYREF
char v7[1048]; // [rsp+10h] [rbp-418h] BYREF

v7[0] = 19;
v7[1] = a2;
v7[2] = 2;
v7[3] = 37;
v7[4] = 2;
v7[5] = 5;
v7[6] = 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; // ebx
struct timespec v6; // [rsp+0h] [rbp-428h] BYREF
char v7[1048]; // [rsp+10h] [rbp-418h] BYREF

v7[0] = 19;
v7[1] = a2;
v7[2] = 2;
v7[3] = 37;
v7[4] = 2;
v7[5] = 5;
v7[6] = 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 __int8 v4; // al
unsigned int v5; // ebp

syslog(7, "COMMAND_CLASS_SWITCH_BINARY - processing message");
v4 = *(_BYTE *)(a2 + 6);
switch ( v4 )
{
case 1u:
syslog(7, "SWITCH_BINARY_SET received from node %d value %d", a3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
case 2u:
syslog(7, "SWITCH_BINARY_GET received from node %d value %d", a3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
case 3u:
syslog(7, "SWITCH_BINARY_REPORT received from node %d value %d", a3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
default:
syslog(5, "%i received from node %d", v4, a3);
return 0LL;
}
pthread_mutex_lock(&val_lock);
if ( (unsigned int)zw_node_set_state(a3, 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 __int8 v4; // al
unsigned int v5; // ebp

syslog(7, "COMMAND_CLASS_SWITCH_BINARY - processing message");
v4 = *(_BYTE *)(a2 + 6);
switch ( v4 )
{
case 1u:
syslog(7, "SWITCH_BINARY_SET received from node %d value %d", a3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
case 2u:
syslog(7, "SWITCH_BINARY_GET received from node %d value %d", a3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
case 3u:
syslog(7, "SWITCH_BINARY_REPORT received from node %d value %d", a3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
default:
syslog(5, "%i received from node %d", v4, a3);
return 0LL;
}
pthread_mutex_lock(&val_lock);
if ( (unsigned int)zw_node_set_state(a3, 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:
void log_exit()
{
closelog();
}

canonical_decompiled_code:
void func1()
{
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)
{
__int64 result; // rax

result = 40LL;
if ( a1 != 19 )
{
result = 48LL;
if ( a1 != 32 )
{
LOBYTE(result) = a1 == 16;
result = (unsigned int)(5 * result + 32);
}
}
return result;
}

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

result = 40LL;
if ( a1 != 19 )
{
result = 48LL;
if ( a1 != 32 )
{
LOBYTE(result) = a1 == 16;
result = (unsigned int)(5 * result + 32);
}
}
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 func2(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 func3(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 func4(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 *


decompiled_code:
void __fastcall zw_node_wakeup_handler(__int64 a1, unsigned __int8 a2)
{
void **v2; // rbx
int v3; // [rsp+8h] [rbp-20h] BYREF
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = -1;
v3 = -1;
v2 = (void **)zw_nodes;
if ( zw_nodes != &zw_nodes )
{
while ( *((_DWORD *)v2 + 12) != a2 )
{
v2 = (void **)*v2;
if ( v2 == &zw_nodes )
return;
}
if ( (unsigned int)cc_get(a1, a2, 128LL, v4) )
syslog(2, "Get Battery state command failed for node %d", a2);
if ( (unsigned int)cc_get(a1, a2, *((unsigned __int8 *)v2 + 57), &v3) )
syslog(2, "Get state command failed for node %d", a2);
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, unsigned __int8 a2)
{
void **v2; // rbx
int v3; // [rsp+8h] [rbp-20h] BYREF
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = -1;
v3 = -1;
v2 = (void **)zw_nodes;
if ( zw_nodes != &zw_nodes )
{
while ( *((_DWORD *)v2 + 12) != a2 )
{
v2 = (void **)*v2;
if ( v2 == &zw_nodes )
return;
}
if ( (unsigned int)cc_get(a1, a2, 128LL, v4) )
syslog(2, "Get Battery state command failed for node %d", a2);
if ( (unsigned int)cc_get(a1, a2, *((unsigned __int8 *)v2 + 57), &v3) )
syslog(2, "Get state command failed for node %d", a2);
}
}

original_code:
void
zw_node_wakeup_handler( zw_api_ctx_S *ctx, u8 id )
{
 list_node *node = ((void *)0);
 struct zw_node *zwnode;
 int batt = -1;
 int state = -1;
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  if ( zwnode->id == id ) {
   if ( 0 != cc_get( ctx, id, 0x80, (void *)&batt ) )
    syslog( 2, "Get Battery state command failed for node %d", id );;
   if ( 0 != cc_get( ctx, id, zwnode->cclass, (void *)&state ) )
    syslog( 2, "Get state command failed for node %d", id );;
   break;
  }
 }
}

canonical_original_code:
void zw_node_wakeup_handler(struct zw_api_ctx *ctx, unsigned char id)
{
 struct _node *node = ((void *)0);
 struct zw_node *zwnode;
 int batt = -1;
 int state = -1;
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  if ( zwnode->id == id ) {
   if ( 0 != cc_get( ctx, id, 0x80, (void *)&batt ) )
    syslog( 2, "Get Battery state command failed for node %d", id );;
   if ( 0 != cc_get( ctx, id, zwnode->cclass, (void *)&state ) )
    syslog( 2, "Get state command failed for node %d", id );;
   break;
  }
 }
}

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

variable_types: batt int

variable_types: state int


decompiled_code:
__int64 __fastcall zw_node_get_version(__int64 a1, __int64 a2, __int64 a3)
{
void **v3; // rax

v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_version(a1, a2, *((unsigned __int8 *)v3 + 57), a3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
void **v3; // rax

v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_version(a1, a2, *((unsigned __int8 *)v3 + 57), a3);
}

original_code:
int
zw_node_get_version( zw_api_ctx_S *ctx, u8 id, void *resp )
{
 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 ) {
   rc = cc_version( ctx, id, zwnode->cclass, resp );
   break;
  }
 }
 return rc;
}

canonical_original_code:
int zw_node_get_version(struct zw_api_ctx *ctx, unsigned char id, void *resp)
{
 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 ) {
   rc = cc_version( ctx, id, zwnode->cclass, resp );
   break;
  }
 }
 return rc;
}


decompiled_code:
__int64 __fastcall zw_node_get_value(__int64 a1, __int64 a2, __int64 a3)
{
void **v3; // rax

v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_get(a1, a2, *((unsigned __int8 *)v3 + 57), a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
void **v3; // rax

v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_get(a1, a2, *((unsigned __int8 *)v3 + 57), a3);
}

original_code:
int
zw_node_get_value( zw_api_ctx_S *ctx, u8 id, void *resp )
{
 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 ) {
   rc = cc_get( ctx, id, zwnode->cclass, resp );
   break;
  }
 }
 return rc;
}

canonical_original_code:
int zw_node_get_value(struct zw_api_ctx *ctx, unsigned char id, void *resp)
{
 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 ) {
   rc = cc_get( ctx, id, zwnode->cclass, resp );
   break;
  }
 }
 return rc;
}


decompiled_code:
__int64 __fastcall zw_node_set_value(__int64 a1, __int64 a2, __int64 a3)
{
void **v3; // rax

v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_set(a1, a2, *((unsigned __int8 *)v3 + 57), a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3)
{
void **v3; // rax

v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_set(a1, a2, *((unsigned __int8 *)v3 + 57), a3);
}

original_code:
int
zw_node_set_value( zw_api_ctx_S *ctx, u8 id, void *value )
{
 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 ) {
   rc = cc_set( ctx, id, zwnode->cclass, value );
   break;
  }
 }
 return rc;
}

canonical_original_code:
int zw_node_set_value(struct zw_api_ctx *ctx, unsigned char id, void *value)
{
 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 ) {
   rc = cc_set( ctx, id, zwnode->cclass, value );
   break;
  }
 }
 return rc;
}

variable_types:
value
void *


decompiled_code:
__int64 __fastcall zw_node_get_report(__int64 a1, __int64 a2, __int64 a3)
{
void **v3; // rax

v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_report(a1, a2, *((unsigned __int8 *)v3 + 57), a3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3)
{
void **v3; // rax

v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_report(a1, a2, *((unsigned __int8 *)v3 + 57), a3);
}

original_code:
int
zw_node_get_report( zw_api_ctx_S *ctx, u8 id, void *resp )
{
 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 ) {
   rc = cc_report( ctx, id, zwnode->cclass, resp );
   break;
  }
 }
 return rc;
}

canonical_original_code:
int zw_node_get_report(struct zw_api_ctx *ctx, unsigned char id, void *resp)
{
 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 ) {
   rc = cc_report( ctx, id, zwnode->cclass, resp );
   break;
  }
 }
 return rc;
}


decompiled_code:
__int64 __fastcall zw_node_get_battery_status(__int64 a1, __int64 a2, __int64 a3)
{
void **v3; // rax

v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_get(a1, a2, 128LL, a3);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, __int64 a3)
{
void **v3; // rax

v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_get(a1, a2, 128LL, a3);
}

original_code:
int
zw_node_get_battery_status( zw_api_ctx_S *ctx, u8 id, void *resp )
{
 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 ) {
   rc = cc_get( ctx, id, 0x80, resp );
   break;
  }
 }
 return rc;
}

canonical_original_code:
int zw_node_get_battery_status(struct zw_api_ctx *ctx, unsigned char id, void *resp)
{
 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 ) {
   rc = cc_get( ctx, id, 0x80, resp );
   break;
  }
 }
 return rc;
}


decompiled_code:
__int64 __fastcall zw_node_set_wakeup_interval(__int64 a1, __int64 a2, int a3)
{
void **v3; // rax
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = a3;
v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_set(a1, a2, 132LL, v5);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, int a3)
{
void **v3; // rax
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = a3;
v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_set(a1, a2, 132LL, v5);
}

original_code:
int
zw_node_set_wakeup_interval( zw_api_ctx_S *ctx, u8 id, int intvl )
{
 list_node *node = ((void *)0);
 struct zw_node *zwnode;
 int rc = -1;
 int val = intvl;
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  if ( zwnode->id == id ) {
   rc = cc_set( ctx, id, 0x84, (void *)&val );
   break;
  }
 }
 return rc;
}

canonical_original_code:
int zw_node_set_wakeup_interval(struct zw_api_ctx *ctx, unsigned char id, int intvl)
{
 struct _node *node = ((void *)0);
 struct zw_node *zwnode;
 int rc = -1;
 int val = intvl;
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  if ( zwnode->id == id ) {
   rc = cc_set( ctx, id, 0x84, (void *)&val );
   break;
  }
 }
 return rc;
}

variable_types: intvl int

variable_types: val int


decompiled_code:
__int64 __fastcall zw_node_get_wakeup_interval(__int64 a1, __int64 a2, __int64 a3)
{
void **v3; // rax

v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_get(a1, a2, 132LL, a3);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3)
{
void **v3; // rax

v3 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
a2 = (unsigned __int8)a2;
while ( *((_DWORD *)v3 + 12) != (_DWORD)a2 )
{
v3 = (void **)*v3;
if ( v3 == &zw_nodes )
return 0xFFFFFFFFLL;
}
return cc_get(a1, a2, 132LL, a3);
}

original_code:
int
zw_node_get_wakeup_interval( zw_api_ctx_S *ctx, u8 id, void *resp )
{
 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 ) {
   rc = cc_get( ctx, id, 0x84, resp );
   break;
  }
 }
 return rc;
}

canonical_original_code:
int zw_node_get_wakeup_interval(struct zw_api_ctx *ctx, unsigned char id, void *resp)
{
 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 ) {
   rc = cc_get( ctx, id, 0x84, resp );
   break;
  }
 }
 return rc;
}

variable_types:
resp
void *


decompiled_code:
void zw_list_nodes()
{
const char *v0; // rbx

v0 = (const char *)zw_nodes;
if ( zw_nodes != &zw_nodes )
{
do
{
syslog(5, "ZW_NODE: %s - %d\n", v0 + 16, *((unsigned int *)v0 + 12));
v0 = *(const char **)v0;
}
while ( v0 != (const char *)&zw_nodes );
}
}

canonical_decompiled_code:
void func13()
{
const char *v0; // rbx

v0 = (const char *)zw_nodes;
if ( zw_nodes != &zw_nodes )
{
do
{
syslog(5, "ZW_NODE: %s - %d\n", v0 + 16, *((unsigned int *)v0 + 12));
v0 = *(const char **)v0;
}
while ( v0 != (const char *)&zw_nodes );
}
}

original_code:
void
zw_list_nodes()
{
 list_node *node = ((void *)0);
 struct zw_node *zwnode;
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  syslog( 5, "ZW_NODE: %s - %d\n", zwnode->name, zwnode->id );;
 }
}

canonical_original_code:
void zw_list_nodes()
{
 struct _node *node = ((void *)0);
 struct zw_node *zwnode;
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  syslog( 5, "ZW_NODE: %s - %d\n", zwnode->name, zwnode->id );;
 }
}


decompiled_code:
__int64 __fastcall register_zw_node(__int64 a1, _BYTE *a2, __int64 a3)
{
unsigned int v4; // ebp
void **v5; // rbx
char v7; // di
unsigned __int8 v8; // al

v4 = a3;
syslog(5, "register_zw_node: %d\n", a3);
fflush(stdout);
v5 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
while ( *((_DWORD *)v5 + 12) != v4 )
{
v5 = (void **)*v5;
if ( v5 == &zw_nodes )
return 0xFFFFFFFFLL;
}
*((_BYTE *)v5 + 52) = a2[2];
*((_BYTE *)v5 + 53) = a2[3];
*((_BYTE *)v5 + 54) = a2[5];
v7 = a2[6];
*((_BYTE *)v5 + 55) = v7;
*((_BYTE *)v5 + 56) = a2[7];
v8 = get_cmd_class(v7);
*((_BYTE *)v5 + 57) = v8;
cc_get(a1, (unsigned __int8)v4, v8, (char *)v5 + 59);
syslog(
5,
"register_zw_node: %d func=%d, bt=%d, gt=%d, st=%d\n",
v4,
*((unsigned __int8 *)v5 + 53),
*((unsigned __int8 *)v5 + 54),
*((unsigned __int8 *)v5 + 55),
*((unsigned __int8 *)v5 + 56));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, _BYTE *a2, __int64 a3)
{
unsigned int v4; // ebp
void **v5; // rbx
char v7; // di
unsigned __int8 v8; // al

v4 = a3;
syslog(5, "register_zw_node: %d\n", a3);
fflush(stdout);
v5 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
while ( *((_DWORD *)v5 + 12) != v4 )
{
v5 = (void **)*v5;
if ( v5 == &zw_nodes )
return 0xFFFFFFFFLL;
}
*((_BYTE *)v5 + 52) = a2[2];
*((_BYTE *)v5 + 53) = a2[3];
*((_BYTE *)v5 + 54) = a2[5];
v7 = a2[6];
*((_BYTE *)v5 + 55) = v7;
*((_BYTE *)v5 + 56) = a2[7];
v8 = func1(v7);
*((_BYTE *)v5 + 57) = v8;
cc_get(a1, (unsigned __int8)v4, v8, (char *)v5 + 59);
syslog(
5,
"register_zw_node: %d func=%d, bt=%d, gt=%d, st=%d\n",
v4,
*((unsigned __int8 *)v5 + 53),
*((unsigned __int8 *)v5 + 54),
*((unsigned __int8 *)v5 + 55),
*((unsigned __int8 *)v5 + 56));
return 0LL;
}

original_code:
int
register_zw_node( zw_api_ctx_S *ctx, const u8 *frame, int id )
{
 list_node *node = ((void *)0);
 struct zw_node *zwnode;
 int rc = -1;
 syslog( 5, "register_zw_node: %d\n", id );;
 fflush(stdout);
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  if ( zwnode->id == id ) {
   zwnode->mode = frame[ 2 ];
   zwnode->func = frame[ 3 ];
   zwnode->btype = frame[ 5 ];
   zwnode->gtype = frame[ 6 ];
   zwnode->stype = frame[ 7 ];
   zwnode->cclass = get_cmd_class( zwnode->gtype );
   cc_get( ctx, id, zwnode->cclass, (void *)&zwnode->state );
   rc = 0;
                        syslog( 5, "register_zw_node: %d func=%d, bt=%d, gt=%d, st=%d\n", id, zwnode->func, zwnode->btype, zwnode->gtype, zwnode->stype );;
   break;
  }
 }
 return rc;
}

canonical_original_code:
int register_zw_node(struct zw_api_ctx *ctx, unsigned char *frame, int id)
{
 struct _node *node = ((void *)0);
 struct zw_node *zwnode;
 int rc = -1;
 syslog( 5, "register_zw_node: %d\n", id );;
 fflush(stdout);
 for(node = (&zw_nodes)->next; node != (&zw_nodes); node = node->next) {
  zwnode = (struct zw_node *)node;
  if ( zwnode->id == id ) {
   zwnode->mode = frame[ 2 ];
   zwnode->func = frame[ 3 ];
   zwnode->btype = frame[ 5 ];
   zwnode->gtype = frame[ 6 ];
   zwnode->stype = frame[ 7 ];
   zwnode->cclass = get_cmd_class( zwnode->gtype );
   cc_get( ctx, id, zwnode->cclass, (void *)&zwnode->state );
   rc = 0;
                        syslog( 5, "register_zw_node: %d func=%d, bt=%d, gt=%d, st=%d\n", id, zwnode->func, zwnode->btype, zwnode->gtype, zwnode->stype );;
   break;
  }
 }
 return rc;
}

variable_types:
frame
unsigned char *

variable_types: id int


decompiled_code:
__int64 __fastcall unregister_zw_node(int a1)
{
void **v1; // rsi

v1 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
while ( *((_DWORD *)v1 + 12) != a1 )
{
v1 = (void **)*v1;
if ( v1 == &zw_nodes )
return 0xFFFFFFFFLL;
}
list_remove((_QWORD **)&zw_nodes, v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
void **v1; // rsi

v1 = (void **)zw_nodes;
if ( zw_nodes == &zw_nodes )
return 0xFFFFFFFFLL;
while ( *((_DWORD *)v1 + 12) != a1 )
{
v1 = (void **)*v1;
if ( v1 == &zw_nodes )
return 0xFFFFFFFFLL;
}
list_remove((_QWORD **)&zw_nodes, v1);
return 0LL;
}

original_code:
int
unregister_zw_node( int id )
{
 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 ) {
   rc = 0;
   break;
  }
 }
 if ( 0 == rc )
  list_remove((list_node *)&zw_nodes, (list_node *)zwnode);
 return rc;
}

canonical_original_code:
int unregister_zw_node(int id)
{
 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 ) {
   rc = 0;
   break;
  }
 }
 if ( 0 == rc )
  list_remove((struct _node *)&zw_nodes, (struct _node *)zwnode);
 return rc;
}


original_code:
static int
toggle_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] = 0x28;
 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 toggle_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] = 0x28;
 buff[4] = 0x01;
 buff[5] = level;
 buff[6] = 0x01 | 0x04;
 return zw_send_request( ctx, buff, 7, 3, 1, 0x13 );
}

variable_types:
nodeid
unsigned char

variable_types:
buff
unsigned char [1024]

variable_types: level int


decompiled_code:
__int64 __fastcall toggle_sw_get(__int64 a1, char a2, _DWORD *a3)
{
unsigned int v4; // ebx
struct timespec v6; // [rsp+0h] [rbp-428h] BYREF
char v7[1048]; // [rsp+10h] [rbp-418h] BYREF

v7[0] = 19;
v7[1] = a2;
v7[2] = 2;
v7[3] = 40;
v7[4] = 2;
v7[5] = 5;
v7[6] = 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(&tsw_value, &val_lock, &v6);
*a3 = tsw_val;
pthread_mutex_unlock(&val_lock);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2, _DWORD *a3)
{
unsigned int v4; // ebx
struct timespec v6; // [rsp+0h] [rbp-428h] BYREF
char v7[1048]; // [rsp+10h] [rbp-418h] BYREF

v7[0] = 19;
v7[1] = a2;
v7[2] = 2;
v7[3] = 40;
v7[4] = 2;
v7[5] = 5;
v7[6] = 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(&tsw_value, &val_lock, &v6);
*a3 = tsw_val;
pthread_mutex_unlock(&val_lock);
return v4;
}

original_code:
static int
toggle_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] = 0x28;
 buff[4] = 0x02;
 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(&tsw_value, &val_lock, &ts);
 *value = tsw_val;
 pthread_mutex_unlock( &val_lock );
 return rc;
}

canonical_original_code:
static int toggle_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] = 0x28;
 buff[4] = 0x02;
 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(&tsw_value, &val_lock, &ts);
 *value = tsw_val;
 pthread_mutex_unlock( &val_lock );
 return rc;
}

variable_types:
value
int *

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


decompiled_code:
__int64 __fastcall toggle_sw_report(__int64 a1, char a2, _DWORD *a3)
{
return toggle_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
toggle_sw_report( zw_api_ctx_S *ctx, u8 nodeid, void *resp )
{
 return toggle_sw_get( ctx, nodeid, resp );
}

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


decompiled_code:
__int64 __fastcall toggle_sw_proc_msg(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned __int8 v4; // dl
int v5; // ebx

syslog(7, "COMMAND_CLASS_BINARY_TOGGLE_SWITCH - processing message");
v4 = *(_BYTE *)(a2 + 6);
switch ( v4 )
{
case 1u:
syslog(7, "SWITCH_TOGGLE_BINARY_SET received from node %d value %d", a3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
case 2u:
syslog(7, "SWITCH_TOGGLE_BINARY_GET received from node %d value %d", a3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
case 3u:
syslog(7, "SWITCH_TOGGLE_BINARY_REPORT received from node %d value %d", a3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
default:
syslog(5, "%i received from node %d", v4, a3);
return 0LL;
}
pthread_mutex_lock(&val_lock);
tsw_val = v5;
pthread_cond_broadcast(&tsw_value);
pthread_mutex_unlock(&val_lock);
return 0LL;
}

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

syslog(7, "COMMAND_CLASS_BINARY_TOGGLE_SWITCH - processing message");
v4 = *(_BYTE *)(a2 + 6);
switch ( v4 )
{
case 1u:
syslog(7, "SWITCH_TOGGLE_BINARY_SET received from node %d value %d", a3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
case 2u:
syslog(7, "SWITCH_TOGGLE_BINARY_GET received from node %d value %d", a3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
case 3u:
syslog(7, "SWITCH_TOGGLE_BINARY_REPORT received from node %d value %d", a3, *(unsigned __int8 *)(a2 + 7));
v5 = *(unsigned __int8 *)(a2 + 7);
break;
default:
syslog(5, "%i received from node %d", v4, a3);
return 0LL;
}
pthread_mutex_lock(&val_lock);
tsw_val = v5;
pthread_cond_broadcast(&tsw_value);
pthread_mutex_unlock(&val_lock);
return 0LL;
}

original_code:
static int
toggle_sw_proc_msg( zw_api_ctx_S *ctx, const u8* frame, u8 nodeid )
{
 int val = -1;
 syslog( 7, "COMMAND_CLASS_BINARY_TOGGLE_SWITCH - processing message" );;
 if ((unsigned char)frame[6] == 0x01) {
  syslog( 7, "SWITCH_TOGGLE_BINARY_SET received from node %d value %d", nodeid,(unsigned char)frame[7] );;
  val = frame[7];
 }
 else if ((unsigned char)frame[6] == 0x02) {
  syslog( 7, "SWITCH_TOGGLE_BINARY_GET received from node %d value %d", nodeid,(unsigned char)frame[7] );;
  val = frame[7];
 }
 else if ((unsigned char)frame[6] == 0x03) {
  syslog( 7, "SWITCH_TOGGLE_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 );
 tsw_val = val;
 pthread_cond_broadcast( &tsw_value );
 pthread_mutex_unlock( &val_lock );
out:
 return 0;
}

canonical_original_code:
static int toggle_sw_proc_msg(struct zw_api_ctx *ctx, unsigned char *frame, unsigned char nodeid)
{
 int val = -1;
 syslog( 7, "COMMAND_CLASS_BINARY_TOGGLE_SWITCH - processing message" );;
 if ((unsigned char)frame[6] == 0x01) {
  syslog( 7, "SWITCH_TOGGLE_BINARY_SET received from node %d value %d", nodeid,(unsigned char)frame[7] );;
  val = frame[7];
 }
 else if ((unsigned char)frame[6] == 0x02) {
  syslog( 7, "SWITCH_TOGGLE_BINARY_GET received from node %d value %d", nodeid,(unsigned char)frame[7] );;
  val = frame[7];
 }
 else if ((unsigned char)frame[6] == 0x03) {
  syslog( 7, "SWITCH_TOGGLE_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 );
 tsw_val = val;
 pthread_cond_broadcast( &tsw_value );
 pthread_mutex_unlock( &val_lock );
out:
 return 0;
}


decompiled_code:
__int64 toggle_sw_init()
{
return register_cmd_class(&toggle_sw);
}

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

original_code:
static void __attribute__ ((constructor)) toggle_sw_init( void )
{
 register_cmd_class( &toggle_sw );
}

canonical_original_code:
static void toggle_sw_init()
{
 register_cmd_class( &toggle_sw );
}


decompiled_code:
int toggle_sw_exit()
{
unregister_cmd_class(&toggle_sw);
pthread_cond_destroy(&tsw_value);
return pthread_mutex_destroy(&val_lock);
}

canonical_decompiled_code:
int func5()
{
unregister_cmd_class(&toggle_sw);
pthread_cond_destroy(&tsw_value);
return pthread_mutex_destroy(&val_lock);
}

original_code:
static void __attribute__ ((destructor)) toggle_sw_exit( void )
{
 unregister_cmd_class( &toggle_sw );
 pthread_cond_destroy( &tsw_value );
 pthread_mutex_destroy( &val_lock );
}

canonical_original_code:
static void toggle_sw_exit()
{
 unregister_cmd_class( &toggle_sw );
 pthread_cond_destroy( &tsw_value );
 pthread_mutex_destroy( &val_lock );
}


decompiled_code:
void print_cmd_classes()
{
const char **v0; // rbx

v0 = (const char **)cmd_classes;
if ( cmd_classes != &cmd_classes )
{
do
{
syslog(7, "CmdClass: %s", v0[2]);
v0 = (const char **)*v0;
}
while ( v0 != (const char **)&cmd_classes );
}
}

canonical_decompiled_code:
void func1()
{
const char **v0; // rbx

v0 = (const char **)cmd_classes;
if ( cmd_classes != &cmd_classes )
{
do
{
syslog(7, "CmdClass: %s", v0[2]);
v0 = (const char **)*v0;
}
while ( v0 != (const char **)&cmd_classes );
}
}

original_code:
void print_cmd_classes()
{
 list_node *node = ((void *)0);
 for(node = (&cmd_classes)->next; node != (&cmd_classes); node = node->next) {
  syslog( 7, "CmdClass: %s", ((struct cmd_class *)node)->name );;
 }
}

canonical_original_code:
void print_cmd_classes()
{
 struct _node *node = ((void *)0);
 for(node = (&cmd_classes)->next; node != (&cmd_classes); node = node->next) {
  syslog( 7, "CmdClass: %s", ((struct cmd_class *)node)->name );;
 }
}

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

user_defined_types: struct cmd_class { struct _node list; char *name; unsigned char type; int (*process_msg)(struct zw_api_ctx *ctx, unsigned char *frame, unsigned char nodeid); int (*version)(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp); int (*get)(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp); int (*set)(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp); int (*report)(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp); }