decompiled_code:
char *__fastcall int2str_base_0pad(unsigned int a1, _DWORD *a2, unsigned int a3, int a4)
{
int v4; // er9
__int64 v5; // rcx
int v6; // ebx
int v7; // er11
int v8; // er12
int v9; // er9
char *result; // rax
const char *v11; // r13
unsigned int v12; // eax
int v13; // ebx
const char *v14; // rbp
unsigned int v15; // eax
const char *v16; // r13
unsigned int v17; // eax

if ( (int)a3 <= 1 )
{
v9 = get_debug_level("core", 4LL);
result = 0LL;
if ( v9 >= -4 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(4294967292LL);
v11 = (const char *)*((_QWORD *)&log_level_info + 2);
v12 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): base underflow\n",
process_no,
v12,
v11,
"<core> [ut.h:256]: ",
"int2str_base_0pad");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 6) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): base underflow\n",
*((const char **)&log_level_info + 2),
"<core> [ut.h:256]: ",
"int2str_base_0pad");
}
--dprint_crit;
result = 0LL;
}
}
else if ( (int)a3 > 36 )
{
v13 = get_debug_level("core", 4LL);
result = 0LL;
if ( v13 >= -4 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(4294967292LL);
v14 = (const char *)*((_QWORD *)&log_level_info + 2);
v15 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): base overflow\n",
process_no,
v15,
v14,
"<core> [ut.h:260]: ",
"int2str_base_0pad");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 6) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): base overflow\n",
*((const char **)&log_level_info + 2),
"<core> [ut.h:260]: ",
"int2str_base_0pad");
}
--dprint_crit;
result = 0LL;
}
}
else
{
v4 = 20 - a4;
byte_875 = 0;
v5 = 19LL;
while ( 1 )
{
v6 = v5 + 1;
v7 = a1 % a3 + 87;
if ( (char)(a1 % a3) <= 9 )
LOBYTE(v7) = a1 % a3 + 48;
byte_861[v5] = v7;
v8 = v5--;
if ( a3 > a1 && v8 <= v4 || v8 < 0 )
break;
a1 /= a3;
}
if ( v8 < 0 && a3 <= a1 && (int)get_debug_level("core", 4LL) >= -4 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(4294967292LL);
v16 = (const char *)*((_QWORD *)&log_level_info + 2);
v17 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): result buffer overflow\n",
process_no,
v17,
v16,
"<core> [ut.h:276]: ",
"int2str_base_0pad");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 6) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): result buffer overflow\n",
*((const char **)&log_level_info + 2),
"<core> [ut.h:276]: ",
"int2str_base_0pad");
}
--dprint_crit;
}
if ( a2 )
*a2 = 20 - v8;
result = (char *)&r_0 + v6;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(unsigned int a1, _DWORD *a2, unsigned int a3, int a4)
{
int v4; // er9
__int64 v5; // rcx
int v6; // ebx
int v7; // er11
int v8; // er12
int v9; // er9
char *result; // rax
const char *v11; // r13
unsigned int v12; // eax
int v13; // ebx
const char *v14; // rbp
unsigned int v15; // eax
const char *v16; // r13
unsigned int v17; // eax

if ( (int)a3 <= 1 )
{
v9 = get_debug_level("core", 4LL);
result = 0LL;
if ( v9 >= -4 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(4294967292LL);
v11 = (const char *)*((_QWORD *)&log_level_info + 2);
v12 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): base underflow\n",
process_no,
v12,
v11,
"<core> [ut.h:256]: ",
"int2str_base_0pad");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 6) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): base underflow\n",
*((const char **)&log_level_info + 2),
"<core> [ut.h:256]: ",
"int2str_base_0pad");
}
--dprint_crit;
result = 0LL;
}
}
else if ( (int)a3 > 36 )
{
v13 = get_debug_level("core", 4LL);
result = 0LL;
if ( v13 >= -4 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(4294967292LL);
v14 = (const char *)*((_QWORD *)&log_level_info + 2);
v15 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): base overflow\n",
process_no,
v15,
v14,
"<core> [ut.h:260]: ",
"int2str_base_0pad");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 6) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): base overflow\n",
*((const char **)&log_level_info + 2),
"<core> [ut.h:260]: ",
"int2str_base_0pad");
}
--dprint_crit;
result = 0LL;
}
}
else
{
v4 = 20 - a4;
byte_875 = 0;
v5 = 19LL;
while ( 1 )
{
v6 = v5 + 1;
v7 = a1 % a3 + 87;
if ( (char)(a1 % a3) <= 9 )
LOBYTE(v7) = a1 % a3 + 48;
byte_861[v5] = v7;
v8 = v5--;
if ( a3 > a1 && v8 <= v4 || v8 < 0 )
break;
a1 /= a3;
}
if ( v8 < 0 && a3 <= a1 && (int)get_debug_level("core", 4LL) >= -4 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(4294967292LL);
v16 = (const char *)*((_QWORD *)&log_level_info + 2);
v17 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): result buffer overflow\n",
process_no,
v17,
v16,
"<core> [ut.h:276]: ",
"int2str_base_0pad");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 6) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): result buffer overflow\n",
*((const char **)&log_level_info + 2),
"<core> [ut.h:276]: ",
"int2str_base_0pad");
}
--dprint_crit;
}
if ( a2 )
*a2 = 20 - v8;
result = (char *)&r_0 + v6;
}
return result;
}

