decompiled_code:
__int64 NP_Shutdown()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func22()
{
return 0LL;
}

original_code:
__attribute__((visibility("default"))) NPError
NP_Shutdown()
{
  return (0 + 0);
}

canonical_original_code:
short NP_Shutdown()
{
  return (0 + 0);
}


kmalloc

repo: cumirror/DFI

decompiled_code:
void *__fastcall kmalloc(int a1)
{
return malloc(a1);
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
return malloc(a1);
}

original_code:
void* kmalloc(int size, int module)
{
 return malloc(size);
}

canonical_original_code:
void *kmalloc(int size, int module)
{
 return malloc(size);
}

variable_types: size int

variable_types: module int

return_type: void *


kfree

decompiled_code:
void __fastcall kfree(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
free(a1);
}

original_code:
void kfree(void* p)
{
 free(p);
}

canonical_original_code:
void kfree(void *p)
{
 free(p);
}

variable_types:
p
void *

return_type: void


kzalloc

decompiled_code:
void *__fastcall kzalloc(int a1)
{
return calloc(1uLL, a1);
}

canonical_decompiled_code:
void *__fastcall func2(int a1)
{
return calloc(1uLL, a1);
}

original_code:
void* kzalloc(int size, int module)
{
 return calloc(1, size);
}

canonical_original_code:
void *kzalloc(int size, int module)
{
 return calloc(1, size);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
acsm_init(argc, argv, envp);
acsmDump(acmTCPTree);
acsmDump(acmUDPTree);
acsmAssistInit();
dfiSearch();
acsmAssistDestroy();
acsmFree();
return 0;
}

original_code:
int main(int argc, char** argv)
{
 acsm_init();
 acsmDump(acmTCPTree);
 acsmDump(acmUDPTree);
 acsmAssistInit();
 dfiSearch();
 acsmAssistDestroy();
 acsmFree();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 acsm_init();
 acsmDump(acmTCPTree);
 acsmDump(acmUDPTree);
 acsmAssistInit();
 dfiSearch();
 acsmAssistDestroy();
 acsmFree();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


refresh

original_code:
static void refresh(ushort* map, ushort len)
{
 int i;
 for(i = 0; i < len; i++){
  if(map[i] == 1)
   map[i] = 0;
  else if(map[i] == 0)
   map[i] = 1;
 }
}

canonical_original_code:
static void refresh(unsigned short *map, unsigned short len)
{
 int i;
 for(i = 0; i < len; i++){
  if(map[i] == 1)
   map[i] = 0;
  else if(map[i] == 0)
   map[i] = 1;
 }
}

variable_types:
map
unsigned short *

variable_types:
len
unsigned short

variable_types: i int


rangeInit

decompiled_code:
__int64 __fastcall rangeInit(unsigned __int16 a1)
{
shadow = kzalloc(2 * (unsigned int)a1, 10LL);
if ( !shadow )
return 1LL;
rangeSize = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 a1)
{
shadow = kzalloc(2 * (unsigned int)a1, 10LL);
if ( !shadow )
return 1LL;
rangeSize = a1;
return 0LL;
}

original_code:
int rangeInit(ushort rangeLen)
{
 shadow = (ushort*)kzalloc(rangeLen * sizeof(ushort), 10);
 if(!shadow){
  return 1;
 }
 rangeSize = rangeLen;
 return 0;
}

canonical_original_code:
int rangeInit(unsigned short rangeLen)
{
 shadow = (unsigned short *)kzalloc(rangeLen * sizeof(ushort), 10);
 if(!shadow){
  return 1;
 }
 rangeSize = rangeLen;
 return 0;
}

variable_types:
rangeLen
unsigned short


rangeDestroy

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

if ( shadow )
{
result = kfree();
rangeSize = 0;
shadow = 0LL;
}
return result;
}

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

if ( shadow )
{
result = kfree();
rangeSize = 0;
shadow = 0LL;
}
return result;
}

original_code:
void rangeDestroy()
{
 if(shadow){
  kfree(shadow);
  rangeSize = 0;
  shadow = ((void *)0);
 }
}


setRange

original_code:
void setRange(ushort* whole, ushort range[2])
{
 ushort left, right, i, color, state;
 left = range[0];
 right = range[1];
 color = whole[left-1];
 color = !color;
 state = 0;
 for(i = left; i <= right; i++){
  if(shadow[i] == 0)
   shadow[i] = 1;
 }
 for(i = left, state = 0; i <= right; i++){
  if(whole[i] == color && state == 0){
   break;
  }
  state = 1;
  if(whole[i] == color){
   color = !color;
  }
  whole[i] = color;
 }
 if(right < (rangeSize - 1) && whole[right+1] == whole[right])
  refresh(whole+right+1, rangeSize-right-1);
}

canonical_original_code:
void setRange(unsigned short *whole, unsigned short range[2])
{
 unsigned short left; unsigned short right; unsigned short i; unsigned short color; unsigned short state;
 left = range[0];
 right = range[1];
 color = whole[left-1];
 color = !color;
 state = 0;
 for(i = left; i <= right; i++){
  if(shadow[i] == 0)
   shadow[i] = 1;
 }
 for(i = left, state = 0; i <= right; i++){
  if(whole[i] == color && state == 0){
   break;
  }
  state = 1;
  if(whole[i] == color){
   color = !color;
  }
  whole[i] = color;
 }
 if(right < (rangeSize - 1) && whole[right+1] == whole[right])
  refresh(whole+right+1, rangeSize-right-1);
}

variable_types:
whole
unsigned short *

variable_types:
range
unsigned short [2]

variable_types:
left
unsigned short

variable_types:
right
unsigned short

variable_types:
i
unsigned short

variable_types:
color
unsigned short

variable_types:
state
unsigned short


buildArea

decompiled_code:
__int64 __fastcall buildArea(__int64 a1)
{
int v1; // esi
__int64 v2; // r9
__int64 result; // rax
int v4; // er10
int v5; // ecx
int v6; // er8
_WORD *v7; // rdx
__int64 v8; // rdx

v1 = (unsigned __int16)rangeSize;
if ( !rangeSize )
return 0LL;
v2 = shadow;
result = 0LL;
v4 = 2;
v5 = 0;
do
{
if ( v1 <= v5 )
{
v6 = v4;
}
else
{
v8 = v5;
v6 = v4;
do
{
v5 = v8;
if ( *(_WORD *)(v2 + 2 * v8) )
break;
v6 = *(unsigned __int16 *)(a1 + 2 * v8);
*(_WORD *)(a1 + 2 * v8) = 0;
v5 = ++v8;
}
while ( v1 > (int)v8 );
}
if ( v1 == v5 )
break;
v7 = (_WORD *)(a1 + 2LL * v5);
v4 = (unsigned __int16)*v7;
result = (v4 != v6) + (unsigned int)result;
*v7 = result;
++v5;
}
while ( v5 < v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // esi
__int64 v2; // r9
__int64 result; // rax
int v4; // er10
int v5; // ecx
int v6; // er8
_WORD *v7; // rdx
__int64 v8; // rdx

v1 = (unsigned __int16)rangeSize;
if ( !rangeSize )
return 0LL;
v2 = shadow;
result = 0LL;
v4 = 2;
v5 = 0;
do
{
if ( v1 <= v5 )
{
v6 = v4;
}
else
{
v8 = v5;
v6 = v4;
do
{
v5 = v8;
if ( *(_WORD *)(v2 + 2 * v8) )
break;
v6 = *(unsigned __int16 *)(a1 + 2 * v8);
*(_WORD *)(a1 + 2 * v8) = 0;
v5 = ++v8;
}
while ( v1 > (int)v8 );
}
if ( v1 == v5 )
break;
v7 = (_WORD *)(a1 + 2LL * v5);
v4 = (unsigned __int16)*v7;
result = (v4 != v6) + (unsigned int)result;
*v7 = result;
++v5;
}
while ( v5 < v1 );
return result;
}

original_code:
ushort buildArea(ushort* whole)
{
 int i, state;
 int count = 0;
 state = 2;
 for(i = 0; i < rangeSize; i++){
  while(i < rangeSize && shadow[i] == 0){
   state = whole[i];
   whole[i] = 0;
   i++;
  }
  if(i == rangeSize)break;
  if(state != whole[i]){
   count++;
   state = whole[i];
  }
  if(state == whole[i]){
   whole[i] = count;
  }
 }
 return count;
}

canonical_original_code:
unsigned short buildArea(unsigned short *whole)
{
 int i; int state;
 int count = 0;
 state = 2;
 for(i = 0; i < rangeSize; i++){
  while(i < rangeSize && shadow[i] == 0){
   state = whole[i];
   whole[i] = 0;
   i++;
  }
  if(i == rangeSize)break;
  if(state != whole[i]){
   count++;
   state = whole[i];
  }
  if(state == whole[i]){
   whole[i] = count;
  }
 }
 return count;
}

variable_types: state int

variable_types: count int

return_type: unsigned short


decompiled_code:
__int64 __fastcall range2Areas(__int64 a1, unsigned __int16 *a2, __int64 a3)
{
__int16 v6; // dx
unsigned __int16 v7; // ax
unsigned int v8; // ecx
__int16 v9; // si

v6 = rangeSize + 1;
v7 = *a2;
if ( *a2 > a2[1] )
return 0;
v8 = 0;
do
{
v9 = v6;
v6 = *(_WORD *)(a1 + 2LL * v7);
if ( v6 != v9 )
*(_WORD *)(a3 + 2LL * (unsigned __int16)v8++) = v6;
++v7;
}
while ( a2[1] >= v7 );
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int16 *a2, __int64 a3)
{
__int16 v6; // dx
unsigned __int16 v7; // ax
unsigned int v8; // ecx
__int16 v9; // si

v6 = rangeSize + 1;
v7 = *a2;
if ( *a2 > a2[1] )
return 0;
v8 = 0;
do
{
v9 = v6;
v6 = *(_WORD *)(a1 + 2LL * v7);
if ( v6 != v9 )
*(_WORD *)(a3 + 2LL * (unsigned __int16)v8++) = v6;
++v7;
}
while ( a2[1] >= v7 );
return v8;
}

original_code:
ushort range2Areas(ushort* whole, ushort range[2], ushort* areas)
{
 ushort indexNum = 0;
 ushort index = rangeSize+1;
 ushort i;
 for(i = range[0]; i <= range[1]; i++){
  if(index != whole[i]){
   areas[indexNum++] = index = whole[i];
  }
 }
 return indexNum;
}

canonical_original_code:
unsigned short range2Areas(unsigned short *whole, unsigned short range[2], unsigned short *areas)
{
 unsigned short indexNum = 0;
 unsigned short index = rangeSize+1;
 unsigned short i;
 for(i = range[0]; i <= range[1]; i++){
  if(index != whole[i]){
   areas[indexNum++] = index = whole[i];
  }
 }
 return indexNum;
}

variable_types:
areas
unsigned short *

variable_types:
indexNum
unsigned short

variable_types:
index
unsigned short


decompiled_code:
__int64 __fastcall internal_print_numbers(int a1)
{
unsigned int i; // ebx

con_printf(" |");
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
con_printf(" %3d", i);
}
return con_printf("|\n");
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int i; // ebx

con_printf(" |");
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
con_printf(" %3d", i);
}
return con_printf("|\n");
}

