decompiled_code:
__int64 __fastcall log_add(__int64 a1, __int32 a2, const char *a3)
{
unsigned int v3; // er12
__m128i *v5; // rbp
_QWORD *v6; // rcx
__m128i v8; // [rsp+0h] [rbp-38h] BYREF

v3 = 4;
if ( *(int *)(a1 + 24) <= 999 )
{
v5 = (__m128i *)log_entry_init();
v3 = 0;
if ( v5 )
{
v3 = gettimeofday((struct timeval *)&v8, 0LL);
if ( v3 )
{
puts("Error in getting time of the day");
v3 = *__errno_location();
}
else
{
v5[1].m128i_i32[0] = a2;
strncpy(&v5[1].m128i_i8[4], a3, 0x200uLL);
*v5 = _mm_loadu_si128(&v8);
v6 = (_QWORD *)(a1 + 536LL * *(int *)(a1 + 24) + 40);
*v6 = v5->m128i_i64[0];
v6[66] = v5[33].m128i_i64[0];
qmemcpy(
(void *)((unsigned __int64)(v6 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)v5 - ((char *)v6 - ((unsigned __int64)(v6 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v6 - (((_DWORD)v6 + 8) & 0xFFFFFFF8) + 536) >> 3));
++*(_DWORD *)(a1 + 24);
}
}
free(v5);
}
return v3;
}

original_code:
int
log_add(log_t *log, int level, char *str)
{
 int ret_val = SUCCESS;
 struct timeval t;
 if (log->num_entries >= 1000)
  return LOG_FULL;
 log_entry_t *log_ent = ((void *)0);
 log_ent = log_entry_init();
 if (!log_ent)
  goto cleanup;
 ret_val = gettimeofday(&t, ((void *)0));
 if (ret_val != 0) {
  printf("Error in getting time of the day\n");
  ret_val = (*__errno_location ());
  goto cleanup;
 }
 log_ent->level = level;
 strncpy(log_ent->log_str, str, 512);
 memcpy(&log_ent->time, &t, sizeof(struct timeval));
 memcpy(&log->entries[log->num_entries],
   log_ent,
   sizeof(log_entry_t));
 log->num_entries++;
cleanup:
 free(log_ent);
 return ret_val;
}

canonical_original_code:
int log_add(struct log_ *log, int level, char *str)
{
 int ret_val = SUCCESS;
 struct timeval t;
 if (log->num_entries >= 1000)
  return LOG_FULL;
 struct log_entry_ *log_ent = ((void *)0);
 log_ent = log_entry_init();
 if (!log_ent)
  goto cleanup;
 ret_val = gettimeofday(&t, ((void *)0));
 if (ret_val != 0) {
  printf("Error in getting time of the day\n");
  ret_val = (*__errno_location ());
  goto cleanup;
 }
 log_ent->level = level;
 strncpy(log_ent->log_str, str, 512);
 memcpy(&log_ent->time, &t, sizeof(struct timeval));
 memcpy(&log->entries[log->num_entries],
   log_ent,
   sizeof(log_entry_t));
 log->num_entries++;
cleanup:
 free(log_ent);
 return ret_val;
}

variable_types: struct log_ { int log_id; char log_name[20]; int num_entries; long buf_len; struct log_entry_ { struct timeval { long tv_sec; long tv_usec; } time; enum log_level { LOG_CRITICAL=0, LOG_ERROR=1, LOG_WARNING=2, LOG_DEBUG=3, LOG_INFO=4, LOG_VERBOSE=5 } level; char log_str[512]; } entries[1000]; } *

variable_types: level int

variable_types:
str
char *

user_defined_types: struct log_ { int log_id; char log_name[20]; int num_entries; long buf_len; struct log_entry_ entries[1000]; }


repo: sidmanu/LibLog

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

switch ( a2 )
{
case 0:
result = 0x4C41434954495243LL;
strcpy(a1, "CRITICAL");
break;
case 1:
strcpy(a1, "ERROR");
break;
case 2:
result = 0x474E494E524157LL;
*(_QWORD *)a1 = 0x474E494E524157LL;
break;
case 3:
strcpy(a1, "DEBUG");
break;
case 4:
strcpy(a1, "INFO");
break;
case 5:
result = 0x45534F42524556LL;
*(_QWORD *)a1 = 0x45534F42524556LL;
break;
default:
result = 0x4E574F4E4B4E55LL;
*(_QWORD *)a1 = 0x4E574F4E4B4E55LL;
break;
}
return result;
}

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

switch ( a2 )
{
case 0:
result = 0x4C41434954495243LL;
strcpy(a1, "CRITICAL");
break;
case 1:
strcpy(a1, "ERROR");
break;
case 2:
result = 0x474E494E524157LL;
*(_QWORD *)a1 = 0x474E494E524157LL;
break;
case 3:
strcpy(a1, "DEBUG");
break;
case 4:
strcpy(a1, "INFO");
break;
case 5:
result = 0x45534F42524556LL;
*(_QWORD *)a1 = 0x45534F42524556LL;
break;
default:
result = 0x4E574F4E4B4E55LL;
*(_QWORD *)a1 = 0x4E574F4E4B4E55LL;
break;
}
return result;
}

original_code:
void
snprintf_level(char *buf, int level)
{
 switch (level) {
 case LOG_CRITICAL:
  snprintf(buf, 20, "CRITICAL");
  break;
 case LOG_ERROR:
  snprintf(buf, 20, "ERROR");
  break;
 case LOG_WARNING:
  snprintf(buf, 20, "WARNING");
  break;
 case LOG_DEBUG:
  snprintf(buf, 20, "DEBUG");
  break;
 case LOG_INFO:
  snprintf(buf, 20, "INFO");
  break;
 case LOG_VERBOSE:
  snprintf(buf, 20, "VERBOSE");
  break;
 default:
  snprintf(buf, 20, "UNKNOWN");
 }
}

variable_types:
buf
char *

return_type: void


decompiled_code:
int __fastcall snprintf_log_entry(char *s, __int64 a2, int a3)
{
__int64 v3; // rbx
struct tm *v4; // rax
char v6[32]; // [rsp+0h] [rbp-E8h] BYREF
char v7[64]; // [rsp+20h] [rbp-C8h] BYREF
char sa[72]; // [rsp+60h] [rbp-88h] BYREF
time_t timer; // [rsp+A8h] [rbp-40h] BYREF

if ( !s )
__assert_fail("str", "log.c", 0x55u, "snprintf_log_entry");
if ( !a2 )
__assert_fail("log", "log.c", 0x56u, "snprintf_log_entry");
if ( a3 < 0 || *(_DWORD *)(a2 + 24) <= a3 )
__assert_fail("(entry_num >= 0) && (entry_num < log->num_entries)", "log.c", 0x57u, "snprintf_log_entry");
v3 = 536LL * a3;
timer = *(_QWORD *)(a2 + v3 + 40);
v4 = localtime(&timer);
strftime(sa, 0x40uLL, "%Y-%m-%d %H:%M:%S", v4);
snprintf(v7, 0x40uLL, "%s.%06d >>", sa, *(_QWORD *)(a2 + v3 + 48));
snprintf_level(v6, *(unsigned int *)(a2 + v3 + 56));
return snprintf(s, 0x200uLL, "%s: %s %s\n", v6, v7, (const char *)(a2 + v3 + 60));
}

canonical_decompiled_code:
int __fastcall func9(char *s, __int64 a2, int a3)
{
__int64 v3; // rbx
struct tm *v4; // rax
char v6[32]; // [rsp+0h] [rbp-E8h] BYREF
char v7[64]; // [rsp+20h] [rbp-C8h] BYREF
char sa[72]; // [rsp+60h] [rbp-88h] BYREF
time_t timer; // [rsp+A8h] [rbp-40h] BYREF

if ( !s )
__assert_fail("str", "log.c", 0x55u, "snprintf_log_entry");
if ( !a2 )
__assert_fail("log", "log.c", 0x56u, "snprintf_log_entry");
if ( a3 < 0 || *(_DWORD *)(a2 + 24) <= a3 )
__assert_fail("(entry_num >= 0) && (entry_num < log->num_entries)", "log.c", 0x57u, "snprintf_log_entry");
v3 = 536LL * a3;
timer = *(_QWORD *)(a2 + v3 + 40);
v4 = localtime(&timer);
strftime(sa, 0x40uLL, "%Y-%m-%d %H:%M:%S", v4);
snprintf(v7, 0x40uLL, "%s.%06d >>", sa, *(_QWORD *)(a2 + v3 + 48));
func8(v6, *(unsigned int *)(a2 + v3 + 56));
return snprintf(s, 0x200uLL, "%s: %s %s\n", v6, v7, (const char *)(a2 + v3 + 60));
}

