#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_9__ TYPE_2__;
typedef struct TYPE_8__ TYPE_1__;

/* Type definitions */
typedef scalar_t__ u_int;
typedef int /*<<< orphan*/ u_char;
typedef TYPE_1__ *res_state;
struct TYPE_9__ {
  int /*<<< orphan*/ rcode;
};
struct TYPE_8__ {
  scalar_t__ ndots;
  int res_h_errno;
  unsigned int options;
  scalar_t__ dnsrch;
};
typedef TYPE_2__ HEADER;

/* Variables and functions */
scalar_t__ ECONNREFUSED;
#define HOST_NOT_FOUND 130
#define NO_DATA 129
int NS_MAXDNAME;
unsigned int RES_DEFNAMES;
unsigned int RES_DNSRCH;
unsigned int RES_NOTLDQUERY;
int /*<<< orphan*/ RES_SET_H_ERRNO(TYPE_1__ *, int const);
int /*<<< orphan*/ SERVFAIL;
#define TRY_AGAIN 128
scalar_t__ errno;
char *res_hostalias(TYPE_1__ *, char const *, char *, int);
int res_nquery(TYPE_1__ *, char const *, int, int, int /*<<< orphan*/ *, int);
int res_nquerydomain(TYPE_1__ *, char const *, char const *, int, int,
                     int /*<<< orphan*/ *, int);
int res_nsearch(res_state statp, const char *name, int class, int type,
                u_char *answer, int anslen) {
  const char *cp, *const *domain;
  HEADER *hp = (HEADER *)answer;
  char tmp[NS_MAXDNAME];
  u_int dots;
  int trailing_dot, ret, saved_herrno;
  int got_nodata = 0, got_servfail = 0, root_on_list = 0;
  int tried_as_is = 0;
  int searched = 0;
  errno = 0;
  RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);
  dots = 0;
  for (cp = name; *cp != '\0'; cp++)
    dots += (*cp == '.');
  trailing_dot = 0;
  if (cp > name && *--cp == '.')
    trailing_dot++;
  if (!dots && (cp = res_hostalias(statp, name, tmp, sizeof tmp)) != NULL)
    return (res_nquery(statp, cp, class, type, answer, anslen));
  saved_herrno = -1;
  if (dots >= statp->ndots || trailing_dot) {
    ret = res_nquerydomain(statp, name, NULL, class, type, answer, anslen);
    if (ret > 0 || trailing_dot)
      return (ret);
    if (errno == ECONNREFUSED) {
      RES_SET_H_ERRNO(statp, TRY_AGAIN);
      return (-1);
    }
    switch (statp->res_h_errno) {
    case NO_DATA:
    case HOST_NOT_FOUND:
      break;
    case TRY_AGAIN:
      if (hp->rcode == SERVFAIL)
        break;
    default:
      return (-1);
    }
    saved_herrno = statp->res_h_errno;
    tried_as_is++;
  }
  if ((!dots && (statp->options & RES_DEFNAMES) != 0U) ||
      (dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0U)) {
    int done = 0;
    for (domain = (const char *const *)statp->dnsrch; *domain && !done;
         domain++) {
      searched = 1;
      if (domain[0][0] == '\0' || (domain[0][0] == '.' && domain[0][1] == '\0'))
        root_on_list++;
      if (root_on_list && tried_as_is)
        continue;
      ret = res_nquerydomain(statp, name, *domain, class, type, answer, anslen);
      if (ret > 0)
        return (ret);
      if (errno == ECONNREFUSED) {
        RES_SET_H_ERRNO(statp, TRY_AGAIN);
        return (-1);
      }
      switch (statp->res_h_errno) {
      case NO_DATA:
        got_nodata++;
      case HOST_NOT_FOUND:
        break;
      case TRY_AGAIN:
        got_servfail++;
        if (hp->rcode == SERVFAIL) {
          break;
        }
      default:
        done++;
      }
      if ((statp->options & RES_DNSRCH) == 0U)
        done++;
    }
  }
  switch (statp->res_h_errno) {
  case NO_DATA:
  case HOST_NOT_FOUND:
    break;
  case TRY_AGAIN:
    if (hp->rcode == SERVFAIL)
      break;
  default:
    goto giveup;
  }
  if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0U) &&
      !(tried_as_is || root_on_list)) {
    ret = res_nquerydomain(statp, name, NULL, class, type, answer, anslen);
    if (ret > 0)
      return (ret);
  }
giveup:
  if (saved_herrno != -1)
    RES_SET_H_ERRNO(statp, saved_herrno);
  else if (got_nodata)
    RES_SET_H_ERRNO(statp, NO_DATA);
  else if (got_servfail)
    RES_SET_H_ERRNO(statp, TRY_AGAIN);
  return (-1);
}