original_code:
static void internal_print_numbers(int size) {
    int i;
    con_printf("  |");
    for (i = 0; i < size; i++) {
        con_printf(" %3d", i);
    }
    con_printf("|\n");
}

variable_types: size int


decompiled_code:
__int64 __fastcall internal_print_hline(int a1)
{
int i; // ebx

con_printf(" +");
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
con_printf("----");
}
return con_printf("+\n");
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int i; // ebx

con_printf(" +");
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
con_printf("----");
}
return con_printf("+\n");
}

original_code:
static void internal_print_hline(int size) {
    int i;
    con_printf("  +");
    for (i = 0; i < size; i++) {
        con_printf("----");
    }
    con_printf("+\n");
}


decompiled_code:
__int64 tabs_init()
{
__int64 result; // rax
int v1; // [rsp+0h] [rbp-28h] BYREF
char v2; // [rsp+4h] [rbp-24h]
int v3; // [rsp+8h] [rbp-20h]
int v4; // [rsp+Ch] [rbp-1Ch]
int v5; // [rsp+10h] [rbp-18h]
int v6; // [rsp+14h] [rbp-14h]
int v7[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v7[0] = -1;
mtab = tab_create(v7, 4LL);
v1 = -1;
v2 = 0;
v3 = -1;
v4 = -1;
v5 = 0;
v6 = 0;
result = tab_create(&v1, 24LL);
mvec = result;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
int v1; // [rsp+0h] [rbp-28h] BYREF
char v2; // [rsp+4h] [rbp-24h]
int v3; // [rsp+8h] [rbp-20h]
int v4; // [rsp+Ch] [rbp-1Ch]
int v5; // [rsp+10h] [rbp-18h]
int v6; // [rsp+14h] [rbp-14h]
int v7[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v7[0] = -1;
mtab = tab_create(v7, 4LL);
v1 = -1;
v2 = 0;
v3 = -1;
v4 = -1;
v5 = 0;
v6 = 0;
result = tab_create(&v1, 24LL);
mvec = result;
return result;
}

original_code:
void tabs_init(void) {
    mtab_t deftab;
    mvec_t defvec;
    deftab.distance = -1;
    mtab = tab_create(&deftab, sizeof(mtab_t));
    defvec.cost = -1;
    defvec.online = 0;
    defvec.via = -1;
    defvec.distance = -1;
    defvec.inseqno = 0;
    defvec.outseqno = 0;
    mvec = tab_create(&defvec, sizeof(mvec_t));
}

canonical_original_code:
void tabs_init() {
    struct mtab_s deftab;
    struct mvec_s defvec;
    deftab.distance = -1;
    mtab = tab_create(&deftab, sizeof(mtab_t));
    defvec.cost = -1;
    defvec.online = 0;
    defvec.via = -1;
    defvec.distance = -1;
    defvec.inseqno = 0;
    defvec.outseqno = 0;
    mvec = tab_create(&defvec, sizeof(mvec_t));
}

variable_types:
deftab
struct mtab_s { int distance; }

variable_types: struct mvec_s { int cost; _Bool online; int via; int distance; int inseqno; }


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

tab_free(mvec);
mvec = 0LL;
result = tab_free(mtab);
mtab = 0LL;
return result;
}

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

tab_free(mvec);
mvec = 0LL;
result = tab_free(mtab);
mtab = 0LL;
return result;
}

original_code:
void tabs_cleanup(void) {
    tab_free(mvec);
    mvec = ((void *)0);
    tab_free(mtab);
    mtab = ((void *)0);
}

canonical_original_code:
void tabs_cleanup() {
    tab_free(mvec);
    mvec = ((void *)0);
    tab_free(mtab);
    mtab = ((void *)0);
}


decompiled_code:
__int64 __fastcall is_neighbour(int a1)
{
if ( a1 < 0 )
_assert_fail("node >= 0", "src/alltabs.c", 0x33u, "is_neighbour");
return *(unsigned __int8 *)(tab_get(mvec, 0LL, (unsigned int)a1) + 4);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
if ( a1 < 0 )
_assert_fail("node >= 0", "src/alltabs.c", 0x33u, "is_neighbour");
return *(unsigned __int8 *)(tab_get(mvec, 0LL, (unsigned int)a1) + 4);
}

original_code:
_Bool is_neighbour(int node) {
    mvec_t *vec;
    ((node >= 0) ? (void) (0) : __assert_fail ("node >= 0", "src/alltabs.c", 51, __extension__ __PRETTY_FUNCTION__));
    vec = (mvec_t *)tab_get(mvec, 0, node);
    return vec->online;
}

canonical_original_code:
_Bool is_neighbour(int node) {
    struct mvec_s *vec;
    ((node >= 0) ? (void) (0) : __assert_fail ("node >= 0", "src/alltabs.c", 51, __extension__ __PRETTY_FUNCTION__));
    vec = (struct mvec_s *)tab_get(mvec, 0, node);
    return vec->online;
}

variable_types: node int

variable_types: struct mvec_s { int cost; _Bool online; int via; int distance; int inseqno; } *


decompiled_code:
__int64 __fastcall internal_print_neighbours(int a1)
{
int i; // ebx

con_printf("N |");
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
if ( (unsigned __int8)is_neighbour(i) )
con_printf(" ngb", 1LL);
else
con_printf(" -");
}
}
return con_printf("|\n");
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int i; // ebx

con_printf("N |");
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
if ( (unsigned __int8)func4(i) )
con_printf(" ngb", 1LL);
else
con_printf(" -");
}
}
return con_printf("|\n");
}

original_code:
static void internal_print_neighbours(int size) {
    int i;
    con_printf("N |");
    for (i = 0; i < size; i++) {
        _Bool v = is_neighbour(i);
        if (v) {
            con_printf(" ngb", v);
        } else {
            con_printf("   -");
        }
    }
    con_printf("|\n");
}

variable_types: i int


decompiled_code:
__int64 __fastcall add_neighbour(unsigned int a1)
{
unsigned int v1; // ebp
int v3; // [rsp+0h] [rbp-38h] BYREF
char v4; // [rsp+4h] [rbp-34h]
unsigned int v5; // [rsp+8h] [rbp-30h]
int v6; // [rsp+Ch] [rbp-2Ch]

tab_getCopy(mvec, 0LL, a1, &v3);
v1 = 0;
if ( v3 >= 0 && !v4 )
{
v4 = 1;
v5 = a1;
v6 = v3;
tab_set(mvec, 0LL, a1, &v3);
v1 = options[14];
if ( (_BYTE)v1 )
con_printf("[DEBUG] adding node %d\n", a1);
else
v1 = 1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
unsigned int v1; // ebp
int v3; // [rsp+0h] [rbp-38h] BYREF
char v4; // [rsp+4h] [rbp-34h]
unsigned int v5; // [rsp+8h] [rbp-30h]
int v6; // [rsp+Ch] [rbp-2Ch]

tab_getCopy(mvec, 0LL, a1, &v3);
v1 = 0;
if ( v3 >= 0 && !v4 )
{
v4 = 1;
v5 = a1;
v6 = v3;
tab_set(mvec, 0LL, a1, &v3);
v1 = options[14];
if ( (_BYTE)v1 )
con_printf("[DEBUG] adding node %d\n", a1);
else
v1 = 1;
}
return v1;
}

original_code:
_Bool add_neighbour(int node) {
    mvec_t vec;
    tab_getCopy(mvec, 0, node, &vec);
    if (!((vec.cost) >= 0)) {
        return 0;
    }
    if (vec.online) {
        return 0;
    }
    vec.online = 1;
    vec.via = node;
    vec.distance = vec.cost;
    tab_set(mvec, 0, node, &vec);
    if (options.show_dropadd) {
        con_printf("[DEBUG] adding node %d\n", node);
    }
    return 1;
}

canonical_original_code:
_Bool add_neighbour(int node) {
    struct mvec_s vec;
    tab_getCopy(mvec, 0, node, &vec);
    if (!((vec.cost) >= 0)) {
        return 0;
    }
    if (vec.online) {
        return 0;
    }
    vec.online = 1;
    vec.via = node;
    vec.distance = vec.cost;
    tab_set(mvec, 0, node, &vec);
    if (options.show_dropadd) {
        con_printf("[DEBUG] adding node %d\n", node);
    }
    return 1;
}

user_defined_types: struct mvec_s { int cost; _Bool online; int via; int distance; int inseqno; }


decompiled_code:
__int64 __fastcall next_neighbour(int a1)
{
int v1; // ebp
unsigned int v2; // ebx

if ( a1 < -1 )
_assert_fail("node >= -1", "src/alltabs.c", 0x69u, "next_neighbour");
v1 = tab_cols(mvec);
v2 = a1 + 1;
if ( v1 <= a1 + 1 )
return (unsigned int)-1;
while ( !(unsigned __int8)is_neighbour(v2) )
{
if ( v1 == ++v2 )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
int v1; // ebp
unsigned int v2; // ebx

if ( a1 < -1 )
_assert_fail("node >= -1", "src/alltabs.c", 0x69u, "next_neighbour");
v1 = tab_cols(mvec);
v2 = a1 + 1;
if ( v1 <= a1 + 1 )
return (unsigned int)-1;
while ( !(unsigned __int8)func4(v2) )
{
if ( v1 == ++v2 )
return (unsigned int)-1;
}
return v2;
}

original_code:
int next_neighbour(int node) {
    int count;
    ((node >= -1) ? (void) (0) : __assert_fail ("node >= -1", "src/alltabs.c", 105, __extension__ __PRETTY_FUNCTION__));
    count = tab_cols(mvec);
    for (int i = node + 1; i < count; i++) {
        if (is_neighbour(i)) {
            return i;
        }
    }
    return -1;
}


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

tab_getCopy(mvec, 0LL, a1, v3);
v3[0] = a2;
return tab_set(mvec, 0LL, a1, v3);
}

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

tab_getCopy(mvec, 0LL, a1, v3);
v3[0] = a2;
return tab_set(mvec, 0LL, a1, v3);
}

original_code:
void set_neighbour_cost(int node, int cost) {
    mvec_t vec;
    tab_getCopy(mvec, 0, node, &vec);
    vec.cost = cost;
    tab_set(mvec, 0, node, &vec);
}

canonical_original_code:
void set_neighbour_cost(int node, int cost) {
    struct mvec_s vec;
    tab_getCopy(mvec, 0, node, &vec);
    vec.cost = cost;
    tab_set(mvec, 0, node, &vec);
}

variable_types: cost int


decompiled_code:
__int64 __fastcall get_neighbour_cost(unsigned int a1)
{
return *(unsigned int *)tab_get(mvec, 0LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
return *(unsigned int *)tab_get(mvec, 0LL, a1);
}

original_code:
int get_neighbour_cost(int node) {
    const mvec_t *vec;
    vec = tab_get(mvec, 0, node);
    return vec->cost;
}

canonical_original_code:
int get_neighbour_cost(int node) {
    struct mvec_s *vec;
    vec = tab_get(mvec, 0, node);
    return vec->cost;
}


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

tab_getCopy(mvec, 0LL, a1, v3);
v3[4] = a2;
return tab_set(mvec, 0LL, a1, v3);
}

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

tab_getCopy(mvec, 0LL, a1, v3);
v3[4] = a2;
return tab_set(mvec, 0LL, a1, v3);
}

original_code:
void set_node_inseqno(int node, int seqno) {
    mvec_t vec;
    tab_getCopy(mvec, 0, node, &vec);
    vec.inseqno = seqno;
    tab_set(mvec, 0, node, &vec);
}

canonical_original_code:
void set_node_inseqno(int node, int seqno) {
    struct mvec_s vec;
    tab_getCopy(mvec, 0, node, &vec);
    vec.inseqno = seqno;
    tab_set(mvec, 0, node, &vec);
}

variable_types: seqno int


decompiled_code:
__int64 __fastcall get_node_inseqno(unsigned int a1)
{
return *(unsigned int *)(tab_get(mvec, 0LL, a1) + 16);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
return *(unsigned int *)(tab_get(mvec, 0LL, a1) + 16);
}

original_code:
int get_node_inseqno(int node) {
    const mvec_t *vec;
    vec = tab_get(mvec, 0, node);
    return vec->inseqno;
}

canonical_original_code:
int get_node_inseqno(int node) {
    struct mvec_s *vec;
    vec = tab_get(mvec, 0, node);
    return vec->inseqno;
}


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

tab_getCopy(mvec, 0LL, a1, v3);
v3[5] = a2;
return tab_set(mvec, 0LL, a1, v3);
}

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

tab_getCopy(mvec, 0LL, a1, v3);
v3[5] = a2;
return tab_set(mvec, 0LL, a1, v3);
}

original_code:
void set_node_outseqno(int node, int seqno) {
    mvec_t vec;
    tab_getCopy(mvec, 0, node, &vec);
    vec.outseqno = seqno;
    tab_set(mvec, 0, node, &vec);
}

canonical_original_code:
void set_node_outseqno(int node, int seqno) {
    struct mvec_s vec;
    tab_getCopy(mvec, 0, node, &vec);
    vec.outseqno = seqno;
    tab_set(mvec, 0, node, &vec);
}


decompiled_code:
__int64 __fastcall get_node_outseqno(unsigned int a1)
{
return *(unsigned int *)(tab_get(mvec, 0LL, a1) + 20);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1)
{
return *(unsigned int *)(tab_get(mvec, 0LL, a1) + 20);
}

original_code:
int get_node_outseqno(int node) {
    const mvec_t *vec;
    vec = tab_get(mvec, 0, node);
    return vec->outseqno;
}

canonical_original_code:
int get_node_outseqno(int node) {
    struct mvec_s *vec;
    vec = tab_get(mvec, 0, node);
    return vec->outseqno;
}


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

tab_getCopy(mvec, 0LL, a1, v3);
v3[3] = a2;
return tab_set(mvec, 0LL, a1, v3);
}

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

tab_getCopy(mvec, 0LL, a1, v3);
v3[3] = a2;
return tab_set(mvec, 0LL, a1, v3);
}

original_code:
void set_rt_distance(int node, int dist) {
    mvec_t vec;
    tab_getCopy(mvec, 0, node, &vec);
    vec.distance = dist;
    tab_set(mvec, 0, node, &vec);
}

canonical_original_code:
void set_rt_distance(int node, int dist) {
    struct mvec_s vec;
    tab_getCopy(mvec, 0, node, &vec);
    vec.distance = dist;
    tab_set(mvec, 0, node, &vec);
}

variable_types: dist int


decompiled_code:
__int64 __fastcall get_rt_distance(unsigned int a1)
{
return *(unsigned int *)(tab_get(mvec, 0LL, a1) + 12);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1)
{
return *(unsigned int *)(tab_get(mvec, 0LL, a1) + 12);
}

original_code:
int get_rt_distance(int node) {
    const mvec_t *vec;
    vec = tab_get(mvec, 0, node);
    return vec->distance;
}

canonical_original_code:
int get_rt_distance(int node) {
    struct mvec_s *vec;
    vec = tab_get(mvec, 0, node);
    return vec->distance;
}


decompiled_code:
__int64 __fastcall internal_print_distances(int a1)
{
unsigned int i; // ebx
int v2; // eax

con_printf("D |");
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v2 = get_rt_distance(i);
if ( v2 >= 0 )
con_printf(" %3d", (unsigned int)v2);
else
con_printf(" -");
}
}
return con_printf("|\n");
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
unsigned int i; // ebx
int v2; // eax

con_printf("D |");
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v2 = func15(i);
if ( v2 >= 0 )
con_printf(" %3d", (unsigned int)v2);
else
con_printf(" -");
}
}
return con_printf("|\n");
}

original_code:
static void internal_print_distances(int size) {
    int i;
    con_printf("D |");
    for (i = 0; i < size; i++) {
        int v = get_rt_distance(i);
        if (v >= 0) {
            con_printf(" %3d", v);
        } else {
            con_printf("   -");
        }
    }
    con_printf("|\n");
}

variable_types: v int


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

tab_getCopy(mvec, 0LL, a1, v3);
v3[2] = a2;
return tab_set(mvec, 0LL, a1, v3);
}

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

tab_getCopy(mvec, 0LL, a1, v3);
v3[2] = a2;
return tab_set(mvec, 0LL, a1, v3);
}

original_code:
void set_rt_via(int node, int via) {
    mvec_t vec;
    tab_getCopy(mvec, 0, node, &vec);
    vec.via = via;
    tab_set(mvec, 0, node, &vec);
}

canonical_original_code:
void set_rt_via(int node, int via) {
    struct mvec_s vec;
    tab_getCopy(mvec, 0, node, &vec);
    vec.via = via;
    tab_set(mvec, 0, node, &vec);
}

variable_types: via int


decompiled_code:
__int64 __fastcall get_rt_via(unsigned int a1)
{
return *(unsigned int *)(tab_get(mvec, 0LL, a1) + 8);
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned int a1)
{
return *(unsigned int *)(tab_get(mvec, 0LL, a1) + 8);
}

original_code:
int get_rt_via(int node) {
    const mvec_t *vec;
    vec = tab_get(mvec, 0, node);
    return vec->via;
}

canonical_original_code:
int get_rt_via(int node) {
    struct mvec_s *vec;
    vec = tab_get(mvec, 0, node);
    return vec->via;
}


decompiled_code:
__int64 __fastcall internal_print_via(int a1)
{
unsigned int i; // ebx
int v2; // eax

con_printf("V |");
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v2 = get_rt_via(i);
if ( v2 >= 0 )
con_printf(" %3d", (unsigned int)v2);
else
con_printf(" -");
}
}
return con_printf("|\n");
}

canonical_decompiled_code:
__int64 __fastcall func19(int a1)
{
unsigned int i; // ebx
int v2; // eax

con_printf("V |");
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v2 = func18(i);
if ( v2 >= 0 )
con_printf(" %3d", (unsigned int)v2);
else
con_printf(" -");
}
}
return con_printf("|\n");
}

original_code:
static void internal_print_via(int size) {
    int i;
    con_printf("V |");
    for (i = 0; i < size; i++) {
        int v = get_rt_via(i);
        if (v >= 0) {
            con_printf(" %3d", v);
        } else {
            con_printf("   -");
        }
    }
    con_printf("|\n");
}


decompiled_code:
__int64 __fastcall internal_print_rtab(int a1)
{
internal_print_hline(a1);
internal_print_numbers(a1);
internal_print_hline(a1);
internal_print_distances(a1);
return internal_print_via(a1);
}

canonical_decompiled_code:
__int64 __fastcall func20(int a1)
{
func1(a1);
func0(a1);
func1(a1);
func16(a1);
return func19(a1);
}

original_code:
static void internal_print_rtab(int size) {
    internal_print_hline(size);
    internal_print_numbers(size);
    internal_print_hline(size);
    internal_print_distances(size);
    internal_print_via(size);
}


