original_code:
int get_socket_list_from_proto_and_family(int **ipList, int protocol, int family) {
 struct socket_info *si;
 struct socket_info** list;
 int num_ip_octets = family == 2 ? 4 : 16;
 int numberOfSockets = 0;
 int currentRow = 0;
 if (protocol == PROTO_SCTP)
 {
  return 0;
 }
 if (protocol == PROTO_WS || protocol == PROTO_WSS)
  return 0;
 list=get_sock_info_list(protocol);
 for(si=list?*list:0; si; si=si->next){
  if (si->address.af == family) {
   numberOfSockets++;
  }
 }
 if (numberOfSockets == 0)
 {
  return 0;
 }
 *ipList = qm_malloc(mem_block, (numberOfSockets * (num_ip_octets + 1) * sizeof(int)));
 if (*ipList == ((void *)0)) {
  do { if (get_debug_level("core", (sizeof("core")-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(): " "no more pkg memory", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "statistics.c" ":" "197" "]: ") , __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(): " "no more pkg memory", (log_level_info[((-1)) - (-5)].name), ("<core> [" "statistics.c" ":" "197" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no more pkg memory", process_no, my_pid(), ("<core> [" "statistics.c" ":" "197" "]: ") , __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(): " "no more pkg memory", ("<core> [" "statistics.c" ":" "197" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no more pkg memory", ("<core> [" "statistics.c" ":" "197" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return 0;
 }
 list=get_sock_info_list(protocol);
 for(si=list?*list:0; si; si=si->next){
  int i;
  if (si->address.af != family) {
   continue;
  }
  for (i = 0; i < num_ip_octets; i++) {
   (*ipList)[currentRow*(num_ip_octets + 1) + i ] =
    si->address.u.addr[i];
  }
  (*ipList)[currentRow*(num_ip_octets + 1) + i] =
   si->port_no;
  currentRow++;
 }
 return numberOfSockets;
}

canonical_original_code:
int get_socket_list_from_proto_and_family(int **ipList, int protocol, int family) {
 struct socket_info *si;
 struct socket_info **list;
 int num_ip_octets = family == 2 ? 4 : 16;
 int numberOfSockets = 0;
 int currentRow = 0;
 if (protocol == PROTO_SCTP)
 {
  return 0;
 }
 if (protocol == PROTO_WS || protocol == PROTO_WSS)
  return 0;
 list=get_sock_info_list(protocol);
 for(si=list?*list:0; si; si=si->next){
  if (si->address.af == family) {
   numberOfSockets++;
  }
 }
 if (numberOfSockets == 0)
 {
  return 0;
 }
 *ipList = qm_malloc(mem_block, (numberOfSockets * (num_ip_octets + 1) * sizeof(int)));
 if (*ipList == ((void *)0)) {
  do { if (get_debug_level("core", (sizeof("core")-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(): " "no more pkg memory", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "statistics.c" ":" "197" "]: ") , __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(): " "no more pkg memory", (log_level_info[((-1)) - (-5)].name), ("<core> [" "statistics.c" ":" "197" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no more pkg memory", process_no, my_pid(), ("<core> [" "statistics.c" ":" "197" "]: ") , __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(): " "no more pkg memory", ("<core> [" "statistics.c" ":" "197" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no more pkg memory", ("<core> [" "statistics.c" ":" "197" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return 0;
 }
 list=get_sock_info_list(protocol);
 for(si=list?*list:0; si; si=si->next){
  int i;
  if (si->address.af != family) {
   continue;
  }
  for (i = 0; i < num_ip_octets; i++) {
   (*ipList)[currentRow*(num_ip_octets + 1) + i ] =
    si->address.u.addr[i];
  }
  (*ipList)[currentRow*(num_ip_octets + 1) + i] =
   si->port_no;
  currentRow++;
 }
 return numberOfSockets;
}

variable_types:
ipList
int **

variable_types: protocol int

variable_types: family int

variable_types: struct socket_info { int socket; struct _str { char *s; int len; } name; struct ip_addr { unsigned int af; unsigned int len; union { unsigned long addrl[-1]; unsigned int addr32[4]; unsigned short addr16[8]; unsigned char addr[16]; } u; } address; struct _str address_str; struct _str port_no_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } s; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } sin6; } su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; } *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info { struct _str name; unsigned short port_no; struct _str port_no_str; struct _str address_str; struct ip_addr address; struct _str sock_str; } useinfo; } **

variable_types: numberOfSockets int

variable_types: currentRow int

user_defined_types: struct socket_info { int socket; struct _str name; struct ip_addr address; struct _str address_str; struct _str port_no_str; enum si_flags flags; union sockaddr_union su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info useinfo; }

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: union sockaddr_union { struct sockaddr s; struct sockaddr_in sin; struct sockaddr_in6 sin6; }

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

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; }


repo: virtualolson/who

decompiled_code:
__int64 __fastcall get_socket_list_from_proto(__int64 *a1, int a2)
{
return get_socket_list_from_proto_and_family(a1, a2, 2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, int a2)
{
return func5(a1, a2, 2);
}

original_code:
int get_socket_list_from_proto(int **ipList, int protocol) {
 return get_socket_list_from_proto_and_family(ipList, protocol, 2);
}

return_type: int


decompiled_code:
__int64 get_total_bytes_waiting()
{
int v0; // er15
int v1; // er13
int v2; // ebp
int v3; // er14
int v4; // er12
int v5; // ebx
int v7; // [rsp+Ch] [rbp-6Ch]
int v8; // [rsp+Ch] [rbp-6Ch]
int v9; // [rsp+Ch] [rbp-6Ch]
int v10; // [rsp+Ch] [rbp-6Ch]
int v11; // [rsp+Ch] [rbp-6Ch]
unsigned int v12; // [rsp+Ch] [rbp-6Ch]
_DWORD *v13; // [rsp+10h] [rbp-68h] BYREF
_DWORD *v14; // [rsp+18h] [rbp-60h] BYREF
_DWORD *v15; // [rsp+20h] [rbp-58h] BYREF
_DWORD *v16; // [rsp+28h] [rbp-50h] BYREF
_DWORD *v17; // [rsp+30h] [rbp-48h] BYREF
__int64 v18[8]; // [rsp+38h] [rbp-40h] BYREF

v18[0] = 0LL;
v17 = 0LL;
v16 = 0LL;
v15 = 0LL;
v14 = 0LL;
v13 = 0LL;
v0 = get_socket_list_from_proto(v18, 1);
v1 = get_socket_list_from_proto((__int64 *)&v17, 2);
v2 = get_socket_list_from_proto((__int64 *)&v16, 3);
v3 = get_socket_list_from_proto_and_family((__int64 *)&v15, 1, 10);
v4 = get_socket_list_from_proto_and_family((__int64 *)&v14, 2, 10);
v5 = get_socket_list_from_proto_and_family((__int64 *)&v13, 3, 10);
v7 = get_used_waiting_queue(0, (_DWORD *)v18[0], v0);
v8 = v7 + get_used_waiting_queue(1, v17, v1);
v9 = v8 + get_used_waiting_queue(1, v16, v2);
v10 = v9 + get_used_waiting_queue(0, v15, v3);
v11 = v10 + get_used_waiting_queue(1, v14, v4);
v12 = v11 + get_used_waiting_queue(1, v13, v5);
if ( v0 > 0 )
qm_free(mem_block, v18[0]);
if ( v3 > 0 )
qm_free(mem_block, v15);
if ( v1 > 0 )
qm_free(mem_block, v17);
if ( v4 > 0 )
qm_free(mem_block, v14);
if ( v2 > 0 )
qm_free(mem_block, v16);
if ( v5 > 0 )
qm_free(mem_block, v13);
return v12;
}

original_code:
int get_total_bytes_waiting(void)
{
 int bytesWaiting = 0;
 int *UDPList = ((void *)0);
 int *TCPList = ((void *)0);
 int *TLSList = ((void *)0);
 int *UDP6List = ((void *)0);
 int *TCP6List = ((void *)0);
 int *TLS6List = ((void *)0);
 int numUDPSockets = 0;
 int numTCPSockets = 0;
 int numTLSSockets = 0;
 int numUDP6Sockets = 0;
 int numTCP6Sockets = 0;
 int numTLS6Sockets = 0;
 numUDPSockets = get_socket_list_from_proto(&UDPList, PROTO_UDP);
 numTCPSockets = get_socket_list_from_proto(&TCPList, PROTO_TCP);
 numTLSSockets = get_socket_list_from_proto(&TLSList, PROTO_TLS);
 numUDP6Sockets = get_socket_list_from_proto_and_family(&UDP6List, PROTO_UDP, 10);
 numTCP6Sockets = get_socket_list_from_proto_and_family(&TCP6List, PROTO_TCP, 10);
 numTLS6Sockets = get_socket_list_from_proto_and_family(&TLS6List, PROTO_TLS, 10);
 bytesWaiting += get_used_waiting_queue(0, UDPList, numUDPSockets);
 bytesWaiting += get_used_waiting_queue(1, TCPList, numTCPSockets);
 bytesWaiting += get_used_waiting_queue(1, TLSList, numTLSSockets);
 bytesWaiting += get_used_waiting_queue(0, UDP6List, numUDP6Sockets);
 bytesWaiting += get_used_waiting_queue(1, TCP6List, numTCP6Sockets);
 bytesWaiting += get_used_waiting_queue(1, TLS6List, numTLS6Sockets);
 if (numUDPSockets > 0)
 {
  qm_free(mem_block, (UDPList));
 }
 if (numUDP6Sockets > 0)
 {
  qm_free(mem_block, (UDP6List));
 }
 if (numTCPSockets > 0)
 {
  qm_free(mem_block, (TCPList));
 }
 if (numTCP6Sockets > 0)
 {
  qm_free(mem_block, (TCP6List));
 }
 if (numTLSSockets > 0)
 {
  qm_free(mem_block, (TLSList));
 }
 if (numTLS6Sockets > 0)
 {
  qm_free(mem_block, (TLS6List));
 }
 return bytesWaiting;
}

canonical_original_code:
int get_total_bytes_waiting()
{
 int bytesWaiting = 0;
 int *UDPList = ((void *)0);
 int *TCPList = ((void *)0);
 int *TLSList = ((void *)0);
 int *UDP6List = ((void *)0);
 int *TCP6List = ((void *)0);
 int *TLS6List = ((void *)0);
 int numUDPSockets = 0;
 int numTCPSockets = 0;
 int numTLSSockets = 0;
 int numUDP6Sockets = 0;
 int numTCP6Sockets = 0;
 int numTLS6Sockets = 0;
 numUDPSockets = get_socket_list_from_proto(&UDPList, PROTO_UDP);
 numTCPSockets = get_socket_list_from_proto(&TCPList, PROTO_TCP);
 numTLSSockets = get_socket_list_from_proto(&TLSList, PROTO_TLS);
 numUDP6Sockets = get_socket_list_from_proto_and_family(&UDP6List, PROTO_UDP, 10);
 numTCP6Sockets = get_socket_list_from_proto_and_family(&TCP6List, PROTO_TCP, 10);
 numTLS6Sockets = get_socket_list_from_proto_and_family(&TLS6List, PROTO_TLS, 10);
 bytesWaiting += get_used_waiting_queue(0, UDPList, numUDPSockets);
 bytesWaiting += get_used_waiting_queue(1, TCPList, numTCPSockets);
 bytesWaiting += get_used_waiting_queue(1, TLSList, numTLSSockets);
 bytesWaiting += get_used_waiting_queue(0, UDP6List, numUDP6Sockets);
 bytesWaiting += get_used_waiting_queue(1, TCP6List, numTCP6Sockets);
 bytesWaiting += get_used_waiting_queue(1, TLS6List, numTLS6Sockets);
 if (numUDPSockets > 0)
 {
  qm_free(mem_block, (UDPList));
 }
 if (numUDP6Sockets > 0)
 {
  qm_free(mem_block, (UDP6List));
 }
 if (numTCPSockets > 0)
 {
  qm_free(mem_block, (TCPList));
 }
 if (numTCP6Sockets > 0)
 {
  qm_free(mem_block, (TCP6List));
 }
 if (numTLSSockets > 0)
 {
  qm_free(mem_block, (TLSList));
 }
 if (numTLS6Sockets > 0)
 {
  qm_free(mem_block, (TLS6List));
 }
 return bytesWaiting;
}

variable_types: bytesWaiting int

variable_types:
UDPList
int *

variable_types:
TCPList
int *

variable_types:
TLSList
int *

variable_types: numUDPSockets int

variable_types: numTCPSockets int

variable_types: numTLSSockets int


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_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 func3(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 func4(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 free_hash_entry(__int64 a1)
{
__int64 result; // rax

if ( a1 )
{
futex_get(mem_lock);
qm_free(shm_block, a1);
result = futex_release(mem_lock);
}
return result;
}

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

if ( a1 )
{
func3(mem_lock);
qm_free(shm_block, a1);
result = func4(mem_lock);
}
return result;
}

original_code:
static void free_hash_entry(struct hash_entry* e)
{
 if (e) do { futex_get(mem_lock); qm_free(shm_block, (e)); futex_release(mem_lock); }while(0);
}

canonical_original_code:
static void free_hash_entry(struct hash_entry *e)
{
 if (e) do { futex_get(mem_lock); qm_free(shm_block, (e)); futex_release(mem_lock); }while(0);
}

variable_types: struct hash_entry { struct _str { char *s; int len; } key; struct domain { struct _str did; int n; struct _str *domain; unsigned int *flags; struct usr_avp { unsigned short id; unsigned int flags; struct usr_avp *next; union usr_avp_data { void *p; long l; char data[-1]; } d; } *attrs; struct domain *next; } *domain; struct hash_entry *next; } *

user_defined_types: struct hash_entry { struct _str key; struct domain *domain; struct hash_entry *next; }

user_defined_types: struct domain { struct _str did; int n; struct _str *domain; unsigned int *flags; struct usr_avp *attrs; struct domain *next; }

user_defined_types: struct usr_avp { unsigned short id; unsigned int flags; struct usr_avp *next; union usr_avp_data d; }


decompiled_code:
__int64 __fastcall gen_domain_table(__int64 *a1, __int64 a2)
{
__int64 v2; // r12
__int64 result; // rax
__int64 v4; // r13
__m128i *v5; // rbx
__int64 *v6; // rcx
int v7; // esi
const char *v8; // r12
unsigned int v9; // eax

if ( a1 )
{
v2 = a2;
result = 0LL;
if ( a2 )
{
while ( 1 )
{
v4 = 0LL;
if ( *(int *)(v2 + 16) > 0 )
break;
LABEL_6:
v2 = *(_QWORD *)(v2 + 48);
if ( !v2 )
return 0LL;
}
while ( 1 )
{
v5 = new_hash_entry((const __m128i *)(*(_QWORD *)(v2 + 24) + 16 * v4), v2);
if ( !v5 )
break;
v6 = &a1[(unsigned int)calc_hash(*(_QWORD *)(v2 + 24) + 16 * v4)];
v5[1].m128i_i64[1] = *v6;
*v6 = (__int64)v5;
if ( *(_DWORD *)(v2 + 16) <= (int)++v4 )
goto LABEL_6;
}
free_table(a1);
result = 0xFFFFFFFFLL;
}
}
else
{
v7 = get_debug_level("uid_domain", 10LL);
result = 0xFFFFFFFFLL;
if ( v7 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v8 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): Invalid parameter value\n",
process_no,
v9,
v8,
"uid_domain [hash.c:116]: ",
"gen_domain_table");
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),
"uid_domain [hash.c:116]: ",
"gen_domain_table");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, __int64 a2)
{
__int64 v2; // r12
__int64 result; // rax
__int64 v4; // r13
__m128i *v5; // rbx
__int64 *v6; // rcx
int v7; // esi
const char *v8; // r12
unsigned int v9; // eax

if ( a1 )
{
v2 = a2;
result = 0LL;
if ( a2 )
{
while ( 1 )
{
v4 = 0LL;
if ( *(int *)(v2 + 16) > 0 )
break;
LABEL_6:
v2 = *(_QWORD *)(v2 + 48);
if ( !v2 )
return 0LL;
}
while ( 1 )
{
v5 = new_hash_entry((const __m128i *)(*(_QWORD *)(v2 + 24) + 16 * v4), v2);
if ( !v5 )
break;
v6 = &a1[(unsigned int)func2(*(_QWORD *)(v2 + 24) + 16 * v4)];
v5[1].m128i_i64[1] = *v6;
*v6 = (__int64)v5;
if ( *(_DWORD *)(v2 + 16) <= (int)++v4 )
goto LABEL_6;
}
func7(a1);
result = 0xFFFFFFFFLL;
}
}
else
{
v7 = get_debug_level("uid_domain", 10LL);
result = 0xFFFFFFFFLL;
if ( v7 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v8 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): Invalid parameter value\n",
process_no,
v9,
v8,
"uid_domain [hash.c:116]: ",
"gen_domain_table");
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),
"uid_domain [hash.c:116]: ",
"gen_domain_table");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int gen_domain_table(struct hash_entry** table, domain_t* list)
{
 struct hash_entry* e;
 unsigned int slot;
 int i;
 if (!table) {
  do { if (get_debug_level("uid_domain", (sizeof("uid_domain")-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), ("uid_domain" " [" "hash.c" ":" "116" "]: ") , __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), ("uid_domain" " [" "hash.c" ":" "116" "]: ") , __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(), ("uid_domain" " [" "hash.c" ":" "116" "]: ") , __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", ("uid_domain" " [" "hash.c" ":" "116" "]: ") , __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", ("uid_domain" " [" "hash.c" ":" "116" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 while(list) {
  for(i = 0; i < list->n; i++) {
   e = new_hash_entry(&list->domain[i], list);
   if (!e) goto error;
   slot = calc_hash(&list->domain[i]);
   e->next = table[slot];
   table[slot] = e;
  }
  list = list->next;
 }
 return 0;
 error:
 free_table(table);
 return -1;
}

canonical_original_code:
int gen_domain_table(struct hash_entry **table, struct domain *list)
{
 struct hash_entry *e;
 unsigned int slot;
 int i;
 if (!table) {
  do { if (get_debug_level("uid_domain", (sizeof("uid_domain")-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), ("uid_domain" " [" "hash.c" ":" "116" "]: ") , __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), ("uid_domain" " [" "hash.c" ":" "116" "]: ") , __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(), ("uid_domain" " [" "hash.c" ":" "116" "]: ") , __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", ("uid_domain" " [" "hash.c" ":" "116" "]: ") , __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", ("uid_domain" " [" "hash.c" ":" "116" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 while(list) {
  for(i = 0; i < list->n; i++) {
   e = new_hash_entry(&list->domain[i], list);
   if (!e) goto error;
   slot = calc_hash(&list->domain[i]);
   e->next = table[slot];
   table[slot] = e;
  }
  list = list->next;
 }
 return 0;
 error:
 free_table(table);
 return -1;
}

variable_types: struct hash_entry { struct _str { char *s; int len; } key; struct domain { struct _str did; int n; struct _str *domain; unsigned int *flags; struct usr_avp { unsigned short id; unsigned int flags; struct usr_avp *next; union usr_avp_data { void *p; long l; char data[-1]; } d; } *attrs; struct domain *next; } *domain; struct hash_entry *next; } **

variable_types:
list
struct domain *

variable_types:
slot
unsigned int


decompiled_code:
__int64 __fastcall gen_did_table(__int64 *a1, const __m128i *a2)
{
const __m128i *v2; // rbx
__int64 result; // rax
__m128i *v4; // rbp
__int64 *v5; // rcx
int v6; // esi
const char *v7; // rbx
unsigned int v8; // eax

if ( a1 )
{
v2 = a2;
result = 0LL;
if ( a2 )
{
while ( 1 )
{
v4 = new_hash_entry(v2, (__int64)v2);
if ( !v4 )
break;
v5 = &a1[(unsigned int)calc_hash((__int64)v2)];
v4[1].m128i_i64[1] = *v5;
*v5 = (__int64)v4;
v2 = (const __m128i *)v2[3].m128i_i64[0];
if ( !v2 )
return 0LL;
}
free_table(a1);
result = 0xFFFFFFFFLL;
}
}
else
{
v6 = get_debug_level("uid_domain", 10LL);
result = 0xFFFFFFFFLL;
if ( v6 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v7 = (const char *)*((_QWORD *)&log_level_info + 8);
v8 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): Invalid parameter value\n",
process_no,
v8,
v7,
"uid_domain [hash.c:148]: ",
"gen_did_table");
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),
"uid_domain [hash.c:148]: ",
"gen_did_table");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, const __m128i *a2)
{
const __m128i *v2; // rbx
__int64 result; // rax
__m128i *v4; // rbp
__int64 *v5; // rcx
int v6; // esi
const char *v7; // rbx
unsigned int v8; // eax

if ( a1 )
{
v2 = a2;
result = 0LL;
if ( a2 )
{
while ( 1 )
{
v4 = new_hash_entry(v2, (__int64)v2);
if ( !v4 )
break;
v5 = &a1[(unsigned int)func2((__int64)v2)];
v4[1].m128i_i64[1] = *v5;
*v5 = (__int64)v4;
v2 = (const __m128i *)v2[3].m128i_i64[0];
if ( !v2 )
return 0LL;
}
func7(a1);
result = 0xFFFFFFFFLL;
}
}
else
{
v6 = get_debug_level("uid_domain", 10LL);
result = 0xFFFFFFFFLL;
if ( v6 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v7 = (const char *)*((_QWORD *)&log_level_info + 8);
v8 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): Invalid parameter value\n",
process_no,
v8,
v7,
"uid_domain [hash.c:148]: ",
"gen_did_table");
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),
"uid_domain [hash.c:148]: ",
"gen_did_table");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int gen_did_table(struct hash_entry** table, domain_t* list)
{
 unsigned int slot;
 struct hash_entry* e;
 if (!table) {
  do { if (get_debug_level("uid_domain", (sizeof("uid_domain")-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), ("uid_domain" " [" "hash.c" ":" "148" "]: ") , __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), ("uid_domain" " [" "hash.c" ":" "148" "]: ") , __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(), ("uid_domain" " [" "hash.c" ":" "148" "]: ") , __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", ("uid_domain" " [" "hash.c" ":" "148" "]: ") , __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", ("uid_domain" " [" "hash.c" ":" "148" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 while(list) {
  e = new_hash_entry(&list->did, list);
  if (!e) goto error;
  slot = calc_hash(&list->did);
  e->next = table[slot];
  table[slot] = e;
  list = list->next;
 }
 return 0;
 error:
 free_table(table);
 return -1;
}

canonical_original_code:
int gen_did_table(struct hash_entry **table, struct domain *list)
{
 unsigned int slot;
 struct hash_entry *e;
 if (!table) {
  do { if (get_debug_level("uid_domain", (sizeof("uid_domain")-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), ("uid_domain" " [" "hash.c" ":" "148" "]: ") , __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), ("uid_domain" " [" "hash.c" ":" "148" "]: ") , __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(), ("uid_domain" " [" "hash.c" ":" "148" "]: ") , __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", ("uid_domain" " [" "hash.c" ":" "148" "]: ") , __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", ("uid_domain" " [" "hash.c" ":" "148" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 while(list) {
  e = new_hash_entry(&list->did, list);
  if (!e) goto error;
  slot = calc_hash(&list->did);
  e->next = table[slot];
  table[slot] = e;
  list = list->next;
 }
 return 0;
 error:
 free_table(table);
 return -1;
}

user_defined_types: union usr_avp_data { void *p; long l; char data[-1]; }


decompiled_code:
__int64 __fastcall hash_lookup(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
int v5; // ebp
__int64 result; // rax

v4 = *(_QWORD *)(a2 + 8LL * (unsigned int)calc_hash(a3));
if ( v4 )
{
v5 = *(_DWORD *)(a3 + 8);
while ( *(_DWORD *)(v4 + 8) != v5 || strncmp(*(const char **)v4, *(const char **)a3, v5) )
{
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
goto LABEL_8;
}
result = 1LL;
if ( a1 )
{
*a1 = *(_QWORD *)(v4 + 16);
result = 1LL;
}
}
else
{
LABEL_8:
result = 0xFFFFFFFFLL;
if ( a1 )
*a1 = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
int v5; // ebp
__int64 result; // rax

v4 = *(_QWORD *)(a2 + 8LL * (unsigned int)func2(a3));
if ( v4 )
{
v5 = *(_DWORD *)(a3 + 8);
while ( *(_DWORD *)(v4 + 8) != v5 || strncmp(*(const char **)v4, *(const char **)a3, v5) )
{
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
goto LABEL_8;
}
result = 1LL;
if ( a1 )
{
*a1 = *(_QWORD *)(v4 + 16);
result = 1LL;
}
}
else
{
LABEL_8:
result = 0xFFFFFFFFLL;
if ( a1 )
*a1 = 0LL;
}
return result;
}

original_code:
int hash_lookup(domain_t** d, struct hash_entry** table, str* key)
{
 struct hash_entry* np;
 for (np = table[calc_hash(key)]; np != ((void *)0); np = np->next) {
  if ((np->key.len == key->len) &&
   (strncmp(np->key.s, key->s, key->len) == 0)) {
   if (d) *d = np->domain;
   return 1;
  }
 }
 if (d) *d = 0;
 return -1;
}

canonical_original_code:
int hash_lookup(struct domain **d, struct hash_entry **table, struct _str *key)
{
 struct hash_entry *np;
 for (np = table[calc_hash(key)]; np != ((void *)0); np = np->next) {
  if ((np->key.len == key->len) &&
   (strncmp(np->key.s, key->s, key->len) == 0)) {
   if (d) *d = np->domain;
   return 1;
  }
 }
 if (d) *d = 0;
 return -1;
}

variable_types: struct domain { struct _str { char *s; int len; } did; int n; struct _str *domain; unsigned int *flags; struct usr_avp { unsigned short id; unsigned int flags; struct usr_avp *next; union usr_avp_data { void *p; long l; char data[-1]; } d; } *attrs; struct domain *next; } **

variable_types: struct hash_entry { struct _str key; struct domain *domain; struct hash_entry *next; } **

variable_types:
key
struct _str *


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


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


decompiled_code:
__int64 __fastcall free_msg_actions(_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 func4(_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:
void free_msg_actions(cp_actions_t *a)
{
 cp_unknown_t *u, *nu;
 if (!a) return;
 u = a->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, (a)); futex_release(mem_lock); }while(0);
}

canonical_original_code:
void free_msg_actions(struct cp_actions_t *a)
{
 struct _cp_unknown_t *u; struct _cp_unknown_t *nu;
 if (!a) return;
 u = a->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, (a)); futex_release(mem_lock); }while(0);
}

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

user_defined_types: struct cp_actions_t { struct _cp_unknown_t *unknown; }


decompiled_code:
__int64 __fastcall get_msg_rules(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rax
const char *v7; // rbx
unsigned int v8; // er12
const char *v10; // r12
unsigned int v11; // eax
const char *v12; // r12
unsigned int v13; // eax
const char *v14; // rbx
unsigned int v15; // eax
unsigned int v16; // [rsp+4h] [rbp-24h] BYREF
__int64 v17[4]; // [rsp+8h] [rbp-20h] BYREF

v17[0] = 0LL;
v16 = 0;
v6 = xcap_uri_for_users_document(1LL, a1, a2, a3);
if ( v6 )
{
v7 = (const char *)v6;
if ( (unsigned int)xcap_query(v6, a3, v17, &v16) )
{
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v12 = (const char *)*((_QWORD *)&log_level_info + 16);
v13 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): XCAP problems for uri '%s'\n",
process_no,
v13,
v12,
"<core> [msg_rules.c:55]: ",
"get_msg_rules",
v7);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): XCAP problems for uri '%s'\n",
*((const char **)&log_level_info + 16),
"<core> [msg_rules.c:55]: ",
"get_msg_rules",
v7);
}
--dprint_crit;
}
if ( v17[0] )
{
futex_get(mem_lock);
qm_free(shm_block, v17[0]);
futex_release(mem_lock);
}
futex_get(mem_lock);
qm_free(shm_block, v7);
futex_release(mem_lock);
v8 = -7;
}
else
{
futex_get(mem_lock);
qm_free(shm_block, v7);
futex_release(mem_lock);
v8 = parse_msg_rules(v17[0], v16, a4);
if ( v8 && (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v14 = (const char *)*((_QWORD *)&log_level_info + 8);
v15 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): Error occured during document parsing!\n",
process_no,
v15,
v14,
"<core> [msg_rules.c:65]: ",
"get_msg_rules");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): Error occured during document parsing!\n",
*((const char **)&log_level_info + 8),
"<core> [msg_rules.c:65]: ",
"get_msg_rules");
}
--dprint_crit;
}
if ( v17[0] )
{
futex_get(mem_lock);
qm_free(shm_block, v17[0]);
futex_release(mem_lock);
}
}
}
else
{
v8 = -7;
if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v10 = (const char *)*((_QWORD *)&log_level_info + 8);
v11 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): can't build XCAP uri\n",
process_no,
v11,
v10,
"<core> [msg_rules.c:49]: ",
"get_msg_rules");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): can't build XCAP uri\n",
*((const char **)&log_level_info + 8),
"<core> [msg_rules.c:49]: ",
"get_msg_rules");
}
--dprint_crit;
v8 = -7;
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rax
const char *v7; // rbx
unsigned int v8; // er12
const char *v10; // r12
unsigned int v11; // eax
const char *v12; // r12
unsigned int v13; // eax
const char *v14; // rbx
unsigned int v15; // eax
unsigned int v16; // [rsp+4h] [rbp-24h] BYREF
__int64 v17[4]; // [rsp+8h] [rbp-20h] BYREF

v17[0] = 0LL;
v16 = 0;
v6 = xcap_uri_for_users_document(1LL, a1, a2, a3);
if ( v6 )
{
v7 = (const char *)v6;
if ( (unsigned int)xcap_query(v6, a3, v17, &v16) )
{
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v12 = (const char *)*((_QWORD *)&log_level_info + 16);
v13 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): XCAP problems for uri '%s'\n",
process_no,
v13,
v12,
"<core> [msg_rules.c:55]: ",
"get_msg_rules",
v7);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): XCAP problems for uri '%s'\n",
*((const char **)&log_level_info + 16),
"<core> [msg_rules.c:55]: ",
"get_msg_rules",
v7);
}
--dprint_crit;
}
if ( v17[0] )
{
func2(mem_lock);
qm_free(shm_block, v17[0]);
func3(mem_lock);
}
func2(mem_lock);
qm_free(shm_block, v7);
func3(mem_lock);
v8 = -7;
}
else
{
func2(mem_lock);
qm_free(shm_block, v7);
func3(mem_lock);
v8 = parse_msg_rules(v17[0], v16, a4);
if ( v8 && (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v14 = (const char *)*((_QWORD *)&log_level_info + 8);
v15 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): Error occured during document parsing!\n",
process_no,
v15,
v14,
"<core> [msg_rules.c:65]: ",
"get_msg_rules");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): Error occured during document parsing!\n",
*((const char **)&log_level_info + 8),
"<core> [msg_rules.c:65]: ",
"get_msg_rules");
}
--dprint_crit;
}
if ( v17[0] )
{
func2(mem_lock);
qm_free(shm_block, v17[0]);
func3(mem_lock);
}
}
}
else
{
v8 = -7;
if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v10 = (const char *)*((_QWORD *)&log_level_info + 8);
v11 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): can't build XCAP uri\n",
process_no,
v11,
v10,
"<core> [msg_rules.c:49]: ",
"get_msg_rules");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): can't build XCAP uri\n",
*((const char **)&log_level_info + 8),
"<core> [msg_rules.c:49]: ",
"get_msg_rules");
}
--dprint_crit;
v8 = -7;
}
}
return v8;
}

