decompiled_code:
__int64 __fastcall futex_get(volatile signed __int32 *a1)
{
__int64 result; // rax
int v2; // ecx

result = atomic_cmpxchg_int_constprop_0(a1);
if ( (_DWORD)result )
{
if ( (_DWORD)result == 2 )
{
do
{
LABEL_24:
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
result = atomic_get_and_set_int(a1, 2);
}
while ( (_DWORD)result );
}
else
{
while ( 1 )
{
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
if ( v2 == 7 )
{
for ( result = atomic_get_and_set_int(a1, 2); (_DWORD)result; result = atomic_get_and_set_int(a1, 2) )
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
return result;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(volatile signed __int32 *a1)
{
__int64 result; // rax
int v2; // ecx

result = func4(a1);
if ( (_DWORD)result )
{
if ( (_DWORD)result == 2 )
{
do
{
LABEL_24:
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
result = func0(a1, 2);
}
while ( (_DWORD)result );
}
else
{
while ( 1 )
{
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
if ( v2 == 7 )
{
for ( result = func0(a1, 2); (_DWORD)result; result = func0(a1, 2) )
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
return result;
}
}
}
}
return result;
}

original_code:
inline static void futex_get(futex_lock_t* lock)
{
 int v;
 register int i=1024;
retry:
 v=atomic_cmpxchg_int(&(lock)->val, 0, 1);
 if (__builtin_expect(!!(v==0), 1)){
  do {} while(0);
  return;
 }else if (__builtin_expect(!!(v==2), 0)){
  do{
   syscall(202 , (&(lock)->val), (0), (2), (0), (0), (0));
   v=atomic_get_and_set_int(&(lock)->val, 2);
  }while(v);
 }else{
  if (i>0){
   i--;
   goto retry;
  }
  v=atomic_get_and_set_int(&(lock)->val, 2);
  while(v){
   syscall(202 , (&(lock)->val), (0), (2), (0), (0), (0));
   v=atomic_get_and_set_int(&(lock)->val, 2);
  }
 }
 do {} while(0);
}

canonical_original_code:
inline static void futex_get(struct atomic_t *lock)
{
 int v;
 register int i = 1024;
retry:
 v=atomic_cmpxchg_int(&(lock)->val, 0, 1);
 if (__builtin_expect(!!(v==0), 1)){
  do {} while(0);
  return;
 }else if (__builtin_expect(!!(v==2), 0)){
  do{
   syscall(202 , (&(lock)->val), (0), (2), (0), (0), (0));
   v=atomic_get_and_set_int(&(lock)->val, 2);
  }while(v);
 }else{
  if (i>0){
   i--;
   goto retry;
  }
  v=atomic_get_and_set_int(&(lock)->val, 2);
  while(v){
   syscall(202 , (&(lock)->val), (0), (2), (0), (0), (0));
   v=atomic_get_and_set_int(&(lock)->val, 2);
  }
 }
 do {} while(0);
}

variable_types: i int


repo: virtualolson/who

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

if ( a1 )
{
dtrie_destroy(a1 + 16, destroy_route_flags_list, cr_match_mode);
dtrie_destroy(a1 + 24, destroy_failure_route_rule_list, cr_match_mode);
futex_get(mem_lock);
qm_free(shm_block, a1);
result = futex_release(mem_lock);
}
return result;
}

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

if ( a1 )
{
dtrie_destroy(a1 + 16, destroy_route_flags_list, cr_match_mode);
dtrie_destroy(a1 + 24, destroy_failure_route_rule_list, cr_match_mode);
func5(mem_lock);
qm_free(shm_block, a1);
result = func1(mem_lock);
}
return result;
}

original_code:
void destroy_domain_data(struct domain_data_t *domain_data) {
 if (domain_data) {
  dtrie_destroy(&domain_data->tree, destroy_route_flags_list, cr_match_mode);
  dtrie_destroy(&domain_data->failure_tree, destroy_failure_route_rule_list,
    cr_match_mode);
  do { futex_get(mem_lock); qm_free(shm_block, (domain_data)); futex_release(mem_lock); }while(0);
 }
}

variable_types: struct domain_data_t { int id; struct _str { char *s; int len; } *name; struct dtrie_node_t { struct dtrie_node_t **child; void *data; } *tree; struct dtrie_node_t *failure_tree; } *

return_type: void

user_defined_types: struct domain_data_t { int id; struct _str *name; struct dtrie_node_t *tree; struct dtrie_node_t *failure_tree; }


decompiled_code:
__int64 __fastcall add_route_to_tree(__int64 a1, _QWORD *a2, unsigned int a3, unsigned int a4, __int64 a5, unsigned int a6, double a7, __int64 a8, __int64 a9, __int64 a10, __int64 a11, __int64 a12, __int64 a13, int a14, __int64 a15, __int64 a16)
{
__int64 v20; // rax
__int64 v21; // r9
unsigned int v22; // edx
__int64 v23; // r12
int v25; // eax
__int64 v26; // rdi
__int64 v27; // r12
unsigned int v28; // eax
const char *v29; // r9
const char *v30; // rsi
__int64 v31; // rcx
__int64 v32; // r8
__int64 v33; // rdx
struct _IO_FILE *v34; // rdi
__int64 v35; // rbp
unsigned int v36; // eax
__int64 v37; // [rsp-8h] [rbp-90h]
__int64 v38; // [rsp-8h] [rbp-90h]
__int64 v39; // [rsp+8h] [rbp-80h]
__int64 v40; // [rsp+28h] [rbp-60h]

v40 = a11;
v39 = dtrie_contains(a1, *a2, *((unsigned int *)a2 + 2), cr_match_mode);
v20 = add_route_flags(v39, a3, a4);
v21 = a10;
v22 = a9;
if ( !v20 )
{
v26 = (__int64)"carrierroute";
if ( (int)get_debug_level("carrierroute", 12LL) < -1 || dprint_crit )
return 0xFFFFFFFFLL;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert route flags into list\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:161]: ",
"add_route_to_tree");
goto LABEL_9;
}
if ( log_color )
{
v26 = 0xFFFFFFFFLL;
dprint_color(0xFFFFFFFFLL);
}
v27 = *((_QWORD *)&log_level_info + 8);
v28 = my_pid(a7);
v29 = "carrierroute [cr_domain.c:161]: ";
v30 = "%2d(%d) %s: %s%s(): cannot insert route flags into list\n";
v37 = v26;
v31 = v28;
v32 = v27;
v33 = process_no;
LABEL_18:
v34 = stderr;
fprintf(stderr, v30, v33, v31, v32, v29, "add_route_to_tree", v37);
if ( log_color )
dprint_color_reset(v34, v30, v38);
goto LABEL_9;
}
v23 = v20;
if ( v39 || (v25 = dtrie_insert(a1, *a2, *((unsigned int *)a2 + 2), v20, cr_match_mode), v22 = a9, v21 = a10, !v25) )
{
LODWORD(a10) = a13;
LODWORD(a9) = a12;
LODWORD(a11) = a14;
return add_route_rule(v23, a5, a6, a8, v22, v21, a7, v40, a9, a10, a11, a15, a16);
}
if ( (int)get_debug_level("carrierroute", 12LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert route flags into d-trie\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:168]: ",
"add_route_to_tree");
LABEL_9:
--dprint_crit;
return 0xFFFFFFFFLL;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v35 = *((_QWORD *)&log_level_info + 8);
v36 = my_pid(a7);
v29 = "carrierroute [cr_domain.c:168]: ";
v31 = v36;
v37 = 12LL;
v32 = v35;
v30 = "%2d(%d) %s: %s%s(): cannot insert route flags into d-trie\n";
v33 = process_no;
goto LABEL_18;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, _QWORD *a2, unsigned int a3, unsigned int a4, __int64 a5, unsigned int a6, double a7, __int64 a8, __int64 a9, __int64 a10, __int64 a11, __int64 a12, __int64 a13, int a14, __int64 a15, __int64 a16)
{
__int64 v20; // rax
__int64 v21; // r9
unsigned int v22; // edx
__int64 v23; // r12
int v25; // eax
__int64 v26; // rdi
__int64 v27; // r12
unsigned int v28; // eax
const char *v29; // r9
const char *v30; // rsi
__int64 v31; // rcx
__int64 v32; // r8
__int64 v33; // rdx
struct _IO_FILE *v34; // rdi
__int64 v35; // rbp
unsigned int v36; // eax
__int64 v37; // [rsp-8h] [rbp-90h]
__int64 v38; // [rsp-8h] [rbp-90h]
__int64 v39; // [rsp+8h] [rbp-80h]
__int64 v40; // [rsp+28h] [rbp-60h]

v40 = a11;
v39 = dtrie_contains(a1, *a2, *((unsigned int *)a2 + 2), cr_match_mode);
v20 = add_route_flags(v39, a3, a4);
v21 = a10;
v22 = a9;
if ( !v20 )
{
v26 = (__int64)"carrierroute";
if ( (int)get_debug_level("carrierroute", 12LL) < -1 || dprint_crit )
return 0xFFFFFFFFLL;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert route flags into list\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:161]: ",
"add_route_to_tree");
goto LABEL_9;
}
if ( log_color )
{
v26 = 0xFFFFFFFFLL;
dprint_color(0xFFFFFFFFLL);
}
v27 = *((_QWORD *)&log_level_info + 8);
v28 = my_pid(a7);
v29 = "carrierroute [cr_domain.c:161]: ";
v30 = "%2d(%d) %s: %s%s(): cannot insert route flags into list\n";
v37 = v26;
v31 = v28;
v32 = v27;
v33 = process_no;
LABEL_18:
v34 = stderr;
fprintf(stderr, v30, v33, v31, v32, v29, "add_route_to_tree", v37);
if ( log_color )
dprint_color_reset(v34, v30, v38);
goto LABEL_9;
}
v23 = v20;
if ( v39 || (v25 = dtrie_insert(a1, *a2, *((unsigned int *)a2 + 2), v20, cr_match_mode), v22 = a9, v21 = a10, !v25) )
{
LODWORD(a10) = a13;
LODWORD(a9) = a12;
LODWORD(a11) = a14;
return add_route_rule(v23, a5, a6, a8, v22, v21, a7, v40, a9, a10, a11, a15, a16);
}
if ( (int)get_debug_level("carrierroute", 12LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert route flags into d-trie\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:168]: ",
"add_route_to_tree");
LABEL_9:
--dprint_crit;
return 0xFFFFFFFFLL;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v35 = *((_QWORD *)&log_level_info + 8);
v36 = my_pid(a7);
v29 = "carrierroute [cr_domain.c:168]: ";
v31 = v36;
v37 = 12LL;
v32 = v35;
v30 = "%2d(%d) %s: %s%s(): cannot insert route flags into d-trie\n";
v33 = process_no;
goto LABEL_18;
}
return 0xFFFFFFFFLL;
}

