user: Converte this assembly snippet into its equivalent C code:

```asm
<res_search>:
  endbr64
  push   %r15
  mov    %r8d,%r9d
  mov    %rdi,%r15
  push   %r14
  mov    %esi,%r14d
  push   %r13
  mov    %edx,%r13d
  push   %r12
  mov    %rcx,%r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    D297(%rip),%rax
  mov    D277(%rip),%rdx
  mov    (%rax),%eax
  and    (%rdx),%eax
  je     L393
L126:
  mov    D282(%rip),%rax
  movq   $0x0,(%rax)
  mov    D3(%rip),%rax
  movl   $0x82,(%rax)
  movzbl (%r15),%edx
  test   %dl,%dl
  je     L158
  mov    %r15,%rax
  xor    %ebx,%ebx
  nopl   (%rax)
L481:
  cmp    $0x2e,%dl
  sete   %dl
  add    $0x1,%rax
  movzbl %dl,%edx
  add    %rdx,%rbx
  movzbl (%rax),%edx
  test   %dl,%dl
  jne    L481
  movl   $0x0,0x10(%rsp)
  cmp    %rax,%r15
  jae    L289
  cmpb   $0x2e,-0x1(%rax)
  sete   %al
  movzbl %al,%eax
  mov    %eax,0x10(%rsp)
L289:
  test   %rbx,%rbx
  je     L158
  mov    D297(%rip),%rax
  cmp    0x8(%rax),%rbx
  jge    L64
  cmpl   $0x1,0x10(%rsp)
  je     L90
  mov    D139(%rip),%rax
  mov    D297(%rip),%rdi
  mov    (%rdi),%edx
  and    (%rax),%edx
  mov    %edx,0x14(%rsp)
  je     L342
  mov    D297(%rip),%rax
  movl   $0xffffffff,0x18(%rsp)
  mov    0x10(%rax),%rbp
  mov    0x0(%rbp),%rsi
  test   %rsi,%rsi
  je     L170
L353:
  movl   $0x0,0x1c(%rsp)
  movl   $0x0,0x14(%rsp)
  mov    %rbx,0x8(%rsp)
  mov    %r9d,%ebx
  nopl   0x0(%rax,%rax,1)
L116:
  mov    %ebx,%r9d
  mov    %r12,%r8
  mov    %r13d,%ecx
  mov    %r14d,%edx
  mov    %r15,%rdi
  call   <res_querydomain@plt>
  test   %eax,%eax
  jg     L274
  mov    D68(%rip),%rax
  mov    D282(%rip),%rcx
  mov    (%rax),%rax
  cmp    %rax,(%rcx)
  je     L454
  mov    D3(%rip),%rax
  mov    (%rax),%eax
  cmp    $0x81,%eax
  je     L154
  cmp    $0x82,%eax
  je     L71
  cmp    $0x80,%eax
  je     L194
L235:
  mov    0x10(%rsp),%ecx
  mov    %ebx,%r9d
  mov    0x8(%rsp),%rbx
  test   %ecx,%ecx
  jne    L239
  test   %rbx,%rbx
  jne    L430
L264:
  mov    D93(%rip),%rax
  mov    D297(%rip),%rdi
  mov    (%rax),%eax
  and    (%rdi),%eax
  je     L430
  nopl   0x0(%rax)
L239:
  cmpl   $0xffffffff,0x18(%rsp)
  jne    L265
  mov    0x14(%rsp),%edx
  test   %edx,%edx
  jne    L83
  mov    0x1c(%rsp),%eax
  test   %eax,%eax
  je     L389
L454:
  mov    D3(%rip),%rax
  movl   $0x80,(%rax)
  add    $0x28,%rsp
  mov    $0xffffffff,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L64:
  xor    %esi,%esi
  mov    %r12,%r8
  mov    %r13d,%ecx
  mov    %r14d,%edx
  mov    %r15,%rdi
  mov    %r9d,0x8(%rsp)
  call   <res_querydomain@plt>
  mov    0x8(%rsp),%r9d
  test   %eax,%eax
  jle    L261
L274:
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L154:
  addl   $0x1,0x14(%rsp)
L71:
  mov    D297(%rip),%rax
  mov    D139(%rip),%rdx
  mov    (%rax),%eax
  and    (%rdx),%eax
  je     L235
  mov    0x8(%rbp),%rsi
  add    $0x8,%rbp
  test   %rsi,%rsi
  jne    L116
  jmp    L235
  nopl   0x0(%rax,%rax,1)
L194:
  mov    D109(%rip),%rax
  mov    (%rax),%eax
  cmp    %eax,(%r12)
  jne    L235
  addl   $0x1,0x1c(%rsp)
  jmp    L71
  nopw   0x0(%rax,%rax,1)
L393:
  mov    %r8d,0x8(%rsp)
  call   <res_init@plt>
  mov    0x8(%rsp),%r9d
  cmp    $0xffffffff,%eax
  jne    L126
  mov    D298(%rip),%rdx
  mov    (%rdx),%ecx
  mov    D3(%rip),%rdx
  mov    %ecx,(%rdx)
  jmp    L274
  nopw   0x0(%rax,%rax,1)
L158:
  mov    %r15,%rdi
  mov    %r9d,0x8(%rsp)
  call   <hostalias@plt>
  mov    0x8(%rsp),%r9d
  test   %rax,%rax
  jne    L291
  mov    D297(%rip),%rax
  cmpq   $0x0,0x8(%rax)
  jle    L293
  mov    (%rax),%eax
  mov    D131(%rip),%rdx
  mov    %eax,%edi
  and    (%rdx),%edi
  jne    L446
  mov    D93(%rip),%rdx
  movl   $0x0,0x1c(%rsp)
  movl   $0xffffffff,0x18(%rsp)
  and    (%rdx),%eax
  mov    %eax,0x14(%rsp)
  jne    L389
L430:
  xor    %esi,%esi
  mov    %r12,%r8
  mov    %r13d,%ecx
  mov    %r14d,%edx
  mov    %r15,%rdi
  call   <res_querydomain@plt>
  test   %eax,%eax
  jle    L239
  jmp    L274
L293:
  xor    %esi,%esi
  mov    %r12,%r8
  mov    %r13d,%ecx
  mov    %r14d,%edx
  mov    %r15,%rdi
  mov    %r9d,0x8(%rsp)
  call   <res_querydomain@plt>
  test   %eax,%eax
  jg     L274
  mov    D3(%rip),%rax
  mov    D131(%rip),%rdx
  mov    0x8(%rsp),%r9d
  mov    (%rax),%eax
  mov    %eax,0x18(%rsp)
  mov    D297(%rip),%rax
  mov    (%rax),%eax
  and    (%rdx),%eax
  je     L186
  mov    D297(%rip),%rax
  movl   $0x1,0x10(%rsp)
  xor    %ebx,%ebx
  mov    0x10(%rax),%rbp
  mov    0x0(%rbp),%rsi
  test   %rsi,%rsi
  jne    L353
L186:
  cmpl   $0xffffffff,0x18(%rsp)
  jne    L265
L389:
  add    $0x28,%rsp
  mov    $0xffffffff,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  cs nopw 0x0(%rax,%rax,1)
L446:
  mov    D297(%rip),%rax
  movl   $0x0,0x10(%rsp)
  xor    %ebx,%ebx
  movl   $0xffffffff,0x18(%rsp)
  mov    0x10(%rax),%rbp
  mov    0x0(%rbp),%rsi
  test   %rsi,%rsi
  jne    L353
  movl   $0x0,0x1c(%rsp)
  movl   $0x0,0x14(%rsp)
  jmp    L264
  nop
L291:
  add    $0x28,%rsp
  mov    %r12,%rcx
  mov    %r13d,%edx
  mov    %r14d,%esi
  pop    %rbx
  mov    %r9d,%r8d
  pop    %rbp
  mov    %rax,%rdi
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    10a0 <res_query@plt>
  nopw   0x0(%rax,%rax,1)
L90:
  movl   $0xffffffff,0x18(%rsp)
  movl   $0x0,0x1c(%rsp)
  movl   $0x0,0x14(%rsp)
  jmp    L430
L342:
  movl   $0x0,0x1c(%rsp)
  movl   $0xffffffff,0x18(%rsp)
  jmp    L430
L170:
  mov    0x10(%rsp),%eax
  mov    %eax,0x1c(%rsp)
  mov    %eax,0x14(%rsp)
  jmp    L430
L265:
  mov    D3(%rip),%rax
  mov    0x18(%rsp),%edi
  mov    %edi,(%rax)
  mov    $0xffffffff,%eax
  jmp    L274
L83:
  mov    D3(%rip),%rax
  movl   $0x81,(%rax)
  mov    $0xffffffff,%eax
  jmp    L274
L261:
  mov    D3(%rip),%rax
  cmpl   $0x1,0x10(%rsp)
  mov    (%rax),%eax
  mov    %eax,0x18(%rsp)
  je     L186
  mov    D297(%rip),%rax
  mov    D139(%rip),%rdx
  mov    (%rax),%eax
  and    (%rdx),%eax
  je     L186
  mov    D297(%rip),%rax
  mov    0x10(%rax),%rbp
  mov    0x0(%rbp),%rsi
  test   %rsi,%rsi
  je     L186
  movl   $0x1,0x10(%rsp)
  jmp    L353
```