original_code:
int get_msg_rules(const str_t *username, const str_t *filename,
  xcap_query_params_t *xcap_params, msg_rules_t **dst)
{
 char *data = ((void *)0);
 int dsize = 0;
 char *uri = ((void *)0);
 int res = 0;
 uri = xcap_uri_for_users_document(xcap_doc_im_rules,
    username, filename,
    xcap_params);
 if (!uri) {
  do { if (get_debug_level("core", (sizeof("core")-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(): " "can't build XCAP uri\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "49" "]: ") , __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(): " "can't build XCAP uri\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "49" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "can't build XCAP uri\n", process_no, my_pid(), ("<core> [" "msg_rules.c" ":" "49" "]: ") , __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(): " "can't build XCAP uri\n", ("<core> [" "msg_rules.c" ":" "49" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't build XCAP uri\n", ("<core> [" "msg_rules.c" ":" "49" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return (-7);
 }
 res = xcap_query(uri, xcap_params, &data, &dsize);
 if (res != 0) {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "XCAP problems for uri \'%s\'\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "55" "]: ") , __func__, uri); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "XCAP problems for uri \'%s\'\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "55" "]: ") , __func__, uri); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "XCAP problems for uri \'%s\'\n", process_no, my_pid(), ("<core> [" "msg_rules.c" ":" "55" "]: ") , __func__, uri); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "XCAP problems for uri \'%s\'\n", ("<core> [" "msg_rules.c" ":" "55" "]: ") , __func__, uri); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "XCAP problems for uri \'%s\'\n", ("<core> [" "msg_rules.c" ":" "55" "]: ") , __func__, uri); } } (dprint_crit--); } } while(0);
  if (data) do { futex_get(mem_lock); qm_free(shm_block, (data)); futex_release(mem_lock); }while(0);
  do { futex_get(mem_lock); qm_free(shm_block, (uri)); futex_release(mem_lock); }while(0);
  return (-7);
 }
 do { futex_get(mem_lock); qm_free(shm_block, (uri)); futex_release(mem_lock); }while(0);
 res = parse_msg_rules(data, dsize, dst);
 if (res != 0) {
  do { if (get_debug_level("core", (sizeof("core")-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(): " "Error occured during document parsing!\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "65" "]: ") , __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(): " "Error occured during document parsing!\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "65" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "Error occured during document parsing!\n", process_no, my_pid(), ("<core> [" "msg_rules.c" ":" "65" "]: ") , __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(): " "Error occured during document parsing!\n", ("<core> [" "msg_rules.c" ":" "65" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Error occured during document parsing!\n", ("<core> [" "msg_rules.c" ":" "65" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 }
 if (data) do { futex_get(mem_lock); qm_free(shm_block, (data)); futex_release(mem_lock); }while(0);
 return res;
}

canonical_original_code:
int get_msg_rules(struct _str *username, struct _str *filename, struct xcap_query_params_t *xcap_params, struct cp_ruleset_t **dst)
{
 char *data = ((void *)0);
 int dsize = 0;
 char *uri = ((void *)0);
 int res = 0;
 uri = xcap_uri_for_users_document(xcap_doc_im_rules,
    username, filename,
    xcap_params);
 if (!uri) {
  do { if (get_debug_level("core", (sizeof("core")-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(): " "can't build XCAP uri\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "49" "]: ") , __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(): " "can't build XCAP uri\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "49" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "can't build XCAP uri\n", process_no, my_pid(), ("<core> [" "msg_rules.c" ":" "49" "]: ") , __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(): " "can't build XCAP uri\n", ("<core> [" "msg_rules.c" ":" "49" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't build XCAP uri\n", ("<core> [" "msg_rules.c" ":" "49" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return (-7);
 }
 res = xcap_query(uri, xcap_params, &data, &dsize);
 if (res != 0) {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "XCAP problems for uri \'%s\'\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "55" "]: ") , __func__, uri); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "XCAP problems for uri \'%s\'\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "55" "]: ") , __func__, uri); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "XCAP problems for uri \'%s\'\n", process_no, my_pid(), ("<core> [" "msg_rules.c" ":" "55" "]: ") , __func__, uri); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "XCAP problems for uri \'%s\'\n", ("<core> [" "msg_rules.c" ":" "55" "]: ") , __func__, uri); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "XCAP problems for uri \'%s\'\n", ("<core> [" "msg_rules.c" ":" "55" "]: ") , __func__, uri); } } (dprint_crit--); } } while(0);
  if (data) do { futex_get(mem_lock); qm_free(shm_block, (data)); futex_release(mem_lock); }while(0);
  do { futex_get(mem_lock); qm_free(shm_block, (uri)); futex_release(mem_lock); }while(0);
  return (-7);
 }
 do { futex_get(mem_lock); qm_free(shm_block, (uri)); futex_release(mem_lock); }while(0);
 res = parse_msg_rules(data, dsize, dst);
 if (res != 0) {
  do { if (get_debug_level("core", (sizeof("core")-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(): " "Error occured during document parsing!\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "65" "]: ") , __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(): " "Error occured during document parsing!\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "65" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "Error occured during document parsing!\n", process_no, my_pid(), ("<core> [" "msg_rules.c" ":" "65" "]: ") , __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(): " "Error occured during document parsing!\n", ("<core> [" "msg_rules.c" ":" "65" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Error occured during document parsing!\n", ("<core> [" "msg_rules.c" ":" "65" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 }
 if (data) do { futex_get(mem_lock); qm_free(shm_block, (data)); futex_release(mem_lock); }while(0);
 return res;
}

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

variable_types:
filename
struct _str *

variable_types: struct xcap_query_params_t { struct _str xcap_root; struct _str auth_user; struct _str auth_pass; int enable_unverified_ssl_peer; } *

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

variable_types:
data
char *

variable_types: dsize int

variable_types:
uri
char *

variable_types: res int

user_defined_types: struct cp_ruleset_t { struct _cp_rule_t *rules; }

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_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_any_identity_t { struct _cp_domain_t *domains; struct _cp_except_domain_t *except_domains; }


decompiled_code:
__int64 __fastcall get_msg_rules_action(__int64 **a1, __int64 a2, unsigned int *a3)
{
__int64 *v4; // rbx
unsigned int v5; // er14
unsigned int v6; // er12
const char *v7; // rcx
const char *v8; // r8
unsigned int v9; // eax
const char *v10; // rcx
void *v11; // rdx
const char *v12; // rcx
void *v13; // rdx
__int64 v14; // rdx
const char *v15; // rcx
const char *v16; // r8
unsigned int v17; // eax
int v19; // [rsp+0h] [rbp-58h]
int v20; // [rsp+0h] [rbp-58h]
int v21; // [rsp+4h] [rbp-54h]
int v22; // [rsp+4h] [rbp-54h]
const char *v23; // [rsp+8h] [rbp-50h]
const char *v24; // [rsp+8h] [rbp-50h]
const char *v25; // [rsp+10h] [rbp-48h]
const char *v26; // [rsp+10h] [rbp-48h]
const char *v27; // [rsp+18h] [rbp-40h]
const char *v28; // [rsp+18h] [rbp-40h]

if ( !a1 )
return (unsigned int)-1;
v4 = *a1;
if ( !*a1 )
return 1;
v5 = 1;
v6 = 0;
do
{
while ( 1 )
{
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v7 = *(const char **)a2;
if ( !*(_QWORD *)a2 )
v7 = (const char *)&LC10;
v25 = v7;
v19 = *(_DWORD *)(a2 + 8);
v8 = (const char *)v4[4];
if ( !v8 )
v8 = (const char *)&LC10;
v27 = v8;
v21 = *((_DWORD *)v4 + 10);
v23 = (const char *)*((_QWORD *)&log_level_info + 16);
v9 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): TRYING rule %.*s for uri %.*s\n",
process_no,
v9,
v23,
"<core> [msg_rules.c:84]: ",
"get_msg_rules_action",
v21,
v27,
v19,
v25);
if ( log_color )
dprint_color_reset();
}
else
{
v10 = *(const char **)a2;
if ( !*(_QWORD *)a2 )
v10 = (const char *)&LC10;
v11 = (void *)v4[4];
if ( !v11 )
v11 = &LC10;
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): TRYING rule %.*s for uri %.*s\n",
*((_QWORD *)&log_level_info + 16),
"<core> [msg_rules.c:84]: ",
"get_msg_rules_action",
*((unsigned int *)v4 + 10),
v11,
*(unsigned int *)(a2 + 8),
v10);
}
--dprint_crit;
}
if ( !(unsigned int)is_rule_for_uri(v4, a2) )
break;
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v15 = *(const char **)a2;
if ( !*(_QWORD *)a2 )
v15 = (const char *)&LC10;
v26 = v15;
v20 = *(_DWORD *)(a2 + 8);
v16 = (const char *)v4[4];
if ( !v16 )
v16 = (const char *)&LC10;
v28 = v16;
v22 = *((_DWORD *)v4 + 10);
v24 = (const char *)*((_QWORD *)&log_level_info + 16);
v17 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): rule %.*s matches for uri %.*s\n",
process_no,
v17,
v24,
"<core> [msg_rules.c:87]: ",
"get_msg_rules_action",
v22,
v28,
v20,
v26);
if ( log_color )
dprint_color_reset();
}
else
{
v12 = *(const char **)a2;
if ( !*(_QWORD *)a2 )
v12 = (const char *)&LC10;
v13 = (void *)v4[4];
if ( !v13 )
v13 = &LC10;
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): rule %.*s matches for uri %.*s\n",
*((_QWORD *)&log_level_info + 16),
"<core> [msg_rules.c:87]: ",
"get_msg_rules_action",
*((unsigned int *)v4 + 10),
v13,
*(unsigned int *)(a2 + 8),
v12);
}
--dprint_crit;
}
v14 = v4[2];
if ( v14 && *(_QWORD *)v14 )
{
if ( v6 < *(_DWORD *)(*(_QWORD *)v14 + 8LL) )
v6 = *(_DWORD *)(*(_QWORD *)v14 + 8LL);
v5 = 0;
break;
}
}
v4 = (__int64 *)*v4;
}
while ( v4 );
if ( a3 && !v5 )
*a3 = v6;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 **a1, __int64 a2, unsigned int *a3)
{
__int64 *v4; // rbx
unsigned int v5; // er14
unsigned int v6; // er12
const char *v7; // rcx
const char *v8; // r8
unsigned int v9; // eax
const char *v10; // rcx
void *v11; // rdx
const char *v12; // rcx
void *v13; // rdx
__int64 v14; // rdx
const char *v15; // rcx
const char *v16; // r8
unsigned int v17; // eax
int v19; // [rsp+0h] [rbp-58h]
int v20; // [rsp+0h] [rbp-58h]
int v21; // [rsp+4h] [rbp-54h]
int v22; // [rsp+4h] [rbp-54h]
const char *v23; // [rsp+8h] [rbp-50h]
const char *v24; // [rsp+8h] [rbp-50h]
const char *v25; // [rsp+10h] [rbp-48h]
const char *v26; // [rsp+10h] [rbp-48h]
const char *v27; // [rsp+18h] [rbp-40h]
const char *v28; // [rsp+18h] [rbp-40h]

if ( !a1 )
return (unsigned int)-1;
v4 = *a1;
if ( !*a1 )
return 1;
v5 = 1;
v6 = 0;
do
{
while ( 1 )
{
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v7 = *(const char **)a2;
if ( !*(_QWORD *)a2 )
v7 = (const char *)&LC10;
v25 = v7;
v19 = *(_DWORD *)(a2 + 8);
v8 = (const char *)v4[4];
if ( !v8 )
v8 = (const char *)&LC10;
v27 = v8;
v21 = *((_DWORD *)v4 + 10);
v23 = (const char *)*((_QWORD *)&log_level_info + 16);
v9 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): TRYING rule %.*s for uri %.*s\n",
process_no,
v9,
v23,
"<core> [msg_rules.c:84]: ",
"get_msg_rules_action",
v21,
v27,
v19,
v25);
if ( log_color )
dprint_color_reset();
}
else
{
v10 = *(const char **)a2;
if ( !*(_QWORD *)a2 )
v10 = (const char *)&LC10;
v11 = (void *)v4[4];
if ( !v11 )
v11 = &LC10;
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): TRYING rule %.*s for uri %.*s\n",
*((_QWORD *)&log_level_info + 16),
"<core> [msg_rules.c:84]: ",
"get_msg_rules_action",
*((unsigned int *)v4 + 10),
v11,
*(unsigned int *)(a2 + 8),
v10);
}
--dprint_crit;
}
if ( !(unsigned int)is_rule_for_uri(v4, a2) )
break;
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v15 = *(const char **)a2;
if ( !*(_QWORD *)a2 )
v15 = (const char *)&LC10;
v26 = v15;
v20 = *(_DWORD *)(a2 + 8);
v16 = (const char *)v4[4];
if ( !v16 )
v16 = (const char *)&LC10;
v28 = v16;
v22 = *((_DWORD *)v4 + 10);
v24 = (const char *)*((_QWORD *)&log_level_info + 16);
v17 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): rule %.*s matches for uri %.*s\n",
process_no,
v17,
v24,
"<core> [msg_rules.c:87]: ",
"get_msg_rules_action",
v22,
v28,
v20,
v26);
if ( log_color )
dprint_color_reset();
}
else
{
v12 = *(const char **)a2;
if ( !*(_QWORD *)a2 )
v12 = (const char *)&LC10;
v13 = (void *)v4[4];
if ( !v13 )
v13 = &LC10;
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): rule %.*s matches for uri %.*s\n",
*((_QWORD *)&log_level_info + 16),
"<core> [msg_rules.c:87]: ",
"get_msg_rules_action",
*((unsigned int *)v4 + 10),
v13,
*(unsigned int *)(a2 + 8),
v12);
}
--dprint_crit;
}
v14 = v4[2];
if ( v14 && *(_QWORD *)v14 )
{
if ( v6 < *(_DWORD *)(*(_QWORD *)v14 + 8LL) )
v6 = *(_DWORD *)(*(_QWORD *)v14 + 8LL);
v5 = 0;
break;
}
}
v4 = (__int64 *)*v4;
}
while ( v4 );
if ( a3 && !v5 )
*a3 = v6;
return v5;
}

