#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 */
int _uiTlvGetObjLen(unsigned char *);
int _iTlvCheckTlvObj(unsigned char *psTlvObj) {
  int iTagLen;
  if (psTlvObj[0] == 0x00 || psTlvObj[0] == 0xff)
    return (-1);
  if ((psTlvObj[0] & 0x1f) == 0x1f && (psTlvObj[1] & 0x80) == 0x80) {
    if (psTlvObj[0] != 0xDF)
      return (-2);
  }
  if ((psTlvObj[0] & 0x1f) == 0x1f)
    iTagLen = 2;
  else
    iTagLen = 1;
  if ((psTlvObj[iTagLen] & 0x80) == 0x80 && (psTlvObj[iTagLen] & 0x7f) != 1)
    return (-3);
  return (_uiTlvGetObjLen(psTlvObj));
}


x86 assembly (clang, -O0):
<_iTlvCheckTlvObj>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     113e <_iTlvCheckTlvObj+0x2e>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xff,%eax
jne    114a <_iTlvCheckTlvObj+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <_iTlvCheckTlvObj+0xfa>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0x1f,%eax
cmp    $0x1f,%eax
jne    1198 <_iTlvCheckTlvObj+0x88>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0x80,%eax
cmp    $0x80,%eax
jne    1198 <_iTlvCheckTlvObj+0x88>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xdf,%eax
je     1193 <_iTlvCheckTlvObj+0x83>
movl   $0xfffffffe,-0x4(%rbp)
jmp    120a <_iTlvCheckTlvObj+0xfa>
jmp    1198 <_iTlvCheckTlvObj+0x88>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0x1f,%eax
cmp    $0x1f,%eax
jne    11b7 <_iTlvCheckTlvObj+0xa7>
movl   $0x2,-0x14(%rbp)
jmp    11be <_iTlvCheckTlvObj+0xae>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0x80,%eax
cmp    $0x80,%eax
jne    11fe <_iTlvCheckTlvObj+0xee>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0x7f,%eax
cmp    $0x1,%eax
je     11fe <_iTlvCheckTlvObj+0xee>
movl   $0xfffffffd,-0x4(%rbp)
jmp    120a <_iTlvCheckTlvObj+0xfa>
mov    -0x10(%rbp),%rdi
call   1030 <_uiTlvGetObjLen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_iTlvCheckTlvObj>:
mov    (%rdi),%cl
mov    $0xffffffff,%eax
lea    0x1(%rcx),%edx
cmp    $0x2,%dl
jae    1120 <_iTlvCheckTlvObj+0x10>
ret
mov    %ecx,%eax
not    %al
mov    $0x1,%edx
test   $0x1f,%al
jne    1142 <_iTlvCheckTlvObj+0x32>
cmpb   $0x0,0x1(%rdi)
mov    $0x2,%edx
jns    1142 <_iTlvCheckTlvObj+0x32>
mov    $0xfffffffe,%eax
cmp    $0xdf,%cl
jne    111f <_iTlvCheckTlvObj+0xf>
movzbl (%rdi,%rdx,1),%ecx
test   $0x80,%cl
je     1158 <_iTlvCheckTlvObj+0x48>
and    $0x7f,%ecx
mov    $0xfffffffd,%eax
cmp    $0x1,%ecx
jne    111f <_iTlvCheckTlvObj+0xf>
jmp    1030 <_uiTlvGetObjLen@plt>

LLVM IR (-O0):
define i32 @_iTlvCheckTlvObj(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = icmp eq i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = icmp eq i32 %14, 255
br i1 %15, label %16, label %17
16: ; preds = %10, %1
store i32 -1, i32* %2
br label %70
17: ; preds = %10
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = and i32 %21, 31
%23 = icmp eq i32 %22, 31
br i1 %23, label %24, label %39
24: ; preds = %17
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = and i32 %28, 128
%30 = icmp eq i32 %29, 128
br i1 %30, label %31, label %39
31: ; preds = %24
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = icmp ne i32 %35, 223
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 -2, i32* %2
br label %70
38: ; preds = %31
br label %39
39: ; preds = %38, %24, %17
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i64 0
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = and i32 %43, 31
%45 = icmp eq i32 %44, 31
br i1 %45, label %46, label %47
46: ; preds = %39
store i32 2, i32* %4
br label %48
47: ; preds = %39
store i32 1, i32* %4
br label %48
48: ; preds = %47, %46
%49 = load i8*, i8** %3
%50 = load i32, i32* %4
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = and i32 %54, 128
%56 = icmp eq i32 %55, 128
br i1 %56, label %57, label %67
57: ; preds = %48
%58 = load i8*, i8** %3
%59 = load i32, i32* %4
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = and i32 %63, 127
%65 = icmp ne i32 %64, 1
br i1 %65, label %66, label %67
66: ; preds = %57
store i32 -3, i32* %2
br label %70
67: ; preds = %57, %48
%68 = load i8*, i8** %3
%69 = call i32 @_uiTlvGetObjLen(i8* %68)
store i32 %69, i32* %2
br label %70
70: ; preds = %67, %66, %37, %16
%71 = load i32, i32* %2
ret i32 %71
}

LLVM IR (-O2):
define i32 @_iTlvCheckTlvObj(i8* %0) {
%2 = load i8, i8* %0
switch i8 %2, label %3 [
i8 0, label %24
i8 -1, label %24
]
3: ; preds = %1
%4 = and i8 %2, 31
%5 = icmp eq i8 %4, 31
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = icmp sgt i8 %8, -1
%10 = icmp eq i8 %2, -33
%11 = select i1 %9, i1 true, i1 %10
br i1 %11, label %12, label %24
12: ; preds = %6, %3
%13 = phi i64 [ 2, %6 ], [ 1, %3 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = and i32 %16, 128
%18 = icmp eq i32 %17, 0
%19 = and i32 %16, 127
%20 = icmp eq i32 %19, 1
%21 = or i1 %18, %20
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = tail call i32 @_uiTlvGetObjLen(i8* %0)
br label %24
24: ; preds = %12, %6, %1, %1, %22
%25 = phi i32 [ %23, %22 ], [ -1, %1 ], [ -1, %1 ], [ -2, %6 ], [ -3, %12 ]
ret i32 %25
}