decompiled_code:
__int64 __fastcall if_parse_generic(char *s, char *src)
{
size_t v2; // rbx
void *v3; // rsp
size_t v4; // rax
__int64 result; // rax
char v6[8]; // [rsp+0h] [rbp-30h] BYREF
int v7; // [rsp+8h] [rbp-28h] BYREF
unsigned int v8; // [rsp+Ch] [rbp-24h] BYREF

v2 = strlen(src);
v3 = alloca(v2 + 13);
strcpy(v6, src);
strcpy(&v6[v2], "%d%n");
if ( !sscanf(s, v6, &v8, &v7) )
return 0xFFFFFFFFLL;
v4 = strlen(s);
if ( v4 == v7 )
result = v8;
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, char *src)
{
size_t v2; // rbx
void *v3; // rsp
size_t v4; // rax
__int64 result; // rax
char v6[8]; // [rsp+0h] [rbp-30h] BYREF
int v7; // [rsp+8h] [rbp-28h] BYREF
unsigned int v8; // [rsp+Ch] [rbp-24h] BYREF

v2 = strlen(src);
v3 = alloca(v2 + 13);
strcpy(v6, src);
strcpy(&v6[v2], "%d%n");
if ( !sscanf(s, v6, &v8, &v7) )
return 0xFFFFFFFFLL;
v4 = strlen(s);
if ( v4 == v7 )
result = v8;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int if_parse_generic(const char *name, const char *type)
{
 int ret, n;
 char *fmt;
 size_t len;
 fmt = __builtin_alloca ((len = strlen(type)) + 5);
 strcpy(fmt, type);
 strcpy(fmt + len, "%d%n");
 if (!sscanf(name, fmt, &ret, &n))
  return -1;
 if (strlen(name) != n)
  return -1;
 return ret;
}

canonical_original_code:
int if_parse_generic(char *name, char *type)
{
 int ret; int n;
 char *fmt;
 unsigned long len;
 fmt = __builtin_alloca ((len = strlen(type)) + 5);
 strcpy(fmt, type);
 strcpy(fmt + len, "%d%n");
 if (!sscanf(name, fmt, &ret, &n))
  return -1;
 if (strlen(name) != n)
  return -1;
 return ret;
}

variable_types:
type
char *

variable_types: ret int

variable_types: n int

variable_types:
fmt
char *

variable_types:
len
unsigned long


repo: lisa-project/lisa-user

decompiled_code:
__int64 __fastcall if_get_index(char *src, int fd)
{
size_t v2; // rdx
__int64 result; // rax
bool v4; // zf
char v5[16]; // [rsp+0h] [rbp-48h] BYREF
unsigned int v6; // [rsp+10h] [rbp-38h]

v2 = strlen(src);
result = 0LL;
if ( v2 <= 0xF )
{
strcpy(v5, src);
if ( fd == -1 )
_assert_fail("sock_fd != -1", "if_generic.c", 0x25u, "if_get_index");
v4 = ioctl(fd, 0x8933uLL, v5) == 0;
result = 0LL;
if ( v4 )
result = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src, int fd)
{
size_t v2; // rdx
__int64 result; // rax
bool v4; // zf
char v5[16]; // [rsp+0h] [rbp-48h] BYREF
unsigned int v6; // [rsp+10h] [rbp-38h]

v2 = strlen(src);
result = 0LL;
if ( v2 <= 0xF )
{
strcpy(v5, src);
if ( fd == -1 )
_assert_fail("sock_fd != -1", "if_generic.c", 0x25u, "if_get_index");
v4 = ioctl(fd, 0x8933uLL, v5) == 0;
result = 0LL;
if ( v4 )
result = v6;
}
return result;
}

original_code:
int if_get_index(const char *name, int sock_fd)
{
 struct ifreq ifr;
 int ret = 0;
 if (strlen(name) >= 16)
  return 0;
 strcpy(ifr.ifr_ifrn.ifrn_name, name);
 ((void) sizeof ((sock_fd != -1) ? 1 : 0), __extension__ ({ if (sock_fd != -1) ; else __assert_fail ("sock_fd != -1", "if_generic.c", 37, __extension__ __PRETTY_FUNCTION__); }));
 if (!ioctl(sock_fd, 0x8933, &ifr))
  ret = ifr.ifr_ifru.ifru_ivalue;
 return ret;
}

canonical_original_code:
int if_get_index(char *name, int sock_fd)
{
 struct ifreq ifr;
 int ret = 0;
 if (strlen(name) >= 16)
  return 0;
 strcpy(ifr.ifr_ifrn.ifrn_name, name);
 ((void) sizeof ((sock_fd != -1) ? 1 : 0), __extension__ ({ if (sock_fd != -1) ; else __assert_fail ("sock_fd != -1", "if_generic.c", 37, __extension__ __PRETTY_FUNCTION__); }));
 if (!ioctl(sock_fd, 0x8933, &ifr))
  ret = ifr.ifr_ifru.ifru_ivalue;
 return ret;
}

variable_types:
name
char *

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto { unsigned short encoding; unsigned short parity; } *raw_hdlc; struct cisco_proto { unsigned int interval; unsigned int timeout; } *cisco; struct fr_proto { unsigned int t391; unsigned int t392; unsigned int n391; unsigned int n392; unsigned int n393; unsigned short lmi; unsigned short dce; } *fr; struct fr_proto_pvc { unsigned int dlci; } *fr_pvc; struct fr_proto_pvc_info { unsigned int dlci; char master[16]; } *fr_pvc_info; struct sync_serial_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; } *sync; struct te1_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; unsigned int slot_map; } *te1; } ifs_ifsu; } ifru_settings; } ifr_ifru; }

return_type: int

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings ifru_settings; } ifr_ifru; }

user_defined_types: struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto *raw_hdlc; struct cisco_proto *cisco; struct fr_proto *fr; struct fr_proto_pvc *fr_pvc; struct fr_proto_pvc_info *fr_pvc_info; struct sync_serial_settings *sync; struct te1_settings *te1; } ifs_ifsu; }


decompiled_code:
char *__fastcall canonical_if_name(__int64 a1)
{
int v1; // eax
int v2; // eax
bool v3; // zf
char *result; // rax
int v5; // eax
char *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

ptr[0] = 0LL;
if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 20);
if ( v1 <= 2 )
{
if ( v1 <= 0 )
return 0LL;
v5 = if_parse_generic((char *)a1, "eth");
if ( v5 < 0 )
v2 = asprintf(ptr, "netdev %s", (const char *)a1);
else
v2 = asprintf(ptr, "Ethernet %d", (unsigned int)v5);
}
else
{
if ( v1 != 4 )
return 0LL;
v2 = asprintf(ptr, "vlan %d", *(unsigned int *)(a1 + 24));
}
v3 = v2 == -1;
result = 0LL;
if ( !v3 )
result = ptr[0];
return result;
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1)
{
int v1; // eax
int v2; // eax
bool v3; // zf
char *result; // rax
int v5; // eax
char *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

ptr[0] = 0LL;
if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 20);
if ( v1 <= 2 )
{
if ( v1 <= 0 )
return 0LL;
v5 = func3((char *)a1, "eth");
if ( v5 < 0 )
v2 = asprintf(ptr, "netdev %s", (const char *)a1);
else
v2 = asprintf(ptr, "Ethernet %d", (unsigned int)v5);
}
else
{
if ( v1 != 4 )
return 0LL;
v2 = asprintf(ptr, "vlan %d", *(unsigned int *)(a1 + 24));
}
v3 = v2 == -1;
result = 0LL;
if ( !v3 )
result = ptr[0];
return result;
}

original_code:
char *canonical_if_name(struct net_switch_device *nsdev)
{
 char *ret = ((void *)0);
 int n, status = -1;
 if (nsdev == ((void *)0))
  return ((void *)0);
 switch (nsdev->type) {
 case 0x01:
 case 0x02:
  if ((n = if_parse_generic(nsdev->name, "eth")) >= 0)
   status = asprintf(&ret, "Ethernet %d", n);
  else
   status = asprintf(&ret, "netdev %s", nsdev->name);
  break;
 case 0x04:
  status = asprintf(&ret, "vlan %d", nsdev->vlan);
  break;
 }
 return status == -1 ? ((void *)0) : ret;
}

canonical_original_code:
char *canonical_if_name(struct net_switch_device *nsdev)
{
 char *ret = ((void *)0);
 int n; int status = -1;
 if (nsdev == ((void *)0))
  return ((void *)0);
 switch (nsdev->type) {
 case 0x01:
 case 0x02:
  if ((n = if_parse_generic(nsdev->name, "eth")) >= 0)
   status = asprintf(&ret, "Ethernet %d", n);
  else
   status = asprintf(&ret, "netdev %s", nsdev->name);
  break;
 case 0x04:
  status = asprintf(&ret, "vlan %d", nsdev->vlan);
  break;
 }
 return status == -1 ? ((void *)0) : ret;
}

variable_types: struct net_switch_device { char name[16]; int ifindex; int type; int vlan; struct list_head { struct list_head *next; } lh; } *

variable_types:
ret
char *

variable_types: status int

return_type: char *

user_defined_types: struct net_switch_device { char name[16]; int ifindex; int type; int vlan; struct list_head lh; }


decompiled_code:
char *__fastcall short_if_name(__int64 a1)
{
int v1; // eax
int v2; // eax
bool v3; // zf
char *result; // rax
int v5; // eax
char *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

ptr[0] = 0LL;
if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 20);
if ( v1 <= 2 )
{
if ( v1 <= 0 )
return 0LL;
v5 = if_parse_generic((char *)a1, "eth");
if ( v5 < 0 )
v2 = asprintf(ptr, "net %s", (const char *)a1);
else
v2 = asprintf(ptr, "Et%d", (unsigned int)v5);
}
else
{
if ( v1 != 4 )
return 0LL;
v2 = asprintf(ptr, "vlan %d", *(unsigned int *)(a1 + 24));
}
v3 = v2 == -1;
result = 0LL;
if ( !v3 )
result = ptr[0];
return result;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1)
{
int v1; // eax
int v2; // eax
bool v3; // zf
char *result; // rax
int v5; // eax
char *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

ptr[0] = 0LL;
if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 20);
if ( v1 <= 2 )
{
if ( v1 <= 0 )
return 0LL;
v5 = func3((char *)a1, "eth");
if ( v5 < 0 )
v2 = asprintf(ptr, "net %s", (const char *)a1);
else
v2 = asprintf(ptr, "Et%d", (unsigned int)v5);
}
else
{
if ( v1 != 4 )
return 0LL;
v2 = asprintf(ptr, "vlan %d", *(unsigned int *)(a1 + 24));
}
v3 = v2 == -1;
result = 0LL;
if ( !v3 )
result = ptr[0];
return result;
}

original_code:
char *short_if_name(struct net_switch_device *nsdev)
{
 char *ret = ((void *)0);
 int n, status = -1;
 if (nsdev == ((void *)0))
  return ((void *)0);
 switch (nsdev->type) {
 case 0x01:
 case 0x02:
  if ((n = if_parse_generic(nsdev->name, "eth")) >= 0)
   status = asprintf(&ret, "Et%d", n);
  else
   status = asprintf(&ret, "net %s", nsdev->name);
  break;
 case 0x04:
  status = asprintf(&ret, "vlan %d", nsdev->vlan);
  break;
 }
 return status == -1 ? ((void *)0) : ret;
}

canonical_original_code:
char *short_if_name(struct net_switch_device *nsdev)
{
 char *ret = ((void *)0);
 int n; int status = -1;
 if (nsdev == ((void *)0))
  return ((void *)0);
 switch (nsdev->type) {
 case 0x01:
 case 0x02:
  if ((n = if_parse_generic(nsdev->name, "eth")) >= 0)
   status = asprintf(&ret, "Et%d", n);
  else
   status = asprintf(&ret, "net %s", nsdev->name);
  break;
 case 0x04:
  status = asprintf(&ret, "vlan %d", nsdev->vlan);
  break;
 }
 return status == -1 ? ((void *)0) : ret;
}

user_defined_types: struct list_head { struct list_head *next; }


decompiled_code:
char *__fastcall if_get_name(int a1, int a2, char *a3)
{
char v5[16]; // [rsp+0h] [rbp-38h] BYREF
int v6; // [rsp+10h] [rbp-28h]

if ( a2 == -1 )
_assert_fail("sock_fd != -1", "if_generic.c", 0x63u, "if_get_name");
v6 = a1;
if ( ioctl(a2, 0x8910uLL, v5) )
return 0LL;
if ( a3 )
return strncpy(a3, v5, 0x10uLL);
return strdup(v5);
}

canonical_decompiled_code:
char *__fastcall func7(int a1, int a2, char *a3)
{
char v5[16]; // [rsp+0h] [rbp-38h] BYREF
int v6; // [rsp+10h] [rbp-28h]

if ( a2 == -1 )
_assert_fail("sock_fd != -1", "if_generic.c", 0x63u, "if_get_name");
v6 = a1;
if ( ioctl(a2, 0x8910uLL, v5) )
return 0LL;
if ( a3 )
return strncpy(a3, v5, 0x10uLL);
return strdup(v5);
}

original_code:
char *if_get_name(int if_index, int sock_fd, char *name)
{
 struct ifreq ifr;
 ((void) sizeof ((sock_fd != -1) ? 1 : 0), __extension__ ({ if (sock_fd != -1) ; else __assert_fail ("sock_fd != -1", "if_generic.c", 99, __extension__ __PRETTY_FUNCTION__); }));
 ifr.ifr_ifru.ifru_ivalue = if_index;
 if (ioctl(sock_fd, 0x8910, &ifr))
  return ((void *)0);
 if (!name)
  return strdup(ifr.ifr_ifrn.ifrn_name);
 strncpy(name, ifr.ifr_ifrn.ifrn_name, 16);
 return name;
}

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

user_defined_types: struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; }

user_defined_types: struct raw_hdlc_proto { unsigned short encoding; unsigned short parity; }

user_defined_types: struct cisco_proto { unsigned int interval; unsigned int timeout; }

user_defined_types: struct fr_proto { unsigned int t391; unsigned int t392; unsigned int n391; unsigned int n392; unsigned int n393; unsigned short lmi; unsigned short dce; }

user_defined_types: struct fr_proto_pvc { unsigned int dlci; }

user_defined_types: struct fr_proto_pvc_info { unsigned int dlci; char master[16]; }

user_defined_types: struct sync_serial_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; }

user_defined_types: struct te1_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; unsigned int slot_map; }


decompiled_code:
__int64 __fastcall if_get_addr(int a1, unsigned int a2, __int64 a3, char *a4)
{
char *v4; // rbx
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-58h] BYREF
int v7; // [rsp+8h] [rbp-50h]
char v8[72]; // [rsp+10h] [rbp-48h] BYREF

