decompiled_code:
__int64 __fastcall db_free_row(_QWORD *a1)
{
__int64 v1; // rbp
__int64 result; // rax
int v3; // er12
const char *v4; // r15
unsigned int v5; // eax
const char *v6; // r15
unsigned int v7; // eax
__int64 v8; // rbx
int v9; // eax
const char *v10; // r15
unsigned int v11; // eax
const void *v12; // r15
unsigned int v13; // eax
const void *v14; // rbp
const char *v15; // r14
unsigned int v16; // eax
const char *v17; // [rsp+0h] [rbp-48h]
int v18; // [rsp+0h] [rbp-48h]
const char *v19; // [rsp+0h] [rbp-48h]
const char *v20; // [rsp+8h] [rbp-40h]

if ( a1 )
{
v1 = 0LL;
if ( *((int *)a1 + 2) <= 0 )
{
LABEL_3:
*((_DWORD *)a1 + 2) = 0;
result = 0LL;
if ( *a1 )
{
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v14 = (const void *)*a1;
v15 = (const char *)*((_QWORD *)&log_level_info + 16);
v16 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): freeing row values at %p\n",
process_no,
v16,
v15,
"<core> [db_row.c:97]: ",
"db_free_row",
v14);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): freeing row values at %p\n",
*((const char **)&log_level_info + 16),
"<core> [db_row.c:97]: ",
"db_free_row",
(const void *)*a1);
}
--dprint_crit;
}
qm_free(mem_block, *a1);
*a1 = 0LL;
result = 0LL;
}
return result;
}
while ( 1 )
{
v8 = *a1 + 32 * v1;
v9 = *(_DWORD *)v8;
if ( *(_DWORD *)v8 == 4 )
{
if ( *(_DWORD *)(v8 + 4) || !*(_DWORD *)(v8 + 8) )
goto LABEL_26;
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v10 = *(const char **)(v8 + 16);
v18 = *(_DWORD *)(v8 + 24);
v20 = (const char *)*((_QWORD *)&log_level_info + 16);
v11 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): free VAL_STR[%d] '%.*s' at %p\n",
process_no,
v11,
v20,
"<core> [db_row.c:75]: ",
"db_free_row",
(unsigned int)v1,
v18,
v10,
v10);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): free VAL_STR[%d] '%.*s' at %p\n",
*((const char **)&log_level_info + 16),
"<core> [db_row.c:75]: ",
"db_free_row",
(unsigned int)v1,
*(_DWORD *)(v8 + 24),
*(const char **)(v8 + 16),
*(const void **)(v8 + 16));
}
--dprint_crit;
}
}
else if ( v9 == 6 )
{
if ( *(_DWORD *)(v8 + 4) || !*(_DWORD *)(v8 + 8) )
goto LABEL_26;
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v12 = *(const void **)(v8 + 16);
v19 = (const char *)*((_QWORD *)&log_level_info + 16);
v13 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): free VAL_BLOB[%d] at %p\n",
process_no,
v13,
v19,
"<core> [db_row.c:84]: ",
"db_free_row",
(unsigned int)v1,
v12);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): free VAL_BLOB[%d] at %p\n",
*((const char **)&log_level_info + 16),
"<core> [db_row.c:84]: ",
"db_free_row",
(unsigned int)v1,
*(const void **)(v8 + 16));
}
--dprint_crit;
}
}
else
{
if ( v9 != 3 || *(_DWORD *)(v8 + 4) || !*(_DWORD *)(v8 + 8) )
goto LABEL_26;
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v6 = *(const char **)(v8 + 16);
v17 = (const char *)*((_QWORD *)&log_level_info + 16);
v7 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): free VAL_STRING[%d] '%s' at %p\n",
process_no,
v7,
v17,
"<core> [db_row.c:66]: ",
"db_free_row",
(unsigned int)v1,
v6,
v6);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): free VAL_STRING[%d] '%s' at %p\n",
*((const char **)&log_level_info + 16),
"<core> [db_row.c:66]: ",
"db_free_row",
(unsigned int)v1,
*(const char **)(v8 + 16),
*(const void **)(v8 + 16));
}
--dprint_crit;
}
}
qm_free(mem_block, *(_QWORD *)(v8 + 16));
*(_QWORD *)(v8 + 16) = 0LL;
LABEL_26:
if ( *((_DWORD *)a1 + 2) <= (int)++v1 )
goto LABEL_3;
}
}
v3 = get_debug_level("core", 4LL);
result = 0xFFFFFFFFLL;
if ( v3 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !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(): invalid parameter value\n",
process_no,
v5,
v4,
"<core> [db_row.c:48]: ",
"db_free_row");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): invalid parameter value\n",
*((const char **)&log_level_info + 8),
"<core> [db_row.c:48]: ",
"db_free_row");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 v1; // rbp
__int64 result; // rax
int v3; // er12
const char *v4; // r15
unsigned int v5; // eax
const char *v6; // r15
unsigned int v7; // eax
__int64 v8; // rbx
int v9; // eax
const char *v10; // r15
unsigned int v11; // eax
const void *v12; // r15
unsigned int v13; // eax
const void *v14; // rbp
const char *v15; // r14
unsigned int v16; // eax
const char *v17; // [rsp+0h] [rbp-48h]
int v18; // [rsp+0h] [rbp-48h]
const char *v19; // [rsp+0h] [rbp-48h]
const char *v20; // [rsp+8h] [rbp-40h]

