decompiled_code:
__int64 init_pkg_mallocs()
{
size_t v0; // rbp
__int64 v1; // rax
const char *v3; // rbp
unsigned int v4; // eax
struct _IO_FILE *v5; // rdi
__int64 v6; // [rsp-10h] [rbp-18h]

v0 = pkg_mem_size;
if ( !pkg_mem_size )
{
pkg_mem_size = 0x400000LL;
v0 = 0x400000LL;
}
mem_pool = malloc(v0);
if ( mem_pool )
{
v1 = qm_malloc_init(mem_pool, v0);
mem_block = v1;
}
else
{
v1 = mem_block;
}
if ( v1 )
return 0LL;
if ( (int)get_debug_level("core", 4LL) >= -2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(4294967294LL);
v3 = (const char *)*((_QWORD *)&log_level_info + 6);
v4 = my_pid();
v5 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): could not initialize memory pool\n",
process_no,
v4,
v3,
"<core> [mem/mem.c:88]: ",
"init_pkg_mallocs");
if ( log_color )
dprint_color_reset(v5, "%2d(%d) %s: %s%s(): could not initialize memory pool\n", v6);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 14) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): could not initialize memory pool\n",
*((const char **)&log_level_info + 6),
"<core> [mem/mem.c:88]: ",
"init_pkg_mallocs");
}
--dprint_crit;
}
fprintf(stderr, "Too much pkg memory demanded: %ld bytes\n", pkg_mem_size);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
size_t v0; // rbp
__int64 v1; // rax
const char *v3; // rbp
unsigned int v4; // eax
struct _IO_FILE *v5; // rdi
__int64 v6; // [rsp-10h] [rbp-18h]

v0 = pkg_mem_size;
if ( !pkg_mem_size )
{
pkg_mem_size = 0x400000LL;
v0 = 0x400000LL;
}
mem_pool = malloc(v0);
if ( mem_pool )
{
v1 = qm_malloc_init(mem_pool, v0);
mem_block = v1;
}
else
{
v1 = mem_block;
}
if ( v1 )
return 0LL;
if ( (int)get_debug_level("core", 4LL) >= -2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(4294967294LL);
v3 = (const char *)*((_QWORD *)&log_level_info + 6);
v4 = my_pid();
v5 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): could not initialize memory pool\n",
process_no,
v4,
v3,
"<core> [mem/mem.c:88]: ",
"init_pkg_mallocs");
if ( log_color )
dprint_color_reset(v5, "%2d(%d) %s: %s%s(): could not initialize memory pool\n", v6);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 14) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): could not initialize memory pool\n",
*((const char **)&log_level_info + 6),
"<core> [mem/mem.c:88]: ",
"init_pkg_mallocs");
}
--dprint_crit;
}
fprintf(stderr, "Too much pkg memory demanded: %ld bytes\n", pkg_mem_size);
return 0xFFFFFFFFLL;
}

original_code:
int init_pkg_mallocs(void)
{
  if (pkg_mem_size == 0)
   pkg_mem_size = 4*1024*1024;
  mem_pool = malloc(pkg_mem_size);
  if (mem_pool)
   mem_block=qm_malloc_init(mem_pool, pkg_mem_size);
 if (mem_block==0){
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-2)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-2)) >= -5) && (((-2)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-2)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "could not initialize memory pool\n", process_no, my_pid(), (log_level_info[((-2)) - (-5)].name), ("<core> [" "mem/mem.c" ":" "88" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-2)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "could not initialize memory pool\n", (log_level_info[((-2)) - (-5)].name), ("<core> [" "mem/mem.c" ":" "88" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-2)); fprintf(stderr, "%2d(%d) %s" "%s(): " "could not initialize memory pool\n", process_no, my_pid(), ("<core> [" "mem/mem.c" ":" "88" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-2))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not initialize memory pool\n", ("<core> [" "mem/mem.c" ":" "88" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not initialize memory pool\n", ("<core> [" "mem/mem.c" ":" "88" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  fprintf(stderr, "Too much pkg memory demanded: %ld bytes\n",
      pkg_mem_size);
  return -1;
 }
 return 0;
}

canonical_original_code:
int init_pkg_mallocs()
{
  if (pkg_mem_size == 0)
   pkg_mem_size = 4*1024*1024;
  mem_pool = malloc(pkg_mem_size);
  if (mem_pool)
   mem_block=qm_malloc_init(mem_pool, pkg_mem_size);
 if (mem_block==0){
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-2)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-2)) >= -5) && (((-2)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-2)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "could not initialize memory pool\n", process_no, my_pid(), (log_level_info[((-2)) - (-5)].name), ("<core> [" "mem/mem.c" ":" "88" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-2)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "could not initialize memory pool\n", (log_level_info[((-2)) - (-5)].name), ("<core> [" "mem/mem.c" ":" "88" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-2)); fprintf(stderr, "%2d(%d) %s" "%s(): " "could not initialize memory pool\n", process_no, my_pid(), ("<core> [" "mem/mem.c" ":" "88" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-2))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not initialize memory pool\n", ("<core> [" "mem/mem.c" ":" "88" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not initialize memory pool\n", ("<core> [" "mem/mem.c" ":" "88" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  fprintf(stderr, "Too much pkg memory demanded: %ld bytes\n",
      pkg_mem_size);
  return -1;
 }
 return 0;
}


repo: virtualolson/who

decompiled_code:
void destroy_pkg_mallocs()
{
if ( mem_pool )
{
free(mem_pool);
mem_pool = 0LL;
}
}

canonical_decompiled_code:
void func1()
{
if ( mem_pool )
{
free(mem_pool);
mem_pool = 0LL;
}
}

original_code:
void destroy_pkg_mallocs(void)
{
  if (mem_pool) {
   free(mem_pool);
   mem_pool = 0;
  }
}

canonical_original_code:
void destroy_pkg_mallocs()
{
  if (mem_pool) {
   free(mem_pool);
   mem_pool = 0;
  }
}

return_type: void


decompiled_code:
__int64 init_shm_mallocs()
{
const char *v1; // rbx
unsigned int v2; // eax
struct _IO_FILE *v3; // rdi
__int64 v4; // [rsp-10h] [rbp-18h]

if ( (int)shm_mem_init() >= 0 )
return 0LL;
if ( (int)get_debug_level("core", 4LL) >= -2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(4294967294LL);
v1 = (const char *)*((_QWORD *)&log_level_info + 6);
v2 = my_pid();
v3 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): could not initialize shared memory pool, exiting...\n",
process_no,
v2,
v1,
"<core> [mem/mem.c:125]: ",
"init_shm_mallocs");
if ( log_color )
dprint_color_reset(v3, "%2d(%d) %s: %s%s(): could not initialize shared memory pool, exiting...\n", v4);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 14) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): could not initialize shared memory pool, exiting...\n",
*((const char **)&log_level_info + 6),
"<core> [mem/mem.c:125]: ",
"init_shm_mallocs");
}
--dprint_crit;
}
fprintf(stderr, "Too much shared memory demanded: %ld\n", shm_mem_size);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func2()
{
const char *v1; // rbx
unsigned int v2; // eax
struct _IO_FILE *v3; // rdi
__int64 v4; // [rsp-10h] [rbp-18h]

if ( (int)shm_mem_init() >= 0 )
return 0LL;
if ( (int)get_debug_level("core", 4LL) >= -2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(4294967294LL);
v1 = (const char *)*((_QWORD *)&log_level_info + 6);
v2 = my_pid();
v3 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): could not initialize shared memory pool, exiting...\n",
process_no,
v2,
v1,
"<core> [mem/mem.c:125]: ",
"init_shm_mallocs");
if ( log_color )
dprint_color_reset(v3, "%2d(%d) %s: %s%s(): could not initialize shared memory pool, exiting...\n", v4);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 14) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): could not initialize shared memory pool, exiting...\n",
*((const char **)&log_level_info + 6),
"<core> [mem/mem.c:125]: ",
"init_shm_mallocs");
}
--dprint_crit;
}
fprintf(stderr, "Too much shared memory demanded: %ld\n", shm_mem_size);
return 0xFFFFFFFFLL;
}