original_code:
int add_route_to_tree(struct dtrie_node_t *node, const str * scan_prefix,
  flag_t flags, flag_t mask, const str * full_prefix, int max_targets, double prob,
  const str * rewrite_hostpart, int strip, const str * rewrite_local_prefix,
  const str * rewrite_local_suffix, int status, int hash_index,
  int backup, int * backed_up, const str * comment) {
 void **ret;
 struct route_flags *rf;
 ret = dtrie_contains(node, scan_prefix->s, scan_prefix->len, cr_match_mode);
 rf = add_route_flags((struct route_flags **)ret, flags, mask);
 if (rf == ((void *)0)) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "cannot insert route flags into list\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "cannot insert route flags into list\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert route flags into list\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert route flags into list\n", ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert route flags into list\n", ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (ret == ((void *)0)) {
  if (dtrie_insert(node, scan_prefix->s, scan_prefix->len, rf, cr_match_mode) != 0) {
   do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "cannot insert route flags into d-trie\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "cannot insert route flags into d-trie\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert route flags into d-trie\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert route flags into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert route flags into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   return -1;
  }
 }
 return add_route_rule(rf, full_prefix, max_targets, prob, rewrite_hostpart, strip,
            rewrite_local_prefix, rewrite_local_suffix, status, hash_index,
            backup, backed_up, comment);
}

canonical_original_code:
int add_route_to_tree(struct dtrie_node_t *node, struct _str *scan_prefix, unsigned int flags, unsigned int mask, struct _str *full_prefix, int max_targets, double prob, struct _str *rewrite_hostpart, int strip, struct _str *rewrite_local_prefix, struct _str *rewrite_local_suffix, int status, int hash_index, int backup, int *backed_up, struct _str *comment) {
 void **ret;
 struct route_flags *rf;
 ret = dtrie_contains(node, scan_prefix->s, scan_prefix->len, cr_match_mode);
 rf = add_route_flags((struct route_flags **)ret, flags, mask);
 if (rf == ((void *)0)) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "cannot insert route flags into list\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "cannot insert route flags into list\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert route flags into list\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert route flags into list\n", ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert route flags into list\n", ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (ret == ((void *)0)) {
  if (dtrie_insert(node, scan_prefix->s, scan_prefix->len, rf, cr_match_mode) != 0) {
   do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "cannot insert route flags into d-trie\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "cannot insert route flags into d-trie\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert route flags into d-trie\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert route flags into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert route flags into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   return -1;
  }
 }
 return add_route_rule(rf, full_prefix, max_targets, prob, rewrite_hostpart, strip,
            rewrite_local_prefix, rewrite_local_suffix, status, hash_index,
            backup, backed_up, comment);
}

variable_types: struct dtrie_node_t { struct dtrie_node_t **child; void *data; } *

variable_types:
flags
unsigned int

variable_types:
mask
unsigned int

variable_types: prob double

variable_types: strip int

variable_types: status int

variable_types: backup int

variable_types:
comment
struct _str *

variable_types:
ret
void **

variable_types: struct route_flags { unsigned int flags; unsigned int mask; struct route_rule { int dice_to; double prob; double orig_prob; struct _str { char *s; int len; } host; int strip; struct _str local_prefix; struct _str local_suffix; struct _str comment; struct _str prefix; int status; struct route_rule_p_list { struct route_rule *rr; int hash_index; struct route_rule_p_list *next; } *backed_up; struct route_rule_p_list *backup; int hash_index; struct route_rule *next; } *rule_list; struct route_rule **rules; int rule_num; int dice_max; int max_targets; struct route_flags *next; } *

return_type: int

user_defined_types: struct route_flags { unsigned int flags; unsigned int mask; struct route_rule *rule_list; struct route_rule **rules; int rule_num; int dice_max; int max_targets; struct route_flags *next; }

user_defined_types: struct cfg_group_core { int debug; int log_facility; int memdbg; int use_dst_blacklist; unsigned int blst_timeout; unsigned int blst_max_mem; unsigned int blst_udp_imask; unsigned int blst_tcp_imask; unsigned int blst_tls_imask; unsigned int blst_sctp_imask; int dns_try_ipv6; int dns_try_naptr; int dns_udp_pref; int dns_tcp_pref; int dns_tls_pref; int dns_sctp_pref; int dns_retr_time; int dns_retr_no; int dns_servers_no; int dns_search_list; int dns_search_fmatch; int dns_reinit; int use_dns_cache; int dns_cache_flags; int use_dns_failover; int dns_srv_lb; unsigned int dns_neg_cache_ttl; unsigned int dns_cache_min_ttl; unsigned int dns_cache_max_ttl; unsigned int dns_cache_max_mem; int dns_cache_del_nonexp; int dns_cache_rec_pref; int mem_dump_pkg; int mem_dump_shm; int max_while_loops; int udp_mtu; int udp_mtu_try_proto; int udp4_raw; int udp4_raw_mtu; int udp4_raw_ttl; int force_rport; int memlog; int mem_summary; int mem_safety; int mem_join; int corelog; int latency_log; int latency_limit_db; int latency_limit_action; }

user_defined_types: struct route_rule { int dice_to; double prob; double orig_prob; struct _str host; int strip; struct _str local_prefix; struct _str local_suffix; struct _str comment; struct _str prefix; int status; struct route_rule_p_list *backed_up; struct route_rule_p_list *backup; int hash_index; struct route_rule *next; }


decompiled_code:
__int64 __fastcall add_failure_route_to_tree(__int64 a1, _QWORD *a2, __int64 a3, __int64 a4, __int64 a5, unsigned int a6, double a7, unsigned int a8, unsigned int a9, __int64 a10)
{
__int64 v13; // rbp
__int64 v14; // rax
int v16; // eax
__int64 v17; // rdi
__int64 v18; // r12
unsigned int v19; // eax
const char *v20; // r9
__int64 v21; // rcx
__int64 v22; // r8
const char *v23; // rsi
__int64 v24; // rdx
struct _IO_FILE *v25; // rdi
__int64 v26; // r15
unsigned int v27; // eax
__int64 v28; // [rsp-8h] [rbp-50h]
__int64 v29; // [rsp-8h] [rbp-50h]

v13 = dtrie_contains(a1, *a2, *((unsigned int *)a2 + 2), cr_match_mode);
v14 = add_failure_route_rule(v13, a3, a4, a5, a6, a8, a9, a10);
if ( !v14 )
{
v17 = (__int64)"carrierroute";
if ( (int)get_debug_level("carrierroute", 12LL) < -1 || dprint_crit )
return 0xFFFFFFFFLL;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert failure route rule into list\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:210]: ",
"add_failure_route_to_tree");
goto LABEL_9;
}
if ( log_color )
{
v17 = 0xFFFFFFFFLL;
dprint_color(0xFFFFFFFFLL);
}
v18 = *((_QWORD *)&log_level_info + 8);
v19 = my_pid(a7);
v20 = "carrierroute [cr_domain.c:210]: ";
v28 = v17;
v21 = v19;
v22 = v18;
v23 = "%2d(%d) %s: %s%s(): cannot insert failure route rule into list\n";
v24 = process_no;
LABEL_18:
v25 = stderr;
fprintf(stderr, v23, v24, v21, v22, v20, "add_failure_route_to_tree", v28);
if ( log_color )
dprint_color_reset(v25, v23, v29);
goto LABEL_9;
}
if ( v13 || !(unsigned int)dtrie_insert(a1, *a2, *((unsigned int *)a2 + 2), v14, cr_match_mode) )
return 0LL;
v16 = get_debug_level("carrierroute", 12LL);
if ( v16 + 1 < 0 == __OFADD__(1, v16) && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert failure route rule into d-trie\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:217]: ",
"add_failure_route_to_tree");
LABEL_9:
--dprint_crit;
return 0xFFFFFFFFLL;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v26 = *((_QWORD *)&log_level_info + 8);
v27 = my_pid(a7);
v20 = "carrierroute [cr_domain.c:217]: ";
v21 = v27;
v28 = 12LL;
v22 = v26;
v23 = "%2d(%d) %s: %s%s(): cannot insert failure route rule into d-trie\n";
v24 = process_no;
goto LABEL_18;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, _QWORD *a2, __int64 a3, __int64 a4, __int64 a5, unsigned int a6, double a7, unsigned int a8, unsigned int a9, __int64 a10)
{
__int64 v13; // rbp
__int64 v14; // rax
int v16; // eax
__int64 v17; // rdi
__int64 v18; // r12
unsigned int v19; // eax
const char *v20; // r9
__int64 v21; // rcx
__int64 v22; // r8
const char *v23; // rsi
__int64 v24; // rdx
struct _IO_FILE *v25; // rdi
__int64 v26; // r15
unsigned int v27; // eax
__int64 v28; // [rsp-8h] [rbp-50h]
__int64 v29; // [rsp-8h] [rbp-50h]

v13 = dtrie_contains(a1, *a2, *((unsigned int *)a2 + 2), cr_match_mode);
v14 = add_failure_route_rule(v13, a3, a4, a5, a6, a8, a9, a10);
if ( !v14 )
{
v17 = (__int64)"carrierroute";
if ( (int)get_debug_level("carrierroute", 12LL) < -1 || dprint_crit )
return 0xFFFFFFFFLL;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert failure route rule into list\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:210]: ",
"add_failure_route_to_tree");
goto LABEL_9;
}
if ( log_color )
{
v17 = 0xFFFFFFFFLL;
dprint_color(0xFFFFFFFFLL);
}
v18 = *((_QWORD *)&log_level_info + 8);
v19 = my_pid(a7);
v20 = "carrierroute [cr_domain.c:210]: ";
v28 = v17;
v21 = v19;
v22 = v18;
v23 = "%2d(%d) %s: %s%s(): cannot insert failure route rule into list\n";
v24 = process_no;
LABEL_18:
v25 = stderr;
fprintf(stderr, v23, v24, v21, v22, v20, "add_failure_route_to_tree", v28);
if ( log_color )
dprint_color_reset(v25, v23, v29);
goto LABEL_9;
}
if ( v13 || !(unsigned int)dtrie_insert(a1, *a2, *((unsigned int *)a2 + 2), v14, cr_match_mode) )
return 0LL;
v16 = get_debug_level("carrierroute", 12LL);
if ( v16 + 1 < 0 == __OFADD__(1, v16) && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert failure route rule into d-trie\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:217]: ",
"add_failure_route_to_tree");
LABEL_9:
--dprint_crit;
return 0xFFFFFFFFLL;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v26 = *((_QWORD *)&log_level_info + 8);
v27 = my_pid(a7);
v20 = "carrierroute [cr_domain.c:217]: ";
v21 = v27;
v28 = 12LL;
v22 = v26;
v23 = "%2d(%d) %s: %s%s(): cannot insert failure route rule into d-trie\n";
v24 = process_no;
goto LABEL_18;
}
return 0xFFFFFFFFLL;
}

