#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 unsigned int uint16_t;
typedef int /*<<< orphan*/ ns_rr;
typedef int /*<<< orphan*/ ns_msg;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ NS_GET16(unsigned int, unsigned char const *);
unsigned int NS_INT16SZ;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ insert_tuple(char *, unsigned int, unsigned int,
                                unsigned int);
int ns_msg_count(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ ns_parserr(int /*<<< orphan*/ *, int /*<<< orphan*/, int,
                      int /*<<< orphan*/ *);
unsigned char *ns_rr_rdata(int /*<<< orphan*/);
unsigned int ns_rr_rdlen(int /*<<< orphan*/);
scalar_t__ ns_rr_type(int /*<<< orphan*/);
int /*<<< orphan*/ ns_s_an;
scalar_t__ ns_t_srv;
int /*<<< orphan*/ perror(char *);
char *target_name(unsigned char const *);
void parse_answer_section(ns_msg *msg) {
  int rrnum, rrmax;
  ns_rr rr;
  uint16_t prio, weight, port, len;
  const unsigned char *rdata;
  char *tname;
  rrmax = ns_msg_count(*msg, ns_s_an);
  for (rrnum = 0; rrnum < rrmax; rrnum++) {
    if (ns_parserr(msg, ns_s_an, rrnum, &rr)) {
      perror("ns_parserr");
      exit(EXIT_FAILURE);
    }
    if (ns_rr_type(rr) == ns_t_srv) {
      len = ns_rr_rdlen(rr);
      rdata = ns_rr_rdata(rr);
      if (len > 3U * NS_INT16SZ) {
        NS_GET16(prio, rdata);
        NS_GET16(weight, rdata);
        NS_GET16(port, rdata);
        len -= 3U * NS_INT16SZ;
        tname = target_name(rdata);
        insert_tuple(tname, prio, weight, port);
      }
    }
  }
}


x86 assembly (clang, -O0):
<parse_answer_section>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
call   1030 <ns_msg_count@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12c4 <parse_answer_section+0x124>
mov    -0x8(%rbp),%rdi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
lea    -0x14(%rbp),%rcx
call   1040 <ns_parserr@plt>
cmp    $0x0,%rax
je     1213 <parse_answer_section+0x73>
lea    0xe00(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
call   10a0 <ns_rr_type@plt>
mov    0x2dc6(%rip),%rcx
cmp    (%rcx),%rax
jne    12b1 <parse_answer_section+0x111>
mov    -0x14(%rbp),%edi
call   1070 <ns_rr_rdlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <ns_rr_rdata@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2d84(%rip),%rcx
imul   $0x3,(%rcx),%ecx
cmp    %ecx,%eax
jbe    12ac <parse_answer_section+0x10c>
mov    -0x18(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1060 <NS_GET16@plt>
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1060 <NS_GET16@plt>
mov    -0x20(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1060 <NS_GET16@plt>
mov    0x2d4e(%rip),%rax
imul   $0x3,(%rax),%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <target_name@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1090 <insert_tuple@plt>
jmp    12b1 <parse_answer_section+0x111>
jmp    12b6 <parse_answer_section+0x116>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ca <parse_answer_section+0x2a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_answer_section>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%edi
mov    0x2e11(%rip),%r13
mov    0x0(%r13),%esi
call   1030 <ns_msg_count@plt>
test   %eax,%eax
jle    1285 <parse_answer_section+0xe5>
mov    %eax,%r12d
xor    %ebx,%ebx
mov    %rsp,%r15
mov    %eax,0x4(%rsp)
jmp    11ec <parse_answer_section+0x4c>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ebx,%r12d
je     1285 <parse_answer_section+0xe5>
mov    0x0(%r13),%esi
mov    %r14,%rdi
mov    %ebx,%edx
mov    %r15,%rcx
call   1040 <ns_parserr@plt>
test   %rax,%rax
jne    1294 <parse_answer_section+0xf4>
mov    (%rsp),%edi
call   10a0 <ns_rr_type@plt>
mov    0x2dd3(%rip),%rcx
cmp    (%rcx),%rax
jne    11e0 <parse_answer_section+0x40>
mov    (%rsp),%edi
call   1070 <ns_rr_rdlen@plt>
mov    %r14,%r12
mov    %r15,%r14
mov    %r13,%r15
mov    %eax,%r13d
mov    (%rsp),%edi
call   1080 <ns_rr_rdata@plt>
mov    %rax,%rbp
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
lea    (%rax,%rax,2),%eax
cmp    %eax,%r13d
mov    %r15,%r13
mov    %r14,%r15
mov    %r12,%r14
mov    0x4(%rsp),%r12d
jbe    11e0 <parse_answer_section+0x40>
mov    %rbp,%rsi
call   1060 <NS_GET16@plt>
mov    %rbp,%rsi
call   1060 <NS_GET16@plt>
mov    %rbp,%rsi
call   1060 <NS_GET16@plt>
mov    %rbp,%rdi
call   1050 <target_name@plt>
mov    %rax,%rdi
call   1090 <insert_tuple@plt>
jmp    11e0 <parse_answer_section+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd65(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@ns_s_an = global i32 0
@.str = [11 x i8] c"ns_parserr\00"
@EXIT_FAILURE = global i32 0
@ns_t_srv = global i64 0
@NS_INT16SZ = global i32 0
define void @parse_answer_section(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i32* %0, i32** %2
%12 = load i32*, i32** %2
%13 = load i32, i32* %12
%14 = load i32, i32* @ns_s_an
%15 = call i32 @ns_msg_count(i32 %13, i32 %14)
store i32 %15, i32* %4
store i32 0, i32* %3
br label %16
16: ; preds = %67, %1
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %70
20: ; preds = %16
%21 = load i32*, i32** %2
%22 = load i32, i32* @ns_s_an
%23 = load i32, i32* %3
%24 = call i64 @ns_parserr(i32* %21, i32 %22, i32 %23, i32* %5)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %20
%31 = load i32, i32* %5
%32 = call i64 @ns_rr_type(i32 %31)
%33 = load i64, i64* @ns_t_srv
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %66
35: ; preds = %30
%36 = load i32, i32* %5
%37 = call i32 @ns_rr_rdlen(i32 %36)
store i32 %37, i32* %9
%38 = load i32, i32* %5
%39 = call i8* @ns_rr_rdata(i32 %38)
store i8* %39, i8** %10
%40 = load i32, i32* %9
%41 = load i32, i32* @NS_INT16SZ
%42 = mul i32 3, %41
%43 = icmp ugt i32 %40, %42
br i1 %43, label %44, label %65
44: ; preds = %35
%45 = load i32, i32* %6
%46 = load i8*, i8** %10
%47 = call i32 @NS_GET16(i32 %45, i8* %46)
%48 = load i32, i32* %7
%49 = load i8*, i8** %10
%50 = call i32 @NS_GET16(i32 %48, i8* %49)
%51 = load i32, i32* %8
%52 = load i8*, i8** %10
%53 = call i32 @NS_GET16(i32 %51, i8* %52)
%54 = load i32, i32* @NS_INT16SZ
%55 = mul i32 3, %54
%56 = load i32, i32* %9
%57 = sub i32 %56, %55
store i32 %57, i32* %9
%58 = load i8*, i8** %10
%59 = call i8* @target_name(i8* %58)
store i8* %59, i8** %11
%60 = load i8*, i8** %11
%61 = load i32, i32* %6
%62 = load i32, i32* %7
%63 = load i32, i32* %8
%64 = call i32 @insert_tuple(i8* %60, i32 %61, i32 %62, i32 %63)
br label %65
65: ; preds = %44, %35
br label %66
66: ; preds = %65, %30
br label %67
67: ; preds = %66
%68 = load i32, i32* %3
%69 = add nsw i32 %68, 1
store i32 %69, i32* %3
br label %16
70: ; preds = %16
ret void
}

LLVM IR (-O2):
@ns_s_an = global i32 0
@.str = [11 x i8] c"ns_parserr\00"
@EXIT_FAILURE = global i32 0
@ns_t_srv = global i64 0
@NS_INT16SZ = global i32 0
define void @parse_answer_section(i32* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* %0
%5 = load i32, i32* @ns_s_an
%6 = tail call i32 @ns_msg_count(i32 %4, i32 %5)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %39
8: ; preds = %1, %36
%9 = phi i32 [ %37, %36 ], [ 0, %1 ]
%10 = load i32, i32* @ns_s_an
%11 = call i64 @ns_parserr(i32* %0, i32 %10, i32 %9, i32* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %8
%18 = load i32, i32* %2
%19 = call i64 @ns_rr_type(i32 %18)
%20 = load i64, i64* @ns_t_srv
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %36
22: ; preds = %17
%23 = load i32, i32* %2
%24 = call i32 @ns_rr_rdlen(i32 %23)
%25 = load i32, i32* %2
%26 = call i8* @ns_rr_rdata(i32 %25)
%27 = load i32, i32* @NS_INT16SZ
%28 = mul i32 %27, 3
%29 = icmp ugt i32 %24, %28
br i1 %29, label %30, label %36
30: ; preds = %22
%31 = call i32 @NS_GET16(i32 undef, i8* %26)
%32 = call i32 @NS_GET16(i32 undef, i8* %26)
%33 = call i32 @NS_GET16(i32 undef, i8* %26)
%34 = call i8* @target_name(i8* %26)
%35 = call i32 @insert_tuple(i8* %34, i32 undef, i32 undef, i32 undef)
br label %36
36: ; preds = %17, %30, %22
%37 = add nuw nsw i32 %9, 1
%38 = icmp eq i32 %37, %6
br i1 %38, label %39, label %8
39: ; preds = %36, %1
ret void
}