original_code:
void
snprintf_log_entry(char *str, log_t *log,
 int entry_num)
{
 ((void) sizeof ((str) ? 1 : 0), __extension__ ({ if (str) ; else __assert_fail ("str", "log.c", 85, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((log) ? 1 : 0), __extension__ ({ if (log) ; else __assert_fail ("log", "log.c", 86, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((entry_num >= 0) && (entry_num < log->num_entries)) ? 1 : 0), __extension__ ({ if ((entry_num >= 0) && (entry_num < log->num_entries)) ; else __assert_fail ("(entry_num >= 0) && (entry_num < log->num_entries)", "log.c", 87, __extension__ __PRETTY_FUNCTION__); }));
 int i = entry_num;
 time_t now_time;
 struct tm *now_tm;
 char tmbuf[64], buf[64], level_buf[20];
 now_time = (log->entries[i]).time.tv_sec;
 now_tm = localtime(&now_time);
 strftime(tmbuf, (sizeof tmbuf),
  "%Y-%m-%d %H:%M:%S",
  now_tm);
 snprintf(buf, sizeof buf, "%s.%06d >>",
  tmbuf, log->entries[i].time.tv_usec);
 snprintf_level((char *)&level_buf,
  (log->entries[i]).level);
 snprintf(str, 512,
  "%s: %s %s\n", level_buf,
                 buf, log->entries[i].log_str);
}

canonical_original_code:
void snprintf_log_entry(char *str, struct log_ *log, int entry_num)
{
 ((void) sizeof ((str) ? 1 : 0), __extension__ ({ if (str) ; else __assert_fail ("str", "log.c", 85, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((log) ? 1 : 0), __extension__ ({ if (log) ; else __assert_fail ("log", "log.c", 86, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((entry_num >= 0) && (entry_num < log->num_entries)) ? 1 : 0), __extension__ ({ if ((entry_num >= 0) && (entry_num < log->num_entries)) ; else __assert_fail ("(entry_num >= 0) && (entry_num < log->num_entries)", "log.c", 87, __extension__ __PRETTY_FUNCTION__); }));
 int i = entry_num;
 long now_time;
 struct tm *now_tm;
 char tmbuf[64]; char buf[64]; char level_buf[20];
 now_time = (log->entries[i]).time.tv_sec;
 now_tm = localtime(&now_time);
 strftime(tmbuf, (sizeof tmbuf),
  "%Y-%m-%d %H:%M:%S",
  now_tm);
 snprintf(buf, sizeof buf, "%s.%06d >>",
  tmbuf, log->entries[i].time.tv_usec);
 snprintf_level((char *)&level_buf,
  (log->entries[i]).level);
 snprintf(str, 512,
  "%s: %s %s\n", level_buf,
                 buf, log->entries[i].log_str);
}

variable_types: i int

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
tmbuf
char [64]

variable_types:
buf
char [64]

user_defined_types: struct log_entry_ { struct timeval time; enum log_level level; char log_str[512]; }

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

user_defined_types: enum log_level { LOG_CRITICAL=0, LOG_ERROR=1, LOG_WARNING=2, LOG_DEBUG=3, LOG_INFO=4, LOG_VERBOSE=5 }


decompiled_code:
int __fastcall log_print_all(__int64 a1, int a2)
{
_DWORD *v2; // rbp
int i; // ebx
int result; // eax
char v5[552]; // [rsp+0h] [rbp-228h] BYREF

if ( !a1 )
__assert_fail("log", "log.c", 0x75u, "log_print_all");
v2 = (_DWORD *)(a1 + 56);
for ( i = 0; i != 1000; ++i )
{
if ( *v2 == a2 )
{
snprintf_log_entry(v5);
result = printf("%s", v5);
}
v2 += 134;
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, int a2)
{
_DWORD *v2; // rbp
int i; // ebx
int result; // eax
char v5[552]; // [rsp+0h] [rbp-228h] BYREF

if ( !a1 )
__assert_fail("log", "log.c", 0x75u, "log_print_all");
v2 = (_DWORD *)(a1 + 56);
for ( i = 0; i != 1000; ++i )
{
if ( *v2 == a2 )
{
func9(v5);
result = printf("%s", v5);
}
v2 += 134;
}
return result;
}

original_code:
void
log_print_all(log_t *log, int level)
{
 int i = 0;
 ((void) sizeof ((log) ? 1 : 0), __extension__ ({ if (log) ; else __assert_fail ("log", "log.c", 117, __extension__ __PRETTY_FUNCTION__); }));
 char str[512];
 for (i = 0; i < 1000; i++) {
  if ((log->entries[i]).level != level)
   continue;
  snprintf_log_entry((char*) str, log, i);
  printf("%s", str);
 }
}

canonical_original_code:
void log_print_all(struct log_ *log, int level)
{
 int i = 0;
 ((void) sizeof ((log) ? 1 : 0), __extension__ ({ if (log) ; else __assert_fail ("log", "log.c", 117, __extension__ __PRETTY_FUNCTION__); }));
 char str[512];
 for (i = 0; i < 1000; i++) {
  if ((log->entries[i]).level != level)
   continue;
  snprintf_log_entry((char *) str, log, i);
  printf("%s", str);
 }
}

variable_types:
str
char [512]


decompiled_code:
__int64 __fastcall log_init(char **a1, int a2, const char *a3)
{
char *v4; // rax
char *v5; // rbx
__int64 result; // rax

if ( !a1 )
__assert_fail("pp_log", "log.c", 0x85u, "log_init");
v4 = (char *)malloc(0x82DE8uLL);
v5 = v4;
*a1 = v4;
if ( v4 )
{
memset(v4, 0, 0x82DE8uLL);
*(_DWORD *)v5 = a2;
strncpy(v5 + 4, a3, 0x14uLL);
result = 0LL;
}
else
{
puts("Error in malloc!");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char **a1, int a2, const char *a3)
{
char *v4; // rax
char *v5; // rbx
__int64 result; // rax

if ( !a1 )
__assert_fail("pp_log", "log.c", 0x85u, "log_init");
v4 = (char *)malloc(0x82DE8uLL);
v5 = v4;
*a1 = v4;
if ( v4 )
{
memset(v4, 0, 0x82DE8uLL);
*(_DWORD *)v5 = a2;
strncpy(v5 + 4, a3, 0x14uLL);
result = 0LL;
}
else
{
puts("Error in malloc!");
result = 1LL;
}
return result;
}

original_code:
int
log_init(log_t **pp_log, int log_id, char *name)
{
 ((void) sizeof ((pp_log) ? 1 : 0), __extension__ ({ if (pp_log) ; else __assert_fail ("pp_log", "log.c", 133, __extension__ __PRETTY_FUNCTION__); }));
 *pp_log = (log_t *) malloc (sizeof(log_t));
 if (!(*pp_log)) {
  printf("Error in malloc!\n");
  return LOG_MALLOC_ERR;
 }
 memset(*pp_log, 0, sizeof(log_t));
 (*pp_log)->log_id = log_id;
 strncpy((*pp_log)->log_name, name, 20);
 return SUCCESS;
}

canonical_original_code:
int log_init(struct log_ **pp_log, int log_id, char *name)
{
 ((void) sizeof ((pp_log) ? 1 : 0), __extension__ ({ if (pp_log) ; else __assert_fail ("pp_log", "log.c", 133, __extension__ __PRETTY_FUNCTION__); }));
 *pp_log = (struct log_ *) malloc (sizeof(log_t));
 if (!(*pp_log)) {
  printf("Error in malloc!\n");
  return LOG_MALLOC_ERR;
 }
 memset(*pp_log, 0, sizeof(log_t));
 (*pp_log)->log_id = log_id;
 strncpy((*pp_log)->log_name, name, 20);
 return SUCCESS;
}

variable_types: struct log_ { int log_id; char log_name[20]; int num_entries; long buf_len; struct log_entry_ { struct timeval { long tv_sec; long tv_usec; } time; enum log_level { LOG_CRITICAL=0, LOG_ERROR=1, LOG_WARNING=2, LOG_DEBUG=3, LOG_INFO=4, LOG_VERBOSE=5 } level; char log_str[512]; } entries[1000]; } **

variable_types:
name
char *

return_type: int


repo: sidmanu/Libsvbst

decompiled_code:
_BOOL8 __fastcall default_comp_fn(_DWORD *a1, _DWORD *a2)
{
return *a1 < *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(_DWORD *a1, _DWORD *a2)
{
return *a1 < *a2;
}

original_code:
int default_comp_fn(void *l_data, void *r_data)
{
 if (*((int*) l_data) < *((int*) r_data))
  return 1;
 else
  return 0;
}

canonical_original_code:
int default_comp_fn(void *l_data, void *r_data)
{
 if (*((int *) l_data) < *((int *) r_data))
  return 1;
 else
  return 0;
}


decompiled_code:
char *__fastcall bst_create(char *src, _BOOL8 (__fastcall *a2)(_DWORD *a1, _DWORD *a2))
{
_BOOL8 (__fastcall *v2)(_DWORD *, _DWORD *); // rbp
char *v3; // rax
char *v4; // rbx
char *result; // rax

v2 = a2;
v3 = (char *)malloc(0x28uLL);
if ( v3 )
{
v4 = v3;
result = strncpy(v3 + 8, src, 0x18uLL);
if ( !a2 )
v2 = default_comp_fn;
*((_QWORD *)v4 + 4) = v2;
}
else
{
fwrite("Error in malloc\n", 1uLL, 0x10uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func7(char *src, _BOOL8 (__fastcall *a2)(_DWORD *a1, _DWORD *a2))
{
_BOOL8 (__fastcall *v2)(_DWORD *, _DWORD *); // rbp
char *v3; // rax
char *v4; // rbx
char *result; // rax

v2 = a2;
v3 = (char *)malloc(0x28uLL);
if ( v3 )
{
v4 = v3;
result = strncpy(v3 + 8, src, 0x18uLL);
if ( !a2 )
v2 = default_comp_fn;
*((_QWORD *)v4 + 4) = v2;
}
else
{
fwrite("Error in malloc\n", 1uLL, 0x10uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bst_t*
bst_create(char name[30],
  int (*comp_fn)(void *l_data, void *r_data))
{
 bst_t *bst = ((void *)0);
 bst = (bst_t *) malloc(sizeof(bst_t));
 if (!bst){
  fprintf(stderr, "Error in malloc\n");
  return bst;
 }
 strncpy(bst->name, name, 30);
 if (comp_fn) {
  bst->comp_fn = comp_fn;
 } else
  bst->comp_fn = &default_comp_fn;
}

canonical_original_code:
struct bst_ *bst_create(char name[30], int (*comp_fn)(void *l_data, void *r_data))
{
 struct bst_ *bst = ((void *)0);
 bst = (struct bst_ *) malloc(sizeof(bst_t));
 if (!bst){
  fprintf(stderr, "Error in malloc\n");
  return bst;
 }
 strncpy(bst->name, name, 30);
 if (comp_fn) {
  bst->comp_fn = comp_fn;
 } else
  bst->comp_fn = &default_comp_fn;
}

variable_types:
name
char [30]

variable_types: struct bst_ { struct bst_node_ { void *data; struct bst_node_ *left; struct bst_node_ *right; } *root; char name[20]; int (*comp_fn)(void *r_data, void *l_data); } *

user_defined_types: struct bst_ { struct bst_node_ *root; char name[20]; int (*comp_fn)(void *r_data, void *l_data); }


decompiled_code:
__int64 __fastcall bst_add(_QWORD **a1, _QWORD *a2)
{
__int64 v3; // rsi

if ( !a1 || !a2 )
fwrite("Invalid argument", 1uLL, 0x10uLL, stderr);
if ( *a1 )
{
if ( ((unsigned int (__fastcall *)(_QWORD, _QWORD))a1[4])(**a1, *a2) )
{
v3 = (*a1)[1];
if ( !v3 )
{
(*a1)[1] = a2;
return 0LL;
}
}
else
{
v3 = (*a1)[2];
if ( !v3 )
{
(*a1)[2] = a2;
return 0LL;
}
}
_bst_node_add_localalias(a1, v3, a2);
}
else
{
*a1 = a2;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD **a1, _QWORD *a2)
{
__int64 v3; // rsi

if ( !a1 || !a2 )
fwrite("Invalid argument", 1uLL, 0x10uLL, stderr);
if ( *a1 )
{
if ( ((unsigned int (__fastcall *)(_QWORD, _QWORD))a1[4])(**a1, *a2) )
{
v3 = (*a1)[1];
if ( !v3 )
{
(*a1)[1] = a2;
return 0LL;
}
}
else
{
v3 = (*a1)[2];
if ( !v3 )
{
(*a1)[2] = a2;
return 0LL;
}
}
_bst_node_add_localalias(a1, v3, a2);
}
else
{
*a1 = a2;
}
return 0LL;
}

original_code:
int bst_add(bst_t *tree, bst_node_t *node)
{
 int ret_val = SUCCESS;
 if (!tree || !node) {
  fprintf(stderr, "Invalid argument");
 }
 if (!tree->root) {
  tree->root = node;
  return ret_val;
 }
 if ((*tree->comp_fn)(tree->root->data, node->data)) {
  if (!tree->root->left){
   tree->root->left = node;
   return 0;
  } else {
   _bst_node_add(tree, tree->root->left, node);
  }
 } else {
  if (!tree->root->right) {
   tree->root->right = node;
   return 0;
  }
  _bst_node_add(tree, tree->root->right, node);
 }
 return ret_val;
}

canonical_original_code:
int bst_add(struct bst_ *tree, struct bst_node_ *node)
{
 int ret_val = SUCCESS;
 if (!tree || !node) {
  fprintf(stderr, "Invalid argument");
 }
 if (!tree->root) {
  tree->root = node;
  return ret_val;
 }
 if ((*tree->comp_fn)(tree->root->data, node->data)) {
  if (!tree->root->left){
   tree->root->left = node;
   return 0;
  } else {
   _bst_node_add(tree, tree->root->left, node);
  }
 } else {
  if (!tree->root->right) {
   tree->root->right = node;
   return 0;
  }
  _bst_node_add(tree, tree->root->right, node);
 }
 return ret_val;
}

variable_types:
node
struct bst_node_ *

user_defined_types: struct bst_node_ { void *data; struct bst_node_ *left; struct bst_node_ *right; }


decompiled_code:
__int64 bst_del()
{
return 0LL;
}

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

original_code:
int bst_del(bst_t *tree, bst_node_t *node)
{
 return 0;
}

canonical_original_code:
int bst_del(struct bst_ *tree, struct bst_node_ *node)
{
 return 0;
}


decompiled_code:
int __fastcall bst_preorder(_QWORD *a1)
{
int result; // eax

if ( !a1 )
result = fprintf(stderr, "Invalid argument to %s", "bst_preorder");
if ( *a1 )
result = _bst_preorder_node_localalias();
return result;
}

canonical_decompiled_code:
int __fastcall func12(_QWORD *a1)
{
int result; // eax

if ( !a1 )
result = fprintf(stderr, "Invalid argument to %s", "bst_preorder");
if ( *a1 )
result = _bst_preorder_node_localalias();
return result;
}

original_code:
void
bst_preorder(bst_t *tree)
{
 if (!tree) {
  fprintf(stderr, "Invalid argument to %s",
   __FUNCTION__);
 }
 if (tree->root) {
  _bst_preorder_node(tree->root);
 }
}

canonical_original_code:
void bst_preorder(struct bst_ *tree)
{
 if (!tree) {
  fprintf(stderr, "Invalid argument to %s",
   __FUNCTION__);
 }
 if (tree->root) {
  _bst_preorder_node(tree->root);
 }
}


repo: sidtechnical/Keccak-Hashing

decompiled_code:
void KeccakF_bytes()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
unsigned char* KeccakF_bytes(unsigned char *state){
}

canonical_original_code:
unsigned char *KeccakF_bytes(unsigned char *state){
}

variable_types:
state
unsigned char *

return_type: unsigned char *


original_code:
unsigned long** x_step(unsigned long **A,unsigned long **B)
{
 unsigned int i,j;
 for(i=0; i<5; i++)
  {
    for(j=0; j<5; j++)
     {
   A[i][j] = B[i][j] ^ ((~B[(i+1)%5][j]) & B[(i+2)%5][j]);
     }
         }
 return A;
}

canonical_original_code:
unsigned long **x_step(unsigned long **A, unsigned long **B)
{
 unsigned int i; unsigned int j;
 for(i=0; i<5; i++)
  {
    for(j=0; j<5; j++)
     {
   A[i][j] = B[i][j] ^ ((~B[(i+1)%5][j]) & B[(i+2)%5][j]);
     }
         }
 return A;
}

variable_types:
A
unsigned long **

variable_types:
B
unsigned long **

variable_types:
i
unsigned int

variable_types:
j
unsigned int

return_type: unsigned long **


rot

decompiled_code:
__int64 __fastcall rot(__int64 a1, char a2)
{
return __ROL8__(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2)
{
return __ROL8__(a1, a2);
}

original_code:
unsigned long rot(unsigned long x,unsigned int y){
unsigned long m,n;
m = 1 << 64;
n = ((x << y) | (x >> (64 - y))) & (m-1);
return n;
}

canonical_original_code:
unsigned long rot(unsigned long x, unsigned int y){
unsigned long m; unsigned long n;
m = 1 << 64;
n = ((x << y) | (x >> (64 - y))) & (m-1);
return n;
}

variable_types:
x
unsigned long

variable_types:
y
unsigned int

variable_types:
m
unsigned long

variable_types:
n
unsigned long

return_type: unsigned long


repo: sigabrt/slurp

decompiled_code:
__int64 __fastcall progress_callback(__int64 a1, double a2, double a3)
{
if ( a3 == 0.0 )
{
if ( *(_DWORD *)a1 )
{
*(_QWORD *)(a1 + 8) = time(0LL);
}
else if ( *(_QWORD *)(a1 + 8) && time(0LL) - *(_QWORD *)(a1 + 8) > 90 )
{
*(_DWORD *)a1 = 1;
*(_QWORD *)(a1 + 8) = 0LL;
return 1LL;
}
}
else if ( !*(_DWORD *)a1 )
{
*(_QWORD *)(a1 + 8) = 0LL;
}
*(_DWORD *)a1 = (int)a3;
return 0LL;
}

original_code:
int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
{
 struct idletimer *timeout;
 timeout = (struct idletimer *)clientp;
 if(dlnow == 0)
 {
  if(timeout->lastdl != 0)
  {
   timeout->idlestart = time(((void *)0));
  }
  else if(timeout->idlestart != 0 &&
    (time(((void *)0)) - timeout->idlestart) > (90))
  {
   timeout->lastdl = 1;
   timeout->idlestart = 0;
   return 1;
  }
 }
 else
 {
  if(timeout->lastdl == 0)
  {
   timeout->idlestart = 0;
  }
 }
 timeout->lastdl = dlnow;
 return 0;
}

variable_types:
clientp
void *

variable_types: dltotal double

variable_types: dlnow double

variable_types: ultotal double

variable_types: ulnow double

variable_types: struct idletimer { int lastdl; long idlestart; } *


decompiled_code:
int __fastcall reconnect_wait(int a1)
{
int v1; // eax
__int64 v3; // rcx
struct timespec v4; // [rsp+0h] [rbp-18h] BYREF

if ( a1 == 1 )
{
v4.tv_sec = rate_limit_sleep_s_1;
v4.tv_nsec = 0LL;
rate_limit_sleep_s_1 *= 2;
}
else if ( a1 == 2 )
{
v4.tv_sec = sock_sleep_ms_0 / 1000;
v4.tv_nsec = 1000000 * (sock_sleep_ms_0 % 1000);
v3 = sock_sleep_ms_0 + 250;
if ( sock_sleep_ms_0 + 250 > 16000 )
v3 = 16000LL;
sock_sleep_ms_0 = v3;
}
else if ( a1 )
{
v4.tv_sec = 0LL;
v4.tv_nsec = 0LL;
}
else
{
v4.tv_sec = http_sleep_s_2;
v4.tv_nsec = 0LL;
v1 = 2 * http_sleep_s_2;
if ( 2 * http_sleep_s_2 > 320 )
v1 = 320;
http_sleep_s_2 = v1;
}
return nanosleep(&v4, 0LL);
}

canonical_decompiled_code:
int __fastcall func11(int a1)
{
int v1; // eax
__int64 v3; // rcx
struct timespec v4; // [rsp+0h] [rbp-18h] BYREF

if ( a1 == 1 )
{
v4.tv_sec = rate_limit_sleep_s_1;
v4.tv_nsec = 0LL;
rate_limit_sleep_s_1 *= 2;
}
else if ( a1 == 2 )
{
v4.tv_sec = sock_sleep_ms_0 / 1000;
v4.tv_nsec = 1000000 * (sock_sleep_ms_0 % 1000);
v3 = sock_sleep_ms_0 + 250;
if ( sock_sleep_ms_0 + 250 > 16000 )
v3 = 16000LL;
sock_sleep_ms_0 = v3;
}
else if ( a1 )
{
v4.tv_sec = 0LL;
v4.tv_nsec = 0LL;
}
else
{
v4.tv_sec = http_sleep_s_2;
v4.tv_nsec = 0LL;
v1 = 2 * http_sleep_s_2;
if ( 2 * http_sleep_s_2 > 320 )
v1 = 320;
http_sleep_s_2 = v1;
}
return nanosleep(&v4, 0LL);
}

original_code:
void reconnect_wait(error_type error)
{
 static int http_sleep_s = 5;
 static int rate_limit_sleep_s = 60;
 static long sock_sleep_ms = 250;
 struct timespec t;
 switch(error)
 {
  case ERROR_TYPE_HTTP:
   t.tv_sec = http_sleep_s;
   t.tv_nsec = 0;
   http_sleep_s *= 2;
   if(http_sleep_s > 320)
   {
    http_sleep_s = 320;
   }
   break;
  case ERROR_TYPE_RATE_LIMITED:
   t.tv_sec = rate_limit_sleep_s;
   t.tv_nsec = 0;
   rate_limit_sleep_s *= 2;
   break;
  case ERROR_TYPE_SOCKET:
   t.tv_sec = sock_sleep_ms / 1000;
   t.tv_nsec = (sock_sleep_ms % 1000) * (1000000);
   sock_sleep_ms += 250;
   if(sock_sleep_ms > 16000)
   {
    sock_sleep_ms = 16000;
   }
   break;
  default:
   t.tv_sec = 0;
   t.tv_nsec = 0;
   break;
 }
 nanosleep(&t, ((void *)0));
}

canonical_original_code:
void reconnect_wait(enum error_type error)
{
 static int http_sleep_s = 5;
 static int rate_limit_sleep_s = 60;
 static long sock_sleep_ms = 250;
 struct timespec t;
 switch(error)
 {
  case ERROR_TYPE_HTTP:
   t.tv_sec = http_sleep_s;
   t.tv_nsec = 0;
   http_sleep_s *= 2;
   if(http_sleep_s > 320)
   {
    http_sleep_s = 320;
   }
   break;
  case ERROR_TYPE_RATE_LIMITED:
   t.tv_sec = rate_limit_sleep_s;
   t.tv_nsec = 0;
   rate_limit_sleep_s *= 2;
   break;
  case ERROR_TYPE_SOCKET:
   t.tv_sec = sock_sleep_ms / 1000;
   t.tv_nsec = (sock_sleep_ms % 1000) * (1000000);
   sock_sleep_ms += 250;
   if(sock_sleep_ms > 16000)
   {
    sock_sleep_ms = 16000;
   }
   break;
  default:
   t.tv_sec = 0;
   t.tv_nsec = 0;
   break;
 }
 nanosleep(&t, ((void *)0));
}

variable_types: enum error_type { ERROR_TYPE_HTTP=0, ERROR_TYPE_RATE_LIMITED=1, ERROR_TYPE_SOCKET=2 }

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


die

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
fputs(a1, stderr);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
fputs(a1, stderr);
fputc(10, stderr);
exit(1);
}

original_code:
void die(const char *message)
{
 fputs(message, stderr);
 fputc('\n', stderr);
 exit(1);
}

canonical_original_code:
void die(char *message)
{
 fputs(message, stderr);
 fputc('\n', stderr);
 exit(1);
}

variable_types:
message
char *


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

switch ( a1 )
{
case 4:
case 80:
case 92:
result = 4294967294LL;
break;
case 7:
case 79:
case 94:
result = 2LL;
break;
case 22:
case 81:
case 90:
result = 0xFFFFFFFFLL;
break;
case 26:
case 82:
case 96:
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 4:
case 80:
case 92:
result = 4294967294LL;
break;
case 7:
case 79:
case 94:
result = 2LL;
break;
case 22:
case 81:
case 90:
result = 0xFFFFFFFFLL;
break;
case 26:
case 82:
case 96:
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
tile_t scancode_to_direction(SDL_Scancode key)
{
 switch(key)
 {
  case SDL_SCANCODE_A:
  case SDL_SCANCODE_LEFT:
  case SDL_SCANCODE_KP_4:
   return TILE_WEST;
  case SDL_SCANCODE_S:
  case SDL_SCANCODE_DOWN:
  case SDL_SCANCODE_KP_2:
   return TILE_SOUTH;
  case SDL_SCANCODE_W:
  case SDL_SCANCODE_UP:
  case SDL_SCANCODE_KP_8:
   return TILE_NORTH;
  case SDL_SCANCODE_D:
  case SDL_SCANCODE_RIGHT:
  case SDL_SCANCODE_KP_6:
   return TILE_EAST;
  default:
   return TILE_NONE;
 }
}

canonical_original_code:
char scancode_to_direction(enum SDL_Scancode key)
{
 switch(key)
 {
  case SDL_SCANCODE_A:
  case SDL_SCANCODE_LEFT:
  case SDL_SCANCODE_KP_4:
   return TILE_WEST;
  case SDL_SCANCODE_S:
  case SDL_SCANCODE_DOWN:
  case SDL_SCANCODE_KP_2:
   return TILE_SOUTH;
  case SDL_SCANCODE_W:
  case SDL_SCANCODE_UP:
  case SDL_SCANCODE_KP_8:
   return TILE_NORTH;
  case SDL_SCANCODE_D:
  case SDL_SCANCODE_RIGHT:
  case SDL_SCANCODE_KP_6:
   return TILE_EAST;
  default:
   return TILE_NONE;
 }
}

variable_types: enum SDL_Scancode { SDL_SCANCODE_UNKNOWN=0, SDL_SCANCODE_A=4, SDL_SCANCODE_B=5, SDL_SCANCODE_C=6, SDL_SCANCODE_D=7, SDL_SCANCODE_E=8, SDL_SCANCODE_F=9, SDL_SCANCODE_G=10, SDL_SCANCODE_H=11, SDL_SCANCODE_I=12, SDL_SCANCODE_J=13, SDL_SCANCODE_K=14, SDL_SCANCODE_L=15, SDL_SCANCODE_M=16, SDL_SCANCODE_N=17, SDL_SCANCODE_O=18, SDL_SCANCODE_P=19, SDL_SCANCODE_Q=20, SDL_SCANCODE_R=21, SDL_SCANCODE_S=22, SDL_SCANCODE_T=23, SDL_SCANCODE_U=24, SDL_SCANCODE_V=25, SDL_SCANCODE_W=26, SDL_SCANCODE_X=27, SDL_SCANCODE_Y=28, SDL_SCANCODE_Z=29, SDL_SCANCODE_1=30, SDL_SCANCODE_2=31, SDL_SCANCODE_3=32, SDL_SCANCODE_4=33, SDL_SCANCODE_5=34, SDL_SCANCODE_6=35, SDL_SCANCODE_7=36, SDL_SCANCODE_8=37, SDL_SCANCODE_9=38, SDL_SCANCODE_0=39, SDL_SCANCODE_RETURN=40, SDL_SCANCODE_ESCAPE=41, SDL_SCANCODE_BACKSPACE=42, SDL_SCANCODE_TAB=43, SDL_SCANCODE_SPACE=44, SDL_SCANCODE_MINUS=45, SDL_SCANCODE_EQUALS=46, SDL_SCANCODE_LEFTBRACKET=47, SDL_SCANCODE_RIGHTBRACKET=48, SDL_SCANCODE_BACKSLASH=49, SDL_SCANCODE_NONUSHASH=50, SDL_SCANCODE_SEMICOLON=51, SDL_SCANCODE_APOSTROPHE=52, SDL_SCANCODE_GRAVE=53, SDL_SCANCODE_COMMA=54, SDL_SCANCODE_PERIOD=55, SDL_SCANCODE_SLASH=56, SDL_SCANCODE_CAPSLOCK=57, SDL_SCANCODE_F1=58, SDL_SCANCODE_F2=59, SDL_SCANCODE_F3=60, SDL_SCANCODE_F4=61, SDL_SCANCODE_F5=62, SDL_SCANCODE_F6=63, SDL_SCANCODE_F7=64, SDL_SCANCODE_F8=65, SDL_SCANCODE_F9=66, SDL_SCANCODE_F10=67, SDL_SCANCODE_F11=68, SDL_SCANCODE_F12=69, SDL_SCANCODE_PRINTSCREEN=70, SDL_SCANCODE_SCROLLLOCK=71, SDL_SCANCODE_PAUSE=72, SDL_SCANCODE_INSERT=73, SDL_SCANCODE_HOME=74, SDL_SCANCODE_PAGEUP=75, SDL_SCANCODE_DELETE=76, SDL_SCANCODE_END=77, SDL_SCANCODE_PAGEDOWN=78, SDL_SCANCODE_RIGHT=79, SDL_SCANCODE_LEFT=80, SDL_SCANCODE_DOWN=81, SDL_SCANCODE_UP=82, SDL_SCANCODE_NUMLOCKCLEAR=83, SDL_SCANCODE_KP_DIVIDE=84, SDL_SCANCODE_KP_MULTIPLY=85, SDL_SCANCODE_KP_MINUS=86, SDL_SCANCODE_KP_PLUS=87, SDL_SCANCODE_KP_ENTER=88, SDL_SCANCODE_KP_1=89, SDL_SCANCODE_KP_2=90, SDL_SCANCODE_KP_3=91, SDL_SCANCODE_KP_4=92, SDL_SCANCODE_KP_5=93, SDL_SCANCODE_KP_6=94, SDL_SCANCODE_KP_7=95, SDL_SCANCODE_KP_8=96, SDL_SCANCODE_KP_9=97, SDL_SCANCODE_KP_0=98, SDL_SCANCODE_KP_PERIOD=99, SDL_SCANCODE_NONUSBACKSLASH=100, SDL_SCANCODE_APPLICATION=101, SDL_SCANCODE_POWER=102, SDL_SCANCODE_KP_EQUALS=103, SDL_SCANCODE_F13=104, SDL_SCANCODE_F14=105, SDL_SCANCODE_F15=106, SDL_SCANCODE_F16=107, SDL_SCANCODE_F17=108, SDL_SCANCODE_F18=109, SDL_SCANCODE_F19=110, SDL_SCANCODE_F20=111, SDL_SCANCODE_F21=112, SDL_SCANCODE_F22=113, SDL_SCANCODE_F23=114, SDL_SCANCODE_F24=115, SDL_SCANCODE_EXECUTE=116, SDL_SCANCODE_HELP=117, SDL_SCANCODE_MENU=118, SDL_SCANCODE_SELECT=119, SDL_SCANCODE_STOP=120, SDL_SCANCODE_AGAIN=121, SDL_SCANCODE_UNDO=122, SDL_SCANCODE_CUT=123, SDL_SCANCODE_COPY=124, SDL_SCANCODE_PASTE=125, SDL_SCANCODE_FIND=126, SDL_SCANCODE_MUTE=127, SDL_SCANCODE_VOLUMEUP=128, SDL_SCANCODE_VOLUMEDOWN=129, SDL_SCANCODE_KP_COMMA=133, SDL_SCANCODE_KP_EQUALSAS400=134, SDL_SCANCODE_INTERNATIONAL1=135, SDL_SCANCODE_INTERNATIONAL2=136, SDL_SCANCODE_INTERNATIONAL3=137, SDL_SCANCODE_INTERNATIONAL4=138, SDL_SCANCODE_INTERNATIONAL5=139, SDL_SCANCODE_INTERNATIONAL6=140, SDL_SCANCODE_INTERNATIONAL7=141, SDL_SCANCODE_INTERNATIONAL8=142, SDL_SCANCODE_INTERNATIONAL9=143, SDL_SCANCODE_LANG1=144, SDL_SCANCODE_LANG2=145, SDL_SCANCODE_LANG3=146, SDL_SCANCODE_LANG4=147, SDL_SCANCODE_LANG5=148, SDL_SCANCODE_LANG6=149, SDL_SCANCODE_LANG7=150, SDL_SCANCODE_LANG8=151, SDL_SCANCODE_LANG9=152, SDL_SCANCODE_ALTERASE=153, SDL_SCANCODE_SYSREQ=154, SDL_SCANCODE_CANCEL=155, SDL_SCANCODE_CLEAR=156, SDL_SCANCODE_PRIOR=157, SDL_SCANCODE_RETURN2=158, SDL_SCANCODE_SEPARATOR=159, SDL_SCANCODE_OUT=160, SDL_SCANCODE_OPER=161, SDL_SCANCODE_CLEARAGAIN=162, SDL_SCANCODE_CRSEL=163, SDL_SCANCODE_EXSEL=164, SDL_SCANCODE_KP_00=176, SDL_SCANCODE_KP_000=177, SDL_SCANCODE_THOUSANDSSEPARATOR=178, SDL_SCANCODE_DECIMALSEPARATOR=179, SDL_SCANCODE_CURRENCYUNIT=180, SDL_SCANCODE_CURRENCYSUBUNIT=181, SDL_SCANCODE_KP_LEFTPAREN=182, SDL_SCANCODE_KP_RIGHTPAREN=183, SDL_SCANCODE_KP_LEFTBRACE=184, SDL_SCANCODE_KP_RIGHTBRACE=185, SDL_SCANCODE_KP_TAB=186, SDL_SCANCODE_KP_BACKSPACE=187, SDL_SCANCODE_KP_A=188, SDL_SCANCODE_KP_B=189, SDL_SCANCODE_KP_C=190, SDL_SCANCODE_KP_D=191, SDL_SCANCODE_KP_E=192, SDL_SCANCODE_KP_F=193, SDL_SCANCODE_KP_XOR=194, SDL_SCANCODE_KP_POWER=195, SDL_SCANCODE_KP_PERCENT=196, SDL_SCANCODE_KP_LESS=197, SDL_SCANCODE_KP_GREATER=198, SDL_SCANCODE_KP_AMPERSAND=199, SDL_SCANCODE_KP_DBLAMPERSAND=200, SDL_SCANCODE_KP_VERTICALBAR=201, SDL_SCANCODE_KP_DBLVERTICALBAR=202, SDL_SCANCODE_KP_COLON=203, SDL_SCANCODE_KP_HASH=204, SDL_SCANCODE_KP_SPACE=205, SDL_SCANCODE_KP_AT=206, SDL_SCANCODE_KP_EXCLAM=207, SDL_SCANCODE_KP_MEMSTORE=208, SDL_SCANCODE_KP_MEMRECALL=209, SDL_SCANCODE_KP_MEMCLEAR=210, SDL_SCANCODE_KP_MEMADD=211, SDL_SCANCODE_KP_MEMSUBTRACT=212, SDL_SCANCODE_KP_MEMMULTIPLY=213, SDL_SCANCODE_KP_MEMDIVIDE=214, SDL_SCANCODE_KP_PLUSMINUS=215, SDL_SCANCODE_KP_CLEAR=216, SDL_SCANCODE_KP_CLEARENTRY=217, SDL_SCANCODE_KP_BINARY=218, SDL_SCANCODE_KP_OCTAL=219, SDL_SCANCODE_KP_DECIMAL=220, SDL_SCANCODE_KP_HEXADECIMAL=221, SDL_SCANCODE_LCTRL=224, SDL_SCANCODE_LSHIFT=225, SDL_SCANCODE_LALT=226, SDL_SCANCODE_LGUI=227, SDL_SCANCODE_RCTRL=228, SDL_SCANCODE_RSHIFT=229, SDL_SCANCODE_RALT=230, SDL_SCANCODE_RGUI=231, SDL_SCANCODE_MODE=257, SDL_SCANCODE_AUDIONEXT=258, SDL_SCANCODE_AUDIOPREV=259, SDL_SCANCODE_AUDIOSTOP=260, SDL_SCANCODE_AUDIOPLAY=261, SDL_SCANCODE_AUDIOMUTE=262, SDL_SCANCODE_MEDIASELECT=263, SDL_SCANCODE_WWW=264, SDL_SCANCODE_MAIL=265, SDL_SCANCODE_CALCULATOR=266, SDL_SCANCODE_COMPUTER=267, SDL_SCANCODE_AC_SEARCH=268, SDL_SCANCODE_AC_HOME=269, SDL_SCANCODE_AC_BACK=270, SDL_SCANCODE_AC_FORWARD=271, SDL_SCANCODE_AC_STOP=272, SDL_SCANCODE_AC_REFRESH=273, SDL_SCANCODE_AC_BOOKMARKS=274, SDL_SCANCODE_BRIGHTNESSDOWN=275, SDL_SCANCODE_BRIGHTNESSUP=276, SDL_SCANCODE_DISPLAYSWITCH=277, SDL_SCANCODE_KBDILLUMTOGGLE=278, SDL_SCANCODE_KBDILLUMDOWN=279, SDL_SCANCODE_KBDILLUMUP=280, SDL_SCANCODE_EJECT=281, SDL_SCANCODE_SLEEP=282, SDL_SCANCODE_APP1=283, SDL_SCANCODE_APP2=284, SDL_SCANCODE_AUDIOREWIND=285, SDL_SCANCODE_AUDIOFASTFORWARD=286, SDL_NUM_SCANCODES=512 }

return_type: char


repo: sigmonsays/netmond

decompiled_code:
__int64 __fastcall debug_log(void *buf)
{
int v1; // eax
int v3; // ebx
size_t v4; // rax

v1 = open("./netmond-debug.log", 1089, 448LL);
if ( v1 )
{
v3 = v1;
v4 = strlen((const char *)buf);
write(v3, buf, v4);
close(v3);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *buf)
{
int v1; // eax
int v3; // ebx
size_t v4; // rax

v1 = open("./netmond-debug.log", 1089, 448LL);
if ( v1 )
{
v3 = v1;
v4 = strlen((const char *)buf);
write(v3, buf, v4);
close(v3);
}
return 0LL;
}

original_code:
int debug_log(char *msg) {
 int f;
        f = open("./netmond-debug.log", 01|02000|0100, (0400|0200|0100));
 if (f) {
  write(f, msg, strlen(msg));
  close(f);
 }
 return 0;
}

variable_types:
msg
char *

variable_types: f int


original_code:
int allow_ip(struct mconfig *mf, char *ipaddy) {
 struct st_ips *new_ip;
 new_ip = (void *) malloc(sizeof(struct st_ips));
 if (new_ip == ((void *)0)) return ((void *)0);
 new_ip->ip = strdup(ipaddy);
 if (mf->allow_ips_head == ((void *)0)) mf->allow_ips_head = new_ip;
 mf->allow_ips->next = new_ip;
 mf->allow_ips = mf->allow_ips->next;
 mf->allow_ips->next = ((void *)0);
 return 0;
}

variable_types: struct mconfig { char *cfg_file; int interval; int database; char *dbHost; struct st_server { char *host; int port; } *smtp; struct st_server *pop3; struct st_server *imap; struct st_server *rad; struct st_ips { char *ip; struct st_ips *next; } *allow_ips_head; struct st_ips *allow_ips; int notifications; long last_check; } *

variable_types:
ipaddy
char *

user_defined_types: struct mconfig { char *cfg_file; int interval; int database; char *dbHost; struct st_server *smtp; struct st_server *pop3; struct st_server *imap; struct st_server *rad; struct st_ips *allow_ips_head; struct st_ips *allow_ips; int notifications; long last_check; }


decompiled_code:
void *__fastcall parse_ips(__int64 a1, char *a2)
{
void *v2; // rax
void *v3; // rbp
char *v4; // rax
char *v5; // rsi

v2 = malloc(0x10uLL);
v3 = v2;
if ( v2 )
{
*(_QWORD *)(a1 + 88) = v2;
v4 = strtok(a2, " ");
if ( v4 )
{
allow_ip(a1, v4);
while ( 1 )
{
v5 = strtok(0LL, " ");
if ( !v5 )
break;
allow_ip(a1, v5);
}
}
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, char *a2)
{
void *v2; // rax
void *v3; // rbp
char *v4; // rax
char *v5; // rsi

v2 = malloc(0x10uLL);
v3 = v2;
if ( v2 )
{
*(_QWORD *)(a1 + 88) = v2;
v4 = strtok(a2, " ");
if ( v4 )
{
func0(a1, v4);
while ( 1 )
{
v5 = strtok(0LL, " ");
if ( !v5 )
break;
func0(a1, v5);
}
}
}
return v3;
}

original_code:
struct st_ips *parse_ips(struct mconfig *mf, char *list) {
 char *tmp;
 struct st_ips *new_ip_list;
 new_ip_list = (void *) malloc(sizeof(struct st_ips));
 if (new_ip_list == ((void *)0)) return ((void *)0);
 mf->allow_ips = new_ip_list;
 tmp = strtok(list, " ");
 if (tmp) {
  allow_ip(mf, tmp);
  while ((tmp = strtok(((void *)0), " "))) {
   allow_ip(mf, tmp);
  }
 }
 return (struct st_ips *) new_ip_list;
}

variable_types: struct mconfig { char *cfg_file; int interval; int database; char *dbHost; struct st_server { char *host; int port; } *smtp; struct st_server *pop3; struct st_server *imap; struct st_server *rad; struct st_ips *allow_ips_head; struct st_ips *allow_ips; int notifications; long last_check; } *

variable_types:
list
char *

variable_types:
tmp
char *

variable_types: struct st_ips { char *ip; struct st_ips *next; } *


decompiled_code:
__int64 __fastcall check_ip(__int64 a1, const char *a2)
{
__int64 v2; // rbx
const char *v3; // rbp
int v4; // eax

v2 = *(_QWORD *)(a1 + 80);
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = *(const char **)v2;
v4 = strlen(*(const char **)v2);
if ( !strncmp(v3, a2, v4) )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
__int64 v2; // rbx
const char *v3; // rbp
int v4; // eax

v2 = *(_QWORD *)(a1 + 80);
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = *(const char **)v2;
v4 = strlen(*(const char **)v2);
if ( !strncmp(v3, a2, v4) )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0LL;
}
return 1LL;
}

original_code:
int check_ip(struct mconfig *mf, char *ip) {
 int l;
 struct st_ips *allow_ips;
 allow_ips = mf->allow_ips_head;
 while (allow_ips) {
  l = strlen(allow_ips->ip);
  if (strncmp(allow_ips->ip, ip, l) == 0) return 1;
  allow_ips = allow_ips->next;
 }
 return 0;
}

variable_types:
ip
char *

variable_types: l int

user_defined_types: struct st_ips { char *ip; struct st_ips *next; }

user_defined_types: struct st_server { char *host; int port; }


decompiled_code:
void __fastcall free_st_server(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi
void *v6; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 3);
if ( v5 )
free(v5);
v6 = (void *)*((_QWORD *)ptr + 4);
if ( v6 )
free(v6);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi
void *v6; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 3);
if ( v5 )
free(v5);
v6 = (void *)*((_QWORD *)ptr + 4);
if ( v6 )
free(v6);
free(ptr);
}
}

original_code:
void free_st_server(struct st_server *st) {
 if (st == ((void *)0)) return;
 if (st->host) free(st->host);
 if (st->user) free(st->user);
 if (st->pass) free(st->pass);
 if (st->email) free(st->email);
 if (st->secret) free(st->secret);
 free(st);
}

variable_types: struct st_server { char *host; int port; } *


decompiled_code:
void __fastcall free_config(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi
__int64 v6; // rbx
void **v7; // rbp

free(*(void **)ptr);
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 3);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 4);
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 5);
if ( v5 )
free(v5);
free_st_server(*((void **)ptr + 6));
free_st_server(*((void **)ptr + 7));
free_st_server(*((void **)ptr + 8));
free_st_server(*((void **)ptr + 9));
v6 = *((_QWORD *)ptr + 10);
while ( v6 )
{
v7 = (void **)v6;
v6 = *(_QWORD *)(v6 + 8);
free(*v7);
free(v7);
}
free(*((void **)ptr + 11));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi
__int64 v6; // rbx
void **v7; // rbp

free(*(void **)ptr);
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 3);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 4);
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 5);
if ( v5 )
free(v5);
func1(*((void **)ptr + 6));
func1(*((void **)ptr + 7));
func1(*((void **)ptr + 8));
func1(*((void **)ptr + 9));
v6 = *((_QWORD *)ptr + 10);
while ( v6 )
{
v7 = (void **)v6;
v6 = *(_QWORD *)(v6 + 8);
free(*v7);
free(v7);
}
free(*((void **)ptr + 11));
free(ptr);
}

original_code:
void free_config(struct mconfig *cfg) {
 struct st_ips *ipcfg, *ipcfg_tmp;
 free(cfg->cfg_file);
 if (cfg->dbHost) free(cfg->dbHost);
 if (cfg->dbUser) free(cfg->dbUser);
 if (cfg->dbPass) free(cfg->dbPass);
 if (cfg->dbDatabase) free(cfg->dbDatabase);
 free_st_server(cfg->smtp);
 free_st_server(cfg->pop3);
 free_st_server(cfg->imap);
 free_st_server(cfg->rad);
 ipcfg = cfg->allow_ips_head;
 while (ipcfg) {
  ipcfg_tmp = ipcfg;
  ipcfg = ipcfg->next;
  if (ipcfg_tmp) {
   free(ipcfg_tmp->ip);
   free(ipcfg_tmp);
  }
 }
 free(cfg->allow_ips);
 free(cfg);
 cfg = ((void *)0);
}

canonical_original_code:
void free_config(struct mconfig *cfg) {
 struct st_ips *ipcfg; struct st_ips *ipcfg_tmp;
 free(cfg->cfg_file);
 if (cfg->dbHost) free(cfg->dbHost);
 if (cfg->dbUser) free(cfg->dbUser);
 if (cfg->dbPass) free(cfg->dbPass);
 if (cfg->dbDatabase) free(cfg->dbDatabase);
 free_st_server(cfg->smtp);
 free_st_server(cfg->pop3);
 free_st_server(cfg->imap);
 free_st_server(cfg->rad);
 ipcfg = cfg->allow_ips_head;
 while (ipcfg) {
  ipcfg_tmp = ipcfg;
  ipcfg = ipcfg->next;
  if (ipcfg_tmp) {
   free(ipcfg_tmp->ip);
   free(ipcfg_tmp);
  }
 }
 free(cfg->allow_ips);
 free(cfg);
 cfg = ((void *)0);
}


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

result = malloc(0x30uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
*((_DWORD *)result + 10) = 0;
return result;
}

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

result = malloc(0x30uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
*((_DWORD *)result + 10) = 0;
return result;
}

original_code:
struct st_server *new_st_server() {
 struct st_server *st;
 st = (void *) malloc(sizeof(struct st_server));
 st->host = ((void *)0);
 st->user = ((void *)0);
 st->pass = ((void *)0);
 st->email = ((void *)0);
 st->secret = ((void *)0);
 st->port = 0;
 return st;
}

return_type: struct st_server { char *host; int port; } *


decompiled_code:
__int64 __fastcall check_smtp(char *cp)
{
unsigned int v2; // ebx
int v3; // eax
unsigned int v4; // edx
void *v5; // rdi
void *v6; // rdi
void *v7; // rdi
void *v8; // rdi
void *v9; // rdi
void *v10; // rdi
char v12[1024]; // [rsp+0h] [rbp-428h] BYREF
struct sockaddr addr; // [rsp+400h] [rbp-28h] BYREF

*(_QWORD *)&addr.sa_data[6] = 0LL;
v2 = socket(2, 1, 0);
fcntl(v2, 4, 2048LL);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(25);
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
connect(v2, &addr, 0x10u);
if ( (unsigned int)wait_io(1LL, v2, 4LL, 0LL) == -1 )
{
shutdown(v2, 2);
close(v2);
v4 = 1;
}
else
{
v3 = read(v2, v12, 0x400uLL);
v4 = 1;
if ( v3 != -1 )
{
if ( v3 > 0 )
v12[v3] = 0;
sprintf(v12, "HELO %s\r\n", cp);
v5 = (void *)net_request(v2, v12);
if ( !v5 )
goto LABEL_14;
free(v5);
sprintf(v12, "MAIL FROM:<%s@%s>\r\n", *(const char **)(*(_QWORD *)(main_config + 48LL) + 8LL), cp);
v6 = (void *)net_request(v2, v12);
if ( !v6 )
goto LABEL_14;
free(v6);
sprintf(v12, "RCPT TO:<%s@%s>\r\n", *(const char **)(*(_QWORD *)(main_config + 48LL) + 8LL), cp);
v7 = (void *)net_request(v2, v12);
if ( !v7 )
goto LABEL_14;
free(v7);
strcpy(v12, "DATA\r\n");
v8 = (void *)net_request(v2, v12);
if ( !v8 )
goto LABEL_14;
free(v8);
sprintf(
v12,
"To: <%s>\r\nFrom: <%s>\r\nSubject: smtp test message\r\n\r\nThis is a test\r\n.\r\n",
*(const char **)(*(_QWORD *)(main_config + 48LL) + 8LL),
*(const char **)(*(_QWORD *)(main_config + 48LL) + 8LL));
v9 = (void *)net_request(v2, v12);
if ( v9 && (free(v9), strcpy(v12, "QUIT\r\n"), (v10 = (void *)net_request(v2, v12)) != 0LL) )
{
free(v10);
shutdown(v2, 2);
close(v2);
v4 = 0;
}
else
{
LABEL_14:
shutdown(v2, 2);
close(v2);
v4 = 1;
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *cp)
{
unsigned int v2; // ebx
int v3; // eax
unsigned int v4; // edx
void *v5; // rdi
void *v6; // rdi
void *v7; // rdi
void *v8; // rdi
void *v9; // rdi
void *v10; // rdi
char v12[1024]; // [rsp+0h] [rbp-428h] BYREF
struct sockaddr addr; // [rsp+400h] [rbp-28h] BYREF

*(_QWORD *)&addr.sa_data[6] = 0LL;
v2 = socket(2, 1, 0);
fcntl(v2, 4, 2048LL);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(25);
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
connect(v2, &addr, 0x10u);
if ( (unsigned int)wait_io(1LL, v2, 4LL, 0LL) == -1 )
{
shutdown(v2, 2);
close(v2);
v4 = 1;
}
else
{
v3 = read(v2, v12, 0x400uLL);
v4 = 1;
if ( v3 != -1 )
{
if ( v3 > 0 )
v12[v3] = 0;
sprintf(v12, "HELO %s\r\n", cp);
v5 = (void *)net_request(v2, v12);
if ( !v5 )
goto LABEL_14;
free(v5);
sprintf(v12, "MAIL FROM:<%s@%s>\r\n", *(const char **)(*(_QWORD *)(main_config + 48LL) + 8LL), cp);
v6 = (void *)net_request(v2, v12);
if ( !v6 )
goto LABEL_14;
free(v6);
sprintf(v12, "RCPT TO:<%s@%s>\r\n", *(const char **)(*(_QWORD *)(main_config + 48LL) + 8LL), cp);
v7 = (void *)net_request(v2, v12);
if ( !v7 )
goto LABEL_14;
free(v7);
strcpy(v12, "DATA\r\n");
v8 = (void *)net_request(v2, v12);
if ( !v8 )
goto LABEL_14;
free(v8);
sprintf(
v12,
"To: <%s>\r\nFrom: <%s>\r\nSubject: smtp test message\r\n\r\nThis is a test\r\n.\r\n",
*(const char **)(*(_QWORD *)(main_config + 48LL) + 8LL),
*(const char **)(*(_QWORD *)(main_config + 48LL) + 8LL));
v9 = (void *)net_request(v2, v12);
if ( v9 && (free(v9), strcpy(v12, "QUIT\r\n"), (v10 = (void *)net_request(v2, v12)) != 0LL) )
{
free(v10);
shutdown(v2, 2);
close(v2);
v4 = 0;
}
else
{
LABEL_14:
shutdown(v2, 2);
close(v2);
v4 = 1;
}
}
}
return v4;
}

original_code:
int check_smtp(char *host) {
 int sockfd, s;
 struct sockaddr_in dest_addr;
 char buf[1024];
 char *tmp;
 memset(&dest_addr, 0, sizeof(struct sockaddr_in));
 sockfd = socket(2, SOCK_STREAM, 0);
 fcntl(sockfd, 4, 04000);
 dest_addr.sin_family = 2;
 dest_addr.sin_port = htons(25);
        dest_addr.sin_addr.s_addr = inet_addr(host);
 connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
 if (wait_io(1, sockfd, 4, 0) == -1) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 s = read(sockfd, &buf, sizeof(buf));
 if (s == -1) return 1;
 if (s > 0) {
  buf[s] = '\0';
 }
 sprintf(buf, "HELO %s\r\n", host);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 sprintf(buf, "MAIL FROM:<%s@%s>\r\n", main_config->smtp->user, host);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 sprintf(buf, "RCPT TO:<%s@%s>\r\n", main_config->smtp->user, host);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 sprintf(buf, "DATA\r\n");
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 sprintf(buf,
  "To: <%s>\r\nFrom: <%s>\r\nSubject: smtp test message\r\n\r\nThis is a test\r\n.\r\n",
   main_config->smtp->user, main_config->smtp->user);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 sprintf(buf, "QUIT\r\n");
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 shutdown(sockfd, 2);
 close(sockfd);
 return 0;
}

canonical_original_code:
int check_smtp(char *host) {
 int sockfd; int s;
 struct sockaddr_in dest_addr;
 char buf[1024];
 char *tmp;
 memset(&dest_addr, 0, sizeof(struct sockaddr_in));
 sockfd = socket(2, SOCK_STREAM, 0);
 fcntl(sockfd, 4, 04000);
 dest_addr.sin_family = 2;
 dest_addr.sin_port = htons(25);
        dest_addr.sin_addr.s_addr = inet_addr(host);
 connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
 if (wait_io(1, sockfd, 4, 0) == -1) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 s = read(sockfd, &buf, sizeof(buf));
 if (s == -1) return 1;
 if (s > 0) {
  buf[s] = '\0';
 }
 sprintf(buf, "HELO %s\r\n", host);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 sprintf(buf, "MAIL FROM:<%s@%s>\r\n", main_config->smtp->user, host);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 sprintf(buf, "RCPT TO:<%s@%s>\r\n", main_config->smtp->user, host);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 sprintf(buf, "DATA\r\n");
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 sprintf(buf,
  "To: <%s>\r\nFrom: <%s>\r\nSubject: smtp test message\r\n\r\nThis is a test\r\n.\r\n",
   main_config->smtp->user, main_config->smtp->user);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 sprintf(buf, "QUIT\r\n");
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 shutdown(sockfd, 2);
 close(sockfd);
 return 0;
}

variable_types:
host
char *

variable_types: sockfd int

variable_types: s int

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

variable_types:
buf
char [1024]

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

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


decompiled_code:
_BOOL8 __fastcall check_pop3(char *cp)
{
unsigned int v1; // ebx
int v2; // eax
_BOOL4 v3; // ebp
void *v4; // rax
void *v5; // rbp
void *v6; // rax
void *v7; // r13
bool v8; // zf
__int64 v9; // rax
void *v10; // r12
void *v11; // rdi
void *v13; // rdi
char v14; // [rsp+8h] [rbp-440h] BYREF
int v15; // [rsp+Ch] [rbp-43Ch] BYREF
__int64 buf[128]; // [rsp+10h] [rbp-438h] BYREF
struct sockaddr addr; // [rsp+410h] [rbp-38h] BYREF

*(_QWORD *)&addr.sa_data[6] = 0LL;
v1 = socket(2, 1, 0);
fcntl(v1, 4, 2048LL);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(110);
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
connect(v1, &addr, 0x10u);
if ( (unsigned int)wait_io(1LL, v1, 4LL, 0LL) == -1 )
{
shutdown(v1, 2);
close(v1);
return 1;
}
v2 = read(v1, buf, 0x400uLL);
v3 = 1;
if ( v2 != -1 )
{
if ( v2 > 0 )
*((_BYTE *)buf + v2) = 0;
sprintf((char *)buf, "USER %s\r\n", *(const char **)(*(_QWORD *)(main_config + 56LL) + 8LL));
v4 = (void *)net_request(v1, buf);
v5 = v4;
if ( !v4 )
goto LABEL_20;
if ( memcmp("+OK", v4, 3uLL) )
{
shutdown(v1, 2);
close(v1);
free(v5);
return 0;
}
free(v4);
sprintf((char *)buf, "PASS %s\r\n", *(const char **)(*(_QWORD *)(main_config + 56LL) + 16LL));
v6 = (void *)net_request(v1, buf);
v7 = v6;
if ( !v6 )
goto LABEL_20;
v8 = memcmp("+OK", v6, 3uLL) == 0;
v3 = !v8;
if ( !v8 )
{
shutdown(v1, 2);
close(v1);
free(v7);
return 0;
}
free(v6);
strcpy((char *)buf, "STAT\r\n");
v9 = net_request(v1, buf);
v10 = (void *)v9;
if ( !v9 )
{
LABEL_20:
shutdown(v1, 2);
close(v1);
return 1;
}
if ( (unsigned int)_isoc99_sscanf(v9, "%*s %d %d", &v15, &v14) == 2 )
{
free(v10);
if ( v15 > 0 )
{
strcpy((char *)buf, "DELE 1\r\n");
v13 = (void *)net_request(v1, buf);
if ( !v13 )
goto LABEL_24;
free(v13);
}
}
else
{
free(v10);
}
strcpy((char *)buf, "QUIT\r\n");
v11 = (void *)net_request(v1, buf);
if ( v11 )
{
free(v11);
shutdown(v1, 2);
close(v1);
return v3;
}
LABEL_24:
shutdown(v1, 2);
close(v1);
v3 = 1;
}
return v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char *cp)
{
unsigned int v1; // ebx
int v2; // eax
_BOOL4 v3; // ebp
void *v4; // rax
void *v5; // rbp
void *v6; // rax
void *v7; // r13
bool v8; // zf
__int64 v9; // rax
void *v10; // r12
void *v11; // rdi
void *v13; // rdi
char v14; // [rsp+8h] [rbp-440h] BYREF
int v15; // [rsp+Ch] [rbp-43Ch] BYREF
__int64 buf[128]; // [rsp+10h] [rbp-438h] BYREF
struct sockaddr addr; // [rsp+410h] [rbp-38h] BYREF

*(_QWORD *)&addr.sa_data[6] = 0LL;
v1 = socket(2, 1, 0);
fcntl(v1, 4, 2048LL);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(110);
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
connect(v1, &addr, 0x10u);
if ( (unsigned int)wait_io(1LL, v1, 4LL, 0LL) == -1 )
{
shutdown(v1, 2);
close(v1);
return 1;
}
v2 = read(v1, buf, 0x400uLL);
v3 = 1;
if ( v2 != -1 )
{
if ( v2 > 0 )
*((_BYTE *)buf + v2) = 0;
sprintf((char *)buf, "USER %s\r\n", *(const char **)(*(_QWORD *)(main_config + 56LL) + 8LL));
v4 = (void *)net_request(v1, buf);
v5 = v4;
if ( !v4 )
goto LABEL_20;
if ( memcmp("+OK", v4, 3uLL) )
{
shutdown(v1, 2);
close(v1);
free(v5);
return 0;
}
free(v4);
sprintf((char *)buf, "PASS %s\r\n", *(const char **)(*(_QWORD *)(main_config + 56LL) + 16LL));
v6 = (void *)net_request(v1, buf);
v7 = v6;
if ( !v6 )
goto LABEL_20;
v8 = memcmp("+OK", v6, 3uLL) == 0;
v3 = !v8;
if ( !v8 )
{
shutdown(v1, 2);
close(v1);
free(v7);
return 0;
}
free(v6);
strcpy((char *)buf, "STAT\r\n");
v9 = net_request(v1, buf);
v10 = (void *)v9;
if ( !v9 )
{
LABEL_20:
shutdown(v1, 2);
close(v1);
return 1;
}
if ( (unsigned int)_isoc99_sscanf(v9, "%*s %d %d", &v15, &v14) == 2 )
{
free(v10);
if ( v15 > 0 )
{
strcpy((char *)buf, "DELE 1\r\n");
v13 = (void *)net_request(v1, buf);
if ( !v13 )
goto LABEL_24;
free(v13);
}
}
else
{
free(v10);
}
strcpy((char *)buf, "QUIT\r\n");
v11 = (void *)net_request(v1, buf);
if ( v11 )
{
free(v11);
shutdown(v1, 2);
close(v1);
return v3;
}
LABEL_24:
shutdown(v1, 2);
close(v1);
v3 = 1;
}
return v3;
}

original_code:
int check_pop3(char *host) {
 int sockfd, s;
 struct sockaddr_in dest_addr;
 char buf[1024];
 char *tmp = ((void *)0);
 int msg_count, box_size;
 memset(&dest_addr, 0, sizeof(struct sockaddr_in));
 sockfd = socket(2, SOCK_STREAM, 0);
 fcntl(sockfd, 4, 04000);
 dest_addr.sin_family = 2;
 dest_addr.sin_port = htons(110);
        dest_addr.sin_addr.s_addr = inet_addr(host);
 connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
 if (wait_io(1, sockfd, 4, 0) == -1) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 s = read(sockfd, &buf, sizeof(buf));
 if (s == -1) {
  return 1;
 }
 if (s > 0) {
  buf[s] = '\0';
 }
 sprintf(buf, "USER %s\r\n", main_config->pop3->user);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 if (strncmp("+OK", tmp, 3) != 0) {
  shutdown(sockfd, 2);
  close(sockfd);
  free(tmp);
  return 0;
 }
 free(tmp);
 sprintf(buf, "PASS %s\r\n", main_config->pop3->pass);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 if (strncmp("+OK", tmp, 3) != 0) {
  shutdown(sockfd, 2);
  close(sockfd);
  free(tmp);
  return 0;
 }
 free(tmp);
 sprintf(buf, "STAT\r\n");
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 s = sscanf(tmp, "%*s %d %d", &msg_count, &box_size);
 if (s == 2) {
  free(tmp);
  if (msg_count > 0) {
   sprintf(buf, "DELE 1\r\n");
   if (!(tmp = net_request(sockfd, buf))) {
    shutdown(sockfd, 2);
    close(sockfd);
    return 1;
   }
   free(tmp);
  }
 } else {
  free(tmp);
 }
 sprintf(buf, "QUIT\r\n");
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 shutdown(sockfd, 2);
 close(sockfd);
 return 0;
}

canonical_original_code:
int check_pop3(char *host) {
 int sockfd; int s;
 struct sockaddr_in dest_addr;
 char buf[1024];
 char *tmp = ((void *)0);
 int msg_count; int box_size;
 memset(&dest_addr, 0, sizeof(struct sockaddr_in));
 sockfd = socket(2, SOCK_STREAM, 0);
 fcntl(sockfd, 4, 04000);
 dest_addr.sin_family = 2;
 dest_addr.sin_port = htons(110);
        dest_addr.sin_addr.s_addr = inet_addr(host);
 connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
 if (wait_io(1, sockfd, 4, 0) == -1) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 s = read(sockfd, &buf, sizeof(buf));
 if (s == -1) {
  return 1;
 }
 if (s > 0) {
  buf[s] = '\0';
 }
 sprintf(buf, "USER %s\r\n", main_config->pop3->user);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 if (strncmp("+OK", tmp, 3) != 0) {
  shutdown(sockfd, 2);
  close(sockfd);
  free(tmp);
  return 0;
 }
 free(tmp);
 sprintf(buf, "PASS %s\r\n", main_config->pop3->pass);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 if (strncmp("+OK", tmp, 3) != 0) {
  shutdown(sockfd, 2);
  close(sockfd);
  free(tmp);
  return 0;
 }
 free(tmp);
 sprintf(buf, "STAT\r\n");
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 s = sscanf(tmp, "%*s %d %d", &msg_count, &box_size);
 if (s == 2) {
  free(tmp);
  if (msg_count > 0) {
   sprintf(buf, "DELE 1\r\n");
   if (!(tmp = net_request(sockfd, buf))) {
    shutdown(sockfd, 2);
    close(sockfd);
    return 1;
   }
   free(tmp);
  }
 } else {
  free(tmp);
 }
 sprintf(buf, "QUIT\r\n");
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 shutdown(sockfd, 2);
 close(sockfd);
 return 0;
}


decompiled_code:
int __fastcall wait_io(unsigned int a1, int a2, int a3, int a4)
{
__int64 v4; // rbp
int result; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

if ( a1 > 1 )
return -1;
v6.tv_sec = a3;
v6.tv_usec = a4;
memset(&readfds, 0, sizeof(readfds));
v4 = 1LL << (a2 % 64);
readfds.fds_bits[a2 / 64] |= v4;
if ( a1 )
result = select(a2 + 1, &readfds, 0LL, 0LL, &v6);
else
result = select(a2 + 1, 0LL, &readfds, 0LL, &v6);
if ( result != -1 )
result = -((readfds.fds_bits[a2 / 64] & v4) == 0);
return result;
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1, int a2, int a3, int a4)
{
__int64 v4; // rbp
int result; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

if ( a1 > 1 )
return -1;
v6.tv_sec = a3;
v6.tv_usec = a4;
memset(&readfds, 0, sizeof(readfds));
v4 = 1LL << (a2 % 64);
readfds.fds_bits[a2 / 64] |= v4;
if ( a1 )
result = select(a2 + 1, &readfds, 0LL, 0LL, &v6);
else
result = select(a2 + 1, 0LL, &readfds, 0LL, &v6);
if ( result != -1 )
result = -((readfds.fds_bits[a2 / 64] & v4) == 0);
return result;
}

original_code:
int wait_io(int mode, int sockfd, int timeout_sec, int timeout_usec) {
 int r;
 fd_set fds;
 struct timeval timeout;
 if (mode != 0 && mode != 1) return -1;
 timeout.tv_sec = timeout_sec;
 timeout.tv_usec = timeout_usec;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fds)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
 if (mode == 0) {
  r = select(sockfd + 1, ((void *)0), &fds, ((void *)0), &timeout);
 } else if (mode == 1) {
  r = select(sockfd + 1, &fds, ((void *)0), ((void *)0), &timeout);
 }
 if (r == -1) return -1;
 if (((((&fds)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
  return 0;
 } else {
  return -1;
 }
}

canonical_original_code:
int wait_io(int mode, int sockfd, int timeout_sec, int timeout_usec) {
 int r;
 struct fd_set fds;
 struct timeval timeout;
 if (mode != 0 && mode != 1) return -1;
 timeout.tv_sec = timeout_sec;
 timeout.tv_usec = timeout_usec;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fds)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
 if (mode == 0) {
  r = select(sockfd + 1, ((void *)0), &fds, ((void *)0), &timeout);
 } else if (mode == 1) {
  r = select(sockfd + 1, &fds, ((void *)0), ((void *)0), &timeout);
 }
 if (r == -1) return -1;
 if (((((&fds)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
  return 0;
 } else {
  return -1;
 }
}

variable_types: mode int

variable_types: r int

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

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


decompiled_code:
void *__fastcall net_request(int fd, void *buf)
{
size_t v2; // rax
void *v3; // rbp
int v4; // eax

if ( wait_io(0, fd, 4, 0) == -1 )
return 0LL;
v2 = strlen((const char *)buf);
send(fd, buf, v2, 0);
if ( wait_io(1u, fd, 4, 0) == -1 )
{
close(fd);
v3 = 0LL;
}
else
{
v3 = malloc(0x400uLL);
v4 = read(fd, v3, 0x400uLL);
if ( v4 == -1 || !v4 )
{
free(v3);
v3 = 0LL;
}
else if ( v4 <= 0 )
{
v3 = 0LL;
}
else
{
*((_BYTE *)v3 + v4) = 0;
}
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func1(int fd, void *buf)
{
size_t v2; // rax
void *v3; // rbp
int v4; // eax

if ( func0(0, fd, 4, 0) == -1 )
return 0LL;
v2 = strlen((const char *)buf);
send(fd, buf, v2, 0);
if ( func0(1u, fd, 4, 0) == -1 )
{
close(fd);
v3 = 0LL;
}
else
{
v3 = malloc(0x400uLL);
v4 = read(fd, v3, 0x400uLL);
if ( v4 == -1 || !v4 )
{
free(v3);
v3 = 0LL;
}
else if ( v4 <= 0 )
{
v3 = 0LL;
}
else
{
*((_BYTE *)v3 + v4) = 0;
}
}
return v3;
}

original_code:
char *net_request(int sock, char *req) {
 int r, s;
 char *buffer = ((void *)0);
 if (wait_io(0, sock, 4, 0) == -1) {
  return ((void *)0);
 }
 r = send(sock, req, strlen(req), 0);
 if (wait_io(1, sock, 4, 0) == -1) {
  close(sock);
  return ((void *)0);
 }
 buffer = (void *) malloc(1024);
 s = read(sock, buffer, 1024);
 if (s == -1) {
  free(buffer);
  return ((void *)0);
 }
 if (s == 0) {
  free(buffer);
  return ((void *)0);
 }
 if (s > 0) {
  *(buffer + s) = '\0';
  return buffer;
 }
 return ((void *)0);
}

canonical_original_code:
char *net_request(int sock, char *req) {
 int r; int s;
 char *buffer = ((void *)0);
 if (wait_io(0, sock, 4, 0) == -1) {
  return ((void *)0);
 }
 r = send(sock, req, strlen(req), 0);
 if (wait_io(1, sock, 4, 0) == -1) {
  close(sock);
  return ((void *)0);
 }
 buffer = (void *) malloc(1024);
 s = read(sock, buffer, 1024);
 if (s == -1) {
  free(buffer);
  return ((void *)0);
 }
 if (s == 0) {
  free(buffer);
  return ((void *)0);
 }
 if (s > 0) {
  *(buffer + s) = '\0';
  return buffer;
 }
 return ((void *)0);
}

variable_types: sock int

variable_types:
req
char *

variable_types:
buffer
char *

return_type: char *


decompiled_code:
__int64 __fastcall check_port(const char *a1, __int16 a2)
{
struct hostent *v2; // rax
unsigned int v3; // ebp
struct hostent *v4; // r13
int v5; // ebx
int v6; // er12
__int64 v7; // r13
int v8; // eax
char buf; // [rsp+Fh] [rbp-149h] BYREF
struct timeval timeout; // [rsp+10h] [rbp-148h] BYREF
fd_set writefds; // [rsp+20h] [rbp-138h] BYREF
fd_set readfds; // [rsp+A0h] [rbp-B8h] BYREF
struct sockaddr addr; // [rsp+120h] [rbp-38h] BYREF

*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v2 = gethostbyname(a1);
v3 = -1;
if ( v2 )
{
v4 = v2;
v5 = socket(2, 1, 0);
fcntl(v5, 4, 2048LL);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a2);
*(_DWORD *)&addr.sa_data[2] = **(_DWORD **)v4->h_addr_list;
connect(v5, &addr, 0x10u);
timeout.tv_sec = 4LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
v6 = v5 / 64;
v7 = 1LL << (v5 % 64);
readfds.fds_bits[v6] |= v7;
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v6] |= v7;
v8 = select(v5 + 1, &readfds, &writefds, 0LL, &timeout);
v3 = v8;
if ( v8 == -1 )
{
shutdown(v5, 2);
close(v5);
}
else if ( v8 > 0 && ((readfds.fds_bits[v6] & v7) != 0 || (writefds.fds_bits[v6] & v7) != 0) )
{
v3 = 1;
if ( (unsigned int)recv(v5, &buf, 1uLL, 2) == -1 )
v3 = *_errno_location() != 111;
shutdown(v5, 2);
close(v5);
}
else
{
shutdown(v5, 2);
close(v5);
v3 = 0;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int16 a2)
{
struct hostent *v2; // rax
unsigned int v3; // ebp
struct hostent *v4; // r13
int v5; // ebx
int v6; // er12
__int64 v7; // r13
int v8; // eax
char buf; // [rsp+Fh] [rbp-149h] BYREF
struct timeval timeout; // [rsp+10h] [rbp-148h] BYREF
fd_set writefds; // [rsp+20h] [rbp-138h] BYREF
fd_set readfds; // [rsp+A0h] [rbp-B8h] BYREF
struct sockaddr addr; // [rsp+120h] [rbp-38h] BYREF

*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v2 = gethostbyname(a1);
v3 = -1;
if ( v2 )
{
v4 = v2;
v5 = socket(2, 1, 0);
fcntl(v5, 4, 2048LL);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(a2);
*(_DWORD *)&addr.sa_data[2] = **(_DWORD **)v4->h_addr_list;
connect(v5, &addr, 0x10u);
timeout.tv_sec = 4LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
v6 = v5 / 64;
v7 = 1LL << (v5 % 64);
readfds.fds_bits[v6] |= v7;
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v6] |= v7;
v8 = select(v5 + 1, &readfds, &writefds, 0LL, &timeout);
v3 = v8;
if ( v8 == -1 )
{
shutdown(v5, 2);
close(v5);
}
else if ( v8 > 0 && ((readfds.fds_bits[v6] & v7) != 0 || (writefds.fds_bits[v6] & v7) != 0) )
{
v3 = 1;
if ( (unsigned int)recv(v5, &buf, 1uLL, 2) == -1 )
v3 = *_errno_location() != 111;
shutdown(v5, 2);
close(v5);
}
else
{
shutdown(v5, 2);
close(v5);
v3 = 0;
}
}
return v3;
}

original_code:
int check_port(char *host, int port) {
 int sockfd, r;
 struct sockaddr_in dest_addr;
 struct hostent *hp;
 fd_set rfds, wfds;
 struct timeval timeout;
 int rc;
 char tmp;
 memset(&dest_addr, 0, sizeof(struct sockaddr_in));
 if ((hp = gethostbyname(host)) == ((void *)0)) {
  return -1;
 }
 sockfd = socket(2, SOCK_STREAM, 0);
 fcntl(sockfd, 4, 04000);
 dest_addr.sin_family = 2;
 dest_addr.sin_port = htons(port);
 dest_addr.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr_list[0]))->s_addr;
 connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
 timeout.tv_sec = 4;
 timeout.tv_usec = 0;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rfds)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&wfds)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
 r = select(sockfd + 1, &rfds, &wfds, ((void *)0), &timeout);
 if (r == -1) {
  shutdown(sockfd, 2);
  close(sockfd);
  return -1;
 }
 if (r > 0) {
  if (((((&rfds)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0) || ((((&wfds)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   rc = 1;
   r = recv(sockfd, &tmp, 1, MSG_PEEK);
   if (r == -1) {
    if ((*__errno_location ()) == 111) {
     rc = 0;
    }
   }
   shutdown(sockfd, 2);
   close(sockfd);
   return rc;
  }
 }
 shutdown(sockfd, 2);
 close(sockfd);
 return 0;
}

canonical_original_code:
int check_port(char *host, int port) {
 int sockfd; int r;
 struct sockaddr_in dest_addr;
 struct hostent *hp;
 struct fd_set rfds; struct fd_set wfds;
 struct timeval timeout;
 int rc;
 char tmp;
 memset(&dest_addr, 0, sizeof(struct sockaddr_in));
 if ((hp = gethostbyname(host)) == ((void *)0)) {
  return -1;
 }
 sockfd = socket(2, SOCK_STREAM, 0);
 fcntl(sockfd, 4, 04000);
 dest_addr.sin_family = 2;
 dest_addr.sin_port = htons(port);
 dest_addr.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr_list[0]))->s_addr;
 connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
 timeout.tv_sec = 4;
 timeout.tv_usec = 0;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rfds)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&wfds)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
 r = select(sockfd + 1, &rfds, &wfds, ((void *)0), &timeout);
 if (r == -1) {
  shutdown(sockfd, 2);
  close(sockfd);
  return -1;
 }
 if (r > 0) {
  if (((((&rfds)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0) || ((((&wfds)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   rc = 1;
   r = recv(sockfd, &tmp, 1, MSG_PEEK);
   if (r == -1) {
    if ((*__errno_location ()) == 111) {
     rc = 0;
    }
   }
   shutdown(sockfd, 2);
   close(sockfd);
   return rc;
  }
 }
 shutdown(sockfd, 2);
 close(sockfd);
 return 0;
}

variable_types: port int

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

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

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

variable_types: rc int

variable_types: tmp char


decompiled_code:
_BOOL8 __fastcall check_imap(char *cp)
{
unsigned int v1; // ebx
int v2; // eax
_BOOL4 v3; // ebp
void *v4; // rax
void *v5; // r12
bool v6; // zf
void *v7; // rdi
char v9[1024]; // [rsp+0h] [rbp-428h] BYREF
struct sockaddr addr; // [rsp+400h] [rbp-28h] BYREF

*(_QWORD *)&addr.sa_data[6] = 0LL;
v1 = socket(2, 1, 0);
fcntl(v1, 4, 2048LL);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(143);
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
connect(v1, &addr, 0x10u);
if ( (unsigned int)wait_io(1LL, v1, 4LL, 0LL) == -1 )
{
shutdown(v1, 2);
close(v1);
v3 = 1;
}
else
{
v2 = read(v1, v9, 0x400uLL);
v3 = 1;
if ( v2 != -1 )
{
if ( v2 > 0 )
v9[v2] = 0;
sprintf(
v9,
"A00001 LOGIN %s %s\r\n",
*(const char **)(*(_QWORD *)(main_config + 64LL) + 8LL),
*(const char **)(*(_QWORD *)(main_config + 64LL) + 16LL));
v4 = (void *)net_request(v1, v9);
v5 = v4;
if ( v4 )
{
v6 = memcmp("A00001 OK", v4, 9uLL) == 0;
v3 = !v6;
if ( v6 )
{
free(v4);
strcpy(v9, "A00002 LIST \"\" \"%%\"\r\n");
v7 = (void *)net_request(v1, v9);
if ( v7 )
free(v7);
shutdown(v1, 2);
close(v1);
}
else
{
shutdown(v1, 2);
close(v1);
free(v5);
v3 = 0;
}
}
else
{
shutdown(v1, 2);
close(v1);
v3 = 0;
}
}
}
return v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char *cp)
{
unsigned int v1; // ebx
int v2; // eax
_BOOL4 v3; // ebp
void *v4; // rax
void *v5; // r12
bool v6; // zf
void *v7; // rdi
char v9[1024]; // [rsp+0h] [rbp-428h] BYREF
struct sockaddr addr; // [rsp+400h] [rbp-28h] BYREF

*(_QWORD *)&addr.sa_data[6] = 0LL;
v1 = socket(2, 1, 0);
fcntl(v1, 4, 2048LL);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(143);
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
connect(v1, &addr, 0x10u);
if ( (unsigned int)wait_io(1LL, v1, 4LL, 0LL) == -1 )
{
shutdown(v1, 2);
close(v1);
v3 = 1;
}
else
{
v2 = read(v1, v9, 0x400uLL);
v3 = 1;
if ( v2 != -1 )
{
if ( v2 > 0 )
v9[v2] = 0;
sprintf(
v9,
"A00001 LOGIN %s %s\r\n",
*(const char **)(*(_QWORD *)(main_config + 64LL) + 8LL),
*(const char **)(*(_QWORD *)(main_config + 64LL) + 16LL));
v4 = (void *)net_request(v1, v9);
v5 = v4;
if ( v4 )
{
v6 = memcmp("A00001 OK", v4, 9uLL) == 0;
v3 = !v6;
if ( v6 )
{
free(v4);
strcpy(v9, "A00002 LIST \"\" \"%%\"\r\n");
v7 = (void *)net_request(v1, v9);
if ( v7 )
free(v7);
shutdown(v1, 2);
close(v1);
}
else
{
shutdown(v1, 2);
close(v1);
free(v5);
v3 = 0;
}
}
else
{
shutdown(v1, 2);
close(v1);
v3 = 0;
}
}
}
return v3;
}

original_code:
int check_imap(char *host) {
 int sockfd, s;
 struct sockaddr_in dest_addr;
 char buf[1024];
 char *tmp;
 memset(&dest_addr, 0, sizeof(struct sockaddr_in));
 sockfd = socket(2, SOCK_STREAM, 0);
 fcntl(sockfd, 4, 04000);
 dest_addr.sin_family = 2;
 dest_addr.sin_port = htons(143);
 dest_addr.sin_addr.s_addr = inet_addr(host);
 connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
 if (wait_io(1, sockfd, 4, 0) == -1) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 s = read(sockfd, &buf, sizeof(buf));
 if (s == -1) return 1;
 if (s > 0) {
  buf[s] = '\0';
 }
 sprintf(buf, "A00001 LOGIN %s %s\r\n", main_config->imap->user, main_config->imap->pass);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 0;
 }
 if (strncmp("A00001 OK", tmp, 9) != 0) {
  shutdown(sockfd, 2);
  close(sockfd);
  free(tmp);
  return 0;
 }
 free(tmp);
 strcpy(buf, "A00002 LIST \"\" \"%%\"\r\n");
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  free(tmp);
  return 0;
 }
 free(tmp);
 shutdown(sockfd, 2);
 close(sockfd);
 return 0;
}

canonical_original_code:
int check_imap(char *host) {
 int sockfd; int s;
 struct sockaddr_in dest_addr;
 char buf[1024];
 char *tmp;
 memset(&dest_addr, 0, sizeof(struct sockaddr_in));
 sockfd = socket(2, SOCK_STREAM, 0);
 fcntl(sockfd, 4, 04000);
 dest_addr.sin_family = 2;
 dest_addr.sin_port = htons(143);
 dest_addr.sin_addr.s_addr = inet_addr(host);
 connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
 if (wait_io(1, sockfd, 4, 0) == -1) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 s = read(sockfd, &buf, sizeof(buf));
 if (s == -1) return 1;
 if (s > 0) {
  buf[s] = '\0';
 }
 sprintf(buf, "A00001 LOGIN %s %s\r\n", main_config->imap->user, main_config->imap->pass);
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 0;
 }
 if (strncmp("A00001 OK", tmp, 9) != 0) {
  shutdown(sockfd, 2);
  close(sockfd);
  free(tmp);
  return 0;
 }
 free(tmp);
 strcpy(buf, "A00002 LIST \"\" \"%%\"\r\n");
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  free(tmp);
  return 0;
 }
 free(tmp);
 shutdown(sockfd, 2);
 close(sockfd);
 return 0;
}

variable_types:
host
char *

variable_types: sockfd int

variable_types:
tmp
char *


decompiled_code:
_BOOL8 __fastcall check_http(char *cp)
{
unsigned int v1; // ebx
_BYTE *v2; // rax
_BYTE *v3; // rbp
_BOOL8 result; // rax
char v5[32]; // [rsp+0h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

strcpy(v5, "GET /robots.txt HTTP/1.0\r\n\r\n");
*(_QWORD *)&addr.sa_data[6] = 0LL;
v1 = socket(2, 1, 0);
fcntl(v1, 4, 2048LL);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(80);
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
connect(v1, &addr, 0x10u);
if ( (unsigned int)wait_io(0LL, v1, 4LL, 0LL) == -1 )
{
shutdown(v1, 2);
close(v1);
}
v2 = (_BYTE *)net_request(v1, v5);
v3 = v2;
if ( v2 )
{
free(v2);
shutdown(v1, 2);
close(v1);
result = *v3 == 0;
}
else
{
shutdown(v1, 2);
close(v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char *cp)
{
unsigned int v1; // ebx
_BYTE *v2; // rax
_BYTE *v3; // rbp
_BOOL8 result; // rax
char v5[32]; // [rsp+0h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

strcpy(v5, "GET /robots.txt HTTP/1.0\r\n\r\n");
*(_QWORD *)&addr.sa_data[6] = 0LL;
v1 = socket(2, 1, 0);
fcntl(v1, 4, 2048LL);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(80);
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
connect(v1, &addr, 0x10u);
if ( (unsigned int)wait_io(0LL, v1, 4LL, 0LL) == -1 )
{
shutdown(v1, 2);
close(v1);
}
v2 = (_BYTE *)net_request(v1, v5);
v3 = v2;
if ( v2 )
{
free(v2);
shutdown(v1, 2);
close(v1);
result = *v3 == 0;
}
else
{
shutdown(v1, 2);
close(v1);
result = 1LL;
}
return result;
}

original_code:
int check_http(char *host) {
 int sockfd;
 struct sockaddr_in dest_addr;
 char buf[] = "GET /robots.txt HTTP/1.0\r\n\r\n";
 char *tmp;
 memset(&dest_addr, 0, sizeof(struct sockaddr_in));
 sockfd = socket(2, SOCK_STREAM, 0);
 fcntl(sockfd, 4, 04000);
 dest_addr.sin_family = 2;
 dest_addr.sin_port = htons(80);
        dest_addr.sin_addr.s_addr = inet_addr(host);
 connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
 if (wait_io(0, sockfd, 4, 0) == -1) {
  shutdown(sockfd, 2);
  close(sockfd);
 }
 if (!(tmp = net_request(sockfd, buf))) {
  shutdown(sockfd, 2);
  close(sockfd);
  return 1;
 }
 free(tmp);
 shutdown(sockfd, 2);
 close(sockfd);
 if (strlen(tmp) == 0) {
  return 1;
 } else {
  return 0;
 }
}

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

variable_types:
buf
char []


decompiled_code:
__int64 __fastcall check_rad(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
__pid_t v4; // eax
size_t v5; // rax
int v6; // eax
char *v7; // rdi
bool v8; // zf
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-82Ch] BYREF
int v10; // [rsp+14h] [rbp-824h]
int pipedes[2]; // [rsp+18h] [rbp-820h] BYREF
char buf[1024]; // [rsp+20h] [rbp-818h] BYREF
char s[1048]; // [rsp+420h] [rbp-418h] BYREF

v2 = -1;
if ( !pipe(pipedes) && !pipe((int *)&stat_loc.__iptr + 1) )
{
v4 = fork();
if ( !v4 )
{
close(pipedes[1]);
dup2(pipedes[0], 0);
close(SHIDWORD(stat_loc.__iptr));
dup2(v10, 1);
close(2);
if ( execlp("radclient", "radclient", a1, "auth", a2, 0LL) == -1 )
write(v10, "radclient_error\n", 0x10uLL);
exit(0);
}
v2 = -1;
if ( v4 >= 0 )
{
close(pipedes[0]);
close(v10);
sprintf(
s,
"User-Name = \"%s\", Password = \"%s\"\r\n",
*(const char **)(*(_QWORD *)(main_config + 72LL) + 8LL),
*(const char **)(*(_QWORD *)(main_config + 72LL) + 16LL));
v5 = strlen(s);
write(pipedes[1], s, v5);
close(pipedes[1]);
v6 = read(SHIDWORD(stat_loc.__iptr), buf, 0x400uLL);
v2 = 1;
if ( v6 > 0 )
{
buf[v6] = 0;
v7 = strtok(buf, "\n");
if ( v7 )
{
while ( 1 )
{
v8 = memcmp(" Service-Type", v7, 0x10uLL) == 0;
v2 = !v8;
if ( v8 )
break;
v7 = strtok(0LL, "\n");
if ( !v7 )
{
v2 = 1;
break;
}
}
}
}
wait((__WAIT_STATUS)&stat_loc);
close(SHIDWORD(stat_loc.__iptr));
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
__pid_t v4; // eax
size_t v5; // rax
int v6; // eax
char *v7; // rdi
bool v8; // zf
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-82Ch] BYREF
int v10; // [rsp+14h] [rbp-824h]
int pipedes[2]; // [rsp+18h] [rbp-820h] BYREF
char buf[1024]; // [rsp+20h] [rbp-818h] BYREF
char s[1048]; // [rsp+420h] [rbp-418h] BYREF

v2 = -1;
if ( !pipe(pipedes) && !pipe((int *)&stat_loc.__iptr + 1) )
{
v4 = fork();
if ( !v4 )
{
close(pipedes[1]);
dup2(pipedes[0], 0);
close(SHIDWORD(stat_loc.__iptr));
dup2(v10, 1);
close(2);
if ( execlp("radclient", "radclient", a1, "auth", a2, 0LL) == -1 )
write(v10, "radclient_error\n", 0x10uLL);
exit(0);
}
v2 = -1;
if ( v4 >= 0 )
{
close(pipedes[0]);
close(v10);
sprintf(
s,
"User-Name = \"%s\", Password = \"%s\"\r\n",
*(const char **)(*(_QWORD *)(main_config + 72LL) + 8LL),
*(const char **)(*(_QWORD *)(main_config + 72LL) + 16LL));
v5 = strlen(s);
write(pipedes[1], s, v5);
close(pipedes[1]);
v6 = read(SHIDWORD(stat_loc.__iptr), buf, 0x400uLL);
v2 = 1;
if ( v6 > 0 )
{
buf[v6] = 0;
v7 = strtok(buf, "\n");
if ( v7 )
{
while ( 1 )
{
v8 = memcmp(" Service-Type", v7, 0x10uLL) == 0;
v2 = !v8;
if ( v8 )
break;
v7 = strtok(0LL, "\n");
if ( !v7 )
{
v2 = 1;
break;
}
}
}
}
wait((__WAIT_STATUS)&stat_loc);
close(SHIDWORD(stat_loc.__iptr));
}
}
return v2;
}

original_code:
int check_rad(char *host, char *secret) {
 char buf[1024], rbuf[1024];
 int fdin[2], fdout[2];
 int childrc, pid, nbytes;
 char *tmp;
 int r, rv = 1;
 if (pipe(fdin) != 0) return -1;
 if (pipe(fdout) != 0) return -1;
 pid = fork();
 if (pid == 0) {
  close(fdin[1]);
  dup2(fdin[0], 0);
  close(fdout[0]);
  dup2(fdout[1], 1);
  close(2);
  r = execlp("radclient", "radclient", host, "auth", secret, ((void *)0));
  if (r == -1) {
   write(fdout[1], "radclient_error\n", 16);
  }
  exit(0);
 } else if (pid < 0) {
  return -1;
 }
 if (pid) {
  close(fdin[0]);
  close(fdout[1]);
  sprintf(buf, "User-Name = \"%s\", Password = \"%s\"\r\n", main_config->rad->user, main_config->rad->pass);
  write(fdin[1], buf, strlen(buf));
  close(fdin[1]);
  nbytes = read(fdout[0], rbuf, sizeof(rbuf));
  if (nbytes > 0) {
   rbuf[nbytes] = '\0';
   tmp = strtok(rbuf, "\n");
   if (tmp) {
    while (1) {
     if (strncmp("    Service-Type", tmp, 16) == 0) {
      rv = 0;
      break;
     }
     if (!(tmp = strtok(((void *)0), "\n"))) break;
    }
   }
  }
  wait(&childrc);
 }
 close(fdout[0]);
 return rv;
}

canonical_original_code:
int check_rad(char *host, char *secret) {
 char buf[1024]; char rbuf[1024];
 int fdin[2]; int fdout[2];
 int childrc; int pid; int nbytes;
 char *tmp;
 int r; int rv = 1;
 if (pipe(fdin) != 0) return -1;
 if (pipe(fdout) != 0) return -1;
 pid = fork();
 if (pid == 0) {
  close(fdin[1]);
  dup2(fdin[0], 0);
  close(fdout[0]);
  dup2(fdout[1], 1);
  close(2);
  r = execlp("radclient", "radclient", host, "auth", secret, ((void *)0));
  if (r == -1) {
   write(fdout[1], "radclient_error\n", 16);
  }
  exit(0);
 } else if (pid < 0) {
  return -1;
 }
 if (pid) {
  close(fdin[0]);
  close(fdout[1]);
  sprintf(buf, "User-Name = \"%s\", Password = \"%s\"\r\n", main_config->rad->user, main_config->rad->pass);
  write(fdin[1], buf, strlen(buf));
  close(fdin[1]);
  nbytes = read(fdout[0], rbuf, sizeof(rbuf));
  if (nbytes > 0) {
   rbuf[nbytes] = '\0';
   tmp = strtok(rbuf, "\n");
   if (tmp) {
    while (1) {
     if (strncmp("    Service-Type", tmp, 16) == 0) {
      rv = 0;
      break;
     }
     if (!(tmp = strtok(((void *)0), "\n"))) break;
    }
   }
  }
  wait(&childrc);
 }
 close(fdout[0]);
 return rv;
}

variable_types:
secret
char *

variable_types:
buf
char [1024]

variable_types:
rbuf
char [1024]

variable_types:
fdin
int [2]

variable_types:
fdout
int [2]

variable_types: childrc int

variable_types: pid int

variable_types: nbytes int

variable_types: r int

variable_types: rv int


decompiled_code:
int __fastcall print_usage(const char *a1)
{
printf("Usage: %s [OPTION]... FILE\n", a1);
puts("Flash firmware file.\n");
puts("OPTIONS can be one of:");
puts(" -d --dev=VID:PID USB VID/PID of the device to program");
puts(" -v, --verify verify program write");
puts(" -l --verbose Verbose (loud) output");
puts(" -r, --reset reset device when done");
puts(" -h, --help print help message and exit\n");
return puts("Use a single hyphen (-) to read firmware hex file from stdin.");
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
printf("Usage: %s [OPTION]... FILE\n", a1);
puts("Flash firmware file.\n");
puts("OPTIONS can be one of:");
puts(" -d --dev=VID:PID USB VID/PID of the device to program");
puts(" -v, --verify verify program write");
puts(" -l --verbose Verbose (loud) output");
puts(" -r, --reset reset device when done");
puts(" -h, --help print help message and exit\n");
return puts("Use a single hyphen (-) to read firmware hex file from stdin.");
}

original_code:
static void print_usage(const char *prog_name)
{
 printf("Usage: %s [OPTION]... FILE\n", prog_name);
 printf("Flash firmware file.\n\n");
 printf("OPTIONS can be one of:\n");
 printf("  -d  --dev=VID:PID     USB VID/PID of the device to program\n");
 printf("  -v, --verify          verify program write\n");
 printf("  -l  --verbose         Verbose (loud) output\n");
 printf("  -r, --reset           reset device when done\n");
 printf("  -h, --help            print help message and exit\n\n");
 printf("Use a single hyphen (-) to read firmware hex file from stdin.\n");
}

canonical_original_code:
static void print_usage(char *prog_name)
{
 printf("Usage: %s [OPTION]... FILE\n", prog_name);
 printf("Flash firmware file.\n\n");
 printf("OPTIONS can be one of:\n");
 printf("  -d  --dev=VID:PID     USB VID/PID of the device to program\n");
 printf("  -v, --verify          verify program write\n");
 printf("  -l  --verbose         Verbose (loud) output\n");
 printf("  -r, --reset           reset device when done\n");
 printf("  -h, --help            print help message and exit\n\n");
 printf("Use a single hyphen (-) to read firmware hex file from stdin.\n");
}


decompiled_code:
__int64 __fastcall parse_vid_pid(char *nptr, _WORD *a2, _WORD *a3)
{
unsigned int v3; // ebp
unsigned int v4; // ebx
char *v6; // rax
char *v7; // r12
int v9; // eax
int v10; // eax
char *endptr[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = 0;
if ( *nptr )
{
v4 = (unsigned int)nptr;
v6 = strchr(nptr, 58);
v7 = v6;
if ( v6 )
{
LOBYTE(v3) = nptr == v6 || v6[1] == 0;
if ( (_BYTE)v3 )
{
v3 = 0;
}
else
{
v9 = strtol(nptr, endptr, 16);
LOBYTE(v4) = v9 > 0xFFFF || *endptr[0] != 58;
if ( !(_BYTE)v4 )
{
*a2 = v9;
v10 = strtol(v7 + 1, endptr, 16);
if ( *endptr[0] || v10 > 0xFFFF )
{
v3 = v4;
}
else
{
*a3 = v10;
v3 = 1;
}
}
}
}
else
{
v3 = 0;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *nptr, _WORD *a2, _WORD *a3)
{
unsigned int v3; // ebp
unsigned int v4; // ebx
char *v6; // rax
char *v7; // r12
int v9; // eax
int v10; // eax
char *endptr[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = 0;
if ( *nptr )
{
v4 = (unsigned int)nptr;
v6 = strchr(nptr, 58);
v7 = v6;
if ( v6 )
{
LOBYTE(v3) = nptr == v6 || v6[1] == 0;
if ( (_BYTE)v3 )
{
v3 = 0;
}
else
{
v9 = strtol(nptr, endptr, 16);
LOBYTE(v4) = v9 > 0xFFFF || *endptr[0] != 58;
if ( !(_BYTE)v4 )
{
*a2 = v9;
v10 = strtol(v7 + 1, endptr, 16);
if ( *endptr[0] || v10 > 0xFFFF )
{
v3 = v4;
}
else
{
*a3 = v10;
v3 = 1;
}
}
}
}
else
{
v3 = 0;
}
}
return v3;
}

original_code:
static _Bool parse_vid_pid(const char *str, uint16_t *vid, uint16_t *pid)
{
 const char *colon;
 char *endptr;
 int val;
 if (!*str)
  return 0;
 colon = strchr(str, ':');
 if (!colon)
  return 0;
 if (!colon[1])
  return 0;
 if (colon == str)
  return 0;
 val = strtol(str, &endptr, 16);
 if (*endptr != ':')
  return 0;
 if (val > 0xffff)
  return 0;
 *vid = val;
 val = strtol(colon+1, &endptr, 16);
 if (*endptr != '\0')
  return 0;
 if (val > 0xffff)
  return 0;
 *pid = val;
 return 1;
}

canonical_original_code:
static _Bool parse_vid_pid(char *str, unsigned short *vid, unsigned short *pid)
{
 char *colon;
 char *endptr;
 int val;
 if (!*str)
  return 0;
 colon = strchr(str, ':');
 if (!colon)
  return 0;
 if (!colon[1])
  return 0;
 if (colon == str)
  return 0;
 val = strtol(str, &endptr, 16);
 if (*endptr != ':')
  return 0;
 if (val > 0xffff)
  return 0;
 *vid = val;
 val = strtol(colon+1, &endptr, 16);
 if (*endptr != '\0')
  return 0;
 if (val > 0xffff)
  return 0;
 *pid = val;
 return 1;
}

variable_types:
str
char *

variable_types:
vid
unsigned short *

variable_types:
pid
unsigned short *

variable_types:
colon
char *

variable_types:
endptr
char *

variable_types: val int


decompiled_code:
__int64 __fastcall create_update_region(unsigned __int64 **a1, unsigned __int64 a2, unsigned __int8 a3)
{
unsigned __int64 *v6; // rax
unsigned int v7; // er11
__int64 v8; // r8
unsigned __int64 v9; // rdi
unsigned __int64 v10; // rdx
unsigned __int64 v11; // rcx
unsigned __int64 v12; // rsi
unsigned __int64 *v14; // rcx
unsigned __int64 *v15; // rax
unsigned __int64 *v16; // rdx

v6 = *a1;
if ( *a1 )
{
v7 = 0;
v8 = a3;
v9 = a3 + a2;
do
{
v10 = *v6;
v11 = v6[2];
v12 = *v6 + v11;
if ( v12 == a2 )
{
v6[2] = v8 + v11;
v7 = 1;
}
else if ( v10 == v9 )
{
*v6 = v10 - v8;
v6[2] = v8 + v11;
v7 = 1;
}
else
{
LOBYTE(v11) = v10 >= a2 && v10 < v9;
if ( (_BYTE)v11 )
return 0;
if ( v12 > a2 && v10 <= a2 )
return (unsigned int)v11;
}
v6 = (unsigned __int64 *)v6[3];
}
while ( v6 );
if ( !(_BYTE)v7 )
goto LABEL_14;
}
else
{
LABEL_14:
v14 = (unsigned __int64 *)calloc(1uLL, 0x20uLL);
*v14 = a2;
v14[2] = a3;
v15 = *a1;
if ( *a1 )
{
do
{
v16 = v15;
v15 = (unsigned __int64 *)v15[3];
}
while ( v15 );
v16[3] = (unsigned __int64)v14;
v7 = 1;
}
else
{
*a1 = v14;
v7 = 1;
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 **a1, unsigned __int64 a2, unsigned __int8 a3)
{
unsigned __int64 *v6; // rax
unsigned int v7; // er11
__int64 v8; // r8
unsigned __int64 v9; // rdi
unsigned __int64 v10; // rdx
unsigned __int64 v11; // rcx
unsigned __int64 v12; // rsi
unsigned __int64 *v14; // rcx
unsigned __int64 *v15; // rax
unsigned __int64 *v16; // rdx

v6 = *a1;
if ( *a1 )
{
v7 = 0;
v8 = a3;
v9 = a3 + a2;
do
{
v10 = *v6;
v11 = v6[2];
v12 = *v6 + v11;
if ( v12 == a2 )
{
v6[2] = v8 + v11;
v7 = 1;
}
else if ( v10 == v9 )
{
*v6 = v10 - v8;
v6[2] = v8 + v11;
v7 = 1;
}
else
{
LOBYTE(v11) = v10 >= a2 && v10 < v9;
if ( (_BYTE)v11 )
return 0;
if ( v12 > a2 && v10 <= a2 )
return (unsigned int)v11;
}
v6 = (unsigned __int64 *)v6[3];
}
while ( v6 );
if ( !(_BYTE)v7 )
goto LABEL_14;
}
else
{
LABEL_14:
v14 = (unsigned __int64 *)calloc(1uLL, 0x20uLL);
*v14 = a2;
v14[2] = a3;
v15 = *a1;
if ( *a1 )
{
do
{
v16 = v15;
v15 = (unsigned __int64 *)v15[3];
}
while ( v15 );
v16[3] = (unsigned __int64)v14;
v7 = 1;
}
else
{
*a1 = v14;
v7 = 1;
}
}
return v7;
}

original_code:
static _Bool
create_update_region(struct hex_data *hd, size_t address, uint8_t len) {
 struct hex_data_region *r;
 _Bool done = 0;
 r = hd->regions;
 while (r) {
  if (address == r->address + r->len) {
      r->len += len;
      done = 1;
  }
  else if (address + len == r->address) {
      r->address -= len;
      r->len += len;
      done = 1;
  }
  else if (address <= r->address && address + len > r->address) {
   return 0;
  }
  else if (address >= r->address && address < r->address + r->len) {
   return 0;
  }
  r = r->next;
 }
 if (!done) {
  r = calloc(1, sizeof(struct hex_data_region));
  r->address = address;
  r->len = len;
  if (!hd->regions) {
   hd->regions = r;
  }
  else {
   struct hex_data_region *iter = hd->regions;
   while(iter->next) {
    iter = iter->next;
   }
   iter->next = r;
  }
 }
 return 1;
}

canonical_original_code:
static _Bool create_update_region(struct hex_data *hd, unsigned long address, unsigned char len) {
 struct hex_data_region *r;
 _Bool done = 0;
 r = hd->regions;
 while (r) {
  if (address == r->address + r->len) {
      r->len += len;
      done = 1;
  }
  else if (address + len == r->address) {
      r->address -= len;
      r->len += len;
      done = 1;
  }
  else if (address <= r->address && address + len > r->address) {
   return 0;
  }
  else if (address >= r->address && address < r->address + r->len) {
   return 0;
  }
  r = r->next;
 }
 if (!done) {
  r = calloc(1, sizeof(struct hex_data_region));
  r->address = address;
  r->len = len;
  if (!hd->regions) {
   hd->regions = r;
  }
  else {
   struct hex_data_region *iter = hd->regions;
   while(iter->next) {
    iter = iter->next;
   }
   iter->next = r;
  }
 }
 return 1;
}

variable_types: struct hex_data { struct hex_data_region { unsigned long address; unsigned char *data; unsigned long len; struct hex_data_region *next; } *regions; } *

variable_types:
address
unsigned long

variable_types:
len
unsigned char

user_defined_types: struct hex_data { struct hex_data_region *regions; }


decompiled_code:
unsigned __int64 __fastcall read_byte(__int64 a1, __int64 a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
char nptr[11]; // [rsp+Dh] [rbp-Bh] BYREF

nptr[0] = *(_BYTE *)(a1 + a2);
nptr[1] = *(_BYTE *)(a1 + a2 + 1);
nptr[2] = 0;
return strtoul(nptr, &v3, 16);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, __int64 a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
char nptr[11]; // [rsp+Dh] [rbp-Bh] BYREF

nptr[0] = *(_BYTE *)(a1 + a2);
nptr[1] = *(_BYTE *)(a1 + a2 + 1);
nptr[2] = 0;
return strtoul(nptr, &v3, 16);
}

original_code:
static uint8_t read_byte(const char *line, size_t offset)
{
 char chars[3];
 char *endptr;
 uint8_t res;
 chars[0] = line[offset];
 chars[1] = line[offset+1];
 chars[2] = '\0';
 res = (uint8_t) strtoul(chars, &endptr, 16);
 return res;
}

canonical_original_code:
static unsigned char read_byte(char *line, unsigned long offset)
{
 char chars[3];
 char *endptr;
 unsigned char res;
 chars[0] = line[offset];
 chars[1] = line[offset+1];
 chars[2] = '\0';
 res = (unsigned char) strtoul(chars, &endptr, 16);
 return res;
}

variable_types:
line
char *

variable_types:
offset
unsigned long

variable_types:
chars
char [3]

variable_types:
res
unsigned char

return_type: unsigned char


decompiled_code:
unsigned __int64 __fastcall read_short(__int64 a1, __int64 a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
char nptr[4]; // [rsp+Ah] [rbp-Eh] BYREF
char v5; // [rsp+Fh] [rbp-9h]

*(_DWORD *)nptr = *(_DWORD *)(a1 + a2);
v5 = 0;
return strtoul(nptr, &v3, 16);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, __int64 a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
char nptr[4]; // [rsp+Ah] [rbp-Eh] BYREF
char v5; // [rsp+Fh] [rbp-9h]

*(_DWORD *)nptr = *(_DWORD *)(a1 + a2);
v5 = 0;
return strtoul(nptr, &v3, 16);
}

original_code:
static uint16_t read_short(const char *line, size_t offset)
{
 char chars[6];
 char *endptr;
 uint16_t res;
 memcpy(chars, line + offset, 4);
 chars[5] = '\0';
 res = (uint16_t) strtoul(chars, &endptr, 16);
 return res;
}

canonical_original_code:
static unsigned short read_short(char *line, unsigned long offset)
{
 char chars[6];
 char *endptr;
 unsigned short res;
 memcpy(chars, line + offset, 4);
 chars[5] = '\0';
 res = (unsigned short) strtoul(chars, &endptr, 16);
 return res;
}

variable_types:
chars
char [6]

variable_types:
res
unsigned short

return_type: unsigned short


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

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

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

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

original_code:
void hex_free(struct hex_data *hd)
{
 struct hex_data_region *r;
 r = hd->regions;
 while (r) {
  struct hex_data_region *this_one = r;
  r = r->next;
  free(this_one);
 }
 free(hd);
}

variable_types: struct hex_data_region { unsigned long address; unsigned char *data; unsigned long len; struct hex_data_region *next; } *


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

if ( a2 )
{
printf("%02hhx ", *a1);
v2 = 1LL;
while ( 1 )
{
if ( (v2 & 0xF) == 0 )
putchar(10);
if ( a2 == v2 )
break;
printf("%02hhx ", a1[v2++]);
if ( (v2 & 7) == 0 )
printf(" ");
}
}
return putchar(10);
}

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

if ( a2 )
{
printf("%02hhx ", *a1);
v2 = 1LL;
while ( 1 )
{
if ( (v2 & 0xF) == 0 )
putchar(10);
if ( a2 == v2 )
break;
printf("%02hhx ", a1[v2++]);
if ( (v2 & 7) == 0 )
printf(" ");
}
}
return putchar(10);
}

original_code:
static void print_data(const unsigned char *data, size_t len)
{
 size_t i;
 for (i = 0; i < len; i++) {
  printf("%02hhx ", data[i]);
  if ((i+1) % 8 == 0)
   printf("  ");
  if ((i+1) % 16 == 0)
   printf("\n");
 }
 printf("\n");
}

canonical_original_code:
static void print_data(unsigned char *data, unsigned long len)
{
 unsigned long i;
 for (i = 0; i < len; i++) {
  printf("%02hhx ", data[i]);
  if ((i+1) % 8 == 0)
   printf("  ");
  if ((i+1) % 16 == 0)
   printf("\n");
 }
 printf("\n");
}

variable_types:
data
unsigned char *

variable_types:
len
unsigned long

variable_types:
i
unsigned long


repo: sikthehedgehog/mdtools

decompiled_code:
void __fastcall set_track_title(void *a1)
{
title = a1;
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
title = a1;
}

original_code:
void set_track_title(const char *text)
{
   title = text;
}

canonical_original_code:
void set_track_title(char *text)
{
   title = text;
}

variable_types:
text
char *


decompiled_code:
void __fastcall set_game_title(void *a1)
{
game = a1;
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
game = a1;
}

original_code:
void set_game_title(const char *text)
{
   game = text;
}

canonical_original_code:
void set_game_title(char *text)
{
   game = text;
}


decompiled_code:
void __fastcall set_composer(void *a1)
{
composer = a1;
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
composer = a1;
}

original_code:
void set_composer(const char *text)
{
   composer = text;
}

canonical_original_code:
void set_composer(char *text)
{
   composer = text;
}


decompiled_code:
void __fastcall set_release(void *a1)
{
release = a1;
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
release = a1;
}

original_code:
void set_release(const char *text)
{
   release = text;
}

canonical_original_code:
void set_release(char *text)
{
   release = text;
}


decompiled_code:
void __fastcall set_rippedby(void *a1)
{
rippedby = a1;
}

canonical_decompiled_code:
void __fastcall func4(void *a1)
{
rippedby = a1;
}

original_code:
void set_rippedby(const char *text)
{
   rippedby = text;
}

canonical_original_code:
void set_rippedby(char *text)
{
   rippedby = text;
}