decompiled_code:
size_t carrierroute_db_vars()
{
size_t result; // rax

if ( carrierroute_db_url )
*((_DWORD *)&carrierroute_db_url + 2) = strlen(carrierroute_db_url);
*((_DWORD *)&carrierroute_table + 2) = strlen(carrierroute_table);
*((_DWORD *)&carrierroute_id_col + 2) = strlen(carrierroute_id_col);
*((_DWORD *)&carrierroute_carrier_col + 2) = strlen(carrierroute_carrier_col);
*((_DWORD *)&carrierroute_domain_col + 2) = strlen(carrierroute_domain_col);
*((_DWORD *)&carrierroute_scan_prefix_col + 2) = strlen(carrierroute_scan_prefix_col);
*((_DWORD *)&carrierroute_flags_col + 2) = strlen(carrierroute_flags_col);
*((_DWORD *)&carrierroute_mask_col + 2) = strlen(carrierroute_mask_col);
*((_DWORD *)&carrierroute_prob_col + 2) = strlen(carrierroute_prob_col);
*((_DWORD *)&carrierroute_strip_col + 2) = strlen(carrierroute_strip_col);
*((_DWORD *)&carrierroute_rewrite_host_col + 2) = strlen(carrierroute_rewrite_host_col);
*((_DWORD *)&carrierroute_rewrite_prefix_col + 2) = strlen(carrierroute_rewrite_prefix_col);
*((_DWORD *)&carrierroute_rewrite_suffix_col + 2) = strlen(carrierroute_rewrite_suffix_col);
*((_DWORD *)&carrierroute_description_col + 2) = strlen(carrierroute_description_col);
*((_DWORD *)&carrierfailureroute_table + 2) = strlen(carrierfailureroute_table);
*((_DWORD *)&carrierfailureroute_id_col + 2) = strlen(carrierfailureroute_id_col);
*((_DWORD *)&carrierfailureroute_carrier_col + 2) = strlen(carrierfailureroute_carrier_col);
*((_DWORD *)&carrierfailureroute_domain_col + 2) = strlen(carrierfailureroute_domain_col);
*((_DWORD *)&carrierfailureroute_scan_prefix_col + 2) = strlen(carrierfailureroute_scan_prefix_col);
*((_DWORD *)&carrierfailureroute_host_name_col + 2) = strlen(carrierfailureroute_host_name_col);
*((_DWORD *)&carrierfailureroute_reply_code_col + 2) = strlen(carrierfailureroute_reply_code_col);
*((_DWORD *)&carrierfailureroute_flags_col + 2) = strlen(carrierfailureroute_flags_col);
*((_DWORD *)&carrierfailureroute_mask_col + 2) = strlen(carrierfailureroute_mask_col);
*((_DWORD *)&carrierfailureroute_next_domain_col + 2) = strlen(carrierfailureroute_next_domain_col);
*((_DWORD *)&carrierfailureroute_description_col + 2) = strlen(carrierfailureroute_description_col);
*((_DWORD *)&carrier_name_table + 2) = strlen(carrier_name_table);
*((_DWORD *)&carrier_name_id_col + 2) = strlen(carrier_name_id_col);
*((_DWORD *)&carrier_name_carrier_col + 2) = strlen(carrier_name_carrier_col);
*((_DWORD *)&domain_name_table + 2) = strlen(domain_name_table);
*((_DWORD *)&domain_name_id_col + 2) = strlen(domain_name_id_col);
result = strlen(domain_name_domain_col);
*((_DWORD *)&domain_name_domain_col + 2) = result;
return result;
}

canonical_decompiled_code:
size_t func3()
{
size_t result; // rax

if ( carrierroute_db_url )
*((_DWORD *)&carrierroute_db_url + 2) = strlen(carrierroute_db_url);
*((_DWORD *)&carrierroute_table + 2) = strlen(carrierroute_table);
*((_DWORD *)&carrierroute_id_col + 2) = strlen(carrierroute_id_col);
*((_DWORD *)&carrierroute_carrier_col + 2) = strlen(carrierroute_carrier_col);
*((_DWORD *)&carrierroute_domain_col + 2) = strlen(carrierroute_domain_col);
*((_DWORD *)&carrierroute_scan_prefix_col + 2) = strlen(carrierroute_scan_prefix_col);
*((_DWORD *)&carrierroute_flags_col + 2) = strlen(carrierroute_flags_col);
*((_DWORD *)&carrierroute_mask_col + 2) = strlen(carrierroute_mask_col);
*((_DWORD *)&carrierroute_prob_col + 2) = strlen(carrierroute_prob_col);
*((_DWORD *)&carrierroute_strip_col + 2) = strlen(carrierroute_strip_col);
*((_DWORD *)&carrierroute_rewrite_host_col + 2) = strlen(carrierroute_rewrite_host_col);
*((_DWORD *)&carrierroute_rewrite_prefix_col + 2) = strlen(carrierroute_rewrite_prefix_col);
*((_DWORD *)&carrierroute_rewrite_suffix_col + 2) = strlen(carrierroute_rewrite_suffix_col);
*((_DWORD *)&carrierroute_description_col + 2) = strlen(carrierroute_description_col);
*((_DWORD *)&carrierfailureroute_table + 2) = strlen(carrierfailureroute_table);
*((_DWORD *)&carrierfailureroute_id_col + 2) = strlen(carrierfailureroute_id_col);
*((_DWORD *)&carrierfailureroute_carrier_col + 2) = strlen(carrierfailureroute_carrier_col);
*((_DWORD *)&carrierfailureroute_domain_col + 2) = strlen(carrierfailureroute_domain_col);
*((_DWORD *)&carrierfailureroute_scan_prefix_col + 2) = strlen(carrierfailureroute_scan_prefix_col);
*((_DWORD *)&carrierfailureroute_host_name_col + 2) = strlen(carrierfailureroute_host_name_col);
*((_DWORD *)&carrierfailureroute_reply_code_col + 2) = strlen(carrierfailureroute_reply_code_col);
*((_DWORD *)&carrierfailureroute_flags_col + 2) = strlen(carrierfailureroute_flags_col);
*((_DWORD *)&carrierfailureroute_mask_col + 2) = strlen(carrierfailureroute_mask_col);
*((_DWORD *)&carrierfailureroute_next_domain_col + 2) = strlen(carrierfailureroute_next_domain_col);
*((_DWORD *)&carrierfailureroute_description_col + 2) = strlen(carrierfailureroute_description_col);
*((_DWORD *)&carrier_name_table + 2) = strlen(carrier_name_table);
*((_DWORD *)&carrier_name_id_col + 2) = strlen(carrier_name_id_col);
*((_DWORD *)&carrier_name_carrier_col + 2) = strlen(carrier_name_carrier_col);
*((_DWORD *)&domain_name_table + 2) = strlen(domain_name_table);
*((_DWORD *)&domain_name_id_col + 2) = strlen(domain_name_id_col);
result = strlen(domain_name_domain_col);
*((_DWORD *)&domain_name_domain_col + 2) = result;
return result;
}

original_code:
void carrierroute_db_vars(void) {
 if (carrierroute_db_url.s) carrierroute_db_url.len = strlen(carrierroute_db_url.s);
 carrierroute_table.len = strlen(carrierroute_table.s);
 carrierroute_id_col.len = strlen(carrierroute_id_col.s);
 carrierroute_carrier_col.len = strlen(carrierroute_carrier_col.s);
 carrierroute_domain_col.len = strlen(carrierroute_domain_col.s);
 carrierroute_scan_prefix_col.len = strlen(carrierroute_scan_prefix_col.s);
 carrierroute_flags_col.len = strlen(carrierroute_flags_col.s);
 carrierroute_mask_col.len = strlen(carrierroute_mask_col.s);
 carrierroute_prob_col.len = strlen(carrierroute_prob_col.s);
 carrierroute_strip_col.len = strlen(carrierroute_strip_col.s);
 carrierroute_rewrite_host_col.len = strlen(carrierroute_rewrite_host_col.s);
 carrierroute_rewrite_prefix_col.len = strlen(carrierroute_rewrite_prefix_col.s);
 carrierroute_rewrite_suffix_col.len = strlen(carrierroute_rewrite_suffix_col.s);
 carrierroute_description_col.len = strlen(carrierroute_description_col.s);
 carrierfailureroute_table.len = strlen(carrierfailureroute_table.s);
 carrierfailureroute_id_col.len = strlen(carrierfailureroute_id_col.s);
 carrierfailureroute_carrier_col.len = strlen(carrierfailureroute_carrier_col.s);
 carrierfailureroute_domain_col.len = strlen(carrierfailureroute_domain_col.s);
 carrierfailureroute_scan_prefix_col.len = strlen(carrierfailureroute_scan_prefix_col.s);
 carrierfailureroute_host_name_col.len = strlen(carrierfailureroute_host_name_col.s);
 carrierfailureroute_reply_code_col.len = strlen(carrierfailureroute_reply_code_col.s);
 carrierfailureroute_flags_col.len = strlen(carrierfailureroute_flags_col.s);
 carrierfailureroute_mask_col.len = strlen(carrierfailureroute_mask_col.s);
 carrierfailureroute_next_domain_col.len = strlen(carrierfailureroute_next_domain_col.s);
 carrierfailureroute_description_col.len = strlen(carrierfailureroute_description_col.s);
 carrier_name_table.len = strlen(carrier_name_table.s);
 carrier_name_id_col.len = strlen(carrier_name_id_col.s);
 carrier_name_carrier_col.len = strlen(carrier_name_carrier_col.s);
 domain_name_table.len = strlen(domain_name_table.s);
 domain_name_id_col.len = strlen(domain_name_id_col.s);
 domain_name_domain_col.len = strlen(domain_name_domain_col.s);
}

canonical_original_code:
void carrierroute_db_vars() {
 if (carrierroute_db_url.s) carrierroute_db_url.len = strlen(carrierroute_db_url.s);
 carrierroute_table.len = strlen(carrierroute_table.s);
 carrierroute_id_col.len = strlen(carrierroute_id_col.s);
 carrierroute_carrier_col.len = strlen(carrierroute_carrier_col.s);
 carrierroute_domain_col.len = strlen(carrierroute_domain_col.s);
 carrierroute_scan_prefix_col.len = strlen(carrierroute_scan_prefix_col.s);
 carrierroute_flags_col.len = strlen(carrierroute_flags_col.s);
 carrierroute_mask_col.len = strlen(carrierroute_mask_col.s);
 carrierroute_prob_col.len = strlen(carrierroute_prob_col.s);
 carrierroute_strip_col.len = strlen(carrierroute_strip_col.s);
 carrierroute_rewrite_host_col.len = strlen(carrierroute_rewrite_host_col.s);
 carrierroute_rewrite_prefix_col.len = strlen(carrierroute_rewrite_prefix_col.s);
 carrierroute_rewrite_suffix_col.len = strlen(carrierroute_rewrite_suffix_col.s);
 carrierroute_description_col.len = strlen(carrierroute_description_col.s);
 carrierfailureroute_table.len = strlen(carrierfailureroute_table.s);
 carrierfailureroute_id_col.len = strlen(carrierfailureroute_id_col.s);
 carrierfailureroute_carrier_col.len = strlen(carrierfailureroute_carrier_col.s);
 carrierfailureroute_domain_col.len = strlen(carrierfailureroute_domain_col.s);
 carrierfailureroute_scan_prefix_col.len = strlen(carrierfailureroute_scan_prefix_col.s);
 carrierfailureroute_host_name_col.len = strlen(carrierfailureroute_host_name_col.s);
 carrierfailureroute_reply_code_col.len = strlen(carrierfailureroute_reply_code_col.s);
 carrierfailureroute_flags_col.len = strlen(carrierfailureroute_flags_col.s);
 carrierfailureroute_mask_col.len = strlen(carrierfailureroute_mask_col.s);
 carrierfailureroute_next_domain_col.len = strlen(carrierfailureroute_next_domain_col.s);
 carrierfailureroute_description_col.len = strlen(carrierfailureroute_description_col.s);
 carrier_name_table.len = strlen(carrier_name_table.s);
 carrier_name_id_col.len = strlen(carrier_name_id_col.s);
 carrier_name_carrier_col.len = strlen(carrier_name_carrier_col.s);
 domain_name_table.len = strlen(domain_name_table.s);
 domain_name_id_col.len = strlen(domain_name_id_col.s);
 domain_name_domain_col.len = strlen(domain_name_domain_col.s);
}


repo: virtualolson/who

decompiled_code:
__int64 __fastcall fixup_subscribe(const char **a1, unsigned int a2)
{
__int64 result; // rax
const char *v4; // rdi
int v5; // er10
__int64 v6; // rdi
const char *v7; // rbp
const char *v8; // rbx
unsigned int v9; // eax
int v10; // edx
const char *v11; // rbp
unsigned int v12; // eax
const char *v13; // [rsp+0h] [rbp-38h] BYREF
int v14; // [rsp+8h] [rbp-30h]
const char *v15; // [rsp+18h] [rbp-20h] BYREF

if ( a2 == 1 )
{
v4 = *a1;
if ( v4 )
{
v13 = v4;
v14 = strlen(v4);
if ( (int)pv_parse_format(&v13, &v15) < 0 )
{
v5 = get_debug_level("pua_reginfo", 11LL);
result = 0xFFFFFFFFLL;
if ( v5 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
v6 = (__int64)&log_stderr;
if ( log_stderr )
{
if ( log_color )
{
v6 = 0xFFFFFFFFLL;
dprint_color(0xFFFFFFFFLL);
}
v7 = *a1;
v8 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid(v6);
fprintf(
stderr,
"%2d(%d) %s: %s%s(): wrong format[%s]\n",
process_no,
v9,
v8,
"pua_reginfo [subscribe.c:90]: ",
"fixup_subscribe",
v7);
if ( log_color )
dprint_color_reset(&log_color);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): wrong format[%s]\n",
*((const char **)&log_level_info + 8),
"pua_reginfo [subscribe.c:90]: ",
"fixup_subscribe",
*a1);
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
else
{
*a1 = v15;
result = a2;
}
}
else
{
v10 = get_debug_level("pua_reginfo", 11LL);
result = 0xFFFFFFFFLL;
if ( v10 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v11 = (const char *)*((_QWORD *)&log_level_info + 8);
v12 = ((__int64 (*)(void))my_pid)();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): null format\n",
process_no,
v12,
v11,
"pua_reginfo [subscribe.c:96]: ",
"fixup_subscribe");
if ( log_color )
((void (*)(void))dprint_color_reset)();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): null format\n",
*((const char **)&log_level_info + 8),
"pua_reginfo [subscribe.c:96]: ",
"fixup_subscribe");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
}
else
{
result = 1LL;
if ( a2 == 2 )
result = fixup_igp_igp(a1, 2LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char **a1, unsigned int a2)
{
__int64 result; // rax
const char *v4; // rdi
int v5; // er10
__int64 v6; // rdi
const char *v7; // rbp
const char *v8; // rbx
unsigned int v9; // eax
int v10; // edx
const char *v11; // rbp
unsigned int v12; // eax
const char *v13; // [rsp+0h] [rbp-38h] BYREF
int v14; // [rsp+8h] [rbp-30h]
const char *v15; // [rsp+18h] [rbp-20h] BYREF

if ( a2 == 1 )
{
v4 = *a1;
if ( v4 )
{
v13 = v4;
v14 = strlen(v4);
if ( (int)pv_parse_format(&v13, &v15) < 0 )
{
v5 = get_debug_level("pua_reginfo", 11LL);
result = 0xFFFFFFFFLL;
if ( v5 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
v6 = (__int64)&log_stderr;
if ( log_stderr )
{
if ( log_color )
{
v6 = 0xFFFFFFFFLL;
dprint_color(0xFFFFFFFFLL);
}
v7 = *a1;
v8 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid(v6);
fprintf(
stderr,
"%2d(%d) %s: %s%s(): wrong format[%s]\n",
process_no,
v9,
v8,
"pua_reginfo [subscribe.c:90]: ",
"fixup_subscribe",
v7);
if ( log_color )
dprint_color_reset(&log_color);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): wrong format[%s]\n",
*((const char **)&log_level_info + 8),
"pua_reginfo [subscribe.c:90]: ",
"fixup_subscribe",
*a1);
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
else
{
*a1 = v15;
result = a2;
}
}
else
{
v10 = get_debug_level("pua_reginfo", 11LL);
result = 0xFFFFFFFFLL;
if ( v10 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v11 = (const char *)*((_QWORD *)&log_level_info + 8);
v12 = ((__int64 (*)(void))my_pid)();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): null format\n",
process_no,
v12,
v11,
"pua_reginfo [subscribe.c:96]: ",
"fixup_subscribe");
if ( log_color )
((void (*)(void))dprint_color_reset)();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): null format\n",
*((const char **)&log_level_info + 8),
"pua_reginfo [subscribe.c:96]: ",
"fixup_subscribe");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
}
else
{
result = 1LL;
if ( a2 == 2 )
result = fixup_igp_igp(a1, 2LL);
}
return result;
}

original_code:
static int fixup_subscribe(void** param, int param_no)
{
 if(library_mode)
 {
  do { if (get_debug_level("presence", (sizeof("presence")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "Bad config - you can not call 'handle_subscribe' function" " (db_url not set)\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("presence" " [" "presence.c" ":" "596" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "Bad config - you can not call 'handle_subscribe' function" " (db_url not set)\n", (log_level_info[((-1)) - (-5)].name), ("presence" " [" "presence.c" ":" "596" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "Bad config - you can not call 'handle_subscribe' function" " (db_url not set)\n", process_no, my_pid(), ("presence" " [" "presence.c" ":" "596" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Bad config - you can not call 'handle_subscribe' function" " (db_url not set)\n", ("presence" " [" "presence.c" ":" "596" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Bad config - you can not call 'handle_subscribe' function" " (db_url not set)\n", ("presence" " [" "presence.c" ":" "596" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (param_no == 1) {
  return fixup_spve_null(param, 1);
 }
 return 0;
}

canonical_original_code:
static int fixup_subscribe(void **param, int param_no)
{
 if(library_mode)
 {
  do { if (get_debug_level("presence", (sizeof("presence")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "Bad config - you can not call 'handle_subscribe' function" " (db_url not set)\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("presence" " [" "presence.c" ":" "596" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "Bad config - you can not call 'handle_subscribe' function" " (db_url not set)\n", (log_level_info[((-1)) - (-5)].name), ("presence" " [" "presence.c" ":" "596" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "Bad config - you can not call 'handle_subscribe' function" " (db_url not set)\n", process_no, my_pid(), ("presence" " [" "presence.c" ":" "596" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Bad config - you can not call 'handle_subscribe' function" " (db_url not set)\n", ("presence" " [" "presence.c" ":" "596" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Bad config - you can not call 'handle_subscribe' function" " (db_url not set)\n", ("presence" " [" "presence.c" ":" "596" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (param_no == 1) {
  return fixup_spve_null(param, 1);
 }
 return 0;
}

variable_types:
param
void **

return_type: int

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 __fastcall cmp_unconfirmed_local_dlg_ids(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // edx

if ( !a1 )
return (unsigned int)-(a2 == 0);
result = 1LL;
if ( a2 )
{
v3 = ((__int64 (*)(void))str_case_equals)();
result = 1LL;
if ( !v3 )
result = (unsigned int)str_case_equals(a1 + 32, a2 + 32) != 0;
}
return result;
}

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

if ( !a1 )
return (unsigned int)-(a2 == 0);
result = 1LL;
if ( a2 )
{
v3 = ((__int64 (*)(void))str_case_equals)();
result = 1LL;
if ( !v3 )
result = (unsigned int)str_case_equals(a1 + 32, a2 + 32) != 0;
}
return result;
}

original_code:
static int cmp_unconfirmed_local_dlg_ids(dlg_id_t *a, dlg_id_t *b)
{
 if (!a) {
  if (!b) return -1;
  else return 0;
 }
 if (!b) return 1;
 if (str_case_equals(&a->call_id, &b->call_id) != 0) return 1;
 if (str_case_equals(&a->loc_tag, &b->loc_tag) != 0) return 1;
 return 0;
}

canonical_original_code:
static int cmp_unconfirmed_local_dlg_ids(struct dlg_id *a, struct dlg_id *b)
{
 if (!a) {
  if (!b) return -1;
  else return 0;
 }
 if (!b) return 1;
 if (str_case_equals(&a->call_id, &b->call_id) != 0) return 1;
 if (str_case_equals(&a->loc_tag, &b->loc_tag) != 0) return 1;
 return 0;
}

variable_types: struct dlg_id { struct _str { char *s; int len; } call_id; struct _str rem_tag; struct _str loc_tag; } *

variable_types:
b
struct dlg_id *

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


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

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

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

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

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

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

variable_types:
lock
struct atomic_t { int val; } *

variable_types: i int

return_type: void


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

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

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

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

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

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


decompiled_code:
_QWORD **lock_events_uac()
{
_QWORD **result; // rax

result = &euac_internals;
if ( euac_internals )
result = (_QWORD **)futex_get((volatile signed __int32 *)euac_internals + 4);
return result;
}

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

result = &euac_internals;
if ( euac_internals )
result = (_QWORD **)func3((volatile signed __int32 *)euac_internals + 4);
return result;
}

original_code:
void lock_events_uac()
{
 if (euac_internals) futex_get(&euac_internals->mutex);
}


decompiled_code:
_QWORD **unlock_events_uac()
{
_QWORD **result; // rax

result = &euac_internals;
if ( euac_internals )
result = (_QWORD **)futex_release((volatile __int32 *)euac_internals + 4);
return result;
}

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

result = &euac_internals;
if ( euac_internals )
result = (_QWORD **)func4((volatile __int32 *)euac_internals + 4);
return result;
}

original_code:
void unlock_events_uac()
{
 if (euac_internals) futex_release(&euac_internals->mutex);
}


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 *


test

original_code:
static void test(rpc_t *rpc, void *c)
{
 int i, sum;
 char *x;
 int sizes[] = { 4, 24, 9, 4, 12, 12, 16, 12, 11, 4, -1 };
 sum = 0;
 for (i = 0; sizes[i] >= 0; i++) {
  sum += sizes[i];
  x = (char*) shm_malloc(sizes[i]);
  if (!x) rpc->fault(c, 500, "allocation error");
 }
 rpc->add(c, "sd", "allocated bytes", sum);
 rpc->add(c, "sd", "allocated blocks", i);
 rpc->send(c);
}

canonical_original_code:
static void test(struct rpc *rpc, void *c)
{
 int i; int sum;
 char *x;
 int sizes[] = { 4, 24, 9, 4, 12, 12, 16, 12, 11, 4, -1 };
 sum = 0;
 for (i = 0; sizes[i] >= 0; i++) {
  sum += sizes[i];
  x = (char *) shm_malloc(sizes[i]);
  if (!x) rpc->fault(c, 500, "allocation error");
 }
 rpc->add(c, "sd", "allocated bytes", sum);
 rpc->add(c, "sd", "allocated blocks", i);
 rpc->send(c);
}

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:
c
void *

variable_types: sum int

variable_types:
x
char *

variable_types:
sizes
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 __fastcall init_input_sstream(__int64 a1, __int64 a2, int a3)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 52) = 0;
*(_DWORD *)(a1 + 40) = a3;
*(_QWORD *)(a1 + 32) = a2;
*(_DWORD *)(a1 + 48) = 0;
return 0LL;
}

original_code:
int init_input_sstream(sstream_t *ss, char *data_in, int data_len)
{
 if (!ss) return -1;
 ss->type = sstream_in;
 ss->in.len = data_len;
 ss->in.s = data_in;
 ss->in_pos = 0;
 return 0;
}

canonical_original_code:
int init_input_sstream(struct sstream_t *ss, char *data_in, int data_len)
{
 if (!ss) return -1;
 ss->type = sstream_in;
 ss->in.len = data_len;
 ss->in.s = data_in;
 ss->in_pos = 0;
 return 0;
}

variable_types: struct sstream_t { 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; } out; struct _str { char *s; int len; } in; int in_pos; enum { sstream_in=0, sstream_out=1 } type; } *

user_defined_types: struct sstream_t { struct _dstring_t out; struct _str in; int in_pos; enum { sstream_in=0, sstream_out=1 } type; }

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


decompiled_code:
__int64 __fastcall init_output_sstream(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 52) = 1;
*(_DWORD *)(a1 + 40) = 0;
*(_QWORD *)(a1 + 32) = 0LL;
*(_DWORD *)(a1 + 48) = 0;
dstr_init();
return 0LL;
}

original_code:
int init_output_sstream(sstream_t *ss, int out_buff_resize)
{
 if (!ss) return -1;
 ss->type = sstream_out;
 do { if (&ss->in != ((void *)0)) { (&ss->in)->len = 0; (&ss->in)->s = 0; } } while (0);
 ss->in_pos = 0;
 dstr_init(&ss->out, out_buff_resize);
 return 0;
}

canonical_original_code:
int init_output_sstream(struct sstream_t *ss, int out_buff_resize)
{
 if (!ss) return -1;
 ss->type = sstream_out;
 do { if (&ss->in != ((void *)0)) { (&ss->in)->len = 0; (&ss->in)->s = 0; } } while (0);
 ss->in_pos = 0;
 dstr_init(&ss->out, out_buff_resize);
 return 0;
}

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


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

if ( *(_DWORD *)(a1 + 52) == 1 )
result = dstr_get_str();
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( *(_DWORD *)(a1 + 52) == 1 )
result = dstr_get_str();
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int get_serialized_sstream(sstream_t *ss, str_t *dst)
{
 if (ss->type == sstream_out) return dstr_get_str(&ss->out, dst);
 else return -1;
}

canonical_original_code:
int get_serialized_sstream(struct sstream_t *ss, struct _str *dst)
{
 if (ss->type == sstream_out) return dstr_get_str(&ss->out, dst);
 else return -1;
}

variable_types:
dst
struct _str *


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

if ( *(_DWORD *)(a1 + 52) == 1 )
result = dstr_get_data();
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( *(_DWORD *)(a1 + 52) == 1 )
result = dstr_get_data();
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int get_serialized_sstream_data(sstream_t *ss, char *dst)
{
 if (ss->type == sstream_out) return dstr_get_data(&ss->out, dst);
 else return -1;
}

canonical_original_code:
int get_serialized_sstream_data(struct sstream_t *ss, char *dst)
{
 if (ss->type == sstream_out) return dstr_get_data(&ss->out, dst);
 else return -1;
}

variable_types:
dst
char *


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

result = 0LL;
if ( *(_DWORD *)(a1 + 52) == 1 )
result = *(unsigned int *)(a1 + 16);
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(a1 + 52) == 1 )
result = *(unsigned int *)(a1 + 16);
return result;
}

original_code:
int get_serialized_sstream_len(sstream_t *ss)
{
 if (ss->type == sstream_out) return (&ss->out)->len;
 else return 0;
}

canonical_original_code:
int get_serialized_sstream_len(struct sstream_t *ss)
{
 if (ss->type == sstream_out) return (&ss->out)->len;
 else return 0;
}


original_code:
int sstream_get(sstream_t *ss, char *c)
{
 if (ss->in_pos < ss->in.len) {
  *c = ss->in.s[ss->in_pos++];
  return 0;
 }
 else return 1;
}

canonical_original_code:
int sstream_get(struct sstream_t *ss, char *c)
{
 if (ss->in_pos < ss->in.len) {
  *c = ss->in.s[ss->in_pos++];
  return 0;
 }
 else return 1;
}

variable_types:
c
char *


decompiled_code:
__int64 sstream_put_str()
{
return dstr_append_str();
}

canonical_decompiled_code:
__int64 func6()
{
return dstr_append_str();
}

original_code:
int sstream_put_str(sstream_t *ss, str_t *s)
{
 return dstr_append_str(&ss->out, s);
}

canonical_original_code:
int sstream_put_str(struct sstream_t *ss, struct _str *s)
{
 return dstr_append_str(&ss->out, s);
}

variable_types:
s
struct _str *


decompiled_code:
__int64 __fastcall sstream_get_str_ex(__int64 a1, int a2, __int64 a3)
{
int v3; // ecx
int v4; // eax
__int64 result; // rax

if ( *(_DWORD *)(a1 + 52) || !a3 )
return 0xFFFFFFFFLL;
if ( a2 )
{
v3 = *(_DWORD *)(a1 + 48);
v4 = *(_DWORD *)(a1 + 40) - v3;
*(_QWORD *)a3 = *(_QWORD *)(a1 + 32) + v3;
if ( a2 > v4 )
a2 = v4;
*(_DWORD *)(a3 + 8) = a2;
*(_DWORD *)(a1 + 48) += a2;
result = 0LL;
}
else
{
*(_DWORD *)(a3 + 8) = 0;
*(_QWORD *)a3 = 0LL;
result = 0LL;
}
return result;
}

original_code:
int sstream_get_str_ex(sstream_t *ss, int len, str_t *dst)
{
 int l;
 int res = 0;
 if (!(ss->type == sstream_in)) return -1;
 if (!dst) return -1;
 if (len == 0) {
  do { if (dst != ((void *)0)) { (dst)->len = 0; (dst)->s = 0; } } while (0);
  return 0;
 }
 l = ss->in.len - ss->in_pos;
 dst->s = ss->in.s + ss->in_pos;
 if (len > l) {
  dst->len = l;
  res = 1;
 }
 else dst->len = len;
 ss->in_pos += dst->len;
 return 0;
}

canonical_original_code:
int sstream_get_str_ex(struct sstream_t *ss, int len, struct _str *dst)
{
 int l;
 int res = 0;
 if (!(ss->type == sstream_in)) return -1;
 if (!dst) return -1;
 if (len == 0) {
  do { if (dst != ((void *)0)) { (dst)->len = 0; (dst)->s = 0; } } while (0);
  return 0;
 }
 l = ss->in.len - ss->in_pos;
 dst->s = ss->in.s + ss->in_pos;
 if (len > l) {
  dst->len = l;
  res = 1;
 }
 else dst->len = len;
 ss->in_pos += dst->len;
 return 0;
}

variable_types: len int

variable_types: l int

variable_types: res int


decompiled_code:
__int64 __fastcall sstream_get_str(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax
_BYTE v5[24]; // [rsp+0h] [rbp-18h] BYREF

result = sstream_get_str_ex(a1, a2, (__int64)v5);
if ( (int)result >= 0 )
{
result = str_dup_impl(a3, v5);
if ( a3 )
{
if ( (_DWORD)result )
{
*(_DWORD *)(a3 + 8) = 0;
*(_QWORD *)a3 = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax
_BYTE v5[24]; // [rsp+0h] [rbp-18h] BYREF

result = func7(a1, a2, (__int64)v5);
if ( (int)result >= 0 )
{
result = str_dup_impl(a3, v5);
if ( a3 )
{
if ( (_DWORD)result )
{
*(_DWORD *)(a3 + 8) = 0;
*(_QWORD *)a3 = 0LL;
}
}
}
return result;
}

original_code:
int sstream_get_str(sstream_t *ss, int len, str_t *dst)
{
 str_t tmp;
 int res = sstream_get_str_ex(ss, len, &tmp);
 if (res >= 0) {
  res = str_dup_impl(dst,&tmp);
  if (res != 0) do { if (dst != ((void *)0)) { (dst)->len = 0; (dst)->s = 0; } } while (0);
 }
 return res;
}

canonical_original_code:
int sstream_get_str(struct sstream_t *ss, int len, struct _str *dst)
{
 struct _str tmp;
 int res = sstream_get_str_ex(ss, len, &tmp);
 if (res >= 0) {
  res = str_dup_impl(dst,&tmp);
  if (res != 0) do { if (dst != ((void *)0)) { (dst)->len = 0; (dst)->s = 0; } } while (0);
 }
 return res;
}

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


decompiled_code:
__int64 sstream_put_zt()
{
return dstr_append_zt();
}

canonical_decompiled_code:
__int64 func9()
{
return dstr_append_zt();
}

original_code:
int sstream_put_zt(sstream_t *ss, const char *s)
{
 return dstr_append_zt(&ss->out, s);
}

canonical_original_code:
int sstream_put_zt(struct sstream_t *ss, char *s)
{
 return dstr_append_zt(&ss->out, s);
}

variable_types:
s
char *


decompiled_code:
__int64 sstream_put()
{
return dstr_append();
}

canonical_decompiled_code:
__int64 func10()
{
return dstr_append();
}

original_code:
int sstream_put(sstream_t *ss, const char *s, int len)
{
 return dstr_append(&ss->out, s, len);
}

canonical_original_code:
int sstream_put(struct sstream_t *ss, char *s, int len)
{
 return dstr_append(&ss->out, s, len);
}


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

if ( *(_DWORD *)(a1 + 52) == 1 )
result = dstr_destroy();
return result;
}

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

if ( *(_DWORD *)(a1 + 52) == 1 )
result = dstr_destroy();
return result;
}

original_code:
void destroy_sstream(sstream_t *ss)
{
 if (ss->type == sstream_out) dstr_destroy(&ss->out);
}

canonical_original_code:
void destroy_sstream(struct sstream_t *ss)
{
 if (ss->type == sstream_out) dstr_destroy(&ss->out);
}


decompiled_code:
__int64 __fastcall serialize_int(__int64 a1, unsigned int *a2)
{
__int64 result; // rax
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 52) )
{
sprintf(v3, "%d%c", *a2, 58LL);
sstream_put_zt(a1, v3);
result = 0LL;
}
else
{
for ( *a2 = 0; ; *a2 = v3[0] + 10 * *a2 - 48 )
{
if ( (unsigned int)sstream_get(a1, v3) || v3[0] == 58 )
return 0LL;
if ( (unsigned __int8)(v3[0] - 48) > 9u )
break;
}
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int *a2)
{
__int64 result; // rax
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 52) )
{
sprintf(v3, "%d%c", *a2, 58LL);
func9(a1, v3);
result = 0LL;
}
else
{
for ( *a2 = 0; ; *a2 = v3[0] + 10 * *a2 - 48 )
{
if ( (unsigned int)func5(a1, v3) || v3[0] == 58 )
return 0LL;
if ( (unsigned __int8)(v3[0] - 48) > 9u )
break;
}
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int serialize_int(sstream_t *ss, int *num)
{
 char sep = ':';
 if (!num) return -1;
 if ((ss->type == sstream_in)) {
  char c;
  int first = 1;
  int sign = 1;
  *num = 0;
  while (sstream_get(ss, &c) == 0) {
   if (c == sep) break;
   if ((c >= '0') && (c <= '9')) *num = 10 * (*num) + (c - '0');
   else {
    switch (c) {
     case '-':
      if (first) sign = -1;
      else return -1;
     case '+':
      if (!first) return -1;
     default:
      return -1;
    }
   }
   first = 0;
  }
  *num = sign * (*num);
 }
 else {
  char tmp[32];
  sprintf(tmp, "%d%c", *num, sep);
  sstream_put_zt(ss, tmp);
 }
 return 0;
}

canonical_original_code:
int serialize_int(struct sstream_t *ss, int *num)
{
 char sep = ':';
 if (!num) return -1;
 if ((ss->type == sstream_in)) {
  char c;
  int first = 1;
  int sign = 1;
  *num = 0;
  while (sstream_get(ss, &c) == 0) {
   if (c == sep) break;
   if ((c >= '0') && (c <= '9')) *num = 10 * (*num) + (c - '0');
   else {
    switch (c) {
     case '-':
      if (first) sign = -1;
      else return -1;
     case '+':
      if (!first) return -1;
     default:
      return -1;
    }
   }
   first = 0;
  }
  *num = sign * (*num);
 }
 else {
  char tmp[32];
  sprintf(tmp, "%d%c", *num, sep);
  sstream_put_zt(ss, tmp);
 }
 return 0;
}

variable_types:
num
int *

variable_types: sep char

variable_types: c char

variable_types: first int

variable_types: sign int

variable_types:
tmp
char [32]


decompiled_code:
__int64 __fastcall serialize_uint(__int64 a1, unsigned int *a2)
{
__int64 result; // rax
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 52) )
{
sprintf(v3, "%u%c", *a2, 58LL);
sstream_put_zt(a1, v3);
result = 0LL;
}
else
{
*a2 = 0;
while ( !(unsigned int)sstream_get(a1, v3) && v3[0] != 58 )
{
if ( (unsigned __int8)(v3[0] - 48) > 9u )
return 0xFFFFFFFFLL;
*a2 = v3[0] + 10 * *a2 - 48;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int *a2)
{
__int64 result; // rax
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 52) )
{
sprintf(v3, "%u%c", *a2, 58LL);
func9(a1, v3);
result = 0LL;
}
else
{
*a2 = 0;
while ( !(unsigned int)func5(a1, v3) && v3[0] != 58 )
{
if ( (unsigned __int8)(v3[0] - 48) > 9u )
return 0xFFFFFFFFLL;
*a2 = v3[0] + 10 * *a2 - 48;
}
result = 0LL;
}
return result;
}

original_code:
int serialize_uint(sstream_t *ss, unsigned int *num)
{
 char sep = ':';
 if (!num) return -1;
 if ((ss->type == sstream_in)) {
  char c;
  *num = 0;
  while (sstream_get(ss, &c) == 0) {
   if (c == sep) break;
   if ((c >= '0') && (c <= '9')) *num = 10 * (*num) + (c - '0');
   else return -1;
  }
 }
 else {
  char tmp[32];
  sprintf(tmp, "%u%c", *num, sep);
  sstream_put_zt(ss, tmp);
 }
 return 0;
}

canonical_original_code:
int serialize_uint(struct sstream_t *ss, unsigned int *num)
{
 char sep = ':';
 if (!num) return -1;
 if ((ss->type == sstream_in)) {
  char c;
  *num = 0;
  while (sstream_get(ss, &c) == 0) {
   if (c == sep) break;
   if ((c >= '0') && (c <= '9')) *num = 10 * (*num) + (c - '0');
   else return -1;
  }
 }
 else {
  char tmp[32];
  sprintf(tmp, "%u%c", *num, sep);
  sstream_put_zt(ss, tmp);
 }
 return 0;
}

variable_types:
num
unsigned int *


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

if ( !a2 )
return 0xFFFFFFFFLL;
if ( (unsigned int)serialize_int(a1, (unsigned int *)(a2 + 8)) )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 52) )
return sstream_put(a1, *(_QWORD *)a2, *(unsigned int *)(a2 + 8));
result = *(unsigned int *)(a2 + 8);
if ( (_DWORD)result )
return sstream_get_str(a1, result, a2);
*(_QWORD *)a2 = 0LL;
return result;
}

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

if ( !a2 )
return 0xFFFFFFFFLL;
if ( (unsigned int)func12(a1, (unsigned int *)(a2 + 8)) )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 52) )
return func10(a1, *(_QWORD *)a2, *(unsigned int *)(a2 + 8));
result = *(unsigned int *)(a2 + 8);
if ( (_DWORD)result )
return func8(a1, result, a2);
*(_QWORD *)a2 = 0LL;
return result;
}

original_code:
int serialize_str(sstream_t *ss, str_t *s)
{
 int res = 0;
 if (!s) return -1;
 if (serialize_int(ss, &s->len) != 0) return -1;
 if ((ss->type == sstream_in)) {
  if (s->len == 0) s->s = ((void *)0);
  else res = sstream_get_str(ss, s->len, s);
 }
 else res = sstream_put(ss, s->s, s->len);
 return res;
}

canonical_original_code:
int serialize_str(struct sstream_t *ss, struct _str *s)
{
 int res = 0;
 if (!s) return -1;
 if (serialize_int(ss, &s->len) != 0) return -1;
 if ((ss->type == sstream_in)) {
  if (s->len == 0) s->s = ((void *)0);
  else res = sstream_get_str(ss, s->len, s);
 }
 else res = sstream_put(ss, s->s, s->len);
 return res;
}

variable_types: struct sstream_t { 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; } out; struct _str { char *s; int len; } in; int in_pos; enum { sstream_in=0, sstream_out=1 } type; } *


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

if ( !a2 )
return 0xFFFFFFFFLL;
if ( (unsigned int)serialize_int(a1, (unsigned int *)(a2 + 8)) )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 52) )
return sstream_put(a1, *(_QWORD *)a2, *(unsigned int *)(a2 + 8));
result = *(unsigned int *)(a2 + 8);
if ( (_DWORD)result )
return sstream_get_str_ex(a1, result, a2);
*(_QWORD *)a2 = 0LL;
return result;
}

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

if ( !a2 )
return 0xFFFFFFFFLL;
if ( (unsigned int)func12(a1, (unsigned int *)(a2 + 8)) )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 52) )
return func10(a1, *(_QWORD *)a2, *(unsigned int *)(a2 + 8));
result = *(unsigned int *)(a2 + 8);
if ( (_DWORD)result )
return func7(a1, result, a2);
*(_QWORD *)a2 = 0LL;
return result;
}

original_code:
int serialize_str_ex(sstream_t *ss, str_t *s)
{
 int res = 0;
 if (!s) return -1;
 if (serialize_int(ss, &s->len) != 0) return -1;
 if ((ss->type == sstream_in)) {
  if (s->len == 0) s->s = ((void *)0);
  else res = sstream_get_str_ex(ss, s->len, s);
 }
 else res = sstream_put(ss, s->s, s->len);
 return res;
}

