decompiled_code:
__int64 __fastcall unlink_lump_rpl(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a1 + 1456);
if ( !result || result == a2 )
{
if ( result )
*(_QWORD *)(a1 + 1456) = *(_QWORD *)(result + 24);
}
else
{
do
{
v3 = result;
result = *(_QWORD *)(result + 24);
}
while ( result && a2 != result );
if ( result )
*(_QWORD *)(v3 + 24) = *(_QWORD *)(result + 24);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a1 + 1456);
if ( !result || result == a2 )
{
if ( result )
*(_QWORD *)(a1 + 1456) = *(_QWORD *)(result + 24);
}
else
{
do
{
v3 = result;
result = *(_QWORD *)(result + 24);
}
while ( result && a2 != result );
if ( result )
*(_QWORD *)(v3 + 24) = *(_QWORD *)(result + 24);
}
return result;
}

original_code:
void unlink_lump_rpl(struct sip_msg * msg, struct lump_rpl* lump)
{
 struct lump_rpl *foo,*prev;
 foo = msg->reply_lump;
 prev = 0;
 while( foo && foo!=lump ) {
  prev = foo;
  foo = foo->next;
 }
 if (foo) {
  if (prev)
   prev->next = foo->next;
  else
   msg->reply_lump = foo->next;
 }
}

canonical_original_code:
void unlink_lump_rpl(struct sip_msg *msg, struct lump_rpl *lump)
{
 struct lump_rpl *foo; struct lump_rpl *prev;
 foo = msg->reply_lump;
 prev = 0;
 while( foo && foo!=lump ) {
  prev = foo;
  foo = foo->next;
 }
 if (foo) {
  if (prev)
   prev->next = foo->next;
  else
   msg->reply_lump = foo->next;
 }
}

variable_types: struct sip_msg { unsigned int id; int pid; struct timeval { long tv_sec; long tv_usec; } tval; struct snd_flags { unsigned char f; unsigned char blst_imask; } fwd_send_flags; struct snd_flags rpl_send_flags; struct msg_start { int type; int len; union { struct { struct _str { char *s; int len; } method; struct _str uri; struct _str version; int method_value; } request; struct { struct _str version; struct _str status; struct _str reason; unsigned int statuscode; } reply; } u; } first_line; struct via_body { int error; struct _str hdr; struct _str name; struct _str version; struct _str transport; struct _str host; short proto; unsigned short port; struct _str port_str; struct _str params; struct _str comment; int bsize; struct via_param { int type; struct _str name; struct _str value; char *start; int size; struct via_param *next; } *param_lst; struct via_param *last_param; struct via_param *branch; struct _str tid; struct via_param *received; struct via_param *rport; struct via_param *i; struct via_param *alias; struct via_body *next; } *via1; struct via_body *via2; struct hdr_field { enum _hdr_types_t { HDR_ERROR_T=-1, HDR_OTHER_T=0, HDR_VIA_T=1, HDR_VIA1_T=1, HDR_VIA2_T=2, HDR_TO_T=3, HDR_FROM_T=4, HDR_CSEQ_T=5, HDR_CALLID_T=6, HDR_CONTACT_T=7, HDR_MAXFORWARDS_T=8, HDR_ROUTE_T=9, HDR_RECORDROUTE_T=10, HDR_CONTENTTYPE_T=11, HDR_CONTENTLENGTH_T=12, HDR_AUTHORIZATION_T=13, HDR_EXPIRES_T=14, HDR_PROXYAUTH_T=15, HDR_SUPPORTED_T=16, HDR_REQUIRE_T=17, HDR_PROXYREQUIRE_T=18, HDR_UNSUPPORTED_T=19, HDR_ALLOW_T=20, HDR_EVENT_T=21, HDR_ACCEPT_T=22, HDR_ACCEPTLANGUAGE_T=23, HDR_ORGANIZATION_T=24, HDR_PRIORITY_T=25, HDR_SUBJECT_T=26, HDR_USERAGENT_T=27, HDR_SERVER_T=28, HDR_CONTENTDISPOSITION_T=29, HDR_DIVERSION_T=30, HDR_RPID_T=31, HDR_REFER_TO_T=32, HDR_SIPIFMATCH_T=33, HDR_SESSIONEXPIRES_T=34, HDR_MIN_SE_T=35, HDR_SUBSCRIPTION_STATE_T=36, HDR_ACCEPTCONTACT_T=37, HDR_ALLOWEVENTS_T=38, HDR_CONTENTENCODING_T=39, HDR_REFERREDBY_T=40, HDR_REJECTCONTACT_T=41, HDR_REQUESTDISPOSITION_T=42, HDR_WWW_AUTHENTICATE_T=43, HDR_PROXY_AUTHENTICATE_T=44, HDR_DATE_T=45, HDR_IDENTITY_T=46, HDR_IDENTITY_INFO_T=47, HDR_RETRY_AFTER_T=48, HDR_PPI_T=49, HDR_PAI_T=50, HDR_PATH_T=51, HDR_PRIVACY_T=52, HDR_REASON_T=53, HDR_EOH_T=54 } type; struct _str name; struct _str body; int len; void *parsed; struct hdr_field *next; } *headers; struct hdr_field *last_header; unsigned long long parsed_flag; struct hdr_field *h_via1; struct hdr_field *h_via2; struct hdr_field *callid; struct hdr_field *to; struct hdr_field *cseq; struct hdr_field *from; struct hdr_field *contact; struct hdr_field *maxforwards; struct hdr_field *route; struct hdr_field *record_route; struct hdr_field *content_type; struct hdr_field *content_length; struct hdr_field *authorization; struct hdr_field *expires; struct hdr_field *proxy_auth; struct hdr_field *supported; struct hdr_field *require; struct hdr_field *proxy_require; struct hdr_field *unsupported; struct hdr_field *allow; struct hdr_field *event; struct hdr_field *accept; struct hdr_field *accept_language; struct hdr_field *organization; struct hdr_field *priority; struct hdr_field *subject; struct hdr_field *user_agent; struct hdr_field *server; struct hdr_field *content_disposition; struct hdr_field *diversion; struct hdr_field *rpid; struct hdr_field *refer_to; struct hdr_field *session_expires; struct hdr_field *min_se; struct hdr_field *sipifmatch; struct hdr_field *subscription_state; struct hdr_field *date; struct hdr_field *identity; struct hdr_field *identity_info; struct hdr_field *pai; struct hdr_field *ppi; struct hdr_field *path; struct hdr_field *privacy; struct msg_body { enum msg_body_type { MSG_BODY_UNKNOWN=0, MSG_BODY_SDP=1 } type; void (*free)(struct msg_body **ptr); } *body; char *eoh; char *unparsed; struct receive_info { 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; } src_ip; struct ip_addr dst_ip; unsigned short src_port; unsigned short dst_port; int proto_reserved1; int proto_reserved2; 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; } src_su; struct socket_info { int socket; struct _str name; struct ip_addr 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 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; } *bind_address; char proto; } rcv; char *buf; unsigned int len; struct _str new_uri; struct _str dst_uri; int parsed_uri_ok; struct sip_uri { struct _str user; struct _str passwd; struct _str host; struct _str port; struct _str params; struct _str sip_params; struct _str headers; unsigned short port_no; unsigned short proto; enum _uri_type { ERROR_URI_T=0, SIP_URI_T=1, SIPS_URI_T=2, TEL_URI_T=3, TELS_URI_T=4, URN_URI_T=5 } type; enum _uri_flags { URI_USER_NORMALIZE=1, URI_SIP_USER_PHONE=2 } flags; struct _str transport; struct _str ttl; struct _str user_param; struct _str maddr; struct _str method; struct _str lr; struct _str r2; struct _str gr; struct _str transport_val; struct _str ttl_val; struct _str user_param_val; struct _str maddr_val; struct _str method_val; struct _str lr_val; struct _str r2_val; struct _str gr_val; } parsed_uri; int parsed_orig_ruri_ok; struct sip_uri parsed_orig_ruri; struct lump { enum _hdr_types_t { HDR_ERROR_T=-1, HDR_OTHER_T=0, HDR_VIA_T=1, HDR_VIA1_T=1, HDR_VIA2_T=2, HDR_TO_T=3, HDR_FROM_T=4, HDR_CSEQ_T=5, HDR_CALLID_T=6, HDR_CONTACT_T=7, HDR_MAXFORWARDS_T=8, HDR_ROUTE_T=9, HDR_RECORDROUTE_T=10, HDR_CONTENTTYPE_T=11, HDR_CONTENTLENGTH_T=12, HDR_AUTHORIZATION_T=13, HDR_EXPIRES_T=14, HDR_PROXYAUTH_T=15, HDR_SUPPORTED_T=16, HDR_REQUIRE_T=17, HDR_PROXYREQUIRE_T=18, HDR_UNSUPPORTED_T=19, HDR_ALLOW_T=20, HDR_EVENT_T=21, HDR_ACCEPT_T=22, HDR_ACCEPTLANGUAGE_T=23, HDR_ORGANIZATION_T=24, HDR_PRIORITY_T=25, HDR_SUBJECT_T=26, HDR_USERAGENT_T=27, HDR_SERVER_T=28, HDR_CONTENTDISPOSITION_T=29, HDR_DIVERSION_T=30, HDR_RPID_T=31, HDR_REFER_TO_T=32, HDR_SIPIFMATCH_T=33, HDR_SESSIONEXPIRES_T=34, HDR_MIN_SE_T=35, HDR_SUBSCRIPTION_STATE_T=36, HDR_ACCEPTCONTACT_T=37, HDR_ALLOWEVENTS_T=38, HDR_CONTENTENCODING_T=39, HDR_REFERREDBY_T=40, HDR_REJECTCONTACT_T=41, HDR_REQUESTDISPOSITION_T=42, HDR_WWW_AUTHENTICATE_T=43, HDR_PROXY_AUTHENTICATE_T=44, HDR_DATE_T=45, HDR_IDENTITY_T=46, HDR_IDENTITY_INFO_T=47, HDR_RETRY_AFTER_T=48, HDR_PPI_T=49, HDR_PAI_T=50, HDR_PATH_T=51, HDR_PRIVACY_T=52, HDR_REASON_T=53, HDR_EOH_T=54 } type; enum lump_op { LUMP_NOP=0, LUMP_DEL=1, LUMP_ADD=2, LUMP_ADD_SUBST=3, LUMP_ADD_OPT=4 } op; union { int offset; enum lump_subst { SUBST_NOP=0, SUBST_RCV_IP=1, SUBST_SND_IP=2, SUBST_RCV_PORT=3, SUBST_SND_PORT=4, SUBST_RCV_PROTO=5, SUBST_SND_PROTO=6, SUBST_RCV_ALL=7, SUBST_SND_ALL=8 } subst; enum lump_conditions { COND_FALSE=0, COND_TRUE=1, COND_IF_DIFF_REALMS=2, COND_IF_DIFF_AF=3, COND_IF_DIFF_PROTO=4, COND_IF_DIFF_PORT=5, COND_IF_DIFF_IP=6, COND_IF_RAND=7 } cond; char *value; } u; int len; struct lump *before; struct lump *after; struct lump *next; enum lump_flag { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2, LUMPFLAG_BRANCH=4, LUMPFLAG_COND_TRUE=8 } flags; } *add_rm; struct lump *body_lumps; struct lump_rpl { struct _str text; int flags; struct lump_rpl *next; } *reply_lump; char add_to_branch_s[-1]; int add_to_branch_len; unsigned int hash_index; unsigned int msg_flags; unsigned int flags; struct _str set_global_address; struct _str set_global_port; struct socket_info *force_send_socket; struct _str path_vec; struct _str instance; unsigned int reg_id; struct _str ruid; struct _str location_ua; struct msg_ldata { struct ocd_flow { int decoded; struct receive_info rcv; } flow; } ldv; } *

