decompiled_code:
void exit_disks_access()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void exit_disks_access(){
}

canonical_original_code:
void exit_disks_access(){
}


repo: mondonc/myscreen

decompiled_code:
__int64 __fastcall exit_modules(int a1)
{
__int64 v1; // rbx
__int64 v2; // rdx
__int64 result; // rax

if ( a1 > 0 )
{
v1 = 0LL;
do
{
v2 = current_conf[v1++];
result = (*(&exit_mod + v2))();
}
while ( v1 != a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v1; // rbx
__int64 v2; // rdx
__int64 result; // rax

if ( a1 > 0 )
{
v1 = 0LL;
do
{
v2 = current_conf[v1++];
result = (*(&exit_mod + v2))();
}
while ( v1 != a1 );
}
return result;
}

original_code:
static void exit_modules(int nb_modules){
 int cpt;
 for (cpt = 0; cpt < nb_modules ; cpt++ ){
  ((void) (0));
  exit_mod[current_conf[cpt]]();
 }
}

variable_types: cpt int

return_type: void


decompiled_code:
__int64 __fastcall update_stats(int a1)
{
__int64 v1; // rbx
__int64 v2; // rdx
__int64 result; // rax

if ( a1 > 0 )
{
v1 = 0LL;
do
{
v2 = current_conf[v1++];
result = (*(&main_mod + v2))();
}
while ( v1 != a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rbx
__int64 v2; // rdx
__int64 result; // rax

if ( a1 > 0 )
{
v1 = 0LL;
do
{
v2 = current_conf[v1++];
result = (*(&main_mod + v2))();
}
while ( v1 != a1 );
}
return result;
}

original_code:
static void update_stats(int nb_modules)
{
  int cpt;
  for (cpt = 0; cpt < nb_modules; cpt++)
    {
      (void)main_mod[current_conf[cpt]]();
    }
}


decompiled_code:
__int64 display_message()
{
FILE *v0; // rsi
const char *v1; // rdi

v0 = stdout;
v1 = (const char *)msg_queue_peek();
fputs(v1, v0);
return msg_queue_pop();
}

canonical_decompiled_code:
__int64 func2()
{
FILE *v0; // rsi
const char *v1; // rdi

v0 = stdout;
v1 = (const char *)msg_queue_peek();
fputs(v1, v0);
return msg_queue_pop();
}

original_code:
static void display_message()
{
  ((void) (0));
  ;;
  ((void) (0));
  ; fputs(msg_queue_peek(), stdout);
  ; (void)msg_queue_pop();
}


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

result = sysinfo(&info);
if ( result == -1 )
{
perror("Fatal error of syscall sysinfo used at least by LOADAVERAGE,USERS,PROCS,RAM,SWAP");
exit(1);
}
return result;
}

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

result = sysinfo(&info);
if ( result == -1 )
{
perror("Fatal error of syscall sysinfo used at least by LOADAVERAGE,USERS,PROCS,RAM,SWAP");
exit(1);
}
return result;
}

original_code:
void get_sysinfo() {
 if (sysinfo(&si) == -1){
  perror("Fatal error of syscall sysinfo used at least by LOADAVERAGE,USERS,PROCS,RAM,SWAP");
  exit(1);
 }
}


decompiled_code:
int __fastcall display_module_stats(int a1)
{
FILE *v1; // rbp
const char *v2; // rax

fputs(*((const char **)&modules_color + a1), stdout);
v1 = stdout;
v2 = (const char *)(*(&main_mod + a1))();
return fputs(v2, v1);
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
FILE *v1; // rbp
const char *v2; // rax

fputs(*((const char **)&modules_color + a1), stdout);
v1 = stdout;
v2 = (const char *)(*(&main_mod + a1))();
return fputs(v2, v1);
}

original_code:
void display_module_stats(int module_idx){
 ;;
 ; (void)fputs(modules_color[module_idx], stdout); (void)fputs(main_mod[module_idx](), stdout);
}


decompiled_code:
unsigned int end_wait()
{
puts(&byte_3C9);
fflush(stdout);
return sleep(2u);
}

canonical_decompiled_code:
unsigned int func5()
{
puts(&byte_3C9);
fflush(stdout);
return sleep(2u);
}

original_code:
void end_wait(){
 (void)puts("\005{-}");
 (void)fflush(stdout);
 (void)sleep(2);
}


decompiled_code:
void __fastcall loop_stat(int a1)
{
__int64 v2; // rbp
__int64 v3; // rbx
int v4; // edi

if ( stats_loop )
{
v2 = a1;
do
{
get_sysinfo();
if ( (unsigned __int8)msg_queue_is_empty() )
{
v3 = 0LL;
if ( a1 > 0 )
{
do
{
v4 = current_conf[v3++];
display_module_stats(v4);
}
while ( v3 != v2 );
}
}
else
{
display_message();
update_stats(a1);
}
end_wait();
}
while ( stats_loop );
}
}

canonical_decompiled_code:
void __fastcall func6(int a1)
{
__int64 v2; // rbp
__int64 v3; // rbx
int v4; // edi

if ( stats_loop )
{
v2 = a1;
do
{
func3();
if ( (unsigned __int8)msg_queue_is_empty() )
{
v3 = 0LL;
if ( a1 > 0 )
{
do
{
v4 = current_conf[v3++];
func4(v4);
}
while ( v3 != v2 );
}
}
else
{
func2();
func1(a1);
}
func5();
}
while ( stats_loop );
}
}

original_code:
static void loop_stat(int nb_modules){
 int cpt;
 ((void) (0));
 while(stats_loop) {
  get_sysinfo();
  if (!msg_queue_is_empty()) {
   display_message();
   update_stats(nb_modules);
  }
  else {
   for(cpt=0; cpt<nb_modules; cpt++){
    (void) display_module_stats(current_conf[cpt]);
   }
  }
  (void) end_wait();
  ;;
 }
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp

main_loop = 1;
install_signals(argc, argv, envp);
while ( 1 )
{
while ( main_loop )
{
stats_loop = 1;
v3 = get_configuration();
loop_stat(v3);
exit_modules(v3);
}
pause();
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp

main_loop = 1;
install_signals(argc, argv, envp);
while ( 1 )
{
while ( main_loop )
{
stats_loop = 1;
v3 = get_configuration();
func6(v3);
func0(v3);
}
pause();
}
}

original_code:
int main ( )
{
 int nb_modules;
 main_loop = 1;
 ;
 install_signals();
 while(1){
  while (main_loop){
   stats_loop=1;
   ;
   nb_modules = get_configuration();
   ((void) (0));
   ;;
   ;
   loop_stat(nb_modules);
   ;
   exit_modules(nb_modules);
   ;;
  }
  (void)pause();
 }
}

canonical_original_code:
int main()
{
 int nb_modules;
 main_loop = 1;
 ;
 install_signals();
 while(1){
  while (main_loop){
   stats_loop=1;
   ;
   nb_modules = get_configuration();
   ((void) (0));
   ;;
   ;
   loop_stat(nb_modules);
   ;
   exit_modules(nb_modules);
   ;;
  }
  (void)pause();
 }
}

return_type: int


uptime

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

if ( qword_238 > 86400 )
{
snprintf(&uptime_result, 0xAuLL, "%ldd%02ldh ", qword_238 / 86400LL, qword_238 % 86400LL / 0xE10uLL);
result = &uptime_result;
}
else if ( qword_238 > 3600 )
{
snprintf(&uptime_result, 0xAuLL, "%02ldh%02ldm ", qword_238 / 3600LL, qword_238 % 3600LL / 0x3CuLL);
result = &uptime_result;
}
else
{
if ( qword_238 > 60 )
snprintf(&uptime_result, 0xAuLL, "%02ldm%02lds ", qword_238 / 60LL, qword_238 % 60LL);
else
uptime_result = 0;
result = &uptime_result;
}
return result;
}

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

if ( qword_238 > 86400 )
{
snprintf(&uptime_result, 0xAuLL, "%ldd%02ldh ", qword_238 / 86400LL, qword_238 % 86400LL / 0xE10uLL);
result = &uptime_result;
}
else if ( qword_238 > 3600 )
{
snprintf(&uptime_result, 0xAuLL, "%02ldh%02ldm ", qword_238 / 3600LL, qword_238 % 3600LL / 0x3CuLL);
result = &uptime_result;
}
else
{
if ( qword_238 > 60 )
snprintf(&uptime_result, 0xAuLL, "%02ldm%02lds ", qword_238 / 60LL, qword_238 % 60LL);
else
uptime_result = 0;
result = &uptime_result;
}
return result;
}

original_code:
char * uptime(){
 ((void) (0));
 if (si.uptime > 86400){
  (void) snprintf(uptime_result, 10, "%ldd%02ldh ", (si.uptime/86400), ((si.uptime%86400)/3600));
 } else if (si.uptime > 3600) {
  (void) snprintf(uptime_result, 10, "%02ldh%02ldm ", (si.uptime/3600), ((si.uptime%3600)/60));
 } else if (si.uptime > 60) {
  (void) snprintf(uptime_result, 10, "%02ldm%02lds ", (si.uptime/60), (si.uptime%60));
 } else {
  uptime_result[0]='\0';
 }
 return uptime_result;
}

canonical_original_code:
char *uptime(){
 ((void) (0));
 if (si.uptime > 86400){
  (void) snprintf(uptime_result, 10, "%ldd%02ldh ", (si.uptime/86400), ((si.uptime%86400)/3600));
 } else if (si.uptime > 3600) {
  (void) snprintf(uptime_result, 10, "%02ldh%02ldm ", (si.uptime/3600), ((si.uptime%3600)/60));
 } else if (si.uptime > 60) {
  (void) snprintf(uptime_result, 10, "%02ldm%02lds ", (si.uptime/60), (si.uptime%60));
 } else {
  uptime_result[0]='\0';
 }
 return uptime_result;
}

return_type: char *


decompiled_code:
const char *init_uptime()
{
return "Uptime ";
}

canonical_decompiled_code:
const char *func1()
{
return "Uptime ";
}

original_code:
char * init_uptime(char * UNUSED_conf_line __attribute__((__unused__))){
 return "Uptime ";
}

canonical_original_code:
char *init_uptime(char *UNUSED_conf_line){
 return "Uptime ";
}


decompiled_code:
void exit_uptime()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void exit_uptime(){
}

canonical_original_code:
void exit_uptime(){
}


decompiled_code:
__int64 calculate_swap()
{
__int64 v0; // rax
__int64 v1; // rdx
float v2; // xmm0_4
float v3; // xmm1_4
unsigned __int64 v5; // rcx
__int64 v6; // rdx

v0 = unk_198[8];
if ( v0 )
{
v1 = v0 - unk_198[9];
if ( v1 < 0 )
{
v5 = v1 & 1 | ((unsigned __int64)(v0 - unk_198[9]) >> 1);
v2 = (float)(int)v5 + (float)(int)v5;
if ( v0 >= 0 )
goto LABEL_4;
}
else
{
v2 = (float)(int)v1;
if ( v0 >= 0 )
{
LABEL_4:
v3 = (float)(int)v0;
return (unsigned int)(int)(float)(v2 / (float)(v3 / 100.0));
}
}
v6 = unk_198[8] & 1LL | (unk_198[8] >> 1);
v3 = (float)(int)v6 + (float)(int)v6;
return (unsigned int)(int)(float)(v2 / (float)(v3 / 100.0));
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
__int64 v1; // rdx
float v2; // xmm0_4
float v3; // xmm1_4
unsigned __int64 v5; // rcx
__int64 v6; // rdx

v0 = unk_198[8];
if ( v0 )
{
v1 = v0 - unk_198[9];
if ( v1 < 0 )
{
v5 = v1 & 1 | ((unsigned __int64)(v0 - unk_198[9]) >> 1);
v2 = (float)(int)v5 + (float)(int)v5;
if ( v0 >= 0 )
goto LABEL_4;
}
else
{
v2 = (float)(int)v1;
if ( v0 >= 0 )
{
LABEL_4:
v3 = (float)(int)v0;
return (unsigned int)(int)(float)(v2 / (float)(v3 / 100.0));
}
}
v6 = unk_198[8] & 1LL | (unk_198[8] >> 1);
v3 = (float)(int)v6 + (float)(int)v6;
return (unsigned int)(int)(float)(v2 / (float)(v3 / 100.0));
}
return 0xFFFFFFFFLL;
}

original_code:
static int calculate_swap(){
 if (si.totalswap == 0)
  return -1;
 return (int) ( (float)( (si.totalswap - si.freeswap)) / ( ((float)si.totalswap) /100) );
}


swap

decompiled_code:
char *swap()
{
int v0; // eax
int v2; // eax

v0 = calculate_swap();
if ( v0 == -1 )
{
swap_result = 0;
}
else
{
swap_result = 60;
v2 = myprint_percentage(&word_109, (unsigned __int16)v0);
*(__int16 *)((char *)&word_109 + v2) = 8254;
byte_10B[v2] = 0;
}
return &swap_result;
}

canonical_decompiled_code:
char *func1()
{
int v0; // eax
int v2; // eax

v0 = func0();
if ( v0 == -1 )
{
swap_result = 0;
}
else
{
swap_result = 60;
v2 = myprint_percentage(&word_109, (unsigned __int16)v0);
*(__int16 *)((char *)&word_109 + v2) = 8254;
byte_10B[v2] = 0;
}
return &swap_result;
}

original_code:
char * swap(){
 int swap_used;
 char * ptr;
 ptr=swap_result;
 swap_used = calculate_swap();
 ((void) (0));
 if (swap_used != -1){
  (*(ptr++))='<';
  ptr+=myprint_percentage(ptr, swap_used);
  (*(ptr++))='>';
  (*(ptr++))=' ';
  (*(ptr))='\0';
 } else {
  swap_result[0]='\0';
 }
 return swap_result;
}

canonical_original_code:
char *swap(){
 int swap_used;
 char *ptr;
 ptr=swap_result;
 swap_used = calculate_swap();
 ((void) (0));
 if (swap_used != -1){
  (*(ptr++))='<';
  ptr+=myprint_percentage(ptr, swap_used);
  (*(ptr++))='>';
  (*(ptr++))=' ';
  (*(ptr))='\0';
 } else {
  swap_result[0]='\0';
 }
 return swap_result;
}

variable_types:
ptr
char *


decompiled_code:
const char *init_swap()
{
return "Swap ";
}

canonical_decompiled_code:
const char *func2()
{
return "Swap ";
}

original_code:
char * init_swap(char * UNUSED_conf_line __attribute__((__unused__))){
 return "Swap ";
}

canonical_original_code:
char *init_swap(char *UNUSED_conf_line){
 return "Swap ";
}


decompiled_code:
void exit_swap()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void exit_swap(){
}

canonical_original_code:
void exit_swap(){
}


decompiled_code:
__int64 __fastcall search_home(_QWORD *a1)
{
char *v1; // rax
const char *v2; // rbp
int v3; // er13
char *v4; // rax
const char *v5; // rbx
char *v6; // rbx
__int64 result; // rax

v1 = getenv("HOME");
if ( v1 )
{
v2 = v1;
v3 = strlen(v1);
v4 = (char *)malloc((unsigned int)(v3 + 14));
*a1 = v4;
v5 = v4;
strncpy(v4, v2, (unsigned int)(v3 + 1));
v6 = (char *)&v5[strlen(v5)];
result = 0x65726373796D2E2FLL;
strcpy(v6, "/.myscreenrc");
}
else
{
result = (__int64)malloc(1uLL);
*(_BYTE *)result = 0;
*a1 = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
char *v1; // rax
const char *v2; // rbp
int v3; // er13
char *v4; // rax
const char *v5; // rbx
char *v6; // rbx
__int64 result; // rax

v1 = getenv("HOME");
if ( v1 )
{
v2 = v1;
v3 = strlen(v1);
v4 = (char *)malloc((unsigned int)(v3 + 14));
*a1 = v4;
v5 = v4;
strncpy(v4, v2, (unsigned int)(v3 + 1));
v6 = (char *)&v5[strlen(v5)];
result = 0x65726373796D2E2FLL;
strcpy(v6, "/.myscreenrc");
}
else
{
result = (__int64)malloc(1uLL);
*(_BYTE *)result = 0;
*a1 = result;
}
return result;
}

original_code:
void search_home(char ** conf_home){
 char * home;
 ((void) (0));
 home = getenv("HOME");
 if (home == ((void *)0)){
  ((void) (0));
  ;
  (*conf_home) = malloc(1);
  (*conf_home)[0]='\0';
 }
 else {
  unsigned int home_len;
  unsigned int home_len_max;
  home_len = strlen(home) + 1;
  home_len_max = home_len + strlen("/.myscreenrc");
  ((void) (0));
  ((void) (0));
  ((void) (0));
  ((void) (0));
  (*conf_home) = malloc(home_len_max + 1);
  strncpy((*conf_home), home, home_len);
  strncat((*conf_home), "/.myscreenrc", (home_len_max - home_len));
  ((void) (0));
 }
 ((void) (0));
}

canonical_original_code:
void search_home(char **conf_home){
 char *home;
 ((void) (0));
 home = getenv("HOME");
 if (home == ((void *)0)){
  ((void) (0));
  ;
  (*conf_home) = malloc(1);
  (*conf_home)[0]='\0';
 }
 else {
  unsigned int home_len;
  unsigned int home_len_max;
  home_len = strlen(home) + 1;
  home_len_max = home_len + strlen("/.myscreenrc");
  ((void) (0));
  ((void) (0));
  ((void) (0));
  ((void) (0));
  (*conf_home) = malloc(home_len_max + 1);
  strncpy((*conf_home), home, home_len);
  strncat((*conf_home), "/.myscreenrc", (home_len_max - home_len));
  ((void) (0));
 }
 ((void) (0));
}

variable_types:
home
char *


decompiled_code:
_BOOL8 try_read_home_configuration()
{
FILE *v0; // rbx
char *filename; // [rsp+8h] [rbp-10h] BYREF

filename = 0LL;
search_home(&filename);
v0 = fopen(filename, "r");
f = v0;
free(filename);
return v0 != 0LL;
}

canonical_decompiled_code:
_BOOL8 func1()
{
FILE *v0; // rbx
char *filename; // [rsp+8h] [rbp-10h] BYREF

filename = 0LL;
func0(&filename);
v0 = fopen(filename, "r");
f = v0;
free(filename);
return v0 != 0LL;
}

original_code:
int try_read_home_configuration(){
 char * conf_home;
 short result;
 conf_home = ((void *)0);
 search_home(&conf_home);
 ((void) (0));
 if (( f = fopen(conf_home, "r")) == ((void *)0)){
  ;
  result = 0;
 } else {
  ;
  result = 1;
 }
 free(conf_home);
 return result;
}

canonical_original_code:
int try_read_home_configuration(){
 char *conf_home;
 short result;
 conf_home = ((void *)0);
 search_home(&conf_home);
 ((void) (0));
 if (( f = fopen(conf_home, "r")) == ((void *)0)){
  ;
  result = 0;
 } else {
  ;
  result = 1;
 }
 free(conf_home);
 return result;
}

variable_types: result short


decompiled_code:
_BOOL8 try_read_etc_configuration()
{
f = fopen("/etc/myscreenrc", "r");
return f != 0LL;
}

canonical_decompiled_code:
_BOOL8 func2()
{
f = fopen("/etc/myscreenrc", "r");
return f != 0LL;
}

original_code:
int try_read_etc_configuration(){
 if ( (f = fopen("/etc/myscreenrc", "r")) == ((void *)0)){
  ;
  return 0;
 }
 ;
 return 1;
}


decompiled_code:
_BOOL8 try_read_local_configuration()
{
f = fopen("./myscreenrc", "r");
return f != 0LL;
}

canonical_decompiled_code:
_BOOL8 func3()
{
f = fopen("./myscreenrc", "r");
return f != 0LL;
}

original_code:
int try_read_local_configuration(){
 if ( (f = fopen("./myscreenrc", "r")) == ((void *)0)){
  ;
  return 0;
 }
 ;
 return 1;
}


decompiled_code:
int __fastcall init_module(int a1, int a2, __int64 a3)
{
FILE *v4; // r12
const char *v5; // rax

*((_DWORD *)&current_conf + a2) = a1;
fputs(*((const char **)&modules_color + a1), stdout);
v4 = stdout;
v5 = (const char *)(*(&init_mod + a1))(a3);
return fputs(v5, v4);
}

canonical_decompiled_code:
int __fastcall func5(int a1, int a2, __int64 a3)
{
FILE *v4; // r12
const char *v5; // rax

*((_DWORD *)&current_conf + a2) = a1;
fputs(*((const char **)&modules_color + a1), stdout);
v4 = stdout;
v5 = (const char *)(*(&init_mod + a1))(a3);
return fputs(v5, v4);
}

original_code:
void init_module(int module_idx, int nb_module, char * line_conf){
 current_conf[nb_module] = module_idx;
 ;
 ;;
 ; (void)fputs(modules_color[module_idx], stdout); (void)fputs(init_mod[module_idx](line_conf), stdout);;
}

canonical_original_code:
void init_module(int module_idx, int nb_module, char *line_conf){
 current_conf[nb_module] = module_idx;
 ;
 ;;
 ; (void)fputs(modules_color[module_idx], stdout); (void)fputs(init_mod[module_idx](line_conf), stdout);;
}


decompiled_code:
__int64 get_default_configuration()
{
int i; // ebx
int v1; // esi
int v2; // edi

for ( i = 0; i != 13; ++i )
{
v1 = i;
v2 = i;
init_module(v2, v1, (__int64)&unk_50A);
}
return 13LL;
}

original_code:
int get_default_configuration(){
 int nb_modules;
 ;;
 for(nb_modules=0;nb_modules < 13;nb_modules++ ) {
  init_module(nb_modules,nb_modules,"\0");
 }
 return nb_modules;
}


decompiled_code:
__int64 __fastcall get_module_index(_BYTE *a1)
{
__int64 v1; // rbx
const char *v2; // rax
size_t v3; // r12
const char *v4; // r14
const char *v5; // rbp
size_t n[6]; // [rsp+8h] [rbp-30h] BYREF

v1 = 0LL;
v2 = identify_module_name(a1, n);
v3 = n[0];
v4 = v2;
do
{
v5 = (const char *)*((_QWORD *)&modules + v1);
if ( strlen(v5) == v3 && !strncmp(v4, v5, v3) )
return (unsigned int)v1;
++v1;
}
while ( v1 != 13 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1)
{
__int64 v1; // rbx
const char *v2; // rax
size_t v3; // r12
const char *v4; // r14
const char *v5; // rbp
size_t n[6]; // [rsp+8h] [rbp-30h] BYREF

v1 = 0LL;
v2 = identify_module_name(a1, n);
v3 = n[0];
v4 = v2;
do
{
v5 = (const char *)*((_QWORD *)&modules + v1);
if ( strlen(v5) == v3 && !strncmp(v4, v5, v3) )
return (unsigned int)v1;
++v1;
}
while ( v1 != 13 );
return 0xFFFFFFFFLL;
}

original_code:
int get_module_index(const char * s) {
  int cpt;
 size_t len;
 char *sptr;
 sptr = identify_module_name(s, &len);
 for (cpt=0 ; cpt<13 ; cpt++){
   if (strlen(modules[cpt]) == len && strncmp(sptr, modules[cpt], len) == 0)
     return cpt;
 }
 ;;
 return -1;
}

canonical_original_code:
int get_module_index(char *s) {
  int cpt;
 unsigned long len;
 char *sptr;
 sptr = identify_module_name(s, &len);
 for (cpt=0 ; cpt<13 ; cpt++){
   if (strlen(modules[cpt]) == len && strncmp(sptr, modules[cpt], len) == 0)
     return cpt;
 }
 ;;
 return -1;
}

variable_types:
s
char *

variable_types:
len
unsigned long

variable_types:
sptr
char *


decompiled_code:
char *__fastcall line_reader(char *s, _DWORD *a2)
{
int v2; // eax
char *v3; // rax
bool v4; // zf
char *result; // rax

v2 = get_module_index(s);
*a2 = v2;
if ( v2 == -1 )
return 0LL;
v3 = strchr(s, 61);
v4 = v3 == 0LL;
result = v3 + 1;
if ( v4 )
result = (char *)empty_string;
return result;
}

canonical_decompiled_code:
char *__fastcall func8(char *s, _DWORD *a2)
{
int v2; // eax
char *v3; // rax
bool v4; // zf
char *result; // rax

v2 = func7(s);
*a2 = v2;
if ( v2 == -1 )
return 0LL;
v3 = strchr(s, 61);
v4 = v3 == 0LL;
result = v3 + 1;
if ( v4 )
result = (char *)empty_string;
return result;
}

original_code:
char * line_reader(char * line, int * module_idx){
 char * adr_equal;
 if ( ((*module_idx) = get_module_index(line)) != -1){
  if ( (adr_equal = strchr(line, '=')) == ((void *)0) ){
   return empty_string;
  } else {
   return adr_equal+1;
  }
 }
 return ((void *)0);
}

canonical_original_code:
char *line_reader(char *line, int *module_idx){
 char *adr_equal;
 if ( ((*module_idx) = get_module_index(line)) != -1){
  if ( (adr_equal = strchr(line, '=')) == ((void *)0) ){
   return empty_string;
  } else {
   return adr_equal+1;
  }
 }
 return ((void *)0);
}

variable_types:
line
char *


decompiled_code:
__int64 read_configuration_file()
{
unsigned int v0; // er13
FILE *v1; // r12
char *v2; // rdx
int v3; // esi
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = 0;
while ( 1 )
{
v1 = f;
if ( feof(f) )
break;
if ( fgets(&line, 200, v1) && line != 10 && line != 35 )
{
v2 = line_reader(&line, v5);
if ( v2 )
{
v3 = v0++;
init_module(v5[0], v3, (__int64)v2);
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // er13
FILE *v1; // r12
char *v2; // rdx
int v3; // esi
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = 0;
while ( 1 )
{
v1 = f;
if ( feof(f) )
break;
if ( fgets(&line, 200, v1) && line != 10 && line != 35 )
{
v2 = func8(&line, v5);
if ( v2 )
{
v3 = v0++;
func5(v5[0], v3, (__int64)v2);
}
}
}
return v0;
}

original_code:
int read_configuration_file(){
 int nb_module;
 int module_idx;
 char * line_conf;
 nb_module = 0;
 while (feof(f) == 0){
  if (fgets(line, 200, f) != ((void *)0) && line[0] != '#' && line[0] != '\n') {
   if ( (line_conf = line_reader(line, &module_idx)) != ((void *)0)){
    init_module(module_idx, nb_module, line_conf);
    nb_module++;
   } else {
    ;;
   }
  }
 }
 ((void) (0));
 return nb_module;
}

canonical_original_code:
int read_configuration_file(){
 int nb_module;
 int module_idx;
 char *line_conf;
 nb_module = 0;
 while (feof(f) == 0){
  if (fgets(line, 200, f) != ((void *)0) && line[0] != '#' && line[0] != '\n') {
   if ( (line_conf = line_reader(line, &module_idx)) != ((void *)0)){
    init_module(module_idx, nb_module, line_conf);
    nb_module++;
   } else {
    ;;
   }
  }
 }
 ((void) (0));
 return nb_module;
}


decompiled_code:
__int64 get_configuration()
{
unsigned int v0; // er12
__int64 result; // rax
unsigned int v2; // er12

find_conf_isra_0();
if ( f )
{
v0 = read_configuration_file();
if ( fclose(f) == -1 )
perror("Closing Configuration file");
end_wait();
result = v0;
}
else
{
v2 = get_default_configuration();
end_wait();
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v0; // er12
__int64 result; // rax
unsigned int v2; // er12

func4();
if ( f )
{
v0 = func9();
if ( fclose(f) == -1 )
perror("Closing Configuration file");
end_wait();
result = v0;
}
else
{
v2 = func6();
end_wait();
result = v2;
}
return result;
}

original_code:
int get_configuration(){
 int nb_modules = -1;
 find_conf();
 if ( f == ((void *)0)){
  nb_modules = get_default_configuration();
 } else {
  nb_modules = read_configuration_file();
  if (fclose(f) == (-1)){
   perror("Closing Configuration file");
  }
 }
 end_wait();
 ((void) (0));
 return nb_modules;
}


decompiled_code:
char *disks_usage()
{
int v0; // eax
const char *v1; // rbx
const char *v2; // rbp
const char *v3; // rsi
_BYTE v5[6056]; // [rsp+0h] [rbp-17A8h] BYREF

v0 = get_disks_usage((__int64)v5);
disk_result[0] = 0;
if ( v0 > 0 )
{
v1 = v5;
v2 = &v5[602 * (v0 - 1) + 602];
do
{
v3 = v1;
v1 += 602;
strcat(disk_result, v3);
*(_WORD *)&disk_result[strlen(disk_result)] = 32;
}
while ( v1 != v2 );
}
return disk_result;
}

canonical_decompiled_code:
char *func2()
{
int v0; // eax
const char *v1; // rbx
const char *v2; // rbp
const char *v3; // rsi
_BYTE v5[6056]; // [rsp+0h] [rbp-17A8h] BYREF

v0 = func1((__int64)v5);
disk_result[0] = 0;
if ( v0 > 0 )
{
v1 = v5;
v2 = &v5[602 * (v0 - 1) + 602];
do
{
v3 = v1;
v1 += 602;
strcat(disk_result, v3);
*(_WORD *)&disk_result[strlen(disk_result)] = 32;
}
while ( v1 != v2 );
}
return disk_result;
}

original_code:
char * disks_usage(){
 int cpt;
 int nb_disks;
 char disks_usage[10][(((( 30 )* 10) +1) * 2 )];
 nb_disks = get_disks_usage(disks_usage);
 disk_result[0]='\0';
 for (cpt=0;cpt<nb_disks;cpt++) {
  strcat(disk_result,disks_usage[cpt]);
  strcat(disk_result," ");
 }
 return disk_result;
}

canonical_original_code:
char *disks_usage(){
 int cpt;
 int nb_disks;
 char disks_usage[10][-1];
 nb_disks = get_disks_usage(disks_usage);
 disk_result[0]='\0';
 for (cpt=0;cpt<nb_disks;cpt++) {
  strcat(disk_result,disks_usage[cpt]);
  strcat(disk_result," ");
 }
 return disk_result;
}


decompiled_code:
const char *init_disks_usage()
{
return "Disk usages ";
}

canonical_decompiled_code:
const char *func3()
{
return "Disk usages ";
}

original_code:
char * init_disks_usage(char * UNUSED_conf_line __attribute__((__unused__))){
 return "Disk usages ";
}

canonical_original_code:
char *init_disks_usage(char *UNUSED_conf_line){
 return "Disk usages ";
}


decompiled_code:
void exit_disks_usage()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void exit_disks_usage(){
}

canonical_original_code:
void exit_disks_usage(){
}


loadaverage

decompiled_code:
char *loadaverage()
{
__int64 v0; // rax
float v1; // xmm0_4

v0 = unk_158[1];
loadaverage_result = 0;
if ( v0 < 0 )
v1 = (float)(v0 & 1 | (unsigned int)((unsigned __int64)v0 >> 1))
+ (float)(v0 & 1 | (unsigned int)((unsigned __int64)v0 >> 1));
else
v1 = (float)(int)v0;
snprintf(&loadaverage_result, 0xAuLL, "%1.2f ", (float)(v1 * 0.000015258789));
return &loadaverage_result;
}

canonical_decompiled_code:
char *func0()
{
__int64 v0; // rax
float v1; // xmm0_4

v0 = unk_158[1];
loadaverage_result = 0;
if ( v0 < 0 )
v1 = (float)(v0 & 1 | (unsigned int)((unsigned __int64)v0 >> 1))
+ (float)(v0 & 1 | (unsigned int)((unsigned __int64)v0 >> 1));
else
v1 = (float)(int)v0;
snprintf(&loadaverage_result, 0xAuLL, "%1.2f ", (float)(v1 * 0.000015258789));
return &loadaverage_result;
}

original_code:
char * loadaverage(){
 loadaverage_result[0]='\0';
 (void)snprintf(loadaverage_result, 10, "%1.2f ", ((float)si.loads[0])/(float)(1<<16));
 return loadaverage_result;
}

canonical_original_code:
char *loadaverage(){
 loadaverage_result[0]='\0';
 (void)snprintf(loadaverage_result, 10, "%1.2f ", ((float)si.loads[0])/(float)(1<<16));
 return loadaverage_result;
}


decompiled_code:
const char *__fastcall init_loadaverage(const char *a1)
{
int v1; // eax
const char *v2; // r8

v1 = atoi(a1);
v2 = "Loadaverage 5mn ";
if ( v1 != 5 )
{
v2 = "Loadaverage 15mn ";
if ( v1 != 15 )
v2 = "Loadaverage 1mn ";
}
return v2;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
int v1; // eax
const char *v2; // r8

v1 = atoi(a1);
v2 = "Loadaverage 5mn ";
if ( v1 != 5 )
{
v2 = "Loadaverage 15mn ";
if ( v1 != 15 )
v2 = "Loadaverage 1mn ";
}
return v2;
}

original_code:
char * init_loadaverage(char * conf_line){
 int int_conf_line;
 int_conf_line = 0;
 config=0;
 int_conf_line = atoi(conf_line);
 if (int_conf_line == 5){
  int_conf_line = 1;
  return "Loadaverage 5mn ";
 } else if (int_conf_line == 15){
  int_conf_line = 2;
  return "Loadaverage 15mn ";
 } else {
  int_conf_line = 0;
  return "Loadaverage 1mn ";
 }
 return "Loadaverage 1mn ";
}

canonical_original_code:
char *init_loadaverage(char *conf_line){
 int int_conf_line;
 int_conf_line = 0;
 config=0;
 int_conf_line = atoi(conf_line);
 if (int_conf_line == 5){
  int_conf_line = 1;
  return "Loadaverage 5mn ";
 } else if (int_conf_line == 15){
  int_conf_line = 2;
  return "Loadaverage 15mn ";
 } else {
  int_conf_line = 0;
  return "Loadaverage 1mn ";
 }
 return "Loadaverage 1mn ";
}


decompiled_code:
void exit_loadaverage()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void exit_loadaverage(){
}

canonical_original_code:
void exit_loadaverage(){
}


processes

decompiled_code:
char *processes()
{
__int64 v0; // rcx

v0 = unk_C8[40];
processes_result = 0;
snprintf(&processes_result, 9uLL, "%hu& ", v0);
return &processes_result;
}

canonical_decompiled_code:
char *func0()
{
__int64 v0; // rcx

v0 = unk_C8[40];
processes_result = 0;
snprintf(&processes_result, 9uLL, "%hu& ", v0);
return &processes_result;
}

original_code:
char * processes(){
 ((void) (0));
 processes_result[0]='\0';
 (void) snprintf(processes_result, 9, "%hu& ", si.procs);
 return processes_result;
}

canonical_original_code:
char *processes(){
 ((void) (0));
 processes_result[0]='\0';
 (void) snprintf(processes_result, 9, "%hu& ", si.procs);
 return processes_result;
}


decompiled_code:
const char *init_processes()
{
return "Procs& ";
}

canonical_decompiled_code:
const char *func1()
{
return "Procs& ";
}

original_code:
char * init_processes(char * UNUSED_conf_line __attribute__((__unused__))){
 return "Procs& ";
}

canonical_original_code:
char *init_processes(char *UNUSED_conf_line){
 return "Procs& ";
}


decompiled_code:
void exit_processes()
{
;
}

original_code:
void exit_processes(){
}

canonical_original_code:
void exit_processes(){
}


decompiled_code:
int sigusr1_handler()
{
stats_loop = 0;
main_loop = 1;
puts("Restarting ...");
return fflush(stdout);
}

canonical_decompiled_code:
int func0()
{
stats_loop = 0;
main_loop = 1;
puts("Restarting ...");
return fflush(stdout);
}

original_code:
void sigusr1_handler(int UNUSED_sig __attribute__((__unused__))){
  stats_loop=0;
  main_loop=1;
  printf("Restarting ...\n");
  (void) (void)fflush(stdout);
  return;
}

canonical_original_code:
void sigusr1_handler(int UNUSED_sig){
  stats_loop=0;
  main_loop=1;
  printf("Restarting ...\n");
  (void) (void)fflush(stdout);
  return;
}


decompiled_code:
int sigusr2_handler()
{
stats_loop = 0;
main_loop = 0;
puts("Stopped : run \"myscreen restart\" to resume");
return fflush(stdout);
}

canonical_decompiled_code:
int func1()
{
stats_loop = 0;
main_loop = 0;
puts("Stopped : run \"myscreen restart\" to resume");
return fflush(stdout);
}

original_code:
void sigusr2_handler(int UNUSED_sig __attribute__((__unused__))){
  stats_loop=0;
  main_loop=0;
  printf("Stopped : run \"myscreen restart\" to resume\n");
  (void) (void)fflush(stdout);
  return;
}

canonical_original_code:
void sigusr2_handler(int UNUSED_sig){
  stats_loop=0;
  main_loop=0;
  printf("Stopped : run \"myscreen restart\" to resume\n");
  (void) (void)fflush(stdout);
  return;
}


error

decompiled_code:
int __fastcall error(const char *a1, __int16 a2)
{
int result; // eax

result = fprintf(stderr, "Error : %s", a1);
if ( a2 == 1 )
exit(1);
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, __int16 a2)
{
int result; // eax

result = fprintf(stderr, "Error : %s", a1);
if ( a2 == 1 )
exit(1);
return result;
}

original_code:
void error(const char * err, unsigned short fatal){
  fprintf(stderr,"Error : %s",err);
  if (fatal == 1)
    exit(1);
}

canonical_original_code:
void error(char *err, unsigned short fatal){
  fprintf(stderr,"Error : %s",err);
  if (fatal == 1)
    exit(1);
}

variable_types:
err
char *

variable_types:
fatal
unsigned short


strncpyclr

decompiled_code:
__int64 __fastcall strncpyclr(__int64 a1, const char *a2, unsigned int a3)
{
size_t v5; // rax
__int64 v6; // rdx
unsigned __int64 v7; // rcx
__int64 result; // rax
unsigned int v9; // er12
size_t v10; // rax
char v11; // si
unsigned int v12; // er14

v5 = strlen(a2);
v6 = 0LL;
v7 = v5;
for ( result = 0LL; (unsigned int)result < a3 && (unsigned int)result < v7; result = v12 )
{
v11 = a2[(unsigned int)result];
v12 = result + 1;
if ( v11 != 32 || a2[v12] != 32 && (_DWORD)result )
{
*(_BYTE *)(a1 + v6) = v11;
v9 = v6 + 1;
v10 = strlen(a2);
v6 = v9;
v7 = v10;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, unsigned int a3)
{
size_t v5; // rax
__int64 v6; // rdx
unsigned __int64 v7; // rcx
__int64 result; // rax
unsigned int v9; // er12
size_t v10; // rax
char v11; // si
unsigned int v12; // er14

v5 = strlen(a2);
v6 = 0LL;
v7 = v5;
for ( result = 0LL; (unsigned int)result < a3 && (unsigned int)result < v7; result = v12 )
{
v11 = a2[(unsigned int)result];
v12 = result + 1;
if ( v11 != 32 || a2[v12] != 32 && (_DWORD)result )
{
*(_BYTE *)(a1 + v6) = v11;
v9 = v6 + 1;
v10 = strlen(a2);
v6 = v9;
v7 = v10;
}
}
return result;
}

original_code:
void strncpyclr(char * dest, const char * src, unsigned int len){
 unsigned int s, d;
 d = 0;
    for (s = 0 ; s < strlen(src) && s < len ; s++){
  if (src[s] != ' ' || (src[s+1] != ' ' && s != 0 )){
            dest[d++] = src[s];
        } else if (src[s] == '\t' || src[s] == '\n'){
         dest[d++] = ' ';
     }
 }
}

canonical_original_code:
void strncpyclr(char *dest, char *src, unsigned int len){
 unsigned int s; unsigned int d;
 d = 0;
    for (s = 0 ; s < strlen(src) && s < len ; s++){
  if (src[s] != ' ' || (src[s+1] != ' ' && s != 0 )){
            dest[d++] = src[s];
        } else if (src[s] == '\t' || src[s] == '\n'){
         dest[d++] = ' ';
     }
 }
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types:
len
unsigned int

variable_types:
s
unsigned int

variable_types:
d
unsigned int


strnclr

decompiled_code:
__int64 __fastcall strnclr(const char *a1, unsigned int a2)
{
return strncpyclr((__int64)a1, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, unsigned int a2)
{
return func3((__int64)a1, a1, a2);
}

original_code:
void strnclr(char * src, unsigned int len){
 strncpyclr(src, (const char *) src, len);
}

canonical_original_code:
void strnclr(char *src, unsigned int len){
 strncpyclr(src, (char *) src, len);
}


original_code:
int myprint_percentage(char * result, unsigned short percentage){
  int cpt=0;
  if (percentage>999){
    error("Percentage",0);
  } else {
    if (percentage>99){
      result[cpt++]= '0' +percentage/100;
      percentage=percentage%100;
    }
    result[cpt++]='0' +percentage/10;
    result[cpt++]='0' +percentage%10;
    result[cpt++]='%';
    result[cpt]='\0';
  }
  return cpt;
}

canonical_original_code:
int myprint_percentage(char *result, unsigned short percentage){
  int cpt = 0;
  if (percentage>999){
    error("Percentage",0);
  } else {
    if (percentage>99){
      result[cpt++]= '0' +percentage/100;
      percentage=percentage%100;
    }
    result[cpt++]='0' +percentage/10;
    result[cpt++]='0' +percentage%10;
    result[cpt++]='%';
    result[cpt]='\0';
  }
  return cpt;
}

variable_types:
result
char *

variable_types:
percentage
unsigned short


decompiled_code:
__int64 __fastcall myprint_percentage_s(_BYTE *a1, unsigned __int16 a2)
{
int v2; // eax

v2 = myprint_percentage(a1, a2);
a1[v2] = 32;
a1[v2 + 1] = 0;
return (unsigned int)(v2 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1, unsigned __int16 a2)
{
int v2; // eax

v2 = func5(a1, a2);
a1[v2] = 32;
a1[v2 + 1] = 0;
return (unsigned int)(v2 + 1);
}

original_code:
int myprint_percentage_s(char * result, unsigned short percentage){
  int cpt;
  cpt=myprint_percentage(result, percentage);
  result[cpt++]=' ';
  result[cpt]='\0';
  return cpt;
}

canonical_original_code:
int myprint_percentage_s(char *result, unsigned short percentage){
  int cpt;
  cpt=myprint_percentage(result, percentage);
  result[cpt++]=' ';
  result[cpt]='\0';
  return cpt;
}

variable_types: cpt int


decompiled_code:
int __fastcall signal_install(struct sigaction *act, int sig, unsigned __int64 a3)
{
__sigset_t *v4; // rdi

v4 = &act->sa_mask;
v4[-1].__val[15] = a3;
LODWORD(v4[1].__val[0]) = 0x10000000;
sigemptyset(v4);
return sigaction(sig, act, 0LL);
}

canonical_decompiled_code:
int __fastcall func7(struct sigaction *act, int sig, unsigned __int64 a3)
{
__sigset_t *v4; // rdi

v4 = &act->sa_mask;
v4[-1].__val[15] = a3;
LODWORD(v4[1].__val[0]) = 0x10000000;
sigemptyset(v4);
return sigaction(sig, act, 0LL);
}

original_code:
void signal_install(struct sigaction * sa, int signum, handler_t * handler) {
  ((void) (0));
  ((void) (0));
  sa->__sigaction_handler.sa_handler = handler;
  sa->sa_flags=0x10000000;
  sigemptyset(&(sa->sa_mask));
  sigaction(signum, sa, (struct sigaction *)0);
}

canonical_original_code:
void signal_install(struct sigaction *sa, int signum, void (*handler)(int)) {
  ((void) (0));
  ((void) (0));
  sa->__sigaction_handler.sa_handler = handler;
  sa->sa_flags=0x10000000;
  sigemptyset(&(sa->sa_mask));
  sigaction(signum, sa, (struct sigaction *)0);
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); } *

variable_types: signum int

variable_types:
handler
void (*)(int)

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
int install_signals()
{
signal_install(&usr1, 10, (unsigned __int64)sigusr1_handler);
signal_install(&usr2, 12, (unsigned __int64)sigusr2_handler);
return signal_install(&cont, 18, (unsigned __int64)sigusr1_handler);
}

canonical_decompiled_code:
int func8()
{
func7(&usr1, 10, (unsigned __int64)sigusr1_handler);
func7(&usr2, 12, (unsigned __int64)sigusr2_handler);
return func7(&cont, 18, (unsigned __int64)sigusr1_handler);
}

original_code:
void install_signals(){
 signal_install(&usr1, 10, sigusr1_handler);
 signal_install(&usr2, 12, sigusr2_handler);
 signal_install(&cont, 18, sigusr1_handler);
}


battery

decompiled_code:
char *battery()
{
int v0; // eax
char *result; // rax
char *v2; // rbx
int v3; // eax

if ( time_cpt )
{
v0 = time_cpt + 1;
if ( time_cpt == 15 )
v0 = 0;
time_cpt = v0;
result = battery_result;
}
else
{
battery_result[0] = 0;
v2 = &battery_result[(int)calculate_battery(battery_result, "/sys/class/power_supply/BAT0/uevent")];
v3 = calculate_battery(v2, "/sys/class/power_supply/BAT1/uevent");
calculate_battery(&v2[v3], "/sys/class/power_supply/BAT2/uevent");
++time_cpt;
result = battery_result;
}
return result;
}

canonical_decompiled_code:
char *func1()
{
int v0; // eax
char *result; // rax
char *v2; // rbx
int v3; // eax

if ( time_cpt )
{
v0 = time_cpt + 1;
if ( time_cpt == 15 )
v0 = 0;
time_cpt = v0;
result = battery_result;
}
else
{
battery_result[0] = 0;
v2 = &battery_result[(int)func0(battery_result, "/sys/class/power_supply/BAT0/uevent")];
v3 = func0(v2, "/sys/class/power_supply/BAT1/uevent");
func0(&v2[v3], "/sys/class/power_supply/BAT2/uevent");
++time_cpt;
result = battery_result;
}
return result;
}

original_code:
char * battery(){
 char * ptr;
 if (time_cpt == 0){
  battery_result[0] = '\0';
  ptr = battery_result;
  ptr += calculate_battery(ptr, "/sys/class/power_supply/BAT0/uevent");
  ptr += calculate_battery(ptr, "/sys/class/power_supply/BAT1/uevent");
  ptr += calculate_battery(ptr, "/sys/class/power_supply/BAT2/uevent");
  ((void) (0));
 } else if (time_cpt == 15) {
  time_cpt = -1;
 }
 time_cpt++;
 return battery_result;
}

canonical_original_code:
char *battery(){
 char *ptr;
 if (time_cpt == 0){
  battery_result[0] = '\0';
  ptr = battery_result;
  ptr += calculate_battery(ptr, "/sys/class/power_supply/BAT0/uevent");
  ptr += calculate_battery(ptr, "/sys/class/power_supply/BAT1/uevent");
  ptr += calculate_battery(ptr, "/sys/class/power_supply/BAT2/uevent");
  ((void) (0));
 } else if (time_cpt == 15) {
  time_cpt = -1;
 }
 time_cpt++;
 return battery_result;
}

variable_types:
ptr
char *


decompiled_code:
const char *init_battery()
{
time_cpt = 0;
return "Battery ";
}

canonical_decompiled_code:
const char *func2()
{
time_cpt = 0;
return "Battery ";
}

original_code:
char * init_battery(char * UNUSED_conf_line __attribute__((__unused__))){
 time_cpt = 0;
 return "Battery ";
}

canonical_original_code:
char *init_battery(char *UNUSED_conf_line){
 time_cpt = 0;
 return "Battery ";
}


decompiled_code:
void exit_battery()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void exit_battery(){
}

canonical_original_code:
void exit_battery(){
}


cpu

decompiled_code:
__int16 *cpu()
{
__int16 *result; // rax
__int64 v1; // rax
float v2; // xmm0_4
int v3; // eax
char *v4; // rbp
__int64 v5; // rbx
int v6; // er12
float v7; // xmm0_4
__int64 v8; // rax
__int64 v9; // rcx

LOBYTE(cpu_result) = 0;
update_cpus();
if ( nb_cpu <= 0 )
return &cpu_result;
v1 = *(_QWORD *)cpus_news - *(_QWORD *)cpus;
if ( v1 < 0 )
{
v9 = v1 & 1 | ((*(_QWORD *)cpus_news - *(_QWORD *)cpus) >> 1);
v2 = (float)(int)v9 + (float)(int)v9;
}
else
{
v2 = (float)(int)v1;
}
v3 = myprint_percentage(
&cpu_result,
(unsigned __int16)(int)(float)((float)((float)(v2 / 200.0) / (float)nb_cpu) * (float)(int)proc_stat_unit));
if ( nb_cpu <= 1 )
{
*(__int16 *)((char *)&cpu_result + v3) = 32;
result = &cpu_result;
}
else
{
*((_BYTE *)&cpu_result + v3) = 40;
v4 = (char *)&cpu_result + v3 + 1;
v5 = 8LL;
v6 = 1;
do
{
v8 = *(_QWORD *)(cpus_news + v5) - *(_QWORD *)(cpus + v5);
if ( v8 >= 0 )
v7 = (float)(int)v8;
else
v7 = (float)(v8 & 1 | (unsigned int)((unsigned __int64)v8 >> 1))
+ (float)(v8 & 1 | (unsigned int)((unsigned __int64)v8 >> 1));
++v6;
v5 += 8LL;
v4 += (int)myprint_percentage(v4, (unsigned __int16)(int)(float)(v7 * 0.5));
}
while ( nb_cpu >= v6 );
result = &cpu_result;
strcpy(v4, ") ");
}
return result;
}

canonical_decompiled_code:
__int16 *func1()
{
__int16 *result; // rax
__int64 v1; // rax
float v2; // xmm0_4
int v3; // eax
char *v4; // rbp
__int64 v5; // rbx
int v6; // er12
float v7; // xmm0_4
__int64 v8; // rax
__int64 v9; // rcx

LOBYTE(cpu_result) = 0;
func0();
if ( nb_cpu <= 0 )
return &cpu_result;
v1 = *(_QWORD *)cpus_news - *(_QWORD *)cpus;
if ( v1 < 0 )
{
v9 = v1 & 1 | ((*(_QWORD *)cpus_news - *(_QWORD *)cpus) >> 1);
v2 = (float)(int)v9 + (float)(int)v9;
}
else
{
v2 = (float)(int)v1;
}
v3 = myprint_percentage(
&cpu_result,
(unsigned __int16)(int)(float)((float)((float)(v2 / 200.0) / (float)nb_cpu) * (float)(int)proc_stat_unit));
if ( nb_cpu <= 1 )
{
*(__int16 *)((char *)&cpu_result + v3) = 32;
result = &cpu_result;
}
else
{
*((_BYTE *)&cpu_result + v3) = 40;
v4 = (char *)&cpu_result + v3 + 1;
v5 = 8LL;
v6 = 1;
do
{
v8 = *(_QWORD *)(cpus_news + v5) - *(_QWORD *)(cpus + v5);
if ( v8 >= 0 )
v7 = (float)(int)v8;
else
v7 = (float)(v8 & 1 | (unsigned int)((unsigned __int64)v8 >> 1))
+ (float)(v8 & 1 | (unsigned int)((unsigned __int64)v8 >> 1));
++v6;
v5 += 8LL;
v4 += (int)myprint_percentage(v4, (unsigned __int16)(int)(float)(v7 * 0.5));
}
while ( nb_cpu >= v6 );
result = &cpu_result;
strcpy(v4, ") ");
}
return result;
}

original_code:
char * cpu(){
 char * ptr = cpu_result;
 ((void) (0));
 cpu_result[0] = '\0';
 ptr = cpu_result;
 update_cpus();
 ((void) (0));
 if(nb_cpu > 0){
  unsigned int percentage;
  percentage = (unsigned int) proc_stat_unit * ( ( (float)( (cpus_news[0] - cpus[0] )) / (2*100) ) / nb_cpu);
  ((void) (0));
  ptr += myprint_percentage(ptr, percentage);
  ((void) (0));
  if (nb_cpu > 1){
   int cpt;
   ((void) (0));
   (*(ptr++)) = '(';
   for(cpt = 1; cpt <= nb_cpu; cpt++){
    percentage = (unsigned int) (( (float)( (cpus_news[cpt] - cpus[cpt] )) / 2) );
    ((void) (0));
    ptr += myprint_percentage(ptr, percentage);
    ((void) (0));
   }
   ((void) (0));
   (*(ptr++)) = ')';
   (*(ptr++)) = ' ';
   (*ptr) = '\0';
  } else {
   ((void) (0));
   (*(ptr++)) = ' ';
   (*ptr) = '\0';
  }
 }
 return cpu_result;
}

canonical_original_code:
char *cpu(){
 char *ptr = cpu_result;
 ((void) (0));
 cpu_result[0] = '\0';
 ptr = cpu_result;
 update_cpus();
 ((void) (0));
 if(nb_cpu > 0){
  unsigned int percentage;
  percentage = (unsigned int) proc_stat_unit * ( ( (float)( (cpus_news[0] - cpus[0] )) / (2*100) ) / nb_cpu);
  ((void) (0));
  ptr += myprint_percentage(ptr, percentage);
  ((void) (0));
  if (nb_cpu > 1){
   int cpt;
   ((void) (0));
   (*(ptr++)) = '(';
   for(cpt = 1; cpt <= nb_cpu; cpt++){
    percentage = (unsigned int) (( (float)( (cpus_news[cpt] - cpus[cpt] )) / 2) );
    ((void) (0));
    ptr += myprint_percentage(ptr, percentage);
    ((void) (0));
   }
   ((void) (0));
   (*(ptr++)) = ')';
   (*(ptr++)) = ' ';
   (*ptr) = '\0';
  } else {
   ((void) (0));
   (*(ptr++)) = ' ';
   (*ptr) = '\0';
  }
 }
 return cpu_result;
}

variable_types:
percentage
unsigned int


decompiled_code:
void exit_cpu()
{
;
}

original_code:
void exit_cpu(){
}

canonical_original_code:
void exit_cpu(){
}


decompiled_code:
bool msg_queue_is_empty()
{
bool result; // al

result = 1;
if ( init )
result = qword_12A0 == 0;
return result;
}

canonical_decompiled_code:
bool func4()
{
bool result; // al

result = 1;
if ( init )
result = qword_12A0 == 0;
return result;
}

original_code:
_Bool msg_queue_is_empty(void)
{
  return !init || self.counter == 0;
}

canonical_original_code:
_Bool msg_queue_is_empty()
{
  return !init || self.counter == 0;
}


decompiled_code:
__int64 __fastcall msg_queue_push(char *src, const char *a2)
{
char *v2; // rax
char *v3; // rbp
size_t v4; // rax

v2 = push();
if ( !v2 )
return 0LL;
*v2 = 0;
v3 = v2;
if ( a2 )
{
strncpy(v2, a2, 0x100uLL);
v3[256] = 0;
}
v4 = strlen(v3);
strncat(v3, src, 256 - v4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *src, const char *a2)
{
char *v2; // rax
char *v3; // rbp
size_t v4; // rax

v2 = func1();
if ( !v2 )
return 0LL;
*v2 = 0;
v3 = v2;
if ( a2 )
{
strncpy(v2, a2, 0x100uLL);
v3[256] = 0;
}
v4 = strlen(v3);
strncat(v3, src, 256 - v4);
return 1LL;
}

original_code:
_Bool msg_queue_push(const char *str, const char *color)
{
  msg_t *msg = _push();
  ((void) (0));
  ((void) (0));
  if (!msg)
    return 0;
  msg->buffer[0] = '\0';
  if (color) {
    (void)strncpy(msg->buffer, color, 256);
    msg->buffer[256] = '\0';
  }
  (void)strncat(msg->buffer, str, 256 - strlen(msg->buffer));
  return 1;
}

canonical_original_code:
_Bool msg_queue_push(char *str, char *color)
{
  struct msg_t *msg = _push();
  ((void) (0));
  ((void) (0));
  if (!msg)
    return 0;
  msg->buffer[0] = '\0';
  if (color) {
    (void)strncpy(msg->buffer, color, 256);
    msg->buffer[256] = '\0';
  }
  (void)strncat(msg->buffer, str, 256 - strlen(msg->buffer));
  return 1;
}

variable_types:
str
char *

variable_types:
color
char *

variable_types:
msg
struct msg_t { char buffer[-1]; } *


decompiled_code:
__int64 msg_queue_vpush(__int64 a1, ...)
{
char *v1; // rdi
const char *v2; // r10
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

v1 = push();
result = 0LL;
if ( v1 )
{
va_start(arg, a1);
vsnprintf(v1, 0x100uLL, v2, arg);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func6(__int64 a1, ...)
{
char *v1; // rdi
const char *v2; // r10
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

v1 = func1();
result = 0LL;
if ( v1 )
{
va_start(arg, a1);
vsnprintf(v1, 0x100uLL, v2, arg);
result = 1LL;
}
return result;
}

original_code:
_Bool msg_queue_vpush(const char *format, ...)
{
  msg_t *msg = _push();
  va_list ap;
  ((void) (0));
  if (!msg)
    return 0;
  __builtin_va_start(ap,format);
  (void)vsnprintf(msg->buffer, 256, format, ap);
  __builtin_va_end(ap);
  return (1);
}

canonical_original_code:
_Bool msg_queue_vpush(char *format, ...)
{
  struct msg_t *msg = _push();
  __builtin_va_list ap;
  ((void) (0));
  if (!msg)
    return 0;
  __builtin_va_start(ap,format);
  (void)vsnprintf(msg->buffer, 256, format, ap);
  __builtin_va_end(ap);
  return (1);
}

variable_types:
format
char *


decompiled_code:
char *msg_queue_peek()
{
return peek();
}

canonical_decompiled_code:
char *func7()
{
return func2();
}

original_code:
const char *msg_queue_peek(void)
{
  msg_t *msg = _peek();
  return msg ? msg->buffer : ((void *)0);
}

canonical_original_code:
char *msg_queue_peek()
{
  struct msg_t *msg = _peek();
  return msg ? msg->buffer : ((void *)0);
}


decompiled_code:
__int64 msg_queue_pop()
{
return pop();
}

canonical_decompiled_code:
__int64 func8()
{
return func3();
}

original_code:
_Bool msg_queue_pop(void)
{
  return _pop();
}

canonical_original_code:
_Bool msg_queue_pop()
{
  return _pop();
}


decompiled_code:
const char *init_wifi()
{
wifi_result = 0;
return "Wifi ";
}

canonical_decompiled_code:
const char *func2()
{
wifi_result = 0;
return "Wifi ";
}

original_code:
char * init_wifi(char * UNUSED_conf_line __attribute__((__unused__))){
  wifi_result[0] = '\0';
  return "Wifi ";
}

canonical_original_code:
char *init_wifi(char *UNUSED_conf_line){
  wifi_result[0] = '\0';
  return "Wifi ";
}


decompiled_code:
void exit_wifi()
{
;
}

original_code:
void exit_wifi(){
}

canonical_original_code:
void exit_wifi(){
}


decompiled_code:
const char *init_reboot()
{
return "Reboot ";
}

canonical_decompiled_code:
const char *func1()
{
return "Reboot ";
}

original_code:
char * init_reboot(char * UNUSED_conf_line __attribute__((__unused__))){
 return "Reboot ";
}

canonical_original_code:
char *init_reboot(char *UNUSED_conf_line){
 return "Reboot ";
}


decompiled_code:
void exit_reboot()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void exit_reboot(){
}

canonical_original_code:
void exit_reboot(){
}


ram

decompiled_code:
char *ram()
{
__int64 v0; // rdx
__int64 v1; // rax
float v2; // xmm0_4
float v3; // xmm1_4

v0 = unk_138[4];
ram_result = 0;
v1 = v0 - unk_138[6] - unk_138[5] - unk_138[7];
if ( v1 < 0 )
{
v2 = (float)(v1 & 1 | (unsigned int)((unsigned __int64)v1 >> 1))
+ (float)(v1 & 1 | (unsigned int)((unsigned __int64)v1 >> 1));
if ( v0 >= 0 )
goto LABEL_3;
LABEL_6:
v3 = (float)(v0 & 1 | (unsigned int)((unsigned __int64)v0 >> 1))
+ (float)(v0 & 1 | (unsigned int)((unsigned __int64)v0 >> 1));
goto LABEL_4;
}
v2 = (float)(int)v1;
if ( v0 < 0 )
goto LABEL_6;
LABEL_3:
v3 = (float)(int)v0;
LABEL_4:
myprint_percentage_s(&ram_result, (unsigned __int16)(int)(float)(v2 / (float)(v3 / 100.0)));
return &ram_result;
}

canonical_decompiled_code:
char *func0()
{
__int64 v0; // rdx
__int64 v1; // rax
float v2; // xmm0_4
float v3; // xmm1_4

v0 = unk_138[4];
ram_result = 0;
v1 = v0 - unk_138[6] - unk_138[5] - unk_138[7];
if ( v1 < 0 )
{
v2 = (float)(v1 & 1 | (unsigned int)((unsigned __int64)v1 >> 1))
+ (float)(v1 & 1 | (unsigned int)((unsigned __int64)v1 >> 1));
if ( v0 >= 0 )
goto LABEL_3;
LABEL_6:
v3 = (float)(v0 & 1 | (unsigned int)((unsigned __int64)v0 >> 1))
+ (float)(v0 & 1 | (unsigned int)((unsigned __int64)v0 >> 1));
goto LABEL_4;
}
v2 = (float)(int)v1;
if ( v0 < 0 )
goto LABEL_6;
LABEL_3:
v3 = (float)(int)v0;
LABEL_4:
myprint_percentage_s(&ram_result, (unsigned __int16)(int)(float)(v2 / (float)(v3 / 100.0)));
return &ram_result;
}

original_code:
char * ram(){
 unsigned long int ram_used;
 ram_result[0]='\0';
 ram_used= si.totalram - si.freeram - si.sharedram - si.bufferram;
 ((void) (0));
 (void)myprint_percentage_s(ram_result, (int) ( ram_used / ( ((float)si.totalram) /100 )));
 return ram_result;
}

canonical_original_code:
char *ram(){
 unsigned long ram_used;
 ram_result[0]='\0';
 ram_used= si.totalram - si.freeram - si.sharedram - si.bufferram;
 ((void) (0));
 (void)myprint_percentage_s(ram_result, (int) ( ram_used / ( ((float)si.totalram) /100 )));
 return ram_result;
}


decompiled_code:
const char *init_ram()
{
return "Ram ";
}

canonical_decompiled_code:
const char *func1()
{
return "Ram ";
}

original_code:
char * init_ram(char * UNUSED_conf_line __attribute__((__unused__))){
 return "Ram ";
}

canonical_original_code:
char *init_ram(char *UNUSED_conf_line){
 return "Ram ";
}


decompiled_code:
void exit_ram()
{
;
}

original_code:
void exit_ram(){
}

canonical_original_code:
void exit_ram(){
}


users

decompiled_code:
char *users()
{
unsigned int v0; // er12
struct utmp *v1; // rax

v0 = 0;
setutent();
user_result = 0;
while ( 1 )
{
v1 = getutent();
if ( !v1 )
break;
v0 += v1->ut_type == 7;
}
snprintf(&user_result, 7uLL, "%d# ", v0);
endutent();
return &user_result;
}

canonical_decompiled_code:
char *func0()
{
unsigned int v0; // er12
struct utmp *v1; // rax

v0 = 0;
setutent();
user_result = 0;
while ( 1 )
{
v1 = getutent();
if ( !v1 )
break;
v0 += v1->ut_type == 7;
}
snprintf(&user_result, 7uLL, "%d# ", v0);
endutent();
return &user_result;
}

original_code:
char * users(){
 struct utmp * user;
 int nb_users;
 setutent();
 nb_users=0;
 user_result[0]='\0';
 while ((user=getutent()) != ((void *)0)) {
  if ((user->ut_type) == 7)
   nb_users++;
 }
 (void) snprintf(user_result, 7, "%d# ", nb_users);
 endutent();
 return user_result;
}

canonical_original_code:
char *users(){
 struct utmp *user;
 int nb_users;
 setutent();
 nb_users=0;
 user_result[0]='\0';
 while ((user=getutent()) != ((void *)0)) {
  if ((user->ut_type) == 7)
   nb_users++;
 }
 (void) snprintf(user_result, 7, "%d# ", nb_users);
 endutent();
 return user_result;
}

variable_types: struct utmp { short ut_type; int ut_pid; char ut_line[32]; char ut_id[4]; char ut_user[32]; char ut_host[256]; struct exit_status { short e_termination; short e_exit; } ut_exit; int ut_session; struct { int tv_sec; int tv_usec; } ut_tv; int ut_addr_v6[4]; char __glibc_reserved[20]; } *

user_defined_types: struct utmp { short ut_type; int ut_pid; char ut_line[32]; char ut_id[4]; char ut_user[32]; char ut_host[256]; struct exit_status ut_exit; int ut_session; struct { int tv_sec; int tv_usec; } ut_tv; int ut_addr_v6[4]; char __glibc_reserved[20]; }


decompiled_code:
const char *init_users()
{
return "Users ";
}

canonical_decompiled_code:
const char *func1()
{
return "Users ";
}

original_code:
char * init_users(char * UNUSED_conf_line __attribute__((__unused__))){
 return "Users ";
}

canonical_original_code:
char *init_users(char *UNUSED_conf_line){
 return "Users ";
}


decompiled_code:
void exit_users()
{
;
}

original_code:
void exit_users(){
}

canonical_original_code:
void exit_users(){
}


main

repo: monfort/ffTES

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int result; // eax
char v5[1024]; // [rsp+0h] [rbp-C08h] BYREF
char v6[1024]; // [rsp+400h] [rbp-808h] BYREF
char nptr[1032]; // [rsp+800h] [rbp-408h] BYREF

if ( argc <= 1 )
{
while ( (unsigned int)__isoc99_fscanf() == 3 )
{
handleInput(v5, v6, nptr);
if ( v3 >= 0.0 )
{
printf("%f\n", v3);
fflush(_bss_start);
}
}
result = 0;
}
else if ( argc == 4 )
{
handleInput((char *)argv[1], (char *)argv[2], (char *)argv[3]);
result = 1;
if ( v3 >= 0.0 )
{
printf("%f\n", v3);
result = 0;
}
}
else
{
printf("usage: %s hexsting1 hexstring2 bitcount\n", *argv);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int result; // eax
char v5[1024]; // [rsp+0h] [rbp-C08h] BYREF
char v6[1024]; // [rsp+400h] [rbp-808h] BYREF
char nptr[1032]; // [rsp+800h] [rbp-408h] BYREF

if ( argc <= 1 )
{
while ( (unsigned int)__isoc99_fscanf() == 3 )
{
func11(v5, v6, nptr);
if ( v3 >= 0.0 )
{
printf("%f\n", v3);
fflush(_bss_start);
}
}
result = 0;
}
else if ( argc == 4 )
{
func11((char *)argv[1], (char *)argv[2], (char *)argv[3]);
result = 1;
if ( v3 >= 0.0 )
{
printf("%f\n", v3);
result = 0;
}
}
else
{
printf("usage: %s hexsting1 hexstring2 bitcount\n", *argv);
result = 1;
}
return result;
}

original_code:
int main(int argc, const char **argv)
{
 int readStdIn = 1;
 if (argc > 1)
 {
  readStdIn = 0;
  if (argc != 4)
  {
   printf("usage: %s hexsting1 hexstring2 bitcount\n", argv[0]);
   return 1;
  }
 }
 if (!readStdIn)
 {
  double res = handleInput(argv[1], argv[2], argv[3]);
  if (res >= 0)
  {
   printf("%f\n", res);
   return 0;
  }
  return 1;
 }
 for (;;)
 {
  char a[1024],b[1024],c[1024];
  double res;
  if (fscanf(stdin, "%s %s %s", a, b, c) != 3)
   return 0;
  res = handleInput(a, b, c);
  if (res >= 0)
  {
   printf("%f\n", res);
   fflush(stdout);
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int readStdIn = 1;
 if (argc > 1)
 {
  readStdIn = 0;
  if (argc != 4)
  {
   printf("usage: %s hexsting1 hexstring2 bitcount\n", argv[0]);
   return 1;
  }
 }
 if (!readStdIn)
 {
  double res = handleInput(argv[1], argv[2], argv[3]);
  if (res >= 0)
  {
   printf("%f\n", res);
   return 0;
  }
  return 1;
 }
 for (;;)
 {
  char a[1024]; char b[1024]; char c[1024];
  double res;
  if (fscanf(stdin, "%s %s %s", a, b, c) != 3)
   return 0;
  res = handleInput(a, b, c);
  if (res >= 0)
  {
   printf("%f\n", res);
   fflush(stdout);
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: readStdIn int

variable_types: res double


hexToBin

decompiled_code:
__int64 __fastcall hexToBin(char a1)
{
if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(char)(a1 - 48);
if ( (unsigned __int8)(a1 - 65) <= 5u )
return (unsigned int)(char)(a1 - 55);
if ( (unsigned __int8)(a1 - 97) > 5u )
return 0xFFFFFFFFLL;
return (unsigned int)(char)(a1 - 87);
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(char)(a1 - 48);
if ( (unsigned __int8)(a1 - 65) <= 5u )
return (unsigned int)(char)(a1 - 55);
if ( (unsigned __int8)(a1 - 97) > 5u )
return 0xFFFFFFFFLL;
return (unsigned int)(char)(a1 - 87);
}

original_code:
int hexToBin(char hex)
{
 if (hex >= '0' && hex <= '9')
  return hex - '0';
 else if (hex >= 'A' && hex <= 'F')
  return hex - 'A' + 10;
 else if (hex >= 'a' && hex <= 'f')
  return hex - 'a' + 10;
 else
  return -1;
}

variable_types: hex char


hexStringToBin

decompiled_code:
__int64 __fastcall hexStringToBin(__int64 a1, char *a2)
{
char v2; // di
int v3; // eax
char v4; // dl
_BYTE *v5; // rcx
int v6; // eax
_BYTE *v7; // rcx

v2 = *a2;
if ( !*a2 )
return 1LL;
while ( 1 )
{
v6 = hexToBin(v2);
if ( v6 < 0 )
break;
*v7 = 16 * v6;
if ( !a2[1] )
return 1LL;
v3 = hexToBin(a2[1]);
if ( v3 < 0 )
break;
a2 += 2;
*v5 = v4 | v3;
v2 = *a2;
if ( !*a2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, char *a2)
{
char v2; // di
int v3; // eax
char v4; // dl
_BYTE *v5; // rcx
int v6; // eax
_BYTE *v7; // rcx

v2 = *a2;
if ( !*a2 )
return 1LL;
while ( 1 )
{
v6 = func7(v2);
if ( v6 < 0 )
break;
*v7 = 16 * v6;
if ( !a2[1] )
return 1LL;
v3 = func7(a2[1]);
if ( v3 < 0 )
break;
a2 += 2;
*v5 = v4 | v3;
v2 = *a2;
if ( !*a2 )
return 1LL;
}
return 0LL;
}

original_code:
int hexStringToBin(unsigned char *binArray, const char *hexString)
{
 for (;*hexString; binArray++)
 {
  int x = hexToBin(*hexString);
  if (x < 0)
   return 0;
  *binArray = x << 4;
  hexString++;
  if (!*hexString)
   break;
  x = hexToBin(*hexString);
  if (x < 0)
   return 0;
  *binArray |= x;
  hexString++;
 }
 return 1;
}

canonical_original_code:
int hexStringToBin(unsigned char *binArray, char *hexString)
{
 for (;*hexString; binArray++)
 {
  int x = hexToBin(*hexString);
  if (x < 0)
   return 0;
  *binArray = x << 4;
  hexString++;
  if (!*hexString)
   break;
  x = hexToBin(*hexString);
  if (x < 0)
   return 0;
  *binArray |= x;
  hexString++;
 }
 return 1;
}

variable_types:
binArray
unsigned char *

variable_types:
hexString
char *

variable_types: x int


normalizedHammingDistance

original_code:
double normalizedHammingDistance(const unsigned char *a, const unsigned char *b, unsigned int bitCount)
{
 unsigned int offset = 0;
 unsigned int dist = 0;
 unsigned int *pa = (unsigned int*)a;
 unsigned int *pb = (unsigned int*)b;
 unsigned int bytesLeft = bitCount/8;
 unsigned int xa = 0;
 unsigned int xb = 0;
 unsigned int remainderBits = bitCount&7;
 ((void) sizeof ((sizeof(unsigned int) == 4) ? 1 : 0), __extension__ ({ if (sizeof(unsigned int) == 4) ; else __assert_fail ("sizeof(unsigned int) == 4", "demo.c", 75, __extension__ __PRETTY_FUNCTION__); }));
 while (bytesLeft >= 4)
 {
  unsigned int wa = *pa++;
  unsigned int wb = *pb++;
  dist += ones32(wa ^ wb);
  offset += 4;
  bytesLeft -= 4;
 }
 memcpy(&xa, a+offset, bytesLeft + (remainderBits?1:0));
 memcpy(&xb, b+offset, bytesLeft + (remainderBits?1:0));
 if (remainderBits)
 {
  ((unsigned char*)&xa)[bytesLeft] &= (1 << remainderBits)-1;
  ((unsigned char*)&xb)[bytesLeft] &= (1 << remainderBits)-1;
 }
 dist += ones32(xa ^ xb);
 return (double)dist / (double)bitCount;
}

canonical_original_code:
double normalizedHammingDistance(unsigned char *a, unsigned char *b, unsigned int bitCount)
{
 unsigned int offset = 0;
 unsigned int dist = 0;
 unsigned int *pa = (unsigned int*)a;
 unsigned int *pb = (unsigned int*)b;
 unsigned int bytesLeft = bitCount/8;
 unsigned int xa = 0;
 unsigned int xb = 0;
 unsigned int remainderBits = bitCount&7;
 ((void) sizeof ((sizeof(unsigned int) == 4) ? 1 : 0), __extension__ ({ if (sizeof(unsigned int) == 4) ; else __assert_fail ("sizeof(unsigned int) == 4", "demo.c", 75, __extension__ __PRETTY_FUNCTION__); }));
 while (bytesLeft >= 4)
 {
  unsigned int wa = *pa++;
  unsigned int wb = *pb++;
  dist += ones32(wa ^ wb);
  offset += 4;
  bytesLeft -= 4;
 }
 memcpy(&xa, a+offset, bytesLeft + (remainderBits?1:0));
 memcpy(&xb, b+offset, bytesLeft + (remainderBits?1:0));
 if (remainderBits)
 {
  ((unsigned char *)&xa)[bytesLeft] &= (1 << remainderBits)-1;
  ((unsigned char *)&xb)[bytesLeft] &= (1 << remainderBits)-1;
 }
 dist += ones32(xa ^ xb);
 return (double)dist / (double)bitCount;
}

variable_types:
a
unsigned char *

variable_types:
b
unsigned char *

variable_types:
bitCount
unsigned int

variable_types:
offset
unsigned int

variable_types:
dist
unsigned int

variable_types:
pa
unsigned int *

variable_types:
pb
unsigned int *

variable_types:
bytesLeft
unsigned int

variable_types:
xa
unsigned int

variable_types:
xb
unsigned int

variable_types:
remainderBits
unsigned int

variable_types:
wa
unsigned int

variable_types:
wb
unsigned int

return_type: double


handleInput

decompiled_code:
double __fastcall handleInput(char *s, char *a2, char *nptr)
{
int v4; // eax
signed int v5; // er14
size_t v6; // rax
int v7; // ebx
void *v8; // rsp
size_t v9; // rax
int v10; // er12
void *v11; // rsp
void *v12; // rax
_DWORD *v13; // r8
int v14; // ebx
int v15; // er12
unsigned int v16; // edx
double result; // xmm0_8
_DWORD v18[3]; // [rsp+0h] [rbp-30h] BYREF

v4 = atoi(nptr);
if ( v4 )
{
v5 = v4;
v6 = strlen(s);
v7 = (v6 & 1) + (v6 >> 1);
v8 = alloca(v7 + 8LL);
memset(v18, 0, v7);
if ( (unsigned int)hexStringToBin((__int64)v18, s) )
{
v9 = strlen(a2);
v10 = (v9 & 1) + (v9 >> 1);
v11 = alloca(v10 + 8LL);
v12 = memset(v18, 0, v10);
if ( (unsigned int)hexStringToBin((__int64)v12, a2) )
{
v14 = 8 * v7;
if ( v14 <= v5 )
v5 = v14;
v15 = 8 * v10;
v16 = v5;
if ( v15 <= v5 )
v16 = v15;
result = normalizedHammingDistance(v18, v13, v16);
}
else
{
fprintf(stderr, "invalid hex string %s\n", a2);
result = -1.0;
}
}
else
{
fprintf(stderr, "invalid hex string %s\n", s);
result = -1.0;
}
}
else
{
fprintf(stderr, "invalid bitcount %s\n", nptr);
result = -1.0;
}
return result;
}

canonical_decompiled_code:
double __fastcall func11(char *s, char *a2, char *nptr)
{
int v4; // eax
signed int v5; // er14
size_t v6; // rax
int v7; // ebx
void *v8; // rsp
size_t v9; // rax
int v10; // er12
void *v11; // rsp
void *v12; // rax
_DWORD *v13; // r8
int v14; // ebx
int v15; // er12
unsigned int v16; // edx
double result; // xmm0_8
_DWORD v18[3]; // [rsp+0h] [rbp-30h] BYREF

v4 = atoi(nptr);
if ( v4 )
{
v5 = v4;
v6 = strlen(s);
v7 = (v6 & 1) + (v6 >> 1);
v8 = alloca(v7 + 8LL);
memset(v18, 0, v7);
if ( (unsigned int)func8((__int64)v18, s) )
{
v9 = strlen(a2);
v10 = (v9 & 1) + (v9 >> 1);
v11 = alloca(v10 + 8LL);
v12 = memset(v18, 0, v10);
if ( (unsigned int)func8((__int64)v12, a2) )
{
v14 = 8 * v7;
if ( v14 <= v5 )
v5 = v14;
v15 = 8 * v10;
v16 = v5;
if ( v15 <= v5 )
v16 = v15;
result = func10(v18, v13, v16);
}
else
{
fprintf(stderr, "invalid hex string %s\n", a2);
result = -1.0;
}
}
else
{
fprintf(stderr, "invalid hex string %s\n", s);
result = -1.0;
}
}
else
{
fprintf(stderr, "invalid bitcount %s\n", nptr);
result = -1.0;
}
return result;
}

original_code:
double handleInput(const char* a, const char* b, const char *c)
{
 int bitcount,len;
 unsigned char *str1,*str2;
 bitcount = atoi(c);
 if (bitcount == 0)
 {
  fprintf(stderr, "invalid bitcount %s\n", c);
  return -1;
 }
 len = strlen(a)/2 + strlen(a)%2;
 bitcount = ((bitcount)<(len*8)?(bitcount):(len*8));
 str1 = __builtin_alloca (len);
 memset(str1, 0, len);
 if (!hexStringToBin(str1, a))
 {
  fprintf(stderr, "invalid hex string %s\n", a);
  return -1;
 }
 len = strlen(b)/2 + strlen(b)%2;
 bitcount = ((bitcount)<(len*8)?(bitcount):(len*8));
 str2 = __builtin_alloca (len);
 memset(str2, 0, len);
 if (!hexStringToBin(str2, b))
 {
  fprintf(stderr, "invalid hex string %s\n", b);
  return -1;
 }
 return normalizedHammingDistance(str1, str2, bitcount);
}

canonical_original_code:
double handleInput(char *a, char *b, char *c)
{
 int bitcount; int len;
 unsigned char *str1; unsigned char *str2;
 bitcount = atoi(c);
 if (bitcount == 0)
 {
  fprintf(stderr, "invalid bitcount %s\n", c);
  return -1;
 }
 len = strlen(a)/2 + strlen(a)%2;
 bitcount = ((bitcount)<(len*8)?(bitcount):(len*8));
 str1 = __builtin_alloca (len);
 memset(str1, 0, len);
 if (!hexStringToBin(str1, a))
 {
  fprintf(stderr, "invalid hex string %s\n", a);
  return -1;
 }
 len = strlen(b)/2 + strlen(b)%2;
 bitcount = ((bitcount)<(len*8)?(bitcount):(len*8));
 str2 = __builtin_alloca (len);
 memset(str2, 0, len);
 if (!hexStringToBin(str2, b))
 {
  fprintf(stderr, "invalid hex string %s\n", b);
  return -1;
 }
 return normalizedHammingDistance(str1, str2, bitcount);
}

variable_types:
a
char *

variable_types:
b
char *

variable_types:
c
char *

variable_types: bitcount int

variable_types: len int


repo: monich/push-receive

decompiled_code:
void __fastcall __noreturn err_exit(const char *a1, __int64 a2)
{
if ( a2 )
{
printf("%s: %s\n", a1, *(const char **)(a2 + 8));
g_error_free(a2);
}
else
{
puts(a1);
}
exit((int)push_notification_agent_release + 1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1, __int64 a2)
{
if ( a2 )
{
printf("%s: %s\n", a1, *(const char **)(a2 + 8));
g_error_free(a2);
}
else
{
puts(a1);
}
exit((int)push_notification_agent_release + 1);
}

original_code:
static void
err_exit(
    const char* prefix,
    GError* error)
{
    if (error) {
        printf("%s: %s\n", prefix, error->message);
        g_error_free(error);
    } else {
        printf("%s\n", prefix);
    }
    exit(1);
}

canonical_original_code:
static void err_exit(char *prefix, struct _GError *error)
{
    if (error) {
        printf("%s: %s\n", prefix, error->message);
        g_error_free(error);
    } else {
        printf("%s\n", prefix);
    }
    exit(1);
}

variable_types:
prefix
char *

variable_types: struct _GError { unsigned int domain; int code; char *message; } *


repo: moonranger/breeze

decompiled_code:
__int64 __fastcall ioloop_destroy(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

original_code:
int ioloop_destroy(ioloop_t *loop) {
    free(loop->handlers);
    free(loop);
    return 0;
}

canonical_original_code:
int ioloop_destroy(struct _ioloop *loop) {
    free(loop->handlers);
    free(loop);
    return 0;
}

variable_types: struct _ioloop { int epoll_fd; int state; struct _io_callback { void (*callback)(struct _ioloop *loop, int fd, unsigned int events, void *args); void *args; } *handlers; struct _callback_chain { struct _callback { void (*callback)(struct _ioloop *loop, void *args); void *args; } callbacks[10000]; int callback_num; } callback_chains[2]; int callback_chain_idx; } *

user_defined_types: struct _ioloop { int epoll_fd; int state; struct _io_callback *handlers; struct _callback_chain callback_chains[2]; int callback_chain_idx; }

user_defined_types: struct _callback_chain { struct _callback callbacks[10000]; int callback_num; }


decompiled_code:
__int64 __fastcall ioloop_add_handler(__int64 a1, int a2, int a3, __int64 a4, __int64 a5)
{
int v6; // edi
unsigned int v9; // er12
_QWORD *v10; // rbx
struct epoll_event event; // [rsp+4h] [rbp-34h] BYREF

if ( a4 )
{
v6 = *(_DWORD *)a1;
event.events = a3 | 0x80000000;
event.data.fd = a2;
v9 = epoll_ctl(v6, 1, a2, &event);
if ( v9 == -1 )
{
logging(3LL, "ioloop.c", 108LL, "Error adding fd to epoll");
}
else
{
v10 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL * a2);
v9 = 0;
*v10 = a4;
v10[1] = a5;
}
}
else
{
v9 = -1;
logging(3LL, "ioloop.c", 101LL, "Handler should not be NULL!");
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int a3, __int64 a4, __int64 a5)
{
int v6; // edi
unsigned int v9; // er12
_QWORD *v10; // rbx
struct epoll_event event; // [rsp+4h] [rbp-34h] BYREF

if ( a4 )
{
v6 = *(_DWORD *)a1;
event.events = a3 | 0x80000000;
event.data.fd = a2;
v9 = epoll_ctl(v6, 1, a2, &event);
if ( v9 == -1 )
{
logging(3LL, "ioloop.c", 108LL, "Error adding fd to epoll");
}
else
{
v10 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL * a2);
v9 = 0;
*v10 = a4;
v10[1] = a5;
}
}
else
{
v9 = -1;
logging(3LL, "ioloop.c", 101LL, "Handler should not be NULL!");
}
return v9;
}

original_code:
int ioloop_add_handler(ioloop_t *loop,
                       int fd,
                       unsigned int events,
                       io_handler handler,
                       void *args) {
    struct epoll_event ev;
    if (handler == ((void *)0)) {
        logging(ERROR, "ioloop.c", 101, "Handler should not be NULL!");
        return -1;
    }
    ev.data.fd = fd;
    ev.events = events | EPOLLET;
    if (epoll_ctl(loop->epoll_fd, 1, fd, &ev) == -1) {
        logging(ERROR, "ioloop.c", 108, "Error adding fd to epoll");
        return -1;
    }
    loop->handlers[fd].callback = handler;
    loop->handlers[fd].args = args;
    return 0;
}

canonical_original_code:
int ioloop_add_handler(struct _ioloop *loop, int fd, unsigned int events, void (*handler)(struct _ioloop *loop, int fd, unsigned int events, void *args), void *args) {
    struct epoll_event ev;
    if (handler == ((void *)0)) {
        logging(ERROR, "ioloop.c", 101, "Handler should not be NULL!");
        return -1;
    }
    ev.data.fd = fd;
    ev.events = events | EPOLLET;
    if (epoll_ctl(loop->epoll_fd, 1, fd, &ev) == -1) {
        logging(ERROR, "ioloop.c", 108, "Error adding fd to epoll");
        return -1;
    }
    loop->handlers[fd].callback = handler;
    loop->handlers[fd].args = args;
    return 0;
}

variable_types: fd int

variable_types:
events
unsigned int

variable_types: void (*)(struct _ioloop *loop, int fd, unsigned int events, void *args)

variable_types:
args
void *

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; }

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }

user_defined_types: struct _io_callback { void (*callback)(struct _ioloop *loop, int fd, unsigned int events, void *args); void *args; }

user_defined_types: struct _callback { void (*callback)(struct _ioloop *loop, void *args); void *args; }


decompiled_code:
__int64 __fastcall ioloop_update_handler(int *a1, int a2, uint32_t a3)
{
int v3; // edi
unsigned int v4; // er12
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

v3 = *a1;
event.data.fd = a2;
event.events = a3;
if ( epoll_ctl(v3, 3, a2, &event) != -1 )
return 0;
v4 = -1;
logging(3LL, "ioloop.c", 123LL, "Error modifying epoll events");
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, int a2, uint32_t a3)
{
int v3; // edi
unsigned int v4; // er12
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

v3 = *a1;
event.data.fd = a2;
event.events = a3;
if ( epoll_ctl(v3, 3, a2, &event) != -1 )
return 0;
v4 = -1;
logging(3LL, "ioloop.c", 123LL, "Error modifying epoll events");
return v4;
}

original_code:
int ioloop_update_handler(ioloop_t *loop, int fd, unsigned int events) {
    struct epoll_event ev;
    ev.data.fd = fd;
    ev.events = events;
    if (epoll_ctl(loop->epoll_fd, 3, fd, &ev) == -1) {
        logging(ERROR, "ioloop.c", 123, "Error modifying epoll events");
        return -1;
    }
    return 0;
}

canonical_original_code:
int ioloop_update_handler(struct _ioloop *loop, int fd, unsigned int events) {
    struct epoll_event ev;
    ev.data.fd = fd;
    ev.events = events;
    if (epoll_ctl(loop->epoll_fd, 3, fd, &ev) == -1) {
        logging(ERROR, "ioloop.c", 123, "Error modifying epoll events");
        return -1;
    }
    return 0;
}

user_defined_types: union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; }


decompiled_code:
__int64 __fastcall ioloop_remove_handler(__int64 a1, int a2)
{
int v3; // edi
__int64 *v4; // rax
__int64 v5; // r13

logging(0LL, "ioloop.c", 134LL, "Removing handler for fd %d", (unsigned int)a2);
v3 = *(_DWORD *)a1;
v4 = (__int64 *)(*(_QWORD *)(a1 + 8) + 16LL * a2);
v5 = *v4;
v4[1] = 0LL;
*v4 = 0LL;
if ( epoll_ctl(v3, 2, a2, 0LL) < 0 )
logging(3LL, "ioloop.c", 140LL, "Error removing fd from epoll");
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
int v3; // edi
__int64 *v4; // rax
__int64 v5; // r13

logging(0LL, "ioloop.c", 134LL, "Removing handler for fd %d", (unsigned int)a2);
v3 = *(_DWORD *)a1;
v4 = (__int64 *)(*(_QWORD *)(a1 + 8) + 16LL * a2);
v5 = *v4;
v4[1] = 0LL;
*v4 = 0LL;
if ( epoll_ctl(v3, 2, a2, 0LL) < 0 )
logging(3LL, "ioloop.c", 140LL, "Error removing fd from epoll");
return v5;
}

original_code:
io_handler ioloop_remove_handler(ioloop_t *loop, int fd) {
    int res;
    io_handler handler;
    logging(DEBUG, "ioloop.c", 134, "Removing handler for fd %d", fd);
    handler = loop->handlers[fd].callback;
    loop->handlers[fd].callback = ((void *)0);
    loop->handlers[fd].args = ((void *)0);
    res = epoll_ctl(loop->epoll_fd, 2, fd, ((void *)0));
    if (res < 0) {
        logging(ERROR, "ioloop.c", 140, "Error removing fd from epoll");
    }
    return handler;
}

canonical_original_code:
void (*ioloop_remove_handler(struct _ioloop *loop, int fd))(struct _ioloop *loop, int fd, unsigned int events, void *args) {
    int res;
    void (*handler)(struct _ioloop *loop, int fd, unsigned int events, void *args);
    logging(DEBUG, "ioloop.c", 134, "Removing handler for fd %d", fd);
    handler = loop->handlers[fd].callback;
    loop->handlers[fd].callback = ((void *)0);
    loop->handlers[fd].args = ((void *)0);
    res = epoll_ctl(loop->epoll_fd, 2, fd, ((void *)0));
    if (res < 0) {
        logging(ERROR, "ioloop.c", 140, "Error removing fd from epoll");
    }
    return handler;
}

variable_types:
loop
struct _ioloop *

variable_types: res int

variable_types: void (*)(struct _ioloop { int epoll_fd; int state; struct _io_callback { void (*callback)(struct _ioloop *loop, int fd, unsigned int events, void *args); void *args; } *handlers; struct _callback_chain { struct _callback { void (*callback)(struct _ioloop *loop, void *args); void *args; } callbacks[10000]; int callback_num; } callback_chains[2]; int callback_chain_idx; } *loop, int fd, unsigned int events, void *args)


original_code:
int ioloop_start(ioloop_t *loop) {
    struct epoll_event events[1024];
    struct _callback_chain *current_chain;
    int epoll_fd, nfds, i, fd, epoll_timeout;
    io_handler handler;
    void *args;
    if (loop->state != INITIALIZED) {
        logging(ERROR, "ioloop.c", 157, "Could not restart an IO loop");
        return -1;
    }
    epoll_fd = loop->epoll_fd;
    loop->state = RUNNING;
    while (loop->state == RUNNING) {
        current_chain = loop->callback_chains + loop->callback_chain_idx;
        if (current_chain->callback_num > 0) {
            loop->callback_chain_idx = (loop->callback_chain_idx + 1) % 2;
            for (i = 0; i < current_chain->callback_num; i++) {
                current_chain->callbacks[i].callback(loop, current_chain->callbacks[i].args);
            }
            current_chain->callback_num = 0;
        }
        epoll_timeout = 100;
        if (loop->callback_chains[loop->callback_chain_idx].callback_num > 0) {
            epoll_timeout = 0;
        }
        nfds = epoll_wait(epoll_fd, events, 1024, epoll_timeout);
        if (nfds == -1) {
            logging(ERROR, "ioloop.c", 181, "epoll_wait");
            continue;
        }
        for (i = 0; i < nfds; i++) {
            fd = events[i].data.fd;
            handler = loop->handlers[fd].callback;
            args = loop->handlers[fd].args;
            if (handler == ((void *)0)) {
                continue;
            }
            handler(loop, fd, events[i].events, args);
        }
    }
    close(epoll_fd);
    return 0;
}

canonical_original_code:
int ioloop_start(struct _ioloop *loop) {
    struct epoll_event events[1024];
    struct _callback_chain *current_chain;
    int epoll_fd; int nfds; int i; int fd; int epoll_timeout;
    void (*handler)(struct _ioloop *loop, int fd, unsigned int events, void *args);
    void *args;
    if (loop->state != INITIALIZED) {
        logging(ERROR, "ioloop.c", 157, "Could not restart an IO loop");
        return -1;
    }
    epoll_fd = loop->epoll_fd;
    loop->state = RUNNING;
    while (loop->state == RUNNING) {
        current_chain = loop->callback_chains + loop->callback_chain_idx;
        if (current_chain->callback_num > 0) {
            loop->callback_chain_idx = (loop->callback_chain_idx + 1) % 2;
            for (i = 0; i < current_chain->callback_num; i++) {
                current_chain->callbacks[i].callback(loop, current_chain->callbacks[i].args);
            }
            current_chain->callback_num = 0;
        }
        epoll_timeout = 100;
        if (loop->callback_chains[loop->callback_chain_idx].callback_num > 0) {
            epoll_timeout = 0;
        }
        nfds = epoll_wait(epoll_fd, events, 1024, epoll_timeout);
        if (nfds == -1) {
            logging(ERROR, "ioloop.c", 181, "epoll_wait");
            continue;
        }
        for (i = 0; i < nfds; i++) {
            fd = events[i].data.fd;
            handler = loop->handlers[fd].callback;
            args = loop->handlers[fd].args;
            if (handler == ((void *)0)) {
                continue;
            }
            handler(loop, fd, events[i].events, args);
        }
    }
    close(epoll_fd);
    return 0;
}

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } [1024]

variable_types: struct _callback_chain { struct _callback { void (*callback)(struct _ioloop { int epoll_fd; int state; struct _io_callback { void (*callback)(struct _ioloop *loop, int fd, unsigned int events, void *args); void *args; } *handlers; struct _callback_chain callback_chains[2]; int callback_chain_idx; } *loop, void *args); void *args; } callbacks[10000]; int callback_num; } *

variable_types: nfds int

variable_types: i int


decompiled_code:
__int64 __fastcall ioloop_stop(__int64 a1)
{
*(_DWORD *)(a1 + 4) = 2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
*(_DWORD *)(a1 + 4) = 2;
return 0LL;
}

original_code:
int ioloop_stop(ioloop_t *loop) {
    loop->state = STOPPED;
    return 0;
}

canonical_original_code:
int ioloop_stop(struct _ioloop *loop) {
    loop->state = STOPPED;
    return 0;
}


original_code:
int ioloop_add_callback(ioloop_t *loop, callback_handler handler, void *args) {
    struct _callback_chain *current_chain = loop->callback_chains + loop->callback_chain_idx;
    int n = current_chain->callback_num;
    if (n >= 10000) {
        return -1;
    }
    current_chain->callbacks[n].callback = handler;
    current_chain->callbacks[n].args = args;
    current_chain->callback_num ++;
    return 0;
}

canonical_original_code:
int ioloop_add_callback(struct _ioloop *loop, void (*handler)(struct _ioloop *loop, void *args), void *args) {
    struct _callback_chain *current_chain = loop->callback_chains + loop->callback_chain_idx;
    int n = current_chain->callback_num;
    if (n >= 10000) {
        return -1;
    }
    current_chain->callbacks[n].callback = handler;
    current_chain->callbacks[n].args = args;
    current_chain->callback_num ++;
    return 0;
}

variable_types: void (*)(struct _ioloop *loop, void *args)

variable_types: n int


decompiled_code:
__int64 __fastcall set_nonblocking(int fd)
{
int v1; // eax

v1 = fcntl(fd, 3);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
BYTE1(v1) |= 8u;
return (unsigned int)(fcntl(fd, 4, (unsigned int)v1) >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd)
{
int v1; // eax

v1 = fcntl(fd, 3);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
BYTE1(v1) |= 8u;
return (unsigned int)(fcntl(fd, 4, (unsigned int)v1) >> 31);
}

original_code:
int set_nonblocking(int sockfd) {
    int opts;
    opts = fcntl(sockfd, 3);
    if (opts < 0)
        return -1;
    opts |= 04000;
    if (fcntl(sockfd, 4, opts) < 0)
        return -1;
    return 0;
}

variable_types: sockfd int

variable_types: opts int


decompiled_code:
__int64 __fastcall buffer_destroy(void *a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
free(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
free(a1);
return 0LL;
}

original_code:
int buffer_destroy(buffer_t *buf) {
    if (buf == ((void *)0))
        return -1;
    free(buf);
    return 0;
}

canonical_original_code:
int buffer_destroy(struct _buffer *buf) {
    if (buf == ((void *)0))
        return -1;
    free(buf);
    return 0;
}

variable_types: struct _buffer { unsigned char *data; unsigned long size; unsigned long capacity; int head; int tail; } *


decompiled_code:
_BOOL8 __fastcall buffer_is_full(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == *(_QWORD *)(a1 + 16);
}

original_code:
int buffer_is_full(buffer_t *buf) {
    return buf->size == buf->capacity;
}

canonical_original_code:
int buffer_is_full(struct _buffer *buf) {
    return buf->size == buf->capacity;
}

user_defined_types: struct _buffer { unsigned char *data; unsigned long size; unsigned long capacity; int head; int tail; }


decompiled_code:
_BOOL8 __fastcall buffer_is_empty(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == 0LL;
}

original_code:
int buffer_is_empty(buffer_t *buf) {
    return buf->size == 0;
}

canonical_original_code:
int buffer_is_empty(struct _buffer *buf) {
    return buf->size == 0;
}


decompiled_code:
__int64 __fastcall buffer_put(__int64 a1, char *a2, size_t a3)
{
size_t v4; // rbx
unsigned int v5; // er14
size_t v6; // rbp

if ( *(_QWORD *)(a1 + 16) - *(_QWORD *)(a1 + 8) < a3 )
return (unsigned int)-1;
v4 = *(_QWORD *)(a1 + 16) - *(int *)(a1 + 28);
if ( v4 > a3 )
v4 = a3;
v5 = 0;
do_put(a1, a2, v4);
v6 = a3 - v4;
if ( !v6 )
return v5;
do_put(a1, &a2[v4], v6);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char *a2, size_t a3)
{
size_t v4; // rbx
unsigned int v5; // er14
size_t v6; // rbp

if ( *(_QWORD *)(a1 + 16) - *(_QWORD *)(a1 + 8) < a3 )
return (unsigned int)-1;
v4 = *(_QWORD *)(a1 + 16) - *(int *)(a1 + 28);
if ( v4 > a3 )
v4 = a3;
v5 = 0;
func1(a1, a2, v4);
v6 = a3 - v4;
if ( !v6 )
return v5;
func1(a1, &a2[v4], v6);
return 0LL;
}

original_code:
int buffer_put(buffer_t *buf, void *data, size_t len) {
    size_t cap;
    size_t write_len;
    byte_t *_data = (byte_t*) data;
    cap = buf->capacity - buf->size;
    if (len > cap) {
        return -1;
    }
    write_len = ((len) < (buf->capacity - buf->tail) ? (len) : (buf->capacity - buf->tail));
    _do_put(buf, _data, write_len);
    _data += write_len;
    write_len = len - write_len;
    if (write_len > 0) {
        _do_put(buf, _data, write_len);
    }
    return 0;
}

canonical_original_code:
int buffer_put(struct _buffer *buf, void *data, unsigned long len) {
    unsigned long cap;
    unsigned long write_len;
    unsigned char *_data = (byte_t*) data;
    cap = buf->capacity - buf->size;
    if (len > cap) {
        return -1;
    }
    write_len = ((len) < (buf->capacity - buf->tail) ? (len) : (buf->capacity - buf->tail));
    _do_put(buf, _data, write_len);
    _data += write_len;
    write_len = len - write_len;
    if (write_len > 0) {
        _do_put(buf, _data, write_len);
    }
    return 0;
}

variable_types:
data
void *

variable_types:
len
unsigned long

variable_types:
cap
unsigned long


original_code:
ssize_t buffer_fill(buffer_t *buf, int fd) {
    ssize_t n, iovcnt;
    struct iovec iov[2];
    iov[0].iov_base = buf->data + buf->tail;
    if (buf->head > buf->tail) {
        iov[0].iov_len = buf->head - buf->tail;
        iovcnt = 1;
    } else {
        iov[0].iov_len = buf->capacity - buf->tail;
        iov[1].iov_base = buf->data;
        iov[1].iov_len = buf->head;
        iovcnt = 2;
    }
    n = readv(fd, iov, iovcnt);
    if (n < 0) {
        if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
            return 0;
        }
        return -1;
    } else if (n == 0) {
        return -2;
    }
    buf->size += n;
    buf->tail = (buf->tail + n) % buf->capacity;
    return n;
}

canonical_original_code:
long buffer_fill(struct _buffer *buf, int fd) {
    long n; long iovcnt;
    struct iovec iov[2];
    iov[0].iov_base = buf->data + buf->tail;
    if (buf->head > buf->tail) {
        iov[0].iov_len = buf->head - buf->tail;
        iovcnt = 1;
    } else {
        iov[0].iov_len = buf->capacity - buf->tail;
        iov[1].iov_base = buf->data;
        iov[1].iov_len = buf->head;
        iovcnt = 2;
    }
    n = readv(fd, iov, iovcnt);
    if (n < 0) {
        if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
            return 0;
        }
        return -1;
    } else if (n == 0) {
        return -2;
    }
    buf->size += n;
    buf->tail = (buf->tail + n) % buf->capacity;
    return n;
}

variable_types: fd int

variable_types: n long

variable_types: iovcnt long

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [2]

return_type: long


original_code:
size_t buffer_get(buffer_t *buf, size_t len, void *target, size_t capacity) {
    size_t read_len, total = 0;
    byte_t *_target = (byte_t*) target;
    len = ((buf->size) < (len) ? (buf->size) : (len));
    read_len = ((len) < (buf->capacity - buf->head) ? (len) : (buf->capacity - buf->head));
    read_len = ((read_len) < (capacity) ? (read_len) : (capacity));
    _do_get(buf, _target, read_len);
    total += read_len;
    _target += read_len;
    capacity -= read_len;
    read_len = ((capacity) < (len - read_len) ? (capacity) : (len - read_len));
    if (read_len > 0) {
        _do_get(buf, _target, read_len);
        total += read_len;
    }
    return total;
}

canonical_original_code:
unsigned long buffer_get(struct _buffer *buf, unsigned long len, void *target, unsigned long capacity) {
    unsigned long read_len; unsigned long total = 0;
    unsigned char *_target = (byte_t*) target;
    len = ((buf->size) < (len) ? (buf->size) : (len));
    read_len = ((len) < (buf->capacity - buf->head) ? (len) : (buf->capacity - buf->head));
    read_len = ((read_len) < (capacity) ? (read_len) : (capacity));
    _do_get(buf, _target, read_len);
    total += read_len;
    _target += read_len;
    capacity -= read_len;
    read_len = ((capacity) < (len - read_len) ? (capacity) : (len - read_len));
    if (read_len > 0) {
        _do_get(buf, _target, read_len);
        total += read_len;
    }
    return total;
}

variable_types:
target
void *

variable_types:
capacity
unsigned long

variable_types:
total
unsigned long

return_type: unsigned long


decompiled_code:
unsigned __int64 __fastcall buffer_skip(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax
unsigned __int64 result; // rax

v2 = *(_QWORD *)(a1 + 8);
if ( v2 <= a2 )
a2 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v2 - a2;
result = a2;
*(_DWORD *)(a1 + 24) = (a2 + *(int *)(a1 + 24)) % *(_QWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax
unsigned __int64 result; // rax

v2 = *(_QWORD *)(a1 + 8);
if ( v2 <= a2 )
a2 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v2 - a2;
result = a2;
*(_DWORD *)(a1 + 24) = (a2 + *(int *)(a1 + 24)) % *(_QWORD *)(a1 + 16);
return result;
}

original_code:
size_t buffer_skip(buffer_t *buf, size_t len) {
    len = ((buf->size) < (len) ? (buf->size) : (len));
    buf->size -= len;
    buf->head = (buf->head + len) % buf->capacity;
    return len;
}

canonical_original_code:
unsigned long buffer_skip(struct _buffer *buf, unsigned long len) {
    len = ((buf->size) < (len) ? (buf->size) : (len));
    buf->size -= len;
    buf->head = (buf->head + len) % buf->capacity;
    return len;
}


decompiled_code:
unsigned __int64 __fastcall buffer_consume(__int64 a1, unsigned __int64 a2, __int64 (__fastcall *a3)(__int64, __int64, __int64), __int64 a4)
{
unsigned __int64 v6; // rbx
unsigned __int64 v7; // r12

v6 = a2;
if ( *(_QWORD *)(a1 + 8) <= a2 )
v6 = *(_QWORD *)(a1 + 8);
v7 = *(_QWORD *)(a1 + 16) - *(int *)(a1 + 24);
if ( v7 > v6 )
v7 = v6;
do_consume((__int64 *)a1, v7, a3, a4);
if ( v6 == v7 )
return v7;
do_consume((__int64 *)a1, v6 - v7, a3, a4);
return v6;
}

original_code:
size_t buffer_consume(buffer_t *buf, size_t len, consumer_func cb, void *args) {
    size_t read_len, total = 0;
    len = ((buf->size) < (len) ? (buf->size) : (len));
    read_len = ((len) < (buf->capacity - buf->head) ? (len) : (buf->capacity - buf->head));
    _do_consume(buf, read_len, cb, args);
    total += read_len;
    read_len = len - read_len;
    if (read_len > 0) {
        _do_consume(buf, read_len, cb, args);
        total += read_len;
    }
    return total;
}

canonical_original_code:
unsigned long buffer_consume(struct _buffer *buf, unsigned long len, void (*cb)(void *data, unsigned long len, void *args), void *args) {
    unsigned long read_len; unsigned long total = 0;
    len = ((buf->size) < (len) ? (buf->size) : (len));
    read_len = ((len) < (buf->capacity - buf->head) ? (len) : (buf->capacity - buf->head));
    _do_consume(buf, read_len, cb, args);
    total += read_len;
    read_len = len - read_len;
    if (read_len > 0) {
        _do_consume(buf, read_len, cb, args);
        total += read_len;
    }
    return total;
}

variable_types: void (*)(void *data, unsigned long len, void *args)

variable_types:
args
void *


original_code:
ssize_t buffer_flush(buffer_t *buf, int fd) {
    ssize_t n;
    int iovcnt;
    struct iovec iov[2];
    iov[0].iov_base = buf->data + buf->head;
    if (buf->tail > buf->head) {
        iov[0].iov_len = buf->tail - buf->head;
        iovcnt = 1;
    } else {
        iov[0].iov_len = buf->capacity - buf->head;
        iov[1].iov_base = buf->data;
        iov[1].iov_len = buf->tail;
        iovcnt = 2;
    }
    n = writev(fd, iov, iovcnt);
    if (n < 0) {
        if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
            return 0;
        }
        return -1;
    }
    buf->size -= n;
    buf->head = (buf->head + n) % buf->capacity;
    return n;
}

canonical_original_code:
long buffer_flush(struct _buffer *buf, int fd) {
    long n;
    int iovcnt;
    struct iovec iov[2];
    iov[0].iov_base = buf->data + buf->head;
    if (buf->tail > buf->head) {
        iov[0].iov_len = buf->tail - buf->head;
        iovcnt = 1;
    } else {
        iov[0].iov_len = buf->capacity - buf->head;
        iov[1].iov_base = buf->data;
        iov[1].iov_len = buf->tail;
        iovcnt = 2;
    }
    n = writev(fd, iov, iovcnt);
    if (n < 0) {
        if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
            return 0;
        }
        return -1;
    }
    buf->size -= n;
    buf->head = (buf->head + n) % buf->capacity;
    return n;
}

variable_types: iovcnt int

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }