decompiled_code:
char *__fastcall jutil_regkey(char *s2, __int64 a2)
{
unsigned int v3; // eax
const char *v4; // rsi
const char *v5; // rax
int v6; // ebx
__int64 v7; // r12
char *v8; // r12
unsigned int v9; // eax
const char *v10; // r14
__int64 v11; // rbx
int i; // ebp
char v14[72]; // [rsp+0h] [rbp-48h] BYREF

if ( last_2 == -1 )
{
last_2 = 0;
memset(&keydb_1, 0, 0x1000uLL);
*((_DWORD *)&keydb_1 + 1024) = 0;
memset(seeddb_0, 0, 0x1000uLL);
*(_DWORD *)&seeddb_0[4096] = 0;
v9 = time(0LL);
srand(v9);
}
if ( s2 || !a2 )
{
v10 = (const char *)shahash(a2);
v11 = 0LL;
for ( i = 0; i != 100; ++i )
{
v8 = (char *)&keydb_1 + v11;
if ( !j_strcmp((const char *)&keydb_1 + v11, s2) && !j_strcmp(&seeddb_0[v11], v10) )
{
seeddb_0[41 * i] = 0;
return v8;
}
v11 += 41LL;
}
v8 = 0LL;
}
else
{
v3 = rand();
sprintf(v14, "%d", v3);
v4 = (const char *)shahash(v14);
strcpy((char *)&keydb_1 + 41 * last_2, v4);
v5 = (const char *)shahash(a2);
v6 = last_2;
v7 = 41LL * last_2;
strcpy(&seeddb_0[v7], v5);
if ( v6 == 99 )
{
last_2 = 0;
v8 = (char *)&unk_287B;
}
else
{
v8 = (char *)&keydb_1 + v7;
last_2 = v6 + 1;
}
}
return v8;
}

canonical_decompiled_code:
char *__fastcall func11(char *s2, __int64 a2)
{
unsigned int v3; // eax
const char *v4; // rsi
const char *v5; // rax
int v6; // ebx
__int64 v7; // r12
char *v8; // r12
unsigned int v9; // eax
const char *v10; // r14
__int64 v11; // rbx
int i; // ebp
char v14[72]; // [rsp+0h] [rbp-48h] BYREF

if ( last_2 == -1 )
{
last_2 = 0;
memset(&keydb_1, 0, 0x1000uLL);
*((_DWORD *)&keydb_1 + 1024) = 0;
memset(seeddb_0, 0, 0x1000uLL);
*(_DWORD *)&seeddb_0[4096] = 0;
v9 = time(0LL);
srand(v9);
}
if ( s2 || !a2 )
{
v10 = (const char *)shahash(a2);
v11 = 0LL;
for ( i = 0; i != 100; ++i )
{
v8 = (char *)&keydb_1 + v11;
if ( !j_strcmp((const char *)&keydb_1 + v11, s2) && !j_strcmp(&seeddb_0[v11], v10) )
{
seeddb_0[41 * i] = 0;
return v8;
}
v11 += 41LL;
}
v8 = 0LL;
}
else
{
v3 = rand();
sprintf(v14, "%d", v3);
v4 = (const char *)shahash(v14);
strcpy((char *)&keydb_1 + 41 * last_2, v4);
v5 = (const char *)shahash(a2);
v6 = last_2;
v7 = 41LL * last_2;
strcpy(&seeddb_0[v7], v5);
if ( v6 == 99 )
{
last_2 = 0;
v8 = (char *)&unk_287B;
}
else
{
v8 = (char *)&keydb_1 + v7;
last_2 = v6 + 1;
}
}
return v8;
}

original_code:
char *jutil_regkey(char *key, char *seed)
{
    static char keydb[100][41];
    static char seeddb[100][41];
    static int last = -1;
    char *str, strint[32];
    int i;
    if(last == -1)
    {
        last = 0;
        memset(&keydb,0,100*41);
        memset(&seeddb,0,100*41);
        srand(time(((void *)0)));
    }
    if(key == ((void *)0) && seed != ((void *)0))
    {
        sprintf(strint,"%d",rand());
        strcpy(keydb[last],shahash(strint));
        strcpy(seeddb[last],shahash(seed));
        str = keydb[last];
        last++;
        if(last == 100) last = 0;
        return str;
    }
    str = shahash(seed);
    for(i=0;i<100;i++)
        if(j_strcmp(keydb[i],key) == 0 && j_strcmp(seeddb[i],str) == 0)
        {
            seeddb[i][0] = '\0';
            return keydb[i];
        }
    return ((void *)0);
}

canonical_original_code:
char *jutil_regkey(char *key, char *seed)
{
    static char keydb[100][41];
    static char seeddb[100][41];
    static int last = -1;
    char *str; char strint[32];
    int i;
    if(last == -1)
    {
        last = 0;
        memset(&keydb,0,100*41);
        memset(&seeddb,0,100*41);
        srand(time(((void *)0)));
    }
    if(key == ((void *)0) && seed != ((void *)0))
    {
        sprintf(strint,"%d",rand());
        strcpy(keydb[last],shahash(strint));
        strcpy(seeddb[last],shahash(seed));
        str = keydb[last];
        last++;
        if(last == 100) last = 0;
        return str;
    }
    str = shahash(seed);
    for(i=0;i<100;i++)
        if(j_strcmp(keydb[i],key) == 0 && j_strcmp(seeddb[i],str) == 0)
        {
            seeddb[i][0] = '\0';
            return keydb[i];
        }
    return ((void *)0);
}

variable_types:
key
char *

variable_types:
seed
char *

variable_types:
keydb
char [100][41]

variable_types:
seeddb
char [100][41]

variable_types: last int

variable_types:
str
char *

variable_types:
strint
char [32]

variable_types: i int


repo: zhenkai/muc

decompiled_code:
char *__fastcall j_strdup(const char *a1)
{
char *result; // rax

result = (char *)a1;
if ( a1 )
result = strdup(a1);
return result;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1)
{
char *result; // rax

result = (char *)a1;
if ( a1 )
result = strdup(a1);
return result;
}

original_code:
char *j_strdup(const char *str)
{
    if(str == ((void *)0))
        return ((void *)0);
    else
        return strdup(str);
}

canonical_original_code:
char *j_strdup(char *str)
{
    if(str == ((void *)0))
        return ((void *)0);
    else
        return strdup(str);
}

return_type: char *


decompiled_code:
__int64 __fastcall j_strcmp(char *a1, char *a2)
{
char v2; // dl
char v3; // cl
__int64 v4; // rax

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
v2 = *a1;
v3 = *a2;
if ( v2 == *a2 && v2 != 0 && v3 )
{
v4 = 1LL;
do
{
v2 = a1[v4];
v3 = a2[v4++];
}
while ( v2 == v3 && v2 != 0 && v3 );
}
return (unsigned int)-(v2 != v3);
}

original_code:
int j_strcmp(const char *a, const char *b)
{
    if(a == ((void *)0) || b == ((void *)0))
        return -1;
    while(*a == *b && *a != '\0' && *b != '\0'){ a++; b++; }
    if(*a == *b) return 0;
    return -1;
}

variable_types:
a
char *

variable_types:
b
char *

return_type: int


decompiled_code:
int __fastcall j_strncmp(const char *a1, const char *a2, int a3)
{
int result; // eax

if ( a1 && a2 )
result = strncmp(a1, a2, a3);
else
result = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, const char *a2, int a3)
{
int result; // eax

if ( a1 && a2 )
result = strncmp(a1, a2, a3);
else
result = -1;
return result;
}

original_code:
int j_strncmp(const char *a, const char *b, int i)
{
    if(a == ((void *)0) || b == ((void *)0))
        return -1;
    else
        return strncmp(a, b, i);
}

canonical_original_code:
int j_strncmp(char *a, char *b, int i)
{
    if(a == ((void *)0) || b == ((void *)0))
        return -1;
    else
        return strncmp(a, b, i);
}


decompiled_code:
int __fastcall j_strncasecmp(const char *a1, const char *a2, int a3)
{
int result; // eax

if ( a1 && a2 )
result = strncasecmp(a1, a2, a3);
else
result = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func3(const char *a1, const char *a2, int a3)
{
int result; // eax

if ( a1 && a2 )
result = strncasecmp(a1, a2, a3);
else
result = -1;
return result;
}

original_code:
int j_strncasecmp(const char *a, const char *b, int i)
{
    if(a == ((void *)0) || b == ((void *)0))
        return -1;
    else
        return strncasecmp(a, b, i);
}

canonical_original_code:
int j_strncasecmp(char *a, char *b, int i)
{
    if(a == ((void *)0) || b == ((void *)0))
        return -1;
    else
        return strncasecmp(a, b, i);
}


decompiled_code:
size_t __fastcall j_strlen(const char *a1)
{
size_t result; // rax

result = 0LL;
if ( a1 )
result = strlen(a1);
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(const char *a1)
{
size_t result; // rax

result = 0LL;
if ( a1 )
result = strlen(a1);
return result;
}

original_code:
int j_strlen(const char *a)
{
    if(a == ((void *)0))
        return 0;
    else
        return strlen(a);
}

canonical_original_code:
int j_strlen(char *a)
{
    if(a == ((void *)0))
        return 0;
    else
        return strlen(a);
}


decompiled_code:
int __fastcall j_atoi(const char *a1, int a2)
{
int result; // eax

result = a2;
if ( a1 )
result = atoi(a1);
return result;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, int a2)
{
int result; // eax

result = a2;
if ( a1 )
result = atoi(a1);
return result;
}

original_code:
int j_atoi(const char *a, int def)
{
    if(a == ((void *)0))
        return def;
    else
        return atoi(a);
}

canonical_original_code:
int j_atoi(char *a, int def)
{
    if(a == ((void *)0))
        return def;
    else
        return atoi(a);
}

variable_types: def int


zonestr

decompiled_code:
char *__fastcall zonestr(const char *a1, unsigned int a2)
{
buff_0[(int)ap_snprintf(buff_0, 63LL, "%s:%d", a1, a2)] = 0;
return buff_0;
}

canonical_decompiled_code:
char *__fastcall func11(const char *a1, unsigned int a2)
{
buff_0[(int)ap_snprintf(buff_0, 63LL, "%s:%d", a1, a2)] = 0;
return buff_0;
}

original_code:
char *zonestr(char *file, int line)
{
    static char buff[64];
    int i;
    i = ap_snprintf(buff,63,"%s:%d",file,line);
    buff[i] = '\0';
    return buff;
}

variable_types:
file
char *

variable_types: line int

variable_types:
buff
char [64]


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

v0 = time(0LL) - 900;
jid_clean_single_cache((_QWORD *)jid_prep_cache_node, v0);
jid_clean_single_cache((_QWORD *)jid_prep_cache_domain, v0);
return jid_clean_single_cache((_QWORD *)jid_prep_cache_resource, v0);
}

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

v0 = time(0LL) - 900;
func0((_QWORD *)jid_prep_cache_node, v0);
func0((_QWORD *)jid_prep_cache_domain, v0);
return func0((_QWORD *)jid_prep_cache_resource, v0);
}

original_code:
void jid_clean_cache(void) {
    time_t keep_newer_as = time(((void *)0)) - 900;
    _jid_clean_single_cache(_jid_prep_cache_node, keep_newer_as);
    _jid_clean_single_cache(_jid_prep_cache_domain, keep_newer_as);
    _jid_clean_single_cache(_jid_prep_cache_resource, keep_newer_as);
}

canonical_original_code:
void jid_clean_cache() {
    long keep_newer_as = time(((void *)0)) - 900;
    _jid_clean_single_cache(_jid_prep_cache_node, keep_newer_as);
    _jid_clean_single_cache(_jid_prep_cache_domain, keep_newer_as);
    _jid_clean_single_cache(_jid_prep_cache_resource, keep_newer_as);
}

return_type: void


decompiled_code:
void jid_stop_caching()
{
jid_stop_single_cache((void **)&jid_prep_cache_node);
jid_stop_single_cache((void **)&jid_prep_cache_domain);
jid_stop_single_cache((void **)&jid_prep_cache_resource);
}

canonical_decompiled_code:
void func11()
{
func2((void **)&jid_prep_cache_node);
func2((void **)&jid_prep_cache_domain);
func2((void **)&jid_prep_cache_resource);
}

original_code:
void jid_stop_caching(void) {
    _jid_stop_single_cache(&_jid_prep_cache_node);
    _jid_stop_single_cache(&_jid_prep_cache_domain);
    _jid_stop_single_cache(&_jid_prep_cache_resource);
}

canonical_original_code:
void jid_stop_caching() {
    _jid_stop_single_cache(&_jid_prep_cache_node);
    _jid_stop_single_cache(&_jid_prep_cache_domain);
    _jid_stop_single_cache(&_jid_prep_cache_resource);
}


decompiled_code:
void jid_init_cache()
{
jid_init_single_cache((__int64)&jid_prep_cache_node, (__int64)&stringprep_xmpp_nodeprep);
jid_init_single_cache((__int64)&jid_prep_cache_domain, (__int64)&stringprep_nameprep);
jid_init_single_cache((__int64)&jid_prep_cache_resource, (__int64)&stringprep_xmpp_resourceprep);
}

canonical_decompiled_code:
void func12()
{
func3((__int64)&jid_prep_cache_node, (__int64)&stringprep_xmpp_nodeprep);
func3((__int64)&jid_prep_cache_domain, (__int64)&stringprep_nameprep);
func3((__int64)&jid_prep_cache_resource, (__int64)&stringprep_xmpp_resourceprep);
}

original_code:
void jid_init_cache(void) {
    _jid_init_single_cache(&_jid_prep_cache_node, stringprep_xmpp_nodeprep);
    _jid_init_single_cache(&_jid_prep_cache_domain, stringprep_nameprep);
    _jid_init_single_cache(&_jid_prep_cache_resource, stringprep_xmpp_resourceprep);
}

canonical_original_code:
void jid_init_cache() {
    _jid_init_single_cache(&_jid_prep_cache_node, stringprep_xmpp_nodeprep);
    _jid_init_single_cache(&_jid_prep_cache_domain, stringprep_nameprep);
    _jid_init_single_cache(&_jid_prep_cache_resource, stringprep_xmpp_resourceprep);
}