v4 = a4;
v6 = a3;
v7 = a1;
if ( !a4 )
{
if ( (unsigned int)rtnl_open(v8) )
return 0xFFFFFFFFLL;
v4 = v8;
}
if ( (int)rtnl_wilddump_request(v4, a2, 22LL) < 0 )
{
perror("Cannot send dump request");
result = 0xFFFFFFFFLL;
}
else if ( (int)rtnl_dump_filter(v4, if_build_ip_list, &v6) < 0 )
{
fwrite("Dump terminated\n", 1uLL, 0x10uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
if ( v4 == v8 )
{
rtnl_close(v8);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, unsigned int a2, __int64 a3, char *a4)
{
char *v4; // rbx
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-58h] BYREF
int v7; // [rsp+8h] [rbp-50h]
char v8[72]; // [rsp+10h] [rbp-48h] BYREF

v4 = a4;
v6 = a3;
v7 = a1;
if ( !a4 )
{
if ( (unsigned int)rtnl_open(v8) )
return 0xFFFFFFFFLL;
v4 = v8;
}
if ( (int)rtnl_wilddump_request(v4, a2, 22LL) < 0 )
{
perror("Cannot send dump request");
result = 0xFFFFFFFFLL;
}
else if ( (int)rtnl_dump_filter(v4, if_build_ip_list, &v6) < 0 )
{
fwrite("Dump terminated\n", 1uLL, 0x10uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
if ( v4 == v8 )
{
rtnl_close(v8);
result = 0LL;
}
}
return result;
}

original_code:
int if_get_addr(int ifindex, int af, struct list_head *lh, struct rtnl_handle *rth)
{
 struct rtnl_handle __rth;
 struct build_ip_list_priv priv = {
  .ifindex = ifindex,
  .lh = lh
 };
 if (rth == ((void *)0) && rtnl_open(rth = &__rth))
  return -1;
 if (rtnl_wilddump_request(rth, af, RTM_GETADDR) < 0) {
  perror("Cannot send dump request");
  return -1;
 }
 if (rtnl_dump_filter(rth, if_build_ip_list, &priv) < 0) {
  fprintf(stderr, "Dump terminated\n");
  return -1;
 }
 if (rth == &__rth)
  rtnl_close(rth);
 return 0;
}

variable_types: ifindex int

variable_types: af int

variable_types: struct rtnl_handle { int fd; struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; } local; struct sockaddr_nl peer; unsigned int seq; unsigned int dump; } *

variable_types: struct build_ip_list_priv { struct list_head { struct list_head *next; } *lh; int ifindex; }

user_defined_types: struct rtnl_handle { int fd; struct sockaddr_nl local; struct sockaddr_nl peer; unsigned int seq; unsigned int dump; }

user_defined_types: struct build_ip_list_priv { struct list_head *lh; int ifindex; }


decompiled_code:
void __fastcall list_del(__int64 a1)
{
_list_del(*(_QWORD **)(a1 + 8), *(_QWORD *)a1);
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
}

original_code:
static __inline__ void list_del(struct list_head *entry)
{
 __list_del(entry->prev, entry->next);
 entry->next = entry->prev = 0;
}

variable_types: struct list_head { struct list_head *next; } *

return_type: void


decompiled_code:
int telnet_listen()
{
int v0; // eax
int result; // eax
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 1, 0);
telnet_sockfd = v0;
if ( v0 == -1 )
__assert_fail("telnet_sockfd != -1", "swclid.c", 0x37u, "telnet_listen");
if ( setsockopt(v0, 1, 2, &yes, 4u) == -1 )
__assert_fail("status != -1", "swclid.c", 0x3Bu, "telnet_listen");
v2.sa_family = 2;
*(_WORD *)v2.sa_data = _bswap_16(23);
*(_DWORD *)&v2.sa_data[2] = 0;
if ( bind(telnet_sockfd, &v2, 0x10u) == -1 )
__assert_fail("status != -1", "swclid.c", 0x42u, "telnet_listen");
result = listen(telnet_sockfd, 10);
if ( result == -1 )
__assert_fail("status != -1", "swclid.c", 0x45u, "telnet_listen");
return result;
}

canonical_decompiled_code:
int func13()
{
int v0; // eax
int result; // eax
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 1, 0);
telnet_sockfd = v0;
if ( v0 == -1 )
__assert_fail("telnet_sockfd != -1", "swclid.c", 0x37u, "telnet_listen");
if ( setsockopt(v0, 1, 2, &yes, 4u) == -1 )
__assert_fail("status != -1", "swclid.c", 0x3Bu, "telnet_listen");
v2.sa_family = 2;
*(_WORD *)v2.sa_data = func11(23);
*(_DWORD *)&v2.sa_data[2] = 0;
if ( bind(telnet_sockfd, &v2, 0x10u) == -1 )
__assert_fail("status != -1", "swclid.c", 0x42u, "telnet_listen");
result = listen(telnet_sockfd, 10);
if ( result == -1 )
__assert_fail("status != -1", "swclid.c", 0x45u, "telnet_listen");
return result;
}

original_code:
void telnet_listen(void) {
 int status;
 struct sockaddr_in bind_addr;
 telnet_sockfd = socket(2, SOCK_STREAM, 0);
 ((void) sizeof ((telnet_sockfd != -1) ? 1 : 0), __extension__ ({ if (telnet_sockfd != -1) ; else __assert_fail ("telnet_sockfd != -1", "swclid.c", 55, __extension__ __PRETTY_FUNCTION__); }));
 status = setsockopt(telnet_sockfd, 1, 2, &yes,
   sizeof(int));
 ((void) sizeof ((status != -1) ? 1 : 0), __extension__ ({ if (status != -1) ; else __assert_fail ("status != -1", "swclid.c", 59, __extension__ __PRETTY_FUNCTION__); }));
 bind_addr.sin_family = 2;
 bind_addr.sin_port = htons(23);
 bind_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 status = bind(telnet_sockfd, (struct sockaddr *)&bind_addr,
   sizeof(struct sockaddr));
 ((void) sizeof ((status != -1) ? 1 : 0), __extension__ ({ if (status != -1) ; else __assert_fail ("status != -1", "swclid.c", 66, __extension__ __PRETTY_FUNCTION__); }));
 status = listen(telnet_sockfd, 10);
 ((void) sizeof ((status != -1) ? 1 : 0), __extension__ ({ if (status != -1) ; else __assert_fail ("status != -1", "swclid.c", 69, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void telnet_listen() {
 int status;
 struct sockaddr_in bind_addr;
 telnet_sockfd = socket(2, SOCK_STREAM, 0);
 ((void) sizeof ((telnet_sockfd != -1) ? 1 : 0), __extension__ ({ if (telnet_sockfd != -1) ; else __assert_fail ("telnet_sockfd != -1", "swclid.c", 55, __extension__ __PRETTY_FUNCTION__); }));
 status = setsockopt(telnet_sockfd, 1, 2, &yes,
   sizeof(int));
 ((void) sizeof ((status != -1) ? 1 : 0), __extension__ ({ if (status != -1) ; else __assert_fail ("status != -1", "swclid.c", 59, __extension__ __PRETTY_FUNCTION__); }));
 bind_addr.sin_family = 2;
 bind_addr.sin_port = htons(23);
 bind_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 status = bind(telnet_sockfd, (struct sockaddr *)&bind_addr,
   sizeof(struct sockaddr));
 ((void) sizeof ((status != -1) ? 1 : 0), __extension__ ({ if (status != -1) ; else __assert_fail ("status != -1", "swclid.c", 66, __extension__ __PRETTY_FUNCTION__); }));
 status = listen(telnet_sockfd, 10);
 ((void) sizeof ((status != -1) ? 1 : 0), __extension__ ({ if (status != -1) ; else __assert_fail ("status != -1", "swclid.c", 69, __extension__ __PRETTY_FUNCTION__); }));
}

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

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


decompiled_code:
void __fastcall destroy_telnet_conn(void *ptr)
{
list_del((__int64)ptr + 24);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func14(void *ptr)
{
func10((__int64)ptr + 24);
free(ptr);
}

original_code:
void destroy_telnet_conn(struct telnet_conn *c) {
 list_del(&c->lh);
 free(c);
}

variable_types: struct telnet_conn { int pid; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } remote_addr; struct list_head { struct list_head *next; } lh; } *

user_defined_types: struct telnet_conn { int pid; struct sockaddr_in remote_addr; struct list_head lh; }


decompiled_code:
int *test_rename_invalid()
{
int *result; // rax

if ( (unsigned int)switch_set_vlan_desc(0xFFFFFFFFLL, 0LL) != -1 )
_assert_fail("ret == -1", "vlan_rename.c", 0x26u, "test_rename_invalid");
result = _errno_location();
if ( *result != 22 )
_assert_fail("errno == EINVAL", "vlan_rename.c", 0x27u, "test_rename_invalid");
return result;
}

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

if ( (unsigned int)switch_set_vlan_desc(0xFFFFFFFFLL, 0LL) != -1 )
_assert_fail("ret == -1", "vlan_rename.c", 0x26u, "test_rename_invalid");
result = _errno_location();
if ( *result != 22 )
_assert_fail("errno == EINVAL", "vlan_rename.c", 0x27u, "test_rename_invalid");
return result;
}

original_code:
static void test_rename_invalid(void) {
 int ret;
 ret = switch_set_vlan_desc(-1, ((void *)0));
 ((void) sizeof ((ret == -1) ? 1 : 0), __extension__ ({ if (ret == -1) ; else __assert_fail ("ret == -1", "vlan_rename.c", 38, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((*__errno_location ()) == 22) ? 1 : 0), __extension__ ({ if ((*__errno_location ()) == 22) ; else __assert_fail ("errno == EINVAL", "vlan_rename.c", 39, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void test_rename_invalid() {
 int ret;
 ret = switch_set_vlan_desc(-1, ((void *)0));
 ((void) sizeof ((ret == -1) ? 1 : 0), __extension__ ({ if (ret == -1) ; else __assert_fail ("ret == -1", "vlan_rename.c", 38, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((*__errno_location ()) == 22) ? 1 : 0), __extension__ ({ if ((*__errno_location ()) == 22) ; else __assert_fail ("errno == EINVAL", "vlan_rename.c", 39, __extension__ __PRETTY_FUNCTION__); }));
}


decompiled_code:
int *test_rename_default()
{
int *result; // rax

if ( (unsigned int)switch_set_vlan_desc(1LL, 0LL) != -1 )
_assert_fail("ret == -1", "vlan_rename.c", 0x2Eu, "test_rename_default");
result = _errno_location();
if ( *result != 1 )
_assert_fail("errno == EPERM", "vlan_rename.c", 0x2Fu, "test_rename_default");
return result;
}

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

if ( (unsigned int)switch_set_vlan_desc(1LL, 0LL) != -1 )
_assert_fail("ret == -1", "vlan_rename.c", 0x2Eu, "test_rename_default");
result = _errno_location();
if ( *result != 1 )
_assert_fail("errno == EPERM", "vlan_rename.c", 0x2Fu, "test_rename_default");
return result;
}

original_code:
static void test_rename_default(void) {
 int ret;
 ret = switch_set_vlan_desc(1, ((void *)0));
 ((void) sizeof ((ret == -1) ? 1 : 0), __extension__ ({ if (ret == -1) ; else __assert_fail ("ret == -1", "vlan_rename.c", 46, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((*__errno_location ()) == 1) ? 1 : 0), __extension__ ({ if ((*__errno_location ()) == 1) ; else __assert_fail ("errno == EPERM", "vlan_rename.c", 47, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void test_rename_default() {
 int ret;
 ret = switch_set_vlan_desc(1, ((void *)0));
 ((void) sizeof ((ret == -1) ? 1 : 0), __extension__ ({ if (ret == -1) ; else __assert_fail ("ret == -1", "vlan_rename.c", 46, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((*__errno_location ()) == 1) ? 1 : 0), __extension__ ({ if ((*__errno_location ()) == 1) ; else __assert_fail ("errno == EPERM", "vlan_rename.c", 47, __extension__ __PRETTY_FUNCTION__); }));
}


decompiled_code:
__int64 test_rename_arbitrary()
{
int v0; // eax
int v1; // ebx
__int64 result; // rax
char v3[32]; // [rsp+0h] [rbp-68h] BYREF
char s2[32]; // [rsp+20h] [rbp-48h] BYREF
char s[40]; // [rsp+40h] [rbp-28h] BYREF

switch_init();
v0 = (*(__int64 (__fastcall **)(_QWORD, __int64))(sw_ops + 104LL))(sw_ops, 100LL);
v1 = v0;
if ( v0 == -1 )
{
if ( *_errno_location() != 17 )
_assert_fail("0", "vlan_rename.c", 0x3Cu, "test_rename_arbitrary");
strcpy(s, "new description");
if ( (unsigned int)switch_get_vlan_desc(100LL, v3) )
_assert_fail("ret == 0", "vlan_rename.c", 0x4Cu, "test_rename_arbitrary");
if ( !strcmp(s, v3) )
strcpy(s, "new desc");
}
else
{
if ( !v0 )
{
snprintf(s, 9uLL, "VLAN%04d", 100LL);
if ( (unsigned int)switch_set_vlan_desc(100LL, s) )
{
result = (*(__int64 (__fastcall **)(_QWORD, __int64))(sw_ops + 112LL))(sw_ops, 100LL);
if ( (_DWORD)result )
_assert_fail("ret == 0", "vlan_rename.c", 0x42u, "test_rename_arbitrary");
return result;
}
}
strcpy(s, "new description");
}
if ( (unsigned int)switch_set_vlan_desc(100LL, s) )
_assert_fail("ret == 0", "vlan_rename.c", 0x52u, "test_rename_arbitrary");
if ( (unsigned int)switch_get_vlan_desc(100LL, s2) )
_assert_fail("ret == 0", "vlan_rename.c", 0x54u, "test_rename_arbitrary");
if ( strcmp(s, s2) )
_assert_fail("strcmp(desc, eq_desc) == 0", "vlan_rename.c", 0x55u, "test_rename_arbitrary");
if ( v1 )
{
result = switch_set_vlan_desc(100LL, v3);
if ( (_DWORD)result )
_assert_fail("ret == 0", "vlan_rename.c", 0x61u, "test_rename_arbitrary");
}
else
{
if ( (*(unsigned int (__fastcall **)(_QWORD, __int64))(sw_ops + 112LL))(sw_ops, 100LL) )
_assert_fail("ret == 0", "vlan_rename.c", 0x5Au, "test_rename_arbitrary");
result = switch_del_vlan_desc(100LL);
if ( (_DWORD)result )
_assert_fail("ret == 0", "vlan_rename.c", 0x5Cu, "test_rename_arbitrary");
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
int v1; // ebx
__int64 result; // rax
char v3[32]; // [rsp+0h] [rbp-68h] BYREF
char s2[32]; // [rsp+20h] [rbp-48h] BYREF
char s[40]; // [rsp+40h] [rbp-28h] BYREF

switch_init();
v0 = (*(__int64 (__fastcall **)(_QWORD, __int64))(sw_ops + 104LL))(sw_ops, 100LL);
v1 = v0;
if ( v0 == -1 )
{
if ( *_errno_location() != 17 )
_assert_fail("0", "vlan_rename.c", 0x3Cu, "test_rename_arbitrary");
strcpy(s, "new description");
if ( (unsigned int)switch_get_vlan_desc(100LL, v3) )
_assert_fail("ret == 0", "vlan_rename.c", 0x4Cu, "test_rename_arbitrary");
if ( !strcmp(s, v3) )
strcpy(s, "new desc");
}
else
{
if ( !v0 )
{
snprintf(s, 9uLL, "VLAN%04d", 100LL);
if ( (unsigned int)switch_set_vlan_desc(100LL, s) )
{
result = (*(__int64 (__fastcall **)(_QWORD, __int64))(sw_ops + 112LL))(sw_ops, 100LL);
if ( (_DWORD)result )
_assert_fail("ret == 0", "vlan_rename.c", 0x42u, "test_rename_arbitrary");
return result;
}
}
strcpy(s, "new description");
}
if ( (unsigned int)switch_set_vlan_desc(100LL, s) )
_assert_fail("ret == 0", "vlan_rename.c", 0x52u, "test_rename_arbitrary");
if ( (unsigned int)switch_get_vlan_desc(100LL, s2) )
_assert_fail("ret == 0", "vlan_rename.c", 0x54u, "test_rename_arbitrary");
if ( strcmp(s, s2) )
_assert_fail("strcmp(desc, eq_desc) == 0", "vlan_rename.c", 0x55u, "test_rename_arbitrary");
if ( v1 )
{
result = switch_set_vlan_desc(100LL, v3);
if ( (_DWORD)result )
_assert_fail("ret == 0", "vlan_rename.c", 0x61u, "test_rename_arbitrary");
}
else
{
if ( (*(unsigned int (__fastcall **)(_QWORD, __int64))(sw_ops + 112LL))(sw_ops, 100LL) )
_assert_fail("ret == 0", "vlan_rename.c", 0x5Au, "test_rename_arbitrary");
result = switch_del_vlan_desc(100LL);
if ( (_DWORD)result )
_assert_fail("ret == 0", "vlan_rename.c", 0x5Cu, "test_rename_arbitrary");
}
return result;
}

original_code:
static void test_rename_arbitrary(void) {
 int add_ret, ret;
 char desc[31 + 1], eq_desc[31 + 1];
 char bkp_desc[31 + 1];
 switch_init();
 add_ret = sw_ops->vlan_add(sw_ops, 100);
 if (add_ret == -1 && (*__errno_location ()) != 17)
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "vlan_rename.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 if (add_ret == 0) {
  snprintf(desc, 9, "VLAN%04d", (100));
  ret = switch_set_vlan_desc(100, desc);
  if (ret) {
   ret = sw_ops->vlan_del(sw_ops, 100);
   ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 66, __extension__ __PRETTY_FUNCTION__); }));
   return;
  }
 }
 strcpy(desc, "new description");
 if (add_ret == -1) {
  ret = switch_get_vlan_desc(100, bkp_desc);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 76, __extension__ __PRETTY_FUNCTION__); }));
  if (strcmp(desc, bkp_desc) == 0)
   strcpy(desc, "new desc");
 }
 ret = switch_set_vlan_desc(100, desc);
 ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 82, __extension__ __PRETTY_FUNCTION__); }));
 ret= switch_get_vlan_desc(100, eq_desc);
 ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 84, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((strcmp(desc, eq_desc) == 0) ? 1 : 0), __extension__ ({ if (strcmp(desc, eq_desc) == 0) ; else __assert_fail ("strcmp(desc, eq_desc) == 0", "vlan_rename.c", 85, __extension__ __PRETTY_FUNCTION__); }));
 if (add_ret == 0) {
  ret = sw_ops->vlan_del(sw_ops, 100);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 90, __extension__ __PRETTY_FUNCTION__); }));
  ret = switch_del_vlan_desc(100);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 92, __extension__ __PRETTY_FUNCTION__); }));
 }
 else {
  ret = switch_set_vlan_desc(100, bkp_desc);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 97, __extension__ __PRETTY_FUNCTION__); }));
 }
}

