#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*/ __set_errno(int /*<<< orphan*/);
int ns_name_skip(const u_char **ptrptr, const u_char *eom) {
  const u_char *cp;
  u_int n;
  cp = *ptrptr;
  while (cp < eom && (n = *cp++) != 0) {
    switch (n & NS_CMPRSFLGS) {
    case 0:
      cp += n;
      continue;
    case NS_CMPRSFLGS:
      cp++;
      break;
    default:
      __set_errno(EMSGSIZE);
      return (-1);
    }
    break;
  }
  if (cp > eom) {
    __set_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,-0x25(%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,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    116b <ns_name_skip+0x5b>
jmp    11de <ns_name_skip+0xce>
mov    -0x24(%rbp),%eax
and    $0x80,%eax
mov    %eax,-0x2c(%rbp)
je     1194 <ns_name_skip+0x84>
jmp    1181 <ns_name_skip+0x71>
mov    -0x2c(%rbp),%eax
sub    $0x80,%eax
je     11ae <ns_name_skip+0x9e>
jmp    11bf <ns_name_skip+0xaf>
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),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
jmp    11d9 <ns_name_skip+0xc9>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <ns_name_skip+0x108>
jmp    11de <ns_name_skip+0xce>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1206 <ns_name_skip+0xf6>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <ns_name_skip+0x108>
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   %rax
mov    (%rdi),%rax
cmp    %rsi,%rax
jae    113f <ns_name_skip+0x2f>
nopl   0x0(%rax)
lea    0x4(%rax),%rcx
movslq (%rax),%rdx
test   %rdx,%rdx
je     113c <ns_name_skip+0x2c>
test   $0x80,%dl
jne    1159 <ns_name_skip+0x49>
lea    (%rcx,%rdx,4),%rax
cmp    %rsi,%rax
jb     1120 <ns_name_skip+0x10>
jmp    113f <ns_name_skip+0x2f>
mov    %rcx,%rax
cmp    %rsi,%rax
jbe    1162 <ns_name_skip+0x52>
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
add    $0x8,%rax
cmp    %rsi,%rax
ja     1144 <ns_name_skip+0x34>
mov    %rax,(%rdi)
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@EMSGSIZE = 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
store i32** %0, i32*** %4
store i32* %1, i32** %5
%8 = load i32**, i32*** %4
%9 = load i32*, i32** %8
store i32* %9, i32** %6
br label %10
10: ; preds = %24, %2
%11 = load i32*, i32** %6
%12 = load i32*, i32** %5
%13 = icmp ult i32* %11, %12
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i32*, i32** %6
%16 = getelementptr inbounds i32, i32* %15, i32 1
store i32* %16, i32** %6
%17 = load i32, i32* %15
store i32 %17, i32* %7
%18 = icmp ne i32 %17, 0
br label %19
19: ; preds = %14, %10
%20 = phi i1 [ false, %10 ], [ %18, %14 ]
br i1 %20, label %21, label %36
21: ; preds = %19
%22 = load i32, i32* %7
%23 = and i32 %22, 128
switch i32 %23, label %32 [
i32 0, label %24
i32 128, label %29
]
24: ; preds = %21
%25 = load i32, i32* %7
%26 = load i32*, i32** %6
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i32, i32* %26, i64 %27
store i32* %28, i32** %6
br label %10
29: ; preds = %21
%30 = load i32*, i32** %6
%31 = getelementptr inbounds i32, i32* %30, i32 1
store i32* %31, i32** %6
br label %35
32: ; preds = %21
%33 = load i32, i32* @EMSGSIZE
%34 = call i32 @__set_errno(i32 %33)
store i32 -1, i32* %3
br label %46
35: ; preds = %29
br label %36
36: ; preds = %35, %19
%37 = load i32*, i32** %6
%38 = load i32*, i32** %5
%39 = icmp ugt i32* %37, %38
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* @EMSGSIZE
%42 = call i32 @__set_errno(i32 %41)
store i32 -1, i32* %3
br label %46
43: ; preds = %36
%44 = load i32*, i32** %6
%45 = load i32**, i32*** %4
store i32* %44, i32** %45
store i32 0, i32* %3
br label %46
46: ; preds = %43, %40, %32
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@EMSGSIZE = 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 %25
22: ; preds = %19
%23 = load i32, i32* @EMSGSIZE
%24 = tail call i32 @__set_errno(i32 %23)
br label %26
25: ; preds = %19
store i32* %20, i32** %0
br label %26
26: ; preds = %25, %22
%27 = phi i32 [ -1, %22 ], [ 0, %25 ]
ret i32 %27
}