decompiled_code:
void __fastcall adns__querysend_tcp(_QWORD *a1)
{
__int64 v1; // rbp
__int64 v3; // rsi
int v4; // eax
__int64 v5; // rdx
int v6; // esi
int v7; // edx
__int64 v8; // rax
__int64 v9; // rdi
int v10; // er13
unsigned int v11; // ecx
bool v12; // al
char *v13; // rax
__int16 v14; // [rsp+Eh] [rbp-4Ah] BYREF
struct iovec iovec; // [rsp+10h] [rbp-48h] BYREF
__int64 v16; // [rsp+20h] [rbp-38h]
__int64 v17; // [rsp+28h] [rbp-30h]

v1 = *a1;
if ( *(_DWORD *)(*a1 + 176LL) == 2 )
{
if ( *((_DWORD *)a1 + 2) != 1 )
_assert_fail("qu->state == query_tcpw", "transmit.c", 0xC5u, "adns__querysend_tcp");
v3 = (unsigned int)(*((_DWORD *)a1 + 30) + *(_DWORD *)(v1 + 120) + 2);
v14 = __ROL2__(*((_WORD *)a1 + 60), 8);
if ( (unsigned int)adns__vbuf_ensure(v1 + 120, v3) )
{
v4 = *(_DWORD *)(v1 + 120);
++*((_DWORD *)a1 + 51);
*(_QWORD *)(v1 + 192) = 0LL;
*(_QWORD *)(v1 + 184) = 0LL;
if ( !v4 )
{
v8 = a1[14];
v9 = *a1;
iovec.iov_base = &v14;
iovec.iov_len = 2LL;
v16 = v8;
v17 = *((int *)a1 + 30);
adns__sigpipe_protect(v9);
v10 = writev(*(_DWORD *)(*a1 + 112LL), &iovec, 2);
adns__sigpipe_unprotect(*a1);
if ( v10 >= 0 )
{
v6 = v10 - 2;
if ( v10 > 1 )
{
LABEL_8:
v7 = *((_DWORD *)a1 + 30);
if ( v7 > v6 && !(unsigned int)adns__vbuf_append(v1 + 120, a1[14] + v6, (unsigned int)(v7 - v6)) )
_assert_fail("r", "transmit.c", 0xEFu, "adns__querysend_tcp");
return;
}
v5 = (unsigned int)(2 - v10);
LABEL_6:
if ( !(unsigned int)adns__vbuf_append(v1 + 120, &v14, v5) )
_assert_fail("r", "transmit.c", 0xE8u, "adns__querysend_tcp");
v6 = 0;
goto LABEL_8;
}
v11 = *_errno_location();
v12 = 1;
if ( v11 <= 0x1C )
v12 = ((0x10001810uLL >> v11) & 1) == 0;
if ( v11 != 105 && v12 )
{
v13 = strerror(v11);
adns__tcp_broken(v1, "write", v13);
return;
}
}
v5 = 2LL;
goto LABEL_6;
}
}
}

canonical_decompiled_code:
void __fastcall func9(_QWORD *a1)
{
__int64 v1; // rbp
__int64 v3; // rsi
int v4; // eax
__int64 v5; // rdx
int v6; // esi
int v7; // edx
__int64 v8; // rax
__int64 v9; // rdi
int v10; // er13
unsigned int v11; // ecx
bool v12; // al
char *v13; // rax
__int16 v14; // [rsp+Eh] [rbp-4Ah] BYREF
struct iovec iovec; // [rsp+10h] [rbp-48h] BYREF
__int64 v16; // [rsp+20h] [rbp-38h]
__int64 v17; // [rsp+28h] [rbp-30h]

v1 = *a1;
if ( *(_DWORD *)(*a1 + 176LL) == 2 )
{
if ( *((_DWORD *)a1 + 2) != 1 )
_assert_fail("qu->state == query_tcpw", "transmit.c", 0xC5u, "adns__querysend_tcp");
v3 = (unsigned int)(*((_DWORD *)a1 + 30) + *(_DWORD *)(v1 + 120) + 2);
v14 = __ROL2__(*((_WORD *)a1 + 60), 8);
if ( (unsigned int)adns__vbuf_ensure(v1 + 120, v3) )
{
v4 = *(_DWORD *)(v1 + 120);
++*((_DWORD *)a1 + 51);
*(_QWORD *)(v1 + 192) = 0LL;
*(_QWORD *)(v1 + 184) = 0LL;
if ( !v4 )
{
v8 = a1[14];
v9 = *a1;
iovec.iov_base = &v14;
iovec.iov_len = 2LL;
v16 = v8;
v17 = *((int *)a1 + 30);
adns__sigpipe_protect(v9);
v10 = writev(*(_DWORD *)(*a1 + 112LL), &iovec, 2);
adns__sigpipe_unprotect(*a1);
if ( v10 >= 0 )
{
v6 = v10 - 2;
if ( v10 > 1 )
{
LABEL_8:
v7 = *((_DWORD *)a1 + 30);
if ( v7 > v6 && !(unsigned int)adns__vbuf_append(v1 + 120, a1[14] + v6, (unsigned int)(v7 - v6)) )
_assert_fail("r", "transmit.c", 0xEFu, "adns__querysend_tcp");
return;
}
v5 = (unsigned int)(2 - v10);
LABEL_6:
if ( !(unsigned int)adns__vbuf_append(v1 + 120, &v14, v5) )
_assert_fail("r", "transmit.c", 0xE8u, "adns__querysend_tcp");
v6 = 0;
goto LABEL_8;
}
v11 = *_errno_location();
v12 = 1;
if ( v11 <= 0x1C )
v12 = ((0x10001810uLL >> v11) & 1) == 0;
if ( v11 != 105 && v12 )
{
v13 = strerror(v11);
adns__tcp_broken(v1, "write", v13);
return;
}
}
v5 = 2LL;
goto LABEL_6;
}
}
}

