decompiled_code:
__int64 __fastcall init_http_db(_QWORD *a1, int a2)
{
__int64 v2; // rbx
unsigned int v3; // ebp
__int64 v5; // rsi
__int64 v6; // r12
unsigned int v7; // eax
const char *v8; // r9
__int64 v9; // r8
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // rdx
const char *v13; // rsi
struct _IO_FILE *v14; // rdi
__int64 v15; // r12
unsigned int v16; // eax
__int64 v17; // [rsp-8h] [rbp-20h]
__int64 v18; // [rsp-8h] [rbp-20h]

v2 = *a1 + 208LL * a2;
if ( (int)db_bind_mod(v2 + 16, v2 + 40) < 0 )
{
if ( (int)get_debug_level("xhttp_pi", 8LL) < -1 || dprint_crit )
return (unsigned int)-1;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): Unable to bind to a database driver\n",
*((const char **)&log_level_info + 8),
"xhttp_pi [http_db_handler.c:75]: ",
"init_http_db");
LABEL_9:
--dprint_crit;
return (unsigned int)-1;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v6 = *((_QWORD *)&log_level_info + 8);
v7 = my_pid();
v8 = "xhttp_pi [http_db_handler.c:75]: ";
v17 = v9;
v10 = v7;
v11 = v6;
v12 = process_no;
v13 = "%2d(%d) %s: %s%s(): Unable to bind to a database driver\n";
LABEL_18:
v14 = stderr;
fprintf(stderr, v13, v12, v10, v11, v8, "init_http_db", v17);
if ( log_color )
dprint_color_reset(v14, v13, v18);
goto LABEL_9;
}
v3 = connect_http_db(a1, a2);
if ( v3 )
{
if ( (int)get_debug_level("xhttp_pi", 8LL) < -1 || dprint_crit )
return (unsigned int)-1;
v5 = (unsigned int)++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): unable to connect to the database\n",
*((const char **)&log_level_info + 8),
"xhttp_pi [http_db_handler.c:79]: ",
"init_http_db");
goto LABEL_9;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v15 = *((_QWORD *)&log_level_info + 8);
v16 = my_pid();
v8 = "xhttp_pi [http_db_handler.c:79]: ";
v17 = v5;
v10 = v16;
v11 = v15;
v12 = process_no;
v13 = "%2d(%d) %s: %s%s(): unable to connect to the database\n";
goto LABEL_18;
}
(*(void (__fastcall **)(_QWORD))(v2 + 72))(*(_QWORD *)(v2 + 32));
*(_QWORD *)(v2 + 32) = 0LL;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, int a2)
{
__int64 v2; // rbx
unsigned int v3; // ebp
__int64 v5; // rsi
__int64 v6; // r12
unsigned int v7; // eax
const char *v8; // r9
__int64 v9; // r8
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // rdx
const char *v13; // rsi
struct _IO_FILE *v14; // rdi
__int64 v15; // r12
unsigned int v16; // eax
__int64 v17; // [rsp-8h] [rbp-20h]
__int64 v18; // [rsp-8h] [rbp-20h]

v2 = *a1 + 208LL * a2;
if ( (int)db_bind_mod(v2 + 16, v2 + 40) < 0 )
{
if ( (int)get_debug_level("xhttp_pi", 8LL) < -1 || dprint_crit )
return (unsigned int)-1;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): Unable to bind to a database driver\n",
*((const char **)&log_level_info + 8),
"xhttp_pi [http_db_handler.c:75]: ",
"init_http_db");
LABEL_9:
--dprint_crit;
return (unsigned int)-1;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v6 = *((_QWORD *)&log_level_info + 8);
v7 = my_pid();
v8 = "xhttp_pi [http_db_handler.c:75]: ";
v17 = v9;
v10 = v7;
v11 = v6;
v12 = process_no;
v13 = "%2d(%d) %s: %s%s(): Unable to bind to a database driver\n";
LABEL_18:
v14 = stderr;
fprintf(stderr, v13, v12, v10, v11, v8, "init_http_db", v17);
if ( log_color )
dprint_color_reset(v14, v13, v18);
goto LABEL_9;
}
v3 = func0(a1, a2);
if ( v3 )
{
if ( (int)get_debug_level("xhttp_pi", 8LL) < -1 || dprint_crit )
return (unsigned int)-1;
v5 = (unsigned int)++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): unable to connect to the database\n",
*((const char **)&log_level_info + 8),
"xhttp_pi [http_db_handler.c:79]: ",
"init_http_db");
goto LABEL_9;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v15 = *((_QWORD *)&log_level_info + 8);
v16 = my_pid();
v8 = "xhttp_pi [http_db_handler.c:79]: ";
v17 = v5;
v10 = v16;
v11 = v15;
v12 = process_no;
v13 = "%2d(%d) %s: %s%s(): unable to connect to the database\n";
goto LABEL_18;
}
(*(void (__fastcall **)(_QWORD))(v2 + 72))(*(_QWORD *)(v2 + 32));
*(_QWORD *)(v2 + 32) = 0LL;
return v3;
}

