decompiled_code:
__int64 __fastcall bind_ipops(__int64 (__fastcall **a1)(__int64 *a1, __int64 *a2))
{
__int64 result; // rax
int v2; // ebx
const char *v3; // rbx
unsigned int v4; // eax

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 (__fastcall **a1)(__int64 *a1, __int64 *a2))
{
__int64 result; // rax
int v2; // ebx
const char *v3; // rbx
unsigned int v4; // eax

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


repo: virtualolson/who

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

return_type: int


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

result = atomic_cmpxchg_int(a1, 0, 1);
if ( (_DWORD)result )
{
v2 = 1024;
if ( (_DWORD)result == 2 )
{
do
{
LABEL_3:
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(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
v3 = v2 - 1;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
v2 = v3 - 7;
if ( !v2 )
{
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 func2(volatile signed __int32 *a1)
{
__int64 result; // rax
int v2; // ebp
int v3; // ebp

result = func1(a1, 0, 1);
if ( (_DWORD)result )
{
v2 = 1024;
if ( (_DWORD)result == 2 )
{
do
{
LABEL_3:
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
result = func0(a1, 2);
}
while ( (_DWORD)result );
}
else
{
while ( 1 )
{
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
v3 = v2 - 1;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
v2 = v3 - 7;
if ( !v2 )
{
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:
lock
struct atomic_t { int val; } *

variable_types: i int

return_type: void


decompiled_code:
__int64 __fastcall futex_release(volatile __int32 *a1)
{
__int64 result; // rax

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

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

result = func0(a1, 0);
if ( (_DWORD)result == 2 )
result = syscall(202LL, a1, 1LL, 1LL, 0LL, 0LL, 0LL);
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));
 }
}


decompiled_code:
__int64 __fastcall mohq_lock_change(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebx

v2 = a2;
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
v2 = *(_DWORD *)(a1 + 8);
if ( v2 == 1 )
*(_DWORD *)(a1 + 8) = -1;
else
v2 = 0;
}
else if ( *(_DWORD *)(a1 + 8) == -1 )
{
*(_DWORD *)(a1 + 8) = 1;
v2 = 1;
}
futex_release(*(volatile __int32 **)a1);
return v2;
}

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

v2 = a2;
func2(*(volatile signed __int32 **)a1);
if ( a2 )
{
v2 = *(_DWORD *)(a1 + 8);
if ( v2 == 1 )
*(_DWORD *)(a1 + 8) = -1;
else
v2 = 0;
}
else if ( *(_DWORD *)(a1 + 8) == -1 )
{
*(_DWORD *)(a1 + 8) = 1;
v2 = 1;
}
func3(*(volatile __int32 **)a1);
return v2;
}

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)
{
func2(mem_lock);
qm_free(shm_block, *a1);
return func3(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 *v1; // rax
unsigned int v2; // ebx
const char *v4; // rbp
unsigned int v5; // eax
const char *v6; // rbp
unsigned int v7; // eax

v1 = (_DWORD *)shm_malloc(4u);
*(_QWORD *)a1 = v1;
if ( v1 )
{
if ( futex_init(v1) )
{
*(_DWORD *)(a1 + 8) = 0;
v2 = -1;
}
else
{
if ( (int)get_debug_level("mohqueue", 8LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v6 = (const char *)*((_QWORD *)&log_level_info + 8);
v7 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): %sUnable to init lock!",
process_no,
v7,
v6,
"mohqueue [mohq_locks.c:111]: ",
"mohq_lock_init",
"mohq_lock_init: ");
if ( log_color )
dprint_color_reset();
}
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);
futex_release(mem_lock);
v2 = 0;
}
}
else
{
v2 = 0;
if ( (int)get_debug_level("mohqueue", 8LL) >= -1 )
{
v2 = dprint_crit;
if ( dprint_crit )
{
v2 = 0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v4 = (const char *)*((_QWORD *)&log_level_info + 8);
v5 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): %sUnable to allocate lock memory!",
process_no,
v5,
v4,
"mohqueue [mohq_locks.c:106]: ",
"mohq_lock_init",
"mohq_lock_init: ");
if ( log_color )
dprint_color_reset();
}
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 v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
_DWORD *v1; // rax
unsigned int v2; // ebx
const char *v4; // rbp
unsigned int v5; // eax
const char *v6; // rbp
unsigned int v7; // eax

v1 = (_DWORD *)func4(4u);
*(_QWORD *)a1 = v1;
if ( v1 )
{
if ( futex_init(v1) )
{
*(_DWORD *)(a1 + 8) = 0;
v2 = -1;
}
else
{
if ( (int)get_debug_level("mohqueue", 8LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v6 = (const char *)*((_QWORD *)&log_level_info + 8);
v7 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): %sUnable to init lock!",
process_no,
v7,
v6,
"mohqueue [mohq_locks.c:111]: ",
"mohq_lock_init",
"mohq_lock_init: ");
if ( log_color )
dprint_color_reset();
}
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;
}
func2(mem_lock);
qm_free(shm_block, *(_QWORD *)a1);
func3(mem_lock);
v2 = 0;
}
}
else
{
v2 = 0;
if ( (int)get_debug_level("mohqueue", 8LL) >= -1 )
{
v2 = dprint_crit;
if ( dprint_crit )
{
v2 = 0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v4 = (const char *)*((_QWORD *)&log_level_info + 8);
v5 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): %sUnable to allocate lock memory!",
process_no,
v5,
v4,
"mohqueue [mohq_locks.c:106]: ",
"mohq_lock_init",
"mohq_lock_init: ");
if ( log_color )
dprint_color_reset();
}
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 v2;
}

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 *

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


decompiled_code:
__int64 __fastcall mohq_lock_release(__int64 a1)
{
int v1; // eax
const char *v3; // rbp
unsigned int v4; // eax

futex_get(*(volatile signed __int32 **)a1);
v1 = *(_DWORD *)(a1 + 8);
if ( v1 == -1 )
{
*(_DWORD *)(a1 + 8) = 0;
}
else if ( v1 )
{
*(_DWORD *)(a1 + 8) = v1 - 1;
}
else if ( (int)get_debug_level("mohqueue", 8LL) >= 0 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0LL);
v3 = (const char *)*((_QWORD *)&log_level_info + 10);
v4 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): mohq_lock_release: Lock was not set",
process_no,
v4,
v3,
"mohqueue [mohq_locks.c:143]: ",
"mohq_lock_release");
if ( log_color )
dprint_color_reset();
}
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 v1; // eax
const char *v3; // rbp
unsigned int v4; // eax