original_code:
void adns__querysend_tcp(adns_query qu, struct timeval now) {
  byte length[2];
  struct iovec iov[2];
  int wr, r;
  adns_state ads;
  if (qu->ads->tcpstate != server_ok) return;
  ((void) sizeof ((qu->state == query_tcpw) ? 1 : 0), __extension__ ({ if (qu->state == query_tcpw) ; else __assert_fail ("qu->state == query_tcpw", "transmit.c", 197, __extension__ __PRETTY_FUNCTION__); }));
  length[0]= (qu->query_dglen&0x0ff00U) >>8;
  length[1]= (qu->query_dglen&0x0ff);
  ads= qu->ads;
  if (!adns__vbuf_ensure(&ads->tcpsend,ads->tcpsend.used+qu->query_dglen+2))
    return;
  qu->retries++;
  ads->tcptimeout.tv_sec= ads->tcptimeout.tv_usec= 0;
  if (ads->tcpsend.used) {
    wr= 0;
  } else {
    iov[0].iov_base= length;
    iov[0].iov_len= 2;
    iov[1].iov_base= qu->query_dgram;
    iov[1].iov_len= qu->query_dglen;
    adns__sigpipe_protect(qu->ads);
    wr= writev(qu->ads->tcpsocket,iov,2);
    adns__sigpipe_unprotect(qu->ads);
    if (wr < 0) {
      if (!((*__errno_location ()) == 11 || (*__errno_location ()) == 4 || (*__errno_location ()) == 28 ||
     (*__errno_location ()) == 105 || (*__errno_location ()) == 12)) {
 adns__tcp_broken(ads,"write",strerror((*__errno_location ())));
 return;
      }
      wr= 0;
    }
  }
  if (wr<2) {
    r= adns__vbuf_append(&ads->tcpsend,length,2-wr); ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "transmit.c", 232, __extension__ __PRETTY_FUNCTION__); }));
    wr= 0;
  } else {
    wr-= 2;
  }
  if (wr<qu->query_dglen) {
    r= adns__vbuf_append(&ads->tcpsend,qu->query_dgram+wr,qu->query_dglen-wr);
    ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "transmit.c", 239, __extension__ __PRETTY_FUNCTION__); }));
  }
}

canonical_original_code:
void adns__querysend_tcp(struct adns__query *qu, struct timeval now) {
  unsigned char length[2];
  struct iovec iov[2];
  int wr; int r;
  struct adns__state *ads;
  if (qu->ads->tcpstate != server_ok) return;
  ((void) sizeof ((qu->state == query_tcpw) ? 1 : 0), __extension__ ({ if (qu->state == query_tcpw) ; else __assert_fail ("qu->state == query_tcpw", "transmit.c", 197, __extension__ __PRETTY_FUNCTION__); }));
  length[0]= (qu->query_dglen&0x0ff00U) >>8;
  length[1]= (qu->query_dglen&0x0ff);
  ads= qu->ads;
  if (!adns__vbuf_ensure(&ads->tcpsend,ads->tcpsend.used+qu->query_dglen+2))
    return;
  qu->retries++;
  ads->tcptimeout.tv_sec= ads->tcptimeout.tv_usec= 0;
  if (ads->tcpsend.used) {
    wr= 0;
  } else {
    iov[0].iov_base= length;
    iov[0].iov_len= 2;
    iov[1].iov_base= qu->query_dgram;
    iov[1].iov_len= qu->query_dglen;
    adns__sigpipe_protect(qu->ads);
    wr= writev(qu->ads->tcpsocket,iov,2);
    adns__sigpipe_unprotect(qu->ads);
    if (wr < 0) {
      if (!((*__errno_location ()) == 11 || (*__errno_location ()) == 4 || (*__errno_location ()) == 28 ||
     (*__errno_location ()) == 105 || (*__errno_location ()) == 12)) {
 adns__tcp_broken(ads,"write",strerror((*__errno_location ())));
 return;
      }
      wr= 0;
    }
  }
  if (wr<2) {
    r= adns__vbuf_append(&ads->tcpsend,length,2-wr); ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "transmit.c", 232, __extension__ __PRETTY_FUNCTION__); }));
    wr= 0;
  } else {
    wr-= 2;
  }
  if (wr<qu->query_dglen) {
    r= adns__vbuf_append(&ads->tcpsend,qu->query_dgram+wr,qu->query_dglen-wr);
    ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "transmit.c", 239, __extension__ __PRETTY_FUNCTION__); }));
  }
}

variable_types: struct adns__query { 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 *head; } udpw; struct adns__query *forallnext; int nextid; struct vbuf { int used; unsigned char *buf; } tcpsend; int nservers; enum adns__tcpstate { server_disconnected=0, server_connecting=1, server_ok=2, server_broken=3 } tcpstate; struct timeval { long tv_sec; long tv_usec; } 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 { unsigned int s_addr; } addr; } servers[5]; struct sortlist { struct in_addr base; } sortlist[15]; char **searchlist; unsigned short rand48xsubi[3]; } *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 *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 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 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; } *

variable_types:
now
struct timeval

variable_types:
length
unsigned char [2]

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [2]

variable_types: wr int

variable_types: r int

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

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


original_code:
static void query_usetcp(adns_query qu, struct timeval now) {
  qu->state= query_tcpw;
  qu->timeout= now;
  timevaladd(&qu->timeout,30000);
  do { (qu)-> next= 0; (qu)-> back= (qu->ads->tcpw).tail; if ((qu->ads->tcpw).tail) (qu->ads->tcpw).tail-> next= (qu); else (qu->ads->tcpw).head= (qu); (qu->ads->tcpw).tail= (qu); } while(0);
  adns__querysend_tcp(qu,now);
  adns__tcp_tryconnect(qu->ads,now);
}

canonical_original_code:
static void query_usetcp(struct adns__query *qu, struct timeval now) {
  qu->state= query_tcpw;
  qu->timeout= now;
  timevaladd(&qu->timeout,30000);
  do { (qu)-> next= 0; (qu)-> back= (qu->ads->tcpw).tail; if ((qu->ads->tcpw).tail) (qu->ads->tcpw).tail-> next= (qu); else (qu->ads->tcpw).head= (qu); (qu->ads->tcpw).tail= (qu); } while(0);
  adns__querysend_tcp(qu,now);
  adns__tcp_tryconnect(qu->ads,now);
}

return_type: void

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 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 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: 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: struct vbuf { int used; unsigned char *buf; }

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

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

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 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: 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: 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: 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_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 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 parseinfo { struct adns__state *ads; struct adns__query *qu; int serv; unsigned char *dgram; int dglen; struct timeval now; }

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

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

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: union sigval { int sival_int; void *sival_ptr; }