original_code:
int init_http_db(ph_framework_t *framework_data, int index)
{
 ph_db_url_t *ph_db_urls = framework_data->ph_db_urls;
 if (db_bind_mod(&ph_db_urls[index].db_url,
  &ph_db_urls[index].http_dbf) < 0) {
  do { if (get_debug_level("xhttp_pi", (sizeof("xhttp_pi")-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(): " "Unable to bind to a database driver\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("xhttp_pi" " [" "http_db_handler.c" ":" "75" "]: ") , __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(): " "Unable to bind to a database driver\n", (log_level_info[((-1)) - (-5)].name), ("xhttp_pi" " [" "http_db_handler.c" ":" "75" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "Unable to bind to a database driver\n", process_no, my_pid(), ("xhttp_pi" " [" "http_db_handler.c" ":" "75" "]: ") , __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(): " "Unable to bind to a database driver\n", ("xhttp_pi" " [" "http_db_handler.c" ":" "75" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Unable to bind to a database driver\n", ("xhttp_pi" " [" "http_db_handler.c" ":" "75" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (connect_http_db(framework_data, index)!=0){
  do { if (get_debug_level("xhttp_pi", (sizeof("xhttp_pi")-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(): " "unable to connect to the database\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("xhttp_pi" " [" "http_db_handler.c" ":" "79" "]: ") , __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(): " "unable to connect to the database\n", (log_level_info[((-1)) - (-5)].name), ("xhttp_pi" " [" "http_db_handler.c" ":" "79" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "unable to connect to the database\n", process_no, my_pid(), ("xhttp_pi" " [" "http_db_handler.c" ":" "79" "]: ") , __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(): " "unable to connect to the database\n", ("xhttp_pi" " [" "http_db_handler.c" ":" "79" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "unable to connect to the database\n", ("xhttp_pi" " [" "http_db_handler.c" ":" "79" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 ph_db_urls[index].http_dbf.close(ph_db_urls[index].http_db_handle);
 ph_db_urls[index].http_db_handle = ((void *)0);
 return 0;
}

canonical_original_code:
int init_http_db(struct ph_framework_ *framework_data, int index)
{
 struct ph_db_url_ *ph_db_urls = framework_data->ph_db_urls;
 if (db_bind_mod(&ph_db_urls[index].db_url,
  &ph_db_urls[index].http_dbf) < 0) {
  do { if (get_debug_level("xhttp_pi", (sizeof("xhttp_pi")-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(): " "Unable to bind to a database driver\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("xhttp_pi" " [" "http_db_handler.c" ":" "75" "]: ") , __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(): " "Unable to bind to a database driver\n", (log_level_info[((-1)) - (-5)].name), ("xhttp_pi" " [" "http_db_handler.c" ":" "75" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "Unable to bind to a database driver\n", process_no, my_pid(), ("xhttp_pi" " [" "http_db_handler.c" ":" "75" "]: ") , __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(): " "Unable to bind to a database driver\n", ("xhttp_pi" " [" "http_db_handler.c" ":" "75" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "Unable to bind to a database driver\n", ("xhttp_pi" " [" "http_db_handler.c" ":" "75" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (connect_http_db(framework_data, index)!=0){
  do { if (get_debug_level("xhttp_pi", (sizeof("xhttp_pi")-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(): " "unable to connect to the database\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("xhttp_pi" " [" "http_db_handler.c" ":" "79" "]: ") , __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(): " "unable to connect to the database\n", (log_level_info[((-1)) - (-5)].name), ("xhttp_pi" " [" "http_db_handler.c" ":" "79" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "unable to connect to the database\n", process_no, my_pid(), ("xhttp_pi" " [" "http_db_handler.c" ":" "79" "]: ") , __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(): " "unable to connect to the database\n", ("xhttp_pi" " [" "http_db_handler.c" ":" "79" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "unable to connect to the database\n", ("xhttp_pi" " [" "http_db_handler.c" ":" "79" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 ph_db_urls[index].http_dbf.close(ph_db_urls[index].http_db_handle);
 ph_db_urls[index].http_db_handle = ((void *)0);
 return 0;
}

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

user_defined_types: enum db_pooling_t { DB_POOLING_PERMITTED=0, DB_POOLING_NONE=1 }

user_defined_types: enum db_locking_t { DB_LOCKING_NONE=0, DB_LOCKING_WRITE=1, DB_LOCKING_FULL=2 }

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 }

user_defined_types: struct ph_vals_ { struct _str *ids; struct _str *vals; int vals_size; }

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


repo: virtualolson/who

decompiled_code:
__int64 __fastcall destroy_http_db(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
int v3; // ebp

if ( a1 )
{
result = *(unsigned int *)(a1 + 8);
if ( (int)result > 0 )
{
v2 = *(_QWORD *)a1 + 32LL;
v3 = 0;
do
{
if ( *(_QWORD *)v2 )
{
result = (*(__int64 (**)(void))(v2 + 40))();
*(_QWORD *)v2 = 0LL;
}
++v3;
v2 += 208LL;
}
while ( *(_DWORD *)(a1 + 8) > v3 );
}
}
return result;
}

original_code:
void destroy_http_db(ph_framework_t *framework_data)
{
 int i;
 ph_db_url_t *ph_db_urls;
 if (framework_data == ((void *)0)) return;
 ph_db_urls = framework_data->ph_db_urls;
 for(i=0;i<framework_data->ph_db_urls_size;i++){
  if (ph_db_urls[i].http_db_handle) {
   ph_db_urls[i].http_dbf.close(ph_db_urls[i].http_db_handle);
   ph_db_urls[i].http_db_handle = ((void *)0);
  }
 }
}

canonical_original_code:
void destroy_http_db(struct ph_framework_ *framework_data)
{
 int i;
 struct ph_db_url_ *ph_db_urls;
 if (framework_data == ((void *)0)) return;
 ph_db_urls = framework_data->ph_db_urls;
 for(i=0;i<framework_data->ph_db_urls_size;i++){
  if (ph_db_urls[i].http_db_handle) {
   ph_db_urls[i].http_dbf.close(ph_db_urls[i].http_db_handle);
   ph_db_urls[i].http_db_handle = ((void *)0);
  }
 }
}

variable_types: struct ph_framework_ { struct ph_db_url_ { struct _str { char *s; int len; } id; struct _str db_url; struct db1_con_t { struct _str *table; unsigned long tail; } *http_db_handle; 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 { 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); } http_dbf; } *ph_db_urls; int ph_db_urls_size; struct ph_db_table_ { struct _str id; struct _str name; struct ph_db_url_ *db_url; struct ph_table_col_ { struct _str field; 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; short validation; } *cols; int cols_size; } *ph_db_tables; int ph_db_tables_size; struct ph_mod_ { struct _str module; struct ph_cmd_ { struct _str name; unsigned int type; struct ph_db_table_ *db_table; char **c_ops; struct _str **c_keys; 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 } *c_types; struct ph_vals_ { struct _str *ids; struct _str *vals; int vals_size; } *c_vals; int c_keys_size; struct _str **q_keys; 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 } *q_types; struct ph_vals_ *q_vals; int q_keys_size; struct _str **o_keys; int o_keys_size; } *cmds; int cmds_size; } *ph_modules; int ph_modules_size; } *

variable_types: i int

return_type: void

user_defined_types: struct ph_framework_ { struct ph_db_url_ *ph_db_urls; int ph_db_urls_size; struct ph_db_table_ *ph_db_tables; int ph_db_tables_size; struct ph_mod_ *ph_modules; int ph_modules_size; }

user_defined_types: struct ph_db_url_ { struct _str id; struct _str db_url; struct db1_con_t *http_db_handle; struct db_func http_dbf; }

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 ph_db_table_ { struct _str id; struct _str name; struct ph_db_url_ *db_url; struct ph_table_col_ *cols; int cols_size; }

user_defined_types: struct ph_mod_ { struct _str module; struct ph_cmd_ *cmds; int cmds_size; }

user_defined_types: struct ph_table_col_ { struct _str field; enum db_type_t type; short validation; }

user_defined_types: struct ph_cmd_ { struct _str name; unsigned int type; struct ph_db_table_ *db_table; char **c_ops; struct _str **c_keys; enum db_type_t *c_types; struct ph_vals_ *c_vals; int c_keys_size; struct _str **q_keys; enum db_type_t *q_types; struct ph_vals_ *q_vals; int q_keys_size; struct _str **o_keys; int o_keys_size; }

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

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 atomic_get_and_set_int(volatile __int32 *a1, __int32 a2)
{
return (unsigned int)_InterlockedExchange(a1, a2);
}

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

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

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

variable_types:
var
int *

variable_types: v int

return_type: int


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

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

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

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

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

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

variable_types:
lock
struct atomic_t { int val; } *


decompiled_code:
__int64 __fastcall str2msg_handling(const char *a1, _DWORD *a2)
{
__int64 result; // rax
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
const char *v8; // rsi
__int64 v9; // rcx
char v10; // bl
const char *v11; // r13
unsigned int v12; // eax
struct _IO_FILE *v13; // rdi
__int64 v14; // [rsp-30h] [rbp-30h]

if ( !a1 )
return 0xFFFFFFFFLL;
result = strcmp(a1, "allow") != 0;
v5 = 0;
v6 = (_DWORD)result == 0;
if ( (_DWORD)result )
{
v7 = "block";
v8 = a1;
v9 = 6LL;
do
{
if ( !v9 )
break;
v5 = *v8 < (unsigned int)*v7;
v6 = *v8++ == *v7++;
--v9;
}
while ( v6 );
v10 = (!v5 && !v6) - v5;
result = (unsigned int)v10;
if ( v10 )
{
if ( (int)get_debug_level("core", 4LL, 6LL, v9, a2) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v11 = (const char *)*((_QWORD *)&log_level_info + 8);
v12 = my_pid();
v13 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): invalid im-handling value: '%s'\n",
process_no,
v12,
v11,
"<core> [parse_msg_rules.c:60]: ",
"str2msg_handling",
a1);
if ( log_color )
dprint_color_reset(v13, "%2d(%d) %s: %s%s(): invalid im-handling value: '%s'\n", v14);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): invalid im-handling value: '%s'\n",
*((const char **)&log_level_info + 8),
"<core> [parse_msg_rules.c:60]: ",
"str2msg_handling",
a1);
}
--dprint_crit;
}
result = 0xFFFFFFFFLL;
}
else
{
*a2 = 0;
}
}
else
{
*a2 = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, _DWORD *a2)
{
__int64 result; // rax
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
const char *v8; // rsi
__int64 v9; // rcx
char v10; // bl
const char *v11; // r13
unsigned int v12; // eax
struct _IO_FILE *v13; // rdi
__int64 v14; // [rsp-30h] [rbp-30h]

if ( !a1 )
return 0xFFFFFFFFLL;
result = strcmp(a1, "allow") != 0;
v5 = 0;
v6 = (_DWORD)result == 0;
if ( (_DWORD)result )
{
v7 = "block";
v8 = a1;
v9 = 6LL;
do
{
if ( !v9 )
break;
v5 = *v8 < (unsigned int)*v7;
v6 = *v8++ == *v7++;
--v9;
}
while ( v6 );
v10 = (!v5 && !v6) - v5;
result = (unsigned int)v10;
if ( v10 )
{
if ( (int)get_debug_level("core", 4LL, 6LL, v9, a2) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v11 = (const char *)*((_QWORD *)&log_level_info + 8);
v12 = my_pid();
v13 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): invalid im-handling value: '%s'\n",
process_no,
v12,
v11,
"<core> [parse_msg_rules.c:60]: ",
"str2msg_handling",
a1);
if ( log_color )
dprint_color_reset(v13, "%2d(%d) %s: %s%s(): invalid im-handling value: '%s'\n", v14);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): invalid im-handling value: '%s'\n",
*((const char **)&log_level_info + 8),
"<core> [parse_msg_rules.c:60]: ",
"str2msg_handling",
a1);
}
--dprint_crit;
}
result = 0xFFFFFFFFLL;
}
else
{
*a2 = 0;
}
}
else
{
*a2 = 1;
}
return result;
}

original_code:
static int str2msg_handling(const char *s, msg_handling_t *dst)
{
 if (!s) return (-1);
 if (strcmp(s, "allow") == 0) {
  *dst = msg_handling_allow;
  return 0;
 }
 if (strcmp(s, "block") == 0) {
  *dst = msg_handling_block;
  return 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(): " "invalid im-handling value: \'%s\'\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "parse_msg_rules.c" ":" "60" "]: ") , __func__, s); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "invalid im-handling value: \'%s\'\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "parse_msg_rules.c" ":" "60" "]: ") , __func__, s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "invalid im-handling value: \'%s\'\n", process_no, my_pid(), ("<core> [" "parse_msg_rules.c" ":" "60" "]: ") , __func__, s); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "invalid im-handling value: \'%s\'\n", ("<core> [" "parse_msg_rules.c" ":" "60" "]: ") , __func__, s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "invalid im-handling value: \'%s\'\n", ("<core> [" "parse_msg_rules.c" ":" "60" "]: ") , __func__, s); } } (dprint_crit--); } } while(0);
 return (-1);
}

canonical_original_code:
static int str2msg_handling(char *s, enum msg_handling_t *dst)
{
 if (!s) return (-1);
 if (strcmp(s, "allow") == 0) {
  *dst = msg_handling_allow;
  return 0;
 }
 if (strcmp(s, "block") == 0) {
  *dst = msg_handling_block;
  return 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(): " "invalid im-handling value: \'%s\'\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "parse_msg_rules.c" ":" "60" "]: ") , __func__, s); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "invalid im-handling value: \'%s\'\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "parse_msg_rules.c" ":" "60" "]: ") , __func__, s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "invalid im-handling value: \'%s\'\n", process_no, my_pid(), ("<core> [" "parse_msg_rules.c" ":" "60" "]: ") , __func__, s); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "invalid im-handling value: \'%s\'\n", ("<core> [" "parse_msg_rules.c" ":" "60" "]: ") , __func__, s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "invalid im-handling value: \'%s\'\n", ("<core> [" "parse_msg_rules.c" ":" "60" "]: ") , __func__, s); } } (dprint_crit--); } } while(0);
 return (-1);
}

variable_types:
s
char *

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall parse_msg_rules(__int64 a1, __int64 a2, __int64 a3)
{
return parse_common_rules(a1, a2, a3, read_msg_actions, &free_msg_actions);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
return parse_common_rules(a1, a2, a3, read_msg_actions, &free_msg_actions);
}

original_code:
int parse_msg_rules(const char *data, int dsize, cp_ruleset_t **dst)
{
 return parse_common_rules(data, dsize, dst,
   read_msg_actions, free_msg_actions);
}

canonical_original_code:
int parse_msg_rules(char *data, int dsize, struct cp_ruleset_t **dst)
{
 return parse_common_rules(data, dsize, dst,
   read_msg_actions, free_msg_actions);
}

variable_types:
data
char *

variable_types: dsize int

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

user_defined_types: struct cp_ruleset_t { struct _cp_rule_t *rules; }

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

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

user_defined_types: struct cp_actions_t { struct _cp_unknown_t *unknown; }

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

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

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


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

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


decompiled_code:
__int64 __fastcall register_xcapcb(int a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rcx
__int64 result; // rax
int v5; // er8
const char *v6; // r12
unsigned int v7; // eax
struct _IO_FILE *v8; // rdi
__int64 v9; // [rsp-8h] [rbp-20h]

v2 = shm_malloc_constprop_0();
if ( v2 )
{
*(_OWORD *)v2 = 0LL;
v3 = xcapcb_list;
*(_DWORD *)v2 = a1;
*(_QWORD *)(v2 + 8) = a2;
*(_QWORD *)(v2 + 16) = v3;
xcapcb_list = v2;
result = 0LL;
}
else
{
v5 = get_debug_level("xcap_client", 11LL);
result = 0xFFFFFFFFLL;
if ( v5 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v6 = (const char *)*((_QWORD *)&log_level_info + 8);
v7 = my_pid();
v8 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): No more %s memory\n",
process_no,
v7,
v6,
"xcap_client [xcap_callbacks.c:58]: ",
"register_xcapcb",
"share");
if ( log_color )
dprint_color_reset(v8, "%2d(%d) %s: %s%s(): No more %s memory\n", v9);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): No more %s memory\n",
*((const char **)&log_level_info + 8),
"xcap_client [xcap_callbacks.c:58]: ",
"register_xcapcb",
"share");
}
result = 0xFFFFFFFFLL;
--dprint_crit;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rcx
__int64 result; // rax
int v5; // er8
const char *v6; // r12
unsigned int v7; // eax
struct _IO_FILE *v8; // rdi
__int64 v9; // [rsp-8h] [rbp-20h]

v2 = func4();
if ( v2 )
{
*(_OWORD *)v2 = 0LL;
v3 = xcapcb_list;
*(_DWORD *)v2 = a1;
*(_QWORD *)(v2 + 8) = a2;
*(_QWORD *)(v2 + 16) = v3;
xcapcb_list = v2;
result = 0LL;
}
else
{
v5 = get_debug_level("xcap_client", 11LL);
result = 0xFFFFFFFFLL;
if ( v5 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v6 = (const char *)*((_QWORD *)&log_level_info + 8);
v7 = my_pid();
v8 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): No more %s memory\n",
process_no,
v7,
v6,
"xcap_client [xcap_callbacks.c:58]: ",
"register_xcapcb",
"share");
if ( log_color )
dprint_color_reset(v8, "%2d(%d) %s: %s%s(): No more %s memory\n", v9);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): No more %s memory\n",
*((const char **)&log_level_info + 8),
"xcap_client [xcap_callbacks.c:58]: ",
"register_xcapcb",
"share");
}
result = 0xFFFFFFFFLL;
--dprint_crit;
}
}
return result;
}

original_code:
int register_xcapcb( int types, xcap_cb f)
{
 xcap_callback_t* xcb;
 xcb= (xcap_callback_t*)shm_malloc(sizeof(xcap_callback_t));
 if(xcb== ((void *)0))
 {
  do { if (get_debug_level("xcap_client", (sizeof("xcap_client")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "No more %s memory\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("xcap_client" " [" "xcap_callbacks.c" ":" "58" "]: ") , __func__,"share"); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "No more %s memory\n", (log_level_info[((-1)) - (-5)].name), ("xcap_client" " [" "xcap_callbacks.c" ":" "58" "]: ") , __func__,"share"); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "No more %s memory\n", process_no, my_pid(), ("xcap_client" " [" "xcap_callbacks.c" ":" "58" "]: ") , __func__,"share"); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "No more %s memory\n", ("xcap_client" " [" "xcap_callbacks.c" ":" "58" "]: ") , __func__,"share"); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "No more %s memory\n", ("xcap_client" " [" "xcap_callbacks.c" ":" "58" "]: ") , __func__,"share"); } } (dprint_crit--); } } while(0); goto error;
 }
 memset(xcb, 0, sizeof(xcap_callback_t));
 xcb->callback= f;
 xcb->types= types;
 xcb->next= xcapcb_list;
 xcapcb_list= xcb;
 return 0;
error:
 return -1;
}

canonical_original_code:
int register_xcapcb(int types, int f(int doc_type, struct _str xid, char *doc))
{
 struct xcap_callback *xcb;
 xcb= (struct xcap_callback *)shm_malloc(sizeof(xcap_callback_t));
 if(xcb== ((void *)0))
 {
  do { if (get_debug_level("xcap_client", (sizeof("xcap_client")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "No more %s memory\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("xcap_client" " [" "xcap_callbacks.c" ":" "58" "]: ") , __func__,"share"); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "No more %s memory\n", (log_level_info[((-1)) - (-5)].name), ("xcap_client" " [" "xcap_callbacks.c" ":" "58" "]: ") , __func__,"share"); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "No more %s memory\n", process_no, my_pid(), ("xcap_client" " [" "xcap_callbacks.c" ":" "58" "]: ") , __func__,"share"); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "No more %s memory\n", ("xcap_client" " [" "xcap_callbacks.c" ":" "58" "]: ") , __func__,"share"); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "No more %s memory\n", ("xcap_client" " [" "xcap_callbacks.c" ":" "58" "]: ") , __func__,"share"); } } (dprint_crit--); } } while(0); goto error;
 }
 memset(xcb, 0, sizeof(xcap_callback_t));
 xcb->callback= f;
 xcb->types= types;
 xcb->next= xcapcb_list;
 xcapcb_list= xcb;
 return 0;
error:
 return -1;
}

variable_types: types int

variable_types: int (int doc_type, struct _str { char *s; int len; } xid, char *doc)

variable_types: struct xcap_callback { int types; int (*callback)(int doc_type, struct _str { char *s; int len; } xid, char *doc); struct xcap_callback *next; } *

user_defined_types: struct xcap_callback { int types; int (*callback)(int doc_type, struct _str xid, char *doc); struct xcap_callback *next; }


decompiled_code:
_QWORD *destroy_xcapcb_list()
{
_QWORD *result; // rax
__int64 i; // rbx
__int64 v2; // r12

result = &xcapcb_list;
for ( i = xcapcb_list; i; result = (_QWORD *)futex_release(mem_lock) )
{
v2 = i;
i = *(_QWORD *)(i + 16);
futex_get(mem_lock);
qm_free(shm_block, v2);
}
return result;
}

canonical_decompiled_code:
_QWORD *func6()
{
_QWORD *result; // rax
__int64 i; // rbx
__int64 v2; // r12

result = &xcapcb_list;
for ( i = xcapcb_list; i; result = (_QWORD *)func1(mem_lock) )
{
v2 = i;
i = *(_QWORD *)(i + 16);
func3(mem_lock);
qm_free(shm_block, v2);
}
return result;
}

original_code:
void destroy_xcapcb_list(void)
{
 xcap_callback_t* xcb, *prev_xcb;
 xcb= xcapcb_list;
 while(xcb)
 {
  prev_xcb= xcb;
  xcb= xcb->next;
  do { futex_get(mem_lock); qm_free(shm_block, (prev_xcb)); futex_release(mem_lock); }while(0);
 }
}

canonical_original_code:
void destroy_xcapcb_list()
{
 struct xcap_callback *xcb; struct xcap_callback *prev_xcb;
 xcb= xcapcb_list;
 while(xcb)
 {
  prev_xcb= xcb;
  xcb= xcb->next;
  do { futex_get(mem_lock); qm_free(shm_block, (prev_xcb)); futex_release(mem_lock); }while(0);
 }
}


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

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

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

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

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

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

variable_types:
size
unsigned int

variable_types:
p
void *

return_type: void *


decompiled_code:
__int64 __fastcall get_user_script(const char **a1, __int64 a2, int a3)
{
const char *v6; // rdx
__int64 v7; // rax
__int64 v8; // r13
__int64 v9; // r12
unsigned int v10; // ebx
unsigned int v12; // edi
void *v13; // rax
const char *v14; // r15
__int64 v15; // r14
__int64 v16; // rbp
__int64 v17; // rcx
const char *v18; // r9
__int64 v19; // r8
__int64 v20; // rdx
const char *v21; // rsi
struct _IO_FILE *v22; // rdi
__int64 v23; // rdx
__int64 v24; // r14
const char *v25; // r15
unsigned int v26; // eax
struct _IO_FILE *v27; // rdi
__int64 v28; // rdx
const char *v29; // r14
const char *v30; // r15
unsigned int v31; // eax
struct _IO_FILE *v32; // rdi
__int64 v33; // rdx
const char *v34; // r15
__int64 v35; // r14
__int64 v36; // rbp
__int64 v37; // r12
__int64 v38; // rcx
const char *v39; // r9
__int64 v40; // r8
__int64 v41; // rdx
const char *v42; // rsi
struct _IO_FILE *v43; // rdi
__int64 v44; // r13
__int64 v45; // [rsp-18h] [rbp-60h]
const char *v46; // [rsp-10h] [rbp-58h]
__int64 v47; // [rsp-8h] [rbp-50h]
__int64 v48[8]; // [rsp+8h] [rbp-40h] BYREF

v6 = *a1;
v48[0] = 0LL;
*(_QWORD *)(*(_QWORD *)(get_script + 560) + 152LL) = v6;
if ( (int)get_debug_level("cpl-c", 5LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v29 = *a1;
v30 = (const char *)*((_QWORD *)&log_level_info + 16);
v31 = my_pid();
v32 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): DEBUG:get_user_script: fetching script for user <%s>\n",
process_no,
v31,
v30,
"cpl-c [cpl_db.c:122]: ",
"get_user_script",
v29);
if ( log_color )
dprint_color_reset(v32, "%2d(%d) %s: %s%s(): DEBUG:get_user_script: fetching script for user <%s>\n", v33);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): DEBUG:get_user_script: fetching script for user <%s>\n",
*((const char **)&log_level_info + 16),
"cpl-c [cpl_db.c:122]: ",
"get_user_script",
*a1);
}
--dprint_crit;
}
if ( (int)db_exec(v48, get_script) < 0 )
{
if ( (int)get_debug_level("cpl-c", 5LL) < -1 || dprint_crit )
goto LABEL_35;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR:cpl-c:get_user_script: db_query failed\n",
*((const char **)&log_level_info + 8),
"cpl-c [cpl_db.c:124]: ",
"get_user_script");
LABEL_34:
--dprint_crit;
goto LABEL_35;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v37 = *((_QWORD *)&log_level_info + 8);
v38 = (unsigned int)my_pid();
v39 = "cpl-c [cpl_db.c:124]: ";
v40 = v37;
v41 = process_no;
v42 = "%2d(%d) %s: %s%s(): ERROR:cpl-c:get_user_script: db_query failed\n";
LABEL_61:
v43 = stderr;
fprintf(stderr, v42, v41, v38, v40, v39, "get_user_script");
if ( log_color )
dprint_color_reset(v43, v42, v47);
goto LABEL_34;
}
if ( !v48[0] || (v7 = db_first(), (v8 = v7) == 0) )
{
if ( (int)get_debug_level("cpl-c", 5LL) <= 2 || dprint_crit )
goto LABEL_11;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): DEBUG:get_user_script: user <%.*s> not found in db -> probably he has no script\n",
*((_QWORD *)&log_level_info + 16),
"cpl-c [cpl_db.c:129]: ",
"get_user_script",
*((unsigned int *)a1 + 2),
*a1);
LABEL_19:
--dprint_crit;
LABEL_11:
*(_QWORD *)a2 = 0LL;
*(_DWORD *)(a2 + 8) = 0;
goto LABEL_12;
}
if ( log_color )
dprint_color(3LL);
v34 = *a1;
v35 = *((unsigned int *)a1 + 2);
v36 = *((_QWORD *)&log_level_info + 16);
v46 = v34;
v17 = (unsigned int)my_pid();
v18 = "cpl-c [cpl_db.c:129]: ";
v19 = v36;
v45 = v35;
v21 = "%2d(%d) %s: %s%s(): DEBUG:get_user_script: user <%.*s> not found in db -> probably he has no script\n";
v20 = process_no;
LABEL_45:
v22 = stderr;
fprintf(stderr, v21, v20, v17, v19, v18, "get_user_script", v45, v46);
if ( log_color )
dprint_color_reset(v22, v21, v23);
goto LABEL_19;
}
v9 = 176LL * (a3 == 0);
if ( (*(_BYTE *)(*(_QWORD *)(v7 + 144) + v9 + 148) & 1) != 0 )
{
if ( (int)get_debug_level("cpl-c", 5LL) <= 2 || dprint_crit )
goto LABEL_11;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): DEBUG:get_user_script: user <%.*s> has a NULL script\n",
*((_QWORD *)&log_level_info + 16),
"cpl-c [cpl_db.c:135]: ",
"get_user_script",
*((unsigned int *)a1 + 2),
*a1);
goto LABEL_19;
}
if ( log_color )
dprint_color(3LL);
v14 = *a1;
v15 = *((unsigned int *)a1 + 2);
v16 = *((_QWORD *)&log_level_info + 16);
v46 = v14;
v17 = (unsigned int)my_pid();
v18 = "cpl-c [cpl_db.c:135]: ";
v19 = v16;
v45 = v15;
v20 = process_no;
v21 = "%2d(%d) %s: %s%s(): DEBUG:get_user_script: user <%.*s> has a NULL script\n";
goto LABEL_45;
}
if ( (int)get_debug_level("cpl-c", 5LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v24 = *(unsigned int *)(*(_QWORD *)(v8 + 144) + v9 + 160);
v25 = (const char *)*((_QWORD *)&log_level_info + 16);
v26 = my_pid();
v27 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): DEBUG:get_user_script: we got the script len=%d\n",
process_no,
v26,
v25,
"cpl-c [cpl_db.c:140]: ",
"get_user_script",
v24);
if ( log_color )
dprint_color_reset(v27, "%2d(%d) %s: %s%s(): DEBUG:get_user_script: we got the script len=%d\n", v28);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): DEBUG:get_user_script: we got the script len=%d\n",
*((const char **)&log_level_info + 16),
"cpl-c [cpl_db.c:140]: ",
"get_user_script",
*(unsigned int *)(*(_QWORD *)(v8 + 144) + v9 + 160));
}
--dprint_crit;
}
v12 = *(_DWORD *)(*(_QWORD *)(v8 + 144) + v9 + 160);
*(_DWORD *)(a2 + 8) = v12;
v13 = (void *)shm_malloc(v12);
*(_QWORD *)a2 = v13;
if ( v13 )
{
memcpy(v13, *(const void **)(*(_QWORD *)(v8 + 144) + v9 + 152), *(int *)(a2 + 8));
LABEL_12:
v10 = 1;
if ( v48[0] )
db_res_free();
return v10;
}
if ( (int)get_debug_level("cpl-c", 5LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR:cpl-c:get_user_script: no free sh_mem\n",
*((const char **)&log_level_info + 8),
"cpl-c [cpl_db.c:145]: ",
"get_user_script");
goto LABEL_34;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v44 = *((_QWORD *)&log_level_info + 8);
v38 = (unsigned int)my_pid();
v40 = v44;
v39 = "cpl-c [cpl_db.c:145]: ";
v41 = process_no;
v42 = "%2d(%d) %s: %s%s(): ERROR:cpl-c:get_user_script: no free sh_mem\n";
goto LABEL_61;
}
LABEL_35:
if ( v48[0] )
db_res_free();
*(_QWORD *)a2 = 0LL;
*(_DWORD *)(a2 + 8) = 0;
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char **a1, __int64 a2, int a3)
{
const char *v6; // rdx
__int64 v7; // rax
__int64 v8; // r13
__int64 v9; // r12
unsigned int v10; // ebx
unsigned int v12; // edi
void *v13; // rax
const char *v14; // r15
__int64 v15; // r14
__int64 v16; // rbp
__int64 v17; // rcx
const char *v18; // r9
__int64 v19; // r8
__int64 v20; // rdx
const char *v21; // rsi
struct _IO_FILE *v22; // rdi
__int64 v23; // rdx
__int64 v24; // r14
const char *v25; // r15
unsigned int v26; // eax
struct _IO_FILE *v27; // rdi
__int64 v28; // rdx
const char *v29; // r14
const char *v30; // r15
unsigned int v31; // eax
struct _IO_FILE *v32; // rdi
__int64 v33; // rdx
const char *v34; // r15
__int64 v35; // r14
__int64 v36; // rbp
__int64 v37; // r12
__int64 v38; // rcx
const char *v39; // r9
__int64 v40; // r8
__int64 v41; // rdx
const char *v42; // rsi
struct _IO_FILE *v43; // rdi
__int64 v44; // r13
__int64 v45; // [rsp-18h] [rbp-60h]
const char *v46; // [rsp-10h] [rbp-58h]
__int64 v47; // [rsp-8h] [rbp-50h]
__int64 v48[8]; // [rsp+8h] [rbp-40h] BYREF

v6 = *a1;
v48[0] = 0LL;
*(_QWORD *)(*(_QWORD *)(get_script + 560) + 152LL) = v6;
if ( (int)get_debug_level("cpl-c", 5LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v29 = *a1;
v30 = (const char *)*((_QWORD *)&log_level_info + 16);
v31 = my_pid();
v32 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): DEBUG:get_user_script: fetching script for user <%s>\n",
process_no,
v31,
v30,
"cpl-c [cpl_db.c:122]: ",
"get_user_script",
v29);
if ( log_color )
dprint_color_reset(v32, "%2d(%d) %s: %s%s(): DEBUG:get_user_script: fetching script for user <%s>\n", v33);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): DEBUG:get_user_script: fetching script for user <%s>\n",
*((const char **)&log_level_info + 16),
"cpl-c [cpl_db.c:122]: ",
"get_user_script",
*a1);
}
--dprint_crit;
}
if ( (int)db_exec(v48, get_script) < 0 )
{
if ( (int)get_debug_level("cpl-c", 5LL) < -1 || dprint_crit )
goto LABEL_35;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR:cpl-c:get_user_script: db_query failed\n",
*((const char **)&log_level_info + 8),
"cpl-c [cpl_db.c:124]: ",
"get_user_script");
LABEL_34:
--dprint_crit;
goto LABEL_35;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v37 = *((_QWORD *)&log_level_info + 8);
v38 = (unsigned int)my_pid();
v39 = "cpl-c [cpl_db.c:124]: ";
v40 = v37;
v41 = process_no;
v42 = "%2d(%d) %s: %s%s(): ERROR:cpl-c:get_user_script: db_query failed\n";
LABEL_61:
v43 = stderr;
fprintf(stderr, v42, v41, v38, v40, v39, "get_user_script");
if ( log_color )
dprint_color_reset(v43, v42, v47);
goto LABEL_34;
}
if ( !v48[0] || (v7 = db_first(), (v8 = v7) == 0) )
{
if ( (int)get_debug_level("cpl-c", 5LL) <= 2 || dprint_crit )
goto LABEL_11;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): DEBUG:get_user_script: user <%.*s> not found in db -> probably he has no script\n",
*((_QWORD *)&log_level_info + 16),
"cpl-c [cpl_db.c:129]: ",
"get_user_script",
*((unsigned int *)a1 + 2),
*a1);
LABEL_19:
--dprint_crit;
LABEL_11:
*(_QWORD *)a2 = 0LL;
*(_DWORD *)(a2 + 8) = 0;
goto LABEL_12;
}
if ( log_color )
dprint_color(3LL);
v34 = *a1;
v35 = *((unsigned int *)a1 + 2);
v36 = *((_QWORD *)&log_level_info + 16);
v46 = v34;
v17 = (unsigned int)my_pid();
v18 = "cpl-c [cpl_db.c:129]: ";
v19 = v36;
v45 = v35;
v21 = "%2d(%d) %s: %s%s(): DEBUG:get_user_script: user <%.*s> not found in db -> probably he has no script\n";
v20 = process_no;
LABEL_45:
v22 = stderr;
fprintf(stderr, v21, v20, v17, v19, v18, "get_user_script", v45, v46);
if ( log_color )
dprint_color_reset(v22, v21, v23);
goto LABEL_19;
}
v9 = 176LL * (a3 == 0);
if ( (*(_BYTE *)(*(_QWORD *)(v7 + 144) + v9 + 148) & 1) != 0 )
{
if ( (int)get_debug_level("cpl-c", 5LL) <= 2 || dprint_crit )
goto LABEL_11;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): DEBUG:get_user_script: user <%.*s> has a NULL script\n",
*((_QWORD *)&log_level_info + 16),
"cpl-c [cpl_db.c:135]: ",
"get_user_script",
*((unsigned int *)a1 + 2),
*a1);
goto LABEL_19;
}
if ( log_color )
dprint_color(3LL);
v14 = *a1;
v15 = *((unsigned int *)a1 + 2);
v16 = *((_QWORD *)&log_level_info + 16);
v46 = v14;
v17 = (unsigned int)my_pid();
v18 = "cpl-c [cpl_db.c:135]: ";
v19 = v16;
v45 = v15;
v20 = process_no;
v21 = "%2d(%d) %s: %s%s(): DEBUG:get_user_script: user <%.*s> has a NULL script\n";
goto LABEL_45;
}
if ( (int)get_debug_level("cpl-c", 5LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v24 = *(unsigned int *)(*(_QWORD *)(v8 + 144) + v9 + 160);
v25 = (const char *)*((_QWORD *)&log_level_info + 16);
v26 = my_pid();
v27 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): DEBUG:get_user_script: we got the script len=%d\n",
process_no,
v26,
v25,
"cpl-c [cpl_db.c:140]: ",
"get_user_script",
v24);
if ( log_color )
dprint_color_reset(v27, "%2d(%d) %s: %s%s(): DEBUG:get_user_script: we got the script len=%d\n", v28);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): DEBUG:get_user_script: we got the script len=%d\n",
*((const char **)&log_level_info + 16),
"cpl-c [cpl_db.c:140]: ",
"get_user_script",
*(unsigned int *)(*(_QWORD *)(v8 + 144) + v9 + 160));
}
--dprint_crit;
}
v12 = *(_DWORD *)(*(_QWORD *)(v8 + 144) + v9 + 160);
*(_DWORD *)(a2 + 8) = v12;
v13 = (void *)func4(v12);
*(_QWORD *)a2 = v13;
if ( v13 )
{
memcpy(v13, *(const void **)(*(_QWORD *)(v8 + 144) + v9 + 152), *(int *)(a2 + 8));
LABEL_12:
v10 = 1;
if ( v48[0] )
db_res_free();
return v10;
}
if ( (int)get_debug_level("cpl-c", 5LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR:cpl-c:get_user_script: no free sh_mem\n",
*((const char **)&log_level_info + 8),
"cpl-c [cpl_db.c:145]: ",
"get_user_script");
goto LABEL_34;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v44 = *((_QWORD *)&log_level_info + 8);
v38 = (unsigned int)my_pid();
v40 = v44;
v39 = "cpl-c [cpl_db.c:145]: ";
v41 = process_no;
v42 = "%2d(%d) %s: %s%s(): ERROR:cpl-c:get_user_script: no free sh_mem\n";
goto LABEL_61;
}
LABEL_35:
if ( v48[0] )
db_res_free();
*(_QWORD *)a2 = 0LL;
*(_DWORD *)(a2 + 8) = 0;
return (unsigned int)-1;
}

