#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 */
scalar_t__ ccnl_iottlv_varlenint(unsigned char **, int *, int *);
int ccnl_iottlv_peekType(unsigned char *buf, int len) {
  int typ;
  if (len < 1)
    return -1;
  if (*buf)
    return *buf >> 6;
  buf++;
  len--;
  if (ccnl_iottlv_varlenint(&buf, &len, &typ) < 0)
    return -1;
  return typ;
}


x86 assembly (clang, -O0):
<ccnl_iottlv_peekType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    1135 <ccnl_iottlv_peekType+0x25>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <ccnl_iottlv_peekType+0x86>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1154 <ccnl_iottlv_peekType+0x44>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
sar    $0x6,%eax
mov    %eax,-0x4(%rbp)
jmp    1196 <ccnl_iottlv_peekType+0x86>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <ccnl_iottlv_varlenint@plt>
cmp    $0x0,%rax
jge    1190 <ccnl_iottlv_peekType+0x80>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <ccnl_iottlv_peekType+0x86>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccnl_iottlv_peekType>:
sub    $0x18,%rsp
test   %esi,%esi
jle    1127 <ccnl_iottlv_peekType+0x17>
movzbl (%rdi),%eax
test   %eax,%eax
je     1131 <ccnl_iottlv_peekType+0x21>
shr    $0x6,%eax
add    $0x18,%rsp
ret
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret
add    $0x1,%rdi
mov    %rdi,0x10(%rsp)
add    $0xffffffff,%esi
mov    %esi,0xc(%rsp)
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1030 <ccnl_iottlv_varlenint@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
js     1166 <ccnl_iottlv_peekType+0x56>
mov    0x8(%rsp),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @ccnl_iottlv_peekType(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %29
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = ashr i32 %17, 6
store i32 %18, i32* %3
br label %29
19: ; preds = %10
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i32, i32* %5
%23 = add nsw i32 %22, -1
store i32 %23, i32* %5
%24 = call i64 @ccnl_iottlv_varlenint(i8** %4, i32* %5, i32* %6)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 -1, i32* %3
br label %29
27: ; preds = %19
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %29
29: ; preds = %27, %26, %14, %9
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @ccnl_iottlv_peekType(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = icmp slt i32 %1, 1
br i1 %7, label %21, label %8
8: ; preds = %2
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = lshr i8 %9, 6
%13 = zext i8 %12 to i32
br label %21
14: ; preds = %8
%15 = getelementptr inbounds i8, i8* %0, i64 1
store i8* %15, i8** %3
%16 = add nsw i32 %1, -1
store i32 %16, i32* %4
%17 = call i64 @ccnl_iottlv_varlenint(i8** %3, i32* %4, i32* %5)
%18 = icmp slt i64 %17, 0
%19 = load i32, i32* %5
%20 = select i1 %18, i32 -1, i32 %19
br label %21
21: ; preds = %14, %2, %11
%22 = phi i32 [ %13, %11 ], [ -1, %2 ], [ %20, %14 ]
ret i32 %22
}