if ( a1 )
{
v1 = 0LL;
if ( *((int *)a1 + 2) <= 0 )
{
LABEL_3:
*((_DWORD *)a1 + 2) = 0;
result = 0LL;
if ( *a1 )
{
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v14 = (const void *)*a1;
v15 = (const char *)*((_QWORD *)&log_level_info + 16);
v16 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): freeing row values at %p\n",
process_no,
v16,
v15,
"<core> [db_row.c:97]: ",
"db_free_row",
v14);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): freeing row values at %p\n",
*((const char **)&log_level_info + 16),
"<core> [db_row.c:97]: ",
"db_free_row",
(const void *)*a1);
}
--dprint_crit;
}
qm_free(mem_block, *a1);
*a1 = 0LL;
result = 0LL;
}
return result;
}
while ( 1 )
{
v8 = *a1 + 32 * v1;
v9 = *(_DWORD *)v8;
if ( *(_DWORD *)v8 == 4 )
{
if ( *(_DWORD *)(v8 + 4) || !*(_DWORD *)(v8 + 8) )
goto LABEL_26;
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v10 = *(const char **)(v8 + 16);
v18 = *(_DWORD *)(v8 + 24);
v20 = (const char *)*((_QWORD *)&log_level_info + 16);
v11 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): free VAL_STR[%d] '%.*s' at %p\n",
process_no,
v11,
v20,
"<core> [db_row.c:75]: ",
"db_free_row",
(unsigned int)v1,
v18,
v10,
v10);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): free VAL_STR[%d] '%.*s' at %p\n",
*((const char **)&log_level_info + 16),
"<core> [db_row.c:75]: ",
"db_free_row",
(unsigned int)v1,
*(_DWORD *)(v8 + 24),
*(const char **)(v8 + 16),
*(const void **)(v8 + 16));
}
--dprint_crit;
}
}
else if ( v9 == 6 )
{
if ( *(_DWORD *)(v8 + 4) || !*(_DWORD *)(v8 + 8) )
goto LABEL_26;
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v12 = *(const void **)(v8 + 16);
v19 = (const char *)*((_QWORD *)&log_level_info + 16);
v13 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): free VAL_BLOB[%d] at %p\n",
process_no,
v13,
v19,
"<core> [db_row.c:84]: ",
"db_free_row",
(unsigned int)v1,
v12);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): free VAL_BLOB[%d] at %p\n",
*((const char **)&log_level_info + 16),
"<core> [db_row.c:84]: ",
"db_free_row",
(unsigned int)v1,
*(const void **)(v8 + 16));
}
--dprint_crit;
}
}
else
{
if ( v9 != 3 || *(_DWORD *)(v8 + 4) || !*(_DWORD *)(v8 + 8) )
goto LABEL_26;
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v6 = *(const char **)(v8 + 16);
v17 = (const char *)*((_QWORD *)&log_level_info + 16);
v7 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): free VAL_STRING[%d] '%s' at %p\n",
process_no,
v7,
v17,
"<core> [db_row.c:66]: ",
"db_free_row",
(unsigned int)v1,
v6,
v6);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): free VAL_STRING[%d] '%s' at %p\n",
*((const char **)&log_level_info + 16),
"<core> [db_row.c:66]: ",
"db_free_row",
(unsigned int)v1,
*(const char **)(v8 + 16),
*(const void **)(v8 + 16));
}
--dprint_crit;
}
}
qm_free(mem_block, *(_QWORD *)(v8 + 16));
*(_QWORD *)(v8 + 16) = 0LL;
LABEL_26:
if ( *((_DWORD *)a1 + 2) <= (int)++v1 )
goto LABEL_3;
}
}
v3 = get_debug_level("core", 4LL);
result = 0xFFFFFFFFLL;
if ( v3 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !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(): invalid parameter value\n",
process_no,
v5,
v4,
"<core> [db_row.c:48]: ",
"db_free_row");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): invalid parameter value\n",
*((const char **)&log_level_info + 8),
"<core> [db_row.c:48]: ",
"db_free_row");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
inline int db_free_row(db_row_t* _r)
{
 int col;
 db_val_t* _val;
 if (!_r) {
  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(): " "invalid parameter value\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "db_row.c" ":" "48" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "invalid parameter value\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "db_row.c" ":" "48" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "invalid parameter value\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "48" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "invalid parameter value\n", ("<core> [" "db_row.c" ":" "48" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "invalid parameter value\n", ("<core> [" "db_row.c" ":" "48" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 for (col = 0; col < ((_r)->n); col++) {
  _val = &(((_r)->values)[col]);
  switch (((_val)->type)) {
   case DB1_STRING:
    if ( (!((_val)->nul)) && ((_val)->free)) {
     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(): " "free VAL_STRING[%d] '%s' at %p\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "66" "]: ") , __func__, col, (char *)((_val)->val.string_val), (char *)((_val)->val.string_val)); 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(): " "free VAL_STRING[%d] '%s' at %p\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "66" "]: ") , __func__, col, (char *)((_val)->val.string_val), (char *)((_val)->val.string_val)); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "free VAL_STRING[%d] '%s' at %p\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "66" "]: ") , __func__, col, (char *)((_val)->val.string_val), (char *)((_val)->val.string_val)); 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(): " "free VAL_STRING[%d] '%s' at %p\n", ("<core> [" "db_row.c" ":" "66" "]: ") , __func__, col, (char *)((_val)->val.string_val), (char *)((_val)->val.string_val)); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "free VAL_STRING[%d] '%s' at %p\n", ("<core> [" "db_row.c" ":" "66" "]: ") , __func__, col, (char *)((_val)->val.string_val), (char *)((_val)->val.string_val)); } } (dprint_crit--); } } while(0);
     qm_free(mem_block, ((char *)((_val)->val.string_val)));
     ((_val)->val.string_val) = ((void *)0);
    }
    break;
   case DB1_STR:
    if ( (!((_val)->nul)) && ((_val)->free)) {
     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(): " "free VAL_STR[%d] '%.*s' at %p\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "75" "]: ") , __func__, col, ((_val)->val.str_val).len, ((_val)->val.str_val).s, ((_val)->val.str_val).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(): " "free VAL_STR[%d] '%.*s' at %p\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "75" "]: ") , __func__, col, ((_val)->val.str_val).len, ((_val)->val.str_val).s, ((_val)->val.str_val).s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "free VAL_STR[%d] '%.*s' at %p\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "75" "]: ") , __func__, col, ((_val)->val.str_val).len, ((_val)->val.str_val).s, ((_val)->val.str_val).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(): " "free VAL_STR[%d] '%.*s' at %p\n", ("<core> [" "db_row.c" ":" "75" "]: ") , __func__, col, ((_val)->val.str_val).len, ((_val)->val.str_val).s, ((_val)->val.str_val).s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "free VAL_STR[%d] '%.*s' at %p\n", ("<core> [" "db_row.c" ":" "75" "]: ") , __func__, col, ((_val)->val.str_val).len, ((_val)->val.str_val).s, ((_val)->val.str_val).s); } } (dprint_crit--); } } while(0);
     qm_free(mem_block, (((_val)->val.str_val).s));
     ((_val)->val.str_val).s = ((void *)0);
    }
    break;
   case DB1_BLOB:
    if ( (!((_val)->nul)) && ((_val)->free)) {
     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(): " "free VAL_BLOB[%d] at %p\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "84" "]: ") , __func__, col, ((_val)->val.blob_val).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(): " "free VAL_BLOB[%d] at %p\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "84" "]: ") , __func__, col, ((_val)->val.blob_val).s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "free VAL_BLOB[%d] at %p\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "84" "]: ") , __func__, col, ((_val)->val.blob_val).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(): " "free VAL_BLOB[%d] at %p\n", ("<core> [" "db_row.c" ":" "84" "]: ") , __func__, col, ((_val)->val.blob_val).s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "free VAL_BLOB[%d] at %p\n", ("<core> [" "db_row.c" ":" "84" "]: ") , __func__, col, ((_val)->val.blob_val).s); } } (dprint_crit--); } } while(0);
     qm_free(mem_block, (((_val)->val.blob_val).s));
     ((_val)->val.blob_val).s = ((void *)0);
    }
    break;
   default:
    break;
  }
 }
 ((_r)->n) = 0;
 if (((_r)->values)) {
  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(): " "freeing row values at %p\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "97" "]: ") , __func__, ((_r)->values)); 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(): " "freeing row values at %p\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "97" "]: ") , __func__, ((_r)->values)); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "freeing row values at %p\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "97" "]: ") , __func__, ((_r)->values)); 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(): " "freeing row values at %p\n", ("<core> [" "db_row.c" ":" "97" "]: ") , __func__, ((_r)->values)); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "freeing row values at %p\n", ("<core> [" "db_row.c" ":" "97" "]: ") , __func__, ((_r)->values)); } } (dprint_crit--); } } while(0);
  qm_free(mem_block, (((_r)->values)));
  ((_r)->values) = ((void *)0);
 }
 return 0;
}

