#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 */
unsigned char NS_CMPRSFLGS;
int local_ns_labellen(const unsigned char *lp) {
  int bitlen;
  unsigned char l = *lp;
  if ((l & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
    return -1;
  }
  if ((l & NS_CMPRSFLGS) == 0x40) {
    if (l == 0x41) {
      if ((bitlen = *(lp + 1)) == 0)
        bitlen = 256;
      return ((bitlen + 7) / 8 + 1);
    }
    return -1;
  }
  return l;
}


x86 assembly (clang, -O0):
<local_ns_labellen>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
mov    0x2ec4(%rip),%rcx
movzbl (%rcx),%ecx
and    %ecx,%eax
mov    0x2eb8(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jne    113f <local_ns_labellen+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <local_ns_labellen+0xac>
movzbl -0x15(%rbp),%eax
mov    0x2e96(%rip),%rcx
movzbl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x40,%eax
jne    11a5 <local_ns_labellen+0xa5>
movzbl -0x15(%rbp),%eax
cmp    $0x41,%eax
jne    1199 <local_ns_labellen+0x99>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1180 <local_ns_labellen+0x80>
movl   $0x100,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x7,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <local_ns_labellen+0xac>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <local_ns_labellen+0xac>
movzbl -0x15(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<local_ns_labellen>:
movzbl (%rdi),%esi
mov    0x2ed6(%rip),%rax
mov    (%rax),%cl
mov    %ecx,%edx
and    %sil,%dl
mov    $0xffffffff,%eax
cmp    %cl,%dl
je     113c <local_ns_labellen+0x3c>
cmp    $0x40,%dl
jne    113d <local_ns_labellen+0x3d>
cmp    $0x41,%sil
jne    113c <local_ns_labellen+0x3c>
movzbl 0x1(%rdi),%eax
lea    0x7(%rax),%ecx
shr    $0x3,%ecx
add    $0x1,%ecx
test   %eax,%eax
mov    $0x21,%eax
cmovne %ecx,%eax
ret
mov    %esi,%eax
ret

LLVM IR (-O0):
@NS_CMPRSFLGS = global i8 0
define i32 @local_ns_labellen(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
store i8 %7, i8* %5
%8 = load i8, i8* %5
%9 = zext i8 %8 to i32
%10 = load i8, i8* @NS_CMPRSFLGS
%11 = zext i8 %10 to i32
%12 = and i32 %9, %11
%13 = load i8, i8* @NS_CMPRSFLGS
%14 = zext i8 %13 to i32
%15 = icmp eq i32 %12, %14
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 -1, i32* %2
br label %44
17: ; preds = %1
%18 = load i8, i8* %5
%19 = zext i8 %18 to i32
%20 = load i8, i8* @NS_CMPRSFLGS
%21 = zext i8 %20 to i32
%22 = and i32 %19, %21
%23 = icmp eq i32 %22, 64
br i1 %23, label %24, label %41
24: ; preds = %17
%25 = load i8, i8* %5
%26 = zext i8 %25 to i32
%27 = icmp eq i32 %26, 65
br i1 %27, label %28, label %40
28: ; preds = %24
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
store i32 %32, i32* %4
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 256, i32* %4
br label %35
35: ; preds = %34, %28
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 7
%38 = sdiv i32 %37, 8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %2
br label %44
40: ; preds = %24
store i32 -1, i32* %2
br label %44
41: ; preds = %17
%42 = load i8, i8* %5
%43 = zext i8 %42 to i32
store i32 %43, i32* %2
br label %44
44: ; preds = %41, %40, %35, %16
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@NS_CMPRSFLGS = global i8 0
define i32 @local_ns_labellen(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = load i8, i8* @NS_CMPRSFLGS
%4 = and i8 %3, %2
%5 = icmp eq i8 %4, %3
br i1 %5, label %20, label %6
6: ; preds = %1
%7 = zext i8 %2 to i32
%8 = icmp eq i8 %4, 64
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = icmp eq i8 %2, 65
br i1 %10, label %11, label %20
11: ; preds = %9
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = icmp eq i8 %13, 0
%16 = add nuw nsw i32 %14, 7
%17 = lshr i32 %16, 3
%18 = add nuw nsw i32 %17, 1
%19 = select i1 %15, i32 33, i32 %18
br label %20
20: ; preds = %6, %9, %1, %11
%21 = phi i32 [ %19, %11 ], [ -1, %1 ], [ -1, %9 ], [ %7, %6 ]
ret i32 %21
}