decompiled_code:
__int64 __fastcall get_msg_rules(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rax
const char *v7; // rbp
unsigned int v8; // er12
const char *v10; // r15
unsigned int v11; // eax
struct _IO_FILE *v12; // rdi
const char *v13; // r8
const char *v14; // r9
const char *v15; // r14
unsigned int v16; // eax
struct _IO_FILE *v17; // rdi
__int64 v18; // rdx
__int64 v19; // rcx
const char *v20; // r12
unsigned int v21; // eax
const char *v22; // [rsp-10h] [rbp-58h]
__int64 v23; // [rsp-8h] [rbp-50h]
const char *v24; // [rsp-8h] [rbp-50h]
const char *v25; // [rsp+0h] [rbp-48h] BYREF
const char *v26; // [rsp+8h] [rbp-40h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rax
const char *v7; // rbp
unsigned int v8; // er12
const char *v10; // r15
unsigned int v11; // eax
struct _IO_FILE *v12; // rdi
const char *v13; // r8
const char *v14; // r9
const char *v15; // r14
unsigned int v16; // eax
struct _IO_FILE *v17; // rdi
__int64 v18; // rdx
__int64 v19; // rcx
const char *v20; // r12
unsigned int v21; // eax
const char *v22; // [rsp-10h] [rbp-58h]
__int64 v23; // [rsp-8h] [rbp-50h]
const char *v24; // [rsp-8h] [rbp-50h]
const char *v25; // [rsp+0h] [rbp-48h] BYREF
const char *v26; // [rsp+8h] [rbp-40h] BYREF

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

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

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

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

variable_types:
filename
struct _str *

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

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

variable_types:
data
char *

variable_types: dsize int

variable_types:
uri
char *

variable_types: res int

user_defined_types: struct cp_ruleset_t { struct _cp_rule_t *rules; }

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

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

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

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


repo: virtualolson/who

decompiled_code:
__int64 __fastcall get_msg_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 *)&LC10;
HIDWORD(v30) = *(_DWORD *)(a2 + 8);
if ( !v14 )
v14 = (const char *)&LC10;
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> [msg_rules.c:84]: ",
"get_msg_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 *)&LC10;
if ( !v8 )
v8 = (const char *)&LC10;
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> [msg_rules.c:84]: ",
"get_msg_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 *)&LC10;
HIDWORD(v31) = *(_DWORD *)(a2 + 8);
if ( !v21 )
v21 = (const char *)&LC10;
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> [msg_rules.c:87]: ",
"get_msg_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 *)&LC10;
if ( !v11 )
v11 = (const char *)&LC10;
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> [msg_rules.c:87]: ",
"get_msg_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 *)&LC10;
HIDWORD(v30) = *(_DWORD *)(a2 + 8);
if ( !v14 )
v14 = (const char *)&LC10;
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> [msg_rules.c:84]: ",
"get_msg_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 *)&LC10;
if ( !v8 )
v8 = (const char *)&LC10;
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> [msg_rules.c:84]: ",
"get_msg_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 *)&LC10;
HIDWORD(v31) = *(_DWORD *)(a2 + 8);
if ( !v21 )
v21 = (const char *)&LC10;
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> [msg_rules.c:87]: ",
"get_msg_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 *)&LC10;
if ( !v11 )
v11 = (const char *)&LC10;
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> [msg_rules.c:87]: ",
"get_msg_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_msg_rules_action(cp_ruleset_t *r, const str_t *wuri,
  msg_handling_t *dst_action)
{
 int res = 1;
 cp_rule_t *rule;
 msg_handling_t a = msg_handling_block;
 msg_handling_t aa;
 if (!r) return -1;
 rule = r->rules;
 while (rule) {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "TRYING rule %.*s for uri %.*s\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "TRYING rule %.*s for uri %.*s\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "TRYING rule %.*s for uri %.*s\n", process_no, my_pid(), ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "TRYING rule %.*s for uri %.*s\n", ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "TRYING rule %.*s for uri %.*s\n", ("<core> [" "msg_rules.c" ":" "84" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); } } (dprint_crit--); } } while(0);
  if (is_rule_for_uri(rule, wuri)) {
   do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "rule %.*s matches for uri %.*s\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "rule %.*s matches for uri %.*s\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "rule %.*s matches for uri %.*s\n", process_no, my_pid(), ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "rule %.*s matches for uri %.*s\n", ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "rule %.*s matches for uri %.*s\n", ("<core> [" "msg_rules.c" ":" "87" "]: ") , __func__, (rule->id).len,((rule->id).s ? (rule->id).s : ""), (*wuri).len,((*wuri).s ? (*wuri).s : "")); } } (dprint_crit--); } } while(0);
   if (!rule->actions) continue;
   if (!rule->actions->unknown) continue;
   aa = *(msg_handling_t*)(rule->actions->unknown->data);
   if (aa > a) a = aa;
   res = 0;
  }
  rule = rule->next;
 }
 if (dst_action && (res == 0)) *dst_action = a;
 return res;
}

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

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