original_code:
int get_user_script(str *username, str *domain, str *script, str* key)
{
 db_key_t keys_cmp[2];
 db_key_t keys_ret[1];
 db_val_t vals[2];
 db1_res_t *res = ((void *)0);
 int n;
 keys_cmp[0] = &cpl_username_col;
 keys_cmp[1] = &cpl_domain_col;
 keys_ret[0] = key;
 do { if (get_debug_level("cpl-c", (sizeof("cpl-c")-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(): " "fetching script for user <%.*s>\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "125" "]: ") , __func__, username->len,username->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(): " "fetching script for user <%.*s>\n", (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "125" "]: ") , __func__, username->len,username->s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "fetching script for user <%.*s>\n", process_no, my_pid(), ("cpl-c" " [" "cpl_db.c" ":" "125" "]: ") , __func__, username->len,username->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(): " "fetching script for user <%.*s>\n", ("cpl-c" " [" "cpl_db.c" ":" "125" "]: ") , __func__, username->len,username->s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "fetching script for user <%.*s>\n", ("cpl-c" " [" "cpl_db.c" ":" "125" "]: ") , __func__, username->len,username->s); } } (dprint_crit--); } } while(0);
 vals[0].type = DB1_STR;
 vals[0].nul = 0;
 vals[0].val.str_val = *username;
 n = 1;
 if (domain) {
  vals[1].type = DB1_STR;
  vals[1].nul = 0;
  vals[1].val.str_val = *domain;
  n++;
 }
 if (cpl_dbf.query(db_hdl, keys_cmp, 0, vals, keys_ret, n, 1, ((void *)0), &res)
   < 0){
  do { if (get_debug_level("cpl-c", (sizeof("cpl-c")-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(): " "db_query failed\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "140" "]: ") , __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(): " "db_query failed\n", (log_level_info[((-1)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "140" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "db_query failed\n", process_no, my_pid(), ("cpl-c" " [" "cpl_db.c" ":" "140" "]: ") , __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(): " "db_query failed\n", ("cpl-c" " [" "cpl_db.c" ":" "140" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "db_query failed\n", ("cpl-c" " [" "cpl_db.c" ":" "140" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (res->n==0) {
  do { if (get_debug_level("cpl-c", (sizeof("cpl-c")-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(): " "user <%.*s> not found in db -> probably " "he has no script\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "145" "]: ") , __func__,username->len, username->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(): " "user <%.*s> not found in db -> probably " "he has no script\n", (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "145" "]: ") , __func__,username->len, username->s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "user <%.*s> not found in db -> probably " "he has no script\n", process_no, my_pid(), ("cpl-c" " [" "cpl_db.c" ":" "145" "]: ") , __func__,username->len, username->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(): " "user <%.*s> not found in db -> probably " "he has no script\n", ("cpl-c" " [" "cpl_db.c" ":" "145" "]: ") , __func__,username->len, username->s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "user <%.*s> not found in db -> probably " "he has no script\n", ("cpl-c" " [" "cpl_db.c" ":" "145" "]: ") , __func__,username->len, username->s); } } (dprint_crit--); } } while(0);
  script->s = 0;
  script->len = 0;
 } else {
  if (res->rows[0].values[0].nul) {
   do { if (get_debug_level("cpl-c", (sizeof("cpl-c")-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(): " "user <%.*s> has a NULL script\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "151" "]: ") , __func__, username->len, username->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(): " "user <%.*s> has a NULL script\n", (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "151" "]: ") , __func__, username->len, username->s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "user <%.*s> has a NULL script\n", process_no, my_pid(), ("cpl-c" " [" "cpl_db.c" ":" "151" "]: ") , __func__, username->len, username->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(): " "user <%.*s> has a NULL script\n", ("cpl-c" " [" "cpl_db.c" ":" "151" "]: ") , __func__, username->len, username->s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "user <%.*s> has a NULL script\n", ("cpl-c" " [" "cpl_db.c" ":" "151" "]: ") , __func__, username->len, username->s); } } (dprint_crit--); } } while(0);
   script->s = 0;
   script->len = 0;
  } else {
   do { if (get_debug_level("cpl-c", (sizeof("cpl-c")-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(): " "we got the script len=%d\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "156" "]: ") , __func__, res->rows[0].values[0].val.blob_val.len); 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(): " "we got the script len=%d\n", (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "156" "]: ") , __func__, res->rows[0].values[0].val.blob_val.len); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "we got the script len=%d\n", process_no, my_pid(), ("cpl-c" " [" "cpl_db.c" ":" "156" "]: ") , __func__, res->rows[0].values[0].val.blob_val.len); 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(): " "we got the script len=%d\n", ("cpl-c" " [" "cpl_db.c" ":" "156" "]: ") , __func__, res->rows[0].values[0].val.blob_val.len); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "we got the script len=%d\n", ("cpl-c" " [" "cpl_db.c" ":" "156" "]: ") , __func__, res->rows[0].values[0].val.blob_val.len); } } (dprint_crit--); } } while(0);
   script->len = res->rows[0].values[0].val.blob_val.len;
   script->s = shm_malloc( script->len );
   if (!script->s) {
    do { if (get_debug_level("cpl-c", (sizeof("cpl-c")-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 free sh_mem\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "161" "]: ") , __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 free sh_mem\n", (log_level_info[((-1)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "161" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no free sh_mem\n", process_no, my_pid(), ("cpl-c" " [" "cpl_db.c" ":" "161" "]: ") , __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 free sh_mem\n", ("cpl-c" " [" "cpl_db.c" ":" "161" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no free sh_mem\n", ("cpl-c" " [" "cpl_db.c" ":" "161" "]: ") , __func__); } } (dprint_crit--); } } while(0);
    goto error;
   }
   memcpy( script->s, res->rows[0].values[0].val.blob_val.s,
    script->len);
  }
 }
 cpl_dbf.free_result( db_hdl, res);
 return 1;
