decompiled_code:
__int64 __fastcall rerr_process(__int64 a1, int a2, unsigned int a3, unsigned int a4)
{
const char *v6; // rax
int v7; // edx
int v8; // er14
__int64 result; // rax
unsigned int *v10; // r15
int *v11; // r14
const char *v12; // rax
unsigned int v14; // ebp
unsigned int v15; // er12
const char *v16; // rax
__int64 v17; // rax
const char *v18; // rax
__int64 v19; // r10
int v20; // ecx
unsigned int v21; // esi
__int64 v22; // r10
unsigned int v23; // ebp
const char *v24; // rax
__int64 v25; // r10
char v26; // dl
unsigned __int64 v27; // rbx
const char *v28; // rbx
const char *v29; // rax
unsigned int v30; // ebp
const char *v31; // rax
int v32; // eax
__int64 v33; // rcx
unsigned int v34; // [rsp+4h] [rbp-44h]
__int64 v35; // [rsp+8h] [rbp-40h]
__int64 v36; // [rsp+8h] [rbp-40h]
__int64 v37; // [rsp+8h] [rbp-40h]
__int64 v38; // [rsp+8h] [rbp-40h]

v6 = (const char *)ip_to_str(a3);
alog(7LL, 0LL, "rerr_process", "ip_src=%s", v6);
log_pkt_fields(a1);
v7 = *(unsigned __int8 *)(a1 + 3);
v8 = v7 - 1;
result = (unsigned int)(8 * v7 + 4);
if ( (int)result > a2 )
{
v28 = (const char *)ip_to_str(a4);
v29 = (const char *)ip_to_str(a3);
result = alog(
4LL,
0LL,
"rerr_process",
"IP data too short (%u bytes) from %s to %s. Should be %d bytes.",
(unsigned int)a2,
v29,
v28,
8LL * v8 + 12);
}
else
{
v34 = 0;
v10 = (unsigned int *)(a1 + 4);
v11 = 0LL;
if ( (_BYTE)v7 )
{
do
{
v14 = *v10;
v15 = _bswap_32(v10[1]);
v16 = (const char *)ip_to_str(v14);
alog(7LL, 0LL, "rerr_process", "unreachable dest=%s seqno=%lu", v16, v15);
v17 = rt_table_find(v14);
if ( v17 && *(_BYTE *)(v17 + 36) == 1 && *(_DWORD *)(v17 + 28) == a3 )
{
v35 = v17;
v18 = (const char *)ip_to_str(v14);
alog(7LL, 0LL, "rerr_process", "removing rte %s - WAS IN RERR!!", v18);
v19 = v35;
if ( *(char *)(a1 + 1) >= 0 )
{
rt_table_invalidate(v35);
v19 = v35;
}
v20 = *(_DWORD *)(v19 + 232);
*(_DWORD *)(v19 + 20) = v15;
if ( !v20 || (*(_BYTE *)(v19 + 34) & 2) != 0 )
{
v37 = v19;
result = alog(7LL, 0LL, "rerr_process", "Not sending RERR, no precursors or route in RT_REPAIR");
v25 = v37;
}
else
{
v21 = *(_DWORD *)(v19 + 16);
if ( v11 )
{
rerr_add_udest((__int64)v11, v21, v15);
v23 = *(_DWORD *)(v22 + 20);
v36 = v22;
v24 = (const char *)ip_to_str(*(unsigned int *)(v22 + 16));
result = alog(7LL, 0LL, "rerr_process", "Added %s as unreachable, seqno=%lu", v24, v23);
v25 = v36;
if ( v34 )
{
result = *(_QWORD *)(v36 + 248);
if ( result != v36 + 240 )
{
while ( *(_DWORD *)(result + 16) == v34 )
{
result = *(_QWORD *)(result + 8);
if ( result == v36 + 240 )
goto LABEL_32;
}
v34 = 0;
}
}
}
else
{
v38 = v19;
v11 = rerr_create(*(char *)(a1 + 1) < 0, v21, v15);
v30 = *(_DWORD *)(v38 + 20);
v31 = (const char *)ip_to_str(*(unsigned int *)(v38 + 16));
result = alog(7LL, 0LL, "rerr_process", "Added %s as unreachable, seqno=%lu", v31, v30);
v25 = v38;
if ( *(_DWORD *)(v38 + 232) == 1 )
{
result = *(unsigned int *)(*(_QWORD *)(v38 + 248) + 16LL);
v34 = *(_DWORD *)(*(_QWORD *)(v38 + 248) + 16LL);
}
}
}
LABEL_32:
if ( !*(_BYTE *)(v25 + 36) )
result = precursor_list_destroy(v25);
}
else
{
v12 = (const char *)ip_to_str(v14);
result = alog(7LL, 0LL, "rerr_process", "Ignoring UDEST %s", v12);
}
v10 += 2;
}
while ( (*(_BYTE *)(a1 + 3))-- != 1 );
if ( v11 )
{
result = rt_table_find(v34);
v26 = *((_BYTE *)v11 + 3);
if ( result && v26 == 1 && v34 )
{
v32 = ifindex2devindex(*(_DWORD *)(result + 24));
result = aodv_socket_send(v11, v34, 12LL, v33, &this_host[11 * v32 + 12]);
}
else if ( v26 )
{
v27 = (unsigned int)((_DWORD)this_host + 48);
do
{
result = *(unsigned int *)v27;
if ( (_DWORD)result )
result = aodv_socket_send(
v11,
0xFFFFFFFFLL,
8 * (unsigned int)*((unsigned __int8 *)v11 + 3) + 4,
1LL,
v27);
v27 += 44LL;
}
while ( (int *)v27 != &this_host[122] );
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, unsigned int a3, unsigned int a4)
{
const char *v6; // rax
int v7; // edx
int v8; // er14
__int64 result; // rax
unsigned int *v10; // r15
int *v11; // r14
const char *v12; // rax
unsigned int v14; // ebp
unsigned int v15; // er12
const char *v16; // rax
__int64 v17; // rax
const char *v18; // rax
__int64 v19; // r10
int v20; // ecx
unsigned int v21; // esi
__int64 v22; // r10
unsigned int v23; // ebp
const char *v24; // rax
__int64 v25; // r10
char v26; // dl
unsigned __int64 v27; // rbx
const char *v28; // rbx
const char *v29; // rax
unsigned int v30; // ebp
const char *v31; // rax
int v32; // eax
__int64 v33; // rcx
unsigned int v34; // [rsp+4h] [rbp-44h]
__int64 v35; // [rsp+8h] [rbp-40h]
__int64 v36; // [rsp+8h] [rbp-40h]
__int64 v37; // [rsp+8h] [rbp-40h]
__int64 v38; // [rsp+8h] [rbp-40h]

v6 = (const char *)ip_to_str(a3);
alog(7LL, 0LL, "rerr_process", "ip_src=%s", v6);
log_pkt_fields(a1);
v7 = *(unsigned __int8 *)(a1 + 3);
v8 = v7 - 1;
result = (unsigned int)(8 * v7 + 4);
if ( (int)result > a2 )
{
v28 = (const char *)ip_to_str(a4);
v29 = (const char *)ip_to_str(a3);
result = alog(
4LL,
0LL,
"rerr_process",
"IP data too short (%u bytes) from %s to %s. Should be %d bytes.",
(unsigned int)a2,
v29,
v28,
8LL * v8 + 12);
}
else
{
v34 = 0;
v10 = (unsigned int *)(a1 + 4);
v11 = 0LL;
if ( (_BYTE)v7 )
{
do
{
v14 = *v10;
v15 = func1(v10[1]);
v16 = (const char *)ip_to_str(v14);
alog(7LL, 0LL, "rerr_process", "unreachable dest=%s seqno=%lu", v16, v15);
v17 = rt_table_find(v14);
if ( v17 && *(_BYTE *)(v17 + 36) == 1 && *(_DWORD *)(v17 + 28) == a3 )
{
v35 = v17;
v18 = (const char *)ip_to_str(v14);
alog(7LL, 0LL, "rerr_process", "removing rte %s - WAS IN RERR!!", v18);
v19 = v35;
if ( *(char *)(a1 + 1) >= 0 )
{
rt_table_invalidate(v35);
v19 = v35;
}
v20 = *(_DWORD *)(v19 + 232);
*(_DWORD *)(v19 + 20) = v15;
if ( !v20 || (*(_BYTE *)(v19 + 34) & 2) != 0 )
{
v37 = v19;
result = alog(7LL, 0LL, "rerr_process", "Not sending RERR, no precursors or route in RT_REPAIR");
v25 = v37;
}
else
{
v21 = *(_DWORD *)(v19 + 16);
if ( v11 )
{
func3((__int64)v11, v21, v15);
v23 = *(_DWORD *)(v22 + 20);
v36 = v22;
v24 = (const char *)ip_to_str(*(unsigned int *)(v22 + 16));
result = alog(7LL, 0LL, "rerr_process", "Added %s as unreachable, seqno=%lu", v24, v23);
v25 = v36;
if ( v34 )
{
result = *(_QWORD *)(v36 + 248);
if ( result != v36 + 240 )
{
while ( *(_DWORD *)(result + 16) == v34 )
{
result = *(_QWORD *)(result + 8);
if ( result == v36 + 240 )
goto LABEL_32;
}
v34 = 0;
}
}
}
else
{
v38 = v19;
v11 = func2(*(char *)(a1 + 1) < 0, v21, v15);
v30 = *(_DWORD *)(v38 + 20);
v31 = (const char *)ip_to_str(*(unsigned int *)(v38 + 16));
result = alog(7LL, 0LL, "rerr_process", "Added %s as unreachable, seqno=%lu", v31, v30);
v25 = v38;
if ( *(_DWORD *)(v38 + 232) == 1 )
{
result = *(unsigned int *)(*(_QWORD *)(v38 + 248) + 16LL);
v34 = *(_DWORD *)(*(_QWORD *)(v38 + 248) + 16LL);
}
}
}
LABEL_32:
if ( !*(_BYTE *)(v25 + 36) )
result = precursor_list_destroy(v25);
}
else
{
v12 = (const char *)ip_to_str(v14);
result = alog(7LL, 0LL, "rerr_process", "Ignoring UDEST %s", v12);
}
v10 += 2;
}
while ( (*(_BYTE *)(a1 + 3))-- != 1 );
if ( v11 )
{
result = rt_table_find(v34);
v26 = *((_BYTE *)v11 + 3);
if ( result && v26 == 1 && v34 )
{
v32 = func0(*(_DWORD *)(result + 24));
result = aodv_socket_send(v11, v34, 12LL, v33, &this_host[11 * v32 + 12]);
}
else if ( v26 )
{
v27 = (unsigned int)((_DWORD)this_host + 48);
do
{
result = *(unsigned int *)v27;
if ( (_DWORD)result )
result = aodv_socket_send(
v11,
0xFFFFFFFFLL,
8 * (unsigned int)*((unsigned __int8 *)v11 + 3) + 4,
1LL,
v27);
v27 += 44LL;
}
while ( (int *)v27 != &this_host[122] );
}
}
}
}
return result;
}

original_code:
void rerr_process(RERR * rerr, int rerrlen, struct in_addr ip_src,
      struct in_addr ip_dst)
{
    RERR *new_rerr = ((void *)0);
    RERR_udest *udest;
    rt_table_t *rt;
    u_int32_t rerr_dest_seqno;
    struct in_addr udest_addr, rerr_unicast_dest;
    int i;
    rerr_unicast_dest.s_addr = 0;
    alog(7, 0, __FUNCTION__, "ip_src=%s", ip_to_str(ip_src));
    log_pkt_fields((AODV_msg *) rerr);
    if (rerrlen < ((int) (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)))) {
 alog(4, 0, __FUNCTION__,
      "IP data too short (%u bytes) from %s to %s. Should be %d bytes.",
      rerrlen, ip_to_str(ip_src), ip_to_str(ip_dst),
      (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)));
 return;
    }
    udest = ((RERR_udest *)&rerr->dest_addr);
    while (rerr->dest_count) {
 udest_addr.s_addr = udest->dest_addr;
 rerr_dest_seqno = ntohl(udest->dest_seqno);
 alog(7, 0, __FUNCTION__, "unreachable dest=%s seqno=%lu", ip_to_str(udest_addr), rerr_dest_seqno);
 rt = rt_table_find(udest_addr);
 if (rt && rt->state == 1 && rt->next_hop.s_addr == ip_src.s_addr) {
     if (0 && (int32_t) rt->dest_seqno > (int32_t) rerr_dest_seqno) {
  alog(7, 0, __FUNCTION__, "Udest ignored because of seqno");
  udest = ((RERR_udest *)((char *)udest + sizeof(RERR_udest)));
  rerr->dest_count--;
  continue;
     }
     alog(7, 0, __FUNCTION__, "removing rte %s - WAS IN RERR!!", ip_to_str(udest_addr));
     if (!rerr->n) {
  rt_table_invalidate(rt);
     }
     rt->dest_seqno = rerr_dest_seqno;
     if (rt->nprec && !(rt->flags & 0x2)) {
  if (!new_rerr) {
      u_int8_t flags = 0;
      if (rerr->n)
   flags |= 0x1;
      new_rerr = rerr_create(flags, rt->dest_addr,
        rt->dest_seqno);
      alog(7, 0, __FUNCTION__, "Added %s as unreachable, seqno=%lu", ip_to_str(rt->dest_addr), rt->dest_seqno);
      if (rt->nprec == 1)
   rerr_unicast_dest =
       ((precursor_t *)((rt->precursors).next))->neighbor;
  } else {
      rerr_add_udest(new_rerr, rt->dest_addr, rt->dest_seqno);
      alog(7, 0, __FUNCTION__, "Added %s as unreachable, seqno=%lu", ip_to_str(rt->dest_addr), rt->dest_seqno);
      if (rerr_unicast_dest.s_addr) {
   list_t *pos2;
   for (pos2 = (&rt->precursors)->next; pos2 != (&rt->precursors); pos2 = pos2->next) {
       precursor_t *pr = (precursor_t *) pos2;
       if (pr->neighbor.s_addr != rerr_unicast_dest.s_addr) {
    rerr_unicast_dest.s_addr = 0;
    break;
       }
   }
      }
  }
     } else {
  alog(7, 0, __FUNCTION__, "Not sending RERR, no precursors or route in RT_REPAIR");
     }
     if (rt->state == 0)
  precursor_list_destroy(rt);
 } else {
     alog(7, 0, __FUNCTION__, "Ignoring UDEST %s", ip_to_str(udest_addr));
 }
 udest = ((RERR_udest *)((char *)udest + sizeof(RERR_udest)));
 rerr->dest_count--;
    }
    if (new_rerr) {
 rt = rt_table_find(rerr_unicast_dest);
 if (rt && new_rerr->dest_count == 1 && rerr_unicast_dest.s_addr)
     aodv_socket_send((AODV_msg *) new_rerr,
        rerr_unicast_dest,
        (sizeof(RERR) + (new_rerr->dest_count-1)*sizeof(RERR_udest)), 1,
        &(this_host.devs[ifindex2devindex(rt->ifindex)]));
 else if (new_rerr->dest_count > 0) {
     for (i = 0; i < 10; i++) {
  struct in_addr dest;
  if (!(this_host.devs[i]).enabled)
      continue;
  dest.s_addr = ((in_addr_t) 0xFFFFFFFF);
  aodv_socket_send((AODV_msg *) new_rerr, dest,
     (sizeof(RERR) + (new_rerr->dest_count-1)*sizeof(RERR_udest)), 1, &(this_host.devs[i]));
     }
 }
    }
}

canonical_original_code:
void rerr_process(struct RERR *rerr, int rerrlen, struct in_addr ip_src, struct in_addr ip_dst)
{
    struct RERR *new_rerr = ((void *)0);
    struct RERR_udest *udest;
    struct rt_table *rt;
    unsigned int rerr_dest_seqno;
    struct in_addr udest_addr; struct in_addr rerr_unicast_dest;
    int i;
    rerr_unicast_dest.s_addr = 0;
    alog(7, 0, __FUNCTION__, "ip_src=%s", ip_to_str(ip_src));
    log_pkt_fields((struct AODV_msg *) rerr);
    if (rerrlen < ((int) (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)))) {
 alog(4, 0, __FUNCTION__,
      "IP data too short (%u bytes) from %s to %s. Should be %d bytes.",
      rerrlen, ip_to_str(ip_src), ip_to_str(ip_dst),
      (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)));
 return;
    }
    udest = ((struct RERR_udest *)&rerr->dest_addr);
    while (rerr->dest_count) {
 udest_addr.s_addr = udest->dest_addr;
 rerr_dest_seqno = ntohl(udest->dest_seqno);
 alog(7, 0, __FUNCTION__, "unreachable dest=%s seqno=%lu", ip_to_str(udest_addr), rerr_dest_seqno);
 rt = rt_table_find(udest_addr);
 if (rt && rt->state == 1 && rt->next_hop.s_addr == ip_src.s_addr) {
     if (0 && (int) rt->dest_seqno > (int) rerr_dest_seqno) {
  alog(7, 0, __FUNCTION__, "Udest ignored because of seqno");
  udest = ((struct RERR_udest *)((char *)udest + sizeof(RERR_udest)));
  rerr->dest_count--;
  continue;
     }
     alog(7, 0, __FUNCTION__, "removing rte %s - WAS IN RERR!!", ip_to_str(udest_addr));
     if (!rerr->n) {
  rt_table_invalidate(rt);
     }
     rt->dest_seqno = rerr_dest_seqno;
     if (rt->nprec && !(rt->flags & 0x2)) {
  if (!new_rerr) {
      unsigned int flags = 0;
      if (rerr->n)
   flags |= 0x1;
      new_rerr = rerr_create(flags, rt->dest_addr,
        rt->dest_seqno);
      alog(7, 0, __FUNCTION__, "Added %s as unreachable, seqno=%lu", ip_to_str(rt->dest_addr), rt->dest_seqno);
      if (rt->nprec == 1)
   rerr_unicast_dest =
       ((struct precursor *)((rt->precursors).next))->neighbor;
  } else {
      rerr_add_udest(new_rerr, rt->dest_addr, rt->dest_seqno);
      alog(7, 0, __FUNCTION__, "Added %s as unreachable, seqno=%lu", ip_to_str(rt->dest_addr), rt->dest_seqno);
      if (rerr_unicast_dest.s_addr) {
   struct list_t *pos2;
   for (pos2 = (&rt->precursors)->next; pos2 != (&rt->precursors); pos2 = pos2->next) {
       struct precursor *pr = (precursor_t *) pos2;
       if (pr->neighbor.s_addr != rerr_unicast_dest.s_addr) {
    rerr_unicast_dest.s_addr = 0;
    break;
       }
   }
      }
  }
     } else {
  alog(7, 0, __FUNCTION__, "Not sending RERR, no precursors or route in RT_REPAIR");
     }
     if (rt->state == 0)
  precursor_list_destroy(rt);
 } else {
     alog(7, 0, __FUNCTION__, "Ignoring UDEST %s", ip_to_str(udest_addr));
 }
 udest = ((struct RERR_udest *)((char *)udest + sizeof(RERR_udest)));
 rerr->dest_count--;
    }
    if (new_rerr) {
 rt = rt_table_find(rerr_unicast_dest);
 if (rt && new_rerr->dest_count == 1 && rerr_unicast_dest.s_addr)
     aodv_socket_send((struct AODV_msg *) new_rerr,
        rerr_unicast_dest,
        (sizeof(RERR) + (new_rerr->dest_count-1)*sizeof(RERR_udest)), 1,
        &(this_host.devs[ifindex2devindex(rt->ifindex)]));
 else if (new_rerr->dest_count > 0) {
     for (i = 0; i < 10; i++) {
  struct in_addr dest;
  if (!(this_host.devs[i]).enabled)
      continue;
  dest.s_addr = ((unsigned int) 0xFFFFFFFF);
  aodv_socket_send((struct AODV_msg *) new_rerr, dest,
     (sizeof(RERR) + (new_rerr->dest_count-1)*sizeof(RERR_udest)), 1, &(this_host.devs[i]));
     }
 }
    }
}

