decompiled_code:
__int64 __fastcall add_virtual_subscriptions_to_rlmi(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned int v4; // er14
_DWORD *v5; // r12
int v6; // er15
unsigned int v7; // ebp
const char *v8; // r13
unsigned int v9; // eax
unsigned int v10; // ebp
int v11; // [rsp+Ch] [rbp-8Ch]
char s[32]; // [rsp+20h] [rbp-78h] BYREF
char v14[16]; // [rsp+40h] [rbp-58h] BYREF
char v15[8]; // [rsp+50h] [rbp-48h] BYREF
int v16; // [rsp+58h] [rbp-40h]

result = *(unsigned int *)(a2 + 228);
v11 = result;
if ( (int)result > 0 )
{
v4 = 0;
do
{
result = ptr_vector_get(a2 + 224, v4);
v5 = (_DWORD *)result;
if ( result )
{
dstr_append_zt(a1, "\t<resource uri=\"");
dstr_append_str(a1, v5 + 38);
dstr_append_zt(a1, "\">\r\n");
v6 = v5[19];
if ( v6 > 0 )
{
v7 = 0;
if ( (v6 & 1) == 0 )
goto LABEL_45;
if ( !(unsigned int)vector_get(v5 + 18, 0LL, v14) )
{
if ( v16 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v15);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v14);
dstr_append_zt(a1, "</name>\r\n");
}
v7 = 1;
if ( v6 != 1 )
{
LABEL_45:
do
{
if ( !(unsigned int)vector_get(v5 + 18, v7, v14) )
{
if ( v16 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v15);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v14);
dstr_append_zt(a1, "</name>\r\n");
}
v10 = v7 + 1;
if ( !(unsigned int)vector_get(v5 + 18, v10, v14) )
{
if ( v16 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v15);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v14);
dstr_append_zt(a1, "</name>\r\n");
}
v7 = v10 + 1;
}
while ( v6 != v7 );
}
}
sprintf(s, "vs%di%d", v4, 1LL);
dstr_append_zt(a1, "\t\t<instance id=\"");
dstr_append_zt(a1, s);
dstr_append_zt(a1, "\" state=\"");
switch ( v5[36] )
{
case 0:
dstr_append_zt(a1, "pending\"");
if ( (int)get_debug_level("rls", 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v8 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): generating RLMI for an unitialized virtual subscription!\n",
process_no,
v9,
v8,
"rls [rlmi_doc.c:67]: ",
"add_virtual_subscriptions_to_rlmi");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): generating RLMI for an unitialized virtual subscription!\n",
*((const char **)&log_level_info + 8),
"rls [rlmi_doc.c:67]: ",
"add_virtual_subscriptions_to_rlmi");
}
--dprint_crit;
}
break;
case 1:
dstr_append_zt(a1, "active\"");
break;
case 2:
dstr_append_zt(a1, "pending\"");
break;
case 3:
case 5:
dstr_append_zt(a1, "terminated\" reason=\"closed\"");
break;
case 4:
case 6:
dstr_append_zt(a1, "terminated\" reason=\"timeout\"");
break;
default:
break;
}
if ( (int)v5[30] <= 0 )
{
dstr_append_zt(a1, "/>\r\n");
}
else
{
sprintf(s, "%d", v4);
dstr_append_zt(a1, " cid=\"");
dstr_append_zt(a1, a3);
dstr_append_zt(a1, s);
dstr_append_zt(a1, "\"/>\r\n");
}
result = dstr_append_zt(a1, "\t</resource>\r\n");
}
++v4;
}
while ( v11 != v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned int v4; // er14
_DWORD *v5; // r12
int v6; // er15
unsigned int v7; // ebp
const char *v8; // r13
unsigned int v9; // eax
unsigned int v10; // ebp
int v11; // [rsp+Ch] [rbp-8Ch]
char s[32]; // [rsp+20h] [rbp-78h] BYREF
char v14[16]; // [rsp+40h] [rbp-58h] BYREF
char v15[8]; // [rsp+50h] [rbp-48h] BYREF
int v16; // [rsp+58h] [rbp-40h]

result = *(unsigned int *)(a2 + 228);
v11 = result;
if ( (int)result > 0 )
{
v4 = 0;
do
{
result = ptr_vector_get(a2 + 224, v4);
v5 = (_DWORD *)result;
if ( result )
{
dstr_append_zt(a1, "\t<resource uri=\"");
dstr_append_str(a1, v5 + 38);
dstr_append_zt(a1, "\">\r\n");
v6 = v5[19];
if ( v6 > 0 )
{
v7 = 0;
if ( (v6 & 1) == 0 )
goto LABEL_45;
if ( !(unsigned int)vector_get(v5 + 18, 0LL, v14) )
{
if ( v16 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v15);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v14);
dstr_append_zt(a1, "</name>\r\n");
}
v7 = 1;
if ( v6 != 1 )
{
LABEL_45:
do
{
if ( !(unsigned int)vector_get(v5 + 18, v7, v14) )
{
if ( v16 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v15);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v14);
dstr_append_zt(a1, "</name>\r\n");
}
v10 = v7 + 1;
if ( !(unsigned int)vector_get(v5 + 18, v10, v14) )
{
if ( v16 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v15);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v14);
dstr_append_zt(a1, "</name>\r\n");
}
v7 = v10 + 1;
}
while ( v6 != v7 );
}
}
sprintf(s, "vs%di%d", v4, 1LL);
dstr_append_zt(a1, "\t\t<instance id=\"");
dstr_append_zt(a1, s);
dstr_append_zt(a1, "\" state=\"");
switch ( v5[36] )
{
case 0:
dstr_append_zt(a1, "pending\"");
if ( (int)get_debug_level("rls", 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v8 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): generating RLMI for an unitialized virtual subscription!\n",
process_no,
v9,
v8,
"rls [rlmi_doc.c:67]: ",
"add_virtual_subscriptions_to_rlmi");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): generating RLMI for an unitialized virtual subscription!\n",
*((const char **)&log_level_info + 8),
"rls [rlmi_doc.c:67]: ",
"add_virtual_subscriptions_to_rlmi");
}
--dprint_crit;
}
break;
case 1:
dstr_append_zt(a1, "active\"");
break;
case 2:
dstr_append_zt(a1, "pending\"");
break;
case 3:
case 5:
dstr_append_zt(a1, "terminated\" reason=\"closed\"");
break;
case 4:
case 6:
dstr_append_zt(a1, "terminated\" reason=\"timeout\"");
break;
default:
break;
}
if ( (int)v5[30] <= 0 )
{
dstr_append_zt(a1, "/>\r\n");
}
else
{
sprintf(s, "%d", v4);
dstr_append_zt(a1, " cid=\"");
dstr_append_zt(a1, a3);
dstr_append_zt(a1, s);
dstr_append_zt(a1, "\"/>\r\n");
}
result = dstr_append_zt(a1, "\t</resource>\r\n");
}
++v4;
}
while ( v11 != v4 );
}
return result;
}