error:
 if (res)
  cpl_dbf.free_result( db_hdl, res);
 script->s = 0;
 script->len = 0;
 return -1;
}

canonical_original_code:
int get_user_script(struct _str *username, struct _str *domain, struct _str *script, struct _str *key)
{
 struct _str *keys_cmp[2];
 struct _str *keys_ret[1];
 struct db_val_t vals[2];
 struct db1_res *res = ((void *)0);
 int n;
 keys_cmp[0] = &cpl_username_col;
 keys_cmp[1] = &cpl_domain_col;
 keys_ret[0] = key;
 do { if (get_debug_level("cpl-c", (sizeof("cpl-c")-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(): " "fetching script for user <%.*s>\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "125" "]: ") , __func__, username->len,username->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(): " "fetching script for user <%.*s>\n", (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "125" "]: ") , __func__, username->len,username->s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "fetching script for user <%.*s>\n", process_no, my_pid(), ("cpl-c" " [" "cpl_db.c" ":" "125" "]: ") , __func__, username->len,username->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(): " "fetching script for user <%.*s>\n", ("cpl-c" " [" "cpl_db.c" ":" "125" "]: ") , __func__, username->len,username->s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "fetching script for user <%.*s>\n", ("cpl-c" " [" "cpl_db.c" ":" "125" "]: ") , __func__, username->len,username->s); } } (dprint_crit--); } } while(0);
 vals[0].type = DB1_STR;
 vals[0].nul = 0;
 vals[0].val.str_val = *username;
 n = 1;
 if (domain) {
  vals[1].type = DB1_STR;
  vals[1].nul = 0;
  vals[1].val.str_val = *domain;
  n++;
 }
 if (cpl_dbf.query(db_hdl, keys_cmp, 0, vals, keys_ret, n, 1, ((void *)0), &res)
   < 0){
  do { if (get_debug_level("cpl-c", (sizeof("cpl-c")-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(): " "db_query failed\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "140" "]: ") , __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(): " "db_query failed\n", (log_level_info[((-1)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "140" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "db_query failed\n", process_no, my_pid(), ("cpl-c" " [" "cpl_db.c" ":" "140" "]: ") , __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(): " "db_query failed\n", ("cpl-c" " [" "cpl_db.c" ":" "140" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "db_query failed\n", ("cpl-c" " [" "cpl_db.c" ":" "140" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (res->n==0) {
  do { if (get_debug_level("cpl-c", (sizeof("cpl-c")-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(): " "user <%.*s> not found in db -> probably " "he has no script\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "145" "]: ") , __func__,username->len, username->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(): " "user <%.*s> not found in db -> probably " "he has no script\n", (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "145" "]: ") , __func__,username->len, username->s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "user <%.*s> not found in db -> probably " "he has no script\n", process_no, my_pid(), ("cpl-c" " [" "cpl_db.c" ":" "145" "]: ") , __func__,username->len, username->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(): " "user <%.*s> not found in db -> probably " "he has no script\n", ("cpl-c" " [" "cpl_db.c" ":" "145" "]: ") , __func__,username->len, username->s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "user <%.*s> not found in db -> probably " "he has no script\n", ("cpl-c" " [" "cpl_db.c" ":" "145" "]: ") , __func__,username->len, username->s); } } (dprint_crit--); } } while(0);
  script->s = 0;
  script->len = 0;
 } else {
  if (res->rows[0].values[0].nul) {
   do { if (get_debug_level("cpl-c", (sizeof("cpl-c")-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(): " "user <%.*s> has a NULL script\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "151" "]: ") , __func__, username->len, username->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(): " "user <%.*s> has a NULL script\n", (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "151" "]: ") , __func__, username->len, username->s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "user <%.*s> has a NULL script\n", process_no, my_pid(), ("cpl-c" " [" "cpl_db.c" ":" "151" "]: ") , __func__, username->len, username->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(): " "user <%.*s> has a NULL script\n", ("cpl-c" " [" "cpl_db.c" ":" "151" "]: ") , __func__, username->len, username->s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "user <%.*s> has a NULL script\n", ("cpl-c" " [" "cpl_db.c" ":" "151" "]: ") , __func__, username->len, username->s); } } (dprint_crit--); } } while(0);
   script->s = 0;
   script->len = 0;
  } else {
   do { if (get_debug_level("cpl-c", (sizeof("cpl-c")-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(): " "we got the script len=%d\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "156" "]: ") , __func__, res->rows[0].values[0].val.blob_val.len); 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(): " "we got the script len=%d\n", (log_level_info[((3)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "156" "]: ") , __func__, res->rows[0].values[0].val.blob_val.len); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "we got the script len=%d\n", process_no, my_pid(), ("cpl-c" " [" "cpl_db.c" ":" "156" "]: ") , __func__, res->rows[0].values[0].val.blob_val.len); 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(): " "we got the script len=%d\n", ("cpl-c" " [" "cpl_db.c" ":" "156" "]: ") , __func__, res->rows[0].values[0].val.blob_val.len); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "we got the script len=%d\n", ("cpl-c" " [" "cpl_db.c" ":" "156" "]: ") , __func__, res->rows[0].values[0].val.blob_val.len); } } (dprint_crit--); } } while(0);
   script->len = res->rows[0].values[0].val.blob_val.len;
   script->s = shm_malloc( script->len );
   if (!script->s) {
    do { if (get_debug_level("cpl-c", (sizeof("cpl-c")-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 free sh_mem\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "161" "]: ") , __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 free sh_mem\n", (log_level_info[((-1)) - (-5)].name), ("cpl-c" " [" "cpl_db.c" ":" "161" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no free sh_mem\n", process_no, my_pid(), ("cpl-c" " [" "cpl_db.c" ":" "161" "]: ") , __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 free sh_mem\n", ("cpl-c" " [" "cpl_db.c" ":" "161" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no free sh_mem\n", ("cpl-c" " [" "cpl_db.c" ":" "161" "]: ") , __func__); } } (dprint_crit--); } } while(0);
    goto error;
   }
   memcpy( script->s, res->rows[0].values[0].val.blob_val.s,
    script->len);
  }
 }
 cpl_dbf.free_result( db_hdl, res);
 return 1;