original_code:
int get_msg_rules_action(cp_ruleset_t *r, const str_t *wuri,
  msg_handling_t *dst_action)
{
 int res = 1;
 cp_rule_t *rule;
 msg_handling_t a = msg_handling_block;
 msg_handling_t aa;
 if (!r) return -1;
 rule = r->rules;
 while (rule) {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "TRYING rule %.*s for uri %.*s\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "TRYING rule %.*s for uri %.*s\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "TRYING rule %.*s for uri %.*s\n", process_no, my_pid(), ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "TRYING rule %.*s for uri %.*s\n", ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "TRYING rule %.*s for uri %.*s\n", ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); } } (dprint_crit--); } } while(0);
  if (is_rule_for_uri(rule, wuri)) {
   do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "rule %.*s matches for uri %.*s\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "rule %.*s matches for uri %.*s\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "rule %.*s matches for uri %.*s\n", process_no, my_pid(), ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "rule %.*s matches for uri %.*s\n", ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "rule %.*s matches for uri %.*s\n", ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); } } (dprint_crit--); } } while(0);
   if (!rule->actions) continue;
   if (!rule->actions->unknown) continue;
   aa = *(msg_handling_t*)(rule->actions->unknown->data);
   if (aa > a) a = aa;
   res = 0;
  }
  rule = rule->next;
 }
 if (dst_action && (res == 0)) *dst_action = a;
 return res;
}

