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


x86 assembly (clang, -O0):
<_uiTlvGetValueLen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <_uiTlvGetTagLen@plt>
cmp    $0x0,%eax
jne    115a <_uiTlvGetValueLen+0x2a>
movl   $0xffff,-0x4(%rbp)
jmp    11e0 <_uiTlvGetValueLen+0xb0>
mov    -0x10(%rbp),%rdi
call   1040 <_uiTlvGetLengthLen@plt>
cmp    $0x0,%rax
jne    1179 <_uiTlvGetValueLen+0x49>
movl   $0xffff,-0x4(%rbp)
jmp    11e0 <_uiTlvGetValueLen+0xb0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <_uiTlvGetTagLen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
and    $0x80,%eax
cmp    $0x80,%eax
je     11c0 <_uiTlvGetValueLen+0x90>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e0 <_uiTlvGetValueLen+0xb0>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
and    $0x7f,%eax
movzwl %ax,%esi
call   1030 <ulStrToLong@plt>
movzwl %ax,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_uiTlvGetValueLen>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <_uiTlvGetTagLen@plt>
mov    $0xffff,%ebp
test   %eax,%eax
je     117c <_uiTlvGetValueLen+0x4c>
mov    %rbx,%rdi
call   1040 <_uiTlvGetLengthLen@plt>
test   %rax,%rax
je     117c <_uiTlvGetValueLen+0x4c>
mov    %rbx,%rdi
call   1050 <_uiTlvGetTagLen@plt>
cltq
movzbl (%rbx,%rax,1),%ebp
test   $0x80,%bpl
je     117c <_uiTlvGetValueLen+0x4c>
add    %rax,%rbx
add    $0x1,%rbx
and    $0x7f,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <ulStrToLong@plt>
movzwl %ax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @_uiTlvGetValueLen(i8* %0) {
%2 = tail call i32 @_uiTlvGetTagLen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %22, label %4
4: ; preds = %1
%5 = tail call i64 @_uiTlvGetLengthLen(i8* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %22, label %7
7: ; preds = %4
%8 = tail call i32 @_uiTlvGetTagLen(i8* %0)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = and i32 %12, 128
%14 = icmp eq i32 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %7
%16 = getelementptr inbounds i8, i8* %10, i64 1
%17 = and i8 %11, 127
%18 = zext i8 %17 to i16
%19 = tail call i64 @ulStrToLong(i8* %16, i16 zeroext %18)
%20 = trunc i64 %19 to i32
%21 = and i32 %20, 65535
br label %22
22: ; preds = %7, %4, %1, %15
%23 = phi i32 [ %21, %15 ], [ 65535, %1 ], [ 65535, %4 ], [ %12, %7 ]
ret i32 %23
}