decompiled_code:
__int64 update_rt()
{
int v0; // eax
int v1; // er14
unsigned int v2; // ebx
unsigned int v3; // er15
unsigned int v4; // er13
int v5; // er12
int i; // ebp
int v7; // eax
int v8; // ebp

v0 = num_destinations();
if ( v0 > 0 )
{
v1 = v0;
v2 = 0;
v3 = 0;
while ( 1 )
{
if ( *((_DWORD *)&options + 1) == v2 )
goto LABEL_3;
v4 = -1;
v5 = -1;
if ( (unsigned __int8)is_neighbour(v2) )
{
v4 = v2;
v5 = get_neighbour_cost(v2);
}
for ( i = next_neighbour(0xFFFFFFFFLL); i >= 0; i = next_neighbour((unsigned int)i) )
{
while ( 1 )
{
v7 = get_dv_distance((unsigned int)i, v2);
if ( v7 >= 0 && (v7 < v5 || v5 < 0) )
break;
i = next_neighbour((unsigned int)i);
if ( i < 0 )
goto LABEL_14;
}
v5 = v7;
v4 = i;
}
LABEL_14:
v8 = get_rt_distance(v2);
if ( v8 == v5 )
goto LABEL_3;
get_rt_via(v2);
set_rt_distance(v2, (unsigned int)v5);
set_rt_via(v2, v4);
v3 = *((unsigned __int8 *)&options + 14);
if ( (_BYTE)v3 )
{
if ( v8 < 0 )
{
con_printf("[DEBUG] adding node %d\n", v2);
if ( v5 >= 0 )
goto LABEL_18;
}
else if ( v5 >= 0 )
{
goto LABEL_18;
}
con_printf("[DEBUG] dropping node %d\n", v2);
LABEL_3:
if ( v1 == ++v2 )
return v3;
}
else
{
LABEL_18:
++v2;
v3 = 1;
if ( v1 == v2 )
return v3;
}
}
}
return 0;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
int v1; // er14
unsigned int v2; // ebx
unsigned int v3; // er15
unsigned int v4; // er13
int v5; // er12
int i; // ebp
int v7; // eax
int v8; // ebp

v0 = num_destinations();
if ( v0 > 0 )
{
v1 = v0;
v2 = 0;
v3 = 0;
while ( 1 )
{
if ( *((_DWORD *)&options + 1) == v2 )
goto LABEL_3;
v4 = -1;
v5 = -1;
if ( (unsigned __int8)is_neighbour(v2) )
{
v4 = v2;
v5 = get_neighbour_cost(v2);
}
for ( i = next_neighbour(0xFFFFFFFFLL); i >= 0; i = next_neighbour((unsigned int)i) )
{
while ( 1 )
{
v7 = get_dv_distance((unsigned int)i, v2);
if ( v7 >= 0 && (v7 < v5 || v5 < 0) )
break;
i = next_neighbour((unsigned int)i);
if ( i < 0 )
goto LABEL_14;
}
v5 = v7;
v4 = i;
}
LABEL_14:
v8 = get_rt_distance(v2);
if ( v8 == v5 )
goto LABEL_3;
get_rt_via(v2);
set_rt_distance(v2, (unsigned int)v5);
set_rt_via(v2, v4);
v3 = *((unsigned __int8 *)&options + 14);
if ( (_BYTE)v3 )
{
if ( v8 < 0 )
{
con_printf("[DEBUG] adding node %d\n", v2);
if ( v5 >= 0 )
goto LABEL_18;
}
else if ( v5 >= 0 )
{
goto LABEL_18;
}
con_printf("[DEBUG] dropping node %d\n", v2);
LABEL_3:
if ( v1 == ++v2 )
return v3;
}
else
{
LABEL_18:
++v2;
v3 = 1;
if ( v1 == v2 )
return v3;
}
}
}
return 0;
}

original_code:
_Bool update_rt(void) {
    int ndests = num_destinations();
    _Bool changed = 0;
    for (int to = 0; to < ndests; to++) {
        if (to == options.id) {
            continue;
        }
        int mindist = -1;
        int minvia = -1;
        if (is_neighbour(to)) {
            mindist = get_neighbour_cost(to);
            minvia = to;
        }
        for (int via = next_neighbour(-1); via >= 0; via = next_neighbour(via)) {
            int newdist = get_dv_distance(via, to);
            if ((((newdist) >= 0) && (((newdist) < (mindist)) || !((mindist) >= 0)))) {
                mindist = newdist;
                minvia = via;
            }
        }
        int olddist = get_rt_distance(to);
        if (olddist != mindist) {
            int oldvia = get_rt_via(to);
            changed = 1;
            set_rt_distance(to, mindist);
            set_rt_via(to, minvia);
            if (options.show_dropadd) {
                if (!((olddist) >= 0)) {
                    con_printf("[DEBUG] adding node %d\n", to);
                }
                if (!((mindist) >= 0)) {
                    con_printf("[DEBUG] dropping node %d\n", to);
                }
            }
        }
    }
    return changed;
}

canonical_original_code:
_Bool update_rt() {
    int ndests = num_destinations();
    _Bool changed = 0;
    for (int to = 0; to < ndests; to++) {
        if (to == options.id) {
            continue;
        }
        int mindist = -1;
        int minvia = -1;
        if (is_neighbour(to)) {
            mindist = get_neighbour_cost(to);
            minvia = to;
        }
        for (int via = next_neighbour(-1); via >= 0; via = next_neighbour(via)) {
            int newdist = get_dv_distance(via, to);
            if ((((newdist) >= 0) && (((newdist) < (mindist)) || !((mindist) >= 0)))) {
                mindist = newdist;
                minvia = via;
            }
        }
        int olddist = get_rt_distance(to);
        if (olddist != mindist) {
            int oldvia = get_rt_via(to);
            changed = 1;
            set_rt_distance(to, mindist);
            set_rt_via(to, minvia);
            if (options.show_dropadd) {
                if (!((olddist) >= 0)) {
                    con_printf("[DEBUG] adding node %d\n", to);
                }
                if (!((mindist) >= 0)) {
                    con_printf("[DEBUG] dropping node %d\n", to);
                }
            }
        }
    }
    return changed;
}

