#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 */
typedef int /*<<< orphan*/ sBuf;

/* Variables and functions */
int iTlvMakeObject(char *, unsigned short, unsigned char *, unsigned char *,
                   int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int iDgiPack70(unsigned char *psDgiBuf) {
  unsigned char sBuf[256];
  int iRet;
  iRet = iTlvMakeObject("\x70", (unsigned short)psDgiBuf[2], psDgiBuf + 3, sBuf,
                        sizeof(sBuf));
  if (iRet <= 0)
    return (1);
  psDgiBuf[2] = iRet;
  memcpy(psDgiBuf + 3, sBuf, iRet);
  return (0);
}


x86 assembly (clang, -O0):
<iDgiPack70>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
mov    -0x10(%rbp),%rdx
add    $0x3,%rdx
lea    -0x110(%rbp),%rcx
lea    0xeb3(%rip),%rdi
mov    $0x100,%r8d
movzwl %ax,%esi
call   1040 <iTlvMakeObject@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jg     117a <iDgiPack70+0x5a>
movl   $0x1,-0x4(%rbp)
jmp    11aa <iDgiPack70+0x8a>
mov    -0x114(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x10(%rbp),%rdi
add    $0x3,%rdi
lea    -0x110(%rbp),%rsi
mov    -0x114(%rbp),%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iDgiPack70>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rbx
movzbl 0x2(%rdi),%esi
lea    0x3(%rdi),%r14
lea    0xec4(%rip),%rdi
mov    %rsp,%rcx
mov    %r14,%rdx
mov    $0x100,%r8d
call   1040 <iTlvMakeObject@plt>
test   %eax,%eax
jle    1165 <iDgiPack70+0x45>
mov    %al,0x2(%rbx)
mov    %rsp,%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1030 <memcpy@plt>
xor    %eax,%eax
jmp    116a <iDgiPack70+0x4a>
mov    $0x1,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"p\00"
define i32 @iDgiPack70(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 2
%8 = load i8, i8* %7
%9 = zext i8 %8 to i16
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 3
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%13 = call i32 @iTlvMakeObject(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i16 zeroext %9, i8* %11, i8* %12, i32 256)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp sle i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 1, i32* %2
br label %27
17: ; preds = %1
%18 = load i32, i32* %5
%19 = trunc i32 %18 to i8
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 2
store i8 %19, i8* %21
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 3
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%25 = load i32, i32* %5
%26 = call i32 @memcpy(i8* %23, i8* %24, i32 %25)
store i32 0, i32* %2
br label %27
27: ; preds = %17, %16
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [2 x i8] c"p\00"
define i32 @iDgiPack70(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds i8, i8* %0, i64 2
%5 = load i8, i8* %4
%6 = zext i8 %5 to i16
%7 = getelementptr inbounds i8, i8* %0, i64 3
%8 = call i32 @iTlvMakeObject(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i16 zeroext %6, i8* %7, i8* %3, i32 256)
%9 = icmp slt i32 %8, 1
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = trunc i32 %8 to i8
store i8 %11, i8* %4
%12 = call i32 @memcpy(i8* %7, i8* %3, i32 %8)
br label %13
13: ; preds = %1, %10
%14 = phi i32 [ 0, %10 ], [ 1, %1 ]
ret i32 %14
}