#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 _uiTlvGetLengthLen(unsigned char *);
int _uiTlvGetTagLen(unsigned char *);
int iTlvGetObj(unsigned char *, unsigned char *, unsigned char **);
int iTlvGetObjValue(unsigned char *psTlvBuffer, unsigned char *psTag,
                    unsigned char **ppsValue) {
  int iRet;
  unsigned char *psTlvObject;
  int iTagLenLengthLen;
  iRet = iTlvGetObj(psTlvBuffer, psTag, &psTlvObject);
  if (iRet < 0)
    return (iRet);
  iTagLenLengthLen =
      _uiTlvGetTagLen(psTlvObject) + _uiTlvGetLengthLen(psTlvObject);
  *ppsValue = psTlvObject + iTagLenLengthLen;
  return (iRet - iTagLenLengthLen);
}


x86 assembly (clang, -O0):
<iTlvGetObjValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <iTlvGetObj@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    116d <iTlvGetObjValue+0x3d>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a7 <iTlvGetObjValue+0x77>
mov    -0x30(%rbp),%rdi
call   1050 <_uiTlvGetTagLen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <_uiTlvGetLengthLen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rcx
movslq -0x34(%rbp),%rax
add    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%eax
sub    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iTlvGetObjValue>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
lea    0x8(%rsp),%rdx
call   1030 <iTlvGetObj@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1172 <iTlvGetObjValue+0x42>
mov    0x8(%rsp),%rdi
call   1050 <_uiTlvGetTagLen@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdi
call   1040 <_uiTlvGetLengthLen@plt>
add    %ebp,%eax
cltq
mov    0x8(%rsp),%rcx
add    %rax,%rcx
mov    %rcx,(%r14)
sub    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @iTlvGetObjValue(i8* %0, i8* %1, i8** nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i32 @iTlvGetObj(i8* %0, i8* %1, i8** %4)
%7 = icmp slt i32 %6, 0
br i1 %7, label %18, label %8
8: ; preds = %3
%9 = load i8*, i8** %4
%10 = call i32 @_uiTlvGetTagLen(i8* %9)
%11 = load i8*, i8** %4
%12 = call i32 @_uiTlvGetLengthLen(i8* %11)
%13 = add nsw i32 %12, %10
%14 = load i8*, i8** %4
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds i8, i8* %14, i64 %15
store i8* %16, i8** %2
%17 = sub nsw i32 %6, %13
br label %18
18: ; preds = %3, %8
%19 = phi i32 [ %17, %8 ], [ %6, %3 ]
ret i32 %19
}