canonical_original_code:
int serialize_str_ex(struct sstream_t *ss, struct _str *s)
{
 int res = 0;
 if (!s) return -1;
 if (serialize_int(ss, &s->len) != 0) return -1;
 if ((ss->type == sstream_in)) {
  if (s->len == 0) s->s = ((void *)0);
  else res = sstream_get_str_ex(ss, s->len, s);
 }
 else res = sstream_put(ss, s->s, s->len);
 return res;
}


decompiled_code:
__int64 __fastcall serialize_uchar(__int64 a1, _BYTE *a2)
{
if ( !a2 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 52) )
return sstream_put(a1, a2, 1LL);
return sstream_get(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, _BYTE *a2)
{
if ( !a2 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 52) )
return func10(a1, a2, 1LL);
return func5(a1, a2);
}

original_code:
int serialize_uchar(sstream_t *ss, unsigned char *c)
{
 if (!c) return -1;
 if ((ss->type == sstream_in)) return sstream_get(ss, (char *)c);
 else return sstream_put(ss, (char *)c, 1);
}

canonical_original_code:
int serialize_uchar(struct sstream_t *ss, unsigned char *c)
{
 if (!c) return -1;
 if ((ss->type == sstream_in)) return sstream_get(ss, (char *)c);
 else return sstream_put(ss, (char *)c, 1);
}

variable_types:
c
unsigned char *


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

if ( a2 == 1 )
return (unsigned int)((int)fixup_spve_null() >> 31);
result = 0LL;
if ( a2 == 2 )
result = (unsigned int)((int)fixup_igp_null(a1, 1LL) >> 31);
return result;
}

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

if ( a2 == 1 )
return (unsigned int)((int)fixup_spve_null() >> 31);
result = 0LL;
if ( a2 == 2 )
result = (unsigned int)((int)fixup_igp_null(a1, 1LL) >> 31);
return result;
}

original_code:
static int fixup_time_period_match(void** param, int param_no)
{
 if(param_no==1)
 {
  if(fixup_spve_null(param, 1)<0)
   return -1;
  return 0;
 } else if(param_no==2) {
  if(fixup_igp_null(param, 1)<0)
   return -1;
 }
 return 0;
}

canonical_original_code:
static int fixup_time_period_match(void **param, int param_no)
{
 if(param_no==1)
 {
  if(fixup_spve_null(param, 1)<0)
   return -1;
  return 0;
 } else if(param_no==2) {
  if(fixup_igp_null(param, 1)<0)
   return -1;
 }
 return 0;
}

variable_types:
param
void **


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

result = 0LL;
if ( (_DWORD)a2 == 1 )
result = fixup_igp_null(a1, a2);
return result;
}

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

result = 0LL;
if ( (_DWORD)a2 == 1 )
result = fixup_igp_null(a1, a2);
return result;
}

original_code:
static int fixup_is_leap_year(void** param, int param_no)
{
 if(param_no==1)
  return fixup_igp_null(param, param_no);
 return 0;
}

canonical_original_code:
static int fixup_is_leap_year(void **param, int param_no)
{
 if(param_no==1)
  return fixup_igp_null(param, param_no);
 return 0;
}


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

if ( a2 == 1 )
return (unsigned int)((int)fixup_spve_null() >> 31);
result = 0LL;
if ( a2 == 2 )
result = (unsigned int)((int)fixup_igp_null(a1, 1LL) >> 31);
return result;
}

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

if ( a2 == 1 )
return (unsigned int)((int)fixup_spve_null() >> 31);
result = 0LL;
if ( a2 == 2 )
result = (unsigned int)((int)fixup_igp_null(a1, 1LL) >> 31);
return result;
}

original_code:
static int fixup_tmrec_match(void** param, int param_no)
{
 if(param_no==1)
 {
  if(fixup_spve_null(param, 1)<0)
   return -1;
  return 0;
 } else if(param_no==2) {
  if(fixup_igp_null(param, 1)<0)
   return -1;
 }
 return 0;
}

canonical_original_code:
static int fixup_tmrec_match(void **param, int param_no)
{
 if(param_no==1)
 {
  if(fixup_spve_null(param, 1)<0)
   return -1;
  return 0;
 } else if(param_no==2) {
  if(fixup_igp_null(param, 1)<0)
   return -1;
 }
 return 0;
}


decompiled_code:
__int64 mod_init()
{
if ( tmrec_separator_param )
tmrec_separator = *tmrec_separator_param;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
if ( tmrec_separator_param )
tmrec_separator = *tmrec_separator_param;
return 0LL;
}

original_code:
static int mod_init(void)
{
 if(tmrec_separator_param!=((void *)0))
  tmrec_separator = tmrec_separator_param[0];
 return 0;
}

canonical_original_code:
static int mod_init()
{
 if(tmrec_separator_param!=((void *)0))
  tmrec_separator = tmrec_separator_param[0];
 return 0;
}


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

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

original_code:
static int child_init(int rank)
{
 if (rank!=0)
  return 0;
 return 0;
}

variable_types: rank int


decompiled_code:
void mod_destroy()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
static void mod_destroy(void)
{
 return;
}

canonical_original_code:
static void mod_destroy()
{
 return;
}


strlower

original_code:
static inline void strlower(str* _s)
{
 int i;
 for(i = 0; i < _s->len; i++) {
  _s->s[i] = tolower(_s->s[i]);
 }
}

canonical_original_code:
static inline void strlower(struct _str *_s)
{
 int i;
 for(i = 0; i < _s->len; i++) {
  _s->s[i] = tolower(_s->s[i]);
 }
}

variable_types: i int


