decompiled_code:
void __fastcall adns__consistency(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // eax
__int64 k; // rax
__int64 j; // rax
__int64 l; // rax
__int64 i; // rax

if ( a3 == 1 )
{
if ( (*(_DWORD *)a1 & 0x100) == 0 )
return;
}
else if ( a3 == 2 )
{
if ( (*(_DWORD *)a1 & 0x300) != 768 )
return;
}
else if ( a3 )
{
adns__consistency_cold();
}
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 )
{
for ( i = *(_QWORD *)(a1 + 64); a2 != i; i = *(_QWORD *)(i + 24) )
{
if ( !i )
_assert_fail("(search)", "check.c", 0xBFu, "adns__consistency");
}
}
else if ( v3 > 2 )
{
if ( v3 != 3 )
_assert_fail("!\"specific query state\"", "check.c", 0xC5u, "adns__consistency");
for ( j = *(_QWORD *)(a1 + 80); a2 != j; j = *(_QWORD *)(j + 24) )
{
if ( !j )
_assert_fail("(search)", "check.c", 0xC2u, "adns__consistency");
}
}
else if ( v3 )
{
for ( k = *(_QWORD *)(a1 + 48); a2 != k; k = *(_QWORD *)(k + 24) )
{
if ( !k )
_assert_fail("(search)", "check.c", 0xBCu, "adns__consistency");
}
}
else
{
for ( l = *(_QWORD *)(a1 + 32); a2 != l; l = *(_QWORD *)(l + 24) )
{
if ( !l )
_assert_fail("(search)", "check.c", 0xB9u, "adns__consistency");
}
}
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // eax
__int64 k; // rax
__int64 j; // rax
__int64 l; // rax
__int64 i; // rax

if ( a3 == 1 )
{
if ( (*(_DWORD *)a1 & 0x100) == 0 )
return;
}
else if ( a3 == 2 )
{
if ( (*(_DWORD *)a1 & 0x300) != 768 )
return;
}
else if ( a3 )
{
func7();
}
func1(a1);
checkc_queue_udpw(a1);
checkc_queue_tcpw(a1);
func4(a1);
func3(a1);
if ( a2 )
{
v3 = *(_DWORD *)(a2 + 8);
if ( v3 == 2 )
{
for ( i = *(_QWORD *)(a1 + 64); a2 != i; i = *(_QWORD *)(i + 24) )
{
if ( !i )
_assert_fail("(search)", "check.c", 0xBFu, "adns__consistency");
}
}
else if ( v3 > 2 )
{
if ( v3 != 3 )
_assert_fail("!\"specific query state\"", "check.c", 0xC5u, "adns__consistency");
for ( j = *(_QWORD *)(a1 + 80); a2 != j; j = *(_QWORD *)(j + 24) )
{
if ( !j )
_assert_fail("(search)", "check.c", 0xC2u, "adns__consistency");
}
}
else if ( v3 )
{
for ( k = *(_QWORD *)(a1 + 48); a2 != k; k = *(_QWORD *)(k + 24) )
{
if ( !k )
_assert_fail("(search)", "check.c", 0xBCu, "adns__consistency");
}
}
else
{
for ( l = *(_QWORD *)(a1 + 32); a2 != l; l = *(_QWORD *)(l + 24) )
{
if ( !l )
_assert_fail("(search)", "check.c", 0xB9u, "adns__consistency");
}
}
}
}

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

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

user_defined_types: struct query_queue { struct adns__query *head; }

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

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

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

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

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

user_defined_types: struct sortlist { struct in_addr base; }

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

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

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

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

user_defined_types: struct allocnode { struct allocnode *next; }

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

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


decompiled_code:
void __fastcall 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);
}

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:
qu
struct adns__query *

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

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

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

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

user_defined_types: struct 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 = *(_DWORD *)a1 > *(_DWORD *)a2;
if ( *(_DWORD *)a1 < *(_DWORD *)a2 )
result = 0xFFFFFFFFLL;
return result;
}

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

