#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_char;

/* Variables and functions */
int NS_CMPRSFLGS;
int labellen(const u_char *lp) {
  int bitlen;
  u_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):
<labellen>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2ec5(%rip),%rcx
and    (%rcx),%eax
mov    0x2ebc(%rip),%rcx
cmp    (%rcx),%eax
jne    1138 <labellen+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <labellen+0x9c>
mov    -0x18(%rbp),%eax
mov    0x2e9e(%rip),%rcx
and    (%rcx),%eax
cmp    $0x40,%eax
jne    1196 <labellen+0x96>
cmpl   $0x41,-0x18(%rbp)
jne    118a <labellen+0x8a>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1171 <labellen+0x71>
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    119c <labellen+0x9c>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <labellen+0x9c>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<labellen>:
mov    (%rdi),%ecx
mov    0x2ed7(%rip),%rax
mov    (%rax),%esi
mov    %esi,%edx
and    %ecx,%edx
mov    $0xffffffff,%eax
cmp    %esi,%edx
je     1140 <labellen+0x40>
cmp    $0x40,%edx
jne    1141 <labellen+0x41>
cmp    $0x41,%ecx
jne    1140 <labellen+0x40>
mov    0x4(%rdi),%eax
lea    0x7(%rax),%ecx
lea    0xe(%rax),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
sar    $0x3,%edx
add    $0x1,%edx
test   %eax,%eax
mov    $0x21,%eax
cmovne %edx,%eax
ret
mov    %ecx,%eax
ret

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

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