canonical_original_code:
inline int db_free_row(struct db_row *_r)
{
 int col;
 struct db_val_t *_val;
 if (!_r) {
  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(): " "invalid parameter value\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "db_row.c" ":" "48" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "invalid parameter value\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "db_row.c" ":" "48" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "invalid parameter value\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "48" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "invalid parameter value\n", ("<core> [" "db_row.c" ":" "48" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "invalid parameter value\n", ("<core> [" "db_row.c" ":" "48" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 for (col = 0; col < ((_r)->n); col++) {
  _val = &(((_r)->values)[col]);
  switch (((_val)->type)) {
   case DB1_STRING:
    if ( (!((_val)->nul)) && ((_val)->free)) {
     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(): " "free VAL_STRING[%d] '%s' at %p\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "66" "]: ") , __func__, col, (char *)((_val)->val.string_val), (char *)((_val)->val.string_val)); 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(): " "free VAL_STRING[%d] '%s' at %p\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "66" "]: ") , __func__, col, (char *)((_val)->val.string_val), (char *)((_val)->val.string_val)); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "free VAL_STRING[%d] '%s' at %p\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "66" "]: ") , __func__, col, (char *)((_val)->val.string_val), (char *)((_val)->val.string_val)); 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(): " "free VAL_STRING[%d] '%s' at %p\n", ("<core> [" "db_row.c" ":" "66" "]: ") , __func__, col, (char *)((_val)->val.string_val), (char *)((_val)->val.string_val)); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "free VAL_STRING[%d] '%s' at %p\n", ("<core> [" "db_row.c" ":" "66" "]: ") , __func__, col, (char *)((_val)->val.string_val), (char *)((_val)->val.string_val)); } } (dprint_crit--); } } while(0);
     qm_free(mem_block, ((char *)((_val)->val.string_val)));
     ((_val)->val.string_val) = ((void *)0);
    }
    break;
   case DB1_STR:
    if ( (!((_val)->nul)) && ((_val)->free)) {
     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(): " "free VAL_STR[%d] '%.*s' at %p\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "75" "]: ") , __func__, col, ((_val)->val.str_val).len, ((_val)->val.str_val).s, ((_val)->val.str_val).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(): " "free VAL_STR[%d] '%.*s' at %p\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "75" "]: ") , __func__, col, ((_val)->val.str_val).len, ((_val)->val.str_val).s, ((_val)->val.str_val).s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "free VAL_STR[%d] '%.*s' at %p\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "75" "]: ") , __func__, col, ((_val)->val.str_val).len, ((_val)->val.str_val).s, ((_val)->val.str_val).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(): " "free VAL_STR[%d] '%.*s' at %p\n", ("<core> [" "db_row.c" ":" "75" "]: ") , __func__, col, ((_val)->val.str_val).len, ((_val)->val.str_val).s, ((_val)->val.str_val).s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "free VAL_STR[%d] '%.*s' at %p\n", ("<core> [" "db_row.c" ":" "75" "]: ") , __func__, col, ((_val)->val.str_val).len, ((_val)->val.str_val).s, ((_val)->val.str_val).s); } } (dprint_crit--); } } while(0);
     qm_free(mem_block, (((_val)->val.str_val).s));
     ((_val)->val.str_val).s = ((void *)0);
    }
    break;
   case DB1_BLOB:
    if ( (!((_val)->nul)) && ((_val)->free)) {
     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(): " "free VAL_BLOB[%d] at %p\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "84" "]: ") , __func__, col, ((_val)->val.blob_val).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(): " "free VAL_BLOB[%d] at %p\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "84" "]: ") , __func__, col, ((_val)->val.blob_val).s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "free VAL_BLOB[%d] at %p\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "84" "]: ") , __func__, col, ((_val)->val.blob_val).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(): " "free VAL_BLOB[%d] at %p\n", ("<core> [" "db_row.c" ":" "84" "]: ") , __func__, col, ((_val)->val.blob_val).s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "free VAL_BLOB[%d] at %p\n", ("<core> [" "db_row.c" ":" "84" "]: ") , __func__, col, ((_val)->val.blob_val).s); } } (dprint_crit--); } } while(0);
     qm_free(mem_block, (((_val)->val.blob_val).s));
     ((_val)->val.blob_val).s = ((void *)0);
    }
    break;
   default:
    break;
  }
 }
 ((_r)->n) = 0;
 if (((_r)->values)) {
  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(): " "freeing row values at %p\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "97" "]: ") , __func__, ((_r)->values)); 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(): " "freeing row values at %p\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "97" "]: ") , __func__, ((_r)->values)); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "freeing row values at %p\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "97" "]: ") , __func__, ((_r)->values)); 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(): " "freeing row values at %p\n", ("<core> [" "db_row.c" ":" "97" "]: ") , __func__, ((_r)->values)); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "freeing row values at %p\n", ("<core> [" "db_row.c" ":" "97" "]: ") , __func__, ((_r)->values)); } } (dprint_crit--); } } while(0);
  qm_free(mem_block, (((_r)->values)));
  ((_r)->values) = ((void *)0);
 }
 return 0;
}

variable_types: struct db_row { struct db_val_t { enum db_type_t { DB1_INT=0, DB1_BIGINT=1, DB1_DOUBLE=2, DB1_STRING=3, DB1_STR=4, DB1_DATETIME=5, DB1_BLOB=6, DB1_BITMAP=7 } type; int nul; int free; union { int int_val; long long ll_val; double double_val; long time_val; char *string_val; struct _str { char *s; int len; } str_val; struct _str blob_val; unsigned int bitmap_val; } val; } *values; int n; } *

variable_types: col int

user_defined_types: struct db_row { struct db_val_t *values; int n; }

user_defined_types: struct db_val_t { enum db_type_t type; int nul; int free; union { int int_val; long long ll_val; double double_val; long time_val; char *string_val; struct _str str_val; struct _str blob_val; unsigned int bitmap_val; } val; }


repo: virtualolson/who

decompiled_code:
__int64 __fastcall db_allocate_row(__int64 a1, const void **a2)
{
int v2; // er12
__int64 v3; // rax
__int64 result; // rax
int v5; // ebx
const char *v6; // rbp
unsigned int v7; // eax
const void *v8; // r15
const char *v9; // r14
unsigned int v10; // eax

v2 = 32 * *(_DWORD *)(a1 + 16);
v3 = qm_malloc(mem_block, v2);
*a2 = (const void *)v3;
if ( v3 )
{
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v8 = *a2;
v9 = (const char *)*((_QWORD *)&log_level_info + 16);
v10 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): allocate %d bytes for row values at %p\n",
process_no,
v10,
v9,
"<core> [db_row.c:119]: ",
"db_allocate_row",
(unsigned int)v2,
v8);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): allocate %d bytes for row values at %p\n",
*((const char **)&log_level_info + 16),
"<core> [db_row.c:119]: ",
"db_allocate_row",
(unsigned int)v2,
*a2);
}
--dprint_crit;
}
memset((void *)*a2, 0, v2);
*((_DWORD *)a2 + 2) = *(_DWORD *)(a1 + 16);
result = 0LL;
}
else
{
v5 = get_debug_level("core", 4LL);
result = 0xFFFFFFFFLL;
if ( v5 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v6 = (const char *)*((_QWORD *)&log_level_info + 8);
v7 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): no private memory left\n",
process_no,
v7,
v6,
"<core> [db_row.c:116]: ",
"db_allocate_row");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): no private memory left\n",
*((const char **)&log_level_info + 8),
"<core> [db_row.c:116]: ",
"db_allocate_row");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const void **a2)
{
int v2; // er12
__int64 v3; // rax
__int64 result; // rax
int v5; // ebx
const char *v6; // rbp
unsigned int v7; // eax
const void *v8; // r15
const char *v9; // r14
unsigned int v10; // eax

v2 = 32 * *(_DWORD *)(a1 + 16);
v3 = qm_malloc(mem_block, v2);
*a2 = (const void *)v3;
if ( v3 )
{
if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v8 = *a2;
v9 = (const char *)*((_QWORD *)&log_level_info + 16);
v10 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): allocate %d bytes for row values at %p\n",
process_no,
v10,
v9,
"<core> [db_row.c:119]: ",
"db_allocate_row",
(unsigned int)v2,
v8);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): allocate %d bytes for row values at %p\n",
*((const char **)&log_level_info + 16),
"<core> [db_row.c:119]: ",
"db_allocate_row",
(unsigned int)v2,
*a2);
}
--dprint_crit;
}
memset((void *)*a2, 0, v2);
*((_DWORD *)a2 + 2) = *(_DWORD *)(a1 + 16);
result = 0LL;
}
else
{
v5 = get_debug_level("core", 4LL);
result = 0xFFFFFFFFLL;
if ( v5 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v6 = (const char *)*((_QWORD *)&log_level_info + 8);
v7 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): no private memory left\n",
process_no,
v7,
v6,
"<core> [db_row.c:116]: ",
"db_allocate_row");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): no private memory left\n",
*((const char **)&log_level_info + 8),
"<core> [db_row.c:116]: ",
"db_allocate_row");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
inline int db_allocate_row(const db1_res_t* _res, db_row_t* _row)
{
 int len = sizeof(db_val_t) * ((_res)->col.n);
 ((_row)->values) = (db_val_t*)qm_malloc(mem_block, (len));
 if (!((_row)->values)) {
  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(): " "no private memory left\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "db_row.c" ":" "116" "]: ") , __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 private memory left\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "db_row.c" ":" "116" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no private memory left\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "116" "]: ") , __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 private memory left\n", ("<core> [" "db_row.c" ":" "116" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no private memory left\n", ("<core> [" "db_row.c" ":" "116" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 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(): " "allocate %d bytes for row values at %p\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "119" "]: ") , __func__, len, ((_row)->values)); 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(): " "allocate %d bytes for row values at %p\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "119" "]: ") , __func__, len, ((_row)->values)); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "allocate %d bytes for row values at %p\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "119" "]: ") , __func__, len, ((_row)->values)); 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(): " "allocate %d bytes for row values at %p\n", ("<core> [" "db_row.c" ":" "119" "]: ") , __func__, len, ((_row)->values)); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "allocate %d bytes for row values at %p\n", ("<core> [" "db_row.c" ":" "119" "]: ") , __func__, len, ((_row)->values)); } } (dprint_crit--); } } while(0);
 memset(((_row)->values), 0, len);
 ((_row)->n) = ((_res)->col.n);
 return 0;
}