canonical_original_code:
int get_msg_rules_action(struct cp_ruleset_t *r, struct _str *wuri, enum msg_handling_t *dst_action)
{
 int res = 1;
 struct _cp_rule_t *rule;
 enum msg_handling_t a = msg_handling_block;
 enum msg_handling_t aa;
 if (!r) return -1;
 rule = r->rules;
 while (rule) {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "TRYING rule %.*s for uri %.*s\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "TRYING rule %.*s for uri %.*s\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "TRYING rule %.*s for uri %.*s\n", process_no, my_pid(), ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "TRYING rule %.*s for uri %.*s\n", ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "TRYING rule %.*s for uri %.*s\n", ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); } } (dprint_crit--); } } while(0);
  if (is_rule_for_uri(rule, wuri)) {
   do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "rule %.*s matches for uri %.*s\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "rule %.*s matches for uri %.*s\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "rule %.*s matches for uri %.*s\n", process_no, my_pid(), ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "rule %.*s matches for uri %.*s\n", ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "rule %.*s matches for uri %.*s\n", ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); } } (dprint_crit--); } } while(0);
   if (!rule->actions) continue;
   if (!rule->actions->unknown) continue;
   aa = *(enum msg_handling_t *)(rule->actions->unknown->data);
   if (aa > a) a = aa;
   res = 0;
  }
  rule = rule->next;
 }
 if (dst_action && (res == 0)) *dst_action = a;
 return res;
}

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

