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

result = router_heartbeat();
if ( !options[13] )
result = con_printf("heartbeat sent\n");
return result;
}

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

result = router_heartbeat();
if ( !options[13] )
result = con_printf("heartbeat sent\n");
return result;
}

original_code:
static void cmd_heartbeat(void) {
    router_heartbeat();
    if (!options.sleeping) {
        con_printf("heartbeat sent\n");
    }
}

canonical_original_code:
static void cmd_heartbeat() {
    router_heartbeat();
    if (!options.sleeping) {
        con_printf("heartbeat sent\n");
    }
}


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

result = router_dropcheck();
if ( !options[13] )
result = con_printf("heartcheck done\n");
return result;
}

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

result = router_dropcheck();
if ( !options[13] )
result = con_printf("heartcheck done\n");
return result;
}

original_code:
static void cmd_heartcheck(void) {
    router_dropcheck();
    if (!options.sleeping) {
        con_printf("heartcheck done\n");
    }
}

canonical_original_code:
static void cmd_heartcheck() {
    router_dropcheck();
    if (!options.sleeping) {
        con_printf("heartcheck done\n");
    }
}

return_type: void


decompiled_code:
__int64 cmd_wake()
{
options[13] = 0;
router_restart();
return con_printf("waking up\n");
}

canonical_decompiled_code:
__int64 func12()
{
options[13] = 0;
router_restart();
return con_printf("waking up\n");
}

original_code:
static void cmd_wake(void) {
    options.sleeping = 0;
    router_restart();
    con_printf("waking up\n");
}

canonical_original_code:
static void cmd_wake() {
    options.sleeping = 0;
    router_restart();
    con_printf("waking up\n");
}


decompiled_code:
__int64 cmd_tabs()
{
return print_tabs();
}

canonical_decompiled_code:
__int64 func13()
{
return print_tabs();
}

original_code:
void cmd_tabs(void) {
    print_tabs();
}

canonical_original_code:
void cmd_tabs() {
    print_tabs();
}


cmdparser

decompiled_code:
int __fastcall cmdparser(_BYTE *a1)
{
_BYTE *v1; // rbx
bool v2; // cf
bool v3; // zf
char v4; // al
_BYTE *v5; // rsi
__int64 v6; // rdi
int result; // eax
const char *v8; // rbp
const char *v9; // rdi
__int64 v10; // rcx
const char *v11; // rsi
char v12; // al
bool v13; // cf
bool v14; // zf
__int64 v15; // rcx
bool v16; // al
bool v17; // cf
bool v18; // zf
const char *v19; // rdi
__int64 v20; // rcx
const char *v21; // rsi
char v22; // al
bool v23; // cf
bool v24; // zf
const char *v25; // rdi
__int64 v26; // rcx
const char *v27; // rsi
bool v28; // al
bool v29; // cf
bool v30; // zf
const char *v31; // rdi
__int64 v32; // rcx
const char *v33; // rsi

v1 = a1;
v2 = *a1 < 0x2Fu;
v3 = *a1 == 47;
if ( *a1 != 47 )
{
if ( *a1 == 32 )
{
do
++v1;
while ( *v1 == 32 );
}
v4 = *v1;
if ( (unsigned __int8)(*v1 - 48) > 9u )
{
v5 = v1;
v6 = 0xFFFFFFFFLL;
}
else
{
v5 = v1;
LODWORD(v6) = 0;
do
{
v6 = (unsigned int)(v4 + 10 * v6 - 48);
v4 = *++v5;
}
while ( (unsigned __int8)(*v5 - 48) <= 9u );
if ( v5 == v1 )
{
result = (unsigned __int8)*v5;
v6 = 0xFFFFFFFFLL;
LABEL_10:
if ( (_BYTE)result )
result = rbl_sendmessage(v6);
return result;
}
}
for ( result = (unsigned __int8)*v5; (_BYTE)result == 32; result = (unsigned __int8)*v5 )
++v5;
goto LABEL_10;
}
v8 = a1 + 1;
v9 = "tabs";
v10 = 5LL;
v11 = v8;
do
{
if ( !v10 )
break;
v2 = *v11 < (unsigned int)*v9;
v3 = *v11++ == *v9++;
--v10;
}
while ( v3 );
v12 = (!v2 && !v3) - v2;
v13 = 0;
v14 = v12 == 0;
if ( !v12 )
return cmd_tabs(v9, v11);
v9 = "t";
v15 = 2LL;
v11 = v8;
do
{
if ( !v15 )
break;
v13 = *v11 < (unsigned int)*v9;
v14 = *v11++ == *v9++;
--v15;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
return cmd_tabs(v9, v11);
if ( !memcmp(v8, "ttl ", 3uLL) )
return cmd_ttl((__int64)(v1 + 4));
if ( !memcmp(v8, "debugrt ", 8uLL) )
return cmd_debugrt((__int64)(v1 + 9));
if ( !memcmp(v8, "debugpacket ", 0xCuLL) )
return cmd_debugpacket((__int64)(v1 + 13));
if ( !memcmp(v8, "debuglost ", 0xAuLL) )
return cmd_debuglost((__int64)(v1 + 11));
if ( !memcmp(v8, "debugroute ", 0xBuLL) )
return cmd_debugroute((__int64)(v1 + 12));
if ( !memcmp(v8, "drop ", 5uLL) )
return cmd_drop((__int64)(v1 + 6));
if ( !memcmp(v8, "showtime ", 9uLL) )
return cmd_showtime((__int64)(v1 + 10));
v16 = memcmp(v8, "all ", 4uLL) != 0;
v17 = 0;
v18 = !v16;
if ( !v16 )
return cmd_all((__int64)(v1 + 5));
v19 = "stall";
v20 = 6LL;
v21 = v8;
do
{
if ( !v20 )
break;
v17 = *v21 < (unsigned int)*v19;
v18 = *v21++ == *v19++;
--v20;
}
while ( v18 );
v22 = (!v17 && !v18) - v17;
v23 = 0;
v24 = v22 == 0;
if ( !v22 )
return cmd_stall(v19, v21);
v25 = "hb";
v26 = 3LL;
v27 = v8;
do
{
if ( !v26 )
break;
v23 = *v27 < (unsigned int)*v25;
v24 = *v27++ == *v25++;
--v26;
}
while ( v24 );
if ( (!v23 && !v24) == v23 )
return cmd_heartbeat(v25, v27);
v28 = memcmp(v8, "hbtime ", 7uLL) != 0;
v29 = 0;
v30 = !v28;
if ( v28 )
{
v31 = "hc";
v32 = 3LL;
v33 = v8;
do
{
if ( !v32 )
break;
v29 = *v33 < (unsigned int)*v31;
v30 = *v33++ == *v31++;
--v32;
}
while ( v30 );
if ( (!v29 && !v30) == v29 )
{
result = cmd_heartcheck(v31, v33);
}
else if ( !strncmp(v8, "hctime ", 7uLL) )
{
result = atoi(v1 + 8);
*(_DWORD *)&options[20] = result;
}
else if ( !strncmp(v8, "infinity ", 9uLL) )
{
result = atoi(v1 + 10);
*(_DWORD *)&options[24] = result;
}
else if ( !strcmp(v8, "sleep") )
{
result = cmd_sleep();
}
else
{
result = strncmp(v8, "dropadd ", 8uLL);
if ( result )
{
if ( !strcmp(v8, "wake") )
{
result = cmd_wake();
}
else if ( !strncmp(v8, "rtimeout ", 9uLL) )
{
result = atoi(v1 + 10);
*(_DWORD *)&options[28] = result;
}
else if ( !strncmp(v8, "rattempts ", 0xAuLL) )
{
result = atoi(v1 + 11);
*(_DWORD *)&options[32] = result;
}
else
{
result = con_errorf("unknown command: %s\n", v8);
}
}
else
{
options[14] = v1[9] != 48;
}
}
}
else
{
result = atoi(v1 + 8);
*(_DWORD *)&options[16] = result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(_BYTE *a1)
{
_BYTE *v1; // rbx
bool v2; // cf
bool v3; // zf
char v4; // al
_BYTE *v5; // rsi
__int64 v6; // rdi
int result; // eax
const char *v8; // rbp
const char *v9; // rdi
__int64 v10; // rcx
const char *v11; // rsi
char v12; // al
bool v13; // cf
bool v14; // zf
__int64 v15; // rcx
bool v16; // al
bool v17; // cf
bool v18; // zf
const char *v19; // rdi
__int64 v20; // rcx
const char *v21; // rsi
char v22; // al
bool v23; // cf
bool v24; // zf
const char *v25; // rdi
__int64 v26; // rcx
const char *v27; // rsi
bool v28; // al
bool v29; // cf
bool v30; // zf
const char *v31; // rdi
__int64 v32; // rcx
const char *v33; // rsi

v1 = a1;
v2 = *a1 < 0x2Fu;
v3 = *a1 == 47;
if ( *a1 != 47 )
{
if ( *a1 == 32 )
{
do
++v1;
while ( *v1 == 32 );
}
v4 = *v1;
if ( (unsigned __int8)(*v1 - 48) > 9u )
{
v5 = v1;
v6 = 0xFFFFFFFFLL;
}
else
{
v5 = v1;
LODWORD(v6) = 0;
do
{
v6 = (unsigned int)(v4 + 10 * v6 - 48);
v4 = *++v5;
}
while ( (unsigned __int8)(*v5 - 48) <= 9u );
if ( v5 == v1 )
{
result = (unsigned __int8)*v5;
v6 = 0xFFFFFFFFLL;
LABEL_10:
if ( (_BYTE)result )
result = rbl_sendmessage(v6);
return result;
}
}
for ( result = (unsigned __int8)*v5; (_BYTE)result == 32; result = (unsigned __int8)*v5 )
++v5;
goto LABEL_10;
}
v8 = a1 + 1;
v9 = "tabs";
v10 = 5LL;
v11 = v8;
do
{
if ( !v10 )
break;
v2 = *v11 < (unsigned int)*v9;
v3 = *v11++ == *v9++;
--v10;
}
while ( v3 );
v12 = (!v2 && !v3) - v2;
v13 = 0;
v14 = v12 == 0;
if ( !v12 )
return func13(v9, v11);
v9 = "t";
v15 = 2LL;
v11 = v8;
do
{
if ( !v15 )
break;
v13 = *v11 < (unsigned int)*v9;
v14 = *v11++ == *v9++;
--v15;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
return func13(v9, v11);
if ( !memcmp(v8, "ttl ", 3uLL) )
return func0((__int64)(v1 + 4));
if ( !memcmp(v8, "debugrt ", 8uLL) )
return func1((__int64)(v1 + 9));
if ( !memcmp(v8, "debugpacket ", 0xCuLL) )
return func2((__int64)(v1 + 13));
if ( !memcmp(v8, "debuglost ", 0xAuLL) )
return func3((__int64)(v1 + 11));
if ( !memcmp(v8, "debugroute ", 0xBuLL) )
return func4((__int64)(v1 + 12));
if ( !memcmp(v8, "drop ", 5uLL) )
return func6((__int64)(v1 + 6));
if ( !memcmp(v8, "showtime ", 9uLL) )
return func5((__int64)(v1 + 10));
v16 = memcmp(v8, "all ", 4uLL) != 0;
v17 = 0;
v18 = !v16;
if ( !v16 )
return func7((__int64)(v1 + 5));
v19 = "stall";
v20 = 6LL;
v21 = v8;
do
{
if ( !v20 )
break;
v17 = *v21 < (unsigned int)*v19;
v18 = *v21++ == *v19++;
--v20;
}
while ( v18 );
v22 = (!v17 && !v18) - v17;
v23 = 0;
v24 = v22 == 0;
if ( !v22 )
return func8(v19, v21);
v25 = "hb";
v26 = 3LL;
v27 = v8;
do
{
if ( !v26 )
break;
v23 = *v27 < (unsigned int)*v25;
v24 = *v27++ == *v25++;
--v26;
}
while ( v24 );
if ( (!v23 && !v24) == v23 )
return func10(v25, v27);
v28 = memcmp(v8, "hbtime ", 7uLL) != 0;
v29 = 0;
v30 = !v28;
if ( v28 )
{
v31 = "hc";
v32 = 3LL;
v33 = v8;
do
{
if ( !v32 )
break;
v29 = *v33 < (unsigned int)*v31;
v30 = *v33++ == *v31++;
--v32;
}
while ( v30 );
if ( (!v29 && !v30) == v29 )
{
result = func11(v31, v33);
}
else if ( !strncmp(v8, "hctime ", 7uLL) )
{
result = atoi(v1 + 8);
*(_DWORD *)&options[20] = result;
}
else if ( !strncmp(v8, "infinity ", 9uLL) )
{
result = atoi(v1 + 10);
*(_DWORD *)&options[24] = result;
}
else if ( !strcmp(v8, "sleep") )
{
result = func9();
}
else
{
result = strncmp(v8, "dropadd ", 8uLL);
if ( result )
{
if ( !strcmp(v8, "wake") )
{
result = func12();
}
else if ( !strncmp(v8, "rtimeout ", 9uLL) )
{
result = atoi(v1 + 10);
*(_DWORD *)&options[28] = result;
}
else if ( !strncmp(v8, "rattempts ", 0xAuLL) )
{
result = atoi(v1 + 11);
*(_DWORD *)&options[32] = result;
}
else
{
result = con_errorf("unknown command: %s\n", v8);
}
}
else
{
options[14] = v1[9] != 48;
}
}
}
else
{
result = atoi(v1 + 8);
*(_DWORD *)&options[16] = result;
}
return result;
}

original_code:
static void cmdparser(const char *text) {
    if (text[0] == '/') {
        text++;
        if ((strcmp(text, "tabs") == 0) ||
            (strcmp(text, "t") == 0)) {
            cmd_tabs();
        } else if (strncmp(text, "ttl ", 3) == 0) {
            cmd_ttl(&text[3]);
        } else if (strncmp(text, "debugrt ", 8) == 0) {
            cmd_debugrt(&text[8]);
        } else if (strncmp(text, "debugpacket ", 12) == 0) {
            cmd_debugpacket(&text[12]);
        } else if (strncmp(text, "debuglost ", 10) == 0) {
            cmd_debuglost(&text[10]);
        } else if (strncmp(text, "debugroute ", 11) == 0) {
            cmd_debugroute(&text[11]);
        } else if (strncmp(text, "drop ", 5) == 0) {
            cmd_drop(&text[5]);
        } else if (strncmp(text, "showtime ", 9) == 0) {
            cmd_showtime(&text[9]);
        } else if (strncmp(text, "all ", 4) == 0) {
            cmd_all(&text[4]);
        } else if (strcmp(text, "stall") == 0) {
            cmd_stall();
        } else if (strcmp(text, "hb") == 0) {
            cmd_heartbeat();
        } else if (strncmp(text, "hbtime ", 7) == 0) {
            options.heartbeat = atoi(&text[7]);
        } else if (strcmp(text, "hc") == 0) {
            cmd_heartcheck();
        } else if (strncmp(text, "hctime ", 7) == 0) {
            options.heartcheck = atoi(&text[7]);
        } else if (strncmp(text, "infinity ", 9) == 0) {
            options.infinity = atoi(&text[9]);
        } else if (strcmp(text, "sleep") == 0) {
            cmd_sleep();
        } else if (strncmp(text, "dropadd ", 8) == 0) {
            options.show_dropadd = (text[8] != '0');
        } else if (strcmp(text, "wake") == 0) {
            cmd_wake();
        } else if (strncmp(text, "rtimeout ", 9) == 0) {
            options.rtimeout = atoi(&text[9]);
        } else if (strncmp(text, "rattempts ", 10) == 0) {
            options.rattempts = atoi(&text[10]);
        } else {
            con_errorf("unknown command: %s\n", text);
        }
    } else {
        while (*text == ' ') {
            text++;
        }
        int dst = 0;
        const char *st = text;
        while (*text >= '0' && *text <= '9') {
            dst = dst * 10 + (*text) - '0';
            text++;
        }
        if (st == text) {
            dst = -1;
        }
        while (*text == ' ') {
            text++;
        }
        if (*text != '\0') {
            rbl_sendmessage(dst, text);
        }
    }
}

canonical_original_code:
static void cmdparser(char *text) {
    if (text[0] == '/') {
        text++;
        if ((strcmp(text, "tabs") == 0) ||
            (strcmp(text, "t") == 0)) {
            cmd_tabs();
        } else if (strncmp(text, "ttl ", 3) == 0) {
            cmd_ttl(&text[3]);
        } else if (strncmp(text, "debugrt ", 8) == 0) {
            cmd_debugrt(&text[8]);
        } else if (strncmp(text, "debugpacket ", 12) == 0) {
            cmd_debugpacket(&text[12]);
        } else if (strncmp(text, "debuglost ", 10) == 0) {
            cmd_debuglost(&text[10]);
        } else if (strncmp(text, "debugroute ", 11) == 0) {
            cmd_debugroute(&text[11]);
        } else if (strncmp(text, "drop ", 5) == 0) {
            cmd_drop(&text[5]);
        } else if (strncmp(text, "showtime ", 9) == 0) {
            cmd_showtime(&text[9]);
        } else if (strncmp(text, "all ", 4) == 0) {
            cmd_all(&text[4]);
        } else if (strcmp(text, "stall") == 0) {
            cmd_stall();
        } else if (strcmp(text, "hb") == 0) {
            cmd_heartbeat();
        } else if (strncmp(text, "hbtime ", 7) == 0) {
            options.heartbeat = atoi(&text[7]);
        } else if (strcmp(text, "hc") == 0) {
            cmd_heartcheck();
        } else if (strncmp(text, "hctime ", 7) == 0) {
            options.heartcheck = atoi(&text[7]);
        } else if (strncmp(text, "infinity ", 9) == 0) {
            options.infinity = atoi(&text[9]);
        } else if (strcmp(text, "sleep") == 0) {
            cmd_sleep();
        } else if (strncmp(text, "dropadd ", 8) == 0) {
            options.show_dropadd = (text[8] != '0');
        } else if (strcmp(text, "wake") == 0) {
            cmd_wake();
        } else if (strncmp(text, "rtimeout ", 9) == 0) {
            options.rtimeout = atoi(&text[9]);
        } else if (strncmp(text, "rattempts ", 10) == 0) {
            options.rattempts = atoi(&text[10]);
        } else {
            con_errorf("unknown command: %s\n", text);
        }
    } else {
        while (*text == ' ') {
            text++;
        }
        int dst = 0;
        char *st = text;
        while (*text >= '0' && *text <= '9') {
            dst = dst * 10 + (*text) - '0';
            text++;
        }
        if (st == text) {
            dst = -1;
        }
        while (*text == ' ') {
            text++;
        }
        if (*text != '\0') {
            rbl_sendmessage(dst, text);
        }
    }
}

variable_types:
text
char *

variable_types: dst int

variable_types:
st
char *


decompiled_code:
int __fastcall cmd_order(_BYTE *a1)
{
return cmdparser(a1);
}

canonical_decompiled_code:
int __fastcall func15(_BYTE *a1)
{
return func14(a1);
}

original_code:
void cmd_order(const char *text) {
    cmdparser(text);
}

canonical_original_code:
void cmd_order(char *text) {
    cmdparser(text);
}


decompiled_code:
__int64 cmd_init()
{
return con_register(cmdparser);
}

canonical_decompiled_code:
__int64 func16()
{
return con_register(cmdparser);
}

original_code:
void cmd_init(void) {
    con_register(cmdparser);
}

canonical_original_code:
void cmd_init() {
    con_register(cmdparser);
}


decompiled_code:
void cmd_cleanup()
{
;
}

canonical_decompiled_code:
void func17()
{
;
}

original_code:
void cmd_cleanup(void) {
}

canonical_original_code:
void cmd_cleanup() {
}


decompiled_code:
__int64 __fastcall print_received_msg(unsigned int a1, const char *a2)
{
return con_printf("(MSG from %d): %s\n", a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, const char *a2)
{
return con_printf("(MSG from %d): %s\n", a1, a2);
}

original_code:
static void print_received_msg(int from, const char *msg) {
    con_printf("(MSG from %d): %s\n", from, msg);
}

canonical_original_code:
static void print_received_msg(int from, char *msg) {
    con_printf("(MSG from %d): %s\n", from, msg);
}

variable_types: from int

variable_types:
msg
char *


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

pending = 0;
result = szb_create();
sndbuf = result;
return result;
}

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

pending = 0;
result = szb_create();
sndbuf = result;
return result;
}

original_code:
void rbl_init(void) {
    pending = 0;
    sndbuf = szb_create();
}

canonical_original_code:
void rbl_init() {
    pending = 0;
    sndbuf = szb_create();
}


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

result = szb_free(sndbuf);
sndbuf = 0LL;
return result;
}

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

result = szb_free(sndbuf);
sndbuf = 0LL;
return result;
}

original_code:
void rbl_cleanup(void) {
    szb_free(sndbuf);
    sndbuf = ((void *)0);
}

canonical_original_code:
void rbl_cleanup() {
    szb_free(sndbuf);
    sndbuf = ((void *)0);
}


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

if ( a1 < 0 )
return con_printf("[ERROR] broadcast not implemented\n");
if ( pending )
return con_printf("[ERROR] can't speak for now, msg pending\n");
if ( strlen(a2) > 0x64 )
return con_printf("[ERROR] chat message has 100 characters limit, sorry\n");
szb_clear(sndbuf);
szb_writeCStr(sndbuf, a2);
pending = 1;
sendtime = sys_getMilli();
sendtarget = a1;
result = options[8];
attempts = options[8];
return result;
}

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