original_code:
int init_shm_mallocs(int force_alloc)
{
 if (shm_mem_init(force_alloc)<0) {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-2)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-2)) >= -5) && (((-2)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-2)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "could not initialize shared memory pool, exiting...\n", process_no, my_pid(), (log_level_info[((-2)) - (-5)].name), ("<core> [" "mem/mem.c" ":" "125" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-2)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "could not initialize shared memory pool, exiting...\n", (log_level_info[((-2)) - (-5)].name), ("<core> [" "mem/mem.c" ":" "125" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-2)); fprintf(stderr, "%2d(%d) %s" "%s(): " "could not initialize shared memory pool, exiting...\n", process_no, my_pid(), ("<core> [" "mem/mem.c" ":" "125" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-2))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not initialize shared memory pool, exiting...\n", ("<core> [" "mem/mem.c" ":" "125" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not initialize shared memory pool, exiting...\n", ("<core> [" "mem/mem.c" ":" "125" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   fprintf(stderr, "Too much shared memory demanded: %ld\n",
   shm_mem_size );
  return -1;
 }
 return 0;
}

return_type: int

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


decompiled_code:
__int64 __fastcall ws_close_fixup(__int64 a1, int a2)
{
if ( a2 == 2 )
return fixup_spve_null(a1, 1LL);
if ( (a2 & 0xFFFFFFFD) == 1 )
return fixup_var_int_1();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
if ( a2 == 2 )
return fixup_spve_null(a1, 1LL);
if ( (a2 & 0xFFFFFFFD) == 1 )
return fixup_var_int_1();
return 0LL;
}

original_code:
static int ws_close_fixup(void** param, int param_no)
{
 switch(param_no) {
 case 1:
 case 3:
  return fixup_var_int_1(param, 1);
 case 2:
  return fixup_spve_null(param, 1);
 default:
  return 0;
 }
}

canonical_original_code:
static int ws_close_fixup(void **param, int param_no)
{
 switch(param_no) {
 case 1:
 case 3:
  return fixup_var_int_1(param, 1);
 case 2:
  return fixup_spve_null(param, 1);
 default:
  return 0;
 }
}

variable_types:
param
void **


decompiled_code:
__int64 __fastcall child_init(int a1)
{
__int64 result; // rax
int v2; // ebx
int v3; // edx
const char *v4; // r12
unsigned int v5; // eax
struct _IO_FILE *v6; // rdi

if ( a1 || !ws_keepalive_mechanism || ws_keepalive_processes <= 0 )
return 0LL;
v2 = 0;
while ( (int)fork_sync_timer(
0xFFFFFFFFLL,
"WEBSOCKET KEEPALIVE",
1LL,
&ws_keepalive,
0LL,
(unsigned int)ws_keepalive_interval) >= 0 )
{
if ( ++v2 >= ws_keepalive_processes )
return 0LL;
}
v3 = get_debug_level("websocket", 9LL);
result = 0xFFFFFFFFLL;
if ( v3 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v4 = (const char *)*((_QWORD *)&log_level_info + 8);
v5 = my_pid();
v6 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): starting keepalive process\n",
process_no,
v5,
v4,
"websocket [ws_mod.c:313]: ",
"child_init");
if ( log_color )
((void (__fastcall *)(struct _IO_FILE *, const char *))dprint_color_reset)(
v6,
"%2d(%d) %s: %s%s(): starting keepalive process\n");
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): starting keepalive process\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:313]: ",
"child_init");
}
result = 0xFFFFFFFFLL;
--dprint_crit;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax
int v2; // ebx
int v3; // edx
const char *v4; // r12
unsigned int v5; // eax
struct _IO_FILE *v6; // rdi

if ( a1 || !ws_keepalive_mechanism || ws_keepalive_processes <= 0 )
return 0LL;
v2 = 0;
while ( (int)fork_sync_timer(
0xFFFFFFFFLL,
"WEBSOCKET KEEPALIVE",
1LL,
&ws_keepalive,
0LL,
(unsigned int)ws_keepalive_interval) >= 0 )
{
if ( ++v2 >= ws_keepalive_processes )
return 0LL;
}
v3 = get_debug_level("websocket", 9LL);
result = 0xFFFFFFFFLL;
if ( v3 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v4 = (const char *)*((_QWORD *)&log_level_info + 8);
v5 = my_pid();
v6 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): starting keepalive process\n",
process_no,
v5,
v4,
"websocket [ws_mod.c:313]: ",
"child_init");
if ( log_color )
((void (__fastcall *)(struct _IO_FILE *, const char *))dprint_color_reset)(
v6,
"%2d(%d) %s: %s%s(): starting keepalive process\n");
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): starting keepalive process\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:313]: ",
"child_init");
}
result = 0xFFFFFFFFLL;
--dprint_crit;
}
return result;
}

original_code:
static int child_init(int rank)
{
 int i;
 if (rank == -127 || rank == -4)
  return 0;
 if (rank == 0
  && ws_keepalive_mechanism != KEEPALIVE_MECHANISM_NONE)
 {
  for (i = 0; i < ws_keepalive_processes; i++)
  {
   if (fork_sync_timer(-1, "WEBSOCKET KEEPALIVE",
      1, ws_keepalive, ((void *)0),
      ws_keepalive_interval) < 0)
   {
    do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "starting keepalive process\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "313" "]: ") , __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(): " "starting keepalive process\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "313" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "starting keepalive process\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "313" "]: ") , __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(): " "starting keepalive process\n", ("websocket" " [" "ws_mod.c" ":" "313" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "starting keepalive process\n", ("websocket" " [" "ws_mod.c" ":" "313" "]: ") , __func__); } } (dprint_crit--); } } while(0);
    return -1;
   }
  }
 }
 return 0;
}

variable_types: rank int

variable_types: i int


destroy

decompiled_code:
// attributes: thunk
__int64 destroy()
{
return wsconn_destroy();
}

canonical_decompiled_code:
__int64 func1()
{
return wsconn_destroy();
}

original_code:
static void destroy(void)
{
 wsconn_destroy();
}

canonical_original_code:
static void destroy()
{
 wsconn_destroy();
}