variable_types:
lump
struct lump_rpl *

user_defined_types: struct msg_start { int type; int len; union { struct { struct _str method; struct _str uri; struct _str version; int method_value; } request; struct { struct _str version; struct _str status; struct _str reason; unsigned int statuscode; } reply; } u; }

user_defined_types: struct sip_uri { struct _str user; struct _str passwd; struct _str host; struct _str port; struct _str params; struct _str sip_params; struct _str headers; unsigned short port_no; unsigned short proto; enum _uri_type type; enum _uri_flags flags; struct _str transport; struct _str ttl; struct _str user_param; struct _str maddr; struct _str method; struct _str lr; struct _str r2; struct _str gr; struct _str transport_val; struct _str ttl_val; struct _str user_param_val; struct _str maddr_val; struct _str method_val; struct _str lr_val; struct _str r2_val; struct _str gr_val; }


repo: virtualolson/who

original_code:
void del_nonshm_lump_rpl(struct lump_rpl** list)
{
        struct lump_rpl* it, *tmp;
        struct lump_rpl** pred;
        it = *list;
        pred = list;
        while(it) {
                if (!(it->flags & (1<<5))) {
                        tmp = it;
                        *pred = it->next;
                        it = it->next;
                        free_lump_rpl(tmp);
                        continue;
                }
                pred = &it->next;
                it = it->next;
        }
}

canonical_original_code:
void del_nonshm_lump_rpl(struct lump_rpl **list)
{
        struct lump_rpl *it; struct lump_rpl *tmp;
        struct lump_rpl **pred;
        it = *list;
        pred = list;
        while(it) {
                if (!(it->flags & (1<<5))) {
                        tmp = it;
                        *pred = it->next;
                        it = it->next;
                        free_lump_rpl(tmp);
                        continue;
                }
                pred = &it->next;
                it = it->next;
        }
}

variable_types: struct lump_rpl { struct _str { char *s; int len; } text; int flags; struct lump_rpl *next; } **

return_type: void

user_defined_types: struct lump_rpl { struct _str text; int flags; struct lump_rpl *next; }


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

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

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

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

variable_types:
var
int *

variable_types: v int

return_type: int


decompiled_code:
__int64 __fastcall pkg_proc_update_used(int a1)
{
if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
if ( process_no >= pkg_proc_stats_no )
return 0xFFFFFFFFLL;
*(_DWORD *)(pkg_proc_stats_list + 20LL * process_no + 8) = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
if ( process_no >= pkg_proc_stats_no )
return 0xFFFFFFFFLL;
*(_DWORD *)(pkg_proc_stats_list + 20LL * process_no + 8) = a1;
return 0LL;
}

original_code:
static int pkg_proc_update_used(void *data)
{
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 if(process_no>=_pkg_proc_stats_no)
  return -1;
 _pkg_proc_stats_list[process_no].used = (unsigned int)(long)data;
 return 0;
}

