decompiled_code:
__int64 __fastcall get_pres_rules_action(__int64 **a1, __int64 a2, char *a3)
{
__int64 *v3; // r14
unsigned int v5; // er13
unsigned int v6; // ebp
const char *v7; // rcx
const char *v8; // rdx
const char *v10; // rcx
const char *v11; // rdx
__int64 v12; // r9
const char *v13; // rsi
const char *v14; // rdx
int v15; // edi
const char *v16; // r15
unsigned int v17; // eax
__int64 v18; // rdx
const char *v19; // r8
const char *v20; // rsi
const char *v21; // rdx
int v22; // edi
const char *v23; // r15
unsigned int v24; // eax
__int64 v25; // rdx
const char *v26; // r8
const char *v28; // [rsp+8h] [rbp-50h]
const char *v29; // [rsp+8h] [rbp-50h]
const char *v30; // [rsp+10h] [rbp-48h]
const char *v31; // [rsp+10h] [rbp-48h]
const char *v32; // [rsp+20h] [rbp-38h]

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 **a1, __int64 a2, char *a3)
{
__int64 *v3; // r14
unsigned int v5; // er13
unsigned int v6; // ebp
const char *v7; // rcx
const char *v8; // rdx
const char *v10; // rcx
const char *v11; // rdx
__int64 v12; // r9
const char *v13; // rsi
const char *v14; // rdx
int v15; // edi
const char *v16; // r15
unsigned int v17; // eax
__int64 v18; // rdx
const char *v19; // r8
const char *v20; // rsi
const char *v21; // rdx
int v22; // edi
const char *v23; // r15
unsigned int v24; // eax
__int64 v25; // rdx
const char *v26; // r8
const char *v28; // [rsp+8h] [rbp-50h]
const char *v29; // [rsp+8h] [rbp-50h]
const char *v30; // [rsp+10h] [rbp-48h]
const char *v31; // [rsp+10h] [rbp-48h]
const char *v32; // [rsp+20h] [rbp-38h]

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

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

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

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

variable_types:
wuri
struct _str *

variable_types: enum sub_handling_t { sub_handling_block=0, sub_handling_confirm=1, sub_handling_polite_block=2, sub_handling_allow=3 } *

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


repo: virtualolson/who

decompiled_code:
__int64 __fastcall free_pres_rules(__int64 a1)
{
return free_common_rules(a1, free_pres_actions);
}

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

original_code:
void free_pres_rules(cp_ruleset_t *r)
{
 free_common_rules(r, free_pres_actions);
}

canonical_original_code:
void free_pres_rules(struct cp_ruleset_t *r)
{
 free_common_rules(r, free_pres_actions);
}

return_type: void

user_defined_types: struct cp_ruleset_t { struct _cp_rule_t *rules; }

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

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

user_defined_types: struct cp_actions_t { struct _cp_unknown_t *unknown; }

user_defined_types: struct cp_transformations_t { struct _cp_unknown_t *unknown; }

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

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall free_cseq(__int64 a1)
{
return qm_free(mem_block, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return qm_free(mem_block, a1);
}

original_code:
void free_cseq(struct cseq_body* const cb)
{
 qm_free(mem_block, (cb));
}

canonical_original_code:
void free_cseq(struct cseq_body *cb)
{
 qm_free(mem_block, (cb));
}

variable_types: struct cseq_body { int error; struct _str { char *s; int len; } number; struct _str method; unsigned int method_id; } *

user_defined_types: struct cseq_body { int error; struct _str number; struct _str method; unsigned int method_id; }


decompiled_code:
__int64 __fastcall fix_send_to(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4)
{
__int64 result; // rax
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = 16 * *a4;
fix_timeout("tcp_send_timeout", v6, 0xA0u, 0x7FFFFFFFu);
result = 0LL;
*(_QWORD *)a4 = (int)v6[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4)
{
__int64 result; // rax
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = 16 * *a4;
func0("tcp_send_timeout", v6, 0xA0u, 0x7FFFFFFFu);
result = 0LL;
*(_QWORD *)a4 = (int)v6[0];
return result;
}

original_code:
static int fix_send_to(void* cfg_h, str* gname, str* name, void** val)
{
 int v;
 v=(((int)(long)*val)*16U);
 fix_timeout("tcp_send_timeout", &v, ((10)*16U),
      ((1U<<(sizeof(ticks_t)*8-1))-1));
 *val=(void*)(long)v;
 return 0;
}

canonical_original_code:
static int fix_send_to(void *cfg_h, struct _str *gname, struct _str *name, void **val)
{
 int v;
 v=(((int)(long)*val)*16U);
 fix_timeout("tcp_send_timeout", &v, ((10)*16U),
      ((1U<<(sizeof(ticks_t)*8-1))-1));
 *val=(void *)(long)v;
 return 0;
}

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

variable_types:
name
struct _str *

variable_types:
val
void **

variable_types: v int

return_type: int


decompiled_code:
__int64 __fastcall fix_connect_to(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 result; // rax
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = *a4;
fix_timeout("tcp_connect_timeout", v6, 0xAu, 0x7FFFFFFu);
result = 0LL;
*a4 = (int)v6[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 result; // rax
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = *a4;
func0("tcp_connect_timeout", v6, 0xAu, 0x7FFFFFFu);
result = 0LL;
*a4 = (int)v6[0];
return result;
}

original_code:
static int fix_connect_to(void* cfg_h, str* gname, str* name, void** val)
{
 int v;
 v=(int)(long)*val;
 fix_timeout("tcp_connect_timeout", &v, 10,
      ((((1U<<(sizeof(ticks_t)*8-1))-1))/16U));
 *val=(void*)(long)v;
 return 0;
}

canonical_original_code:
static int fix_connect_to(void *cfg_h, struct _str *gname, struct _str *name, void **val)
{
 int v;
 v=(int)(long)*val;
 fix_timeout("tcp_connect_timeout", &v, 10,
      ((((1U<<(sizeof(ticks_t)*8-1))-1))/16U));
 *val=(void *)(long)v;
 return 0;
}


decompiled_code:
__int64 __fastcall fix_max_tls_conns(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 result; // rax
const char *v6; // rbp
unsigned int v7; // eax
struct _IO_FILE *v8; // rdi

if ( tls_max_connections < (int)*a4 )
{
if ( (int)get_debug_level("core", 4LL) > 1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(2LL);
v6 = (const char *)*((_QWORD *)&log_level_info + 14);
v7 = my_pid();
v8 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cannot override hard tls_max_connections limit, please restart and increase tls_max_connec"
"tions in the cfg.\n",
process_no,
v7,
v6,
"<core> [tcp_options.c:269]: ",
"fix_max_tls_conns");
if ( log_color )
((void (__fastcall *)(struct _IO_FILE *, const char *))dprint_color_reset)(
v8,
"%2d(%d) %s: %s%s(): cannot override hard tls_max_connections limit, please restart and increase tls_max_conn"
"ections in the cfg.\n");
}
else
{
syslog(
*((_DWORD *)&log_level_info + 30) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot override hard tls_max_connections limit, please restart and increase tls_max_connections in the cfg.\n",
*((const char **)&log_level_info + 14),
"<core> [tcp_options.c:269]: ",
"fix_max_tls_conns");
}
--dprint_crit;
}
result = 0LL;
*a4 = tls_max_connections;
}
else
{
*a4 = (int)*a4;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 result; // rax
const char *v6; // rbp
unsigned int v7; // eax
struct _IO_FILE *v8; // rdi

if ( tls_max_connections < (int)*a4 )
{
if ( (int)get_debug_level("core", 4LL) > 1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(2LL);
v6 = (const char *)*((_QWORD *)&log_level_info + 14);
v7 = my_pid();
v8 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cannot override hard tls_max_connections limit, please restart and increase tls_max_connec"
"tions in the cfg.\n",
process_no,
v7,
v6,
"<core> [tcp_options.c:269]: ",
"fix_max_tls_conns");
if ( log_color )
((void (__fastcall *)(struct _IO_FILE *, const char *))dprint_color_reset)(
v8,
"%2d(%d) %s: %s%s(): cannot override hard tls_max_connections limit, please restart and increase tls_max_conn"
"ections in the cfg.\n");
}
else
{
syslog(
*((_DWORD *)&log_level_info + 30) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot override hard tls_max_connections limit, please restart and increase tls_max_connections in the cfg.\n",
*((const char **)&log_level_info + 14),
"<core> [tcp_options.c:269]: ",
"fix_max_tls_conns");
}
--dprint_crit;
}
result = 0LL;
*a4 = tls_max_connections;
}
else
{
*a4 = (int)*a4;
result = 0LL;
}
return result;
}

original_code:
static int fix_max_tls_conns(void* cfg_h, str* gname, str* name, void** val)
{
 int v;
 v=(int)(long)*val;
 if (v>tls_max_connections){
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((2)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((2)) >= -5) && (((2)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((2)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "cannot override hard tls_max_connections limit, please" " restart and increase tls_max_connections in the cfg.\n", process_no, my_pid(), (log_level_info[((2)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "269" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((2)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "cannot override hard tls_max_connections limit, please" " restart and increase tls_max_connections in the cfg.\n", (log_level_info[((2)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "269" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((2)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot override hard tls_max_connections limit, please" " restart and increase tls_max_connections in the cfg.\n", process_no, my_pid(), ("<core> [" "tcp_options.c" ":" "269" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((2))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot override hard tls_max_connections limit, please" " restart and increase tls_max_connections in the cfg.\n", ("<core> [" "tcp_options.c" ":" "269" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot override hard tls_max_connections limit, please" " restart and increase tls_max_connections in the cfg.\n", ("<core> [" "tcp_options.c" ":" "269" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  v=tls_max_connections;
 }
 *val=(void*)(long)v;
 return 0;
}

canonical_original_code:
static int fix_max_tls_conns(void *cfg_h, struct _str *gname, struct _str *name, void **val)
{
 int v;
 v=(int)(long)*val;
 if (v>tls_max_connections){
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((2)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((2)) >= -5) && (((2)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((2)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "cannot override hard tls_max_connections limit, please" " restart and increase tls_max_connections in the cfg.\n", process_no, my_pid(), (log_level_info[((2)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "269" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((2)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "cannot override hard tls_max_connections limit, please" " restart and increase tls_max_connections in the cfg.\n", (log_level_info[((2)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "269" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((2)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot override hard tls_max_connections limit, please" " restart and increase tls_max_connections in the cfg.\n", process_no, my_pid(), ("<core> [" "tcp_options.c" ":" "269" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((2))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot override hard tls_max_connections limit, please" " restart and increase tls_max_connections in the cfg.\n", ("<core> [" "tcp_options.c" ":" "269" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot override hard tls_max_connections limit, please" " restart and increase tls_max_connections in the cfg.\n", ("<core> [" "tcp_options.c" ":" "269" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  v=tls_max_connections;
 }
 *val=(void *)(long)v;
 return 0;
}

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


decompiled_code:
__int64 __fastcall fix_max_conns(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 result; // rax
const char *v6; // rbp
unsigned int v7; // eax
struct _IO_FILE *v8; // rdi

if ( tcp_max_connections < (int)*a4 )
{
if ( (int)get_debug_level("core", 4LL) > 1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(2LL);
v6 = (const char *)*((_QWORD *)&log_level_info + 14);
v7 = my_pid();
v8 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cannot override hard tcp_max_connections limit, please restart and increase tcp_max_connec"
"tions in the cfg.\n",
process_no,
v7,
v6,
"<core> [tcp_options.c:248]: ",
"fix_max_conns");
if ( log_color )
dprint_color_reset(
v8,
"%2d(%d) %s: %s%s(): cannot override hard tcp_max_connections limit, please restart and increase tcp_max_conn"
"ections in the cfg.\n");
}
else
{
syslog(
*((_DWORD *)&log_level_info + 30) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot override hard tcp_max_connections limit, please restart and increase tcp_max_connections in the cfg.\n",
*((const char **)&log_level_info + 14),
"<core> [tcp_options.c:248]: ",
"fix_max_conns");
}
--dprint_crit;
}
result = 0LL;
*a4 = tcp_max_connections;
}
else
{
*a4 = (int)*a4;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 result; // rax
const char *v6; // rbp
unsigned int v7; // eax
struct _IO_FILE *v8; // rdi

if ( tcp_max_connections < (int)*a4 )
{
if ( (int)get_debug_level("core", 4LL) > 1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(2LL);
v6 = (const char *)*((_QWORD *)&log_level_info + 14);
v7 = my_pid();
v8 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cannot override hard tcp_max_connections limit, please restart and increase tcp_max_connec"
"tions in the cfg.\n",
process_no,
v7,
v6,
"<core> [tcp_options.c:248]: ",
"fix_max_conns");
if ( log_color )
dprint_color_reset(
v8,
"%2d(%d) %s: %s%s(): cannot override hard tcp_max_connections limit, please restart and increase tcp_max_conn"
"ections in the cfg.\n");
}
else
{
syslog(
*((_DWORD *)&log_level_info + 30) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot override hard tcp_max_connections limit, please restart and increase tcp_max_connections in the cfg.\n",
*((const char **)&log_level_info + 14),
"<core> [tcp_options.c:248]: ",
"fix_max_conns");
}
--dprint_crit;
}
result = 0LL;
*a4 = tcp_max_connections;
}
else
{
*a4 = (int)*a4;
result = 0LL;
}
return result;
}

original_code:
static int fix_max_conns(void* cfg_h, str* gname, str* name, void** val)
{
 int v;
 v=(int)(long)*val;
 if (v>tcp_max_connections){
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((2)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((2)) >= -5) && (((2)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((2)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "cannot override hard tcp_max_connections limit, please" " restart and increase tcp_max_connections in the cfg.\n", process_no, my_pid(), (log_level_info[((2)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "248" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((2)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "cannot override hard tcp_max_connections limit, please" " restart and increase tcp_max_connections in the cfg.\n", (log_level_info[((2)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "248" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((2)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot override hard tcp_max_connections limit, please" " restart and increase tcp_max_connections in the cfg.\n", process_no, my_pid(), ("<core> [" "tcp_options.c" ":" "248" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((2))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot override hard tcp_max_connections limit, please" " restart and increase tcp_max_connections in the cfg.\n", ("<core> [" "tcp_options.c" ":" "248" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot override hard tcp_max_connections limit, please" " restart and increase tcp_max_connections in the cfg.\n", ("<core> [" "tcp_options.c" ":" "248" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  v=tcp_max_connections;
 }
 *val=(void*)(long)v;
 return 0;
}

canonical_original_code:
static int fix_max_conns(void *cfg_h, struct _str *gname, struct _str *name, void **val)
{
 int v;
 v=(int)(long)*val;
 if (v>tcp_max_connections){
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((2)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((2)) >= -5) && (((2)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((2)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "cannot override hard tcp_max_connections limit, please" " restart and increase tcp_max_connections in the cfg.\n", process_no, my_pid(), (log_level_info[((2)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "248" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((2)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "cannot override hard tcp_max_connections limit, please" " restart and increase tcp_max_connections in the cfg.\n", (log_level_info[((2)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "248" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((2)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot override hard tcp_max_connections limit, please" " restart and increase tcp_max_connections in the cfg.\n", process_no, my_pid(), ("<core> [" "tcp_options.c" ":" "248" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((2))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot override hard tcp_max_connections limit, please" " restart and increase tcp_max_connections in the cfg.\n", ("<core> [" "tcp_options.c" ":" "248" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot override hard tcp_max_connections limit, please" " restart and increase tcp_max_connections in the cfg.\n", ("<core> [" "tcp_options.c" ":" "248" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  v=tcp_max_connections;
 }
 *val=(void *)(long)v;
 return 0;
}


decompiled_code:
__int64 init_tcp_options()
{
int v0; // edx
int v1; // ecx
__int64 result; // rax

v0 = tcp_max_connections;
v1 = tls_max_connections;
result = 0xA00000000ALL;
tcp_default_cfg = 0xA00000000ALL;
*((_DWORD *)&tcp_default_cfg + 2) = 1920;
*((_DWORD *)&tcp_default_cfg + 3) = v0;
*((_DWORD *)&tcp_default_cfg + 4) = v1;
*(&tcp_default_cfg + 3) = 0x100000001LL;
*(&tcp_default_cfg + 4) = 0x800000000001LL;
*((_DWORD *)&tcp_default_cfg + 10) = 10485760;
*((_DWORD *)&tcp_default_cfg + 15) = 1;
*((_DWORD *)&tcp_default_cfg + 12) = 1;
*(__int64 *)((char *)&tcp_default_cfg + 76) = 1LL;
*(__int64 *)((char *)&tcp_default_cfg + 84) = 0x200000001LL;
*(&tcp_default_cfg + 12) = 0x83400001000LL;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // edx
int v1; // ecx
__int64 result; // rax

v0 = tcp_max_connections;
v1 = tls_max_connections;
result = 0xA00000000ALL;
tcp_default_cfg = 0xA00000000ALL;
*((_DWORD *)&tcp_default_cfg + 2) = 1920;
*((_DWORD *)&tcp_default_cfg + 3) = v0;
*((_DWORD *)&tcp_default_cfg + 4) = v1;
*(&tcp_default_cfg + 3) = 0x100000001LL;
*(&tcp_default_cfg + 4) = 0x800000000001LL;
*((_DWORD *)&tcp_default_cfg + 10) = 10485760;
*((_DWORD *)&tcp_default_cfg + 15) = 1;
*((_DWORD *)&tcp_default_cfg + 12) = 1;
*(__int64 *)((char *)&tcp_default_cfg + 76) = 1LL;
*(__int64 *)((char *)&tcp_default_cfg + 84) = 0x200000001LL;
*(&tcp_default_cfg + 12) = 0x83400001000LL;
return result;
}

original_code:
void init_tcp_options()
{
 tcp_default_cfg.connect_timeout_s=10;
 tcp_default_cfg.send_timeout=((10)*16U);
 tcp_default_cfg.con_lifetime=((120)*16U);
 tcp_default_cfg.max_connections=tcp_max_connections;
 tcp_default_cfg.max_tls_connections=tls_max_connections;
 tcp_default_cfg.async=1;
 tcp_default_cfg.tcpconn_wq_max=32*1024;
 tcp_default_cfg.tcp_wq_max=10*1024*1024;
 tcp_default_cfg.tcp_connect_wait=1;
 tcp_default_cfg.fd_cache=1;
 tcp_default_cfg.keepalive=1;
 tcp_default_cfg.delayed_ack=1;
 tcp_default_cfg.crlf_ping=1;
 tcp_default_cfg.accept_aliases=0;
 tcp_default_cfg.alias_flags=1;
 tcp_default_cfg.new_conn_alias_flags=2;
 tcp_default_cfg.rd_buf_size=4096;
 tcp_default_cfg.wq_blk_size=2100;
}


decompiled_code:
void tcp_options_check()
{
int v0; // edi

if ( *((_DWORD *)&tcp_default_cfg + 8) && !*((_DWORD *)&tcp_default_cfg + 7) )
*((_DWORD *)&tcp_default_cfg + 8) = 0;
if ( *((_DWORD *)&tcp_default_cfg + 18) | *((_DWORD *)&tcp_default_cfg + 16) | *((_DWORD *)&tcp_default_cfg + 17) )
*((_DWORD *)&tcp_default_cfg + 15) = 1;
fix_timeout("tcp_connect_timeout", (unsigned int *)&tcp_default_cfg, 0xAu, 0x7FFFFFFu);
fix_timeout("tcp_send_timeout", (unsigned int *)(unsigned int)((_DWORD)&tcp_default_cfg + 4), 0xA0u, 0x7FFFFFFFu);
fix_timeout(
"tcp_connection_lifetime",
(unsigned int *)(unsigned int)((_DWORD)&tcp_default_cfg + 8),
0x7FFFFFFFu,
0x7FFFFFFFu);
v0 = tls_max_connections;
*((_DWORD *)&tcp_default_cfg + 3) = tcp_max_connections;
*((_DWORD *)&tcp_default_cfg + 4) = v0;
tcp_cfg_def_fix_isra_0("rd_buf_size", (int *)(unsigned int)((_DWORD)&tcp_default_cfg + 96));
tcp_cfg_def_fix_isra_0("wq_blk_size", (int *)(unsigned int)((_DWORD)&tcp_default_cfg + 100));
}

canonical_decompiled_code:
void func8()
{
int v0; // edi

if ( *((_DWORD *)&tcp_default_cfg + 8) && !*((_DWORD *)&tcp_default_cfg + 7) )
*((_DWORD *)&tcp_default_cfg + 8) = 0;
if ( *((_DWORD *)&tcp_default_cfg + 18) | *((_DWORD *)&tcp_default_cfg + 16) | *((_DWORD *)&tcp_default_cfg + 17) )
*((_DWORD *)&tcp_default_cfg + 15) = 1;
func0("tcp_connect_timeout", (unsigned int *)&tcp_default_cfg, 0xAu, 0x7FFFFFFu);
func0("tcp_send_timeout", (unsigned int *)(unsigned int)((_DWORD)&tcp_default_cfg + 4), 0xA0u, 0x7FFFFFFFu);
func0(
"tcp_connection_lifetime",
(unsigned int *)(unsigned int)((_DWORD)&tcp_default_cfg + 8),
0x7FFFFFFFu,
0x7FFFFFFFu);
v0 = tls_max_connections;
*((_DWORD *)&tcp_default_cfg + 3) = tcp_max_connections;
*((_DWORD *)&tcp_default_cfg + 4) = v0;
func6("rd_buf_size", (int *)(unsigned int)((_DWORD)&tcp_default_cfg + 96));
func6("wq_blk_size", (int *)(unsigned int)((_DWORD)&tcp_default_cfg + 100));
}

original_code:
void tcp_options_check()
{
 if (tcp_default_cfg.tcp_connect_wait && !tcp_default_cfg.async){
  tcp_default_cfg.tcp_connect_wait=0;
 }
 if (tcp_default_cfg.keepintvl || tcp_default_cfg.keepidle ||
   tcp_default_cfg.keepcnt){
  tcp_default_cfg.keepalive=1;
 }
 fix_timeout("tcp_connect_timeout", &tcp_default_cfg.connect_timeout_s,
      10,
      ((((1U<<(sizeof(ticks_t)*8-1))-1))/16U));
 fix_timeout("tcp_send_timeout", &tcp_default_cfg.send_timeout,
      ((10)*16U),
      ((1U<<(sizeof(ticks_t)*8-1))-1));
 fix_timeout("tcp_connection_lifetime", &tcp_default_cfg.con_lifetime,
      ((1U<<(sizeof(ticks_t)*8-1))-1), ((1U<<(sizeof(ticks_t)*8-1))-1));
 tcp_default_cfg.max_connections=tcp_max_connections;
 tcp_default_cfg.max_tls_connections=tls_max_connections;
 tcp_cfg_def_fix("rd_buf_size", (int*)&tcp_default_cfg.rd_buf_size);
 tcp_cfg_def_fix("wq_blk_size", (int*)&tcp_default_cfg.wq_blk_size);
}

canonical_original_code:
void tcp_options_check()
{
 if (tcp_default_cfg.tcp_connect_wait && !tcp_default_cfg.async){
  tcp_default_cfg.tcp_connect_wait=0;
 }
 if (tcp_default_cfg.keepintvl || tcp_default_cfg.keepidle ||
   tcp_default_cfg.keepcnt){
  tcp_default_cfg.keepalive=1;
 }
 fix_timeout("tcp_connect_timeout", &tcp_default_cfg.connect_timeout_s,
      10,
      ((((1U<<(sizeof(ticks_t)*8-1))-1))/16U));
 fix_timeout("tcp_send_timeout", &tcp_default_cfg.send_timeout,
      ((10)*16U),
      ((1U<<(sizeof(ticks_t)*8-1))-1));
 fix_timeout("tcp_connection_lifetime", &tcp_default_cfg.con_lifetime,
      ((1U<<(sizeof(ticks_t)*8-1))-1), ((1U<<(sizeof(ticks_t)*8-1))-1));
 tcp_default_cfg.max_connections=tcp_max_connections;
 tcp_default_cfg.max_tls_connections=tls_max_connections;
 tcp_cfg_def_fix("rd_buf_size", (int *)&tcp_default_cfg.rd_buf_size);
 tcp_cfg_def_fix("wq_blk_size", (int *)&tcp_default_cfg.wq_blk_size);
}


decompiled_code:
__int64 tcp_register_cfg()
{
__int64 result; // rax
const char *v1; // rbx
unsigned int v2; // eax
struct _IO_FILE *v3; // rdi

result = cfg_declare("tcp", &tcp_cfg_def, &tcp_default_cfg, 104LL, &tcp_cfg);
if ( !(_DWORD)result )
{
if ( tcp_cfg )
return result;
if ( (int)get_debug_level("core", 4LL) >= -4 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(4294967292LL);
v1 = (const char *)*((_QWORD *)&log_level_info + 2);
v2 = my_pid();
v3 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): null tcp cfg",
process_no,
v2,
v1,
"<core> [tcp_options.c:404]: ",
"tcp_register_cfg");
if ( log_color )
dprint_color_reset(v3, "%2d(%d) %s: %s%s(): null tcp cfg");
}
else
{
syslog(
*((_DWORD *)&log_level_info + 6) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): null tcp cfg",
*((const char **)&log_level_info + 2),
"<core> [tcp_options.c:404]: ",
"tcp_register_cfg");
}
--dprint_crit;
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax
const char *v1; // rbx
unsigned int v2; // eax
struct _IO_FILE *v3; // rdi

result = cfg_declare("tcp", &tcp_cfg_def, &tcp_default_cfg, 104LL, &tcp_cfg);
if ( !(_DWORD)result )
{
if ( tcp_cfg )
return result;
if ( (int)get_debug_level("core", 4LL) >= -4 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(4294967292LL);
v1 = (const char *)*((_QWORD *)&log_level_info + 2);
v2 = my_pid();
v3 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): null tcp cfg",
process_no,
v2,
v1,
"<core> [tcp_options.c:404]: ",
"tcp_register_cfg");
if ( log_color )
dprint_color_reset(v3, "%2d(%d) %s: %s%s(): null tcp cfg");
}
else
{
syslog(
*((_DWORD *)&log_level_info + 6) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): null tcp cfg",
*((const char **)&log_level_info + 2),
"<core> [tcp_options.c:404]: ",
"tcp_register_cfg");
}
--dprint_crit;
}
}
return 0xFFFFFFFFLL;
}

original_code:
int tcp_register_cfg()
{
 if (cfg_declare("tcp", tcp_cfg_def, &tcp_default_cfg, sizeof(struct cfg_group_tcp),
     &tcp_cfg))
  return -1;
 if (tcp_cfg==0){
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-4)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-4)) >= -5) && (((-4)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "null tcp cfg", process_no, my_pid(), (log_level_info[((-4)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "404" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-4)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "null tcp cfg", (log_level_info[((-4)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "404" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s" "%s(): " "null tcp cfg", process_no, my_pid(), ("<core> [" "tcp_options.c" ":" "404" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-4))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "null tcp cfg", ("<core> [" "tcp_options.c" ":" "404" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "null tcp cfg", ("<core> [" "tcp_options.c" ":" "404" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 return 0;
}

user_defined_types: struct cfg_group_tcp { int connect_timeout_s; int send_timeout; int con_lifetime; int max_connections; int max_tls_connections; int no_connect; int fd_cache; int async; int tcp_connect_wait; unsigned int tcpconn_wq_max; unsigned int tcp_wq_max; int defer_accept; int delayed_ack; int syncnt; int linger2; int keepalive; int keepidle; int keepintvl; int keepcnt; int crlf_ping; int accept_aliases; int alias_flags; int new_conn_alias_flags; int accept_no_cl; unsigned int rd_buf_size; unsigned int wq_blk_size; }


decompiled_code:
int __fastcall fix_timeout(const char *a1, unsigned int *a2, unsigned int a3, unsigned int a4)
{
int result; // eax
__int64 v5; // rbp
__int64 v6; // r14
const char *v7; // r13
unsigned int v8; // eax
int v9; // [rsp-10h] [rbp-38h]

result = *a2;
if ( (*a2 & 0x80000000) != 0 )
{
*a2 = a3;
}
else
{
v5 = a4;
if ( result > a4 )
{
result = get_debug_level("core", 4LL);
if ( result >= 0 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0LL);
v6 = *a2;
v7 = (const char *)*((_QWORD *)&log_level_info + 10);
v8 = my_pid();
result = fprintf(
stderr,
"%2d(%d) %s: %s%s(): %s: timeout too big (%u), the maximum value is %u\n",
process_no,
v8,
v7,
"<core> [tcp_options.c:201]: ",
"fix_timeout",
a1,
v6,
v5);
if ( log_color )
result = dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 22) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): %s: timeout too big (%u), the maximum value is %u\n",
*((const char **)&log_level_info + 10),
"<core> [tcp_options.c:201]: ",
"fix_timeout",
a1,
*a2,
v5);
result = v9;
}
--dprint_crit;
}
*a2 = v5;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, unsigned int *a2, unsigned int a3, unsigned int a4)
{
int result; // eax
__int64 v5; // rbp
__int64 v6; // r14
const char *v7; // r13
unsigned int v8; // eax
int v9; // [rsp-10h] [rbp-38h]

result = *a2;
if ( (*a2 & 0x80000000) != 0 )
{
*a2 = a3;
}
else
{
v5 = a4;
if ( result > a4 )
{
result = get_debug_level("core", 4LL);
if ( result >= 0 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0LL);
v6 = *a2;
v7 = (const char *)*((_QWORD *)&log_level_info + 10);
v8 = my_pid();
result = fprintf(
stderr,
"%2d(%d) %s: %s%s(): %s: timeout too big (%u), the maximum value is %u\n",
process_no,
v8,
v7,
"<core> [tcp_options.c:201]: ",
"fix_timeout",
a1,
v6,
v5);
if ( log_color )
result = dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 22) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): %s: timeout too big (%u), the maximum value is %u\n",
*((const char **)&log_level_info + 10),
"<core> [tcp_options.c:201]: ",
"fix_timeout",
a1,
*a2,
v5);
result = v9;
}
--dprint_crit;
}
*a2 = v5;
}
}
return result;
}

original_code:
static void fix_timeout(char* name, int* to, int default_val, unsigned max_val)
{
 if (*to < 0) *to=default_val;
 else if ((unsigned)*to > max_val){
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((0)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((0)) >= -5) && (((0)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "%s: timeout too big (%u), the maximum value is %u\n", process_no, my_pid(), (log_level_info[((0)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "201" "]: ") , __func__, name, *to, max_val); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((0)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "%s: timeout too big (%u), the maximum value is %u\n", (log_level_info[((0)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "201" "]: ") , __func__, name, *to, max_val); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s" "%s(): " "%s: timeout too big (%u), the maximum value is %u\n", process_no, my_pid(), ("<core> [" "tcp_options.c" ":" "201" "]: ") , __func__, name, *to, max_val); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((0))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "%s: timeout too big (%u), the maximum value is %u\n", ("<core> [" "tcp_options.c" ":" "201" "]: ") , __func__, name, *to, max_val); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "%s: timeout too big (%u), the maximum value is %u\n", ("<core> [" "tcp_options.c" ":" "201" "]: ") , __func__, name, *to, max_val); } } (dprint_crit--); } } while(0);
  *to=max_val;
 }
}

canonical_original_code:
static void fix_timeout(char *name, int *to, int default_val, unsigned int max_val)
{
 if (*to < 0) *to=default_val;
 else if ((unsigned int)*to > max_val){
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((0)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((0)) >= -5) && (((0)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "%s: timeout too big (%u), the maximum value is %u\n", process_no, my_pid(), (log_level_info[((0)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "201" "]: ") , __func__, name, *to, max_val); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((0)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "%s: timeout too big (%u), the maximum value is %u\n", (log_level_info[((0)) - (-5)].name), ("<core> [" "tcp_options.c" ":" "201" "]: ") , __func__, name, *to, max_val); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s" "%s(): " "%s: timeout too big (%u), the maximum value is %u\n", process_no, my_pid(), ("<core> [" "tcp_options.c" ":" "201" "]: ") , __func__, name, *to, max_val); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((0))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "%s: timeout too big (%u), the maximum value is %u\n", ("<core> [" "tcp_options.c" ":" "201" "]: ") , __func__, name, *to, max_val); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "%s: timeout too big (%u), the maximum value is %u\n", ("<core> [" "tcp_options.c" ":" "201" "]: ") , __func__, name, *to, max_val); } } (dprint_crit--); } } while(0);
  *to=max_val;
 }
}

variable_types:
name
char *

variable_types:
to
int *


decompiled_code:
__int64 __fastcall fix_con_lt(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4)
{
__int64 result; // rax
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = 16 * *a4;
fix_timeout("tcp_connection_lifetime", v6, 0x7FFFFFFFu, 0x7FFFFFFFu);
result = 0LL;
*(_QWORD *)a4 = (int)v6[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4)
{
__int64 result; // rax
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = 16 * *a4;
func0("tcp_connection_lifetime", v6, 0x7FFFFFFFu, 0x7FFFFFFFu);
result = 0LL;
*(_QWORD *)a4 = (int)v6[0];
return result;
}

original_code:
static int fix_con_lt(void* cfg_h, str* gname, str* name, void** val)
{
 int v;
 v=(((int)(long)*val)*16U);
 fix_timeout("tcp_connection_lifetime", &v,
     ((1U<<(sizeof(ticks_t)*8-1))-1), ((1U<<(sizeof(ticks_t)*8-1))-1));
 *val=(void*)(long)v;
 return 0;
}

canonical_original_code:
static int fix_con_lt(void *cfg_h, struct _str *gname, struct _str *name, void **val)
{
 int v;
 v=(((int)(long)*val)*16U);
 fix_timeout("tcp_connection_lifetime", &v,
     ((1U<<(sizeof(ticks_t)*8-1))-1), ((1U<<(sizeof(ticks_t)*8-1))-1));
 *val=(void *)(long)v;
 return 0;
}


decompiled_code:
__int64 __fastcall ul_set_keepalive_timeout(int a1)
{
unsigned int v1; // er8

v1 = ul_keepalive_timeout;
ul_keepalive_timeout = a1;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // er8

v1 = ul_keepalive_timeout;
ul_keepalive_timeout = a1;
return v1;
}

original_code:
int ul_set_keepalive_timeout(int _to)
{
 int oto;
 oto = ul_keepalive_timeout;
 ul_keepalive_timeout = _to;
 return oto;
}

variable_types: oto int


decompiled_code:
__int64 __fastcall bind_usrloc(__int64 a1)
{
int v1; // er8
__int64 result; // rax
int v3; // ecx
int v4; // esi
__int64 v5; // r12
unsigned int v6; // eax
const char *v7; // r9
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // rdx
const char *v11; // rsi
struct _IO_FILE *v12; // rdi
__int64 v13; // r12
__int64 v14; // r9
__int64 v15; // [rsp-8h] [rbp-20h]
__int64 v16; // [rsp-8h] [rbp-20h]

if ( !a1 )
{
if ( (int)get_debug_level("usrloc", 6LL) < -1 || dprint_crit )
return 0xFFFFFFFFLL;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): invalid parameter value\n",
*((const char **)&log_level_info + 8),
"usrloc [usrloc.c:53]: ",
"bind_usrloc");
goto LABEL_8;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v13 = *((_QWORD *)&log_level_info + 8);
v8 = (unsigned int)my_pid();
v15 = v14;
v9 = v13;
v7 = "usrloc [usrloc.c:53]: ";
v10 = process_no;
v11 = "%2d(%d) %s: %s%s(): invalid parameter value\n";
LABEL_17:
v12 = stderr;
fprintf(stderr, v11, v10, v8, v9, v7, "bind_usrloc", v15);
if ( log_color )
dprint_color_reset(v12, v11, v16);
goto LABEL_8;
}
if ( init_flag )
{
*(_QWORD *)(a1 + 16) = &register_udomain;
*(_QWORD *)(a1 + 24) = &get_udomain;
*(_QWORD *)(a1 + 32) = &get_all_ucontacts;
*(_QWORD *)(a1 + 40) = &insert_urecord;
*(_QWORD *)(a1 + 48) = &delete_urecord;
*(_QWORD *)(a1 + 64) = &get_urecord;
*(_QWORD *)(a1 + 72) = &lock_udomain;
*(_QWORD *)(a1 + 80) = &unlock_udomain;
*(_QWORD *)(a1 + 88) = &release_urecord;
*(_QWORD *)(a1 + 96) = &insert_ucontact;
*(_QWORD *)(a1 + 104) = &delete_ucontact;
*(_QWORD *)(a1 + 112) = &get_ucontact;
*(_QWORD *)(a1 + 136) = &update_ucontact;
*(_QWORD *)(a1 + 144) = &register_ulcb;
*(_QWORD *)(a1 + 56) = &delete_urecord_by_ruid;
*(_QWORD *)(a1 + 152) = &ul_get_aorhash;
*(_QWORD *)(a1 + 120) = &get_urecord_by_ruid;
v1 = use_domain;
result = 0LL;
v3 = db_mode;
*(_QWORD *)(a1 + 128) = &get_ucontact_by_instance;
v4 = nat_bflag;
*(_QWORD *)(a1 + 160) = ul_set_keepalive_timeout;
*(_QWORD *)(a1 + 168) = &ul_refresh_keepalive;
*(_DWORD *)a1 = v1;
*(_DWORD *)(a1 + 4) = v3;
*(_DWORD *)(a1 + 8) = v4;
return result;
}
if ( (int)get_debug_level("usrloc", 6LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): configuration error - trying to bind to usrloc module before being initialized\n",
*((const char **)&log_level_info + 8),
"usrloc [usrloc.c:57]: ",
"bind_usrloc");
LABEL_8:
--dprint_crit;
return 0xFFFFFFFFLL;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v5 = *((_QWORD *)&log_level_info + 8);
v6 = my_pid();
v7 = "usrloc [usrloc.c:57]: ";
v15 = 6LL;
v8 = v6;
v9 = v5;
v10 = process_no;
v11 = "%2d(%d) %s: %s%s(): configuration error - trying to bind to usrloc module before being initialized\n";
goto LABEL_17;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // er8
__int64 result; // rax
int v3; // ecx
int v4; // esi
__int64 v5; // r12
unsigned int v6; // eax
const char *v7; // r9
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // rdx
const char *v11; // rsi
struct _IO_FILE *v12; // rdi
__int64 v13; // r12
__int64 v14; // r9
__int64 v15; // [rsp-8h] [rbp-20h]
__int64 v16; // [rsp-8h] [rbp-20h]

if ( !a1 )
{
if ( (int)get_debug_level("usrloc", 6LL) < -1 || dprint_crit )
return 0xFFFFFFFFLL;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): invalid parameter value\n",
*((const char **)&log_level_info + 8),
"usrloc [usrloc.c:53]: ",
"bind_usrloc");
goto LABEL_8;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v13 = *((_QWORD *)&log_level_info + 8);
v8 = (unsigned int)my_pid();
v15 = v14;
v9 = v13;
v7 = "usrloc [usrloc.c:53]: ";
v10 = process_no;
v11 = "%2d(%d) %s: %s%s(): invalid parameter value\n";
LABEL_17:
v12 = stderr;
fprintf(stderr, v11, v10, v8, v9, v7, "bind_usrloc", v15);
if ( log_color )
dprint_color_reset(v12, v11, v16);
goto LABEL_8;
}
if ( init_flag )
{
*(_QWORD *)(a1 + 16) = &register_udomain;
*(_QWORD *)(a1 + 24) = &get_udomain;
*(_QWORD *)(a1 + 32) = &get_all_ucontacts;
*(_QWORD *)(a1 + 40) = &insert_urecord;
*(_QWORD *)(a1 + 48) = &delete_urecord;
*(_QWORD *)(a1 + 64) = &get_urecord;
*(_QWORD *)(a1 + 72) = &lock_udomain;
*(_QWORD *)(a1 + 80) = &unlock_udomain;
*(_QWORD *)(a1 + 88) = &release_urecord;
*(_QWORD *)(a1 + 96) = &insert_ucontact;
*(_QWORD *)(a1 + 104) = &delete_ucontact;
*(_QWORD *)(a1 + 112) = &get_ucontact;
*(_QWORD *)(a1 + 136) = &update_ucontact;
*(_QWORD *)(a1 + 144) = &register_ulcb;
*(_QWORD *)(a1 + 56) = &delete_urecord_by_ruid;
*(_QWORD *)(a1 + 152) = &ul_get_aorhash;
*(_QWORD *)(a1 + 120) = &get_urecord_by_ruid;
v1 = use_domain;
result = 0LL;
v3 = db_mode;
*(_QWORD *)(a1 + 128) = &get_ucontact_by_instance;
v4 = nat_bflag;
*(_QWORD *)(a1 + 160) = ul_set_keepalive_timeout;
*(_QWORD *)(a1 + 168) = &ul_refresh_keepalive;
*(_DWORD *)a1 = v1;
*(_DWORD *)(a1 + 4) = v3;
*(_DWORD *)(a1 + 8) = v4;
return result;
}
if ( (int)get_debug_level("usrloc", 6LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): configuration error - trying to bind to usrloc module before being initialized\n",
*((const char **)&log_level_info + 8),
"usrloc [usrloc.c:57]: ",
"bind_usrloc");
LABEL_8:
--dprint_crit;
return 0xFFFFFFFFLL;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v5 = *((_QWORD *)&log_level_info + 8);
v6 = my_pid();
v7 = "usrloc [usrloc.c:57]: ";
v15 = 6LL;
v8 = v6;
v9 = v5;
v10 = process_no;
v11 = "%2d(%d) %s: %s%s(): configuration error - trying to bind to usrloc module before being initialized\n";
goto LABEL_17;
}
return 0xFFFFFFFFLL;
}

original_code:
int bind_usrloc(usrloc_api_t* api)
{
 if (!api) {
  do { if (get_debug_level("usrloc", (sizeof("usrloc")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "invalid parameter value\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("usrloc" " [" "usrloc.c" ":" "53" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "invalid parameter value\n", (log_level_info[((-1)) - (-5)].name), ("usrloc" " [" "usrloc.c" ":" "53" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "invalid parameter value\n", process_no, my_pid(), ("usrloc" " [" "usrloc.c" ":" "53" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "invalid parameter value\n", ("usrloc" " [" "usrloc.c" ":" "53" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "invalid parameter value\n", ("usrloc" " [" "usrloc.c" ":" "53" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (init_flag==0) {
  do { if (get_debug_level("usrloc", (sizeof("usrloc")-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(): " "configuration error - trying to bind to usrloc module" " before being initialized\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("usrloc" " [" "usrloc.c" ":" "57" "]: ") , __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(): " "configuration error - trying to bind to usrloc module" " before being initialized\n", (log_level_info[((-1)) - (-5)].name), ("usrloc" " [" "usrloc.c" ":" "57" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "configuration error - trying to bind to usrloc module" " before being initialized\n", process_no, my_pid(), ("usrloc" " [" "usrloc.c" ":" "57" "]: ") , __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(): " "configuration error - trying to bind to usrloc module" " before being initialized\n", ("usrloc" " [" "usrloc.c" ":" "57" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "configuration error - trying to bind to usrloc module" " before being initialized\n", ("usrloc" " [" "usrloc.c" ":" "57" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 api->register_udomain = register_udomain;
 api->get_udomain = get_udomain;
 api->get_all_ucontacts = get_all_ucontacts;
 api->insert_urecord = insert_urecord;
 api->delete_urecord = delete_urecord;
 api->delete_urecord_by_ruid = delete_urecord_by_ruid;
 api->get_urecord = get_urecord;
 api->lock_udomain = lock_udomain;
 api->unlock_udomain = unlock_udomain;
 api->release_urecord = release_urecord;
 api->insert_ucontact = insert_ucontact;
 api->delete_ucontact = delete_ucontact;
 api->get_ucontact = get_ucontact;
 api->update_ucontact = update_ucontact;
 api->register_ulcb = register_ulcb;
 api->get_aorhash = ul_get_aorhash;
 api->get_urecord_by_ruid = get_urecord_by_ruid;
 api->get_ucontact_by_instance = get_ucontact_by_instance;
 api->set_keepalive_timeout = ul_set_keepalive_timeout;
 api->refresh_keepalive = ul_refresh_keepalive;
 api->use_domain = use_domain;
 api->db_mode = db_mode;
 api->nat_flag = nat_bflag;
 return 0;
}

canonical_original_code:
int bind_usrloc(struct usrloc_api *api)
{
 if (!api) {
  do { if (get_debug_level("usrloc", (sizeof("usrloc")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "invalid parameter value\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("usrloc" " [" "usrloc.c" ":" "53" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "invalid parameter value\n", (log_level_info[((-1)) - (-5)].name), ("usrloc" " [" "usrloc.c" ":" "53" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "invalid parameter value\n", process_no, my_pid(), ("usrloc" " [" "usrloc.c" ":" "53" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "invalid parameter value\n", ("usrloc" " [" "usrloc.c" ":" "53" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "invalid parameter value\n", ("usrloc" " [" "usrloc.c" ":" "53" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (init_flag==0) {
  do { if (get_debug_level("usrloc", (sizeof("usrloc")-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(): " "configuration error - trying to bind to usrloc module" " before being initialized\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("usrloc" " [" "usrloc.c" ":" "57" "]: ") , __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(): " "configuration error - trying to bind to usrloc module" " before being initialized\n", (log_level_info[((-1)) - (-5)].name), ("usrloc" " [" "usrloc.c" ":" "57" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "configuration error - trying to bind to usrloc module" " before being initialized\n", process_no, my_pid(), ("usrloc" " [" "usrloc.c" ":" "57" "]: ") , __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(): " "configuration error - trying to bind to usrloc module" " before being initialized\n", ("usrloc" " [" "usrloc.c" ":" "57" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "configuration error - trying to bind to usrloc module" " before being initialized\n", ("usrloc" " [" "usrloc.c" ":" "57" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 api->register_udomain = register_udomain;
 api->get_udomain = get_udomain;
 api->get_all_ucontacts = get_all_ucontacts;
 api->insert_urecord = insert_urecord;
 api->delete_urecord = delete_urecord;
 api->delete_urecord_by_ruid = delete_urecord_by_ruid;
 api->get_urecord = get_urecord;
 api->lock_udomain = lock_udomain;
 api->unlock_udomain = unlock_udomain;
 api->release_urecord = release_urecord;
 api->insert_ucontact = insert_ucontact;
 api->delete_ucontact = delete_ucontact;
 api->get_ucontact = get_ucontact;
 api->update_ucontact = update_ucontact;
 api->register_ulcb = register_ulcb;
 api->get_aorhash = ul_get_aorhash;
 api->get_urecord_by_ruid = get_urecord_by_ruid;
 api->get_ucontact_by_instance = get_ucontact_by_instance;
 api->set_keepalive_timeout = ul_set_keepalive_timeout;
 api->refresh_keepalive = ul_refresh_keepalive;
 api->use_domain = use_domain;
 api->db_mode = db_mode;
 api->nat_flag = nat_bflag;
 return 0;
}

variable_types: struct usrloc_api { int use_domain; int db_mode; unsigned int nat_flag; int (*register_udomain)(char *_n, struct udomain { struct _str { char *s; int len; } *name; int size; struct hslot { int n; struct urecord { struct _str *domain; struct _str aor; unsigned int aorhash; struct ucontact { struct _str *domain; struct _str ruid; struct _str *aor; struct _str c; struct _str received; struct _str path; long expires; int q; struct _str callid; int cseq; enum cstate { CS_NEW=0, CS_SYNC=1, CS_DIRTY=2 } state; unsigned int flags; unsigned int cflags; struct _str user_agent; struct socket_info { int socket; struct _str name; struct ip_addr { unsigned int af; unsigned int len; union { unsigned long addrl[-1]; unsigned int addr32[4]; unsigned short addr16[8]; unsigned char addr[16]; } u; } address; struct _str address_str; struct _str port_no_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } s; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } sin6; } su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; } *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info { struct _str name; unsigned short port_no; struct _str port_no_str; struct _str address_str; struct ip_addr address; struct _str sock_str; } useinfo; } *sock; long last_modified; long last_keepalive; unsigned int methods; struct _str instance; unsigned int reg_id; int tcpconn_id; struct _sr_xavp { unsigned int id; struct _str name; struct _sr_xval { enum sr_xtype_t { SR_XTYPE_NULL=0, SR_XTYPE_INT=1, SR_XTYPE_STR=2, SR_XTYPE_TIME=3, SR_XTYPE_LONG=4, SR_XTYPE_LLONG=5, SR_XTYPE_XAVP=6, SR_XTYPE_DATA=7 } type; union { int i; struct _str s; long t; long l; long long ll; struct _sr_xavp *xavp; struct _sr_data { void *p; void (*pfree)(void *d, void (*sfree)(void *d)); } *data; } v; } val; struct _sr_xavp *next; } *xavp; struct ucontact *next; struct ucontact *prev; } *contacts; struct hslot *slot; struct urecord *prev; struct urecord *next; } *first; struct urecord *last; struct udomain *d; struct atomic_t { int val; } *lock; } *table; void *users; void *contacts; void *expires; } **_d); int (*get_udomain)(char *_n, struct udomain **_d); int (*get_all_ucontacts)(void *buf, int len, unsigned int flags, unsigned int part_idx, unsigned int part_max); int (*insert_urecord)(struct udomain *_d, struct _str *_aor, struct urecord **_r); int (*delete_urecord)(struct udomain *_d, struct _str *_aor, struct urecord *_r); int (*delete_urecord_by_ruid)(struct udomain *_d, struct _str *_ruid); int (*get_urecord)(struct udomain *_d, struct _str *_aor, struct urecord **_r); void (*lock_udomain)(struct udomain *_d, struct _str *_aor); void (*unlock_udomain)(struct udomain *_d, struct _str *_aor); void (*release_urecord)(struct urecord *_r); int (*insert_ucontact)(struct urecord *_r, struct _str *_contact, struct ucontact_info { struct _str ruid; struct _str *c; struct _str received; struct _str *path; long expires; int q; struct _str *callid; int cseq; unsigned int flags; unsigned int cflags; struct _str *user_agent; struct socket_info *sock; unsigned int methods; struct _str instance; unsigned int reg_id; int tcpconn_id; struct _sr_xavp *xavp; long last_modified; } *_ci, struct ucontact **_c); int (*delete_ucontact)(struct urecord *_r, struct ucontact *_c); int (*get_ucontact)(struct urecord *_r, struct _str *_c, struct _str *_callid, struct _str *_path, int _cseq, struct ucontact **_co); int (*get_urecord_by_ruid)(struct udomain *_d, unsigned int _aorhash, struct _str *_ruid, struct urecord **_r, struct ucontact **_c); int (*get_ucontact_by_instance)(struct urecord *_r, struct _str *_c, struct ucontact_info *_ci, struct ucontact **_co); int (*update_ucontact)(struct urecord *_r, struct ucontact *_c, struct ucontact_info *_ci); int (*register_ulcb)(int cb_types, void f(struct ucontact *c, int type, void *param), void *param); unsigned int (*get_aorhash)(struct _str *_aor); int (*set_keepalive_timeout)(int _to); int (*refresh_keepalive)(unsigned int _aorhash, struct _str *_ruid); } *

user_defined_types: struct usrloc_api { int use_domain; int db_mode; unsigned int nat_flag; int (*register_udomain)(char *_n, struct udomain **_d); int (*get_udomain)(char *_n, struct udomain **_d); int (*get_all_ucontacts)(void *buf, int len, unsigned int flags, unsigned int part_idx, unsigned int part_max); int (*insert_urecord)(struct udomain *_d, struct _str *_aor, struct urecord **_r); int (*delete_urecord)(struct udomain *_d, struct _str *_aor, struct urecord *_r); int (*delete_urecord_by_ruid)(struct udomain *_d, struct _str *_ruid); int (*get_urecord)(struct udomain *_d, struct _str *_aor, struct urecord **_r); void (*lock_udomain)(struct udomain *_d, struct _str *_aor); void (*unlock_udomain)(struct udomain *_d, struct _str *_aor); void (*release_urecord)(struct urecord *_r); int (*insert_ucontact)(struct urecord *_r, struct _str *_contact, struct ucontact_info *_ci, struct ucontact **_c); int (*delete_ucontact)(struct urecord *_r, struct ucontact *_c); int (*get_ucontact)(struct urecord *_r, struct _str *_c, struct _str *_callid, struct _str *_path, int _cseq, struct ucontact **_co); int (*get_urecord_by_ruid)(struct udomain *_d, unsigned int _aorhash, struct _str *_ruid, struct urecord **_r, struct ucontact **_c); int (*get_ucontact_by_instance)(struct urecord *_r, struct _str *_c, struct ucontact_info *_ci, struct ucontact **_co); int (*update_ucontact)(struct urecord *_r, struct ucontact *_c, struct ucontact_info *_ci); int (*register_ulcb)(int cb_types, void f(struct ucontact *c, int type, void *param), void *param); unsigned int (*get_aorhash)(struct _str *_aor); int (*set_keepalive_timeout)(int _to); int (*refresh_keepalive)(unsigned int _aorhash, struct _str *_ruid); }

user_defined_types: struct udomain { struct _str *name; int size; struct hslot *table; void *users; void *contacts; void *expires; }

user_defined_types: struct hslot { int n; struct urecord *first; struct urecord *last; struct udomain *d; struct atomic_t *lock; }

user_defined_types: struct urecord { struct _str *domain; struct _str aor; unsigned int aorhash; struct ucontact *contacts; struct hslot *slot; struct urecord *prev; struct urecord *next; }

user_defined_types: struct ucontact { struct _str *domain; struct _str ruid; struct _str *aor; struct _str c; struct _str received; struct _str path; long expires; int q; struct _str callid; int cseq; enum cstate state; unsigned int flags; unsigned int cflags; struct _str user_agent; struct socket_info *sock; long last_modified; long last_keepalive; unsigned int methods; struct _str instance; unsigned int reg_id; int tcpconn_id; struct _sr_xavp *xavp; struct ucontact *next; struct ucontact *prev; }

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

user_defined_types: struct _sr_xavp { unsigned int id; struct _str name; struct _sr_xval val; struct _sr_xavp *next; }

user_defined_types: union sockaddr_union { struct sockaddr s; struct sockaddr_in sin; struct sockaddr_in6 sin6; }

user_defined_types: struct _sr_xval { enum sr_xtype_t type; union { int i; struct _str s; long t; long l; long long ll; struct _sr_xavp *xavp; struct _sr_data *data; } v; }

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

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

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


decompiled_code:
// attributes: thunk
__int64 get_stat_val()
{
return counter_get_val();
}

canonical_decompiled_code:
__int64 func0()
{
return counter_get_val();
}

original_code:
inline static unsigned long get_stat_val(stat_var *v)
{
 counter_handle_t h;
 h.id = (unsigned short)(unsigned long)v;
 return (unsigned long)counter_get_val(h);
}

canonical_original_code:
inline static unsigned long get_stat_val(void *v)
{
 struct counter_handle_s h;
 h.id = (unsigned short)(unsigned long)v;
 return (unsigned long)counter_get_val(h);
}

variable_types:
v
void *

variable_types: struct counter_handle_s { unsigned short id; }

return_type: unsigned long


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

v0 = get_stat_val(successful_initial_ccrs);
return get_stat_val(initial_ccrs) - v0;
}

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

v0 = func0(successful_initial_ccrs);
return func0(initial_ccrs) - v0;
}

original_code:
unsigned long get_failed_initial_ccrs() {
 unsigned long success_number = get_stat_val(successful_initial_ccrs),
   total_number = get_stat_val(initial_ccrs);
 return total_number - success_number;
}

canonical_original_code:
unsigned long get_failed_initial_ccrs() {
 unsigned long success_number = get_stat_val(successful_initial_ccrs); unsigned long total_number = get_stat_val(initial_ccrs);
 return total_number - success_number;
}


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

v0 = get_stat_val(successful_interim_ccrs);
return get_stat_val(interim_ccrs) - v0;
}

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

v0 = func0(successful_interim_ccrs);
return func0(interim_ccrs) - v0;
}

original_code:
unsigned long get_failed_interim_ccrs() {
 unsigned long success_number = get_stat_val(successful_interim_ccrs),
   total_number = get_stat_val(interim_ccrs);
 return total_number - success_number;
}

canonical_original_code:
unsigned long get_failed_interim_ccrs() {
 unsigned long success_number = get_stat_val(successful_interim_ccrs); unsigned long total_number = get_stat_val(interim_ccrs);
 return total_number - success_number;
}


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

v0 = get_stat_val(successful_final_ccrs);
return get_stat_val(final_ccrs) - v0;
}

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

v0 = func0(successful_final_ccrs);
return func0(final_ccrs) - v0;
}

original_code:
unsigned long get_failed_final_ccrs() {
 unsigned long success_number = get_stat_val(successful_final_ccrs),
   total_number = get_stat_val(final_ccrs);
 return total_number - success_number;
}

canonical_original_code:
unsigned long get_failed_final_ccrs() {
 unsigned long success_number = get_stat_val(successful_final_ccrs); unsigned long total_number = get_stat_val(final_ccrs);
 return total_number - success_number;
}


decompiled_code:
unsigned __int64 get_ccr_avg_response_time()
{
unsigned __int64 v0; // rbp
__int64 v1; // rbx
__int64 v2; // rbx
unsigned __int64 v3; // rdi
unsigned __int64 result; // rax

v0 = get_stat_val(ccr_responses_time);
v1 = get_stat_val(initial_ccrs);
v2 = get_stat_val(interim_ccrs) + v1;
v3 = v2 + get_stat_val(final_ccrs);
if ( v0 && v3 )
result = v0 / v3;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
unsigned __int64 func4()
{
unsigned __int64 v0; // rbp
__int64 v1; // rbx
__int64 v2; // rbx
unsigned __int64 v3; // rdi
unsigned __int64 result; // rax

v0 = func0(ccr_responses_time);
v1 = func0(initial_ccrs);
v2 = func0(interim_ccrs) + v1;
v3 = v2 + func0(final_ccrs);
if ( v0 && v3 )
result = v0 / v3;
else
result = 0LL;
return result;
}

original_code:
unsigned long get_ccr_avg_response_time() {
 unsigned long responses_time = get_stat_val(ccr_responses_time),
      ccrs = get_stat_val(initial_ccrs)
            + get_stat_val(interim_ccrs)
            + get_stat_val(final_ccrs);
 if (responses_time == 0 || ccrs == 0)
  return 0;
 return responses_time / ccrs;
}

canonical_original_code:
unsigned long get_ccr_avg_response_time() {
 unsigned long responses_time = get_stat_val(ccr_responses_time); unsigned long ccrs = get_stat_val(initial_ccrs)
            + get_stat_val(interim_ccrs)
            + get_stat_val(final_ccrs);
 if (responses_time == 0 || ccrs == 0)
  return 0;
 return responses_time / ccrs;
}

variable_types:
ccrs
unsigned long


decompiled_code:
__int64 __fastcall char2digit(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 35;
result = 0LL;
if ( v1 <= 0x23u )
result = CSWTCH_14[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 35;
result = 0LL;
if ( v1 <= 0x23u )
result = CSWTCH_14[v1];
return result;
}

original_code:
static char char2digit(char localchar)
{
 switch (localchar) {
  case '0':
   return 0;
  case '1':
   return 1;
  case '2':
   return 2;
  case '3':
   return 3;
  case '4':
   return 4;
  case '5':
   return 5;
  case '6':
   return 6;
  case '7':
   return 7;
  case '8':
   return 8;
  case '9':
   return 9;
  case 'A':
   return 0xa;
  case 'B':
   return 0xb;
  case 'C':
   return 0xc;
  case 'D':
   return 0xd;
  case '*':
   return 0xe;
  case '#':
  case 'F':
   return 0xf;
  default:
   return 0;
 }
}

variable_types: localchar char

return_type: char


original_code:
static void isup_put_number(unsigned char *dest, char *src, int *len, int *oddeven)
{
 int i = 0;
 int numlen = strlen(src);
 if (numlen % 2) {
  *oddeven = 1;
  *len = numlen/2 + 1;
 } else {
  *oddeven = 0;
  *len = numlen/2;
 }
 while (i < numlen) {
  if (!(i % 2))
   dest[i/2] = char2digit(src[i]) & 0xf;
  else
  {
   dest[i/2] |= (char2digit(src[i]) << 4) & 0xf0;
  }
  i++;
 }
}

variable_types:
dest
unsigned char *

variable_types:
src
char *

variable_types:
len
int *

variable_types:
oddeven
int *

variable_types: i int

variable_types: numlen int


decompiled_code:
__int64 __fastcall isup_get_hop_counter(_BYTE *a1, int a2)
{
__int64 result; // rax

result = get_optional_header(61, a1, a2);
if ( (_DWORD)result != -1 )
{
if ( a2 - (int)result <= 2 )
result = 0xFFFFFFFFLL;
else
result = a1[(int)result + 2] & 0x1F;
}
return result;
}

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

result = func1(61, a1, a2);
if ( (_DWORD)result != -1 )
{
if ( a2 - (int)result <= 2 )
result = 0xFFFFFFFFLL;
else
result = a1[(int)result + 2] & 0x1F;
}
return result;
}

original_code:
int isup_get_hop_counter(unsigned char *buf, int len)
{
 int offset = get_optional_header(0x3d, buf, len);
 if(offset != -1 && len-offset-2 > 0)
 {
  return buf[offset+2] & 0x1F;
 }
 return -1;
}

variable_types:
buf
unsigned char *

variable_types: len int

variable_types: offset int


decompiled_code:
__int64 __fastcall isup_get_calling_party_nai(_BYTE *a1, int a2)
{
__int64 result; // rax

result = get_optional_header(10, a1, a2);
if ( (_DWORD)result != -1 )
{
if ( a2 - (int)result <= 2 )
result = 0xFFFFFFFFLL;
else
result = a1[(int)result + 2] & 0x7F;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1, int a2)
{
__int64 result; // rax

result = func1(10, a1, a2);
if ( (_DWORD)result != -1 )
{
if ( a2 - (int)result <= 2 )
result = 0xFFFFFFFFLL;
else
result = a1[(int)result + 2] & 0x7F;
}
return result;
}

original_code:
int isup_get_calling_party_nai(unsigned char *buf, int len)
{
 int offset = get_optional_header(0x0a, buf, len);
 if(offset != -1 && len-offset-2 > 0)
 {
  return buf[offset+2] & 0x7F;
 }
 return -1;
}


decompiled_code:
__int64 __fastcall isup_get_screening(_BYTE *a1, int a2)
{
__int64 result; // rax

result = get_optional_header(10, a1, a2);
if ( (_DWORD)result != -1 )
{
if ( a2 - (int)result <= 3 )
result = 0xFFFFFFFFLL;
else
result = a1[(int)result + 3] & 3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1, int a2)
{
__int64 result; // rax

result = func1(10, a1, a2);
if ( (_DWORD)result != -1 )
{
if ( a2 - (int)result <= 3 )
result = 0xFFFFFFFFLL;
else
result = a1[(int)result + 3] & 3;
}
return result;
}

original_code:
int isup_get_screening(unsigned char *buf, int len)
{
 int offset = get_optional_header(0x0a, buf, len);
 if(offset != -1 && len-offset-3 > 0)
 {
  return buf[offset+3] & 0x03;
 }
 return -1;
}


decompiled_code:
__int64 __fastcall isup_get_presentation(_BYTE *a1, int a2)
{
__int64 result; // rax

result = get_optional_header(10, a1, a2);
if ( (_DWORD)result != -1 )
{
if ( a2 - (int)result <= 3 )
result = 0xFFFFFFFFLL;
else
result = (a1[(int)result + 3] >> 2) & 3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1, int a2)
{
__int64 result; // rax

result = func1(10, a1, a2);
if ( (_DWORD)result != -1 )
{
if ( a2 - (int)result <= 3 )
result = 0xFFFFFFFFLL;
else
result = (a1[(int)result + 3] >> 2) & 3;
}
return result;
}

original_code:
int isup_get_presentation(unsigned char *buf, int len)
{
 int offset = get_optional_header(0x0a, buf, len);
 if(offset != -1 && len-offset-3 > 0)
 {
  return (buf[offset+3]>>2) & 0x03;
 }
 return -1;
}


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

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

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

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

variable_types:
var
int *

variable_types: v int


decompiled_code:
__int64 __fastcall futex_release(volatile __int32 *a1)
{
__int64 result; // rax
__int64 v2; // [rsp-10h] [rbp-18h]

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

canonical_decompiled_code:
__int64 __fastcall func1(volatile __int32 *a1)
{
__int64 result; // rax
__int64 v2; // [rsp-10h] [rbp-18h]

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

variable_types:
lock
struct atomic_t { int val; } *


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

result = atomic_cmpxchg_int_constprop_0(a1);
if ( (_DWORD)result )
{
if ( (_DWORD)result == 2 )
{
do
{
LABEL_24:
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_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
if ( v2 == 7 )
{
for ( result = atomic_get_and_set_int(a1, 2); (_DWORD)result; result = atomic_get_and_set_int(a1, 2) )
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
return result;
}
}
}
}
return result;
}

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

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