#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 */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ HOST_NOT_FOUND;
int /*<<< orphan*/ NO_DATA;
int /*<<< orphan*/ TRY_AGAIN;
int __res_mkquery(int /*<<< orphan*/, char const *, int, int,
                  int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                  unsigned char *, int);
int __res_send(unsigned char *, int, unsigned char *, int);
int /*<<< orphan*/ h_errno;
int res_query(const char *name, int class, int type, unsigned char *dest,
              int len) {
  unsigned char q[280];
  int ql = __res_mkquery(0, name, class, type, 0, 0, 0, q, sizeof q);
  if (ql < 0)
    return ql;
  int r = __res_send(q, ql, dest, len);
  if (r < 12) {
    h_errno = TRY_AGAIN;
    return -1;
  }
  if ((dest[3] & 15) == 3) {
    h_errno = HOST_NOT_FOUND;
    return -1;
  }
  if ((dest[3] & 15) == 0 && !dest[6] && !dest[7]) {
    h_errno = NO_DATA;
    return -1;
  }
  return r;
}


x86 assembly (clang, -O0):
<res_query>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    -0x140(%rbp),%rax
xor    %r9d,%r9d
mov    %r9d,%edi
mov    %r9d,%r8d
movl   $0x0,(%rsp)
mov    %rax,0x8(%rsp)
movl   $0x118,0x10(%rsp)
call   1030 <__res_mkquery@plt>
mov    %eax,-0x144(%rbp)
cmpl   $0x0,-0x144(%rbp)
jge    1191 <res_query+0x71>
mov    -0x144(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1264 <res_query+0x144>
lea    -0x140(%rbp),%rdi
mov    -0x144(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1040 <__res_send@plt>
mov    %eax,-0x148(%rbp)
cmpl   $0xc,-0x148(%rbp)
jge    11db <res_query+0xbb>
mov    0x2e0c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e1b(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1264 <res_query+0x144>
mov    -0x20(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0xf,%eax
cmp    $0x3,%eax
jne    120d <res_query+0xed>
mov    0x2dea(%rip),%rax
mov    (%rax),%ecx
mov    0x2de9(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1264 <res_query+0x144>
mov    -0x20(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    125b <res_query+0x13b>
mov    -0x20(%rbp),%rax
cmpb   $0x0,0x6(%rax)
jne    125b <res_query+0x13b>
mov    -0x20(%rbp),%rax
cmpb   $0x0,0x7(%rax)
jne    125b <res_query+0x13b>
mov    0x2d84(%rip),%rax
mov    (%rax),%ecx
mov    0x2d9b(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1264 <res_query+0x144>
mov    -0x148(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<res_query>:
push   %rbp
push   %rbx
sub    $0x118,%rsp
mov    %r8d,%ebp
mov    %rcx,%rbx
mov    %edx,%ecx
mov    %esi,%edx
mov    %rdi,%rsi
sub    $0x8,%rsp
lea    0x8(%rsp),%rax
xor    %edi,%edi
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x118
push   %rax
push   $0x0
call   1030 <__res_mkquery@plt>
add    $0x20,%rsp
test   %eax,%eax
js     11b4 <res_query+0x94>
mov    %rsp,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1040 <__res_send@plt>
cmp    $0xc,%eax
jge    1179 <res_query+0x59>
mov    0x2e59(%rip),%rax
jmp    11a4 <res_query+0x84>
mov    0x3(%rbx),%cl
and    $0xf,%cl
cmp    $0x3,%cl
je     119d <res_query+0x7d>
test   %cl,%cl
jne    11b4 <res_query+0x94>
cmpb   $0x0,0x6(%rbx)
jne    11b4 <res_query+0x94>
cmpb   $0x0,0x7(%rbx)
jne    11b4 <res_query+0x94>
mov    0x2e2d(%rip),%rax
jmp    11a4 <res_query+0x84>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    0x2e3b(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x118,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@TRY_AGAIN = global i32 0
@h_errno = global i32 0
@HOST_NOT_FOUND = global i32 0
@NO_DATA = global i32 0
define i32 @res_query(i8* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [280 x i8]
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%15 = load i8*, i8** %7
%16 = load i32, i32* %8
%17 = load i32, i32* %9
%18 = getelementptr inbounds [280 x i8], [280 x i8]* %12, i64 0, i64 0
%19 = call i32 @__res_mkquery(i32 0, i8* %15, i32 %16, i32 %17, i32 0, i32 0, i32 0, i8* %18, i32 280)
store i32 %19, i32* %13
%20 = load i32, i32* %13
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %5
%23 = load i32, i32* %13
store i32 %23, i32* %6
br label %64
24: ; preds = %5
%25 = getelementptr inbounds [280 x i8], [280 x i8]* %12, i64 0, i64 0
%26 = load i32, i32* %13
%27 = load i8*, i8** %10
%28 = load i32, i32* %11
%29 = call i32 @__res_send(i8* %25, i32 %26, i8* %27, i32 %28)
store i32 %29, i32* %14
%30 = load i32, i32* %14
%31 = icmp slt i32 %30, 12
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = load i32, i32* @TRY_AGAIN
store i32 %33, i32* @h_errno
store i32 -1, i32* %6
br label %64
34: ; preds = %24
%35 = load i8*, i8** %10
%36 = getelementptr inbounds i8, i8* %35, i64 3
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = and i32 %38, 15
%40 = icmp eq i32 %39, 3
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = load i32, i32* @HOST_NOT_FOUND
store i32 %42, i32* @h_errno
store i32 -1, i32* %6
br label %64
43: ; preds = %34
%44 = load i8*, i8** %10
%45 = getelementptr inbounds i8, i8* %44, i64 3
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = and i32 %47, 15
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %62
50: ; preds = %43
%51 = load i8*, i8** %10
%52 = getelementptr inbounds i8, i8* %51, i64 6
%53 = load i8, i8* %52
%54 = icmp ne i8 %53, 0
br i1 %54, label %62, label %55
55: ; preds = %50
%56 = load i8*, i8** %10
%57 = getelementptr inbounds i8, i8* %56, i64 7
%58 = load i8, i8* %57
%59 = icmp ne i8 %58, 0
br i1 %59, label %62, label %60
60: ; preds = %55
%61 = load i32, i32* @NO_DATA
store i32 %61, i32* @h_errno
store i32 -1, i32* %6
br label %64
62: ; preds = %55, %50, %43
%63 = load i32, i32* %14
store i32 %63, i32* %6
br label %64
64: ; preds = %62, %60, %41, %32, %22
%65 = load i32, i32* %6
ret i32 %65
}

LLVM IR (-O2):
@TRY_AGAIN = global i32 0
@h_errno = global i32 0
@HOST_NOT_FOUND = global i32 0
@NO_DATA = global i32 0
define i32 @res_query(i8* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca [280 x i8]
%7 = getelementptr inbounds [280 x i8], [280 x i8]* %6, i64 0, i64 0
%8 = call i32 @__res_mkquery(i32 0, i8* %0, i32 %1, i32 %2, i32 0, i32 0, i32 0, i8* %7, i32 280)
%9 = icmp slt i32 %8, 0
br i1 %9, label %28, label %10
10: ; preds = %5
%11 = call i32 @__res_send(i8* %7, i32 %8, i8* %3, i32 %4)
%12 = icmp slt i32 %11, 12
br i1 %12, label %25, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %3, i64 3
%15 = load i8, i8* %14
%16 = and i8 %15, 15
switch i8 %16, label %28 [
i8 3, label %25
i8 0, label %17
]
17: ; preds = %13
%18 = getelementptr inbounds i8, i8* %3, i64 6
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %3, i64 7
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21, %13, %10
%26 = phi i32* [ @TRY_AGAIN, %10 ], [ @HOST_NOT_FOUND, %13 ], [ @NO_DATA, %21 ]
%27 = load i32, i32* %26
store i32 %27, i32* @h_errno
br label %28
28: ; preds = %25, %13, %21, %17, %5
%29 = phi i32 [ %8, %5 ], [ %11, %13 ], [ %11, %21 ], [ %11, %17 ], [ -1, %25 ]
ret i32 %29
}