#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_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ u_char;
struct timeval {
  int tv_sec;
  int tv_usec;
};
typedef TYPE_1__ *res_state;
struct TYPE_5__ {
  int id;
  int opcode;
  int rd;
  void *ancount;
  void *arcount;
  void *qdcount;
  int /*<<< orphan*/ rcode;
};
struct TYPE_4__ {
  int id;
  int options;
};
typedef TYPE_2__ HEADER;

/* Variables and functions */
int HFIXEDSZ;
#define IQUERY 130
int /*<<< orphan*/ NOERROR;
#define NS_NOTIFY_OP 129
int /*<<< orphan*/ NS_PUT16(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ NS_PUT32(int /*<<< orphan*/, int /*<<< orphan*/ *);
int QFIXEDSZ;
#define QUERY 128
int RES_RECURSE;
int RRFIXEDSZ;
int T_NULL;
int /*<<< orphan*/ __gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ __glibc_unlikely(int);
void *htons(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int ns_name_compress(char const *, int /*<<< orphan*/ *, int,
                     int /*<<< orphan*/ const **, int /*<<< orphan*/ const **);
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 (__glibc_unlikely(n < 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 (__glibc_unlikely(buflen < 1 + RRFIXEDSZ + datalen))
      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);
}


x86 assembly (clang, -O0):
<res_nmkquery>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpq   $0x0,0x20(%rbp)
je     11cc <res_nmkquery+0x4c>
mov    0x28(%rbp),%eax
mov    0x2e04(%rip),%rcx
cmp    (%rcx),%eax
jge    11d8 <res_nmkquery+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    1605 <res_nmkquery+0x485>
mov    0x20(%rbp),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x110(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <__gettimeofday@plt>
mov    -0x110(%rbp),%eax
shl    $0x8,%eax
xor    -0x10c(%rbp),%eax
mov    %eax,-0x104(%rbp)
mov    -0x104(%rbp),%eax
and    $0xffff,%eax
cmp    $0x0,%eax
je     11f4 <res_nmkquery+0x74>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x104(%rbp),%edx
add    %edx,%ecx
movzwl %cx,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2d7c(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
test   %eax,%eax
setne  %al
movzbl %al,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x2d5a(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,0x28(%rax)
mov    0x20(%rbp),%rcx
mov    0x2d36(%rip),%rax
movslq (%rax),%rdx
lea    (%rcx,%rdx,4),%rcx
mov    %rcx,-0x40(%rbp)
mov    (%rax),%ecx
mov    0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,0x28(%rbp)
lea    -0xf0(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    0x20(%rbp),%rcx
mov    -0xf8(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0xf8(%rbp)
mov    %rcx,(%rax)
mov    -0xf8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0xf8(%rbp)
movq   $0x0,(%rax)
lea    -0x50(%rbp),%rax
mov    %rax,-0x100(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x114(%rbp)
sub    $0x80,%eax
je     13a3 <res_nmkquery+0x223>
jmp    1311 <res_nmkquery+0x191>
mov    -0x114(%rbp),%eax
sub    $0x81,%eax
je     133d <res_nmkquery+0x1bd>
jmp    1327 <res_nmkquery+0x1a7>
mov    -0x114(%rbp),%eax
sub    $0x82,%eax
je     1524 <res_nmkquery+0x3a4>
jmp    15e7 <res_nmkquery+0x467>
mov    0x2c74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x118(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1364 <res_nmkquery+0x1e4>
xor    %eax,%eax
mov    %eax,-0x11c(%rbp)
jmp    1373 <res_nmkquery+0x1f3>
mov    0x2c65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x11c(%rbp)
mov    -0x118(%rbp),%ecx
mov    -0x11c(%rbp),%eax
add    %eax,%ecx
mov    0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,0x28(%rbp)
cmp    $0x0,%eax
jge    139e <res_nmkquery+0x21e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1605 <res_nmkquery+0x485>
jmp    13ce <res_nmkquery+0x24e>
mov    0x2c0e(%rip),%rax
mov    (%rax),%ecx
mov    0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,0x28(%rbp)
cmp    $0x0,%eax
jge    13c9 <res_nmkquery+0x249>
movl   $0xffffffff,-0x4(%rbp)
jmp    1605 <res_nmkquery+0x485>
jmp    13ce <res_nmkquery+0x24e>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    0x28(%rbp),%edx
lea    -0xf0(%rbp),%rcx
mov    -0x100(%rbp),%r8
call   10a0 <ns_name_compress@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1405 <res_nmkquery+0x285>
movl   $0xffffffff,-0x4(%rbp)
jmp    1605 <res_nmkquery+0x485>
mov    -0x44(%rbp),%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x44(%rbp),%ecx
mov    0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,0x28(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   1040 <NS_PUT16@plt>
mov    -0x24(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   1040 <NS_PUT16@plt>
mov    $0x1,%edi
call   1050 <htons@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x20(%rax)
cmpl   $0x80,-0x14(%rbp)
je     146a <res_nmkquery+0x2ea>
cmpq   $0x0,-0x30(%rbp)
jne    146f <res_nmkquery+0x2ef>
jmp    15f3 <res_nmkquery+0x473>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    0x28(%rbp),%edx
lea    -0xf0(%rbp),%rcx
mov    -0x100(%rbp),%r8
call   10a0 <ns_name_compress@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <__glibc_unlikely@plt>
cmp    $0x0,%eax
je     14b6 <res_nmkquery+0x336>
movl   $0xffffffff,-0x4(%rbp)
jmp    1605 <res_nmkquery+0x485>
mov    -0x44(%rbp),%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x44(%rbp),%ecx
mov    0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,0x28(%rbp)
mov    0x2b1b(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rsi
call   1040 <NS_PUT16@plt>
mov    -0x24(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   1040 <NS_PUT16@plt>
mov    -0x40(%rbp),%rsi
xor    %edi,%edi
call   1030 <NS_PUT32@plt>
mov    -0x40(%rbp),%rsi
xor    %edi,%edi
call   1040 <NS_PUT16@plt>
mov    $0x1,%edi
call   1050 <htons@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x18(%rax)
jmp    15f3 <res_nmkquery+0x473>
mov    0x28(%rbp),%eax
mov    0x2aa2(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
add    0x10(%rbp),%ecx
cmp    %ecx,%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <__glibc_unlikely@plt>
cmp    $0x0,%eax
je     155a <res_nmkquery+0x3da>
movl   $0xffffffff,-0x4(%rbp)
jmp    1605 <res_nmkquery+0x485>
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x40(%rbp)
movl   $0x0,(%rax)
mov    -0x28(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   1040 <NS_PUT16@plt>
mov    -0x24(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   1040 <NS_PUT16@plt>
mov    -0x40(%rbp),%rsi
xor    %edi,%edi
call   1030 <NS_PUT32@plt>
mov    0x10(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   1040 <NS_PUT16@plt>
cmpl   $0x0,0x10(%rbp)
je     15cd <res_nmkquery+0x44d>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x10(%rbp),%edx
call   1080 <memcpy@plt>
mov    0x10(%rbp),%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    $0x1,%edi
call   1050 <htons@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x10(%rax)
jmp    15f3 <res_nmkquery+0x473>
movl   $0xffffffff,-0x4(%rbp)
jmp    1605 <res_nmkquery+0x485>
mov    -0x40(%rbp),%rax
mov    0x20(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<res_nmkquery>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %rdi,%r15
mov    0x110(%rsp),%rdi
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1444 <res_nmkquery+0x2c4>
mov    %rdx,%rax
mov    0x118(%rsp),%ebx
mov    0x2e0d(%rip),%r14
mov    (%r14),%edx
cmp    %ebx,%edx
jg     1444 <res_nmkquery+0x2c4>
mov    %esi,%r12d
mov    %rax,0x8(%rsp)
mov    %r8d,0x14(%rsp)
mov    %r9,0x18(%rsp)
mov    %ecx,0x4(%rsp)
xor    %esi,%esi
call   1070 <memset@plt>
lea    0x20(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <__gettimeofday@plt>
mov    0x20(%rsp),%eax
shl    $0x8,%eax
xor    0x24(%rsp),%eax
test   %ax,%ax
je     11f0 <res_nmkquery+0x70>
add    (%r15),%eax
movzwl %ax,%eax
mov    %eax,(%r15)
mov    0x110(%rsp),%r13
mov    %eax,0x0(%r13)
mov    %r12d,0x4(%r13)
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
xor    %ecx,%ecx
and    0x4(%r15),%eax
setne  %cl
mov    %ecx,0x8(%r13)
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%r13)
movslq (%r14),%rax
lea    0x0(,%rax,4),%r14
add    %r13,%r14
sub    %eax,%ebx
mov    %r13,0x20(%rsp)
movq   $0x0,0x28(%rsp)
cmp    $0x80,%r12d
je     12ac <res_nmkquery+0x12c>
cmp    $0x82,%r12d
je     13a3 <res_nmkquery+0x223>
cmp    $0x81,%r12d
jne    1444 <res_nmkquery+0x2c4>
mov    0x2d2a(%rip),%rax
xor    %ecx,%ecx
cmpq   $0x0,0x18(%rsp)
je     12a1 <res_nmkquery+0x121>
mov    0x2d31(%rip),%rcx
mov    (%rcx),%ecx
add    (%rax),%ecx
sub    %ecx,%ebx
jns    12bb <res_nmkquery+0x13b>
jmp    1444 <res_nmkquery+0x2c4>
mov    0x2d05(%rip),%rax
sub    (%rax),%ebx
js     1444 <res_nmkquery+0x2c4>
lea    0xc0(%rsp),%r8
lea    0x20(%rsp),%rcx
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   10a0 <ns_name_compress@plt>
test   %eax,%eax
js     1444 <res_nmkquery+0x2c4>
mov    %eax,%r15d
mov    %eax,%eax
lea    (%r14,%rax,4),%r14
mov    0x14(%rsp),%edi
mov    %r14,%rsi
call   1040 <NS_PUT16@plt>
mov    0x4(%rsp),%edi
mov    %r14,0x8(%rsp)
mov    %r14,%rsi
call   1040 <NS_PUT16@plt>
mov    $0x1,%edi
call   1050 <htons@plt>
mov    %rax,0x20(%r13)
cmp    $0x80,%r12d
je     1435 <res_nmkquery+0x2b5>
mov    0x18(%rsp),%rdi
test   %rdi,%rdi
je     1435 <res_nmkquery+0x2b5>
sub    %r15d,%ebx
lea    0x20(%rsp),%rcx
mov    0x8(%rsp),%r14
mov    %r14,%rsi
mov    %ebx,%edx
lea    0xc0(%rsp),%r8
call   10a0 <ns_name_compress@plt>
mov    %eax,%ebx
mov    %eax,%edi
shr    $0x1f,%edi
call   1090 <__glibc_unlikely@plt>
test   %eax,%eax
jne    1444 <res_nmkquery+0x2c4>
movslq %ebx,%rax
lea    (%r14,%rax,4),%r14
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
call   1040 <NS_PUT16@plt>
mov    0x4(%rsp),%edi
mov    %r14,%rsi
call   1040 <NS_PUT16@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1030 <NS_PUT32@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <NS_PUT16@plt>
mov    $0x6,%ebx
jmp    1424 <res_nmkquery+0x2a4>
mov    0x2c26(%rip),%rax
mov    (%rax),%eax
mov    0x100(%rsp),%r15d
add    %r15d,%eax
add    $0x1,%eax
xor    %edi,%edi
cmp    %eax,%ebx
setl   %dil
call   1090 <__glibc_unlikely@plt>
test   %eax,%eax
jne    1444 <res_nmkquery+0x2c4>
movl   $0x0,(%r14)
add    $0x4,%r14
mov    0x14(%rsp),%edi
mov    %r14,%rsi
call   1040 <NS_PUT16@plt>
mov    0x4(%rsp),%edi
mov    %r14,%rsi
call   1040 <NS_PUT16@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1030 <NS_PUT32@plt>
mov    %r15d,%edi
mov    %r14,%rsi
call   1040 <NS_PUT16@plt>
mov    $0x4,%ebx
test   %r15d,%r15d
je     1424 <res_nmkquery+0x2a4>
mov    %r14,%rdi
mov    0x18(%rsp),%rsi
mov    %r15d,%edx
call   1080 <memcpy@plt>
movslq %r15d,%rax
lea    (%r14,%rax,4),%r14
mov    $0x1,%edi
call   1050 <htons@plt>
mov    %rax,0x0(%r13,%rbx,4)
jmp    143a <res_nmkquery+0x2ba>
mov    0x8(%rsp),%r14
sub    %r13,%r14
shr    $0x2,%r14
mov    %r14d,%ebp
mov    %ebp,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_5__ = type { i32, i32, i32, i8*, i8*, i8*, i32 }
%struct.timeval = type { i32, i32 }
@HFIXEDSZ = global i32 0
@RES_RECURSE = global i32 0
@NOERROR = global i32 0
@QFIXEDSZ = global i32 0
@RRFIXEDSZ = global i32 0
@T_NULL = global i32 0
define i32 @res_nmkquery(%struct.TYPE_4__* %0, i32 %1, i8* %2, i32 %3, i32 %4, i32* %5, i32 %6, i32* %7, i32* %8, i32 %9) {
%11 = alloca i32
%12 = alloca %struct.TYPE_4__*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i32
%19 = alloca i32*
%20 = alloca i32*
%21 = alloca i32
%22 = alloca %struct.TYPE_5__*
%23 = alloca i32*
%24 = alloca i32
%25 = alloca [20 x i32*]
%26 = alloca i32**
%27 = alloca i32**
%28 = alloca i32
%29 = alloca %struct.timeval
store %struct.TYPE_4__* %0, %struct.TYPE_4__** %12
store i32 %1, i32* %13
store i8* %2, i8** %14
store i32 %3, i32* %15
store i32 %4, i32* %16
store i32* %5, i32** %17
store i32 %6, i32* %18
store i32* %7, i32** %19
store i32* %8, i32** %20
store i32 %9, i32* %21
%30 = load i32*, i32** %20
%31 = icmp eq i32* %30, null
br i1 %31, label %36, label %32
32: ; preds = %10
%33 = load i32, i32* %21
%34 = load i32, i32* @HFIXEDSZ
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %32, %10
store i32 -1, i32* %11
br label %239
37: ; preds = %32
%38 = load i32*, i32** %20
%39 = load i32, i32* @HFIXEDSZ
%40 = call i32 @memset(i32* %38, i32 0, i32 %39)
%41 = load i32*, i32** %20
%42 = bitcast i32* %41 to %struct.TYPE_5__*
store %struct.TYPE_5__* %42, %struct.TYPE_5__** %22
br label %43
43: ; preds = %51, %37
%44 = call i32 @__gettimeofday(%struct.timeval* %29, i32* null)
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %29, i32 0, i32 0
%46 = load i32, i32* %45
%47 = shl i32 %46, 8
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %29, i32 0, i32 1
%49 = load i32, i32* %48
%50 = xor i32 %47, %49
store i32 %50, i32* %28
br label %51
51: ; preds = %43
%52 = load i32, i32* %28
%53 = and i32 %52, 65535
%54 = icmp eq i32 %53, 0
br i1 %54, label %43, label %55
55: ; preds = %51
%56 = load %struct.TYPE_4__*, %struct.TYPE_4__** %12
%57 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %56, i32 0, i32 0
%58 = load i32, i32* %57
%59 = load i32, i32* %28
%60 = add nsw i32 %58, %59
%61 = and i32 %60, 65535
%62 = load %struct.TYPE_4__*, %struct.TYPE_4__** %12
%63 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %62, i32 0, i32 0
store i32 %61, i32* %63
%64 = load %struct.TYPE_4__*, %struct.TYPE_4__** %12
%65 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %64, i32 0, i32 0
%66 = load i32, i32* %65
%67 = load %struct.TYPE_5__*, %struct.TYPE_5__** %22
%68 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %67, i32 0, i32 0
store i32 %66, i32* %68
%69 = load i32, i32* %13
%70 = load %struct.TYPE_5__*, %struct.TYPE_5__** %22
%71 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %70, i32 0, i32 1
store i32 %69, i32* %71
%72 = load %struct.TYPE_4__*, %struct.TYPE_4__** %12
%73 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %72, i32 0, i32 1
%74 = load i32, i32* %73
%75 = load i32, i32* @RES_RECURSE
%76 = and i32 %74, %75
%77 = icmp ne i32 %76, 0
%78 = zext i1 %77 to i32
%79 = load %struct.TYPE_5__*, %struct.TYPE_5__** %22
%80 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %79, i32 0, i32 2
store i32 %78, i32* %80
%81 = load i32, i32* @NOERROR
%82 = load %struct.TYPE_5__*, %struct.TYPE_5__** %22
%83 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %82, i32 0, i32 6
store i32 %81, i32* %83
%84 = load i32*, i32** %20
%85 = load i32, i32* @HFIXEDSZ
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i32, i32* %84, i64 %86
store i32* %87, i32** %23
%88 = load i32, i32* @HFIXEDSZ
%89 = load i32, i32* %21
%90 = sub nsw i32 %89, %88
store i32 %90, i32* %21
%91 = getelementptr inbounds [20 x i32*], [20 x i32*]* %25, i64 0, i64 0
store i32** %91, i32*** %26
%92 = load i32*, i32** %20
%93 = load i32**, i32*** %26
%94 = getelementptr inbounds i32*, i32** %93, i32 1
store i32** %94, i32*** %26
store i32* %92, i32** %93
%95 = load i32**, i32*** %26
%96 = getelementptr inbounds i32*, i32** %95, i32 1
store i32** %96, i32*** %26
store i32* null, i32** %95
%97 = getelementptr inbounds [20 x i32*], [20 x i32*]* %25, i64 0, i64 0
%98 = getelementptr inbounds i32*, i32** %97, i64 20
store i32** %98, i32*** %27
%99 = load i32, i32* %13
switch i32 %99, label %230 [
i32 129, label %100
i32 128, label %115
i32 130, label %190
]
100: ; preds = %55
%101 = load i32, i32* @QFIXEDSZ
%102 = load i32*, i32** %17
%103 = icmp eq i32* %102, null
br i1 %103, label %104, label %105
104: ; preds = %100
br label %107
105: ; preds = %100
%106 = load i32, i32* @RRFIXEDSZ
br label %107
107: ; preds = %105, %104
%108 = phi i32 [ 0, %104 ], [ %106, %105 ]
%109 = add nsw i32 %101, %108
%110 = load i32, i32* %21
%111 = sub nsw i32 %110, %109
store i32 %111, i32* %21
%112 = icmp slt i32 %111, 0
br i1 %112, label %113, label %114
113: ; preds = %107
store i32 -1, i32* %11
br label %239
114: ; preds = %107
br label %122
115: ; preds = %55
%116 = load i32, i32* @QFIXEDSZ
%117 = load i32, i32* %21
%118 = sub nsw i32 %117, %116
store i32 %118, i32* %21
%119 = icmp slt i32 %118, 0
br i1 %119, label %120, label %121
120: ; preds = %115
store i32 -1, i32* %11
br label %239
121: ; preds = %115
br label %122
122: ; preds = %121, %114
%123 = load i8*, i8** %14
%124 = load i32*, i32** %23
%125 = load i32, i32* %21
%126 = getelementptr inbounds [20 x i32*], [20 x i32*]* %25, i64 0, i64 0
%127 = load i32**, i32*** %27
%128 = call i32 @ns_name_compress(i8* %123, i32* %124, i32 %125, i32** %126, i32** %127)
store i32 %128, i32* %24
%129 = load i32, i32* %24
%130 = icmp slt i32 %129, 0
br i1 %130, label %131, label %132
131: ; preds = %122
store i32 -1, i32* %11
br label %239
132: ; preds = %122
%133 = load i32, i32* %24
%134 = load i32*, i32** %23
%135 = sext i32 %133 to i64
%136 = getelementptr inbounds i32, i32* %134, i64 %135
store i32* %136, i32** %23
%137 = load i32, i32* %24
%138 = load i32, i32* %21
%139 = sub nsw i32 %138, %137
store i32 %139, i32* %21
%140 = load i32, i32* %16
%141 = load i32*, i32** %23
%142 = call i32 @NS_PUT16(i32 %140, i32* %141)
%143 = load i32, i32* %15
%144 = load i32*, i32** %23
%145 = call i32 @NS_PUT16(i32 %143, i32* %144)
%146 = call i8* @htons(i32 1)
%147 = load %struct.TYPE_5__*, %struct.TYPE_5__** %22
%148 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %147, i32 0, i32 5
store i8* %146, i8** %148
%149 = load i32, i32* %13
%150 = icmp eq i32 %149, 128
br i1 %150, label %154, label %151
151: ; preds = %132
%152 = load i32*, i32** %17
%153 = icmp eq i32* %152, null
br i1 %153, label %154, label %155
154: ; preds = %151, %132
br label %231
155: ; preds = %151
%156 = load i32*, i32** %17
%157 = bitcast i32* %156 to i8*
%158 = load i32*, i32** %23
%159 = load i32, i32* %21
%160 = getelementptr inbounds [20 x i32*], [20 x i32*]* %25, i64 0, i64 0
%161 = load i32**, i32*** %27
%162 = call i32 @ns_name_compress(i8* %157, i32* %158, i32 %159, i32** %160, i32** %161)
store i32 %162, i32* %24
%163 = load i32, i32* %24
%164 = icmp slt i32 %163, 0
%165 = zext i1 %164 to i32
%166 = call i32 @__glibc_unlikely(i32 %165)
%167 = icmp ne i32 %166, 0
br i1 %167, label %168, label %169
168: ; preds = %155
store i32 -1, i32* %11
br label %239
169: ; preds = %155
%170 = load i32, i32* %24
%171 = load i32*, i32** %23
%172 = sext i32 %170 to i64
%173 = getelementptr inbounds i32, i32* %171, i64 %172
store i32* %173, i32** %23
%174 = load i32, i32* %24
%175 = load i32, i32* %21
%176 = sub nsw i32 %175, %174
store i32 %176, i32* %21
%177 = load i32, i32* @T_NULL
%178 = load i32*, i32** %23
%179 = call i32 @NS_PUT16(i32 %177, i32* %178)
%180 = load i32, i32* %15
%181 = load i32*, i32** %23
%182 = call i32 @NS_PUT16(i32 %180, i32* %181)
%183 = load i32*, i32** %23
%184 = call i32 @NS_PUT32(i32 0, i32* %183)
%185 = load i32*, i32** %23
%186 = call i32 @NS_PUT16(i32 0, i32* %185)
%187 = call i8* @htons(i32 1)
%188 = load %struct.TYPE_5__*, %struct.TYPE_5__** %22
%189 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %188, i32 0, i32 4
store i8* %187, i8** %189
br label %231
190: ; preds = %55
%191 = load i32, i32* %21
%192 = load i32, i32* @RRFIXEDSZ
%193 = add nsw i32 1, %192
%194 = load i32, i32* %18
%195 = add nsw i32 %193, %194
%196 = icmp slt i32 %191, %195
%197 = zext i1 %196 to i32
%198 = call i32 @__glibc_unlikely(i32 %197)
%199 = icmp ne i32 %198, 0
br i1 %199, label %200, label %201
200: ; preds = %190
store i32 -1, i32* %11
br label %239
201: ; preds = %190
%202 = load i32*, i32** %23
%203 = getelementptr inbounds i32, i32* %202, i32 1
store i32* %203, i32** %23
store i32 0, i32* %202
%204 = load i32, i32* %16
%205 = load i32*, i32** %23
%206 = call i32 @NS_PUT16(i32 %204, i32* %205)
%207 = load i32, i32* %15
%208 = load i32*, i32** %23
%209 = call i32 @NS_PUT16(i32 %207, i32* %208)
%210 = load i32*, i32** %23
%211 = call i32 @NS_PUT32(i32 0, i32* %210)
%212 = load i32, i32* %18
%213 = load i32*, i32** %23
%214 = call i32 @NS_PUT16(i32 %212, i32* %213)
%215 = load i32, i32* %18
%216 = icmp ne i32 %215, 0
br i1 %216, label %217, label %226
217: ; preds = %201
%218 = load i32*, i32** %23
%219 = load i32*, i32** %17
%220 = load i32, i32* %18
%221 = call i32 @memcpy(i32* %218, i32* %219, i32 %220)
%222 = load i32, i32* %18
%223 = load i32*, i32** %23
%224 = sext i32 %222 to i64
%225 = getelementptr inbounds i32, i32* %223, i64 %224
store i32* %225, i32** %23
br label %226
226: ; preds = %217, %201
%227 = call i8* @htons(i32 1)
%228 = load %struct.TYPE_5__*, %struct.TYPE_5__** %22
%229 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %228, i32 0, i32 3
store i8* %227, i8** %229
br label %231
230: ; preds = %55
store i32 -1, i32* %11
br label %239
231: ; preds = %226, %169, %154
%232 = load i32*, i32** %23
%233 = load i32*, i32** %20
%234 = ptrtoint i32* %232 to i64
%235 = ptrtoint i32* %233 to i64
%236 = sub i64 %234, %235
%237 = sdiv exact i64 %236, 4
%238 = trunc i64 %237 to i32
store i32 %238, i32* %11
br label %239
239: ; preds = %231, %230, %200, %168, %131, %120, %113, %36
%240 = load i32, i32* %11
ret i32 %240
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32 }
%struct.timeval = type { i32, i32 }
@HFIXEDSZ = global i32 0
@RES_RECURSE = global i32 0
@NOERROR = global i32 0
@QFIXEDSZ = global i32 0
@RRFIXEDSZ = global i32 0
@T_NULL = global i32 0
define i32 @res_nmkquery(%struct.TYPE_4__* nocapture %0, i32 %1, i8* %2, i32 %3, i32 %4, i32* %5, i32 %6, i32* nocapture readnone %7, i32* %8, i32 %9) {
%11 = alloca [20 x i32*]
%12 = alloca %struct.timeval
%13 = bitcast [20 x i32*]* %11 to i8*
%14 = icmp eq i32* %8, null
br i1 %14, label %127, label %15
15: ; preds = %10
%16 = load i32, i32* @HFIXEDSZ
%17 = icmp sgt i32 %16, %9
br i1 %17, label %127, label %18
18: ; preds = %15
%19 = tail call i32 @memset(i32* %8, i32 0, i32 %16)
%20 = bitcast %struct.timeval* %12 to i8*
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i64 0, i32 0
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i64 0, i32 1
br label %23
23: ; preds = %23, %18
%24 = call i32 @__gettimeofday(%struct.timeval* %12, i32* null)
%25 = load i32, i32* %21
%26 = shl i32 %25, 8
%27 = load i32, i32* %22
%28 = xor i32 %26, %27
%29 = and i32 %28, 65535
%30 = icmp eq i32 %29, 0
br i1 %30, label %23, label %31
31: ; preds = %23
%32 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
%33 = load i32, i32* %32
%34 = add nsw i32 %33, %28
%35 = and i32 %34, 65535
store i32 %35, i32* %32
store i32 %35, i32* %8
%36 = getelementptr inbounds i32, i32* %8, i64 1
store i32 %1, i32* %36
%37 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
%38 = load i32, i32* %37
%39 = load i32, i32* @RES_RECURSE
%40 = and i32 %39, %38
%41 = icmp ne i32 %40, 0
%42 = zext i1 %41 to i32
%43 = getelementptr inbounds i32, i32* %8, i64 2
store i32 %42, i32* %43
%44 = load i32, i32* @NOERROR
%45 = getelementptr inbounds i32, i32* %8, i64 10
store i32 %44, i32* %45
%46 = load i32, i32* @HFIXEDSZ
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %8, i64 %47
%49 = sub nsw i32 %9, %46
%50 = getelementptr inbounds [20 x i32*], [20 x i32*]* %11, i64 0, i64 0
%51 = getelementptr inbounds [20 x i32*], [20 x i32*]* %11, i64 0, i64 1
store i32* %8, i32** %50
store i32* null, i32** %51
%52 = getelementptr inbounds [20 x i32*], [20 x i32*]* %11, i64 0, i64 20
switch i32 %1, label %127 [
i32 129, label %53
i32 128, label %61
i32 130, label %95
]
53: ; preds = %31
%54 = load i32, i32* @QFIXEDSZ
%55 = icmp eq i32* %5, null
%56 = load i32, i32* @RRFIXEDSZ
%57 = select i1 %55, i32 0, i32 %56
%58 = add i32 %54, %57
%59 = sub i32 %49, %58
%60 = icmp slt i32 %59, 0
br i1 %60, label %127, label %65
61: ; preds = %31
%62 = load i32, i32* @QFIXEDSZ
%63 = sub nsw i32 %49, %62
%64 = icmp slt i32 %63, 0
br i1 %64, label %127, label %65
65: ; preds = %61, %53
%66 = phi i32 [ %63, %61 ], [ %59, %53 ]
%67 = call i32 @ns_name_compress(i8* %2, i32* %48, i32 %66, i32** %50, i32** %52)
%68 = icmp slt i32 %67, 0
br i1 %68, label %127, label %69
69: ; preds = %65
%70 = zext i32 %67 to i64
%71 = getelementptr inbounds i32, i32* %48, i64 %70
%72 = call i32 @NS_PUT16(i32 %4, i32* %71)
%73 = call i32 @NS_PUT16(i32 %3, i32* %71)
%74 = call i8* @htons(i32 1)
%75 = getelementptr inbounds i32, i32* %8, i64 8
%76 = bitcast i32* %75 to i8**
store i8* %74, i8** %76
%77 = icmp eq i32 %1, 128
%78 = icmp eq i32* %5, null
%79 = or i1 %77, %78
br i1 %79, label %120, label %80
80: ; preds = %69
%81 = sub nsw i32 %66, %67
%82 = bitcast i32* %5 to i8*
%83 = call i32 @ns_name_compress(i8* %82, i32* %71, i32 %81, i32** %50, i32** %52)
%84 = lshr i32 %83, 31
%85 = call i32 @__glibc_unlikely(i32 %84)
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %127
87: ; preds = %80
%88 = sext i32 %83 to i64
%89 = getelementptr inbounds i32, i32* %71, i64 %88
%90 = load i32, i32* @T_NULL
%91 = call i32 @NS_PUT16(i32 %90, i32* %89)
%92 = call i32 @NS_PUT16(i32 %3, i32* %89)
%93 = call i32 @NS_PUT32(i32 0, i32* %89)
%94 = call i32 @NS_PUT16(i32 0, i32* %89)
br label %114
95: ; preds = %31
%96 = load i32, i32* @RRFIXEDSZ
%97 = add i32 %6, 1
%98 = add i32 %97, %96
%99 = icmp slt i32 %49, %98
%100 = zext i1 %99 to i32
%101 = call i32 @__glibc_unlikely(i32 %100)
%102 = icmp eq i32 %101, 0
br i1 %102, label %103, label %127
103: ; preds = %95
%104 = getelementptr inbounds i32, i32* %48, i64 1
store i32 0, i32* %48
%105 = call i32 @NS_PUT16(i32 %4, i32* %104)
%106 = call i32 @NS_PUT16(i32 %3, i32* %104)
%107 = call i32 @NS_PUT32(i32 0, i32* %104)
%108 = call i32 @NS_PUT16(i32 %6, i32* %104)
%109 = icmp eq i32 %6, 0
br i1 %109, label %114, label %110
110: ; preds = %103
%111 = call i32 @memcpy(i32* %104, i32* %5, i32 %6)
%112 = sext i32 %6 to i64
%113 = getelementptr inbounds i32, i32* %104, i64 %112
br label %114
114: ; preds = %103, %110, %87
%115 = phi i64 [ 6, %87 ], [ 4, %110 ], [ 4, %103 ]
%116 = phi i32* [ %89, %87 ], [ %113, %110 ], [ %104, %103 ]
%117 = call i8* @htons(i32 1)
%118 = getelementptr inbounds i32, i32* %8, i64 %115
%119 = bitcast i32* %118 to i8**
store i8* %117, i8** %119
br label %120
120: ; preds = %114, %69
%121 = phi i32* [ %71, %69 ], [ %116, %114 ]
%122 = ptrtoint i32* %121 to i64
%123 = ptrtoint i32* %8 to i64
%124 = sub i64 %122, %123
%125 = lshr exact i64 %124, 2
%126 = trunc i64 %125 to i32
br label %127
127: ; preds = %120, %53, %61, %65, %80, %95, %31, %10, %15
%128 = phi i32 [ -1, %15 ], [ -1, %10 ], [ %126, %120 ], [ -1, %53 ], [ -1, %61 ], [ -1, %65 ], [ -1, %80 ], [ -1, %95 ], [ -1, %31 ]
ret i32 %128
}