if ( a1 < 0 )
return con_printf("[ERROR] broadcast not implemented\n");
if ( pending )
return con_printf("[ERROR] can't speak for now, msg pending\n");
if ( strlen(a2) > 0x64 )
return con_printf("[ERROR] chat message has 100 characters limit, sorry\n");
szb_clear(sndbuf);
szb_writeCStr(sndbuf, a2);
pending = 1;
sendtime = sys_getMilli();
sendtarget = a1;
result = options[8];
attempts = options[8];
return result;
}

original_code:
void rbl_sendmessage(int dst, const char *text) {
    if (dst < 0) {
        con_printf("[ERROR] broadcast not implemented\n");
        return;
    }
    if (pending) {
        con_printf("[ERROR] can't speak for now, msg pending\n");
        return;
    }
    if (strlen(text) > 100) {
        con_printf("[ERROR] chat message has 100 characters limit, sorry\n");
        return;
    }
    szb_clear(sndbuf);
    szb_writeCStr(sndbuf, text);
    pending = 1;
    sendtime = sys_getMilli();
    sendtarget = dst;
    attempts = options.rattempts;
}

canonical_original_code:
void rbl_sendmessage(int dst, char *text) {
    if (dst < 0) {
        con_printf("[ERROR] broadcast not implemented\n");
        return;
    }
    if (pending) {
        con_printf("[ERROR] can't speak for now, msg pending\n");
        return;
    }
    if (strlen(text) > 100) {
        con_printf("[ERROR] chat message has 100 characters limit, sorry\n");
        return;
    }
    szb_clear(sndbuf);
    szb_writeCStr(sndbuf, text);
    pending = 1;
    sendtime = sys_getMilli();
    sendtarget = dst;
    attempts = options.rattempts;
}


getNodeFromAddr