variable_types: rerrlen int

variable_types:
flags
unsigned int

variable_types: struct precursor { struct list_t { struct list_t *prev; } l; struct in_addr { unsigned int s_addr; } neighbor; } *

variable_types:
dest
struct in_addr { unsigned int s_addr; }

user_defined_types: struct RERR_udest { unsigned int dest_addr; unsigned int dest_seqno; }

user_defined_types: struct precursor { struct list_t l; struct in_addr neighbor; }


repo: frank-liu/aodv-multi-interface

decompiled_code:
__int64 __fastcall ifindex2devindex(int a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = this_host[11];
if ( (int)v1 <= 0 )
return 10LL;
result = 0LL;
while ( dev_indices[result] != a1 )
{
if ( ++result == v1 )
return 10LL;
}
return (unsigned int)result;
}

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

v1 = this_host[11];
if ( (int)v1 <= 0 )
return 10LL;
result = 0LL;
while ( dev_indices[result] != a1 )
{
if ( ++result == v1 )
return 10LL;
}
return (unsigned int)result;
}

original_code:
static inline unsigned int ifindex2devindex(unsigned int ifindex)
{
    int i;
    for (i = 0; i < this_host.nif; i++)
 if (dev_indices[i] == ifindex)
     return i;
    return 10;
}

variable_types:
ifindex
unsigned int

variable_types: i int

return_type: unsigned int


decompiled_code:
__int64 __fastcall neighbor_add(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rbp
__int64 result; // rax
const char *v7; // rax
struct timeval v8; // [rsp+0h] [rbp-28h] BYREF

v3 = a3;
gettimeofday(&v8, 0LL);
v4 = rt_table_find(a2);
if ( v4 )
{
v5 = v4;
result = *(unsigned __int16 *)(v4 + 34);
if ( (result & 1) != 0 )
return result;
result = rt_table_update(v5, a2, 1LL, *(unsigned int *)(v5 + 20), active_route_timeout, 1LL, result);
}
else
{
v7 = (const char *)ip_to_str(a2);
alog(7LL, 0LL, "neighbor_add", "%s new NEIGHBOR!", v7);
result = rt_table_insert(a2, a2, 1LL, 0LL, active_route_timeout, 1LL, 0LL, v3);
v5 = result;
}
if ( !llfeedback )
{
result = *(unsigned int *)(v5 + 168);
if ( (_DWORD)result )
result = hello_update_timeout(v5, &v8, 2000LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rbp
__int64 result; // rax
const char *v7; // rax
struct timeval v8; // [rsp+0h] [rbp-28h] BYREF

v3 = a3;
gettimeofday(&v8, 0LL);
v4 = rt_table_find(a2);
if ( v4 )
{
v5 = v4;
result = *(unsigned __int16 *)(v4 + 34);
if ( (result & 1) != 0 )
return result;
result = rt_table_update(v5, a2, 1LL, *(unsigned int *)(v5 + 20), active_route_timeout, 1LL, result);
}
else
{
v7 = (const char *)ip_to_str(a2);
alog(7LL, 0LL, "neighbor_add", "%s new NEIGHBOR!", v7);
result = rt_table_insert(a2, a2, 1LL, 0LL, active_route_timeout, 1LL, 0LL, v3);
v5 = result;
}
if ( !llfeedback )
{
result = *(unsigned int *)(v5 + 168);
if ( (_DWORD)result )
result = hello_update_timeout(v5, &v8, 2000LL);
}
return result;
}

original_code:
void neighbor_add(AODV_msg * aodv_msg, struct in_addr source,
      unsigned int ifindex)
{
    struct timeval now;
    rt_table_t *rt = ((void *)0);
    u_int32_t seqno = 0;
    gettimeofday(&now, ((void *)0));
    rt = rt_table_find(source);
    if (!rt) {
 alog(7, 0, __FUNCTION__, "%s new NEIGHBOR!", ip_to_str(source));
 rt = rt_table_insert(source, source, 1, 0,
        active_route_timeout, 1, 0, ifindex);
    } else {
 if (rt->flags & 0x1)
     return;
 if (rt->dest_seqno != 0)
     seqno = rt->dest_seqno;
 rt_table_update(rt, source, 1, seqno, active_route_timeout,
   1, rt->flags);
    }
    if (!llfeedback && rt->hello_timer.used)
 hello_update_timeout(rt, &now, 2 * 1000);
    return;
}

canonical_original_code:
void neighbor_add(struct AODV_msg *aodv_msg, struct in_addr source, unsigned int ifindex)
{
    struct timeval now;
    struct rt_table *rt = ((void *)0);
    unsigned int seqno = 0;
    gettimeofday(&now, ((void *)0));
    rt = rt_table_find(source);
    if (!rt) {
 alog(7, 0, __FUNCTION__, "%s new NEIGHBOR!", ip_to_str(source));
 rt = rt_table_insert(source, source, 1, 0,
        active_route_timeout, 1, 0, ifindex);
    } else {
 if (rt->flags & 0x1)
     return;
 if (rt->dest_seqno != 0)
     seqno = rt->dest_seqno;
 rt_table_update(rt, source, 1, seqno, active_route_timeout,
   1, rt->flags);
    }
    if (!llfeedback && rt->hello_timer.used)
 hello_update_timeout(rt, &now, 2 * 1000);
    return;
}

variable_types: struct AODV_msg { unsigned int type; } *

variable_types:
source
struct in_addr { unsigned int s_addr; }

variable_types: struct rt_table { struct list_t { struct list_t *prev; } l; struct in_addr { unsigned int s_addr; } dest_addr; unsigned int dest_seqno; unsigned int ifindex; struct in_addr next_hop; unsigned int hcnt; unsigned int flags; unsigned int state; struct timer { struct list_t l; int used; struct timeval { long tv_sec; long tv_usec; } timeout; void (*handler)(void *); void *data; } rt_timer; struct timer ack_timer; struct timer hello_timer; struct timeval last_hello_time; unsigned int hello_cnt; unsigned int hash; int nprec; struct list_t precursors; } *

variable_types:
seqno
unsigned int

return_type: void

user_defined_types: struct rt_table { struct list_t l; struct in_addr dest_addr; unsigned int dest_seqno; unsigned int ifindex; struct in_addr next_hop; unsigned int hcnt; unsigned int flags; unsigned int state; struct timer rt_timer; struct timer ack_timer; struct timer hello_timer; struct timeval last_hello_time; unsigned int hello_cnt; unsigned int hash; int nprec; struct list_t precursors; }

user_defined_types: struct timer { struct list_t l; int used; struct timeval timeout; void (*handler)(void *); void *data; }


decompiled_code:
void __fastcall neighbor_link_break(__int64 a1)
{
unsigned __int8 v2; // bl
__int64 v3; // rdi
const char *v4; // rax
unsigned int v5; // er14
__int64 v6; // r13
__int64 v7; // rbp
__int64 v8; // rbx
int v9; // eax
__int64 v10; // rdx
__int64 v11; // rsi
const char *v12; // rax
__int64 v13; // rax
char v14; // dl
unsigned __int64 v15; // rbx
const char *v16; // rax
const char *v17; // rax
__int64 v18; // rax
__int64 v19; // rax
unsigned int v20; // ebx
const char *v21; // rax
int v22; // eax
__int64 v23; // rcx
unsigned int v24; // [rsp+0h] [rbp-3Ch]

if ( !a1 )
return;
v2 = *(_BYTE *)(a1 + 32);
v3 = *(unsigned int *)(a1 + 16);
if ( v2 != 1 )
{
v16 = (const char *)ip_to_str(v3);
alog(7LL, 0LL, "neighbor_link_break", "%s is not a neighbor, hcnt=%d!!!", v16, v2);
return;
}
v4 = (const char *)ip_to_str(v3);
v5 = 0;
alog(7LL, 0LL, "neighbor_link_break", "Link %s down!", v4);
v6 = 0LL;
rt_table_invalidate(a1);
if ( !*(_DWORD *)(a1 + 232) )
goto LABEL_41;
if ( (*(_BYTE *)(a1 + 34) & 2) == 0 )
{
v19 = rerr_create(0LL, *(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20));
v20 = *(_DWORD *)(a1 + 20);
v6 = v19;
v21 = (const char *)ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "neighbor_link_break", "Added %s as unreachable, seqno=%lu", v21, v20);
if ( *(_DWORD *)(a1 + 232) == 1 )
v5 = *(_DWORD *)(*(_QWORD *)(a1 + 248) + 16LL);
LABEL_41:
if ( (*(_BYTE *)(a1 + 34) & 2) == 0 )
precursor_list_destroy(a1);
}
v7 = (unsigned int)((_DWORD)&rt_tbl + 8);
do
{
v8 = *(_QWORD *)(v7 + 8);
if ( v8 != v7 )
{
while ( 1 )
{
if ( *(_BYTE *)(v8 + 36) != 1 )
goto LABEL_8;
v9 = *(_DWORD *)(a1 + 16);
if ( *(_DWORD *)(v8 + 28) != v9 || v9 == *(_DWORD *)(v8 + 16) )
goto LABEL_8;
if ( (*(_BYTE *)(a1 + 34) & 2) != 0 && *(_BYTE *)(v8 + 32) <= 0xAu )
{
*(_WORD *)(v8 + 34) |= 2u;
v17 = (const char *)ip_to_str(*(unsigned int *)(v8 + 16));
alog(7LL, 0LL, "neighbor_link_break", "Marking %s for REPAIR", v17);
rt_table_invalidate(v8);
LABEL_8:
v8 = *(_QWORD *)(v8 + 8);
if ( v8 == v7 )
break;
}
else
{
rt_table_invalidate(v8);
if ( *(_DWORD *)(v8 + 232) )
{
v10 = *(unsigned int *)(v8 + 20);
v11 = *(unsigned int *)(v8 + 16);
if ( v6 )
{
rerr_add_udest(v6, v11, v10);
if ( v5 )
{
v18 = *(_QWORD *)(v8 + 248);
if ( v18 != v8 + 240 )
{
while ( *(_DWORD *)(v18 + 16) == v5 )
{
v18 = *(_QWORD *)(v18 + 8);
if ( v18 == v8 + 240 )
goto LABEL_17;
}
v5 = 0;
}
}
}
else
{
v6 = rerr_create(0LL, v11, v10);
if ( *(_DWORD *)(v8 + 232) == 1 )
v5 = *(_DWORD *)(*(_QWORD *)(v8 + 248) + 16LL);
}
LABEL_17:
v24 = *(_DWORD *)(v8 + 20);
v12 = (const char *)ip_to_str(*(unsigned int *)(v8 + 16));
alog(7LL, 0LL, "neighbor_link_break", "Added %s as unreachable, seqno=%lu", v12, v24);
}
precursor_list_destroy(v8);
v8 = *(_QWORD *)(v8 + 8);
if ( v8 == v7 )
break;
}
}
}
v7 += 16LL;
}
while ( (_DWORD)&rt_tbl + 1032 != v7 );
if ( v6 )
{
alog(7LL, 0LL, "neighbor_link_break", "RERR created, %d bytes.", 8LL * (*(unsigned __int8 *)(v6 + 3) - 1) + 12);
v13 = rt_table_find(v5);
v14 = *(_BYTE *)(v6 + 3);
if ( v13 && v14 == 1 && v5 )
{
v22 = ifindex2devindex(*(_DWORD *)(v13 + 24));
aodv_socket_send(v6, v5, 12LL, v23, &this_host[11 * v22 + 12]);
}
else if ( v14 )
{
v15 = (unsigned int)((_DWORD)this_host + 48);
do
{
if ( *(_DWORD *)v15 )
aodv_socket_send(v6, 0xFFFFFFFFLL, 8 * (unsigned int)*(unsigned __int8 *)(v6 + 3) + 4, 1LL, v15);
v15 += 44LL;
}
while ( (_DWORD)this_host + 488 != v15 );
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
unsigned __int8 v2; // bl
__int64 v3; // rdi
const char *v4; // rax
unsigned int v5; // er14
__int64 v6; // r13
__int64 v7; // rbp
__int64 v8; // rbx
int v9; // eax
__int64 v10; // rdx
__int64 v11; // rsi
const char *v12; // rax
__int64 v13; // rax
char v14; // dl
unsigned __int64 v15; // rbx
const char *v16; // rax
const char *v17; // rax
__int64 v18; // rax
__int64 v19; // rax
unsigned int v20; // ebx
const char *v21; // rax
int v22; // eax
__int64 v23; // rcx
unsigned int v24; // [rsp+0h] [rbp-3Ch]

if ( !a1 )
return;
v2 = *(_BYTE *)(a1 + 32);
v3 = *(unsigned int *)(a1 + 16);
if ( v2 != 1 )
{
v16 = (const char *)ip_to_str(v3);
alog(7LL, 0LL, "neighbor_link_break", "%s is not a neighbor, hcnt=%d!!!", v16, v2);
return;
}
v4 = (const char *)ip_to_str(v3);
v5 = 0;
alog(7LL, 0LL, "neighbor_link_break", "Link %s down!", v4);
v6 = 0LL;
rt_table_invalidate(a1);
if ( !*(_DWORD *)(a1 + 232) )
goto LABEL_41;
if ( (*(_BYTE *)(a1 + 34) & 2) == 0 )
{
v19 = rerr_create(0LL, *(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20));
v20 = *(_DWORD *)(a1 + 20);
v6 = v19;
v21 = (const char *)ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "neighbor_link_break", "Added %s as unreachable, seqno=%lu", v21, v20);
if ( *(_DWORD *)(a1 + 232) == 1 )
v5 = *(_DWORD *)(*(_QWORD *)(a1 + 248) + 16LL);
LABEL_41:
if ( (*(_BYTE *)(a1 + 34) & 2) == 0 )
precursor_list_destroy(a1);
}
v7 = (unsigned int)((_DWORD)&rt_tbl + 8);
do
{
v8 = *(_QWORD *)(v7 + 8);
if ( v8 != v7 )
{
while ( 1 )
{
if ( *(_BYTE *)(v8 + 36) != 1 )
goto LABEL_8;
v9 = *(_DWORD *)(a1 + 16);
if ( *(_DWORD *)(v8 + 28) != v9 || v9 == *(_DWORD *)(v8 + 16) )
goto LABEL_8;
if ( (*(_BYTE *)(a1 + 34) & 2) != 0 && *(_BYTE *)(v8 + 32) <= 0xAu )
{
*(_WORD *)(v8 + 34) |= 2u;
v17 = (const char *)ip_to_str(*(unsigned int *)(v8 + 16));
alog(7LL, 0LL, "neighbor_link_break", "Marking %s for REPAIR", v17);
rt_table_invalidate(v8);
LABEL_8:
v8 = *(_QWORD *)(v8 + 8);
if ( v8 == v7 )
break;
}
else
{
rt_table_invalidate(v8);
if ( *(_DWORD *)(v8 + 232) )
{
v10 = *(unsigned int *)(v8 + 20);
v11 = *(unsigned int *)(v8 + 16);
if ( v6 )
{
rerr_add_udest(v6, v11, v10);
if ( v5 )
{
v18 = *(_QWORD *)(v8 + 248);
if ( v18 != v8 + 240 )
{
while ( *(_DWORD *)(v18 + 16) == v5 )
{
v18 = *(_QWORD *)(v18 + 8);
if ( v18 == v8 + 240 )
goto LABEL_17;
}
v5 = 0;
}
}
}
else
{
v6 = rerr_create(0LL, v11, v10);
if ( *(_DWORD *)(v8 + 232) == 1 )
v5 = *(_DWORD *)(*(_QWORD *)(v8 + 248) + 16LL);
}
LABEL_17:
v24 = *(_DWORD *)(v8 + 20);
v12 = (const char *)ip_to_str(*(unsigned int *)(v8 + 16));
alog(7LL, 0LL, "neighbor_link_break", "Added %s as unreachable, seqno=%lu", v12, v24);
}
precursor_list_destroy(v8);
v8 = *(_QWORD *)(v8 + 8);
if ( v8 == v7 )
break;
}
}
}
v7 += 16LL;
}
while ( (_DWORD)&rt_tbl + 1032 != v7 );
if ( v6 )
{
alog(7LL, 0LL, "neighbor_link_break", "RERR created, %d bytes.", 8LL * (*(unsigned __int8 *)(v6 + 3) - 1) + 12);
v13 = rt_table_find(v5);
v14 = *(_BYTE *)(v6 + 3);
if ( v13 && v14 == 1 && v5 )
{
v22 = func0(*(_DWORD *)(v13 + 24));
aodv_socket_send(v6, v5, 12LL, v23, &this_host[11 * v22 + 12]);
}
else if ( v14 )
{
v15 = (unsigned int)((_DWORD)this_host + 48);
do
{
if ( *(_DWORD *)v15 )
aodv_socket_send(v6, 0xFFFFFFFFLL, 8 * (unsigned int)*(unsigned __int8 *)(v6 + 3) + 4, 1LL, v15);
v15 += 44LL;
}
while ( (_DWORD)this_host + 488 != v15 );
}
}
}

original_code:
void neighbor_link_break(rt_table_t * rt)
{
    RERR *rerr = ((void *)0);
    rt_table_t *rt_u;
    struct in_addr rerr_unicast_dest;
    int i;
    rerr_unicast_dest.s_addr = 0;
    if (!rt)
 return;
    if (rt->hcnt != 1) {
 alog(7, 0, __FUNCTION__, "%s is not a neighbor, hcnt=%d!!!", ip_to_str(rt->dest_addr), rt->hcnt);
 return;
    }
    alog(7, 0, __FUNCTION__, "Link %s down!", ip_to_str(rt->dest_addr));
    rt_table_invalidate(rt);
    if (rt->nprec && !(rt->flags & 0x2)) {
 rerr = rerr_create(0, rt->dest_addr, rt->dest_seqno);
 alog(7, 0, __FUNCTION__, "Added %s as unreachable, seqno=%lu", ip_to_str(rt->dest_addr), rt->dest_seqno);
 if (rt->nprec == 1)
     rerr_unicast_dest = ((precursor_t *)((rt->precursors).next))->neighbor;
    }
    if (!(rt->flags & 0x2))
 precursor_list_destroy(rt);
    for (i = 0; i < 64; i++) {
 list_t *pos;
 for (pos = (&rt_tbl.tbl[i])->next; pos != (&rt_tbl.tbl[i]); pos = pos->next) {
     rt_table_t *rt_u = (rt_table_t *) pos;
     if (rt_u->state == 1 &&
  rt_u->next_hop.s_addr == rt->dest_addr.s_addr &&
  rt_u->dest_addr.s_addr != rt->dest_addr.s_addr) {
  if ((rt->flags & 0x2) && rt_u->hcnt <= 3 * 35 / 10) {
      rt_u->flags |= 0x2;
      alog(7, 0, __FUNCTION__, "Marking %s for REPAIR", ip_to_str(rt_u->dest_addr));
      rt_table_invalidate(rt_u);
      continue;
  }
  rt_table_invalidate(rt_u);
  if (rt_u->nprec) {
      if (!rerr) {
   rerr =
       rerr_create(0, rt_u->dest_addr, rt_u->dest_seqno);
   if (rt_u->nprec == 1)
       rerr_unicast_dest =
    ((precursor_t *)((rt_u->precursors).next))->neighbor;
   alog(7, 0, __FUNCTION__, "Added %s as unreachable, seqno=%lu", ip_to_str(rt_u->dest_addr), rt_u->dest_seqno);
      } else {
   rerr_add_udest(rerr, rt_u->dest_addr, rt_u->dest_seqno);
   if (rerr_unicast_dest.s_addr) {
       list_t *pos2;
       for (pos2 = (&rt_u->precursors)->next; pos2 != (&rt_u->precursors); pos2 = pos2->next) {
    precursor_t *pr = (precursor_t *) pos2;
    if (pr->neighbor.s_addr !=
        rerr_unicast_dest.s_addr) {
        rerr_unicast_dest.s_addr = 0;
        break;
    }
       }
   }
   alog(7, 0, __FUNCTION__, "Added %s as unreachable, seqno=%lu", ip_to_str(rt_u->dest_addr), rt_u->dest_seqno);
      }
  }
  precursor_list_destroy(rt_u);
     }
 }
    }
    if (rerr) {
 alog(7, 0, __FUNCTION__, "RERR created, %d bytes.", (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)));
 rt_u = rt_table_find(rerr_unicast_dest);
 if (rt_u && rerr->dest_count == 1 && rerr_unicast_dest.s_addr)
     aodv_socket_send((AODV_msg *) rerr,
        rerr_unicast_dest,
        (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)), 1,
        &(this_host.devs[ifindex2devindex(rt_u->ifindex)]));
 else if (rerr->dest_count > 0) {
     for (i = 0; i < 10; i++) {
  struct in_addr dest;
  if (!(this_host.devs[i]).enabled)
      continue;
  dest.s_addr = ((in_addr_t) 0xFFFFFFFF);
  aodv_socket_send((AODV_msg *) rerr, dest,
     (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)), 1, &(this_host.devs[i]));
     }
 }
    }
}

canonical_original_code:
void neighbor_link_break(struct rt_table *rt)
{
    struct RERR *rerr = ((void *)0);
    struct rt_table *rt_u;
    struct in_addr rerr_unicast_dest;
    int i;
    rerr_unicast_dest.s_addr = 0;
    if (!rt)
 return;
    if (rt->hcnt != 1) {
 alog(7, 0, __FUNCTION__, "%s is not a neighbor, hcnt=%d!!!", ip_to_str(rt->dest_addr), rt->hcnt);
 return;
    }
    alog(7, 0, __FUNCTION__, "Link %s down!", ip_to_str(rt->dest_addr));
    rt_table_invalidate(rt);
    if (rt->nprec && !(rt->flags & 0x2)) {
 rerr = rerr_create(0, rt->dest_addr, rt->dest_seqno);
 alog(7, 0, __FUNCTION__, "Added %s as unreachable, seqno=%lu", ip_to_str(rt->dest_addr), rt->dest_seqno);
 if (rt->nprec == 1)
     rerr_unicast_dest = ((struct precursor *)((rt->precursors).next))->neighbor;
    }
    if (!(rt->flags & 0x2))
 precursor_list_destroy(rt);
    for (i = 0; i < 64; i++) {
 struct list_t *pos;
 for (pos = (&rt_tbl.tbl[i])->next; pos != (&rt_tbl.tbl[i]); pos = pos->next) {
     struct rt_table *rt_u = (rt_table_t *) pos;
     if (rt_u->state == 1 &&
  rt_u->next_hop.s_addr == rt->dest_addr.s_addr &&
  rt_u->dest_addr.s_addr != rt->dest_addr.s_addr) {
  if ((rt->flags & 0x2) && rt_u->hcnt <= 3 * 35 / 10) {
      rt_u->flags |= 0x2;
      alog(7, 0, __FUNCTION__, "Marking %s for REPAIR", ip_to_str(rt_u->dest_addr));
      rt_table_invalidate(rt_u);
      continue;
  }
  rt_table_invalidate(rt_u);
  if (rt_u->nprec) {
      if (!rerr) {
   rerr =
       rerr_create(0, rt_u->dest_addr, rt_u->dest_seqno);
   if (rt_u->nprec == 1)
       rerr_unicast_dest =
    ((struct precursor *)((rt_u->precursors).next))->neighbor;
   alog(7, 0, __FUNCTION__, "Added %s as unreachable, seqno=%lu", ip_to_str(rt_u->dest_addr), rt_u->dest_seqno);
      } else {
   rerr_add_udest(rerr, rt_u->dest_addr, rt_u->dest_seqno);
   if (rerr_unicast_dest.s_addr) {
       struct list_t *pos2;
       for (pos2 = (&rt_u->precursors)->next; pos2 != (&rt_u->precursors); pos2 = pos2->next) {
    struct precursor *pr = (precursor_t *) pos2;
    if (pr->neighbor.s_addr !=
        rerr_unicast_dest.s_addr) {
        rerr_unicast_dest.s_addr = 0;
        break;
    }
       }
   }
   alog(7, 0, __FUNCTION__, "Added %s as unreachable, seqno=%lu", ip_to_str(rt_u->dest_addr), rt_u->dest_seqno);
      }
  }
  precursor_list_destroy(rt_u);
     }
 }
    }
    if (rerr) {
 alog(7, 0, __FUNCTION__, "RERR created, %d bytes.", (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)));
 rt_u = rt_table_find(rerr_unicast_dest);
 if (rt_u && rerr->dest_count == 1 && rerr_unicast_dest.s_addr)
     aodv_socket_send((struct AODV_msg *) rerr,
        rerr_unicast_dest,
        (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)), 1,
        &(this_host.devs[ifindex2devindex(rt_u->ifindex)]));
 else if (rerr->dest_count > 0) {
     for (i = 0; i < 10; i++) {
  struct in_addr dest;
  if (!(this_host.devs[i]).enabled)
      continue;
  dest.s_addr = ((unsigned int) 0xFFFFFFFF);
  aodv_socket_send((struct AODV_msg *) rerr, dest,
     (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)), 1, &(this_host.devs[i]));
     }
 }
    }
}

variable_types: struct RERR { unsigned int type; unsigned int res1; unsigned int n; unsigned int res2; unsigned int dest_count; unsigned int dest_addr; unsigned int dest_seqno; } *

variable_types: struct list_t { struct list_t *prev; } *

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


original_code:
static inline long timeval_diff(struct timeval *t1, struct timeval *t2)
{
    long long res;
    if (!t1 || !t2)
 return -1;
    else {
 res = t1->tv_sec;
 res = ((res - t2->tv_sec) * 1000000 + t1->tv_usec - t2->tv_usec) / 1000;
 return (long) res;
    }
}

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

variable_types:
res
long long

return_type: long


decompiled_code:
void log_init()
{
if ( log_to_file )
{
log_file_fd = open("/var/log/aodvd.log", 578, 420LL);
if ( log_file_fd < 0 )
{
perror("open log file failed!");
exit(-1);
}
}
if ( rt_log_interval )
{
log_rt_fd = open("/var/log/aodvd.rtlog", 578, 420LL);
if ( log_rt_fd < 0 )
{
perror("open rt log file failed!");
exit(-1);
}
}
openlog(progname, 0, 24);
}

canonical_decompiled_code:
void func2()
{
if ( log_to_file )
{
log_file_fd = open("/var/log/aodvd.log", 578, 420LL);
if ( log_file_fd < 0 )
{
perror("open log file failed!");
exit(-1);
}
}
if ( rt_log_interval )
{
log_rt_fd = open("/var/log/aodvd.rtlog", 578, 420LL);
if ( log_rt_fd < 0 )
{
perror("open rt log file failed!");
exit(-1);
}
}
openlog(progname, 0, 24);
}


decompiled_code:
__int64 log_rt_table_init()
{
timer_init(&rt_log_timer, print_rt_table, 0LL);
return timer_set_timeout(&rt_log_timer, rt_log_interval);
}

canonical_decompiled_code:
__int64 func3()
{
timer_init(&rt_log_timer, print_rt_table, 0LL);
return timer_set_timeout(&rt_log_timer, rt_log_interval);
}

original_code:
void log_rt_table_init()
{
    timer_init(&rt_log_timer, & print_rt_table, ((void *)0));
    timer_set_timeout(&rt_log_timer, rt_log_interval);
}


decompiled_code:
int log_cleanup()
{
int result; // eax

result = log_to_file;
if ( log_to_file && log_file_fd )
{
result = close(log_file_fd);
if ( result < 0 )
result = fwrite("Could not close log_file_fd!\n", 1uLL, 0x1DuLL, stderr);
}
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax

result = log_to_file;
if ( log_to_file && log_file_fd )
{
result = close(log_file_fd);
if ( result < 0 )
result = fwrite("Could not close log_file_fd!\n", 1uLL, 0x1DuLL, stderr);
}
return result;
}

original_code:
void log_cleanup()
{
    if (log_to_file && log_file_fd) {
 if ( close(log_file_fd) < 0)
     fprintf(stderr, "Could not close log_file_fd!\n");
    }
}


decompiled_code:
void __fastcall write_to_log_file(void *buf, int a2)
{
if ( log_file_fd )
{
if ( a2 <= 0 )
{
fwrite("len=0\n", 1uLL, 6uLL, stderr);
}
else if ( write(log_file_fd, buf, a2) < 0 )
{
perror("Could not write to log file");
}
}
else
{
fwrite("Could not write to log file\n", 1uLL, 0x1CuLL, stderr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *buf, int a2)
{
if ( log_file_fd )
{
if ( a2 <= 0 )
{
fwrite("len=0\n", 1uLL, 6uLL, stderr);
}
else if ( write(log_file_fd, buf, a2) < 0 )
{
perror("Could not write to log file");
}
}
else
{
fwrite("Could not write to log file\n", 1uLL, 0x1CuLL, stderr);
}
}

original_code:
void write_to_log_file(char *msg, int len)
{
    if (!log_file_fd) {
 fprintf(stderr, "Could not write to log file\n");
 return;
    }
    if (len <= 0) {
 fprintf(stderr, "len=0\n");
 return;
    }
    if (write(log_file_fd, msg, len) < 0)
 perror("Could not write to log file");
}

variable_types:
msg
char *

variable_types: len int


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

v1 = a1 - 1;
if ( (unsigned int)v1 <= 2 )
return CSWTCH_47[v1];
sprintf(temp_9, "Unknown packet type %d", a1);
return temp_9;
}

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

v1 = a1 - 1;
if ( (unsigned int)v1 <= 2 )
return CSWTCH_47[v1];
sprintf(temp_9, "Unknown packet type %d", a1);
return temp_9;
}

original_code:
char *packet_type(u_int type)
{
    static char temp[50];
    switch (type) {
    case 1:
 return "AODV_RREQ";
    case 2:
 return "AODV_RREP";
    case 3:
 return "AODV_RERR";
    default:
 sprintf(temp, "Unknown packet type %d", type);
 return temp;
    }
}

canonical_original_code:
char *packet_type(unsigned int type)
{
    static char temp[50];
    switch (type) {
    case 1:
 return "AODV_RREQ";
    case 2:
 return "AODV_RREP";
    case 3:
 return "AODV_RERR";
    default:
 sprintf(temp, "Unknown packet type %d", type);
 return temp;
    }
}

variable_types:
type
unsigned int

variable_types:
temp
char [50]

return_type: char *


alog

decompiled_code:
void alog(int pri, int errnum, const char *a3, const char *a4, ...)
{
char *v6; // r12
struct tm *v7; // rax
int v8; // eax
int v9; // ebp
char *v10; // rax
int v11; // esi
struct timeval v12; // [rsp+0h] [rbp-108h] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-F0h] BYREF

va_start(arg, a4);
v6 = (char *)&unk_17C9;
if ( pri != 4 )
v6 = buffer_8;
arg[0].fp_offset = 48;
vsprintf(v6, a4, arg);
if ( log_to_file | debug )
{
gettimeofday(&v12, 0LL);
v7 = localtime(&v12.tv_sec);
v8 = sprintf(
log_buf_7,
"%02d:%02d:%02d.%03ld %s: %s",
(unsigned int)v7->tm_hour,
(unsigned int)v7->tm_min,
(unsigned int)v7->tm_sec,
v12.tv_usec / 1000,
a3,
v6);
v9 = v8;
if ( errnum )
{
v10 = strerror(errnum);
v11 = v9 + sprintf(&log_buf_7[v9], ": %s\n", v10);
if ( v11 <= 1024 )
{
LABEL_6:
if ( log_to_file )
write_to_log_file(log_buf_7, v11);
if ( debug )
printf("%s", log_buf_7);
goto LABEL_10;
}
}
else
{
v11 = v8 + 1;
*(_WORD *)&log_buf_7[v8] = 10;
if ( v8 + 1 <= 1024 )
goto LABEL_6;
}
fprintf(stderr, "alog(): buffer to small! len = %d\n", (unsigned int)v11);
}
LABEL_10:
if ( pri <= 5 )
{
if ( errnum )
{
*_errno_location() = errnum;
syslog(pri, "%s: %s: %m", a3, v6);
}
else
{
syslog(pri, "%s: %s", a3, v6);
}
if ( pri <= 3 )
exit(-1);
}
}

canonical_decompiled_code:
void func7(int pri, int errnum, const char *a3, const char *a4, ...)
{
char *v6; // r12
struct tm *v7; // rax
int v8; // eax
int v9; // ebp
char *v10; // rax
int v11; // esi
struct timeval v12; // [rsp+0h] [rbp-108h] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-F0h] BYREF

va_start(arg, a4);
v6 = (char *)&unk_17C9;
if ( pri != 4 )
v6 = buffer_8;
arg[0].fp_offset = 48;
vsprintf(v6, a4, arg);
if ( log_to_file | debug )
{
gettimeofday(&v12, 0LL);
v7 = localtime(&v12.tv_sec);
v8 = sprintf(
log_buf_7,
"%02d:%02d:%02d.%03ld %s: %s",
(unsigned int)v7->tm_hour,
(unsigned int)v7->tm_min,
(unsigned int)v7->tm_sec,
v12.tv_usec / 1000,
a3,
v6);
v9 = v8;
if ( errnum )
{
v10 = strerror(errnum);
v11 = v9 + sprintf(&log_buf_7[v9], ": %s\n", v10);
if ( v11 <= 1024 )
{
LABEL_6:
if ( log_to_file )
func5(log_buf_7, v11);
if ( debug )
printf("%s", log_buf_7);
goto LABEL_10;
}
}
else
{
v11 = v8 + 1;
*(_WORD *)&log_buf_7[v8] = 10;
if ( v8 + 1 <= 1024 )
goto LABEL_6;
}
fprintf(stderr, "alog(): buffer to small! len = %d\n", (unsigned int)v11);
}
LABEL_10:
if ( pri <= 5 )
{
if ( errnum )
{
*_errno_location() = errnum;
syslog(pri, "%s: %s: %m", a3, v6);
}
else
{
syslog(pri, "%s: %s", a3, v6);
}
if ( pri <= 3 )
exit(-1);
}
}

original_code:
void alog(int type, int errnum, const char *function, char *format,
     ...)
{
    va_list ap;
    static char buffer[256] = "";
    static char log_buf[1024];
    char *msg;
    struct timeval now;
    struct tm *time;
    int len = 0;
    __builtin_va_start(ap,format);
    if (type == 4)
 msg = &buffer[9];
    else
 msg = buffer;
    vsprintf(msg, format, ap);
    __builtin_va_end(ap);
    if (!debug && !log_to_file)
 goto syslog;
    gettimeofday(&now, ((void *)0));
    time = localtime(&now.tv_sec);
    len += sprintf(log_buf + len, "%02d:%02d:%02d.%03ld %s: %s", time->tm_hour,
     time->tm_min, time->tm_sec, now.tv_usec / 1000, function,
     msg);
    if (errnum == 0)
 len += sprintf(log_buf + len, "\n");
    else
 len += sprintf(log_buf + len, ": %s\n", strerror(errnum));
    if (len > 1024) {
 fprintf(stderr, "alog(): buffer to small! len = %d\n", len);
 goto syslog;
    }
    if (log_to_file)
 write_to_log_file(log_buf, len);
    if (debug)
            printf("%s", log_buf);
  syslog:
    if (type <= 5) {
 if (errnum != 0) {
     (*__errno_location ()) = errnum;
     syslog(type, "%s: %s: %m", function, msg);
 } else
     syslog(type, "%s: %s", function, msg);
    }
    if (type <= 3)
 exit(-1);
}

canonical_original_code:
void alog(int type, int errnum, char *function, char *format, ...)
{
    __builtin_va_list ap;
    static char buffer[256] = "";
    static char log_buf[1024];
    char *msg;
    struct timeval now;
    struct tm *time;
    int len = 0;
    __builtin_va_start(ap,format);
    if (type == 4)
 msg = &buffer[9];
    else
 msg = buffer;
    vsprintf(msg, format, ap);
    __builtin_va_end(ap);
    if (!debug && !log_to_file)
 goto syslog;
    gettimeofday(&now, ((void *)0));
    time = localtime(&now.tv_sec);
    len += sprintf(log_buf + len, "%02d:%02d:%02d.%03ld %s: %s", time->tm_hour,
     time->tm_min, time->tm_sec, now.tv_usec / 1000, function,
     msg);
    if (errnum == 0)
 len += sprintf(log_buf + len, "\n");
    else
 len += sprintf(log_buf + len, ": %s\n", strerror(errnum));
    if (len > 1024) {
 fprintf(stderr, "alog(): buffer to small! len = %d\n", len);
 goto syslog;
    }
    if (log_to_file)
 write_to_log_file(log_buf, len);
    if (debug)
            printf("%s", log_buf);
  syslog:
    if (type <= 5) {
 if (errnum != 0) {
     (*__errno_location ()) = errnum;
     syslog(type, "%s: %s: %m", function, msg);
 } else
     syslog(type, "%s: %s", function, msg);
    }
    if (type <= 3)
 exit(-1);
}

variable_types: type int

variable_types: errnum int

variable_types:
function
char *

variable_types:
format
char *

variable_types:
buffer
char [256]

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

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


original_code:
char * rreq_flags_to_str(RREQ * rreq)
{
    static char buf[5];
    int len = 0;
    char *str;
    if (rreq->j)
 buf[len++] = 'J';
    if (rreq->r)
 buf[len++] = 'R';
    if (rreq->g)
 buf[len++] = 'G';
    if (rreq->d)
 buf[len++] = 'D';
    buf[len] = '\0';
    str = buf;
    return str;
}

canonical_original_code:
char *rreq_flags_to_str(struct RREQ *rreq)
{
    static char buf[5];
    int len = 0;
    char *str;
    if (rreq->j)
 buf[len++] = 'J';
    if (rreq->r)
 buf[len++] = 'R';
    if (rreq->g)
 buf[len++] = 'G';
    if (rreq->d)
 buf[len++] = 'D';
    buf[len] = '\0';
    str = buf;
    return str;
}

variable_types: struct RREQ { unsigned int type; unsigned int res1; unsigned int d; unsigned int g; unsigned int r; unsigned int j; unsigned int res2; unsigned int hcnt; unsigned int rreq_id; unsigned int dest_addr; unsigned int dest_seqno; unsigned int orig_addr; unsigned int orig_seqno; } *

variable_types:
buf
char [5]

variable_types:
str
char *


original_code:
char * rrep_flags_to_str(RREP * rrep)
{
    static char buf[3];
    int len = 0;
    char *str;
    if (rrep->r)
 buf[len++] = 'R';
    if (rrep->a)
 buf[len++] = 'A';
    buf[len] = '\0';
    str = buf;
    return str;
}

canonical_original_code:
char *rrep_flags_to_str(struct RREP *rrep)
{
    static char buf[3];
    int len = 0;
    char *str;
    if (rrep->r)
 buf[len++] = 'R';
    if (rrep->a)
 buf[len++] = 'A';
    buf[len] = '\0';
    str = buf;
    return str;
}

variable_types: struct RREP { unsigned int type; unsigned int res1; unsigned int a; unsigned int r; unsigned int prefix; unsigned int res2; unsigned int hcnt; unsigned int dest_addr; unsigned int dest_seqno; unsigned int orig_addr; unsigned int lifetime; } *

variable_types:
buf
char [3]


original_code:
char * rt_flags_to_str(u_int16_t flags)
{
    static char buf[5];
    int len = 0;
    char *str;
    if (flags & 0x1)
 buf[len++] = 'U';
    if (flags & 0x2)
 buf[len++] = 'R';
    if (flags & 0x8)
 buf[len++] = 'I';
    if (flags & 0x10)
 buf[len++] = 'G';
    buf[len] = '\0';
    str = buf;
    return str;
}

canonical_original_code:
char *rt_flags_to_str(unsigned int flags)
{
    static char buf[5];
    int len = 0;
    char *str;
    if (flags & 0x1)
 buf[len++] = 'U';
    if (flags & 0x2)
 buf[len++] = 'R';
    if (flags & 0x8)
 buf[len++] = 'I';
    if (flags & 0x10)
 buf[len++] = 'G';
    buf[len] = '\0';
    str = buf;
    return str;
}

variable_types:
flags
unsigned int


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

result = "VAL";
if ( a1 != 1 )
{
result = "INV";
if ( a1 )
result = "?";
}
return result;
}

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

result = "VAL";
if ( a1 != 1 )
{
result = "INV";
if ( a1 )
result = "?";
}
return result;
}

original_code:
char * state_to_str(u_int8_t state)
{
    if (state == 1)
 return "VAL";
    else if (state == 0)
 return "INV";
    else
 return "?";
}

canonical_original_code:
char *state_to_str(unsigned int state)
{
    if (state == 1)
 return "VAL";
    else if (state == 0)
 return "INV";
    else
 return "?";
}

variable_types:
state
unsigned int


decompiled_code:
char *__fastcall ip_to_str(struct in_addr a1)
{
char *v1; // rax
int v2; // ebx
char *result; // rax

v1 = inet_ntoa(a1);
v2 = index_1 + 16;
result = strcpy(&buf_0[index_1], v1);
index_1 = v2 % 64;
return result;
}

canonical_decompiled_code:
char *__fastcall func12(struct in_addr a1)
{
char *v1; // rax
int v2; // ebx
char *result; // rax

v1 = inet_ntoa(a1);
v2 = index_1 + 16;
result = strcpy(&buf_0[index_1], v1);
index_1 = v2 % 64;
return result;
}

original_code:
char * ip_to_str(struct in_addr addr)
{
    static char buf[16 * 4];
    static int index = 0;
    char *str;
    strcpy(&buf[index], inet_ntoa(addr));
    str = &buf[index];
    index += 16;
    index %= 64;
    return str;
}

canonical_original_code:
char *ip_to_str(struct in_addr addr)
{
    static char buf[-1];
    static int index = 0;
    char *str;
    strcpy(&buf[index], inet_ntoa(addr));
    str = &buf[index];
    index += 16;
    index %= 64;
    return str;
}

variable_types:
addr
struct in_addr { unsigned int s_addr; }

variable_types:
buf
char [-1]

variable_types: index int


decompiled_code:
void __fastcall log_pkt_fields(__int64 a1)
{
char v1; // al
struct in_addr v2; // er13
struct in_addr v3; // ebp
char *v4; // rax
const char *v5; // rcx
unsigned int v6; // er12
char *v7; // rax
unsigned int v8; // ebx
char *v9; // rax
struct in_addr v10; // er13
struct in_addr v11; // ebp
char *v12; // rax
__int64 v13; // rcx
__int64 v14; // r9
unsigned int v15; // er12
char *v16; // rax
unsigned int v17; // ebx
char *v18; // rax
const char *v19; // r9

v1 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 2 )
{
v2.s_addr = *(_DWORD *)(a1 + 4);
v3.s_addr = *(_DWORD *)(a1 + 12);
v4 = rrep_flags_to_str(a1);
alog(7, 0, "log_pkt_fields", v5, v4);
v6 = _bswap_32(*(_DWORD *)(a1 + 8));
v7 = ip_to_str(v2);
alog(7, 0, "log_pkt_fields", "rrep->dest_addr:%s rrep->dest_seqno=%d", v7, v6);
v8 = _bswap_32(*(_DWORD *)(a1 + 16));
v9 = ip_to_str(v3);
alog(7, 0, "log_pkt_fields", "rrep->orig_addr:%s rrep->lifetime=%d", v9, v8);
}
else if ( v1 == 3 )
{
v19 = "N";
if ( *(char *)(a1 + 1) >= 0 )
v19 = "-";
alog(7, 0, "log_pkt_fields", "rerr->dest_count:%d rerr->flags=%s", *(unsigned __int8 *)(a1 + 3), v19);
}
else if ( v1 == 1 )
{
v10.s_addr = *(_DWORD *)(a1 + 8);
v11.s_addr = *(_DWORD *)(a1 + 16);
_bswap_32(*(_DWORD *)(a1 + 4));
v12 = rreq_flags_to_str(a1);
alog(7, 0, "log_pkt_fields", "rreq->flags:%s rreq->hopcount=%d rreq->rreq_id=%ld", v12, v14, v13);
v15 = _bswap_32(*(_DWORD *)(a1 + 12));
v16 = ip_to_str(v10);
alog(7, 0, "log_pkt_fields", "rreq->dest_addr:%s rreq->dest_seqno=%lu", v16, v15);
v17 = _bswap_32(*(_DWORD *)(a1 + 20));
v18 = ip_to_str(v11);
alog(7, 0, "log_pkt_fields", "rreq->orig_addr:%s rreq->orig_seqno=%ld", v18, v17);
}
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1)
{
char v1; // al
struct in_addr v2; // er13
struct in_addr v3; // ebp
char *v4; // rax
const char *v5; // rcx
unsigned int v6; // er12
char *v7; // rax
unsigned int v8; // ebx
char *v9; // rax
struct in_addr v10; // er13
struct in_addr v11; // ebp
char *v12; // rax
__int64 v13; // rcx
__int64 v14; // r9
unsigned int v15; // er12
char *v16; // rax
unsigned int v17; // ebx
char *v18; // rax
const char *v19; // r9

v1 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 2 )
{
v2.s_addr = *(_DWORD *)(a1 + 4);
v3.s_addr = *(_DWORD *)(a1 + 12);
v4 = func9(a1);
func7(7, 0, "log_pkt_fields", v5, v4);
v6 = func1(*(_DWORD *)(a1 + 8));
v7 = func12(v2);
func7(7, 0, "log_pkt_fields", "rrep->dest_addr:%s rrep->dest_seqno=%d", v7, v6);
v8 = func1(*(_DWORD *)(a1 + 16));
v9 = func12(v3);
func7(7, 0, "log_pkt_fields", "rrep->orig_addr:%s rrep->lifetime=%d", v9, v8);
}
else if ( v1 == 3 )
{
v19 = "N";
if ( *(char *)(a1 + 1) >= 0 )
v19 = "-";
func7(7, 0, "log_pkt_fields", "rerr->dest_count:%d rerr->flags=%s", *(unsigned __int8 *)(a1 + 3), v19);
}
else if ( v1 == 1 )
{
v10.s_addr = *(_DWORD *)(a1 + 8);
v11.s_addr = *(_DWORD *)(a1 + 16);
func1(*(_DWORD *)(a1 + 4));
v12 = func8(a1);
func7(7, 0, "log_pkt_fields", "rreq->flags:%s rreq->hopcount=%d rreq->rreq_id=%ld", v12, v14, v13);
v15 = func1(*(_DWORD *)(a1 + 12));
v16 = func12(v10);
func7(7, 0, "log_pkt_fields", "rreq->dest_addr:%s rreq->dest_seqno=%lu", v16, v15);
v17 = func1(*(_DWORD *)(a1 + 20));
v18 = func12(v11);
func7(7, 0, "log_pkt_fields", "rreq->orig_addr:%s rreq->orig_seqno=%ld", v18, v17);
}
}

original_code:
void log_pkt_fields(AODV_msg * msg)
{
    RREQ *rreq;
    RREP *rrep;
    RERR *rerr;
    struct in_addr dest, orig;
    switch (msg->type) {
    case 1:
 rreq = (RREQ *) msg;
 dest.s_addr = rreq->dest_addr;
 orig.s_addr = rreq->orig_addr;
 alog(7, 0, __FUNCTION__, "rreq->flags:%s rreq->hopcount=%d rreq->rreq_id=%ld", rreq_flags_to_str(rreq), rreq->hcnt, ntohl(rreq->rreq_id));
 alog(7, 0, __FUNCTION__, "rreq->dest_addr:%s rreq->dest_seqno=%lu", ip_to_str(dest), ntohl(rreq->dest_seqno));
 alog(7, 0, __FUNCTION__, "rreq->orig_addr:%s rreq->orig_seqno=%ld", ip_to_str(orig), ntohl(rreq->orig_seqno));
 break;
    case 2:
 rrep = (RREP *) msg;
 dest.s_addr = rrep->dest_addr;
 orig.s_addr = rrep->orig_addr;
 alog(7, 0, __FUNCTION__, "rrep->flags:%s rrep->hcnt=%d", rrep_flags_to_str(rrep), rrep->hcnt);
 alog(7, 0, __FUNCTION__, "rrep->dest_addr:%s rrep->dest_seqno=%d", ip_to_str(dest), ntohl(rrep->dest_seqno));
 alog(7, 0, __FUNCTION__, "rrep->orig_addr:%s rrep->lifetime=%d", ip_to_str(orig), ntohl(rrep->lifetime));
 break;
    case 3:
 rerr = (RERR *) msg;
 alog(7, 0, __FUNCTION__, "rerr->dest_count:%d rerr->flags=%s", rerr->dest_count, rerr->n ? "N" : "-");
 break;
    }
}

canonical_original_code:
void log_pkt_fields(struct AODV_msg *msg)
{
    struct RREQ *rreq;
    struct RREP *rrep;
    struct RERR *rerr;
    struct in_addr dest; struct in_addr orig;
    switch (msg->type) {
    case 1:
 rreq = (struct RREQ *) msg;
 dest.s_addr = rreq->dest_addr;
 orig.s_addr = rreq->orig_addr;
 alog(7, 0, __FUNCTION__, "rreq->flags:%s rreq->hopcount=%d rreq->rreq_id=%ld", rreq_flags_to_str(rreq), rreq->hcnt, ntohl(rreq->rreq_id));
 alog(7, 0, __FUNCTION__, "rreq->dest_addr:%s rreq->dest_seqno=%lu", ip_to_str(dest), ntohl(rreq->dest_seqno));
 alog(7, 0, __FUNCTION__, "rreq->orig_addr:%s rreq->orig_seqno=%ld", ip_to_str(orig), ntohl(rreq->orig_seqno));
 break;
    case 2:
 rrep = (struct RREP *) msg;
 dest.s_addr = rrep->dest_addr;
 orig.s_addr = rrep->orig_addr;
 alog(7, 0, __FUNCTION__, "rrep->flags:%s rrep->hcnt=%d", rrep_flags_to_str(rrep), rrep->hcnt);
 alog(7, 0, __FUNCTION__, "rrep->dest_addr:%s rrep->dest_seqno=%d", ip_to_str(dest), ntohl(rrep->dest_seqno));
 alog(7, 0, __FUNCTION__, "rrep->orig_addr:%s rrep->lifetime=%d", ip_to_str(orig), ntohl(rrep->lifetime));
 break;
    case 3:
 rerr = (struct RERR *) msg;
 alog(7, 0, __FUNCTION__, "rerr->dest_count:%d rerr->flags=%s", rerr->dest_count, rerr->n ? "N" : "-");
 break;
    }
}

variable_types: struct AODV_msg { unsigned int type; } *

variable_types: struct RERR { unsigned int type; unsigned int res1; unsigned int n; unsigned int res2; unsigned int dest_count; unsigned int dest_addr; unsigned int dest_seqno; } *

variable_types:
dest
struct in_addr { unsigned int s_addr; }

variable_types:
orig
struct in_addr { unsigned int s_addr; }

user_defined_types: struct RREQ { unsigned int type; unsigned int res1; unsigned int d; unsigned int g; unsigned int r; unsigned int j; unsigned int res2; unsigned int hcnt; unsigned int rreq_id; unsigned int dest_addr; unsigned int dest_seqno; unsigned int orig_addr; unsigned int orig_seqno; }

user_defined_types: struct RREP { unsigned int type; unsigned int res1; unsigned int a; unsigned int r; unsigned int prefix; unsigned int res2; unsigned int hcnt; unsigned int dest_addr; unsigned int dest_seqno; unsigned int orig_addr; unsigned int lifetime; }


decompiled_code:
char *devs_ip_to_str()
{
int v0; // ebp
__int64 i; // rbx
char *v2; // rax

v0 = 0;
for ( i = 0LL; i != 10; ++i )
{
if ( this_host[11 * i + 12] )
{
v2 = ip_to_str((struct in_addr)this_host[11 * (int)i + 20]);
v0 += sprintf(&buf_2[v0], "%s,", v2);
}
}
return buf_2;
}

canonical_decompiled_code:
char *func14()
{
int v0; // ebp
__int64 i; // rbx
char *v2; // rax

v0 = 0;
for ( i = 0LL; i != 10; ++i )
{
if ( this_host[11 * i + 12] )
{
v2 = func12((struct in_addr)this_host[11 * (int)i + 20]);
v0 += sprintf(&buf_2[v0], "%s,", v2);
}
}
return buf_2;
}

original_code:
char * devs_ip_to_str()
{
    static char buf[10 * 16];
    char *str;
    int i, index = 0;
    for (i = 0; i < 10; i++) {
 if (!(this_host.devs[i]).enabled)
     continue;
 index += sprintf(buf + index, "%s,", ip_to_str((this_host.devs[i]).ipaddr));
    }
    str = buf;
    return str;
}

canonical_original_code:
char *devs_ip_to_str()
{
    static char buf[-1];
    char *str;
    int i; int index = 0;
    for (i = 0; i < 10; i++) {
 if (!(this_host.devs[i]).enabled)
     continue;
 index += sprintf(buf + index, "%s,", ip_to_str((this_host.devs[i]).ipaddr));
    }
    str = buf;
    return str;
}

variable_types: i int


decompiled_code:
__int64 print_rt_table()
{
__int64 v1; // r14
struct tm *v2; // rax
__int64 v3; // r13
__int64 v4; // r12
struct tm *v5; // rbx
__int64 v6; // rbp
char *v7; // rax
int v8; // edx
int v9; // ebx
__int64 i; // rbp
struct in_addr *v11; // rax
__int64 v12; // r15
__int64 v13; // rsi
char *v14; // r12
char *v15; // rax
unsigned __int8 v16; // r15
char *v17; // rax
size_t v18; // rdx
__int64 v19; // rdx
__int64 v20; // rsi
char *v21; // rax
unsigned __int8 v22; // r12
char *v23; // rax
int v24; // eax
__int64 v25; // r12
char *v26; // rax
int v27; // edx
const char *v28; // [rsp+0h] [rbp-8C8h]
char *v29; // [rsp+0h] [rbp-8C8h]
char *v30; // [rsp+8h] [rbp-8C0h]
char *v31; // [rsp+8h] [rbp-8C0h]
const char *v32; // [rsp+10h] [rbp-8B8h]
const char *v33; // [rsp+10h] [rbp-8B8h]
char *v34; // [rsp+18h] [rbp-8B0h]
const char *v35; // [rsp+20h] [rbp-8A8h]
char v36[11]; // [rsp+35h] [rbp-893h] BYREF
struct timeval tv; // [rsp+40h] [rbp-888h] BYREF
char ifname[64]; // [rsp+50h] [rbp-878h] BYREF
char s[2104]; // [rsp+90h] [rbp-838h] BYREF

if ( rt_tbl[0] )
{
v1 = (unsigned int)((_DWORD)rt_tbl + 8);
gettimeofday(&tv, 0LL);
v2 = localtime(&tv.tv_sec);
v3 = (unsigned int)rt_tbl[1];
v4 = (unsigned int)rt_tbl[0];
v5 = v2;
v6 = (unsigned int)this_host[0];
v7 = devs_ip_to_str();
LODWORD(v5) = sprintf(
s,
"# Time: %02d:%02d:%02d.%03ld IP: %s seqno: %u entries/active: %u/%u\n",
(unsigned int)v5->tm_hour,
(unsigned int)v5->tm_min,
(unsigned int)v5->tm_sec,
tv.tv_usec / 1000,
v7,
v6,
v4,
v3);
sprintf(
&s[(int)v5],
"%-15s %-15s %-3s %-3s %-5s %-6s %-5s %-5s %-15s\n",
"Destination",
"Next hop",
"HC",
"St.",
"Seqno",
"Expire",
"Flags",
"Iface",
"Precursors");
v8 = (_DWORD)v5 + 81;
v9 = 0;
write(log_rt_fd, s, v8);
do
{
for ( i = *(_QWORD *)(v1 + 8); v1 != i; i = *(_QWORD *)(i + 8) )
{
v19 = *(unsigned int *)(i + 20);
if ( (_DWORD)v19 )
sprintf(v36, "%u", v19);
else
*(_WORD *)v36 = 45;
v11 = *(struct in_addr **)(i + 248);
v12 = i + 240;
if ( (struct in_addr *)(i + 240) == v11 )
{
v13 = 0LL;
v14 = if_indextoname(*(_DWORD *)(i + 24), ifname);
v15 = rt_flags_to_str(*(_WORD *)(i + 34));
v16 = *(_BYTE *)(i + 32);
v28 = v15;
if ( v16 != 0xFF )
v13 = timeval_diff((_QWORD *)(i + 64), &tv);
v32 = state_to_str(*(_BYTE *)(i + 36));
v30 = ip_to_str(*(struct in_addr *)(i + 28));
v17 = ip_to_str(*(struct in_addr *)(i + 16));
v9 += sprintf(&s[v9], "%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s\n", v17, v30, v16, v32, v36, v13, v28, v14);
}
else
{
v29 = ip_to_str(v11[4]);
v20 = 0LL;
v31 = if_indextoname(*(_DWORD *)(i + 24), ifname);
v21 = rt_flags_to_str(*(_WORD *)(i + 34));
v22 = *(_BYTE *)(i + 32);
v33 = v21;
if ( v22 != 0xFF )
v20 = timeval_diff((_QWORD *)(i + 64), &tv);
v35 = state_to_str(*(_BYTE *)(i + 36));
v34 = ip_to_str(*(struct in_addr *)(i + 28));
v23 = ip_to_str(*(struct in_addr *)(i + 16));
v24 = sprintf(
&s[v9],
"%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s %-15s\n",
v23,
v34,
v22,
v35,
v36,
v20,
v33,
v31,
v29);
v25 = *(_QWORD *)(i + 248);
for ( v9 += v24; v12 != v25; v25 = *(_QWORD *)(v25 + 8) )
{
if ( v12 != *(_QWORD *)v25 )
{
v26 = ip_to_str(*(struct in_addr *)(v25 + 16));
v27 = sprintf(&s[v9], "%64s %-15s\n", " ", v26) + v9;
v9 = 0;
write(log_rt_fd, s, v27);
}
}
}
if ( v9 > 0 )
{
v18 = v9;
v9 = 0;
write(log_rt_fd, s, v18);
}
}
v1 += 16LL;
}
while ( (_DWORD)rt_tbl + 1032 != v1 );
}
return timer_set_timeout(&rt_log_timer, rt_log_interval);
}