decompiled_code:
__int64 __fastcall extract_aor(const char **a1, __int64 a2, char *a3)
{
char *v4; // rbx
int v5; // er8
int v6; // edx
int v7; // er12
int v8; // er13
__int64 result; // rax
int v10; // edi
const char *v11; // r13
int v12; // er12
const char *v13; // r15
unsigned int v14; // eax
int v15; // esi
const char *v16; // rbx
unsigned int v17; // eax
int v18; // er14
const char *v19; // r14
unsigned int v20; // eax
const char *v21; // r15
int v22; // er14
const char *v23; // r14
unsigned int v24; // eax
char *v25; // [rsp+8h] [rbp-1D0h]
char v26; // [rsp+10h] [rbp-1C8h] BYREF
__int64 v27; // [rsp+190h] [rbp-48h] BYREF
int v28; // [rsp+198h] [rbp-40h]

memset(aor_buf_3, 0, sizeof(aor_buf_3));
v4 = &v26;
if ( a3 )
v4 = a3;
if ( (int)parse_uri(*a1, *((unsigned int *)a1 + 2), v4) < 0 )
{
rerrno = 11;
v10 = get_debug_level("registrar", 9LL);
result = 0xFFFFFFFFLL;
if ( v10 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v11 = *a1;
v12 = *((_DWORD *)a1 + 2);
v13 = (const char *)*((_QWORD *)&log_level_info + 8);
v14 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): failed to parse AoR [%.*s]\n",
process_no,
v14,
v13,
"registrar [common.c:69]: ",
"extract_aor",
v12,
v11);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): failed to parse AoR [%.*s]\n",
*((_QWORD *)&log_level_info + 8),
"registrar [common.c:69]: ",
"extract_aor",
*((unsigned int *)a1 + 2),
*a1);
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
else
{
v5 = *((_DWORD *)v4 + 2);
v6 = *((_DWORD *)v4 + 10);
if ( v6 > 128 || v5 > 64 || v6 + v5 > 255 )
{
rerrno = 10;
v15 = get_debug_level("registrar", 9LL);
result = 4294967294LL;
if ( v15 >= -1 )
{
result = 4294967294LL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v16 = (const char *)*((_QWORD *)&log_level_info + 8);
v17 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): Address Of Record too long\n",
process_no,
v17,
v16,
"registrar [common.c:77]: ",
"extract_aor");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): Address Of Record too long\n",
*((const char **)&log_level_info + 8),
"registrar [common.c:77]: ",
"extract_aor");
}
--dprint_crit;
result = 4294967294LL;
}
}
}
else
{
*(_QWORD *)a2 = aor_buf_3;
*(_DWORD *)(a2 + 8) = *((_DWORD *)v4 + 2);
if ( (int)un_escape(v4, a2) < 0 )
{
rerrno = 24;
v18 = get_debug_level("registrar", 9LL);
result = 4294967293LL;
if ( v18 >= -1 )
{
result = 4294967293LL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v19 = (const char *)*((_QWORD *)&log_level_info + 8);
v20 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): failed to unescape username\n",
process_no,
v20,
v19,
"registrar [common.c:86]: ",
"extract_aor");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): failed to unescape username\n",
*((const char **)&log_level_info + 8),
"registrar [common.c:86]: ",
"extract_aor");
}
--dprint_crit;
result = 4294967293LL;
}
}
}
else
{
v7 = *(_DWORD *)(a2 + 8);
if ( reg_use_domain )
{
if ( v7 )
{
*(_DWORD *)(a2 + 8) = v7 + 1;
aor_buf_3[v7] = 64;
}
v8 = *((_DWORD *)registrar_cfg + 2);
if ( v8 <= 0 )
goto LABEL_11;
v21 = (const char *)*registrar_cfg;
if ( (int)get_debug_level("registrar", 9LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v23 = (const char *)*((_QWORD *)&log_level_info + 16);
v24 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): realm prefix is [%.*s]\n",
process_no,
v24,
v23,
"registrar [common.c:99]: ",
"extract_aor",
v8,
v21);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): realm prefix is [%.*s]\n",
*((_QWORD *)&log_level_info + 16),
"registrar [common.c:99]: ",
"extract_aor",
(unsigned int)v8,
v21);
}
--dprint_crit;
}
v22 = *((_DWORD *)v4 + 10);
if ( v8 < v22 && (v25 = (char *)*((_QWORD *)v4 + 4), !memcmp(v21, v25, v8)) )
{
memcpy(&aor_buf_3[*(int *)(a2 + 8)], &v25[v8], v22 - v8);
*(_DWORD *)(a2 + 8) += *((_DWORD *)v4 + 10) - v8;
}
else
{
LABEL_11:
memcpy(&aor_buf_3[*(int *)(a2 + 8)], *((const void **)v4 + 4), *((int *)v4 + 10));
*(_DWORD *)(a2 + 8) += *((_DWORD *)v4 + 10);
}
}
if ( *((_DWORD *)registrar_cfg + 10) && v7 )
{
v27 = *(_QWORD *)a2 + v7 + 1LL;
v28 = *(_DWORD *)(a2 + 8) - (v7 + 1);
strlower((__int64)&v27);
result = 0LL;
}
else
{
strlower(a2);
result = 0LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char **a1, __int64 a2, char *a3)
{
char *v4; // rbx
int v5; // er8
int v6; // edx
int v7; // er12
int v8; // er13
__int64 result; // rax
int v10; // edi
const char *v11; // r13
int v12; // er12
const char *v13; // r15
unsigned int v14; // eax
int v15; // esi
const char *v16; // rbx
unsigned int v17; // eax
int v18; // er14
const char *v19; // r14
unsigned int v20; // eax
const char *v21; // r15
int v22; // er14
const char *v23; // r14
unsigned int v24; // eax
char *v25; // [rsp+8h] [rbp-1D0h]
char v26; // [rsp+10h] [rbp-1C8h] BYREF
__int64 v27; // [rsp+190h] [rbp-48h] BYREF
int v28; // [rsp+198h] [rbp-40h]

memset(aor_buf_3, 0, sizeof(aor_buf_3));
v4 = &v26;
if ( a3 )
v4 = a3;
if ( (int)parse_uri(*a1, *((unsigned int *)a1 + 2), v4) < 0 )
{
rerrno = 11;
v10 = get_debug_level("registrar", 9LL);
result = 0xFFFFFFFFLL;
if ( v10 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v11 = *a1;
v12 = *((_DWORD *)a1 + 2);
v13 = (const char *)*((_QWORD *)&log_level_info + 8);
v14 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): failed to parse AoR [%.*s]\n",
process_no,
v14,
v13,
"registrar [common.c:69]: ",
"extract_aor",
v12,
v11);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): failed to parse AoR [%.*s]\n",
*((_QWORD *)&log_level_info + 8),
"registrar [common.c:69]: ",
"extract_aor",
*((unsigned int *)a1 + 2),
*a1);
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
else
{
v5 = *((_DWORD *)v4 + 2);
v6 = *((_DWORD *)v4 + 10);
if ( v6 > 128 || v5 > 64 || v6 + v5 > 255 )
{
rerrno = 10;
v15 = get_debug_level("registrar", 9LL);
result = 4294967294LL;
if ( v15 >= -1 )
{
result = 4294967294LL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v16 = (const char *)*((_QWORD *)&log_level_info + 8);
v17 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): Address Of Record too long\n",
process_no,
v17,
v16,
"registrar [common.c:77]: ",
"extract_aor");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): Address Of Record too long\n",
*((const char **)&log_level_info + 8),
"registrar [common.c:77]: ",
"extract_aor");
}
--dprint_crit;
result = 4294967294LL;
}
}
}
else
{
*(_QWORD *)a2 = aor_buf_3;
*(_DWORD *)(a2 + 8) = *((_DWORD *)v4 + 2);
if ( (int)func1(v4, a2) < 0 )
{
rerrno = 24;
v18 = get_debug_level("registrar", 9LL);
result = 4294967293LL;
if ( v18 >= -1 )
{
result = 4294967293LL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v19 = (const char *)*((_QWORD *)&log_level_info + 8);
v20 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): failed to unescape username\n",
process_no,
v20,
v19,
"registrar [common.c:86]: ",
"extract_aor");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): failed to unescape username\n",
*((const char **)&log_level_info + 8),
"registrar [common.c:86]: ",
"extract_aor");
}
--dprint_crit;
result = 4294967293LL;
}
}
}
else
{
v7 = *(_DWORD *)(a2 + 8);
if ( reg_use_domain )
{
if ( v7 )
{
*(_DWORD *)(a2 + 8) = v7 + 1;
aor_buf_3[v7] = 64;
}
v8 = *((_DWORD *)registrar_cfg + 2);
if ( v8 <= 0 )
goto LABEL_11;
v21 = (const char *)*registrar_cfg;
if ( (int)get_debug_level("registrar", 9LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v23 = (const char *)*((_QWORD *)&log_level_info + 16);
v24 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): realm prefix is [%.*s]\n",
process_no,
v24,
v23,
"registrar [common.c:99]: ",
"extract_aor",
v8,
v21);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): realm prefix is [%.*s]\n",
*((_QWORD *)&log_level_info + 16),
"registrar [common.c:99]: ",
"extract_aor",
(unsigned int)v8,
v21);
}
--dprint_crit;
}
v22 = *((_DWORD *)v4 + 10);
if ( v8 < v22 && (v25 = (char *)*((_QWORD *)v4 + 4), !memcmp(v21, v25, v8)) )
{
memcpy(&aor_buf_3[*(int *)(a2 + 8)], &v25[v8], v22 - v8);
*(_DWORD *)(a2 + 8) += *((_DWORD *)v4 + 10) - v8;
}
else
{
LABEL_11:
memcpy(&aor_buf_3[*(int *)(a2 + 8)], *((const void **)v4 + 4), *((int *)v4 + 10));
*(_DWORD *)(a2 + 8) += *((_DWORD *)v4 + 10);
}
}
if ( *((_DWORD *)registrar_cfg + 10) && v7 )
{
v27 = *(_QWORD *)a2 + v7 + 1LL;
v28 = *(_DWORD *)(a2 + 8) - (v7 + 1);
func2((__int64)&v27);
result = 0LL;
}
else
{
func2(a2);
result = 0LL;
}
}
}
}
return result;
}

