#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 u_int;
typedef int /*<<< orphan*/ u_char;

/* Variables and functions */
int /*<<< orphan*/ EMSGSIZE;
#define NS_CMPRSFLGS 128
int /*<<< orphan*/ errno;
int labellen(int /*<<< orphan*/ const *);
int ns_name_skip(const u_char **ptrptr, const u_char *eom) {
  const u_char *cp;
  u_int n;
  int l;
  cp = *ptrptr;
  while (cp < eom && (n = *cp++) != 0) {
    switch (n & NS_CMPRSFLGS) {
    case 0:
      cp += n;
      continue;
    case 0x40:
      if ((l = labellen(cp - 1)) < 0) {
        errno = EMSGSIZE;
        return (-1);
      }
      cp += l;
      continue;
    case NS_CMPRSFLGS:
      cp++;
      break;
    default:
      errno = EMSGSIZE;
      return (-1);
    }
    break;
  }
  if (cp > eom) {
    errno = EMSGSIZE;
    return (-1);
  }
  *ptrptr = cp;
  return (0);
}


x86 assembly (clang, -O0):
<ns_name_skip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x29(%rbp)
jae    115b <ns_name_skip+0x4b>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    116b <ns_name_skip+0x5b>
jmp    1244 <ns_name_skip+0x134>
mov    -0x24(%rbp),%eax
and    $0x80,%eax
mov    %eax,-0x30(%rbp)
je     11a5 <ns_name_skip+0x95>
jmp    1181 <ns_name_skip+0x71>
mov    -0x30(%rbp),%eax
sub    $0x40,%eax
je     11bf <ns_name_skip+0xaf>
jmp    1192 <ns_name_skip+0x82>
mov    -0x30(%rbp),%eax
sub    $0x80,%eax
je     1210 <ns_name_skip+0x100>
jmp    1221 <ns_name_skip+0x111>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    112b <ns_name_skip+0x1b>
mov    -0x20(%rbp),%rdi
add    $0xfffffffffffffffc,%rdi
call   1030 <labellen@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    11f6 <ns_name_skip+0xe6>
mov    0x2e09(%rip),%rax
mov    (%rax),%ecx
mov    0x2df0(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <ns_name_skip+0x172>
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    112b <ns_name_skip+0x1b>
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
jmp    123f <ns_name_skip+0x12f>
mov    0x2dc0(%rip),%rax
mov    (%rax),%ecx
mov    0x2da7(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <ns_name_skip+0x172>
jmp    1244 <ns_name_skip+0x134>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1270 <ns_name_skip+0x160>
mov    0x2d8f(%rip),%rax
mov    (%rax),%ecx
mov    0x2d76(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <ns_name_skip+0x172>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ns_name_skip>:
mov    (%rdi),%rax
cmp    %rsi,%rax
jae    112f <ns_name_skip+0x2f>
nopl   0x0(%rax,%rax,1)
lea    0x4(%rax),%rcx
movslq (%rax),%rdx
test   %rdx,%rdx
je     112c <ns_name_skip+0x2c>
test   $0x80,%dl
jne    114c <ns_name_skip+0x4c>
lea    (%rcx,%rdx,4),%rax
cmp    %rsi,%rax
jb     1110 <ns_name_skip+0x10>
jmp    112f <ns_name_skip+0x2f>
mov    %rcx,%rax
cmp    %rsi,%rax
jbe    1155 <ns_name_skip+0x55>
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    0x2e94(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret
add    $0x8,%rax
cmp    %rsi,%rax
ja     1134 <ns_name_skip+0x34>
mov    %rax,(%rdi)
xor    %eax,%eax
ret

LLVM IR (-O0):
@EMSGSIZE = global i32 0
@errno = global i32 0
define i32 @ns_name_skip(i32** %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32** %0, i32*** %4
store i32* %1, i32** %5
%9 = load i32**, i32*** %4
%10 = load i32*, i32** %9
store i32* %10, i32** %6
br label %11
11: ; preds = %37, %25, %2
%12 = load i32*, i32** %6
%13 = load i32*, i32** %5
%14 = icmp ult i32* %12, %13
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i32*, i32** %6
%17 = getelementptr inbounds i32, i32* %16, i32 1
store i32* %17, i32** %6
%18 = load i32, i32* %16
store i32 %18, i32* %7
%19 = icmp ne i32 %18, 0
br label %20
20: ; preds = %15, %11
%21 = phi i1 [ false, %11 ], [ %19, %15 ]
br i1 %21, label %22, label %48
22: ; preds = %20
%23 = load i32, i32* %7
%24 = and i32 %23, 128
switch i32 %24, label %45 [
i32 0, label %25
i32 64, label %30
i32 128, label %42
]
25: ; preds = %22
%26 = load i32, i32* %7
%27 = load i32*, i32** %6
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i32, i32* %27, i64 %28
store i32* %29, i32** %6
br label %11
30: ; preds = %22
%31 = load i32*, i32** %6
%32 = getelementptr inbounds i32, i32* %31, i64 -1
%33 = call i32 @labellen(i32* %32)
store i32 %33, i32* %8
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = load i32, i32* @EMSGSIZE
store i32 %36, i32* @errno
store i32 -1, i32* %3
br label %57
37: ; preds = %30
%38 = load i32, i32* %8
%39 = load i32*, i32** %6
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i32, i32* %39, i64 %40
store i32* %41, i32** %6
br label %11
42: ; preds = %22
%43 = load i32*, i32** %6
%44 = getelementptr inbounds i32, i32* %43, i32 1
store i32* %44, i32** %6
br label %47
45: ; preds = %22
%46 = load i32, i32* @EMSGSIZE
store i32 %46, i32* @errno
store i32 -1, i32* %3
br label %57
47: ; preds = %42
br label %48
48: ; preds = %47, %20
%49 = load i32*, i32** %6
%50 = load i32*, i32** %5
%51 = icmp ugt i32* %49, %50
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = load i32, i32* @EMSGSIZE
store i32 %53, i32* @errno
store i32 -1, i32* %3
br label %57
54: ; preds = %48
%55 = load i32*, i32** %6
%56 = load i32**, i32*** %4
store i32* %55, i32** %56
store i32 0, i32* %3
br label %57
57: ; preds = %54, %52, %45, %35
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@EMSGSIZE = global i32 0
@errno = global i32 0
define i32 @ns_name_skip(i32** nocapture %0, i32* readnone %1) {
%3 = load i32*, i32** %0
%4 = icmp ult i32* %3, %1
br i1 %4, label %5, label %19
5: ; preds = %2, %13
%6 = phi i32* [ %15, %13 ], [ %3, %2 ]
%7 = getelementptr inbounds i32, i32* %6, i64 1
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %5
%11 = and i32 %8, 128
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = sext i32 %8 to i64
%15 = getelementptr inbounds i32, i32* %7, i64 %14
%16 = icmp ult i32* %15, %1
br i1 %16, label %5, label %19
17: ; preds = %10
%18 = getelementptr inbounds i32, i32* %6, i64 2
br label %19
19: ; preds = %5, %13, %2, %17
%20 = phi i32* [ %18, %17 ], [ %3, %2 ], [ %7, %5 ], [ %15, %13 ]
%21 = icmp ugt i32* %20, %1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i32, i32* @EMSGSIZE
store i32 %23, i32* @errno
br label %25
24: ; preds = %19
store i32* %20, i32** %0
br label %25
25: ; preds = %24, %22
%26 = phi i32 [ -1, %22 ], [ 0, %24 ]
ret i32 %26
}