#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*/ u_char;
typedef scalar_t__ ns_sect;

/* Variables and functions */
int /*<<< orphan*/ EMSGSIZE;
int /*<<< orphan*/ NS_GET16(int, int /*<<< orphan*/ const *);
int NS_INT16SZ;
int NS_INT32SZ;
int dn_skipname(int /*<<< orphan*/ const *, int /*<<< orphan*/ const *);
int /*<<< orphan*/ errno;
scalar_t__ ns_s_qd;
int ns_skiprr(const u_char *ptr, const u_char *eom, ns_sect section,
              int count) {
  const u_char *optr = ptr;
  for ((void)NULL; count > 0; count--) {
    int b, rdlength;
    b = dn_skipname(ptr, eom);
    if (b < 0)
      do {
        errno = (EMSGSIZE);
        return (-1);
      } while (0);
    ptr += b + NS_INT16SZ + NS_INT16SZ;
    if (section != ns_s_qd) {
      if (ptr + NS_INT32SZ + NS_INT16SZ > eom)
        do {
          errno = (EMSGSIZE);
          return (-1);
        } while (0);
      ptr += NS_INT32SZ;
      NS_GET16(rdlength, ptr);
      ptr += rdlength;
    }
  }
  if (ptr > eom)
    do {
      errno = (EMSGSIZE);
      return (-1);
    } while (0);
  return (ptr - optr);
}


