#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__ _uiTlvGetTagLen(unsigned char *);
unsigned int _uiTlvGetLengthLen(unsigned char *psTlvObject) {
  unsigned char *psPointer;
  psPointer = psTlvObject;
  if (_uiTlvGetTagLen(psTlvObject) == 0)
    return (0);
  psPointer += _uiTlvGetTagLen(psTlvObject);
  if (((*psPointer) & 0x80) != 0x80)
    return (1);
  if (*psPointer != 0x81)
    return (0);
  return (((*psPointer) & 0x7f) + 1);
}


x86 assembly (clang, -O0):
<_uiTlvGetLengthLen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <_uiTlvGetTagLen@plt>
cmp    $0x0,%rax
jne    1143 <_uiTlvGetLengthLen+0x33>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <_uiTlvGetLengthLen+0x95>
mov    -0x10(%rbp),%rdi
call   1030 <_uiTlvGetTagLen@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
and    $0x80,%eax
cmp    $0x80,%eax
je     1177 <_uiTlvGetLengthLen+0x67>
movl   $0x1,-0x4(%rbp)
jmp    11a5 <_uiTlvGetLengthLen+0x95>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x81,%eax
je     1195 <_uiTlvGetLengthLen+0x85>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <_uiTlvGetLengthLen+0x95>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
and    $0x7f,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_uiTlvGetLengthLen>:
push   %rbx
mov    %rdi,%rbx
call   1030 <_uiTlvGetTagLen@plt>
test   %rax,%rax
je     1134 <_uiTlvGetLengthLen+0x24>
mov    %rbx,%rdi
call   1030 <_uiTlvGetTagLen@plt>
mov    (%rbx,%rax,1),%cl
mov    $0x1,%eax
test   %cl,%cl
js     1138 <_uiTlvGetLengthLen+0x28>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
xor    %eax,%eax
cmp    $0x81,%cl
sete   %al
add    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @_uiTlvGetLengthLen(i8* %0) {
%2 = tail call i64 @_uiTlvGetTagLen(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i64 @_uiTlvGetTagLen(i8* %0)
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp sgt i8 %7, -1
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = icmp eq i8 %7, -127
%11 = select i1 %10, i32 2, i32 0
br label %12
12: ; preds = %9, %4, %1
%13 = phi i32 [ 0, %1 ], [ 1, %4 ], [ %11, %9 ]
ret i32 %13
}