#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*/ u_char;

/* Variables and functions */
void *memcpy(void *, int /*<<< orphan*/ const *, size_t);
int /*<<< orphan*/ printf(char *);
void *pkt_memcpy(const u_char *packet_data, void *target, const int offset,
                 size_t length) {
  if (offset < 0 || NULL == packet_data || NULL == target) {
    printf("ERR: Invalid input packet_data or target str or offset\n");
    return NULL;
  }
  return memcpy(target, packet_data + offset, length);
}


x86 assembly (clang, -O0):
<pkt_memcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1159 <pkt_memcpy+0x39>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     1159 <pkt_memcpy+0x39>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    1172 <pkt_memcpy+0x52>
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1192 <pkt_memcpy+0x72>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkt_memcpy>:
push   %rbx
test   %rsi,%rsi
je     1145 <pkt_memcpy+0x25>
test   %rdi,%rdi
je     1145 <pkt_memcpy+0x25>
test   %edx,%edx
js     1145 <pkt_memcpy+0x25>
mov    %rsi,%rbx
mov    %edx,%eax
lea    (%rdi,%rax,4),%rsi
mov    %rbx,%rdi
mov    %rcx,%rdx
call   1040 <memcpy@plt>
jmp    1153 <pkt_memcpy+0x33>
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [56 x i8] c"ERR: Invalid input packet_data or target str or offset\0A\00"
define i8* @pkt_memcpy(i32* %0, i8* %1, i32 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i64 %3, i64* %9
%10 = load i32, i32* %8
%11 = icmp slt i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %4
%13 = load i32*, i32** %6
%14 = icmp eq i32* null, %13
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i8*, i8** %7
%17 = icmp eq i8* null, %16
br i1 %17, label %18, label %20
18: ; preds = %15, %12, %4
%19 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %5
br label %28
20: ; preds = %15
%21 = load i8*, i8** %7
%22 = load i32*, i32** %6
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i64, i64* %9
%27 = call i8* @memcpy(i8* %21, i32* %25, i64 %26)
store i8* %27, i8** %5
br label %28
28: ; preds = %20, %18
%29 = load i8*, i8** %5
ret i8* %29
}

LLVM IR (-O2):
@str = [55 x i8] c"ERR: Invalid input packet_data or target str or offset\00"
define i8* @pkt_memcpy(i32* %0, i8* writeonly %1, i32 %2, i64 %3) {
%5 = icmp slt i32 %2, 0
%6 = icmp eq i32* %0, null
%7 = or i1 %6, %5
%8 = icmp eq i8* %1, null
%9 = or i1 %8, %7
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
br label %16
12: ; preds = %4
%13 = zext i32 %2 to i64
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = bitcast i32* %14 to i8*
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %1, i8* align 1 %15, i64 %3, i1 false)
br label %16
16: ; preds = %12, %10
%17 = phi i8* [ null, %10 ], [ %1, %12 ]
ret i8* %17
}