variable_types:
data
void *


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


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 shm_malloc(unsigned int a1)
{
__int64 v1; // rbx

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

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

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

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

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

variable_types:
size
unsigned int

variable_types:
p
void *

return_type: void *


decompiled_code:
__int64 __fastcall pkg_proc_update_real_used(int a1)
{
if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
if ( process_no >= pkg_proc_stats_no )
return 0xFFFFFFFFLL;
*(_DWORD *)(pkg_proc_stats_list + 20LL * process_no + 16) = a1;
*(_DWORD *)(pkg_proc_stats_list + 20LL * process_no + 12) = qm_available(mem_block);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
if ( process_no >= pkg_proc_stats_no )
return 0xFFFFFFFFLL;
*(_DWORD *)(pkg_proc_stats_list + 20LL * process_no + 16) = a1;
*(_DWORD *)(pkg_proc_stats_list + 20LL * process_no + 12) = qm_available(mem_block);
return 0LL;
}

original_code:
static int pkg_proc_update_real_used(void *data)
{
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 if(process_no>=_pkg_proc_stats_no)
  return -1;
 _pkg_proc_stats_list[process_no].real_used = (unsigned int)(long)data;
 _pkg_proc_stats_list[process_no].available = qm_available(mem_block);
 return 0;
}


decompiled_code:
__int64 pkg_proc_stats_init()
{
int v0; // eax
void *v1; // rdi

v0 = get_max_procs();
pkg_proc_stats_no = v0;
if ( v0 <= 0 )
return 0xFFFFFFFFLL;
if ( pkg_proc_stats_list )
return 0xFFFFFFFFLL;
v1 = (void *)shm_malloc(20 * v0);
pkg_proc_stats_list = (__int64)v1;
if ( !v1 )
return 0xFFFFFFFFLL;
memset(v1, 0, 20LL * pkg_proc_stats_no);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
void *v1; // rdi

v0 = get_max_procs();
pkg_proc_stats_no = v0;
if ( v0 <= 0 )
return 0xFFFFFFFFLL;
if ( pkg_proc_stats_list )
return 0xFFFFFFFFLL;
v1 = (void *)func5(20 * v0);
pkg_proc_stats_list = (__int64)v1;
if ( !v1 )
return 0xFFFFFFFFLL;
memset(v1, 0, 20LL * pkg_proc_stats_no);
return 0LL;
}

original_code:
int pkg_proc_stats_init(void)
{
 _pkg_proc_stats_no = get_max_procs();
 if(_pkg_proc_stats_no<=0)
  return -1;
 if(_pkg_proc_stats_list!=((void *)0))
  return -1;
 _pkg_proc_stats_list = (pkg_proc_stats_t*)shm_malloc(
   _pkg_proc_stats_no*sizeof(pkg_proc_stats_t));
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 memset(_pkg_proc_stats_list, 0,
   _pkg_proc_stats_no*sizeof(pkg_proc_stats_t));
 return 0;
}

canonical_original_code:
int pkg_proc_stats_init()
{
 _pkg_proc_stats_no = get_max_procs();
 if(_pkg_proc_stats_no<=0)
  return -1;
 if(_pkg_proc_stats_list!=((void *)0))
  return -1;
 _pkg_proc_stats_list = (struct pkg_proc_stats *)shm_malloc(
   _pkg_proc_stats_no*sizeof(pkg_proc_stats_t));
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 memset(_pkg_proc_stats_list, 0,
   _pkg_proc_stats_no*sizeof(pkg_proc_stats_t));
 return 0;
}

user_defined_types: struct pkg_proc_stats { int rank; unsigned int pid; unsigned int used; unsigned int available; unsigned int real_used; }


decompiled_code:
__int64 __fastcall pkg_proc_stats_myinit(int a1)
{
int v1; // eax
_DWORD *v2; // r9
__int64 v3; // rcx
_DWORD v5[22]; // [rsp-10h] [rbp-58h] BYREF

if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
if ( process_no >= pkg_proc_stats_no )
return 0xFFFFFFFFLL;
v1 = my_pid();
v2 = (_DWORD *)(pkg_proc_stats_list + 20LL * process_no);
v2[1] = v1;
*v2 = a1;
qm_info(mem_block, v5);
v3 = pkg_proc_stats_list + 20LL * process_no;
*(_DWORD *)(v3 + 8) = v5[4];
*(_DWORD *)(v3 + 16) = v5[6];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int v1; // eax
_DWORD *v2; // r9
__int64 v3; // rcx
_DWORD v5[22]; // [rsp-10h] [rbp-58h] BYREF

if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
if ( process_no >= pkg_proc_stats_no )
return 0xFFFFFFFFLL;
v1 = my_pid();
v2 = (_DWORD *)(pkg_proc_stats_list + 20LL * process_no);
v2[1] = v1;
*v2 = a1;
qm_info(mem_block, v5);
v3 = pkg_proc_stats_list + 20LL * process_no;
*(_DWORD *)(v3 + 8) = v5[4];
*(_DWORD *)(v3 + 16) = v5[6];
return 0LL;
}

original_code:
int pkg_proc_stats_myinit(int rank)
{
 struct mem_info info;
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 if(process_no>=_pkg_proc_stats_no)
  return -1;
 _pkg_proc_stats_list[process_no].pid = (unsigned int)my_pid();
 _pkg_proc_stats_list[process_no].rank = rank;
 qm_info(mem_block, &info);
 _pkg_proc_stats_list[process_no].used = info.used;
 _pkg_proc_stats_list[process_no].real_used = info.real_used;
 return 0;
}

variable_types: rank int

variable_types: struct mem_info { unsigned long total_size; unsigned long free; unsigned long used; unsigned long real_used; unsigned long max_used; unsigned long min_frag; unsigned long total_frags; }


decompiled_code:
__int64 pkg_proc_stats_destroy()
{
__int64 v0; // rbx

v0 = pkg_proc_stats_list;
if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
futex_get(mem_lock);
qm_free(shm_block, v0);
futex_release(mem_lock);
pkg_proc_stats_list = 0LL;
pkg_proc_stats_no = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rbx

v0 = pkg_proc_stats_list;
if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
func3(mem_lock);
qm_free(shm_block, v0);
func4(mem_lock);
pkg_proc_stats_list = 0LL;
pkg_proc_stats_no = 0;
return 0LL;
}

original_code:
int pkg_proc_stats_destroy(void)
{
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 do { futex_get(mem_lock); qm_free(shm_block, (_pkg_proc_stats_list)); futex_release(mem_lock); }while(0);
 _pkg_proc_stats_list = 0;
 _pkg_proc_stats_no = 0;
 return 0;
}

canonical_original_code:
int pkg_proc_stats_destroy()
{
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 do { futex_get(mem_lock); qm_free(shm_block, (_pkg_proc_stats_list)); futex_release(mem_lock); }while(0);
 _pkg_proc_stats_list = 0;
 _pkg_proc_stats_no = 0;
 return 0;
}


decompiled_code:
__int64 register_pkg_proc_stats()
{
sr_event_register_cb(5LL, pkg_proc_update_used);
sr_event_register_cb(6LL, pkg_proc_update_real_used);
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
sr_event_register_cb(5LL, pkg_proc_update_used);
sr_event_register_cb(6LL, pkg_proc_update_real_used);
return 0LL;
}

original_code:
int register_pkg_proc_stats(void)
{
 sr_event_register_cb(5, pkg_proc_update_used);
 sr_event_register_cb(6, pkg_proc_update_real_used);
 return 0;
}

canonical_original_code:
int register_pkg_proc_stats()
{
 sr_event_register_cb(5, pkg_proc_update_used);
 sr_event_register_cb(6, pkg_proc_update_real_used);
 return 0;
}


decompiled_code:
__int64 __fastcall pkg_proc_get_pid_index(int a1)
{
_DWORD *v1; // rdx
__int64 result; // rax
int v3; // ecx
int v4; // er9

if ( pkg_proc_stats_no <= 0 )
return 0xFFFFFFFFLL;
v1 = (_DWORD *)(pkg_proc_stats_list + 4);
result = 0LL;
v3 = pkg_proc_stats_no & 7;
if ( (pkg_proc_stats_no & 7) == 0 )
{
LABEL_23:
while ( *v1 != a1 )
{
v4 = result + 1;
result = (unsigned int)(result + 1);
if ( v1[5] == a1 )
break;
result = (unsigned int)(v4 + 1);
if ( v1[10] == a1 )
break;
result = (unsigned int)(v4 + 2);
if ( v1[15] == a1 )
break;
result = (unsigned int)(v4 + 3);
if ( v1[20] == a1 )
break;
result = (unsigned int)(v4 + 4);
if ( v1[25] == a1 )
break;
result = (unsigned int)(v4 + 5);
if ( v1[30] == a1 )
break;
result = (unsigned int)(v4 + 6);
if ( v1[35] == a1 )
break;
result = (unsigned int)(v4 + 7);
v1 += 40;
if ( (_DWORD)result == pkg_proc_stats_no )
goto LABEL_32;
}
return result;
}
switch ( v3 )
{
case 1:
goto LABEL_21;
case 2:
LABEL_19:
if ( *v1 == a1 )
return result;
result = (unsigned int)(result + 1);
v1 += 5;
LABEL_21:
if ( *v1 != a1 )
{
result = (unsigned int)(result + 1);
v1 += 5;
if ( (_DWORD)result != pkg_proc_stats_no )
goto LABEL_23;
LABEL_32:
result = 0xFFFFFFFFLL;
}
return result;
case 3:
LABEL_17:
if ( *v1 == a1 )
return result;
result = (unsigned int)(result + 1);
v1 += 5;
goto LABEL_19;
case 4:
LABEL_15:
if ( *v1 == a1 )
return result;
result = (unsigned int)(result + 1);
v1 += 5;
goto LABEL_17;
case 5:
LABEL_13:
if ( *v1 == a1 )
return result;
result = (unsigned int)(result + 1);
v1 += 5;
goto LABEL_15;
}
if ( v3 != 6 )
{
if ( *v1 == a1 )
return result;
result = 1LL;
v1 = (_DWORD *)(pkg_proc_stats_list + 24);
}
if ( *v1 != a1 )
{
result = (unsigned int)(result + 1);
v1 += 5;
goto LABEL_13;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
_DWORD *v1; // rdx
__int64 result; // rax
int v3; // ecx
int v4; // er9

if ( pkg_proc_stats_no <= 0 )
return 0xFFFFFFFFLL;
v1 = (_DWORD *)(pkg_proc_stats_list + 4);
result = 0LL;
v3 = pkg_proc_stats_no & 7;
if ( (pkg_proc_stats_no & 7) == 0 )
{
LABEL_23:
while ( *v1 != a1 )
{
v4 = result + 1;
result = (unsigned int)(result + 1);
if ( v1[5] == a1 )
break;
result = (unsigned int)(v4 + 1);
if ( v1[10] == a1 )
break;
result = (unsigned int)(v4 + 2);
if ( v1[15] == a1 )
break;
result = (unsigned int)(v4 + 3);
if ( v1[20] == a1 )
break;
result = (unsigned int)(v4 + 4);
if ( v1[25] == a1 )
break;
result = (unsigned int)(v4 + 5);
if ( v1[30] == a1 )
break;
result = (unsigned int)(v4 + 6);
if ( v1[35] == a1 )
break;
result = (unsigned int)(v4 + 7);
v1 += 40;
if ( (_DWORD)result == pkg_proc_stats_no )
goto LABEL_32;
}
return result;
}
switch ( v3 )
{
case 1:
goto LABEL_21;
case 2:
LABEL_19:
if ( *v1 == a1 )
return result;
result = (unsigned int)(result + 1);
v1 += 5;
LABEL_21:
if ( *v1 != a1 )
{
result = (unsigned int)(result + 1);
v1 += 5;
if ( (_DWORD)result != pkg_proc_stats_no )
goto LABEL_23;
LABEL_32:
result = 0xFFFFFFFFLL;
}
return result;
case 3:
LABEL_17:
if ( *v1 == a1 )
return result;
result = (unsigned int)(result + 1);
v1 += 5;
goto LABEL_19;
case 4:
LABEL_15:
if ( *v1 == a1 )
return result;
result = (unsigned int)(result + 1);
v1 += 5;
goto LABEL_17;
case 5:
LABEL_13:
if ( *v1 == a1 )
return result;
result = (unsigned int)(result + 1);
v1 += 5;
goto LABEL_15;
}
if ( v3 != 6 )
{
if ( *v1 == a1 )
return result;
result = 1LL;
v1 = (_DWORD *)(pkg_proc_stats_list + 24);
}
if ( *v1 != a1 )
{
result = (unsigned int)(result + 1);
v1 += 5;
goto LABEL_13;
}
return result;
}

original_code:
int pkg_proc_get_pid_index(unsigned int pid)
{
 int i;
 for(i=0; i<_pkg_proc_stats_no; i++)
 {
  if(_pkg_proc_stats_list[i].pid == pid)
   return i;
 }
 return -1;
}

variable_types:
pid
unsigned int


decompiled_code:
__int64 __fastcall rpc_pkg_stats(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v5; // er13
int v6; // ebx
__int64 v7; // r12
bool v8; // zf
unsigned int v9; // ebx
__int64 v10; // r15
int v11; // [rsp+Ch] [rbp-6Ch]
__int64 v12; // [rsp+18h] [rbp-60h] BYREF
const void *v13; // [rsp+20h] [rbp-58h] BYREF
int v14; // [rsp+28h] [rbp-50h]
int v15[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

if ( !pkg_proc_stats_list )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Not initialized");
v15[0] = 0;
v11 = pkg_proc_stats_no;
result = (*(__int64 (__fastcall **)(__int64, const char *, const void **))(a1 + 24))(a2, "*S", &v13);
v5 = result;
if ( (_DWORD)result != 1 )
{
v5 = 0;
v6 = 0;
goto LABEL_4;
}
if ( v14 == 3 )
{
if ( !memcmp(v13, "pid", 3uLL) )
{
if ( (*(int (__fastcall **)(__int64, const char *, int *))(a1 + 24))(a2, "d", v15) <= 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "One more parameter expected");
result = pkg_proc_get_pid_index(v15[0]);
v6 = result;
v11 = result + 1;
if ( (int)result < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "No such pid");
goto LABEL_4;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Invalid filter type");
}
if ( v14 == 4 )
{
v8 = memcmp(v13, "rank", 4uLL) == 0;
v6 = !v8;
if ( v8 )
{
result = (*(__int64 (__fastcall **)(__int64, const char *, int *))(a1 + 24))(a2, "d", v15);
if ( (int)result <= 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "One more parameter expected");
v5 = 2;
goto LABEL_4;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Invalid filter type");
}
if ( v14 != 5 || memcmp(v13, "index", 5uLL) )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Invalid filter type");
result = (*(__int64 (__fastcall **)(__int64, const char *, int *))(a1 + 24))(a2, "d", v15);
if ( (int)result <= 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "One more parameter expected");
v6 = v15[0];
v11 = v15[0] + 1;
v5 = 3;
LABEL_4:
if ( v6 >= v11 )
return result;
v7 = 20LL * v6;
result = (unsigned int)(v11 - v6);
if ( (((_BYTE)v11 - (_BYTE)v6) & 1) == 0 )
{
LABEL_37:
while ( 1 )
{
if ( v5 != 2 || *(_DWORD *)(pkg_proc_stats_list + v7) == v15[0] )
{
if ( (*(int (__fastcall **)(__int64, const char *, __int64 *))(a1 + 16))(a2, "{", &v12) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(
a2,
500LL,
"Internal error creating rpc");
result = (*(__int64 (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD))(a1 + 40))(
v12,
"dddddd",
"entry",
(unsigned int)v6,
"pid",
*(unsigned int *)(pkg_proc_stats_list + v7 + 4),
"rank",
*(unsigned int *)(pkg_proc_stats_list + v7),
"used",
*(unsigned int *)(pkg_proc_stats_list + v7 + 8),
"free",
*(unsigned int *)(pkg_proc_stats_list + v7 + 12),
"real_used",
*(unsigned int *)(pkg_proc_stats_list + v7 + 16));
if ( (int)result < 0 )
break;
}
v9 = v6 + 1;
if ( v5 != 2 || *(_DWORD *)(pkg_proc_stats_list + v7 + 20) == v15[0] )
{
if ( (*(int (__fastcall **)(__int64, const char *, __int64 *))(a1 + 16))(a2, "{", &v12) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(
a2,
500LL,
"Internal error creating rpc");
v10 = v7 + 20;
result = (*(__int64 (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD))(a1 + 40))(
v12,
"dddddd",
"entry",
v9,
"pid",
*(unsigned int *)(pkg_proc_stats_list + v10 + 4),
"rank",
*(unsigned int *)(pkg_proc_stats_list + v10),
"used",
*(unsigned int *)(pkg_proc_stats_list + v10 + 8),
"free",
*(unsigned int *)(pkg_proc_stats_list + v10 + 12),
"real_used",
*(unsigned int *)(pkg_proc_stats_list + v10 + 16));
if ( (int)result < 0 )
break;
}
v6 = v9 + 1;
v7 += 40LL;
if ( v6 == v11 )
return result;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error creating rpc");
}
if ( v5 != 2 || *(_DWORD *)(pkg_proc_stats_list + 20LL * v6) == v15[0] )
{
if ( (*(int (__fastcall **)(__int64, const char *, __int64 *))(a1 + 16))(a2, "{", &v12) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error creating rpc");
result = (*(__int64 (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD))(a1 + 40))(
v12,
"dddddd",
"entry",
(unsigned int)v6,
"pid",
*(unsigned int *)(pkg_proc_stats_list + v7 + 4),
"rank",
*(unsigned int *)(pkg_proc_stats_list + 20LL * v6),
"used",
*(unsigned int *)(pkg_proc_stats_list + v7 + 8),
"free",
*(unsigned int *)(pkg_proc_stats_list + v7 + 12),
"real_used",
*(unsigned int *)(pkg_proc_stats_list + v7 + 16));
if ( (int)result < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error creating rpc");
}
++v6;
v7 += 20LL;
if ( v6 != v11 )
goto LABEL_37;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v5; // er13
int v6; // ebx
__int64 v7; // r12
bool v8; // zf
unsigned int v9; // ebx
__int64 v10; // r15
int v11; // [rsp+Ch] [rbp-6Ch]
__int64 v12; // [rsp+18h] [rbp-60h] BYREF
const void *v13; // [rsp+20h] [rbp-58h] BYREF
int v14; // [rsp+28h] [rbp-50h]
int v15[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

if ( !pkg_proc_stats_list )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Not initialized");
v15[0] = 0;
v11 = pkg_proc_stats_no;
result = (*(__int64 (__fastcall **)(__int64, const char *, const void **))(a1 + 24))(a2, "*S", &v13);
v5 = result;
if ( (_DWORD)result != 1 )
{
v5 = 0;
v6 = 0;
goto LABEL_4;
}
if ( v14 == 3 )
{
if ( !memcmp(v13, "pid", 3uLL) )
{
if ( (*(int (__fastcall **)(__int64, const char *, int *))(a1 + 24))(a2, "d", v15) <= 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "One more parameter expected");
result = func11(v15[0]);
v6 = result;
v11 = result + 1;
if ( (int)result < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "No such pid");
goto LABEL_4;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Invalid filter type");
}
if ( v14 == 4 )
{
v8 = memcmp(v13, "rank", 4uLL) == 0;
v6 = !v8;
if ( v8 )
{
result = (*(__int64 (__fastcall **)(__int64, const char *, int *))(a1 + 24))(a2, "d", v15);
if ( (int)result <= 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "One more parameter expected");
v5 = 2;
goto LABEL_4;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Invalid filter type");
}
if ( v14 != 5 || memcmp(v13, "index", 5uLL) )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Invalid filter type");
result = (*(__int64 (__fastcall **)(__int64, const char *, int *))(a1 + 24))(a2, "d", v15);
if ( (int)result <= 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "One more parameter expected");
v6 = v15[0];
v11 = v15[0] + 1;
v5 = 3;
LABEL_4:
if ( v6 >= v11 )
return result;
v7 = 20LL * v6;
result = (unsigned int)(v11 - v6);
if ( (((_BYTE)v11 - (_BYTE)v6) & 1) == 0 )
{
LABEL_37:
while ( 1 )
{
if ( v5 != 2 || *(_DWORD *)(pkg_proc_stats_list + v7) == v15[0] )
{
if ( (*(int (__fastcall **)(__int64, const char *, __int64 *))(a1 + 16))(a2, "{", &v12) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(
a2,
500LL,
"Internal error creating rpc");
result = (*(__int64 (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD))(a1 + 40))(
v12,
"dddddd",
"entry",
(unsigned int)v6,
"pid",
*(unsigned int *)(pkg_proc_stats_list + v7 + 4),
"rank",
*(unsigned int *)(pkg_proc_stats_list + v7),
"used",
*(unsigned int *)(pkg_proc_stats_list + v7 + 8),
"free",
*(unsigned int *)(pkg_proc_stats_list + v7 + 12),
"real_used",
*(unsigned int *)(pkg_proc_stats_list + v7 + 16));
if ( (int)result < 0 )
break;
}
v9 = v6 + 1;
if ( v5 != 2 || *(_DWORD *)(pkg_proc_stats_list + v7 + 20) == v15[0] )
{
if ( (*(int (__fastcall **)(__int64, const char *, __int64 *))(a1 + 16))(a2, "{", &v12) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(
a2,
500LL,
"Internal error creating rpc");
v10 = v7 + 20;
result = (*(__int64 (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD))(a1 + 40))(
v12,
"dddddd",
"entry",
v9,
"pid",
*(unsigned int *)(pkg_proc_stats_list + v10 + 4),
"rank",
*(unsigned int *)(pkg_proc_stats_list + v10),
"used",
*(unsigned int *)(pkg_proc_stats_list + v10 + 8),
"free",
*(unsigned int *)(pkg_proc_stats_list + v10 + 12),
"real_used",
*(unsigned int *)(pkg_proc_stats_list + v10 + 16));
if ( (int)result < 0 )
break;
}
v6 = v9 + 1;
v7 += 40LL;
if ( v6 == v11 )
return result;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error creating rpc");
}
if ( v5 != 2 || *(_DWORD *)(pkg_proc_stats_list + 20LL * v6) == v15[0] )
{
if ( (*(int (__fastcall **)(__int64, const char *, __int64 *))(a1 + 16))(a2, "{", &v12) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error creating rpc");
result = (*(__int64 (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD))(a1 + 40))(
v12,
"dddddd",
"entry",
(unsigned int)v6,
"pid",
*(unsigned int *)(pkg_proc_stats_list + v7 + 4),
"rank",
*(unsigned int *)(pkg_proc_stats_list + 20LL * v6),
"used",
*(unsigned int *)(pkg_proc_stats_list + v7 + 8),
"free",
*(unsigned int *)(pkg_proc_stats_list + v7 + 12),
"real_used",
*(unsigned int *)(pkg_proc_stats_list + v7 + 16));
if ( (int)result < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error creating rpc");
}
++v6;
v7 += 20LL;
if ( v6 != v11 )
goto LABEL_37;
return result;
}

original_code:
static void rpc_pkg_stats(rpc_t* rpc, void* ctx)
{
 int i;
 int limit;
 int cval;
 str cname;
 void* th;
 int mode;
 if(_pkg_proc_stats_list==((void *)0))
 {
  rpc->fault(ctx, 500, "Not initialized");
  return;
 }
 i = 0;
 mode = 0;
 cval = 0;
 limit = _pkg_proc_stats_no;
 if (rpc->scan(ctx, "*S", &cname) == 1)
 {
  if(cname.len==3 && strncmp(cname.s, "pid", 3)==0)
   mode = 1;
  else if(cname.len==4 && strncmp(cname.s, "rank", 4)==0)
   mode = 2;
  else if(cname.len==5 && strncmp(cname.s, "index", 5)==0)
   mode = 3;
  else {
   rpc->fault(ctx, 500, "Invalid filter type");
   return;
  }
  if (rpc->scan(ctx, "d", &cval) < 1)
  {
   rpc->fault(ctx, 500, "One more parameter expected");
   return;
  }
  if(mode==1)
  {
   i = pkg_proc_get_pid_index((unsigned int)cval);
   if(i<0)
   {
    rpc->fault(ctx, 500, "No such pid");
    return;
   }
   limit = i + 1;
  } else if(mode==3) {
   i=cval;
   limit = i + 1;
  }
 }
 for(; i<limit; i++)
 {
  if(mode!=2 || _pkg_proc_stats_list[i].rank==cval)
  {
   if (rpc->add(ctx, "{", &th) < 0)
   {
    rpc->fault(ctx, 500, "Internal error creating rpc");
    return;
   }
   if(rpc->struct_add(th, "dddddd",
       "entry", i,
       "pid", _pkg_proc_stats_list[i].pid,
       "rank", _pkg_proc_stats_list[i].rank,
       "used", _pkg_proc_stats_list[i].used,
       "free", _pkg_proc_stats_list[i].available,
       "real_used", _pkg_proc_stats_list[i].real_used
      )<0)
   {
    rpc->fault(ctx, 500, "Internal error creating rpc");
    return;
   }
  }
 }
}

canonical_original_code:
static void rpc_pkg_stats(struct rpc *rpc, void *ctx)
{
 int i;
 int limit;
 int cval;
 struct _str cname;
 void *th;
 int mode;
 if(_pkg_proc_stats_list==((void *)0))
 {
  rpc->fault(ctx, 500, "Not initialized");
  return;
 }
 i = 0;
 mode = 0;
 cval = 0;
 limit = _pkg_proc_stats_no;
 if (rpc->scan(ctx, "*S", &cname) == 1)
 {
  if(cname.len==3 && strncmp(cname.s, "pid", 3)==0)
   mode = 1;
  else if(cname.len==4 && strncmp(cname.s, "rank", 4)==0)
   mode = 2;
  else if(cname.len==5 && strncmp(cname.s, "index", 5)==0)
   mode = 3;
  else {
   rpc->fault(ctx, 500, "Invalid filter type");
   return;
  }
  if (rpc->scan(ctx, "d", &cval) < 1)
  {
   rpc->fault(ctx, 500, "One more parameter expected");
   return;
  }
  if(mode==1)
  {
   i = pkg_proc_get_pid_index((unsigned int)cval);
   if(i<0)
   {
    rpc->fault(ctx, 500, "No such pid");
    return;
   }
   limit = i + 1;
  } else if(mode==3) {
   i=cval;
   limit = i + 1;
  }
 }
 for(; i<limit; i++)
 {
  if(mode!=2 || _pkg_proc_stats_list[i].rank==cval)
  {
   if (rpc->add(ctx, "{", &th) < 0)
   {
    rpc->fault(ctx, 500, "Internal error creating rpc");
    return;
   }
   if(rpc->struct_add(th, "dddddd",
       "entry", i,
       "pid", _pkg_proc_stats_list[i].pid,
       "rank", _pkg_proc_stats_list[i].rank,
       "used", _pkg_proc_stats_list[i].used,
       "free", _pkg_proc_stats_list[i].available,
       "real_used", _pkg_proc_stats_list[i].real_used
      )<0)
   {
    rpc->fault(ctx, 500, "Internal error creating rpc");
    return;
   }
  }
 }
}

variable_types: struct rpc { void (*fault)(void *ctx, int code, char *fmt, ...); int (*send)(void *ctx); int (*add)(void *ctx, char *fmt, ...); int (*scan)(void *ctx, char *fmt, ...); int (*printf)(void *ctx, char *fmt, ...); int (*struct_add)(void *ctx, char *fmt, ...); int (*struct_scan)(void *ctx, char *fmt, ...); int (*struct_printf)(void *ctx, char *name, char *fmt, ...); enum rpc_capabilities { RPC_DELAYED_REPLY=expr } (*capabilities)(void *ctx); struct rpc_delayed_ctx { struct rpc rpc; void *reply_ctx; } *(*delayed_ctx_new)(void *ctx); void (*delayed_ctx_close)(struct rpc_delayed_ctx *dctx); } *

variable_types:
ctx
void *

variable_types: limit int

variable_types: cval int

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

variable_types:
th
void *

variable_types: mode int

user_defined_types: struct rpc { void (*fault)(void *ctx, int code, char *fmt, ...); int (*send)(void *ctx); int (*add)(void *ctx, char *fmt, ...); int (*scan)(void *ctx, char *fmt, ...); int (*printf)(void *ctx, char *fmt, ...); int (*struct_add)(void *ctx, char *fmt, ...); int (*struct_scan)(void *ctx, char *fmt, ...); int (*struct_printf)(void *ctx, char *name, char *fmt, ...); enum rpc_capabilities (*capabilities)(void *ctx); struct rpc_delayed_ctx *(*delayed_ctx_new)(void *ctx); void (*delayed_ctx_close)(struct rpc_delayed_ctx *dctx); }


decompiled_code:
__int64 pkg_proc_stats_init_rpc()
{
__int64 result; // rax
int v1; // edx
const char *v2; // rbx
unsigned int v3; // eax

result = rpc_register_array(&kex_pkg_rpc);
if ( (_DWORD)result )
{
v1 = get_debug_level("kex", 3LL);
result = 0xFFFFFFFFLL;
if ( v1 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v2 = (const char *)*((_QWORD *)&log_level_info + 8);
v3 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): failed to register RPC commands\n",
process_no,
v3,
v2,
"kex [pkg_stats.c:272]: ",
"pkg_proc_stats_init_rpc");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): failed to register RPC commands\n",
*((const char **)&log_level_info + 8),
"kex [pkg_stats.c:272]: ",
"pkg_proc_stats_init_rpc");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax
int v1; // edx
const char *v2; // rbx
unsigned int v3; // eax

result = rpc_register_array(&kex_pkg_rpc);
if ( (_DWORD)result )
{
v1 = get_debug_level("kex", 3LL);
result = 0xFFFFFFFFLL;
if ( v1 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v2 = (const char *)*((_QWORD *)&log_level_info + 8);
v3 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): failed to register RPC commands\n",
process_no,
v3,
v2,
"kex [pkg_stats.c:272]: ",
"pkg_proc_stats_init_rpc");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): failed to register RPC commands\n",
*((const char **)&log_level_info + 8),
"kex [pkg_stats.c:272]: ",
"pkg_proc_stats_init_rpc");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int pkg_proc_stats_init_rpc(void)
{
 if (rpc_register_array(kex_pkg_rpc)!=0)
 {
  do { if (get_debug_level("kex", (sizeof("kex")-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(): " "failed to register RPC commands\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __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(): " "failed to register RPC commands\n", (log_level_info[((-1)) - (-5)].name), ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "failed to register RPC commands\n", process_no, my_pid(), ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __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(): " "failed to register RPC commands\n", ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "failed to register RPC commands\n", ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 return 0;
}

canonical_original_code:
int pkg_proc_stats_init_rpc()
{
 if (rpc_register_array(kex_pkg_rpc)!=0)
 {
  do { if (get_debug_level("kex", (sizeof("kex")-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(): " "failed to register RPC commands\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __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(): " "failed to register RPC commands\n", (log_level_info[((-1)) - (-5)].name), ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "failed to register RPC commands\n", process_no, my_pid(), ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __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(): " "failed to register RPC commands\n", ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "failed to register RPC commands\n", ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 return 0;
}

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


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 qsa_initialize()
{
__int64 result; // rax
_DWORD *v1; // rax
__int64 v2; // rbx
const char *v3; // rbx
unsigned int v4; // eax
const char *v5; // rbx
unsigned int v6; // eax

if ( init )
{
if ( *(int *)init > 0 )
{
++*(_DWORD *)init;
return 0LL;
}
}
else
{
v1 = (_DWORD *)shm_malloc(0x10u);
init = (__int64)v1;
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = 0;
}
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v3 = (const char *)*((_QWORD *)&log_level_info + 16);
v4 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): init the content\n",
process_no,
v4,
v3,
"<core> [qsa.c:55]: ",
"qsa_initialize");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): init the content\n",
*((const char **)&log_level_info + 16),
"<core> [qsa.c:55]: ",
"qsa_initialize");
}
--dprint_crit;
}
v2 = init;
*(_QWORD *)(v2 + 8) = create_domain_maintainer();
if ( *(_QWORD *)(init + 8) )
{
++*(_DWORD *)init;
result = 0LL;
}
else if ( (int)get_debug_level("core", 4LL) < -1 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v5 = (const char *)*((_QWORD *)&log_level_info + 8);
v6 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): qsa_initialize error - can't initialize domain maintainer\n",
process_no,
v6,
v5,
"<core> [qsa.c:60]: ",
"qsa_initialize");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): qsa_initialize error - can't initialize domain maintainer\n",
*((const char **)&log_level_info + 8),
"<core> [qsa.c:60]: ",
"qsa_initialize");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
_DWORD *v1; // rax
__int64 v2; // rbx
const char *v3; // rbx
unsigned int v4; // eax
const char *v5; // rbx
unsigned int v6; // eax

if ( init )
{
if ( *(int *)init > 0 )
{
++*(_DWORD *)init;
return 0LL;
}
}
else
{
v1 = (_DWORD *)func4(0x10u);
init = (__int64)v1;
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = 0;
}
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v3 = (const char *)*((_QWORD *)&log_level_info + 16);
v4 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): init the content\n",
process_no,
v4,
v3,
"<core> [qsa.c:55]: ",
"qsa_initialize");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): init the content\n",
*((const char **)&log_level_info + 16),
"<core> [qsa.c:55]: ",
"qsa_initialize");
}
--dprint_crit;
}
v2 = init;
*(_QWORD *)(v2 + 8) = create_domain_maintainer();
if ( *(_QWORD *)(init + 8) )
{
++*(_DWORD *)init;
result = 0LL;
}
else if ( (int)get_debug_level("core", 4LL) < -1 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v5 = (const char *)*((_QWORD *)&log_level_info + 8);
v6 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): qsa_initialize error - can't initialize domain maintainer\n",
process_no,
v6,
v5,
"<core> [qsa.c:60]: ",
"qsa_initialize");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): qsa_initialize error - can't initialize domain maintainer\n",
*((const char **)&log_level_info + 8),
"<core> [qsa.c:60]: ",
"qsa_initialize");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int qsa_initialize()
{
 int res = 0;
 if (!init) {
  init = (init_data_t*)shm_malloc(sizeof(init_data_t));
  if (!init) return -1;
  init->init_cnt = 0;
 }
 if (init->init_cnt > 0) {
  init->init_cnt++;
  return 0;
 }
 else {
  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(): " "init the content\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "qsa.c" ":" "55" "]: ") , __func__); 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(): " "init the content\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "qsa.c" ":" "55" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "init the content\n", process_no, my_pid(), ("<core> [" "qsa.c" ":" "55" "]: ") , __func__); 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(): " "init the content\n", ("<core> [" "qsa.c" ":" "55" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "init the content\n", ("<core> [" "qsa.c" ":" "55" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  init->dm = create_domain_maintainer();
  if (!init->dm) {
   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(): " "qsa_initialize error - can't initialize domain maintainer\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "qsa.c" ":" "60" "]: ") , __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(): " "qsa_initialize error - can't initialize domain maintainer\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "qsa.c" ":" "60" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "qsa_initialize error - can't initialize domain maintainer\n", process_no, my_pid(), ("<core> [" "qsa.c" ":" "60" "]: ") , __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(): " "qsa_initialize error - can't initialize domain maintainer\n", ("<core> [" "qsa.c" ":" "60" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "qsa_initialize error - can't initialize domain maintainer\n", ("<core> [" "qsa.c" ":" "60" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   res = -1;
  }
 }
 if (res == 0) init->init_cnt++;
 return res;
}

canonical_original_code:
int qsa_initialize()
{
 int res = 0;
 if (!init) {
  init = (struct init_data_t *)shm_malloc(sizeof(init_data_t));
  if (!init) return -1;
  init->init_cnt = 0;
 }
 if (init->init_cnt > 0) {
  init->init_cnt++;
  return 0;
 }
 else {
  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(): " "init the content\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "qsa.c" ":" "55" "]: ") , __func__); 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(): " "init the content\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "qsa.c" ":" "55" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "init the content\n", process_no, my_pid(), ("<core> [" "qsa.c" ":" "55" "]: ") , __func__); 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(): " "init the content\n", ("<core> [" "qsa.c" ":" "55" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "init the content\n", ("<core> [" "qsa.c" ":" "55" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  init->dm = create_domain_maintainer();
  if (!init->dm) {
   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(): " "qsa_initialize error - can't initialize domain maintainer\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "qsa.c" ":" "60" "]: ") , __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(): " "qsa_initialize error - can't initialize domain maintainer\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "qsa.c" ":" "60" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "qsa_initialize error - can't initialize domain maintainer\n", process_no, my_pid(), ("<core> [" "qsa.c" ":" "60" "]: ") , __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(): " "qsa_initialize error - can't initialize domain maintainer\n", ("<core> [" "qsa.c" ":" "60" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "qsa_initialize error - can't initialize domain maintainer\n", ("<core> [" "qsa.c" ":" "60" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   res = -1;
  }
 }
 if (res == 0) init->init_cnt++;
 return res;
}

variable_types: res int

user_defined_types: struct init_data_t { int init_cnt; struct domain_maintainer_t *dm; }

user_defined_types: struct domain_maintainer_t { struct vector_t registered_domains; struct reference_counter_group_t *rc_grp; struct atomic_t mutex; }

user_defined_types: struct vector_t { int element_size; int element_count; int allocated_count; int allocation_count; void *data; }

user_defined_types: struct reference_counter_group_t { int mutex_cnt; int mutex_to_assign; struct atomic_t mutexes[1]; }


decompiled_code:
void qsa_cleanup()
{
const char *v1; // rbx
unsigned int v2; // eax

if ( init )
{
if ( (*(_DWORD *)init)-- == 1 )
{
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v1 = (const char *)*((_QWORD *)&log_level_info + 16);
v2 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cleaning the content\n",
process_no,
v2,
v1,
"<core> [qsa.c:73]: ",
"qsa_cleanup");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cleaning the content\n",
*((const char **)&log_level_info + 16),
"<core> [qsa.c:73]: ",
"qsa_cleanup");
}
--dprint_crit;
}
if ( *(_QWORD *)(init + 8) )
destroy_domain_maintainer();
futex_get(mem_lock);
qm_free(shm_block, init);
futex_release(mem_lock);
init = 0LL;
}
}
}

canonical_decompiled_code:
void func6()
{
const char *v1; // rbx
unsigned int v2; // eax

if ( init )
{
if ( (*(_DWORD *)init)-- == 1 )
{
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v1 = (const char *)*((_QWORD *)&log_level_info + 16);
v2 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cleaning the content\n",
process_no,
v2,
v1,
"<core> [qsa.c:73]: ",
"qsa_cleanup");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cleaning the content\n",
*((const char **)&log_level_info + 16),
"<core> [qsa.c:73]: ",
"qsa_cleanup");
}
--dprint_crit;
}
if ( *(_QWORD *)(init + 8) )
destroy_domain_maintainer();
func2(mem_lock);
qm_free(shm_block, init);
func3(mem_lock);
init = 0LL;
}
}
}