variable_types:
wuri
struct _str *

variable_types: enum msg_handling_t { msg_handling_block=0, msg_handling_allow=1 } *

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


decompiled_code:
__int64 __fastcall free_msg_rules(__int64 a1)
{
return free_common_rules(a1, free_msg_actions);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return free_common_rules(a1, free_msg_actions);
}

original_code:
void free_msg_rules(cp_ruleset_t *r)
{
 free_common_rules(r, free_msg_actions);
}

canonical_original_code:
void free_msg_rules(struct cp_ruleset_t *r)
{
 free_common_rules(r, free_msg_actions);
}

user_defined_types: struct cp_transformations_t { struct _cp_unknown_t *unknown; }

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

user_defined_types: struct _cp_domain_t { struct _cp_domain_t *next; struct _str domain; }

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

user_defined_types: struct _cp_except_domain_t { struct _cp_except_domain_t *next; struct _str domain; }


decompiled_code:
__int64 __fastcall get_from_user(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = *(_QWORD *)(a1 + 64);
if ( !v2 )
return 0xFFFFFFFFLL;
if ( !*(_DWORD *)(a1 + 72) )
return 0xFFFFFFFFLL;
*(_QWORD *)a2 = v2;
*(_DWORD *)(a2 + 8) = *(_DWORD *)(a1 + 72);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = *(_QWORD *)(a1 + 64);
if ( !v2 )
return 0xFFFFFFFFLL;
if ( !*(_DWORD *)(a1 + 72) )
return 0xFFFFFFFFLL;
*(_QWORD *)a2 = v2;
*(_DWORD *)(a2 + 8) = *(_DWORD *)(a1 + 72);
return 0LL;
}

