#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 UnpckBacpSerialAppEx(unsigned char *, unsigned char *, unsigned char **,
                         unsigned short *, unsigned char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned short);
int UnpckBacpSerialApp(unsigned char *pnFunCategory, unsigned char *pnFunCode,
                       unsigned char *pData, unsigned short *pnDataLen,
                       unsigned char *pFrm, int nFrmLen) {
  unsigned char *pDataTmp;
  int nFrmLenInner;
  nFrmLenInner = UnpckBacpSerialAppEx(pnFunCategory, pnFunCode, &pDataTmp,
                                      pnDataLen, pFrm, nFrmLen);
  if (nFrmLenInner > 0) {
    if (*pnDataLen > 0) {
      memcpy(pData, pDataTmp, *pnDataLen);
    }
  }
  return nFrmLenInner;
}


x86 assembly (clang, -O0):
<UnpckBacpSerialApp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
lea    -0x38(%rbp),%rdx
call   1040 <UnpckBacpSerialAppEx@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jle    1196 <UnpckBacpSerialApp+0x76>
mov    -0x20(%rbp),%rax
movzwl (%rax),%eax
cmp    $0x0,%eax
jle    1191 <UnpckBacpSerialApp+0x71>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%ax
movzwl %ax,%edx
call   1030 <memcpy@plt>
jmp    1196 <UnpckBacpSerialApp+0x76>
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UnpckBacpSerialApp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbx
mov    %rdx,%r14
lea    0x8(%rsp),%rdx
call   1040 <UnpckBacpSerialAppEx@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1156 <UnpckBacpSerialApp+0x36>
movzwl (%rbx),%eax
test   %ax,%ax
je     1156 <UnpckBacpSerialApp+0x36>
mov    0x8(%rsp),%rsi
movzwl %ax,%edx
mov    %r14,%rdi
call   1030 <memcpy@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @UnpckBacpSerialApp(i8* %0, i8* %1, i8* %2, i16* %3, i8* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i16*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i16* %3, i16** %10
store i8* %4, i8** %11
store i32 %5, i32* %12
%15 = load i8*, i8** %7
%16 = load i8*, i8** %8
%17 = load i16*, i16** %10
%18 = load i8*, i8** %11
%19 = load i32, i32* %12
%20 = call i32 @UnpckBacpSerialAppEx(i8* %15, i8* %16, i8** %13, i16* %17, i8* %18, i32 %19)
store i32 %20, i32* %14
%21 = load i32, i32* %14
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %35
23: ; preds = %6
%24 = load i16*, i16** %10
%25 = load i16, i16* %24
%26 = zext i16 %25 to i32
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %23
%29 = load i8*, i8** %9
%30 = load i8*, i8** %13
%31 = load i16*, i16** %10
%32 = load i16, i16* %31
%33 = call i32 @memcpy(i8* %29, i8* %30, i16 zeroext %32)
br label %34
34: ; preds = %28, %23
br label %35
35: ; preds = %34, %6
%36 = load i32, i32* %14
ret i32 %36
}

LLVM IR (-O2):
define i32 @UnpckBacpSerialApp(i8* %0, i8* %1, i8* %2, i16* %3, i8* %4, i32 %5) {
%7 = alloca i8*
%8 = bitcast i8** %7 to i8*
%9 = call i32 @UnpckBacpSerialAppEx(i8* %0, i8* %1, i8** %7, i16* %3, i8* %4, i32 %5)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = load i16, i16* %3
%13 = icmp eq i16 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i8*, i8** %7
%16 = call i32 @memcpy(i8* %2, i8* %15, i16 zeroext %12)
br label %17
17: ; preds = %11, %14, %6
ret i32 %9
}