decompiled_code:
void __fastcall checkc_notcpbuf(_DWORD *a1)
{
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");
if ( a1[43] )
_assert_fail("!ads->tcprecv_skip", "check.c", 0x4Au, "checkc_notcpbuf");
}

canonical_decompiled_code:
void __fastcall func0(_DWORD *a1)
{
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");
if ( a1[43] )
_assert_fail("!ads->tcprecv_skip", "check.c", 0x4Au, "checkc_notcpbuf");
}

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

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: 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_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 adns_rr_intstr { int i; char *str; }

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

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

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:
void __fastcall checkc_global(__int64 a1)
{
int v1; // eax
_DWORD *v2; // rdx
int v3; // eax
unsigned int v4; // eax

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:
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");
if ( *(_DWORD *)(a1 + 172) > *(_DWORD *)(a1 + 136) )
_assert_fail("ads->tcprecv_skip <= ads->tcprecv.used", "check.c", 0x63u, "checkc_global");
LABEL_13:
if ( !*(_QWORD *)(a1 + 640) )
{
if ( *(_DWORD *)(a1 + 160) )
_assert_fail("ads->searchlist || !ads->nsearchlist", "check.c", 0x69u, "checkc_global");
}
}

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

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:
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");
if ( *(_DWORD *)(a1 + 172) > *(_DWORD *)(a1 + 136) )
_assert_fail("ads->tcprecv_skip <= ads->tcprecv.used", "check.c", 0x63u, "checkc_global");
LABEL_13:
if ( !*(_QWORD *)(a1 + 640) )
{
if ( *(_DWORD *)(a1 + 160) )
_assert_fail("ads->searchlist || !ads->nsearchlist", "check.c", 0x69u, "checkc_global");
}
}

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: 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: i int

return_type: void

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


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 )
{
result = *(_QWORD *)(result + 40);
if ( a2 != result )
{
if ( !result )
LABEL_9:
_assert_fail("(child)", "check.c", 0x44u, "checkc_query");
while ( 1 )
{
result = *(_QWORD *)(result + 64);
if ( a2 == result )
break;
if ( !result )
goto LABEL_9;
}
}
}
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 )
{
result = *(_QWORD *)(result + 40);
if ( a2 != result )
{
if ( !result )
LABEL_9:
_assert_fail("(child)", "check.c", 0x44u, "checkc_query");
while ( 1 )
{
result = *(_QWORD *)(result + 64);
if ( a2 == result )
break;
if ( !result )
goto LABEL_9;
}
}
}
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 *

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


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

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

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

