#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 */
unsigned int _uiTlvGetLengthLen(unsigned char *);
unsigned int _uiTlvGetTagLen(unsigned char *);
unsigned int _uiTlvGetValueLen(unsigned char *);
unsigned int _uiTlvGetObjLen(unsigned char *psTlvObject) {
  unsigned int uiRet, uiLength;
  uiRet = _uiTlvGetTagLen(psTlvObject);
  if (uiRet == 0)
    return (0);
  uiLength = uiRet;
  uiRet = _uiTlvGetLengthLen(psTlvObject);
  if (uiRet == 0)
    return (0);
  uiLength += uiRet;
  uiRet = _uiTlvGetValueLen(psTlvObject);
  if (uiRet == 0xffff)
    return (0);
  uiLength += uiRet;
  return (uiLength);
}


x86 assembly (clang, -O0):
<_uiTlvGetObjLen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <_uiTlvGetTagLen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    115e <_uiTlvGetObjLen+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11c3 <_uiTlvGetObjLen+0x93>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <_uiTlvGetLengthLen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1186 <_uiTlvGetObjLen+0x56>
movl   $0x0,-0x4(%rbp)
jmp    11c3 <_uiTlvGetObjLen+0x93>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <_uiTlvGetValueLen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffff,-0x14(%rbp)
jne    11b4 <_uiTlvGetObjLen+0x84>
movl   $0x0,-0x4(%rbp)
jmp    11c3 <_uiTlvGetObjLen+0x93>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_uiTlvGetObjLen>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <_uiTlvGetTagLen@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     116e <_uiTlvGetObjLen+0x3e>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1030 <_uiTlvGetLengthLen@plt>
test   %eax,%eax
je     116e <_uiTlvGetObjLen+0x3e>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <_uiTlvGetValueLen@plt>
cmp    $0xffff,%eax
je     116e <_uiTlvGetObjLen+0x3e>
add    %r15d,%ebp
add    %eax,%ebp
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @_uiTlvGetObjLen(i8* %0) {
%2 = tail call i32 @_uiTlvGetTagLen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = tail call i32 @_uiTlvGetLengthLen(i8* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = tail call i32 @_uiTlvGetValueLen(i8* %0)
%9 = icmp eq i32 %8, 65535
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = add i32 %5, %2
%12 = add i32 %11, %8
br label %13
13: ; preds = %7, %4, %1, %10
%14 = phi i32 [ %12, %10 ], [ 0, %1 ], [ 0, %4 ], [ 0, %7 ]
ret i32 %14
}