original_code:
int extract_aor(str* _uri, str* _a, sip_uri_t *_pu)
{
 static char aor_buf[256];
 str tmp;
 sip_uri_t turi;
 sip_uri_t *puri;
 int user_len;
 str *uri;
 str realm_prefix = {0};
 memset(aor_buf, 0, 256);
 uri=_uri;
 if(_pu!=((void *)0))
  puri = _pu;
 else
  puri = &turi;
 if (parse_uri(uri->s, uri->len, puri) < 0) {
  rerrno = R_AOR_PARSE;
  do { if (get_debug_level("registrar", (sizeof("registrar")-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 parse AoR [%.*s]\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("registrar" " [" "common.c" ":" "69" "]: ") , __func__, uri->len, uri->s); 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 parse AoR [%.*s]\n", (log_level_info[((-1)) - (-5)].name), ("registrar" " [" "common.c" ":" "69" "]: ") , __func__, uri->len, uri->s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "failed to parse AoR [%.*s]\n", process_no, my_pid(), ("registrar" " [" "common.c" ":" "69" "]: ") , __func__, uri->len, uri->s); 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 parse AoR [%.*s]\n", ("registrar" " [" "common.c" ":" "69" "]: ") , __func__, uri->len, uri->s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "failed to parse AoR [%.*s]\n", ("registrar" " [" "common.c" ":" "69" "]: ") , __func__, uri->len, uri->s); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if ( (puri->user.len + puri->host.len + 1) > 256
 || puri->user.len > 64
 || puri->host.len > 128 ) {
  rerrno = R_AOR_LEN;
  do { if (get_debug_level("registrar", (sizeof("registrar")-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(): " "Address Of Record too long\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("registrar" " [" "common.c" ":" "77" "]: ") , __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(): " "Address Of Record too long\n", (log_level_info[((-1)) - (-5)].name), ("registrar" " [" "common.c" ":" "77" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "Address Of Record too long\n", process_no, my_pid(), ("registrar" " [" "common.c" ":" "77" "]: ") , __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(): " "Address Of Record too long\n", ("registrar" " [" "common.c" ":" "77" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Address Of Record too long\n", ("registrar" " [" "common.c" ":" "77" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -2;
 }
 _a->s = aor_buf;
 _a->len = puri->user.len;
 if (un_escape(&puri->user, _a) < 0) {
  rerrno = R_UNESCAPE;
  do { if (get_debug_level("registrar", (sizeof("registrar")-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 unescape username\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("registrar" " [" "common.c" ":" "86" "]: ") , __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 unescape username\n", (log_level_info[((-1)) - (-5)].name), ("registrar" " [" "common.c" ":" "86" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "failed to unescape username\n", process_no, my_pid(), ("registrar" " [" "common.c" ":" "86" "]: ") , __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 unescape username\n", ("registrar" " [" "common.c" ":" "86" "]: ") , __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 unescape username\n", ("registrar" " [" "common.c" ":" "86" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -3;
 }
 user_len = _a->len;
 if (reg_use_domain) {
  if (user_len)
   aor_buf[_a->len++] = '@';
   realm_prefix.len = ((struct cfg_group_registrar *)registrar_cfg)->realm_pref.len;
  if(realm_prefix.len>0) {
   realm_prefix.s = ((struct cfg_group_registrar *)registrar_cfg)->realm_pref.s;
   do { if (get_debug_level("registrar", (sizeof("registrar")-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(): " "realm prefix is [%.*s]\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("registrar" " [" "common.c" ":" "99" "]: ") , __func__, realm_prefix.len, (realm_prefix.len>0)?realm_prefix.s:""); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "realm prefix is [%.*s]\n", (log_level_info[((3)) - (-5)].name), ("registrar" " [" "common.c" ":" "99" "]: ") , __func__, realm_prefix.len, (realm_prefix.len>0)?realm_prefix.s:""); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "realm prefix is [%.*s]\n", process_no, my_pid(), ("registrar" " [" "common.c" ":" "99" "]: ") , __func__, realm_prefix.len, (realm_prefix.len>0)?realm_prefix.s:""); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "realm prefix is [%.*s]\n", ("registrar" " [" "common.c" ":" "99" "]: ") , __func__, realm_prefix.len, (realm_prefix.len>0)?realm_prefix.s:""); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "realm prefix is [%.*s]\n", ("registrar" " [" "common.c" ":" "99" "]: ") , __func__, realm_prefix.len, (realm_prefix.len>0)?realm_prefix.s:""); } } (dprint_crit--); } } while(0);
  }
  if (realm_prefix.len>0
    && realm_prefix.len<puri->host.len
    && (memcmp(realm_prefix.s, puri->host.s, realm_prefix.len)==0))
  {
   memcpy(aor_buf + _a->len, puri->host.s + realm_prefix.len,
     puri->host.len - realm_prefix.len);
   _a->len += puri->host.len - realm_prefix.len;
  } else {
   memcpy(aor_buf + _a->len, puri->host.s, puri->host.len);
   _a->len += puri->host.len;
  }
 }
 if (((struct cfg_group_registrar *)registrar_cfg)->case_sensitive && user_len) {
  tmp.s = _a->s + user_len + 1;
  tmp.len = _a->s + _a->len - tmp.s;
  strlower(&tmp);
 } else {
  strlower(_a);
 }
 return 0;
}

canonical_original_code:
int extract_aor(struct _str *_uri, struct _str *_a, struct sip_uri *_pu)
{
 static char aor_buf[256];
 struct _str tmp;
 struct sip_uri turi;
 struct sip_uri *puri;
 int user_len;
 struct _str *uri;
 struct _str realm_prefix = {0};
 memset(aor_buf, 0, 256);
 uri=_uri;
 if(_pu!=((void *)0))
  puri = _pu;
 else
  puri = &turi;
 if (parse_uri(uri->s, uri->len, puri) < 0) {
  rerrno = R_AOR_PARSE;
  do { if (get_debug_level("registrar", (sizeof("registrar")-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 parse AoR [%.*s]\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("registrar" " [" "common.c" ":" "69" "]: ") , __func__, uri->len, uri->s); 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 parse AoR [%.*s]\n", (log_level_info[((-1)) - (-5)].name), ("registrar" " [" "common.c" ":" "69" "]: ") , __func__, uri->len, uri->s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "failed to parse AoR [%.*s]\n", process_no, my_pid(), ("registrar" " [" "common.c" ":" "69" "]: ") , __func__, uri->len, uri->s); 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 parse AoR [%.*s]\n", ("registrar" " [" "common.c" ":" "69" "]: ") , __func__, uri->len, uri->s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "failed to parse AoR [%.*s]\n", ("registrar" " [" "common.c" ":" "69" "]: ") , __func__, uri->len, uri->s); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if ( (puri->user.len + puri->host.len + 1) > 256
 || puri->user.len > 64
 || puri->host.len > 128 ) {
  rerrno = R_AOR_LEN;
  do { if (get_debug_level("registrar", (sizeof("registrar")-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(): " "Address Of Record too long\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("registrar" " [" "common.c" ":" "77" "]: ") , __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(): " "Address Of Record too long\n", (log_level_info[((-1)) - (-5)].name), ("registrar" " [" "common.c" ":" "77" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "Address Of Record too long\n", process_no, my_pid(), ("registrar" " [" "common.c" ":" "77" "]: ") , __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(): " "Address Of Record too long\n", ("registrar" " [" "common.c" ":" "77" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Address Of Record too long\n", ("registrar" " [" "common.c" ":" "77" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -2;
 }
 _a->s = aor_buf;
 _a->len = puri->user.len;
 if (un_escape(&puri->user, _a) < 0) {
  rerrno = R_UNESCAPE;
  do { if (get_debug_level("registrar", (sizeof("registrar")-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 unescape username\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("registrar" " [" "common.c" ":" "86" "]: ") , __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 unescape username\n", (log_level_info[((-1)) - (-5)].name), ("registrar" " [" "common.c" ":" "86" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "failed to unescape username\n", process_no, my_pid(), ("registrar" " [" "common.c" ":" "86" "]: ") , __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 unescape username\n", ("registrar" " [" "common.c" ":" "86" "]: ") , __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 unescape username\n", ("registrar" " [" "common.c" ":" "86" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -3;
 }
 user_len = _a->len;
 if (reg_use_domain) {
  if (user_len)
   aor_buf[_a->len++] = '@';
   realm_prefix.len = ((struct cfg_group_registrar *)registrar_cfg)->realm_pref.len;
  if(realm_prefix.len>0) {
   realm_prefix.s = ((struct cfg_group_registrar *)registrar_cfg)->realm_pref.s;
   do { if (get_debug_level("registrar", (sizeof("registrar")-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(): " "realm prefix is [%.*s]\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("registrar" " [" "common.c" ":" "99" "]: ") , __func__, realm_prefix.len, (realm_prefix.len>0)?realm_prefix.s:""); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "realm prefix is [%.*s]\n", (log_level_info[((3)) - (-5)].name), ("registrar" " [" "common.c" ":" "99" "]: ") , __func__, realm_prefix.len, (realm_prefix.len>0)?realm_prefix.s:""); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "realm prefix is [%.*s]\n", process_no, my_pid(), ("registrar" " [" "common.c" ":" "99" "]: ") , __func__, realm_prefix.len, (realm_prefix.len>0)?realm_prefix.s:""); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "realm prefix is [%.*s]\n", ("registrar" " [" "common.c" ":" "99" "]: ") , __func__, realm_prefix.len, (realm_prefix.len>0)?realm_prefix.s:""); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "realm prefix is [%.*s]\n", ("registrar" " [" "common.c" ":" "99" "]: ") , __func__, realm_prefix.len, (realm_prefix.len>0)?realm_prefix.s:""); } } (dprint_crit--); } } while(0);
  }
  if (realm_prefix.len>0
    && realm_prefix.len<puri->host.len
    && (memcmp(realm_prefix.s, puri->host.s, realm_prefix.len)==0))
  {
   memcpy(aor_buf + _a->len, puri->host.s + realm_prefix.len,
     puri->host.len - realm_prefix.len);
   _a->len += puri->host.len - realm_prefix.len;
  } else {
   memcpy(aor_buf + _a->len, puri->host.s, puri->host.len);
   _a->len += puri->host.len;
  }
 }
 if (((struct cfg_group_registrar *)registrar_cfg)->case_sensitive && user_len) {
  tmp.s = _a->s + user_len + 1;
  tmp.len = _a->s + _a->len - tmp.s;
  strlower(&tmp);
 } else {
  strlower(_a);
 }
 return 0;
}

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

variable_types: struct sip_uri { struct _str { char *s; int len; } 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; } *

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

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

user_defined_types: struct cfg_group_registrar { struct _str realm_pref; unsigned int default_expires; unsigned int default_expires_range; unsigned int min_expires; unsigned int max_expires; unsigned int max_contacts; unsigned int retry_after; unsigned int case_sensitive; int default_q; unsigned int append_branches; }


decompiled_code:
__int64 __fastcall sca_dialog_build_from_tags(char **a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
char *v9; // rdi
int v10; // edx
int v11; // er14
int v12; // eax
char *v13; // rdi
int v14; // eax
char *v15; // rdi
int v16; // eax
int v17; // er8
const char *v19; // rbx
unsigned int v20; // eax

if ( !a1 || (v9 = *a1) == 0LL )
_assert_fail("dialog != NULL && dialog->id.s != NULL", "sca_dialog.c", 0x24u, "sca_dialog_build_from_tags");
if ( !a3 )
_assert_fail("call_id != NULL", "sca_dialog.c", 0x25u, "sca_dialog_build_from_tags");
if ( !a4 )
_assert_fail("from_tag != NULL", "sca_dialog.c", 0x26u, "sca_dialog_build_from_tags");
v10 = *(_DWORD *)(a3 + 8);
v11 = *(_DWORD *)(a4 + 8) + v10;
if ( a5 )
{
if ( *(_QWORD *)a5 )
{
v12 = *(_DWORD *)(a5 + 8);
if ( v12 > 0 )
v11 += v12;
}
}
if ( a2 <= v11 )
{
v11 = -1;
if ( (int)get_debug_level("sca", 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v19 = (const char *)*((_QWORD *)&log_level_info + 8);
v20 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): sca_dialog_build_from_tags: tags too long",
process_no,
v20,
v19,
"sca [sca_dialog.c:46]: ",
"sca_dialog_build_from_tags");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): sca_dialog_build_from_tags: tags too long",
*((const char **)&log_level_info + 8),
"sca [sca_dialog.c:46]: ",
"sca_dialog_build_from_tags");
}
--dprint_crit;
v11 = -1;
}
}
else
{
memcpy(v9, *(const void **)a3, v10);
v13 = *a1;
a1[2] = *a1;
v14 = *(_DWORD *)(a3 + 8);
*((_DWORD *)a1 + 6) = v14;
memcpy(&v13[v14], *(const void **)a4, *(int *)(a4 + 8));
v15 = *a1;
a1[4] = &(*a1)[*(int *)(a3 + 8)];
v16 = *(_DWORD *)(a4 + 8);
*((_DWORD *)a1 + 10) = v16;
if ( a5 )
{
if ( *(_QWORD *)a5 )
{
v17 = *(_DWORD *)(a5 + 8);
if ( v17 > 0 )
{
memcpy(&v15[*(int *)(a3 + 8) + (__int64)v16], *(const void **)a5, v17);
a1[6] = &(*a1)[*(int *)(a4 + 8) + (__int64)*(int *)(a3 + 8)];
*((_DWORD *)a1 + 14) = *(_DWORD *)(a5 + 8);
}
}
}
*((_DWORD *)a1 + 2) = v11;
}
return (unsigned int)v11;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
char *v9; // rdi
int v10; // edx
int v11; // er14
int v12; // eax
char *v13; // rdi
int v14; // eax
char *v15; // rdi
int v16; // eax
int v17; // er8
const char *v19; // rbx
unsigned int v20; // eax

if ( !a1 || (v9 = *a1) == 0LL )
_assert_fail("dialog != NULL && dialog->id.s != NULL", "sca_dialog.c", 0x24u, "sca_dialog_build_from_tags");
if ( !a3 )
_assert_fail("call_id != NULL", "sca_dialog.c", 0x25u, "sca_dialog_build_from_tags");
if ( !a4 )
_assert_fail("from_tag != NULL", "sca_dialog.c", 0x26u, "sca_dialog_build_from_tags");
v10 = *(_DWORD *)(a3 + 8);
v11 = *(_DWORD *)(a4 + 8) + v10;
if ( a5 )
{
if ( *(_QWORD *)a5 )
{
v12 = *(_DWORD *)(a5 + 8);
if ( v12 > 0 )
v11 += v12;
}
}
if ( a2 <= v11 )
{
v11 = -1;
if ( (int)get_debug_level("sca", 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v19 = (const char *)*((_QWORD *)&log_level_info + 8);
v20 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): sca_dialog_build_from_tags: tags too long",
process_no,
v20,
v19,
"sca [sca_dialog.c:46]: ",
"sca_dialog_build_from_tags");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): sca_dialog_build_from_tags: tags too long",
*((const char **)&log_level_info + 8),
"sca [sca_dialog.c:46]: ",
"sca_dialog_build_from_tags");
}
--dprint_crit;
v11 = -1;
}
}
else
{
memcpy(v9, *(const void **)a3, v10);
v13 = *a1;
a1[2] = *a1;
v14 = *(_DWORD *)(a3 + 8);
*((_DWORD *)a1 + 6) = v14;
memcpy(&v13[v14], *(const void **)a4, *(int *)(a4 + 8));
v15 = *a1;
a1[4] = &(*a1)[*(int *)(a3 + 8)];
v16 = *(_DWORD *)(a4 + 8);
*((_DWORD *)a1 + 10) = v16;
if ( a5 )
{
if ( *(_QWORD *)a5 )
{
v17 = *(_DWORD *)(a5 + 8);
if ( v17 > 0 )
{
memcpy(&v15[*(int *)(a3 + 8) + (__int64)v16], *(const void **)a5, v17);
a1[6] = &(*a1)[*(int *)(a4 + 8) + (__int64)*(int *)(a3 + 8)];
*((_DWORD *)a1 + 14) = *(_DWORD *)(a5 + 8);
}
}
}
*((_DWORD *)a1 + 2) = v11;
}
return (unsigned int)v11;
}

original_code:
int
sca_dialog_build_from_tags( sca_dialog *dialog, int maxlen, str *call_id,
 str *from_tag, str *to_tag )
{
    int len = 0;
    ((void) sizeof ((dialog != ((void *)0) && dialog->id.s != ((void *)0)) ? 1 : 0), __extension__ ({ if (dialog != ((void *)0) && dialog->id.s != ((void *)0)) ; else __assert_fail ("dialog != NULL && dialog->id.s != NULL", "sca_dialog.c", 36, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((call_id != ((void *)0)) ? 1 : 0), __extension__ ({ if (call_id != ((void *)0)) ; else __assert_fail ("call_id != NULL", "sca_dialog.c", 37, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((from_tag != ((void *)0)) ? 1 : 0), __extension__ ({ if (from_tag != ((void *)0)) ; else __assert_fail ("from_tag != NULL", "sca_dialog.c", 38, __extension__ __PRETTY_FUNCTION__); }));
    len = call_id->len + from_tag->len;
    if ( !((to_tag) == ((void *)0) || ((to_tag)->s == ((void *)0) || (to_tag)->len <= 0 ))) {
 len += to_tag->len;
    }
    if ( len >= maxlen ) {
 do { if (get_debug_level("sca", (sizeof("sca")-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(): " "sca_dialog_build_from_tags: tags too long", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("sca" " [" "sca_dialog.c" ":" "46" "]: ") , __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(): " "sca_dialog_build_from_tags: tags too long", (log_level_info[((-1)) - (-5)].name), ("sca" " [" "sca_dialog.c" ":" "46" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "sca_dialog_build_from_tags: tags too long", process_no, my_pid(), ("sca" " [" "sca_dialog.c" ":" "46" "]: ") , __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(): " "sca_dialog_build_from_tags: tags too long", ("sca" " [" "sca_dialog.c" ":" "46" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "sca_dialog_build_from_tags: tags too long", ("sca" " [" "sca_dialog.c" ":" "46" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 return( -1 );
    }
    memcpy( dialog->id.s, call_id->s, call_id->len );
    dialog->call_id.s = dialog->id.s;
    dialog->call_id.len = call_id->len;
    memcpy( dialog->id.s + call_id->len, from_tag->s, from_tag->len );
    dialog->from_tag.s = dialog->id.s + call_id->len;
    dialog->from_tag.len = from_tag->len;
    if ( !((to_tag) == ((void *)0) || ((to_tag)->s == ((void *)0) || (to_tag)->len <= 0 ))) {
 memcpy( dialog->id.s + call_id->len + from_tag->len,
  to_tag->s, to_tag->len );
 dialog->to_tag.s = dialog->id.s + call_id->len + from_tag->len;
 dialog->to_tag.len = to_tag->len;
    }
    dialog->id.len = len;
    return( len );
}

canonical_original_code:
int sca_dialog_build_from_tags(struct _sca_dialog *dialog, int maxlen, struct _str *call_id, struct _str *from_tag, struct _str *to_tag)
{
    int len = 0;
    ((void) sizeof ((dialog != ((void *)0) && dialog->id.s != ((void *)0)) ? 1 : 0), __extension__ ({ if (dialog != ((void *)0) && dialog->id.s != ((void *)0)) ; else __assert_fail ("dialog != NULL && dialog->id.s != NULL", "sca_dialog.c", 36, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((call_id != ((void *)0)) ? 1 : 0), __extension__ ({ if (call_id != ((void *)0)) ; else __assert_fail ("call_id != NULL", "sca_dialog.c", 37, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((from_tag != ((void *)0)) ? 1 : 0), __extension__ ({ if (from_tag != ((void *)0)) ; else __assert_fail ("from_tag != NULL", "sca_dialog.c", 38, __extension__ __PRETTY_FUNCTION__); }));
    len = call_id->len + from_tag->len;
    if ( !((to_tag) == ((void *)0) || ((to_tag)->s == ((void *)0) || (to_tag)->len <= 0 ))) {
 len += to_tag->len;
    }
    if ( len >= maxlen ) {
 do { if (get_debug_level("sca", (sizeof("sca")-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(): " "sca_dialog_build_from_tags: tags too long", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("sca" " [" "sca_dialog.c" ":" "46" "]: ") , __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(): " "sca_dialog_build_from_tags: tags too long", (log_level_info[((-1)) - (-5)].name), ("sca" " [" "sca_dialog.c" ":" "46" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "sca_dialog_build_from_tags: tags too long", process_no, my_pid(), ("sca" " [" "sca_dialog.c" ":" "46" "]: ") , __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(): " "sca_dialog_build_from_tags: tags too long", ("sca" " [" "sca_dialog.c" ":" "46" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "sca_dialog_build_from_tags: tags too long", ("sca" " [" "sca_dialog.c" ":" "46" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 return( -1 );
    }
    memcpy( dialog->id.s, call_id->s, call_id->len );
    dialog->call_id.s = dialog->id.s;
    dialog->call_id.len = call_id->len;
    memcpy( dialog->id.s + call_id->len, from_tag->s, from_tag->len );
    dialog->from_tag.s = dialog->id.s + call_id->len;
    dialog->from_tag.len = from_tag->len;
    if ( !((to_tag) == ((void *)0) || ((to_tag)->s == ((void *)0) || (to_tag)->len <= 0 ))) {
 memcpy( dialog->id.s + call_id->len + from_tag->len,
  to_tag->s, to_tag->len );
 dialog->to_tag.s = dialog->id.s + call_id->len + from_tag->len;
 dialog->to_tag.len = to_tag->len;
    }
    dialog->id.len = len;
    return( len );
}

variable_types: struct _sca_dialog { struct _str { char *s; int len; } id; struct _str call_id; struct _str from_tag; struct _str to_tag; int notify_cseq; int subscribe_cseq; } *

variable_types: maxlen int

variable_types: len int

user_defined_types: struct _sca_dialog { struct _str id; struct _str call_id; struct _str from_tag; struct _str to_tag; int notify_cseq; int subscribe_cseq; }