user: Please show me the C implementation that matches the assembly code listed below:

```asm
<res_nmkquery>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0xd8,%rsp
  mov    %rdx,(%rsp)
  mov    %r8d,0x8(%rsp)
  mov    0x120(%rsp),%rbx
  mov    %fs:0x28,%rax
  mov    %rax,0xc8(%rsp)
  xor    %eax,%eax
  test   %rbx,%rbx
  je     L86
  mov    %rdi,%r13
  mov    %esi,%r12d
  mov    %ecx,%r14d
  mov    %r9,%r15
  mov    D82(%rip),%rax
  mov    (%rax),%edx
  cmp    0x128(%rsp),%edx
  jg     L237
  mov    $0x0,%esi
  mov    %rbx,%rdi
  call   <memset@plt>
  lea    0x18(%rsp),%rbp
L78:
  mov    $0x0,%esi
  mov    %rbp,%rdi
  call   <__gettimeofday@plt>
  mov    0x18(%rsp),%eax
  shl    $0x8,%eax
  xor    0x1c(%rsp),%eax
  test   %ax,%ax
  je     L78
  add    0x0(%r13),%eax
  movzwl %ax,%eax
  mov    %eax,0x0(%r13)
  mov    %eax,(%rbx)
  mov    %r12d,0x4(%rbx)
  mov    0x4(%r13),%eax
  mov    D85(%rip),%rdx
  and    (%rdx),%eax
  setne  %al
  movzbl %al,%eax
  mov    %eax,0x8(%rbx)
  mov    D35(%rip),%rax
  mov    (%rax),%eax
  mov    %eax,0x28(%rbx)
  mov    D82(%rip),%rax
  mov    (%rax),%eax
  movslq %eax,%rdx
  lea    (%rbx,%rdx,4),%rbp
  mov    0x128(%rsp),%edx
  sub    %eax,%edx
  mov    %rbx,0x20(%rsp)
  movq   $0x0,0x28(%rsp)
  cmp    $0x81,%r12d
  je     L243
  cmp    $0x82,%r12d
  je     L10
  mov    $0xffffffff,%eax
  cmp    $0x80,%r12d
  jne    L196
  mov    D89(%rip),%rax
  sub    (%rax),%edx
  js     L5
  lea    0x20(%rsp),%rcx
  lea    0xc0(%rsp),%r8
  mov    %rbp,%rsi
  mov    (%rsp),%rdi
  call   <ns_name_compress@plt>
  test   %eax,%eax
  js     L145
  cltq
  lea    0x0(%rbp,%rax,4),%r12
  mov    %r12,%rsi
  mov    0x8(%rsp),%edi
  call   <NS_PUT16@plt>
  mov    %r12,%rsi
  mov    %r14d,%edi
  call   <NS_PUT16@plt>
  mov    $0x1,%edi
  call   <htons@plt>
  mov    %rax,0x20(%rbx)
  jmp    L148
L243:
  mov    $0x0,%eax
  test   %r15,%r15
  je     L213
  mov    D31(%rip),%rax
  mov    (%rax),%eax
L213:
  mov    D89(%rip),%rcx
  add    (%rcx),%eax
  sub    %eax,%edx
  mov    %edx,0xc(%rsp)
  js     L75
  lea    0x20(%rsp),%rcx
  lea    0xc0(%rsp),%r8
  mov    0xc(%rsp),%edx
  mov    %rbp,%rsi
  mov    (%rsp),%rdi
  call   <ns_name_compress@plt>
  mov    %eax,%r13d
  test   %eax,%eax
  js     L118
  cltq
  lea    0x0(%rbp,%rax,4),%r12
  mov    %r12,%rsi
  mov    0x8(%rsp),%edi
  call   <NS_PUT16@plt>
  mov    %r12,%rsi
  mov    %r14d,%edi
  call   <NS_PUT16@plt>
  mov    $0x1,%edi
  call   <htons@plt>
  mov    %rax,0x20(%rbx)
  test   %r15,%r15
  je     L148
  mov    0xc(%rsp),%edx
  sub    %r13d,%edx
  lea    0x20(%rsp),%rcx
  lea    0xc0(%rsp),%r8
  mov    %r12,%rsi
  mov    %r15,%rdi
  call   <ns_name_compress@plt>
  mov    %eax,%ebp
  mov    %eax,%edi
  shr    $0x1f,%edi
  mov    $0x0,%esi
  call   <__builtin_expect@plt>
  test   %eax,%eax
  jne    L195
  movslq %ebp,%rbp
  lea    (%r12,%rbp,4),%r12
  mov    %r12,%rsi
  mov    D47(%rip),%rax
  mov    (%rax),%edi
  call   <NS_PUT16@plt>
  mov    %r12,%rsi
  mov    %r14d,%edi
  call   <NS_PUT16@plt>
  mov    %r12,%rsi
  mov    $0x0,%edi
  call   <NS_PUT32@plt>
  mov    %r12,%rsi
  mov    $0x0,%edi
  call   <NS_PUT16@plt>
  mov    $0x1,%edi
  call   <htons@plt>
  mov    %rax,0x18(%rbx)
  jmp    L148
L10:
  mov    D31(%rip),%rax
  mov    (%rax),%eax
  mov    0x110(%rsp),%ecx
  lea    0x1(%rcx,%rax,1),%eax
  cmp    %edx,%eax
  setg   %dil
  movzbl %dil,%edi
  mov    $0x0,%esi
  call   <__builtin_expect@plt>
  test   %eax,%eax
  jne    L188
  lea    0x4(%rbp),%r12
  movl   $0x0,0x0(%rbp)
  mov    %r12,%rsi
  mov    0x8(%rsp),%edi
  call   <NS_PUT16@plt>
  mov    %r12,%rsi
  mov    %r14d,%edi
  call   <NS_PUT16@plt>
  mov    %r12,%rsi
  mov    $0x0,%edi
  call   <NS_PUT32@plt>
  mov    %r12,%rsi
  mov    0x110(%rsp),%edi
  call   <NS_PUT16@plt>
  cmpl   $0x0,0x110(%rsp)
  jne    L81
L13:
  mov    $0x1,%edi
  call   <htons@plt>
  mov    %rax,0x10(%rbx)
L148:
  mov    %r12,%rax
  sub    %rbx,%rax
  sar    $0x2,%rax
L196:
  mov    0xc8(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L113
  add    $0xd8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L81:
  mov    0x110(%rsp),%edx
  mov    %r15,%rsi
  mov    %r12,%rdi
  call   <memcpy@plt>
  movslq 0x110(%rsp),%rax
  lea    (%r12,%rax,4),%r12
  jmp    L13
L86:
  mov    $0xffffffff,%eax
  jmp    L196
L237:
  mov    $0xffffffff,%eax
  jmp    L196
L75:
  mov    $0xffffffff,%eax
  jmp    L196
L5:
  mov    $0xffffffff,%eax
  jmp    L196
L118:
  mov    $0xffffffff,%eax
  jmp    L196
L195:
  mov    $0xffffffff,%eax
  jmp    L196
L188:
  mov    $0xffffffff,%eax
  jmp    L196
L145:
  mov    $0xffffffff,%eax
  jmp    L196
L113:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int res_nmkquery(res_state statp, int op, const char *dname, int class, int type, const u_char *data, int datalen, const u_char *newrr_in, u_char *buf, int buflen) {
  HEADER *hp;
  u_char *cp;
  int n;
  u_char *dnptrs[20], **dpp, **lastdnptr;
  if ((buf == NULL) || (buflen < HFIXEDSZ))
    return (-1);
  memset(buf, 0, HFIXEDSZ);
  hp = (HEADER *)buf;
  int randombits;
  do {
    struct timeval tv;
    __gettimeofday(&tv, NULL);
    randombits = (tv.tv_sec << 8) ^ tv.tv_usec;
  } while ((randombits & 0xffff) == 0);
  statp->id = (statp->id + randombits) & 0xffff;
  hp->id = statp->id;
  hp->opcode = op;
  hp->rd = (statp->options & RES_RECURSE) != 0;
  hp->rcode = NOERROR;
  cp = buf + HFIXEDSZ;
  buflen -= HFIXEDSZ;
  dpp = dnptrs;
  *dpp++ = buf;
  *dpp++ = NULL;
  lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
  switch (op) {
  case NS_NOTIFY_OP:
    if ((buflen -= QFIXEDSZ + (data == NULL ? 0 : RRFIXEDSZ)) < 0)
      return (-1);
    goto compose;
  case QUERY:
    if ((buflen -= QFIXEDSZ) < 0)
      return (-1);
  compose:
    n = ns_name_compress(dname, cp, buflen, (const u_char **)dnptrs, (const u_char **)lastdnptr);
    if (n < 0)
      return (-1);
    cp += n;
    buflen -= n;
    NS_PUT16(type, cp);
    NS_PUT16(class, cp);
    hp->qdcount = htons(1);
    if (op == QUERY || data == NULL)
      break;
    n = ns_name_compress((char *)data, cp, buflen, (const u_char **)dnptrs, (const u_char **)lastdnptr);
    if (__builtin_expect(n < 0, 0))
      return (-1);
    cp += n;
    buflen -= n;
    NS_PUT16(T_NULL, cp);
    NS_PUT16(class, cp);
    NS_PUT32(0, cp);
    NS_PUT16(0, cp);
    hp->arcount = htons(1);
    break;
  case IQUERY:
    if (__builtin_expect(buflen < 1 + RRFIXEDSZ + datalen, 0))
      return (-1);
    *cp++ = '\0';
    NS_PUT16(type, cp);
    NS_PUT16(class, cp);
    NS_PUT32(0, cp);
    NS_PUT16(datalen, cp);
    if (datalen) {
      memcpy(cp, data, datalen);
      cp += datalen;
    }
    hp->ancount = htons(1);
    break;
  default:
    return (-1);
  }
  return (cp - buf);
}
```