decompiled_code:
__int64 __fastcall print_option(char *s, size_t maxlen, int a3, int a4, unsigned __int8 *a5, __int64 a6)
{
char *v6; // r14
size_t v7; // r13
int v8; // er12
char *v9; // rbp
__int64 v11; // r15
unsigned __int16 v12; // ax
const char *v13; // rdx
int v15; // eax
__int64 v16; // rcx
int v17; // eax
unsigned int v18; // eax
const char *v19; // rdx
int v20; // eax
__int64 v21; // rax
unsigned __int8 *v22; // rax
unsigned __int8 *v23; // rbx
const char *v24; // rax
unsigned __int8 *v25; // r12
int v26; // eax
char *v27; // rax
__int64 v28; // rax
int v29; // eax
__int64 v30; // r15
unsigned __int8 *v31; // rbp
int v32; // eax
unsigned __int8 *v33; // [rsp+0h] [rbp-58h]
unsigned __int8 *v35; // [rsp+18h] [rbp-40h]
unsigned __int8 *v36; // [rsp+18h] [rbp-40h]
unsigned __int8 *v37; // [rsp+18h] [rbp-40h]
unsigned __int8 *v38; // [rsp+18h] [rbp-40h]

v6 = (char *)a5;
v7 = maxlen;
v8 = a4;
v9 = s;
if ( (a3 & 0x800) != 0 )
{
v21 = decode_rfc3397(0LL, 0LL, a4, (char *)a5);
v11 = v21;
if ( v21 <= 0 )
return v11;
v22 = (unsigned __int8 *)malloc(v21);
v23 = v22;
if ( v22 )
{
decode_rfc3397(v22, v11, v8, v6);
v11 = print_string(s, maxlen, (int)v11 - 1, v23);
free(v23);
return v11;
}
return -1LL;
}
if ( (a3 & 0x400) != 0 )
{
v24 = (const char *)decode_rfc3361((unsigned int)a4, a5);
v25 = (unsigned __int8 *)v24;
if ( v24 )
{
v26 = strlen(v24);
v11 = print_string(s, maxlen, v26 - 1, v25);
free(v25);
return v11;
}
return -1LL;
}
if ( (a3 & 0x1000) != 0 )
return decode_rfc3442(s, maxlen, (unsigned int)a4, a5);
if ( (a3 & 0x2000) == 0 )
{
if ( (a3 & 0x80u) != 0 )
{
v11 = 0LL;
LABEL_12:
if ( *v6 )
v11 += print_string(s, v7, v8, (unsigned __int8 *)v6);
return v11;
}
if ( (a3 & 0x20000) != 0 )
{
v11 = 2LL;
if ( s )
*(_WORD *)s = 49;
return v11;
}
if ( (a3 & 0x10000) != 0 && a4 > 1 )
{
v11 = 7LL;
if ( s )
{
v12 = _bswap_16(*(_WORD *)a5);
v11 = snprintf(s, maxlen, v13, v12);
v7 = maxlen - v11;
}
v6 += 2;
v8 -= 2;
if ( !v8 )
return v11;
goto LABEL_12;
}
if ( s )
{
v33 = &a5[a4];
if ( v33 > a5 )
{
v11 = 0LL;
while ( (a3 & 2) == 0 )
{
while ( 1 )
{
if ( (a3 & 4) != 0 )
{
v36 = a5;
v16 = (unsigned __int16)_bswap_16(*(_WORD *)a5);
LABEL_43:
v17 = snprintf(v9, v7, "%d", v16);
a5 = v36 + 2;
v7 -= v17;
v11 += v17;
v9 += v17;
goto LABEL_26;
}
if ( (a3 & 8) != 0 )
{
v36 = a5;
v16 = (unsigned int)_bswap_16(*(_WORD *)a5);
goto LABEL_43;
}
if ( (a3 & 0x10) != 0 || (a3 & 0x20) != 0 )
{
v37 = a5;
v18 = _bswap_32(*(_DWORD *)a5);
v20 = snprintf(v9, v7, v19, v18);
LABEL_45:
v7 -= v20;
v11 += v20;
v9 += v20;
a5 = v37 + 4;
goto LABEL_26;
}
if ( (a3 & 0x40) != 0 )
{
v37 = a5;
v27 = inet_ntoa(*(struct in_addr *)a5);
v20 = snprintf(v9, v7, "%s", v27);
goto LABEL_45;
}
if ( (a3 & 0x4000) != 0 )
{
v38 = a5;
v29 = ipv6_printaddr(v9, v7, a5, a6);
if ( v29 != -1 )
{
v7 -= v29;
v11 += v29;
v9 += v29;
}
a5 = v38 + 16;
goto LABEL_26;
}
if ( (a3 & 0x8000) != 0 )
{
v35 = a5;
v15 = snprintf(v9, v7, "%.2x", *a5);
LABEL_31:
a5 = v35 + 1;
v7 -= v15;
v11 += v15;
v9 += v15;
}
LABEL_26:
if ( a5 >= v33 )
return v11;
if ( a5 == (unsigned __int8 *)v6 || a3 == 0x8000 )
break;
*v9 = 32;
++v11;
--v7;
++v9;
if ( (a3 & 2) != 0 )
goto LABEL_30;
}
}
LABEL_30:
v35 = a5;
v15 = snprintf(v9, v7, "%d", *a5);
goto LABEL_31;
}
return 0LL;
}
if ( (a3 & 2) != 0 )
{
v28 = 4LL;
}
else if ( (a3 & 4) != 0 )
{
v28 = 6LL;
v8 = a4 / 2;
}
else if ( (a3 & 8) != 0 )
{
v28 = 7LL;
v8 = a4 / 2;
}
else if ( (a3 & 0x10) != 0 )
{
if ( a4 < 0 )
v8 = a4 + 3;
v28 = 11LL;
v8 >>= 2;
}
else if ( (a3 & 0x20) != 0 )
{
if ( a4 < 0 )
v8 = a4 + 3;
v28 = 12LL;
v8 >>= 2;
}
else if ( (a3 & 0x40) != 0 )
{
if ( a4 < 0 )
v8 = a4 + 3;
v28 = 17LL;
v8 >>= 2;
}
else
{
if ( (a3 & 0x4000) != 0 )
{
v30 = 0LL;
v31 = &a5[a4];
if ( v31 > a5 )
{
while ( 1 )
{
v32 = ipv6_printaddr(0LL, 0LL, v6, a6);
if ( v32 != -1 )
v30 += v32;
v6 += 16;
if ( v31 <= (unsigned __int8 *)v6 )
break;
v30 -= (v30 == 0) - 1LL;
}
}
return v30 + 1;
}
if ( (a3 & 0x8000) == 0 )
{
*_errno_location() = 22;
return -1LL;
}
v28 = 3LL;
}
return v28 * v8;
}
return decode_rfc5969(s, maxlen, (unsigned int)a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s, size_t maxlen, int a3, int a4, unsigned __int8 *a5, __int64 a6)
{
char *v6; // r14
size_t v7; // r13
int v8; // er12
char *v9; // rbp
__int64 v11; // r15
unsigned __int16 v12; // ax
const char *v13; // rdx
int v15; // eax
__int64 v16; // rcx
int v17; // eax
unsigned int v18; // eax
const char *v19; // rdx
int v20; // eax
__int64 v21; // rax
unsigned __int8 *v22; // rax
unsigned __int8 *v23; // rbx
const char *v24; // rax
unsigned __int8 *v25; // r12
int v26; // eax
char *v27; // rax
__int64 v28; // rax
int v29; // eax
__int64 v30; // r15
unsigned __int8 *v31; // rbp
int v32; // eax
unsigned __int8 *v33; // [rsp+0h] [rbp-58h]
unsigned __int8 *v35; // [rsp+18h] [rbp-40h]
unsigned __int8 *v36; // [rsp+18h] [rbp-40h]
unsigned __int8 *v37; // [rsp+18h] [rbp-40h]
unsigned __int8 *v38; // [rsp+18h] [rbp-40h]

v6 = (char *)a5;
v7 = maxlen;
v8 = a4;
v9 = s;
if ( (a3 & 0x800) != 0 )
{
v21 = func4(0LL, 0LL, a4, (char *)a5);
v11 = v21;
if ( v21 <= 0 )
return v11;
v22 = (unsigned __int8 *)malloc(v21);
v23 = v22;
if ( v22 )
{
func4(v22, v11, v8, v6);
v11 = func5(s, maxlen, (int)v11 - 1, v23);
free(v23);
return v11;
}
return -1LL;
}
if ( (a3 & 0x400) != 0 )
{
v24 = (const char *)decode_rfc3361((unsigned int)a4, a5);
v25 = (unsigned __int8 *)v24;
if ( v24 )
{
v26 = strlen(v24);
v11 = func5(s, maxlen, v26 - 1, v25);
free(v25);
return v11;
}
return -1LL;
}
if ( (a3 & 0x1000) != 0 )
return decode_rfc3442(s, maxlen, (unsigned int)a4, a5);
if ( (a3 & 0x2000) == 0 )
{
if ( (a3 & 0x80u) != 0 )
{
v11 = 0LL;
LABEL_12:
if ( *v6 )
v11 += func5(s, v7, v8, (unsigned __int8 *)v6);
return v11;
}
if ( (a3 & 0x20000) != 0 )
{
v11 = 2LL;
if ( s )
*(_WORD *)s = 49;
return v11;
}
if ( (a3 & 0x10000) != 0 && a4 > 1 )
{
v11 = 7LL;
if ( s )
{
v12 = func0(*(_WORD *)a5);
v11 = snprintf(s, maxlen, v13, v12);
v7 = maxlen - v11;
}
v6 += 2;
v8 -= 2;
if ( !v8 )
return v11;
goto LABEL_12;
}
if ( s )
{
v33 = &a5[a4];
if ( v33 > a5 )
{
v11 = 0LL;
while ( (a3 & 2) == 0 )
{
while ( 1 )
{
if ( (a3 & 4) != 0 )
{
v36 = a5;
v16 = (unsigned __int16)func0(*(_WORD *)a5);
LABEL_43:
v17 = snprintf(v9, v7, "%d", v16);
a5 = v36 + 2;
v7 -= v17;
v11 += v17;
v9 += v17;
goto LABEL_26;
}
if ( (a3 & 8) != 0 )
{
v36 = a5;
v16 = (unsigned int)func0(*(_WORD *)a5);
goto LABEL_43;
}
if ( (a3 & 0x10) != 0 || (a3 & 0x20) != 0 )
{
v37 = a5;
v18 = func1(*(_DWORD *)a5);
v20 = snprintf(v9, v7, v19, v18);
LABEL_45:
v7 -= v20;
v11 += v20;
v9 += v20;
a5 = v37 + 4;
goto LABEL_26;
}
if ( (a3 & 0x40) != 0 )
{
v37 = a5;
v27 = inet_ntoa(*(struct in_addr *)a5);
v20 = snprintf(v9, v7, "%s", v27);
goto LABEL_45;
}
if ( (a3 & 0x4000) != 0 )
{
v38 = a5;
v29 = ipv6_printaddr(v9, v7, a5, a6);
if ( v29 != -1 )
{
v7 -= v29;
v11 += v29;
v9 += v29;
}
a5 = v38 + 16;
goto LABEL_26;
}
if ( (a3 & 0x8000) != 0 )
{
v35 = a5;
v15 = snprintf(v9, v7, "%.2x", *a5);
LABEL_31:
a5 = v35 + 1;
v7 -= v15;
v11 += v15;
v9 += v15;
}
LABEL_26:
if ( a5 >= v33 )
return v11;
if ( a5 == (unsigned __int8 *)v6 || a3 == 0x8000 )
break;
*v9 = 32;
++v11;
--v7;
++v9;
if ( (a3 & 2) != 0 )
goto LABEL_30;
}
}
LABEL_30:
v35 = a5;
v15 = snprintf(v9, v7, "%d", *a5);
goto LABEL_31;
}
return 0LL;
}
if ( (a3 & 2) != 0 )
{
v28 = 4LL;
}
else if ( (a3 & 4) != 0 )
{
v28 = 6LL;
v8 = a4 / 2;
}
else if ( (a3 & 8) != 0 )
{
v28 = 7LL;
v8 = a4 / 2;
}
else if ( (a3 & 0x10) != 0 )
{
if ( a4 < 0 )
v8 = a4 + 3;
v28 = 11LL;
v8 >>= 2;
}
else if ( (a3 & 0x20) != 0 )
{
if ( a4 < 0 )
v8 = a4 + 3;
v28 = 12LL;
v8 >>= 2;
}
else if ( (a3 & 0x40) != 0 )
{
if ( a4 < 0 )
v8 = a4 + 3;
v28 = 17LL;
v8 >>= 2;
}
else
{
if ( (a3 & 0x4000) != 0 )
{
v30 = 0LL;
v31 = &a5[a4];
if ( v31 > a5 )
{
while ( 1 )
{
v32 = ipv6_printaddr(0LL, 0LL, v6, a6);
if ( v32 != -1 )
v30 += v32;
v6 += 16;
if ( v31 <= (unsigned __int8 *)v6 )
break;
v30 -= (v30 == 0) - 1LL;
}
}
return v30 + 1;
}
if ( (a3 & 0x8000) == 0 )
{
*_errno_location() = 22;
return -1LL;
}
v28 = 3LL;
}
return v28 * v8;
}
return decode_rfc5969(s, maxlen, (unsigned int)a4, a5);
}

original_code:
ssize_t
print_option(char *s, ssize_t len, int type, int dl, const uint8_t *data,
    const char *ifname)
{
 const uint8_t *e, *t;
 uint16_t u16;
 int16_t s16;
 uint32_t u32;
 int32_t s32;
 struct in_addr addr;
 ssize_t bytes = 0;
 ssize_t l;
 char *tmp;
 if (type & (1 << 11)) {
  l = decode_rfc3397(((void *)0), 0, dl, data);
  if (l < 1)
   return l;
  tmp = malloc(l);
  if (tmp == ((void *)0))
   return -1;
  decode_rfc3397(tmp, l, dl, data);
  l = print_string(s, len, l - 1, (uint8_t *)tmp);
  free(tmp);
  return l;
 }
 if (type & (1 << 10)) {
  if ((tmp = decode_rfc3361(dl, data)) == ((void *)0))
   return -1;
  l = strlen(tmp);
  l = print_string(s, len, l - 1, (uint8_t *)tmp);
  free(tmp);
  return l;
 }
 if (type & (1 << 12))
  return decode_rfc3442(s, len, dl, data);
 if (type & (1 << 13))
  return decode_rfc5969(s, len, dl, data);
 if (type & (1 << 7)) {
  if (*data == '\0')
   return 0;
  return print_string(s, len, dl, data);
 }
 if (type & (1 << 17)) {
  if (s) {
   *s++ = '1';
   *s = '\0';
  }
  return 2;
 }
 if (type & (1 << 16) && dl >= (int)sizeof(u16)) {
  if (s) {
   memcpy(&u16, data, sizeof(u16));
   u16 = ntohs(u16);
   l = snprintf(s, len, "%d ", u16);
   len -= l;
  } else
   l = 7;
  data += sizeof(u16);
  dl -= sizeof(u16);
  if (dl)
   l += print_option(s, len, (1 << 7), dl, data, ifname);
  return l;
 }
 if (!s) {
  if (type & (1 << 1))
   l = 3;
  else if (type & (1 << 2)) {
   l = 5;
   dl /= 2;
  } else if (type & (1 << 3)) {
   l = 6;
   dl /= 2;
  } else if (type & (1 << 4)) {
   l = 10;
   dl /= 4;
  } else if (type & (1 << 5)) {
   l = 11;
   dl /= 4;
  } else if (type & (1 << 6)) {
   l = 16;
   dl /= 4;
  }
  else if (type & (1 << 14)) {
   e = data + dl;
   l = 0;
   while (data < e) {
    if (l)
     l++;
    dl = ipv6_printaddr(((void *)0), 0, data, ifname);
    if (dl != -1)
     l += dl;
    data += 16;
   }
   return l + 1;
  }
  else if (type & (1 << 15)) {
   l = 2;
  } else {
   (*__errno_location ()) = 22;
   return -1;
  }
  return (l + 1) * dl;
 }
 t = data;
 e = data + dl;
 while (data < e) {
  if (data != t && type != (1 << 15)) {
   *s++ = ' ';
   bytes++;
   len--;
  }
  if (type & (1 << 1)) {
   l = snprintf(s, len, "%d", *data);
   data++;
  } else if (type & (1 << 2)) {
   memcpy(&u16, data, sizeof(u16));
   u16 = ntohs(u16);
   l = snprintf(s, len, "%d", u16);
   data += sizeof(u16);
  } else if (type & (1 << 3)) {
   memcpy(&s16, data, sizeof(s16));
   s16 = ntohs(s16);
   l = snprintf(s, len, "%d", s16);
   data += sizeof(s16);
  } else if (type & (1 << 4)) {
   memcpy(&u32, data, sizeof(u32));
   u32 = ntohl(u32);
   l = snprintf(s, len, "%d", u32);
   data += sizeof(u32);
  } else if (type & (1 << 5)) {
   memcpy(&s32, data, sizeof(s32));
   s32 = ntohl(s32);
   l = snprintf(s, len, "%d", s32);
   data += sizeof(s32);
  } else if (type & (1 << 6)) {
   memcpy(&addr.s_addr, data, sizeof(addr.s_addr));
   l = snprintf(s, len, "%s", inet_ntoa(addr));
   data += sizeof(addr.s_addr);
  }
  else if (type & (1 << 14)) {
   dl = ipv6_printaddr(s, len, data, ifname);
   if (dl != -1)
    l = dl;
   else
    l = 0;
   data += 16;
  }
  else if (type & (1 << 15)) {
   l = snprintf(s, len, "%.2x", data[0]);
   data++;
  } else
   l = 0;
  len -= l;
  bytes += l;
  s += l;
 }
 return bytes;
}

canonical_original_code:
long print_option(char *s, long len, int type, int dl, unsigned char *data, char *ifname)
{
 unsigned char *e; unsigned char *t;
 unsigned short u16;
 short s16;
 unsigned int u32;
 int s32;
 struct in_addr addr;
 long bytes = 0;
 long l;
 char *tmp;
 if (type & (1 << 11)) {
  l = decode_rfc3397(((void *)0), 0, dl, data);
  if (l < 1)
   return l;
  tmp = malloc(l);
  if (tmp == ((void *)0))
   return -1;
  decode_rfc3397(tmp, l, dl, data);
  l = print_string(s, len, l - 1, (unsigned char *)tmp);
  free(tmp);
  return l;
 }
 if (type & (1 << 10)) {
  if ((tmp = decode_rfc3361(dl, data)) == ((void *)0))
   return -1;
  l = strlen(tmp);
  l = print_string(s, len, l - 1, (unsigned char *)tmp);
  free(tmp);
  return l;
 }
 if (type & (1 << 12))
  return decode_rfc3442(s, len, dl, data);
 if (type & (1 << 13))
  return decode_rfc5969(s, len, dl, data);
 if (type & (1 << 7)) {
  if (*data == '\0')
   return 0;
  return print_string(s, len, dl, data);
 }
 if (type & (1 << 17)) {
  if (s) {
   *s++ = '1';
   *s = '\0';
  }
  return 2;
 }
 if (type & (1 << 16) && dl >= (int)sizeof(u16)) {
  if (s) {
   memcpy(&u16, data, sizeof(u16));
   u16 = ntohs(u16);
   l = snprintf(s, len, "%d ", u16);
   len -= l;
  } else
   l = 7;
  data += sizeof(u16);
  dl -= sizeof(u16);
  if (dl)
   l += print_option(s, len, (1 << 7), dl, data, ifname);
  return l;
 }
 if (!s) {
  if (type & (1 << 1))
   l = 3;
  else if (type & (1 << 2)) {
   l = 5;
   dl /= 2;
  } else if (type & (1 << 3)) {
   l = 6;
   dl /= 2;
  } else if (type & (1 << 4)) {
   l = 10;
   dl /= 4;
  } else if (type & (1 << 5)) {
   l = 11;
   dl /= 4;
  } else if (type & (1 << 6)) {
   l = 16;
   dl /= 4;
  }
  else if (type & (1 << 14)) {
   e = data + dl;
   l = 0;
   while (data < e) {
    if (l)
     l++;
    dl = ipv6_printaddr(((void *)0), 0, data, ifname);
    if (dl != -1)
     l += dl;
    data += 16;
   }
   return l + 1;
  }
  else if (type & (1 << 15)) {
   l = 2;
  } else {
   (*__errno_location ()) = 22;
   return -1;
  }
  return (l + 1) * dl;
 }
 t = data;
 e = data + dl;
 while (data < e) {
  if (data != t && type != (1 << 15)) {
   *s++ = ' ';
   bytes++;
   len--;
  }
  if (type & (1 << 1)) {
   l = snprintf(s, len, "%d", *data);
   data++;
  } else if (type & (1 << 2)) {
   memcpy(&u16, data, sizeof(u16));
   u16 = ntohs(u16);
   l = snprintf(s, len, "%d", u16);
   data += sizeof(u16);
  } else if (type & (1 << 3)) {
   memcpy(&s16, data, sizeof(s16));
   s16 = ntohs(s16);
   l = snprintf(s, len, "%d", s16);
   data += sizeof(s16);
  } else if (type & (1 << 4)) {
   memcpy(&u32, data, sizeof(u32));
   u32 = ntohl(u32);
   l = snprintf(s, len, "%d", u32);
   data += sizeof(u32);
  } else if (type & (1 << 5)) {
   memcpy(&s32, data, sizeof(s32));
   s32 = ntohl(s32);
   l = snprintf(s, len, "%d", s32);
   data += sizeof(s32);
  } else if (type & (1 << 6)) {
   memcpy(&addr.s_addr, data, sizeof(addr.s_addr));
   l = snprintf(s, len, "%s", inet_ntoa(addr));
   data += sizeof(addr.s_addr);
  }
  else if (type & (1 << 14)) {
   dl = ipv6_printaddr(s, len, data, ifname);
   if (dl != -1)
    l = dl;
   else
    l = 0;
   data += 16;
  }
  else if (type & (1 << 15)) {
   l = snprintf(s, len, "%.2x", data[0]);
   data++;
  } else
   l = 0;
  len -= l;
  bytes += l;
  s += l;
 }
 return bytes;
}

variable_types: type int

variable_types:
ifname
char *

variable_types:
t
unsigned char *

variable_types:
addr
struct in_addr { unsigned int s_addr; }

variable_types: l long

variable_types:
tmp
char *


repo: sklvjz/network

decompiled_code:
void __fastcall signal_handler(int a1)
{
int *v1; // rax
char *v2; // rax
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
if ( send(fd, buf, 4uLL, 64) < 0 )
{
v1 = _errno_location();
v2 = strerror(*v1);
logger(3LL, "Could not send signal: %s", v2);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
int *v1; // rax
char *v2; // rax
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
if ( send(fd, buf, 4uLL, 64) < 0 )
{
v1 = _errno_location();
v2 = strerror(*v1);
logger(3LL, "Could not send signal: %s", v2);
}
}

original_code:
static void signal_handler (int sig)
{
  if (send (signal_pipe[1], &sig, sizeof (sig), MSG_DONTWAIT) < 0)
    logger (3, "Could not send signal: %s", strerror ((*__errno_location ())));
}

canonical_original_code:
static void signal_handler(int sig)
{
  if (send (signal_pipe[1], &sig, sizeof (sig), MSG_DONTWAIT) < 0)
    logger (3, "Could not send signal: %s", strerror ((*__errno_location ())));
}

variable_types: sig int

return_type: void


decompiled_code:
__sighandler_t signal_setup()
{
int *v0; // rbx
int v1; // eax
int *v3; // rax
char *v4; // rax

v0 = signal_pipe;
socketpair(1, 1, 0, signal_pipe);
do
{
v1 = fcntl(*v0, 1, 0LL);
if ( v1 < 0 || fcntl(*v0, 2, v1 | 1u) < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
logger(3LL, "fcntl: %s", v4);
}
++v0;
}
while ( v0 != (int *)"Could not send signal: %s" );
signal(1, signal_handler);
signal(14, signal_handler);
signal(15, signal_handler);
return signal(2, signal_handler);
}

canonical_decompiled_code:
__sighandler_t func1()
{
int *v0; // rbx
int v1; // eax
int *v3; // rax
char *v4; // rax

v0 = signal_pipe;
socketpair(1, 1, 0, signal_pipe);
do
{
v1 = fcntl(*v0, 1, 0LL);
if ( v1 < 0 || fcntl(*v0, 2, v1 | 1u) < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
logger(3LL, "fcntl: %s", v4);
}
++v0;
}
while ( v0 != (int *)"Could not send signal: %s" );
signal(1, signal_handler);
signal(14, signal_handler);
signal(15, signal_handler);
return signal(2, signal_handler);
}

original_code:
void signal_setup(void)
{
  int i;
  int flags;
  socketpair (1, SOCK_STREAM, 0, signal_pipe);
  for (i = 0; i < 2; i++)
    if ((flags = fcntl (signal_pipe[i], 1, 0)) < 0 ||
 fcntl (signal_pipe[i], 2, flags | 1) < 0)
      logger (3 ,"fcntl: %s", strerror ((*__errno_location ())));
  signal (1, signal_handler);
  signal (14, signal_handler);
  signal (15, signal_handler);
  signal (2, signal_handler);
}

canonical_original_code:
void signal_setup()
{
  int i;
  int flags;
  socketpair (1, SOCK_STREAM, 0, signal_pipe);
  for (i = 0; i < 2; i++)
    if ((flags = fcntl (signal_pipe[i], 1, 0)) < 0 ||
 fcntl (signal_pipe[i], 2, flags | 1) < 0)
      logger (3 ,"fcntl: %s", strerror ((*__errno_location ())));
  signal (1, signal_handler);
  signal (14, signal_handler);
  signal (15, signal_handler);
  signal (2, signal_handler);
}

variable_types: i int

variable_types: flags int


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

memset(a1, 0, 0x80uLL);
result = (unsigned int)signal_pipe[0];
*((_QWORD *)a1 + signal_pipe[0] / 64) |= 1LL << (signal_pipe[0] % 64);
if ( a2 >= 0 )
*((_QWORD *)a1 + (a2 >> 6)) |= 1LL << a2;
if ( (int)result < a2 )
result = (unsigned int)a2;
return result;
}

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

memset(a1, 0, 0x80uLL);
result = (unsigned int)signal_pipe[0];
*((_QWORD *)a1 + signal_pipe[0] / 64) |= 1LL << (signal_pipe[0] % 64);
if ( a2 >= 0 )
*((_QWORD *)a1 + (a2 >> 6)) |= 1LL << a2;
if ( (int)result < a2 )
result = (unsigned int)a2;
return result;
}

