#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;
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*/ sprintf(char *, 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);
    }
    sprintf(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    $0x70,%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    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
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    0x2e27(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1217 <res_nquerydomain+0xb7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ec <res_nquerydomain+0x8c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    11fc <res_nquerydomain+0x9c>
lea    0xe32(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    11fc <res_nquerydomain+0x9c>
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
lea    0xdee(%rip),%rdi
call   1060 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    12bc <res_nquerydomain+0x15c>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    0x2da0(%rip),%rcx
cmp    (%rcx),%eax
jl     1265 <res_nquerydomain+0x105>
mov    -0x10(%rbp),%rdi
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
call   1030 <RES_SET_H_ERRNO@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    134e <res_nquerydomain+0x1ee>
mov    -0x4c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jl     12af <res_nquerydomain+0x14f>
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    12af <res_nquerydomain+0x14f>
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    12b7 <res_nquerydomain+0x157>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1329 <res_nquerydomain+0x1c9>
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    0x2cf4(%rip),%rcx
cmp    (%rcx),%eax
jl     1311 <res_nquerydomain+0x1b1>
mov    -0x10(%rbp),%rdi
mov    0x2cd9(%rip),%rax
mov    (%rax),%esi
call   1030 <RES_SET_H_ERRNO@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    134e <res_nquerydomain+0x1ee>
mov    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xd07(%rip),%rsi
call   1080 <sprintf@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   1070 <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    $0x18,%rsp
mov    %r9,-0x40(%rbp)
mov    %r8d,%r12d
mov    %ecx,%r13d
mov    %rdx,%r15
mov    %rsi,%r14
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %rdi,-0x38(%rbp)
test   %eax,(%rdi)
je     11cf <res_nquerydomain+0x6f>
test   %r15,%r15
lea    0xe6f(%rip),%rdx
cmovne %r15,%rdx
lea    0xe3f(%rip),%rdi
mov    %r14,%rsi
mov    %r13d,%ecx
mov    %r12d,%r8d
call   1060 <printf@plt>
mov    %r12d,-0x2c(%rbp)
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
test   %r15,%r15
je     1213 <res_nquerydomain+0xb3>
mov    %r15,%rdi
call   1050 <strlen@plt>
add    %r12d,%eax
add    $0x1,%eax
mov    0x2de0(%rip),%rcx
cmp    (%rcx),%eax
jge    1244 <res_nquerydomain+0xe4>
lea    0xe28(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
call   1080 <sprintf@plt>
jmp    1260 <res_nquerydomain+0x100>
mov    0x2dbe(%rip),%rax
cmp    (%rax),%r12d
jge    1244 <res_nquerydomain+0xe4>
test   %r12d,%r12d
jle    125d <res_nquerydomain+0xfd>
add    $0xffffffff,%r12d
cmpb   $0x2e,(%r14,%r12,1)
jne    125d <res_nquerydomain+0xfd>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1040 <strncpy@plt>
movb   $0x0,(%rbx,%r12,1)
jmp    1260 <res_nquerydomain+0x100>
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
mov    -0x38(%rbp),%rdi
call   1030 <RES_SET_H_ERRNO@plt>
mov    $0xffffffff,%eax
jmp    127a <res_nquerydomain+0x11a>
mov    %r14,%rbx
mov    -0x40(%rbp),%r8
mov    -0x2c(%rbp),%ecx
mov    %r13d,%edx
mov    -0x38(%rbp),%rdi
mov    0x10(%rbp),%r9d
mov    %rbx,%rsi
call   1070 <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 %108
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 %100
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 %108
96: ; preds = %81
%97 = load i8*, i8** %10
%98 = load i8*, i8** %11
%99 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %97, i8* %98)
br label %100
100: ; preds = %96, %80
%101 = load %struct.TYPE_5__*, %struct.TYPE_5__** %9
%102 = load i8*, i8** %18
%103 = load i32, i32* %12
%104 = load i32, i32* %13
%105 = load i32*, i32** %14
%106 = load i32, i32* %15
%107 = call i32 @res_nquery(%struct.TYPE_5__* %101, i8* %102, i32 %103, i32 %104, i32* %105, i32 %106)
store i32 %107, i32* %8
store i32 1, i32* %21
br label %108
108: ; preds = %100, %92, %53
%109 = load i8*, i8** %16
%110 = load i32, i32* %8
ret i32 %110
}

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 @sprintf(i8* %10, i8* dereferenceable(1) 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
}