variable_types: ndests int

variable_types: to int

variable_types: mindist int

variable_types: minvia int

variable_types: via int

variable_types: newdist int

variable_types: olddist int

variable_types: oldvia int


decompiled_code:
void router_dropcheck()
{
char v0; // bl
char v1; // r12
int v2; // ebp
int v3; // er13
int v4; // eax
int v5; // er13
int v6; // ebp
int v7; // ebp

v0 = *((_BYTE *)&options + 13);
if ( v0 )
return;
v1 = *((_BYTE *)&options + 12);
if ( !v1 )
{
v7 = next_neighbour(0xFFFFFFFFLL);
if ( v7 < 0 )
return;
do
{
if ( (int)(*((_DWORD *)&options + 5) + net_lastTime((unsigned int)v7)) < time )
{
v0 = 1;
drop_neighbour((unsigned int)v7);
}
v7 = next_neighbour((unsigned int)v7);
}
while ( v7 >= 0 );
goto LABEL_14;
}
v2 = next_neighbour(0xFFFFFFFFLL);
if ( v2 < 0 )
{
v5 = -1001;
}
else
{
v3 = -1;
do
{
v4 = net_lastTime((unsigned int)v2);
if ( v3 < v4 )
v3 = v4;
v2 = next_neighbour((unsigned int)v2);
}
while ( v2 >= 0 );
v5 = v3 - 1000;
}
v6 = next_neighbour(0xFFFFFFFFLL);
if ( v6 >= 0 )
{
do
{
while ( (int)net_lastTime((unsigned int)v6) >= v5 )
{
v6 = next_neighbour((unsigned int)v6);
if ( v6 < 0 )
goto LABEL_14;
}
v0 = v1;
drop_neighbour((unsigned int)v6);
v6 = next_neighbour((unsigned int)v6);
}
while ( v6 >= 0 );
LABEL_14:
if ( v0 )
{
update_rt();
send_dv();
if ( *((_BYTE *)&options + 44) )
my_print_rtab();
}
}
}

canonical_decompiled_code:
void func3()
{
char v0; // bl
char v1; // r12
int v2; // ebp
int v3; // er13
int v4; // eax
int v5; // er13
int v6; // ebp
int v7; // ebp

v0 = *((_BYTE *)&options + 13);
if ( v0 )
return;
v1 = *((_BYTE *)&options + 12);
if ( !v1 )
{
v7 = next_neighbour(0xFFFFFFFFLL);
if ( v7 < 0 )
return;
do
{
if ( (int)(*((_DWORD *)&options + 5) + net_lastTime((unsigned int)v7)) < time )
{
v0 = 1;
drop_neighbour((unsigned int)v7);
}
v7 = next_neighbour((unsigned int)v7);
}
while ( v7 >= 0 );
goto LABEL_14;
}
v2 = next_neighbour(0xFFFFFFFFLL);
if ( v2 < 0 )
{
v5 = -1001;
}
else
{
v3 = -1;
do
{
v4 = net_lastTime((unsigned int)v2);
if ( v3 < v4 )
v3 = v4;
v2 = next_neighbour((unsigned int)v2);
}
while ( v2 >= 0 );
v5 = v3 - 1000;
}
v6 = next_neighbour(0xFFFFFFFFLL);
if ( v6 >= 0 )
{
do
{
while ( (int)net_lastTime((unsigned int)v6) >= v5 )
{
v6 = next_neighbour((unsigned int)v6);
if ( v6 < 0 )
goto LABEL_14;
}
v0 = v1;
drop_neighbour((unsigned int)v6);
v6 = next_neighbour((unsigned int)v6);
}
while ( v6 >= 0 );
LABEL_14:
if ( v0 )
{
func2();
func1();
if ( *((_BYTE *)&options + 44) )
func0();
}
}
}

original_code:
void router_dropcheck(void) {
    int i;
    _Bool dropped = 0;
    if (options.sleeping) {
        return;
    }
    if (options.stalled) {
        int largest_time = -1;
        for (i = next_neighbour(-1); i >= 0; i = next_neighbour(i)) {
            int thistime = net_lastTime(i);
            if (thistime > largest_time) {
                largest_time = thistime;
            }
        }
        int base_time = largest_time;
        base_time -= 1000;
        for (i = next_neighbour(-1); i >= 0; i = next_neighbour(i)) {
            if (net_lastTime(i) < base_time) {
                drop_neighbour(i);
                dropped = 1;
            }
        }
    } else {
        for (i = next_neighbour(-1); i >= 0; i = next_neighbour(i)) {
            if (net_lastTime(i) + options.heartcheck < time) {
                drop_neighbour(i);
                dropped = 1;
            }
        }
    }
    if (dropped) {
        update_rt();
        send_dv();
        if (options.debugrt) {
            my_print_rtab();
        }
    }
}