x86 assembly (clang, -O0):
<ns_skiprr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    1263 <ns_skiprr+0x143>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <dn_skipname@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1186 <ns_skiprr+0x66>
jmp    1168 <ns_skiprr+0x48>
mov    0x2e71(%rip),%rax
mov    (%rax),%ecx
mov    0x2e50(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    12a6 <ns_skiprr+0x186>
mov    -0x34(%rbp),%ecx
mov    0x2e30(%rip),%rax
add    (%rax),%ecx
mov    0x2e27(%rip),%rax
add    (%rax),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%rax
je     1250 <ns_skiprr+0x130>
mov    -0x10(%rbp),%rax
mov    0x2e1c(%rip),%rcx
movslq (%rcx),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    0x2de3(%rip),%rcx
movslq (%rcx),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
cmp    -0x18(%rbp),%rax
jbe    1214 <ns_skiprr+0xf4>
jmp    11f6 <ns_skiprr+0xd6>
mov    0x2de3(%rip),%rax
mov    (%rax),%ecx
mov    0x2dc2(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    12a6 <ns_skiprr+0x186>
mov    0x2dcd(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <NS_GET16@plt>
mov    -0x38(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1255 <ns_skiprr+0x135>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    113f <ns_skiprr+0x1f>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1294 <ns_skiprr+0x174>
jmp    1276 <ns_skiprr+0x156>
mov    0x2d63(%rip),%rax
mov    (%rax),%ecx
mov    0x2d42(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    12a6 <ns_skiprr+0x186>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ns_skiprr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdi,(%rsp)
test   %ecx,%ecx
jle    11aa <ns_skiprr+0x8a>
mov    %ecx,%ebp
mov    %rdx,%r12
add    $0x1,%ebp
mov    0x2e78(%rip),%r13
mov    0x2e89(%rip),%r14
mov    (%rsp),%rbx
jmp    1170 <ns_skiprr+0x50>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rsi
call   1040 <NS_GET16@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jle    11aa <ns_skiprr+0x8a>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <dn_skipname@plt>
test   %eax,%eax
js     11af <ns_skiprr+0x8f>
movslq 0x0(%r13),%rcx
lea    (%rax,%rcx,2),%eax
cltq
lea    (%rbx,%rax,4),%rbx
cmp    %r12,(%r14)
je     1168 <ns_skiprr+0x48>
mov    0x2e50(%rip),%rax
movslq (%rax),%rax
lea    (%rbx,%rax,4),%rbx
lea    (%rbx,%rcx,4),%rax
cmp    %r15,%rax
jbe    1160 <ns_skiprr+0x40>
jmp    11af <ns_skiprr+0x8f>
cmp    %r15,%rbx
jbe    11c8 <ns_skiprr+0xa8>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    0x2e09(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebx
jmp    11d0 <ns_skiprr+0xb0>
sub    (%rsp),%rbx
shr    $0x2,%rbx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EMSGSIZE = global i32 0
@errno = global i32 0
@NS_INT16SZ = global i32 0
@ns_s_qd = global i64 0
@NS_INT32SZ = global i32 0
define i32 @ns_skiprr(i32* %0, i32* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
%13 = load i32*, i32** %6
store i32* %13, i32** %10
br label %14
14: ; preds = %66, %4
%15 = load i32, i32* %9
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %69
17: ; preds = %14
%18 = load i32*, i32** %6
%19 = load i32*, i32** %7
%20 = call i32 @dn_skipname(i32* %18, i32* %19)
store i32 %20, i32* %11
%21 = load i32, i32* %11
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %17
br label %24
24: ; preds = %23
%25 = load i32, i32* @EMSGSIZE
store i32 %25, i32* @errno
store i32 -1, i32* %5
br label %85
26: ; No predecessors!
br label %27
27: ; preds = %26, %17
%28 = load i32, i32* %11
%29 = load i32, i32* @NS_INT16SZ
%30 = add nsw i32 %28, %29
%31 = load i32, i32* @NS_INT16SZ
%32 = add nsw i32 %30, %31
%33 = load i32*, i32** %6
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i32, i32* %33, i64 %34
store i32* %35, i32** %6
%36 = load i64, i64* %8
%37 = load i64, i64* @ns_s_qd
%38 = icmp ne i64 %36, %37
br i1 %38, label %39, label %65
39: ; preds = %27
%40 = load i32*, i32** %6
%41 = load i32, i32* @NS_INT32SZ
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* @NS_INT16SZ
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32*, i32** %7
%48 = icmp ugt i32* %46, %47
br i1 %48, label %49, label %53
49: ; preds = %39
br label %50
50: ; preds = %49
%51 = load i32, i32* @EMSGSIZE
store i32 %51, i32* @errno
store i32 -1, i32* %5
br label %85
52: ; No predecessors!
br label %53
53: ; preds = %52, %39
%54 = load i32, i32* @NS_INT32SZ
%55 = load i32*, i32** %6
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds i32, i32* %55, i64 %56
store i32* %57, i32** %6
%58 = load i32, i32* %12
%59 = load i32*, i32** %6
%60 = call i32 @NS_GET16(i32 %58, i32* %59)
%61 = load i32, i32* %12
%62 = load i32*, i32** %6
%63 = sext i32 %61 to i64
%64 = getelementptr inbounds i32, i32* %62, i64 %63
store i32* %64, i32** %6
br label %65
65: ; preds = %53, %27
br label %66
66: ; preds = %65
%67 = load i32, i32* %9
%68 = add nsw i32 %67, -1
store i32 %68, i32* %9
br label %14
69: ; preds = %14
%70 = load i32*, i32** %6
%71 = load i32*, i32** %7
%72 = icmp ugt i32* %70, %71
br i1 %72, label %73, label %77
73: ; preds = %69
br label %74
74: ; preds = %73
%75 = load i32, i32* @EMSGSIZE
store i32 %75, i32* @errno
store i32 -1, i32* %5
br label %85
76: ; No predecessors!
br label %77
77: ; preds = %76, %69
%78 = load i32*, i32** %6
%79 = load i32*, i32** %10
%80 = ptrtoint i32* %78 to i64
%81 = ptrtoint i32* %79 to i64
%82 = sub i64 %80, %81
%83 = sdiv exact i64 %82, 4
%84 = trunc i64 %83 to i32
store i32 %84, i32* %5
br label %85
85: ; preds = %77, %74, %50, %24
%86 = load i32, i32* %5
ret i32 %86
}

LLVM IR (-O2):
@EMSGSIZE = global i32 0
@errno = global i32 0
@NS_INT16SZ = global i32 0
@ns_s_qd = global i64 0
@NS_INT32SZ = global i32 0
define i32 @ns_skiprr(i32* %0, i32* %1, i64 %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %36
6: ; preds = %4, %32
%7 = phi i32* [ %33, %32 ], [ %0, %4 ]
%8 = phi i32 [ %34, %32 ], [ %3, %4 ]
%9 = tail call i32 @dn_skipname(i32* %7, i32* %1)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = load i32, i32* @EMSGSIZE
store i32 %12, i32* @errno
br label %47
13: ; preds = %6
%14 = load i32, i32* @NS_INT16SZ
%15 = shl i32 %14, 1
%16 = add i32 %15, %9
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %7, i64 %17
%19 = load i64, i64* @ns_s_qd
%20 = icmp eq i64 %19, %2
br i1 %20, label %32, label %21
21: ; preds = %13
%22 = load i32, i32* @NS_INT32SZ
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %18, i64 %23
%25 = sext i32 %14 to i64
%26 = getelementptr inbounds i32, i32* %24, i64 %25
%27 = icmp ugt i32* %26, %1
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = load i32, i32* @EMSGSIZE
store i32 %29, i32* @errno
br label %47
30: ; preds = %21
%31 = tail call i32 @NS_GET16(i32 undef, i32* %24)
br label %32
32: ; preds = %30, %13
%33 = phi i32* [ %18, %13 ], [ %24, %30 ]
%34 = add nsw i32 %8, -1
%35 = icmp sgt i32 %8, 1
br i1 %35, label %6, label %36
36: ; preds = %32, %4
%37 = phi i32* [ %0, %4 ], [ %33, %32 ]
%38 = icmp ugt i32* %37, %1
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = load i32, i32* @EMSGSIZE
store i32 %40, i32* @errno
br label %47
41: ; preds = %36
%42 = ptrtoint i32* %37 to i64
%43 = ptrtoint i32* %0 to i64
%44 = sub i64 %42, %43
%45 = lshr exact i64 %44, 2
%46 = trunc i64 %45 to i32
br label %47
47: ; preds = %11, %28, %41, %39
%48 = phi i32 [ -1, %39 ], [ %46, %41 ], [ -1, %28 ], [ -1, %11 ]
ret i32 %48
}