decompiled_code:
__int64 __fastcall set_dv_distance(unsigned int a1, unsigned int a2, int a3)
{
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

tab_getCopy(mtab, a1, a2, v5);
v5[0] = a3;
return tab_set(mtab, a1, a2, v5);
}

canonical_decompiled_code:
__int64 __fastcall func21(unsigned int a1, unsigned int a2, int a3)
{
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

tab_getCopy(mtab, a1, a2, v5);
v5[0] = a3;
return tab_set(mtab, a1, a2, v5);
}

original_code:
void set_dv_distance(int via, int to, int dist) {
    mtab_t tab;
    tab_getCopy(mtab, via, to, &tab);
    tab.distance = dist;
    tab_set(mtab, via, to, &tab);
}

canonical_original_code:
void set_dv_distance(int via, int to, int dist) {
    struct mtab_s tab;
    tab_getCopy(mtab, via, to, &tab);
    tab.distance = dist;
    tab_set(mtab, via, to, &tab);
}

variable_types: to int

variable_types:
tab
struct mtab_s { int distance; }


decompiled_code:
__int64 __fastcall get_dv_distance(unsigned int a1, unsigned int a2)
{
return *(unsigned int *)tab_get(mtab, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func22(unsigned int a1, unsigned int a2)
{
return *(unsigned int *)tab_get(mtab, a1, a2);
}

original_code:
int get_dv_distance(int via, int to) {
    const mtab_t *tab;
    tab = tab_get(mtab, via, to);
    return tab->distance;
}

canonical_original_code:
int get_dv_distance(int via, int to) {
    struct mtab_s *tab;
    tab = tab_get(mtab, via, to);
    return tab->distance;
}

variable_types:
tab
struct mtab_s { int distance; } *


decompiled_code:
void __fastcall internal_print_dvtab(int a1)
{
unsigned int i; // ebp
unsigned int j; // ebx
int v3; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
if ( (unsigned __int8)is_neighbour(i) )
{
con_printf("%d |", i);
for ( j = 0; j != a1; ++j )
{
v3 = get_dv_distance(i, j);
if ( v3 < 0 )
con_printf(" -");
else
con_printf(" %3d", (unsigned int)v3);
}
con_printf("|\n");
}
}
}
}

canonical_decompiled_code:
void __fastcall func23(int a1)
{
unsigned int i; // ebp
unsigned int j; // ebx
int v3; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
if ( (unsigned __int8)func4(i) )
{
con_printf("%d |", i);
for ( j = 0; j != a1; ++j )
{
v3 = func22(i, j);
if ( v3 < 0 )
con_printf(" -");
else
con_printf(" %3d", (unsigned int)v3);
}
con_printf("|\n");
}
}
}
}

original_code:
static void internal_print_dvtab(int size) {
    int i;
    for (int n = 0; n < size; n++) {
        if (!is_neighbour(n)) {
            continue;
        }
        con_printf("%d |", n);
        for (i = 0; i < size; i++) {
            int v = get_dv_distance(n, i);
            if (v >= 0) {
                con_printf(" %3d", v);
            } else {
                con_printf("   -");
            }
        }
        con_printf("|\n");
    }
}

variable_types: n int


decompiled_code:
__int64 num_destinations()
{
int v0; // ebx
__int64 result; // rax

v0 = tab_cols(mvec);
if ( v0 < (int)tab_cols(mtab) )
result = tab_cols(mtab);
else
result = tab_cols(mvec);
return result;
}

canonical_decompiled_code:
__int64 func24()
{
int v0; // ebx
__int64 result; // rax

v0 = tab_cols(mvec);
if ( v0 < (int)tab_cols(mtab) )
result = tab_cols(mtab);
else
result = tab_cols(mvec);
return result;
}

original_code:
int num_destinations(void) {
    return (((tab_cols(mvec))>=(tab_cols(mtab)))?(tab_cols(mvec)):(tab_cols(mtab)));
}

canonical_original_code:
int num_destinations() {
    return (((tab_cols(mvec))>=(tab_cols(mtab)))?(tab_cols(mvec)):(tab_cols(mtab)));
}


decompiled_code:
__int64 __fastcall drop_neighbour(unsigned int a1)
{
__int64 result; // rax
int v2; // er12
unsigned int i; // ebx
_BYTE v4[8]; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+8h] [rbp-30h]
int v6; // [rsp+Ch] [rbp-2Ch]

tab_getCopy(mvec, 0LL, a1, v4);
v4[4] = 0;
v5 = -1;
v6 = -1;
tab_set(mvec, 0LL, a1, v4);
result = num_destinations();
if ( (int)result > 0 )
{
v2 = result;
for ( i = 0; i != v2; ++i )
{
result = get_rt_via(i);
if ( (_DWORD)result == a1 )
{
set_rt_via(i, -1);
result = set_rt_distance(i, -1);
}
}
}
if ( options[14] )
result = con_printf("[DEBUG] dropping node %d\n", a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func25(unsigned int a1)
{
__int64 result; // rax
int v2; // er12
unsigned int i; // ebx
_BYTE v4[8]; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+8h] [rbp-30h]
int v6; // [rsp+Ch] [rbp-2Ch]

tab_getCopy(mvec, 0LL, a1, v4);
v4[4] = 0;
v5 = -1;
v6 = -1;
tab_set(mvec, 0LL, a1, v4);
result = func24();
if ( (int)result > 0 )
{
v2 = result;
for ( i = 0; i != v2; ++i )
{
result = func18(i);
if ( (_DWORD)result == a1 )
{
func17(i, -1);
result = func14(i, -1);
}
}
}
if ( options[14] )
result = con_printf("[DEBUG] dropping node %d\n", a1);
return result;
}

original_code:
void drop_neighbour(int node) {
    int count;
    mvec_t vec;
    tab_getCopy(mvec, 0, node, &vec);
    vec.online = 0;
    vec.via = -1;
    vec.distance = -1;
    tab_set(mvec, 0, node, &vec);
    count = num_destinations();
    for (int i = 0; i < count; i++) {
        if (get_rt_via(i) == node) {
            set_rt_via(i, -1);
            set_rt_distance(i, -1);
        }
    }
    if (options.show_dropadd) {
        con_printf("[DEBUG] dropping node %d\n", node);
    }
}

canonical_original_code:
void drop_neighbour(int node) {
    int count;
    struct mvec_s vec;
    tab_getCopy(mvec, 0, node, &vec);
    vec.online = 0;
    vec.via = -1;
    vec.distance = -1;
    tab_set(mvec, 0, node, &vec);
    count = num_destinations();
    for (int i = 0; i < count; i++) {
        if (get_rt_via(i) == node) {
            set_rt_via(i, -1);
            set_rt_distance(i, -1);
        }
    }
    if (options.show_dropadd) {
        con_printf("[DEBUG] dropping node %d\n", node);
    }
}

variable_types: count int


decompiled_code:
__int64 print_rtab()
{
int v0; // ebx

v0 = num_destinations();
internal_print_rtab(v0);
return internal_print_hline(v0);
}

canonical_decompiled_code:
__int64 func26()
{
int v0; // ebx

v0 = func24();
func20(v0);
return func1(v0);
}

original_code:
void print_rtab(void) {
    int size = num_destinations();
    internal_print_rtab(size);
    internal_print_hline(size);
}

canonical_original_code:
void print_rtab() {
    int size = num_destinations();
    internal_print_rtab(size);
    internal_print_hline(size);
}


decompiled_code:
__int64 print_tabs()
{
int v0; // ebx

v0 = num_destinations();
internal_print_rtab(v0);
internal_print_neighbours(v0);
internal_print_hline(v0);
internal_print_dvtab(v0);
return internal_print_hline(v0);
}

canonical_decompiled_code:
__int64 func27()
{
int v0; // ebx

v0 = func24();
func20(v0);
func5(v0);
func1(v0);
func23(v0);
return func1(v0);
}

original_code:
void print_tabs(void) {
    int size = num_destinations();
    internal_print_rtab(size);
    internal_print_neighbours(size);
    internal_print_hline(size);
    internal_print_dvtab(size);
    internal_print_hline(size);
}

canonical_original_code:
void print_tabs() {
    int size = num_destinations();
    internal_print_rtab(size);
    internal_print_neighbours(size);
    internal_print_hline(size);
    internal_print_dvtab(size);
    internal_print_hline(size);
}


decompiled_code:
_DWORD *szb_create()
{
_DWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
*result = 0;
result[1] = 0;
result[2] = 0;
*((_QWORD *)result + 2) = 0LL;
}
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
*result = 0;
result[1] = 0;
result[2] = 0;
*((_QWORD *)result + 2) = 0LL;
}
return result;
}

original_code:
szb_t *szb_create() {
    szb_t *buf = malloc(sizeof(*buf));
    if (buf == ((void *)0)) {
        return buf;
    }
    buf->pos = 0;
    buf->size = 0;
    buf->capacity = 0;
    buf->data = ((void *)0);
    return buf;
}

canonical_original_code:
struct szb_s *szb_create() {
    struct szb_s *buf = malloc(sizeof(*buf));
    if (buf == ((void *)0)) {
        return buf;
    }
    buf->pos = 0;
    buf->size = 0;
    buf->capacity = 0;
    buf->data = ((void *)0);
    return buf;
}

variable_types: struct szb_s { int pos; int size; int capacity; char *data; } *


decompiled_code:
void __fastcall szb_free(void *ptr)
{
if ( !ptr )
_assert_fail("buf != NULL", "src/szb.c", 0x2Cu, "szb_free");
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( !ptr )
_assert_fail("buf != NULL", "src/szb.c", 0x2Cu, "szb_free");
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void szb_free(szb_t *buf) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 44, __extension__ __PRETTY_FUNCTION__));
    free(buf->data);
    free(buf);;
}

canonical_original_code:
void szb_free(struct szb_s *buf) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 44, __extension__ __PRETTY_FUNCTION__));
    free(buf->data);
    free(buf);;
}

user_defined_types: struct szb_s { int pos; int size; int capacity; char *data; }


