decompiled_code:
__int64 mod_init()
{
unsigned int v0; // ebp
unsigned int v1; // ebx
const char *v3; // rbp
unsigned int v4; // eax
const char *v5; // rbx
unsigned int v6; // eax
const char *v7; // rbx
unsigned int v8; // eax
const char *v9; // rbp
unsigned int v10; // eax
const char *v11; // rbp
unsigned int v12; // eax
const char *v13; // rbx
unsigned int v14; // eax
const char *v15; // rbx
unsigned int v16; // eax
const char *v17; // rbp
unsigned int v18; // eax
const char *v19; // rbp
unsigned int v20; // eax
const char *v21; // rbx
unsigned int v22; // eax
const char *v23; // rbx
unsigned int v24; // eax
const char *v25; // rbp
unsigned int v26; // eax

if ( (unsigned int)sl_load_api((__int64)&ws_slb) )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v3 = (const char *)*((_QWORD *)&log_level_info + 8);
v4 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): binding to SL\n",
process_no,
v4,
v3,
"websocket [ws_mod.c:175]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( (unsigned int)sr_event_register_cb(10LL, &ws_frame_receive) )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v5 = (const char *)*((_QWORD *)&log_level_info + 8);
v6 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): registering WebSocket receive call-back\n",
process_no,
v6,
v5,
"websocket [ws_mod.c:181]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( (unsigned int)sr_event_register_cb(11LL, &ws_frame_transmit) )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v7 = (const char *)*((_QWORD *)&log_level_info + 8);
v8 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): registering WebSocket transmit call-back\n",
process_no,
v8,
v7,
"websocket [ws_mod.c:187]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( (unsigned int)register_module_stats(exports, &stats) )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v9 = (const char *)*((_QWORD *)&log_level_info + 8);
v10 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): registering core statistics\n",
process_no,
v10,
v9,
"websocket [ws_mod.c:193]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( (unsigned int)register_mi_mod(exports, &mi_cmds) )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v11 = (const char *)*((_QWORD *)&log_level_info + 8);
v12 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): registering MI commands\n",
process_no,
v12,
v11,
"websocket [ws_mod.c:199]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( (int)wsconn_init() < 0 )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v13 = (const char *)*((_QWORD *)&log_level_info + 8);
v14 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): initialising WebSocket connections table\n",
process_no,
v14,
v13,
"websocket [ws_mod.c:205]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( ws_ping_application_data )
*((_DWORD *)&ws_ping_application_data + 2) = strlen(ws_ping_application_data);
if ( (unsigned int)(*((_DWORD *)&ws_ping_application_data + 2) - 1) > 0x7C )
{
ws_ping_application_data = "kamailio (4.1.0-dev9 (x86_64/linux))";
*((_DWORD *)&ws_ping_application_data + 2) = 36;
}
if ( ws_keepalive_mechanism )
{
if ( (unsigned int)(ws_keepalive_timeout - 1) > 0xE0F )
ws_keepalive_timeout = 180;
if ( 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((unsigned int)ws_keepalive_processes);
}
if ( (ws_sub_protocols & 2) != 0 && !(unsigned int)sr_event_enabled(9LL) )
ws_sub_protocols &= 0xFFFFFFFD;
if ( (ws_sub_protocols & 3) == 0 )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v15 = (const char *)*((_QWORD *)&log_level_info + 8);
v16 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): no sub-protocols enabled\n",
process_no,
v16,
v15,
"websocket [ws_mod.c:251]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( (ws_sub_protocols & 0xFFFFFFFC) != 0 )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v17 = (const char *)*((_QWORD *)&log_level_info + 8);
v18 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): unrecognised sub-protocols enabled\n",
process_no,
v18,
v17,
"websocket [ws_mod.c:257]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( ws_cors_mode > 2u )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v19 = (const char *)*((_QWORD *)&log_level_info + 8);
v20 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): bad value for cors_mode\n",
process_no,
v20,
v19,
"websocket [ws_mod.c:263]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
LABEL_34:
wsconn_destroy();
return (unsigned int)-1;
}
v0 = cfg_declare("websocket", &ws_cfg_def, &default_ws_cfg, 8LL, &ws_cfg);
if ( v0 )
{
v1 = -1;
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v21 = (const char *)*((_QWORD *)&log_level_info + 8);
v22 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): declaring configuration\n",
process_no,
v22,
v21,
"websocket [ws_mod.c:270]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
v1 = -1;
}
}
else
{
*ws_cfg = ws_keepalive_timeout;
if ( find_module_by_name("xhttp") )
{
v1 = ws_sub_protocols & 1;
if ( (ws_sub_protocols & 1) != 0 )
{
v1 = v0;
if ( !find_module_by_name("nathelper")
&& !find_module_by_name("outbound")
&& (int)get_debug_level("websocket", 9LL) >= 0 )
{
v1 = dprint_crit;
if ( dprint_crit )
{
v1 = v0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0LL);
v25 = (const char *)*((_QWORD *)&log_level_info + 10);
v26 = my_pid();
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,
v26,
v25,
"websocket [ws_mod.c:285]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
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 correct routing of SIP over WebSocket.\n",
*((const char **)&log_level_info + 10),
"websocket [ws_mod.c:285]: ",
"mod_init");
}
--dprint_crit;
}
}
}
}
else
{
v1 = -1;
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v23 = (const char *)*((_QWORD *)&log_level_info + 8);
v24 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): \"xhttp\" must be loaded to use WebSocket.\n",
process_no,
v24,
v23,
"websocket [ws_mod.c:277]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
v1 = -1;
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebp
unsigned int v1; // ebx
const char *v3; // rbp
unsigned int v4; // eax
const char *v5; // rbx
unsigned int v6; // eax
const char *v7; // rbx
unsigned int v8; // eax
const char *v9; // rbp
unsigned int v10; // eax
const char *v11; // rbp
unsigned int v12; // eax
const char *v13; // rbx
unsigned int v14; // eax
const char *v15; // rbx
unsigned int v16; // eax
const char *v17; // rbp
unsigned int v18; // eax
const char *v19; // rbp
unsigned int v20; // eax
const char *v21; // rbx
unsigned int v22; // eax
const char *v23; // rbx
unsigned int v24; // eax
const char *v25; // rbp
unsigned int v26; // eax