original_code:
int add_failure_route_to_tree(struct dtrie_node_t * failure_node, const str * scan_prefix,
  const str * full_prefix, const str * host, const str * reply_code,
  const flag_t flags, const flag_t mask, const int next_domain, const str * comment) {
 void **ret;
 struct failure_route_rule *frr;
 ret = dtrie_contains(failure_node, scan_prefix->s, scan_prefix->len, cr_match_mode);
 frr = add_failure_route_rule((struct failure_route_rule **)ret, full_prefix, host, reply_code, flags, mask, next_domain, comment);
 if (frr == ((void *)0)) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "cannot insert failure route rule into list\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "cannot insert failure route rule into list\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert failure route rule into list\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert failure route rule into list\n", ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert failure route rule into list\n", ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
  }
 if (ret == ((void *)0)) {
  if (dtrie_insert(failure_node, scan_prefix->s, scan_prefix->len, frr, cr_match_mode) != 0) {
   do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "cannot insert failure route rule into d-trie\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "cannot insert failure route rule into d-trie\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert failure route rule into d-trie\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert failure route rule into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert failure route rule into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int add_failure_route_to_tree(struct dtrie_node_t *failure_node, struct _str *scan_prefix, struct _str *full_prefix, struct _str *host, struct _str *reply_code, unsigned int flags, unsigned int mask, int next_domain, struct _str *comment) {
 void **ret;
 struct failure_route_rule *frr;
 ret = dtrie_contains(failure_node, scan_prefix->s, scan_prefix->len, cr_match_mode);
 frr = add_failure_route_rule((struct failure_route_rule **)ret, full_prefix, host, reply_code, flags, mask, next_domain, comment);
 if (frr == ((void *)0)) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "cannot insert failure route rule into list\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "cannot insert failure route rule into list\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert failure route rule into list\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert failure route rule into list\n", ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert failure route rule into list\n", ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
  }
 if (ret == ((void *)0)) {
  if (dtrie_insert(failure_node, scan_prefix->s, scan_prefix->len, frr, cr_match_mode) != 0) {
   do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "cannot insert failure route rule into d-trie\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "cannot insert failure route rule into d-trie\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert failure route rule into d-trie\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert failure route rule into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert failure route rule into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   return -1;
  }
 }
 return 0;
}

variable_types:
host
struct _str *

variable_types: struct failure_route_rule { struct _str { char *s; int len; } host; struct _str comment; struct _str prefix; struct _str reply_code; int next_domain; unsigned int flags; unsigned int mask; struct failure_route_rule *next; } *

user_defined_types: struct dtrie_node_t { struct dtrie_node_t **child; void *data; }

user_defined_types: struct failure_route_rule { struct _str host; struct _str comment; struct _str prefix; struct _str reply_code; int next_domain; unsigned int flags; unsigned int mask; struct failure_route_rule *next; }


decompiled_code:
__int64 __fastcall compare_domain_data(int **a1, int **a2)
{
int *v2; // rdx
int *v3; // rax
int v4; // ecx
__int64 result; // rax

v2 = *a1;
v3 = *a2;
if ( !*a1 )
return v3 != 0LL;
if ( !v3 )
return 0xFFFFFFFFLL;
v4 = *v3;
result = *v2 > *v3;
if ( *v2 < v4 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int **a1, int **a2)
{
int *v2; // rdx
int *v3; // rax
int v4; // ecx
__int64 result; // rax

v2 = *a1;
v3 = *a2;
if ( !*a1 )
return v3 != 0LL;
if ( !v3 )
return 0xFFFFFFFFLL;
v4 = *v3;
result = *v2 > *v3;
if ( *v2 < v4 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int compare_domain_data(const void *v1, const void *v2) {
  struct domain_data_t *d1 = *(struct domain_data_t * const *)v1;
 struct domain_data_t *d2 = *(struct domain_data_t * const *)v2;
 if (d1 == ((void *)0)) {
  if (d2 == ((void *)0)) return 0;
  else return 1;
 }
 else {
  if (d2 == ((void *)0)) return -1;
  else {
   if (d1->id < d2->id) return -1;
   else if (d1->id > d2->id) return 1;
   else return 0;
  }
 }
}

canonical_original_code:
int compare_domain_data(void *v1, void *v2) {
  struct domain_data_t *d1 = *(struct domain_data_t * const *)v1;
 struct domain_data_t *d2 = *(struct domain_data_t * const *)v2;
 if (d1 == ((void *)0)) {
  if (d2 == ((void *)0)) return 0;
  else return 1;
 }
 else {
  if (d2 == ((void *)0)) return -1;
  else {
   if (d1->id < d2->id) return -1;
   else if (d1->id > d2->id) return 1;
   else return 0;
  }
 }
}


decompiled_code:
__int64 __fastcall ipopsapi_is_ip(__int64 a1)
{
return 2 * (unsigned int)((unsigned int)ip_parser_execute(*(_QWORD *)a1, *(int *)(a1 + 8)) != 4) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return 2 * (unsigned int)((unsigned int)ip_parser_execute(*(_QWORD *)a1, *(int *)(a1 + 8)) != 4) - 1;
}

original_code:
int ipopsapi_is_ip(const str * const ip)
{
  if (ip_parser_execute(ip->s, ip->len) != ip_type_error)
    return 1;
  else
    return -1;
}

canonical_original_code:
int ipopsapi_is_ip(struct _str *ip)
{
  if (ip_parser_execute(ip->s, ip->len) != ip_type_error)
    return 1;
  else
    return -1;
}

variable_types:
ip
struct _str { char *s; int len; } *


decompiled_code:
__int64 __fastcall ipopsapi_compare_ips(__int64 *a1, __int64 *a2)
{
int v2; // ebx
__int64 v3; // rbp
__int64 v4; // r13
int v5; // er14
unsigned int v6; // eax
unsigned int v7; // er12
__int64 v9; // r15
unsigned int v10; // eax
__int64 v11; // r9

v2 = *((_DWORD *)a1 + 2);
v3 = *a1;
v4 = *a2;
v5 = *((_DWORD *)a2 + 2);
v6 = ip_parser_execute(*a1, v2);
if ( v6 == 3 )
{
++v3;
v2 -= 2;
v7 = 2;
}
else
{
v7 = v6;
if ( v6 == 4 )
return 0xFFFFFFFFLL;
}
v9 = v5;
v10 = ip_parser_execute(v4, v5);
v11 = v10;
if ( v10 == 3 )
{
++v4;
v11 = 2LL;
v9 = v5 - 2;
}
else if ( v10 == 4 )
{
return 0xFFFFFFFFLL;
}
return (unsigned int)compare_ips(v3, v2, v7, v4, v9, v11) == 0 ? -1 : 1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, __int64 *a2)
{
int v2; // ebx
__int64 v3; // rbp
__int64 v4; // r13
int v5; // er14
unsigned int v6; // eax
unsigned int v7; // er12
__int64 v9; // r15
unsigned int v10; // eax
__int64 v11; // r9

v2 = *((_DWORD *)a1 + 2);
v3 = *a1;
v4 = *a2;
v5 = *((_DWORD *)a2 + 2);
v6 = ip_parser_execute(*a1, v2);
if ( v6 == 3 )
{
++v3;
v2 -= 2;
v7 = 2;
}
else
{
v7 = v6;
if ( v6 == 4 )
return 0xFFFFFFFFLL;
}
v9 = v5;
v10 = ip_parser_execute(v4, v5);
v11 = v10;
if ( v10 == 3 )
{
++v4;
v11 = 2LL;
v9 = v5 - 2;
}
else if ( v10 == 4 )
{
return 0xFFFFFFFFLL;
}
return (unsigned int)compare_ips(v3, v2, v7, v4, v9, v11) == 0 ? -1 : 1;
}

original_code:
int ipopsapi_compare_ips(const str *const ip1, const str *const ip2)
{
  str string1 = *ip1;
  str string2 = *ip2;
  enum enum_ip_type ip1_type, ip2_type;
  switch(ip1_type = ip_parser_execute(string1.s, string1.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      string1.s += 1;
      string1.len -= 2;
      ip1_type = ip_type_ipv6;
      break;
    default:
      break;
  }
  switch(ip2_type = ip_parser_execute(string2.s, string2.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      string2.s += 1;
      string2.len -= 2;
      ip2_type = ip_type_ipv6;
      break;
    default:
      break;
  }
  if (_compare_ips(string1.s, string1.len, ip1_type, string2.s, string2.len, ip2_type))
    return 1;
  else
    return -1;
}

canonical_original_code:
int ipopsapi_compare_ips(struct _str *ip1, struct _str *ip2)
{
  struct _str string1 = *ip1;
  struct _str string2 = *ip2;
  enum enum_ip_type ip1_type; enum enum_ip_type ip2_type;
  switch(ip1_type = ip_parser_execute(string1.s, string1.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      string1.s += 1;
      string1.len -= 2;
      ip1_type = ip_type_ipv6;
      break;
    default:
      break;
  }
  switch(ip2_type = ip_parser_execute(string2.s, string2.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      string2.s += 1;
      string2.len -= 2;
      ip2_type = ip_type_ipv6;
      break;
    default:
      break;
  }
  if (_compare_ips(string1.s, string1.len, ip1_type, string2.s, string2.len, ip2_type))
    return 1;
  else
    return -1;
}

variable_types: enum enum_ip_type { ip_type_ipv4=1, ip_type_ipv6=2, ip_type_ipv6_reference=3, ip_type_error=4 }


original_code:
int ipopsapi_ip_is_in_subnet(const str *const ip1, const str *const ip2)
{
  str string1 = *ip1;
  str string2 = *ip2;
  enum enum_ip_type ip1_type, ip2_type;
  char *cidr_pos = ((void *)0);
  int netmask = 0;
  switch(ip1_type = ip_parser_execute(string1.s, string1.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      return -1;
      break;
    default:
      break;
  }
  cidr_pos = string2.s + string2.len - 1;
  while (cidr_pos > string2.s)
  {
    if (*cidr_pos == '/') break;
    cidr_pos--;
  }
  if (cidr_pos == string2.s) return -1;
  string2.len = (cidr_pos - string2.s);
  netmask = atoi(cidr_pos+1);
  switch(ip2_type = ip_parser_execute(string2.s, string2.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      return -1;
      break;
    default:
      break;
  }
  if (_ip_is_in_subnet(string1.s, string1.len, ip1_type, string2.s, string2.len, ip2_type, netmask))
    return 1;
  else
    return -1;
}

canonical_original_code:
int ipopsapi_ip_is_in_subnet(struct _str *ip1, struct _str *ip2)
{
  struct _str string1 = *ip1;
  struct _str string2 = *ip2;
  enum enum_ip_type ip1_type; enum enum_ip_type ip2_type;
  char *cidr_pos = ((void *)0);
  int netmask = 0;
  switch(ip1_type = ip_parser_execute(string1.s, string1.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      return -1;
      break;
    default:
      break;
  }
  cidr_pos = string2.s + string2.len - 1;
  while (cidr_pos > string2.s)
  {
    if (*cidr_pos == '/') break;
    cidr_pos--;
  }
  if (cidr_pos == string2.s) return -1;
  string2.len = (cidr_pos - string2.s);
  netmask = atoi(cidr_pos+1);
  switch(ip2_type = ip_parser_execute(string2.s, string2.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      return -1;
      break;
    default:
      break;
  }
  if (_ip_is_in_subnet(string1.s, string1.len, ip1_type, string2.s, string2.len, ip2_type, netmask))
    return 1;
  else
    return -1;
}

variable_types: netmask int

user_defined_types: enum enum_ip_type { ip_type_ipv4=1, ip_type_ipv6=2, ip_type_ipv6_reference=3, ip_type_error=4 }


decompiled_code:
__int64 __fastcall bind_ipops(__int64 (__fastcall **a1)(__int64 *a1, __int64 *a2))
{
__int64 result; // rax
int v2; // er8
const char *v3; // r12
struct _IO_FILE *v4; // rdi
__int64 v5; // [rsp-28h] [rbp-28h]
unsigned int v6; // [rsp-20h] [rbp-20h]

if ( a1 )
{
*a1 = ipopsapi_compare_ips;
result = 0LL;
a1[1] = (__int64 (__fastcall *)(__int64 *, __int64 *))ipopsapi_ip_is_in_subnet;
a1[2] = (__int64 (__fastcall *)(__int64 *, __int64 *))ipopsapi_is_ip;
}
else
{
v2 = get_debug_level("ipops", 5LL);
result = 0xFFFFFFFFLL;
if ( v2 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v3 = (const char *)*((_QWORD *)&log_level_info + 8);
v6 = my_pid();
v4 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): Invalid parameter value\n",
process_no,
v6,
v3,
"ipops [api.c:137]: ",
"bind_ipops");
if ( log_color )
dprint_color_reset(v4, "%2d(%d) %s: %s%s(): Invalid parameter value\n", v5);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): Invalid parameter value\n",
*((const char **)&log_level_info + 8),
"ipops [api.c:137]: ",
"bind_ipops");
}
result = 0xFFFFFFFFLL;
--dprint_crit;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 (__fastcall **a1)(__int64 *a1, __int64 *a2))
{
__int64 result; // rax
int v2; // er8
const char *v3; // r12
struct _IO_FILE *v4; // rdi
__int64 v5; // [rsp-28h] [rbp-28h]
unsigned int v6; // [rsp-20h] [rbp-20h]

if ( a1 )
{
*a1 = ipopsapi_compare_ips;
result = 0LL;
a1[1] = (__int64 (__fastcall *)(__int64 *, __int64 *))ipopsapi_ip_is_in_subnet;
a1[2] = (__int64 (__fastcall *)(__int64 *, __int64 *))ipopsapi_is_ip;
}
else
{
v2 = get_debug_level("ipops", 5LL);
result = 0xFFFFFFFFLL;
if ( v2 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v3 = (const char *)*((_QWORD *)&log_level_info + 8);
v6 = my_pid();
v4 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): Invalid parameter value\n",
process_no,
v6,
v3,
"ipops [api.c:137]: ",
"bind_ipops");
if ( log_color )
dprint_color_reset(v4, "%2d(%d) %s: %s%s(): Invalid parameter value\n", v5);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): Invalid parameter value\n",
*((const char **)&log_level_info + 8),
"ipops [api.c:137]: ",
"bind_ipops");
}
result = 0xFFFFFFFFLL;
--dprint_crit;
}
}
return result;
}

original_code:
int bind_ipops(ipops_api_t* api)
{
 if (!api) {
  do { if (get_debug_level("ipops", (sizeof("ipops")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "Invalid parameter value\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("ipops" " [" "api.c" ":" "137" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "Invalid parameter value\n", (log_level_info[((-1)) - (-5)].name), ("ipops" " [" "api.c" ":" "137" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "Invalid parameter value\n", process_no, my_pid(), ("ipops" " [" "api.c" ":" "137" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Invalid parameter value\n", ("ipops" " [" "api.c" ":" "137" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Invalid parameter value\n", ("ipops" " [" "api.c" ":" "137" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 api->compare_ips = ipopsapi_compare_ips;
 api->ip_is_in_subnet = ipopsapi_ip_is_in_subnet;
 api->is_ip = ipopsapi_is_ip;
 return 0;
}

canonical_original_code:
int bind_ipops(struct ipops_api *api)
{
 if (!api) {
  do { if (get_debug_level("ipops", (sizeof("ipops")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "Invalid parameter value\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("ipops" " [" "api.c" ":" "137" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "Invalid parameter value\n", (log_level_info[((-1)) - (-5)].name), ("ipops" " [" "api.c" ":" "137" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "Invalid parameter value\n", process_no, my_pid(), ("ipops" " [" "api.c" ":" "137" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Invalid parameter value\n", ("ipops" " [" "api.c" ":" "137" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Invalid parameter value\n", ("ipops" " [" "api.c" ":" "137" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 api->compare_ips = ipopsapi_compare_ips;
 api->ip_is_in_subnet = ipopsapi_ip_is_in_subnet;
 api->is_ip = ipopsapi_is_ip;
 return 0;
}

variable_types: struct ipops_api { int (*compare_ips)(struct _str { char *s; int len; } *, struct _str *); int (*ip_is_in_subnet)(struct _str *, struct _str *); int (*is_ip)(struct _str *ip); } *

user_defined_types: struct ipops_api { int (*compare_ips)(struct _str *, struct _str *); int (*ip_is_in_subnet)(struct _str *, struct _str *); int (*is_ip)(struct _str *ip); }


decompiled_code:
__int64 __fastcall atomic_get_and_set_int(volatile __int32 *a1, __int32 a2)
{
return (unsigned int)_InterlockedExchange(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(volatile __int32 *a1, __int32 a2)
{
return (unsigned int)_InterlockedExchange(a1, a2);
}

original_code: inline static int atomic_get_and_set_int(volatile int* var, int v) { asm volatile( "xchgl %1, %0" " \n\t" : "+q"(v), "=m"(*var) : "m"(*var) : "memory" ); return v; }

canonical_original_code: inline static int atomic_get_and_set_int(int *var, int v) { asm volatile( "xchgl %1, %0" " \n\t" : "+q"(v), "=m"(*var) : "m"(*var) : "memory" ); return v; }

variable_types:
var
int *

variable_types: v int


decompiled_code:
__int64 __fastcall futex_release(volatile __int32 *a1)
{
__int64 result; // rax
__int64 v2; // [rsp-10h] [rbp-18h]

result = atomic_get_and_set_int(a1, 0);
if ( (_DWORD)result == 2 )
{
syscall(202LL, a1, 1LL, 1LL, 0LL, 0LL, 0LL);
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(volatile __int32 *a1)
{
__int64 result; // rax
__int64 v2; // [rsp-10h] [rbp-18h]

result = func0(a1, 0);
if ( (_DWORD)result == 2 )
{
syscall(202LL, a1, 1LL, 1LL, 0LL, 0LL, 0LL);
result = v2;
}
return result;
}

original_code:
inline static void futex_release(futex_lock_t* lock)
{
 int v;
 do {} while(0);
 v=atomic_get_and_set_int(&(lock)->val, 0);
 if (__builtin_expect(!!(v==2), 0)){
  syscall(202 , (&(lock)->val), (1), (1), (0), (0), (0));
 }
}

canonical_original_code:
inline static void futex_release(struct atomic_t *lock)
{
 int v;
 do {} while(0);
 v=atomic_get_and_set_int(&(lock)->val, 0);
 if (__builtin_expect(!!(v==2), 0)){
  syscall(202 , (&(lock)->val), (1), (1), (0), (0), (0));
 }
}

variable_types:
lock
struct atomic_t { int val; } *


canonical_decompiled_code:
__int64 __fastcall func3(volatile signed __int32 *a1)
{
__int64 result; // rax
int v2; // ecx

result = func2(a1);
if ( (_DWORD)result )
{
if ( (_DWORD)result == 2 )
{
do
{
LABEL_24:
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
result = func0(a1, 2);
}
while ( (_DWORD)result );
}
else
{
while ( 1 )
{
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
if ( v2 == 7 )
{
for ( result = func0(a1, 2); (_DWORD)result; result = func0(a1, 2) )
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
return result;
}
}
}
}
return result;
}

variable_types: i int


decompiled_code:
__int64 __fastcall mohq_lock_change(__int64 a1, int a2)
{
__int64 result; // rax

futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( *(_DWORD *)(a1 + 8) != 1 )
{
LABEL_3:
futex_release(*(volatile __int32 **)a1);
return 0LL;
}
*(_DWORD *)(a1 + 8) = -1;
futex_release(*(volatile __int32 **)a1);
result = 1LL;
}
else
{
if ( *(_DWORD *)(a1 + 8) != -1 )
goto LABEL_3;
*(_DWORD *)(a1 + 8) = 1;
futex_release(*(volatile __int32 **)a1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
__int64 result; // rax

func3(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( *(_DWORD *)(a1 + 8) != 1 )
{
LABEL_3:
func1(*(volatile __int32 **)a1);
return 0LL;
}
*(_DWORD *)(a1 + 8) = -1;
func1(*(volatile __int32 **)a1);
result = 1LL;
}
else
{
if ( *(_DWORD *)(a1 + 8) != -1 )
goto LABEL_3;
*(_DWORD *)(a1 + 8) = 1;
func1(*(volatile __int32 **)a1);
result = 1LL;
}
return result;
}

original_code:
int mohq_lock_change (mohq_lock *plock, int bexcl)
{
int nret = 0;
futex_get(plock->plock);
if (bexcl)
  {
  if (plock->lock_cnt == 1)
    {
    plock->lock_cnt = -1;
    nret = 1;
    }
  }
else
  {
  if (plock->lock_cnt == -1)
    {
    plock->lock_cnt = 1;
    nret = 1;
    }
  }
futex_release(plock->plock);
return nret;
}

canonical_original_code:
int mohq_lock_change(struct mohq_lock *plock, int bexcl)
{
int nret = 0;
futex_get(plock->plock);
if (bexcl)
  {
  if (plock->lock_cnt == 1)
    {
    plock->lock_cnt = -1;
    nret = 1;
    }
  }
else
  {
  if (plock->lock_cnt == -1)
    {
    plock->lock_cnt = 1;
    nret = 1;
    }
  }
futex_release(plock->plock);
return nret;
}

variable_types: struct mohq_lock { struct atomic_t { int val; } *plock; int lock_cnt; } *

variable_types: bexcl int

variable_types: nret int

user_defined_types: struct mohq_lock { struct atomic_t *plock; int lock_cnt; }


decompiled_code:
__int64 __fastcall mohq_lock_destroy(_QWORD *a1)
{
futex_get(mem_lock);
qm_free(shm_block, *a1);
return futex_release(mem_lock);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
func3(mem_lock);
qm_free(shm_block, *a1);
return func1(mem_lock);
}

original_code:
void mohq_lock_destroy (mohq_lock *plock)
{
;
do { futex_get(mem_lock); qm_free(shm_block, ((void*)plock->plock)); futex_release(mem_lock); }while(0);
return;
}

canonical_original_code:
void mohq_lock_destroy(struct mohq_lock *plock)
{
;
do { futex_get(mem_lock); qm_free(shm_block, ((void *)plock->plock)); futex_release(mem_lock); }while(0);
return;
}


decompiled_code:
__int64 __fastcall mohq_lock_init(__int64 a1)
{
_DWORD *v2; // rax
unsigned int v3; // er12
const char *v5; // r13
unsigned int v6; // eax
struct _IO_FILE *v7; // rdi
const char *v8; // r8
const char *v9; // r9
const char *v10; // r13
unsigned int v11; // eax
struct _IO_FILE *v12; // rdi
__int64 v13; // rdx
const char *v14; // [rsp-10h] [rbp-38h]
__int64 v15; // [rsp-8h] [rbp-30h]
const char *v16; // [rsp-8h] [rbp-30h]
const char *v17; // [rsp+0h] [rbp-28h]
const char *v18; // [rsp+8h] [rbp-20h]

v2 = (_DWORD *)shm_malloc_constprop_0();
*(_QWORD *)a1 = v2;
if ( !v2 )
{
v3 = 0;
if ( (int)get_debug_level("mohqueue", 8LL) >= -1 )
{
v3 = dprint_crit;
if ( dprint_crit )
{
v3 = 0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v10 = (const char *)*((_QWORD *)&log_level_info + 8);
v11 = my_pid();
v12 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): %sUnable to allocate lock memory!",
process_no,
v11,
v10,
"mohqueue [mohq_locks.c:106]: ",
"mohq_lock_init",
"mohq_lock_init: ");
if ( log_color )
dprint_color_reset(
v12,
"%2d(%d) %s: %s%s(): %sUnable to allocate lock memory!",
v13,
log_color,
v14,
v16,
v17,
v18);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): %sUnable to allocate lock memory!",
*((const char **)&log_level_info + 8),
"mohqueue [mohq_locks.c:106]: ",
"mohq_lock_init",
"mohq_lock_init: ");
}
--dprint_crit;
}
}
return v3;
}
if ( !futex_init(v2) )
{
if ( (int)get_debug_level("mohqueue", 8LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v5 = (const char *)*((_QWORD *)&log_level_info + 8);
v6 = my_pid();
v7 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): %sUnable to init lock!",
process_no,
v6,
v5,
"mohqueue [mohq_locks.c:111]: ",
"mohq_lock_init",
"mohq_lock_init: ");
if ( log_color )
dprint_color_reset(v7, "%2d(%d) %s: %s%s(): %sUnable to init lock!", v15, log_color, v8, v9, v17, v18);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): %sUnable to init lock!",
*((const char **)&log_level_info + 8),
"mohqueue [mohq_locks.c:111]: ",
"mohq_lock_init",
"mohq_lock_init: ");
}
--dprint_crit;
}
futex_get(mem_lock);
qm_free(shm_block, *(_QWORD *)a1);
v3 = 0;
futex_release(mem_lock);
return v3;
}
*(_DWORD *)(a1 + 8) = 0;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
_DWORD *v2; // rax
unsigned int v3; // er12
const char *v5; // r13
unsigned int v6; // eax
struct _IO_FILE *v7; // rdi
const char *v8; // r8
const char *v9; // r9
const char *v10; // r13
unsigned int v11; // eax
struct _IO_FILE *v12; // rdi
__int64 v13; // rdx
const char *v14; // [rsp-10h] [rbp-38h]
__int64 v15; // [rsp-8h] [rbp-30h]
const char *v16; // [rsp-8h] [rbp-30h]
const char *v17; // [rsp+0h] [rbp-28h]
const char *v18; // [rsp+8h] [rbp-20h]

v2 = (_DWORD *)func4();
*(_QWORD *)a1 = v2;
if ( !v2 )
{
v3 = 0;
if ( (int)get_debug_level("mohqueue", 8LL) >= -1 )
{
v3 = dprint_crit;
if ( dprint_crit )
{
v3 = 0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v10 = (const char *)*((_QWORD *)&log_level_info + 8);
v11 = my_pid();
v12 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): %sUnable to allocate lock memory!",
process_no,
v11,
v10,
"mohqueue [mohq_locks.c:106]: ",
"mohq_lock_init",
"mohq_lock_init: ");
if ( log_color )
dprint_color_reset(
v12,
"%2d(%d) %s: %s%s(): %sUnable to allocate lock memory!",
v13,
log_color,
v14,
v16,
v17,
v18);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): %sUnable to allocate lock memory!",
*((const char **)&log_level_info + 8),
"mohqueue [mohq_locks.c:106]: ",
"mohq_lock_init",
"mohq_lock_init: ");
}
--dprint_crit;
}
}
return v3;
}
if ( !futex_init(v2) )
{
if ( (int)get_debug_level("mohqueue", 8LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v5 = (const char *)*((_QWORD *)&log_level_info + 8);
v6 = my_pid();
v7 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): %sUnable to init lock!",
process_no,
v6,
v5,
"mohqueue [mohq_locks.c:111]: ",
"mohq_lock_init",
"mohq_lock_init: ");
if ( log_color )
dprint_color_reset(v7, "%2d(%d) %s: %s%s(): %sUnable to init lock!", v15, log_color, v8, v9, v17, v18);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): %sUnable to init lock!",
*((const char **)&log_level_info + 8),
"mohqueue [mohq_locks.c:111]: ",
"mohq_lock_init",
"mohq_lock_init: ");
}
--dprint_crit;
}
func3(mem_lock);
qm_free(shm_block, *(_QWORD *)a1);
v3 = 0;
func1(mem_lock);
return v3;
}
*(_DWORD *)(a1 + 8) = 0;
return 0xFFFFFFFFLL;
}

original_code:
int mohq_lock_init (mohq_lock *plock)
{
char *pfncname = "mohq_lock_init: ";
plock->plock = shm_malloc(sizeof(gen_lock_t));
if (!plock->plock)
  {
  do { if (get_debug_level("mohqueue", (sizeof("mohqueue")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "%sUnable to allocate lock memory!", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("mohqueue" " [" "mohq_locks.c" ":" "106" "]: ") , __func__, pfncname); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "%sUnable to allocate lock memory!", (log_level_info[((-1)) - (-5)].name), ("mohqueue" " [" "mohq_locks.c" ":" "106" "]: ") , __func__, pfncname); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "%sUnable to allocate lock memory!", process_no, my_pid(), ("mohqueue" " [" "mohq_locks.c" ":" "106" "]: ") , __func__, pfncname); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "%sUnable to allocate lock memory!", ("mohqueue" " [" "mohq_locks.c" ":" "106" "]: ") , __func__, pfncname); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "%sUnable to allocate lock memory!", ("mohqueue" " [" "mohq_locks.c" ":" "106" "]: ") , __func__, pfncname); } } (dprint_crit--); } } while(0);
  return 0;
  }
if (!futex_init(plock->plock))
  {
  do { if (get_debug_level("mohqueue", (sizeof("mohqueue")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "%sUnable to init lock!", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("mohqueue" " [" "mohq_locks.c" ":" "111" "]: ") , __func__, pfncname); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "%sUnable to init lock!", (log_level_info[((-1)) - (-5)].name), ("mohqueue" " [" "mohq_locks.c" ":" "111" "]: ") , __func__, pfncname); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "%sUnable to init lock!", process_no, my_pid(), ("mohqueue" " [" "mohq_locks.c" ":" "111" "]: ") , __func__, pfncname); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "%sUnable to init lock!", ("mohqueue" " [" "mohq_locks.c" ":" "111" "]: ") , __func__, pfncname); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "%sUnable to init lock!", ("mohqueue" " [" "mohq_locks.c" ":" "111" "]: ") , __func__, pfncname); } } (dprint_crit--); } } while(0);
  do { futex_get(mem_lock); qm_free(shm_block, ((void*)plock->plock)); futex_release(mem_lock); }while(0);
  return 0;
  }
plock->lock_cnt = 0;
return -1;
}

canonical_original_code:
int mohq_lock_init(struct mohq_lock *plock)
{
char *pfncname = "mohq_lock_init: ";
plock->plock = shm_malloc(sizeof(gen_lock_t));
if (!plock->plock)
  {
  do { if (get_debug_level("mohqueue", (sizeof("mohqueue")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "%sUnable to allocate lock memory!", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("mohqueue" " [" "mohq_locks.c" ":" "106" "]: ") , __func__, pfncname); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "%sUnable to allocate lock memory!", (log_level_info[((-1)) - (-5)].name), ("mohqueue" " [" "mohq_locks.c" ":" "106" "]: ") , __func__, pfncname); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "%sUnable to allocate lock memory!", process_no, my_pid(), ("mohqueue" " [" "mohq_locks.c" ":" "106" "]: ") , __func__, pfncname); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "%sUnable to allocate lock memory!", ("mohqueue" " [" "mohq_locks.c" ":" "106" "]: ") , __func__, pfncname); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "%sUnable to allocate lock memory!", ("mohqueue" " [" "mohq_locks.c" ":" "106" "]: ") , __func__, pfncname); } } (dprint_crit--); } } while(0);
  return 0;
  }
