#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 */
typedef int u_int16_t;
typedef int /*<<< orphan*/ u_char;
struct in_addr {
  int dummy;
};
typedef int /*<<< orphan*/ ns_rr;
typedef int /*<<< orphan*/ ns_msg;
typedef int /*<<< orphan*/ mx_name;

/* Variables and functions */
int MAXDNAME;
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *ns_msg_base(int /*<<< orphan*/);
int ns_msg_size(int /*<<< orphan*/);
int ns_name_uncompress(int /*<<< orphan*/ const *, int /*<<< orphan*/ const *,
                       int /*<<< orphan*/ const *, char *, int);
int /*<<< orphan*/ *ns_rr_rdata(int /*<<< orphan*/);
int ns_rr_rdlen(int /*<<< orphan*/);
scalar_t__ ns_rr_type(int /*<<< orphan*/);
int /*<<< orphan*/ ns_t_a;
scalar_t__ ns_t_mx;
int query(char *, int /*<<< orphan*/, struct in_addr *);
int /*<<< orphan*/ stderr;
int process_mx_record(ns_msg *handle, ns_rr *record, struct in_addr *results) {
  if (ns_rr_type(*record) != ns_t_mx) {
    fputs("unexpected resource record type\n", stderr);
    return -1;
  }
  const u_char *msg_begin = ns_msg_base(*handle);
  const u_char *msg_end = msg_begin + ns_msg_size(*handle);
  const u_char *data = ns_rr_rdata(*record);
  u_int16_t data_len = ns_rr_rdlen(*record);
  if (data_len < 3) {
    fputs("malformed (too short) resource record\n", stderr);
    return -1;
  }
  char mx_name[MAXDNAME];
  int status = ns_name_uncompress(msg_begin, msg_end, data + 2, mx_name,
                                  sizeof(mx_name));
  if (status == -1 || data_len != 2 + status) {
    fputs("malformed resource record\n", stderr);
    return -1;
  }
  status = query(mx_name, ns_t_a, results);
  if (status == 0) {
    fputs("failed to resolve MX name to IPv4 address\n", stderr);
  }
  return status;
}


