#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 iDgiAddItem(unsigned char *, unsigned char *, int);
int iTlvGetObj(unsigned char *, unsigned char *, unsigned char **);
int iDgiAddItemFromTLVBuf(unsigned char *psDgiBuf, unsigned char *psTag,
                          unsigned char *psTlvBuf) {
  unsigned char *psTlvObject;
  int iRet, iLen;
  iLen = iTlvGetObj(psTlvBuf, psTag, &psTlvObject);
  if (iLen <= 0)
    return (4);
  iRet = iDgiAddItem(psDgiBuf, psTlvObject, iLen);
  if (iRet)
    return (1);
  return (0);
}


x86 assembly (clang, -O0):
<iDgiAddItemFromTLVBuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <iTlvGetObj@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jg     115e <iDgiAddItemFromTLVBuf+0x3e>
movl   $0x4,-0x4(%rbp)
jmp    118e <iDgiAddItemFromTLVBuf+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1040 <iDgiAddItem@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1187 <iDgiAddItemFromTLVBuf+0x67>
movl   $0x1,-0x4(%rbp)
jmp    118e <iDgiAddItemFromTLVBuf+0x6e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iDgiAddItemFromTLVBuf>:
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rax
mov    %rdi,%rbx
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1030 <iTlvGetObj@plt>
test   %eax,%eax
jle    1156 <iDgiAddItemFromTLVBuf+0x36>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <iDgiAddItem@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setne  %al
jmp    115b <iDgiAddItemFromTLVBuf+0x3b>
mov    $0x4,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @iDgiAddItemFromTLVBuf(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %7
%12 = load i8*, i8** %6
%13 = call i32 @iTlvGetObj(i8* %11, i8* %12, i8** %8)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp sle i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 4, i32* %4
br label %26
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i8*, i8** %8
%20 = load i32, i32* %10
%21 = call i32 @iDgiAddItem(i8* %18, i8* %19, i32 %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 1, i32* %4
br label %26
25: ; preds = %17
store i32 0, i32* %4
br label %26
26: ; preds = %25, %24, %16
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
define i32 @iDgiAddItemFromTLVBuf(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i32 @iTlvGetObj(i8* %2, i8* %1, i8** %4)
%7 = icmp slt i32 %6, 1
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = load i8*, i8** %4
%10 = call i32 @iDgiAddItem(i8* %0, i8* %9, i32 %6)
%11 = icmp ne i32 %10, 0
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %8, %3
%14 = phi i32 [ 4, %3 ], [ %12, %8 ]
ret i32 %14
}