variable_types:
wuri
struct _str *

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

return_type: int

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

user_defined_types: struct cp_actions_t { struct _cp_unknown_t *unknown; }

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


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

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

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

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

return_type: void

user_defined_types: struct cp_transformations_t { struct _cp_unknown_t *unknown; }

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall get_from_user(__int64 a1, __int64 a2)
{
__int64 v2; // rax
int v3; // edx
__int64 result; // rax

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall get_to_user(__int64 a1, __int64 a2)
{
__int64 v2; // rax
int v3; // edx
__int64 result; // rax

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

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

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

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

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


decompiled_code:
__int64 __fastcall get_call_id(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
int v3; // ecx

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
int v3; // ecx

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

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

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


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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall get_hash_source(char *s2)
{
int v1; // er8
__int64 result; // rax
int v3; // edx

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall hash_func(__int64 a1, unsigned int a2, unsigned int a3)
{
const char *v6; // r13
unsigned int v7; // er15
const char *v8; // r14
unsigned int v9; // eax
unsigned int v10; // [rsp+Ch] [rbp-4Ch] BYREF
const char *v11; // [rsp+10h] [rbp-48h] BYREF
unsigned int v12; // [rsp+18h] [rbp-40h]

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, unsigned int a3)
{
const char *v6; // r13
unsigned int v7; // er15
const char *v8; // r14
unsigned int v9; // eax
unsigned int v10; // [rsp+Ch] [rbp-4Ch] BYREF
const char *v11; // [rsp+10h] [rbp-48h] BYREF
unsigned int v12; // [rsp+18h] [rbp-40h]

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

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

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

variable_types: denominator int

variable_types: ret int

variable_types:
hash
unsigned int

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


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 func3(volatile signed __int32 *a1)
{
__int64 result; // rax
int v2; // ecx

result = func2(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 = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(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);
}

variable_types: i int


decompiled_code:
__int64 __fastcall shm_malloc(unsigned int a1)
{
__int64 v1; // r12

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

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
__int64 v1; // r12

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

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

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

variable_types:
size
unsigned int

variable_types:
p
void *

return_type: void *


decompiled_code:
__int64 init_pua_evlist()
{
__int64 v0; // rax
__int64 v1; // r12
const char *v3; // r13
unsigned int v4; // eax

v0 = shm_malloc(0x38u);
v1 = v0;
if ( v0 )
{
*(_QWORD *)(v0 + 48) = 0LL;
}
else if ( (int)get_debug_level(&LC0, 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v3 = (const char *)*((_QWORD *)&log_level_info + 8);
v4 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): no more share memory\n",
process_no,
v4,
v3,
"pua [event_list.c:42]: ",
"init_pua_evlist");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): no more share memory\n",
*((const char **)&log_level_info + 8),
"pua [event_list.c:42]: ",
"init_pua_evlist");
}
--dprint_crit;
}
return v1;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rax
__int64 v1; // r12
const char *v3; // r13
unsigned int v4; // eax

v0 = func4(0x38u);
v1 = v0;
if ( v0 )
{
*(_QWORD *)(v0 + 48) = 0LL;
}
else if ( (int)get_debug_level(&LC0, 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v3 = (const char *)*((_QWORD *)&log_level_info + 8);
v4 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): no more share memory\n",
process_no,
v4,
v3,
"pua [event_list.c:42]: ",
"init_pua_evlist");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): no more share memory\n",
*((const char **)&log_level_info + 8),
"pua [event_list.c:42]: ",
"init_pua_evlist");
}
--dprint_crit;
}
return v1;
}