x86 assembly (clang, -O0):
<process_mx_record>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1080 <ns_rr_type@plt>
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
je     11d0 <process_mx_record+0x50>
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
lea    0xe41(%rip),%rdi
call   1040 <fputs@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1324 <process_mx_record+0x1a4>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1090 <ns_msg_base@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <ns_msg_size@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1060 <ns_rr_rdata@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <ns_rr_rdlen@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x3,-0x3c(%rbp)
jge    124e <process_mx_record+0xce>
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
lea    0xde4(%rip),%rdi
call   1040 <fputs@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1324 <process_mx_record+0x1a4>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
add    $0x8,%rdx
mov    %eax,%r8d
call   10a0 <ns_name_uncompress@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
je     12b0 <process_mx_record+0x130>
mov    -0x3c(%rbp),%eax
mov    -0x54(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
je     12d8 <process_mx_record+0x158>
mov    0x2d19(%rip),%rax
mov    (%rax),%esi
lea    0xd88(%rip),%rdi
call   1040 <fputs@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    131d <process_mx_record+0x19d>
mov    -0x68(%rbp),%rdi
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
call   1070 <query@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jne    1310 <process_mx_record+0x190>
mov    0x2cce(%rip),%rax
mov    (%rax),%esi
lea    0xd58(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x58(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_mx_record>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%edi
call   1080 <ns_rr_type@plt>
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%rax
jne    11ef <process_mx_record+0x6f>
mov    %r15,-0x38(%rbp)
mov    (%r14),%edi
call   1090 <ns_msg_base@plt>
mov    %rax,%r12
mov    (%r14),%edi
call   1030 <ns_msg_size@plt>
mov    %eax,%r13d
mov    (%rbx),%edi
call   1060 <ns_rr_rdata@plt>
mov    %rax,%r14
mov    (%rbx),%edi
call   1050 <ns_rr_rdlen@plt>
cmp    $0x2,%eax
jg     120e <process_mx_record+0x8e>
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
lea    0xe34(%rip),%rdi
jmp    11ff <process_mx_record+0x7f>
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
lea    0xe01(%rip),%rdi
call   1040 <fputs@plt>
mov    $0xffffffff,%ebx
jmp    129b <process_mx_record+0x11b>
mov    %eax,%r15d
mov    %rsp,-0x30(%rbp)
movslq %r13d,%rax
lea    (%r12,%rax,4),%rsi
mov    0x2da5(%rip),%rax
mov    (%rax),%r8d
mov    %rsp,%r13
mov    %r8,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
add    $0x8,%r14
mov    %r12,%rdi
mov    %r14,%rdx
mov    %r13,%rcx
call   10a0 <ns_name_uncompress@plt>
mov    $0xffffffff,%ebx
lea    0xdf0(%rip),%rdi
cmp    $0xffffffff,%eax
je     1289 <process_mx_record+0x109>
add    $0x2,%eax
cmp    %eax,%r15d
jne    1289 <process_mx_record+0x109>
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
mov    -0x38(%rbp),%rdx
call   1070 <query@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1297 <process_mx_record+0x117>
xor    %ebx,%ebx
lea    0xdda(%rip),%rdi
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    -0x30(%rbp),%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@ns_t_mx = global i64 0
@.str = [33 x i8] c"unexpected resource record type\0A\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"malformed (too short) resource record\0A\00"
@MAXDNAME = global i32 0
@.str.2 = [27 x i8] c"malformed resource record\0A\00"
@ns_t_a = global i32 0
@.str.3 = [43 x i8] c"failed to resolve MX name to IPv4 address\0A\00"
define i32 @process_mx_record(i32* %0, i32* %1, %struct.in_addr* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca %struct.in_addr*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store %struct.in_addr* %2, %struct.in_addr** %7
%16 = load i32*, i32** %6
%17 = load i32, i32* %16
%18 = call i64 @ns_rr_type(i32 %17)
%19 = load i64, i64* @ns_t_mx
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %3
%22 = load i32, i32* @stderr
%23 = call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %22)
store i32 -1, i32* %4
br label %79
24: ; preds = %3
%25 = load i32*, i32** %5
%26 = load i32, i32* %25
%27 = call i32* @ns_msg_base(i32 %26)
store i32* %27, i32** %8
%28 = load i32*, i32** %8
%29 = load i32*, i32** %5
%30 = load i32, i32* %29
%31 = call i32 @ns_msg_size(i32 %30)
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %28, i64 %32
store i32* %33, i32** %9
%34 = load i32*, i32** %6
%35 = load i32, i32* %34
%36 = call i32* @ns_rr_rdata(i32 %35)
store i32* %36, i32** %10
%37 = load i32*, i32** %6
%38 = load i32, i32* %37
%39 = call i32 @ns_rr_rdlen(i32 %38)
store i32 %39, i32* %11
%40 = load i32, i32* %11
%41 = icmp slt i32 %40, 3
br i1 %41, label %42, label %45
42: ; preds = %24
%43 = load i32, i32* @stderr
%44 = call i32 @fputs(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %43)
store i32 -1, i32* %4
br label %79
45: ; preds = %24
%46 = load i32, i32* @MAXDNAME
%47 = zext i32 %46 to i64
%48 = call i8* @llvm.stacksave()
store i8* %48, i8** %12
%49 = alloca i8, i64 %47
store i64 %47, i64* %13
%50 = load i32*, i32** %8
%51 = load i32*, i32** %9
%52 = load i32*, i32** %10
%53 = getelementptr inbounds i32, i32* %52, i64 2
%54 = trunc i64 %47 to i32
%55 = call i32 @ns_name_uncompress(i32* %50, i32* %51, i32* %53, i8* %49, i32 %54)
store i32 %55, i32* %14
%56 = load i32, i32* %14
%57 = icmp eq i32 %56, -1
br i1 %57, label %63, label %58
58: ; preds = %45
%59 = load i32, i32* %11
%60 = load i32, i32* %14
%61 = add nsw i32 2, %60
%62 = icmp ne i32 %59, %61
br i1 %62, label %63, label %66
63: ; preds = %58, %45
%64 = load i32, i32* @stderr
%65 = call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %64)
store i32 -1, i32* %4
store i32 1, i32* %15
br label %77
66: ; preds = %58
%67 = load i32, i32* @ns_t_a
%68 = load %struct.in_addr*, %struct.in_addr** %7
%69 = call i32 @query(i8* %49, i32 %67, %struct.in_addr* %68)
store i32 %69, i32* %14
%70 = load i32, i32* %14
%71 = icmp eq i32 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %66
%73 = load i32, i32* @stderr
%74 = call i32 @fputs(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %72, %66
%76 = load i32, i32* %14
store i32 %76, i32* %4
store i32 1, i32* %15
br label %77
77: ; preds = %75, %63
%78 = load i8*, i8** %12
br label %79
79: ; preds = %77, %42, %21
%80 = load i32, i32* %4
ret i32 %80
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@ns_t_mx = global i64 0
@.str = [33 x i8] c"unexpected resource record type\0A\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"malformed (too short) resource record\0A\00"
@MAXDNAME = global i32 0
@.str.2 = [27 x i8] c"malformed resource record\0A\00"
@ns_t_a = global i32 0
@.str.3 = [43 x i8] c"failed to resolve MX name to IPv4 address\0A\00"
define i32 @process_mx_record(i32* nocapture %0, i32* nocapture %1, %struct.in_addr* %2) {
%4 = load i32, i32* %1
%5 = tail call i64 @ns_rr_type(i32 %4)
%6 = load i64, i64* @ns_t_mx
%7 = icmp eq i64 %5, %6
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %48
11: ; preds = %3
%12 = load i32, i32* %0
%13 = tail call i32* @ns_msg_base(i32 %12)
%14 = load i32, i32* %0
%15 = tail call i32 @ns_msg_size(i32 %14)
%16 = load i32, i32* %1
%17 = tail call i32* @ns_rr_rdata(i32 %16)
%18 = load i32, i32* %1
%19 = tail call i32 @ns_rr_rdlen(i32 %18)
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = load i32, i32* @stderr
%23 = tail call i32 @fputs(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %48
24: ; preds = %11
%25 = sext i32 %15 to i64
%26 = getelementptr inbounds i32, i32* %13, i64 %25
%27 = load i32, i32* @MAXDNAME
%28 = zext i32 %27 to i64
%29 = tail call i8* @llvm.stacksave()
%30 = alloca i8, i64 %28
%31 = getelementptr inbounds i32, i32* %17, i64 2
%32 = call i32 @ns_name_uncompress(i32* %13, i32* %26, i32* %31, i8* %30, i32 %27)
%33 = icmp ne i32 %32, -1
%34 = add nsw i32 %32, 2
%35 = icmp eq i32 %19, %34
%36 = select i1 %33, i1 %35, i1 false
br i1 %36, label %37, label %41
37: ; preds = %24
%38 = load i32, i32* @ns_t_a
%39 = call i32 @query(i8* %30, i32 %38, %struct.in_addr* %2)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %37, %24
%42 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), %24 ], [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), %37 ]
%43 = phi i32 [ -1, %24 ], [ 0, %37 ]
%44 = load i32, i32* @stderr
%45 = call i32 @fputs(i8* %42, i32 %44)
br label %46
46: ; preds = %41, %37
%47 = phi i32 [ %39, %37 ], [ %43, %41 ]
br label %48
48: ; preds = %21, %46, %8
%49 = phi i32 [ -1, %8 ], [ -1, %21 ], [ %47, %46 ]
ret i32 %49
}