#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_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ u_char;
struct TYPE_2__ {
  int options;
};

/* Variables and functions */
int MAXDNAME;
int /*<<< orphan*/ NETDB_INTERNAL;
int /*<<< orphan*/ NO_RECOVERY;
int RES_DEBUG;
int RES_INIT;
TYPE_1__ _res;
int /*<<< orphan*/ h_errno;
int /*<<< orphan*/ printf(char *, char const *, char const *, int, int);
int res_init();
int res_query(char const *, int, int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int res_querydomain(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 ((_res.options & RES_INIT) == 0 && res_init() == -1) {
    h_errno = NETDB_INTERNAL;
    return (-1);
  }
  if (_res.options & RES_DEBUG)
    printf(";; res_querydomain(%s, %s, %d, %d)\n", name,
           domain ? domain : "<Nil>", class, type);
  if (domain == NULL) {
    n = (int)strlen(name);
    if (n >= MAXDNAME) {
      h_errno = NO_RECOVERY;
      return (-1);
    }
    n--;
    if (n >= 0 && name[n] == '.') {
      strncpy(nbuf, name, n);
      nbuf[n] = '\0';
    } else
      longname = name;
  } else {
    n = (int)strlen(name);
    d = (int)strlen(domain);
    if (n + d + 1 >= MAXDNAME) {
      h_errno = NO_RECOVERY;
      return (-1);
    }
    sprintf(nbuf, "%s.%s", name, domain);
  }
  return (res_query(longname, class, type, answer, anslen));
}


x86 assembly (clang, -O0):
<res_querydomain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    0x2e3b(%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    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    0x2df0(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1200 <res_querydomain+0xa0>
mov    $0x0,%al
call   1060 <res_init@plt>
cmp    $0xffffffff,%eax
jne    1200 <res_querydomain+0xa0>
mov    0x2dee(%rip),%rax
mov    (%rax),%ecx
mov    0x2ded(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1398 <res_querydomain+0x238>
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    0x2dd0(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1266 <res_querydomain+0x106>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     123b <res_querydomain+0xdb>
mov    -0x18(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    124b <res_querydomain+0xeb>
lea    0xde2(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    124b <res_querydomain+0xeb>
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xd9f(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
jne    130a <res_querydomain+0x1aa>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    0x2d39(%rip),%rcx
cmp    (%rcx),%eax
jl     12b4 <res_querydomain+0x154>
mov    0x2d22(%rip),%rax
mov    (%rax),%ecx
mov    0x2d39(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1398 <res_querydomain+0x238>
mov    -0x4c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jl     12fd <res_querydomain+0x19d>
mov    -0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    12fd <res_querydomain+0x19d>
mov    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x60(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1305 <res_querydomain+0x1a5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1377 <res_querydomain+0x217>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x50(%rbp)
mov    -0x4c(%rbp),%eax
add    -0x50(%rbp),%eax
add    $0x1,%eax
mov    0x2c8e(%rip),%rcx
cmp    (%rcx),%eax
jl     135f <res_querydomain+0x1ff>
mov    0x2c77(%rip),%rax
mov    (%rax),%ecx
mov    0x2c8e(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1398 <res_querydomain+0x238>
mov    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xcb8(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x48(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
call   1070 <res_query@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_querydomain>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,-0x2c(%rbp)
mov    %r8,-0x40(%rbp)
mov    %ecx,-0x34(%rbp)
mov    %edx,-0x30(%rbp)
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e34(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e40(%rip),%r12
mov    (%r12),%eax
mov    0x2dfd(%rip),%rcx
test   %eax,(%rcx)
jne    11cb <res_querydomain+0x6b>
xor    %eax,%eax
call   1060 <res_init@plt>
cmp    $0xffffffff,%eax
je     1289 <res_querydomain+0x129>
mov    (%r12),%eax
mov    0x2e0e(%rip),%rcx
test   %eax,(%rcx)
je     11fa <res_querydomain+0x9a>
test   %r15,%r15
lea    0xe44(%rip),%rdx
cmovne %r15,%rdx
lea    0xe15(%rip),%rdi
mov    %r14,%rsi
mov    -0x30(%rbp),%ecx
mov    -0x34(%rbp),%r8d
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
test   %r15,%r15
je     124e <res_querydomain+0xee>
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %r12d,%eax
add    $0x1,%eax
cmp    0x0(%r13),%eax
jge    1280 <res_querydomain+0x120>
lea    0xe05(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
call   1080 <sprintf@plt>
mov    -0x2c(%rbp),%r13d
mov    -0x40(%rbp),%rcx
mov    %rbx,%rdi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    %r13d,%r8d
call   1070 <res_query@plt>
jmp    12a0 <res_querydomain+0x140>
cmp    %r12d,0x0(%r13)
jle    1280 <res_querydomain+0x120>
test   %r12d,%r12d
jle    12af <res_querydomain+0x14f>
add    $0xffffffff,%r12d
mov    %r12d,%r15d
cmpb   $0x2e,(%r14,%r15,1)
mov    -0x2c(%rbp),%r13d
jne    12b7 <res_querydomain+0x157>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rbx,%r15,1)
jmp    1237 <res_querydomain+0xd7>
mov    0x2d31(%rip),%rax
jmp    1290 <res_querydomain+0x130>
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    0x2d3f(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rbx
jmp    1233 <res_querydomain+0xd3>
mov    %r14,%rbx
jmp    1237 <res_querydomain+0xd7>

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

LLVM IR (-O2):
%struct.TYPE_2__ = type { i32 }
@MAXDNAME = global i32 0
@_res = global %struct.TYPE_2__ zeroinitializer
@RES_INIT = global i32 0
@NETDB_INTERNAL = global i32 0
@h_errno = global i32 0
@RES_DEBUG = global i32 0
@.str = [36 x i8] c";; res_querydomain(%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_querydomain(i8* %0, i8* %1, i32 %2, i32 %3, i32* %4, i32 %5) {
%7 = load i32, i32* @MAXDNAME
%8 = zext i32 %7 to i64
%9 = alloca i8, i64 %8
%10 = load i32, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @_res, i64 0, i32 0)
%11 = load i32, i32* @RES_INIT
%12 = and i32 %11, %10
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %6
%15 = tail call i32 (...) @res_init()
%16 = icmp eq i32 %15, -1
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = load i32, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @_res, i64 0, i32 0)
br label %21
19: ; preds = %14
%20 = load i32, i32* @NETDB_INTERNAL
store i32 %20, i32* @h_errno
br label %64
21: ; preds = %17, %6
%22 = phi i32 [ %18, %17 ], [ %10, %6 ]
%23 = load i32, i32* @RES_DEBUG
%24 = and i32 %23, %22
%25 = icmp eq i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %21
%27 = icmp eq i8* %1, null
%28 = select i1 %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1
%29 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %28, i32 %2, i32 %3)
br label %30
30: ; preds = %26, %21
%31 = icmp eq i8* %1, null
%32 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%33 = trunc i64 %32 to i32
br i1 %31, label %34, label %50
34: ; preds = %30
%35 = load i32, i32* @MAXDNAME
%36 = icmp sgt i32 %35, %33
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = load i32, i32* @NO_RECOVERY
store i32 %38, i32* @h_errno
br label %64
39: ; preds = %34
%40 = add nsw i32 %33, -1
%41 = icmp sgt i32 %33, 0
br i1 %41, label %42, label %61
42: ; preds = %39
%43 = zext i32 %40 to i64
%44 = getelementptr inbounds i8, i8* %0, i64 %43
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, 46
br i1 %46, label %47, label %61
47: ; preds = %42
%48 = call i32 @strncpy(i8* %9, i8* %0, i32 %40)
%49 = getelementptr inbounds i8, i8* %9, i64 %43
store i8 0, i8* %49
br label %61
50: ; preds = %30
%51 = tail call i64 @strlen(i8* %1)
%52 = trunc i64 %51 to i32
%53 = add i32 %33, 1
%54 = add i32 %53, %52
%55 = load i32, i32* @MAXDNAME
%56 = icmp slt i32 %54, %55
br i1 %56, label %59, label %57
57: ; preds = %50
%58 = load i32, i32* @NO_RECOVERY
store i32 %58, i32* @h_errno
br label %64
59: ; preds = %50
%60 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
br label %61
61: ; preds = %39, %42, %47, %59
%62 = phi i8* [ %9, %47 ], [ %9, %59 ], [ %0, %42 ], [ %0, %39 ]
%63 = call i32 @res_query(i8* %62, i32 %2, i32 %3, i32* %4, i32 %5)
br label %64
64: ; preds = %61, %57, %37, %19
%65 = phi i32 [ -1, %19 ], [ -1, %37 ], [ %63, %61 ], [ -1, %57 ]
ret i32 %65
}