original_code:
int signal_fd_set (fd_set *rfds, int extra_fd)
{
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((rfds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((rfds)->__fds_bits)[((signal_pipe[0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((signal_pipe[0]) % (8 * (int) sizeof (__fd_mask)))))));
  if (extra_fd >= 0)
    ((void) (((rfds)->__fds_bits)[((extra_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((extra_fd) % (8 * (int) sizeof (__fd_mask)))))));
  return signal_pipe[0] > extra_fd ? signal_pipe[0] : extra_fd;
}

canonical_original_code:
int signal_fd_set(struct fd_set *rfds, int extra_fd)
{
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((rfds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((rfds)->__fds_bits)[((signal_pipe[0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((signal_pipe[0]) % (8 * (int) sizeof (__fd_mask)))))));
  if (extra_fd >= 0)
    ((void) (((rfds)->__fds_bits)[((extra_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((extra_fd) % (8 * (int) sizeof (__fd_mask)))))));
  return signal_pipe[0] > extra_fd ? signal_pipe[0] : extra_fd;
}

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

return_type: int


decompiled_code:
__int64 __fastcall signal_read(__int64 a1)
{
__int64 result; // rax
unsigned int buf[3]; // [rsp+0h] [rbp-Ch] BYREF

result = 0LL;
if ( (*(_QWORD *)(a1 + 8LL * (signal_pipe[0] / 64)) & (1LL << (signal_pipe[0] % 64))) != 0 )
{
if ( read(signal_pipe[0], buf, 4uLL) < 0 )
result = 0xFFFFFFFFLL;
else
result = buf[0];
}
return result;
}

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

result = 0LL;
if ( (*(_QWORD *)(a1 + 8LL * (signal_pipe[0] / 64)) & (1LL << (signal_pipe[0] % 64))) != 0 )
{
if ( read(signal_pipe[0], buf, 4uLL) < 0 )
result = 0xFFFFFFFFLL;
else
result = buf[0];
}
return result;
}

original_code:
int signal_read (fd_set *rfds)
{
  int sig;
  if (!((((rfds)->__fds_bits)[((signal_pipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((signal_pipe[0]) % (8 * (int) sizeof (__fd_mask)))))) != 0))
    return 0;
  if (read (signal_pipe[0], &sig, sizeof (sig)) < 0)
    return -1;
  return sig;
}

canonical_original_code:
int signal_read(struct fd_set *rfds)
{
  int sig;
  if (!((((rfds)->__fds_bits)[((signal_pipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((signal_pipe[0]) % (8 * (int) sizeof (__fd_mask)))))) != 0))
    return 0;
  if (read (signal_pipe[0], &sig, sizeof (sig)) < 0)
    return -1;
  return sig;
}


decompiled_code:
char *__fastcall hwaddr_ntoa(__int64 a1, __int64 a2)
{
char *v2; // rbx
char *v3; // rax
__int64 v4; // rbp
__int64 v5; // rcx

v2 = hwaddr_buffer;
v3 = hwaddr_buffer;
if ( a2 )
{
v4 = 0LL;
while ( 1 )
{
v5 = *(unsigned __int8 *)(a1 + v4++);
snprintf(v2, 3uLL, "%.2x", v5);
v3 = v2 + 2;
if ( a2 == v4 )
break;
v2[2] = 58;
v2 += 3;
}
}
*v3 = 0;
return hwaddr_buffer;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, __int64 a2)
{
char *v2; // rbx
char *v3; // rax
__int64 v4; // rbp
__int64 v5; // rcx

v2 = hwaddr_buffer;
v3 = hwaddr_buffer;
if ( a2 )
{
v4 = 0LL;
while ( 1 )
{
v5 = *(unsigned __int8 *)(a1 + v4++);
snprintf(v2, 3uLL, "%.2x", v5);
v3 = v2 + 2;
if ( a2 == v4 )
break;
v2[2] = 58;
v2 += 3;
}
}
*v3 = 0;
return hwaddr_buffer;
}

original_code:
char *
hwaddr_ntoa(const unsigned char *hwaddr, size_t hwlen)
{
 char *p = hwaddr_buffer;
 size_t i;
 for (i = 0; i < hwlen; i++) {
  if (i > 0)
   *p ++= ':';
  p += snprintf(p, 3, "%.2x", hwaddr[i]);
 }
 *p ++= '\0';
 return hwaddr_buffer;
}

canonical_original_code:
char *hwaddr_ntoa(unsigned char *hwaddr, unsigned long hwlen)
{
 char *p = hwaddr_buffer;
 unsigned long i;
 for (i = 0; i < hwlen; i++) {
  if (i > 0)
   *p ++= ':';
  p += snprintf(p, 3, "%.2x", hwaddr[i]);
 }
 *p ++= '\0';
 return hwaddr_buffer;
}

variable_types:
hwaddr
unsigned char *

variable_types:
hwlen
unsigned long

variable_types:
p
char *

variable_types:
i
unsigned long

return_type: char *


decompiled_code:
__int64 __fastcall hwaddr_aton(_BYTE *a1, unsigned __int8 *a2)
{
__int64 v2; // rbx
unsigned __int8 *v4; // rbp
__int64 v5; // r12
const unsigned __int16 **v6; // r14
__int64 v7; // rax
const unsigned __int16 *v8; // rdx
unsigned __int8 v9; // al
char nptr[43]; // [rsp+Dh] [rbp-2Bh] BYREF

v2 = *a2;
nptr[2] = 0;
if ( (_BYTE)v2 )
{
v4 = a2;
v5 = 0LL;
v6 = _ctype_b_loc();
while ( 1 )
{
v7 = v4[1];
v8 = *v6;
nptr[0] = v2;
nptr[1] = v7;
if ( (v8[v2] & 0x1000) == 0 || (v8[v7] & 0x1000) == 0 )
{
LABEL_15:
v5 = 0LL;
*_errno_location() = 22;
return v5;
}
v9 = v4[2];
if ( v5 )
{
if ( !v9 )
{
v4 += 2;
goto LABEL_7;
}
}
else if ( !v9 )
{
*_errno_location() = 22;
return 0LL;
}
if ( v9 != 58 || !v4[3] )
goto LABEL_15;
v4 += 3;
LABEL_7:
if ( a1 )
*a1++ = strtol(nptr, 0LL, 16);
v2 = *v4;
++v5;
if ( !(_BYTE)v2 )
return v5;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, unsigned __int8 *a2)
{
__int64 v2; // rbx
unsigned __int8 *v4; // rbp
__int64 v5; // r12
const unsigned __int16 **v6; // r14
__int64 v7; // rax
const unsigned __int16 *v8; // rdx
unsigned __int8 v9; // al
char nptr[43]; // [rsp+Dh] [rbp-2Bh] BYREF

v2 = *a2;
nptr[2] = 0;
if ( (_BYTE)v2 )
{
v4 = a2;
v5 = 0LL;
v6 = _ctype_b_loc();
while ( 1 )
{
v7 = v4[1];
v8 = *v6;
nptr[0] = v2;
nptr[1] = v7;
if ( (v8[v2] & 0x1000) == 0 || (v8[v7] & 0x1000) == 0 )
{
LABEL_15:
v5 = 0LL;
*_errno_location() = 22;
return v5;
}
v9 = v4[2];
if ( v5 )
{
if ( !v9 )
{
v4 += 2;
goto LABEL_7;
}
}
else if ( !v9 )
{
*_errno_location() = 22;
return 0LL;
}
if ( v9 != 58 || !v4[3] )
goto LABEL_15;
v4 += 3;
LABEL_7:
if ( a1 )
*a1++ = strtol(nptr, 0LL, 16);
v2 = *v4;
++v5;
if ( !(_BYTE)v2 )
return v5;
}
}
return 0LL;
}

original_code:
size_t
hwaddr_aton(unsigned char *buffer, const char *addr)
{
 char c[3];
 const char *p = addr;
 unsigned char *bp = buffer;
 size_t len = 0;
 c[2] = '\0';
 while (*p) {
  c[0] = *p++;
  c[1] = *p++;
  if (((*__ctype_b_loc ())[(int) (((unsigned char)c[0]))] & (unsigned short int) _ISxdigit) == 0 ||
      ((*__ctype_b_loc ())[(int) (((unsigned char)c[1]))] & (unsigned short int) _ISxdigit) == 0)
  {
   (*__errno_location ()) = 22;
   return 0;
  }
  if (len == 0 && *p == '\0') {
   (*__errno_location ()) = 22;
   return 0;
  }
  if (!(*p == '\0' || (*p == ':' && *(p + 1) != '\0'))) {
   (*__errno_location ()) = 22;
   return 0;
  }
  if (*p)
   p++;
  if (bp)
   *bp++ = (unsigned char)strtol(c, ((void *)0), 16);
  len++;
 }
 return len;
}

canonical_original_code:
unsigned long hwaddr_aton(unsigned char *buffer, char *addr)
{
 char c[3];
 char *p = addr;
 unsigned char *bp = buffer;
 unsigned long len = 0;
 c[2] = '\0';
 while (*p) {
  c[0] = *p++;
  c[1] = *p++;
  if (((*__ctype_b_loc ())[(int) (((unsigned char)c[0]))] & (unsigned short) _ISxdigit) == 0 ||
      ((*__ctype_b_loc ())[(int) (((unsigned char)c[1]))] & (unsigned short) _ISxdigit) == 0)
  {
   (*__errno_location ()) = 22;
   return 0;
  }
  if (len == 0 && *p == '\0') {
   (*__errno_location ()) = 22;
   return 0;
  }
  if (!(*p == '\0' || (*p == ':' && *(p + 1) != '\0'))) {
   (*__errno_location ()) = 22;
   return 0;
  }
  if (*p)
   p++;
  if (bp)
   *bp++ = (unsigned char)strtol(c, ((void *)0), 16);
  len++;
 }
 return len;
}

variable_types:
buffer
unsigned char *

variable_types:
addr
char *

variable_types:
c
char [3]

variable_types:
bp
unsigned char *

variable_types:
len
unsigned long

return_type: unsigned long


decompiled_code:
void __fastcall free_interface(void *ptr)
{
if ( ptr )
{
dhcp_free();
ipv6_free(ptr);
dhcp6_free(ptr);
ipv6nd_free(ptr);
free_options(*((_QWORD *)ptr + 23));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( ptr )
{
dhcp_free();
ipv6_free(ptr);
dhcp6_free(ptr);
ipv6nd_free(ptr);
free_options(*((_QWORD *)ptr + 23));
free(ptr);
}
}

original_code:
void
free_interface(struct interface *ifp)
{
 if (ifp == ((void *)0))
  return;
 dhcp_free(ifp);
 ipv6_free(ifp);
 dhcp6_free(ifp);
 ipv6nd_free(ifp);
 free_options(ifp->options);
 free(ifp);
}

variable_types: struct interface { struct { struct interface *tqe_next; struct interface **tqe_prev; } next; char name[16]; unsigned int index; int flags; unsigned short family; unsigned char hwaddr[20]; unsigned long hwlen; int metric; int carrier; int wireless; char ssid[33]; char profile[64]; struct if_options { int metric; unsigned char requestmask[-1]; unsigned char requiremask[-1]; unsigned char nomask[-1]; unsigned char requestmask6[-1]; unsigned char requiremask6[-1]; unsigned char nomask6[-1]; unsigned char dstmask[-1]; unsigned int leasetime; long timeout; long reboot; unsigned long long options; struct in_addr { unsigned int s_addr; } req_addr; struct in_addr req_mask; struct rt_head { struct rt { struct { struct rt *tqe_next; struct rt **tqe_prev; } next; struct in_addr dest; struct in_addr net; struct in_addr gate; struct interface *iface; int metric; struct in_addr src; } *tqh_first; struct rt **tqh_last; } *routes; char **config; char **environ; char script[4096]; char hostname[-1]; int fqdn; unsigned char vendorclassid[-1]; char clientid[-1]; unsigned char userclass[-1]; unsigned char vendor[-1]; unsigned long blacklist_len; unsigned int *blacklist; unsigned long whitelist_len; unsigned int *whitelist; unsigned long arping_len; unsigned int *arping; char *fallback; unsigned short ia_type; unsigned long iaid_len; struct if_iaid { unsigned char iaid[4]; unsigned long sla_len; struct if_sla { char ifname[16]; unsigned int sla; short prefix_len; char sla_set; } *sla; } *iaid; int dadtransmits; } *options; void *if_data[4]; } *

user_defined_types: struct interface { struct { struct interface *tqe_next; struct interface **tqe_prev; } next; char name[16]; unsigned int index; int flags; unsigned short family; unsigned char hwaddr[20]; unsigned long hwlen; int metric; int carrier; int wireless; char ssid[33]; char profile[64]; struct if_options *options; void *if_data[4]; }

user_defined_types: struct if_options { int metric; unsigned char requestmask[-1]; unsigned char requiremask[-1]; unsigned char nomask[-1]; unsigned char requestmask6[-1]; unsigned char requiremask6[-1]; unsigned char nomask6[-1]; unsigned char dstmask[-1]; unsigned int leasetime; long timeout; long reboot; unsigned long long options; struct in_addr req_addr; struct in_addr req_mask; struct rt_head *routes; char **config; char **environ; char script[4096]; char hostname[-1]; int fqdn; unsigned char vendorclassid[-1]; char clientid[-1]; unsigned char userclass[-1]; unsigned char vendor[-1]; unsigned long blacklist_len; unsigned int *blacklist; unsigned long whitelist_len; unsigned int *whitelist; unsigned long arping_len; unsigned int *arping; char *fallback; unsigned short ia_type; unsigned long iaid_len; struct if_iaid *iaid; int dadtransmits; }

user_defined_types: struct rt_head { struct rt *tqh_first; struct rt **tqh_last; }

user_defined_types: struct if_iaid { unsigned char iaid[4]; unsigned long sla_len; struct if_sla *sla; }


decompiled_code:
__int64 __fastcall carrier_status(__int64 a1)
{
char *v1; // rax
int v2; // er8
__int64 result; // rax
char v4; // al
__int128 v5; // [rsp+0h] [rbp-38h] BYREF
__int128 v6; // [rsp+10h] [rbp-28h]
__int64 v7; // [rsp+20h] [rbp-18h]

v5 = 0LL;
v7 = 0LL;
v6 = 0LL;
strlcpy(&v5, a1 + 16, 16LL);
v1 = strchr((const char *)&v5, 58);
if ( v1 )
*v1 = 0;
v2 = ioctl(socket_afnet, 0x8913uLL, &v5);
result = 0LL;
if ( v2 != -1 )
{
v4 = v6;
*(_DWORD *)(a1 + 36) = (__int16)v6;
result = (v4 & 0x40) == 0 ? -1 : 1;
}
return result;
}

original_code:
int
carrier_status(struct interface *iface)
{
 int ret;
 struct ifreq ifr;
 char *p;
 memset(&ifr, 0, sizeof(ifr));
 strlcpy(ifr.ifr_ifrn.ifrn_name, iface->name, sizeof(ifr.ifr_ifrn.ifrn_name));
 if ((p = strchr(ifr.ifr_ifrn.ifrn_name, ':')))
  *p = '\0';
 if (ioctl(socket_afnet, 0x8913, &ifr) == -1)
  return 0;
 iface->flags = ifr.ifr_ifru.ifru_flags;
 ret = 0;
 if (ret == 0)
  ret = (ifr.ifr_ifru.ifru_flags & IFF_RUNNING) ? 1 : -1;
 return ret;
}

variable_types: ret int

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]; char *ifru_data; } ifr_ifru; }

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]; char *ifru_data; } ifr_ifru; }

user_defined_types: struct rt { struct { struct rt *tqe_next; struct rt **tqe_prev; } next; struct in_addr dest; struct in_addr net; struct in_addr gate; struct interface *iface; int metric; struct in_addr src; }

user_defined_types: struct if_sla { char ifname[16]; unsigned int sla; short prefix_len; char sla_set; }


decompiled_code:
__int64 __fastcall up_interface(__int64 a1)
{
char *v1; // rax
unsigned int v2; // eax
__int64 v3; // rcx
__int64 v4; // r8
int v5; // eax
bool v7; // zf
__int128 v8; // [rsp+0h] [rbp-38h] BYREF
__int128 v9; // [rsp+10h] [rbp-28h]
__int64 v10; // [rsp+20h] [rbp-18h]

v8 = 0LL;
v10 = 0LL;
v9 = 0LL;
strlcpy(&v8, a1 + 16, 16LL);
v1 = strchr((const char *)&v8, 58);
if ( v1 )
*v1 = 0;
v2 = ioctl(socket_afnet, 0x8913uLL, &v8);
v4 = v2;
if ( v2 )
{
LODWORD(v4) = -1;
}
else
{
v5 = (__int16)v9;
if ( (v9 & 1) == 0 )
{
LOWORD(v9) = v9 | 1;
v7 = ioctl(socket_afnet, 0x8914uLL, &v8, v3, v4) == 0;
v5 = (__int16)v9;
LODWORD(v4) = -!v7;
}
*(_DWORD *)(a1 + 36) = v5;
}
return (unsigned int)v4;
}

original_code:
int
up_interface(struct interface *iface)
{
 struct ifreq ifr;
 int retval = -1;
 char *p;
 memset(&ifr, 0, sizeof(ifr));
 strlcpy(ifr.ifr_ifrn.ifrn_name, iface->name, sizeof(ifr.ifr_ifrn.ifrn_name));
 if ((p = strchr(ifr.ifr_ifrn.ifrn_name, ':')))
  *p = '\0';
 if (ioctl(socket_afnet, 0x8913, &ifr) == 0) {
  if ((ifr.ifr_ifru.ifru_flags & IFF_UP))
   retval = 0;
  else {
   ifr.ifr_ifru.ifru_flags |= IFF_UP;
   if (ioctl(socket_afnet, 0x8914, &ifr) == 0)
    retval = 0;
  }
  iface->flags = ifr.ifr_ifru.ifru_flags;
 }
 return retval;
}

variable_types: retval int

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


decompiled_code:
int __fastcall do_mtu(__int64 a1, __int16 a2)
{
int result; // eax
__int128 v3; // [rsp+0h] [rbp-38h] BYREF
__int128 v4; // [rsp+10h] [rbp-28h]
__int64 v5; // [rsp+20h] [rbp-18h]

v3 = 0LL;
v5 = 0LL;
v4 = 0LL;
strlcpy(&v3, a1, 16LL);
LODWORD(v4) = a2;
result = ioctl(socket_afnet, 35105 - ((a2 == 0) - 1LL), &v3);
if ( result != -1 )
result = v4;
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int16 a2)
{
int result; // eax
__int128 v3; // [rsp+0h] [rbp-38h] BYREF
__int128 v4; // [rsp+10h] [rbp-28h]
__int64 v5; // [rsp+20h] [rbp-18h]

v3 = 0LL;
v5 = 0LL;
v4 = 0LL;
strlcpy(&v3, a1, 16LL);
LODWORD(v4) = a2;
result = ioctl(socket_afnet, 35105 - ((a2 == 0) - 1LL), &v3);
if ( result != -1 )
result = v4;
return result;
}

original_code:
int
do_mtu(const char *ifname, short int mtu)
{
 struct ifreq ifr;
 int r;
 memset(&ifr, 0, sizeof(ifr));
 strlcpy(ifr.ifr_ifrn.ifrn_name, ifname, sizeof(ifr.ifr_ifrn.ifrn_name));
 ifr.ifr_ifru.ifru_mtu = mtu;
 r = ioctl(socket_afnet, mtu ? 0x8922 : 0x8921, &ifr);
 if (r == -1)
  return -1;
 return ifr.ifr_ifru.ifru_mtu;
}

canonical_original_code:
int do_mtu(char *ifname, short mtu)
{
 struct ifreq ifr;
 int r;
 memset(&ifr, 0, sizeof(ifr));
 strlcpy(ifr.ifr_ifrn.ifrn_name, ifname, sizeof(ifr.ifr_ifrn.ifrn_name));
 ifr.ifr_ifru.ifru_mtu = mtu;
 r = ioctl(socket_afnet, mtu ? 0x8922 : 0x8921, &ifr);
 if (r == -1)
  return -1;
 return ifr.ifr_ifru.ifru_mtu;
}

variable_types:
ifname
char *

variable_types: mtu short

variable_types: r int


decompiled_code:
const char **__fastcall discover_interfaces(int a1, const char **a2)
{
const char **v2; // rax
const char **v3; // r14
struct ifaddrs *v4; // rbp
struct sockaddr *v5; // rax
const char *v6; // rbx
const char *v7; // r12
const char *v8; // r12
__int64 v9; // r15
__int64 v10; // r15
int v11; // eax
int v12; // ebx
char *v13; // rax
__int64 v14; // r15
const char *v15; // rbx
unsigned int v16; // eax
int v17; // er9
struct sockaddr *v18; // rcx
unsigned int v19; // er9
__int64 v20; // rdx
__int16 v21; // ax
const char *v22; // rdx
int v23; // eax
const char *v24; // rsi
__int64 *v25; // rax
struct sockaddr *v26; // rcx
char *v27; // r12
unsigned int v28; // eax
const char **v30; // r12
int v31; // ebx
char *v32; // rax
char *v33; // r10
char *v34; // rsi
unsigned int v35; // eax
int v37; // [rsp+Ch] [rbp-5Ch]
struct ifaddrs *ifap; // [rsp+18h] [rbp-50h] BYREF
char s[72]; // [rsp+20h] [rbp-48h] BYREF

if ( getifaddrs(&ifap) == -1 )
return 0LL;
v2 = (const char **)malloc(0x10uLL);
v3 = v2;
if ( !v2 )
return 0LL;
v4 = ifap;
*v2 = 0LL;
v2[1] = (const char *)v2;
if ( !v4 )
goto LABEL_51;
do
{
while ( 1 )
{
v5 = v4->ifa_addr;
if ( v5 && v5->sa_family != 17 )
goto LABEL_5;
v6 = *v3;
if ( *v3 )
{
v7 = v4->ifa_name;
while ( strcmp(v6 + 16, v7) )
{
v6 = *(const char **)v6;
if ( !v6 )
goto LABEL_12;
}
goto LABEL_5;
}
LABEL_12:
if ( a1 > 0 )
{
v30 = a2;
v31 = 0;
while ( 1 )
{
strlcpy(s, *v30, 16LL);
v32 = strchr(s, 58);
if ( v32 )
*v32 = 0;
if ( !strcmp(s, v4->ifa_name) )
break;
++v31;
++v30;
if ( a1 == v31 )
goto LABEL_5;
}
if ( a1 == v31 )
goto LABEL_5;
v8 = a2[v31];
}
else
{
v8 = v4->ifa_name;
if ( a1 == -1 && strcmp(*a2, v4->ifa_name) )
goto LABEL_5;
}
if ( ifdc > 0 )
{
v9 = 0LL;
while ( fnmatch(*(const char **)(ifdv + 8 * v9), v8, 0) )
{
if ( ifdc <= (int)++v9 )
goto LABEL_20;
}
if ( ifdc > (int)v9 )
goto LABEL_5;
}
LABEL_20:
v10 = 0LL;
if ( ifac <= 0 )
break;
while ( 1 )
{
v12 = v10;
if ( !fnmatch(*(const char **)(ifav + 8 * v10), v8, 0) )
break;
v11 = ifac;
v12 = ++v10;
if ( ifac <= (int)v10 )
goto LABEL_25;
}
v11 = ifac;
LABEL_25:
if ( !v11 || v12 != v11 )
break;
LABEL_5:
v4 = v4->ifa_next;
if ( !v4 )
goto LABEL_43;
}
v13 = (char *)calloc(1uLL, 0xE0uLL);
v14 = (__int64)v13;
if ( !v13 )
return 0LL;
v15 = v13 + 16;
strlcpy(v13 + 16, v8, 16LL);
v16 = v4->ifa_flags;
*(_DWORD *)(v14 + 36) = v16;
if ( (v16 & 1) != 0 )
goto LABEL_29;
if ( (unsigned int)up_interface(v14) )
{
syslog(3, "%s: up_interface: %m", v15);
v16 = *(_DWORD *)(v14 + 36);
LABEL_29:
v17 = v16 & 8;
if ( (v16 & 8) == 0 )
goto LABEL_30;
goto LABEL_60;
}
options |= 0x4000000uLL;
v16 = *(_DWORD *)(v14 + 36);
v17 = v16 & 8;
if ( (v16 & 8) == 0 )
{
LABEL_30:
v18 = v4->ifa_addr;
if ( v18 )
{
v19 = *(unsigned __int16 *)&v18->sa_data[6];
*(_DWORD *)(v14 + 32) = *(_DWORD *)&v18->sa_data[2];
*(_WORD *)(v14 + 40) = v19;
v20 = (unsigned __int8)v18->sa_data[9];
*(_QWORD *)(v14 + 64) = v20;
if ( v20 )
{
v33 = (char *)(v14 + 42);
v34 = &v18->sa_data[10];
if ( (unsigned int)v20 >= 8 )
{
*(_QWORD *)(v14 + 42) = *(_QWORD *)&v18->sa_data[10];
*(_QWORD *)&v33[v20 - 8] = *(_QWORD *)&v34[v20 - 8];
qmemcpy(
(void *)((v14 + 50) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v34 - &v33[-((v14 + 50) & 0xFFFFFFFFFFFFFFF8LL)]),
8LL * (((unsigned int)v20 + (_DWORD)v33 - (((_DWORD)v14 + 50) & 0xFFFFFFF8)) >> 3));
}
else if ( (v20 & 4) != 0 )
{
*(_DWORD *)(v14 + 42) = *(_DWORD *)&v18->sa_data[10];
*(_DWORD *)&v33[v20 - 4] = *(_DWORD *)&v34[v20 - 4];
}
else
{
*(_BYTE *)(v14 + 42) = v18->sa_data[10];
if ( (v20 & 2) != 0 )
*(_WORD *)&v33[v20 - 2] = *(_WORD *)&v34[v20 - 2];
}
}
}
else
{
v37 = v17;
v35 = if_nametoindex(v15);
v19 = v37;
*(_DWORD *)(v14 + 32) = v35;
v16 = *(_DWORD *)(v14 + 36);
}
goto LABEL_32;
}
LABEL_60:
v19 = 0;
if ( !(ifac | a1) )
goto LABEL_61;
LABEL_32:
if ( (v16 & 0x10) != 0 )
goto LABEL_37;
v21 = *(_WORD *)(v14 + 40);
if ( v21 == 1 )
goto LABEL_37;
if ( !(ifac | a1) )
{
LABEL_61:
free_interface((void *)v14);
goto LABEL_5;
}
if ( ((v21 - 24) & 0xFFF7) != 0 )
{
syslog(4, "%s: unsupported interface type %.2x, falling back to ethernet", v15, v19);
*(_WORD *)(v14 + 40) = 1;
}
LABEL_37:
if ( (unsigned int)if_init(v14) == -1 )
{
v22 = v8;
v24 = "%s: if_init: %m";
LABEL_70:
syslog(3, v24, v22);
free_interface((void *)v14);
goto LABEL_5;
}
if ( do_mtu((__int64)v15, 0) <= 575 )
{
v23 = do_mtu((__int64)v15, 576);
v22 = v8;
v24 = "%s: set_mtu: %m";
if ( v23 == -1 )
goto LABEL_70;
}
*(_DWORD *)(v14 + 72) = *(_DWORD *)(v14 + 32) + 200;
if ( (unsigned int)getifssid(v15, v14 + 84, v22) != -1 )
{
*(_DWORD *)(v14 + 72) += 100;
*(_DWORD *)(v14 + 80) = 1;
}
v25 = (__int64 *)v3[1];
v4 = v4->ifa_next;
*(_QWORD *)v14 = 0LL;
*(_QWORD *)(v14 + 8) = v25;
*v25 = v14;
v3[1] = (const char *)v14;
}
while ( v4 );
LABEL_43:
v4 = ifap;
if ( ifap )
{
do
{
while ( 1 )
{
v26 = v4->ifa_addr;
if ( v26 )
{
if ( v26->sa_family == 10 )
{
v27 = &v26->sa_data[6];
v28 = in6_addr_flags(v4->ifa_name, &v26->sa_data[6]);
if ( v28 != -1 )
break;
}
}
v4 = v4->ifa_next;
if ( !v4 )
goto LABEL_50;
}
ipv6_handleifa(20LL, v3, v4->ifa_name, v27, v28);
v4 = v4->ifa_next;
}
while ( v4 );
LABEL_50:
v4 = ifap;
}
LABEL_51:
freeifaddrs(v4);
return v3;
}

canonical_decompiled_code:
const char **__fastcall func6(int a1, const char **a2)
{
const char **v2; // rax
const char **v3; // r14
struct ifaddrs *v4; // rbp
struct sockaddr *v5; // rax
const char *v6; // rbx
const char *v7; // r12
const char *v8; // r12
__int64 v9; // r15
__int64 v10; // r15
int v11; // eax
int v12; // ebx
char *v13; // rax
__int64 v14; // r15
const char *v15; // rbx
unsigned int v16; // eax
int v17; // er9
struct sockaddr *v18; // rcx
unsigned int v19; // er9
__int64 v20; // rdx
__int16 v21; // ax
const char *v22; // rdx
int v23; // eax
const char *v24; // rsi
__int64 *v25; // rax
struct sockaddr *v26; // rcx
char *v27; // r12
unsigned int v28; // eax
const char **v30; // r12
int v31; // ebx
char *v32; // rax
char *v33; // r10
char *v34; // rsi
unsigned int v35; // eax
int v37; // [rsp+Ch] [rbp-5Ch]
struct ifaddrs *ifap; // [rsp+18h] [rbp-50h] BYREF
char s[72]; // [rsp+20h] [rbp-48h] BYREF

if ( getifaddrs(&ifap) == -1 )
return 0LL;
v2 = (const char **)malloc(0x10uLL);
v3 = v2;
if ( !v2 )
return 0LL;
v4 = ifap;
*v2 = 0LL;
v2[1] = (const char *)v2;
if ( !v4 )
goto LABEL_51;
do
{
while ( 1 )
{
v5 = v4->ifa_addr;
if ( v5 && v5->sa_family != 17 )
goto LABEL_5;
v6 = *v3;
if ( *v3 )
{
v7 = v4->ifa_name;
while ( strcmp(v6 + 16, v7) )
{
v6 = *(const char **)v6;
if ( !v6 )
goto LABEL_12;
}
goto LABEL_5;
}
LABEL_12:
if ( a1 > 0 )
{
v30 = a2;
v31 = 0;
while ( 1 )
{
strlcpy(s, *v30, 16LL);
v32 = strchr(s, 58);
if ( v32 )
*v32 = 0;
if ( !strcmp(s, v4->ifa_name) )
break;
++v31;
++v30;
if ( a1 == v31 )
goto LABEL_5;
}
if ( a1 == v31 )
goto LABEL_5;
v8 = a2[v31];
}
else
{
v8 = v4->ifa_name;
if ( a1 == -1 && strcmp(*a2, v4->ifa_name) )
goto LABEL_5;
}
if ( ifdc > 0 )
{
v9 = 0LL;
while ( fnmatch(*(const char **)(ifdv + 8 * v9), v8, 0) )
{
if ( ifdc <= (int)++v9 )
goto LABEL_20;
}
if ( ifdc > (int)v9 )
goto LABEL_5;
}
LABEL_20:
v10 = 0LL;
if ( ifac <= 0 )
break;
while ( 1 )
{
v12 = v10;
if ( !fnmatch(*(const char **)(ifav + 8 * v10), v8, 0) )
break;
v11 = ifac;
v12 = ++v10;
if ( ifac <= (int)v10 )
goto LABEL_25;
}
v11 = ifac;
LABEL_25:
if ( !v11 || v12 != v11 )
break;
LABEL_5:
v4 = v4->ifa_next;
if ( !v4 )
goto LABEL_43;
}
v13 = (char *)calloc(1uLL, 0xE0uLL);
v14 = (__int64)v13;
if ( !v13 )
return 0LL;
v15 = v13 + 16;
strlcpy(v13 + 16, v8, 16LL);
v16 = v4->ifa_flags;
*(_DWORD *)(v14 + 36) = v16;
if ( (v16 & 1) != 0 )
goto LABEL_29;
if ( (unsigned int)func4(v14) )
{
syslog(3, "%s: up_interface: %m", v15);
v16 = *(_DWORD *)(v14 + 36);
LABEL_29:
v17 = v16 & 8;
if ( (v16 & 8) == 0 )
goto LABEL_30;
goto LABEL_60;
}
options |= 0x4000000uLL;
v16 = *(_DWORD *)(v14 + 36);
v17 = v16 & 8;
if ( (v16 & 8) == 0 )
{
LABEL_30:
v18 = v4->ifa_addr;
if ( v18 )
{
v19 = *(unsigned __int16 *)&v18->sa_data[6];
*(_DWORD *)(v14 + 32) = *(_DWORD *)&v18->sa_data[2];
*(_WORD *)(v14 + 40) = v19;
v20 = (unsigned __int8)v18->sa_data[9];
*(_QWORD *)(v14 + 64) = v20;
if ( v20 )
{
v33 = (char *)(v14 + 42);
v34 = &v18->sa_data[10];
if ( (unsigned int)v20 >= 8 )
{
*(_QWORD *)(v14 + 42) = *(_QWORD *)&v18->sa_data[10];
*(_QWORD *)&v33[v20 - 8] = *(_QWORD *)&v34[v20 - 8];
qmemcpy(
(void *)((v14 + 50) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v34 - &v33[-((v14 + 50) & 0xFFFFFFFFFFFFFFF8LL)]),
8LL * (((unsigned int)v20 + (_DWORD)v33 - (((_DWORD)v14 + 50) & 0xFFFFFFF8)) >> 3));
}
else if ( (v20 & 4) != 0 )
{
*(_DWORD *)(v14 + 42) = *(_DWORD *)&v18->sa_data[10];
*(_DWORD *)&v33[v20 - 4] = *(_DWORD *)&v34[v20 - 4];
}
else
{
*(_BYTE *)(v14 + 42) = v18->sa_data[10];
if ( (v20 & 2) != 0 )
*(_WORD *)&v33[v20 - 2] = *(_WORD *)&v34[v20 - 2];
}
}
}
else
{
v37 = v17;
v35 = if_nametoindex(v15);
v19 = v37;
*(_DWORD *)(v14 + 32) = v35;
v16 = *(_DWORD *)(v14 + 36);
}
goto LABEL_32;
}
LABEL_60:
v19 = 0;
if ( !(ifac | a1) )
goto LABEL_61;
LABEL_32:
if ( (v16 & 0x10) != 0 )
goto LABEL_37;
v21 = *(_WORD *)(v14 + 40);
if ( v21 == 1 )
goto LABEL_37;
if ( !(ifac | a1) )
{
LABEL_61:
func2((void *)v14);
goto LABEL_5;
}
if ( ((v21 - 24) & 0xFFF7) != 0 )
{
syslog(4, "%s: unsupported interface type %.2x, falling back to ethernet", v15, v19);
*(_WORD *)(v14 + 40) = 1;
}
LABEL_37:
if ( (unsigned int)if_init(v14) == -1 )
{
v22 = v8;
v24 = "%s: if_init: %m";
LABEL_70:
syslog(3, v24, v22);
func2((void *)v14);
goto LABEL_5;
}
if ( func5((__int64)v15, 0) <= 575 )
{
v23 = func5((__int64)v15, 576);
v22 = v8;
v24 = "%s: set_mtu: %m";
if ( v23 == -1 )
goto LABEL_70;
}
*(_DWORD *)(v14 + 72) = *(_DWORD *)(v14 + 32) + 200;
if ( (unsigned int)getifssid(v15, v14 + 84, v22) != -1 )
{
*(_DWORD *)(v14 + 72) += 100;
*(_DWORD *)(v14 + 80) = 1;
}
v25 = (__int64 *)v3[1];
v4 = v4->ifa_next;
*(_QWORD *)v14 = 0LL;
*(_QWORD *)(v14 + 8) = v25;
*v25 = v14;
v3[1] = (const char *)v14;
}
while ( v4 );
LABEL_43:
v4 = ifap;
if ( ifap )
{
do
{
while ( 1 )
{
v26 = v4->ifa_addr;
if ( v26 )
{
if ( v26->sa_family == 10 )
{
v27 = &v26->sa_data[6];
v28 = in6_addr_flags(v4->ifa_name, &v26->sa_data[6]);
if ( v28 != -1 )
break;
}
}
v4 = v4->ifa_next;
if ( !v4 )
goto LABEL_50;
}
ipv6_handleifa(20LL, v3, v4->ifa_name, v27, v28);
v4 = v4->ifa_next;
}
while ( v4 );
LABEL_50:
v4 = ifap;
}
LABEL_51:
freeifaddrs(v4);
return v3;
}

original_code:
struct if_head *
discover_interfaces(int argc, char * const *argv)
{
 struct ifaddrs *ifaddrs, *ifa;
 char *p;
 int i, sdl_type;
 struct if_head *ifs;
 struct interface *ifp;
 char ifn[16];
 const struct sockaddr_in6 *sin6;
 int ifa_flags;
 const struct sockaddr_ll *sll;
 if (getifaddrs(&ifaddrs) == -1)
  return ((void *)0);
 ifs = malloc(sizeof(*ifs));
 if (ifs == ((void *)0))
  return ((void *)0);
 do { (ifs)->tqh_first = ((void *)0); (ifs)->tqh_last = &(ifs)->tqh_first; } while ( 0);
 for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
  if (ifa->ifa_addr != ((void *)0)) {
   if (ifa->ifa_addr->sa_family != 17)
    continue;
  }
  for ((ifp) = ((ifs)->tqh_first); (ifp); (ifp) = ((ifp)->next.tqe_next)) {
   if (strcmp(ifp->name, ifa->ifa_name) == 0)
    break;
  }
  if (ifp)
   continue;
  if (argc > 0) {
   for (i = 0; i < argc; i++) {
    strlcpy(ifn, argv[i], sizeof(ifn));
    p = strchr(ifn, ':');
    if (p)
     *p = '\0';
    if (strcmp(ifn, ifa->ifa_name) == 0)
     break;
   }
   if (i == argc)
    continue;
   p = argv[i];
  } else {
   p = ifa->ifa_name;
   if (argc == -1 && strcmp(argv[0], ifa->ifa_name) != 0)
    continue;
  }
  for (i = 0; i < ifdc; i++)
   if (!fnmatch(ifdv[i], p, 0))
    break;
  if (i < ifdc)
   continue;
  for (i = 0; i < ifac; i++)
   if (!fnmatch(ifav[i], p, 0))
    break;
  if (ifac && i == ifac)
   continue;
  ifp = calloc(1, sizeof(*ifp));
  if (ifp == ((void *)0))
   return ((void *)0);
  strlcpy(ifp->name, p, sizeof(ifp->name));
  ifp->flags = ifa->ifa_flags;
  if (!(ifp->flags & IFF_UP)
     )
  {
   if (up_interface(ifp) == 0)
    options |= (1ULL << 26);
   else
    syslog(3, "%s: up_interface: %m",
        ifp->name);
  }
  sdl_type = 0;
  if (ifp->flags & IFF_LOOPBACK) {
   if (argc == 0 && ifac == 0) {
    free_interface(ifp);
    continue;
   }
  } else if (ifa->ifa_addr != ((void *)0)) {
   sll = (const struct sockaddr_ll *)(void *)ifa->ifa_addr;
   ifp->index = sll->sll_ifindex;
   ifp->family = sdl_type = sll->sll_hatype;
   ifp->hwlen = sll->sll_halen;
   if (ifp->hwlen != 0)
    memcpy(ifp->hwaddr, sll->sll_addr, ifp->hwlen);
  }
  else
   ifp->index = if_nametoindex(ifp->name);
  if (!(ifp->flags & IFF_POINTOPOINT) &&
      ifp->family != 1)
  {
   if (argc == 0 && ifac == 0) {
    free_interface(ifp);
    continue;
   }
   switch (ifp->family) {
   case 24:
   case 32:
    break;
   default:
    syslog(4,
        "%s: unsupported interface type %.2x"
        ", falling back to ethernet",
        ifp->name, sdl_type);
    ifp->family = 1;
    break;
   }
  }
  if (if_init(ifp) == -1) {
   syslog(3, "%s: if_init: %m", p);
   free_interface(ifp);
   continue;
  }
  if (do_mtu(ifp->name, 0) < 576 &&
      do_mtu(ifp->name, 576) == -1)
  {
   syslog(3, "%s: set_mtu: %m", p);
   free_interface(ifp);
   continue;
  }
  ifp->metric = 200 + ifp->index;
  if (getifssid(ifp->name, ifp->ssid) != -1) {
   ifp->wireless = 1;
   ifp->metric += 100;
  }
  do { (ifp)->next.tqe_next = ((void *)0); (ifp)->next.tqe_prev = (ifs)->tqh_last; *(ifs)->tqh_last = (ifp); (ifs)->tqh_last = &(ifp)->next.tqe_next; } while ( 0);
 }
 for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
  if (ifa->ifa_addr != ((void *)0) &&
      ifa->ifa_addr->sa_family == 10)
  {
   sin6 = (const struct sockaddr_in6 *)
       (void *)ifa->ifa_addr;
   ifa_flags = in6_addr_flags(ifa->ifa_name,
       &sin6->sin6_addr);
   if (ifa_flags != -1)
    ipv6_handleifa(RTM_NEWADDR, ifs,
        ifa->ifa_name,
        &sin6->sin6_addr, ifa_flags);
  }
 }
 freeifaddrs(ifaddrs);
 return ifs;
}

canonical_original_code:
struct if_head *discover_interfaces(int argc, char **argv)
{
 struct ifaddrs *ifaddrs; struct ifaddrs *ifa;
 char *p;
 int i; int sdl_type;
 struct if_head *ifs;
 struct interface *ifp;
 char ifn[16];
 struct sockaddr_in6 *sin6;
 int ifa_flags;
 struct sockaddr_ll *sll;
 if (getifaddrs(&ifaddrs) == -1)
  return ((void *)0);
 ifs = malloc(sizeof(*ifs));
 if (ifs == ((void *)0))
  return ((void *)0);
 do { (ifs)->tqh_first = ((void *)0); (ifs)->tqh_last = &(ifs)->tqh_first; } while ( 0);
 for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
  if (ifa->ifa_addr != ((void *)0)) {
   if (ifa->ifa_addr->sa_family != 17)
    continue;
  }
  for ((ifp) = ((ifs)->tqh_first); (ifp); (ifp) = ((ifp)->next.tqe_next)) {
   if (strcmp(ifp->name, ifa->ifa_name) == 0)
    break;
  }
  if (ifp)
   continue;
  if (argc > 0) {
   for (i = 0; i < argc; i++) {
    strlcpy(ifn, argv[i], sizeof(ifn));
    p = strchr(ifn, ':');
    if (p)
     *p = '\0';
    if (strcmp(ifn, ifa->ifa_name) == 0)
     break;
   }
   if (i == argc)
    continue;
   p = argv[i];
  } else {
   p = ifa->ifa_name;
   if (argc == -1 && strcmp(argv[0], ifa->ifa_name) != 0)
    continue;
  }
  for (i = 0; i < ifdc; i++)
   if (!fnmatch(ifdv[i], p, 0))
    break;
  if (i < ifdc)
   continue;
  for (i = 0; i < ifac; i++)
   if (!fnmatch(ifav[i], p, 0))
    break;
  if (ifac && i == ifac)
   continue;
  ifp = calloc(1, sizeof(*ifp));
  if (ifp == ((void *)0))
   return ((void *)0);
  strlcpy(ifp->name, p, sizeof(ifp->name));
  ifp->flags = ifa->ifa_flags;
  if (!(ifp->flags & IFF_UP)
     )
  {
   if (up_interface(ifp) == 0)
    options |= (1ULL << 26);
   else
    syslog(3, "%s: up_interface: %m",
        ifp->name);
  }
  sdl_type = 0;
  if (ifp->flags & IFF_LOOPBACK) {
   if (argc == 0 && ifac == 0) {
    free_interface(ifp);
    continue;
   }
  } else if (ifa->ifa_addr != ((void *)0)) {
   sll = (struct sockaddr_ll *)(void *)ifa->ifa_addr;
   ifp->index = sll->sll_ifindex;
   ifp->family = sdl_type = sll->sll_hatype;
   ifp->hwlen = sll->sll_halen;
   if (ifp->hwlen != 0)
    memcpy(ifp->hwaddr, sll->sll_addr, ifp->hwlen);
  }
  else
   ifp->index = if_nametoindex(ifp->name);
  if (!(ifp->flags & IFF_POINTOPOINT) &&
      ifp->family != 1)
  {
   if (argc == 0 && ifac == 0) {
    free_interface(ifp);
    continue;
   }
   switch (ifp->family) {
   case 24:
   case 32:
    break;
   default:
    syslog(4,
        "%s: unsupported interface type %.2x"
        ", falling back to ethernet",
        ifp->name, sdl_type);
    ifp->family = 1;
    break;
   }
  }
  if (if_init(ifp) == -1) {
   syslog(3, "%s: if_init: %m", p);
   free_interface(ifp);
   continue;
  }
  if (do_mtu(ifp->name, 0) < 576 &&
      do_mtu(ifp->name, 576) == -1)
  {
   syslog(3, "%s: set_mtu: %m", p);
   free_interface(ifp);
   continue;
  }
  ifp->metric = 200 + ifp->index;
  if (getifssid(ifp->name, ifp->ssid) != -1) {
   ifp->wireless = 1;
   ifp->metric += 100;
  }
  do { (ifp)->next.tqe_next = ((void *)0); (ifp)->next.tqe_prev = (ifs)->tqh_last; *(ifs)->tqh_last = (ifp); (ifs)->tqh_last = &(ifp)->next.tqe_next; } while ( 0);
 }
 for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
  if (ifa->ifa_addr != ((void *)0) &&
      ifa->ifa_addr->sa_family == 10)
  {
   sin6 = (struct sockaddr_in6 *)
       (void *)ifa->ifa_addr;
   ifa_flags = in6_addr_flags(ifa->ifa_name,
       &sin6->sin6_addr);
   if (ifa_flags != -1)
    ipv6_handleifa(RTM_NEWADDR, ifs,
        ifa->ifa_name,
        &sin6->sin6_addr, ifa_flags);
  }
 }
 freeifaddrs(ifaddrs);
 return ifs;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

variable_types: i int

variable_types: struct if_head { struct interface { struct { struct interface *tqe_next; struct interface **tqe_prev; } next; char name[16]; unsigned int index; int flags; unsigned short family; unsigned char hwaddr[20]; unsigned long hwlen; int metric; int carrier; int wireless; char ssid[33]; char profile[64]; struct if_options { int metric; unsigned char requestmask[-1]; unsigned char requiremask[-1]; unsigned char nomask[-1]; unsigned char requestmask6[-1]; unsigned char requiremask6[-1]; unsigned char nomask6[-1]; unsigned char dstmask[-1]; unsigned int leasetime; long timeout; long reboot; unsigned long long options; struct in_addr { unsigned int s_addr; } req_addr; struct in_addr req_mask; struct rt_head { struct rt { struct { struct rt *tqe_next; struct rt **tqe_prev; } next; struct in_addr dest; struct in_addr net; struct in_addr gate; struct interface *iface; int metric; struct in_addr src; } *tqh_first; struct rt **tqh_last; } *routes; char **config; char **environ; char script[4096]; char hostname[-1]; int fqdn; unsigned char vendorclassid[-1]; char clientid[-1]; unsigned char userclass[-1]; unsigned char vendor[-1]; unsigned long blacklist_len; unsigned int *blacklist; unsigned long whitelist_len; unsigned int *whitelist; unsigned long arping_len; unsigned int *arping; char *fallback; unsigned short ia_type; unsigned long iaid_len; struct if_iaid { unsigned char iaid[4]; unsigned long sla_len; struct if_sla { char ifname[16]; unsigned int sla; short prefix_len; char sla_set; } *sla; } *iaid; int dadtransmits; } *options; void *if_data[4]; } *tqh_first; struct interface **tqh_last; } *

variable_types:
ifn
char [16]

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } *

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; } *

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }

user_defined_types: struct if_head { struct interface *tqh_first; struct interface **tqh_last; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }


decompiled_code:
__int64 __fastcall set_cloexec(int fd)
{
int v1; // eax

v1 = fcntl(fd, 1, 0LL);
if ( v1 != -1 && fcntl(fd, 2, v1 | 1u) != -1 )
return 0LL;
syslog(3, "fcntl: %m");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd)
{
int v1; // eax

v1 = fcntl(fd, 1, 0LL);
if ( v1 != -1 && fcntl(fd, 2, v1 | 1u) != -1 )
return 0LL;
syslog(3, "fcntl: %m");
return 0xFFFFFFFFLL;
}

original_code:
int
set_cloexec(int fd)
{
 int flags;
 if ((flags = fcntl(fd, 1, 0)) == -1 ||
     fcntl(fd, 2, flags | 1) == -1)
 {
  syslog(3, "fcntl: %m");
  return -1;
 }
 return 0;
}

variable_types: fd int

variable_types: flags int


decompiled_code:
__int64 __fastcall set_nonblock(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3, 0LL);
if ( v1 != -1 )
{
BYTE1(v1) |= 8u;
if ( fcntl(fd, 4, v1) != -1 )
return 0LL;
}
syslog(3, "fcntl: %m");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3, 0LL);
if ( v1 != -1 )
{
BYTE1(v1) |= 8u;
if ( fcntl(fd, 4, v1) != -1 )
return 0LL;
}
syslog(3, "fcntl: %m");
return 0xFFFFFFFFLL;
}

original_code:
int
set_nonblock(int fd)
{
 int flags;
 if ((flags = fcntl(fd, 3, 0)) == -1 ||
     fcntl(fd, 4, flags | 04000) == -1)
 {
  syslog(3, "fcntl: %m");
  return -1;
 }
 return 0;
}


decompiled_code:
char *__fastcall get_hostname(int a1)
{
char *v1; // rax

gethostname(hostname_buffer, 0xFBuLL);
byte_5FA = 0;
if ( *(_DWORD *)hostname_buffer == 1852796456 && *(_WORD *)&hostname_buffer[4] == 10597 && !hostname_buffer[6]
|| *(_QWORD *)hostname_buffer == 0x736F686C61636F6CLL && word_508 == 116
|| *(_QWORD *)hostname_buffer == 0x736F686C61636F6CLL && word_508 == 11892
|| hostname_buffer[0] == 46 )
{
return 0LL;
}
if ( a1 )
{
v1 = strchr(hostname_buffer, 46);
if ( v1 )
*v1 = 0;
}
return hostname_buffer;
}

canonical_decompiled_code:
char *__fastcall func3(int a1)
{
char *v1; // rax

gethostname(hostname_buffer, 0xFBuLL);
byte_5FA = 0;
if ( *(_DWORD *)hostname_buffer == 1852796456 && *(_WORD *)&hostname_buffer[4] == 10597 && !hostname_buffer[6]
|| *(_QWORD *)hostname_buffer == 0x736F686C61636F6CLL && word_508 == 116
|| *(_QWORD *)hostname_buffer == 0x736F686C61636F6CLL && word_508 == 11892
|| hostname_buffer[0] == 46 )
{
return 0LL;
}
if ( a1 )
{
v1 = strchr(hostname_buffer, 46);
if ( v1 )
*v1 = 0;
}
return hostname_buffer;
}