original_code:
static void add_virtual_subscriptions_to_rlmi(dstring_t *doc, rl_subscription_t *s, const char *part_id)
{
 int i, j, ncnt, cnt;
 virtual_subscription_t *vs;
 vs_display_name_t dn;
 char tmp[32];
 cnt = (&s->vs)->element_count;
 for (i = 0; i < cnt; i++) {
  vs = ptr_vector_get(&s->vs, i);
  if (!vs) continue;
  dstr_append_zt(doc, "\t<resource uri=\"");
  dstr_append_str(doc, &vs->uri);
  dstr_append_zt(doc, "\">\r\n");
  ncnt = (&vs->display_names)->element_count;
  for (j = 0; j < ncnt; j++) {
   if (vector_get(&vs->display_names, j, &dn) != 0) continue;
   if (dn.lang.len > 0) {
    dstr_append_zt(doc, "\t\t<name language=\"");
    dstr_append_str(doc, &dn.lang);
    dstr_append_zt(doc, "\">");
   }
   else dstr_append_zt(doc, "\t\t<name>");
   dstr_append_str(doc, &dn.name);
   dstr_append_zt(doc, "</name>\r\n");
  }
  sprintf(tmp, "vs%di%d", i, 1);
  dstr_append_zt(doc, "\t\t<instance id=\"");
  dstr_append_zt(doc, tmp);
  dstr_append_zt(doc, "\" state=\"");
  switch (vs->status) {
   case subscription_active:
     dstr_append_zt(doc, "active\"");
     break;
   case subscription_pending:
     dstr_append_zt(doc, "pending\"");
     break;
   case subscription_terminated_pending:
   case subscription_terminated:
     dstr_append_zt(doc, "terminated\" reason=\"closed\"");
     break;
   case subscription_terminated_pending_to:
   case subscription_terminated_to:
     dstr_append_zt(doc,
      "terminated\" reason=\"timeout\"");
     break;
   case subscription_uninitialized:
     dstr_append_zt(doc, "pending\"");
     do { if (get_debug_level("rls", (sizeof("rls")-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(): " "generating RLMI for an unitialized virtual subscription!\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __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(): " "generating RLMI for an unitialized virtual subscription!\n", (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", process_no, my_pid(), ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __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(): " "generating RLMI for an unitialized virtual subscription!\n", ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); } } (dprint_crit--); } } while(0);
     break;
  }
  if (vs->state_document.len > 0) {
   sprintf(tmp, "%d", i);
   dstr_append_zt(doc, " cid=\"");
   dstr_append_zt(doc, part_id);
   dstr_append_zt(doc, tmp);
   dstr_append_zt(doc, "\"/>\r\n");
  }
  else dstr_append_zt(doc, "/>\r\n");
  dstr_append_zt(doc, "\t</resource>\r\n");
 }
}

canonical_original_code:
static void add_virtual_subscriptions_to_rlmi(struct _dstring_t *doc, struct _rl_subscription_t *s, char *part_id)
{
 int i; int j; int ncnt; int cnt;
 struct _virtual_subscription_t *vs;
 struct vs_display_name_t dn;
 char tmp[32];
 cnt = (&s->vs)->element_count;
 for (i = 0; i < cnt; i++) {
  vs = ptr_vector_get(&s->vs, i);
  if (!vs) continue;
  dstr_append_zt(doc, "\t<resource uri=\"");
  dstr_append_str(doc, &vs->uri);
  dstr_append_zt(doc, "\">\r\n");
  ncnt = (&vs->display_names)->element_count;
  for (j = 0; j < ncnt; j++) {
   if (vector_get(&vs->display_names, j, &dn) != 0) continue;
   if (dn.lang.len > 0) {
    dstr_append_zt(doc, "\t\t<name language=\"");
    dstr_append_str(doc, &dn.lang);
    dstr_append_zt(doc, "\">");
   }
   else dstr_append_zt(doc, "\t\t<name>");
   dstr_append_str(doc, &dn.name);
   dstr_append_zt(doc, "</name>\r\n");
  }
  sprintf(tmp, "vs%di%d", i, 1);
  dstr_append_zt(doc, "\t\t<instance id=\"");
  dstr_append_zt(doc, tmp);
  dstr_append_zt(doc, "\" state=\"");
  switch (vs->status) {
   case subscription_active:
     dstr_append_zt(doc, "active\"");
     break;
   case subscription_pending:
     dstr_append_zt(doc, "pending\"");
     break;
   case subscription_terminated_pending:
   case subscription_terminated:
     dstr_append_zt(doc, "terminated\" reason=\"closed\"");
     break;
   case subscription_terminated_pending_to:
   case subscription_terminated_to:
     dstr_append_zt(doc,
      "terminated\" reason=\"timeout\"");
     break;
   case subscription_uninitialized:
     dstr_append_zt(doc, "pending\"");
     do { if (get_debug_level("rls", (sizeof("rls")-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(): " "generating RLMI for an unitialized virtual subscription!\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __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(): " "generating RLMI for an unitialized virtual subscription!\n", (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", process_no, my_pid(), ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __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(): " "generating RLMI for an unitialized virtual subscription!\n", ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); } } (dprint_crit--); } } while(0);
     break;
  }
  if (vs->state_document.len > 0) {
   sprintf(tmp, "%d", i);
   dstr_append_zt(doc, " cid=\"");
   dstr_append_zt(doc, part_id);
   dstr_append_zt(doc, tmp);
   dstr_append_zt(doc, "\"/>\r\n");
  }
  else dstr_append_zt(doc, "/>\r\n");
  dstr_append_zt(doc, "\t</resource>\r\n");
 }
}

variable_types: struct _dstring_t { struct _dstr_buff_t { int len; int used; struct _dstr_buff_t *next; char data[1]; } *first; struct _dstr_buff_t *last; int len; int buff_size; int error; } *

variable_types: struct _rl_subscription_t { enum rls_subscription_type_t { rls_internal_subscription=0, rls_external_subscription=1 } type; struct xcap_query_params_t { struct _str { char *s; int len; } xcap_root; struct _str auth_user; struct _str auth_pass; int enable_unverified_ssl_peer; } xcap_params; union { struct _subscription_data_t { struct _time_event_data_t { unsigned int tick_time; void (*cb)(struct _time_event_data_t *s); void *cb_param; void *cb_param1; struct _time_event_data_t *next; struct _time_event_data_t *prev; } expiration; struct dlg { struct dlg_id { struct _str call_id; struct _str rem_tag; struct _str loc_tag; } id; struct dlg_seq { unsigned int value; unsigned char is_set; } loc_seq; struct dlg_seq rem_seq; struct _str loc_uri; struct _str rem_uri; struct _str rem_target; struct _str dst_uri; struct _str loc_dname; struct _str rem_dname; unsigned char secure; enum dlg_state { DLG_NEW=0, DLG_EARLY=1, DLG_CONFIRMED=2, DLG_DESTROYED=3 } state; struct rr { struct name_addr { struct _str name; struct _str uri; int len; } nameaddr; struct param { enum ptype { P_OTHER=0, P_Q=1, P_EXPIRES=2, P_METHODS=3, P_RECEIVED=4, P_TRANSPORT=5, P_LR=6, P_R2=7, P_MADDR=8, P_TTL=9, P_DSTIP=10, P_DSTPORT=11, P_INSTANCE=12, P_REG_ID=13, P_FTAG=14, P_CALL_ID=15, P_FROM_TAG=16, P_TO_TAG=17, P_ISD=18, P_SLA=19, P_MA=20, P_OB=21 } type; struct _str name; struct _str body; int len; struct param *next; } *r2; struct param *params; int len; struct rr *next; } *route_set; struct dlg_hooks { struct _str ru; struct _str nh; struct _str *request_uri; struct _str *next_hop; struct rr *first_route; struct _str *last_route; } hooks; struct socket_info { int socket; struct _str name; struct ip_addr { unsigned int af; unsigned int len; union { unsigned long addrl[-1]; unsigned int addr32[4]; unsigned short addr16[8]; unsigned char addr[16]; } u; } address; struct _str address_str; struct _str port_no_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } s; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } sin6; } su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; } *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info { struct _str name; unsigned short port_no; struct _str port_no_str; struct _str address_str; struct ip_addr address; struct _str sock_str; } useinfo; } *send_sock; } *dialog; void *usr_data; enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 } status; struct _subscription_data_t *next; struct _subscription_data_t *prev; struct _str contact; struct _str record_id; struct _str package; struct _str subscriber; } external; struct internal_subscription_data_t { struct _str *package; struct _str *record_id; struct _str *subscriber_id; struct _virtual_subscription_t { struct _qsa_subscription_data_t { struct msg_queue { struct reference_counter_data_t { int cntr; struct atomic_t { int val; } *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; } local_subscription_pres_data; struct _qsa_subscription_t { struct atomic_t *mutex; struct _notifier_package_t { struct _str name; 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 { 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; } *domain; 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; } *first_notifier; struct _qsa_subscription_t *first_subscription; struct _notifier_package_t *next; } *package; int allow_notifications; struct _qsa_subscription_data_t *data; struct _qsa_subscription_t *prev; struct reference_counter_data_t ref; } *local_subscription_pres; struct _rl_subscription_t *local_subscription_list; struct vector_t { int element_size; int element_count; int allocated_count; int allocation_count; void *data; } display_names; struct _rl_subscription_t *subscription; int changed; struct _str state_document; struct _str content_type; enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 } status; struct _str uri; struct _virtual_subscription_t *next; struct _virtual_subscription_t *prev; char dbid[48]; char uri_str[1]; } *vs; } internal; } u; int doc_version; int changed; struct vector_t vs; struct _str from_uid; char dbid[48]; } *

variable_types: i int

variable_types: j int

variable_types: ncnt int

variable_types: cnt int

variable_types: struct _virtual_subscription_t { struct _qsa_subscription_data_t { struct msg_queue { struct reference_counter_data_t { int cntr; struct atomic_t { int val; } *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 { char *s; int len; } 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; } local_subscription_pres_data; struct _qsa_subscription_t { struct atomic_t *mutex; struct _notifier_package_t { struct _str name; 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 { 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; } *domain; 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; } *first_notifier; struct _qsa_subscription_t *first_subscription; struct _notifier_package_t *next; } *package; int allow_notifications; struct _qsa_subscription_data_t *data; struct _qsa_subscription_t *prev; struct reference_counter_data_t ref; } *local_subscription_pres; struct _rl_subscription_t { enum rls_subscription_type_t { rls_internal_subscription=0, rls_external_subscription=1 } type; struct xcap_query_params_t { struct _str xcap_root; struct _str auth_user; struct _str auth_pass; int enable_unverified_ssl_peer; } xcap_params; union { struct _subscription_data_t { struct _time_event_data_t { unsigned int tick_time; void (*cb)(struct _time_event_data_t *s); void *cb_param; void *cb_param1; struct _time_event_data_t *next; struct _time_event_data_t *prev; } expiration; struct dlg { struct dlg_id { struct _str call_id; struct _str rem_tag; struct _str loc_tag; } id; struct dlg_seq { unsigned int value; unsigned char is_set; } loc_seq; struct dlg_seq rem_seq; struct _str loc_uri; struct _str rem_uri; struct _str rem_target; struct _str dst_uri; struct _str loc_dname; struct _str rem_dname; unsigned char secure; enum dlg_state { DLG_NEW=0, DLG_EARLY=1, DLG_CONFIRMED=2, DLG_DESTROYED=3 } state; struct rr { struct name_addr { struct _str name; struct _str uri; int len; } nameaddr; struct param { enum ptype { P_OTHER=0, P_Q=1, P_EXPIRES=2, P_METHODS=3, P_RECEIVED=4, P_TRANSPORT=5, P_LR=6, P_R2=7, P_MADDR=8, P_TTL=9, P_DSTIP=10, P_DSTPORT=11, P_INSTANCE=12, P_REG_ID=13, P_FTAG=14, P_CALL_ID=15, P_FROM_TAG=16, P_TO_TAG=17, P_ISD=18, P_SLA=19, P_MA=20, P_OB=21 } type; struct _str name; struct _str body; int len; struct param *next; } *r2; struct param *params; int len; struct rr *next; } *route_set; struct dlg_hooks { struct _str ru; struct _str nh; struct _str *request_uri; struct _str *next_hop; struct rr *first_route; struct _str *last_route; } hooks; struct socket_info { int socket; struct _str name; struct ip_addr { unsigned int af; unsigned int len; union { unsigned long addrl[-1]; unsigned int addr32[4]; unsigned short addr16[8]; unsigned char addr[16]; } u; } address; struct _str address_str; struct _str port_no_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } s; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } sin6; } su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; } *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info { struct _str name; unsigned short port_no; struct _str port_no_str; struct _str address_str; struct ip_addr address; struct _str sock_str; } useinfo; } *send_sock; } *dialog; void *usr_data; enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 } status; struct _subscription_data_t *next; struct _subscription_data_t *prev; struct _str contact; struct _str record_id; struct _str package; struct _str subscriber; } external; struct internal_subscription_data_t { struct _str *package; struct _str *record_id; struct _str *subscriber_id; struct _virtual_subscription_t *vs; } internal; } u; int doc_version; int changed; struct vector_t { int element_size; int element_count; int allocated_count; int allocation_count; void *data; } vs; struct _str from_uid; char dbid[48]; } *local_subscription_list; struct vector_t display_names; struct _rl_subscription_t *subscription; int changed; struct _str state_document; struct _str content_type; enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 } status; struct _str uri; struct _virtual_subscription_t *next; struct _virtual_subscription_t *prev; char dbid[48]; char uri_str[1]; } *

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