canonical_original_code:
static void test_rename_arbitrary() {
 int add_ret; int ret;
 char desc[-1]; char eq_desc[-1];
 char bkp_desc[-1];
 switch_init();
 add_ret = sw_ops->vlan_add(sw_ops, 100);
 if (add_ret == -1 && (*__errno_location ()) != 17)
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "vlan_rename.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 if (add_ret == 0) {
  snprintf(desc, 9, "VLAN%04d", (100));
  ret = switch_set_vlan_desc(100, desc);
  if (ret) {
   ret = sw_ops->vlan_del(sw_ops, 100);
   ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 66, __extension__ __PRETTY_FUNCTION__); }));
   return;
  }
 }
 strcpy(desc, "new description");
 if (add_ret == -1) {
  ret = switch_get_vlan_desc(100, bkp_desc);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 76, __extension__ __PRETTY_FUNCTION__); }));
  if (strcmp(desc, bkp_desc) == 0)
   strcpy(desc, "new desc");
 }
 ret = switch_set_vlan_desc(100, desc);
 ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 82, __extension__ __PRETTY_FUNCTION__); }));
 ret= switch_get_vlan_desc(100, eq_desc);
 ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 84, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((strcmp(desc, eq_desc) == 0) ? 1 : 0), __extension__ ({ if (strcmp(desc, eq_desc) == 0) ; else __assert_fail ("strcmp(desc, eq_desc) == 0", "vlan_rename.c", 85, __extension__ __PRETTY_FUNCTION__); }));
 if (add_ret == 0) {
  ret = sw_ops->vlan_del(sw_ops, 100);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 90, __extension__ __PRETTY_FUNCTION__); }));
  ret = switch_del_vlan_desc(100);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 92, __extension__ __PRETTY_FUNCTION__); }));
 }
 else {
  ret = switch_set_vlan_desc(100, bkp_desc);
  ((void) sizeof ((ret == 0) ? 1 : 0), __extension__ ({ if (ret == 0) ; else __assert_fail ("ret == 0", "vlan_rename.c", 97, __extension__ __PRETTY_FUNCTION__); }));
 }
}

variable_types:
desc
char [-1]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_rename_invalid();
puts("Rename Invalid test susccesful");
test_rename_default();
puts("Rename Default test susccesful");
test_rename_arbitrary("Rename Default test susccesful", argv);
puts("Rename vlan tests susccesful");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0();
puts("Rename Invalid test susccesful");
func1();
puts("Rename Default test susccesful");
func2("Rename Default test susccesful", argv);
puts("Rename vlan tests susccesful");
return 0;
}