original_code:
void qsa_cleanup()
{
 if (init) {
  if (--init->init_cnt == 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(): " "cleaning the content\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "qsa.c" ":" "73" "]: ") , __func__); 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(): " "cleaning the content\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "qsa.c" ":" "73" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cleaning the content\n", process_no, my_pid(), ("<core> [" "qsa.c" ":" "73" "]: ") , __func__); 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(): " "cleaning the content\n", ("<core> [" "qsa.c" ":" "73" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cleaning the content\n", ("<core> [" "qsa.c" ":" "73" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   if (init->dm) destroy_domain_maintainer(init->dm);
   do { futex_get(mem_lock); qm_free(shm_block, (init)); futex_release(mem_lock); }while(0);
   init = ((void *)0);
  }
 }
}


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

v1 = init;
if ( init )
{
v1 = *(_QWORD *)(init + 8);
if ( v1 )
v1 = register_notifier_domain(v1, a1);
}
else if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v3 = (const char *)*((_QWORD *)&log_level_info + 8);
v4 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): qsa_initialize was not called - can't register domain\n",
process_no,
v4,
v3,
"<core> [qsa.c:89]: ",
"qsa_register_domain");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): qsa_initialize was not called - can't register domain\n",
*((const char **)&log_level_info + 8),
"<core> [qsa.c:89]: ",
"qsa_register_domain");
}
--dprint_crit;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rbx
const char *v3; // rbp
unsigned int v4; // eax