variable_types:
tmp
char [32]

user_defined_types: struct vs_display_name_t { struct _str name; struct _str lang; }

user_defined_types: struct _dstring_t { struct _dstr_buff_t *first; struct _dstr_buff_t *last; int len; int buff_size; int error; }

user_defined_types: struct _rl_subscription_t { enum rls_subscription_type_t type; struct xcap_query_params_t xcap_params; union { struct _subscription_data_t external; struct internal_subscription_data_t internal; } u; int doc_version; int changed; struct vector_t vs; struct _str from_uid; char dbid[48]; }

user_defined_types: struct _virtual_subscription_t { struct _qsa_subscription_data_t local_subscription_pres_data; struct _qsa_subscription_t *local_subscription_pres; struct _rl_subscription_t *local_subscription_list; struct vector_t display_names; struct _rl_subscription_t *subscription; int changed; struct _str state_document; struct _str content_type; enum subscription_status_t status; struct _str uri; struct _virtual_subscription_t *next; struct _virtual_subscription_t *prev; char dbid[48]; char uri_str[1]; }

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

user_defined_types: struct _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 _subscription_data_t { struct _time_event_data_t expiration; struct dlg *dialog; void *usr_data; enum subscription_status_t status; struct _subscription_data_t *next; struct _subscription_data_t *prev; struct _str contact; struct _str record_id; struct _str package; struct _str subscriber; }

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 dlg { struct dlg_id id; struct dlg_seq loc_seq; struct dlg_seq rem_seq; struct _str loc_uri; struct _str rem_uri; struct _str rem_target; struct _str dst_uri; struct _str loc_dname; struct _str rem_dname; unsigned char secure; enum dlg_state state; struct rr *route_set; struct dlg_hooks hooks; struct socket_info *send_sock; }

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 rr { struct name_addr nameaddr; struct param *r2; struct param *params; int len; struct rr *next; }

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

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

user_defined_types: struct param { enum ptype type; struct _str name; struct _str body; int len; struct param *next; }

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

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

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


repo: virtualolson/who