original_code:
void adns__query_send(adns_query qu, struct timeval now) {
  struct sockaddr_in servaddr;
  int serv, r;
  adns_state ads;
  ((void) sizeof ((qu->state == query_tosend) ? 1 : 0), __extension__ ({ if (qu->state == query_tosend) ; else __assert_fail ("qu->state == query_tosend", "transmit.c", 257, __extension__ __PRETTY_FUNCTION__); }));
  if ((qu->flags & adns_qf_usevc) || (qu->query_dglen > 512)) {
    query_usetcp(qu,now);
    return;
  }
  if (qu->retries >= 15) {
    adns__query_fail(qu,adns_s_timeout);
    return;
  }
  serv= qu->udpnextserver;
  memset(&servaddr,0,sizeof(servaddr));
  ads= qu->ads;
  servaddr.sin_family= 2;
  servaddr.sin_addr= ads->servers[serv].addr;
  servaddr.sin_port= htons(53);
  r= sendto(ads->udpsocket,qu->query_dgram,qu->query_dglen,0,
     (const struct sockaddr*)&servaddr,sizeof(servaddr));
  if (r<0 && (*__errno_location ()) == 90) {
    qu->retries= 0;
    query_usetcp(qu,now);
    return;
  }
  if (r<0 && (*__errno_location ()) != 11)
    adns__warn(ads,serv,0,"sendto failed: %s",strerror((*__errno_location ())));
  qu->timeout= now;
  timevaladd(&qu->timeout,2000);
  qu->udpsent |= (1<<serv);
  qu->udpnextserver= (serv+1)%ads->nservers;
  qu->retries++;
  do { (qu)-> next= 0; (qu)-> back= (ads->udpw).tail; if ((ads->udpw).tail) (ads->udpw).tail-> next= (qu); else (ads->udpw).head= (qu); (ads->udpw).tail= (qu); } while(0);
}

canonical_original_code:
void adns__query_send(struct adns__query *qu, struct timeval now) {
  struct sockaddr_in servaddr;
  int serv; int r;
  struct adns__state *ads;
  ((void) sizeof ((qu->state == query_tosend) ? 1 : 0), __extension__ ({ if (qu->state == query_tosend) ; else __assert_fail ("qu->state == query_tosend", "transmit.c", 257, __extension__ __PRETTY_FUNCTION__); }));
  if ((qu->flags & adns_qf_usevc) || (qu->query_dglen > 512)) {
    query_usetcp(qu,now);
    return;
  }
  if (qu->retries >= 15) {
    adns__query_fail(qu,adns_s_timeout);
    return;
  }
  serv= qu->udpnextserver;
  memset(&servaddr,0,sizeof(servaddr));
  ads= qu->ads;
  servaddr.sin_family= 2;
  servaddr.sin_addr= ads->servers[serv].addr;
  servaddr.sin_port= htons(53);
  r= sendto(ads->udpsocket,qu->query_dgram,qu->query_dglen,0,
     (struct sockaddr *)&servaddr,sizeof(servaddr));
  if (r<0 && (*__errno_location ()) == 90) {
    qu->retries= 0;
    query_usetcp(qu,now);
    return;
  }
  if (r<0 && (*__errno_location ()) != 11)
    adns__warn(ads,serv,0,"sendto failed: %s",strerror((*__errno_location ())));
  qu->timeout= now;
  timevaladd(&qu->timeout,2000);
  qu->udpsent |= (1<<serv);
  qu->udpnextserver= (serv+1)%ads->nservers;
  qu->retries++;
  do { (qu)-> next= 0; (qu)-> back= (ads->udpw).tail; if ((ads->udpw).tail) (ads->udpw).tail-> next= (qu); else (ads->udpw).head= (qu); (ads->udpw).tail= (qu); } while(0);
}

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

variable_types: serv int

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 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 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: 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 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 __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 vbuf { int used; unsigned char *buf; }

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

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


decompiled_code:
__int64 __fastcall checkc_notcpbuf(_DWORD *a1)
{
__int64 result; // rax

if ( a1[30] )
_assert_fail("!ads->tcpsend.used", "check.c", 0x48u, "checkc_notcpbuf");
if ( a1[34] )
_assert_fail("!ads->tcprecv.used", "check.c", 0x49u, "checkc_notcpbuf");
result = (unsigned int)a1[43];
if ( (_DWORD)result )
_assert_fail("!ads->tcprecv_skip", "check.c", 0x4Au, "checkc_notcpbuf");
return result;
}

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

if ( a1[30] )
_assert_fail("!ads->tcpsend.used", "check.c", 0x48u, "checkc_notcpbuf");
if ( a1[34] )
_assert_fail("!ads->tcprecv.used", "check.c", 0x49u, "checkc_notcpbuf");
result = (unsigned int)a1[43];
if ( (_DWORD)result )
_assert_fail("!ads->tcprecv_skip", "check.c", 0x4Au, "checkc_notcpbuf");
return result;
}