decompiled_code:
__int64 __fastcall szb_read8(int *a1)
{
int v1; // eax
unsigned int v2; // edx

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x53u, "szb_read8");
v1 = *a1;
if ( *a1 >= a1[1] )
return (unsigned int)-1;
v2 = *(char *)(*((_QWORD *)a1 + 2) + v1);
*a1 = v1 + 1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1)
{
int v1; // eax
unsigned int v2; // edx

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x53u, "szb_read8");
v1 = *a1;
if ( *a1 >= a1[1] )
return (unsigned int)-1;
v2 = *(char *)(*((_QWORD *)a1 + 2) + v1);
*a1 = v1 + 1;
return v2;
}

original_code:
int szb_read8(szb_t *buf) {
    int r;
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 83, __extension__ __PRETTY_FUNCTION__));
    if (buf->pos + 1 > buf->size) { return -1; };
    r = buf->data[buf->pos];
    buf->pos += 1;
    return r;
}

canonical_original_code:
int szb_read8(struct szb_s *buf) {
    int r;
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 83, __extension__ __PRETTY_FUNCTION__));
    if (buf->pos + 1 > buf->size) { return -1; };
    r = buf->data[buf->pos];
    buf->pos += 1;
    return r;
}

variable_types: r int


decompiled_code:
__int64 __fastcall szb_read16(int *a1)
{
int v1; // ebp

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x5Du, "szb_read16");
v1 = (unsigned __int8)szb_read8(a1);
return v1 | (unsigned int)(unsigned __int16)((unsigned __int16)szb_read8(a1) << 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1)
{
int v1; // ebp

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x5Du, "szb_read16");
v1 = (unsigned __int8)func2(a1);
return v1 | (unsigned int)(unsigned __int16)((unsigned __int16)func2(a1) << 8);
}

original_code:
int szb_read16(szb_t *buf) {
    int r;
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 93, __extension__ __PRETTY_FUNCTION__));
    r = szb_read8(buf) & 0xFF;
    r |= (szb_read8(buf) << 8) & 0xFF00;
    return r;
}

canonical_original_code:
int szb_read16(struct szb_s *buf) {
    int r;
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 93, __extension__ __PRETTY_FUNCTION__));
    r = szb_read8(buf) & 0xFF;
    r |= (szb_read8(buf) << 8) & 0xFF00;
    return r;
}


decompiled_code:
__int64 __fastcall szb_read32(int *a1)
{
int v1; // ebx
__int16 v2; // bp
unsigned int v3; // ebx

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x66u, "szb_read32");
v1 = (unsigned __int8)szb_read8(a1);
v2 = szb_read8(a1);
v3 = ((unsigned int)szb_read8(a1) << 16) & 0xFF0000 | (unsigned __int16)(v2 << 8) | v1;
return v3 | ((unsigned int)szb_read8(a1) << 24);
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1)
{
int v1; // ebx
__int16 v2; // bp
unsigned int v3; // ebx

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x66u, "szb_read32");
v1 = (unsigned __int8)func2(a1);
v2 = func2(a1);
v3 = ((unsigned int)func2(a1) << 16) & 0xFF0000 | (unsigned __int16)(v2 << 8) | v1;
return v3 | ((unsigned int)func2(a1) << 24);
}

original_code:
int szb_read32(szb_t *buf) {
    int r;
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 102, __extension__ __PRETTY_FUNCTION__));
    r = szb_read8(buf) & 0xFF;
    r |= (szb_read8(buf) << 8) & 0xFF00;
    r |= (szb_read8(buf) << 16) & 0xFF0000;
    r |= (szb_read8(buf) << 24) & 0xFF000000;
    return r;
}

canonical_original_code:
int szb_read32(struct szb_s *buf) {
    int r;
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 102, __extension__ __PRETTY_FUNCTION__));
    r = szb_read8(buf) & 0xFF;
    r |= (szb_read8(buf) << 8) & 0xFF00;
    r |= (szb_read8(buf) << 16) & 0xFF0000;
    r |= (szb_read8(buf) << 24) & 0xFF000000;
    return r;
}


decompiled_code:
int __fastcall szb_print(__int64 a1)
{
__int64 i; // rbx

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x71u, "szb_print");
for ( i = 0LL; *(_DWORD *)(a1 + 4) > (int)i; ++i )
printf(" %02X", (unsigned int)*(char *)(*(_QWORD *)(a1 + 16) + i));
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
__int64 i; // rbx

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x71u, "szb_print");
for ( i = 0LL; *(_DWORD *)(a1 + 4) > (int)i; ++i )
printf(" %02X", (unsigned int)*(char *)(*(_QWORD *)(a1 + 16) + i));
return putchar(10);
}

original_code:
void szb_print(szb_t *buf) {
    int i;
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 113, __extension__ __PRETTY_FUNCTION__));
    for (i = 0; i < buf->size; i++) {
        printf(" %02X", buf->data[i]);
    }
    printf("\n");
}

canonical_original_code:
void szb_print(struct szb_s *buf) {
    int i;
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 113, __extension__ __PRETTY_FUNCTION__));
    for (i = 0; i < buf->size; i++) {
        printf(" %02X", buf->data[i]);
    }
    printf("\n");
}


decompiled_code:
void __fastcall szb_setCapacity(__int64 a1, int a2)
{
int v2; // ebx
void *v3; // r12

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x7Eu, "szb_setCapacity");
if ( a2 < 0 )
_assert_fail("capacity >= 0", "src/szb.c", 0x7Fu, "szb_setCapacity");
v2 = a2 + 255;
LOBYTE(v2) = 0;
if ( *(_DWORD *)(a1 + 8) != v2 )
{
v3 = realloc(*(void **)(a1 + 16), v2);
if ( !v3 )
free(*(void **)(a1 + 16));
*(_QWORD *)(a1 + 16) = v3;
*(_DWORD *)(a1 + 8) = v2;
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2)
{
int v2; // ebx
void *v3; // r12

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x7Eu, "szb_setCapacity");
if ( a2 < 0 )
_assert_fail("capacity >= 0", "src/szb.c", 0x7Fu, "szb_setCapacity");
v2 = a2 + 255;
LOBYTE(v2) = 0;
if ( *(_DWORD *)(a1 + 8) != v2 )
{
v3 = realloc(*(void **)(a1 + 16), v2);
if ( !v3 )
free(*(void **)(a1 + 16));
*(_QWORD *)(a1 + 16) = v3;
*(_DWORD *)(a1 + 8) = v2;
}
}

original_code:
void szb_setCapacity(szb_t *buf, int capacity) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 126, __extension__ __PRETTY_FUNCTION__));
    ((capacity >= 0) ? (void) (0) : __assert_fail ("capacity >= 0", "src/szb.c", 127, __extension__ __PRETTY_FUNCTION__));
    capacity = (capacity + 256 - 1) & 0xFFFFFF00;
    if (capacity != buf->capacity) {
        char *data;
        data = realloc(buf->data, capacity);
        if (data == ((void *)0)) {
            free(buf->data);
        }
        buf->data = data;
        buf->capacity = capacity;
    }
}

canonical_original_code:
void szb_setCapacity(struct szb_s *buf, int capacity) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 126, __extension__ __PRETTY_FUNCTION__));
    ((capacity >= 0) ? (void) (0) : __assert_fail ("capacity >= 0", "src/szb.c", 127, __extension__ __PRETTY_FUNCTION__));
    capacity = (capacity + 256 - 1) & 0xFFFFFF00;
    if (capacity != buf->capacity) {
        char *data;
        data = realloc(buf->data, capacity);
        if (data == ((void *)0)) {
            free(buf->data);
        }
        buf->data = data;
        buf->capacity = capacity;
    }
}

variable_types: capacity int

variable_types:
data
char *


decompiled_code:
void __fastcall szb_resize(int *a1, int a2)
{
if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x8Eu, "szb_resize");
if ( a2 < 0 )
_assert_fail("size >= 0", "src/szb.c", 0x8Fu, "szb_resize");
if ( a1[2] < a2 )
szb_setCapacity((__int64)a1, a2);
a1[1] = a2;
if ( *a1 > a2 )
*a1 = a2;
}

canonical_decompiled_code:
void __fastcall func8(int *a1, int a2)
{
if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x8Eu, "szb_resize");
if ( a2 < 0 )
_assert_fail("size >= 0", "src/szb.c", 0x8Fu, "szb_resize");
if ( a1[2] < a2 )
func7((__int64)a1, a2);
a1[1] = a2;
if ( *a1 > a2 )
*a1 = a2;
}

original_code:
void szb_resize(szb_t *buf, int size) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 142, __extension__ __PRETTY_FUNCTION__));
    ((size >= 0) ? (void) (0) : __assert_fail ("size >= 0", "src/szb.c", 143, __extension__ __PRETTY_FUNCTION__));
    if (size > buf->capacity) {
        szb_setCapacity(buf, size);
    }
    buf->size = size;
    if (buf->pos > buf->size) {
        buf->pos = buf->size;
    }
}

canonical_original_code:
void szb_resize(struct szb_s *buf, int size) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 142, __extension__ __PRETTY_FUNCTION__));
    ((size >= 0) ? (void) (0) : __assert_fail ("size >= 0", "src/szb.c", 143, __extension__ __PRETTY_FUNCTION__));
    if (size > buf->capacity) {
        szb_setCapacity(buf, size);
    }
    buf->size = size;
    if (buf->pos > buf->size) {
        buf->pos = buf->size;
    }
}

variable_types: size int


decompiled_code:
void __fastcall need_space(int *a1, int a2)
{
int v2; // esi

v2 = *a1 + a2;
if ( a1[1] < v2 )
szb_resize(a1, v2);
}

canonical_decompiled_code:
void __fastcall func9(int *a1, int a2)
{
int v2; // esi

v2 = *a1 + a2;
if ( a1[1] < v2 )
func8(a1, v2);
}

original_code:
static void need_space(szb_t *buf, int space) {
    int npos = buf->pos + space;
    if (npos > buf->size) {
        szb_resize(buf, npos);
    }
}

canonical_original_code:
static void need_space(struct szb_s *buf, int space) {
    int npos = buf->pos + space;
    if (npos > buf->size) {
        szb_resize(buf, npos);
    }
}

variable_types: space int