v1 = *(_QWORD *)(a1 + 64);
if ( v1 )
{
if ( *(_QWORD *)(v1 + 16) )
_assert_fail("! (ads->childw).head-> back", "check.c", 0x88u, "checkc_queue_childw");
do
{
v4 = v1;
v1 = *(_QWORD *)(v1 + 24);
if ( v1 )
{
if ( *(_QWORD *)(v1 + 16) != v4 )
LABEL_5:
_assert_fail(
"(parent)-> next ? (parent) == (parent)-> next-> back : (parent) == (ads->childw).tail",
"check.c",
0x88u,
"checkc_queue_childw");
}
else if ( *(_QWORD *)(a1 + 72) != v4 )
{
goto LABEL_5;
}
if ( *(_DWORD *)(v4 + 8) != 2 )
_assert_fail("parent->state == query_childw", "check.c", 0x89u, "checkc_queue_childw");
v3 = *(_QWORD *)(v4 + 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
{
v2 = v3;
v3 = *(_QWORD *)(v3 + 64);
if ( v3 )
{
if ( *(_QWORD *)(v3 + 56) != v2 )
LABEL_14:
_assert_fail(
"(child)->siblings. next ? (child) == (child)->siblings. next->siblings. back : (child) == (parent->children).tail",
"check.c",
0x8Bu,
"checkc_queue_childw");
}
else if ( *(_QWORD *)(v4 + 48) != v2 )
{
goto LABEL_14;
}
if ( *(_QWORD *)(v2 + 32) != v4 )
_assert_fail("child->parent == parent", "check.c", 0x8Cu, "checkc_queue_childw");
if ( *(_DWORD *)(v2 + 8) == 3 )
_assert_fail("child->state != query_done", "check.c", 0x8Du, "checkc_queue_childw");
}
while ( v3 );
func2(a1, v4);
checkc_query_alloc(a1, v4);
}
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: 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 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 vbuf { int used; unsigned char *buf; }

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


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 )
LABEL_14:
_assert_fail(
"(qu)-> next ? (qu) == (qu)-> next-> back : (qu) == (ads->output).tail",
"check.c",
0x97u,
"checkc_queue_output");
}
else if ( *(_QWORD *)(a1 + 88) != v3 )
{
goto LABEL_14;
}
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 func4(__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 )
LABEL_14:
_assert_fail(
"(qu)-> next ? (qu) == (qu)-> next-> back : (qu) == (ads->output).tail",
"check.c",
0x97u,
"checkc_queue_output");
}
else if ( *(_QWORD *)(a1 + 88) != v3 )
{
goto LABEL_14;
}
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: 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 timeval { long tv_sec; long tv_usec; }

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_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:
void __fastcall adns__consistency(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // eax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

if ( a3 == 1 )
{
if ( (*(_DWORD *)a1 & 0x100) == 0 )
return;
}
else if ( a3 == 2 )
{
if ( (*(_DWORD *)a1 & 0x300) != 768 )
return;
}
else if ( a3 )
{
abort();
}
checkc_global(a1);
checkc_queue_udpw(a1);
checkc_queue_tcpw(a1);
checkc_queue_childw(a1);
checkc_queue_output(a1);
if ( a2 )
{
v3 = *(_DWORD *)(a2 + 8);
if ( v3 == 2 )
{
v7 = *(_QWORD *)(a1 + 64);
if ( a2 != v7 )
{
if ( !v7 )
LABEL_33:
_assert_fail("(search)", "check.c", 0xBFu, "adns__consistency");
while ( 1 )
{
v7 = *(_QWORD *)(v7 + 24);
if ( a2 == v7 )
break;
if ( !v7 )
goto LABEL_33;
}
}
}
else if ( v3 > 2 )
{
if ( v3 != 3 )
_assert_fail("!\"specific query state\"", "check.c", 0xC5u, "adns__consistency");
v5 = *(_QWORD *)(a1 + 80);
if ( a2 != v5 )
{
if ( !v5 )
LABEL_23:
_assert_fail("(search)", "check.c", 0xC2u, "adns__consistency");
while ( 1 )
{
v5 = *(_QWORD *)(v5 + 24);
if ( a2 == v5 )
break;
if ( !v5 )
goto LABEL_23;
}
}
}
else if ( v3 )
{
v4 = *(_QWORD *)(a1 + 48);
if ( a2 != v4 )
{
if ( !v4 )
LABEL_14:
_assert_fail("(search)", "check.c", 0xBCu, "adns__consistency");
while ( 1 )
{
v4 = *(_QWORD *)(v4 + 24);
if ( a2 == v4 )
break;
if ( !v4 )
goto LABEL_14;
}
}
}
else
{
v6 = *(_QWORD *)(a1 + 32);
if ( a2 != v6 )
{
if ( !v6 )
LABEL_28:
_assert_fail("(search)", "check.c", 0xB9u, "adns__consistency");
while ( 1 )
{
v6 = *(_QWORD *)(v6 + 24);
if ( a2 == v6 )
break;
if ( !v6 )
goto LABEL_28;
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // eax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

if ( a3 == 1 )
{
if ( (*(_DWORD *)a1 & 0x100) == 0 )
return;
}
else if ( a3 == 2 )
{
if ( (*(_DWORD *)a1 & 0x300) != 768 )
return;
}
else if ( a3 )
{
abort();
}
func1(a1);
checkc_queue_udpw(a1);
checkc_queue_tcpw(a1);
func3(a1);
func4(a1);
if ( a2 )
{
v3 = *(_DWORD *)(a2 + 8);
if ( v3 == 2 )
{
v7 = *(_QWORD *)(a1 + 64);
if ( a2 != v7 )
{
if ( !v7 )
LABEL_33:
_assert_fail("(search)", "check.c", 0xBFu, "adns__consistency");
while ( 1 )
{
v7 = *(_QWORD *)(v7 + 24);
if ( a2 == v7 )
break;
if ( !v7 )
goto LABEL_33;
}
}
}
else if ( v3 > 2 )
{
if ( v3 != 3 )
_assert_fail("!\"specific query state\"", "check.c", 0xC5u, "adns__consistency");
v5 = *(_QWORD *)(a1 + 80);
if ( a2 != v5 )
{
if ( !v5 )
LABEL_23:
_assert_fail("(search)", "check.c", 0xC2u, "adns__consistency");
while ( 1 )
{
v5 = *(_QWORD *)(v5 + 24);
if ( a2 == v5 )
break;
if ( !v5 )
goto LABEL_23;
}
}
}
else if ( v3 )
{
v4 = *(_QWORD *)(a1 + 48);
if ( a2 != v4 )
{
if ( !v4 )
LABEL_14:
_assert_fail("(search)", "check.c", 0xBCu, "adns__consistency");
while ( 1 )
{
v4 = *(_QWORD *)(v4 + 24);
if ( a2 == v4 )
break;
if ( !v4 )
goto LABEL_14;
}
}
}
else
{
v6 = *(_QWORD *)(a1 + 32);
if ( a2 != v6 )
{
if ( !v6 )
LABEL_28:
_assert_fail("(search)", "check.c", 0xB9u, "adns__consistency");
while ( 1 )
{
v6 = *(_QWORD *)(v6 + 24);
if ( a2 == v6 )
break;
if ( !v6 )
goto LABEL_28;
}
}
}
}
}

original_code:
void adns__consistency(adns_state ads, adns_query qu, consistency_checks cc) {
  adns_query search;
  switch (cc) {
  case cc_user:
    break;
  case cc_entex:
    if (!(ads->iflags & adns_if_checkc_entex)) return;
    break;
  case cc_freq:
    if ((ads->iflags & adns_if_checkc_freq) != adns_if_checkc_freq) return;
    break;
  default:
    abort();
  }
  checkc_global(ads);
  checkc_queue_udpw(ads);
  checkc_queue_tcpw(ads);
  checkc_queue_childw(ads);
  checkc_queue_output(ads);
  if (qu) {
    switch (qu->state) {
    case query_tosend:
      do { for ((search)= (ads->udpw).head; (search) != (qu); (search)= (search)-> next) { ((void) sizeof (((search)) ? 1 : 0), __extension__ ({ if ((search)) ; else __assert_fail ("(search)", "check.c", 185, __extension__ __PRETTY_FUNCTION__); })); } } while(0);
      break;
    case query_tcpw:
      do { for ((search)= (ads->tcpw).head; (search) != (qu); (search)= (search)-> next) { ((void) sizeof (((search)) ? 1 : 0), __extension__ ({ if ((search)) ; else __assert_fail ("(search)", "check.c", 188, __extension__ __PRETTY_FUNCTION__); })); } } while(0);
      break;
    case query_childw:
      do { for ((search)= (ads->childw).head; (search) != (qu); (search)= (search)-> next) { ((void) sizeof (((search)) ? 1 : 0), __extension__ ({ if ((search)) ; else __assert_fail ("(search)", "check.c", 191, __extension__ __PRETTY_FUNCTION__); })); } } while(0);
      break;
    case query_done:
      do { for ((search)= (ads->output).head; (search) != (qu); (search)= (search)-> next) { ((void) sizeof (((search)) ? 1 : 0), __extension__ ({ if ((search)) ; else __assert_fail ("(search)", "check.c", 194, __extension__ __PRETTY_FUNCTION__); })); } } while(0);
      break;
    default:
      ((void) sizeof ((!"specific query state") ? 1 : 0), __extension__ ({ if (!"specific query state") ; else __assert_fail ("!\"specific query state\"", "check.c", 197, __extension__ __PRETTY_FUNCTION__); }));
    }
  }
}

canonical_original_code:
void adns__consistency(struct adns__state *ads, struct adns__query *qu, enum consistency_checks cc) {
  struct adns__query *search;
  switch (cc) {
  case cc_user:
    break;
  case cc_entex:
    if (!(ads->iflags & adns_if_checkc_entex)) return;
    break;
  case cc_freq:
    if ((ads->iflags & adns_if_checkc_freq) != adns_if_checkc_freq) return;
    break;
  default:
    abort();
  }
  checkc_global(ads);
  checkc_queue_udpw(ads);
  checkc_queue_tcpw(ads);
  checkc_queue_childw(ads);
  checkc_queue_output(ads);
  if (qu) {
    switch (qu->state) {
    case query_tosend:
      do { for ((search)= (ads->udpw).head; (search) != (qu); (search)= (search)-> next) { ((void) sizeof (((search)) ? 1 : 0), __extension__ ({ if ((search)) ; else __assert_fail ("(search)", "check.c", 185, __extension__ __PRETTY_FUNCTION__); })); } } while(0);
      break;
    case query_tcpw:
      do { for ((search)= (ads->tcpw).head; (search) != (qu); (search)= (search)-> next) { ((void) sizeof (((search)) ? 1 : 0), __extension__ ({ if ((search)) ; else __assert_fail ("(search)", "check.c", 188, __extension__ __PRETTY_FUNCTION__); })); } } while(0);
      break;
    case query_childw:
      do { for ((search)= (ads->childw).head; (search) != (qu); (search)= (search)-> next) { ((void) sizeof (((search)) ? 1 : 0), __extension__ ({ if ((search)) ; else __assert_fail ("(search)", "check.c", 191, __extension__ __PRETTY_FUNCTION__); })); } } while(0);
      break;
    case query_done:
      do { for ((search)= (ads->output).head; (search) != (qu); (search)= (search)-> next) { ((void) sizeof (((search)) ? 1 : 0), __extension__ ({ if ((search)) ; else __assert_fail ("(search)", "check.c", 194, __extension__ __PRETTY_FUNCTION__); })); } } while(0);
      break;
    default:
      ((void) sizeof ((!"specific query state") ? 1 : 0), __extension__ ({ if (!"specific query state") ; else __assert_fail ("!\"specific query state\"", "check.c", 197, __extension__ __PRETTY_FUNCTION__); }));
    }
  }
}

variable_types: enum consistency_checks { cc_user=0, cc_entex=1, cc_freq=2 }

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__tcpstate { server_disconnected=0, server_connecting=1, server_ok=2, server_broken=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: 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 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: 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_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; }


decompiled_code:
void __fastcall adns_checkconsistency(__int64 a1, __int64 a2)
{
adns__consistency(a1, a2, 0);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, __int64 a2)
{
func5(a1, a2, 0);
}

original_code:
void adns_checkconsistency(adns_state ads, adns_query qu) {
  adns__consistency(ads,qu,cc_user);
}

canonical_original_code:
void adns_checkconsistency(struct adns__state *ads, struct adns__query *qu) {
  adns__consistency(ads,qu,cc_user);
}

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: 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 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 timeval { long tv_sec; long tv_usec; }

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 si_compar(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 >= *(_DWORD *)a2 )
result = *(_DWORD *)a1 > *(_DWORD *)a2;
return result;
}

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

result = 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 >= *(_DWORD *)a2 )
result = *(_DWORD *)a1 > *(_DWORD *)a2;
return result;
}

original_code:
static int si_compar(const void *key, const void *elem) {
  const adns_status *st= key;
  const struct sinfo *si= elem;
  return *st < si->st ? -1 : *st > si->st ? 1 : 0;
}

canonical_original_code:
static int si_compar(void *key, void *elem) {
  enum adns_status *st = key;
  struct sinfo *si = elem;
  return *st < si->st ? -1 : *st > si->st ? 1 : 0;
}

variable_types:
key
void *

variable_types:
elem
void *

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

variable_types: struct sinfo { 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 } st; char *abbrev; char *string; } *

