#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 _uiTlvGetValueLen(unsigned char *);
short iTlvSearchObj(unsigned char *, int, int, unsigned char *,
                    unsigned char **);
int iTlvSearchObjValue(unsigned char *psTemplate, int iTemplateLen, int iIndex,
                       unsigned char *psTagRoute,
                       unsigned char **ppsTlvObjValue) {
  short iRet;
  unsigned char *psTlvObj;
  iRet = iTlvSearchObj(psTemplate, iTemplateLen, iIndex, psTagRoute, &psTlvObj);
  if (iRet < 0)
    return (iRet);
  *ppsTlvObjValue =
      psTlvObj + _uiTlvGetTagLen(psTlvObj) + _uiTlvGetLengthLen(psTlvObj);
  return (_uiTlvGetValueLen(psTlvObj));
}


x86 assembly (clang, -O0):
<iTlvSearchObjValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1040 <iTlvSearchObj@plt>
mov    %ax,-0x2a(%rbp)
movswl -0x2a(%rbp),%eax
cmp    $0x0,%eax
jge    118e <iTlvSearchObjValue+0x4e>
movswl -0x2a(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <iTlvSearchObjValue+0x94>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <_uiTlvGetTagLen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <_uiTlvGetLengthLen@plt>
mov    -0x40(%rbp),%rcx
cltq
add    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
call   1050 <_uiTlvGetValueLen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iTlvSearchObjValue>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r14
lea    0x8(%rsp),%r8
call   1040 <iTlvSearchObj@plt>
test   %ax,%ax
js     118c <iTlvSearchObjValue+0x4c>
mov    0x8(%rsp),%r15
mov    %r15,%rdi
call   1060 <_uiTlvGetTagLen@plt>
movslq %eax,%rbx
add    %r15,%rbx
mov    0x8(%rsp),%rdi
call   1030 <_uiTlvGetLengthLen@plt>
cltq
add    %rbx,%rax
mov    %rax,(%r14)
mov    0x8(%rsp),%rdi
call   1050 <_uiTlvGetValueLen@plt>
jmp    118d <iTlvSearchObjValue+0x4d>
cwtl
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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