original_code:
const char *
get_hostname(int short_hostname)
{
 char *p;
 gethostname(hostname_buffer, sizeof(hostname_buffer));
 hostname_buffer[sizeof(hostname_buffer) - 1] = '\0';
 if (strcmp(hostname_buffer, "(none)") == 0 ||
     strcmp(hostname_buffer, "localhost") == 0 ||
     strncmp(hostname_buffer, "localhost.", strlen("localhost.")) == 0 ||
     hostname_buffer[0] == '.')
  return ((void *)0);
 if (short_hostname) {
  p = strchr(hostname_buffer, '.');
  if (p)
   *p = '\0';
 }
 return hostname_buffer;
}

canonical_original_code:
char *get_hostname(int short_hostname)
{
 char *p;
 gethostname(hostname_buffer, sizeof(hostname_buffer));
 hostname_buffer[sizeof(hostname_buffer) - 1] = '\0';
 if (strcmp(hostname_buffer, "(none)") == 0 ||
     strcmp(hostname_buffer, "localhost") == 0 ||
     strncmp(hostname_buffer, "localhost.", strlen("localhost.")) == 0 ||
     hostname_buffer[0] == '.')
  return ((void *)0);
 if (short_hostname) {
  p = strchr(hostname_buffer, '.');
  if (p)
   *p = '\0';
 }
 return hostname_buffer;
}

variable_types:
p
char *