v1 = init;
if ( init )
{
v1 = *(_QWORD *)(init + 8);
if ( v1 )
v1 = register_notifier_domain(v1, a1);
}
else if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v3 = (const char *)*((_QWORD *)&log_level_info + 8);
v4 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): qsa_initialize was not called - can't register domain\n",
process_no,
v4,
v3,
"<core> [qsa.c:89]: ",
"qsa_register_domain");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): qsa_initialize was not called - can't register domain\n",
*((const char **)&log_level_info + 8),
"<core> [qsa.c:89]: ",
"qsa_register_domain");
}
--dprint_crit;
}
return v1;
}

original_code:
notifier_domain_t *qsa_register_domain(const str_t *name)
{
 notifier_domain_t *d = ((void *)0);
 if (!init) {
  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(): " "qsa_initialize was not called - can't register domain\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "qsa.c" ":" "89" "]: ") , __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(): " "qsa_initialize was not called - can't register domain\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "qsa.c" ":" "89" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "qsa_initialize was not called - can't register domain\n", process_no, my_pid(), ("<core> [" "qsa.c" ":" "89" "]: ") , __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(): " "qsa_initialize was not called - can't register domain\n", ("<core> [" "qsa.c" ":" "89" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "qsa_initialize was not called - can't register domain\n", ("<core> [" "qsa.c" ":" "89" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return ((void *)0);
 }
 if (init->dm) d = register_notifier_domain(init->dm, name);
 return d;
}

canonical_original_code:
struct _notifier_domain_t *qsa_register_domain(struct _str *name)
{
 struct _notifier_domain_t *d = ((void *)0);
 if (!init) {
  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(): " "qsa_initialize was not called - can't register domain\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "qsa.c" ":" "89" "]: ") , __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(): " "qsa_initialize was not called - can't register domain\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "qsa.c" ":" "89" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "qsa_initialize was not called - can't register domain\n", process_no, my_pid(), ("<core> [" "qsa.c" ":" "89" "]: ") , __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(): " "qsa_initialize was not called - can't register domain\n", ("<core> [" "qsa.c" ":" "89" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "qsa_initialize was not called - can't register domain\n", ("<core> [" "qsa.c" ":" "89" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return ((void *)0);
 }
 if (init->dm) d = register_notifier_domain(init->dm, name);
 return d;
}

variable_types:
name
struct _str *

variable_types: struct _notifier_domain_t { struct atomic_t { int val; } mutex; struct atomic_t data_mutex; struct _str { char *s; int len; } name; struct _notifier_package_t { struct _str name; struct _notifier_domain_t *domain; struct _notifier_t { int (*subscribe)(struct _notifier_t *n, struct _qsa_subscription_t { struct atomic_t *mutex; struct _notifier_package_t *package; int allow_notifications; struct _qsa_subscription_data_t { struct msg_queue { struct reference_counter_data_t { int cntr; struct atomic_t *mutex; } ref; struct _mq_message_t { void *data; int data_len; struct _mq_message_t *next; void (*destroy_function)(void *); enum { message_allocated_with_data=0, message_holding_data_ptr=1 } allocation_style; char data_buf[1]; } *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; } *dst; struct _str record_id; struct _str subscriber_id; struct _qsa_subscription_params_t { struct _str name; struct _str value; char buf[1]; } *first_param; void *subscriber_data; } *data; struct _qsa_subscription_t *prev; struct reference_counter_data_t ref; } *subscription); void (*unsubscribe)(struct _notifier_t *n, struct _qsa_subscription_t *subscription); void *user_data; struct _notifier_package_t *package; struct _notifier_t *prev; } *first_notifier; struct _qsa_subscription_t *first_subscription; struct _notifier_package_t *next; } *first_package; struct _qsa_content_type_t { struct _qsa_content_type_t *next; struct _str name; void (*destroy_func)(void *); char buf[1]; } *first_content_type; struct reference_counter_data_t ref; struct reference_counter_group_t { int mutex_cnt; int mutex_to_assign; struct atomic_t mutexes[1]; } *rc_grp; } *

user_defined_types: struct _notifier_domain_t { struct atomic_t mutex; struct atomic_t data_mutex; struct _str name; struct _notifier_package_t *first_package; struct _qsa_content_type_t *first_content_type; struct reference_counter_data_t ref; struct reference_counter_group_t *rc_grp; }

user_defined_types: struct _notifier_package_t { struct _str name; struct _notifier_domain_t *domain; struct _notifier_t *first_notifier; struct _qsa_subscription_t *first_subscription; struct _notifier_package_t *next; }

user_defined_types: struct _notifier_t { int (*subscribe)(struct _notifier_t *n, struct _qsa_subscription_t *subscription); void (*unsubscribe)(struct _notifier_t *n, struct _qsa_subscription_t *subscription); void *user_data; struct _notifier_package_t *package; struct _notifier_t *prev; }

user_defined_types: struct _qsa_subscription_t { struct atomic_t *mutex; struct _notifier_package_t *package; int allow_notifications; struct _qsa_subscription_data_t *data; struct _qsa_subscription_t *prev; struct reference_counter_data_t ref; }

user_defined_types: struct _qsa_subscription_data_t { struct msg_queue *dst; struct _str record_id; struct _str subscriber_id; struct _qsa_subscription_params_t *first_param; void *subscriber_data; }

user_defined_types: struct msg_queue { struct reference_counter_data_t ref; struct _mq_message_t *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; }


decompiled_code:
__int64 qsa_get_default_domain()
{
return qsa_register_domain(0LL);
}

canonical_decompiled_code:
__int64 func8()
{
return func7(0LL);
}

canonical_original_code:
struct _notifier_domain_t *qsa_get_default_domain()
{
 return qsa_register_domain(((void *)0));
}

return_type: struct _notifier_domain_t { struct atomic_t { int val; } mutex; struct atomic_t data_mutex; struct _str { char *s; int len; } name; struct _notifier_package_t { struct _str name; struct _notifier_domain_t *domain; struct _notifier_t { int (*subscribe)(struct _notifier_t *n, struct _qsa_subscription_t { struct atomic_t *mutex; struct _notifier_package_t *package; int allow_notifications; struct _qsa_subscription_data_t { struct msg_queue { struct reference_counter_data_t { int cntr; struct atomic_t *mutex; } ref; struct _mq_message_t { void *data; int data_len; struct _mq_message_t *next; void (*destroy_function)(void *); enum { message_allocated_with_data=0, message_holding_data_ptr=1 } allocation_style; char data_buf[1]; } *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; } *dst; struct _str record_id; struct _str subscriber_id; struct _qsa_subscription_params_t { struct _str name; struct _str value; char buf[1]; } *first_param; void *subscriber_data; } *data; struct _qsa_subscription_t *prev; struct reference_counter_data_t ref; } *subscription); void (*unsubscribe)(struct _notifier_t *n, struct _qsa_subscription_t *subscription); void *user_data; struct _notifier_package_t *package; struct _notifier_t *prev; } *first_notifier; struct _qsa_subscription_t *first_subscription; struct _notifier_package_t *next; } *first_package; struct _qsa_content_type_t { struct _qsa_content_type_t *next; struct _str name; void (*destroy_func)(void *); char buf[1]; } *first_content_type; struct reference_counter_data_t ref; struct reference_counter_group_t { int mutex_cnt; int mutex_to_assign; struct atomic_t mutexes[1]; } *rc_grp; } *


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

result = init;
if ( init )
{
if ( *(_QWORD *)(init + 8) )
result = release_notifier_domain(*(_QWORD *)(init + 8), a1);
}
return result;
}

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

result = init;
if ( init )
{
if ( *(_QWORD *)(init + 8) )
result = release_notifier_domain(*(_QWORD *)(init + 8), a1);
}
return result;
}