original_code:
static int get_from_user (struct _sipcapture_object * sco, str *source_string) {
 if (!sco->from_user.s || !sco->from_user.len)
 {
  return -1;
 }
 source_string->s = sco->from_user.s;
 source_string->len = sco->from_user.len;
 return 0;
}

canonical_original_code:
static int get_from_user(struct _sipcapture_object *sco, struct _str *source_string) {
 if (!sco->from_user.s || !sco->from_user.len)
 {
  return -1;
 }
 source_string->s = sco->from_user.s;
 source_string->len = sco->from_user.len;
 return 0;
}

variable_types: struct _sipcapture_object { struct _str { char *s; int len; } method; struct _str reply_reason; struct _str ruri; struct _str ruri_user; struct _str from_user; struct _str from_tag; struct _str to_user; struct _str to_tag; struct _str pid_user; struct _str contact_user; struct _str auth_user; struct _str callid; struct _str callid_aleg; struct _str via_1; struct _str via_1_branch; struct _str cseq; struct _str diversion; struct _str reason; struct _str content_type; struct _str authorization; struct _str user_agent; struct _str source_ip; int source_port; struct _str destination_ip; int destination_port; struct _str contact_ip; int contact_port; struct _str originator_ip; int originator_port; int proto; int family; struct _str rtp_stat; int type; long long tmstamp; struct _str node; struct _str msg; void *stat; } *

user_defined_types: struct _sipcapture_object { struct _str method; struct _str reply_reason; struct _str ruri; struct _str ruri_user; struct _str from_user; struct _str from_tag; struct _str to_user; struct _str to_tag; struct _str pid_user; struct _str contact_user; struct _str auth_user; struct _str callid; struct _str callid_aleg; struct _str via_1; struct _str via_1_branch; struct _str cseq; struct _str diversion; struct _str reason; struct _str content_type; struct _str authorization; struct _str user_agent; struct _str source_ip; int source_port; struct _str destination_ip; int destination_port; struct _str contact_ip; int contact_port; struct _str originator_ip; int originator_port; int proto; int family; struct _str rtp_stat; int type; long long tmstamp; struct _str node; struct _str msg; void *stat; }


decompiled_code:
__int64 __fastcall get_to_user(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = *(_QWORD *)(a1 + 96);
if ( !v2 )
return 0xFFFFFFFFLL;
if ( !*(_DWORD *)(a1 + 104) )
return 0xFFFFFFFFLL;
*(_QWORD *)a2 = v2;
*(_DWORD *)(a2 + 8) = *(_DWORD *)(a1 + 104);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = *(_QWORD *)(a1 + 96);
if ( !v2 )
return 0xFFFFFFFFLL;
if ( !*(_DWORD *)(a1 + 104) )
return 0xFFFFFFFFLL;
*(_QWORD *)a2 = v2;
*(_DWORD *)(a2 + 8) = *(_DWORD *)(a1 + 104);
return 0LL;
}

original_code:
static int get_to_user (struct _sipcapture_object * sco, str *source_string) {
 if (!sco->to_user.s || !sco->to_user.len)
 {
  return -1;
 }
 source_string->s = sco->to_user.s;
 source_string->len = sco->to_user.len;
 return 0;
}

canonical_original_code:
static int get_to_user(struct _sipcapture_object *sco, struct _str *source_string) {
 if (!sco->to_user.s || !sco->to_user.len)
 {
  return -1;
 }
 source_string->s = sco->to_user.s;
 source_string->len = sco->to_user.len;
 return 0;
}


decompiled_code:
__int64 __fastcall get_call_id(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = *(_QWORD *)(a1 + 176);
if ( !v2 )
return 0xFFFFFFFFLL;
if ( !*(_DWORD *)(a1 + 184) )
return 0xFFFFFFFFLL;
*(_QWORD *)a2 = v2;
*(_DWORD *)(a2 + 8) = *(_DWORD *)(a1 + 184);
first_token((char **)a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = *(_QWORD *)(a1 + 176);
if ( !v2 )
return 0xFFFFFFFFLL;
if ( !*(_DWORD *)(a1 + 184) )
return 0xFFFFFFFFLL;
*(_QWORD *)a2 = v2;
*(_DWORD *)(a2 + 8) = *(_DWORD *)(a1 + 184);
func2((char **)a2);
return 0LL;
}

original_code:
static int get_call_id (struct _sipcapture_object * sco, str *source_string) {
 if (!sco->callid.s || !sco->callid.len)
 {
  return -1;
 }
 source_string->s = sco->callid.s;
 source_string->len = sco->callid.len;
 first_token (source_string);
 return 0;
}

canonical_original_code:
static int get_call_id(struct _sipcapture_object *sco, struct _str *source_string) {
 if (!sco->callid.s || !sco->callid.len)
 {
  return -1;
 }
 source_string->s = sco->callid.s;
 source_string->len = sco->callid.len;
 first_token (source_string);
 return 0;
}


decompiled_code:
__int64 __fastcall get_source(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax
const char *v4; // rbp
unsigned int v5; // eax

*(_QWORD *)a3 = 0LL;
*(_DWORD *)(a3 + 8) = 0;
switch ( a2 )
{
case 2u:
return get_from_user(a1, a3);
case 3u:
return get_to_user(a1, a3);
case 1u:
return get_call_id(a1, a3);
}
if ( (int)get_debug_level("sipcapture", 10LL) < -1 )
return 0xFFFFFFFFLL;
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++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(): unknown hash source %i.\n",
process_no,
v5,
v4,
"sipcapture [hash_mode.c:49]: ",
"get_source",
a2);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): unknown hash source %i.\n",
*((const char **)&log_level_info + 8),
"sipcapture [hash_mode.c:49]: ",
"get_source",
a2);
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax
const char *v4; // rbp
unsigned int v5; // eax

*(_QWORD *)a3 = 0LL;
*(_DWORD *)(a3 + 8) = 0;
switch ( a2 )
{
case 2u:
return func0(a1, a3);
case 3u:
return func1(a1, a3);
case 1u:
return func3(a1, a3);
}
if ( (int)get_debug_level("sipcapture", 10LL) < -1 )
return 0xFFFFFFFFLL;
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++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(): unknown hash source %i.\n",
process_no,
v5,
v4,
"sipcapture [hash_mode.c:49]: ",
"get_source",
a2);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): unknown hash source %i.\n",
*((const char **)&log_level_info + 8),
"sipcapture [hash_mode.c:49]: ",
"get_source",
a2);
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int get_source (struct _sipcapture_object *sco, enum hash_source source,
                             str *source_string) {
 source_string->s = ((void *)0);
 source_string->len = 0;
 switch (source) {
   case hs_call_id:
   return get_call_id (sco, source_string);
   case hs_from_user:
   return get_from_user(sco, source_string);
   case hs_to_user:
   return get_to_user(sco, source_string);
   default:
   do { if (get_debug_level("sipcapture", (sizeof("sipcapture")-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(): " "unknown hash source %i.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("sipcapture" " [" "hash_mode.c" ":" "49" "]: ") , __func__, (int) source); 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(): " "unknown hash source %i.\n", (log_level_info[((-1)) - (-5)].name), ("sipcapture" " [" "hash_mode.c" ":" "49" "]: ") , __func__, (int) source); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "unknown hash source %i.\n", process_no, my_pid(), ("sipcapture" " [" "hash_mode.c" ":" "49" "]: ") , __func__, (int) source); 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(): " "unknown hash source %i.\n", ("sipcapture" " [" "hash_mode.c" ":" "49" "]: ") , __func__, (int) source); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "unknown hash source %i.\n", ("sipcapture" " [" "hash_mode.c" ":" "49" "]: ") , __func__, (int) source); } } (dprint_crit--); } } while(0);
   return -1;
 }
}