original_code:
static inline char* int2str_base_0pad(unsigned int l, int* len, int base,
           int size)
{
 static char r[(19+1+1+1)];
 int i, j;
 if (base < 2) {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-4)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-4)) >= -5) && (((-4)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "base underflow\n", process_no, my_pid(), (log_level_info[((-4)) - (-5)].name), ("<core> [" "ut.h" ":" "256" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-4)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "base underflow\n", (log_level_info[((-4)) - (-5)].name), ("<core> [" "ut.h" ":" "256" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s" "%s(): " "base underflow\n", process_no, my_pid(), ("<core> [" "ut.h" ":" "256" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-4))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "base underflow\n", ("<core> [" "ut.h" ":" "256" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "base underflow\n", ("<core> [" "ut.h" ":" "256" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return ((void *)0);
 }
 if (base > 36) {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-4)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-4)) >= -5) && (((-4)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "base overflow\n", process_no, my_pid(), (log_level_info[((-4)) - (-5)].name), ("<core> [" "ut.h" ":" "260" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-4)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "base overflow\n", (log_level_info[((-4)) - (-5)].name), ("<core> [" "ut.h" ":" "260" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s" "%s(): " "base overflow\n", process_no, my_pid(), ("<core> [" "ut.h" ":" "260" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-4))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "base overflow\n", ("<core> [" "ut.h" ":" "260" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "base overflow\n", ("<core> [" "ut.h" ":" "260" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return ((void *)0);
 }
 i=(19+1+1+1)-2;
 j=i-size;
 r[(19+1+1+1)-1]=0;
 do{
  r[i]=l%base;
  if (r[i]<10)
          r[i]+='0';
  else
          r[i]+='a'-10;
  i--;
  l/=base;
 }while((l || i>j) && (i>=0));
 if (l && (i<0)){
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-4)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-4)) >= -5) && (((-4)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "result buffer overflow\n", process_no, my_pid(), (log_level_info[((-4)) - (-5)].name), ("<core> [" "ut.h" ":" "276" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-4)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "result buffer overflow\n", (log_level_info[((-4)) - (-5)].name), ("<core> [" "ut.h" ":" "276" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s" "%s(): " "result buffer overflow\n", process_no, my_pid(), ("<core> [" "ut.h" ":" "276" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-4))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "result buffer overflow\n", ("<core> [" "ut.h" ":" "276" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "result buffer overflow\n", ("<core> [" "ut.h" ":" "276" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 }
 if (len) *len=((19+1+1+1)-2)-i;
 return &r[i+1];
}

canonical_original_code:
static inline char *int2str_base_0pad(unsigned int l, int *len, int base, int size)
{
 static char r[-1];
 int i; int j;
 if (base < 2) {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-4)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-4)) >= -5) && (((-4)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "base underflow\n", process_no, my_pid(), (log_level_info[((-4)) - (-5)].name), ("<core> [" "ut.h" ":" "256" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-4)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "base underflow\n", (log_level_info[((-4)) - (-5)].name), ("<core> [" "ut.h" ":" "256" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s" "%s(): " "base underflow\n", process_no, my_pid(), ("<core> [" "ut.h" ":" "256" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-4))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "base underflow\n", ("<core> [" "ut.h" ":" "256" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "base underflow\n", ("<core> [" "ut.h" ":" "256" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return ((void *)0);
 }
 if (base > 36) {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-4)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-4)) >= -5) && (((-4)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "base overflow\n", process_no, my_pid(), (log_level_info[((-4)) - (-5)].name), ("<core> [" "ut.h" ":" "260" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-4)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "base overflow\n", (log_level_info[((-4)) - (-5)].name), ("<core> [" "ut.h" ":" "260" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s" "%s(): " "base overflow\n", process_no, my_pid(), ("<core> [" "ut.h" ":" "260" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-4))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "base overflow\n", ("<core> [" "ut.h" ":" "260" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "base overflow\n", ("<core> [" "ut.h" ":" "260" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return ((void *)0);
 }
 i=(19+1+1+1)-2;
 j=i-size;
 r[(19+1+1+1)-1]=0;
 do{
  r[i]=l%base;
  if (r[i]<10)
          r[i]+='0';
  else
          r[i]+='a'-10;
  i--;
  l/=base;
 }while((l || i>j) && (i>=0));
 if (l && (i<0)){
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-4)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-4)) >= -5) && (((-4)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "result buffer overflow\n", process_no, my_pid(), (log_level_info[((-4)) - (-5)].name), ("<core> [" "ut.h" ":" "276" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-4)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "result buffer overflow\n", (log_level_info[((-4)) - (-5)].name), ("<core> [" "ut.h" ":" "276" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-4)); fprintf(stderr, "%2d(%d) %s" "%s(): " "result buffer overflow\n", process_no, my_pid(), ("<core> [" "ut.h" ":" "276" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-4))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "result buffer overflow\n", ("<core> [" "ut.h" ":" "276" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "result buffer overflow\n", ("<core> [" "ut.h" ":" "276" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 }
 if (len) *len=((19+1+1+1)-2)-i;
 return &r[i+1];
}

variable_types:
l
unsigned int

variable_types:
len
int *

variable_types:
r
char [-1]

variable_types: j int


repo: virtualolson/who

decompiled_code:
void __fastcall sca_db_subscriptions_get_value_for_column(__int64 a1, __int64 a2, __int64 a3)
{
if ( !a3 )
_assert_fail("column_value != NULL", "sca_db.c", 0x31u, "sca_db_subscriptions_get_value_for_column");
if ( !a2 )
_assert_fail("row_values != NULL", "sca_db.c", 0x32u, "sca_db_subscriptions_get_value_for_column");
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
if ( !a3 )
_assert_fail("column_value != NULL", "sca_db.c", 0x31u, "sca_db_subscriptions_get_value_for_column");
if ( !a2 )
_assert_fail("row_values != NULL", "sca_db.c", 0x32u, "sca_db_subscriptions_get_value_for_column");
}

original_code:
void
sca_db_subscriptions_get_value_for_column( int column, db_val_t *row_values,
 void *column_value )
{
    ((void) sizeof ((column_value != ((void *)0)) ? 1 : 0), __extension__ ({ if (column_value != ((void *)0)) ; else __assert_fail ("column_value != NULL", "sca_db.c", 49, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_values != ((void *)0)) ? 1 : 0), __extension__ ({ if (row_values != ((void *)0)) ; else __assert_fail ("row_values != NULL", "sca_db.c", 50, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((column >= 0 && column < SCA_DB_SUBS_BOUNDARY) ? 1 : 0), __extension__ ({ if (column >= 0 && column < SCA_DB_SUBS_BOUNDARY) ; else __assert_fail ("column >= 0 && column < SCA_DB_SUBS_BOUNDARY", "sca_db.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    switch ( column ) {
    case SCA_DB_SUBS_SUBSCRIBER_COL:
    case SCA_DB_SUBS_AOR_COL:
    case SCA_DB_SUBS_CALL_ID_COL:
    case SCA_DB_SUBS_FROM_TAG_COL:
    case SCA_DB_SUBS_TO_TAG_COL:
    case SCA_DB_SUBS_RECORD_ROUTE_COL:
 ((str *)column_value)->s = (char *)row_values[ column ].val.string_val;
 ((str *)column_value)->len = strlen(((str *)column_value)->s );
 break;
    case SCA_DB_SUBS_EXPIRES_COL:
 *((time_t *)column_value) = row_values[ column ].val.time_val;
 break;
    case SCA_DB_SUBS_EVENT_COL:
    case SCA_DB_SUBS_STATE_COL:
    case SCA_DB_SUBS_NOTIFY_CSEQ_COL:
    case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL:
 *((int *)column_value) = row_values[ column ].val.int_val;
 break;
    default:
 column_value = ((void *)0);
    }
}

canonical_original_code:
void sca_db_subscriptions_get_value_for_column(int column, struct db_val_t *row_values, void *column_value)
{
    ((void) sizeof ((column_value != ((void *)0)) ? 1 : 0), __extension__ ({ if (column_value != ((void *)0)) ; else __assert_fail ("column_value != NULL", "sca_db.c", 49, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_values != ((void *)0)) ? 1 : 0), __extension__ ({ if (row_values != ((void *)0)) ; else __assert_fail ("row_values != NULL", "sca_db.c", 50, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((column >= 0 && column < SCA_DB_SUBS_BOUNDARY) ? 1 : 0), __extension__ ({ if (column >= 0 && column < SCA_DB_SUBS_BOUNDARY) ; else __assert_fail ("column >= 0 && column < SCA_DB_SUBS_BOUNDARY", "sca_db.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    switch ( column ) {
    case SCA_DB_SUBS_SUBSCRIBER_COL:
    case SCA_DB_SUBS_AOR_COL:
    case SCA_DB_SUBS_CALL_ID_COL:
    case SCA_DB_SUBS_FROM_TAG_COL:
    case SCA_DB_SUBS_TO_TAG_COL:
    case SCA_DB_SUBS_RECORD_ROUTE_COL:
 ((struct _str *)column_value)->s = (char *)row_values[ column ].val.string_val;
 ((struct _str *)column_value)->len = strlen(((struct _str *)column_value)->s );
 break;
    case SCA_DB_SUBS_EXPIRES_COL:
 *((long *)column_value) = row_values[ column ].val.time_val;
 break;
    case SCA_DB_SUBS_EVENT_COL:
    case SCA_DB_SUBS_STATE_COL:
    case SCA_DB_SUBS_NOTIFY_CSEQ_COL:
    case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL:
 *((int *)column_value) = row_values[ column ].val.int_val;
 break;
    default:
 column_value = ((void *)0);
    }
}

variable_types: column int

variable_types: 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; } *

return_type: void

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


decompiled_code:
void __fastcall sca_db_subscriptions_set_value_for_column(unsigned int a1, _DWORD *a2, const __m128i *a3)
{
__m128i *v4; // rbp
_DWORD *v5; // rbx
const char *v6; // r13
unsigned int v7; // eax

if ( a1 > 0xB )
_assert_fail(
"column >= 0 && column < SCA_DB_SUBS_BOUNDARY",
"sca_db.c",
0x54u,
"sca_db_subscriptions_set_value_for_column");
if ( !a3 )
_assert_fail("column_value != NULL", "sca_db.c", 0x55u, "sca_db_subscriptions_set_value_for_column");
if ( !a2 )
_assert_fail("row_values != NULL", "sca_db.c", 0x56u, "sca_db_subscriptions_set_value_for_column");
switch ( a1 )
{
case 0u:
case 1u:
case 6u:
case 7u:
case 8u:
case 9u:
v4 = (__m128i *)&a2[8 * a1];
v4[1] = _mm_loadu_si128(a3);
v4->m128i_i32[0] = 4;
v4->m128i_i32[1] = 0;
break;
case 2u:
case 4u:
case 0xAu:
case 0xBu:
goto LABEL_16;
case 3u:
a2[28] = a3->m128i_i64[0];
a2[24] = 0;
a2[25] = 0;
break;
case 5u:
a2[44] = 0;
a2[40] = 0;
a2[41] = 0;
break;
default:
if ( (int)get_debug_level("sca", 3LL) >= 0 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0LL);
v6 = (const char *)*((_QWORD *)&log_level_info + 10);
v7 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): sca_db_subscriptions_set_value_for_column: unrecognized column index %d, treating as INT",
process_no,
v7,
v6,
"sca [sca_db.c:114]: ",
"sca_db_subscriptions_set_value_for_column",
a1);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 22) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): sca_db_subscriptions_set_value_for_column: unrecognized column index %d, treating as INT",
*((const char **)&log_level_info + 10),
"sca [sca_db.c:114]: ",
"sca_db_subscriptions_set_value_for_column",
a1);
}
--dprint_crit;
}
LABEL_16:
v5 = &a2[8 * a1];
v5[4] = a3->m128i_i32[0];
*v5 = 0;
v5[1] = 0;
break;
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int a1, _DWORD *a2, const __m128i *a3)
{
__m128i *v4; // rbp
_DWORD *v5; // rbx
const char *v6; // r13
unsigned int v7; // eax

if ( a1 > 0xB )
_assert_fail(
"column >= 0 && column < SCA_DB_SUBS_BOUNDARY",
"sca_db.c",
0x54u,
"sca_db_subscriptions_set_value_for_column");
if ( !a3 )
_assert_fail("column_value != NULL", "sca_db.c", 0x55u, "sca_db_subscriptions_set_value_for_column");
if ( !a2 )
_assert_fail("row_values != NULL", "sca_db.c", 0x56u, "sca_db_subscriptions_set_value_for_column");
switch ( a1 )
{
case 0u:
case 1u:
case 6u:
case 7u:
case 8u:
case 9u:
v4 = (__m128i *)&a2[8 * a1];
v4[1] = _mm_loadu_si128(a3);
v4->m128i_i32[0] = 4;
v4->m128i_i32[1] = 0;
break;
case 2u:
case 4u:
case 0xAu:
case 0xBu:
goto LABEL_16;
case 3u:
a2[28] = a3->m128i_i64[0];
a2[24] = 0;
a2[25] = 0;
break;
case 5u:
a2[44] = 0;
a2[40] = 0;
a2[41] = 0;
break;
default:
if ( (int)get_debug_level("sca", 3LL) >= 0 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0LL);
v6 = (const char *)*((_QWORD *)&log_level_info + 10);
v7 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): sca_db_subscriptions_set_value_for_column: unrecognized column index %d, treating as INT",
process_no,
v7,
v6,
"sca [sca_db.c:114]: ",
"sca_db_subscriptions_set_value_for_column",
a1);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 22) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): sca_db_subscriptions_set_value_for_column: unrecognized column index %d, treating as INT",
*((const char **)&log_level_info + 10),
"sca [sca_db.c:114]: ",
"sca_db_subscriptions_set_value_for_column",
a1);
}
--dprint_crit;
}
LABEL_16:
v5 = &a2[8 * a1];
v5[4] = a3->m128i_i32[0];
*v5 = 0;
v5[1] = 0;
break;
}
}

original_code:
void
sca_db_subscriptions_set_value_for_column( int column, db_val_t *row_values,
 void *column_value )
{
    ((void) sizeof ((column >= 0 && column < SCA_DB_SUBS_BOUNDARY) ? 1 : 0), __extension__ ({ if (column >= 0 && column < SCA_DB_SUBS_BOUNDARY) ; else __assert_fail ("column >= 0 && column < SCA_DB_SUBS_BOUNDARY", "sca_db.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((column_value != ((void *)0)) ? 1 : 0), __extension__ ({ if (column_value != ((void *)0)) ; else __assert_fail ("column_value != NULL", "sca_db.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_values != ((void *)0)) ? 1 : 0), __extension__ ({ if (row_values != ((void *)0)) ; else __assert_fail ("row_values != NULL", "sca_db.c", 86, __extension__ __PRETTY_FUNCTION__); }));
    switch ( column ) {
    case SCA_DB_SUBS_SUBSCRIBER_COL:
    case SCA_DB_SUBS_AOR_COL:
    case SCA_DB_SUBS_CALL_ID_COL:
    case SCA_DB_SUBS_FROM_TAG_COL:
    case SCA_DB_SUBS_TO_TAG_COL:
    case SCA_DB_SUBS_RECORD_ROUTE_COL:
 row_values[ column ].val.str_val = *((str *)column_value);
 row_values[ column ].type = DB1_STR;
 row_values[ column ].nul = 0;
 break;
    case SCA_DB_SUBS_EXPIRES_COL:
 row_values[ column ].val.int_val = (int)(*((time_t *)column_value));
 row_values[ column ].type = DB1_INT;
 row_values[ column ].nul = 0;
 break;
    case SCA_DB_SUBS_APP_IDX_COL:
 row_values[ column ].val.int_val = 0;
 row_values[ column ].type = DB1_INT;
 row_values[ column ].nul = 0;
 break;
    default:
 do { if (get_debug_level("sca", (sizeof("sca")-1)) >= ((0)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((0)) >= -5) && (((0)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "sca_db_subscriptions_set_value_for_column: unrecognized " "column index %d, treating as INT", process_no, my_pid(), (log_level_info[((0)) - (-5)].name), ("sca" " [" "sca_db.c" ":" "114" "]: ") , __func__, column); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((0)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "sca_db_subscriptions_set_value_for_column: unrecognized " "column index %d, treating as INT", (log_level_info[((0)) - (-5)].name), ("sca" " [" "sca_db.c" ":" "114" "]: ") , __func__, column); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s" "%s(): " "sca_db_subscriptions_set_value_for_column: unrecognized " "column index %d, treating as INT", process_no, my_pid(), ("sca" " [" "sca_db.c" ":" "114" "]: ") , __func__, column); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((0))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "sca_db_subscriptions_set_value_for_column: unrecognized " "column index %d, treating as INT", ("sca" " [" "sca_db.c" ":" "114" "]: ") , __func__, column); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "sca_db_subscriptions_set_value_for_column: unrecognized " "column index %d, treating as INT", ("sca" " [" "sca_db.c" ":" "114" "]: ") , __func__, column); } } (dprint_crit--); } } while(0);
    case SCA_DB_SUBS_EVENT_COL:
    case SCA_DB_SUBS_STATE_COL:
    case SCA_DB_SUBS_NOTIFY_CSEQ_COL:
    case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL:
 row_values[ column ].val.int_val = *((int *)column_value);
 row_values[ column ].type = DB1_INT;
 row_values[ column ].nul = 0;
 break;
    }
}

canonical_original_code:
void sca_db_subscriptions_set_value_for_column(int column, struct db_val_t *row_values, void *column_value)
{
    ((void) sizeof ((column >= 0 && column < SCA_DB_SUBS_BOUNDARY) ? 1 : 0), __extension__ ({ if (column >= 0 && column < SCA_DB_SUBS_BOUNDARY) ; else __assert_fail ("column >= 0 && column < SCA_DB_SUBS_BOUNDARY", "sca_db.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((column_value != ((void *)0)) ? 1 : 0), __extension__ ({ if (column_value != ((void *)0)) ; else __assert_fail ("column_value != NULL", "sca_db.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((row_values != ((void *)0)) ? 1 : 0), __extension__ ({ if (row_values != ((void *)0)) ; else __assert_fail ("row_values != NULL", "sca_db.c", 86, __extension__ __PRETTY_FUNCTION__); }));
    switch ( column ) {
    case SCA_DB_SUBS_SUBSCRIBER_COL:
    case SCA_DB_SUBS_AOR_COL:
    case SCA_DB_SUBS_CALL_ID_COL:
    case SCA_DB_SUBS_FROM_TAG_COL:
    case SCA_DB_SUBS_TO_TAG_COL:
    case SCA_DB_SUBS_RECORD_ROUTE_COL:
 row_values[ column ].val.str_val = *((struct _str *)column_value);
 row_values[ column ].type = DB1_STR;
 row_values[ column ].nul = 0;
 break;
    case SCA_DB_SUBS_EXPIRES_COL:
 row_values[ column ].val.int_val = (int)(*((long *)column_value));
 row_values[ column ].type = DB1_INT;
 row_values[ column ].nul = 0;
 break;
    case SCA_DB_SUBS_APP_IDX_COL:
 row_values[ column ].val.int_val = 0;
 row_values[ column ].type = DB1_INT;
 row_values[ column ].nul = 0;
 break;
    default:
 do { if (get_debug_level("sca", (sizeof("sca")-1)) >= ((0)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((0)) >= -5) && (((0)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "sca_db_subscriptions_set_value_for_column: unrecognized " "column index %d, treating as INT", process_no, my_pid(), (log_level_info[((0)) - (-5)].name), ("sca" " [" "sca_db.c" ":" "114" "]: ") , __func__, column); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((0)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "sca_db_subscriptions_set_value_for_column: unrecognized " "column index %d, treating as INT", (log_level_info[((0)) - (-5)].name), ("sca" " [" "sca_db.c" ":" "114" "]: ") , __func__, column); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s" "%s(): " "sca_db_subscriptions_set_value_for_column: unrecognized " "column index %d, treating as INT", process_no, my_pid(), ("sca" " [" "sca_db.c" ":" "114" "]: ") , __func__, column); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((0))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "sca_db_subscriptions_set_value_for_column: unrecognized " "column index %d, treating as INT", ("sca" " [" "sca_db.c" ":" "114" "]: ") , __func__, column); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "sca_db_subscriptions_set_value_for_column: unrecognized " "column index %d, treating as INT", ("sca" " [" "sca_db.c" ":" "114" "]: ") , __func__, column); } } (dprint_crit--); } } while(0);
    case SCA_DB_SUBS_EVENT_COL:
    case SCA_DB_SUBS_STATE_COL:
    case SCA_DB_SUBS_NOTIFY_CSEQ_COL:
    case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL:
 row_values[ column ].val.int_val = *((int *)column_value);
 row_values[ column ].type = DB1_INT;
 row_values[ column ].nul = 0;
 break;
    }
}

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

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


decompiled_code:
char **sca_db_subscriptions_columns()
{
return subs_columns_1;
}

canonical_decompiled_code:
char **func2()
{
return subs_columns_1;
}

original_code:
str **
sca_db_subscriptions_columns( void )
{
    static str *subs_columns[] = {
       (str *)&SCA_DB_SUBSCRIBER_COL_NAME,
       (str *)&SCA_DB_AOR_COL_NAME,
       (str *)&SCA_DB_EVENT_COL_NAME,
       (str *)&SCA_DB_EXPIRES_COL_NAME,
       (str *)&SCA_DB_STATE_COL_NAME,
       (str *)&SCA_DB_APP_IDX_COL_NAME,
       (str *)&SCA_DB_CALL_ID_COL_NAME,
       (str *)&SCA_DB_FROM_TAG_COL_NAME,
       (str *)&SCA_DB_TO_TAG_COL_NAME,
       (str *)&SCA_DB_RECORD_ROUTE_COL_NAME,
       (str *)&SCA_DB_NOTIFY_CSEQ_COL_NAME,
       (str *)&SCA_DB_SUBSCRIBE_CSEQ_COL_NAME,
       ((void *)0)
   };
    return( subs_columns );
}

canonical_original_code:
struct _str **sca_db_subscriptions_columns()
{
    static struct _str *subs_columns[] = {
       (str *)&SCA_DB_SUBSCRIBER_COL_NAME,
       (str *)&SCA_DB_AOR_COL_NAME,
       (str *)&SCA_DB_EVENT_COL_NAME,
       (str *)&SCA_DB_EXPIRES_COL_NAME,
       (str *)&SCA_DB_STATE_COL_NAME,
       (str *)&SCA_DB_APP_IDX_COL_NAME,
       (str *)&SCA_DB_CALL_ID_COL_NAME,
       (str *)&SCA_DB_FROM_TAG_COL_NAME,
       (str *)&SCA_DB_TO_TAG_COL_NAME,
       (str *)&SCA_DB_RECORD_ROUTE_COL_NAME,
       (str *)&SCA_DB_NOTIFY_CSEQ_COL_NAME,
       (str *)&SCA_DB_SUBSCRIBE_CSEQ_COL_NAME,
       ((void *)0)
   };
    return( subs_columns );
}

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


decompiled_code:
__int64 sca_db_get_connection()
{
__int64 v0; // rsi
__int64 (*v1)(void); // rax

if ( !sca || !*(_QWORD *)(*sca + 8LL) )
_assert_fail("sca && sca->cfg->db_url", "sca_db.c", 0x9Au, "sca_db_get_connection");
v0 = sca[3];
if ( !v0 || (v1 = *(__int64 (**)(void))(v0 + 16)) == 0LL )
_assert_fail("sca->db_api && sca->db_api->init", "sca_db.c", 0x9Bu, "sca_db_get_connection");
if ( !sca_db_con )
sca_db_con = v1();
return sca_db_con;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rsi
__int64 (*v1)(void); // rax

if ( !sca || !*(_QWORD *)(*sca + 8LL) )
_assert_fail("sca && sca->cfg->db_url", "sca_db.c", 0x9Au, "sca_db_get_connection");
v0 = sca[3];
if ( !v0 || (v1 = *(__int64 (**)(void))(v0 + 16)) == 0LL )
_assert_fail("sca->db_api && sca->db_api->init", "sca_db.c", 0x9Bu, "sca_db_get_connection");
if ( !sca_db_con )
sca_db_con = v1();
return sca_db_con;
}

original_code:
db1_con_t *
sca_db_get_connection( void )
{
    ((void) sizeof ((sca && sca->cfg->db_url) ? 1 : 0), __extension__ ({ if (sca && sca->cfg->db_url) ; else __assert_fail ("sca && sca->cfg->db_url", "sca_db.c", 154, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((sca->db_api && sca->db_api->init) ? 1 : 0), __extension__ ({ if (sca->db_api && sca->db_api->init) ; else __assert_fail ("sca->db_api && sca->db_api->init", "sca_db.c", 155, __extension__ __PRETTY_FUNCTION__); }));
    if ( sca_db_con == ((void *)0) ) {
 sca_db_con = sca->db_api->init( sca->cfg->db_url );
    }
    return( sca_db_con );
}

canonical_original_code:
struct db1_con_t *sca_db_get_connection()
{
    ((void) sizeof ((sca && sca->cfg->db_url) ? 1 : 0), __extension__ ({ if (sca && sca->cfg->db_url) ; else __assert_fail ("sca && sca->cfg->db_url", "sca_db.c", 154, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((sca->db_api && sca->db_api->init) ? 1 : 0), __extension__ ({ if (sca->db_api && sca->db_api->init) ; else __assert_fail ("sca->db_api && sca->db_api->init", "sca_db.c", 155, __extension__ __PRETTY_FUNCTION__); }));
    if ( sca_db_con == ((void *)0) ) {
 sca_db_con = sca->db_api->init( sca->cfg->db_url );
    }
    return( sca_db_con );
}

return_type: struct db1_con_t { struct _str { char *s; int len; } *table; unsigned long tail; } *

user_defined_types: struct db1_con_t { struct _str *table; unsigned long tail; }


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

result = &sca_db_con;
if ( sca_db_con )
{
result = (_QWORD *)(*(__int64 (**)(void))(sca[3] + 32LL))();
sca_db_con = 0LL;
}
return result;
}

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

result = &sca_db_con;
if ( sca_db_con )
{
result = (_QWORD *)(*(__int64 (**)(void))(sca[3] + 32LL))();
sca_db_con = 0LL;
}
return result;
}

original_code:
void
sca_db_disconnect( void )
{
    if ( sca_db_con != ((void *)0) ) {
 sca->db_api->close( sca_db_con );
 sca_db_con = ((void *)0);
    }
}

canonical_original_code:
void sca_db_disconnect()
{
    if ( sca_db_con != ((void *)0) ) {
 sca->db_api->close( sca_db_con );
 sca_db_con = ((void *)0);
    }
}


decompiled_code:
__int64 __fastcall corex_rpc_list_sockets(__int64 a1, __int64 a2)
{
unsigned __int16 v2; // r11
unsigned int v3; // er14
__int64 *v4; // rax
__int64 v5; // r12
__int64 result; // rax
const char *v7; // r8
int v8; // ecx
const char *v9; // rsi
const char *v10; // r9
int (__fastcall *v11)(__int64, const char *, const char *, __int64, const char *, __int64, const char *, __int64 *); // rbx
__int64 v12; // r13
__int64 v13; // rax
__int64 v14; // rbx
__int64 v16; // [rsp+10h] [rbp-48h] BYREF
__int64 v17[8]; // [rsp+18h] [rbp-40h] BYREF

v2 = 1;
while ( 1 )
{
v3 = v2;
v4 = (__int64 *)get_sock_info_list(v2);
if ( v4 )
{
v5 = *v4;
if ( *v4 )
break;
}
LABEL_25:
result = next_proto(v3);
v2 = result;
if ( !(_WORD)result )
return result;
}
while ( 1 )
{
if ( (*(int (__fastcall **)(__int64, void *, __int64 *))(a1 + 16))(a2, &LC0, v17) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(
a2,
500LL,
"Internal error socket structure");
v11 = *(int (__fastcall **)(__int64, const char *, const char *, __int64, const char *, __int64, const char *, __int64 *))(a1 + 40);
v12 = *(_QWORD *)(v5 + 8);
v13 = get_valid_proto_name(v3);
if ( v11(v17[0], "ss{", "PROTO", v13, "NAME", v12, "ADDRLIST", &v16) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(
a2,
500LL,
"Internal error address list structure");
if ( (*(int (__fastcall **)(__int64, const char *, const char *, _QWORD))(a1 + 40))(
v16,
"s",
"ADDR",
*(_QWORD *)(v5 + 48)) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(
a2,
500LL,
"Internal error address structure");
v14 = *(_QWORD *)(v5 + 152);
if ( v14 )
break;
LABEL_9:
v7 = *(const char **)(v5 + 168);
if ( !v7 )
v7 = "-";
v8 = *(_DWORD *)(v5 + 80);
v9 = "yes";
if ( (v8 & 0x10) == 0 )
v9 = "no";
v10 = "yes";
if ( (v8 & 4) == 0 )
v10 = "no";
if ( (*(int (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, const char *, const char *, const char *, const char *, const char *))(a1 + 40))(
v17[0],
"ssss",
"PORT",
*(_QWORD *)(v5 + 64),
"MCAST",
v10,
"MHOMED",
v9,
"ADVERTISE",
v7) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error attrs structure");
v5 = *(_QWORD *)(v5 + 112);
if ( !v5 )
goto LABEL_25;
}
while ( (*(int (__fastcall **)(__int64, const char *, const char *, _QWORD))(a1 + 40))(
v16,
"s",
"ADDR",
*(_QWORD *)(v14 + 40)) >= 0 )
{
v14 = *(_QWORD *)(v14 + 88);
if ( !v14 )
goto LABEL_9;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(
a2,
500LL,
"Internal error extra address structure");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
unsigned __int16 v2; // r11
unsigned int v3; // er14
__int64 *v4; // rax
__int64 v5; // r12
__int64 result; // rax
const char *v7; // r8
int v8; // ecx
const char *v9; // rsi
const char *v10; // r9
int (__fastcall *v11)(__int64, const char *, const char *, __int64, const char *, __int64, const char *, __int64 *); // rbx
__int64 v12; // r13
__int64 v13; // rax
__int64 v14; // rbx
__int64 v16; // [rsp+10h] [rbp-48h] BYREF
__int64 v17[8]; // [rsp+18h] [rbp-40h] BYREF

v2 = 1;
while ( 1 )
{
v3 = v2;
v4 = (__int64 *)get_sock_info_list(v2);
if ( v4 )
{
v5 = *v4;
if ( *v4 )
break;
}
LABEL_25:
result = func0(v3);
v2 = result;
if ( !(_WORD)result )
return result;
}
while ( 1 )
{
if ( (*(int (__fastcall **)(__int64, void *, __int64 *))(a1 + 16))(a2, &LC0, v17) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(
a2,
500LL,
"Internal error socket structure");
v11 = *(int (__fastcall **)(__int64, const char *, const char *, __int64, const char *, __int64, const char *, __int64 *))(a1 + 40);
v12 = *(_QWORD *)(v5 + 8);
v13 = get_valid_proto_name(v3);
if ( v11(v17[0], "ss{", "PROTO", v13, "NAME", v12, "ADDRLIST", &v16) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(
a2,
500LL,
"Internal error address list structure");
if ( (*(int (__fastcall **)(__int64, const char *, const char *, _QWORD))(a1 + 40))(
v16,
"s",
"ADDR",
*(_QWORD *)(v5 + 48)) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(
a2,
500LL,
"Internal error address structure");
v14 = *(_QWORD *)(v5 + 152);
if ( v14 )
break;
LABEL_9:
v7 = *(const char **)(v5 + 168);
if ( !v7 )
v7 = "-";
v8 = *(_DWORD *)(v5 + 80);
v9 = "yes";
if ( (v8 & 0x10) == 0 )
v9 = "no";
v10 = "yes";
if ( (v8 & 4) == 0 )
v10 = "no";
if ( (*(int (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, const char *, const char *, const char *, const char *, const char *))(a1 + 40))(
v17[0],
"ssss",
"PORT",
*(_QWORD *)(v5 + 64),
"MCAST",
v10,
"MHOMED",
v9,
"ADVERTISE",
v7) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error attrs structure");
v5 = *(_QWORD *)(v5 + 112);
if ( !v5 )
goto LABEL_25;
}
while ( (*(int (__fastcall **)(__int64, const char *, const char *, _QWORD))(a1 + 40))(
v16,
"s",
"ADDR",
*(_QWORD *)(v14 + 40)) >= 0 )
{
v14 = *(_QWORD *)(v14 + 88);
if ( !v14 )
goto LABEL_9;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(
a2,
500LL,
"Internal error extra address structure");
}

original_code:
static void corex_rpc_list_sockets(rpc_t* rpc, void* ctx)
{
 void* th;
 void* ih;
 struct socket_info *si;
 struct socket_info** list;
 struct addr_info* ai;
 unsigned short proto;
 proto=PROTO_UDP;
 do {
  list=get_sock_info_list(proto);
  for(si=list?*list:0; si; si=si->next)
  {
   if (rpc->add(ctx, "{", &th) < 0)
   {
    rpc->fault(ctx, 500, "Internal error socket structure");
    return;
   }
   if(rpc->struct_add(th, "ss{",
    "PROTO", get_valid_proto_name(proto),
    "NAME", si->name.s,
    "ADDRLIST", &ih)<0)
   {
    rpc->fault(ctx, 500, "Internal error address list structure");
    return;
   }
   if(rpc->struct_add(ih, "s", "ADDR", si->address_str.s)<0)
   {
    rpc->fault(ctx, 500, "Internal error address structure");
    return;
   }
   if (si->addr_info_lst)
   {
    for (ai=si->addr_info_lst; ai; ai=ai->next)
    {
     if(rpc->struct_add(ih, "s", "ADDR", ai->address_str.s)<0)
     {
      rpc->fault(ctx, 500,
        "Internal error extra address structure");
      return;
     }
    }
   }
   if(rpc->struct_add(th, "ssss",
     "PORT", si->port_no_str.s,
     "MCAST", si->flags & SI_IS_MCAST ? "yes" : "no",
     "MHOMED", si->flags & SI_IS_MHOMED? "yes" : "no",
     "ADVERTISE", si->useinfo.name.s?si->useinfo.name.s:"-")<0)
   {
    rpc->fault(ctx, 500, "Internal error attrs structure");
    return;
   }
  }
 } while((proto=next_proto(proto)));
 return;
}

canonical_original_code:
static void corex_rpc_list_sockets(struct rpc *rpc, void *ctx)
{
 void *th;
 void *ih;
 struct socket_info *si;
 struct socket_info **list;
 struct addr_info *ai;
 unsigned short proto;
 proto=PROTO_UDP;
 do {
  list=get_sock_info_list(proto);
  for(si=list?*list:0; si; si=si->next)
  {
   if (rpc->add(ctx, "{", &th) < 0)
   {
    rpc->fault(ctx, 500, "Internal error socket structure");
    return;
   }
   if(rpc->struct_add(th, "ss{",
    "PROTO", get_valid_proto_name(proto),
    "NAME", si->name.s,
    "ADDRLIST", &ih)<0)
   {
    rpc->fault(ctx, 500, "Internal error address list structure");
    return;
   }
   if(rpc->struct_add(ih, "s", "ADDR", si->address_str.s)<0)
   {
    rpc->fault(ctx, 500, "Internal error address structure");
    return;
   }
   if (si->addr_info_lst)
   {
    for (ai=si->addr_info_lst; ai; ai=ai->next)
    {
     if(rpc->struct_add(ih, "s", "ADDR", ai->address_str.s)<0)
     {
      rpc->fault(ctx, 500,
        "Internal error extra address structure");
      return;
     }
    }
   }
   if(rpc->struct_add(th, "ssss",
     "PORT", si->port_no_str.s,
     "MCAST", si->flags & SI_IS_MCAST ? "yes" : "no",
     "MHOMED", si->flags & SI_IS_MHOMED? "yes" : "no",
     "ADVERTISE", si->useinfo.name.s?si->useinfo.name.s:"-")<0)
   {
    rpc->fault(ctx, 500, "Internal error attrs structure");
    return;
   }
  }
 } while((proto=next_proto(proto)));
 return;
}

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 *

variable_types:
th
void *

variable_types:
ih
void *

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

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

variable_types:
proto
unsigned short

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

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

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


decompiled_code:
__int64 corex_init_rpc()
{
__int64 result; // rax
int v1; // edx
const char *v2; // rbx
unsigned int v3; // eax

result = rpc_register_array(&corex_rpc_cmds);
if ( (_DWORD)result )
{
v1 = get_debug_level("corex", 5LL);
result = 0xFFFFFFFFLL;
if ( v1 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !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(): failed to register RPC commands\n",
process_no,
v3,
v2,
"corex [corex_rpc.c:164]: ",
"corex_init_rpc");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): failed to register RPC commands\n",
*((const char **)&log_level_info + 8),
"corex [corex_rpc.c:164]: ",
"corex_init_rpc");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
int v1; // edx
const char *v2; // rbx
unsigned int v3; // eax

result = rpc_register_array(&corex_rpc_cmds);
if ( (_DWORD)result )
{
v1 = get_debug_level("corex", 5LL);
result = 0xFFFFFFFFLL;
if ( v1 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !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(): failed to register RPC commands\n",
process_no,
v3,
v2,
"corex [corex_rpc.c:164]: ",
"corex_init_rpc");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): failed to register RPC commands\n",
*((const char **)&log_level_info + 8),
"corex [corex_rpc.c:164]: ",
"corex_init_rpc");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int corex_init_rpc(void)
{
 if (rpc_register_array(corex_rpc_cmds)!=0)
 {
  do { if (get_debug_level("corex", (sizeof("corex")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "failed to register RPC commands\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("corex" " [" "corex_rpc.c" ":" "164" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "failed to register RPC commands\n", (log_level_info[((-1)) - (-5)].name), ("corex" " [" "corex_rpc.c" ":" "164" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "failed to register RPC commands\n", process_no, my_pid(), ("corex" " [" "corex_rpc.c" ":" "164" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "failed to register RPC commands\n", ("corex" " [" "corex_rpc.c" ":" "164" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "failed to register RPC commands\n", ("corex" " [" "corex_rpc.c" ":" "164" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 return 0;
}

canonical_original_code:
int corex_init_rpc()
{
 if (rpc_register_array(corex_rpc_cmds)!=0)
 {
  do { if (get_debug_level("corex", (sizeof("corex")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "failed to register RPC commands\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("corex" " [" "corex_rpc.c" ":" "164" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "failed to register RPC commands\n", (log_level_info[((-1)) - (-5)].name), ("corex" " [" "corex_rpc.c" ":" "164" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "failed to register RPC commands\n", process_no, my_pid(), ("corex" " [" "corex_rpc.c" ":" "164" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "failed to register RPC commands\n", ("corex" " [" "corex_rpc.c" ":" "164" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "failed to register RPC commands\n", ("corex" " [" "corex_rpc.c" ":" "164" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall next_proto(unsigned __int16 a1)
{
unsigned int v1; // ebp
const char *v3; // r12
unsigned int v4; // eax

if ( a1 <= 7u )
return (unsigned int)nxt_proto[a1];
v1 = 0;
if ( (int)get_debug_level("corex", 5LL) >= -1 )
{
v1 = dprint_crit;
if ( dprint_crit )
{
v1 = 0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v3 = (const char *)*((_QWORD *)&log_level_info + 8);
v4 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): ERROR: next_proto: unknown proto %d\n",
process_no,
v4,
v3,
"corex [../../socket_info.h:119]: ",
"next_proto",
a1);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR: next_proto: unknown proto %d\n",
*((const char **)&log_level_info + 8),
"corex [../../socket_info.h:119]: ",
"next_proto",
a1);
}
--dprint_crit;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1)
{
unsigned int v1; // ebp
const char *v3; // r12
unsigned int v4; // eax

if ( a1 <= 7u )
return (unsigned int)nxt_proto[a1];
v1 = 0;
if ( (int)get_debug_level("corex", 5LL) >= -1 )
{
v1 = dprint_crit;
if ( dprint_crit )
{
v1 = 0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v3 = (const char *)*((_QWORD *)&log_level_info + 8);
v4 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): ERROR: next_proto: unknown proto %d\n",
process_no,
v4,
v3,
"corex [../../socket_info.h:119]: ",
"next_proto",
a1);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR: next_proto: unknown proto %d\n",
*((const char **)&log_level_info + 8),
"corex [../../socket_info.h:119]: ",
"next_proto",
a1);
}
--dprint_crit;
}
}
return v1;
}

original_code:
static inline int next_proto(unsigned short proto)
{
 if (proto>PROTO_OTHER)
   do { if (get_debug_level("corex", (sizeof("corex")-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: next_proto: unknown proto %d\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("corex" " [" "../../socket_info.h" ":" "119" "]: ") , __func__, proto); 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: next_proto: unknown proto %d\n", (log_level_info[((-1)) - (-5)].name), ("corex" " [" "../../socket_info.h" ":" "119" "]: ") , __func__, proto); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR: next_proto: unknown proto %d\n", process_no, my_pid(), ("corex" " [" "../../socket_info.h" ":" "119" "]: ") , __func__, proto); 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: next_proto: unknown proto %d\n", ("corex" " [" "../../socket_info.h" ":" "119" "]: ") , __func__, proto); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR: next_proto: unknown proto %d\n", ("corex" " [" "../../socket_info.h" ":" "119" "]: ") , __func__, proto); } } (dprint_crit--); } } while(0);
 else
  return nxt_proto[proto];
 return 0;
}


decompiled_code:
int __fastcall generate_dbid_ptr(char *s, const void *a2)
{
unsigned int v2; // er12
unsigned int v3; // eax

v2 = rand();
v3 = time(0LL);
return snprintf(s, 0x30uLL, "%px%xx%x", a2, v3, v2);
}

canonical_decompiled_code:
int __fastcall func0(char *s, const void *a2)
{
unsigned int v2; // er12
unsigned int v3; // eax

v2 = rand();
v3 = time(0LL);
return snprintf(s, 0x30uLL, "%px%xx%x", a2, v3, v2);
}

original_code:
void generate_dbid_ptr(dbid_t dst, void *data_ptr)
{
 snprintf(dst, 48, "%px%xx%x",
   data_ptr, (int)time(((void *)0)), rand());
}

canonical_original_code:
void generate_dbid_ptr(char dst[48], void *data_ptr)
{
 snprintf(dst, 48, "%px%xx%x",
   data_ptr, (int)time(((void *)0)), rand());
}

variable_types:
dst
char [48]


decompiled_code:
int __fastcall generate_dbid(char *s)
{
__int64 v1; // rbp
unsigned int v2; // eax
__int64 v3; // r8

if ( my_pid_1 < 0 )
my_pid_1 = getpid();
v1 = (unsigned int)rand();
v2 = time(0LL);
v3 = (unsigned int)cntr_0++;
return snprintf(s, 0x30uLL, "%xy%xy%xy%x", (unsigned int)my_pid_1, v3, v2, v1);
}

canonical_decompiled_code:
int __fastcall func1(char *s)
{
__int64 v1; // rbp
unsigned int v2; // eax
__int64 v3; // r8

if ( my_pid_1 < 0 )
my_pid_1 = getpid();
v1 = (unsigned int)rand();
v2 = time(0LL);
v3 = (unsigned int)cntr_0++;
return snprintf(s, 0x30uLL, "%xy%xy%xy%x", (unsigned int)my_pid_1, v3, v2, v1);
}

original_code:
void generate_dbid(dbid_t dst)
{
 static int cntr = 0;
 static pid_t my_pid = -1;
 if (my_pid < 0) {
  my_pid = getpid();
 }
 snprintf(dst, 48, "%xy%xy%xy%x",
   my_pid, cntr++, (int)time(((void *)0)), rand());
}

canonical_original_code:
void generate_dbid(char dst[48])
{
 static int cntr = 0;
 static int my_pid = -1;
 if (my_pid < 0) {
  my_pid = getpid();
 }
 snprintf(dst, 48, "%xy%xy%xy%x",
   my_pid, cntr++, (int)time(((void *)0)), rand());
}

variable_types: cntr int


decompiled_code:
__int64 __fastcall dbt_bind_api(_QWORD *a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*a1 = 0LL;
a1[20] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 168) >> 3));
a1[1] = &dbt_use_table;
a1[2] = &dbt_init;
a1[4] = &dbt_close;
a1[5] = &dbt_query;
a1[8] = &dbt_free_result;
a1[9] = &dbt_insert;
a1[10] = &dbt_delete;
a1[11] = &dbt_update;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*a1 = 0LL;
a1[20] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 168) >> 3));
a1[1] = &dbt_use_table;
a1[2] = &dbt_init;
a1[4] = &dbt_close;
a1[5] = &dbt_query;
a1[8] = &dbt_free_result;
a1[9] = &dbt_insert;
a1[10] = &dbt_delete;
a1[11] = &dbt_update;
return 0LL;
}

original_code:
int dbt_bind_api(db_func_t *dbb)
{
 if(dbb==((void *)0))
  return -1;
 memset(dbb, 0, sizeof(db_func_t));
 dbb->use_table = dbt_use_table;
 dbb->init = dbt_init;
 dbb->close = dbt_close;
 dbb->query = (db_query_f)dbt_query;
 dbb->free_result = dbt_free_result;
 dbb->insert = (db_insert_f)dbt_insert;
 dbb->delete = (db_delete_f)dbt_delete;
 dbb->update = (db_update_f)dbt_update;
 return 0;
}

canonical_original_code:
int dbt_bind_api(struct db_func *dbb)
{
 if(dbb==((void *)0))
  return -1;
 memset(dbb, 0, sizeof(db_func_t));
 dbb->use_table = dbt_use_table;
 dbb->init = dbt_init;
 dbb->close = dbt_close;
 dbb->query = (int (*)(struct db1_con_t *_h, struct _str **_k, char **_op, struct db_val_t *_v, struct _str **_c, int _n, int _nc, struct _str *_o, struct db1_res **_r))dbt_query;
 dbb->free_result = dbt_free_result;
 dbb->insert = (int (*)(struct db1_con_t *_h, struct _str **_k, struct db_val_t *_v, int _n))dbt_insert;
 dbb->delete = (int (*)(struct db1_con_t *_h, struct _str **_k, char **_o, struct db_val_t *_v, int _n))dbt_delete;
 dbb->update = (int (*)(struct db1_con_t *_h, struct _str **_k, char **_o, struct db_val_t *_v, struct _str **_uk, struct db_val_t *_uv, int _n, int _un))dbt_update;
 return 0;
}

variable_types: struct db_func { unsigned int cap; int (*use_table)(struct db1_con_t { struct _str { char *s; int len; } *table; unsigned long tail; } *_h, struct _str *_t); struct db1_con_t *(*init)(struct _str *_sqlurl); struct db1_con_t *(*init2)(struct _str *_sqlurl, enum db_pooling_t { DB_POOLING_PERMITTED=0, DB_POOLING_NONE=1 } _pooling); void (*close)(struct db1_con_t *_h); int (*query)(struct db1_con_t *_h, struct _str **_k, char **_op, 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; } *_v, struct _str **_c, int _n, int _nc, struct _str *_o, struct db1_res { struct { struct _str **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 *values; int n; } *rows; int n; int res_rows; int last_row; void *ptr; } **_r); int (*fetch_result)(struct db1_con_t *_h, struct db1_res **_r, int _n); int (*raw_query)(struct db1_con_t *_h, struct _str *_s, struct db1_res **_r); int (*free_result)(struct db1_con_t *_h, struct db1_res *_r); int (*insert)(struct db1_con_t *_h, struct _str **_k, struct db_val_t *_v, int _n); int (*delete)(struct db1_con_t *_h, struct _str **_k, char **_o, struct db_val_t *_v, int _n); int (*update)(struct db1_con_t *_h, struct _str **_k, char **_o, struct db_val_t *_v, struct _str **_uk, struct db_val_t *_uv, int _n, int _un); int (*replace)(struct db1_con_t *handle, struct _str **keys, struct db_val_t *vals, int n, int _un, int _m); int (*last_inserted_id)(struct db1_con_t *_h); int (*insert_update)(struct db1_con_t *_h, struct _str **_k, struct db_val_t *_v, int _n); int (*insert_delayed)(struct db1_con_t *_h, struct _str **_k, struct db_val_t *_v, int _n); int (*affected_rows)(struct db1_con_t *_h); int (*start_transaction)(struct db1_con_t *_h, enum db_locking_t { DB_LOCKING_NONE=0, DB_LOCKING_WRITE=1, DB_LOCKING_FULL=2 } _l); int (*end_transaction)(struct db1_con_t *_h); int (*abort_transaction)(struct db1_con_t *_h); int (*query_lock)(struct db1_con_t *_h, struct _str **_k, char **_op, struct db_val_t *_v, struct _str **_c, int _n, int _nc, struct _str *_o, struct db1_res **_r); } *

user_defined_types: struct db_func { unsigned int cap; int (*use_table)(struct db1_con_t *_h, struct _str *_t); struct db1_con_t *(*init)(struct _str *_sqlurl); struct db1_con_t *(*init2)(struct _str *_sqlurl, enum db_pooling_t _pooling); void (*close)(struct db1_con_t *_h); int (*query)(struct db1_con_t *_h, struct _str **_k, char **_op, struct db_val_t *_v, struct _str **_c, int _n, int _nc, struct _str *_o, struct db1_res **_r); int (*fetch_result)(struct db1_con_t *_h, struct db1_res **_r, int _n); int (*raw_query)(struct db1_con_t *_h, struct _str *_s, struct db1_res **_r); int (*free_result)(struct db1_con_t *_h, struct db1_res *_r); int (*insert)(struct db1_con_t *_h, struct _str **_k, struct db_val_t *_v, int _n); int (*delete)(struct db1_con_t *_h, struct _str **_k, char **_o, struct db_val_t *_v, int _n); int (*update)(struct db1_con_t *_h, struct _str **_k, char **_o, struct db_val_t *_v, struct _str **_uk, struct db_val_t *_uv, int _n, int _un); int (*replace)(struct db1_con_t *handle, struct _str **keys, struct db_val_t *vals, int n, int _un, int _m); int (*last_inserted_id)(struct db1_con_t *_h); int (*insert_update)(struct db1_con_t *_h, struct _str **_k, struct db_val_t *_v, int _n); int (*insert_delayed)(struct db1_con_t *_h, struct _str **_k, struct db_val_t *_v, int _n); int (*affected_rows)(struct db1_con_t *_h); int (*start_transaction)(struct db1_con_t *_h, enum db_locking_t _l); int (*end_transaction)(struct db1_con_t *_h); int (*abort_transaction)(struct db1_con_t *_h); int (*query_lock)(struct db1_con_t *_h, struct _str **_k, char **_op, struct db_val_t *_v, struct _str **_c, int _n, int _nc, struct _str *_o, struct db1_res **_r); }

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


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

if ( (unsigned int)dbt_cache_print(0LL) )
result = (*(__int64 (__fastcall **)(__int64, const char *))(a1 + 32))(a2, "Dump failed");
else
result = (*(__int64 (__fastcall **)(__int64, const char *))(a1 + 32))(a2, "Dump OK");
return result;
}

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

if ( (unsigned int)dbt_cache_print(0LL) )
result = (*(__int64 (__fastcall **)(__int64, const char *))(a1 + 32))(a2, "Dump failed");
else
result = (*(__int64 (__fastcall **)(__int64, const char *))(a1 + 32))(a2, "Dump OK");
return result;
}

original_code:
static void rpc_dump(rpc_t *rpc, void *c) {
 if (0!=dbt_cache_print(0))
  rpc->printf(c, "Dump failed");
 else
  rpc->printf(c, "Dump OK");
 return;
}

canonical_original_code:
static void rpc_dump(struct rpc *rpc, void *c) {
 if (0!=dbt_cache_print(0))
  rpc->printf(c, "Dump failed");
 else
  rpc->printf(c, "Dump OK");
 return;
}

variable_types:
c
void *

user_defined_types: enum rpc_capabilities { RPC_DELAYED_REPLY=expr }

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


destroy

decompiled_code:
__int64 destroy()
{
const char *v1; // rbx
unsigned int v2; // eax

if ( (int)get_debug_level("db_text", 7LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v1 = (const char *)*((_QWORD *)&log_level_info + 16);
v2 = my_pid();
fprintf(stderr, "%2d(%d) %s: %s%s(): destroy ...\n", process_no, v2, v1, "db_text [dbtext.c:111]: ", "destroy");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): destroy ...\n",
*((const char **)&log_level_info + 16),
"db_text [dbtext.c:111]: ",
"destroy");
}
--dprint_crit;
}
dbt_cache_print(0LL);
return dbt_cache_destroy();
}

canonical_decompiled_code:
__int64 func1()
{
const char *v1; // rbx
unsigned int v2; // eax

if ( (int)get_debug_level("db_text", 7LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v1 = (const char *)*((_QWORD *)&log_level_info + 16);
v2 = my_pid();
fprintf(stderr, "%2d(%d) %s: %s%s(): destroy ...\n", process_no, v2, v1, "db_text [dbtext.c:111]: ", "destroy");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): destroy ...\n",
*((const char **)&log_level_info + 16),
"db_text [dbtext.c:111]: ",
"destroy");
}
--dprint_crit;
}
dbt_cache_print(0LL);
return dbt_cache_destroy();
}

original_code:
static void destroy(void)
{
 do { if (get_debug_level("db_text", (sizeof("db_text")-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(): " "destroy ...\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("db_text" " [" "dbtext.c" ":" "111" "]: ") , __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(): " "destroy ...\n", (log_level_info[((3)) - (-5)].name), ("db_text" " [" "dbtext.c" ":" "111" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "destroy ...\n", process_no, my_pid(), ("db_text" " [" "dbtext.c" ":" "111" "]: ") , __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(): " "destroy ...\n", ("db_text" " [" "dbtext.c" ":" "111" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "destroy ...\n", ("db_text" " [" "dbtext.c" ":" "111" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 dbt_cache_print(0);
 dbt_cache_destroy();
}

canonical_original_code:
static void destroy()
{
 do { if (get_debug_level("db_text", (sizeof("db_text")-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(): " "destroy ...\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("db_text" " [" "dbtext.c" ":" "111" "]: ") , __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(): " "destroy ...\n", (log_level_info[((3)) - (-5)].name), ("db_text" " [" "dbtext.c" ":" "111" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "destroy ...\n", process_no, my_pid(), ("db_text" " [" "dbtext.c" ":" "111" "]: ") , __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(): " "destroy ...\n", ("db_text" " [" "dbtext.c" ":" "111" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "destroy ...\n", ("db_text" " [" "dbtext.c" ":" "111" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 dbt_cache_print(0);
 dbt_cache_destroy();
}


decompiled_code:
__int64 mod_init()
{
return (unsigned int)-((unsigned int)dbt_init_cache() != 0);
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)-((unsigned int)dbt_init_cache() != 0);
}

original_code:
static int mod_init(void)
{
 if(dbt_init_cache())
  return -1;
 return 0;
}

canonical_original_code:
static int mod_init()
{
 if(dbt_init_cache())
  return -1;
 return 0;
}


decompiled_code:
__int64 mod_register()
{
__int64 result; // rax
int v1; // edx
const char *v2; // rbx
unsigned int v3; // eax

if ( !(unsigned int)rpc_register_array(&rpc_methods) )
return (unsigned int)((int)db_api_init() >> 31);
v1 = get_debug_level("db_text", 7LL);
result = 0xFFFFFFFFLL;
if ( v1 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !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(): failed to register RPC commands\n",
process_no,
v3,
v2,
"db_text [dbtext.c:91]: ",
"mod_register");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): failed to register RPC commands\n",
*((const char **)&log_level_info + 8),
"db_text [dbtext.c:91]: ",
"mod_register");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
int v1; // edx
const char *v2; // rbx
unsigned int v3; // eax

if ( !(unsigned int)rpc_register_array(&rpc_methods) )
return (unsigned int)((int)db_api_init() >> 31);
v1 = get_debug_level("db_text", 7LL);
result = 0xFFFFFFFFLL;
if ( v1 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !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(): failed to register RPC commands\n",
process_no,
v3,
v2,
"db_text [dbtext.c:91]: ",
"mod_register");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): failed to register RPC commands\n",
*((const char **)&log_level_info + 8),
"db_text [dbtext.c:91]: ",
"mod_register");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int mod_register(char *path, int *dlflags, void *p1, void *p2)
{
 if (rpc_register_array(rpc_methods)!=0) {
  do { if (get_debug_level("db_text", (sizeof("db_text")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "failed to register RPC commands\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("db_text" " [" "dbtext.c" ":" "91" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "failed to register RPC commands\n", (log_level_info[((-1)) - (-5)].name), ("db_text" " [" "dbtext.c" ":" "91" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "failed to register RPC commands\n", process_no, my_pid(), ("db_text" " [" "dbtext.c" ":" "91" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "failed to register RPC commands\n", ("db_text" " [" "dbtext.c" ":" "91" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "failed to register RPC commands\n", ("db_text" " [" "dbtext.c" ":" "91" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if(db_api_init()<0)
  return -1;
 return 0;
}

variable_types:
path
char *

variable_types:
dlflags
int *


decompiled_code:
__int64 __fastcall num_digits(int a1)
{
unsigned int v1; // edx
int v2; // ecx

if ( a1 <= 9 )
return 1;
v1 = 1;
do
{
v2 = a1;
a1 /= 10;
++v1;
}
while ( v2 > 99 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned int v1; // edx
int v2; // ecx

if ( a1 <= 9 )
return 1;
v1 = 1;
do
{
v2 = a1;
a1 /= 10;
++v1;
}
while ( v2 > 99 );
return v1;
}

original_code:
static inline int num_digits(int i)
{
 int digits = 1;
 while (i > 9) {
  i = i / 10;
  digits++;
 }
 return digits;
}

variable_types: i int

variable_types: digits int


decompiled_code:
__int64 __fastcall serialize_avp(__int64 a1, char *a2)
{
__int64 v2; // rax
const char *v3; // r14
unsigned int v4; // er13
unsigned int v5; // er15
int v6; // ebx
int v7; // ebx
unsigned int v8; // ebp
unsigned int v9; // ebx
const char *v10; // rax
int v12; // [rsp+Ch] [rbp-4Ch] BYREF
__m128i v13; // [rsp+10h] [rbp-48h] BYREF

get_avp_value_ex(a1, &v13, &v12);
v2 = get_avp_name(a1);
if ( v2 )
{
v3 = *(const char **)v2;
v4 = *(_DWORD *)(v2 + 8);
}
else
{
v3 = 0LL;
v4 = 0;
}
v5 = v13.m128i_u32[2];
v6 = num_digits(v4) + v5 + v4 + 4;
v7 = num_digits(v5) + v6;
v8 = *(_DWORD *)(a1 + 4);
v9 = num_digits(v8) + v7;
if ( a2 )
{
v10 = (const char *)v13.m128i_i64[0];
if ( !v13.m128i_i64[0] )
v10 = (const char *)&LC4;
if ( !v3 )
v3 = (const char *)&LC4;
sprintf(a2, "%c%d:%d:%d:%.*s%.*s", (unsigned int)(char)(5 * (v12 == 2) + 110), v4, v5, v8, v4, v3, v5, v10);
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2)
{
__int64 v2; // rax
const char *v3; // r14
unsigned int v4; // er13
unsigned int v5; // er15
int v6; // ebx
int v7; // ebx
unsigned int v8; // ebp
unsigned int v9; // ebx
const char *v10; // rax
int v12; // [rsp+Ch] [rbp-4Ch] BYREF
__m128i v13; // [rsp+10h] [rbp-48h] BYREF

get_avp_value_ex(a1, &v13, &v12);
v2 = get_avp_name(a1);
if ( v2 )
{
v3 = *(const char **)v2;
v4 = *(_DWORD *)(v2 + 8);
}
else
{
v3 = 0LL;
v4 = 0;
}
v5 = v13.m128i_u32[2];
v6 = func1(v4) + v5 + v4 + 4;
v7 = func1(v5) + v6;
v8 = *(_DWORD *)(a1 + 4);
v9 = func1(v8) + v7;
if ( a2 )
{
v10 = (const char *)v13.m128i_i64[0];
if ( !v13.m128i_i64[0] )
v10 = (const char *)&LC4;
if ( !v3 )
v3 = (const char *)&LC4;
sprintf(a2, "%c%d:%d:%d:%.*s%.*s", (unsigned int)(char)(5 * (v12 == 2) + 110), v4, v5, v8, v4, v3, v5, v10);
}
return v9;
}

original_code:
int serialize_avp(avp_t *avp, char *buf)
{
 int len = 0;
 str name = {0, 0};
 str val;
 str *s;
 int type;
 char c;
 get_avp_value_ex(avp, &val, &type);
 s = get_avp_name(avp);
 if (s) name = *s;
 len = name.len + val.len + 3 + 1 +
  num_digits(name.len) + num_digits(val.len) +
  num_digits(avp->flags);
 if (buf) {
  if (type == (1<<1)) c = 's';
  else c = 'n';
  sprintf(buf, "%c%d:%d:%d:%.*s%.*s", c, name.len, val.len, avp->flags,
    name.len, ((name.s)?(name.s):""),
    val.len, ((val.s)?(val.s):""));
 }
 return len;
}

canonical_original_code:
int serialize_avp(struct usr_avp *avp, char *buf)
{
 int len = 0;
 struct _str name = {0, 0};
 struct _str val;
 struct _str *s;
 int type;
 char c;
 get_avp_value_ex(avp, &val, &type);
 s = get_avp_name(avp);
 if (s) name = *s;
 len = name.len + val.len + 3 + 1 +
  num_digits(name.len) + num_digits(val.len) +
  num_digits(avp->flags);
 if (buf) {
  if (type == (1<<1)) c = 's';
  else c = 'n';
  sprintf(buf, "%c%d:%d:%d:%.*s%.*s", c, name.len, val.len, avp->flags,
    name.len, ((name.s)?(name.s):""),
    val.len, ((val.s)?(val.s):""));
 }
 return len;
}

variable_types: 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; } *

variable_types:
buf
char *

variable_types: len int

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

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

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

variable_types: type int

variable_types: c char

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


decompiled_code:
__int64 __fastcall serialize_avps(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // rax
int v6; // er12
__int64 result; // rax
int v8; // edx
const char *v9; // rbp
unsigned int v10; // eax

if ( !a1 )
{
*(_DWORD *)(a2 + 8) = 0;
LABEL_20:
*(_QWORD *)a2 = 0LL;
return 0LL;
}
v2 = a1;
v3 = a1;
LODWORD(v4) = 0;
do
{
v4 = (unsigned int)serialize_avp(v3, 0LL) + (unsigned int)v4;
v3 = *(_QWORD *)(v3 + 8);
}
while ( v3 );
*(_DWORD *)(a2 + 8) = v4;
if ( (int)v4 <= 0 )
goto LABEL_20;
v5 = qm_malloc(mem_block, (int)v4 + 1);
*(_QWORD *)a2 = v5;
if ( v5 )
{
v6 = 0;
do
{
v6 += serialize_avp(v2, (char *)(*(_QWORD *)a2 + v6));
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
result = 0LL;
}
else
{
*(_DWORD *)(a2 + 8) = 0;
v8 = get_debug_level("usrloc", 6LL);
result = 0xFFFFFFFFLL;
if ( v8 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v9 = (const char *)*((_QWORD *)&log_level_info + 8);
v10 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): no pkg mem (%d)\n",
process_no,
v10,
v9,
"usrloc [reg_avps_db.c:165]: ",
"serialize_avps",
v4);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): no pkg mem (%d)\n",
*((const char **)&log_level_info + 8),
"usrloc [reg_avps_db.c:165]: ",
"serialize_avps",
(unsigned int)v4);
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // rax
int v6; // er12
__int64 result; // rax
int v8; // edx
const char *v9; // rbp
unsigned int v10; // eax

if ( !a1 )
{
*(_DWORD *)(a2 + 8) = 0;
LABEL_20:
*(_QWORD *)a2 = 0LL;
return 0LL;
}
v2 = a1;
v3 = a1;
LODWORD(v4) = 0;
do
{
v4 = (unsigned int)func2(v3, 0LL) + (unsigned int)v4;
v3 = *(_QWORD *)(v3 + 8);
}
while ( v3 );
*(_DWORD *)(a2 + 8) = v4;
if ( (int)v4 <= 0 )
goto LABEL_20;
v5 = qm_malloc(mem_block, (int)v4 + 1);
*(_QWORD *)a2 = v5;
if ( v5 )
{
v6 = 0;
do
{
v6 += func2(v2, (char *)(*(_QWORD *)a2 + v6));
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
result = 0LL;
}
else
{
*(_DWORD *)(a2 + 8) = 0;
v8 = get_debug_level("usrloc", 6LL);
result = 0xFFFFFFFFLL;
if ( v8 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v9 = (const char *)*((_QWORD *)&log_level_info + 8);
v10 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): no pkg mem (%d)\n",
process_no,
v10,
v9,
"usrloc [reg_avps_db.c:165]: ",
"serialize_avps",
v4);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): no pkg mem (%d)\n",
*((const char **)&log_level_info + 8),
"usrloc [reg_avps_db.c:165]: ",
"serialize_avps",
(unsigned int)v4);
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int serialize_avps(avp_t *first, str *dst)
{
 avp_t *avp;
 int len = 0;
 avp = first;
 while (avp) {
  len += serialize_avp(avp, ((void *)0));
  avp = avp->next;
 }
 dst->len = len;
 if (len < 1) {
  dst->s = ((void *)0);
  return 0;
 }
 dst->s = (char*)qm_malloc(mem_block, (len + 1));
 if (!dst->s) {
  dst->len = 0;
  do { if (get_debug_level("usrloc", (sizeof("usrloc")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "no pkg mem (%d)\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("usrloc" " [" "reg_avps_db.c" ":" "165" "]: ") , __func__, len); 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 pkg mem (%d)\n", (log_level_info[((-1)) - (-5)].name), ("usrloc" " [" "reg_avps_db.c" ":" "165" "]: ") , __func__, len); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no pkg mem (%d)\n", process_no, my_pid(), ("usrloc" " [" "reg_avps_db.c" ":" "165" "]: ") , __func__, len); 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 pkg mem (%d)\n", ("usrloc" " [" "reg_avps_db.c" ":" "165" "]: ") , __func__, len); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no pkg mem (%d)\n", ("usrloc" " [" "reg_avps_db.c" ":" "165" "]: ") , __func__, len); } } (dprint_crit--); } } while(0);
  return -1;
 }
 avp = first;
 len = 0;
 while (avp) {
  len += serialize_avp(avp, dst->s + len);
  avp = avp->next;
 }
 return 0;
}

canonical_original_code:
int serialize_avps(struct usr_avp *first, struct _str *dst)
{
 struct usr_avp *avp;
 int len = 0;
 avp = first;
 while (avp) {
  len += serialize_avp(avp, ((void *)0));
  avp = avp->next;
 }
 dst->len = len;
 if (len < 1) {
  dst->s = ((void *)0);
  return 0;
 }
 dst->s = (char *)qm_malloc(mem_block, (len + 1));
 if (!dst->s) {
  dst->len = 0;
  do { if (get_debug_level("usrloc", (sizeof("usrloc")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "no pkg mem (%d)\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("usrloc" " [" "reg_avps_db.c" ":" "165" "]: ") , __func__, len); 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 pkg mem (%d)\n", (log_level_info[((-1)) - (-5)].name), ("usrloc" " [" "reg_avps_db.c" ":" "165" "]: ") , __func__, len); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no pkg mem (%d)\n", process_no, my_pid(), ("usrloc" " [" "reg_avps_db.c" ":" "165" "]: ") , __func__, len); 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 pkg mem (%d)\n", ("usrloc" " [" "reg_avps_db.c" ":" "165" "]: ") , __func__, len); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no pkg mem (%d)\n", ("usrloc" " [" "reg_avps_db.c" ":" "165" "]: ") , __func__, len); } } (dprint_crit--); } } while(0);
  return -1;
 }
 avp = first;
 len = 0;
 while (avp) {
  len += serialize_avp(avp, dst->s + len);
  avp = avp->next;
 }
 return 0;
}

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

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


decompiled_code:
__int64 dnssec_exit()
{
dnssec_res_destroy();
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
dnssec_res_destroy();
return 0LL;
}

original_code:
static int dnssec_exit(void)
{
 (void)dnssec_res_destroy();
 return 0;
}

canonical_original_code:
static int dnssec_exit()
{
 (void)dnssec_res_destroy();
 return 0;
}


decompiled_code:
__int64 load_dns()
{
_QWORD *v0; // rax

v0 = (_QWORD *)qm_malloc(mem_block, 32LL);
if ( !v0 )
return 0xFFFFFFFFLL;
*v0 = &dnssec_res_init;
v0[2] = &dnssec_gethostbyname;
v0[3] = &dnssec_gethostbyname2;
v0[1] = &dnssec_res_search;
load_dnsfunc(v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
_QWORD *v0; // rax

v0 = (_QWORD *)qm_malloc(mem_block, 32LL);
if ( !v0 )
return 0xFFFFFFFFLL;
*v0 = &dnssec_res_init;
v0[2] = &dnssec_gethostbyname;
v0[3] = &dnssec_gethostbyname2;
v0[1] = &dnssec_res_search;
load_dnsfunc(v0);
return 0LL;
}

original_code:
static int load_dns(void)
{
 struct dns_func_t *f = qm_malloc(mem_block, (sizeof(struct dns_func_t)));
 if( ((void *)0) == f ) {
  return -1;
 }
 memset(f, 0, sizeof(struct dns_func_t));
 f->sr_res_init = dnssec_res_init;
 f->sr_gethostbyname = dnssec_gethostbyname;
 f->sr_gethostbyname2 = dnssec_gethostbyname2;
 f->sr_res_search = dnssec_res_search;
 load_dnsfunc(f);
 return 0;
}

canonical_original_code:
static int load_dns()
{
 struct dns_func_t *f = qm_malloc(mem_block, (sizeof(struct dns_func_t)));
 if( ((void *)0) == f ) {
  return -1;
 }
 memset(f, 0, sizeof(struct dns_func_t));
 f->sr_res_init = dnssec_res_init;
 f->sr_gethostbyname = dnssec_gethostbyname;
 f->sr_gethostbyname2 = dnssec_gethostbyname2;
 f->sr_res_search = dnssec_res_search;
 load_dnsfunc(f);
 return 0;
}

variable_types: struct dns_func_t { int (*sr_res_init)(); int (*sr_res_search)(char *, int, int, unsigned char *, int); struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *(*sr_gethostbyname)(char *); struct hostent *(*sr_gethostbyname2)(char *, int); } *

user_defined_types: struct dns_func_t { int (*sr_res_init)(); int (*sr_res_search)(char *, int, int, unsigned char *, int); struct hostent *(*sr_gethostbyname)(char *); struct hostent *(*sr_gethostbyname2)(char *, int); }