original_code:
static void checkc_notcpbuf(adns_state ads) {
  ((void) sizeof ((!ads->tcpsend.used) ? 1 : 0), __extension__ ({ if (!ads->tcpsend.used) ; else __assert_fail ("!ads->tcpsend.used", "check.c", 72, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((!ads->tcprecv.used) ? 1 : 0), __extension__ ({ if (!ads->tcprecv.used) ; else __assert_fail ("!ads->tcprecv.used", "check.c", 73, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((!ads->tcprecv_skip) ? 1 : 0), __extension__ ({ if (!ads->tcprecv_skip) ; else __assert_fail ("!ads->tcprecv_skip", "check.c", 74, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void checkc_notcpbuf(struct adns__state *ads) {
  ((void) sizeof ((!ads->tcpsend.used) ? 1 : 0), __extension__ ({ if (!ads->tcpsend.used) ; else __assert_fail ("!ads->tcpsend.used", "check.c", 72, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((!ads->tcprecv.used) ? 1 : 0), __extension__ ({ if (!ads->tcprecv.used) ; else __assert_fail ("!ads->tcprecv.used", "check.c", 73, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((!ads->tcprecv_skip) ? 1 : 0), __extension__ ({ if (!ads->tcprecv_skip) ; else __assert_fail ("!ads->tcprecv_skip", "check.c", 74, __extension__ __PRETTY_FUNCTION__); }));
}

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 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: 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_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 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 parseinfo { struct adns__state *ads; struct adns__query *qu; int serv; unsigned char *dgram; int dglen; struct timeval now; }

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


decompiled_code:
__int64 __fastcall checkc_global(__int64 a1)
{
int v1; // eax
_DWORD *v2; // rdx
int v3; // eax
unsigned int v4; // eax
__int64 result; // rax

if ( *(int *)(a1 + 108) < 0 )
_assert_fail("ads->udpsocket >= 0", "check.c", 0x50u, "checkc_global");
v1 = *(_DWORD *)(a1 + 156);
if ( v1 > 0 )
{
v2 = (_DWORD *)(a1 + 516);
do
{
if ( (*v2 & ~v2[1]) != 0 )
_assert_fail(
"!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr)",
"check.c",
0x53u,
"checkc_global");
v2 += 2;
}
while ( v2 != (_DWORD *)(a1 + 8LL * (unsigned int)(v1 - 1) + 524) );
}
v3 = *(_DWORD *)(a1 + 168);
if ( v3 < 0 || v3 >= *(_DWORD *)(a1 + 152) )
_assert_fail("ads->tcpserver >= 0 && ads->tcpserver < ads->nservers", "check.c", 0x55u, "checkc_global");
v4 = *(_DWORD *)(a1 + 176);
if ( v4 != 2 )
{
if ( v4 > 2 )
{
if ( v4 != 3 )
_assert_fail("!\"ads->tcpstate value\"", "check.c", 0x66u, "checkc_global");
}
else if ( v4 )
{
if ( *(int *)(a1 + 112) < 0 )
_assert_fail("ads->tcpsocket >= 0", "check.c", 0x59u, "checkc_global");
LABEL_12:
result = checkc_notcpbuf((_DWORD *)a1);
goto LABEL_13;
}
if ( *(_DWORD *)(a1 + 112) != -1 )
_assert_fail("ads->tcpsocket == -1", "check.c", 0x5Eu, "checkc_global");
goto LABEL_12;
}
if ( *(int *)(a1 + 112) < 0 )
_assert_fail("ads->tcpsocket >= 0", "check.c", 0x62u, "checkc_global");
result = *(unsigned int *)(a1 + 136);
if ( *(_DWORD *)(a1 + 172) > (int)result )
_assert_fail("ads->tcprecv_skip <= ads->tcprecv.used", "check.c", 0x63u, "checkc_global");
LABEL_13:
if ( !*(_QWORD *)(a1 + 640) )
{
result = *(unsigned int *)(a1 + 160);
if ( (_DWORD)result )
_assert_fail("ads->searchlist || !ads->nsearchlist", "check.c", 0x69u, "checkc_global");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // eax
_DWORD *v2; // rdx
int v3; // eax
unsigned int v4; // eax
__int64 result; // rax

if ( *(int *)(a1 + 108) < 0 )
_assert_fail("ads->udpsocket >= 0", "check.c", 0x50u, "checkc_global");
v1 = *(_DWORD *)(a1 + 156);
if ( v1 > 0 )
{
v2 = (_DWORD *)(a1 + 516);
do
{
if ( (*v2 & ~v2[1]) != 0 )
_assert_fail(
"!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr)",
"check.c",
0x53u,
"checkc_global");
v2 += 2;
}
while ( v2 != (_DWORD *)(a1 + 8LL * (unsigned int)(v1 - 1) + 524) );
}
v3 = *(_DWORD *)(a1 + 168);
if ( v3 < 0 || v3 >= *(_DWORD *)(a1 + 152) )
_assert_fail("ads->tcpserver >= 0 && ads->tcpserver < ads->nservers", "check.c", 0x55u, "checkc_global");
v4 = *(_DWORD *)(a1 + 176);
if ( v4 != 2 )
{
if ( v4 > 2 )
{
if ( v4 != 3 )
_assert_fail("!\"ads->tcpstate value\"", "check.c", 0x66u, "checkc_global");
}
else if ( v4 )
{
if ( *(int *)(a1 + 112) < 0 )
_assert_fail("ads->tcpsocket >= 0", "check.c", 0x59u, "checkc_global");
LABEL_12:
result = func0((_DWORD *)a1);
goto LABEL_13;
}
if ( *(_DWORD *)(a1 + 112) != -1 )
_assert_fail("ads->tcpsocket == -1", "check.c", 0x5Eu, "checkc_global");
goto LABEL_12;
}
if ( *(int *)(a1 + 112) < 0 )
_assert_fail("ads->tcpsocket >= 0", "check.c", 0x62u, "checkc_global");
result = *(unsigned int *)(a1 + 136);
if ( *(_DWORD *)(a1 + 172) > (int)result )
_assert_fail("ads->tcprecv_skip <= ads->tcprecv.used", "check.c", 0x63u, "checkc_global");
LABEL_13:
if ( !*(_QWORD *)(a1 + 640) )
{
result = *(unsigned int *)(a1 + 160);
if ( (_DWORD)result )
_assert_fail("ads->searchlist || !ads->nsearchlist", "check.c", 0x69u, "checkc_global");
}
return result;
}

original_code:
static void checkc_global(adns_state ads) {
  int i;
  ((void) sizeof ((ads->udpsocket >= 0) ? 1 : 0), __extension__ ({ if (ads->udpsocket >= 0) ; else __assert_fail ("ads->udpsocket >= 0", "check.c", 80, __extension__ __PRETTY_FUNCTION__); }));
  for (i=0; i<ads->nsortlist; i++)
    ((void) sizeof ((!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr)) ? 1 : 0), __extension__ ({ if (!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr)) ; else __assert_fail ("!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr)", "check.c", 83, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((ads->tcpserver >= 0 && ads->tcpserver < ads->nservers) ? 1 : 0), __extension__ ({ if (ads->tcpserver >= 0 && ads->tcpserver < ads->nservers) ; else __assert_fail ("ads->tcpserver >= 0 && ads->tcpserver < ads->nservers", "check.c", 85, __extension__ __PRETTY_FUNCTION__); }));
  switch (ads->tcpstate) {
  case server_connecting:
    ((void) sizeof ((ads->tcpsocket >= 0) ? 1 : 0), __extension__ ({ if (ads->tcpsocket >= 0) ; else __assert_fail ("ads->tcpsocket >= 0", "check.c", 89, __extension__ __PRETTY_FUNCTION__); }));
    checkc_notcpbuf(ads);
    break;
  case server_disconnected:
  case server_broken:
    ((void) sizeof ((ads->tcpsocket == -1) ? 1 : 0), __extension__ ({ if (ads->tcpsocket == -1) ; else __assert_fail ("ads->tcpsocket == -1", "check.c", 94, __extension__ __PRETTY_FUNCTION__); }));
    checkc_notcpbuf(ads);
    break;
  case server_ok:
    ((void) sizeof ((ads->tcpsocket >= 0) ? 1 : 0), __extension__ ({ if (ads->tcpsocket >= 0) ; else __assert_fail ("ads->tcpsocket >= 0", "check.c", 98, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((ads->tcprecv_skip <= ads->tcprecv.used) ? 1 : 0), __extension__ ({ if (ads->tcprecv_skip <= ads->tcprecv.used) ; else __assert_fail ("ads->tcprecv_skip <= ads->tcprecv.used", "check.c", 99, __extension__ __PRETTY_FUNCTION__); }));
    break;
  default:
    ((void) sizeof ((!"ads->tcpstate value") ? 1 : 0), __extension__ ({ if (!"ads->tcpstate value") ; else __assert_fail ("!\"ads->tcpstate value\"", "check.c", 102, __extension__ __PRETTY_FUNCTION__); }));
  }
  ((void) sizeof ((ads->searchlist || !ads->nsearchlist) ? 1 : 0), __extension__ ({ if (ads->searchlist || !ads->nsearchlist) ; else __assert_fail ("ads->searchlist || !ads->nsearchlist", "check.c", 105, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void checkc_global(struct adns__state *ads) {
  int i;
  ((void) sizeof ((ads->udpsocket >= 0) ? 1 : 0), __extension__ ({ if (ads->udpsocket >= 0) ; else __assert_fail ("ads->udpsocket >= 0", "check.c", 80, __extension__ __PRETTY_FUNCTION__); }));
  for (i=0; i<ads->nsortlist; i++)
    ((void) sizeof ((!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr)) ? 1 : 0), __extension__ ({ if (!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr)) ; else __assert_fail ("!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr)", "check.c", 83, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((ads->tcpserver >= 0 && ads->tcpserver < ads->nservers) ? 1 : 0), __extension__ ({ if (ads->tcpserver >= 0 && ads->tcpserver < ads->nservers) ; else __assert_fail ("ads->tcpserver >= 0 && ads->tcpserver < ads->nservers", "check.c", 85, __extension__ __PRETTY_FUNCTION__); }));
  switch (ads->tcpstate) {
  case server_connecting:
    ((void) sizeof ((ads->tcpsocket >= 0) ? 1 : 0), __extension__ ({ if (ads->tcpsocket >= 0) ; else __assert_fail ("ads->tcpsocket >= 0", "check.c", 89, __extension__ __PRETTY_FUNCTION__); }));
    checkc_notcpbuf(ads);
    break;
  case server_disconnected:
  case server_broken:
    ((void) sizeof ((ads->tcpsocket == -1) ? 1 : 0), __extension__ ({ if (ads->tcpsocket == -1) ; else __assert_fail ("ads->tcpsocket == -1", "check.c", 94, __extension__ __PRETTY_FUNCTION__); }));
    checkc_notcpbuf(ads);
    break;
  case server_ok:
    ((void) sizeof ((ads->tcpsocket >= 0) ? 1 : 0), __extension__ ({ if (ads->tcpsocket >= 0) ; else __assert_fail ("ads->tcpsocket >= 0", "check.c", 98, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((ads->tcprecv_skip <= ads->tcprecv.used) ? 1 : 0), __extension__ ({ if (ads->tcprecv_skip <= ads->tcprecv.used) ; else __assert_fail ("ads->tcprecv_skip <= ads->tcprecv.used", "check.c", 99, __extension__ __PRETTY_FUNCTION__); }));
    break;
  default:
    ((void) sizeof ((!"ads->tcpstate value") ? 1 : 0), __extension__ ({ if (!"ads->tcpstate value") ; else __assert_fail ("!\"ads->tcpstate value\"", "check.c", 102, __extension__ __PRETTY_FUNCTION__); }));
  }
  ((void) sizeof ((ads->searchlist || !ads->nsearchlist) ? 1 : 0), __extension__ ({ if (ads->searchlist || !ads->nsearchlist) ; else __assert_fail ("ads->searchlist || !ads->nsearchlist", "check.c", 105, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: i int

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 sortlist { struct in_addr base; }

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 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 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 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: 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: struct vbuf { int used; unsigned char *buf; }

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


decompiled_code:
__int64 __fastcall checkc_query(__int64 a1, __int64 a2)
{
int v2; // ecx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 152);
if ( *(_DWORD *)(a2 + 208) >= v2 )
_assert_fail("qu->udpnextserver < ads->nservers", "check.c", 0x41u, "checkc_query");
if ( (*(_QWORD *)(a2 + 216) & (-1LL << v2)) != 0 )
_assert_fail("!(qu->udpsent & (~0UL << ads->nservers))", "check.c", 0x42u, "checkc_query");
if ( *(_DWORD *)(a2 + 188) > *(_DWORD *)(a1 + 160) )
_assert_fail("qu->search_pos <= ads->nsearchlist", "check.c", 0x43u, "checkc_query");
result = *(_QWORD *)(a2 + 32);
if ( result )
{
for ( result = *(_QWORD *)(result + 40); a2 != result; result = *(_QWORD *)(result + 64) )
{
if ( !result )
_assert_fail("(child)", "check.c", 0x44u, "checkc_query");
}
}
return result;
}

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

v2 = *(_DWORD *)(a1 + 152);
if ( *(_DWORD *)(a2 + 208) >= v2 )
_assert_fail("qu->udpnextserver < ads->nservers", "check.c", 0x41u, "checkc_query");
if ( (*(_QWORD *)(a2 + 216) & (-1LL << v2)) != 0 )
_assert_fail("!(qu->udpsent & (~0UL << ads->nservers))", "check.c", 0x42u, "checkc_query");
if ( *(_DWORD *)(a2 + 188) > *(_DWORD *)(a1 + 160) )
_assert_fail("qu->search_pos <= ads->nsearchlist", "check.c", 0x43u, "checkc_query");
result = *(_QWORD *)(a2 + 32);
if ( result )
{
for ( result = *(_QWORD *)(result + 40); a2 != result; result = *(_QWORD *)(result + 64) )
{
if ( !result )
_assert_fail("(child)", "check.c", 0x44u, "checkc_query");
}
}
return result;
}

original_code:
static void checkc_query(adns_state ads, adns_query qu) {
  adns_query child;
  ((void) sizeof ((qu->udpnextserver < ads->nservers) ? 1 : 0), __extension__ ({ if (qu->udpnextserver < ads->nservers) ; else __assert_fail ("qu->udpnextserver < ads->nservers", "check.c", 65, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((!(qu->udpsent & (~0UL << ads->nservers))) ? 1 : 0), __extension__ ({ if (!(qu->udpsent & (~0UL << ads->nservers))) ; else __assert_fail ("!(qu->udpsent & (~0UL << ads->nservers))", "check.c", 66, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((qu->search_pos <= ads->nsearchlist) ? 1 : 0), __extension__ ({ if (qu->search_pos <= ads->nsearchlist) ; else __assert_fail ("qu->search_pos <= ads->nsearchlist", "check.c", 67, __extension__ __PRETTY_FUNCTION__); }));
  if (qu->parent) do { for ((child)= (qu->parent->children).head; (child) != (qu); (child)= (child)->siblings. next) { ((void) sizeof (((child)) ? 1 : 0), __extension__ ({ if ((child)) ; else __assert_fail ("(child)", "check.c", 68, __extension__ __PRETTY_FUNCTION__); })); } } while(0);
}

canonical_original_code:
static void checkc_query(struct adns__state *ads, struct adns__query *qu) {
  struct adns__query *child;
  ((void) sizeof ((qu->udpnextserver < ads->nservers) ? 1 : 0), __extension__ ({ if (qu->udpnextserver < ads->nservers) ; else __assert_fail ("qu->udpnextserver < ads->nservers", "check.c", 65, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((!(qu->udpsent & (~0UL << ads->nservers))) ? 1 : 0), __extension__ ({ if (!(qu->udpsent & (~0UL << ads->nservers))) ; else __assert_fail ("!(qu->udpsent & (~0UL << ads->nservers))", "check.c", 66, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((qu->search_pos <= ads->nsearchlist) ? 1 : 0), __extension__ ({ if (qu->search_pos <= ads->nsearchlist) ; else __assert_fail ("qu->search_pos <= ads->nsearchlist", "check.c", 67, __extension__ __PRETTY_FUNCTION__); }));
  if (qu->parent) do { for ((child)= (qu->parent->children).head; (child) != (qu); (child)= (child)->siblings. next) { ((void) sizeof (((child)) ? 1 : 0), __extension__ ({ if ((child)) ; else __assert_fail ("(child)", "check.c", 68, __extension__ __PRETTY_FUNCTION__); })); } } while(0);
}

variable_types:
qu
struct adns__query *

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_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_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 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 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 parseinfo { struct adns__state *ads; struct adns__query *qu; int serv; unsigned char *dgram; int dglen; struct timeval now; }

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

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

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


decompiled_code:
__int64 __fastcall checkc_queue_output(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
__int64 v3; // rsi

v1 = *(_QWORD *)(a1 + 80);
if ( v1 )
{
if ( *(_QWORD *)(v1 + 16) )
_assert_fail("! (ads->output).head-> back", "check.c", 0x97u, "checkc_queue_output");
do
{
v3 = v1;
v1 = *(_QWORD *)(v1 + 24);
if ( v1 )
{
if ( *(_QWORD *)(v1 + 16) != v3 )
goto LABEL_14;
}
else if ( *(_QWORD *)(a1 + 88) != v3 )
{
LABEL_14:
_assert_fail(
"(qu)-> next ? (qu) == (qu)-> next-> back : (qu) == (ads->output).tail",
"check.c",
0x97u,
"checkc_queue_output");
}
if ( *(_DWORD *)(v3 + 8) != 3 )
_assert_fail("qu->state == query_done", "check.c", 0x98u, "checkc_queue_output");
if ( *(_QWORD *)(v3 + 40) || *(_QWORD *)(v3 + 48) )
_assert_fail("!qu->children.head && !qu->children.tail", "check.c", 0x99u, "checkc_queue_output");
if ( *(_QWORD *)(v3 + 32) )
_assert_fail("!qu->parent", "check.c", 0x9Au, "checkc_queue_output");
if ( *(_QWORD *)(v3 + 72) || *(_QWORD *)(v3 + 80) )
_assert_fail("!qu->allocations.head && !qu->allocations.tail", "check.c", 0x9Bu, "checkc_queue_output");
result = checkc_query(a1, v3);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
__int64 v3; // rsi

v1 = *(_QWORD *)(a1 + 80);
if ( v1 )
{
if ( *(_QWORD *)(v1 + 16) )
_assert_fail("! (ads->output).head-> back", "check.c", 0x97u, "checkc_queue_output");
do
{
v3 = v1;
v1 = *(_QWORD *)(v1 + 24);
if ( v1 )
{
if ( *(_QWORD *)(v1 + 16) != v3 )
goto LABEL_14;
}
else if ( *(_QWORD *)(a1 + 88) != v3 )
{
LABEL_14:
_assert_fail(
"(qu)-> next ? (qu) == (qu)-> next-> back : (qu) == (ads->output).tail",
"check.c",
0x97u,
"checkc_queue_output");
}
if ( *(_DWORD *)(v3 + 8) != 3 )
_assert_fail("qu->state == query_done", "check.c", 0x98u, "checkc_queue_output");
if ( *(_QWORD *)(v3 + 40) || *(_QWORD *)(v3 + 48) )
_assert_fail("!qu->children.head && !qu->children.tail", "check.c", 0x99u, "checkc_queue_output");
if ( *(_QWORD *)(v3 + 32) )
_assert_fail("!qu->parent", "check.c", 0x9Au, "checkc_queue_output");
if ( *(_QWORD *)(v3 + 72) || *(_QWORD *)(v3 + 80) )
_assert_fail("!qu->allocations.head && !qu->allocations.tail", "check.c", 0x9Bu, "checkc_queue_output");
result = func2(a1, v3);
}
while ( v1 );
}
return result;
}

original_code:
static void checkc_queue_output(adns_state ads) {
  adns_query qu;
  if ((ads->output).head) { ((void) sizeof ((! (ads->output).head-> back) ? 1 : 0), __extension__ ({ if (! (ads->output).head-> back) ; else __assert_fail ("! (ads->output).head-> back", "check.c", 151, __extension__ __PRETTY_FUNCTION__); })); for ((qu)= (ads->output).head; (qu); (qu)= (qu)-> next) { ((void) sizeof (((qu)-> next ? (qu) == (qu)-> next-> back : (qu) == (ads->output).tail) ? 1 : 0), __extension__ ({ if ((qu)-> next ? (qu) == (qu)-> next-> back : (qu) == (ads->output).tail) ; else __assert_fail ("(qu)-> next ? (qu) == (qu)-> next-> back : (qu) == (ads->output).tail", "check.c", 151, __extension__ __PRETTY_FUNCTION__); })); { ((void) sizeof ((qu->state == query_done) ? 1 : 0), __extension__ ({ if (qu->state == query_done) ; else __assert_fail ("qu->state == query_done", "check.c", 152, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((!qu->children.head && !qu->children.tail) ? 1 : 0), __extension__ ({ if (!qu->children.head && !qu->children.tail) ; else __assert_fail ("!qu->children.head && !qu->children.tail", "check.c", 153, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((!qu->parent) ? 1 : 0), __extension__ ({ if (!qu->parent) ; else __assert_fail ("!qu->parent", "check.c", 154, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((!qu->allocations.head && !qu->allocations.tail) ? 1 : 0), __extension__ ({ if (!qu->allocations.head && !qu->allocations.tail) ; else __assert_fail ("!qu->allocations.head && !qu->allocations.tail", "check.c", 155, __extension__ __PRETTY_FUNCTION__); })); checkc_query(ads,qu); } } };
}

canonical_original_code:
static void checkc_queue_output(struct adns__state *ads) {
  struct adns__query *qu;
  if ((ads->output).head) { ((void) sizeof ((! (ads->output).head-> back) ? 1 : 0), __extension__ ({ if (! (ads->output).head-> back) ; else __assert_fail ("! (ads->output).head-> back", "check.c", 151, __extension__ __PRETTY_FUNCTION__); })); for ((qu)= (ads->output).head; (qu); (qu)= (qu)-> next) { ((void) sizeof (((qu)-> next ? (qu) == (qu)-> next-> back : (qu) == (ads->output).tail) ? 1 : 0), __extension__ ({ if ((qu)-> next ? (qu) == (qu)-> next-> back : (qu) == (ads->output).tail) ; else __assert_fail ("(qu)-> next ? (qu) == (qu)-> next-> back : (qu) == (ads->output).tail", "check.c", 151, __extension__ __PRETTY_FUNCTION__); })); { ((void) sizeof ((qu->state == query_done) ? 1 : 0), __extension__ ({ if (qu->state == query_done) ; else __assert_fail ("qu->state == query_done", "check.c", 152, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((!qu->children.head && !qu->children.tail) ? 1 : 0), __extension__ ({ if (!qu->children.head && !qu->children.tail) ; else __assert_fail ("!qu->children.head && !qu->children.tail", "check.c", 153, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((!qu->parent) ? 1 : 0), __extension__ ({ if (!qu->parent) ; else __assert_fail ("!qu->parent", "check.c", 154, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((!qu->allocations.head && !qu->allocations.tail) ? 1 : 0), __extension__ ({ if (!qu->allocations.head && !qu->allocations.tail) ; else __assert_fail ("!qu->allocations.head && !qu->allocations.tail", "check.c", 155, __extension__ __PRETTY_FUNCTION__); })); checkc_query(ads,qu); } } };
}

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 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: 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 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 __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 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 vbuf { int used; unsigned char *buf; }

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

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


decompiled_code:
void __fastcall checkc_queue_childw(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rdx

v1 = *(_QWORD *)(a1 + 64);
if ( v1 )
{
if ( *(_QWORD *)(v1 + 16) )
_assert_fail("! (ads->childw).head-> back", "check.c", 0x88u, "checkc_queue_childw");
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 24);
if ( v1 )
{
if ( *(_QWORD *)(v1 + 16) != v2 )
goto LABEL_19;
}
else if ( *(_QWORD *)(a1 + 72) != v2 )
{
LABEL_19:
_assert_fail(
"(parent)-> next ? (parent) == (parent)-> next-> back : (parent) == (ads->childw).tail",
"check.c",
0x88u,
"checkc_queue_childw");
}
if ( *(_DWORD *)(v2 + 8) != 2 )
_assert_fail("parent->state == query_childw", "check.c", 0x89u, "checkc_queue_childw");
v3 = *(_QWORD *)(v2 + 40);
if ( !v3 )
_assert_fail("parent->children.head", "check.c", 0x8Au, "checkc_queue_childw");
if ( *(_QWORD *)(v3 + 56) )
_assert_fail("! (parent->children).head->siblings. back", "check.c", 0x8Bu, "checkc_queue_childw");
do
{
v4 = v3;
v3 = *(_QWORD *)(v3 + 64);
if ( v3 )
{
if ( *(_QWORD *)(v3 + 56) != v4 )
goto LABEL_15;
}
else if ( *(_QWORD *)(v2 + 48) != v4 )
{
LABEL_15:
_assert_fail(
"(child)->siblings. next ? (child) == (child)->siblings. next->siblings. back : (child) == (parent->children).tail",
"check.c",
0x8Bu,
"checkc_queue_childw");
}
if ( *(_QWORD *)(v4 + 32) != v2 )
_assert_fail("child->parent == parent", "check.c", 0x8Cu, "checkc_queue_childw");
if ( *(_DWORD *)(v4 + 8) == 3 )
_assert_fail("child->state != query_done", "check.c", 0x8Du, "checkc_queue_childw");
}
while ( v3 );
checkc_query(a1, v2);
checkc_query_alloc_constprop_0(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rdx

v1 = *(_QWORD *)(a1 + 64);
if ( v1 )
{
if ( *(_QWORD *)(v1 + 16) )
_assert_fail("! (ads->childw).head-> back", "check.c", 0x88u, "checkc_queue_childw");
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 24);
if ( v1 )
{
if ( *(_QWORD *)(v1 + 16) != v2 )
goto LABEL_19;
}
else if ( *(_QWORD *)(a1 + 72) != v2 )
{
LABEL_19:
_assert_fail(
"(parent)-> next ? (parent) == (parent)-> next-> back : (parent) == (ads->childw).tail",
"check.c",
0x88u,
"checkc_queue_childw");
}
if ( *(_DWORD *)(v2 + 8) != 2 )
_assert_fail("parent->state == query_childw", "check.c", 0x89u, "checkc_queue_childw");
v3 = *(_QWORD *)(v2 + 40);
if ( !v3 )
_assert_fail("parent->children.head", "check.c", 0x8Au, "checkc_queue_childw");
if ( *(_QWORD *)(v3 + 56) )
_assert_fail("! (parent->children).head->siblings. back", "check.c", 0x8Bu, "checkc_queue_childw");
do
{
v4 = v3;
v3 = *(_QWORD *)(v3 + 64);
if ( v3 )
{
if ( *(_QWORD *)(v3 + 56) != v4 )
goto LABEL_15;
}
else if ( *(_QWORD *)(v2 + 48) != v4 )
{
LABEL_15:
_assert_fail(
"(child)->siblings. next ? (child) == (child)->siblings. next->siblings. back : (child) == (parent->children).tail",
"check.c",
0x8Bu,
"checkc_queue_childw");
}
if ( *(_QWORD *)(v4 + 32) != v2 )
_assert_fail("child->parent == parent", "check.c", 0x8Cu, "checkc_queue_childw");
if ( *(_DWORD *)(v4 + 8) == 3 )
_assert_fail("child->state != query_done", "check.c", 0x8Du, "checkc_queue_childw");
}
while ( v3 );
func2(a1, v2);
checkc_query_alloc_constprop_0(v2);
}
while ( v1 );
}
}

original_code:
static void checkc_queue_childw(adns_state ads) {
  adns_query parent, child;
  if ((ads->childw).head) { ((void) sizeof ((! (ads->childw).head-> back) ? 1 : 0), __extension__ ({ if (! (ads->childw).head-> back) ; else __assert_fail ("! (ads->childw).head-> back", "check.c", 136, __extension__ __PRETTY_FUNCTION__); })); for ((parent)= (ads->childw).head; (parent); (parent)= (parent)-> next) { ((void) sizeof (((parent)-> next ? (parent) == (parent)-> next-> back : (parent) == (ads->childw).tail) ? 1 : 0), __extension__ ({ if ((parent)-> next ? (parent) == (parent)-> next-> back : (parent) == (ads->childw).tail) ; else __assert_fail ("(parent)-> next ? (parent) == (parent)-> next-> back : (parent) == (ads->childw).tail", "check.c", 136, __extension__ __PRETTY_FUNCTION__); })); { ((void) sizeof ((parent->state == query_childw) ? 1 : 0), __extension__ ({ if (parent->state == query_childw) ; else __assert_fail ("parent->state == query_childw", "check.c", 137, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((parent->children.head) ? 1 : 0), __extension__ ({ if (parent->children.head) ; else __assert_fail ("parent->children.head", "check.c", 138, __extension__ __PRETTY_FUNCTION__); })); if ((parent->children).head) { ((void) sizeof ((! (parent->children).head->siblings. back) ? 1 : 0), __extension__ ({ if (! (parent->children).head->siblings. back) ; else __assert_fail ("! (parent->children).head->siblings. back", "check.c", 139, __extension__ __PRETTY_FUNCTION__); })); for ((child)= (parent->children).head; (child); (child)= (child)->siblings. next) { ((void) sizeof (((child)->siblings. next ? (child) == (child)->siblings. next->siblings. back : (child) == (parent->children).tail) ? 1 : 0), __extension__ ({ if ((child)->siblings. next ? (child) == (child)->siblings. next->siblings. back : (child) == (parent->children).tail) ; else __assert_fail ("(child)->siblings. next ? (child) == (child)->siblings. next->siblings. back : (child) == (parent->children).tail", "check.c", 139, __extension__ __PRETTY_FUNCTION__); })); { ((void) sizeof ((child->parent == parent) ? 1 : 0), __extension__ ({ if (child->parent == parent) ; else __assert_fail ("child->parent == parent", "check.c", 140, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((child->state != query_done) ? 1 : 0), __extension__ ({ if (child->state != query_done) ; else __assert_fail ("child->state != query_done", "check.c", 141, __extension__ __PRETTY_FUNCTION__); })); } } }; checkc_query(ads,parent); checkc_query_alloc(ads,parent); } } };
}

canonical_original_code:
static void checkc_queue_childw(struct adns__state *ads) {
  struct adns__query *parent; struct adns__query *child;
  if ((ads->childw).head) { ((void) sizeof ((! (ads->childw).head-> back) ? 1 : 0), __extension__ ({ if (! (ads->childw).head-> back) ; else __assert_fail ("! (ads->childw).head-> back", "check.c", 136, __extension__ __PRETTY_FUNCTION__); })); for ((parent)= (ads->childw).head; (parent); (parent)= (parent)-> next) { ((void) sizeof (((parent)-> next ? (parent) == (parent)-> next-> back : (parent) == (ads->childw).tail) ? 1 : 0), __extension__ ({ if ((parent)-> next ? (parent) == (parent)-> next-> back : (parent) == (ads->childw).tail) ; else __assert_fail ("(parent)-> next ? (parent) == (parent)-> next-> back : (parent) == (ads->childw).tail", "check.c", 136, __extension__ __PRETTY_FUNCTION__); })); { ((void) sizeof ((parent->state == query_childw) ? 1 : 0), __extension__ ({ if (parent->state == query_childw) ; else __assert_fail ("parent->state == query_childw", "check.c", 137, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((parent->children.head) ? 1 : 0), __extension__ ({ if (parent->children.head) ; else __assert_fail ("parent->children.head", "check.c", 138, __extension__ __PRETTY_FUNCTION__); })); if ((parent->children).head) { ((void) sizeof ((! (parent->children).head->siblings. back) ? 1 : 0), __extension__ ({ if (! (parent->children).head->siblings. back) ; else __assert_fail ("! (parent->children).head->siblings. back", "check.c", 139, __extension__ __PRETTY_FUNCTION__); })); for ((child)= (parent->children).head; (child); (child)= (child)->siblings. next) { ((void) sizeof (((child)->siblings. next ? (child) == (child)->siblings. next->siblings. back : (child) == (parent->children).tail) ? 1 : 0), __extension__ ({ if ((child)->siblings. next ? (child) == (child)->siblings. next->siblings. back : (child) == (parent->children).tail) ; else __assert_fail ("(child)->siblings. next ? (child) == (child)->siblings. next->siblings. back : (child) == (parent->children).tail", "check.c", 139, __extension__ __PRETTY_FUNCTION__); })); { ((void) sizeof ((child->parent == parent) ? 1 : 0), __extension__ ({ if (child->parent == parent) ; else __assert_fail ("child->parent == parent", "check.c", 140, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((child->state != query_done) ? 1 : 0), __extension__ ({ if (child->state != query_done) ; else __assert_fail ("child->state != query_done", "check.c", 141, __extension__ __PRETTY_FUNCTION__); })); } } }; checkc_query(ads,parent); checkc_query_alloc(ads,parent); } } };
}

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_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_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 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 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 parseinfo { struct adns__state *ads; struct adns__query *qu; int serv; unsigned char *dgram; int dglen; struct timeval now; }

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

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

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