#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_1__;

/* Type definitions */
typedef int /*<<< orphan*/ u_char;
typedef TYPE_1__ *res_state;
typedef int /*<<< orphan*/ nbuf;
struct TYPE_5__ {
  int options;
};

/* Variables and functions */
int MAXDNAME;
int /*<<< orphan*/ NO_RECOVERY;
int RES_DEBUG;
int /*<<< orphan*/ RES_SET_H_ERRNO(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *, char const *, int, int);
int res_nquery(TYPE_1__ *, char const *, int, int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
int res_nquerydomain(res_state statp, const char *name, const char *domain,
                     int class, int type, u_char *answer, int anslen) {
  char nbuf[MAXDNAME];
  const char *longname = nbuf;
  int n, d;
  if (statp->options & RES_DEBUG)
    printf(";; res_nquerydomain(%s, %s, %d, %d)\n", name,
           domain ? domain : "<Nil>", class, type);
  if (domain == NULL) {
    n = strlen(name);
    if (n >= MAXDNAME) {
      RES_SET_H_ERRNO(statp, NO_RECOVERY);
      return (-1);
    }
    n--;
    if (n >= 0 && name[n] == '.') {
      strncpy(nbuf, name, (size_t)n);
      nbuf[n] = '\0';
    } else
      longname = name;
  } else {
    n = strlen(name);
    d = strlen(domain);
    if (n + d + 1 >= MAXDNAME) {
      RES_SET_H_ERRNO(statp, NO_RECOVERY);
      return (-1);
    }
    snprintf(nbuf, sizeof(nbuf), "%s.%s", name, domain);
  }
  return (res_nquery(statp, longname, class, type, answer, anslen));
}


x86 assembly (clang, -O0):
<res_nquerydomain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
mov    %rcx,-0x68(%rbp)
mov    %rsp,%rax
mov    %rax,-0x38(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x60(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x40(%rbp)
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    0x2e20(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     121e <res_nquerydomain+0xbe>
mov    -0x18(%rbp),%rax
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f3 <res_nquerydomain+0x93>
mov    -0x20(%rbp),%rax
mov    %rax,-0x78(%rbp)
jmp    1203 <res_nquerydomain+0xa3>
lea    0xe2b(%rip),%rax
mov    %rax,-0x78(%rbp)
jmp    1203 <res_nquerydomain+0xa3>
mov    -0x70(%rbp),%rsi
mov    -0x78(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
lea    0xde7(%rip),%rdi
call   1060 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    12c3 <res_nquerydomain+0x163>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    0x2d99(%rip),%rcx
cmp    (%rcx),%eax
jl     126c <res_nquerydomain+0x10c>
mov    -0x10(%rbp),%rdi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
call   1030 <RES_SET_H_ERRNO@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    135b <res_nquerydomain+0x1fb>
mov    -0x4c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jl     12b6 <res_nquerydomain+0x156>
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    12b6 <res_nquerydomain+0x156>
mov    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x4c(%rbp),%rdx
call   1040 <strncpy@plt>
mov    -0x60(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12be <res_nquerydomain+0x15e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1336 <res_nquerydomain+0x1d6>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x50(%rbp)
mov    -0x4c(%rbp),%eax
add    -0x50(%rbp),%eax
add    $0x1,%eax
mov    0x2ced(%rip),%rcx
cmp    (%rcx),%eax
jl     1318 <res_nquerydomain+0x1b8>
mov    -0x10(%rbp),%rdi
mov    0x2cd2(%rip),%rax
mov    (%rax),%esi
call   1030 <RES_SET_H_ERRNO@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    135b <res_nquerydomain+0x1fb>
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xcfa(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x30(%rbp),%r8
mov    0x10(%rbp),%r9d
call   1080 <res_nquery@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<res_nquerydomain>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,-0x40(%rbp)
mov    %r8d,%r13d
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %rsi,%r14
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %rdi,-0x38(%rbp)
test   %eax,(%rdi)
je     11d3 <res_nquerydomain+0x73>
test   %r15,%r15
lea    0xe6b(%rip),%rdx
cmovne %r15,%rdx
lea    0xe3b(%rip),%rdi
mov    %r14,%rsi
mov    %r12d,%ecx
mov    %r13d,%r8d
call   1060 <printf@plt>
mov    %r13d,-0x2c(%rbp)
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
test   %r15,%r15
je     121b <res_nquerydomain+0xbb>
mov    %r15,%rdi
call   1050 <strlen@plt>
add    %r13d,%eax
add    $0x1,%eax
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%eax
jge    124c <res_nquerydomain+0xec>
lea    0xe24(%rip),%rdx
mov    %rbx,%rdi
mov    -0x48(%rbp),%rsi
mov    %r14,%rcx
mov    %r15,%r8
call   1070 <snprintf@plt>
jmp    1268 <res_nquerydomain+0x108>
mov    0x2db6(%rip),%rax
cmp    (%rax),%r13d
jge    124c <res_nquerydomain+0xec>
test   %r13d,%r13d
jle    1265 <res_nquerydomain+0x105>
add    $0xffffffff,%r13d
cmpb   $0x2e,(%r14,%r13,1)
jne    1265 <res_nquerydomain+0x105>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1040 <strncpy@plt>
movb   $0x0,(%rbx,%r13,1)
jmp    1268 <res_nquerydomain+0x108>
mov    0x2d7d(%rip),%rax
mov    (%rax),%esi
mov    -0x38(%rbp),%rdi
call   1030 <RES_SET_H_ERRNO@plt>
mov    $0xffffffff,%eax
jmp    1282 <res_nquerydomain+0x122>
mov    %r14,%rbx
mov    -0x40(%rbp),%r8
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%ecx
mov    %r12d,%edx
mov    0x10(%rbp),%r9d
mov    %rbx,%rsi
call   1080 <res_nquery@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32 }
@MAXDNAME = global i32 0
@RES_DEBUG = global i32 0
@.str = [37 x i8] c";; res_nquerydomain(%s, %s, %d, %d)\0A\00"
@.str.1 = [6 x i8] c"<Nil>\00"
@NO_RECOVERY = global i32 0
@.str.2 = [6 x i8] c"%s.%s\00"
define i32 @res_nquerydomain(%struct.TYPE_5__* %0, i8* %1, i8* %2, i32 %3, i32 %4, i32* %5, i32 %6) {
%8 = alloca i32
%9 = alloca %struct.TYPE_5__*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i8*
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store %struct.TYPE_5__* %0, %struct.TYPE_5__** %9
store i8* %1, i8** %10
store i8* %2, i8** %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32* %5, i32** %14
store i32 %6, i32* %15
%22 = load i32, i32* @MAXDNAME
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %16
%25 = alloca i8, i64 %23
store i64 %23, i64* %17
store i8* %25, i8** %18
%26 = load %struct.TYPE_5__*, %struct.TYPE_5__** %9
%27 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load i32, i32* @RES_DEBUG
%30 = and i32 %28, %29
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %44
32: ; preds = %7
%33 = load i8*, i8** %10
%34 = load i8*, i8** %11
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = load i8*, i8** %11
br label %39
38: ; preds = %32
br label %39
39: ; preds = %38, %36
%40 = phi i8* [ %37, %36 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %38 ]
%41 = load i32, i32* %12
%42 = load i32, i32* %13
%43 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %33, i8* %40, i32 %41, i32 %42)
br label %44
44: ; preds = %39, %7
%45 = load i8*, i8** %11
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %81
47: ; preds = %44
%48 = load i8*, i8** %10
%49 = call i32 @strlen(i8* %48)
store i32 %49, i32* %19
%50 = load i32, i32* %19
%51 = load i32, i32* @MAXDNAME
%52 = icmp sge i32 %50, %51
br i1 %52, label %53, label %57
53: ; preds = %47
%54 = load %struct.TYPE_5__*, %struct.TYPE_5__** %9
%55 = load i32, i32* @NO_RECOVERY
%56 = call i32 @RES_SET_H_ERRNO(%struct.TYPE_5__* %54, i32 %55)
store i32 -1, i32* %8
store i32 1, i32* %21
br label %109
57: ; preds = %47
%58 = load i32, i32* %19
%59 = add nsw i32 %58, -1
store i32 %59, i32* %19
%60 = load i32, i32* %19
%61 = icmp sge i32 %60, 0
br i1 %61, label %62, label %78
62: ; preds = %57
%63 = load i8*, i8** %10
%64 = load i32, i32* %19
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 46
br i1 %69, label %70, label %78
70: ; preds = %62
%71 = load i8*, i8** %10
%72 = load i32, i32* %19
%73 = sext i32 %72 to i64
%74 = call i32 @strncpy(i8* %25, i8* %71, i64 %73)
%75 = load i32, i32* %19
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %25, i64 %76
store i8 0, i8* %77
br label %80
78: ; preds = %62, %57
%79 = load i8*, i8** %10
store i8* %79, i8** %18
br label %80
80: ; preds = %78, %70
br label %101
81: ; preds = %44
%82 = load i8*, i8** %10
%83 = call i32 @strlen(i8* %82)
store i32 %83, i32* %19
%84 = load i8*, i8** %11
%85 = call i32 @strlen(i8* %84)
store i32 %85, i32* %20
%86 = load i32, i32* %19
%87 = load i32, i32* %20
%88 = add nsw i32 %86, %87
%89 = add nsw i32 %88, 1
%90 = load i32, i32* @MAXDNAME
%91 = icmp sge i32 %89, %90
br i1 %91, label %92, label %96
92: ; preds = %81
%93 = load %struct.TYPE_5__*, %struct.TYPE_5__** %9
%94 = load i32, i32* @NO_RECOVERY
%95 = call i32 @RES_SET_H_ERRNO(%struct.TYPE_5__* %93, i32 %94)
store i32 -1, i32* %8
store i32 1, i32* %21
br label %109
96: ; preds = %81
%97 = trunc i64 %23 to i32
%98 = load i8*, i8** %10
%99 = load i8*, i8** %11
%100 = call i32 @snprintf(i8* %25, i32 %97, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %98, i8* %99)
br label %101
101: ; preds = %96, %80
%102 = load %struct.TYPE_5__*, %struct.TYPE_5__** %9
%103 = load i8*, i8** %18
%104 = load i32, i32* %12
%105 = load i32, i32* %13
%106 = load i32*, i32** %14
%107 = load i32, i32* %15
%108 = call i32 @res_nquery(%struct.TYPE_5__* %102, i8* %103, i32 %104, i32 %105, i32* %106, i32 %107)
store i32 %108, i32* %8
store i32 1, i32* %21
br label %109
109: ; preds = %101, %92, %53
%110 = load i8*, i8** %16
%111 = load i32, i32* %8
ret i32 %111
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32 }
@MAXDNAME = global i32 0
@RES_DEBUG = global i32 0
@.str = [37 x i8] c";; res_nquerydomain(%s, %s, %d, %d)\0A\00"
@.str.1 = [6 x i8] c"<Nil>\00"
@NO_RECOVERY = global i32 0
@.str.2 = [6 x i8] c"%s.%s\00"
define i32 @res_nquerydomain(%struct.TYPE_5__* %0, i8* %1, i8* %2, i32 %3, i32 %4, i32* %5, i32 %6) {
%8 = load i32, i32* @MAXDNAME
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %0, i64 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @RES_DEBUG
%14 = and i32 %13, %12
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %7
%17 = icmp eq i8* %2, null
%18 = select i1 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %2
%19 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %18, i32 %3, i32 %4)
br label %20
20: ; preds = %16, %7
%21 = icmp eq i8* %2, null
%22 = tail call i32 @strlen(i8* %1)
br i1 %21, label %23, label %40
23: ; preds = %20
%24 = load i32, i32* @MAXDNAME
%25 = icmp slt i32 %22, %24
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* @NO_RECOVERY
%28 = tail call i32 @RES_SET_H_ERRNO(%struct.TYPE_5__* %0, i32 %27)
br label %54
29: ; preds = %23
%30 = icmp sgt i32 %22, 0
br i1 %30, label %31, label %51
31: ; preds = %29
%32 = add nsw i32 %22, -1
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %1, i64 %33
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 46
br i1 %36, label %37, label %51
37: ; preds = %31
%38 = call i32 @strncpy(i8* %10, i8* %1, i64 %33)
%39 = getelementptr inbounds i8, i8* %10, i64 %33
store i8 0, i8* %39
br label %51
40: ; preds = %20
%41 = tail call i32 @strlen(i8* %2)
%42 = add i32 %22, 1
%43 = add i32 %42, %41
%44 = load i32, i32* @MAXDNAME
%45 = icmp slt i32 %43, %44
br i1 %45, label %49, label %46
46: ; preds = %40
%47 = load i32, i32* @NO_RECOVERY
%48 = tail call i32 @RES_SET_H_ERRNO(%struct.TYPE_5__* %0, i32 %47)
br label %54
49: ; preds = %40
%50 = call i32 @snprintf(i8* %10, i32 %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %2)
br label %51
51: ; preds = %29, %31, %37, %49
%52 = phi i8* [ %10, %37 ], [ %10, %49 ], [ %1, %31 ], [ %1, %29 ]
%53 = call i32 @res_nquery(%struct.TYPE_5__* %0, i8* %52, i32 %3, i32 %4, i32* %5, i32 %6)
br label %54
54: ; preds = %51, %46, %26
%55 = phi i32 [ -1, %26 ], [ %53, %51 ], [ -1, %46 ]
ret i32 %55
}