variable_types: npos int


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

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x32u, "szb_write8");
need_space(a1, 1);
result = *a1;
*(_BYTE *)(*((_QWORD *)a1 + 2) + result) = a2;
++*a1;
return result;
}

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

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x32u, "szb_write8");
func9(a1, 1);
result = *a1;
*(_BYTE *)(*((_QWORD *)a1 + 2) + result) = a2;
++*a1;
return result;
}

original_code:
void szb_write8(szb_t *buf, int v) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 50, __extension__ __PRETTY_FUNCTION__));
    need_space(buf, 1);
    buf->data[buf->pos] = v;
    buf->pos += 1;
}

canonical_original_code:
void szb_write8(struct szb_s *buf, int v) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 50, __extension__ __PRETTY_FUNCTION__));
    need_space(buf, 1);
    buf->data[buf->pos] = v;
    buf->pos += 1;
}


decompiled_code:
__int64 __fastcall szb_write16(int *a1, __int16 a2)
{
if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x39u, "szb_write16");
szb_write8(a1, a2);
return szb_write8(a1, SHIBYTE(a2));
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1, __int16 a2)
{
if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x39u, "szb_write16");
func10(a1, a2);
return func10(a1, SHIBYTE(a2));
}

original_code:
void szb_write16(szb_t *buf, int v) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 57, __extension__ __PRETTY_FUNCTION__));
    szb_write8(buf, v & 0xFF);
    szb_write8(buf, (v >> 8) & 0xFF);
}

canonical_original_code:
void szb_write16(struct szb_s *buf, int v) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 57, __extension__ __PRETTY_FUNCTION__));
    szb_write8(buf, v & 0xFF);
    szb_write8(buf, (v >> 8) & 0xFF);
}


decompiled_code:
__int64 __fastcall szb_write32(int *a1, int a2)
{
if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x3Fu, "szb_write32");
szb_write8(a1, a2);
szb_write8(a1, SBYTE1(a2));
szb_write8(a1, SBYTE2(a2));
return szb_write8(a1, SHIBYTE(a2));
}

canonical_decompiled_code:
__int64 __fastcall func12(int *a1, int a2)
{
if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x3Fu, "szb_write32");
func10(a1, a2);
func10(a1, SBYTE1(a2));
func10(a1, SBYTE2(a2));
return func10(a1, SHIBYTE(a2));
}

original_code:
void szb_write32(szb_t *buf, int v) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 63, __extension__ __PRETTY_FUNCTION__));
    szb_write8(buf, v & 0xFF);
    szb_write8(buf, (v >> 8) & 0xFF);
    szb_write8(buf, (v >> 16) & 0xFF);
    szb_write8(buf, (v >> 24) & 0xFF);
}

canonical_original_code:
void szb_write32(struct szb_s *buf, int v) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 63, __extension__ __PRETTY_FUNCTION__));
    szb_write8(buf, v & 0xFF);
    szb_write8(buf, (v >> 8) & 0xFF);
    szb_write8(buf, (v >> 16) & 0xFF);
    szb_write8(buf, (v >> 24) & 0xFF);
}


decompiled_code:
void *__fastcall szb_writeCStr(int *a1, const char *a2)
{
int v2; // ebp
void *result; // rax

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x49u, "szb_writeCStr");
v2 = strlen(a2) + 1;
need_space(a1, v2);
result = memcpy((void *)(*((_QWORD *)a1 + 2) + *a1), a2, v2);
*a1 += v2;
return result;
}

canonical_decompiled_code:
void *__fastcall func13(int *a1, const char *a2)
{
int v2; // ebp
void *result; // rax

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x49u, "szb_writeCStr");
v2 = strlen(a2) + 1;
func9(a1, v2);
result = memcpy((void *)(*((_QWORD *)a1 + 2) + *a1), a2, v2);
*a1 += v2;
return result;
}

original_code:
void szb_writeCStr(szb_t *buf, const char *str) {
    int len;
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 73, __extension__ __PRETTY_FUNCTION__));
    len = strlen(str) + 1;
    need_space(buf, len);
    memcpy(&buf->data[buf->pos], str, len);
    buf->pos += len;
}

canonical_original_code:
void szb_writeCStr(struct szb_s *buf, char *str) {
    int len;
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 73, __extension__ __PRETTY_FUNCTION__));
    len = strlen(str) + 1;
    need_space(buf, len);
    memcpy(&buf->data[buf->pos], str, len);
    buf->pos += len;
}

variable_types:
str
char *

variable_types: len int


decompiled_code:
__int64 __fastcall szb_getPtr(__int64 a1)
{
if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x9Au, "szb_getPtr");
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x9Au, "szb_getPtr");
return *(_QWORD *)(a1 + 16);
}

original_code:
void *szb_getPtr(szb_t *buf) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 154, __extension__ __PRETTY_FUNCTION__));
    return buf->data;
}

canonical_original_code:
void *szb_getPtr(struct szb_s *buf) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 154, __extension__ __PRETTY_FUNCTION__));
    return buf->data;
}


decompiled_code:
__int64 __fastcall szb_getPosPtr(__int64 a1)
{
int v1; // eax

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x9Fu, "szb_getPosPtr");
v1 = *(_DWORD *)a1;
if ( *(int *)a1 < 0 )
return 0LL;
if ( v1 >= *(_DWORD *)(a1 + 4) )
return 0LL;
return *(_QWORD *)(a1 + 16) + v1;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
int v1; // eax

if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0x9Fu, "szb_getPosPtr");
v1 = *(_DWORD *)a1;
if ( *(int *)a1 < 0 )
return 0LL;
if ( v1 >= *(_DWORD *)(a1 + 4) )
return 0LL;
return *(_QWORD *)(a1 + 16) + v1;
}

original_code:
void *szb_getPosPtr(szb_t *buf) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 159, __extension__ __PRETTY_FUNCTION__));
    if (buf->pos < 0 || buf->pos >= buf->size) {
        return ((void *)0);
    }
    return &buf->data[buf->pos];
}

canonical_original_code:
void *szb_getPosPtr(struct szb_s *buf) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 159, __extension__ __PRETTY_FUNCTION__));
    if (buf->pos < 0 || buf->pos >= buf->size) {
        return ((void *)0);
    }
    return &buf->data[buf->pos];
}


decompiled_code:
__int64 __fastcall szb_getSize(__int64 a1)
{
if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0xA7u, "szb_getSize");
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0xA7u, "szb_getSize");
return *(unsigned int *)(a1 + 4);
}

original_code:
int szb_getSize(szb_t *buf) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 167, __extension__ __PRETTY_FUNCTION__));
    return buf->size;
}

canonical_original_code:
int szb_getSize(struct szb_s *buf) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 167, __extension__ __PRETTY_FUNCTION__));
    return buf->size;
}


decompiled_code:
bool __fastcall szb_eof(_DWORD *a1)
{
if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0xACu, "szb_eof");
return *a1 >= a1[1];
}

canonical_decompiled_code:
bool __fastcall func17(_DWORD *a1)
{
if ( !a1 )
_assert_fail("buf != NULL", "src/szb.c", 0xACu, "szb_eof");
return *a1 >= a1[1];
}

original_code:
_Bool szb_eof(szb_t *buf) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 172, __extension__ __PRETTY_FUNCTION__));
    if (buf->pos >= buf->size) {
        return 1;
    }
    return 0;
}

canonical_original_code:
_Bool szb_eof(struct szb_s *buf) {
    ((buf != ((void *)0)) ? (void) (0) : __assert_fail ("buf != NULL", "src/szb.c", 172, __extension__ __PRETTY_FUNCTION__));
    if (buf->pos >= buf->size) {
        return 1;
    }
    return 0;
}


decompiled_code:
void init_term()
{
if ( !input_on )
_assert_fail("input_on", "src/console.c", 0x21u, "init_term");
tcgetattr(0, &orig_termios);
tty_erase = orig_termios.c_cc[2];
*(__m128i *)&new_termios.c_iflag = _mm_load_si128((const __m128i *)&orig_termios);
*(__m128i *)&new_termios.c_line = _mm_load_si128((const __m128i *)&orig_termios.c_line);
*(__m128i *)&new_termios.c_cc[15] = _mm_load_si128((const __m128i *)&orig_termios.c_cc[15]);
*(_QWORD *)&new_termios.c_cc[31] = *(_QWORD *)&orig_termios.c_cc[31];
new_termios.c_ospeed = orig_termios.c_ospeed;
cfmakeraw(&new_termios);
}

canonical_decompiled_code:
void func0()
{
if ( !input_on )
_assert_fail("input_on", "src/console.c", 0x21u, "init_term");
tcgetattr(0, &orig_termios);
tty_erase = orig_termios.c_cc[2];
*(__m128i *)&new_termios.c_iflag = _mm_load_si128((const __m128i *)&orig_termios);
*(__m128i *)&new_termios.c_line = _mm_load_si128((const __m128i *)&orig_termios.c_line);
*(__m128i *)&new_termios.c_cc[15] = _mm_load_si128((const __m128i *)&orig_termios.c_cc[15]);
*(_QWORD *)&new_termios.c_cc[31] = *(_QWORD *)&orig_termios.c_cc[31];
new_termios.c_ospeed = orig_termios.c_ospeed;
cfmakeraw(&new_termios);
}

original_code:
static void init_term() {
    ((input_on) ? (void) (0) : __assert_fail ("input_on", "src/console.c", 33, __extension__ __PRETTY_FUNCTION__));
    tcgetattr(0, &orig_termios);
    tty_erase = orig_termios.c_cc[2];
    memcpy(&new_termios, &orig_termios, sizeof(new_termios));
    cfmakeraw(&new_termios);
}


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

if ( !input_on )
_assert_fail("input_on", "src/console.c", 0x18u, "set_raw");
if ( a1 )
result = tcsetattr(0, 0, &new_termios);
else
result = tcsetattr(0, 0, &orig_termios);
return result;
}

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

if ( !input_on )
_assert_fail("input_on", "src/console.c", 0x18u, "set_raw");
if ( a1 )
result = tcsetattr(0, 0, &new_termios);
else
result = tcsetattr(0, 0, &orig_termios);
return result;
}