canonical_original_code:
void router_dropcheck() {
    int i;
    _Bool dropped = 0;
    if (options.sleeping) {
        return;
    }
    if (options.stalled) {
        int largest_time = -1;
        for (i = next_neighbour(-1); i >= 0; i = next_neighbour(i)) {
            int thistime = net_lastTime(i);
            if (thistime > largest_time) {
                largest_time = thistime;
            }
        }
        int base_time = largest_time;
        base_time -= 1000;
        for (i = next_neighbour(-1); i >= 0; i = next_neighbour(i)) {
            if (net_lastTime(i) < base_time) {
                drop_neighbour(i);
                dropped = 1;
            }
        }
    } else {
        for (i = next_neighbour(-1); i >= 0; i = next_neighbour(i)) {
            if (net_lastTime(i) + options.heartcheck < time) {
                drop_neighbour(i);
                dropped = 1;
            }
        }
    }
    if (dropped) {
        update_rt();
        send_dv();
        if (options.debugrt) {
            my_print_rtab();
        }
    }
}

variable_types: i int

variable_types: thistime int

return_type: void


decompiled_code:
__int64 reset_timeouts()
{
int v0; // eax
int v1; // edx
int v2; // edx
__int64 result; // rax

v0 = sys_getMilli();
v1 = options[4];
time = v0;
nextHeartBeat = v0 + v1;
v2 = v0 + options[5];
result = (unsigned int)(options[2] + v0);
nextHeartCheck = v2;
nextShow = result;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // eax
int v1; // edx
int v2; // edx
__int64 result; // rax

v0 = sys_getMilli();
v1 = options[4];
time = v0;
nextHeartBeat = v0 + v1;
v2 = v0 + options[5];
result = (unsigned int)(options[2] + v0);
nextHeartCheck = v2;
nextShow = result;
return result;
}

original_code:
void reset_timeouts(void) {
    int startTime = time = sys_getMilli();
    nextHeartBeat = startTime + options.heartbeat;
    nextHeartCheck = startTime + options.heartcheck;
    nextShow = startTime + options.showtime;
}

canonical_original_code:
void reset_timeouts() {
    int startTime = time = sys_getMilli();
    nextHeartBeat = startTime + options.heartbeat;
    nextHeartCheck = startTime + options.heartcheck;
    nextShow = startTime + options.showtime;
}

variable_types: startTime int


decompiled_code:
void router_cleanup()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void router_cleanup(void) {
}

canonical_original_code:
void router_cleanup() {
}


decompiled_code:
void router_logic()
{
int v0; // eax
bool v1; // zf
int v2; // edx

v0 = sys_getMilli();
v1 = LOBYTE(options[3]) == 0;
time = v0;
if ( v1 )
{
v2 = options[2];
if ( v2 > 0 && v0 >= nextShow )
{
nextShow = v2 + v0;
cmd_tabs();
v0 = time;
if ( nextHeartBeat > time )
{
LABEL_5:
if ( nextHeartCheck > v0 )
return;
LABEL_7:
nextHeartCheck = options[5] + v0;
router_dropcheck();
return;
}
}
else if ( nextHeartBeat > v0 )
{
goto LABEL_5;
}
nextHeartBeat = options[4] + v0;
send_dv();
v0 = time;
if ( nextHeartCheck <= time )
goto LABEL_7;
}
}

canonical_decompiled_code:
void func7()
{
int v0; // eax
bool v1; // zf
int v2; // edx

v0 = sys_getMilli();
v1 = LOBYTE(options[3]) == 0;
time = v0;
if ( v1 )
{
v2 = options[2];
if ( v2 > 0 && v0 >= nextShow )
{
nextShow = v2 + v0;
cmd_tabs();
v0 = time;
if ( nextHeartBeat > time )
{
LABEL_5:
if ( nextHeartCheck > v0 )
return;
LABEL_7:
nextHeartCheck = options[5] + v0;
func3();
return;
}
}
else if ( nextHeartBeat > v0 )
{
goto LABEL_5;
}
nextHeartBeat = options[4] + v0;
func1();
v0 = time;
if ( nextHeartCheck <= time )
goto LABEL_7;
}
}

original_code:
void router_logic(void) {
    time = sys_getMilli();
    if (options.stalled) {
        return;
    }
    if (options.showtime > 0 && time >= nextShow) {
        nextShow = time + options.showtime;
        cmd_tabs();
    }
    if (time >= nextHeartBeat) {
        nextHeartBeat = time + options.heartbeat;
        send_dv();
    }
    if (time >= nextHeartCheck) {
        nextHeartCheck = time + options.heartcheck;
        router_dropcheck();
    }
}

canonical_original_code:
void router_logic() {
    time = sys_getMilli();
    if (options.stalled) {
        return;
    }
    if (options.showtime > 0 && time >= nextShow) {
        nextShow = time + options.showtime;
        cmd_tabs();
    }
    if (time >= nextHeartBeat) {
        nextHeartBeat = time + options.heartbeat;
        send_dv();
    }
    if (time >= nextHeartCheck) {
        nextHeartCheck = time + options.heartcheck;
        router_dropcheck();
    }
}


decompiled_code:
// attributes: thunk
void router_heartbeat()
{
send_dv();
}

canonical_decompiled_code:
void func9()
{
func1();
}

original_code:
void router_heartbeat(void) {
    send_dv();
}

canonical_original_code:
void router_heartbeat() {
    send_dv();
}


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

tabs_cleanup();
tabs_init();
net_loadLinks();
time = sys_getMilli();
router_heartbeat();
result = reset_timeouts();
if ( LOBYTE(options[11]) )
result = my_print_rtab();
return result;
}

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

tabs_cleanup();
tabs_init();
net_loadLinks();
time = sys_getMilli();
func9();
result = func5();
if ( LOBYTE(options[11]) )
result = func0();
return result;
}

original_code:
void router_restart(void) {
    tabs_cleanup();
    tabs_init();
    net_loadLinks();
    time = sys_getMilli();
    router_heartbeat();
    reset_timeouts();
    if (options.debugrt) {
        my_print_rtab();
    }
}