error:
 if (res)
  cpl_dbf.free_result( db_hdl, res);
 script->s = 0;
 script->len = 0;
 return -1;
}

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

variable_types:
domain
struct _str *

variable_types:
script
struct _str *

variable_types:
key
struct _str *

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; } [2]

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: n int

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


decompiled_code:
__int64 bdb_mod_destroy()
{
km_destroy();
return bdblib_destroy();
}

canonical_decompiled_code:
__int64 func0()
{
km_destroy();
return bdblib_destroy();
}

original_code:
static void bdb_mod_destroy(void)
{
 km_destroy();
 bdblib_destroy();
}

canonical_original_code:
static void bdb_mod_destroy()
{
 km_destroy();
 bdblib_destroy();
}


decompiled_code:
__int64 bdb_mod_init()
{
__int64 result; // rax
int v1[6]; // [rsp+0h] [rbp-18h] BYREF

v1[0] = 0x400000;
v1[1] = auto_reload;
v1[2] = log_enable;
v1[3] = journal_roll_interval;
if ( (unsigned int)bdblib_init(v1) )
result = 0xFFFFFFFFLL;
else
result = km_mod_init();
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
int v1[6]; // [rsp+0h] [rbp-18h] BYREF

v1[0] = 0x400000;
v1[1] = auto_reload;
v1[2] = log_enable;
v1[3] = journal_roll_interval;
if ( (unsigned int)bdblib_init(v1) )
result = 0xFFFFFFFFLL;
else
result = km_mod_init();
return result;
}

