decompiled_code:
void __fastcall adns__sigpipe_protect(__int64 a1)
{
sigset_t v1; // [rsp-80h] [rbp-128h] BYREF
struct sigaction v2; // [rsp+0h] [rbp-A8h] BYREF

if ( (*(_BYTE *)a1 & 0x40) == 0 )
{
sigfillset(&v1);
sigdelset(&v1, 13);
v2.sa_handler = (__sighandler_t)(si_compar + 1);
sigfillset(&v2.sa_mask);
v2.sa_flags = 0;
if ( sigprocmask(2, &v1, (sigset_t *)(a1 + 352)) )
_assert_fail("!r", "general.c", 0x170u, "adns__sigpipe_protect");
if ( sigaction(13, &v2, (struct sigaction *)(a1 + 200)) )
_assert_fail("!r", "general.c", 0x171u, "adns__sigpipe_protect");
}
}

canonical_decompiled_code:
void __fastcall func21(__int64 a1)
{
sigset_t v1; // [rsp-80h] [rbp-128h] BYREF
struct sigaction v2; // [rsp+0h] [rbp-A8h] BYREF

if ( (*(_BYTE *)a1 & 0x40) == 0 )
{
sigfillset(&v1);
sigdelset(&v1, 13);
v2.sa_handler = (__sighandler_t)(si_compar + 1);
sigfillset(&v2.sa_mask);
v2.sa_flags = 0;
if ( sigprocmask(2, &v1, (sigset_t *)(a1 + 352)) )
_assert_fail("!r", "general.c", 0x170u, "adns__sigpipe_protect");
if ( sigaction(13, &v2, (struct sigaction *)(a1 + 200)) )
_assert_fail("!r", "general.c", 0x171u, "adns__sigpipe_protect");
}
}

original_code:
void adns__sigpipe_protect(adns_state ads) {
  sigset_t toblock;
  struct sigaction sa;
  int r;
  if (ads->iflags & adns_if_nosigpipe) return;
  sigfillset(&toblock);
  sigdelset(&toblock,13);
  sa.__sigaction_handler.sa_handler= ((__sighandler_t) 1);
  sigfillset(&sa.sa_mask);
  sa.sa_flags= 0;
  r= sigprocmask(2,&toblock,&ads->stdsigmask); ((void) sizeof ((!r) ? 1 : 0), __extension__ ({ if (!r) ; else __assert_fail ("!r", "general.c", 368, __extension__ __PRETTY_FUNCTION__); }));
  r= sigaction(13,&sa,&ads->stdsigpipe); ((void) sizeof ((!r) ? 1 : 0), __extension__ ({ if (!r) ; else __assert_fail ("!r", "general.c", 369, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void adns__sigpipe_protect(struct adns__state *ads) {
  struct __sigset_t toblock;
  struct sigaction sa;
  int r;
  if (ads->iflags & adns_if_nosigpipe) return;
  sigfillset(&toblock);
  sigdelset(&toblock,13);
  sa.__sigaction_handler.sa_handler= ((void (*)(int)) 1);
  sigfillset(&sa.sa_mask);
  sa.sa_flags= 0;
  r= sigprocmask(2,&toblock,&ads->stdsigmask); ((void) sizeof ((!r) ? 1 : 0), __extension__ ({ if (!r) ; else __assert_fail ("!r", "general.c", 368, __extension__ __PRETTY_FUNCTION__); }));
  r= sigaction(13,&sa,&ads->stdsigpipe); ((void) sizeof ((!r) ? 1 : 0), __extension__ ({ if (!r) ; else __assert_fail ("!r", "general.c", 369, __extension__ __PRETTY_FUNCTION__); }));
}

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

variable_types: r 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 query_queue { struct adns__query *head; }

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


decompiled_code:
void __fastcall adns__sigpipe_unprotect(__int64 a1)
{
if ( (*(_BYTE *)a1 & 0x40) == 0 )
{
if ( sigaction(13, (const struct sigaction *)(a1 + 200), 0LL) )
_assert_fail("!r", "general.c", 0x179u, "adns__sigpipe_unprotect");
if ( sigprocmask(2, (const sigset_t *)(a1 + 352), 0LL) )
_assert_fail("!r", "general.c", 0x17Au, "adns__sigpipe_unprotect");
}
}

canonical_decompiled_code:
void __fastcall func22(__int64 a1)
{
if ( (*(_BYTE *)a1 & 0x40) == 0 )
{
if ( sigaction(13, (const struct sigaction *)(a1 + 200), 0LL) )
_assert_fail("!r", "general.c", 0x179u, "adns__sigpipe_unprotect");
if ( sigprocmask(2, (const sigset_t *)(a1 + 352), 0LL) )
_assert_fail("!r", "general.c", 0x17Au, "adns__sigpipe_unprotect");
}
}

original_code:
void adns__sigpipe_unprotect(adns_state ads) {
  int r;
  if (ads->iflags & adns_if_nosigpipe) return;
  r= sigaction(13,&ads->stdsigpipe,0); ((void) sizeof ((!r) ? 1 : 0), __extension__ ({ if (!r) ; else __assert_fail ("!r", "general.c", 377, __extension__ __PRETTY_FUNCTION__); }));
  r= sigprocmask(2,&ads->stdsigmask,0); ((void) sizeof ((!r) ? 1 : 0), __extension__ ({ if (!r) ; else __assert_fail ("!r", "general.c", 378, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void adns__sigpipe_unprotect(struct adns__state *ads) {
  int r;
  if (ads->iflags & adns_if_nosigpipe) return;
  r= sigaction(13,&ads->stdsigpipe,0); ((void) sizeof ((!r) ? 1 : 0), __extension__ ({ if (!r) ; else __assert_fail ("!r", "general.c", 377, __extension__ __PRETTY_FUNCTION__); }));
  r= sigprocmask(2,&ads->stdsigmask,0); ((void) sizeof ((!r) ? 1 : 0), __extension__ ({ if (!r) ; else __assert_fail ("!r", "general.c", 378, __extension__ __PRETTY_FUNCTION__); }));
}

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

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

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

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

user_defined_types: struct sortlist { struct in_addr base; }

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

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

user_defined_types: struct 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: enum adns_queryflags { adns_qf_none=0, adns_qf_search=1, adns_qf_usevc=2, adns_qf_owner=4, adns_qf_quoteok_query=16, adns_qf_quoteok_cname=0, adns_qf_quoteok_anshost=64, adns_qf_quotefail_cname=128, adns_qf_cname_loose=256, adns_qf_cname_forbid=512, adns__qf_internalmask=267386880 }

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

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

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

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

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

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

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

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

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

user_defined_types: struct 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 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:
_BOOL8 __fastcall ctype_digit(int a1)
{
return (unsigned int)(a1 - 48) <= 9;
}

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

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

variable_types: c int

return_type: int


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

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

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


decompiled_code:
__int64 __fastcall ctype_domainunquoted(int c)
{
unsigned int v1; // er8
__int64 result; // rax

if ( ctype_alpha(c) || ctype_digit(c) )
result = v1;
else
result = strchr("-_/+", c) != 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int c)
{
unsigned int v1; // er8
__int64 result; // rax

if ( func1(c) || func0(c) )
result = v1;
else
result = strchr("-_/+", c) != 0LL;
return result;
}

original_code:
static inline int ctype_domainunquoted(int c) {
  return ctype_alpha(c) || ctype_digit(c) || (strchr("-_/+",c) != 0);
}


decompiled_code:
__int64 __fastcall vbuf__append_quoted1035(__int64 a1, unsigned __int8 *a2, int a3)
{
int v4; // er13
unsigned __int8 *v5; // rbp
int v6; // ebx
unsigned int v7; // er12
size_t v8; // rax
int v9; // ebx
char s[66]; // [rsp+0h] [rbp-42h] BYREF

if ( !a3 )
return 1LL;
v4 = a3;
while ( 1 )
{
s[0] = 0;
if ( v4 <= 0 )
{
v6 = 0;
}
else
{
v5 = a2;
v6 = 0;
while ( 1 )
{
v7 = *v5;
if ( v7 - 33 > 0x5D )
{
sprintf(s, "\\%03o", *v5);
goto LABEL_9;
}
if ( !(unsigned int)ctype_domainunquoted(*v5) )
break;
++v6;
++v5;
if ( v6 == v4 )
goto LABEL_9;
}
sprintf(s, "\\%c", v7);
}
LABEL_9:
if ( !(unsigned int)adns__vbuf_append(a1, a2, (unsigned int)v6) )
return 0LL;
v8 = strlen(s);
if ( !(unsigned int)adns__vbuf_append(a1, s, v8) )
return 0LL;
v9 = (v4 > v6) + v6;
a2 += v9;
v4 -= v9;
if ( !v4 )
return 1LL;
}
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int8 *a2, int a3)
{
int v4; // er13
unsigned __int8 *v5; // rbp
int v6; // ebx
unsigned int v7; // er12
size_t v8; // rax
int v9; // ebx
char s[66]; // [rsp+0h] [rbp-42h] BYREF

if ( !a3 )
return 1LL;
v4 = a3;
while ( 1 )
{
s[0] = 0;
if ( v4 <= 0 )
{
v6 = 0;
}
else
{
v5 = a2;
v6 = 0;
while ( 1 )
{
v7 = *v5;
if ( v7 - 33 > 0x5D )
{
sprintf(s, "\\%03o", *v5);
goto LABEL_9;
}
if ( !(unsigned int)func2(*v5) )
break;
++v6;
++v5;
if ( v6 == v4 )
goto LABEL_9;
}
sprintf(s, "\\%c", v7);
}
LABEL_9:
if ( !(unsigned int)adns__vbuf_append(a1, a2, (unsigned int)v6) )
return 0LL;
v8 = strlen(s);
if ( !(unsigned int)adns__vbuf_append(a1, s, v8) )
return 0LL;
v9 = (v4 > v6) + v6;
a2 += v9;
v4 -= v9;
if ( !v4 )
return 1LL;
}
}

original_code:
int vbuf__append_quoted1035(vbuf *vb, const byte *buf, int len) {
  char qbuf[10];
  int i, ch;
  while (len) {
    qbuf[0]= 0;
    for (i=0; i<len; i++) {
      ch= buf[i];
      if (ch <= ' ' || ch >= 127) {
 sprintf(qbuf,"\\%03o",ch);
 break;
      } else if (!ctype_domainunquoted(ch)) {
 sprintf(qbuf,"\\%c",ch);
 break;
      }
    }
    if (!adns__vbuf_append(vb,buf,i) ||
 !adns__vbuf_append(vb,qbuf,strlen(qbuf)))
      return 0;
    if (i<len) i++;
    buf+= i;
    len-= i;
  }
  return 1;
}

canonical_original_code:
int vbuf__append_quoted1035(struct vbuf *vb, unsigned char *buf, int len) {
  char qbuf[10];
  int i; int ch;
  while (len) {
    qbuf[0]= 0;
    for (i=0; i<len; i++) {
      ch= buf[i];
      if (ch <= ' ' || ch >= 127) {
 sprintf(qbuf,"\\%03o",ch);
 break;
      } else if (!ctype_domainunquoted(ch)) {
 sprintf(qbuf,"\\%c",ch);
 break;
      }
    }
    if (!adns__vbuf_append(vb,buf,i) ||
 !adns__vbuf_append(vb,qbuf,strlen(qbuf)))
      return 0;
    if (i<len) i++;
    buf+= i;
    len-= i;
  }
  return 1;
}

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

variable_types:
buf
unsigned char *

variable_types: len int

variable_types:
qbuf
char [10]

variable_types: i int

variable_types: ch int


original_code:
void adns__findlabel_start(findlabel_state *fls, adns_state ads,
      int serv, adns_query qu,
      const byte *dgram, int dglen, int max,
      int dmbegin, int *dmend_rlater) {
  fls->ads= ads;
  fls->qu= qu;
  fls->serv= serv;
  fls->dgram= dgram;
  fls->dglen= dglen;
  fls->max= max;
  fls->cbyte= dmbegin;
  fls->namelen= 0;
  fls->dmend_r= dmend_rlater;
}

canonical_original_code:
void adns__findlabel_start(struct findlabel_state *fls, struct adns__state *ads, int serv, struct adns__query *qu, unsigned char *dgram, int dglen, int max, int dmbegin, int *dmend_rlater) {
  fls->ads= ads;
  fls->qu= qu;
  fls->serv= serv;
  fls->dgram= dgram;
  fls->dglen= dglen;
  fls->max= max;
  fls->cbyte= dmbegin;
  fls->namelen= 0;
  fls->dmend_r= dmend_rlater;
}

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:
ads
struct adns__state *

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

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

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

user_defined_types: struct query_queue { struct adns__query *head; }

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

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

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

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

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


original_code:
adns_status adns__findlabel_next(findlabel_state *fls,
     int *lablen_r, int *labstart_r) {
  int lablen, jumpto;
  const char *dgram;
  dgram= fls->dgram;
  for (;;) {
    if (fls->cbyte >= fls->dglen) goto x_truncated;
    if (fls->cbyte >= fls->max) goto x_badresponse;
    ((lablen)= (((dgram)[((fls->cbyte))++]) & 0x0ff));
    if (!(lablen & 0x0c0)) break;
    if ((lablen & 0x0c0) != 0x0c0) return adns_s_unknownformat;
    if (fls->cbyte >= fls->dglen) goto x_truncated;
    if (fls->cbyte >= fls->max) goto x_badresponse;
    ((jumpto)= (((dgram)[((fls->cbyte))++]) & 0x0ff));
    jumpto |= (lablen&0x3f)<<8;
    if (fls->dmend_r) *(fls->dmend_r)= fls->cbyte;
    fls->cbyte= jumpto;
    fls->dmend_r= 0; fls->max= fls->dglen+1;
  }
  if (labstart_r) *labstart_r= fls->cbyte;
  if (lablen) {
    if (fls->namelen) fls->namelen++;
    fls->namelen+= lablen;
    if (fls->namelen > 255) return adns_s_answerdomaintoolong;
    fls->cbyte+= lablen;
    if (fls->cbyte > fls->dglen) goto x_truncated;
    if (fls->cbyte > fls->max) goto x_badresponse;
  } else {
    if (fls->dmend_r) *(fls->dmend_r)= fls->cbyte;
  }
  *lablen_r= lablen;
  return adns_s_ok;
 x_truncated:
  *lablen_r= -1;
  return adns_s_ok;
 x_badresponse:
  adns__diag(fls->ads,fls->serv,fls->qu,
      "label in domain runs beyond end of domain");
  return adns_s_invalidresponse;
}

canonical_original_code:
enum adns_status adns__findlabel_next(struct findlabel_state *fls, int *lablen_r, int *labstart_r) {
  int lablen; int jumpto;
  char *dgram;
  dgram= fls->dgram;
  for (;;) {
    if (fls->cbyte >= fls->dglen) goto x_truncated;
    if (fls->cbyte >= fls->max) goto x_badresponse;
    ((lablen)= (((dgram)[((fls->cbyte))++]) & 0x0ff));
    if (!(lablen & 0x0c0)) break;
    if ((lablen & 0x0c0) != 0x0c0) return adns_s_unknownformat;
    if (fls->cbyte >= fls->dglen) goto x_truncated;
    if (fls->cbyte >= fls->max) goto x_badresponse;
    ((jumpto)= (((dgram)[((fls->cbyte))++]) & 0x0ff));
    jumpto |= (lablen&0x3f)<<8;
    if (fls->dmend_r) *(fls->dmend_r)= fls->cbyte;
    fls->cbyte= jumpto;
    fls->dmend_r= 0; fls->max= fls->dglen+1;
  }
  if (labstart_r) *labstart_r= fls->cbyte;
  if (lablen) {
    if (fls->namelen) fls->namelen++;
    fls->namelen+= lablen;
    if (fls->namelen > 255) return adns_s_answerdomaintoolong;
    fls->cbyte+= lablen;
    if (fls->cbyte > fls->dglen) goto x_truncated;
    if (fls->cbyte > fls->max) goto x_badresponse;
  } else {
    if (fls->dmend_r) *(fls->dmend_r)= fls->cbyte;
  }
  *lablen_r= lablen;
  return adns_s_ok;
 x_truncated:
  *lablen_r= -1;
  return adns_s_ok;
 x_badresponse:
  adns__diag(fls->ads,fls->serv,fls->qu,
      "label in domain runs beyond end of domain");
  return adns_s_invalidresponse;
}

variable_types: lablen int

variable_types: jumpto int

variable_types:
dgram
char *

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

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

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

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

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

user_defined_types: struct sortlist { struct in_addr base; }

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

user_defined_types: struct allocnode { struct allocnode *next; }

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

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

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

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall adns__parse_domain_more(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4, char a5, __int64 a6)
{
int v6; // er14
int v7; // er13
__int64 result; // rax
unsigned __int8 *v11; // rsi
int v12; // ecx
int v13; // er8
unsigned int v14; // er9
__int64 v15; // rdx
int v16; // ecx
int v17; // er8
int v18; // [rsp+8h] [rbp-30h] BYREF
int v19[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = 1;
v7 = a5 & 1;
while ( 1 )
{
result = adns__findlabel_next(a1, &v18, v19);
if ( (_DWORD)result )
return result;
if ( v18 < 0 )
{
*a4 = 0;
return result;
}
if ( !v18 )
return (unsigned int)adns__vbuf_append(a4, &unk_8A9, 1LL) == 0;
if ( !v6 && !(unsigned int)adns__vbuf_append(a4, ".", 1LL) )
return 1LL;
v11 = (unsigned __int8 *)(a6 + v19[0]);
if ( v7 )
{
if ( !(unsigned int)vbuf__append_quoted1035((__int64)a4, v11, v18) )
return 1LL;
}
else
{
if ( !ctype_alpha(*v11) && !ctype_digit(v13) )
return 102LL;
v14 = v18;
LODWORD(v15) = v12 + 1;
v16 = v18 + v12;
if ( v18 > 1 )
{
v15 = (int)v15;
while ( *(_BYTE *)(a6 + v15) == 45 || ctype_alpha(*(unsigned __int8 *)(a6 + v15)) || ctype_digit(v17) )
{
if ( v16 <= (int)++v15 )
goto LABEL_15;
}
return 102LL;
}
LABEL_15:
if ( !(unsigned int)adns__vbuf_append(a4, v11, v14) )
return 1LL;
}
v6 = 0;
}
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4, char a5, __int64 a6)
{
int v6; // er14
int v7; // er13
__int64 result; // rax
unsigned __int8 *v11; // rsi
int v12; // ecx
int v13; // er8
unsigned int v14; // er9
__int64 v15; // rdx
int v16; // ecx
int v17; // er8
int v18; // [rsp+8h] [rbp-30h] BYREF
int v19[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = 1;
v7 = a5 & 1;
while ( 1 )
{
result = func5(a1, &v18, v19);
if ( (_DWORD)result )
return result;
if ( v18 < 0 )
{
*a4 = 0;
return result;
}
if ( !v18 )
return (unsigned int)adns__vbuf_append(a4, &unk_8A9, 1LL) == 0;
if ( !v6 && !(unsigned int)adns__vbuf_append(a4, ".", 1LL) )
return 1LL;
v11 = (unsigned __int8 *)(a6 + v19[0]);
if ( v7 )
{
if ( !(unsigned int)func3((__int64)a4, v11, v18) )
return 1LL;
}
else
{
if ( !func1(*v11) && !func0(v13) )
return 102LL;
v14 = v18;
LODWORD(v15) = v12 + 1;
v16 = v18 + v12;
if ( v18 > 1 )
{
v15 = (int)v15;
while ( *(_BYTE *)(a6 + v15) == 45 || func1(*(unsigned __int8 *)(a6 + v15)) || func0(v17) )
{
if ( v16 <= (int)++v15 )
goto LABEL_15;
}
return 102LL;
}
LABEL_15:
if ( !(unsigned int)adns__vbuf_append(a4, v11, v14) )
return 1LL;
}
v6 = 0;
}
}

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: 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_byteblock { int len; unsigned char *data; }

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 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)
{
__int64 v11; // r8
__int64 v12; // r11
char v14[88]; // [rsp+0h] [rbp-58h] 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, v12, a4, a5, v11);
}

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

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


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

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


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

variable_types: serv int

variable_types:
dgram
unsigned char *

variable_types: dglen int

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

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

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

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