canonical_decompiled_code:
__int64 func15()
{
__int64 v1; // r14
struct tm *v2; // rax
__int64 v3; // r13
__int64 v4; // r12
struct tm *v5; // rbx
__int64 v6; // rbp
char *v7; // rax
int v8; // edx
int v9; // ebx
__int64 i; // rbp
struct in_addr *v11; // rax
__int64 v12; // r15
__int64 v13; // rsi
char *v14; // r12
char *v15; // rax
unsigned __int8 v16; // r15
char *v17; // rax
size_t v18; // rdx
__int64 v19; // rdx
__int64 v20; // rsi
char *v21; // rax
unsigned __int8 v22; // r12
char *v23; // rax
int v24; // eax
__int64 v25; // r12
char *v26; // rax
int v27; // edx
const char *v28; // [rsp+0h] [rbp-8C8h]
char *v29; // [rsp+0h] [rbp-8C8h]
char *v30; // [rsp+8h] [rbp-8C0h]
char *v31; // [rsp+8h] [rbp-8C0h]
const char *v32; // [rsp+10h] [rbp-8B8h]
const char *v33; // [rsp+10h] [rbp-8B8h]
char *v34; // [rsp+18h] [rbp-8B0h]
const char *v35; // [rsp+20h] [rbp-8A8h]
char v36[11]; // [rsp+35h] [rbp-893h] BYREF
struct timeval tv; // [rsp+40h] [rbp-888h] BYREF
char ifname[64]; // [rsp+50h] [rbp-878h] BYREF
char s[2104]; // [rsp+90h] [rbp-838h] BYREF

if ( rt_tbl[0] )
{
v1 = (unsigned int)((_DWORD)rt_tbl + 8);
gettimeofday(&tv, 0LL);
v2 = localtime(&tv.tv_sec);
v3 = (unsigned int)rt_tbl[1];
v4 = (unsigned int)rt_tbl[0];
v5 = v2;
v6 = (unsigned int)this_host[0];
v7 = func14();
LODWORD(v5) = sprintf(
s,
"# Time: %02d:%02d:%02d.%03ld IP: %s seqno: %u entries/active: %u/%u\n",
(unsigned int)v5->tm_hour,
(unsigned int)v5->tm_min,
(unsigned int)v5->tm_sec,
tv.tv_usec / 1000,
v7,
v6,
v4,
v3);
sprintf(
&s[(int)v5],
"%-15s %-15s %-3s %-3s %-5s %-6s %-5s %-5s %-15s\n",
"Destination",
"Next hop",
"HC",
"St.",
"Seqno",
"Expire",
"Flags",
"Iface",
"Precursors");
v8 = (_DWORD)v5 + 81;
v9 = 0;
write(log_rt_fd, s, v8);
do
{
for ( i = *(_QWORD *)(v1 + 8); v1 != i; i = *(_QWORD *)(i + 8) )
{
v19 = *(unsigned int *)(i + 20);
if ( (_DWORD)v19 )
sprintf(v36, "%u", v19);
else
*(_WORD *)v36 = 45;
v11 = *(struct in_addr **)(i + 248);
v12 = i + 240;
if ( (struct in_addr *)(i + 240) == v11 )
{
v13 = 0LL;
v14 = if_indextoname(*(_DWORD *)(i + 24), ifname);
v15 = func10(*(_WORD *)(i + 34));
v16 = *(_BYTE *)(i + 32);
v28 = v15;
if ( v16 != 0xFF )
v13 = func0((_QWORD *)(i + 64), &tv);
v32 = func11(*(_BYTE *)(i + 36));
v30 = func12(*(struct in_addr *)(i + 28));
v17 = func12(*(struct in_addr *)(i + 16));
v9 += sprintf(&s[v9], "%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s\n", v17, v30, v16, v32, v36, v13, v28, v14);
}
else
{
v29 = func12(v11[4]);
v20 = 0LL;
v31 = if_indextoname(*(_DWORD *)(i + 24), ifname);
v21 = func10(*(_WORD *)(i + 34));
v22 = *(_BYTE *)(i + 32);
v33 = v21;
if ( v22 != 0xFF )
v20 = func0((_QWORD *)(i + 64), &tv);
v35 = func11(*(_BYTE *)(i + 36));
v34 = func12(*(struct in_addr *)(i + 28));
v23 = func12(*(struct in_addr *)(i + 16));
v24 = sprintf(
&s[v9],
"%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s %-15s\n",
v23,
v34,
v22,
v35,
v36,
v20,
v33,
v31,
v29);
v25 = *(_QWORD *)(i + 248);
for ( v9 += v24; v12 != v25; v25 = *(_QWORD *)(v25 + 8) )
{
if ( v12 != *(_QWORD *)v25 )
{
v26 = func12(*(struct in_addr *)(v25 + 16));
v27 = sprintf(&s[v9], "%64s %-15s\n", " ", v26) + v9;
v9 = 0;
write(log_rt_fd, s, v27);
}
}
}
if ( v9 > 0 )
{
v18 = v9;
v9 = 0;
write(log_rt_fd, s, v18);
}
}
v1 += 16LL;
}
while ( (_DWORD)rt_tbl + 1032 != v1 );
}
return timer_set_timeout(&rt_log_timer, rt_log_interval);
}

original_code:
void print_rt_table(void *arg)
{
    char rt_buf[2048], ifname[64], seqno_str[11];
    int len = 0;
    int i = 0;
    struct timeval now;
    struct tm *time;
    ssize_t written;
    if (rt_tbl.num_entries == 0)
 goto schedule;
    gettimeofday(&now, ((void *)0));
    time = localtime(&now.tv_sec);
    len +=
 sprintf(rt_buf,
  "# Time: %02d:%02d:%02d.%03ld IP: %s seqno: %u entries/active: %u/%u\n",
  time->tm_hour, time->tm_min, time->tm_sec, now.tv_usec / 1000,
  devs_ip_to_str(), this_host.seqno, rt_tbl.num_entries,
  rt_tbl.num_active);
    len +=
 sprintf(rt_buf + len,
  "%-15s %-15s %-3s %-3s %-5s %-6s %-5s %-5s %-15s\n",
  "Destination", "Next hop", "HC", "St.", "Seqno", "Expire",
  "Flags", "Iface", "Precursors");
    written = write(log_rt_fd, rt_buf, len);
    len = 0;
    for (i = 0; i < 64; i++) {
 list_t *pos;
 for (pos = (&rt_tbl.tbl[i])->next; pos != (&rt_tbl.tbl[i]); pos = pos->next) {
     rt_table_t *rt = (rt_table_t *) pos;
     if (rt->dest_seqno == 0)
  sprintf(seqno_str, "-");
     else
  sprintf(seqno_str, "%u", rt->dest_seqno);
     if (((&rt->precursors) == (&rt->precursors)->next))
  len += sprintf(rt_buf + len,
          "%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s\n",
          ip_to_str(rt->dest_addr),
          ip_to_str(rt->next_hop), rt->hcnt,
          state_to_str(rt->state), seqno_str,
          (rt->hcnt == 255) ? 0 :
          timeval_diff(&rt->rt_timer.timeout, &now),
          rt_flags_to_str(rt->flags),
          if_indextoname(rt->ifindex, ifname));
     else {
  list_t *pos2;
  len += sprintf(rt_buf + len,
          "%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s %-15s\n",
          ip_to_str(rt->dest_addr),
          ip_to_str(rt->next_hop), rt->hcnt,
          state_to_str(rt->state), seqno_str,
          (rt->hcnt == 255) ? 0 :
          timeval_diff(&rt->rt_timer.timeout, &now),
          rt_flags_to_str(rt->flags),
          if_indextoname(rt->ifindex, ifname),
          ip_to_str(((precursor_t *) rt->precursors.next)->
      neighbor));
  for (pos2 = (&rt->precursors)->next; pos2 != (&rt->precursors); pos2 = pos2->next) {
      precursor_t *pr = (precursor_t *) pos2;
      if (pos2->prev == &rt->precursors)
   continue;
      len += sprintf(rt_buf + len, "%64s %-15s\n", " ",
       ip_to_str(pr->neighbor));
      written = write(log_rt_fd, rt_buf, len);
      len = 0;
  }
     }
     if (len > 0) {
  written = write(log_rt_fd, rt_buf, len);
  len = 0;
     }
 }
    }
  schedule:
    timer_set_timeout(&rt_log_timer, rt_log_interval);
}

canonical_original_code:
void print_rt_table(void *arg)
{
    char rt_buf[2048]; char ifname[64]; char seqno_str[11];
    int len = 0;
    int i = 0;
    struct timeval now;
    struct tm *time;
    long written;
    if (rt_tbl.num_entries == 0)
 goto schedule;
    gettimeofday(&now, ((void *)0));
    time = localtime(&now.tv_sec);
    len +=
 sprintf(rt_buf,
  "# Time: %02d:%02d:%02d.%03ld IP: %s seqno: %u entries/active: %u/%u\n",
  time->tm_hour, time->tm_min, time->tm_sec, now.tv_usec / 1000,
  devs_ip_to_str(), this_host.seqno, rt_tbl.num_entries,
  rt_tbl.num_active);
    len +=
 sprintf(rt_buf + len,
  "%-15s %-15s %-3s %-3s %-5s %-6s %-5s %-5s %-15s\n",
  "Destination", "Next hop", "HC", "St.", "Seqno", "Expire",
  "Flags", "Iface", "Precursors");
    written = write(log_rt_fd, rt_buf, len);
    len = 0;
    for (i = 0; i < 64; i++) {
 struct list_t *pos;
 for (pos = (&rt_tbl.tbl[i])->next; pos != (&rt_tbl.tbl[i]); pos = pos->next) {
     struct rt_table *rt = (rt_table_t *) pos;
     if (rt->dest_seqno == 0)
  sprintf(seqno_str, "-");
     else
  sprintf(seqno_str, "%u", rt->dest_seqno);
     if (((&rt->precursors) == (&rt->precursors)->next))
  len += sprintf(rt_buf + len,
          "%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s\n",
          ip_to_str(rt->dest_addr),
          ip_to_str(rt->next_hop), rt->hcnt,
          state_to_str(rt->state), seqno_str,
          (rt->hcnt == 255) ? 0 :
          timeval_diff(&rt->rt_timer.timeout, &now),
          rt_flags_to_str(rt->flags),
          if_indextoname(rt->ifindex, ifname));
     else {
  struct list_t *pos2;
  len += sprintf(rt_buf + len,
          "%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s %-15s\n",
          ip_to_str(rt->dest_addr),
          ip_to_str(rt->next_hop), rt->hcnt,
          state_to_str(rt->state), seqno_str,
          (rt->hcnt == 255) ? 0 :
          timeval_diff(&rt->rt_timer.timeout, &now),
          rt_flags_to_str(rt->flags),
          if_indextoname(rt->ifindex, ifname),
          ip_to_str(((struct precursor *) rt->precursors.next)->
      neighbor));
  for (pos2 = (&rt->precursors)->next; pos2 != (&rt->precursors); pos2 = pos2->next) {
      struct precursor *pr = (precursor_t *) pos2;
      if (pos2->prev == &rt->precursors)
   continue;
      len += sprintf(rt_buf + len, "%64s %-15s\n", " ",
       ip_to_str(pr->neighbor));
      written = write(log_rt_fd, rt_buf, len);
      len = 0;
  }
     }
     if (len > 0) {
  written = write(log_rt_fd, rt_buf, len);
  len = 0;
     }
 }
    }
  schedule:
    timer_set_timeout(&rt_log_timer, rt_log_interval);
}

variable_types:
arg
void *

variable_types:
ifname
char [64]

variable_types: len int

variable_types: written long

variable_types: struct list_t { struct list_t *prev; } *

variable_types: struct rt_table { struct list_t { struct list_t *prev; } l; struct in_addr { unsigned int s_addr; } dest_addr; unsigned int dest_seqno; unsigned int ifindex; struct in_addr next_hop; unsigned int hcnt; unsigned int flags; unsigned int state; struct timer { struct list_t l; int used; struct timeval { long tv_sec; long tv_usec; } timeout; void (*handler)(void *); void *data; } rt_timer; struct timer ack_timer; struct timer hello_timer; struct timeval last_hello_time; unsigned int hello_cnt; unsigned int hash; int nprec; struct list_t precursors; } *

variable_types: struct precursor { struct list_t { struct list_t *prev; } l; struct in_addr { unsigned int s_addr; } neighbor; } *

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


decompiled_code:
void __fastcall list_add(__int64 a1, _QWORD *a2)
{
if ( a1 )
{
if ( a2 )
listelm_add_isra_0(a2, a1, *(_QWORD **)(a1 + 8));
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, _QWORD *a2)
{
if ( a1 )
{
if ( a2 )
func0(a2, a1, *(_QWORD **)(a1 + 8));
}
}

original_code:
int list_add(list_t * head, list_t * le)
{
    if (!head || !le)
 return -1;
    listelm_add(le, head, head->next);
    return 1;
}

canonical_original_code:
int list_add(struct list_t *head, struct list_t *le)
{
    if (!head || !le)
 return -1;
    listelm_add(le, head, head->next);
    return 1;
}

variable_types:
le
struct list_t *

return_type: int


decompiled_code:
void __fastcall list_add_tail(__int64 *a1, _QWORD *a2)
{
if ( a1 )
{
if ( a2 )
listelm_add_isra_0(a2, *a1, a1);
}
}

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

original_code:
int list_add_tail(list_t * head, list_t * le)
{
    if (!head || !le)
 return -1;
    listelm_add(le, head->prev, head);
    return 1;
}

canonical_original_code:
int list_add_tail(struct list_t *head, struct list_t *le)
{
    if (!head || !le)
 return -1;
    listelm_add(le, head->prev, head);
    return 1;
}


decompiled_code:
__int64 __fastcall list_detach(__int64 a1)
{
unsigned int v1; // er8
_QWORD *v2; // rax

v1 = -1;
if ( a1 )
{
listelm_detach_isra_0(*(_QWORD *)a1, *(_QWORD **)(a1 + 8));
*v2 = 0LL;
v2[1] = 0LL;
}
return v1;
}

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

v1 = -1;
if ( a1 )
{
func1(*(_QWORD *)a1, *(_QWORD **)(a1 + 8));
*v2 = 0LL;
v2[1] = 0LL;
}
return v1;
}

original_code:
int list_detach(list_t * le)
{
    if (!le)
 return -1;
    listelm_detach(le->prev, le->next);
    le->next = le->prev = ((void *)0);
    return 1;
}

canonical_original_code:
int list_detach(struct list_t *le)
{
    if (!le)
 return -1;
    listelm_detach(le->prev, le->next);
    le->next = le->prev = ((void *)0);
    return 1;
}


original_code:
static inline long timeval_diff(struct timeval *t1, struct timeval *t2)
{
    long long res;
    if (!t1 || !t2)
 return -1;
    else {
 res = t1->tv_sec;
 res = ((res - t2->tv_sec) * 1000000 + t1->tv_usec - t2->tv_usec) / 1000;
 return (long) res;
    }
}

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

variable_types:
res
long long


decompiled_code:
__int64 __fastcall ifindex2devindex(int a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = this_host[11];
if ( (int)v1 <= 0 )
return 10LL;
result = 0LL;
while ( dev_indices[result] != a1 )
{
if ( ++result == v1 )
return 10LL;
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = this_host[11];
if ( (int)v1 <= 0 )
return 10LL;
result = 0LL;
while ( dev_indices[result] != a1 )
{
if ( ++result == v1 )
return 10LL;
}
return (unsigned int)result;
}

original_code:
static inline unsigned int ifindex2devindex(unsigned int ifindex)
{
    int i;
    for (i = 0; i < this_host.nif; i++)
 if (dev_indices[i] == ifindex)
     return i;
    return 10;
}

variable_types:
ifindex
unsigned int


decompiled_code:
void __fastcall route_delete_timeout(__int64 a1)
{
__int64 v1; // rax

if ( a1 )
{
v1 = ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "route_delete_timeout", &unk_D78, v1);
rt_table_delete(a1);
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
__int64 v1; // rax

if ( a1 )
{
v1 = ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "route_delete_timeout", &unk_D78, v1);
rt_table_delete(a1);
}
}

original_code:
void route_delete_timeout(void *arg)
{
 rt_table_t *rt;
 rt = (rt_table_t *) arg;
 if (!rt)
  return;
 alog(7, 0, __FUNCTION__, "%s", ip_to_str(rt->dest_addr));
 rt_table_delete(rt);
}

canonical_original_code:
void route_delete_timeout(void *arg)
{
 struct rt_table *rt;
 rt = (struct rt_table *) arg;
 if (!rt)
  return;
 alog(7, 0, __FUNCTION__, "%s", ip_to_str(rt->dest_addr));
 rt_table_delete(rt);
}