decompiled_code:
void __fastcall add_virtual_subscriptions_documents(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // er15
unsigned int i; // er12
__int64 v6; // rax
__int64 v7; // rbx
const char *v8; // r14
unsigned int v9; // eax
char s[88]; // [rsp+10h] [rbp-58h] BYREF

v4 = *(_DWORD *)(a2 + 228);
if ( v4 > 0 )
{
for ( i = 0; i != v4; ++i )
{
v6 = ptr_vector_get(a2 + 224, i);
v7 = v6;
if ( v6 && *(int *)(v6 + 120) > 0 )
{
if ( *(int *)(v6 + 136) <= 0 )
{
if ( (int)get_debug_level("rls", 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v8 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): can't send resource status document for unknown type\n",
process_no,
v9,
v8,
"rls [rlmi_doc.c:102]: ",
"add_virtual_subscriptions_documents");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): can't send resource status document for unknown type\n",
*((const char **)&log_level_info + 8),
"rls [rlmi_doc.c:102]: ",
"add_virtual_subscriptions_documents");
}
--dprint_crit;
}
}
else
{
dstr_append(a1, "--", 2LL);
dstr_append_zt(a1, a3);
dstr_append(a1, "\r\n", 2LL);
sprintf(s, "%d", i);
dstr_append_zt(a1, "Content-Transfer-Encoding: binary\r\nContent-ID: ");
dstr_append_zt(a1, a4);
dstr_append_zt(a1, s);
dstr_append_zt(a1, "\r\nContent-Type: ");
dstr_append_str(a1, v7 + 128);
dstr_append_zt(a1, "\r\n\r\n");
dstr_append_str(a1, v7 + 112);
dstr_append(a1, "\r\n", 2LL);
dstr_append(a1, "\r\n", 2LL);
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // er15
unsigned int i; // er12
__int64 v6; // rax
__int64 v7; // rbx
const char *v8; // r14
unsigned int v9; // eax
char s[88]; // [rsp+10h] [rbp-58h] BYREF

v4 = *(_DWORD *)(a2 + 228);
if ( v4 > 0 )
{
for ( i = 0; i != v4; ++i )
{
v6 = ptr_vector_get(a2 + 224, i);
v7 = v6;
if ( v6 && *(int *)(v6 + 120) > 0 )
{
if ( *(int *)(v6 + 136) <= 0 )
{
if ( (int)get_debug_level("rls", 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v8 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): can't send resource status document for unknown type\n",
process_no,
v9,
v8,
"rls [rlmi_doc.c:102]: ",
"add_virtual_subscriptions_documents");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): can't send resource status document for unknown type\n",
*((const char **)&log_level_info + 8),
"rls [rlmi_doc.c:102]: ",
"add_virtual_subscriptions_documents");
}
--dprint_crit;
}
}
else
{
dstr_append(a1, "--", 2LL);
dstr_append_zt(a1, a3);
dstr_append(a1, "\r\n", 2LL);
sprintf(s, "%d", i);
dstr_append_zt(a1, "Content-Transfer-Encoding: binary\r\nContent-ID: ");
dstr_append_zt(a1, a4);
dstr_append_zt(a1, s);
dstr_append_zt(a1, "\r\nContent-Type: ");
dstr_append_str(a1, v7 + 128);
dstr_append_zt(a1, "\r\n\r\n");
dstr_append_str(a1, v7 + 112);
dstr_append(a1, "\r\n", 2LL);
dstr_append(a1, "\r\n", 2LL);
}
}
}
}
}

