#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 __dns_get_rr(int /*<<< orphan*/, int /*<<< orphan*/, int const, int,
                 unsigned char const *, int const, int /*<<< orphan*/);
int __dns_count_addrs(const unsigned char *r, int cnt) {
  int found = 0, res, i;
  static const int p[2][2] = {{4, 1}, {16, 28}};
  while (cnt--) {
    for (i = 0; i < 2; i++) {
      res = __dns_get_rr(0, 0, p[i][0], -1, r, p[i][1], 0);
      if (res < 0)
        return res;
      found += res;
    }
    r += 512;
  }
  return found;
}


x86 assembly (clang, -O0):
<__dns_count_addrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     11c4 <__dns_count_addrs+0xb4>
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
jge    11b1 <__dns_count_addrs+0xa1>
movslq -0x20(%rbp),%rcx
lea    0xeaa(%rip),%rax
mov    (%rax,%rcx,8),%edx
mov    -0x10(%rbp),%r8
movslq -0x20(%rbp),%rcx
lea    0xe98(%rip),%rax
mov    0x4(%rax,%rcx,8),%r9d
xor    %esi,%esi
mov    $0xffffffff,%ecx
mov    %esi,%edi
movl   $0x0,(%rsp)
call   1030 <__dns_get_rr@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    119a <__dns_count_addrs+0x8a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ca <__dns_count_addrs+0xba>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1141 <__dns_count_addrs+0x31>
mov    -0x10(%rbp),%rax
add    $0x200,%rax
mov    %rax,-0x10(%rbp)
jmp    1126 <__dns_count_addrs+0x16>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__dns_count_addrs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     1196 <__dns_count_addrs+0x86>
mov    %esi,%r14d
mov    %rdi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movl   $0x0,(%rsp)
xor    %edi,%edi
xor    %esi,%esi
mov    $0x4,%edx
mov    $0xffffffff,%ecx
mov    %r15,%r8
mov    $0x1,%r9d
call   1030 <__dns_get_rr@plt>
mov    %eax,%ebp
test   %eax,%eax
js     119a <__dns_count_addrs+0x8a>
movl   $0x0,(%rsp)
xor    %edi,%edi
xor    %esi,%esi
mov    $0x10,%edx
mov    $0xffffffff,%ecx
mov    %r15,%r8
mov    $0x1c,%r9d
call   1030 <__dns_get_rr@plt>
test   %eax,%eax
js     119e <__dns_count_addrs+0x8e>
add    $0xffffffff,%r14d
add    %ebp,%ebx
add    %eax,%ebx
add    $0x200,%r15
test   %r14d,%r14d
jne    1130 <__dns_count_addrs+0x20>
jmp    11a0 <__dns_count_addrs+0x90>
xor    %ebx,%ebx
jmp    11a0 <__dns_count_addrs+0x90>
mov    %ebp,%ebx
jmp    11a0 <__dns_count_addrs+0x90>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__dns_count_addrs.p = internal constant [2 x [2 x i32]] [[2 x i32] [i32 4, i32 1], [2 x i32] [i32 16, i32 28]]
define i32 @__dns_count_addrs(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
br label %9
9: ; preds = %41, %2
%10 = load i32, i32* %5
%11 = add nsw i32 %10, -1
store i32 %11, i32* %5
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %44
13: ; preds = %9
store i32 0, i32* %8
br label %14
14: ; preds = %38, %13
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %41
17: ; preds = %14
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* @__dns_count_addrs.p, i64 0, i64 %19
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 0
%22 = load i32, i32* %21
%23 = load i8*, i8** %4
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* @__dns_count_addrs.p, i64 0, i64 %25
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %26, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @__dns_get_rr(i32 0, i32 0, i32 %22, i32 -1, i8* %23, i32 %28, i32 0)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %17
%33 = load i32, i32* %7
store i32 %33, i32* %3
br label %46
34: ; preds = %17
%35 = load i32, i32* %7
%36 = load i32, i32* %6
%37 = add nsw i32 %36, %35
store i32 %37, i32* %6
br label %38
38: ; preds = %34
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %14
41: ; preds = %14
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i64 512
store i8* %43, i8** %4
br label %9
44: ; preds = %9
%45 = load i32, i32* %6
store i32 %45, i32* %3
br label %46
46: ; preds = %44, %32
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
define i32 @__dns_count_addrs(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %19, label %4
4: ; preds = %2, %14
%5 = phi i32 [ %8, %14 ], [ %1, %2 ]
%6 = phi i32 [ %16, %14 ], [ 0, %2 ]
%7 = phi i8* [ %17, %14 ], [ %0, %2 ]
%8 = add nsw i32 %5, -1
%9 = tail call i32 @__dns_get_rr(i32 0, i32 0, i32 4, i32 -1, i8* %7, i32 1, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %4
%12 = tail call i32 @__dns_get_rr(i32 0, i32 0, i32 16, i32 -1, i8* %7, i32 28, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = add nsw i32 %9, %6
%16 = add nsw i32 %12, %15
%17 = getelementptr inbounds i8, i8* %7, i64 512
%18 = icmp eq i32 %8, 0
br i1 %18, label %19, label %4
19: ; preds = %14, %4, %11, %2
%20 = phi i32 [ 0, %2 ], [ %16, %14 ], [ %12, %11 ], [ %9, %4 ]
ret i32 %20
}