decompiled_code:
void __fastcall ght_remove_key(void *ptr)
{
const char *v1; // rax

v1 = (const char *)funcstr("hash.c", "ght_remove_key", 25LL);
log_debug("MU-Conference", "[%s] Auto-removing key %s", v1, (const char *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
const char *v1; // rax

v1 = (const char *)funcstr("hash.c", "ght_remove_key", 25LL);
log_debug("MU-Conference", "[%s] Auto-removing key %s", v1, (const char *)ptr);
free(ptr);
}

original_code:
void ght_remove_key(gpointer data)
{
  log_debug("MU-Conference", "[%s] Auto-removing key %s", funcstr("hash.c",__FUNCTION__,25), (char*) data);
  free(data);
}

canonical_original_code:
void ght_remove_key(void *data)
{
  log_debug("MU-Conference", "[%s] Auto-removing key %s", funcstr("hash.c",__FUNCTION__,25), (char *) data);
  free(data);
}

variable_types:
data
void *


decompiled_code:
__int64 jcr_server_hangup()
{
__int64 v0; // rdi
__int64 v1; // rax

v0 = jcr_debug_msg("jcr_shutdown.c", "jcr_server_hangup", 70LL);
log_warn(v0, "server received hangup signal, reopening logs");
jcr_log_close();
v1 = jcr_debug_msg("jcr_shutdown.c", "jcr_server_hangup", 72LL);
return log_warn(v1, "started new log");
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rdi
__int64 v1; // rax

v0 = jcr_debug_msg("jcr_shutdown.c", "jcr_server_hangup", 70LL);
log_warn(v0, "server received hangup signal, reopening logs");
jcr_log_close();
v1 = jcr_debug_msg("jcr_shutdown.c", "jcr_server_hangup", 72LL);
return log_warn(v1, "started new log");
}

original_code:
void jcr_server_hangup(int signum) {
  log_warn(jcr_debug_msg("jcr_shutdown.c",__FUNCTION__,70), "server received hangup signal, reopening logs");
  jcr_log_close();
  log_warn(jcr_debug_msg("jcr_shutdown.c",__FUNCTION__,72), "started new log");
  return;
}

variable_types: signum int


usage

decompiled_code:
int usage()
{
puts("Usage: mu-conference [-B] [-s] [-h] [-d LEVEL] -c FILE");
puts(" -B Put the daemon in background");
puts(" -s Show debug messages on stderr");
puts(" -h Print this help");
puts(" -d LEVEL Set the level of debug output");
return puts(" -c FILE Set the config file, mandatory argument");
}

canonical_decompiled_code:
int func0()
{
puts("Usage: mu-conference [-B] [-s] [-h] [-d LEVEL] -c FILE");
puts(" -B Put the daemon in background");
puts(" -s Show debug messages on stderr");
puts(" -h Print this help");
puts(" -d LEVEL Set the level of debug output");
return puts(" -c FILE Set the config file, mandatory argument");
}

original_code:
void usage() {
    printf("Usage: mu-conference [-B] [-s] [-h] [-d LEVEL] -c FILE\n");
    printf("          -B         Put the daemon in background\n");
    printf("          -s         Show debug messages on stderr\n");
    printf("          -h         Print this help\n");
    printf("          -d LEVEL   Set the level of debug output\n");
    printf("          -c FILE    Set the config file, mandatory argument\n");
}


decompiled_code:
__int64 jcr_internal_pool_free()
{
return g_free();
}

canonical_decompiled_code:
__int64 func0()
{
return g_free();
}

original_code:
static void jcr_internal_pool_free(gpointer data, gpointer user_data) {
  g_free(data);
}

canonical_original_code:
static void jcr_internal_pool_free(void *data, void *user_data) {
  g_free(data);
}


decompiled_code:
char *__fastcall jcr_debug_msg(const char *a1, const char *a2, unsigned int a3)
{
buff_0[(int)ap_snprintf(buff_0, 127LL, "%s:%d (%s)", a1, a3, a2)] = 0;
return buff_0;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1, const char *a2, unsigned int a3)
{
buff_0[(int)ap_snprintf(buff_0, 127LL, "%s:%d (%s)", a1, a3, a2)] = 0;
return buff_0;
}

original_code:
char *jcr_debug_msg(const char *file, const char *function, int line) {
    static char buff[128];
    int i;
    i = ap_snprintf(buff,127,"%s:%d (%s)",file,line,function);
    buff[i] = '\0';
    return buff;
}

canonical_original_code:
char *jcr_debug_msg(char *file, char *function, int line) {
    static char buff[128];
    int i;
    i = ap_snprintf(buff,127,"%s:%d (%s)",file,line,function);
    buff[i] = '\0';
    return buff;
}

variable_types:
function
char *

variable_types:
buff
char [128]


decompiled_code:
__int64 jcr_main_new_stream()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // rbx
__int64 v4; // rbx
__int64 v5; // rax

v0 = jcr;
*(_QWORD *)(jcr + 112) = 0LL;
if ( *(_QWORD *)(v0 + 120) )
XML_ParserFree();
v1 = jcr;
*(_DWORD *)(jcr + 96) = -1;
*(_DWORD *)(v1 + 128) = 0;
*(_QWORD *)(v1 + 120) = XML_ParserCreate(0LL);
XML_SetElementHandler(*(_QWORD *)(jcr + 120), &jcr_start_element, &jcr_end_element);
XML_SetCharacterDataHandler(*(_QWORD *)(jcr + 120), &jcr_cdata);
XML_SetUserData(*(_QWORD *)(jcr + 120), 0LL);
while ( (unsigned int)jcr_socket_connect() )
sleep(2u);
v2 = jcr;
*(_QWORD *)(v2 + 8) = g_io_channel_unix_new(*(unsigned int *)(jcr + 96));
g_io_channel_set_encoding(*(_QWORD *)(jcr + 8), 0LL, 0LL);
g_io_channel_set_buffered(*(_QWORD *)(jcr + 8), 0LL);
v3 = jcr;
*(_QWORD *)(v3 + 24) = g_thread_create(&jcr_queue_deliver, 0LL, 1LL, 0LL);
v4 = jcr;
*(_DWORD *)(v4 + 32) = g_io_add_watch_full(*(_QWORD *)(jcr + 8), 4294967196LL, 57LL, &jcr_read_data, 0LL, 0LL);
jcr_send_start_stream();
v5 = jcr_debug_msg("jcr_main_stream_error.c", "jcr_main_new_stream", 50LL);
return log_notice(v5, "Server stream connected.");
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // rbx
__int64 v4; // rbx
__int64 v5; // rax

v0 = jcr;
*(_QWORD *)(jcr + 112) = 0LL;
if ( *(_QWORD *)(v0 + 120) )
XML_ParserFree();
v1 = jcr;
*(_DWORD *)(jcr + 96) = -1;
*(_DWORD *)(v1 + 128) = 0;
*(_QWORD *)(v1 + 120) = XML_ParserCreate(0LL);
XML_SetElementHandler(*(_QWORD *)(jcr + 120), &jcr_start_element, &jcr_end_element);
XML_SetCharacterDataHandler(*(_QWORD *)(jcr + 120), &jcr_cdata);
XML_SetUserData(*(_QWORD *)(jcr + 120), 0LL);
while ( (unsigned int)jcr_socket_connect() )
sleep(2u);
v2 = jcr;
*(_QWORD *)(v2 + 8) = g_io_channel_unix_new(*(unsigned int *)(jcr + 96));
g_io_channel_set_encoding(*(_QWORD *)(jcr + 8), 0LL, 0LL);
g_io_channel_set_buffered(*(_QWORD *)(jcr + 8), 0LL);
v3 = jcr;
*(_QWORD *)(v3 + 24) = g_thread_create(&jcr_queue_deliver, 0LL, 1LL, 0LL);
v4 = jcr;
*(_DWORD *)(v4 + 32) = g_io_add_watch_full(*(_QWORD *)(jcr + 8), 4294967196LL, 57LL, &jcr_read_data, 0LL, 0LL);
jcr_send_start_stream();
v5 = jcr_debug_msg("jcr_main_stream_error.c", "jcr_main_new_stream", 50LL);
return log_notice(v5, "Server stream connected.");
}

original_code:
void jcr_main_new_stream(void) {
  jcr->current = ((void *)0);
  if (jcr->parser)
    XML_ParserFree(jcr->parser);
  jcr->fd = -1;
  jcr->stream_state = 0;
  jcr->parser = XML_ParserCreate(((void *)0));
  XML_SetElementHandler(jcr->parser, (void *)jcr_start_element, (void *)jcr_end_element);
  XML_SetCharacterDataHandler(jcr->parser, (void *)jcr_cdata);
  XML_SetUserData(jcr->parser, ((void *)0));
  while (jcr_socket_connect()) {
    sleep(2);
  }
  jcr->gio = g_io_channel_unix_new(jcr->fd);
  g_io_channel_set_encoding(jcr->gio, ((void *)0), ((void *)0));
  g_io_channel_set_buffered(jcr->gio, (0));
  jcr->dthread = g_thread_create((void *)jcr_queue_deliver, ((void *)0), (!(0)), ((void *)0));
  jcr->gmain_watch_source = g_io_add_watch_full(jcr->gio, -100, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL), (void *)jcr_read_data, ((void *)0), ((void *)0));
  jcr_send_start_stream();
  log_notice(jcr_debug_msg("jcr_main_stream_error.c",__FUNCTION__,50), "Server stream connected.");
}

canonical_original_code:
void jcr_main_new_stream() {
  jcr->current = ((void *)0);
  if (jcr->parser)
    XML_ParserFree(jcr->parser);
  jcr->fd = -1;
  jcr->stream_state = 0;
  jcr->parser = XML_ParserCreate(((void *)0));
  XML_SetElementHandler(jcr->parser, (void *)jcr_start_element, (void *)jcr_end_element);
  XML_SetCharacterDataHandler(jcr->parser, (void *)jcr_cdata);
  XML_SetUserData(jcr->parser, ((void *)0));
  while (jcr_socket_connect()) {
    sleep(2);
  }
  jcr->gio = g_io_channel_unix_new(jcr->fd);
  g_io_channel_set_encoding(jcr->gio, ((void *)0), ((void *)0));
  g_io_channel_set_buffered(jcr->gio, (0));
  jcr->dthread = g_thread_create((void *)jcr_queue_deliver, ((void *)0), (!(0)), ((void *)0));
  jcr->gmain_watch_source = g_io_add_watch_full(jcr->gio, -100, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL), (void *)jcr_read_data, ((void *)0), ((void *)0));
  jcr_send_start_stream();
  log_notice(jcr_debug_msg("jcr_main_stream_error.c",__FUNCTION__,50), "Server stream connected.");
}


decompiled_code:
__int64 __fastcall pkg_data_mem_size(__int64 a1)
{
return (unsigned int)*(unsigned __int16 *)(a1 + 8) + 24;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return (unsigned int)*(unsigned __int16 *)(a1 + 8) + 24;
}

original_code:
uint32_t
pkg_data_mem_size(pkg_data_t *pkg)
{
    return sizeof(pkg_data_t) + pkg->data_len;
}

canonical_original_code:
unsigned int pkg_data_mem_size(struct pkg_data *pkg)
{
    return sizeof(pkg_data_t) + pkg->data_len;
}

variable_types: struct pkg_data { void *data; unsigned short data_len; unsigned short type; struct pkg_data *next; } *

return_type: unsigned int


decompiled_code:
__int64 __fastcall pkg_data_get_data(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
void *
pkg_data_get_data(pkg_data_t *pkt)
{
    return pkt->data;
}

canonical_original_code:
void *pkg_data_get_data(struct pkg_data *pkt)
{
    return pkt->data;
}

return_type: void *

user_defined_types: struct pkg_data { void *data; unsigned short data_len; unsigned short type; struct pkg_data *next; }


decompiled_code:
__int64 __fastcall pkg_data_get_type(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 10);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 10);
}

original_code:
uint16_t
pkg_data_get_type(pkg_data_t *pkt)
{
    return pkt->type;
}

canonical_original_code:
unsigned short pkg_data_get_type(struct pkg_data *pkt)
{
    return pkt->type;
}

return_type: unsigned short


decompiled_code:
__int64 __fastcall pkg_data_get_len(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 8);
}

original_code:
uint16_t
pkg_data_get_len(pkg_data_t *pkt)
{
    return pkt->data_len;
}

canonical_original_code:
unsigned short pkg_data_get_len(struct pkg_data *pkt)
{
    return pkt->data_len;
}


decompiled_code:
void __fastcall pkg_data_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void pkg_data_free(pkg_data_t *pkt)
{
    free(pkt->data);
    free(pkt);
}

canonical_original_code:
void pkg_data_free(struct pkg_data *pkt)
{
    free(pkt->data);
    free(pkt);
}


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

if ( *(_QWORD *)(a1 + 8) < a2 )
result = 0LL;
else
result = *(_QWORD *)(a1 + 32) + a2;
return result;
}

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

if ( *(_QWORD *)(a1 + 8) < a2 )
result = 0LL;
else
result = *(_QWORD *)(a1 + 32) + a2;
return result;
}

original_code:
static inline uint8_t *
buffer_at(const buffer_t *buffer, size_t at)
{
 if (at > buffer->_limit)
        return ((void *)0);
 return buffer->_data + at;
}

canonical_original_code:
static inline unsigned char *buffer_at(struct buffer *buffer, unsigned long at)
{
 if (at > buffer->_limit)
        return ((void *)0);
 return buffer->_data + at;
}

variable_types: struct buffer { unsigned long _position; unsigned long _limit; unsigned long _reservered_capacity; unsigned long _actual_capacity; unsigned char *_data; unsigned int _fixed; } *

variable_types:
at
unsigned long

return_type: unsigned char *