original_code:
static void set_raw(_Bool raw) {
    ((input_on) ? (void) (0) : __assert_fail ("input_on", "src/console.c", 24, __extension__ __PRETTY_FUNCTION__));
    if (raw) {
        tcsetattr(0, 0, &new_termios);
    } else {
        tcsetattr(0, 0, &orig_termios);
    }
}


getch

decompiled_code:
__int64 getch()
{
int v0; // edx
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( !input_on )
_assert_fail("input_on", "src/console.c", 0x36u, "getch");
v0 = read(0, buf, 1uLL);
if ( v0 >= 0 )
v0 = (unsigned __int8)buf[0];
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // edx
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( !input_on )
_assert_fail("input_on", "src/console.c", 0x36u, "getch");
v0 = read(0, buf, 1uLL);
if ( v0 >= 0 )
v0 = (unsigned __int8)buf[0];
return (unsigned int)v0;
}

original_code:
static int getch() {
    int r;
    unsigned char c;
    ((input_on) ? (void) (0) : __assert_fail ("input_on", "src/console.c", 54, __extension__ __PRETTY_FUNCTION__));
    if ((r = read(0, &c, sizeof(c))) < 0) {
        return r;
    } else {
        return c;
    }
}

variable_types:
c
unsigned char


decompiled_code:
char __fastcall con_run(char *s)
{
const unsigned __int16 **v2; // rbp
char result; // al
int v4; // eax
bool v5; // cf
bool v6; // zf
char *i; // rax
__int64 v8; // rcx
const char *v9; // rdi
__int64 v10; // rcx
char *v11; // rsi

v2 = _ctype_b_loc();
while ( 1 )
{
result = *s;
if ( ((*v2)[*s] & 0x2000) == 0 )
break;
++s;
}
if ( result != 35 )
{
v4 = strlen(s) - 1;
v5 = 0;
v6 = v4 == 0;
if ( v4 > 0 )
{
for ( i = &s[v4]; ; *i = 0 )
{
v8 = *i;
v5 = 0;
v6 = ((*v2)[v8] & 0x2000) == 0;
if ( ((*v2)[v8] & 0x2000) == 0 )
break;
}
}
v9 = "/quit";
v10 = 6LL;
v11 = s;
do
{
if ( !v10 )
break;
v5 = (unsigned __int8)*v11 < (unsigned int)*v9;
v6 = *v11++ == *v9++;
--v10;
}
while ( v6 );
result = (!v5 && !v6) - v5;
if ( result )
{
result = (char)cmdparserfn;
if ( cmdparserfn )
result = cmdparserfn(s, v11);
}
else
{
quitFlag = 1;
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func3(char *s)
{
const unsigned __int16 **v2; // rbp
char result; // al
int v4; // eax
bool v5; // cf
bool v6; // zf
char *i; // rax
__int64 v8; // rcx
const char *v9; // rdi
__int64 v10; // rcx
char *v11; // rsi

v2 = _ctype_b_loc();
while ( 1 )
{
result = *s;
if ( ((*v2)[*s] & 0x2000) == 0 )
break;
++s;
}
if ( result != 35 )
{
v4 = strlen(s) - 1;
v5 = 0;
v6 = v4 == 0;
if ( v4 > 0 )
{
for ( i = &s[v4]; ; *i = 0 )
{
v8 = *i;
v5 = 0;
v6 = ((*v2)[v8] & 0x2000) == 0;
if ( ((*v2)[v8] & 0x2000) == 0 )
break;
}
}
v9 = "/quit";
v10 = 6LL;
v11 = s;
do
{
if ( !v10 )
break;
v5 = (unsigned __int8)*v11 < (unsigned int)*v9;
v6 = *v11++ == *v9++;
--v10;
}
while ( v6 );
result = (!v5 && !v6) - v5;
if ( result )
{
result = (char)cmdparserfn;
if ( cmdparserfn )
result = cmdparserfn(s, v11);
}
else
{
quitFlag = 1;
}
}
return result;
}

original_code:
static void con_run(char *str) {
    int len;
    int pos;
    while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace)) {
        str++;
    }
    if (*str == '#') {
        return;
    }
    len = strlen(str);
    pos = len - 1;
    while(pos > 0) {
        if (!((*__ctype_b_loc ())[(int) ((str[pos]))] & (unsigned short int) _ISspace)) {
            break;
        }
        str[pos] = '\0';
    }
    if (strcmp(str, "/quit") == 0) {
        quitFlag = 1;
        return;
    }
    if (cmdparserfn != ((void *)0)) {
        cmdparserfn(str);
    }
}

canonical_original_code:
static void con_run(char *str) {
    int len;
    int pos;
    while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace)) {
        str++;
    }
    if (*str == '#') {
        return;
    }
    len = strlen(str);
    pos = len - 1;
    while(pos > 0) {
        if (!((*__ctype_b_loc ())[(int) ((str[pos]))] & (unsigned short) _ISspace)) {
            break;
        }
        str[pos] = '\0';
    }
    if (strcmp(str, "/quit") == 0) {
        quitFlag = 1;
        return;
    }
    if (cmdparserfn != ((void *)0)) {
        cmdparserfn(str);
    }
}

variable_types: pos int


kbhit

decompiled_code:
int kbhit()
{
struct timeval v1; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v1.tv_sec = 0LL;
v1.tv_usec = 0LL;
if ( !input_on )
_assert_fail("input_on", "src/console.c", 0x2Cu, "kbhit");
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[0] |= 1uLL;
return select(1, &readfds, 0LL, 0LL, &v1);
}

canonical_decompiled_code:
int func4()
{
struct timeval v1; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v1.tv_sec = 0LL;
v1.tv_usec = 0LL;
if ( !input_on )
_assert_fail("input_on", "src/console.c", 0x2Cu, "kbhit");
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[0] |= 1uLL;
return select(1, &readfds, 0LL, 0LL, &v1);
}

original_code:
static int kbhit() {
    fd_set fds;
    struct timeval tv = { 0L, 0L };
    ((input_on) ? (void) (0) : __assert_fail ("input_on", "src/console.c", 44, __extension__ __PRETTY_FUNCTION__));
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
    return select(1, &fds, ((void *)0), ((void *)0), &tv);
}

canonical_original_code:
static int kbhit() {
    struct fd_set fds;
    struct timeval tv = { 0L, 0L };
    ((input_on) ? (void) (0) : __assert_fail ("input_on", "src/console.c", 44, __extension__ __PRETTY_FUNCTION__));
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
    return select(1, &fds, ((void *)0), ((void *)0), &tv);
}

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

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


decompiled_code:
__int64 con_init()
{
input_on = 1;
kbd_buf = szb_create();
init_term();
if ( input_on )
set_raw(1);
quitFlag = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
input_on = 1;
kbd_buf = szb_create();
func0();
if ( input_on )
func1(1);
quitFlag = 0;
return 1LL;
}

original_code:
_Bool con_init() {
    input_on = 1;
    kbd_buf = szb_create();
    init_term();
    if (input_on) {
        set_raw(1);
    }
    quitFlag = 0;
    return 1;
}