original_code:
static int bdb_mod_init(void)
{
 bdb_params_t p;
 p.auto_reload = auto_reload;
 p.log_enable = log_enable;
 p.cache_size = (4 * 1024 * 1024);
 p.journal_roll_interval = journal_roll_interval;
 if(bdblib_init(&p))
  return -1;
 return km_mod_init();
}

canonical_original_code:
static int bdb_mod_init()
{
 struct _bdb_params p;
 p.auto_reload = auto_reload;
 p.log_enable = log_enable;
 p.cache_size = (4 * 1024 * 1024);
 p.journal_roll_interval = journal_roll_interval;
 if(bdblib_init(&p))
  return -1;
 return km_mod_init();
}

variable_types: struct _bdb_params { unsigned int cache_size; int auto_reload; int log_enable; int journal_roll_interval; }


decompiled_code:
__int64 mod_register()
{
return (unsigned int)((int)db_api_init() >> 31);
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)((int)db_api_init() >> 31);
}

original_code:
int mod_register(char *path, int *dlflags, void *p1, void *p2)
{
 if(db_api_init()<0)
  return -1;
 return 0;
}

variable_types:
path
char *

variable_types:
dlflags
int *


decompiled_code:
__int64 __fastcall bdb_fld_free(__int64 a1, __int64 a2)
{
db_drv_free(a2);
if ( *(_QWORD *)(a2 + 32) )
qm_free(mem_block);
if ( *(_QWORD *)(a2 + 8) )
qm_free(mem_block);
return qm_free(mem_block);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
db_drv_free(a2);
if ( *(_QWORD *)(a2 + 32) )
qm_free(mem_block);
if ( *(_QWORD *)(a2 + 8) )
qm_free(mem_block);
return qm_free(mem_block);
}