canonical_original_code:
inline int db_allocate_row(struct db1_res *_res, struct db_row *_row)
{
 int len = sizeof(db_val_t) * ((_res)->col.n);
 ((_row)->values) = (struct db_val_t *)qm_malloc(mem_block, (len));
 if (!((_row)->values)) {
  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(): " "no private memory left\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "db_row.c" ":" "116" "]: ") , __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 private memory left\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "db_row.c" ":" "116" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no private memory left\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "116" "]: ") , __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 private memory left\n", ("<core> [" "db_row.c" ":" "116" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no private memory left\n", ("<core> [" "db_row.c" ":" "116" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 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(): " "allocate %d bytes for row values at %p\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "119" "]: ") , __func__, len, ((_row)->values)); 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(): " "allocate %d bytes for row values at %p\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "db_row.c" ":" "119" "]: ") , __func__, len, ((_row)->values)); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "allocate %d bytes for row values at %p\n", process_no, my_pid(), ("<core> [" "db_row.c" ":" "119" "]: ") , __func__, len, ((_row)->values)); 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(): " "allocate %d bytes for row values at %p\n", ("<core> [" "db_row.c" ":" "119" "]: ") , __func__, len, ((_row)->values)); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "allocate %d bytes for row values at %p\n", ("<core> [" "db_row.c" ":" "119" "]: ") , __func__, len, ((_row)->values)); } } (dprint_crit--); } } while(0);
 memset(((_row)->values), 0, len);
 ((_row)->n) = ((_res)->col.n);
 return 0;
}

variable_types: struct db1_res { struct { struct _str { char *s; int len; } **names; enum db_type_t { DB1_INT=0, DB1_BIGINT=1, DB1_DOUBLE=2, DB1_STRING=3, DB1_STR=4, DB1_DATETIME=5, DB1_BLOB=6, DB1_BITMAP=7 } *types; int n; } col; struct db_row { struct db_val_t { enum db_type_t { DB1_INT=0, DB1_BIGINT=1, DB1_DOUBLE=2, DB1_STRING=3, DB1_STR=4, DB1_DATETIME=5, DB1_BLOB=6, DB1_BITMAP=7 } type; int nul; int free; union { int int_val; long long ll_val; double double_val; long time_val; char *string_val; struct _str str_val; struct _str blob_val; unsigned int bitmap_val; } val; } *values; int n; } *rows; int n; int res_rows; int last_row; void *ptr; } *

variable_types: len int

return_type: int

user_defined_types: struct db1_res { struct { struct _str **names; enum db_type_t *types; int n; } col; struct db_row *rows; int n; int res_rows; int last_row; void *ptr; }

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


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

canonical_decompiled_code:
__int64 __fastcall func6(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_get(volatile signed __int32 *a1)
{
__int64 result; // rax
int v2; // ebp
int v3; // ebp

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

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

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

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

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

variable_types:
lock
struct atomic_t { int val; } *

variable_types: i int

return_type: void


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

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

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

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

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

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


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

if ( a1 )
{
futex_get(mem_lock);
qm_free();
result = futex_release(mem_lock);
}
return result;
}

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

if ( a1 )
{
func8(mem_lock);
qm_free();
result = func9(mem_lock);
}
return result;
}

original_code:
static void shm_free_hook(void *ptr, const void *caller)
{
 if (ptr) do { futex_get(mem_lock); qm_free(shm_block, (ptr)); futex_release(mem_lock); }while(0);
}

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

variable_types:
ptr
void *

variable_types:
caller
void *


decompiled_code:
__int64 shm_realloc()
{
__int64 v0; // rbp

futex_get(mem_lock);
v0 = qm_realloc();
futex_release(mem_lock);
return v0;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 v0; // rbp

func8(mem_lock);
v0 = qm_realloc();
func9(mem_lock);
return v0;
}

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

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

variable_types:
size
unsigned int

variable_types:
p
void *

return_type: void *


decompiled_code:
__int64 shm_realloc_hook()
{
return shm_realloc();
}

canonical_decompiled_code:
__int64 func12()
{
return func11();
}

original_code:
static void *shm_realloc_hook(void *p, size_t size, const void *caller)
{
 return shm_realloc (p, size);
}

canonical_original_code:
static void *shm_realloc_hook(void *p, unsigned long size, void *caller)
{
 return shm_realloc (p, size);
}

variable_types:
size
unsigned long


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

futex_get(mem_lock);
v0 = qm_malloc();
futex_release(mem_lock);
return v0;
}

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

func8(mem_lock);
v0 = qm_malloc();
func9(mem_lock);
return v0;
}

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


decompiled_code:
__int64 shm_malloc_hook()
{
return shm_malloc();
}

canonical_decompiled_code:
__int64 func14()
{
return func13();
}

original_code:
static void *shm_malloc_hook(size_t size, const void *caller)
{
 return shm_malloc (size);
}

canonical_original_code:
static void *shm_malloc_hook(unsigned long size, void *caller)
{
 return shm_malloc (size);
}


decompiled_code:
void __fastcall im_reload(void (__fastcall **a1)(__int64, __int64, const char *), __int64 a2)
{
const char *v2; // r12
unsigned int v3; // eax
const char *v4; // rbx
unsigned int v5; // eax

if ( db_mode == 1 )
{
if ( (unsigned int)reload_im_cache() )
{
if ( (int)get_debug_level("permissions", 11LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v2 = (const char *)*((_QWORD *)&log_level_info + 8);
v3 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): ERROR: Reloading of ipmatch cache failed\n",
process_no,
v3,
v2,
"permissions [im_rpc.c:50]: ",
"im_reload");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR: Reloading of ipmatch cache failed\n",
*((const char **)&log_level_info + 8),
"permissions [im_rpc.c:50]: ",
"im_reload");
}
--dprint_crit;
}
(*a1)(a2, 400LL, "Reloading failed");
}
else if ( (int)get_debug_level("permissions", 11LL) > 1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(2LL);
v4 = (const char *)*((_QWORD *)&log_level_info + 14);
v5 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): INFO: ipmatch cache is reloaded\n",
process_no,
v5,
v4,
"permissions [im_rpc.c:54]: ",
"im_reload");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 30) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): INFO: ipmatch cache is reloaded\n",
*((const char **)&log_level_info + 14),
"permissions [im_rpc.c:54]: ",
"im_reload");
}
--dprint_crit;
}
}
else
{
(*a1)(a2, 400LL, "Database cache is not enabled");
}
}