result = *(_DWORD *)a1 > *(_DWORD *)a2;
if ( *(_DWORD *)a1 < *(_DWORD *)a2 )
result = 0xFFFFFFFFLL;
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; // edx
unsigned int v3; // ecx

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

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

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

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: enum adns_initflags { adns_if_none=0, adns_if_noenv=1, adns_if_noerrprint=2, adns_if_noserverwarn=4, adns_if_debug=8, adns_if_logpid=128, adns_if_noautosys=16, adns_if_eintr=32, adns_if_nosigpipe=64, adns_if_checkc_entex=256, adns_if_checkc_freq=768 }

user_defined_types: struct query_queue { struct adns__query *head; }

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

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

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

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

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

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

user_defined_types: enum adns_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 sockaddr { unsigned short sa_family; char sa_data[14]; }


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: enum adns__tcpstate { server_disconnected=0, server_connecting=1, server_ok=2, server_broken=3 }

user_defined_types: struct sortlist { struct in_addr base; }

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

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

user_defined_types: struct allocnode { struct allocnode *next; }

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

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

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

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

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

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 adns__vbuf_init(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func5(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

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)
{
unsigned int v2; // er12
__int64 result; // rax
void *v4; // rax

v2 = 1;
if ( *(_DWORD *)(a1 + 4) >= a2 )
return v2;
v4 = realloc(*(void **)(a1 + 8), a2);
if ( !v4 )
return 0;
*(_QWORD *)(a1 + 8) = v4;
result = 1LL;
*(_DWORD *)(a1 + 4) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
unsigned int v2; // er12
__int64 result; // rax
void *v4; // rax

v2 = 1;
if ( *(_DWORD *)(a1 + 4) >= a2 )
return v2;
v4 = realloc(*(void **)(a1 + 8), a2);
if ( !v4 )
return 0;
*(_QWORD *)(a1 + 8) = v4;
result = 1LL;
*(_DWORD *)(a1 + 4) = a2;
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 *


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 v5; // eax
void *v6; // rdi
int v7; // ebx
void *v8; // rax
unsigned int v9; // er8

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

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((_QWORD *)a1);
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
free(*(void **)(a1 + 8));
func5((_QWORD *)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);
}


decompiled_code:
__int64 __fastcall adns_rr_info(__int64 a1, _QWORD *a2, _QWORD *a3, _DWORD *a4, __int64 a5, char **a6)
{
__int64 v10; // rax
__int64 v11; // rax
unsigned int v12; // er12
char *v14; // r13
size_t v15; // rax
char *v16; // rax
__int64 v17; // [rsp+0h] [rbp-38h] BYREF
char *s; // [rsp+8h] [rbp-30h]

v10 = adns__findtype();
if ( !v10 )
return 2LL;
if ( a2 )
*a2 = *(_QWORD *)(v10 + 8);
if ( a3 )
*a3 = *(_QWORD *)(v10 + 16);
if ( a4 )
*a4 = *(_DWORD *)(v10 + 24);
if ( a5 )
{
adns__vbuf_init(&v17);
v12 = (*(__int64 (__fastcall **)(__int64 *, __int64))(v11 + 40))(&v17, a5);
if ( v12 )
{
LABEL_10:
adns__vbuf_free((__int64)&v17);
return v12;
}
if ( !(unsigned int)adns__vbuf_append((__int64)&v17, &unk_B40, 1) )
{
v12 = 1;
goto LABEL_10;
}
v14 = s;
v15 = strlen(s);
if ( v15 != (_DWORD)v17 - 1 )
_assert_fail("strlen(vb.buf) == vb.used-1", "general.c", 0xDCu, "adns_rr_info");
v16 = (char *)realloc(v14, (int)v17);
*a6 = v16;
if ( !v16 )
{
*a6 = s;
return v12;
}
}
return 0LL;
}

original_code:
adns_status adns_rr_info(adns_rrtype type,
    const char **rrtname_r, const char **fmtname_r,
    int *len_r,
    const void *datap, char **data_r) {
  const typeinfo *typei;
  vbuf vb;
  adns_status st;
  typei= adns__findtype(type);
  if (!typei) return adns_s_unknownrrtype;
  if (rrtname_r) *rrtname_r= typei->rrtname;
  if (fmtname_r) *fmtname_r= typei->fmtname;
  if (len_r) *len_r= typei->rrsz;
  if (!datap) return adns_s_ok;
  adns__vbuf_init(&vb);
  st= typei->convstring(&vb,datap);
  if (st) goto x_freevb;
  if (!adns__vbuf_append(&vb,"",1)) { st= adns_s_nomemory; goto x_freevb; }
  ((void) sizeof ((strlen(vb.buf) == vb.used-1) ? 1 : 0), __extension__ ({ if (strlen(vb.buf) == vb.used-1) ; else __assert_fail ("strlen(vb.buf) == vb.used-1", "general.c", 220, __extension__ __PRETTY_FUNCTION__); }));
  *data_r= realloc(vb.buf,vb.used);
  if (!*data_r) *data_r= vb.buf;
  return adns_s_ok;
 x_freevb:
  adns__vbuf_free(&vb);
  return st;
}

canonical_original_code:
enum adns_status adns_rr_info(enum adns_rrtype type, char **rrtname_r, char **fmtname_r, int *len_r, void *datap, char **data_r) {
  struct typeinfo *typei;
  struct vbuf vb;
  enum adns_status st;
  typei= adns__findtype(type);
  if (!typei) return adns_s_unknownrrtype;
  if (rrtname_r) *rrtname_r= typei->rrtname;
  if (fmtname_r) *fmtname_r= typei->fmtname;
  if (len_r) *len_r= typei->rrsz;
  if (!datap) return adns_s_ok;
  adns__vbuf_init(&vb);
  st= typei->convstring(&vb,datap);
  if (st) goto x_freevb;
  if (!adns__vbuf_append(&vb,"",1)) { st= adns_s_nomemory; goto x_freevb; }
  ((void) sizeof ((strlen(vb.buf) == vb.used-1) ? 1 : 0), __extension__ ({ if (strlen(vb.buf) == vb.used-1) ; else __assert_fail ("strlen(vb.buf) == vb.used-1", "general.c", 220, __extension__ __PRETTY_FUNCTION__); }));
  *data_r= realloc(vb.buf,vb.used);
  if (!*data_r) *data_r= vb.buf;
  return adns_s_ok;
 x_freevb:
  adns__vbuf_free(&vb);
  return st;
}

variable_types:
datap
void *

variable_types: 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 { 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 *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; } *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); } *

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

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

user_defined_types: struct 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)(); }


decompiled_code:
__int64 __fastcall adns_strerror(int a1)
{
return *((_QWORD *)findsinfo(a1) + 2);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
return *((_QWORD *)func2(a1) + 2);
}

original_code:
const char *adns_strerror(adns_status st) {
  const struct sinfo *si;
  si= findsinfo(st);
  return si->string;
}

canonical_original_code:
char *adns_strerror(enum adns_status st) {
  struct sinfo *si;
  si= findsinfo(st);
  return si->string;
}

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 }

return_type: char *

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


decompiled_code:
const char *__fastcall adns__diag_domain(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
int v8; // ebp
const char *result; // rax
const char *v10; // rax

v8 = adns__parse_domain(a1, a2, a3, a4, 1LL, a5, a6, &a7, a6);
result = "<cannot report domain... out of memory>";
if ( v8 != 1 )
{
if ( !v8
|| (*(_DWORD *)a4 = 0, (unsigned int)adns__vbuf_appendstr(a4, "<bad format... "))
&& (v10 = (const char *)adns_strerror(v8), (unsigned int)adns__vbuf_appendstr(a4, v10))
&& (unsigned int)adns__vbuf_appendstr(a4, ">")
&& (unsigned int)adns__vbuf_append(a4, &unk_B40, 1) )
{
if ( !*(_DWORD *)a4 )
{
adns__vbuf_appendstr(a4, "<truncated ...>");
adns__vbuf_append(a4, &unk_B40, 1);
}
result = *(const char **)(a4 + 8);
}
else
{
result = "<cannot report bad format... out of memory>";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func13(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
int v8; // ebp
const char *result; // rax
const char *v10; // rax

v8 = adns__parse_domain(a1, a2, a3, a4, 1LL, a5, a6, &a7, a6);
result = "<cannot report domain... out of memory>";
if ( v8 != 1 )
{
if ( !v8
|| (*(_DWORD *)a4 = 0, (unsigned int)func9(a4, "<bad format... "))
&& (v10 = (const char *)func12(v8), (unsigned int)func9(a4, v10))
&& (unsigned int)func9(a4, ">")
&& (unsigned int)func8(a4, &unk_B40, 1) )
{
if ( !*(_DWORD *)a4 )
{
func9(a4, "<truncated ...>");
func8(a4, &unk_B40, 1);
}
result = *(const char **)(a4 + 8);
}
else
{
result = "<cannot report bad format... out of memory>";
}
}
return result;
}

original_code:
const char *adns__diag_domain(adns_state ads, int serv, adns_query qu,
         vbuf *vb, const byte *dgram,
         int dglen, int cbyte) {
  adns_status st;
  st= adns__parse_domain(ads,serv,qu,vb, pdf_quoteok,
    dgram,dglen,&cbyte,dglen);
  if (st == adns_s_nomemory) {
    return "<cannot report domain... out of memory>";
  }
  if (st) {
    vb->used= 0;
    if (!(adns__vbuf_appendstr(vb,"<bad format... ") &&
   adns__vbuf_appendstr(vb,adns_strerror(st)) &&
   adns__vbuf_appendstr(vb,">") &&
   adns__vbuf_append(vb,"",1))) {
      return "<cannot report bad format... out of memory>";
    }
  }
  if (!vb->used) {
    adns__vbuf_appendstr(vb,"<truncated ...>");
    adns__vbuf_append(vb,"",1);
  }
  return vb->buf;
}

canonical_original_code:
char *adns__diag_domain(struct adns__state *ads, int serv, struct adns__query *qu, struct vbuf *vb, unsigned char *dgram, int dglen, int cbyte) {
  enum adns_status st;
  st= adns__parse_domain(ads,serv,qu,vb, pdf_quoteok,
    dgram,dglen,&cbyte,dglen);
  if (st == adns_s_nomemory) {
    return "<cannot report domain... out of memory>";
  }
  if (st) {
    vb->used= 0;
    if (!(adns__vbuf_appendstr(vb,"<bad format... ") &&
   adns__vbuf_appendstr(vb,adns_strerror(st)) &&
   adns__vbuf_appendstr(vb,">") &&
   adns__vbuf_append(vb,"",1))) {
      return "<cannot report bad format... out of memory>";
    }
  }
  if (!vb->used) {
    adns__vbuf_appendstr(vb,"<truncated ...>");
    adns__vbuf_append(vb,"",1);
  }
  return vb->buf;
}

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

variable_types:
qu
struct adns__query *

variable_types:
vb
struct vbuf *

variable_types:
dgram
unsigned char *

variable_types: dglen int

variable_types: cbyte int

user_defined_types: struct query_queue { struct adns__query *head; }


original_code:
void adns__vdiag(adns_state ads, const char *pfx, adns_initflags prevent,
   int serv, adns_query qu, const char *fmt, va_list al) {
  const char *bef, *aft;
  vbuf vb;
  if (!ads->logfn ||
      (!(ads->iflags & adns_if_debug)
       && (!prevent || (ads->iflags & prevent))))
    return;
  if (ads->iflags & adns_if_logpid) {
    adns__lprintf(ads,"adns%s [%ld]: ",pfx,(long)getpid());
  } else {
    adns__lprintf(ads,"adns%s: ",pfx);
  }
  adns__vlprintf(ads,fmt,al);
  bef= " (";
  aft= "\n";
  if (qu && qu->query_dgram) {
    adns__vbuf_init(&vb);
    adns__lprintf(ads,"%sQNAME=%s, QTYPE=%s",
     bef,
     adns__diag_domain(qu->ads,-1,0, &vb,
         qu->query_dgram,qu->query_dglen,12),
     qu->typei ? qu->typei->rrtname : "<unknown>");
    if (qu->typei && qu->typei->fmtname)
      adns__lprintf(ads,"(%s)",qu->typei->fmtname);
    bef=", "; aft=")\n";
    adns__vbuf_free(&vb);
  }
  if (serv>=0) {
    adns__lprintf(ads,"%sNS=%s",bef,inet_ntoa(ads->servers[serv].addr));
    bef=", "; aft=")\n";
  }
  adns__lprintf(ads,"%s",aft);
}

canonical_original_code:
void adns__vdiag(struct adns__state *ads, char *pfx, enum adns_initflags prevent, int serv, struct adns__query *qu, char *fmt, __builtin_va_list al) {
  char *bef; char *aft;
  struct vbuf vb;
  if (!ads->logfn ||
      (!(ads->iflags & adns_if_debug)
       && (!prevent || (ads->iflags & prevent))))
    return;
  if (ads->iflags & adns_if_logpid) {
    adns__lprintf(ads,"adns%s [%ld]: ",pfx,(long)getpid());
  } else {
    adns__lprintf(ads,"adns%s: ",pfx);
  }
  adns__vlprintf(ads,fmt,al);
  bef= " (";
  aft= "\n";
  if (qu && qu->query_dgram) {
    adns__vbuf_init(&vb);
    adns__lprintf(ads,"%sQNAME=%s, QTYPE=%s",
     bef,
     adns__diag_domain(qu->ads,-1,0, &vb,
         qu->query_dgram,qu->query_dglen,12),
     qu->typei ? qu->typei->rrtname : "<unknown>");
    if (qu->typei && qu->typei->fmtname)
      adns__lprintf(ads,"(%s)",qu->typei->fmtname);
    bef=", "; aft=")\n";
    adns__vbuf_free(&vb);
  }
  if (serv>=0) {
    adns__lprintf(ads,"%sNS=%s",bef,inet_ntoa(ads->servers[serv].addr));
    bef=", "; aft=")\n";
  }
  adns__lprintf(ads,"%s",aft);
}

variable_types:
pfx
char *

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

variable_types:
fmt
char *

variable_types:
bef
char *

variable_types:
aft
char *

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

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

user_defined_types: struct __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 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: 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 sockaddr { unsigned short sa_family; char sa_data[14]; }


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

va_start(va, a4);
adns__vdiag(a1, " debug", 0, a2, a3, a4, (__int64)va);
}

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

va_start(va, a4);
func14(a1, " debug", 0, a2, a3, a4, (__int64)va);
}

original_code:
void adns__debug(adns_state ads, int serv, adns_query qu,
   const char *fmt, ...) {
  va_list al;
  __builtin_va_start(al,fmt);
  adns__vdiag(ads," debug",0,serv,qu,fmt,al);
  __builtin_va_end(al);
}

canonical_original_code:
void adns__debug(struct adns__state *ads, int serv, struct adns__query *qu, char *fmt, ...) {
  __builtin_va_list al;
  __builtin_va_start(al,fmt);
  adns__vdiag(ads," debug",0,serv,qu,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: enum adns__tcpstate { server_disconnected=0, server_connecting=1, server_ok=2, server_broken=3 }

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

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

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

user_defined_types: struct allocnode { struct allocnode *next; }

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

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

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

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

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

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 adns__warn(__int64 a1, int a2, __int64 a3, __int64 a4, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a4);
adns__vdiag(a1, " warning", 6, a2, a3, a4, (__int64)va);
}

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

va_start(va, a4);
func14(a1, " warning", 6, a2, a3, a4, (__int64)va);
}

original_code:
void adns__warn(adns_state ads, int serv, adns_query qu,
  const char *fmt, ...) {
  va_list al;
  __builtin_va_start(al,fmt);
  adns__vdiag(ads," warning",
       adns_if_noerrprint|adns_if_noserverwarn, serv,qu,fmt,al);
  __builtin_va_end(al);
}

canonical_original_code:
void adns__warn(struct adns__state *ads, int serv, struct adns__query *qu, char *fmt, ...) {
  __builtin_va_list al;
  __builtin_va_start(al,fmt);
  adns__vdiag(ads," warning",
       adns_if_noerrprint|adns_if_noserverwarn, serv,qu,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: 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 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: 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 sockaddr { unsigned short sa_family; char sa_data[14]; }


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

va_start(va, a4);
adns__vdiag(a1, (const char *)&unk_B40, 2, a2, a3, a4, (__int64)va);
}

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

va_start(va, a4);
func14(a1, (const char *)&unk_B40, 2, a2, a3, a4, (__int64)va);
}

original_code:
void adns__diag(adns_state ads, int serv, adns_query qu,
  const char *fmt, ...) {
  va_list al;
  __builtin_va_start(al,fmt);
  adns__vdiag(ads,"",adns_if_noerrprint,serv,qu,fmt,al);
  __builtin_va_end(al);
}

canonical_original_code:
void adns__diag(struct adns__state *ads, int serv, struct adns__query *qu, char *fmt, ...) {
  __builtin_va_list al;
  __builtin_va_start(al,fmt);
  adns__vdiag(ads,"",adns_if_noerrprint,serv,qu,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: enum adns__tcpstate { server_disconnected=0, server_connecting=1, server_ok=2, server_broken=3 }

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

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

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

user_defined_types: struct allocnode { struct allocnode *next; }

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

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

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

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

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

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 adns_errabbrev(int a1)
{
return *((_QWORD *)findsinfo(a1) + 1);
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1)
{
return *((_QWORD *)func2(a1) + 1);
}

original_code:
const char *adns_errabbrev(adns_status st) {
  const struct sinfo *si;
  si= findsinfo(st);
  return si->abbrev;
}

canonical_original_code:
char *adns_errabbrev(enum adns_status st) {
  struct sinfo *si;
  si= findsinfo(st);
  return si->abbrev;
}

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

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


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

key[0] = a1;
return *((_QWORD *)bsearch(key, &stinfos, 7uLL, 0x10uLL, (__compar_fn_t)sti_compar) + 1);
}

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

key[0] = a1;
return *((_QWORD *)bsearch(key, &stinfos, 7uLL, 0x10uLL, (__compar_fn_t)sti_compar) + 1);
}

original_code:
const char *adns_errtypeabbrev(adns_status st) {
  const struct stinfo *sti;
  sti= bsearch(&st,stinfos, sizeof(stinfos)/sizeof(*stinfos),
        sizeof(*stinfos), sti_compar);
  return sti->abbrev;
}

canonical_original_code:
char *adns_errtypeabbrev(enum adns_status st) {
  struct stinfo *sti;
  sti= bsearch(&st,stinfos, sizeof(stinfos)/sizeof(*stinfos),
        sizeof(*stinfos), sti_compar);
  return sti->abbrev;
}

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


original_code:
void adns__isort(void *array, int nobjs, int sz, void *tempbuf,
   int (*needswap)(void *context, const void *a, const void *b),
   void *context) {
  byte *data= array;
  int i, place;
  for (i=0; i<nobjs; i++) {
    for (place= i;
  place>0 && needswap(context, data + (place-1)*sz, data + i*sz);
  place--);
    if (place != i) {
      memcpy(tempbuf, data + i*sz, sz);
      memmove(data + (place+1)*sz, data + place*sz, (i-place)*sz);
      memcpy(data + place*sz, tempbuf, sz);
    }
  }
}

canonical_original_code:
void adns__isort(void *array, int nobjs, int sz, void *tempbuf, int (*needswap)(void *context, void *a, void *b), void *context) {
  unsigned char *data = array;
  int i; int place;
  for (i=0; i<nobjs; i++) {
    for (place= i;
  place>0 && needswap(context, data + (place-1)*sz, data + i*sz);
  place--);
    if (place != i) {
      memcpy(tempbuf, data + i*sz, sz);
      memmove(data + (place+1)*sz, data + place*sz, (i-place)*sz);
      memcpy(data + place*sz, tempbuf, sz);
    }
  }
}

variable_types:
array
void *

variable_types: nobjs int

variable_types: sz int

variable_types:
tempbuf
void *

variable_types: int (*)(void *context, void *a, void *b)

variable_types:
context
void *

variable_types:
data
unsigned char *

variable_types: i int

variable_types: place int