func2(*(volatile signed __int32 **)a1);
v1 = *(_DWORD *)(a1 + 8);
if ( v1 == -1 )
{
*(_DWORD *)(a1 + 8) = 0;
}
else if ( v1 )
{
*(_DWORD *)(a1 + 8) = v1 - 1;
}
else if ( (int)get_debug_level("mohqueue", 8LL) >= 0 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0LL);
v3 = (const char *)*((_QWORD *)&log_level_info + 10);
v4 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): mohq_lock_release: Lock was not set",
process_no,
v4,
v3,
"mohqueue [mohq_locks.c:143]: ",
"mohq_lock_release");
if ( log_color )
dprint_color_reset();
}
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 func3(*(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 v4; // er13
int v5; // ebp
int v6; // eax
int v8; // ebp

v4 = a3 & 3;
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 != -1 )
goto LABEL_11;
}
futex_release(*(volatile __int32 **)a1);
usleep(1u);
v5 = a3 - 1;
if ( v5 >= 0 )
{
if ( !v4 )
goto LABEL_41;
if ( v4 == 1 )
goto LABEL_27;
if ( v4 != 2 )
{
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 != -1 )
goto LABEL_11;
}
futex_release(*(volatile __int32 **)a1);
usleep(1u);
--v5;
}
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
goto LABEL_26;
}
v6 = *(_DWORD *)(a1 + 8);
if ( v6 == -1 )
{
LABEL_26:
futex_release(*(volatile __int32 **)a1);
usleep(1u);
--v5;
LABEL_27:
futex_get(*(volatile signed __int32 **)a1);
if ( !a2 )
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 == -1 )
{
LABEL_31:
futex_release(*(volatile __int32 **)a1);
usleep(1u);
if ( --v5 >= 0 )
{
do
{
LABEL_41:
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 != -1 )
goto LABEL_11;
}
futex_release(*(volatile __int32 **)a1);
usleep(1u);
v8 = v5 - 1;
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 != -1 )
goto LABEL_11;
}
futex_release(*(volatile __int32 **)a1);
usleep(1u);
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 != -1 )
goto LABEL_11;
}
futex_release(*(volatile __int32 **)a1);
usleep(1u);
futex_get(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 != -1 )
goto LABEL_11;
}
futex_release(*(volatile __int32 **)a1);
usleep(1u);
v5 = v8 - 3;
}
while ( v5 >= 0 );
}
return 0LL;
}
goto LABEL_11;
}
if ( *(_DWORD *)(a1 + 8) )
goto LABEL_31;
LABEL_43:
*(_DWORD *)(a1 + 8) = -1;
goto LABEL_12;
}
LABEL_11:
*(_DWORD *)(a1 + 8) = v6 + 1;
LABEL_12:
futex_release(*(volatile __int32 **)a1);
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3)
{
int v4; // er13
int v5; // ebp
int v6; // eax
int v8; // ebp

v4 = a3 & 3;
func2(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 != -1 )
goto LABEL_11;
}
func3(*(volatile __int32 **)a1);
usleep(1u);
v5 = a3 - 1;
if ( v5 >= 0 )
{
if ( !v4 )
goto LABEL_41;
if ( v4 == 1 )
goto LABEL_27;
if ( v4 != 2 )
{
func2(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 != -1 )
goto LABEL_11;
}
func3(*(volatile __int32 **)a1);
usleep(1u);
--v5;
}
func2(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
goto LABEL_26;
}
v6 = *(_DWORD *)(a1 + 8);
if ( v6 == -1 )
{
LABEL_26:
func3(*(volatile __int32 **)a1);
usleep(1u);
--v5;
LABEL_27:
func2(*(volatile signed __int32 **)a1);
if ( !a2 )
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 == -1 )
{
LABEL_31:
func3(*(volatile __int32 **)a1);
usleep(1u);
if ( --v5 >= 0 )
{
do
{
LABEL_41:
func2(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 != -1 )
goto LABEL_11;
}
func3(*(volatile __int32 **)a1);
usleep(1u);
v8 = v5 - 1;
func2(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 != -1 )
goto LABEL_11;
}
func3(*(volatile __int32 **)a1);
usleep(1u);
func2(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 != -1 )
goto LABEL_11;
}
func3(*(volatile __int32 **)a1);
usleep(1u);
func2(*(volatile signed __int32 **)a1);
if ( a2 )
{
if ( !*(_DWORD *)(a1 + 8) )
goto LABEL_43;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
if ( v6 != -1 )
goto LABEL_11;
}
func3(*(volatile __int32 **)a1);
usleep(1u);
v5 = v8 - 3;
}
while ( v5 >= 0 );
}
return 0LL;
}
goto LABEL_11;
}
if ( *(_DWORD *)(a1 + 8) )
goto LABEL_31;
LABEL_43:
*(_DWORD *)(a1 + 8) = -1;
goto LABEL_12;
}
LABEL_11:
*(_DWORD *)(a1 + 8) = v6 + 1;
LABEL_12:
func3(*(volatile __int32 **)a1);
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 v0; // rdi
int v1; // er8

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

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rdi
int v1; // er8

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

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

