decompiled_code:
__int64 __fastcall adns__parse_domain_more(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4, char a5, __int64 a6)
{
int v7; // ebp
unsigned int i; // eax
unsigned int v9; // ebx
__int64 v10; // rbx
int v11; // ebp
int v13; // er12
unsigned __int8 *v14; // r14
int v15; // ebx
unsigned int v16; // er15
int v17; // er12
int v20; // [rsp+28h] [rbp-40h] BYREF
int v21[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v7 = 1;
for ( i = adns__findlabel_next(a1, v21, &v20); ; i = adns__findlabel_next(a1, v21, &v20) )
{
v9 = i;
if ( i )
break;
if ( v21[0] < 0 )
{
*a4 = 0;
return v9;
}
if ( !v21[0] )
return (unsigned int)adns__vbuf_append(a4, &unk_8C9, 1LL) == 0;
if ( !v7 && !(unsigned int)adns__vbuf_append(a4, ".", 1LL) )
return 1;
v9 = a5 & 1;
if ( (a5 & 1) != 0 )
{
if ( !(unsigned int)vbuf__append_quoted1035((__int64)a4, (unsigned __int8 *)(a6 + v20), v21[0]) )
return v9;
}
else
{
v13 = v20;
v14 = (unsigned __int8 *)(a6 + v20);
v15 = *v14;
if ( !ctype_alpha(v15) && !ctype_digit(v15) )
return 102;
LODWORD(v10) = v13 + 1;
v16 = v21[0];
v17 = v21[0] + v13;
if ( v21[0] > 1 )
{
v10 = (int)v10;
do
{
v11 = *(unsigned __int8 *)(a6 + v10);
if ( v11 != 45 && !ctype_alpha(*(unsigned __int8 *)(a6 + v10)) && !ctype_digit(v11) )
return 102;
}
while ( v17 > (int)++v10 );
}
if ( !(unsigned int)adns__vbuf_append(a4, v14, v16) )
return 1;
}
v7 = 0;
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4, char a5, __int64 a6)
{
int v7; // ebp
unsigned int i; // eax
unsigned int v9; // ebx
__int64 v10; // rbx
int v11; // ebp
int v13; // er12
unsigned __int8 *v14; // r14
int v15; // ebx
unsigned int v16; // er15
int v17; // er12
int v20; // [rsp+28h] [rbp-40h] BYREF
int v21[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v7 = 1;
for ( i = func5(a1, v21, &v20); ; i = func5(a1, v21, &v20) )
{
v9 = i;
if ( i )
break;
if ( v21[0] < 0 )
{
*a4 = 0;
return v9;
}
if ( !v21[0] )
return (unsigned int)adns__vbuf_append(a4, &unk_8C9, 1LL) == 0;
if ( !v7 && !(unsigned int)adns__vbuf_append(a4, ".", 1LL) )
return 1;
v9 = a5 & 1;
if ( (a5 & 1) != 0 )
{
if ( !(unsigned int)func3((__int64)a4, (unsigned __int8 *)(a6 + v20), v21[0]) )
return v9;
}
else
{
v13 = v20;
v14 = (unsigned __int8 *)(a6 + v20);
v15 = *v14;
if ( !func1(v15) && !func0(v15) )
return 102;
LODWORD(v10) = v13 + 1;
v16 = v21[0];
v17 = v21[0] + v13;
if ( v21[0] > 1 )
{
v10 = (int)v10;
do
{
v11 = *(unsigned __int8 *)(a6 + v10);
if ( v11 != 45 && !func1(*(unsigned __int8 *)(a6 + v10)) && !func0(v11) )
return 102;
}
while ( v17 > (int)++v10 );
}
if ( !(unsigned int)adns__vbuf_append(a4, v14, v16) )
return 1;
}
v7 = 0;
}
return v9;
}

original_code:
adns_status adns__parse_domain_more(findlabel_state *fls, adns_state ads,
        adns_query qu, vbuf *vb,
        parsedomain_flags flags,
        const byte *dgram) {
  int lablen, labstart, i, ch, first;
  adns_status st;
  first= 1;
  for (;;) {
    st= adns__findlabel_next(fls,&lablen,&labstart);
    if (st) return st;
    if (lablen<0) { vb->used=0; return adns_s_ok; }
    if (!lablen) break;
    if (first) {
      first= 0;
    } else {
      if (!adns__vbuf_append(vb,".",1)) return adns_s_nomemory;
    }
    if (flags & pdf_quoteok) {
      if (!vbuf__append_quoted1035(vb,dgram+labstart,lablen))
 return adns_s_nomemory;
    } else {
      ch= dgram[labstart];
      if (!ctype_alpha(ch) && !ctype_digit(ch))
 return adns_s_answerdomaininvalid;
      for (i= labstart+1; i<labstart+lablen; i++) {
 ch= dgram[i];
 if (ch != '-' && !ctype_alpha(ch) && !ctype_digit(ch))
   return adns_s_answerdomaininvalid;
      }
      if (!adns__vbuf_append(vb,dgram+labstart,lablen))
 return adns_s_nomemory;
    }
  }
  if (!adns__vbuf_append(vb,"",1)) return adns_s_nomemory;
  return adns_s_ok;
}

canonical_original_code:
enum adns_status adns__parse_domain_more(struct findlabel_state *fls, struct adns__state *ads, struct adns__query *qu, struct vbuf *vb, enum parsedomain_flags flags, unsigned char *dgram) {
  int lablen; int labstart; int i; int ch; int first;
  enum adns_status st;
  first= 1;
  for (;;) {
    st= adns__findlabel_next(fls,&lablen,&labstart);
    if (st) return st;
    if (lablen<0) { vb->used=0; return adns_s_ok; }
    if (!lablen) break;
    if (first) {
      first= 0;
    } else {
      if (!adns__vbuf_append(vb,".",1)) return adns_s_nomemory;
    }
    if (flags & pdf_quoteok) {
      if (!vbuf__append_quoted1035(vb,dgram+labstart,lablen))
 return adns_s_nomemory;
    } else {
      ch= dgram[labstart];
      if (!ctype_alpha(ch) && !ctype_digit(ch))
 return adns_s_answerdomaininvalid;
      for (i= labstart+1; i<labstart+lablen; i++) {
 ch= dgram[i];
 if (ch != '-' && !ctype_alpha(ch) && !ctype_digit(ch))
   return adns_s_answerdomaininvalid;
      }
      if (!adns__vbuf_append(vb,dgram+labstart,lablen))
 return adns_s_nomemory;
    }
  }
  if (!adns__vbuf_append(vb,"",1)) return adns_s_nomemory;
  return adns_s_ok;
}

variable_types:
vb
struct vbuf *

variable_types: enum parsedomain_flags { pdf_quoteok=1 }

variable_types: labstart int

variable_types: i int

variable_types: first int

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

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

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

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

user_defined_types: struct query_queue { struct adns__query *head; }

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

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

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

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

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

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

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall adns__parse_domain(__int64 a1, int a2, __int64 a3, _DWORD *a4, char a5, __int64 a6, int a7, int *a8, int a9)
{
char v14[104]; // [rsp+0h] [rbp-68h] BYREF

adns__findlabel_start((__int64)v14, a1, a2, a3, a6, a7, a9, *a8, (__int64)a8);
*a4 = 0;
return adns__parse_domain_more((__int64)v14, a1, a3, a4, a5, a6);
}

original_code:
adns_status adns__parse_domain(adns_state ads, int serv, adns_query qu,
          vbuf *vb, parsedomain_flags flags,
          const byte *dgram, int dglen, int *cbyte_io,
          int max) {
  findlabel_state fls;
  adns__findlabel_start(&fls,ads, serv,qu, dgram,dglen,max,
   *cbyte_io,cbyte_io);
  vb->used= 0;
  return adns__parse_domain_more(&fls,ads,qu, vb,flags,dgram);
}

canonical_original_code:
enum adns_status adns__parse_domain(struct adns__state *ads, int serv, struct adns__query *qu, struct vbuf *vb, enum parsedomain_flags flags, unsigned char *dgram, int dglen, int *cbyte_io, int max) {
  struct findlabel_state fls;
  adns__findlabel_start(&fls,ads, serv,qu, dgram,dglen,max,
   *cbyte_io,cbyte_io);
  vb->used= 0;
  return adns__parse_domain_more(&fls,ads,qu, vb,flags,dgram);
}

variable_types: serv int

variable_types:
qu
struct adns__query *

variable_types:
dgram
unsigned char *

variable_types: dglen int

variable_types: max int

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

user_defined_types: enum parsedomain_flags { pdf_quoteok=1 }

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


original_code:
adns_status adns__findrr_anychk(adns_query qu, int serv,
    const byte *dgram, int dglen, int *cbyte_io,
    int *type_r, int *class_r,
    unsigned long *ttl_r,
    int *rdlen_r, int *rdstart_r,
    const byte *eo_dgram, int eo_dglen,
    int eo_cbyte, int *eo_matched_r) {
  findlabel_state fls, eo_fls_buf;
  findlabel_state *eo_fls;
  int cbyte;
  int tmp, rdlen;
  unsigned long ttl;
  int lablen, labstart, ch;
  int eo_lablen, eo_labstart, eo_ch;
  adns_status st;
  cbyte= *cbyte_io;
  adns__findlabel_start(&fls,qu->ads, serv,qu, dgram,dglen,dglen,cbyte,&cbyte);
  if (eo_dgram) {
    eo_fls= &eo_fls_buf;
    adns__findlabel_start(eo_fls,qu->ads, -1,0,
     eo_dgram,eo_dglen,eo_dglen,eo_cbyte,0);
  } else {
    eo_fls= 0;
  }
  for (;;) {
    st= adns__findlabel_next(&fls,&lablen,&labstart);
    if (st) return st;
    if (lablen<0) goto x_truncated;
    if (eo_fls) {
      st= adns__findlabel_next(eo_fls,&eo_lablen,&eo_labstart);
      ((void) sizeof ((!st) ? 1 : 0), __extension__ ({ if (!st) ; else __assert_fail ("!st", "parse.c", 199, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((eo_lablen>=0) ? 1 : 0), __extension__ ({ if (eo_lablen>=0) ; else __assert_fail ("eo_lablen>=0", "parse.c", 199, __extension__ __PRETTY_FUNCTION__); }));
      if (lablen != eo_lablen) eo_fls= 0;
      while (eo_fls && eo_lablen-- > 0) {
 ch= dgram[labstart++]; if (ctype_alpha(ch)) ch &= ~32;
 eo_ch= eo_dgram[eo_labstart++]; if (ctype_alpha(eo_ch)) eo_ch &= ~32;
 if (ch != eo_ch) eo_fls= 0;
      }
    }
    if (!lablen) break;
  }
  if (eo_matched_r) *eo_matched_r= !!eo_fls;
  if (cbyte+10>dglen) goto x_truncated;
  ((tmp)=0,(tmp)|=((((dgram)[((cbyte))++]) & 0x0ff)<<8), (tmp)|=(((dgram)[(cbyte)++]) & 0x0ff), (tmp)); *type_r= tmp;
  ((tmp)=0,(tmp)|=((((dgram)[((cbyte))++]) & 0x0ff)<<8), (tmp)|=(((dgram)[(cbyte)++]) & 0x0ff), (tmp)); *class_r= tmp;
  ( (ttl)=0, (ttl)|=((((dgram)[((cbyte))++]) & 0x0ff)<<24), (ttl)|=((((dgram)[((cbyte))++]) & 0x0ff)<<16), (ttl)|=((((dgram)[((cbyte))++]) & 0x0ff)<<8), (ttl)|=(((dgram)[(cbyte)++]) & 0x0ff), (ttl) );
  if (ttl > (7*86400)) ttl= (7*86400);
  *ttl_r= ttl;
  ((rdlen)=0,(rdlen)|=((((dgram)[((cbyte))++]) & 0x0ff)<<8), (rdlen)|=(((dgram)[(cbyte)++]) & 0x0ff), (rdlen)); if (rdlen_r) *rdlen_r= rdlen;
  if (rdstart_r) *rdstart_r= cbyte;
  cbyte+= rdlen;
  if (cbyte>dglen) goto x_truncated;
  *cbyte_io= cbyte;
  return adns_s_ok;
 x_truncated:
  *type_r= -1;
  return 0;
}

canonical_original_code:
enum adns_status adns__findrr_anychk(struct adns__query *qu, int serv, unsigned char *dgram, int dglen, int *cbyte_io, int *type_r, int *class_r, unsigned long *ttl_r, int *rdlen_r, int *rdstart_r, unsigned char *eo_dgram, int eo_dglen, int eo_cbyte, int *eo_matched_r) {
  struct findlabel_state fls; struct findlabel_state eo_fls_buf;
  struct findlabel_state *eo_fls;
  int cbyte;
  int tmp; int rdlen;
  unsigned long ttl;
  int lablen; int labstart; int ch;
  int eo_lablen; int eo_labstart; int eo_ch;
  enum adns_status st;
  cbyte= *cbyte_io;
  adns__findlabel_start(&fls,qu->ads, serv,qu, dgram,dglen,dglen,cbyte,&cbyte);
  if (eo_dgram) {
    eo_fls= &eo_fls_buf;
    adns__findlabel_start(eo_fls,qu->ads, -1,0,
     eo_dgram,eo_dglen,eo_dglen,eo_cbyte,0);
  } else {
    eo_fls= 0;
  }
  for (;;) {
    st= adns__findlabel_next(&fls,&lablen,&labstart);
    if (st) return st;
    if (lablen<0) goto x_truncated;
    if (eo_fls) {
      st= adns__findlabel_next(eo_fls,&eo_lablen,&eo_labstart);
      ((void) sizeof ((!st) ? 1 : 0), __extension__ ({ if (!st) ; else __assert_fail ("!st", "parse.c", 199, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((eo_lablen>=0) ? 1 : 0), __extension__ ({ if (eo_lablen>=0) ; else __assert_fail ("eo_lablen>=0", "parse.c", 199, __extension__ __PRETTY_FUNCTION__); }));
      if (lablen != eo_lablen) eo_fls= 0;
      while (eo_fls && eo_lablen-- > 0) {
 ch= dgram[labstart++]; if (ctype_alpha(ch)) ch &= ~32;
 eo_ch= eo_dgram[eo_labstart++]; if (ctype_alpha(eo_ch)) eo_ch &= ~32;
 if (ch != eo_ch) eo_fls= 0;
      }
    }
    if (!lablen) break;
  }
  if (eo_matched_r) *eo_matched_r= !!eo_fls;
  if (cbyte+10>dglen) goto x_truncated;
  ((tmp)=0,(tmp)|=((((dgram)[((cbyte))++]) & 0x0ff)<<8), (tmp)|=(((dgram)[(cbyte)++]) & 0x0ff), (tmp)); *type_r= tmp;
  ((tmp)=0,(tmp)|=((((dgram)[((cbyte))++]) & 0x0ff)<<8), (tmp)|=(((dgram)[(cbyte)++]) & 0x0ff), (tmp)); *class_r= tmp;
  ( (ttl)=0, (ttl)|=((((dgram)[((cbyte))++]) & 0x0ff)<<24), (ttl)|=((((dgram)[((cbyte))++]) & 0x0ff)<<16), (ttl)|=((((dgram)[((cbyte))++]) & 0x0ff)<<8), (ttl)|=(((dgram)[(cbyte)++]) & 0x0ff), (ttl) );
  if (ttl > (7*86400)) ttl= (7*86400);
  *ttl_r= ttl;
  ((rdlen)=0,(rdlen)|=((((dgram)[((cbyte))++]) & 0x0ff)<<8), (rdlen)|=(((dgram)[(cbyte)++]) & 0x0ff), (rdlen)); if (rdlen_r) *rdlen_r= rdlen;
  if (rdstart_r) *rdstart_r= cbyte;
  cbyte+= rdlen;
  if (cbyte>dglen) goto x_truncated;
  *cbyte_io= cbyte;
  return adns_s_ok;
 x_truncated:
  *type_r= -1;
  return 0;
}

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

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

variable_types: cbyte int

variable_types: tmp int

variable_types: rdlen int

variable_types:
ttl
unsigned long

variable_types: lablen int

variable_types: ch int

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


original_code:
adns_status adns__findrr(adns_query qu, int serv,
    const byte *dgram, int dglen, int *cbyte_io,
    int *type_r, int *class_r, unsigned long *ttl_r,
    int *rdlen_r, int *rdstart_r,
    int *ownermatchedquery_r) {
  if (!ownermatchedquery_r) {
    return adns__findrr_anychk(qu,serv,
          dgram,dglen,cbyte_io,
          type_r,class_r,ttl_r,rdlen_r,rdstart_r,
          0,0,0, 0);
  } else if (!qu->cname_dgram) {
    return adns__findrr_anychk(qu,serv,
          dgram,dglen,cbyte_io,
          type_r,class_r,ttl_r,rdlen_r,rdstart_r,
          qu->query_dgram,qu->query_dglen,12,
          ownermatchedquery_r);
  } else {
    return adns__findrr_anychk(qu,serv,
          dgram,dglen,cbyte_io,
          type_r,class_r,ttl_r,rdlen_r,rdstart_r,
          qu->cname_dgram,qu->cname_dglen,qu->cname_begin,
          ownermatchedquery_r);
  }
}

canonical_original_code:
enum adns_status adns__findrr(struct adns__query *qu, int serv, unsigned char *dgram, int dglen, int *cbyte_io, int *type_r, int *class_r, unsigned long *ttl_r, int *rdlen_r, int *rdstart_r, int *ownermatchedquery_r) {
  if (!ownermatchedquery_r) {
    return adns__findrr_anychk(qu,serv,
          dgram,dglen,cbyte_io,
          type_r,class_r,ttl_r,rdlen_r,rdstart_r,
          0,0,0, 0);
  } else if (!qu->cname_dgram) {
    return adns__findrr_anychk(qu,serv,
          dgram,dglen,cbyte_io,
          type_r,class_r,ttl_r,rdlen_r,rdstart_r,
          qu->query_dgram,qu->query_dglen,12,
          ownermatchedquery_r);
  } else {
    return adns__findrr_anychk(qu,serv,
          dgram,dglen,cbyte_io,
          type_r,class_r,ttl_r,rdlen_r,rdstart_r,
          qu->cname_dgram,qu->cname_dglen,qu->cname_begin,
          ownermatchedquery_r);
  }
}

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

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

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

user_defined_types: struct query_queue { struct adns__query *head; }

user_defined_types: 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 allocnode { struct allocnode *next; }

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

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

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

user_defined_types: struct sortlist { struct in_addr base; }

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

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


original_code:
int adns_beforepoll(adns_state ads, struct pollfd *fds, int *nfds_io,
      int *timeout_io, const struct timeval *now) {
  struct timeval tv_nowbuf, tv_tobuf, *tv_to;
  int space, found, timeout_ms, r;
  struct pollfd fds_tmp[2];
  adns__consistency(ads,0,cc_entex);
  if (timeout_io) {
    adns__must_gettimeofday(ads,&now,&tv_nowbuf);
    if (!now) { *nfds_io= 0; r= 0; goto xit; }
    timeout_ms= *timeout_io;
    if (timeout_ms == -1) {
      tv_to= 0;
    } else {
      tv_tobuf.tv_sec= timeout_ms / 1000;
      tv_tobuf.tv_usec= (timeout_ms % 1000)*1000;
      tv_to= &tv_tobuf;
    }
    adns__timeouts(ads, 0, &tv_to,&tv_tobuf, *now);
    if (tv_to) {
      ((void) sizeof ((tv_to == &tv_tobuf) ? 1 : 0), __extension__ ({ if (tv_to == &tv_tobuf) ; else __assert_fail ("tv_to == &tv_tobuf", "poll.c", 58, __extension__ __PRETTY_FUNCTION__); }));
      timeout_ms= (tv_tobuf.tv_usec+999)/1000;
      ((void) sizeof ((tv_tobuf.tv_sec < (0x7fffffff -timeout_ms)/1000) ? 1 : 0), __extension__ ({ if (tv_tobuf.tv_sec < (0x7fffffff -timeout_ms)/1000) ; else __assert_fail ("tv_tobuf.tv_sec < (INT_MAX-timeout_ms)/1000", "poll.c", 60, __extension__ __PRETTY_FUNCTION__); }));
      timeout_ms += tv_tobuf.tv_sec*1000;
    } else {
      timeout_ms= -1;
    }
    *timeout_io= timeout_ms;
  }
  space= *nfds_io;
  if (space >= 2) {
    found= adns__pollfds(ads,fds);
    *nfds_io= found;
  } else {
    found= adns__pollfds(ads,fds_tmp);
    *nfds_io= found;
    if (space < found) { r= 34; goto xit; }
    memcpy(fds,fds_tmp,sizeof(struct pollfd)*found);
  }
  r= 0;
xit:
  adns__consistency(ads,0,cc_entex);
  return r;
}

canonical_original_code:
int adns_beforepoll(struct adns__state *ads, struct pollfd *fds, int *nfds_io, int *timeout_io, struct timeval *now) {
  struct timeval tv_nowbuf; struct timeval tv_tobuf; struct timeval *tv_to;
  int space; int found; int timeout_ms; int r;
  struct pollfd fds_tmp[2];
  adns__consistency(ads,0,cc_entex);
  if (timeout_io) {
    adns__must_gettimeofday(ads,&now,&tv_nowbuf);
    if (!now) { *nfds_io= 0; r= 0; goto xit; }
    timeout_ms= *timeout_io;
    if (timeout_ms == -1) {
      tv_to= 0;
    } else {
      tv_tobuf.tv_sec= timeout_ms / 1000;
      tv_tobuf.tv_usec= (timeout_ms % 1000)*1000;
      tv_to= &tv_tobuf;
    }
    adns__timeouts(ads, 0, &tv_to,&tv_tobuf, *now);
    if (tv_to) {
      ((void) sizeof ((tv_to == &tv_tobuf) ? 1 : 0), __extension__ ({ if (tv_to == &tv_tobuf) ; else __assert_fail ("tv_to == &tv_tobuf", "poll.c", 58, __extension__ __PRETTY_FUNCTION__); }));
      timeout_ms= (tv_tobuf.tv_usec+999)/1000;
      ((void) sizeof ((tv_tobuf.tv_sec < (0x7fffffff -timeout_ms)/1000) ? 1 : 0), __extension__ ({ if (tv_tobuf.tv_sec < (0x7fffffff -timeout_ms)/1000) ; else __assert_fail ("tv_tobuf.tv_sec < (INT_MAX-timeout_ms)/1000", "poll.c", 60, __extension__ __PRETTY_FUNCTION__); }));
      timeout_ms += tv_tobuf.tv_sec*1000;
    } else {
      timeout_ms= -1;
    }
    *timeout_io= timeout_ms;
  }
  space= *nfds_io;
  if (space >= 2) {
    found= adns__pollfds(ads,fds);
    *nfds_io= found;
  } else {
    found= adns__pollfds(ads,fds_tmp);
    *nfds_io= found;
    if (space < found) { r= 34; goto xit; }
    memcpy(fds,fds_tmp,sizeof(struct pollfd)*found);
  }
  r= 0;
xit:
  adns__consistency(ads,0,cc_entex);
  return r;
}

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:
fds
struct pollfd *

variable_types:
now
struct timeval *

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

variable_types: space int

variable_types: found int

variable_types: r int

variable_types: struct pollfd { int fd; short events; short revents; } [2]

return_type: int

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

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

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

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

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

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

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

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

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

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_afterpoll(__int64 a1, __int64 a2, unsigned int a3, _QWORD *a4)
{
_QWORD *v6; // [rsp+8h] [rbp-30h] BYREF
char v7[40]; // [rsp+10h] [rbp-28h] BYREF

v6 = a4;
adns__consistency(a1, 0LL, 1LL);
adns__must_gettimeofday(a1, &v6, v7);
if ( v6 )
{
adns__timeouts(a1, 1LL, 0LL, 0LL, *v6, v6[1]);
adns__fdevents(a1, a2, a3, 0LL, 0LL, 0LL, 0LL, *v6, v6[1], 0LL);
}
return adns__consistency(a1, 0LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3, _QWORD *a4)
{
_QWORD *v6; // [rsp+8h] [rbp-30h] BYREF
char v7[40]; // [rsp+10h] [rbp-28h] BYREF

v6 = a4;
adns__consistency(a1, 0LL, 1LL);
adns__must_gettimeofday(a1, &v6, v7);
if ( v6 )
{
adns__timeouts(a1, 1LL, 0LL, 0LL, *v6, v6[1]);
adns__fdevents(a1, a2, a3, 0LL, 0LL, 0LL, 0LL, *v6, v6[1], 0LL);
}
return adns__consistency(a1, 0LL, 1LL);
}

original_code:
void adns_afterpoll(adns_state ads, const struct pollfd *fds, int nfds,
      const struct timeval *now) {
  struct timeval tv_buf;
  adns__consistency(ads,0,cc_entex);
  adns__must_gettimeofday(ads,&now,&tv_buf);
  if (now) {
    adns__timeouts(ads, 1, 0,0, *now);
    adns__fdevents(ads, fds,nfds, 0,0,0,0, *now,0);
  }
  adns__consistency(ads,0,cc_entex);
}

canonical_original_code:
void adns_afterpoll(struct adns__state *ads, struct pollfd *fds, int nfds, struct timeval *now) {
  struct timeval tv_buf;
  adns__consistency(ads,0,cc_entex);
  adns__must_gettimeofday(ads,&now,&tv_buf);
  if (now) {
    adns__timeouts(ads, 1, 0,0, *now);
    adns__fdevents(ads, fds,nfds, 0,0,0,0, *now,0);
  }
  adns__consistency(ads,0,cc_entex);
}

variable_types: nfds int

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

return_type: void

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

user_defined_types: struct query_queue { struct adns__query *head; }

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

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

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

user_defined_types: struct sortlist { struct in_addr base; }

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

user_defined_types: struct allocnode { struct allocnode *next; }

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

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall adns_wait_poll(_BYTE *a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v6; // ebx
int v7; // eax
char *v8; // rax
struct pollfd v10[3]; // [rsp+0h] [rbp-48h] BYREF
int timeout; // [rsp+18h] [rbp-30h] BYREF
int v12[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

adns__consistency(a1, 0LL, 1LL);
while ( 1 )
{
v6 = adns__internal_check(a1, a2, a3, a4);
if ( v6 != 11 )
break;
v12[0] = 2;
timeout = -1;
adns_beforepoll((__int64)a1, v10, v12, &timeout, 0LL);
v7 = poll(v10, v12[0], timeout);
if ( v7 == -1 )
{
v6 = *_errno_location();
if ( v6 == 4 )
{
if ( (*a1 & 0x20) != 0 )
break;
}
else
{
v8 = strerror(v6);
adns__diag(a1, 0xFFFFFFFFLL, 0LL, "poll failed in wait: %s", v8);
adns_globalsystemfailure(a1);
}
}
else
{
if ( v7 < 0 )
_assert_fail("r >= 0", "poll.c", 0x78u, "adns_wait_poll");
adns_afterpoll((__int64)a1, (__int64)v10, v12[0], 0LL);
}
}
adns__consistency(a1, 0LL, 1LL);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v6; // ebx
int v7; // eax
char *v8; // rax
struct pollfd v10[3]; // [rsp+0h] [rbp-48h] BYREF
int timeout; // [rsp+18h] [rbp-30h] BYREF
int v12[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

adns__consistency(a1, 0LL, 1LL);
while ( 1 )
{
v6 = adns__internal_check(a1, a2, a3, a4);
if ( v6 != 11 )
break;
v12[0] = 2;
timeout = -1;
func0((__int64)a1, v10, v12, &timeout, 0LL);
v7 = poll(v10, v12[0], timeout);
if ( v7 == -1 )
{
v6 = *_errno_location();
if ( v6 == 4 )
{
if ( (*a1 & 0x20) != 0 )
break;
}
else
{
v8 = strerror(v6);
adns__diag(a1, 0xFFFFFFFFLL, 0LL, "poll failed in wait: %s", v8);
adns_globalsystemfailure(a1);
}
}
else
{
if ( v7 < 0 )
_assert_fail("r >= 0", "poll.c", 0x78u, "adns_wait_poll");
func1((__int64)a1, (__int64)v10, v12[0], 0LL);
}
}
adns__consistency(a1, 0LL, 1LL);
return v6;
}

original_code:
int adns_wait_poll(adns_state ads,
     adns_query *query_io,
     adns_answer **answer_r,
     void **context_r) {
  int r, nfds, to;
  struct pollfd fds[2];
  adns__consistency(ads,0,cc_entex);
  for (;;) {
    r= adns__internal_check(ads,query_io,answer_r,context_r);
    if (r != 11) goto xit;
    nfds= 2; to= -1;
    adns_beforepoll(ads,fds,&nfds,&to,0);
    r= poll(fds,nfds,to);
    if (r == -1) {
      if ((*__errno_location ()) == 4) {
 if (ads->iflags & adns_if_eintr) { r= 4; goto xit; }
      } else {
 adns__diag(ads,-1,0,"poll failed in wait: %s",strerror((*__errno_location ())));
 adns_globalsystemfailure(ads);
      }
    } else {
      ((void) sizeof ((r >= 0) ? 1 : 0), __extension__ ({ if (r >= 0) ; else __assert_fail ("r >= 0", "poll.c", 120, __extension__ __PRETTY_FUNCTION__); }));
      adns_afterpoll(ads,fds,nfds,0);
    }
  }
 xit:
  adns__consistency(ads,0,cc_entex);
  return r;
}

canonical_original_code:
int adns_wait_poll(struct adns__state *ads, struct adns__query **query_io, struct adns_answer **answer_r, void **context_r) {
  int r; int nfds; int to;
  struct pollfd fds[2];
  adns__consistency(ads,0,cc_entex);
  for (;;) {
    r= adns__internal_check(ads,query_io,answer_r,context_r);
    if (r != 11) goto xit;
    nfds= 2; to= -1;
    adns_beforepoll(ads,fds,&nfds,&to,0);
    r= poll(fds,nfds,to);
    if (r == -1) {
      if ((*__errno_location ()) == 4) {
 if (ads->iflags & adns_if_eintr) { r= 4; goto xit; }
      } else {
 adns__diag(ads,-1,0,"poll failed in wait: %s",strerror((*__errno_location ())));
 adns_globalsystemfailure(ads);
      }
    } else {
      ((void) sizeof ((r >= 0) ? 1 : 0), __extension__ ({ if (r >= 0) ; else __assert_fail ("r >= 0", "poll.c", 120, __extension__ __PRETTY_FUNCTION__); }));
      adns_afterpoll(ads,fds,nfds,0);
    }
  }
 xit:
  adns__consistency(ads,0,cc_entex);
  return r;
}

variable_types: to int

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


insert

original_code:
void insert(struct heap* hp, void* data) {
    hp->count++;
    if (hp->count >= hp->max) {
        hp->max *= 2;
        void **buffer = malloc(sizeof(void *[hp->max]));
        unsigned i;
        for (i = 0; i < hp->count - 1; i++)
            buffer[i] = hp->heap[i];
        free(hp->heap);
        hp->heap = buffer;
    }
    if (hp->count == 1) {
        hp->heap[0] = data;
    } else {
        unsigned pos = hp->count - 1;
        int cont = 1;
        while (cont) {
            if (pos == 0) {
                hp->heap[0] = data;
                break;
            }
            if (hp->compare(data, hp->heap[pos / 2]) > 0) {
                hp->heap[pos] = data;
                cont = 0;
            } else {
                hp->heap[pos] = hp->heap[pos / 2];
                pos /= 2;
            }
        }
    }
}

canonical_original_code:
void insert(struct heap *hp, void *data) {
    hp->count++;
    if (hp->count >= hp->max) {
        hp->max *= 2;
        void **buffer = malloc(sizeof(void *[hp->max]));
        unsigned int i;
        for (i = 0; i < hp->count - 1; i++)
            buffer[i] = hp->heap[i];
        free(hp->heap);
        hp->heap = buffer;
    }
    if (hp->count == 1) {
        hp->heap[0] = data;
    } else {
        unsigned int pos = hp->count - 1;
        int cont = 1;
        while (cont) {
            if (pos == 0) {
                hp->heap[0] = data;
                break;
            }
            if (hp->compare(data, hp->heap[pos / 2]) > 0) {
                hp->heap[pos] = data;
                cont = 0;
            } else {
                hp->heap[pos] = hp->heap[pos / 2];
                pos /= 2;
            }
        }
    }
}

variable_types: struct heap { void **heap; int (*compare)(void *, void *); void (*destruct)(void *); unsigned int count; } *

variable_types:
data
void *

variable_types:
buffer
void **

variable_types:
i
unsigned int

variable_types:
pos
unsigned int

variable_types: cont int


peek

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

result = 0LL;
if ( *((_DWORD *)a1 + 6) )
result = **a1;
return result;
}

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

result = 0LL;
if ( *((_DWORD *)a1 + 6) )
result = **a1;
return result;
}

original_code:
void *peek(struct heap *hp) {
    if (hp->count > 0)
        return hp->heap[0];
    return ((void *)0);
}

return_type: void *

user_defined_types: struct heap { void **heap; int (*compare)(void *, void *); void (*destruct)(void *); unsigned int count; }


original_code:
void min_heapify(struct heap *hp, int index) {
    unsigned pos = index + 1;
    while ((pos * 2 < hp->count && hp->compare(hp->heap[pos-1], hp->heap[pos*2]) > 0) ||
            (pos*2 -1 < hp->count && hp->compare(hp->heap[pos-1], hp->heap[pos*2 - 1]) > 0)) {
        void *buffer;
        if (pos * 2 >= hp->count || hp->compare(hp->heap[pos*2 - 1], hp->heap[pos*2]) < 0) {
            buffer = hp->heap[pos-1];
            hp->heap[pos-1] = hp->heap[pos*2 - 1];
            hp->heap[pos*2 - 1] = buffer;
            pos = pos*2 - 1;
        } else {
            buffer = hp->heap[pos-1];
            hp->heap[pos-1] = hp->heap[pos*2];
            hp->heap[pos*2] = buffer;
            pos = pos * 2;
        }
    }
}

canonical_original_code:
void min_heapify(struct heap *hp, int index) {
    unsigned int pos = index + 1;
    while ((pos * 2 < hp->count && hp->compare(hp->heap[pos-1], hp->heap[pos*2]) > 0) ||
            (pos*2 -1 < hp->count && hp->compare(hp->heap[pos-1], hp->heap[pos*2 - 1]) > 0)) {
        void *buffer;
        if (pos * 2 >= hp->count || hp->compare(hp->heap[pos*2 - 1], hp->heap[pos*2]) < 0) {
            buffer = hp->heap[pos-1];
            hp->heap[pos-1] = hp->heap[pos*2 - 1];
            hp->heap[pos*2 - 1] = buffer;
            pos = pos*2 - 1;
        } else {
            buffer = hp->heap[pos-1];
            hp->heap[pos-1] = hp->heap[pos*2];
            hp->heap[pos*2] = buffer;
            pos = pos * 2;
        }
    }
}

variable_types: index int

variable_types:
buffer
void *


pop

original_code:
void *pop(struct heap *hp) {
    if (hp->count == 0)
        return ((void *)0);
    hp->count--;
    void *top = hp->heap[0];
    hp->heap[0] = hp->heap[hp->count];
    hp->heap[hp->count] = ((void *)0);
    min_heapify(hp, 0);
    return top;
}

variable_types:
top
void *


original_code:
void remove_if(struct heap* hp, int (*to_remove)(void*)) {
    int i;
    for (i = 0; i < hp->count; i++) {
        if ( to_remove(hp->heap[i]) ) {
            hp->count--;
            hp->destruct(hp->heap[i]);
            hp->heap[i] = hp->heap[hp->count];
            hp->heap[hp->count] = ((void *)0);
            min_heapify(hp, i);
        }
    }
}

canonical_original_code:
void remove_if(struct heap *hp, int (*to_remove)(void *)) {
    int i;
    for (i = 0; i < hp->count; i++) {
        if ( to_remove(hp->heap[i]) ) {
            hp->count--;
            hp->destruct(hp->heap[i]);
            hp->heap[i] = hp->heap[hp->count];
            hp->heap[hp->count] = ((void *)0);
            min_heapify(hp, i);
        }
    }
}

variable_types: i int


size

decompiled_code:
__int64 __fastcall size(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

original_code:
unsigned size(struct heap *hp) {
    return hp->count;
}

canonical_original_code:
unsigned int size(struct heap *hp) {
    return hp->count;
}

return_type: unsigned int


traverse

decompiled_code:
__int64 __fastcall traverse(__int64 a1, __int64 (__fastcall *a2)(_QWORD))
{
__int64 v2; // rbx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 24) )
{
v2 = 0LL;
do
result = a2(*(_QWORD *)(*(_QWORD *)a1 + 8 * v2++));
while ( *(_DWORD *)(a1 + 24) > (unsigned int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 (__fastcall *a2)(_QWORD))
{
__int64 v2; // rbx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 24) )
{
v2 = 0LL;
do
result = a2(*(_QWORD *)(*(_QWORD *)a1 + 8 * v2++));
while ( *(_DWORD *)(a1 + 24) > (unsigned int)v2 );
}
return result;
}

original_code:
void traverse(struct heap* hp, void (*func)(void*)) {
    int i;
    for (i = 0; i < hp->count; i++) {
        func( hp->heap[i] );
    }
}

canonical_original_code:
void traverse(struct heap *hp, void (*func)(void *)) {
    int i;
    for (i = 0; i < hp->count; i++) {
        func( hp->heap[i] );
    }
}

variable_types:
func
void (*)(void *)


decompiled_code:
__int64 __fastcall job_compare(__int64 a1, __int64 a2)
{
return 2 * (unsigned int)(*(_DWORD *)(a1 + 20) <= *(_DWORD *)(a2 + 20)) - 1;
}

original_code:
int job_compare( jobinfo j1, jobinfo j2) {
    if (j1->current_pri > j2->current_pri)
        return -1;
    else
        return 1;
}

canonical_original_code:
int job_compare(struct jobinfo *j1, struct jobinfo *j2) {
    if (j1->current_pri > j2->current_pri)
        return -1;
    else
        return 1;
}

variable_types: struct jobinfo { int jid; int pid; char **argv; int default_pri; int current_pri; int owner; int wait_time; long create_time; int run_time; int state; } *


decompiled_code:
void __fastcall job_destruct(void *ptr)
{
void **v2; // rax
void *v3; // rdi
__int64 v4; // rbx

v2 = (void **)*((_QWORD *)ptr + 1);
v3 = *v2;
if ( *v2 )
{
v4 = 0LL;
do
{
free(v3);
*(_QWORD *)(*((_QWORD *)ptr + 1) + v4 * 8) = 0LL;
v2 = (void **)*((_QWORD *)ptr + 1);
v3 = v2[++v4];
}
while ( v3 );
}
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
void **v2; // rax
void *v3; // rdi
__int64 v4; // rbx

v2 = (void **)*((_QWORD *)ptr + 1);
v3 = *v2;
if ( *v2 )
{
v4 = 0LL;
do
{
free(v3);
*(_QWORD *)(*((_QWORD *)ptr + 1) + v4 * 8) = 0LL;
v2 = (void **)*((_QWORD *)ptr + 1);
v3 = v2[++v4];
}
while ( v3 );
}
free(v2);
free(ptr);
}

original_code:
void job_destruct( jobinfo job ) {
    int i;
    for (i = 0; job->argv[i] != ((void *)0); i++) {
        free( job->argv[i] );
        job->argv[i] = ((void *)0);
    }
    free(job->argv);
    free(job);
}

canonical_original_code:
void job_destruct(struct jobinfo *job) {
    int i;
    for (i = 0; job->argv[i] != ((void *)0); i++) {
        free( job->argv[i] );
        job->argv[i] = ((void *)0);
    }
    free(job->argv);
    free(job);
}

user_defined_types: struct jobinfo { int jid; int pid; char **argv; int default_pri; int current_pri; int owner; int wait_time; long create_time; int run_time; int state; }


original_code:
struct command *create_cmd( int type, int pri, int uid, int argc, char *argv[] ) {
    char **p;
    struct command *cmd = malloc(sizeof(struct command));
    cmd->info = type;
    cmd->pri = pri;
    cmd->owner = uid;
    cmd->argc = argc;
    strcat(cmd->buf, *argv++);
    argc--;
    while (argc-- > 0) {
        strcat(cmd->buf, ":");
        strcat(cmd->buf, *argv++);
    }
    return cmd;
}

canonical_original_code:
struct command *create_cmd(int type, int pri, int uid, int argc, char *argv[]) {
    char **p;
    struct command *cmd = malloc(sizeof(struct command));
    cmd->info = type;
    cmd->pri = pri;
    cmd->owner = uid;
    cmd->argc = argc;
    strcat(cmd->buf, *argv++);
    argc--;
    while (argc-- > 0) {
        strcat(cmd->buf, ":");
        strcat(cmd->buf, *argv++);
    }
    return cmd;
}

variable_types: type int

variable_types: pri int

variable_types: uid int

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
p
char **

variable_types: struct command { int info; int state; int argc; int owner; int pri; char buf[100]; } *


return_type: struct command { int info; int state; int argc; int owner; int pri; char buf[100]; } *


yyerror

decompiled_code:
int __fastcall yyerror(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

original_code:
void yyerror(char *s) {
    fprintf(stderr, "%s\n", s);
}

variable_types:
s
char *


decompiled_code:
_QWORD *init_temp_cmd()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
cmd = (__int64)result;
*(_DWORD *)result = 0;
result[1] = 0LL;
*((_DWORD *)result + 1) = 0;
result[2] = 0LL;
result[3] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
cmd = (__int64)result;
*(_DWORD *)result = 0;
result[1] = 0LL;
*((_DWORD *)result + 1) = 0;
result[2] = 0LL;
result[3] = 0LL;
return result;
}

original_code:
void init_temp_cmd() {
    cmd = malloc(sizeof(struct simple_cmd));
    cmd->argc = 0;
    cmd->args = ((void *)0);
    cmd->append = 0;
    cmd->input = ((void *)0);
    cmd->output = ((void *)0);
}

user_defined_types: struct simple_cmd { int argc; int append; char **args; char *input; char *output; }