original_code:
int main(int argc, char **argv) {
 test_rename_invalid();
 printf("Rename Invalid test susccesful\n");
 test_rename_default();
 printf("Rename Default test susccesful\n");
 test_rename_arbitrary();
 printf("Rename vlan tests susccesful\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall cli_mask_apply(int *a1, int a2)
{
int v2; // eax

if ( !a1 )
return 1LL;
v2 = *a1;
if ( !*a1 )
return 1LL;
while ( (v2 & a2) != 0 )
{
v2 = *++a1;
if ( !*a1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int a2)
{
int v2; // eax

if ( !a1 )
return 1LL;
v2 = *a1;
if ( !*a1 )
return 1LL;
while ( (v2 & a2) != 0 )
{
v2 = *++a1;
if ( !*a1 )
return 1LL;
}
return 0LL;
}

original_code:
static __inline__ int cli_mask_apply(uint32_t *mask, uint32_t filter) {
 if (!mask)
  return 1;
 while (*mask) {
  if (!(*mask & filter))
   return 0;
  mask++;
 }
 return 1;
}

canonical_original_code:
static __inline__ int cli_mask_apply(unsigned int *mask, unsigned int filter) {
 if (!mask)
  return 1;
 while (*mask) {
  if (!(*mask & filter))
   return 0;
  mask++;
 }
 return 1;
}

variable_types:
mask
unsigned int *

variable_types:
filter
unsigned int


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

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

original_code:
int rlshell_ctrl_l(int i, int j)
{
 return 0;
}

variable_types: i int

variable_types: j int


decompiled_code:
__int64 rlshell_ctrl_z()
{
if ( *(_DWORD *)(currctx + 92) )
{
puts("^Z");
ctrl_z = 1;
rl_done = 1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
if ( *(_DWORD *)(currctx + 92) )
{
puts("^Z");
ctrl_z = 1;
rl_done = 1;
}
return 0LL;
}

original_code:
int rlshell_ctrl_z(int i, int j)
{
 if (!currctx->enable_ctrl_z)
  return 0;
 printf("^Z\n");
 ctrl_z = 1;
 rl_done = 1;
 return 0;
}


decompiled_code:
__int64 rlshell_ctrl_c()
{
putchar(10);
rl_replace_line(&LC2, 1LL);
rl_forced_update_display();
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
putchar(10);
rl_replace_line(&LC2, 1LL);
rl_forced_update_display();
return 0LL;
}

original_code:
int rlshell_ctrl_c(int i, int j)
{
 printf("\n");
 rl_replace_line("", 1);
 rl_forced_update_display();
 return 0;
}


decompiled_code:
int rlshell_prep_terminal()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

rl_prep_terminal();
tcgetattr(0, &v1);
v1.c_lflag &= 0xFFFFFFFE;
return tcsetattr(0, 0, &v1);
}

canonical_decompiled_code:
int func5()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

rl_prep_terminal();
tcgetattr(0, &v1);
v1.c_lflag &= 0xFFFFFFFE;
return tcsetattr(0, 0, &v1);
}

original_code:
void rlshell_prep_terminal(int meta_flag)
{
 struct termios t;
 rl_prep_terminal(meta_flag);
 tcgetattr(0, &t);
 t.c_lflag &= ~0000001;
 tcsetattr(0, 0, &t);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
int rlshell_invalid_cmd()
{
return printf("%% Unrecognized command\n");
}

canonical_decompiled_code:
int func7()
{
return printf("%% Unrecognized command\n");
}

original_code:
void rlshell_invalid_cmd(void)
{
 printf("%% Unrecognized command\n");
}

canonical_original_code:
void rlshell_invalid_cmd()
{
 printf("%% Unrecognized command\n");
}


decompiled_code:
int __fastcall rlshell_ambiguous_cmd(const char *a1)
{
return printf("%% Ambiguous command: \"%s\"\n", a1);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
return printf("%% Ambiguous command: \"%s\"\n", a1);
}

original_code:
void rlshell_ambiguous_cmd(char *cmd)
{
 printf("%% Ambiguous command: \"%s\"\n", cmd);
}

variable_types:
cmd
char *


decompiled_code:
int rlshell_incomplete_cmd()
{
return printf("%% Incomplete command.\n");
}

canonical_decompiled_code:
int func9()
{
return printf("%% Incomplete command.\n");
}

original_code:
void rlshell_incomplete_cmd(char *cmd)
{
 printf("%% Incomplete command.\n");
}


decompiled_code:
int __fastcall rlshell_extra_input(unsigned int a1)
{
char s[18]; // [rsp+6h] [rbp-12h] BYREF

snprintf(s, 0xAuLL, "%%%dc^\n", a1);
printf(s, 32LL);
return printf("%% Invalid input detected at '^' marker.\n\n");
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1)
{
char s[18]; // [rsp+6h] [rbp-12h] BYREF

snprintf(s, 0xAuLL, "%%%dc^\n", a1);
printf(s, 32LL);
return printf("%% Invalid input detected at '^' marker.\n\n");
}

original_code:
void rlshell_extra_input(int off)
{
 char fmt[10];
 snprintf(fmt, sizeof(fmt), "%%%dc^\n", off);
 printf(fmt, ' ');
 printf("%% Invalid input detected at '^' marker.\n\n");
}

variable_types: off int

variable_types:
fmt
char [10]


decompiled_code:
void __fastcall rlshell_rejected_cmd(void *ptr)
{
if ( ptr )
{
printf("Command rejected: %s\n", (const char *)ptr);
free(ptr);
}
else
{
puts("Command rejected");
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
if ( ptr )
{
printf("Command rejected: %s\n", (const char *)ptr);
free(ptr);
}
else
{
puts("Command rejected");
}
}

original_code:
void rlshell_rejected_cmd(char *reason)
{
 if (reason == ((void *)0))
  printf("Command rejected\n");
 else {
  printf("Command rejected: %s\n", reason);
  free(reason);
 }
}

variable_types:
reason
char *


decompiled_code:
void __fastcall rlshell_warning_cmd(void *ptr)
{
if ( ptr )
{
puts((const char *)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
if ( ptr )
{
puts((const char *)ptr);
free(ptr);
}
}

original_code:
void rlshell_warning_cmd(char *reason)
{
 if (reason == ((void *)0))
  return;
 puts(reason);
 free(reason);
}


decompiled_code:
int rlshell_go_ahead()
{
return puts(" <cr>");
}

canonical_decompiled_code:
int func13()
{
return puts(" <cr>");
}

original_code:
void rlshell_go_ahead(void)
{
 printf("  <cr>\n");
}

canonical_original_code:
void rlshell_go_ahead()
{
 printf("  <cr>\n");
}


decompiled_code:
__int64 rlshell_init()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax

rl_readline_name = "rlshell";
rl_prep_term_function = rlshell_prep_terminal;
rl_bind_key(63LL, rlshell_help);
rl_bind_key(9LL, rlshell_completion);
v0 = rl_get_keymap();
rl_set_key("\\C-l", rlshell_ctrl_l, v0);
v1 = rl_get_keymap();
rl_set_key("\\C-z", rlshell_ctrl_z, v1);
v2 = rl_get_keymap();
rl_set_key("\\C-c", rlshell_ctrl_c, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 func18()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax

rl_readline_name = "rlshell";
rl_prep_term_function = rlshell_prep_terminal;
rl_bind_key(63LL, rlshell_help);
rl_bind_key(9LL, rlshell_completion);
v0 = rl_get_keymap();
rl_set_key("\\C-l", rlshell_ctrl_l, v0);
v1 = rl_get_keymap();
rl_set_key("\\C-z", rlshell_ctrl_z, v1);
v2 = rl_get_keymap();
rl_set_key("\\C-c", rlshell_ctrl_c, v2);
return 0LL;
}

original_code:
int rlshell_init(void)
{
 ;
 rl_readline_name = "rlshell";
 rl_prep_term_function = rlshell_prep_terminal;
 rl_bind_key('?', rlshell_help);
 rl_bind_key('\t', rlshell_completion);
 rl_set_key("\\C-l", rlshell_ctrl_l, rl_get_keymap());
 rl_set_key("\\C-z", rlshell_ctrl_z, rl_get_keymap());
 rl_set_key("\\C-c", rlshell_ctrl_c, rl_get_keymap());
 return 0;
}

canonical_original_code:
int rlshell_init()
{
 ;
 rl_readline_name = "rlshell";
 rl_prep_term_function = rlshell_prep_terminal;
 rl_bind_key('?', rlshell_help);
 rl_bind_key('\t', rlshell_completion);
 rl_set_key("\\C-l", rlshell_ctrl_l, rl_get_keymap());
 rl_set_key("\\C-z", rlshell_ctrl_z, rl_get_keymap());
 rl_set_key("\\C-c", rlshell_ctrl_c, rl_get_keymap());
 return 0;
}


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

if ( !ptr )
_assert_fail("s", "rstp_client.c", 0x3Fu, "rstp_session_end");
v2 = (void *)*((_QWORD *)ptr + 9);
if ( v2 )
free(v2);
if ( *(_DWORD *)ptr != -1 )
mq_close();
if ( *((_DWORD *)ptr + 1) != -1 )
{
mq_close();
mq_unlink((char *)ptr + 40);
}
free(ptr);
}

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

if ( !ptr )
_assert_fail("s", "rstp_client.c", 0x3Fu, "rstp_session_end");
v2 = (void *)*((_QWORD *)ptr + 9);
if ( v2 )
free(v2);
if ( *(_DWORD *)ptr != -1 )
mq_close();
if ( *((_DWORD *)ptr + 1) != -1 )
{
mq_close();
mq_unlink((char *)ptr + 40);
}
free(ptr);
}

original_code:
void
rstp_session_end(struct rstp_session *s)
{
 ((void) sizeof ((s) ? 1 : 0), __extension__ ({ if (s) ; else __assert_fail ("s", "rstp_client.c", 63, __extension__ __PRETTY_FUNCTION__); }));
 if (s->response)
  free(s->response);
 if (s->sq != -1) {
  mq_close(s->sq);
 }
 if (s->rq != -1) {
  mq_close(s->rq);
  mq_unlink(s->rq_name);
 }
 free(s);
}

variable_types: struct rstp_session { int sq; char sq_name[32]; char *response; int max_msg_len; } *


decompiled_code:
char *rstp_session_start()
{
char *v0; // rax
char *v1; // rbx
char *v2; // rbp
int v3; // eax
unsigned int v4; // eax
int v5; // eax
int v6; // edi
void *v7; // rax
__int64 v9; // [rsp+0h] [rbp-58h] BYREF
__int64 v10; // [rsp+10h] [rbp-48h]

v0 = (char *)malloc(0x58uLL);
v1 = v0;
if ( v0 )
{
*((_QWORD *)v0 + 5) = 0LL;
*((_QWORD *)v0 + 6) = 0LL;
*((_QWORD *)v0 + 7) = 0LL;
*((_QWORD *)v0 + 8) = 0LL;
*((_QWORD *)v0 + 9) = 0LL;
*((_QWORD *)v0 + 10) = 0LL;
*((_DWORD *)v0 + 1) = -1;
*(_DWORD *)v0 = -1;
v2 = v0 + 8;
*((_QWORD *)v0 + 1) = 0LL;
*((_QWORD *)v0 + 2) = 0LL;
*((_QWORD *)v0 + 3) = 0LL;
*((_QWORD *)v0 + 4) = 0LL;
snprintf(v0 + 8, 0x20uLL, "/lisa-rstp-%d", 0LL);
v1[39] = 0;
v3 = mq_open(v2, 1LL);
*(_DWORD *)v1 = v3;
if ( v3 < 0 )
{
perror("Could not open send queue\n");
}
else
{
*((_QWORD *)v1 + 5) = 0LL;
*((_QWORD *)v1 + 6) = 0LL;
*((_QWORD *)v1 + 7) = 0LL;
*((_QWORD *)v1 + 8) = 0LL;
v4 = getpid();
snprintf(v1 + 40, 0x20uLL, "/lisa-rstp-%d", v4);
v1[71] = 0;
v5 = mq_open(v1 + 40, 64LL);
*((_DWORD *)v1 + 1) = v5;
if ( v5 < 0 )
{
puts("Could not open recv queue");
}
else if ( (int)mq_getattr((unsigned int)v5, &v9) < 0 )
{
puts("Could not get attributes");
}
else
{
v6 = v10;
*((_DWORD *)v1 + 20) = v10;
v7 = malloc(v6);
*((_QWORD *)v1 + 9) = v7;
if ( v7 )
return v1;
puts("Could not allocate mem");
}
}
rstp_session_end(v1);
v1 = 0LL;
}
return v1;
}

canonical_decompiled_code:
char *func1()
{
char *v0; // rax
char *v1; // rbx
char *v2; // rbp
int v3; // eax
unsigned int v4; // eax
int v5; // eax
int v6; // edi
void *v7; // rax
__int64 v9; // [rsp+0h] [rbp-58h] BYREF
__int64 v10; // [rsp+10h] [rbp-48h]

v0 = (char *)malloc(0x58uLL);
v1 = v0;
if ( v0 )
{
*((_QWORD *)v0 + 5) = 0LL;
*((_QWORD *)v0 + 6) = 0LL;
*((_QWORD *)v0 + 7) = 0LL;
*((_QWORD *)v0 + 8) = 0LL;
*((_QWORD *)v0 + 9) = 0LL;
*((_QWORD *)v0 + 10) = 0LL;
*((_DWORD *)v0 + 1) = -1;
*(_DWORD *)v0 = -1;
v2 = v0 + 8;
*((_QWORD *)v0 + 1) = 0LL;
*((_QWORD *)v0 + 2) = 0LL;
*((_QWORD *)v0 + 3) = 0LL;
*((_QWORD *)v0 + 4) = 0LL;
snprintf(v0 + 8, 0x20uLL, "/lisa-rstp-%d", 0LL);
v1[39] = 0;
v3 = mq_open(v2, 1LL);
*(_DWORD *)v1 = v3;
if ( v3 < 0 )
{
perror("Could not open send queue\n");
}
else
{
*((_QWORD *)v1 + 5) = 0LL;
*((_QWORD *)v1 + 6) = 0LL;
*((_QWORD *)v1 + 7) = 0LL;
*((_QWORD *)v1 + 8) = 0LL;
v4 = getpid();
snprintf(v1 + 40, 0x20uLL, "/lisa-rstp-%d", v4);
v1[71] = 0;
v5 = mq_open(v1 + 40, 64LL);
*((_DWORD *)v1 + 1) = v5;
if ( v5 < 0 )
{
puts("Could not open recv queue");
}
else if ( (int)mq_getattr((unsigned int)v5, &v9) < 0 )
{
puts("Could not get attributes");
}
else
{
v6 = v10;
*((_DWORD *)v1 + 20) = v10;
v7 = malloc(v6);
*((_QWORD *)v1 + 9) = v7;
if ( v7 )
return v1;
puts("Could not allocate mem");
}
}
func0(v1);
v1 = 0LL;
}
return v1;
}

original_code:
struct rstp_session *
rstp_session_start(void)
{
 struct rstp_session *s;
 struct mq_attr attr;
 if (!(s = (struct rstp_session *)malloc(sizeof(struct rstp_session))))
  return ((void *)0);
 memset(s, 0, sizeof(struct rstp_session));
 s->sq = s->rq = -1;
 memset(s->sq_name, 0, sizeof(s->sq_name));
 snprintf(s->sq_name, sizeof(s->sq_name), "/lisa-rstp-%d", 0);
 s->sq_name[sizeof(s->sq_name) - 1] = '\0';
 if ((s->sq = mq_open(s->sq_name, 01)) < 0) {
  perror("Could not open send queue\n");
  goto out_err;
 }
 memset(s->rq_name, 0, sizeof(s->rq_name));
 snprintf(s->rq_name, sizeof(s->rq_name), "/lisa-rstp-%d", getpid());
 s->rq_name[sizeof(s->rq_name) - 1] = '\0';
 if ((s->rq = mq_open(s->rq_name, 0100 | 00, 0666, ((void *)0))) < 0) {
  printf("Could not open recv queue\n");
  goto out_err;
 }
 if (mq_getattr(s->rq, &attr) < 0) {
  printf("Could not get attributes\n");
  goto out_err;
 }
 s->max_msg_len = attr.mq_msgsize;
 if (!(s->response = malloc(s->max_msg_len))) {
  printf("Could not allocate mem\n");
  goto out_err;
 }
 return s;
out_err:
 rstp_session_end(s);
 return ((void *)0);
}

canonical_original_code:
struct rstp_session *rstp_session_start()
{
 struct rstp_session *s;
 struct mq_attr attr;
 if (!(s = (struct rstp_session *)malloc(sizeof(struct rstp_session))))
  return ((void *)0);
 memset(s, 0, sizeof(struct rstp_session));
 s->sq = s->rq = -1;
 memset(s->sq_name, 0, sizeof(s->sq_name));
 snprintf(s->sq_name, sizeof(s->sq_name), "/lisa-rstp-%d", 0);
 s->sq_name[sizeof(s->sq_name) - 1] = '\0';
 if ((s->sq = mq_open(s->sq_name, 01)) < 0) {
  perror("Could not open send queue\n");
  goto out_err;
 }
 memset(s->rq_name, 0, sizeof(s->rq_name));
 snprintf(s->rq_name, sizeof(s->rq_name), "/lisa-rstp-%d", getpid());
 s->rq_name[sizeof(s->rq_name) - 1] = '\0';
 if ((s->rq = mq_open(s->rq_name, 0100 | 00, 0666, ((void *)0))) < 0) {
  printf("Could not open recv queue\n");
  goto out_err;
 }
 if (mq_getattr(s->rq, &attr) < 0) {
  printf("Could not get attributes\n");
  goto out_err;
 }
 s->max_msg_len = attr.mq_msgsize;
 if (!(s->response = malloc(s->max_msg_len))) {
  printf("Could not allocate mem\n");
  goto out_err;
 }
 return s;
out_err:
 rstp_session_end(s);
 return ((void *)0);
}

variable_types: struct mq_attr { long mq_flags; long mq_maxmsg; long mq_msgsize; long mq_curmsgs; long __pad[4]; }

return_type: struct rstp_session { int sq; char sq_name[32]; char *response; int max_msg_len; } *


decompiled_code:
__int64 __fastcall rstp_session_recv(__int64 a1)
{
int v1; // ebx
time_t timer; // [rsp+8h] [rbp-30h] BYREF
__int64 v4[5]; // [rsp+10h] [rbp-28h] BYREF

if ( !a1 )
_assert_fail("s", "rstp_client.c", 0x55u, "rstp_session_recv");
v4[0] = 0LL;
v4[1] = 0LL;
time(&timer);
v4[0] = timer + 3;
v1 = mq_timedreceive(*(unsigned int *)(a1 + 4), *(_QWORD *)(a1 + 72), *(int *)(a1 + 80), 0LL, v4);
if ( v1 < 0 )
fprintf(stderr, "No message received from rstpd in %d seconds.\nDisabling rstp in this session.\n", 3LL);
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // ebx
time_t timer; // [rsp+8h] [rbp-30h] BYREF
__int64 v4[5]; // [rsp+10h] [rbp-28h] BYREF

if ( !a1 )
_assert_fail("s", "rstp_client.c", 0x55u, "rstp_session_recv");
v4[0] = 0LL;
v4[1] = 0LL;
time(&timer);
v4[0] = timer + 3;
v1 = mq_timedreceive(*(unsigned int *)(a1 + 4), *(_QWORD *)(a1 + 72), *(int *)(a1 + 80), 0LL, v4);
if ( v1 < 0 )
fprintf(stderr, "No message received from rstpd in %d seconds.\nDisabling rstp in this session.\n", 3LL);
return (unsigned int)v1;
}

original_code:
int
rstp_session_recv(struct rstp_session *s)
{
 struct timespec ts;
 time_t ns;
 int err;
 ((void) sizeof ((s) ? 1 : 0), __extension__ ({ if (s) ; else __assert_fail ("s", "rstp_client.c", 85, __extension__ __PRETTY_FUNCTION__); }));
 memset(&ts, 0, sizeof(ts));
 time(&ns);
 ts.tv_sec = ns + 3;
 if ((err = mq_timedreceive(s->rq, s->response, s->max_msg_len, ((void *)0), &ts)) < 0) {
  fprintf(stderr, "No message received from rstpd in %d seconds.\n"
   "Disabling rstp in this session.\n", 3);
 }
 return err;
}

canonical_original_code:
int rstp_session_recv(struct rstp_session *s)
{
 struct timespec ts;
 long ns;
 int err;
 ((void) sizeof ((s) ? 1 : 0), __extension__ ({ if (s) ; else __assert_fail ("s", "rstp_client.c", 85, __extension__ __PRETTY_FUNCTION__); }));
 memset(&ts, 0, sizeof(ts));
 time(&ns);
 ts.tv_sec = ns + 3;
 if ((err = mq_timedreceive(s->rq, s->response, s->max_msg_len, ((void *)0), &ts)) < 0) {
  fprintf(stderr, "No message received from rstpd in %d seconds.\n"
   "Disabling rstp in this session.\n", 3);
 }
 return err;
}

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

variable_types: ns long

variable_types: err int

user_defined_types: struct rstp_session { int sq; char sq_name[32]; char *response; int max_msg_len; }


decompiled_code:
__int64 __fastcall rstp_set_interface(unsigned int *a1, int a2, int a3)
{
int v3; // ebx
int v5[26]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "rstp_client.c", 0x69u, "rstp_set_interface");
memset(v5, 0, 0x48uLL);
v5[18] = 0;
v5[0] = a3 == 0;
v5[1] = getpid();
v5[2] = a2;
v3 = mq_send(*a1, v5, 76LL, 0LL);
if ( v3 < 0 )
perror("rstp_session_send");
else
v3 = 10;
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, int a2, int a3)
{
int v3; // ebx
int v5[26]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "rstp_client.c", 0x69u, "rstp_set_interface");
memset(v5, 0, 0x48uLL);
v5[18] = 0;
v5[0] = a3 == 0;
v5[1] = getpid();
v5[2] = a2;
v3 = mq_send(*a1, v5, 76LL, 0LL);
if ( v3 < 0 )
perror("rstp_session_send");
else
v3 = 10;
return (unsigned int)v3;
}

original_code:
int
rstp_set_interface(struct rstp_session *session, int if_index, int enabled)
{
 struct rstp_request m;
 int err;
 ((void) sizeof ((session) ? 1 : 0), __extension__ ({ if (session) ; else __assert_fail ("session", "rstp_client.c", 105, __extension__ __PRETTY_FUNCTION__); }));
 memset(&m, 0, sizeof(m));
 m.type = enabled ? RSTP_IF_ENABLE : RSTP_IF_DISABLE;
 m.pid = getpid();
 m.if_index = if_index;
 if ((err = ({ int r = mq_send(session->sq, (const char *)&m, sizeof(m), 0); r; })) < 0) {
  perror("rstp_session_send");
  return err;
 }
 return 10;
}

variable_types: enabled int

variable_types: struct rstp_request { int type; int pid; int if_index; char device_id[64]; }

variable_types: r int


decompiled_code:
__int64 __fastcall get_integer(_DWORD *a1, const char *a2, int a3)
{
__int64 v3; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
if ( !*a2 )
return 0xFFFFFFFFLL;
v3 = strtol(a2, &endptr, a3);
if ( endptr == a2 || !endptr )
return 0xFFFFFFFFLL;
if ( *endptr )
return 0xFFFFFFFFLL;
if ( (unsigned __int64)(v3 + 0x80000000LL) > 0xFFFFFFFF )
return 0xFFFFFFFFLL;
*a1 = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, const char *a2, int a3)
{
__int64 v3; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
if ( !*a2 )
return 0xFFFFFFFFLL;
v3 = strtol(a2, &endptr, a3);
if ( endptr == a2 || !endptr )
return 0xFFFFFFFFLL;
if ( *endptr )
return 0xFFFFFFFFLL;
if ( (unsigned __int64)(v3 + 0x80000000LL) > 0xFFFFFFFF )
return 0xFFFFFFFFLL;
*a1 = v3;
return 0LL;
}

original_code:
int get_integer(int *val, const char *arg, int base) {
 long res;
 char *ptr;
 if (!arg || !*arg)
  return -1;
 res = strtol(arg, &ptr, base);
 if (!ptr || ptr == arg || *ptr || res > 0x7fffffff || res < (-0x7fffffff - 1))
  return -1;
 *val = res;
 return 0;
}

canonical_original_code:
int get_integer(int *val, char *arg, int base) {
 long res;
 char *ptr;
 if (!arg || !*arg)
  return -1;
 res = strtol(arg, &ptr, base);
 if (!ptr || ptr == arg || *ptr || res > 0x7fffffff || res < (-0x7fffffff - 1))
  return -1;
 *val = res;
 return 0;
}

variable_types:
val
int *

variable_types:
arg
char *

variable_types: base int

variable_types: res long

variable_types:
ptr
char *


decompiled_code:
__int64 __fastcall parse_rtattr(__int64 a1, int a2, unsigned __int16 *a3, int a4)
{
int i; // esi
unsigned int v7; // eax
unsigned __int16 v8; // ax

for ( i = a4; i > 3; a3 = (unsigned __int16 *)((char *)a3 + v7) )
{
if ( *a3 <= 3u || *a3 > i )
break;
v8 = a3[1];
if ( v8 <= a2 )
*(_QWORD *)(a1 + 8LL * v8) = a3;
v7 = (*a3 + 3) & 0xFFFFFFFC;
i -= v7;
}
if ( i )
fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", (unsigned int)i, *a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, unsigned __int16 *a3, int a4)
{
int i; // esi
unsigned int v7; // eax
unsigned __int16 v8; // ax

for ( i = a4; i > 3; a3 = (unsigned __int16 *)((char *)a3 + v7) )
{
if ( *a3 <= 3u || *a3 > i )
break;
v8 = a3[1];
if ( v8 <= a2 )
*(_QWORD *)(a1 + 8LL * v8) = a3;
v7 = (*a3 + 3) & 0xFFFFFFFC;
i -= v7;
}
if ( i )
fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", (unsigned int)i, *a3);
return 0LL;
}

original_code:
int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) {
 while (((len) >= (int)sizeof(struct rtattr) && (rta)->rta_len >= sizeof(struct rtattr) && (rta)->rta_len <= (len))) {
  if (rta->rta_type <= max)
   tb[rta->rta_type] = rta;
  rta = ((len) -= ( (((rta)->rta_len)+4U -1) & ~(4U -1) ), (struct rtattr*)(((char*)(rta)) + ( (((rta)->rta_len)+4U -1) & ~(4U -1) )));
 }
 if (len)
  fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
 return 0;
}

canonical_original_code:
int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) {
 while (((len) >= (int)sizeof(struct rtattr) && (rta)->rta_len >= sizeof(struct rtattr) && (rta)->rta_len <= (len))) {
  if (rta->rta_type <= max)
   tb[rta->rta_type] = rta;
  rta = ((len) -= ( (((rta)->rta_len)+4U -1) & ~(4U -1) ), (struct rtattr *)(((char *)(rta)) + ( (((rta)->rta_len)+4U -1) & ~(4U -1) )));
 }
 if (len)
  fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
 return 0;
}

variable_types: struct rtattr { unsigned short rta_len; unsigned short rta_type; } *[]

variable_types: max int

variable_types:
rta
struct rtattr *

variable_types: len int


decompiled_code:
__int64 __fastcall addattr_l(_DWORD *a1, unsigned int a2, __int16 a3, const void *a4, int a5)
{
int v6; // ebp
unsigned int v7; // edi
_WORD *v8; // rdi
__int64 result; // rax

v6 = a5 + 4;
v7 = (*a1 + 3) & 0xFFFFFFFC;
if ( a5 + 4 + v7 > a2 )
{
fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n", a2);
result = 0xFFFFFFFFLL;
}
else
{
v8 = (_WORD *)((char *)a1 + v7);
v8[1] = a3;
*v8 = a5 + 4;
memcpy(v8 + 2, a4, a5);
*a1 = ((*a1 + 3) & 0xFFFFFFFC) + v6;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1, unsigned int a2, __int16 a3, const void *a4, int a5)
{
int v6; // ebp
unsigned int v7; // edi
_WORD *v8; // rdi
__int64 result; // rax

v6 = a5 + 4;
v7 = (*a1 + 3) & 0xFFFFFFFC;
if ( a5 + 4 + v7 > a2 )
{
fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n", a2);
result = 0xFFFFFFFFLL;
}
else
{
v8 = (_WORD *)((char *)a1 + v7);
v8[1] = a3;
*v8 = a5 + 4;
memcpy(v8 + 2, a4, a5);
*a1 = ((*a1 + 3) & 0xFFFFFFFC) + v6;
result = 0LL;
}
return result;
}

original_code:
int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data,
       int alen) {
 int len = (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (alen));
 struct rtattr *rta;
 if (( ((n->nlmsg_len)+4U -1) & ~(4U -1) ) + len > maxlen) {
  fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n",maxlen);
  return -1;
 }
 rta = (struct rtattr*)(((char*)n) + ( ((n->nlmsg_len)+4U -1) & ~(4U -1) ));
 rta->rta_type = type;
 rta->rta_len = len;
 memcpy(((void*)(((char*)(rta)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))), data, alen);
 n->nlmsg_len = ( ((n->nlmsg_len)+4U -1) & ~(4U -1) ) + len;
 return 0;
}

canonical_original_code:
int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen) {
 int len = (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (alen));
 struct rtattr *rta;
 if (( ((n->nlmsg_len)+4U -1) & ~(4U -1) ) + len > maxlen) {
  fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n",maxlen);
  return -1;
 }
 rta = (struct rtattr *)(((char *)n) + ( ((n->nlmsg_len)+4U -1) & ~(4U -1) ));
 rta->rta_type = type;
 rta->rta_len = len;
 memcpy(((void *)(((char *)(rta)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))), data, alen);
 n->nlmsg_len = ( ((n->nlmsg_len)+4U -1) & ~(4U -1) ) + len;
 return 0;
}

variable_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } *

variable_types: maxlen int

variable_types: type int

variable_types:
data
void *

variable_types: alen int

variable_types: struct rtattr { unsigned short rta_len; unsigned short rta_type; } *


decompiled_code:
__int64 __fastcall rtnl_open(__int64 a1)
{
int v1; // eax
unsigned __int16 v2; // dx
__int64 result; // rax
int v4; // [rsp+4h] [rbp-24h] BYREF
int optval; // [rsp+8h] [rbp-20h] BYREF
socklen_t len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval = 0x8000;
v4 = 0x8000;
*(_QWORD *)a1 = 0LL;
v1 = socket(16, 3, 0);
*(_DWORD *)a1 = v1;
if ( v1 < 0 )
{
perror("Cannot open netlink socket");
result = 0xFFFFFFFFLL;
}
else if ( setsockopt(v1, 1, 7, &optval, 4u) < 0 )
{
perror("SO_SNDBUF");
result = 0xFFFFFFFFLL;
}
else if ( setsockopt(*(_DWORD *)a1, 1, 8, &v4, 4u) < 0 )
{
perror("SO_RCVBUF");
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)(a1 + 4) = 0LL;
*(_DWORD *)(a1 + 12) = 0;
*(_WORD *)(a1 + 4) = 16;
if ( bind(*(_DWORD *)a1, (const struct sockaddr *)(a1 + 4), 0xCu) < 0 )
{
perror("Cannot bind netlink socket");
result = 0xFFFFFFFFLL;
}
else
{
len[0] = 12;
if ( getsockname(*(_DWORD *)a1, (struct sockaddr *)(a1 + 4), len) < 0 )
{
perror("Cannot getsockname");
result = 0xFFFFFFFFLL;
}
else if ( len[0] == 12 )
{
v2 = *(_WORD *)(a1 + 4);
if ( v2 == 16 )
{
*(_DWORD *)(a1 + 28) = time(0LL);
result = 0LL;
}
else
{
fprintf(stderr, "Wrong address family %d\n", v2);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "Wrong address length %d\n", len[0]);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // eax
unsigned __int16 v2; // dx
__int64 result; // rax
int v4; // [rsp+4h] [rbp-24h] BYREF
int optval; // [rsp+8h] [rbp-20h] BYREF
socklen_t len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval = 0x8000;
v4 = 0x8000;
*(_QWORD *)a1 = 0LL;
v1 = socket(16, 3, 0);
*(_DWORD *)a1 = v1;
if ( v1 < 0 )
{
perror("Cannot open netlink socket");
result = 0xFFFFFFFFLL;
}
else if ( setsockopt(v1, 1, 7, &optval, 4u) < 0 )
{
perror("SO_SNDBUF");
result = 0xFFFFFFFFLL;
}
else if ( setsockopt(*(_DWORD *)a1, 1, 8, &v4, 4u) < 0 )
{
perror("SO_RCVBUF");
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)(a1 + 4) = 0LL;
*(_DWORD *)(a1 + 12) = 0;
*(_WORD *)(a1 + 4) = 16;
if ( bind(*(_DWORD *)a1, (const struct sockaddr *)(a1 + 4), 0xCu) < 0 )
{
perror("Cannot bind netlink socket");
result = 0xFFFFFFFFLL;
}
else
{
len[0] = 12;
if ( getsockname(*(_DWORD *)a1, (struct sockaddr *)(a1 + 4), len) < 0 )
{
perror("Cannot getsockname");
result = 0xFFFFFFFFLL;
}
else if ( len[0] == 12 )
{
v2 = *(_WORD *)(a1 + 4);
if ( v2 == 16 )
{
*(_DWORD *)(a1 + 28) = time(0LL);
result = 0LL;
}
else
{
fprintf(stderr, "Wrong address family %d\n", v2);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "Wrong address length %d\n", len[0]);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int rtnl_open(struct rtnl_handle *rth) {
 unsigned int addr_len;
 int sndbuf = 32768;
 int rcvbuf = 32768;
 memset(rth, 0, sizeof(rth));
 rth->fd = socket(16, SOCK_RAW, 0);
 if (rth->fd < 0) {
  perror("Cannot open netlink socket");
  return -1;
 }
 if (setsockopt(rth->fd,1,7,&sndbuf,sizeof(sndbuf)) < 0) {
  perror("SO_SNDBUF");
  return -1;
 }
 if (setsockopt(rth->fd,1,8,&rcvbuf,sizeof(rcvbuf)) < 0) {
  perror("SO_RCVBUF");
  return -1;
 }
 memset(&rth->local, 0, sizeof(rth->local));
 rth->local.nl_family = 16;
 rth->local.nl_groups = 0;
 if (bind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)) < 0) {
  perror("Cannot bind netlink socket");
  return -1;
 }
 addr_len = sizeof(rth->local);
 if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) {
  perror("Cannot getsockname");
  return -1;
 }
 if (addr_len != sizeof(rth->local)) {
  fprintf(stderr, "Wrong address length %d\n", addr_len);
  return -1;
 }
 if (rth->local.nl_family != 16) {
  fprintf(stderr, "Wrong address family %d\n", rth->local.nl_family);
  return -1;
 }
 rth->seq = time(((void *)0));
 return 0;
}

canonical_original_code:
int rtnl_open(struct rtnl_handle *rth) {
 unsigned int addr_len;
 int sndbuf = 32768;
 int rcvbuf = 32768;
 memset(rth, 0, sizeof(rth));
 rth->fd = socket(16, SOCK_RAW, 0);
 if (rth->fd < 0) {
  perror("Cannot open netlink socket");
  return -1;
 }
 if (setsockopt(rth->fd,1,7,&sndbuf,sizeof(sndbuf)) < 0) {
  perror("SO_SNDBUF");
  return -1;
 }
 if (setsockopt(rth->fd,1,8,&rcvbuf,sizeof(rcvbuf)) < 0) {
  perror("SO_RCVBUF");
  return -1;
 }
 memset(&rth->local, 0, sizeof(rth->local));
 rth->local.nl_family = 16;
 rth->local.nl_groups = 0;
 if (bind(rth->fd, (struct sockaddr *)&rth->local, sizeof(rth->local)) < 0) {
  perror("Cannot bind netlink socket");
  return -1;
 }
 addr_len = sizeof(rth->local);
 if (getsockname(rth->fd, (struct sockaddr *)&rth->local, &addr_len) < 0) {
  perror("Cannot getsockname");
  return -1;
 }
 if (addr_len != sizeof(rth->local)) {
  fprintf(stderr, "Wrong address length %d\n", addr_len);
  return -1;
 }
 if (rth->local.nl_family != 16) {
  fprintf(stderr, "Wrong address family %d\n", rth->local.nl_family);
  return -1;
 }
 rth->seq = time(((void *)0));
 return 0;
}

variable_types: struct rtnl_handle { int fd; struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; } local; struct sockaddr_nl peer; unsigned int seq; unsigned int dump; } *

variable_types: sndbuf int

variable_types: rcvbuf int


decompiled_code:
__int64 __fastcall rtnl_talk(int *a1, char *a2)
{
int v2; // er14
int v3; // eax
__int64 v4; // rdx
char *v5; // rbp
int v6; // er13
int v7; // ebx
unsigned int v8; // ebx
unsigned int v9; // ebx
struct msghdr v11; // [rsp+0h] [rbp-4098h] BYREF
char s[16384]; // [rsp+40h] [rbp-4058h] BYREF
char *v13; // [rsp+4040h] [rbp-58h] BYREF
__int64 v14; // [rsp+4048h] [rbp-50h]
__int64 v15; // [rsp+4054h] [rbp-44h] BYREF
int v16; // [rsp+405Ch] [rbp-3Ch]

v13 = a2;
v14 = *(unsigned int *)a2;
v11.msg_name = &v15;
v11.msg_namelen = 12;
v11.msg_iov = (struct iovec *)&v13;
v11.msg_iovlen = 1LL;
v11.msg_control = 0LL;
v11.msg_controllen = 0LL;
v11.msg_flags = 0;
v15 = 16LL;
v16 = 0;
v2 = a1[7] + 1;
a1[7] = v2;
*((_DWORD *)a2 + 2) = v2;
*((_WORD *)a2 + 3) |= 4u;
if ( (int)sendmsg(*a1, &v11, 0) < 0 )
{
perror("Cannot talk to rtnetlink");
v9 = -1;
}
else
{
memset(s, 0, sizeof(s));
v13 = s;
LABEL_3:
while ( 1 )
{
v14 = 0x4000LL;
v3 = recvmsg(*a1, &v11, 0);
v4 = (unsigned int)v3;
if ( v3 >= 0 )
break;
if ( *_errno_location() != 4 )
perror("OVERRUN");
}
if ( v3 )
{
if ( v11.msg_namelen == 12 )
{
v5 = s;
while ( 2 )
{
while ( 2 )
{
v6 = v4;
do
{
if ( (unsigned int)v4 <= 0xF )
{
if ( (v11.msg_flags & 0x20) != 0 )
{
fwrite("Message truncated\n", 1uLL, 0x12uLL, stderr);
goto LABEL_3;
}
if ( !(_DWORD)v4 )
goto LABEL_3;
fprintf(stderr, "!!!Remnant of size %d\n", v4);
return (unsigned int)-1;
}
v7 = *(_DWORD *)v5;
if ( *(_DWORD *)v5 - 16 < 0 || (int)v4 < v7 )
{
if ( (v11.msg_flags & 0x20) != 0 )
fwrite("Truncated message\n", 1uLL, 0x12uLL, stderr);
else
fprintf(stderr, "!!!malformed message: len=%d\n", (unsigned int)v7);
return (unsigned int)-1;
}
}
while ( HIDWORD(v15) );
if ( *((_DWORD *)v5 + 3) != a1[2] || v2 != *((_DWORD *)v5 + 2) )
continue;
break;
}
if ( *((_WORD *)v5 + 2) != 2 )
{
fwrite("Unexpected reply!!!\n", 1uLL, 0x14uLL, stderr);
v8 = (v7 + 3) & 0xFFFFFFFC;
v4 = v6 - v8;
v5 += v8;
continue;
}
break;
}
if ( (unsigned int)(*(_DWORD *)v5 - 16) <= 0x13 )
{
fwrite("ERROR truncated\n", 1uLL, 0x10uLL, stderr);
v9 = -1;
}
else
{
v9 = *((_DWORD *)v5 + 4);
*_errno_location() = -v9;
if ( v9 )
{
perror("RTNETLINK answers");
v9 = -1;
}
}
}
else
{
fprintf(stderr, "sender address length == %d\n", v11.msg_namelen);
v9 = -1;
}
}
else
{
fwrite("EOF on netlink\n", 1uLL, 0xFuLL, stderr);
v9 = -1;
}
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1, char *a2)
{
int v2; // er14
int v3; // eax
__int64 v4; // rdx
char *v5; // rbp
int v6; // er13
int v7; // ebx
unsigned int v8; // ebx
unsigned int v9; // ebx
struct msghdr v11; // [rsp+0h] [rbp-4098h] BYREF
char s[16384]; // [rsp+40h] [rbp-4058h] BYREF
char *v13; // [rsp+4040h] [rbp-58h] BYREF
__int64 v14; // [rsp+4048h] [rbp-50h]
__int64 v15; // [rsp+4054h] [rbp-44h] BYREF
int v16; // [rsp+405Ch] [rbp-3Ch]

v13 = a2;
v14 = *(unsigned int *)a2;
v11.msg_name = &v15;
v11.msg_namelen = 12;
v11.msg_iov = (struct iovec *)&v13;
v11.msg_iovlen = 1LL;
v11.msg_control = 0LL;
v11.msg_controllen = 0LL;
v11.msg_flags = 0;
v15 = 16LL;
v16 = 0;
v2 = a1[7] + 1;
a1[7] = v2;
*((_DWORD *)a2 + 2) = v2;
*((_WORD *)a2 + 3) |= 4u;
if ( (int)sendmsg(*a1, &v11, 0) < 0 )
{
perror("Cannot talk to rtnetlink");
v9 = -1;
}
else
{
memset(s, 0, sizeof(s));
v13 = s;
LABEL_3:
while ( 1 )
{
v14 = 0x4000LL;
v3 = recvmsg(*a1, &v11, 0);
v4 = (unsigned int)v3;
if ( v3 >= 0 )
break;
if ( *_errno_location() != 4 )
perror("OVERRUN");
}
if ( v3 )
{
if ( v11.msg_namelen == 12 )
{
v5 = s;
while ( 2 )
{
while ( 2 )
{
v6 = v4;
do
{
if ( (unsigned int)v4 <= 0xF )
{
if ( (v11.msg_flags & 0x20) != 0 )
{
fwrite("Message truncated\n", 1uLL, 0x12uLL, stderr);
goto LABEL_3;
}
if ( !(_DWORD)v4 )
goto LABEL_3;
fprintf(stderr, "!!!Remnant of size %d\n", v4);
return (unsigned int)-1;
}
v7 = *(_DWORD *)v5;
if ( *(_DWORD *)v5 - 16 < 0 || (int)v4 < v7 )
{
if ( (v11.msg_flags & 0x20) != 0 )
fwrite("Truncated message\n", 1uLL, 0x12uLL, stderr);
else
fprintf(stderr, "!!!malformed message: len=%d\n", (unsigned int)v7);
return (unsigned int)-1;
}
}
while ( HIDWORD(v15) );
if ( *((_DWORD *)v5 + 3) != a1[2] || v2 != *((_DWORD *)v5 + 2) )
continue;
break;
}
if ( *((_WORD *)v5 + 2) != 2 )
{
fwrite("Unexpected reply!!!\n", 1uLL, 0x14uLL, stderr);
v8 = (v7 + 3) & 0xFFFFFFFC;
v4 = v6 - v8;
v5 += v8;
continue;
}
break;
}
if ( (unsigned int)(*(_DWORD *)v5 - 16) <= 0x13 )
{
fwrite("ERROR truncated\n", 1uLL, 0x10uLL, stderr);
v9 = -1;
}
else
{
v9 = *((_DWORD *)v5 + 4);
*_errno_location() = -v9;
if ( v9 )
{
perror("RTNETLINK answers");
v9 = -1;
}
}
}
else
{
fprintf(stderr, "sender address length == %d\n", v11.msg_namelen);
v9 = -1;
}
}
else
{
fwrite("EOF on netlink\n", 1uLL, 0xFuLL, stderr);
v9 = -1;
}
}
return v9;
}

original_code:
int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n) {
 int status;
 unsigned seq;
 struct nlmsghdr *h;
 struct sockaddr_nl nladdr;
 struct iovec iov = { (void*)n, n->nlmsg_len };
 char buf[16384];
 struct msghdr msg = {
  (void*)&nladdr, sizeof(nladdr),
  &iov, 1,
  ((void *)0), 0,
  0
 };
 memset(&nladdr, 0, sizeof(nladdr));
 nladdr.nl_family = 16;
 nladdr.nl_pid = 0;
 nladdr.nl_groups = 0;
 n->nlmsg_seq = seq = ++rtnl->seq;
 n->nlmsg_flags |= 0x04;
 status = sendmsg(rtnl->fd, &msg, 0);
 if (status < 0) {
  perror("Cannot talk to rtnetlink");
  return -1;
 }
 memset(buf,0,sizeof(buf));
 iov.iov_base = buf;
 while (1) {
  iov.iov_len = sizeof(buf);
  status = recvmsg(rtnl->fd, &msg, 0);
  if (status < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   perror("OVERRUN");
   continue;
  }
  if (status == 0) {
   fprintf(stderr, "EOF on netlink\n");
   return -1;
  }
  if (msg.msg_namelen != sizeof(nladdr)) {
   fprintf(stderr, "sender address length == %d\n", msg.msg_namelen);
   return -1;
  }
  for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) {
   int len = h->nlmsg_len;
   int l = len - sizeof(*h);
   if (l<0 || len>status) {
    if (msg.msg_flags & MSG_TRUNC) {
     fprintf(stderr, "Truncated message\n");
     return -1;
    }
    fprintf(stderr, "!!!malformed message: len=%d\n", len);
    return -1;
   }
   if (nladdr.nl_pid != 0 ||
     h->nlmsg_pid != rtnl->local.nl_pid ||
     h->nlmsg_seq != seq)
    continue;
   if (h->nlmsg_type == 0x2) {
    struct nlmsgerr *err = (struct nlmsgerr*)((void*)(((char*)h) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
    if (l < sizeof(struct nlmsgerr)) {
     fprintf(stderr, "ERROR truncated\n");
    } else {
     (*__errno_location ()) = -err->error;
     if ((*__errno_location ()) == 0)
      return 0;
     perror("RTNETLINK answers");
    }
    return -1;
   }
   fprintf(stderr, "Unexpected reply!!!\n");
   status -= ( ((len)+4U -1) & ~(4U -1) );
   h = (struct nlmsghdr*)((char*)h + ( ((len)+4U -1) & ~(4U -1) ));
  }
  if (msg.msg_flags & MSG_TRUNC) {
   fprintf(stderr, "Message truncated\n");
   continue;
  }
  if (status) {
   fprintf(stderr, "!!!Remnant of size %d\n", status);
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n) {
 int status;
 unsigned int seq;
 struct nlmsghdr *h;
 struct sockaddr_nl nladdr;
 struct iovec iov = { (void*)n, n->nlmsg_len };
 char buf[16384];
 struct msghdr msg = {
  (void*)&nladdr, sizeof(nladdr),
  &iov, 1,
  ((void *)0), 0,
  0
 };
 memset(&nladdr, 0, sizeof(nladdr));
 nladdr.nl_family = 16;
 nladdr.nl_pid = 0;
 nladdr.nl_groups = 0;
 n->nlmsg_seq = seq = ++rtnl->seq;
 n->nlmsg_flags |= 0x04;
 status = sendmsg(rtnl->fd, &msg, 0);
 if (status < 0) {
  perror("Cannot talk to rtnetlink");
  return -1;
 }
 memset(buf,0,sizeof(buf));
 iov.iov_base = buf;
 while (1) {
  iov.iov_len = sizeof(buf);
  status = recvmsg(rtnl->fd, &msg, 0);
  if (status < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   perror("OVERRUN");
   continue;
  }
  if (status == 0) {
   fprintf(stderr, "EOF on netlink\n");
   return -1;
  }
  if (msg.msg_namelen != sizeof(nladdr)) {
   fprintf(stderr, "sender address length == %d\n", msg.msg_namelen);
   return -1;
  }
  for (h = (struct nlmsghdr *)buf; status >= sizeof(*h); ) {
   int len = h->nlmsg_len;
   int l = len - sizeof(*h);
   if (l<0 || len>status) {
    if (msg.msg_flags & MSG_TRUNC) {
     fprintf(stderr, "Truncated message\n");
     return -1;
    }
    fprintf(stderr, "!!!malformed message: len=%d\n", len);
    return -1;
   }
   if (nladdr.nl_pid != 0 ||
     h->nlmsg_pid != rtnl->local.nl_pid ||
     h->nlmsg_seq != seq)
    continue;
   if (h->nlmsg_type == 0x2) {
    struct nlmsgerr *err = (struct nlmsgerr*)((void*)(((char*)h) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
    if (l < sizeof(struct nlmsgerr)) {
     fprintf(stderr, "ERROR truncated\n");
    } else {
     (*__errno_location ()) = -err->error;
     if ((*__errno_location ()) == 0)
      return 0;
     perror("RTNETLINK answers");
    }
    return -1;
   }
   fprintf(stderr, "Unexpected reply!!!\n");
   status -= ( ((len)+4U -1) & ~(4U -1) );
   h = (struct nlmsghdr *)((char *)h + ( ((len)+4U -1) & ~(4U -1) ));
  }
  if (msg.msg_flags & MSG_TRUNC) {
   fprintf(stderr, "Message truncated\n");
   continue;
  }
  if (status) {
   fprintf(stderr, "!!!Remnant of size %d\n", status);
   return -1;
  }
 }
 return 0;
}

variable_types: status int

variable_types:
seq
unsigned int

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; }

variable_types:
buf
char [16384]

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

variable_types: l int

variable_types: struct nlmsgerr { int error; struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } msg; } *

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

user_defined_types: struct nlmsgerr { int error; struct nlmsghdr msg; }


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

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

original_code:
void rtnl_close(struct rtnl_handle *rth) {
 close(rth->fd);
}

user_defined_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; }


decompiled_code:
_BOOL8 __fastcall password_valid(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
static int password_valid(char *pw, void *priv)
{
 return !strcmp(pw, (char *)priv);
}

variable_types:
pw
char *

variable_types:
priv
void *


decompiled_code:
int redisplay_password()
{
fwrite("\rPassword: ", 1uLL, 0xBuLL, rl_outstream);
return fflush(rl_outstream);
}

canonical_decompiled_code:
int func2()
{
fwrite("\rPassword: ", 1uLL, 0xBuLL, rl_outstream);
return fflush(rl_outstream);
}

original_code:
static void redisplay_password(void)
{
 fprintf(rl_outstream, "\rPassword: ");
 fflush(rl_outstream);
}

canonical_original_code:
static void redisplay_password()
{
 fprintf(rl_outstream, "\rPassword: ");
 fflush(rl_outstream);
}


decompiled_code:
__int64 __fastcall cli_mask_apply(int *a1, int a2)
{
int v2; // eax

if ( !a1 )
return 1LL;
v2 = *a1;
if ( !*a1 )
return 1LL;
while ( (v2 & a2) != 0 )
{
v2 = *++a1;
if ( !*a1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int a2)
{
int v2; // eax

if ( !a1 )
return 1LL;
v2 = *a1;
if ( !*a1 )
return 1LL;
while ( (v2 & a2) != 0 )
{
v2 = *++a1;
if ( !*a1 )
return 1LL;
}
return 0LL;
}

original_code:
static __inline__ int cli_mask_apply(uint32_t *mask, uint32_t filter) {
 if (!mask)
  return 1;
 while (*mask) {
  if (!(*mask & filter))
   return 0;
  mask++;
 }
 return 1;
}

variable_types:
mask
unsigned int *

variable_types:
filter
unsigned int


decompiled_code:
__int64 __fastcall valid_mac(char *a1, int a2)
{
char v2; // al
char *v3; // rdi
int v4; // er8
unsigned int v5; // edx

v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
v4 = 1;
v5 = 0;
do
{
if ( v2 == 46 )
{
if ( !v5 )
return v5;
++v4;
v5 = 0;
}
else
{
if ( (unsigned __int8)(v2 - 48) > 9u && (unsigned __int8)((v2 & 0xDF) - 65) > 5u )
return 0;
if ( (int)++v5 > 4 )
return 0;
}
v2 = *v3++;
}
while ( v2 );
v5 = 0;
if ( v4 > 3 )
return v5;
}
else
{
v4 = 1;
}
return (v4 == 3) | (unsigned __int8)(a2 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, int a2)
{
char v2; // al
char *v3; // rdi
int v4; // er8
unsigned int v5; // edx

v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
v4 = 1;
v5 = 0;
do
{
if ( v2 == 46 )
{
if ( !v5 )
return v5;
++v4;
v5 = 0;
}
else
{
if ( (unsigned __int8)(v2 - 48) > 9u && (unsigned __int8)((v2 & 0xDF) - 65) > 5u )
return 0;
if ( (int)++v5 > 4 )
return 0;
}
v2 = *v3++;
}
while ( v2 );
v5 = 0;
if ( v4 > 3 )
return v5;
}
else
{
v4 = 1;
}
return (v4 == 3) | (unsigned __int8)(a2 != 0);
}

original_code:
static int valid_mac(const char *token, int part, void *priv)
{
 int digits = 0, group = 1, i;
 for (i = 0; token[i] != '\0'; i++) {
  if (token[i] == '.') {
   if (!digits)
    return 0;
   digits = 0;
   group ++;
   continue;
  }
  if (!(((token[i]) >= '0' && (token[i]) <= '9') || ((token[i]) >= 'a' && (token[i]) <= 'f') || ((token[i]) >= 'A' && (token[i]) <= 'F')))
   return 0;
  if (++digits > 4)
   return 0;
 }
 if (group > 3)
  return 0;
 return part || group == 3;
}

canonical_original_code:
static int valid_mac(char *token, int part, void *priv)
{
 int digits = 0; int group = 1; int i;
 for (i = 0; token[i] != '\0'; i++) {
  if (token[i] == '.') {
   if (!digits)
    return 0;
   digits = 0;
   group ++;
   continue;
  }
  if (!(((token[i]) >= '0' && (token[i]) <= '9') || ((token[i]) >= 'a' && (token[i]) <= 'f') || ((token[i]) >= 'A' && (token[i]) <= 'F')))
   return 0;
  if (++digits > 4)
   return 0;
 }
 if (group > 3)
  return 0;
 return part || group == 3;
}

variable_types:
token
char *

variable_types: part int

variable_types: digits int

variable_types: group int

variable_types: i int


original_code:
static int valid_ip(const char *token, int part, void *priv)
{
 int x = 0, digits = 0, group = 1, i;
 for (i = 0; token[i] != '\0'; i++) {
  if (token[i] == '.') {
   if (!digits)
    return 0;
   digits = 0;
   x = 0;
   group ++;
   continue;
  }
  if (token[i] < '0' || token[i] > '9')
   return 0;
  ++digits;
  if ((x = x * 10 + (token[i] - '0')) > 255)
   return 0;
 }
 if (group > 4)
  return 0;
 return part || group == 4;
}

canonical_original_code:
static int valid_ip(char *token, int part, void *priv)
{
 int x = 0; int digits = 0; int group = 1; int i;
 for (i = 0; token[i] != '\0'; i++) {
  if (token[i] == '.') {
   if (!digits)
    return 0;
   digits = 0;
   x = 0;
   group ++;
   continue;
  }
  if (token[i] < '0' || token[i] > '9')
   return 0;
  ++digits;
  if ((x = x * 10 + (token[i] - '0')) > 255)
   return 0;
 }
 if (group > 4)
  return 0;
 return part || group == 4;
}

variable_types: x int


decompiled_code:
__int64 __fastcall swcli_valid_number(const char *a1, __int64 a2, unsigned int *a3)
{
char v4; // al
char *v5; // rdx
int v6; // eax
int v7; // ecx
unsigned int v8; // edx
int v9; // edi
__int64 v10; // rax

if ( !a3 )
return 1LL;
if ( !a1 )
_assert_fail("token", "lib/tokenizers.c", 0xFu, "swcli_valid_number");
v4 = *a1;
v5 = (char *)(a1 + 1);
if ( *a1 )
{
while ( (unsigned __int8)(v4 - 48) <= 9u )
{
v4 = *v5++;
if ( !v4 )
goto LABEL_6;
}
v8 = 0;
}
else
{
LABEL_6:
v6 = atoi(a1);
v7 = v6;
v8 = *a3;
if ( *a3 )
{
if ( v8 == 1 )
{
v9 = a3[1];
v10 = 2LL;
if ( v9 <= 0 )
{
v8 = 0;
}
else
{
while ( a3[v10] != v7 )
{
if ( (int)++v10 - 1 > v9 )
return 0;
}
}
}
else
{
v8 = 1;
}
}
else if ( (int)a3[1] <= v6 )
{
v8 = (int)a3[2] >= v6;
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2, unsigned int *a3)
{
char v4; // al
char *v5; // rdx
int v6; // eax
int v7; // ecx
unsigned int v8; // edx
int v9; // edi
__int64 v10; // rax

if ( !a3 )
return 1LL;
if ( !a1 )
_assert_fail("token", "lib/tokenizers.c", 0xFu, "swcli_valid_number");
v4 = *a1;
v5 = (char *)(a1 + 1);
if ( *a1 )
{
while ( (unsigned __int8)(v4 - 48) <= 9u )
{
v4 = *v5++;
if ( !v4 )
goto LABEL_6;
}
v8 = 0;
}
else
{
LABEL_6:
v6 = atoi(a1);
v7 = v6;
v8 = *a3;
if ( *a3 )
{
if ( v8 == 1 )
{
v9 = a3[1];
v10 = 2LL;
if ( v9 <= 0 )
{
v8 = 0;
}
else
{
while ( a3[v10] != v7 )
{
if ( (int)++v10 - 1 > v9 )
return 0;
}
}
}
else
{
v8 = 1;
}
}
else if ( (int)a3[1] <= v6 )
{
v8 = (int)a3[2] >= v6;
}
}
return v8;
}

original_code:
static int swcli_valid_number(const char *token, int part, void *priv)
{
 int i, val;
 int *valid = priv;
 if (!valid)
  return 1;
 ((void) sizeof ((token) ? 1 : 0), __extension__ ({ if (token) ; else __assert_fail ("token", "lib/tokenizers.c", 15, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; token[i] != '\0'; i++)
  if (token[i] < '0' || token[i] > '9')
   return 0;
 val = atoi(token);
 switch (valid[0]) {
 case VALID_LIMITS:
  return val >= valid[1] && val <= valid[2];
 case VALID_LIST:
  for (i = 2; i < valid[1] + 2; i++)
   if (val == valid[i])
    return 1;
  return 0;
 }
 return 1;
}

canonical_original_code:
static int swcli_valid_number(char *token, int part, void *priv)
{
 int i; int val;
 int *valid = priv;
 if (!valid)
  return 1;
 ((void) sizeof ((token) ? 1 : 0), __extension__ ({ if (token) ; else __assert_fail ("token", "lib/tokenizers.c", 15, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; token[i] != '\0'; i++)
  if (token[i] < '0' || token[i] > '9')
   return 0;
 val = atoi(token);
 switch (valid[0]) {
 case VALID_LIMITS:
  return val >= valid[1] && val <= valid[2];
 case VALID_LIST:
  for (i = 2; i < valid[1] + 2; i++)
   if (val == valid[i])
    return 1;
  return 0;
 }
 return 1;
}

variable_types: val int

variable_types:
valid
int *


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

if ( !ptr )
_assert_fail("s", "cdp_client.c", 0x38u, "cdp_session_end");
v2 = (void *)*((_QWORD *)ptr + 9);
if ( v2 )
free(v2);
if ( *(_DWORD *)ptr != -1 )
mq_close();
if ( *((_DWORD *)ptr + 1) != -1 )
{
mq_close();
mq_unlink((char *)ptr + 40);
}
free(ptr);
}

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

if ( !ptr )
_assert_fail("s", "cdp_client.c", 0x38u, "cdp_session_end");
v2 = (void *)*((_QWORD *)ptr + 9);
if ( v2 )
free(v2);
if ( *(_DWORD *)ptr != -1 )
mq_close();
if ( *((_DWORD *)ptr + 1) != -1 )
{
mq_close();
mq_unlink((char *)ptr + 40);
}
free(ptr);
}

original_code:
void cdp_session_end(struct cdp_session *s)
{
 ((void) sizeof ((s) ? 1 : 0), __extension__ ({ if (s) ; else __assert_fail ("s", "cdp_client.c", 56, __extension__ __PRETTY_FUNCTION__); }));
 if (s->response)
  free(s->response);
 if (s->sq != -1)
  mq_close(s->sq);
 if (s->rq != -1) {
  mq_close(s->rq);
  mq_unlink(s->rq_name);
 }
 free(s);
}

variable_types: struct cdp_session { int sq; char sq_name[32]; char *response; int max_msg_len; } *


original_code:
struct cdp_session *cdp_session_start(void)
{
 struct cdp_session *s;
 struct mq_attr attr;
 if (!(s = (struct cdp_session *)malloc(sizeof(struct cdp_session))))
  return ((void *)0);
 memset(s, 0, sizeof(struct cdp_session));
 s->sq = s->rq = -1;
 memset(s->sq_name, 0, sizeof(s->sq_name));
 snprintf(s->sq_name, sizeof(s->sq_name), "/lisa-cdp-%d", 0);
 s->sq_name[sizeof(s->sq_name)-1] = '\0';
 if ((s->sq = mq_open(s->sq_name, 01)) < 0)
  goto out_err;
 memset(s->rq_name, 0, sizeof(s->rq_name));
 snprintf(s->rq_name, sizeof(s->rq_name), "/lisa-cdp-%d", getpid());
 s->rq_name[sizeof(s->rq_name)-1] = '\0';
 if ((s->rq = mq_open(s->rq_name, 0100|00, 0666, ((void *)0))) < 0)
  goto out_err;
 if (mq_getattr(s->rq, &attr) < 0)
  goto out_err;
 s->max_msg_len = attr.mq_msgsize;
 if (!(s->response = malloc(s->max_msg_len)))
  goto out_err;
 return s;
out_err:
 cdp_session_end(s);
 return ((void *)0);
}

canonical_original_code:
struct cdp_session *cdp_session_start()
{
 struct cdp_session *s;
 struct mq_attr attr;
 if (!(s = (struct cdp_session *)malloc(sizeof(struct cdp_session))))
  return ((void *)0);
 memset(s, 0, sizeof(struct cdp_session));
 s->sq = s->rq = -1;
 memset(s->sq_name, 0, sizeof(s->sq_name));
 snprintf(s->sq_name, sizeof(s->sq_name), "/lisa-cdp-%d", 0);
 s->sq_name[sizeof(s->sq_name)-1] = '\0';
 if ((s->sq = mq_open(s->sq_name, 01)) < 0)
  goto out_err;
 memset(s->rq_name, 0, sizeof(s->rq_name));
 snprintf(s->rq_name, sizeof(s->rq_name), "/lisa-cdp-%d", getpid());
 s->rq_name[sizeof(s->rq_name)-1] = '\0';
 if ((s->rq = mq_open(s->rq_name, 0100|00, 0666, ((void *)0))) < 0)
  goto out_err;
 if (mq_getattr(s->rq, &attr) < 0)
  goto out_err;
 s->max_msg_len = attr.mq_msgsize;
 if (!(s->response = malloc(s->max_msg_len)))
  goto out_err;
 return s;
out_err:
 cdp_session_end(s);
 return ((void *)0);
}

variable_types: struct mq_attr { long mq_flags; long mq_maxmsg; long mq_msgsize; long mq_curmsgs; long __pad[4]; }

return_type: struct cdp_session { int sq; char sq_name[32]; char *response; int max_msg_len; } *


decompiled_code:
__int64 __fastcall cdp_session_recv(__int64 a1)
{
int v1; // ebx
time_t timer; // [rsp+8h] [rbp-30h] BYREF
__int64 v4[5]; // [rsp+10h] [rbp-28h] BYREF

if ( !a1 )
_assert_fail("s", "cdp_client.c", 0x4Bu, "cdp_session_recv");
v4[0] = 0LL;
v4[1] = 0LL;
time(&timer);
v4[0] = timer + 3;
v1 = mq_timedreceive(*(unsigned int *)(a1 + 4), *(_QWORD *)(a1 + 72), *(int *)(a1 + 80), 0LL, v4);
if ( v1 < 0 )
fprintf(stderr, "No message received from cdpd in %d seconds.\nDisabling cdp in this session.\n", 3LL);
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // ebx
time_t timer; // [rsp+8h] [rbp-30h] BYREF
__int64 v4[5]; // [rsp+10h] [rbp-28h] BYREF

if ( !a1 )
_assert_fail("s", "cdp_client.c", 0x4Bu, "cdp_session_recv");
v4[0] = 0LL;
v4[1] = 0LL;
time(&timer);
v4[0] = timer + 3;
v1 = mq_timedreceive(*(unsigned int *)(a1 + 4), *(_QWORD *)(a1 + 72), *(int *)(a1 + 80), 0LL, v4);
if ( v1 < 0 )
fprintf(stderr, "No message received from cdpd in %d seconds.\nDisabling cdp in this session.\n", 3LL);
return (unsigned int)v1;
}

original_code:
int cdp_session_recv(struct cdp_session *s)
{
 struct timespec ts;
 time_t ns;
 int err;
 ((void) sizeof ((s) ? 1 : 0), __extension__ ({ if (s) ; else __assert_fail ("s", "cdp_client.c", 75, __extension__ __PRETTY_FUNCTION__); }));
 memset(&ts, 0, sizeof(ts));
 time(&ns);
 ts.tv_sec = ns + 3;
 if ((err = mq_timedreceive(s->rq, s->response, s->max_msg_len, ((void *)0), &ts)) < 0) {
  fprintf(stderr, "No message received from cdpd in %d seconds.\n"
   "Disabling cdp in this session.\n", 3);
 }
 return err;
}

canonical_original_code:
int cdp_session_recv(struct cdp_session *s)
{
 struct timespec ts;
 long ns;
 int err;
 ((void) sizeof ((s) ? 1 : 0), __extension__ ({ if (s) ; else __assert_fail ("s", "cdp_client.c", 75, __extension__ __PRETTY_FUNCTION__); }));
 memset(&ts, 0, sizeof(ts));
 time(&ns);
 ts.tv_sec = ns + 3;
 if ((err = mq_timedreceive(s->rq, s->response, s->max_msg_len, ((void *)0), &ts)) < 0) {
  fprintf(stderr, "No message received from cdpd in %d seconds.\n"
   "Disabling cdp in this session.\n", 3);
 }
 return err;
}

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

variable_types: ns long

variable_types: err int

user_defined_types: struct cdp_session { int sq; char sq_name[32]; char *response; int max_msg_len; }


decompiled_code:
__int64 __fastcall cdp_is_enabled(unsigned int *a1, int a2)
{
int v2; // ebx
int v4[26]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0x5Eu, "cdp_is_enabled");
memset(v4, 0, 0x48uLL);
v4[18] = 0;
v4[0] = 5;
v4[1] = getpid();
v4[2] = a2;
v2 = mq_send(*a1, v4, 76LL, 0LL);
if ( v2 < 0 )
{
perror("cdp_session_send");
}
else
{
v2 = cdp_session_recv((__int64)a1);
if ( v2 < 0 )
perror("cdp_session_recv");
else
v2 = **((_DWORD **)a1 + 9);
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, int a2)
{
int v2; // ebx
int v4[26]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0x5Eu, "cdp_is_enabled");
memset(v4, 0, 0x48uLL);
v4[18] = 0;
v4[0] = 5;
v4[1] = getpid();
v4[2] = a2;
v2 = mq_send(*a1, v4, 76LL, 0LL);
if ( v2 < 0 )
{
perror("cdp_session_send");
}
else
{
v2 = func2((__int64)a1);
if ( v2 < 0 )
perror("cdp_session_recv");
else
v2 = **((_DWORD **)a1 + 9);
}
return (unsigned int)v2;
}

original_code:
int cdp_is_enabled(struct cdp_session *session, int if_index)
{
 struct cdp_request m;
 int err;
 ((void) sizeof ((session) ? 1 : 0), __extension__ ({ if (session) ; else __assert_fail ("session", "cdp_client.c", 94, __extension__ __PRETTY_FUNCTION__); }));
 memset(&m, 0, sizeof(m));
 m.type = CDP_IF_STATUS;
 m.pid = getpid();
 m.if_index = if_index;
 if ((err = ({ int r = mq_send(session->sq, (const char *)&m, sizeof(m), 0); r; })) < 0) {
  perror("cdp_session_send");
  return err;
 }
 if ((err = cdp_session_recv(session)) < 0) {
  perror("cdp_session_recv");
  return err;
 }
 return *((int *)session->response);
}

variable_types: struct cdp_request { int type; int pid; int if_index; char device_id[64]; }

variable_types: r int


decompiled_code:
__int64 __fastcall cdp_set_interface(unsigned int *a1, int a2, int a3)
{
int v3; // ebx
int v5[26]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0x76u, "cdp_set_interface");
memset(v5, 0, 0x48uLL);
v5[18] = 0;
v5[0] = (a3 == 0) + 3;
v5[1] = getpid();
v5[2] = a2;
v3 = mq_send(*a1, v5, 76LL, 0LL);
if ( v3 < 0 )
perror("cdp_session_send");
else
v3 = cdp_session_recv((__int64)a1);
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, int a2, int a3)
{
int v3; // ebx
int v5[26]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0x76u, "cdp_set_interface");
memset(v5, 0, 0x48uLL);
v5[18] = 0;
v5[0] = (a3 == 0) + 3;
v5[1] = getpid();
v5[2] = a2;
v3 = mq_send(*a1, v5, 76LL, 0LL);
if ( v3 < 0 )
perror("cdp_session_send");
else
v3 = func2((__int64)a1);
return (unsigned int)v3;
}

original_code:
int cdp_set_interface(struct cdp_session *session, int if_index, int enabled)
{
 struct cdp_request m;
 int err;
 ((void) sizeof ((session) ? 1 : 0), __extension__ ({ if (session) ; else __assert_fail ("session", "cdp_client.c", 118, __extension__ __PRETTY_FUNCTION__); }));
 memset(&m, 0, sizeof(m));
 m.type = enabled? CDP_IF_ENABLE : CDP_IF_DISABLE;
 m.pid = getpid();
 m.if_index = if_index;
 if ((err = ({ int r = mq_send(session->sq, (const char *)&m, sizeof(m), 0); r; })) < 0) {
  perror("cdp_session_send");
  return err;
 }
 return cdp_session_recv(session);
}

variable_types: enabled int

user_defined_types: struct cdp_request { int type; int pid; int if_index; char device_id[64]; }


decompiled_code:
__int64 __fastcall cdp_get_neighbors(unsigned int *a1, int a2, const char *a3)
{
size_t v4; // rax
int v5; // ebx
int v7[26]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0x89u, "cdp_get_neighbors");
memset(v7, 0, 0x48uLL);
v7[18] = 0;
v7[1] = getpid();
v7[2] = a2;
if ( a3 )
{
v4 = strlen(a3);
strncpy((char *)&v7[3], a3, v4);
*((_BYTE *)&v7[3] + strlen(a3)) = 0;
}
v5 = mq_send(*a1, v7, 76LL, 0LL);
if ( v5 < 0 )
perror("cdp_session_send");
else
v5 = cdp_session_recv((__int64)a1);
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1, int a2, const char *a3)
{
size_t v4; // rax
int v5; // ebx
int v7[26]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0x89u, "cdp_get_neighbors");
memset(v7, 0, 0x48uLL);
v7[18] = 0;
v7[1] = getpid();
v7[2] = a2;
if ( a3 )
{
v4 = strlen(a3);
strncpy((char *)&v7[3], a3, v4);
*((_BYTE *)&v7[3] + strlen(a3)) = 0;
}
v5 = mq_send(*a1, v7, 76LL, 0LL);
if ( v5 < 0 )
perror("cdp_session_send");
else
v5 = func2((__int64)a1);
return (unsigned int)v5;
}

original_code:
int cdp_get_neighbors(struct cdp_session *session, int if_index, char *device_id)
{
 struct cdp_request m;
 int err;
 ((void) sizeof ((session) ? 1 : 0), __extension__ ({ if (session) ; else __assert_fail ("session", "cdp_client.c", 137, __extension__ __PRETTY_FUNCTION__); }));
 memset(&m, 0, sizeof(m));
 m.type = CDP_SHOW_NEIGHBORS;
 m.pid = getpid();
 m.if_index = if_index;
 if (device_id) {
  strncpy(m.device_id, device_id, strlen(device_id));
  m.device_id[strlen(device_id)] = '\0';
 }
 if ((err = ({ int r = mq_send(session->sq, (const char *)&m, sizeof(m), 0); r; })) < 0) {
  perror("cdp_session_send");
  return err;
 }
 return cdp_session_recv(session);
}


decompiled_code:
__int64 __fastcall cdp_get_interfaces(unsigned int *a1, int a2)
{
int v2; // ebx
int v4[26]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0xA1u, "cdp_get_interfaces");
memset(v4, 0, 0x48uLL);
v4[18] = 0;
v4[0] = 2;
v4[1] = getpid();
v4[2] = a2;
v2 = mq_send(*a1, v4, 76LL, 0LL);
if ( v2 < 0 )
perror("cdp_session_send");
else
v2 = cdp_session_recv((__int64)a1);
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1, int a2)
{
int v2; // ebx
int v4[26]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0xA1u, "cdp_get_interfaces");
memset(v4, 0, 0x48uLL);
v4[18] = 0;
v4[0] = 2;
v4[1] = getpid();
v4[2] = a2;
v2 = mq_send(*a1, v4, 76LL, 0LL);
if ( v2 < 0 )
perror("cdp_session_send");
else
v2 = func2((__int64)a1);
return (unsigned int)v2;
}

original_code:
int cdp_get_interfaces(struct cdp_session *session, int if_index)
{
 struct cdp_request m;
 int err;
 ((void) sizeof ((session) ? 1 : 0), __extension__ ({ if (session) ; else __assert_fail ("session", "cdp_client.c", 161, __extension__ __PRETTY_FUNCTION__); }));
 memset(&m, 0, sizeof(m));
 m.type = CDP_SHOW_INTF;
 m.pid = getpid();
 m.if_index = if_index;
 if ((err = ({ int r = mq_send(session->sq, (const char *)&m, sizeof(m), 0); r; })) < 0) {
  perror("cdp_session_send");
  return err;
 }
 return cdp_session_recv(session);
}


decompiled_code:
__int64 __fastcall cdp_get_stats(unsigned int *a1, __int64 a2)
{
int v2; // ebx
int v4[26]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0xB4u, "cdp_get_stats");
if ( !a2 )
_assert_fail("stats", "cdp_client.c", 0xB5u, "cdp_get_stats");
memset(v4, 0, 0x48uLL);
v4[18] = 0;
v4[0] = 1;
v4[1] = getpid();
v2 = mq_send(*a1, v4, 76LL, 0LL);
if ( v2 < 0 )
perror("cdp_session_send");
else
v2 = cdp_session_recv((__int64)a1);
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1, __int64 a2)
{
int v2; // ebx
int v4[26]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("session", "cdp_client.c", 0xB4u, "cdp_get_stats");
if ( !a2 )
_assert_fail("stats", "cdp_client.c", 0xB5u, "cdp_get_stats");
memset(v4, 0, 0x48uLL);
v4[18] = 0;
v4[0] = 1;
v4[1] = getpid();
v2 = mq_send(*a1, v4, 76LL, 0LL);
if ( v2 < 0 )
perror("cdp_session_send");
else
v2 = func2((__int64)a1);
return (unsigned int)v2;
}

original_code:
int cdp_get_stats(struct cdp_session *session, struct cdp_traffic_stats *stats)
{
 struct cdp_request m;
 int err;
 ((void) sizeof ((session) ? 1 : 0), __extension__ ({ if (session) ; else __assert_fail ("session", "cdp_client.c", 180, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((stats) ? 1 : 0), __extension__ ({ if (stats) ; else __assert_fail ("stats", "cdp_client.c", 181, __extension__ __PRETTY_FUNCTION__); }));
 memset(&m, 0, sizeof(m));
 m.type = CDP_SHOW_STATS;
 m.pid = getpid();
 if ((err = ({ int r = mq_send(session->sq, (const char *)&m, sizeof(m), 0); r; })) < 0) {
  perror("cdp_session_send");
  return err;
 }
 if ((err = cdp_session_recv(session)) < 0)
  return err;
 stats = (struct cdp_traffic_stats *)session->response;
 return err;
}

variable_types: struct cdp_traffic_stats { unsigned int v1_in; unsigned int v2_in; unsigned int v1_out; unsigned int v2_out; } *


decompiled_code:
void __noreturn timedout2()
{
_BYTE v0[6]; // [rsp+0h] [rbp-28h] BYREF
__int16 v1; // [rsp+6h] [rbp-22h]

ioctl(0, 0x5405uLL, v0);
v1 |= 8u;
ioctl(0, 0x5406uLL, v0);
exit(0);
}

original_code:
static void
timedout2(int sig) {
 struct termio ti;
 ioctl(0, 0x5405, &ti);
 ti.c_lflag |= 0000010;
 ioctl(0, 0x5406, &ti);
 exit(0);
}

variable_types: sig int

variable_types: struct termio { unsigned short c_iflag; unsigned short c_oflag; unsigned short c_cflag; unsigned short c_lflag; unsigned char c_line; unsigned char c_cc[8]; }


timedout

decompiled_code:
void __noreturn timedout()
{
signal(14, (__sighandler_t)timedout2);
alarm(0xAu);
fprintf(stderr, "Login timed out after %d seconds\n", 6000LL);
signal(14, (__sighandler_t)((char *)timedout2 + 1));
alarm(0);
timedout2();
}

canonical_decompiled_code:
void __noreturn func1()
{
signal(14, (__sighandler_t)timedout2);
alarm(0xAu);
fprintf(stderr, "Login timed out after %d seconds\n", 6000LL);
signal(14, (__sighandler_t)((char *)timedout2 + 1));
alarm(0);
func0();
}

original_code:
static void
timedout(int sig) {
 signal(14, timedout2);
 alarm(10);
 fprintf(stderr, "Login timed out after %d seconds\n", timeout);
 signal(14, ((__sighandler_t) 1));
 alarm(0);
 timedout2(0);
}

canonical_original_code:
static void timedout(int sig) {
 signal(14, timedout2);
 alarm(10);
 fprintf(stderr, "Login timed out after %d seconds\n", timeout);
 signal(14, ((void (*)(int)) 1));
 alarm(0);
 timedout2(0);
}


decompiled_code:
int __fastcall check_ttyname(char *s1)
{
int result; // eax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( lstat(s1, &v2)
|| (result = v2.st_mode & 0xF000, result != 0x2000)
|| v2.st_nlink > 1 && (result = strncmp(s1, "/dev/", 5uLL)) != 0 )
{
syslog(3, "FATAL: bad tty");
sleep(1u);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *s1)
{
int result; // eax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( lstat(s1, &v2)
|| (result = v2.st_mode & 0xF000, result != 0x2000)
|| v2.st_nlink > 1 && (result = strncmp(s1, "/dev/", 5uLL)) != 0 )
{
syslog(3, "FATAL: bad tty");
sleep(1u);
exit(1);
}
return result;
}

original_code:
static void
check_ttyname(char *ttyn) {
 struct stat statbuf;
 if (lstat(ttyn, &statbuf)
     || !((((statbuf.st_mode)) & 0170000) == (0020000))
     || (statbuf.st_nlink > 1 && strncmp(ttyn, "/dev/", 5))) {
  syslog(3, "FATAL: bad tty");
  sleep(1);
  exit(1);
 }
}

variable_types:
ttyn
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }