#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 labellen(const u_char *lp) {
  int bitlen;
  u_char l = *lp;
  if ((l & 0xc0) == 0xc0) {
    return -1;
  }
  if ((l & 0xc0) == 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
and    $0xc0,%eax
cmp    $0xc0,%eax
jne    1130 <labellen+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    1190 <labellen+0x90>
mov    -0x18(%rbp),%eax
and    $0xc0,%eax
cmp    $0x40,%eax
jne    118a <labellen+0x8a>
cmpl   $0x41,-0x18(%rbp)
jne    117e <labellen+0x7e>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1165 <labellen+0x65>
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    1190 <labellen+0x90>
movl   $0xffffffff,-0x4(%rbp)
jmp    1190 <labellen+0x90>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<labellen>:
mov    (%rdi),%ecx
mov    %ecx,%edx
and    $0xc0,%dl
mov    $0xffffffff,%eax
cmp    $0xc0,%dl
je     113c <labellen+0x3c>
cmp    $0x40,%dl
jne    113a <labellen+0x3a>
cmp    $0x41,%ecx
jne    113c <labellen+0x3c>
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):
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 = and i32 %8, 192
%10 = icmp eq i32 %9, 192
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %33
12: ; preds = %1
%13 = load i32, i32* %5
%14 = and i32 %13, 192
%15 = icmp eq i32 %14, 64
br i1 %15, label %16, label %31
16: ; preds = %12
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 65
br i1 %18, label %19, label %30
19: ; preds = %16
%20 = load i32*, i32** %3
%21 = getelementptr inbounds i32, i32* %20, i64 1
%22 = load i32, i32* %21
store i32 %22, i32* %4
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 256, i32* %4
br label %25
25: ; preds = %24, %19
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 7
%28 = sdiv i32 %27, 8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %33
30: ; preds = %16
store i32 -1, i32* %2
br label %33
31: ; preds = %12
%32 = load i32, i32* %5
store i32 %32, i32* %2
br label %33
33: ; preds = %31, %30, %25, %11
%34 = load i32, i32* %2
ret i32 %34
}

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