x86 assembly (clang, -O0):
<res_nsearch>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x98(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x90(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x70(%rbp)
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
movl   $0x0,-0x80(%rbp)
mov    0x2dff(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x82,%esi
call   1030 <RES_SET_H_ERRNO@plt>
movq   $0x0,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     122b <res_nsearch+0xeb>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cltq
add    -0x60(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11ee <res_nsearch+0xae>
movl   $0x0,-0x64(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1265 <res_nsearch+0x125>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
movsbl -0x1(%rax),%eax
cmp    $0x2e,%eax
jne    1265 <res_nsearch+0x125>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    12c8 <res_nsearch+0x188>
mov    -0x90(%rbp),%rdx
mov    -0x98(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    %eax,%ecx
call   1050 <res_hostalias@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     12c8 <res_nsearch+0x188>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
call   1040 <res_nquery@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    17c3 <res_nsearch+0x683>
movl   $0xffffffff,-0x6c(%rbp)
mov    -0x60(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jge    12ea <res_nsearch+0x1aa>
cmpl   $0x0,-0x64(%rbp)
je     13ff <res_nsearch+0x2bf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x28(%rbp),%r9
mov    -0x2c(%rbp),%eax
xor    %edx,%edx
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1060 <res_nquerydomain@plt>
add    $0x10,%rsp
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jg     1329 <res_nsearch+0x1e9>
cmpl   $0x0,-0x64(%rbp)
je     133e <res_nsearch+0x1fe>
mov    -0x68(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    17c3 <res_nsearch+0x683>
mov    0x2c83(%rip),%rax
mov    (%rax),%rax
mov    0x2c91(%rip),%rcx
cmp    (%rcx),%rax
jne    137c <res_nsearch+0x23c>
mov    -0x10(%rbp),%rdi
mov    $0x80,%esi
call   1030 <RES_SET_H_ERRNO@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    17c3 <res_nsearch+0x683>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x9c(%rbp)
sub    $0x80,%eax
je     13b7 <res_nsearch+0x277>
jmp    1399 <res_nsearch+0x259>
mov    -0x9c(%rbp),%eax
add    $0xffffff7f,%eax
sub    $0x1,%eax
ja     13d6 <res_nsearch+0x296>
jmp    13b2 <res_nsearch+0x272>
jmp    13ec <res_nsearch+0x2ac>
mov    -0x48(%rbp),%rax
mov    (%rax),%eax
mov    0x2c0c(%rip),%rcx
cmp    (%rcx),%eax
jne    13d1 <res_nsearch+0x291>
jmp    13ec <res_nsearch+0x2ac>
jmp    13d6 <res_nsearch+0x296>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    17c3 <res_nsearch+0x683>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    1423 <res_nsearch+0x2e3>
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
mov    0x2b98(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1451 <res_nsearch+0x311>
cmpq   $0x0,-0x60(%rbp)
je     1663 <res_nsearch+0x523>
cmpl   $0x0,-0x64(%rbp)
jne    1663 <res_nsearch+0x523>
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
mov    0x2b72(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1663 <res_nsearch+0x523>
movl   $0x0,-0x88(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rcx
xor    %eax,%eax
cmpq   $0x0,(%rcx)
mov    %al,-0x9d(%rbp)
je     148f <res_nsearch+0x34f>
cmpl   $0x0,-0x88(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x9d(%rbp)
mov    -0x9d(%rbp),%al
test   $0x1,%al
jne    14a2 <res_nsearch+0x362>
jmp    165e <res_nsearch+0x51e>
movl   $0x1,-0x80(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     14e3 <res_nsearch+0x3a3>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    14ec <res_nsearch+0x3ac>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    14ec <res_nsearch+0x3ac>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
cmpl   $0x0,-0x78(%rbp)
je     1505 <res_nsearch+0x3c5>
cmpl   $0x0,-0x7c(%rbp)
je     1505 <res_nsearch+0x3c5>
jmp    164d <res_nsearch+0x50d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    (%rax),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x28(%rbp),%r9
mov    -0x2c(%rbp),%eax
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1060 <res_nquerydomain@plt>
add    $0x10,%rsp
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jle    1554 <res_nsearch+0x414>
mov    -0x68(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    17c3 <res_nsearch+0x683>
mov    0x2a6d(%rip),%rax
mov    (%rax),%rax
mov    0x2a7b(%rip),%rcx
cmp    (%rcx),%rax
jne    1592 <res_nsearch+0x452>
mov    -0x10(%rbp),%rdi
mov    $0x80,%esi
call   1030 <RES_SET_H_ERRNO@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    17c3 <res_nsearch+0x683>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0xa4(%rbp)
sub    $0x80,%eax
je     15e9 <res_nsearch+0x4a9>
jmp    15af <res_nsearch+0x46f>
mov    -0xa4(%rbp),%eax
sub    $0x81,%eax
je     15db <res_nsearch+0x49b>
jmp    15c5 <res_nsearch+0x485>
mov    -0xa4(%rbp),%eax
sub    $0x82,%eax
je     15e4 <res_nsearch+0x4a4>
jmp    1611 <res_nsearch+0x4d1>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    1620 <res_nsearch+0x4e0>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%eax
mov    0x29d1(%rip),%rcx
cmp    (%rcx),%eax
jne    160c <res_nsearch+0x4cc>
jmp    1620 <res_nsearch+0x4e0>
jmp    1611 <res_nsearch+0x4d1>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
mov    0x298a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1648 <res_nsearch+0x508>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    164d <res_nsearch+0x50d>
mov    -0x40(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x40(%rbp)
jmp    1467 <res_nsearch+0x327>
jmp    1663 <res_nsearch+0x523>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0xa8(%rbp)
sub    $0x80,%eax
je     169e <res_nsearch+0x55e>
jmp    1680 <res_nsearch+0x540>
mov    -0xa8(%rbp),%eax
add    $0xffffff7f,%eax
sub    $0x1,%eax
ja     16bd <res_nsearch+0x57d>
jmp    1699 <res_nsearch+0x559>
jmp    16c2 <res_nsearch+0x582>
mov    -0x48(%rbp),%rax
mov    (%rax),%eax
mov    0x2925(%rip),%rcx
cmp    (%rcx),%eax
jne    16b8 <res_nsearch+0x578>
jmp    16c2 <res_nsearch+0x582>
jmp    16bd <res_nsearch+0x57d>
jmp    1758 <res_nsearch+0x618>
cmpq   $0x0,-0x60(%rbp)
jne    16f0 <res_nsearch+0x5b0>
cmpl   $0x0,-0x80(%rbp)
je     16f0 <res_nsearch+0x5b0>
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
mov    0x28db(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1753 <res_nsearch+0x613>
cmpl   $0x0,-0x7c(%rbp)
jne    1753 <res_nsearch+0x613>
cmpl   $0x0,-0x78(%rbp)
jne    1753 <res_nsearch+0x613>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x28(%rbp),%r9
mov    -0x2c(%rbp),%eax
xor    %edx,%edx
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1060 <res_nquerydomain@plt>
add    $0x10,%rsp
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jle    174e <res_nsearch+0x60e>
mov    -0x68(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    17c3 <res_nsearch+0x683>
jmp    1753 <res_nsearch+0x613>
jmp    1758 <res_nsearch+0x618>
cmpl   $0xffffffff,-0x6c(%rbp)
je     1773 <res_nsearch+0x633>
mov    -0x10(%rbp),%rdi
mov    -0x6c(%rbp),%esi
call   1030 <RES_SET_H_ERRNO@plt>
jmp    17b2 <res_nsearch+0x672>
cmpl   $0x0,-0x70(%rbp)
je     1790 <res_nsearch+0x650>
mov    -0x10(%rbp),%rdi
mov    $0x81,%esi
call   1030 <RES_SET_H_ERRNO@plt>
jmp    17ad <res_nsearch+0x66d>
cmpl   $0x0,-0x74(%rbp)
je     17a8 <res_nsearch+0x668>
mov    -0x10(%rbp),%rdi
mov    $0x80,%esi
call   1030 <RES_SET_H_ERRNO@plt>
jmp    17ad <res_nsearch+0x66d>
jmp    17b2 <res_nsearch+0x672>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<res_nsearch>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,-0x58(%rbp)
mov    %r8,-0x48(%rbp)
mov    %ecx,-0x40(%rbp)
mov    %edx,-0x3c(%rbp)
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e7c(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%r13
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    0x2e40(%rip),%rax
movq   $0x0,(%rax)
mov    $0x82,%esi
call   1030 <RES_SET_H_ERRNO@plt>
mov    (%rbx),%dl
test   %dl,%dl
je     11dc <res_nsearch+0x9c>
xor    %eax,%eax
mov    %rbx,%rcx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %esi,%esi
cmp    $0x2e,%dl
sete   %sil
add    %rsi,%rax
movzbl 0x1(%rcx),%edx
add    $0x1,%rcx
test   %dl,%dl
jne    11b0 <res_nsearch+0x70>
cmp    %rbx,%rcx
jbe    11e1 <res_nsearch+0xa1>
cmpb   $0x2e,-0x1(%rcx)
sete   %r14b
test   %rax,%rax
jne    11e9 <res_nsearch+0xa9>
jmp    11f6 <res_nsearch+0xb6>
xor    %r14d,%r14d
jmp    11f6 <res_nsearch+0xb6>
xor    %r14d,%r14d
test   %rax,%rax
je     11f6 <res_nsearch+0xb6>
mov    %rbx,-0x38(%rbp)
movl   $0x0,-0x4c(%rbp)
jmp    1237 <res_nsearch+0xf7>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r12d,%ecx
call   1050 <res_hostalias@plt>
test   %rax,%rax
je     122c <res_nsearch+0xec>
mov    %r15,%rdi
mov    %rax,%rsi
mov    -0x3c(%rbp),%edx
mov    -0x40(%rbp),%ecx
mov    -0x48(%rbp),%r8
mov    -0x58(%rbp),%r9
call   1040 <res_nquery@plt>
mov    %eax,%ebx
jmp    1503 <res_nsearch+0x3c3>
mov    %rbx,-0x38(%rbp)
mov    $0x1,%al
mov    %eax,-0x4c(%rbp)
xor    %eax,%eax
cmp    (%r15),%rax
setge  %r12b
or     %r14b,%r12b
mov    $0xffffffff,%eax
mov    %rax,-0x60(%rbp)
cmp    $0x1,%r12b
jne    12ef <res_nsearch+0x1af>
sub    $0x8,%rsp
mov    %r15,%rdi
mov    -0x38(%rbp),%rsi
xor    %edx,%edx
mov    -0x3c(%rbp),%ecx
mov    -0x40(%rbp),%r8d
mov    -0x48(%rbp),%r9
push   -0x58(%rbp)
call   1060 <res_nquerydomain@plt>
add    $0x10,%rsp
mov    %eax,%ebx
test   %eax,%eax
setg   %al
or     %r14b,%al
jne    1503 <res_nsearch+0x3c3>
mov    0x2d39(%rip),%rax
mov    (%rax),%rax
mov    0x2d47(%rip),%rcx
cmp    (%rcx),%rax
jne    12ab <res_nsearch+0x16b>
mov    %r15,%rdi
mov    $0x80,%esi
jmp    14f9 <res_nsearch+0x3b9>
mov    0x8(%r15),%ecx
lea    -0x81(%rcx),%eax
cmp    $0x2,%eax
jae    12c0 <res_nsearch+0x180>
mov    %rcx,-0x60(%rbp)
jmp    12ef <res_nsearch+0x1af>
mov    $0xffffffff,%ebx
cmp    $0x80,%ecx
jne    1503 <res_nsearch+0x3c3>
mov    -0x48(%rbp),%rax
mov    (%rax),%eax
mov    0x2cf2(%rip),%rcx
mov    $0x80,%edx
mov    %rdx,-0x60(%rbp)
cmp    (%rcx),%eax
jne    1503 <res_nsearch+0x3c3>
cmpb   $0x0,-0x4c(%rbp)
je     130d <res_nsearch+0x1cd>
mov    0x2cb4(%rip),%rax
mov    (%rax),%eax
test   %eax,0xc(%r15)
mov    -0x38(%rbp),%rsi
jne    1345 <res_nsearch+0x205>
jmp    1451 <res_nsearch+0x311>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0x0,%edi
mov    $0x0,%ecx
test   %r14b,%r14b
mov    -0x38(%rbp),%rsi
jne    1463 <res_nsearch+0x323>
mov    0x2c7f(%rip),%rax
mov    (%rax),%eax
test   %eax,0xc(%r15)
je     1451 <res_nsearch+0x311>
mov    0x10(%r15),%r14
mov    (%r14),%rdx
test   %rdx,%rdx
je     1451 <res_nsearch+0x311>
add    $0x8,%r14
xor    %edi,%edi
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
nopl   0x0(%rax)
movzbl (%rdx),%eax
test   %al,%al
je     1381 <res_nsearch+0x241>
cmp    $0x2e,%al
jne    1384 <res_nsearch+0x244>
cmpb   $0x0,0x1(%rdx)
jne    1384 <res_nsearch+0x244>
add    $0x1,%edi
test   %edi,%edi
setne  %cl
xor    %eax,%eax
test   %r12b,%cl
jne    1439 <res_nsearch+0x2f9>
mov    %edi,-0x38(%rbp)
mov    %r15,%rdi
sub    $0x8,%rsp
mov    %rsi,%r13
mov    -0x3c(%rbp),%ecx
mov    -0x40(%rbp),%r8d
mov    -0x48(%rbp),%r9
push   -0x58(%rbp)
call   1060 <res_nquerydomain@plt>
add    $0x10,%rsp
test   %eax,%eax
jg     152e <res_nsearch+0x3ee>
mov    0x2c01(%rip),%rax
mov    (%rax),%rax
mov    0x2c0f(%rip),%rcx
cmp    (%rcx),%rax
je     129e <res_nsearch+0x15e>
mov    0x8(%r15),%ecx
xor    %eax,%eax
cmp    $0x80,%ecx
je     1401 <res_nsearch+0x2c1>
cmp    $0x82,%ecx
je     1420 <res_nsearch+0x2e0>
cmp    $0x81,%ecx
mov    %r13,%rsi
jne    1419 <res_nsearch+0x2d9>
addl   $0x1,-0x30(%rbp)
jmp    1423 <res_nsearch+0x2e3>
addl   $0x1,-0x2c(%rbp)
mov    -0x48(%rbp),%rcx
mov    (%rcx),%ecx
mov    0x2bbe(%rip),%rdx
cmp    (%rdx),%ecx
mov    %r13,%rsi
je     1423 <res_nsearch+0x2e3>
mov    $0x1,%eax
jmp    1423 <res_nsearch+0x2e3>
mov    %r13,%rsi
mov    -0x38(%rbp),%edi
mov    0x2b8b(%rip),%rcx
mov    (%rcx),%ecx
and    0xc(%r15),%ecx
cmp    $0x1,%ecx
adc    $0x0,%eax
mov    (%r14),%rdx
mov    $0x1,%cl
test   %rdx,%rdx
je     1463 <res_nsearch+0x323>
add    $0x8,%r14
test   %eax,%eax
je     1370 <res_nsearch+0x230>
jmp    1463 <res_nsearch+0x323>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
xor    %edi,%edi
xor    %ecx,%ecx
mov    0x8(%r15),%eax
lea    -0x81(%rax),%edx
cmp    $0x2,%edx
jae    1494 <res_nsearch+0x354>
mov    -0x4c(%rbp),%eax
and    %cl,%al
cmp    $0x1,%al
jne    14ae <res_nsearch+0x36e>
mov    0x2b3e(%rip),%rax
mov    (%rax),%eax
test   %eax,0xc(%r15)
setne  %al
or     %r12b,%al
cmp    $0x1,%al
jne    14b3 <res_nsearch+0x373>
jmp    14dd <res_nsearch+0x39d>
cmp    $0x80,%eax
jne    14dd <res_nsearch+0x39d>
mov    -0x48(%rbp),%rax
mov    (%rax),%eax
mov    0x2b28(%rip),%rdx
cmp    (%rdx),%eax
je     1472 <res_nsearch+0x332>
jmp    14dd <res_nsearch+0x39d>
test   %r12b,%r12b
jne    14dd <res_nsearch+0x39d>
test   %edi,%edi
jne    14dd <res_nsearch+0x39d>
sub    $0x8,%rsp
mov    %r15,%rdi
xor    %edx,%edx
mov    -0x3c(%rbp),%ecx
mov    -0x40(%rbp),%r8d
mov    -0x48(%rbp),%r9
push   -0x58(%rbp)
call   1060 <res_nquerydomain@plt>
add    $0x10,%rsp
mov    %eax,%ebx
test   %eax,%eax
jg     1503 <res_nsearch+0x3c3>
mov    -0x60(%rbp),%rsi
cmp    $0xffffffff,%esi
je     14eb <res_nsearch+0x3ab>
mov    %r15,%rdi
jmp    14f9 <res_nsearch+0x3b9>
cmpl   $0x0,-0x30(%rbp)
je     1514 <res_nsearch+0x3d4>
mov    %r15,%rdi
mov    $0x81,%esi
call   1030 <RES_SET_H_ERRNO@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%ebx
cmpl   $0x0,-0x2c(%rbp)
je     1503 <res_nsearch+0x3c3>
mov    %r15,%rdi
mov    $0x80,%esi
call   1030 <RES_SET_H_ERRNO@plt>
jmp    1503 <res_nsearch+0x3c3>
mov    %eax,%ebx
jmp    1503 <res_nsearch+0x3c3>

LLVM IR (-O0):
%struct.TYPE_8__ = type { i64, i32, i32, i64 }
%struct.TYPE_9__ = type { i32 }
@NS_MAXDNAME = global i32 0
@errno = global i64 0
@ECONNREFUSED = global i64 0
@SERVFAIL = global i32 0
@RES_DEFNAMES = global i32 0
@RES_DNSRCH = global i32 0
@RES_NOTLDQUERY = global i32 0
define i32 @res_nsearch(%struct.TYPE_8__* %0, i8* %1, i32 %2, i32 %3, i32* %4, i32 %5) {
%7 = alloca i32
%8 = alloca %struct.TYPE_8__*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8**
%16 = alloca %struct.TYPE_9__*
%17 = alloca i8*
%18 = alloca i64
%19 = alloca i64
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
store %struct.TYPE_8__* %0, %struct.TYPE_8__** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32* %4, i32** %12
store i32 %5, i32* %13
%30 = load i32*, i32** %12
%31 = bitcast i32* %30 to %struct.TYPE_9__*
store %struct.TYPE_9__* %31, %struct.TYPE_9__** %16
%32 = load i32, i32* @NS_MAXDNAME
%33 = zext i32 %32 to i64
%34 = call i8* @llvm.stacksave()
store i8* %34, i8** %17
%35 = alloca i8, i64 %33
store i64 %33, i64* %18
store i32 0, i32* %23
store i32 0, i32* %24
store i32 0, i32* %25
store i32 0, i32* %26
store i32 0, i32* %27
store i64 0, i64* @errno
%36 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%37 = call i32 @RES_SET_H_ERRNO(%struct.TYPE_8__* %36, i32 130)
store i64 0, i64* %19
%38 = load i8*, i8** %9
store i8* %38, i8** %14
br label %39
39: ; preds = %53, %6
%40 = load i8*, i8** %14
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %56
44: ; preds = %39
%45 = load i8*, i8** %14
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 46
%49 = zext i1 %48 to i32
%50 = sext i32 %49 to i64
%51 = load i64, i64* %19
%52 = add nsw i64 %51, %50
store i64 %52, i64* %19
br label %53
53: ; preds = %44
%54 = load i8*, i8** %14
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %14
br label %39
56: ; preds = %39
store i32 0, i32* %20
%57 = load i8*, i8** %14
%58 = load i8*, i8** %9
%59 = icmp ugt i8* %57, %58
br i1 %59, label %60, label %69
60: ; preds = %56
%61 = load i8*, i8** %14
%62 = getelementptr inbounds i8, i8* %61, i32 -1
store i8* %62, i8** %14
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 46
br i1 %65, label %66, label %69
66: ; preds = %60
%67 = load i32, i32* %20
%68 = add nsw i32 %67, 1
store i32 %68, i32* %20
br label %69
69: ; preds = %66, %60, %56
%70 = load i64, i64* %19
%71 = icmp ne i64 %70, 0
br i1 %71, label %86, label %72
72: ; preds = %69
%73 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%74 = load i8*, i8** %9
%75 = trunc i64 %33 to i32
%76 = call i8* @res_hostalias(%struct.TYPE_8__* %73, i8* %74, i8* %35, i32 %75)
store i8* %76, i8** %14
%77 = icmp ne i8* %76, null
br i1 %77, label %78, label %86
78: ; preds = %72
%79 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%80 = load i8*, i8** %14
%81 = load i32, i32* %10
%82 = load i32, i32* %11
%83 = load i32*, i32** %12
%84 = load i32, i32* %13
%85 = call i32 @res_nquery(%struct.TYPE_8__* %79, i8* %80, i32 %81, i32 %82, i32* %83, i32 %84)
store i32 %85, i32* %7
store i32 1, i32* %28
br label %335
86: ; preds = %72, %69
store i32 -1, i32* %22
%87 = load i64, i64* %19
%88 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%89 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %88, i32 0, i32 0
%90 = load i64, i64* %89
%91 = icmp sge i64 %87, %90
br i1 %91, label %95, label %92
92: ; preds = %86
%93 = load i32, i32* %20
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %137
95: ; preds = %92, %86
%96 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%97 = load i8*, i8** %9
%98 = load i32, i32* %10
%99 = load i32, i32* %11
%100 = load i32*, i32** %12
%101 = load i32, i32* %13
%102 = call i32 @res_nquerydomain(%struct.TYPE_8__* %96, i8* %97, i8* null, i32 %98, i32 %99, i32* %100, i32 %101)
store i32 %102, i32* %21
%103 = load i32, i32* %21
%104 = icmp sgt i32 %103, 0
br i1 %104, label %108, label %105
105: ; preds = %95
%106 = load i32, i32* %20
%107 = icmp ne i32 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %105, %95
%109 = load i32, i32* %21
store i32 %109, i32* %7
store i32 1, i32* %28
br label %335
110: ; preds = %105
%111 = load i64, i64* @errno
%112 = load i64, i64* @ECONNREFUSED
%113 = icmp eq i64 %111, %112
br i1 %113, label %114, label %117
114: ; preds = %110
%115 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%116 = call i32 @RES_SET_H_ERRNO(%struct.TYPE_8__* %115, i32 128)
store i32 -1, i32* %7
store i32 1, i32* %28
br label %335
117: ; preds = %110
%118 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%119 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %118, i32 0, i32 1
%120 = load i32, i32* %119
switch i32 %120, label %130 [
i32 129, label %121
i32 130, label %121
i32 128, label %122
]
121: ; preds = %117, %117
br label %131
122: ; preds = %117
%123 = load %struct.TYPE_9__*, %struct.TYPE_9__** %16
%124 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %123, i32 0, i32 0
%125 = load i32, i32* %124
%126 = load i32, i32* @SERVFAIL
%127 = icmp eq i32 %125, %126
br i1 %127, label %128, label %129
128: ; preds = %122
br label %131
129: ; preds = %122
br label %130
130: ; preds = %117, %129
store i32 -1, i32* %7
store i32 1, i32* %28
br label %335
131: ; preds = %128, %121
%132 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%133 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %132, i32 0, i32 1
%134 = load i32, i32* %133
store i32 %134, i32* %22
%135 = load i32, i32* %26
%136 = add nsw i32 %135, 1
store i32 %136, i32* %26
br label %137
137: ; preds = %131, %92
%138 = load i64, i64* %19
%139 = icmp ne i64 %138, 0
br i1 %139, label %147, label %140
140: ; preds = %137
%141 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%142 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %141, i32 0, i32 2
%143 = load i32, i32* %142
%144 = load i32, i32* @RES_DEFNAMES
%145 = and i32 %143, %144
%146 = icmp ne i32 %145, 0
br i1 %146, label %160, label %147
147: ; preds = %140, %137
%148 = load i64, i64* %19
%149 = icmp ne i64 %148, 0
br i1 %149, label %150, label %266
150: ; preds = %147
%151 = load i32, i32* %20
%152 = icmp ne i32 %151, 0
br i1 %152, label %266, label %153
153: ; preds = %150
%154 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%155 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %154, i32 0, i32 2
%156 = load i32, i32* %155
%157 = load i32, i32* @RES_DNSRCH
%158 = and i32 %156, %157
%159 = icmp ne i32 %158, 0
br i1 %159, label %160, label %266
160: ; preds = %153, %140
store i32 0, i32* %29
%161 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%162 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %161, i32 0, i32 3
%163 = load i64, i64* %162
%164 = inttoptr i64 %163 to i8**
store i8** %164, i8*** %15
br label %165
165: ; preds = %262, %160
%166 = load i8**, i8*** %15
%167 = load i8*, i8** %166
%168 = icmp ne i8* %167, null
br i1 %168, label %169, label %173
169: ; preds = %165
%170 = load i32, i32* %29
%171 = icmp ne i32 %170, 0
%172 = xor i1 %171, true
br label %173
173: ; preds = %169, %165
%174 = phi i1 [ false, %165 ], [ %172, %169 ]
br i1 %174, label %175, label %265
175: ; preds = %173
store i32 1, i32* %27
%176 = load i8**, i8*** %15
%177 = getelementptr inbounds i8*, i8** %176, i64 0
%178 = load i8*, i8** %177
%179 = getelementptr inbounds i8, i8* %178, i64 0
%180 = load i8, i8* %179
%181 = sext i8 %180 to i32
%182 = icmp eq i32 %181, 0
br i1 %182, label %199, label %183
183: ; preds = %175
%184 = load i8**, i8*** %15
%185 = getelementptr inbounds i8*, i8** %184, i64 0
%186 = load i8*, i8** %185
%187 = getelementptr inbounds i8, i8* %186, i64 0
%188 = load i8, i8* %187
%189 = sext i8 %188 to i32
%190 = icmp eq i32 %189, 46
br i1 %190, label %191, label %202
191: ; preds = %183
%192 = load i8**, i8*** %15
%193 = getelementptr inbounds i8*, i8** %192, i64 0
%194 = load i8*, i8** %193
%195 = getelementptr inbounds i8, i8* %194, i64 1
%196 = load i8, i8* %195
%197 = sext i8 %196 to i32
%198 = icmp eq i32 %197, 0
br i1 %198, label %199, label %202
199: ; preds = %191, %175
%200 = load i32, i32* %25
%201 = add nsw i32 %200, 1
store i32 %201, i32* %25
br label %202
202: ; preds = %199, %191, %183
%203 = load i32, i32* %25
%204 = icmp ne i32 %203, 0
br i1 %204, label %205, label %209
205: ; preds = %202
%206 = load i32, i32* %26
%207 = icmp ne i32 %206, 0
br i1 %207, label %208, label %209
208: ; preds = %205
br label %262
209: ; preds = %205, %202
%210 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%211 = load i8*, i8** %9
%212 = load i8**, i8*** %15
%213 = load i8*, i8** %212
%214 = load i32, i32* %10
%215 = load i32, i32* %11
%216 = load i32*, i32** %12
%217 = load i32, i32* %13
%218 = call i32 @res_nquerydomain(%struct.TYPE_8__* %210, i8* %211, i8* %213, i32 %214, i32 %215, i32* %216, i32 %217)
store i32 %218, i32* %21
%219 = load i32, i32* %21
%220 = icmp sgt i32 %219, 0
br i1 %220, label %221, label %223
221: ; preds = %209
%222 = load i32, i32* %21
store i32 %222, i32* %7
store i32 1, i32* %28
br label %335
223: ; preds = %209
%224 = load i64, i64* @errno
%225 = load i64, i64* @ECONNREFUSED
%226 = icmp eq i64 %224, %225
br i1 %226, label %227, label %230
227: ; preds = %223
%228 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%229 = call i32 @RES_SET_H_ERRNO(%struct.TYPE_8__* %228, i32 128)
store i32 -1, i32* %7
store i32 1, i32* %28
br label %335
230: ; preds = %223
%231 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%232 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %231, i32 0, i32 1
%233 = load i32, i32* %232
switch i32 %233, label %248 [
i32 129, label %234
i32 130, label %237
i32 128, label %238
]
234: ; preds = %230
%235 = load i32, i32* %23
%236 = add nsw i32 %235, 1
store i32 %236, i32* %23
br label %237
237: ; preds = %230, %234
br label %251
238: ; preds = %230
%239 = load i32, i32* %24
%240 = add nsw i32 %239, 1
store i32 %240, i32* %24
%241 = load %struct.TYPE_9__*, %struct.TYPE_9__** %16
%242 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %241, i32 0, i32 0
%243 = load i32, i32* %242
%244 = load i32, i32* @SERVFAIL
%245 = icmp eq i32 %243, %244
br i1 %245, label %246, label %247
246: ; preds = %238
br label %251
247: ; preds = %238
br label %248
248: ; preds = %230, %247
%249 = load i32, i32* %29
%250 = add nsw i32 %249, 1
store i32 %250, i32* %29
br label %251
251: ; preds = %248, %246, %237
%252 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%253 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %252, i32 0, i32 2
%254 = load i32, i32* %253
%255 = load i32, i32* @RES_DNSRCH
%256 = and i32 %254, %255
%257 = icmp eq i32 %256, 0
br i1 %257, label %258, label %261
258: ; preds = %251
%259 = load i32, i32* %29
%260 = add nsw i32 %259, 1
store i32 %260, i32* %29
br label %261
261: ; preds = %258, %251
br label %262
262: ; preds = %261, %208
%263 = load i8**, i8*** %15
%264 = getelementptr inbounds i8*, i8** %263, i32 1
store i8** %264, i8*** %15
br label %165
265: ; preds = %173
br label %266
266: ; preds = %265, %153, %150, %147
%267 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%268 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %267, i32 0, i32 1
%269 = load i32, i32* %268
switch i32 %269, label %279 [
i32 129, label %270
i32 130, label %270
i32 128, label %271
]
270: ; preds = %266, %266
br label %280
271: ; preds = %266
%272 = load %struct.TYPE_9__*, %struct.TYPE_9__** %16
%273 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %272, i32 0, i32 0
%274 = load i32, i32* %273
%275 = load i32, i32* @SERVFAIL
%276 = icmp eq i32 %274, %275
br i1 %276, label %277, label %278
277: ; preds = %271
br label %280
278: ; preds = %271
br label %279
279: ; preds = %266, %278
br label %313
280: ; preds = %277, %270
%281 = load i64, i64* %19
%282 = icmp ne i64 %281, 0
br i1 %282, label %293, label %283
283: ; preds = %280
%284 = load i32, i32* %27
%285 = icmp ne i32 %284, 0
br i1 %285, label %286, label %293
286: ; preds = %283
%287 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%288 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %287, i32 0, i32 2
%289 = load i32, i32* %288
%290 = load i32, i32* @RES_NOTLDQUERY
%291 = and i32 %289, %290
%292 = icmp eq i32 %291, 0
br i1 %292, label %293, label %312
293: ; preds = %286, %283, %280
%294 = load i32, i32* %26
%295 = icmp ne i32 %294, 0
br i1 %295, label %312, label %296
296: ; preds = %293
%297 = load i32, i32* %25
%298 = icmp ne i32 %297, 0
br i1 %298, label %312, label %299
299: ; preds = %296
%300 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%301 = load i8*, i8** %9
%302 = load i32, i32* %10
%303 = load i32, i32* %11
%304 = load i32*, i32** %12
%305 = load i32, i32* %13
%306 = call i32 @res_nquerydomain(%struct.TYPE_8__* %300, i8* %301, i8* null, i32 %302, i32 %303, i32* %304, i32 %305)
store i32 %306, i32* %21
%307 = load i32, i32* %21
%308 = icmp sgt i32 %307, 0
br i1 %308, label %309, label %311
309: ; preds = %299
%310 = load i32, i32* %21
store i32 %310, i32* %7
store i32 1, i32* %28
br label %335
311: ; preds = %299
br label %312
312: ; preds = %311, %296, %293, %286
br label %313
313: ; preds = %312, %279
%314 = load i32, i32* %22
%315 = icmp ne i32 %314, -1
br i1 %315, label %316, label %320
316: ; preds = %313
%317 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%318 = load i32, i32* %22
%319 = call i32 @RES_SET_H_ERRNO(%struct.TYPE_8__* %317, i32 %318)
br label %334
320: ; preds = %313
%321 = load i32, i32* %23
%322 = icmp ne i32 %321, 0
br i1 %322, label %323, label %326
323: ; preds = %320
%324 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%325 = call i32 @RES_SET_H_ERRNO(%struct.TYPE_8__* %324, i32 129)
br label %333
326: ; preds = %320
%327 = load i32, i32* %24
%328 = icmp ne i32 %327, 0
br i1 %328, label %329, label %332
329: ; preds = %326
%330 = load %struct.TYPE_8__*, %struct.TYPE_8__** %8
%331 = call i32 @RES_SET_H_ERRNO(%struct.TYPE_8__* %330, i32 128)
br label %332
332: ; preds = %329, %326
br label %333
333: ; preds = %332, %323
br label %334
334: ; preds = %333, %316
store i32 -1, i32* %7
store i32 1, i32* %28
br label %335
335: ; preds = %334, %309, %227, %221, %130, %114, %108, %78
%336 = load i8*, i8** %17
%337 = load i32, i32* %7
ret i32 %337
}

LLVM IR (-O2):
%struct.TYPE_8__ = type { i64, i32, i32, i64 }
@NS_MAXDNAME = global i32 0
@errno = global i64 0
@ECONNREFUSED = global i64 0
@SERVFAIL = global i32 0
@RES_DEFNAMES = global i32 0
@RES_DNSRCH = global i32 0
@RES_NOTLDQUERY = global i32 0
define i32 @res_nsearch(%struct.TYPE_8__* %0, i8* %1, i32 %2, i32 %3, i32* %4, i32 %5) {
%7 = load i32, i32* @NS_MAXDNAME
%8 = zext i32 %7 to i64
%9 = alloca i8, i64 %8
store i64 0, i64* @errno
%10 = tail call i32 @RES_SET_H_ERRNO(%struct.TYPE_8__* %0, i32 130)
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 0
br i1 %12, label %31, label %13
13: ; preds = %6, %13
%14 = phi i8 [ %21, %13 ], [ %11, %6 ]
%15 = phi i64 [ %19, %13 ], [ 0, %6 ]
%16 = phi i8* [ %20, %13 ], [ %1, %6 ]
%17 = icmp eq i8 %14, 46
%18 = zext i1 %17 to i64
%19 = add nuw nsw i64 %15, %18
%20 = getelementptr inbounds i8, i8* %16, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %13
23: ; preds = %13
%24 = icmp ugt i8* %20, %1
br i1 %24, label %25, label %28
25: ; preds = %23
%26 = load i8, i8* %16
%27 = icmp eq i8 %26, 46
br label %28
28: ; preds = %25, %23
%29 = phi i1 [ false, %23 ], [ %27, %25 ]
%30 = icmp eq i64 %19, 0
br i1 %30, label %31, label %37
31: ; preds = %6, %28
%32 = phi i1 [ %29, %28 ], [ false, %6 ]
%33 = call i8* @res_hostalias(%struct.TYPE_8__* %0, i8* %1, i8* %9, i32 %7)
%34 = icmp eq i8* %33, null
br i1 %34, label %37, label %35
35: ; preds = %31
%36 = call i32 @res_nquery(%struct.TYPE_8__* %0, i8* %33, i32 %2, i32 %3, i32* %4, i32 %5)
br label %184
37: ; preds = %31, %28
%38 = phi i1 [ true, %31 ], [ false, %28 ]
%39 = phi i1 [ %32, %31 ], [ %29, %28 ]
%40 = phi i64 [ 0, %31 ], [ %19, %28 ]
%41 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %0, i64 0, i32 0
%42 = load i64, i64* %41
%43 = icmp sge i64 %40, %42
%44 = or i1 %39, %43
br i1 %44, label %45, label %62
45: ; preds = %37
%46 = call i32 @res_nquerydomain(%struct.TYPE_8__* %0, i8* %1, i8* null, i32 %2, i32 %3, i32* %4, i32 %5)
%47 = icmp sgt i32 %46, 0
%48 = or i1 %39, %47
br i1 %48, label %184, label %49
49: ; preds = %45
%50 = load i64, i64* @errno
%51 = load i64, i64* @ECONNREFUSED
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @RES_SET_H_ERRNO(%struct.TYPE_8__* %0, i32 128)
br label %184
55: ; preds = %49
%56 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %0, i64 0, i32 1
%57 = load i32, i32* %56
switch i32 %57, label %184 [
i32 129, label %62
i32 130, label %62
i32 128, label %58
]
58: ; preds = %55
%59 = load i32, i32* %4
%60 = load i32, i32* @SERVFAIL
%61 = icmp eq i32 %59, %60
br i1 %61, label %62, label %184
62: ; preds = %55, %55, %58, %37
%63 = phi i32 [ -1, %37 ], [ 128, %58 ], [ %57, %55 ], [ %57, %55 ]
br i1 %38, label %64, label %70
64: ; preds = %62
%65 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %0, i64 0, i32 2
%66 = load i32, i32* %65
%67 = load i32, i32* @RES_DEFNAMES
%68 = and i32 %67, %66
%69 = icmp eq i32 %68, 0
br i1 %69, label %142, label %77
70: ; preds = %62
br i1 %39, label %142, label %71
71: ; preds = %70
%72 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %0, i64 0, i32 2
%73 = load i32, i32* %72
%74 = load i32, i32* @RES_DNSRCH
%75 = and i32 %74, %73
%76 = icmp eq i32 %75, 0
br i1 %76, label %142, label %77
77: ; preds = %71, %64
%78 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %0, i64 0, i32 3
%79 = load i64, i64* %78
%80 = inttoptr i64 %79 to i8**
%81 = load i8*, i8** %80
%82 = icmp eq i8* %81, null
br i1 %82, label %142, label %83
83: ; preds = %77
%84 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %0, i64 0, i32 1
%85 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %0, i64 0, i32 2
br label %86
86: ; preds = %83, %133
%87 = phi i8* [ %81, %83 ], [ %138, %133 ]
%88 = phi i32 [ 0, %83 ], [ %100, %133 ]
%89 = phi i32 [ 0, %83 ], [ %135, %133 ]
%90 = phi i32 [ 0, %83 ], [ %134, %133 ]
%91 = phi i8** [ %80, %83 ], [ %137, %133 ]
%92 = load i8, i8* %87
switch i8 %92, label %99 [
i8 0, label %97
i8 46, label %93
]
93: ; preds = %86
%94 = getelementptr inbounds i8, i8* %87, i64 1
%95 = load i8, i8* %94
%96 = icmp eq i8 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %86, %93
%98 = add nsw i32 %88, 1
br label %99
99: ; preds = %86, %97, %93
%100 = phi i32 [ %98, %97 ], [ %88, %93 ], [ %88, %86 ]
%101 = icmp ne i32 %100, 0
%102 = select i1 %101, i1 %44, i1 false
br i1 %102, label %133, label %103
103: ; preds = %99
%104 = call i32 @res_nquerydomain(%struct.TYPE_8__* %0, i8* %1, i8* %87, i32 %2, i32 %3, i32* %4, i32 %5)
%105 = icmp sgt i32 %104, 0
br i1 %105, label %184, label %106
106: ; preds = %103
%107 = load i64, i64* @errno
%108 = load i64, i64* @ECONNREFUSED
%109 = icmp eq i64 %107, %108
br i1 %109, label %110, label %112
110: ; preds = %106
%111 = call i32 @RES_SET_H_ERRNO(%struct.TYPE_8__* %0, i32 128)
br label %184
112: ; preds = %106
%113 = load i32, i32* %84
switch i32 %113, label %121 [
i32 129, label %114
i32 130, label %123
i32 128, label %116
]
114: ; preds = %112
%115 = add nsw i32 %90, 1
br label %123
116: ; preds = %112
%117 = add nsw i32 %89, 1
%118 = load i32, i32* %4
%119 = load i32, i32* @SERVFAIL
%120 = icmp eq i32 %118, %119
br i1 %120, label %123, label %121
121: ; preds = %116, %112
%122 = phi i32 [ %89, %112 ], [ %117, %116 ]
br label %123
123: ; preds = %116, %121, %114, %112
%124 = phi i32 [ %90, %121 ], [ %90, %116 ], [ %90, %112 ], [ %115, %114 ]
%125 = phi i32 [ %122, %121 ], [ %117, %116 ], [ %89, %112 ], [ %89, %114 ]
%126 = phi i32 [ 1, %121 ], [ 0, %116 ], [ 0, %112 ], [ 0, %114 ]
%127 = load i32, i32* %85
%128 = load i32, i32* @RES_DNSRCH
%129 = and i32 %128, %127
%130 = icmp eq i32 %129, 0
%131 = zext i1 %130 to i32
%132 = add nuw nsw i32 %126, %131
br label %133
133: ; preds = %123, %99
%134 = phi i32 [ %90, %99 ], [ %124, %123 ]
%135 = phi i32 [ %89, %99 ], [ %125, %123 ]
%136 = phi i32 [ 0, %99 ], [ %132, %123 ]
%137 = getelementptr inbounds i8*, i8** %91, i64 1
%138 = load i8*, i8** %137
%139 = icmp ne i8* %138, null
%140 = icmp eq i32 %136, 0
%141 = select i1 %139, i1 %140, i1 false
br i1 %141, label %86, label %142
142: ; preds = %133, %77, %64, %71, %70
%143 = phi i32 [ 0, %70 ], [ 0, %71 ], [ 0, %64 ], [ 0, %77 ], [ %134, %133 ]
%144 = phi i32 [ 0, %70 ], [ 0, %71 ], [ 0, %64 ], [ 0, %77 ], [ %135, %133 ]
%145 = phi i32 [ 0, %70 ], [ 0, %71 ], [ 0, %64 ], [ 0, %77 ], [ %100, %133 ]
%146 = phi i1 [ false, %70 ], [ false, %71 ], [ false, %64 ], [ false, %77 ], [ true, %133 ]
%147 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %0, i64 0, i32 1
%148 = load i32, i32* %147
switch i32 %148, label %172 [
i32 129, label %153
i32 130, label %153
i32 128, label %149
]
149: ; preds = %142
%150 = load i32, i32* %4
%151 = load i32, i32* @SERVFAIL
%152 = icmp eq i32 %150, %151
br i1 %152, label %153, label %172
153: ; preds = %149, %142, %142
%154 = and i1 %38, %146
br i1 %154, label %155, label %165
155: ; preds = %153
%156 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %0, i64 0, i32 2
%157 = load i32, i32* %156
%158 = load i32, i32* @RES_NOTLDQUERY
%159 = and i32 %158, %157
%160 = icmp ne i32 %159, 0
%161 = select i1 %160, i1 true, i1 %44
%162 = xor i1 %161, true
%163 = icmp eq i32 %145, 0
%164 = select i1 %162, i1 %163, i1 false
br i1 %164, label %169, label %172
165: ; preds = %153
%166 = xor i1 %44, true
%167 = icmp eq i32 %145, 0
%168 = select i1 %166, i1 %167, i1 false
br i1 %168, label %169, label %172
169: ; preds = %165, %155
%170 = call i32 @res_nquerydomain(%struct.TYPE_8__* %0, i8* %1, i8* null, i32 %2, i32 %3, i32* %4, i32 %5)
%171 = icmp sgt i32 %170, 0
br i1 %171, label %184, label %172
172: ; preds = %155, %165, %169, %142, %149
%173 = icmp eq i32 %63, -1
br i1 %173, label %176, label %174
174: ; preds = %172
%175 = call i32 @RES_SET_H_ERRNO(%struct.TYPE_8__* %0, i32 %63)
br label %184
176: ; preds = %172
%177 = icmp eq i32 %143, 0
br i1 %177, label %180, label %178
178: ; preds = %176
%179 = call i32 @RES_SET_H_ERRNO(%struct.TYPE_8__* %0, i32 129)
br label %184
180: ; preds = %176
%181 = icmp eq i32 %144, 0
br i1 %181, label %184, label %182
182: ; preds = %180
%183 = call i32 @RES_SET_H_ERRNO(%struct.TYPE_8__* %0, i32 128)
br label %184
184: ; preds = %103, %110, %174, %180, %182, %178, %169, %55, %58, %45, %53, %35
%185 = phi i32 [ -1, %53 ], [ %36, %35 ], [ %46, %45 ], [ -1, %58 ], [ -1, %55 ], [ %170, %169 ], [ -1, %178 ], [ -1, %182 ], [ -1, %180 ], [ -1, %174 ], [ -1, %110 ], [ %104, %103 ]
ret i32 %185
}