decompiled_code:
__int64 __fastcall get_monotonic(struct timeval *tv)
{
clockid_t v2; // edi
__int64 result; // rax
__int64 v4; // rcx
__int64 v5; // r8
unsigned int v6; // eax
__int64 v7; // rdx
__syscall_slong_t v8; // rcx
struct timespec v9; // [rsp+0h] [rbp-28h] BYREF

if ( posix_clock_set_2 )
{
v2 = posix_clock_1;
if ( !clock_monotonic )
return (unsigned int)gettimeofday(tv, 0LL);
}
else if ( clock_gettime(1, &v9) )
{
v7 = (unsigned int)clock_monotonic;
v2 = posix_clock_1;
if ( !clock_monotonic )
goto LABEL_8;
}
else
{
posix_clock_1 = 1;
v2 = 1;
posix_clock_set_2 = 1;
clock_monotonic = 1;
}
v6 = clock_gettime(v2, &v9);
v5 = v6;
if ( v6 )
{
v4 = (unsigned int)posix_clock_set_2;
if ( posix_clock_set_2 )
return (unsigned int)gettimeofday(tv, 0LL);
LABEL_8:
syslog(4, "host does not support a monotonic clock - timing can skew", v7, v4, v5);
posix_clock_set_2 = 1;
return (unsigned int)gettimeofday(tv, 0LL);
}
v8 = v9.tv_nsec;
tv->tv_sec = v9.tv_sec;
result = 0LL;
tv->tv_usec = v8 / 1000;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(struct timeval *tv)
{
clockid_t v2; // edi
__int64 result; // rax
__int64 v4; // rcx
__int64 v5; // r8
unsigned int v6; // eax
__int64 v7; // rdx
__syscall_slong_t v8; // rcx
struct timespec v9; // [rsp+0h] [rbp-28h] BYREF

if ( posix_clock_set_2 )
{
v2 = posix_clock_1;
if ( !clock_monotonic )
return (unsigned int)gettimeofday(tv, 0LL);
}
else if ( clock_gettime(1, &v9) )
{
v7 = (unsigned int)clock_monotonic;
v2 = posix_clock_1;
if ( !clock_monotonic )
goto LABEL_8;
}
else
{
posix_clock_1 = 1;
v2 = 1;
posix_clock_set_2 = 1;
clock_monotonic = 1;
}
v6 = clock_gettime(v2, &v9);
v5 = v6;
if ( v6 )
{
v4 = (unsigned int)posix_clock_set_2;
if ( posix_clock_set_2 )
return (unsigned int)gettimeofday(tv, 0LL);
LABEL_8:
syslog(4, "host does not support a monotonic clock - timing can skew", v7, v4, v5);
posix_clock_set_2 = 1;
return (unsigned int)gettimeofday(tv, 0LL);
}
v8 = v9.tv_nsec;
tv->tv_sec = v9.tv_sec;
result = 0LL;
tv->tv_usec = v8 / 1000;
return result;
}

original_code:
int
get_monotonic(struct timeval *tp)
{
 static int posix_clock_set = 0;
 struct timespec ts;
 static clockid_t posix_clock;
 if (!posix_clock_set) {
  if (clock_gettime(1, &ts) == 0) {
   posix_clock = 1;
   clock_monotonic = posix_clock_set = 1;
  }
 }
 if (clock_monotonic) {
  if (clock_gettime(posix_clock, &ts) == 0) {
   tp->tv_sec = ts.tv_sec;
   tp->tv_usec = ts.tv_nsec / 1000;
   return 0;
  }
 }
 if (!posix_clock_set) {
  syslog(4, "host does not support a monotonic clock - timing can skew");
  posix_clock_set = 1;
 }
 return gettimeofday(tp, ((void *)0));
}

canonical_original_code:
int get_monotonic(struct timeval *tp)
{
 static int posix_clock_set = 0;
 struct timespec ts;
 static int posix_clock;
 if (!posix_clock_set) {
  if (clock_gettime(1, &ts) == 0) {
   posix_clock = 1;
   clock_monotonic = posix_clock_set = 1;
  }
 }
 if (clock_monotonic) {
  if (clock_gettime(posix_clock, &ts) == 0) {
   tp->tv_sec = ts.tv_sec;
   tp->tv_usec = ts.tv_nsec / 1000;
   return 0;
  }
 }
 if (!posix_clock_set) {
  syslog(4, "host does not support a monotonic clock - timing can skew");
  posix_clock_set = 1;
 }
 return gettimeofday(tp, ((void *)0));
}

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

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


setvar

decompiled_code:
__int64 __fastcall setvar(char ***a1, const char *a2, const char *a3, const char *a4)
{
size_t v6; // rbx
size_t v7; // rbx
size_t v8; // rax
char **v9; // r15
size_t v10; // rbx
char *v11; // rax
char **v13; // r13
char *v14; // rax

v6 = strlen(a3);
v7 = strlen(a4) + v6;
if ( a2 )
{
v8 = strlen(a2);
v9 = *a1;
v10 = v7 + v8 + 4;
v11 = (char *)malloc(v10);
*v9 = v11;
if ( v11 )
{
snprintf(v11, v10, "%s_%s=%s", a2, a3, a4);
LABEL_4:
++*a1;
return v10;
}
}
else
{
v10 = v7 + 3;
v13 = *a1;
v14 = (char *)malloc(v10);
*v13 = v14;
if ( v14 )
{
snprintf(v14, v10, "%s=%s", a3, a4);
goto LABEL_4;
}
}
syslog(3, "%s: %m", "setvar");
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char ***a1, const char *a2, const char *a3, const char *a4)
{
size_t v6; // rbx
size_t v7; // rbx
size_t v8; // rax
char **v9; // r15
size_t v10; // rbx
char *v11; // rax
char **v13; // r13
char *v14; // rax

v6 = strlen(a3);
v7 = strlen(a4) + v6;
if ( a2 )
{
v8 = strlen(a2);
v9 = *a1;
v10 = v7 + v8 + 4;
v11 = (char *)malloc(v10);
*v9 = v11;
if ( v11 )
{
snprintf(v11, v10, "%s_%s=%s", a2, a3, a4);
LABEL_4:
++*a1;
return v10;
}
}
else
{
v10 = v7 + 3;
v13 = *a1;
v14 = (char *)malloc(v10);
*v13 = v14;
if ( v14 )
{
snprintf(v14, v10, "%s=%s", a3, a4);
goto LABEL_4;
}
}
syslog(3, "%s: %m", "setvar");
return -1LL;
}

original_code:
ssize_t
setvar(char ***e, const char *prefix, const char *var, const char *value)
{
 size_t len = strlen(var) + strlen(value) + 3;
 if (prefix)
  len += strlen(prefix) + 1;
 **e = malloc(len);
 if (**e == ((void *)0)) {
  syslog(3, "%s: %m", __func__);
  return -1;
 }
 if (prefix)
  snprintf(**e, len, "%s_%s=%s", prefix, var, value);
 else
  snprintf(**e, len, "%s=%s", var, value);
 (*e)++;
 return len;
}

canonical_original_code:
long setvar(char ***e, char *prefix, char *var, char *value)
{
 unsigned long len = strlen(var) + strlen(value) + 3;
 if (prefix)
  len += strlen(prefix) + 1;
 **e = malloc(len);
 if (**e == ((void *)0)) {
  syslog(3, "%s: %m", __func__);
  return -1;
 }
 if (prefix)
  snprintf(**e, len, "%s_%s=%s", prefix, var, value);
 else
  snprintf(**e, len, "%s=%s", var, value);
 (*e)++;
 return len;
}

variable_types:
e
char ***

variable_types:
prefix
char *

variable_types:
var
char *

variable_types:
value
char *

variable_types:
len
unsigned long

return_type: long


setvard

decompiled_code:
__int64 __fastcall setvard(char ***a1, const char *a2, const char *a3, __int64 a4)
{
char v6[56]; // [rsp+0h] [rbp-38h] BYREF

snprintf(v6, 0x20uLL, "%d", a4);
return setvar(a1, a2, a3, v6);
}

canonical_decompiled_code:
__int64 __fastcall func6(char ***a1, const char *a2, const char *a3, __int64 a4)
{
char v6[56]; // [rsp+0h] [rbp-38h] BYREF

snprintf(v6, 0x20uLL, "%d", a4);
return func5(a1, a2, a3, v6);
}

original_code:
ssize_t
setvard(char ***e, const char *prefix, const char *var, int value)
{
 char buffer[32];
 snprintf(buffer, sizeof(buffer), "%d", value);
 return setvar(e, prefix, var, buffer);
}

canonical_original_code:
long setvard(char ***e, char *prefix, char *var, int value)
{
 char buffer[32];
 snprintf(buffer, sizeof(buffer), "%d", value);
 return setvar(e, prefix, var, buffer);
}

variable_types: value int

variable_types:
buffer
char [32]


writepid

decompiled_code:
int __fastcall writepid(int fd, unsigned int a2)
{
int result; // eax
size_t v3; // rax
ssize_t v4; // rbp
char v5[40]; // [rsp+0h] [rbp-28h] BYREF

result = ftruncate(fd, 0LL);
if ( result != -1 )
{
snprintf(v5, 0x10uLL, "%u\n", a2);
v3 = strlen(v5);
v4 = pwrite(fd, v5, v3, 0LL);
result = -(v4 != strlen(v5));
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int fd, unsigned int a2)
{
int result; // eax
size_t v3; // rax
ssize_t v4; // rbp
char v5[40]; // [rsp+0h] [rbp-28h] BYREF

result = ftruncate(fd, 0LL);
if ( result != -1 )
{
snprintf(v5, 0x10uLL, "%u\n", a2);
v3 = strlen(v5);
v4 = pwrite(fd, v5, v3, 0LL);
result = -(v4 != strlen(v5));
}
return result;
}

original_code:
int
writepid(int fd, pid_t pid)
{
 char spid[16];
 ssize_t len;
 if (ftruncate(fd, (off_t)0) == -1)
  return -1;
 snprintf(spid, sizeof(spid), "%u\n", pid);
 len = pwrite(fd, spid, strlen(spid), (off_t)0);
 if (len != (ssize_t)strlen(spid))
  return -1;
 return 0;
}

canonical_original_code:
int writepid(int fd, int pid)
{
 char spid[16];
 long len;
 if (ftruncate(fd, (long)0) == -1)
  return -1;
 snprintf(spid, sizeof(spid), "%u\n", pid);
 len = pwrite(fd, spid, strlen(spid), (long)0);
 if (len != (long)strlen(spid))
  return -1;
 return 0;
}

variable_types: pid int

variable_types:
spid
char [16]

variable_types: len long


uptime

decompiled_code:
__time_t uptime()
{
__time_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( (unsigned int)get_monotonic(&v1) == -1 )
result = -1LL;
else
result = v1.tv_sec;
return result;
}

canonical_decompiled_code:
__time_t func7()
{
__time_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( (unsigned int)func4(&v1) == -1 )
result = -1LL;
else
result = v1.tv_sec;
return result;
}

original_code:
time_t
uptime(void)
{
 struct timeval tv;
 if (get_monotonic(&tv) == -1)
  return -1;
 return tv.tv_sec;
}

canonical_original_code:
long uptime()
{
 struct timeval tv;
 if (get_monotonic(&tv) == -1)
  return -1;
 return tv.tv_sec;
}

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


mkArpMsg

original_code:
void mkArpMsg(int opcode, u_long tInaddr, u_char *tHaddr,
   u_long sInaddr, u_char *sHaddr, struct arpMsg *msg) {
 bzero(msg, sizeof(*msg));
 bcopy("\xff\xff\xff\xff\xff\xff", msg->ethhdr.ether_dhost, 6);
 bcopy(sHaddr, msg->ethhdr.ether_shost, 6);
 msg->ethhdr.ether_type = htons(0x0806);
 msg->htype = htons(1);
 msg->ptype = htons(0x0800);
 msg->hlen = 6;
 msg->plen = 4;
 msg->operation = htons(opcode);
 bcopy(&sInaddr, msg->sInaddr,
   sizeof(msg->sInaddr));
 bcopy(sHaddr, msg->sHaddr, 6);
 bcopy(&tInaddr, msg->tInaddr,
   sizeof(msg->tInaddr));
 if ( opcode == 2 ) {
  bcopy(tHaddr, msg->tHaddr, 6);
 }
}

canonical_original_code:
void mkArpMsg(int opcode, unsigned long tInaddr, unsigned char *tHaddr, unsigned long sInaddr, unsigned char *sHaddr, struct arpMsg *msg) {
 bzero(msg, sizeof(*msg));
 bcopy("\xff\xff\xff\xff\xff\xff", msg->ethhdr.ether_dhost, 6);
 bcopy(sHaddr, msg->ethhdr.ether_shost, 6);
 msg->ethhdr.ether_type = htons(0x0806);
 msg->htype = htons(1);
 msg->ptype = htons(0x0800);
 msg->hlen = 6;
 msg->plen = 4;
 msg->operation = htons(opcode);
 bcopy(&sInaddr, msg->sInaddr,
   sizeof(msg->sInaddr));
 bcopy(sHaddr, msg->sHaddr, 6);
 bcopy(&tInaddr, msg->tInaddr,
   sizeof(msg->tInaddr));
 if ( opcode == 2 ) {
  bcopy(tHaddr, msg->tHaddr, 6);
 }
}

variable_types: opcode int

variable_types:
tInaddr
unsigned long

variable_types:
tHaddr
unsigned char *

variable_types:
sInaddr
unsigned long

variable_types:
sHaddr
unsigned char *

variable_types: struct arpMsg { struct ether_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; } ethhdr; unsigned short htype; unsigned short ptype; unsigned char hlen; unsigned char plen; unsigned short operation; unsigned char sHaddr[6]; unsigned char sInaddr[4]; unsigned char tHaddr[6]; unsigned char tInaddr[4]; unsigned char pad[18]; } *

user_defined_types: struct arpMsg { struct ether_header ethhdr; unsigned short htype; unsigned short ptype; unsigned char hlen; unsigned char plen; unsigned short operation; unsigned char sHaddr[6]; unsigned char sInaddr[4]; unsigned char tHaddr[6]; unsigned char tInaddr[4]; unsigned char pad[18]; }


openRawSocket

decompiled_code:
int __fastcall openRawSocket(int *a1, __int16 a2)
{
unsigned __int16 v2; // ax
int v3; // eax
int result; // eax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
v2 = _bswap_16(a2);
v3 = socket(2, 10, v2);
*a1 = v3;
if ( v3 == -1 || (result = setsockopt(v3, 1, 6, optval, 4u), result == -1) )
result = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func2(int *a1, __int16 a2)
{
unsigned __int16 v2; // ax
int v3; // eax
int result; // eax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
v2 = func0(a2);
v3 = socket(2, 10, v2);
*a1 = v3;
if ( v3 == -1 || (result = setsockopt(v3, 1, 6, optval, 4u), result == -1) )
result = -1;
return result;
}

original_code:
int openRawSocket (int *s, u_short type) {
 int optval = 1;
 if((*s = socket (2, SOCK_PACKET, htons (type))) == -1) {
  return -1;
 }
 if(setsockopt (*s, 1, 6, &optval, sizeof (optval)) == -1) {
  return -1;
    }
}

canonical_original_code:
int openRawSocket(int *s, unsigned short type) {
 int optval = 1;
 if((*s = socket (2, SOCK_PACKET, htons (type))) == -1) {
  return -1;
 }
 if(setsockopt (*s, 1, 6, &optval, sizeof (optval)) == -1) {
  return -1;
    }
}

variable_types:
s
int *

variable_types:
type
unsigned short

variable_types: optval int


arpCheck

decompiled_code:
_BOOL8 __fastcall arpCheck(int a1, __int64 a2, __time_t a3)
{
ssize_t v4; // rax
_BOOL4 v5; // er12
int v6; // edi
int fd; // [rsp+14h] [rbp-124h] BYREF
time_t timer; // [rsp+18h] [rbp-120h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-118h] BYREF
struct timeval timeout; // [rsp+30h] [rbp-108h] BYREF
char buf[20]; // [rsp+40h] [rbp-F8h] BYREF
__int16 v14; // [rsp+54h] [rbp-E4h]
int v15; // [rsp+5Ch] [rbp-DCh]
int v16; // [rsp+60h] [rbp-D8h]
__int16 v17; // [rsp+64h] [rbp-D4h]
fd_set readfds; // [rsp+80h] [rbp-B8h] BYREF

openRawSocket(&fd, 2054);
mkArpMsg(1, a1, 0LL, *(_QWORD *)(a2 + 16), (const void *)(a2 + 40), (__int64)buf);
addr = 0LL;
strcpy(addr.sa_data, (const char *)a2);
v4 = sendto(fd, buf, 0x3CuLL, 0, &addr, 0x10u);
timeout.tv_usec = 0LL;
v5 = v4 >= 0;
time(&timer);
if ( a3 > 0 )
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
v6 = fd;
timeout.tv_sec = a3;
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
if ( select(v6 + 1, &readfds, 0LL, 0LL, &timeout) < 0 )
v5 = 0;
if ( (readfds.fds_bits[fd / 64] & (1LL << (fd % 64))) != 0 )
{
if ( recv(fd, buf, 0x3CuLL, 0) < 0 )
v5 = 0;
if ( v14 == _bswap_16(2) && v16 == *(_DWORD *)(a2 + 40) && v17 == *(_WORD *)(a2 + 44) && a1 == v15 )
break;
}
a3 -= (int)time(0LL) - timer;
time(&timer);
if ( a3 <= 0 )
goto LABEL_14;
}
v5 = 0;
}
LABEL_14:
close(fd);
return v5;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1, __int64 a2, __time_t a3)
{
ssize_t v4; // rax
_BOOL4 v5; // er12
int v6; // edi
int fd; // [rsp+14h] [rbp-124h] BYREF
time_t timer; // [rsp+18h] [rbp-120h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-118h] BYREF
struct timeval timeout; // [rsp+30h] [rbp-108h] BYREF
char buf[20]; // [rsp+40h] [rbp-F8h] BYREF
__int16 v14; // [rsp+54h] [rbp-E4h]
int v15; // [rsp+5Ch] [rbp-DCh]
int v16; // [rsp+60h] [rbp-D8h]
__int16 v17; // [rsp+64h] [rbp-D4h]
fd_set readfds; // [rsp+80h] [rbp-B8h] BYREF

func2(&fd, 2054);
func1(1, a1, 0LL, *(_QWORD *)(a2 + 16), (const void *)(a2 + 40), (__int64)buf);
addr = 0LL;
strcpy(addr.sa_data, (const char *)a2);
v4 = sendto(fd, buf, 0x3CuLL, 0, &addr, 0x10u);
timeout.tv_usec = 0LL;
v5 = v4 >= 0;
time(&timer);
if ( a3 > 0 )
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
v6 = fd;
timeout.tv_sec = a3;
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
if ( select(v6 + 1, &readfds, 0LL, 0LL, &timeout) < 0 )
v5 = 0;
if ( (readfds.fds_bits[fd / 64] & (1LL << (fd % 64))) != 0 )
{
if ( recv(fd, buf, 0x3CuLL, 0) < 0 )
v5 = 0;
if ( v14 == func0(2) && v16 == *(_DWORD *)(a2 + 40) && v17 == *(_WORD *)(a2 + 44) && a1 == v15 )
break;
}
a3 -= (int)time(0LL) - timer;
time(&timer);
if ( a3 <= 0 )
goto LABEL_14;
}
v5 = 0;
}
LABEL_14:
close(fd);
return v5;
}