if ( (unsigned int)func2((__int64)&ws_slb) )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v3 = (const char *)*((_QWORD *)&log_level_info + 8);
v4 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): binding to SL\n",
process_no,
v4,
v3,
"websocket [ws_mod.c:175]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( (unsigned int)sr_event_register_cb(10LL, &ws_frame_receive) )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v5 = (const char *)*((_QWORD *)&log_level_info + 8);
v6 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): registering WebSocket receive call-back\n",
process_no,
v6,
v5,
"websocket [ws_mod.c:181]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( (unsigned int)sr_event_register_cb(11LL, &ws_frame_transmit) )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v7 = (const char *)*((_QWORD *)&log_level_info + 8);
v8 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): registering WebSocket transmit call-back\n",
process_no,
v8,
v7,
"websocket [ws_mod.c:187]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( (unsigned int)register_module_stats(exports, &stats) )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v9 = (const char *)*((_QWORD *)&log_level_info + 8);
v10 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): registering core statistics\n",
process_no,
v10,
v9,
"websocket [ws_mod.c:193]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( (unsigned int)register_mi_mod(exports, &mi_cmds) )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v11 = (const char *)*((_QWORD *)&log_level_info + 8);
v12 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): registering MI commands\n",
process_no,
v12,
v11,
"websocket [ws_mod.c:199]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( (int)wsconn_init() < 0 )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v13 = (const char *)*((_QWORD *)&log_level_info + 8);
v14 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): initialising WebSocket connections table\n",
process_no,
v14,
v13,
"websocket [ws_mod.c:205]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( ws_ping_application_data )
*((_DWORD *)&ws_ping_application_data + 2) = strlen(ws_ping_application_data);
if ( (unsigned int)(*((_DWORD *)&ws_ping_application_data + 2) - 1) > 0x7C )
{
ws_ping_application_data = "kamailio (4.1.0-dev9 (x86_64/linux))";
*((_DWORD *)&ws_ping_application_data + 2) = 36;
}
if ( ws_keepalive_mechanism )
{
if ( (unsigned int)(ws_keepalive_timeout - 1) > 0xE0F )
ws_keepalive_timeout = 180;
if ( 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((unsigned int)ws_keepalive_processes);
}
if ( (ws_sub_protocols & 2) != 0 && !(unsigned int)sr_event_enabled(9LL) )
ws_sub_protocols &= 0xFFFFFFFD;
if ( (ws_sub_protocols & 3) == 0 )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v15 = (const char *)*((_QWORD *)&log_level_info + 8);
v16 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): no sub-protocols enabled\n",
process_no,
v16,
v15,
"websocket [ws_mod.c:251]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( (ws_sub_protocols & 0xFFFFFFFC) != 0 )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v17 = (const char *)*((_QWORD *)&log_level_info + 8);
v18 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): unrecognised sub-protocols enabled\n",
process_no,
v18,
v17,
"websocket [ws_mod.c:257]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
goto LABEL_34;
}
if ( ws_cors_mode > 2u )
{
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v19 = (const char *)*((_QWORD *)&log_level_info + 8);
v20 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): bad value for cors_mode\n",
process_no,
v20,
v19,
"websocket [ws_mod.c:263]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
}
LABEL_34:
wsconn_destroy();
return (unsigned int)-1;
}
v0 = cfg_declare("websocket", &ws_cfg_def, &default_ws_cfg, 8LL, &ws_cfg);
if ( v0 )
{
v1 = -1;
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v21 = (const char *)*((_QWORD *)&log_level_info + 8);
v22 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): declaring configuration\n",
process_no,
v22,
v21,
"websocket [ws_mod.c:270]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
v1 = -1;
}
}
else
{
*ws_cfg = ws_keepalive_timeout;
if ( find_module_by_name("xhttp") )
{
v1 = ws_sub_protocols & 1;
if ( (ws_sub_protocols & 1) != 0 )
{
v1 = v0;
if ( !find_module_by_name("nathelper")
&& !find_module_by_name("outbound")
&& (int)get_debug_level("websocket", 9LL) >= 0 )
{
v1 = dprint_crit;
if ( dprint_crit )
{
v1 = v0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0LL);
v25 = (const char *)*((_QWORD *)&log_level_info + 10);
v26 = my_pid();
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,
v26,
v25,
"websocket [ws_mod.c:285]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
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 correct routing of SIP over WebSocket.\n",
*((const char **)&log_level_info + 10),
"websocket [ws_mod.c:285]: ",
"mod_init");
}
--dprint_crit;
}
}
}
}
else
{
v1 = -1;
if ( (int)get_debug_level("websocket", 9LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v23 = (const char *)*((_QWORD *)&log_level_info + 8);
v24 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): \"xhttp\" must be loaded to use WebSocket.\n",
process_no,
v24,
v23,
"websocket [ws_mod.c:277]: ",
"mod_init");
if ( log_color )
dprint_color_reset();
}
else
{
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");
}
--dprint_crit;
v1 = -1;
}
}
}
return v1;
}

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