assistant: ```c
int res_search(const char *name, int class, int type, u_char *answer, int anslen) {
  const char *cp, *const *domain;
  HEADER *hp = (HEADER *)answer;
  u_int dots;
  int trailing_dot, ret, saved_herrno;
  int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
  if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
    h_errno = NETDB_INTERNAL;
    return (-1);
  }
  errno = 0;
  h_errno = HOST_NOT_FOUND;
  dots = 0;
  for (cp = name; *cp; cp++)
    dots += (*cp == '.');
  trailing_dot = 0;
  if (cp > name && *--cp == '.')
    trailing_dot++;
  if (!dots && (cp = hostalias(name)) != NULL)
    return (res_query(cp, class, type, answer, anslen));
  saved_herrno = -1;
  if (dots >= _res.ndots) {
    ret = res_querydomain(name, NULL, class, type, answer, anslen);
    if (ret > 0)
      return (ret);
    saved_herrno = h_errno;
    tried_as_is++;
  }
  if ((!dots && (_res.options & RES_DEFNAMES)) || (dots && !trailing_dot && (_res.options & RES_DNSRCH))) {
    int done = 0;
    for (domain = (const char *const *)_res.dnsrch; *domain && !done; domain++) {
      ret = res_querydomain(name, *domain, class, type, answer, anslen);
      if (ret > 0)
        return (ret);
      if (errno == ECONNREFUSED) {
        h_errno = TRY_AGAIN;
        return (-1);
      }
      switch (h_errno) {
      case NO_DATA:
        got_nodata++;
      case HOST_NOT_FOUND:
        break;
      case TRY_AGAIN:
        if (hp->rcode == SERVFAIL) {
          got_servfail++;
          break;
        }
      default:
        done++;
      }
      if (!(_res.options & RES_DNSRCH))
        done++;
    }
  }
  if (!tried_as_is && (dots || !(_res.options & RES_NOTLDQUERY))) {
    ret = res_querydomain(name, NULL, class, type, answer, anslen);
    if (ret > 0)
      return (ret);
  }
  if (saved_herrno != -1)
    h_errno = saved_herrno;
  else if (got_nodata)
    h_errno = NO_DATA;
  else if (got_servfail)
    h_errno = TRY_AGAIN;
  return (-1);
}
```