original_code:
static void bdb_fld_free(db_fld_t* fld, bdb_fld_t* payload)
{
 db_drv_free(&payload->gen);
 if (payload->buf.s) qm_free(mem_block, (payload->buf.s));
 if (payload->name) qm_free(mem_block, (payload->name));
 qm_free(mem_block, (payload));
}

canonical_original_code:
static void bdb_fld_free(struct db_fld *fld, struct _bdb_fld *payload)
{
 db_drv_free(&payload->gen);
 if (payload->buf.s) qm_free(mem_block, (payload->buf.s));
 if (payload->name) qm_free(mem_block, (payload->name));
 qm_free(mem_block, (payload));
}

variable_types: struct db_fld { struct db_gen { struct { struct db_gen *stqe_next; } next; struct db_drv { void (*free)(struct db_gen *db_struct, struct db_drv *payload); } *data[16]; } gen; char *name; enum db_fld_type { DB_NONE=0, DB_INT=1, DB_FLOAT=2, DB_DOUBLE=3, DB_CSTR=4, DB_STR=5, DB_DATETIME=6, DB_BLOB=7, DB_BITMAP=8 } type; unsigned int flags; union db_fld_val { int int4; float flt; double dbl; long time; char *cstr; struct _str { char *s; int len; } lstr; struct _str blob; unsigned int bitmap; long long int8; } v; enum db_fld_op { DB_EQ=0, DB_NE=1, DB_LT=2, DB_GT=3, DB_LEQ=4, DB_GEQ=5 } op; } *

variable_types: struct _bdb_fld { struct db_drv gen; char *name; int is_null; unsigned long length; struct _str buf; int col_pos; } *

user_defined_types: struct db_fld { struct db_gen gen; char *name; enum db_fld_type type; unsigned int flags; union db_fld_val v; enum db_fld_op op; }

user_defined_types: struct db_gen { struct { struct db_gen *stqe_next; } next; struct db_drv *data[16]; }

user_defined_types: union db_fld_val { int int4; float flt; double dbl; long time; char *cstr; struct _str lstr; struct _str blob; unsigned int bitmap; long long int8; }