decompiled_code:
__int64 __fastcall getNodeFromAddr(__int64 a1)
{
char *v1; // rax
unsigned int v2; // edx

if ( !a1 )
_assert_fail("sin != NULL", "src/net.c", 0x22u, "getNodeFromAddr");
if ( !nodes )
return (unsigned int)-1;
if ( numNodes <= 0 )
return (unsigned int)-1;
v1 = (char *)nodes + 10;
v2 = 0;
while ( *(_DWORD *)(v1 + 2) != *(_DWORD *)(a1 + 4) || *(_WORD *)v1 != *(_WORD *)(a1 + 2) )
{
++v2;
v1 += 24;
if ( v2 == numNodes )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *v1; // rax
unsigned int v2; // edx

if ( !a1 )
_assert_fail("sin != NULL", "src/net.c", 0x22u, "getNodeFromAddr");
if ( !nodes )
return (unsigned int)-1;
if ( numNodes <= 0 )
return (unsigned int)-1;
v1 = (char *)nodes + 10;
v2 = 0;
while ( *(_DWORD *)(v1 + 2) != *(_DWORD *)(a1 + 4) || *(_WORD *)v1 != *(_WORD *)(a1 + 2) )
{
++v2;
v1 += 24;
if ( v2 == numNodes )
return (unsigned int)-1;
}
return v2;
}

original_code:
static int getNodeFromAddr(struct sockaddr_in *sin) {
    int i;
    ((sin != ((void *)0)) ? (void) (0) : __assert_fail ("sin != NULL", "src/net.c", 34, __extension__ __PRETTY_FUNCTION__));
    if (nodes == ((void *)0)) {
        return -1;
    }
    for (i = 0; i < numNodes; i++) {
        if (nodes[i].sin.sin_addr.s_addr == sin->sin_addr.s_addr &&
            nodes[i].sin.sin_port == sin->sin_port) {
            return i;
        }
    }
    return -1;
}

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

variable_types: i int

return_type: int

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


decompiled_code:
void net_cleanup()
{
if ( sock != -1 )
{
close(sock);
sock = -1;
}
free(nodes);
nodes = 0LL;
}

canonical_decompiled_code:
void func7()
{
if ( sock != -1 )
{
close(sock);
sock = -1;
}
free(nodes);
nodes = 0LL;
}

original_code:
void net_cleanup(void) {
    if (sock != -1) {
        close(sock);
        sock = -1;
    }
    free(nodes);
    nodes = ((void *)0);
}

canonical_original_code:
void net_cleanup() {
    if (sock != -1) {
        close(sock);
        sock = -1;
    }
    free(nodes);
    nodes = ((void *)0);
}


decompiled_code:
__int64 net_init()
{
unsigned int v0; // eax
unsigned int v1; // ebx
int v2; // ebp

v0 = loadRouters();
if ( (_BYTE)v0 )
{
v1 = net_loadLinks();
if ( (_BYTE)v1 )
{
v2 = socket(2, 2, 17);
sock = v2;
if ( v2 == -1 )
{
con_errorf("socket allocation error\n");
v1 = 0;
}
else if ( bind(v2, (const struct sockaddr *)((char *)nodes + 24 * *(int *)&options[4] + 8), 0x10u) == -1 )
{
close(v2);
sock = -1;
con_errorf("socket bind error\n");
v1 = 0;
}
}
else
{
net_cleanup();
}
}
else
{
v1 = v0;
net_cleanup();
}
return v1;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // eax
unsigned int v1; // ebx
int v2; // ebp

v0 = func2();
if ( (_BYTE)v0 )
{
v1 = func6();
if ( (_BYTE)v1 )
{
v2 = socket(2, 2, 17);
sock = v2;
if ( v2 == -1 )
{
con_errorf("socket allocation error\n");
v1 = 0;
}
else if ( bind(v2, (const struct sockaddr *)((char *)nodes + 24 * *(int *)&options[4] + 8), 0x10u) == -1 )
{
close(v2);
sock = -1;
con_errorf("socket bind error\n");
v1 = 0;
}
}
else
{
func7();
}
}
else
{
v1 = v0;
func7();
}
return v1;
}

original_code:
_Bool net_init(void) {
    if (!loadRouters()) {
        net_cleanup();
        return 0;
    }
    if (!net_loadLinks()) {
        net_cleanup();
        return 0;
    }
    sock = socket(2, SOCK_DGRAM, IPPROTO_UDP);
    if (sock == -1) {
        con_errorf("socket allocation error\n");
        return 0;
    }
    if (bind(sock, (struct sockaddr *)&nodes[options.id].sin, sizeof(nodes[options.id].sin)) == -1) {
        close(sock);
        sock = -1;
        con_errorf("socket bind error\n");
        return 0;
    }
    return 1;
}

canonical_original_code:
_Bool net_init() {
    if (!loadRouters()) {
        net_cleanup();
        return 0;
    }
    if (!net_loadLinks()) {
        net_cleanup();
        return 0;
    }
    sock = socket(2, SOCK_DGRAM, IPPROTO_UDP);
    if (sock == -1) {
        con_errorf("socket allocation error\n");
        return 0;
    }
    if (bind(sock, (struct sockaddr *)&nodes[options.id].sin, sizeof(nodes[options.id].sin)) == -1) {
        close(sock);
        sock = -1;
        con_errorf("socket bind error\n");
        return 0;
    }
    return 1;
}

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall net_lastTime(int a1)
{
if ( a1 >= 0 && numNodes > a1 )
return *((unsigned int *)nodes + 6 * a1 + 1);
con_errorf("invalid node number: %d\n", (unsigned int)a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
if ( a1 >= 0 && numNodes > a1 )
return *((unsigned int *)nodes + 6 * a1 + 1);
con_errorf("invalid node number: %d\n", (unsigned int)a1);
return 0LL;
}

original_code:
int net_lastTime(int node) {
    if (node < 0 || node >= numNodes) {
        con_errorf("invalid node number: %d\n", node);
        return 0;
    }
    return nodes[node].lastTime;
}

variable_types: node int


decompiled_code:
__int64 __fastcall net_nextNode(int a1)
{
__int64 result; // rax

result = (unsigned int)(a1 + 1);
if ( a1 + 1 < 0 )
return 0xFFFFFFFFLL;
if ( numNodes <= (int)result )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
__int64 result; // rax

result = (unsigned int)(a1 + 1);
if ( a1 + 1 < 0 )
return 0xFFFFFFFFLL;
if ( numNodes <= (int)result )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int net_nextNode(int node) {
    node = node + 1;
    if (node < 0 || node >= numNodes) {
        return -1;
    }
    return node;
}


decompiled_code:
__int64 sys_getMilli()
{
int v0; // edx
__int64 result; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v0 = clock_gettime(0, &v2);
result = 0LL;
if ( !v0 )
{
if ( !secbase_0 )
secbase_0 = v2.tv_sec;
result = 1000 * (LODWORD(v2.tv_sec) - (_DWORD)secbase_0) + (unsigned int)(v2.tv_nsec / 1000000);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // edx
__int64 result; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v0 = clock_gettime(0, &v2);
result = 0LL;
if ( !v0 )
{
if ( !secbase_0 )
secbase_0 = v2.tv_sec;
result = 1000 * (LODWORD(v2.tv_sec) - (_DWORD)secbase_0) + (unsigned int)(v2.tv_nsec / 1000000);
}
return result;
}

original_code:
int sys_getMilli() {
    int curtime;
    struct timespec tp;
    static time_t secbase = 0;
    if (clock_gettime(0, &tp) != 0) {
        return 0;
    }
    if (secbase == 0) {
        secbase = tp.tv_sec;
    }
    curtime = (tp.tv_sec - secbase) * 1000 + tp.tv_nsec / 1000000;
    return curtime;
}

canonical_original_code:
int sys_getMilli() {
    int curtime;
    struct timespec tp;
    static long secbase = 0;
    if (clock_gettime(0, &tp) != 0) {
        return 0;
    }
    if (secbase == 0) {
        secbase = tp.tv_sec;
    }
    curtime = (tp.tv_sec - secbase) * 1000 + tp.tv_nsec / 1000000;
    return curtime;
}

variable_types: curtime int

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types: secbase long


decompiled_code:
int __fastcall sys_sleep(int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 1000;
v2.tv_nsec = 1000000 * (a1 % 1000);
return clock_nanosleep(0, 0, &v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 1000;
v2.tv_nsec = 1000000 * (a1 % 1000);
return clock_nanosleep(0, 0, &v2, 0LL);
}

original_code:
void sys_sleep(int milli) {
    struct timespec tp;
    tp.tv_sec = milli / 1000;
    tp.tv_nsec = (milli % 1000) * 1000000;
    clock_nanosleep(0, 0, &tp, ((void *)0));
}

variable_types: milli int

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
void sys_init()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

canonical_decompiled_code:
void func2()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

original_code:
void sys_init(void) {
    srand(time(((void *)0)));
}

canonical_original_code:
void sys_init() {
    srand(time(((void *)0)));
}


decompiled_code:
void __fastcall opt_readArgs(int a1, __int64 a2)
{
int i; // ebx
char v5; // si
int v6; // eax
__int64 v7; // rdx
__int64 v8; // rdi

options = 0LL;
*(&options + 1) = 0LL;
*(&options + 5) = 0LL;
*((_DWORD *)&options + 4) = 2000;
*((_DWORD *)&options + 5) = 4000;
*((_DWORD *)&options + 6) = 100;
*((_DWORD *)&options + 7) = 1000;
*((_DWORD *)&options + 8) = 3;
*((_DWORD *)&options + 9) = 10;
if ( a1 > 1 )
{
for ( i = 1; i < a1; ++i )
{
v7 = 8LL * i;
v8 = *(_QWORD *)(a2 + v7);
if ( *(_BYTE *)v8 == 45 )
{
v5 = *(_BYTE *)(v8 + 1);
if ( v5 == 101 )
{
if ( ++i >= a1 )
return;
v6 = atoi(*(const char **)(a2 + v7 + 8));
if ( v6 < 0 )
{
LODWORD(options) = 0;
}
else
{
if ( v6 > 100 )
v6 = 100;
LODWORD(options) = v6;
}
}
else
{
con_errorf("unknown option: %c\n", (unsigned int)v5);
}
}
else if ( (unsigned __int8)(*(_BYTE *)v8 - 48) > 9u )
{
con_errorf("invalid argument: %s\n", *(const char **)(a2 + 8LL * i));
}
else
{
HIDWORD(options) = atoi((const char *)v8);
}
}
}
}

canonical_decompiled_code:
void __fastcall func0(int a1, __int64 a2)
{
int i; // ebx
char v5; // si
int v6; // eax
__int64 v7; // rdx
__int64 v8; // rdi

options = 0LL;
*(&options + 1) = 0LL;
*(&options + 5) = 0LL;
*((_DWORD *)&options + 4) = 2000;
*((_DWORD *)&options + 5) = 4000;
*((_DWORD *)&options + 6) = 100;
*((_DWORD *)&options + 7) = 1000;
*((_DWORD *)&options + 8) = 3;
*((_DWORD *)&options + 9) = 10;
if ( a1 > 1 )
{
for ( i = 1; i < a1; ++i )
{
v7 = 8LL * i;
v8 = *(_QWORD *)(a2 + v7);
if ( *(_BYTE *)v8 == 45 )
{
v5 = *(_BYTE *)(v8 + 1);
if ( v5 == 101 )
{
if ( ++i >= a1 )
return;
v6 = atoi(*(const char **)(a2 + v7 + 8));
if ( v6 < 0 )
{
LODWORD(options) = 0;
}
else
{
if ( v6 > 100 )
v6 = 100;
LODWORD(options) = v6;
}
}
else
{
con_errorf("unknown option: %c\n", (unsigned int)v5);
}
}
else if ( (unsigned __int8)(*(_BYTE *)v8 - 48) > 9u )
{
con_errorf("invalid argument: %s\n", *(const char **)(a2 + 8LL * i));
}
else
{
HIDWORD(options) = atoi((const char *)v8);
}
}
}
}

original_code:
void opt_readArgs(int argc, char **argv) {
    int i;
    memset(&options, 0, sizeof(options));
    options.heartbeat = 2000;
    options.heartcheck = (2*options.heartbeat);
    options.infinity = 100;
    options.rtimeout = 1000;
    options.rattempts = 3;
    options.ttl = 10;
    for (i = 1; i < argc; i++) {
        if (argv[i][0] == '-') {
            switch(argv[i][1]) {
            case 'e':
                if (i + 1 < argc) {
                    options.errRate = atoi(argv[++i]);
                    if (options.errRate < 0) {
                        options.errRate = 0;
                    } else if (options.errRate > 100) {
                        options.errRate = 100;
                    }
                }
                break;
            default:
                con_errorf("unknown option: %c\n", argv[i][1]);
                break;
            }
        } else if (argv[i][0] >= '0' && argv[i][0] <= '9') {
            options.id = atoi(argv[i]);
        } else {
            con_errorf("invalid argument: %s\n", argv[i]);
        }
    }
}

variable_types: argc int

variable_types:
argv
char **


original_code:
static void copy_ent(struct mntent *dst, struct mntent *src)
{
 free(dst->mnt_opts);
 free(dst->mnt_type);
 free(dst->mnt_dir);
 free(dst->mnt_fsname);
 dst->mnt_dir = ((void *)0);
 dst->mnt_type = ((void *)0);
 dst->mnt_opts = ((void *)0);
 dst->mnt_fsname = strdup(src->mnt_fsname);
 if (dst->mnt_fsname)
  dst->mnt_dir = strdup(src->mnt_dir);
 if (dst->mnt_dir)
  dst->mnt_type = strdup(src->mnt_type);
 if (dst->mnt_type)
  dst->mnt_opts = strdup(src->mnt_opts);
 if (dst->mnt_opts) {
  dst->mnt_freq = src->mnt_freq;
  dst->mnt_passno = src->mnt_passno;
 } else
  error_at_line((*__errno_location ()), (*__errno_location ()), "proc_mnt.c", 52, "strdup");
}

variable_types: struct mntent { char *mnt_fsname; char *mnt_dir; char *mnt_type; char *mnt_opts; int mnt_freq; int mnt_passno; } *

variable_types:
src
struct mntent *


decompiled_code:
void __fastcall lock_mtab(char *from)
{
int v1; // ebx
int *v2; // rax

v1 = 5;
while ( link(from, "/etc/mtab~") )
{
sleep(1u);
if ( !--v1 )
{
v2 = _errno_location();
error_at_line(*v2, *v2, "mtab.c", 0x3Au, "/etc/mtab~");
return;
}
}
}

canonical_decompiled_code:
void __fastcall func0(char *from)
{
int v1; // ebx
int *v2; // rax

v1 = 5;
while ( link(from, "/etc/mtab~") )
{
sleep(1u);
if ( !--v1 )
{
v2 = _errno_location();
error_at_line(*v2, *v2, "mtab.c", 0x3Au, "/etc/mtab~");
return;
}
}
}

original_code:
static void lock_mtab(char *pid_file)
{
 int err, i;
 for (i = 0; i < 5; i++) {
  err = link(pid_file, "/etc/mtab" "~");
  if (!err)
   break;
  sleep(1);
 }
 if (err)
  error_at_line((*__errno_location ()), (*__errno_location ()), "mtab.c", 58, "/etc/mtab" "~");
}

canonical_original_code:
static void lock_mtab(char *pid_file)
{
 int err; int i;
 for (i = 0; i < 5; i++) {
  err = link(pid_file, "/etc/mtab" "~");
  if (!err)
   break;
  sleep(1);
 }
 if (err)
  error_at_line((*__errno_location ()), (*__errno_location ()), "mtab.c", 58, "/etc/mtab" "~");
}

variable_types: err int


decompiled_code:
void unlock_mtab()
{
int *v0; // rax

if ( rename("/etc/mtab~", "/etc/mtab") )
{
v0 = _errno_location();
error_at_line(*v0, *v0, "mtab.c", 0x43u, "/etc/mtab");
}
}

canonical_decompiled_code:
void func2()
{
int *v0; // rax

if ( rename("/etc/mtab~", "/etc/mtab") )
{
v0 = _errno_location();
error_at_line(*v0, *v0, "mtab.c", 0x43u, "/etc/mtab");
}
}

original_code:
static void unlock_mtab(void)
{
 int err;
 err = rename("/etc/mtab" "~", "/etc/mtab");
 if (err)
  error_at_line((*__errno_location ()), (*__errno_location ()), "mtab.c", 67, "/etc/mtab");
}

canonical_original_code:
static void unlock_mtab()
{
 int err;
 err = rename("/etc/mtab" "~", "/etc/mtab");
 if (err)
  error_at_line((*__errno_location ()), (*__errno_location ()), "mtab.c", 67, "/etc/mtab");
}


decompiled_code:
int __fastcall au_print_ent(const char **a1)
{
return printf("%s on %s type %s (%s)\n", *a1, a1[1], a1[2], a1[3]);
}

canonical_decompiled_code:
int __fastcall func3(const char **a1)
{
return printf("%s on %s type %s (%s)\n", *a1, a1[1], a1[2], a1[3]);
}

original_code:
void au_print_ent(struct mntent *ent)
{
 printf("%s on %s type %s (%s)\n",
        ent->mnt_fsname, ent->mnt_dir, ent->mnt_type, ent->mnt_opts);
}

user_defined_types: struct mntent { char *mnt_fsname; char *mnt_dir; char *mnt_type; char *mnt_opts; int mnt_freq; int mnt_passno; }


decompiled_code:
_BOOL8 __fastcall libau_dl(void **a1, const char *a2)
{
_BOOL8 result; // rax
char *v3; // rax
char *v4; // rbx

result = 0LL;
if ( !*a1 )
{
dlerror();
*a1 = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, a2);
v3 = dlerror();
v4 = v3;
if ( v3 )
fprintf(stderr, "%s\n", v3);
result = v4 != 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(void **a1, const char *a2)
{
_BOOL8 result; // rax
char *v3; // rax
char *v4; // rbx

result = 0LL;
if ( !*a1 )
{
dlerror();
*a1 = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, a2);
v3 = dlerror();
v4 = v3;
if ( v3 )
fprintf(stderr, "%s\n", v3);
result = v4 != 0LL;
}
return result;
}

original_code:
int libau_dl(void **real, char *sym)
{
 char *p;
 if (*real)
  return 0;
 dlerror();
 *real = dlsym(((void *) -1l), sym);
 p = dlerror();
 if (p)
  fprintf(stderr, "%s\n", p);
 return !!p;
}

variable_types:
real
void **

variable_types:
sym
char *

variable_types:
p
char *


decompiled_code:
char *__fastcall libau_test_func(char *needle)
{
char *v1; // rax
const char *v2; // rbx
char *result; // rax
int v4; // edx
__int64 v5; // r12
char v6; // dl

v1 = getenv("LIBAU");
if ( !v1 )
return 0LL;
v2 = v1;
result = (_BYTE *)(libau_dl + 1);
if ( *v2 )
{
v4 = strcasecmp(v2, "all");
result = (_BYTE *)(libau_dl + 1);
if ( v4 )
{
v5 = (int)strlen(needle);
while ( 1 )
{
result = strstr(v2, needle);
if ( !result )
break;
v6 = result[v5];
v2 = result + 1;
if ( !v6 || v6 == 58 )
return (_BYTE *)(libau_dl + 1);
}
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *needle)
{
char *v1; // rax
const char *v2; // rbx
char *result; // rax
int v4; // edx
__int64 v5; // r12
char v6; // dl

v1 = getenv("LIBAU");
if ( !v1 )
return 0LL;
v2 = v1;
result = (_BYTE *)(libau_dl + 1);
if ( *v2 )
{
v4 = strcasecmp(v2, "all");
result = (_BYTE *)(libau_dl + 1);
if ( v4 )
{
v5 = (int)strlen(needle);
while ( 1 )
{
result = strstr(v2, needle);
if ( !result )
break;
v6 = result[v5];
v2 = result + 1;
if ( !v6 || v6 == 58 )
return (_BYTE *)(libau_dl + 1);
}
}
}
return result;
}

original_code:
int libau_test_func(char *sym)
{
 int ret, l;
 char *e;
 ret = 0;
 e = getenv("LIBAU");
 if (!e)
  goto out;
 do {} while (0);
 ret = !*e || !strcasecmp(e, "all");
 if (ret)
  goto out;
 l = strlen(sym);
 while (!ret && (e = strstr(e, sym))) {
  do {} while (0);
  ret = (!e[l] || e[l] == ':');
  e++;
 }
 out:
 do {} while (0);
 return ret;
}

canonical_original_code:
int libau_test_func(char *sym)
{
 int ret; int l;
 char *e;
 ret = 0;
 e = getenv("LIBAU");
 if (!e)
  goto out;
 do {} while (0);
 ret = !*e || !strcasecmp(e, "all");
 if (ret)
  goto out;
 l = strlen(sym);
 while (!ret && (e = strstr(e, sym))) {
  do {} while (0);
  ret = (!e[l] || e[l] == ':');
  e++;
 }
 out:
 do {} while (0);
 return ret;
}

variable_types: ret int

variable_types: l int

variable_types:
e
char *


repo: cvsync/cvsync

decompiled_code:
char *__fastcall scanfile_rcs_init(__int64 a1)
{
char *v1; // rax
char *v2; // rbx
size_t v3; // rax
size_t v4; // rcx
int *v6; // rax
char *v7; // rax
int *v8; // rax
struct stat v9; // [rsp+0h] [rbp-B8h] BYREF

v1 = (char *)malloc(0x43A0uLL);
v2 = v1;
if ( v1 )
{
scanfile_init(v1);
*((_QWORD *)v2 + 1) = *(_QWORD *)a1;
if ( (unsigned __int8)scanfile_create_tmpfile(v2, *(unsigned int *)(a1 + 40)) )
{
if ( stat(*(const char **)(a1 + 8), &v9) == -1 )
goto LABEL_14;
if ( (v9.st_mode & 0xF000) != 0x4000 )
{
strerror(20);
logmsg_err("%s: %s", *(_QWORD *)(a1 + 8));
scanfile_remove_tmpfile(v2);
free(v2);
return 0LL;
}
if ( !realpath(*(const char **)(a1 + 8), v2 + 4456) )
{
LABEL_14:
v8 = _errno_location();
strerror(*v8);
logmsg_err("%s: %s", *(_QWORD *)(a1 + 8));
scanfile_remove_tmpfile(v2);
free(v2);
v2 = 0LL;
}
else
{
*((_QWORD *)v2 + 1615) = 4352LL;
v3 = strlen(v2 + 4456);
*((_QWORD *)v2 + 1614) = v3 + 1;
if ( v3 + 1 > 0x10FF )
{
strerror(36);
logmsg_err("%s: %s", *(_QWORD *)(a1 + 8));
scanfile_remove_tmpfile(v2);
free(v2);
v2 = 0LL;
}
else
{
v4 = *(_QWORD *)(a1 + 32);
*((_QWORD *)v2 + 1616) = v4;
if ( v4 > 0x10FF )
{
strerror(36);
logmsg_err("%.*s: %s", *(_QWORD *)(a1 + 32));
scanfile_remove_tmpfile(v2);
free(v2);
v2 = 0LL;
}
else
{
v2[v3 + 4456] = 47;
v2[v3 + 4457] = 0;
*((_QWORD *)v2 + 1101) = &v2[v3 + 4457];
if ( v4 )
memcpy(v2 + 8816, *(const void **)(a1 + 24), v4);
*((_QWORD *)v2 + 1617) = *(_QWORD *)(a1 + 48);
*((_DWORD *)v2 + 3236) = *(_DWORD *)(a1 + 56);
*((_QWORD *)v2 + 2163) = 4351LL;
}
}
}
}
else
{
free(v2);
v2 = 0LL;
}
}
else
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err(&unk_BEE, v7);
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1)
{
char *v1; // rax
char *v2; // rbx
size_t v3; // rax
size_t v4; // rcx
int *v6; // rax
char *v7; // rax
int *v8; // rax
struct stat v9; // [rsp+0h] [rbp-B8h] BYREF

v1 = (char *)malloc(0x43A0uLL);
v2 = v1;
if ( v1 )
{
scanfile_init(v1);
*((_QWORD *)v2 + 1) = *(_QWORD *)a1;
if ( (unsigned __int8)scanfile_create_tmpfile(v2, *(unsigned int *)(a1 + 40)) )
{
if ( stat(*(const char **)(a1 + 8), &v9) == -1 )
goto LABEL_14;
if ( (v9.st_mode & 0xF000) != 0x4000 )
{
strerror(20);
logmsg_err("%s: %s", *(_QWORD *)(a1 + 8));
scanfile_remove_tmpfile(v2);
free(v2);
return 0LL;
}
if ( !realpath(*(const char **)(a1 + 8), v2 + 4456) )
{
LABEL_14:
v8 = _errno_location();
strerror(*v8);
logmsg_err("%s: %s", *(_QWORD *)(a1 + 8));
scanfile_remove_tmpfile(v2);
free(v2);
v2 = 0LL;
}
else
{
*((_QWORD *)v2 + 1615) = 4352LL;
v3 = strlen(v2 + 4456);
*((_QWORD *)v2 + 1614) = v3 + 1;
if ( v3 + 1 > 0x10FF )
{
strerror(36);
logmsg_err("%s: %s", *(_QWORD *)(a1 + 8));
scanfile_remove_tmpfile(v2);
free(v2);
v2 = 0LL;
}
else
{
v4 = *(_QWORD *)(a1 + 32);
*((_QWORD *)v2 + 1616) = v4;
if ( v4 > 0x10FF )
{
strerror(36);
logmsg_err("%.*s: %s", *(_QWORD *)(a1 + 32));
scanfile_remove_tmpfile(v2);
free(v2);
v2 = 0LL;
}
else
{
v2[v3 + 4456] = 47;
v2[v3 + 4457] = 0;
*((_QWORD *)v2 + 1101) = &v2[v3 + 4457];
if ( v4 )
memcpy(v2 + 8816, *(const void **)(a1 + 24), v4);
*((_QWORD *)v2 + 1617) = *(_QWORD *)(a1 + 48);
*((_DWORD *)v2 + 3236) = *(_DWORD *)(a1 + 56);
*((_QWORD *)v2 + 2163) = 4351LL;
}
}
}
}
else
{
free(v2);
v2 = 0LL;
}
}
else
{
v6 = _errno_location();
v7 = strerror(*v6);
logmsg_err(&unk_BEE, v7);
}
return v2;
}

original_code:
struct scanfile_rcs_args *
scanfile_rcs_init(struct scanfile_create_args *sca)
{
 struct scanfile_rcs_args *sra;
 struct stat st;
 if ((sra = malloc(sizeof(*sra))) == ((void *)0)) {
  logmsg_err("%s", strerror((*__errno_location ())));
  return (((void *)0));
 }
 scanfile_init(&sra->sra_scanfile);
 sra->sra_scanfile.sa_scanfile_name = sca->sca_name;
 if (!scanfile_create_tmpfile(&sra->sra_scanfile, sca->sca_mode)) {
  free(sra);
  return (0);
 }
 if (stat(sca->sca_prefix, &st) == -1) {
  logmsg_err("%s: %s", sca->sca_prefix, strerror((*__errno_location ())));
  scanfile_remove_tmpfile(&sra->sra_scanfile);
  free(sra);
  return (((void *)0));
 }
 if (!((((st.st_mode)) & 0170000) == (0040000))) {
  logmsg_err("%s: %s", sca->sca_prefix, strerror(20));
  scanfile_remove_tmpfile(&sra->sra_scanfile);
  free(sra);
  return (((void *)0));
 }
 if (realpath(sca->sca_prefix, sra->sra_path) == ((void *)0)) {
  logmsg_err("%s: %s", sca->sca_prefix, strerror((*__errno_location ())));
  scanfile_remove_tmpfile(&sra->sra_scanfile);
  free(sra);
  return (((void *)0));
 }
 sra->sra_pathmax = sizeof(sra->sra_path);
 sra->sra_pathlen = strlen(sra->sra_path) + 1;
 if (sra->sra_pathlen >= sra->sra_pathmax) {
  logmsg_err("%s: %s", sca->sca_prefix, strerror(36));
  scanfile_remove_tmpfile(&sra->sra_scanfile);
  free(sra);
  return (((void *)0));
 }
 if ((sra->sra_rprefixlen = sca->sca_rprefixlen) >= sra->sra_pathmax) {
  logmsg_err("%.*s: %s", sca->sca_rprefixlen, sca->sca_rprefix,
      strerror(36));
  scanfile_remove_tmpfile(&sra->sra_scanfile);
  free(sra);
  return (((void *)0));
 }
 sra->sra_path[sra->sra_pathlen - 1] = '/';
 sra->sra_path[sra->sra_pathlen] = '\0';
 sra->sra_rpath = &sra->sra_path[sra->sra_pathlen];
 if (sra->sra_rprefixlen > 0) {
  (void)memcpy(sra->sra_rprefix, sca->sca_rprefix,
        sca->sca_rprefixlen);
 }
 sra->sra_mdirent_args = sca->sca_mdirent_args;
 sra->sra_umask = sca->sca_umask;
 sra->sra_auxmax = sizeof(sra->sra_aux);
 return (sra);
}

canonical_original_code:
struct scanfile_rcs_args *scanfile_rcs_init(struct scanfile_create_args *sca)
{
 struct scanfile_rcs_args *sra;
 struct stat st;
 if ((sra = malloc(sizeof(*sra))) == ((void *)0)) {
  logmsg_err("%s", strerror((*__errno_location ())));
  return (((void *)0));
 }
 scanfile_init(&sra->sra_scanfile);
 sra->sra_scanfile.sa_scanfile_name = sca->sca_name;
 if (!scanfile_create_tmpfile(&sra->sra_scanfile, sca->sca_mode)) {
  free(sra);
  return (0);
 }
 if (stat(sca->sca_prefix, &st) == -1) {
  logmsg_err("%s: %s", sca->sca_prefix, strerror((*__errno_location ())));
  scanfile_remove_tmpfile(&sra->sra_scanfile);
  free(sra);
  return (((void *)0));
 }
 if (!((((st.st_mode)) & 0170000) == (0040000))) {
  logmsg_err("%s: %s", sca->sca_prefix, strerror(20));
  scanfile_remove_tmpfile(&sra->sra_scanfile);
  free(sra);
  return (((void *)0));
 }
 if (realpath(sca->sca_prefix, sra->sra_path) == ((void *)0)) {
  logmsg_err("%s: %s", sca->sca_prefix, strerror((*__errno_location ())));
  scanfile_remove_tmpfile(&sra->sra_scanfile);
  free(sra);
  return (((void *)0));
 }
 sra->sra_pathmax = sizeof(sra->sra_path);
 sra->sra_pathlen = strlen(sra->sra_path) + 1;
 if (sra->sra_pathlen >= sra->sra_pathmax) {
  logmsg_err("%s: %s", sca->sca_prefix, strerror(36));
  scanfile_remove_tmpfile(&sra->sra_scanfile);
  free(sra);
  return (((void *)0));
 }
 if ((sra->sra_rprefixlen = sca->sca_rprefixlen) >= sra->sra_pathmax) {
  logmsg_err("%.*s: %s", sca->sca_rprefixlen, sca->sca_rprefix,
      strerror(36));
  scanfile_remove_tmpfile(&sra->sra_scanfile);
  free(sra);
  return (((void *)0));
 }
 sra->sra_path[sra->sra_pathlen - 1] = '/';
 sra->sra_path[sra->sra_pathlen] = '\0';
 sra->sra_rpath = &sra->sra_path[sra->sra_pathlen];
 if (sra->sra_rprefixlen > 0) {
  (void)memcpy(sra->sra_rprefix, sca->sca_rprefix,
        sca->sca_rprefixlen);
 }
 sra->sra_mdirent_args = sca->sca_mdirent_args;
 sra->sra_umask = sca->sca_umask;
 sra->sra_auxmax = sizeof(sra->sra_aux);
 return (sra);
}

variable_types: struct scanfile_create_args { char *sca_name; char *sca_rprefix; unsigned long sca_rprefixlen; unsigned int sca_mode; struct mdirent_args *sca_mdirent_args; unsigned int sca_umask; } *

variable_types: struct scanfile_rcs_args { struct scanfile_args { struct cvsync_file { int cf_fileno; long cf_size; long cf_mtime; unsigned int cf_mode; void *cf_addr; unsigned long cf_msize; } *sa_scanfile; char *sa_scanfile_name; unsigned char *sa_start; int sa_tmp; char sa_tmp_name[-1]; unsigned int sa_tmp_mode; struct list { struct listent { struct listent *le_next; void *le_elm; int le_state; } *l_entries; void (*l_destructor)(void *); } *sa_dirlist; struct scanfile_attr { unsigned long a_size; unsigned char a_type; void *a_name; unsigned long a_namelen; void *a_aux; unsigned long a_auxlen; } sa_attr; _Bool sa_changed; } sra_scanfile; char sra_path[-1]; char *sra_rpath; char sra_rprefix[4096]; unsigned long sra_pathlen; struct mdirent_args { int mda_errormode; _Bool mda_symfollow; } *sra_mdirent_args; unsigned int sra_umask; unsigned char sra_aux[-1]; unsigned long sra_auxmax; } *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }

user_defined_types: struct scanfile_rcs_args { struct scanfile_args sra_scanfile; char sra_path[-1]; char *sra_rpath; char sra_rprefix[4096]; unsigned long sra_pathlen; struct mdirent_args *sra_mdirent_args; unsigned int sra_umask; unsigned char sra_aux[-1]; unsigned long sra_auxmax; }

user_defined_types: struct scanfile_args { struct cvsync_file *sa_scanfile; char *sa_scanfile_name; unsigned char *sa_start; int sa_tmp; char sa_tmp_name[-1]; unsigned int sa_tmp_mode; struct list *sa_dirlist; struct scanfile_attr sa_attr; _Bool sa_changed; }

user_defined_types: struct list { struct listent *l_entries; void (*l_destructor)(void *); }


decompiled_code:
void __fastcall scanfile_rcs_destroy(void *ptr)
{
if ( *((_BYTE *)ptr + 36) )
scanfile_remove_tmpfile(ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( *((_BYTE *)ptr + 36) )
scanfile_remove_tmpfile(ptr);
free(ptr);
}

original_code:
void
scanfile_rcs_destroy(struct scanfile_rcs_args *sra)
{
 if (strlen(sra->sra_scanfile.sa_tmp_name) != 0)
  scanfile_remove_tmpfile(&sra->sra_scanfile);
 free(sra);
}

user_defined_types: struct scanfile_attr { unsigned long a_size; unsigned char a_type; void *a_name; unsigned long a_namelen; void *a_aux; unsigned long a_auxlen; }

user_defined_types: struct mdirent_args { int mda_errormode; _Bool mda_symfollow; }

user_defined_types: struct cvsync_file { int cf_fileno; long cf_size; long cf_mtime; unsigned int cf_mode; void *cf_addr; unsigned long cf_msize; }

user_defined_types: struct listent { struct listent *le_next; void *le_elm; int le_state; }


original_code:
_Bool
scanfile_rcs_dir(struct scanfile_rcs_args *sra, struct mdirent_rcs *mdp)
{
 struct scanfile_args *sa = &sra->sra_scanfile;
 struct scanfile_attr *attr = &sa->sa_attr;
 uint16_t mode = ((uint16_t)(((uint16_t)(mdp->md_stat.st_mode) & ~(sra->sra_umask)) & ((0400|0200|0100)|((0400|0200|0100) >> 3)|(((0400|0200|0100) >> 3) >> 3))));
 size_t rpathlen, namelen, auxlen;
 rpathlen = sra->sra_pathlen - (size_t)(sra->sra_rpath - sra->sra_path);
 if ((namelen = rpathlen + mdp->md_namelen) >= sra->sra_pathmax)
  return (0);
 (void)memcpy(&sra->sra_rpath[rpathlen], mdp->md_name, mdp->md_namelen);
 if ((auxlen = attr_rcs_encode_dir(sra->sra_aux, sra->sra_auxmax,
       mode)) == 0) {
  return (0);
 }
 attr->a_type = 'D';
 attr->a_name = sra->sra_rpath;
 attr->a_namelen = namelen;
 attr->a_aux = sra->sra_aux;
 attr->a_auxlen = auxlen;
 if (!scanfile_write_attr(sa, attr))
  return (0);
 return (1);
}

canonical_original_code:
_Bool scanfile_rcs_dir(struct scanfile_rcs_args *sra, struct mdirent_rcs *mdp)
{
 struct scanfile_args *sa = &sra->sra_scanfile;
 struct scanfile_attr *attr = &sa->sa_attr;
 unsigned short mode = ((uint16_t)(((uint16_t)(mdp->md_stat.st_mode) & ~(sra->sra_umask)) & ((0400|0200|0100)|((0400|0200|0100) >> 3)|(((0400|0200|0100) >> 3) >> 3))));
 unsigned long rpathlen; unsigned long namelen; unsigned long auxlen;
 rpathlen = sra->sra_pathlen - (unsigned long)(sra->sra_rpath - sra->sra_path);
 if ((namelen = rpathlen + mdp->md_namelen) >= sra->sra_pathmax)
  return (0);
 (void)memcpy(&sra->sra_rpath[rpathlen], mdp->md_name, mdp->md_namelen);
 if ((auxlen = attr_rcs_encode_dir(sra->sra_aux, sra->sra_auxmax,
       mode)) == 0) {
  return (0);
 }
 attr->a_type = 'D';
 attr->a_name = sra->sra_rpath;
 attr->a_namelen = namelen;
 attr->a_aux = sra->sra_aux;
 attr->a_auxlen = auxlen;
 if (!scanfile_write_attr(sa, attr))
  return (0);
 return (1);
}

variable_types: struct mdirent_rcs { char md_name[-1]; unsigned long md_namelen; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; } md_stat; _Bool md_dead; _Bool md_attic; } *

variable_types: struct scanfile_args { struct cvsync_file { int cf_fileno; long cf_size; long cf_mtime; unsigned int cf_mode; void *cf_addr; unsigned long cf_msize; } *sa_scanfile; char *sa_scanfile_name; unsigned char *sa_start; int sa_tmp; char sa_tmp_name[-1]; unsigned int sa_tmp_mode; struct list { struct listent { struct listent *le_next; void *le_elm; int le_state; } *l_entries; void (*l_destructor)(void *); } *sa_dirlist; struct scanfile_attr { unsigned long a_size; unsigned char a_type; void *a_name; unsigned long a_namelen; void *a_aux; unsigned long a_auxlen; } sa_attr; _Bool sa_changed; } *

variable_types: struct scanfile_attr { unsigned long a_size; unsigned char a_type; void *a_name; unsigned long a_namelen; void *a_aux; unsigned long a_auxlen; } *

variable_types:
mode
unsigned short

variable_types:
rpathlen
unsigned long

variable_types:
namelen
unsigned long

variable_types:
auxlen
unsigned long

user_defined_types: struct mdirent_rcs { char md_name[-1]; unsigned long md_namelen; struct stat md_stat; _Bool md_dead; _Bool md_attic; }


original_code:
_Bool
scanfile_rcs_file(struct scanfile_rcs_args *sra, struct mdirent_rcs *mdp)
{
 struct scanfile_args *sa = &sra->sra_scanfile;
 struct scanfile_attr *attr = &sa->sa_attr;
 struct stat *st = &mdp->md_stat;
 uint16_t mode = ((uint16_t)(((uint16_t)(st->st_mode) & ~(sra->sra_umask)) & ((0400|0200|0100)|((0400|0200|0100) >> 3)|(((0400|0200|0100) >> 3) >> 3))));
 size_t rpathlen, namelen, auxlen;
 rpathlen = sra->sra_pathlen - (size_t)(sra->sra_rpath - sra->sra_path);
 if ((namelen = rpathlen + mdp->md_namelen) >= sra->sra_pathmax)
  return (0);
 (void)memcpy(&sra->sra_rpath[rpathlen], mdp->md_name, mdp->md_namelen);
 if ((((mdp->md_namelen) > 2) && ((mdp->md_name)[(mdp->md_namelen) - 2] == ',') && ((mdp->md_name)[(mdp->md_namelen) - 1] == 'v'))) {
  if (mdp->md_attic)
   attr->a_type = 'r';
  else
   attr->a_type = 'R';
  if ((auxlen = attr_rcs_encode_rcs(sra->sra_aux,
        sra->sra_auxmax,
        st->st_mtime, mode)) == 0) {
   return (0);
  }
 } else {
  attr->a_type = 'F';
  if ((auxlen = attr_rcs_encode_file(sra->sra_aux,
         sra->sra_auxmax,
         st->st_mtime, st->st_size,
         mode)) == 0) {
   return (0);
  }
 }
 attr->a_name = sra->sra_rpath;
 attr->a_namelen = namelen;
 attr->a_aux = sra->sra_aux;
 attr->a_auxlen = auxlen;
 if (!scanfile_write_attr(sa, attr))
  return (0);
 return (1);
}

canonical_original_code:
_Bool scanfile_rcs_file(struct scanfile_rcs_args *sra, struct mdirent_rcs *mdp)
{
 struct scanfile_args *sa = &sra->sra_scanfile;
 struct scanfile_attr *attr = &sa->sa_attr;
 struct stat *st = &mdp->md_stat;
 unsigned short mode = ((uint16_t)(((uint16_t)(st->st_mode) & ~(sra->sra_umask)) & ((0400|0200|0100)|((0400|0200|0100) >> 3)|(((0400|0200|0100) >> 3) >> 3))));
 unsigned long rpathlen; unsigned long namelen; unsigned long auxlen;
 rpathlen = sra->sra_pathlen - (unsigned long)(sra->sra_rpath - sra->sra_path);
 if ((namelen = rpathlen + mdp->md_namelen) >= sra->sra_pathmax)
  return (0);
 (void)memcpy(&sra->sra_rpath[rpathlen], mdp->md_name, mdp->md_namelen);
 if ((((mdp->md_namelen) > 2) && ((mdp->md_name)[(mdp->md_namelen) - 2] == ',') && ((mdp->md_name)[(mdp->md_namelen) - 1] == 'v'))) {
  if (mdp->md_attic)
   attr->a_type = 'r';
  else
   attr->a_type = 'R';
  if ((auxlen = attr_rcs_encode_rcs(sra->sra_aux,
        sra->sra_auxmax,
        st->st_mtime, mode)) == 0) {
   return (0);
  }
 } else {
  attr->a_type = 'F';
  if ((auxlen = attr_rcs_encode_file(sra->sra_aux,
         sra->sra_auxmax,
         st->st_mtime, st->st_size,
         mode)) == 0) {
   return (0);
  }
 }
 attr->a_name = sra->sra_rpath;
 attr->a_namelen = namelen;
 attr->a_aux = sra->sra_aux;
 attr->a_auxlen = auxlen;
 if (!scanfile_write_attr(sa, attr))
  return (0);
 return (1);
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; } *


original_code:
_Bool
scanfile_rcs_symlink(struct scanfile_rcs_args *sra, struct mdirent_rcs *mdp)
{
 struct scanfile_args *sa = &sra->sra_scanfile;
 struct scanfile_attr *attr = &sa->sa_attr;
 size_t rpathlen, namelen;
 ssize_t auxlen;
 rpathlen = sra->sra_pathlen - (size_t)(sra->sra_rpath - sra->sra_path);
 if ((namelen = rpathlen + mdp->md_namelen) >= sra->sra_pathmax)
  return (0);
 (void)memcpy(&sra->sra_rpath[rpathlen], mdp->md_name, mdp->md_namelen);
 sra->sra_rpath[rpathlen + mdp->md_namelen] = '\0';
 if ((auxlen = readlink(sra->sra_path, (char *)sra->sra_aux,
          sra->sra_auxmax)) == -1) {
  logmsg_err("%s: %s", sra->sra_path, strerror((*__errno_location ())));
  return (0);
 }
 attr->a_type = 'S';
 attr->a_name = sra->sra_rpath;
 attr->a_namelen = namelen;
 attr->a_aux = sra->sra_aux;
 attr->a_auxlen = (size_t)auxlen;
 if (!scanfile_write_attr(sa, attr))
  return (0);
 return (1);
}

canonical_original_code:
_Bool scanfile_rcs_symlink(struct scanfile_rcs_args *sra, struct mdirent_rcs *mdp)
{
 struct scanfile_args *sa = &sra->sra_scanfile;
 struct scanfile_attr *attr = &sa->sa_attr;
 unsigned long rpathlen; unsigned long namelen;
 long auxlen;
 rpathlen = sra->sra_pathlen - (unsigned long)(sra->sra_rpath - sra->sra_path);
 if ((namelen = rpathlen + mdp->md_namelen) >= sra->sra_pathmax)
  return (0);
 (void)memcpy(&sra->sra_rpath[rpathlen], mdp->md_name, mdp->md_namelen);
 sra->sra_rpath[rpathlen + mdp->md_namelen] = '\0';
 if ((auxlen = readlink(sra->sra_path, (char *)sra->sra_aux,
          sra->sra_auxmax)) == -1) {
  logmsg_err("%s: %s", sra->sra_path, strerror((*__errno_location ())));
  return (0);
 }
 attr->a_type = 'S';
 attr->a_name = sra->sra_rpath;
 attr->a_namelen = namelen;
 attr->a_aux = sra->sra_aux;
 attr->a_auxlen = (unsigned long)auxlen;
 if (!scanfile_write_attr(sa, attr))
  return (0);
 return (1);
}

variable_types: auxlen long

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall scanfile_rcs(__int64 a1)
{
char *v1; // rax
unsigned int v2; // er13
__int64 *v3; // r12
__int64 v4; // rax
__int64 v5; // r14
__int64 v6; // rbx
_QWORD *v7; // rbp
__int64 v8; // rax
__int64 v9; // rbx
int v10; // eax
unsigned int v12; // er15
__int64 v13; // rax
size_t v14; // rdx
unsigned __int64 v15; // r15
__int64 v16; // rax
__int64 v17; // rax
size_t v18; // [rsp+8h] [rbp-40h]

v1 = scanfile_rcs_init(a1);
v2 = 0;
if ( v1 )
{
v3 = (__int64 *)v1;
v1[4448] = 1;
v4 = list_init();
v5 = v4;
if ( !v4 )
{
LABEL_34:
scanfile_rcs_destroy(v3);
return v2;
}
_list_set_destructor(v4, &mclosedir);
v6 = scanfile_rcs_opendir(v3, v3[1614]);
if ( v6 )
{
*(_QWORD *)(v6 + 32) = v3[1614];
v2 = list_insert_tail(v5, v6);
if ( !(_BYTE)v2 )
{
mclosedir(v6);
list_destroy(v5);
scanfile_rcs_destroy(v3);
return v2;
}
while ( 1 )
{
v7 = (_QWORD *)list_remove_tail(v5);
if ( !v7 )
break;
while ( v7[2] < v7[1] )
{
if ( (unsigned __int8)cvsync_isinterrupted() )
goto LABEL_18;
v8 = v7[2];
v7[2] = v8 + 1;
v9 = *v7 + 416 * v8;
v2 = *(unsigned __int8 *)(v9 + 408);
if ( !(_BYTE)v2 )
{
v10 = *(_DWORD *)(v9 + 288) & 0xF000;
switch ( v10 )
{
case 32768:
v2 = scanfile_rcs_file((__int64)v3, v9);
if ( !(_BYTE)v2 )
goto LABEL_12;
break;
case 40960:
v2 = scanfile_rcs_symlink((__int64)v3, (_QWORD *)v9);
if ( !(_BYTE)v2 )
{
LABEL_12:
mclosedir(v7);
list_destroy(v5);
scanfile_rcs_destroy(v3);
return v2;
}
break;
case 16384:
v12 = scanfile_rcs_dir((__int64)v3, v9);
if ( !(_BYTE)v12 )
{
mclosedir(v7);
list_destroy(v5);
scanfile_rcs_destroy(v3);
return v12;
}
v13 = v3[1614];
v14 = *(_QWORD *)(v9 + 256);
v18 = v13 + v14;
v15 = v13 + v14 + 1;
if ( v3[1615] <= v15 )
goto LABEL_12;
memcpy((char *)v3 + v13 + 4456, (const void *)v9, v14);
*((_BYTE *)v3 + v18 + 4456) = 47;
*((_BYTE *)v3 + v15 + 4456) = 0;
if ( !(unsigned __int8)list_insert_tail(v5, v7) )
{
LABEL_18:
mclosedir(v7);
list_destroy(v5);
scanfile_rcs_destroy(v3);
return 0;
}
v16 = scanfile_rcs_opendir(v3, v15);
v7 = (_QWORD *)v16;
if ( !v16 )
{
list_destroy(v5);
scanfile_rcs_destroy(v3);
return v2;
}
*(_QWORD *)(v16 + 24) = v9;
*(_QWORD *)(v16 + 32) = v3[1614];
v3[1614] = v15;
break;
default:
goto LABEL_12;
}
}
}
v17 = v7[4];
v3[1614] = v17;
*((_BYTE *)v3 + v17 + 4456) = 0;
mclosedir(v7);
if ( (unsigned __int8)list_isempty(v5) )
{
list_destroy(v5);
v2 = scanfile_rename(v3);
goto LABEL_34;
}
}
}
list_destroy(v5);
scanfile_rcs_destroy(v3);
v2 = 0;
}
return v2;
}

original_code:
_Bool
scanfile_rcs(struct scanfile_create_args *sca)
{
 struct scanfile_rcs_args *sra;
 struct mDIR *mdirp;
 struct mdirent_rcs *mdp, *entries;
 struct list *lp;
 size_t len;
 if ((sra = scanfile_rcs_init(sca)) == ((void *)0))
  return (0);
 sra->sra_scanfile.sa_changed = 1;
 if ((lp = list_init()) == ((void *)0)) {
  scanfile_rcs_destroy(sra);
  return (0);
 }
 __list_set_destructor((lp), (list_destructor)(mclosedir));
 if ((mdirp = scanfile_rcs_opendir(sra, sra->sra_pathlen)) == ((void *)0)) {
  list_destroy(lp);
  scanfile_rcs_destroy(sra);
  return (0);
 }
 mdirp->m_parent_pathlen = sra->sra_pathlen;
 if (!list_insert_tail(lp, mdirp)) {
  mclosedir(mdirp);
  list_destroy(lp);
  scanfile_rcs_destroy(sra);
  return (0);
 }
 do {
  if ((mdirp = list_remove_tail(lp)) == ((void *)0)) {
   list_destroy(lp);
   scanfile_rcs_destroy(sra);
   return (0);
  }
  while (mdirp->m_offset < mdirp->m_nentries) {
   if (cvsync_isinterrupted()) {
    mclosedir(mdirp);
    list_destroy(lp);
    scanfile_rcs_destroy(sra);
    return (0);
   }
   entries = mdirp->m_entries;
   mdp = &entries[mdirp->m_offset++];
   if (mdp->md_dead)
    continue;
   switch (mdp->md_stat.st_mode & 0170000) {
   case 0040000:
    if (!scanfile_rcs_dir(sra, mdp)) {
     mclosedir(mdirp);
     list_destroy(lp);
     scanfile_rcs_destroy(sra);
     return (0);
    }
    len = sra->sra_pathlen + mdp->md_namelen + 1;
    if (len >= sra->sra_pathmax) {
     mclosedir(mdirp);
     list_destroy(lp);
     scanfile_rcs_destroy(sra);
     return (0);
    }
    (void)memcpy(&sra->sra_path[sra->sra_pathlen],
          mdp->md_name, mdp->md_namelen);
    sra->sra_path[len - 1] = '/';
    sra->sra_path[len] = '\0';
    if (!list_insert_tail(lp, mdirp)) {
     mclosedir(mdirp);
     list_destroy(lp);
     scanfile_rcs_destroy(sra);
     return (0);
    }
    mdirp = scanfile_rcs_opendir(sra, len);
    if (mdirp == ((void *)0)) {
     list_destroy(lp);
     scanfile_rcs_destroy(sra);
     return (0);
    }
    mdirp->m_parent = mdp;
    mdirp->m_parent_pathlen = sra->sra_pathlen;
    sra->sra_pathlen = len;
    break;
   case 0100000:
    if (!scanfile_rcs_file(sra, mdp)) {
     mclosedir(mdirp);
     list_destroy(lp);
     scanfile_rcs_destroy(sra);
     return (0);
    }
    break;
   case 0120000:
    if (!scanfile_rcs_symlink(sra, mdp)) {
     mclosedir(mdirp);
     list_destroy(lp);
     scanfile_rcs_destroy(sra);
     return (0);
    }
    break;
   default:
    mclosedir(mdirp);
    list_destroy(lp);
    scanfile_rcs_destroy(sra);
    return (0);
   }
  }
  sra->sra_pathlen = mdirp->m_parent_pathlen;
  sra->sra_path[sra->sra_pathlen] = '\0';
  mclosedir(mdirp);
 } while (!list_isempty(lp));
 list_destroy(lp);
 if (!scanfile_rename(&sra->sra_scanfile)) {
  scanfile_rcs_destroy(sra);
  return (0);
 }
 scanfile_rcs_destroy(sra);
 return (1);
}

canonical_original_code:
_Bool scanfile_rcs(struct scanfile_create_args *sca)
{
 struct scanfile_rcs_args *sra;
 struct mDIR *mdirp;
 struct mdirent_rcs *mdp; struct mdirent_rcs *entries;
 struct list *lp;
 unsigned long len;
 if ((sra = scanfile_rcs_init(sca)) == ((void *)0))
  return (0);
 sra->sra_scanfile.sa_changed = 1;
 if ((lp = list_init()) == ((void *)0)) {
  scanfile_rcs_destroy(sra);
  return (0);
 }
 __list_set_destructor((lp), (list_destructor)(mclosedir));
 if ((mdirp = scanfile_rcs_opendir(sra, sra->sra_pathlen)) == ((void *)0)) {
  list_destroy(lp);
  scanfile_rcs_destroy(sra);
  return (0);
 }
 mdirp->m_parent_pathlen = sra->sra_pathlen;
 if (!list_insert_tail(lp, mdirp)) {
  mclosedir(mdirp);
  list_destroy(lp);
  scanfile_rcs_destroy(sra);
  return (0);
 }
 do {
  if ((mdirp = list_remove_tail(lp)) == ((void *)0)) {
   list_destroy(lp);
   scanfile_rcs_destroy(sra);
   return (0);
  }
  while (mdirp->m_offset < mdirp->m_nentries) {
   if (cvsync_isinterrupted()) {
    mclosedir(mdirp);
    list_destroy(lp);
    scanfile_rcs_destroy(sra);
    return (0);
   }
   entries = mdirp->m_entries;
   mdp = &entries[mdirp->m_offset++];
   if (mdp->md_dead)
    continue;
   switch (mdp->md_stat.st_mode & 0170000) {
   case 0040000:
    if (!scanfile_rcs_dir(sra, mdp)) {
     mclosedir(mdirp);
     list_destroy(lp);
     scanfile_rcs_destroy(sra);
     return (0);
    }
    len = sra->sra_pathlen + mdp->md_namelen + 1;
    if (len >= sra->sra_pathmax) {
     mclosedir(mdirp);
     list_destroy(lp);
     scanfile_rcs_destroy(sra);
     return (0);
    }
    (void)memcpy(&sra->sra_path[sra->sra_pathlen],
          mdp->md_name, mdp->md_namelen);
    sra->sra_path[len - 1] = '/';
    sra->sra_path[len] = '\0';
    if (!list_insert_tail(lp, mdirp)) {
     mclosedir(mdirp);
     list_destroy(lp);
     scanfile_rcs_destroy(sra);
     return (0);
    }
    mdirp = scanfile_rcs_opendir(sra, len);
    if (mdirp == ((void *)0)) {
     list_destroy(lp);
     scanfile_rcs_destroy(sra);
     return (0);
    }
    mdirp->m_parent = mdp;
    mdirp->m_parent_pathlen = sra->sra_pathlen;
    sra->sra_pathlen = len;
    break;
   case 0100000:
    if (!scanfile_rcs_file(sra, mdp)) {
     mclosedir(mdirp);
     list_destroy(lp);
     scanfile_rcs_destroy(sra);
     return (0);
    }
    break;
   case 0120000:
    if (!scanfile_rcs_symlink(sra, mdp)) {
     mclosedir(mdirp);
     list_destroy(lp);
     scanfile_rcs_destroy(sra);
     return (0);
    }
    break;
   default:
    mclosedir(mdirp);
    list_destroy(lp);
    scanfile_rcs_destroy(sra);
    return (0);
   }
  }
  sra->sra_pathlen = mdirp->m_parent_pathlen;
  sra->sra_path[sra->sra_pathlen] = '\0';
  mclosedir(mdirp);
 } while (!list_isempty(lp));
 list_destroy(lp);
 if (!scanfile_rename(&sra->sra_scanfile)) {
  scanfile_rcs_destroy(sra);
  return (0);
 }
 scanfile_rcs_destroy(sra);
 return (1);
}

variable_types: struct scanfile_create_args { char *sca_name; char *sca_rprefix; unsigned long sca_rprefixlen; unsigned int sca_mode; struct mdirent_args { int mda_errormode; _Bool mda_symfollow; } *sca_mdirent_args; unsigned int sca_umask; } *

variable_types: struct mDIR { void *m_entries; unsigned long m_nentries; void *m_parent; unsigned long m_parent_pathlen; } *

variable_types: struct list { struct listent { struct listent *le_next; void *le_elm; int le_state; } *l_entries; void (*l_destructor)(void *); } *

variable_types:
len
unsigned long

user_defined_types: struct scanfile_create_args { char *sca_name; char *sca_rprefix; unsigned long sca_rprefixlen; unsigned int sca_mode; struct mdirent_args *sca_mdirent_args; unsigned int sca_umask; }


decompiled_code:
__int64 __fastcall config_insert_collection(__int64 a1, __int64 a2)
{
char *v2; // rbx
const char *v3; // rbp
const char *v4; // r12
__int64 result; // rax

v2 = *(char **)(a1 + 22328);
v3 = (const char *)(a2 + 8);
v4 = (const char *)(a2 + 264);
if ( v2 )
{
while ( 1 )
{
if ( !strcasecmp(v2 + 8, v3) && !strcasecmp(v2 + 264, v4) )
{
logmsg_err("collection %s/%s: duplicate", v3, v4);
return 0LL;
}
if ( !*(_QWORD *)v2 )
break;
v2 = *(char **)v2;
}
*(_QWORD *)v2 = a2;
result = 1LL;
}
else
{
*(_QWORD *)(a1 + 22328) = a2;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
char *v2; // rbx
const char *v3; // rbp
const char *v4; // r12
__int64 result; // rax

v2 = *(char **)(a1 + 22328);
v3 = (const char *)(a2 + 8);
v4 = (const char *)(a2 + 264);
if ( v2 )
{
while ( 1 )
{
if ( !strcasecmp(v2 + 8, v3) && !strcasecmp(v2 + 264, v4) )
{
logmsg_err("collection %s/%s: duplicate", v3, v4);
return 0LL;
}
if ( !*(_QWORD *)v2 )
break;
v2 = *(char **)v2;
}
*(_QWORD *)v2 = a2;
result = 1LL;
}
else
{
*(_QWORD *)(a1 + 22328) = a2;
result = 1LL;
}
return result;
}

original_code:
_Bool
config_insert_collection(struct config *cf, struct collection *cl)
{
 struct collection *prev = cf->cf_collections;
 if (prev == ((void *)0)) {
  cf->cf_collections = cl;
  return (1);
 }
 for (;;) {
  if ((strcasecmp(prev->cl_name, cl->cl_name) == 0) &&
      (strcasecmp(prev->cl_release, cl->cl_release) == 0)) {
   logmsg_err("collection %s/%s: duplicate", cl->cl_name,
       cl->cl_release);
   return (0);
  }
  if (prev->cl_next == ((void *)0)) {
   prev->cl_next = cl;
   break;
  }
  prev = prev->cl_next;
 }
 return (1);
}

variable_types: struct config { char cf_addr[-1]; char cf_serv[-1]; unsigned long cf_maxclients; char cf_base[4096]; char cf_access_name[-1]; char cf_halt_name[-1]; char cf_pid_name[-1]; int cf_hash; struct collection { struct collection *cl_next; char cl_name[-1]; char cl_release[-1]; char cl_prefix[4096]; unsigned long cl_prefixlen; char cl_comment[256]; int cl_errormode; _Bool cl_symfollow; unsigned short cl_umask; char cl_dist_name[-1]; char cl_scan_name[-1]; struct collection *cl_super; char cl_super_name[-1]; } *cf_collections; struct config_include { struct config_include *ci_next; char ci_name[-1]; long ci_mtime; } *cf_includes; int cf_refcnt; } *

variable_types:
cl
struct collection *

user_defined_types: struct config { char cf_addr[-1]; char cf_serv[-1]; unsigned long cf_maxclients; char cf_base[4096]; char cf_access_name[-1]; char cf_halt_name[-1]; char cf_pid_name[-1]; int cf_hash; struct collection *cf_collections; struct config_include *cf_includes; int cf_refcnt; }


decompiled_code:
__int64 __fastcall config_resolv_prefix(__int64 a1, __int64 a2, unsigned int a3)
{
char v4; // al
__int64 result; // rax
int v6; // eax
char *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
size_t v11; // rdx
size_t v12; // rax
int v13; // er13
char *v14; // rax
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
char v19[4096]; // [rsp+0h] [rbp-10B8h] BYREF
struct stat v20; // [rsp+1000h] [rbp-B8h] BYREF

v4 = *(_BYTE *)(a2 + 520);
if ( v4 == 47 )
{
v6 = snprintf(v19, 0x1000uLL, "%s", (const char *)(a2 + 520));
}
else
{
if ( !*(_BYTE *)(a1 + 5168) )
{
if ( v4 )
{
logmsg_err(
"collection %s/%s: prefix %s: must be the absolute path",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520));
result = 0LL;
}
else
{
logmsg_err("collection %s/%s: no prefix", (const char *)(a2 + 8), (const char *)(a2 + 264));
result = 0LL;
}
return result;
}
v6 = snprintf(v19, 0x1000uLL, "%s/%s", (const char *)(a1 + 5168), (const char *)(a2 + 520));
}
if ( (unsigned int)(v6 - 1) > 0xFFE )
{
v8 = strerror(22);
logmsg_err(
"collection %s/%s: prefix %s: %s",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520),
v8);
return 0LL;
}
if ( stat(v19, &v20) == -1 )
goto LABEL_14;
if ( (v20.st_mode & 0xF000) != 0x4000 )
{
v7 = strerror(20);
logmsg_err(
"collection %s/%s: prefix %s: %s",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520),
v7);
return 0LL;
}
if ( !realpath(v19, (char *)(a2 + 520)) )
{
LABEL_14:
v9 = _errno_location();
v10 = strerror(*v9);
logmsg_err(
"collection %s/%s: prefix %s: %s",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520),
v10);
return 0LL;
}
v11 = strlen((const char *)(a2 + 520));
*(_QWORD *)(a2 + 8712) = v11;
v12 = v11 + 1;
if ( v11 + 1 > 0xFFF )
{
v14 = strerror(36);
logmsg_err(
"collection %s/%s: prefix %s: %s",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520),
v14);
return 0LL;
}
*(_QWORD *)(a2 + 8712) = v12;
*(_BYTE *)(a2 + v11 + 520) = 47;
*(_BYTE *)(a2 + v12 + 520) = 0;
result = a3;
if ( !(_BYTE)a3 )
{
qmemcpy((void *)(a2 + v11 + 521), ".cvsync.XXXXXX", 14);
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 534) = 0;
v13 = mkstemp((char *)(a2 + 520));
if ( v13 != -1 )
{
if ( unlink((const char *)(a2 + 520)) == -1 )
{
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 520) = 0;
v15 = _errno_location();
v16 = strerror(*v15);
logmsg_err(
"collection %s/%s: prefix %s: %s",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520),
v16);
close(v13);
return a3;
}
if ( close(v13) != -1 )
{
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 520) = 0;
return 1LL;
}
}
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 520) = 0;
v17 = _errno_location();
v18 = strerror(*v17);
logmsg_err(
"collection %s/%s: prefix %s: %s",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520),
v18);
result = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3)
{
char v4; // al
__int64 result; // rax
int v6; // eax
char *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
size_t v11; // rdx
size_t v12; // rax
int v13; // er13
char *v14; // rax
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
char v19[4096]; // [rsp+0h] [rbp-10B8h] BYREF
struct stat v20; // [rsp+1000h] [rbp-B8h] BYREF

v4 = *(_BYTE *)(a2 + 520);
if ( v4 == 47 )
{
v6 = snprintf(v19, 0x1000uLL, "%s", (const char *)(a2 + 520));
}
else
{
if ( !*(_BYTE *)(a1 + 5168) )
{
if ( v4 )
{
logmsg_err(
"collection %s/%s: prefix %s: must be the absolute path",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520));
result = 0LL;
}
else
{
logmsg_err("collection %s/%s: no prefix", (const char *)(a2 + 8), (const char *)(a2 + 264));
result = 0LL;
}
return result;
}
v6 = snprintf(v19, 0x1000uLL, "%s/%s", (const char *)(a1 + 5168), (const char *)(a2 + 520));
}
if ( (unsigned int)(v6 - 1) > 0xFFE )
{
v8 = strerror(22);
logmsg_err(
"collection %s/%s: prefix %s: %s",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520),
v8);
return 0LL;
}
if ( stat(v19, &v20) == -1 )
goto LABEL_14;
if ( (v20.st_mode & 0xF000) != 0x4000 )
{
v7 = strerror(20);
logmsg_err(
"collection %s/%s: prefix %s: %s",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520),
v7);
return 0LL;
}
if ( !realpath(v19, (char *)(a2 + 520)) )
{
LABEL_14:
v9 = _errno_location();
v10 = strerror(*v9);
logmsg_err(
"collection %s/%s: prefix %s: %s",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520),
v10);
return 0LL;
}
v11 = strlen((const char *)(a2 + 520));
*(_QWORD *)(a2 + 8712) = v11;
v12 = v11 + 1;
if ( v11 + 1 > 0xFFF )
{
v14 = strerror(36);
logmsg_err(
"collection %s/%s: prefix %s: %s",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520),
v14);
return 0LL;
}
*(_QWORD *)(a2 + 8712) = v12;
*(_BYTE *)(a2 + v11 + 520) = 47;
*(_BYTE *)(a2 + v12 + 520) = 0;
result = a3;
if ( !(_BYTE)a3 )
{
qmemcpy((void *)(a2 + v11 + 521), ".cvsync.XXXXXX", 14);
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 534) = 0;
v13 = mkstemp((char *)(a2 + 520));
if ( v13 != -1 )
{
if ( unlink((const char *)(a2 + 520)) == -1 )
{
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 520) = 0;
v15 = _errno_location();
v16 = strerror(*v15);
logmsg_err(
"collection %s/%s: prefix %s: %s",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520),
v16);
close(v13);
return a3;
}
if ( close(v13) != -1 )
{
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 520) = 0;
return 1LL;
}
}
*(_BYTE *)(a2 + *(_QWORD *)(a2 + 8712) + 520) = 0;
v17 = _errno_location();
v18 = strerror(*v17);
logmsg_err(
"collection %s/%s: prefix %s: %s",
(const char *)(a2 + 8),
(const char *)(a2 + 264),
(const char *)(a2 + 520),
v18);
result = a3;
}
return result;
}

