main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r15
const char **v4; // r12
int v5; // ebp
char v6; // al
__int64 v7; // rbx
_QWORD *i; // rbx
const char *v10; // rbx
char v11; // al
__int64 v12; // rax
unsigned int v13; // [rsp+8h] [rbp-40h]
int v14; // [rsp+Ch] [rbp-3Ch]

v3 = list_new(0LL, argv, envp);
v14 = 0;
if ( !setlocale(6, &locale) )
{
fprintf(stderr, "%s: Warning: Locale not specified :(\n", *argv);
v14 = 1;
}
signal(1, (__sighandler_t)sigh);
signal(2, (__sighandler_t)sigh);
signal(15, (__sighandler_t)sigh);
signal(3, (__sighandler_t)sigh);
if ( argc <= 1 )
{
v5 = argc;
v13 = 0;
goto LABEL_28;
}
v4 = argv + 1;
v13 = 0;
v5 = 1;
while ( 1 )
{
v10 = *v4;
v11 = **v4;
if ( v11 != 45 )
{
if ( v11 != 43 )
goto LABEL_28;
if ( (unsigned int)str_numeric(v10 + 1) )
{
v12 = ustrprintf("%sG", *v4 + 1);
list_append(v3, v12);
}
else
{
v7 = ustrdup(*v4 + 1);
str_escape(v7);
list_append(v3, v7);
}
goto LABEL_27;
}
if ( strlen(*v4) != 2 )
break;
v6 = v10[1];
if ( v6 == 45 )
{
++v5;
goto LABEL_28;
}
if ( v6 != 82 )
{
fprintf(stderr, "unknown option: \"%s\"\n", v10);
usage(*argv);
}
v13 = 1;
LABEL_27:
if ( argc == ++v5 )
goto LABEL_28;
++v4;
}
if ( strcmp(v10, "-") )
{
fprintf(stderr, "invalid option: \"%s\"\n", v10);
usage(*argv);
}
LABEL_28:
if ( (int)list_count(v3) > 0 )
{
for ( i = (_QWORD *)list_gettail(v3); i; i = (_QWORD *)i[2] )
gui_queue(*i);
}
list_free(v3, &free);
if ( !isatty(0) )
{
fwrite("uvi: warning: input is not a terminal\n", 1uLL, 0x26uLL, stderr);
if ( isatty(1) )
goto LABEL_19;
goto LABEL_18;
}
if ( !isatty(1) )
{
LABEL_18:
fwrite("uvi: warning: output is not a terminal\n", 1uLL, 0x27uLL, stderr);
goto LABEL_19;
}
if ( v14 )
LABEL_19:
sleep(1u);
vars_default();
map_init();
gui_init();
gui_term();
rc_read();
info_read();
buffers_init((unsigned int)(argc - v5), &argv[v5], v13);
gui_reload();
gui_run();
gui_term();
info_write();
map_term();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r15
const char **v4; // r12
int v5; // ebp
char v6; // al
__int64 v7; // rbx
_QWORD *i; // rbx
const char *v10; // rbx
char v11; // al
__int64 v12; // rax
unsigned int v13; // [rsp+8h] [rbp-40h]
int v14; // [rsp+Ch] [rbp-3Ch]

v3 = list_new(0LL, argv, envp);
v14 = 0;
if ( !setlocale(6, &locale) )
{
fprintf(stderr, "%s: Warning: Locale not specified :(\n", *argv);
v14 = 1;
}
signal(1, (__sighandler_t)sigh);
signal(2, (__sighandler_t)sigh);
signal(15, (__sighandler_t)sigh);
signal(3, (__sighandler_t)sigh);
if ( argc <= 1 )
{
v5 = argc;
v13 = 0;
goto LABEL_28;
}
v4 = argv + 1;
v13 = 0;
v5 = 1;
while ( 1 )
{
v10 = *v4;
v11 = **v4;
if ( v11 != 45 )
{
if ( v11 != 43 )
goto LABEL_28;
if ( (unsigned int)str_numeric(v10 + 1) )
{
v12 = ustrprintf("%sG", *v4 + 1);
list_append(v3, v12);
}
else
{
v7 = ustrdup(*v4 + 1);
str_escape(v7);
list_append(v3, v7);
}
goto LABEL_27;
}
if ( strlen(*v4) != 2 )
break;
v6 = v10[1];
if ( v6 == 45 )
{
++v5;
goto LABEL_28;
}
if ( v6 != 82 )
{
fprintf(stderr, "unknown option: \"%s\"\n", v10);
func1(*argv);
}
v13 = 1;
LABEL_27:
if ( argc == ++v5 )
goto LABEL_28;
++v4;
}
if ( strcmp(v10, "-") )
{
fprintf(stderr, "invalid option: \"%s\"\n", v10);
func1(*argv);
}
LABEL_28:
if ( (int)list_count(v3) > 0 )
{
for ( i = (_QWORD *)list_gettail(v3); i; i = (_QWORD *)i[2] )
gui_queue(*i);
}
list_free(v3, &free);
if ( !isatty(0) )
{
fwrite("uvi: warning: input is not a terminal\n", 1uLL, 0x26uLL, stderr);
if ( isatty(1) )
goto LABEL_19;
goto LABEL_18;
}
if ( !isatty(1) )
{
LABEL_18:
fwrite("uvi: warning: output is not a terminal\n", 1uLL, 0x27uLL, stderr);
goto LABEL_19;
}
if ( v14 )
LABEL_19:
sleep(1u);
vars_default();
map_init();
gui_init();
gui_term();
rc_read();
info_read();
buffers_init((unsigned int)(argc - v5), &argv[v5], v13);
gui_reload();
gui_run();
gui_term();
info_write();
map_term();
return 0;
}

original_code:
int main(int argc, const char **argv)
{
 struct list *cmds = list_new(((void *)0));
 int i, argv_options = 1;
 int argv_fname_start = argc;
 int ro = 0;
 int wait = 0;
 if(setlocale(6, "") == ((void *)0)){
  fprintf(stderr, "%s: Warning: Locale not specified :(\n", *argv);
  wait = 1;
 }
 signal(1, &sigh);
 signal(2, &sigh);
 signal(15, &sigh);
 signal(3, &sigh);
 for(i = 1; i < argc; i++)
  if(argv_options && *argv[i] == '-'){
   if(strlen(argv[i]) == 2){
    switch(argv[i][1]){
     case '-':
      argv_options = 0;
      break;
     case 'R':
      ro = 1;
      break;
     default:
      fprintf(stderr, "unknown option: \"%s\"\n", argv[i]);
      usage(*argv);
    }
   }else if(!strcmp(argv[i], "-")){
    argv_options = 0;
    goto at_fnames;
   }else{
    fprintf(stderr, "invalid option: \"%s\"\n", argv[i]);
    usage(*argv);
   }
  }else if(argv_options && *argv[i] == '+'){
   if(str_numeric(argv[i] + 1)){
    list_append(cmds, ustrprintf("%sG", argv[i] + 1));
   }else{
    char *s = ustrdup(argv[i] + 1);
    str_escape(s);
    list_append(cmds, s);
   }
  }else{
at_fnames:
   argv_fname_start = i;
   break;
  }
 if(list_count(cmds) > 0){
  struct list *l = list_gettail(cmds);
  while(l){
   gui_queue(l->data);
   l = l->prev;
  }
 }
 list_free(cmds, free);
 if(!isatty(0)){
  fputs("uvi: warning: input is not a terminal\n", stderr);
  wait = 1;
 }
 if(!isatty(1)){
  fputs("uvi: warning: output is not a terminal\n", stderr);
  wait = 1;
 }
 if(wait)
  sleep(1);
 vars_default();
 map_init();
 gui_init();
 gui_term();
 rc_read();
 info_read();
 buffers_init(
   argc - argv_fname_start,
   argv + argv_fname_start,
   ro);
 gui_reload();
 gui_run();
 gui_term();
 info_write();
 map_term();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct list *cmds = list_new(((void *)0));
 int i; int argv_options = 1;
 int argv_fname_start = argc;
 int ro = 0;
 int wait = 0;
 if(setlocale(6, "") == ((void *)0)){
  fprintf(stderr, "%s: Warning: Locale not specified :(\n", *argv);
  wait = 1;
 }
 signal(1, &sigh);
 signal(2, &sigh);
 signal(15, &sigh);
 signal(3, &sigh);
 for(i = 1; i < argc; i++)
  if(argv_options && *argv[i] == '-'){
   if(strlen(argv[i]) == 2){
    switch(argv[i][1]){
     case '-':
      argv_options = 0;
      break;
     case 'R':
      ro = 1;
      break;
     default:
      fprintf(stderr, "unknown option: \"%s\"\n", argv[i]);
      usage(*argv);
    }
   }else if(!strcmp(argv[i], "-")){
    argv_options = 0;
    goto at_fnames;
   }else{
    fprintf(stderr, "invalid option: \"%s\"\n", argv[i]);
    usage(*argv);
   }
  }else if(argv_options && *argv[i] == '+'){
   if(str_numeric(argv[i] + 1)){
    list_append(cmds, ustrprintf("%sG", argv[i] + 1));
   }else{
    char *s = ustrdup(argv[i] + 1);
    str_escape(s);
    list_append(cmds, s);
   }
  }else{
at_fnames:
   argv_fname_start = i;
   break;
  }
 if(list_count(cmds) > 0){
  struct list *l = list_gettail(cmds);
  while(l){
   gui_queue(l->data);
   l = l->prev;
  }
 }
 list_free(cmds, free);
 if(!isatty(0)){
  fputs("uvi: warning: input is not a terminal\n", stderr);
  wait = 1;
 }
 if(!isatty(1)){
  fputs("uvi: warning: output is not a terminal\n", stderr);
  wait = 1;
 }
 if(wait)
  sleep(1);
 vars_default();
 map_init();
 gui_init();
 gui_term();
 rc_read();
 info_read();
 buffers_init(
   argc - argv_fname_start,
   argv + argv_fname_start,
   ro);
 gui_reload();
 gui_run();
 gui_term();
 info_write();
 map_term();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct list { void *data; struct list *next; } *

variable_types: i int

variable_types: ro int

variable_types: wait int


repo: bobrippling/uvi

decompiled_code:
int __fastcall term_canon(int fd, int a2)
{
int result; // eax
struct termios v3; // [rsp+0h] [rbp-58h] BYREF

result = tcgetattr(fd, &v3);
if ( result != -1 )
{
if ( a2 )
{
v3.c_lflag |= 0xBu;
v3.c_cc[6] = 0;
v3.c_cc[5] = 0;
}
else
{
v3.c_lflag &= 0xFFFFFFF4;
v3.c_cc[6] = 1;
v3.c_cc[5] = 2;
}
result = tcsetattr(fd, 0, &v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int fd, int a2)
{
int result; // eax
struct termios v3; // [rsp+0h] [rbp-58h] BYREF

result = tcgetattr(fd, &v3);
if ( result != -1 )
{
if ( a2 )
{
v3.c_lflag |= 0xBu;
v3.c_cc[6] = 0;
v3.c_cc[5] = 0;
}
else
{
v3.c_lflag &= 0xFFFFFFF4;
v3.c_cc[6] = 1;
v3.c_cc[5] = 2;
}
result = tcsetattr(fd, 0, &v3);
}
return result;
}

original_code:
void term_canon(int fd, int on)
{
 struct termios attr;
 if(tcgetattr(fd, &attr) == -1)
  return;
 if(on){
  attr.c_lflag |= (0000001|0000002|0000010);
  attr.c_cc[6] = 0;
  attr.c_cc[5] = 0;
 }else{
  attr.c_lflag &= ~(0000001|0000002|0000010);
  attr.c_cc[6] = 1;
  attr.c_cc[5] = 2;
 }
 tcsetattr(fd, 0, &attr);
}

variable_types: fd int

variable_types: on int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

return_type: void


decompiled_code:
int __fastcall kill_a_node(void *ptr)
{
kill(*((_DWORD *)ptr + 2), 15);
pthread_cancel(*((_QWORD *)ptr + 26));
pthread_cancel(*((_QWORD *)ptr + 14));
pthread_join(*((_QWORD *)ptr + 26), 0LL);
pthread_join(*((_QWORD *)ptr + 14), 0LL);
close(*((_DWORD *)ptr + 18));
close(*((_DWORD *)ptr + 6));
close(*((_DWORD *)ptr + 30));
close((_DWORD)ptr + 172);
sleep(1u);
unlink((const char *)ptr + 28);
unlink((const char *)ptr + 76);
unlink((const char *)ptr + 124);
unlink((const char *)ptr + 172);
list_remove(&node_list, ptr);
free(ptr);
return printf("Node %d was terminated.\n", *((unsigned int *)ptr + 3));
}

canonical_decompiled_code:
int __fastcall func3(void *ptr)
{
kill(*((_DWORD *)ptr + 2), 15);
pthread_cancel(*((_QWORD *)ptr + 26));
pthread_cancel(*((_QWORD *)ptr + 14));
pthread_join(*((_QWORD *)ptr + 26), 0LL);
pthread_join(*((_QWORD *)ptr + 14), 0LL);
close(*((_DWORD *)ptr + 18));
close(*((_DWORD *)ptr + 6));
close(*((_DWORD *)ptr + 30));
close((_DWORD)ptr + 172);
sleep(1u);
unlink((const char *)ptr + 28);
unlink((const char *)ptr + 76);
unlink((const char *)ptr + 124);
unlink((const char *)ptr + 172);
list_remove(&node_list, ptr);
free(ptr);
return printf("Node %d was terminated.\n", *((unsigned int *)ptr + 3));
}

original_code:
void static kill_a_node(struct sim_node_t *nd)
{
 kill(nd->pid, 15);
 pthread_cancel(nd->cmd_out.thread);
 pthread_cancel(nd->data_out.thread);
 pthread_join(nd->cmd_out.thread, ((void *)0));
 pthread_join(nd->data_out.thread, ((void *)0));
 close(nd->data_out.pipe);
 close(nd->data_in.pipe);
 close(nd->cmd_in.pipe);
 close(nd->cmd_out.name);
 sleep(1);
 unlink(nd->data_in.name);
 unlink(nd->data_out.name);
 unlink(nd->cmd_in.name);
 unlink(nd->cmd_out.name);
 list_remove(&node_list, &nd->list);
 free(nd);
 printf("Node %d was terminated.\n", nd->index);
}

canonical_original_code:
static void kill_a_node(struct sim_node_t *nd)
{
 kill(nd->pid, 15);
 pthread_cancel(nd->cmd_out.thread);
 pthread_cancel(nd->data_out.thread);
 pthread_join(nd->cmd_out.thread, ((void *)0));
 pthread_join(nd->data_out.thread, ((void *)0));
 close(nd->data_out.pipe);
 close(nd->data_in.pipe);
 close(nd->cmd_in.pipe);
 close(nd->cmd_out.name);
 sleep(1);
 unlink(nd->data_in.name);
 unlink(nd->data_out.name);
 unlink(nd->cmd_in.name);
 unlink(nd->cmd_out.name);
 list_remove(&node_list, &nd->list);
 free(nd);
 printf("Node %d was terminated.\n", nd->index);
}

variable_types: struct sim_node_t { struct list_head { struct list_head *next; } list; int pid; int index; unsigned short addr; struct pipe_t { int pipe; char name[30]; unsigned long thread; } data_in; struct pipe_t data_out; struct pipe_t cmd_in; struct pipe_t cmd_out; unsigned char buf[128]; unsigned char cmdbuf[128]; } *

user_defined_types: struct sim_node_t { struct list_head list; int pid; int index; unsigned short addr; struct pipe_t data_in; struct pipe_t data_out; struct pipe_t cmd_in; struct pipe_t cmd_out; unsigned char buf[128]; unsigned char cmdbuf[128]; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

INIT_LIST_HEAD(&node_list);
atexit((void (*)(void))sim_kill_all_nodes);
signal(2, (__sighandler_t)sim_kill_all_nodes);
signal(17, (__sighandler_t)sigchld_handler);
mkdir("./log", 0x1FDu);
strcpy(v4, "./log/sim.txt");
freopen(v4, "w", stderr);
mkdir("./fifo", 0x1FDu);
strcpy(file, "./fifo/PUBLIC");
if ( mknod(file, 0x11B6u, 0LL) == -1 )
perror("mknod");
cli();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

func0(&node_list);
atexit((void (*)(void))sim_kill_all_nodes);
signal(2, (__sighandler_t)sim_kill_all_nodes);
signal(17, (__sighandler_t)sigchld_handler);
mkdir("./log", 0x1FDu);
strcpy(v4, "./log/sim.txt");
freopen(v4, "w", stderr);
mkdir("./fifo", 0x1FDu);
strcpy(file, "./fifo/PUBLIC");
if ( mknod(file, 0x11B6u, 0LL) == -1 )
perror("mknod");
cli();
return 0;
}

variable_types:
argv
char *[]

variable_types:
msg
char [50]

return_type: int


decompiled_code:
__int64 __fastcall send_data(__int64 a1)
{
return sim_send_data(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return sim_send_data(a1, 0LL);
}

original_code:
void send_data(char *msg)
{
 sim_send_data(msg, 0);
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall send_cmd(char *a1)
{
char *v1; // rbx
size_t v2; // rbp
unsigned __int8 v3; // al

v1 = strtok(a1, " ");
v2 = (size_t)&a1[strlen(v1) + 1];
v3 = strtol(v1, 0LL, 10);
return sim_send_cmd(v2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char *v1; // rbx
size_t v2; // rbp
unsigned __int8 v3; // al

v1 = strtok(a1, " ");
v2 = (size_t)&a1[strlen(v1) + 1];
v3 = strtol(v1, 0LL, 10);
return sim_send_cmd(v2, v3);
}

original_code:
void send_cmd(char *str)
{
        U8 index;
        char *num, *msg;
        num = strtok(str, " ");
        msg = str + strlen(num) + 1;
        index = strtol(num, ((void *)0), 10);
        sim_send_cmd(msg, index);
}

canonical_original_code:
void send_cmd(char *str)
{
        unsigned char index;
        char *num; char *msg;
        num = strtok(str, " ");
        msg = str + strlen(num) + 1;
        index = strtol(num, ((void *)0), 10);
        sim_send_cmd(msg, index);
}

variable_types:
str
char *

variable_types:
index
unsigned char

variable_types:
num
char *


decompiled_code:
int __fastcall add_node(char *a1)
{
char *v1; // rax
unsigned __int8 v2; // al

v1 = strtok(a1, " ");
if ( !v1 )
return puts("Please add an index number after the 'add' command.");
v2 = strtol(v1, 0LL, 10);
return sim_add_node(v2);
}

canonical_decompiled_code:
int __fastcall func2(char *a1)
{
char *v1; // rax
unsigned __int8 v2; // al

v1 = strtok(a1, " ");
if ( !v1 )
return puts("Please add an index number after the 'add' command.");
v2 = strtol(v1, 0LL, 10);
return sim_add_node(v2);
}

original_code:
void add_node(char *str)
{
 U8 index;
 struct sim_node_t *nd;
 char *tmp;
 tmp = strtok(str, " ");
 if (!tmp)
 {
  printf("Please add an index number after the 'add' command.\n");
  return;
 }
 index = strtol(tmp, ((void *)0), 10);
 sim_add_node(index);
}

canonical_original_code:
void add_node(char *str)
{
 unsigned char index;
 struct sim_node_t *nd;
 char *tmp;
 tmp = strtok(str, " ");
 if (!tmp)
 {
  printf("Please add an index number after the 'add' command.\n");
  return;
 }
 index = strtol(tmp, ((void *)0), 10);
 sim_add_node(index);
}

variable_types:
tmp
char *

user_defined_types: struct list_head { struct list_head *next; }

user_defined_types: struct pipe_t { int pipe; char name[30]; unsigned long thread; }


decompiled_code:
int __fastcall kill_node(char *a1)
{
char *v1; // rax
unsigned __int8 v2; // al

v1 = strtok(a1, " ");
if ( !v1 )
return puts("Please add an index number after the 'add' command.");
v2 = strtol(v1, 0LL, 10);
return sim_kill_nodes(v2);
}

canonical_decompiled_code:
int __fastcall func3(char *a1)
{
char *v1; // rax
unsigned __int8 v2; // al

v1 = strtok(a1, " ");
if ( !v1 )
return puts("Please add an index number after the 'add' command.");
v2 = strtol(v1, 0LL, 10);
return sim_kill_nodes(v2);
}

original_code:
void kill_node(char *str)
{
 U8 index;
 char *tmp;
 tmp = strtok(str, " ");
 if (tmp == ((void *)0))
 {
  printf("Please add an index number after the 'add' command.\n");
  return;
 }
 index = strtol(tmp, ((void *)0), 10);
 sim_kill_nodes(index);
}

canonical_original_code:
void kill_node(char *str)
{
 unsigned char index;
 char *tmp;
 tmp = strtok(str, " ");
 if (tmp == ((void *)0))
 {
  printf("Please add an index number after the 'add' command.\n");
  return;
 }
 index = strtol(tmp, ((void *)0), 10);
 sim_kill_nodes(index);
}


decompiled_code:
__int64 list_nodes()
{
return sim_list_print();
}

canonical_decompiled_code:
__int64 func4()
{
return sim_list_print();
}

original_code:
void list_nodes(char *str)
{
 sim_list_print();
}


decompiled_code:
void __noreturn quit_sim()
{
exit(0);
}

canonical_decompiled_code:
void __noreturn func5()
{
exit(0);
}

original_code:
void quit_sim(char *str)
{
 exit(0);
}

canonical_original_code:
void quit_sim(char *str)
{
 exit(0);
}


decompiled_code:
unsigned __int64 __fastcall write_cli_buf(_BYTE *a1, unsigned __int8 a2)
{
unsigned __int64 result; // rax
_BYTE *v3; // rcx

result = (unsigned __int64)a1;
if ( *a1 == 0xFF )
{
v3 = a1 + 1;
if ( a2 > 7u )
{
result = *(_QWORD *)&v3[a2 - 8];
*(_QWORD *)&cond.__size[a2 + 40] = result;
qmemcpy(s1, a1 + 1, 8LL * (((unsigned int)a2 - 1) >> 3));
}
else if ( (a2 & 4) != 0 )
{
*(_DWORD *)s1 = *(_DWORD *)(a1 + 1);
result = *(unsigned int *)&v3[a2 - 4];
*(unsigned int *)((char *)&cond.__broadcast_seq + a2) = result;
}
else if ( a2 )
{
result = (unsigned __int8)a1[1];
s1[0] = a1[1];
if ( (a2 & 2) != 0 )
{
result = *(unsigned __int16 *)&v3[a2 - 2];
*(_WORD *)&cond.__size[a2 + 46] = result;
}
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(_BYTE *a1, unsigned __int8 a2)
{
unsigned __int64 result; // rax
_BYTE *v3; // rcx

result = (unsigned __int64)a1;
if ( *a1 == 0xFF )
{
v3 = a1 + 1;
if ( a2 > 7u )
{
result = *(_QWORD *)&v3[a2 - 8];
*(_QWORD *)&cond.__size[a2 + 40] = result;
qmemcpy(s1, a1 + 1, 8LL * (((unsigned int)a2 - 1) >> 3));
}
else if ( (a2 & 4) != 0 )
{
*(_DWORD *)s1 = *(_DWORD *)(a1 + 1);
result = *(unsigned int *)&v3[a2 - 4];
*(unsigned int *)((char *)&cond.__broadcast_seq + a2) = result;
}
else if ( a2 )
{
result = (unsigned __int8)a1[1];
s1[0] = a1[1];
if ( (a2 & 2) != 0 )
{
result = *(unsigned __int16 *)&v3[a2 - 2];
*(_WORD *)&cond.__size[a2 + 46] = result;
}
}
}
return result;
}

original_code:
void write_cli_buf(U8 *msg, U8 len)
{
 if (msg[0] == 0xff)
  memcpy(cli_buf.buf, &msg[1], len);
}

canonical_original_code:
void write_cli_buf(unsigned char *msg, unsigned char len)
{
 if (msg[0] == 0xff)
  memcpy(cli_buf.buf, &msg[1], len);
}

variable_types:
msg
unsigned char *

variable_types:
len
unsigned char


decompiled_code:
int __fastcall parse_string(char *a1)
{
char *v1; // rbp
int v2; // ebx
const char *v3; // rsi
int v4; // er12
size_t v6; // rax

v1 = strtok(a1, " ");
v2 = 0;
v3 = "send";
v4 = 0;
while ( strcmp(v1, v3) )
{
v4 = (unsigned __int8)++v2;
v3 = (&cmd_tbl)[2 * (unsigned __int8)v2];
if ( !v3 )
return printf("Command '%s' not recognized.\n", v1);
}
v6 = strlen(v1);
return ((__int64 (__fastcall *)(char *))*(&off_728 + 2 * v4))(&a1[v6 + 1]);
}

canonical_decompiled_code:
int __fastcall func8(char *a1)
{
char *v1; // rbp
int v2; // ebx
const char *v3; // rsi
int v4; // er12
size_t v6; // rax

v1 = strtok(a1, " ");
v2 = 0;
v3 = "send";
v4 = 0;
while ( strcmp(v1, v3) )
{
v4 = (unsigned __int8)++v2;
v3 = (&cmd_tbl)[2 * (unsigned __int8)v2];
if ( !v3 )
return printf("Command '%s' not recognized.\n", v1);
}
v6 = strlen(v1);
return ((__int64 (__fastcall *)(char *))*(&off_728 + 2 * v4))(&a1[v6 + 1]);
}

original_code:
void parse_string(char *str)
{
 char *cmd;
 U8 i = 0;
 cmd = strtok(str, " ");
 for (i = 0; cmd_tbl[i].cmd != ((void *)0); i++)
 {
  if (!strcmp(cmd, cmd_tbl[i].cmd))
  {
      cmd_tbl[i].func(str + strlen(cmd) + 1);
      return;
  }
 }
 printf("Command '%s' not recognized.\n", cmd);
}

canonical_original_code:
void parse_string(char *str)
{
 char *cmd;
 unsigned char i = 0;
 cmd = strtok(str, " ");
 for (i = 0; cmd_tbl[i].cmd != ((void *)0); i++)
 {
  if (!strcmp(cmd, cmd_tbl[i].cmd))
  {
      cmd_tbl[i].func(str + strlen(cmd) + 1);
      return;
  }
 }
 printf("Command '%s' not recognized.\n", cmd);
}

variable_types:
cmd
char *

variable_types:
i
unsigned char


decompiled_code:
int __fastcall process_script(char *a1)
{
char *v1; // rbx
size_t v3; // rax
char *v4; // rax
char *v5; // rbp
int v6; // ebx
struct timespec v7; // [rsp+0h] [rbp-A8h] BYREF
char s[152]; // [rsp+10h] [rbp-98h] BYREF

v1 = strtok(a1, " ");
fp = fopen(v1, "r");
if ( !fp )
return printf("PROCESS_SCRIPT: Cannot open file - %s.\n", v1);
while ( fgets(s, 128, fp) )
{
*strchr(s, 10) = 0;
if ( s[0] )
{
v4 = strtok(s, " ");
if ( !strcmp(v4, "send") )
{
v3 = strlen(v4);
parse_string(&s[v3 + 1]);
}
else if ( !strcmp(v4, "wait") )
{
v5 = &s[strlen(v4) + 1];
v7.tv_sec = time(0LL) + 5;
v7.tv_nsec = 0LL;
if ( pthread_mutex_lock(&cli_buf) )
perror("process script lock mutex");
while ( check_cli_buf(v5) )
{
v6 = pthread_cond_timedwait(&cond, &cli_buf, &v7);
if ( v6 )
{
perror("cond timed wait");
if ( v6 == 110 )
{
puts("ERROR - WAIT CONDITION TIMED OUT");
exit(1);
}
}
}
if ( pthread_mutex_unlock(&cli_buf) )
perror("process script unlock mutex");
}
}
}
fclose(fp);
return puts("SUCCESS: Tests passed and script file closed.");
}

canonical_decompiled_code:
int __fastcall func9(char *a1)
{
char *v1; // rbx
size_t v3; // rax
char *v4; // rax
char *v5; // rbp
int v6; // ebx
struct timespec v7; // [rsp+0h] [rbp-A8h] BYREF
char s[152]; // [rsp+10h] [rbp-98h] BYREF

v1 = strtok(a1, " ");
fp = fopen(v1, "r");
if ( !fp )
return printf("PROCESS_SCRIPT: Cannot open file - %s.\n", v1);
while ( fgets(s, 128, fp) )
{
*strchr(s, 10) = 0;
if ( s[0] )
{
v4 = strtok(s, " ");
if ( !strcmp(v4, "send") )
{
v3 = strlen(v4);
func8(&s[v3 + 1]);
}
else if ( !strcmp(v4, "wait") )
{
v5 = &s[strlen(v4) + 1];
v7.tv_sec = time(0LL) + 5;
v7.tv_nsec = 0LL;
if ( pthread_mutex_lock(&cli_buf) )
perror("process script lock mutex");
while ( func7(v5) )
{
v6 = pthread_cond_timedwait(&cond, &cli_buf, &v7);
if ( v6 )
{
perror("cond timed wait");
if ( v6 == 110 )
{
puts("ERROR - WAIT CONDITION TIMED OUT");
exit(1);
}
}
}
if ( pthread_mutex_unlock(&cli_buf) )
perror("process script unlock mutex");
}
}
}
fclose(fp);
return puts("SUCCESS: Tests passed and script file closed.");
}

original_code:
void process_script(char *str)
{
 char *name, *tmp, *cmdtype, *msg;
 char fcmd[128];
 struct timespec timeout;
 int status;
 name = strtok(str, " ");
 if ((fp = fopen(name, "r")) == ((void *)0))
 {
  printf("PROCESS_SCRIPT: Cannot open file - %s.\n", name);
  return;
 }
 while (fgets(fcmd, 128, fp) != ((void *)0))
 {
  tmp = strchr(fcmd, '\n');
  *tmp = '\0';
  if (fcmd[0] == '\0')
   continue;
  cmdtype = strtok(fcmd, " ");
  if (strcmp(cmdtype, "send") == 0)
  {
   msg = fcmd + strlen(cmdtype) + 1;
   parse_string(msg);
  } else if (strcmp(cmdtype, "wait") == 0) {
   msg = fcmd + strlen(cmdtype) + 1;
   timeout.tv_sec = time(((void *)0)) + 5;
   timeout.tv_nsec = 0;
   status = pthread_mutex_lock(&cli_buf.mutex);
   if (status)
    perror("process script lock mutex");
   while (check_cli_buf(msg))
   {
    status = pthread_cond_timedwait(&cli_buf.cond, &cli_buf.mutex, &timeout);
    if (status)
     perror("cond timed wait");
    if (status == 110)
    {
     printf("ERROR - WAIT CONDITION TIMED OUT\n");
     exit(1);
    }
   }
   status = pthread_mutex_unlock(&cli_buf.mutex);
   if (status)
    perror("process script unlock mutex");
  }
 }
 fclose(fp);
 printf("SUCCESS: Tests passed and script file closed.\n");
}

canonical_original_code:
void process_script(char *str)
{
 char *name; char *tmp; char *cmdtype; char *msg;
 char fcmd[128];
 struct timespec timeout;
 int status;
 name = strtok(str, " ");
 if ((fp = fopen(name, "r")) == ((void *)0))
 {
  printf("PROCESS_SCRIPT: Cannot open file - %s.\n", name);
  return;
 }
 while (fgets(fcmd, 128, fp) != ((void *)0))
 {
  tmp = strchr(fcmd, '\n');
  *tmp = '\0';
  if (fcmd[0] == '\0')
   continue;
  cmdtype = strtok(fcmd, " ");
  if (strcmp(cmdtype, "send") == 0)
  {
   msg = fcmd + strlen(cmdtype) + 1;
   parse_string(msg);
  } else if (strcmp(cmdtype, "wait") == 0) {
   msg = fcmd + strlen(cmdtype) + 1;
   timeout.tv_sec = time(((void *)0)) + 5;
   timeout.tv_nsec = 0;
   status = pthread_mutex_lock(&cli_buf.mutex);
   if (status)
    perror("process script lock mutex");
   while (check_cli_buf(msg))
   {
    status = pthread_cond_timedwait(&cli_buf.cond, &cli_buf.mutex, &timeout);
    if (status)
     perror("cond timed wait");
    if (status == 110)
    {
     printf("ERROR - WAIT CONDITION TIMED OUT\n");
     exit(1);
    }
   }
   status = pthread_mutex_unlock(&cli_buf.mutex);
   if (status)
    perror("process script unlock mutex");
  }
 }
 fclose(fp);
 printf("SUCCESS: Tests passed and script file closed.\n");
}

variable_types:
name
char *

variable_types:
cmdtype
char *

variable_types:
fcmd
char [128]

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

variable_types: status int


cli

decompiled_code:
void __noreturn cli()
{
char *v0; // rax
char v1[520]; // [rsp+0h] [rbp-208h] BYREF

while ( 1 )
{
printf("FreakZim>> ");
fflush(stdout);
fgets(v1, 512, stdin);
v0 = strchr(v1, 10);
if ( v0 )
*v0 = 0;
if ( v1[0] )
parse_string(v1);
}
}

canonical_decompiled_code:
void __noreturn func11()
{
char *v0; // rax
char v1[520]; // [rsp+0h] [rbp-208h] BYREF

while ( 1 )
{
printf("FreakZim>> ");
fflush(stdout);
fgets(v1, 512, stdin);
v0 = strchr(v1, 10);
if ( v0 )
*v0 = 0;
if ( v1[0] )
func8(v1);
}
}

original_code:
void cli()
{
 char msg[512];
 char *msg_ptr = ((void *)0);
 struct sim_node_t *nd;
 while (1)
 {
  printf("FreakZim>> ");
  fflush(stdout);
  fgets(msg, sizeof(msg), stdin);
  msg_ptr = strchr(msg, '\n');
  if (msg_ptr)
   *msg_ptr = '\0';
  if (strcmp(msg, "\0"))
   parse_string(msg);
 }
}

variable_types:
msg
char [512]

variable_types: struct sim_node_t { struct list_head { struct list_head *next; } list; int pid; int index; unsigned short addr; struct pipe_t { int pipe; char name[30]; unsigned long thread; } data_in; struct pipe_t data_out; struct pipe_t cmd_in; struct pipe_t cmd_out; unsigned char buf[128]; unsigned char cmdbuf[128]; } *


decompiled_code:
__int64 __fastcall list_head(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
struct list_head *list_head(struct list_head *list)
{
 return list->next;
}

variable_types:
list
struct list_head *

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


decompiled_code:
__int64 __fastcall list_length(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = (_QWORD *)*v1;
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = (_QWORD *)*v1;
}
while ( v1 );
return v2;
}

original_code:
int list_length(struct list_head *list)
{
 struct list_head *l;
 int n = 0;
 for(l = list->next; l != ((void *)0); l = l->next) {
  ++n;
 }
 return n;
}

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

variable_types: n int


decompiled_code:
char *__fastcall l2tp_code(unsigned int a1)
{
char *result; // rax

if ( a1 > 0x10 || (result = (char *)l2tp_codes[a1]) == 0LL )
{
snprintf(n_11, 0x10uLL, "%d", a1);
result = n_11;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1)
{
char *result; // rax

if ( a1 > 0x10 || (result = (char *)l2tp_codes[a1]) == 0LL )
{
snprintf(n_11, 0x10uLL, "%d", a1);
result = n_11;
}
return result;
}

original_code: char const *l2tp_code(int index) { static char n[16]; if (index >= 0 && index < sizeof(l2tp_codes) / sizeof(l2tp_codes[0]) && l2tp_codes[index]) return l2tp_codes[index]; snprintf(n, sizeof(n), "%d", index); return n; }

canonical_original_code: char *l2tp_code(int index) { static char n[16]; if (index >= 0 && index < sizeof(l2tp_codes) / sizeof(l2tp_codes[0]) && l2tp_codes[index]) return l2tp_codes[index]; snprintf(n, sizeof(n), "%d", index); return n; }

variable_types: index int

variable_types:
n
char [16]

return_type: char *


decompiled_code:
char *__fastcall l2tp_avp_name(unsigned int a1)
{
char *result; // rax

if ( a1 > 0x27 || (result = l2tp_avp_names[a1]) == 0LL )
{
snprintf(n_10, 0x10uLL, "%d", a1);
result = n_10;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(unsigned int a1)
{
char *result; // rax

if ( a1 > 0x27 || (result = l2tp_avp_names[a1]) == 0LL )
{
snprintf(n_10, 0x10uLL, "%d", a1);
result = n_10;
}
return result;
}

original_code: char const *l2tp_avp_name(int index) { static char n[16]; if (index >= 0 && index < sizeof(l2tp_avp_names) / sizeof(l2tp_avp_names[0]) && l2tp_avp_names[index]) return l2tp_avp_names[index]; snprintf(n, sizeof(n), "%d", index); return n; }

canonical_original_code: char *l2tp_avp_name(int index) { static char n[16]; if (index >= 0 && index < sizeof(l2tp_avp_names) / sizeof(l2tp_avp_names[0]) && l2tp_avp_names[index]) return l2tp_avp_names[index]; snprintf(n, sizeof(n), "%d", index); return n; }


decompiled_code:
char *__fastcall l2tp_stopccn_result_code(unsigned int a1)
{
char *result; // rax

if ( a1 > 7 || (result = (char *)l2tp_stopccn_result_codes[a1]) == 0LL )
{
snprintf(n_9, 0x10uLL, "%d", a1);
result = n_9;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1)
{
char *result; // rax

if ( a1 > 7 || (result = (char *)l2tp_stopccn_result_codes[a1]) == 0LL )
{
snprintf(n_9, 0x10uLL, "%d", a1);
result = n_9;
}
return result;
}

original_code: char const *l2tp_stopccn_result_code(int index) { static char n[16]; if (index >= 0 && index < sizeof(l2tp_stopccn_result_codes) / sizeof(l2tp_stopccn_result_codes[0]) && l2tp_stopccn_result_codes[index]) return l2tp_stopccn_result_codes[index]; snprintf(n, sizeof(n), "%d", index); return n; }

canonical_original_code: char *l2tp_stopccn_result_code(int index) { static char n[16]; if (index >= 0 && index < sizeof(l2tp_stopccn_result_codes) / sizeof(l2tp_stopccn_result_codes[0]) && l2tp_stopccn_result_codes[index]) return l2tp_stopccn_result_codes[index]; snprintf(n, sizeof(n), "%d", index); return n; }


decompiled_code:
char *__fastcall l2tp_cdn_result_code(unsigned int a1)
{
char *result; // rax

if ( a1 > 0xB || (result = (char *)l2tp_cdn_result_codes[a1]) == 0LL )
{
snprintf(n_8, 0x10uLL, "%d", a1);
result = n_8;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(unsigned int a1)
{
char *result; // rax

if ( a1 > 0xB || (result = (char *)l2tp_cdn_result_codes[a1]) == 0LL )
{
snprintf(n_8, 0x10uLL, "%d", a1);
result = n_8;
}
return result;
}

original_code: char const *l2tp_cdn_result_code(int index) { static char n[16]; if (index >= 0 && index < sizeof(l2tp_cdn_result_codes) / sizeof(l2tp_cdn_result_codes[0]) && l2tp_cdn_result_codes[index]) return l2tp_cdn_result_codes[index]; snprintf(n, sizeof(n), "%d", index); return n; }

canonical_original_code: char *l2tp_cdn_result_code(int index) { static char n[16]; if (index >= 0 && index < sizeof(l2tp_cdn_result_codes) / sizeof(l2tp_cdn_result_codes[0]) && l2tp_cdn_result_codes[index]) return l2tp_cdn_result_codes[index]; snprintf(n, sizeof(n), "%d", index); return n; }


decompiled_code:
char *__fastcall l2tp_error_code(unsigned int a1)
{
char *result; // rax

if ( a1 > 8 || (result = l2tp_error_codes[a1]) == 0LL )
{
snprintf(n_7, 0x10uLL, "%d", a1);
result = n_7;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(unsigned int a1)
{
char *result; // rax

if ( a1 > 8 || (result = l2tp_error_codes[a1]) == 0LL )
{
snprintf(n_7, 0x10uLL, "%d", a1);
result = n_7;
}
return result;
}

original_code: char const *l2tp_error_code(int index) { static char n[16]; if (index >= 0 && index < sizeof(l2tp_error_codes) / sizeof(l2tp_error_codes[0]) && l2tp_error_codes[index]) return l2tp_error_codes[index]; snprintf(n, sizeof(n), "%d", index); return n; }

canonical_original_code: char *l2tp_error_code(int index) { static char n[16]; if (index >= 0 && index < sizeof(l2tp_error_codes) / sizeof(l2tp_error_codes[0]) && l2tp_error_codes[index]) return l2tp_error_codes[index]; snprintf(n, sizeof(n), "%d", index); return n; }


decompiled_code:
char *__fastcall ppp_phase(unsigned int a1)
{
char *result; // rax

if ( a1 > 4 || (result = ppp_phases[a1]) == 0LL )
{
snprintf(n_6, 0x10uLL, "%d", a1);
result = n_6;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func5(unsigned int a1)
{
char *result; // rax

if ( a1 > 4 || (result = ppp_phases[a1]) == 0LL )
{
snprintf(n_6, 0x10uLL, "%d", a1);
result = n_6;
}
return result;
}

original_code: char const *ppp_phase(int index) { static char n[16]; if (index >= 0 && index < sizeof(ppp_phases) / sizeof(ppp_phases[0]) && ppp_phases[index]) return ppp_phases[index]; snprintf(n, sizeof(n), "%d", index); return n; }

canonical_original_code: char *ppp_phase(int index) { static char n[16]; if (index >= 0 && index < sizeof(ppp_phases) / sizeof(ppp_phases[0]) && ppp_phases[index]) return ppp_phases[index]; snprintf(n, sizeof(n), "%d", index); return n; }


decompiled_code:
char *__fastcall ppp_state(unsigned int a1)
{
char *result; // rax

if ( a1 > 9 || (result = ppp_states[a1]) == 0LL )
{
snprintf(n_5, 0x10uLL, "%d", a1);
result = n_5;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func6(unsigned int a1)
{
char *result; // rax

if ( a1 > 9 || (result = ppp_states[a1]) == 0LL )
{
snprintf(n_5, 0x10uLL, "%d", a1);
result = n_5;
}
return result;
}

original_code: char const *ppp_state(int index) { static char n[16]; if (index >= 0 && index < sizeof(ppp_states) / sizeof(ppp_states[0]) && ppp_states[index]) return ppp_states[index]; snprintf(n, sizeof(n), "%d", index); return n; }

canonical_original_code: char *ppp_state(int index) { static char n[16]; if (index >= 0 && index < sizeof(ppp_states) / sizeof(ppp_states[0]) && ppp_states[index]) return ppp_states[index]; snprintf(n, sizeof(n), "%d", index); return n; }


decompiled_code:
char *__fastcall ppp_auth_type(unsigned int a1)
{
char *result; // rax

if ( a1 > 5 || (result = (char *)ppp_auth_types[a1]) == 0LL )
{
snprintf(n_4, 0x10uLL, "%d", a1);
result = n_4;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func7(unsigned int a1)
{
char *result; // rax

if ( a1 > 5 || (result = (char *)ppp_auth_types[a1]) == 0LL )
{
snprintf(n_4, 0x10uLL, "%d", a1);
result = n_4;
}
return result;
}

original_code: char const *ppp_auth_type(int index) { static char n[16]; if (index >= 0 && index < sizeof(ppp_auth_types) / sizeof(ppp_auth_types[0]) && ppp_auth_types[index]) return ppp_auth_types[index]; snprintf(n, sizeof(n), "%d", index); return n; }

canonical_original_code: char *ppp_auth_type(int index) { static char n[16]; if (index >= 0 && index < sizeof(ppp_auth_types) / sizeof(ppp_auth_types[0]) && ppp_auth_types[index]) return ppp_auth_types[index]; snprintf(n, sizeof(n), "%d", index); return n; }


decompiled_code:
char *__fastcall ppp_code(unsigned int a1)
{
char *result; // rax

if ( a1 > 0xC || (result = (char *)ppp_codes[a1]) == 0LL )
{
snprintf(n_3, 0x10uLL, "%d", a1);
result = n_3;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(unsigned int a1)
{
char *result; // rax

if ( a1 > 0xC || (result = (char *)ppp_codes[a1]) == 0LL )
{
snprintf(n_3, 0x10uLL, "%d", a1);
result = n_3;
}
return result;
}

original_code: char const *ppp_code(int index) { static char n[16]; if (index >= 0 && index < sizeof(ppp_codes) / sizeof(ppp_codes[0]) && ppp_codes[index]) return ppp_codes[index]; snprintf(n, sizeof(n), "%d", index); return n; }

canonical_original_code: char *ppp_code(int index) { static char n[16]; if (index >= 0 && index < sizeof(ppp_codes) / sizeof(ppp_codes[0]) && ppp_codes[index]) return ppp_codes[index]; snprintf(n, sizeof(n), "%d", index); return n; }


decompiled_code:
char *__fastcall ppp_lcp_option(unsigned int a1)
{
char *result; // rax

if ( a1 > 8 || (result = (char *)ppp_lcp_options[a1]) == 0LL )
{
snprintf(n_2, 0x10uLL, "%d", a1);
result = n_2;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func9(unsigned int a1)
{
char *result; // rax

if ( a1 > 8 || (result = (char *)ppp_lcp_options[a1]) == 0LL )
{
snprintf(n_2, 0x10uLL, "%d", a1);
result = n_2;
}
return result;
}

original_code: char const *ppp_lcp_option(int index) { static char n[16]; if (index >= 0 && index < sizeof(ppp_lcp_options) / sizeof(ppp_lcp_options[0]) && ppp_lcp_options[index]) return ppp_lcp_options[index]; snprintf(n, sizeof(n), "%d", index); return n; }

canonical_original_code: char *ppp_lcp_option(int index) { static char n[16]; if (index >= 0 && index < sizeof(ppp_lcp_options) / sizeof(ppp_lcp_options[0]) && ppp_lcp_options[index]) return ppp_lcp_options[index]; snprintf(n, sizeof(n), "%d", index); return n; }


decompiled_code:
char *__fastcall radius_state(unsigned int a1)
{
char *result; // rax

if ( a1 > 7 || (result = radius_states[a1]) == 0LL )
{
snprintf(n_1, 0x10uLL, "%d", a1);
result = n_1;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func10(unsigned int a1)
{
char *result; // rax

if ( a1 > 7 || (result = radius_states[a1]) == 0LL )
{
snprintf(n_1, 0x10uLL, "%d", a1);
result = n_1;
}
return result;
}

original_code: char const *radius_state(int index) { static char n[16]; if (index >= 0 && index < sizeof(radius_states) / sizeof(radius_states[0]) && radius_states[index]) return radius_states[index]; snprintf(n, sizeof(n), "%d", index); return n; }

canonical_original_code: char *radius_state(int index) { static char n[16]; if (index >= 0 && index < sizeof(radius_states) / sizeof(radius_states[0]) && radius_states[index]) return radius_states[index]; snprintf(n, sizeof(n), "%d", index); return n; }


decompiled_code:
char *__fastcall radius_code(unsigned int a1)
{
char *result; // rax

if ( a1 > 0x2D || (result = (char *)radius_codes[a1]) == 0LL )
{
snprintf(n_0, 0x10uLL, "%d", a1);
result = n_0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func11(unsigned int a1)
{
char *result; // rax

if ( a1 > 0x2D || (result = (char *)radius_codes[a1]) == 0LL )
{
snprintf(n_0, 0x10uLL, "%d", a1);
result = n_0;
}
return result;
}

original_code: char const *radius_code(int index) { static char n[16]; if (index >= 0 && index < sizeof(radius_codes) / sizeof(radius_codes[0]) && radius_codes[index]) return radius_codes[index]; snprintf(n, sizeof(n), "%d", index); return n; }

canonical_original_code: char *radius_code(int index) { static char n[16]; if (index >= 0 && index < sizeof(radius_codes) / sizeof(radius_codes[0]) && radius_codes[index]) return radius_codes[index]; snprintf(n, sizeof(n), "%d", index); return n; }


decompiled_code:
void *ll_init()
{
return calloc(0x18uLL, 1uLL);
}

canonical_decompiled_code:
void *func0()
{
return calloc(0x18uLL, 1uLL);
}

original_code:
linked_list *ll_init()
{
 return (linked_list *)calloc(sizeof(linked_list), 1);
}

canonical_original_code:
struct s_ll *ll_init()
{
 return (struct s_ll *)calloc(sizeof(linked_list), 1);
}

return_type: struct s_ll { struct s_li { void *data; struct s_li *next; } *head; struct s_li *end; struct s_li *current; } *

user_defined_types: struct s_ll { struct s_li *head; struct s_li *end; struct s_li *current; }


decompiled_code:
void __fastcall ll_done(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void ll_done(linked_list *l)
{
 li *i = l->head, *n;
 while (i)
 {
  n = i->next;
  free(i);
  i = n;
 }
 free(l);
}

canonical_original_code:
void ll_done(struct s_ll *l)
{
 struct s_li *i = l->head; struct s_li *n;
 while (i)
 {
  n = i->next;
  free(i);
  i = n;
 }
 free(l);
}

variable_types: struct s_ll { struct s_li { void *data; struct s_li *next; } *head; struct s_li *end; struct s_li *current; } *


original_code:
void *ll_pop(linked_list *l)
{
 li *i;
 void *data;
 if (!l) return ((void *)0);
 if (!l->head)
  return ((void *)0);
 data = l->head->data;
 i = l->head->next;
 free(l->head);
 l->head = i;
 return data;
}

canonical_original_code:
void *ll_pop(struct s_ll *l)
{
 struct s_li *i;
 void *data;
 if (!l) return ((void *)0);
 if (!l->head)
  return ((void *)0);
 data = l->head->data;
 i = l->head->next;
 free(l->head);
 l->head = i;
 return data;
}

variable_types: struct s_li { void *data; struct s_li *next; } *

variable_types:
data
void *

return_type: void *


decompiled_code:
void __fastcall ll_iterate(_QWORD **a1, unsigned int (*a2)(void))
{
_QWORD *i; // rbx

if ( a1 )
{
if ( a2 )
{
for ( i = *a1; i; i = (_QWORD *)i[1] )
{
if ( *i && !a2() )
break;
}
}
}
}

canonical_decompiled_code:
void __fastcall func3(_QWORD **a1, unsigned int (*a2)(void))
{
_QWORD *i; // rbx

if ( a1 )
{
if ( a2 )
{
for ( i = *a1; i; i = (_QWORD *)i[1] )
{
if ( *i && !a2() )
break;
}
}
}
}

original_code:
void ll_iterate(linked_list *l, int(*func)(void *))
{
 li *i;
 if (!l || !func) return;
 for (i = l->head; i; i = i->next)
 {
  if (i->data && !func(i->data))
   break;
 }
}

canonical_original_code:
void ll_iterate(struct s_ll *l, int (*func)(void *))
{
 struct s_li *i;
 if (!l || !func) return;
 for (i = l->head; i; i = i->next)
 {
  if (i->data && !func(i->data))
   break;
 }
}

variable_types:
func
int (*)(void *)

user_defined_types: struct s_li { void *data; struct s_li *next; }


decompiled_code:
void __fastcall ll_reset(__int64 a1)
{
if ( a1 )
*(_QWORD *)(a1 + 16) = 0LL;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
if ( a1 )
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code:
void ll_reset(linked_list *l)
{
 if (!l) return;
 l->current = ((void *)0);
}

canonical_original_code:
void ll_reset(struct s_ll *l)
{
 if (!l) return;
 l->current = ((void *)0);
}


decompiled_code:
__int64 __fastcall ll_size(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int v2; // edx

if ( !a1 )
return 0;
v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
v2 -= (*v1 == 0LL) - 1;
v1 = (_QWORD *)v1[1];
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int v2; // edx

if ( !a1 )
return 0;
v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
v2 -= (*v1 == 0LL) - 1;
v1 = (_QWORD *)v1[1];
}
while ( v1 );
return v2;
}

original_code:
int ll_size(linked_list *l)
{
 int count = 0;
 li *i;
 if (!l) return 0;
 for (i = l->head; i; i = i->next)
  if (i->data) count++;
 return count;
}

canonical_original_code:
int ll_size(struct s_ll *l)
{
 int count = 0;
 struct s_li *i;
 if (!l) return 0;
 for (i = l->head; i; i = i->next)
  if (i->data) count++;
 return count;
}

variable_types: count int


repo: bodokaiser/libuv-snippets

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

result = counter + 1;
counter = result;
if ( (double)(int)result >= 10000000.0 )
result = uv_idle_stop();
return result;
}

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

result = counter + 1;
counter = result;
if ( (double)(int)result >= 10000000.0 )
result = uv_idle_stop();
return result;
}

original_code:
void wait_for_a_while(uv_idle_t* handle, int status) {
    counter++;
    if (counter >= 10e6)
        uv_idle_stop(handle);
}

canonical_original_code:
void wait_for_a_while(struct uv_idle_s *handle, int status) {
    counter++;
    if (counter >= 10e6)
        uv_idle_stop(handle);
}

variable_types: struct uv_idle_s { void *data; struct uv_loop_s { void *data; unsigned int active_handles; void *handle_queue[2]; union { void *unused[2]; unsigned int count; } active_reqs; unsigned int stop_flag; unsigned long flags; int backend_fd; void *pending_queue[2]; void *watcher_queue[2]; struct uv__io_s { void (*cb)(struct uv_loop_s *loop, struct uv__io_s *w, unsigned int events); void *pending_queue[2]; void *watcher_queue[2]; unsigned int pevents; unsigned int events; int fd; } **watchers; unsigned int nwatchers; unsigned int nfds; void *wq[2]; 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; } wq_mutex; struct uv_async_s { void *data; struct uv_loop_s *loop; enum uv_handle_type { UV_UNKNOWN_HANDLE=0, UV_ASYNC=1, UV_CHECK=2, UV_FS_EVENT=3, UV_FS_POLL=4, UV_HANDLE=5, UV_IDLE=6, UV_NAMED_PIPE=7, UV_POLL=8, UV_PREPARE=9, UV_PROCESS=10, UV_STREAM=11, UV_TCP=12, UV_TIMER=13, UV_TTY=14, UV_UDP=15, UV_SIGNAL=16, UV_FILE=17, UV_HANDLE_TYPE_MAX=18 } type; void (*close_cb)(struct uv_handle_s { void *data; struct uv_loop_s *loop; enum uv_handle_type { UV_UNKNOWN_HANDLE=0, UV_ASYNC=1, UV_CHECK=2, UV_FS_EVENT=3, UV_FS_POLL=4, UV_HANDLE=5, UV_IDLE=6, UV_NAMED_PIPE=7, UV_POLL=8, UV_PREPARE=9, UV_PROCESS=10, UV_STREAM=11, UV_TCP=12, UV_TIMER=13, UV_TTY=14, UV_UDP=15, UV_SIGNAL=16, UV_FILE=17, UV_HANDLE_TYPE_MAX=18 } type; void (*close_cb)(struct uv_handle_s *handle); void *handle_queue[2]; union { int fd; void *reserved[4]; } u; struct uv_handle_s *next_closing; unsigned int flags; } *handle); void *handle_queue[2]; union { int fd; void *reserved[4]; } u; struct uv_handle_s *next_closing; unsigned int flags; void (*async_cb)(struct uv_async_s *handle); void *queue[2]; int pending; } wq_async; union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } cloexec_lock; struct uv_handle_s *closing_handles; void *process_handles[2]; void *prepare_handles[2]; void *check_handles[2]; void *idle_handles[2]; void *async_handles[2]; void (*async_unused)(); struct uv__io_s async_io_watcher; int async_wfd; struct { void *min; unsigned int nelts; } timer_heap; unsigned long timer_counter; unsigned long time; int signal_pipefd[2]; struct uv__io_s signal_io_watcher; struct uv_signal_s { void *data; struct uv_loop_s *loop; enum uv_handle_type { UV_UNKNOWN_HANDLE=0, UV_ASYNC=1, UV_CHECK=2, UV_FS_EVENT=3, UV_FS_POLL=4, UV_HANDLE=5, UV_IDLE=6, UV_NAMED_PIPE=7, UV_POLL=8, UV_PREPARE=9, UV_PROCESS=10, UV_STREAM=11, UV_TCP=12, UV_TIMER=13, UV_TTY=14, UV_UDP=15, UV_SIGNAL=16, UV_FILE=17, UV_HANDLE_TYPE_MAX=18 } type; void (*close_cb)(struct uv_handle_s *handle); void *handle_queue[2]; union { int fd; void *reserved[4]; } u; struct uv_handle_s *next_closing; unsigned int flags; void (*signal_cb)(struct uv_signal_s *handle, int signum); int signum; struct { struct uv_signal_s *rbe_left; struct uv_signal_s *rbe_right; struct uv_signal_s *rbe_parent; int rbe_color; } tree_entry; unsigned int caught_signals; unsigned int dispatched_signals; } child_watcher; int emfile_fd; struct uv__io_s inotify_read_watcher; void *inotify_watchers; int inotify_fd; } *loop; enum uv_handle_type { UV_UNKNOWN_HANDLE=0, UV_ASYNC=1, UV_CHECK=2, UV_FS_EVENT=3, UV_FS_POLL=4, UV_HANDLE=5, UV_IDLE=6, UV_NAMED_PIPE=7, UV_POLL=8, UV_PREPARE=9, UV_PROCESS=10, UV_STREAM=11, UV_TCP=12, UV_TIMER=13, UV_TTY=14, UV_UDP=15, UV_SIGNAL=16, UV_FILE=17, UV_HANDLE_TYPE_MAX=18 } type; void (*close_cb)(struct uv_handle_s *handle); void *handle_queue[2]; union { int fd; void *reserved[4]; } u; struct uv_handle_s *next_closing; unsigned int flags; void (*idle_cb)(struct uv_idle_s *handle); void *queue[2]; } *

user_defined_types: struct uv_idle_s { void *data; struct uv_loop_s *loop; enum uv_handle_type type; void (*close_cb)(struct uv_handle_s *handle); void *handle_queue[2]; union { int fd; void *reserved[4]; } u; struct uv_handle_s *next_closing; unsigned int flags; void (*idle_cb)(struct uv_idle_s *handle); void *queue[2]; }

user_defined_types: struct uv_loop_s { void *data; unsigned int active_handles; void *handle_queue[2]; union { void *unused[2]; unsigned int count; } active_reqs; unsigned int stop_flag; unsigned long flags; int backend_fd; void *pending_queue[2]; void *watcher_queue[2]; struct uv__io_s **watchers; unsigned int nwatchers; unsigned int nfds; void *wq[2]; union pthread_mutex_t wq_mutex; struct uv_async_s wq_async; union pthread_rwlock_t cloexec_lock; struct uv_handle_s *closing_handles; void *process_handles[2]; void *prepare_handles[2]; void *check_handles[2]; void *idle_handles[2]; void *async_handles[2]; void (*async_unused)(); struct uv__io_s async_io_watcher; int async_wfd; struct { void *min; unsigned int nelts; } timer_heap; unsigned long timer_counter; unsigned long time; int signal_pipefd[2]; struct uv__io_s signal_io_watcher; struct uv_signal_s child_watcher; int emfile_fd; struct uv__io_s inotify_read_watcher; void *inotify_watchers; int inotify_fd; }

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

user_defined_types: struct uv_async_s { void *data; struct uv_loop_s *loop; enum uv_handle_type type; void (*close_cb)(struct uv_handle_s *handle); void *handle_queue[2]; union { int fd; void *reserved[4]; } u; struct uv_handle_s *next_closing; unsigned int flags; void (*async_cb)(struct uv_async_s *handle); void *queue[2]; int pending; }

user_defined_types: union pthread_rwlock_t { struct __pthread_rwlock_arch_t __data; char __size[56]; long __align; }

user_defined_types: struct uv_signal_s { void *data; struct uv_loop_s *loop; enum uv_handle_type type; void (*close_cb)(struct uv_handle_s *handle); void *handle_queue[2]; union { int fd; void *reserved[4]; } u; struct uv_handle_s *next_closing; unsigned int flags; void (*signal_cb)(struct uv_signal_s *handle, int signum); int signum; struct { struct uv_signal_s *rbe_left; struct uv_signal_s *rbe_right; struct uv_signal_s *rbe_parent; int rbe_color; } tree_entry; unsigned int caught_signals; unsigned int dispatched_signals; }

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

user_defined_types: struct uv_handle_s { void *data; struct uv_loop_s *loop; enum uv_handle_type type; void (*close_cb)(struct uv_handle_s *handle); void *handle_queue[2]; union { int fd; void *reserved[4]; } u; struct uv_handle_s *next_closing; unsigned int flags; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
uv_default_loop();
uv_idle_init();
uv_idle_start();
puts("Idling ...");
uv_run();
return 0;
}

original_code:
int main() {
    uv_loop_t *loop;
    uv_idle_t idler;
    loop = uv_default_loop();
    uv_idle_init(loop, &idler);
    uv_idle_start(&idler, wait_for_a_while);
    printf("Idling ...\n");
    uv_run(loop, UV_RUN_DEFAULT);
}

canonical_original_code:
int main() {
    struct uv_loop_s *loop;
    struct uv_idle_s idler;
    loop = uv_default_loop();
    uv_idle_init(loop, &idler);
    uv_idle_start(&idler, wait_for_a_while);
    printf("Idling ...\n");
    uv_run(loop, UV_RUN_DEFAULT);
}

variable_types: struct uv_idle_s { void *data; struct uv_loop_s { void *data; unsigned int active_handles; void *handle_queue[2]; union { void *unused[2]; unsigned int count; } active_reqs; unsigned int stop_flag; unsigned long flags; int backend_fd; void *pending_queue[2]; void *watcher_queue[2]; struct uv__io_s { void (*cb)(struct uv_loop_s *loop, struct uv__io_s *w, unsigned int events); void *pending_queue[2]; void *watcher_queue[2]; unsigned int pevents; unsigned int events; int fd; } **watchers; unsigned int nwatchers; unsigned int nfds; void *wq[2]; 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; } wq_mutex; struct uv_async_s { void *data; struct uv_loop_s *loop; enum uv_handle_type { UV_UNKNOWN_HANDLE=0, UV_ASYNC=1, UV_CHECK=2, UV_FS_EVENT=3, UV_FS_POLL=4, UV_HANDLE=5, UV_IDLE=6, UV_NAMED_PIPE=7, UV_POLL=8, UV_PREPARE=9, UV_PROCESS=10, UV_STREAM=11, UV_TCP=12, UV_TIMER=13, UV_TTY=14, UV_UDP=15, UV_SIGNAL=16, UV_FILE=17, UV_HANDLE_TYPE_MAX=18 } type; void (*close_cb)(struct uv_handle_s { void *data; struct uv_loop_s *loop; enum uv_handle_type { UV_UNKNOWN_HANDLE=0, UV_ASYNC=1, UV_CHECK=2, UV_FS_EVENT=3, UV_FS_POLL=4, UV_HANDLE=5, UV_IDLE=6, UV_NAMED_PIPE=7, UV_POLL=8, UV_PREPARE=9, UV_PROCESS=10, UV_STREAM=11, UV_TCP=12, UV_TIMER=13, UV_TTY=14, UV_UDP=15, UV_SIGNAL=16, UV_FILE=17, UV_HANDLE_TYPE_MAX=18 } type; void (*close_cb)(struct uv_handle_s *handle); void *handle_queue[2]; union { int fd; void *reserved[4]; } u; struct uv_handle_s *next_closing; unsigned int flags; } *handle); void *handle_queue[2]; union { int fd; void *reserved[4]; } u; struct uv_handle_s *next_closing; unsigned int flags; void (*async_cb)(struct uv_async_s *handle); void *queue[2]; int pending; } wq_async; union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } cloexec_lock; struct uv_handle_s *closing_handles; void *process_handles[2]; void *prepare_handles[2]; void *check_handles[2]; void *idle_handles[2]; void *async_handles[2]; void (*async_unused)(); struct uv__io_s async_io_watcher; int async_wfd; struct { void *min; unsigned int nelts; } timer_heap; unsigned long timer_counter; unsigned long time; int signal_pipefd[2]; struct uv__io_s signal_io_watcher; struct uv_signal_s { void *data; struct uv_loop_s *loop; enum uv_handle_type { UV_UNKNOWN_HANDLE=0, UV_ASYNC=1, UV_CHECK=2, UV_FS_EVENT=3, UV_FS_POLL=4, UV_HANDLE=5, UV_IDLE=6, UV_NAMED_PIPE=7, UV_POLL=8, UV_PREPARE=9, UV_PROCESS=10, UV_STREAM=11, UV_TCP=12, UV_TIMER=13, UV_TTY=14, UV_UDP=15, UV_SIGNAL=16, UV_FILE=17, UV_HANDLE_TYPE_MAX=18 } type; void (*close_cb)(struct uv_handle_s *handle); void *handle_queue[2]; union { int fd; void *reserved[4]; } u; struct uv_handle_s *next_closing; unsigned int flags; void (*signal_cb)(struct uv_signal_s *handle, int signum); int signum; struct { struct uv_signal_s *rbe_left; struct uv_signal_s *rbe_right; struct uv_signal_s *rbe_parent; int rbe_color; } tree_entry; unsigned int caught_signals; unsigned int dispatched_signals; } child_watcher; int emfile_fd; struct uv__io_s inotify_read_watcher; void *inotify_watchers; int inotify_fd; } *loop; enum uv_handle_type { UV_UNKNOWN_HANDLE=0, UV_ASYNC=1, UV_CHECK=2, UV_FS_EVENT=3, UV_FS_POLL=4, UV_HANDLE=5, UV_IDLE=6, UV_NAMED_PIPE=7, UV_POLL=8, UV_PREPARE=9, UV_PROCESS=10, UV_STREAM=11, UV_TCP=12, UV_TIMER=13, UV_TTY=14, UV_UDP=15, UV_SIGNAL=16, UV_FILE=17, UV_HANDLE_TYPE_MAX=18 } type; void (*close_cb)(struct uv_handle_s *handle); void *handle_queue[2]; union { int fd; void *reserved[4]; } u; struct uv_handle_s *next_closing; unsigned int flags; void (*idle_cb)(struct uv_idle_s *handle); void *queue[2]; }


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

result = socket(2, 2, 0);
if ( result < 0 )
{
perror("socket");
result = -1;
}
return result;
}

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

result = socket(2, 2, 0);
if ( result < 0 )
{
perror("socket");
result = -1;
}
return result;
}

original_code:
int new_localSocket(void)
{
    int socket_local;
    socket_local = socket(2, SOCK_DGRAM, 0);
    if(socket_local < 0)
    {
 perror("socket");
 return -1;
    }
    return socket_local;
}

canonical_original_code:
int new_localSocket()
{
    int socket_local;
    socket_local = socket(2, SOCK_DGRAM, 0);
    if(socket_local < 0)
    {
 perror("socket");
 return -1;
    }
    return socket_local;
}


decompiled_code:
char *__fastcall new_destAddr(char *name, __int16 a2)
{
struct hostent *v2; // r12
char *v3; // rbx
struct in_addr inp; // [rsp+Ch] [rbp-1Ch] BYREF

if ( inet_aton(name, &inp) )
v2 = gethostbyaddr(&inp, 4u, 2);
else
v2 = gethostbyname(name);
if ( !v2 )
{
printf("Endereco de rede invalido");
exit(1);
}
v3 = (char *)malloc(0x10uLL);
*(_QWORD *)v3 = 0LL;
*((_QWORD *)v3 + 1) = 0LL;
*(__m128i *)(v3 + 4) = _mm_loadu_si128((const __m128i *)*v2->h_addr_list);
*(_WORD *)v3 = 2;
*((_WORD *)v3 + 1) = _bswap_16(a2);
return v3;
}

canonical_decompiled_code:
char *__fastcall func2(char *name, __int16 a2)
{
struct hostent *v2; // r12
char *v3; // rbx
struct in_addr inp; // [rsp+Ch] [rbp-1Ch] BYREF

if ( inet_aton(name, &inp) )
v2 = gethostbyaddr(&inp, 4u, 2);
else
v2 = gethostbyname(name);
if ( !v2 )
{
printf("Endereco de rede invalido");
exit(1);
}
v3 = (char *)malloc(0x10uLL);
*(_QWORD *)v3 = 0LL;
*((_QWORD *)v3 + 1) = 0LL;
*(__m128i *)(v3 + 4) = _mm_loadu_si128((const __m128i *)*v2->h_addr_list);
*(_WORD *)v3 = 2;
*((_WORD *)v3 + 1) = func0(a2);
return v3;
}

original_code:
Sockaddr_in* new_destAddr(char* dest, int destPort)
{
    Sockaddr_in *sockaddr_serv;
    Hostent *addr_dest;
    In_addr ip_dest;
    if (inet_aton(dest, &ip_dest))
 addr_dest = gethostbyaddr((char* )&ip_dest, sizeof(ip_dest), 2);
    else
 addr_dest = gethostbyname(dest);
    if(addr_dest == ((void *)0))
    {
 printf("Endereco de rede invalido");
 exit(1);
    }
    sockaddr_serv = (Sockaddr_in*)malloc(sizeof(Sockaddr_in));
    memset((char *)sockaddr_serv, 0, sizeof(*sockaddr_serv));
    memcpy(&sockaddr_serv->sin_addr, addr_dest->h_addr_list[0], sizeof(*sockaddr_serv));
    sockaddr_serv->sin_family = 2;
    sockaddr_serv->sin_port = htons(destPort);
    return sockaddr_serv;
}

canonical_original_code:
struct sockaddr_in *new_destAddr(char *dest, int destPort)
{
    struct sockaddr_in *sockaddr_serv;
    struct hostent *addr_dest;
    struct in_addr ip_dest;
    if (inet_aton(dest, &ip_dest))
 addr_dest = gethostbyaddr((char * )&ip_dest, sizeof(ip_dest), 2);
    else
 addr_dest = gethostbyname(dest);
    if(addr_dest == ((void *)0))
    {
 printf("Endereco de rede invalido");
 exit(1);
    }
    sockaddr_serv = (struct sockaddr_in *)malloc(sizeof(Sockaddr_in));
    memset((char *)sockaddr_serv, 0, sizeof(*sockaddr_serv));
    memcpy(&sockaddr_serv->sin_addr, addr_dest->h_addr_list[0], sizeof(*sockaddr_serv));
    sockaddr_serv->sin_family = 2;
    sockaddr_serv->sin_port = htons(destPort);
    return sockaddr_serv;
}

variable_types:
dest
char *

variable_types: destPort int

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

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

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


decompiled_code:
__int64 __fastcall send_msg(__int64 a1, const char *a2)
{
size_t v2; // rax
ssize_t v3; // rdx
__int64 result; // rax

v2 = strlen(a2);
v3 = sendto(*(_DWORD *)a1, a2, v2 + 1, 0, *(const struct sockaddr **)(a1 + 8), 0x10u);
result = 1LL;
if ( v3 < 0 )
{
perror("sendto");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
size_t v2; // rax
ssize_t v3; // rdx
__int64 result; // rax

v2 = strlen(a2);
v3 = sendto(*(_DWORD *)a1, a2, v2 + 1, 0, *(const struct sockaddr **)(a1 + 8), 0x10u);
result = 1LL;
if ( v3 < 0 )
{
perror("sendto");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int send_msg(UdpCom* udpcom, char *msg)
{
    if (sendto(udpcom->localSocket, msg, strlen(msg)+1, 0, (Sockaddr *)udpcom->destAddr, sizeof(*udpcom->destAddr)) < 0)
    {
 perror("sendto");
 return -1;
    }
    return 1;
}

canonical_original_code:
int send_msg(struct udpCom *udpcom, char *msg)
{
    if (sendto(udpcom->localSocket, msg, strlen(msg)+1, 0, (struct sockaddr *)udpcom->destAddr, sizeof(*udpcom->destAddr)) < 0)
    {
 perror("sendto");
 return -1;
    }
    return 1;
}

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

variable_types:
msg
char *

user_defined_types: struct udpCom { int localSocket; struct sockaddr_in *destAddr; }

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


decompiled_code:
__int64 __fastcall recv_msg(int *a1, void *a2, int a3)
{
int v3; // ebx

v3 = recvfrom(*a1, a2, a3, 0, 0LL, 0LL);
if ( v3 < 0 )
perror("recvfrom");
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, void *a2, int a3)
{
int v3; // ebx

v3 = recvfrom(*a1, a2, a3, 0, 0LL, 0LL);
if ( v3 < 0 )
perror("recvfrom");
return (unsigned int)v3;
}

original_code:
int recv_msg(UdpCom* udpcom, char *buffer, int bufferSize)
{
    int bytes_recv;
    bytes_recv = recvfrom(udpcom->localSocket, buffer, bufferSize, 0, ((void *)0), 0);
    if (bytes_recv < 0)
    {
 perror("recvfrom");
    }
    return bytes_recv;
}

canonical_original_code:
int recv_msg(struct udpCom *udpcom, char *buffer, int bufferSize)
{
    int bytes_recv;
    bytes_recv = recvfrom(udpcom->localSocket, buffer, bufferSize, 0, ((void *)0), 0);
    if (bytes_recv < 0)
    {
 perror("recvfrom");
    }
    return bytes_recv;
}

variable_types:
buffer
char *

variable_types: bufferSize int


decompiled_code:
void __fastcall delete_udpCom(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void delete_udpCom(UdpCom* udpcom)
{
    free(udpcom->destAddr);
    free(udpcom);
}

canonical_original_code:
void delete_udpCom(struct udpCom *udpcom)
{
    free(udpcom->destAddr);
    free(udpcom);
}


decompiled_code:
int __fastcall init_monitor(__int64 a1, __int64 a2, _DWORD *a3)
{
*(_QWORD *)(a2 + 56) = 0LL;
*(_QWORD *)(a2 + 64) = 0LL;
*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 24) = 0LL;
*(_QWORD *)(a2 + 32) = 0LL;
*(_QWORD *)(a2 + 40) = 0LL;
*(_QWORD *)(a2 + 48) = 0LL;
*(_BYTE *)(a2 + 73) = 110;
*(_BYTE *)(a2 + 72) = 0;
a3[40] = 0;
a3[41] = 0;
a3[42] = 0;
pthread_mutex_init((pthread_mutex_t *)a1, 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 40), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 80), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 120), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 160), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 200), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 240), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 280), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 320), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 360), 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 400), 0LL);
return pthread_cond_init((pthread_cond_t *)(a1 + 448), 0LL);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, _DWORD *a3)
{
*(_QWORD *)(a2 + 56) = 0LL;
*(_QWORD *)(a2 + 64) = 0LL;
*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 24) = 0LL;
*(_QWORD *)(a2 + 32) = 0LL;
*(_QWORD *)(a2 + 40) = 0LL;
*(_QWORD *)(a2 + 48) = 0LL;
*(_BYTE *)(a2 + 73) = 110;
*(_BYTE *)(a2 + 72) = 0;
a3[40] = 0;
a3[41] = 0;
a3[42] = 0;
pthread_mutex_init((pthread_mutex_t *)a1, 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 40), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 80), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 120), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 160), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 200), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 240), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 280), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 320), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 360), 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 400), 0LL);
return pthread_cond_init((pthread_cond_t *)(a1 + 448), 0LL);
}

original_code:
void init_monitor(PthreadAcess* pth, SharedVars* vars, BufferControl* buffer)
{
    vars->H = 0;
    vars->Href = 0;
    vars->Ni = 0;
    vars->No = 0;
    vars->Q = 0;
    vars->T = 0;
    vars->Tref = 0;
    vars->Ta = 0;
    vars->Ti = 0;
    vars->stop_threads = 'n';
    vars->screen = 0;
    buffer->bufferRec = 0;
    buffer->bufferRead = 0;
    buffer->ndata = 0;
    pthread_mutex_init(&pth->mQ, ((void *)0));
    pthread_mutex_init(&pth->mNi, ((void *)0));
    pthread_mutex_init(&pth->mT, ((void *)0));
    pthread_mutex_init(&pth->mTref, ((void *)0));
    pthread_mutex_init(&pth->mPert, ((void *)0));
    pthread_mutex_init(&pth->mH, ((void *)0));
    pthread_mutex_init(&pth->mHref, ((void *)0));
    pthread_mutex_init(&pth->mstop_threads, ((void *)0));
    pthread_mutex_init(&pth->mscreen, ((void *)0));
    pthread_mutex_init(&pth->mbuffer, ((void *)0));
    pthread_cond_init(&pth->writeBuffer, ((void *)0));
    pthread_cond_init(&pth->levAlarm, ((void *)0));
}

canonical_original_code:
void init_monitor(struct pthreadAcess *pth, struct sharedVars *vars, struct bufferControl *buffer)
{
    vars->H = 0;
    vars->Href = 0;
    vars->Ni = 0;
    vars->No = 0;
    vars->Q = 0;
    vars->T = 0;
    vars->Tref = 0;
    vars->Ta = 0;
    vars->Ti = 0;
    vars->stop_threads = 'n';
    vars->screen = 0;
    buffer->bufferRec = 0;
    buffer->bufferRead = 0;
    buffer->ndata = 0;
    pthread_mutex_init(&pth->mQ, ((void *)0));
    pthread_mutex_init(&pth->mNi, ((void *)0));
    pthread_mutex_init(&pth->mT, ((void *)0));
    pthread_mutex_init(&pth->mTref, ((void *)0));
    pthread_mutex_init(&pth->mPert, ((void *)0));
    pthread_mutex_init(&pth->mH, ((void *)0));
    pthread_mutex_init(&pth->mHref, ((void *)0));
    pthread_mutex_init(&pth->mstop_threads, ((void *)0));
    pthread_mutex_init(&pth->mscreen, ((void *)0));
    pthread_mutex_init(&pth->mbuffer, ((void *)0));
    pthread_cond_init(&pth->writeBuffer, ((void *)0));
    pthread_cond_init(&pth->levAlarm, ((void *)0));
}

variable_types: struct pthreadAcess { 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; } mQ; union pthread_mutex_t mNi; union pthread_mutex_t mT; union pthread_mutex_t mTref; union pthread_mutex_t mPert; union pthread_mutex_t mH; union pthread_mutex_t mHref; union pthread_mutex_t mstop_threads; union pthread_mutex_t mscreen; union pthread_mutex_t mbuffer; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } writeBuffer; union pthread_cond_t levAlarm; union pthread_mutex_t mexc; union pthread_cond_t ok2writers; union pthread_cond_t ok2readers; short rcount; short pendingw; char busy; } *

variable_types: struct sharedVars { double Ni; double No; double Q; double T; double Tref; double Ta; double Ti; double H; double Href; char screen; char stop_threads; } *

variable_types: struct bufferControl { struct sharedVars array[2]; int bufferRec; int bufferRead; int ndata; } *

user_defined_types: struct pthreadAcess { union pthread_mutex_t mQ; union pthread_mutex_t mNi; union pthread_mutex_t mT; union pthread_mutex_t mTref; union pthread_mutex_t mPert; union pthread_mutex_t mH; union pthread_mutex_t mHref; union pthread_mutex_t mstop_threads; union pthread_mutex_t mscreen; union pthread_mutex_t mbuffer; union pthread_cond_t writeBuffer; union pthread_cond_t levAlarm; union pthread_mutex_t mexc; union pthread_cond_t ok2writers; union pthread_cond_t ok2readers; short rcount; short pendingw; char busy; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }


readGen

decompiled_code:
int __fastcall readGen(_QWORD *a1, pthread_mutex_t *a2, _QWORD *a3)
{
pthread_mutex_lock(a2);
*a3 = *a1;
return pthread_mutex_unlock(a2);
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1, pthread_mutex_t *a2, _QWORD *a3)
{
pthread_mutex_lock(a2);
*a3 = *a1;
return pthread_mutex_unlock(a2);
}

original_code:
void readGen(double* sv, pthread_mutex_t* m, double* res)
{
    pthread_mutex_lock(m);
    *res = *sv;
    pthread_mutex_unlock(m);
}

canonical_original_code:
void readGen(double *sv, union pthread_mutex_t *m, double *res)
{
    pthread_mutex_lock(m);
    *res = *sv;
    pthread_mutex_unlock(m);
}

variable_types:
sv
double *

variable_types: 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; } *

variable_types:
res
double *


setGen

decompiled_code:
int __fastcall setGen(_QWORD *a1, pthread_mutex_t *a2, _QWORD *a3)
{
pthread_mutex_lock(a2);
*a1 = *a3;
return pthread_mutex_unlock(a2);
}

canonical_decompiled_code:
int __fastcall func2(_QWORD *a1, pthread_mutex_t *a2, _QWORD *a3)
{
pthread_mutex_lock(a2);
*a1 = *a3;
return pthread_mutex_unlock(a2);
}

original_code:
void setGen(double* sv, pthread_mutex_t* m, double* value)
{
    pthread_mutex_lock(m);
    *sv = *value;
    pthread_mutex_unlock(m);
}

canonical_original_code:
void setGen(double *sv, union pthread_mutex_t *m, double *value)
{
    pthread_mutex_lock(m);
    *sv = *value;
    pthread_mutex_unlock(m);
}

variable_types:
value
double *

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


readQ

decompiled_code:
int __fastcall readQ(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return readGen((_QWORD *)(a1 + 16), a2, a3);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return func1((_QWORD *)(a1 + 16), a2, a3);
}

original_code:
void readQ(SharedVars* v, PthreadAcess* p, double* res)
{
    readGen(&v->Q, &p->mQ, res);
}

canonical_original_code:
void readQ(struct sharedVars *v, struct pthreadAcess *p, double *res)
{
    readGen(&v->Q, &p->mQ, res);
}

user_defined_types: struct sharedVars { double Ni; double No; double Q; double T; double Tref; double Ta; double Ti; double H; double Href; char screen; char stop_threads; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }


setQ

decompiled_code:
int __fastcall setQ(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return setGen((_QWORD *)(a1 + 16), a2, v4);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return func2((_QWORD *)(a1 + 16), a2, v4);
}

original_code:
void setQ(SharedVars* v, PthreadAcess* p, double value)
{
    setGen(&v->Q, &p->mQ, &value);
}

canonical_original_code:
void setQ(struct sharedVars *v, struct pthreadAcess *p, double value)
{
    setGen(&v->Q, &p->mQ, &value);
}

variable_types: value double


readNi

decompiled_code:
int __fastcall readNi(_QWORD *a1, pthread_mutex_t *a2, _QWORD *a3)
{
return readGen(a1, a2 + 1, a3);
}

canonical_decompiled_code:
int __fastcall func5(_QWORD *a1, pthread_mutex_t *a2, _QWORD *a3)
{
return func1(a1, a2 + 1, a3);
}

original_code:
void readNi(SharedVars* v, PthreadAcess* p, double* res)
{
    readGen(&v->Ni, &p->mNi, res);
}

canonical_original_code:
void readNi(struct sharedVars *v, struct pthreadAcess *p, double *res)
{
    readGen(&v->Ni, &p->mNi, res);
}


setNi

decompiled_code:
int __fastcall setNi(double *a1, pthread_mutex_t *a2, double a3)
{
pthread_mutex_lock(a2 + 1);
*a1 = a3;
return pthread_mutex_unlock(a2 + 1);
}

canonical_decompiled_code:
int __fastcall func6(double *a1, pthread_mutex_t *a2, double a3)
{
pthread_mutex_lock(a2 + 1);
*a1 = a3;
return pthread_mutex_unlock(a2 + 1);
}

original_code:
void setNi(SharedVars* v, PthreadAcess* p, double value)
{
    pthread_mutex_lock(&p->mNi);
    v->Ni = value;
    pthread_mutex_unlock(&p->mNi);
}

canonical_original_code:
void setNi(struct sharedVars *v, struct pthreadAcess *p, double value)
{
    pthread_mutex_lock(&p->mNi);
    v->Ni = value;
    pthread_mutex_unlock(&p->mNi);
}


readNo

decompiled_code:
int __fastcall readNo(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return readGen((_QWORD *)(a1 + 8), a2 + 4, a3);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return func1((_QWORD *)(a1 + 8), a2 + 4, a3);
}

original_code:
void readNo(SharedVars* v, PthreadAcess* p, double* res)
{
    readGen(&v->No, &p->mPert, res);
}

canonical_original_code:
void readNo(struct sharedVars *v, struct pthreadAcess *p, double *res)
{
    readGen(&v->No, &p->mPert, res);
}


setNo

decompiled_code:
int __fastcall setNo(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return setGen((_QWORD *)(a1 + 8), a2 + 4, v4);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return func2((_QWORD *)(a1 + 8), a2 + 4, v4);
}

original_code:
void setNo(SharedVars* v, PthreadAcess* p, double value)
{
    setGen(&v->No, &p->mPert, &value);
}

canonical_original_code:
void setNo(struct sharedVars *v, struct pthreadAcess *p, double value)
{
    setGen(&v->No, &p->mPert, &value);
}


readT

decompiled_code:
int __fastcall readT(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return readGen((_QWORD *)(a1 + 24), a2 + 2, a3);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return func1((_QWORD *)(a1 + 24), a2 + 2, a3);
}

original_code:
void readT(SharedVars* v, PthreadAcess* p, double* res)
{
    readGen(&v->T, &p->mT, res);
}

canonical_original_code:
void readT(struct sharedVars *v, struct pthreadAcess *p, double *res)
{
    readGen(&v->T, &p->mT, res);
}


setT

decompiled_code:
int __fastcall setT(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return setGen((_QWORD *)(a1 + 24), a2 + 2, v4);
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return func2((_QWORD *)(a1 + 24), a2 + 2, v4);
}

original_code:
void setT(SharedVars* v, PthreadAcess* p, double value)
{
    setGen(&v->T, &p->mT, &value);
}

canonical_original_code:
void setT(struct sharedVars *v, struct pthreadAcess *p, double value)
{
    setGen(&v->T, &p->mT, &value);
}


readTref

decompiled_code:
int __fastcall readTref(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return readGen((_QWORD *)(a1 + 32), a2 + 3, a3);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return func1((_QWORD *)(a1 + 32), a2 + 3, a3);
}

original_code:
void readTref(SharedVars* v, PthreadAcess* p, double* res)
{
    readGen(&v->Tref, &p->mTref, res);
}

canonical_original_code:
void readTref(struct sharedVars *v, struct pthreadAcess *p, double *res)
{
    readGen(&v->Tref, &p->mTref, res);
}


setTref

decompiled_code:
int __fastcall setTref(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return setGen((_QWORD *)(a1 + 32), a2 + 3, v4);
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return func2((_QWORD *)(a1 + 32), a2 + 3, v4);
}

original_code:
void setTref(SharedVars* v, PthreadAcess* p, double value)
{
    setGen(&v->Tref, &p->mTref, &value);
}

canonical_original_code:
void setTref(struct sharedVars *v, struct pthreadAcess *p, double value)
{
    setGen(&v->Tref, &p->mTref, &value);
}


readTa

decompiled_code:
int __fastcall readTa(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return readGen((_QWORD *)(a1 + 40), a2 + 4, a3);
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return func1((_QWORD *)(a1 + 40), a2 + 4, a3);
}

original_code:
void readTa(SharedVars* v, PthreadAcess* p, double* res)
{
    readGen(&v->Ta, &p->mPert, res);
}

canonical_original_code:
void readTa(struct sharedVars *v, struct pthreadAcess *p, double *res)
{
    readGen(&v->Ta, &p->mPert, res);
}


setTa

decompiled_code:
int __fastcall setTa(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return setGen((_QWORD *)(a1 + 40), a2 + 4, v4);
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return func2((_QWORD *)(a1 + 40), a2 + 4, v4);
}

original_code:
void setTa(SharedVars* v, PthreadAcess* p, double value)
{
    setGen(&v->Ta, &p->mPert, &value);
}

canonical_original_code:
void setTa(struct sharedVars *v, struct pthreadAcess *p, double value)
{
    setGen(&v->Ta, &p->mPert, &value);
}


readTi

decompiled_code:
int __fastcall readTi(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return readGen((_QWORD *)(a1 + 48), a2 + 4, a3);
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return func1((_QWORD *)(a1 + 48), a2 + 4, a3);
}

original_code:
void readTi(SharedVars* v, PthreadAcess* p, double* res)
{
    readGen(&v->Ti, &p->mPert, res);
}

canonical_original_code:
void readTi(struct sharedVars *v, struct pthreadAcess *p, double *res)
{
    readGen(&v->Ti, &p->mPert, res);
}


setTi

decompiled_code:
int __fastcall setTi(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return setGen((_QWORD *)(a1 + 48), a2 + 4, v4);
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return func2((_QWORD *)(a1 + 48), a2 + 4, v4);
}

original_code:
void setTi(SharedVars* v, PthreadAcess* p, double value)
{
    setGen(&v->Ti, &p->mPert, &value);
}

canonical_original_code:
void setTi(struct sharedVars *v, struct pthreadAcess *p, double value)
{
    setGen(&v->Ti, &p->mPert, &value);
}


readH

decompiled_code:
int __fastcall readH(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return readGen((_QWORD *)(a1 + 56), a2 + 5, a3);
}

canonical_decompiled_code:
int __fastcall func17(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return func1((_QWORD *)(a1 + 56), a2 + 5, a3);
}

original_code:
void readH(SharedVars* v, PthreadAcess* p, double* res)
{
    readGen(&v->H, &p->mH, res);
}

canonical_original_code:
void readH(struct sharedVars *v, struct pthreadAcess *p, double *res)
{
    readGen(&v->H, &p->mH, res);
}


setH

decompiled_code:
int __fastcall setH(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return setGen((_QWORD *)(a1 + 56), a2 + 5, v4);
}

canonical_decompiled_code:
int __fastcall func18(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return func2((_QWORD *)(a1 + 56), a2 + 5, v4);
}

original_code:
void setH(SharedVars* v, PthreadAcess* p, double value)
{
    setGen(&v->H, &p->mH, &value);
}

canonical_original_code:
void setH(struct sharedVars *v, struct pthreadAcess *p, double value)
{
    setGen(&v->H, &p->mH, &value);
}


readHref

decompiled_code:
int __fastcall readHref(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return readGen((_QWORD *)(a1 + 64), a2 + 6, a3);
}

canonical_decompiled_code:
int __fastcall func19(__int64 a1, pthread_mutex_t *a2, _QWORD *a3)
{
return func1((_QWORD *)(a1 + 64), a2 + 6, a3);
}

original_code:
void readHref(SharedVars* v, PthreadAcess* p, double* res)
{
    readGen(&v->Href, &p->mHref, res);
}

canonical_original_code:
void readHref(struct sharedVars *v, struct pthreadAcess *p, double *res)
{
    readGen(&v->Href, &p->mHref, res);
}


setHref

decompiled_code:
int __fastcall setHref(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return setGen((_QWORD *)(a1 + 64), a2 + 6, v4);
}

canonical_decompiled_code:
int __fastcall func20(__int64 a1, pthread_mutex_t *a2, double a3)
{
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a3;
return func2((_QWORD *)(a1 + 64), a2 + 6, v4);
}

original_code:
void setHref(SharedVars* v, PthreadAcess* p, double value)
{
    setGen(&v->Href, &p->mHref, &value);
}

canonical_original_code:
void setHref(struct sharedVars *v, struct pthreadAcess *p, double value)
{
    setGen(&v->Href, &p->mHref, &value);
}


decompiled_code:
int __fastcall readstop_threads(__int64 a1, pthread_mutex_t *a2, _BYTE *a3)
{
pthread_mutex_lock(a2 + 7);
*a3 = *(_BYTE *)(a1 + 73);
return pthread_mutex_unlock(a2 + 7);
}

canonical_decompiled_code:
int __fastcall func21(__int64 a1, pthread_mutex_t *a2, _BYTE *a3)
{
pthread_mutex_lock(a2 + 7);
*a3 = *(_BYTE *)(a1 + 73);
return pthread_mutex_unlock(a2 + 7);
}

original_code:
void readstop_threads(SharedVars* v, PthreadAcess* p, char* res)
{
    pthread_mutex_lock(&p->mstop_threads);
    *res = v->stop_threads;
    pthread_mutex_unlock(&p->mstop_threads);
}

canonical_original_code:
void readstop_threads(struct sharedVars *v, struct pthreadAcess *p, char *res)
{
    pthread_mutex_lock(&p->mstop_threads);
    *res = v->stop_threads;
    pthread_mutex_unlock(&p->mstop_threads);
}

variable_types:
res
char *


decompiled_code:
int __fastcall setstop_threads(__int64 a1, pthread_mutex_t *a2, char a3)
{
pthread_mutex_lock(a2 + 7);
*(_BYTE *)(a1 + 73) = a3;
return pthread_mutex_unlock(a2 + 7);
}

canonical_decompiled_code:
int __fastcall func22(__int64 a1, pthread_mutex_t *a2, char a3)
{
pthread_mutex_lock(a2 + 7);
*(_BYTE *)(a1 + 73) = a3;
return pthread_mutex_unlock(a2 + 7);
}

original_code:
void setstop_threads(SharedVars* v, PthreadAcess* p, char value)
{
    pthread_mutex_lock(&p->mstop_threads);
    v->stop_threads = value;
    pthread_mutex_unlock(&p->mstop_threads);
}

canonical_original_code:
void setstop_threads(struct sharedVars *v, struct pthreadAcess *p, char value)
{
    pthread_mutex_lock(&p->mstop_threads);
    v->stop_threads = value;
    pthread_mutex_unlock(&p->mstop_threads);
}

variable_types: value char


readscreen

decompiled_code:
int __fastcall readscreen(__int64 a1, pthread_mutex_t *a2, _BYTE *a3)
{
pthread_mutex_lock(a2 + 8);
*a3 = *(_BYTE *)(a1 + 72);
return pthread_mutex_unlock(a2 + 8);
}

canonical_decompiled_code:
int __fastcall func23(__int64 a1, pthread_mutex_t *a2, _BYTE *a3)
{
pthread_mutex_lock(a2 + 8);
*a3 = *(_BYTE *)(a1 + 72);
return pthread_mutex_unlock(a2 + 8);
}

original_code:
void readscreen(SharedVars* v, PthreadAcess* p, char* res)
{
    pthread_mutex_lock(&p->mscreen);
    *res = v->screen;
    pthread_mutex_unlock(&p->mscreen);
}

canonical_original_code:
void readscreen(struct sharedVars *v, struct pthreadAcess *p, char *res)
{
    pthread_mutex_lock(&p->mscreen);
    *res = v->screen;
    pthread_mutex_unlock(&p->mscreen);
}


setscreen

decompiled_code:
int __fastcall setscreen(__int64 a1, pthread_mutex_t *a2, char a3)
{
pthread_mutex_lock(a2 + 8);
*(_BYTE *)(a1 + 72) = a3;
return pthread_mutex_unlock(a2 + 8);
}

canonical_decompiled_code:
int __fastcall func24(__int64 a1, pthread_mutex_t *a2, char a3)
{
pthread_mutex_lock(a2 + 8);
*(_BYTE *)(a1 + 72) = a3;
return pthread_mutex_unlock(a2 + 8);
}

original_code:
void setscreen(SharedVars* v, PthreadAcess* p, char value)
{
    pthread_mutex_lock(&p->mscreen);
    v->screen = value;
    pthread_mutex_unlock(&p->mscreen);
}

canonical_original_code:
void setscreen(struct sharedVars *v, struct pthreadAcess *p, char value)
{
    pthread_mutex_lock(&p->mscreen);
    v->screen = value;
    pthread_mutex_unlock(&p->mscreen);
}


writeBuffer

original_code:
void writeBuffer(SharedVars* vars, BufferControl* buffer, PthreadAcess* p)
{
    pthread_mutex_lock(&p->mbuffer);
    if (buffer->ndata != 2)
    {
 buffer->array[buffer->bufferRec] = *vars;
 buffer->bufferRec = (buffer->bufferRec + 1) % 2;
 buffer->ndata ++;
 pthread_cond_signal(&p->writeBuffer);
    }
    pthread_mutex_unlock(&p->mbuffer);
}

canonical_original_code:
void writeBuffer(struct sharedVars *vars, struct bufferControl *buffer, struct pthreadAcess *p)
{
    pthread_mutex_lock(&p->mbuffer);
    if (buffer->ndata != 2)
    {
 buffer->array[buffer->bufferRec] = *vars;
 buffer->bufferRec = (buffer->bufferRec + 1) % 2;
 buffer->ndata ++;
 pthread_cond_signal(&p->writeBuffer);
    }
    pthread_mutex_unlock(&p->mbuffer);
}

user_defined_types: struct bufferControl { struct sharedVars array[2]; int bufferRec; int bufferRead; int ndata; }


wakeupThreads

decompiled_code:
int __fastcall wakeupThreads(__int64 a1)
{
pthread_cond_signal((pthread_cond_t *)(a1 + 400));
return pthread_cond_signal((pthread_cond_t *)(a1 + 448));
}

canonical_decompiled_code:
int __fastcall func27(__int64 a1)
{
pthread_cond_signal((pthread_cond_t *)(a1 + 400));
return pthread_cond_signal((pthread_cond_t *)(a1 + 448));
}

original_code:
void wakeupThreads(PthreadAcess* p)
{
    pthread_cond_signal(&p->writeBuffer);
    pthread_cond_signal(&p->levAlarm);
}

canonical_original_code:
void wakeupThreads(struct pthreadAcess *p)
{
    pthread_cond_signal(&p->writeBuffer);
    pthread_cond_signal(&p->levAlarm);
}


wakeuplevAlarm

decompiled_code:
int __fastcall wakeuplevAlarm(__int64 a1)
{
return pthread_cond_signal((pthread_cond_t *)(a1 + 448));
}

canonical_decompiled_code:
int __fastcall func28(__int64 a1)
{
return pthread_cond_signal((pthread_cond_t *)(a1 + 448));
}

original_code:
void wakeuplevAlarm(PthreadAcess* p)
{
    pthread_cond_signal(&p->levAlarm);
}

canonical_original_code:
void wakeuplevAlarm(struct pthreadAcess *p)
{
    pthread_cond_signal(&p->levAlarm);
}


decompiled_code:
int __fastcall data4levAlarm(__int64 a1, __int64 a2, _QWORD *a3)
{
pthread_mutex_lock((pthread_mutex_t *)(a2 + 200));
pthread_cond_wait((pthread_cond_t *)(a2 + 448), (pthread_mutex_t *)(a2 + 200));
*a3 = *(_QWORD *)(a1 + 56);
return pthread_mutex_unlock((pthread_mutex_t *)(a2 + 200));
}

canonical_decompiled_code:
int __fastcall func29(__int64 a1, __int64 a2, _QWORD *a3)
{
pthread_mutex_lock((pthread_mutex_t *)(a2 + 200));
pthread_cond_wait((pthread_cond_t *)(a2 + 448), (pthread_mutex_t *)(a2 + 200));
*a3 = *(_QWORD *)(a1 + 56);
return pthread_mutex_unlock((pthread_mutex_t *)(a2 + 200));
}

original_code:
void data4levAlarm(SharedVars* v, PthreadAcess* p, double* aH)
{
    pthread_mutex_lock(&p->mH);
    pthread_cond_wait(&p->levAlarm, &p->mH);
    *aH = v->H;
    pthread_mutex_unlock(&p->mH);
}

canonical_original_code:
void data4levAlarm(struct sharedVars *v, struct pthreadAcess *p, double *aH)
{
    pthread_mutex_lock(&p->mH);
    pthread_cond_wait(&p->levAlarm, &p->mH);
    *aH = v->H;
    pthread_mutex_unlock(&p->mH);
}

variable_types:
aH
double *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc != 3 )
{
puts("\n\tSao necessarios dois argumentos para execucao: endereco do servidor e porta de comunicacao.\n");
exit(1);
}
start_tasks(argv[1], argv[2], envp);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
    if (argc != 3)
    {
 puts("\n\tSao necessarios dois argumentos para execucao: endereco do servidor e porta de comunicacao.\n");
 exit(1);
    }
    start_tasks(argv[1], argv[2]);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    if (argc != 3)
    {
 puts("\n\tSao necessarios dois argumentos para execucao: endereco do servidor e porta de comunicacao.\n");
 exit(1);
    }
    start_tasks(argv[1], argv[2]);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]