if (!futex_init(plock->plock))
  {
  do { if (get_debug_level("mohqueue", (sizeof("mohqueue")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "%sUnable to init lock!", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("mohqueue" " [" "mohq_locks.c" ":" "111" "]: ") , __func__, pfncname); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "%sUnable to init lock!", (log_level_info[((-1)) - (-5)].name), ("mohqueue" " [" "mohq_locks.c" ":" "111" "]: ") , __func__, pfncname); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "%sUnable to init lock!", process_no, my_pid(), ("mohqueue" " [" "mohq_locks.c" ":" "111" "]: ") , __func__, pfncname); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "%sUnable to init lock!", ("mohqueue" " [" "mohq_locks.c" ":" "111" "]: ") , __func__, pfncname); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "%sUnable to init lock!", ("mohqueue" " [" "mohq_locks.c" ":" "111" "]: ") , __func__, pfncname); } } (dprint_crit--); } } while(0);
  do { futex_get(mem_lock); qm_free(shm_block, ((void *)plock->plock)); futex_release(mem_lock); }while(0);
  return 0;
  }
plock->lock_cnt = 0;
return -1;
}

variable_types:
pfncname
char *


decompiled_code:
__int64 __fastcall mohq_lock_release(__int64 a1)
{
int v2; // eax
const char *v4; // r13
unsigned int v5; // eax
struct _IO_FILE *v6; // rdi
const char *v7; // r8
const char *v8; // r9
__int64 v9; // [rsp-8h] [rbp-30h]
const char *v10; // [rsp+0h] [rbp-28h]

futex_get(*(volatile signed __int32 **)a1);
v2 = *(_DWORD *)(a1 + 8);
if ( v2 == -1 )
{
*(_DWORD *)(a1 + 8) = 0;
}
else if ( v2 )
{
*(_DWORD *)(a1 + 8) = v2 - 1;
}
else if ( (int)get_debug_level("mohqueue", 8LL) >= 0 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0LL);
v4 = (const char *)*((_QWORD *)&log_level_info + 10);
v5 = my_pid();
v6 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): mohq_lock_release: Lock was not set",
process_no,
v5,
v4,
"mohqueue [mohq_locks.c:143]: ",
"mohq_lock_release");
if ( log_color )
dprint_color_reset(v6, "%2d(%d) %s: %s%s(): mohq_lock_release: Lock was not set", v9, log_color, v7, v8, v10);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 22) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): mohq_lock_release: Lock was not set",
*((const char **)&log_level_info + 10),
"mohqueue [mohq_locks.c:143]: ",
"mohq_lock_release");
}
--dprint_crit;
}
return futex_release(*(volatile __int32 **)a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int v2; // eax
const char *v4; // r13
unsigned int v5; // eax
struct _IO_FILE *v6; // rdi
const char *v7; // r8
const char *v8; // r9
__int64 v9; // [rsp-8h] [rbp-30h]
const char *v10; // [rsp+0h] [rbp-28h]

func3(*(volatile signed __int32 **)a1);
v2 = *(_DWORD *)(a1 + 8);
if ( v2 == -1 )
{
*(_DWORD *)(a1 + 8) = 0;
}
else if ( v2 )
{
*(_DWORD *)(a1 + 8) = v2 - 1;
}
else if ( (int)get_debug_level("mohqueue", 8LL) >= 0 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0LL);
v4 = (const char *)*((_QWORD *)&log_level_info + 10);
v5 = my_pid();
v6 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): mohq_lock_release: Lock was not set",
process_no,
v5,
v4,
"mohqueue [mohq_locks.c:143]: ",
"mohq_lock_release");
if ( log_color )
dprint_color_reset(v6, "%2d(%d) %s: %s%s(): mohq_lock_release: Lock was not set", v9, log_color, v7, v8, v10);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 22) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): mohq_lock_release: Lock was not set",
*((const char **)&log_level_info + 10),
"mohqueue [mohq_locks.c:143]: ",
"mohq_lock_release");
}
--dprint_crit;
}
return func1(*(volatile __int32 **)a1);
}