canonical_original_code:
void router_restart() {
    tabs_cleanup();
    tabs_init();
    net_loadLinks();
    time = sys_getMilli();
    router_heartbeat();
    reset_timeouts();
    if (options.debugrt) {
        my_print_rtab();
    }
}


decompiled_code:
__int64 router_init()
{
router_restart();
con_runfile("autoexec.script");
return reset_timeouts();
}

canonical_decompiled_code:
__int64 func11()
{
func10();
con_runfile("autoexec.script");
return func5();
}

original_code:
void router_init(void) {
    router_restart();
    con_runfile("autoexec.script");
    reset_timeouts();
}

canonical_original_code:
void router_init() {
    router_restart();
    con_runfile("autoexec.script");
    reset_timeouts();
}


decompiled_code:
__int64 __fastcall tab_rows(__int64 a1)
{
if ( !a1 )
_assert_fail("tab != NULL", "src/tables.c", 0x11u, "tab_rows");
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( !a1 )
_assert_fail("tab != NULL", "src/tables.c", 0x11u, "tab_rows");
return *(unsigned int *)(a1 + 4);
}

original_code:
int tab_rows(table_t *tab) {
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 17, __extension__ __PRETTY_FUNCTION__));
    return tab->rows;
}

canonical_original_code:
int tab_rows(struct table_s *tab) {
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 17, __extension__ __PRETTY_FUNCTION__));
    return tab->rows;
}

variable_types: struct table_s { int itemsize; int rows; char *data; char *newitem; } *

return_type: int


decompiled_code:
__int64 __fastcall tab_cols(__int64 a1)
{
if ( !a1 )
_assert_fail("tab != NULL", "src/tables.c", 0x16u, "tab_cols");
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( !a1 )
_assert_fail("tab != NULL", "src/tables.c", 0x16u, "tab_cols");
return *(unsigned int *)(a1 + 8);
}

original_code:
int tab_cols(table_t *tab) {
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 22, __extension__ __PRETTY_FUNCTION__));
    return tab->cols;
}

canonical_original_code:
int tab_cols(struct table_s *tab) {
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 22, __extension__ __PRETTY_FUNCTION__));
    return tab->cols;
}

user_defined_types: struct table_s { int itemsize; int rows; char *data; char *newitem; }


decompiled_code:
void __fastcall tab_free(void *ptr)
{
if ( !ptr )
_assert_fail("tab != NULL", "src/tables.c", 0x27u, "tab_free");
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( !ptr )
_assert_fail("tab != NULL", "src/tables.c", 0x27u, "tab_free");
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
void tab_free(table_t *tab) {
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 39, __extension__ __PRETTY_FUNCTION__));
    free(tab->data);
    free(tab->newitem);
    free(tab);
}

canonical_original_code:
void tab_free(struct table_s *tab) {
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 39, __extension__ __PRETTY_FUNCTION__));
    free(tab->data);
    free(tab->newitem);
    free(tab);
}


original_code:
void tab_resize(table_t *tab, int i, int j) {
    int nrows, ncols;
    char *ndata;
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 49, __extension__ __PRETTY_FUNCTION__));
    nrows = (((i + 1)>=(tab->rows))?(i + 1):(tab->rows));
    ncols = (((j + 1)>=(tab->cols))?(j + 1):(tab->cols));
    ndata = malloc(nrows * ncols * tab->itemsize);
    for (i = 0; i < nrows; i++) {
        for (j = 0; j < ncols; j++) {
            char *src;
            if (i < tab->rows && j < tab->cols) {
                src = &tab->data[(i * tab->cols + j) * tab->itemsize];
            } else {
                src = tab->newitem;
            }
            memcpy(&ndata[(i * ncols + j) * tab->itemsize], src, tab->itemsize);
        }
    }
    free(tab->data);
    tab->data = ndata;
    tab->rows = nrows;
    tab->cols = ncols;
}

canonical_original_code:
void tab_resize(struct table_s *tab, int i, int j) {
    int nrows; int ncols;
    char *ndata;
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 49, __extension__ __PRETTY_FUNCTION__));
    nrows = (((i + 1)>=(tab->rows))?(i + 1):(tab->rows));
    ncols = (((j + 1)>=(tab->cols))?(j + 1):(tab->cols));
    ndata = malloc(nrows * ncols * tab->itemsize);
    for (i = 0; i < nrows; i++) {
        for (j = 0; j < ncols; j++) {
            char *src;
            if (i < tab->rows && j < tab->cols) {
                src = &tab->data[(i * tab->cols + j) * tab->itemsize];
            } else {
                src = tab->newitem;
            }
            memcpy(&ndata[(i * ncols + j) * tab->itemsize], src, tab->itemsize);
        }
    }
    free(tab->data);
    tab->data = ndata;
    tab->rows = nrows;
    tab->cols = ncols;
}

variable_types: j int

variable_types: nrows int

variable_types: ncols int

variable_types:
ndata
char *

variable_types:
src
char *


decompiled_code:
__int64 __fastcall tab_get(__int64 a1, int a2, int a3)
{
int v4; // esi
__int64 result; // rax

if ( !a1 )
_assert_fail("tab != NULL", "src/tables.c", 0x47u, "tab_get");
if ( a2 < 0 || a3 < 0 || *(_DWORD *)(a1 + 4) <= a2 || (v4 = *(_DWORD *)(a1 + 8), v4 <= a3) )
result = *(_QWORD *)(a1 + 24);
else
result = *(_QWORD *)(a1 + 16) + *(_DWORD *)a1 * (a2 * v4 + a3);
return result;
}

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

if ( !a1 )
_assert_fail("tab != NULL", "src/tables.c", 0x47u, "tab_get");
if ( a2 < 0 || a3 < 0 || *(_DWORD *)(a1 + 4) <= a2 || (v4 = *(_DWORD *)(a1 + 8), v4 <= a3) )
result = *(_QWORD *)(a1 + 24);
else
result = *(_QWORD *)(a1 + 16) + *(_DWORD *)a1 * (a2 * v4 + a3);
return result;
}