original_code:
pua_event_t* init_pua_evlist(void)
{
 pua_event_t* list= ((void *)0);
 list= (pua_event_t*)shm_malloc(sizeof(pua_event_t));
 if(list== ((void *)0))
 {
  do { if (get_debug_level("pua", (sizeof("pua")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "no more share memory\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("pua" " [" "event_list.c" ":" "42" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "no more share memory\n", (log_level_info[((-1)) - (-5)].name), ("pua" " [" "event_list.c" ":" "42" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no more share memory\n", process_no, my_pid(), ("pua" " [" "event_list.c" ":" "42" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no more share memory\n", ("pua" " [" "event_list.c" ":" "42" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no more share memory\n", ("pua" " [" "event_list.c" ":" "42" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return ((void *)0);
 }
 list->next= ((void *)0);
 return list;
}

canonical_original_code:
struct pua_event *init_pua_evlist()
{
 struct pua_event *list = ((void *)0);
 list= (struct pua_event *)shm_malloc(sizeof(pua_event_t));
 if(list== ((void *)0))
 {
  do { if (get_debug_level("pua", (sizeof("pua")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "no more share memory\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("pua" " [" "event_list.c" ":" "42" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "no more share memory\n", (log_level_info[((-1)) - (-5)].name), ("pua" " [" "event_list.c" ":" "42" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no more share memory\n", process_no, my_pid(), ("pua" " [" "event_list.c" ":" "42" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no more share memory\n", ("pua" " [" "event_list.c" ":" "42" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no more share memory\n", ("pua" " [" "event_list.c" ":" "42" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return ((void *)0);
 }
 list->next= ((void *)0);
 return list;
}

variable_types: struct pua_event { int ev_flag; struct _str { char *s; int len; } name; struct _str content_type; int (*process_body)(struct publ_info { struct _str id; struct _str *pres_uri; struct _str *body; int expires; int flag; int source_flag; int event; struct _str content_type; struct _str *etag; struct _str *extra_headers; void *cb_param; } *, struct _str **final_body, int ver, struct _str **tuple); struct pua_event *next; } *

user_defined_types: struct pua_event { int ev_flag; struct _str name; struct _str content_type; int (*process_body)(struct publ_info *, struct _str **final_body, int ver, struct _str **tuple); struct pua_event *next; }


decompiled_code:
__int64 __fastcall contains_pua_event(__int64 a1)
{
__int64 v1; // r12
size_t v2; // r13
int v3; // ebx

v1 = *(_QWORD *)(pua_evlist + 48LL);
if ( v1 )
{
v2 = *(int *)(a1 + 8);
v3 = *(_DWORD *)(a1 + 8);
do
{
if ( *(_DWORD *)(v1 + 16) == v3 && !strncmp(*(const char **)(v1 + 8), *(const char **)a1, v2) )
break;
v1 = *(_QWORD *)(v1 + 48);
}
while ( v1 );
}
return v1;
}

original_code:
pua_event_t* contains_pua_event(str* name)
{
 pua_event_t* event;
 event= pua_evlist->next;
 while(event)
 {
  if(event->name.len== name->len &&
    strncmp(event->name.s, name->s, name->len)== 0)
  {
   return event;
  }
  event= event->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct pua_event *contains_pua_event(struct _str *name)
{
 struct pua_event *event;
 event= pua_evlist->next;
 while(event)
 {
  if(event->name.len== name->len &&
    strncmp(event->name.s, name->s, name->len)== 0)
  {
   return event;
  }
  event= event->next;
 }
 return ((void *)0);
}

variable_types:
name
struct _str *

return_type: struct pua_event { int ev_flag; struct _str { char *s; int len; } name; struct _str content_type; int (*process_body)(struct publ_info { struct _str id; struct _str *pres_uri; struct _str *body; int expires; int flag; int source_flag; int event; struct _str content_type; struct _str *etag; struct _str *extra_headers; void *cb_param; } *, struct _str **final_body, int ver, struct _str **tuple); struct pua_event *next; } *


decompiled_code:
__int64 __fastcall add_pua_event(int a1, const char *a2, const char *a3, __int64 a4)
{
int v7; // ebx
int v8; // edx
_QWORD *v9; // rax
_QWORD *v10; // r15
char *v11; // rdi
unsigned int v12; // er12
__int64 v13; // rcx
const char *v15; // rbp
unsigned int v16; // eax
const char *v17; // r15
struct _IO_FILE *v18; // rdi
const char *v19; // r8
const char *v20; // r9
const char *v21; // [rsp-10h] [rbp-68h]
__int64 v22; // [rsp-10h] [rbp-68h]
__int64 v23; // [rsp-8h] [rbp-60h]
__int64 v24; // [rsp-8h] [rbp-60h]
const char *v25; // [rsp+0h] [rbp-58h]
int v26; // [rsp+8h] [rbp-50h]
int v27; // [rsp+Ch] [rbp-4Ch]
const char *v28; // [rsp+10h] [rbp-48h] BYREF
int v29; // [rsp+18h] [rbp-40h]

v28 = a2;
v29 = strlen(a2);
v7 = v29;
if ( contains_pua_event((__int64)&v28) )
{
v12 = 0;
if ( (int)get_debug_level(&LC0, 3LL) > 2 )
{
v12 = dprint_crit;
if ( dprint_crit )
{
v12 = 0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v15 = (const char *)*((_QWORD *)&log_level_info + 16);
v16 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): Event already exists\n",
process_no,
v16,
v15,
"pua [event_list.c:67]: ",
"add_pua_event");
if ( log_color )
dprint_color_reset(v23, v21);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): Event already exists\n",
*((const char **)&log_level_info + 16),
"pua [event_list.c:67]: ",
"add_pua_event");
}
--dprint_crit;
}
}
}
else
{
if ( a3 )
{
v27 = strlen(a3);
v8 = v7 + v27;
}
else
{
v27 = 0;
v8 = v7;
}
v26 = v8 + 56;
v9 = (_QWORD *)shm_malloc(v8 + 56);
v10 = v9;
if ( v9 )
{
memset(v9, 0, v26);
v10[1] = v10 + 7;
memcpy(v10 + 7, a2, v7);
*((_DWORD *)v10 + 4) = v7;
if ( a3 )
{
v11 = (char *)v10 + v7 + 56;
v10[3] = v11;
memcpy(v11, a3, v27);
*((_DWORD *)v10 + 8) = v27;
}
v10[5] = a4;
v12 = 0;
*(_DWORD *)v10 = a1;
v13 = pua_evlist;
v10[6] = *(_QWORD *)(pua_evlist + 48LL);
*(_QWORD *)(v13 + 48) = v10;
}
else
{
v12 = -1;
if ( (int)get_debug_level(&LC0, 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v17 = (const char *)*((_QWORD *)&log_level_info + 8);
v24 = my_pid();
v18 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): No more share memory\n",
process_no,
(unsigned int)v24,
v17,
"pua [event_list.c:78]: ",
"add_pua_event");
if ( log_color )
dprint_color_reset(v18, "%2d(%d) %s: %s%s(): No more share memory\n", v22, v24, v19, v20, v25);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): No more share memory\n",
*((const char **)&log_level_info + 8),
"pua [event_list.c:78]: ",
"add_pua_event");
}
v12 = -1;
--dprint_crit;
}
}
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, const char *a2, const char *a3, __int64 a4)
{
int v7; // ebx
int v8; // edx
_QWORD *v9; // rax
_QWORD *v10; // r15
char *v11; // rdi
unsigned int v12; // er12
__int64 v13; // rcx
const char *v15; // rbp
unsigned int v16; // eax
const char *v17; // r15
struct _IO_FILE *v18; // rdi
const char *v19; // r8
const char *v20; // r9
const char *v21; // [rsp-10h] [rbp-68h]
__int64 v22; // [rsp-10h] [rbp-68h]
__int64 v23; // [rsp-8h] [rbp-60h]
__int64 v24; // [rsp-8h] [rbp-60h]
const char *v25; // [rsp+0h] [rbp-58h]
int v26; // [rsp+8h] [rbp-50h]
int v27; // [rsp+Ch] [rbp-4Ch]
const char *v28; // [rsp+10h] [rbp-48h] BYREF
int v29; // [rsp+18h] [rbp-40h]

v28 = a2;
v29 = strlen(a2);
v7 = v29;
if ( func6((__int64)&v28) )
{
v12 = 0;
if ( (int)get_debug_level(&LC0, 3LL) > 2 )
{
v12 = dprint_crit;
if ( dprint_crit )
{
v12 = 0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v15 = (const char *)*((_QWORD *)&log_level_info + 16);
v16 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): Event already exists\n",
process_no,
v16,
v15,
"pua [event_list.c:67]: ",
"add_pua_event");
if ( log_color )
dprint_color_reset(v23, v21);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): Event already exists\n",
*((const char **)&log_level_info + 16),
"pua [event_list.c:67]: ",
"add_pua_event");
}
--dprint_crit;
}
}
}
else
{
if ( a3 )
{
v27 = strlen(a3);
v8 = v7 + v27;
}
else
{
v27 = 0;
v8 = v7;
}
v26 = v8 + 56;
v9 = (_QWORD *)func4(v8 + 56);
v10 = v9;
if ( v9 )
{
memset(v9, 0, v26);
v10[1] = v10 + 7;
memcpy(v10 + 7, a2, v7);
*((_DWORD *)v10 + 4) = v7;
if ( a3 )
{
v11 = (char *)v10 + v7 + 56;
v10[3] = v11;
memcpy(v11, a3, v27);
*((_DWORD *)v10 + 8) = v27;
}
v10[5] = a4;
v12 = 0;
*(_DWORD *)v10 = a1;
v13 = pua_evlist;
v10[6] = *(_QWORD *)(pua_evlist + 48LL);
*(_QWORD *)(v13 + 48) = v10;
}
else
{
v12 = -1;
if ( (int)get_debug_level(&LC0, 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v17 = (const char *)*((_QWORD *)&log_level_info + 8);
v24 = my_pid();
v18 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): No more share memory\n",
process_no,
(unsigned int)v24,
v17,
"pua [event_list.c:78]: ",
"add_pua_event");
if ( log_color )
dprint_color_reset(v18, "%2d(%d) %s: %s%s(): No more share memory\n", v22, v24, v19, v20, v25);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): No more share memory\n",
*((const char **)&log_level_info + 8),
"pua [event_list.c:78]: ",
"add_pua_event");
}
v12 = -1;
--dprint_crit;
}
}
}
return v12;
}

original_code:
int add_pua_event(int ev_flag, char* name, char* content_type,
  evs_process_body_t* process_body)
{
 pua_event_t* event= ((void *)0);
 int size;
 int name_len;
 int ctype_len= 0;
 str str_name;
 name_len= strlen(name);
 str_name.s= name;
 str_name.len= name_len;
 if(contains_pua_event(&str_name))
 {
  do { if (get_debug_level("pua", (sizeof("pua")-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(): " "Event already exists\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("pua" " [" "event_list.c" ":" "67" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "Event already exists\n", (log_level_info[((3)) - (-5)].name), ("pua" " [" "event_list.c" ":" "67" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "Event already exists\n", process_no, my_pid(), ("pua" " [" "event_list.c" ":" "67" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Event already exists\n", ("pua" " [" "event_list.c" ":" "67" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Event already exists\n", ("pua" " [" "event_list.c" ":" "67" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return 0;
 }
 if(content_type)
  ctype_len= strlen(content_type);
 size= sizeof(pua_event_t)+ (name_len+ ctype_len)* sizeof(char);
 event= (pua_event_t*)shm_malloc(size);
 if(event== ((void *)0))
 {
  do { if (get_debug_level("pua", (sizeof("pua")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "No more share memory\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("pua" " [" "event_list.c" ":" "78" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "No more share memory\n", (log_level_info[((-1)) - (-5)].name), ("pua" " [" "event_list.c" ":" "78" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "No more share memory\n", process_no, my_pid(), ("pua" " [" "event_list.c" ":" "78" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "No more share memory\n", ("pua" " [" "event_list.c" ":" "78" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "No more share memory\n", ("pua" " [" "event_list.c" ":" "78" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 memset(event, 0, size);
 size= sizeof(pua_event_t);
 event->name.s= (char*)event+ size;
 memcpy(event->name.s, name, name_len);
 event->name.len= name_len;
 size+= name_len;
 if(content_type)
 {
  event->content_type.s= (char*)event+ size;
  memcpy(event->content_type.s, content_type, ctype_len);
  event->content_type.len= ctype_len;
  size+= ctype_len;
 }
 event->process_body= process_body;
 event->ev_flag= ev_flag;
 event->next= pua_evlist->next;
 pua_evlist->next= event;
 return 0;
}

canonical_original_code:
int add_pua_event(int ev_flag, char *name, char *content_type, int (*process_body)(struct publ_info *, struct _str **final_body, int ver, struct _str **tuple))
{
 struct pua_event *event = ((void *)0);
 int size;
 int name_len;
 int ctype_len = 0;
 struct _str str_name;
 name_len= strlen(name);
 str_name.s= name;
 str_name.len= name_len;
 if(contains_pua_event(&str_name))
 {
  do { if (get_debug_level("pua", (sizeof("pua")-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(): " "Event already exists\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("pua" " [" "event_list.c" ":" "67" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "Event already exists\n", (log_level_info[((3)) - (-5)].name), ("pua" " [" "event_list.c" ":" "67" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "Event already exists\n", process_no, my_pid(), ("pua" " [" "event_list.c" ":" "67" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Event already exists\n", ("pua" " [" "event_list.c" ":" "67" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Event already exists\n", ("pua" " [" "event_list.c" ":" "67" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return 0;
 }
 if(content_type)
  ctype_len= strlen(content_type);
 size= sizeof(pua_event_t)+ (name_len+ ctype_len)* sizeof(char);
 event= (struct pua_event *)shm_malloc(size);
 if(event== ((void *)0))
 {
  do { if (get_debug_level("pua", (sizeof("pua")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "No more share memory\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("pua" " [" "event_list.c" ":" "78" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "No more share memory\n", (log_level_info[((-1)) - (-5)].name), ("pua" " [" "event_list.c" ":" "78" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "No more share memory\n", process_no, my_pid(), ("pua" " [" "event_list.c" ":" "78" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "No more share memory\n", ("pua" " [" "event_list.c" ":" "78" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "No more share memory\n", ("pua" " [" "event_list.c" ":" "78" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 memset(event, 0, size);
 size= sizeof(pua_event_t);
 event->name.s= (char *)event+ size;
 memcpy(event->name.s, name, name_len);
 event->name.len= name_len;
 size+= name_len;
 if(content_type)
 {
  event->content_type.s= (char *)event+ size;
  memcpy(event->content_type.s, content_type, ctype_len);
  event->content_type.len= ctype_len;
  size+= ctype_len;
 }
 event->process_body= process_body;
 event->ev_flag= ev_flag;
 event->next= pua_evlist->next;
 pua_evlist->next= event;
 return 0;
}

variable_types:
name
char *

variable_types: int (*)(struct publ_info { struct _str { char *s; int len; } id; struct _str *pres_uri; struct _str *body; int expires; int flag; int source_flag; int event; struct _str content_type; struct _str *etag; struct _str *extra_headers; void *cb_param; } *, struct _str **final_body, int ver, struct _str **tuple)

variable_types: size int

user_defined_types: struct publ_info { struct _str id; struct _str *pres_uri; struct _str *body; int expires; int flag; int source_flag; int event; struct _str content_type; struct _str *etag; struct _str *extra_headers; void *cb_param; }


decompiled_code:
__int64 destroy_pua_evlist()
{
__int64 result; // rax
__int64 v1; // rbx
__int64 v2; // r12

result = pua_evlist;
if ( pua_evlist )
{
v1 = *(_QWORD *)(pua_evlist + 48LL);
while ( v1 )
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 48);
futex_get(mem_lock);
qm_free(shm_block, v2);
futex_release(mem_lock);
}
futex_get(mem_lock);
qm_free(shm_block, pua_evlist);
result = futex_release(mem_lock);
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax
__int64 v1; // rbx
__int64 v2; // r12

result = pua_evlist;
if ( pua_evlist )
{
v1 = *(_QWORD *)(pua_evlist + 48LL);
while ( v1 )
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 48);
func3(mem_lock);
qm_free(shm_block, v2);
func1(mem_lock);
}
func3(mem_lock);
qm_free(shm_block, pua_evlist);
result = func1(mem_lock);
}
return result;
}

original_code:
void destroy_pua_evlist(void)
{
 pua_event_t* e1, *e2;
 if(pua_evlist)
 {
  e1= pua_evlist->next;
  while(e1)
  {
   e2= e1->next;
   do { futex_get(mem_lock); qm_free(shm_block, (e1)); futex_release(mem_lock); }while(0);
   e1= e2;
  }
  do { futex_get(mem_lock); qm_free(shm_block, (pua_evlist)); futex_release(mem_lock); }while(0);
 }
}

canonical_original_code:
void destroy_pua_evlist()
{
 struct pua_event *e1; struct pua_event *e2;
 if(pua_evlist)
 {
  e1= pua_evlist->next;
  while(e1)
  {
   e2= e1->next;
   do { futex_get(mem_lock); qm_free(shm_block, (e1)); futex_release(mem_lock); }while(0);
   e1= e2;
  }
  do { futex_get(mem_lock); qm_free(shm_block, (pua_evlist)); futex_release(mem_lock); }while(0);
 }
}


decompiled_code:
char **__fastcall normalize_sip_uri(_QWORD *a1)
{
char **v1; // r12
char *v2; // rbp
const char *v4; // rbx
unsigned int v5; // eax
struct _IO_FILE *v6; // rdi

normalized_uri_5 = (char *)&buf_4;
if ( (int)un_escape_constprop_0(a1) < 0 )
{
v1 = (char **)&null_str_2;
if ( (int)get_debug_level(&LC0, 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v4 = (const char *)*((_QWORD *)&log_level_info + 8);
v5 = my_pid();
v6 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): un-escaping URI\n",
process_no,
v5,
v4,
"rls [utils.c:38]: ",
"normalize_sip_uri");
if ( log_color )
dprint_color_reset(v6, "%2d(%d) %s: %s%s(): un-escaping URI\n");
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): un-escaping URI\n",
*((const char **)&log_level_info + 8),
"rls [utils.c:38]: ",
"normalize_sip_uri");
}
v1 = (char **)&null_str_2;
--dprint_crit;
}
}
else
{
v1 = &normalized_uri_5;
normalized_uri_5[dword_DC8] = 0;
v2 = normalized_uri_5;
if ( strncasecmp(normalized_uri_5, "sip:", 4uLL) && strchr(v2, 64) )
{
memmove(v2 + 4, v2, dword_DC8 + 1);
*(_DWORD *)normalized_uri_5 = 980445555;
dword_DC8 += 4;
}
}
return v1;
}

canonical_decompiled_code:
char **__fastcall func2(_QWORD *a1)
{
char **v1; // r12
char *v2; // rbp
const char *v4; // rbx
unsigned int v5; // eax
struct _IO_FILE *v6; // rdi

normalized_uri_5 = (char *)&buf_4;
if ( (int)func1(a1) < 0 )
{
v1 = (char **)&null_str_2;
if ( (int)get_debug_level(&LC0, 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v4 = (const char *)*((_QWORD *)&log_level_info + 8);
v5 = my_pid();
v6 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): un-escaping URI\n",
process_no,
v5,
v4,
"rls [utils.c:38]: ",
"normalize_sip_uri");
if ( log_color )
dprint_color_reset(v6, "%2d(%d) %s: %s%s(): un-escaping URI\n");
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): un-escaping URI\n",
*((const char **)&log_level_info + 8),
"rls [utils.c:38]: ",
"normalize_sip_uri");
}
v1 = (char **)&null_str_2;
--dprint_crit;
}
}
else
{
v1 = &normalized_uri_5;
normalized_uri_5[dword_DC8] = 0;
v2 = normalized_uri_5;
if ( strncasecmp(normalized_uri_5, "sip:", 4uLL) && strchr(v2, 64) )
{
memmove(v2 + 4, v2, dword_DC8 + 1);
*(_DWORD *)normalized_uri_5 = 980445555;
dword_DC8 += 4;
}
}
return v1;
}

original_code:
str* normalize_sip_uri(const str *uri)
{
        static str normalized_uri;
        static str null_str = {((void *)0), 0};
        static char buf[1024];
        normalized_uri.s = buf;
        if (un_escape((str *)uri, &normalized_uri) < 0)
        {
                do { if (get_debug_level("rls", (sizeof("rls")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "un-escaping URI\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("rls" " [" "utils.c" ":" "38" "]: ") , __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(): " "un-escaping URI\n", (log_level_info[((-1)) - (-5)].name), ("rls" " [" "utils.c" ":" "38" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "un-escaping URI\n", process_no, my_pid(), ("rls" " [" "utils.c" ":" "38" "]: ") , __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(): " "un-escaping URI\n", ("rls" " [" "utils.c" ":" "38" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "un-escaping URI\n", ("rls" " [" "utils.c" ":" "38" "]: ") , __func__); } } (dprint_crit--); } } while(0);
                return &null_str;
        }
        normalized_uri.s[normalized_uri.len] = '\0';
        if (strncasecmp(normalized_uri.s, "sip:", sizeof("sip:")-1) != 0 && strchr(normalized_uri.s, '@') != ((void *)0))
        {
                memmove(normalized_uri.s+sizeof("sip:")-1, normalized_uri.s, normalized_uri.len+1);
                memcpy(normalized_uri.s, "sip:", sizeof("sip:")-1);
                normalized_uri.len += sizeof("sip:")-1;
        }
        return &normalized_uri;
}

canonical_original_code:
struct _str *normalize_sip_uri(struct _str *uri)
{
        static struct _str normalized_uri;
        static struct _str null_str = {((void *)0), 0};
        static char buf[1024];
        normalized_uri.s = buf;
        if (un_escape((struct _str *)uri, &normalized_uri) < 0)
        {
                do { if (get_debug_level("rls", (sizeof("rls")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "un-escaping URI\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("rls" " [" "utils.c" ":" "38" "]: ") , __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(): " "un-escaping URI\n", (log_level_info[((-1)) - (-5)].name), ("rls" " [" "utils.c" ":" "38" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "un-escaping URI\n", process_no, my_pid(), ("rls" " [" "utils.c" ":" "38" "]: ") , __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(): " "un-escaping URI\n", ("rls" " [" "utils.c" ":" "38" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "un-escaping URI\n", ("rls" " [" "utils.c" ":" "38" "]: ") , __func__); } } (dprint_crit--); } } while(0);
                return &null_str;
        }
        normalized_uri.s[normalized_uri.len] = '\0';
        if (strncasecmp(normalized_uri.s, "sip:", sizeof("sip:")-1) != 0 && strchr(normalized_uri.s, '@') != ((void *)0))
        {
                memmove(normalized_uri.s+sizeof("sip:")-1, normalized_uri.s, normalized_uri.len+1);
                memcpy(normalized_uri.s, "sip:", sizeof("sip:")-1);
                normalized_uri.len += sizeof("sip:")-1;
        }
        return &normalized_uri;
}

variable_types:
uri
struct _str *

variable_types:
buf
char [1024]

return_type: struct _str { char *s; int len; } *