original_code:
_Bool
config_resolv_prefix(struct config *cf, struct collection *cl, _Bool rdonly)
{
 struct stat st;
 char path[4096];
 int fd, wn;
 if (cl->cl_prefix[0] != '/') {
  if (strlen(cf->cf_base_prefix) == 0) {
   if (strlen(cl->cl_prefix) == 0) {
    logmsg_err("collection %s/%s: no prefix",
        cl->cl_name, cl->cl_release);
   } else {
    logmsg_err("collection %s/%s: prefix %s: "
        "must be the absolute path",
        cl->cl_name, cl->cl_release,
        cl->cl_prefix);
   }
   return (0);
  }
  wn = snprintf(path, sizeof(path), "%s/%s", cf->cf_base_prefix,
         cl->cl_prefix);
 } else {
  wn = snprintf(path, sizeof(path), "%s", cl->cl_prefix);
 }
 if ((wn <= 0) || ((size_t)wn >= sizeof(path))) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror(22));
  return (0);
 }
 if (stat(path, &st) == -1) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror((*__errno_location ())));
  return (0);
 }
 if (!((((st.st_mode)) & 0170000) == (0040000))) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror(20));
  return (0);
 }
 if (realpath(path, cl->cl_prefix) == ((void *)0)) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror((*__errno_location ())));
  return (0);
 }
 cl->cl_prefixlen = strlen(cl->cl_prefix);
 if (cl->cl_prefixlen + 1 >= sizeof(cl->cl_prefix)) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix,
      strerror(36));
  return (0);
 }
 cl->cl_prefix[cl->cl_prefixlen++] = '/';
 cl->cl_prefix[cl->cl_prefixlen] = '\0';
 if (!rdonly) {
  (void)memcpy(&cl->cl_prefix[cl->cl_prefixlen], ".cvsync.XXXXXX",
        (14));
  cl->cl_prefix[cl->cl_prefixlen + (14)] = '\0';
  if ((fd = mkstemp(cl->cl_prefix)) == -1) {
   cl->cl_prefix[cl->cl_prefixlen] = '\0';
   logmsg_err("collection %s/%s: prefix %s: %s",
       cl->cl_name, cl->cl_release, cl->cl_prefix,
       strerror((*__errno_location ())));
   return (0);
  }
  if (unlink(cl->cl_prefix) == -1) {
   cl->cl_prefix[cl->cl_prefixlen] = '\0';
   logmsg_err("collection %s/%s: prefix %s: %s",
       cl->cl_name, cl->cl_release, cl->cl_prefix,
       strerror((*__errno_location ())));
   (void)close(fd);
   return (0);
  }
  if (close(fd) == -1) {
   cl->cl_prefix[cl->cl_prefixlen] = '\0';
   logmsg_err("collection %s/%s: prefix %s: %s",
       cl->cl_name, cl->cl_release, cl->cl_prefix,
       strerror((*__errno_location ())));
   return (0);
  }
  cl->cl_prefix[cl->cl_prefixlen] = '\0';
 }
 return (1);
}