return_type: int

user_defined_types: struct sinfo { enum adns_status st; char *abbrev; char *string; }


decompiled_code:
__int64 __fastcall sti_compar(const void *a1, const void *a2)
{
unsigned int v2; // ecx
unsigned int v3; // edi
unsigned int v4; // edx

v2 = *(_DWORD *)a1;
if ( a2 == &stinfos )
{
v3 = 0;
return v2 > v3;
}
v3 = *(_DWORD *)a2;
v4 = -1;
if ( v2 >= *((_DWORD *)a2 - 4) + 1 )
return v2 > v3;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1, const void *a2)
{
unsigned int v2; // ecx
unsigned int v3; // edi
unsigned int v4; // edx

v2 = *(_DWORD *)a1;
if ( a2 == &stinfos )
{
v3 = 0;
return v2 > v3;
}
v3 = *(_DWORD *)a2;
v4 = -1;
if ( v2 >= *((_DWORD *)a2 - 4) + 1 )
return v2 > v3;
return v4;
}

original_code:
static int sti_compar(const void *key, const void *elem) {
  const adns_status *st= key;
  const struct stinfo *sti= elem;
  adns_status here, min, max;
  here= *st;
  min= (sti==stinfos) ? 0 : sti[-1].stmax+1;
  max= sti->stmax;
  return here < min ? -1 : here > max ? 1 : 0;
}

canonical_original_code:
static int sti_compar(void *key, void *elem) {
  enum adns_status *st = key;
  struct stinfo *sti = elem;
  enum adns_status here; enum adns_status min; enum adns_status max;
  here= *st;
  min= (sti==stinfos) ? 0 : sti[-1].stmax+1;
  max= sti->stmax;
  return here < min ? -1 : here > max ? 1 : 0;
}

variable_types: struct stinfo { 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 } stmax; char *abbrev; } *

user_defined_types: struct stinfo { enum adns_status stmax; char *abbrev; }


findsinfo

decompiled_code:
void *__fastcall findsinfo(int a1)
{
int key[3]; // [rsp+Ch] [rbp-Ch] BYREF

key[0] = a1;
return bsearch(key, &sinfos, 0x18uLL, 0x18uLL, (__compar_fn_t)si_compar);
}

canonical_decompiled_code:
void *__fastcall func2(int a1)
{
int key[3]; // [rsp+Ch] [rbp-Ch] BYREF

key[0] = a1;
return bsearch(key, &sinfos, 0x18uLL, 0x18uLL, (__compar_fn_t)si_compar);
}

original_code:
static const struct sinfo *findsinfo(adns_status st) {
  return bsearch(&st,sinfos, sizeof(sinfos)/sizeof(*sinfos),
   sizeof(*sinfos), si_compar);
}

canonical_original_code:
static struct sinfo *findsinfo(enum adns_status st) {
  return bsearch(&st,sinfos, sizeof(sinfos)/sizeof(*sinfos),
   sizeof(*sinfos), si_compar);
}

return_type: struct sinfo { 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 } st; char *abbrev; char *string; } *


original_code:
void adns__vlprintf(adns_state ads, const char *fmt, va_list al) {
  ads->logfn(ads,ads->logfndata,fmt,al);
}

canonical_original_code:
void adns__vlprintf(struct adns__state *ads, char *fmt, __builtin_va_list al) {
  ads->logfn(ads,ads->logfndata,fmt,al);
}

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


decompiled_code:
__int64 adns__lprintf(__int64 a1, __int64 a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return adns__vlprintf(a1, a2, (__int64)va);
}

canonical_decompiled_code:
__int64 func4(__int64 a1, __int64 a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return func3(a1, a2, (__int64)va);
}

original_code:
void adns__lprintf(adns_state ads, const char *fmt, ...) {
  va_list al;
  __builtin_va_start(al,fmt);
  adns__vlprintf(ads,fmt,al);
  __builtin_va_end(al);
}

canonical_original_code:
void adns__lprintf(struct adns__state *ads, char *fmt, ...) {
  __builtin_va_list al;
  __builtin_va_start(al,fmt);
  adns__vlprintf(ads,fmt,al);
  __builtin_va_end(al);
}

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: 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 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 timeval { long tv_sec; long tv_usec; }

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:
void adns__vbuf_init(vbuf *vb) {
  vb->used= vb->avail= 0; vb->buf= 0;
}

canonical_original_code:
void adns__vbuf_init(struct vbuf *vb) {
  vb->used= vb->avail= 0; vb->buf= 0;
}

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


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

result = 1LL;
if ( *(_DWORD *)(a1 + 4) < a2 )
{
v3 = realloc(*(void **)(a1 + 8), a2);
if ( v3 )
{
*(_QWORD *)(a1 + 8) = v3;
*(_DWORD *)(a1 + 4) = a2;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

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

result = 1LL;
if ( *(_DWORD *)(a1 + 4) < a2 )
{
v3 = realloc(*(void **)(a1 + 8), a2);
if ( v3 )
{
*(_QWORD *)(a1 + 8) = v3;
*(_DWORD *)(a1 + 4) = a2;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int adns__vbuf_ensure(vbuf *vb, int want) {
  void *nb;
  if (vb->avail >= want) return 1;
  nb= realloc(vb->buf,want); if (!nb) return 0;
  vb->buf= nb;
  vb->avail= want;
  return 1;
}

canonical_original_code:
int adns__vbuf_ensure(struct vbuf *vb, int want) {
  void *nb;
  if (vb->avail >= want) return 1;
  nb= realloc(vb->buf,want); if (!nb) return 0;
  vb->buf= nb;
  vb->avail= want;
  return 1;
}

variable_types: want int

variable_types:
nb
void *

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


decompiled_code:
void *__fastcall adns__vbuf_appendq(int *a1, const void *a2, int a3)
{
void *result; // rax

result = memcpy((void *)(*((_QWORD *)a1 + 1) + *a1), a2, a3);
*a1 += a3;
return result;
}

canonical_decompiled_code:
void *__fastcall func7(int *a1, const void *a2, int a3)
{
void *result; // rax

result = memcpy((void *)(*((_QWORD *)a1 + 1) + *a1), a2, a3);
*a1 += a3;
return result;
}

original_code:
void adns__vbuf_appendq(vbuf *vb, const byte *data, int len) {
  memcpy(vb->buf+vb->used,data,len);
  vb->used+= len;
}

canonical_original_code:
void adns__vbuf_appendq(struct vbuf *vb, unsigned char *data, int len) {
  memcpy(vb->buf+vb->used,data,len);
  vb->used+= len;
}

variable_types:
data
unsigned char *

variable_types: len int


decompiled_code:
__int64 __fastcall adns__vbuf_append(__int64 a1, const void *a2, int a3)
{
int v4; // eax
int v5; // ebp
void *v6; // rax
unsigned int v7; // edx

v4 = *(_DWORD *)a1 + a3;
if ( *(_DWORD *)(a1 + 4) >= v4 )
goto LABEL_6;
if ( v4 < 20 )
v4 = 20;
v5 = 2 * v4;
v6 = realloc(*(void **)(a1 + 8), 2 * v4);
if ( v6 || (v5 = *(_DWORD *)a1 + a3, v6 = realloc(*(void **)(a1 + 8), v5), v7 = 0, v6) )
{
*(_QWORD *)(a1 + 8) = v6;
*(_DWORD *)(a1 + 4) = v5;
LABEL_6:
adns__vbuf_appendq((int *)a1, a2, a3);
v7 = 1;
}
return v7;
}

original_code:
int adns__vbuf_append(vbuf *vb, const byte *data, int len) {
  int newlen;
  void *nb;
  newlen= vb->used+len;
  if (vb->avail < newlen) {
    if (newlen<20) newlen= 20;
    newlen <<= 1;
    nb= realloc(vb->buf,newlen);
    if (!nb) { newlen= vb->used+len; nb= realloc(vb->buf,newlen); }
    if (!nb) return 0;
    vb->buf= nb;
    vb->avail= newlen;
  }
  adns__vbuf_appendq(vb,data,len);
  return 1;
}

canonical_original_code:
int adns__vbuf_append(struct vbuf *vb, unsigned char *data, int len) {
  int newlen;
  void *nb;
  newlen= vb->used+len;
  if (vb->avail < newlen) {
    if (newlen<20) newlen= 20;
    newlen <<= 1;
    nb= realloc(vb->buf,newlen);
    if (!nb) { newlen= vb->used+len; nb= realloc(vb->buf,newlen); }
    if (!nb) return 0;
    vb->buf= nb;
    vb->avail= newlen;
  }
  adns__vbuf_appendq(vb,data,len);
  return 1;
}

variable_types: newlen int


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

v2 = strlen(a2);
return adns__vbuf_append(a1, a2, v2);
}

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

v2 = strlen(a2);
return func8(a1, a2, v2);
}

original_code:
int adns__vbuf_appendstr(vbuf *vb, const char *data) {
  int l;
  l= strlen(data);
  return adns__vbuf_append(vb,data,l);
}

canonical_original_code:
int adns__vbuf_appendstr(struct vbuf *vb, char *data) {
  int l;
  l= strlen(data);
  return adns__vbuf_append(vb,data,l);
}

variable_types:
data
char *

variable_types: l int


decompiled_code:
void __fastcall adns__vbuf_free(__int64 a1)
{
free(*(void **)(a1 + 8));
adns__vbuf_init(a1);
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
free(*(void **)(a1 + 8));
func5(a1);
}

original_code:
void adns__vbuf_free(vbuf *vb) {
  free(vb->buf);
  adns__vbuf_init(vb);
}

canonical_original_code:
void adns__vbuf_free(struct vbuf *vb) {
  free(vb->buf);
  adns__vbuf_init(vb);
}