#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 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 & 0xc0) {
    case 0:
      cp += n;
      continue;
    case 0x40:
      if ((l = labellen(cp - 1)) < 0) {
        return -1;
      }
      cp += l;
      continue;
    case 0xc0:
      cp++;
      break;
    default:
      return -1;
    }
    break;
  }
  if (cp > eom) {
    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    1220 <ns_name_skip+0x110>
mov    -0x24(%rbp),%eax
and    $0xc0,%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    $0xc0,%eax
je     11fe <ns_name_skip+0xee>
jmp    120f <ns_name_skip+0xff>
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    11e4 <ns_name_skip+0xd4>
movl   $0xffffffff,-0x4(%rbp)
jmp    124c <ns_name_skip+0x13c>
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    121b <ns_name_skip+0x10b>
movl   $0xffffffff,-0x4(%rbp)
jmp    124c <ns_name_skip+0x13c>
jmp    1220 <ns_name_skip+0x110>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    123a <ns_name_skip+0x12a>
movl   $0xffffffff,-0x4(%rbp)
jmp    124c <ns_name_skip+0x13c>
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>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%rdi
cmp    %rsi,%rdi
jae    116c <ns_name_skip+0x5c>
mov    $0xffffffff,%ebp
jmp    1139 <ns_name_skip+0x29>
nopl   0x0(%rax)
lea    (%rbx,%rax,4),%rdi
cmp    %r15,%rdi
jae    116c <ns_name_skip+0x5c>
lea    0x4(%rdi),%rbx
movslq (%rdi),%rax
test   %rax,%rax
je     115e <ns_name_skip+0x4e>
mov    %eax,%ecx
and    $0xc0,%cl
je     1130 <ns_name_skip+0x20>
cmp    $0x40,%cl
jne    1163 <ns_name_skip+0x53>
call   1030 <labellen@plt>
test   %eax,%eax
js     117b <ns_name_skip+0x6b>
mov    %eax,%eax
jmp    1130 <ns_name_skip+0x20>
mov    %rbx,%rdi
jmp    116c <ns_name_skip+0x5c>
cmp    $0xc0,%cl
jne    117b <ns_name_skip+0x6b>
add    $0x8,%rdi
mov    $0xffffffff,%ebp
cmp    %r15,%rdi
ja     117b <ns_name_skip+0x6b>
mov    %rdi,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
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 = %36, %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 %46
22: ; preds = %20
%23 = load i32, i32* %7
%24 = and i32 %23, 192
switch i32 %24, label %44 [
i32 0, label %25
i32 64, label %30
i32 192, label %41
]
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 %36
35: ; preds = %30
store i32 -1, i32* %3
br label %54
36: ; preds = %30
%37 = load i32, i32* %8
%38 = load i32*, i32** %6
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i32, i32* %38, i64 %39
store i32* %40, i32** %6
br label %11
41: ; preds = %22
%42 = load i32*, i32** %6
%43 = getelementptr inbounds i32, i32* %42, i32 1
store i32* %43, i32** %6
br label %45
44: ; preds = %22
store i32 -1, i32* %3
br label %54
45: ; preds = %41
br label %46
46: ; preds = %45, %20
%47 = load i32*, i32** %6
%48 = load i32*, i32** %5
%49 = icmp ugt i32* %47, %48
br i1 %49, label %50, label %51
50: ; preds = %46
store i32 -1, i32* %3
br label %54
51: ; preds = %46
%52 = load i32*, i32** %6
%53 = load i32**, i32*** %4
store i32* %52, i32** %53
store i32 0, i32* %3
br label %54
54: ; preds = %51, %50, %44, %35
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
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 %26
5: ; preds = %2, %15
%6 = phi i32* [ %17, %15 ], [ %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 %26, label %10
10: ; preds = %5
%11 = trunc i32 %8 to i8
%12 = and i8 %11, -64
switch i8 %12, label %30 [
i8 0, label %13
i8 64, label %19
i8 -64, label %24
]
13: ; preds = %10
%14 = sext i32 %8 to i64
br label %15
15: ; preds = %13, %22
%16 = phi i64 [ %23, %22 ], [ %14, %13 ]
%17 = getelementptr inbounds i32, i32* %7, i64 %16
%18 = icmp ult i32* %17, %1
br i1 %18, label %5, label %26
19: ; preds = %10
%20 = tail call i32 @labellen(i32* %6)
%21 = icmp slt i32 %20, 0
br i1 %21, label %30, label %22
22: ; preds = %19
%23 = zext i32 %20 to i64
br label %15
24: ; preds = %10
%25 = getelementptr inbounds i32, i32* %6, i64 2
br label %26
26: ; preds = %5, %15, %2, %24
%27 = phi i32* [ %25, %24 ], [ %3, %2 ], [ %7, %5 ], [ %17, %15 ]
%28 = icmp ugt i32* %27, %1
br i1 %28, label %30, label %29
29: ; preds = %26
store i32* %27, i32** %0
br label %30
30: ; preds = %10, %19, %26, %29
%31 = phi i32 [ 0, %29 ], [ -1, %26 ], [ -1, %19 ], [ -1, %10 ]
ret i32 %31
}