canonical_original_code:
_Bool config_resolv_prefix(struct config *cf, struct collection *cl, _Bool rdonly)
{
 struct stat st;
 char path[4096];
 int fd; int wn;
 if (cl->cl_prefix[0] != '/') {
  if (strlen(cf->cf_base_prefix) == 0) {
   if (strlen(cl->cl_prefix) == 0) {
    logmsg_err("collection %s/%s: no prefix",
        cl->cl_name, cl->cl_release);
   } else {
    logmsg_err("collection %s/%s: prefix %s: "
        "must be the absolute path",
        cl->cl_name, cl->cl_release,
        cl->cl_prefix);
   }
   return (0);
  }
  wn = snprintf(path, sizeof(path), "%s/%s", cf->cf_base_prefix,
         cl->cl_prefix);
 } else {
  wn = snprintf(path, sizeof(path), "%s", cl->cl_prefix);
 }
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(path))) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror(22));
  return (0);
 }
 if (stat(path, &st) == -1) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror((*__errno_location ())));
  return (0);
 }
 if (!((((st.st_mode)) & 0170000) == (0040000))) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror(20));
  return (0);
 }
 if (realpath(path, cl->cl_prefix) == ((void *)0)) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix, strerror((*__errno_location ())));
  return (0);
 }
 cl->cl_prefixlen = strlen(cl->cl_prefix);
 if (cl->cl_prefixlen + 1 >= sizeof(cl->cl_prefix)) {
  logmsg_err("collection %s/%s: prefix %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_prefix,
      strerror(36));
  return (0);
 }
 cl->cl_prefix[cl->cl_prefixlen++] = '/';
 cl->cl_prefix[cl->cl_prefixlen] = '\0';
 if (!rdonly) {
  (void)memcpy(&cl->cl_prefix[cl->cl_prefixlen], ".cvsync.XXXXXX",
        (14));
  cl->cl_prefix[cl->cl_prefixlen + (14)] = '\0';
  if ((fd = mkstemp(cl->cl_prefix)) == -1) {
   cl->cl_prefix[cl->cl_prefixlen] = '\0';
   logmsg_err("collection %s/%s: prefix %s: %s",
       cl->cl_name, cl->cl_release, cl->cl_prefix,
       strerror((*__errno_location ())));
   return (0);
  }
  if (unlink(cl->cl_prefix) == -1) {
   cl->cl_prefix[cl->cl_prefixlen] = '\0';
   logmsg_err("collection %s/%s: prefix %s: %s",
       cl->cl_name, cl->cl_release, cl->cl_prefix,
       strerror((*__errno_location ())));
   (void)close(fd);
   return (0);
  }
  if (close(fd) == -1) {
   cl->cl_prefix[cl->cl_prefixlen] = '\0';
   logmsg_err("collection %s/%s: prefix %s: %s",
       cl->cl_name, cl->cl_release, cl->cl_prefix,
       strerror((*__errno_location ())));
   return (0);
  }
  cl->cl_prefix[cl->cl_prefixlen] = '\0';
 }
 return (1);
}