original_code:
const void *tab_get(table_t *tab, int i, int j) {
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 71, __extension__ __PRETTY_FUNCTION__));
    if (i < 0 || j < 0 || i >= tab->rows || j >= tab->cols) {
        return tab->newitem;
    }
    return &tab->data[(i * tab->cols + j) * tab->itemsize];
}

canonical_original_code:
void *tab_get(struct table_s *tab, int i, int j) {
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 71, __extension__ __PRETTY_FUNCTION__));
    if (i < 0 || j < 0 || i >= tab->rows || j >= tab->cols) {
        return tab->newitem;
    }
    return &tab->data[(i * tab->cols + j) * tab->itemsize];
}

return_type: void *


decompiled_code:
void *__fastcall tab_getCopy(int *a1, int a2, int a3, void *a4)
{
const void *v5; // rax

if ( !a1 )
_assert_fail("tab != NULL", "src/tables.c", 0x50u, "tab_getCopy");
v5 = (const void *)tab_get((__int64)a1, a2, a3);
return memcpy(a4, v5, *a1);
}

canonical_decompiled_code:
void *__fastcall func5(int *a1, int a2, int a3, void *a4)
{
const void *v5; // rax

if ( !a1 )
_assert_fail("tab != NULL", "src/tables.c", 0x50u, "tab_getCopy");
v5 = (const void *)func4((__int64)a1, a2, a3);
return memcpy(a4, v5, *a1);
}

original_code:
void tab_getCopy(table_t *tab, int i, int j, void *data) {
    const void *src;
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 80, __extension__ __PRETTY_FUNCTION__));
    src = tab_get(tab, i, j);
    memcpy(data, src, tab->itemsize);
}

canonical_original_code:
void tab_getCopy(struct table_s *tab, int i, int j, void *data) {
    void *src;
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 80, __extension__ __PRETTY_FUNCTION__));
    src = tab_get(tab, i, j);
    memcpy(data, src, tab->itemsize);
}

variable_types:
data
void *

variable_types:
src
void *


decompiled_code:
void *__fastcall tab_set(int *a1, int a2, int a3, const void *a4)
{
int v7; // edi
void *result; // rax

if ( !a1 )
_assert_fail("tab != NULL", "src/tables.c", 0x56u, "tab_set");
if ( a2 >= 0 && a3 >= 0 )
{
if ( a1[1] <= a2 || (v7 = a1[2], v7 <= a3) )
{
tab_resize(a1, a2, a3);
v7 = a1[2];
}
result = memcpy((void *)(*((_QWORD *)a1 + 2) + *a1 * (v7 * a2 + a3)), a4, *a1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(int *a1, int a2, int a3, const void *a4)
{
int v7; // edi
void *result; // rax

if ( !a1 )
_assert_fail("tab != NULL", "src/tables.c", 0x56u, "tab_set");
if ( a2 >= 0 && a3 >= 0 )
{
if ( a1[1] <= a2 || (v7 = a1[2], v7 <= a3) )
{
func3(a1, a2, a3);
v7 = a1[2];
}
result = memcpy((void *)(*((_QWORD *)a1 + 2) + *a1 * (v7 * a2 + a3)), a4, *a1);
}
return result;
}

original_code:
void tab_set(table_t *tab, int i, int j, const void *item) {
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 86, __extension__ __PRETTY_FUNCTION__));
    if (i < 0 || j < 0) {
        return;
    }
    if (i >= tab->rows || j >= tab->cols) {
        tab_resize(tab, i, j);
    }
    memcpy(&tab->data[(i * tab->cols + j) * tab->itemsize], item, tab->itemsize);
}

canonical_original_code:
void tab_set(struct table_s *tab, int i, int j, void *item) {
    ((tab != ((void *)0)) ? (void) (0) : __assert_fail ("tab != NULL", "src/tables.c", 86, __extension__ __PRETTY_FUNCTION__));
    if (i < 0 || j < 0) {
        return;
    }
    if (i >= tab->rows || j >= tab->cols) {
        tab_resize(tab, i, j);
    }
    memcpy(&tab->data[(i * tab->cols + j) * tab->itemsize], item, tab->itemsize);
}

variable_types:
item
void *


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

result = _isoc99_sscanf(a1, &unk_6F3, (unsigned int)((_DWORD)&options + 36));
if ( (_DWORD)result != 1 )
result = con_error("usage: ttl <ttl>\n");
return result;
}

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

result = _isoc99_sscanf(a1, &unk_6F3, (unsigned int)((_DWORD)&options + 36));
if ( (_DWORD)result != 1 )
result = con_error("usage: ttl <ttl>\n");
return result;
}

original_code:
static void cmd_ttl(const char *args) {
    if (sscanf(args, "%d", &options.ttl) != 1) {
        con_error("usage: ttl <ttl>\n");
        return;
    }
}

canonical_original_code:
static void cmd_ttl(char *args) {
    if (sscanf(args, "%d", &options.ttl) != 1) {
        con_error("usage: ttl <ttl>\n");
        return;
    }
}

variable_types:
args
char *


decompiled_code:
__int64 __fastcall cmd_debugrt(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, &unk_6F3, v2) != 1 )
return con_error("usage: debugrt <0/1>\n");
result = v2[0];
options[44] = v2[0] != 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, &unk_6F3, v2) != 1 )
return con_error("usage: debugrt <0/1>\n");
result = v2[0];
options[44] = v2[0] != 0;
return result;
}

original_code:
static void cmd_debugrt(const char *args) {
    int yesno;
    if (sscanf(args, "%d", &yesno) != 1) {
        con_error("usage: debugrt <0/1>\n");
        return;
    }
    options.debugrt = yesno;
}

canonical_original_code:
static void cmd_debugrt(char *args) {
    int yesno;
    if (sscanf(args, "%d", &yesno) != 1) {
        con_error("usage: debugrt <0/1>\n");
        return;
    }
    options.debugrt = yesno;
}

variable_types: yesno int


decompiled_code:
__int64 __fastcall cmd_debugpacket(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, &unk_6F3, v2) != 1 )
return con_error("usage: debugpacket <0/1>\n");
result = v2[0];
options[43] = v2[0] != 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, &unk_6F3, v2) != 1 )
return con_error("usage: debugpacket <0/1>\n");
result = v2[0];
options[43] = v2[0] != 0;
return result;
}

original_code:
static void cmd_debugpacket(const char *args) {
    int yesno;
    if (sscanf(args, "%d", &yesno) != 1) {
        con_error("usage: debugpacket <0/1>\n");
        return;
    }
    options.debugpacket = yesno;
}

canonical_original_code:
static void cmd_debugpacket(char *args) {
    int yesno;
    if (sscanf(args, "%d", &yesno) != 1) {
        con_error("usage: debugpacket <0/1>\n");
        return;
    }
    options.debugpacket = yesno;
}


decompiled_code:
__int64 __fastcall cmd_debuglost(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, &unk_6F3, v2) != 1 )
return con_error("usage: debuglost <0/1>\n");
result = v2[0];
options[42] = v2[0] != 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, &unk_6F3, v2) != 1 )
return con_error("usage: debuglost <0/1>\n");
result = v2[0];
options[42] = v2[0] != 0;
return result;
}

original_code:
static void cmd_debuglost(const char *args) {
    int yesno;
    if (sscanf(args, "%d", &yesno) != 1) {
        con_error("usage: debuglost <0/1>\n");
        return;
    }
    options.debuglost = yesno;
}

canonical_original_code:
static void cmd_debuglost(char *args) {
    int yesno;
    if (sscanf(args, "%d", &yesno) != 1) {
        con_error("usage: debuglost <0/1>\n");
        return;
    }
    options.debuglost = yesno;
}


decompiled_code:
__int64 __fastcall cmd_debugroute(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, &unk_6F3, v2) != 1 )
return con_error("usage: debugroute <0/1>\n");
result = v2[0];
options[41] = v2[0] != 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, &unk_6F3, v2) != 1 )
return con_error("usage: debugroute <0/1>\n");
result = v2[0];
options[41] = v2[0] != 0;
return result;
}

original_code:
static void cmd_debugroute(const char *args) {
    int yesno;
    if (sscanf(args, "%d", &yesno) != 1) {
        con_error("usage: debugroute <0/1>\n");
        return;
    }
    options.debugroute = yesno;
}

canonical_original_code:
static void cmd_debugroute(char *args) {
    int yesno;
    if (sscanf(args, "%d", &yesno) != 1) {
        con_error("usage: debugroute <0/1>\n");
        return;
    }
    options.debugroute = yesno;
}


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

result = _isoc99_sscanf(a1, &unk_6F3, (unsigned int)((_DWORD)options + 8));
if ( (_DWORD)result != 1 )
result = con_error("usage: showtime <milliseconds>\n");
return result;
}

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

result = _isoc99_sscanf(a1, &unk_6F3, (unsigned int)((_DWORD)options + 8));
if ( (_DWORD)result != 1 )
result = con_error("usage: showtime <milliseconds>\n");
return result;
}

original_code:
static void cmd_showtime(const char *args) {
    if (sscanf(args, "%d", &options.showtime) != 1) {
        con_error("usage: showtime <milliseconds>\n");
    }
}

canonical_original_code:
static void cmd_showtime(char *args) {
    if (sscanf(args, "%d", &options.showtime) != 1) {
        con_error("usage: showtime <milliseconds>\n");
    }
}


decompiled_code:
__int64 __fastcall cmd_drop(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, &unk_6F3, v2) == 1 )
result = drop_neighbour(v2[0]);
else
result = con_error("usage: drop <node>\n");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, &unk_6F3, v2) == 1 )
result = drop_neighbour(v2[0]);
else
result = con_error("usage: drop <node>\n");
return result;
}

original_code:
static void cmd_drop(const char *args) {
    int node;
    if (sscanf(args, "%d", &node) != 1) {
        con_error("usage: drop <node>\n");
        return;
    }
    drop_neighbour(node);
}

canonical_original_code:
static void cmd_drop(char *args) {
    int node;
    if (sscanf(args, "%d", &node) != 1) {
        con_error("usage: drop <node>\n");
        return;
    }
    drop_neighbour(node);
}

variable_types: node int


decompiled_code:
__int64 cmd_stall()
{
options[12] = 1;
return con_printf("algorithm stalled\n");
}

canonical_decompiled_code:
__int64 func8()
{
options[12] = 1;
return con_printf("algorithm stalled\n");
}

original_code:
static void cmd_stall(void) {
    options.stalled = 1;
    con_printf("algorithm stalled\n");
}

canonical_original_code:
static void cmd_stall() {
    options.stalled = 1;
    con_printf("algorithm stalled\n");
}


decompiled_code:
__int64 cmd_sleep()
{
options[13] = 1;
return con_printf("sleeping\n");
}

canonical_decompiled_code:
__int64 func9()
{
options[13] = 1;
return con_printf("sleeping\n");
}

original_code:
static void cmd_sleep(void) {
    options.sleeping = 1;
    con_printf("sleeping\n");
}