func2((volatile signed __int32 *)(IM_HASH + 8LL));
v0 = IM_HASH;
--*(_DWORD *)(IM_HASH + 16LL);
return func3((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

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

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

*(_DWORD *)(IM_HASH + 20LL) = 1;
while ( 1 )
{
func2((volatile signed __int32 *)(IM_HASH + 8LL));
v0 = IM_HASH;
if ( !*(_DWORD *)(IM_HASH + 16LL) )
break;
func3((volatile __int32 *)(IM_HASH + 8LL));
sched_yield();
}
*(_DWORD *)(IM_HASH + 16LL) = -1;
return func3((volatile __int32 *)(v0 + 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

func2((volatile signed __int32 *)(IM_HASH + 8LL));
v0 = IM_HASH;
++*(_DWORD *)(IM_HASH + 16LL);
result = func3((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 + 10);
free(v1);
}
top_list_root = 0LL;
result = 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 + 10);
free(v1);
}
top_list_root = 0LL;
result = 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; // ecx
int v3; // edx
__int64 result; // rax

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

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

v2 = *((_DWORD *)a1 + 4);
v3 = *((_DWORD *)a2 + 4);
result = 0xFFFFFFFFLL;
if ( v2 >= v3 )
result = v2 > v3;
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; // r12
__int64 v6; // rcx
__int64 v7; // r13
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
__int64 v13; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // r12
__int64 v6; // rcx
__int64 v7; // r13
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
__int64 v13; // rbx

if ( !a3 )
return 0xFFFFFFFFLL;
if ( *(int *)(a3 + 8) <= 0 )
return 0xFFFFFFFFLL;
if ( a2 <= 0 )
return 0xFFFFFFFFLL;
v4 = a1;
v5 = a1 + 24LL * (unsigned int)(a2 - 1) + 24;
v6 = a2 & 7;
if ( (a2 & 7) == 0 )
{
LABEL_19:
while ( 1 )
{
v7 = v4;
if ( !(unsigned int)func1(v4, a3) )
break;
v13 = v4 + 24;
v7 = v13;
if ( !(unsigned int)func1(v13, a3) )
break;
v7 = v13 + 24;
if ( !(unsigned int)func1(v13 + 24, a3) )
break;
v7 = v13 + 48;
if ( !(unsigned int)func1(v13 + 48, a3) )
break;
v7 = v13 + 72;
if ( !(unsigned int)func1(v13 + 72, a3) )
break;
v7 = v13 + 96;
if ( !(unsigned int)func1(v13 + 96, a3) )
break;
v7 = v13 + 120;
if ( !(unsigned int)func1(v13 + 120, a3) )
break;
v7 = v13 + 144;
if ( !(unsigned int)func1(v13 + 144, a3) )
break;
v4 = v13 + 168;
if ( v4 == v5 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v7 + 16);
}
if ( v6 != 1 )
{
if ( v6 != 2 )
{
if ( v6 != 3 )
{
if ( v6 != 4 )
{
if ( v6 != 5 )
{
if ( v6 != 6 )
{
v7 = a1;
v4 = a1 + 24;
if ( !(unsigned int)func1(a1, a3) )
return *(unsigned int *)(v7 + 16);
}
v7 = v4;
v8 = func1(v4, a3);
v4 += 24LL;
if ( !v8 )
return *(unsigned int *)(v7 + 16);
}
v7 = v4;
v9 = func1(v4, a3);
v4 += 24LL;
if ( !v9 )
return *(unsigned int *)(v7 + 16);
}
v7 = v4;
v10 = func1(v4, a3);
v4 += 24LL;
if ( !v10 )
return *(unsigned int *)(v7 + 16);
}
v7 = v4;
v11 = func1(v4, a3);
v4 += 24LL;
if ( !v11 )
return *(unsigned int *)(v7 + 16);
}
v7 = v4;
v12 = func1(v4, a3);
v4 += 24LL;
if ( !v12 )
return *(unsigned int *)(v7 + 16);
}
v7 = v4;
if ( !(unsigned int)func1(v4, a3) )
return *(unsigned int *)(v7 + 16);
v4 += 24LL;
if ( v4 != v5 )
goto LABEL_19;
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:
__int64 __fastcall str_strcmp(__int64 a1, __int64 a2)
{
int v2; // edx
int v3; // eax
unsigned int v4; // ecx
int v6; // eax
__int64 v7; // rsi
const char *v8; // rbx
unsigned int v9; // eax

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
int v2; // edx
int v3; // eax
unsigned int v4; // ecx
int v6; // eax
__int64 v7; // rsi
const char *v8; // rbx
unsigned int v9; // eax

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

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_get(volatile signed __int32 *a1)
{
__int64 result; // rax
int v2; // ebp
int v3; // ebp

result = atomic_cmpxchg_int(a1, 0, 1);
if ( (_DWORD)result )
{
v2 = 1024;
if ( (_DWORD)result == 2 )
{
do
{
LABEL_3:
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(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
v3 = v2 - 1;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
v2 = v3 - 7;
if ( !v2 )
{
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 func2(volatile signed __int32 *a1)
{
__int64 result; // rax
int v2; // ebp
int v3; // ebp

result = func1(a1, 0, 1);
if ( (_DWORD)result )
{
v2 = 1024;
if ( (_DWORD)result == 2 )
{
do
{
LABEL_3:
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
result = func0(a1, 2);
}
while ( (_DWORD)result );
}
else
{
while ( 1 )
{
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
v3 = v2 - 1;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
v2 = v3 - 7;
if ( !v2 )
{
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);
}


decompiled_code:
__int64 __fastcall futex_release(volatile __int32 *a1)
{
__int64 result; // rax

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

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

result = func0(a1, 0);
if ( (_DWORD)result == 2 )
result = syscall(202LL, a1, 1LL, 1LL, 0LL, 0LL, 0LL);
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));
 }
}


decompiled_code:
__int64 __fastcall shm_malloc(unsigned int a1)
{
__int64 v1; // rbx

futex_get(mem_lock);
v1 = qm_malloc(shm_block, a1);
futex_release(mem_lock);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
__int64 v1; // rbx

func2(mem_lock);
v1 = qm_malloc(shm_block, a1);
func3(mem_lock);
return v1;
}

original_code:
inline static void* shm_malloc(unsigned int size)
{
 void *p;
 futex_get(mem_lock);
 p=qm_malloc(shm_block, (size));
 futex_release(mem_lock);
  return p;
}

canonical_original_code:
inline static void *shm_malloc(unsigned int size)
{
 void *p;
 futex_get(mem_lock);
 p=qm_malloc(shm_block, (size));
 futex_release(mem_lock);
  return p;
}

variable_types:
size
unsigned int

variable_types:
p
void *

return_type: void *


decompiled_code:
__int64 __fastcall free_conditions(_QWORD *a1)
{
__int64 v2; // rdi
int *v3; // rbp
__int64 result; // rax
int *v5; // rbx

if ( a1 )
{
if ( *a1 )
{
futex_get(mem_lock);
qm_free(shm_block, *a1);
futex_release(mem_lock);
}
v2 = a1[1];
if ( v2 )
free_identity(v2);
v3 = (int *)a1[2];
while ( v3 )
{
v5 = v3;
v3 = *(int **)v3;
if ( v5[4] > 0 )
{
if ( *((_QWORD *)v5 + 1) )
{
futex_get(mem_lock);
qm_free(shm_block, *((_QWORD *)v5 + 1));
futex_release(mem_lock);
}
}
v5[4] = 0;
*((_QWORD *)v5 + 1) = 0LL;
futex_get(mem_lock);
qm_free(shm_block, v5);
futex_release(mem_lock);
}
futex_get(mem_lock);
qm_free(shm_block, a1);
result = futex_release(mem_lock);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
__int64 v2; // rdi
int *v3; // rbp
__int64 result; // rax
int *v5; // rbx

if ( a1 )
{
if ( *a1 )
{
func2(mem_lock);
qm_free(shm_block, *a1);
func3(mem_lock);
}
v2 = a1[1];
if ( v2 )
func5(v2);
v3 = (int *)a1[2];
while ( v3 )
{
v5 = v3;
v3 = *(int **)v3;
if ( v5[4] > 0 )
{
if ( *((_QWORD *)v5 + 1) )
{
func2(mem_lock);
qm_free(shm_block, *((_QWORD *)v5 + 1));
func3(mem_lock);
}
}
v5[4] = 0;
*((_QWORD *)v5 + 1) = 0LL;
func2(mem_lock);
qm_free(shm_block, v5);
func3(mem_lock);
}
func2(mem_lock);
qm_free(shm_block, a1);
result = func3(mem_lock);
}
return result;
}

original_code:
static void free_conditions(cp_conditions_t *c)
{
 cp_sphere_t *s, *n;
 if (!c) return;
 if (c->validity) do { futex_get(mem_lock); qm_free(shm_block, (c->validity)); futex_release(mem_lock); }while(0);
 if (c->identity) free_identity(c->identity);
 s = c->spheres;
 while (s) {
  n = s->next;
  do { if (&s->value != ((void *)0)) { if (((&s->value)->len > 0) && ((&s->value)->s)) do { futex_get(mem_lock); qm_free(shm_block, ((&s->value)->s)); futex_release(mem_lock); }while(0); (&s->value)->len = 0; (&s->value)->s = 0; } } while (0);
  do { futex_get(mem_lock); qm_free(shm_block, (s)); futex_release(mem_lock); }while(0);
  s = n;
 }
 do { futex_get(mem_lock); qm_free(shm_block, (c)); futex_release(mem_lock); }while(0);
}

canonical_original_code:
static void free_conditions(struct cp_conditions_t *c)
{
 struct _cp_sphere_t *s; struct _cp_sphere_t *n;
 if (!c) return;
 if (c->validity) do { futex_get(mem_lock); qm_free(shm_block, (c->validity)); futex_release(mem_lock); }while(0);
 if (c->identity) free_identity(c->identity);
 s = c->spheres;
 while (s) {
  n = s->next;
  do { if (&s->value != ((void *)0)) { if (((&s->value)->len > 0) && ((&s->value)->s)) do { futex_get(mem_lock); qm_free(shm_block, ((&s->value)->s)); futex_release(mem_lock); }while(0); (&s->value)->len = 0; (&s->value)->s = 0; } } while (0);
  do { futex_get(mem_lock); qm_free(shm_block, (s)); futex_release(mem_lock); }while(0);
  s = n;
 }
 do { futex_get(mem_lock); qm_free(shm_block, (c)); futex_release(mem_lock); }while(0);
}

variable_types: struct cp_conditions_t { struct cp_validity_t { long from; long to; } *validity; struct cp_identity_t { struct _cp_id_t { struct _cp_id_t *next; struct _str { char *s; int len; } entity; } *ids; struct _cp_domain_t { struct _cp_domain_t *next; struct _str domain; } *domains; struct _cp_except_t { struct _cp_except_t *next; struct _str entity; } *excepts; struct cp_any_identity_t { struct _cp_domain_t *domains; struct _cp_except_domain_t { struct _cp_except_domain_t *next; struct _str domain; } *except_domains; } *any_identity; } *identity; struct _cp_sphere_t { struct _cp_sphere_t *next; struct _str value; } *spheres; } *

variable_types: struct _cp_sphere_t { struct _cp_sphere_t *next; struct _str { char *s; int len; } value; } *

user_defined_types: struct cp_conditions_t { struct cp_validity_t *validity; struct cp_identity_t *identity; struct _cp_sphere_t *spheres; }

user_defined_types: struct cp_identity_t { struct _cp_id_t *ids; struct _cp_domain_t *domains; struct _cp_except_t *excepts; struct cp_any_identity_t *any_identity; }

user_defined_types: struct _cp_id_t { struct _cp_id_t *next; struct _str entity; }

user_defined_types: struct cp_any_identity_t { struct _cp_domain_t *domains; struct _cp_except_domain_t *except_domains; }


decompiled_code:
__int64 __fastcall free_transformations(_QWORD **a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // r12
__int64 result; // rax

if ( a1 )
{
v1 = *a1;
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)*v1;
futex_get(mem_lock);
qm_free(shm_block, v2);
futex_release(mem_lock);
}
futex_get(mem_lock);
qm_free(shm_block, a1);
result = futex_release(mem_lock);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD **a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // r12
__int64 result; // rax

if ( a1 )
{
v1 = *a1;
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)*v1;
func2(mem_lock);
qm_free(shm_block, v2);
func3(mem_lock);
}
func2(mem_lock);
qm_free(shm_block, a1);
result = func3(mem_lock);
}
return result;
}

original_code:
static void free_transformations(cp_transformations_t *t)
{
 cp_unknown_t *u, *nu;
 if (!t) return;
 u = t->unknown;
 while (u) {
  nu = u->next;
  do { futex_get(mem_lock); qm_free(shm_block, (u)); futex_release(mem_lock); }while(0);
  u = nu;
 }
 do { futex_get(mem_lock); qm_free(shm_block, (t)); futex_release(mem_lock); }while(0);
}

canonical_original_code:
static void free_transformations(struct cp_transformations_t *t)
{
 struct _cp_unknown_t *u; struct _cp_unknown_t *nu;
 if (!t) return;
 u = t->unknown;
 while (u) {
  nu = u->next;
  do { futex_get(mem_lock); qm_free(shm_block, (u)); futex_release(mem_lock); }while(0);
  u = nu;
 }
 do { futex_get(mem_lock); qm_free(shm_block, (t)); futex_release(mem_lock); }while(0);
}

variable_types: struct cp_transformations_t { struct _cp_unknown_t { struct _cp_unknown_t *next; char data[1]; } *unknown; } *

user_defined_types: struct cp_transformations_t { struct _cp_unknown_t *unknown; }


original_code:
static void parse_uri(const str_t *uri, str_t *user, str_t *domain)
{
 char *a;
 char *d;
 str_t s;
 do { if (user != ((void *)0)) { (user)->len = 0; (user)->s = 0; } } while (0);
 do { if (domain != ((void *)0)) { (domain)->len = 0; (domain)->s = 0; } } while (0);
 if (uri->len > 0) {
  d = str_strchr(uri, ':');
  if (d) {
   s.s = d + 1;
   s.len = uri->len - (s.s - uri->s);
  }
  else s = *uri;
  a = str_strchr(&s, '@');
  if (a) {
   user->s = s.s;
   user->len = a - s.s;
  }
  domain->s = s.s + user->len;
  if (a) domain->s++;
  domain->len = uri->len - (domain->s - uri->s);
 }
}

canonical_original_code:
static void parse_uri(struct _str *uri, struct _str *user, struct _str *domain)
{
 char *a;
 char *d;
 struct _str s;
 do { if (user != ((void *)0)) { (user)->len = 0; (user)->s = 0; } } while (0);
 do { if (domain != ((void *)0)) { (domain)->len = 0; (domain)->s = 0; } } while (0);
 if (uri->len > 0) {
  d = str_strchr(uri, ':');
  if (d) {
   s.s = d + 1;
   s.len = uri->len - (s.s - uri->s);
  }
  else s = *uri;
  a = str_strchr(&s, '@');
  if (a) {
   user->s = s.s;
   user->len = a - s.s;
  }
  domain->s = s.s + user->len;
  if (a) domain->s++;
  domain->len = uri->len - (domain->s - uri->s);
 }
}

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

variable_types:
user
struct _str *

variable_types:
domain
struct _str *

variable_types:
a
char *

variable_types:
d
char *

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


decompiled_code:
__int64 __fastcall free_cp_rule(__int64 a1, void (*a2)(void))
{
_QWORD *v3; // rdi
_QWORD **v4; // rdi
__int64 result; // rax

if ( a1 )
{
v3 = *(_QWORD **)(a1 + 8);
if ( v3 )
free_conditions(v3);
if ( *(_QWORD *)(a1 + 16) )
a2();
v4 = *(_QWORD ***)(a1 + 24);
if ( v4 )
free_transformations(v4);
if ( *(int *)(a1 + 40) > 0 )
{
if ( *(_QWORD *)(a1 + 32) )
{
futex_get(mem_lock);
qm_free(shm_block, *(_QWORD *)(a1 + 32));
futex_release(mem_lock);
}
}
*(_DWORD *)(a1 + 40) = 0;
*(_QWORD *)(a1 + 32) = 0LL;
futex_get(mem_lock);
qm_free(shm_block, a1);
result = futex_release(mem_lock);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, void (*a2)(void))
{
_QWORD *v3; // rdi
_QWORD **v4; // rdi
__int64 result; // rax

if ( a1 )
{
v3 = *(_QWORD **)(a1 + 8);
if ( v3 )
func6(v3);
if ( *(_QWORD *)(a1 + 16) )
a2();
v4 = *(_QWORD ***)(a1 + 24);
if ( v4 )
func7(v4);
if ( *(int *)(a1 + 40) > 0 )
{
if ( *(_QWORD *)(a1 + 32) )
{
func2(mem_lock);
qm_free(shm_block, *(_QWORD *)(a1 + 32));
func3(mem_lock);
}
}
*(_DWORD *)(a1 + 40) = 0;
*(_QWORD *)(a1 + 32) = 0LL;
func2(mem_lock);
qm_free(shm_block, a1);
result = func3(mem_lock);
}
return result;
}

original_code:
void free_cp_rule(cp_rule_t *r, cp_free_actions_func free_actions)
{
 if (!r) return;
 if (r->conditions) free_conditions(r->conditions);
 if (r->actions) free_actions(r->actions);
 if (r->transformations) free_transformations(r->transformations);
 do { if (&r->id != ((void *)0)) { if (((&r->id)->len > 0) && ((&r->id)->s)) do { futex_get(mem_lock); qm_free(shm_block, ((&r->id)->s)); futex_release(mem_lock); }while(0); (&r->id)->len = 0; (&r->id)->s = 0; } } while (0);
 do { futex_get(mem_lock); qm_free(shm_block, (r)); futex_release(mem_lock); }while(0);
}

canonical_original_code:
void free_cp_rule(struct _cp_rule_t *r, void free_actions(struct cp_actions_t *a))
{
 if (!r) return;
 if (r->conditions) free_conditions(r->conditions);
 if (r->actions) free_actions(r->actions);
 if (r->transformations) free_transformations(r->transformations);
 do { if (&r->id != ((void *)0)) { if (((&r->id)->len > 0) && ((&r->id)->s)) do { futex_get(mem_lock); qm_free(shm_block, ((&r->id)->s)); futex_release(mem_lock); }while(0); (&r->id)->len = 0; (&r->id)->s = 0; } } while (0);
 do { futex_get(mem_lock); qm_free(shm_block, (r)); futex_release(mem_lock); }while(0);
}

variable_types: struct _cp_rule_t { struct _cp_rule_t *next; struct cp_conditions_t { struct cp_validity_t { long from; long to; } *validity; struct cp_identity_t { struct _cp_id_t { struct _cp_id_t *next; struct _str { char *s; int len; } entity; } *ids; struct _cp_domain_t { struct _cp_domain_t *next; struct _str domain; } *domains; struct _cp_except_t { struct _cp_except_t *next; struct _str entity; } *excepts; struct cp_any_identity_t { struct _cp_domain_t *domains; struct _cp_except_domain_t { struct _cp_except_domain_t *next; struct _str domain; } *except_domains; } *any_identity; } *identity; struct _cp_sphere_t { struct _cp_sphere_t *next; struct _str value; } *spheres; } *conditions; struct cp_actions_t { struct _cp_unknown_t { struct _cp_unknown_t *next; char data[1]; } *unknown; } *actions; struct cp_transformations_t { struct _cp_unknown_t *unknown; } *transformations; struct _str id; } *

user_defined_types: struct _cp_rule_t { struct _cp_rule_t *next; struct cp_conditions_t *conditions; struct cp_actions_t *actions; struct cp_transformations_t *transformations; struct _str id; }

user_defined_types: struct cp_actions_t { struct _cp_unknown_t *unknown; }


decompiled_code:
__int64 __fastcall free_common_rules(_QWORD **a1, void (*a2)(void))
{
_QWORD *v3; // rbx
__int64 v4; // rdi
__int64 result; // rax

if ( a1 )
{
v3 = *a1;
while ( v3 )
{
v4 = (__int64)v3;
v3 = (_QWORD *)*v3;
free_cp_rule(v4, a2);
}
futex_get(mem_lock);
qm_free(shm_block, a1);
result = futex_release(mem_lock);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD **a1, void (*a2)(void))
{
_QWORD *v3; // rbx
__int64 v4; // rdi
__int64 result; // rax

if ( a1 )
{
v3 = *a1;
while ( v3 )
{
v4 = (__int64)v3;
v3 = (_QWORD *)*v3;
func9(v4, a2);
}
func2(mem_lock);
qm_free(shm_block, a1);
result = func3(mem_lock);
}
return result;
}

original_code:
void free_common_rules(cp_ruleset_t *r, cp_free_actions_func free_actions)
{
 cp_rule_t *rule, *n;
 if (!r) return;
 rule = r->rules;
 while (rule) {
  n = rule->next;
  free_cp_rule(rule, free_actions);
  rule = n;
 }
 do { futex_get(mem_lock); qm_free(shm_block, (r)); futex_release(mem_lock); }while(0);
}

canonical_original_code:
void free_common_rules(struct cp_ruleset_t *r, void free_actions(struct cp_actions_t *a))
{
 struct _cp_rule_t *rule; struct _cp_rule_t *n;
 if (!r) return;
 rule = r->rules;
 while (rule) {
  n = rule->next;
  free_cp_rule(rule, free_actions);
  rule = n;
 }
 do { futex_get(mem_lock); qm_free(shm_block, (r)); futex_release(mem_lock); }while(0);
}

variable_types: struct cp_ruleset_t { struct _cp_rule_t { struct _cp_rule_t *next; struct cp_conditions_t { struct cp_validity_t { long from; long to; } *validity; struct cp_identity_t { struct _cp_id_t { struct _cp_id_t *next; struct _str { char *s; int len; } entity; } *ids; struct _cp_domain_t { struct _cp_domain_t *next; struct _str domain; } *domains; struct _cp_except_t { struct _cp_except_t *next; struct _str entity; } *excepts; struct cp_any_identity_t { struct _cp_domain_t *domains; struct _cp_except_domain_t { struct _cp_except_domain_t *next; struct _str domain; } *except_domains; } *any_identity; } *identity; struct _cp_sphere_t { struct _cp_sphere_t *next; struct _str value; } *spheres; } *conditions; struct cp_actions_t { struct _cp_unknown_t { struct _cp_unknown_t *next; char data[1]; } *unknown; } *actions; struct cp_transformations_t { struct _cp_unknown_t *unknown; } *transformations; struct _str id; } *rules; } *

user_defined_types: struct cp_ruleset_t { struct _cp_rule_t *rules; }


original_code:
int is_rule_for_uri(cp_rule_t *rule, const str_t *uri)
{
 cp_identity_t *id;
 int ok = 0;
 str_t domain, user;
 str_t d_, u_;
 cp_domain_t *d;
 cp_id_t *i;
 cp_except_t *e;
 cp_except_domain_t *ed;
 if (!rule) return 0;
 if (!rule->conditions) return 1;
 id = rule->conditions->identity;
 if (!id) return 0;
 parse_uri(uri, &user, &domain);
 i = id->ids;
 while (i) {
  parse_uri(&i->entity, &u_, &d_);
  if (str_case_equals(&user, &u_) == 0) {
   if (str_nocase_equals(&domain, &d_) == 0) {
    return 1;
   }
  }
  i = i->next;
 }
 d = id->domains;
 while (d) {
  if (str_nocase_equals(&domain, &d->domain) == 0) ok = 1;
  d = d->next;
 }
 if (ok) {
  e = id->excepts;
  while (e) {
   if (str_case_equals(&user, &e->entity) == 0)
    return 0;
   e = e->next;
  }
  return 1;
 }
 if (id->any_identity) {
  d = id->any_identity->domains;
  while (d) {
   if (str_nocase_equals(&domain, &d->domain) == 0) {
    return 1;
   }
   d = d->next;
  }
  ed = id->any_identity->except_domains;
  while (ed) {
   if (str_nocase_equals(&domain, &d->domain) == 0) return 0;
   ed = ed->next;
  }
 }
 return 0;
}

canonical_original_code:
int is_rule_for_uri(struct _cp_rule_t *rule, struct _str *uri)
{
 struct cp_identity_t *id;
 int ok = 0;
 struct _str domain; struct _str user;
 struct _str d_; struct _str u_;
 struct _cp_domain_t *d;
 struct _cp_id_t *i;
 struct _cp_except_t *e;
 struct _cp_except_domain_t *ed;
 if (!rule) return 0;
 if (!rule->conditions) return 1;
 id = rule->conditions->identity;
 if (!id) return 0;
 parse_uri(uri, &user, &domain);
 i = id->ids;
 while (i) {
  parse_uri(&i->entity, &u_, &d_);
  if (str_case_equals(&user, &u_) == 0) {
   if (str_nocase_equals(&domain, &d_) == 0) {
    return 1;
   }
  }
  i = i->next;
 }
 d = id->domains;
 while (d) {
  if (str_nocase_equals(&domain, &d->domain) == 0) ok = 1;
  d = d->next;
 }
 if (ok) {
  e = id->excepts;
  while (e) {
   if (str_case_equals(&user, &e->entity) == 0)
    return 0;
   e = e->next;
  }
  return 1;
 }
 if (id->any_identity) {
  d = id->any_identity->domains;
  while (d) {
   if (str_nocase_equals(&domain, &d->domain) == 0) {
    return 1;
   }
   d = d->next;
  }
  ed = id->any_identity->except_domains;
  while (ed) {
   if (str_nocase_equals(&domain, &d->domain) == 0) return 0;
   ed = ed->next;
  }
 }
 return 0;
}

variable_types:
uri
struct _str *

variable_types: struct cp_identity_t { struct _cp_id_t { struct _cp_id_t *next; struct _str { char *s; int len; } entity; } *ids; struct _cp_domain_t { struct _cp_domain_t *next; struct _str domain; } *domains; struct _cp_except_t { struct _cp_except_t *next; struct _str entity; } *excepts; struct cp_any_identity_t { struct _cp_domain_t *domains; struct _cp_except_domain_t { struct _cp_except_domain_t *next; struct _str domain; } *except_domains; } *any_identity; } *

variable_types: ok int

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

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

variable_types: struct _cp_domain_t { struct _cp_domain_t *next; struct _str { char *s; int len; } domain; } *

variable_types: struct _cp_except_t { struct _cp_except_t *next; struct _str { char *s; int len; } entity; } *

variable_types: struct _cp_except_domain_t { struct _cp_except_domain_t *next; struct _str { char *s; int len; } domain; } *

user_defined_types: struct cp_validity_t { long from; long to; }

user_defined_types: struct _cp_sphere_t { struct _cp_sphere_t *next; struct _str value; }

user_defined_types: struct _cp_unknown_t { struct _cp_unknown_t *next; char data[1]; }