variable_types:
path
char [4096]

variable_types: fd int

variable_types: wn int

user_defined_types: struct collection { struct collection *cl_next; char cl_name[-1]; char cl_release[-1]; char cl_prefix[4096]; unsigned long cl_prefixlen; char cl_comment[256]; int cl_errormode; _Bool cl_symfollow; unsigned short cl_umask; char cl_dist_name[-1]; char cl_scan_name[-1]; struct collection *cl_super; char cl_super_name[-1]; }

user_defined_types: struct config_include { struct config_include *ci_next; char ci_name[-1]; long ci_mtime; }


decompiled_code:
__int64 __fastcall config_resolv_scanfile(__int64 a1, const char *a2)
{
char v2; // dl
__int64 result; // rax
int v4; // eax
unsigned int v5; // edx
char *v6; // rax
char *v7; // rax
char v8[4360]; // [rsp-1108h] [rbp-1108h] BYREF

v2 = a2[13344];
result = 1LL;
if ( v2 )
{
if ( v2 == 47 )
{
v4 = snprintf(v8, 0x1100uLL, "%s", a2 + 13344);
}
else
{
if ( !*(_BYTE *)(a1 + 1072) )
{
logmsg_err("collection %s/%s: scanfile %s: must be an absolute path", a2 + 8, a2 + 264, a2 + 13344);
return 0LL;
}
v4 = snprintf(v8, 0x1100uLL, "%s/%s", (const char *)(a1 + 1072), a2 + 13344);
}
if ( (unsigned int)(v4 - 1) > 0x10FE )
{
v6 = strerror(22);
logmsg_err("collection %s/%s: scanfile %s: %s", a2 + 8, a2 + 264, a2 + 13344, v6);
result = 0LL;
}
else
{
v5 = snprintf((char *)a2 + 13344, 0x1100uLL, "%s", v8) - 1;
result = 1LL;
if ( v5 > 0x10FE )
{
v7 = strerror(22);
logmsg_err("collection %s/%s: scanfile %s: %s", a2 + 8, a2 + 264, v8, v7);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
char v2; // dl
__int64 result; // rax
int v4; // eax
unsigned int v5; // edx
char *v6; // rax
char *v7; // rax
char v8[4360]; // [rsp-1108h] [rbp-1108h] BYREF

v2 = a2[13344];
result = 1LL;
if ( v2 )
{
if ( v2 == 47 )
{
v4 = snprintf(v8, 0x1100uLL, "%s", a2 + 13344);
}
else
{
if ( !*(_BYTE *)(a1 + 1072) )
{
logmsg_err("collection %s/%s: scanfile %s: must be an absolute path", a2 + 8, a2 + 264, a2 + 13344);
return 0LL;
}
v4 = snprintf(v8, 0x1100uLL, "%s/%s", (const char *)(a1 + 1072), a2 + 13344);
}
if ( (unsigned int)(v4 - 1) > 0x10FE )
{
v6 = strerror(22);
logmsg_err("collection %s/%s: scanfile %s: %s", a2 + 8, a2 + 264, a2 + 13344, v6);
result = 0LL;
}
else
{
v5 = snprintf((char *)a2 + 13344, 0x1100uLL, "%s", v8) - 1;
result = 1LL;
if ( v5 > 0x10FE )
{
v7 = strerror(22);
logmsg_err("collection %s/%s: scanfile %s: %s", a2 + 8, a2 + 264, v8, v7);
result = 0LL;
}
}
}
return result;
}

original_code:
_Bool
config_resolv_scanfile(struct config *cf, struct collection *cl)
{
 char path[4096 + (255) + 1];
 int wn;
 if (strlen(cl->cl_scan_name) == 0)
  return (1);
 if (cl->cl_scan_name[0] != '/') {
  if (strlen(cf->cf_base) == 0) {
   logmsg_err("collection %s/%s: scanfile %s: must be an "
       "absolute path", cl->cl_name,
       cl->cl_release, cl->cl_scan_name);
   return (0);
  }
  wn = snprintf(path, sizeof(path), "%s/%s", cf->cf_base,
         cl->cl_scan_name);
 } else {
  wn = snprintf(path, sizeof(path), "%s", cl->cl_scan_name);
 }
 if ((wn <= 0) || ((size_t)wn >= sizeof(path))) {
  logmsg_err("collection %s/%s: scanfile %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_scan_name, strerror(22));
  return (0);
 }
 wn = snprintf(cl->cl_scan_name, sizeof(cl->cl_scan_name), "%s", path);
 if ((wn <= 0) || ((size_t)wn >= sizeof(cl->cl_scan_name))) {
  logmsg_err("collection %s/%s: scanfile %s: %s", cl->cl_name,
      cl->cl_release, path, strerror(22));
  return (0);
 }
 return (1);
}

canonical_original_code:
_Bool config_resolv_scanfile(struct config *cf, struct collection *cl)
{
 char path[-1];
 int wn;
 if (strlen(cl->cl_scan_name) == 0)
  return (1);
 if (cl->cl_scan_name[0] != '/') {
  if (strlen(cf->cf_base) == 0) {
   logmsg_err("collection %s/%s: scanfile %s: must be an "
       "absolute path", cl->cl_name,
       cl->cl_release, cl->cl_scan_name);
   return (0);
  }
  wn = snprintf(path, sizeof(path), "%s/%s", cf->cf_base,
         cl->cl_scan_name);
 } else {
  wn = snprintf(path, sizeof(path), "%s", cl->cl_scan_name);
 }
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(path))) {
  logmsg_err("collection %s/%s: scanfile %s: %s", cl->cl_name,
      cl->cl_release, cl->cl_scan_name, strerror(22));
  return (0);
 }
 wn = snprintf(cl->cl_scan_name, sizeof(cl->cl_scan_name), "%s", path);
 if ((wn <= 0) || ((unsigned long)wn >= sizeof(cl->cl_scan_name))) {
  logmsg_err("collection %s/%s: scanfile %s: %s", cl->cl_name,
      cl->cl_release, path, strerror(22));
  return (0);
 }
 return (1);
}

variable_types:
path
char [-1]


decompiled_code:
__int64 __fastcall attr_rcs_encode_dir(_BYTE *a1, unsigned __int64 a2, __int16 a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 > 1 )
{
*a1 = HIBYTE(a3);
a1[1] = a3;
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, unsigned __int64 a2, __int16 a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 > 1 )
{
*a1 = HIBYTE(a3);
a1[1] = a3;
result = 2LL;
}
return result;
}

original_code:
size_t
attr_rcs_encode_dir(uint8_t *buffer, size_t bufsize, uint16_t mode)
{
 if (bufsize < (2))
  return (0);
 do { (buffer)[0] = (uint8_t)((uint16_t)(mode) >> 8); (buffer)[1] = (uint8_t)((uint16_t)(mode) >> 0); } while ( 0);
 return ((2));
}

canonical_original_code:
unsigned long attr_rcs_encode_dir(unsigned char *buffer, unsigned long bufsize, unsigned short mode)
{
 if (bufsize < (2))
  return (0);
 do { (buffer)[0] = (unsigned char)((unsigned short)(mode) >> 8); (buffer)[1] = (unsigned char)((unsigned short)(mode) >> 0); } while ( 0);
 return ((2));
}

variable_types:
buffer
unsigned char *

variable_types:
bufsize
unsigned long

return_type: unsigned long


canonical_original_code:
unsigned long attr_rcs_encode_file(unsigned char *buffer, unsigned long bufsize, long mtime, long size, unsigned short mode)
{
 if (bufsize < (18))
  return (0);
 do { (buffer)[0] = (unsigned char)((unsigned long)(mtime) >> 56); (buffer)[1] = (unsigned char)((unsigned long)(mtime) >> 48); (buffer)[2] = (unsigned char)((unsigned long)(mtime) >> 40); (buffer)[3] = (unsigned char)((unsigned long)(mtime) >> 32); (buffer)[4] = (unsigned char)((unsigned long)(mtime) >> 24); (buffer)[5] = (unsigned char)((unsigned long)(mtime) >> 16); (buffer)[6] = (unsigned char)((unsigned long)(mtime) >> 8); (buffer)[7] = (unsigned char)((unsigned long)(mtime) >> 0); } while ( 0);
 do { (&buffer[8])[0] = (unsigned char)((unsigned long)(size) >> 56); (&buffer[8])[1] = (unsigned char)((unsigned long)(size) >> 48); (&buffer[8])[2] = (unsigned char)((unsigned long)(size) >> 40); (&buffer[8])[3] = (unsigned char)((unsigned long)(size) >> 32); (&buffer[8])[4] = (unsigned char)((unsigned long)(size) >> 24); (&buffer[8])[5] = (unsigned char)((unsigned long)(size) >> 16); (&buffer[8])[6] = (unsigned char)((unsigned long)(size) >> 8); (&buffer[8])[7] = (unsigned char)((unsigned long)(size) >> 0); } while ( 0);
 do { (&buffer[16])[0] = (unsigned char)((unsigned short)(mode) >> 8); (&buffer[16])[1] = (unsigned char)((unsigned short)(mode) >> 0); } while ( 0);
 return ((18));
}

variable_types: mtime long

variable_types: size long

variable_types:
mode
unsigned short


decompiled_code:
__int64 __fastcall attr_rcs_encode_rcs(_BYTE *a1, unsigned __int64 a2, __int64 a3, __int16 a4)
{
__int64 result; // rax

result = 0LL;
if ( a2 > 9 )
{
*a1 = HIBYTE(a3);
a1[1] = BYTE6(a3);
a1[2] = BYTE5(a3);
a1[3] = BYTE4(a3);
a1[4] = BYTE3(a3);
a1[5] = BYTE2(a3);
a1[6] = BYTE1(a3);
a1[7] = a3;
a1[8] = HIBYTE(a4);
a1[9] = a4;
result = 10LL;
}
return result;
}

original_code:
size_t
attr_rcs_encode_rcs(uint8_t *buffer, size_t bufsize, time_t mtime,
      uint16_t mode)
{
 if (bufsize < (10))
  return (0);
 do { (buffer)[0] = (uint8_t)((uint64_t)(mtime) >> 56); (buffer)[1] = (uint8_t)((uint64_t)(mtime) >> 48); (buffer)[2] = (uint8_t)((uint64_t)(mtime) >> 40); (buffer)[3] = (uint8_t)((uint64_t)(mtime) >> 32); (buffer)[4] = (uint8_t)((uint64_t)(mtime) >> 24); (buffer)[5] = (uint8_t)((uint64_t)(mtime) >> 16); (buffer)[6] = (uint8_t)((uint64_t)(mtime) >> 8); (buffer)[7] = (uint8_t)((uint64_t)(mtime) >> 0); } while ( 0);
 do { (&buffer[8])[0] = (uint8_t)((uint16_t)(mode) >> 8); (&buffer[8])[1] = (uint8_t)((uint16_t)(mode) >> 0); } while ( 0);
 return ((10));
}

canonical_original_code:
unsigned long attr_rcs_encode_rcs(unsigned char *buffer, unsigned long bufsize, long mtime, unsigned short mode)
{
 if (bufsize < (10))
  return (0);
 do { (buffer)[0] = (unsigned char)((unsigned long)(mtime) >> 56); (buffer)[1] = (unsigned char)((unsigned long)(mtime) >> 48); (buffer)[2] = (unsigned char)((unsigned long)(mtime) >> 40); (buffer)[3] = (unsigned char)((unsigned long)(mtime) >> 32); (buffer)[4] = (unsigned char)((unsigned long)(mtime) >> 24); (buffer)[5] = (unsigned char)((unsigned long)(mtime) >> 16); (buffer)[6] = (unsigned char)((unsigned long)(mtime) >> 8); (buffer)[7] = (unsigned char)((unsigned long)(mtime) >> 0); } while ( 0);
 do { (&buffer[8])[0] = (unsigned char)((unsigned short)(mode) >> 8); (&buffer[8])[1] = (unsigned char)((unsigned short)(mode) >> 0); } while ( 0);
 return ((10));
}


decompiled_code:
__int64 __fastcall attr_rcs_decode_dir(unsigned __int16 *a1, unsigned __int64 a2, __int64 a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 > 1 )
{
*(_WORD *)(a3 + 4384) = _byteswap_ushort(*a1);
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a2 > 1 )
{
*(_WORD *)(a3 + 4384) = _byteswap_ushort(*a1);
result = 1LL;
}
return result;
}