original_code:
void mohq_lock_release (mohq_lock *plock)
{
futex_get(plock->plock);
switch (plock->lock_cnt)
  {
  case -1:
    plock->lock_cnt = 0;
    break;
  case 0:
    do { if (get_debug_level("mohqueue", (sizeof("mohqueue")-1)) >= ((0)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((0)) >= -5) && (((0)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "mohq_lock_release: Lock was not set", process_no, my_pid(), (log_level_info[((0)) - (-5)].name), ("mohqueue" " [" "mohq_locks.c" ":" "143" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((0)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "mohq_lock_release: Lock was not set", (log_level_info[((0)) - (-5)].name), ("mohqueue" " [" "mohq_locks.c" ":" "143" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s" "%s(): " "mohq_lock_release: Lock was not set", process_no, my_pid(), ("mohqueue" " [" "mohq_locks.c" ":" "143" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((0))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "mohq_lock_release: Lock was not set", ("mohqueue" " [" "mohq_locks.c" ":" "143" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "mohq_lock_release: Lock was not set", ("mohqueue" " [" "mohq_locks.c" ":" "143" "]: ") , __func__); } } (dprint_crit--); } } while(0);
    break;
  default:
    plock->lock_cnt--;
    break;
  }
futex_release(plock->plock);
return;
}

canonical_original_code:
void mohq_lock_release(struct mohq_lock *plock)
{
futex_get(plock->plock);
switch (plock->lock_cnt)
  {
  case -1:
    plock->lock_cnt = 0;
    break;
  case 0:
    do { if (get_debug_level("mohqueue", (sizeof("mohqueue")-1)) >= ((0)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((0)) >= -5) && (((0)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "mohq_lock_release: Lock was not set", process_no, my_pid(), (log_level_info[((0)) - (-5)].name), ("mohqueue" " [" "mohq_locks.c" ":" "143" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((0)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "mohq_lock_release: Lock was not set", (log_level_info[((0)) - (-5)].name), ("mohqueue" " [" "mohq_locks.c" ":" "143" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s" "%s(): " "mohq_lock_release: Lock was not set", process_no, my_pid(), ("mohqueue" " [" "mohq_locks.c" ":" "143" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((0))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "mohq_lock_release: Lock was not set", ("mohqueue" " [" "mohq_locks.c" ":" "143" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "mohq_lock_release: Lock was not set", ("mohqueue" " [" "mohq_locks.c" ":" "143" "]: ") , __func__); } } (dprint_crit--); } } while(0);
    break;
  default:
    plock->lock_cnt--;
    break;
  }
futex_release(plock->plock);
return;
}


decompiled_code:
__int64 __fastcall mohq_lock_set(__int64 a1, int a2, int a3)
{
int v3; // er13
volatile __int32 *v6; // rdi
int v7; // ebp
int v8; // eax
int v9; // ebp

v3 = a3 & 3;
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
futex_release(v6);
usleep(1u);
v7 = a3 - 1;
if ( v7 >= 0 )
{
if ( !v3 )
goto LABEL_16;
if ( v3 != 1 )
{
if ( v3 != 2 )
{
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
futex_release(v6);
--v7;
usleep(1u);
}
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
futex_release(v6);
--v7;
usleep(1u);
}
futex_get(*(volatile signed __int32 **)a1);
if ( !a2 )
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 == -1 )
goto LABEL_15;
LABEL_22:
*(_DWORD *)(a1 + 8) = v8 + 1;
futex_release(v6);
return 1LL;
}
v6 = *(volatile __int32 **)a1;
if ( *(_DWORD *)(a1 + 8) )
{
LABEL_15:
futex_release(v6);
usleep(1u);
if ( --v7 >= 0 )
{
do
{
LABEL_16:
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
futex_release(v6);
v9 = v7 - 1;
usleep(1u);
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
futex_release(v6);
usleep(1u);
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
futex_release(v6);
usleep(1u);
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
futex_release(v6);
usleep(1u);
v7 = v9 - 3;
}
while ( v7 >= 0 );
}
return 0LL;
}
LABEL_24:
*(_DWORD *)(a1 + 8) = -1;
futex_release(v6);
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3)
{
int v3; // er13
volatile __int32 *v6; // rdi
int v7; // ebp
int v8; // eax
int v9; // ebp

v3 = a3 & 3;
func3(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
func1(v6);
usleep(1u);
v7 = a3 - 1;
if ( v7 >= 0 )
{
if ( !v3 )
goto LABEL_16;
if ( v3 != 1 )
{
if ( v3 != 2 )
{
func3(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
func1(v6);
--v7;
usleep(1u);
}
func3(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
func1(v6);
--v7;
usleep(1u);
}
func3(*(volatile signed __int32 **)a1);
if ( !a2 )
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 == -1 )
goto LABEL_15;
LABEL_22:
*(_DWORD *)(a1 + 8) = v8 + 1;
func1(v6);
return 1LL;
}
v6 = *(volatile __int32 **)a1;
if ( *(_DWORD *)(a1 + 8) )
{
LABEL_15:
func1(v6);
usleep(1u);
if ( --v7 >= 0 )
{
do
{
LABEL_16:
func3(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
func1(v6);
v9 = v7 - 1;
usleep(1u);
func3(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
func1(v6);
usleep(1u);
func3(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
func1(v6);
usleep(1u);
func3(*(volatile signed __int32 **)a1);
if ( a2 )
{
v6 = *(volatile __int32 **)a1;
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_24;
}
else
{
v8 = *(_DWORD *)(a1 + 8);
v6 = *(volatile __int32 **)a1;
if ( v8 != -1 )
goto LABEL_22;
}
func1(v6);
usleep(1u);
v7 = v9 - 3;
}
while ( v7 >= 0 );
}
return 0LL;
}
LABEL_24:
*(_DWORD *)(a1 + 8) = -1;
func1(v6);
return 1LL;
}
return 0LL;
}

original_code:
int mohq_lock_set (mohq_lock *plock, int bexcl, int nms_cnt)
{
int nret = 0;
do
  {
  futex_get(plock->plock);
  if (bexcl)
    {
    if (!plock->lock_cnt)
      {
      plock->lock_cnt = -1;
      nret = 1;
      }
    }
  else
    {
    if (plock->lock_cnt != -1)
      {
      plock->lock_cnt++;
      nret = 1;
      }
    }
  futex_release(plock->plock);
  if (!nret)
    { usleep (1); }
  }
while (!nret && --nms_cnt >= 0);
return nret;
}

canonical_original_code:
int mohq_lock_set(struct mohq_lock *plock, int bexcl, int nms_cnt)
{
int nret = 0;
do
  {
  futex_get(plock->plock);
  if (bexcl)
    {
    if (!plock->lock_cnt)
      {
      plock->lock_cnt = -1;
      nret = 1;
      }
    }
  else
    {
    if (plock->lock_cnt != -1)
      {
      plock->lock_cnt++;
      nret = 1;
      }
    }
  futex_release(plock->plock);
  if (!nret)
    { usleep (1); }
  }
while (!nret && --nms_cnt >= 0);
return nret;
}


decompiled_code:
__int64 reader_lock_imhash()
{
__int64 i; // rdi
int v1; // ecx
volatile __int32 *v2; // rdi

for ( i = IM_HASH; *(_DWORD *)(IM_HASH + 20LL); i = IM_HASH )
sched_yield();
while ( 1 )
{
futex_get((volatile signed __int32 *)(i + 8));
v1 = *(_DWORD *)(IM_HASH + 16LL);
if ( v1 >= 0 )
break;
futex_release((volatile __int32 *)(IM_HASH + 8LL));
sched_yield();
i = IM_HASH;
}
v2 = (volatile __int32 *)(IM_HASH + 8LL);
*(_DWORD *)(IM_HASH + 16LL) = v1 + 1;
return futex_release(v2);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 i; // rdi
int v1; // ecx
volatile __int32 *v2; // rdi

for ( i = IM_HASH; *(_DWORD *)(IM_HASH + 20LL); i = IM_HASH )
sched_yield();
while ( 1 )
{
func3((volatile signed __int32 *)(i + 8));
v1 = *(_DWORD *)(IM_HASH + 16LL);
if ( v1 >= 0 )
break;
func1((volatile __int32 *)(IM_HASH + 8LL));
sched_yield();
i = IM_HASH;
}
v2 = (volatile __int32 *)(IM_HASH + 8LL);
*(_DWORD *)(IM_HASH + 16LL) = v1 + 1;
return func1(v2);
}

original_code:
void reader_lock_imhash(void)
{
 while (IM_HASH->writer_demand) sched_yield();
 while (1) {
  futex_get(&(IM_HASH->read_lock));
  if (IM_HASH->reader_count >= 0) {
   IM_HASH->reader_count++;
   futex_release(&(IM_HASH->read_lock));
   break;
  }
  futex_release(&(IM_HASH->read_lock));
  sched_yield();
 }
}

canonical_original_code:
void reader_lock_imhash()
{
 while (IM_HASH->writer_demand) sched_yield();
 while (1) {
  futex_get(&(IM_HASH->read_lock));
  if (IM_HASH->reader_count >= 0) {
   IM_HASH->reader_count++;
   futex_release(&(IM_HASH->read_lock));
   break;
  }
  futex_release(&(IM_HASH->read_lock));
  sched_yield();
 }
}


decompiled_code:
__int64 reader_release_imhash()
{
__int64 v0; // rdi

futex_get((volatile signed __int32 *)(IM_HASH + 8LL));
v0 = IM_HASH;
--*(_DWORD *)(IM_HASH + 16LL);
return futex_release((volatile __int32 *)(v0 + 8));
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rdi

func3((volatile signed __int32 *)(IM_HASH + 8LL));
v0 = IM_HASH;
--*(_DWORD *)(IM_HASH + 16LL);
return func1((volatile __int32 *)(v0 + 8));
}

original_code:
void reader_release_imhash(void)
{
 futex_get(&(IM_HASH->read_lock));
 IM_HASH->reader_count--;
 futex_release(&(IM_HASH->read_lock));
}

canonical_original_code:
void reader_release_imhash()
{
 futex_get(&(IM_HASH->read_lock));
 IM_HASH->reader_count--;
 futex_release(&(IM_HASH->read_lock));
}


decompiled_code:
__int64 set_wd_imhash()
{
__int64 v0; // rdi
__int64 v1; // rdi

v0 = IM_HASH;
*(_DWORD *)(IM_HASH + 20LL) = 1;
while ( 1 )
{
futex_get((volatile signed __int32 *)(v0 + 8));
v1 = IM_HASH;
if ( !*(_DWORD *)(IM_HASH + 16LL) )
break;
futex_release((volatile __int32 *)(IM_HASH + 8LL));
sched_yield();
v0 = IM_HASH;
}
*(_DWORD *)(IM_HASH + 16LL) = -1;
return futex_release((volatile __int32 *)(v1 + 8));
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rdi
__int64 v1; // rdi

v0 = IM_HASH;
*(_DWORD *)(IM_HASH + 20LL) = 1;
while ( 1 )
{
func3((volatile signed __int32 *)(v0 + 8));
v1 = IM_HASH;
if ( !*(_DWORD *)(IM_HASH + 16LL) )
break;
func1((volatile __int32 *)(IM_HASH + 8LL));
sched_yield();
v0 = IM_HASH;
}
*(_DWORD *)(IM_HASH + 16LL) = -1;
return func1((volatile __int32 *)(v1 + 8));
}

original_code:
void set_wd_imhash(void)
{
 IM_HASH->writer_demand = 1;
 while(1) {
  futex_get(&(IM_HASH->read_lock));
  if (IM_HASH->reader_count == 0) {
   IM_HASH->reader_count--;
   futex_release(&(IM_HASH->read_lock));
   break;
  }
  futex_release(&(IM_HASH->read_lock));
  sched_yield();
 }
}

canonical_original_code:
void set_wd_imhash()
{
 IM_HASH->writer_demand = 1;
 while(1) {
  futex_get(&(IM_HASH->read_lock));
  if (IM_HASH->reader_count == 0) {
   IM_HASH->reader_count--;
   futex_release(&(IM_HASH->read_lock));
   break;
  }
  futex_release(&(IM_HASH->read_lock));
  sched_yield();
 }
}


decompiled_code:
__int64 del_wd_imhash()
{
__int64 v0; // rdi
__int64 result; // rax

futex_get((volatile signed __int32 *)(IM_HASH + 8LL));
v0 = IM_HASH;
++*(_DWORD *)(IM_HASH + 16LL);
result = futex_release((volatile __int32 *)(v0 + 8));
*(_DWORD *)(IM_HASH + 20LL) = 0;
return result;
}

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

func3((volatile signed __int32 *)(IM_HASH + 8LL));
v0 = IM_HASH;
++*(_DWORD *)(IM_HASH + 16LL);
result = func1((volatile __int32 *)(v0 + 8));
*(_DWORD *)(IM_HASH + 20LL) = 0;
return result;
}

original_code:
void del_wd_imhash(void) {
 futex_get(&(IM_HASH->read_lock));
 IM_HASH->reader_count++;
 futex_release(&(IM_HASH->read_lock));
 IM_HASH->writer_demand = 0;
}

canonical_original_code:
void del_wd_imhash() {
 futex_get(&(IM_HASH->read_lock));
 IM_HASH->reader_count++;
 futex_release(&(IM_HASH->read_lock));
 IM_HASH->writer_demand = 0;
}


decompiled_code:
void *pike_top_get_root()
{
return top_list_root;
}

canonical_decompiled_code:
void *func1()
{
return top_list_root;
}

original_code: struct TopListItem_t *pike_top_get_root() { return top_list_root; }

return_type: struct TopListItem_t { int addr_len; unsigned char ip_addr[16]; unsigned short leaf_hits[2]; unsigned short hits[2]; unsigned int expires; enum node_status_t { NODE_STATUS_OK=0, NODE_STATUS_WARM=1, NODE_STATUS_HOT=2, NODE_STATUS_ALL=3 } status; struct TopListItem_t *next; } *

user_defined_types: struct TopListItem_t { int addr_len; unsigned char ip_addr[16]; unsigned short leaf_hits[2]; unsigned short hits[2]; unsigned int expires; enum node_status_t status; struct TopListItem_t *next; }


decompiled_code:
__int64 pike_top_list_clear()
{
void *v0; // rbx
void *v1; // rdi
__int64 result; // rax

v0 = top_list_root;
for ( top_list_iter = (__int64)top_list_root; v0; top_list_iter = (__int64)v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 5);
free(v1);
}
result = 0LL;
top_list_root = 0LL;
memset(buff, 0, sizeof(buff));
return result;
}

canonical_decompiled_code:
__int64 func5()
{
void *v0; // rbx
void *v1; // rdi
__int64 result; // rax

v0 = top_list_root;
for ( top_list_iter = (__int64)top_list_root; v0; top_list_iter = (__int64)v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 5);
free(v1);
}
result = 0LL;
top_list_root = 0LL;
memset(buff, 0, sizeof(buff));
return result;
}

original_code:
void pike_top_list_clear()
{
 struct TopListItem_t *ptr;
 top_list_iter = top_list_root;
 while (top_list_iter) {
  ptr = top_list_iter->next;
  free(top_list_iter);
  top_list_iter = ptr;
 }
 top_list_root = 0;
 memset(buff, 0, sizeof(buff));
}

variable_types: struct TopListItem_t { int addr_len; unsigned char ip_addr[16]; unsigned short leaf_hits[2]; unsigned short hits[2]; unsigned int expires; enum node_status_t { NODE_STATUS_OK=0, NODE_STATUS_WARM=1, NODE_STATUS_HOT=2, NODE_STATUS_ALL=3 } status; struct TopListItem_t *next; } *


decompiled_code:
__int64 __fastcall compare_name_map(const void *a1, const void *a2)
{
int v2; // eax
bool v3; // cc
__int64 result; // rax

v2 = *((_DWORD *)a2 + 4);
v3 = *((_DWORD *)a1 + 4) < v2;
result = *((_DWORD *)a1 + 4) > v2;
if ( v3 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
int v2; // eax
bool v3; // cc
__int64 result; // rax

v2 = *((_DWORD *)a2 + 4);
v3 = *((_DWORD *)a1 + 4) < v2;
result = *((_DWORD *)a1 + 4) > v2;
if ( v3 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int compare_name_map(const void *v1, const void *v2) {
 if (((struct name_map_t *)v1)->id < ((struct name_map_t *)v2)->id) return -1;
 else if (((struct name_map_t *)v1)->id > ((struct name_map_t *)v2)->id) return 1;
 else return 0;
}

canonical_original_code:
int compare_name_map(void *v1, void *v2) {
 if (((struct name_map_t *)v1)->id < ((struct name_map_t *)v2)->id) return -1;
 else if (((struct name_map_t *)v1)->id > ((struct name_map_t *)v2)->id) return 1;
 else return 0;
}

user_defined_types: struct name_map_t { struct _str name; int id; }


decompiled_code:
__int64 __fastcall map_name2id(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // r13
__int64 v6; // rcx
__int64 v7; // r12

if ( a3 )
{
if ( *(int *)(a3 + 8) <= 0 || a2 <= 0 )
return 0xFFFFFFFFLL;
v4 = a1;
v5 = a1 + 24LL * (unsigned int)(a2 - 1) + 24;
v6 = a2 & 7;
if ( (a2 & 7) == 0 )
{
LABEL_23:
while ( str_strcmp(v4, a3) )
{
v7 = v4 + 24;
v4 += 24LL;
if ( !str_strcmp(v4, a3) )
break;
v4 += 24LL;
if ( !str_strcmp(v4, a3) )
break;
v4 = v7 + 48;
if ( !str_strcmp(v7 + 48, a3) )
break;
v4 = v7 + 72;
if ( !str_strcmp(v7 + 72, a3) )
break;
v4 = v7 + 96;
if ( !str_strcmp(v7 + 96, a3) )
break;
v4 = v7 + 120;
if ( !str_strcmp(v7 + 120, a3) )
break;
v4 = v7 + 144;
if ( !str_strcmp(v7 + 144, a3) )
break;
v4 = v7 + 168;
if ( v7 + 168 == v5 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v4 + 16);
}
if ( v6 == 1 )
goto LABEL_21;
if ( v6 != 2 )
{
if ( v6 != 3 )
{
if ( v6 != 4 )
{
if ( v6 != 5 )
{
if ( v6 != 6 )
{
if ( !str_strcmp(a1, a3) )
return *(unsigned int *)(v4 + 16);
v4 = a1 + 24;
}
if ( !str_strcmp(v4, a3) )
return *(unsigned int *)(v4 + 16);
v4 += 24LL;
}
if ( !str_strcmp(v4, a3) )
return *(unsigned int *)(v4 + 16);
v4 += 24LL;
}
if ( !str_strcmp(v4, a3) )
return *(unsigned int *)(v4 + 16);
v4 += 24LL;
}
if ( !str_strcmp(v4, a3) )
return *(unsigned int *)(v4 + 16);
v4 += 24LL;
}
if ( str_strcmp(v4, a3) )
{
v4 += 24LL;
LABEL_21:
if ( str_strcmp(v4, a3) )
{
v4 += 24LL;
if ( v4 != v5 )
goto LABEL_23;
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v4 + 16);
}
return *(unsigned int *)(v4 + 16);
}
return 0xFFFFFFFFLL;
}

original_code:
int map_name2id(struct name_map_t * map, int size, const str * name) {
 int i;
 if ((!name) || (name->len <= 0)) {
  return -1;
 }
 for (i=0; i<size; i++) {
  if (str_strcmp(&map[i].name, name) == 0) return map[i].id;
 }
 return -1;
}

canonical_original_code:
int map_name2id(struct name_map_t *map, int size, struct _str *name) {
 int i;
 if ((!name) || (name->len <= 0)) {
  return -1;
 }
 for (i=0; i<size; i++) {
  if (str_strcmp(&map[i].name, name) == 0) return map[i].id;
 }
 return -1;
}

variable_types: struct name_map_t { struct _str { char *s; int len; } name; int id; } *

variable_types: size int

variable_types:
name
struct _str *


decompiled_code:
void *__fastcall map_id2name(void *base, int a2, int a3)
{
_DWORD v4[10]; // [rsp+0h] [rbp-28h] BYREF

v4[4] = a3;
return bsearch(v4, base, a2, 0x18uLL, (__compar_fn_t)compare_name_map);
}

canonical_decompiled_code:
void *__fastcall func3(void *base, int a2, int a3)
{
_DWORD v4[10]; // [rsp+0h] [rbp-28h] BYREF

v4[4] = a3;
return bsearch(v4, base, a2, 0x18uLL, (__compar_fn_t)compare_name_map);
}

original_code:
str * map_id2name(struct name_map_t * map, int size, int id) {
 struct name_map_t key;
 struct name_map_t * tmp;
 key.id = id;
 tmp = bsearch(&key, map, size, sizeof(struct name_map_t), compare_name_map);
 if (tmp == ((void *)0)) return ((void *)0);
 return &tmp->name;
}

canonical_original_code:
struct _str *map_id2name(struct name_map_t *map, int size, int id) {
 struct name_map_t key;
 struct name_map_t *tmp;
 key.id = id;
 tmp = bsearch(&key, map, size, sizeof(struct name_map_t), compare_name_map);
 if (tmp == ((void *)0)) return ((void *)0);
 return &tmp->name;
}

variable_types: struct name_map_t { struct _str name; int id; } *

variable_types: id int

variable_types: struct name_map_t { struct _str { char *s; int len; } name; int id; }

return_type: struct _str { char *s; int len; } *


decompiled_code:
int __fastcall str_strcmp(__int64 a1, __int64 a2)
{
size_t v2; // rdx
int v3; // eax
int result; // eax
int v5; // edx
const char *v6; // r12
struct _IO_FILE *v7; // rdi
__int64 v8; // [rsp-28h] [rbp-28h]
unsigned int v9; // [rsp-20h] [rbp-20h]

if ( a1
&& a2
&& *(_QWORD *)a1
&& *(_QWORD *)a2
&& (v2 = *(int *)(a1 + 8), (v2 & 0x80000000) == 0LL)
&& (v3 = *(_DWORD *)(a2 + 8), v3 >= 0) )
{
if ( (int)v2 < v3 )
{
result = -1;
}
else if ( (int)v2 <= v3 )
{
result = strncmp(*(const char **)a1, *(const char **)a2, v2);
}
else
{
result = 1;
}
}
else
{
v5 = get_debug_level("carrierroute", 12LL);
result = -2;
if ( v5 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v6 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid();
v7 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): bad parameters\n",
process_no,
v9,
v6,
"carrierroute [../../ut.h:755]: ",
"str_strcmp");
if ( log_color )
dprint_color_reset(v7, "%2d(%d) %s: %s%s(): bad parameters\n", v8);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): bad parameters\n",
*((const char **)&log_level_info + 8),
"carrierroute [../../ut.h:755]: ",
"str_strcmp");
}
result = -2;
--dprint_crit;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
size_t v2; // rdx
int v3; // eax
int result; // eax
int v5; // edx
const char *v6; // r12
struct _IO_FILE *v7; // rdi
__int64 v8; // [rsp-28h] [rbp-28h]
unsigned int v9; // [rsp-20h] [rbp-20h]

if ( a1
&& a2
&& *(_QWORD *)a1
&& *(_QWORD *)a2
&& (v2 = *(int *)(a1 + 8), (v2 & 0x80000000) == 0LL)
&& (v3 = *(_DWORD *)(a2 + 8), v3 >= 0) )
{
if ( (int)v2 < v3 )
{
result = -1;
}
else if ( (int)v2 <= v3 )
{
result = strncmp(*(const char **)a1, *(const char **)a2, v2);
}
else
{
result = 1;
}
}
else
{
v5 = get_debug_level("carrierroute", 12LL);
result = -2;
if ( v5 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v6 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid();
v7 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): bad parameters\n",
process_no,
v9,
v6,
"carrierroute [../../ut.h:755]: ",
"str_strcmp");
if ( log_color )
dprint_color_reset(v7, "%2d(%d) %s: %s%s(): bad parameters\n", v8);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): bad parameters\n",
*((const char **)&log_level_info + 8),
"carrierroute [../../ut.h:755]: ",
"str_strcmp");
}
result = -2;
--dprint_crit;
}
}
return result;
}

original_code:
static inline int str_strcmp(const str *str1, const str *str2)
{
 if(str1==((void *)0) || str2==((void *)0) || str1->s ==((void *)0) || str2->s==((void *)0) || str1->len<0 || str2->len<0)
 {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "bad parameters\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "../../ut.h" ":" "755" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "bad parameters\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "../../ut.h" ":" "755" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "bad parameters\n", process_no, my_pid(), ("carrierroute" " [" "../../ut.h" ":" "755" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "bad parameters\n", ("carrierroute" " [" "../../ut.h" ":" "755" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "bad parameters\n", ("carrierroute" " [" "../../ut.h" ":" "755" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -2;
 }
 if (str1->len < str2->len)
  return -1;
 else if (str1->len > str2->len)
  return 1;
 else
  return strncmp(str1->s, str2->s, str1->len);
}

canonical_original_code:
static inline int str_strcmp(struct _str *str1, struct _str *str2)
{
 if(str1==((void *)0) || str2==((void *)0) || str1->s ==((void *)0) || str2->s==((void *)0) || str1->len<0 || str2->len<0)
 {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "bad parameters\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "../../ut.h" ":" "755" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "bad parameters\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "../../ut.h" ":" "755" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "bad parameters\n", process_no, my_pid(), ("carrierroute" " [" "../../ut.h" ":" "755" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "bad parameters\n", ("carrierroute" " [" "../../ut.h" ":" "755" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "bad parameters\n", ("carrierroute" " [" "../../ut.h" ":" "755" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -2;
 }
 if (str1->len < str2->len)
  return -1;
 else if (str1->len > str2->len)
  return 1;
 else
  return strncmp(str1->s, str2->s, str1->len);
}


decompiled_code:
__int64 __fastcall atomic_get_and_set_int(volatile __int32 *a1, __int32 a2)
{
return (unsigned int)_InterlockedExchange(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(volatile __int32 *a1, __int32 a2)
{
return (unsigned int)_InterlockedExchange(a1, a2);
}

original_code: inline static int atomic_get_and_set_int(volatile int* var, int v) { asm volatile( "xchgl %1, %0" " \n\t" : "+q"(v), "=m"(*var) : "m"(*var) : "memory" ); return v; }


decompiled_code:
__int64 __fastcall futex_release(volatile __int32 *a1)
{
__int64 result; // rax
__int64 v2; // [rsp-10h] [rbp-18h]

result = atomic_get_and_set_int(a1, 0);
if ( (_DWORD)result == 2 )
{
syscall(202LL, a1, 1LL, 1LL, 0LL, 0LL, 0LL);
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(volatile __int32 *a1)
{
__int64 result; // rax
__int64 v2; // [rsp-10h] [rbp-18h]

result = func0(a1, 0);
if ( (_DWORD)result == 2 )
{
syscall(202LL, a1, 1LL, 1LL, 0LL, 0LL, 0LL);
result = v2;
}
return result;
}

original_code:
inline static void futex_release(futex_lock_t* lock)
{
 int v;
 do {} while(0);
 v=atomic_get_and_set_int(&(lock)->val, 0);
 if (__builtin_expect(!!(v==2), 0)){
  syscall(202 , (&(lock)->val), (1), (1), (0), (0), (0));
 }
}