original_code:
int arpCheck(u_long inaddr, struct ifinfo *ifbuf, long timeout) {
 int s;
 int rv;
 struct sockaddr addr;
 struct arpMsg arp;
 fd_set fdset;
 struct timeval tm;
 time_t prevTime;
 rv = 1;
 openRawSocket(&s, 0x0806);
 mkArpMsg(1, inaddr, ((void *)0), ifbuf->addr, ifbuf->haddr, &arp);
 bzero(&addr, sizeof(addr));
 strcpy(addr.sa_data, ifbuf->ifname);
 if ( sendto(s, &arp, sizeof(arp), 0, &addr, sizeof(addr)) < 0 ) {
  rv = 0;
 }
 tm.tv_usec = 0;
 time(&prevTime);
 while ( timeout > 0 ) {
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdset)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&fdset)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
  tm.tv_sec = timeout;
  if ( select(s+1, &fdset, (fd_set *)((void *)0), (fd_set *)((void *)0), &tm) < 0 ) {
   rv = 0;
  }
  if ( ((((&fdset)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0) ) {
   if (recv(s, &arp, sizeof(arp), 0) < 0 ) {
    rv = 0;
   }
   if (arp.operation == htons(2) &&
     bcmp(arp.tHaddr, ifbuf->haddr, 6) == 0 &&
     bcmp(arp.sInaddr, &inaddr, sizeof(arp.sInaddr)) == 0) {
    rv = 0;
    break;
   }
  }
  timeout -= time(((void *)0)) - prevTime;
  time(&prevTime);
 }
 close(s);
 return rv;
}

canonical_original_code:
int arpCheck(unsigned long inaddr, struct ifinfo *ifbuf, long timeout) {
 int s;
 int rv;
 struct sockaddr addr;
 struct arpMsg arp;
 struct fd_set fdset;
 struct timeval tm;
 long prevTime;
 rv = 1;
 openRawSocket(&s, 0x0806);
 mkArpMsg(1, inaddr, ((void *)0), ifbuf->addr, ifbuf->haddr, &arp);
 bzero(&addr, sizeof(addr));
 strcpy(addr.sa_data, ifbuf->ifname);
 if ( sendto(s, &arp, sizeof(arp), 0, &addr, sizeof(addr)) < 0 ) {
  rv = 0;
 }
 tm.tv_usec = 0;
 time(&prevTime);
 while ( timeout > 0 ) {
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdset)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&fdset)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
  tm.tv_sec = timeout;
  if ( select(s+1, &fdset, (struct fd_set *)((void *)0), (struct fd_set *)((void *)0), &tm) < 0 ) {
   rv = 0;
  }
  if ( ((((&fdset)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0) ) {
   if (recv(s, &arp, sizeof(arp), 0) < 0 ) {
    rv = 0;
   }
   if (arp.operation == htons(2) &&
     bcmp(arp.tHaddr, ifbuf->haddr, 6) == 0 &&
     bcmp(arp.sInaddr, &inaddr, sizeof(arp.sInaddr)) == 0) {
    rv = 0;
    break;
   }
  }
  timeout -= time(((void *)0)) - prevTime;
  time(&prevTime);
 }
 close(s);
 return rv;
}

variable_types:
inaddr
unsigned long

variable_types: struct ifinfo { char ifname[16]; unsigned long addr; unsigned long mask; unsigned long bcast; unsigned char haddr[6]; short flags; } *

variable_types: timeout long

variable_types: s int

variable_types: rv int

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

variable_types: struct arpMsg { struct ether_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; } ethhdr; unsigned short htype; unsigned short ptype; unsigned char hlen; unsigned char plen; unsigned short operation; unsigned char sHaddr[6]; unsigned char sInaddr[4]; unsigned char tHaddr[6]; unsigned char tInaddr[4]; unsigned char pad[18]; }

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

variable_types: prevTime long

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


arpping

decompiled_code:
_BOOL8 __fastcall arpping(int a1)
{
__int16 v1; // ax
char v3[16]; // [rsp+0h] [rbp-38h] BYREF
__int64 v4; // [rsp+10h] [rbp-28h]
__int64 v5; // [rsp+18h] [rbp-20h]
__int64 v6; // [rsp+20h] [rbp-18h]
int v7; // [rsp+28h] [rbp-10h]
__int16 v8; // [rsp+2Ch] [rbp-Ch]
__int16 v9; // [rsp+2Eh] [rbp-Ah]

strcpy(v3, interface_name);
v4 = 3407386538LL;
v5 = 0LL;
v7 = interface_hwaddr;
v1 = *((_WORD *)&interface_hwaddr + 2);
v6 = 0LL;
v8 = v1;
v9 = 0;
return arpCheck(a1, (__int64)v3, 3LL);
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1)
{
__int16 v1; // ax
char v3[16]; // [rsp+0h] [rbp-38h] BYREF
__int64 v4; // [rsp+10h] [rbp-28h]
__int64 v5; // [rsp+18h] [rbp-20h]
__int64 v6; // [rsp+20h] [rbp-18h]
int v7; // [rsp+28h] [rbp-10h]
__int16 v8; // [rsp+2Ch] [rbp-Ch]
__int16 v9; // [rsp+2Eh] [rbp-Ah]

strcpy(v3, interface_name);
v4 = 3407386538LL;
v5 = 0LL;
v7 = interface_hwaddr;
v1 = *((_WORD *)&interface_hwaddr + 2);
v6 = 0LL;
v8 = v1;
v9 = 0;
return func3(a1, (__int64)v3, 3LL);
}

original_code:
int arpping(u_int32_t yiaddr)
{
 int rv;
 struct ifinfo ifbuf;
 int n;
 static int nr = 0;
 unsigned char *ep;
 strcpy(ifbuf.ifname, interface_name);
 ifbuf.addr = 0xcb1897aa;
 ifbuf.mask = 0x0;
 ifbuf.bcast = 0x0;
 ep = &interface_hwaddr[0];
 for(n = 0; n < 6; n++)
  ifbuf.haddr[n] = ep[n];
 ifbuf.flags = 0;
 rv = arpCheck(yiaddr, &ifbuf, 3);
 return rv;
}

canonical_original_code:
int arpping(unsigned int yiaddr)
{
 int rv;
 struct ifinfo ifbuf;
 int n;
 static int nr = 0;
 unsigned char *ep;
 strcpy(ifbuf.ifname, interface_name);
 ifbuf.addr = 0xcb1897aa;
 ifbuf.mask = 0x0;
 ifbuf.bcast = 0x0;
 ep = &interface_hwaddr[0];
 for(n = 0; n < 6; n++)
  ifbuf.haddr[n] = ep[n];
 ifbuf.flags = 0;
 rv = arpCheck(yiaddr, &ifbuf, 3);
 return rv;
}

variable_types:
yiaddr
unsigned int

variable_types: struct ifinfo { char ifname[16]; unsigned long addr; unsigned long mask; unsigned long bcast; unsigned char haddr[6]; short flags; }

variable_types: n int

variable_types: nr int

variable_types:
ep
unsigned char *


original_code:
static size_t
make_duid(unsigned char *duid, const struct interface *ifp, uint16_t type)
{
 unsigned char *p;
 uint16_t u16;
 time_t t;
 uint32_t u32;
 p = duid;
 u16 = htons(type);
 memcpy(p, &u16, 2);
 p += 2;
 u16 = htons(ifp->family);
 memcpy(p, &u16, 2);
 p += 2;
 if (type == 1) {
  t = time(((void *)0)) - 946684800;
  u32 = htonl(t & 0xffffffff);
  memcpy(p, &u32, 4);
  p += 4;
 }
 memcpy(p, ifp->hwaddr, ifp->hwlen);
 p += ifp->hwlen;
 return p - duid;
}

canonical_original_code:
static unsigned long make_duid(unsigned char *duid, struct interface *ifp, unsigned short type)
{
 unsigned char *p;
 unsigned short u16;
 long t;
 unsigned int u32;
 p = duid;
 u16 = htons(type);
 memcpy(p, &u16, 2);
 p += 2;
 u16 = htons(ifp->family);
 memcpy(p, &u16, 2);
 p += 2;
 if (type == 1) {
  t = time(((void *)0)) - 946684800;
  u32 = htonl(t & 0xffffffff);
  memcpy(p, &u32, 4);
  p += 4;
 }
 memcpy(p, ifp->hwaddr, ifp->hwlen);
 p += ifp->hwlen;
 return p - duid;
}

variable_types:
duid
unsigned char *

variable_types: struct interface { struct { struct interface *tqe_next; struct interface **tqe_prev; } next; char name[16]; unsigned int index; int flags; unsigned short family; unsigned char hwaddr[20]; unsigned long hwlen; int metric; int carrier; int wireless; char ssid[33]; char profile[64]; struct if_options { int metric; unsigned char requestmask[-1]; unsigned char requiremask[-1]; unsigned char nomask[-1]; unsigned char requestmask6[-1]; unsigned char requiremask6[-1]; unsigned char nomask6[-1]; unsigned char dstmask[-1]; unsigned int leasetime; long timeout; long reboot; unsigned long long options; struct in_addr { unsigned int s_addr; } req_addr; struct in_addr req_mask; struct rt_head { struct rt { struct { struct rt *tqe_next; struct rt **tqe_prev; } next; struct in_addr dest; struct in_addr net; struct in_addr gate; struct interface *iface; int metric; struct in_addr src; } *tqh_first; struct rt **tqh_last; } *routes; char **config; char **environ; char script[4096]; char hostname[-1]; int fqdn; unsigned char vendorclassid[-1]; char clientid[-1]; unsigned char userclass[-1]; unsigned char vendor[-1]; unsigned long blacklist_len; unsigned int *blacklist; unsigned long whitelist_len; unsigned int *whitelist; unsigned long arping_len; unsigned int *arping; char *fallback; unsigned short ia_type; unsigned long iaid_len; struct if_iaid { unsigned char iaid[4]; unsigned long sla_len; struct if_sla { char ifname[16]; unsigned int sla; short prefix_len; char sla_set; } *sla; } *iaid; int dadtransmits; } *options; void *if_data[4]; } *

variable_types:
p
unsigned char *

variable_types: t long


decompiled_code:
void restore_kernel_ra(void)
{
__int64 i; // rax
char v1[264]; // [rsp-108h] [rbp-108h] BYREF

if ( (options[4] & 0x10) == 0 )
{
for ( i = --nrestore; nrestore >= 0; --nrestore )
{
syslog(6, "%s: restoring Kernel IPv6 RA support", *((const char **)restore + i));
snprintf(v1, 0x100uLL, "%s/%s/accept_ra", "/proc/sys/net/ipv6/conf", *((const char **)restore + nrestore));
if ( write_path(v1, "1") == -1 && *_errno_location() != 2 )
syslog(3, "write_path: %s: %m", v1);
i = nrestore - 1;
}
}
}

canonical_decompiled_code:
void func1(void)
{
__int64 i; // rax
char v1[264]; // [rsp-108h] [rbp-108h] BYREF

if ( (options[4] & 0x10) == 0 )
{
for ( i = --nrestore; nrestore >= 0; --nrestore )
{
syslog(6, "%s: restoring Kernel IPv6 RA support", *((const char **)restore + i));
snprintf(v1, 0x100uLL, "%s/%s/accept_ra", "/proc/sys/net/ipv6/conf", *((const char **)restore + nrestore));
if ( func0(v1, "1") == -1 && *_errno_location() != 2 )
syslog(3, "write_path: %s: %m", v1);
i = nrestore - 1;
}
}
}

original_code:
static void
restore_kernel_ra(void)
{
 char path[256];
 if (options & (1ULL << 36))
  return;
 for (nrestore--; nrestore >= 0; nrestore--) {
  syslog(6, "%s: restoring Kernel IPv6 RA support",
         restore[nrestore]);
  snprintf(path, sizeof(path), "%s/%s/accept_ra",
    prefix, restore[nrestore]);
  if (write_path(path, "1") == -1 && (*__errno_location ()) != 2)
   syslog(3, "write_path: %s: %m", path);
 }
}

canonical_original_code:
static void restore_kernel_ra()
{
 char path[256];
 if (options & (1ULL << 36))
  return;
 for (nrestore--; nrestore >= 0; nrestore--) {
  syslog(6, "%s: restoring Kernel IPv6 RA support",
         restore[nrestore]);
  snprintf(path, sizeof(path), "%s/%s/accept_ra",
    prefix, restore[nrestore]);
  if (write_path(path, "1") == -1 && (*__errno_location ()) != 2)
   syslog(3, "write_path: %s: %m", path);
 }
}

variable_types:
path
char [256]