original_code:
_Bool
attr_rcs_decode_dir(uint8_t *buffer, size_t bufsize, struct cvsync_attr *cap)
{
 if (bufsize < (2))
  return (0);
 cap->ca_mode = ((uint16_t)((((uint16_t)((buffer)[0])) << 8) | (((uint16_t)((buffer)[1])) << 0)));
 return (1);
}

canonical_original_code:
_Bool attr_rcs_decode_dir(unsigned char *buffer, unsigned long bufsize, struct cvsync_attr *cap)
{
 if (bufsize < (2))
  return (0);
 cap->ca_mode = ((unsigned short)((((unsigned short)((buffer)[0])) << 8) | (((unsigned short)((buffer)[1])) << 0)));
 return (1);
}

variable_types: struct cvsync_attr { unsigned char ca_tag; unsigned char ca_type; unsigned char ca_name[-1]; unsigned long ca_namelen; long ca_mtime; unsigned long ca_size; unsigned short ca_mode; unsigned char ca_aux[-1]; unsigned long ca_auxlen; } *


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

result = 0LL;
if ( a2 > 0x11 )
{
*(_QWORD *)(a3 + 4368) = _byteswap_uint64(*(_QWORD *)a1);
*(_QWORD *)(a3 + 4376) = _byteswap_uint64(*(_QWORD *)(a1 + 8));
*(_WORD *)(a3 + 4384) = _byteswap_ushort(*(_WORD *)(a1 + 16));
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a2 > 0x11 )
{
*(_QWORD *)(a3 + 4368) = _byteswap_uint64(*(_QWORD *)a1);
*(_QWORD *)(a3 + 4376) = _byteswap_uint64(*(_QWORD *)(a1 + 8));
*(_WORD *)(a3 + 4384) = _byteswap_ushort(*(_WORD *)(a1 + 16));
result = 1LL;
}
return result;
}

