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

/* Variables and functions */
int /*<<< orphan*/ dump_dns_rr(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int ns_msg_count(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ ns_parserr(int /*<<< orphan*/ *, int /*<<< orphan*/, int,
                      int /*<<< orphan*/ *);
char *strerror(int /*<<< orphan*/);
void dump_dns_sect(ns_msg *msg, ns_sect sect, FILE *trace,
                   const char *endline) {
  int rrnum, rrmax;
  ns_rr rr;
  fprintf(trace, "||");
  rrmax = ns_msg_count(*msg, sect);
  if (rrmax == 0) {
    fputs("0", trace);
    return;
  }
  fprintf(trace, "%d", rrmax);
  for (rrnum = 0; rrnum < rrmax; rrnum++) {
    if (ns_parserr(msg, sect, rrnum, &rr)) {
      fputs(strerror(errno), trace);
      return;
    }
    fprintf(trace, "||");
    dump_dns_rr(msg, &rr, sect, trace);
  }
}


x86 assembly (clang, -O0):
<dump_dns_sect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%esi
call   1030 <ns_msg_count@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    11b9 <dump_dns_sect+0x59>
mov    -0x18(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1050 <fputs@plt>
jmp    1251 <dump_dns_sect+0xf1>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1251 <dump_dns_sect+0xf1>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    -0x2c(%rbp),%rcx
call   1040 <ns_parserr@plt>
cmp    $0x0,%rax
je     121d <dump_dns_sect+0xbd>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fputs@plt>
jmp    1251 <dump_dns_sect+0xf1>
mov    -0x18(%rbp),%rdi
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    -0x2c(%rbp),%rsi
call   1070 <dump_dns_rr@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d5 <dump_dns_sect+0x75>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_dns_sect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%rbx
lea    0xe65(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
mov    (%rbx),%edi
mov    %r12d,%esi
call   1030 <ns_msg_count@plt>
test   %eax,%eax
je     1239 <dump_dns_sect+0xb9>
mov    %eax,%r15d
lea    0xe3e(%rip),%rsi
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %r15d,%r15d
jle    126d <dump_dns_sect+0xed>
lea    0x4(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
mov    %r13,%rcx
call   1040 <ns_parserr@plt>
test   %rax,%rax
jne    1254 <dump_dns_sect+0xd4>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xdea(%rip),%rdi
mov    %r14,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
mov    %r14,%rcx
call   1080 <dump_dns_rr@plt>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    11f0 <dump_dns_sect+0x70>
jmp    126d <dump_dns_sect+0xed>
mov    $0x30,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fputc@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <fputs@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"||\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [3 x i8] c"%d\00"
@errno = global i32 0
define void @dump_dns_sect(i32* %0, i32 %1, i32* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i8* %3, i8** %8
%12 = load i32*, i32** %7
%13 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = load i32*, i32** %5
%15 = load i32, i32* %14
%16 = load i32, i32* %6
%17 = call i32 @ns_msg_count(i32 %15, i32 %16)
store i32 %17, i32* %10
%18 = load i32, i32* %10
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %4
%21 = load i32*, i32** %7
%22 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32* %21)
br label %52
23: ; preds = %4
%24 = load i32*, i32** %7
%25 = load i32, i32* %10
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %25)
store i32 0, i32* %9
br label %27
27: ; preds = %49, %23
%28 = load i32, i32* %9
%29 = load i32, i32* %10
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %52
31: ; preds = %27
%32 = load i32*, i32** %5
%33 = load i32, i32* %6
%34 = load i32, i32* %9
%35 = call i64 @ns_parserr(i32* %32, i32 %33, i32 %34, i32* %11)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = load i32*, i32** %7
%41 = call i32 @fputs(i8* %39, i32* %40)
br label %52
42: ; preds = %31
%43 = load i32*, i32** %7
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%45 = load i32*, i32** %5
%46 = load i32, i32* %6
%47 = load i32*, i32** %7
%48 = call i32 @dump_dns_rr(i32* %45, i32* %11, i32 %46, i32* %47)
br label %49
49: ; preds = %42
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %27
52: ; preds = %20, %37, %27
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"||\00"
@.str.2 = [3 x i8] c"%d\00"
@errno = global i32 0
define void @dump_dns_sect(i32* %0, i32 %1, i32* %2, i8* nocapture readnone %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2, i64 1, i32* %2)
%8 = load i32, i32* %0
%9 = tail call i32 @ns_msg_count(i32 %8, i32 %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = tail call i32 @fputc(i32 48, i32* %2)
br label %29
13: ; preds = %4
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%15 = icmp sgt i32 %9, 0
br i1 %15, label %16, label %29
16: ; preds = %13, %24
%17 = phi i32 [ %27, %24 ], [ 0, %13 ]
%18 = call i64 @ns_parserr(i32* %0, i32 %1, i32 %17, i32* %5)
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @fputs(i8* %22, i32* %2)
br label %29
24: ; preds = %16
%25 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2, i64 1, i32* %2)
%26 = call i32 @dump_dns_rr(i32* %0, i32* %5, i32 %1, i32* %2)
%27 = add nuw nsw i32 %17, 1
%28 = icmp eq i32 %27, %9
br i1 %28, label %29, label %16
29: ; preds = %24, %13, %20, %11
ret void
}