canonical_original_code:
static int get_source(struct _sipcapture_object *sco, enum hash_source source, struct _str *source_string) {
 source_string->s = ((void *)0);
 source_string->len = 0;
 switch (source) {
   case hs_call_id:
   return get_call_id (sco, source_string);
   case hs_from_user:
   return get_from_user(sco, source_string);
   case hs_to_user:
   return get_to_user(sco, source_string);
   default:
   do { if (get_debug_level("sipcapture", (sizeof("sipcapture")-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(): " "unknown hash source %i.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("sipcapture" " [" "hash_mode.c" ":" "49" "]: ") , __func__, (int) source); 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(): " "unknown hash source %i.\n", (log_level_info[((-1)) - (-5)].name), ("sipcapture" " [" "hash_mode.c" ":" "49" "]: ") , __func__, (int) source); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "unknown hash source %i.\n", process_no, my_pid(), ("sipcapture" " [" "hash_mode.c" ":" "49" "]: ") , __func__, (int) source); 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(): " "unknown hash source %i.\n", ("sipcapture" " [" "hash_mode.c" ":" "49" "]: ") , __func__, (int) source); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "unknown hash source %i.\n", ("sipcapture" " [" "hash_mode.c" ":" "49" "]: ") , __func__, (int) source); } } (dprint_crit--); } } while(0);
   return -1;
 }
}

variable_types: enum hash_source { hs_call_id=1, hs_from_user=2, hs_to_user=3, hs_error=4 }

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 get_hash_source(char *s2)
{
int v1; // edx
__int64 result; // rax
int v3; // ecx

v1 = strcasecmp("call_id", s2);
result = 1LL;
if ( v1 )
{
v3 = strcasecmp("from_user", s2);
result = 2LL;
if ( v3 )
result = 3 - ((unsigned int)(strcasecmp("to_user", s2) == 0) - 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s2)
{
int v1; // edx
__int64 result; // rax
int v3; // ecx

v1 = strcasecmp("call_id", s2);
result = 1LL;
if ( v1 )
{
v3 = strcasecmp("from_user", s2);
result = 2LL;
if ( v3 )
result = 3 - ((unsigned int)(strcasecmp("to_user", s2) == 0) - 1);
}
return result;
}

original_code:
enum hash_source get_hash_source (const char *hash_source){
 if (strcasecmp ("call_id", hash_source) == 0){
  return hs_call_id;
 }
 else if (strcasecmp("from_user", hash_source) == 0)
 {
  return hs_from_user;
 }
 else if (strcasecmp("to_user", hash_source) == 0)
 {
  return hs_to_user;
 }
 else {
  return hs_error;
 }
}

canonical_original_code:
enum hash_source get_hash_source(char *hash_source){
 if (strcasecmp ("call_id", hash_source) == 0){
  return hs_call_id;
 }
 else if (strcasecmp("from_user", hash_source) == 0)
 {
  return hs_from_user;
 }
 else if (strcasecmp("to_user", hash_source) == 0)
 {
  return hs_to_user;
 }
 else {
  return hs_error;
 }
}

return_type: enum hash_source { hs_call_id=1, hs_from_user=2, hs_to_user=3, hs_error=4 }


decompiled_code:
__int64 __fastcall hash_func(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // edx
const char *v6; // r13
unsigned int v7; // er12
const char *v8; // rbp
unsigned int v9; // eax
const char *v10; // [rsp+0h] [rbp-48h] BYREF
unsigned int v11; // [rsp+8h] [rbp-40h]
unsigned int v12[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v4 = get_source(a1, a2, (__int64)&v10);
if ( v4 != -1 )
{
if ( (int)get_debug_level("sipcapture", 10LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v6 = v10;
v7 = v11;
v8 = (const char *)*((_QWORD *)&log_level_info + 16);
v9 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): source string: [%.*s]\n",
process_no,
v9,
v8,
"sipcapture [hash_mode.c:29]: ",
"hash_func",
v7,
v6);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): source string: [%.*s]\n",
*((_QWORD *)&log_level_info + 16),
"sipcapture [hash_mode.c:29]: ",
"hash_func",
v11,
v10);
}
--dprint_crit;
}
crc32_uint(&v10, v12);
v4 = v12[0] % a3;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // edx
const char *v6; // r13
unsigned int v7; // er12
const char *v8; // rbp
unsigned int v9; // eax
const char *v10; // [rsp+0h] [rbp-48h] BYREF
unsigned int v11; // [rsp+8h] [rbp-40h]
unsigned int v12[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v4 = func4(a1, a2, (__int64)&v10);
if ( v4 != -1 )
{
if ( (int)get_debug_level("sipcapture", 10LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v6 = v10;
v7 = v11;
v8 = (const char *)*((_QWORD *)&log_level_info + 16);
v9 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): source string: [%.*s]\n",
process_no,
v9,
v8,
"sipcapture [hash_mode.c:29]: ",
"hash_func",
v7,
v6);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): source string: [%.*s]\n",
*((_QWORD *)&log_level_info + 16),
"sipcapture [hash_mode.c:29]: ",
"hash_func",
v11,
v10);
}
--dprint_crit;
}
crc32_uint(&v10, v12);
v4 = v12[0] % a3;
}
return v4;
}

original_code:
int hash_func (struct _sipcapture_object * sco,
                         enum hash_source source, int denominator) {
 int ret;
 unsigned int hash;
 str source_string;
 if(get_source (sco, source, &source_string) == -1) {
  return -1;
 }
 do { if (get_debug_level("sipcapture", (sizeof("sipcapture")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "source string: [%.*s]\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("sipcapture" " [" "hash_mode.c" ":" "29" "]: ") , __func__, source_string.len, source_string.s); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "source string: [%.*s]\n", (log_level_info[((3)) - (-5)].name), ("sipcapture" " [" "hash_mode.c" ":" "29" "]: ") , __func__, source_string.len, source_string.s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "source string: [%.*s]\n", process_no, my_pid(), ("sipcapture" " [" "hash_mode.c" ":" "29" "]: ") , __func__, source_string.len, source_string.s); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "source string: [%.*s]\n", ("sipcapture" " [" "hash_mode.c" ":" "29" "]: ") , __func__, source_string.len, source_string.s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "source string: [%.*s]\n", ("sipcapture" " [" "hash_mode.c" ":" "29" "]: ") , __func__, source_string.len, source_string.s); } } (dprint_crit--); } } while(0);
 crc32_uint(&source_string, &hash);
 ret = hash % denominator;
 return ret;
}

canonical_original_code:
int hash_func(struct _sipcapture_object *sco, enum hash_source source, int denominator) {
 int ret;
 unsigned int hash;
 struct _str source_string;
 if(get_source (sco, source, &source_string) == -1) {
  return -1;
 }
 do { if (get_debug_level("sipcapture", (sizeof("sipcapture")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "source string: [%.*s]\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("sipcapture" " [" "hash_mode.c" ":" "29" "]: ") , __func__, source_string.len, source_string.s); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "source string: [%.*s]\n", (log_level_info[((3)) - (-5)].name), ("sipcapture" " [" "hash_mode.c" ":" "29" "]: ") , __func__, source_string.len, source_string.s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "source string: [%.*s]\n", process_no, my_pid(), ("sipcapture" " [" "hash_mode.c" ":" "29" "]: ") , __func__, source_string.len, source_string.s); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "source string: [%.*s]\n", ("sipcapture" " [" "hash_mode.c" ":" "29" "]: ") , __func__, source_string.len, source_string.s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "source string: [%.*s]\n", ("sipcapture" " [" "hash_mode.c" ":" "29" "]: ") , __func__, source_string.len, source_string.s); } } (dprint_crit--); } } while(0);
 crc32_uint(&source_string, &hash);
 ret = hash % denominator;
 return ret;
}

variable_types: denominator int

variable_types: ret int

variable_types:
hash
unsigned int

user_defined_types: enum hash_source { hs_call_id=1, hs_from_user=2, hs_to_user=3, hs_error=4 }