original_code:
void qsa_release_domain(notifier_domain_t *domain)
{
 if (init)
  if (init->dm) release_notifier_domain(init->dm, domain);
}

canonical_original_code:
void qsa_release_domain(struct _notifier_domain_t *domain)
{
 if (init)
  if (init->dm) release_notifier_domain(init->dm, domain);
}

user_defined_types: struct _qsa_content_type_t { struct _qsa_content_type_t *next; struct _str name; void (*destroy_func)(void *); char buf[1]; }

user_defined_types: struct _qsa_subscription_params_t { struct _str name; struct _str value; char buf[1]; }

user_defined_types: struct reference_counter_data_t { int cntr; struct atomic_t *mutex; }

user_defined_types: struct _mq_message_t { void *data; int data_len; struct _mq_message_t *next; void (*destroy_function)(void *); enum { message_allocated_with_data=0, message_holding_data_ptr=1 } allocation_style; char data_buf[1]; }


decompiled_code:
_DWORD *prof_handler()
{
_DWORD *result; // rax

result = tick_counter;
++tick_counter[0];
return result;
}

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

result = tick_counter;
++tick_counter[0];
return result;
}

original_code:
void prof_handler(int a, siginfo_t *info, void *b)
{
 tick_counter++;
}

canonical_original_code:
void prof_handler(int a, struct siginfo_t *info, void *b)
{
 tick_counter++;
}

