#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 *);
int _uiTlvGetValueLen(unsigned char *);
int iTlvValue(unsigned char *psTlvObj, unsigned char **ppsTlvObjValue) {
  unsigned int uiRet;
  unsigned char ucPos;
  uiRet = _uiTlvGetTagLen(psTlvObj);
  if (uiRet == 0)
    return (-10002);
  ucPos = (unsigned char)uiRet;
  uiRet = _uiTlvGetLengthLen(psTlvObj);
  if (uiRet == 0)
    return (-10002);
  ucPos += (unsigned char)uiRet;
  *ppsTlvObjValue = psTlvObj + ucPos;
  return (_uiTlvGetValueLen(psTlvObj));
}


x86 assembly (clang, -O0):
<iTlvValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <_uiTlvGetTagLen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1162 <iTlvValue+0x32>
movl   $0xffffd8ee,-0x4(%rbp)
jmp    11b9 <iTlvValue+0x89>
mov    -0x1c(%rbp),%eax
mov    %al,-0x1d(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <_uiTlvGetLengthLen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    118a <iTlvValue+0x5a>
movl   $0xffffd8ee,-0x4(%rbp)
jmp    11b9 <iTlvValue+0x89>
mov    -0x1c(%rbp),%eax
movzbl %al,%ecx
movzbl -0x1d(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x1d(%rbp)
mov    -0x10(%rbp),%rcx
movzbl -0x1d(%rbp),%eax
cltq
add    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <_uiTlvGetValueLen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iTlvValue>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <_uiTlvGetTagLen@plt>
test   %eax,%eax
je     1168 <iTlvValue+0x38>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <_uiTlvGetLengthLen@plt>
test   %eax,%eax
je     1168 <iTlvValue+0x38>
add    %ebp,%eax
movzbl %al,%eax
add    %rbx,%rax
mov    %rax,(%r14)
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <_uiTlvGetValueLen@plt>
mov    $0xffffd8ee,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @iTlvValue(i8* %0, i8** nocapture writeonly %1) {
%3 = tail call i32 @_uiTlvGetTagLen(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = tail call i32 @_uiTlvGetLengthLen(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = add i32 %6, %3
%10 = and i32 %9, 255
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8* %12, i8** %1
%13 = tail call i32 @_uiTlvGetValueLen(i8* %0)
br label %14
14: ; preds = %5, %2, %8
%15 = phi i32 [ %13, %8 ], [ -10002, %2 ], [ -10002, %5 ]
ret i32 %15
}