canonical_original_code:
_Bool attr_rcs_decode_file(unsigned char *buffer, unsigned long bufsize, struct cvsync_attr *cap)
{
 if (bufsize < (18))
  return (0);
 cap->ca_mtime = (long)((unsigned long)((((unsigned long)((buffer)[0])) << 56) | (((unsigned long)((buffer)[1])) << 48) | (((unsigned long)((buffer)[2])) << 40) | (((unsigned long)((buffer)[3])) << 32) | (((unsigned long)((buffer)[4])) << 24) | (((unsigned long)((buffer)[5])) << 16) | (((unsigned long)((buffer)[6])) << 8) | (((unsigned long)((buffer)[7])) << 0)));
 cap->ca_size = ((unsigned long)((((unsigned long)((&buffer[8])[0])) << 56) | (((unsigned long)((&buffer[8])[1])) << 48) | (((unsigned long)((&buffer[8])[2])) << 40) | (((unsigned long)((&buffer[8])[3])) << 32) | (((unsigned long)((&buffer[8])[4])) << 24) | (((unsigned long)((&buffer[8])[5])) << 16) | (((unsigned long)((&buffer[8])[6])) << 8) | (((unsigned long)((&buffer[8])[7])) << 0)));
 cap->ca_mode = ((unsigned short)((((unsigned short)((&buffer[16])[0])) << 8) | (((unsigned short)((&buffer[16])[1])) << 0)));
 return (1);
}

user_defined_types: struct cvsync_attr { unsigned char ca_tag; unsigned char ca_type; unsigned char ca_name[-1]; unsigned long ca_namelen; long ca_mtime; unsigned long ca_size; unsigned short ca_mode; unsigned char ca_aux[-1]; unsigned long ca_auxlen; }


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

result = 0LL;
if ( a2 > 9 )
{
*(_QWORD *)(a3 + 4368) = _byteswap_uint64(*(_QWORD *)a1);
*(_WORD *)(a3 + 4384) = _byteswap_ushort(*(_WORD *)(a1 + 8));
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a2 > 9 )
{
*(_QWORD *)(a3 + 4368) = _byteswap_uint64(*(_QWORD *)a1);
*(_WORD *)(a3 + 4384) = _byteswap_ushort(*(_WORD *)(a1 + 8));
result = 1LL;
}
return result;
}

canonical_original_code:
_Bool attr_rcs_decode_rcs(unsigned char *buffer, unsigned long bufsize, struct cvsync_attr *cap)
{
 if (bufsize < (10))
  return (0);
 cap->ca_mtime = (long)((unsigned long)((((unsigned long)((buffer)[0])) << 56) | (((unsigned long)((buffer)[1])) << 48) | (((unsigned long)((buffer)[2])) << 40) | (((unsigned long)((buffer)[3])) << 32) | (((unsigned long)((buffer)[4])) << 24) | (((unsigned long)((buffer)[5])) << 16) | (((unsigned long)((buffer)[6])) << 8) | (((unsigned long)((buffer)[7])) << 0)));
 cap->ca_mode = ((unsigned short)((((unsigned short)((&buffer[8])[0])) << 8) | (((unsigned short)((&buffer[8])[1])) << 0)));
 return (1);
}


decompiled_code:
int __fastcall cvsync_signal(int a1)
{
int result; // eax

sigaction(2, &cvsync_sig_ign, 0LL);
result = sigaction(15, &cvsync_sig_ign, 0LL);
if ( a1 == 2 )
{
cvsync_process_terminated = 1;
}
else if ( a1 != 15 )
{
return result;
}
cvsync_process_interrupted = 1;
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int result; // eax

sigaction(2, &cvsync_sig_ign, 0LL);
result = sigaction(15, &cvsync_sig_ign, 0LL);
if ( a1 == 2 )
{
cvsync_process_terminated = 1;
}
else if ( a1 != 15 )
{
return result;
}
cvsync_process_interrupted = 1;
return result;
}

original_code:
void
cvsync_signal(int sig)
{
 sigaction(2, &cvsync_sig_ign, ((void *)0));
 sigaction(15, &cvsync_sig_ign, ((void *)0));
 switch (sig) {
 case 1:
 case 13:
  break;
 case 2:
  cvsync_process_terminated = 1;
 case 15:
  cvsync_process_interrupted = 1;
  break;
 default:
  break;
 }
}

variable_types: sig int