original_code:
static void add_virtual_subscriptions_documents(dstring_t *doc,
  rl_subscription_t *s, const char *boundary_str, const char *part_id)
{
 int i, cnt;
 virtual_subscription_t *vs;
 char tmp[32];
 cnt = (&s->vs)->element_count;
 for (i = 0; i < cnt; i++) {
  vs = ptr_vector_get(&s->vs, i);
  if (!vs) continue;
  if (vs->state_document.len < 1) {
   vs = vs->next;
   continue;
  }
  if (vs->content_type.len < 1) {
   do { if (get_debug_level("rls", (sizeof("rls")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "can't send resource status document for unknown type\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "can't send resource status document for unknown type\n", (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "can't send resource status document for unknown type\n", process_no, my_pid(), ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't send resource status document for unknown type\n", ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't send resource status document for unknown type\n", ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   vs = vs->next;
   continue;
  }
  dstr_append(doc, "--", 2);
  dstr_append_zt(doc, boundary_str);
  dstr_append(doc, "\r\n", 2);
  sprintf(tmp, "%d", i);
  dstr_append_zt(doc, "Content-Transfer-Encoding: binary\r\nContent-ID: ");
  dstr_append_zt(doc, part_id);
  dstr_append_zt(doc, tmp);
  dstr_append_zt(doc, "\r\nContent-Type: ");
  dstr_append_str(doc, &vs->content_type);
  dstr_append_zt(doc, "\r\n\r\n");
  dstr_append_str(doc, &vs->state_document);
  dstr_append(doc, "\r\n", 2);
  dstr_append(doc, "\r\n", 2);
 }
}

canonical_original_code:
static void add_virtual_subscriptions_documents(struct _dstring_t *doc, struct _rl_subscription_t *s, char *boundary_str, char *part_id)
{
 int i; int cnt;
 struct _virtual_subscription_t *vs;
 char tmp[32];
 cnt = (&s->vs)->element_count;
 for (i = 0; i < cnt; i++) {
  vs = ptr_vector_get(&s->vs, i);
  if (!vs) continue;
  if (vs->state_document.len < 1) {
   vs = vs->next;
   continue;
  }
  if (vs->content_type.len < 1) {
   do { if (get_debug_level("rls", (sizeof("rls")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "can't send resource status document for unknown type\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "can't send resource status document for unknown type\n", (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "can't send resource status document for unknown type\n", process_no, my_pid(), ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't send resource status document for unknown type\n", ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't send resource status document for unknown type\n", ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   vs = vs->next;
   continue;
  }
  dstr_append(doc, "--", 2);
  dstr_append_zt(doc, boundary_str);
  dstr_append(doc, "\r\n", 2);
  sprintf(tmp, "%d", i);
  dstr_append_zt(doc, "Content-Transfer-Encoding: binary\r\nContent-ID: ");
  dstr_append_zt(doc, part_id);
  dstr_append_zt(doc, tmp);
  dstr_append_zt(doc, "\r\nContent-Type: ");
  dstr_append_str(doc, &vs->content_type);
  dstr_append_zt(doc, "\r\n\r\n");
  dstr_append_str(doc, &vs->state_document);
  dstr_append(doc, "\r\n", 2);
  dstr_append(doc, "\r\n", 2);
 }
}

return_type: void

user_defined_types: struct _dstring_t { struct _dstr_buff_t *first; struct _dstr_buff_t *last; int len; int buff_size; int error; }

user_defined_types: enum rls_subscription_type_t { rls_internal_subscription=0, rls_external_subscription=1 }

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

user_defined_types: enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 }

user_defined_types: struct _dstr_buff_t { int len; int used; struct _dstr_buff_t *next; char data[1]; }

user_defined_types: struct internal_subscription_data_t { struct _str *package; struct _str *record_id; struct _str *subscriber_id; struct _virtual_subscription_t *vs; }

user_defined_types: struct _time_event_data_t { unsigned int tick_time; void (*cb)(struct _time_event_data_t *s); void *cb_param; void *cb_param1; struct _time_event_data_t *next; struct _time_event_data_t *prev; }

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

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

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_data_t { int cntr; struct atomic_t *mutex; }

user_defined_types: struct dlg_id { struct _str call_id; struct _str rem_tag; struct _str loc_tag; }

user_defined_types: struct dlg_seq { unsigned int value; unsigned char is_set; }

user_defined_types: enum dlg_state { DLG_NEW=0, DLG_EARLY=1, DLG_CONFIRMED=2, DLG_DESTROYED=3 }

user_defined_types: struct dlg_hooks { struct _str ru; struct _str nh; struct _str *request_uri; struct _str *next_hop; struct rr *first_route; struct _str *last_route; }

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

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 name_addr { struct _str name; struct _str uri; int len; }

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

user_defined_types: 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 }

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

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

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 reference_counter_group_t { int mutex_cnt; int mutex_to_assign; struct atomic_t mutexes[1]; }

user_defined_types: enum ptype { P_OTHER=0, P_Q=1, P_EXPIRES=2, P_METHODS=3, P_RECEIVED=4, P_TRANSPORT=5, P_LR=6, P_R2=7, P_MADDR=8, P_TTL=9, P_DSTIP=10, P_DSTPORT=11, P_INSTANCE=12, P_REG_ID=13, P_FTAG=14, P_CALL_ID=15, P_FROM_TAG=16, P_TO_TAG=17, P_ISD=18, P_SLA=19, P_MA=20, P_OB=21 }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
__int64 __fastcall create_rlmi_document(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // ebx
unsigned int v5; // eax
unsigned int v6; // er14
unsigned int v7; // eax
unsigned int v8; // er15
unsigned int v9; // eax
__int64 v10; // rax
char v12[64]; // [rsp+10h] [rbp-158h] BYREF
char v13[64]; // [rsp+50h] [rbp-118h] BYREF
char s[64]; // [rsp+90h] [rbp-D8h] BYREF
char v15[32]; // [rsp+D0h] [rbp-98h] BYREF
char v16[32]; // [rsp+F0h] [rbp-78h] BYREF
char v17[88]; // [rsp+110h] [rbp-58h] BYREF

if ( a2 == 0 || a1 == 0 || !a3 )
return 0xFFFFFFFFLL;
v4 = rand();
v5 = rand();
sprintf(s, "qwW%dpPdxX%d", v5, v4);
v6 = rand();
v7 = rand();
sprintf(v13, "RewXdpxR%dxA%d", v7, v6);
v8 = rand();
v9 = rand();
sprintf(v12, "id%di%dx", v9, v8);
dstr_init(v17, 256LL);
dstr_append(v17, "--", 2LL);
dstr_append_zt(v17, v13);
dstr_append(v17, "\r\n", 2LL);
dstr_append_zt(v17, "Content-Transfer-Encoding: binary\r\nContent-ID: ");
dstr_append_zt(v17, s);
dstr_append_zt(v17, "\r\n");
dstr_append_zt(v17, "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n");
dstr_append(v17, "\r\n", 2LL);
dstr_append_zt(v17, "<?xml version=\"1.0\"?>\r\n<list xmlns=\"urn:ietf:params:xml:ns:rlmi\" uri=\"");
v10 = rls_get_uri(a3);
dstr_append_str(v17, v10);
dstr_append_zt(v17, "\" version=\"");
sprintf(v15, "%d", *(unsigned int *)(a3 + 216));
dstr_append_zt(v17, v15);
dstr_append_zt(v17, "\" fullState=\"true\">\r\n");
add_virtual_subscriptions_to_rlmi((__int64)v17, a3, (__int64)v12);
dstr_append_zt(v17, "</list>\r\n\r\n");
add_virtual_subscriptions_documents((__int64)v17, a3, (__int64)v13, (__int64)v12);
dstr_append(v17, "--", 2LL);
dstr_append_zt(v17, v13);
dstr_append(v17, "--\r\n", 4LL);
dstr_append(v17, "\r\n", 2LL);
dstr_init(v16, 256LL);
dstr_append_zt(v16, "multipart/related;type=\"application/rlmi+xml\";start=\"");
dstr_append_zt(v16, s);
dstr_append_zt(v16, "\";boundary=\"");
dstr_append_zt(v16, v13);
dstr_append_zt(v16, "\";");
dstr_get_str(v17, a1);
dstr_destroy(v17);
dstr_get_str(v16, a2);
dstr_destroy(v16);
++*(_DWORD *)(a3 + 216);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // ebx
unsigned int v5; // eax
unsigned int v6; // er14
unsigned int v7; // eax
unsigned int v8; // er15
unsigned int v9; // eax
__int64 v10; // rax
char v12[64]; // [rsp+10h] [rbp-158h] BYREF
char v13[64]; // [rsp+50h] [rbp-118h] BYREF
char s[64]; // [rsp+90h] [rbp-D8h] BYREF
char v15[32]; // [rsp+D0h] [rbp-98h] BYREF
char v16[32]; // [rsp+F0h] [rbp-78h] BYREF
char v17[88]; // [rsp+110h] [rbp-58h] BYREF

if ( a2 == 0 || a1 == 0 || !a3 )
return 0xFFFFFFFFLL;
v4 = rand();
v5 = rand();
sprintf(s, "qwW%dpPdxX%d", v5, v4);
v6 = rand();
v7 = rand();
sprintf(v13, "RewXdpxR%dxA%d", v7, v6);
v8 = rand();
v9 = rand();
sprintf(v12, "id%di%dx", v9, v8);
dstr_init(v17, 256LL);
dstr_append(v17, "--", 2LL);
dstr_append_zt(v17, v13);
dstr_append(v17, "\r\n", 2LL);
dstr_append_zt(v17, "Content-Transfer-Encoding: binary\r\nContent-ID: ");
dstr_append_zt(v17, s);
dstr_append_zt(v17, "\r\n");
dstr_append_zt(v17, "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n");
dstr_append(v17, "\r\n", 2LL);
dstr_append_zt(v17, "<?xml version=\"1.0\"?>\r\n<list xmlns=\"urn:ietf:params:xml:ns:rlmi\" uri=\"");
v10 = rls_get_uri(a3);
dstr_append_str(v17, v10);
dstr_append_zt(v17, "\" version=\"");
sprintf(v15, "%d", *(unsigned int *)(a3 + 216));
dstr_append_zt(v17, v15);
dstr_append_zt(v17, "\" fullState=\"true\">\r\n");
func0((__int64)v17, a3, (__int64)v12);
dstr_append_zt(v17, "</list>\r\n\r\n");
func1((__int64)v17, a3, (__int64)v13, (__int64)v12);
dstr_append(v17, "--", 2LL);
dstr_append_zt(v17, v13);
dstr_append(v17, "--\r\n", 4LL);
dstr_append(v17, "\r\n", 2LL);
dstr_init(v16, 256LL);
dstr_append_zt(v16, "multipart/related;type=\"application/rlmi+xml\";start=\"");
dstr_append_zt(v16, s);
dstr_append_zt(v16, "\";boundary=\"");
dstr_append_zt(v16, v13);
dstr_append_zt(v16, "\";");
dstr_get_str(v17, a1);
dstr_destroy(v17);
dstr_get_str(v16, a2);
dstr_destroy(v16);
++*(_DWORD *)(a3 + 216);
return 0LL;
}

original_code:
int create_rlmi_document(str *dst, str *content_type_dst, rl_subscription_t *s, int full_info)
{
 dstring_t doc, cont;
 char tmp[32];
 char start_str[64];
 char boundary_str[64];
 char part_id[64];
 if ((!s) || (!dst) || (!content_type_dst)) return (-1);
 sprintf(start_str, "qwW%dpPdxX%d", rand(), rand());
 sprintf(boundary_str, "RewXdpxR%dxA%d", rand(), rand());
 sprintf(part_id, "id%di%dx", rand(), rand());
 dstr_init(&doc, 256);
 dstr_append(&doc, "--", 2);
 dstr_append_zt(&doc, boundary_str);
 dstr_append(&doc, "\r\n", 2);
 dstr_append_zt(&doc,
   "Content-Transfer-Encoding: binary\r\n"
   "Content-ID: ");
 dstr_append_zt(&doc, start_str);
 dstr_append_zt(&doc, "\r\n");
 dstr_append_zt(&doc,
  "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n");
 dstr_append(&doc, "\r\n", 2);
 dstr_append_zt(&doc,
  "<?xml version=\"1.0\"?>\r\n"
  "<list xmlns=\"urn:ietf:params:xml:ns:rlmi\" "
  "uri=\"");
 dstr_append_str(&doc, rls_get_uri(s));
 dstr_append_zt(&doc, "\" version=\"");
 sprintf(tmp, "%d", s->doc_version);
 dstr_append_zt(&doc, tmp);
 dstr_append_zt(&doc, "\" fullState=\"true\">\r\n");
 add_virtual_subscriptions_to_rlmi(&doc, s, part_id);
 dstr_append_zt(&doc, "</list>\r\n\r\n");
 add_virtual_subscriptions_documents(&doc, s, boundary_str, part_id);
 dstr_append(&doc, "--", 2);
 dstr_append_zt(&doc, boundary_str);
 dstr_append(&doc, "--\r\n", 4);
 dstr_append(&doc, "\r\n", 2);
 dstr_init(&cont, 256);
 dstr_append_zt(&cont,
   "multipart/related;type=\"application/rlmi+xml\";"
   "start=\"");
 dstr_append_zt(&cont, start_str);
 dstr_append_zt(&cont, "\";boundary=\"");
 dstr_append_zt(&cont, boundary_str);
 dstr_append_zt(&cont, "\";");
 dstr_get_str(&doc, dst);
 dstr_destroy(&doc);
 dstr_get_str(&cont, content_type_dst);
 dstr_destroy(&cont);
 s->doc_version++;
 return 0;
}

canonical_original_code:
int create_rlmi_document(struct _str *dst, struct _str *content_type_dst, struct _rl_subscription_t *s, int full_info)
{
 struct _dstring_t doc; struct _dstring_t cont;
 char tmp[32];
 char start_str[64];
 char boundary_str[64];
 char part_id[64];
 if ((!s) || (!dst) || (!content_type_dst)) return (-1);
 sprintf(start_str, "qwW%dpPdxX%d", rand(), rand());
 sprintf(boundary_str, "RewXdpxR%dxA%d", rand(), rand());
 sprintf(part_id, "id%di%dx", rand(), rand());
 dstr_init(&doc, 256);
 dstr_append(&doc, "--", 2);
 dstr_append_zt(&doc, boundary_str);
 dstr_append(&doc, "\r\n", 2);
 dstr_append_zt(&doc,
   "Content-Transfer-Encoding: binary\r\n"
   "Content-ID: ");
 dstr_append_zt(&doc, start_str);
 dstr_append_zt(&doc, "\r\n");
 dstr_append_zt(&doc,
  "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n");
 dstr_append(&doc, "\r\n", 2);
 dstr_append_zt(&doc,
  "<?xml version=\"1.0\"?>\r\n"
  "<list xmlns=\"urn:ietf:params:xml:ns:rlmi\" "
  "uri=\"");
 dstr_append_str(&doc, rls_get_uri(s));
 dstr_append_zt(&doc, "\" version=\"");
 sprintf(tmp, "%d", s->doc_version);
 dstr_append_zt(&doc, tmp);
 dstr_append_zt(&doc, "\" fullState=\"true\">\r\n");
 add_virtual_subscriptions_to_rlmi(&doc, s, part_id);
 dstr_append_zt(&doc, "</list>\r\n\r\n");
 add_virtual_subscriptions_documents(&doc, s, boundary_str, part_id);
 dstr_append(&doc, "--", 2);
 dstr_append_zt(&doc, boundary_str);
 dstr_append(&doc, "--\r\n", 4);
 dstr_append(&doc, "\r\n", 2);
 dstr_init(&cont, 256);
 dstr_append_zt(&cont,
   "multipart/related;type=\"application/rlmi+xml\";"
   "start=\"");
 dstr_append_zt(&cont, start_str);
 dstr_append_zt(&cont, "\";boundary=\"");
 dstr_append_zt(&cont, boundary_str);
 dstr_append_zt(&cont, "\";");
 dstr_get_str(&doc, dst);
 dstr_destroy(&doc);
 dstr_get_str(&cont, content_type_dst);
 dstr_destroy(&cont);
 s->doc_version++;
 return 0;
}

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

variable_types: struct _rl_subscription_t { enum rls_subscription_type_t { rls_internal_subscription=0, rls_external_subscription=1 } type; struct xcap_query_params_t { struct _str xcap_root; struct _str auth_user; struct _str auth_pass; int enable_unverified_ssl_peer; } xcap_params; union { struct _subscription_data_t { struct _time_event_data_t { unsigned int tick_time; void (*cb)(struct _time_event_data_t *s); void *cb_param; void *cb_param1; struct _time_event_data_t *next; struct _time_event_data_t *prev; } expiration; struct dlg { struct dlg_id { struct _str call_id; struct _str rem_tag; struct _str loc_tag; } id; struct dlg_seq { unsigned int value; unsigned char is_set; } loc_seq; struct dlg_seq rem_seq; struct _str loc_uri; struct _str rem_uri; struct _str rem_target; struct _str dst_uri; struct _str loc_dname; struct _str rem_dname; unsigned char secure; enum dlg_state { DLG_NEW=0, DLG_EARLY=1, DLG_CONFIRMED=2, DLG_DESTROYED=3 } state; struct rr { struct name_addr { struct _str name; struct _str uri; int len; } nameaddr; struct param { enum ptype { P_OTHER=0, P_Q=1, P_EXPIRES=2, P_METHODS=3, P_RECEIVED=4, P_TRANSPORT=5, P_LR=6, P_R2=7, P_MADDR=8, P_TTL=9, P_DSTIP=10, P_DSTPORT=11, P_INSTANCE=12, P_REG_ID=13, P_FTAG=14, P_CALL_ID=15, P_FROM_TAG=16, P_TO_TAG=17, P_ISD=18, P_SLA=19, P_MA=20, P_OB=21 } type; struct _str name; struct _str body; int len; struct param *next; } *r2; struct param *params; int len; struct rr *next; } *route_set; struct dlg_hooks { struct _str ru; struct _str nh; struct _str *request_uri; struct _str *next_hop; struct rr *first_route; struct _str *last_route; } hooks; struct socket_info { int socket; struct _str name; struct ip_addr { unsigned int af; unsigned int len; union { unsigned long addrl[-1]; unsigned int addr32[4]; unsigned short addr16[8]; unsigned char addr[16]; } u; } address; struct _str address_str; struct _str port_no_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } s; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } sin6; } su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; } *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info { struct _str name; unsigned short port_no; struct _str port_no_str; struct _str address_str; struct ip_addr address; struct _str sock_str; } useinfo; } *send_sock; } *dialog; void *usr_data; enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 } status; struct _subscription_data_t *next; struct _subscription_data_t *prev; struct _str contact; struct _str record_id; struct _str package; struct _str subscriber; } external; struct internal_subscription_data_t { struct _str *package; struct _str *record_id; struct _str *subscriber_id; struct _virtual_subscription_t { struct _qsa_subscription_data_t { struct msg_queue { struct reference_counter_data_t { int cntr; struct atomic_t { int val; } *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; } local_subscription_pres_data; struct _qsa_subscription_t { struct atomic_t *mutex; struct _notifier_package_t { struct _str name; 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 { 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; } *domain; 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; } *first_notifier; struct _qsa_subscription_t *first_subscription; struct _notifier_package_t *next; } *package; int allow_notifications; struct _qsa_subscription_data_t *data; struct _qsa_subscription_t *prev; struct reference_counter_data_t ref; } *local_subscription_pres; struct _rl_subscription_t *local_subscription_list; struct vector_t { int element_size; int element_count; int allocated_count; int allocation_count; void *data; } display_names; struct _rl_subscription_t *subscription; int changed; struct _str state_document; struct _str content_type; enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 } status; struct _str uri; struct _virtual_subscription_t *next; struct _virtual_subscription_t *prev; char dbid[48]; char uri_str[1]; } *vs; } internal; } u; int doc_version; int changed; struct vector_t vs; struct _str from_uid; char dbid[48]; } *

variable_types: struct _dstring_t { struct _dstr_buff_t { int len; int used; struct _dstr_buff_t *next; char data[1]; } *first; struct _dstr_buff_t *last; int len; int buff_size; int error; }

return_type: int

user_defined_types: struct _dstring_t { struct _dstr_buff_t *first; struct _dstr_buff_t *last; int len; int buff_size; int error; }

user_defined_types: struct _rl_subscription_t { enum rls_subscription_type_t type; struct xcap_query_params_t xcap_params; union { struct _subscription_data_t external; struct internal_subscription_data_t internal; } u; int doc_version; int changed; struct vector_t vs; struct _str from_uid; char dbid[48]; }

user_defined_types: struct _subscription_data_t { struct _time_event_data_t expiration; struct dlg *dialog; void *usr_data; enum subscription_status_t status; struct _subscription_data_t *next; struct _subscription_data_t *prev; struct _str contact; struct _str record_id; struct _str package; struct _str subscriber; }

user_defined_types: struct internal_subscription_data_t { struct _str *package; struct _str *record_id; struct _str *subscriber_id; struct _virtual_subscription_t *vs; }

user_defined_types: struct dlg { struct dlg_id id; struct dlg_seq loc_seq; struct dlg_seq rem_seq; struct _str loc_uri; struct _str rem_uri; struct _str rem_target; struct _str dst_uri; struct _str loc_dname; struct _str rem_dname; unsigned char secure; enum dlg_state state; struct rr *route_set; struct dlg_hooks hooks; struct socket_info *send_sock; }

user_defined_types: struct _virtual_subscription_t { struct _qsa_subscription_data_t local_subscription_pres_data; struct _qsa_subscription_t *local_subscription_pres; struct _rl_subscription_t *local_subscription_list; struct vector_t display_names; struct _rl_subscription_t *subscription; int changed; struct _str state_document; struct _str content_type; enum subscription_status_t status; struct _str uri; struct _virtual_subscription_t *next; struct _virtual_subscription_t *prev; char dbid[48]; char uri_str[1]; }

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 rr { struct name_addr nameaddr; struct param *r2; struct param *params; int len; struct rr *next; }

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

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

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

user_defined_types: struct param { enum ptype type; struct _str name; struct _str body; int len; struct param *next; }

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

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

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

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


original_code:
char* parse_retry_after(char* const buf, const char* const end, unsigned* const after, int* const err)
{
 char *t;
 int i;
 unsigned val;
 val=0;
 t=buf;
 t=eat_lws_end(t, end);
 if (t>=end) goto error;
 for (i=0; t<end; i++,t++){
  if ((*t >= '0') && (*t <= '9')){
   val=val*10+(*t-'0');
  }else{
   switch(*t){
    case ' ':
    case '\t':
    case ';':
    case '\r':
    case '\n':
     goto found;
    default:
     goto error;
   }
  }
 }
 goto error_nocrlf;
found:
 if (i>10 || i==0)
  goto error;
 *after=val;
 for (; t<end; t++){
  if (*t=='\n'){
   if (((t+1)<end) && (*(t+1)=='\r'))
    t++;
   if (((t+1)<end) && (*(t+1)==' ' || *(t+1)=='\t')){
    t++;
    continue;
   }
   *err=0;
   return t+1;
  }
 }
error_nocrlf:
 do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "ERROR: parse_retry_after: strange EoHF\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "parser/parse_retry_after.c" ":" "88" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "ERROR: parse_retry_after: strange EoHF\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "parser/parse_retry_after.c" ":" "88" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR: parse_retry_after: strange EoHF\n", process_no, my_pid(), ("<core> [" "parser/parse_retry_after.c" ":" "88" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR: parse_retry_after: strange EoHF\n", ("<core> [" "parser/parse_retry_after.c" ":" "88" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR: parse_retry_after: strange EoHF\n", ("<core> [" "parser/parse_retry_after.c" ":" "88" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 goto error;
error:
 do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "ERROR: parse_retry_after: bad Retry-After header \n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "parser/parse_retry_after.c" ":" "91" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "ERROR: parse_retry_after: bad Retry-After header \n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "parser/parse_retry_after.c" ":" "91" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR: parse_retry_after: bad Retry-After header \n", process_no, my_pid(), ("<core> [" "parser/parse_retry_after.c" ":" "91" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR: parse_retry_after: bad Retry-After header \n", ("<core> [" "parser/parse_retry_after.c" ":" "91" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR: parse_retry_after: bad Retry-After header \n", ("<core> [" "parser/parse_retry_after.c" ":" "91" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 *err=1;
 return t;
}

canonical_original_code:
char *parse_retry_after(char *buf, char *end, unsigned int *after, int *err)
{
 char *t;
 int i;
 unsigned int val;
 val=0;
 t=buf;
 t=eat_lws_end(t, end);
 if (t>=end) goto error;
 for (i=0; t<end; i++,t++){
  if ((*t >= '0') && (*t <= '9')){
   val=val*10+(*t-'0');
  }else{
   switch(*t){
    case ' ':
    case '\t':
    case ';':
    case '\r':
    case '\n':
     goto found;
    default:
     goto error;
   }
  }
 }
 goto error_nocrlf;
found:
 if (i>10 || i==0)
  goto error;
 *after=val;
 for (; t<end; t++){
  if (*t=='\n'){
   if (((t+1)<end) && (*(t+1)=='\r'))
    t++;
   if (((t+1)<end) && (*(t+1)==' ' || *(t+1)=='\t')){
    t++;
    continue;
   }
   *err=0;
   return t+1;
  }
 }
error_nocrlf:
 do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "ERROR: parse_retry_after: strange EoHF\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "parser/parse_retry_after.c" ":" "88" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "ERROR: parse_retry_after: strange EoHF\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "parser/parse_retry_after.c" ":" "88" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR: parse_retry_after: strange EoHF\n", process_no, my_pid(), ("<core> [" "parser/parse_retry_after.c" ":" "88" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR: parse_retry_after: strange EoHF\n", ("<core> [" "parser/parse_retry_after.c" ":" "88" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR: parse_retry_after: strange EoHF\n", ("<core> [" "parser/parse_retry_after.c" ":" "88" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 goto error;
error:
 do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "ERROR: parse_retry_after: bad Retry-After header \n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "parser/parse_retry_after.c" ":" "91" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "ERROR: parse_retry_after: bad Retry-After header \n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "parser/parse_retry_after.c" ":" "91" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR: parse_retry_after: bad Retry-After header \n", process_no, my_pid(), ("<core> [" "parser/parse_retry_after.c" ":" "91" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR: parse_retry_after: bad Retry-After header \n", ("<core> [" "parser/parse_retry_after.c" ":" "91" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR: parse_retry_after: bad Retry-After header \n", ("<core> [" "parser/parse_retry_after.c" ":" "91" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 *err=1;
 return t;
}

variable_types:
buf
char *

variable_types:
end
char *

variable_types:
after
unsigned int *

variable_types:
err
int *

variable_types:
t
char *

variable_types:
val
unsigned int

return_type: char *

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


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

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

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

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

variable_types:
var
int *

variable_types: v int


decompiled_code:
__int64 get_first_socket()
{
__int64 result; // rax

result = udp_listen;
if ( !udp_listen )
{
result = tcp_listen;
if ( !tcp_listen )
result = tls_listen;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax

result = udp_listen;
if ( !udp_listen )
{
result = tcp_listen;
if ( !tcp_listen )
result = tls_listen;
}
return result;
}

original_code:
inline static struct socket_info* get_first_socket(void)
{
 if (udp_listen) return udp_listen;
 else if (tcp_listen) return tcp_listen;
 else if (tls_listen) return tls_listen;
 return 0;
}

canonical_original_code:
inline static struct socket_info *get_first_socket()
{
 if (udp_listen) return udp_listen;
 else if (tcp_listen) return tcp_listen;
 else if (tls_listen) return tls_listen;
 return 0;
}

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


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

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

original_code:
static int dlg_mod_child_init(int _rank)
{
 return 0;
}


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 func4(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 func5(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:
_QWORD *destroy_dialog_mutex()
{
_QWORD *result; // rax

result = dlg_mutex;
if ( dlg_mutex[0] )
{
futex_get(mem_lock);
qm_free(shm_block, dlg_mutex[0]);
result = (_QWORD *)futex_release(mem_lock);
}
return result;
}

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

result = dlg_mutex;
if ( dlg_mutex[0] )
{
func4(mem_lock);
qm_free(shm_block, dlg_mutex[0]);
result = (_QWORD *)func5(mem_lock);
}
return result;
}

original_code:
static void destroy_dialog_mutex()
{
 if (dlg_mutex) {
  ;
  do { futex_get(mem_lock); qm_free(shm_block, ((void*)dlg_mutex)); futex_release(mem_lock); }while(0);
 }
}

canonical_original_code:
static void destroy_dialog_mutex()
{
 if (dlg_mutex) {
  ;
  do { futex_get(mem_lock); qm_free(shm_block, ((void *)dlg_mutex)); futex_release(mem_lock); }while(0);
 }
}


decompiled_code:
_QWORD *dlg_mod_destroy()
{
return destroy_dialog_mutex();
}

canonical_decompiled_code:
_QWORD *func7()
{
return func6();
}

original_code:
static void dlg_mod_destroy(void)
{
 destroy_dialog_mutex();
}

canonical_original_code:
static void dlg_mod_destroy()
{
 destroy_dialog_mutex();
}


decompiled_code:
__int64 init_dialog_mutex()
{
_DWORD *v0; // rdi

v0 = (_DWORD *)shm_malloc(4u);
dlg_mutex[0] = v0;
if ( !v0 )
return 0xFFFFFFFFLL;
futex_init(v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
_DWORD *v0; // rdi

v0 = (_DWORD *)func8(4u);
dlg_mutex[0] = v0;
if ( !v0 )
return 0xFFFFFFFFLL;
futex_init(v0);
return 0LL;
}

original_code:
static int init_dialog_mutex()
{
 dlg_mutex = (gen_lock_t*)shm_malloc(sizeof(*dlg_mutex));
 if (!dlg_mutex) return -1;
 futex_init(dlg_mutex);
 return 0;
}

canonical_original_code:
static int init_dialog_mutex()
{
 dlg_mutex = (struct atomic_t *)shm_malloc(sizeof(*dlg_mutex));
 if (!dlg_mutex) return -1;
 futex_init(dlg_mutex);
 return 0;
}


decompiled_code:
__int64 init_dialog_tags()
{
return init_tags((__int64)&dialog_tags, dialog_tag_suffix, "SER-DIALOG/tags", 45);
}

canonical_decompiled_code:
__int64 func11()
{
return func10((__int64)&dialog_tags, dialog_tag_suffix, "SER-DIALOG/tags", 45);
}

original_code:
static void init_dialog_tags()
{
 init_tags(dialog_tags, &dialog_tag_suffix, "SER-DIALOG/tags", '-');
}


decompiled_code:
__int64 __fastcall m_apo_escape(__int64 a1, int a2, _WORD *a3, int a4)
{
__int64 v6; // r8
__int64 result; // rax
int v8; // esi
int v9; // eax
int v10; // eax
int v11; // er11
__int64 v12; // rcx
char v13; // di
char v14; // r10
char v15; // r12

if ( a4 <= 0 || a3 == 0LL || !a1 )
return 0xFFFFFFFFLL;
if ( a2 == -1 )
a2 = strlen((const char *)a1);
if ( a2 <= 0 )
{
result = 0LL;
LABEL_25:
*((_BYTE *)a3 + (int)result) = 0;
return result;
}
v6 = a1 + (unsigned int)(a2 - 1) + 1;
LODWORD(result) = 0;
v8 = a2 & 3;
if ( !v8 )
goto LABEL_42;
if ( v8 == 1LL )
goto LABEL_17;
if ( v8 != 2LL )
{
if ( *(_BYTE *)a1 == 39 )
{
if ( a4 <= 2 )
return 4294967294LL;
*a3 = 10076;
LODWORD(result) = 2;
}
else
{
if ( a4 <= 1 )
return 4294967294LL;
*(_BYTE *)a3 = *(_BYTE *)a1;
LODWORD(result) = 1;
}
++a1;
}
if ( *(_BYTE *)a1 == 39 )
{
if ( (int)result + 2 >= a4 )
return 4294967294LL;
*(_WORD *)((char *)a3 + (int)result) = 10076;
LODWORD(result) = result + 2;
goto LABEL_16;
}
if ( (int)result + 1 < a4 )
{
*((_BYTE *)a3 + (int)result) = *(_BYTE *)a1;
LODWORD(result) = result + 1;
LABEL_16:
++a1;
LABEL_17:
if ( *(_BYTE *)a1 != 39 )
{
if ( (int)result + 1 < a4 )
{
*((_BYTE *)a3 + (int)result) = *(_BYTE *)a1;
result = (unsigned int)(result + 1);
goto LABEL_20;
}
return 4294967294LL;
}
if ( (int)result + 2 < a4 )
{
*(_WORD *)((char *)a3 + (int)result) = 10076;
result = (unsigned int)(result + 2);
LABEL_20:
if ( ++a1 != v6 )
{
while ( 1 )
{
LABEL_42:
if ( *(_BYTE *)a1 == 39 )
{
if ( (int)result + 2 >= a4 )
return 4294967294LL;
*(_WORD *)((char *)a3 + (int)result) = 10076;
v9 = result + 2;
}
else
{
if ( (int)result + 1 >= a4 )
return 4294967294LL;
*((_BYTE *)a3 + (int)result) = *(_BYTE *)a1;
v9 = result + 1;
}
v12 = a1 + 1;
v13 = *(_BYTE *)(a1 + 1);
if ( v13 == 39 )
{
if ( v9 + 2 >= a4 )
return 4294967294LL;
*(_WORD *)((char *)a3 + v9) = 10076;
v10 = v9 + 2;
}
else
{
if ( v9 + 1 >= a4 )
return 4294967294LL;
*((_BYTE *)a3 + v9) = v13;
v10 = v9 + 1;
}
v14 = *(_BYTE *)(v12 + 1);
if ( v14 == 39 )
{
v11 = v10 + 2;
if ( v10 + 2 >= a4 )
return 4294967294LL;
*(_WORD *)((char *)a3 + v10) = 10076;
}
else
{
v11 = v10 + 1;
if ( v10 + 1 >= a4 )
return 4294967294LL;
*((_BYTE *)a3 + v10) = v14;
}
v15 = *(_BYTE *)(v12 + 2);
if ( v15 == 39 )
{
result = (unsigned int)(v11 + 2);
if ( (int)result >= a4 )
return 4294967294LL;
*(_WORD *)((char *)a3 + v11) = 10076;
}
else
{
result = (unsigned int)(v11 + 1);
if ( (int)result >= a4 )
return 4294967294LL;
*((_BYTE *)a3 + v11) = v15;
}
a1 = v12 + 3;
if ( v12 + 3 == v6 )
goto LABEL_25;
}
}
goto LABEL_25;
}
return 4294967294LL;
}
return 4294967294LL;
}

original_code:
int m_apo_escape(char* src, int slen, char* dst, int dlen)
{
 int i, j;
 if(!src || !dst || dlen <= 0)
  return -1;
 if(slen == -1)
  slen = strlen(src);
 for(i=j=0; i<slen; i++)
 {
  switch(src[i])
  {
   case '\'':
     if(j+2>=dlen)
      return -2;
     memcpy(&dst[j], "\\'", 2);
     j += 2;
    break;
   default:
    if(j+1>=dlen)
      return -2;
    dst[j] = src[i];
    j++;
  }
 }
 dst[j] = '\0';
 return j;
}

canonical_original_code:
int m_apo_escape(char *src, int slen, char *dst, int dlen)
{
 int i; int j;
 if(!src || !dst || dlen <= 0)
  return -1;
 if(slen == -1)
  slen = strlen(src);
 for(i=j=0; i<slen; i++)
 {
  switch(src[i])
  {
   case '\'':
     if(j+2>=dlen)
      return -2;
     memcpy(&dst[j], "\\'", 2);
     j += 2;
    break;
   default:
    if(j+1>=dlen)
      return -2;
    dst[j] = src[i];
    j++;
  }
 }
 dst[j] = '\0';
 return j;
}

variable_types:
src
char *

variable_types: slen int

variable_types:
dst
char *

variable_types: dlen int

variable_types: j int