decompiled_code:
__int64 mod_init()
{
int v0; // eax
unsigned int v1; // eax
unsigned int v2; // er12
bool v4; // zf
__int64 v5; // rsi
__int64 v6; // rsi
const char *v7; // r12
struct _IO_FILE *v8; // rdi
__int64 v9; // r12
__int64 v10; // rax
const char *v11; // r9
__int64 v12; // rcx
__int64 v13; // r8
const char *v14; // rsi
__int64 v15; // rdx
struct _IO_FILE *v16; // rdi
__int64 v17; // rdx
__int64 v18; // r12
__int64 v19; // rax
__int64 v20; // r12
__int64 v21; // rax
__int64 v22; // r12
__int64 v23; // rax
__int64 v24; // r12
__int64 v25; // rax
__int64 v26; // r12
unsigned int v27; // eax
__int64 v28; // r12
unsigned int v29; // eax
__int64 v30; // r10
__int64 v31; // r12
unsigned int v32; // eax
const char *v33; // rsi
__int64 v34; // rdx
__int64 v35; // r12
__int64 v36; // rcx
__int64 v37; // r12
unsigned int v38; // eax
__int64 v39; // r12
unsigned int v40; // eax
__int64 v41; // r8
__int64 v42; // [rsp-10h] [rbp-28h]
__int64 v43; // [rsp-10h] [rbp-28h]
unsigned int v44; // [rsp-8h] [rbp-20h]
__int64 v45; // [rsp-8h] [rbp-20h]

if ( (unsigned int)sl_load_api_constprop_0() )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
v5 = (unsigned int)++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v26 = *((_QWORD *)&log_level_info + 8);
v27 = my_pid();
v11 = "websocket [ws_mod.c:175]: ";
v45 = v5;
v12 = v27;
v13 = v26;
v14 = "%2d(%d) %s: %s%s(): binding to SL\n";
v15 = process_no;
goto LABEL_94;
}
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): binding to SL\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:175]: ",
"mod_init");
goto LABEL_43;
}
if ( (unsigned int)sr_event_register_cb(10LL, &ws_frame_receive) )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v9 = *((_QWORD *)&log_level_info + 8);
v10 = my_pid();
v11 = "websocket [ws_mod.c:181]: ";
v12 = (unsigned int)v10;
v45 = v10;
v13 = v9;
v14 = "%2d(%d) %s: %s%s(): registering WebSocket receive call-back\n";
v15 = process_no;
goto LABEL_94;
}
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): registering WebSocket receive call-back\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:181]: ",
"mod_init");
goto LABEL_43;
}
if ( (unsigned int)sr_event_register_cb(11LL, &ws_frame_transmit) )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v18 = *((_QWORD *)&log_level_info + 8);
v19 = my_pid();
v11 = "websocket [ws_mod.c:187]: ";
v12 = (unsigned int)v19;
v13 = v18;
v14 = "%2d(%d) %s: %s%s(): registering WebSocket transmit call-back\n";
v45 = v19;
v15 = process_no;
goto LABEL_94;
}
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): registering WebSocket transmit call-back\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:187]: ",
"mod_init");
goto LABEL_43;
}
if ( (unsigned int)register_module_stats(exports, &stats) )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v20 = *((_QWORD *)&log_level_info + 8);
v21 = my_pid();
v11 = "websocket [ws_mod.c:193]: ";
v12 = (unsigned int)v21;
v13 = v20;
v14 = "%2d(%d) %s: %s%s(): registering core statistics\n";
v45 = v21;
v15 = process_no;
goto LABEL_94;
}
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): registering core statistics\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:193]: ",
"mod_init");
goto LABEL_43;
}
if ( (unsigned int)register_mi_mod(exports, &mi_cmds) )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v28 = *((_QWORD *)&log_level_info + 8);
v29 = my_pid();
v11 = "websocket [ws_mod.c:199]: ";
v45 = v30;
v12 = v29;
v13 = v28;
v14 = "%2d(%d) %s: %s%s(): registering MI commands\n";
v15 = process_no;
goto LABEL_94;
}
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): registering MI commands\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:199]: ",
"mod_init");
LABEL_43:
--dprint_crit;
LABEL_44:
wsconn_destroy();
return (unsigned int)-1;
}
if ( (int)wsconn_init() < 0 )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): initialising WebSocket connections table\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:205]: ",
"mod_init");
goto LABEL_43;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v39 = *((_QWORD *)&log_level_info + 8);
v40 = my_pid();
v11 = "websocket [ws_mod.c:205]: ";
v45 = v41;
v12 = v40;
v13 = v39;
v14 = "%2d(%d) %s: %s%s(): initialising WebSocket connections table\n";
v15 = process_no;
goto LABEL_94;
}
if ( ws_ping_application_data )
{
v0 = strlen(ws_ping_application_data);
*((_DWORD *)&ws_ping_application_data + 2) = v0;
}
else
{
v0 = *((_DWORD *)&ws_ping_application_data + 2);
}
if ( (unsigned int)(v0 - 1) > 0x7C )
{
*((_DWORD *)&ws_ping_application_data + 2) = 36;
ws_ping_application_data = "kamailio (4.1.0-dev9 (x86_64/linux))";
}
if ( ws_keepalive_mechanism )
{
if ( (unsigned int)(ws_keepalive_timeout - 1) > 0xE0F )
ws_keepalive_timeout = 180;
if ( (unsigned int)(ws_keepalive_mechanism - 1) > 1 )
ws_keepalive_mechanism = 1;
if ( (unsigned int)(ws_keepalive_interval - 1) > 0x3B )
ws_keepalive_interval = 1;
if ( (unsigned int)(ws_keepalive_processes - 1) > 0xF )
ws_keepalive_processes = 1;
register_sync_timers();
}
v1 = ws_sub_protocols;
if ( (ws_sub_protocols & 2) != 0 )
{
v4 = (unsigned int)sr_event_enabled(9LL) == 0;
v1 = ws_sub_protocols;
if ( v4 )
{
v1 = ws_sub_protocols & 0xFFFFFFFD;
ws_sub_protocols &= 0xFFFFFFFD;
}
}
if ( (v1 & 3) == 0 )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
v6 = (unsigned int)++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): no sub-protocols enabled\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:251]: ",
"mod_init");
goto LABEL_43;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v37 = *((_QWORD *)&log_level_info + 8);
v38 = my_pid();
v11 = "websocket [ws_mod.c:251]: ";
v45 = v6;
v12 = v38;
v13 = v37;
v14 = "%2d(%d) %s: %s%s(): no sub-protocols enabled\n";
v15 = process_no;
goto LABEL_94;
}
if ( (v1 & 0xFFFFFFFC) != 0 )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): unrecognised sub-protocols enabled\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:257]: ",
"mod_init");
goto LABEL_43;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v22 = *((_QWORD *)&log_level_info + 8);
v23 = my_pid();
v11 = "websocket [ws_mod.c:257]: ";
v12 = (unsigned int)v23;
v13 = v22;
v14 = "%2d(%d) %s: %s%s(): unrecognised sub-protocols enabled\n";
v45 = v23;
v15 = process_no;
goto LABEL_94;
}
if ( ws_cors_mode > 2u )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): bad value for cors_mode\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:263]: ",
"mod_init");
goto LABEL_43;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v24 = *((_QWORD *)&log_level_info + 8);
v25 = my_pid();
v11 = "websocket [ws_mod.c:263]: ";
v12 = (unsigned int)v25;
v13 = v24;
v14 = "%2d(%d) %s: %s%s(): bad value for cors_mode\n";
v45 = v25;
v15 = process_no;
LABEL_94:
v16 = stderr;
fprintf(stderr, v14, v15, v12, v13, v11, "mod_init", v45);
if ( log_color )
dprint_color_reset(v16, v14, v17);
goto LABEL_43;
}
v2 = cfg_declare("websocket", &ws_cfg_def, &default_ws_cfg, 8LL, &ws_cfg);
if ( v2 )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): declaring configuration\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:270]: ",
"mod_init");
LABEL_70:
v2 = -1;
--dprint_crit;
return v2;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v31 = *((_QWORD *)&log_level_info + 8);
v32 = my_pid();
v33 = "%2d(%d) %s: %s%s(): declaring configuration\n";
fprintf(
stderr,
"%2d(%d) %s: %s%s(): declaring configuration\n",
process_no,
v32,
v31,
"websocket [ws_mod.c:270]: ",
"mod_init");
LABEL_117:
if ( log_color )
dprint_color_reset(v43, v33, v34);
goto LABEL_70;
}
return (unsigned int)-1;
}
*ws_cfg = ws_keepalive_timeout;
if ( !find_module_by_name("xhttp") )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): \"xhttp\" must be loaded to use WebSocket.\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:277]: ",
"mod_init");
goto LABEL_70;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v35 = *((_QWORD *)&log_level_info + 8);
v33 = "%2d(%d) %s: %s%s(): \"xhttp\" must be loaded to use WebSocket.\n";
v36 = (unsigned int)my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): \"xhttp\" must be loaded to use WebSocket.\n",
process_no,
v36,
v35,
"websocket [ws_mod.c:277]: ",
"mod_init");
goto LABEL_117;
}
return (unsigned int)-1;
}
if ( (ws_sub_protocols & 1) != 0
&& !find_module_by_name("nathelper")
&& !find_module_by_name("outbound")
&& (int)get_debug_level("websocket", 9LL) >= 0
&& !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0LL);
v7 = (const char *)*((_QWORD *)&log_level_info + 10);
v44 = my_pid();
v8 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): neither \"nathelper\" nor \"outbound\" modules are loaded. At least one of these is required"
" for correct routing of SIP over WebSocket.\n",
process_no,
v44,
v7,
"websocket [ws_mod.c:285]: ",
"mod_init");
if ( log_color )
dprint_color_reset(
v8,
"%2d(%d) %s: %s%s(): neither \"nathelper\" nor \"outbound\" modules are loaded. At least one of these is requir"
"ed for correct routing of SIP over WebSocket.\n",
v42);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 22) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): neither \"nathelper\" nor \"outbound\" modules are loaded. At least one of these is required for cor"
"rect routing of SIP over WebSocket.\n",
*((const char **)&log_level_info + 10),
"websocket [ws_mod.c:285]: ",
"mod_init");
}
v2 = 0;
--dprint_crit;
}
return v2;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
unsigned int v1; // eax
unsigned int v2; // er12
bool v4; // zf
__int64 v5; // rsi
__int64 v6; // rsi
const char *v7; // r12
struct _IO_FILE *v8; // rdi
__int64 v9; // r12
__int64 v10; // rax
const char *v11; // r9
__int64 v12; // rcx
__int64 v13; // r8
const char *v14; // rsi
__int64 v15; // rdx
struct _IO_FILE *v16; // rdi
__int64 v17; // rdx
__int64 v18; // r12
__int64 v19; // rax
__int64 v20; // r12
__int64 v21; // rax
__int64 v22; // r12
__int64 v23; // rax
__int64 v24; // r12
__int64 v25; // rax
__int64 v26; // r12
unsigned int v27; // eax
__int64 v28; // r12
unsigned int v29; // eax
__int64 v30; // r10
__int64 v31; // r12
unsigned int v32; // eax
const char *v33; // rsi
__int64 v34; // rdx
__int64 v35; // r12
__int64 v36; // rcx
__int64 v37; // r12
unsigned int v38; // eax
__int64 v39; // r12
unsigned int v40; // eax
__int64 v41; // r8
__int64 v42; // [rsp-10h] [rbp-28h]
__int64 v43; // [rsp-10h] [rbp-28h]
unsigned int v44; // [rsp-8h] [rbp-20h]
__int64 v45; // [rsp-8h] [rbp-20h]

if ( (unsigned int)func3() )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
v5 = (unsigned int)++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v26 = *((_QWORD *)&log_level_info + 8);
v27 = my_pid();
v11 = "websocket [ws_mod.c:175]: ";
v45 = v5;
v12 = v27;
v13 = v26;
v14 = "%2d(%d) %s: %s%s(): binding to SL\n";
v15 = process_no;
goto LABEL_94;
}
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): binding to SL\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:175]: ",
"mod_init");
goto LABEL_43;
}
if ( (unsigned int)sr_event_register_cb(10LL, &ws_frame_receive) )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v9 = *((_QWORD *)&log_level_info + 8);
v10 = my_pid();
v11 = "websocket [ws_mod.c:181]: ";
v12 = (unsigned int)v10;
v45 = v10;
v13 = v9;
v14 = "%2d(%d) %s: %s%s(): registering WebSocket receive call-back\n";
v15 = process_no;
goto LABEL_94;
}
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): registering WebSocket receive call-back\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:181]: ",
"mod_init");
goto LABEL_43;
}
if ( (unsigned int)sr_event_register_cb(11LL, &ws_frame_transmit) )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v18 = *((_QWORD *)&log_level_info + 8);
v19 = my_pid();
v11 = "websocket [ws_mod.c:187]: ";
v12 = (unsigned int)v19;
v13 = v18;
v14 = "%2d(%d) %s: %s%s(): registering WebSocket transmit call-back\n";
v45 = v19;
v15 = process_no;
goto LABEL_94;
}
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): registering WebSocket transmit call-back\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:187]: ",
"mod_init");
goto LABEL_43;
}
if ( (unsigned int)register_module_stats(exports, &stats) )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v20 = *((_QWORD *)&log_level_info + 8);
v21 = my_pid();
v11 = "websocket [ws_mod.c:193]: ";
v12 = (unsigned int)v21;
v13 = v20;
v14 = "%2d(%d) %s: %s%s(): registering core statistics\n";
v45 = v21;
v15 = process_no;
goto LABEL_94;
}
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): registering core statistics\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:193]: ",
"mod_init");
goto LABEL_43;
}
if ( (unsigned int)register_mi_mod(exports, &mi_cmds) )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v28 = *((_QWORD *)&log_level_info + 8);
v29 = my_pid();
v11 = "websocket [ws_mod.c:199]: ";
v45 = v30;
v12 = v29;
v13 = v28;
v14 = "%2d(%d) %s: %s%s(): registering MI commands\n";
v15 = process_no;
goto LABEL_94;
}
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): registering MI commands\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:199]: ",
"mod_init");
LABEL_43:
--dprint_crit;
LABEL_44:
wsconn_destroy();
return (unsigned int)-1;
}
if ( (int)wsconn_init() < 0 )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): initialising WebSocket connections table\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:205]: ",
"mod_init");
goto LABEL_43;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v39 = *((_QWORD *)&log_level_info + 8);
v40 = my_pid();
v11 = "websocket [ws_mod.c:205]: ";
v45 = v41;
v12 = v40;
v13 = v39;
v14 = "%2d(%d) %s: %s%s(): initialising WebSocket connections table\n";
v15 = process_no;
goto LABEL_94;
}
if ( ws_ping_application_data )
{
v0 = strlen(ws_ping_application_data);
*((_DWORD *)&ws_ping_application_data + 2) = v0;
}
else
{
v0 = *((_DWORD *)&ws_ping_application_data + 2);
}
if ( (unsigned int)(v0 - 1) > 0x7C )
{
*((_DWORD *)&ws_ping_application_data + 2) = 36;
ws_ping_application_data = "kamailio (4.1.0-dev9 (x86_64/linux))";
}
if ( ws_keepalive_mechanism )
{
if ( (unsigned int)(ws_keepalive_timeout - 1) > 0xE0F )
ws_keepalive_timeout = 180;
if ( (unsigned int)(ws_keepalive_mechanism - 1) > 1 )
ws_keepalive_mechanism = 1;
if ( (unsigned int)(ws_keepalive_interval - 1) > 0x3B )
ws_keepalive_interval = 1;
if ( (unsigned int)(ws_keepalive_processes - 1) > 0xF )
ws_keepalive_processes = 1;
register_sync_timers();
}
v1 = ws_sub_protocols;
if ( (ws_sub_protocols & 2) != 0 )
{
v4 = (unsigned int)sr_event_enabled(9LL) == 0;
v1 = ws_sub_protocols;
if ( v4 )
{
v1 = ws_sub_protocols & 0xFFFFFFFD;
ws_sub_protocols &= 0xFFFFFFFD;
}
}
if ( (v1 & 3) == 0 )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
v6 = (unsigned int)++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): no sub-protocols enabled\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:251]: ",
"mod_init");
goto LABEL_43;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v37 = *((_QWORD *)&log_level_info + 8);
v38 = my_pid();
v11 = "websocket [ws_mod.c:251]: ";
v45 = v6;
v12 = v38;
v13 = v37;
v14 = "%2d(%d) %s: %s%s(): no sub-protocols enabled\n";
v15 = process_no;
goto LABEL_94;
}
if ( (v1 & 0xFFFFFFFC) != 0 )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): unrecognised sub-protocols enabled\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:257]: ",
"mod_init");
goto LABEL_43;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v22 = *((_QWORD *)&log_level_info + 8);
v23 = my_pid();
v11 = "websocket [ws_mod.c:257]: ";
v12 = (unsigned int)v23;
v13 = v22;
v14 = "%2d(%d) %s: %s%s(): unrecognised sub-protocols enabled\n";
v45 = v23;
v15 = process_no;
goto LABEL_94;
}
if ( ws_cors_mode > 2u )
{
if ( (int)get_debug_level("websocket", 9LL) < -1 || dprint_crit )
goto LABEL_44;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): bad value for cors_mode\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:263]: ",
"mod_init");
goto LABEL_43;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v24 = *((_QWORD *)&log_level_info + 8);
v25 = my_pid();
v11 = "websocket [ws_mod.c:263]: ";
v12 = (unsigned int)v25;
v13 = v24;
v14 = "%2d(%d) %s: %s%s(): bad value for cors_mode\n";
v45 = v25;
v15 = process_no;
LABEL_94:
v16 = stderr;
fprintf(stderr, v14, v15, v12, v13, v11, "mod_init", v45);
if ( log_color )
dprint_color_reset(v16, v14, v17);
goto LABEL_43;
}
v2 = cfg_declare("websocket", &ws_cfg_def, &default_ws_cfg, 8LL, &ws_cfg);
if ( v2 )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): declaring configuration\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:270]: ",
"mod_init");
LABEL_70:
v2 = -1;
--dprint_crit;
return v2;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v31 = *((_QWORD *)&log_level_info + 8);
v32 = my_pid();
v33 = "%2d(%d) %s: %s%s(): declaring configuration\n";
fprintf(
stderr,
"%2d(%d) %s: %s%s(): declaring configuration\n",
process_no,
v32,
v31,
"websocket [ws_mod.c:270]: ",
"mod_init");
LABEL_117:
if ( log_color )
dprint_color_reset(v43, v33, v34);
goto LABEL_70;
}
return (unsigned int)-1;
}
*ws_cfg = ws_keepalive_timeout;
if ( !find_module_by_name("xhttp") )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): \"xhttp\" must be loaded to use WebSocket.\n",
*((const char **)&log_level_info + 8),
"websocket [ws_mod.c:277]: ",
"mod_init");
goto LABEL_70;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v35 = *((_QWORD *)&log_level_info + 8);
v33 = "%2d(%d) %s: %s%s(): \"xhttp\" must be loaded to use WebSocket.\n";
v36 = (unsigned int)my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): \"xhttp\" must be loaded to use WebSocket.\n",
process_no,
v36,
v35,
"websocket [ws_mod.c:277]: ",
"mod_init");
goto LABEL_117;
}
return (unsigned int)-1;
}
if ( (ws_sub_protocols & 1) != 0
&& !find_module_by_name("nathelper")
&& !find_module_by_name("outbound")
&& (int)get_debug_level("websocket", 9LL) >= 0
&& !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0LL);
v7 = (const char *)*((_QWORD *)&log_level_info + 10);
v44 = my_pid();
v8 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): neither \"nathelper\" nor \"outbound\" modules are loaded. At least one of these is required"
" for correct routing of SIP over WebSocket.\n",
process_no,
v44,
v7,
"websocket [ws_mod.c:285]: ",
"mod_init");
if ( log_color )
dprint_color_reset(
v8,
"%2d(%d) %s: %s%s(): neither \"nathelper\" nor \"outbound\" modules are loaded. At least one of these is requir"
"ed for correct routing of SIP over WebSocket.\n",
v42);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 22) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): neither \"nathelper\" nor \"outbound\" modules are loaded. At least one of these is required for cor"
"rect routing of SIP over WebSocket.\n",
*((const char **)&log_level_info + 10),
"websocket [ws_mod.c:285]: ",
"mod_init");
}
v2 = 0;
--dprint_crit;
}
return v2;
}