canonical_decompiled_code:
void __fastcall func0(void (__fastcall **a1)(__int64, __int64, const char *), __int64 a2)
{
const char *v2; // r12
unsigned int v3; // eax
const char *v4; // rbx
unsigned int v5; // eax

if ( db_mode == 1 )
{
if ( (unsigned int)reload_im_cache() )
{
if ( (int)get_debug_level("permissions", 11LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v2 = (const char *)*((_QWORD *)&log_level_info + 8);
v3 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): ERROR: Reloading of ipmatch cache failed\n",
process_no,
v3,
v2,
"permissions [im_rpc.c:50]: ",
"im_reload");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR: Reloading of ipmatch cache failed\n",
*((const char **)&log_level_info + 8),
"permissions [im_rpc.c:50]: ",
"im_reload");
}
--dprint_crit;
}
(*a1)(a2, 400LL, "Reloading failed");
}
else if ( (int)get_debug_level("permissions", 11LL) > 1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(2LL);
v4 = (const char *)*((_QWORD *)&log_level_info + 14);
v5 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): INFO: ipmatch cache is reloaded\n",
process_no,
v5,
v4,
"permissions [im_rpc.c:54]: ",
"im_reload");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 30) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): INFO: ipmatch cache is reloaded\n",
*((const char **)&log_level_info + 14),
"permissions [im_rpc.c:54]: ",
"im_reload");
}
--dprint_crit;
}
}
else
{
(*a1)(a2, 400LL, "Database cache is not enabled");
}
}

