decompiled_code:
__int64 __fastcall do_connect(char *cp, __int16 a2)
{
int v4; // eax
unsigned int v5; // er12
char *v6; // rdi
char *v7; // rdi
int v8; // eax
socklen_t v9; // edx
unsigned __int16 v10; // bx
char *v11; // rax
struct in_addr inp[4]; // [rsp+0h] [rbp-28h] BYREF

v4 = socket(2, 1, 0);
if ( v4 < 0 )
{
v5 = -1;
perror("socket");
}
else
{
v5 = v4;
*(_OWORD *)&inp[0].s_addr = 0LL;
LOWORD(inp[0].s_addr) = 2;
v6 = getenv("IPFW_HOST");
if ( !v6 )
v6 = cp;
inet_aton(v6, &inp[1]);
v7 = getenv("IPFW_PORT");
if ( v7 )
{
v8 = atoi(v7);
if ( v8 > 0 )
a2 = v8;
}
HIWORD(inp[0].s_addr) = _bswap_16(a2);
if ( connect(v5, (const struct sockaddr *)inp, v9) < 0 )
{
v5 = -1;
perror("connect");
}
else
{
v10 = _bswap_16(SHIWORD(inp[0].s_addr));
v11 = inet_ntoa(inp[1]);
fprintf(stderr, "connected to %s:%d\n", v11, v10);
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func14(char *cp, __int16 a2)
{
int v4; // eax
unsigned int v5; // er12
char *v6; // rdi
char *v7; // rdi
int v8; // eax
socklen_t v9; // edx
unsigned __int16 v10; // bx
char *v11; // rax
struct in_addr inp[4]; // [rsp+0h] [rbp-28h] BYREF

v4 = socket(2, 1, 0);
if ( v4 < 0 )
{
v5 = -1;
perror("socket");
}
else
{
v5 = v4;
*(_OWORD *)&inp[0].s_addr = 0LL;
LOWORD(inp[0].s_addr) = 2;
v6 = getenv("IPFW_HOST");
if ( !v6 )
v6 = cp;
inet_aton(v6, &inp[1]);
v7 = getenv("IPFW_PORT");
if ( v7 )
{
v8 = atoi(v7);
if ( v8 > 0 )
a2 = v8;
}
HIWORD(inp[0].s_addr) = func3(a2);
if ( connect(v5, (const struct sockaddr *)inp, v9) < 0 )
{
v5 = -1;
perror("connect");
}
else
{
v10 = func3(SHIWORD(inp[0].s_addr));
v11 = inet_ntoa(inp[1]);
fprintf(stderr, "connected to %s:%d\n", v11, v10);
}
}
return v5;
}

original_code:
int
do_connect(const char *addr, int port)
{
 int conn_fd;
        struct sockaddr_in server;
 const char *s;
        conn_fd = socket(2, SOCK_STREAM, 0);
        if (conn_fd < 0) {
  perror("socket");
  return -1;
 }
 bzero(&server, sizeof(server));
 server.sin_family = 2;
 s = getenv("IPFW_HOST");
 if (s)
  addr = s;
 inet_aton(addr, &server.sin_addr);
 s = getenv("IPFW_PORT");
 if (s && atoi(s) > 0)
  port = atoi(s);
 server.sin_port = htons(port);
        if (connect(conn_fd, (struct sockaddr*) &server, sizeof(server)) < 0) {
  perror("connect");
  return -1;
 }
 if (1)
  fprintf(stderr, "connected to %s:%d\n",
   inet_ntoa(server.sin_addr), ntohs(server.sin_port));
 return conn_fd;
}

canonical_original_code:
int do_connect(char *addr, int port)
{
 int conn_fd;
        struct sockaddr_in server;
 char *s;
        conn_fd = socket(2, SOCK_STREAM, 0);
        if (conn_fd < 0) {
  perror("socket");
  return -1;
 }
 bzero(&server, sizeof(server));
 server.sin_family = 2;
 s = getenv("IPFW_HOST");
 if (s)
  addr = s;
 inet_aton(addr, &server.sin_addr);
 s = getenv("IPFW_PORT");
 if (s && atoi(s) > 0)
  port = atoi(s);
 server.sin_port = htons(port);
        if (connect(conn_fd, (struct sockaddr *) &server, sizeof(server)) < 0) {
  perror("connect");
  return -1;
 }
 if (1)
  fprintf(stderr, "connected to %s:%d\n",
   inet_ntoa(server.sin_addr), ntohs(server.sin_port));
 return conn_fd;
}

variable_types:
addr
char *

variable_types: port int

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

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

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


repo: polymorf/ipfw-user

original_code:
static int
ipfw_ctl_h(struct sockopt *s, int cmd, int dir, int len, void *user)
{
 struct thread t;
 int ret = 22;
 memset(s, 0, sizeof(s));
 s->sopt_name = cmd;
 s->sopt_dir = dir;
 s->sopt_valsize = len;
 s->sopt_val = user;
 memset(&t, 0, sizeof(t));
 s->sopt_td = &t;
 if (ip_fw_ctl_ptr && cmd != (100 + 9) && (cmd == (100 + 8) ||
     cmd < (100 + 20)))
  ret = ip_fw_ctl_ptr(s);
 else if (ip_dn_ctl_ptr && (cmd == (100 + 9) ||
     cmd >= (100 + 20)))
  ret = ip_dn_ctl_ptr(s);
 return -ret;
}

variable_types: struct sockopt { enum sopt_dir { SOPT_GET=0, SOPT_SET=1 } sopt_dir; int sopt_level; int sopt_name; void *sopt_val; unsigned long sopt_valsize; struct thread { void *sopt_td; void *td_ucred; } *sopt_td; } *

variable_types: cmd int

variable_types: dir int

variable_types: len int

variable_types:
user
void *

variable_types: ret int

return_type: int

user_defined_types: struct sockopt { enum sopt_dir sopt_dir; int sopt_level; int sopt_name; void *sopt_val; unsigned long sopt_valsize; struct thread *sopt_td; }


decompiled_code:
__int64 __fastcall do_ipfw_set_ctl(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 v5; // [rsp+0h] [rbp-38h] BYREF

return ipfw_ctl_h((__int64)&v5, a2, 1, a4, a3);
}

original_code:
int
do_ipfw_set_ctl(void *sk, int cmd,
 void *user, unsigned int len)
{
 struct sockopt s;
 return ipfw_ctl_h(&s, cmd, SOPT_SET, len, user);
}

variable_types:
sk
void *

variable_types:
len
unsigned int

variable_types: struct sockopt { enum sopt_dir { SOPT_GET=0, SOPT_SET=1 } sopt_dir; int sopt_level; int sopt_name; void *sopt_val; unsigned long sopt_valsize; struct thread { void *sopt_td; void *td_ucred; } *sopt_td; }


decompiled_code:
__int64 __fastcall do_ipfw_get_ctl(__int64 a1, __int64 a2, __int64 a3, int *a4)
{
__int64 result; // rax
_DWORD v6[14]; // [rsp+0h] [rbp-38h] BYREF

result = ipfw_ctl_h((__int64)v6, a2, 0, *a4, a3);
*a4 = v6[6];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, int *a4)
{
__int64 result; // rax
_DWORD v6[14]; // [rsp+0h] [rbp-38h] BYREF

result = func0((__int64)v6, a2, 0, *a4, a3);
*a4 = v6[6];
return result;
}

original_code:
int
do_ipfw_get_ctl(void *sk,
 int cmd, void *user, int *len)
{
 struct sockopt s;
 int ret = ipfw_ctl_h(&s, cmd, SOPT_GET, *len, user);
 *len = s.sopt_valsize;
 return ret;
}

variable_types:
len
int *

user_defined_types: enum sopt_dir { SOPT_GET=0, SOPT_SET=1 }

user_defined_types: struct thread { void *sopt_td; void *td_ucred; }


decompiled_code:
__int64 ipfw_module_init()
{
__int64 v0; // rdx
__int64 v1; // rcx
__int64 v2; // r8
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // rcx
__int64 v10; // r8

rn_init(64LL);
my_mod_register((__int64)"ipfw", 1, moddesc_ipfw, 0LL, 0LL);
my_mod_register((__int64)"sy_ipfw", 2, 0LL, sysinit_ipfw_init, sysuninit_ipfw_destroy);
my_mod_register((__int64)"sy_Vnet_ipfw", 3, v0, sysinit_vnet_ipfw_init, sysuninit_vnet_ipfw_uninit);
my_mod_register((__int64)"dummynet", 4, moddesc_dummynet, 0LL, 0LL);
my_mod_register((__int64)"dn_fifo", 5, moddesc_dn_fifo, v1, v2);
my_mod_register((__int64)"dn_wf2qp", 6, moddesc_dn_wf2qp, v3, v4);
my_mod_register((__int64)"dn_rr", 7, moddesc_dn_rr, v5, v6);
my_mod_register((__int64)"dn_qfq", 8, moddesc_dn_qfq, v7, v8);
my_mod_register((__int64)"dn_prio", 9, moddesc_dn_prio, v9, v10);
init_children();
keinit_GST();
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rdx
__int64 v1; // rcx
__int64 v2; // r8
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // rcx
__int64 v10; // r8

rn_init(64LL);
func5((__int64)"ipfw", 1, moddesc_ipfw, 0LL, 0LL);
func5((__int64)"sy_ipfw", 2, 0LL, sysinit_ipfw_init, sysuninit_ipfw_destroy);
func5((__int64)"sy_Vnet_ipfw", 3, v0, sysinit_vnet_ipfw_init, sysuninit_vnet_ipfw_uninit);
func5((__int64)"dummynet", 4, moddesc_dummynet, 0LL, 0LL);
func5((__int64)"dn_fifo", 5, moddesc_dn_fifo, v1, v2);
func5((__int64)"dn_wf2qp", 6, moddesc_dn_wf2qp, v3, v4);
func5((__int64)"dn_rr", 7, moddesc_dn_rr, v5, v6);
func5((__int64)"dn_qfq", 8, moddesc_dn_qfq, v7, v8);
func5((__int64)"dn_prio", 9, moddesc_dn_prio, v9, v10);
func1();
keinit_GST();
return 0LL;
}

original_code:
int
ipfw_module_init(void)
{
 int ret = 0;
 rn_init(64);
 my_mod_register("ipfw", 1, moddesc_ipfw, ((void *)0), ((void *)0));
 my_mod_register("sy_ipfw", 2, ((void *)0),
  sysinit_ipfw_init, sysuninit_ipfw_destroy);
 my_mod_register("sy_Vnet_ipfw", 3, ((void *)0),
  sysinit_vnet_ipfw_init, sysuninit_vnet_ipfw_uninit);
 my_mod_register("dummynet", 4, moddesc_dummynet, ((void *)0), ((void *)0));
 my_mod_register("dn_fifo", 5, moddesc_dn_fifo, ((void *)0), ((void *)0));
 my_mod_register("dn_wf2qp", 6, moddesc_dn_wf2qp, ((void *)0), ((void *)0));
 my_mod_register("dn_rr", 7, moddesc_dn_rr, ((void *)0), ((void *)0));
 my_mod_register("dn_qfq", 8, moddesc_dn_qfq, ((void *)0), ((void *)0));
 my_mod_register("dn_prio", 9, moddesc_dn_prio, ((void *)0), ((void *)0));
 init_children();
 keinit_GST();
 return ret;
}

canonical_original_code:
int ipfw_module_init()
{
 int ret = 0;
 rn_init(64);
 my_mod_register("ipfw", 1, moddesc_ipfw, ((void *)0), ((void *)0));
 my_mod_register("sy_ipfw", 2, ((void *)0),
  sysinit_ipfw_init, sysuninit_ipfw_destroy);
 my_mod_register("sy_Vnet_ipfw", 3, ((void *)0),
  sysinit_vnet_ipfw_init, sysuninit_vnet_ipfw_uninit);
 my_mod_register("dummynet", 4, moddesc_dummynet, ((void *)0), ((void *)0));
 my_mod_register("dn_fifo", 5, moddesc_dn_fifo, ((void *)0), ((void *)0));
 my_mod_register("dn_wf2qp", 6, moddesc_dn_wf2qp, ((void *)0), ((void *)0));
 my_mod_register("dn_rr", 7, moddesc_dn_rr, ((void *)0), ((void *)0));
 my_mod_register("dn_qfq", 8, moddesc_dn_qfq, ((void *)0), ((void *)0));
 my_mod_register("dn_prio", 9, moddesc_dn_prio, ((void *)0), ((void *)0));
 init_children();
 keinit_GST();
 return ret;
}


decompiled_code:
int ipfw_module_exit()
{
keexit_GST();
fini_children();
return printf("%s unloaded\n", "ipfw_module_exit");
}

canonical_decompiled_code:
int func7()
{
keexit_GST();
func2();
return printf("%s unloaded\n", "ipfw_module_exit");
}

original_code:
void
ipfw_module_exit(void)
{
 keexit_GST();
 fini_children();
 printf("%s unloaded\n", __FUNCTION__);
}

canonical_original_code:
void ipfw_module_exit()
{
 keexit_GST();
 fini_children();
 printf("%s unloaded\n", __FUNCTION__);
}

return_type: void


decompiled_code:
void ipfw_log_bpf()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void
ipfw_log_bpf(int onoff)
{
}

canonical_original_code:
void ipfw_log_bpf(int onoff)
{
}

variable_types: onoff int


decompiled_code:
__int64 __fastcall expand_number(const char *a1, uintmax_t *a2)
{
uintmax_t v2; // rax
char *v3; // r13
uintmax_t v4; // rbp
__int32_t v5; // eax
__int64 result; // rax
char v7; // cl
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v2 = strtoumax(a1, &endptr, 0);
v3 = endptr;
if ( endptr == a1 )
{
LABEL_4:
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
else
{
v4 = v2;
v5 = (*_ctype_tolower_loc())[(unsigned __int8)*v3];
if ( v5 )
{
switch ( v5 )
{
case 'b':
goto LABEL_5;
case 'e':
v7 = 60;
break;
case 'g':
v7 = 30;
break;
case 'k':
v7 = 10;
break;
case 'm':
v7 = 20;
break;
case 'p':
v7 = 50;
break;
case 't':
v7 = 40;
break;
default:
goto LABEL_4;
}
if ( v4 == v4 << v7 >> v7 )
{
*a2 = v4 << v7;
result = 0LL;
}
else
{
*_errno_location() = 34;
result = 0xFFFFFFFFLL;
}
}
else
{
LABEL_5:
*a2 = v4;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, uintmax_t *a2)
{
uintmax_t v2; // rax
char *v3; // r13
uintmax_t v4; // rbp
__int32_t v5; // eax
__int64 result; // rax
char v7; // cl
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v2 = strtoumax(a1, &endptr, 0);
v3 = endptr;
if ( endptr == a1 )
{
LABEL_4:
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
else
{
v4 = v2;
v5 = (*_ctype_tolower_loc())[(unsigned __int8)*v3];
if ( v5 )
{
switch ( v5 )
{
case 'b':
goto LABEL_5;
case 'e':
v7 = 60;
break;
case 'g':
v7 = 30;
break;
case 'k':
v7 = 10;
break;
case 'm':
v7 = 20;
break;
case 'p':
v7 = 50;
break;
case 't':
v7 = 40;
break;
default:
goto LABEL_4;
}
if ( v4 == v4 << v7 >> v7 )
{
*a2 = v4 << v7;
result = 0LL;
}
else
{
*_errno_location() = 34;
result = 0xFFFFFFFFLL;
}
}
else
{
LABEL_5:
*a2 = v4;
result = 0LL;
}
}
return result;
}

original_code:
int
expand_number(const char *buf, uint64_t *num)
{
 uint64_t number;
 unsigned shift;
 char *endptr;
 number = strtoumax(buf, &endptr, 0);
 if (endptr == buf) {
  (*__errno_location ()) = 22;
  return (-1);
 }
 switch (tolower((unsigned char)*endptr)) {
 case 'e':
  shift = 60;
  break;
 case 'p':
  shift = 50;
  break;
 case 't':
  shift = 40;
  break;
 case 'g':
  shift = 30;
  break;
 case 'm':
  shift = 20;
  break;
 case 'k':
  shift = 10;
  break;
 case 'b':
 case '\0':
  *num = number;
  return (0);
 default:
  (*__errno_location ()) = 22;
  return (-1);
 }
 if ((number << shift) >> shift != number) {
  (*__errno_location ()) = 34;
  return (-1);
 }
 *num = number << shift;
 return (0);
}

canonical_original_code:
int expand_number(char *buf, unsigned long *num)
{
 unsigned long number;
 unsigned int shift;
 char *endptr;
 number = strtoumax(buf, &endptr, 0);
 if (endptr == buf) {
  (*__errno_location ()) = 22;
  return (-1);
 }
 switch (tolower((unsigned char)*endptr)) {
 case 'e':
  shift = 60;
  break;
 case 'p':
  shift = 50;
  break;
 case 't':
  shift = 40;
  break;
 case 'g':
  shift = 30;
  break;
 case 'm':
  shift = 20;
  break;
 case 'k':
  shift = 10;
  break;
 case 'b':
 case '\0':
  *num = number;
  return (0);
 default:
  (*__errno_location ()) = 22;
  return (-1);
 }
 if ((number << shift) >> shift != number) {
  (*__errno_location ()) = 34;
  return (-1);
 }
 *num = number << shift;
 return (0);
}

variable_types:
buf
char *

variable_types:
num
unsigned long *

variable_types:
number
unsigned long

variable_types:
shift
unsigned int

variable_types:
endptr
char *


decompiled_code:
__int64 __fastcall humanize_number(char *s, size_t maxlen, __int64 a3, const char *a4, int a5, char a6)
{
__int64 v10; // rbx
const char *v12; // r9
__int64 v13; // rax
__int64 v14; // rbp
__int64 v15; // rcx
const char *v16; // r8
size_t v17; // rcx
int i; // er10
const char *v19; // r9
__int64 v20; // rdx
const char *v21; // rbp
struct lconv *v22; // rax
__int64 v24; // rsi
int v25; // eax
int v27; // [rsp+Ch] [rbp-5Ch]
int v28; // [rsp+18h] [rbp-50h]
const char *v29; // [rsp+20h] [rbp-48h]
const char *v30; // [rsp+28h] [rbp-40h]

if ( !s )
_assert_fail("buf != NULL", "../extra/humanize_number.c", 0x38u, "humanize_number");
if ( !a4 )
_assert_fail("suffix != NULL", "../extra/humanize_number.c", 0x39u, "humanize_number");
if ( a5 < 0 )
_assert_fail("scale >= 0", "../extra/humanize_number.c", 0x3Au, "humanize_number");
v10 = a3;
if ( a5 > 6 && (a5 & 0x30) == 0 )
_assert_fail(
"scale < maxscale || (((scale & (HN_AUTOSCALE | HN_GETSCALE)) != 0))",
"../extra/humanize_number.c",
0x3Bu,
"humanize_number");
if ( (a6 & 0x18) == 24 )
_assert_fail(
"!((flags & HN_DIVISOR_1000) && (flags & HN_IEC_PREFIXES))",
"../extra/humanize_number.c",
0x3Cu,
"humanize_number");
if ( (a6 & 0x10) != 0 )
{
v12 = (const char *)&unk_3A0;
v13 = 2LL;
if ( (a6 & 4) != 0 )
v12 = (const char *)&unk_3C8;
v14 = 1024LL;
}
else
{
v12 = (const char *)&unk_3DD;
v13 = 1LL;
v14 = (a6 & 8) == 0 ? 1024LL : 1000LL;
if ( (a6 & 4) != 0 )
v12 = (const char *)&unk_3B4;
}
if ( a5 > 6 && (a5 & 0x30) == 0 )
return (unsigned int)-1;
if ( maxlen )
*s = 0;
v27 = 1;
v15 = v13 + 1;
if ( a3 < 0 )
{
v27 = -1;
v10 = -a3;
v15 = v13 + 2;
}
v16 = (const char *)&unk_412;
if ( (a6 & 2) == 0 )
{
++v15;
v16 = " ";
}
v30 = v12;
v29 = v16;
v17 = strlen(a4) + v15;
if ( v17 + 1 > maxlen )
return (unsigned int)-1;
i = a5 & 0x30;
v19 = v30;
if ( (a5 & 0x30) == 0 )
{
if ( !a5 )
return (unsigned int)snprintf(s, maxlen, "%ld%s%s%s", v10 * v27, v29, v19, a4);
do
{
++i;
v20 = v10 % v14;
v10 /= v14;
}
while ( a5 > i && i <= 6 );
LABEL_22:
if ( (int)v20 <= 949 && v10 <= 9 && i )
{
if ( (a6 & 1) != 0 )
{
v28 = v20;
if ( v17 + 3 <= maxlen )
{
v21 = &v30[3 * i];
v22 = localeconv();
return (unsigned int)snprintf(
s,
maxlen,
"%d%s%d%s%s%s",
(unsigned int)(v10 * v27),
v22->decimal_point,
(unsigned int)(v28 + 50) / 0x64uLL,
v29,
v21,
a4);
}
return (unsigned int)-1;
}
v19 = &v30[3 * i];
}
else
{
v19 = &v30[3 * i];
v10 += (unsigned int)(v20 + 50) / 0x3E8uLL;
}
return (unsigned int)snprintf(s, maxlen, "%ld%s%s%s", v10 * v27, v29, v19, a4);
}
v24 = 1LL;
v25 = maxlen - v17 - 1;
if ( (int)maxlen - (int)v17 > 0 )
{
do
v24 *= 10LL;
while ( v25-- != 0 );
}
LODWORD(v20) = 0;
for ( i = 0; (v10 >= v24 || v24 - 1 == v10 && (int)v20 > 949) && i != 7; ++i )
{
v20 = v10 % v14;
v10 /= v14;
}
if ( (a5 & 0x10) == 0 )
goto LABEL_22;
return (unsigned int)i;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s, size_t maxlen, __int64 a3, const char *a4, int a5, char a6)
{
__int64 v10; // rbx
const char *v12; // r9
__int64 v13; // rax
__int64 v14; // rbp
__int64 v15; // rcx
const char *v16; // r8
size_t v17; // rcx
int i; // er10
const char *v19; // r9
__int64 v20; // rdx
const char *v21; // rbp
struct lconv *v22; // rax
__int64 v24; // rsi
int v25; // eax
int v27; // [rsp+Ch] [rbp-5Ch]
int v28; // [rsp+18h] [rbp-50h]
const char *v29; // [rsp+20h] [rbp-48h]
const char *v30; // [rsp+28h] [rbp-40h]

if ( !s )
_assert_fail("buf != NULL", "../extra/humanize_number.c", 0x38u, "humanize_number");
if ( !a4 )
_assert_fail("suffix != NULL", "../extra/humanize_number.c", 0x39u, "humanize_number");
if ( a5 < 0 )
_assert_fail("scale >= 0", "../extra/humanize_number.c", 0x3Au, "humanize_number");
v10 = a3;
if ( a5 > 6 && (a5 & 0x30) == 0 )
_assert_fail(
"scale < maxscale || (((scale & (HN_AUTOSCALE | HN_GETSCALE)) != 0))",
"../extra/humanize_number.c",
0x3Bu,
"humanize_number");
if ( (a6 & 0x18) == 24 )
_assert_fail(
"!((flags & HN_DIVISOR_1000) && (flags & HN_IEC_PREFIXES))",
"../extra/humanize_number.c",
0x3Cu,
"humanize_number");
if ( (a6 & 0x10) != 0 )
{
v12 = (const char *)&unk_3A0;
v13 = 2LL;
if ( (a6 & 4) != 0 )
v12 = (const char *)&unk_3C8;
v14 = 1024LL;
}
else
{
v12 = (const char *)&unk_3DD;
v13 = 1LL;
v14 = (a6 & 8) == 0 ? 1024LL : 1000LL;
if ( (a6 & 4) != 0 )
v12 = (const char *)&unk_3B4;
}
if ( a5 > 6 && (a5 & 0x30) == 0 )
return (unsigned int)-1;
if ( maxlen )
*s = 0;
v27 = 1;
v15 = v13 + 1;
if ( a3 < 0 )
{
v27 = -1;
v10 = -a3;
v15 = v13 + 2;
}
v16 = (const char *)&unk_412;
if ( (a6 & 2) == 0 )
{
++v15;
v16 = " ";
}
v30 = v12;
v29 = v16;
v17 = strlen(a4) + v15;
if ( v17 + 1 > maxlen )
return (unsigned int)-1;
i = a5 & 0x30;
v19 = v30;
if ( (a5 & 0x30) == 0 )
{
if ( !a5 )
return (unsigned int)snprintf(s, maxlen, "%ld%s%s%s", v10 * v27, v29, v19, a4);
do
{
++i;
v20 = v10 % v14;
v10 /= v14;
}
while ( a5 > i && i <= 6 );
LABEL_22:
if ( (int)v20 <= 949 && v10 <= 9 && i )
{
if ( (a6 & 1) != 0 )
{
v28 = v20;
if ( v17 + 3 <= maxlen )
{
v21 = &v30[3 * i];
v22 = localeconv();
return (unsigned int)snprintf(
s,
maxlen,
"%d%s%d%s%s%s",
(unsigned int)(v10 * v27),
v22->decimal_point,
(unsigned int)(v28 + 50) / 0x64uLL,
v29,
v21,
a4);
}
return (unsigned int)-1;
}
v19 = &v30[3 * i];
}
else
{
v19 = &v30[3 * i];
v10 += (unsigned int)(v20 + 50) / 0x3E8uLL;
}
return (unsigned int)snprintf(s, maxlen, "%ld%s%s%s", v10 * v27, v29, v19, a4);
}
v24 = 1LL;
v25 = maxlen - v17 - 1;
if ( (int)maxlen - (int)v17 > 0 )
{
do
v24 *= 10LL;
while ( v25-- != 0 );
}
LODWORD(v20) = 0;
for ( i = 0; (v10 >= v24 || v24 - 1 == v10 && (int)v20 > 949) && i != 7; ++i )
{
v20 = v10 % v14;
v10 /= v14;
}
if ( (a5 & 0x10) == 0 )
goto LABEL_22;
return (unsigned int)i;
}

original_code:
int
humanize_number(char *buf, size_t len, int64_t quotient,
    const char *suffix, int scale, int flags)
{
 const char *prefixes, *sep;
 int i, r, remainder, s1, s2, sign;
 int64_t divisor, max;
 size_t baselen;
 ((void) sizeof ((buf != ((void *)0)) ? 1 : 0), __extension__ ({ if (buf != ((void *)0)) ; else __assert_fail ("buf != NULL", "../extra/humanize_number.c", 56, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((suffix != ((void *)0)) ? 1 : 0), __extension__ ({ if (suffix != ((void *)0)) ; else __assert_fail ("suffix != NULL", "../extra/humanize_number.c", 57, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((scale >= 0) ? 1 : 0), __extension__ ({ if (scale >= 0) ; else __assert_fail ("scale >= 0", "../extra/humanize_number.c", 58, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((scale < maxscale || (((scale & (0x20 | 0x10)) != 0))) ? 1 : 0), __extension__ ({ if (scale < maxscale || (((scale & (0x20 | 0x10)) != 0))) ; else __assert_fail ("scale < maxscale || (((scale & (HN_AUTOSCALE | HN_GETSCALE)) != 0))", "../extra/humanize_number.c", 59, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!((flags & 0x08) && (flags & 0x10))) ? 1 : 0), __extension__ ({ if (!((flags & 0x08) && (flags & 0x10))) ; else __assert_fail ("!((flags & HN_DIVISOR_1000) && (flags & HN_IEC_PREFIXES))", "../extra/humanize_number.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 remainder = 0;
 if (flags & 0x10) {
  baselen = 2;
  divisor = 1024;
  if (flags & 0x04)
   prefixes = "B\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei";
  else
   prefixes = "\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei";
 } else {
  baselen = 1;
  if (flags & 0x08)
   divisor = 1000;
  else
   divisor = 1024;
  if (flags & 0x04)
   prefixes = "B\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E";
  else
   prefixes = "\0\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E";
 }
 if (scale < 0 || (scale >= maxscale &&
     (scale & (0x20 | 0x10)) == 0))
  return (-1);
 if (buf == ((void *)0) || suffix == ((void *)0))
  return (-1);
 if (len > 0)
  buf[0] = '\0';
 if (quotient < 0) {
  sign = -1;
  quotient = -quotient;
  baselen += 2;
 } else {
  sign = 1;
  baselen += 1;
 }
 if (flags & 0x02)
  sep = "";
 else {
  sep = " ";
  baselen++;
 }
 baselen += strlen(suffix);
 if (len < baselen + 1)
  return (-1);
 if (scale & (0x20 | 0x10)) {
  for (max = 1, i = len - baselen; i-- > 0;)
   max *= 10;
  for (i = 0;
      (quotient >= max || (quotient == max - 1 && remainder >= 950)) &&
      i < maxscale; i++) {
   remainder = quotient % divisor;
   quotient /= divisor;
  }
  if (scale & 0x10)
   return (i);
 } else {
  for (i = 0; i < scale && i < maxscale; i++) {
   remainder = quotient % divisor;
   quotient /= divisor;
  }
 }
 if (quotient <= 9 && remainder < 950 && i > 0 && flags & 0x01) {
  if (len < baselen + 1 + 2)
   return (-1);
  s1 = (int)quotient + ((remainder + 50) / 1000);
  s2 = ((remainder + 50) / 100) % 10;
  r = snprintf(buf, len, "%d%s%d%s%s%s",
      sign * s1, localeconv()->decimal_point, s2,
      sep, (&prefixes[(i) * 3]), suffix);
 } else
  r = snprintf(buf, len, "%" "l" "d" "%s%s%s",
      sign * (quotient + (remainder + 50) / 1000),
      sep, (&prefixes[(i) * 3]), suffix);
 return (r);
}

canonical_original_code:
int humanize_number(char *buf, unsigned long len, long quotient, char *suffix, int scale, int flags)
{
 char *prefixes; char *sep;
 int i; int r; int remainder; int s1; int s2; int sign;
 long divisor; long max;
 unsigned long baselen;
 ((void) sizeof ((buf != ((void *)0)) ? 1 : 0), __extension__ ({ if (buf != ((void *)0)) ; else __assert_fail ("buf != NULL", "../extra/humanize_number.c", 56, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((suffix != ((void *)0)) ? 1 : 0), __extension__ ({ if (suffix != ((void *)0)) ; else __assert_fail ("suffix != NULL", "../extra/humanize_number.c", 57, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((scale >= 0) ? 1 : 0), __extension__ ({ if (scale >= 0) ; else __assert_fail ("scale >= 0", "../extra/humanize_number.c", 58, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((scale < maxscale || (((scale & (0x20 | 0x10)) != 0))) ? 1 : 0), __extension__ ({ if (scale < maxscale || (((scale & (0x20 | 0x10)) != 0))) ; else __assert_fail ("scale < maxscale || (((scale & (HN_AUTOSCALE | HN_GETSCALE)) != 0))", "../extra/humanize_number.c", 59, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!((flags & 0x08) && (flags & 0x10))) ? 1 : 0), __extension__ ({ if (!((flags & 0x08) && (flags & 0x10))) ; else __assert_fail ("!((flags & HN_DIVISOR_1000) && (flags & HN_IEC_PREFIXES))", "../extra/humanize_number.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 remainder = 0;
 if (flags & 0x10) {
  baselen = 2;
  divisor = 1024;
  if (flags & 0x04)
   prefixes = "B\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei";
  else
   prefixes = "\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei";
 } else {
  baselen = 1;
  if (flags & 0x08)
   divisor = 1000;
  else
   divisor = 1024;
  if (flags & 0x04)
   prefixes = "B\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E";
  else
   prefixes = "\0\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E";
 }
 if (scale < 0 || (scale >= maxscale &&
     (scale & (0x20 | 0x10)) == 0))
  return (-1);
 if (buf == ((void *)0) || suffix == ((void *)0))
  return (-1);
 if (len > 0)
  buf[0] = '\0';
 if (quotient < 0) {
  sign = -1;
  quotient = -quotient;
  baselen += 2;
 } else {
  sign = 1;
  baselen += 1;
 }
 if (flags & 0x02)
  sep = "";
 else {
  sep = " ";
  baselen++;
 }
 baselen += strlen(suffix);
 if (len < baselen + 1)
  return (-1);
 if (scale & (0x20 | 0x10)) {
  for (max = 1, i = len - baselen; i-- > 0;)
   max *= 10;
  for (i = 0;
      (quotient >= max || (quotient == max - 1 && remainder >= 950)) &&
      i < maxscale; i++) {
   remainder = quotient % divisor;
   quotient /= divisor;
  }
  if (scale & 0x10)
   return (i);
 } else {
  for (i = 0; i < scale && i < maxscale; i++) {
   remainder = quotient % divisor;
   quotient /= divisor;
  }
 }
 if (quotient <= 9 && remainder < 950 && i > 0 && flags & 0x01) {
  if (len < baselen + 1 + 2)
   return (-1);
  s1 = (int)quotient + ((remainder + 50) / 1000);
  s2 = ((remainder + 50) / 100) % 10;
  r = snprintf(buf, len, "%d%s%d%s%s%s",
      sign * s1, localeconv()->decimal_point, s2,
      sep, (&prefixes[(i) * 3]), suffix);
 } else
  r = snprintf(buf, len, "%" "l" "d" "%s%s%s",
      sign * (quotient + (remainder + 50) / 1000),
      sep, (&prefixes[(i) * 3]), suffix);
 return (r);
}

variable_types:
len
unsigned long

variable_types: quotient long

variable_types:
suffix
char *

variable_types: scale int

variable_types: flags int

variable_types:
prefixes
char *

variable_types:
sep
char *

variable_types: i int

variable_types: r int

variable_types: remainder int

variable_types: sign int

variable_types: divisor long

variable_types: max long

variable_types:
baselen
unsigned long


decompiled_code:
__int64 sysctl_addgroup_f1()
{
return sysctl_pushback("net_inet_ip_fw.enable", 258LL, 4LL, ipfw_chg_hook);
}

canonical_decompiled_code:
__int64 func10()
{
return sysctl_pushback("net_inet_ip_fw.enable", 258LL, 4LL, ipfw_chg_hook);
}

original_code:
void sysctl_addgroup_f1() {
;
sysctl_pushback("_net_inet_ip_fw" "." "enable" + 1, (CTLTYPE_INT | 2 | 0), 4 , ipfw_chg_hook);
}


repo: polyphemus/libspacemouse

decompiled_code:
__int64 __fastcall spacemouse_device_list_get_next(__int64 a1)
{
return *(_QWORD *)(a1 + 88);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)(a1 + 88);
}

original_code:
struct spacemouse *spacemouse_device_list_get_next(struct spacemouse *mouse) {
  return mouse->next;
}

variable_types:
mouse
struct spacemouse *

return_type: struct spacemouse { int id; int fd; void *data; char *devnode; char *manufacturer; char *product; struct spacemouse_buf { struct spacemouse_event_motion { int type; int x; int rx; unsigned int period; } motion; struct timeval { long tv_sec; long tv_usec; } time; } buf; struct spacemouse *next; } *

user_defined_types: struct spacemouse { int id; int fd; void *data; char *devnode; char *manufacturer; char *product; struct spacemouse_buf buf; struct spacemouse *next; }

user_defined_types: struct spacemouse_buf { struct spacemouse_event_motion motion; struct timeval time; }


decompiled_code:
__int64 __fastcall spacemouse_device_get_id(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
return *a1;
}

original_code:
int spacemouse_device_get_id(struct spacemouse *mouse) {
  return mouse->id;
}

variable_types: struct spacemouse { int id; int fd; void *data; char *devnode; char *manufacturer; char *product; struct spacemouse_buf { struct spacemouse_event_motion { int type; int x; int rx; unsigned int period; } motion; struct timeval { long tv_sec; long tv_usec; } time; } buf; struct spacemouse *next; } *


decompiled_code:
__int64 __fastcall spacemouse_device_get_fd(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

original_code:
int spacemouse_device_get_fd(struct spacemouse *mouse) {
  return mouse->fd;
}

user_defined_types: struct spacemouse_event_motion { int type; int x; int rx; unsigned int period; }

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


decompiled_code:
__int64 __fastcall spacemouse_device_get_devnode(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
char const * const spacemouse_device_get_devnode(struct spacemouse *mouse) {
  return mouse->devnode;
}

canonical_original_code:
char *spacemouse_device_get_devnode(struct spacemouse *mouse) {
  return mouse->devnode;
}

return_type: char *


decompiled_code:
__int64 __fastcall spacemouse_device_get_manufacturer(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
char const * const spacemouse_device_get_manufacturer(
    struct spacemouse *mouse) {
  return mouse->manufacturer;
}

canonical_original_code:
char *spacemouse_device_get_manufacturer(struct spacemouse *mouse) {
  return mouse->manufacturer;
}


decompiled_code:
__int64 __fastcall spacemouse_device_get_product(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

original_code:
char const * const spacemouse_device_get_product(struct spacemouse *mouse) {
  return mouse->product;
}

canonical_original_code:
char *spacemouse_device_get_product(struct spacemouse *mouse) {
  return mouse->product;
}


decompiled_code:
void __fastcall spacemouse_device_set_data(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

original_code:
void spacemouse_device_set_data(struct spacemouse *mouse, void *data) {
  mouse->data = data;
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall spacemouse_device_get_data(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
void *spacemouse_device_get_data(struct spacemouse *mouse) {
  return mouse->data;
}

return_type: void *


decompiled_code:
__int64 __fastcall devnode_used_in_list(char *s2)
{
__int64 i; // r12

for ( i = spacemouse_head; i; i = *(_QWORD *)(i + 88) )
{
if ( !strcmp(*(const char **)(i + 16), s2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2)
{
__int64 i; // r12

for ( i = spacemouse_head; i; i = *(_QWORD *)(i + 88) )
{
if ( !strcmp(*(const char **)(i + 16), s2) )
break;
}
return i;
}

original_code:
static struct spacemouse *devnode_used_in_list(char const *devnode)
{
  struct spacemouse *iter = spacemouse_head;
  for ( ; iter; iter = iter->next)
    if (strcmp(iter->devnode, devnode) == 0)
      return iter;
  return ((void *)0);
}

canonical_original_code:
static struct spacemouse *devnode_used_in_list(char *devnode)
{
  struct spacemouse *iter = spacemouse_head;
  for ( ; iter; iter = iter->next)
    if (strcmp(iter->devnode, devnode) == 0)
      return iter;
  return ((void *)0);
}

variable_types:
devnode
char *


decompiled_code:
__int64 spacemouse_monitor_open()
{
int v0; // eax
unsigned int v1; // er12
unsigned int v2; // eax
__int64 v4; // rdi

if ( !udev_monitor )
{
v4 = udev;
if ( !udev )
{
udev = udev_new();
v4 = udev;
}
udev_monitor = udev_monitor_new_from_netlink(v4, "udev");
udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "input", 0LL);
udev_monitor_enable_receiving(udev_monitor);
}
v0 = udev_monitor_get_fd();
v1 = v0;
if ( v0 < 0 )
return (unsigned int)-*_errno_location();
v2 = fcntl(v0, 3);
BYTE1(v2) &= 0xF7u;
fcntl(v1, 4, v2);
return v1;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
unsigned int v1; // er12
unsigned int v2; // eax
__int64 v4; // rdi

if ( !udev_monitor )
{
v4 = udev;
if ( !udev )
{
udev = udev_new();
v4 = udev;
}
udev_monitor = udev_monitor_new_from_netlink(v4, "udev");
udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "input", 0LL);
udev_monitor_enable_receiving(udev_monitor);
}
v0 = udev_monitor_get_fd();
v1 = v0;
if ( v0 < 0 )
return (unsigned int)-*_errno_location();
v2 = fcntl(v0, 3);
BYTE1(v2) &= 0xF7u;
fcntl(v1, 4, v2);
return v1;
}

original_code:
int spacemouse_monitor_open(void)
{
  int fd;
  if (!udev_monitor) {
    if (!udev)
      udev = udev_new();
    udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
    udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "input",
                                                    ((void *)0));
    udev_monitor_enable_receiving(udev_monitor);
  }
  fd = udev_monitor_get_fd(udev_monitor);
  if (fd < 0)
    return -(*__errno_location ());
  fcntl(fd, 4, fcntl(fd, 3) & ~04000);
  return fd;
}

canonical_original_code:
int spacemouse_monitor_open()
{
  int fd;
  if (!udev_monitor) {
    if (!udev)
      udev = udev_new();
    udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
    udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "input",
                                                    ((void *)0));
    udev_monitor_enable_receiving(udev_monitor);
  }
  fd = udev_monitor_get_fd(udev_monitor);
  if (fd < 0)
    return -(*__errno_location ());
  fcntl(fd, 4, fcntl(fd, 3) & ~04000);
  return fd;
}

variable_types: fd int


decompiled_code:
__int64 spacemouse_monitor_close()
{
if ( udev_monitor )
udev_monitor_unref();
if ( udev )
udev_unref(udev);
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
if ( udev_monitor )
udev_monitor_unref();
if ( udev )
udev_unref(udev);
return 0LL;
}

original_code:
int spacemouse_monitor_close(void)
{
  if (udev_monitor)
    udev_monitor_unref(udev_monitor);
  if (udev)
    udev_unref(udev);
  return 0;
}

canonical_original_code:
int spacemouse_monitor_close()
{
  if (udev_monitor)
    udev_monitor_unref(udev_monitor);
  if (udev)
    udev_unref(udev);
  return 0;
}


decompiled_code:
int __fastcall spacemouse_device_open(__int64 a1)
{
int result; // eax

result = open(*(const char **)(a1 + 16), 2);
if ( result == -1 )
{
result = open(*(const char **)(a1 + 16), 0);
if ( result == -1 )
return -*_errno_location();
}
*(_DWORD *)(a1 + 4) = result;
return result;
}

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

result = open(*(const char **)(a1 + 16), 2);
if ( result == -1 )
{
result = open(*(const char **)(a1 + 16), 0);
if ( result == -1 )
return -*_errno_location();
}
*(_DWORD *)(a1 + 4) = result;
return result;
}

original_code:
int spacemouse_device_open(struct spacemouse *mouse)
{
  int fd;
  if ((fd = open(mouse->devnode, 02)) == -1) {
     if ((fd = open(mouse->devnode, 00)) == -1) {
      return -(*__errno_location ());
    }
  }
  return (mouse->fd = fd);
}


decompiled_code:
__int64 __fastcall spacemouse_device_set_grab(__int64 a1, unsigned int a2)
{
if ( a2 > 1 )
return 0LL;
if ( ioctl(*(_DWORD *)(a1 + 4), 0x40044590uLL, a2 & 1) == -1 )
return (unsigned int)-*_errno_location();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
if ( a2 > 1 )
return 0LL;
if ( ioctl(*(_DWORD *)(a1 + 4), 0x40044590uLL, a2 & 1) == -1 )
return (unsigned int)-*_errno_location();
return 0LL;
}

original_code:
int spacemouse_device_set_grab(struct spacemouse *mouse, int grab)
{
  if (grab == 0 || grab == 1)
    if (ioctl(mouse->fd, (((1U) << (((0 +8)+8)+14)) | ((('E')) << (0 +8)) | (((0x90)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), grab ? (void *)1 : (void *)0) == -1)
      return -(*__errno_location ());
    return 0;
  return -22;
}

variable_types: grab int


decompiled_code:
unsigned __int64 __fastcall spacemouse_device_get_led(__int64 a1)
{
int v1; // edi
unsigned __int64 result; // rax
unsigned __int64 v3; // [rsp+8h] [rbp-10h] BYREF

v1 = *(_DWORD *)(a1 + 4);
v3 = 0LL;
if ( ioctl(v1, 0x800F4519uLL, &v3) == -1 )
result = (unsigned int)-*_errno_location();
else
result = (v3 >> 8) & 1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(__int64 a1)
{
int v1; // edi
unsigned __int64 result; // rax
unsigned __int64 v3; // [rsp+8h] [rbp-10h] BYREF

v1 = *(_DWORD *)(a1 + 4);
v3 = 0LL;
if ( ioctl(v1, 0x800F4519uLL, &v3) == -1 )
result = (unsigned int)-*_errno_location();
else
result = (v3 >> 8) & 1;
return result;
}

variable_types:
bits
unsigned long [-1]


decompiled_code:
int __fastcall spacemouse_device_close(__int64 a1)
{
int result; // eax

result = close(*(_DWORD *)(a1 + 4));
*(_DWORD *)(a1 + 4) = -1;
if ( result == -1 )
result = -*_errno_location();
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
int result; // eax

result = close(*(_DWORD *)(a1 + 4));
*(_DWORD *)(a1 + 4) = -1;
if ( result == -1 )
result = -*_errno_location();
return result;
}

original_code:
int spacemouse_device_close(struct spacemouse *mouse)
{
  int ret = close(mouse->fd);
  mouse->fd = -1;
  return ret == -1 ? -(*__errno_location ()) : ret;
}

variable_types: ret int


main

canonical_name: main

repo: poomon/obcpufreq

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax

puts("<?xml version='1.0' encoding='UTF-8'?>\n<openbox_pipe_menu>");
v3 = count_cpus("<?xml version='1.0' encoding='UTF-8'?>\n<openbox_pipe_menu>", argv);
print_cpu(0LL, v3);
puts("</openbox_pipe_menu>");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax

puts("<?xml version='1.0' encoding='UTF-8'?>\n<openbox_pipe_menu>");
v3 = func7("<?xml version='1.0' encoding='UTF-8'?>\n<openbox_pipe_menu>", argv);
func9(0LL, v3);
puts("</openbox_pipe_menu>");
return 0;
}

original_code:
int main(int argc, char** argv)
{
    printf("<?xml version='1.0' encoding='UTF-8'?>\n<openbox_pipe_menu>\n");
    print_cpu(0, count_cpus());
    printf("</openbox_pipe_menu>\n");
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    printf("<?xml version='1.0' encoding='UTF-8'?>\n<openbox_pipe_menu>\n");
    print_cpu(0, count_cpus());
    printf("</openbox_pipe_menu>\n");
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
int __fastcall get_human_speed(char *a1, unsigned __int64 a2)
{
int result; // eax

if ( a2 <= 0xF4240 )
{
if ( a2 <= 0x186A0 )
{
if ( a2 <= 0x3E8 )
{
result = snprintf(a1, 0x14uLL, "%lu kHz", a2);
}
else
{
if ( a2
- 20 * (a2 / 0x64 + (((0x28F5C28F5C28F5C3LL * (unsigned __int128)(a2 >> 2)) >> 64) & 0xFFFFFFFFFFFFFFFCLL)) > 0x31 )
a2 += 100LL;
result = snprintf(a1, 0x14uLL, "%u.%01u MHz", (unsigned int)a2 / 0x3E8uLL, a2 % 0x3E8 / 0x64);
}
}
else
{
if ( a2 % 0x3E8 > 0x1F3 )
LODWORD(a2) = a2 + 1000;
result = snprintf(a1, 0x14uLL, "%u MHz", (unsigned int)a2 / 0x3E8uLL);
}
}
else
{
if ( a2 % 0x2710 > 0x1387 )
a2 += 10000LL;
result = snprintf(a1, 0x14uLL, "%u.%02u GHz", (unsigned int)a2 / 0xF4240uLL, a2 % 0xF4240 / 0x2710);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(char *a1, unsigned __int64 a2)
{
int result; // eax

if ( a2 <= 0xF4240 )
{
if ( a2 <= 0x186A0 )
{
if ( a2 <= 0x3E8 )
{
result = snprintf(a1, 0x14uLL, "%lu kHz", a2);
}
else
{
if ( a2
- 20 * (a2 / 0x64 + (((0x28F5C28F5C28F5C3LL * (unsigned __int128)(a2 >> 2)) >> 64) & 0xFFFFFFFFFFFFFFFCLL)) > 0x31 )
a2 += 100LL;
result = snprintf(a1, 0x14uLL, "%u.%01u MHz", (unsigned int)a2 / 0x3E8uLL, a2 % 0x3E8 / 0x64);
}
}
else
{
if ( a2 % 0x3E8 > 0x1F3 )
LODWORD(a2) = a2 + 1000;
result = snprintf(a1, 0x14uLL, "%u MHz", (unsigned int)a2 / 0x3E8uLL);
}
}
else
{
if ( a2 % 0x2710 > 0x1387 )
a2 += 10000LL;
result = snprintf(a1, 0x14uLL, "%u.%02u GHz", (unsigned int)a2 / 0xF4240uLL, a2 % 0xF4240 / 0x2710);
}
return result;
}

original_code:
void get_human_speed(char* dest, unsigned long speed)
{
    unsigned long tmp;
    if (speed > 1000000) {
        tmp = speed % 10000;
        if (tmp >= 5000)
            speed += 10000;
        snprintf (dest, 20, "%u.%02u GHz", ((unsigned int) speed/1000000),
            ((unsigned int) (speed%1000000)/10000));
    } else if (speed > 100000) {
        tmp = speed % 1000;
        if (tmp >= 500)
            speed += 1000;
        snprintf (dest, 20, "%u MHz", ((unsigned int) speed / 1000));
    } else if (speed > 1000) {
        tmp = speed % 100;
        if (tmp >= 50)
            speed += 100;
        snprintf (dest, 20, "%u.%01u MHz", ((unsigned int) speed/1000),
            ((unsigned int) (speed%1000)/100));
    } else
        snprintf (dest, 20, "%lu kHz", speed);
    return;
}

canonical_original_code:
void get_human_speed(char *dest, unsigned long speed)
{
    unsigned long tmp;
    if (speed > 1000000) {
        tmp = speed % 10000;
        if (tmp >= 5000)
            speed += 10000;
        snprintf (dest, 20, "%u.%02u GHz", ((unsigned int) speed/1000000),
            ((unsigned int) (speed%1000000)/10000));
    } else if (speed > 100000) {
        tmp = speed % 1000;
        if (tmp >= 500)
            speed += 1000;
        snprintf (dest, 20, "%u MHz", ((unsigned int) speed / 1000));
    } else if (speed > 1000) {
        tmp = speed % 100;
        if (tmp >= 50)
            speed += 100;
        snprintf (dest, 20, "%u.%01u MHz", ((unsigned int) speed/1000),
            ((unsigned int) (speed%1000)/100));
    } else
        snprintf (dest, 20, "%lu kHz", speed);
    return;
}

variable_types:
dest
char *

variable_types:
speed
unsigned long

variable_types:
tmp
unsigned long


decompiled_code:
void __fastcall print_cpu(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er12
struct cpufreq_policy *v3; // rbp
struct cpufreq_available_governors *v4; // r12
const char *v5; // rsi
const char *v6; // r15
struct cpufreq_available_frequencies *v7; // r15
unsigned int v8; // er12
__int64 v9; // r8
unsigned __int64 v10; // r14
unsigned __int64 v11; // rdx
unsigned __int64 v12; // [rsp+8h] [rbp-A0h]
char v13[32]; // [rsp+10h] [rbp-98h] BYREF
__int16 v14[16]; // [rsp+30h] [rbp-78h] BYREF
char v15[88]; // [rsp+50h] [rbp-58h] BYREF

v2 = a1 + 1;
if ( a1 + 1 == a2 )
{
printf("<item label='cpu %u'/>\n", a1);
}
else if ( v2 < a2 )
{
printf("<menu label='cpu %u' id='obcpufreq-cpu%u'>\n", a1, v2);
print_cpu(v2, a2);
puts("</menu>");
}
puts(" <separator/>");
v12 = cpufreq_get_freq_kernel(a1);
v3 = cpufreq_get_policy(a1);
v4 = cpufreq_get_available_governors(a1);
if ( v4 )
{
printf("<menu label='governors' id='obcpufreq-governors%u'>\n", a1);
do
{
v5 = v3->governor;
v14[0] = 32;
v6 = v4->governor;
if ( !strcmp(v4->governor, v5) )
{
LOBYTE(v14[0]) = 42;
v6 = v4->governor;
}
printf(
" <item label='%s%s'><action name='Execute'><command>sudo -n cpufreq-set --cpu %u -g %s</command></action></item>\n",
(const char *)v14,
v6,
a1,
v6);
v4 = v4->next;
}
while ( v4 );
puts("</menu>");
cpufreq_put_available_governors(0LL);
}
else
{
printf("<item label='%s'/>\n", "no available governors");
}
puts(" <separator/>");
v7 = cpufreq_get_available_frequencies(a1);
if ( v7 )
{
v8 = 0;
do
{
v10 = v7->frequency;
get_human_speed(v13, v7->frequency);
v14[0] = 32;
if ( v12 == v10 )
LOBYTE(v14[0]) = 42;
v15[0] = 0;
if ( v3 )
{
v11 = v3->min;
if ( v3->max == v10 )
{
if ( v11 == v10 )
strcpy(v15, " (max,min)");
else
strcpy(v15, " (max)");
}
else if ( v11 == v10 )
{
strcpy(v15, " (min)");
}
}
v9 = v8++;
printf(
"<menu label='%s%s%s' id='obcpufreq-freq%d'>\n"
" <item label='set as max'><action name='Execute'><command>sudo -n cpufreq-set --cpu %u --max %lu</command></act"
"ion></item>\n"
" <item label='set as min'><action name='Execute'><command>sudo -n cpufreq-set --cpu %u --min %lu</command></act"
"ion></item>\n"
"</menu>\n",
(const char *)v14,
v13,
v15,
v9,
a1,
v7->frequency,
a1,
v7->frequency);
v7 = v7->next;
}
while ( v7 );
cpufreq_put_available_frequencies(0LL);
}
else
{
printf("<item label='%s'/>\n", "no available freqs");
}
cpufreq_put_policy(v3);
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er12
struct cpufreq_policy *v3; // rbp
struct cpufreq_available_governors *v4; // r12
const char *v5; // rsi
const char *v6; // r15
struct cpufreq_available_frequencies *v7; // r15
unsigned int v8; // er12
__int64 v9; // r8
unsigned __int64 v10; // r14
unsigned __int64 v11; // rdx
unsigned __int64 v12; // [rsp+8h] [rbp-A0h]
char v13[32]; // [rsp+10h] [rbp-98h] BYREF
__int16 v14[16]; // [rsp+30h] [rbp-78h] BYREF
char v15[88]; // [rsp+50h] [rbp-58h] BYREF

v2 = a1 + 1;
if ( a1 + 1 == a2 )
{
printf("<item label='cpu %u'/>\n", a1);
}
else if ( v2 < a2 )
{
printf("<menu label='cpu %u' id='obcpufreq-cpu%u'>\n", a1, v2);
func9(v2, a2);
puts("</menu>");
}
puts(" <separator/>");
v12 = cpufreq_get_freq_kernel(a1);
v3 = cpufreq_get_policy(a1);
v4 = cpufreq_get_available_governors(a1);
if ( v4 )
{
printf("<menu label='governors' id='obcpufreq-governors%u'>\n", a1);
do
{
v5 = v3->governor;
v14[0] = 32;
v6 = v4->governor;
if ( !strcmp(v4->governor, v5) )
{
LOBYTE(v14[0]) = 42;
v6 = v4->governor;
}
printf(
" <item label='%s%s'><action name='Execute'><command>sudo -n cpufreq-set --cpu %u -g %s</command></action></item>\n",
(const char *)v14,
v6,
a1,
v6);
v4 = v4->next;
}
while ( v4 );
puts("</menu>");
cpufreq_put_available_governors(0LL);
}
else
{
printf("<item label='%s'/>\n", "no available governors");
}
puts(" <separator/>");
v7 = cpufreq_get_available_frequencies(a1);
if ( v7 )
{
v8 = 0;
do
{
v10 = v7->frequency;
func8(v13, v7->frequency);
v14[0] = 32;
if ( v12 == v10 )
LOBYTE(v14[0]) = 42;
v15[0] = 0;
if ( v3 )
{
v11 = v3->min;
if ( v3->max == v10 )
{
if ( v11 == v10 )
strcpy(v15, " (max,min)");
else
strcpy(v15, " (max)");
}
else if ( v11 == v10 )
{
strcpy(v15, " (min)");
}
}
v9 = v8++;
printf(
"<menu label='%s%s%s' id='obcpufreq-freq%d'>\n"
" <item label='set as max'><action name='Execute'><command>sudo -n cpufreq-set --cpu %u --max %lu</command></act"
"ion></item>\n"
" <item label='set as min'><action name='Execute'><command>sudo -n cpufreq-set --cpu %u --min %lu</command></act"
"ion></item>\n"
"</menu>\n",
(const char *)v14,
v13,
v15,
v9,
a1,
v7->frequency,
a1,
v7->frequency);
v7 = v7->next;
}
while ( v7 );
cpufreq_put_available_frequencies(0LL);
}
else
{
printf("<item label='%s'/>\n", "no available freqs");
}
cpufreq_put_policy(v3);
}

original_code:
void print_cpu(unsigned int cpu, unsigned int n_cpus)
{
    int i;
    char str[20];
    char premark[20];
    char postmark[20];
    unsigned long curfreq, freq;
    struct cpufreq_available_frequencies* freqs;
    struct cpufreq_available_governors* govs;
    struct cpufreq_policy* policy;
    if (cpu + 1 == n_cpus)
        printf("<item label='cpu %u'/>\n", cpu);
    else if (cpu + 1 < n_cpus)
    {
        printf("<menu label='cpu %u' id='obcpufreq-cpu%u'>\n", cpu, cpu + 1);
        print_cpu(cpu + 1, n_cpus);
        printf("</menu>\n");
    }
    printf(" <separator/>\n");
    curfreq = cpufreq_get_freq_kernel(cpu);
    policy = cpufreq_get_policy(cpu);
    govs = cpufreq_get_available_governors(cpu);
    if (govs)
    {
        printf("<menu label='governors' id='obcpufreq-governors%u'>\n", cpu);
        for (; govs; govs = govs->next)
        {
            premark[0] = ' ';
            premark[1] = '\0';
            if (!strcmp(govs->governor, policy->governor))
                premark[0] = '*';
            printf("  <item label='%s%s'><action name='Execute'><command>"
                   "sudo -n cpufreq-set" " --cpu %u -g %s</command></action></item>\n",
                   premark, govs->governor,
                   cpu, govs->governor);
        }
        printf("</menu>\n");
        cpufreq_put_available_governors(govs);
    }
    else
        printf("<item label='%s'/>\n", "no available governors");
    printf(" <separator/>\n");
    freqs = cpufreq_get_available_frequencies(cpu);
    if (freqs)
    {
        for (i = 0; freqs; freqs = freqs->next, i++)
        {
            freq = freqs->frequency;
            get_human_speed(str, freq);
            premark[0] = ' ';
            premark[1] = '\0';
            if (freq == curfreq)
                premark[0] = '*';
            postmark[0] = '\0';
            if (policy)
            {
                if (freq == policy->max && freq == policy->min)
                    strcpy(postmark, " (max,min)");
                else if (freq == policy->max)
                    strcpy(postmark, " (max)");
                else if (freq == policy->min)
                    strcpy(postmark, " (min)");
            }
            printf("<menu label='%s%s%s' id='obcpufreq-freq%d'>\n"
                   "  <item label='set as max'><action name='Execute'><command>"
                       "sudo -n cpufreq-set" " --cpu %u --max %lu</command></action></item>\n"
                   "  <item label='set as min'><action name='Execute'><command>"
                       "sudo -n cpufreq-set" " --cpu %u --min %lu</command></action></item>\n</menu>\n",
                   premark, str, postmark, i,
                   cpu, freqs->frequency,
                   cpu, freqs->frequency);
        }
        cpufreq_put_available_frequencies(freqs);
    }
    else
        printf("<item label='%s'/>\n", "no available freqs");
    cpufreq_put_policy(policy);
    return;
}

canonical_original_code:
void print_cpu(unsigned int cpu, unsigned int n_cpus)
{
    int i;
    char str[20];
    char premark[20];
    char postmark[20];
    unsigned long curfreq; unsigned long freq;
    struct cpufreq_available_frequencies *freqs;
    struct cpufreq_available_governors *govs;
    struct cpufreq_policy *policy;
    if (cpu + 1 == n_cpus)
        printf("<item label='cpu %u'/>\n", cpu);
    else if (cpu + 1 < n_cpus)
    {
        printf("<menu label='cpu %u' id='obcpufreq-cpu%u'>\n", cpu, cpu + 1);
        print_cpu(cpu + 1, n_cpus);
        printf("</menu>\n");
    }
    printf(" <separator/>\n");
    curfreq = cpufreq_get_freq_kernel(cpu);
    policy = cpufreq_get_policy(cpu);
    govs = cpufreq_get_available_governors(cpu);
    if (govs)
    {
        printf("<menu label='governors' id='obcpufreq-governors%u'>\n", cpu);
        for (; govs; govs = govs->next)
        {
            premark[0] = ' ';
            premark[1] = '\0';
            if (!strcmp(govs->governor, policy->governor))
                premark[0] = '*';
            printf("  <item label='%s%s'><action name='Execute'><command>"
                   "sudo -n cpufreq-set" " --cpu %u -g %s</command></action></item>\n",
                   premark, govs->governor,
                   cpu, govs->governor);
        }
        printf("</menu>\n");
        cpufreq_put_available_governors(govs);
    }
    else
        printf("<item label='%s'/>\n", "no available governors");
    printf(" <separator/>\n");
    freqs = cpufreq_get_available_frequencies(cpu);
    if (freqs)
    {
        for (i = 0; freqs; freqs = freqs->next, i++)
        {
            freq = freqs->frequency;
            get_human_speed(str, freq);
            premark[0] = ' ';
            premark[1] = '\0';
            if (freq == curfreq)
                premark[0] = '*';
            postmark[0] = '\0';
            if (policy)
            {
                if (freq == policy->max && freq == policy->min)
                    strcpy(postmark, " (max,min)");
                else if (freq == policy->max)
                    strcpy(postmark, " (max)");
                else if (freq == policy->min)
                    strcpy(postmark, " (min)");
            }
            printf("<menu label='%s%s%s' id='obcpufreq-freq%d'>\n"
                   "  <item label='set as max'><action name='Execute'><command>"
                       "sudo -n cpufreq-set" " --cpu %u --max %lu</command></action></item>\n"
                   "  <item label='set as min'><action name='Execute'><command>"
                       "sudo -n cpufreq-set" " --cpu %u --min %lu</command></action></item>\n</menu>\n",
                   premark, str, postmark, i,
                   cpu, freqs->frequency,
                   cpu, freqs->frequency);
        }
        cpufreq_put_available_frequencies(freqs);
    }
    else
        printf("<item label='%s'/>\n", "no available freqs");
    cpufreq_put_policy(policy);
    return;
}

variable_types:
cpu
unsigned int

variable_types: i int

variable_types:
str
char [20]

variable_types:
premark
char [20]

variable_types:
postmark
char [20]

variable_types:
curfreq
unsigned long

variable_types:
freq
unsigned long

variable_types: struct cpufreq_available_frequencies { unsigned long frequency; struct cpufreq_available_frequencies *next; struct cpufreq_available_frequencies *first; } *

variable_types: struct cpufreq_available_governors { char *governor; struct cpufreq_available_governors *next; struct cpufreq_available_governors *first; } *

variable_types: struct cpufreq_policy { unsigned long min; unsigned long max; char *governor; } *


decompiled_code:
_BOOL8 __fastcall ctype_digit(int a1)
{
return (unsigned int)(a1 - 48) <= 9;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1)
{
return (unsigned int)(a1 - 48) <= 9;
}

original_code: static inline int ctype_digit(int c) { return c>='0' && c<='9'; }

variable_types: c int


decompiled_code:
_BOOL8 __fastcall ctype_alpha(int a1)
{
return (a1 & 0xFFFFFFDF) - 65 <= 0x19;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1)
{
return (a1 & 0xFFFFFFDF) - 65 <= 0x19;
}

original_code:
static inline int ctype_alpha(int c) {
  return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}


canonical_original_code:
static enum adns_status mkquery_header(struct adns__state *ads, struct vbuf *vb, int *id_r, int qdlen) {
  int id;
  unsigned char *rqp;
  if (!adns__vbuf_ensure(vb,12 +qdlen+4)) return adns_s_nomemory;
  vb->used= 0;
  (rqp= (vb)->buf+(vb)->used);
  *id_r= id= (ads->nextid++) & 0x0ffff;
  (*rqp++= (((id)>>8)&0x0ff), *rqp++= ((id)&0x0ff));
  *rqp++= (0x01);
  *rqp++= (0x00);
  (*rqp++= (((1)>>8)&0x0ff), *rqp++= ((1)&0x0ff));
  (*rqp++= (((0)>>8)&0x0ff), *rqp++= ((0)&0x0ff));
  (*rqp++= (((0)>>8)&0x0ff), *rqp++= ((0)&0x0ff));
  (*rqp++= (((0)>>8)&0x0ff), *rqp++= ((0)&0x0ff));
  ((vb)->used= rqp-(vb)->buf);
  return adns_s_ok;
}

variable_types: struct adns__state { enum adns_initflags { adns_if_none=0, adns_if_noenv=1, adns_if_noerrprint=2, adns_if_noserverwarn=4, adns_if_debug=8, adns_if_logpid=128, adns_if_noautosys=16, adns_if_eintr=32, adns_if_nosigpipe=64, adns_if_checkc_entex=256, adns_if_checkc_freq=768 } iflags; void (*logfn)(struct adns__state *ads, void *logfndata, char *fmt, __builtin_va_list al); void *logfndata; int configerrno; struct query_queue { struct adns__query { struct adns__state *ads; enum { query_tosend=0, query_tcpw=1, query_childw=2, query_done=3 } state; struct adns__query *back; struct { struct adns__query *head; } children; struct { struct adns__query *back; } siblings; struct { struct allocnode { struct allocnode *next; } *head; } allocations; int interim_allocd; void *final_allocspace; struct typeinfo { enum adns_rrtype { adns_rrt_typemask=65535, adns__qtf_deref=65536, adns__qtf_mail822=131072, adns_r_unknown=262144, adns_r_none=0, adns_r_a=1, adns_r_ns_raw=2, adns_r_ns=expr, adns_r_cname=5, adns_r_soa_raw=6, adns_r_soa=expr, adns_r_ptr_raw=12, adns_r_ptr=expr, adns_r_hinfo=13, adns_r_mx_raw=15, adns_r_mx=expr, adns_r_txt=16, adns_r_rp_raw=17, adns_r_rp=expr, adns_r_srv_raw=33, adns_r_srv=expr, adns_r_addr=expr } typekey; char *rrtname; char *fmtname; int rrsz; void (*makefinal)(struct adns__query *qu, void *data); enum adns_status { adns_s_ok=0, adns_s_nomemory=1, adns_s_unknownrrtype=2, adns_s_systemfail=3, adns_s_max_localfail=29, adns_s_timeout=30, adns_s_allservfail=31, adns_s_norecurse=32, adns_s_invalidresponse=33, adns_s_unknownformat=34, adns_s_max_remotefail=59, adns_s_rcodeservfail=60, adns_s_rcodeformaterror=61, adns_s_rcodenotimplemented=62, adns_s_rcoderefused=63, adns_s_rcodeunknown=64, adns_s_max_tempfail=99, adns_s_inconsistent=100, adns_s_prohibitedcname=101, adns_s_answerdomaininvalid=102, adns_s_answerdomaintoolong=103, adns_s_invaliddata=104, adns_s_max_misconfig=199, adns_s_querydomainwrong=200, adns_s_querydomaininvalid=201, adns_s_querydomaintoolong=202, adns_s_max_misquery=299, adns_s_nxdomain=300, adns_s_nodata=301, adns_s_max_permfail=499 } (*convstring)(struct vbuf { int used; unsigned char *buf; } *vb, void *data); enum adns_status { adns_s_ok=0, adns_s_nomemory=1, adns_s_unknownrrtype=2, adns_s_systemfail=3, adns_s_max_localfail=29, adns_s_timeout=30, adns_s_allservfail=31, adns_s_norecurse=32, adns_s_invalidresponse=33, adns_s_unknownformat=34, adns_s_max_remotefail=59, adns_s_rcodeservfail=60, adns_s_rcodeformaterror=61, adns_s_rcodenotimplemented=62, adns_s_rcoderefused=63, adns_s_rcodeunknown=64, adns_s_max_tempfail=99, adns_s_inconsistent=100, adns_s_prohibitedcname=101, adns_s_answerdomaininvalid=102, adns_s_answerdomaintoolong=103, adns_s_invaliddata=104, adns_s_max_misconfig=199, adns_s_querydomainwrong=200, adns_s_querydomaininvalid=201, adns_s_querydomaintoolong=202, adns_s_max_misquery=299, adns_s_nxdomain=300, adns_s_nodata=301, adns_s_max_permfail=499 } (*parse)(struct parseinfo { struct adns__state *ads; struct adns__query *qu; int serv; unsigned char *dgram; int dglen; struct timeval { long tv_sec; long tv_usec; } now; } *pai, int cbyte, int max, void *store_r); int (*diff_needswap)(struct adns__state *ads, void *datap_a, void *datap_b); enum adns_status { adns_s_ok=0, adns_s_nomemory=1, adns_s_unknownrrtype=2, adns_s_systemfail=3, adns_s_max_localfail=29, adns_s_timeout=30, adns_s_allservfail=31, adns_s_norecurse=32, adns_s_invalidresponse=33, adns_s_unknownformat=34, adns_s_max_remotefail=59, adns_s_rcodeservfail=60, adns_s_rcodeformaterror=61, adns_s_rcodenotimplemented=62, adns_s_rcoderefused=63, adns_s_rcodeunknown=64, adns_s_max_tempfail=99, adns_s_inconsistent=100, adns_s_prohibitedcname=101, adns_s_answerdomaininvalid=102, adns_s_answerdomaintoolong=103, adns_s_invaliddata=104, adns_s_max_misconfig=199, adns_s_querydomainwrong=200, adns_s_querydomaininvalid=201, adns_s_querydomaintoolong=202, adns_s_max_misquery=299, adns_s_nxdomain=300, adns_s_nodata=301, adns_s_max_permfail=499 } (*qdparselabel)(struct adns__state *ads, char **p_io, char *pe, int labelnum, char label_r[255], int *ll_io, enum adns_queryflags { adns_qf_none=0, adns_qf_search=1, adns_qf_usevc=2, adns_qf_owner=4, adns_qf_quoteok_query=16, adns_qf_quoteok_cname=0, adns_qf_quoteok_anshost=64, adns_qf_quotefail_cname=128, adns_qf_cname_loose=256, adns_qf_cname_forbid=512, adns__qf_internalmask=267386880 } flags, struct typeinfo *typei); void (*postsort)(struct adns__state *ads, void *array, int nrrs, struct typeinfo *typei); } *typei; unsigned char *query_dgram; int query_dglen; struct vbuf vb; struct adns_answer { enum adns_status { adns_s_ok=0, adns_s_nomemory=1, adns_s_unknownrrtype=2, adns_s_systemfail=3, adns_s_max_localfail=29, adns_s_timeout=30, adns_s_allservfail=31, adns_s_norecurse=32, adns_s_invalidresponse=33, adns_s_unknownformat=34, adns_s_max_remotefail=59, adns_s_rcodeservfail=60, adns_s_rcodeformaterror=61, adns_s_rcodenotimplemented=62, adns_s_rcoderefused=63, adns_s_rcodeunknown=64, adns_s_max_tempfail=99, adns_s_inconsistent=100, adns_s_prohibitedcname=101, adns_s_answerdomaininvalid=102, adns_s_answerdomaintoolong=103, adns_s_invaliddata=104, adns_s_max_misconfig=199, adns_s_querydomainwrong=200, adns_s_querydomaininvalid=201, adns_s_querydomaintoolong=202, adns_s_max_misquery=299, adns_s_nxdomain=300, adns_s_nodata=301, adns_s_max_permfail=499 } status; char *cname; char *owner; enum adns_rrtype { adns_rrt_typemask=65535, adns__qtf_deref=65536, adns__qtf_mail822=131072, adns_r_unknown=262144, adns_r_none=0, adns_r_a=1, adns_r_ns_raw=2, adns_r_ns=expr, adns_r_cname=5, adns_r_soa_raw=6, adns_r_soa=expr, adns_r_ptr_raw=12, adns_r_ptr=expr, adns_r_hinfo=13, adns_r_mx_raw=15, adns_r_mx=expr, adns_r_txt=16, adns_r_rp_raw=17, adns_r_rp=expr, adns_r_srv_raw=33, adns_r_srv=expr, adns_r_addr=expr } type; long expires; int nrrs; union { void *untyped; unsigned char *bytes; char **str; struct adns_rr_intstr { int i; char *str; } **manyistr; struct adns_rr_addr { int len; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } sa; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } inet; } addr; } *addr; struct in_addr *inaddr; struct adns_rr_hostaddr { char *host; enum adns_status { adns_s_ok=0, adns_s_nomemory=1, adns_s_unknownrrtype=2, adns_s_systemfail=3, adns_s_max_localfail=29, adns_s_timeout=30, adns_s_allservfail=31, adns_s_norecurse=32, adns_s_invalidresponse=33, adns_s_unknownformat=34, adns_s_max_remotefail=59, adns_s_rcodeservfail=60, adns_s_rcodeformaterror=61, adns_s_rcodenotimplemented=62, adns_s_rcoderefused=63, adns_s_rcodeunknown=64, adns_s_max_tempfail=99, adns_s_inconsistent=100, adns_s_prohibitedcname=101, adns_s_answerdomaininvalid=102, adns_s_answerdomaintoolong=103, adns_s_invaliddata=104, adns_s_max_misconfig=199, adns_s_querydomainwrong=200, adns_s_querydomaininvalid=201, adns_s_querydomaintoolong=202, adns_s_max_misquery=299, adns_s_nxdomain=300, adns_s_nodata=301, adns_s_max_permfail=499 } astatus; int naddrs; struct adns_rr_addr *addrs; } *hostaddr; struct adns_rr_intstrpair { struct adns_rr_intstr array[2]; } *intstrpair; struct adns_rr_strpair { char *array[2]; } *strpair; struct adns_rr_inthostaddr { int i; struct adns_rr_hostaddr ha; } *inthostaddr; struct adns_rr_intstr *intstr; struct adns_rr_soa { char *mname; unsigned long serial; } *soa; struct adns_rr_srvraw { int priority; char *host; } *srvraw; struct adns_rr_srvha { int priority; struct adns_rr_hostaddr ha; } *srvha; struct adns_rr_byteblock { int len; unsigned char *data; } *byteblock; } rrs; } *answer; unsigned char *cname_dgram; int cname_dglen; struct vbuf search_vb; int search_origlen; int id; int udpnextserver; unsigned long udpsent; struct timeval timeout; long expires; struct qcontext { void *ext; void (*callback)(struct adns__query *parent, struct adns__query *child); union { struct adns_rr_addr ptr_parent_addr; struct adns_rr_hostaddr *hostaddr; } info; } ctx; } *head; } udpw; struct adns__query *forallnext; int nextid; struct vbuf tcpsend; int nservers; enum adns__tcpstate { server_disconnected=0, server_connecting=1, server_ok=2, server_broken=3 } tcpstate; struct timeval tcptimeout; struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); } stdsigpipe; struct __sigset_t stdsigmask; struct pollfd { int fd; short events; short revents; } pollfds_buf[2]; struct server { struct in_addr addr; } servers[5]; struct sortlist { struct in_addr base; } sortlist[15]; char **searchlist; unsigned short rand48xsubi[3]; } *

variable_types:
vb
struct vbuf *

variable_types: qdlen int

variable_types: id int

variable_types:
rqp
unsigned char *

user_defined_types: struct adns__state { enum adns_initflags iflags; void (*logfn)(struct adns__state *ads, void *logfndata, char *fmt, __builtin_va_list al); void *logfndata; int configerrno; struct query_queue udpw; struct adns__query *forallnext; int nextid; struct vbuf tcpsend; int nservers; enum adns__tcpstate tcpstate; struct timeval tcptimeout; struct sigaction stdsigpipe; struct __sigset_t stdsigmask; struct pollfd pollfds_buf[2]; struct server servers[5]; struct sortlist sortlist[15]; char **searchlist; unsigned short rand48xsubi[3]; }

user_defined_types: struct query_queue { struct adns__query *head; }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct adns__query { struct adns__state *ads; enum { query_tosend=0, query_tcpw=1, query_childw=2, query_done=3 } state; struct adns__query *back; struct { struct adns__query *head; } children; struct { struct adns__query *back; } siblings; struct { struct allocnode *head; } allocations; int interim_allocd; void *final_allocspace; struct typeinfo *typei; unsigned char *query_dgram; int query_dglen; struct vbuf vb; struct adns_answer *answer; unsigned char *cname_dgram; int cname_dglen; struct vbuf search_vb; int search_origlen; int id; int udpnextserver; unsigned long udpsent; struct timeval timeout; long expires; struct qcontext ctx; }

user_defined_types: struct typeinfo { enum adns_rrtype typekey; char *rrtname; char *fmtname; int rrsz; void (*makefinal)(struct adns__query *qu, void *data); enum adns_status (*convstring)(struct vbuf *vb, void *data); enum adns_status (*parse)(struct parseinfo *pai, int cbyte, int max, void *store_r); int (*diff_needswap)(struct adns__state *ads, void *datap_a, void *datap_b); enum adns_status (*qdparselabel)(struct adns__state *ads, char **p_io, char *pe, int labelnum, char label_r[255], int *ll_io, enum adns_queryflags flags, struct typeinfo *typei); void (*postsort)(struct adns__state *ads, void *array, int nrrs, struct typeinfo *typei); }

user_defined_types: struct adns_answer { enum adns_status status; char *cname; char *owner; enum adns_rrtype type; long expires; int nrrs; union { void *untyped; unsigned char *bytes; char **str; struct adns_rr_intstr **manyistr; struct adns_rr_addr *addr; struct in_addr *inaddr; struct adns_rr_hostaddr *hostaddr; struct adns_rr_intstrpair *intstrpair; struct adns_rr_strpair *strpair; struct adns_rr_inthostaddr *inthostaddr; struct adns_rr_intstr *intstr; struct adns_rr_soa *soa; struct adns_rr_srvraw *srvraw; struct adns_rr_srvha *srvha; struct adns_rr_byteblock *byteblock; } rrs; }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }

user_defined_types: struct adns_rr_addr { int len; union { struct sockaddr sa; struct sockaddr_in inet; } addr; }

user_defined_types: struct adns_rr_hostaddr { char *host; enum adns_status astatus; int naddrs; struct adns_rr_addr *addrs; }

user_defined_types: struct parseinfo { struct adns__state *ads; struct adns__query *qu; int serv; unsigned char *dgram; int dglen; struct timeval now; }


timevaladd

decompiled_code:
unsigned __int64 __fastcall timevaladd(_QWORD *a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // rdx
signed __int64 v4; // rsi

result = 1000 * (a2 / 0x3E8);
v3 = *a1 + a2 / 0x3E8;
v4 = a1[1] + 1000 * (a2 % 0x3E8);
if ( v4 > 999999 )
{
++v3;
v4 -= 1000000LL;
}
*a1 = v3;
a1[1] = v4;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(_QWORD *a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // rdx
signed __int64 v4; // rsi

result = 1000 * (a2 / 0x3E8);
v3 = *a1 + a2 / 0x3E8;
v4 = a1[1] + 1000 * (a2 % 0x3E8);
if ( v4 > 999999 )
{
++v3;
v4 -= 1000000LL;
}
*a1 = v3;
a1[1] = v4;
return result;
}

original_code:
static inline void timevaladd(struct timeval *tv_io, long ms) {
  struct timeval tmp;
  ((void) sizeof ((ms>=0) ? 1 : 0), __extension__ ({ if (ms>=0) ; else __assert_fail ("ms>=0", "tvarith.h", 32, __extension__ __PRETTY_FUNCTION__); }));
  tmp= *tv_io;
  tmp.tv_usec += (ms%1000)*1000;
  tmp.tv_sec += ms/1000;
  if (tmp.tv_usec >= 1000000) { tmp.tv_sec++; tmp.tv_usec -= 1000000; }
  *tv_io= tmp;
}

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

variable_types: ms long


original_code:
adns_status adns__qdpl_normal(adns_state ads,
         const char **p_io, const char *pe, int labelnum,
         char label_r[], int *ll_io,
         adns_queryflags flags,
         const typeinfo *typei) {
  int ll, c;
  const char *p;
  ll= 0;
  p= *p_io;
  while (p!=pe && (c= *p++)!='.') {
    if (c=='\\') {
      if (!(flags & adns_qf_quoteok_query)) return adns_s_querydomaininvalid;
      if (ctype_digit(p[0])) {
 if (p+1==pe || p+2==pe) return adns_s_querydomaininvalid;
 if (ctype_digit(p[1]) && ctype_digit(p[2])) {
   c= (*p++ - '0')*100;
   c += (*p++ - '0')*10;
   c += (*p++ - '0');
   if (c >= 256) return adns_s_querydomaininvalid;
 } else {
   return adns_s_querydomaininvalid;
 }
      } else if (!(c= *p++)) {
 return adns_s_querydomaininvalid;
      }
    }
    if (!(flags & adns_qf_quoteok_query)) {
      if (c == '-') {
 if (!ll) return adns_s_querydomaininvalid;
      } else if (!ctype_alpha(c) && !ctype_digit(c)) {
 return adns_s_querydomaininvalid;
      }
    }
    if (ll == *ll_io) return adns_s_querydomaininvalid;
    label_r[ll++]= c;
  }
  *p_io= p;
  *ll_io= ll;
  return adns_s_ok;
}

canonical_original_code:
enum adns_status adns__qdpl_normal(struct adns__state *ads, char **p_io, char *pe, int labelnum, char label_r[], int *ll_io, enum adns_queryflags flags, struct typeinfo *typei) {
  int ll; int c;
  char *p;
  ll= 0;
  p= *p_io;
  while (p!=pe && (c= *p++)!='.') {
    if (c=='\\') {
      if (!(flags & adns_qf_quoteok_query)) return adns_s_querydomaininvalid;
      if (ctype_digit(p[0])) {
 if (p+1==pe || p+2==pe) return adns_s_querydomaininvalid;
 if (ctype_digit(p[1]) && ctype_digit(p[2])) {
   c= (*p++ - '0')*100;
   c += (*p++ - '0')*10;
   c += (*p++ - '0');
   if (c >= 256) return adns_s_querydomaininvalid;
 } else {
   return adns_s_querydomaininvalid;
 }
      } else if (!(c= *p++)) {
 return adns_s_querydomaininvalid;
      }
    }
    if (!(flags & adns_qf_quoteok_query)) {
      if (c == '-') {
 if (!ll) return adns_s_querydomaininvalid;
      } else if (!ctype_alpha(c) && !ctype_digit(c)) {
 return adns_s_querydomaininvalid;
      }
    }
    if (ll == *ll_io) return adns_s_querydomaininvalid;
    label_r[ll++]= c;
  }
  *p_io= p;
  *ll_io= ll;
  return adns_s_ok;
}

variable_types:
pe
char *

variable_types: labelnum int

variable_types: enum adns_queryflags { adns_qf_none=0, adns_qf_search=1, adns_qf_usevc=2, adns_qf_owner=4, adns_qf_quoteok_query=16, adns_qf_quoteok_cname=0, adns_qf_quoteok_anshost=64, adns_qf_quotefail_cname=128, adns_qf_cname_loose=256, adns_qf_cname_forbid=512, adns__qf_internalmask=267386880 }

variable_types:
typei
struct typeinfo *

variable_types: ll int

variable_types:
p
char *

return_type: enum adns_status { adns_s_ok=0, adns_s_nomemory=1, adns_s_unknownrrtype=2, adns_s_systemfail=3, adns_s_max_localfail=29, adns_s_timeout=30, adns_s_allservfail=31, adns_s_norecurse=32, adns_s_invalidresponse=33, adns_s_unknownformat=34, adns_s_max_remotefail=59, adns_s_rcodeservfail=60, adns_s_rcodeformaterror=61, adns_s_rcodenotimplemented=62, adns_s_rcoderefused=63, adns_s_rcodeunknown=64, adns_s_max_tempfail=99, adns_s_inconsistent=100, adns_s_prohibitedcname=101, adns_s_answerdomaininvalid=102, adns_s_answerdomaintoolong=103, adns_s_invaliddata=104, adns_s_max_misconfig=199, adns_s_querydomainwrong=200, adns_s_querydomaininvalid=201, adns_s_querydomaintoolong=202, adns_s_max_misquery=299, adns_s_nxdomain=300, adns_s_nodata=301, adns_s_max_permfail=499 }

user_defined_types: enum adns_initflags { adns_if_none=0, adns_if_noenv=1, adns_if_noerrprint=2, adns_if_noserverwarn=4, adns_if_debug=8, adns_if_logpid=128, adns_if_noautosys=16, adns_if_eintr=32, adns_if_nosigpipe=64, adns_if_checkc_entex=256, adns_if_checkc_freq=768 }

user_defined_types: enum adns__tcpstate { server_disconnected=0, server_connecting=1, server_ok=2, server_broken=3 }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: struct pollfd { int fd; short events; short revents; }

user_defined_types: struct sortlist { struct in_addr base; }

user_defined_types: struct qcontext { void *ext; void (*callback)(struct adns__query *parent, struct adns__query *child); union { struct adns_rr_addr ptr_parent_addr; struct adns_rr_hostaddr *hostaddr; } info; }

user_defined_types: struct allocnode { struct allocnode *next; }

user_defined_types: enum adns_rrtype { adns_rrt_typemask=65535, adns__qtf_deref=65536, adns__qtf_mail822=131072, adns_r_unknown=262144, adns_r_none=0, adns_r_a=1, adns_r_ns_raw=2, adns_r_ns=expr, adns_r_cname=5, adns_r_soa_raw=6, adns_r_soa=expr, adns_r_ptr_raw=12, adns_r_ptr=expr, adns_r_hinfo=13, adns_r_mx_raw=15, adns_r_mx=expr, adns_r_txt=16, adns_r_rp_raw=17, adns_r_rp=expr, adns_r_srv_raw=33, adns_r_srv=expr, adns_r_addr=expr }

user_defined_types: struct adns_rr_intstrpair { struct adns_rr_intstr array[2]; }

user_defined_types: struct adns_rr_strpair { char *array[2]; }

user_defined_types: struct adns_rr_inthostaddr { int i; struct adns_rr_hostaddr ha; }

user_defined_types: struct adns_rr_soa { char *mname; unsigned long serial; }

user_defined_types: struct adns_rr_srvraw { int priority; char *host; }

user_defined_types: struct adns_rr_srvha { int priority; struct adns_rr_hostaddr ha; }

user_defined_types: struct adns_rr_byteblock { int len; unsigned char *data; }

user_defined_types: struct vbuf { int used; unsigned char *buf; }

user_defined_types: struct adns_rr_intstr { int i; char *str; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }

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

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


original_code:
adns_status adns__mkquery(adns_state ads, vbuf *vb, int *id_r,
     const char *owner, int ol,
     const typeinfo *typei, adns_rrtype type,
     adns_queryflags flags) {
  int labelnum, ll, nbytes;
  byte label[255];
  byte *rqp;
  const char *p, *pe;
  adns_status st;
  st= mkquery_header(ads,vb,id_r,ol+2); if (st) return st;
  (rqp= (vb)->buf+(vb)->used);
  p= owner; pe= owner+ol;
  nbytes= 0;
  labelnum= 0;
  while (p!=pe) {
    ll= sizeof(label);
    st= typei->qdparselabel(ads, &p,pe, labelnum++, label, &ll, flags, typei);
    if (st) return st;
    if (!ll) return adns_s_querydomaininvalid;
    if (ll > 63) return adns_s_querydomaintoolong;
    nbytes+= ll+1;
    if (nbytes >= 255) return adns_s_querydomaintoolong;
    *rqp++= (ll);
    memcpy(rqp,label,ll); rqp+= ll;
  }
  *rqp++= (0);
  ((vb)->used= rqp-(vb)->buf);
  st= mkquery_footer(vb,type);
  return adns_s_ok;
}

canonical_original_code:
enum adns_status adns__mkquery(struct adns__state *ads, struct vbuf *vb, int *id_r, char *owner, int ol, struct typeinfo *typei, enum adns_rrtype type, enum adns_queryflags flags) {
  int labelnum; int ll; int nbytes;
  unsigned char label[255];
  unsigned char *rqp;
  char *p; char *pe;
  enum adns_status st;
  st= mkquery_header(ads,vb,id_r,ol+2); if (st) return st;
  (rqp= (vb)->buf+(vb)->used);
  p= owner; pe= owner+ol;
  nbytes= 0;
  labelnum= 0;
  while (p!=pe) {
    ll= sizeof(label);
    st= typei->qdparselabel(ads, &p,pe, labelnum++, label, &ll, flags, typei);
    if (st) return st;
    if (!ll) return adns_s_querydomaininvalid;
    if (ll > 63) return adns_s_querydomaintoolong;
    nbytes+= ll+1;
    if (nbytes >= 255) return adns_s_querydomaintoolong;
    *rqp++= (ll);
    memcpy(rqp,label,ll); rqp+= ll;
  }
  *rqp++= (0);
  ((vb)->used= rqp-(vb)->buf);
  st= mkquery_footer(vb,type);
  return adns_s_ok;
}

variable_types:
owner
char *

variable_types: ol int

variable_types: enum adns_rrtype { adns_rrt_typemask=65535, adns__qtf_deref=65536, adns__qtf_mail822=131072, adns_r_unknown=262144, adns_r_none=0, adns_r_a=1, adns_r_ns_raw=2, adns_r_ns=expr, adns_r_cname=5, adns_r_soa_raw=6, adns_r_soa=expr, adns_r_ptr_raw=12, adns_r_ptr=expr, adns_r_hinfo=13, adns_r_mx_raw=15, adns_r_mx=expr, adns_r_txt=16, adns_r_rp_raw=17, adns_r_rp=expr, adns_r_srv_raw=33, adns_r_srv=expr, adns_r_addr=expr }

variable_types: nbytes int

variable_types:
label
unsigned char [255]

variable_types: enum adns_status { adns_s_ok=0, adns_s_nomemory=1, adns_s_unknownrrtype=2, adns_s_systemfail=3, adns_s_max_localfail=29, adns_s_timeout=30, adns_s_allservfail=31, adns_s_norecurse=32, adns_s_invalidresponse=33, adns_s_unknownformat=34, adns_s_max_remotefail=59, adns_s_rcodeservfail=60, adns_s_rcodeformaterror=61, adns_s_rcodenotimplemented=62, adns_s_rcoderefused=63, adns_s_rcodeunknown=64, adns_s_max_tempfail=99, adns_s_inconsistent=100, adns_s_prohibitedcname=101, adns_s_answerdomaininvalid=102, adns_s_answerdomaintoolong=103, adns_s_invaliddata=104, adns_s_max_misconfig=199, adns_s_querydomainwrong=200, adns_s_querydomaininvalid=201, adns_s_querydomaintoolong=202, adns_s_max_misquery=299, adns_s_nxdomain=300, adns_s_nodata=301, adns_s_max_permfail=499 }

user_defined_types: enum adns_queryflags { adns_qf_none=0, adns_qf_search=1, adns_qf_usevc=2, adns_qf_owner=4, adns_qf_quoteok_query=16, adns_qf_quoteok_cname=0, adns_qf_quoteok_anshost=64, adns_qf_quotefail_cname=128, adns_qf_cname_loose=256, adns_qf_cname_forbid=512, adns__qf_internalmask=267386880 }

user_defined_types: struct adns__state { enum adns_initflags iflags; void (*logfn)(struct adns__state *ads, void *logfndata, char *fmt, __builtin_va_list al); void *logfndata; int configerrno; struct query_queue udpw; struct adns__query *forallnext; int nextid; struct vbuf tcpsend; int nservers; enum adns__tcpstate tcpstate; struct timeval tcptimeout; struct sigaction stdsigpipe; struct __sigset_t stdsigmask; struct pollfd pollfds_buf[2]; struct server servers[5]; struct sortlist sortlist[15]; char **searchlist; unsigned short rand48xsubi[3]; }

user_defined_types: enum adns_initflags { adns_if_none=0, adns_if_noenv=1, adns_if_noerrprint=2, adns_if_noserverwarn=4, adns_if_debug=8, adns_if_logpid=128, adns_if_noautosys=16, adns_if_eintr=32, adns_if_nosigpipe=64, adns_if_checkc_entex=256, adns_if_checkc_freq=768 }

user_defined_types: struct query_queue { struct adns__query *head; }

user_defined_types: enum adns__tcpstate { server_disconnected=0, server_connecting=1, server_ok=2, server_broken=3 }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: struct pollfd { int fd; short events; short revents; }

user_defined_types: struct adns__query { struct adns__state *ads; enum { query_tosend=0, query_tcpw=1, query_childw=2, query_done=3 } state; struct adns__query *back; struct { struct adns__query *head; } children; struct { struct adns__query *back; } siblings; struct { struct allocnode *head; } allocations; int interim_allocd; void *final_allocspace; struct typeinfo *typei; unsigned char *query_dgram; int query_dglen; struct vbuf vb; struct adns_answer *answer; unsigned char *cname_dgram; int cname_dglen; struct vbuf search_vb; int search_origlen; int id; int udpnextserver; unsigned long udpsent; struct timeval timeout; long expires; struct qcontext ctx; }

user_defined_types: struct typeinfo { enum adns_rrtype typekey; char *rrtname; char *fmtname; int rrsz; void (*makefinal)(struct adns__query *qu, void *data); enum adns_status (*convstring)(struct vbuf *vb, void *data); enum adns_status (*parse)(struct parseinfo *pai, int cbyte, int max, void *store_r); int (*diff_needswap)(struct adns__state *ads, void *datap_a, void *datap_b); enum adns_status (*qdparselabel)(struct adns__state *ads, char **p_io, char *pe, int labelnum, char label_r[255], int *ll_io, enum adns_queryflags flags, struct typeinfo *typei); void (*postsort)(struct adns__state *ads, void *array, int nrrs, struct typeinfo *typei); }

user_defined_types: struct adns_answer { enum adns_status status; char *cname; char *owner; enum adns_rrtype type; long expires; int nrrs; union { void *untyped; unsigned char *bytes; char **str; struct adns_rr_intstr **manyistr; struct adns_rr_addr *addr; struct in_addr *inaddr; struct adns_rr_hostaddr *hostaddr; struct adns_rr_intstrpair *intstrpair; struct adns_rr_strpair *strpair; struct adns_rr_inthostaddr *inthostaddr; struct adns_rr_intstr *intstr; struct adns_rr_soa *soa; struct adns_rr_srvraw *srvraw; struct adns_rr_srvha *srvha; struct adns_rr_byteblock *byteblock; } rrs; }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }

user_defined_types: struct adns_rr_addr { int len; union { struct sockaddr sa; struct sockaddr_in inet; } addr; }

user_defined_types: struct adns_rr_hostaddr { char *host; enum adns_status astatus; int naddrs; struct adns_rr_addr *addrs; }

user_defined_types: struct parseinfo { struct adns__state *ads; struct adns__query *qu; int serv; unsigned char *dgram; int dglen; struct timeval now; }

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


decompiled_code:
__int64 __fastcall adns__mkquery_frdgram(__int64 a1, int *a2, _DWORD *a3, __int64 a4, unsigned int a5, unsigned int a6, __int16 a7)
{
__int64 v7; // r14
__int64 v8; // r13
__int64 result; // rax
char *v11; // rbx
char *v12; // rax
int v13; // [rsp+18h] [rbp-80h] BYREF
int v14; // [rsp+1Ch] [rbp-7Ch] BYREF
char v15[120]; // [rsp+20h] [rbp-78h] BYREF

v7 = a5;
v8 = a6;
result = mkquery_header(a1, (__int64)a2, a3, a5);
if ( !(_DWORD)result )
{
v11 = (char *)(*((_QWORD *)a2 + 1) + *a2);
adns__findlabel_start(v15, a1, 0xFFFFFFFFLL, 0LL, a4, (unsigned int)v7, v7, v8, 0LL);
while ( 1 )
{
if ( (unsigned int)adns__findlabel_next(v15, &v13, &v14) )
_assert_fail("!st", "transmit.c", 0xADu, "adns__mkquery_frdgram");
if ( !v13 )
break;
if ( v13 > 254 )
_assert_fail("lablen<255", "transmit.c", 0xAFu, "adns__mkquery_frdgram");
*v11 = v13;
v12 = (char *)memcpy(v11 + 1, (const void *)(a4 + v14), v13);
v11 = &v12[v13];
}
*v11 = 0;
*a2 = (_DWORD)v11 + 1 - a2[2];
mkquery_footer_isra_0(a2, a7);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int *a2, _DWORD *a3, __int64 a4, unsigned int a5, unsigned int a6, __int16 a7)
{
__int64 v7; // r14
__int64 v8; // r13
__int64 result; // rax
char *v11; // rbx
char *v12; // rax
int v13; // [rsp+18h] [rbp-80h] BYREF
int v14; // [rsp+1Ch] [rbp-7Ch] BYREF
char v15[120]; // [rsp+20h] [rbp-78h] BYREF

v7 = a5;
v8 = a6;
result = func2(a1, (__int64)a2, a3, a5);
if ( !(_DWORD)result )
{
v11 = (char *)(*((_QWORD *)a2 + 1) + *a2);
adns__findlabel_start(v15, a1, 0xFFFFFFFFLL, 0LL, a4, (unsigned int)v7, v7, v8, 0LL);
while ( 1 )
{
if ( (unsigned int)adns__findlabel_next(v15, &v13, &v14) )
_assert_fail("!st", "transmit.c", 0xADu, "adns__mkquery_frdgram");
if ( !v13 )
break;
if ( v13 > 254 )
_assert_fail("lablen<255", "transmit.c", 0xAFu, "adns__mkquery_frdgram");
*v11 = v13;
v12 = (char *)memcpy(v11 + 1, (const void *)(a4 + v14), v13);
v11 = &v12[v13];
}
*v11 = 0;
*a2 = (_DWORD)v11 + 1 - a2[2];
func5(a2, a7);
result = 0LL;
}
return result;
}

original_code:
adns_status adns__mkquery_frdgram(adns_state ads, vbuf *vb, int *id_r,
      const byte *qd_dgram, int qd_dglen,
      int qd_begin,
      adns_rrtype type, adns_queryflags flags) {
  byte *rqp;
  findlabel_state fls;
  int lablen, labstart;
  adns_status st;
  st= mkquery_header(ads,vb,id_r,qd_dglen); if (st) return st;
  (rqp= (vb)->buf+(vb)->used);
  adns__findlabel_start(&fls,ads,-1,0,qd_dgram,qd_dglen,qd_dglen,qd_begin,0);
  for (;;) {
    st= adns__findlabel_next(&fls,&lablen,&labstart); ((void) sizeof ((!st) ? 1 : 0), __extension__ ({ if (!st) ; else __assert_fail ("!st", "transmit.c", 173, __extension__ __PRETTY_FUNCTION__); }));
    if (!lablen) break;
    ((void) sizeof ((lablen<255) ? 1 : 0), __extension__ ({ if (lablen<255) ; else __assert_fail ("lablen<255", "transmit.c", 175, __extension__ __PRETTY_FUNCTION__); }));
    *rqp++= (lablen);
    memcpy(rqp,qd_dgram+labstart,lablen);
    rqp+= lablen;
  }
  *rqp++= (0);
  ((vb)->used= rqp-(vb)->buf);
  st= mkquery_footer(vb,type);
  return adns_s_ok;
}

canonical_original_code:
enum adns_status adns__mkquery_frdgram(struct adns__state *ads, struct vbuf *vb, int *id_r, unsigned char *qd_dgram, int qd_dglen, int qd_begin, enum adns_rrtype type, enum adns_queryflags flags) {
  unsigned char *rqp;
  struct findlabel_state fls;
  int lablen; int labstart;
  enum adns_status st;
  st= mkquery_header(ads,vb,id_r,qd_dglen); if (st) return st;
  (rqp= (vb)->buf+(vb)->used);
  adns__findlabel_start(&fls,ads,-1,0,qd_dgram,qd_dglen,qd_dglen,qd_begin,0);
  for (;;) {
    st= adns__findlabel_next(&fls,&lablen,&labstart); ((void) sizeof ((!st) ? 1 : 0), __extension__ ({ if (!st) ; else __assert_fail ("!st", "transmit.c", 173, __extension__ __PRETTY_FUNCTION__); }));
    if (!lablen) break;
    ((void) sizeof ((lablen<255) ? 1 : 0), __extension__ ({ if (lablen<255) ; else __assert_fail ("lablen<255", "transmit.c", 175, __extension__ __PRETTY_FUNCTION__); }));
    *rqp++= (lablen);
    memcpy(rqp,qd_dgram+labstart,lablen);
    rqp+= lablen;
  }
  *rqp++= (0);
  ((vb)->used= rqp-(vb)->buf);
  st= mkquery_footer(vb,type);
  return adns_s_ok;
}

variable_types:
vb
struct vbuf *

variable_types: struct findlabel_state { struct adns__state { enum adns_initflags { adns_if_none=0, adns_if_noenv=1, adns_if_noerrprint=2, adns_if_noserverwarn=4, adns_if_debug=8, adns_if_logpid=128, adns_if_noautosys=16, adns_if_eintr=32, adns_if_nosigpipe=64, adns_if_checkc_entex=256, adns_if_checkc_freq=768 } iflags; void (*logfn)(struct adns__state *ads, void *logfndata, char *fmt, __builtin_va_list al); void *logfndata; int configerrno; struct query_queue { struct adns__query { struct adns__state *ads; enum { query_tosend=0, query_tcpw=1, query_childw=2, query_done=3 } state; struct adns__query *back; struct { struct adns__query *head; } children; struct { struct adns__query *back; } siblings; struct { struct allocnode { struct allocnode *next; } *head; } allocations; int interim_allocd; void *final_allocspace; struct typeinfo { enum adns_rrtype { adns_rrt_typemask=65535, adns__qtf_deref=65536, adns__qtf_mail822=131072, adns_r_unknown=262144, adns_r_none=0, adns_r_a=1, adns_r_ns_raw=2, adns_r_ns=expr, adns_r_cname=5, adns_r_soa_raw=6, adns_r_soa=expr, adns_r_ptr_raw=12, adns_r_ptr=expr, adns_r_hinfo=13, adns_r_mx_raw=15, adns_r_mx=expr, adns_r_txt=16, adns_r_rp_raw=17, adns_r_rp=expr, adns_r_srv_raw=33, adns_r_srv=expr, adns_r_addr=expr } typekey; char *rrtname; char *fmtname; int rrsz; void (*makefinal)(struct adns__query *qu, void *data); enum adns_status { adns_s_ok=0, adns_s_nomemory=1, adns_s_unknownrrtype=2, adns_s_systemfail=3, adns_s_max_localfail=29, adns_s_timeout=30, adns_s_allservfail=31, adns_s_norecurse=32, adns_s_invalidresponse=33, adns_s_unknownformat=34, adns_s_max_remotefail=59, adns_s_rcodeservfail=60, adns_s_rcodeformaterror=61, adns_s_rcodenotimplemented=62, adns_s_rcoderefused=63, adns_s_rcodeunknown=64, adns_s_max_tempfail=99, adns_s_inconsistent=100, adns_s_prohibitedcname=101, adns_s_answerdomaininvalid=102, adns_s_answerdomaintoolong=103, adns_s_invaliddata=104, adns_s_max_misconfig=199, adns_s_querydomainwrong=200, adns_s_querydomaininvalid=201, adns_s_querydomaintoolong=202, adns_s_max_misquery=299, adns_s_nxdomain=300, adns_s_nodata=301, adns_s_max_permfail=499 } (*convstring)(struct vbuf { int used; unsigned char *buf; } *vb, void *data); enum adns_status { adns_s_ok=0, adns_s_nomemory=1, adns_s_unknownrrtype=2, adns_s_systemfail=3, adns_s_max_localfail=29, adns_s_timeout=30, adns_s_allservfail=31, adns_s_norecurse=32, adns_s_invalidresponse=33, adns_s_unknownformat=34, adns_s_max_remotefail=59, adns_s_rcodeservfail=60, adns_s_rcodeformaterror=61, adns_s_rcodenotimplemented=62, adns_s_rcoderefused=63, adns_s_rcodeunknown=64, adns_s_max_tempfail=99, adns_s_inconsistent=100, adns_s_prohibitedcname=101, adns_s_answerdomaininvalid=102, adns_s_answerdomaintoolong=103, adns_s_invaliddata=104, adns_s_max_misconfig=199, adns_s_querydomainwrong=200, adns_s_querydomaininvalid=201, adns_s_querydomaintoolong=202, adns_s_max_misquery=299, adns_s_nxdomain=300, adns_s_nodata=301, adns_s_max_permfail=499 } (*parse)(struct parseinfo { struct adns__state *ads; struct adns__query *qu; int serv; unsigned char *dgram; int dglen; struct timeval { long tv_sec; long tv_usec; } now; } *pai, int cbyte, int max, void *store_r); int (*diff_needswap)(struct adns__state *ads, void *datap_a, void *datap_b); enum adns_status { adns_s_ok=0, adns_s_nomemory=1, adns_s_unknownrrtype=2, adns_s_systemfail=3, adns_s_max_localfail=29, adns_s_timeout=30, adns_s_allservfail=31, adns_s_norecurse=32, adns_s_invalidresponse=33, adns_s_unknownformat=34, adns_s_max_remotefail=59, adns_s_rcodeservfail=60, adns_s_rcodeformaterror=61, adns_s_rcodenotimplemented=62, adns_s_rcoderefused=63, adns_s_rcodeunknown=64, adns_s_max_tempfail=99, adns_s_inconsistent=100, adns_s_prohibitedcname=101, adns_s_answerdomaininvalid=102, adns_s_answerdomaintoolong=103, adns_s_invaliddata=104, adns_s_max_misconfig=199, adns_s_querydomainwrong=200, adns_s_querydomaininvalid=201, adns_s_querydomaintoolong=202, adns_s_max_misquery=299, adns_s_nxdomain=300, adns_s_nodata=301, adns_s_max_permfail=499 } (*qdparselabel)(struct adns__state *ads, char **p_io, char *pe, int labelnum, char label_r[255], int *ll_io, enum adns_queryflags { adns_qf_none=0, adns_qf_search=1, adns_qf_usevc=2, adns_qf_owner=4, adns_qf_quoteok_query=16, adns_qf_quoteok_cname=0, adns_qf_quoteok_anshost=64, adns_qf_quotefail_cname=128, adns_qf_cname_loose=256, adns_qf_cname_forbid=512, adns__qf_internalmask=267386880 } flags, struct typeinfo *typei); void (*postsort)(struct adns__state *ads, void *array, int nrrs, struct typeinfo *typei); } *typei; unsigned char *query_dgram; int query_dglen; struct vbuf vb; struct adns_answer { enum adns_status { adns_s_ok=0, adns_s_nomemory=1, adns_s_unknownrrtype=2, adns_s_systemfail=3, adns_s_max_localfail=29, adns_s_timeout=30, adns_s_allservfail=31, adns_s_norecurse=32, adns_s_invalidresponse=33, adns_s_unknownformat=34, adns_s_max_remotefail=59, adns_s_rcodeservfail=60, adns_s_rcodeformaterror=61, adns_s_rcodenotimplemented=62, adns_s_rcoderefused=63, adns_s_rcodeunknown=64, adns_s_max_tempfail=99, adns_s_inconsistent=100, adns_s_prohibitedcname=101, adns_s_answerdomaininvalid=102, adns_s_answerdomaintoolong=103, adns_s_invaliddata=104, adns_s_max_misconfig=199, adns_s_querydomainwrong=200, adns_s_querydomaininvalid=201, adns_s_querydomaintoolong=202, adns_s_max_misquery=299, adns_s_nxdomain=300, adns_s_nodata=301, adns_s_max_permfail=499 } status; char *cname; char *owner; enum adns_rrtype { adns_rrt_typemask=65535, adns__qtf_deref=65536, adns__qtf_mail822=131072, adns_r_unknown=262144, adns_r_none=0, adns_r_a=1, adns_r_ns_raw=2, adns_r_ns=expr, adns_r_cname=5, adns_r_soa_raw=6, adns_r_soa=expr, adns_r_ptr_raw=12, adns_r_ptr=expr, adns_r_hinfo=13, adns_r_mx_raw=15, adns_r_mx=expr, adns_r_txt=16, adns_r_rp_raw=17, adns_r_rp=expr, adns_r_srv_raw=33, adns_r_srv=expr, adns_r_addr=expr } type; long expires; int nrrs; union { void *untyped; unsigned char *bytes; char **str; struct adns_rr_intstr { int i; char *str; } **manyistr; struct adns_rr_addr { int len; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } sa; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } inet; } addr; } *addr; struct in_addr *inaddr; struct adns_rr_hostaddr { char *host; enum adns_status { adns_s_ok=0, adns_s_nomemory=1, adns_s_unknownrrtype=2, adns_s_systemfail=3, adns_s_max_localfail=29, adns_s_timeout=30, adns_s_allservfail=31, adns_s_norecurse=32, adns_s_invalidresponse=33, adns_s_unknownformat=34, adns_s_max_remotefail=59, adns_s_rcodeservfail=60, adns_s_rcodeformaterror=61, adns_s_rcodenotimplemented=62, adns_s_rcoderefused=63, adns_s_rcodeunknown=64, adns_s_max_tempfail=99, adns_s_inconsistent=100, adns_s_prohibitedcname=101, adns_s_answerdomaininvalid=102, adns_s_answerdomaintoolong=103, adns_s_invaliddata=104, adns_s_max_misconfig=199, adns_s_querydomainwrong=200, adns_s_querydomaininvalid=201, adns_s_querydomaintoolong=202, adns_s_max_misquery=299, adns_s_nxdomain=300, adns_s_nodata=301, adns_s_max_permfail=499 } astatus; int naddrs; struct adns_rr_addr *addrs; } *hostaddr; struct adns_rr_intstrpair { struct adns_rr_intstr array[2]; } *intstrpair; struct adns_rr_strpair { char *array[2]; } *strpair; struct adns_rr_inthostaddr { int i; struct adns_rr_hostaddr ha; } *inthostaddr; struct adns_rr_intstr *intstr; struct adns_rr_soa { char *mname; unsigned long serial; } *soa; struct adns_rr_srvraw { int priority; char *host; } *srvraw; struct adns_rr_srvha { int priority; struct adns_rr_hostaddr ha; } *srvha; struct adns_rr_byteblock { int len; unsigned char *data; } *byteblock; } rrs; } *answer; unsigned char *cname_dgram; int cname_dglen; struct vbuf search_vb; int search_origlen; int id; int udpnextserver; unsigned long udpsent; struct timeval timeout; long expires; struct qcontext { void *ext; void (*callback)(struct adns__query *parent, struct adns__query *child); union { struct adns_rr_addr ptr_parent_addr; struct adns_rr_hostaddr *hostaddr; } info; } ctx; } *head; } udpw; struct adns__query *forallnext; int nextid; struct vbuf tcpsend; int nservers; enum adns__tcpstate { server_disconnected=0, server_connecting=1, server_ok=2, server_broken=3 } tcpstate; struct timeval tcptimeout; struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); } stdsigpipe; struct __sigset_t stdsigmask; struct pollfd { int fd; short events; short revents; } pollfds_buf[2]; struct server { struct in_addr addr; } servers[5]; struct sortlist { struct in_addr base; } sortlist[15]; char **searchlist; unsigned short rand48xsubi[3]; } *ads; struct adns__query *qu; int serv; unsigned char *dgram; int dglen; int *dmend_r; }

variable_types: lablen int

variable_types: labstart int

user_defined_types: struct findlabel_state { struct adns__state *ads; struct adns__query *qu; int serv; unsigned char *dgram; int dglen; int *dmend_r; }

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