decompiled_code:
__int64 con_cleanup()
{
if ( input_on )
set_raw(0);
if ( kbd_buf )
{
szb_free();
kbd_buf = 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 func6()
{
if ( input_on )
func1(0);
if ( kbd_buf )
{
szb_free();
kbd_buf = 0LL;
}
return 1LL;
}

original_code:
_Bool con_cleanup() {
    if (input_on) {
        set_raw(0);
    }
    if (kbd_buf != ((void *)0)) {
        szb_free(kbd_buf);
        kbd_buf = ((void *)0);
    }
    return 1;
}


decompiled_code:
int __fastcall con_print(const char *a1)
{
int result; // eax

if ( input_on )
set_raw(0);
printf("%s", a1);
result = fflush(stdout);
if ( input_on )
result = set_raw(1);
return result;
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
int result; // eax

if ( input_on )
func1(0);
printf("%s", a1);
result = fflush(stdout);
if ( input_on )
result = func1(1);
return result;
}

original_code:
void con_print(const char *msg) {
    if (input_on) {
        set_raw(0);
    }
    printf("%s", msg);
    fflush(stdout);
    if (input_on) {
        set_raw(1);
    }
}

canonical_original_code:
void con_print(char *msg) {
    if (input_on) {
        set_raw(0);
    }
    printf("%s", msg);
    fflush(stdout);
    if (input_on) {
        set_raw(1);
    }
}

variable_types:
msg
char *


decompiled_code:
int con_printf(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

if ( format )
{
va_start(arg, format);
vsnprintf(s, 0x400uLL, format, arg);
result = con_print(s);
}
return result;
}

canonical_decompiled_code:
int func8(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

if ( format )
{
va_start(arg, format);
vsnprintf(s, 0x400uLL, format, arg);
result = func7(s);
}
return result;
}

original_code:
void con_printf(const char *fmt, ...) {
    char text[1024];
    va_list ap;
    if (fmt == ((void *)0))
        return;
    __builtin_va_start(ap,fmt);
    vsnprintf(text, sizeof(text), fmt, ap);
    __builtin_va_end(ap);
    con_print(text);
}

canonical_original_code:
void con_printf(char *fmt, ...) {
    char text[1024];
    __builtin_va_list ap;
    if (fmt == ((void *)0))
        return;
    __builtin_va_start(ap,fmt);
    vsnprintf(text, sizeof(text), fmt, ap);
    __builtin_va_end(ap);
    con_print(text);
}

variable_types:
fmt
char *

variable_types:
text
char [1024]


decompiled_code:
int __fastcall con_error(const char *a1)
{
int result; // eax

if ( input_on )
set_raw(0);
fprintf(stderr, "[ERROR] %s", a1);
result = fflush(stderr);
if ( input_on )
result = set_raw(1);
return result;
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
int result; // eax

if ( input_on )
func1(0);
fprintf(stderr, "[ERROR] %s", a1);
result = fflush(stderr);
if ( input_on )
result = func1(1);
return result;
}

original_code:
void con_error(const char *msg) {
    if (input_on) {
        set_raw(0);
    }
    fprintf(stderr, "[ERROR] %s", msg);
    fflush(stderr);
    if (input_on) {
        set_raw(1);
    }
}

canonical_original_code:
void con_error(char *msg) {
    if (input_on) {
        set_raw(0);
    }
    fprintf(stderr, "[ERROR] %s", msg);
    fflush(stderr);
    if (input_on) {
        set_raw(1);
    }
}


decompiled_code:
int con_errorf(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

if ( format )
{
va_start(arg, format);
vsnprintf(s, 0x400uLL, format, arg);
result = con_error(s);
}
return result;
}

canonical_decompiled_code:
int func10(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

if ( format )
{
va_start(arg, format);
vsnprintf(s, 0x400uLL, format, arg);
result = func9(s);
}
return result;
}

original_code:
void con_errorf(const char *fmt, ...) {
    char text[1024];
    va_list ap;
    if (fmt == ((void *)0))
        return;
    __builtin_va_start(ap,fmt);
    vsnprintf(text, sizeof(text), fmt, ap);
    __builtin_va_end(ap);
    con_error(text);
}

canonical_original_code:
void con_errorf(char *fmt, ...) {
    char text[1024];
    __builtin_va_list ap;
    if (fmt == ((void *)0))
        return;
    __builtin_va_start(ap,fmt);
    vsnprintf(text, sizeof(text), fmt, ap);
    __builtin_va_end(ap);
    con_error(text);
}


decompiled_code:
void con_checkInput()
{
int v0; // ebx
char v1; // al
char *v2; // rax
char buf[9]; // [rsp+1h] [rbp-9h] BYREF

if ( input_on )
{
while ( kbhit() )
{
v1 = getch();
buf[0] = v1;
if ( v1 == tty_erase )
{
v0 = szb_getSize(kbd_buf);
if ( v0 > 0 )
{
write(1, "\b \b", 3uLL);
szb_resize(kbd_buf, (unsigned int)(v0 - 1));
}
}
else if ( v1 == 27 )
{
quitFlag = 1;
}
else if ( (v1 > 31 || (v1 & 0xFB) == 9) && buf[0] )
{
write(1, buf, 1uLL);
if ( buf[0] == 13 )
{
buf[0] = 10;
write(1, buf, 1uLL);
}
if ( buf[0] == 10 || (szb_write8(kbd_buf, (unsigned int)buf[0]), buf[0] == 10) )
{
szb_write8(kbd_buf, 0LL);
v2 = (char *)szb_getPtr(kbd_buf);
con_run(v2);
szb_resize(kbd_buf, 0LL);
}
}
}
}
}

canonical_decompiled_code:
void func11()
{
int v0; // ebx
char v1; // al
char *v2; // rax
char buf[9]; // [rsp+1h] [rbp-9h] BYREF

if ( input_on )
{
while ( func4() )
{
v1 = func2();
buf[0] = v1;
if ( v1 == tty_erase )
{
v0 = szb_getSize(kbd_buf);
if ( v0 > 0 )
{
write(1, "\b \b", 3uLL);
szb_resize(kbd_buf, (unsigned int)(v0 - 1));
}
}
else if ( v1 == 27 )
{
quitFlag = 1;
}
else if ( (v1 > 31 || (v1 & 0xFB) == 9) && buf[0] )
{
write(1, buf, 1uLL);
if ( buf[0] == 13 )
{
buf[0] = 10;
write(1, buf, 1uLL);
}
if ( buf[0] == 10 || (szb_write8(kbd_buf, (unsigned int)buf[0]), buf[0] == 10) )
{
szb_write8(kbd_buf, 0LL);
v2 = (char *)szb_getPtr(kbd_buf);
func3(v2);
szb_resize(kbd_buf, 0LL);
}
}
}
}
}

original_code:
void con_checkInput() {
    if (!input_on) {
        return;
    }
    while (kbhit()) {
        int r;
        char cc;
        cc = getch();
        if (cc == tty_erase) {
            int len = szb_getSize(kbd_buf);
            if (len > 0) {
                r = write(1, "\b \b", 3);
                szb_resize(kbd_buf, len - 1);
            }
            continue;
        }
        if (cc == 27) {
            quitFlag = 1;
            cc = 0;
        }
        if (cc < ' ') {
            if (cc != '\r' && cc != '\t') {
                cc = 0;
            }
        }
        if (cc != 0) {
            r = write(1, &cc, 1);
            if (cc == '\r') {
                cc = '\n';
                r = write(1, &cc, 1);
            }
            if (cc != '\n') {
                szb_write8(kbd_buf, cc);
            }
        }
        if (cc == '\n') {
            szb_write8(kbd_buf, '\0');
            con_run(szb_getPtr(kbd_buf));
            szb_resize(kbd_buf, 0);
        }
    }
}

variable_types: cc char


decompiled_code:
__int64 con_isRunning()
{
return (unsigned __int8)quitFlag ^ 1u;
}

canonical_decompiled_code:
__int64 func12()
{
return (unsigned __int8)quitFlag ^ 1u;
}

original_code:
_Bool con_isRunning() {
    return !quitFlag;
}


decompiled_code:
__int64 my_print_rtab()
{
unsigned int v0; // eax

v0 = sys_getMilli();
con_printf("[DEBUG] current routing table (timestamp = %d):\n", v0);
return print_rtab();
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax

v0 = sys_getMilli();
con_printf("[DEBUG] current routing table (timestamp = %d):\n", v0);
return print_rtab();
}

original_code:
static void my_print_rtab(void) {
    con_printf("[DEBUG] current routing table (timestamp = %d):\n", sys_getMilli());
    print_rtab();
}

canonical_original_code:
static void my_print_rtab() {
    con_printf("[DEBUG] current routing table (timestamp = %d):\n", sys_getMilli());
    print_rtab();
}


decompiled_code:
__int64 update_rt()
{
int v0; // eax
int v1; // er13
unsigned int v2; // ebp
unsigned int v3; // er15
int v4; // er12
int i; // ebx
int v6; // eax
int v7; // ebx
unsigned int v9; // [rsp+Ch] [rbp-3Ch]

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

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
int v1; // er13
unsigned int v2; // ebp
unsigned int v3; // er15
int v4; // er12
int i; // ebx
int v6; // eax
int v7; // ebx
unsigned int v9; // [rsp+Ch] [rbp-3Ch]

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

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; // r12
char v1; // bp
int v2; // ebx
int v3; // er13
int v4; // eax
int v5; // er13
int v6; // ebx
int v7; // ebx

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 )
{
drop_neighbour((unsigned int)v7);
v1 = 1;
}
v7 = next_neighbour((unsigned int)v7);
}
while ( v7 >= 0 );
v0 = v1;
goto LABEL_20;
}
v2 = next_neighbour(0xFFFFFFFFLL);
if ( v2 < 0 )
{
v3 = -1;
}
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
{
if ( (int)net_lastTime((unsigned int)v6) < v5 )
{
drop_neighbour((unsigned int)v6);
v0 = v1;
}
v6 = next_neighbour((unsigned int)v6);
}
while ( v6 >= 0 );
LABEL_20:
if ( v0 )
{
update_rt();
send_dv();
if ( *((_BYTE *)&options + 44) )
my_print_rtab();
}
}
}

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

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 )
{
drop_neighbour((unsigned int)v7);
v1 = 1;
}
v7 = next_neighbour((unsigned int)v7);
}
while ( v7 >= 0 );
v0 = v1;
goto LABEL_20;
}
v2 = next_neighbour(0xFFFFFFFFLL);
if ( v2 < 0 )
{
v3 = -1;
}
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
{
if ( (int)net_lastTime((unsigned int)v6) < v5 )
{
drop_neighbour((unsigned int)v6);
v0 = v1;
}
v6 = next_neighbour((unsigned int)v6);
}
while ( v6 >= 0 );
LABEL_20:
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


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

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

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

time = sys_getMilli();
nextHeartBeat = options[4] + time;
nextHeartCheck = options[5] + time;
result = (unsigned int)(options[2] + time);
nextShow = options[2] + time;
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
int v1; // edx

v0 = sys_getMilli();
time = v0;
if ( !LOBYTE(options[3]) )
{
v1 = options[2];
if ( v1 > 0 && v0 >= nextShow )
{
nextShow = v1 + v0;
cmd_tabs();
}
if ( time >= nextHeartBeat )
{
nextHeartBeat = options[4] + time;
send_dv();
}
if ( time >= nextHeartCheck )
{
nextHeartCheck = options[5] + time;
router_dropcheck();
}
}
}

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

v0 = sys_getMilli();
time = v0;
if ( !LOBYTE(options[3]) )
{
v1 = options[2];
if ( v1 > 0 && v0 >= nextShow )
{
nextShow = v1 + v0;
cmd_tabs();
}
if ( time >= nextHeartBeat )
{
nextHeartBeat = options[4] + time;
func1();
}
if ( time >= nextHeartCheck )
{
nextHeartCheck = options[5] + time;
func3();
}
}
}

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


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


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)
{
void *result; // rax

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

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

if ( !a1 )
_assert_fail("tab != NULL", "src/tables.c", 0x56u, "tab_set");
if ( a2 >= 0 && a3 >= 0 )
{
if ( a1[1] <= a2 || a1[2] <= a3 )
func3(a1, a2, a3);
result = memcpy((void *)(*((_QWORD *)a1 + 2) + *a1 * (a1[2] * 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_6A2, (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_6A2, (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
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

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

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

result = _isoc99_sscanf(a1, &unk_6A2, v2);
if ( (_DWORD)result != 1 )
return con_error("usage: debugrt <0/1>\n");
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
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

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

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

result = _isoc99_sscanf(a1, &unk_6A2, v2);
if ( (_DWORD)result != 1 )
return con_error("usage: debugpacket <0/1>\n");
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
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

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

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

result = _isoc99_sscanf(a1, &unk_6A2, v2);
if ( (_DWORD)result != 1 )
return con_error("usage: debuglost <0/1>\n");
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
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

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

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

result = _isoc99_sscanf(a1, &unk_6A2, v2);
if ( (_DWORD)result != 1 )
return con_error("usage: debugroute <0/1>\n");
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_6A2, (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_6A2, (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_6A2, 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_6A2, 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");
}