decompiled_code:
__int64 __fastcall bdb_fld(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 result; // rax
int v4; // er8
const char *v5; // r12
struct _IO_FILE *v6; // rdi
__int64 v7; // [rsp-10h] [rbp-28h]
unsigned int v8; // [rsp-8h] [rbp-20h]

v1 = qm_malloc(mem_block, 56LL);
if ( v1 )
{
*(_QWORD *)(v1 + 48) = 0LL;
v2 = v1;
*(_DWORD *)(v1 + 48) = -1;
*(_OWORD *)v1 = 0LL;
*(_OWORD *)(v1 + 16) = 0LL;
*(_OWORD *)(v1 + 32) = 0LL;
if ( (int)db_drv_init(v1, bdb_fld_free) < 0 )
{
qm_free(mem_block);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
*(_QWORD *)(a1 + 8LL * db_payload_idx + 8) = v2;
}
}
else
{
v4 = get_debug_level("db_berkeley", 11LL);
result = 0xFFFFFFFFLL;
if ( v4 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v5 = (const char *)*((_QWORD *)&log_level_info + 8);
v8 = my_pid();
v6 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): oracle: No memory left\n",
process_no,
v8,
v5,
"db_berkeley [bdb_fld.c:64]: ",
"bdb_fld");
if ( log_color )
dprint_color_reset(v6, "%2d(%d) %s: %s%s(): oracle: No memory left\n", v7);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): oracle: No memory left\n",
*((const char **)&log_level_info + 8),
"db_berkeley [bdb_fld.c:64]: ",
"bdb_fld");
}
result = 0xFFFFFFFFLL;
--dprint_crit;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 result; // rax
int v4; // er8
const char *v5; // r12
struct _IO_FILE *v6; // rdi
__int64 v7; // [rsp-10h] [rbp-28h]
unsigned int v8; // [rsp-8h] [rbp-20h]

v1 = qm_malloc(mem_block, 56LL);
if ( v1 )
{
*(_QWORD *)(v1 + 48) = 0LL;
v2 = v1;
*(_DWORD *)(v1 + 48) = -1;
*(_OWORD *)v1 = 0LL;
*(_OWORD *)(v1 + 16) = 0LL;
*(_OWORD *)(v1 + 32) = 0LL;
if ( (int)db_drv_init(v1, bdb_fld_free) < 0 )
{
qm_free(mem_block);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
*(_QWORD *)(a1 + 8LL * db_payload_idx + 8) = v2;
}
}
else
{
v4 = get_debug_level("db_berkeley", 11LL);
result = 0xFFFFFFFFLL;
if ( v4 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v5 = (const char *)*((_QWORD *)&log_level_info + 8);
v8 = my_pid();
v6 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): oracle: No memory left\n",
process_no,
v8,
v5,
"db_berkeley [bdb_fld.c:64]: ",
"bdb_fld");
if ( log_color )
dprint_color_reset(v6, "%2d(%d) %s: %s%s(): oracle: No memory left\n", v7);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): oracle: No memory left\n",
*((const char **)&log_level_info + 8),
"db_berkeley [bdb_fld.c:64]: ",
"bdb_fld");
}
result = 0xFFFFFFFFLL;
--dprint_crit;
}
}
return result;
}

original_code:
int bdb_fld(db_fld_t* fld, char* table)
{
 bdb_fld_t *res;
 res = (bdb_fld_t*)qm_malloc(mem_block, (sizeof(bdb_fld_t)));
 if (res == ((void *)0)) {
  do { if (get_debug_level("db_berkeley", (sizeof("db_berkeley")-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(): " "oracle: No memory left\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("db_berkeley" " [" "bdb_fld.c" ":" "64" "]: ") , __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(): " "oracle: No memory left\n", (log_level_info[((-1)) - (-5)].name), ("db_berkeley" " [" "bdb_fld.c" ":" "64" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "oracle: No memory left\n", process_no, my_pid(), ("db_berkeley" " [" "bdb_fld.c" ":" "64" "]: ") , __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(): " "oracle: No memory left\n", ("db_berkeley" " [" "bdb_fld.c" ":" "64" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "oracle: No memory left\n", ("db_berkeley" " [" "bdb_fld.c" ":" "64" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 memset(res, '\0', sizeof(bdb_fld_t));
 res->col_pos = -1;
 if (db_drv_init(&res->gen, bdb_fld_free) < 0) goto error;
 do { ((struct db_gen*)(fld))->data[db_payload_idx] = (struct db_drv*)(res); } while(0);
 return 0;
error:
 if (res) qm_free(mem_block, (res));
 return -1;
}

canonical_original_code:
int bdb_fld(struct db_fld *fld, char *table)
{
 struct _bdb_fld *res;
 res = (struct _bdb_fld *)qm_malloc(mem_block, (sizeof(bdb_fld_t)));
 if (res == ((void *)0)) {
  do { if (get_debug_level("db_berkeley", (sizeof("db_berkeley")-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(): " "oracle: No memory left\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("db_berkeley" " [" "bdb_fld.c" ":" "64" "]: ") , __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(): " "oracle: No memory left\n", (log_level_info[((-1)) - (-5)].name), ("db_berkeley" " [" "bdb_fld.c" ":" "64" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "oracle: No memory left\n", process_no, my_pid(), ("db_berkeley" " [" "bdb_fld.c" ":" "64" "]: ") , __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(): " "oracle: No memory left\n", ("db_berkeley" " [" "bdb_fld.c" ":" "64" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "oracle: No memory left\n", ("db_berkeley" " [" "bdb_fld.c" ":" "64" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 memset(res, '\0', sizeof(bdb_fld_t));
 res->col_pos = -1;
 if (db_drv_init(&res->gen, bdb_fld_free) < 0) goto error;
 do { ((struct db_gen *)(fld))->data[db_payload_idx] = (struct db_drv *)(res); } while(0);
 return 0;
error:
 if (res) qm_free(mem_block, (res));
 return -1;
}

variable_types:
table
char *

variable_types: struct _bdb_fld { struct db_drv { void (*free)(struct db_gen { struct { struct db_gen *stqe_next; } next; struct db_drv *data[16]; } *db_struct, struct db_drv *payload); } gen; char *name; int is_null; unsigned long length; struct _str { char *s; int len; } buf; int col_pos; } *

user_defined_types: struct _bdb_fld { struct db_drv gen; char *name; int is_null; unsigned long length; struct _str buf; int col_pos; }

user_defined_types: struct db_drv { void (*free)(struct db_gen *db_struct, struct db_drv *payload); }

user_defined_types: enum db_fld_type { DB_NONE=0, DB_INT=1, DB_FLOAT=2, DB_DOUBLE=3, DB_CSTR=4, DB_STR=5, DB_DATETIME=6, DB_BLOB=7, DB_BITMAP=8 }

user_defined_types: enum db_fld_op { DB_EQ=0, DB_NE=1, DB_LT=2, DB_GT=3, DB_LEQ=4, DB_GEQ=5 }


decompiled_code:
__int64 ul_unlock_locks()
{
__int64 *v0; // rsi
unsigned int v1; // ebx
__int64 v2; // rcx
__int64 result; // rax

v0 = ul_locks;
if ( ul_locks && ul_locks_no )
{
v1 = 0;
while ( 1 )
{
v2 = v1++;
result = futex_release((volatile __int32 *)(v0[1] + 4 * v2));
if ( ul_locks_no <= v1 )
break;
v0 = ul_locks;
}
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 *v0; // rsi
unsigned int v1; // ebx
__int64 v2; // rcx
__int64 result; // rax

v0 = ul_locks;
if ( ul_locks && ul_locks_no )
{
v1 = 0;
while ( 1 )
{
v2 = v1++;
result = func1((volatile __int32 *)(v0[1] + 4 * v2));
if ( ul_locks_no <= v1 )
break;
v0 = ul_locks;
}
}
return result;
}

original_code:
void ul_unlock_locks(void)
{
 unsigned int i;
 if (ul_locks==0)
  return;
 for (i=0;i<ul_locks_no;i++) {
  futex_release(&ul_locks->locks[i]);
 };
}

canonical_original_code:
void ul_unlock_locks()
{
 unsigned int i;
 if (ul_locks==0)
  return;
 for (i=0;i<ul_locks_no;i++) {
  futex_release(&ul_locks->locks[i]);
 };
}

variable_types:
i
unsigned int


decompiled_code:
__int64 ul_destroy_locks()
{
__int64 result; // rax

if ( ul_locks )
{
futex_get(mem_lock);
qm_free(shm_block, ul_locks);
result = futex_release(mem_lock);
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax

if ( ul_locks )
{
func3(mem_lock);
qm_free(shm_block, ul_locks);
result = func1(mem_lock);
}
return result;
}

original_code:
void ul_destroy_locks(void)
{
 if (ul_locks !=0){
  ;
  do { futex_get(mem_lock); qm_free(shm_block, ((void*)ul_locks)); futex_release(mem_lock); }while(0);
 };
}

canonical_original_code:
void ul_destroy_locks()
{
 if (ul_locks !=0){
  ;
  do { futex_get(mem_lock); qm_free(shm_block, ((void *)ul_locks)); futex_release(mem_lock); }while(0);
 };
}