variable_types: a int

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

variable_types:
b
void *

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


decompiled_code:
void trace_handler()
{
if ( trace_function )
trace_function();
}

canonical_decompiled_code:
void func1()
{
if ( trace_function )
trace_function();
}

original_code:
void trace_handler(int a)
{
 if (trace_function) trace_function();
}


decompiled_code:
int reset_timer()
{
struct itimerval v1; // [rsp+0h] [rbp-28h] BYREF

v1.it_interval.tv_sec = 0LL;
v1.it_interval.tv_usec = 1000LL;
v1.it_value.tv_sec = 0LL;
v1.it_value.tv_usec = 1000LL;
return setitimer(ITIMER_PROF, &v1, 0LL);
}

canonical_decompiled_code:
int func2()
{
struct itimerval v1; // [rsp+0h] [rbp-28h] BYREF

v1.it_interval.tv_sec = 0LL;
v1.it_interval.tv_usec = 1000LL;
v1.it_value.tv_sec = 0LL;
v1.it_value.tv_usec = 1000LL;
return setitimer(ITIMER_PROF, &v1, 0LL);
}

original_code:
int reset_timer()
{
 struct itimerval tv;
 int res;
 tv.it_interval.tv_sec = 0;
 tv.it_interval.tv_usec = 1000;
 tv.it_value.tv_sec = tv.it_interval.tv_sec;
 tv.it_value.tv_usec = tv.it_interval.tv_usec;
 res = setitimer(ITIMER_PROF, &tv, ((void *)0));
 return res;
}

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