decompiled_code:
__int64 __fastcall check_ipv6(char *s, int a2)
{
char *v2; // r12
int v3; // ebp
int v4; // eax
unsigned int v5; // er13
int *v7; // rax
int v8; // eax
__int64 v9; // r14
const char **v10; // r15
__int64 v11; // rbx
int *v12; // rax
char *v13; // r14
__int64 v14; // rbx
void *v15; // rax
char v16[312]; // [rsp+0h] [rbp-138h] BYREF

if ( s )
{
v2 = s;
v3 = 0;
}
else
{
v5 = 1;
if ( ipv6_checked_1 )
return v5;
ipv6_checked_1 = 1;
v3 = 1;
v2 = "all";
}
snprintf(v16, 0x100uLL, "%s/%s/accept_ra", "/proc/sys/net/ipv6/conf", v2);
v4 = check_proc_int(v16);
v5 = v4;
if ( v4 != -1 )
{
if ( v4 && a2 )
{
syslog(6, "%s: disabling Kernel IPv6 RA support", v2);
if ( write_path(v16, "0") == -1 )
{
syslog(3, "write_path: %s: %m", v16);
return v5;
}
v9 = nrestore;
v10 = (const char **)restore;
v11 = 1LL;
if ( nrestore > 0 )
{
while ( strcmp(v10[v11 - 1], v2) )
{
if ( v9 == v11 )
goto LABEL_23;
++v11;
}
}
else
{
v11 = 0LL;
LABEL_23:
if ( v11 == v9 )
{
v13 = strdup(v2);
if ( !v13 || (v14 = v11 + 1, (v15 = realloc(restore, 8 * v14)) == 0LL) )
{
syslog(3, "%s: %m", "check_ipv6");
goto LABEL_6;
}
restore = v15;
nrestore = v14;
*((_QWORD *)v15 + v14 - 1) = v13;
}
}
if ( v3 )
atexit(restore_kernel_ra);
}
LABEL_6:
if ( v5 == 2 )
return v5;
goto LABEL_9;
}
v7 = _errno_location();
syslog(3 * (*v7 == 2) + 4, "%s: %m", v16);
LABEL_9:
snprintf(v16, 0x100uLL, "%s/%s/forwarding", "/proc/sys/net/ipv6/conf", v2);
v8 = check_proc_int(v16);
if ( v8 == -1 )
{
v12 = _errno_location();
syslog(3 * (*v12 == 2) + 4, "%s: %m", v16);
}
else if ( v8 )
{
syslog(4, "%s: configured as a router, not a host", v2);
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s, int a2)
{
char *v2; // r12
int v3; // ebp
int v4; // eax
unsigned int v5; // er13
int *v7; // rax
int v8; // eax
__int64 v9; // r14
const char **v10; // r15
__int64 v11; // rbx
int *v12; // rax
char *v13; // r14
__int64 v14; // rbx
void *v15; // rax
char v16[312]; // [rsp+0h] [rbp-138h] BYREF

if ( s )
{
v2 = s;
v3 = 0;
}
else
{
v5 = 1;
if ( ipv6_checked_1 )
return v5;
ipv6_checked_1 = 1;
v3 = 1;
v2 = "all";
}
snprintf(v16, 0x100uLL, "%s/%s/accept_ra", "/proc/sys/net/ipv6/conf", v2);
v4 = func2(v16);
v5 = v4;
if ( v4 != -1 )
{
if ( v4 && a2 )
{
syslog(6, "%s: disabling Kernel IPv6 RA support", v2);
if ( func0(v16, "0") == -1 )
{
syslog(3, "write_path: %s: %m", v16);
return v5;
}
v9 = nrestore;
v10 = (const char **)restore;
v11 = 1LL;
if ( nrestore > 0 )
{
while ( strcmp(v10[v11 - 1], v2) )
{
if ( v9 == v11 )
goto LABEL_23;
++v11;
}
}
else
{
v11 = 0LL;
LABEL_23:
if ( v11 == v9 )
{
v13 = strdup(v2);
if ( !v13 || (v14 = v11 + 1, (v15 = realloc(restore, 8 * v14)) == 0LL) )
{
syslog(3, "%s: %m", "check_ipv6");
goto LABEL_6;
}
restore = v15;
nrestore = v14;
*((_QWORD *)v15 + v14 - 1) = v13;
}
}
if ( v3 )
atexit(restore_kernel_ra);
}
LABEL_6:
if ( v5 == 2 )
return v5;
goto LABEL_9;
}
v7 = _errno_location();
syslog(3 * (*v7 == 2) + 4, "%s: %m", v16);
LABEL_9:
snprintf(v16, 0x100uLL, "%s/%s/forwarding", "/proc/sys/net/ipv6/conf", v2);
v8 = func2(v16);
if ( v8 == -1 )
{
v12 = _errno_location();
syslog(3 * (*v12 == 2) + 4, "%s: %m", v16);
}
else if ( v8 )
{
syslog(4, "%s: configured as a router, not a host", v2);
v5 = 0;
}
return v5;
}

original_code:
int
check_ipv6(const char *ifname, int own)
{
 static int ipv6_checked = 0;
 int ra, forward, ex, i;
 char path[256], *p, **nrest;
 if (ifname == ((void *)0)) {
  if (ipv6_checked)
   return 1;
  ipv6_checked = 1;
  ifname = "all";
  ex = 1;
 } else
  ex = 0;
 snprintf(path, sizeof(path), "%s/%s/accept_ra", prefix, ifname);
 ra = check_proc_int(path);
 if (ra == -1)
  syslog((*__errno_location ()) == 2 ? 7 : 4,
      "%s: %m", path);
 else if (ra != 0 && own) {
  syslog(6, "%s: disabling Kernel IPv6 RA support",
      ifname);
  if (write_path(path, "0") == -1) {
   syslog(3, "write_path: %s: %m", path);
   return ra;
  }
  for (i = 0; i < nrestore; i++)
   if (strcmp(restore[i], ifname) == 0)
    break;
  if (i == nrestore) {
   p = strdup(ifname);
   if (p == ((void *)0)) {
    syslog(3, "%s: %m", __func__);
    goto forward;
   }
   nrest = realloc(restore,
       (nrestore + 1) * sizeof(char *));
   if (nrest == ((void *)0)) {
    syslog(3, "%s: %m", __func__);
    goto forward;
   }
   restore = nrest;
   restore[nrestore++] = p;
  }
  if (ex)
   atexit(restore_kernel_ra);
 }
forward:
 if (ra != 2) {
  snprintf(path, sizeof(path), "%s/%s/forwarding",
      prefix, ifname);
  forward = check_proc_int(path);
  if (forward == -1) {
   syslog((*__errno_location ()) == 2 ? 7 : 4,
       "%s: %m", path);
  } else if (forward != 0) {
   syslog(4,
       "%s: configured as a router, not a host", ifname);
   return 0;
  }
 }
 return ra;
}

canonical_original_code:
int check_ipv6(char *ifname, int own)
{
 static int ipv6_checked = 0;
 int ra; int forward; int ex; int i;
 char path[256]; char *p; char **nrest;
 if (ifname == ((void *)0)) {
  if (ipv6_checked)
   return 1;
  ipv6_checked = 1;
  ifname = "all";
  ex = 1;
 } else
  ex = 0;
 snprintf(path, sizeof(path), "%s/%s/accept_ra", prefix, ifname);
 ra = check_proc_int(path);
 if (ra == -1)
  syslog((*__errno_location ()) == 2 ? 7 : 4,
      "%s: %m", path);
 else if (ra != 0 && own) {
  syslog(6, "%s: disabling Kernel IPv6 RA support",
      ifname);
  if (write_path(path, "0") == -1) {
   syslog(3, "write_path: %s: %m", path);
   return ra;
  }
  for (i = 0; i < nrestore; i++)
   if (strcmp(restore[i], ifname) == 0)
    break;
  if (i == nrestore) {
   p = strdup(ifname);
   if (p == ((void *)0)) {
    syslog(3, "%s: %m", __func__);
    goto forward;
   }
   nrest = realloc(restore,
       (nrestore + 1) * sizeof(char *));
   if (nrest == ((void *)0)) {
    syslog(3, "%s: %m", __func__);
    goto forward;
   }
   restore = nrest;
   restore[nrestore++] = p;
  }
  if (ex)
   atexit(restore_kernel_ra);
 }
forward:
 if (ra != 2) {
  snprintf(path, sizeof(path), "%s/%s/forwarding",
      prefix, ifname);
  forward = check_proc_int(path);
  if (forward == -1) {
   syslog((*__errno_location ()) == 2 ? 7 : 4,
       "%s: %m", path);
  } else if (forward != 0) {
   syslog(4,
       "%s: configured as a router, not a host", ifname);
   return 0;
  }
 }
 return ra;
}

variable_types:
ifname
char *

variable_types: own int

variable_types: ra int

variable_types: forward int

variable_types: ex int

variable_types: i int

variable_types:
p
char *

variable_types:
nrest
char **


decompiled_code:
int __fastcall ipv6_dadtransmits(const char *a1)
{
const char *v1; // r8
int result; // eax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = a1;
if ( !a1 )
v1 = "default";
snprintf(v3, 0x100uLL, "%s/%s/dad_transmits", "/proc/sys/net/ipv6/conf", v1);
result = check_proc_int(v3);
if ( result < 0 )
result = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1)
{
const char *v1; // r8
int result; // eax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = a1;
if ( !a1 )
v1 = "default";
snprintf(v3, 0x100uLL, "%s/%s/dad_transmits", "/proc/sys/net/ipv6/conf", v1);
result = func2(v3);
if ( result < 0 )
result = 0;
return result;
}

original_code:
int
ipv6_dadtransmits(const char *ifname)
{
 char path[256];
 int r;
 if (ifname == ((void *)0))
  ifname = "default";
 snprintf(path, sizeof(path), "%s/%s/dad_transmits", prefix, ifname);
 r = check_proc_int(path);
 return r < 0 ? 0 : r;
}

canonical_original_code:
int ipv6_dadtransmits(char *ifname)
{
 char path[256];
 int r;
 if (ifname == ((void *)0))
  ifname = "default";
 snprintf(path, sizeof(path), "%s/%s/dad_transmits", prefix, ifname);
 r = check_proc_int(path);
 return r < 0 ? 0 : r;
}

variable_types: r int


endOption

decompiled_code:
__int64 __fastcall endOption(_BYTE **a1)
{
_BYTE *i; // rax

for ( i = *a1; *i != 0xFF; i += (unsigned __int8)i[1] + 2 )
{
while ( !*i )
;
}
*a1 = i;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE **a1)
{
_BYTE *i; // rax

for ( i = *a1; *i != 0xFF; i += (unsigned __int8)i[1] + 2 )
{
while ( !*i )
;
}
*a1 = i;
return 0LL;
}

original_code:
int endOption(unsigned char **optionptr) {
        unsigned char *tmpptr = *optionptr;
        while(tmpptr[0] != 0xff) {
                if(tmpptr[0] == 0x00)
                        continue;
                tmpptr++;
                tmpptr += tmpptr[0];
                tmpptr++;
        }
        *optionptr = tmpptr;
        return 0;
}

variable_types:
optionptr
unsigned char **

variable_types:
tmpptr
unsigned char *


addOption

original_code:
int addOption(unsigned char *optionptr, unsigned char code,
                                char datalength, char *data) {
        endOption(&optionptr);
        optionptr[0] = code;
        if(code == 0xff)
                return 0;
        optionptr++;
        optionptr[0] = datalength;
        optionptr++;
        memcpy(optionptr, data, datalength);
        optionptr += datalength;
        optionptr[0] = 0xff;
        return 0;
}

variable_types:
optionptr
unsigned char *

variable_types:
code
unsigned char

variable_types: datalength char

variable_types:
data
char *


original_code:
int add_multiple_option(unsigned char *optionptr, unsigned char code,
                                char datalength, char *data1, char *data2, char *data3) {
        endOption(&optionptr);
        optionptr[0] = code;
        if(code == 0xff)
                return 0;
        optionptr++;
        optionptr[0] = datalength;
        optionptr++;
        if(data1 != ((void *)0)) {
                memcpy(optionptr, data1, 0x04);
                optionptr += 0x04;
                if(data2 != ((void *)0)) {
                        memcpy(optionptr, data2, 0x04);
                        optionptr += 0x04;
                        if(data3 != ((void *)0)) {
                                memcpy(optionptr, data3, 0x04);
                                optionptr += 0x04;
                        }
                }
        }
        optionptr[0] = 0xff;
        return 0;
}


addOptionMulti

original_code:
int addOptionMulti(unsigned char *optionptr, unsigned char code,
                                char datalength, char *data,int mul) {
        int i;
        endOption(&optionptr);
        optionptr[0] = code;
        if(code == 0xff)
                return 0;
        optionptr++;
        optionptr[0] = (datalength * mul);
        optionptr++;
        for (i=0;i<mul;i++) {
                memcpy(optionptr, data, datalength);
                optionptr += datalength;
        }
        optionptr[0] = 0xff;
        return 0;
}

canonical_original_code:
int addOptionMulti(unsigned char *optionptr, unsigned char code, char datalength, char *data, int mul) {
        int i;
        endOption(&optionptr);
        optionptr[0] = code;
        if(code == 0xff)
                return 0;
        optionptr++;
        optionptr[0] = (datalength * mul);
        optionptr++;
        for (i=0;i<mul;i++) {
                memcpy(optionptr, data, datalength);
                optionptr += datalength;
        }
        optionptr[0] = 0xff;
        return 0;
}

variable_types: mul int


getOption

decompiled_code:
unsigned __int8 *__fastcall getOption(unsigned __int8 *a1, int a2)
{
int v2; // eax

getOption:
v2 = *a1;
if ( (_BYTE)v2 == 0xFF )
return 0LL;
while ( 1 )
{
if ( !(_BYTE)v2 )
{
++a1;
goto getOption;
}
if ( v2 == a2 )
return a1 + 2;
a1 += a1[1] + 2;
v2 = *a1;
if ( (_BYTE)v2 == 0xFF )
return 0LL;
}
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func4(unsigned __int8 *a1, int a2)
{
int v2; // eax

getOption:
v2 = *a1;
if ( (_BYTE)v2 == 0xFF )
return 0LL;
while ( 1 )
{
if ( !(_BYTE)v2 )
{
++a1;
goto getOption;
}
if ( v2 == a2 )
return a1 + 2;
a1 += a1[1] + 2;
v2 = *a1;
if ( (_BYTE)v2 == 0xFF )
return 0LL;
}
}

original_code:
unsigned char *getOption(unsigned char *options, int option_val) {
        while(options[0] != 0xff) {
                if(options[0] == 0) {
                        options++;
                        continue;
                }
                if(options[0] == 0xff)
                        return ((void *)0);
                if(options[0] == option_val)
                        return options+2;
                options++;
                options += options[0];
                options++;
        }
        return ((void *)0);
}

variable_types:
options
unsigned char *

return_type: unsigned char *


logtolevel

decompiled_code:
__int64 __fastcall logtolevel(char *s1)
{
const char *v1; // rsi
__int64 v2; // rbx

v1 = "LOG_EMERG";
v2 = 0LL;
do
{
if ( !strcmp(s1, v1) )
return (unsigned int)v2;
v1 = syslog_level[++v2];
}
while ( v1 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
const char *v1; // rsi
__int64 v2; // rbx

v1 = "LOG_EMERG";
v2 = 0LL;
do
{
if ( !strcmp(s1, v1) )
return (unsigned int)v2;
v1 = syslog_level[++v2];
}
while ( v1 );
return 0xFFFFFFFFLL;
}

original_code:
int logtolevel (const char *priority)
{
  int i = 0;
  while (syslog_level[i])
    {
      if (!strcmp (priority, syslog_level[i]))
 return i;
      i++;
    }
  return -1;
}

canonical_original_code:
int logtolevel(char *priority)
{
  int i = 0;
  while (syslog_level[i])
    {
      if (!strcmp (priority, syslog_level[i]))
 return i;
      i++;
    }
  return -1;
}

variable_types:
priority
char *


setloglevel

decompiled_code:
void __fastcall setloglevel(int a1)
{
loglevel = a1;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
loglevel = a1;
}

original_code:
void setloglevel (int level)
{
  loglevel = level;
}

canonical_original_code:
void setloglevel(int level)
{
  loglevel = level;
}

variable_types: level int


setlogprefix

decompiled_code:
int __fastcall setlogprefix(const char *a1)
{
return snprintf(logprefix, 0xCuLL, "%s", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return snprintf(logprefix, 0xCuLL, "%s", a1);
}

original_code:
void setlogprefix (const char *prefix)
{
  snprintf (logprefix, sizeof (logprefix), "%s", prefix);
}

canonical_original_code:
void setlogprefix(char *prefix)
{
  snprintf (logprefix, sizeof (logprefix), "%s", prefix);
}

variable_types:
prefix
char *