repo: virtualolson/who

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

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

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

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

variable_types:
var
int *

variable_types: v int

return_type: int


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

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

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

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

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

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

variable_types:
lock
struct atomic_t { int val; } *

variable_types: i int

return_type: void


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

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

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

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

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

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


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

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; // rbx

func2(mem_lock);
v1 = qm_malloc(shm_block, a1);
func3(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 func5(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 func6(__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 func9(_QWORD *a1)
{
void (*v1)(void); // rax

v1 = (void (*)(void))a1[3];
if ( v1 && *a1 )
v1();
func2(mem_lock);
qm_free(shm_block, a1);
return func3(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);
}


decompiled_code:
void __fastcall msg_queue_destroy_and_free(__int64 a1, int a2)
{
_QWORD *v3; // rbx
_QWORD *v4; // rdi

if ( a1 && ((*(_BYTE *)(a1 + 36) & 2) == 0 || (unsigned int)remove_reference()) )
{
if ( (*(_BYTE *)(a1 + 36) & 1) != 0 )
futex_get((volatile signed __int32 *)(a1 + 32));
v3 = *(_QWORD **)(a1 + 16);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[2];
free_message(v4);
}
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
if ( (*(_BYTE *)(a1 + 36) & 1) != 0 )
futex_release((volatile __int32 *)(a1 + 32));
if ( a2 )
{
futex_get(mem_lock);
qm_free(shm_block, a1);
futex_release(mem_lock);
}
}
}

original_code:
static inline void msg_queue_destroy_and_free(msg_queue_t *q, int do_free)
{
 mq_message_t *m,*n;
 if (!q) return;
 if (q->flags & 2) {
  if (!remove_reference(&q->ref)) {
   return;
  }
 }
 if (q->flags & 1) futex_get(&q->q_mutex);
 m = q->first;
 while (m) {
  n = m->next;
  free_message(m);
  m = n;
 }
 q->first = ((void *)0);
 q->last = ((void *)0);
 if (q->flags & 1) {
  futex_release(&q->q_mutex);
  ;
 }
 if (do_free) do { futex_get(mem_lock); qm_free(shm_block, (q)); futex_release(mem_lock); }while(0);
}

canonical_original_code:
static inline void msg_queue_destroy_and_free(struct msg_queue *q, int do_free)
{
 struct _mq_message_t *m; struct _mq_message_t *n;
 if (!q) return;
 if (q->flags & 2) {
  if (!remove_reference(&q->ref)) {
   return;
  }
 }
 if (q->flags & 1) futex_get(&q->q_mutex);
 m = q->first;
 while (m) {
  n = m->next;
  free_message(m);
  m = n;
 }
 q->first = ((void *)0);
 q->last = ((void *)0);
 if (q->flags & 1) {
  futex_release(&q->q_mutex);
  ;
 }
 if (do_free) do { futex_get(mem_lock); qm_free(shm_block, (q)); futex_release(mem_lock); }while(0);
}

variable_types: struct msg_queue { struct reference_counter_data_t { int cntr; struct atomic_t { int val; } *mutex; } ref; 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]; } *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; } *

user_defined_types: struct msg_queue { struct reference_counter_data_t ref; struct _mq_message_t *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; }

user_defined_types: struct reference_counter_data_t { int cntr; struct atomic_t *mutex; }


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

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a2 + 16) = 0LL;
if ( (*(_BYTE *)(a1 + 36) & 1) != 0 )
futex_get((volatile signed __int32 *)(a1 + 32));
v2 = *(_QWORD *)(a1 + 24);
if ( v2 )
*(_QWORD *)(v2 + 16) = a2;
else
*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 24) = a2;
result = 0LL;
if ( (*(_BYTE *)(a1 + 36) & 1) != 0 )
{
futex_release((volatile __int32 *)(a1 + 32));
result = 0LL;
}
return result;
}

original_code:
int push_message(msg_queue_t *q, mq_message_t *m)
{
 if ((!q) || (!m)) return -1;
 m->next = ((void *)0);
 if (q->flags & 1) futex_get(&q->q_mutex);
 if (q->last) q->last->next = m;
 else {
  q->first = m;
  q->last = m;
 }
 q->last = m;
 if (q->flags & 1) futex_release(&q->q_mutex);
 return 0;
}

canonical_original_code:
int push_message(struct msg_queue *q, struct _mq_message_t *m)
{
 if ((!q) || (!m)) return -1;
 m->next = ((void *)0);
 if (q->flags & 1) futex_get(&q->q_mutex);
 if (q->last) q->last->next = m;
 else {
  q->first = m;
  q->last = m;
 }
 q->last = m;
 if (q->flags & 1) futex_release(&q->q_mutex);
 return 0;
}

variable_types:
m
struct _mq_message_t *


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

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a2 + 16) = 0LL;
if ( (*(_BYTE *)(a1 + 36) & 1) != 0 )
futex_get((volatile signed __int32 *)(a1 + 32));
*(_QWORD *)(a2 + 16) = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 16) = a2;
if ( !*(_QWORD *)(a1 + 24) )
*(_QWORD *)(a1 + 24) = a2;
result = 0LL;
if ( (*(_BYTE *)(a1 + 36) & 1) != 0 )
{
futex_release((volatile __int32 *)(a1 + 32));
result = 0LL;
}
return result;
}

original_code:
int mq_add_to_top(msg_queue_t *q, mq_message_t *m)
{
 if ((!q) || (!m)) return -1;
 m->next = ((void *)0);
 if (q->flags & 1) futex_get(&q->q_mutex);
 m->next = q->first;
 q->first = m;
 if (!q->last) q->last = m;
 if (q->flags & 1) futex_release(&q->q_mutex);
 return 0;
}

canonical_original_code:
int mq_add_to_top(struct msg_queue *q, struct _mq_message_t *m)
{
 if ((!q) || (!m)) return -1;
 m->next = ((void *)0);
 if (q->flags & 1) futex_get(&q->q_mutex);
 m->next = q->first;
 q->first = m;
 if (!q->last) q->last = m;
 if (q->flags & 1) futex_release(&q->q_mutex);
 return 0;
}


original_code:
mq_message_t *pop_message(msg_queue_t *q)
{
 mq_message_t *m;
 if (!q) return ((void *)0);
 if (q->flags & 1) futex_get(&q->q_mutex);
 m = q->first;
 if (m) {
  if (q->first == q->last) {
   q->first = ((void *)0);
   q->last = ((void *)0);
  }
  else q->first = m->next;
  m->next = ((void *)0);
 }
 if (q->flags & 1) futex_release(&q->q_mutex);
 return m;
}

canonical_original_code:
struct _mq_message_t *pop_message(struct msg_queue *q)
{
 struct _mq_message_t *m;
 if (!q) return ((void *)0);
 if (q->flags & 1) futex_get(&q->q_mutex);
 m = q->first;
 if (m) {
  if (q->first == q->last) {
   q->first = ((void *)0);
   q->last = ((void *)0);
  }
  else q->first = m->next;
  m->next = ((void *)0);
 }
 if (q->flags & 1) futex_release(&q->q_mutex);
 return m;
}

variable_types: struct msg_queue { struct reference_counter_data_t { int cntr; struct atomic_t { int val; } *mutex; } ref; struct _mq_message_t *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; } *


decompiled_code:
_BOOL8 __fastcall is_msg_queue_empty(__int64 a1)
{
_BOOL4 v1; // ebp

if ( (*(_BYTE *)(a1 + 36) & 1) == 0 )
return *(_QWORD *)(a1 + 16) == 0LL;
futex_get((volatile signed __int32 *)(a1 + 32));
v1 = *(_QWORD *)(a1 + 16) == 0LL;
if ( (*(_BYTE *)(a1 + 36) & 1) != 0 )
futex_release((volatile __int32 *)(a1 + 32));
return v1;
}

original_code:
int is_msg_queue_empty(msg_queue_t *q)
{
 int res = 1;
 if (q->flags & 1) futex_get(&q->q_mutex);
 if (q->first) res = 0;
 if (q->flags & 1) futex_release(&q->q_mutex);
 return res;
}

canonical_original_code:
int is_msg_queue_empty(struct msg_queue *q)
{
 int res = 1;
 if (q->flags & 1) futex_get(&q->q_mutex);
 if (q->first) res = 0;
 if (q->flags & 1) futex_release(&q->q_mutex);
 return res;
}

variable_types: res int


original_code:
int msg_queue_init_ex(msg_queue_t *q, int synchronize)
{
 if (synchronize) {
  futex_init(&q->q_mutex);
  q->flags = 1;
 }
 else q->flags = 0;
 q->first = ((void *)0);
 q->last = ((void *)0);
 return 0;
}

canonical_original_code:
int msg_queue_init_ex(struct msg_queue *q, int synchronize)
{
 if (synchronize) {
  futex_init(&q->q_mutex);
  q->flags = 1;
 }
 else q->flags = 0;
 q->first = ((void *)0);
 q->last = ((void *)0);
 return 0;
}

variable_types: synchronize int


decompiled_code:
__int64 __fastcall msg_queue_init(__int64 a1)
{
return msg_queue_init_ex(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
return func15(a1, 1);
}

original_code:
int msg_queue_init(msg_queue_t *q)
{
 return msg_queue_init_ex(q, 1);
}

canonical_original_code:
int msg_queue_init(struct msg_queue *q)
{
 return msg_queue_init_ex(q, 1);
}


decompiled_code:
void __fastcall msg_queue_destroy(__int64 a1)
{
msg_queue_destroy_and_free(a1, 0);
}

canonical_decompiled_code:
void __fastcall func17(__int64 a1)
{
func10(a1, 0);
}

original_code:
void msg_queue_destroy(msg_queue_t *q)
{
 msg_queue_destroy_and_free(q, 0);
}

canonical_original_code:
void msg_queue_destroy(struct msg_queue *q)
{
 msg_queue_destroy_and_free(q, 0);
}


decompiled_code:
void __fastcall msg_queue_free(__int64 a1)
{
msg_queue_destroy_and_free(a1, 1);
}

canonical_decompiled_code:
void __fastcall func18(__int64 a1)
{
func10(a1, 1);
}

original_code:
void msg_queue_free(msg_queue_t *q)
{
 msg_queue_destroy_and_free(q, 1);
}

canonical_original_code:
void msg_queue_free(struct msg_queue *q)
{
 msg_queue_destroy_and_free(q, 1);
}


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

if ( a2 )
{
result = init_reference_counter(a2, a1);
*(_DWORD *)(a1 + 36) |= 2u;
}
else
{
*(_DWORD *)(a1 + 36) &= 0xFFFFFFFD;
}
return result;
}

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

if ( a2 )
{
result = init_reference_counter(a2, a1);
*(_DWORD *)(a1 + 36) |= 2u;
}
else
{
*(_DWORD *)(a1 + 36) &= 0xFFFFFFFD;
}
return result;
}

original_code:
void msg_queue_init_ref_cnt(msg_queue_t *q, reference_counter_group_t *grp)
{
 if (grp) {
  init_reference_counter(grp, &q->ref);
  q->flags |= 2;
 }
 else q->flags &= ~2;
}

canonical_original_code:
void msg_queue_init_ref_cnt(struct msg_queue *q, struct reference_counter_group_t *grp)
{
 if (grp) {
  init_reference_counter(grp, &q->ref);
  q->flags |= 2;
 }
 else q->flags &= ~2;
}

variable_types: struct reference_counter_group_t { int mutex_cnt; int mutex_to_assign; struct atomic_t mutexes[1]; } *


decompiled_code:
__int64 __fastcall user2uid(__uid_t *a1, __gid_t *a2, const char *a3)
{
unsigned int v5; // edi
struct passwd *v6; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a3 )
return 0xFFFFFFFFLL;
*a1 = strtol(a3, &endptr, 10);
if ( !endptr || (v5 = 0, *endptr) )
{
v6 = getpwnam(a3);
if ( v6 )
{
*a1 = v6->pw_uid;
v5 = 0;
if ( a2 )
*a2 = v6->pw_gid;
}
else
{
v5 = -1;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__uid_t *a1, __gid_t *a2, const char *a3)
{
unsigned int v5; // edi
struct passwd *v6; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a3 )
return 0xFFFFFFFFLL;
*a1 = strtol(a3, &endptr, 10);
if ( !endptr || (v5 = 0, *endptr) )
{
v6 = getpwnam(a3);
if ( v6 )
{
*a1 = v6->pw_uid;
v5 = 0;
if ( a2 )
*a2 = v6->pw_gid;
}
else
{
v5 = -1;
}
}
return v5;
}