original_code:
void im_reload(rpc_t *rpc, void *c)
{
 if (db_mode != 1) {
  rpc->fault(c, 400, "Database cache is not enabled");
  return;
 }
 if (reload_im_cache()) {
  do { if (get_debug_level("permissions", (sizeof("permissions")-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: Reloading of ipmatch cache failed\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("permissions" " [" "im_rpc.c" ":" "50" "]: ") , __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: Reloading of ipmatch cache failed\n", (log_level_info[((-1)) - (-5)].name), ("permissions" " [" "im_rpc.c" ":" "50" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR: Reloading of ipmatch cache failed\n", process_no, my_pid(), ("permissions" " [" "im_rpc.c" ":" "50" "]: ") , __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: Reloading of ipmatch cache failed\n", ("permissions" " [" "im_rpc.c" ":" "50" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR: Reloading of ipmatch cache failed\n", ("permissions" " [" "im_rpc.c" ":" "50" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  rpc->fault(c, 400, "Reloading failed");
 } else {
  do { if (get_debug_level("permissions", (sizeof("permissions")-1)) >= ((2)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((2)) >= -5) && (((2)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((2)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "INFO: ipmatch cache is reloaded\n", process_no, my_pid(), (log_level_info[((2)) - (-5)].name), ("permissions" " [" "im_rpc.c" ":" "54" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((2)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "INFO: ipmatch cache is reloaded\n", (log_level_info[((2)) - (-5)].name), ("permissions" " [" "im_rpc.c" ":" "54" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((2)); fprintf(stderr, "%2d(%d) %s" "%s(): " "INFO: ipmatch cache is reloaded\n", process_no, my_pid(), ("permissions" " [" "im_rpc.c" ":" "54" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((2))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "INFO: ipmatch cache is reloaded\n", ("permissions" " [" "im_rpc.c" ":" "54" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "INFO: ipmatch cache is reloaded\n", ("permissions" " [" "im_rpc.c" ":" "54" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 }
}

canonical_original_code:
void im_reload(struct rpc *rpc, void *c)
{
 if (db_mode != 1) {
  rpc->fault(c, 400, "Database cache is not enabled");
  return;
 }
 if (reload_im_cache()) {
  do { if (get_debug_level("permissions", (sizeof("permissions")-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: Reloading of ipmatch cache failed\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("permissions" " [" "im_rpc.c" ":" "50" "]: ") , __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: Reloading of ipmatch cache failed\n", (log_level_info[((-1)) - (-5)].name), ("permissions" " [" "im_rpc.c" ":" "50" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR: Reloading of ipmatch cache failed\n", process_no, my_pid(), ("permissions" " [" "im_rpc.c" ":" "50" "]: ") , __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: Reloading of ipmatch cache failed\n", ("permissions" " [" "im_rpc.c" ":" "50" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR: Reloading of ipmatch cache failed\n", ("permissions" " [" "im_rpc.c" ":" "50" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  rpc->fault(c, 400, "Reloading failed");
 } else {
  do { if (get_debug_level("permissions", (sizeof("permissions")-1)) >= ((2)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((2)) >= -5) && (((2)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((2)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "INFO: ipmatch cache is reloaded\n", process_no, my_pid(), (log_level_info[((2)) - (-5)].name), ("permissions" " [" "im_rpc.c" ":" "54" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((2)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "INFO: ipmatch cache is reloaded\n", (log_level_info[((2)) - (-5)].name), ("permissions" " [" "im_rpc.c" ":" "54" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((2)); fprintf(stderr, "%2d(%d) %s" "%s(): " "INFO: ipmatch cache is reloaded\n", process_no, my_pid(), ("permissions" " [" "im_rpc.c" ":" "54" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((2))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "INFO: ipmatch cache is reloaded\n", ("permissions" " [" "im_rpc.c" ":" "54" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "INFO: ipmatch cache is reloaded\n", ("permissions" " [" "im_rpc.c" ":" "54" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 }
}

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

variable_types:
c
void *

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


decompiled_code:
__int64 __fastcall udp4_raw_ttl_fixup(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
int v5; // eax

v5 = *a4;
if ( v5 < 0 )
{
v5 = 63;
if ( sendipv4 )
{
v5 = sock_get_ttl((unsigned int)*sendipv4);
if ( v5 < 0 )
v5 = 63;
}
}
*a4 = v5;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
int v5; // eax

v5 = *a4;
if ( v5 < 0 )
{
v5 = 63;
if ( sendipv4 )
{
v5 = sock_get_ttl((unsigned int)*sendipv4);
if ( v5 < 0 )
v5 = 63;
}
}
*a4 = v5;
return 0LL;
}

original_code:
static int udp4_raw_ttl_fixup(void* cfg_h, str* gname, str* name, void** val)
{
 int v;
 v = (int)(long)(*val);
 if (v < 0) {
  if (sendipv4)
   v = sock_get_ttl(sendipv4->socket);
 }
 if (v < 0) {
  v = 63;
 }
 *val = (void*)(long)v;
 return 0;
}

canonical_original_code:
static int udp4_raw_ttl_fixup(void *cfg_h, struct _str *gname, struct _str *name, void **val)
{
 int v;
 v = (int)(long)(*val);
 if (v < 0) {
  if (sendipv4)
   v = sock_get_ttl(sendipv4->socket);
 }
 if (v < 0) {
  v = 63;
 }
 *val = (void *)(long)v;
 return 0;
}

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

variable_types:
name
struct _str *

variable_types:
val
void **


decompiled_code:
__int64 __fastcall check_raw_sock_support(__int64 a1, __int64 a2, __int64 a3, __int64 *a4)
{
__int64 v4; // rdx
__int64 result; // rax
int v6; // ecx
const char *v7; // rbx
unsigned int v8; // eax

v4 = *a4;
if ( raw_udp4_send_sock < 0 )
{
if ( (int)v4 > 0 )
{
v6 = get_debug_level("core", 4LL);
result = 0xFFFFFFFFLL;
if ( v6 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v7 = (const char *)*((_QWORD *)&log_level_info + 8);
v8 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): could not intialize raw socket on startup, please restart as root or with CAP_NET_RAW\n",
process_no,
v8,
v7,
"<core> [cfg_core.c:146]: ",
"check_raw_sock_support");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *((_DWORD *)core_cfg + 1),
"%s: %s%s(): could not intialize raw socket on startup, please restart as root or with CAP_NET_RAW\n",
*((const char **)&log_level_info + 8),
"<core> [cfg_core.c:146]: ",
"check_raw_sock_support");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0LL;
if ( (int)v4 < 0 )
*a4 = 0LL;
}
}
else
{
result = 0LL;
if ( (int)v4 < 0 )
*a4 = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 *a4)
{
__int64 v4; // rdx
__int64 result; // rax
int v6; // ecx
const char *v7; // rbx
unsigned int v8; // eax

v4 = *a4;
if ( raw_udp4_send_sock < 0 )
{
if ( (int)v4 > 0 )
{
v6 = get_debug_level("core", 4LL);
result = 0xFFFFFFFFLL;
if ( v6 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v7 = (const char *)*((_QWORD *)&log_level_info + 8);
v8 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): could not intialize raw socket on startup, please restart as root or with CAP_NET_RAW\n",
process_no,
v8,
v7,
"<core> [cfg_core.c:146]: ",
"check_raw_sock_support");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *((_DWORD *)core_cfg + 1),
"%s: %s%s(): could not intialize raw socket on startup, please restart as root or with CAP_NET_RAW\n",
*((const char **)&log_level_info + 8),
"<core> [cfg_core.c:146]: ",
"check_raw_sock_support");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0LL;
if ( (int)v4 < 0 )
*a4 = 0LL;
}
}
else
{
result = 0LL;
if ( (int)v4 < 0 )
*a4 = 1LL;
}
return result;
}

original_code:
static int check_raw_sock_support(void* cfg_h, str* gname, str* name,
         void** v)
{
 int val;
 val = (int)(long)(*v);
 if (raw_udp4_send_sock < 0) {
  if (val > 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(): " "could not intialize raw socket on startup, please " "restart as root or with CAP_NET_RAW\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "cfg_core.c" ":" "146" "]: ") , __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(): " "could not intialize raw socket on startup, please " "restart as root or with CAP_NET_RAW\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "cfg_core.c" ":" "146" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "could not intialize raw socket on startup, please " "restart as root or with CAP_NET_RAW\n", process_no, my_pid(), ("<core> [" "cfg_core.c" ":" "146" "]: ") , __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(): " "could not intialize raw socket on startup, please " "restart as root or with CAP_NET_RAW\n", ("<core> [" "cfg_core.c" ":" "146" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not intialize raw socket on startup, please " "restart as root or with CAP_NET_RAW\n", ("<core> [" "cfg_core.c" ":" "146" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   return -1;
  } else if (val < 0) {
   *v = (void*)(long)0;
  }
 } else if (val < 0) {
  *v = (void*)(long)1;
 }
 return 0;
}

canonical_original_code:
static int check_raw_sock_support(void *cfg_h, struct _str *gname, struct _str *name, void **v)
{
 int val;
 val = (int)(long)(*v);
 if (raw_udp4_send_sock < 0) {
  if (val > 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(): " "could not intialize raw socket on startup, please " "restart as root or with CAP_NET_RAW\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "cfg_core.c" ":" "146" "]: ") , __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(): " "could not intialize raw socket on startup, please " "restart as root or with CAP_NET_RAW\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "cfg_core.c" ":" "146" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "could not intialize raw socket on startup, please " "restart as root or with CAP_NET_RAW\n", process_no, my_pid(), ("<core> [" "cfg_core.c" ":" "146" "]: ") , __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(): " "could not intialize raw socket on startup, please " "restart as root or with CAP_NET_RAW\n", ("<core> [" "cfg_core.c" ":" "146" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not intialize raw socket on startup, please " "restart as root or with CAP_NET_RAW\n", ("<core> [" "cfg_core.c" ":" "146" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   return -1;
  } else if (val < 0) {
   *v = (void *)(long)0;
  }
 } else if (val < 0) {
  *v = (void *)(long)1;
 }
 return 0;
}

variable_types:
v
void **

variable_types: val int


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


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

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


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

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


decompiled_code:
__int64 __fastcall create_lpidf_document(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // er12
_BYTE v6[72]; // [rsp+0h] [rbp-48h] BYREF

if ( !a2 )
return (unsigned int)-1;
*(_DWORD *)(a2 + 8) = 0;
*(_QWORD *)a2 = 0LL;
if ( a3 )
{
*(_DWORD *)(a3 + 8) = 0;
*(_QWORD *)a3 = 0LL;
if ( !a1 )
return (unsigned int)-1;
if ( (int)str_dup_zt(a3, "text/lpidf") < 0 )
return (unsigned int)-1;
}
else if ( !a1 )
{
return (unsigned int)-1;
}
dstr_init(v6, 2048LL);
doc_add_presentity((__int64)v6, a1);
v4 = dstr_get_str(v6, a2);
dstr_destroy(v6);
if ( v4 )
{
if ( *(int *)(a2 + 8) > 0 && *(_QWORD *)a2 )
{
futex_get(mem_lock);
qm_free(shm_block, *(_QWORD *)a2);
futex_release(mem_lock);
}
*(_DWORD *)(a2 + 8) = 0;
*(_QWORD *)a2 = 0LL;
if ( a3 )
{
if ( *(int *)(a3 + 8) > 0 && *(_QWORD *)a3 )
{
futex_get(mem_lock);
qm_free(shm_block, *(_QWORD *)a3);
futex_release(mem_lock);
}
*(_DWORD *)(a3 + 8) = 0;
*(_QWORD *)a3 = 0LL;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // er12
_BYTE v6[72]; // [rsp+0h] [rbp-48h] BYREF

if ( !a2 )
return (unsigned int)-1;
*(_DWORD *)(a2 + 8) = 0;
*(_QWORD *)a2 = 0LL;
if ( a3 )
{
*(_DWORD *)(a3 + 8) = 0;
*(_QWORD *)a3 = 0LL;
if ( !a1 )
return (unsigned int)-1;
if ( (int)str_dup_zt(a3, "text/lpidf") < 0 )
return (unsigned int)-1;
}
else if ( !a1 )
{
return (unsigned int)-1;
}
dstr_init(v6, 2048LL);
func3((__int64)v6, a1);
v4 = dstr_get_str(v6, a2);
dstr_destroy(v6);
if ( v4 )
{
if ( *(int *)(a2 + 8) > 0 && *(_QWORD *)a2 )
{
func4(mem_lock);
qm_free(shm_block, *(_QWORD *)a2);
func5(mem_lock);
}
*(_DWORD *)(a2 + 8) = 0;
*(_QWORD *)a2 = 0LL;
if ( a3 )
{
if ( *(int *)(a3 + 8) > 0 && *(_QWORD *)a3 )
{
func4(mem_lock);
qm_free(shm_block, *(_QWORD *)a3);
func5(mem_lock);
}
*(_DWORD *)(a3 + 8) = 0;
*(_QWORD *)a3 = 0LL;
}
}
return v4;
}

original_code:
int create_lpidf_document(presentity_info_t *p, str_t *dst, str_t *dst_content_type)
{
 dstring_t buf;
 int err;
 if (!dst) return -1;
 do { if (dst != ((void *)0)) { (dst)->len = 0; (dst)->s = 0; } } while (0);
 if (dst_content_type) do { if (dst_content_type != ((void *)0)) { (dst_content_type)->len = 0; (dst_content_type)->s = 0; } } while (0);
 if (!p) return -1;
 if (dst_content_type) {
  if (str_dup_zt(dst_content_type, "text/lpidf") < 0) {
   return -1;
  }
 }
 dstr_init(&buf, 2048);
 doc_add_presentity(&buf, p);
 err = dstr_get_str(&buf, dst);
 dstr_destroy(&buf);
 if (err != 0) {
  do { if (dst != ((void *)0)) { if (((dst)->len > 0) && ((dst)->s)) do { futex_get(mem_lock); qm_free(shm_block, ((dst)->s)); futex_release(mem_lock); }while(0); (dst)->len = 0; (dst)->s = 0; } } while (0);
  if (dst_content_type) do { if (dst_content_type != ((void *)0)) { if (((dst_content_type)->len > 0) && ((dst_content_type)->s)) do { futex_get(mem_lock); qm_free(shm_block, ((dst_content_type)->s)); futex_release(mem_lock); }while(0); (dst_content_type)->len = 0; (dst_content_type)->s = 0; } } while (0);
 }
 return err;
}

canonical_original_code:
int create_lpidf_document(struct presentity_info_t *p, struct _str *dst, struct _str *dst_content_type)
{
 struct _dstring_t buf;
 int err;
 if (!dst) return -1;
 do { if (dst != ((void *)0)) { (dst)->len = 0; (dst)->s = 0; } } while (0);
 if (dst_content_type) do { if (dst_content_type != ((void *)0)) { (dst_content_type)->len = 0; (dst_content_type)->s = 0; } } while (0);
 if (!p) return -1;
 if (dst_content_type) {
  if (str_dup_zt(dst_content_type, "text/lpidf") < 0) {
   return -1;
  }
 }
 dstr_init(&buf, 2048);
 doc_add_presentity(&buf, p);
 err = dstr_get_str(&buf, dst);
 dstr_destroy(&buf);
 if (err != 0) {
  do { if (dst != ((void *)0)) { if (((dst)->len > 0) && ((dst)->s)) do { futex_get(mem_lock); qm_free(shm_block, ((dst)->s)); futex_release(mem_lock); }while(0); (dst)->len = 0; (dst)->s = 0; } } while (0);
  if (dst_content_type) do { if (dst_content_type != ((void *)0)) { if (((dst_content_type)->len > 0) && ((dst_content_type)->s)) do { futex_get(mem_lock); qm_free(shm_block, ((dst_content_type)->s)); futex_release(mem_lock); }while(0); (dst_content_type)->len = 0; (dst_content_type)->s = 0; } } while (0);
 }
 return err;
}

variable_types: struct presentity_info_t { struct _str { char *s; int len; } uri; struct _presence_tuple_info_t { struct _str contact; struct _str id; double priority; struct presence_tuple_status_t { enum basic_tuple_status_t { presence_tuple_open=0, presence_tuple_closed=1, presence_tuple_undefined_status=2 } basic; struct _extension_element_t { struct _str element; struct _extension_element_t *next; } *first_unknown_element; } status; struct _extension_element_t *first_unknown_element; struct _presence_tuple_info_t *next; struct _presence_note_t { struct _str value; struct _str lang; struct _presence_note_t *prev; } *first_note; } *first_tuple; struct _presence_note_t *first_note; struct _extension_element_t *first_unknown_element; char presentity_data[1]; } *

variable_types:
dst
struct _str *

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

variable_types: err int

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

user_defined_types: struct presentity_info_t { struct _str uri; struct _presence_tuple_info_t *first_tuple; struct _presence_note_t *first_note; struct _extension_element_t *first_unknown_element; char presentity_data[1]; }

user_defined_types: struct _presence_tuple_info_t { struct _str contact; struct _str id; double priority; struct presence_tuple_status_t status; struct _extension_element_t *first_unknown_element; struct _presence_tuple_info_t *next; struct _presence_note_t *first_note; }

user_defined_types: struct presence_tuple_status_t { enum basic_tuple_status_t basic; struct _extension_element_t *first_unknown_element; }


decompiled_code:
__int64 __fastcall stun_process_msg(const char *a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // ebx
const char *v6; // rbx
unsigned int v7; // eax
unsigned int v8; // er12
const char *v9; // rbp
unsigned int v10; // eax
const char *v11; // [rsp+0h] [rbp-48h] BYREF
unsigned int v12; // [rsp+8h] [rbp-40h]
int v13; // [rsp+Ch] [rbp-3Ch]
__int64 v14; // [rsp+10h] [rbp-38h]

if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v6 = (const char *)*((_QWORD *)&log_level_info + 16);
v7 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): STUN Message: [[>>>\n%.*s<<<]]\n",
process_no,
v7,
v6,
"<core> [stun.c:34]: ",
"stun_process_msg",
a2,
a1);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): STUN Message: [[>>>\n%.*s<<<]]\n",
*((_QWORD *)&log_level_info + 16),
"<core> [stun.c:34]: ",
"stun_process_msg",
a2,
a1);
}
--dprint_crit;
}
v4 = sr_event_enabled(12LL);
if ( v4 )
{
v13 = 0;
v11 = a1;
v12 = a2;
v14 = a3;
v4 = sr_event_exec(12LL, &v11);
}
else if ( (int)get_debug_level("core", 4LL) > 2 )
{
v8 = dprint_crit;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v9 = (const char *)*((_QWORD *)&log_level_info + 16);
v10 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): no callback registering for handling STUN - dropping!\n",
process_no,
v10,
v9,
"<core> [stun.c:42]: ",
"stun_process_msg");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): no callback registering for handling STUN - dropping!\n",
*((const char **)&log_level_info + 16),
"<core> [stun.c:42]: ",
"stun_process_msg");
}
--dprint_crit;
v4 = v8;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // ebx
const char *v6; // rbx
unsigned int v7; // eax
unsigned int v8; // er12
const char *v9; // rbp
unsigned int v10; // eax
const char *v11; // [rsp+0h] [rbp-48h] BYREF
unsigned int v12; // [rsp+8h] [rbp-40h]
int v13; // [rsp+Ch] [rbp-3Ch]
__int64 v14; // [rsp+10h] [rbp-38h]

if ( (int)get_debug_level("core", 4LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v6 = (const char *)*((_QWORD *)&log_level_info + 16);
v7 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): STUN Message: [[>>>\n%.*s<<<]]\n",
process_no,
v7,
v6,
"<core> [stun.c:34]: ",
"stun_process_msg",
a2,
a1);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): STUN Message: [[>>>\n%.*s<<<]]\n",
*((_QWORD *)&log_level_info + 16),
"<core> [stun.c:34]: ",
"stun_process_msg",
a2,
a1);
}
--dprint_crit;
}
v4 = sr_event_enabled(12LL);
if ( v4 )
{
v13 = 0;
v11 = a1;
v12 = a2;
v14 = a3;
v4 = sr_event_exec(12LL, &v11);
}
else if ( (int)get_debug_level("core", 4LL) > 2 )
{
v8 = dprint_crit;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v9 = (const char *)*((_QWORD *)&log_level_info + 16);
v10 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): no callback registering for handling STUN - dropping!\n",
process_no,
v10,
v9,
"<core> [stun.c:42]: ",
"stun_process_msg");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): no callback registering for handling STUN - dropping!\n",
*((const char **)&log_level_info + 16),
"<core> [stun.c:42]: ",
"stun_process_msg");
}
--dprint_crit;
v4 = v8;
}
}
return v4;
}

original_code:
int stun_process_msg(char* buf, unsigned int len, struct receive_info* ri)
{
        int ret;
 stun_event_info_t sev;
        ret = 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(): " "STUN Message: [[>>>\n%.*s<<<]]\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "stun.c" ":" "34" "]: ") , __func__, len, buf); 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(): " "STUN Message: [[>>>\n%.*s<<<]]\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "stun.c" ":" "34" "]: ") , __func__, len, buf); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "STUN Message: [[>>>\n%.*s<<<]]\n", process_no, my_pid(), ("<core> [" "stun.c" ":" "34" "]: ") , __func__, len, buf); 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(): " "STUN Message: [[>>>\n%.*s<<<]]\n", ("<core> [" "stun.c" ":" "34" "]: ") , __func__, len, buf); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "STUN Message: [[>>>\n%.*s<<<]]\n", ("<core> [" "stun.c" ":" "34" "]: ") , __func__, len, buf); } } (dprint_crit--); } } while(0);
        if(__builtin_expect(!!(sr_event_enabled(12)), 1)) {
  memset(&sev, 0, sizeof(stun_event_info_t));
  sev.buf = buf;
  sev.len = len;
  sev.rcv = ri;
                ret = sr_event_exec(12, (void *) &sev);
        } else {
                do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "no callback registering for handling STUN -" " dropping!\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "stun.c" ":" "42" "]: ") , __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(): " "no callback registering for handling STUN -" " dropping!\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "stun.c" ":" "42" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no callback registering for handling STUN -" " dropping!\n", process_no, my_pid(), ("<core> [" "stun.c" ":" "42" "]: ") , __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(): " "no callback registering for handling STUN -" " dropping!\n", ("<core> [" "stun.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 callback registering for handling STUN -" " dropping!\n", ("<core> [" "stun.c" ":" "42" "]: ") , __func__); } } (dprint_crit--); } } while(0);
        }
        return ret;
}

canonical_original_code:
int stun_process_msg(char *buf, unsigned int len, struct receive_info *ri)
{
        int ret;
 struct stun_event_info sev;
        ret = 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(): " "STUN Message: [[>>>\n%.*s<<<]]\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "stun.c" ":" "34" "]: ") , __func__, len, buf); 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(): " "STUN Message: [[>>>\n%.*s<<<]]\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "stun.c" ":" "34" "]: ") , __func__, len, buf); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "STUN Message: [[>>>\n%.*s<<<]]\n", process_no, my_pid(), ("<core> [" "stun.c" ":" "34" "]: ") , __func__, len, buf); 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(): " "STUN Message: [[>>>\n%.*s<<<]]\n", ("<core> [" "stun.c" ":" "34" "]: ") , __func__, len, buf); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "STUN Message: [[>>>\n%.*s<<<]]\n", ("<core> [" "stun.c" ":" "34" "]: ") , __func__, len, buf); } } (dprint_crit--); } } while(0);
        if(__builtin_expect(!!(sr_event_enabled(12)), 1)) {
  memset(&sev, 0, sizeof(stun_event_info_t));
  sev.buf = buf;
  sev.len = len;
  sev.rcv = ri;
                ret = sr_event_exec(12, (void *) &sev);
        } else {
                do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "no callback registering for handling STUN -" " dropping!\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "stun.c" ":" "42" "]: ") , __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(): " "no callback registering for handling STUN -" " dropping!\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "stun.c" ":" "42" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no callback registering for handling STUN -" " dropping!\n", process_no, my_pid(), ("<core> [" "stun.c" ":" "42" "]: ") , __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(): " "no callback registering for handling STUN -" " dropping!\n", ("<core> [" "stun.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 callback registering for handling STUN -" " dropping!\n", ("<core> [" "stun.c" ":" "42" "]: ") , __func__); } } (dprint_crit--); } } while(0);
        }
        return ret;
}

variable_types:
buf
char *

variable_types:
len
unsigned int

variable_types: ret int

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

user_defined_types: struct stun_event_info { char *buf; unsigned int len; struct receive_info *rcv; }

user_defined_types: struct receive_info { struct ip_addr src_ip; struct ip_addr dst_ip; unsigned short src_port; unsigned short dst_port; int proto_reserved1; int proto_reserved2; union sockaddr_union src_su; struct socket_info *bind_address; char proto; }

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

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

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

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

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


decompiled_code:
double __fastcall str2double(__int64 a1)
{
int v1; // edx
void *v2; // rsp
char vars0[8]; // [rsp+0h] [rbp+0h] BYREF

v1 = *(_DWORD *)(a1 + 8);
v2 = alloca(v1 + 1);
vars0[v1] = 0;
memcpy(vars0, *(const void **)a1, v1);
return atof(vars0);
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1)
{
int v1; // edx
void *v2; // rsp
char vars0[8]; // [rsp+0h] [rbp+0h] BYREF

v1 = *(_DWORD *)(a1 + 8);
v2 = alloca(v1 + 1);
vars0[v1] = 0;
memcpy(vars0, *(const void **)a1, v1);
return atof(vars0);
}

original_code:
double str2double(str *string)
{
 char buffer[string->len + 1];
 buffer[string->len] = '\0';
 memcpy(buffer, string->s, string->len);
 return atof(buffer);
}

canonical_original_code:
double str2double(struct _str *string)
{
 char buffer[-1];
 buffer[string->len] = '\0';
 memcpy(buffer, string->s, string->len);
 return atof(buffer);
}

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

variable_types:
buffer
char [-1]

return_type: double


decompiled_code:
__int64 __fastcall domain_reload(__int64 (__fastcall **a1)(__int64, __int64, const char *), __int64 a2)
{
__int64 result; // rax

if ( !db_mode )
return (*a1)(a2, 200LL, "Server Domain Cache Disabled");
result = reload_domain_list();
if ( (int)result < 0 )
result = (*a1)(a2, 400LL, "Domain Table Reload Failed");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 (__fastcall **a1)(__int64, __int64, const char *), __int64 a2)
{
__int64 result; // rax

if ( !db_mode )
return (*a1)(a2, 200LL, "Server Domain Cache Disabled");
result = reload_domain_list();
if ( (int)result < 0 )
result = (*a1)(a2, 400LL, "Domain Table Reload Failed");
return result;
}

original_code:
static void domain_reload(rpc_t* rpc, void* ctx)
{
 if (!db_mode) {
  rpc->fault(ctx, 200, "Server Domain Cache Disabled");
  return;
 }
 if (reload_domain_list() < 0) {
  rpc->fault(ctx, 400, "Domain Table Reload Failed");
 }
}

canonical_original_code:
static void domain_reload(struct rpc *rpc, void *ctx)
{
 if (!db_mode) {
  rpc->fault(ctx, 200, "Server Domain Cache Disabled");
  return;
 }
 if (reload_domain_list() < 0) {
  rpc->fault(ctx, 400, "Domain Table Reload Failed");
 }
}

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

variable_types:
ctx
void *


decompiled_code:
__int64 __fastcall dump_domain_list(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = a3; i; i = *(_QWORD *)(i + 48) )
result = dump_domain(a1, a2, i);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = a3; i; i = *(_QWORD *)(i + 48) )
result = func0(a1, a2, i);
return result;
}

original_code:
void dump_domain_list(rpc_t* rpc, void* ctx, domain_t* list)
{
 while(list) {
  dump_domain(rpc, ctx, list);
  list = list->next;
 }
}

canonical_original_code:
void dump_domain_list(struct rpc *rpc, void *ctx, struct domain *list)
{
 while(list) {
  dump_domain(rpc, ctx, list);
  list = list->next;
 }
}

variable_types: struct domain { struct _str { char *s; int len; } did; int n; struct _str *domain; unsigned int *flags; struct usr_avp { unsigned short id; unsigned int flags; struct usr_avp *next; union usr_avp_data { void *p; long l; char data[-1]; } d; } *attrs; struct domain *next; } *

user_defined_types: struct domain { struct _str did; int n; struct _str *domain; unsigned int *flags; struct usr_avp *attrs; struct domain *next; }

user_defined_types: struct usr_avp { unsigned short id; unsigned int flags; struct usr_avp *next; union usr_avp_data d; }

user_defined_types: enum rpc_capabilities { RPC_DELAYED_REPLY=expr }

user_defined_types: struct rpc_delayed_ctx { struct rpc rpc; void *reply_ctx; }


decompiled_code:
__int64 __fastcall domain_dump(__int64 (__fastcall **a1)(__int64, __int64, const char *), __int64 a2)
{
__int64 v2; // rdx

if ( !db_mode )
return (*a1)(a2, 400LL, "Server Domain Cache Disabled");
if ( *active_hash == hash_1 )
v2 = *domains_1;
else
v2 = *domains_2;
return dump_domain_list((__int64)a1, a2, v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 (__fastcall **a1)(__int64, __int64, const char *), __int64 a2)
{
__int64 v2; // rdx

if ( !db_mode )
return (*a1)(a2, 400LL, "Server Domain Cache Disabled");
if ( *active_hash == hash_1 )
v2 = *domains_1;
else
v2 = *domains_2;
return func2((__int64)a1, a2, v2);
}

original_code:
static void domain_dump(rpc_t* rpc, void* ctx)
{
 domain_t* list;
 if (!db_mode) {
  rpc->fault(ctx, 400, "Server Domain Cache Disabled");
  return;
 }
 if (*active_hash == hash_1) list = *domains_1;
 else list = *domains_2;
 dump_domain_list(rpc, ctx, list);
}

canonical_original_code:
static void domain_dump(struct rpc *rpc, void *ctx)
{
 struct domain *list;
 if (!db_mode) {
  rpc->fault(ctx, 400, "Server Domain Cache Disabled");
  return;
 }
 if (*active_hash == hash_1) list = *domains_1;
 else list = *domains_2;
 dump_domain_list(rpc, ctx, list);
}

user_defined_types: union usr_avp_data { void *p; long l; char data[-1]; }