original_code:
static int mod_init(void)
{
 if (sl_load_api(&ws_slb) != 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "binding to SL\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "175" "]: ") , __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(): " "binding to SL\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "175" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "binding to SL\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "175" "]: ") , __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(): " "binding to SL\n", ("websocket" " [" "ws_mod.c" ":" "175" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "binding to SL\n", ("websocket" " [" "ws_mod.c" ":" "175" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (sr_event_register_cb(10, ws_frame_receive) != 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "registering WebSocket receive call-back\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "181" "]: ") , __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(): " "registering WebSocket receive call-back\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "181" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "registering WebSocket receive call-back\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "181" "]: ") , __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(): " "registering WebSocket receive call-back\n", ("websocket" " [" "ws_mod.c" ":" "181" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "registering WebSocket receive call-back\n", ("websocket" " [" "ws_mod.c" ":" "181" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (sr_event_register_cb(11, ws_frame_transmit) != 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "registering WebSocket transmit call-back\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "187" "]: ") , __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(): " "registering WebSocket transmit call-back\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "187" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "registering WebSocket transmit call-back\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "187" "]: ") , __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(): " "registering WebSocket transmit call-back\n", ("websocket" " [" "ws_mod.c" ":" "187" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "registering WebSocket transmit call-back\n", ("websocket" " [" "ws_mod.c" ":" "187" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (register_module_stats(exports.name, stats) != 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "registering core statistics\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "193" "]: ") , __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(): " "registering core statistics\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "193" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "registering core statistics\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "193" "]: ") , __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(): " "registering core statistics\n", ("websocket" " [" "ws_mod.c" ":" "193" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "registering core statistics\n", ("websocket" " [" "ws_mod.c" ":" "193" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (register_mi_mod(exports.name, mi_cmds) != 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "registering MI commands\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "199" "]: ") , __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(): " "registering MI commands\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "199" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "registering MI commands\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "199" "]: ") , __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(): " "registering MI commands\n", ("websocket" " [" "ws_mod.c" ":" "199" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "registering MI commands\n", ("websocket" " [" "ws_mod.c" ":" "199" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (wsconn_init() < 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "initialising WebSocket connections table\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "205" "]: ") , __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(): " "initialising WebSocket connections table\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "205" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "initialising WebSocket connections table\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "205" "]: ") , __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(): " "initialising WebSocket connections table\n", ("websocket" " [" "ws_mod.c" ":" "205" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "initialising WebSocket connections table\n", ("websocket" " [" "ws_mod.c" ":" "205" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (ws_ping_application_data.s != 0)
  ws_ping_application_data.len =
     strlen(ws_ping_application_data.s);
 if (ws_ping_application_data.len < 1
  || ws_ping_application_data.len > 125)
 {
  ws_ping_application_data.s = "Server: " "kamailio" " (" "4.1.0-dev9" " (" "x86_64" "/" "linux" "))" + 8;
  ws_ping_application_data.len =
     (sizeof("Server: " "kamailio" " (" "4.1.0-dev9" " (" "x86_64" "/" "linux" "))")-1) - 8;
 }
 if (ws_keepalive_mechanism != KEEPALIVE_MECHANISM_NONE)
 {
  if (ws_keepalive_timeout < 1 || ws_keepalive_timeout > 3600)
   ws_keepalive_timeout = 180;
  switch(ws_keepalive_mechanism)
  {
  case KEEPALIVE_MECHANISM_PING:
  case KEEPALIVE_MECHANISM_PONG:
   break;
  default:
   ws_keepalive_mechanism = KEEPALIVE_MECHANISM_PING;
   break;
  }
  if (ws_keepalive_interval < 1 || ws_keepalive_interval > 60)
   ws_keepalive_interval = 1;
  if (ws_keepalive_processes < 1 || ws_keepalive_processes > 16)
   ws_keepalive_processes = 1;
  register_sync_timers(ws_keepalive_processes);
 }
 if (ws_sub_protocols & SUB_PROTOCOL_MSRP
  && !sr_event_enabled(9))
  ws_sub_protocols &= ~SUB_PROTOCOL_MSRP;
 if ((ws_sub_protocols & (SUB_PROTOCOL_SIP | SUB_PROTOCOL_MSRP)) == 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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 sub-protocols enabled\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "251" "]: ") , __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 sub-protocols enabled\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "251" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no sub-protocols enabled\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "251" "]: ") , __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 sub-protocols enabled\n", ("websocket" " [" "ws_mod.c" ":" "251" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no sub-protocols enabled\n", ("websocket" " [" "ws_mod.c" ":" "251" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if ((ws_sub_protocols | (SUB_PROTOCOL_SIP | SUB_PROTOCOL_MSRP)) != (SUB_PROTOCOL_SIP | SUB_PROTOCOL_MSRP))
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "unrecognised sub-protocols enabled\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "257" "]: ") , __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(): " "unrecognised sub-protocols enabled\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "257" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "unrecognised sub-protocols enabled\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "257" "]: ") , __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(): " "unrecognised sub-protocols enabled\n", ("websocket" " [" "ws_mod.c" ":" "257" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "unrecognised sub-protocols enabled\n", ("websocket" " [" "ws_mod.c" ":" "257" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (ws_cors_mode < 0 || ws_cors_mode > 2)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "bad value for cors_mode\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "263" "]: ") , __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(): " "bad value for cors_mode\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "263" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "bad value for cors_mode\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "263" "]: ") , __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(): " "bad value for cors_mode\n", ("websocket" " [" "ws_mod.c" ":" "263" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "bad value for cors_mode\n", ("websocket" " [" "ws_mod.c" ":" "263" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (cfg_declare("websocket", ws_cfg_def, &default_ws_cfg,
   sizeof(struct cfg_group_websocket), &ws_cfg))
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "declaring configuration\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "270" "]: ") , __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(): " "declaring configuration\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "270" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "declaring configuration\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "270" "]: ") , __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(): " "declaring configuration\n", ("websocket" " [" "ws_mod.c" ":" "270" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "declaring configuration\n", ("websocket" " [" "ws_mod.c" ":" "270" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 ((struct cfg_group_websocket *)ws_cfg)->keepalive_timeout = ws_keepalive_timeout;
 if (!(find_module_by_name("xhttp")!=0))
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "\"xhttp\" must be loaded to use WebSocket.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "277" "]: ") , __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(): " "\"xhttp\" must be loaded to use WebSocket.\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "277" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "\"xhttp\" must be loaded to use WebSocket.\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "277" "]: ") , __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(): " "\"xhttp\" must be loaded to use WebSocket.\n", ("websocket" " [" "ws_mod.c" ":" "277" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "\"xhttp\" must be loaded to use WebSocket.\n", ("websocket" " [" "ws_mod.c" ":" "277" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (((ws_sub_protocols & SUB_PROTOCOL_SIP) == SUB_PROTOCOL_SIP)
   && !(find_module_by_name("nathelper")!=0)
   && !(find_module_by_name("outbound")!=0))
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-1)) >= ((0)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((0)) >= -5) && (((0)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "neither \"nathelper\" nor \"outbound\" modules are" " loaded. At least one of these is required for correct" " routing of SIP over WebSocket.\n", process_no, my_pid(), (log_level_info[((0)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "285" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((0)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "neither \"nathelper\" nor \"outbound\" modules are" " loaded. At least one of these is required for correct" " routing of SIP over WebSocket.\n", (log_level_info[((0)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "285" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s" "%s(): " "neither \"nathelper\" nor \"outbound\" modules are" " loaded. At least one of these is required for correct" " routing of SIP over WebSocket.\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "285" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((0))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "neither \"nathelper\" nor \"outbound\" modules are" " loaded. At least one of these is required for correct" " routing of SIP over WebSocket.\n", ("websocket" " [" "ws_mod.c" ":" "285" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "neither \"nathelper\" nor \"outbound\" modules are" " loaded. At least one of these is required for correct" " routing of SIP over WebSocket.\n", ("websocket" " [" "ws_mod.c" ":" "285" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 }
 return 0;
error:
 wsconn_destroy();
 return -1;
}

canonical_original_code:
static int mod_init()
{
 if (sl_load_api(&ws_slb) != 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "binding to SL\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "175" "]: ") , __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(): " "binding to SL\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "175" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "binding to SL\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "175" "]: ") , __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(): " "binding to SL\n", ("websocket" " [" "ws_mod.c" ":" "175" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "binding to SL\n", ("websocket" " [" "ws_mod.c" ":" "175" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (sr_event_register_cb(10, ws_frame_receive) != 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "registering WebSocket receive call-back\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "181" "]: ") , __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(): " "registering WebSocket receive call-back\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "181" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "registering WebSocket receive call-back\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "181" "]: ") , __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(): " "registering WebSocket receive call-back\n", ("websocket" " [" "ws_mod.c" ":" "181" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "registering WebSocket receive call-back\n", ("websocket" " [" "ws_mod.c" ":" "181" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (sr_event_register_cb(11, ws_frame_transmit) != 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "registering WebSocket transmit call-back\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "187" "]: ") , __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(): " "registering WebSocket transmit call-back\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "187" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "registering WebSocket transmit call-back\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "187" "]: ") , __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(): " "registering WebSocket transmit call-back\n", ("websocket" " [" "ws_mod.c" ":" "187" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "registering WebSocket transmit call-back\n", ("websocket" " [" "ws_mod.c" ":" "187" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (register_module_stats(exports.name, stats) != 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "registering core statistics\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "193" "]: ") , __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(): " "registering core statistics\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "193" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "registering core statistics\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "193" "]: ") , __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(): " "registering core statistics\n", ("websocket" " [" "ws_mod.c" ":" "193" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "registering core statistics\n", ("websocket" " [" "ws_mod.c" ":" "193" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (register_mi_mod(exports.name, mi_cmds) != 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "registering MI commands\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "199" "]: ") , __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(): " "registering MI commands\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "199" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "registering MI commands\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "199" "]: ") , __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(): " "registering MI commands\n", ("websocket" " [" "ws_mod.c" ":" "199" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "registering MI commands\n", ("websocket" " [" "ws_mod.c" ":" "199" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (wsconn_init() < 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "initialising WebSocket connections table\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "205" "]: ") , __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(): " "initialising WebSocket connections table\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "205" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "initialising WebSocket connections table\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "205" "]: ") , __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(): " "initialising WebSocket connections table\n", ("websocket" " [" "ws_mod.c" ":" "205" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "initialising WebSocket connections table\n", ("websocket" " [" "ws_mod.c" ":" "205" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (ws_ping_application_data.s != 0)
  ws_ping_application_data.len =
     strlen(ws_ping_application_data.s);
 if (ws_ping_application_data.len < 1
  || ws_ping_application_data.len > 125)
 {
  ws_ping_application_data.s = "Server: " "kamailio" " (" "4.1.0-dev9" " (" "x86_64" "/" "linux" "))" + 8;
  ws_ping_application_data.len =
     (sizeof("Server: " "kamailio" " (" "4.1.0-dev9" " (" "x86_64" "/" "linux" "))")-1) - 8;
 }
 if (ws_keepalive_mechanism != KEEPALIVE_MECHANISM_NONE)
 {
  if (ws_keepalive_timeout < 1 || ws_keepalive_timeout > 3600)
   ws_keepalive_timeout = 180;
  switch(ws_keepalive_mechanism)
  {
  case KEEPALIVE_MECHANISM_PING:
  case KEEPALIVE_MECHANISM_PONG:
   break;
  default:
   ws_keepalive_mechanism = KEEPALIVE_MECHANISM_PING;
   break;
  }
  if (ws_keepalive_interval < 1 || ws_keepalive_interval > 60)
   ws_keepalive_interval = 1;
  if (ws_keepalive_processes < 1 || ws_keepalive_processes > 16)
   ws_keepalive_processes = 1;
  register_sync_timers(ws_keepalive_processes);
 }
 if (ws_sub_protocols & SUB_PROTOCOL_MSRP
  && !sr_event_enabled(9))
  ws_sub_protocols &= ~SUB_PROTOCOL_MSRP;
 if ((ws_sub_protocols & (SUB_PROTOCOL_SIP | SUB_PROTOCOL_MSRP)) == 0)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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 sub-protocols enabled\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "251" "]: ") , __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 sub-protocols enabled\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "251" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "no sub-protocols enabled\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "251" "]: ") , __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 sub-protocols enabled\n", ("websocket" " [" "ws_mod.c" ":" "251" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "no sub-protocols enabled\n", ("websocket" " [" "ws_mod.c" ":" "251" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if ((ws_sub_protocols | (SUB_PROTOCOL_SIP | SUB_PROTOCOL_MSRP)) != (SUB_PROTOCOL_SIP | SUB_PROTOCOL_MSRP))
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "unrecognised sub-protocols enabled\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "257" "]: ") , __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(): " "unrecognised sub-protocols enabled\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "257" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "unrecognised sub-protocols enabled\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "257" "]: ") , __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(): " "unrecognised sub-protocols enabled\n", ("websocket" " [" "ws_mod.c" ":" "257" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "unrecognised sub-protocols enabled\n", ("websocket" " [" "ws_mod.c" ":" "257" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (ws_cors_mode < 0 || ws_cors_mode > 2)
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "bad value for cors_mode\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "263" "]: ") , __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(): " "bad value for cors_mode\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "263" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "bad value for cors_mode\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "263" "]: ") , __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(): " "bad value for cors_mode\n", ("websocket" " [" "ws_mod.c" ":" "263" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "bad value for cors_mode\n", ("websocket" " [" "ws_mod.c" ":" "263" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (cfg_declare("websocket", ws_cfg_def, &default_ws_cfg,
   sizeof(struct cfg_group_websocket), &ws_cfg))
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "declaring configuration\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "270" "]: ") , __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(): " "declaring configuration\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "270" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "declaring configuration\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "270" "]: ") , __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(): " "declaring configuration\n", ("websocket" " [" "ws_mod.c" ":" "270" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "declaring configuration\n", ("websocket" " [" "ws_mod.c" ":" "270" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 ((struct cfg_group_websocket *)ws_cfg)->keepalive_timeout = ws_keepalive_timeout;
 if (!(find_module_by_name("xhttp")!=0))
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-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(): " "\"xhttp\" must be loaded to use WebSocket.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "277" "]: ") , __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(): " "\"xhttp\" must be loaded to use WebSocket.\n", (log_level_info[((-1)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "277" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "\"xhttp\" must be loaded to use WebSocket.\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "277" "]: ") , __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(): " "\"xhttp\" must be loaded to use WebSocket.\n", ("websocket" " [" "ws_mod.c" ":" "277" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "\"xhttp\" must be loaded to use WebSocket.\n", ("websocket" " [" "ws_mod.c" ":" "277" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (((ws_sub_protocols & SUB_PROTOCOL_SIP) == SUB_PROTOCOL_SIP)
   && !(find_module_by_name("nathelper")!=0)
   && !(find_module_by_name("outbound")!=0))
 {
  do { if (get_debug_level("websocket", (sizeof("websocket")-1)) >= ((0)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((0)) >= -5) && (((0)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "neither \"nathelper\" nor \"outbound\" modules are" " loaded. At least one of these is required for correct" " routing of SIP over WebSocket.\n", process_no, my_pid(), (log_level_info[((0)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "285" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((0)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "neither \"nathelper\" nor \"outbound\" modules are" " loaded. At least one of these is required for correct" " routing of SIP over WebSocket.\n", (log_level_info[((0)) - (-5)].name), ("websocket" " [" "ws_mod.c" ":" "285" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((0)); fprintf(stderr, "%2d(%d) %s" "%s(): " "neither \"nathelper\" nor \"outbound\" modules are" " loaded. At least one of these is required for correct" " routing of SIP over WebSocket.\n", process_no, my_pid(), ("websocket" " [" "ws_mod.c" ":" "285" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((0))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "neither \"nathelper\" nor \"outbound\" modules are" " loaded. At least one of these is required for correct" " routing of SIP over WebSocket.\n", ("websocket" " [" "ws_mod.c" ":" "285" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "neither \"nathelper\" nor \"outbound\" modules are" " loaded. At least one of these is required for correct" " routing of SIP over WebSocket.\n", ("websocket" " [" "ws_mod.c" ":" "285" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 }
 return 0;
error:
 wsconn_destroy();
 return -1;
}

user_defined_types: struct cfg_group_websocket { int keepalive_timeout; int enabled; }


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

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

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

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

variable_types:
var
int *

variable_types: v int


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

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

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

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

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

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

variable_types:
lock
struct atomic_t { int val; } *


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

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

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

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

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

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


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 create_message_ex(int a1)
{
int v1; // ebx
__int64 result; // rax

v1 = 0;
if ( a1 >= 0 )
v1 = a1;
result = shm_malloc(v1 + 40);
if ( result )
{
*(_DWORD *)(result + 8) = v1;
*(_QWORD *)result = result + 40;
*(_QWORD *)(result + 16) = 0LL;
*(_DWORD *)(result + 32) = 0;
*(_QWORD *)(result + 24) = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
int v1; // ebx
__int64 result; // rax

v1 = 0;
if ( a1 >= 0 )
v1 = a1;
result = func4(v1 + 40);
if ( result )
{
*(_DWORD *)(result + 8) = v1;
*(_QWORD *)result = result + 40;
*(_QWORD *)(result + 16) = 0LL;
*(_DWORD *)(result + 32) = 0;
*(_QWORD *)(result + 24) = 0LL;
}
return result;
}

original_code:
mq_message_t *create_message_ex(int data_len)
{
 mq_message_t *m;
 if (data_len < 0) data_len = 0;
 m = shm_malloc(data_len + sizeof(mq_message_t));
 if (!m) return ((void *)0);
 m->data_len = data_len;
 m->data = (((char *)m) + sizeof(mq_message_t));
 m->next = ((void *)0);
 m->allocation_style = message_allocated_with_data;
 m->destroy_function = ((void *)0);
 return m;
}

canonical_original_code:
struct _mq_message_t *create_message_ex(int data_len)
{
 struct _mq_message_t *m;
 if (data_len < 0) data_len = 0;
 m = shm_malloc(data_len + sizeof(mq_message_t));
 if (!m) return ((void *)0);
 m->data_len = data_len;
 m->data = (((char *)m) + sizeof(mq_message_t));
 m->next = ((void *)0);
 m->allocation_style = message_allocated_with_data;
 m->destroy_function = ((void *)0);
 return m;
}

variable_types: struct _mq_message_t { void *data; int data_len; struct _mq_message_t *next; void (*destroy_function)(void *); enum { message_allocated_with_data=0, message_holding_data_ptr=1 } allocation_style; char data_buf[1]; } *


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

result = shm_malloc(0x28u);
if ( result )
{
*(_DWORD *)(result + 8) = a2;
*(_QWORD *)result = a1;
*(_QWORD *)(result + 16) = 0LL;
*(_DWORD *)(result + 32) = 1;
*(_QWORD *)(result + 24) = &shm_free_x;
}
return result;
}

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

result = func4(0x28u);
if ( result )
{
*(_DWORD *)(result + 8) = a2;
*(_QWORD *)result = a1;
*(_QWORD *)(result + 16) = 0LL;
*(_DWORD *)(result + 32) = 1;
*(_QWORD *)(result + 24) = &shm_free_x;
}
return result;
}

original_code:
mq_message_t *create_message(void *data, int data_len)
{
 mq_message_t *m;
 m = shm_malloc(sizeof(mq_message_t));
 if (!m) return ((void *)0);
 m->data_len = data_len;
 m->data = data;
 m->next = ((void *)0);
 m->allocation_style = message_holding_data_ptr;
 m->destroy_function = shm_free_x;
 return m;
}

canonical_original_code:
struct _mq_message_t *create_message(void *data, int data_len)
{
 struct _mq_message_t *m;
 m = shm_malloc(sizeof(mq_message_t));
 if (!m) return ((void *)0);
 m->data_len = data_len;
 m->data = data;
 m->next = ((void *)0);
 m->allocation_style = message_holding_data_ptr;
 m->destroy_function = shm_free_x;
 return m;
}

variable_types:
data
void *

return_type: struct _mq_message_t { void *data; int data_len; struct _mq_message_t *next; void (*destroy_function)(void *); enum { message_allocated_with_data=0, message_holding_data_ptr=1 } allocation_style; char data_buf[1]; } *


original_code:
void init_message_ex(mq_message_t *m, void *data, int data_len, destroy_function_f func)
{
 if (!m) return;
 m->data_len = data_len;
 m->data = data;
 m->next = ((void *)0);
 m->destroy_function = func;
 m->allocation_style = message_holding_data_ptr;
}

canonical_original_code:
void init_message_ex(struct _mq_message_t *m, void *data, int data_len, void (*func)(void *))
{
 if (!m) return;
 m->data_len = data_len;
 m->data = data;
 m->next = ((void *)0);
 m->destroy_function = func;
 m->allocation_style = message_holding_data_ptr;
}

variable_types:
func
void (*)(void *)

user_defined_types: struct _mq_message_t { void *data; int data_len; struct _mq_message_t *next; void (*destroy_function)(void *); enum { message_allocated_with_data=0, message_holding_data_ptr=1 } allocation_style; char data_buf[1]; }


decompiled_code:
void __fastcall set_data_destroy_function(__int64 a1, __int64 a2)
{
if ( a1 )
*(_QWORD *)(a1 + 24) = a2;
}

original_code:
void set_data_destroy_function(mq_message_t *msg, destroy_function_f func)
{
 if (msg) msg->destroy_function = func;
}

canonical_original_code:
void set_data_destroy_function(struct _mq_message_t *msg, void (*func)(void *))
{
 if (msg) msg->destroy_function = func;
}


decompiled_code:
__int64 __fastcall free_message(_QWORD *a1)
{
void (*v1)(void); // rax

v1 = (void (*)(void))a1[3];
if ( v1 && *a1 )
v1();
futex_get(mem_lock);
qm_free(shm_block, a1);
return futex_release(mem_lock);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
void (*v1)(void); // rax

v1 = (void (*)(void))a1[3];
if ( v1 && *a1 )
v1();
func3(mem_lock);
qm_free(shm_block, a1);
return func1(mem_lock);
}

original_code:
void free_message(mq_message_t *msg)
{
 if (msg->destroy_function && msg->data)
  msg->destroy_function(msg->data);
 switch (msg->allocation_style) {
  case message_allocated_with_data:
    break;
  case message_holding_data_ptr:
    break;
 }
 do { futex_get(mem_lock); qm_free(shm_block, (msg)); futex_release(mem_lock); }while(0);
}

canonical_original_code:
void free_message(struct _mq_message_t *msg)
{
 if (msg->destroy_function && msg->data)
  msg->destroy_function(msg->data);
 switch (msg->allocation_style) {
  case message_allocated_with_data:
    break;
  case message_holding_data_ptr:
    break;
 }
 do { futex_get(mem_lock); qm_free(shm_block, (msg)); futex_release(mem_lock); }while(0);
}