decompiled_code:
int __fastcall start_profile(__int64 (*a1)(void))
{
int result; // eax
int v2; // er8
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

result = 1;
if ( !initialized )
{
initialized = 1;
trace_function = a1;
memset(&v3.sa_mask, 0, 0x90uLL);
v3.sa_handler = (__sighandler_t)prof_handler;
sigemptyset(&v3.sa_mask);
v3.sa_flags = 4;
v2 = sigaction(27, &v3, &old_sigprof_action);
result = -1;
if ( !v2 )
{
old_sigx_action = signal(5, (__sighandler_t)trace_handler);
result = reset_timer();
if ( result )
{
signal(5, old_sigx_action);
sigaction(27, &old_sigprof_action, 0LL);
result = -1;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 (*a1)(void))
{
int result; // eax
int v2; // er8
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

result = 1;
if ( !initialized )
{
initialized = 1;
trace_function = a1;
memset(&v3.sa_mask, 0, 0x90uLL);
v3.sa_handler = (__sighandler_t)prof_handler;
sigemptyset(&v3.sa_mask);
v3.sa_flags = 4;
v2 = sigaction(27, &v3, &old_sigprof_action);
result = -1;
if ( !v2 )
{
old_sigx_action = signal(5, (__sighandler_t)trace_handler);
result = func2();
if ( result )
{
signal(5, old_sigx_action);
sigaction(27, &old_sigprof_action, 0LL);
result = -1;
}
}
}
return result;
}

original_code:
int start_profile(trace_f tf)
{
 struct sigaction action;
 int res;
 if (initialized) return 1;
 initialized = 1;
 trace_function = tf;
 memset(&action, 0, sizeof(action));
 action.__sigaction_handler.sa_sigaction = prof_handler;
    sigemptyset(&action.sa_mask);
 action.sa_flags = 4;
 res = sigaction(27, &action, &old_sigprof_action);
 if (res != 0) {
  return -1;
 }
 old_sigx_action = signal(5, &trace_handler);
 res = reset_timer();
 if (res != 0) {
  signal(5, old_sigx_action);
  sigaction(27, &old_sigprof_action, ((void *)0));
  return -1;
 }
 return 0;
}

canonical_original_code:
int start_profile(void (*tf)())
{
 struct sigaction action;
 int res;
 if (initialized) return 1;
 initialized = 1;
 trace_function = tf;
 memset(&action, 0, sizeof(action));
 action.__sigaction_handler.sa_sigaction = prof_handler;
    sigemptyset(&action.sa_mask);
 action.sa_flags = 4;
 res = sigaction(27, &action, &old_sigprof_action);
 if (res != 0) {
  return -1;
 }
 old_sigx_action = signal(5, &trace_handler);
 res = reset_timer();
 if (res != 0) {
  signal(5, old_sigx_action);
  sigaction(27, &old_sigprof_action, ((void *)0));
  return -1;
 }
 return 0;
}

variable_types:
tf
void (*)()

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

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


decompiled_code:
int stop_profile()
{
if ( !initialized )
return -1;
initialized = 0;
signal(5, old_sigx_action);
return sigaction(27, &old_sigprof_action, 0LL);
}

canonical_decompiled_code:
int func4()
{
if ( !initialized )
return -1;
initialized = 0;
signal(5, old_sigx_action);
return sigaction(27, &old_sigprof_action, 0LL);
}

original_code:
int stop_profile()
{
 if (initialized) {
  initialized = 0;
  signal(5, old_sigx_action);
  return sigaction(27, &old_sigprof_action, ((void *)0));
 }
 else return -1;
}


original_code:
static int match_ip_and_port(int *ipOne, int *ipArray, int sizeOf_ipArray)
{
 int curIPAddrIdx;
 int curOctetIdx;
 int ipArrayIndex;
 for (curIPAddrIdx = 0; curIPAddrIdx < sizeOf_ipArray; curIPAddrIdx++) {
  for (curOctetIdx = 0; curOctetIdx < 4 + 1; curOctetIdx++) {
   ipArrayIndex =
    curIPAddrIdx * (4 + 1) + curOctetIdx;
   if (ipOne[curOctetIdx] != ipArray[ipArrayIndex]) {
    break;
   }
  }
  if (curOctetIdx == 4 + 1) {
   return 1;
  }
 }
 return 0;
}

variable_types:
ipOne
int *

variable_types:
ipArray
int *

variable_types: curIPAddrIdx int

variable_types: curOctetIdx int

variable_types: ipArrayIndex int


decompiled_code:
__int64 __fastcall get_stat(__int64 a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-28h] BYREF
int v3; // [rsp+8h] [rbp-20h]
unsigned __int16 v4[5]; // [rsp+1Eh] [rbp-Ah] BYREF

v2 = 0LL;
v3 = 0;
if ( (int)counter_lookup_str(v4, &v2, a1) < 0 )
result = 0LL;
else
result = v4[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-28h] BYREF
int v3; // [rsp+8h] [rbp-20h]
unsigned __int16 v4[5]; // [rsp+1Eh] [rbp-Ah] BYREF

v2 = 0LL;
v3 = 0;
if ( (int)counter_lookup_str(v4, &v2, a1) < 0 )
result = 0LL;
else
result = v4[0];
return result;
}

original_code:
inline static stat_var* get_stat(str *name)
{
 counter_handle_t h;
 str grp;
 grp.s = 0;
 grp.len = 0;
 if (counter_lookup_str(&h, &grp, name) < 0)
  return 0;
 return (void*)(unsigned long)h.id;
}

canonical_original_code:
inline static void *get_stat(struct _str *name)
{
 struct counter_handle_s h;
 struct _str grp;
 grp.s = 0;
 grp.len = 0;
 if (counter_lookup_str(&h, &grp, name) < 0)
  return 0;
 return (void *)(unsigned long)h.id;
}

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

variable_types: struct counter_handle_s { unsigned short id; }

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


decompiled_code:
__int64 __fastcall parse_proc_net_line(char *a1, _DWORD *a2, _DWORD *a3)
{
char *v4; // rbx
char *v5; // rax
char *v6; // r15
int v7; // eax
int v9[4]; // [rsp+0h] [rbp-58h] BYREF
char v10; // [rsp+10h] [rbp-48h] BYREF
char *endptr; // [rsp+18h] [rbp-40h] BYREF

v4 = (char *)v9;
while ( 1 )
{
v5 = strchr(a1, 58);
if ( !v5 )
return 0LL;
v6 = v5 + 1;
*(_DWORD *)v4 = strtol(v5 + 1, &endptr, 16);
a1 = endptr;
if ( endptr == v6 )
break;
v4 += 4;
if ( v4 == &v10 )
{
v7 = v9[0];
*a2 = LOBYTE(v9[0]);
a2[1] = BYTE1(v7);
a2[2] = BYTE2(v7);
a2[3] = v7 >> 24;
a2[4] = v9[1];
*a3 = v9[3];
return 1LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, _DWORD *a2, _DWORD *a3)
{
char *v4; // rbx
char *v5; // rax
char *v6; // r15
int v7; // eax
int v9[4]; // [rsp+0h] [rbp-58h] BYREF
char v10; // [rsp+10h] [rbp-48h] BYREF
char *endptr; // [rsp+18h] [rbp-40h] BYREF

v4 = (char *)v9;
while ( 1 )
{
v5 = strchr(a1, 58);
if ( !v5 )
return 0LL;
v6 = v5 + 1;
*(_DWORD *)v4 = strtol(v5 + 1, &endptr, 16);
a1 = endptr;
if ( endptr == v6 )
break;
v4 += 4;
if ( v4 == &v10 )
{
v7 = v9[0];
*a2 = LOBYTE(v9[0]);
a2[1] = BYTE1(v7);
a2[2] = BYTE2(v7);
a2[3] = v7 >> 24;
a2[4] = v9[1];
*a3 = v9[3];
return 1LL;
}
}
return 0LL;
}

original_code:
static int parse_proc_net_line(char *line, int *ipAddress, int *rx_queue)
{
 int i;
 int ipOctetExtractionMask = 0xFF;
 char *currColonLocation;
 char *nextNonNumericalChar;
 char *currentLocationInLine = line;
 int parsedInteger[4];
 for (i = 0; i < 4; i++) {
  currColonLocation = strchr(currentLocationInLine, ':');
  if (currColonLocation == ((void *)0)) {
   return 0;
  }
  parsedInteger[i] =
   (int) strtol(++currColonLocation, &nextNonNumericalChar,
     16);
  if (nextNonNumericalChar == currColonLocation) {
   return 0;
  }
  currentLocationInLine = nextNonNumericalChar;
 }
 for (i = 0; i < 4; i++) {
  ipAddress[i] =
   parsedInteger[0] & (ipOctetExtractionMask << i*8);
  ipAddress[i] >>= i*8;
 }
 ipAddress[4] = parsedInteger[1];
 *rx_queue = parsedInteger[3];
 return 1;
}

variable_types:
line
char *

variable_types:
ipAddress
int *

variable_types: i int

variable_types: ipOctetExtractionMask int

variable_types:
currColonLocation
char *

variable_types:
nextNonNumericalChar
char *

variable_types:
currentLocationInLine
char *

variable_types:
parsedInteger
int [4]


original_code:
stat_var *get_stat_var_from_num_code(unsigned int numerical_code, int out_codes)
{
 static char msg_code[(19+1+1+1)+4];
 str stat_name;
 stat_name.s = int2bstr( (unsigned long)numerical_code, msg_code,
  &stat_name.len);
 stat_name.s[stat_name.len++] = '_';
 if (out_codes) {
  stat_name.s[stat_name.len++] = 'o';
  stat_name.s[stat_name.len++] = 'u';
  stat_name.s[stat_name.len++] = 't';
 } else {
  stat_name.s[stat_name.len++] = 'i';
  stat_name.s[stat_name.len++] = 'n';
 }
 return get_stat(&stat_name);
}

canonical_original_code:
void *get_stat_var_from_num_code(unsigned int numerical_code, int out_codes)
{
 static char msg_code[-1];
 struct _str stat_name;
 stat_name.s = int2bstr( (unsigned long)numerical_code, msg_code,
  &stat_name.len);
 stat_name.s[stat_name.len++] = '_';
 if (out_codes) {
  stat_name.s[stat_name.len++] = 'o';
  stat_name.s[stat_name.len++] = 'u';
  stat_name.s[stat_name.len++] = 't';
 } else {
  stat_name.s[stat_name.len++] = 'i';
  stat_name.s[stat_name.len++] = 'n';
 }
 return get_stat(&stat_name);
}