canonical_original_code:
static void cmd_sleep() {
    options.sleeping = 1;
    con_printf("sleeping\n");
}


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


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:
// attributes: thunk
__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
int result; // eax
bool v3; // cf
bool v4; // zf
_BYTE *v5; // rsi
__int64 v6; // rdi
const char *v7; // rbp
__int64 v8; // rcx
const char *v9; // rdi
const char *v10; // rsi
unsigned int v11; // edx
bool v12; // al
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
const char *v17; // rsi
bool v18; // cf
bool v19; // zf
const char *v20; // rdi
__int64 v21; // rcx
const char *v22; // rsi
__int64 v23; // [rsp+0h] [rbp-18h]

v1 = a1;
result = (char)*a1;
v3 = *a1 < 0x2Fu;
v4 = *a1 == 47;
if ( *a1 == 47 )
{
v7 = a1 + 1;
v8 = 5LL;
v9 = "tabs";
v10 = v7;
do
{
if ( !v8 )
break;
v3 = *v10 < (unsigned int)*v9;
v4 = *v10++ == *v9++;
--v8;
}
while ( v4 );
if ( (!v3 && !v4) == v3 || v1[1] == 116 && !v7[1] )
return cmd_tabs(v9, v10);
v11 = *(unsigned __int8 *)v7;
if ( v11 == 116 && v7[1] == 116 && v7[2] == 108 )
return cmd_ttl((__int64)(v1 + 4));
if ( !memcmp(v7, "debugrt ", 8uLL) )
return cmd_debugrt((__int64)(v1 + 9));
if ( !memcmp(v7, "debugpacket ", 0xCuLL) )
return cmd_debugpacket((__int64)(v1 + 13));
if ( !memcmp(v7, "debuglost ", 0xAuLL) )
return cmd_debuglost((__int64)(v1 + 11));
if ( !memcmp(v7, "debugroute ", 0xBuLL) )
return cmd_debugroute((__int64)(v1 + 12));
if ( !memcmp(v7, "drop ", 5uLL) )
return cmd_drop((__int64)(v1 + 6));
if ( !memcmp(v7, "showtime ", 9uLL) )
return cmd_showtime((__int64)(v1 + 10));
v12 = memcmp(v7, "all ", 4uLL) != 0;
v13 = 0;
v14 = !v12;
if ( !v12 )
return cmd_all((__int64)(v1 + 5));
v15 = "stall";
v16 = 6LL;
v17 = v7;
do
{
if ( !v16 )
break;
v13 = *v17 < (unsigned int)*v15;
v14 = *v17++ == *v15++;
--v16;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
return cmd_stall(v15, v17);
v18 = v11 < 0x68;
v19 = v11 == 104;
if ( v11 == 104 )
{
v18 = v7[1] < 0x62u;
v19 = v7[1] == 98;
if ( v7[1] == 98 )
{
v18 = 0;
v19 = v7[2] == 0;
if ( !v7[2] )
return cmd_heartbeat(v15, v17);
}
}
v20 = "hbtime ";
v21 = 7LL;
v22 = v7;
do
{
if ( !v21 )
break;
v18 = *v22 < (unsigned int)*v20;
v19 = *v22++ == *v20++;
--v21;
}
while ( v19 );
if ( (!v18 && !v19) == v18 )
{
result = atoi(v1 + 8);
*(_DWORD *)&options[16] = result;
}
else if ( v11 == 104 && v7[1] == 99 && !v7[2] )
{
result = cmd_heartcheck(v23, v22);
}
else if ( !strncmp(v7, "hctime ", 7uLL) )
{
result = atoi(v1 + 8);
*(_DWORD *)&options[20] = result;
}
else if ( !strncmp(v7, "infinity ", 9uLL) )
{
result = atoi(v1 + 10);
*(_DWORD *)&options[24] = result;
}
else if ( !strcmp(v7, "sleep") )
{
result = ((__int64 (__fastcall *)(const char *))cmd_sleep)(v7);
}
else
{
result = strncmp(v7, "dropadd ", 8uLL);
if ( result )
{
if ( !strcmp(v7, "wake") )
{
result = cmd_wake();
}
else if ( !strncmp(v7, "rtimeout ", 9uLL) )
{
result = atoi(v1 + 10);
*(_DWORD *)&options[28] = result;
}
else if ( !strncmp(v7, "rattempts ", 0xAuLL) )
{
result = atoi(v1 + 11);
*(_DWORD *)&options[32] = result;
}
else
{
result = con_errorf("unknown command: %s\n", v7);
}
}
else
{
options[14] = v1[9] != 48;
}
}
return result;
}
while ( (_BYTE)result == 32 )
result = (char)*++v1;
if ( (unsigned __int8)(result - 48) > 9u )
{
v6 = 0xFFFFFFFFLL;
LABEL_38:
v5 = v1;
goto LABEL_12;
}
v5 = v1;
LODWORD(v6) = 0;
do
{
++v5;
v6 = (unsigned int)(result + 10 * v6 - 48);
result = (char)*v5;
}
while ( (unsigned __int8)(*v5 - 48) <= 9u );
if ( v5 == v1 )
v6 = 0xFFFFFFFFLL;
if ( (_BYTE)result != 32 )
{
v1 = v5;
goto LABEL_38;
}
do
result = (unsigned __int8)*++v5;
while ( (_BYTE)result == 32 );
LABEL_12:
if ( (_BYTE)result )
result = rbl_sendmessage(v6, v5);
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:
// attributes: thunk
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)
{
int v2; // eax
__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;
v2 = sys_getMilli();
sendtarget = a1;
sendtime = v2;
result = options[8];
attempts = options[8];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, const char *a2)
{
int v2; // eax
__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;
v2 = sys_getMilli();
sendtarget = a1;
sendtime = v2;
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; // er8

if ( !nodes || numNodes <= 0 )
return 0xFFFFFFFFLL;
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 0xFFFFFFFFLL;
}
return v2;
}

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

if ( !nodes || numNodes <= 0 )
return 0xFFFFFFFFLL;
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 0xFFFFFFFFLL;
}
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

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; // er12
int v1; // eax
int v2; // ebp

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

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

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

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


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

result = (unsigned int)(a1 + 1);
if ( a1 + 1 < 0 || 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 || 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; // er8
__int64 result; // rax
int v2; // ecx
struct timespec v3; // [rsp+0h] [rbp-18h] BYREF

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

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

v0 = clock_gettime(0, &v3);
result = 0LL;
if ( !v0 )
{
if ( secbase_0 )
{
v2 = 1000 * (LODWORD(v3.tv_sec) - secbase_0);
}
else
{
secbase_0 = v3.tv_sec;
v2 = 0;
}
result = v2 + (unsigned int)(v3.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:
int __fastcall opt_readArgs(int a1, __int64 a2)
{
int result; // eax
int i; // ebx
const char *v5; // rdi
__int64 v6; // rdx

*((_QWORD *)&options + 2) = 0xFA0000007D0LL;
*((_QWORD *)&options + 3) = 0x3E800000064LL;
result = 3;
*(&options + 2) = 0LL;
options = 0LL;
*((_QWORD *)&options + 4) = 0xA00000003LL;
if ( a1 > 1 )
{
for ( i = 1; a1 > i; ++i )
{
while ( 1 )
{
v5 = *(const char **)(a2 + 8LL * i);
v6 = 8LL * i;
result = *(unsigned __int8 *)v5;
if ( (_BYTE)result != 45 )
{
if ( (unsigned __int8)(result - 48) > 9u )
{
result = con_errorf("invalid argument: %s\n", *(const char **)(a2 + 8LL * i));
}
else
{
result = atoi(v5);
DWORD1(options) = result;
}
goto LABEL_5;
}
if ( v5[1] == 101 )
break;
result = con_errorf("unknown option: %c\n", (unsigned int)v5[1]);
LABEL_5:
if ( a1 <= ++i )
return result;
}
if ( a1 <= ++i )
return result;
result = atoi(*(const char **)(a2 + v6 + 8));
if ( result < 0 )
{
LODWORD(options) = 0;
goto LABEL_5;
}
if ( result > 100 )
result = 100;
LODWORD(options) = result;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, __int64 a2)
{
int result; // eax
int i; // ebx
const char *v5; // rdi
__int64 v6; // rdx

*((_QWORD *)&options + 2) = 0xFA0000007D0LL;
*((_QWORD *)&options + 3) = 0x3E800000064LL;
result = 3;
*(&options + 2) = 0LL;
options = 0LL;
*((_QWORD *)&options + 4) = 0xA00000003LL;
if ( a1 > 1 )
{
for ( i = 1; a1 > i; ++i )
{
while ( 1 )
{
v5 = *(const char **)(a2 + 8LL * i);
v6 = 8LL * i;
result = *(unsigned __int8 *)v5;
if ( (_BYTE)result != 45 )
{
if ( (unsigned __int8)(result - 48) > 9u )
{
result = con_errorf("invalid argument: %s\n", *(const char **)(a2 + 8LL * i));
}
else
{
result = atoi(v5);
DWORD1(options) = result;
}
goto LABEL_5;
}
if ( v5[1] == 101 )
break;
result = con_errorf("unknown option: %c\n", (unsigned int)v5[1]);
LABEL_5:
if ( a1 <= ++i )
return result;
}
if ( a1 <= ++i )
return result;
result = atoi(*(const char **)(a2 + v6 + 8));
if ( result < 0 )
{
LODWORD(options) = 0;
goto LABEL_5;
}
if ( result > 100 )
result = 100;
LODWORD(options) = result;
}
}
return result;
}

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)
{
char *v3; // rax
char *v4; // rbx

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

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

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

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:
__int64 __fastcall libau_test_func(char *needle)
{
char *v1; // rax
const char *v2; // rbp
unsigned int v3; // er12
__int64 v4; // r12
char v5; // dl
char *v6; // rax

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

canonical_decompiled_code:
__int64 __fastcall func1(char *needle)
{
char *v1; // rax
const char *v2; // rbp
unsigned int v3; // er12
__int64 v4; // r12
char v5; // dl
char *v6; // rax

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

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

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(_BYTE *a1)
{
if ( a1[36] )
scanfile_remove_tmpfile(a1);
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(_BYTE *a1)
{
if ( a1[36] )
scanfile_remove_tmpfile(a1);
free(a1);
}

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)
{
unsigned int v1; // er15
char *v2; // rax
_QWORD *v3; // r12
__int64 v4; // rax
__int64 v5; // r13
__int64 v6; // rbp
_QWORD *v7; // rdi
_QWORD *v8; // r14
unsigned __int64 v9; // rdx
__int64 v10; // rax
__int64 v11; // rbp
int v12; // eax
__int64 v14; // rax
size_t v15; // rdx
unsigned __int64 v16; // rbx
__int64 v17; // rax
__int64 v18; // rax
size_t v19; // [rsp+8h] [rbp-40h]

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

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)
{
const char *v2; // r12
const char *v3; // rbp
char *v4; // rbx
__int64 result; // rax

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

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

v2 = (const char *)(a2 + 264);
v3 = (const char *)(a2 + 8);
v4 = *(char **)(a1 + 22328);
if ( v4 )
{
while ( strcasecmp(v4 + 8, v3) || strcasecmp(v4 + 264, v2) )
{
if ( !*(_QWORD *)v4 )
{
*(_QWORD *)v4 = a2;
return 1LL;
}
v4 = *(char **)v4;
}
logmsg_err("collection %s/%s: duplicate", v3, v2);
result = 0LL;
}
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; }