decompiled_code:
void __fastcall local_repair_timeout(__int64 a1)
{
unsigned int v1; // er13
__int64 v2; // rsi
__int64 v3; // rax
unsigned __int64 v4; // rbp
__int64 v5; // r12
__int64 v6; // rax
int v7; // eax
__int64 v8; // rcx

if ( a1 )
{
v1 = -1;
*(_WORD *)(a1 + 34) &= 0xFFFDu;
nl_send_del_route_msg(*(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 28), *(unsigned __int8 *)(a1 + 32));
if ( *(_DWORD *)(a1 + 232) )
{
v4 = (unsigned int)((_DWORD)this_host + 48);
v5 = rerr_create(0LL, *(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20));
if ( *(_DWORD *)(a1 + 232) == 1 )
{
v1 = *(_DWORD *)(*(_QWORD *)(a1 + 248) + 16LL);
v7 = ifindex2devindex(*(_DWORD *)(a1 + 24));
aodv_socket_send(v5, v1, 8 * (unsigned int)*(unsigned __int8 *)(v5 + 3) + 4, v8, &this_host[11 * v7 + 12]);
}
else
{
do
{
if ( *(_DWORD *)v4 )
aodv_socket_send(v5, 0xFFFFFFFFLL, 8 * (unsigned int)*(unsigned __int8 *)(v5 + 3) + 4, 1LL, v4);
v4 += 44LL;
}
while ( (int *)v4 != &this_host[122] );
}
ip_to_str(v1);
v6 = ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "local_repair_timeout", "Sending RERR about %s to %s", v6);
}
precursor_list_destroy(a1);
v2 = delete_period;
*(_QWORD *)(a1 + 80) = route_delete_timeout;
timer_set_timeout(a1 + 40, v2);
v3 = ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "local_repair_timeout", "%s removed in %u msecs", v3);
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
unsigned int v1; // er13
__int64 v2; // rsi
__int64 v3; // rax
unsigned __int64 v4; // rbp
__int64 v5; // r12
__int64 v6; // rax
int v7; // eax
__int64 v8; // rcx

if ( a1 )
{
v1 = -1;
*(_WORD *)(a1 + 34) &= 0xFFFDu;
nl_send_del_route_msg(*(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 28), *(unsigned __int8 *)(a1 + 32));
if ( *(_DWORD *)(a1 + 232) )
{
v4 = (unsigned int)((_DWORD)this_host + 48);
v5 = rerr_create(0LL, *(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20));
if ( *(_DWORD *)(a1 + 232) == 1 )
{
v1 = *(_DWORD *)(*(_QWORD *)(a1 + 248) + 16LL);
v7 = func1(*(_DWORD *)(a1 + 24));
aodv_socket_send(v5, v1, 8 * (unsigned int)*(unsigned __int8 *)(v5 + 3) + 4, v8, &this_host[11 * v7 + 12]);
}
else
{
do
{
if ( *(_DWORD *)v4 )
aodv_socket_send(v5, 0xFFFFFFFFLL, 8 * (unsigned int)*(unsigned __int8 *)(v5 + 3) + 4, 1LL, v4);
v4 += 44LL;
}
while ( (int *)v4 != &this_host[122] );
}
ip_to_str(v1);
v6 = ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "local_repair_timeout", "Sending RERR about %s to %s", v6);
}
precursor_list_destroy(a1);
v2 = delete_period;
*(_QWORD *)(a1 + 80) = route_delete_timeout;
timer_set_timeout(a1 + 40, v2);
v3 = ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "local_repair_timeout", "%s removed in %u msecs", v3);
}
}

original_code:
void local_repair_timeout(void *arg)
{
 rt_table_t *rt;
 struct in_addr rerr_dest;
 RERR *rerr = ((void *)0);
 rt = (rt_table_t *) arg;
 if (!rt)
  return;
 rerr_dest.s_addr = ((in_addr_t) 0xFFFFFFFF);
 rt->flags &= ~0x2;
 nl_send_del_route_msg(rt->dest_addr, rt->next_hop, rt->hcnt);
 if (rt->nprec) {
  rerr = rerr_create(0, rt->dest_addr, rt->dest_seqno);
  if (rt->nprec == 1) {
   rerr_dest = ((precursor_t *)((rt->precursors).next))->neighbor;
   aodv_socket_send((AODV_msg *) rerr, rerr_dest,
      (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)), 1,
      &(this_host.devs[ifindex2devindex(rt->ifindex)]));
  } else {
   int i;
   for (i = 0; i < 10; i++) {
    if (!(this_host.devs[i]).enabled)
     continue;
    aodv_socket_send((AODV_msg *) rerr, rerr_dest,
       (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)), 1,
       &(this_host.devs[i]));
   }
  }
  alog(7, 0, __FUNCTION__, "Sending RERR about %s to %s", ip_to_str(rt->dest_addr), ip_to_str(rerr_dest));
 }
 precursor_list_destroy(rt);
 rt->rt_timer.handler = & route_delete_timeout;
 timer_set_timeout(&rt->rt_timer, delete_period);
 alog(7, 0, __FUNCTION__, "%s removed in %u msecs", ip_to_str(rt->dest_addr), delete_period);
}

canonical_original_code:
void local_repair_timeout(void *arg)
{
 struct rt_table *rt;
 struct in_addr rerr_dest;
 struct RERR *rerr = ((void *)0);
 rt = (struct rt_table *) arg;
 if (!rt)
  return;
 rerr_dest.s_addr = ((unsigned int) 0xFFFFFFFF);
 rt->flags &= ~0x2;
 nl_send_del_route_msg(rt->dest_addr, rt->next_hop, rt->hcnt);
 if (rt->nprec) {
  rerr = rerr_create(0, rt->dest_addr, rt->dest_seqno);
  if (rt->nprec == 1) {
   rerr_dest = ((struct precursor *)((rt->precursors).next))->neighbor;
   aodv_socket_send((struct AODV_msg *) rerr, rerr_dest,
      (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)), 1,
      &(this_host.devs[ifindex2devindex(rt->ifindex)]));
  } else {
   int i;
   for (i = 0; i < 10; i++) {
    if (!(this_host.devs[i]).enabled)
     continue;
    aodv_socket_send((struct AODV_msg *) rerr, rerr_dest,
       (sizeof(RERR) + (rerr->dest_count-1)*sizeof(RERR_udest)), 1,
       &(this_host.devs[i]));
   }
  }
  alog(7, 0, __FUNCTION__, "Sending RERR about %s to %s", ip_to_str(rt->dest_addr), ip_to_str(rerr_dest));
 }
 precursor_list_destroy(rt);
 rt->rt_timer.handler = & route_delete_timeout;
 timer_set_timeout(&rt->rt_timer, delete_period);
 alog(7, 0, __FUNCTION__, "%s removed in %u msecs", ip_to_str(rt->dest_addr), delete_period);
}

user_defined_types: struct RERR { unsigned int type; unsigned int res1; unsigned int n; unsigned int res2; unsigned int dest_count; unsigned int dest_addr; unsigned int dest_seqno; }


decompiled_code:
void __fastcall route_discovery_timeout(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // r8
int v4; // eax
__int64 v5; // rdi
int v6; // edx
__int64 v7; // rsi
__int64 v8; // rax
__int64 v9; // r8
__int64 v10; // r8
__int64 v11; // r12
const char *v12; // rax
int v13; // eax
struct timeval v14; // [rsp-28h] [rbp-28h] BYREF

if ( a1 )
{
gettimeofday(&v14, 0LL);
v2 = ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "route_discovery_timeout", "%s", v2);
v4 = *(_DWORD *)(a1 + 36);
if ( v4 > 1 )
{
alog(7LL, 0LL, "route_discovery_timeout", "NO ROUTE FOUND!", v3);
nl_send_no_route_found_msg(*(unsigned int *)(a1 + 16));
v11 = rt_table_find(*(unsigned int *)(a1 + 16));
seek_list_remove(a1);
if ( v11 && (*(_BYTE *)(v11 + 34) & 2) != 0 )
{
v12 = (const char *)ip_to_str(*(unsigned int *)(v11 + 16));
alog(7LL, 0LL, "route_discovery_timeout", "REPAIR for %s failed!", v12);
local_repair_timeout(v11);
}
}
else
{
v5 = a1 + 48;
if ( expanding_ring_search )
{
v6 = *(_DWORD *)(a1 + 40);
if ( v6 <= 6 )
{
*(_DWORD *)(a1 + 40) = v6 + 2;
v7 = 16 * (5 * v6 + 20);
}
else
{
*(_DWORD *)(a1 + 40) = 35;
v7 = 2960LL;
*(_DWORD *)(a1 + 36) = v4 + 1;
}
}
else
{
v13 = v4 + 1;
*(_DWORD *)(a1 + 36) = v13;
v7 = 5600 * v13;
}
timer_set_timeout(v5, v7);
v8 = ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "route_discovery_timeout", "Seeking %s ttl=%d wait=%d", v8);
v9 = rt_table_find(*(unsigned int *)(a1 + 16));
if ( v9 )
{
if ( timeval_diff((_QWORD *)(v9 + 64), &v14) <= 5599 )
rt_table_update_timeout(v10, 5600LL);
}
rreq_send(
*(unsigned int *)(a1 + 16),
*(unsigned int *)(a1 + 20),
*(unsigned int *)(a1 + 40),
*(unsigned __int8 *)(a1 + 32));
}
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // r8
int v4; // eax
__int64 v5; // rdi
int v6; // edx
__int64 v7; // rsi
__int64 v8; // rax
__int64 v9; // r8
__int64 v10; // r8
__int64 v11; // r12
const char *v12; // rax
int v13; // eax
struct timeval v14; // [rsp-28h] [rbp-28h] BYREF

if ( a1 )
{
gettimeofday(&v14, 0LL);
v2 = ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "route_discovery_timeout", "%s", v2);
v4 = *(_DWORD *)(a1 + 36);
if ( v4 > 1 )
{
alog(7LL, 0LL, "route_discovery_timeout", "NO ROUTE FOUND!", v3);
nl_send_no_route_found_msg(*(unsigned int *)(a1 + 16));
v11 = rt_table_find(*(unsigned int *)(a1 + 16));
seek_list_remove(a1);
if ( v11 && (*(_BYTE *)(v11 + 34) & 2) != 0 )
{
v12 = (const char *)ip_to_str(*(unsigned int *)(v11 + 16));
alog(7LL, 0LL, "route_discovery_timeout", "REPAIR for %s failed!", v12);
func3(v11);
}
}
else
{
v5 = a1 + 48;
if ( expanding_ring_search )
{
v6 = *(_DWORD *)(a1 + 40);
if ( v6 <= 6 )
{
*(_DWORD *)(a1 + 40) = v6 + 2;
v7 = 16 * (5 * v6 + 20);
}
else
{
*(_DWORD *)(a1 + 40) = 35;
v7 = 2960LL;
*(_DWORD *)(a1 + 36) = v4 + 1;
}
}
else
{
v13 = v4 + 1;
*(_DWORD *)(a1 + 36) = v13;
v7 = 5600 * v13;
}
timer_set_timeout(v5, v7);
v8 = ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "route_discovery_timeout", "Seeking %s ttl=%d wait=%d", v8);
v9 = rt_table_find(*(unsigned int *)(a1 + 16));
if ( v9 )
{
if ( func0((_QWORD *)(v9 + 64), &v14) <= 5599 )
rt_table_update_timeout(v10, 5600LL);
}
rreq_send(
*(unsigned int *)(a1 + 16),
*(unsigned int *)(a1 + 20),
*(unsigned int *)(a1 + 40),
*(unsigned __int8 *)(a1 + 32));
}
}
}

original_code:
void route_discovery_timeout(void *arg)
{
 struct timeval now;
 seek_list_t *seek_entry;
 rt_table_t *rt, *repair_rt;
 seek_entry = (seek_list_t *) arg;
 if (!seek_entry)
  return;
 gettimeofday(&now, ((void *)0));
 alog(7, 0, __FUNCTION__, "%s", ip_to_str(seek_entry->dest_addr));
 if (seek_entry->reqs < 2) {
  if (expanding_ring_search) {
   if (seek_entry->ttl < 7)
    seek_entry->ttl += 2;
   else {
    seek_entry->ttl = 35;
    seek_entry->reqs++;
   }
   timer_set_timeout(&seek_entry->seek_timer,
       2 * 40 * (seek_entry->ttl + 2));
  } else {
   seek_entry->reqs++;
   timer_set_timeout(&seek_entry->seek_timer,
       seek_entry->reqs * 2 *
       2 * 40 * 35);
  }
  alog(7, 0, __FUNCTION__, "Seeking %s ttl=%d wait=%d", ip_to_str(seek_entry->dest_addr), seek_entry->ttl, 2 * seek_entry->ttl * 40);
  rt = rt_table_find(seek_entry->dest_addr);
  if (rt && timeval_diff(&rt->rt_timer.timeout, &now) <
      (2 * 2 * 40 * 35))
   rt_table_update_timeout(rt, 2 * 2 * 40 * 35);
  rreq_send(seek_entry->dest_addr, seek_entry->dest_seqno,
     seek_entry->ttl, seek_entry->flags);
 } else {
  alog(7, 0, __FUNCTION__, "NO ROUTE FOUND!");
  nl_send_no_route_found_msg(seek_entry->dest_addr);
  repair_rt = rt_table_find(seek_entry->dest_addr);
  seek_list_remove(seek_entry);
  if (repair_rt && (repair_rt->flags & 0x2)) {
   alog(7, 0, __FUNCTION__, "REPAIR for %s failed!", ip_to_str(repair_rt->dest_addr));
   local_repair_timeout(repair_rt);
  }
 }
}

canonical_original_code:
void route_discovery_timeout(void *arg)
{
 struct timeval now;
 struct seek_list *seek_entry;
 struct rt_table *rt; struct rt_table *repair_rt;
 seek_entry = (struct seek_list *) arg;
 if (!seek_entry)
  return;
 gettimeofday(&now, ((void *)0));
 alog(7, 0, __FUNCTION__, "%s", ip_to_str(seek_entry->dest_addr));
 if (seek_entry->reqs < 2) {
  if (expanding_ring_search) {
   if (seek_entry->ttl < 7)
    seek_entry->ttl += 2;
   else {
    seek_entry->ttl = 35;
    seek_entry->reqs++;
   }
   timer_set_timeout(&seek_entry->seek_timer,
       2 * 40 * (seek_entry->ttl + 2));
  } else {
   seek_entry->reqs++;
   timer_set_timeout(&seek_entry->seek_timer,
       seek_entry->reqs * 2 *
       2 * 40 * 35);
  }
  alog(7, 0, __FUNCTION__, "Seeking %s ttl=%d wait=%d", ip_to_str(seek_entry->dest_addr), seek_entry->ttl, 2 * seek_entry->ttl * 40);
  rt = rt_table_find(seek_entry->dest_addr);
  if (rt && timeval_diff(&rt->rt_timer.timeout, &now) <
      (2 * 2 * 40 * 35))
   rt_table_update_timeout(rt, 2 * 2 * 40 * 35);
  rreq_send(seek_entry->dest_addr, seek_entry->dest_seqno,
     seek_entry->ttl, seek_entry->flags);
 } else {
  alog(7, 0, __FUNCTION__, "NO ROUTE FOUND!");
  nl_send_no_route_found_msg(seek_entry->dest_addr);
  repair_rt = rt_table_find(seek_entry->dest_addr);
  seek_list_remove(seek_entry);
  if (repair_rt && (repair_rt->flags & 0x2)) {
   alog(7, 0, __FUNCTION__, "REPAIR for %s failed!", ip_to_str(repair_rt->dest_addr));
   local_repair_timeout(repair_rt);
  }
 }
}

variable_types: struct seek_list { struct list_t { struct list_t *prev; } l; struct in_addr { unsigned int s_addr; } dest_addr; unsigned int dest_seqno; struct ip_data { char data[-1]; int len; } *ipd; unsigned int flags; int reqs; int ttl; struct timer { struct list_t l; int used; struct timeval { long tv_sec; long tv_usec; } timeout; void (*handler)(void *); void *data; } seek_timer; } *

user_defined_types: struct seek_list { struct list_t l; struct in_addr dest_addr; unsigned int dest_seqno; struct ip_data *ipd; unsigned int flags; int reqs; int ttl; struct timer seek_timer; }


decompiled_code:
__int64 __fastcall route_expire_timeout(__int64 a1)
{
unsigned int v1; // ebx
const char *v2; // rax

if ( !a1 )
return alog(4LL, 0LL, "route_expire_timeout", "arg was NULL, ignoring timeout!");
v1 = *(_DWORD *)(a1 + 20);
v2 = (const char *)ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "route_expire_timeout", "Route %s DOWN, seqno=%d", v2, v1);
if ( *(_BYTE *)(a1 + 32) == 1 )
return neighbor_link_break(a1);
rt_table_invalidate(a1);
return precursor_list_destroy(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int v1; // ebx
const char *v2; // rax

if ( !a1 )
return alog(4LL, 0LL, "route_expire_timeout", "arg was NULL, ignoring timeout!");
v1 = *(_DWORD *)(a1 + 20);
v2 = (const char *)ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "route_expire_timeout", "Route %s DOWN, seqno=%d", v2, v1);
if ( *(_BYTE *)(a1 + 32) == 1 )
return neighbor_link_break(a1);
rt_table_invalidate(a1);
return precursor_list_destroy(a1);
}