decompiled_code:
unsigned __int64 __fastcall buffer_current(unsigned __int64 *a1)
{
return buffer_at((__int64)a1, *a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(unsigned __int64 *a1)
{
return func3((__int64)a1, *a1);
}

original_code:
static inline uint8_t *
buffer_current(const buffer_t *buffer)
{
 return buffer_at(buffer, buffer->_position);
}

canonical_original_code:
static inline unsigned char *buffer_current(struct buffer *buffer)
{
 return buffer_at(buffer, buffer->_position);
}

user_defined_types: struct buffer { unsigned long _position; unsigned long _limit; unsigned long _reservered_capacity; unsigned long _actual_capacity; unsigned char *_data; unsigned int _fixed; }


decompiled_code:
__int64 __fastcall buffer_remaining(__int64 *a1)
{
return buffer_remaining_at((__int64)a1, *a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1)
{
return func5((__int64)a1, *a1, 0LL);
}

original_code:
static inline size_t
buffer_remaining(const buffer_t *buffer)
{
 return buffer_remaining_at(buffer, buffer->_position, 0);
}

canonical_original_code:
static inline unsigned long buffer_remaining(struct buffer *buffer)
{
 return buffer_remaining_at(buffer, buffer->_position, 0);
}

return_type: unsigned long


original_code:
void
buffer_create_from(buffer_t *buffer, void *data, size_t size)
{
    buffer->_position = 0;
    buffer->_limit = size;
    buffer->_actual_capacity = size;
    buffer->_reservered_capacity = size;
    buffer->_data = (uint8_t *) data;
    buffer->_fixed = 1;
}

canonical_original_code:
void buffer_create_from(struct buffer *buffer, void *data, unsigned long size)
{
    buffer->_position = 0;
    buffer->_limit = size;
    buffer->_actual_capacity = size;
    buffer->_reservered_capacity = size;
    buffer->_data = (unsigned char *) data;
    buffer->_fixed = 1;
}

variable_types:
size
unsigned long


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

result = 0LL;
if ( *(_QWORD *)a1 <= a2 )
{
*(_QWORD *)(a1 + 32) = realloc(*(void **)(a1 + 32), a2);
*(_QWORD *)(a1 + 24) = a2;
*(_QWORD *)(a1 + 16) = a2;
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( *(_QWORD *)a1 <= a2 )
{
*(_QWORD *)(a1 + 32) = realloc(*(void **)(a1 + 32), a2);
*(_QWORD *)(a1 + 24) = a2;
*(_QWORD *)(a1 + 16) = a2;
result = 1LL;
}
return result;
}

original_code:
_Bool
buffer_set_capacity(buffer_t *buffer, size_t capacity)
{
 if (buffer->_position > capacity)
        return 0;
    buffer->_data = realloc(buffer->_data, capacity);
 buffer->_actual_capacity = capacity;
 buffer->_reservered_capacity = capacity;
    return 1;
}

canonical_original_code:
_Bool buffer_set_capacity(struct buffer *buffer, unsigned long capacity)
{
 if (buffer->_position > capacity)
        return 0;
    buffer->_data = realloc(buffer->_data, capacity);
 buffer->_actual_capacity = capacity;
 buffer->_reservered_capacity = capacity;
    return 1;
}

variable_types:
capacity
unsigned long


decompiled_code:
__int64 __fastcall buffer_create(__int64 a1, size_t a2)
{
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 32) = 0LL;
*(_BYTE *)(a1 + 40) &= 0xFEu;
return buffer_set_capacity(a1, a2);
}

original_code:
void
buffer_create(buffer_t *buffer, size_t init_size)
{
    buffer->_position = 0;
    buffer->_limit = init_size;
    buffer->_data = ((void *)0);
    buffer->_fixed = 0;
    buffer_set_capacity(buffer, init_size);
}

canonical_original_code:
void buffer_create(struct buffer *buffer, unsigned long init_size)
{
    buffer->_position = 0;
    buffer->_limit = init_size;
    buffer->_data = ((void *)0);
    buffer->_fixed = 0;
    buffer_set_capacity(buffer, init_size);
}


decompiled_code:
__int64 __fastcall buffer_reserve(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rsi
__int64 result; // rax
char v4[216]; // [rsp+0h] [rbp-D8h] BYREF

if ( (*(_BYTE *)(a1 + 40) & 1) != 0 )
{
strcpy(v4, "fixed buffer can not be reserved\n");
printf("%s in file %s at line %d\n", v4, "../src/dig_buffer.c", 62LL);
exit(1);
}
v2 = *(_QWORD *)a1 + a2;
if ( *(_QWORD *)(a1 + 16) < v2 )
{
if ( v2 < (unsigned __int64)(3LL * *(_QWORD *)(a1 + 24)) >> 1 )
v2 = (unsigned __int64)(3LL * *(_QWORD *)(a1 + 24)) >> 1;
buffer_set_capacity(a1, v2);
}
result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rsi
__int64 result; // rax
char v4[216]; // [rsp+0h] [rbp-D8h] BYREF

if ( (*(_BYTE *)(a1 + 40) & 1) != 0 )
{
strcpy(v4, "fixed buffer can not be reserved\n");
printf("%s in file %s at line %d\n", v4, "../src/dig_buffer.c", 62LL);
exit(1);
}
v2 = *(_QWORD *)a1 + a2;
if ( *(_QWORD *)(a1 + 16) < v2 )
{
if ( v2 < (unsigned __int64)(3LL * *(_QWORD *)(a1 + 24)) >> 1 )
v2 = (unsigned __int64)(3LL * *(_QWORD *)(a1 + 24)) >> 1;
func10(a1, v2);
}
result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
void
buffer_reserve(buffer_t *buffer, size_t amount)
{
 do{ if (!(!(buffer->_fixed))) { char str[200]; sprintf(str, "fixed buffer can not be reserved\n"); printf("%s in file %s at line %d\n", str, "../src/dig_buffer.c", 62); exit(1); }}while (0);
 if (buffer->_reservered_capacity < buffer->_position + amount)
    {
  size_t new_capacity = buffer->_actual_capacity * 3 / 2;
  if (new_capacity < buffer->_position + amount)
   new_capacity = buffer->_position + amount;
  buffer_set_capacity(buffer, new_capacity);
 }
 buffer->_limit = buffer->_actual_capacity;
}

canonical_original_code:
void buffer_reserve(struct buffer *buffer, unsigned long amount)
{
 do{ if (!(!(buffer->_fixed))) { char str[200]; sprintf(str, "fixed buffer can not be reserved\n"); printf("%s in file %s at line %d\n", str, "../src/dig_buffer.c", 62); exit(1); }}while (0);
 if (buffer->_reservered_capacity < buffer->_position + amount)
    {
  unsigned long new_capacity = buffer->_actual_capacity * 3 / 2;
  if (new_capacity < buffer->_position + amount)
   new_capacity = buffer->_position + amount;
  buffer_set_capacity(buffer, new_capacity);
 }
 buffer->_limit = buffer->_actual_capacity;
}

variable_types:
amount
unsigned long

variable_types:
str
char [200]


decompiled_code:
__int64 buffer_printf(__int64 *a1, const char *a2, ...)
{
unsigned __int64 v2; // rbp
char *v3; // rax
int v4; // eax
unsigned int v5; // edx
const char *v7; // rsi
__int64 v8; // rcx
char *v9; // rdi
char v10[200]; // [rsp+0h] [rbp-1A8h] BYREF
gcc_va_list arg; // [rsp+C8h] [rbp-E0h] BYREF

if ( a1[1] != a1[2] )
{
v7 = "read limit is not the same as capacity of a buffer\n";
v8 = 13LL;
v9 = v10;
while ( v8 )
{
*(_DWORD *)v9 = *(_DWORD *)v7;
v7 += 4;
v9 += 4;
--v8;
}
printf("%s in file %s at line %d\n", v10, "../src/dig_buffer.c", 81LL);
exit(1);
}
v2 = buffer_remaining(a1);
va_start(arg, a2);
v3 = (char *)buffer_current((unsigned __int64 *)a1);
v4 = vsnprintf(v3, v2, a2, arg);
if ( v4 < 0 || (v5 = 0, v4 < v2) )
{
*a1 += v4;
v5 = v4;
}
return v5;
}

canonical_decompiled_code:
__int64 func13(__int64 *a1, const char *a2, ...)
{
unsigned __int64 v2; // rbp
char *v3; // rax
int v4; // eax
unsigned int v5; // edx
const char *v7; // rsi
__int64 v8; // rcx
char *v9; // rdi
char v10[200]; // [rsp+0h] [rbp-1A8h] BYREF
gcc_va_list arg; // [rsp+C8h] [rbp-E0h] BYREF

if ( a1[1] != a1[2] )
{
v7 = "read limit is not the same as capacity of a buffer\n";
v8 = 13LL;
v9 = v10;
while ( v8 )
{
*(_DWORD *)v9 = *(_DWORD *)v7;
v7 += 4;
v9 += 4;
--v8;
}
printf("%s in file %s at line %d\n", v10, "../src/dig_buffer.c", 81LL);
exit(1);
}
v2 = func6(a1);
va_start(arg, a2);
v3 = (char *)func4((unsigned __int64 *)a1);
v4 = vsnprintf(v3, v2, a2, arg);
if ( v4 < 0 || (v5 = 0, v4 < v2) )
{
*a1 += v4;
v5 = v4;
}
return v5;
}

original_code:
uint32_t
buffer_printf(buffer_t *buffer, const char *format, ...)
{
 va_list args;
 int written;
 size_t remaining;
 do{ if (!(buffer->_limit == buffer->_reservered_capacity)) { char str[200]; sprintf(str, "read limit is not the same as capacity of a buffer\n"); printf("%s in file %s at line %d\n", str, "../src/dig_buffer.c", 81); exit(1); }}while (0);
 remaining = buffer_remaining(buffer);
 __builtin_va_start(args,format);
 written = vsnprintf((char *) buffer_current(buffer), remaining,
       format, args);
 __builtin_va_end(args);
 if (written >= 0 && (size_t) written >= remaining)
        return 0;
 buffer->_position += written;
 return (uint32_t)written;
}

canonical_original_code:
unsigned int buffer_printf(struct buffer *buffer, char *format, ...)
{
 __builtin_va_list args;
 int written;
 unsigned long remaining;
 do{ if (!(buffer->_limit == buffer->_reservered_capacity)) { char str[200]; sprintf(str, "read limit is not the same as capacity of a buffer\n"); printf("%s in file %s at line %d\n", str, "../src/dig_buffer.c", 81); exit(1); }}while (0);
 remaining = buffer_remaining(buffer);
 __builtin_va_start(args,format);
 written = vsnprintf((char *) buffer_current(buffer), remaining,
       format, args);
 __builtin_va_end(args);
 if (written >= 0 && (unsigned long) written >= remaining)
        return 0;
 buffer->_position += written;
 return (unsigned int)written;
}

variable_types:
format
char *

variable_types: written int

variable_types:
remaining
unsigned long


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

if ( *(_QWORD *)(a1 + 8) )
{
v1 = 0LL;
do
{
if ( 20 * ((int)v1 / 20) == (_DWORD)v1 )
putchar(10);
printf("%02x", *(unsigned __int8 *)(*(_QWORD *)(a1 + 32) + v1++));
}
while ( *(_QWORD *)(a1 + 8) > v1 );
}
return putchar(10);
}

original_code:
void
buffer_dump(buffer_t *buffer)
{
    int i;
    for (i = 0; i < buffer->_limit; i++)
    {
        if (i % 20 == 0)
            printf("\n");
        printf("%02x", buffer->_data[i]);
    }
    printf("\n");
}

canonical_original_code:
void buffer_dump(struct buffer *buffer)
{
    int i;
    for (i = 0; i < buffer->_limit; i++)
    {
        if (i % 20 == 0)
            printf("\n");
        printf("%02x", buffer->_data[i]);
    }
    printf("\n");
}

variable_types: i int


decompiled_code:
int __fastcall mem_dump(__int64 a1, int a2)
{
unsigned __int64 v3[7]; // [rsp+0h] [rbp-38h] BYREF

buffer_create_from((__int64)v3, a1, a2);
buffer_set_limit(v3, a2);
return buffer_dump((__int64)v3);
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, int a2)
{
unsigned __int64 v3[7]; // [rsp+0h] [rbp-38h] BYREF

func7((__int64)v3, a1, a2);
func1(v3, a2);
return func14((__int64)v3);
}

original_code:
void
mem_dump(char *mem, int len)
{
    buffer_t buf;
    buffer_create_from(&buf, mem, len);
    buffer_set_limit(&buf, len);
    buffer_dump(&buf);
}

canonical_original_code:
void mem_dump(char *mem, int len)
{
    struct buffer buf;
    buffer_create_from(&buf, mem, len);
    buffer_set_limit(&buf, len);
    buffer_dump(&buf);
}

variable_types:
mem
char *

variable_types: len int

variable_types: struct buffer { unsigned long _position; unsigned long _limit; unsigned long _reservered_capacity; unsigned long _actual_capacity; unsigned char *_data; unsigned int _fixed; }


decompiled_code:
__int64 __fastcall buffer_add_capacity(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rax

v2 = buffer_position(a1) + a2;
v3 = buffer_reservered_capacity(a1);
return buffer_set_capacity(a1, v3 * (int)(v2 / v3 + 1));
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rax

v2 = func0(a1) + a2;
v3 = func2(a1);
return func10(a1, v3 * (int)(v2 / v3 + 1));
}

original_code:
_Bool
buffer_add_capacity(buffer_t *buffer, size_t add_capacity)
{
    int num = (buffer_position(buffer) + add_capacity) / buffer_reservered_capacity(buffer);
    return buffer_set_capacity(buffer, buffer_reservered_capacity(buffer) * (num + 1));
}

canonical_original_code:
_Bool buffer_add_capacity(struct buffer *buffer, unsigned long add_capacity)
{
    int num = (buffer_position(buffer) + add_capacity) / buffer_reservered_capacity(buffer);
    return buffer_set_capacity(buffer, buffer_reservered_capacity(buffer) * (num + 1));
}

variable_types: num int


decompiled_code:
int __fastcall socket_close(int *a1)
{
return close(*a1);
}

canonical_decompiled_code:
int __fastcall func1(int *a1)
{
return close(*a1);
}

original_code:
void
socket_close(socket_t *s)
{
    close(((s)->fd));
}

canonical_original_code:
void socket_close(struct msocket *s)
{
    close(((s)->fd));
}

variable_types: struct msocket { int fd; int type; int family; } *


decompiled_code:
int __fastcall socket_set_addr_reusable(int *a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
return setsockopt(*a1, 1, 2, optval, 4u);
}

canonical_decompiled_code:
int __fastcall func3(int *a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
return setsockopt(*a1, 1, 2, optval, 4u);
}

original_code:
int
socket_set_addr_reusable(socket_t *s)
{
    int flag = 1;
    return setsockopt(((s)->fd), 1, 2,
                                                        &flag, sizeof(int));
}

canonical_original_code:
int socket_set_addr_reusable(struct msocket *s)
{
    int flag = 1;
    return setsockopt(((s)->fd), 1, 2,
                                                        &flag, sizeof(int));
}

variable_types: flag int

user_defined_types: struct msocket { int fd; int type; int family; }


decompiled_code:
int __fastcall socket_set_rdtimeout(int *a1, int a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 0LL;
return setsockopt(*a1, 1, 20, v3, 0x10u);
}

canonical_decompiled_code:
int __fastcall func4(int *a1, int a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 0LL;
return setsockopt(*a1, 1, 20, v3, 0x10u);
}

original_code:
int
socket_set_rdtimeout(socket_t *s, int secs)
{
    struct timeval tm;
    tm.tv_sec = secs;
    tm.tv_usec = 0;
    return setsockopt(((s)->fd), 1, 20, &tm, sizeof(tm));
}

canonical_original_code:
int socket_set_rdtimeout(struct msocket *s, int secs)
{
    struct timeval tm;
    tm.tv_sec = secs;
    tm.tv_usec = 0;
    return setsockopt(((s)->fd), 1, 20, &tm, sizeof(tm));
}

variable_types: secs int

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
int __fastcall socket_set_notimewait(int *a1)
{
int optval[4]; // [rsp+8h] [rbp-10h] BYREF

optval[0] = 1;
optval[1] = 0;
return setsockopt(*a1, 1, 13, optval, 8u);
}

canonical_decompiled_code:
int __fastcall func5(int *a1)
{
int optval[4]; // [rsp+8h] [rbp-10h] BYREF

optval[0] = 1;
optval[1] = 0;
return setsockopt(*a1, 1, 13, optval, 8u);
}

original_code:
int
socket_set_notimewait(socket_t *s)
{
    struct linger nowait_linger;
    nowait_linger.l_onoff = 1;
    nowait_linger.l_linger = 0;
    return setsockopt(((s)->fd),
                      1,
                      13,
                      (const void *)&nowait_linger,
                      sizeof(struct linger));
}

canonical_original_code:
int socket_set_notimewait(struct msocket *s)
{
    struct linger nowait_linger;
    nowait_linger.l_onoff = 1;
    nowait_linger.l_linger = 0;
    return setsockopt(((s)->fd),
                      1,
                      13,
                      (void *)&nowait_linger,
                      sizeof(struct linger));
}

variable_types: struct linger { int l_onoff; int l_linger; }


decompiled_code:
int __fastcall socket_connect(int *a1, __int64 a2)
{
socklen_t v2; // er12
const struct sockaddr *v3; // rax

v2 = addr_get_socklen(a2);
v3 = (const struct sockaddr *)addr_to_sockaddr(a2);
return connect(*a1, v3, v2);
}

canonical_decompiled_code:
int __fastcall func6(int *a1, __int64 a2)
{
socklen_t v2; // er12
const struct sockaddr *v3; // rax

v2 = addr_get_socklen(a2);
v3 = (const struct sockaddr *)addr_to_sockaddr(a2);
return connect(*a1, v3, v2);
}

original_code:
int
socket_connect(socket_t *s, const addr_t *server_addr)
{
    return connect(((s)->fd),
                   addr_to_sockaddr(server_addr),
                   addr_get_socklen(server_addr));
}

canonical_original_code:
int socket_connect(struct msocket *s, struct _addr *server_addr)
{
    return connect(((s)->fd),
                   addr_to_sockaddr(server_addr),
                   addr_get_socklen(server_addr));
}

variable_types: struct _addr { union { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr_v4; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } addr_v6; }; int mask; enum addr_type_t { ADDR_IPV4=0, ADDR_IPV6=1 } addr_type; } *

user_defined_types: struct _addr { union { struct sockaddr_in addr_v4; struct sockaddr_in6 addr_v6; }; int mask; enum addr_type_t addr_type; }

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

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


decompiled_code:
__int64 __fastcall socket_connect_with_timeout(int *a1, __int64 a2, unsigned int a3)
{
unsigned int v5; // ebx
int v7; // edi
int v8; // eax
struct timeval v9; // [rsp+0h] [rbp-A8h] BYREF
fd_set writefds; // [rsp+10h] [rbp-98h] BYREF

v5 = socket_connect(a1, a2);
if ( v5 && *_errno_location() == 115 )
{
memset(&writefds, 0, sizeof(writefds));
v7 = *a1;
v8 = *a1 + 63;
if ( *a1 >= 0 )
v8 = *a1;
writefds.fds_bits[v8 >> 6] |= 1LL << (v7 % 64);
v9.tv_sec = a3;
v9.tv_usec = 0LL;
v5 = select(v7 + 1, 0LL, &writefds, 0LL, &v9) <= 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1, __int64 a2, unsigned int a3)
{
unsigned int v5; // ebx
int v7; // edi
int v8; // eax
struct timeval v9; // [rsp+0h] [rbp-A8h] BYREF
fd_set writefds; // [rsp+10h] [rbp-98h] BYREF

v5 = func6(a1, a2);
if ( v5 && *_errno_location() == 115 )
{
memset(&writefds, 0, sizeof(writefds));
v7 = *a1;
v8 = *a1 + 63;
if ( *a1 >= 0 )
v8 = *a1;
writefds.fds_bits[v8 >> 6] |= 1LL << (v7 % 64);
v9.tv_sec = a3;
v9.tv_usec = 0LL;
v5 = select(v7 + 1, 0LL, &writefds, 0LL, &v9) <= 0;
}
return v5;
}

original_code:
int
socket_connect_with_timeout(socket_t *s,
                            const addr_t *server_addr,
                            uint32_t sec_to_wait)
{
    int ret = socket_connect(s, server_addr);
    if (ret != 0)
    {
        if (115 == (*__errno_location ()))
        {
            fd_set set;
            do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
            ((void) (((&set)->__fds_bits)[((((s)->fd)) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((((s)->fd)) % (8 * (int) sizeof (__fd_mask)))))));
            struct timeval tv;
            tv.tv_sec = sec_to_wait;
            tv.tv_usec = 0;
            if (select(((s)->fd) + 1, ((void *)0), &set, ((void *)0), &tv) > 0)
                ret = 0;
            else
                ret = 1;
        }
    }
    return ret;
}

canonical_original_code:
int socket_connect_with_timeout(struct msocket *s, struct _addr *server_addr, unsigned int sec_to_wait)
{
    int ret = socket_connect(s, server_addr);
    if (ret != 0)
    {
        if (115 == (*__errno_location ()))
        {
            struct fd_set set;
            do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
            ((void) (((&set)->__fds_bits)[((((s)->fd)) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((((s)->fd)) % (8 * (int) sizeof (__fd_mask)))))));
            struct timeval tv;
            tv.tv_sec = sec_to_wait;
            tv.tv_usec = 0;
            if (select(((s)->fd) + 1, ((void *)0), &set, ((void *)0), &tv) > 0)
                ret = 0;
            else
                ret = 1;
        }
    }
    return ret;
}

variable_types: ret int

variable_types:
set
struct fd_set { long __fds_bits[-1]; }

user_defined_types: struct timeval { long tv_sec; long tv_usec; }

user_defined_types: enum addr_type_t { ADDR_IPV4=0, ADDR_IPV6=1 }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
int __fastcall socket_bind(int *a1, __int64 a2)
{
socklen_t v2; // er12
const struct sockaddr *v3; // rax

v2 = addr_get_socklen(a2);
v3 = (const struct sockaddr *)addr_to_sockaddr(a2);
return bind(*a1, v3, v2);
}

canonical_decompiled_code:
int __fastcall func8(int *a1, __int64 a2)
{
socklen_t v2; // er12
const struct sockaddr *v3; // rax

v2 = addr_get_socklen(a2);
v3 = (const struct sockaddr *)addr_to_sockaddr(a2);
return bind(*a1, v3, v2);
}

original_code:
int
socket_bind(socket_t *s, const addr_t *addr)
{
    return bind(((s)->fd), addr_to_sockaddr(addr), addr_get_socklen(addr));
}

canonical_original_code:
int socket_bind(struct msocket *s, struct _addr *addr)
{
    return bind(((s)->fd), addr_to_sockaddr(addr), addr_get_socklen(addr));
}


decompiled_code:
int __fastcall socket_listen(int *a1, int a2)
{
return listen(*a1, a2);
}

canonical_decompiled_code:
int __fastcall func9(int *a1, int a2)
{
return listen(*a1, a2);
}

original_code:
int
socket_listen(socket_t *s, int pending_request)
{
    return listen(((s)->fd), pending_request);
}

canonical_original_code:
int socket_listen(struct msocket *s, int pending_request)
{
    return listen(((s)->fd), pending_request);
}


decompiled_code:
ssize_t __fastcall socket_read(int *a1, char *a2, size_t a3)
{
char *v3; // rbp
int v4; // er13
size_t v5; // rbx
ssize_t v6; // rax

v3 = a2;
v4 = a3;
if ( a1[1] != 1 )
return recv(*a1, a2, a3, 0);
if ( a3 )
{
v5 = a3;
do
{
v6 = read(*a1, v3, v5);
if ( !v6 )
break;
v3 += v6;
v5 -= v6;
}
while ( v5 );
}
else
{
LODWORD(v5) = 0;
}
return (unsigned int)(v4 - v5);
}

canonical_decompiled_code:
ssize_t __fastcall func10(int *a1, char *a2, size_t a3)
{
char *v3; // rbp
int v4; // er13
size_t v5; // rbx
ssize_t v6; // rax

v3 = a2;
v4 = a3;
if ( a1[1] != 1 )
return recv(*a1, a2, a3, 0);
if ( a3 )
{
v5 = a3;
do
{
v6 = read(*a1, v3, v5);
if ( !v6 )
break;
v3 += v6;
v5 -= v6;
}
while ( v5 );
}
else
{
LODWORD(v5) = 0;
}
return (unsigned int)(v4 - v5);
}

original_code:
int
socket_read(socket_t *s, void *buffer, size_t len)
{
    if (((s)->type) == SOCK_STREAM)
    {
        char *read_pos = buffer;
        size_t left_len = len;
        size_t read_len = 0;
        while (left_len > 0)
        {
            if ((read_len = read(((s)->fd), read_pos, left_len)) < 0)
            {
                if ((*__errno_location ()) == 4)
                    read_len = 0;
                else
                    return -1;
            }
            else if (read_len == 0)
                break;
            left_len -= read_len;
            read_pos += read_len;
        }
        return len - left_len;
    }
    else
    {
        return recv(((s)->fd), buffer, len, 0);
    }
}

canonical_original_code:
int socket_read(struct msocket *s, void *buffer, unsigned long len)
{
    if (((s)->type) == SOCK_STREAM)
    {
        char *read_pos = buffer;
        unsigned long left_len = len;
        unsigned long read_len = 0;
        while (left_len > 0)
        {
            if ((read_len = read(((s)->fd), read_pos, left_len)) < 0)
            {
                if ((*__errno_location ()) == 4)
                    read_len = 0;
                else
                    return -1;
            }
            else if (read_len == 0)
                break;
            left_len -= read_len;
            read_pos += read_len;
        }
        return len - left_len;
    }
    else
    {
        return recv(((s)->fd), buffer, len, 0);
    }
}

variable_types:
buffer
void *

variable_types:
len
unsigned long


decompiled_code:
ssize_t __fastcall socket_write(int *a1, char *a2, size_t a3)
{
char *v3; // rbp
unsigned int v4; // er13
size_t v5; // rbx
ssize_t v6; // rax

v3 = a2;
v4 = a3;
if ( a1[1] != 1 )
return send(*a1, a2, a3, 0);
if ( !a3 )
return v4;
v5 = a3;
while ( 1 )
{
v6 = write(*a1, v3, v5);
if ( v6 <= 0 )
break;
LABEL_4:
v3 += v6;
v5 -= v6;
if ( !v5 )
return v4;
}
if ( v6 >= 0 )
return 0xFFFFFFFFLL;
if ( *_errno_location() == 4 )
{
v6 = 0LL;
goto LABEL_4;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
ssize_t __fastcall func12(int *a1, char *a2, size_t a3)
{
char *v3; // rbp
unsigned int v4; // er13
size_t v5; // rbx
ssize_t v6; // rax

v3 = a2;
v4 = a3;
if ( a1[1] != 1 )
return send(*a1, a2, a3, 0);
if ( !a3 )
return v4;
v5 = a3;
while ( 1 )
{
v6 = write(*a1, v3, v5);
if ( v6 <= 0 )
break;
LABEL_4:
v3 += v6;
v5 -= v6;
if ( !v5 )
return v4;
}
if ( v6 >= 0 )
return 0xFFFFFFFFLL;
if ( *_errno_location() == 4 )
{
v6 = 0LL;
goto LABEL_4;
}
return 0xFFFFFFFFLL;
}

original_code:
int
socket_write(socket_t *s, void *buffer, size_t len)
{
    if (((s)->type) == SOCK_STREAM)
    {
        size_t left_len = len;
        ssize_t written_len = 0;
        char *write_pos = buffer;
        while (left_len > 0)
        {
            if ((written_len = write(((s)->fd), write_pos, left_len)) <= 0)
            {
                if (written_len < 0 && (*__errno_location ()) == 4)
                    written_len = 0;
                else
                    return -1;
            }
            left_len -= written_len;
            write_pos += written_len;
        }
        return len;
    }
    else
    {
        return send(((s)->fd), buffer, len, 0);
    }
}

canonical_original_code:
int socket_write(struct msocket *s, void *buffer, unsigned long len)
{
    if (((s)->type) == SOCK_STREAM)
    {
        unsigned long left_len = len;
        long written_len = 0;
        char *write_pos = buffer;
        while (left_len > 0)
        {
            if ((written_len = write(((s)->fd), write_pos, left_len)) <= 0)
            {
                if (written_len < 0 && (*__errno_location ()) == 4)
                    written_len = 0;
                else
                    return -1;
            }
            left_len -= written_len;
            write_pos += written_len;
        }
        return len;
    }
    else
    {
        return send(((s)->fd), buffer, len, 0);
    }
}


decompiled_code:
__int64 __fastcall swap_int8(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax

result = (unsigned __int8)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

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

result = (unsigned __int8)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
static void swap_int8(uint8_t* x, uint8_t* y)
{
 uint8_t t = *x; *x = *y; *y = t;
}

canonical_original_code:
static void swap_int8(unsigned char *x, unsigned char *y)
{
 unsigned char t = *x; *x = *y; *y = t;
}

variable_types:
x
unsigned char *

variable_types:
y
unsigned char *

variable_types:
t
unsigned char


decompiled_code:
void **__fastcall rbtree_next(void **a1)
{
void **v1; // rax
void **v2; // rdx

v1 = (void **)a1[2];
if ( v1 == &rbtree_null_node )
{
v2 = (void **)*a1;
if ( *a1 != &rbtree_null_node )
{
while ( v2[2] == a1 )
{
a1 = v2;
if ( *v2 == &rbtree_null_node )
return (void **)*v2;
v2 = (void **)*v2;
}
}
}
else
{
do
{
v2 = v1;
v1 = (void **)v1[1];
}
while ( v1 != &rbtree_null_node );
}
return v2;
}

canonical_decompiled_code:
void **__fastcall func12(void **a1)
{
void **v1; // rax
void **v2; // rdx

v1 = (void **)a1[2];
if ( v1 == &rbtree_null_node )
{
v2 = (void **)*a1;
if ( *a1 != &rbtree_null_node )
{
while ( v2[2] == a1 )
{
a1 = v2;
if ( *v2 == &rbtree_null_node )
return (void **)*v2;
v2 = (void **)*v2;
}
}
}
else
{
do
{
v2 = v1;
v1 = (void **)v1[1];
}
while ( v1 != &rbtree_null_node );
}
return v2;
}

original_code:
rbnode_t *
rbtree_next (rbnode_t *node)
{
 rbnode_t *parent;
 if (node->right != &rbtree_null_node) {
  for (node = node->right; node->left != &rbtree_null_node; node = node->left);
 } else {
  parent = node->parent;
  while (parent != &rbtree_null_node && node == parent->right) {
   node = parent;
   parent = parent->parent;
  }
  node = parent;
 }
 return node;
}

canonical_original_code:
struct rbnode_t *rbtree_next(struct rbnode_t *node)
{
 struct rbnode_t *parent;
 if (node->right != &rbtree_null_node) {
  for (node = node->right; node->left != &rbtree_null_node; node = node->left);
 } else {
  parent = node->parent;
  while (parent != &rbtree_null_node && node == parent->right) {
   node = parent;
   parent = parent->parent;
  }
  node = parent;
 }
 return node;
}

variable_types:
node
struct rbnode_t *

variable_types: struct rbnode_t { struct rbnode_t *parent; struct rbnode_t *left; struct rbnode_t *right; void *mkey; void *value; unsigned char color; } *


decompiled_code:
void **__fastcall rbtree_previous(void **a1)
{
void **v1; // rax
void **v2; // rdx

v1 = (void **)a1[1];
if ( v1 == &rbtree_null_node )
{
v2 = (void **)*a1;
if ( *a1 != &rbtree_null_node )
{
while ( v2[1] == a1 )
{
a1 = v2;
if ( *v2 == &rbtree_null_node )
return (void **)*v2;
v2 = (void **)*v2;
}
}
}
else
{
do
{
v2 = v1;
v1 = (void **)v1[2];
}
while ( v1 != &rbtree_null_node );
}
return v2;
}

canonical_decompiled_code:
void **__fastcall func13(void **a1)
{
void **v1; // rax
void **v2; // rdx

v1 = (void **)a1[1];
if ( v1 == &rbtree_null_node )
{
v2 = (void **)*a1;
if ( *a1 != &rbtree_null_node )
{
while ( v2[1] == a1 )
{
a1 = v2;
if ( *v2 == &rbtree_null_node )
return (void **)*v2;
v2 = (void **)*v2;
}
}
}
else
{
do
{
v2 = v1;
v1 = (void **)v1[2];
}
while ( v1 != &rbtree_null_node );
}
return v2;
}

original_code:
rbnode_t *
rbtree_previous(rbnode_t *node)
{
 rbnode_t *parent;
 if (node->left != &rbtree_null_node) {
  for (node = node->left; node->right != &rbtree_null_node; node = node->right);
 } else {
  parent = node->parent;
  while (parent != &rbtree_null_node && node == parent->left) {
   node = parent;
   parent = parent->parent;
  }
  node = parent;
 }
 return node;
}

canonical_original_code:
struct rbnode_t *rbtree_previous(struct rbnode_t *node)
{
 struct rbnode_t *parent;
 if (node->left != &rbtree_null_node) {
  for (node = node->left; node->right != &rbtree_null_node; node = node->right);
 } else {
  parent = node->parent;
  while (parent != &rbtree_null_node && node == parent->left) {
   node = parent;
   parent = parent->parent;
  }
  node = parent;
 }
 return node;
}

return_type: struct rbnode_t { struct rbnode_t *parent; struct rbnode_t *left; struct rbnode_t *right; void *mkey; void *value; unsigned char color; } *


decompiled_code:
__int64 __fastcall radix_tree_walk_helper(_QWORD *a1, __int64 (*a2)(void))
{
__int64 result; // rax

if ( a1[1] )
result = ((__int64 (*)(void))radix_tree_walk_helper)();
if ( *a1 )
result = radix_tree_walk_helper(*a1, a2);
if ( a1[3] )
result = a2();
return result;
}

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

if ( a1[1] )
result = ((__int64 (*)(void))radix_tree_walk_helper)();
if ( *a1 )
result = func0(*a1, a2);
if ( a1[3] )
result = a2();
return result;
}

original_code:
static void
radix_tree_walk_helper(radix_node_t *node, value_func value_function)
{
    if (node->left)
        radix_tree_walk_helper(node->left, value_function);
    if (node->right)
        radix_tree_walk_helper(node->right, value_function);
    if (!((void *)((void *)0) == ((node)->value)))
        value_function(node->value);
}

canonical_original_code:
static void radix_tree_walk_helper(struct radix_node *node, void (*value_function)(void *value))
{
    if (node->left)
        radix_tree_walk_helper(node->left, value_function);
    if (node->right)
        radix_tree_walk_helper(node->right, value_function);
    if (!((void *)((void *)0) == ((node)->value)))
        value_function(node->value);
}

variable_types: struct radix_node { struct radix_node *right; struct radix_node *left; struct radix_node *parent; void *value; } *


decompiled_code:
void __fastcall ip_node_delete(__int64 *a1, void (*a2)(void))
{
__int64 v3; // rdi

if ( a1 )
{
if ( a1[1] )
((void (*)(void))ip_node_delete)();
v3 = *a1;
if ( *a1 )
ip_node_delete(v3, a2);
if ( a2 )
{
if ( a1[3] )
a2();
}
free(a1);
}
}

original_code:
static void
ip_node_delete(radix_node_t *node, value_func del_func)
{
    if (node)
    {
        if (node->left)
            ip_node_delete(node->left, del_func);
        if (node->right)
            ip_node_delete(node->right, del_func);
        if (!((void *)((void *)0) == ((node)->value)) && del_func)
            del_func(node->value);
        free(node);
    }
}

canonical_original_code:
static void ip_node_delete(struct radix_node *node, void (*del_func)(void *value))
{
    if (node)
    {
        if (node->left)
            ip_node_delete(node->left, del_func);
        if (node->right)
            ip_node_delete(node->right, del_func);
        if (!((void *)((void *)0) == ((node)->value)) && del_func)
            del_func(node->value);
        free(node);
    }
}

user_defined_types: struct radix_node { struct radix_node *right; struct radix_node *left; struct radix_node *parent; void *value; }


decompiled_code:
__int64 __fastcall trim_binary_subnet(void *src, _DWORD *a2)
{
char *v2; // rax
char *v3; // rbx
char v4; // al
char *v5; // rdx
unsigned int v6; // er13
size_t v7; // rbx
unsigned int buf; // [rsp+Ch] [rbp-5Ch] BYREF
char dest[88]; // [rsp+10h] [rbp-58h] BYREF

v2 = strchr((const char *)src, 47);
if ( !v2 )
return (unsigned int)-1;
v3 = v2;
v4 = v2[1];
if ( v4 )
{
v5 = v3 + 2;
while ( (unsigned __int8)(v4 - 48) <= 9u )
{
v4 = *v5++;
if ( !v4 )
goto LABEL_6;
}
v6 = -1;
}
else
{
LABEL_6:
v6 = atoi(v3 + 1);
if ( v6 - 1 > 0x1F )
{
v6 = -1;
}
else
{
v7 = v3 - (_BYTE *)src;
memcpy(dest, src, v7);
dest[v7] = 0;
if ( inet_pton(2, dest, &buf) == 1 )
*a2 = _bswap_32(buf);
else
v6 = -1;
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *src, _DWORD *a2)
{
char *v2; // rax
char *v3; // rbx
char v4; // al
char *v5; // rdx
unsigned int v6; // er13
size_t v7; // rbx
unsigned int buf; // [rsp+Ch] [rbp-5Ch] BYREF
char dest[88]; // [rsp+10h] [rbp-58h] BYREF

v2 = strchr((const char *)src, 47);
if ( !v2 )
return (unsigned int)-1;
v3 = v2;
v4 = v2[1];
if ( v4 )
{
v5 = v3 + 2;
while ( (unsigned __int8)(v4 - 48) <= 9u )
{
v4 = *v5++;
if ( !v4 )
goto LABEL_6;
}
v6 = -1;
}
else
{
LABEL_6:
v6 = atoi(v3 + 1);
if ( v6 - 1 > 0x1F )
{
v6 = -1;
}
else
{
v7 = v3 - (_BYTE *)src;
memcpy(dest, src, v7);
dest[v7] = 0;
if ( inet_pton(2, dest, &buf) == 1 )
*a2 = func2(buf);
else
v6 = -1;
}
}
return v6;
}

original_code:
static int
trim_binary_subnet(const char *input_str, uint32_t *key)
{
    char *p = strchr(input_str, '/');
    if (!p)
        return -1;
    int i = 0;
    for (;*(p + 1 + i) != '\0'; i++)
        if (*(p + 1 + i) > '9' || *(p + 1 + i) < '0')
            return -1;
    int mask = atoi(p + 1);
    if (mask <= 0 || mask > 32)
        return -1;
    char bi_subnet[33];
    memcpy(bi_subnet, input_str, p-input_str);
    bi_subnet[p-input_str] = '\0';
    struct in_addr myin;
    int ret = inet_pton(2, bi_subnet, &myin);
    if (ret != 1)
        return -1;
    *key = ntohl(myin.s_addr);
    return mask;
}

canonical_original_code:
static int trim_binary_subnet(char *input_str, unsigned int *key)
{
    char *p = strchr(input_str, '/');
    if (!p)
        return -1;
    int i = 0;
    for (;*(p + 1 + i) != '\0'; i++)
        if (*(p + 1 + i) > '9' || *(p + 1 + i) < '0')
            return -1;
    int mask = atoi(p + 1);
    if (mask <= 0 || mask > 32)
        return -1;
    char bi_subnet[33];
    memcpy(bi_subnet, input_str, p-input_str);
    bi_subnet[p-input_str] = '\0';
    struct in_addr myin;
    int ret = inet_pton(2, bi_subnet, &myin);
    if (ret != 1)
        return -1;
    *key = ntohl(myin.s_addr);
    return mask;
}

variable_types:
key
unsigned int *

variable_types:
p
char *

variable_types: i int

variable_types: mask int

variable_types:
myin
struct in_addr { unsigned int s_addr; }


decompiled_code:
void __fastcall radix_tree_print_helper(_QWORD *a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // ebp
__int64 v6; // rdi
int cp; // [rsp+Ch] [rbp-2Ch] BYREF
char buf[40]; // [rsp+10h] [rbp-28h] BYREF

v4 = a2;
if ( a1[3] )
{
v4 = (-1 << (32 - a3)) & a2;
cp = _bswap_32(v4);
inet_ntop(2, &cp, buf, 0x10u);
printf("ip is %s/%d\n", buf, a3);
}
v6 = a1[1];
if ( v6 )
radix_tree_print_helper(v6, v4, a3 + 1);
if ( *a1 )
radix_tree_print_helper(*a1, v4 | (0x80000000 >> a3), a3 + 1);
}

canonical_decompiled_code:
void __fastcall func4(_QWORD *a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // ebp
__int64 v6; // rdi
int cp; // [rsp+Ch] [rbp-2Ch] BYREF
char buf[40]; // [rsp+10h] [rbp-28h] BYREF

v4 = a2;
if ( a1[3] )
{
v4 = (-1 << (32 - a3)) & a2;
cp = func2(v4);
inet_ntop(2, &cp, buf, 0x10u);
printf("ip is %s/%d\n", buf, a3);
}
v6 = a1[1];
if ( v6 )
func4(v6, v4, a3 + 1);
if ( *a1 )
func4(*a1, v4 | (0x80000000 >> a3), a3 + 1);
}

original_code:
static void
radix_tree_print_helper(radix_node_t *node, uint32_t ip, int mask)
{
    if (!((void *)((void *)0) == ((node)->value)))
    {
        uint32_t code = -1;
        code = code << (32 - mask);
        ip &= code;
        uint32_t temp = ip;
        temp = htonl(temp);
        char ip_addr[16];
        inet_ntop(2, &temp, ip_addr, 16);
        printf("ip is %s/%d\n", ip_addr, mask);
    }
    if (node->left)
    {
        mask++;
        radix_tree_print_helper(node->left, ip, mask);
        --mask;
    }
    if (node->right)
    {
        uint32_t bit = 0x80000000;
        bit >>= mask;
        ip |= bit;
        mask++;
        radix_tree_print_helper(node->right, ip, mask);
        --mask;
    }
}

canonical_original_code:
static void radix_tree_print_helper(struct radix_node *node, unsigned int ip, int mask)
{
    if (!((void *)((void *)0) == ((node)->value)))
    {
        unsigned int code = -1;
        code = code << (32 - mask);
        ip &= code;
        unsigned int temp = ip;
        temp = htonl(temp);
        char ip_addr[16];
        inet_ntop(2, &temp, ip_addr, 16);
        printf("ip is %s/%d\n", ip_addr, mask);
    }
    if (node->left)
    {
        mask++;
        radix_tree_print_helper(node->left, ip, mask);
        --mask;
    }
    if (node->right)
    {
        unsigned int bit = 0x80000000;
        bit >>= mask;
        ip |= bit;
        mask++;
        radix_tree_print_helper(node->right, ip, mask);
        --mask;
    }
}

variable_types:
ip
unsigned int

variable_types:
code
unsigned int

variable_types:
temp
unsigned int

variable_types:
bit
unsigned int


decompiled_code:
const char *__fastcall radix_tree_get_result(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "success";
break;
case 1:
result = "failed,perhaps this ip isn't in wblist";
break;
case 2:
result = "not enough memory";
break;
case 3:
result = "ip already exists";
break;
case 4:
result = "failed ,perhaps format error";
break;
default:
result = "unkown reason";
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func5(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "success";
break;
case 1:
result = "failed,perhaps this ip isn't in wblist";
break;
case 2:
result = "not enough memory";
break;
case 3:
result = "ip already exists";
break;
case 4:
result = "failed ,perhaps format error";
break;
default:
result = "unkown reason";
break;
}
return result;
}

original_code:
const char *
radix_tree_get_result(result_t result)
{
    switch(result)
    {
    case SUCCEED:
        return "success";
    case FAILED:
        return "failed,perhaps this ip isn't in wblist";
    case NO_MEMORY:
        return "not enough memory";
    case DUP_KEY:
        return "ip already exists";
    case FORMART_ERROR:
        return "failed ,perhaps format error";
    default:
        return "unkown reason";
    }
}

canonical_original_code:
char *radix_tree_get_result(enum result_t result)
{
    switch(result)
    {
    case SUCCEED:
        return "success";
    case FAILED:
        return "failed,perhaps this ip isn't in wblist";
    case NO_MEMORY:
        return "not enough memory";
    case DUP_KEY:
        return "ip already exists";
    case FORMART_ERROR:
        return "failed ,perhaps format error";
    default:
        return "unkown reason";
    }
}

variable_types: enum result_t { SUCCEED=0, FAILED=1, NO_MEMORY=2, DUP_KEY=3, FORMART_ERROR=4 }


decompiled_code:
void __fastcall radix_tree_delete(void *ptr)
{
_QWORD *i; // rdi

ip_node_delete(*(__int64 **)ptr, *((void (**)(void))ptr + 2));
for ( i = (_QWORD *)*((_QWORD *)ptr + 1); i; i = (_QWORD *)*((_QWORD *)ptr + 1) )
{
*((_QWORD *)ptr + 1) = *i;
free(i);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
_QWORD *i; // rdi

func1(*(__int64 **)ptr, *((void (**)(void))ptr + 2));
for ( i = (_QWORD *)*((_QWORD *)ptr + 1); i; i = (_QWORD *)*((_QWORD *)ptr + 1) )
{
*((_QWORD *)ptr + 1) = *i;
free(i);
}
free(ptr);
}

original_code:
void
radix_tree_delete(radix_tree_t *tree)
{
    ip_node_delete(tree->root, tree->value_delete_func);
    while (tree->free)
    {
        radix_node_t *free_node = tree->free;
        tree->free = tree->free->right;
        free(free_node);
    }
    free(tree);
}

canonical_original_code:
void radix_tree_delete(struct radix_tree *tree)
{
    ip_node_delete(tree->root, tree->value_delete_func);
    while (tree->free)
    {
        struct radix_node *free_node = tree->free;
        tree->free = tree->free->right;
        free(free_node);
    }
    free(tree);
}

variable_types: struct radix_tree { struct radix_node { struct radix_node *right; struct radix_node *left; struct radix_node *parent; void *value; } *root; struct radix_node *free; void (*value_delete_func)(void *value); unsigned int count; } *

user_defined_types: struct radix_tree { struct radix_node *root; struct radix_node *free; void (*value_delete_func)(void *value); unsigned int count; }


decompiled_code:
__int64 __fastcall radix_tree_walk(_QWORD **a1, __int64 (*a2)(void))
{
return radix_tree_walk_helper(*a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD **a1, __int64 (*a2)(void))
{
return func0(*a1, a2);
}

original_code:
void
radix_tree_walk(radix_tree_t *tree, value_func value_function)
{
    radix_tree_walk_helper(tree->root, value_function);
}

canonical_original_code:
void radix_tree_walk(struct radix_tree *tree, void (*value_function)(void *value))
{
    radix_tree_walk_helper(tree->root, value_function);
}


original_code:
result_t
radix_tree_insert_node(radix_tree_t *tree, uint32_t key,
                                           uint32_t mask, void *value)
{
    radix_node_t *node, *next;
    uint32_t bit = 0x80000000;
    node = next = tree->root;
    while (mask > 0)
    {
        if (key & bit)
            next = node->right;
        else
            next = node->left;
        if (next == ((void *)0))
            break;
        bit >>= 1;
        node = next;
        --mask;
    }
    if (next)
    {
        if (node->value != (void *)((void *)0))
            return DUP_KEY;
        node->value = value;
        tree->count += 1;
        return SUCCEED;
    }
    while (mask > 0)
    {
        next = (radix_node_t *)radix_tree_alloc(tree);
        if (next == ((void *)0))
            return NO_MEMORY;
        next->right = ((void *)0);
        next->left = ((void *)0);
        next->parent = node;
        next->value = (void *)((void *)0);
        if (key & bit)
            node->right = next;
        else
            node->left = next;
        bit >>= 1;
        node = next;
        --mask;
    }
    node->value = value;
    tree->count += 1;
    return SUCCEED;
}

canonical_original_code:
enum result_t radix_tree_insert_node(struct radix_tree *tree, unsigned int key, unsigned int mask, void *value)
{
    struct radix_node *node; struct radix_node *next;
    unsigned int bit = 0x80000000;
    node = next = tree->root;
    while (mask > 0)
    {
        if (key & bit)
            next = node->right;
        else
            next = node->left;
        if (next == ((void *)0))
            break;
        bit >>= 1;
        node = next;
        --mask;
    }
    if (next)
    {
        if (node->value != (void *)((void *)0))
            return DUP_KEY;
        node->value = value;
        tree->count += 1;
        return SUCCEED;
    }
    while (mask > 0)
    {
        next = (struct radix_node *)radix_tree_alloc(tree);
        if (next == ((void *)0))
            return NO_MEMORY;
        next->right = ((void *)0);
        next->left = ((void *)0);
        next->parent = node;
        next->value = (void *)((void *)0);
        if (key & bit)
            node->right = next;
        else
            node->left = next;
        bit >>= 1;
        node = next;
        --mask;
    }
    node->value = value;
    tree->count += 1;
    return SUCCEED;
}

variable_types:
key
unsigned int

variable_types:
mask
unsigned int

variable_types:
value
void *

return_type: enum result_t { SUCCEED=0, FAILED=1, NO_MEMORY=2, DUP_KEY=3, FORMART_ERROR=4 }


decompiled_code:
__int64 __fastcall radix_tree_insert_subnet(__int64 a1, void *a2, __int64 a3)
{
int v4; // edx
__int64 result; // rax
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = trim_binary_subnet(a2, v6);
result = 4LL;
if ( v4 >= 0 )
result = radix_tree_insert_node(a1, v6[0], v4, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, void *a2, __int64 a3)
{
int v4; // edx
__int64 result; // rax
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = func3(a2, v6);
result = 4LL;
if ( v4 >= 0 )
result = func8(a1, v6[0], v4, a3);
return result;
}

original_code:
result_t
radix_tree_insert_subnet(radix_tree_t *tree, const char *subnet, void* info)
{
    uint32_t key;
    int mask = trim_binary_subnet(subnet, &key);
    if (mask < 0)
        return FORMART_ERROR;
    return radix_tree_insert_node(tree, key, mask, info);
}

canonical_original_code:
enum result_t radix_tree_insert_subnet(struct radix_tree *tree, char *subnet, void *info)
{
    unsigned int key;
    int mask = trim_binary_subnet(subnet, &key);
    if (mask < 0)
        return FORMART_ERROR;
    return radix_tree_insert_node(tree, key, mask, info);
}

variable_types:
subnet
char *

variable_types:
info
void *

user_defined_types: enum result_t { SUCCEED=0, FAILED=1, NO_MEMORY=2, DUP_KEY=3, FORMART_ERROR=4 }


original_code:
result_t
radix_tree_delete_node(radix_tree_t *tree, uint32_t key, uint32_t mask)
{
    uint32_t bit = 0x80000000;
    radix_node_t *node = tree->root;
    while (node && mask > 0)
    {
        if (key & bit)
            node = node->right;
        else
            node = node->left;
        bit >>= 1;
        --mask;
    }
    if (node == ((void *)0))
        return FAILED;
    if (node->right || node->left)
    {
        if (node->value != (void *)((void *)0))
        {
            node->value = (void *)((void *)0);
            tree->count -= 1;
            return SUCCEED;
        }
        return FAILED;
    }
    for ( ;; )
    {
        if (node->parent->right == node)
            node->parent->right = ((void *)0);
        else
            node->parent->left = ((void *)0);
        node->right = tree->free;
        tree->free = node;
        node = node->parent;
        if (node->right || node->left)
            break;
        if (node->value != (void *)((void *)0))
            break;
        if (node->parent == ((void *)0))
            break;
    }
    tree->count -= 1;
    return SUCCEED;
}

canonical_original_code:
enum result_t radix_tree_delete_node(struct radix_tree *tree, unsigned int key, unsigned int mask)
{
    unsigned int bit = 0x80000000;
    struct radix_node *node = tree->root;
    while (node && mask > 0)
    {
        if (key & bit)
            node = node->right;
        else
            node = node->left;
        bit >>= 1;
        --mask;
    }
    if (node == ((void *)0))
        return FAILED;
    if (node->right || node->left)
    {
        if (node->value != (void *)((void *)0))
        {
            node->value = (void *)((void *)0);
            tree->count -= 1;
            return SUCCEED;
        }
        return FAILED;
    }
    for ( ;; )
    {
        if (node->parent->right == node)
            node->parent->right = ((void *)0);
        else
            node->parent->left = ((void *)0);
        node->right = tree->free;
        tree->free = node;
        node = node->parent;
        if (node->right || node->left)
            break;
        if (node->value != (void *)((void *)0))
            break;
        if (node->parent == ((void *)0))
            break;
    }
    tree->count -= 1;
    return SUCCEED;
}

variable_types: struct radix_node { struct radix_node *right; struct radix_node *left; struct radix_node *parent; void *value; } *


decompiled_code:
__int64 __fastcall radix_tree_remove_subnet(__int64 a1, void *a2)
{
int v2; // edx
__int64 result; // rax
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = trim_binary_subnet(a2, v4);
result = 4LL;
if ( v2 > 0 )
result = radix_tree_delete_node(a1, v4[0], v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, void *a2)
{
int v2; // edx
__int64 result; // rax
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = func3(a2, v4);
result = 4LL;
if ( v2 > 0 )
result = func10(a1, v4[0], v2);
return result;
}

original_code:
result_t
radix_tree_remove_subnet(radix_tree_t *tree, const char* subnet)
{
    uint32_t key;
    int mask = trim_binary_subnet(subnet, &key);
    if (mask <= 0)
        return FORMART_ERROR;
    return radix_tree_delete_node(tree, key, mask);
}

canonical_original_code:
enum result_t radix_tree_remove_subnet(struct radix_tree *tree, char *subnet)
{
    unsigned int key;
    int mask = trim_binary_subnet(subnet, &key);
    if (mask <= 0)
        return FORMART_ERROR;
    return radix_tree_delete_node(tree, key, mask);
}


decompiled_code:
__int64 __fastcall radix_tree_find(_QWORD *a1, int a2)
{
_QWORD *v4; // rax
__int64 v5; // rsi
unsigned int v6; // edx

v4 = (_QWORD *)*a1;
if ( !v4 )
return 0LL;
v5 = 0LL;
v6 = 0x80000000;
do
{
if ( v4[3] )
v5 = v4[3];
if ( (v6 & a2) != 0 )
v4 = (_QWORD *)*v4;
else
v4 = (_QWORD *)v4[1];
v6 >>= 1;
}
while ( v4 );
return v5;
}

original_code:
void *
radix_tree_find(radix_tree_t *tree, uint32_t key)
{
    uint32_t bit = 0x80000000;
    void *value = (void *)((void *)0);
    radix_node_t *node = tree->root;
;
    while (node)
    {
        if (node->value != (void *)((void *)0))
            value = node->value;
        if (key & bit)
            node = node->right;
        else
            node = node->left;
        bit >>= 1;
    }
    return value;
}

canonical_original_code:
void *radix_tree_find(struct radix_tree *tree, unsigned int key)
{
    unsigned int bit = 0x80000000;
    void *value = (void *)((void *)0);
    struct radix_node *node = tree->root;
;
    while (node)
    {
        if (node->value != (void *)((void *)0))
            value = node->value;
        if (key & bit)
            node = node->right;
        else
            node = node->left;
        bit >>= 1;
    }
    return value;
}


decompiled_code:
__int64 __fastcall radix_tree_find_str(_QWORD *a1, const char *a2)
{
int v2; // edx
__int64 result; // rax
int v4; // eax
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = inet_pton(2, a2, buf);
result = 0LL;
if ( v2 == 1 )
{
v4 = _bswap_32(buf[0]);
result = radix_tree_find(a1, v4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1, const char *a2)
{
int v2; // edx
__int64 result; // rax
int v4; // eax
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = inet_pton(2, a2, buf);
result = 0LL;
if ( v2 == 1 )
{
v4 = func2(buf[0]);
result = func12(a1, v4);
}
return result;
}

original_code:
void *
radix_tree_find_str(radix_tree_t *tree, const char *strip)
{
    struct in_addr myin;
    int ret = inet_pton(2, strip, &myin);
    if (ret != 1)
        return ((void *)0);
    return radix_tree_find(tree, ntohl(myin.s_addr));
}

canonical_original_code:
void *radix_tree_find_str(struct radix_tree *tree, char *strip)
{
    struct in_addr myin;
    int ret = inet_pton(2, strip, &myin);
    if (ret != 1)
        return ((void *)0);
    return radix_tree_find(tree, ntohl(myin.s_addr));
}

variable_types:
strip
char *

variable_types: ret int


decompiled_code:
void __fastcall radix_tree_print(_QWORD **a1)
{
radix_tree_print_helper(*a1, 0, 0);
}

canonical_decompiled_code:
void __fastcall func14(_QWORD **a1)
{
func4(*a1, 0, 0);
}

original_code:
void
radix_tree_print(radix_tree_t *tree)
{
    radix_tree_print_helper(tree->root, 0, 0);
}

canonical_original_code:
void radix_tree_print(struct radix_tree *tree)
{
    radix_tree_print_helper(tree->root, 0, 0);
}


decompiled_code:
__int64 __fastcall radix_tree_get_ip_size(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

original_code:
uint32_t
radix_tree_get_ip_size(radix_tree_t *tree)
{
    return tree->count;
}

canonical_original_code:
unsigned int radix_tree_get_ip_size(struct radix_tree *tree)
{
    return tree->count;
}


decompiled_code:
__int16 __fastcall addr_get_port(__int64 a1)
{
addr_get_type();
return _bswap_16(*(_WORD *)(a1 + 2));
}

canonical_decompiled_code:
__int16 __fastcall func4(__int64 a1)
{
addr_get_type();
return func0(*(_WORD *)(a1 + 2));
}

original_code:
uint16_t
addr_get_port(const addr_t *addr)
{
    return addr_get_type(addr) == ADDR_IPV4 ? ntohs(addr->addr_v4.sin_port) :
        ntohs(addr->addr_v6.sin6_port);
}

canonical_original_code:
unsigned short addr_get_port(struct _addr *addr)
{
    return addr_get_type(addr) == ADDR_IPV4 ? ntohs(addr->addr_v4.sin_port) :
        ntohs(addr->addr_v6.sin6_port);
}

variable_types: struct _addr { union { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr_v4; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } addr_v6; }; int mask; enum addr_type_t { ADDR_IPV4=0, ADDR_IPV6=1 } addr_type; } *


decompiled_code:
__int16 __fastcall addr_set_port(__int64 a1, __int16 a2)
{
__int16 result; // ax

addr_get_type();
result = _bswap_16(a2);
*(_WORD *)(a1 + 2) = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func5(__int64 a1, __int16 a2)
{
__int16 result; // ax

addr_get_type();
result = func0(a2);
*(_WORD *)(a1 + 2) = result;
return result;
}

original_code:
void
addr_set_port(addr_t *addr, uint16_t port)
{
    if (addr_get_type(addr) == ADDR_IPV4)
        addr->addr_v4.sin_port = htons(port);
    else
        addr->addr_v6.sin6_port = htons(port);
}

canonical_original_code:
void addr_set_port(struct _addr *addr, unsigned short port)
{
    if (addr_get_type(addr) == ADDR_IPV4)
        addr->addr_v4.sin_port = htons(port);
    else
        addr->addr_v6.sin6_port = htons(port);
}

variable_types:
port
unsigned short


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

if ( (unsigned int)addr_get_type() )
result = inet_ntop(10, (const void *)(a1 + 8), a2, 0x40u);
else
result = inet_ntop(2, (const void *)(a1 + 4), a2, 0x40u);
return result;
}

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

if ( (unsigned int)addr_get_type() )
result = inet_ntop(10, (const void *)(a1 + 8), a2, 0x40u);
else
result = inet_ntop(2, (const void *)(a1 + 4), a2, 0x40u);
return result;
}

original_code:
void
addr_get_ip(const addr_t *addr, char *ip)
{
    if (addr_get_type(addr) == ADDR_IPV4)
        inet_ntop(2, &(addr->addr_v4.sin_addr), ip, 64);
    else
        inet_ntop(10, &(addr->addr_v6.sin6_addr), ip, 64);
}

canonical_original_code:
void addr_get_ip(struct _addr *addr, char *ip)
{
    if (addr_get_type(addr) == ADDR_IPV4)
        inet_ntop(2, &(addr->addr_v4.sin_addr), ip, 64);
    else
        inet_ntop(10, &(addr->addr_v6.sin6_addr), ip, 64);
}

variable_types:
ip
char *


decompiled_code:
void __fastcall addr_set_mask(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 28) = a2;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 28) = a2;
}

original_code:
inline void
addr_set_mask(addr_t *addr, int mask)
{
    addr->mask = mask;
}

canonical_original_code:
inline void addr_set_mask(struct _addr *addr, int mask)
{
    addr->mask = mask;
}

variable_types: mask int


decompiled_code:
__int64 __fastcall addr_get_mask(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

original_code:
inline int
addr_get_mask(const addr_t *addr)
{
    return addr->mask;
}

canonical_original_code:
inline int addr_get_mask(struct _addr *addr)
{
    return addr->mask;
}


decompiled_code:
bool __fastcall addr_is_loopback(__int64 a1)
{
bool v2; // al
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

addr_get_ip(a1, v3);
if ( !(unsigned int)addr_get_type(a1) )
return strcmp(v3, "127.0.0.1") == 0;
v2 = 1;
if ( strcmp(v3, "0:0:0:0:0:0:0:1") )
v2 = strcmp(v3, "::1") == 0;
return v2;
}

canonical_decompiled_code:
bool __fastcall func10(__int64 a1)
{
bool v2; // al
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

func6(a1, v3);
if ( !(unsigned int)addr_get_type(a1) )
return strcmp(v3, "127.0.0.1") == 0;
v2 = 1;
if ( strcmp(v3, "0:0:0:0:0:0:0:1") )
v2 = strcmp(v3, "::1") == 0;
return v2;
}

original_code:
_Bool
addr_is_loopback(const addr_t *addr)
{
    static const char *IPV4_LOOPBACK = "127.0.0.1";
    static const char *IPV6_LOOPBACK = "0:0:0:0:0:0:0:1";
    static const char *IPV6_LOOPBACK_SIMPLE = "::1";
    char ip[64];
    addr_get_ip(addr, ip);
    if (addr_get_type(addr) == ADDR_IPV4)
        return strcmp(ip, IPV4_LOOPBACK) == 0;
    else
        return strcmp(ip, IPV6_LOOPBACK) == 0 || strcmp(ip, IPV6_LOOPBACK_SIMPLE) == 0;
}

canonical_original_code:
_Bool addr_is_loopback(struct _addr *addr)
{
    static char *IPV4_LOOPBACK = "127.0.0.1";
    static char *IPV6_LOOPBACK = "0:0:0:0:0:0:0:1";
    static char *IPV6_LOOPBACK_SIMPLE = "::1";
    char ip[64];
    addr_get_ip(addr, ip);
    if (addr_get_type(addr) == ADDR_IPV4)
        return strcmp(ip, IPV4_LOOPBACK) == 0;
    else
        return strcmp(ip, IPV6_LOOPBACK) == 0 || strcmp(ip, IPV6_LOOPBACK_SIMPLE) == 0;
}

variable_types:
ip
char [64]


decompiled_code:
_BOOL8 __fastcall addr_compare(__int64 a1, __int64 a2)
{
char v3[64]; // [rsp+0h] [rbp-88h] BYREF
char s1[72]; // [rsp+40h] [rbp-48h] BYREF

addr_get_ip(a1, s1);
addr_get_ip(a2, v3);
return strcmp(s1, v3) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1, __int64 a2)
{
char v3[64]; // [rsp+0h] [rbp-88h] BYREF
char s1[72]; // [rsp+40h] [rbp-48h] BYREF

func6(a1, s1);
func6(a2, v3);
return strcmp(s1, v3) == 0;
}

original_code:
int
addr_compare(const addr_t *src, const addr_t *dst)
{
    char ip1[64];
    char ip2[64];
    int ret;
    addr_get_ip(src, ip1);
    addr_get_ip(dst, ip2);
    if (strcmp(ip1, ip2) == 0)
        ret = 1;
    else
        ret = 0;
    return ret;
}

canonical_original_code:
int addr_compare(struct _addr *src, struct _addr *dst)
{
    char ip1[64];
    char ip2[64];
    int ret;
    addr_get_ip(src, ip1);
    addr_get_ip(dst, ip2);
    if (strcmp(ip1, ip2) == 0)
        ret = 1;
    else
        ret = 0;
    return ret;
}

variable_types:
dst
struct _addr *


decompiled_code:
__int64 __fastcall wire_name_to_human_name(char *a1, _BYTE *a2, unsigned __int16 a3)
{
char v4; // al
int v5; // ebx
unsigned __int16 v6; // r8
unsigned __int16 v7; // r9
__int64 v8; // rsi
unsigned __int16 v9; // dx
_QWORD *v10; // rcx
char *v11; // rsi
__int64 result; // rax

v4 = *a1;
if ( *a1 )
{
if ( v4 > 63 )
{
result = 0xFFFFFFFFLL;
}
else
{
v5 = a3;
if ( v4 > (int)a3 )
{
result = 0xFFFFFFFFLL;
}
else
{
v6 = 0;
v7 = 0;
v8 = 0LL;
do
{
v10 = &a2[v7];
v11 = &a1[v8 + 1];
if ( (unsigned __int64)v4 >= 8 )
{
*v10 = *(_QWORD *)v11;
*(_QWORD *)((char *)v10 + v4 - 8) = *(_QWORD *)&v11[v4 - 8];
qmemcpy(
(void *)((unsigned __int64)(v10 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v11 - ((char *)v10 - ((unsigned __int64)(v10 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8 * (((unsigned __int64)v10 + v4 - ((unsigned __int64)(v10 + 1) & 0xFFFFFFFFFFFFFFF8LL)) >> 3));
}
else if ( (v4 & 4) != 0 )
{
*(_DWORD *)v10 = *(_DWORD *)v11;
*(_DWORD *)((char *)v10 + v4 - 4) = *(_DWORD *)&v11[v4 - 4];
}
else
{
*(_BYTE *)v10 = *v11;
if ( (v4 & 2) != 0 )
*(_WORD *)((char *)v10 + v4 - 2) = *(_WORD *)&v11[v4 - 2];
}
v9 = v4 + v7;
v7 = v9 + 1;
a2[v9] = 46;
v6 += v4 + 1;
v8 = v6;
v4 = a1[v6];
if ( !v4 )
{
a2[v7] = 0;
return 0LL;
}
if ( v6 > 0x100u || v4 > 63 )
return 0xFFFFFFFFLL;
}
while ( v4 + v6 <= v5 );
result = 0xFFFFFFFFLL;
}
}
}
else
{
*a2 = 0;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, _BYTE *a2, unsigned __int16 a3)
{
char v4; // al
int v5; // ebx
unsigned __int16 v6; // r8
unsigned __int16 v7; // r9
__int64 v8; // rsi
unsigned __int16 v9; // dx
_QWORD *v10; // rcx
char *v11; // rsi
__int64 result; // rax

v4 = *a1;
if ( *a1 )
{
if ( v4 > 63 )
{
result = 0xFFFFFFFFLL;
}
else
{
v5 = a3;
if ( v4 > (int)a3 )
{
result = 0xFFFFFFFFLL;
}
else
{
v6 = 0;
v7 = 0;
v8 = 0LL;
do
{
v10 = &a2[v7];
v11 = &a1[v8 + 1];
if ( (unsigned __int64)v4 >= 8 )
{
*v10 = *(_QWORD *)v11;
*(_QWORD *)((char *)v10 + v4 - 8) = *(_QWORD *)&v11[v4 - 8];
qmemcpy(
(void *)((unsigned __int64)(v10 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v11 - ((char *)v10 - ((unsigned __int64)(v10 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8 * (((unsigned __int64)v10 + v4 - ((unsigned __int64)(v10 + 1) & 0xFFFFFFFFFFFFFFF8LL)) >> 3));
}
else if ( (v4 & 4) != 0 )
{
*(_DWORD *)v10 = *(_DWORD *)v11;
*(_DWORD *)((char *)v10 + v4 - 4) = *(_DWORD *)&v11[v4 - 4];
}
else
{
*(_BYTE *)v10 = *v11;
if ( (v4 & 2) != 0 )
*(_WORD *)((char *)v10 + v4 - 2) = *(_WORD *)&v11[v4 - 2];
}
v9 = v4 + v7;
v7 = v9 + 1;
a2[v9] = 46;
v6 += v4 + 1;
v8 = v6;
v4 = a1[v6];
if ( !v4 )
{
a2[v7] = 0;
return 0LL;
}
if ( v6 > 0x100u || v4 > 63 )
return 0xFFFFFFFFLL;
}
while ( v4 + v6 <= v5 );
result = 0xFFFFFFFFLL;
}
}
}
else
{
*a2 = 0;
result = 0LL;
}
return result;
}

original_code:
int
wire_name_to_human_name(const char *wire_name,
                        char *human_name,
                        uint16_t wire_name_len)
{
    char label_len = 0;
    uint16_t human_name_pos = 0;
    uint16_t wire_name_pos = 0;
    while ((label_len = wire_name[wire_name_pos]) != 0)
    {
        if (label_len > 63)
            return -1;
        if (wire_name_pos > 256)
            return -1;
        if (wire_name_pos + label_len > wire_name_len)
            return -1;
        memcpy(human_name + human_name_pos,
               wire_name + wire_name_pos + 1,
               label_len);
        human_name_pos += label_len;
        human_name[human_name_pos++] = '.';
        wire_name_pos += label_len + 1;
    }
    human_name[human_name_pos] = 0;
    return 0;
}

canonical_original_code:
int wire_name_to_human_name(char *wire_name, char *human_name, unsigned short wire_name_len)
{
    char label_len = 0;
    unsigned short human_name_pos = 0;
    unsigned short wire_name_pos = 0;
    while ((label_len = wire_name[wire_name_pos]) != 0)
    {
        if (label_len > 63)
            return -1;
        if (wire_name_pos > 256)
            return -1;
        if (wire_name_pos + label_len > wire_name_len)
            return -1;
        memcpy(human_name + human_name_pos,
               wire_name + wire_name_pos + 1,
               label_len);
        human_name_pos += label_len;
        human_name[human_name_pos++] = '.';
        wire_name_pos += label_len + 1;
    }
    human_name[human_name_pos] = 0;
    return 0;
}


decompiled_code:
__int64 __fastcall dns_header_get_opt(__int64 a1)
{
return ntohs(*(_WORD *)(a1 + 2)) & 0x7800;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return ntohs(*(_WORD *)(a1 + 2)) & 0x7800;
}

original_code:
opcode_t
dns_header_get_opt(const uint8_t *header)
{
    uint16_t flag = ntohs(*((uint16_t *)header + 1));
    return flag & 0x7800;
}

canonical_original_code:
enum opcode_t dns_header_get_opt(unsigned char *header)
{
    unsigned short flag = ntohs(*((uint16_t *)header + 1));
    return flag & 0x7800;
}

variable_types:
header
unsigned char *

variable_types:
flag
unsigned short

return_type: enum opcode_t { QUERY_STAND=0, QUERY_INVERSE=2048, QUERY_STATUS=4096, QUERY_NOTIFY=8192, QUERY_UPDATE=10240 }


decompiled_code:
uint16_t __fastcall dns_header_set_opt(__int64 a1, __int16 a2)
{
uint16_t v2; // ax
uint16_t result; // ax

v2 = ntohs(*(_WORD *)(a1 + 2));
result = htons(a2 | v2);
*(_WORD *)(a1 + 2) = result;
return result;
}

canonical_decompiled_code:
uint16_t __fastcall func2(__int64 a1, __int16 a2)
{
uint16_t v2; // ax
uint16_t result; // ax

v2 = ntohs(*(_WORD *)(a1 + 2));
result = htons(a2 | v2);
*(_WORD *)(a1 + 2) = result;
return result;
}

original_code:
void
dns_header_set_opt(uint8_t *header, opcode_t opcode)
{
    uint16_t flag = ntohs(*((uint16_t *)header + 1));
    flag |= opcode;
    *((uint16_t *)header + 1) = htons(flag);
}

canonical_original_code:
void dns_header_set_opt(unsigned char *header, enum opcode_t opcode)
{
    unsigned short flag = ntohs(*((uint16_t *)header + 1));
    flag |= opcode;
    *((unsigned short *)header + 1) = htons(flag);
}

variable_types: enum opcode_t { QUERY_STAND=0, QUERY_INVERSE=2048, QUERY_STATUS=4096, QUERY_NOTIFY=8192, QUERY_UPDATE=10240 }


decompiled_code:
const char *__fastcall domain_wblist_get_result(int a1)
{
const char *result; // rax

if ( a1 == 2 )
return "domain name exists";
if ( a1 > 2 )
{
result = "unknown reason";
if ( a1 == 3 )
result = "invalid domain name";
}
else
{
result = "success";
if ( a1 )
{
result = "unknown reason";
if ( a1 == 1 )
result = "domain name isn't exists";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

if ( a1 == 2 )
return "domain name exists";
if ( a1 > 2 )
{
result = "unknown reason";
if ( a1 == 3 )
result = "invalid domain name";
}
else
{
result = "success";
if ( a1 )
{
result = "unknown reason";
if ( a1 == 1 )
result = "domain name isn't exists";
}
}
return result;
}

original_code:
const char *
domain_wblist_get_result(int type)
{
    switch(type)
    {
    case DOMAIN_WBLIST_SUCCESS:
        return "success";
    case DOMAIN_WBLIST_FAILED:
        return "domain name isn't exists";
    case DOMAIN_WBLIST_EXIST:
        return "domain name exists";
    case DOMAIN_WBLIST_INVALID:
        return "invalid domain name";
    default:
        return "unknown reason";
    }
}

canonical_original_code:
char *domain_wblist_get_result(int type)
{
    switch(type)
    {
    case DOMAIN_WBLIST_SUCCESS:
        return "success";
    case DOMAIN_WBLIST_FAILED:
        return "domain name isn't exists";
    case DOMAIN_WBLIST_EXIST:
        return "domain name exists";
    case DOMAIN_WBLIST_INVALID:
        return "invalid domain name";
    default:
        return "unknown reason";
    }
}

variable_types: type int


decompiled_code:
bool __fastcall query_pkg_is_valid(__int64 a1, __int16 a2)
{
bool result; // al

result = 0;
if ( (unsigned __int16)(a2 - 17) <= 0x1EFu )
result = (unsigned int)dns_header_get_opt() == 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func5(__int64 a1, __int16 a2)
{
bool result; // al

result = 0;
if ( (unsigned __int16)(a2 - 17) <= 0x1EFu )
result = (unsigned int)dns_header_get_opt() == 0;
return result;
}

original_code:
_Bool
query_pkg_is_valid(const char *raw_data, uint16_t data_len)
{
    if (data_len < 12 + 4 + 1 || data_len > 512)
        return 0;
    if (dns_header_get_opt(raw_data) != QUERY_STAND)
        return 0;
    return 1;
}

canonical_original_code:
_Bool query_pkg_is_valid(char *raw_data, unsigned short data_len)
{
    if (data_len < 12 + 4 + 1 || data_len > 512)
        return 0;
    if (dns_header_get_opt(raw_data) != QUERY_STAND)
        return 0;
    return 1;
}


decompiled_code:
__int16 __fastcall pkg_query_or_response(__int64 a1)
{
return (unsigned __int16)_bswap_16(*(_WORD *)(a1 + 2)) >> 15;
}

canonical_decompiled_code:
__int16 __fastcall func1(__int64 a1)
{
return (unsigned __int16)func0(*(_WORD *)(a1 + 2)) >> 15;
}

original_code:
uint16_t
pkg_query_or_response(const char *raw_data)
{
    uint16_t flag = ntohs(*((uint16_t *)(raw_data+2)));
    return !!(flag & 0x8000);
}

canonical_original_code:
unsigned short pkg_query_or_response(char *raw_data)
{
    unsigned short flag = ntohs(*((uint16_t *)(raw_data+2)));
    return !!(flag & 0x8000);
}


decompiled_code:
__int16 __fastcall pkg_get_query_type(__int64 a1, unsigned __int16 a2)
{
__int64 v3; // rdx
unsigned __int8 v4; // al

if ( !pkg_query_or_response(a1) )
return _bswap_16(*(_WORD *)(a1 + a2 - 4));
v3 = a1 + 12;
v4 = *(_BYTE *)(a1 + 12);
if ( v4 )
{
do
{
v3 += v4 + 1LL;
v4 = *(_BYTE *)v3;
}
while ( *(_BYTE *)v3 );
}
return _bswap_16(*(_WORD *)(v3 + 1));
}

original_code:
uint16_t
pkg_get_query_type(const char *raw_data, uint16_t data_len)
{
    uint16_t type;
    if (pkg_query_or_response(raw_data) == DNS_QUERY)
    {
        type = ntohs(*((uint16_t *)(raw_data + data_len - 4)));
    }
    else
    {
        uint8_t *pos = (uint8_t *)(raw_data + 12);
        while (*pos != 0)
            pos = pos + *pos + 1;
        type = ntohs(*((uint16_t *)(pos + 1)));
    }
    return type;
}

canonical_original_code:
unsigned short pkg_get_query_type(char *raw_data, unsigned short data_len)
{
    unsigned short type;
    if (pkg_query_or_response(raw_data) == DNS_QUERY)
    {
        type = ntohs(*((unsigned short *)(raw_data + data_len - 4)));
    }
    else
    {
        unsigned char *pos = (uint8_t *)(raw_data + 12);
        while (*pos != 0)
            pos = pos + *pos + 1;
        type = ntohs(*((unsigned short *)(pos + 1)));
    }
    return type;
}

variable_types:
type
unsigned short

variable_types:
pos
unsigned char *


decompiled_code:
__int16 __fastcall pkg_get_query_id(__int16 *a1)
{
return _bswap_16(*a1);
}

canonical_decompiled_code:
__int16 __fastcall func3(__int16 *a1)
{
return func0(*a1);
}

original_code:
uint16_t
pkg_get_query_id(const char *raw_data)
{
    return ntohs(*(uint16_t*)raw_data);
}

canonical_original_code:
unsigned short pkg_get_query_id(char *raw_data)
{
    return ntohs(*(unsigned short *)raw_data);
}


decompiled_code:
__int16 __fastcall pkg_set_response_id(__int16 *a1, __int16 a2)
{
__int16 result; // ax

result = _bswap_16(a2);
*a1 = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func4(__int16 *a1, __int16 a2)
{
__int16 result; // ax

result = func0(a2);
*a1 = result;
return result;
}

original_code:
void
pkg_set_response_id(char *pkg_data, uint16_t id)
{
    *((uint16_t*)(pkg_data)) = htons(id);
}

canonical_original_code:
void pkg_set_response_id(char *pkg_data, unsigned short id)
{
    *((unsigned short *)(pkg_data)) = htons(id);
}

variable_types:
id
unsigned short


decompiled_code:
bool __fastcall dqueue_empty(__int64 a1)
{
if ( !a1 )
_assert_fail("q != NULL", "dynamic_queue.c", 0x27u, "dqueue_empty");
return *(_DWORD *)(a1 + 8) == *(_DWORD *)(a1 + 12);
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
if ( !a1 )
_assert_fail("q != NULL", "dynamic_queue.c", 0x27u, "dqueue_empty");
return *(_DWORD *)(a1 + 8) == *(_DWORD *)(a1 + 12);
}

original_code:
_Bool dqueue_empty(link_queue_t *q)
{
    ((void) sizeof ((q != ((void *)0)) ? 1 : 0), __extension__ ({ if (q != ((void *)0)) ; else __assert_fail ("q != NULL", "dynamic_queue.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    if(q->front == q->rear)
        return 1;
    else
        return 0;
}

canonical_original_code:
_Bool dqueue_empty(struct link_queue_t *q)
{
    ((void) sizeof ((q != ((void *)0)) ? 1 : 0), __extension__ ({ if (q != ((void *)0)) ; else __assert_fail ("q != NULL", "dynamic_queue.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    if(q->front == q->rear)
        return 1;
    else
        return 0;
}

variable_types: struct link_queue_t { void **data; int front; int rear; struct atomic_t { int counter; } atomic; int queue_size; } *

user_defined_types: struct link_queue_t { void **data; int front; int rear; struct atomic_t atomic; int queue_size; }


decompiled_code:
bool __fastcall dqueue_full(_DWORD *a1)
{
if ( !a1 )
_assert_fail("q != NULL", "dynamic_queue.c", 0x31u, "dqueue_full");
return (a1[3] + 1) % a1[5] == a1[2];
}

canonical_decompiled_code:
bool __fastcall func2(_DWORD *a1)
{
if ( !a1 )
_assert_fail("q != NULL", "dynamic_queue.c", 0x31u, "dqueue_full");
return (a1[3] + 1) % a1[5] == a1[2];
}

original_code:
_Bool dqueue_full(link_queue_t *q)
{
    ((void) sizeof ((q != ((void *)0)) ? 1 : 0), __extension__ ({ if (q != ((void *)0)) ; else __assert_fail ("q != NULL", "dynamic_queue.c", 49, __extension__ __PRETTY_FUNCTION__); }));
    if (q->front == (q->rear + 1) % q->queue_size)
        return 1;
    else
        return 0;
}

canonical_original_code:
_Bool dqueue_full(struct link_queue_t *q)
{
    ((void) sizeof ((q != ((void *)0)) ? 1 : 0), __extension__ ({ if (q != ((void *)0)) ; else __assert_fail ("q != NULL", "dynamic_queue.c", 49, __extension__ __PRETTY_FUNCTION__); }));
    if (q->front == (q->rear + 1) % q->queue_size)
        return 1;
    else
        return 0;
}


canonical_original_code:
static void xxtea_long_encrypt(unsigned int *v, unsigned int len, unsigned int *k)
{
    unsigned int n = len - 1;
    unsigned int z = v[n]; unsigned int y = v[0]; unsigned int p; unsigned int q = 6 + 52 / (n + 1); unsigned int sum = 0; unsigned int e;
    if (n < 1) {
        return;
    }
    while (0 < q--) {
        sum += 0x9e3779b9;
        e = sum >> 2 & 3;
        for (p = 0; p < n; p++) {
            y = v[p + 1];
            z = v[p] += (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
        }
        y = v[0];
        z = v[n] += (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
    }
}

variable_types:
v
unsigned int *

variable_types:
len
unsigned int

variable_types:
k
unsigned int *

variable_types:
n
unsigned int

variable_types:
z
unsigned int

variable_types:
y
unsigned int

variable_types:
p
unsigned int

variable_types:
q
unsigned int

variable_types:
sum
unsigned int

variable_types:
e
unsigned int


canonical_original_code:
static void xxtea_long_decrypt(unsigned int *v, unsigned int len, unsigned int *k)
{
    unsigned int n = len - 1;
    unsigned int z = v[n]; unsigned int y = v[0]; unsigned int p; unsigned int q = 6 + 52 / (n + 1); unsigned int sum = q * 0x9e3779b9; unsigned int e;
    if (n < 1) {
        return;
    }
    while (sum != 0) {
        e = sum >> 2 & 3;
        for (p = n; p > 0; p--) {
            z = v[p - 1];
            y = v[p] -= (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
        }
        z = v[n];
        y = v[0] -= (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
        sum -= 0x9e3779b9;
    }
}