original_code:
int user2uid(int* uid, int* gid, char* user)
{
 char* tmp;
 struct passwd *pw_entry;
 if (user){
  *uid=strtol(user, &tmp, 10);
  if ((tmp==0) ||(*tmp)){
   pw_entry=getpwnam(user);
   if (pw_entry==0){
    goto error;
   }
   *uid=pw_entry->pw_uid;
   if (gid) *gid=pw_entry->pw_gid;
  }
  return 0;
 }
error:
 return -1;
}

canonical_original_code:
int user2uid(int *uid, int *gid, char *user)
{
 char *tmp;
 struct passwd *pw_entry;
 if (user){
  *uid=strtol(user, &tmp, 10);
  if ((tmp==0) ||(*tmp)){
   pw_entry=getpwnam(user);
   if (pw_entry==0){
    goto error;
   }
   *uid=pw_entry->pw_uid;
   if (gid) *gid=pw_entry->pw_gid;
  }
  return 0;
 }
error:
 return -1;
}

variable_types:
uid
int *

variable_types:
gid
int *

variable_types:
user
char *

variable_types:
tmp
char *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
__int64 __fastcall group2gid(__gid_t *a1, const char *a2)
{
unsigned int v3; // esi
struct group *v4; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
*a1 = strtol(a2, &endptr, 10);
if ( !endptr || (v3 = 0, *endptr) )
{
v4 = getgrnam(a2);
if ( v4 )
{
*a1 = v4->gr_gid;
v3 = 0;
}
else
{
v3 = -1;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__gid_t *a1, const char *a2)
{
unsigned int v3; // esi
struct group *v4; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
*a1 = strtol(a2, &endptr, 10);
if ( !endptr || (v3 = 0, *endptr) )
{
v4 = getgrnam(a2);
if ( v4 )
{
*a1 = v4->gr_gid;
v3 = 0;
}
else
{
v3 = -1;
}
}
return v3;
}

original_code:
int group2gid(int* gid, char* group)
{
 char* tmp;
 struct group *gr_entry;
 if (group){
  *gid=strtol(group, &tmp, 10);
  if ((tmp==0) ||(*tmp)){
   gr_entry=getgrnam(group);
   if (gr_entry==0){
    goto error;
   }
   *gid=gr_entry->gr_gid;
  }
  return 0;
 }
 error:
 return -1;
}

canonical_original_code:
int group2gid(int *gid, char *group)
{
 char *tmp;
 struct group *gr_entry;
 if (group){
  *gid=strtol(group, &tmp, 10);
  if ((tmp==0) ||(*tmp)){
   gr_entry=getgrnam(group);
   if (gr_entry==0){
    goto error;
   }
   *gid=gr_entry->gr_gid;
  }
  return 0;
 }
 error:
 return -1;
}

variable_types:
group
char *

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *


decompiled_code:
time_t __fastcall local2utc(time_t a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = gmtime(&timer);
v1->tm_isdst = -1;
return mktime(v1);
}

canonical_decompiled_code:
time_t __fastcall func3(time_t a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = gmtime(&timer);
v1->tm_isdst = -1;
return mktime(v1);
}

original_code:
time_t local2utc(time_t in)
{
 struct tm* tt;
 tt = gmtime(&in);
 tt->tm_isdst = -1;
 return mktime(tt);
}

canonical_original_code:
long local2utc(long in)
{
 struct tm *tt;
 tt = gmtime(&in);
 tt->tm_isdst = -1;
 return mktime(tt);
}

variable_types: in long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

return_type: long


decompiled_code:
time_t __fastcall utc2local(time_t a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = localtime(&timer);
return timegm(v1);
}

canonical_decompiled_code:
time_t __fastcall func4(time_t a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = localtime(&timer);
return func2(v1);
}

original_code:
time_t utc2local(time_t in)
{
 struct tm* tt;
 tt = localtime(&in);
 return timegm(tt);
}

canonical_original_code:
long utc2local(long in)
{
 struct tm *tt;
 tt = localtime(&in);
 return timegm(tt);
}

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


decompiled_code:
__int64 __fastcall get_sys_version(_DWORD *a1, _DWORD *a2, _DWORD *a3)
{
int v5; // ebx
int v6; // esi
int v7; // ebp
char *endptr; // [rsp+8h] [rbp-1C0h] BYREF
struct utsname name; // [rsp+10h] [rbp-1B8h] BYREF

memset(&name, 0, 0x180uLL);
*(_DWORD *)&name.domainname[59] = 0;
*(_WORD *)&name.domainname[63] = 0;
uname(&name);
v5 = strtol(name.release, &endptr, 10);
v6 = 0;
v7 = 0;
if ( *endptr == 46 )
{
++endptr;
v7 = strtol(endptr, &endptr, 10);
v6 = 0;
if ( *endptr == 46 )
{
++endptr;
v6 = strtol(endptr, &endptr, 10);
}
}
if ( a1 )
*a1 = v5;
if ( a2 )
*a2 = v7;
if ( a3 )
*a3 = v6;
return (v7 << 8) | v6 | (unsigned int)(v5 << 16);
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, _DWORD *a2, _DWORD *a3)
{
int v5; // ebx
int v6; // esi
int v7; // ebp
char *endptr; // [rsp+8h] [rbp-1C0h] BYREF
struct utsname name; // [rsp+10h] [rbp-1B8h] BYREF

memset(&name, 0, 0x180uLL);
*(_DWORD *)&name.domainname[59] = 0;
*(_WORD *)&name.domainname[63] = 0;
uname(&name);
v5 = strtol(name.release, &endptr, 10);
v6 = 0;
v7 = 0;
if ( *endptr == 46 )
{
++endptr;
v7 = strtol(endptr, &endptr, 10);
v6 = 0;
if ( *endptr == 46 )
{
++endptr;
v6 = strtol(endptr, &endptr, 10);
}
}
if ( a1 )
*a1 = v5;
if ( a2 )
*a2 = v7;
if ( a3 )
*a3 = v6;
return (v7 << 8) | v6 | (unsigned int)(v5 << 16);
}

original_code:
unsigned int get_sys_version(int* major, int* minor, int* minor2)
{
 struct utsname un;
 int m1;
 int m2;
 int m3;
 char* p;
 memset (&un, 0, sizeof(un));
 m1=m2=m3=0;
 uname(&un);
 m1=strtol(un.release, &p, 10);
 if (*p=='.'){
  p++;
  m2=strtol(p, &p, 10);
  if (*p=='.'){
   p++;
   m3=strtol(p, &p, 10);
  }
 }
 if (major) *major=m1;
 if (minor) *minor=m2;
 if (minor2) *minor2=m3;
 return ((m1<<16)|(m2<<8)|(m3));
}

canonical_original_code:
unsigned int get_sys_version(int *major, int *minor, int *minor2)
{
 struct utsname un;
 int m1;
 int m2;
 int m3;
 char *p;
 memset (&un, 0, sizeof(un));
 m1=m2=m3=0;
 uname(&un);
 m1=strtol(un.release, &p, 10);
 if (*p=='.'){
  p++;
  m2=strtol(p, &p, 10);
  if (*p=='.'){
   p++;
   m3=strtol(p, &p, 10);
  }
 }
 if (major) *major=m1;
 if (minor) *minor=m2;
 if (minor2) *minor2=m3;
 return ((m1<<16)|(m2<<8)|(m3));
}

variable_types:
major
int *

variable_types:
minor
int *

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char __domainname[65]; }

variable_types:
p
char *

return_type: unsigned int