original_code:
void route_expire_timeout(void *arg)
{
 rt_table_t *rt;
 rt = (rt_table_t *) arg;
 if (!rt) {
  alog(4, 0, __FUNCTION__,
       "arg was NULL, ignoring timeout!");
  return;
 }
 alog(7, 0, __FUNCTION__, "Route %s DOWN, seqno=%d", ip_to_str(rt->dest_addr), rt->dest_seqno);
 if (rt->hcnt == 1)
  neighbor_link_break(rt);
 else {
  rt_table_invalidate(rt);
  precursor_list_destroy(rt);
 }
 return;
}

canonical_original_code:
void route_expire_timeout(void *arg)
{
 struct rt_table *rt;
 rt = (struct rt_table *) arg;
 if (!rt) {
  alog(4, 0, __FUNCTION__,
       "arg was NULL, ignoring timeout!");
  return;
 }
 alog(7, 0, __FUNCTION__, "Route %s DOWN, seqno=%d", ip_to_str(rt->dest_addr), rt->dest_seqno);
 if (rt->hcnt == 1)
  neighbor_link_break(rt);
 else {
  rt_table_invalidate(rt);
  precursor_list_destroy(rt);
 }
 return;
}


decompiled_code:
void __fastcall hello_timeout(__int64 a1)
{
__int64 v2; // rbx
const char *v3; // rax
__int16 v4; // ax
__int64 v5; // rdi
const char *v6; // rax
struct timeval v7; // [rsp-28h] [rbp-28h] BYREF

if ( a1 )
{
gettimeofday(&v7, 0LL);
v2 = timeval_diff(&v7, (_QWORD *)(a1 + 208));
v3 = (const char *)ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "hello_timeout", "LINK/HELLO FAILURE %s last HELLO: %d", v3, v2);
if ( *(_BYTE *)(a1 + 36) == 1 )
{
v4 = *(_WORD *)(a1 + 34);
if ( (v4 & 1) == 0 )
{
if ( local_repair )
{
if ( *(_BYTE *)(a1 + 32) <= 0xAu )
{
v5 = *(unsigned int *)(a1 + 16);
*(_WORD *)(a1 + 34) = v4 | 2;
v6 = (const char *)ip_to_str(v5);
alog(7LL, 0LL, "hello_timeout", "Marking %s for REPAIR", v6);
}
}
neighbor_link_break(a1);
}
}
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
__int64 v2; // rbx
const char *v3; // rax
__int16 v4; // ax
__int64 v5; // rdi
const char *v6; // rax
struct timeval v7; // [rsp-28h] [rbp-28h] BYREF

if ( a1 )
{
gettimeofday(&v7, 0LL);
v2 = func0(&v7, (_QWORD *)(a1 + 208));
v3 = (const char *)ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "hello_timeout", "LINK/HELLO FAILURE %s last HELLO: %d", v3, v2);
if ( *(_BYTE *)(a1 + 36) == 1 )
{
v4 = *(_WORD *)(a1 + 34);
if ( (v4 & 1) == 0 )
{
if ( local_repair )
{
if ( *(_BYTE *)(a1 + 32) <= 0xAu )
{
v5 = *(unsigned int *)(a1 + 16);
*(_WORD *)(a1 + 34) = v4 | 2;
v6 = (const char *)ip_to_str(v5);
alog(7LL, 0LL, "hello_timeout", "Marking %s for REPAIR", v6);
}
}
neighbor_link_break(a1);
}
}
}
}

original_code:
void hello_timeout(void *arg)
{
 rt_table_t *rt;
 struct timeval now;
 rt = (rt_table_t *) arg;
 if (!rt)
  return;
 gettimeofday(&now, ((void *)0));
 alog(7, 0, __FUNCTION__, "LINK/HELLO FAILURE %s last HELLO: %d", ip_to_str(rt->dest_addr), timeval_diff(&now, &rt->last_hello_time));
 if (rt && rt->state == 1 && !(rt->flags & 0x1)) {
  if (local_repair && rt->hcnt <= 3 * 35 / 10) {
   rt->flags |= 0x2;
   alog(7, 0, __FUNCTION__, "Marking %s for REPAIR", ip_to_str(rt->dest_addr));
  }
  neighbor_link_break(rt);
 }
}

canonical_original_code:
void hello_timeout(void *arg)
{
 struct rt_table *rt;
 struct timeval now;
 rt = (struct rt_table *) arg;
 if (!rt)
  return;
 gettimeofday(&now, ((void *)0));
 alog(7, 0, __FUNCTION__, "LINK/HELLO FAILURE %s last HELLO: %d", ip_to_str(rt->dest_addr), timeval_diff(&now, &rt->last_hello_time));
 if (rt && rt->state == 1 && !(rt->flags & 0x1)) {
  if (local_repair && rt->hcnt <= 3 * 35 / 10) {
   rt->flags |= 0x2;
   alog(7, 0, __FUNCTION__, "Marking %s for REPAIR", ip_to_str(rt->dest_addr));
  }
  neighbor_link_break(rt);
 }
}

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


decompiled_code:
void __fastcall rrep_ack_timeout(__int64 a1)
{
const char *v1; // rax

if ( a1 )
{
rreq_blacklist_insert(*(unsigned int *)(a1 + 16));
v1 = (const char *)ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "rrep_ack_timeout", "%s", v1);
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
const char *v1; // rax

if ( a1 )
{
rreq_blacklist_insert(*(unsigned int *)(a1 + 16));
v1 = (const char *)ip_to_str(*(unsigned int *)(a1 + 16));
alog(7LL, 0LL, "rrep_ack_timeout", "%s", v1);
}
}

original_code:
void rrep_ack_timeout(void *arg)
{
 rt_table_t *rt;
 rt = (rt_table_t *) arg;
 if (!rt)
  return;
 rreq_blacklist_insert(rt->dest_addr);
 alog(7, 0, __FUNCTION__, "%s", ip_to_str(rt->dest_addr));
}

canonical_original_code:
void rrep_ack_timeout(void *arg)
{
 struct rt_table *rt;
 rt = (struct rt_table *) arg;
 if (!rt)
  return;
 rreq_blacklist_insert(rt->dest_addr);
 alog(7, 0, __FUNCTION__, "%s", ip_to_str(rt->dest_addr));
}


decompiled_code:
__int64 __fastcall wait_on_reboot_timeout(_DWORD *a1)
{
*a1 = 0;
return alog(7LL, 0LL, "wait_on_reboot_timeout", "Wait on reboot over!!");
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1)
{
*a1 = 0;
return alog(7LL, 0LL, "wait_on_reboot_timeout", "Wait on reboot over!!");
}

original_code:
void wait_on_reboot_timeout(void *arg)
{
 *((int *) arg) = 0;
 alog(7, 0, __FUNCTION__, "Wait on reboot over!!");
}


decompiled_code:
__int64 __fastcall seek_list_remove(void *ptr)
{
void *v2; // rdi

if ( !ptr )
return 0LL;
list_detach();
timer_remove((char *)ptr + 48);
v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
void *v2; // rdi

if ( !ptr )
return 0LL;
list_detach();
timer_remove((char *)ptr + 48);
v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
free(ptr);
return 1LL;
}

original_code:
int seek_list_remove(seek_list_t * entry)
{
    if (!entry)
 return 0;
    list_detach(&entry->l);
    timer_remove(&entry->seek_timer);
    if (entry->ipd)
 free(entry->ipd);
    free(entry);
    return 1;
}

canonical_original_code:
int seek_list_remove(struct seek_list *entry)
{
    if (!entry)
 return 0;
    list_detach(&entry->l);
    timer_remove(&entry->seek_timer);
    if (entry->ipd)
 free(entry->ipd);
    free(entry);
    return 1;
}

user_defined_types: struct ip_data { char data[-1]; int len; }


decompiled_code:
void **__fastcall seek_list_find(int a1)
{
void **result; // rax

result = off_128;
if ( off_128 == &seekhead )
return 0LL;
while ( *((_DWORD *)result + 4) != a1 )
{
result = (void **)result[1];
if ( result == &seekhead )
return 0LL;
}
return result;
}

canonical_decompiled_code:
void **__fastcall func1(int a1)
{
void **result; // rax

result = off_128;
if ( off_128 == &seekhead )
return 0LL;
while ( *((_DWORD *)result + 4) != a1 )
{
result = (void **)result[1];
if ( result == &seekhead )
return 0LL;
}
return result;
}

original_code:
seek_list_t * seek_list_find(struct in_addr dest_addr)
{
    list_t *pos;
    for (pos = (&seekhead)->next; pos != (&seekhead); pos = pos->next) {
 seek_list_t *entry = (seek_list_t *) pos;
 if (entry->dest_addr.s_addr == dest_addr.s_addr)
     return entry;
    }
    return ((void *)0);
}

canonical_original_code:
struct seek_list *seek_list_find(struct in_addr dest_addr)
{
    struct list_t *pos;
    for (pos = (&seekhead)->next; pos != (&seekhead); pos = pos->next) {
 struct seek_list *entry = (seek_list_t *) pos;
 if (entry->dest_addr.s_addr == dest_addr.s_addr)
     return entry;
    }
    return ((void *)0);
}

return_type: struct seek_list { struct list_t { struct list_t *prev; } l; struct in_addr { unsigned int s_addr; } dest_addr; unsigned int dest_seqno; struct ip_data { char data[-1]; int len; } *ipd; unsigned int flags; int reqs; int ttl; struct timer { struct list_t l; int used; struct timeval { long tv_sec; long tv_usec; } timeout; void (*handler)(void *); void *data; } seek_timer; } *


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

v1 = this_host[11];
if ( (int)v1 <= 0 )
return 10LL;
result = 0LL;
while ( dev_indices[result] != a1 )
{
if ( ++result == v1 )
return 10LL;
}
return (unsigned int)result;
}

canonical_original_code:
static inline unsigned int ifindex2devindex(unsigned int ifindex)
{
    int i;
    for (i = 0; i < this_host.nif; i++)
 if (dev_indices[i] == ifindex)
     return i;
    return 10;
}


locality

decompiled_code:
__int64 __fastcall locality(unsigned int a1, int a2)
{
int v2; // eax
__int64 result; // rax
struct hostent *v4; // r8
const char *v5; // rax
unsigned int addr[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr[0] = a1;
if ( gw_prefix )
{
v2 = ifindex2devindex(a2);
result = (this_host[11 * v2 + 21] & this_host[11 * v2 + 20]) != (addr[0] & this_host[11 * v2 + 21]);
}
else
{
v4 = gethostbyaddr(addr, 4u, 2);
result = 1LL;
if ( !v4 )
{
if ( *_h_errno_location() == 1 )
{
v5 = (const char *)ip_to_str(addr[0]);
alog(7LL, 0LL, "locality", "RREQ for Non-Internet dest %s", v5);
}
else
{
alog(7LL, 0LL, "locality", "Unknown DNS error");
}
result = 2LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2)
{
int v2; // eax
__int64 result; // rax
struct hostent *v4; // r8
const char *v5; // rax
unsigned int addr[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr[0] = a1;
if ( gw_prefix )
{
v2 = func0(a2);
result = (this_host[11 * v2 + 21] & this_host[11 * v2 + 20]) != (addr[0] & this_host[11 * v2 + 21]);
}
else
{
v4 = gethostbyaddr(addr, 4u, 2);
result = 1LL;
if ( !v4 )
{
if ( *_h_errno_location() == 1 )
{
v5 = (const char *)ip_to_str(addr[0]);
alog(7LL, 0LL, "locality", "RREQ for Non-Internet dest %s", v5);
}
else
{
alog(7LL, 0LL, "locality", "Unknown DNS error");
}
result = 2LL;
}
}
return result;
}

original_code:
int locality(struct in_addr dest, unsigned int ifindex)
{
    if (gw_prefix) {
 if ((dest.s_addr & (this_host.devs[ifindex2devindex(ifindex)]).netmask.s_addr) ==
     ((this_host.devs[ifindex2devindex(ifindex)]).ipaddr.s_addr & (this_host.devs[ifindex2devindex(ifindex)]).netmask.
      s_addr))
     return HOST_ADHOC;
 else
     return HOST_INET;
    } else {
 struct hostent *hent;
 hent = gethostbyaddr(&dest, sizeof(struct in_addr), 2);
 if (!hent) {
     switch ((*__h_errno_location ())) {
     case 1:
  alog(7, 0, __FUNCTION__, "RREQ for Non-Internet dest %s", ip_to_str(dest));
  return HOST_UNKNOWN;
     default:
  alog(7, 0, __FUNCTION__, "Unknown DNS error");
  break;
     }
 } else
     return HOST_INET;
    }
    return HOST_UNKNOWN;
}

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


repo: franko/regress-pro

decompiled_code:
_BOOL8 __fastcall is_dir_separator(char a1)
{
return a1 == 47;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char a1)
{
return a1 == 47;
}

original_code:
static int is_dir_separator(char c) {
    return (c == '/');
}

variable_types: c char


decompiled_code:
__int64 __fastcall str_getcwd(__int64 a1)
{
size_t i; // rbx
char *v2; // rax

for ( i = 64LL; ; i *= 2LL )
{
if ( i + 1 > *(_QWORD *)(a1 + 8) )
str_resize(a1, i);
v2 = getcwd(*(char **)a1, i);
if ( v2 == *(char **)a1 )
{
*(_QWORD *)(a1 + 16) = strlen(v2);
return 0LL;
}
if ( *_errno_location() != 34 )
break;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
size_t i; // rbx
char *v2; // rax

for ( i = 64LL; ; i *= 2LL )
{
if ( i + 1 > *(_QWORD *)(a1 + 8) )
str_resize(a1, i);
v2 = getcwd(*(char **)a1, i);
if ( v2 == *(char **)a1 )
{
*(_QWORD *)(a1 + 16) = strlen(v2);
return 0LL;
}
if ( *_errno_location() != 34 )
break;
}
return 1LL;
}

original_code:
int
str_getcwd(str_t dir)
{
    size_t bsize;
    for(bsize = 64; ; bsize *= 2) {
        { if((bsize)+1 > (dir)->size) { str_resize(dir, bsize); } };
        if(getcwd(dir->heap, bsize) == dir->heap) {
            dir->length = strlen(dir->heap);
            return 0;
        }
        if((*__errno_location ()) != 34) {
            break;
        }
    }
    return 1;
}

canonical_original_code:
int str_getcwd(struct _str dir[1])
{
    unsigned long bsize;
    for(bsize = 64; ; bsize *= 2) {
        { if((bsize)+1 > (dir)->size) { str_resize(dir, bsize); } };
        if(getcwd(dir->heap, bsize) == dir->heap) {
            dir->length = strlen(dir->heap);
            return 0;
        }
        if((*__errno_location ()) != 34) {
            break;
        }
    }
    return 1;
}

variable_types: struct _str { char *heap; unsigned long size; unsigned long length; } [1]

variable_types:
bsize
unsigned long


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

result = 0LL;
if ( *(_QWORD *)(a1 + 16) )
result = **(_BYTE **)a1 == 47;
return result;
}

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

result = 0LL;
if ( *(_QWORD *)(a1 + 16) )
result = **(_BYTE **)a1 == 47;
return result;
}

original_code:
int
str_is_abs_pathname(str_t path)
{
    if(path->length == 0) {
        return 0;
    }
    return (path->heap[0] == '/');
}

canonical_original_code:
int str_is_abs_pathname(struct _str path[1])
{
    if(path->length == 0) {
        return 0;
    }
    return (path->heap[0] == '/');
}

user_defined_types: struct _str { char *heap; unsigned long size; unsigned long length; }