#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*/ uint32_t;
typedef scalar_t__ uint16_t;

/* Variables and functions */
char *_dns_skip_qname(char const *);
scalar_t__ ntohs(scalar_t__);
const char *_dns_skip_resources(uint16_t count, const char *p) {
  uint16_t i;
  for (i = 0; i < count; i++) {
    p = _dns_skip_qname(p);
    p += sizeof(uint16_t);
    p += sizeof(uint16_t);
    p += sizeof(uint32_t);
    uint16_t rdlength = ntohs(*(uint16_t *)p);
    p += sizeof(uint16_t) + rdlength;
  }
  return p;
}


x86 assembly (clang, -O0):
<_dns_skip_resources>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11a8 <_dns_skip_resources+0x88>
mov    -0x10(%rbp),%rdi
call   1030 <_dns_skip_qname@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <ntohs@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <_dns_skip_resources+0x18>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_dns_skip_resources>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
test   %rdi,%rdi
jle    1151 <_dns_skip_resources+0x31>
mov    %rdi,%rbx
nop
mov    %rax,%rdi
call   1030 <_dns_skip_qname@plt>
mov    %rax,%r14
mov    0x14(%rax),%rdi
call   1040 <ntohs@plt>
add    %r14,%rax
add    $0x1c,%rax
add    $0xffffffffffffffff,%rbx
jne    1130 <_dns_skip_resources+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @_dns_skip_resources(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %3
store i8* %1, i8** %4
store i64 0, i64* %5
br label %7
7: ; preds = %28, %2
%8 = load i64, i64* %5
%9 = load i64, i64* %3
%10 = icmp slt i64 %8, %9
br i1 %10, label %11, label %31
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = call i8* @_dns_skip_qname(i8* %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 8
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 8
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 4
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = bitcast i8* %20 to i64*
%22 = load i64, i64* %21
%23 = call i64 @ntohs(i64 %22)
store i64 %23, i64* %6
%24 = load i64, i64* %6
%25 = add i64 8, %24
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 %25
store i8* %27, i8** %4
br label %28
28: ; preds = %11
%29 = load i64, i64* %5
%30 = add nsw i64 %29, 1
store i64 %30, i64* %5
br label %7
31: ; preds = %7
%32 = load i8*, i8** %4
ret i8* %32
}

LLVM IR (-O2):
define i8* @_dns_skip_resources(i64 %0, i8* %1) {
%3 = icmp sgt i64 %0, 0
br i1 %3, label %4, label %16
4: ; preds = %2, %4
%5 = phi i8* [ %13, %4 ], [ %1, %2 ]
%6 = phi i64 [ %14, %4 ], [ 0, %2 ]
%7 = tail call i8* @_dns_skip_qname(i8* %5)
%8 = getelementptr inbounds i8, i8* %7, i64 20
%9 = bitcast i8* %8 to i64*
%10 = load i64, i64* %9
%11 = tail call i64 @ntohs(i64 %10)
%12 = add i64 %11, 8
%13 = getelementptr inbounds i8, i8* %8, i64 %12
%14 = add nuw nsw i64 %6, 1
%15 = icmp eq i64 %14, %0
br i1 %15, label %16, label %4
16: ; preds = %4, %2
%17 = phi i8* [ %1, %2 ], [ %13, %4 ]
ret i8* %17
}